Skip to content

Commit

Permalink
Extend to all timetable mode setting of specific sound triggers
Browse files Browse the repository at this point in the history
  • Loading branch information
Csantucci committed Dec 5, 2024
1 parent db032e7 commit 801ad4a
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 11 deletions.
1 change: 1 addition & 0 deletions Source/Documentation/Manual/sound.rst
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ Trigger Function
333 PlayerTrainHelperLoco
334 AITrainApproachingStation
335 AITrainLeavingStation
336 StaticTrainLoco
========= =====================================


Expand Down
2 changes: 2 additions & 0 deletions Source/Orts.Simulation/Common/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public enum Event
AITrainLeavingStation,
PlayerTrainHelperLoco,
PlayerTrainLeadLoco,
StaticTrainLoco,
BatterySwitchOff,
BatterySwitchOn,
BatterySwitchCommandOff,
Expand Down Expand Up @@ -574,6 +575,7 @@ public static Event From(Source source, int eventID)
case 333: return Event.PlayerTrainHelperLoco;
case 334: return Event.AITrainApproachingStation;
case 335: return Event.AITrainLeavingStation;
case 336: return Event.StaticTrainLoco;

default: return 0;
}
Expand Down
9 changes: 5 additions & 4 deletions Source/Orts.Simulation/Simulation/AIs/AITrain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4381,7 +4381,8 @@ public void CoupleAI(Train attachTrain, bool thisTrainFront, bool attachTrainFro
AI.AITrains.Add(this);
AI.aiListChanged = true;
}
else if (attachTrain is AITrain) attachTrain.RedefineAITriggers();
else
attachTrain.RedefineSoundTriggers();
if (!UncondAttach)
{
RemoveTrain();
Expand Down Expand Up @@ -4490,7 +4491,7 @@ public void CoupleAIToStatic(Train attachTrain, bool thisTrainFront, bool attach
AddTrackSections();
ResetActions(true);
physicsUpdate(0);
RedefineAITriggers();
RedefineSoundTriggers();
}

//================================================================================================//
Expand Down Expand Up @@ -4732,8 +4733,8 @@ public void TerminateCoupling(Train attachTrain, bool thisTrainFront, bool attac
// Move WP, if any, just under the loco;
AuxActionsContain.MoveAuxActionAfterReversal(this);
ResetActions(true);
RedefineAITriggers();
if (attachTrain is AITrain) attachTrain.RedefineAITriggers();
RedefineSoundTriggers();
attachTrain.RedefineSoundTriggers();
physicsUpdate(0);// Stop the wheels from moving etc

}
Expand Down
33 changes: 30 additions & 3 deletions Source/Orts.Simulation/Simulation/Physics/Train.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public enum TRAINTYPE
AI_NOTSTARTED,
AI_AUTOGENERATE,
REMOTE,
AI_PLAYERDRIVEN, //Player is on board and is durrently driving train
AI_PLAYERDRIVEN, //Player is on board and is currently driving train
AI_PLAYERHOSTING, //Player is on board, but train is currently autopiloted
AI_INCORPORATED // AI train is incorporated in other train
}
Expand Down Expand Up @@ -1504,6 +1504,7 @@ public void ReverseFormation(bool setMUParameters)
MUReverserPercent = -MUReverserPercent;
}
if (!((this is AITrain && Simulator.PreUpdate) || this.TrainType == TRAINTYPE.STATIC)) FormationReversed = true;
RedefineSoundTriggers();
}

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

/// <summary>
Expand Down Expand Up @@ -13870,6 +13870,33 @@ public void RedefinePlayerTrainTriggers()
}
}

//================================================================================================//
/// <summary>
/// Redefine sound triggers for static trains
/// </summary>
public void RedefineStaticTrainTriggers()
{
foreach (var car in Cars)
{
if (car is MSTSLocomotive)
car.SignalEvent(Event.StaticTrainLoco);
}
}

//================================================================================================//
/// <summary>
/// Redefine sound triggers
/// </summary>
public void RedefineSoundTriggers()
{
if (TrainType == TRAINTYPE.PLAYER || TrainType == TRAINTYPE.AI_PLAYERDRIVEN || TrainType == TRAINTYPE.AI_PLAYERHOSTING)
RedefinePlayerTrainTriggers();
else if (TrainType == TRAINTYPE.AI)
RedefineAITriggers();
else
RedefineStaticTrainTriggers();
}

//================================================================================================//

/// <summary>
Expand Down
18 changes: 14 additions & 4 deletions Source/Orts.Simulation/Simulation/Timetables/TTTrain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3875,10 +3875,7 @@ public override void UpdateStationState(float elapsedClockSeconds, int presentTi

// Reverse formation
ReverseFormation(false);
if (TrainType == TRAINTYPE.PLAYER)
RedefinePlayerTrainTriggers();
else if (TrainType == TRAINTYPE.AI)
RedefineAITriggers();
RedefineSoundTriggers();



Expand Down Expand Up @@ -6429,6 +6426,7 @@ public void InitalizePlayerTrain()
}

PowerState = true;
RedefinePlayerTrainTriggers();
}

//================================================================================================//
Expand Down Expand Up @@ -9396,6 +9394,8 @@ public void FormTrainFromAI(int presentTime)
// Reinstate as to be started (note : train is not yet removed from reference)
AI.StartList.InsertTrain(formedTrain);
}

RedefineSoundTriggers();
}
}

Expand Down Expand Up @@ -11794,6 +11794,7 @@ public void TTCouple(TTTrain attachTrain, bool thisTrainFront, bool attachTrainF
{
attachTrain.InitializeBrakes();
}
attachTrain.RedefineSoundTriggers();

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

// redefine sound triggers
RedefineSoundTriggers();

// Return new lead locomotive position
return newLeadLocomotiveIndex;
}
Expand Down Expand Up @@ -12469,6 +12473,7 @@ public int CreateStaticTrain(TTTrain train, ref List<TTTrain> trainList, string
formedTrain.AI = train.AI;

trainList.Add(formedTrain);
formedTrain.RedefineStaticTrainTriggers();
return formedTrain.Number;
}

Expand Down Expand Up @@ -13815,6 +13820,8 @@ public bool PerformDetach(TTTrain train, bool allowPlayerSelect)
}
}
}
train.RedefineSoundTriggers();
newTrain.RedefineSoundTriggers();
}

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

train.RedefineSoundTriggers();
newTrain.RedefineSoundTriggers();

train.DetachPending = false; // Detach completed
}

Expand Down

0 comments on commit 801ad4a

Please sign in to comment.