Skip to content

Commit

Permalink
Automatic merge of T1.5.1-1430-g3fb566e8b and 13 pull requests
Browse files Browse the repository at this point in the history
- Pull request #892 at 1f5ba4c: Signal Function OPP_SIG_ID_TRAINPATH
- Pull request #961 at 8a9c8f9: Improvements for Power Supplies
- Pull request #981 at 067c009: Multiple type trainset lightglows
- Pull request #996 at 2fcbcde: Replace dynamic brakes by engine brakes at low speeds
- Pull request #1008 at e827fbd: Fix: TrainCarOperations doesn't work as expected after resume.
- Pull request #1009 at 80172b8: Fix: TrainCarViewer overlaps when display size changed
- Pull request #1010 at 6a1060f: Fix: TrainDrivingInfo window width not stable.
- Pull request #1012 at fbb87b0: doc:adds 3 news items to Manual
- Pull request #1014 at 3dbe81f: Bug fix for https://bugs.launchpad.net/or/+bug/2091895 Train disappears from train list window
- Pull request #900 at c27f32d: DMI updates
- Pull request #876 at f92de76: docs: add source for documents previously on website to source Documentation folder
- Pull request #896 at f1681df: First implementation of https://blueprints.launchpad.net/or/+spec/specific-sounds-for-ai-trains
- Pull request #1003 at c734592: Clean up logging during loading #or-std-log
  • Loading branch information
openrails-bot committed Dec 18, 2024
15 parents b47fff6 + 3fb566e + 1f5ba4c + 8a9c8f9 + 067c009 + 2fcbcde + e827fbd + 80172b8 + 6a1060f + fbb87b0 + 3dbe81f + c27f32d + f92de76 + f1681df + c734592 commit 62ec256
Show file tree
Hide file tree
Showing 7 changed files with 197 additions and 4 deletions.
15 changes: 15 additions & 0 deletions Source/Documentation/Manual/sound.rst
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,21 @@ Trigger Function
322 BoosterCylinderCocksClose
========= =====================================

Following triggers referring to locomotive and train type are available:

========= =====================================
Trigger Function
========= =====================================
330 AITrainLeadLoco
331 AITrainHelperLoco
332 PlayerTrainLeadLoco
333 PlayerTrainHelperLoco
334 AITrainApproachingStation
335 AITrainLeavingStation
336 StaticTrainLoco
========= =====================================


Variable Triggers
-----------------

Expand Down
18 changes: 18 additions & 0 deletions Source/Orts.Simulation/Common/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ public interface EventHandler
public enum Event
{
None,
AITrainApproachingStation,
AITrainHelperLoco,
AITrainLeadLoco,
AITrainLeavingStation,
PlayerTrainHelperLoco,
PlayerTrainLeadLoco,
StaticTrainLoco,
EndAITrainLeadLoco,
BatterySwitchOff,
BatterySwitchOn,
BatterySwitchCommandOff,
Expand Down Expand Up @@ -572,6 +580,16 @@ public static Event From(Source source, int eventID)
case 321: return Event.BoosterCylinderCocksOpen;
case 322: return Event.BoosterCylinderCocksClose;

// AI train related events
case 330: return Event.AITrainLeadLoco;
case 331: return Event.AITrainHelperLoco;
case 332: return Event.PlayerTrainLeadLoco;
case 333: return Event.PlayerTrainHelperLoco;
case 334: return Event.AITrainApproachingStation;
case 335: return Event.AITrainLeavingStation;
case 336: return Event.StaticTrainLoco;
case 337: return Event.EndAITrainLeadLoco;

default: return 0;
}
case Source.MSTSCrossing:
Expand Down
18 changes: 17 additions & 1 deletion Source/Orts.Simulation/Simulation/AIs/AITrain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public class AITrain : Train
public float DoorOpenTimer = -1f;
public float DoorCloseTimer = -1f;
public AILevelCrossingHornPattern LevelCrossingHornPattern { get; set; }
public bool ApproachTriggerSet = false; // station approach trigger for AI trains has been set

public float PathLength;

Expand Down Expand Up @@ -246,6 +247,7 @@ public AITrain(Simulator simulator, BinaryReader inf, AI airef)
UncondAttach = inf.ReadBoolean();
DoorCloseTimer = inf.ReadSingle();
DoorOpenTimer = inf.ReadSingle();
ApproachTriggerSet = inf.ReadBoolean();
if (!Simulator.TimetableMode && DoorOpenTimer <= 0 && DoorCloseTimer > 0 && Simulator.OpenDoorsInAITrains &&
MovementState == AI_MOVEMENT_STATE.STATION_STOP && StationStops.Count > 0)
{
Expand Down Expand Up @@ -339,6 +341,7 @@ public override void Save(BinaryWriter outf)
outf.Write(UncondAttach);
outf.Write(DoorCloseTimer);
outf.Write(DoorOpenTimer);
outf.Write(ApproachTriggerSet);
if (LevelCrossingHornPattern != null)
{
outf.Write(0);
Expand Down Expand Up @@ -1302,6 +1305,7 @@ public virtual void SetNextStationAction(bool fromAutopilotSwitch = false)
AIActionItem newAction = new AIActionItem(null, AIActionItem.AI_ACTION_TYPE.STATION_STOP);
newAction.SetParam(distancesM[1], 0.0f, distancesM[0], DistanceTravelledM);
requiredActions.InsertAction(newAction);
ApproachTriggerSet = false;

#if DEBUG_REPORTS
if (StationStops[0].ActualStopType == StationStop.STOPTYPE.STATION_STOP)
Expand Down Expand Up @@ -2061,6 +2065,7 @@ public virtual void UpdateStationState(float elapsedClockSeconds, int presentTim

Delay = TimeSpan.FromSeconds((presentTime - thisStation.DepartTime) % (24 * 3600));
}
if (Cars[0] is MSTSLocomotive) Cars[0].SignalEvent(Event.AITrainLeavingStation);

#if DEBUG_REPORTS
DateTime baseDTd = new DateTime();
Expand Down Expand Up @@ -2622,6 +2627,13 @@ public virtual void UpdateBrakingState(float elapsedClockSeconds, int presentTim
}
}

if (nextActionInfo != null && nextActionInfo.NextAction == AIActionItem.AI_ACTION_TYPE.STATION_STOP &&
distanceToGoM < 150 + StationStops[0].PlatformItem.Length && !ApproachTriggerSet)
{
if (Cars[0] is MSTSLocomotive) Cars[0].SignalEvent(Event.AITrainApproachingStation);
ApproachTriggerSet = true;
}

if (nextActionInfo != null && nextActionInfo.NextAction == AIActionItem.AI_ACTION_TYPE.STATION_STOP)
creepDistanceM = 0.0f;
if (nextActionInfo == null && requiredSpeedMpS == 0)
Expand Down Expand Up @@ -4369,6 +4381,8 @@ public void CoupleAI(Train attachTrain, bool thisTrainFront, bool attachTrainFro
AI.AITrains.Add(this);
AI.aiListChanged = true;
}
else
attachTrain.RedefineSoundTriggers();
if (!UncondAttach)
{
RemoveTrain();
Expand Down Expand Up @@ -4477,6 +4491,7 @@ public void CoupleAIToStatic(Train attachTrain, bool thisTrainFront, bool attach
AddTrackSections();
ResetActions(true);
physicsUpdate(0);
RedefineSoundTriggers();
}

//================================================================================================//
Expand Down Expand Up @@ -4718,7 +4733,8 @@ public void TerminateCoupling(Train attachTrain, bool thisTrainFront, bool attac
// Move WP, if any, just under the loco;
AuxActionsContain.MoveAuxActionAfterReversal(this);
ResetActions(true);

RedefineSoundTriggers();
attachTrain.RedefineSoundTriggers();
physicsUpdate(0);// Stop the wheels from moving etc

}
Expand Down
79 changes: 78 additions & 1 deletion 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,6 +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;
RedefineSoundTriggers();
}

/// <summary>
Expand Down Expand Up @@ -13831,6 +13833,81 @@ public string GetTrainName(string ID)
return ID.Substring(0, location - 1);
}

//================================================================================================//
/// <summary>
/// Redefine sound triggers for AI trains
/// </summary>
public void RedefineAITriggers()
{
var leadFound = false;
foreach (var car in Cars)
{
if (car is MSTSLocomotive)
{
if (!leadFound)
{
car.SignalEvent(Event.AITrainLeadLoco);
leadFound = true;
}
else
{
car.SignalEvent(Event.AITrainHelperLoco);
car.SignalEvent(Event.EndAITrainLeadLoco);
}
}
}
}

//================================================================================================//
/// <summary>
/// Redefine sound triggers for Player Train
/// </summary>
public void RedefinePlayerTrainTriggers()
{
Simulator.PlayerLocomotive.SignalEvent(Event.PlayerTrainLeadLoco);
foreach (var car in Cars)
{
if (car is MSTSLocomotive)
{
if (car != Simulator.PlayerLocomotive)
{
car.SignalEvent(Event.PlayerTrainHelperLoco);
}
car.SignalEvent(Event.EndAITrainLeadLoco);
}
}
}

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

//================================================================================================//
/// <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
29 changes: 28 additions & 1 deletion Source/Orts.Simulation/Simulation/Simulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -755,14 +755,20 @@ public void SetWagonCommandReceivers(MSTSWagon wag)
public TrainCar SetPlayerLocomotive(Train playerTrain)
{
TrainCar PlayerLocomotive = null;
var leadFound = false;
foreach (TrainCar car in playerTrain.Cars)
if (car.IsDriveable) // first loco is the one the player drives
{
if (!leadFound)
{
PlayerLocomotive = car;
playerTrain.LeadLocomotive = car;
playerTrain.InitializeBrakes();
PlayerLocomotive.LocalThrottlePercent = playerTrain.AITrainThrottlePercent;
break;
PlayerLocomotive.SignalEvent(Event.PlayerTrainLeadLoco);
leadFound = true;
}
else car.SignalEvent(Event.PlayerTrainHelperLoco);
}
if (PlayerLocomotive == null)
throw new InvalidDataException("Can't find player locomotive in activity");
Expand Down Expand Up @@ -982,6 +988,7 @@ private void FinishCoupling(Train drivenTrain, Train train, bool couple_to_front
}
drivenTrain.Cars.Clear();
AI.TrainsToRemoveFromAI.Add((AITrain)train);
PlayerLocomotive.SignalEvent(Event.PlayerTrainHelperLoco);
PlayerLocomotive = SetPlayerLocomotive(train);
(train as AITrain).SwitchToPlayerControl();
OnPlayerLocomotiveChanged();
Expand Down Expand Up @@ -1096,6 +1103,7 @@ public void CheckForCoupling(Train drivenTrain, float elapsedClockSeconds)
{
drivenTrain.Cars.Add(car);
car.Train = drivenTrain;
if (car is MSTSLocomotive) car.SignalEvent(Event.PlayerTrainHelperLoco);
}
FinishRearCoupling(drivenTrain, train, true);
return;
Expand Down Expand Up @@ -1126,6 +1134,7 @@ public void CheckForCoupling(Train drivenTrain, float elapsedClockSeconds)
drivenTrain.Cars.Add(car);
car.Train = drivenTrain;
car.Flipped = !car.Flipped;
if (car is MSTSLocomotive) car.SignalEvent(Event.PlayerTrainHelperLoco);
}
FinishRearCoupling(drivenTrain, train, false);
return;
Expand Down Expand Up @@ -1190,6 +1199,7 @@ public void CheckForCoupling(Train drivenTrain, float elapsedClockSeconds)
TrainCar car = train.Cars[i];
drivenTrain.Cars.Insert(i, car);
car.Train = drivenTrain;
if (car is MSTSLocomotive) car.SignalEvent(Event.PlayerTrainHelperLoco);
}
if (drivenTrain.LeadLocomotiveIndex >= 0) drivenTrain.LeadLocomotiveIndex += train.Cars.Count;
FinishFrontCoupling(drivenTrain, train, lead, true);
Expand Down Expand Up @@ -1223,6 +1233,7 @@ public void CheckForCoupling(Train drivenTrain, float elapsedClockSeconds)
drivenTrain.Cars.Insert(0, car);
car.Train = drivenTrain;
car.Flipped = !car.Flipped;
if (car is MSTSLocomotive) car.SignalEvent(Event.PlayerTrainHelperLoco);
}
if (drivenTrain.LeadLocomotiveIndex >= 0) drivenTrain.LeadLocomotiveIndex += train.Cars.Count;
FinishFrontCoupling(drivenTrain, train, lead, false);
Expand Down Expand Up @@ -1831,6 +1842,19 @@ public void UncoupleBehind(TrainCar car, bool keepFront)
train2.TrainType = Train.TRAINTYPE.AI;
train.IncorporatedTrainNo = -1;
train2.MUDirection = Direction.Forward;
var leadFound = false;
foreach (var trainCar in train2.Cars)
{
if (trainCar is MSTSLocomotive)
{
if (!leadFound)
{
trainCar.SignalEvent(Event.AITrainLeadLoco);
leadFound = true;
}
}
else trainCar.SignalEvent(Event.AITrainHelperLoco);
}
}
else train2.TrainType = Train.TRAINTYPE.STATIC;
train2.LeadLocomotive = null;
Expand Down Expand Up @@ -1958,6 +1982,8 @@ private void StartSwitchPlayerTrain()
// and now switch!
playerTrain.TrainType = Train.TRAINTYPE.AI;
if (!TimetableMode) AI.AITrains.Add(playerTrain);
playerTrain.Autopilot = false;
playerTrain.RedefineAITriggers();
if (TrainSwitcher.SuspendOldPlayer)
{
playerTrain.MovementState = AITrain.AI_MOVEMENT_STATE.SUSPENDED;
Expand Down Expand Up @@ -2157,6 +2183,7 @@ private void CompleteSwitchPlayerTrain()
PlayerLocomotive.Train.CreatePathlessPlayerTrain();
}
var playerLocomotive = PlayerLocomotive as MSTSLocomotive;
PlayerLocomotive.Train.RedefinePlayerTrainTriggers();
playerLocomotive.UsingRearCab = (PlayerLocomotive.Flipped ^ PlayerLocomotive.Train.MUDirection == Direction.Reverse) && (playerLocomotive.HasRearCab || playerLocomotive.HasRear3DCab);
OnPlayerLocomotiveChanged();
playerSwitchOngoing = false;
Expand Down
Loading

0 comments on commit 62ec256

Please sign in to comment.