// called upon Trade with People private void UpdateSupplyOnTradeWithPeople() { foreach (Good.GoodType type in goodsToSupply.Keys) { // store number of icons in inventory being displayed int countInInventory = GovtInventory.GetGoodsOfType(type).Count + PeoplesInventory.GetGoodsOfType(type).Count; // calculate how much was there before float currentSupply = goodsToSupply [type]; float max = (type == Good.GoodType.Ideas) ? MaxIdeasSupply : MaxDrugsSupply; int projectedNum = ((currentSupply / max) < 0.3f) ? 0 : Mathf.FloorToInt((currentSupply - (max * 0.3f)) / 100); float diff = 100.0f * (projectedNum - countInInventory); // 100 is value of single icon goodsToSupply [type] += diff; } }
// called upon DetermineState(), alters number of icons in government inventory based on city's supply of good private void UpdateInventory() { foreach (Good.GoodType type in goodsToSupply.Keys) { float currentSupply = goodsToSupply [type]; float max = (type == Good.GoodType.Ideas) ? MaxIdeasSupply : MaxDrugsSupply; int projectedNum = ((currentSupply / max) < 0.3f) ? 0 : Mathf.FloorToInt((currentSupply - (max * 0.3f)) / 100); // projectedNum should be between 0 and 10 for most goods and max of 5 for ideas List <int> govtInventoryGoods = GovtInventory.GetGoodsOfType(type); List <int> peopleInventoryGoods = PeoplesInventory.GetGoodsOfType(type); if (projectedNum < govtInventoryGoods.Count + peopleInventoryGoods.Count) { // consumed int numToRemove = govtInventoryGoods.Count + peopleInventoryGoods.Count - projectedNum; // take from people first for (int i = peopleInventoryGoods.Count - 1; i > 0 && numToRemove > 0; i--) { PeoplesInventory.RemoveGoodIfAny(i); numToRemove--; } for (int i = govtInventoryGoods.Count - 1; i > 0 && numToRemove > 0; i--) { GovtInventory.RemoveGoodIfAny(i); numToRemove--; } } else if (projectedNum > govtInventoryGoods.Count + peopleInventoryGoods.Count) { // produced int numToAdd = projectedNum - govtInventoryGoods.Count - peopleInventoryGoods.Count; for (int i = 0; i < numToAdd; i++) { switch (type) { case Good.GoodType.Food: GovtInventory.AddGood(ServiceLocator.Instance.food); if (i + 1 >= numToAdd) { break; } i++; PeoplesInventory.AddGood(ServiceLocator.Instance.food); break; case Good.GoodType.Drugs: GovtInventory.AddGood(ServiceLocator.Instance.drugs); if (i + 1 >= numToAdd) { break; } i++; PeoplesInventory.AddGood(ServiceLocator.Instance.drugs); break; case Good.GoodType.Exotics: GovtInventory.AddGood(ServiceLocator.Instance.exotics); if (i + 1 >= numToAdd) { break; } i++; PeoplesInventory.AddGood(ServiceLocator.Instance.exotics); break; case Good.GoodType.Fuel: GovtInventory.AddGood(ServiceLocator.Instance.fuel); if (i + 1 >= numToAdd) { break; } i++; PeoplesInventory.AddGood(ServiceLocator.Instance.fuel); break; case Good.GoodType.Ideas: GovtInventory.AddGood(ServiceLocator.Instance.ideas); if (i + 1 >= numToAdd) { break; } i++; PeoplesInventory.AddGood(ServiceLocator.Instance.ideas); break; case Good.GoodType.Medicine: GovtInventory.AddGood(ServiceLocator.Instance.medicine); if (i + 1 >= numToAdd) { break; } i++; PeoplesInventory.AddGood(ServiceLocator.Instance.medicine); break; case Good.GoodType.Textiles: GovtInventory.AddGood(ServiceLocator.Instance.textiles); if (i + 1 >= numToAdd) { break; } i++; PeoplesInventory.AddGood(ServiceLocator.Instance.textiles); break; case Good.GoodType.Water: GovtInventory.AddGood(ServiceLocator.Instance.water); if (i + 1 >= numToAdd) { break; } i++; PeoplesInventory.AddGood(ServiceLocator.Instance.water); break; case Good.GoodType.Weapons: GovtInventory.AddGood(ServiceLocator.Instance.weapons); if (i + 1 >= numToAdd) { break; } i++; PeoplesInventory.AddGood(ServiceLocator.Instance.weapons); break; default: break; } } } } }