Skip to content

Commit fb44c19

Browse files
committed
TMPE version 1.8.11:
- Bugfix: Speed limits for elevated/underground road segments are sometimes not correctly loaded (thanks to @Pirazel and @[P.A.N] Uf0 for reporting this issue)
1 parent 1a85193 commit fb44c19

File tree

3 files changed

+119
-8
lines changed

3 files changed

+119
-8
lines changed

TLM/TLM/Manager/SpeedLimitManager.cs

Lines changed: 112 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,20 @@ public ushort LaneToCustomSpeedLimit(float laneSpeedLimit, bool roundToSignLimit
286286
/// </summary>
287287
/// <param name="info"></param>
288288
public void FixCurrentSpeedLimits(NetInfo info) {
289+
if (info == null) {
290+
#if DEBUG
291+
Log.Warning($"SpeedLimitManager.FixCurrentSpeedLimits: info is null!");
292+
#endif
293+
return;
294+
}
295+
296+
if (info.name == null) {
297+
#if DEBUG
298+
Log.Warning($"SpeedLimitManager.FixCurrentSpeedLimits: info.name is null!");
299+
#endif
300+
return;
301+
}
302+
289303
if (!customizableNetInfos.Contains(info))
290304
return;
291305

@@ -308,6 +322,20 @@ public void FixCurrentSpeedLimits(NetInfo info) {
308322
/// </summary>
309323
/// <param name="info"></param>
310324
public void ClearCurrentSpeedLimits(NetInfo info) {
325+
if (info == null) {
326+
#if DEBUG
327+
Log.Warning($"SpeedLimitManager.ClearCurrentSpeedLimits: info is null!");
328+
#endif
329+
return;
330+
}
331+
332+
if (info.name == null) {
333+
#if DEBUG
334+
Log.Warning($"SpeedLimitManager.ClearCurrentSpeedLimits: info.name is null!");
335+
#endif
336+
return;
337+
}
338+
311339
if (!customizableNetInfos.Contains(info))
312340
return;
313341

@@ -330,8 +358,26 @@ public void ClearCurrentSpeedLimits(NetInfo info) {
330358
/// <param name="roundToSignLimits">if true, custom speed limit are rounded to speed limits available as speed limit sign</param>
331359
/// <returns></returns>
332360
public ushort GetVanillaNetInfoSpeedLimit(NetInfo info, bool roundToSignLimits = true) {
333-
if (info.m_netAI == null)
361+
if (info == null) {
362+
#if DEBUG
363+
Log.Warning($"SpeedLimitManager.GetVanillaNetInfoSpeedLimit: info is null!");
364+
#endif
334365
return 0;
366+
}
367+
368+
if (info.m_netAI == null) {
369+
#if DEBUG
370+
Log.Warning($"SpeedLimitManager.GetVanillaNetInfoSpeedLimit: info.m_netAI is null!");
371+
#endif
372+
return 0;
373+
}
374+
375+
if (info.name == null) {
376+
#if DEBUG
377+
Log.Warning($"SpeedLimitManager.GetVanillaNetInfoSpeedLimit: info.name is null!");
378+
#endif
379+
return 0;
380+
}
335381

336382
/*if (! (info.m_netAI is RoadBaseAI))
337383
return 0;*/
@@ -361,8 +407,19 @@ public ushort GetVanillaNetInfoSpeedLimit(NetInfo info, bool roundToSignLimits =
361407
/// <param name="info">the NetInfo of which the custom speed limit should be determined</param>
362408
/// <returns></returns>
363409
public int GetCustomNetInfoSpeedLimitIndex(NetInfo info) {
364-
if (info.m_netAI == null)
410+
if (info == null) {
411+
#if DEBUG
412+
Log.Warning($"SpeedLimitManager.SetCustomNetInfoSpeedLimitIndex: info is null!");
413+
#endif
365414
return -1;
415+
}
416+
417+
if (info.name == null) {
418+
#if DEBUG
419+
Log.Warning($"SpeedLimitManager.SetCustomNetInfoSpeedLimitIndex: info.name is null!");
420+
#endif
421+
return -1;
422+
}
366423

367424
/*if (!(info.m_netAI is RoadBaseAI))
368425
return -1;*/
@@ -381,8 +438,19 @@ public int GetCustomNetInfoSpeedLimitIndex(NetInfo info) {
381438
/// <param name="info">the NetInfo for which the custom speed limit should be set</param>
382439
/// <returns></returns>
383440
public void SetCustomNetInfoSpeedLimitIndex(NetInfo info, int customSpeedLimitIndex) {
384-
if (info.m_netAI == null)
441+
if (info == null) {
442+
#if DEBUG
443+
Log.Warning($"SetCustomNetInfoSpeedLimitIndex: info is null!");
444+
#endif
445+
return;
446+
}
447+
448+
if (info.name == null) {
449+
#if DEBUG
450+
Log.Warning($"SetCustomNetInfoSpeedLimitIndex: info.name is null!");
451+
#endif
385452
return;
453+
}
386454

387455
/*if (!(info.m_netAI is RoadBaseAI))
388456
return;*/
@@ -402,6 +470,7 @@ public void SetCustomNetInfoSpeedLimitIndex(NetInfo info, int customSpeedLimitIn
402470
foreach (string childNetInfoName in childNetInfoNamesByCustomizableNetInfoName[infoName]) {
403471
if (NetInfoByName.ContainsKey(childNetInfoName)) {
404472
Log._Debug($"Updating child NetInfo {childNetInfoName}: Setting speed limit to {gameSpeedLimit}");
473+
CustomLaneSpeedLimitIndexByNetInfoName[childNetInfoName] = customSpeedLimitIndex;
405474
UpdateNetInfoGameSpeedLimit(NetInfoByName[childNetInfoName], gameSpeedLimit);
406475
}
407476
}
@@ -410,7 +479,23 @@ public void SetCustomNetInfoSpeedLimitIndex(NetInfo info, int customSpeedLimitIn
410479

411480
private void UpdateNetInfoGameSpeedLimit(NetInfo info, float gameSpeedLimit) {
412481
if (info == null) {
413-
Log._Debug($"Updating speed limit of NetInfo: info is null!");
482+
#if DEBUG
483+
Log.Warning($"SpeedLimitManager.UpdateNetInfoGameSpeedLimit: info is null!");
484+
#endif
485+
return;
486+
}
487+
488+
if (info.name == null) {
489+
#if DEBUG
490+
Log.Warning($"SpeedLimitManager.UpdateNetInfoGameSpeedLimit: info.name is null!");
491+
#endif
492+
return;
493+
}
494+
495+
if (info.m_lanes == null) {
496+
#if DEBUG
497+
Log.Warning($"SpeedLimitManager.UpdateNetInfoGameSpeedLimit: info.name is null!");
498+
#endif
414499
return;
415500
}
416501

@@ -449,6 +534,21 @@ public bool SetSpeedLimit(ushort segmentId, NetInfo.Direction finalDir, ushort s
449534
}
450535

451536
NetInfo segmentInfo = Singleton<NetManager>.instance.m_segments.m_buffer[segmentId].Info;
537+
538+
if (segmentInfo == null) {
539+
#if DEBUG
540+
Log.Warning($"SpeedLimitManager.SetSpeedLimit: info is null!");
541+
#endif
542+
return false;
543+
}
544+
545+
if (segmentInfo.m_lanes == null) {
546+
#if DEBUG
547+
Log.Warning($"SpeedLimitManager.SetSpeedLimit: info.name is null!");
548+
#endif
549+
return false;
550+
}
551+
452552
uint curLaneId = Singleton<NetManager>.instance.m_segments.m_buffer[segmentId].m_lanes;
453553
int laneIndex = 0;
454554
while (laneIndex < segmentInfo.m_lanes.Length && curLaneId != 0u) {
@@ -648,21 +748,26 @@ public bool LoadData(List<Configuration.LaneSpeedLimit> data) {
648748
Log.Info($"Loading lane speed limit data. {data.Count} elements");
649749
foreach (Configuration.LaneSpeedLimit laneSpeedLimit in data) {
650750
try {
651-
if (!NetUtil.IsLaneValid(laneSpeedLimit.laneId))
751+
if (!NetUtil.IsLaneValid(laneSpeedLimit.laneId)) {
752+
Log._Debug($"SpeedLimitManager.LoadData: Skipping lane {laneSpeedLimit.laneId}: Lane is invalid");
652753
continue;
754+
}
653755

654756
ushort segmentId = Singleton<NetManager>.instance.m_lanes.m_buffer[laneSpeedLimit.laneId].m_segment;
655757
NetInfo info = Singleton<NetManager>.instance.m_segments.m_buffer[segmentId].Info;
656758
int customSpeedLimitIndex = GetCustomNetInfoSpeedLimitIndex(info);
759+
Log._Debug($"SpeedLimitManager.LoadData: Handling lane {laneSpeedLimit.laneId}: Custom speed limit index of segment {segmentId} info ({info}, name={info?.name}, lanes={info?.m_lanes} is {customSpeedLimitIndex}");
657760
if (customSpeedLimitIndex < 0 || AvailableSpeedLimits[customSpeedLimitIndex] != laneSpeedLimit.speedLimit) {
658761
// lane speed limit differs from default speed limit
659-
Log._Debug($"Loading lane speed limit: lane {laneSpeedLimit.laneId} = {laneSpeedLimit.speedLimit}");
762+
Log._Debug($"SpeedLimitManager.LoadData: Loading lane speed limit: lane {laneSpeedLimit.laneId} = {laneSpeedLimit.speedLimit}");
660763
Flags.setLaneSpeedLimit(laneSpeedLimit.laneId, laneSpeedLimit.speedLimit);
661764
SubscribeToSegmentGeometry(segmentId);
765+
} else {
766+
Log._Debug($"SpeedLimitManager.LoadData: Skipping lane speed limit of lane {laneSpeedLimit.laneId} ({laneSpeedLimit.speedLimit})");
662767
}
663768
} catch (Exception e) {
664769
// ignore, as it's probably corrupt save data. it'll be culled on next save
665-
Log.Warning("Error loading speed limits: " + e.ToString());
770+
Log.Warning("SpeedLimitManager.LoadData: Error loading speed limits: " + e.ToString());
666771
success = false;
667772
}
668773
}

TLM/TLM/TLM.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@
122122
<Compile Include="Geometry\SegmentEndGeometry.cs" />
123123
<Compile Include="Manager\VehicleStateManager.cs" />
124124
<Compile Include="Manager\VehicleRestrictionsManager.cs" />
125+
<Compile Include="Traffic\Template\JunctionRestrictionsTemplate.cs" />
126+
<Compile Include="Traffic\Template\JunctionTemplate.cs" />
127+
<Compile Include="Traffic\Template\LaneConnectionTemplate.cs" />
128+
<Compile Include="Traffic\Template\LaneTemplate.cs" />
129+
<Compile Include="Traffic\Template\SegmentEndTemplate.cs" />
130+
<Compile Include="Traffic\Template\SegmentEndLightsTemplate.cs" />
125131
<Compile Include="Traffic\VehicleJunctionTransitState.cs" />
126132
<Compile Include="State\Configuration.cs" />
127133
<Compile Include="Custom\AI\CustomCarAI.cs" />

TLM/TLM/TrafficManagerMod.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace TrafficManager {
66
public class TrafficManagerMod : IUserMod {
77

8-
public static readonly string Version = "1.8.10";
8+
public static readonly string Version = "1.8.11";
99

1010
public static readonly uint GameVersion = 159638032u;
1111
public static readonly uint GameVersionA = 1u;

0 commit comments

Comments
 (0)