-
Notifications
You must be signed in to change notification settings - Fork 0
/
CitadelBrainManager.h
247 lines (192 loc) · 5.62 KB
/
CitadelBrainManager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Data/PlanData.h"
#include "GameFramework/Actor.h"
#include "Data/ProgressGridData.h"
#include "CitadelBrainManager.generated.h"
class UPlanData;
class AGenericMech;
struct FCutterQueue;
class ATransportSpire;
class ADisharmonyGameMode;
class AMech_Weaver;
class AMech_Cutter;
USTRUCT()
struct FFrontierInfo
{
GENERATED_BODY()
UPROPERTY()
TArray<int32> SiteIx;
UPROPERTY()
TArray<int32> EstimatedMass;
UPROPERTY()
TArray<int32> PrevSiteID;
};
USTRUCT()
struct FNeighborList
{
GENERATED_BODY()
UPROPERTY()
TArray<int32> Neighbors;
};
USTRUCT()
struct FPioneerRetryData
{
GENERATED_BODY()
UPROPERTY()
float time;
UPROPERTY()
int32 startIx;
UPROPERTY()
int32 targetIx;
UPROPERTY()
int32 pioneerX;
UPROPERTY()
int32 pioneerY;
};
USTRUCT()
struct FSiteDemandInfo
{
GENERATED_BODY()
UPROPERTY()
int32 StartSite;
UPROPERTY()
int32 EndSite;
UPROPERTY()
FVector StartLoc;
UPROPERTY()
FVector EndLoc;
};
USTRUCT()
struct FProductionSitePlan
{
GENERATED_BODY()
UPROPERTY()
int32 Progress = 0;
UPROPERTY()
FSiteDemandInfo DemandInfo;
};
UCLASS()
class UNSATISFACTORY_API ACitadelBrainManager : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
ACitadelBrainManager();
//Initialzied by game mode
void InitializeSystem();
// Called every frame
virtual void Tick(float DeltaTime) override;
void RegisterGameMode(ADisharmonyGameMode* gm)
{
GameMode = gm;
}
protected:
UPROPERTY()
ADisharmonyGameMode* GameMode;
UPROPERTY(EditAnywhere)
bool bWork = true;
UPROPERTY(EditAnywhere)
bool bAllSitesCanBeFactories = true;
UPROPERTY()
float RunningTime = 0;
//Sorted least to most desirable
UPROPERTY()
FFrontierInfo Frontier;
//-----------Sites
//Site Data
UPROPERTY(EditAnywhere, Category = "Sites")
int32 CuttersPerSite;
UPROPERTY(EditAnywhere, Category = "Sites")
int32 FactoryCandidateBigNeighborThreshold = 3;
UPROPERTY(EditAnywhere, Category = "Sites")
int32 BigNeighborTreeCount = 50;
//Sites about to be ready for work
UPROPERTY()
TArray<int32> PendingSites;
UPROPERTY()
TArray<int32> ActiveSites;
UPROPERTY()
TArray<int32> FinishedSites;
//UPROPERTY()
//TMap<int32, FNeighborList> FinishedNeighbors;
//Cutter Demands
UPROPERTY()
TArray<int32> Demand_C_Site;
UPROPERTY()
TArray<int32> Demand_C_Pioneer;
UPROPERTY()
TMap<int32, int32> Demand_C_PioneerPrev;
//Unit Build Demands
UPROPERTY()
int32 Demand_U_Cutter;
UPROPERTY()
int32 FormingCutters;
//UPROPERTY()
//int32 Demand_U_Weaver;
UPROPERTY()
int32 FormingWeavers;
//Building Build Demands
UPROPERTY()
TArray<FSiteDemandInfo> Demand_W_ProductionSite;
//Mech tracking
UPROPERTY()
TMap<AMech_Cutter*, int32> SiteCutters;
UPROPERTY()
TMap<AMech_Cutter*, int32> PioneerCutterEnds;
UPROPERTY()
TMap<AMech_Cutter*, int32> PioneerCutterStarts;
//Weavers building production sites
UPROPERTY()
TMap<int32, FProductionSitePlan> ProductionSitePlan;
UPROPERTY()
int32 ProdPlansCreated = 0;
UPROPERTY(EditAnywhere)
float RetryPioneerTimer = 60;
UPROPERTY()
TMap<AMech_Cutter*, FPioneerRetryData> RetryForlornPioneers;
UPROPERTY()
TMap<AMech_Cutter*, bool> CutterSplineReady;
//Data
UPROPERTY(EditAnywhere, Category = "Data References")
UProgressGridData* ProgressGridData;
UPROPERTY(EditAnywhere, Category="Data References")
UPlanData* PlanData;
protected:
//Update functions
void UpdateJoblessCutters(TArray<AMech_Cutter*>& Removed);
void UpdateSiteDemand();
void UpdateUnitDemand();
void UpdateWeaverCreationInstructions();
void UpdateForlornPioneers(float DeltaTime);
TArray<int32> GetClosestDemandSites(int32 x, int32 y, bool bIsPioneer, int32 considerNum);
int32 AddNeighborSitesToFrontier(int32 sIx);
void AddSiteToFrontier(int32 sIx, int32 prevIx, int32& estMass);
void MarkSiteHalfFinished(int32 ix);
void MarkSiteFullyFinished(int32 ix);
public:
//Waypoint stuff
//TArray<FVector> GetWaypointPath(FVector start, FVector end, float simplePathRange);
// int32 GetClosestFinishedSiteCell(int32 x, int32 y);
// TArray<FVector> AStarFinishedSites(int32 startIx, int32 endIx);
// int32 WaypointHeuristic(int32 curIx, int32 neighIx);
//Update forming things
int32 GetFormingCutters(){return FormingCutters;}
void SetFormingCutters(int32 f){FormingCutters = f;}
//Mark work finished
void MarkPioneeringFinished(AMech_Cutter* cut, AActor* attachedSpire, int32 ¢erX, int32 ¢erY, FVector &worldLoc);
void MarkSiteCutterFinished(AMech_Cutter* cut);
// void SubmitSiteWorkWeaver(FProductionSitePlan plan, AMech_Weaver* weav);
// void MarkSiteWorkWeaverReady(AMech_Weaver* weav);
void TryAddSpireToSite(AActor* spire, AMech_Cutter* mech);
//Get work
bool CutterSiteHasNext(AMech_Cutter* cut, FVector& attendLoc, int32& prevX, int32& prevY, ETreePatchDirection& dir);
void GetCutterSiteWork(int32 limbIx, int32 limbTotal, int32 x, int32 y, ETreePatchDirection dir, TArray<int32>& trees);
//Tree stuff
void PopulateCornerIndices(int32 dX, int32 dY, int32 cornerX, int32 cornerY, TArray<int32>& indicesX, TArray<int32>& indicesY, int32 span);
void PopulateOrthogonalIndices(int32 dX, int32 dY, int32 cornerX, int32 cornerY, TArray<int32>& indicesX, TArray<int32>& indicesY, int32 span);
void GatherScrapTrees(bool diagonal, bool firstHalf, TArray<FCutterQueue>& cutterQueues, int32 dX, int32 dY, int32 span, TArray<int32> halfIxX, TArray<int32> halfIxY);
void GetCutterPioneerWork(AMech_Cutter* cut, TArray<FCutterQueue>& cutterQueues, FVector& attendLoc);
//FPlanStack GetNextProductionPlan(int32 planID, AMech_Weaver* weaver);
};