# HG changeset patch # User alys # Date 2021-02-06 01:39:05 # Node ID ce6ae9b53a3fa248e6ec24eff73b275ccbd4190c # Parent 9969dbe66c2aef32a37f43d3585a4261bf964275 Some refactoring. diff --git a/isometric-park-fna/FNAGame.cs b/isometric-park-fna/FNAGame.cs --- a/isometric-park-fna/FNAGame.cs +++ b/isometric-park-fna/FNAGame.cs @@ -124,7 +124,7 @@ { if (this.random_generator.NextDouble() > 0.75) { - int random_year = (int)MathHelper.Clamp((float)MathUtils.NextNormal(random_generator, 2010.0f, 40.0f), 1800, 2020); + int random_year = (int)MathHelper.Clamp((float)MathUtils.NextNormal(random_generator, 2010.0f, 40.0f), 1800, Simulation.START_YEAR); int random_month = random_generator.Next(1, 12); DateTime random_date = new DateTime(random_year, random_month, 1); @@ -145,9 +145,6 @@ currentNode = DialogTrees.introTree; - - - } protected override void Initialize() 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 @@ -37,6 +37,11 @@ public const int START_MONTH = 1; public const int START_DAY = 1; + public DateTime START_DATETIME{ + get { + return new DateTime(START_YEAR, START_MONTH, START_DAY); + }} + private const float SPONTANEOUS_NEW_TREE_CHANCE = 0.9995f; private const float NEIGHBOR_NEW_TREE_CHANCE = 0.995f; @@ -45,6 +50,9 @@ public const int TREE_PLANT_COST = 750; public const int TREE_CLEAR_COST = 500; + public const int MAX_TREES_TO_PLANT = 25; + public const int MAX_TREES_TO_CLEAR = 25; + public int Tick { get; @@ -139,7 +147,7 @@ return _tree_planting; } set { - _tree_planting = MathUtils.Clamp(value, 0, 25); + _tree_planting = MathUtils.Clamp(value, 0, MAX_TREES_TO_PLANT); } } private int _tree_clearing = 0; @@ -149,7 +157,7 @@ return _tree_clearing; } set { - _tree_clearing = MathUtils.Clamp(value, 0, 25); + _tree_clearing = MathUtils.Clamp(value, 0, MAX_TREES_TO_CLEAR); } } diff --git a/isometric-park-fna/UI/ForestWindow.cs b/isometric-park-fna/UI/ForestWindow.cs --- a/isometric-park-fna/UI/ForestWindow.cs +++ b/isometric-park-fna/UI/ForestWindow.cs @@ -34,11 +34,11 @@ int new_tree_planting = sim.tree_planting; - ImGui.SliderInt("Tree Planting ", ref new_tree_planting, 0, 25, string.Format("%d (${0})", new_tree_planting*Simulation.TREE_PLANT_COST)); + ImGui.SliderInt("Tree Planting ", ref new_tree_planting, 0, Simulation.MAX_TREES_TO_PLANT, string.Format("%d (${0})", new_tree_planting*Simulation.TREE_PLANT_COST)); sim.tree_planting = new_tree_planting; int new_tree_clearing = sim.tree_clearing; - ImGui.SliderInt("Tree Clearing", ref new_tree_clearing, 0, 25, string.Format("%d (${0})", new_tree_clearing*Simulation.TREE_CLEAR_COST)); + ImGui.SliderInt("Tree Clearing", ref new_tree_clearing, 0, Simulation.MAX_TREES_TO_CLEAR, string.Format("%d (${0})", new_tree_clearing*Simulation.TREE_CLEAR_COST)); sim.tree_clearing = new_tree_clearing; ImGui.Text(string.Format("Crowded Trees: {0}", sim.crowded_trees )); diff --git a/isometric-park-fna/Utils/MathUtils.cs b/isometric-park-fna/Utils/MathUtils.cs --- a/isometric-park-fna/Utils/MathUtils.cs +++ b/isometric-park-fna/Utils/MathUtils.cs @@ -60,7 +60,7 @@ } - public static System.Collections.Generic.IEnumerable NextNormalEnumerator(Random random, float mean) + public static System.Collections.Generic.IEnumerable NextNormalEnumerator(Random random, float mean, float variation) { while (true) { @@ -70,13 +70,14 @@ double z1 = Math.Sqrt(-2 * Math.Log(u1)) * Math.Cos(2 * Math.PI * u2); double z2 = Math.Sqrt(-2 * Math.Log(u1)) * Math.Sin(2 * Math.PI * u2); - yield return z1; - yield return z2; + yield return (variation * z1) + mean; + yield return (variation * z2) + mean; } } public static Double NextNormal(Random random, float mean, float variation) { + //Uses Box-Muller to scale the default uniform distribution double u1 = random.NextDouble(); double u2 = random.NextDouble();