static void Postfix(LocoControllerShunter __instance)
        {
            AnimationCurve accAnimationCurve = __instance.tractionTorqueCurve;

            accAnimationCurve.RemoveKey(2);
            accAnimationCurve.AddKey(300f, 0f);
        }
Exemple #2
0
            public static bool Prefix(LocoControllerShunter __instance)
            {
                var sim = __instance.sim;

                sim.throttle.SetValue(sim.engineOn ? ThrottleNotching.Notched(__instance.targetThrottle) : 0.0f);
                return(false);
            }
        void Awake()
        {
            var audioAnchors = transform?.Find("Audio anchors");
            var engineAudio  = audioAnchors.transform?.Find("Engine");

            var Engine_Layered = engineAudio?.Find("Engine_Layered(Clone)");

            var Engine_Layered_Audio = Engine_Layered.GetComponent <LayeredAudio>();

            var EngineFan_Layered = new GameObject();

            EngineFan_Layered.name                    = "EngineFan_Layered";
            EngineFan_Layered.transform.parent        = engineAudio;
            EngineFan_Layered.transform.localPosition = Vector3.zero;
            EngineFan_Layered.transform.localRotation = Quaternion.identity;

            var train_engine_layer_fan = new GameObject();

            train_engine_layer_fan.name                    = "train_engine_layer_fan";
            train_engine_layer_fan.transform.parent        = EngineFan_Layered.transform;
            train_engine_layer_fan.transform.localPosition = Vector3.zero;
            train_engine_layer_fan.transform.localRotation = Quaternion.identity;

            var audioSource = train_engine_layer_fan.AddComponent <AudioSource>();

            audioSource.outputAudioMixerGroup = Engine_Layered_Audio.audioMixerGroup;
            audioSource.playOnAwake           = true;
            audioSource.loop         = true;
            audioSource.maxDistance  = 300f;
            audioSource.clip         = Main.fanAudioClip;
            audioSource.spatialBlend = 1f;
            audioSource.dopplerLevel = 0f;
            audioSource.spread       = 10f;

            var audioLayer = new LayeredAudio.Layer();

            audioLayer.name          = "engine_fan";
            audioLayer.volumeCurve   = AnimationCurve.Linear(0f, 0f, 1f, 1f);
            audioLayer.usePitchCurve = false;
            audioLayer.inertia       = 0f;
            audioLayer.inertialPitch = false;
            audioLayer.source        = audioSource;
            audioLayer.refVelo       = 0f;
            audioLayer.startPitch    = 0.5f;

            var layeredAudio = EngineFan_Layered.AddComponent <LayeredAudio>();

            layeredAudio.audioMixerGroup = Engine_Layered_Audio.audioMixerGroup;
            layeredAudio.layers          = new LayeredAudio.Layer[1];
            layeredAudio.layers[0]       = audioLayer;
            layeredAudio.RandomizeTime();
            layeredAudio.Reset();
            layeredAudio.Play();
            layeredAudio.masterVolume = 0.6f;

            fanAudio   = layeredAudio;
            controller = gameObject.GetComponent <LocoControllerShunter>();
        }
Exemple #4
0
        protected override void Init()
        {
            base.Init();

            _controller = GetComponent <LocoControllerShunter>();
            _action     = new LocoShunterActionPacket()
            {
                Id = Id
            };
        }
        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);
                    }
                }
            }
        }
Exemple #7
0
        public static LocoAI GetLocoAI(TrainCar car)
        {
            LocoAI locoAI;

            if (!locosAI.TryGetValue(car.logicCar.ID, out locoAI))
            {
                DieselLocoSimulation dieselSim = car.GetComponent <DieselLocoSimulation>();
                if (dieselSim != null)
                {
                    if (!dieselSim.engineOn)
                    {
                        throw new CommandException("Engine off");
                    }
                }
                else
                {
                    ShunterLocoSimulation shunterSim = car.GetComponent <ShunterLocoSimulation>();
                    if (shunterSim != null)
                    {
                        if (!shunterSim.engineOn)
                        {
                            throw new CommandException("Engine off");
                        }
                    }
                    else
                    {
                        throw new CommandException("Loco not compatible");
                    }
                }

                LocoControllerShunter    shunterController = car.GetComponent <LocoControllerShunter>();
                ILocomotiveRemoteControl remote            = car.GetComponent <ILocomotiveRemoteControl>();
                locoAI = new LocoAI(remote);
                locosAI.Add(car.logicCar.ID, locoAI);
            }

            return(locoAI);
        }
        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(LocoControllerShunter __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);
                        }
                    }
                }
            }
        }
Exemple #10
0
 public LocoShunter(LocoControllerShunter inner)
 {
     _inner = inner;
     _base  = new LocoBase(inner);
     _sim   = inner.GetComponent <ShunterLocoSimulation>();
 }
Exemple #11
0
 public ExtraState(LocoControllerShunter controller)
 {
     this.controller = controller;
 }
Exemple #12
0
 public static bool Prefix(LocoControllerShunter __instance, ref float __result)
 {
     __result = TransmissionEfficiency * CrankshaftPower(__instance.sim) / Mathf.Max(1f, Mathf.Abs(__instance.GetForwardSpeed()));
     return(false);
 }
Exemple #13
0
        static void Postfix(LocoControllerShunter __instance)
        {
            ShunterLocoSimulation sim = (ShunterLocoSimulation)Helper.Get(__instance, "sim");

            dict.Add(sim, __instance);
        }