/
Commands.cs
2349 lines (1972 loc) · 63.3 KB
/
Commands.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// COPYRIGHT 2012, 2013, 2014, 2015 by the Open Rails project.
//
// This file is part of Open Rails.
//
// Open Rails is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Open Rails is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Open Rails. If not, see <http://www.gnu.org/licenses/>.
// This file is the responsibility of the 3D & Environment Team.
using Orts.Simulation;
using Orts.Simulation.Physics;
using Orts.Simulation.RollingStocks;
using Orts.Simulation.RollingStocks.SubSystems;
using Orts.Simulation.RollingStocks.SubSystems.PowerSupplies;
using ORTS.Common;
using ORTS.Scripting.Api;
using System;
using System.Diagnostics; // Used by Trace.Warnings
using System.IO;
namespace Orts.Common
{
/// <summary>
/// This Command Pattern allows requests to be encapsulated as objects (http://sourcemaking.com/design_patterns/command).
/// The pattern provides many advantages, but it allows OR to record the commands and then to save them when the user presses F2.
/// The commands can later be read from file and replayed.
/// Writing and reading is done using the .NET binary serialization which is quick to code. (For an editable version, JSON has
/// been successfully explored.)
///
/// Immediate commands (e.g. sound horn) are straightforward but continuous commands (e.g. apply train brake) are not.
/// OR aims for commands which can be repeated accurately and possibly on a range of hardware. Continuous commands therefore
/// have a target value which is recorded once the key is released. OR creates an immediate command as soon as the user
/// presses the key, but OR creates the continuous command once the user releases the key and the target is known.
///
/// All commands record the time when the command is created, but a continuous command backdates the time to when the key
/// was pressed.
///
/// Each command class has a Receiver property and calls methods on the Receiver to execute the command.
/// This property is static for 2 reasons:
/// - so all command objects of the same class will share the same Receiver object;
/// - so when a command is serialized to and deserialised from file, its Receiver does not have to be saved
/// (which would be impractical) but is automatically available to commands which have been re-created from file.
///
/// Before each command class is used, this Receiver must be assigned, e.g.
/// ReverserCommand.Receiver = (MSTSLocomotive)PlayerLocomotive;
///
/// </summary>
public interface ICommand
{
/// <summary>
/// The time when the command was issued (compatible with Simlator.ClockTime).
/// </summary>
double Time { get; set; }
/// <summary>
/// Call the Receiver to repeat the Command.
/// Each class of command shares a single object, the Receiver, and the command executes by
/// call methods of the Receiver.
/// </summary>
void Redo();
/// <summary>
/// Print the content of the command.
/// </summary>
void Report();
}
[Serializable()]
public abstract class Command : ICommand
{
public double Time { get; set; }
/// <summary>
/// Each command adds itself to the log when it is constructed.
/// </summary>
public Command(CommandLog log)
{
log.CommandAdd(this as ICommand);
}
// Method required by ICommand
public virtual void Redo() { Trace.TraceWarning("Dummy method"); }
public override string ToString()
{
return this.GetType().ToString();
}
// Method required by ICommand
public virtual void Report()
{
Trace.WriteLine(String.Format(
"Command: {0} {1}", FormatStrings.FormatPreciseTime(Time), ToString()));
}
}
// <Superclasses>
[Serializable()]
public abstract class BooleanCommand : Command
{
protected bool ToState;
public BooleanCommand(CommandLog log, bool toState)
: base(log)
{
ToState = toState;
}
}
[Serializable()]
public abstract class IndexCommand : Command
{
protected int Index;
public IndexCommand(CommandLog log, int index)
: base(log)
{
Index = index;
}
}
/// <summary>
/// Superclass for continuous commands. Do not create a continuous command until the operation is complete.
/// </summary>
[Serializable()]
public abstract class ContinuousCommand : BooleanCommand
{
protected float? Target;
public ContinuousCommand(CommandLog log, bool toState, float? target, double startTime)
: base(log, toState)
{
Target = target;
this.Time = startTime; // Continuous commands are created at end of change, so overwrite time when command was created
}
public override string ToString()
{
return base.ToString() + " - " + (ToState ? "increase" : "decrease") + ", target = " + Target.ToString();
}
}
[Serializable()]
public abstract class PausedCommand : Command
{
public double PauseDurationS;
public PausedCommand(CommandLog log, double pauseDurationS)
: base(log)
{
PauseDurationS = pauseDurationS;
}
public override string ToString()
{
return String.Format("{0} Paused Duration: {1}", base.ToString(), PauseDurationS);
}
}
[Serializable()]
public abstract class CameraCommand : Command
{
public CameraCommand(CommandLog log)
: base(log)
{
}
}
[Serializable()]
public sealed class SaveCommand : Command {
public string FileStem;
public SaveCommand( CommandLog log, string fileStem )
: base( log ){
this.FileStem = fileStem;
Redo();
}
public override void Redo() {
// Redo does nothing as SaveCommand is just a marker and saves the fileStem but is not used during replay to redo the save.
// Report();
}
public override string ToString() {
return base.ToString() + " to file \"" + FileStem + ".replay\"";
}
}
// Direction
[Serializable()]
public sealed class ReverserCommand : BooleanCommand {
public static MSTSLocomotive Receiver { get; set; }
public ReverserCommand( CommandLog log, bool toState )
: base( log, toState ) {
Redo();
}
public override void Redo() {
if( ToState ) {
Receiver.StartReverseIncrease( null );
} else {
Receiver.StartReverseDecrease( null );
}
// Report();
}
public override string ToString() {
return base.ToString() + " - " + (ToState ? "step forward" : "step back");
}
}
[Serializable()]
public sealed class ContinuousReverserCommand : ContinuousCommand {
public static MSTSSteamLocomotive Receiver { get; set; }
public ContinuousReverserCommand( CommandLog log, bool toState, float? target, double startTime )
: base( log, toState, target, startTime ) {
Redo();
}
public override void Redo() {
if (Receiver == null) return;
Receiver.ReverserChangeTo( ToState, Target );
// Report();
}
}
// Power : Raise/lower pantograph
[Serializable()]
public sealed class PantographCommand : BooleanCommand {
public static MSTSLocomotive Receiver { get; set; }
private int item;
public PantographCommand( CommandLog log, int item, bool toState )
: base( log, toState ) {
this.item = item;
Redo();
}
public override void Redo() {
if (Receiver != null && Receiver.Train != null)
{
Receiver.Train.SignalEvent((ToState ? PowerSupplyEvent.RaisePantograph : PowerSupplyEvent.LowerPantograph), item);
}
}
public override string ToString() {
return base.ToString() + " - " + (ToState ? "raise" : "lower") + ", item = " + item.ToString();
}
}
// Power : Close/open circuit breaker switch
[Serializable()]
public sealed class CircuitBreakerClosingOrderCommand : BooleanCommand
{
public static ILocomotivePowerSupply Receiver { get; set; }
public CircuitBreakerClosingOrderCommand(CommandLog log, bool toState)
: base(log, toState)
{
Redo();
}
public override void Redo()
{
Receiver?.HandleEvent(ToState ? PowerSupplyEvent.CloseCircuitBreaker : PowerSupplyEvent.OpenCircuitBreaker);
}
public override string ToString()
{
return base.ToString() + " - " + (ToState ? "close" : "open");
}
}
// Power : Close circuit breaker button
[Serializable()]
public sealed class CircuitBreakerClosingOrderButtonCommand : BooleanCommand
{
public static ILocomotivePowerSupply Receiver { get; set; }
public CircuitBreakerClosingOrderButtonCommand(CommandLog log, bool toState)
: base(log, toState)
{
Redo();
}
public override void Redo()
{
Receiver?.HandleEvent(ToState ? PowerSupplyEvent.CloseCircuitBreakerButtonPressed : PowerSupplyEvent.CloseCircuitBreakerButtonReleased);
}
public override string ToString()
{
return base.ToString() + " - " + (ToState ? "pressed" : "released");
}
}
// Power : Open circuit breaker button
[Serializable()]
public sealed class CircuitBreakerOpeningOrderButtonCommand : BooleanCommand
{
public static ILocomotivePowerSupply Receiver { get; set; }
public CircuitBreakerOpeningOrderButtonCommand(CommandLog log, bool toState)
: base(log, toState)
{
Redo();
}
public override void Redo()
{
Receiver?.HandleEvent(ToState ? PowerSupplyEvent.OpenCircuitBreakerButtonPressed : PowerSupplyEvent.OpenCircuitBreakerButtonReleased);
}
public override string ToString()
{
return base.ToString() + " - " + (ToState ? "pressed" : "released");
}
}
// Power : Give/remove circuit breaker authorization switch
[Serializable()]
public sealed class CircuitBreakerClosingAuthorizationCommand : BooleanCommand
{
public static ILocomotivePowerSupply Receiver { get; set; }
public CircuitBreakerClosingAuthorizationCommand(CommandLog log, bool toState)
: base(log, toState)
{
Redo();
}
public override void Redo()
{
Receiver?.HandleEvent(ToState ? PowerSupplyEvent.GiveCircuitBreakerClosingAuthorization : PowerSupplyEvent.RemoveCircuitBreakerClosingAuthorization);
}
public override string ToString()
{
return base.ToString() + " - " + (ToState ? "given" : "removed");
}
}
// Power : Close/open traction cut-off relay switch
[Serializable()]
public sealed class TractionCutOffRelayClosingOrderCommand : BooleanCommand
{
public static ILocomotivePowerSupply Receiver { get; set; }
public TractionCutOffRelayClosingOrderCommand(CommandLog log, bool toState)
: base(log, toState)
{
Redo();
}
public override void Redo()
{
Receiver?.HandleEvent(ToState ? PowerSupplyEvent.CloseTractionCutOffRelay : PowerSupplyEvent.OpenTractionCutOffRelay);
}
public override string ToString()
{
return base.ToString() + " - " + (ToState ? "close" : "open");
}
}
// Power : Close traction cut-off relay button
[Serializable()]
public sealed class TractionCutOffRelayClosingOrderButtonCommand : BooleanCommand
{
public static ILocomotivePowerSupply Receiver { get; set; }
public TractionCutOffRelayClosingOrderButtonCommand(CommandLog log, bool toState)
: base(log, toState)
{
Redo();
}
public override void Redo()
{
Receiver?.HandleEvent(ToState ? PowerSupplyEvent.CloseTractionCutOffRelayButtonPressed : PowerSupplyEvent.CloseTractionCutOffRelayButtonReleased);
}
public override string ToString()
{
return base.ToString() + " - " + (ToState ? "pressed" : "released");
}
}
// Power : Open traction cut-off relay button
[Serializable()]
public sealed class TractionCutOffRelayOpeningOrderButtonCommand : BooleanCommand
{
public static ILocomotivePowerSupply Receiver { get; set; }
public TractionCutOffRelayOpeningOrderButtonCommand(CommandLog log, bool toState)
: base(log, toState)
{
Redo();
}
public override void Redo()
{
Receiver?.HandleEvent(ToState ? PowerSupplyEvent.OpenTractionCutOffRelayButtonPressed : PowerSupplyEvent.OpenTractionCutOffRelayButtonReleased);
}
public override string ToString()
{
return base.ToString() + " - " + (ToState ? "pressed" : "released");
}
}
// Power : Give/remove traction cut-off relay closing authorization switch
[Serializable()]
public sealed class TractionCutOffRelayClosingAuthorizationCommand : BooleanCommand
{
public static ILocomotivePowerSupply Receiver { get; set; }
public TractionCutOffRelayClosingAuthorizationCommand(CommandLog log, bool toState)
: base(log, toState)
{
Redo();
}
public override void Redo()
{
Receiver?.HandleEvent(ToState ? PowerSupplyEvent.GiveTractionCutOffRelayClosingAuthorization : PowerSupplyEvent.RemoveTractionCutOffRelayClosingAuthorization);
}
public override string ToString()
{
return base.ToString() + " - " + (ToState ? "given" : "removed");
}
}
// Power : Service retention button
[Serializable()]
public sealed class ServiceRetentionButtonCommand : BooleanCommand
{
public static ILocomotivePowerSupply Receiver { get; set; }
public ServiceRetentionButtonCommand(CommandLog log, bool toState)
: base(log, toState)
{
Redo();
}
public override void Redo()
{
Receiver?.HandleEvent(ToState ? PowerSupplyEvent.ServiceRetentionButtonPressed : PowerSupplyEvent.ServiceRetentionButtonReleased);
}
public override string ToString()
{
return base.ToString() + " - " + (ToState ? "pressed" : "released");
}
}
// Power : Service retention cancellation button
[Serializable()]
public sealed class ServiceRetentionCancellationButtonCommand : BooleanCommand
{
public static ILocomotivePowerSupply Receiver { get; set; }
public ServiceRetentionCancellationButtonCommand(CommandLog log, bool toState)
: base(log, toState)
{
Redo();
}
public override void Redo()
{
Receiver?.HandleEvent(ToState ? PowerSupplyEvent.ServiceRetentionCancellationButtonPressed : PowerSupplyEvent.ServiceRetentionCancellationButtonReleased);
}
public override string ToString()
{
return base.ToString() + " - " + (ToState ? "pressed" : "released");
}
}
// Power
[Serializable()]
public sealed class PowerCommand : BooleanCommand
{
public static MSTSLocomotive Receiver { get; set; }
public PowerCommand(CommandLog log, MSTSLocomotive receiver, bool toState)
: base(log, toState)
{
Receiver = receiver;
Redo();
}
public override void Redo()
{
Receiver?.SetPower(ToState);
}
public override string ToString()
{
return base.ToString() + " - " + (ToState ? "ON" : "OFF");
}
}
// MU commands connection
[Serializable()]
public sealed class ToggleMUCommand : BooleanCommand
{
public static MSTSLocomotive Receiver { get; set; }
public ToggleMUCommand(CommandLog log, MSTSLocomotive receiver, bool toState)
: base(log, toState)
{
Receiver = receiver;
Redo();
}
public override void Redo()
{
Receiver?.ToggleMUCommand(ToState);
}
public override string ToString()
{
return base.ToString() + " - " + (ToState ? "ON" : "OFF");
}
}
[Serializable()]
public sealed class NotchedThrottleCommand : BooleanCommand
{
public static MSTSLocomotive Receiver { get; set; }
public NotchedThrottleCommand(CommandLog log, bool toState) : base(log, toState)
{
Redo();
}
public override void Redo()
{
Receiver.AdjustNotchedThrottle(ToState);
// Report();
}
public override string ToString()
{
return base.ToString() + " - " + (ToState ? "step forward" : "step back");
}
}
[Serializable()]
public sealed class ContinuousThrottleCommand : ContinuousCommand
{
public static MSTSLocomotive Receiver { get; set; }
public ContinuousThrottleCommand(CommandLog log, bool toState, float? target, double startTime)
: base(log, toState, target, startTime)
{
Redo();
}
public override void Redo()
{
Receiver.ThrottleChangeTo(ToState, Target);
// Report();
}
}
// Brakes
[Serializable()]
public sealed class TrainBrakeCommand : ContinuousCommand
{
public static MSTSLocomotive Receiver { get; set; }
public TrainBrakeCommand(CommandLog log, bool toState, float? target, double startTime)
: base(log, toState, target, startTime)
{
Redo();
}
public override void Redo()
{
Receiver.TrainBrakeChangeTo(ToState, Target);
// Report();
}
}
[Serializable()]
public sealed class EngineBrakeCommand : ContinuousCommand
{
public static MSTSLocomotive Receiver { get; set; }
public EngineBrakeCommand(CommandLog log, bool toState, float? target, double startTime)
: base(log, toState, target, startTime)
{
Redo();
}
public override void Redo()
{
Receiver.EngineBrakeChangeTo(ToState, Target);
// Report();
}
}
[Serializable()]
public sealed class BrakemanBrakeCommand : ContinuousCommand
{
public static MSTSLocomotive Receiver { get; set; }
public BrakemanBrakeCommand(CommandLog log, bool toState, float? target, double startTime)
: base(log, toState, target, startTime)
{
Redo();
}
public override void Redo()
{
Receiver.BrakemanBrakeChangeTo(ToState, Target);
// Report();
}
}
[Serializable()]
public sealed class DynamicBrakeCommand : ContinuousCommand
{
public static MSTSLocomotive Receiver { get; set; }
public DynamicBrakeCommand(CommandLog log, bool toState, float? target, double startTime)
: base(log, toState, target, startTime)
{
Redo();
}
public override void Redo()
{
Receiver.DynamicBrakeChangeTo(ToState, Target);
// Report();
}
}
[Serializable()]
public sealed class InitializeBrakesCommand : Command
{
public static Train Receiver { get; set; }
public InitializeBrakesCommand(CommandLog log)
: base(log)
{
Redo();
}
public override void Redo()
{
Receiver.UnconditionalInitializeBrakes();
}
}
[Serializable()]
public sealed class ResetOutOfControlModeCommand : Command
{
public static Train Receiver { get; set; }
public ResetOutOfControlModeCommand(CommandLog log) : base(log)
{
Redo();
}
public override void Redo()
{
Receiver.ManualResetOutOfControlMode();
Receiver.SignalEvent(TCSEvent.ManualResetOutOfControlMode);
}
}
[Serializable()]
public sealed class EmergencyPushButtonCommand : BooleanCommand
{
public static MSTSLocomotive Receiver { get; set; }
public EmergencyPushButtonCommand(CommandLog log, bool toState)
: base(log, toState)
{
Redo();
}
public override void Redo()
{
Receiver.EmergencyButtonPressed = ToState;
Receiver.TrainBrakeController.EmergencyBrakingPushButton = ToState;
}
}
[Serializable()]
public sealed class BailOffCommand : BooleanCommand
{
public static MSTSLocomotive Receiver { get; set; }
public BailOffCommand(CommandLog log, bool toState)
: base(log, toState)
{
Redo();
}
public override void Redo()
{
Receiver.SetBailOff(ToState);
// Report();
}
public override string ToString()
{
return base.ToString() + " - " + (ToState ? "disengage" : "engage");
}
}
[Serializable()]
public sealed class QuickReleaseCommand : BooleanCommand
{
public static MSTSLocomotive Receiver { get; set; }
public QuickReleaseCommand(CommandLog log, bool toState)
: base(log, toState)
{
Redo();
}
public override void Redo()
{
Receiver.TrainBrakeController.QuickReleaseButtonPressed = ToState;
// Report();
}
public override string ToString()
{
return base.ToString() + " - " + (ToState ? "off" : "on");
}
}
[Serializable()]
public sealed class BrakeOverchargeCommand : BooleanCommand
{
public static MSTSLocomotive Receiver { get; set; }
public BrakeOverchargeCommand(CommandLog log, bool toState)
: base(log, toState)
{
Redo();
}
public override void Redo()
{
Receiver.TrainBrakeController.OverchargeButtonPressed = ToState;
// Report();
}
public override string ToString()
{
return base.ToString() + " - " + (ToState ? "off" : "on");
}
}
[Serializable()]
public sealed class HandbrakeCommand : BooleanCommand
{
public static MSTSLocomotive Receiver { get; set; }
public HandbrakeCommand(CommandLog log, bool toState)
: base(log, toState)
{
Redo();
}
public override void Redo()
{
Receiver.SetTrainHandbrake(ToState);
// Report();
}
public override string ToString()
{
return base.ToString() + " - " + (ToState ? "apply" : "release");
}
}
[Serializable()]
public sealed class WagonHandbrakeCommand : BooleanCommand
{
public static MSTSWagon Receiver { get; set; }
public WagonHandbrakeCommand(CommandLog log, MSTSWagon car, bool toState)
: base(log, toState)
{
Receiver = car;
Redo();
}
public override void Redo()
{
Receiver.SetWagonHandbrake(ToState);
// Report();
}
public override string ToString()
{
return base.ToString() + " - " + (ToState ? "apply" : "release");
}
}
[Serializable()]
public sealed class RetainersCommand : BooleanCommand
{
public static MSTSLocomotive Receiver { get; set; }
public RetainersCommand(CommandLog log, bool toState)
: base(log, toState)
{
Redo();
}
public override void Redo()
{
Receiver.SetTrainRetainers(ToState);
// Report();
}
public override string ToString()
{
return base.ToString() + " - " + (ToState ? "apply" : "release");
}
}
[Serializable()]
public sealed class BrakeHoseConnectCommand : BooleanCommand
{
public static MSTSLocomotive Receiver { get; set; }
public BrakeHoseConnectCommand(CommandLog log, bool toState)
: base(log, toState)
{
Redo();
}
public override void Redo()
{
Receiver.BrakeHoseConnect(ToState);
// Report();
}
public override string ToString()
{
return base.ToString() + " - " + (ToState ? "connect" : "disconnect");
}
}
[Serializable()]
public sealed class WagonBrakeHoseConnectCommand : BooleanCommand
{
public static MSTSWagon Receiver { get; set; }
public WagonBrakeHoseConnectCommand(CommandLog log, MSTSWagon car, bool toState)
: base(log, toState)
{
Receiver = car;
Redo();
}
public override void Redo()
{
Receiver.BrakeSystem.FrontBrakeHoseConnected = ToState;
// Report();
}
public override string ToString()
{
return base.ToString() + " - " + (ToState ? "connect" : "disconnect");
}
}
[Serializable()]
public sealed class ToggleAngleCockACommand : BooleanCommand
{
public static MSTSWagon Receiver { get; set; }
public ToggleAngleCockACommand(CommandLog log, MSTSWagon car, bool toState)
: base(log, toState)
{
Receiver = car;
Redo();
}
public override void Redo()
{
Receiver.BrakeSystem.AngleCockAOpen = ToState;
// Report();
}
public override string ToString()
{
return base.ToString() + " - " + (ToState ? "open" : "close");
}
}
[Serializable()]
public sealed class ToggleAngleCockBCommand : BooleanCommand
{
public static MSTSWagon Receiver { get; set; }
public ToggleAngleCockBCommand(CommandLog log, MSTSWagon car, bool toState)
: base(log, toState)
{
Receiver = car;
Redo();
}
public override void Redo()
{
Receiver.BrakeSystem.AngleCockBOpen = ToState;
// Report();
}
public override string ToString()
{
return base.ToString() + " - " + (ToState ? "open" : "close");
}
}
[Serializable()]
public sealed class ToggleBleedOffValveCommand : BooleanCommand
{
public static MSTSWagon Receiver { get; set; }
public ToggleBleedOffValveCommand(CommandLog log, MSTSWagon car, bool toState)
: base(log, toState)
{
Receiver = car;
Redo();
}
public override void Redo()
{
Receiver.BrakeSystem.BleedOffValveOpen = ToState;
// Report();
}
public override string ToString()
{
return base.ToString() + " - " + (ToState ? "open" : "close");
}
}
[Serializable()]
public sealed class SanderCommand : BooleanCommand
{
public static MSTSLocomotive Receiver { get; set; }
public SanderCommand(CommandLog log, bool toState)
: base(log, toState)
{
Redo();
}
public override void Redo()
{
if (ToState)
{
if (!Receiver.Sander)
Receiver.Train.SignalEvent(Event.SanderOn);
}
else
{
Receiver.Train.SignalEvent(Event.SanderOff);
}
// Report();
}
public override string ToString()
{
return base.ToString() + " - " + (ToState ? "on" : "off");
}
}
[Serializable()]
public sealed class AlerterCommand : BooleanCommand
{
public static MSTSLocomotive Receiver { get; set; }
public AlerterCommand(CommandLog log, bool toState)
: base(log, toState)