Space Plunder
Loading...
Searching...
No Matches
DungeonData.h
Go to the documentation of this file.
1// Fill out your copyright notice in the Description page of Project Settings.
2
3#pragma once
4
5#include "CoreMinimal.h"
7#include "Data/DungeonEnums.h"
8#include "DungeonData.generated.h"
9
10class IDungeonRoom;
11
12
13DECLARE_STATS_GROUP(TEXT("Procedural Dungeons"), STATGROUP_ProceduralDungeons, STATCAT_Advanced);
14
15DECLARE_CYCLE_STAT(TEXT("Procedural Dungeons (All Functions)"), STAT_ProceduralDungeons, STATGROUP_ProceduralDungeons);
16DECLARE_CYCLE_STAT(TEXT("Builder (All Functions)"), STAT_ProceduralDungeons_Builder, STATGROUP_ProceduralDungeons);
17DECLARE_CYCLE_STAT(TEXT("Rooms (All Functions)"), STAT_ProceduralDungeons_Rooms, STATGROUP_ProceduralDungeons);
18DECLARE_CYCLE_STAT(TEXT("BP Library (All Functions)"), STAT_ProceduralDungeons_BPLib, STATGROUP_ProceduralDungeons);
19
20DECLARE_DWORD_COUNTER_STAT(TEXT("Dungeon Rooms"), STAT_RoomsCreated, STATGROUP_ProceduralDungeons);
21DECLARE_DWORD_COUNTER_STAT(TEXT("Dungeon Rooms Destoryed"), STAT_RoomsDeleted, STATGROUP_ProceduralDungeons);
22DECLARE_DWORD_COUNTER_STAT(TEXT("Dungeon Room Attempts"), STAT_GenerateAttempts, STATGROUP_ProceduralDungeons);
23
24DECLARE_LOG_CATEGORY_CLASS(LogDungeonData, Display, All);
25
26
27USTRUCT(BlueprintType)
29{
30 GENERATED_BODY()
31
32 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Special Room")
33 TSubclassOf<AActor> Class = nullptr;
34 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Special Room")
35 int32 NumberToSpawn = 1;
36
37 // Default constructor
39
40 // Parameterized constructor
41 FDungeonSpecialItem(const TSubclassOf<AActor> InClass, const int32 InNumberToSpawn)
42 : Class(InClass), NumberToSpawn(InNumberToSpawn) {}
43
45 {
46 if(Other.Class == Class){return true;}
47 return false;
48 }
49};
50
51
52
53// Check if this is used anywhere?
54// Use as Not Arrays or Types, but for just one type, With it's own Weight, etc.
55// Then the builder will just have an array of this
56USTRUCT(BlueprintType)
58{
59 GENERATED_BODY()
60
61
62 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="General")
63 TSubclassOf<AActor> Type = nullptr;
65 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="General")
66 int32 TypeWeight = 1;
67
68 //@TODO make Enum? or Tag for type of room, then can spawn room or hallways etc.
69 // UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="General")
70 // FString TypeTag = "Hallway";
71 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="General")
72 bool bDisable = false;
73
74 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="General")
75 bool bSpawnLimit = false;
76 // -1 is not limit
77 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="General", meta=(EditCondition=bSpawnLimit))
78 int32 NumberToSpawn = -1;
79 UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Spawn")
80 int32 NumberSpawned = 0;
81 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="General")
82 bool bRequired = false;
83
84
85 UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Calculated")
86 bool bCalculatedValues = false;
88 UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Calculated")
89 int32 CalculatedExits = 0;
90 UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Calculated")
91 EDungeonRoomType CalculatedType = EDungeonRoomType::Hallway;
92 UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Calculated")
93 FBox CalculatedRoomBounds = FBox(FVector::ZeroVector, FVector::ZeroVector);
94
95 bool GetHasSpawnedLimit() const
96 {
97 if(bSpawnLimit)
98 {
99 return NumberSpawned >= NumberToSpawn;
100 }
101 return false;
102 }
103
104
105 int32 GetExits() const
106 {
107 return CalculatedExits;
108 // if(Type == nullptr){UE_LOG(LogDungeonData, Warning, TEXT("FDungeonSpawnType::GetExits Type Failed"));return 0;}
109 // // BUG Get Exits doesn't seem to work on Default Object
110 // const IDungeonRoom* DungeonRoomClass = Cast<IDungeonRoom>(Type.GetDefaultObject());
111 // if(DungeonRoomClass == nullptr){UE_LOG(LogDungeonData, Warning, TEXT("FDungeonSpawnType::GetExits DungeonRoomClass Failed"));return 0;}
112 // return DungeonRoomClass->GetNumOfExits();
113 }
114
116 {
117 }
118
119 //@TODO Add sizes
120 // UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Spawn Type")
121 // int32 Size = 0;
122 // Get Size from Class?
123 // UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Spawn Type")
124 // TArray<int32> CompatibleSizes;
125
126
127 TArray<TSubclassOf<AActor>>& GetWeightedTypes()
128 {
129 if(Type == nullptr){UE_LOG(LogDungeonData, Error, TEXT("FDungeonSpawnRoom::GetWeightedTypes No Valid Type"));return WeightedTypes;}
130 WeightedTypes.Empty();
131 for(int32 i = 0; i < TypeWeight; ++i)
132 {
133 WeightedTypes.Add(Type);
134 }
135 return WeightedTypes;
136 };
137
138private:
139 TArray<TSubclassOf<AActor>> WeightedTypes;
140
141public:
143 {
144 if(Other.Type == Type){return true;}
145 return false;
146 }
148 {
149 if(Other.Type != Type){return true;}
150 return false;
151 }
152 bool IsValid() const
153 {
154 if(Type == nullptr)
155 {
156 return false;
157 }
158 if(Type->ImplementsInterface(UDungeonRoom::StaticClass()) == false)
159 {
160 UE_LOG(LogDungeonData, Error, TEXT("FDungeonSpawnRoom::IsValid Please Remove RoomType %s Doesn't Implement Interface"), *Type->GetName());
161 return false;
162 }
163 return true;
164 }
165};
166
167USTRUCT(BlueprintType)
169{
170 GENERATED_BODY()
171
172 // Protected?
173
174
175 TArray<FDungeonSpawnRoom> GetAllRooms() const
176 {
177 return GetRoomsWithNumOfExits(0);
178 }
179
180 TArray<FDungeonSpawnRoom>& GetRooms()
181 {
182 return Rooms;
183 }
184
185 TArray<FDungeonSpawnRoom> GetRoomsOfType(const TSubclassOf<AActor> ActorClass)
186 {
187 TArray<FDungeonSpawnRoom> SelectedRooms;
188 for(auto& Room : Rooms)
189 {
190 if(Room.Type == ActorClass)
191 {
192 SelectedRooms.Add(Room);
193 }
194 }
195 return SelectedRooms;
196 }
197
198
199
200 /* Will only return rooms with exits */
201 TArray<FDungeonSpawnRoom> GetRoomsWithExits() const
202 {
203 return GetRoomsWithNumOfExits(1);
204 }
205 /* Will only return dead end rooms */
206 TArray<FDungeonSpawnRoom> GetRoomsWithNoExits() const
207 {
208 return GetRoomsWithNumOfExits(0, 0);
209 }
210
211 /* Will return ALL rooms with minExits or more */
212 TArray<FDungeonSpawnRoom> GetRoomsWithNumOfExits(const int32 MinExits) const
213 {
214 TArray<FDungeonSpawnRoom> SelectedRooms;
215 for(int32 i = 0; i < Rooms.Num(); ++i)
216 {
217 if(Rooms[i].IsValid() == false){UE_LOG(LogDungeonData, Warning, TEXT("FDungeonSpawns::GetRoomsWithNumOfExits Room %i Not Valid"), i);continue;}
218 // UE_LOG(LogDungeonData, Warning, TEXT("Rooms %s GetExits: %i"), *Rooms[i].Type->GetName(), Rooms[i].GetExits());
219 if(Rooms[i].GetExits() >= MinExits)
220 {
221 SelectedRooms.AddUnique(Rooms[i]);
222 }
223 }
224 return SelectedRooms;
225 }
226 TArray<FDungeonSpawnRoom> GetRoomsWithNumOfExits(const int32 MinExits, const int32 MaxExits) const
227 {
228 TArray<FDungeonSpawnRoom> SelectedRooms;
229 for(int32 i = 0; i < Rooms.Num(); ++i)
230 {
231 if(Rooms[i].IsValid() == false){UE_LOG(LogDungeonData, Warning, TEXT("FDungeonSpawns::GetRoomsWithNumOfExits Room %i Not Valid"), i);continue;}
232 // if(Rooms[i].GetExits() >= MinExits && Rooms[i].GetExits() <= MaxExits)
233 if(Rooms[i].GetExits() >= MinExits && Rooms[i].GetExits() <= MaxExits)
234 {
235 // This needs to add the room with weights
236 SelectedRooms.AddUnique(Rooms[i]);
237 }
238 }
239 return SelectedRooms;
240 }
241
242 FDungeonSpawnRoom* Find(const TSubclassOf<AActor> ActorClass)
243 {
244 for(auto& Room : Rooms)
245 {
246 if(Room.Type == ActorClass)
247 {
248 return &Room;
249 }
250 }
251 return nullptr;
252 }
253 EDungeonRoomType FindType(const TSubclassOf<AActor> ActorClass) const
254 {
255 for(auto& Room : Rooms)
256 {
257 if(Room.Type == ActorClass)
258 {
259 return Room.CalculatedType;
260 }
261 }
262 return EDungeonRoomType::Hallway;
263 }
264
265
266 bool IsEmpty() const
267 {
268 return Rooms.IsEmpty();
269 }
270 bool IsValidIndex(const int32 Index) const
271 {
272 return Rooms.IsValidIndex(Index);
273 }
274 int32 Num() const
275 {
276 return Rooms.Num();
277 }
278
280 {
281
282 }
283 explicit FDungeonSpawns(const TArray<FDungeonSpawnRoom>& InitialRooms)
284 {
285 Rooms = InitialRooms;
286 }
287
288
289protected:
290 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="General")
291 TArray<FDungeonSpawnRoom> Rooms;
292
293};
294
295
299class PROCEDURALDUNGEONS_API DungeonData
300{
301public:
302};
DECLARE_CYCLE_STAT(TEXT("Procedural Dungeons (All Functions)"), STAT_ProceduralDungeons, STATGROUP_ProceduralDungeons)
DECLARE_STATS_GROUP(TEXT("Procedural Dungeons"), STATGROUP_ProceduralDungeons, STATCAT_Advanced)
DECLARE_LOG_CATEGORY_CLASS(LogDungeonData, Display, All)
DECLARE_DWORD_COUNTER_STAT(TEXT("Dungeon Rooms"), STAT_RoomsCreated, STATGROUP_ProceduralDungeons)
EDungeonRoomType
Definition DungeonEnums.h:11
Definition DungeonData.h:300
Definition DungeonRoom.h:21
Definition DungeonData.h:58
bool IsValid() const
Definition DungeonData.h:152
bool operator==(const FDungeonSpawnRoom &Other) const
Definition DungeonData.h:142
bool operator!=(const FDungeonSpawnRoom &Other) const
Definition DungeonData.h:147
int32 GetExits() const
Definition DungeonData.h:105
FDungeonSpawnRoom()
Definition DungeonData.h:115
TArray< TSubclassOf< AActor > > WeightedTypes
Definition DungeonData.h:139
TArray< TSubclassOf< AActor > > & GetWeightedTypes()
Definition DungeonData.h:127
Definition DungeonData.h:169
bool IsEmpty() const
Definition DungeonData.h:266
bool IsValidIndex(const int32 Index) const
Definition DungeonData.h:270
TArray< FDungeonSpawnRoom > & GetRooms()
Definition DungeonData.h:180
FDungeonSpawns()
Definition DungeonData.h:279
TArray< FDungeonSpawnRoom > GetRoomsWithNumOfExits(const int32 MinExits, const int32 MaxExits) const
Definition DungeonData.h:226
EDungeonRoomType FindType(const TSubclassOf< AActor > ActorClass) const
Definition DungeonData.h:253
int32 Num() const
Definition DungeonData.h:274
TArray< FDungeonSpawnRoom > GetRoomsWithExits() const
Definition DungeonData.h:201
FDungeonSpawns(const TArray< FDungeonSpawnRoom > &InitialRooms)
Definition DungeonData.h:283
TArray< FDungeonSpawnRoom > GetRoomsWithNoExits() const
Definition DungeonData.h:206
TArray< FDungeonSpawnRoom > GetRoomsOfType(const TSubclassOf< AActor > ActorClass)
Definition DungeonData.h:185
FDungeonSpawnRoom * Find(const TSubclassOf< AActor > ActorClass)
Definition DungeonData.h:242
TArray< FDungeonSpawnRoom > GetRoomsWithNumOfExits(const int32 MinExits) const
Definition DungeonData.h:212
Definition DungeonData.h:29
FDungeonSpecialItem(const TSubclassOf< AActor > InClass, const int32 InNumberToSpawn)
Definition DungeonData.h:41
bool operator==(const FDungeonSpecialItem &Other) const
Definition DungeonData.h:44