NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
d_wm_csvdata.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <types.h>
4#include <game/mLib/m_3d.hpp>
5/// @file
6
7#define MAX_POINT_COUNT (192)
8#define MAX_SUBROUTE_COUNT (160)
9#define MAX_ROUTE_COUNT (64)
10
11#define MAX_POINT_NAME_LEN (5)
12#define MAX_ROUTE_NAME_LEN (10)
13#define MAX_FLAG_DATA_LEN (10)
14
15#define MAX_OPEN_POINT_COUNT (4)
16#define MAX_OPEN_ROUTE_COUNT (16)
17#define MAX_FLAG_DATA_COUNT (2)
18
19#define SUBWORLD_CHAR_OFFSET (10) // The position of 'a' in "Wx/pointWxa.csv"
20
21/// @brief Loader for world map point / route data.
22/// @ingroup bases
24public:
25 /// @unofficial
27 POINT_URA = BIT_FLAG(0),
28 POINT_STOP = BIT_FLAG(1),
29 POINT_LINK1 = BIT_FLAG(2),
30 POINT_LINK2 = BIT_FLAG(3),
31 POINT_LINK3 = BIT_FLAG(4),
32 POINT_LINK4 = BIT_FLAG(5),
33 POINT_LINK5 = BIT_FLAG(6),
34 POINT_SCROLL = BIT_FLAG(7),
35 POINT_SCALE = BIT_FLAG(8),
36 POINT_DOKAN = BIT_FLAG(10),
37 POINT_SWITCH = BIT_FLAG(11),
38 POINT_ANCHOR_X = BIT_FLAG(12),
39 POINT_ANCHOR_Y = BIT_FLAG(13),
40 POINT_TILT = BIT_FLAG(14),
41 POINT_DEMO1 = BIT_FLAG(15),
42 POINT_DEMO2 = BIT_FLAG(16),
43 POINT_DEMO3 = BIT_FLAG(17),
44 POINT_CROSSROAD = BIT_FLAG(18),
45 POINT_FOCUS = BIT_FLAG(19),
46 POINT_BOARD = BIT_FLAG(20),
47 POINT_DEMOSTOP = BIT_FLAG(21),
48 POINT_SCROLL_Y = BIT_FLAG(22),
49 POINT_SAND = BIT_FLAG(23),
50 POINT_ICE = BIT_FLAG(24),
51 POINT_DEMO4 = BIT_FLAG(25),
52 POINT_DEMO5 = BIT_FLAG(26),
53 POINT_DEMO6 = BIT_FLAG(27),
54 POINT_DEMO7 = BIT_FLAG(28),
55 POINT_CAMSTOP = BIT_FLAG(29),
56 POINT_NOSHIFT = BIT_FLAG(30),
57 POINT_SCROLL_A = BIT_FLAG(31)
58 };
59
60 /// @unofficial
62 ENEMY_KURIBO1 = BIT_FLAG(1),
63 ENEMY_KURIBO2 = BIT_FLAG(2),
64 ENEMY_PUKU1 = BIT_FLAG(3),
65 ENEMY_PUKU2 = BIT_FLAG(4),
66 ENEMY_PAK1 = BIT_FLAG(5),
67 ENEMY_PAK2 = BIT_FLAG(6),
68 ENEMY_PAK3 = BIT_FLAG(7),
69 ENEMY_HBROS1 = BIT_FLAG(8),
70 ENEMY_TRAP1 = BIT_FLAG(10),
71 ENEMY_TRAP2 = BIT_FLAG(11)
72 };
73
74 /// @unofficial
76 ACTION_TYPE_NONE = -1,
77 ACTION_TYPE_0, ///< @unused
78 ACTION_TYPE_1, ///< @unused
79 ACTION_TYPE_ROAD,
80 ACTION_TYPE_LADDER,
81 ACTION_TYPE_JUMP,
82 ACTION_TYPE_5, ///< @unused
83 ACTION_TYPE_VINE,
84 ACTION_TYPE_SLOPE,
85 ACTION_TYPE_ICE_SLOPE,
86 ACTION_TYPE_SWITCH_BLOCK = 14,
87 ACTION_TYPE_SAND,
88 ACTION_TYPE_QUICKSAND,
89 ACTION_TYPE_SNOW,
90 ACTION_TYPE_ICE,
91 ACTION_TYPE_CLOUD,
92 ACTION_TYPE_WATER,
93 ACTION_TYPE_LEFT_LADDER,
94 ACTION_TYPE_RIGHT_LADDER,
95 ACTION_TYPE_DIRT,
96 ACTION_TYPE_ROCK_LADDER,
97 ACTION_TYPE_ROPE_LADDER,
98 ACTION_TYPE_WOOD
99 };
100
101 /// @brief Contains the data for a single point on the world map.
102 struct Point_s {
103 char mName[MAX_POINT_NAME_LEN]; ///< The name of the point.
104 char mOpenPointNameRegular[MAX_OPEN_POINT_COUNT][MAX_POINT_NAME_LEN]; ///< The points to be opened by the regular exit.
105 char mRouteNameRegular[MAX_OPEN_ROUTE_COUNT][MAX_ROUTE_NAME_LEN]; ///< The routes to be opened by the regular exit.
106 char mOpenPointNameSecret[MAX_OPEN_POINT_COUNT][MAX_POINT_NAME_LEN]; ///< The points to be opened by the secret exit.
107 char mRouteNameSecret[MAX_OPEN_ROUTE_COUNT][MAX_ROUTE_NAME_LEN]; ///< The routes to be opened by the secret exit.
108 int mOpenPointNumRegular; ///< The number of points in mOpenPointNameRegular.
109 int mOpenRouteNumRegular; ///< The number of routes in mRouteNameRegular.
110 int mOpenRouteNumSecret; ///< The number of routes in mRouteNameSecret.
111 int mOpenPointNumSecret; ///< The number of points in mOpenPointNameSecret.
112 char mFlagDataRegular[MAX_FLAG_DATA_COUNT][MAX_FLAG_DATA_LEN]; ///< The point flag data for the regular exit.
113 char mFlagDataSecret[MAX_FLAG_DATA_COUNT][MAX_FLAG_DATA_LEN]; ///< The point flag data for the secret exit.
114 int mFlagDataNumRegular; ///< The number of entries in mFlagDataRegular.
115 int mFlagDataNumSecret; ///< The number of entries in mFlagDataSecret.
116 u32 mFlags; ///< A bitfield of PointFlag_e values.
117 u8 mParam; ///< A parameter value for the point. @decompnote{Seems to only be used for "anchor[0-9]" / "anchor[xy][0-9]" points}.
118 u32 mFlagsEnemy; ///< A bitfield of EnemyFlag_e values.
119 u8 m_1bc;
120 };
121
122 /// @brief Contains the data for a point-to-point route on the world map.
123 struct SubRoute_s {
124 char mName[MAX_ROUTE_NAME_LEN]; ///< The name of the route.
125 ActionType_e mActionType; ///< The action type of the route.
126 int m_10;
127 u8 mFlags;
128 };
129
130 /// @brief Contains the points of a route on the world map.
131 /// @details The difference between this and SubRoute_s is that a route can span multiple subroutes.
132 /// E.g. R00010003, consisting of subroutes R00010002 and R00020003 and the points 0001, 0002, and 0003.
133 struct Route_s {
134 char mName[MAX_ROUTE_NAME_LEN]; ///< The name of the route.
135 char (*mChildPoints)[MAX_POINT_NAME_LEN]; ///< The points that make up the route.
136 int mChildPointNum; ///< The number of occupied entries in mChildPoints.
137 int mNumSubroutes; ///< The number of subroutes this route is made up of.
138 };
139
140 virtual ~dCsvData_c(); ///< Destroys the class.
141
142 /// @brief Initializes the class and loads the CSV data for the specified world and subworld.
143 void initialize(int world, int subworld);
144
145 void RouteInfoInit(); ///< Resets all currently loaded point and route data.
146 void ReadCsvData(); ///< Loads the CSV point and route data for the specified world and subworld.
147
148 void ReadPointName(char *csv, int &pos); ///< Reads a point name from a CSV entry.
149 void ReadPointType(char *csv, int &pos); ///< Reads a point type from a CSV entry.
150 void ReadOpenPointName(char *csv, int &pos, bool regularExit); ///< Reads an open point name from a CSV entry.
151 void ReadOpenRouteName(char *csv, int &pos, bool regularExit); ///< Reads an open route name from a CSV entry.
152 void ReadFlagData(char *csv, int &pos, bool regularExit); ///< Reads the point flag data from a CSV entry.
153
154 void ReadAnimeRouteName(char *csv, int &pos); ///< Reads a route name from a CSV entry.
155 void ReadAction(char *csv, int &pos); ///< Reads a route action type from a CSV entry.
156 void ReadRouteFlag(char *csv, int &pos); ///< Reads the route flag data from a CSV entry.
157
158 ActionType_e GetActionLabel(const char *route); ///< Gets the action type for a given route name.
159 int GetIndexFromPointName(const char *pointName); ///< Gets the index of a point.
160
161 void addKeyPoint(const m3d::mdl_c &model); ///< Adds a key point from a model.
162 void SetRouteInfo(const m3d::mdl_c &model); ///< Creates a route from a model and adds it to the route list.
163
164 const char *GetPointName(int idx) const; ///< Returns the name of a point at the specified index.
165 const char *GetOpenPointName(bool regularExit, int idx, int openPointIdx) const; ///< Returns the name of a point that is opened from a regular or secret exit from this point.
166 int GetOpenPointNum(bool regularExit, int idx) const; ///< Returns the number of points that are opened from a regular or secret exit from this point.
167 const char *GetOpenRouteName(bool regularExit, int idx, int openRouteIdx) const; ///< Returns the name of a route that is opened from a regular or secret exit from this point.
168 int GetOpenRouteNum(bool regularExit, int idx) const; ///< Returns the number of routes that are opened from a regular or secret exit from this point.
169 u32 GetPointFlags(int idx, PointFlag_e flags) const; ///< Returns the flags ANDed with @p flags. @unofficial
170 u32 GetEnemyPointFlags(int idx, EnemyFlag_e flags) const; ///< Returns the enemy flags ANDed with @p flags. @unofficial
171 u32 GetPointParam(int idx); ///< Returns the parameter value for this point.
172
173 const char *GetRouteName(int idx); ///< Returns the name of a route at the specified index.
174 const char *GetChildPointName(int idx, int childIdx); ///< Returns the name of a point that is part of a route at the specified index.
175 const char *GetSubRouteName(int idx); ///< Returns the name of a subroute at the specified index.
176 int GetSubRouteIdx(const char *pointA, const char *pointB); ///< Returns the index of a route connecting two points.
177 int GetPointNum(int idx); ///< Returns the number of points that are part of a route at the specified index.
178 u32 GetSubRouteFlag(int idx); ///< Returns the flags for a route at the specified index.
179
180 int GetRouteAnimNum(bool regularExit, int idx); ///< Returns the number of flag data entries for a point.
181 const char *GetRouteAnimName(bool regularExit, int idx, int animIdx); ///< Returns the value of a flag data entry for a point.
182
183 /// @brief Searches the subroute graph for a path between two points and writes the length of the path to @p route.
184 /// @param startPointName The name of the starting point.
185 /// @param endPointName The name of the ending point.
186 /// @param route The route to write the path length to.
187 /// @param maxLevel The maximum depth of the search.
188 /// @param resetLevel Whether to reset the search depth counter. Should be true for the initial call and false for recursive calls.
189 /// @return True if a path was found, false otherwise.
190 /// @unofficial
191 bool findSubRoutesForRoute(const char *startPointName, const char *endPointName, Route_s *route, int maxLevel, bool resetLevel = true);
192
193 /// @brief Searches the subroute graph for a path between two points and appends the child points to @p route.
194 /// @details This function assumes the length of the path has already been determined with findSubRoutesForRoute.
195 /// @param startPointName The name of the starting point.
196 /// @param endPointName The name of the ending point.
197 /// @param route The route to write the points to.
198 /// @param maxLevel The maximum depth of the search.
199 /// @param resetLevel Whether to reset the search depth counter. Should be true for the initial call and false for recursive calls.
200 /// @return True if everything was successful, false otherwise.
201 bool appendChildFromSubRoute(const char *startPointName, const char *endPointName, Route_s *route, int maxLevel, bool resetLevel = true);
202
203 void appendChildFromModel(const nw4r::g3d::ResNode &node, int); ///< Appends the child points of a route from a model to @p route.
204 void adjustChildInfo(Route_s *route); ///< Reverses the order of the child points of a route.
205
206 bool isLineEnd(char *csv, int pos); ///< Returns whether the the CSV has a line ending at the specified position.
207
208 /// @brief Initializes a route with the specified number of child points.
209 /// @param route The route to initialize.
210 /// @param childCount The number of child points to allocate for the route.
211 static void initRouteStruct(Route_s *route, int childCount);
212
213 /// @brief Destroys a route and frees its child point data.
214 static void destroyRouteStruct(Route_s *route);
215
216private:
217 int mWorld; ///< The world number for which to load the point and route data.
218 int mSubworld; ///< The subworld number for which to load the point and route data.
219 int mPointCount; ///< The number of loaded points in mPoints.
220 int mSubrouteCount; ///< The number of loaded subroutes in mSubRoutes.
221 int mRouteCount; ///< The number of loaded routes in mRoutes.
222 Point_s mPoints[MAX_POINT_COUNT]; ///< The loaded point data.
223 SubRoute_s mSubRoutes[MAX_SUBROUTE_COUNT]; ///< The loaded subroute data.
224 Route_s mRoutes[MAX_ROUTE_COUNT]; ///< The loaded route data.
225
226public:
227 static const int c_COURSE_ID;
228 static const int c_GHOST_ID;
229 static const int c_TOWER_ID;
230 static const int c_CASTLE_ID;
231 static const int c_KINOKO_ID;
232 static const int c_ENEMY_ID;
233 static const int c_CANON_ID;
234 static const int c_TRSHIP_ID;
235 static const int c_AIRSHIP_ID;
236 static const int c_START_ID;
237 static const int c_PEACH_ID;
238};
Loader for world map point / route data.
u32 GetPointFlags(int idx, PointFlag_e flags) const
Returns the flags ANDed with flags.
Route_s mRoutes[(64)]
The loaded route data.
SubRoute_s mSubRoutes[(160)]
The loaded subroute data.
int GetOpenPointNum(bool regularExit, int idx) const
Returns the number of points that are opened from a regular or secret exit from this point.
bool findSubRoutesForRoute(const char *startPointName, const char *endPointName, Route_s *route, int maxLevel, bool resetLevel=true)
Searches the subroute graph for a path between two points and writes the length of the path to route.
virtual ~dCsvData_c()
Destroys the class.
bool isLineEnd(char *csv, int pos)
Returns whether the the CSV has a line ending at the specified position.
const char * GetRouteAnimName(bool regularExit, int idx, int animIdx)
Returns the value of a flag data entry for a point.
ActionType_e GetActionLabel(const char *route)
Gets the action type for a given route name.
const char * GetOpenRouteName(bool regularExit, int idx, int openRouteIdx) const
Returns the name of a route that is opened from a regular or secret exit from this point.
int GetPointNum(int idx)
Returns the number of points that are part of a route at the specified index.
void ReadPointType(char *csv, int &pos)
Reads a point type from a CSV entry.
int mWorld
The world number for which to load the point and route data.
void RouteInfoInit()
Resets all currently loaded point and route data.
int GetOpenRouteNum(bool regularExit, int idx) const
Returns the number of routes that are opened from a regular or secret exit from this point.
const char * GetChildPointName(int idx, int childIdx)
Returns the name of a point that is part of a route at the specified index.
void ReadRouteFlag(char *csv, int &pos)
Reads the route flag data from a CSV entry.
int mSubrouteCount
The number of loaded subroutes in mSubRoutes.
int mRouteCount
The number of loaded routes in mRoutes.
void ReadOpenRouteName(char *csv, int &pos, bool regularExit)
Reads an open route name from a CSV entry.
u32 GetSubRouteFlag(int idx)
Returns the flags for a route at the specified index.
int GetSubRouteIdx(const char *pointA, const char *pointB)
Returns the index of a route connecting two points.
int mPointCount
The number of loaded points in mPoints.
void ReadPointName(char *csv, int &pos)
Reads a point name from a CSV entry.
const char * GetPointName(int idx) const
Returns the name of a point at the specified index.
const char * GetOpenPointName(bool regularExit, int idx, int openPointIdx) const
Returns the name of a point that is opened from a regular or secret exit from this point.
void SetRouteInfo(const m3d::mdl_c &model)
Creates a route from a model and adds it to the route list.
void initialize(int world, int subworld)
Initializes the class and loads the CSV data for the specified world and subworld.
void ReadOpenPointName(char *csv, int &pos, bool regularExit)
Reads an open point name from a CSV entry.
u32 GetEnemyPointFlags(int idx, EnemyFlag_e flags) const
Returns the enemy flags ANDed with flags.
static void initRouteStruct(Route_s *route, int childCount)
Initializes a route with the specified number of child points.
void ReadCsvData()
Loads the CSV point and route data for the specified world and subworld.
void ReadAnimeRouteName(char *csv, int &pos)
Reads a route name from a CSV entry.
const char * GetRouteName(int idx)
Returns the name of a route at the specified index.
int GetIndexFromPointName(const char *pointName)
Gets the index of a point.
Point_s mPoints[(192)]
The loaded point data.
const char * GetSubRouteName(int idx)
Returns the name of a subroute at the specified index.
bool appendChildFromSubRoute(const char *startPointName, const char *endPointName, Route_s *route, int maxLevel, bool resetLevel=true)
Searches the subroute graph for a path between two points and appends the child points to route.
int GetRouteAnimNum(bool regularExit, int idx)
Returns the number of flag data entries for a point.
int mSubworld
The subworld number for which to load the point and route data.
void appendChildFromModel(const nw4r::g3d::ResNode &node, int)
Appends the child points of a route from a model to route.
void ReadFlagData(char *csv, int &pos, bool regularExit)
Reads the point flag data from a CSV entry.
static void destroyRouteStruct(Route_s *route)
Destroys a route and frees its child point data.
void ReadAction(char *csv, int &pos)
Reads a route action type from a CSV entry.
void addKeyPoint(const m3d::mdl_c &model)
Adds a key point from a model.
u32 GetPointParam(int idx)
Returns the parameter value for this point.
void adjustChildInfo(Route_s *route)
Reverses the order of the child points of a route.
Contains the data for a single point on the world map.
int mOpenPointNumSecret
The number of points in mOpenPointNameSecret.
u32 mFlagsEnemy
A bitfield of EnemyFlag_e values.
int mFlagDataNumRegular
The number of entries in mFlagDataRegular.
char mOpenPointNameSecret[(4)][(5)]
The points to be opened by the secret exit.
char mFlagDataSecret[(2)][(10)]
The point flag data for the secret exit.
u8 mParam
A parameter value for the point.
char mName[(5)]
The name of the point.
int mFlagDataNumSecret
The number of entries in mFlagDataSecret.
char mRouteNameRegular[(16)][(10)]
The routes to be opened by the regular exit.
char mFlagDataRegular[(2)][(10)]
The point flag data for the regular exit.
char mOpenPointNameRegular[(4)][(5)]
The points to be opened by the regular exit.
int mOpenRouteNumSecret
The number of routes in mRouteNameSecret.
int mOpenPointNumRegular
The number of points in mOpenPointNameRegular.
int mOpenRouteNumRegular
The number of routes in mRouteNameRegular.
char mRouteNameSecret[(16)][(10)]
The routes to be opened by the secret exit.
u32 mFlags
A bitfield of PointFlag_e values.
Contains the points of a route on the world map.
int mChildPointNum
The number of occupied entries in mChildPoints.
char mName[(10)]
The name of the route.
char(* mChildPoints)[(5)]
The points that make up the route.
int mNumSubroutes
The number of subroutes this route is made up of.
Contains the data for a point-to-point route on the world map.
ActionType_e mActionType
The action type of the route.
char mName[(10)]
The name of the route.