Skip to content

Commit

Permalink
Version 1.10.13: Updated for game version 1.11.0-f3
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorPhilipp committed Mar 1, 2019
1 parent 168fe21 commit 6c58225
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 76 deletions.
10 changes: 5 additions & 5 deletions TLM/TLM/Custom/AI/CustomCargoTruckAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ public bool CustomStartPathFind(ushort vehicleID, ref Vehicle vehicleData, Vecto
PathUnit.Position startAltPosB;
float startAltDistSqrA;
float startAltDistSqrB;
if (CustomPathManager.FindPathPosition(startPos, ItemClass.Service.PublicTransport, NetInfo.LaneType.Vehicle, VehicleInfo.VehicleType.Train | VehicleInfo.VehicleType.Ship, allowUnderground, false, 32f, out startAltPosA, out startAltPosB, out startAltDistSqrA, out startAltDistSqrB)) {
if (!startPosFound || startAltDistSqrA < startDistSqrA) {
if (CustomPathManager.FindPathPosition(startPos, ItemClass.Service.PublicTransport, NetInfo.LaneType.Vehicle, VehicleInfo.VehicleType.Train | VehicleInfo.VehicleType.Ship | VehicleInfo.VehicleType.Plane, allowUnderground, false, 32f, out startAltPosA, out startAltPosB, out startAltDistSqrA, out startAltDistSqrB)) {
if (!startPosFound || (startAltDistSqrA < startDistSqrA && (Mathf.Abs(startPos.x) > 4800f || Mathf.Abs(startPos.z) > 4800f))) {
startPosA = startAltPosA;
startPosB = startAltPosB;
startDistSqrA = startAltDistSqrA;
Expand All @@ -110,8 +110,8 @@ public bool CustomStartPathFind(ushort vehicleID, ref Vehicle vehicleData, Vecto
PathUnit.Position endAltPosB;
float endAltDistSqrA;
float endAltDistSqrB;
if (CustomPathManager.FindPathPosition(endPos, ItemClass.Service.PublicTransport, NetInfo.LaneType.Vehicle, VehicleInfo.VehicleType.Train | VehicleInfo.VehicleType.Ship, undergroundTarget, false, 32f, out endAltPosA, out endAltPosB, out endAltDistSqrA, out endAltDistSqrB)) {
if (!endPosFound || endAltDistSqrA < endDistSqrA) {
if (CustomPathManager.FindPathPosition(endPos, ItemClass.Service.PublicTransport, NetInfo.LaneType.Vehicle, VehicleInfo.VehicleType.Train | VehicleInfo.VehicleType.Ship | VehicleInfo.VehicleType.Plane, undergroundTarget, false, 32f, out endAltPosA, out endAltPosB, out endAltDistSqrA, out endAltDistSqrB)) {
if (!endPosFound || (endAltDistSqrA < endDistSqrA && (Mathf.Abs(endPos.x) > 4800f || Mathf.Abs(endPos.z) > 4800f))) {
endPosA = endAltPosA;
endPosB = endAltPosB;
endDistSqrA = endAltDistSqrA;
Expand All @@ -128,7 +128,7 @@ public bool CustomStartPathFind(ushort vehicleID, ref Vehicle vehicleData, Vecto
endPosB = default(PathUnit.Position);
}
NetInfo.LaneType laneTypes = NetInfo.LaneType.Vehicle | NetInfo.LaneType.CargoVehicle;
VehicleInfo.VehicleType vehicleTypes = VehicleInfo.VehicleType.Car | VehicleInfo.VehicleType.Train | VehicleInfo.VehicleType.Ship;
VehicleInfo.VehicleType vehicleTypes = VehicleInfo.VehicleType.Car | VehicleInfo.VehicleType.Train | VehicleInfo.VehicleType.Ship | VehicleInfo.VehicleType.Plane;
uint path;
// NON-STOCK CODE START
PathCreationArgs args;
Expand Down
117 changes: 66 additions & 51 deletions TLM/TLM/Custom/AI/CustomRoadAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ public void CustomUpdateLanes(ushort segmentID, ref NetSegment data, bool loadin
NetSegment.CalculateMiddlePoints(vector3, startDir, vector4, endDir, smoothStart, smoothEnd, out b3, out c);
NetLane.Flags flags2 = (NetLane.Flags)instance.m_lanes.m_buffer[num16].m_flags;
NetLane.Flags flags3 = flags;
flags2 &= ~(NetLane.Flags.Forward | NetLane.Flags.Left | NetLane.Flags.Right | NetLane.Flags.YieldStart | NetLane.Flags.YieldEnd | NetLane.Flags.StartOneWayLeft | NetLane.Flags.StartOneWayRight | NetLane.Flags.EndOneWayLeft | NetLane.Flags.EndOneWayRight);
flags2 &= ~(NetLane.Flags.Forward | NetLane.Flags.Left | NetLane.Flags.Right | NetLane.Flags.Merge | NetLane.Flags.YieldStart | NetLane.Flags.YieldEnd | NetLane.Flags.StartOneWayLeft | NetLane.Flags.StartOneWayRight | NetLane.Flags.EndOneWayLeft | NetLane.Flags.EndOneWayRight);
if ((byte)(lane.m_finalDirection & NetInfo.Direction.Both) == 2) {
flags3 &= ~NetLane.Flags.YieldEnd;
}
Expand Down Expand Up @@ -456,63 +456,78 @@ public void CustomUpdateLanes(ushort segmentID, ref NetSegment data, bool loadin
num18 = 255;
num19 = 0;
if (num25 != 0) {
int num26;
int num27;
if (lane.m_similarLaneCount >= num25) {
num26 = num20;
num27 = num22;
} else {
num26 = num20 * lane.m_similarLaneCount / (num25 + (num21 >> 1));
num27 = num22 * lane.m_similarLaneCount / (num25 + (num21 >> 1));
}
int num28 = num26;
int num29 = lane.m_similarLaneCount - num26 - num27;
int num30 = num27;
if (num29 > 0) {
if (num20 > num26) {
num28++;
}
if (num22 > num27) {
num30++;
}
}
if (num23 < num28) {
int num31 = (num23 * num20 + num28 - 1) / num28;
int num32 = ((num23 + 1) * num20 + num28 - 1) / num28;
if (num32 > num31) {
if (lane.m_similarLaneCount > num25 && num25 > 0) {
num18 = num25 * num23 / lane.m_similarLaneCount;
num19 = num25 - num25 * num24 / lane.m_similarLaneCount;
flags2 |= NetLane.Flags.Merge;
if (num18 < num20) {
flags2 |= NetLane.Flags.Left;
num18 = Mathf.Min(num18, num31);
num19 = Mathf.Max(num19, num32);
}
}
if (num23 >= num26 && num24 >= num27 && num21 != 0) {
if (lane.m_similarLaneCount > num25) {
num26++;
if (num25 - num19 < num22) {
flags2 |= NetLane.Flags.Right;
}
int num33 = num20 + ((num23 - num26) * num21 + num29 - 1) / num29;
int num34 = num20 + ((num23 + 1 - num26) * num21 + num29 - 1) / num29;
if (num34 > num33) {
if (num21 != 0 && num18 < num20 + num21 && num19 > num20) {
flags2 |= NetLane.Flags.Forward;
num18 = Mathf.Min(num18, num33);
num19 = Mathf.Max(num19, num34);
}
}
if (num24 < num30) {
int num35 = num25 - ((num24 + 1) * num22 + num30 - 1) / num30;
int num36 = num25 - (num24 * num22 + num30 - 1) / num30;
if (num36 > num35) {
flags2 |= NetLane.Flags.Right;
num18 = Mathf.Min(num18, num35);
num19 = Mathf.Max(num19, num36);
} else {
int num26;
int num27;
if (lane.m_similarLaneCount >= num25) {
num26 = num20;
num27 = num22;
} else {
num26 = num20 * lane.m_similarLaneCount / (num25 + (num21 >> 1));
num27 = num22 * lane.m_similarLaneCount / (num25 + (num21 >> 1));
}
}
if (this.m_highwayRules) {
if ((flags2 & NetLane.Flags.LeftRight) == NetLane.Flags.Left) {
if ((flags2 & NetLane.Flags.Forward) == NetLane.Flags.None || (num21 >= 2 && num20 == 1)) {
num19 = Mathf.Min(num19, num18 + 1);
int num28 = num26;
int num29 = lane.m_similarLaneCount - num26 - num27;
int num30 = num27;
if (num29 > 0) {
if (num20 > num26) {
num28++;
}
if (num22 > num27) {
num30++;
}
}
if (num23 < num28) {
int num31 = (num23 * num20 + num28 - 1) / num28;
int num32 = ((num23 + 1) * num20 + num28 - 1) / num28;
if (num32 > num31) {
flags2 |= NetLane.Flags.Left;
num18 = Mathf.Min(num18, num31);
num19 = Mathf.Max(num19, num32);
}
}
if (num23 >= num26 && num24 >= num27 && num21 != 0) {
if (lane.m_similarLaneCount > num25) {
num26++;
}
int num33 = num20 + ((num23 - num26) * num21 + num29 - 1) / num29;
int num34 = num20 + ((num23 + 1 - num26) * num21 + num29 - 1) / num29;
if (num34 > num33) {
flags2 |= NetLane.Flags.Forward;
num18 = Mathf.Min(num18, num33);
num19 = Mathf.Max(num19, num34);
}
}
if (num24 < num30) {
int num35 = num25 - ((num24 + 1) * num22 + num30 - 1) / num30;
int num36 = num25 - (num24 * num22 + num30 - 1) / num30;
if (num36 > num35) {
flags2 |= NetLane.Flags.Right;
num18 = Mathf.Min(num18, num35);
num19 = Mathf.Max(num19, num36);
}
}
if (this.m_highwayRules) {
if ((flags2 & NetLane.Flags.LeftRight) == NetLane.Flags.Left) {
if ((flags2 & NetLane.Flags.Forward) == NetLane.Flags.None || (num21 >= 2 && num20 == 1)) {
num19 = Mathf.Min(num19, num18 + 1);
}
} else if ((flags2 & NetLane.Flags.LeftRight) == NetLane.Flags.Right && ((flags2 & NetLane.Flags.Forward) == NetLane.Flags.None || (num21 >= 2 && num22 == 1))) {
num18 = Mathf.Max(num18, num19 - 1);
}
} else if ((flags2 & NetLane.Flags.LeftRight) == NetLane.Flags.Right && ((flags2 & NetLane.Flags.Forward) == NetLane.Flags.None || (num21 >= 2 && num22 == 1))) {
num18 = Mathf.Max(num18, num19 - 1);
}
}
}
Expand Down
26 changes: 26 additions & 0 deletions TLM/TLM/Custom/AI/CustomVehicleAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,21 @@ protected void CustomUpdatePathTargetPositions(ushort vehicleID, ref Vehicle veh
}
}

if ((vehicleData.m_flags2 & Vehicle.Flags2.EndStop) != 0) {
if (targetPosIndex <= 0) {
targetPos.w = 0f;
if (VectorUtils.LengthSqrXZ(vehicleData.GetLastFrameVelocity()) < 0.01f) {
vehicleData.m_flags2 &= ~Vehicle.Flags2.EndStop;
}
} else {
targetPos.w = 1f;
}
while (targetPosIndex < maxTargetPosIndex) {
vehicleData.SetTargetPos(targetPosIndex++, targetPos);
}
return;
}

// vehicle is in transition now

/*
Expand Down Expand Up @@ -444,6 +459,17 @@ protected void CustomUpdatePathTargetPositions(ushort vehicleID, ref Vehicle veh

// check for arrival
if (targetPosIndex <= 0) {
if ((netManager.m_segments.m_buffer[nextPathPos.m_segment].m_flags & NetSegment.Flags.Untouchable) != 0 && (netManager.m_segments.m_buffer[currentPosition.m_segment].m_flags & NetSegment.Flags.Untouchable) == NetSegment.Flags.None) {
ushort ownerBuildingId = NetSegment.FindOwnerBuilding(nextPathPos.m_segment, 363f);
if (ownerBuildingId != 0) {
BuildingManager buildingMan = Singleton<BuildingManager>.instance;
BuildingInfo ownerBuildingInfo = buildingMan.m_buildings.m_buffer[ownerBuildingId].Info;
InstanceID itemID = default(InstanceID);
itemID.Vehicle = vehicleID;
ownerBuildingInfo.m_buildingAI.EnterBuildingSegment(ownerBuildingId, ref buildingMan.m_buildings.m_buffer[ownerBuildingId], nextPathPos.m_segment, nextPathPos.m_offset, itemID);
}
}

if (nextCoarsePathPosIndex == 0) {
Singleton<PathManager>.instance.ReleaseFirstUnit(ref vehicleData.m_path);
}
Expand Down
5 changes: 5 additions & 0 deletions TLM/TLM/Custom/Data/CustomVehicle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public static void Spawn(ref Vehicle vehicleData, ushort vehicleId) {
float length = (!hasTrailers) ? (vehicleInfo.m_generatedInfo.m_size.z * 0.5f) : 0f;
length -= (((vehicleData.m_flags & Vehicle.Flags.Inverted) == (Vehicle.Flags)0) ? vehicleInfo.m_attachOffsetBack : vehicleInfo.m_attachOffsetFront);
Randomizer randomizer = new Randomizer((int)vehicleId);
int trailerCount = 0;
for (int i = 0; i < vehicleInfo.m_trailers.Length; i++) {
if (randomizer.Int32(100u) < vehicleInfo.m_trailers[i].m_probability) {
VehicleInfo trailerInfo = vehicleInfo.m_trailers[i].m_info;
Expand All @@ -54,6 +55,7 @@ public static void Spawn(ref Vehicle vehicleData, ushort vehicleId) {
if (vehManager.CreateVehicle(out trailerVehicleId, ref Singleton<SimulationManager>.instance.m_randomizer, trailerInfo, position, (TransferManager.TransferReason)vehicleData.m_transferType, false, false)) {
vehManager.m_vehicles.m_buffer[(int)curVehicleId].m_trailingVehicle = trailerVehicleId;
vehManager.m_vehicles.m_buffer[(int)trailerVehicleId].m_leadingVehicle = curVehicleId;
vehManager.m_vehicles.m_buffer[(int)trailerVehicleId].m_gateIndex = vehicleData.m_gateIndex;
if (inverted) {
vehManager.m_vehicles.m_buffer[trailerVehicleId].m_flags |= Vehicle.Flags.Inverted;
}
Expand All @@ -70,6 +72,9 @@ public static void Spawn(ref Vehicle vehicleData, ushort vehicleId) {
}
length += ((!hasTrailers) ? (trailerInfo.m_generatedInfo.m_size.z * 0.5f) : 0f);
length -= ((!inverted) ? trailerInfo.m_attachOffsetBack : trailerInfo.m_attachOffsetFront);
if (++trailerCount == vehicleInfo.m_maxTrailerCount) {
break;
}
}
}
}
Expand Down
22 changes: 17 additions & 5 deletions TLM/TLM/Custom/PathFinding/CustomPathFind2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1975,11 +1975,9 @@ private bool ProcessItemCosts(
comparisonValue += baseLength;
}
#endif
if (!m_ignoreCost) {
int ticketCost = prevLane.m_ticketCost;
if (ticketCost != 0) {
comparisonValue += (float)(ticketCost * m_pathRandomizer.Int32(2000u)) * TICKET_COST_CONVERSION_FACTOR;
}
int ticketCost = prevLane.m_ticketCost;
if (!m_ignoreCost && ticketCost != 0) {
comparisonValue += (float)(ticketCost * m_pathRandomizer.Int32(2000u)) * TICKET_COST_CONVERSION_FACTOR;
}

if ((prevLaneType & (NetInfo.LaneType.Vehicle | NetInfo.LaneType.TransportVehicle)) != NetInfo.LaneType.None) {
Expand Down Expand Up @@ -2074,6 +2072,9 @@ private bool ProcessItemCosts(
if (isTransition) {
transitionCost *= 2f;
}
if (ticketCost != 0 && netManager.m_lanes.m_buffer[nextLaneId].m_ticketCost != 0) {
transitionCost *= 10f;
}

float nextMaxSpeed;
#if SPEEDLIMITS
Expand All @@ -2085,6 +2086,17 @@ private bool ProcessItemCosts(
#endif

float transitionCostOverMeanMaxSpeed = transitionCost / ((prevMaxSpeed + nextMaxSpeed) * 0.5f * m_maxLength);
#if ADVANCEDAI && ROUTING
if (!enableAdvancedAI) {
#endif
if (!this.m_stablePath && (netManager.m_lanes.m_buffer[nextLaneId].m_flags & (ushort)NetLane.Flags.Merge) != 0) {
int firstTarget = netManager.m_lanes.m_buffer[nextLaneId].m_firstTarget;
int lastTarget = netManager.m_lanes.m_buffer[nextLaneId].m_lastTarget;
transitionCostOverMeanMaxSpeed *= (float)new Randomizer(this.m_pathFindIndex ^ nextLaneId).Int32(1000, (lastTarget - firstTarget + 2) * 1000) * 0.001f;
}
#if ADVANCEDAI && ROUTING
}
#endif
nextItem.m_position.m_segment = nextSegmentId;
nextItem.m_position.m_lane = (byte)nextLaneIndex;
nextItem.m_position.m_offset = (byte)(((nextDir & NetInfo.Direction.Forward) != NetInfo.Direction.None) ? 255 : 0);
Expand Down
16 changes: 11 additions & 5 deletions TLM/TLM/Custom/PathFinding/StockPathFind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -808,11 +808,9 @@ private bool ProcessItemCosts(BufferItem item, ushort nextNodeId, ushort nextSeg
}

float comparisonValue = item.m_comparisonValue + offsetLength / (prevLaneSpeed * m_maxLength);
if (!m_ignoreCost) {
int ticketCost = netManager.m_lanes.m_buffer[item.m_laneID].m_ticketCost;
if (ticketCost != 0) {
comparisonValue += (float)(ticketCost * m_pathRandomizer.Int32(2000u)) * TICKET_COST_CONVERSION_FACTOR;
}
int ticketCost = netManager.m_lanes.m_buffer[item.m_laneID].m_ticketCost;
if (!this.m_ignoreCost && ticketCost != 0) {
comparisonValue += (float)(ticketCost * this.m_pathRandomizer.Int32(2000u)) * TICKET_COST_CONVERSION_FACTOR;
}
if ((prevLaneType & (NetInfo.LaneType.Vehicle | NetInfo.LaneType.TransportVehicle)) != 0) {
prevLaneType = (NetInfo.LaneType.Vehicle | NetInfo.LaneType.TransportVehicle);
Expand Down Expand Up @@ -846,7 +844,15 @@ private bool ProcessItemCosts(BufferItem item, ushort nextNodeId, ushort nextSeg
if (transitionNode) {
transitionCost *= 2f;
}
if (ticketCost != 0 && netManager.m_lanes.m_buffer[curLaneId].m_ticketCost != 0) {
transitionCost *= 10f;
}
float transitionCostOverMeanMaxSpeed = transitionCost / ((prevMaxSpeed + nextLaneInfo.m_speedLimit) * 0.5f * m_maxLength);
if (!this.m_stablePath && (netManager.m_lanes.m_buffer[curLaneId].m_flags & 0x80) != 0) {
int firstTarget = netManager.m_lanes.m_buffer[curLaneId].m_firstTarget;
int lastTarget = netManager.m_lanes.m_buffer[curLaneId].m_lastTarget;
transitionCostOverMeanMaxSpeed *= (float)new Randomizer(this.m_pathFindIndex ^ curLaneId).Int32(1000, (lastTarget - firstTarget + 2) * 1000) * 0.001f;
}
nextItem.m_position.m_segment = nextSegmentId;
nextItem.m_position.m_lane = (byte)i;
nextItem.m_position.m_offset = (byte)(((nextDir & NetInfo.Direction.Forward) != 0) ? 255 : 0);
Expand Down
10 changes: 6 additions & 4 deletions TLM/TLM/Traffic/Data/VehicleState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ private void DetermineVehicleType(ref Vehicle vehicleData) {
case VehicleInfo.VehicleType.Car:
if (ai is PassengerCarAI)
return ExtVehicleType.PassengerCar;
if (ai is AmbulanceAI || ai is FireTruckAI || ai is PoliceCarAI || ai is HearseAI || ai is GarbageTruckAI || ai is MaintenanceTruckAI || ai is SnowTruckAI || ai is WaterTruckAI || ai is DisasterResponseVehicleAI || ai is ParkMaintenanceVehicleAI) {
if (ai is AmbulanceAI || ai is FireTruckAI || ai is PoliceCarAI || ai is HearseAI || ai is GarbageTruckAI || ai is MaintenanceTruckAI || ai is SnowTruckAI || ai is WaterTruckAI || ai is DisasterResponseVehicleAI || ai is ParkMaintenanceVehicleAI || ai is PostVanAI) {
return ExtVehicleType.Service;
}
if (ai is CarTrailerAI)
Expand All @@ -585,9 +585,11 @@ private void DetermineVehicleType(ref Vehicle vehicleData) {
return ExtVehicleType.CargoShip;
//break;
case VehicleInfo.VehicleType.Plane:
//if (ai is PassengerPlaneAI)
return ExtVehicleType.PassengerPlane;
//break;
if (ai is PassengerPlaneAI)
return ExtVehicleType.PassengerPlane;
if (ai is CargoPlaneAI)
return ExtVehicleType.CargoPlane;
break;
case VehicleInfo.VehicleType.Helicopter:
//if (ai is PassengerPlaneAI)
return ExtVehicleType.Helicopter;
Expand Down
5 changes: 3 additions & 2 deletions TLM/TLM/Traffic/ExtVehicleType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ public enum ExtVehicleType {
CableCar = 1 << 15,
PassengerFerry = 1 << 16,
PassengerBlimp = 1 << 17,
Plane = PassengerPlane,
CargoPlane = 1 << 18,
Plane = PassengerPlane | CargoPlane,
Ship = PassengerShip | CargoShip,
CargoVehicle = CargoTruck | CargoTrain | CargoShip,
CargoVehicle = CargoTruck | CargoTrain | CargoShip | CargoPlane,
PublicTransport = Bus | Taxi | Tram | PassengerTrain,
RoadPublicTransport = Bus | Taxi,
RoadVehicle = PassengerCar | Bus | Taxi | CargoTruck | Service | Emergency,
Expand Down
8 changes: 4 additions & 4 deletions TLM/TLM/TrafficManagerMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
namespace TrafficManager {
public class TrafficManagerMod : IUserMod {

public static readonly string Version = "1.10.12";
public static readonly string Version = "1.10.13";

public static readonly uint GameVersion = 176415504u;
public static readonly uint GameVersion = 180478736u;
public static readonly uint GameVersionA = 1u;
public static readonly uint GameVersionB = 10u;
public static readonly uint GameVersionC = 1u;
public static readonly uint GameVersionB = 11u;
public static readonly uint GameVersionC = 0u;
public static readonly uint GameVersionBuild = 3u;

public string Name => "Traffic Manager: President Edition [" + Version + "]";
Expand Down

0 comments on commit 6c58225

Please sign in to comment.