Description:
Add Dezone.
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
@@ -7,7 +7,8 | |||
|
7 | 7 | public enum Tool |
|
8 | 8 | { |
|
9 | 9 | None, |
|
10 | Preserve | |
|
10 | Preserve, | |
|
11 | Dezone | |
|
11 | 12 | |
|
12 | 13 | } |
|
13 | 14 |
@@ -24,6 +24,7 | |||
|
24 | 24 | typeof(PreserveComponent), |
|
25 | 25 | typeof(SelectedComponent), |
|
26 | 26 | typeof(ToolComponent))] |
|
27 | [Sends(typeof(ChangeContractStatusMessage))] | |
|
27 | 28 | public class BuildToolEngine : Engine { |
|
28 | 29 | |
|
29 | 30 | private CellMap Map; |
@@ -47,9 +48,37 | |||
|
47 | 48 | } |
|
48 | 49 | } |
|
49 | 50 | |
|
51 | private void clear(Vector2[] clear_squares) { | |
|
52 | List<Entity> entities = new List<Entity>(); | |
|
53 | foreach(ref readonly var entity in ReadEntities<AreaComponent>() ) { | |
|
54 | var squares = GetComponent<AreaComponent>(entity).squares; | |
|
55 | ||
|
56 | foreach(var clear_square in clear_squares) { | |
|
57 | ||
|
58 | foreach(var square in squares) { | |
|
59 | if(square == clear_square) { | |
|
60 | entities.Add(entity); | |
|
61 | break; | |
|
62 | } | |
|
63 | } | |
|
64 | } | |
|
65 | } | |
|
66 | ||
|
67 | foreach(var entity in entities) { | |
|
68 | Logging.Debug("Deleting entity."); | |
|
69 | ||
|
70 | if (HasComponent<ContractStatusComponent>(entity)) { | |
|
71 | SendMessage(new ChangeContractStatusMessage {newStatus = ContractStatus.Broken, Entity = entity}); | |
|
72 | } | |
|
73 | else { | |
|
74 | Destroy(entity); | |
|
75 | } | |
|
76 | } | |
|
77 | ||
|
78 | } | |
|
79 | ||
|
50 | 80 | public override void Update(double dt) { |
|
51 | 81 | var occupied = new List<Vector2>(); |
|
52 | ||
|
53 | 82 | Dictionary<Tool, bool> statuses = new Dictionary<Tool, bool>(); |
|
54 | 83 | |
|
55 | 84 | foreach (var entity in ReadEntities<ToolComponent>()) { |
@@ -78,8 +107,6 | |||
|
78 | 107 | occupied.AddRange(entitySquares); |
|
79 | 108 | } |
|
80 | 109 | |
|
81 | ||
|
82 | ||
|
83 | 110 | foreach (ref readonly var message in ReadMessages<SpawnSelection>()) |
|
84 | 111 | { |
|
85 | 112 | if (message.Start.X >= 0 && message.Start.X < this.Map.MapWidth |
@@ -114,19 +141,63 | |||
|
114 | 141 | foreach (var i in step_until(area.squares[0].X, end_x)) { |
|
115 | 142 | foreach (var j in step_until(area.squares[0].Y, end_y)) { |
|
116 | 143 | var newSquare = new Vector2(i, j); |
|
144 | newSquares.Add(newSquare); | |
|
145 | } | |
|
146 | } | |
|
147 | ||
|
148 | SetComponent(entity, new AreaComponent { squares = newSquares.ToArray() /*new[]{ area.squares[0], message.End}*/}); | |
|
149 | } | |
|
150 | } | |
|
151 | } | |
|
152 | } | |
|
153 | } | |
|
154 | else if (statuses.ContainsKey(Tool.Dezone) && statuses[Tool.Dezone]) { | |
|
155 | ||
|
156 | foreach (ref readonly var message in ReadMessages<SpawnSelection>()) | |
|
157 | { | |
|
158 | if (message.Start.X >= 0 && message.Start.X < this.Map.MapWidth | |
|
159 | && message.Start.Y >= 0 && message.Start.Y < this.Map.MapHeight) { | |
|
160 | var entity = CreateEntity(); | |
|
161 | ||
|
162 | AddComponent(entity, new AreaComponent { squares = new[] {message.Start} }); | |
|
163 | AddComponent(entity, new SelectedComponent { selected = true, Type= SelectionType.Area}); | |
|
164 | } | |
|
165 | } | |
|
166 | ||
|
167 | foreach (ref readonly var message in ReadMessages<AdjustSelection>()) { | |
|
168 | foreach (ref readonly var entity in ReadEntities<SelectedComponent>()) { | |
|
169 | var selection = GetComponent<SelectedComponent>(entity); | |
|
170 | if(selection.Type == SelectionType.Area | |
|
171 | && selection.selected) { | |
|
172 | if(message.Type == AdjustmentType.Clear) { | |
|
173 | Destroy(entity); | |
|
174 | } | |
|
175 | else if(message.Type == AdjustmentType.Complete) { | |
|
176 | var squares = GetComponent<AreaComponent>(entity).squares; | |
|
177 | clear(squares); | |
|
178 | } | |
|
179 | else { | |
|
180 | var area = GetComponent<AreaComponent>(entity); | |
|
181 | ||
|
182 | var newSquares = new List<Vector2>(); | |
|
183 | ||
|
184 | var end_x = MathUtils.Clamp(message.End.X, 0.0f, this.Map.MapWidth); | |
|
185 | var end_y = MathUtils.Clamp(message.End.Y, 0.0f, this.Map.MapHeight); | |
|
186 | ||
|
187 | foreach (var i in step_until(area.squares[0].X, end_x)) { | |
|
188 | foreach (var j in step_until(area.squares[0].Y, end_y)) { | |
|
189 | var newSquare = new Vector2(i, j); | |
|
117 | 190 | if (!occupied.Contains(newSquare)) { |
|
118 | 191 | newSquares.Add(newSquare); |
|
119 | 192 | } |
|
120 | 193 | } |
|
121 | 194 | } |
|
122 | ||
|
123 | SetComponent(entity, new AreaComponent { squares = newSquares.ToArray() /*( new[]{ area.squares[0], message.End}*/}); | |
|
124 |
|
|
|
125 |
|
|
|
126 | } | |
|
127 | ||
|
128 | } | |
|
129 | } | |
|
195 | SetComponent(entity, new AreaComponent { squares = newSquares.ToArray() /*new[]{ area.squares[0], message.End}*/}); | |
|
196 | } | |
|
197 | } | |
|
198 | } | |
|
199 | } | |
|
200 | } | |
|
130 | 201 | } |
|
131 | 202 | } |
|
132 | 203 | } |
@@ -98,6 +98,8 | |||
|
98 | 98 | } |
|
99 | 99 | } |
|
100 | 100 | |
|
101 | ||
|
102 | //Set tool | |
|
101 | 103 | foreach (ref readonly var toolMessage in ReadMessages<ToggleToolMessage>()) |
|
102 | 104 | { |
|
103 | 105 | foreach (ref readonly var entity in ReadEntities<ToolComponent>()) |
@@ -106,7 +108,6 | |||
|
106 | 108 | var tool_type = GetComponent<ToolComponent>(entity).Tool; |
|
107 | 109 | if (tool_type == toolMessage.Tool) |
|
108 | 110 | { |
|
109 | ||
|
110 | 111 | //Clear selections |
|
111 | 112 | foreach (ref readonly var inner_entity in ReadEntities<ToolComponent>()) |
|
112 | 113 | { |
@@ -118,7 +119,6 | |||
|
118 | 119 | selectedComponent.selected = !selectedComponent.selected; |
|
119 | 120 | SetComponent(entity, selectedComponent); |
|
120 | 121 | } |
|
121 | ||
|
122 | 122 | } |
|
123 | 123 | } |
|
124 | 124 |
@@ -330,6 +330,10 | |||
|
330 | 330 | WorldBuilder.SetComponent(preserveTool, new ToolComponent { Tool = Tool.Preserve }); |
|
331 | 331 | WorldBuilder.SetComponent(preserveTool, new SelectedComponent {Type = SelectionType.Tool, selected = true}); |
|
332 | 332 | |
|
333 | var dezoneTool = WorldBuilder.CreateEntity(); | |
|
334 | WorldBuilder.SetComponent(dezoneTool, new ToolComponent { Tool = Tool.Dezone }); | |
|
335 | WorldBuilder.SetComponent(dezoneTool, new SelectedComponent {Type = SelectionType.Tool, selected = false}); | |
|
336 | ||
|
333 | 337 | |
|
334 | 338 | var gameEntity = WorldBuilder.CreateEntity(); |
|
335 | 339 |
@@ -290,7 +290,7 | |||
|
290 | 290 | for(int j = 0; j < this.map.MapHeight; j++) |
|
291 | 291 | { |
|
292 | 292 | var cell = this.map.cells[i][j]; |
|
293 |
var rate = interpolate |
|
|
293 | var rate = interpolate(8 - (double)this.PreserveCounts[i, j] / 8.0d, PRESERVE_SPONTANEOUS_NEW_TREE_CHANCE, SPONTANEOUS_NEW_TREE_CHANCE); | |
|
294 | 294 | if (random.NextDouble() > rate) |
|
295 | 295 | { |
|
296 | 296 | var random_type = random.Next(0, 4); |
@@ -99,7 +99,7 | |||
|
99 | 99 | ImGui.Text(header); |
|
100 | 100 | |
|
101 | 101 | |
|
102 | var dimensions = ImGui.CalcTextSize("| X Graph X Contracts $ Budget X Forest X News X | Pause 1 2 3 4 5") ; | |
|
102 | var dimensions = ImGui.CalcTextSize("X Preserve X Dezone | 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 |
@@ -108,7 +108,10 | |||
|
108 | 108 | if (Menu.activeButton("X Preserve", bridgeEngine.toolStatuses[Tool.Preserve], StyleSets.selected, StyleSets.white)) |
|
109 | 109 | { |
|
110 | 110 | bridgeEngine.toggleToolMessages.Add(new ToggleToolMessage {Tool = Tool.Preserve}); |
|
111 | ||
|
111 | } | |
|
112 | if (Menu.activeButton("X Dezone", bridgeEngine.toolStatuses[Tool.Dezone], StyleSets.selected, StyleSets.white)) | |
|
113 | { | |
|
114 | bridgeEngine.toggleToolMessages.Add(new ToggleToolMessage {Tool = Tool.Dezone}); | |
|
112 | 115 | } |
|
113 | 116 | |
|
114 | 117 | ImGui.Text("|"); |
You need to be logged in to leave comments.
Login now