Description:
Add a file I forgot, plus use organization type to spawn contracts.
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
@@ -0,0 +1,13 | |||
|
1 | ||
|
2 | ||
|
3 | using Encompass; | |
|
4 | ||
|
5 | using isometricparkfna.Spawners; | |
|
6 | ||
|
7 | namespace isometricparkfna.Components | |
|
8 | { | |
|
9 | public struct OrganizationTypeComponent : IComponent | |
|
10 | { | |
|
11 | public OrganizationType type; | |
|
12 | } | |
|
13 | } No newline at end of file |
@@ -0,0 +1,63 | |||
|
1 | using System; | |
|
2 | using System.Linq; | |
|
3 | using System.Collections.Generic; | |
|
4 | ||
|
5 | using Microsoft.Xna.Framework; | |
|
6 | ||
|
7 | ||
|
8 | using Encompass; | |
|
9 | using JM.LinqFaster; | |
|
10 | using TraceryNet; | |
|
11 | ||
|
12 | using isometricparkfna.Messages; | |
|
13 | using isometricparkfna.Components; | |
|
14 | ||
|
15 | namespace isometricparkfna.Spawners { | |
|
16 | ||
|
17 | //Only used for controlling generation, at least for now | |
|
18 | public enum OrganizationType | |
|
19 | { | |
|
20 | Unspecified, | |
|
21 | Family, | |
|
22 | LargeCorporation, | |
|
23 | Cooperative | |
|
24 | ||
|
25 | } | |
|
26 | ||
|
27 | [Receives(typeof(SpawnOrganizationtMessage))] | |
|
28 | //[Reads(typeof(AreaComponent), typeof(ContractStatusComponent))] | |
|
29 | class OrganizationSpawner : Spawner<SpawnOrganizationtMessage> | |
|
30 | { | |
|
31 | ||
|
32 | private Random random_generator; | |
|
33 | private Grammar grammar; | |
|
34 | ||
|
35 | public OrganizationSpawner(Simulation simulation, Grammar grammar) | |
|
36 | { | |
|
37 | this.random_generator = new Random(); | |
|
38 | ||
|
39 | // this.simulation = simulation; | |
|
40 | this.grammar = grammar; | |
|
41 | } | |
|
42 | ||
|
43 | ||
|
44 | protected override void Spawn(in SpawnOrganizationtMessage message) | |
|
45 | { | |
|
46 | ||
|
47 | var organization = CreateEntity(); | |
|
48 | var image_index = random_generator.Next(1, 7); | |
|
49 | ||
|
50 | var name = message.name != null ? message.name : "#logging_company.capitalizeAll#"; | |
|
51 | var description = message.description != null ? message.description : ""; | |
|
52 | ||
|
53 | AddComponent(organization, new NameAndDescriptionComponent { DisplayName = this.grammar.Flatten(name), | |
|
54 | Description = this.grammar.Flatten(description) }); | |
|
55 | AddComponent(organization, new ImageComponent { ImageIndex = image_index }); | |
|
56 | AddComponent(organization, new OffersContractsComponent { }); | |
|
57 | AddComponent(organization, new OrganizationTypeComponent { type = message.type }); | |
|
58 | ||
|
59 | ||
|
60 | } | |
|
61 | ||
|
62 | } | |
|
63 | } No newline at end of file |
@@ -16,7 +16,7 | |||
|
16 | 16 | |
|
17 | 17 | [Receives(typeof(SpawnContractMessage))] |
|
18 | 18 | [Reads(typeof(AreaComponent), typeof(ContractStatusComponent), |
|
19 | typeof(OffersContractsComponent))] | |
|
19 | typeof(OffersContractsComponent), typeof(OrganizationTypeComponent))] | |
|
20 | 20 | class ContractSpawner : Spawner<SpawnContractMessage> |
|
21 | 21 | { |
|
22 | 22 | private Random random_generator; |
@@ -24,7 +24,7 | |||
|
24 | 24 | public const int DEFAULT_MIN_SQUARES = 10; |
|
25 | 25 | public const int DEFAULT_SQUARES = 25; |
|
26 | 26 | public const int CONTRACT_MINIMUM = 50; |
|
27 |
public const int CONTRACT_MAXIMUM = |
|
|
27 | public const int CONTRACT_MAXIMUM = 400; | |
|
28 | 28 | |
|
29 | 29 | private int MapWidth; |
|
30 | 30 | private int MapHeight; |
@@ -95,7 +95,13 | |||
|
95 | 95 | var contractOrganizations = ReadEntities<OffersContractsComponent>().ToArray(); |
|
96 | 96 | |
|
97 | 97 | var contractCount = contractOrganizations.Count(); |
|
98 | OrganizationType organization_type = OrganizationType.Unspecified; | |
|
98 | 99 | |
|
100 | if (contractCount > 0) | |
|
101 | { | |
|
102 | var organization_index = random_generator.Next(0, contractCount); | |
|
103 | organization_type = GetComponent<OrganizationTypeComponent>(contractOrganizations[organization_index]).type; | |
|
104 | } | |
|
99 | 105 | |
|
100 | 106 | foreach (var (entity, status) in ReadEntities<AreaComponent>().SelectWhereF((e) => (e, GetComponent<ContractStatusComponent>(e)), |
|
101 | 107 | (e) => (e.Item2.status != ContractStatus.Expired)) |
@@ -114,13 +120,34 | |||
|
114 | 120 | int min_squares = (message.min_squares == null) ? DEFAULT_MIN_SQUARES : (int)message.min_squares; |
|
115 | 121 | Vector2[] squares = (message.squares == null) ? CreateArea(start_x, start_y, max_squares, new HashSet<Vector2>(occupied)) : message.squares; |
|
116 | 122 | |
|
123 | ||
|
117 | 124 | if (squares.Length > min_squares) |
|
118 | 125 | { |
|
119 | 126 | var contract = CreateEntity(); |
|
120 | 127 | |
|
121 | int contract_amount = random_generator.Next(CONTRACT_MINIMUM, CONTRACT_MAXIMUM); | |
|
128 | ||
|
129 | if (contractCount > 0) | |
|
130 | { | |
|
131 | AddComponent(contract, new RelatedOrganizationComponent { Entity = contractOrganizations[organization_index] }); | |
|
132 | } | |
|
133 | ||
|
134 | ||
|
135 | var deltaTrees = organization_type switch { | |
|
122 | 136 | |
|
123 |
|
|
|
137 | OrganizationType.Family => random_generator.Next(-10, 3), | |
|
138 | OrganizationType.LargeCorporation => random_generator.Next(-20, 0), | |
|
139 | OrganizationType.Cooperative => random_generator.Next(-1, 3), | |
|
140 | _ => random_generator.Next(-20, 3) | |
|
141 | }; | |
|
142 | ||
|
143 | var contract_amount = organization_type switch { | |
|
144 | OrganizationType.Family => random_generator.Next(CONTRACT_MINIMUM, CONTRACT_MAXIMUM/2), | |
|
145 | OrganizationType.LargeCorporation => random_generator.Next(CONTRACT_MINIMUM*2, CONTRACT_MAXIMUM), | |
|
146 | OrganizationType.Cooperative => random_generator.Next(CONTRACT_MINIMUM, CONTRACT_MAXIMUM/2), | |
|
147 | _ => random_generator.Next(CONTRACT_MINIMUM, CONTRACT_MAXIMUM) | |
|
148 | ||
|
149 | }; | |
|
150 | ||
|
124 | 151 | |
|
125 | 152 | // AddComponent |
|
126 | 153 | AddComponent(contract, new AreaComponent { squares = squares }); |
@@ -138,11 +165,6 | |||
|
138 | 165 | AddComponent(contract, new WindowTypeComponent { type = Window.Contract}); |
|
139 | 166 | AddComponent(contract, new VisibilityComponent { visible = false}); |
|
140 | 167 | |
|
141 | if (contractCount > 0) | |
|
142 | { | |
|
143 | var organization_index = random_generator.Next(0, contractCount); | |
|
144 | AddComponent(contract, new RelatedOrganizationComponent { Entity = contractOrganizations[organization_index] }); | |
|
145 | } | |
|
146 | 168 | } |
|
147 | 169 | |
|
148 | 170 | } |
You need to be logged in to leave comments.
Login now