Skip to content

Commit 3f4e22e

Browse files
committed
Version 1.7.5:
- Bugfix: AI: Cims were using pocket cars whenever possible - Bugfix: AI: Path-finding failures led to much less vehicles spawning - Bugfix: AI: Lane selection at junctions with custom lane connection was not always working properly (e.g. for Network Extensions roads with middle lane) - Bugfix: While editing a timed traffic light it could happen that the traffic light was deleted
1 parent 3624aa8 commit 3f4e22e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+2126
-1111
lines changed

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,23 @@
22
A work-in-progress modification for **Cities: Skylines** to add additional traffic control
33

44
# Changelog
5+
1.7.5, 08/07/2016:
6+
- Bugfix: AI: Cims were using pocket cars whenever possible
7+
- Bugfix: AI: Path-finding failures led to much less vehicles spawning
8+
- Bugfix: AI: Lane selection at junctions with custom lane connection was not always working properly (e.g. for Network Extensions roads with middle lane)
9+
- Bugfix: While editing a timed traffic light it could happen that the traffic light was deleted
10+
11+
1.7.4, 07/31/2016:
12+
- AI: Switched from relative to absolute traffic density measurement
13+
- AI: Tuned new parameters
14+
- Bugfix: Activated/Disabled features were not loaded correctly
15+
- Bugfix: AI: At specific junctions the lane changer did not work as intended
16+
- Possible fix for OSX performance issues
17+
- Code improvements
18+
- Added French translations (thanks to @simon.royer007 for translating!)
19+
520
1.7.3, 07/29/2016:
6-
- Added the possibility to enable/disable mod features (e.g. for performance reasons)
21+
- Added the ability to enable/disable mod features (e.g. for performance reasons)
722
- Bugfix: Vehicle type determination was incorrect (fixed u-turning trams/trains, stuck vehicles)
823
- Bugfix: Clicking on a train/tram node with the lane connector tool led to an uncorrectable error (thanks to @noaccount for reporting this problem)
924
- Further code improvements

TLM/TLM/Custom/AI/CustomAmbulanceAI.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,18 @@
44
using System.Linq;
55
using System.Text;
66
using TrafficManager.Custom.PathFinding;
7+
using TrafficManager.Geometry;
8+
using TrafficManager.Manager;
79
using TrafficManager.Traffic;
810
using UnityEngine;
911

1012
namespace TrafficManager.Custom.AI {
1113
class CustomAmbulanceAI : CarAI {
1214
public bool CustomStartPathFind(ushort vehicleID, ref Vehicle vehicleData, Vector3 startPos, Vector3 endPos, bool startBothWays, bool endBothWays, bool undergroundTarget) {
15+
#if DEBUG
16+
//Log._Debug($"CustomAmbulanceAI.CustomStartPathFind called for vehicle {vehicleID}");
17+
#endif
18+
1319
ExtVehicleType vehicleType = (vehicleData.m_flags & Vehicle.Flags.Emergency2) != 0 ? ExtVehicleType.Emergency : ExtVehicleType.Service;
1420
VehicleStateManager.Instance()._GetVehicleState(vehicleID).VehicleType = vehicleType;
1521

@@ -32,7 +38,12 @@ public bool CustomStartPathFind(ushort vehicleID, ref Vehicle vehicleData, Vecto
3238
endPosB = default(PathUnit.Position);
3339
}
3440
uint path;
35-
if (Singleton<CustomPathManager>.instance.CreatePath(vehicleType, out path, ref Singleton<SimulationManager>.instance.m_randomizer, Singleton<SimulationManager>.instance.m_currentBuildIndex, startPosA, startPosB, endPosA, endPosB, NetInfo.LaneType.Vehicle | NetInfo.LaneType.TransportVehicle, info.m_vehicleType, 20000f, this.IsHeavyVehicle(), this.IgnoreBlocked(vehicleID, ref vehicleData), false, false)) {
41+
if (Singleton<CustomPathManager>.instance.CreatePath(vehicleType, vehicleID, out path, ref Singleton<SimulationManager>.instance.m_randomizer, Singleton<SimulationManager>.instance.m_currentBuildIndex, startPosA, startPosB, endPosA, endPosB, NetInfo.LaneType.Vehicle | NetInfo.LaneType.TransportVehicle, info.m_vehicleType, 20000f, this.IsHeavyVehicle(), this.IgnoreBlocked(vehicleID, ref vehicleData), false, false)) {
42+
#if USEPATHWAITCOUNTER
43+
VehicleState state = VehicleStateManager.Instance()._GetVehicleState(vehicleID);
44+
state.PathWaitCounter = 0;
45+
#endif
46+
3647
if (vehicleData.m_path != 0u) {
3748
Singleton<PathManager>.instance.ReleasePath(vehicleData.m_path);
3849
}

TLM/TLM/Custom/AI/CustomBusAI.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,23 @@
66
using System.Linq;
77
using System.Text;
88
using TrafficManager.Custom.PathFinding;
9+
using TrafficManager.Geometry;
10+
using TrafficManager.Manager;
911
using TrafficManager.Traffic;
1012
using UnityEngine;
1113

1214
namespace TrafficManager.Custom.AI {
1315
class CustomBusAI : CarAI {
1416
public bool CustomStartPathFind(ushort vehicleID, ref Vehicle vehicleData, Vector3 startPos, Vector3 endPos, bool startBothWays, bool endBothWays, bool undergroundTarget) {
17+
#if DEBUG
18+
//Log._Debug($"CustomBusAI.CustomStartPathFind called for vehicle {vehicleID}");
19+
#endif
20+
1521
#if PATHRECALC
1622
VehicleState state = VehicleStateManager._GetVehicleState(vehicleID);
1723
bool recalcRequested = state.PathRecalculationRequested;
1824
state.PathRecalculationRequested = false;
1925
#endif
20-
VehicleStateManager.Instance()._GetVehicleState(vehicleID).VehicleType = ExtVehicleType.Bus;
21-
2226
VehicleInfo info = this.m_info;
2327
bool allowUnderground = (vehicleData.m_flags & (Vehicle.Flags.Underground | Vehicle.Flags.Transition)) != 0;
2428
PathUnit.Position startPosA;
@@ -42,7 +46,12 @@ public bool CustomStartPathFind(ushort vehicleID, ref Vehicle vehicleData, Vecto
4246
#if PATHRECALC
4347
recalcRequested,
4448
#endif
45-
ExtVehicleType.Bus, out path, ref Singleton<SimulationManager>.instance.m_randomizer, Singleton<SimulationManager>.instance.m_currentBuildIndex, startPosA, startPosB, endPosA, endPosB, NetInfo.LaneType.Vehicle | NetInfo.LaneType.TransportVehicle, info.m_vehicleType, 20000f, this.IsHeavyVehicle(), this.IgnoreBlocked(vehicleID, ref vehicleData), false, false)) {
49+
ExtVehicleType.Bus, vehicleID, out path, ref Singleton<SimulationManager>.instance.m_randomizer, Singleton<SimulationManager>.instance.m_currentBuildIndex, startPosA, startPosB, endPosA, endPosB, NetInfo.LaneType.Vehicle | NetInfo.LaneType.TransportVehicle, info.m_vehicleType, 20000f, this.IsHeavyVehicle(), this.IgnoreBlocked(vehicleID, ref vehicleData), false, false)) {
50+
#if USEPATHWAITCOUNTER
51+
VehicleState state = VehicleStateManager.Instance()._GetVehicleState(vehicleID);
52+
state.PathWaitCounter = 0;
53+
#endif
54+
4655
if (vehicleData.m_path != 0u) {
4756
Singleton<PathManager>.instance.ReleasePath(vehicleData.m_path);
4857
}

TLM/TLM/Custom/AI/CustomCarAI.cs

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
using System.Collections.Generic;
77
using ColossalFramework;
88
using ColossalFramework.Math;
9-
using TrafficManager.Traffic;
9+
using TrafficManager.Geometry;
1010
using TrafficManager.TrafficLight;
1111
using UnityEngine;
1212
using Random = UnityEngine.Random;
1313
using TrafficManager.Custom.PathFinding;
1414
using TrafficManager.State;
15+
using TrafficManager.Manager;
16+
using TrafficManager.Traffic;
1517

1618
namespace TrafficManager.Custom.AI {
1719
public class CustomCarAI : CarAI { // correct would be to inherit from VehicleAI (in order to keep the correct references to `base`)
@@ -31,38 +33,31 @@ internal static void OnLevelUnloading() {
3133
/// <param name="vehicleData"></param>
3234
/// <param name="physicsLodRefPos"></param>
3335
public void CustomSimulationStep(ushort vehicleId, ref Vehicle vehicleData, Vector3 physicsLodRefPos) {
34-
#if USEPATHWAITCOUNTER
35-
VehicleState state = VehicleStateManager._GetVehicleState(vehicleId);
36-
#endif
37-
3836
PathManager pathMan = Singleton<PathManager>.instance;
3937
#if DEBUG
40-
if (!Options.disableSomething1) {
38+
/*if (!Options.disableSomething1) {
4139
Log._Debug($"CustomCarAI.CustomSimulationStep({vehicleId}) called. flags: {vehicleData.m_flags} pfFlags: {pathMan.m_pathUnits.m_buffer[vehicleData.m_path].m_pathFindFlags}");
42-
}
40+
}*/
4341
#endif
4442

4543
if ((vehicleData.m_flags & Vehicle.Flags.WaitingPath) != 0) {
4644
PathManager pathManager = Singleton<PathManager>.instance;
4745
byte pathFindFlags = pathManager.m_pathUnits.m_buffer[vehicleData.m_path].m_pathFindFlags;
48-
if ((pathFindFlags & PathUnit.FLAG_READY) != 0) {
4946

5047
#if USEPATHWAITCOUNTER
48+
if ((pathFindFlags & (PathUnit.FLAG_READY | PathUnit.FLAG_FAILED)) != 0) {
49+
VehicleState state = VehicleStateManager.Instance()._GetVehicleState(vehicleId);
5150
state.PathWaitCounter = 0; // NON-STOCK CODE
51+
}
5252
#endif
53+
54+
if ((pathFindFlags & PathUnit.FLAG_READY) != 0) {
5355
vehicleData.m_pathPositionIndex = 255;
5456
vehicleData.m_flags &= ~Vehicle.Flags.WaitingPath;
5557
vehicleData.m_flags &= ~Vehicle.Flags.Arriving;
5658
this.PathfindSuccess(vehicleId, ref vehicleData);
5759
this.TrySpawn(vehicleId, ref vehicleData);
58-
} else if ((pathFindFlags & PathUnit.FLAG_FAILED) != 0 || vehicleData.m_path == 0
59-
#if USEPATHWAITCOUNTER
60-
|| ((pathFindFlags & PathUnit.FLAG_CREATED) != 0 && state.PathWaitCounter == ushort.MaxValue)
61-
#endif
62-
) { // NON-STOCK CODE
63-
#if USEPATHWAITCOUNTER
64-
state.PathWaitCounter = 0; // NON-STOCK CODE
65-
#endif
60+
} else if ((pathFindFlags & PathUnit.FLAG_FAILED) != 0 || vehicleData.m_path == 0) { // path == 0: non-stock code!
6661
vehicleData.m_flags &= ~Vehicle.Flags.WaitingPath;
6762
Singleton<PathManager>.instance.ReleasePath(vehicleData.m_path);
6863
vehicleData.m_path = 0u;
@@ -71,13 +66,11 @@ public void CustomSimulationStep(ushort vehicleId, ref Vehicle vehicleData, Vect
7166
}
7267
#if USEPATHWAITCOUNTER
7368
else {
69+
VehicleState state = VehicleStateManager.Instance()._GetVehicleState(vehicleId);
7470
state.PathWaitCounter = (ushort)Math.Min(ushort.MaxValue, (int)state.PathWaitCounter+1); // NON-STOCK CODE
7571
}
7672
#endif
7773
} else {
78-
#if USEPATHWAITCOUNTER
79-
state.PathWaitCounter = 0; // NON-STOCK CODE
80-
#endif
8174
if ((vehicleData.m_flags & Vehicle.Flags.WaitingSpace) != 0) {
8275
this.TrySpawn(vehicleId, ref vehicleData);
8376
}
@@ -134,7 +127,7 @@ public void CustomSimulationStep(ushort vehicleId, ref Vehicle vehicleData, Vect
134127
int maxBlockCounter = (privateServiceIndex == -1) ? 150 : 100;
135128
if ((vehicleData.m_flags & (Vehicle.Flags.Spawned | Vehicle.Flags.WaitingPath | Vehicle.Flags.WaitingSpace)) == 0 && vehicleData.m_cargoParent == 0) {
136129
Singleton<VehicleManager>.instance.ReleaseVehicle(vehicleId);
137-
} else if ((int)vehicleData.m_blockCounter == maxBlockCounter && Options.enableDespawning) {
130+
} else if ((int)vehicleData.m_blockCounter >= maxBlockCounter && Options.enableDespawning) {
138131
Singleton<VehicleManager>.instance.ReleaseVehicle(vehicleId);
139132
}
140133
#if PATHRECALC
@@ -146,6 +139,12 @@ public void CustomSimulationStep(ushort vehicleId, ref Vehicle vehicleData, Vect
146139
}
147140

148141
public override bool TrySpawn(ushort vehicleID, ref Vehicle vehicleData) {
142+
// NON-STOCK CODE START
143+
if (Options.prioritySignsEnabled || Options.timedLightsEnabled) {
144+
VehicleStateManager.Instance().OnBeforeSpawnVehicle(vehicleID, ref vehicleData);
145+
}
146+
// NON-STOCK CODE END
147+
149148
if ((vehicleData.m_flags & Vehicle.Flags.Spawned) != (Vehicle.Flags)0) {
150149
return true;
151150
}
@@ -156,12 +155,6 @@ public override bool TrySpawn(ushort vehicleID, ref Vehicle vehicleData) {
156155
vehicleData.Spawn(vehicleID);
157156
vehicleData.m_flags &= ~Vehicle.Flags.WaitingSpace;
158157

159-
// NON-STOCK CODE START
160-
if (Options.prioritySignsEnabled || Options.timedLightsEnabled) {
161-
VehicleStateManager.Instance().OnVehicleSpawned(vehicleID, ref vehicleData);
162-
}
163-
// NON-STOCK CODE END
164-
165158
return true;
166159
}
167160

@@ -347,6 +340,10 @@ public bool CustomStartPathFind(ushort vehicleID, ref Vehicle vehicleData, Vecto
347340
bool recalcRequested = state.PathRecalculationRequested;
348341
state.PathRecalculationRequested = false;
349342
#endif
343+
#if DEBUG
344+
//Log._Debug($"CustomCarAI.CustomStartPathFind called for vehicle {vehicleID}");
345+
#endif
346+
350347
VehicleInfo info = this.m_info;
351348
bool allowUnderground = (vehicleData.m_flags & (Vehicle.Flags.Underground | Vehicle.Flags.Transition)) != 0;
352349
PathUnit.Position startPosA;
@@ -374,12 +371,17 @@ public bool CustomStartPathFind(ushort vehicleID, ref Vehicle vehicleData, Vecto
374371
vehicleType = ExtVehicleType.RoadVehicle;
375372
}
376373

377-
bool res = Singleton<CustomPathManager>.instance.CreatePath(
374+
if (Singleton<CustomPathManager>.instance.CreatePath(
378375
#if PATHRECALC
379376
recalcRequested,
380377
#endif
381-
(ExtVehicleType)vehicleType, out path, ref Singleton<SimulationManager>.instance.m_randomizer, Singleton<SimulationManager>.instance.m_currentBuildIndex, startPosA, startPosB, endPosA, endPosB, NetInfo.LaneType.Vehicle, info.m_vehicleType, 20000f, this.IsHeavyVehicle(), this.IgnoreBlocked(vehicleID, ref vehicleData), false, false);
382-
if (res) {
378+
(ExtVehicleType)vehicleType, vehicleID, out path, ref Singleton<SimulationManager>.instance.m_randomizer, Singleton<SimulationManager>.instance.m_currentBuildIndex, startPosA, startPosB, endPosA, endPosB, NetInfo.LaneType.Vehicle, info.m_vehicleType, 20000f, this.IsHeavyVehicle(), this.IgnoreBlocked(vehicleID, ref vehicleData), false, false)) {
379+
380+
#if USEPATHWAITCOUNTER
381+
VehicleState state = VehicleStateManager.Instance()._GetVehicleState(vehicleID);
382+
state.PathWaitCounter = 0;
383+
#endif
384+
383385
if (vehicleData.m_path != 0u) {
384386
Singleton<PathManager>.instance.ReleasePath(vehicleData.m_path);
385387
}

TLM/TLM/Custom/AI/CustomCargoTruckAI.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
using ColossalFramework;
55
using UnityEngine;
66
using TrafficManager.State;
7-
using TrafficManager.Traffic;
7+
using TrafficManager.Geometry;
88
using TrafficManager.Custom.PathFinding;
9+
using TrafficManager.Traffic;
10+
using TrafficManager.Manager;
911

1012
namespace TrafficManager.Custom.AI {
1113
public class CustomCargoTruckAI : CarAI {
@@ -44,12 +46,14 @@ private static void RemoveOffers(ushort vehicleId, ref Vehicle data) {
4446
}
4547

4648
public bool CustomStartPathFind(ushort vehicleID, ref Vehicle vehicleData, Vector3 startPos, Vector3 endPos, bool startBothWays, bool endBothWays, bool undergroundTarget) {
49+
#if DEBUG
50+
//Log._Debug($"CustomCargoTruckAI.CustomStartPathFind called for vehicle {vehicleID}");
51+
#endif
52+
4753
if ((vehicleData.m_flags & (Vehicle.Flags.TransferToSource | Vehicle.Flags.GoingBack)) != 0) {
4854
return base.StartPathFind(vehicleID, ref vehicleData, startPos, endPos, startBothWays, endBothWays, undergroundTarget);
4955
}
5056

51-
VehicleStateManager.Instance()._GetVehicleState(vehicleID).VehicleType = ExtVehicleType.CargoTruck;
52-
5357
bool allowUnderground = (vehicleData.m_flags & (Vehicle.Flags.Underground | Vehicle.Flags.Transition)) != 0;
5458
PathUnit.Position startPosA;
5559
PathUnit.Position startPosB;
@@ -98,7 +102,12 @@ public bool CustomStartPathFind(ushort vehicleID, ref Vehicle vehicleData, Vecto
98102
NetInfo.LaneType laneTypes = NetInfo.LaneType.Vehicle | NetInfo.LaneType.CargoVehicle;
99103
VehicleInfo.VehicleType vehicleTypes = VehicleInfo.VehicleType.Car | VehicleInfo.VehicleType.Train | VehicleInfo.VehicleType.Ship;
100104
uint path;
101-
if (instance.CreatePath(ExtVehicleType.CargoVehicle, out path, ref Singleton<SimulationManager>.instance.m_randomizer, Singleton<SimulationManager>.instance.m_currentBuildIndex, startPosA, startPosB, endPosA, endPosB, laneTypes, vehicleTypes, 20000f, this.IsHeavyVehicle(), this.IgnoreBlocked(vehicleID, ref vehicleData), false, false)) {
105+
if (instance.CreatePath(ExtVehicleType.CargoVehicle, vehicleID, out path, ref Singleton<SimulationManager>.instance.m_randomizer, Singleton<SimulationManager>.instance.m_currentBuildIndex, startPosA, startPosB, endPosA, endPosB, laneTypes, vehicleTypes, 20000f, this.IsHeavyVehicle(), this.IgnoreBlocked(vehicleID, ref vehicleData), false, false)) {
106+
#if USEPATHWAITCOUNTER
107+
VehicleState state = VehicleStateManager.Instance()._GetVehicleState(vehicleID);
108+
state.PathWaitCounter = 0;
109+
#endif
110+
102111
if (vehicleData.m_path != 0u) {
103112
instance.ReleasePath(vehicleData.m_path);
104113
}

0 commit comments

Comments
 (0)