Description:
Add bulldozer tool.
Adds a bulldozer tool for removing structures. For the moment, works like
dezone, i.e., it can delete entire areas rather than working on one area at a
time.
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
@@ -9,7 +9,8 | |||
|
9 | 9 | None, |
|
10 | 10 | Preserve, |
|
11 | 11 | Dezone, |
|
12 | Tower | |
|
12 | Tower, | |
|
13 | Bulldozer | |
|
13 | 14 | |
|
14 | 15 | } |
|
15 | 16 |
@@ -52,7 +52,7 | |||
|
52 | 52 | } |
|
53 | 53 | } |
|
54 | 54 | |
|
55 | private void clear(Vector2[] clear_squares) { | |
|
55 | private void clear_areas(Vector2[] clear_squares) { | |
|
56 | 56 | List<Entity> entities = new List<Entity>(); |
|
57 | 57 | foreach(ref readonly var entity in ReadEntities<AreaComponent>() ) { |
|
58 | 58 | var squares = GetComponent<AreaComponent>(entity).squares; |
@@ -80,6 +80,24 | |||
|
80 | 80 | } |
|
81 | 81 | } |
|
82 | 82 | |
|
83 | private void clear_structures(Vector2[] clear_squares) { | |
|
84 | List<Entity> entities = new List<Entity>(); | |
|
85 | foreach(ref readonly var entity in ReadEntities<StructureComponent>() ) { | |
|
86 | var square = GetComponent<PointComponent>(entity).Square; | |
|
87 | ||
|
88 | foreach(var clear_square in clear_squares) { | |
|
89 | if(square == clear_square) { | |
|
90 | entities.Add(entity); | |
|
91 | } | |
|
92 | } | |
|
93 | } | |
|
94 | ||
|
95 | foreach(var entity in entities) { | |
|
96 | Logging.Debug("Deleting entity."); | |
|
97 | Destroy(entity); | |
|
98 | } | |
|
99 | } | |
|
100 | ||
|
83 | 101 | public List<Vector2> GetOccupied() { |
|
84 | 102 | List<Vector2> occupied = new List<Vector2>(); |
|
85 | 103 | |
@@ -165,7 +183,6 | |||
|
165 | 183 | } |
|
166 | 184 | } |
|
167 | 185 | else if (statuses.ContainsKey(Tool.Dezone) && statuses[Tool.Dezone]) { |
|
168 | ||
|
169 | 186 | foreach (ref readonly var message in ReadMessages<SpawnSelection>()) |
|
170 | 187 | { |
|
171 | 188 | if (message.Start.X >= 0 && message.Start.X < this.Map.MapWidth |
@@ -188,7 +205,7 | |||
|
188 | 205 | } |
|
189 | 206 | else if(message.Type == AdjustmentType.Complete) { |
|
190 | 207 | var squares = GetComponent<AreaComponent>(entity).squares; |
|
191 | clear(squares); | |
|
208 | clear_areas(squares); | |
|
192 | 209 | } |
|
193 | 210 | else { |
|
194 | 211 | var area = GetComponent<AreaComponent>(entity); |
@@ -233,7 +250,7 | |||
|
233 | 250 | } |
|
234 | 251 | |
|
235 | 252 | foreach (ref readonly var message in ReadMessages<AdjustSelection>()) { |
|
236 |
foreach (ref readonly |
|
|
253 | foreach (ref readonly var entity in ReadEntities<SelectedComponent>()) { | |
|
237 | 254 | var selection = GetComponent<SelectedComponent>(entity); |
|
238 | 255 | |
|
239 | 256 | if (selection.Type == SelectionType.Area |
@@ -241,7 +258,7 | |||
|
241 | 258 | if(message.Type == AdjustmentType.Clear) { |
|
242 | 259 | Destroy(entity); |
|
243 | 260 | } |
|
244 | else if(message.Type == AdjustmentType.Complete) { | |
|
261 | else if (message.Type == AdjustmentType.Complete) { | |
|
245 | 262 | var point = GetComponent<PointComponent>(entity); |
|
246 | 263 | var structure_entity = CreateEntity(); |
|
247 | 264 | var cell = this.Map.cells[(int)point.Square.X][(int)point.Square.Y]; |
@@ -251,7 +268,7 | |||
|
251 | 268 | |
|
252 | 269 | AddComponent(structure_entity, new PointComponent {Square = point.Square, |
|
253 | 270 | Tool = point.Tool} ); |
|
254 |
AddComponent(structure_entity, |
|
|
271 | AddComponent(structure_entity, | |
|
255 | 272 | new StructureComponent { Structure = Structure.Tower}); |
|
256 | 273 | Destroy(entity); |
|
257 | 274 | SendMessage(new PlaySoundMessage { SoundName = "ConstructionShort" }); |
@@ -270,6 +287,53 | |||
|
270 | 287 | } |
|
271 | 288 | } |
|
272 | 289 | } |
|
290 | ||
|
291 | else if ((statuses.ContainsKey(Tool.Bulldozer) && statuses[Tool.Bulldozer])) { | |
|
292 | foreach (ref readonly var message in ReadMessages<SpawnSelection>()) | |
|
293 | { | |
|
294 | if (message.Start.X >= 0 && message.Start.X < this.Map.MapWidth | |
|
295 | && message.Start.Y >= 0 && message.Start.Y < this.Map.MapHeight) { | |
|
296 | var entity = CreateEntity(); | |
|
297 | ||
|
298 | AddComponent(entity, new AreaComponent { squares = new[] {message.Start}, | |
|
299 | Tool = Tool.Bulldozer }); | |
|
300 | AddComponent(entity, new SelectedComponent { selected = true, Type= SelectionType.Area}); | |
|
301 | } | |
|
302 | } | |
|
303 | ||
|
304 | foreach (ref readonly var message in ReadMessages<AdjustSelection>()) { | |
|
305 | foreach (ref readonly var entity in ReadEntities<SelectedComponent>()) { | |
|
306 | var selection = GetComponent<SelectedComponent>(entity); | |
|
307 | if(selection.Type == SelectionType.Area | |
|
308 | && selection.selected) { | |
|
309 | if (message.Type == AdjustmentType.Clear) { | |
|
310 | Destroy(entity); | |
|
311 | } | |
|
312 | else if (message.Type == AdjustmentType.Complete) { | |
|
313 | var squares = GetComponent<AreaComponent>(entity).squares; | |
|
314 | clear_structures(squares); | |
|
315 | Destroy(entity); //Dezone destroys itself, so it doesn't need this command. | |
|
316 | } | |
|
317 | else { | |
|
318 | var area = GetComponent<AreaComponent>(entity); | |
|
319 | ||
|
320 | var newSquares = new List<Vector2>(); | |
|
321 | ||
|
322 | var end_x = MathUtils.Clamp(message.End.X, 0.0f, this.Map.MapWidth); | |
|
323 | var end_y = MathUtils.Clamp(message.End.Y, 0.0f, this.Map.MapHeight); | |
|
324 | ||
|
325 | foreach (var i in step_until(area.squares[0].X, end_x)) { | |
|
326 | foreach (var j in step_until(area.squares[0].Y, end_y)) { | |
|
327 | var newSquare = new Vector2(i, j); | |
|
328 | newSquares.Add(newSquare); | |
|
329 | } | |
|
330 | } | |
|
331 | SetComponent(entity, new AreaComponent { squares = newSquares.ToArray(), Tool = area.Tool}); | |
|
332 | } | |
|
333 | } | |
|
334 | } | |
|
335 | } | |
|
336 | } | |
|
273 | 337 | } |
|
274 | 338 | } |
|
275 | 339 | } |
@@ -99,7 +99,7 | |||
|
99 | 99 | ImGui.Text(header); |
|
100 | 100 | |
|
101 | 101 | |
|
102 | var dimensions = ImGui.CalcTextSize("X Tower X Preserve X Dezone | X Graph X Contracts $ Budget X Forest X News X | Pause 1 2 3 4 5") ; | |
|
102 | var dimensions = ImGui.CalcTextSize("X Tower X Preserve X Dezone X Bulldozer | X Graph X Contracts $ Budget X Forest X News X | Pause 1 2 3 4 5") ; | |
|
103 | 103 | |
|
104 | 104 | // ImGui.SetCursorPosX(width - 520); |
|
105 | 105 | // Add 12 pixels for each button, plus separator |
@@ -117,7 +117,10 | |||
|
117 | 117 | { |
|
118 | 118 | bridgeEngine.toggleToolMessages.Add(new ToggleToolMessage {Tool = Tool.Dezone}); |
|
119 | 119 | } |
|
120 | ||
|
120 | if (Menu.activeButton("\ue122 Bulldozer", bridgeEngine.toolStatuses[Tool.Bulldozer], StyleSets.selected, StyleSets.white)) | |
|
121 | { | |
|
122 | bridgeEngine.toggleToolMessages.Add(new ToggleToolMessage {Tool = Tool.Bulldozer}); | |
|
123 | } | |
|
121 | 124 | ImGui.Text("|"); |
|
122 | 125 | |
|
123 | 126 | if (Menu.activeButton("\ue03e Graph", bridgeEngine.windowStatuses[Window.Graph], StyleSets.selected, StyleSets.white)) |
You need to be logged in to leave comments.
Login now