Esempio n. 1
0
 public static void Postfix(LocoControllerBase __instance, float __result)
 {
     if (!AppUtil.IsPaused)
     {
         tractiveEffortProvider.SetValue(__instance.train, __result);
         indicatedPowerProvider.SetValue(__instance.train, __result * __instance.GetSpeedKmH() / 3.6f);
     }
 }
Esempio n. 2
0
 public override void GetState([NotNull] BaseLocoState state)
 {
     state.Reverser       = _inner.reverser;
     state.ReverserSymbol = _inner.GetReverserSymbol();
     state.Throttle       = (float)Math.Round(_inner.throttle, 2);
     state.TargetThrottle = (float)Math.Round(_inner.targetThrottle, 2);
     state.Break          = (float)Math.Round(_inner.brake, 2);
     state.TargetBreak    = (float)Math.Round(_inner.targetBrake, 2);
     state.Derailed       = _inner.IsDerailed();
     state.WheelSlip      = _inner.IsWheelslipping();
     state.Speed          = (float)Math.Round(_inner.GetSpeedKmH(), 2);
     state.CanCouple      = _inner.IsCouplerInRange();
     state.MinCouplePos   = -_inner.GetNumberOfCarsInRear() - 1;
     state.MaxCouplePos   = _inner.GetNumberOfCarsInFront() + 1;
     state.LocoType       = "base";
 }
Esempio n. 3
0
        /// <summary>
        /// Determines whether this locomotive is eligible for automatic shutdown on player exit
        /// </summary>
        /// <param name="Loco">Locomotive</param>
        /// <returns>true, if should be shut down</returns>
        private static bool ShouldPerformAutoShutdown(LocoControllerBase Loco)
        {
            var s = Main.settings.ShutdownOptions;

            if (s == null)
            {
                s = new AutomaticShutdownOptions();
            }
            //Don't do anything if this object is not present
            if (Loco == null)
            {
                WarnMessage("ShouldPerformAutoShutdown argument is <null> but should not be");
                return(false);
            }
            //Don't shut down if cars are coupled
            if (s.NoCarsCoupled && (Loco.GetNumberOfCarsInFront() > 0 || Loco.GetNumberOfCarsInRear() > 0))
            {
                return(false);
            }
            //Don't shut down if a coupler is in range
            if (s.NoCarsInCouplingRange && Loco.IsCouplerInRange(LocoControllerBase.COUPLING_RANGE))
            {
                return(false);
            }
            //Don't shut down if rolling
            if (s.MustBeStationary && Math.Abs(Loco.GetSpeedKmH()) >= 1.0f)
            {
                return(false);
            }
            //Don't shut down if the reverser is not centered
            if (s.ReverserCentered && Math.Abs(Loco.reverser) >= 0.1f)
            {
                return(false);
            }
            //Don't shut down if independent brake not at least 90% applied
            if (s.IndependentBrakesApplied && Loco.independentBrake < 0.9f)
            {
                return(false);
            }
            //Don't shut down if remote controlled
            if (s.RemoteControlDisconnected && Loco.IsRemoteControlled())
            {
                return(false);
            }
            //All checks passed
            return(true);
        }
Esempio n. 4
0
        private void OnGUI()
        {
            Color defaultColor = GUI.color;

            if (Instance == null)
            {
                return;
            }

            GUILayout.BeginVertical();

            GUILayout.BeginHorizontal();

            // row spacer
            GUILayout.BeginVertical();
            GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true), GUILayout.MaxWidth(1920));
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();             // row spacer end

            // row last
            GUILayout.BeginVertical();

            // stats box
            GUILayout.BeginVertical(GUI.skin.box, GUILayout.Width(200));

            if (Instance.MasterLoco != null)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label($"Master [{Instance.MasterLoco.ID}]", GUILayout.Width(150));
                GUILayout.EndHorizontal();

                LocoControllerBase masterBase = Instance.MasterLoco.GetComponent <LocoControllerBase>();

                GUILayout.BeginHorizontal();
                GUILayout.Label("Throttle", GUILayout.Width(150));
                GUILayout.Label(masterBase.throttle.ToString("n2"));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label($"Reverser [{((masterBase.reverser > 0) ? "FWD" : (masterBase.reverser < 0) ? "BWD" : "NTR")}]", GUILayout.Width(150));
                GUILayout.Label(masterBase.reverser.ToString("n2"));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("Speed", GUILayout.Width(150));
                GUILayout.Label(masterBase.GetSpeedKmH().ToString("n2"));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("Speed (FWD)", GUILayout.Width(150));
                GUILayout.Label(masterBase.GetForwardSpeed().ToString("n2"));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("Brake", GUILayout.Width(150));
                GUILayout.Label(masterBase.brake.ToString("n2"));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("Brake Ind.", GUILayout.Width(150));
                GUILayout.Label(masterBase.independentBrake.ToString("n2"));
                GUILayout.EndHorizontal();
            }

            GUILayout.EndVertical();             // stats box end

            GUILayout.EndVertical();             // row last end

            GUILayout.EndHorizontal();


            // column spacer
            GUILayout.BeginHorizontal();
            GUILayout.BeginVertical(GUILayout.ExpandHeight(true), GUILayout.MaxHeight(1080));
            GUILayout.FlexibleSpace();
            GUILayout.EndVertical();
            GUILayout.EndHorizontal();            // column spacer end

            GUILayout.BeginHorizontal();
            GUILayout.Label("DV TS", GUILayout.Width(30));

            if (Instance.MasterLoco != null && Instance.MasterLoco.trainset.cars != null)
            {
                for (int i = 0; i < Instance.MasterLoco.trainset.cars.Count; i++)
                {
                    int index = Instance.MasterLoco.trainset.cars.Count - 1 - i;
                    GUILayout.BeginVertical(GUI.skin.box, GUILayout.Width(100));

                    if (Instance.MasterLoco.trainset.cars[index] == Instance.MasterLoco)
                    {
                        GUI.color = Color.yellow;
                    }
                    else
                    {
                        if (Instance.MasterLoco.trainset.cars[index].IsLoco)
                        {
                        }
                        else if (Instance.MasterLoco.trainset.cars[index] == Instance.MasterLoco.trainset.firstCar)
                        {
                            GUI.color = Color.green;
                        }
                        else if (Instance.MasterLoco.trainset.cars[index] == Instance.MasterLoco.trainset.lastCar)
                        {
                            GUI.color = Color.red;
                        }
                        else
                        {
                            GUI.color = Color.gray;
                        }
                    }

                    GUILayout.Label(Instance.MasterLoco.trainset.cars[index].ID);

                    GUI.color = defaultColor;

                    GUILayout.EndVertical();
                }
            }

            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("CBX TS", GUILayout.Width(30));

            if (sortedTrainSet != null && sortedTrainSet.cars != null)
            {
                for (int i = 0; i < sortedTrainSet.cars.Count; i++)
                {
                    int index = sortedTrainSet.cars.Count - 1 - i;
                    GUILayout.BeginVertical(GUI.skin.box, GUILayout.Width(100));

                    if (sortedTrainSet.cars[index].trainCar == Instance.MasterLoco)
                    {
                        GUI.color = Color.yellow;
                    }
                    else
                    {
                        if (sortedTrainSet.cars[index].trainCar.IsLoco)
                        {
                        }
                        else if (sortedTrainSet.cars[index].trainCar == sortedTrainSet.cars.First().trainCar)
                        {
                            GUI.color = Color.green;
                        }
                        else if (sortedTrainSet.cars[index].trainCar == sortedTrainSet.cars.Last().trainCar)
                        {
                            GUI.color = Color.red;
                        }
                        else
                        {
                            GUI.color = Color.gray;
                        }
                    }

                    GUILayout.Label($"{sortedTrainSet.cars[index].trainCar.ID} {((sortedTrainSet.cars[index].trainCar == Instance.MasterLoco) ? "[M]":"")}");
                    GUILayout.Label((sortedTrainSet.cars[index].forward) ? "FWD" : "BWD");

                    GUI.color = defaultColor;

                    GUILayout.EndVertical();
                }
            }

            GUILayout.EndHorizontal();

            GUILayout.EndVertical();
        }
Esempio n. 5
0
 public static void Postfix(LocoControllerBase __instance, float __result)
 {
     if (!AppUtil.IsPaused)
     {
         tractiveEffortProvider.SetValue(__instance.train, new Force(__result, Newton));
         indicatedPowerProvider.SetValue(__instance.train, new Force(__result, Newton) * new Velocity(__instance.GetSpeedKmH(), KilometersPerHour));
     }
 }