Exemplo n.º 1
0
        public void SimulateTick(SteamLocoSimulation locoSim)
        {
            if (_turningOff)
            {
                // reset injector to 0
                locoSim.injector.SetNextValue(0f);
                locoSim.injector.SetValue(0f);
                _turningOff = false;
            }

            if (_mode == StokerMode.Off || locoSim == null || locoSim.fireOn.value <= 0.01f)
            {
                return;
            }

            float steamPressure = locoSim.boilerPressure.value;
            float coalLevel     = locoSim.coalbox.value;
            float waterLevel    = locoSim.boilerWater.value;

            if (
                coalLevel == 0 &&       // For some reason, these values are populated with real data only
                steamPressure == 0 &&   // once every 3 ticks. If they're these values above,
                waterLevel == 14400     // one of those magical skipped ticks. Do nothing.
                )
            {
                return;
            }

            // add coal if level is too low
            // only add a shovel every n seconds
            if (coalLevel < _coalTarget && _timeTilNextShovel <= 0)
            {
                locoSim.AddCoalChunk();
                _timeTilNextShovel = ShovelWaitTime;
            }

            var injectorSetting = CalculateInjectorSetting(waterLevel);

            locoSim.injector.SetNextValue(injectorSetting);
            locoSim.injector.SetValue(injectorSetting);
        }
Exemplo n.º 2
0
        static void Postfix(SteamLocoSimulation __instance)
        {
            // Target values for water, coal, steam
            // const float steamTarget = 9; // Not used right now but who knows, maybe I'll automate everything
            const float waterTarget = 15000;
            const float coalTarget  = 54;

            // Max deviations. Larger numbers will mean more fluctuation in the boiler.
            const float waterDiff = 750;

            float steamPressure = __instance.boilerPressure.value;
            float coalLevel     = __instance.coalbox.value;
            float waterLevel    = __instance.boilerWater.value;

            if (
                coalLevel == 0 &&       // For some reason, these values are populated with real data only
                steamPressure == 0 &&   // once every 3 ticks. If they're the values above, then this is
                waterLevel == 14400     // one of those magical skipped ticks. Do nothing.
                )
            {
                return;
            }

            // Keep coal topped up
            if (coalLevel <= coalTarget)
            {
                __instance.AddCoalChunk();
            }

            // Make sure the boiler has water in it
            if (Math.Abs(waterLevel - waterTarget) > waterDiff)
            {
                float newValue = (waterLevel < waterTarget) ? 1.0f : 0.0f;

                __instance.injector.SetValue(newValue);
            }
        }