Description:
Improve contract spawning.
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
|
1 | NO CONTENT: modified file, binary diff hidden |
|
NO CONTENT: modified file, binary diff hidden |
|
1 | NO CONTENT: modified file, binary diff hidden |
|
NO CONTENT: modified file, binary diff hidden |
@@ -1,6 +1,8 | |||||
|
1 | using System; |
|
1 | using System; |
|
|
2 | using System.Linq; | ||
|
2 | using System.Collections.Generic; |
|
3 | using System.Collections.Generic; |
|
3 | using Encompass; |
|
4 | using Encompass; |
|
|
5 | using JM.LinqFaster; | ||
|
4 |
|
6 | ||
|
5 | using Microsoft.Xna.Framework; |
|
7 | using Microsoft.Xna.Framework; |
|
6 |
|
8 | ||
@@ -10,11 +12,12 | |||||
|
10 | namespace isometricparkfna.Spawners { |
|
12 | namespace isometricparkfna.Spawners { |
|
11 |
|
13 | ||
|
12 | [Receives(typeof(SpawnContractMessage))] |
|
14 | [Receives(typeof(SpawnContractMessage))] |
|
13 | [Reads(typeof(AreaComponent))] |
|
15 | [Reads(typeof(AreaComponent), typeof(ContractStatusComponent))] |
|
14 | class ContractSpawner : Spawner<SpawnContractMessage> |
|
16 | class ContractSpawner : Spawner<SpawnContractMessage> |
|
15 | { |
|
17 | { |
|
16 | private Random random_generator; |
|
18 | private Random random_generator; |
|
17 |
|
19 | ||
|
|
20 | public const int DEFAULT_MIN_SQUARES = 10; | ||
|
18 | public const int DEFAULT_SQUARES = 25; |
|
21 | public const int DEFAULT_SQUARES = 25; |
|
19 | public const int CONTRACT_MINIMUM = 50; |
|
22 | public const int CONTRACT_MINIMUM = 50; |
|
20 | public const int CONTRACT_MAXIMUM = 250; |
|
23 | public const int CONTRACT_MAXIMUM = 250; |
@@ -63,10 +66,11 | |||||
|
63 | attempts += 1; |
|
66 | attempts += 1; |
|
64 | } |
|
67 | } |
|
65 | } |
|
68 | } |
|
66 | squares.AddRange(squares_to_add); |
|
69 | var remaining = max_size - squares.Count; |
|
|
70 | squares.AddRange(squares_to_add.Take(remaining)); | ||
|
67 | squares_to_add.Clear(); |
|
71 | squares_to_add.Clear(); |
|
68 |
|
72 | ||
|
69 | if (attempts >= maxAttempts) |
|
73 | if (attempts >= maxAttempts && squares.Count < max_size) |
|
70 | { |
|
74 | { |
|
71 | System.Console.WriteLine(string.Format("Failed to generate enough squares. {0} were requested, only {1} were found ({2} attempts)", max_size, squares.Count, attempts)); |
|
75 | System.Console.WriteLine(string.Format("Failed to generate enough squares. {0} were requested, only {1} were found ({2} attempts)", max_size, squares.Count, attempts)); |
|
72 | break; |
|
76 | break; |
@@ -77,34 +81,44 | |||||
|
77 |
|
81 | ||
|
78 | protected override void Spawn(in SpawnContractMessage message) |
|
82 | protected override void Spawn(in SpawnContractMessage message) |
|
79 | { |
|
83 | { |
|
80 | var contract = CreateEntity(); |
|
||
|
81 |
|
84 | ||
|
82 |
|
|
85 | //for now: |
|
83 |
|
|
86 | var occupied = new List<Vector2>(); |
|
84 |
|
87 | ||
|
85 | foreach(ref readonly var entity in ReadEntities<AreaComponent>()) |
|
88 | foreach (var (entity, status) in ReadEntities<AreaComponent>().SelectWhereF((e) => (e, GetComponent<ContractStatusComponent>(e)), |
|
86 | { |
|
89 | (e) => (e.Item2.status != ContractStatus.Expired)) |
|
87 | var entitySquares = GetComponent<AreaComponent>(entity).squares; |
|
90 | ) |
|
88 | occupied.AddRange(entitySquares); |
|
91 | { |
|
89 | } |
|
92 | var entitySquares = GetComponent<AreaComponent>(entity).squares; |
|
|
93 | occupied.AddRange(entitySquares); | ||
|
|
94 | } | ||
|
90 |
|
95 | ||
|
91 |
|
|
96 | var start_x = random_generator.Next(0, 50); |
|
92 |
|
|
97 | var start_y = random_generator.Next(0, 50); |
|
|
98 | |||
|
|
99 | int max_squares = (message.max_squares == 0) ? DEFAULT_SQUARES : message.max_squares; | ||
|
|
100 | int min_squares = (message.min_squares == null) ? DEFAULT_MIN_SQUARES : (int)message.min_squares; | ||
|
|
101 | Vector2[] squares = (message.squares == null) ? CreateArea(start_x, start_y, max_squares, new HashSet<Vector2>(occupied)) : message.squares; | ||
|
93 |
|
102 | ||
|
94 | int max_squares = (message.max_squares == 0) ? DEFAULT_SQUARES : message.max_squares; |
|
103 | if (squares.Length > min_squares) |
|
95 | Vector2[] squares = (message.squares == null) ? CreateArea(start_x, start_y, max_squares, new HashSet<Vector2>(occupied)) : message.squares; |
|
104 | { |
|
|
105 | var contract = CreateEntity(); | ||
|
96 |
|
106 | ||
|
97 |
|
|
107 | int contract_amount = random_generator.Next(CONTRACT_MINIMUM, CONTRACT_MAXIMUM); |
|
98 |
|
108 | ||
|
99 | // AddComponent |
|
109 | // AddComponent |
|
100 | AddComponent(contract, new AreaComponent { squares = squares }); |
|
110 | AddComponent(contract, new AreaComponent { squares = squares }); |
|
101 | AddComponent(contract, new NameComponent { DisplayName = message.name }); |
|
111 | AddComponent(contract, new NameComponent { DisplayName = message.name }); |
|
102 | AddComponent(contract, new SelectedComponent { selected = false }); |
|
112 | AddComponent(contract, new SelectedComponent { selected = false }); |
|
103 | AddComponent(contract, new ContractStatusComponent { status = ContractStatus.Proposed, date = this.simulation.DateTime }); |
|
113 | AddComponent(contract, new ContractStatusComponent { status = ContractStatus.Proposed, date = this.simulation.DateTime }); |
|
104 |
|
|
114 | AddComponent(contract, new TreeDeltaComponent { deltaTrees = -1 }); |
|
105 |
AddComponent(contract, new BudgetLineComponent |
|
115 | AddComponent(contract, new BudgetLineComponent |
|
106 | //Round to the nearest $5 |
|
116 | { |
|
107 | amount = (decimal)((contract_amount/5)*5) }); |
|
117 | category = "Contracts", |
|
|
118 | //Round to the nearest $5 | ||
|
|
119 | amount = (decimal)((contract_amount / 5) * 5) | ||
|
|
120 | }); | ||
|
|
121 | } | ||
|
108 |
|
122 | ||
|
109 | } |
|
123 | } |
|
110 | } |
|
124 | } |
@@ -7,6 +7,8 | |||||
|
7 | { |
|
7 | { |
|
8 | public Vector2[] squares; |
|
8 | public Vector2[] squares; |
|
9 | public string name; |
|
9 | public string name; |
|
10 |
|
|
10 | public int max_squares; |
|
|
11 | |||
|
|
12 | public int? min_squares; | ||
|
11 | } |
|
13 | } |
|
12 | } |
|
14 | } |
@@ -194,6 +194,9 | |||||
|
194 | </Reference> |
|
194 | </Reference> |
|
195 | <Reference Include="System.Data.DataSetExtensions" /> |
|
195 | <Reference Include="System.Data.DataSetExtensions" /> |
|
196 | <Reference Include="System.Xml" /> |
|
196 | <Reference Include="System.Xml" /> |
|
|
197 | <Reference Include="JM.LinqFaster"> | ||
|
|
198 | <HintPath>..\packages\JM.LinqFaster.1.1.2\lib\net461\JM.LinqFaster.dll</HintPath> | ||
|
|
199 | </Reference> | ||
|
197 | </ItemGroup> |
|
200 | </ItemGroup> |
|
198 | <ItemGroup> |
|
201 | <ItemGroup> |
|
199 | <Folder Include="Utils\" /> |
|
202 | <Folder Include="Utils\" /> |
@@ -2,8 +2,9 | |||||
|
2 | <packages> |
|
2 | <packages> |
|
3 | <package id="Collections.Pooled" version="1.0.82" targetFramework="net461" /> |
|
3 | <package id="Collections.Pooled" version="1.0.82" targetFramework="net461" /> |
|
4 | <package id="ImGui.NET" version="1.78.0" targetFramework="net472" /> |
|
4 | <package id="ImGui.NET" version="1.78.0" targetFramework="net472" /> |
|
5 |
<package id=" |
|
5 | <package id="JM.LinqFaster" version="1.1.2" targetFramework="net461" /> |
|
6 |
<package id=" |
|
6 | <package id="morelinq" version="3.3.2" targetFramework="net461" /> |
|
|
7 | <package id="Newtonsoft.Json" version="13.0.1" targetFramework="net461" /> | ||
|
7 | <package id="System.Buffers" version="4.5.1" targetFramework="net461" /> |
|
8 | <package id="System.Buffers" version="4.5.1" targetFramework="net461" /> |
|
8 | <package id="System.Memory" version="4.5.4" targetFramework="net461" /> |
|
9 | <package id="System.Memory" version="4.5.4" targetFramework="net461" /> |
|
9 | <package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net461" /> |
|
10 | <package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net461" /> |
@@ -11,7 +12,7 | |||||
|
11 | <package id="System.Security.AccessControl" version="5.0.0" targetFramework="net461" /> |
|
12 | <package id="System.Security.AccessControl" version="5.0.0" targetFramework="net461" /> |
|
12 | <package id="System.Security.Permissions" version="5.0.0" targetFramework="net461" /> |
|
13 | <package id="System.Security.Permissions" version="5.0.0" targetFramework="net461" /> |
|
13 | <package id="System.Security.Principal.Windows" version="5.0.0" targetFramework="net461" /> |
|
14 | <package id="System.Security.Principal.Windows" version="5.0.0" targetFramework="net461" /> |
|
14 |
<package id="System.ValueTuple" version="4. |
|
15 | <package id="System.ValueTuple" version="4.5.0" targetFramework="net461" /> |
|
15 | <package id="Tracery.Net" version="1.0.0" targetFramework="net461" /> |
|
16 | <package id="Tracery.Net" version="1.0.0" targetFramework="net461" /> |
|
16 |
<package id="YamlDotNet" version=" |
|
17 | <package id="YamlDotNet" version="11.1.1" targetFramework="net461" /> |
|
17 | </packages> No newline at end of file |
|
18 | </packages> |
You need to be logged in to leave comments.
Login now