Skip to content

Commit 01409bb

Browse files
committed
Allow notch labels
1 parent d500329 commit 01409bb

File tree

4 files changed

+53
-37
lines changed

4 files changed

+53
-37
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,10 @@ public void SetDynamicBrakeIntervention(float value)
277277
/// </summary>
278278
/// <returns>The nullable state fraction</returns>
279279
public abstract float? GetStateFraction();
280+
public virtual string GetStateName()
281+
{
282+
return ControllerStateDictionary.Dict[GetState()];
283+
}
280284
}
281285

282286
public enum BrakeControllerEvent

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/Controllers/BrakeController.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,20 @@ public void Parse(string lowercasetoken, STFReader stf)
313313
float value = stf.ReadFloat(STFReader.UNITS.None, null);
314314
int smooth = stf.ReadInt(null);
315315
string type = stf.ReadString();
316-
Notches.Add(new MSTSNotch(value, smooth, type, stf));
317-
if (type != ")") stf.SkipRestOfBlock();
316+
string name = null;
317+
while(type != ")" && !stf.EndOfBlock())
318+
{
319+
switch (stf.ReadItem().ToLower())
320+
{
321+
case "(":
322+
stf.SkipRestOfBlock();
323+
break;
324+
case "ortslabel":
325+
name = stf.ReadStringBlock(null);
326+
break;
327+
}
328+
}
329+
Notches.Add(new MSTSNotch(value, smooth, type, name, stf));
318330
}),
319331
});
320332
break;
@@ -484,7 +496,7 @@ public string GetStatus()
484496
{
485497
if (Script != null)
486498
{
487-
string state = ControllerStateDictionary.Dict[Script.GetState()];
499+
string state = Script.GetStateName();
488500
string fraction = GetStateFractionScripted();
489501

490502
if (String.IsNullOrEmpty(state) && String.IsNullOrEmpty(fraction))

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/Controllers/MSTSBrakeController.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,19 @@ public override ControllerState GetState()
382382
return ControllerState.Dummy;
383383
}
384384

385+
public override string GetStateName()
386+
{
387+
if (!EmergencyBrakingPushButton() && !TCSEmergencyBraking() && !TCSFullServiceBraking() &&
388+
!OverchargeButtonPressed() && !QuickReleaseButtonPressed() &&
389+
NotchController != null && NotchController.NotchCount() > 0)
390+
{
391+
var notch = NotchController.GetCurrentNotch();
392+
if (!string.IsNullOrEmpty(notch.Name))
393+
return notch.Name;
394+
}
395+
return base.GetStateName();
396+
}
397+
385398
public override float? GetStateFraction()
386399
{
387400
if (EmergencyBrakingPushButton() || TCSEmergencyBraking() || TCSFullServiceBraking() || QuickReleaseButtonPressed() || OverchargeButtonPressed())

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/Controllers/MSTSNotchController.cs

Lines changed: 21 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ public class MSTSNotch {
2727
public float Value;
2828
public bool Smooth;
2929
public ControllerState Type;
30-
public MSTSNotch(float v, int s, string type, STFReader stf)
30+
public string Name;
31+
public MSTSNotch(float v, int s, string type, string name, STFReader stf)
3132
{
3233
Value = v;
3334
Smooth = s == 0 ? false : true;
@@ -85,6 +86,7 @@ public MSTSNotch(float v, int s, string type, STFReader stf)
8586
STFException.TraceInformation(stf, "Skipped unknown notch type " + type);
8687
break;
8788
}
89+
Name = name;
8890
}
8991
public MSTSNotch(float v, bool s, int t)
9092
{
@@ -98,13 +100,7 @@ public MSTSNotch(MSTSNotch other)
98100
Value = other.Value;
99101
Smooth = other.Smooth;
100102
Type = other.Type;
101-
}
102-
103-
public MSTSNotch(BinaryReader inf)
104-
{
105-
Value = inf.ReadSingle();
106-
Smooth = inf.ReadBoolean();
107-
Type = (ControllerState)inf.ReadInt32();
103+
Name = other.Name;
108104
}
109105

110106
public MSTSNotch Clone()
@@ -114,15 +110,9 @@ public MSTSNotch Clone()
114110

115111
public string GetName()
116112
{
113+
if (!string.IsNullOrEmpty(Name)) return Name;
117114
return ControllerStateDictionary.Dict[Type];
118115
}
119-
120-
public void Save(BinaryWriter outf)
121-
{
122-
outf.Write(Value);
123-
outf.Write(Smooth);
124-
outf.Write((int)Type);
125-
}
126116
}
127117

128118
/**
@@ -229,8 +219,20 @@ public void Parse(STFReader stf)
229219
float value = stf.ReadFloat(STFReader.UNITS.None, null);
230220
int smooth = stf.ReadInt(null);
231221
string type = stf.ReadString();
232-
Notches.Add(new MSTSNotch(value, smooth, type, stf));
233-
if (type != ")") stf.SkipRestOfBlock();
222+
string name = null;
223+
while(type != ")" && !stf.EndOfBlock())
224+
{
225+
switch (stf.ReadItem().ToLower())
226+
{
227+
case "(":
228+
stf.SkipRestOfBlock();
229+
break;
230+
case "ortslabel":
231+
name = stf.ReadStringBlock(null);
232+
break;
233+
}
234+
}
235+
Notches.Add(new MSTSNotch(value, smooth, type, name, stf));
234236
}),
235237
});
236238
SetValue(CurrentValue);
@@ -541,33 +543,18 @@ protected virtual void SaveData(BinaryWriter outf)
541543
outf.Write(MinimumValue);
542544
outf.Write(MaximumValue);
543545
outf.Write(StepSize);
544-
outf.Write(CurrentNotch);
545-
outf.Write(Notches.Count);
546-
547-
foreach(MSTSNotch notch in Notches)
548-
{
549-
notch.Save(outf);
550-
}
546+
outf.Write(CurrentNotch);
551547
}
552548

553549
public virtual void Restore(BinaryReader inf)
554550
{
555-
Notches.Clear();
556-
557551
IntermediateValue = CurrentValue = inf.ReadSingle();
558552
MinimumValue = inf.ReadSingle();
559553
MaximumValue = inf.ReadSingle();
560554
StepSize = inf.ReadSingle();
561555
CurrentNotch = inf.ReadInt32();
562556

563-
UpdateValue = 0;
564-
565-
int count = inf.ReadInt32();
566-
567-
for (int i = 0; i < count; ++i)
568-
{
569-
Notches.Add(new MSTSNotch(inf));
570-
}
557+
UpdateValue = 0;
571558
}
572559

573560
public MSTSNotch GetCurrentNotch()

0 commit comments

Comments
 (0)