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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
|
#ifndef ENGINE_COURSE_H
#define ENGINE_COURSE_H
#include <libultraship.h>
#include "CoreMath.h"
#ifdef __cplusplus
#include "engine/objects/Lakitu.h"
#include "port/resource/type/TrackSections.h"
extern "C" {
#endif
#include "camera.h"
#include "course_offsets.h"
#include "data/some_data.h"
#include "defines.h"
#include "bomb_kart.h"
#include "path_spawn_metadata.h"
#include "waypoints.h"
#include "sounds.h"
#include "common_structs.h"
#ifdef __cplusplus
}
#endif
typedef struct SkyboxColours {
RGB8 TopRight;
RGB8 BottomRight;
RGB8 BottomLeft;
RGB8 TopLeft;
RGB8 FloorTopRight;
RGB8 FloorBottomRight;
RGB8 FloorBottomLeft;
RGB8 FloorTopLeft;
} SkyboxColours;
// Extends infinitely in the Y direction
// If a player is overtop of a water volume then it should use its height
// Recommend using the new water surface type. This is here to support the stock tracks.
// Albeit, there's no reason you cannot use this so long as you input a square.
// How to use: WaterVolumes.push_back({0, -100, 100, -100, 100});
struct WaterVolume {
float Height; // Y coordinate of the Water level
float MinX;
float MaxX;
float MinZ;
float MaxZ;
};
typedef struct MinimapProps {
const char* Texture;
int16_t Width;
int16_t Height;
IVector2D Pos[2]; // Minimap position for players 1 and 2. 3/4 player mode is hard-coded to the center.
int32_t PlayerX; // The offset to place the player markers
int32_t PlayerY;
float PlayerScaleFactor; // Scale factor of the player markers
float FinishlineX; // The offset to place the finishline texture on the minimap
float FinishlineY;
RGB8 Colour; // Colour of the visible pixels (the track path)
} MinimapProps;
typedef struct Properties {
char Name[128];
char DebugName[128];
char CourseLength[128];
int32_t LakituTowType;
MinimapProps Minimap;
const char* AIBehaviour;
float AIMaximumSeparation;
float AIMinimumSeparation;
float NearPersp;
float FarPersp;
int16_t* AIDistance;
uint32_t AISteeringSensitivity;
_struct_gCoursePathSizes_0x10 PathSizes;
Vec4f D_0D009418;
Vec4f D_0D009568;
Vec4f D_0D0096B8;
Vec4f D_0D009808;
TrackWaypoint* PathTable[4];
TrackWaypoint* PathTable2[4];
uint8_t* CloudTexture;
CloudData *Clouds;
CloudData *CloudList;
SkyboxColours Skybox;
const course_texture *textures;
enum MusicSeq Sequence;
float WaterLevel; // Used for effects, and Lakitu pick up height. Not necessarily the visual water model height.
#ifdef __cplusplus
nlohmann::json to_json() const {
nlohmann::json j;
// j["Id"] = Id ? Id : "";
j["Name"] = Name ? Name : "";
j["DebugName"] = DebugName ? DebugName : "";
j["CourseLength"] = CourseLength ? CourseLength : "";
j["AIBehaviour"] = AIBehaviour ? AIBehaviour : "";
j["LakituTowType"] = LakituTowType;
j["AIMaximumSeparation"] = AIMaximumSeparation;
j["AIMinimumSeparation"] = AIMinimumSeparation;
j["NearPersp"] = NearPersp;
j["FarPersp"] = FarPersp;
// AIDistance as a JSON array
j["AIDistance"] = std::vector<int16_t>(AIDistance, AIDistance + 32); // gAIDistances array size of 32
j["AISteeringSensitivity"] = AISteeringSensitivity;
// PathSizes - Assuming _struct_gCoursePathSizes_0x10 can be serialized similarly
// j["PathSizes"] = PathSizes; // Implement your serialization logic here
j["D_0D009418"] = { D_0D009418[0], D_0D009418[1], D_0D009418[2], D_0D009418[3] };
j["D_0D009568"] = { D_0D009568[0], D_0D009568[1], D_0D009568[2], D_0D009568[3] };
j["D_0D0096B8"] = { D_0D0096B8[0], D_0D0096B8[1], D_0D0096B8[2], D_0D0096B8[3] };
j["D_0D009808"] = { D_0D009808[0], D_0D009808[1], D_0D009808[2], D_0D009808[3] };
// Serialize arrays PathTable and PathTable2 (convert pointers into a JSON array if possible)
//j["PathTable"] = {{}};
//j["PathTable2"] = {{}};
// Populate PathTable and PathTable2
//j["Clouds"] = Clouds ? nlohmann::json{{"x", Clouds->x, "y", Clouds->y, "z", Clouds->z}} : nullptr;
//j["CloudList"] = CloudList ? nlohmann::json{{"x", CloudList->x, "y", CloudList->y, "z", CloudList->z}} : nullptr;
j["MinimapPosition"] = {Minimap.Pos[0].X, Minimap.Pos[0].Y};
j["MinimapPosition2P"] = {Minimap.Pos[1].X, Minimap.Pos[1].Y};
j["MinimapPlayerX"] = Minimap.PlayerX;
j["MinimapPlayerY"] = Minimap.PlayerY;
j["MinimapPlayerScaleFactor"] = Minimap.PlayerScaleFactor;
j["MinimapFinishlineX"] = Minimap.FinishlineX;
j["MinimapFinishlineY"] = Minimap.FinishlineY;
j["MinimapColour"] = {static_cast<int>(Minimap.Colour.r), static_cast<int>(Minimap.Colour.g), static_cast<int>(Minimap.Colour.b)};
// SkyboxColors - assuming SkyboxColors can be serialized similarly
// j["Skybox"] = Skybox; // Implement your serialization logic here
j["Sequence"] = static_cast<int>(Sequence);
j["WaterLevel"] = static_cast<float>(WaterLevel);
return j;
}
// Function to load struct from JSON
void from_json(const nlohmann::json& j) {
//Id = j.at("Id").get<std::string>().c_str();
// Name = j.at("Name").get<std::string>().c_str();
strncpy(Name, j.at("Name").get<std::string>().c_str(), sizeof(Name) - 1);
Name[sizeof(Name) - 1] = '\0'; // Ensure null termination
// DebugName = j.at("DebugName").get<std::string>().c_str();
strncpy(DebugName, j.at("DebugName").get<std::string>().c_str(), sizeof(DebugName) - 1);
DebugName[sizeof(DebugName) - 1] = '\0'; // Ensure null termination
// CourseLength = j.at("CourseLength").get<std::string>().c_str();
strncpy(CourseLength, j.at("CourseLength").get<std::string>().c_str(), sizeof(CourseLength) - 1);
CourseLength[sizeof(CourseLength) - 1] = '\0'; // Ensure null termination
AIBehaviour = j.at("AIBehaviour").get<std::string>().c_str();
LakituTowType = j.at("LakituTowType").get<int>();
AIMaximumSeparation = j.at("AIMaximumSeparation").get<float>();
AIMinimumSeparation = j.at("AIMinimumSeparation").get<float>();
NearPersp = j.at("NearPersp").get<float>();
FarPersp = j.at("FarPersp").get<float>();
const auto temp = j.at("AIDistance").get<std::vector<int16_t>>();
// Ensure the vector has 32 entries
if (temp.size() == 32) {
// Copy the data into the existing AIDistances array
std::copy(temp.begin(), temp.end(), AIDistance);
} else {
printf("Course::from_json() AIDistance array not size of 32\n");
}
AISteeringSensitivity = j.at("AISteeringSensitivity").get<uint32_t>();
// Deserialize PathSizes and other custom structs if needed
D_0D009418[0] = j.at("D_0D009418")[0].get<float>();
D_0D009418[1] = j.at("D_0D009418")[1].get<float>();
D_0D009418[2] = j.at("D_0D009418")[2].get<float>();
D_0D009418[3] = j.at("D_0D009418")[3].get<float>();
D_0D009568[0] = j.at("D_0D009568")[0].get<float>();
D_0D009568[1] = j.at("D_0D009568")[1].get<float>();
D_0D009568[2] = j.at("D_0D009568")[2].get<float>();
D_0D009568[3] = j.at("D_0D009568")[3].get<float>();
D_0D0096B8[0] = j.at("D_0D0096B8")[0].get<float>();
D_0D0096B8[1] = j.at("D_0D0096B8")[1].get<float>();
D_0D0096B8[2] = j.at("D_0D0096B8")[2].get<float>();
D_0D0096B8[3] = j.at("D_0D0096B8")[3].get<float>();
D_0D009808[0] = j.at("D_0D009808")[0].get<float>();
D_0D009808[1] = j.at("D_0D009808")[1].get<float>();
D_0D009808[2] = j.at("D_0D009808")[2].get<float>();
D_0D009808[3] = j.at("D_0D009808")[3].get<float>();
// Deserialize arrays PathTable and PathTable2 similarly
//Clouds = nullptr; // Deserialize if data is present
//CloudList = nullptr; // Deserialize if data is present
Minimap.Pos[0].X = j.at("MinimapPosition")[0].get<int32_t>();
Minimap.Pos[0].Y = j.at("MinimapPosition")[1].get<int32_t>();
Minimap.Pos[1].X = j.at("MinimapPosition2P")[0].get<int32_t>();
Minimap.Pos[1].Y = j.at("MinimapPosition2P")[1].get<int32_t>();
Minimap.PlayerX = j.at("MinimapPlayerX").get<int32_t>();
Minimap.PlayerY = j.at("MinimapPlayerY").get<int32_t>();
Minimap.PlayerScaleFactor = j.at("MinimapPlayerScaleFactor").get<float>();
Minimap.FinishlineX = j.at("MinimapFinishlineX").get<float>();
Minimap.FinishlineY = j.at("MinimapFinishlineY").get<float>();
Minimap.Colour.r = j.at("MinimapColour")[0].get<uint8_t>();
Minimap.Colour.g = j.at("MinimapColour")[1].get<uint8_t>();
Minimap.Colour.b = j.at("MinimapColour")[2].get<uint8_t>();
//textures = nullptr; // Deserialize textures if present
Sequence = static_cast<MusicSeq>(j.at("Sequence").get<int>());
WaterLevel = j.at("WaterLevel").get<float>();
}
void SetText(char* name, const char* title, size_t bufferSize) {
// Copy the title into the name buffer, ensuring it's null-terminated and within bounds
std::strncpy(name, title, bufferSize - 1);
name[bufferSize - 1] = '\0'; // Ensure the string is null-terminated
}
const char* GetName() {
return Name;
}
void New() {
SetText(Name, "", sizeof(Name));
SetText(DebugName, "", sizeof(DebugName));
SetText(CourseLength, "", sizeof(CourseLength));
}
#endif
} Properties;
#ifdef __cplusplus
class World; // <-- Forward declare
class Course {
public:
std::string Id;
Properties Props;
// This allows multiple water levels in a map.
// Ex. DK Jungle where there's a waterfall and you can drive above and below it.
std::vector<WaterVolume> WaterVolumes;
const char* vtx = nullptr;
const char* gfx = nullptr;
size_t gfxSize = 0;
const course_texture* textures = nullptr;
bool bSpawnFinishline = true;
std::optional<FVector> FinishlineSpawnPoint;
std::string TrackSectionsPtr;
bool bIsMod = false;
virtual ~Course() = default;
explicit Course();
virtual void LoadO2R(std::string trackPath); // Load custom track from o2r
virtual void Load(); // Decompress and load stock courses or from o2r but TrackSectionsPtr must be set.
virtual void Load(Vtx* vtx, Gfx *gfx); // Load custom track from code. Load must be overridden and then call to this base class method impl.
virtual void LoadTextures();
virtual void ParseCourseSections(TrackSectionsO2R* sections, size_t size);
/**
* @brief BeginPlay This function is called once at the start of gameplay.
* Actor spawning should go here.
*/
virtual void BeginPlay();
virtual void TestPath();
virtual void InitClouds();
virtual void UpdateClouds(s32, Camera*);
virtual void SomeCollisionThing(Player *player, Vec3f arg1, Vec3f arg2, Vec3f arg3, f32* arg4, f32* arg5, f32* arg6, f32* arg7);
virtual void InitCourseObjects();
virtual void UpdateCourseObjects();
virtual void RenderCourseObjects(s32 cameraId);
virtual void SomeSounds();
virtual void CreditsSpawnActors();
virtual void WhatDoesThisDo(Player*, int8_t);
virtual void WhatDoesThisDoAI(Player*, int8_t);
virtual void SetStaffGhost();
virtual void Render(struct UnkStruct_800DC5EC*);
virtual void RenderCredits();
virtual void Waypoints(Player* player, int8_t playerId);
virtual f32 GetWaterLevel(FVector pos, Collision* collision);
virtual void ScrollingTextures();
virtual void DrawWater(struct UnkStruct_800DC5EC* screen, uint16_t pathCounter, uint16_t cameraRot, uint16_t playerDirection);
virtual void Destroy();
virtual bool IsMod();
private:
void Init();
};
#endif
#endif // ENGINE_COURSE_H
|