protected virtual void AssignScriptFunctions() { // AbstractScriptClass Script.ClockTime = () => (float)Simulator.ClockTime; Script.GameTime = () => (float)Simulator.GameTime; Script.PreUpdate = () => Simulator.PreUpdate; Script.DistanceM = () => Wagon.DistanceM; Script.SpeedMpS = () => Math.Abs(Wagon.SpeedMpS); Script.Confirm = Simulator.Confirmer.Confirm; Script.Message = Simulator.Confirmer.Message; Script.SignalEvent = Wagon.SignalEvent; Script.SignalEventToTrain = (evt) => Train?.SignalEvent(evt); // AbstractPowerSupply getters Script.CurrentElectricTrainSupplyState = () => ElectricTrainSupplyState; Script.CurrentLowVoltagePowerSupplyState = () => LowVoltagePowerSupplyState; Script.CurrentBatteryState = () => BatteryState; Script.BatterySwitchOn = () => BatterySwitch.On; // PassengerCarPowerSupply getters Script.CurrentVentilationState = () => VentilationState; Script.CurrentHeatingState = () => HeatingState; Script.CurrentAirConditioningState = () => AirConditioningState; Script.CurrentElectricTrainSupplyPowerW = () => ElectricTrainSupplyPowerW; Script.CurrentHeatFlowRateW = () => HeatFlowRateW; Script.ContinuousPowerW = () => ContinuousPowerW; Script.HeatingPowerW = () => HeatingPowerW; Script.AirConditioningPowerW = () => AirConditioningPowerW; Script.AirConditioningYield = () => AirConditioningYield; Script.PowerOnDelayS = () => PowerOnDelayS; Script.DesiredTemperatureC = () => Wagon.DesiredCompartmentTempSetpointC; Script.InsideTemperatureC = () => Wagon.CarInsideTempC; Script.OutsideTemperatureC = () => Wagon.CarOutsideTempC; // AbstractPowerSupply setters Script.SetCurrentLowVoltagePowerSupplyState = (value) => LowVoltagePowerSupplyState = value; Script.SetCurrentBatteryState = (value) => BatteryState = value; Script.SignalEventToBatterySwitch = (evt) => BatterySwitch.HandleEvent(evt); Script.SignalEventToPantographs = (evt) => Wagon.Pantographs.HandleEvent(evt); Script.SignalEventToPantograph = (evt, id) => Wagon.Pantographs.HandleEvent(evt, id); // PassengerCarPowerSupply setters Script.SetCurrentVentilationState = (value) => VentilationState = value; Script.SetCurrentHeatingState = (value) => HeatingState = value; Script.SetCurrentAirConditioningState = (value) => AirConditioningState = value; Script.SetCurrentElectricTrainSupplyPowerW = (value) => { if (value >= 0f) { ElectricTrainSupplyPowerW = value; } }; Script.SetCurrentHeatFlowRateW = (value) => HeatFlowRateW = value; }
protected virtual void AssignScriptFunctions() { // AbstractScriptClass AbstractScript.ClockTime = () => (float)Simulator.ClockTime; AbstractScript.GameTime = () => (float)Simulator.GameTime; AbstractScript.PreUpdate = () => Simulator.PreUpdate; AbstractScript.DistanceM = () => Locomotive.DistanceM; AbstractScript.SpeedMpS = () => Math.Abs(Locomotive.SpeedMpS); AbstractScript.Confirm = Locomotive.Simulator.Confirmer.Confirm; AbstractScript.Message = Locomotive.Simulator.Confirmer.Message; AbstractScript.SignalEvent = Locomotive.SignalEvent; AbstractScript.SignalEventToTrain = (evt) => { if (Locomotive.Train != null) { Locomotive.Train.SignalEvent(evt); } }; // AbstractPowerSupply getters AbstractScript.CurrentMainPowerSupplyState = () => MainPowerSupplyState; AbstractScript.CurrentAuxiliaryPowerSupplyState = () => AuxiliaryPowerSupplyState; AbstractScript.CurrentElectricTrainSupplyState = () => ElectricTrainSupplyState; AbstractScript.CurrentLowVoltagePowerSupplyState = () => LowVoltagePowerSupplyState; AbstractScript.CurrentBatteryState = () => BatteryState; AbstractScript.CurrentCabPowerSupplyState = () => CabPowerSupplyState; AbstractScript.CurrentHelperEnginesState = () => { DieselEngineState state = DieselEngineState.Unavailable; foreach (MSTSDieselLocomotive locomotive in Train.Cars.OfType <MSTSDieselLocomotive>().Where((MSTSLocomotive locomotive) => { return(locomotive.AcceptMUSignals); })) { if (locomotive == Simulator.PlayerLocomotive) { foreach (DieselEngine dieselEngine in locomotive.DieselEngines.DEList.Where(de => de != locomotive.DieselEngines[0])) { if (dieselEngine.State > state) { state = dieselEngine.State; } } } else { foreach (DieselEngine dieselEngine in locomotive.DieselEngines) { if (dieselEngine.State > state) { state = dieselEngine.State; } } } } return(state); }; AbstractScript.CurrentDynamicBrakeAvailability = () => DynamicBrakeAvailable; AbstractScript.ThrottlePercent = () => Locomotive.ThrottlePercent; AbstractScript.PowerOnDelayS = () => PowerOnDelayS; AbstractScript.AuxPowerOnDelayS = () => AuxPowerOnDelayS; AbstractScript.BatterySwitchOn = () => BatterySwitch.On; AbstractScript.MasterKeyOn = () => MasterKey.On; AbstractScript.ElectricTrainSupplySwitchOn = () => ElectricTrainSupplySwitch.On; AbstractScript.ElectricTrainSupplyUnfitted = () => ElectricTrainSupplySwitch.Mode == ElectricTrainSupplySwitch.ModeType.Unfitted; // AbstractPowerSupply setters AbstractScript.SetCurrentMainPowerSupplyState = (value) => MainPowerSupplyState = value; AbstractScript.SetCurrentAuxiliaryPowerSupplyState = (value) => AuxiliaryPowerSupplyState = value; AbstractScript.SetCurrentElectricTrainSupplyState = (value) => ElectricTrainSupplyState = value; AbstractScript.SetCurrentLowVoltagePowerSupplyState = (value) => LowVoltagePowerSupplyState = value; AbstractScript.SetCurrentBatteryState = (value) => BatteryState = value; AbstractScript.SetCurrentCabPowerSupplyState = (value) => CabPowerSupplyState = value; AbstractScript.SetCurrentDynamicBrakeAvailability = (value) => DynamicBrakeAvailable = value; AbstractScript.SignalEventToBatterySwitch = (evt) => BatterySwitch.HandleEvent(evt); AbstractScript.SignalEventToMasterKey = (evt) => MasterKey.HandleEvent(evt); AbstractScript.SignalEventToElectricTrainSupplySwitch = (evt) => ElectricTrainSupplySwitch.HandleEvent(evt); AbstractScript.SignalEventToPantographs = (evt) => Locomotive.Pantographs.HandleEvent(evt); AbstractScript.SignalEventToPantograph = (evt, id) => Locomotive.Pantographs.HandleEvent(evt, id); AbstractScript.SignalEventToTcs = (evt) => Locomotive.TrainControlSystem.HandleEvent(evt); AbstractScript.SignalEventToTcsWithMessage = (evt, message) => Locomotive.TrainControlSystem.HandleEvent(evt, message); AbstractScript.SignalEventToOtherLocomotives = (evt) => { if (Locomotive == Simulator.PlayerLocomotive) { foreach (MSTSLocomotive locomotive in Locomotive.Train.Cars.OfType <MSTSLocomotive>()) { if (locomotive != Locomotive && locomotive != Locomotive.Train.LeadLocomotive && locomotive.AcceptMUSignals) { locomotive.LocomotivePowerSupply.HandleEventFromLeadLocomotive(evt); } } } }; AbstractScript.SignalEventToOtherLocomotivesWithId = (evt, id) => { if (Locomotive == Simulator.PlayerLocomotive) { foreach (MSTSLocomotive locomotive in Locomotive.Train.Cars.OfType <MSTSLocomotive>()) { if (locomotive != Locomotive && locomotive != Locomotive.Train.LeadLocomotive && locomotive.AcceptMUSignals) { locomotive.LocomotivePowerSupply.HandleEventFromLeadLocomotive(evt, id); } } } }; AbstractScript.SignalEventToOtherTrainVehicles = (evt) => { if (Locomotive == Simulator.PlayerLocomotive) { foreach (TrainCar car in Locomotive.Train.Cars) { if (car != Locomotive && car != Locomotive.Train.LeadLocomotive && car.AcceptMUSignals) { car.PowerSupply?.HandleEventFromLeadLocomotive(evt); } } } }; AbstractScript.SignalEventToOtherTrainVehiclesWithId = (evt, id) => { if (Locomotive == Simulator.PlayerLocomotive) { foreach (TrainCar car in Locomotive.Train.Cars) { if (car != Locomotive && car != Locomotive.Train.LeadLocomotive && car.AcceptMUSignals) { car.PowerSupply?.HandleEventFromLeadLocomotive(evt, id); } } } }; AbstractScript.SignalEventToHelperEngines = (evt) => { bool helperFound = false; //this avoids that locomotive engines toggle in opposite directions foreach (MSTSDieselLocomotive locomotive in Train.Cars.OfType <MSTSDieselLocomotive>().Where((MSTSLocomotive locomotive) => { return(locomotive.AcceptMUSignals); })) { if (locomotive == Simulator.PlayerLocomotive) { // Engine number 1 or above are helper engines for (int i = 1; i < locomotive.DieselEngines.Count; i++) { if (!helperFound) { helperFound = true; } locomotive.DieselEngines.HandleEvent(evt, i); } } else { if (!helperFound) { helperFound = true; } locomotive.DieselEngines.HandleEvent(evt); } } if (helperFound && (evt == PowerSupplyEvent.StartEngine || evt == PowerSupplyEvent.StopEngine)) { Simulator.Confirmer.Confirm(CabControl.HelperDiesel, evt == PowerSupplyEvent.StartEngine ? CabSetting.On : CabSetting.Off); } }; }