Skip to content

Commit 0642f10

Browse files
committed
Automatic merge of T1.5.1-1088-g264349b1ce and 21 pull requests
- Pull request #891 at 9a1d6b2: Auto save - Pull request #959 at 2452cb0: Fix TrackViewer crash on big zoom value - Pull request #972 at e90a2aa: On Map window color changed switch or signal is not changed - Pull request #839 at d00beb9: First phase of https://blueprints.launchpad.net/or/+spec/additional-cruise-control-parameters - Pull request #882 at 8f695a4: Blueprint/train car operations UI window - Pull request #892 at 1f5ba4c: Signal Function OPP_SIG_ID_TRAINPATH - Pull request #922 at a3bc9e7: Autopilot for timetable mode - Pull request #953 at a519452: Fix Lights Crash on Corrupt Shapes - Pull request #962 at 46d0472: Fix pantographs on unpowered cars - Pull request #970 at 6fa5eed: feat: Remove unnecessary Windows.Forms usage - Pull request #973 at c35be87: fix: Using singular target framework to allow for different platforms across different projects - Pull request #974 at 5faea6f: Bug fix for https://bugs.launchpad.net/or/+bug/2076034 Doors remain open in AI trains - Pull request #900 at c27f32d: DMI updates - Pull request #903 at 9dabe97: Downloading route content (Github, zip) - Pull request #799 at dfc715e: Consolidated wind simulation - Pull request #876 at f92de76: docs: add source for documents previously on website to source Documentation folder - Pull request #885 at 067662e: feat: Add notifications to Menu - Pull request #946 at 91a03af: Advanced track sounds - Pull request #952 at 8347095: Investigation - Pulsing graphics - Pull request #954 at f837ffd: Multiple Track Profiles & Superelevation Improvements - Pull request #968 at a88cb26: Initial build of adding track section identifier for rack railway
23 parents cdd9fb3 + 264349b + 9a1d6b2 + 2452cb0 + e90a2aa + d00beb9 + 8f695a4 + 1f5ba4c + a3bc9e7 + a519452 + 46d0472 + 6fa5eed + c35be87 + 5faea6f + c27f32d + 9dabe97 + dfc715e + f92de76 + 067662e + 91a03af + 8347095 + f837ffd + a88cb26 commit 0642f10

File tree

6 files changed

+24
-110
lines changed

6 files changed

+24
-110
lines changed

Source/Orts.Simulation/Common/Events.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ public interface EventHandler
2727
public enum Event
2828
{
2929
None,
30-
AITrainApproachingStation,
31-
AITrainHelperLoco,
32-
AITrainLeadLoco,
33-
AITrainLeavingStation,
3430
BatterySwitchOff,
3531
BatterySwitchOn,
3632
BatterySwitchCommandOff,
@@ -127,8 +123,6 @@ public enum Event
127123
PermissionDenied,
128124
PermissionGranted,
129125
PermissionToDepart,
130-
PlayerTrainHelperLoco,
131-
PlayerTrainLeadLoco,
132126
PowerKeyOff,
133127
PowerKeyOn,
134128
ReverserChange,
@@ -567,14 +561,6 @@ public static Event From(Source source, int eventID)
567561
case 321: return Event.BoosterCylinderCocksOpen;
568562
case 322: return Event.BoosterCylinderCocksClose;
569563

570-
// AI train related events
571-
case 330: return Event.AITrainLeadLoco;
572-
case 331: return Event.AITrainHelperLoco;
573-
case 332: return Event.PlayerTrainLeadLoco;
574-
case 333: return Event.PlayerTrainHelperLoco;
575-
case 334: return Event.AITrainApproachingStation;
576-
case 335: return Event.AITrainLeavingStation;
577-
578564
default: return 0;
579565
}
580566
case Source.MSTSCrossing:

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

Lines changed: 21 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,9 @@ public class AITrain : Train
7272
public Service_Definition ServiceDefinition = null; // train's service definition in .act file
7373
public bool UncondAttach = false; // if false it states that train will unconditionally attach to a train on its path
7474

75-
public float doorOpenDelay = -1f;
76-
public float doorCloseAdvance = -1f;
75+
public float DoorOpenTimer = -1f;
76+
public float DoorCloseTimer = -1f;
7777
public AILevelCrossingHornPattern LevelCrossingHornPattern { get; set; }
78-
public bool ApproachTriggerSet = false; // station approach trigger for AI trains has been set
7978

8079
public float PathLength;
8180

@@ -245,10 +244,9 @@ public AITrain(Simulator simulator, BinaryReader inf, AI airef)
245244
Efficiency = inf.ReadSingle();
246245
MaxVelocityA = inf.ReadSingle();
247246
UncondAttach = inf.ReadBoolean();
248-
doorCloseAdvance = inf.ReadSingle();
249-
doorOpenDelay = inf.ReadSingle();
250-
ApproachTriggerSet = inf.ReadBoolean();
251-
if (!Simulator.TimetableMode && doorOpenDelay <= 0 && doorCloseAdvance > 0 && Simulator.OpenDoorsInAITrains &&
247+
DoorCloseTimer = inf.ReadSingle();
248+
DoorOpenTimer = inf.ReadSingle();
249+
if (!Simulator.TimetableMode && DoorOpenTimer <= 0 && DoorCloseTimer > 0 && Simulator.OpenDoorsInAITrains &&
252250
MovementState == AI_MOVEMENT_STATE.STATION_STOP && StationStops.Count > 0)
253251
{
254252
StationStop thisStation = StationStops[0];
@@ -339,9 +337,8 @@ public override void Save(BinaryWriter outf)
339337
outf.Write(Efficiency);
340338
outf.Write(MaxVelocityA);
341339
outf.Write(UncondAttach);
342-
outf.Write(doorCloseAdvance);
343-
outf.Write(doorOpenDelay);
344-
outf.Write(ApproachTriggerSet);
340+
outf.Write(DoorCloseTimer);
341+
outf.Write(DoorOpenTimer);
345342
if (LevelCrossingHornPattern != null)
346343
{
347344
outf.Write(0);
@@ -1303,7 +1300,6 @@ public virtual void SetNextStationAction(bool fromAutopilotSwitch = false)
13031300
AIActionItem newAction = new AIActionItem(null, AIActionItem.AI_ACTION_TYPE.STATION_STOP);
13041301
newAction.SetParam(distancesM[1], 0.0f, distancesM[0], DistanceTravelledM);
13051302
requiredActions.InsertAction(newAction);
1306-
ApproachTriggerSet = false;
13071303

13081304
#if DEBUG_REPORTS
13091305
if (StationStops[0].ActualStopType == StationStop.STOPTYPE.STATION_STOP)
@@ -1855,13 +1851,12 @@ public virtual void UpdateStationState(float elapsedClockSeconds, int presentTim
18551851
thisStation.ActualArrival = presentTime;
18561852
var stopTime = thisStation.CalculateDepartTime(presentTime, this);
18571853
actualdepart = thisStation.ActualDepart;
1858-
doorOpenDelay = 4.0f;
1859-
doorCloseAdvance = stopTime - 10.0f;
1860-
if (PreUpdate) doorCloseAdvance -= 10;
1861-
if (doorCloseAdvance - 6 < doorOpenDelay)
1854+
DoorOpenTimer = PreUpdate ? 0 : 4;
1855+
DoorCloseTimer = PreUpdate ? stopTime - 20 : stopTime - 10.0f;
1856+
if (DoorCloseTimer - 6 < DoorOpenTimer)
18621857
{
1863-
doorOpenDelay = 0;
1864-
doorCloseAdvance = stopTime - 3;
1858+
DoorOpenTimer = 0;
1859+
DoorCloseTimer = Math.Max (stopTime - 3, 0);
18651860
}
18661861

18671862
#if DEBUG_REPORTS
@@ -1891,10 +1886,10 @@ public virtual void UpdateStationState(float elapsedClockSeconds, int presentTim
18911886
if (!IsFreight && Simulator.OpenDoorsInAITrains)
18921887
{
18931888
var frontIsFront = thisStation.PlatformReference == thisStation.PlatformItem.PlatformFrontUiD;
1894-
if (doorOpenDelay > 0)
1889+
if (DoorOpenTimer >= 0)
18951890
{
1896-
doorOpenDelay -= elapsedClockSeconds;
1897-
if (doorOpenDelay < 0)
1891+
DoorOpenTimer -= elapsedClockSeconds;
1892+
if (DoorOpenTimer < 0)
18981893
{
18991894
if (thisStation.PlatformItem.PlatformSide[0])
19001895
{
@@ -1908,19 +1903,19 @@ public virtual void UpdateStationState(float elapsedClockSeconds, int presentTim
19081903
}
19091904
}
19101905
}
1911-
if (doorCloseAdvance > 0)
1906+
if (DoorCloseTimer >= 0)
19121907
{
1913-
doorCloseAdvance -= elapsedClockSeconds;
1914-
if (doorCloseAdvance < 0)
1908+
DoorCloseTimer -= elapsedClockSeconds;
1909+
if (DoorCloseTimer < 0)
19151910
{
19161911
if (thisStation.PlatformItem.PlatformSide[0])
19171912
{
1918-
// Open left doors
1913+
// Close left doors
19191914
SetDoors(frontIsFront ? DoorSide.Right : DoorSide.Left, false);
19201915
}
19211916
if (thisStation.PlatformItem.PlatformSide[1])
19221917
{
1923-
// Open right doors
1918+
// Close right doors
19241919
SetDoors(frontIsFront ? DoorSide.Left : DoorSide.Right, false);
19251920
}
19261921
}
@@ -2064,7 +2059,6 @@ public virtual void UpdateStationState(float elapsedClockSeconds, int presentTim
20642059

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

20692063
#if DEBUG_REPORTS
20702064
DateTime baseDTd = new DateTime();
@@ -2626,13 +2620,6 @@ public virtual void UpdateBrakingState(float elapsedClockSeconds, int presentTim
26262620
}
26272621
}
26282622

2629-
if (nextActionInfo != null && nextActionInfo.NextAction == AIActionItem.AI_ACTION_TYPE.STATION_STOP &&
2630-
distanceToGoM < 150 + StationStops[0].PlatformItem.Length && !ApproachTriggerSet)
2631-
{
2632-
if (Cars[0] is MSTSLocomotive) Cars[0].SignalEvent(Event.AITrainApproachingStation);
2633-
ApproachTriggerSet = true;
2634-
}
2635-
26362623
if (nextActionInfo != null && nextActionInfo.NextAction == AIActionItem.AI_ACTION_TYPE.STATION_STOP)
26372624
creepDistanceM = 0.0f;
26382625
if (nextActionInfo == null && requiredSpeedMpS == 0)
@@ -4380,7 +4367,6 @@ public void CoupleAI(Train attachTrain, bool thisTrainFront, bool attachTrainFro
43804367
AI.AITrains.Add(this);
43814368
AI.aiListChanged = true;
43824369
}
4383-
else if (attachTrain is AITrain) RedefineAITriggers(attachTrain as AITrain);
43844370
if (!UncondAttach)
43854371
{
43864372
RemoveTrain();
@@ -4489,7 +4475,6 @@ public void CoupleAIToStatic(Train attachTrain, bool thisTrainFront, bool attach
44894475
AddTrackSections();
44904476
ResetActions(true);
44914477
physicsUpdate(0);
4492-
RedefineAITriggers(this);
44934478
}
44944479

44954480
//================================================================================================//
@@ -4731,8 +4716,7 @@ public void TerminateCoupling(Train attachTrain, bool thisTrainFront, bool attac
47314716
// Move WP, if any, just under the loco;
47324717
AuxActionsContain.MoveAuxActionAfterReversal(this);
47334718
ResetActions(true);
4734-
RedefineAITriggers(this);
4735-
if (attachTrain is AITrain) RedefineAITriggers(attachTrain as AITrain);
4719+
47364720
physicsUpdate(0);// Stop the wheels from moving etc
47374721

47384722
}
@@ -6594,27 +6578,6 @@ public void RestartWaitingTrain(RestartWaitingTrain restartWaitingTrain)
65946578
}
65956579
}
65966580

6597-
//================================================================================================//
6598-
/// <summary>
6599-
/// Redefine sound triggers for AI trains
6600-
/// </summary>
6601-
public void RedefineAITriggers(AITrain train)
6602-
{
6603-
var leadFound = false;
6604-
foreach (var car in train.Cars)
6605-
{
6606-
if (car is MSTSLocomotive)
6607-
{
6608-
if (!leadFound)
6609-
{
6610-
car.SignalEvent(Event.AITrainLeadLoco);
6611-
leadFound = true;
6612-
}
6613-
else car.SignalEvent(Event.AITrainHelperLoco);
6614-
}
6615-
}
6616-
}
6617-
66186581
}
66196582

66206583

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,8 +1538,6 @@ public void ReverseCars()
15381538
// Update flipped state of each car.
15391539
for (var i = 0; i < Cars.Count; i++)
15401540
Cars[i].Flipped = !Cars[i].Flipped;
1541-
// if AI train redefine first loco for sound
1542-
if (TrainType == TRAINTYPE.AI) (this as AITrain).RedefineAITriggers(this as AITrain);
15431541
}
15441542

15451543
/// <summary>

Source/Orts.Simulation/Simulation/Simulator.cs

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -748,20 +748,14 @@ public void SetWagonCommandReceivers(MSTSWagon wag)
748748
public TrainCar SetPlayerLocomotive(Train playerTrain)
749749
{
750750
TrainCar PlayerLocomotive = null;
751-
var leadFound = false;
752751
foreach (TrainCar car in playerTrain.Cars)
753752
if (car.IsDriveable) // first loco is the one the player drives
754753
{
755-
if (!leadFound)
756-
{
757754
PlayerLocomotive = car;
758755
playerTrain.LeadLocomotive = car;
759756
playerTrain.InitializeBrakes();
760757
PlayerLocomotive.LocalThrottlePercent = playerTrain.AITrainThrottlePercent;
761-
PlayerLocomotive.SignalEvent(Event.PlayerTrainLeadLoco);
762-
leadFound = true;
763-
}
764-
else car.SignalEvent(Event.PlayerTrainHelperLoco);
758+
break;
765759
}
766760
if (PlayerLocomotive == null)
767761
throw new InvalidDataException("Can't find player locomotive in activity");
@@ -981,7 +975,6 @@ private void FinishCoupling(Train drivenTrain, Train train, bool couple_to_front
981975
}
982976
drivenTrain.Cars.Clear();
983977
AI.TrainsToRemoveFromAI.Add((AITrain)train);
984-
PlayerLocomotive.SignalEvent(Event.PlayerTrainHelperLoco);
985978
PlayerLocomotive = SetPlayerLocomotive(train);
986979
(train as AITrain).SwitchToPlayerControl();
987980
OnPlayerLocomotiveChanged();
@@ -1096,7 +1089,6 @@ public void CheckForCoupling(Train drivenTrain, float elapsedClockSeconds)
10961089
{
10971090
drivenTrain.Cars.Add(car);
10981091
car.Train = drivenTrain;
1099-
if (car is MSTSLocomotive) car.SignalEvent(Event.PlayerTrainHelperLoco);
11001092
}
11011093
FinishRearCoupling(drivenTrain, train, true);
11021094
return;
@@ -1127,7 +1119,6 @@ public void CheckForCoupling(Train drivenTrain, float elapsedClockSeconds)
11271119
drivenTrain.Cars.Add(car);
11281120
car.Train = drivenTrain;
11291121
car.Flipped = !car.Flipped;
1130-
if (car is MSTSLocomotive) car.SignalEvent(Event.PlayerTrainHelperLoco);
11311122
}
11321123
FinishRearCoupling(drivenTrain, train, false);
11331124
return;
@@ -1192,7 +1183,6 @@ public void CheckForCoupling(Train drivenTrain, float elapsedClockSeconds)
11921183
TrainCar car = train.Cars[i];
11931184
drivenTrain.Cars.Insert(i, car);
11941185
car.Train = drivenTrain;
1195-
if (car is MSTSLocomotive) car.SignalEvent(Event.PlayerTrainHelperLoco);
11961186
}
11971187
if (drivenTrain.LeadLocomotiveIndex >= 0) drivenTrain.LeadLocomotiveIndex += train.Cars.Count;
11981188
FinishFrontCoupling(drivenTrain, train, lead, true);
@@ -1226,7 +1216,6 @@ public void CheckForCoupling(Train drivenTrain, float elapsedClockSeconds)
12261216
drivenTrain.Cars.Insert(0, car);
12271217
car.Train = drivenTrain;
12281218
car.Flipped = !car.Flipped;
1229-
if (car is MSTSLocomotive) car.SignalEvent(Event.PlayerTrainHelperLoco);
12301219
}
12311220
if (drivenTrain.LeadLocomotiveIndex >= 0) drivenTrain.LeadLocomotiveIndex += train.Cars.Count;
12321221
FinishFrontCoupling(drivenTrain, train, lead, false);
@@ -1829,19 +1818,6 @@ public void UncoupleBehind(TrainCar car, bool keepFront)
18291818
train2.TrainType = Train.TRAINTYPE.AI;
18301819
train.IncorporatedTrainNo = -1;
18311820
train2.MUDirection = Direction.Forward;
1832-
var leadFound = false;
1833-
foreach (var trainCar in train2.Cars)
1834-
{
1835-
if (trainCar is MSTSLocomotive)
1836-
{
1837-
if (!leadFound)
1838-
{
1839-
trainCar.SignalEvent(Event.AITrainLeadLoco);
1840-
leadFound = true;
1841-
}
1842-
}
1843-
else trainCar.SignalEvent(Event.AITrainHelperLoco);
1844-
}
18451821
}
18461822
else train2.TrainType = Train.TRAINTYPE.STATIC;
18471823
train2.LeadLocomotive = null;

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -583,9 +583,8 @@ public override void Save(BinaryWriter outf)
583583
outf.Write(Efficiency);
584584
outf.Write(MaxVelocityA);
585585
outf.Write(UncondAttach);
586-
outf.Write(doorCloseAdvance);
587-
outf.Write(doorOpenDelay);
588-
outf.Write(ApproachTriggerSet);
586+
outf.Write(DoorCloseTimer);
587+
outf.Write(DoorOpenTimer);
589588
// Dummy for level crossing horn pattern
590589
outf.Write(-1);
591590

Source/RunActivity/Viewer3D/RollingStock/MSTSWagonViewer.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,14 +1426,6 @@ protected void LoadCarSound(string wagonFolderSlash, string filename)
14261426
try
14271427
{
14281428
Viewer.SoundProcess.AddSoundSource(this, new SoundSource(Viewer, MSTSWagon, smsFilePath));
1429-
if (MSTSWagon is MSTSLocomotive && MSTSWagon.Train != null && MSTSWagon.Train.TrainType == Simulation.Physics.Train.TRAINTYPE.AI)
1430-
{
1431-
if (MSTSWagon.CarID == MSTSWagon.Train.Cars[0].CarID)
1432-
// Lead loco, enable AI train trigger
1433-
MSTSWagon.SignalEvent(Orts.Common.Event.AITrainLeadLoco);
1434-
// AI train helper loco
1435-
else MSTSWagon.SignalEvent(Orts.Common.Event.AITrainHelperLoco);
1436-
}
14371429
}
14381430
catch (Exception error)
14391431
{

0 commit comments

Comments
 (0)