Skip to content

Commit 14405bf

Browse files
authored
Merge pull request #962 from cesarBLG/pantograph-fix
Fix pantographs on unpowered cars
2 parents 041e55a + 46d0472 commit 14405bf

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

Source/Orts.Simulation/Common/Scripting/PowerSupply/PowerSupply.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ public virtual void HandleEvent(PowerSupplyEvent evt, int id)
9595
public virtual void HandleEventFromLeadLocomotive(PowerSupplyEvent evt)
9696
{
9797
// By default, send the event to every component
98+
SignalEventToPantographs(evt);
9899
SignalEventToBatterySwitch(evt);
99100
}
100101

Source/Orts.Simulation/Simulation/RollingStocks/MSTSWagon.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,6 +1177,7 @@ public override void Initialize()
11771177
}
11781178
FreightAnimations?.Load(FreightAnimations.LoadDataList, true);
11791179
InitializeLoadPhysics();
1180+
if (!(this is MSTSLocomotive) && Simulator.Settings.ElectricHotStart) Pantographs.HandleEvent(PowerSupplyEvent.RaisePantograph, 1);
11801181
}
11811182

11821183
public override void InitializeMoving()

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/PowerSupplies/LocomotivePowerSupply.cs

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -332,11 +332,11 @@ protected virtual void AssignScriptFunctions()
332332
AbstractScript.SignalEventToTcsWithMessage = (evt, message) => Locomotive.TrainControlSystem.HandleEvent(evt, message);
333333
AbstractScript.SignalEventToOtherLocomotives = (evt) =>
334334
{
335-
if (Locomotive == Simulator.PlayerLocomotive)
335+
if (Locomotive == Train.LeadLocomotive)
336336
{
337337
foreach (MSTSLocomotive locomotive in Locomotive.Train.Cars.OfType<MSTSLocomotive>())
338338
{
339-
if (locomotive != Locomotive && locomotive != Locomotive.Train.LeadLocomotive && locomotive.RemoteControlGroup != -1)
339+
if (locomotive != Locomotive && locomotive.RemoteControlGroup != -1)
340340
{
341341
locomotive.LocomotivePowerSupply.HandleEventFromLeadLocomotive(evt);
342342
}
@@ -345,11 +345,11 @@ protected virtual void AssignScriptFunctions()
345345
};
346346
AbstractScript.SignalEventToOtherLocomotivesWithId = (evt, id) =>
347347
{
348-
if (Locomotive == Simulator.PlayerLocomotive)
348+
if (Locomotive == Train.LeadLocomotive)
349349
{
350350
foreach (MSTSLocomotive locomotive in Locomotive.Train.Cars.OfType<MSTSLocomotive>())
351351
{
352-
if (locomotive != Locomotive && locomotive != Locomotive.Train.LeadLocomotive && locomotive.RemoteControlGroup != -1)
352+
if (locomotive != Locomotive && locomotive.RemoteControlGroup != -1)
353353
{
354354
locomotive.LocomotivePowerSupply.HandleEventFromLeadLocomotive(evt, id);
355355
}
@@ -358,26 +358,40 @@ protected virtual void AssignScriptFunctions()
358358
};
359359
AbstractScript.SignalEventToOtherTrainVehicles = (evt) =>
360360
{
361-
if (Locomotive == Simulator.PlayerLocomotive)
361+
if (Locomotive == Train.LeadLocomotive)
362362
{
363363
foreach (TrainCar car in Locomotive.Train.Cars)
364364
{
365-
if (car != Locomotive && car != Locomotive.Train.LeadLocomotive && car.RemoteControlGroup != -1)
365+
if (car != Locomotive && car.RemoteControlGroup != -1)
366366
{
367-
car.PowerSupply?.HandleEventFromLeadLocomotive(evt);
367+
if (car.PowerSupply != null)
368+
{
369+
car.PowerSupply.HandleEventFromLeadLocomotive(evt);
370+
}
371+
else if (car is MSTSWagon wagon)
372+
{
373+
wagon.Pantographs.HandleEvent(evt);
374+
}
368375
}
369376
}
370377
}
371378
};
372379
AbstractScript.SignalEventToOtherTrainVehiclesWithId = (evt, id) =>
373380
{
374-
if (Locomotive == Simulator.PlayerLocomotive)
381+
if (Locomotive == Train.LeadLocomotive)
375382
{
376383
foreach (TrainCar car in Locomotive.Train.Cars)
377384
{
378-
if (car != Locomotive && car != Locomotive.Train.LeadLocomotive && car.RemoteControlGroup != -1)
385+
if (car != Locomotive && car.RemoteControlGroup != -1)
379386
{
380-
car.PowerSupply?.HandleEventFromLeadLocomotive(evt, id);
387+
if (car.PowerSupply != null)
388+
{
389+
car.PowerSupply.HandleEventFromLeadLocomotive(evt, id);
390+
}
391+
else if (car is MSTSWagon wagon)
392+
{
393+
wagon.Pantographs.HandleEvent(evt, id);
394+
}
381395
}
382396
}
383397
}
@@ -388,7 +402,7 @@ protected virtual void AssignScriptFunctions()
388402

389403
foreach (MSTSDieselLocomotive locomotive in Train.Cars.OfType<MSTSDieselLocomotive>().Where((MSTSLocomotive locomotive) => { return locomotive.RemoteControlGroup != -1; }))
390404
{
391-
if (locomotive == Simulator.PlayerLocomotive)
405+
if (locomotive == Train.LeadLocomotive)
392406
{
393407
// Engine number 1 or above are helper engines
394408
for (int i = 1; i < locomotive.DieselEngines.Count; i++)

0 commit comments

Comments
 (0)