diff --git a/isometric-park-fna/Engines/ImGuiWindowBridgeEngine.cs b/isometric-park-fna/Engines/ImGuiWindowBridgeEngine.cs --- a/isometric-park-fna/Engines/ImGuiWindowBridgeEngine.cs +++ b/isometric-park-fna/Engines/ImGuiWindowBridgeEngine.cs @@ -19,7 +19,8 @@ typeof(GameStateMessage), typeof(SetResolutionMessage), typeof(SetFontMessage), - typeof(SetTrespassingPolicyMessage))] + typeof(SetTrespassingPolicyMessage), + typeof(SpawnGameMessage))] [Reads(typeof(VisibilityComponent), typeof(WindowTypeComponent), typeof(TrespassingPolicyComponent) @@ -38,6 +39,7 @@ public List resolutionMessages; public List fontMessages; public List trespassingPolicyMessages; + public List spawnGameMessages; bool showBudget {get;} bool showForest {get;} @@ -64,6 +66,7 @@ this.resolutionMessages = new List(); this.fontMessages = new List(); this.trespassingPolicyMessages = new List(); + this.spawnGameMessages = new List(); this.windowStatuses = new Dictionary(); @@ -132,6 +135,11 @@ { SendMessage(message); } + + foreach (var message in this.spawnGameMessages) + { + SendMessage(message); + } @@ -152,6 +160,7 @@ this.resolutionMessages.Clear(); this.fontMessages.Clear(); this.trespassingPolicyMessages.Clear(); + this.spawnGameMessages.Clear(); } } } diff --git a/isometric-park-fna/Engines/Spawners/GameSpawner.cs b/isometric-park-fna/Engines/Spawners/GameSpawner.cs new file mode 100644 --- /dev/null +++ b/isometric-park-fna/Engines/Spawners/GameSpawner.cs @@ -0,0 +1,109 @@ + +using System; +using System.Collections.Generic; + +using Microsoft.Xna.Framework; + + +using Encompass; + +using isometricparkfna.Messages; +using static isometricparkfna.CellMap; +// using isometricparkfna.Components; + +namespace isometricparkfna.Spawners { + + [Receives(typeof(SpawnGameMessage))] + [Sends(typeof(SpawnContractMessage), + typeof(SpawnOrganizationtMessage))] + class GameSpawner : Spawner + + { + private Simulation simulation; + Random random_generator; + + + public GameSpawner(Simulation simulation) + { + this.simulation = simulation; + this.random_generator = new Random(); + } + + + protected override void Spawn(in SpawnGameMessage message) + { + +#region generate_trees + + foreach (List row in this.simulation.map.cells) + { + foreach (Cell cell in row) + { + if (this.random_generator.NextDouble() > 0.75) + { + int random_year = (int)MathHelper.Clamp((float)MathUtils.NextNormal(random_generator, 2010.0f, 40.0f), 1800, Simulation.START_YEAR); + int random_month = random_generator.Next(1, 12); + DateTime random_date = new DateTime(random_year, random_month, 1); + + cell.addTree(random_date); + } + } + } +#endregion + +#region create_contracts + + var area = CreateEntity(); + var size = 5; + var squares = new Vector2[size * size]; + var start_x = 10; + + for (int i = 0; i < size; i++) + { + for (int j = 0; j < size; j++) + { + squares[i * size + j] = new Vector2(i + start_x, j); + } + + } + SendMessage(new SpawnContractMessage + { + squares = squares, + name = "Northshore Logging" + }); + SendMessage(new SpawnContractMessage + { + name = "Aeres Maximalis Ltd." + }); +#endregion + +#region create_organizations + for (int i = 0; i < 3; i++) + { + + SendMessage(new SpawnOrganizationtMessage { offersContracts = true, + name = "#family_company.capitalizeAll#", + description = "#family_company_description#", + type = OrganizationType.Family }); + SendMessage(new SpawnOrganizationtMessage { offersContracts = true, + name = "#large_company.capitalizeAll#", + description = "#large_company_description#", + type = OrganizationType.LargeCorporation }); + } + SendMessage(new SpawnOrganizationtMessage { offersContracts = true, + name = "#logging_company.capitalizeAll#", + description = "#company_description#" }); + SendMessage(new SpawnOrganizationtMessage { offersContracts = true, + name = "#coop_company.capitalizeAll#", + description = "#coop_company_description#", + type = OrganizationType.Cooperative }); + SendMessage(new SpawnOrganizationtMessage { offersContracts = true, + name = "#coop_company.capitalizeAll#", + description = "#coop_company_description#", + type = OrganizationType.Cooperative }); +#endregion + Logging.Success("Spawned new game."); + + } + } +} diff --git a/isometric-park-fna/FNAGame.cs b/isometric-park-fna/FNAGame.cs --- a/isometric-park-fna/FNAGame.cs +++ b/isometric-park-fna/FNAGame.cs @@ -147,20 +147,6 @@ 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 }); - foreach (List row in this.simulation.map.cells) - { - foreach (Cell cell in row) - { - if (this.random_generator.NextDouble() > 0.75) - { - int random_year = (int)MathHelper.Clamp((float)MathUtils.NextNormal(random_generator, 2010.0f, 40.0f), 1800, Simulation.START_YEAR); - int random_month = random_generator.Next(1, 12); - DateTime random_date = new DateTime(random_year, random_month, 1); - - cell.addTree(random_date); - } - } - } showInitial = true; messageIndex = 0; @@ -265,6 +251,7 @@ WorldBuilder.AddEngine(new ContractStatusEngine(this.simulation)); WorldBuilder.AddEngine(new ContractSpawner(simulation.map.MapWidth, simulation.map.MapHeight, this.simulation, this.grammar)); + WorldBuilder.AddEngine(new GameSpawner(this.simulation)); WorldBuilder.AddEngine(new OrganizationSpawner(this.simulation, this.grammar)); WorldBuilder.AddEngine(new PolicyEngine()); @@ -307,62 +294,13 @@ WorldBuilder.SetComponent(policyEntity, new BudgetLineComponent { }); - - - - var area = WorldBuilder.CreateEntity(); - var size = 5; - var squares = new Vector2[size * size]; - var start_x = 10; - - for (int i = 0; i < size; i++) - { - for (int j = 0; j < size; j++) - { - squares[i * size + j] = new Vector2(i + start_x, j); - } - - } - for (int i = 0; i < 3; i++) - { - - WorldBuilder.SendMessage(new SpawnOrganizationtMessage { offersContracts = true, - name = "#family_company.capitalizeAll#", - description = "#family_company_description#", - type = OrganizationType.Family }); - WorldBuilder.SendMessage(new SpawnOrganizationtMessage { offersContracts = true, - name = "#large_company.capitalizeAll#", - description = "#large_company_description#", - type = OrganizationType.LargeCorporation }); - } - WorldBuilder.SendMessage(new SpawnOrganizationtMessage { offersContracts = true, - name = "#logging_company.capitalizeAll#", - description = "#company_description#" }); - WorldBuilder.SendMessage(new SpawnOrganizationtMessage { offersContracts = true, - name = "#coop_company.capitalizeAll#", - description = "#coop_company_description#", - type = OrganizationType.Cooperative }); - WorldBuilder.SendMessage(new SpawnOrganizationtMessage { offersContracts = true, - name = "#coop_company.capitalizeAll#", - description = "#coop_company_description#", - type = OrganizationType.Cooperative }); - WorldBuilder.SendMessage(new SpawnContractMessage - { - squares = squares, - name = "Northshore Logging" - }); - WorldBuilder.SendMessage(new SpawnContractMessage - { - name = "Aeres Maximalis Ltd." - }); - - try { var options = Options.readOptions(); this.imGuiWindowBridgeEngine.fontMessages.Add(new SetFontMessage{ fontSize = options.fontSize, fontName = options.fontName}); + Logging.Success("Loaded options."); } catch (FileNotFoundException e) { diff --git a/isometric-park-fna/Messages/SpawnGameMessage.cs b/isometric-park-fna/Messages/SpawnGameMessage.cs new file mode 100644 --- /dev/null +++ b/isometric-park-fna/Messages/SpawnGameMessage.cs @@ -0,0 +1,6 @@ +using Encompass; + +namespace isometricparkfna.Messages { + + public struct SpawnGameMessage : IMessage { } +} diff --git a/isometric-park-fna/UI/MainMenu.cs b/isometric-park-fna/UI/MainMenu.cs --- a/isometric-park-fna/UI/MainMenu.cs +++ b/isometric-park-fna/UI/MainMenu.cs @@ -33,6 +33,7 @@ if (ImGui.Button("New Game", button_size)) { bridgeEngine.gameStateMessages.Add(new GameStateMessage { isPlaying = true}); + bridgeEngine.spawnGameMessages.Add(new SpawnGameMessage()); } if (ImGui.Button("Quit", button_size))