Skip to content

Commit

Permalink
fix: Handle capacity=0 leading to NaN pop growth
Browse files Browse the repository at this point in the history
  • Loading branch information
Clashsoft committed Jun 16, 2024
1 parent 683e70f commit b0698cb
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/game-logic/game-logic.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@ export class GameLogicService {

private popGrowth(system: SystemDocument, variables: Record<Variable, number>, aggregates?: Partial<Record<ResourceName, AggregateResult>>) {
const {population, capacity} = system;
if (!capacity) {
// Growth calculation will yield NaN. This is probably an uninhabitable system, so just do nothing.
return;
}
const growthVariable: Variable = `systems.${system.upgrade}.pop_growth`;
const growthRate = variables[growthVariable];
const growth = growthRate * population * Math.clamp(1 - population / capacity, 0, 1); // logistic growth
Expand Down

0 comments on commit b0698cb

Please sign in to comment.