Ejemplo n.º 1
0
        public override void OnFixedUpdate()
        {
            var resources = Misc.GetConnectedResources(part, "ElectricCharge");
            var demand    = Enabled ? logistic((float)(resources.Sum(r => r.amount) / resources.Sum(r => r.maxAmount))) : 0;

            if (demand < 0.1f)
            {
                demand = 0;
            }

            var pressure = (float)FlightGlobals.getStaticPressure(part.transform.position);

            fanSpeed.Update(TimeWarp.fixedDeltaTime, demand * (2 * pressure) / (pressure * pressure + 1));

            var pressureEfficiencyFactor = 0.5f;
            var kethaneDemand            = demand * KethaneRate * TimeWarp.fixedDeltaTime / (1 + fanSpeed.Average * pressure * pressureEfficiencyFactor);

            var kethaneDrawn = (float)part.RequestResource("Kethane", kethaneDemand);

            output.Update(TimeWarp.fixedDeltaTime, kethaneDemand > 0 ? demand * kethaneDrawn / kethaneDemand : 0);

            part.RequestResource("XenonGas", -kethaneDrawn * XenonMassRatio * PartResourceLibrary.Instance.GetDefinition("Kethane").density / PartResourceLibrary.Instance.GetDefinition("XenonGas").density);

            Output = output.Average;
            part.RequestResource("ElectricCharge", -Output * PowerRate * TimeWarp.fixedDeltaTime);
        }
Ejemplo n.º 2
0
        public override void OnFixedUpdate()
        {
            if (!IsEnabled)
            {
                return;
            }

            var conversionRatio = PartResourceLibrary.Instance.GetDefinition("Kethane").density / PartResourceLibrary.Instance.GetDefinition(TargetResource).density;

            double requestedSpace   = KethaneConsumption * conversionRatio * ConversionEfficiency * TimeWarp.fixedDeltaTime;
            double requestedKethane = KethaneConsumption * TimeWarp.fixedDeltaTime;
            double requestedEnergy  = PowerConsumption * TimeWarp.fixedDeltaTime;

            var availableSpace   = Misc.GetConnectedResources(this.part, TargetResource).Max(r => r.maxAmount - r.amount);
            var availableKethane = Misc.GetConnectedResources(this.part, "Kethane").Max(r => r.amount);
            var availableEnergy  = Misc.GetConnectedResources(this.part, "ElectricCharge").Max(r => r.amount);

            var spaceRatio   = availableSpace / requestedSpace;
            var kethaneRatio = availableKethane / requestedKethane;
            var energyRatio  = availableEnergy / requestedEnergy;

            var ratio = Math.Min(Math.Min(Math.Min(spaceRatio, kethaneRatio), energyRatio), 1);

            var heatsink = this.part.Modules.OfType <HeatSinkAnimator>().SingleOrDefault();

            if (heatsink != null)
            {
                var heatRequest = (float)ratio * HeatProduction * TimeWarp.fixedDeltaTime;
                ratio *= heatsink.AddHeat(heatRequest) / heatRequest;
            }

            requestedKethane *= ratio;

            var drawnKethane = this.part.RequestResource("Kethane", requestedKethane);

            ratio           *= drawnKethane / requestedKethane;
            requestedEnergy *= ratio;

            var drawnEnergy = this.part.RequestResource("ElectricCharge", requestedEnergy);

            ratio          *= drawnEnergy / requestedEnergy;
            requestedSpace *= ratio;

            this.part.RequestResource(TargetResource, -requestedSpace);
        }
Ejemplo n.º 3
0
        public override void OnFixedUpdate()
        {
            if (!IsEnabled)
            {
                return;
            }

            var rates = outputRates.Select(r => r * -1).Concat(inputRates).Select(r => r * TimeWarp.fixedDeltaTime).ToArray();
            var ratio = rates.Select(r => Misc.GetConnectedResources(this.part, r.Resource).Select(c => r.Rate > 0 ? c.amount : c.maxAmount - c.amount).DefaultIfEmpty().Max() / Math.Abs(r.Rate)).Prepend(1).Min();

            var heatsink = this.part.Modules.OfType <HeatSinkAnimator>().SingleOrDefault();

            if (heatsink != null)
            {
                var heatRequest = (float)ratio * HeatProduction * TimeWarp.fixedDeltaTime;
                ratio *= heatsink.AddHeat(heatRequest) / heatRequest;
            }

            foreach (var rate in rates)
            {
                this.part.RequestResource(rate.Resource, rate.Rate * ratio);
            }
        }