# HG changeset patch # User Alys Brooks # Date 2022-02-05 10:13:36 # Node ID 6b7b45b604e5fae349b7bd6c5286ed954957ed7f # Parent 5885087ddbe1630366b9a575b4e907c8d7eab4f6 Spawn trees of similar type to neighbors. diff --git a/isometric-park-fna/CellMap.cs b/isometric-park-fna/CellMap.cs --- a/isometric-park-fna/CellMap.cs +++ b/isometric-park-fna/CellMap.cs @@ -113,7 +113,7 @@ return MathUtils.BetweenExclusive(x, 0, MapWidth - 1) && MathUtils.BetweenExclusive(y, 0, MapHeight - 1); } - private System.Collections.Generic.IEnumerable iterate_neighbors(int x, int y) + public System.Collections.Generic.IEnumerable iterate_neighbors(int x, int y) { //iterates over neighbors (clockwise starting at noon/midnight) if (inBounds(x, y + 1)) @@ -176,8 +176,21 @@ } } } + } - + public System.Collections.Generic.IEnumerable<(int, int)> iterate_cell_locations_with_neighbors(int neighbors) + { + for (int i = 0; i < MapHeight; i++) + { + List newRow = new List(); + for (int j = 0; j < MapWidth; j++) + { + if (this.countNeighbors(i, j) >= neighbors) + { + yield return (i, j); + } + } + } } public enum CellStatus { diff --git a/isometric-park-fna/Engines/Spawners/GameSpawner.cs b/isometric-park-fna/Engines/Spawners/GameSpawner.cs --- a/isometric-park-fna/Engines/Spawners/GameSpawner.cs +++ b/isometric-park-fna/Engines/Spawners/GameSpawner.cs @@ -125,14 +125,14 @@ #endregion this.simulation.Subsidy = message.Difficulty switch { DifficultyLevel.Hard => 0M, - DifficultyLevel.Medium => 760M, - DifficultyLevel.Easy => 1000M, + DifficultyLevel.Medium => 12_550M, + DifficultyLevel.Easy => 15_000M, _ => 1000M }; this.simulation.SubsidyDelta = message.Difficulty switch { DifficultyLevel.Hard => 0M, - DifficultyLevel.Medium => -10M, + DifficultyLevel.Medium => -50M, DifficultyLevel.Easy => 0M, _ => 1000M }; 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 @@ -276,12 +276,15 @@ } int new_planted = 0; - foreach (Cell cell in this.map.iterate_cells_with_neighbors(4)) + foreach (var (x, y) in this.map.iterate_cell_locations_with_neighbors(4)) { + var neighbor = this.map.iterate_neighbors(x, y).First(); + var cell = this.map.cells[x][y]; + if (random.NextDouble() > NEIGHBOR_NEW_TREE_CHANCE) { var random_type = random.Next(0, 4); - cell.AddTree(this.DateTime, (TreeType)random_type); + cell.AddTree(this.DateTime, neighbor.Type); new_planted += 1; } }