Inheritance: IAnalyticTemperatureModifier, IAnalyticPreview
Esempio n. 1
0
 public static void HideGUIForModule(ModuleFuelTanks tank_module)
 {
     if (instance != null && instance.tank_module == tank_module)
     {
         HideGUI();
     }
 }
        public void ChangeTotalVolume(double newTotalVolume, bool propagate = false)
        {
            double newVolume   = Math.Round(newTotalVolume * utilization * 0.01d, 4);
            double volumeRatio = newVolume / volume;

            bool doResources = false;

            if (volume > newVolume)
            {
                ChangeResources(volumeRatio, propagate);
            }
            else
            {
                doResources = true;
            }
            totalVolume = newTotalVolume;
            volume      = newVolume;
            if (propagate)
            {
                foreach (Part p in part.symmetryCounterparts)
                {
                    // FIXME: Not safe, assumes only 1 MFT on the part.
                    ModuleFuelTanks m = (ModuleFuelTanks)p.Modules["ModuleFuelTanks"];
                    m.totalVolume = newTotalVolume;
                    m.volume      = newVolume;
                }
            }
            if (doResources)
            {
                ChangeResources(volumeRatio, propagate);
            }
            massDirty = true;
        }
 public static void ShowGUI(ModuleFuelTanks tank_module)
 {
     if (instance != null) {
         instance.tank_module = tank_module;
         instance.UpdateGUIState ();
     }
 }
Esempio n. 4
0
        public FuelInfo(List<Propellant> props, ModuleFuelTanks tank, string title)
        {
            // tank math:
            // efficiency = sum[utilization * ratio]
            // then final volume per fuel = fuel_ratio / fuel_utilization / efficiency

            ratioFactor = 0.0;
            efficiency = 0.0;
            propellants = props;

            foreach (Propellant tfuel in propellants) {
                if (PartResourceLibrary.Instance.GetDefinition (tfuel.name) == null) {
                    Debug.LogError ("Unknown RESOURCE {" + tfuel.name + "}");
                    ratioFactor = 0.0;
                    break;
                }
                if (PartResourceLibrary.Instance.GetDefinition (tfuel.name).resourceTransferMode != ResourceTransferMode.NONE) {
                    FuelTank t;
                    if (tank.tankList.TryGet (tfuel.name, out t)) {
                        efficiency += tfuel.ratio/t.utilization;
                        ratioFactor += tfuel.ratio;
                    } else if (!IgnoreFuel (tfuel.name)) {
                        ratioFactor = 0.0;
                        break;
                    }
                }
            }
            names = "Used by: " + title;
        }
Esempio n. 5
0
        public FuelInfo(List <Propellant> props, ModuleFuelTanks tank, string title)
        {
            // tank math:
            // efficiency = sum[utilization * ratio]
            // then final volume per fuel = fuel_ratio / fuel_utilization / efficiency

            ratioFactor = 0.0;
            efficiency  = 0.0;
            propellants = props;

            foreach (Propellant tfuel in propellants)
            {
                if (PartResourceLibrary.Instance.GetDefinition(tfuel.name) == null)
                {
                    Debug.LogError("Unknown RESOURCE {" + tfuel.name + "}");
                    ratioFactor = 0.0;
                    break;
                }
                if (PartResourceLibrary.Instance.GetDefinition(tfuel.name).resourceTransferMode != ResourceTransferMode.NONE)
                {
                    FuelTank t;
                    if (tank.tankList.TryGet(tfuel.name, out t))
                    {
                        efficiency  += tfuel.ratio / t.utilization;
                        ratioFactor += tfuel.ratio;
                    }
                    else if (!IgnoreFuel(tfuel.name))
                    {
                        ratioFactor = 0.0;
                        break;
                    }
                }
            }
            names = "Used by: " + title;
        }
Esempio n. 6
0
 public static void ShowGUI(ModuleFuelTanks tank_module)
 {
     if (instance != null)
     {
         instance.tank_module = tank_module;
         instance.UpdateGUIState();
     }
 }
Esempio n. 7
0
        private void FillAttachedTanks(double deltaTime)
        {
            // sanity check
            if (deltaTime <= 0)
            {
                return;
            }

            // now, let's look at what we're connected to.
            foreach (Part p in vessel.Parts) // look through all parts
            {
                if (p.Modules.Contains("ModuleFuelTanks"))
                {
                    Tanks.ModuleFuelTanks m = (Tanks.ModuleFuelTanks)p.Modules["ModuleFuelTanks"];
                    // look through all tanks inside this part
                    foreach (Tanks.FuelTank tank in m.tankList)
                    {
                        // if a tank isn't full, start filling it.
                        PartResource r = tank.resource;
                        if (r == null)
                        {
                            continue;
                        }
                        PartResourceDefinition d = PartResourceLibrary.Instance.GetDefinition(r.resourceName);
                        if (d == null)
                        {
                            continue;
                        }
                        if (tank.amount < tank.maxAmount && tank.fillable && r.flowMode != PartResource.FlowMode.None && d.resourceTransferMode == ResourceTransferMode.PUMP)
                        {
                            double amount = deltaTime * pump_rate;
                            var    game   = HighLogic.CurrentGame;

                            if (d.unitCost > 0 && game.Mode == Game.Modes.CAREER && Funding.Instance != null)
                            {
                                double funds = Funding.Instance.Funds;
                                double cost  = amount * d.unitCost;
                                if (cost > funds)
                                {
                                    amount = funds / d.unitCost;
                                    cost   = funds;
                                }
                                Funding.Instance.AddFunds(-cost, TransactionReasons.VesselRollout);
                            }
                            tank.amount = tank.amount + amount;
                        }
                    }
                }
            }
        }
Esempio n. 8
0
 void EnsureFreshAddLabelCache()
 {
     if (tank_module.AvailableVolume != oldAvailableVolume || tank_module.type != oldTankType)
     {
         foreach (FuelTank tank in tank_module.tankList)
         {
             double maxVol    = tank_module.AvailableVolume * tank.utilization;
             string maxVolStr = KSPUtil.PrintSI(maxVol, "L");
             string label     = "Max: " + maxVolStr + " (+" + ModuleFuelTanks.FormatMass((float)(tank_module.AvailableVolume * tank.mass)) + " )";
             addLabelCache[tank.name] = label;
         }
         oldAvailableVolume = tank_module.AvailableVolume;
         oldTankType        = tank_module.type;
     }
 }
Esempio n. 9
0
        void AddTank(FuelTank tank)
        {
            double maxVol    = tank_module.AvailableVolume * tank.utilization;
            string maxVolStr = KSPUtil.PrintSI(maxVol, "L");
            string extraData = "Max: " + maxVolStr + " (+" + ModuleFuelTanks.FormatMass((float)(tank_module.AvailableVolume * tank.mass)) + " )";

            GUILayout.Label(extraData, GUILayout.Width(150));

            if (GUILayout.Button("Add", GUILayout.Width(120)))
            {
                tank.maxAmount = tank_module.AvailableVolume * tank.utilization;
                tank.amount    = tank.fillable ? tank.maxAmount : 0;

                tank.maxAmountExpression = tank.maxAmount.ToString();
                //Debug.LogWarning ("[MFT] Adding tank " + tank.name + " maxAmount: " + tank.maxAmountExpression ?? "null");
            }
        }
Esempio n. 10
0
        internal FuelTank CreateCopy(ModuleFuelTanks toModule, ConfigNode overNode, bool initializeAmounts)
        {
            FuelTank clone = (FuelTank)MemberwiseClone();

            clone.module = toModule;

            if (overNode != null)
            {
                clone.Load(overNode);
            }
            if (initializeAmounts)
            {
                clone.InitializeAmounts();
            }
            else
            {
                clone.amountExpression = clone.maxAmountExpression = null;
            }
            return(clone);
        }
Esempio n. 11
0
        public void ChangeTotalVolume(double newTotalVolume, bool propagate = false)
        {
            double newVolume = Math.Round(newTotalVolume * utilization * 0.01d, 4);

            if (Double.IsInfinity(newVolume / volume))
            {
                totalVolume = newTotalVolume;
                volume      = newVolume;
                Debug.LogWarning("[ModularFuelTanks] caught DIV/0 in ChangeTotalVolume. Setting volume/totalVolume and exiting function");
                return;
            }
            double volumeRatio = newVolume / volume;

            bool doResources = false;

            if (volume > newVolume)
            {
                ChangeResources(volumeRatio, propagate);
            }
            else
            {
                doResources = true;
            }
            totalVolume = newTotalVolume;
            volume      = newVolume;
            if (propagate)
            {
                foreach (Part p in part.symmetryCounterparts)
                {
                    // FIXME: Not safe, assumes only 1 MFT on the part.
                    ModuleFuelTanks m = (ModuleFuelTanks)p.Modules["ModuleFuelTanks"];
                    m.totalVolume = newTotalVolume;
                    m.volume      = newVolume;
                }
            }
            if (doResources)
            {
                ChangeResources(volumeRatio, propagate);
            }
            massDirty = true;
        }
Esempio n. 12
0
        private void FillAttachedTanks(double deltaTime)
        {
            // sanity check
            if (deltaTime <= 0)
            {
                return;
            }

            // now, let's look at what we're connected to.
            for (int i = vessel.parts.Count - 1; i >= 0; --i)  // look through all parts
            {
                Part p = vessel.parts[i];
                if (p.Modules.Contains("ModuleFuelTanks"))
                {
                    Tanks.ModuleFuelTanks m = (Tanks.ModuleFuelTanks)p.Modules["ModuleFuelTanks"];
                    double minTemp          = p.temperature;
                    // look through all tanks inside this part
                    for (int j = m.tankList.Count - 1; j >= 0; --j)
                    {
                        Tanks.FuelTank tank = m.tankList[j];
                        // if a tank isn't full, start filling it.
                        PartResource r = tank.resource;
                        if (r == null)
                        {
                            continue;
                        }
                        PartResourceDefinition d = PartResourceLibrary.Instance.GetDefinition(r.resourceName);
                        if (d == null)
                        {
                            continue;
                        }
                        if (tank.maxAmount > 0d)
                        {
                            if (tank.loss_rate > 0d)
                            {
                                minTemp = Math.Min(p.temperature, tank.temperature);
                            }
                            if (tank.amount < tank.maxAmount && tank.fillable && r.flowMode != PartResource.FlowMode.None && d.resourceTransferMode == ResourceTransferMode.PUMP && r.flowState)
                            {
                                double amount = Math.Min(deltaTime * pump_rate * tank.utilization, tank.maxAmount - tank.amount);
                                var    game   = HighLogic.CurrentGame;

                                if (d.unitCost > 0 && game.Mode == Game.Modes.CAREER && Funding.Instance != null)
                                {
                                    double funds = Funding.Instance.Funds;
                                    double cost  = amount * d.unitCost;
                                    if (cost > funds)
                                    {
                                        amount = funds / d.unitCost;
                                        cost   = funds;
                                    }
                                    Funding.Instance.AddFunds(-cost, TransactionReasons.VesselRollout);
                                }
                                //tank.amount = tank.amount + amount;
                                p.TransferResource(r, amount, this.part);
                            }
                        }
                    }
                    p.temperature = minTemp;
                }
                else
                {
                    for (int j = p.Resources.Count - 1; j >= 0; --j)
                    {
                        PartResource r = p.Resources[j];
                        if (r.info.name == "ElectricCharge")
                        {
                            if (r.flowMode != PartResource.FlowMode.None && r.info.resourceTransferMode == ResourceTransferMode.PUMP && r.flowState)
                            {
                                double amount = deltaTime * pump_rate;
                                amount = Math.Min(amount, r.maxAmount - r.amount);
                                p.TransferResource(r, amount, this.part);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 13
0
        private void FillAttachedTanks(double deltaTime)
        {
            // sanity check
            if (deltaTime <= 0)
            {
                return;
            }

            // now, let's look at what we're connected to.
            foreach (Part p in vessel.parts)  // look through all parts
            {
                Tanks.ModuleFuelTanks m = p.FindModuleImplementing <Tanks.ModuleFuelTanks>();
                if (m != null)
                {
                    m.fueledByLaunchClamp = true;
                    // look through all tanks inside this part
                    for (int j = m.tankList.Count - 1; j >= 0; --j)
                    {
                        Tanks.FuelTank tank = m.tankList[j];
                        // if a tank isn't full, start filling it.

                        if (tank.maxAmount <= 0)
                        {
                            continue;
                        }

                        PartResource r = tank.resource;
                        if (r == null)
                        {
                            continue;
                        }

                        PartResourceDefinition d = PartResourceLibrary.Instance.GetDefinition(r.resourceName);
                        if (d == null)
                        {
                            continue;
                        }

                        if (tank.amount < tank.maxAmount && tank.fillable && r.flowMode != PartResource.FlowMode.None && d.resourceTransferMode == ResourceTransferMode.PUMP && r.flowState)
                        {
                            double amount = Math.Min(deltaTime * pump_rate * tank.utilization, tank.maxAmount - tank.amount);
                            var    game   = HighLogic.CurrentGame;

                            if (d.unitCost > 0 && game.Mode == Game.Modes.CAREER && Funding.Instance != null)
                            {
                                double funds = Funding.Instance.Funds;
                                double cost  = amount * d.unitCost;
                                if (cost > funds)
                                {
                                    amount = funds / d.unitCost;
                                    cost   = funds;
                                }
                                Funding.Instance.AddFunds(-cost, TransactionReasons.VesselRollout);
                            }
                            //tank.amount = tank.amount + amount;
                            p.TransferResource(r, amount, this.part);
                        }
                    }
                }
                else
                {
                    for (int j = p.Resources.Count - 1; j >= 0; --j)
                    {
                        PartResource partResource = p.Resources[j];
                        if (partResource.info.name == "ElectricCharge")
                        {
                            if (partResource.flowMode != PartResource.FlowMode.None && partResource.info.resourceTransferMode == ResourceTransferMode.PUMP && partResource.flowState)
                            {
                                double amount = deltaTime * pump_rate;
                                amount = Math.Min(amount, partResource.maxAmount - partResource.amount);
                                p.TransferResource(partResource, amount, this.part);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 14
0
        internal FuelTank CreateCopy(ModuleFuelTanks toModule, ConfigNode overNode, bool initializeAmounts)
        {
            FuelTank clone = (FuelTank)MemberwiseClone ();
            clone.module = toModule;

            if (overNode != null) {
                clone.Load (overNode);
            }
            if (initializeAmounts) {
                clone.InitializeAmounts ();
            } else {
                clone.amountExpression = clone.maxAmountExpression = null;
            }
            clone.GetDensity();
            return clone;
        }