-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Keep removed traffic lights on big roads after loading a saved game
- Loading branch information
Showing
2 changed files
with
61 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,31 @@ | ||
using ColossalFramework; | ||
using HarmonyLib; | ||
using UnityEngine; | ||
|
||
namespace Crossings | ||
{ | ||
[HarmonyPatch(typeof(RoadBaseAI))] | ||
[HarmonyPatch(typeof(RoadBaseAI))] | ||
[HarmonyPatch(nameof(RoadBaseAI.UpdateNodeFlags))] | ||
class UpdateNodeFlags | ||
{ | ||
static void Postfix(ref RoadBaseAI __instance, ref NetNode data) | ||
static bool Prefix(ref RoadBaseAI __instance, ref NetNode data) | ||
{ | ||
bool wantTrafficLights = __instance.WantTrafficLights(); | ||
NetManager netManager = Singleton<NetManager>.instance; | ||
var andFlags = | ||
Crossings.CrossingFlag | ||
| NetNode.Flags.TrafficLights | ||
| NetNode.Flags.CustomTrafficLights | ||
; | ||
var checkFlags = | ||
Crossings.CrossingFlag | ||
| NetNode.Flags.TrafficLights | ||
; | ||
|
||
//Debug.Log("isCrossing: " + isCrossing); | ||
//Debug.Log("wantTrafficLights: " + wantTrafficLights); | ||
|
||
if (!wantTrafficLights) | ||
// Crossing & TrafficLights, but no CustomTrafficLights | ||
if((data.m_flags & andFlags) == checkFlags) | ||
{ | ||
for (int i = 0; i < 8; i++) | ||
{ | ||
ushort segment = data.GetSegment(i); | ||
if (segment != 0) | ||
{ | ||
NetInfo info = netManager.m_segments.m_buffer[(int)segment].Info; | ||
if (info != null) | ||
{ | ||
if ((info.m_vehicleTypes & VehicleInfo.VehicleType.Train) != VehicleInfo.VehicleType.None) | ||
{ | ||
// No crossings allowed where there's a railway intersecting | ||
return; | ||
} | ||
|
||
if (info.m_netAI.WantTrafficLights()) | ||
{ | ||
wantTrafficLights = true; | ||
} | ||
} | ||
} | ||
} | ||
data.m_flags |= NetNode.Flags.CustomTrafficLights; | ||
} | ||
|
||
bool isCrossing = (data.m_flags & (NetNode.Flags)Crossings.CrossingFlag) != NetNode.Flags.None; | ||
|
||
if (wantTrafficLights && isCrossing) | ||
{ | ||
data.m_flags |= NetNode.Flags.TrafficLights; | ||
} | ||
// return true -> execute UpdateNodeFlags | ||
return true; | ||
} | ||
} | ||
} |