Skip to content

Commit 19f2bde

Browse files
Achievement Fix-ups (#1)
* Add `BossDefeated` event to final bowser * Add new hooks * actual achievement work; clang * fix star counts for getting total stars when determining achievements * implemented racing achievement * clang * implemented metal cap achievement; added save support for metal cap (+ coins); (mostly) stick with event Mario state instead of `gMarioState`; added color support for achievement histograms; clang
1 parent d27ac8e commit 19f2bde

11 files changed

Lines changed: 253 additions & 52 deletions

File tree

src/engine/level_script.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,7 @@ static void level_cmd_set_music(void) {
705705
gAreas[sCurrAreaIndex].musicParam = CMD_GET(s16, 2);
706706
gAreas[sCurrAreaIndex].musicParam2 = CMD_GET(s16, 4);
707707
}
708+
CALL_EVENT(MusicChanged, gAreas[sCurrAreaIndex].musicParam2);
708709
sCurrentCmd = CMD_NEXT;
709710
}
710711

src/game/behaviors/bowser.inc.c

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,20 +1322,22 @@ s32 bowser_dead_final_stage_ending(void) {
13221322
} else {
13231323
dialogID = DIALOG_163;
13241324
}
1325-
// Lower music volume
1326-
if (o->oBowserTimer == 0) {
1327-
seq_player_lower_volume(SEQ_PLAYER_LEVEL, 60, 40);
1328-
o->oBowserTimer++;
1329-
}
1330-
// Play Bowser defeated dialog
1331-
if (cur_obj_update_dialog(MARIO_DIALOG_LOOK_UP,
1332-
(DIALOG_FLAG_TEXT_DEFAULT | DIALOG_FLAG_TIME_STOP_ENABLED), dialogID, 0)) {
1333-
// Dialog is done, fade out music and spawn grand star
1334-
cur_obj_set_model(MODEL_BOWSER_NO_SHADOW);
1335-
seq_player_unlower_volume(SEQ_PLAYER_LEVEL, 60);
1336-
seq_player_fade_out(SEQ_PLAYER_LEVEL, 1);
1337-
bowser_spawn_collectable();
1338-
o->oBowserTimer++;
1325+
CALL_CANCELLABLE_EVENT(BossDefeated, o, BOSS_TYPE_BOWSER_BITS) {
1326+
// Lower music volume
1327+
if (o->oBowserTimer == 0) {
1328+
seq_player_lower_volume(SEQ_PLAYER_LEVEL, 60, 40);
1329+
o->oBowserTimer++;
1330+
}
1331+
// Play Bowser defeated dialog
1332+
if (cur_obj_update_dialog(MARIO_DIALOG_LOOK_UP,
1333+
(DIALOG_FLAG_TEXT_DEFAULT | DIALOG_FLAG_TIME_STOP_ENABLED), dialogID, 0)) {
1334+
// Dialog is done, fade out music and spawn grand star
1335+
cur_obj_set_model(MODEL_BOWSER_NO_SHADOW);
1336+
seq_player_unlower_volume(SEQ_PLAYER_LEVEL, 60);
1337+
seq_player_fade_out(SEQ_PLAYER_LEVEL, 1);
1338+
bowser_spawn_collectable();
1339+
o->oBowserTimer++;
1340+
}
13391341
}
13401342
// Slowly fade him out
13411343
} else if (o->oOpacity > 4) {

src/game/level_update.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,5 +1330,6 @@ s32 lvl_set_current_level(UNUSED s16 arg0, s32 levelNum) {
13301330
*/
13311331
s32 lvl_play_the_end_screen_sound(UNUSED s16 arg0, UNUSED s32 arg1) {
13321332
play_sound(SOUND_MENU_THANK_YOU_PLAYING_MY_GAME, gGlobalSoundSource);
1333+
CALL_EVENT(GameEnded);
13331334
return 1;
13341335
}

src/port/Engine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ void GameEngine::AudioInit() {
918918
}
919919

920920
for (auto& sequence : *sequences_files) {
921-
if(sequence.find(".m64") != std::string::npos) {
921+
if (sequence.find(".m64") != std::string::npos) {
922922
continue;
923923
}
924924
auto path = "__OTR__" + sequence;

src/port/data/SaveConversion.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ inline void to_json(json& j, const AchievementSaveEntry& entry) {
6161

6262
inline void from_json(const json& j, AchievementSaveData& data) {
6363
data.cheated = j.at("cheated").get<bool>();
64+
data.capStars = j.at("capStars").get<int>();
65+
data.coins = j.at("coins").get<int>();
6466

6567
auto entriesJson = j.at("entries");
6668
for (size_t i = 0; i < entriesJson.size(); i++) {
@@ -76,6 +78,8 @@ inline void to_json(json& j, const AchievementSaveData& data) {
7678

7779
j = json{
7880
{ "cheated", data.cheated },
81+
{ "capStars",data.capStars },
82+
{ "coins", data.coins },
7983
{ "entries", entriesJson }
8084
};
8185
}

src/port/hooks/list/GameEvent.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,10 @@ DEFINE_EVENT(SpawnCollectible,
5959
DEFINE_EVENT(BossBattleStarted,
6060
BossBattleType type;
6161
);
62-
DEFINE_EVENT(BossBattleEnded);
62+
DEFINE_EVENT(BossBattleEnded);
63+
64+
DEFINE_EVENT(MusicChanged,
65+
s16 seqId;
66+
);
67+
68+
DEFINE_EVENT(GameEnded);

src/port/importer/AudioSequenceFactory.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,18 @@ SM64::AudioSequenceFactoryV0::ReadResource(std::shared_ptr<Ship::File> file,
3535
return bank;
3636
}
3737

38-
3938
std::shared_ptr<Ship::IResource>
4039
SM64::AudioSequenceXMLFactoryV0::ReadResource(std::shared_ptr<Ship::File> file,
41-
std::shared_ptr<Ship::ResourceInitData> initData) {
40+
std::shared_ptr<Ship::ResourceInitData> initData) {
4241
if (!FileHasValidFormatAndReader(file, initData)) {
4342
return nullptr;
4443
}
4544

4645
std::shared_ptr<AudioSequence> seq = std::make_shared<AudioSequence>(initData);
47-
auto child =
48-
std::get<std::shared_ptr<tinyxml2::XMLDocument>>(file->Reader)->FirstChildElement();
46+
auto child = std::get<std::shared_ptr<tinyxml2::XMLDocument>>(file->Reader)->FirstChildElement();
4947

50-
auto m64File = Ship::Context::GetInstance()->GetResourceManager()->GetArchiveManager()->LoadFile(child->Attribute("Path"));
48+
auto m64File =
49+
Ship::Context::GetInstance()->GetResourceManager()->GetArchiveManager()->LoadFile(child->Attribute("Path"));
5150

5251
tinyxml2::XMLElement* banksRoot = child->FirstChildElement("Banks");
5352
tinyxml2::XMLElement* banks = banksRoot->FirstChildElement();
@@ -58,8 +57,8 @@ SM64::AudioSequenceXMLFactoryV0::ReadResource(std::shared_ptr<Ship::File> file,
5857
}
5958

6059
// Copy m64 to sampleData
61-
for(size_t i = 0; i < m64File->Buffer->size(); i++) {
62-
seq->sampleData.push_back((uint8_t) m64File->Buffer->at(i));
60+
for (size_t i = 0; i < m64File->Buffer->size(); i++) {
61+
seq->sampleData.push_back((uint8_t)m64File->Buffer->at(i));
6362
}
6463

6564
seq->mData.id = child->IntAttribute("ID");

src/port/mods/PortEnhancements.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ void PortEnhancements_Register() {
137137
REGISTER_EVENT(SpawnCollectible);
138138
REGISTER_EVENT(BossBattleStarted);
139139
REGISTER_EVENT(BossBattleEnded);
140+
REGISTER_EVENT(MusicChanged);
141+
REGISTER_EVENT(GameEnded);
140142

141143
Rando::Init();
142144
LoadGuiTextures();

0 commit comments

Comments
 (0)