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 @@ -344,21 +344,16 @@ this.showBudget = !this.showBudget; } + if (keyboardCur.IsKeyDown(Keys.F) && keyboardPrev.IsKeyUp(Keys.F)) + { + this.showForest = !this.showForest; + + } if (keyboardCur.IsKeyDown(Keys.C) && keyboardPrev.IsKeyUp(Keys.C)) { this.camera.Jump(Vector2.Zero); } - if (keyboardCur.IsKeyDown(Keys.O) && keyboardPrev.IsKeyUp(Keys.O)) - { - this.simulation.tree_planting -= 1; - - } - if (keyboardCur.IsKeyDown(Keys.P) && keyboardPrev.IsKeyUp(Keys.P)) - { - this.simulation.tree_planting += 1; - - } if (keyboardCur.IsKeyDown(Keys.OemBackslash) && keyboardPrev.IsKeyUp(Keys.OemBackslash) && keyboardCur.IsKeyDown(Keys.LeftShift)) { sound.Play(volume, pitch, pan); @@ -832,7 +827,10 @@ ref this.simulation.paused, debugWindow.monoFont, this.currentNode); } - ForestWindow.Render(ref this.showForest, debugWindow.monoFont, this.simulation); + if (this.showForest) + { + ForestWindow.Render(ref this.showForest, debugWindow.monoFont, this.simulation); + } _imGuiRenderer.AfterLayout(); 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 @@ -42,8 +42,8 @@ private const float NEIGHBOR_NEW_TREE_CHANCE = 0.995f; private const float NEIGHBOR_CROWDS_TREE_CHANCE = 0.995f; - public const int TREE_PLANT_COST = 1000; - public const int TREE_CLEAR_COST = 750; + public const int TREE_PLANT_COST = 750; + public const int TREE_CLEAR_COST = 500; public int Tick { @@ -142,7 +142,7 @@ _tree_planting = MathUtils.Clamp(value, 0, 25); } } - public int _tree_clearing = 5; + public int _tree_clearing = 0; public int tree_clearing { get { @@ -153,10 +153,18 @@ } } + public int crowded_trees + { + get { + return this.map.iterate_cells_with_neighbors(7).Where(c => c.hasTree).Count(); + + } + } + public float healthy_percent { get { - return ((float)(this.map.tree_count - this.map.iterate_cells_with_neighbors(7).Count()) / this.map.tree_count) * 100; + return (float)(this.map.tree_count - this.map.iterate_cells_with_neighbors(7).Where(c => c.hasTree).Count()) / this.map.tree_count * 100; } } @@ -182,6 +190,7 @@ this.DateTime = this.DateTime.AddMonths(1); + foreach (Cell cell in this.map.iterate_cells()) { if (random.NextDouble() > SPONTANEOUS_NEW_TREE_CHANCE) @@ -190,21 +199,27 @@ } } + int new_planted = 0; foreach (Cell cell in this.map.iterate_cells_with_neighbors(4)) { if (random.NextDouble() > NEIGHBOR_NEW_TREE_CHANCE) { cell.hasTree = true; + new_planted += 1; } } + System.Console.WriteLine(String.Format("New {0}", new_planted)); + int crowded_out = 0; foreach (Cell cell in this.map.iterate_cells_with_neighbors(7)) { if (random.NextDouble() > NEIGHBOR_CROWDS_TREE_CHANCE) { cell.hasTree = false; + crowded_out += 1; } } + System.Console.Write(String.Format("Crowded {0}", crowded_out)); int trees_to_plant = this.tree_planting; @@ -219,22 +234,18 @@ } } + + // while (trees_to_clear > 0 && neigh.Current != null) int trees_to_clear = this.tree_clearing; - - IEnumerator neigh = this.map.iterate_cells_with_neighbors(7).GetEnumerator(); - neigh.MoveNext(); - - while (trees_to_clear > 0 && neigh.Current != null) + System.Console.Write(String.Format("Found {0}; ", this.map.iterate_cells_with_neighbors(7).Where(c => c.hasTree).Count())); + foreach (Cell cell in this.map.iterate_cells_with_neighbors(7).Where(c => c.hasTree)) { - Cell current = neigh.Current; - current.hasTree = false; - neigh.MoveNext(); - trees_to_clear -= 1; + if (trees_to_clear > 0) { + cell.hasTree = false; + trees_to_clear -= 1; + } } - //this.money -= (this.map.tree_count * 1); - //this.money += 1000; - Budget newBudget = new Budget { DateTime = this.DateTime, 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 @@ -1,7 +1,6 @@ using ImGuiNET; using Num = System.Numerics; -using System.Linq; namespace isometricparkfna.UI { @@ -42,7 +41,7 @@ ImGui.SliderInt("Tree Clearing", ref new_tree_clearing, 0, 25, 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.map.iterate_cells_with_neighbors(7).Count())); //via LINQ + ImGui.Text(string.Format("Crowded Trees: {0}", sim.crowded_trees )); ImGui.Text(string.Format("Percent Healthy Trees: {0:F2}", sim.healthy_percent)); if (ImGui.Button("Okay"))