Exemple #1
0
        protected virtual void Cooling()
        {
            if (!HasEnoughCoolant() || primary.Temperature <= LowTemperature)
            {
                return;
            }

            PrimaryElement compo;
            float          forchange = GameUtil.CalculateEnergyDeltaForElementChange(primary.Element.specificHeatCapacity, primary.Mass, primary.Temperature, primary.Temperature - CoolingPerSecond);

            List <GameObject> plist = new List <GameObject>();

            storage.Find(CoolantTag, plist);

            float fmass, total = 0;

            for (int a = 0, max = plist.Count; a < max; a++)
            {
                compo  = plist[a].GetComponent <PrimaryElement>();
                total += compo.Mass * compo.Element.specificHeatCapacity;
            }

            compo = plist[0].GetComponent <PrimaryElement>();
            fmass = compo.Mass * compo.Element.specificHeatCapacity / total;

            compo.Temperature   += GameUtil.CalculateTemperatureChange(compo.Element.specificHeatCapacity, compo.Mass, -forchange * fmass * ThermalFudge);;
            primary.Temperature -= CoolingPerSecond;

            storage.Transfer(plist[0], OutStorage, false, true);
        }
Exemple #2
0
        private void OnConvertMass(float mass)
        {
            if (mass <= 0)
            {
                return;
            }

            Log.Spam($"Converted {mass} kg");

            GetCoolantMassAndHeatCapacity(out float totalCoolantMass, out float totalCoolantHeatCapacity);

            float radiationPerKg  = mass * producedRadiationPerKg / totalCoolantMass;
            float heatPerCapacity = mass * producedHeatPerKg / totalCoolantHeatCapacity;

            int radiation = (int)(mass * producedRadiationPerKg);

            foreach (var go in coolantStorage.items)
            {
                var coolant = go.GetComponent <PrimaryElement>();
                if (coolant == null || coolant.Mass == 0 || IsFuelOrExhaust(coolant))
                {
                    continue;
                }

                int radiationPart = (int)(coolant.Mass * radiationPerKg);
                radiation -= radiationPart;
                coolant.AddDisease(RadiationIndex, radiationPart, "FusionReactor");

                float heat = coolant.Mass * coolant.Element.specificHeatCapacity * heatPerCapacity;
                float temperatureChange = GameUtil.CalculateTemperatureChange(coolant.Element.specificHeatCapacity, coolant.Mass, heat);
                coolant.Temperature += temperatureChange;

                Game.Instance.accumulators.Accumulate(heatAccumulator, heat);
                Game.Instance.accumulators.Accumulate(radiationAccumulator, radiationPart);

                Log.Spam($"Added {heat} kDTU ({temperatureChange} K) and {radiationPart} radiation to {coolant.ElementID}");
            }

            if (radiation > 0)
            {
                var coolant = coolantStorage.FindFirstWithMass(GameTags.Any);
                if (coolant != null)
                {
                    Game.Instance.accumulators.Accumulate(radiationAccumulator, radiation);
                    coolant.AddDisease(RadiationIndex, radiation, "FusionReactor");
                    Log.Spam($"Added {radiation} radiation to {coolant.ElementID}");
                }
            }

            foreach (var go in fusionStorage.items)
            {
                var fuel = go.GetComponent <PrimaryElement>();
                if (fuel == null || fuel.Mass == 0 || !IsFuel(fuel))
                {
                    continue;
                }

                fuel.Temperature = 9999;
            }
        }
        private void FireAt(Comet comet, float dt)
        {
            float electricity_used = laser_electricity_consumption * dt;

            if (electricity_available < electricity_used)
            {
                return;
            }
            electricity_available -= electricity_used;

            var primary_element = comet.gameObject.GetComponent <PrimaryElement>();
            var heat_energy     = laser_heat_production * dt;

            if (primary_element.Mass > 100)
            {
                // HACK: Rock comets are hundreds of times more massive than iron comets. Even with the electricity to heat multiplier we couldn't affect them. Apply heat based on mass (Rock Comets are between 4000kg and 7200kg)
                heat_energy *= primary_element.Mass / 10;
            }
            // Use half the heat to ablate the meteor and the rest to warm it.
            var burn_heat_energy = 0.5f * heat_energy;
            var warm_heat_energy = heat_energy - burn_heat_energy;

            primary_element.Temperature += GameUtil.CalculateTemperatureChange(primary_element.Element.specificHeatCapacity, primary_element.Mass, warm_heat_energy / 1000 /*KJ*/);
            var mass_removed = burn_heat_energy / (1000 * primary_element.Element.specificHeatCapacity * (primary_element.Element.highTemp - primary_element.Temperature));

            if (primary_element.Temperature > primary_element.Element.highTemp || primary_element.Mass <= mass_removed)
            {
                ShowExplosion(comet);
                // Drop Resources! :D - If there is a better way to do this, I'm not surprised but I sure couldn't find it (outseeker)
                PrimaryElement component = comet.GetComponent <PrimaryElement>();
                component.Mass        = primary_element.Mass;
                component.Temperature = primary_element.Temperature;
                Element    element   = component.Element;
                Substance  substance = element.substance;
                GameObject go        = substance.SpawnResource(comet.transform.GetPosition(), component.Mass, component.Temperature, byte.MaxValue, 0);
                //Debug.Log("Spawned resource from destroyed comet");
                Util.KDestroyGameObject(comet.gameObject);
                kills += 1;
            }
            else
            {
                primary_element.SetMassTemperature(primary_element.Mass - mass_removed, primary_element.Temperature);
                ShowDamageFx(comet.transform.position);
            }

            float sqrMagnitude = (Vec3To2D(comet.transform.position) - Vec3To2D(transform.position)).sqrMagnitude;

            arm_anim_ctrl.GetBatchInstanceData().SetClipRadius(transform.position.x, transform.position.y, sqrMagnitude, do_clip: true);
            foreach (var beam_seg in beam_segs)
            {
                beam_seg.GetComponent <KBatchedAnimController>().GetBatchInstanceData().SetClipRadius(arm_anim_ctrl.transform.position.x, arm_anim_ctrl.transform.position.y, sqrMagnitude, do_clip: true);
            }
        }
        private void FireAt(Comet comet, float dt)
        {
            float electricity_used = this.laser_electricity_consumption * dt;

            if (this.electricity_available < electricity_used)
            {
                return;
            }

            this.electricity_available -= electricity_used;

            var primary_element = comet.gameObject.GetComponent <PrimaryElement>();
            var heat_energy     = this.laser_heat_production * dt;

            if (primary_element.Mass > 100)
            {
                // HACK: Rock comets are hundreds of times more massive than iron comets. Even with the electricity to heat multiplier we couldn't affect them. Boost heat production by 100x.
                heat_energy *= 100;
            }

            // Use half the heat to ablate the meteor and the rest to warm it.
            var burn_heat_energy = 0.5f * heat_energy;
            var warm_heat_energy = heat_energy - burn_heat_energy;

            primary_element.Temperature += GameUtil.CalculateTemperatureChange(primary_element.Element.specificHeatCapacity, primary_element.Mass, warm_heat_energy / 1000 /*KJ*/);
            var mass_removed = burn_heat_energy / (1000 * primary_element.Element.specificHeatCapacity * (primary_element.Element.highTemp - primary_element.Temperature));

            if (primary_element.Temperature > primary_element.Element.highTemp || primary_element.Mass <= mass_removed)
            {
                this.ShowExplosion(comet);
                Util.KDestroyGameObject(comet.gameObject);
                this.kills += 1;
            }
            else
            {
                primary_element.SetMassTemperature(primary_element.Mass - mass_removed, primary_element.Temperature);
                this.ShowDamageFx(comet.transform.position);
            }

            float sqrMagnitude = (Vec3To2D(comet.transform.position) - Vec3To2D(this.transform.position)).sqrMagnitude;

            this.arm_anim_ctrl.GetBatchInstanceData().SetClipRadius(this.transform.position.x, this.transform.position.y, sqrMagnitude, do_clip: true);
            foreach (var beam_seg in this.beam_segs)
            {
                beam_seg.GetComponent <KBatchedAnimController>().GetBatchInstanceData().SetClipRadius(this.arm_anim_ctrl.transform.position.x, this.arm_anim_ctrl.transform.position.y, sqrMagnitude, do_clip: true);
            }
        }
    public override List <Descriptor> AdditionalEffectsForRecipe(ComplexRecipe recipe)
    {
        List <Descriptor> list           = base.AdditionalEffectsForRecipe(recipe);
        GameObject        prefab         = Assets.GetPrefab(recipe.results[0].material);
        PrimaryElement    component      = prefab.GetComponent <PrimaryElement>();
        PrimaryElement    primaryElement = inStorage.FindFirstWithMass(coolantTag);
        string            format         = UI.BUILDINGEFFECTS.TOOLTIPS.REFINEMENT_ENERGY_HAS_COOLANT;

        if ((Object)primaryElement == (Object)null)
        {
            GameObject prefab2 = Assets.GetPrefab(GameTags.Water);
            primaryElement = prefab2.GetComponent <PrimaryElement>();
            format         = UI.BUILDINGEFFECTS.TOOLTIPS.REFINEMENT_ENERGY_NO_COOLANT;
        }
        float num  = 0f - GameUtil.CalculateEnergyDeltaForElementChange(component.Element.specificHeatCapacity, recipe.results[0].amount, component.Element.highTemp, outputTemperature);
        float temp = GameUtil.CalculateTemperatureChange(primaryElement.Element.specificHeatCapacity, minCoolantMass, num * thermalFudge);

        list.Add(new Descriptor(string.Format(UI.BUILDINGEFFECTS.REFINEMENT_ENERGY, GameUtil.GetFormattedJoules(num, "F1", GameUtil.TimeSlice.None)), string.Format(format, GameUtil.GetFormattedJoules(num, "F1", GameUtil.TimeSlice.None), primaryElement.GetProperName(), GameUtil.GetFormattedTemperature(temp, GameUtil.TimeSlice.None, GameUtil.TemperatureInterpretation.Relative, true, false)), Descriptor.DescriptorType.Effect, false));
        return(list);
    }
    protected override List <GameObject> SpawnOrderProduct(ComplexRecipe recipe)
    {
        List <GameObject> list      = base.SpawnOrderProduct(recipe);
        PrimaryElement    component = list[0].GetComponent <PrimaryElement>();

        component.Temperature = outputTemperature;
        float num = GameUtil.CalculateEnergyDeltaForElementChange(component.Element.specificHeatCapacity, component.Mass, component.Element.highTemp, outputTemperature);

        ListPool <GameObject, LiquidCooledRefinery> .PooledList pooledList = ListPool <GameObject, LiquidCooledRefinery> .Allocate();

        buildStorage.Find(coolantTag, pooledList);
        float num2 = 0f;

        foreach (GameObject item in pooledList)
        {
            PrimaryElement component2 = item.GetComponent <PrimaryElement>();
            if (component2.Mass != 0f)
            {
                num2 += component2.Mass * component2.Element.specificHeatCapacity;
            }
        }
        foreach (GameObject item2 in pooledList)
        {
            PrimaryElement component3 = item2.GetComponent <PrimaryElement>();
            if (component3.Mass != 0f)
            {
                float num3        = component3.Mass * component3.Element.specificHeatCapacity / num2;
                float kilowatts   = (0f - num) * num3 * thermalFudge;
                float num4        = GameUtil.CalculateTemperatureChange(component3.Element.specificHeatCapacity, component3.Mass, kilowatts);
                float temperature = component3.Temperature;
                component3.Temperature += num4;
            }
        }
        buildStorage.Transfer(outStorage, coolantTag, 3.40282347E+38f, false, true);
        pooledList.Recycle();
        return(list);
    }
Exemple #7
0
        private float GetCoolingEnergy(float delta, bool doPull = false)
        {
            if (!operational.IsOperational || !operational.IsActive)
            {
                return(0);
            }

            float energyPulled      = 0;
            var   energyToPullPerKG = GetEnergyPerHotMass();

            if (energyToPullPerKG > 0)
            {
                energyToPullPerKG = Mathf.Min(energyToPullPerKG, GetAvailableCoolingEnergy() * energyMaxMultiplier);
                if (energyToPullPerKG > 0)
                {
                    foreach (var item in GetHotStorageItems())
                    {
                        var element = item.GetComponent <PrimaryElement>();

                        float energyToPullPerItem = energyToPullPerKG * element.Mass;
                        float deltaTemp           = Mathf.Min(energyToPullPerItem, Mathf.Max(0, GameUtil.CalculateEnergyDeltaForElement(element, temperatureCurrent - 1, element.Temperature)));

                        energyPulled += deltaTemp;
                        if (doPull)
                        {
                            element.Temperature += GameUtil.CalculateTemperatureChange(
                                element.Element.specificHeatCapacity,
                                element.Mass,
                                -(deltaTemp * thermalEfficiency)
                                );
                        }
                    }
                }
            }
            return(energyPulled);
        }
Exemple #8
0
 public static float CalculateTemperatureDelta(this LiquidCooledRefinery @this, PrimaryElement primaryElement, float energyDelta)
 {
     return(GameUtil.CalculateTemperatureChange(primaryElement.Element.specificHeatCapacity, @this.minCoolantMass, -energyDelta));
 }