Skip to content

Commit

Permalink
Add end of loco being lead of an AI train
Browse files Browse the repository at this point in the history
  • Loading branch information
Csantucci committed Dec 13, 2024
1 parent 801ad4a commit f1681df
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Source/Orts.Simulation/Common/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public enum Event
PlayerTrainHelperLoco,
PlayerTrainLeadLoco,
StaticTrainLoco,
EndAITrainLeadLoco,
BatterySwitchOff,
BatterySwitchOn,
BatterySwitchCommandOff,
Expand Down Expand Up @@ -576,6 +577,7 @@ public static Event From(Source source, int eventID)
case 334: return Event.AITrainApproachingStation;
case 335: return Event.AITrainLeavingStation;
case 336: return Event.StaticTrainLoco;
case 337: return Event.EndAITrainLeadLoco;

default: return 0;
}
Expand Down
17 changes: 14 additions & 3 deletions Source/Orts.Simulation/Simulation/Physics/Train.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13849,7 +13849,11 @@ public void RedefineAITriggers()
car.SignalEvent(Event.AITrainLeadLoco);
leadFound = true;
}
else car.SignalEvent(Event.AITrainHelperLoco);
else
{
car.SignalEvent(Event.AITrainHelperLoco);
car.SignalEvent(Event.EndAITrainLeadLoco);
}
}
}
}
Expand All @@ -13863,9 +13867,13 @@ public void RedefinePlayerTrainTriggers()
Simulator.PlayerLocomotive.SignalEvent(Event.PlayerTrainLeadLoco);
foreach (var car in Cars)
{
if (car is MSTSLocomotive && car != Simulator.PlayerLocomotive)
if (car is MSTSLocomotive)
{
car.SignalEvent(Event.PlayerTrainHelperLoco);
if (car != Simulator.PlayerLocomotive)
{
car.SignalEvent(Event.PlayerTrainHelperLoco);
}
car.SignalEvent(Event.EndAITrainLeadLoco);
}
}
}
Expand All @@ -13879,7 +13887,10 @@ public void RedefineStaticTrainTriggers()
foreach (var car in Cars)
{
if (car is MSTSLocomotive)
{
car.SignalEvent(Event.StaticTrainLoco);
car.SignalEvent(Event.EndAITrainLeadLoco);
}
}
}

Expand Down

0 comments on commit f1681df

Please sign in to comment.