/// <summary> /// Sets up our abundance. /// </summary> public virtual void SetupAbundance() { //Get the ore resource List <ModuleAsteroidResource> asteroidResources = this.part.FindModulesImplementing <ModuleAsteroidResource>(); int resourceCount = asteroidResources.Count; ModuleAsteroidResource oreResource = null; for (int index = 0; index < resourceCount; index++) { if (asteroidResources[index].resourceName == "Ore") { oreResource = asteroidResources[index]; break; } } //Not sure why but display abundance isn't the same as abundance so we'll fudge this... float displayFactor = 0.875f; if (oreResource != null) { displayFactor = oreResource.displayAbundance / oreResource.abundance; } //Take an average of all the resource high/low values float averageRange = 0f; float totalAverageRange = 0f; for (int index = 0; index < resourceCount; index++) { averageRange = ((float)asteroidResources[index].lowRange + (float)asteroidResources[index].highRange) / 2.0f; totalAverageRange += averageRange; } //Now let's get a random range for the resource float resourceRange = UnityEngine.Random.Range((float)lowRange, (float)highRange); //Set abundance abundance = resourceRange / totalAverageRange; //Set display abundance displayAbundance = abundance * displayFactor; }
/// <summary> /// Assimilates resources specified in resourcesToAssimilate by taking their abundance and display abundance /// and adding it to this asteroid resource. Resistance is futile. /// </summary> public virtual void AssimilateResources() { List <ModuleAsteroidResource> asteroidResources = this.part.FindModulesImplementing <ModuleAsteroidResource>(); int resourceCount = asteroidResources.Count; ModuleAsteroidResource asteroidResource = null; float assimilateAbundance = 0f; float assimilateDisplayAbundance = 0f; for (int index = 0; index < resourceCount; index++) { asteroidResource = asteroidResources[index]; if (resourcesToAssimilate.Contains(asteroidResource.resourceName)) { assimilateAbundance = asteroidResource.abundance * assimilateFraction; assimilateDisplayAbundance = asteroidResource.displayAbundance * assimilateFraction; abundance += assimilateAbundance; displayAbundance += assimilateDisplayAbundance; asteroidResource.abundance -= assimilateAbundance; asteroidResource.displayAbundance -= assimilateDisplayAbundance; } } }
protected override ConversionRecipe PrepareRecipe(double deltaTime) { this._status = "Connected"; this._potato = this.GetAttachedPotato(); this._drilledMass = 0; if (this._potato == null) { this._status = cacheAutoLOC_258405; this.IsActivated = false; return(null); } if (this.DirectAttach && !base.part.children.Contains(this._potato) && !(base.part.parent == this._potato)) { this._status = cacheAutoLOC_258412; this.IsActivated = false; return(null); } if (!this.RockOnly && !this._potato.Modules.Contains("ModuleAsteroidResource")) { this._status = cacheAutoLOC_258419; this.IsActivated = false; return(null); } List <ModuleAsteroidResource> moduleAsteroidResources = this._potato.FindModulesImplementing <ModuleAsteroidResource>(); if (!this.CheckForImpact()) { this._status = cacheAutoLOC_258428; this.IsActivated = false; return(null); } this._info = this._potato.FindModuleImplementing <ModuleAsteroidInfo>(); if (this._info == null) { this._status = cacheAutoLOC_258436; this.IsActivated = false; return(null); } if (this._info.massThresholdVal >= this._info.currentMassVal) { this._status = cacheAutoLOC_258443; this.IsActivated = false; return(null); } if (this.ResBroker.AmountAvailable(base.part, "ElectricCharge", deltaTime, ResourceFlowMode.NULL) <= deltaTime * (double)this.PowerConsumption) { this._status = cacheAutoLOC_258451; this.IsActivated = false; return(null); } this.UpdateConverterStatus(); if (!this.IsActivated) { return(null); } double efficiencyMultiplier = this.GetEfficiencyMultiplier(); bool flag = false; int count = moduleAsteroidResources.Count; int num = 0; while (true) { if (num < count) { ModuleAsteroidResource item = moduleAsteroidResources[num]; if (this.ResBroker.StorageAvailable(base.part, item.resourceName, deltaTime, item._flowMode, (double)this.FillAmount) > deltaTime * (double)item.abundance * (double)this.Efficiency * efficiencyMultiplier) { flag = true; break; } else { num++; } } else { break; } } this.recipe.Clear(); if (!flag) { this._status = cacheAutoLOC_258501; } else { List <ResourceRatio> inputs = this.recipe.Inputs; ResourceRatio resourceRatio = new ResourceRatio() { ResourceName = "ElectricCharge", Ratio = (double)this.PowerConsumption, FlowMode = ResourceFlowMode.NULL }; inputs.Add(resourceRatio); for (int i = 0; i < count; i++) { ModuleAsteroidResource moduleAsteroidResource = moduleAsteroidResources[i]; if ((double)moduleAsteroidResource.abundance > 1E-09) { PartResourceDefinition definition = PartResourceLibrary.Instance.GetDefinition(moduleAsteroidResource.resourceName); double num1 = deltaTime * (double)moduleAsteroidResource.abundance * (double)this.Efficiency * efficiencyMultiplier; double num2 = this._info.currentMassVal - this._info.massThresholdVal; double num3 = num2 / (double)definition.density; double num4 = Math.Min(num1, num3); GTI_ModuleAsteroidDrill moduleAsteroidDrill = this; moduleAsteroidDrill._drilledMass = moduleAsteroidDrill._drilledMass + (double)definition.density * num4; ResourceRatio resourceRatio1 = new ResourceRatio() { ResourceName = moduleAsteroidResource.resourceName, Ratio = num4 / deltaTime, DumpExcess = true, FlowMode = ResourceFlowMode.NULL }; this.recipe.Outputs.Add(resourceRatio1); } } } return(this.recipe); }
public void CheckGoldStrike() { string[] strikeResourceKeys = null; int resourceIndex; GoldStrikeData strikeData = null; WBIGoldStrikeScenario scenario = WBIGoldStrikeScenario.Instance; string resourceName = string.Empty; double resourceAmount = 0f; float analysisRoll = 0f; float successTargetNumber = prospectChance; string navigationID = string.Empty; GoldStrikeLode lode = null; string biomeName = string.Empty; int planetID = -1; //Do we have a valid situation? if (SituationIsValid() == false) { return; } //Update our location. asteroid = this.part.vessel.FindPartModuleImplementing <ModuleAsteroid>(); GoldStrikeUtils.GetBiomeAndPlanet(out biomeName, out planetID, this.part.vessel, asteroid); vesselModule.UpdateLastProspectLocation(); //Time to see if we find anything. //prospectChance: base chance to find a prospect. Some parts are better than others. //prospectBonus: Various situations contribute to the success of the attempt. successTargetNumber = 100 - (prospectChance + GetProspectBonus()); debugLog("successTargetNumber: " + successTargetNumber); //Roll the chance and check it. analysisRoll = UnityEngine.Random.Range(1, 100); debugLog("analysisRoll: " + analysisRoll); //If we didn't succeed then we're done. if (analysisRoll < successTargetNumber && !WBIGoldStrikeScenario.debugProspectAlwaysSuccessful) { debugLog("Prospect failed; didn't roll high enough."); ScreenMessages.PostScreenMessage("Nothing of value here, try another location. ", kMessageDisplayTime, ScreenMessageStyle.UPPER_CENTER); return; } //Success! Get the resource name and strike data. //If we're near an anomaly then we need a roll table. if (anomalyBonus > 0) { SortedDictionary <int, GoldStrikeData> sortedResources = new SortedDictionary <int, GoldStrikeData>(); int resourceCount = prospectResources.Count; //Add any resources that have an anomaly chance into the sorted resources for (int index = 0; index < resourceCount; index++) { strikeData = prospectResources[index]; if (strikeData.anomalyChance > 0) { sortedResources.Add(strikeData.anomalyChance, strikeData); } } //Roll a 1-100 int pressenceRoll = UnityEngine.Random.Range(1, 100); //See if we have any strike data strikeData = null; foreach (KeyValuePair <int, GoldStrikeData> pair in sortedResources) { if (pressenceRoll < pair.Key) { strikeData = pair.Value; break; } } //If we don't have any strike data then pick a random resource if (strikeData == null) { resourceIndex = UnityEngine.Random.Range(0, resourceCount - 1); strikeData = prospectResources[resourceIndex]; resourceName = strikeData.resourceName; } } else { resourceIndex = UnityEngine.Random.Range(0, prospectResources.Count - 1); strikeData = prospectResources[resourceIndex]; resourceName = strikeData.resourceName; debugLog("prospectResources count: " + prospectResources.Count); debugLog("resourceIndex: " + resourceIndex); } debugLog("strikeData: " + strikeData.ToString()); //Play the jingle playJingle(); //Setup a planetary surface lode if (asteroid == null) { debugLog("Setting up surface lode"); //Now, generate the resource amount to add to the map resourceAmount = UnityEngine.Random.Range(strikeData.minAmount, strikeData.maxAmount); debugLog("resourceAmount: " + resourceAmount); //If we hit the motherlode then factor that in. //The motherloade is 5% of the target number. if (analysisRoll <= (successTargetNumber * kMotherlodeFactor)) { resourceAmount *= strikeData.motherlodeMultiplier; debugLog("resourceAmount after motherlode: " + resourceAmount); ScreenMessages.PostScreenMessage(string.Format("Congratulations! You found a {0:s} motherlode with {1:f2} units available to mine!", resourceName, resourceAmount), kMessageDisplayTime, ScreenMessageStyle.UPPER_CENTER); } else { ScreenMessages.PostScreenMessage(string.Format("Congratulations! You found a {0:s} lode with {1:f2} units available to mine!", resourceName, resourceAmount), kMessageDisplayTime, ScreenMessageStyle.UPPER_CENTER); } if (!string.IsNullOrEmpty(anomalyName)) { ScreenMessages.PostScreenMessage("Special cache found at " + anomalyName, kMessageDisplayTime, ScreenMessageStyle.UPPER_CENTER); } debugLog("Adding new lode entry to " + FlightGlobals.currentMainBody.name + " with flight global index " + FlightGlobals.currentMainBody.flightGlobalsIndex); debugLog("Biome: " + biomeName); debugLog("Lon/Lat: " + this.part.vessel.longitude + "/" + this.part.vessel.latitude); lode = scenario.AddLode(planetID, biomeName, this.part.vessel.longitude, this.part.vessel.latitude, this.part.vessel.altitude, resourceName, resourceAmount); } //Setup an asteroid lode else { debugLog("Setting up asteroid lode"); float abundance = 0.01f; //Get the resource module for the lode. ModuleAsteroidResource lodeResource = null; ModuleAsteroidResource[] resourceModules = asteroid.part.FindModulesImplementing <ModuleAsteroidResource>().ToArray(); for (int index = 0; index < resourceModules.Length; index++) { if (resourceModules[index].resourceName == resourceName) { debugLog("ModuleAsteroidResource found for " + resourceName); lodeResource = resourceModules[index]; break; } } if (lodeResource == null) { debugLog("ModuleAsteroidResource NOT found for " + resourceName); return; } //Adjust abundance for motherlode if (analysisRoll <= (successTargetNumber * kMotherlodeFactor)) { abundance *= strikeData.motherlodeMultiplier; } debugLog("abundance increase: " + abundance); //Display appropriate message ScreenMessages.PostScreenMessage(string.Format("Congratulations! A careful scan of {0:s} has revealed an increased abundance of {1:s}", asteroid.AsteroidName, resourceName), kMessageDisplayTime, ScreenMessageStyle.UPPER_CENTER); //Update resource module debugLog("Old abundance: " + lodeResource.abundance); lodeResource.abundance += abundance; lodeResource.displayAbundance += abundance; debugLog("New abundance: " + lodeResource.abundance); debugLog("Adding new lode entry for asteroid: " + asteroid.AsteroidName); lode = scenario.AddLode(asteroid, resourceName, lodeResource.displayAbundance); } //Update any drills in the area. scenario.UpdateDrillLodes(asteroid); //Set waypoint if (lode != null && asteroid == null) { setWaypoint(resourceName, lode); } }
protected void setupResources() { //If we've already done the resource swap them we're done. if (resourcesConverted) { return; } //Find the Ore, water, and guaranteed resources (if any) ModuleAsteroidResource[] asteroidResources = this.part.FindModulesImplementing <ModuleAsteroidResource>().ToArray(); ModuleAsteroidResource oreResource = null; ModuleAsteroidResource waterResource = null; List <ModuleAsteroidResource> extraResources = new List <ModuleAsteroidResource>(); PartResourceDefinitionList definitions = PartResourceLibrary.Instance.resourceDefinitions; for (int index = 0; index < asteroidResources.Length; index++) { if (asteroidResources[index].resourceName == "Ore") { oreResource = asteroidResources[index]; } else if (asteroidResources[index].resourceName == waterResourceName) { //Does definition exist? if (definitions.Contains(asteroidResources[index].resourceName)) { waterResource = asteroidResources[index]; } } //If the resource is guaranteed then add it to the guarantee list. else if (string.IsNullOrEmpty(guaranteeResources) == false) { if (guaranteeResources.Contains(asteroidResources[index].resourceName) && definitions.Contains(asteroidResources[index].resourceName)) { extraResources.Add(asteroidResources[index]); } } } if (oreResource == null) { Debug.Log("[ModuleKomet] - oreResource is null, cannot setup resources."); return; } if (waterResource == null) { Debug.Log("[ModuleKomet] - waterResource is null, cannot setup resources."); return; } //Adjust the abundance for the guaranteed resources to at least the minimum float guaranteedResourcePercent = minimumResourcePercent / 100.0f; ModuleAsteroidResource[] resExtras = extraResources.ToArray(); for (int index = 0; index < resExtras.Length; index++) { resExtras[index].abundance += guaranteedResourcePercent; //Reduce ore percentage accordingly. oreResource.abundance -= guaranteedResourcePercent; // Debug.Log("[ModuleKomet] - " + resExtras[index].resourceName + " abundance: " + resExtras[index].abundance); } //Adjust the Water and Ore abundance float waterAbundancePercent = (waterPercentage / 100.0f) * oreResource.abundance; oreResource.abundance = oreResource.abundance = waterAbundancePercent; waterResource.abundance += waterAbundancePercent; // Debug.Log("[ModuleKomet] - oreResource abundance: " + oreResource.abundance); // Debug.Log("[ModuleKomet] - waterResource abundance: " + waterResource.abundance); ModuleAsteroidInfo asteroidInfo = this.part.FindModuleImplementing <ModuleAsteroidInfo>(); Debug.Log(asteroidInfo.resources); //Set the converted flag. resourcesConverted = true; }