Skip to content

Commit

Permalink
Version 1.7.5:
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
VictorPhilipp committed Aug 11, 2016
1 parent 3624aa8 commit 3f4e22e
Show file tree
Hide file tree
Showing 62 changed files with 2,126 additions and 1,111 deletions.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,23 @@
A work-in-progress modification for **Cities: Skylines** to add additional traffic control

# Changelog
1.7.5, 08/07/2016:
- 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.7.4, 07/31/2016:
- AI: Switched from relative to absolute traffic density measurement
- AI: Tuned new parameters
- Bugfix: Activated/Disabled features were not loaded correctly
- Bugfix: AI: At specific junctions the lane changer did not work as intended
- Possible fix for OSX performance issues
- Code improvements
- Added French translations (thanks to @simon.royer007 for translating!)

1.7.3, 07/29/2016:
- Added the possibility to enable/disable mod features (e.g. for performance reasons)
- Added the ability to enable/disable mod features (e.g. for performance reasons)
- Bugfix: Vehicle type determination was incorrect (fixed u-turning trams/trains, stuck vehicles)
- Bugfix: Clicking on a train/tram node with the lane connector tool led to an uncorrectable error (thanks to @noaccount for reporting this problem)
- Further code improvements
Expand Down
13 changes: 12 additions & 1 deletion TLM/TLM/Custom/AI/CustomAmbulanceAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@
using System.Linq;
using System.Text;
using TrafficManager.Custom.PathFinding;
using TrafficManager.Geometry;
using TrafficManager.Manager;
using TrafficManager.Traffic;
using UnityEngine;

namespace TrafficManager.Custom.AI {
class CustomAmbulanceAI : CarAI {
public bool CustomStartPathFind(ushort vehicleID, ref Vehicle vehicleData, Vector3 startPos, Vector3 endPos, bool startBothWays, bool endBothWays, bool undergroundTarget) {
#if DEBUG
//Log._Debug($"CustomAmbulanceAI.CustomStartPathFind called for vehicle {vehicleID}");
#endif

ExtVehicleType vehicleType = (vehicleData.m_flags & Vehicle.Flags.Emergency2) != 0 ? ExtVehicleType.Emergency : ExtVehicleType.Service;
VehicleStateManager.Instance()._GetVehicleState(vehicleID).VehicleType = vehicleType;

Expand All @@ -32,7 +38,12 @@ public bool CustomStartPathFind(ushort vehicleID, ref Vehicle vehicleData, Vecto
endPosB = default(PathUnit.Position);
}
uint path;
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)) {
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)) {
#if USEPATHWAITCOUNTER
VehicleState state = VehicleStateManager.Instance()._GetVehicleState(vehicleID);
state.PathWaitCounter = 0;
#endif

if (vehicleData.m_path != 0u) {
Singleton<PathManager>.instance.ReleasePath(vehicleData.m_path);
}
Expand Down
15 changes: 12 additions & 3 deletions TLM/TLM/Custom/AI/CustomBusAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,23 @@
using System.Linq;
using System.Text;
using TrafficManager.Custom.PathFinding;
using TrafficManager.Geometry;
using TrafficManager.Manager;
using TrafficManager.Traffic;
using UnityEngine;

namespace TrafficManager.Custom.AI {
class CustomBusAI : CarAI {
public bool CustomStartPathFind(ushort vehicleID, ref Vehicle vehicleData, Vector3 startPos, Vector3 endPos, bool startBothWays, bool endBothWays, bool undergroundTarget) {
#if DEBUG
//Log._Debug($"CustomBusAI.CustomStartPathFind called for vehicle {vehicleID}");
#endif

#if PATHRECALC
VehicleState state = VehicleStateManager._GetVehicleState(vehicleID);
bool recalcRequested = state.PathRecalculationRequested;
state.PathRecalculationRequested = false;
#endif
VehicleStateManager.Instance()._GetVehicleState(vehicleID).VehicleType = ExtVehicleType.Bus;

VehicleInfo info = this.m_info;
bool allowUnderground = (vehicleData.m_flags & (Vehicle.Flags.Underground | Vehicle.Flags.Transition)) != 0;
PathUnit.Position startPosA;
Expand All @@ -42,7 +46,12 @@ public bool CustomStartPathFind(ushort vehicleID, ref Vehicle vehicleData, Vecto
#if PATHRECALC
recalcRequested,
#endif
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)) {
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)) {
#if USEPATHWAITCOUNTER
VehicleState state = VehicleStateManager.Instance()._GetVehicleState(vehicleID);
state.PathWaitCounter = 0;
#endif

if (vehicleData.m_path != 0u) {
Singleton<PathManager>.instance.ReleasePath(vehicleData.m_path);
}
Expand Down
60 changes: 31 additions & 29 deletions TLM/TLM/Custom/AI/CustomCarAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
using System.Collections.Generic;
using ColossalFramework;
using ColossalFramework.Math;
using TrafficManager.Traffic;
using TrafficManager.Geometry;
using TrafficManager.TrafficLight;
using UnityEngine;
using Random = UnityEngine.Random;
using TrafficManager.Custom.PathFinding;
using TrafficManager.State;
using TrafficManager.Manager;
using TrafficManager.Traffic;

namespace TrafficManager.Custom.AI {
public class CustomCarAI : CarAI { // correct would be to inherit from VehicleAI (in order to keep the correct references to `base`)
Expand All @@ -31,38 +33,31 @@ internal static void OnLevelUnloading() {
/// <param name="vehicleData"></param>
/// <param name="physicsLodRefPos"></param>
public void CustomSimulationStep(ushort vehicleId, ref Vehicle vehicleData, Vector3 physicsLodRefPos) {
#if USEPATHWAITCOUNTER
VehicleState state = VehicleStateManager._GetVehicleState(vehicleId);
#endif

PathManager pathMan = Singleton<PathManager>.instance;
#if DEBUG
if (!Options.disableSomething1) {
/*if (!Options.disableSomething1) {
Log._Debug($"CustomCarAI.CustomSimulationStep({vehicleId}) called. flags: {vehicleData.m_flags} pfFlags: {pathMan.m_pathUnits.m_buffer[vehicleData.m_path].m_pathFindFlags}");
}
}*/
#endif

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

#if USEPATHWAITCOUNTER
if ((pathFindFlags & (PathUnit.FLAG_READY | PathUnit.FLAG_FAILED)) != 0) {
VehicleState state = VehicleStateManager.Instance()._GetVehicleState(vehicleId);
state.PathWaitCounter = 0; // NON-STOCK CODE
}
#endif

if ((pathFindFlags & PathUnit.FLAG_READY) != 0) {
vehicleData.m_pathPositionIndex = 255;
vehicleData.m_flags &= ~Vehicle.Flags.WaitingPath;
vehicleData.m_flags &= ~Vehicle.Flags.Arriving;
this.PathfindSuccess(vehicleId, ref vehicleData);
this.TrySpawn(vehicleId, ref vehicleData);
} else if ((pathFindFlags & PathUnit.FLAG_FAILED) != 0 || vehicleData.m_path == 0
#if USEPATHWAITCOUNTER
|| ((pathFindFlags & PathUnit.FLAG_CREATED) != 0 && state.PathWaitCounter == ushort.MaxValue)
#endif
) { // NON-STOCK CODE
#if USEPATHWAITCOUNTER
state.PathWaitCounter = 0; // NON-STOCK CODE
#endif
} else if ((pathFindFlags & PathUnit.FLAG_FAILED) != 0 || vehicleData.m_path == 0) { // path == 0: non-stock code!
vehicleData.m_flags &= ~Vehicle.Flags.WaitingPath;
Singleton<PathManager>.instance.ReleasePath(vehicleData.m_path);
vehicleData.m_path = 0u;
Expand All @@ -71,13 +66,11 @@ public void CustomSimulationStep(ushort vehicleId, ref Vehicle vehicleData, Vect
}
#if USEPATHWAITCOUNTER
else {
VehicleState state = VehicleStateManager.Instance()._GetVehicleState(vehicleId);
state.PathWaitCounter = (ushort)Math.Min(ushort.MaxValue, (int)state.PathWaitCounter+1); // NON-STOCK CODE
}
#endif
} else {
#if USEPATHWAITCOUNTER
state.PathWaitCounter = 0; // NON-STOCK CODE
#endif
if ((vehicleData.m_flags & Vehicle.Flags.WaitingSpace) != 0) {
this.TrySpawn(vehicleId, ref vehicleData);
}
Expand Down Expand Up @@ -134,7 +127,7 @@ public void CustomSimulationStep(ushort vehicleId, ref Vehicle vehicleData, Vect
int maxBlockCounter = (privateServiceIndex == -1) ? 150 : 100;
if ((vehicleData.m_flags & (Vehicle.Flags.Spawned | Vehicle.Flags.WaitingPath | Vehicle.Flags.WaitingSpace)) == 0 && vehicleData.m_cargoParent == 0) {
Singleton<VehicleManager>.instance.ReleaseVehicle(vehicleId);
} else if ((int)vehicleData.m_blockCounter == maxBlockCounter && Options.enableDespawning) {
} else if ((int)vehicleData.m_blockCounter >= maxBlockCounter && Options.enableDespawning) {
Singleton<VehicleManager>.instance.ReleaseVehicle(vehicleId);
}
#if PATHRECALC
Expand All @@ -146,6 +139,12 @@ public void CustomSimulationStep(ushort vehicleId, ref Vehicle vehicleData, Vect
}

public override bool TrySpawn(ushort vehicleID, ref Vehicle vehicleData) {
// NON-STOCK CODE START
if (Options.prioritySignsEnabled || Options.timedLightsEnabled) {
VehicleStateManager.Instance().OnBeforeSpawnVehicle(vehicleID, ref vehicleData);
}
// NON-STOCK CODE END

if ((vehicleData.m_flags & Vehicle.Flags.Spawned) != (Vehicle.Flags)0) {
return true;
}
Expand All @@ -156,12 +155,6 @@ public override bool TrySpawn(ushort vehicleID, ref Vehicle vehicleData) {
vehicleData.Spawn(vehicleID);
vehicleData.m_flags &= ~Vehicle.Flags.WaitingSpace;

// NON-STOCK CODE START
if (Options.prioritySignsEnabled || Options.timedLightsEnabled) {
VehicleStateManager.Instance().OnVehicleSpawned(vehicleID, ref vehicleData);
}
// NON-STOCK CODE END

return true;
}

Expand Down Expand Up @@ -347,6 +340,10 @@ public bool CustomStartPathFind(ushort vehicleID, ref Vehicle vehicleData, Vecto
bool recalcRequested = state.PathRecalculationRequested;
state.PathRecalculationRequested = false;
#endif
#if DEBUG
//Log._Debug($"CustomCarAI.CustomStartPathFind called for vehicle {vehicleID}");
#endif

VehicleInfo info = this.m_info;
bool allowUnderground = (vehicleData.m_flags & (Vehicle.Flags.Underground | Vehicle.Flags.Transition)) != 0;
PathUnit.Position startPosA;
Expand Down Expand Up @@ -374,12 +371,17 @@ public bool CustomStartPathFind(ushort vehicleID, ref Vehicle vehicleData, Vecto
vehicleType = ExtVehicleType.RoadVehicle;
}

bool res = Singleton<CustomPathManager>.instance.CreatePath(
if (Singleton<CustomPathManager>.instance.CreatePath(
#if PATHRECALC
recalcRequested,
#endif
(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);
if (res) {
(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)) {

#if USEPATHWAITCOUNTER
VehicleState state = VehicleStateManager.Instance()._GetVehicleState(vehicleID);
state.PathWaitCounter = 0;
#endif

if (vehicleData.m_path != 0u) {
Singleton<PathManager>.instance.ReleasePath(vehicleData.m_path);
}
Expand Down
17 changes: 13 additions & 4 deletions TLM/TLM/Custom/AI/CustomCargoTruckAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
using ColossalFramework;
using UnityEngine;
using TrafficManager.State;
using TrafficManager.Traffic;
using TrafficManager.Geometry;
using TrafficManager.Custom.PathFinding;
using TrafficManager.Traffic;
using TrafficManager.Manager;

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

public bool CustomStartPathFind(ushort vehicleID, ref Vehicle vehicleData, Vector3 startPos, Vector3 endPos, bool startBothWays, bool endBothWays, bool undergroundTarget) {
#if DEBUG
//Log._Debug($"CustomCargoTruckAI.CustomStartPathFind called for vehicle {vehicleID}");
#endif

if ((vehicleData.m_flags & (Vehicle.Flags.TransferToSource | Vehicle.Flags.GoingBack)) != 0) {
return base.StartPathFind(vehicleID, ref vehicleData, startPos, endPos, startBothWays, endBothWays, undergroundTarget);
}

VehicleStateManager.Instance()._GetVehicleState(vehicleID).VehicleType = ExtVehicleType.CargoTruck;

bool allowUnderground = (vehicleData.m_flags & (Vehicle.Flags.Underground | Vehicle.Flags.Transition)) != 0;
PathUnit.Position startPosA;
PathUnit.Position startPosB;
Expand Down Expand Up @@ -98,7 +102,12 @@ public bool CustomStartPathFind(ushort vehicleID, ref Vehicle vehicleData, Vecto
NetInfo.LaneType laneTypes = NetInfo.LaneType.Vehicle | NetInfo.LaneType.CargoVehicle;
VehicleInfo.VehicleType vehicleTypes = VehicleInfo.VehicleType.Car | VehicleInfo.VehicleType.Train | VehicleInfo.VehicleType.Ship;
uint path;
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)) {
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)) {
#if USEPATHWAITCOUNTER
VehicleState state = VehicleStateManager.Instance()._GetVehicleState(vehicleID);
state.PathWaitCounter = 0;
#endif

if (vehicleData.m_path != 0u) {
instance.ReleasePath(vehicleData.m_path);
}
Expand Down
Loading

0 comments on commit 3f4e22e

Please sign in to comment.