public void CalculateWaterNeed() { //Debug.Log(population.species.SpeciesName + " has liquid need " + population.Needs.ContainsKey("Liquid")); if (!population.Needs.ContainsKey("Liquid")) { waterRating = 0; return; } LiquidNeed tileNeed = (LiquidNeed)population.Needs["Liquid"]; LiquidNeed waterNeed = null; if (population.Needs.ContainsKey("Water")) { waterNeed = (LiquidNeed)population.Needs["Water"]; } LiquidNeed saltNeed = null; if (population.Needs.ContainsKey("Salt")) { saltNeed = (LiquidNeed)population.Needs["Salt"]; } LiquidNeed bacteriaNeed = null; if (population.Needs.ContainsKey("Bacteria")) { bacteriaNeed = (LiquidNeed)population.Needs["Bacteria"]; } int numAnimals = population.AnimalPopulation.Count; float waterSourceSize = tileNeed.NeedValue; float totalNeedWaterTiles = tileNeed.GetThreshold() * numAnimals; float waterTilesUsed = Mathf.Min(waterSourceSize, totalNeedWaterTiles); if (waterTilesUsed >= totalNeedWaterTiles) { //Debug.Log("Water need met"); IsNeedMet[NeedType.Liquid] = true; waterRating = 0; if (waterNeed != null) { float percentPureWater = waterNeed.NeedValue; float neededPureWaterThreshold = waterNeed.GetThreshold(); waterRating += (percentPureWater - neededPureWaterThreshold) / (maxFreshWaterTilePercent - neededPureWaterThreshold); //Debug.Log("Pure water received: " + percentPureWater + " out of " + neededPureWaterThreshold); } if (saltNeed != null) { float percentSalt = saltNeed.NeedValue; float neededSaltThreshold = saltNeed.GetThreshold(); waterRating += (percentSalt - neededSaltThreshold) / (maxSaltTilePercent - neededSaltThreshold); //Debug.Log("Salt received: " + percentSalt + " out of " + neededSaltThreshold); } if (bacteriaNeed != null) { float percentBacteria = bacteriaNeed.NeedValue; float neededBacteriaThreshold = bacteriaNeed.GetThreshold(); waterRating += (percentBacteria - neededBacteriaThreshold) / (maxBacteriaTilePercent - neededBacteriaThreshold); //Debug.Log("Bacteria received: " + percentBacteria + " out of " + neededBacteriaThreshold); } } else { IsNeedMet[NeedType.Liquid] = false; waterRating = (waterTilesUsed - totalNeedWaterTiles) / totalNeedWaterTiles; } //Debug.Log(population.gameObject.name + " water Rating: " + waterRating + ", water source size: "+ waterTilesUsed); }
public void CalculateWaterNeed() { if (!needs.ContainsKey("LiquidTiles")) { waterRating = 0; return; } LiquidNeed tileNeed = (LiquidNeed)needs["LiquidTiles"]; LiquidNeed waterNeed = null; if (needs.ContainsKey("Water")) { waterNeed = (LiquidNeed)needs["Water"]; } LiquidNeed saltNeed = null; if (needs.ContainsKey("Salt")) { saltNeed = (LiquidNeed)needs["Salt"]; } LiquidNeed bacteriaNeed = null; if (needs.ContainsKey("Bacteria")) { bacteriaNeed = (LiquidNeed)needs["Bacteria"]; } float waterSourceSize = tileNeed.NeedValue; float totalNeedWaterTiles = tileNeed.GetThreshold(); float waterTilesUsed = Mathf.Min(waterSourceSize, totalNeedWaterTiles); if (waterTilesUsed >= totalNeedWaterTiles) { //Debug.Log("Water need met"); waterNeedMet = true; waterRating = 0; if (waterNeed != null) { float percentPureWater = waterNeed.NeedValue; float neededPureWaterThreshold = waterNeed.GetThreshold(); waterRating += (percentPureWater - neededPureWaterThreshold) / (GrowthCalculator.maxFreshWaterTilePercent - neededPureWaterThreshold); //Debug.Log("Pure water received: " + percentPureWater + " out of " + neededPureWaterThreshold); } if (saltNeed != null) { float percentSalt = saltNeed.NeedValue; float neededSaltThreshold = saltNeed.GetThreshold(); waterRating += (percentSalt - neededSaltThreshold) / (GrowthCalculator.maxSaltTilePercent - neededSaltThreshold); //Debug.Log("Salt received: " + percentSalt + " out of " + neededSaltThreshold); } if (bacteriaNeed != null) { float percentBacteria = bacteriaNeed.NeedValue; float neededBacteriaThreshold = bacteriaNeed.GetThreshold(); waterRating += (percentBacteria - neededBacteriaThreshold) / (GrowthCalculator.maxBacteriaTilePercent - neededBacteriaThreshold); //Debug.Log("Bacteria received: " + percentBacteria + " out of " + neededBacteriaThreshold); } } else { waterNeedMet = false; waterRating = (waterTilesUsed - totalNeedWaterTiles) / totalNeedWaterTiles; } //if (gameObject) //Debug.Log(gameObject.name + " water Rating: " + waterRating + ", water source size: " + waterTilesUsed); }