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#include <game/bases/d_a_player_com.hpp>
5
7
9
10 // Clear slot and set version and completion
11 memset(this, 0, sizeof(dMj2dGame_c));
15
16 // Mark the starting toad house stage as cleared for each world
17 for (int world = 0; world <= NORMAL_WORLD_COUNT; world++) {
19 }
20
21 // Initialize the player data
22 for (int player = 0; player < PLAYER_COUNT; player++) {
23 setPlrID(player, daPyCom_c::sc_PLAYER_ORDER[player]);
24 setPlrMode(player, POWERUP_NONE);
26 setCreateItem(player, CREATE_ITEM_NONE);
27 }
28
29 // Initialize map data
30 for (int world = 0; world < WORLD_COUNT; world++) {
31 setKinopioCourseNo(world, STAGE_COUNT);
32
33 for (int enemy = 0; enemy < AMBUSH_ENEMY_COUNT; enemy++) {
34 setCSEnemyPosIndex(world, enemy, -1);
35 setCSEnemyWalkDir(world, enemy, 2);
36 }
37 }
38
39 setIbaraNow(2);
40};
41
49
50void dMj2dGame_c::setPlrID(int player, int character) {
51 mPlayerCharacter[player] = character;
52}
53
54int dMj2dGame_c::getPlrID(int player) const {
55 return mPlayerCharacter[player];
56}
57
58void dMj2dGame_c::setPlrMode(int player, u8 powerup) {
59 mPlayerPowerup[player] = powerup;
60}
61
62int dMj2dGame_c::getPlrMode(int player) const {
63 return mPlayerPowerup[player];
64}
65
66void dMj2dGame_c::setRest(int player, u8 lives) {
67 mPlayerLife[player] = lives;
68}
69
70int dMj2dGame_c::getRest(int player) const {
71 return mPlayerLife[player];
72}
73
74void dMj2dGame_c::setCreateItem(int player, u8 flag) {
76}
77
78int dMj2dGame_c::getCreateItem(int player) const {
80}
81
82void dMj2dGame_c::setCoin(int player, s8 coins) {
83 mPlayerCoin[player] = coins;
84}
85
86s8 dMj2dGame_c::getCoin(int player) const {
87 return mPlayerCoin[player];
88}
89
90void dMj2dGame_c::setScore(ulong score) {
91 mScore = score;
92}
93
95 return mScore;
96}
97
99 if (mStaffRollHighScore < score) {
100 mStaffRollHighScore = score;
101 }
102}
103
107
109 mOtehonMenuOpen[movie] = true;
110}
111
113 return mOtehonMenuOpen[movie] != 0;
114}
115
116void dMj2dGame_c::setCollectCoin(int world, int level, u8 coins) {
117 onCourseDataFlag(world, level, coins & COIN_MASK);
118}
119
121 int coinCount = 0;
122 for (int level = 0; level < STAGE_COUNT; level++) {
123 for (u32 coin = 0; coin < STAR_COIN_COUNT; coin++) {
124 if (isCollectCoin(world, level, coin) & 0xFF) {
125 coinCount++;
126 }
127 }
128 }
129
130 return coinCount;
131}
132
133u8 dMj2dGame_c::isCollectCoin(int world, int level, int coin) const {
134 return 1 << coin & mStageCompletion[world][level];
135}
136
137void dMj2dGame_c::setStartKinokoKind(int world, u8 type) {
138 mStartKinokoType[world] = type;
139}
140
142 return mStartKinokoType[world];
143}
144
145void dMj2dGame_c::setDeathCount(int world, int level, bool isSwitchPressed, u8 count) {
146 if (count >= SUPER_GUIDE_DEATH_COUNT && world < NORMAL_WORLD_COUNT && (level <= STAGE_CASTLE || level == STAGE_DOOMSHIP)) {
148 }
149
150 // [Hardcoded check for World 3-4]
151 if (isSwitchPressed && world == WORLD_3 && level == STAGE_4) {
152 setSwitchDeathCount(count);
153 } else {
154 mDeathCount[world][level] = count;
155 }
156}
157
158int dMj2dGame_c::getDeathCount(int world, int level, bool isSwitchPressed) const {
159 // [Hardcoded check for World 3-4]
160 if (isSwitchPressed && world == WORLD_3 && level == STAGE_4) {
161 return getSwitchDeathCount();
162 }
163
164 return mDeathCount[world][level];
165}
166
168 mDeathCountSwitch = count;
169}
170
174
175void dMj2dGame_c::setContinue(int player, s8 continues) {
176 mPlayerContinue[player] = continues;
177}
178
179s8 dMj2dGame_c::getContinue(int player) const {
180 return mPlayerContinue[player];
181}
182void dMj2dGame_c::setStockItem(int item, s8 count) {
183 if (count > MAX_STOCK_ITEM) {
184 count = MAX_STOCK_ITEM;
185 }
186
187 mStockItemCount[item] = count;
188}
189
190u8 dMj2dGame_c::isWorldDataFlag(int world, u8 flag) const {
191 return flag & mWorldCompletion[world];
192}
193
194void dMj2dGame_c::onWorldDataFlag(int world, u8 flag) {
195 mWorldCompletion[world] |= flag;
196}
197
198void dMj2dGame_c::offWorldDataFlag(int world, u8 flag) {
199 mWorldCompletion[world] &= ~flag;
200}
201
202int dMj2dGame_c::getCourseDataFlag(int world, int level) const {
203 return mStageCompletion[world][level];
204}
205
206bool dMj2dGame_c::isCourseDataFlag(int world, int level, ulong flag) const {
207 return (mStageCompletion[world][level] & flag) != 0;
208}
209
210void dMj2dGame_c::onCourseDataFlag(int world, int level, ulong flag) {
211 mStageCompletion[world][level] |= flag;
212}
213
214void dMj2dGame_c::offCourseDataFlag(int world, int level, ulong flag) {
215 mStageCompletion[world][level] &= ~flag;
216}
217
218void dMj2dGame_c::setCSEnemyRevivalCnt(int world, int enemy, int count) {
219 mEnemyRevivalCount[world][enemy] = count;
220}
221
222u8 dMj2dGame_c::getCSEnemyRevivalCnt(int world, int enemy) const {
223 return mEnemyRevivalCount[world][enemy];
224}
225
226void dMj2dGame_c::setCSEnemySceneNo(int world, int enemy, u8 subworld) {
227 mEnemySceneNo[world][enemy] = subworld;
228}
229
230u8 dMj2dGame_c::getCSEnemySceneNo(int world, int enemy) const {
231 return mEnemySceneNo[world][enemy];
232}
233
234void dMj2dGame_c::setCSEnemyPosIndex(int world, int enemy, u8 node) {
235 mEnemyPosIndex[world][enemy] = node;
236}
237
238u8 dMj2dGame_c::getCSEnemyPosIndex(int world, int enemy) const {
239 return mEnemyPosIndex[world][enemy];
240}
241
242void dMj2dGame_c::setCSEnemyWalkDir(int world, int enemy, u8 direction) {
243 mEnemyWalkDir[world][enemy] = direction;
244}
245
246u8 dMj2dGame_c::getCSEnemyWalkDir(int world, int enemy) const {
247 return mEnemyWalkDir[world][enemy];
248}
249
250void dMj2dGame_c::setKinopioCourseNo(int world, int level) {
251 mKinopioCourseNo[world] = level;
252}
253
255 return mKinopioCourseNo[world];
256}
257
258void dMj2dGame_c::setIbaraNow(int ibaraNow) {
259 mIbaraNow = ibaraNow;
260}
261
263 return mIbaraNow;
264}
265
268
270 memset(this, 0, sizeof(dMj2dHeader_c));
271
272 mMagic[0] = SAVE_MAGIC[0];
273 mMagic[1] = SAVE_MAGIC[1];
274 mMagic[2] = SAVE_MAGIC[2];
275 mMagic[3] = SAVE_MAGIC[3];
276
279}
280
282 mLastSelectedFile = fileNum;
283}
284
285u16 dMj2dHeader_c::getPlayCountFreeMode(int world, int level) const {
286 return mPlayCountFreeMode[world][level];
287}
288
289void dMj2dHeader_c::setPlayCountFreeMode(int world, int level, int count) {
290 mPlayCountFreeMode[world][level] = count;
291}
292
293u16 dMj2dHeader_c::getPlayCountCoinBattle(int world, int level) const {
294 return mPlayCountCoinBattle[world][level];
295}
296
297void dMj2dHeader_c::setPlayCountCoinBattle(int world, int level, int count) {
298 mPlayCountCoinBattle[world][level] = count;
299}
300
302 mMultiWorldOpenFlag |= 1 << world;
303}
304
306 return mMultiWorldOpenFlag & (1 << world);
307}
308
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.
int getStaffCreditHighScore()
Gets the staff credit high score.
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.
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.
u8 getIbaraNow() const
Gets the worldmap vine reshuffle counter.
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_START_KINOKO_HOUSE
The toad house on the starting node of each world.
static const PLAYER_CHARACTER_e sc_PLAYER_ORDER[]