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) { log.error ("Unknown RESOURCE [{0}]", 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; }
public static void ShowGUI(ModuleFuelTanks tank_module) { if (instance != null) { instance.tank_module = tank_module; instance.UpdateGUIState(); } }
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; } }
void Awake() { GameEvents.onGUIEditorToolbarReady.Add(onGUIEditorToolbarReady); if (mftItems == null) { mftItems = new HashSet <string> (); } mftItems.Clear(); foreach (AvailablePart ap in PartLoader.LoadedPartsList) { Part part = ap.partPrefab; Tanks.ModuleFuelTanks mft = part.FindModuleImplementing <Tanks.ModuleFuelTanks> (); if (mft != null) { mftItems.Add(ap.name); } } }
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; log.warn("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; }
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); }
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); Game 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); } } } } } }