public static float GetResourceCost(Part part, bool maxAmount = false) { PartResourceDefinitionList definitions = PartResourceLibrary.Instance.resourceDefinitions; PartResourceList resources = part.Resources; PartResourceDefinition resourceDef; float totalCost = 0f; foreach (PartResource resource in resources) { //Find definition resourceDef = definitions[resource.resourceName]; if (resourceDef != null) { if (!maxAmount) { totalCost += (float)(resourceDef.unitCost * resource.amount); } else { totalCost += (float)(resourceDef.unitCost * resource.maxAmount); } } } return(totalCost); }
public override void OnStart(StartState state) { PartResourceDefinitionList definitions = PartResourceLibrary.Instance.resourceDefinitions; PartResourceDefinition definition; base.OnStart(state); definition = definitions[liftGasResource]; if (definition != null) { liftGasDensity = definition.density * 1000000; //units * 1000000 = kg/m^3 } //fields shown when debugMode = true Fields["liftGasResource"].guiActive = debugMode; Fields["liftGasDensity"].guiActive = debugMode; Fields["forceOfGravity"].guiActive = debugMode; Fields["atmosphericDensity"].guiActive = debugMode; Fields["liftMultiplier"].guiActive = debugMode; List <WBIModuleStaticLift> lifters = this.part.vessel.FindPartModulesImplementing <WBIModuleStaticLift>(); lifters.Remove(this); if (lifters.Count > 0) { liftModules = lifters.ToArray(); } prevLiftMultiplier = liftMultiplier; }
bool hasResourcesToDump() { string resourceName; double amount, maxAmount; PartResourceDefinition resourceDef = null; PartResourceDefinitionList definitions = PartResourceLibrary.Instance.resourceDefinitions; for (int index = 0; index < resourcesToDump.Length; index++) { resourceName = resourcesToDump[index]; //Get resource definition if (definitions.Contains(resourceName)) { resourceDef = definitions[resourceName]; } //Check resource amount this.part.GetConnectedResourceTotals(resourceDef.id, out amount, out maxAmount); if (amount >= 0.0001f) { return(true); } } return(false); }
bool consumeInputs(ResourceRatio[] inputs, double elapsedTime) { double amountObtained = 0f; double demand; for (int index = 0; index < inputs.Length; index++) { demand = inputs[index].Ratio; if (elapsedTime >= 1.0f) { demand *= elapsedTime; } amountObtained = this.part.RequestResource(inputs[index].ResourceName, demand); if (amountObtained / demand < 0.9999f) { PartResourceDefinition resourceDef = null; PartResourceDefinitionList definitions = PartResourceLibrary.Instance.resourceDefinitions; resourceDef = definitions[inputs[index].ResourceName]; status = statusMissing + resourceDef.displayName; dischargeRate = 0f; return(false); } } return(true); }
public override void OnStart(StartState state) { base.OnStart(state); if (string.IsNullOrEmpty(resourceName)) { return; } PartResourceDefinitionList definitions = PartResourceLibrary.Instance.resourceDefinitions; if (definitions.Contains(resourceName)) { resourceDefinition = definitions[resourceName]; Events["enableResourceTweak"].guiName = resourceDefinition.displayName + " " + tweakEnabledName; Events["disableResourceTweak"].guiName = resourceDefinition.displayName + " " + tweakDisabledName; if (HighLogic.LoadedSceneIsEditor) { this.part.Resources[resourceName].isTweakable = resourceDefinition.isTweakable; updateUI(); if (isEnabled) { enableResourceTweak(); } GameEvents.onPartResourceListChange.Add(onPartResourceListChange); } } }
/// <summary> /// Initializes a new instance of the <see cref="T:Snacks.ConsumeResource"/> class. /// </summary> /// <param name="node">A ConfigNode containing initialization parameters. Parameters in the /// <see cref="T:Snacks.BaseOutcome"/> class also apply.</param> public ConsumeResource(ConfigNode node) : base(node) { if (node.HasValue(ResourceName)) { resourceName = node.GetValue(ResourceName); } PartResourceDefinitionList definitions = PartResourceLibrary.Instance.resourceDefinitions; if (definitions.Contains(resourceName)) { isRosterResource = false; } else { isRosterResource = true; } if (node.HasValue(ResourceAmount)) { double.TryParse(node.GetValue(ResourceAmount), out amount); } if (node.HasValue(ResourceRandomMin)) { float.TryParse(node.GetValue(ResourceRandomMin), out randomMax); } if (node.HasValue(ResourceRandomMax)) { float.TryParse(node.GetValue(ResourceRandomMax), out randomMin); } }
/// <summary> /// If the part with crew capacity doesn't have the resource, then add it. /// </summary> /// <param name="part"></param> public void addResourcesIfNeeded(Part part) { if (part == null) { return; } if (part.CrewCapacity <= 0) { return; } PartResourceDefinitionList definitions = PartResourceLibrary.Instance.resourceDefinitions; PartResourceDefinition def; double partCurrentAmount = 0; double partMaxAmount = 0; double unitsToAdd = 0; double maxUnitsToAdd = 0; int moduleCount; if (string.IsNullOrEmpty(resourceName)) { return; } if (!definitions.Contains(resourceName)) { return; } //Check the part to see if it has the resources already. def = definitions[resourceName]; part.GetConnectedResourceTotals(def.id, out partCurrentAmount, out partMaxAmount, true); if (partMaxAmount > 0) { return; } //Now add the resource. //Determine how many units to add. If the part has any module on the capacity list, then we use the capacity modifier. unitsToAdd = amount; maxUnitsToAdd = maxAmount; if (isPerKerbal) { unitsToAdd *= part.CrewCapacity; maxUnitsToAdd *= part.CrewCapacity; } //Next, account for capacity multiplier moduleCount = part.Modules.Count; for (int moduleIndex = 0; moduleIndex < moduleCount; moduleIndex++) { if (capacityAffectingModules.Contains(part.Modules[moduleIndex].moduleName)) { unitsToAdd *= capacityMultiplier; maxUnitsToAdd *= capacityMultiplier; break; } } //Add the resource. part.Resources.Add(def.name, unitsToAdd, maxUnitsToAdd, true, true, false, true, PartResource.FlowMode.Both); }
public static bool VesselHasResource(string resourceName, Vessel vessel) { PartResourceDefinitionList definitions = PartResourceLibrary.Instance.resourceDefinitions; List <PartResource> resources; List <Part> parts; int resourceID; //First, does the resource definition exist? if (definitions.Contains(resourceName)) { resources = new List <PartResource>(); resourceID = definitions[resourceName].id; //The definition exists, now see if the vessel has the resource parts = vessel.parts; foreach (Part part in parts) { if (part.Resources.Contains(resourceName)) { return(true); } } } return(false); }
/// <summary> /// Initializes a new instance of the <see cref="T:Snacks.CheckResource"/> class. /// </summary> /// <param name="node">A ConfigNode containing initialization parameters. parameters from the /// <see cref="T:Snacks.BasePrecondition"/> class also apply.</param> public CheckResource(ConfigNode node) : base(node) { if (node.HasValue(ValueResourceName)) { resourceName = node.GetValue(ValueResourceName); } if (node.HasValue(CheckTypeValue)) { checkType = (CheckValueConditionals)Enum.Parse(typeof(CheckValueConditionals), node.GetValue(CheckTypeValue)); } if (node.HasValue(CheckValue)) { double.TryParse(node.GetValue(CheckValue), out valueToCheck); } if (node.HasValue(CheckConditionalMaxAmount)) { bool.TryParse(node.GetValue(CheckConditionalMaxAmount), out checkMaxAmount); } //Now determine if the resource is a roster resource PartResourceDefinitionList definitions = PartResourceLibrary.Instance.resourceDefinitions; if (definitions.Contains(resourceName)) { isRosterResource = false; } else { isRosterResource = true; } }
void AddResourcesToPotentialReactions(ConfigNode reactantNode) { if (reactantNode == null) { return; } PartResourceDefinitionList resourceDefinitions = PartResourceLibrary.Instance.resourceDefinitions; for (int j = 0; j < reactantNode.values.Count; ++j) { ConfigNode.Value v = reactantNode.values[j]; if (v.name != "resource") { continue; } string resString = v.value; if (resourceDefinitions.Contains(resString)) { PartResourceDefinition p = resourceDefinitions[resString]; if (reactantPotentialReactions.ContainsKey(p.id)) { continue; } Debug.Log("[Blastwave]: Adding " + p.name + " as possible reactant"); reactantPotentialReactions.Add(p.id, new HashSet <ExplosiveReaction>()); } } }
public override void OnStart(StartState state) { base.OnStart(state); //Debug fields Fields["targetRotation"].guiActive = debugEnabled; Fields["targetElevation"].guiActive = debugEnabled; Fields["currentElevation"].guiActive = debugEnabled; //Find the transforms layerMask = 1 << LayerMask.NameToLayer("TerrainColliders") | 1 << LayerMask.NameToLayer("Local Scenery"); rotationTransform = this.part.FindModelTransform(rotationTransformName); elevationTransform = this.part.FindModelTransform(elevationTransformName); //This is needed to calculate the angle between reference straight up and elevationTransform. elevationReferenceTransform = this.part.FindModelTransform(referenceElevationTransformName); //This is needed to calculate the reference angle between a fixed point and rotationTransform. rotationReferenceTransform = this.part.FindModelTransform(referenceRotationTransformName); //Similar to a solar panel tracking the sun, this is used to determine if the tracking unit is blocked by something. secondaryTransform = this.part.FindModelTransform(secondaryTransformName); //Upkeep resource if (!string.IsNullOrEmpty(upkeepResource)) { PartResourceDefinitionList definitions = PartResourceLibrary.Instance.resourceDefinitions; resourceDef = definitions[upkeepResource]; minECLevel = (double)minimumVesselPercentEC / 100.0f; } }
protected void dumpCoolant(CoolantResource coolant, double dumpRate) { PartResourceDefinitionList definitions = PartResourceLibrary.Instance.resourceDefinitions; PartResourceDefinition resourceDef; double coolantToDump = dumpRate * TimeWarp.fixedDeltaTime; double coolantDumped = 0; double thermalEnergyCoolant = 0; //The the resource definition resourceDef = definitions[coolant.name]; //Now calculate the resource amount dumped and the thermal energy of that slug of resource. coolantDumped = this.part.RequestResource(resourceDef.id, coolantToDump * coolant.ratio, coolant.flowMode); if (coolantDumped <= 0.001) { if (soundClip != null) { soundClip.audio.Stop(); } showParticleEffects(false); ToggleCoolingMode(); return; } thermalEnergyCoolant = this.part.temperature * this.part.resourceThermalMass * coolantDumped; //Practice conservation of energy... if (coolantDumped > 0.001) { this.part.AddThermalFlux(-thermalEnergyCoolant); } }
protected void drawECStatus() { if (payloadMass < 0.001f) { GUILayout.Label("<color=white><b>ElectricCharge: </b></color>GO"); return; } PartResourceDefinitionList definitions = PartResourceLibrary.Instance.resourceDefinitions; PartResourceDefinition def; double amountAvailable = 0f; double maxAmount = 0; double amountRequired = electricityCostPerTonne * projectileMass; def = definitions["ElectricCharge"]; FlightGlobals.ActiveVessel.rootPart.GetConnectedResourceTotals(def.id, out amountAvailable, out maxAmount, true); if (amountAvailable >= amountRequired) { GUILayout.Label("<color=white><b>ElectricCharge: </b></color>GO"); } else { GUILayout.Label("<color=white><b>ElectricCharge: </b></color><color=red>NO GO</color>"); issues.AppendLine(string.Format(kECShortage, (amountRequired - amountAvailable))); } }
/// <summary> /// If the loaded vessel's parts with crew capacity don't have the resource /// </summary> /// <param name="vessel"></param> public void addResourcesIfNeeded(Vessel vessel) { if (!vessel.isEVA) { return; } PartResourceDefinitionList definitions = PartResourceLibrary.Instance.resourceDefinitions; PartResourceDefinition def; double partCurrentAmount = 0; double partMaxAmount = 0; if (string.IsNullOrEmpty(resourceName)) { return; } if (!definitions.Contains(resourceName)) { return; } //Check the vessel to see if it has the resources already. def = definitions[resourceName]; vessel.rootPart.GetConnectedResourceTotals(def.id, out partCurrentAmount, out partMaxAmount, true); if (partMaxAmount > 0) { return; } //Add the resource vessel.rootPart.Resources.Add(def.name, amount, maxAmount, true, true, false, true, PartResource.FlowMode.Both); }
public override string GetInfo() { PartResourceDefinitionList definitions = PartResourceLibrary.Instance.resourceDefinitions; PartResourceDefinition definition; StringBuilder info = new StringBuilder(); //Max acceleration info.AppendLine(string.Format(WBIKFSUtils.kMaxAcceleration, maxAcceleration)); //Propellants info.AppendLine(WBIKFSUtils.kPropellants); for (int index = 0; index < this.propellants.Count; index++) { info.AppendLine("-" + this.propellants[index].displayName); info.Append(propellants[index].GetFlowModeDescription()); } if (!string.IsNullOrEmpty(convertResource)) { definition = definitions[convertResource]; info.AppendLine(WBIKFSUtils.kRCSProducedFrom + definition.displayName); } info.AppendLine(WBIKFSUtils.kFuelFlowVaries); return(info.ToString()); }
public static bool VesselHasResource(string resourceName, Vessel vessel) { PartResourceDefinitionList definitions = PartResourceLibrary.Instance.resourceDefinitions; List <PartResource> resources; List <Part> parts; int resourceID; //First, does the resource definition exist? if (definitions.Contains(resourceName)) { resources = new List <PartResource>(); resourceID = definitions[resourceName].id; //The definition exists, now see if the vessel has the resource parts = vessel.parts; foreach (Part part in parts) { part.GetConnectedResources(resourceID, ResourceFlowMode.NULL, resources); //If somebody has the resource, then we're good. if (resources.Count > 0) { return(true); } } } return(false); }
public static double GetTotalResourceAmount(string resourceName, Vessel vessel) { PartResourceDefinitionList definitions = PartResourceLibrary.Instance.resourceDefinitions; List <Part> parts; double totalResources = 0f; //First, does the resource definition exist? if (definitions.Contains(resourceName)) { //The definition exists, now see if the vessel has the resource parts = vessel.parts; foreach (Part part in parts) { if (part.Resources.Count > 0) { foreach (PartResource res in part.Resources) { if (res.resourceName == resourceName) { totalResources += res.amount; } } } } } return(totalResources); }
public virtual void RemoveResource(string resourceName) { PartResourceDefinitionList definitions = PartResourceLibrary.Instance.resourceDefinitions; int resourceID = definitions[resourceName].id; this.part.Resources.dict.Remove(resourceID); }
/// <summary> /// Handles the crew eva event. The kerbal gains the EVA resource and the vessel loses a corresponding amount. /// </summary> /// <param name="evaKerbal">The kerbal that went on EVA</param> /// <param name="partExited">The part that the kerbal exited</param> public void onCrewEVA(Part evaKerbal, Part partExited) { PartResourceDefinitionList definitions = PartResourceLibrary.Instance.resourceDefinitions; PartResourceDefinition def; double partCurrentAmount = 0; double partMaxAmount = 0; if (string.IsNullOrEmpty(resourceName)) { return; } if (!definitions.Contains(resourceName)) { return; } //Make sure that we have enough resources. def = definitions[resourceName]; partExited.vessel.rootPart.GetConnectedResourceTotals(def.id, out partCurrentAmount, out partMaxAmount, true); if (partCurrentAmount <= amount) { return; } //Add the resource evaKerbal.Resources.Add(def.name, amount, maxAmount, true, true, false, true, PartResource.FlowMode.Both); //Remove resource from the vessel partExited.vessel.rootPart.RequestResource(def.id, amount); }
protected void emailPlayer(string resourceName, WBIBackroundEmailTypes emailType) { StringBuilder resultsMessage = new StringBuilder(); MessageSystem.Message msg; PartResourceDefinition resourceDef = null; PartResourceDefinitionList definitions = PartResourceLibrary.Instance.resourceDefinitions; string titleMessage; //Spam check if (playerEmailed || !WBIMainSettings.EmailConverterResults) { return; } else { playerEmailed = true; moduleSnapshot.moduleValues.SetValue("playerEmailed", playerEmailed); } //From resultsMessage.AppendLine("From: " + protoPart.pVesselRef.vesselName); switch (emailType) { case WBIBackroundEmailTypes.missingResources: resourceDef = definitions[resourceName]; titleMessage = " needs more resources"; resultsMessage.AppendLine("Subject: Missing Resources"); resultsMessage.AppendLine("There is no more " + resourceDef.displayName + " available to continue production. Operations cannot continue with the " + ConverterName + " until more resource becomes available."); break; case WBIBackroundEmailTypes.missingRequiredResource: resourceDef = definitions[resourceName]; titleMessage = " needs a resource"; resultsMessage.AppendLine("Subject: Missing Required Resource"); resultsMessage.AppendLine(ConverterName + " needs " + resourceDef.displayName + " in order to function. Operations halted until the resource becomes available."); break; case WBIBackroundEmailTypes.containerFull: resourceDef = definitions[resourceName]; titleMessage = " is out of storage space"; resultsMessage.AppendLine("Subject: Containers Are Full"); resultsMessage.AppendLine("There is no more storage space available for " + resourceDef.displayName + ". Operations cannot continue with the " + ConverterName + " until more space becomes available."); break; case WBIBackroundEmailTypes.yieldCriticalFail: titleMessage = "has suffered a critical failure in one of its converters"; resultsMessage.AppendLine("A " + ConverterName + " has failed! The production yield has been lost. It must be repaired and/or restarted before it can begin production again."); break; default: return; } msg = new MessageSystem.Message(protoPart.pVesselRef.vesselName + titleMessage, resultsMessage.ToString(), MessageSystemButton.MessageButtonColor.ORANGE, MessageSystemButton.ButtonIcons.ALERT); MessageSystem.Instance.AddMessage(msg); }
protected void getVesselResources(Vessel vessel, Dictionary <string, WBIResourceTotals> resourceMap) { resourceMap.Clear(); Part vesselPart; int totalParts = vessel.parts.Count; PartResource resource; int totalResources; WBIResourceTotals resourceTotals; PartResourceDefinitionList definitions = PartResourceLibrary.Instance.resourceDefinitions; PartResourceDefinition def; string displayName; for (int index = 0; index < totalParts; index++) { vesselPart = vessel.parts[index]; if (vesselPart == this.part) { continue; } totalResources = vesselPart.Resources.Count; for (int resourceIndex = 0; resourceIndex < totalResources; resourceIndex++) { //Get the resource resource = vesselPart.Resources[resourceIndex]; if (blackListedResources.Contains(resource.resourceName)) { continue; } //Get the display name def = definitions[resource.resourceName]; if (!string.IsNullOrEmpty(def.displayName)) { displayName = def.displayName; } else { displayName = resource.resourceName; } //Fill out the totals if (!resourceMap.ContainsKey(displayName)) { resourceTotals = new WBIResourceTotals(); resourceTotals.resourceName = resource.resourceName; resourceTotals.displayName = displayName; resourceMap.Add(displayName, resourceTotals); } resourceTotals = resourceMap[displayName]; resourceTotals.amount += resource.amount; resourceTotals.maxAmount += resource.maxAmount; resourceTotals.density = def.density; resourceMap[displayName] = resourceTotals; } } }
protected void drawLFOStatus() { PartResourceDefinitionList definitions = PartResourceLibrary.Instance.resourceDefinitions; PartResourceDefinition def; WBIResourceTotals[] resourceTotals = sourceVesselResources.Values.ToArray(); WBIResourceTotals totals; //Calculate the LiquidFuel requirements def = definitions["LiquidFuel"]; liquidFuelUnits = ((fuelMassFraction * payloadMass) * kLiquidFuelRatio) / def.density; totals.amount = 0f; totals.transferPercent = 0f; totals.maxAmount = 0f; for (int index = 0; index < resourceTotals.Length; index++) { totals = resourceTotals[index]; if (totals.resourceName == "LiquidFuel") { break; } } if (totals.maxAmount - (totals.amount * totals.transferPercent) >= liquidFuelUnits) { GUILayout.Label("<color=white><b>LiquidFuel: </b></color>GO"); } else { GUILayout.Label("<color=white><b>LiquidFuel: </b></color><color=red>NO GO</color>"); issues.AppendLine(string.Format(kLFShortage, (liquidFuelUnits - (totals.maxAmount - (totals.amount * totals.transferPercent))))); } //Calculate the Oxidizer requirements def = definitions["Oxidizer"]; oxidizerUnits = ((fuelMassFraction * payloadMass) * kOxidizerRatio) / def.density; totals.amount = 0f; totals.transferPercent = 0f; totals.maxAmount = 0f; for (int index = 0; index < resourceTotals.Length; index++) { totals = resourceTotals[index]; if (totals.resourceName == "Oxidizer") { break; } } if (totals.maxAmount - (totals.amount * totals.transferPercent) >= oxidizerUnits) { GUILayout.Label("<color=white><b>Oxidizer: </b></color>GO"); } else { GUILayout.Label("<color=white><b>Oxidizer: </b></color><color=red>NO GO</color>"); issues.AppendLine(string.Format(kOxShortage, (oxidizerUnits - (totals.maxAmount - (totals.amount * totals.transferPercent))))); } }
public static void AddResource(string resourceName, double amount, double maxAmount, Part part) { PartResourceDefinitionList definitions = PartResourceLibrary.Instance.resourceDefinitions; //First, does the resource definition exist? if (definitions.Contains(resourceName)) { part.Resources.Add(resourceName, amount, maxAmount, true, true, false, true, PartResource.FlowMode.Both); } }
private void loadSettings() { // Load the settings we need for interstellar travel. ConfigNode[] nodes = GameDatabase.Instance.GetConfigNodes(kBlueshiftSettings); if (nodes != null) { ConfigNode nodeSettings = nodes[0]; if (nodeSettings.HasValue(kInterstellarWarpSpeedMultiplier)) { float.TryParse(nodeSettings.GetValue(kInterstellarWarpSpeedMultiplier), out interstellarWarpSpeedMultiplier); } if (nodeSettings.HasValue(kSOIMultiplier)) { double.TryParse(nodeSettings.GetValue(kSOIMultiplier), out soiMultiplier); } if (nodeSettings.HasValue(kAutoCircularizationDelay)) { float.TryParse(nodeSettings.GetValue(kAutoCircularizationDelay), out autoCircularizationDelay); } if (nodeSettings.HasValue(kCircularizationResource)) { PartResourceDefinitionList definitions = PartResourceLibrary.Instance.resourceDefinitions; string resourceName = nodeSettings.GetValue(kCircularizationResource); if (definitions.Contains(resourceName)) { circularizationResourceDef = definitions[resourceName]; } } if (nodeSettings.HasValue(kCircularizationCostPerTonne)) { double.TryParse(nodeSettings.GetValue(kCircularizationCostPerTonne), out circularizationCostPerTonne); } if (nodeSettings.HasValue(kAnomalyCheckSeconds)) { double.TryParse(nodeSettings.GetValue(kAnomalyCheckSeconds), out anomalyCheckSeconds); } if (nodeSettings.HasValue(kCelestialBlacklist)) { celestialBlacklists = nodeSettings.GetValues(kCelestialBlacklist); } if (nodeSettings.HasValue(kSoiNoPlanetsMultiplier)) { double.TryParse(nodeSettings.GetValue(kSoiNoPlanetsMultiplier), out soiNoPlanetsMultiplier); } } }
public virtual string GetStatusDisplay() { StringBuilder status = new StringBuilder(); string colorTag = string.Empty; string endTag = string.Empty; double percentRemaining = amount / maxAmount; PartResourceDefinitionList definitions = PartResourceLibrary.Instance.resourceDefinitions; //Determine color tag if (estimatedTimeRemaining < 0 || percentRemaining > 0.5) { colorTag = string.Empty; endTag = string.Empty; } else if (percentRemaining > 0.25) { colorTag = "<color=yellow>"; endTag = "</color>"; } else { colorTag = "<color=red><b>"; endTag = "</b></color>"; } //Resource and amount / maxAmount status.Append(colorTag + definitions[resourceName].displayName + ": "); status.AppendFormat("{0:f2}/{1:f2}", amount, maxAmount); status.AppendLine(endTag); //Duration if (simulatorInterrupted) { status.AppendLine("<color=white>Duration: Unavailable</color>"); } else if (estimatedTimeRemaining < 0) { status.AppendLine("<color=white>Duration: Indefinite</color>"); } else if (isSimulatorRunning) { status.AppendLine("<color=white>Duration: Calculating...</color>"); } else { string timeString = SnacksScenario.FormatTime(estimatedTimeRemaining); if (amount < 0.0001) { timeString = "0 Seconds"; } status.AppendLine(colorTag + "Duration: " + timeString + endTag); } return(status.ToString()); }
protected void updateResourceRatios() { ResourceRatio ratio; StringBuilder resourceBuilder = new StringBuilder(); string inputRatios, outputRatios; //Inputs for (int index = 0; index < inputList.Count; index++) { ratio = inputList[index]; if (ratio.ResourceName == "ElectricCharge") { hasElectricChargeInput = true; PartResourceDefinitionList definitions = PartResourceLibrary.Instance.resourceDefinitions; resourceDef = definitions["ElectricCharge"]; minECLevel = (double)minimumVesselPercentEC / 100.0f; continue; } resourceBuilder.Append(ratio.ResourceName); resourceBuilder.Append(","); resourceBuilder.Append(ratio.Ratio.ToString()); resourceBuilder.Append(";"); } //Trim the trailing ";" character. inputRatios = resourceBuilder.ToString(); inputRatios = inputRatios.TrimEnd(new char[] { ';' }); //Outputs resourceBuilder = new StringBuilder(); for (int index = 0; index < outputList.Count; index++) { ratio = outputList[index]; resourceBuilder.Append(ratio.ResourceName); resourceBuilder.Append(","); resourceBuilder.Append(ratio.Ratio.ToString()); resourceBuilder.Append(";"); if (ratio.ResourceName == SnacksProperties.SnacksResourceName) { originalSnacksRatio = ratio.Ratio; } } //Trim the trailing ";" character. outputRatios = resourceBuilder.ToString(); outputRatios = outputRatios.TrimEnd(new char[] { ';' }); resourceRatios = inputRatios + "|" + outputRatios; if (SnackController.debugMode) { Debug.Log("[" + this.ClassName + "] - resourceRatios: " + resourceRatios); } }
public static void RemoveResource(string resourceName, Part part) { if (part.Resources.Contains(resourceName)) { PartResourceDefinitionList definitions = PartResourceLibrary.Instance.resourceDefinitions; PartResource resource = part.Resources[resourceName]; int resourceID = definitions[resourceName].id; part.Resources.dict.Remove(resourceID); } }
public static PartResourceDefinition DefinitionForResource(string resourceName) { PartResourceDefinitionList definitions = PartResourceLibrary.Instance.resourceDefinitions; if (definitions.Contains(resourceName)) { return(definitions[resourceName]); } return(null); }
public static List <PartResource> GetConnectedResources(string resourceName, Part part) { PartResourceDefinitionList definitions = PartResourceLibrary.Instance.resourceDefinitions; List <PartResource> resources = new List <PartResource>(); int resourceID; if (definitions.Contains(resourceName)) { resourceID = definitions[resourceName].id; part.GetConnectedResources(resourceID, ResourceFlowMode.NULL, resources); } return(resources); }
public WBIRefineryResource(ConfigNode node) { if (node == null) { return; } AddTier(node); PartResourceDefinitionList definitions = PartResourceLibrary.Instance.resourceDefinitions; if (!definitions.Contains(resourceName)) { return; } resourceDef = definitions[resourceName]; }