Skip to content

Commit

Permalink
207 planetary pops wind up in cargo (#267)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ekolis committed Mar 19, 2023
1 parent 3496eea commit fa90b4f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
13 changes: 11 additions & 2 deletions FrEee/Game/Objects/Space/Planet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
5 changes: 4 additions & 1 deletion FrEee/Utility/Extensions/CommonExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit fa90b4f

Please sign in to comment.