NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
d_mj2d_data.cpp
1#include <types.h>
2#include <lib/MSL_C/string.h>
3#include <game/bases/d_mj2d_data.hpp>
4
5const u32 dMj2dGame_c::sDefaultCharacters[PLAYER_COUNT] = {PLAYER_MARIO, PLAYER_LUIGI, PLAYER_YELLOW_TOAD, PLAYER_BLUE_TOAD};
6
8
10
11 // Clear slot and set version and completion
12 memset(this, 0, sizeof(dMj2dGame_c));
16
17 // Unlock the rescue stage for each world
18 for (int world = 0; world <= NORMAL_WORLD_COUNT; world++) {
19 onCourseDataFlag(world, STAGE_RESCUE, GOAL_MASK);
20 }
21
22 // Initialize the player data
23 for (int player = 0; player < PLAYER_COUNT; player++) {
24 setPlrID(player, sDefaultCharacters[player]);
25 setPlrMode(player, POWERUP_NONE);
27 setCreateItem(player, CREATE_ITEM_NONE);
28 }
29
30 // Initialize map data
31 for (int world = 0; world < WORLD_COUNT; world++) {
32 setKinopioCourseNo(world, STAGE_COUNT);
33
34 for (int enemy = 0; enemy < AMBUSH_ENEMY_COUNT; enemy++) {
35 setCSEnemyPosIndex(world, enemy, -1);
36 setCSEnemyWalkDir(world, enemy, 2);
37 }
38 }
39
40 setIbaraNow(2);
41};
42
50
51void dMj2dGame_c::setPlrID(int player, int character) {
52 mPlayerCharacter[player] = character;
53}
54
55int dMj2dGame_c::getPlrID(int player) const {
56 return mPlayerCharacter[player];
57}
58
59void dMj2dGame_c::setPlrMode(int player, u8 powerup) {
60 mPlayerPowerup[player] = powerup;
61}
62
63int dMj2dGame_c::getPlrMode(int player) const {
64 return mPlayerPowerup[player];
65}
66
67void dMj2dGame_c::setRest(int player, u8 lives) {
68 mPlayerLife[player] = lives;
69}
70
71int dMj2dGame_c::getRest(int player) const {
72 return mPlayerLife[player];
73}
74
75void dMj2dGame_c::setCreateItem(int player, u8 flag) {
77}
78
79int dMj2dGame_c::getCreateItem(int player) const {
81}
82
83void dMj2dGame_c::setCoin(int player, s8 coins) {
84 mPlayerCoin[player] = coins;
85}
86
87s8 dMj2dGame_c::getCoin(int player) const {
88 return mPlayerCoin[player];
89}
90
91void dMj2dGame_c::setScore(ulong score) {
92 mScore = score;
93}
94
96 return mScore;
97}
98
100 if (mStaffRollHighScore < score) {
101 mStaffRollHighScore = score;
102 }
103}
104
108
110 mOtehonMenuOpen[movie] = true;
111}
112
114 return mOtehonMenuOpen[movie] != 0;
115}
116
117void dMj2dGame_c::setCollectCoin(int world, int level, u8 coins) {
118 onCourseDataFlag(world, level, coins & COIN_MASK);
119}
120
122 int coinCount = 0;
123 for (int level = 0; level < STAGE_COUNT; level++) {
124 for (u32 coin = 0; coin < STAR_COIN_COUNT; coin++) {
125 if (isCollectCoin(world, level, coin) & 0xFF) {
126 coinCount++;
127 }
128 }
129 }
130
131 return coinCount;
132}
133
134u8 dMj2dGame_c::isCollectCoin(int world, int level, int coin) const {
135 return 1 << coin & mStageCompletion[world][level];
136}
137
138void dMj2dGame_c::setStartKinokoKind(int world, u8 type) {
139 mStartKinokoType[world] = type;
140}
141
143 return mStartKinokoType[world];
144}
145
146void dMj2dGame_c::setDeathCount(int world, int level, bool isSwitchPressed, u8 count) {
147 if (count >= SUPER_GUIDE_DEATH_COUNT && world < NORMAL_WORLD_COUNT && (level <= STAGE_CASTLE || level == STAGE_DOOMSHIP)) {
149 }
150
151 // [Hardcoded check for World 3-4]
152 if (isSwitchPressed && world == WORLD_3 && level == STAGE_4) {
153 setSwitchDeathCount(count);
154 } else {
155 mDeathCount[world][level] = count;
156 }
157}
158
159int dMj2dGame_c::getDeathCount(int world, int level, bool isSwitchPressed) const {
160 // [Hardcoded check for World 3-4]
161 if (isSwitchPressed && world == WORLD_3 && level == STAGE_4) {
162 return getSwitchDeathCount();
163 }
164
165 return mDeathCount[world][level];
166}
167
169 mDeathCountSwitch = count;
170}
171
175
176void dMj2dGame_c::setContinue(int player, s8 continues) {
177 mPlayerContinue[player] = continues;
178}
179
180s8 dMj2dGame_c::getContinue(int player) const {
181 return mPlayerContinue[player];
182}
183void dMj2dGame_c::setStockItem(int item, s8 count) {
184 if (count > MAX_STOCK_ITEM) {
185 count = MAX_STOCK_ITEM;
186 }
187
188 mStockItemCount[item] = count;
189}
190
191u8 dMj2dGame_c::isWorldDataFlag(int world, u8 flag) const {
192 return flag & mWorldCompletion[world];
193}
194
195void dMj2dGame_c::onWorldDataFlag(int world, u8 flag) {
196 mWorldCompletion[world] |= flag;
197}
198
199void dMj2dGame_c::offWorldDataFlag(int world, u8 flag) {
200 mWorldCompletion[world] &= ~flag;
201}
202
203int dMj2dGame_c::getCourseDataFlag(int world, int level) const {
204 return mStageCompletion[world][level];
205}
206
207bool dMj2dGame_c::isCourseDataFlag(int world, int level, ulong flag) const {
208 return (mStageCompletion[world][level] & flag) != 0;
209}
210
211void dMj2dGame_c::onCourseDataFlag(int world, int level, ulong flag) {
212 mStageCompletion[world][level] |= flag;
213}
214
215void dMj2dGame_c::offCourseDataFlag(int world, int level, ulong flag) {
216 mStageCompletion[world][level] &= ~flag;
217}
218
219void dMj2dGame_c::setCSEnemyRevivalCnt(int world, int enemy, int count) {
220 mEnemyRevivalCount[world][enemy] = count;
221}
222
223u8 dMj2dGame_c::getCSEnemyRevivalCnt(int world, int enemy) const {
224 return mEnemyRevivalCount[world][enemy];
225}
226
227void dMj2dGame_c::setCSEnemySceneNo(int world, int enemy, u8 subworld) {
228 mEnemySceneNo[world][enemy] = subworld;
229}
230
231u8 dMj2dGame_c::getCSEnemySceneNo(int world, int enemy) const {
232 return mEnemySceneNo[world][enemy];
233}
234
235void dMj2dGame_c::setCSEnemyPosIndex(int world, int enemy, u8 node) {
236 mEnemyPosIndex[world][enemy] = node;
237}
238
239u8 dMj2dGame_c::getCSEnemyPosIndex(int world, int enemy) const {
240 return mEnemyPosIndex[world][enemy];
241}
242
243void dMj2dGame_c::setCSEnemyWalkDir(int world, int enemy, u8 direction) {
244 mEnemyWalkDir[world][enemy] = direction;
245}
246
247u8 dMj2dGame_c::getCSEnemyWalkDir(int world, int enemy) const {
248 return mEnemyWalkDir[world][enemy];
249}
250
251void dMj2dGame_c::setKinopioCourseNo(int world, int level) {
252 mKinopioCourseNo[world] = level;
253}
254
256 return mKinopioCourseNo[world];
257}
258
259void dMj2dGame_c::setIbaraNow(int ibaraNow) {
260 mIbaraNow = ibaraNow;
261}
262
264 return mIbaraNow;
265}
266
269
271 memset(this, 0, sizeof(dMj2dHeader_c));
272
273 mMagic[0] = SAVE_MAGIC[0];
274 mMagic[1] = SAVE_MAGIC[1];
275 mMagic[2] = SAVE_MAGIC[2];
276 mMagic[3] = SAVE_MAGIC[3];
277
280}
281
283 mLastSelectedFile = fileNum;
284}
285
286u16 dMj2dHeader_c::getPlayCountFreeMode(int world, int level) const {
287 return mPlayCountFreeMode[world][level];
288}
289
290void dMj2dHeader_c::setPlayCountFreeMode(int world, int level, int count) {
291 mPlayCountFreeMode[world][level] = count;
292}
293
294u16 dMj2dHeader_c::getPlayCountCoinBattle(int world, int level) const {
295 return mPlayCountCoinBattle[world][level];
296}
297
298void dMj2dHeader_c::setPlayCountCoinBattle(int world, int level, int count) {
299 mPlayCountCoinBattle[world][level] = count;
300}
301
303 mMultiWorldOpenFlag |= 1 << world;
304}
305
307 return mMultiWorldOpenFlag & (1 << world);
308}
309
Save slot data holder.
u8 getCSEnemyPosIndex(int world, int enemy) const
Gets the path node for the given map enemy.
@ SUPER_GUIDE_TRIGGERED
The player died at least SUPER_GUIDE_DEATH_COUNT times in a single stage.
@ SAVE_EMPTY
The slot is empty.
int getSwitchDeathCount() const
Gets the death count for World 3-4 for the worldmap switch-enabled variant.
s8 getContinue(int player) const
Gets player 's continue count.
u8 mIbaraNow
The worldmap vine reshuffle counter.
u32 mStageCompletion[WORLD_COUNT][STAGE_COUNT]
The completion flags for each level. See COURSE_COMPLETION_e.
int getStartKinokoKind(int world) const
Gets the starting Toad House type in the given world. See START_KINOKO_KIND_e.
void offCourseDataFlag(int world, int level, ulong flag)
Unsets the completion flag(s) for the given world/level. See COURSE_COMPLETION_e.
void setScore(ulong score)
Sets the score.
u8 mEnemySceneNo[WORLD_COUNT][AMBUSH_ENEMY_COUNT]
The subworld number for each map enemy.
void setSwitchDeathCount(u8 count)
Sets the death count for World 3-4 for the worldmap switch-enabled variant.
void setStockItem(int item, s8 count)
Sets the inventory amount for the given item.
u8 mPlayerContinue[PLAYER_COUNT]
The continue count for each player.
void setCSEnemySceneNo(int world, int enemy, u8 subworld)
Sets the subworld number for the given map enemy.
bool mOtehonMenuOpen[HINT_MOVIE_COUNT]
The hint movie bought status for each movie.
u8 getCSEnemySceneNo(int world, int enemy) const
Gets the subworld number for the given map enemy.
u16 mStaffRollHighScore
The staff credits high score.
u8 mPlayerCreateItem[PLAYER_COUNT]
The Star Power flag for each player. See PLAYER_CREATE_ITEM_e.
u8 getCSEnemyWalkDir(int world, int enemy) const
Gets the path direction for the given map enemy.
void setContinue(int player, s8 continues)
Sets player 's continue count.
void setPlrID(int player, int character)
Sets player 's character. See PLAYER_CHARACTER_e.
u8 mEnemyRevivalCount[WORLD_COUNT][AMBUSH_ENEMY_COUNT]
The revival counter for each map enemy.
void initialize()
Initializes the slot data.
u8 mPlayerPowerup[PLAYER_COUNT]
The powerup for each player. See PLAYER_POWERUP_e.
void onCourseDataFlag(int world, int level, ulong flag)
Sets the completion flag(s) for the given world/level. See COURSE_COMPLETION_e.
u8 getCSEnemyRevivalCnt(int world, int enemy) const
Gets the revival counter for the given map enemy.
void setRest(int player, u8 lives)
Sets player 's life count.
int getRest(int player) const
Gets player 's life count.
void setStaffCreditHighScore(u16 score)
Sets the staff credit high score.
u32 mScore
The regular score.
u8 isWorldDataFlag(int world, u8 flag) const
Checks if the completion flag(s) for the given world is set. See WORLD_COMPLETION_e.
void setDeathCount(int world, int level, bool isSwitchPressed, u8 count)
Sets the death count in a specific stage.
u8 mStockItemCount[POWERUP_COUNT]
The inventory amount for each item.
u8 mDeathCount[WORLD_COUNT][STAGE_COUNT]
The death count for each level.
void setIbaraNow(int ibaraNow)
Sets the worldmap vine reshuffle counter.
void setCSEnemyPosIndex(int world, int enemy, u8 node)
Sets the path node for the given map enemy.
void setStartKinokoKind(int world, u8 type)
Sets the starting Toad House type in the given world. See START_KINOKO_KIND_e.
u8 mGameCompletion
The overall completion of the save slot. See GAME_COMPLETION_e.
u8 mEnemyWalkDir[WORLD_COUNT][AMBUSH_ENEMY_COUNT]
The movement direction for each map enemy.
int getCourseDataFlag(int world, int level) const
Gets all the completion flags for the given world/level. See COURSE_COMPLETION_e.
int getDeathCount(int world, int level, bool isSwitchPressed) const
Gets the death count in a specific stage.
void setPlrMode(int player, u8 powerup)
Sets player 's powerup. See PLAYER_POWERUP_e.
void setCSEnemyRevivalCnt(int world, int enemy, int count)
Sets the revival counter for the given map enemy.
int getScore() const
Gets the score.
u8 isCollectCoin(int world, int level, int coin) const
Checks if the given Star Coin has been obtained in the given world/level.
int getPlrID(int player) const
Gets player 's character. See PLAYER_CHARACTER_e.
void setCreateItem(int player, u8 flag)
Sets player 's createItem flag. See PLAYER_CREATE_ITEM_e.
u8 mPlayerCharacter[PLAYER_COUNT]
The character for each player. See PLAYER_CHARACTER_e.
void setCollectCoin(int world, int level, u8 coins)
Sets the obtained Star Coin(s) for the given world/level. See COURSE_COMPLETION_e.
u8 mPlayerLife[PLAYER_COUNT]
The life count for each player.
void versionUpdate()
Checks that the save data version matches the current one and clears the slot if not.
bool isCourseDataFlag(int world, int level, ulong flag) const
Checks if the completion flag for the given world/level is set. See COURSE_COMPLETION_e.
void offWorldDataFlag(int world, u8 flag)
Unsets the specified flag(s) for the given world. See WORLD_COMPLETION_e.
int getPlrMode(int player) const
Gets player 's powerup. See PLAYER_POWERUP_e.
u8 mDeathCountSwitch
The death count for the worldmap switch variant of World 3-4. See mDeathCount.
void onOtehonMenuOpenFlag(int movie)
Sets the given hint movie as bought.
u8 mRevision[2]
The save data version and subversion. See SAVE_REVISION_MAJOR and SAVE_REVISION_MINOR.
bool isOtehonMenuOpenFlag(int movie) const
Checks if the given hint movie was bought.
void onWorldDataFlag(int world, u8 flag)
Sets the specified flag(s) for the given world. See WORLD_COMPLETION_e.
void setKinopioCourseNo(int world, int level)
Sets the Toad rescue level for the given world.
u8 mEnemyPosIndex[WORLD_COUNT][AMBUSH_ENEMY_COUNT]
The path node for each map enemy.
u8 mKinopioCourseNo[WORLD_COUNT]
The Toad Rescue level for each world.
u8 mWorldCompletion[WORLD_COUNT]
The completion flags for each world. See WORLD_COMPLETION_e.
s8 mPlayerCoin[PLAYER_COUNT]
The coin count for each player.
void setCoin(int player, s8 coins)
Sets player 's coin count.
dMj2dGame_c()
Constructs the holder.
u8 mStartKinokoType[WORLD_COUNT]
The starting Toad House type for each world. See START_KINOKO_KIND_e.
int getTotalWorldCollectCoin(int world)
Gets the obtainable Star Coin count for the given world.
int getCreateItem(int player) const
Gets player 's createItem flag. See PLAYER_CREATE_ITEM_e.
u8 getKinopioCourseNo(int world) const
Gets the Toad rescue level for the given world.
static const u32 sDefaultCharacters[4]
The default character for each player.
s8 getCoin(int player) const
Gets player 's coin count.
void setCSEnemyWalkDir(int world, int enemy, u8 direction)
Sets the path direction for the given map enemy.
int getStaffCreditHighScore() const
Gets the staff credit high score.
u8 getIbaraNow() const
Gets the worldmap vine reshuffle counter.
Represents the header of the game's save file.
void setPlayCountFreeMode(int world, int level, int count)
Sets the Free Mode play count for the given world/level. See mPlayCountFreeMode.
u16 mPlayCountFreeMode[WORLD_COUNT][STAGE_COUNT]
The play count of each level in Free Mode.
bool isMultiWorldOpenFlag(int world)
Checks if the given world is unlocked in extra modes.
char mMagic[4]
The savegame magic. See SAVE_MAGIC.
u16 mPlayCountCoinBattle[WORLD_COUNT][STAGE_COUNT]
The play count of each level in Coin Battle.
void initialize()
Initializes the header data.
dMj2dHeader_c()
Constructs the holder.
void versionUpdate()
Ensures that the save's major revision number matches the current one.
void setPlayCountCoinBattle(int world, int level, int count)
Sets the Coin Battle play count for the given world/level. See mPlayCountCoinBattle.
u16 getPlayCountFreeMode(int world, int level) const
Gets the Free Mode play count for the given world/level. See mPlayCountFreeMode.
void setSelectFileNo(s8 file)
Sets the last used save data slot.
u8 mRevision[2]
The save revision numbers. See SAVE_REVISION_MAJOR and SAVE_REVISION_MINOR.
u16 mMultiWorldOpenFlag
The worlds unlocked in Extra Modes.
void onMultiWorldOpenFlag(int world)
Unlocks the given world in extra modes.
u8 mLastSelectedFile
The last selected save data slot.
u16 getPlayCountCoinBattle(int world, int level) const
Gets the Coin Battle play count for the given world/level. See mPlayCountCoinBattle.
#define SAVE_REVISION_MAJOR
The savegame's major revision number.
#define SUPER_GUIDE_DEATH_COUNT
The amount of deaths required for the Super Guide to show.
#define STARTING_LIVES_COUNT
The amount of starting lives.
#define STAR_COIN_COUNT
The amount of Star Coins per level.
#define SAVE_MAGIC
The savegame's magic.
#define AMBUSH_ENEMY_COUNT
The maximum amount of ambush enemies per world map.
#define MAX_STOCK_ITEM
The maximum inventory amount per item.
#define SAVE_REVISION_MINOR
The savegame's minor revision number.
@ CREATE_ITEM_STAR_POWER
Gives the player Star Power.
@ STAGE_RESCUE
When used, it loads the Toad Rescue level for the corresponding world.