Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 23 additions & 19 deletions TLM/TLM/Custom/PathFinding/CustomPathFind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public class CustomPathFind : PathFind {

private GlobalConfig globalConf_;

private SavedGameOptions savedGameOptions_;

private struct BufferItem {
public PathUnit.Position Position;
public float ComparisonValue;
Expand Down Expand Up @@ -252,7 +254,9 @@ private bool ExtCalculatePath(uint unit, bool skipQueue) {
}

private void PathFindImplementation(uint unit, ref PathUnit data) {

globalConf_ = GlobalConfig.Instance; // NON-STOCK CODE
savedGameOptions_ = SavedGameOptions.Instance;

NetManager netManager = Singleton<NetManager>.instance;

Expand Down Expand Up @@ -298,11 +302,11 @@ private void PathFindImplementation(uint unit, ref PathUnit data) {
(queueItem_.vehicleType & ExtVehicleType.RoadVehicle) != ExtVehicleType.None;

isLaneArrowObeyingEntity_ =
(!Options.relaxedBusses || queueItem_.vehicleType != ExtVehicleType.Bus) &&
(!savedGameOptions_.relaxedBusses || queueItem_.vehicleType != ExtVehicleType.Bus) &&
(vehicleTypes_ & LaneArrowManager.VEHICLE_TYPES) != VehicleInfo.VehicleType.None &&
(queueItem_.vehicleType & LaneArrowManager.EXT_VEHICLE_TYPES) != ExtVehicleType.None;
#if DEBUG
isLaneArrowObeyingEntity_ &= !Options.allRelaxed;
isLaneArrowObeyingEntity_ &= !savedGameOptions_.allRelaxed;
#endif
#endif

Expand Down Expand Up @@ -1263,7 +1267,7 @@ ref nextLaneId.ToLane(),

if (isPedZoneRoad &&
// NON-STOCK CODE START skip execution when driving-only path for passenger car
!(Options.parkingAI &&
!(savedGameOptions_.parkingAI &&
queueItem_.vehicleType == ExtVehicleType.PassengerCar &&
queueItem_.pathType == ExtPathType.DrivingOnly)
// NON-STOCK CODE END
Expand Down Expand Up @@ -1366,7 +1370,7 @@ ref nextSegmentId.ToSegment(),
bool parkingAllowed = true;

// Parking AI: Determine if parking is allowed
if (Options.parkingAI) {
if (savedGameOptions_.parkingAI) {
if (isLogEnabled) {
DebugLog(
unitId,
Expand Down Expand Up @@ -1528,7 +1532,7 @@ ref sameSegLaneId.ToLane(),
}
} else {
// pocket car spawning
if (Options.parkingAI) {
if (savedGameOptions_.parkingAI) {
if (isLogEnabled) {
DebugLog(
unitId,
Expand Down Expand Up @@ -1792,11 +1796,11 @@ ref nextSegmentId.ToSegment(),
unitId,
item,
"ProcessItemMain: vehicle -> vehicle: Custom routing\n" +
$"\tOptions.advancedAI={Options.advancedAI}\n" +
$"\tOptions.advancedAI={savedGameOptions_.advancedAI}\n" +
$"\tprevIsRouted={prevIsRouted}\n" +
$"\tm_isRoadVehicle={isRoadVehicle_}\n" +
$"\tprevIsCarLane={prevIsCarLane}\n" +
$"\tm_stablePath={Options.advancedAI}");
$"\tm_stablePath={savedGameOptions_.advancedAI}");
}

// NON-STOCK CODE START
Expand All @@ -1812,7 +1816,7 @@ ref nextSegmentId.ToSegment(),
* Calculate Advanced Vehicle AI cost factors
* =============================================================================
*/
if (Options.advancedAI
if (savedGameOptions_.advancedAI
&& prevIsRouted
&& isRoadVehicle_
&& prevIsCarLane )
Expand Down Expand Up @@ -2692,7 +2696,7 @@ private bool ProcessItemCosts(
globalConf_.PathFinding.PublicTransportTransitionMaxPenalty;

bool applyTransportTransferPenalty =
Options.realisticPublicTransport &&
savedGameOptions_.realisticPublicTransport &&
!stablePath_ &&
(allowedLaneTypes &
(NetInfo.LaneType.PublicTransport | NetInfo.LaneType.Pedestrian)) ==
Expand All @@ -2708,7 +2712,7 @@ private bool ProcessItemCosts(
nextSegmentId,
$"ProcessItemCosts: Shall apply transport transfer penalty?\n" +
$"\tapplyTransportTransferPenalty={applyTransportTransferPenalty}\n" +
$"\tOptions.realisticPublicTransport={Options.realisticPublicTransport}\n" +
$"\tOptions.realisticPublicTransport={savedGameOptions_.realisticPublicTransport}\n" +
$"\tallowedLaneTypes={allowedLaneTypes}\n" +
$"\tallowedVehicleTypes={allowedVehicleTypes}\n" +
$"\tconf.pf.PubTranspTransitionMinPenalty={pfPublicTransportTransitionMinPenalty}\n" +
Expand Down Expand Up @@ -3239,12 +3243,12 @@ private void ProcessItemPedBicycle(
// NON-STOCK CODE START
bool mayCross = true;
#if JUNCTIONRESTRICTIONS || CUSTOMTRAFFICLIGHTS
if (Options.junctionRestrictionsEnabled || Options.timedLightsEnabled) {
if (savedGameOptions_.junctionRestrictionsEnabled || savedGameOptions_.timedLightsEnabled) {
bool nextIsStartNode = nextNodeId == nextSegment.m_startNode;

if (nextIsStartNode || nextNodeId == nextSegment.m_endNode) {
#if JUNCTIONRESTRICTIONS
if (Options.junctionRestrictionsEnabled &&
if (savedGameOptions_.junctionRestrictionsEnabled &&
item.Position.m_segment == nextSegmentId) {
// check if pedestrians are not allowed to cross here
if (!junctionManager.IsPedestrianCrossingAllowed(
Expand All @@ -3265,7 +3269,7 @@ private void ProcessItemPedBicycle(
#endif

#if CUSTOMTRAFFICLIGHTS
if (Options.timedLightsEnabled) {
if (savedGameOptions_.timedLightsEnabled) {
// check if pedestrian light won't change to green
CustomSegmentLights lights = customTrafficLightsManager.GetSegmentLights(nextSegmentId, nextIsStartNode, false);

Expand Down Expand Up @@ -3606,7 +3610,7 @@ private bool ProcessItemRouted(
* =====================================================================================
*/
bool canUseLane = CanUseLane(prevSegmentId, prevSegmentInfo, prevLaneIndex, prevLaneInfo, item.LaneId);
if (!canUseLane && Options.vehicleRestrictionsAggression ==
if (!canUseLane && savedGameOptions_.vehicleRestrictionsAggression ==
VehicleRestrictionsAggression.Strict) {
// vehicle is strictly prohibited to use this lane
if (isLogEnabled) {
Expand Down Expand Up @@ -3654,7 +3658,7 @@ private bool ProcessItemRouted(
bool isStockUturnPoint = (nextNode.m_flags & (NetNode.Flags.End | NetNode.Flags.OneWayOut)) != NetNode.Flags.None;

#if JUNCTIONRESTRICTIONS
if (Options.junctionRestrictionsEnabled) {
if (savedGameOptions_.junctionRestrictionsEnabled) {
bool nextIsStartNode = nextNodeId == prevSegment.m_startNode;
bool prevIsOutgoingOneWay =
nextIsStartNode
Expand Down Expand Up @@ -3712,7 +3716,7 @@ private bool ProcessItemRouted(
if (!canUseLane) {
laneSelectionCost *=
VehicleRestrictionsManager.PATHFIND_PENALTIES[
(int)Options.vehicleRestrictionsAggression];
(int)savedGameOptions_.vehicleRestrictionsAggression];
if (isLogEnabled) {
DebugLog(
unitId,
Expand All @@ -3727,7 +3731,7 @@ private bool ProcessItemRouted(
* Apply costs for large vehicles using inner lanes on highways
* =======================================================================================================
*/
if (Options.preferOuterLane &&
if (savedGameOptions_.preferOuterLane &&
isHeavyVehicle_ &&
isRoadVehicle_ &&
prevIsCarLane &&
Expand All @@ -3745,7 +3749,7 @@ private bool ProcessItemRouted(
item,
"ProcessItemRouted: Heavy trucks prefer outer lanes on highways: Applied lane costs\n"
+ "\t" + $"laneSelectionCost={laneSelectionCost}\n"
+ "\t" + $"Options.preferOuterLane={Options.preferOuterLane}\n"
+ "\t" + $"savedGameOptions_.preferOuterLane={savedGameOptions_.preferOuterLane}\n"
+ "\t" + $"m_isHeavyVehicle={isHeavyVehicle_}\n"
+ "\t" + $"m_isRoadVehicle={isRoadVehicle_}\n"
+ "\t" + $"prevIsCarLane={prevIsCarLane}\n"
Expand Down Expand Up @@ -4073,7 +4077,7 @@ private bool CanUseLane(ushort segmentId,
int laneIndex,
NetInfo.Lane laneInfo,
uint laneId) {
if (!Options.vehicleRestrictionsEnabled ||
if (!savedGameOptions_.vehicleRestrictionsEnabled ||
queueItem_.vehicleType == ExtVehicleType.None ||
queueItem_.vehicleType == ExtVehicleType.Tram ||
queueItem_.vehicleType == ExtVehicleType.Trolleybus ||
Expand Down
8 changes: 4 additions & 4 deletions TLM/TLM/Custom/PathFinding/PathfinderUpdates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ public static class PathfinderUpdates {
public static ExtVehicleType DespawnVehiclesIfNecessary() {
var filter = ExtVehicleType.None;

if (Options.SavegamePathfinderEdition == LatestPathfinderEdition) {
if (SavedGameOptions.Instance.SavegamePathfinderEdition == LatestPathfinderEdition) {
return filter; // nothing to do, everything is fine
}

Log.Info($"Pathfinder update from {Options.SavegamePathfinderEdition} to {LatestPathfinderEdition}.");
Log.Info($"Pathfinder update from {SavedGameOptions.Instance.SavegamePathfinderEdition} to {LatestPathfinderEdition}.");

if (Options.SavegamePathfinderEdition < 1) {
if (SavedGameOptions.Instance.SavegamePathfinderEdition < 1) {
filter |= ExtVehicleType.Plane; // #1338
}

Expand All @@ -60,7 +60,7 @@ public static ExtVehicleType DespawnVehiclesIfNecessary() {
}

// this will be stored in savegame
Options.SavegamePathfinderEdition = LatestPathfinderEdition;
SavedGameOptions.Instance.SavegamePathfinderEdition = LatestPathfinderEdition;

return filter;
}
Expand Down
3 changes: 2 additions & 1 deletion TLM/TLM/Lifecycle/TMPELifecycle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ private static void CompatibilityCheck() {
}

internal void Preload() {
SavedGameOptions.Release();
Patcher.InstallPreload();
Asset2Data = new Dictionary<BuildingInfo, AssetData>();
Log.Info("Preloading Managers");
Expand Down Expand Up @@ -343,7 +344,7 @@ internal void Load() {

internal void Unload() {
try {
Options.Available = false;
SavedGameOptions.Release();

GeometryNotifierDisposable?.Dispose();
GeometryNotifierDisposable = null;
Expand Down
2 changes: 1 addition & 1 deletion TLM/TLM/Lifecycle/ThreadingExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public override void OnBeforeSimulationTick() {
public override void OnBeforeSimulationFrame() {
base.OnBeforeSimulationFrame();

if (Options.timedLightsEnabled) {
if (SavedGameOptions.Instance.timedLightsEnabled) {
TrafficLightSimulationManager.Instance.SimulationStep();
}
}
Expand Down
3 changes: 2 additions & 1 deletion TLM/TLM/Lifecycle/TrafficManagerMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public void OnSettingsUI(UIHelper helper) {
// Note: This bugs out if done in OnEnabled(), hence doing it here instead.
LocaleManager.eventLocaleChanged -= Translation.HandleGameLocaleChange;
LocaleManager.eventLocaleChanged += Translation.HandleGameLocaleChange;
Options.MakeSettings(helper);
SavedGameOptions.Ensure();
TMPESettings.MakeSettings(helper);
}

public void OnCreated(ILoading loading) { }
Expand Down
10 changes: 5 additions & 5 deletions TLM/TLM/Manager/Impl/AdvancedParkingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2415,12 +2415,12 @@ bool LoopHandler(int i, int j) {
out _))
{
NetInfo.Lane laneInfo = segmentInfo.m_lanes[laneIndex];
if (!Options.parkingRestrictionsEnabled ||
if (!SavedGameOptions.Instance.parkingRestrictionsEnabled ||
ParkingRestrictionsManager.Instance.IsParkingAllowed(
segmentId,
laneInfo.m_finalDirection))
{
if (!Options.vehicleRestrictionsEnabled ||
if (!SavedGameOptions.Instance.vehicleRestrictionsEnabled ||
(VehicleRestrictionsManager.Instance.GetAllowedVehicleTypes(
segmentId,
segmentInfo,
Expand Down Expand Up @@ -2658,7 +2658,7 @@ public bool FindParkingSpacePropAtBuilding(VehicleInfo vehicleInfo,
var result = false;

if (buildingInfo.m_class.m_service == ItemClass.Service.Residential &&
buildingId != homeId && rng.Int32((uint)Options.getRecklessDriverModulo()) != 0) {
buildingId != homeId && rng.Int32((uint)SavedGameOptions.Instance.getRecklessDriverModulo()) != 0) {
// NON-STOCK CODE
return false;
}
Expand Down Expand Up @@ -2830,7 +2830,7 @@ public bool FindParkingSpaceRoadSideForVehiclePos(VehicleInfo vehicleInfo,
out laneIndex,
out parkOffset))
{
if (!Options.parkingRestrictionsEnabled ||
if (!SavedGameOptions.Instance.parkingRestrictionsEnabled ||
ParkingRestrictionsManager.Instance.IsParkingAllowed(
segmentId,
netSegment.Info.m_lanes[laneIndex].m_finalDirection))
Expand Down Expand Up @@ -2936,7 +2936,7 @@ public bool VanillaFindParkingSpaceWithoutRestrictions(bool isElectric,
}

// in vanilla parkOffset is always >= 0 for RoadSideParkingSpace
if (Options.parkingRestrictionsEnabled && parkOffset >= 0) {
if (SavedGameOptions.Instance.parkingRestrictionsEnabled && parkOffset >= 0) {
if (netSegment.GetClosestLanePosition(
refPos,
NetInfo.LaneType.Parking,
Expand Down
2 changes: 1 addition & 1 deletion TLM/TLM/Manager/Impl/ExtBuildingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private ExtBuildingManager() {

public void OnBeforeSimulationStep(ushort buildingId, ref Building data) {
// slowly decrease parking space demand / public transport demand if Parking AI is active
if (!Options.parkingAI) {
if (!SavedGameOptions.Instance.parkingAI) {
return;
}

Expand Down
Loading