Skip to content

Commit

Permalink
allow boss warping while already in battle or paused
Browse files Browse the repository at this point in the history
  • Loading branch information
JCog committed Sep 24, 2024
1 parent 5902f94 commit a2e9227
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 29 deletions.
5 changes: 3 additions & 2 deletions lib/libpm-jp.a
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ pm_gCameras = 0x800B1D60;
pm_gEffectInstances = 0x800B4378;
__osEventStateTab = 0x800D9F60;
pm_gCurrentSaveFile = 0x800DACA0;
pm_battleState = 0x800DC048;
pm_gBattleState = 0x800DC048;
pm_gBattleStatus = 0x800DC050;
pm_battleState2 = 0x800DC4BC;
pm_gBattleSubState = 0x800DC4BC;
pm_playerActionsTable = 0x800F7E1C;
pm_popupMenuVar = 0x8010D800;
pm_gPartnerActionStatus = 0x8010ED70;
Expand Down Expand Up @@ -80,6 +80,7 @@ pm_updateExitMapScreenOverlay = 0x8013D35C;
pm_clearWindows = 0x8014C4A0;
pm_playSfx = 0x8014ED64;
pm_bgmSetSong = 0x8014F9C8;
pm_bgm_pop_battle_song = 0x8014FF1C;
pm_useIdleAnimation = 0x8026F26C;
pm_gotoMap = 0x802CA400;
pm_saveGame = 0x802DC150;
Expand Down
5 changes: 3 additions & 2 deletions lib/libpm-us.a
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ pm_gCameras = 0x800B1D80;
pm_gEffectInstances = 0x800B4398;
__osEventStateTab = 0x800D9F80;
pm_gCurrentSaveFile = 0x800DACC0;
pm_battleState = 0x800DC068;
pm_gBattleState = 0x800DC068;
pm_gBattleStatus = 0x800DC070;
pm_battleState2 = 0x800DC4DC;
pm_gBattleSubState = 0x800DC4DC;
pm_playerActionsTable = 0x800F7C8C;
pm_popupMenuVar = 0x8010D640;
pm_gPartnerActionStatus = 0x8010EBB0;
Expand Down Expand Up @@ -80,6 +80,7 @@ pm_updateExitMapScreenOverlay = 0x801382AC;
pm_clearWindows = 0x801473F0;
pm_playSfx = 0x80149CB4;
pm_bgmSetSong = 0x8014A918;
pm_bgm_pop_battle_song = 0x8014AE6C;
pm_useIdleAnimation = 0x8026F0EC;
pm_gotoMap = 0x802CA400;
pm_saveGame = 0x802E11A0;
Expand Down
2 changes: 1 addition & 1 deletion src/fp.c
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ HOOK s32 fpIsAbilityActive(s32 ability) {
}

HOOK pm_Npc *fpGetNpcUnsafe(s16 npcId) {
if (npcId == BATTLE_DUMMY_ID) {
if (npcId == BOSSES_DUMMY_ID) {
bossesDummyNpc.pos = pm_gPlayerStatus.position;
return &bossesDummyNpc;
}
Expand Down
4 changes: 2 additions & 2 deletions src/fp/practice/trainer.c
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,8 @@ static void updateBlockTrainer(void) {
}

// Either goombario or mario attacking
if ((pm_battleState2 == 3 && pm_gPlayerStatus.playerData.currentPartner == PARTNER_GOOMBARIO) ||
pm_battleState2 == 4) {
if ((pm_gBattleSubState == 3 && pm_gPlayerStatus.playerData.currentPartner == PARTNER_GOOMBARIO) ||
pm_gBattleSubState == 4) {
if (pm_gActionCommandStatus.state == 10 && pm_gGameStatus.pressedButtons[0].a) {
acLastAPress = pm_gGameStatus.frameCounter;
} else if (pm_gActionCommandStatus.state == 11) {
Expand Down
65 changes: 46 additions & 19 deletions src/fp/warps/bosses.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "bosses.h"
#include "common.h"
#include "fp.h"
#include "menu/menu.h"
#include <stdlib.h>

Expand Down Expand Up @@ -108,7 +107,7 @@ static BattlePage *pageList[] = {
pm_Npc bossesDummyNpc = {0};

static pm_Enemy dummyEnemy = {
.npcID = BATTLE_DUMMY_ID,
.npcID = BOSSES_DUMMY_ID,
};

static pm_Encounter dummyEncounter = {
Expand All @@ -118,15 +117,12 @@ static pm_Encounter dummyEncounter = {
.stage = 0
};

static s8 warping = -1;
static s8 warpCountdown = 0;
static bool leavingBattle = FALSE;
static u8 page = 0;
static u8 battle = 0;

static void bossWarpProc(struct MenuItem *item, void *data) {
if (pm_gGameStatus.isBattle) {
fpLog("can't warp now");
return;
}
u8 page = (u8)((s32)data >> 8);
u8 battle = (u8)((s32)data & 0xFF);
static void bossWarp() {
BattleInfo info = pageList[page]->battles[battle];

dummyEncounter.battle = info.battleId;
Expand All @@ -140,21 +136,52 @@ static void bossWarpProc(struct MenuItem *item, void *data) {
es->forbidFleeing = FALSE;
es->scriptedBattle = TRUE;
es->songID = info.songId;
es->unk_18 = -1;
es->unk_94 = 0;

pm_gEncounterState = 3;
pm_gEncounterSubState = 0;
warping = 1;
pm_gEncounterState = 3; // ENCOUNTER_STATE_PRE_BATTLE
pm_gEncounterSubState = 0; // ENCOUNTER_SUBSTATE_PRE_BATTLE_INIT
warpCountdown = 31;
// may want to try and clear speech bubbles, but it doesn't seem to crash, so not worried for now
}

static void bossWarpProc(struct MenuItem *item, void *data) {
if (warpCountdown > 0) {
// prevent warp spamming
return;
}
page = (u8)((s32)data >> 8);
battle = (u8)((s32)data & 0xFF);
pm_clearWindows();
// isBattle is also true when paused, so checking game mode
if (pm_gGameStatus.isBattle && pm_gameMode != 10 && pm_gameMode != 11) {
// end battle cleanly so next fight can start fresh
pm_gBattleState = 32; // BATTLE_STATE_END_BATTLE
pm_gBattleSubState = 2; // BTL_SUBSTATE_END_BATTLE_EXEC_STAGE_SCRIPT
pm_bgm_pop_battle_song();
leavingBattle = TRUE;
return;
}
bossWarp();
}

void battleUpdateWarps() {
if (warping == 0) {
if (leavingBattle && !pm_gGameStatus.isBattle) {
leavingBattle = FALSE;
bossWarp();
} else if (warpCountdown == 30) {
// speed up warp fadeout
pm_gCurrentEncounter.fadeOutAmount = 0xFF;
pm_gCurrentEncounter.battleStartCountdown = 0;
warping = FALSE;
} else if (warping > 0) {
warping--;
warpCountdown--;
} else if (warpCountdown > 30) {
if (pm_gameMode == 10) {
// unpause
pm_setGameMode(11);
} else if (pm_gameMode != 11) {
// delay countdown until unpaused
warpCountdown--;
}
} else if (warpCountdown > 0){
warpCountdown--;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/fp/warps/bosses.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define BOSSES_H
#include "menu/menu.h"

#define BATTLE_DUMMY_ID (s16)0xDEAD
#define BOSSES_DUMMY_ID (s16)0xDEAD

extern pm_Npc bossesDummyNpc;

Expand Down
5 changes: 3 additions & 2 deletions src/pm64.h
Original file line number Diff line number Diff line change
Expand Up @@ -1308,9 +1308,9 @@ extern_data pm_EncounterStatus pm_gCurrentEncounter;
extern_data pm_Camera pm_gCameras[4];
extern_data pm_EffectInstance *pm_gEffectInstances[96];
extern_data pm_SaveData pm_gCurrentSaveFile;
extern_data s32 pm_battleState;
extern_data s32 pm_gBattleState;
extern_data pm_BattleStatus pm_gBattleStatus;
extern_data s32 pm_battleState2;
extern_data s32 pm_gBattleSubState;
extern_data pm_Action pm_playerActionsTable[39];
extern_data s32 pm_popupMenuVar;
extern_data pm_PartnerActionStatus pm_gPartnerActionStatus;
Expand Down Expand Up @@ -1362,6 +1362,7 @@ s32 pm_updateExitMapScreenOverlay(s16 *progress);
void pm_clearWindows(void);
void pm_playSfx(s32 sound_id);
void pm_bgmSetSong(s32 player_index, s32 song_id, s32 variation, s32 fade_out_time, s16 volume);
void pm_bgm_pop_battle_song(void);
pm_ApiStatus pm_useIdleAnimation(pm_Evt *script, s32 isInitialCall);
pm_ApiStatus pm_gotoMap(pm_Evt *script, s32 isInitialCall);
void pm_saveGame(void);
Expand Down

0 comments on commit a2e9227

Please sign in to comment.