From fa90b4f0b3c2cc56a9132bbc1d53e1e9599c6e38 Mon Sep 17 00:00:00 2001 From: Ed Kolis Date: Sun, 19 Mar 2023 12:48:00 -0400 Subject: [PATCH] 207 planetary pops wind up in cargo (#267) * Don't put population in planetary cargo; planets have their own population storage and it's confusing to use both * Don't let population be eradicated during cargo transfers if there is nowhere to store it on the destination --- FrEee/Game/Objects/Space/Planet.cs | 13 +++++++++++-- FrEee/Utility/Extensions/CommonExtensions.cs | 5 ++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/FrEee/Game/Objects/Space/Planet.cs b/FrEee/Game/Objects/Space/Planet.cs index 02e3ecc6..d7f4143c 100644 --- a/FrEee/Game/Objects/Space/Planet.cs +++ b/FrEee/Game/Objects/Space/Planet.cs @@ -604,16 +604,25 @@ public void AddOrder(IOrder order) public long AddPopulation(Race race, long amount) { + // make sure planet has a colony if (Colony == null) return amount; // can't add population with no colony + + // put population in planetary population storage var canPop = Math.Min(amount, PopulationStorageFree); amount -= canPop; Colony.Population[race] += canPop; - var canCargo = Math.Min(amount, (long)(this.CargoStorageFree() / Mod.Current.Settings.PopulationSize)); + + // don't put population in planetary cargo storage, that's just confusing + /*var canCargo = Math.Min(amount, (long)(this.CargoStorageFree() / Mod.Current.Settings.PopulationSize)); amount -= canCargo; - Colony.Cargo.Population[race] += canCargo; + Colony.Cargo.Population[race] += canCargo;*/ + + // apply anger to population if (!Colony.Anger.ContainsKey(race)) Colony.Anger[race] = Mod.Current.Settings.StartPopulationAnger; + + // return leftover population return amount; } diff --git a/FrEee/Utility/Extensions/CommonExtensions.cs b/FrEee/Utility/Extensions/CommonExtensions.cs index 48790aa9..c25a36fb 100644 --- a/FrEee/Utility/Extensions/CommonExtensions.cs +++ b/FrEee/Utility/Extensions/CommonExtensions.cs @@ -1642,7 +1642,10 @@ public static void TransferCargo(this ICargoContainer src, CargoDelta delta, ICa // transfer population from source to destination amount -= src.RemovePopulation(kvp.Key, amount); - dest.AddPopulation(kvp.Key, amount); + amount += dest.AddPopulation(kvp.Key, amount); + + // put any population that didn't fit back on the source + src.AddPopulation(kvp.Key, amount); // log warnings if (amount < anyPopLeft)