# HG changeset patch # User Alys Brooks # Date 2022-03-14 06:13:25 # Node ID b60c04fb0618b1ddcdfe0f61ed46f963abe65378 # Parent da13ec49a1f1d531c6569546b9e53b9b5d2f93b5 Scale tree planting based on preserve. diff --git a/isometric-park-fna/Simulation.cs b/isometric-park-fna/Simulation.cs --- a/isometric-park-fna/Simulation.cs +++ b/isometric-park-fna/Simulation.cs @@ -266,6 +266,14 @@ this.PreserveCounts = new int[this.map.MapWidth, this.map.MapHeight]; } + private double interpolate(double percent, double start, double end) { + var low = Math.Min(start, end); + var high = Math.Max(start, end); + var range = high - low; + + return range * percent + low; + } + private void advanceSimulation() { var oldSeason = this.Season; @@ -282,7 +290,8 @@ for(int j = 0; j < this.map.MapHeight; j++) { var cell = this.map.cells[i][j]; - if (random.NextDouble() > (this.PreserveCounts[i, j] > 0 ? PRESERVE_SPONTANEOUS_NEW_TREE_CHANCE : SPONTANEOUS_NEW_TREE_CHANCE )) + var rate = interpolate((8 - (double)this.PreserveCounts[i, j] / 8.0d, PRESERVE_SPONTANEOUS_NEW_TREE_CHANCE, SPONTANEOUS_NEW_TREE_CHANCE); + if (random.NextDouble() > rate) { var random_type = random.Next(0, 4); cell.AddTree(this.DateTime, (TreeType)random_type);