|
15 | 15 | // You should have received a copy of the GNU General Public License
|
16 | 16 | // along with Open Rails. If not, see <http://www.gnu.org/licenses/>.
|
17 | 17 |
|
18 |
| -using GNU.Gettext; |
19 |
| -using Orts.Simulation.RollingStocks.SubSystems.Controllers; |
20 | 18 | using System;
|
21 | 19 | using System.Collections.Generic;
|
| 20 | +using GNU.Gettext; |
| 21 | +using Orts.Simulation.RollingStocks; |
| 22 | +using Orts.Simulation.RollingStocks.SubSystems.Controllers; |
| 23 | +using Orts.Simulation.RollingStocks.SubSystems.PowerSupplies; |
| 24 | +using ORTS.Common; |
22 | 25 |
|
23 | 26 | namespace ORTS.Scripting.Api
|
24 | 27 | {
|
25 | 28 | public abstract class BrakeController : AbstractTrainScriptClass
|
26 | 29 | {
|
| 30 | + internal ScriptedBrakeController Host; |
| 31 | + internal MSTSLocomotive Locomotive => Host.Locomotive; |
| 32 | + internal ILocomotivePowerSupply LocomotivePowerSupply => Locomotive.PowerSupply as ILocomotivePowerSupply; |
| 33 | + |
| 34 | + /// <summary> |
| 35 | + /// Attaches the script to its host |
| 36 | + /// </summary> |
| 37 | + /// <param name="host">The hosting ScriptedBrakeController object</param> |
| 38 | + internal void AttachToHost(ScriptedBrakeController host) |
| 39 | + { |
| 40 | + Host = host; |
| 41 | + } |
| 42 | + |
27 | 43 | /// <summary>
|
28 | 44 | /// True if the driver has asked for an emergency braking (push button)
|
29 | 45 | /// </summary>
|
30 |
| - public Func<bool> EmergencyBrakingPushButton; |
| 46 | + public bool EmergencyBrakingPushButton() => Host.EmergencyBrakingPushButton; |
| 47 | + |
31 | 48 | /// <summary>
|
32 | 49 | /// True if the TCS has asked for an emergency braking
|
33 | 50 | /// </summary>
|
34 |
| - public Func<bool> TCSEmergencyBraking; |
| 51 | + public bool TCSEmergencyBraking() => Host.TCSEmergencyBraking; |
| 52 | + |
35 | 53 | /// <summary>
|
36 | 54 | /// True if the TCS has asked for a full service braking
|
37 | 55 | /// </summary>
|
38 |
| - public Func<bool> TCSFullServiceBraking; |
| 56 | + public bool TCSFullServiceBraking() => Host.TCSFullServiceBraking; |
| 57 | + |
39 | 58 | /// <summary>
|
40 | 59 | /// True if the driver has pressed the Quick Release button
|
41 | 60 | /// </summary>
|
42 |
| - public Func<bool> QuickReleaseButtonPressed; |
| 61 | + public bool QuickReleaseButtonPressed() => Host.QuickReleaseButtonPressed; |
| 62 | + |
43 | 63 | /// <summary>
|
44 | 64 | /// True if the driver has pressed the Overcharge button
|
45 | 65 | /// </summary>
|
46 |
| - public Func<bool> OverchargeButtonPressed; |
| 66 | + public bool OverchargeButtonPressed() => Host.OverchargeButtonPressed; |
| 67 | + |
47 | 68 | /// <summary>
|
48 | 69 | /// True if low voltage power supply is switched on.
|
49 | 70 | /// </summary>
|
50 |
| - public Func<bool> IsLowVoltagePowerSupplyOn; |
| 71 | + public bool IsLowVoltagePowerSupplyOn() => LocomotivePowerSupply.LowVoltagePowerSupplyOn; |
| 72 | + |
51 | 73 | /// <summary>
|
52 | 74 | /// True if cab power supply is switched on.
|
53 | 75 | /// </summary>
|
54 |
| - public Func<bool> IsCabPowerSupplyOn; |
| 76 | + public bool IsCabPowerSupplyOn() => LocomotivePowerSupply.CabPowerSupplyOn; |
| 77 | + |
55 | 78 | /// <summary>
|
56 | 79 | /// Main reservoir pressure
|
57 | 80 | /// </summary>
|
58 |
| - public Func<float> MainReservoirPressureBar; |
| 81 | + public float MainReservoirPressureBar() |
| 82 | + { |
| 83 | + if (Locomotive.Train != null) |
| 84 | + return Bar.FromPSI(Locomotive.MainResPressurePSI); |
| 85 | + else |
| 86 | + return float.MaxValue; |
| 87 | + } |
| 88 | + |
59 | 89 | /// <summary>
|
60 | 90 | /// Maximum pressure in the brake pipes and the equalizing reservoir
|
61 | 91 | /// </summary>
|
62 |
| - public Func<float> MaxPressureBar; |
| 92 | + public float MaxPressureBar() => Bar.FromPSI(Host.MaxPressurePSI); |
| 93 | + |
63 | 94 | /// <summary>
|
64 | 95 | /// Maximum pressure in the brake pipes when they are overcharged
|
65 | 96 | /// </summary>
|
66 |
| - public Func<float> MaxOverchargePressureBar; |
| 97 | + public float MaxOverchargePressureBar() => Bar.FromPSI(Host.MaxOverchargePressurePSI); |
| 98 | + |
67 | 99 | /// <summary>
|
68 | 100 | /// Release rate of the equalizing reservoir
|
69 | 101 | /// </summary>
|
70 |
| - public Func<float> ReleaseRateBarpS; |
| 102 | + public float ReleaseRateBarpS() => BarpS.FromPSIpS(Host.ReleaseRatePSIpS); |
| 103 | + |
71 | 104 | /// <summary>
|
72 | 105 | /// Quick release rate of the equalizing reservoir
|
73 | 106 | /// </summary>
|
74 |
| - public Func<float> QuickReleaseRateBarpS; |
| 107 | + public float QuickReleaseRateBarpS() => BarpS.FromPSIpS(Host.QuickReleaseRatePSIpS); |
| 108 | + |
75 | 109 | /// <summary>
|
76 | 110 | /// Pressure decrease rate of equalizing reservoir when eliminating overcharge
|
77 | 111 | /// </summary>
|
78 |
| - public Func<float> OverchargeEliminationRateBarpS; |
| 112 | + public float OverchargeEliminationRateBarpS() => BarpS.FromPSIpS(Host.OverchargeEliminationRatePSIpS); |
| 113 | + |
79 | 114 | /// <summary>
|
80 | 115 | /// Slow application rate of the equalizing reservoir
|
81 | 116 | /// </summary>
|
82 |
| - public Func<float> SlowApplicationRateBarpS; |
| 117 | + public float SlowApplicationRateBarpS() => BarpS.FromPSIpS(Host.SlowApplicationRatePSIpS); |
| 118 | + |
83 | 119 | /// <summary>
|
84 | 120 | /// Apply rate of the equalizing reservoir
|
85 | 121 | /// </summary>
|
86 |
| - public Func<float> ApplyRateBarpS; |
| 122 | + public float ApplyRateBarpS() => BarpS.FromPSIpS(Host.ApplyRatePSIpS); |
| 123 | + |
87 | 124 | /// <summary>
|
88 | 125 | /// Emergency rate of the equalizing reservoir
|
89 | 126 | /// </summary>
|
90 |
| - public Func<float> EmergencyRateBarpS; |
| 127 | + public float EmergencyRateBarpS() => BarpS.FromPSIpS(Host.EmergencyRatePSIpS); |
| 128 | + |
91 | 129 | /// <summary>
|
92 | 130 | /// Depressure needed in order to obtain the full service braking
|
93 | 131 | /// </summary>
|
94 |
| - public Func<float> FullServReductionBar; |
| 132 | + public float FullServReductionBar() => Bar.FromPSI(Host.FullServReductionPSI); |
| 133 | + |
95 | 134 | /// <summary>
|
96 | 135 | /// Release rate of the equalizing reservoir
|
97 | 136 | /// </summary>
|
98 |
| - public Func<float> MinReductionBar; |
| 137 | + public float MinReductionBar() => Bar.FromPSI(Host.MinReductionPSI); |
| 138 | + |
99 | 139 | /// <summary>
|
100 | 140 | /// Current value of the brake controller
|
101 | 141 | /// </summary>
|
102 |
| - public Func<float> CurrentValue; |
| 142 | + public float CurrentValue() => Host.CurrentValue; |
| 143 | + |
| 144 | + /// <summary> |
| 145 | + /// Intermediate value of the brake controller |
| 146 | + /// </summary> |
| 147 | + public float IntermediateValue |
| 148 | + { |
| 149 | + get |
| 150 | + { |
| 151 | + return Host.IntermediateValue; |
| 152 | + } |
| 153 | + set |
| 154 | + { |
| 155 | + Host.IntermediateValue = value; |
| 156 | + } |
| 157 | + } |
| 158 | + |
103 | 159 | /// <summary>
|
104 | 160 | /// Minimum value of the brake controller
|
105 | 161 | /// </summary>
|
106 |
| - public Func<float> MinimumValue; |
| 162 | + public float MinimumValue() => Host.MinimumValue; |
| 163 | + |
107 | 164 | /// <summary>
|
108 | 165 | /// Maximum value of the brake controller
|
109 | 166 | /// </summary>
|
110 |
| - public Func<float> MaximumValue; |
| 167 | + public float MaximumValue() => Host.MaximumValue; |
| 168 | + |
111 | 169 | /// <summary>
|
112 | 170 | /// Step size of the brake controller
|
113 | 171 | /// </summary>
|
114 |
| - public Func<float> StepSize; |
| 172 | + public float StepSize() => Host.StepSize; |
| 173 | + |
115 | 174 | /// <summary>
|
116 | 175 | /// State of the brake pressure (1 = increasing, -1 = decreasing)
|
117 | 176 | /// </summary>
|
118 |
| - public Func<float> UpdateValue; |
| 177 | + public float UpdateValue() => Host.UpdateValue; |
| 178 | + |
119 | 179 | /// <summary>
|
120 | 180 | /// Gives the list of notches
|
121 | 181 | /// </summary>
|
122 |
| - public Func<List<MSTSNotch>> Notches; |
| 182 | + public List<MSTSNotch> Notches() => Host.Notches; |
| 183 | + |
123 | 184 | /// <summary>
|
124 | 185 | /// Fraction of train brake demanded by cruise control
|
125 | 186 | /// </summary>
|
126 |
| - public Func<float> CruiseControlBrakeDemand; |
| 187 | + public float CruiseControlBrakeDemand() => Locomotive.CruiseControl != null ? Locomotive.CruiseControl.TrainBrakePercent/100 : 0; |
| 188 | + |
| 189 | + /// <summary> |
| 190 | + /// Current notch of the brake controller |
| 191 | + /// </summary> |
| 192 | + public int CurrentNotch |
| 193 | + { |
| 194 | + get |
| 195 | + { |
| 196 | + return Host.CurrentNotch; |
| 197 | + } |
| 198 | + set |
| 199 | + { |
| 200 | + Host.CurrentNotch = value; |
| 201 | + } |
| 202 | + } |
127 | 203 |
|
128 | 204 | /// <summary>
|
129 | 205 | /// Sets the current value of the brake controller lever
|
130 | 206 | /// </summary>
|
131 |
| - public Action<float> SetCurrentValue; |
| 207 | + public void SetCurrentValue(float value) |
| 208 | + { |
| 209 | + Host.CurrentValue = value; |
| 210 | + } |
| 211 | + |
132 | 212 | /// <summary>
|
133 | 213 | /// Sets the state of the brake pressure (1 = increasing, -1 = decreasing)
|
134 | 214 | /// </summary>
|
135 |
| - public Action<float> SetUpdateValue; |
| 215 | + public void SetUpdateValue(float value) |
| 216 | + { |
| 217 | + Host.UpdateValue = value; |
| 218 | + } |
| 219 | + |
136 | 220 | /// <summary>
|
137 | 221 | /// Sets the dynamic brake intervention value
|
138 | 222 | /// </summary>
|
139 |
| - public Action<float> SetDynamicBrakeIntervention; |
| 223 | + public void SetDynamicBrakeIntervention(float value) |
| 224 | + { |
| 225 | + // TODO: Set dynamic brake intervention instead of controller position |
| 226 | + // There are some issues that need to be identified and fixed before setting the intervention directly |
| 227 | + if (Locomotive.DynamicBrakeController == null) return; |
| 228 | + Locomotive.DynamicBrakeChangeActiveState(value > 0); |
| 229 | + Locomotive.DynamicBrakeController.SetValue(value); |
| 230 | + } |
140 | 231 |
|
141 | 232 | /// <summary>
|
142 | 233 | /// Called once at initialization time.
|
|
0 commit comments