Skip to content

Commit

Permalink
TMPE 1.10.4-alpha for C:S 1.9.0-beta1
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorPhilipp committed Aug 25, 2017
1 parent a04d6aa commit 8773045
Show file tree
Hide file tree
Showing 26 changed files with 721 additions and 182 deletions.
26 changes: 24 additions & 2 deletions TLM/TLM/Custom/AI/CustomAmbulanceAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using TrafficManager.Traffic;
using TrafficManager.Traffic.Data;
using UnityEngine;
using static TrafficManager.Custom.PathFinding.CustomPathManager;

namespace TrafficManager.Custom.AI {
class CustomAmbulanceAI : CarAI {
Expand Down Expand Up @@ -39,8 +40,29 @@ public bool CustomStartPathFind(ushort vehicleID, ref Vehicle vehicleData, Vecto
}
uint path;
// NON-STOCK CODE START
if (CustomPathManager._instance.CreatePath(vehicleType, vehicleID, ExtCitizenInstance.ExtPathType.None, 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, (vehicleData.m_flags & Vehicle.Flags.Spawned) != 0)) {
// NON-STOCK CODE END
PathCreationArgs args;
args.extPathType = ExtCitizenInstance.ExtPathType.None;
args.extVehicleType = vehicleType;
args.vehicleId = vehicleID;
args.buildIndex = Singleton<SimulationManager>.instance.m_currentBuildIndex;
args.startPosA = startPosA;
args.startPosB = startPosB;
args.endPosA = endPosA;
args.endPosB = endPosB;
args.vehiclePosition = default(PathUnit.Position);
args.laneTypes = NetInfo.LaneType.Vehicle | NetInfo.LaneType.TransportVehicle;
args.vehicleTypes = info.m_vehicleType;
args.maxLength = 20000f;
args.isHeavyVehicle = this.IsHeavyVehicle();
args.hasCombustionEngine = this.CombustionEngine();
args.ignoreBlocked = this.IgnoreBlocked(vehicleID, ref vehicleData);
args.ignoreFlooded = false;
args.randomParking = false;
args.stablePath = false;
args.skipQueue = (vehicleData.m_flags & Vehicle.Flags.Spawned) != 0;

if (CustomPathManager._instance.CreatePath(out path, ref Singleton<SimulationManager>.instance.m_randomizer, args)) {
// NON-STOCK CODE END
if (vehicleData.m_path != 0u) {
Singleton<PathManager>.instance.ReleasePath(vehicleData.m_path);
}
Expand Down
25 changes: 23 additions & 2 deletions TLM/TLM/Custom/AI/CustomBusAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using TrafficManager.Traffic;
using TrafficManager.Traffic.Data;
using UnityEngine;
using static TrafficManager.Custom.PathFinding.CustomPathManager;

namespace TrafficManager.Custom.AI {
class CustomBusAI : CarAI {
Expand Down Expand Up @@ -36,8 +37,28 @@ public bool CustomStartPathFind(ushort vehicleID, ref Vehicle vehicleData, Vecto
}
uint path;
// NON-STOCK CODE START
if (CustomPathManager._instance.CreatePath(
ExtVehicleType.Bus, vehicleID, ExtCitizenInstance.ExtPathType.None, 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), true, true)) {
PathCreationArgs args;
args.extPathType = ExtCitizenInstance.ExtPathType.None;
args.extVehicleType = ExtVehicleType.Bus;
args.vehicleId = vehicleID;
args.buildIndex = Singleton<SimulationManager>.instance.m_currentBuildIndex;
args.startPosA = startPosA;
args.startPosB = startPosB;
args.endPosA = endPosA;
args.endPosB = endPosB;
args.vehiclePosition = default(PathUnit.Position);
args.laneTypes = NetInfo.LaneType.Vehicle | NetInfo.LaneType.TransportVehicle;
args.vehicleTypes = info.m_vehicleType;
args.maxLength = 20000f;
args.isHeavyVehicle = this.IsHeavyVehicle();
args.hasCombustionEngine = this.CombustionEngine();
args.ignoreBlocked = this.IgnoreBlocked(vehicleID, ref vehicleData);
args.ignoreFlooded = false;
args.randomParking = false;
args.stablePath = true;
args.skipQueue = true;

if (CustomPathManager._instance.CreatePath(out path, ref Singleton<SimulationManager>.instance.m_randomizer, args)) {
// NON-STOCK CODE END

if (vehicleData.m_path != 0u) {
Expand Down
24 changes: 23 additions & 1 deletion TLM/TLM/Custom/AI/CustomCarAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using TrafficManager.Traffic.Data;
using static TrafficManager.Traffic.Data.ExtCitizenInstance;
using CSUtil.Commons.Benchmark;
using static TrafficManager.Custom.PathFinding.CustomPathManager;

namespace TrafficManager.Custom.AI {
public class CustomCarAI : CarAI { // TODO inherit from VehicleAI (in order to keep the correct references to `base`)
Expand Down Expand Up @@ -481,7 +482,28 @@ public bool CustomStartPathFind(ushort vehicleID, ref Vehicle vehicleData, Vecto
uint path;

// NON-STOCK CODE START
if (CustomPathManager._instance.CreatePath((ExtVehicleType)vehicleType, vehicleID, ExtCitizenInstance.ExtPathType.None, 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, (vehicleData.m_flags & Vehicle.Flags.Spawned) != 0)) {
PathCreationArgs args;
args.extPathType = ExtCitizenInstance.ExtPathType.None;
args.extVehicleType = vehicleType;
args.vehicleId = vehicleID;
args.buildIndex = Singleton<SimulationManager>.instance.m_currentBuildIndex;
args.startPosA = startPosA;
args.startPosB = startPosB;
args.endPosA = endPosA;
args.endPosB = endPosB;
args.vehiclePosition = default(PathUnit.Position);
args.laneTypes = NetInfo.LaneType.Vehicle | NetInfo.LaneType.TransportVehicle;
args.vehicleTypes = info.m_vehicleType;
args.maxLength = 20000f;
args.isHeavyVehicle = this.IsHeavyVehicle();
args.hasCombustionEngine = this.CombustionEngine();
args.ignoreBlocked = this.IgnoreBlocked(vehicleID, ref vehicleData);
args.ignoreFlooded = false;
args.randomParking = false;
args.stablePath = false;
args.skipQueue = (vehicleData.m_flags & Vehicle.Flags.Spawned) != 0;

if (CustomPathManager._instance.CreatePath(out path, ref Singleton<SimulationManager>.instance.m_randomizer, args)) {
#if DEBUG
if (GlobalConfig.Instance.Debug.Switches[2])
Log._Debug($"CustomCarAI.CustomStartPathFind({vehicleID}): Path-finding starts for vehicle {vehicleID}, path={path}, extVehicleType={vehicleType}, startPosA.segment={startPosA.m_segment}, startPosA.lane={startPosA.m_lane}, info.m_vehicleType={info.m_vehicleType}, endPosA.segment={endPosA.m_segment}, endPosA.lane={endPosA.m_lane}");
Expand Down
26 changes: 25 additions & 1 deletion TLM/TLM/Custom/AI/CustomCargoTruckAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using TrafficManager.Manager.Impl;
using TrafficManager.Traffic.Data;
using CSUtil.Commons.Benchmark;
using static TrafficManager.Custom.PathFinding.CustomPathManager;

namespace TrafficManager.Custom.AI {
public class CustomCargoTruckAI : CarAI {
Expand Down Expand Up @@ -129,7 +130,30 @@ 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 (pathMan.CreatePath(ExtVehicleType.CargoVehicle, vehicleID, ExtCitizenInstance.ExtPathType.None, 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, (vehicleData.m_flags & Vehicle.Flags.Spawned) != 0)) {
// NON-STOCK CODE START
PathCreationArgs args;
args.extPathType = ExtCitizenInstance.ExtPathType.None;
args.extVehicleType = ExtVehicleType.CargoVehicle;
args.vehicleId = vehicleID;
args.buildIndex = Singleton<SimulationManager>.instance.m_currentBuildIndex;
args.startPosA = startPosA;
args.startPosB = startPosB;
args.endPosA = endPosA;
args.endPosB = endPosB;
args.vehiclePosition = default(PathUnit.Position);
args.laneTypes = laneTypes;
args.vehicleTypes = vehicleTypes;
args.maxLength = 20000f;
args.isHeavyVehicle = this.IsHeavyVehicle();
args.hasCombustionEngine = this.CombustionEngine();
args.ignoreBlocked = this.IgnoreBlocked(vehicleID, ref vehicleData);
args.ignoreFlooded = false;
args.randomParking = false;
args.stablePath = false;
args.skipQueue = (vehicleData.m_flags & Vehicle.Flags.Spawned) != 0;

if (pathMan.CreatePath(out path, ref Singleton<SimulationManager>.instance.m_randomizer, args)) {
// NON-STOCK CODE END
if (vehicleData.m_path != 0u) {
pathMan.ReleasePath(vehicleData.m_path);
}
Expand Down
44 changes: 35 additions & 9 deletions TLM/TLM/Custom/AI/CustomCitizenAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using TrafficManager.Traffic.Data;
using static TrafficManager.Traffic.Data.ExtCitizenInstance;
using CSUtil.Commons.Benchmark;
using static TrafficManager.Custom.PathFinding.CustomPathManager;

namespace TrafficManager.Custom.AI {
// TODO move Parking AI features from here to a distinct manager
Expand Down Expand Up @@ -145,15 +146,16 @@ public bool ExtStartPathFind(ushort instanceID, ref CitizenInstance citizenData,
// NON-STOCK CODE END

NetInfo.LaneType laneTypes = NetInfo.LaneType.Pedestrian;
VehicleInfo.VehicleType vehicleType = VehicleInfo.VehicleType.None;
VehicleInfo.VehicleType vehicleTypes = VehicleInfo.VehicleType.None;
bool randomParking = false;
bool combustionEngine = false;
if (vehicleInfo != null) {
if (vehicleInfo.m_class.m_subService == ItemClass.SubService.PublicTransportTaxi) {
if ((citizenData.m_flags & CitizenInstance.Flags.CannotUseTaxi) == CitizenInstance.Flags.None && Singleton<DistrictManager>.instance.m_districts.m_buffer[0].m_productionData.m_finalTaxiCapacity != 0u) {
SimulationManager instance = Singleton<SimulationManager>.instance;
if (instance.m_isNightTime || instance.m_randomizer.Int32(2u) == 0) {
laneTypes |= (NetInfo.LaneType.Vehicle | NetInfo.LaneType.TransportVehicle);
vehicleType |= vehicleInfo.m_vehicleType;
vehicleTypes |= vehicleInfo.m_vehicleType;
extVehicleType = ExtVehicleType.Taxi; // NON-STOCK CODE
// NON-STOCK CODE START
if (Options.prohibitPocketCars) {
Expand All @@ -168,13 +170,14 @@ public bool ExtStartPathFind(ushort instanceID, ref CitizenInstance citizenData,
if (carUsageMode == CarUsagePolicy.Allowed || carUsageMode == CarUsagePolicy.Forced) {
extVehicleType = ExtVehicleType.PassengerCar;
laneTypes |= NetInfo.LaneType.Vehicle;
vehicleType |= vehicleInfo.m_vehicleType;
vehicleTypes |= vehicleInfo.m_vehicleType;
combustionEngine = vehicleInfo.m_class.m_subService == ItemClass.SubService.ResidentialLow;
canUseOwnPassengerCar = true;
}
} else if (vehicleInfo.m_vehicleType == VehicleInfo.VehicleType.Bicycle) {
extVehicleType = ExtVehicleType.Bicycle;
laneTypes |= NetInfo.LaneType.Vehicle;
vehicleType |= vehicleInfo.m_vehicleType;
vehicleTypes |= vehicleInfo.m_vehicleType;
if (citizenData.m_targetBuilding != 0 && Singleton<BuildingManager>.instance.m_buildings.m_buffer[citizenData.m_targetBuilding].Info.m_class.m_service > ItemClass.Service.Office) {
randomParking = true;
}
Expand Down Expand Up @@ -289,14 +292,14 @@ public bool ExtStartPathFind(ushort instanceID, ref CitizenInstance citizenData,
Log._Debug($"CustomCitizenAI.ExtStartPathFind({instanceID}): Requesting path-finding for citizen instance {instanceID}, citizen {citizenData.m_citizen}, extVehicleType={extVehicleType}, extPathType={extPathType}, startPos={startPos}, endPos={endPos}, sourceBuilding={citizenData.m_sourceBuilding}, targetBuilding={citizenData.m_targetBuilding} pathMode={extInstance.pathMode}");
#endif

bool foundEndPos = !calculateEndPos || FindPathPosition(instanceID, ref citizenData, endPos, Options.prohibitPocketCars && (citizenData.m_targetBuilding == 0 || (Singleton<BuildingManager>.instance.m_buildings.m_buffer[citizenData.m_targetBuilding].m_flags & Building.Flags.IncomingOutgoing) == Building.Flags.None) ? NetInfo.LaneType.Pedestrian : (laneTypes | NetInfo.LaneType.Pedestrian), vehicleType, false, out endPosA); // NON-STOCK CODE: with Parking AI enabled, the end position must be a pedestrian position
bool foundEndPos = !calculateEndPos || FindPathPosition(instanceID, ref citizenData, endPos, Options.prohibitPocketCars && (citizenData.m_targetBuilding == 0 || (Singleton<BuildingManager>.instance.m_buildings.m_buffer[citizenData.m_targetBuilding].m_flags & Building.Flags.IncomingOutgoing) == Building.Flags.None) ? NetInfo.LaneType.Pedestrian : (laneTypes | NetInfo.LaneType.Pedestrian), vehicleTypes, false, out endPosA); // NON-STOCK CODE: with Parking AI enabled, the end position must be a pedestrian position
bool foundStartPos = false;
PathUnit.Position startPosA;

if (Options.prohibitPocketCars && (extInstance.pathMode == ExtPathMode.CalculatingCarPathToTarget || extInstance.pathMode == ExtPathMode.CalculatingCarPathToKnownParkPos)) {
foundStartPos = CustomPathManager.FindPathPosition(startPos, ItemClass.Service.Road, laneTypes & ~NetInfo.LaneType.Pedestrian, vehicleType, allowUnderground, false, GlobalConfig.Instance.ParkingAI.MaxBuildingToPedestrianLaneDistance, out startPosA);
foundStartPos = CustomPathManager.FindPathPosition(startPos, ItemClass.Service.Road, laneTypes & ~NetInfo.LaneType.Pedestrian, vehicleTypes, allowUnderground, false, GlobalConfig.Instance.ParkingAI.MaxBuildingToPedestrianLaneDistance, out startPosA);
} else {
foundStartPos = FindPathPosition(instanceID, ref citizenData, startPos, startLaneType, vehicleType, allowUnderground, out startPosA);
foundStartPos = FindPathPosition(instanceID, ref citizenData, startPos, startLaneType, vehicleTypes, allowUnderground, out startPosA);
}

if (foundStartPos && // TODO probably fails if vehicle is parked too far away from road
Expand Down Expand Up @@ -327,12 +330,35 @@ public bool ExtStartPathFind(ushort instanceID, ref CitizenInstance citizenData,

PathUnit.Position dummyPathPos = default(PathUnit.Position);
uint path;
bool res = CustomPathManager._instance.CreatePath(extVehicleType, 0, extPathType, out path, ref Singleton<SimulationManager>.instance.m_randomizer, Singleton<SimulationManager>.instance.m_currentBuildIndex, startPosA, dummyPathPos, endPosA, dummyPathPos, vehiclePosition, laneTypes, vehicleType, 20000f, false, false, false, false, randomParking, false);
// NON-STOCK CODE START
PathCreationArgs args;
args.extPathType = extPathType;
args.extVehicleType = extVehicleType;
args.vehicleId = 0;
args.buildIndex = Singleton<SimulationManager>.instance.m_currentBuildIndex;
args.startPosA = startPosA;
args.startPosB = dummyPathPos;
args.endPosA = endPosA;
args.endPosB = dummyPathPos;
args.vehiclePosition = vehiclePosition;
args.laneTypes = laneTypes;
args.vehicleTypes = vehicleTypes;
args.maxLength = 20000f;
args.isHeavyVehicle = false;
args.hasCombustionEngine = combustionEngine;
args.ignoreBlocked = false;
args.ignoreFlooded = false;
args.randomParking = randomParking;
args.stablePath = false;
args.skipQueue = false;

bool res = CustomPathManager._instance.CreatePath(out path, ref Singleton<SimulationManager>.instance.m_randomizer, args);
// NON-STOCK CODE END

if (res) {
#if DEBUG
if (GlobalConfig.Instance.Debug.Switches[2])
Log._Debug($"CustomCitizenAI.ExtStartPathFind({instanceID}): Path-finding starts for citizen instance {instanceID}, path={path}, extVehicleType={extVehicleType}, startPosA.segment={startPosA.m_segment}, startPosA.lane={startPosA.m_lane}, laneType={laneTypes}, vehicleType={vehicleType}, endPosA.segment={endPosA.m_segment}, endPosA.lane={endPosA.m_lane}, vehiclePos.m_segment={vehiclePosition.m_segment}, vehiclePos.m_lane={vehiclePosition.m_lane}, vehiclePos.m_offset={vehiclePosition.m_offset}");
Log._Debug($"CustomCitizenAI.ExtStartPathFind({instanceID}): Path-finding starts for citizen instance {instanceID}, path={path}, extVehicleType={extVehicleType}, startPosA.segment={startPosA.m_segment}, startPosA.lane={startPosA.m_lane}, laneType={laneTypes}, vehicleType={vehicleTypes}, endPosA.segment={endPosA.m_segment}, endPosA.lane={endPosA.m_lane}, vehiclePos.m_segment={vehiclePosition.m_segment}, vehiclePos.m_lane={vehiclePosition.m_lane}, vehiclePos.m_offset={vehiclePosition.m_offset}");
#endif

if (citizenData.m_path != 0u) {
Expand Down
26 changes: 24 additions & 2 deletions TLM/TLM/Custom/AI/CustomFireTruckAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using TrafficManager.Traffic;
using TrafficManager.Traffic.Data;
using UnityEngine;
using static TrafficManager.Custom.PathFinding.CustomPathManager;

namespace TrafficManager.Custom.AI {
class CustomFireTruckAI : CarAI {
Expand Down Expand Up @@ -44,9 +45,30 @@ public bool CustomStartPathFind(ushort vehicleID, ref Vehicle vehicleData, Vecto
endPosB = default(PathUnit.Position);
}
uint path;
if (CustomPathManager._instance.CreatePath(
vehicleType, vehicleID, ExtCitizenInstance.ExtPathType.None, 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, (vehicleData.m_flags & Vehicle.Flags.Spawned) != 0)) {
// NON-STOCK CODE START
PathCreationArgs args;
args.extPathType = ExtCitizenInstance.ExtPathType.None;
args.extVehicleType = vehicleType;
args.vehicleId = vehicleID;
args.buildIndex = Singleton<SimulationManager>.instance.m_currentBuildIndex;
args.startPosA = startPosA;
args.startPosB = startPosB;
args.endPosA = endPosA;
args.endPosB = endPosB;
args.vehiclePosition = default(PathUnit.Position);
args.laneTypes = NetInfo.LaneType.Vehicle | NetInfo.LaneType.TransportVehicle;
args.vehicleTypes = info.m_vehicleType;
args.maxLength = 20000f;
args.isHeavyVehicle = this.IsHeavyVehicle();
args.hasCombustionEngine = this.CombustionEngine();
args.ignoreBlocked = this.IgnoreBlocked(vehicleID, ref vehicleData);
args.ignoreFlooded = false;
args.randomParking = false;
args.stablePath = false;
args.skipQueue = (vehicleData.m_flags & Vehicle.Flags.Spawned) != 0;

if (CustomPathManager._instance.CreatePath(out path, ref Singleton<SimulationManager>.instance.m_randomizer, args)) {
// NON-STOCK CODE END
if (vehicleData.m_path != 0u) {
Singleton<PathManager>.instance.ReleasePath(vehicleData.m_path);
}
Expand Down
Loading

0 comments on commit 8773045

Please sign in to comment.