Skip to content

Commit

Permalink
TM:PE 1.9.0-alpha3
Browse files Browse the repository at this point in the history
- Updated for game version 1.7.0-f2
- UI: More compact, movable main menu UI integrated
- New option: Main button position can be locked
- New option: Main menu position can be locked
- New option: Added language selection in options dialog
- New option: Customization of lane arrows, lane connections and vehicle restrictions can now come into effect instantaneously
- Path-finding cost multiplicator for vehicle restrictions is configurable in TMPE_GlobalConfig.xml
- Bugfix: Game crashes when trying to display a warning message while using CO's traffic light toggling feature on junctions having timed traffic lights (disabled displaying the message box)
- Bugfix: Timed traffic lights resets back to first step when clicking on an active junction
  • Loading branch information
VictorPhilipp committed Apr 22, 2017
1 parent e413c37 commit 42d6a21
Show file tree
Hide file tree
Showing 53 changed files with 1,177 additions and 237 deletions.
8 changes: 4 additions & 4 deletions TLM/TLM/Custom/AI/CustomRoadAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ public void CustomClickNodeButton(ushort nodeID, ref NetNode data, int index) {
/*data.m_flags ^= NetNode.Flags.TrafficLights;
data.m_flags |= NetNode.Flags.CustomTrafficLights;*/
// NON-STOCK CODE START
ToggleTrafficLightsTool toggleTool = (ToggleTrafficLightsTool)TrafficManagerTool.GetSubTool(ToolMode.SwitchTrafficLight);
toggleTool.ToggleTrafficLight(nodeID);
ToggleTrafficLightsTool toggleTool = (ToggleTrafficLightsTool)LoadingExtension.TrafficManagerTool.GetSubTool(ToolMode.SwitchTrafficLight);
toggleTool.ToggleTrafficLight(nodeID, false);
// NON-STOCK CODE END
this.UpdateNodeFlags(nodeID, ref data);
Singleton<NetManager>.instance.m_yieldLights.Disable();
Expand Down Expand Up @@ -729,7 +729,7 @@ public void OriginalSimulationStep(ushort segmentID, ref NetSegment data) { // s
// NON-STOCK CODE START
// Rainfall compatibility
float _roadwayFloodedTolerance = LoadingExtension.IsRainfallLoaded ? (float)PlayerPrefs.GetInt("RF_RoadwayFloodedTolerance", 100)/100f : 1f;
if (waterLevelAtMiddlePoint > middlePoint.y + _roadwayFloodedTolerance) {
if (waterLevelAtMiddlePoint > middlePoint.y + _roadwayFloodedTolerance && waterLevelAtMiddlePoint > 0f) {
flooded = true;
data.m_flags |= NetSegment.Flags.Flooded;
problem = Notification.AddProblems(problem, Notification.Problem.Flood | Notification.Problem.MajorProblem);
Expand All @@ -739,7 +739,7 @@ public void OriginalSimulationStep(ushort segmentID, ref NetSegment data) { // s
} else {
data.m_flags &= ~NetSegment.Flags.Flooded;
float _roadwayFloodingTolerance = LoadingExtension.IsRainfallLoaded ? (float)PlayerPrefs.GetInt("RF_RoadwayFloodingTolerance", 50)/100f : 0f;
if (waterLevelAtMiddlePoint > middlePoint.y + _roadwayFloodingTolerance) {
if (waterLevelAtMiddlePoint > middlePoint.y + _roadwayFloodingTolerance && waterLevelAtMiddlePoint > 0f) {
flooded = true;
problem = Notification.AddProblems(problem, Notification.Problem.Flood);
}
Expand Down
4 changes: 2 additions & 2 deletions TLM/TLM/Custom/PathFinding/CustomPathFind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2367,9 +2367,9 @@ private bool ProcessItemCosts(bool allowAdvancedAI, bool obeyStockLaneArrows, La
if (strictlyAvoidLane) {
#if DEBUGPF
if (debug)
logBuf.Add($"ProcessItemCosts: applying strict lane avoidance on deactivated advaned AI");
logBuf.Add($"ProcessItemCosts: applying strict lane avoidance");
#endif
prevCost *= 10000f;
prevCost *= _conf.VehicleRestrictionsPenalty;
}

if (!useAdvancedAI) {
Expand Down
11 changes: 10 additions & 1 deletion TLM/TLM/LoadingExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1941,6 +1941,8 @@ public override void OnLevelLoaded(LoadMode mode) {
manager.OnLevelLoading();
}

InitTool();

Log.Info("OnLevelLoaded complete.");
}

Expand Down Expand Up @@ -2005,12 +2007,19 @@ public static void SetToolMode(TrafficManagerMode mode) {
}
}

public static void EnableTool() {
public static void InitTool() {
Log.Info("Initializing traffic manager tool...");
if (TrafficManagerTool == null) {
TrafficManagerTool = ToolsModifierControl.toolController.gameObject.GetComponent<TrafficManagerTool>() ??
ToolsModifierControl.toolController.gameObject.AddComponent<TrafficManagerTool>();
}

TrafficManagerTool.Initialize();
}

public static void EnableTool() {
InitTool();

ToolsModifierControl.toolController.CurrentTool = TrafficManagerTool;
ToolsModifierControl.SetTool<TrafficManagerTool>();
}
Expand Down
14 changes: 12 additions & 2 deletions TLM/TLM/Manager/LaneArrowManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,30 @@ protected override void InternalPrintDebugInfo() {

public bool SetLaneArrows(uint laneId, LaneArrows flags, bool overrideHighwayArrows = false) {
if (Flags.setLaneArrowFlags(laneId, flags, overrideHighwayArrows)) {
SubscribeToSegmentGeometry(Singleton<NetManager>.instance.m_lanes.m_buffer[laneId].m_segment);
OnLaneChange(laneId);
return true;
}
return false;
}

public bool ToggleLaneArrows(uint laneId, bool startNode, LaneArrows flags, out LaneArrowChangeResult res) {
if (Flags.toggleLaneArrowFlags(laneId, startNode, flags, out res)) {
SubscribeToSegmentGeometry(Singleton<NetManager>.instance.m_lanes.m_buffer[laneId].m_segment);
OnLaneChange(laneId);
return true;
}
return false;
}

protected void OnLaneChange(uint laneId) {
Services.NetService.ProcessLane(laneId, delegate (uint lId, ref NetLane lane) {
SubscribeToSegmentGeometry(lane.m_segment);
if (Options.instantEffects) {
Services.NetService.PublishSegmentChanges(lane.m_segment);
}
return true;
});
}

protected override void HandleInvalidSegment(SegmentGeometry geometry) {
Flags.resetSegmentArrowFlags(geometry.SegmentId);
}
Expand Down
41 changes: 32 additions & 9 deletions TLM/TLM/Manager/LaneConnectionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ internal bool RemoveLaneConnection(uint laneId1, uint laneId2, bool startNode1)

UnsubscribeFromSegmentGeometry(segmentId1);
UnsubscribeFromSegmentGeometry(segmentId2);

if (Options.instantEffects) {
Services.NetService.PublishSegmentChanges(segmentId1);
Services.NetService.PublishSegmentChanges(segmentId2);
}
}

return ret;
Expand All @@ -152,13 +157,16 @@ internal void RemoveLaneConnectionsFromNode(ushort nodeId) {
#if DEBUGCONN
Log._Debug($"LaneConnectionManager.RemoveLaneConnectionsFromNode({nodeId}) called.");
#endif
NetManager netManager = Singleton<NetManager>.instance;
for (int i = 0; i < 8; ++i) {
ushort segmentId = netManager.m_nodes.m_buffer[nodeId].GetSegment(i);
if (segmentId == 0)
continue;

RemoveLaneConnectionsFromSegment(segmentId, netManager.m_segments.m_buffer[segmentId].m_startNode == nodeId);
Services.NetService.IterateNodeSegments(nodeId, delegate (ushort segmentId, ref NetSegment segment) {
RemoveLaneConnectionsFromSegment(segmentId, segment.m_startNode == nodeId);
return true;
});

if (Options.instantEffects) {
Services.NetService.IterateNodeSegments(nodeId, delegate (ushort segmentId, ref NetSegment segment) {
Services.NetService.PublishSegmentChanges(segmentId);
return true;
});
}
}

Expand All @@ -181,6 +189,10 @@ internal void RemoveLaneConnectionsFromSegment(ushort segmentId, bool startNode)
RemoveLaneConnections(curLaneId, startNode);
curLaneId = netManager.m_lanes.m_buffer[curLaneId].m_nextLane;
}

if (Options.instantEffects) {
Services.NetService.PublishSegmentChanges(segmentId);
}
}

/// <summary>
Expand Down Expand Up @@ -218,8 +230,14 @@ internal void RemoveLaneConnections(uint laneId, bool startNode) {
Flags.RemoveLaneConnections(laneId, startNode);

if (Flags.laneConnections[laneId] == null) {
ushort segmentId = netManager.m_lanes.m_buffer[laneId].m_segment;
UnsubscribeFromSegmentGeometry(segmentId);
Services.NetService.ProcessLane(laneId, delegate (uint lId, ref NetLane lane) {
UnsubscribeFromSegmentGeometry(lane.m_segment);

if (Options.instantEffects) {
Services.NetService.PublishSegmentChanges(lane.m_segment);
}
return true;
});
}
}

Expand Down Expand Up @@ -254,6 +272,11 @@ internal bool AddLaneConnection(uint laneId1, uint laneId2, bool startNode1) {

SubscribeToSegmentGeometry(segmentId1);
SubscribeToSegmentGeometry(segmentId2);

if (Options.instantEffects) {
Services.NetService.PublishSegmentChanges(segmentId1);
Services.NetService.PublishSegmentChanges(segmentId2);
}
}

return ret;
Expand Down
33 changes: 30 additions & 3 deletions TLM/TLM/Manager/VehicleRestrictionsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,12 @@ internal ExtVehicleType GetDefaultAllowedVehicleTypes(uint laneId) {
/// <param name="allowedTypes"></param>
/// <returns></returns>
internal bool SetAllowedVehicleTypes(ushort segmentId, NetInfo segmentInfo, uint laneIndex, NetInfo.Lane laneInfo, uint laneId, ExtVehicleType allowedTypes) {
if (segmentId == 0 || (Singleton<NetManager>.instance.m_segments.m_buffer[segmentId].m_flags & NetSegment.Flags.Created) == NetSegment.Flags.None || ((NetLane.Flags)Singleton<NetManager>.instance.m_lanes.m_buffer[laneId].m_flags & NetLane.Flags.Created) == NetLane.Flags.None) {
if (! Services.NetService.IsLaneValid(laneId)) {
return false;
}

if (! Services.NetService.IsSegmentValid(segmentId)) {
// TODO we do not need the segmentId given here. Lane is enough
return false;
}

Expand All @@ -218,6 +223,10 @@ internal bool SetAllowedVehicleTypes(ushort segmentId, NetInfo segmentInfo, uint
SubscribeToSegmentGeometry(segmentId);
NotifyStartEndNode(segmentId);

if (Options.instantEffects) {
Services.NetService.PublishSegmentChanges(segmentId);
}

return true;
}

Expand All @@ -231,7 +240,12 @@ internal bool SetAllowedVehicleTypes(ushort segmentId, NetInfo segmentInfo, uint
/// <param name="road"></param>
/// <param name="vehicleType"></param>
public void AddAllowedType(ushort segmentId, NetInfo segmentInfo, uint laneIndex, uint laneId, NetInfo.Lane laneInfo, ExtVehicleType vehicleType) {
if (segmentId == 0 || (Singleton<NetManager>.instance.m_segments.m_buffer[segmentId].m_flags & NetSegment.Flags.Created) == NetSegment.Flags.None || ((NetLane.Flags)Singleton<NetManager>.instance.m_lanes.m_buffer[laneId].m_flags & NetLane.Flags.Created) == NetLane.Flags.None) {
if (!Services.NetService.IsLaneValid(laneId)) {
return;
}

if (!Services.NetService.IsSegmentValid(segmentId)) {
// TODO we do not need the segmentId given here. Lane is enough
return;
}

Expand All @@ -241,6 +255,10 @@ public void AddAllowedType(ushort segmentId, NetInfo segmentInfo, uint laneIndex
Flags.setLaneAllowedVehicleTypes(segmentId, laneIndex, laneId, allowedTypes);
SubscribeToSegmentGeometry(segmentId);
NotifyStartEndNode(segmentId);

if (Options.instantEffects) {
Services.NetService.PublishSegmentChanges(segmentId);
}
}

/// <summary>
Expand All @@ -253,7 +271,12 @@ public void AddAllowedType(ushort segmentId, NetInfo segmentInfo, uint laneIndex
/// <param name="road"></param>
/// <param name="vehicleType"></param>
public void RemoveAllowedType(ushort segmentId, NetInfo segmentInfo, uint laneIndex, uint laneId, NetInfo.Lane laneInfo, ExtVehicleType vehicleType) {
if (segmentId == 0 || (Singleton<NetManager>.instance.m_segments.m_buffer[segmentId].m_flags & NetSegment.Flags.Created) == NetSegment.Flags.None || ((NetLane.Flags)Singleton<NetManager>.instance.m_lanes.m_buffer[laneId].m_flags & NetLane.Flags.Created) == NetLane.Flags.None) {
if (!Services.NetService.IsLaneValid(laneId)) {
return;
}

if (!Services.NetService.IsSegmentValid(segmentId)) {
// TODO we do not need the segmentId given here. Lane is enough
return;
}

Expand All @@ -263,6 +286,10 @@ public void RemoveAllowedType(ushort segmentId, NetInfo segmentInfo, uint laneIn
Flags.setLaneAllowedVehicleTypes(segmentId, laneIndex, laneId, allowedTypes);
SubscribeToSegmentGeometry(segmentId);
NotifyStartEndNode(segmentId);

if (Options.instantEffects) {
Services.NetService.PublishSegmentChanges(segmentId);
}
}

public void ToggleAllowedType(ushort segmentId, NetInfo segmentInfo, uint laneIndex, uint laneId, NetInfo.Lane laneInfo, ExtVehicleType vehicleType, bool add) {
Expand Down
9 changes: 8 additions & 1 deletion TLM/TLM/Resources/lang.txt
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,11 @@ Vehicle_behavior Vehicle behavior
Policies_&_Restrictions Policies & Restrictions
At_junctions At junctions
In_case_of_emergency In case of emergency
Show_lane-wise_speed_limits Show lane-wise speed limits
Show_lane-wise_speed_limits Show lane-wise speed limits
Language Language
Game_language Game language
requires_game_restart requires game restart
Customizations_come_into_effect_instantaneously Customizations come into effect instantaneously
Options Options
Lock_main_menu_button_position Lock main menu button position
Lock_main_menu_position Lock main menu position
Binary file added TLM/TLM/Resources/mainmenu-btns.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions TLM/TLM/State/GlobalConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ internal static void OnLevelUnloading() {
public ushort TTLDebugNodeId = 0;
#endif

/// <summary>
/// Language to use (if null then the game's language is being used)
/// </summary>
public string LanguageCode = null;

/// <summary>
/// base lane changing cost factor on highways
/// </summary>
Expand Down Expand Up @@ -150,6 +155,11 @@ internal static void OnLevelUnloading() {
/// </summary>
public float HeavyVehicleMaxInnerLanePenalty = 40f;

/// <summary>
/// Path cost multiplier for vehicle restrictions
/// </summary>
public float VehicleRestrictionsPenalty = 2500f;


/// <summary>
/// parking space search radius; used if pocket car spawning is disabled
Expand Down Expand Up @@ -292,6 +302,14 @@ internal static void OnLevelUnloading() {
/// </summary>
public int MainMenuButtonX = 464;
public int MainMenuButtonY = 10;
public bool MainMenuButtonPosLocked = false;

/// <summary>
/// Main menu position
/// </summary>
public int MainMenuX = 85;
public int MainMenuY = 60;
public bool MainMenuPosLocked = false;

internal static void WriteConfig() {
ModifiedTime = WriteConfig(Instance);
Expand Down
Loading

0 comments on commit 42d6a21

Please sign in to comment.