/// <summary> /// returns excess lodgers /// </summary> private int AddLodgers(byte x) { if (x == 0 || lodgersCount == MAX_LODGERS_COUNT) { return(0); } else { int v = lodgersCount + x, excess; if (v > MAX_LODGERS_COUNT) { x = (byte)(MAX_LODGERS_COUNT - lodgersCount); lodgersCount = MAX_LODGERS_COUNT; excess = v - MAX_LODGERS_COUNT; } else { lodgersCount += x; excess = 0; } colony.AddCitizens(x, false); return(excess); } }
public void HandleShip(Dock d, Ship s, ColonyController colony) { int peopleBefore = immigrationPlan; float efficientcy = (float)d.workersCount / (float)d.maxWorkers; float tradeVolume = s.volume * (0.05f + 0.95f * efficientcy); float rewardValue = 1f; var storage = colony.storage; switch (s.type) { case ShipType.Passenger: { float vol = s.volume * (Random.value * 0.5f * colony.happinessCoefficient + 0.5f); if (immigrationEnabled && immigrationPlan > 0) { if (vol > immigrationPlan) { colony.AddCitizens(immigrationPlan, true); immigrationPlan = 0; vol -= immigrationPlan; } else { int x = (int)vol; colony.AddCitizens(x, true); immigrationPlan -= x; vol = 0; } } else { vol = 0f; if (Random.value < colony.happinessCoefficient * 0.25f) { int x = (int)(Random.value * colony.hq.level); if (x != 0) { colony.AddCitizens(x, true); } } } if (vol > 0) { vol *= colony.happinessCoefficient; if (vol > 1f) { Hotel.DistributeLodgers((int)vol); } rewardValue += 0.5f; } if (isForSale[ResourceType.FOOD_ID] != null) { if (isForSale[ResourceType.FOOD_ID] == true) { d.SellResource(ResourceType.Food, s.volume * 0.1f); } else { d.BuyResource(ResourceType.Food, s.volume * 0.1f); } rewardValue += 0.3f * Random.value; } break; } case ShipType.Cargo: { int totalPositions = 0; List <int> buyPositions = new List <int>(), sellPositions = new List <int>(); for (int i = 0; i < ResourceType.TYPES_COUNT; i++) { if (isForSale[i] == null) { continue; } if (isForSale[i] == true) // продаваемый островом ресурс { if (storage.GetResourceCount(i) > minValueForTrading[i]) { sellPositions.Add(i); totalPositions++; } } else // покупаемый островом ресурс { if (storage.GetResourceCount(i) <= minValueForTrading[i]) { buyPositions.Add(i); totalPositions++; } } } float pc = tradeVolume * 1f / (float)totalPositions; float v, a; if (buyPositions.Count > 0) { foreach (int id in buyPositions) { v = pc * (0.9f + 0.2f * Random.value); a = storage.GetResourceCount(id); if (a + v > minValueForTrading[id]) { v = minValueForTrading[id] - a; } if (v > 0) { d.BuyResource(ResourceType.GetResourceTypeById(id), v); rewardValue += 0.2f; } } } else { rewardValue += 0.1f; } if (sellPositions.Count > 0) { foreach (int id in sellPositions) { v = pc * (0.9f + 0.2f * Random.value); a = storage.GetResourceCount(id); if (a - v <= minValueForTrading[id]) { v = a - minValueForTrading[id]; } if (v > 0) { d.SellResource(ResourceType.GetResourceTypeById(id), v); rewardValue += 0.2f; } } } else { rewardValue += 0.1f; } if (d.ID != Structure.DOCK_ID) { if (d.ID == Structure.DOCK_2_ID) { rewardValue *= 2f; } else { if (d.ID == Structure.DOCK_3_ID) { rewardValue *= 3f; } } } break; } case ShipType.Military: { rewardValue += 1f; if (GameMaster.realMaster.warProximity < 0.5f && Random.value < 0.1f && immigrationPlan > 0) { int veterans = (int)(s.volume * 0.02f); if (veterans > immigrationPlan) { veterans = immigrationPlan; } colony.AddCitizens(veterans, true); } if (isForSale[ResourceType.FUEL_ID] == true) { float tv = (float)(tradeVolume * 0.5f * (Random.value * 0.5f + 0.5f)); if (tv != 0) { d.SellResource(ResourceType.Fuel, tv); } } ; if (GameMaster.realMaster.warProximity > 0.5f) { if (isForSale[ResourceType.METAL_S_ID] == true) { d.SellResource(ResourceType.metal_S, s.volume * 0.1f); } if (isForSale[ResourceType.METAL_K_ID] == true) { d.SellResource(ResourceType.metal_K, s.volume * 0.05f); } if (isForSale[ResourceType.METAL_M_ID] == true) { d.SellResource(ResourceType.metal_M, s.volume * 0.1f); } } break; } case ShipType.Private: rewardValue += 0.1f; if (isForSale[ResourceType.FUEL_ID] == true) { d.SellResource(ResourceType.Fuel, (float)(tradeVolume * 0.8f)); } if (isForSale[ResourceType.FOOD_ID] == true) { d.SellResource(ResourceType.Fuel, (float)(tradeVolume * 0.15f)); } break; } int newPeople = peopleBefore - immigrationPlan; if (newPeople != 0) { if (newPeople > 0) { AnnouncementCanvasController.MakeAnnouncement(Localization.GetPhrase(LocalizedPhrase.ColonistsArrived) + " (" + newPeople.ToString() + ')'); immigrantsArrived += (uint)newPeople; Knowledge.GetCurrent()?.ImmigrantsCheck(immigrantsArrived); } else { emigrantsGone += (uint)(newPeople * (-1)); } } rewardValue += d.workersCount * 0.1f; colony.AddEnergyCrystals(rewardValue * GameConstants.PER_DOCKED_SHIP_BASIC_REWARD * GameMaster.realMaster.GetDifficultyCoefficient()); }
public void ShipLoading(Ship s) { if (loadingShip == null) { loadingTimer = LOADING_TIME; loadingShip = s; return; } int peopleBefore = immigrationPlan; switch (s.type) { case ShipType.Passenger: if (immigrationPlan > 0) { if (s.volume > immigrationPlan) { GameMaster.colonyController.AddCitizens(immigrationPlan); immigrationPlan = 0; } else { GameMaster.colonyController.AddCitizens(s.volume); immigrationPlan -= s.volume; } } if (isForSale[ResourceType.FOOD_ID] != null) { if (isForSale[ResourceType.FOOD_ID] == true) { SellResource(ResourceType.Food, s.volume * 0.1f); } else { BuyResource(ResourceType.Food, s.volume * 0.1f); } } break; case ShipType.Cargo: float totalDemand = 0; List <int> buyPositions = new List <int>(); for (int i = 0; i < ResourceType.RTYPES_COUNT; i++) { if (isForSale[i] == null) { continue; } if (isForSale[i] == true) { totalDemand += ResourceType.demand[i]; } else { if (colony.storage.standartResources[i] <= minValueForTrading[i]) { buyPositions.Add(i); } } } if (totalDemand > 0) { float demandPiece = 1 / totalDemand; for (int i = 0; i < ResourceType.RTYPES_COUNT; i++) { if (isForSale[i] == true) { SellResource(ResourceType.resourceTypesArray[i], ResourceType.demand[i] * demandPiece * s.volume); } } } if (buyPositions.Count > 0) { float v = s.volume; while (v > 0 && buyPositions.Count > 0) { int buyIndex = (int)(Random.value * buyPositions.Count - 1); // index in index arrays int i = buyPositions[buyIndex]; // real index float buyVolume = minValueForTrading[i] - colony.storage.standartResources[i]; if (buyVolume < 0) { buyVolume = 0; } if (v < buyVolume) { buyVolume = v; } BuyResource(ResourceType.resourceTypesArray[i], buyVolume); v -= buyVolume; buyPositions.RemoveAt(buyIndex); } } break; case ShipType.Military: if (GameMaster.warProximity < 0.5f && Random.value < 0.1f && immigrationPlan > 0) { int veterans = (int)(s.volume * 0.02f); if (veterans > immigrationPlan) { veterans = immigrationPlan; } colony.AddCitizens(veterans); } if (isForSale[ResourceType.FUEL_ID] == true) { SellResource(ResourceType.Fuel, s.volume * 0.5f * (Random.value * 0.5f + 0.5f)); } if (GameMaster.warProximity > 0.5f) { if (isForSale[ResourceType.METAL_S_ID] == true) { SellResource(ResourceType.metal_S, s.volume * 0.1f); } if (isForSale[ResourceType.METAL_K_ID] == true) { SellResource(ResourceType.metal_K, s.volume * 0.05f); } if (isForSale[ResourceType.METAL_M_ID] == true) { SellResource(ResourceType.metal_M, s.volume * 0.1f); } } break; case ShipType.Private: if (isForSale[ResourceType.FUEL_ID] == true) { SellResource(ResourceType.Fuel, s.volume * 0.8f); } if (isForSale[ResourceType.FOOD_ID] == true) { SellResource(ResourceType.Fuel, s.volume * 0.15f); } break; } loadingShip = null; maintainingShip = false; s.Undock(); shipArrivingTimer = SHIP_ARRIVING_TIME * GameMaster.tradeVesselsTrafficCoefficient * (1 - (colony.docksLevel * 2 / 100f)); float f = 1; if (colony.docks.Count != 0) { f /= (float)colony.docks.Count; } if (f < 0.1f) { f = 0.1f; } shipArrivingTimer /= f; int newPeople = peopleBefore - immigrationPlan; if (newPeople > 0) { UIController.current.MakeAnnouncement(Localization.GetPhrase(LocalizedPhrase.ColonistsArrived) + " (" + newPeople.ToString() + ')'); } }
public void HandleShip(Dock d, Ship s, ColonyController colony) { int peopleBefore = immigrationPlan; float efficientcy = (float)d.workersCount / (float)d.maxWorkers; float tradeVolume = s.volume * (0.05f + 0.95f * efficientcy); switch (s.type) { case ShipType.Passenger: { float vol = s.volume * (Random.value * 0.5f * colony.happiness_coefficient + 0.5f); if (immigrationPlan > 0) { if (vol > immigrationPlan) { colony.AddCitizens(immigrationPlan); immigrationPlan = 0; vol -= immigrationPlan; } else { int x = (int)vol; colony.AddCitizens(x); immigrationPlan -= x; vol = 0; } } if (vol > 0) { vol *= colony.happiness_coefficient; if (vol > 1f) { Hotel.DistributeLodgers((int)vol); } } if (isForSale[ResourceType.FOOD_ID] != null) { if (isForSale[ResourceType.FOOD_ID] == true) { d.SellResource(ResourceType.Food, s.volume * 0.1f); } else { d.BuyResource(ResourceType.Food, s.volume * 0.1f); } } break; } case ShipType.Cargo: { float buyPrioritiesPool = 0, sellPrioritiesPool = 0; List <int> buyPositions = new List <int>(), sellPositions = new List <int>(); var storage = colony.storage.standartResources; float[] demands = ResourceType.demand; for (int i = 0; i < ResourceType.TYPES_COUNT; i++) { if (isForSale[i] == null) { continue; } if (isForSale[i] == true) // продаваемый островом ресурс { if (storage[i] > minValueForTrading[i]) { sellPositions.Add(i); sellPrioritiesPool += demands[i]; } } else // покупаемый островом ресурс { if (storage[i] <= minValueForTrading[i]) { buyPositions.Add(i); buyPrioritiesPool += demands[i]; } } } if (buyPositions.Count > 0) { float boughtVolume = 0; foreach (int id in buyPositions) { float v = demands[id] / buyPrioritiesPool * tradeVolume; if (storage[id] + v > minValueForTrading[id]) { v = minValueForTrading[id] - storage[id]; } if (v != 0) { boughtVolume += d.BuyResource(ResourceType.GetResourceTypeById(id), v); } } tradeVolume += boughtVolume; } if (sellPositions.Count > 0) { foreach (int id in sellPositions) { double v = demands[id] / buyPrioritiesPool * tradeVolume; if (storage[id] - v < minValueForTrading[id]) { v = storage[id] - minValueForTrading[id]; } float v2 = (float)(demands[id] / sellPrioritiesPool * tradeVolume); if (v2 != 0) { d.SellResource(ResourceType.GetResourceTypeById(id), v2); } } } break; } case ShipType.Military: { if (GameMaster.realMaster.warProximity < 0.5f && Random.value < 0.1f && immigrationPlan > 0) { int veterans = (int)(s.volume * 0.02f); if (veterans > immigrationPlan) { veterans = immigrationPlan; } colony.AddCitizens(veterans); } if (isForSale[ResourceType.FUEL_ID] == true) { float tv = (float)(tradeVolume * 0.5f * (Random.value * 0.5f + 0.5f)); if (tv != 0) { d.SellResource(ResourceType.Fuel, tv); } } ; if (GameMaster.realMaster.warProximity > 0.5f) { if (isForSale[ResourceType.METAL_S_ID] == true) { d.SellResource(ResourceType.metal_S, s.volume * 0.1f); } if (isForSale[ResourceType.METAL_K_ID] == true) { d.SellResource(ResourceType.metal_K, s.volume * 0.05f); } if (isForSale[ResourceType.METAL_M_ID] == true) { d.SellResource(ResourceType.metal_M, s.volume * 0.1f); } } break; } case ShipType.Private: if (isForSale[ResourceType.FUEL_ID] == true) { d.SellResource(ResourceType.Fuel, (float)(tradeVolume * 0.8f)); } if (isForSale[ResourceType.FOOD_ID] == true) { d.SellResource(ResourceType.Fuel, (float)(tradeVolume * 0.15f)); } break; } int newPeople = peopleBefore - immigrationPlan; if (newPeople != 0) { if (newPeople > 0) { GameLogUI.MakeAnnouncement(Localization.GetPhrase(LocalizedPhrase.ColonistsArrived) + " (" + newPeople.ToString() + ')'); immigrantsArrived += (uint)newPeople; Knowledge.GetCurrent()?.ImmigrantsCheck(immigrantsArrived); } else { emigrantsGone += (uint)(newPeople * (-1)); } } }