public static bool Prefix(LocoControllerDiesel __instance, ref float __result) { var state = ExtraState.Instance(__instance.sim); __result = state.tractiveEffort; return(false); }
public static bool Prefix(LocoControllerDiesel __instance) { var sim = __instance.sim; sim.throttle.SetValue(sim.engineOn ? ThrottleNotching.Notched(__instance.targetThrottle) : 0.0f); return(false); }
public static bool Prefix(LocoControllerDiesel __instance, ref float __result) { if (!__instance.sim.engineOn) { return(true); } __result = Mathf.Lerp(275f / 10f, 835f / 10f, __instance.sim.engineRPM.value); return(false); // Main.DebugLog(() => $"gauge: {TrainCar.Resolve(__instance.gameObject).carType} {__instance.name}: unclamped={__instance.unclamped}, min={__instance.minValue}, max={__instance.maxValue}, minAngle={__instance.minAngle}, maxAngle={__instance.maxAngle}"); }
static void Postfix(LocoControllerBase __instance, float nextTargetIndependentBrake) { TrainCar currentCar = __instance.GetComponent <TrainCar>(); TrainCar targetCar = null; Trainset trainset = null; if (Main.remoteCar) { targetCar = Main.remoteCar; trainset = targetCar.trainset; } else if (PlayerManager.Car != null) { targetCar = PlayerManager.Car; trainset = PlayerManager.Car.trainset; } if (currentCar == null || targetCar == null || !targetCar.Equals(currentCar) || trainset == null || trainset.cars.Count < 2) { return; } for (int i = 0; i < trainset.cars.Count; i++) { TrainCar car = trainset.cars[i]; if (targetCar.Equals(car)) { continue; } if (car.carType == TrainCarType.LocoShunter) { LocoControllerShunter locoController = car.GetComponent <LocoControllerShunter>(); if (locoController) { locoController.SetIndependentBrake(nextTargetIndependentBrake); } } else if (car.carType == TrainCarType.LocoDiesel) { LocoControllerDiesel locoController = car.GetComponent <LocoControllerDiesel>(); if (locoController) { locoController.SetIndependentBrake(nextTargetIndependentBrake); } } } }
static void Prefix(LocoControllerDiesel __instance, ToggleDirection toggle) { TrainCar targetCar = __instance.GetComponent <TrainCar>(); Trainset trainset = targetCar.trainset; if (trainset == null) { return; } for (int i = 0; i < trainset.cars.Count; i++) { TrainCar car = trainset.cars[i]; if (targetCar.Equals(car)) { continue; } if (car.carType == TrainCarType.LocoShunter) { LocoControllerShunter locoController = car.GetComponent <LocoControllerShunter>(); if (locoController != null) { locoController.SetSandersOn(toggle == ToggleDirection.UP); } } else if (car.carType == TrainCarType.LocoDiesel) { LocoControllerDiesel locoController = car.GetComponent <LocoControllerDiesel>(); if (locoController != null) { locoController.SetSandersOn(toggle == ToggleDirection.UP); } } } }
static IEnumerator <object> AttachListeners() { yield return((object)null); DV.CabControls.ControlImplBase sandDeployCtrl = instance.sandDeployBtn.GetComponent <DV.CabControls.ControlImplBase>(); sandDeployCtrl.ValueChanged += (e => { if (PlayerManager.Car == null || PlayerManager.Car.trainset == null) { return; } for (int i = 0; i < PlayerManager.Car.trainset.cars.Count; i++) { TrainCar car = PlayerManager.Car.trainset.cars[i]; if (PlayerManager.Car.Equals(car)) { continue; } if (car.carType == TrainCarType.LocoShunter) { LocoControllerShunter locoController = car.GetComponent <LocoControllerShunter>(); if (locoController) { locoController.SetSandersOn(e.newValue >= 0.5f); } } else if (car.carType == TrainCarType.LocoDiesel) { LocoControllerDiesel locoController = car.GetComponent <LocoControllerDiesel>(); if (locoController) { locoController.SetSandersOn(e.newValue >= 0.5f); } } } }); DV.CabControls.ControlImplBase fanCtrl = instance.fanSwitchButton.GetComponent <DV.CabControls.ControlImplBase>(); fanCtrl.ValueChanged += (e => { if (PlayerManager.Car == null || PlayerManager.Car.trainset == null) { return; } for (int i = 0; i < PlayerManager.Car.trainset.cars.Count; i++) { TrainCar car = PlayerManager.Car.trainset.cars[i]; if (PlayerManager.Car.Equals(car)) { continue; } if (car.carType == TrainCarType.LocoShunter) { LocoControllerShunter locoController = car.GetComponent <LocoControllerShunter>(); if (locoController) { locoController.SetFan(e.newValue >= 0.5f); } } else if (car.carType == TrainCarType.LocoDiesel) { LocoControllerDiesel locoController = car.GetComponent <LocoControllerDiesel>(); if (locoController) { locoController.SetFan(e.newValue >= 0.5f); } } } }); }
static void Postfix(LocoControllerDiesel __instance, float position) { TrainCar currentCar = __instance.GetComponent <TrainCar>(); TrainCar targetCar = null; Trainset trainset = null; if (Main.remoteCar) { targetCar = Main.remoteCar; trainset = targetCar.trainset; } else if (PlayerManager.Car != null) { targetCar = PlayerManager.Car; trainset = PlayerManager.Car.trainset; } if (currentCar == null || targetCar == null || !targetCar.Equals(currentCar) || trainset == null || trainset.cars.Count < 2) { return; } List <TrainCar> trainsetCars = trainset.cars; for (int i = 0; i < trainsetCars.Count; i++) { TrainCar car = trainsetCars[i]; if (targetCar.Equals(car)) { continue; } LocoControllerBase locoController = null; if (car.carType == TrainCarType.LocoShunter) { locoController = car.GetComponent <LocoControllerShunter>(); } else if (car.carType == TrainCarType.LocoDiesel) { locoController = car.GetComponent <LocoControllerDiesel>(); } if (locoController != null) { if (GetCarsBehind(targetCar).Contains(car)) { if (GetCarsInFrontOf(car).Contains(targetCar)) { locoController.SetReverser(position); } else { locoController.SetReverser(position * -1f); } } else if (GetCarsInFrontOf(targetCar).Contains(car)) { if (GetCarsBehind(car).Contains(targetCar)) { locoController.SetReverser(position); } else { locoController.SetReverser(position * -1f); } } } } }