private static bool MinePlanetaryBody(IResourceManager resMan, Vessel vessel, Dictionary <string, CrustalResourceAbundance> resourceAbundance, double percentPower, double drillSize, double effectiveness) { var ret = GetResourceData(vessel, out var localResources, resourceAbundance); if (ret == false) // if gathering resource data was not okay, no mining { ScreenMessages.PostScreenMessage(Localizer.Format("#LOC_KSPIE_UniversalCrustExtractor_PostMsg2"), 3.0f, ScreenMessageStyle.LOWER_CENTER); //"The universal drill is not sure where you are trying to mine. Please contact the mod author, tell him the details of this situation and provide the output log." // DisableCollector(); } if (!CalculateCrustThickness(vessel.altitude, FlightGlobals.currentMainBody, out var crustThickness)) // crust thickness calculation off, no mining { return(false); } double minedAmount = crustThickness * drillSize * effectiveness * percentPower; double minedAmountStock = 0.0005 * drillSize * effectiveness * percentPower; foreach (CrustalResource resource in localResources) { resourceAbundance.TryGetValue(resource.ResourceName, out var abundance); if (abundance == null) { continue; } if (resource.ResourceName == "Ore") { resource.Production = minedAmountStock * abundance.Local; } else { resource.Production = minedAmount * abundance.Local; } var resId = KITResourceSettings.NameToResource(resource.ResourceName); var ok = resMan.CapacityInformation(resId, out var maxAmount, out var spareRoom, out var currentAmount, out var _); if (!ok) { continue; } if (resource.SpareRoom > 0) // if there's space, add the resource { resMan.Produce(resId, resource.Production); } } return(true); }
/// <summary> /// Does the actual addition (collection) of the current resource. /// </summary> /// <param name="amount">The amount of resource to collect/add.</param> /// <param name="resourceName">The name of the current resource.</param> private double AddResource(IResourceManager resMan, double amount, string resourceName) { var resID = KITResourceSettings.NameToResource(resourceName); if (resID == ResourceName.Unknown) { return(part.RequestResource(resourceName, -amount * resMan.FixedDeltaTime(), ResourceFlowMode.ALL_VESSEL)); } resMan.Produce(resID, amount); return(amount); }
public BoilOffConfiguration(ConfigNode node) { Name = KITResourceSettings.NameToResource(node.name); _failed = (Name == ResourceName.Unknown); _failed |= !node.TryGetValue("resourceGUIName", ref ResourceGuiName); _failed |= !node.TryGetValue("boilOffRate", ref BoilOffRate); _failed |= !node.TryGetValue("boilOffTemp", ref BoilOffTemp); _failed |= !node.TryGetValue("boilOffMultiplier", ref BoilOffMultiplier); _failed |= !node.TryGetValue("boilOffBase", ref BoilOffBase); _failed |= !node.TryGetValue("boilOffAddition", ref BoilOffAddition); if (_failed) { Debug.Log($"[BoilOffConfiguration] Unable to parse KIT_CRYOSTAT_CONFIG node {node.name}, got {Name}, {ResourceGuiName}, {BoilOffRate}, {BoilOffTemp}, {BoilOffMultiplier}, {BoilOffBase}, and {BoilOffAddition}"); } }
private static DecayConfiguration ParseConfig(ConfigNode node) { DecayConfiguration ret = new DecayConfiguration(); string tmpStr = ""; if (!node.TryGetValue("decayProduct", ref tmpStr)) { Debug.Log($"[VesselDecay.ParseConfig] - resource configuration {node.name} is invalid. Error getting decayProduct"); return(ret); } ret.DecayProduct = KITResourceSettings.NameToResource(tmpStr); if (ret.DecayProduct == ResourceName.Unknown) { Debug.Log($"[VesselDecay.ParseConfig] - resource configuration {node.name} is invalid. Unable to convert decayProduct to a resource identifier"); return(ret); } if (!PartResourceLibrary.Instance.resourceDefinitions.Contains(tmpStr)) { Debug.Log($"[VesselDecay.ParseConfig] - resource configuration {node.name} is invalid. {tmpStr} is an undefined resource"); return(ret); } ret.DensityRatio = PartResourceLibrary.Instance.GetDefinition(node.name).density / PartResourceLibrary.Instance.GetDefinition(tmpStr).density; if (!node.TryGetValue("decayConstant", ref ret.DecayConstant)) { Debug.Log($"[VesselDecay.ParseConfig] - resource configuration {node.name} is invalid. Error getting decayConstant"); return(ret); } if (!PartResourceLibrary.Instance.resourceDefinitions.Contains(node.name)) { Debug.Log($"[VesselDecay.ParseConfig] missing resource definition for {node.name}"); return(ret); } ret.ResourceId = KITResourceSettings.NameToResource(node.name); if (ret.ResourceId == ResourceName.Unknown) { Debug.Log($"[VesselDecay.ParseConfig] missing resource definition for either {ret.DecayProduct} or {node.name}"); return(ret); } ret.Valid = true; return(ret); }
private static bool MineAsteroidComet(IResourceManager resMan, ModuleSpaceObjectInfo spaceObjectInfo, List <ModuleSpaceObjectResource> asteroidCometResources, double drillSize, double effectiveness, double percentPower) { // TODO - can we add a bonus multiplier here? Perhaps based on asteroid mass? double bonusMultiplier = 0.05; // 0.0005 double minedAmount = bonusMultiplier * drillSize * effectiveness * percentPower; minedAmount = Math.Min(minedAmount, (spaceObjectInfo.currentMassVal - spaceObjectInfo.massThresholdVal)); if (minedAmount < 1e-6) { spaceObjectInfo.currentMassVal = spaceObjectInfo.massThresholdVal; return(false); } foreach (var resource in asteroidCometResources) { var def = PartResourceLibrary.Instance.GetDefinition(resource.resourceName); if (def == null) { continue; } var amount = (minedAmount * resource.abundance) * def.density; if (amount == 0) { continue; } var resId = KITResourceSettings.NameToResource(resource.resourceName); resMan.Produce(resId, amount); } spaceObjectInfo.currentMassVal = Math.Max(spaceObjectInfo.massThresholdVal, spaceObjectInfo.currentMassVal - (minedAmount * resMan.FixedDeltaTime())); return(true); }
public GasLiquidConversion() { if (_conversionTable != null) { return; } _conversionTable = new Dictionary <ResourceName, Conversion>(24); var rootNode = GameDatabase.Instance.GetConfigNodes("KIT_GAS_LIQUID_CONVERSION"); if (rootNode == null || rootNode.Length == 0) { Debug.Log("[GasLiquidConversion] Can not find configuration node KIT_GAS_LIQUID_CONVERSION"); return; } foreach (var node in rootNode[0].GetNodes("Conversion")) { string secondaryResourceName; double maxPowerSecondary, primaryConversionEnergyCost, secondaryConversionEnergyCost; var primaryResourceName = secondaryResourceName = ""; var maxPowerPrimary = maxPowerSecondary = primaryConversionEnergyCost = secondaryConversionEnergyCost = 0; var failed = !node.TryGetValue(nameof(primaryResourceName), ref primaryResourceName); if (!node.TryGetValue(nameof(secondaryResourceName), ref secondaryResourceName)) { failed = true; } if (!node.TryGetValue(nameof(maxPowerPrimary), ref maxPowerPrimary)) { failed = true; } if (!node.TryGetValue(nameof(maxPowerSecondary), ref maxPowerSecondary)) { failed = true; } if (!node.TryGetValue(nameof(primaryConversionEnergyCost), ref primaryConversionEnergyCost)) { failed = true; } if (!node.TryGetValue(nameof(secondaryConversionEnergyCost), ref secondaryConversionEnergyCost)) { failed = true; } if (failed) { Debug.Log($"[GasLiquidConversion] unable to parse the entry of {primaryResourceName} / {secondaryResourceName} / {maxPowerPrimary} / {maxPowerSecondary}"); continue; } var primaryId = KITResourceSettings.NameToResource(primaryResourceName); var secondaryId = KITResourceSettings.NameToResource(secondaryResourceName); if (primaryId == ResourceName.Unknown || secondaryId == ResourceName.Unknown) { Debug.Log($"[GasLiquidConversion] can't convert either {primaryResourceName} or {secondaryResourceName} to KIT resource"); continue; } var primaryDefinition = PartResourceLibrary.Instance.GetDefinition(primaryResourceName); var secondaryDefinition = PartResourceLibrary.Instance.GetDefinition(secondaryResourceName); if (primaryDefinition == null || secondaryDefinition == null) { Debug.Log($"[GasLiquidConversion] unable to find resource definition {primaryResourceName} and/or {secondaryResourceName}"); return; } if (primaryDefinition.density == 0 || secondaryDefinition.density == 0) { Debug.Log("[GasLiquidConversion] why is the definition density 0 on {primaryResourceName} and/or {secondaryResourceName}"); return; } _conversionTable[primaryId] = new Conversion(maxPowerPrimary, maxPowerSecondary, primaryConversionEnergyCost, secondaryConversionEnergyCost, primaryDefinition, secondaryDefinition); } }