Skip to content

Commit

Permalink
Fixed #168: Prohibiting cims from crossing the road also affect paths…
Browse files Browse the repository at this point in the history
… where crossing is unnecessary

Fixed #183: Parking AI causes unnecessary path-findings
  • Loading branch information
VictorPhilipp committed Jul 14, 2018
1 parent 7ff2fae commit 529ca64
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 1,313 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ A modification for **Cities: Skylines** to add additional traffic control.
User manual: http://www.viathinksoft.de/tmpe/wiki

# Changelog
1.10.10, 07/14/2018
- Bugfix: Parking AI causes unnecessary path-findings (#183, thanks to Sipke82 for reporting)
- Bugfix: Prohibiting cims from crossing the road also affect paths where crossing is unnecessary (#168, thanks to aubergine10 for reporting)

1.10.9, 07/13/2018
- Updated for game version 1.10.1-f3
- Re-implemented path-finding algorithm
Expand Down
49 changes: 40 additions & 9 deletions TLM/TLM/Custom/AI/CustomCitizenAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,45 @@ public bool ExtStartPathFind(ushort instanceID, ref CitizenInstance instanceData
vehicleInfo = null;
}

bool startAtRoadConnection = false;
if (Options.prohibitPocketCars) {
ItemClass.Service sourceBuildingService = Singleton<BuildingManager>.instance.m_buildings.m_buffer[instanceData.m_sourceBuilding].Info.m_class.m_service;
bool isAtNonRoadOutsideConnection = Constants.ManagerFactory.ExtCitizenInstanceManager.IsAtOutsideConnection(instanceID, ref instanceData, ref citizenManager.m_citizens.m_buffer[instanceData.m_citizen]) && sourceBuildingService != ItemClass.Service.Road;

/*
* force car usage if citizen is at a road outside connection,
* probibit car usage if citizen is at a non-road outside connection
*/
if (Constants.ManagerFactory.ExtCitizenInstanceManager.IsAtOutsideConnection(instanceID, ref instanceData, ref citizenManager.m_citizens.m_buffer[instanceData.m_citizen])) {
if (sourceBuildingService == ItemClass.Service.Road) {
if (instanceData.Info.m_agePhase > Citizen.AgePhase.Child && !ignoreCost && !isOnWalkingTour) {
#if DEBUG
if (debug)
Log._Debug($"CustomCitizenAI.ExtStartPathFind({instanceID}): Is citizen at a non-road outside connection? {isAtNonRoadOutsideConnection} ({sourceBuildingService})");
if (debug)
Log._Debug($"CustomCitizenAI.ExtStartPathFind({instanceID}): Citizen is located at a road outside connection: Setting path mode to 'RequiresCarPath'");
#endif

// disallow car usage if citizen is on a walking tour
if (ignoreCost /* = we are a mascot */ || isAtNonRoadOutsideConnection || isOnWalkingTour) {
carUsageMode = CarUsagePolicy.Forbidden;
extInstance.pathMode = ExtPathMode.RequiresCarPath;
startAtRoadConnection = true;
} else {
#if DEBUG
if (debug)
Log._Debug($"CustomCitizenAI.ExtStartPathFind({instanceID}): Citizen is located at a road outside connection but is not allowed to use a car (agePhase={instanceData.Info.m_agePhase}, ignoreCost={ignoreCost}, isOnWalkingTour={isOnWalkingTour}): ABORTING PATH-FINDING");
#endif
extInstance.Reset();
return false;
}
} else {
#if DEBUG
if (debug)
Log._Debug($"CustomCitizenAI.ExtStartPathFind({instanceID}): Citizen is located at a non-road outside connection: Setting path mode to 'RequiresWalkingPathToTarget'");
#endif
extInstance.pathMode = ExtPathMode.RequiresWalkingPathToTarget;
}
} else if (ignoreCost /* = we are a mascot */ || isOnWalkingTour) {
// disallow car usage if citizen is a mascot or on a walking tour
#if DEBUG
if (debug)
Log._Debug($"CustomCitizenAI.ExtStartPathFind({instanceID}): Citizen ignores cost ({ignoreCost}) or is on a walking tour ({isOnWalkingTour}): Setting path mode to 'RequiresWalkingPathToTarget'");
#endif
extInstance.pathMode = ExtPathMode.RequiresWalkingPathToTarget;
}
}

Expand Down Expand Up @@ -100,7 +128,7 @@ public bool ExtStartPathFind(ushort instanceID, ref CitizenInstance instanceData
case ExtPathMode.CalculatingCarPathToAltParkPos:
case ExtPathMode.CalculatingCarPathToKnownParkPos:
case ExtPathMode.CalculatingCarPathToTarget:
if (parkedVehicleId == 0 || carUsageMode == CarUsagePolicy.Forbidden) {
if (!startAtRoadConnection && (parkedVehicleId == 0 || carUsageMode == CarUsagePolicy.Forbidden)) {
// parked vehicle not present or citizen is on a walking tour

#if DEBUG
Expand Down Expand Up @@ -287,7 +315,10 @@ public bool ExtStartPathFind(ushort instanceID, ref CitizenInstance instanceData
Log._Debug($"CustomCitizenAI.ExtStartPathFind({instanceID}): Setting startPos={startPos} for citizen instance {instanceID}. CurrentDepartureMode={extInstance.pathMode}");
#endif

if (instanceData.m_targetBuilding == 0 || (Singleton<BuildingManager>.instance.m_buildings.m_buffer[instanceData.m_targetBuilding].m_flags & Building.Flags.IncomingOutgoing) == Building.Flags.None) {
if (
instanceData.m_targetBuilding == 0 ||
(Singleton<BuildingManager>.instance.m_buildings.m_buffer[instanceData.m_targetBuilding].m_flags & Building.Flags.IncomingOutgoing) == Building.Flags.None
) {
/*
* the citizen is starting their journey and the target is not an outside connection
* -> find a suitable parking space near the target
Expand Down
2 changes: 1 addition & 1 deletion TLM/TLM/Custom/PathFinding/CustomPathFind2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1454,7 +1454,7 @@ private void ProcessItemPedBicycle(BufferItem item, ref NetSegment prevSegment,
bool nextIsStartNode = nextNodeId == nextSegment.m_startNode;
if (nextIsStartNode || nextNodeId == nextSegment.m_endNode) {
#if JUNCTIONRESTRICTIONS
if (Options.junctionRestrictionsEnabled) {
if (Options.junctionRestrictionsEnabled && item.m_position.m_segment == nextSegmentId) {
// check if pedestrians are not allowed to cross here
if (!m_junctionManager.IsPedestrianCrossingAllowed(nextSegmentId, nextIsStartNode)) {
return;
Expand Down
Loading

0 comments on commit 529ca64

Please sign in to comment.