Skip to content

Commit

Permalink
TMPE version 1.9.7 working state
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorPhilipp committed Jun 3, 2017
1 parent 8df4524 commit 32ff38b
Show file tree
Hide file tree
Showing 19 changed files with 776 additions and 729 deletions.
6 changes: 3 additions & 3 deletions TLM/TLM/Custom/AI/CustomCitizenAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public bool CustomStartPathFind(ushort instanceID, ref CitizenInstance citizenDa
// check distance between home and parked car. if too far away: force to take the car back home
float distHomeToParked = (Singleton<VehicleManager>.instance.m_parkedVehicles.m_buffer[parkedVehicleId].m_position - Singleton<BuildingManager>.instance.m_buildings.m_buffer[homeId].m_position).magnitude;

if (distHomeToParked >= GlobalConfig.Instance.MinParkedCarToTargetBuildingDistance && distHomeToParked > GlobalConfig.Instance.MaxParkedCarDistanceToHome) {
if (distHomeToParked > GlobalConfig.Instance.MaxParkedCarDistanceToHome) {
// force to take car back home
#if DEBUG
if (GlobalConfig.Instance.DebugSwitches[2])
Expand Down Expand Up @@ -194,7 +194,7 @@ public bool CustomStartPathFind(ushort instanceID, ref CitizenInstance citizenDa
// find a parking space in the vicinity of the target
bool calcEndPos;
Vector3 parkPos;
if (AdvancedParkingManager.Instance.FindParkingSpaceForCitizen(endPos, vehicleInfo, extInstance, homeId, 0, false, out parkPos, ref endPosA, out calcEndPos) && extInstance.CalculateReturnPath(parkPos, endPos)) {
if (AdvancedParkingManager.Instance.FindParkingSpaceForCitizen(endPos, vehicleInfo, extInstance, homeId, citizenData.m_targetBuilding == homeId, 0, false, out parkPos, ref endPosA, out calcEndPos) && extInstance.CalculateReturnPath(parkPos, endPos)) {
// success
extInstance.PathMode = ExtCitizenInstance.ExtPathMode.CalculatingCarPathToKnownParkPos;
calculateEndPos = calcEndPos; // if true, the end path position still needs to be calculated
Expand All @@ -218,7 +218,7 @@ public bool CustomStartPathFind(ushort instanceID, ref CitizenInstance citizenDa
// no known parking space found. calculate direct path to target
#if DEBUG
if (GlobalConfig.Instance.DebugSwitches[2])
Log._Debug($"Citizen instance {instanceID} is still at CurrentPathMode={extInstance.PathMode}. Setting it to CalculatingCarPath. parkedVehicleId={parkedVehicleId}");
Log._Debug($"Citizen instance {instanceID} is still at CurrentPathMode={extInstance.PathMode} (no parking space found?). Setting it to CalculatingCarPath. parkedVehicleId={parkedVehicleId}");
#endif
extInstance.PathMode = ExtCitizenInstance.ExtPathMode.CalculatingCarPathToTarget;
}
Expand Down
15 changes: 11 additions & 4 deletions TLM/TLM/Custom/AI/CustomHumanAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public void CustomSimulationStep(ushort instanceID, ref CitizenInstance instance
// NON-STOCK CODE START
if (Options.prohibitPocketCars) {
// check if the citizen has reached a parked car or target
if (CustomHumanAI.CheckReachedParkedCar(instanceID, ref instanceData)) {
if (CheckReachedParkedCar(instanceID, ref instanceData)) {
#if DEBUG
if (GlobalConfig.Instance.DebugSwitches[2])
Log._Debug($"CustomHumanAI.CustomSimulationStep: Citizen instance {instanceID} arrives at parked car or parked car is too far way to enter. PathMode={extInstance.PathMode}");
Expand Down Expand Up @@ -250,6 +250,7 @@ protected static bool OnPathFindFailure(ushort instanceID, ref CitizenInstance i
case ExtPathMode.None:
case ExtPathMode.CalculatingWalkingPathToParkedCar:
case ExtPathMode.CalculatingWalkingPathToTarget:
case ExtPathMode.PublicTransportToTarget:
case ExtPathMode.TaxiToTarget:
if ((instanceData.m_flags & CitizenInstance.Flags.CannotUseTransport) == CitizenInstance.Flags.None) {
if (instanceData.m_targetBuilding != 0) {
Expand Down Expand Up @@ -494,7 +495,8 @@ protected static bool OnPathFindSuccess(ushort instanceID, ref CitizenInstance i
if (instanceData.m_targetBuilding != 0) {
// check distance between parked vehicle and target building. If it is too small then the cim is walking/using transport to get to their target
float parkedDistToTarget = (Singleton<BuildingManager>.instance.m_buildings.m_buffer[instanceData.m_targetBuilding].m_position - Singleton<VehicleManager>.instance.m_parkedVehicles.m_buffer[parkedVehicleId].m_position).magnitude;
if (parkedDistToTarget < GlobalConfig.Instance.MinParkedCarToTargetBuildingDistance) {
if ((instanceData.m_targetBuilding != homeId && parkedDistToTarget < GlobalConfig.Instance.MaxParkedCarDistanceToBuilding) ||
(instanceData.m_targetBuilding == homeId && parkedDistToTarget <= GlobalConfig.Instance.MaxParkedCarDistanceToHome)) {
extInstance.PathMode = ExtCitizenInstance.ExtPathMode.CalculatingWalkingPathToTarget;
handleSoftPathFindFailure = true;

Expand Down Expand Up @@ -720,7 +722,7 @@ protected static bool EnterParkedCar(ushort instanceID, ref CitizenInstance inst
}
}

internal static bool CheckReachedParkedCar(ushort instanceID, ref CitizenInstance instanceData) {
internal bool CheckReachedParkedCar(ushort instanceID, ref CitizenInstance instanceData) {
ExtCitizenInstance extInstance = ExtCitizenInstanceManager.Instance.GetExtInstance(instanceID);

if (instanceData.m_citizen == 0) {
Expand Down Expand Up @@ -815,8 +817,13 @@ internal static bool CheckReachedParkedCar(ushort instanceID, ref CitizenInstanc
extInstance.Reset();
#if DEBUG
if (GlobalConfig.Instance.DebugSwitches[2])
Log._Debug($"CustomHumanAI.NeedsCarPath: Citizen instance {instanceID} reached parking position but does not own a parked car. Illegal state! Setting CurrentDepartureMode={extInstance.PathMode}");
Log.Warning($"CustomHumanAI.NeedsCarPath: Citizen instance {instanceID} reached parking position but does not own a parked car. Illegal state! Setting PathMode={extInstance.PathMode} and invalidating current path");
#endif

instanceData.m_flags &= ~CitizenInstance.Flags.WaitingPath;
instanceData.m_flags &= ~(CitizenInstance.Flags.HangAround | CitizenInstance.Flags.Panicking | CitizenInstance.Flags.SittingDown);
this.InvalidPath(instanceID, ref instanceData);

return false;
}
} else {
Expand Down
4 changes: 2 additions & 2 deletions TLM/TLM/Custom/AI/CustomPassengerCarAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public bool CustomStartPathFind(ushort vehicleID, ref Vehicle vehicleData, Vecto
bool calcEndPos;
Vector3 parkPos;

if (AdvancedParkingManager.Instance.FindParkingSpaceForCitizen(endPos, vehicleData.Info, driverExtInstance, homeId, vehicleID, allowTourists, out parkPos, ref endPosA, out calcEndPos)) {
if (AdvancedParkingManager.Instance.FindParkingSpaceForCitizen(endPos, vehicleData.Info, driverExtInstance, homeId, targetBuildingId == homeId, vehicleID, allowTourists, out parkPos, ref endPosA, out calcEndPos)) {
calculateEndPos = calcEndPos;
allowRandomParking = false;
movingToParkingPos = true;
Expand Down Expand Up @@ -302,7 +302,7 @@ public void CustomUpdateParkedVehicle(ushort parkedId, ref VehicleParked data) {
Quaternion parkRot;
float parkOffset;

if (AdvancedParkingManager.Instance.FindParkingSpaceInVicinity(data.m_position, data.Info, homeID, 0, out parkingSpaceLocation, out parkingSpaceLocationId, out parkPos, out parkRot, out parkOffset)) {
if (AdvancedParkingManager.Instance.FindParkingSpaceInVicinity(data.m_position, data.Info, homeID, 0, GlobalConfig.Instance.MaxParkedCarDistanceToBuilding, out parkingSpaceLocation, out parkingSpaceLocationId, out parkPos, out parkRot, out parkOffset)) {
Singleton<VehicleManager>.instance.RemoveFromGrid(parkedId, ref data);
data.m_position = parkPos;
data.m_rotation = parkRot;
Expand Down
Loading

0 comments on commit 32ff38b

Please sign in to comment.