コード例 #1
0
        public static void PatchSmelter(Smelter smelter)
        {
            if (smelter.m_emptyOreSwitch && smelter.m_spawnStack)
            {
                int processedQueueSize = smelter.GetProcessedQueueSize();
                smelter.m_emptyOreSwitch.m_hoverText = $"{smelter.m_name} {processedQueueSize} $piece_smelter_ready \n{useKey} {smelter.m_emptyOreTooltip}";
            }
            int queueSize = smelter.GetQueueSize();

            smelter.m_addOreSwitch.m_hoverText = $"{smelter.m_name} ({queueSize}/{smelter.m_maxOre}) ";

            if (queueSize > 0) // This codeline is run every tick when windmill is on!!
            {
                Debug.Log($"{smelter.GetBakeTimer()}, {smelter.m_secPerProduct}, {queueSize}");

                smelter.m_addOreSwitch.m_hoverText += $"{Helpers.TimeString(smelter.m_secPerProduct * queueSize - smelter.GetBakeTimer())}";
                // 8sec - 10sec (30sec)
                // 9sec - 10sec (30sec)
            }

            if (smelter.m_requiresRoof && !smelter.m_haveRoof && Mathf.Sin(Time.time * 10f) > 0f)
            {
                Switch addOreSwitch = smelter.m_addOreSwitch;
                addOreSwitch.m_hoverText += $" {smelterRoof}";
            }
            Switch addOreSwitch2 = smelter.m_addOreSwitch;

            addOreSwitch2.m_hoverText = $"{addOreSwitch2.m_hoverText} \n{useKey} {smelter.m_addOreTooltip}";
        }
コード例 #2
0
        private static void CalculateSmelterBakeTime(Smelter smelter)
        {
            double deltaTime   = smelter.GetDeltaTime();
            float  accumulator = smelter.GetAccumulator();

            accumulator += (float)deltaTime;
            float power = smelter.m_windmill ? smelter.m_windmill.GetPowerOutput() : 1f;

            while (accumulator >= 1f)
            {
                accumulator -= 1f;
                float  fuel      = smelter.GetFuel();
                string queuedOre = smelter.GetQueuedOre();
                if ((smelter.m_maxFuel == 0 || fuel > 0f) && queuedOre != "" && smelter.m_secPerProduct > 0f && (!smelter.m_requiresRoof || smelter.m_haveRoof))
                {
                    float speed = 1f * power;
                    if (smelter.m_maxFuel > 0)
                    {
                        float usage = smelter.m_secPerProduct / (float)smelter.m_fuelPerProduct;
                        fuel -= speed / usage;
                        if (fuel < 0f)
                        {
                            fuel = 0f;
                        }
                        smelter.SetFuel(fuel);
                    }
                    float bakeTime = smelter.GetBakeTimer();
                    bakeTime += speed;
                    smelter.SetBakeTimer(bakeTime);
                    if (bakeTime > smelter.m_secPerProduct)
                    {
                        smelter.SetBakeTimer(0f);
                        smelter.RemoveOneOre();
                        smelter.QueueProcessed(queuedOre);
                    }
                }
            }

            if (smelter.GetQueuedOre() == "" || ((float)smelter.m_maxFuel > 0f && smelter.GetFuel() == 0f))
            {
                smelter.SpawnProcessed();
            }

            smelter.SetAccumulator(accumulator);
        }