# HG changeset patch # User Alys Brooks # Date 2022-02-20 09:29:39 # Node ID f1b00533ab6a24e6bb1ff1c1d6e2a93a065e2fa5 # Parent bc25da6405438f3b69ffffe986822df103c41eb4 Spawn trees differently in preserves. diff --git a/isometric-park-fna/Engines/SimulationBridgeEngine.cs b/isometric-park-fna/Engines/SimulationBridgeEngine.cs --- a/isometric-park-fna/Engines/SimulationBridgeEngine.cs +++ b/isometric-park-fna/Engines/SimulationBridgeEngine.cs @@ -17,7 +17,8 @@ typeof(BudgetComponent), typeof(BudgetLineComponent), typeof(ContractStatusComponent), - typeof(TreeDeltaComponent))] + typeof(TreeDeltaComponent), + typeof(PreserveComponent))] [Writes(typeof(BudgetComponent))] public class SimulationBridgeEngine : Engine { @@ -68,6 +69,18 @@ decimal new_enforcement_amount = 0M; decimal new_misc_amount = 0M; // decimal new_upkeep_amount = 0M; + + this.simulation.PreserveCells.Clear(); + + foreach (ref readonly var entity in ReadEntities()) { + ref readonly var areaComponent = ref GetComponent(entity); + + foreach (var square in areaComponent.squares) { + this.simulation.PreserveCells.Add(this.simulation.map.cells[(int)square.X][(int)square.Y]); + } + + + } foreach (ref readonly var entity in ReadEntities()) { diff --git a/isometric-park-fna/Engines/Spawners/ContractSpawner.cs b/isometric-park-fna/Engines/Spawners/ContractSpawner.cs --- a/isometric-park-fna/Engines/Spawners/ContractSpawner.cs +++ b/isometric-park-fna/Engines/Spawners/ContractSpawner.cs @@ -129,7 +129,9 @@ Logging.Debug(String.Format("Creating contract {0} without organizations.", message.name )); } - foreach (var (entity, status) in ReadEntities().SelectWhereF((e) => (e, GetComponent(e)), (e) => ((e.Item2.status != ContractStatus.Broken) && (e.Item2.status != ContractStatus.Rejected) && (e.Item2.status != ContractStatus.Expired)))) { + foreach (var (entity, status) in ReadEntities() + .WhereF((e) => HasComponent(e)) + .SelectWhereF((e) => (e, GetComponent(e)), (e) => ((e.Item2.status != ContractStatus.Broken) && (e.Item2.status != ContractStatus.Rejected) && (e.Item2.status != ContractStatus.Expired)))) { var entitySquares = GetComponent(entity).squares; occupied.AddRange(entitySquares); } 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 @@ -60,6 +60,10 @@ private const float NEIGHBOR_NEW_TREE_CHANCE = 0.995f; private const float NEIGHBOR_CROWDS_TREE_CHANCE = 0.995f; + private const float PRESERVE_SPONTANEOUS_NEW_TREE_CHANCE = 0.995f; + private const float PRESERVE_NEIGHBOR_NEW_TREE_CHANCE = 0.995f; + private const float PRESERVE_NEIGHBOR_CROWDS_TREE_CHANCE = 0.9995f; + public const int TREE_PLANT_COST = 500; public const int TREE_CLEAR_COST = 250; @@ -172,6 +176,8 @@ public CellMap map; + public HashSet PreserveCells; + public int ticksPerAdvance; private float lastAdvance; public bool paused; @@ -254,6 +260,8 @@ this.budgets = new List(); this.BridgeEngine = new SimulationBridgeEngine(this); + + this.PreserveCells = new HashSet(); } private void advanceSimulation() @@ -268,7 +276,7 @@ foreach (Cell cell in this.map.iterate_cells()) { - if (random.NextDouble() > SPONTANEOUS_NEW_TREE_CHANCE) + if (random.NextDouble() > (this.PreserveCells.Contains(cell) ? PRESERVE_SPONTANEOUS_NEW_TREE_CHANCE : SPONTANEOUS_NEW_TREE_CHANCE )) { var random_type = random.Next(0, 4); cell.AddTree(this.DateTime, (TreeType)random_type); @@ -281,7 +289,7 @@ var neighbor = this.map.iterate_neighbors(x, y).First(); var cell = this.map.cells[x][y]; - if (random.NextDouble() > NEIGHBOR_NEW_TREE_CHANCE) + if (random.NextDouble() > (this.PreserveCells.Contains(cell) ? PRESERVE_NEIGHBOR_NEW_TREE_CHANCE : NEIGHBOR_NEW_TREE_CHANCE )) { var random_type = random.Next(0, 4); cell.AddTree(this.DateTime, neighbor.Type); @@ -292,7 +300,7 @@ int crowded_out = 0; foreach (Cell cell in this.map.iterate_cells_with_neighbors(7)) { - if (random.NextDouble() > NEIGHBOR_CROWDS_TREE_CHANCE) + if (random.NextDouble() > (this.PreserveCells.Contains(cell) ? PRESERVE_NEIGHBOR_CROWDS_TREE_CHANCE : NEIGHBOR_CROWDS_TREE_CHANCE ) ) { cell.MarkTreeDead(); crowded_out += 1;