Description:
Update Cell to follow C# convention while I'm here.
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r522:07e6179554d0 -

@@ -75,7 +75,7
75 75 {
76 76 foreach (Cell cell in row)
77 77 {
78 if (cell.hasTree)
78 if (cell.HasTree)
79 79 {
80 80 yield return cell;
81 81 }
@@ -89,7 +89,7
89 89 {
90 90 foreach (Cell cell in row)
91 91 {
92 if (cell.hasTree)
92 if (cell.HasTree)
93 93 {
94 94 yield return cell;
95 95 }
@@ -155,7 +155,7
155 155 int count = 0;
156 156 foreach (Cell neighbor in this.iterate_neighbors(x, y))
157 157 {
158 if (neighbor.hasTree) {
158 if (neighbor.HasTree) {
159 159 count++;
160 160 }
161 161 }
@@ -193,15 +193,14
193 193
194 194 public class Cell
195 195 {
196 // public Boolean _hasTree = false;
197 public CellStatus status {
196 public CellStatus Status {
198 197 get;
199 198 private set;
200 199 }
201 200
202 201 public String StatusAdjective {
203 202 get {
204 return this.status.ToString().Replace("Tree", "");
203 return this.Status.ToString().Replace("Tree", "");
205 204 }
206 205 }
207 206
@@ -216,28 +215,28
216 215 }
217 216 }
218 217
219 public Boolean hasTree {
218 public Boolean HasTree {
220 219 get {
221 return this.status == CellStatus.LivingTree;
220 return this.Status == CellStatus.LivingTree;
222 221 }
223 222 }
224 223
225 public DateTime planted;
224 public DateTime Planted;
226 225
227 public void addTree(DateTime datetime, TreeType type) {
228 this.status = CellStatus.LivingTree;
226 public void AddTree(DateTime datetime, TreeType type) {
227 this.Status = CellStatus.LivingTree;
229 228
230 this.planted = datetime;
229 this.Planted = datetime;
231 230
232 231 this.Type = type;
233 232 }
234 233
235 public void removeTree() {
236 this.status = CellStatus.Clear;
234 public void RemoveTree() {
235 this.Status = CellStatus.Clear;
237 236 }
238 237
239 public void markTreeDead() {
240 this.status = CellStatus.DeadTree;
238 public void MarkTreeDead() {
239 this.Status = CellStatus.DeadTree;
241 240 }
242 241 }
243 242 }
@@ -151,7 +151,7
151 151 var squares = HasComponent<AreaComponent>(entity) ? GetComponent<AreaComponent>(entity).squares : this.all_squares;
152 152 var removed = 0;
153 153 var added = 0;
154 var tree_squares = squares.Where((square) => simulation.map.cells[(int)square.X][(int)square.Y].hasTree);
154 var tree_squares = squares.Where((square) => simulation.map.cells[(int)square.X][(int)square.Y].HasTree);
155 155 var to_remove = Math.Abs(delta.deltaTrees.Value);
156 156
157 157 //calculate the probability in order to get the expected number of removed trees
@@ -162,18 +162,18
162 162 foreach (var square in tree_squares)
163 163 {
164 164 var cell = simulation.map.cells[(int)square.X][(int)square.Y];
165 if (cell.hasTree
165 if (cell.HasTree
166 166 && random_generator.NextDouble() < probability)
167 167 {
168 168 if (delta.deltaTrees.Value < 0)
169 169 {
170 cell.removeTree();
170 cell.RemoveTree();
171 171 removed++;
172 172 }
173 173 else if (delta.deltaTrees.Value > 0)
174 174 {
175 175 var random_type = random_generator.Next(0, 1);
176 cell.addTree(this.simulation.DateTime, (CellMap.TreeType)random_type);
176 cell.AddTree(this.simulation.DateTime, (CellMap.TreeType)random_type);
177 177 added++;
178 178 }
179 179 }
@@ -55,7 +55,7
55 55
56 56 int random_type = random_generator.Next(0, 2);
57 57
58 cell.addTree(random_date, (TreeType)random_type);
58 cell.AddTree(random_date, (TreeType)random_type);
59 59 }
60 60 }
61 61 }
@@ -728,7 +728,7
728 728 {
729 729 for (int j = 0; j < this.simulation.map.MapWidth; j += 1)
730 730 {
731 if (this.simulation.map.cells[i][j].hasTree)
731 if (this.simulation.map.cells[i][j].HasTree)
732 732 { //until we actually simulate:
733 733 if (this.simulation.map.cells[i][j].Type == TreeType.GenericDeciduous) {
734 734 drawTileAt(i, j, 142, 2);
@@ -745,7 +745,7
745 745 // drawTileAt(i, j, 142, 2);
746 746 // }
747 747 }
748 else if (this.simulation.map.cells[i][j].status == CellStatus.DeadTree) {
748 else if (this.simulation.map.cells[i][j].Status == CellStatus.DeadTree) {
749 749 drawTileAt(i, j, 141, 2);
750 750 // System.Console.WriteLine(String.Format("Drew Dead Tree at {0},{1}", i, j));
751 751 }
@@ -777,14 +777,14
777 777 if (MathUtils.BetweenExclusive(this.mouseGrid.X, 0, this.squaresAcross)
778 778 && MathUtils.BetweenExclusive(this.mouseGrid.Y, 0, this.squaresAcross))
779 779 {
780 has_tree = this.simulation.map.cells[(int)this.mouseGrid.X][(int)this.mouseGrid.Y].hasTree;
780 has_tree = this.simulation.map.cells[(int)this.mouseGrid.X][(int)this.mouseGrid.Y].HasTree;
781 781 }
782 782
783 783 String status_left = "";
784 784 if (MathUtils.BetweenExclusive(this.mouseGrid.X, -1, this.simulation.map.MapWidth)
785 785 && MathUtils.BetweenExclusive(this.mouseGrid.Y, -1, this.simulation.map.MapHeight))
786 786 {
787 var treeStatus = this.simulation.map.cells[(int)this.mouseGrid.X][(int)this.mouseGrid.Y].status;
787 var treeStatus = this.simulation.map.cells[(int)this.mouseGrid.X][(int)this.mouseGrid.Y].Status;
788 788 var treeStatusAdjective = this.simulation.map.cells[(int)this.mouseGrid.X][(int)this.mouseGrid.Y].StatusAdjective;
789 789 var treeType = this.simulation.map.cells[(int)this.mouseGrid.X][(int)this.mouseGrid.Y].TypeName;
790 790 if (treeStatus != CellStatus.Clear)
@@ -201,7 +201,7
201 201 public int crowded_trees
202 202 {
203 203 get {
204 return this.map.iterate_cells_with_neighbors(7).Where(c => c.hasTree).Count();
204 return this.map.iterate_cells_with_neighbors(7).Where(c => c.HasTree).Count();
205 205
206 206 }
207 207 }
@@ -209,14 +209,14
209 209 public int dead_trees
210 210 {
211 211 get {
212 return this.map.iterate_cells().Where(c => (c.status == CellStatus.DeadTree)).Count();
212 return this.map.iterate_cells().Where(c => (c.Status == CellStatus.DeadTree)).Count();
213 213 }
214 214 }
215 215
216 216 public float healthy_percent
217 217 {
218 218 get {
219 return (float)(this.map.tree_count - this.map.iterate_cells_with_neighbors(7).Where(c => c.hasTree).Count()) / this.map.tree_count * 100;
219 return (float)(this.map.tree_count - this.map.iterate_cells_with_neighbors(7).Where(c => c.HasTree).Count()) / this.map.tree_count * 100;
220 220 }
221 221 }
222 222
@@ -224,7 +224,7
224 224 {
225 225 get
226 226 {
227 return this.map.iterate_cells().Where(c => c.hasTree).Select(c => (this.DateTime - c.planted).Days / 365.0).Average();
227 return this.map.iterate_cells().Where(c => c.HasTree).Select(c => (this.DateTime - c.Planted).Days / 365.0).Average();
228 228 }
229 229 }
230 230
@@ -232,7 +232,7
232 232 {
233 233 get
234 234 {
235 return this.map.iterate_cells().Where(c => c.hasTree).Select(c => (this.DateTime - c.planted).Days / 365.0).Max();
235 return this.map.iterate_cells().Where(c => c.HasTree).Select(c => (this.DateTime - c.Planted).Days / 365.0).Max();
236 236 }
237 237 }
238 238
@@ -271,7 +271,7
271 271 if (random.NextDouble() > SPONTANEOUS_NEW_TREE_CHANCE)
272 272 {
273 273 var random_type = random.Next(0, 2);
274 cell.addTree(this.DateTime, (TreeType)random_type);
274 cell.AddTree(this.DateTime, (TreeType)random_type);
275 275 }
276 276 }
277 277
@@ -281,7 +281,7
281 281 if (random.NextDouble() > NEIGHBOR_NEW_TREE_CHANCE)
282 282 {
283 283 var random_type = random.Next(0, 2);
284 cell.addTree(this.DateTime, (TreeType)random_type);
284 cell.AddTree(this.DateTime, (TreeType)random_type);
285 285 new_planted += 1;
286 286 }
287 287 }
@@ -291,7 +291,7
291 291 {
292 292 if (random.NextDouble() > NEIGHBOR_CROWDS_TREE_CHANCE)
293 293 {
294 cell.markTreeDead();
294 cell.MarkTreeDead();
295 295 crowded_out += 1;
296 296 }
297 297 }
@@ -303,19 +303,19
303 303 int x = random.Next(0, this.map.MapWidth);
304 304 Cell chosen_cell = this.map.cells[x][y];
305 305
306 if (!chosen_cell.hasTree) {
306 if (!chosen_cell.HasTree) {
307 307 var random_type = random.Next(0, 2);
308 chosen_cell.addTree(this.DateTime, (TreeType)random_type);
308 chosen_cell.AddTree(this.DateTime, (TreeType)random_type);
309 309 trees_to_plant -= 1;
310 310 }
311 311 }
312 312
313 313 int trees_to_clear = this.tree_clearing;
314 foreach (Cell cell in this.map.iterate_cells_with_neighbors(7).Where(c => c.hasTree))
314 foreach (Cell cell in this.map.iterate_cells_with_neighbors(7).Where(c => c.HasTree))
315 315 {
316 316 if (trees_to_clear > 0) {
317 cell.removeTree();
318 317 trees_to_clear -= 1;
318 cell.RemoveTree();
319 319 }
320 320 }
321 321
You need to be logged in to leave comments. Login now