Skip to content

Commit 127a70e

Browse files
committed
refactor: clarify use of the first update variable
1 parent 224d3ca commit 127a70e

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public class ScriptedPassengerCarPowerSupply : IPassengerCarPowerSupply, ISubSys
6565
public float AirConditioningPowerW { get; protected set; } = 0f;
6666
public float AirConditioningYield { get; protected set; } = 0.9f;
6767

68-
private bool firstUpdate = true;
68+
private bool IsFirstUpdate = true;
6969

7070
public ScriptedPassengerCarPowerSupply(MSTSWagon wagon)
7171
{
@@ -186,18 +186,19 @@ public virtual void Restore(BinaryReader inf)
186186
ElectricTrainSupplyState = (PowerSupplyState)Enum.Parse(typeof(PowerSupplyState), inf.ReadString());
187187
BatteryState = (PowerSupplyState)Enum.Parse(typeof(PowerSupplyState), inf.ReadString());
188188

189-
firstUpdate = false;
189+
IsFirstUpdate = false;
190190
}
191191

192192
public virtual void Update(float elapsedClockSeconds)
193193
{
194194
CarId = Train?.Cars.IndexOf(Wagon) ?? 0;
195195

196-
if (firstUpdate)
196+
if (IsFirstUpdate)
197197
{
198-
firstUpdate = false;
198+
IsFirstUpdate = false;
199199

200-
TrainCar previousCar = CarId > 0 ? Train.Cars[CarId - 1] : null;
200+
// At this point, we can expect Train to be initialized.
201+
var previousCar = CarId > 0 ? Train.Cars[CarId - 1] : null;
201202

202203
// Connect the power supply cable if the previous car is a locomotive or another passenger car
203204
if (previousCar != null

0 commit comments

Comments
 (0)