Skip to content

Commit

Permalink
The correct bus types should now be spawned
Browse files Browse the repository at this point in the history
  • Loading branch information
bloodypenguin committed Feb 16, 2022
1 parent 2a3dee5 commit 7ad82f7
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 1 deletion.
42 changes: 42 additions & 0 deletions HarmonyPatches/BuildingManagerPatches/GetDepotLevelsPatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using ColossalFramework;
using ImprovedPublicTransport2.HarmonyPatches.DepotAIPatches;
using ImprovedPublicTransport2.Util;

namespace ImprovedPublicTransport2.HarmonyPatches.BuildingManagerPatches
{
public static class GetDepotLevelsPatch
{
public static void Apply()
{
PatchUtil.Patch(
new PatchUtil.MethodDefinition(typeof(BuildingManager), nameof(BuildingManager.GetDepotLevels)),
new PatchUtil.MethodDefinition(typeof(GetDepotLevelsPatch), nameof(Prefix)),
null
);
}

public static void Undo()
{
PatchUtil.Unpatch(
new PatchUtil.MethodDefinition(typeof(BuildingManager), nameof(BuildingManager.GetDepotLevels))
);
}

private static bool Prefix(ref TransportLine.DepotLevels __result, ushort lineID)
{
var info1 = Singleton<TransportManager>.instance.m_lines.m_buffer[lineID].Info;
if (info1 == null || info1.GetSubService() != ItemClass.SubService.PublicTransportBus ||
info1.GetClassLevel() != ItemClass.Level.Level1)
{
return true;
}
__result = new TransportLine.DepotLevels()
{
m_level1 = true,
m_level2 = true
};
return false;

}
}
}
36 changes: 36 additions & 0 deletions HarmonyPatches/DepotAIPatches/ClassMatchesPatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using ImprovedPublicTransport2.Util;

namespace ImprovedPublicTransport2.HarmonyPatches.DepotAIPatches
{
public static class ClassMatchesPatch
{

public static void Apply()
{
PatchUtil.Patch(
new PatchUtil.MethodDefinition(typeof(DepotAI), "ClassMatches"),
new PatchUtil.MethodDefinition(typeof(ClassMatchesPatch),
nameof(Prefix))
);
}

public static void Undo()
{
PatchUtil.Unpatch(
new PatchUtil.MethodDefinition(typeof(DepotAI), "ClassMatches")
);
}

private static bool Prefix(ref bool __result, ItemClass itemClass, ItemClass otherItemClass)
{
if (itemClass.m_subService == ItemClass.SubService.PublicTransportBus
&& (itemClass.m_level == ItemClass.Level.Level1 || itemClass.m_level == ItemClass.Level.Level2))
{
__result = otherItemClass.m_subService == ItemClass.SubService.PublicTransportBus && (otherItemClass.m_level == ItemClass.Level.Level1 || otherItemClass.m_level == ItemClass.Level.Level2);
return false;
}

return true;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using ImprovedPublicTransport2.Util;

namespace ImprovedPublicTransport2.HarmonyPatches.TransportManagerPatches
{
public static class CheckTransportLineVehiclesPatch
{
public static void Apply()
{
PatchUtil.Patch(
new PatchUtil.MethodDefinition(typeof(TransportManager),
nameof(TransportManager.CheckTransportLineVehicles)),
new PatchUtil.MethodDefinition(typeof(CheckTransportLineVehiclesPatch),
nameof(Prefix))
);
}

public static void Undo()
{
PatchUtil.Unpatch(
new PatchUtil.MethodDefinition(typeof(TransportManager),
nameof(TransportManager.CheckTransportLineVehicles))
);
}

public static bool Prefix()
{

return false; //we don't want to despawn buses of the 'wrong type'
}
}
}
3 changes: 3 additions & 0 deletions ImprovedPublicTransport.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,14 @@
<Compile Include="Detour\Vehicles\TramAIDetour.cs" />
<Compile Include="Detour\Vehicles\TrolleybusAIDetour.cs" />
<Compile Include="GameDefault.cs" />
<Compile Include="HarmonyPatches\BuildingManagerPatches\GetDepotLevelsPatch.cs" />
<Compile Include="HarmonyPatches\DepotAIPatches\ClassMatchesPatch.cs" />
<Compile Include="HarmonyPatches\DepotAIPatches\StartTransferPatch.cs" />
<Compile Include="HarmonyPatches\NetManagerPatches\ReleaseNodePatch.cs" />
<Compile Include="HarmonyPatches\PublicTransportLineVehicleSelectorPatches\GetVehicleInfoPatch.cs" />
<Compile Include="HarmonyPatches\TransportLinePatches\GetLineVehiclePatch.cs" />
<Compile Include="HarmonyPatches\TransportLinePatches\SimulationStepPatch.cs" />
<Compile Include="HarmonyPatches\TransportManagerPatches\CheckTransportLineVehiclesPatch.cs" />
<Compile Include="HarmonyPatches\VehicleManagerPatches\ReleaseWaterSourcePatch.cs" />
<Compile Include="HarmonyPatches\XYZVehicleAIPatches\LoadPassengersPatch.cs" />
<Compile Include="HarmonyPatches\XYZVehicleAIPatches\UnloadPassengersPatch.cs" />
Expand Down
10 changes: 9 additions & 1 deletion ImprovedPublicTransportMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
using ImprovedPublicTransport2.Detour;
using ImprovedPublicTransport2.Detour.Vehicles;
using ImprovedPublicTransport2.HarmonyPatches;
using ImprovedPublicTransport2.HarmonyPatches.BuildingManagerPatches;
using ImprovedPublicTransport2.HarmonyPatches.DepotAIPatches;
using ImprovedPublicTransport2.HarmonyPatches.NetManagerPatches;
using ImprovedPublicTransport2.HarmonyPatches.PublicTransportLineVehicleSelectorPatches;
using ImprovedPublicTransport2.HarmonyPatches.TransportLinePatches;
using ImprovedPublicTransport2.HarmonyPatches.TransportManagerPatches;
using ImprovedPublicTransport2.HarmonyPatches.VehicleManagerPatches;
using ImprovedPublicTransport2.HarmonyPatches.XYZVehicleAIPatches;
using ImprovedPublicTransport2.OptionsFramework.Extensions;
Expand Down Expand Up @@ -91,6 +93,9 @@ public override void OnLevelLoaded(LoadMode mode)
ReleaseNodePatch.Apply();
ReleaseWaterSourcePatch.Apply();
GetVehicleInfoPatch.Apply();
CheckTransportLineVehiclesPatch.Apply();
ClassMatchesPatch.Apply();
GetDepotLevelsPatch.Apply();

Redirector<BusAIDetour>.Deploy();
Redirector<TrolleybusAIDetour>.Deploy();
Expand Down Expand Up @@ -176,7 +181,10 @@ private void Deinit()
ReleaseNodePatch.Undo();
ReleaseWaterSourcePatch.Undo();
GetVehicleInfoPatch.Undo();

ClassMatchesPatch.Undo();
CheckTransportLineVehiclesPatch.Undo();
GetDepotLevelsPatch.Undo();

Redirector<TramAIDetour>.Revert();
Redirector<PassengerTrainAIDetour>.Revert();
Redirector<PassengerShipAIDetour>.Revert();
Expand Down

0 comments on commit 7ad82f7

Please sign in to comment.