Пример #1
0
        public override void Load()
        {
            Logger.DebugFormat("Loading Factories and System Loaders...");

            LiquidLoader      = new ModLiquidLoader();
            LiquidFactory     = new ModLiquidFactory();
            machineLoader     = new MachineUILoader();
            temperatureSystem = new TemperatureSystem();

            Logger.DebugFormat("Initializing dictionaries...");

            DebugHotkey = RegisterHotKey("Debugging", "J");

            TileUtils.tileToEntity        = new Dictionary <int, MachineEntity>();
            TileUtils.tileToStructureName = new Dictionary <int, string>();

            ElectrolyzerEntity.liquidToGas = new Dictionary <MachineLiquidID, (MachineGasID, MachineGasID)>()
            {
Пример #2
0
        public override bool UpdateReaction()
        {
            /*    dT/dt = k(M - T), k > 0
             *
             *    where dT = change in Heat
             *          dt = change in time
             *          k = heat_K (M > T) or cool_K (M < T)
             *          M = targetHeat
             *          T = Heat
             */
            MachineUILoader loader = TechMod.Instance.machineLoader;
            float           dt     = (float)loader.lastUpdateUIGameTime.ElapsedGameTime.TotalSeconds;

            if (!Heating && Heat - targetHeat < epsilon)
            {
                //Stop the furnace if we've cooled down to room temperature
                Heat             = targetHeat;
                ReactionSpeed    = 1f;
                ReactionProgress = 0f;
                return(false);
            }

            ReactionSpeed *= Heating ? 1f + 0.06f / 60f : 1f - 0.235f / 60f;
            ReactionSpeed  = Utils.Clamp(ReactionSpeed, 1f, 3f);

            if (Heating && AtMaxHeat)
            {
                //If we're at max heat, then make ReactionProgress increase linearly
                ReactionProgress += ReactionSpeed * BaseReactionIncrease * dt;
                Heat              = HeatMax;
            }
            else
            {
                //Actual physics
                float k  = targetHeat >= Heat ? heat_K : cool_K;
                float dT = k * (targetHeat - Heat) * dt;

                if (Heating)
                {
                    ReactionProgress += ReactionSpeed * BaseReactionIncrease * Heat / HeatMax * dt;
                }

                float cool_factor = 9.25f;
                float heat_factor = 6.35f;
                if (!Heating && dT / dt > -cool_factor)
                {
                    //Linear decrease to make it not super slow
                    Heat -= cool_factor * dt;
                }
                else if (Heating && dT / dt < heat_factor)
                {
                    //Linear increase to make it not super slow
                    Heat += heat_factor * dt;
                }
                else
                {
                    //Regular heat change
                    Heat += dT;
                }
            }

            return(true);
        }