diff --git a/isometric-park-fna/Components/OrganizationTypeComponent.cs b/isometric-park-fna/Components/OrganizationTypeComponent.cs new file mode 100644 --- /dev/null +++ b/isometric-park-fna/Components/OrganizationTypeComponent.cs @@ -0,0 +1,13 @@ + + +using Encompass; + +using isometricparkfna.Spawners; + +namespace isometricparkfna.Components +{ + public struct OrganizationTypeComponent : IComponent + { + public OrganizationType type; + } +} \ No newline at end of file diff --git a/isometric-park-fna/Engines/Spawners/ContractSpawner.cs b/isometric-park-fna/Engines/Spawners/ContractSpawner.cs --- a/isometric-park-fna/Engines/Spawners/ContractSpawner.cs +++ b/isometric-park-fna/Engines/Spawners/ContractSpawner.cs @@ -16,7 +16,7 @@ [Receives(typeof(SpawnContractMessage))] [Reads(typeof(AreaComponent), typeof(ContractStatusComponent), - typeof(OffersContractsComponent))] + typeof(OffersContractsComponent), typeof(OrganizationTypeComponent))] class ContractSpawner : Spawner { private Random random_generator; @@ -24,7 +24,7 @@ public const int DEFAULT_MIN_SQUARES = 10; public const int DEFAULT_SQUARES = 25; public const int CONTRACT_MINIMUM = 50; - public const int CONTRACT_MAXIMUM = 250; + public const int CONTRACT_MAXIMUM = 400; private int MapWidth; private int MapHeight; @@ -95,7 +95,13 @@ var contractOrganizations = ReadEntities().ToArray(); var contractCount = contractOrganizations.Count(); + OrganizationType organization_type = OrganizationType.Unspecified; + if (contractCount > 0) + { + var organization_index = random_generator.Next(0, contractCount); + organization_type = GetComponent(contractOrganizations[organization_index]).type; + } foreach (var (entity, status) in ReadEntities().SelectWhereF((e) => (e, GetComponent(e)), (e) => (e.Item2.status != ContractStatus.Expired)) @@ -114,13 +120,34 @@ int min_squares = (message.min_squares == null) ? DEFAULT_MIN_SQUARES : (int)message.min_squares; Vector2[] squares = (message.squares == null) ? CreateArea(start_x, start_y, max_squares, new HashSet(occupied)) : message.squares; + if (squares.Length > min_squares) { var contract = CreateEntity(); - int contract_amount = random_generator.Next(CONTRACT_MINIMUM, CONTRACT_MAXIMUM); + + if (contractCount > 0) + { + AddComponent(contract, new RelatedOrganizationComponent { Entity = contractOrganizations[organization_index] }); + } + + + var deltaTrees = organization_type switch { - var deltaTrees = random_generator.Next(-20, 3); + OrganizationType.Family => random_generator.Next(-10, 3), + OrganizationType.LargeCorporation => random_generator.Next(-20, 0), + OrganizationType.Cooperative => random_generator.Next(-1, 3), + _ => random_generator.Next(-20, 3) + }; + + var contract_amount = organization_type switch { + OrganizationType.Family => random_generator.Next(CONTRACT_MINIMUM, CONTRACT_MAXIMUM/2), + OrganizationType.LargeCorporation => random_generator.Next(CONTRACT_MINIMUM*2, CONTRACT_MAXIMUM), + OrganizationType.Cooperative => random_generator.Next(CONTRACT_MINIMUM, CONTRACT_MAXIMUM/2), + _ => random_generator.Next(CONTRACT_MINIMUM, CONTRACT_MAXIMUM) + + }; + // AddComponent AddComponent(contract, new AreaComponent { squares = squares }); @@ -138,11 +165,6 @@ AddComponent(contract, new WindowTypeComponent { type = Window.Contract}); AddComponent(contract, new VisibilityComponent { visible = false}); - if (contractCount > 0) - { - var organization_index = random_generator.Next(0, contractCount); - AddComponent(contract, new RelatedOrganizationComponent { Entity = contractOrganizations[organization_index] }); - } } } diff --git a/isometric-park-fna/Engines/Spawners/OrganizationSpawner.cs b/isometric-park-fna/Engines/Spawners/OrganizationSpawner.cs new file mode 100644 --- /dev/null +++ b/isometric-park-fna/Engines/Spawners/OrganizationSpawner.cs @@ -0,0 +1,63 @@ +using System; +using System.Linq; +using System.Collections.Generic; + +using Microsoft.Xna.Framework; + + +using Encompass; +using JM.LinqFaster; +using TraceryNet; + +using isometricparkfna.Messages; +using isometricparkfna.Components; + +namespace isometricparkfna.Spawners { + +//Only used for controlling generation, at least for now + public enum OrganizationType + { + Unspecified, + Family, + LargeCorporation, + Cooperative + + } + + [Receives(typeof(SpawnOrganizationtMessage))] + //[Reads(typeof(AreaComponent), typeof(ContractStatusComponent))] + class OrganizationSpawner : Spawner + { + + private Random random_generator; + private Grammar grammar; + + public OrganizationSpawner(Simulation simulation, Grammar grammar) + { + this.random_generator = new Random(); + + // this.simulation = simulation; + this.grammar = grammar; + } + + + protected override void Spawn(in SpawnOrganizationtMessage message) + { + + var organization = CreateEntity(); + var image_index = random_generator.Next(1, 7); + + var name = message.name != null ? message.name : "#logging_company.capitalizeAll#"; + var description = message.description != null ? message.description : ""; + + AddComponent(organization, new NameAndDescriptionComponent { DisplayName = this.grammar.Flatten(name), + Description = this.grammar.Flatten(description) }); + AddComponent(organization, new ImageComponent { ImageIndex = image_index }); + AddComponent(organization, new OffersContractsComponent { }); + AddComponent(organization, new OrganizationTypeComponent { type = message.type }); + + + } + + } +} \ No newline at end of file