Description:
Calculate surrounding cells for preserve.
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
@@ -70,16 +70,29 | |||||
|
70 | decimal new_misc_amount = 0M; |
|
70 | decimal new_misc_amount = 0M; |
|
71 | // decimal new_upkeep_amount = 0M; |
|
71 | // decimal new_upkeep_amount = 0M; |
|
72 |
|
72 | ||
|
73 | this.simulation.PreserveCells.Clear(); |
|
73 | // this.simulation.PreserveCells.Clear(); |
|
|
74 | |||
|
|
75 | var preserve_cells = new HashSet<isometricparkfna.CellMap.Cell>(); | ||
|
|
76 | var count = 0; | ||
|
74 |
|
77 | ||
|
75 | foreach (ref readonly var entity in ReadEntities<PreserveComponent>()) { |
|
78 | foreach (ref readonly var entity in ReadEntities<PreserveComponent>()) { |
|
76 | ref readonly var areaComponent = ref GetComponent<AreaComponent>(entity); |
|
79 | ref readonly var areaComponent = ref GetComponent<AreaComponent>(entity); |
|
77 |
|
80 | ||
|
78 | foreach (var square in areaComponent.squares) { |
|
81 | foreach (var square in areaComponent.squares) { |
|
79 |
|
|
82 | preserve_cells.Add(this.simulation.map.cells[(int)square.X][(int)square.Y]); |
|
80 | } |
|
83 | } |
|
|
84 | } | ||
|
81 |
|
85 | ||
|
82 |
|
86 | for (int i = 0; i < this.simulation.PreserveCounts.GetLength(0); i++) { | |
|
|
87 | for (int j = 0; j < this.simulation.PreserveCounts.GetLength(0); j++) { | ||
|
|
88 | count = 0; | ||
|
|
89 | foreach (var cell in this.simulation.map.iterate_neighbor_cells(i, j)) { | ||
|
|
90 | if (preserve_cells.Contains(cell)) { | ||
|
|
91 | count++; | ||
|
|
92 | } | ||
|
|
93 | } | ||
|
|
94 | this.simulation.PreserveCounts[i, j] = count; | ||
|
|
95 | } | ||
|
83 | } |
|
96 | } |
|
84 |
|
97 | ||
|
85 | foreach (ref readonly var entity in ReadEntities<BudgetLineComponent>()) |
|
98 | foreach (ref readonly var entity in ReadEntities<BudgetLineComponent>()) |
@@ -26,7 +26,7 | |||||
|
26 | public override void Render() |
|
26 | public override void Render() |
|
27 | { |
|
27 | { |
|
28 |
|
28 | ||
|
29 |
var budgetWindow = new BudgetWindow(new Budget { |
|
29 | var budgetWindow = new BudgetWindow(new Budget {}, this.font, 0, 0); |
|
30 |
|
30 | ||
|
31 | foreach (ref readonly var entity in ReadEntities<AreaComponent>()) |
|
31 | foreach (ref readonly var entity in ReadEntities<AreaComponent>()) |
|
32 | { |
|
32 | { |
@@ -176,7 +176,8 | |||||
|
176 |
|
176 | ||
|
177 | public CellMap map; |
|
177 | public CellMap map; |
|
178 |
|
178 | ||
|
179 | public HashSet<Cell> PreserveCells; |
|
179 | // public HashSet<Cell> PreserveCells; |
|
|
180 | public int[,] PreserveCounts; | ||
|
180 |
|
181 | ||
|
181 | public int ticksPerAdvance; |
|
182 | public int ticksPerAdvance; |
|
182 | private float lastAdvance; |
|
183 | private float lastAdvance; |
@@ -261,7 +262,8 | |||||
|
261 |
|
262 | ||
|
262 | this.BridgeEngine = new SimulationBridgeEngine(this); |
|
263 | this.BridgeEngine = new SimulationBridgeEngine(this); |
|
263 |
|
264 | ||
|
264 | this.PreserveCells = new HashSet<Cell>(); |
|
265 | // this.PreserveCells = new HashSet<Cell>(); |
|
|
266 | this.PreserveCounts = new int[this.map.MapWidth, this.map.MapHeight]; | ||
|
265 | } |
|
267 | } |
|
266 |
|
268 | ||
|
267 | private void advanceSimulation() |
|
269 | private void advanceSimulation() |
@@ -274,12 +276,17 | |||||
|
274 |
|
276 | ||
|
275 | this.BridgeEngine.addTick(); |
|
277 | this.BridgeEngine.addTick(); |
|
276 |
|
278 | ||
|
277 | foreach (Cell cell in this.map.iterate_cells()) |
|
279 | // foreach (Cell cell in this.map.iterate_cells()) |
|
|
280 | for(int i = 0; i < this.map.MapWidth; i++) | ||
|
278 | { |
|
281 | { |
|
279 | if (random.NextDouble() > (this.PreserveCells.Contains(cell) ? PRESERVE_SPONTANEOUS_NEW_TREE_CHANCE : SPONTANEOUS_NEW_TREE_CHANCE )) |
|
282 | for(int j = 0; j < this.map.MapHeight; j++) |
|
280 | { |
|
283 | { |
|
281 | var random_type = random.Next(0, 4); |
|
284 | var cell = this.map.cells[i][j]; |
|
282 | cell.AddTree(this.DateTime, (TreeType)random_type); |
|
285 | if (random.NextDouble() > (this.PreserveCounts[i, j] > 0 ? PRESERVE_SPONTANEOUS_NEW_TREE_CHANCE : SPONTANEOUS_NEW_TREE_CHANCE )) |
|
|
286 | { | ||
|
|
287 | var random_type = random.Next(0, 4); | ||
|
|
288 | cell.AddTree(this.DateTime, (TreeType)random_type); | ||
|
|
289 | } | ||
|
283 | } |
|
290 | } |
|
284 | } |
|
291 | } |
|
285 |
|
292 | ||
@@ -287,10 +294,10 | |||||
|
287 | foreach (var (x, y) in this.map.iterate_cell_locations_with_neighbors(4)) |
|
294 | foreach (var (x, y) in this.map.iterate_cell_locations_with_neighbors(4)) |
|
288 | { |
|
295 | { |
|
289 | var neighbor = this.map.iterate_neighbors(x, y).First(); |
|
296 | var neighbor = this.map.iterate_neighbors(x, y).First(); |
|
290 | var cell = this.map.cells[x][y]; |
|
||
|
291 |
|
297 | ||
|
292 |
if (random.NextDouble() > (this.PreserveC |
|
298 | if (random.NextDouble() > (this.PreserveCounts[x, y] > 0 ? PRESERVE_NEIGHBOR_NEW_TREE_CHANCE : NEIGHBOR_NEW_TREE_CHANCE )) |
|
293 | { |
|
299 | { |
|
|
300 | var cell = this.map.cells[x][y]; | ||
|
294 | var random_type = random.Next(0, 4); |
|
301 | var random_type = random.Next(0, 4); |
|
295 | cell.AddTree(this.DateTime, neighbor.Type); |
|
302 | cell.AddTree(this.DateTime, neighbor.Type); |
|
296 | new_planted += 1; |
|
303 | new_planted += 1; |
@@ -298,10 +305,11 | |||||
|
298 | } |
|
305 | } |
|
299 |
|
306 | ||
|
300 | int crowded_out = 0; |
|
307 | int crowded_out = 0; |
|
301 |
foreach ( |
|
308 | foreach (var (x, y) in this.map.iterate_cell_locations_with_neighbors(7)) |
|
302 | { |
|
309 | { |
|
303 |
if (random.NextDouble() > (this.PreserveC |
|
310 | if (random.NextDouble() > (this.PreserveCounts[x, y] > 0 ? PRESERVE_NEIGHBOR_CROWDS_TREE_CHANCE : NEIGHBOR_CROWDS_TREE_CHANCE ) ) |
|
304 | { |
|
311 | { |
|
|
312 | var cell = this.map.cells[x][y]; | ||
|
305 | cell.MarkTreeDead(); |
|
313 | cell.MarkTreeDead(); |
|
306 | crowded_out += 1; |
|
314 | crowded_out += 1; |
|
307 | } |
|
315 | } |
You need to be logged in to leave comments.
Login now