Description:
Refactor starting code to Spawner.
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
@@ -0,0 +1,109 | |||
|
1 | ||
|
2 | using System; | |
|
3 | using System.Collections.Generic; | |
|
4 | ||
|
5 | using Microsoft.Xna.Framework; | |
|
6 | ||
|
7 | ||
|
8 | using Encompass; | |
|
9 | ||
|
10 | using isometricparkfna.Messages; | |
|
11 | using static isometricparkfna.CellMap; | |
|
12 | // using isometricparkfna.Components; | |
|
13 | ||
|
14 | namespace isometricparkfna.Spawners { | |
|
15 | ||
|
16 | [Receives(typeof(SpawnGameMessage))] | |
|
17 | [Sends(typeof(SpawnContractMessage), | |
|
18 | typeof(SpawnOrganizationtMessage))] | |
|
19 | class GameSpawner : Spawner<SpawnGameMessage> | |
|
20 | ||
|
21 | { | |
|
22 | private Simulation simulation; | |
|
23 | Random random_generator; | |
|
24 | ||
|
25 | ||
|
26 | public GameSpawner(Simulation simulation) | |
|
27 | { | |
|
28 | this.simulation = simulation; | |
|
29 | this.random_generator = new Random(); | |
|
30 | } | |
|
31 | ||
|
32 | ||
|
33 | protected override void Spawn(in SpawnGameMessage message) | |
|
34 | { | |
|
35 | ||
|
36 | #region generate_trees | |
|
37 | ||
|
38 | foreach (List<Cell> row in this.simulation.map.cells) | |
|
39 | { | |
|
40 | foreach (Cell cell in row) | |
|
41 | { | |
|
42 | if (this.random_generator.NextDouble() > 0.75) | |
|
43 | { | |
|
44 | int random_year = (int)MathHelper.Clamp((float)MathUtils.NextNormal(random_generator, 2010.0f, 40.0f), 1800, Simulation.START_YEAR); | |
|
45 | int random_month = random_generator.Next(1, 12); | |
|
46 | DateTime random_date = new DateTime(random_year, random_month, 1); | |
|
47 | ||
|
48 | cell.addTree(random_date); | |
|
49 | } | |
|
50 | } | |
|
51 | } | |
|
52 | #endregion | |
|
53 | ||
|
54 | #region create_contracts | |
|
55 | ||
|
56 | var area = CreateEntity(); | |
|
57 | var size = 5; | |
|
58 | var squares = new Vector2[size * size]; | |
|
59 | var start_x = 10; | |
|
60 | ||
|
61 | for (int i = 0; i < size; i++) | |
|
62 | { | |
|
63 | for (int j = 0; j < size; j++) | |
|
64 | { | |
|
65 | squares[i * size + j] = new Vector2(i + start_x, j); | |
|
66 | } | |
|
67 | ||
|
68 | } | |
|
69 | SendMessage(new SpawnContractMessage | |
|
70 | { | |
|
71 | squares = squares, | |
|
72 | name = "Northshore Logging" | |
|
73 | }); | |
|
74 | SendMessage(new SpawnContractMessage | |
|
75 | { | |
|
76 | name = "Aeres Maximalis Ltd." | |
|
77 | }); | |
|
78 | #endregion | |
|
79 | ||
|
80 | #region create_organizations | |
|
81 | for (int i = 0; i < 3; i++) | |
|
82 | { | |
|
83 | ||
|
84 | SendMessage(new SpawnOrganizationtMessage { offersContracts = true, | |
|
85 | name = "#family_company.capitalizeAll#", | |
|
86 | description = "#family_company_description#", | |
|
87 | type = OrganizationType.Family }); | |
|
88 | SendMessage(new SpawnOrganizationtMessage { offersContracts = true, | |
|
89 | name = "#large_company.capitalizeAll#", | |
|
90 | description = "#large_company_description#", | |
|
91 | type = OrganizationType.LargeCorporation }); | |
|
92 | } | |
|
93 | SendMessage(new SpawnOrganizationtMessage { offersContracts = true, | |
|
94 | name = "#logging_company.capitalizeAll#", | |
|
95 | description = "#company_description#" }); | |
|
96 | SendMessage(new SpawnOrganizationtMessage { offersContracts = true, | |
|
97 | name = "#coop_company.capitalizeAll#", | |
|
98 | description = "#coop_company_description#", | |
|
99 | type = OrganizationType.Cooperative }); | |
|
100 | SendMessage(new SpawnOrganizationtMessage { offersContracts = true, | |
|
101 | name = "#coop_company.capitalizeAll#", | |
|
102 | description = "#coop_company_description#", | |
|
103 | type = OrganizationType.Cooperative }); | |
|
104 | #endregion | |
|
105 | Logging.Success("Spawned new game."); | |
|
106 | ||
|
107 | } | |
|
108 | } | |
|
109 | } |
@@ -0,0 +1,6 | |||
|
1 | using Encompass; | |
|
2 | ||
|
3 | namespace isometricparkfna.Messages { | |
|
4 | ||
|
5 | public struct SpawnGameMessage : IMessage { } | |
|
6 | } |
@@ -19,7 +19,8 | |||
|
19 | 19 | typeof(GameStateMessage), |
|
20 | 20 | typeof(SetResolutionMessage), |
|
21 | 21 | typeof(SetFontMessage), |
|
22 |
typeof(SetTrespassingPolicyMessage) |
|
|
22 | typeof(SetTrespassingPolicyMessage), | |
|
23 | typeof(SpawnGameMessage))] | |
|
23 | 24 | [Reads(typeof(VisibilityComponent), |
|
24 | 25 | typeof(WindowTypeComponent), |
|
25 | 26 | typeof(TrespassingPolicyComponent) |
@@ -38,6 +39,7 | |||
|
38 | 39 | public List<SetResolutionMessage> resolutionMessages; |
|
39 | 40 | public List<SetFontMessage> fontMessages; |
|
40 | 41 | public List<SetTrespassingPolicyMessage> trespassingPolicyMessages; |
|
42 | public List<SpawnGameMessage> spawnGameMessages; | |
|
41 | 43 | |
|
42 | 44 | bool showBudget {get;} |
|
43 | 45 | bool showForest {get;} |
@@ -64,6 +66,7 | |||
|
64 | 66 | this.resolutionMessages = new List<SetResolutionMessage>(); |
|
65 | 67 | this.fontMessages = new List<SetFontMessage>(); |
|
66 | 68 | this.trespassingPolicyMessages = new List<SetTrespassingPolicyMessage>(); |
|
69 | this.spawnGameMessages = new List<SpawnGameMessage>(); | |
|
67 | 70 | this.windowStatuses = new Dictionary<Window, bool>(); |
|
68 | 71 | |
|
69 | 72 | |
@@ -132,6 +135,11 | |||
|
132 | 135 | { |
|
133 | 136 | SendMessage(message); |
|
134 | 137 | } |
|
138 | ||
|
139 | foreach (var message in this.spawnGameMessages) | |
|
140 | { | |
|
141 | SendMessage(message); | |
|
142 | } | |
|
135 | 143 | |
|
136 | 144 | |
|
137 | 145 | |
@@ -152,6 +160,7 | |||
|
152 | 160 | this.resolutionMessages.Clear(); |
|
153 | 161 | this.fontMessages.Clear(); |
|
154 | 162 | this.trespassingPolicyMessages.Clear(); |
|
163 | this.spawnGameMessages.Clear(); | |
|
155 | 164 | } |
|
156 | 165 | } |
|
157 | 166 | } |
@@ -147,20 +147,6 | |||
|
147 | 147 | |
|
148 | 148 | this.simulation = new Simulation(this.squaresAcross, this.squaresDown, new float[] {16.66667f*240, 16.66667f*120, 16.66667f*60, 16.66667f*30f, 16.66667f*1 }); |
|
149 | 149 | |
|
150 | foreach (List<Cell> row in this.simulation.map.cells) | |
|
151 | { | |
|
152 | foreach (Cell cell in row) | |
|
153 | { | |
|
154 | if (this.random_generator.NextDouble() > 0.75) | |
|
155 | { | |
|
156 | int random_year = (int)MathHelper.Clamp((float)MathUtils.NextNormal(random_generator, 2010.0f, 40.0f), 1800, Simulation.START_YEAR); | |
|
157 | int random_month = random_generator.Next(1, 12); | |
|
158 | DateTime random_date = new DateTime(random_year, random_month, 1); | |
|
159 | ||
|
160 | cell.addTree(random_date); | |
|
161 | } | |
|
162 | } | |
|
163 | } | |
|
164 | 150 | |
|
165 | 151 | showInitial = true; |
|
166 | 152 | messageIndex = 0; |
@@ -265,6 +251,7 | |||
|
265 | 251 | WorldBuilder.AddEngine(new ContractStatusEngine(this.simulation)); |
|
266 | 252 | |
|
267 | 253 | WorldBuilder.AddEngine(new ContractSpawner(simulation.map.MapWidth, simulation.map.MapHeight, this.simulation, this.grammar)); |
|
254 | WorldBuilder.AddEngine(new GameSpawner(this.simulation)); | |
|
268 | 255 | WorldBuilder.AddEngine(new OrganizationSpawner(this.simulation, this.grammar)); |
|
269 | 256 | WorldBuilder.AddEngine(new PolicyEngine()); |
|
270 | 257 | |
@@ -307,62 +294,13 | |||
|
307 | 294 | WorldBuilder.SetComponent(policyEntity, |
|
308 | 295 | new BudgetLineComponent { }); |
|
309 | 296 | |
|
310 | ||
|
311 | ||
|
312 | ||
|
313 | var area = WorldBuilder.CreateEntity(); | |
|
314 | var size = 5; | |
|
315 | var squares = new Vector2[size * size]; | |
|
316 | var start_x = 10; | |
|
317 | ||
|
318 | for (int i = 0; i < size; i++) | |
|
319 | { | |
|
320 | for (int j = 0; j < size; j++) | |
|
321 | { | |
|
322 | squares[i * size + j] = new Vector2(i + start_x, j); | |
|
323 | } | |
|
324 | ||
|
325 | } | |
|
326 | for (int i = 0; i < 3; i++) | |
|
327 | { | |
|
328 | ||
|
329 | WorldBuilder.SendMessage(new SpawnOrganizationtMessage { offersContracts = true, | |
|
330 | name = "#family_company.capitalizeAll#", | |
|
331 | description = "#family_company_description#", | |
|
332 | type = OrganizationType.Family }); | |
|
333 | WorldBuilder.SendMessage(new SpawnOrganizationtMessage { offersContracts = true, | |
|
334 | name = "#large_company.capitalizeAll#", | |
|
335 | description = "#large_company_description#", | |
|
336 | type = OrganizationType.LargeCorporation }); | |
|
337 | } | |
|
338 | WorldBuilder.SendMessage(new SpawnOrganizationtMessage { offersContracts = true, | |
|
339 | name = "#logging_company.capitalizeAll#", | |
|
340 | description = "#company_description#" }); | |
|
341 | WorldBuilder.SendMessage(new SpawnOrganizationtMessage { offersContracts = true, | |
|
342 | name = "#coop_company.capitalizeAll#", | |
|
343 | description = "#coop_company_description#", | |
|
344 | type = OrganizationType.Cooperative }); | |
|
345 | WorldBuilder.SendMessage(new SpawnOrganizationtMessage { offersContracts = true, | |
|
346 | name = "#coop_company.capitalizeAll#", | |
|
347 | description = "#coop_company_description#", | |
|
348 | type = OrganizationType.Cooperative }); | |
|
349 | WorldBuilder.SendMessage(new SpawnContractMessage | |
|
350 | { | |
|
351 | squares = squares, | |
|
352 | name = "Northshore Logging" | |
|
353 | }); | |
|
354 | WorldBuilder.SendMessage(new SpawnContractMessage | |
|
355 | { | |
|
356 | name = "Aeres Maximalis Ltd." | |
|
357 | }); | |
|
358 | ||
|
359 | ||
|
360 | 297 | try { |
|
361 | 298 | var options = Options.readOptions(); |
|
362 | 299 | |
|
363 | 300 | this.imGuiWindowBridgeEngine.fontMessages.Add(new SetFontMessage{ |
|
364 | 301 | fontSize = options.fontSize, |
|
365 | 302 | fontName = options.fontName}); |
|
303 | Logging.Success("Loaded options."); | |
|
366 | 304 | } |
|
367 | 305 | catch (FileNotFoundException e) |
|
368 | 306 | { |
You need to be logged in to leave comments.
Login now