Skip to content

Commit 801ad4a

Browse files
committed
Extend to all timetable mode setting of specific sound triggers
1 parent db032e7 commit 801ad4a

File tree

5 files changed

+52
-11
lines changed

5 files changed

+52
-11
lines changed

Source/Documentation/Manual/sound.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ Trigger Function
441441
333 PlayerTrainHelperLoco
442442
334 AITrainApproachingStation
443443
335 AITrainLeavingStation
444+
336 StaticTrainLoco
444445
========= =====================================
445446

446447

Source/Orts.Simulation/Common/Events.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public enum Event
3333
AITrainLeavingStation,
3434
PlayerTrainHelperLoco,
3535
PlayerTrainLeadLoco,
36+
StaticTrainLoco,
3637
BatterySwitchOff,
3738
BatterySwitchOn,
3839
BatterySwitchCommandOff,
@@ -574,6 +575,7 @@ public static Event From(Source source, int eventID)
574575
case 333: return Event.PlayerTrainHelperLoco;
575576
case 334: return Event.AITrainApproachingStation;
576577
case 335: return Event.AITrainLeavingStation;
578+
case 336: return Event.StaticTrainLoco;
577579

578580
default: return 0;
579581
}

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4381,7 +4381,8 @@ 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) attachTrain.RedefineAITriggers();
4384+
else
4385+
attachTrain.RedefineSoundTriggers();
43854386
if (!UncondAttach)
43864387
{
43874388
RemoveTrain();
@@ -4490,7 +4491,7 @@ public void CoupleAIToStatic(Train attachTrain, bool thisTrainFront, bool attach
44904491
AddTrackSections();
44914492
ResetActions(true);
44924493
physicsUpdate(0);
4493-
RedefineAITriggers();
4494+
RedefineSoundTriggers();
44944495
}
44954496

44964497
//================================================================================================//
@@ -4732,8 +4733,8 @@ public void TerminateCoupling(Train attachTrain, bool thisTrainFront, bool attac
47324733
// Move WP, if any, just under the loco;
47334734
AuxActionsContain.MoveAuxActionAfterReversal(this);
47344735
ResetActions(true);
4735-
RedefineAITriggers();
4736-
if (attachTrain is AITrain) attachTrain.RedefineAITriggers();
4736+
RedefineSoundTriggers();
4737+
attachTrain.RedefineSoundTriggers();
47374738
physicsUpdate(0);// Stop the wheels from moving etc
47384739

47394740
}

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

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ public enum TRAINTYPE
215215
AI_NOTSTARTED,
216216
AI_AUTOGENERATE,
217217
REMOTE,
218-
AI_PLAYERDRIVEN, //Player is on board and is durrently driving train
218+
AI_PLAYERDRIVEN, //Player is on board and is currently driving train
219219
AI_PLAYERHOSTING, //Player is on board, but train is currently autopiloted
220220
AI_INCORPORATED // AI train is incorporated in other train
221221
}
@@ -1504,6 +1504,7 @@ public void ReverseFormation(bool setMUParameters)
15041504
MUReverserPercent = -MUReverserPercent;
15051505
}
15061506
if (!((this is AITrain && Simulator.PreUpdate) || this.TrainType == TRAINTYPE.STATIC)) FormationReversed = true;
1507+
RedefineSoundTriggers();
15071508
}
15081509

15091510
//================================================================================================//
@@ -1538,8 +1539,7 @@ public void ReverseCars()
15381539
// Update flipped state of each car.
15391540
for (var i = 0; i < Cars.Count; i++)
15401541
Cars[i].Flipped = !Cars[i].Flipped;
1541-
// if AI train redefine first loco for sound
1542-
if (TrainType == TRAINTYPE.AI) RedefineAITriggers();
1542+
RedefineSoundTriggers();
15431543
}
15441544

15451545
/// <summary>
@@ -13870,6 +13870,33 @@ public void RedefinePlayerTrainTriggers()
1387013870
}
1387113871
}
1387213872

13873+
//================================================================================================//
13874+
/// <summary>
13875+
/// Redefine sound triggers for static trains
13876+
/// </summary>
13877+
public void RedefineStaticTrainTriggers()
13878+
{
13879+
foreach (var car in Cars)
13880+
{
13881+
if (car is MSTSLocomotive)
13882+
car.SignalEvent(Event.StaticTrainLoco);
13883+
}
13884+
}
13885+
13886+
//================================================================================================//
13887+
/// <summary>
13888+
/// Redefine sound triggers
13889+
/// </summary>
13890+
public void RedefineSoundTriggers()
13891+
{
13892+
if (TrainType == TRAINTYPE.PLAYER || TrainType == TRAINTYPE.AI_PLAYERDRIVEN || TrainType == TRAINTYPE.AI_PLAYERHOSTING)
13893+
RedefinePlayerTrainTriggers();
13894+
else if (TrainType == TRAINTYPE.AI)
13895+
RedefineAITriggers();
13896+
else
13897+
RedefineStaticTrainTriggers();
13898+
}
13899+
1387313900
//================================================================================================//
1387413901

1387513902
/// <summary>

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3875,10 +3875,7 @@ public override void UpdateStationState(float elapsedClockSeconds, int presentTi
38753875

38763876
// Reverse formation
38773877
ReverseFormation(false);
3878-
if (TrainType == TRAINTYPE.PLAYER)
3879-
RedefinePlayerTrainTriggers();
3880-
else if (TrainType == TRAINTYPE.AI)
3881-
RedefineAITriggers();
3878+
RedefineSoundTriggers();
38823879

38833880

38843881

@@ -6429,6 +6426,7 @@ public void InitalizePlayerTrain()
64296426
}
64306427

64316428
PowerState = true;
6429+
RedefinePlayerTrainTriggers();
64326430
}
64336431

64346432
//================================================================================================//
@@ -9396,6 +9394,8 @@ public void FormTrainFromAI(int presentTime)
93969394
// Reinstate as to be started (note : train is not yet removed from reference)
93979395
AI.StartList.InsertTrain(formedTrain);
93989396
}
9397+
9398+
RedefineSoundTriggers();
93999399
}
94009400
}
94019401

@@ -11794,6 +11794,7 @@ public void TTCouple(TTTrain attachTrain, bool thisTrainFront, bool attachTrainF
1179411794
{
1179511795
attachTrain.InitializeBrakes();
1179611796
}
11797+
attachTrain.RedefineSoundTriggers();
1179711798

1179811799
// Update route positions if required
1179911800
int trainRearPositionIndex = attachTrain.ValidRoute[0].GetRouteIndex(tempRoute.First().TCSectionIndex, 0);
@@ -12097,6 +12098,9 @@ public int TTUncoupleBehind(TTTrain newTrain, bool reverseTrain, int leadLocomot
1209712098
DelayedStartState = AI_START_MOVEMENT.PATH_ACTION;
1209812099
}
1209912100

12101+
// redefine sound triggers
12102+
RedefineSoundTriggers();
12103+
1210012104
// Return new lead locomotive position
1210112105
return newLeadLocomotiveIndex;
1210212106
}
@@ -12469,6 +12473,7 @@ public int CreateStaticTrain(TTTrain train, ref List<TTTrain> trainList, string
1246912473
formedTrain.AI = train.AI;
1247012474

1247112475
trainList.Add(formedTrain);
12476+
formedTrain.RedefineStaticTrainTriggers();
1247212477
return formedTrain.Number;
1247312478
}
1247412479

@@ -13815,6 +13820,8 @@ public bool PerformDetach(TTTrain train, bool allowPlayerSelect)
1381513820
}
1381613821
}
1381713822
}
13823+
train.RedefineSoundTriggers();
13824+
newTrain.RedefineSoundTriggers();
1381813825
}
1381913826

1382013827
return true;
@@ -13911,6 +13918,9 @@ public void DetachPlayerTrain(TTTrain train, int newTrainNumber)
1391113918
Trace.TraceInformation("Player switched to train : " + newTrain.Name);
1391213919
}
1391313920

13921+
train.RedefineSoundTriggers();
13922+
newTrain.RedefineSoundTriggers();
13923+
1391413924
train.DetachPending = false; // Detach completed
1391513925
}
1391613926

0 commit comments

Comments
 (0)