Skip to content

Commit db032e7

Browse files
committed
Extend checks to state what triggers are enabled
1 parent 838c314 commit db032e7

File tree

4 files changed

+51
-44
lines changed

4 files changed

+51
-44
lines changed

Source/Orts.Simulation/Simulation/AIs/AITrain.cs

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4381,7 +4381,7 @@ public void CoupleAI(Train attachTrain, bool thisTrainFront, bool attachTrainFro
43814381
AI.AITrains.Add(this);
43824382
AI.aiListChanged = true;
43834383
}
4384-
else if (attachTrain is AITrain) RedefineAITriggers(attachTrain as AITrain);
4384+
else if (attachTrain is AITrain) attachTrain.RedefineAITriggers();
43854385
if (!UncondAttach)
43864386
{
43874387
RemoveTrain();
@@ -4490,7 +4490,7 @@ public void CoupleAIToStatic(Train attachTrain, bool thisTrainFront, bool attach
44904490
AddTrackSections();
44914491
ResetActions(true);
44924492
physicsUpdate(0);
4493-
RedefineAITriggers(this);
4493+
RedefineAITriggers();
44944494
}
44954495

44964496
//================================================================================================//
@@ -4732,8 +4732,8 @@ public void TerminateCoupling(Train attachTrain, bool thisTrainFront, bool attac
47324732
// Move WP, if any, just under the loco;
47334733
AuxActionsContain.MoveAuxActionAfterReversal(this);
47344734
ResetActions(true);
4735-
RedefineAITriggers(this);
4736-
if (attachTrain is AITrain) RedefineAITriggers(attachTrain as AITrain);
4735+
RedefineAITriggers();
4736+
if (attachTrain is AITrain) attachTrain.RedefineAITriggers();
47374737
physicsUpdate(0);// Stop the wheels from moving etc
47384738

47394739
}
@@ -6595,43 +6595,6 @@ public void RestartWaitingTrain(RestartWaitingTrain restartWaitingTrain)
65956595
}
65966596
}
65976597

6598-
//================================================================================================//
6599-
/// <summary>
6600-
/// Redefine sound triggers for AI trains
6601-
/// </summary>
6602-
public void RedefineAITriggers(AITrain train)
6603-
{
6604-
var leadFound = false;
6605-
foreach (var car in train.Cars)
6606-
{
6607-
if (car is MSTSLocomotive)
6608-
{
6609-
if (!leadFound)
6610-
{
6611-
car.SignalEvent(Event.AITrainLeadLoco);
6612-
leadFound = true;
6613-
}
6614-
else car.SignalEvent(Event.AITrainHelperLoco);
6615-
}
6616-
}
6617-
}
6618-
6619-
//================================================================================================//
6620-
/// <summary>
6621-
/// Redefine sound triggers for Player Train
6622-
/// </summary>
6623-
public void RedefinePlayerTrainTriggers(AITrain train)
6624-
{
6625-
Simulator.PlayerLocomotive.SignalEvent(Event.PlayerTrainLeadLoco);
6626-
foreach (var car in train.Cars)
6627-
{
6628-
if (car is MSTSLocomotive && car != Simulator.PlayerLocomotive)
6629-
{
6630-
car.SignalEvent(Event.PlayerTrainHelperLoco);
6631-
}
6632-
}
6633-
}
6634-
66356598
}
66366599

66376600

Source/Orts.Simulation/Simulation/Physics/Train.cs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1539,7 +1539,7 @@ public void ReverseCars()
15391539
for (var i = 0; i < Cars.Count; i++)
15401540
Cars[i].Flipped = !Cars[i].Flipped;
15411541
// if AI train redefine first loco for sound
1542-
if (TrainType == TRAINTYPE.AI) (this as AITrain).RedefineAITriggers(this as AITrain);
1542+
if (TrainType == TRAINTYPE.AI) RedefineAITriggers();
15431543
}
15441544

15451545
/// <summary>
@@ -13833,6 +13833,43 @@ public string GetTrainName(string ID)
1383313833
return ID.Substring(0, location - 1);
1383413834
}
1383513835

13836+
//================================================================================================//
13837+
/// <summary>
13838+
/// Redefine sound triggers for AI trains
13839+
/// </summary>
13840+
public void RedefineAITriggers()
13841+
{
13842+
var leadFound = false;
13843+
foreach (var car in Cars)
13844+
{
13845+
if (car is MSTSLocomotive)
13846+
{
13847+
if (!leadFound)
13848+
{
13849+
car.SignalEvent(Event.AITrainLeadLoco);
13850+
leadFound = true;
13851+
}
13852+
else car.SignalEvent(Event.AITrainHelperLoco);
13853+
}
13854+
}
13855+
}
13856+
13857+
//================================================================================================//
13858+
/// <summary>
13859+
/// Redefine sound triggers for Player Train
13860+
/// </summary>
13861+
public void RedefinePlayerTrainTriggers()
13862+
{
13863+
Simulator.PlayerLocomotive.SignalEvent(Event.PlayerTrainLeadLoco);
13864+
foreach (var car in Cars)
13865+
{
13866+
if (car is MSTSLocomotive && car != Simulator.PlayerLocomotive)
13867+
{
13868+
car.SignalEvent(Event.PlayerTrainHelperLoco);
13869+
}
13870+
}
13871+
}
13872+
1383613873
//================================================================================================//
1383713874

1383813875
/// <summary>

Source/Orts.Simulation/Simulation/Simulator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1987,7 +1987,7 @@ private void StartSwitchPlayerTrain()
19871987
// and now switch!
19881988
playerTrain.TrainType = Train.TRAINTYPE.AI;
19891989
playerTrain.Autopilot = false;
1990-
(playerTrain as AITrain).RedefineAITriggers(playerTrain as AITrain);
1990+
playerTrain.RedefineAITriggers();
19911991
if (TrainSwitcher.SuspendOldPlayer)
19921992
{
19931993
playerTrain.MovementState = AITrain.AI_MOVEMENT_STATE.SUSPENDED;
@@ -2187,7 +2187,7 @@ private void CompleteSwitchPlayerTrain()
21872187
PlayerLocomotive.Train.CreatePathlessPlayerTrain();
21882188
}
21892189
var playerLocomotive = PlayerLocomotive as MSTSLocomotive;
2190-
(PlayerLocomotive.Train as AITrain).RedefinePlayerTrainTriggers(PlayerLocomotive.Train as AITrain);
2190+
PlayerLocomotive.Train.RedefinePlayerTrainTriggers();
21912191
playerLocomotive.UsingRearCab = (PlayerLocomotive.Flipped ^ PlayerLocomotive.Train.MUDirection == Direction.Reverse) && (playerLocomotive.HasRearCab || playerLocomotive.HasRear3DCab);
21922192
OnPlayerLocomotiveChanged();
21932193
playerSwitchOngoing = false;

Source/Orts.Simulation/Simulation/Timetables/TTTrain.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2936,6 +2936,7 @@ public override void UpdateAIStaticState(int presentTime)
29362936
}
29372937

29382938
TrainType = TRAINTYPE.PLAYER;
2939+
RedefinePlayerTrainTriggers();
29392940
}
29402941

29412942
PostInit(true);
@@ -3874,6 +3875,12 @@ public override void UpdateStationState(float elapsedClockSeconds, int presentTi
38743875

38753876
// Reverse formation
38763877
ReverseFormation(false);
3878+
if (TrainType == TRAINTYPE.PLAYER)
3879+
RedefinePlayerTrainTriggers();
3880+
else if (TrainType == TRAINTYPE.AI)
3881+
RedefineAITriggers();
3882+
3883+
38773884

38783885
// Get new route list indices from new route
38793886
DistanceTravelledM = 0;

0 commit comments

Comments
 (0)