Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes Harmony savegame compat with the pre-Harmony master #427

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 72 additions & 78 deletions TLM/TLM/Custom/AI/CustomAmbulanceAI.cs
Original file line number Diff line number Diff line change
@@ -1,81 +1,75 @@
using ColossalFramework;
using TrafficManager.RedirectionFramework.Attributes;
using System;
using System.Collections.Generic;
using System.Text;
using TrafficManager.Custom.PathFinding;
using TrafficManager.Geometry;
using TrafficManager.Manager;
using TrafficManager.Manager.Impl;
using TrafficManager.Traffic;
using TrafficManager.Traffic.Data;
using TrafficManager.Traffic.Enums;
using UnityEngine;
using static TrafficManager.Custom.PathFinding.CustomPathManager;
namespace TrafficManager.Custom.AI {
using API.Traffic.Data;
using API.Traffic.Enums;
using ColossalFramework;
using Custom.PathFinding;
using Manager.Impl;
using RedirectionFramework.Attributes;
using Traffic.Data;
using UnityEngine;

namespace TrafficManager.Custom.AI {
[TargetType(typeof(AmbulanceAI))]
public class CustomAmbulanceAI : CarAI {
[RedirectMethod]
public bool CustomStartPathFind(ushort vehicleID, ref Vehicle vehicleData, Vector3 startPos, Vector3 endPos, bool startBothWays, bool endBothWays, bool undergroundTarget) {
ExtVehicleType vehicleType = ExtVehicleManager.Instance.OnStartPathFind(vehicleID, ref vehicleData, (vehicleData.m_flags & Vehicle.Flags.Emergency2) != 0 ? ExtVehicleType.Emergency : ExtVehicleType.Service);
[TargetType(typeof(AmbulanceAI))]
public class CustomAmbulanceAI : CarAI {
[RedirectMethod]
public bool CustomStartPathFind(ushort vehicleID, ref Vehicle vehicleData, Vector3 startPos, Vector3 endPos, bool startBothWays, bool endBothWays, bool undergroundTarget) {
ExtVehicleType vehicleType = ExtVehicleManager.Instance.OnStartPathFind(vehicleID, ref vehicleData, (vehicleData.m_flags & Vehicle.Flags.Emergency2) != 0 ? ExtVehicleType.Emergency : ExtVehicleType.Service);

VehicleInfo info = this.m_info;
bool allowUnderground = (vehicleData.m_flags & (Vehicle.Flags.Underground | Vehicle.Flags.Transition)) != 0;
PathUnit.Position startPosA;
PathUnit.Position startPosB;
float startDistSqrA;
float startDistSqrB;
PathUnit.Position endPosA;
PathUnit.Position endPosB;
float endDistSqrA;
float endDistSqrB;
if (CustomPathManager.FindPathPosition(startPos, ItemClass.Service.Road, NetInfo.LaneType.Vehicle | NetInfo.LaneType.TransportVehicle, info.m_vehicleType, allowUnderground, false, 32f, out startPosA, out startPosB, out startDistSqrA, out startDistSqrB) &&
CustomPathManager.FindPathPosition(endPos, ItemClass.Service.Road, NetInfo.LaneType.Vehicle | NetInfo.LaneType.TransportVehicle, info.m_vehicleType, undergroundTarget, false, 32f, out endPosA, out endPosB, out endDistSqrA, out endDistSqrB)) {
if (!startBothWays || startDistSqrA < 10f) {
startPosB = default(PathUnit.Position);
}
if (!endBothWays || endDistSqrA < 10f) {
endPosB = default(PathUnit.Position);
}
uint path;
// NON-STOCK CODE START
PathCreationArgs args;
args.extPathType = ExtPathType.None;
args.extVehicleType = vehicleType;
args.vehicleId = vehicleID;
args.spawned = (vehicleData.m_flags & Vehicle.Flags.Spawned) != 0;
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.ignoreCosts = false;
args.randomParking = false;
args.stablePath = false;
args.skipQueue = (vehicleData.m_flags & Vehicle.Flags.Spawned) != 0;
VehicleInfo info = this.m_info;
bool allowUnderground = (vehicleData.m_flags & (Vehicle.Flags.Underground | Vehicle.Flags.Transition)) != 0;
PathUnit.Position startPosA;
PathUnit.Position startPosB;
float startDistSqrA;
float startDistSqrB;
PathUnit.Position endPosA;
PathUnit.Position endPosB;
float endDistSqrA;
float endDistSqrB;
if (CustomPathManager.FindPathPosition(startPos, ItemClass.Service.Road, NetInfo.LaneType.Vehicle | NetInfo.LaneType.TransportVehicle, info.m_vehicleType, allowUnderground, false, 32f, out startPosA, out startPosB, out startDistSqrA, out startDistSqrB) &&
CustomPathManager.FindPathPosition(endPos, ItemClass.Service.Road, NetInfo.LaneType.Vehicle | NetInfo.LaneType.TransportVehicle, info.m_vehicleType, undergroundTarget, false, 32f, out endPosA, out endPosB, out endDistSqrA, out endDistSqrB)) {
if (!startBothWays || startDistSqrA < 10f) {
startPosB = default(PathUnit.Position);
}
if (!endBothWays || endDistSqrA < 10f) {
endPosB = default(PathUnit.Position);
}
uint path;
// NON-STOCK CODE START
PathCreationArgs args;
args.extPathType = ExtPathType.None;
args.extVehicleType = vehicleType;
args.vehicleId = vehicleID;
args.spawned = (vehicleData.m_flags & Vehicle.Flags.Spawned) != 0;
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.ignoreCosts = false;
args.randomParking = false;
args.stablePath = false;
args.skipQueue = (vehicleData.m_flags & Vehicle.Flags.Spawned) != 0;

if (CustomPathManager._instance.CustomCreatePath(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);
}
vehicleData.m_path = path;
vehicleData.m_flags |= Vehicle.Flags.WaitingPath;
return true;
}
} else {
PathfindFailure(vehicleID, ref vehicleData);
}
return false;
}
}
}
if (CustomPathManager._instance.CustomCreatePath(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);
}
vehicleData.m_path = path;
vehicleData.m_flags |= Vehicle.Flags.WaitingPath;
return true;
}
} else {
PathfindFailure(vehicleID, ref vehicleData);
}
return false;
}
}
}
142 changes: 68 additions & 74 deletions TLM/TLM/Custom/AI/CustomBusAI.cs
Original file line number Diff line number Diff line change
@@ -1,77 +1,71 @@
using ColossalFramework;
using TrafficManager.RedirectionFramework.Attributes;
using System;
using System.Collections.Generic;
using System.Text;
using TrafficManager.Custom.PathFinding;
using TrafficManager.Geometry;
using TrafficManager.Manager;
using TrafficManager.Traffic;
using TrafficManager.Traffic.Data;
using TrafficManager.Traffic.Enums;
using UnityEngine;
using static TrafficManager.Custom.PathFinding.CustomPathManager;
namespace TrafficManager.Custom.AI {
using API.Traffic.Data;
using API.Traffic.Enums;
using ColossalFramework;
using Custom.PathFinding;
using RedirectionFramework.Attributes;
using Traffic.Data;
using UnityEngine;

namespace TrafficManager.Custom.AI {
[TargetType(typeof(BusAI))]
public class CustomBusAI : CarAI {
[RedirectMethod]
public bool CustomStartPathFind(ushort vehicleID, ref Vehicle vehicleData, Vector3 startPos, Vector3 endPos, bool startBothWays, bool endBothWays, bool undergroundTarget) {
VehicleInfo info = this.m_info;
bool allowUnderground = (vehicleData.m_flags & (Vehicle.Flags.Underground | Vehicle.Flags.Transition)) != 0;
PathUnit.Position startPosA;
PathUnit.Position startPosB;
float startDistSqrA;
float startDistSqrB;
PathUnit.Position endPosA;
PathUnit.Position endPosB;
float endDistSqrA;
float endDistSqrB;
if (CustomPathManager.FindPathPosition(startPos, ItemClass.Service.Road, NetInfo.LaneType.Vehicle | NetInfo.LaneType.TransportVehicle, info.m_vehicleType, allowUnderground, false, 32f, out startPosA, out startPosB, out startDistSqrA, out startDistSqrB) &&
CustomPathManager.FindPathPosition(endPos, ItemClass.Service.Road, NetInfo.LaneType.Vehicle | NetInfo.LaneType.TransportVehicle, info.m_vehicleType, undergroundTarget, false, 32f, out endPosA, out endPosB, out endDistSqrA, out endDistSqrB)) {
if (!startBothWays || startDistSqrA < 10f) {
startPosB = default(PathUnit.Position);
}
if (!endBothWays || endDistSqrA < 10f) {
endPosB = default(PathUnit.Position);
}
uint path;
// NON-STOCK CODE START
PathCreationArgs args;
args.extPathType = ExtPathType.None;
args.extVehicleType = ExtVehicleType.Bus;
args.vehicleId = vehicleID;
args.spawned = (vehicleData.m_flags & Vehicle.Flags.Spawned) != 0;
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.ignoreCosts = false;
args.stablePath = true;
args.skipQueue = true;
[TargetType(typeof(BusAI))]
public class CustomBusAI : CarAI {
[RedirectMethod]
public bool CustomStartPathFind(ushort vehicleID, ref Vehicle vehicleData, Vector3 startPos, Vector3 endPos, bool startBothWays, bool endBothWays, bool undergroundTarget) {
VehicleInfo info = this.m_info;
bool allowUnderground = (vehicleData.m_flags & (Vehicle.Flags.Underground | Vehicle.Flags.Transition)) != 0;
PathUnit.Position startPosA;
PathUnit.Position startPosB;
float startDistSqrA;
float startDistSqrB;
PathUnit.Position endPosA;
PathUnit.Position endPosB;
float endDistSqrA;
float endDistSqrB;
if (CustomPathManager.FindPathPosition(startPos, ItemClass.Service.Road, NetInfo.LaneType.Vehicle | NetInfo.LaneType.TransportVehicle, info.m_vehicleType, allowUnderground, false, 32f, out startPosA, out startPosB, out startDistSqrA, out startDistSqrB) &&
CustomPathManager.FindPathPosition(endPos, ItemClass.Service.Road, NetInfo.LaneType.Vehicle | NetInfo.LaneType.TransportVehicle, info.m_vehicleType, undergroundTarget, false, 32f, out endPosA, out endPosB, out endDistSqrA, out endDistSqrB)) {
if (!startBothWays || startDistSqrA < 10f) {
startPosB = default(PathUnit.Position);
}
if (!endBothWays || endDistSqrA < 10f) {
endPosB = default(PathUnit.Position);
}
uint path;
// NON-STOCK CODE START
PathCreationArgs args;
args.extPathType = ExtPathType.None;
args.extVehicleType = ExtVehicleType.Bus;
args.vehicleId = vehicleID;
args.spawned = (vehicleData.m_flags & Vehicle.Flags.Spawned) != 0;
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.ignoreCosts = false;
args.stablePath = true;
args.skipQueue = true;

if (CustomPathManager._instance.CustomCreatePath(out path, ref Singleton<SimulationManager>.instance.m_randomizer, args)) {
// NON-STOCK CODE END
if (CustomPathManager._instance.CustomCreatePath(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);
}
vehicleData.m_path = path;
vehicleData.m_flags |= Vehicle.Flags.WaitingPath;
return true;
}
}
return false;
}
}
}
if (vehicleData.m_path != 0u) {
Singleton<PathManager>.instance.ReleasePath(vehicleData.m_path);
}
vehicleData.m_path = path;
vehicleData.m_flags |= Vehicle.Flags.WaitingPath;
return true;
}
}
return false;
}
}
}
Loading