From 2ef68bfd9511df945cf052898fc509b654b6143b Mon Sep 17 00:00:00 2001 From: MokhaLeee Date: Fri, 10 May 2024 11:36:35 +0800 Subject: [PATCH] review bmtrap --- include/bmtrap.h | 25 +++-- include/bmtrick.h | 3 + include/bmusemind.h | 2 +- src/bmmind.c | 8 +- src/bmtrap.c | 231 +++++++++++++++++++++----------------------- src/bmusemind.c | 10 +- 6 files changed, 135 insertions(+), 144 deletions(-) diff --git a/include/bmtrap.h b/include/bmtrap.h index ce1eefd0d..c033122fc 100644 --- a/include/bmtrap.h +++ b/include/bmtrap.h @@ -12,28 +12,27 @@ struct TrapData { /* 05 */ u8 turn; } __attribute__((packed)); -struct UnknownBMTrapProc { +struct ProcBmTrap { /* 00 */ PROC_HEADER; - /* 29 */ u8 _pad_29[0x50-0x29]; + STRUCT_PAD(0x29, 0x50); + + /* 50 */ s16 post_exec_type; - /* 50 */ s16 unk_50; - /* 52 */ s8 unk_52; - /* 53 */ s8 unk_53; /* 54 */ struct Unit* unit; }; -void sub_80374F4(struct UnknownBMTrapProc * proc); -void sub_8037510(struct UnknownBMTrapProc * proc); -void sub_8037528(struct UnknownBMTrapProc * proc); -void sub_8037540(struct UnknownBMTrapProc * proc); -void sub_80375A0(struct UnknownBMTrapProc * proc); +void RegisterTrapDeathBWL(struct ProcBmTrap * proc); +void ExecFireTileTrapAnim1(struct ProcBmTrap * proc); +void ExecFireTileTrapAnim2(struct ProcBmTrap * proc); +void ApplyTrapDamageAnim(struct ProcBmTrap * proc); +void ApplyTrapDamageReal(struct ProcBmTrap * proc); int GetPickTrapType(struct Unit * unit); int ExecTrap(ProcPtr proc, struct Unit * unit, int param_3); bool HandlePostActionTraps(ProcPtr); -bool sub_80377CC(ProcPtr proc); -bool sub_80377F0(ProcPtr proc, struct Unit * unit); -bool sub_8037830(ProcPtr proc, struct Unit * unit); +bool ExecTrapAfterWarp(ProcPtr proc); +bool ExecTrapAfterDropAction(ProcPtr proc, struct Unit * unit); +bool ExecTrapAfterDeathDrop(ProcPtr proc, struct Unit * unit); void LoadTrapData(const struct TrapData * data); void LoadChapterTraps(void); void AddGorgonEggTrap(s8 x, s8 y, u8 turnsToHatch, u8 level, u8 unk_05); diff --git a/include/bmtrick.h b/include/bmtrick.h index d0cbaa0fe..63538479f 100644 --- a/include/bmtrick.h +++ b/include/bmtrick.h @@ -22,6 +22,9 @@ enum TRAP_MINE = 11, TRAP_GORGON_EGG = 12, // TODO: figure out TRAP_LIGHT_RUNE = 13, + TRAP_14 = 14, + TRAP_FIRE_THIEF = 15, + TRAP_MINE_ASSASSIN = 16, }; enum diff --git a/include/bmusemind.h b/include/bmusemind.h index 0658ab92c..734d17ccc 100644 --- a/include/bmusemind.h +++ b/include/bmusemind.h @@ -9,7 +9,7 @@ void ExecRestore(ProcPtr proc); void ExecBarrierStaff(ProcPtr proc); void GetRescueStaffeePosition(struct Unit* unit, struct Unit* target, int* xOut, int* yOut); void ExecRescueStaff(ProcPtr proc); -int sub_802EF70(ProcPtr proc); +int PostWarpStaff_ExecTrap(ProcPtr proc); int sub_802EF80(); void ExecWarpStaff(ProcPtr proc); void ExecStatusStaff(ProcPtr proc); diff --git a/src/bmmind.c b/src/bmmind.c index 5e76adb3d..169f392da 100644 --- a/src/bmmind.c +++ b/src/bmmind.c @@ -195,7 +195,7 @@ s8 ActionRescue(ProcPtr proc) { //! FE8U = 0x080321B8 int AfterDrop_CheckTrapAfterDropMaybe(struct AfterDropActionProc* proc) { - return sub_80377F0(proc, proc->unit); + return ExecTrapAfterDropAction(proc, proc->unit); } //! FE8U = 0x080321C8 @@ -455,9 +455,9 @@ void DeathDropSpriteAnim_Loop(struct DeathDropAnimProc* proc) { } //! FE8U = 0x08032658 -void DeathDropSpriteAnim_ExecAnyTrap(struct DeathDropAnimProc* proc) { - sub_8037830(proc, proc->unit); - return; +void DeathDropSpriteAnim_ExecAnyTrap(struct DeathDropAnimProc * proc) +{ + ExecTrapAfterDeathDrop(proc, proc->unit); } //! FE8U = 0x08032664 diff --git a/src/bmtrap.c b/src/bmtrap.c index d6858ffac..8699dce8b 100644 --- a/src/bmtrap.c +++ b/src/bmtrap.c @@ -25,15 +25,15 @@ struct ProcCmd CONST_DATA sProcScr_ExecTrap8[] = { PROC_SLEEP(1), PROC_WHILE(MU_IsAnyActive), - PROC_CALL(sub_80374F4), - PROC_CALL(sub_8037510), - PROC_SLEEP(0), + PROC_CALL(RegisterTrapDeathBWL), + PROC_CALL(ExecFireTileTrapAnim1), + PROC_YIELD, - PROC_CALL(sub_8037540), - PROC_SLEEP(0), + PROC_CALL(ApplyTrapDamageAnim), + PROC_YIELD, - PROC_CALL(sub_80375A0), - PROC_SLEEP(0), + PROC_CALL(ApplyTrapDamageReal), + PROC_YIELD, PROC_END, }; @@ -41,147 +41,142 @@ struct ProcCmd CONST_DATA sProcScr_ExecTrap8[] = { struct ProcCmd CONST_DATA sProcScr_ExecTrapMine[] = { PROC_SLEEP(1), PROC_WHILE(MU_IsAnyActive), - PROC_CALL(sub_80374F4), - PROC_CALL(sub_8037528), - PROC_SLEEP(0), + PROC_CALL(RegisterTrapDeathBWL), + PROC_CALL(ExecFireTileTrapAnim2), + PROC_YIELD, - PROC_CALL(sub_8037540), - PROC_SLEEP(0), + PROC_CALL(ApplyTrapDamageAnim), + PROC_YIELD, - PROC_CALL(sub_80375A0), - PROC_SLEEP(0), + PROC_CALL(ApplyTrapDamageReal), + PROC_YIELD, PROC_END, }; -void sub_80374F4(struct UnknownBMTrapProc* proc) { - struct Unit* unit = proc->unit; +void RegisterTrapDeathBWL(struct ProcBmTrap * proc) +{ + struct Unit * unit = proc->unit; - if (GetUnitCurrentHp(unit) <= 10) { + if (GetUnitCurrentHp(unit) <= 10) PidStatsRecordLoseData(unit->pCharacterData->number); - } - - return; } -void sub_8037510(struct UnknownBMTrapProc* proc) { +void ExecFireTileTrapAnim1(struct ProcBmTrap * proc) +{ StartFireTrapAnim(proc, proc->unit->xPos, proc->unit->yPos); - return; } -void sub_8037528(struct UnknownBMTrapProc* proc) { +void ExecFireTileTrapAnim2(struct ProcBmTrap * proc) +{ StartFireTrapAnim2(proc, proc->unit->xPos, proc->unit->yPos); - return; } -void sub_8037540(struct UnknownBMTrapProc* proc) { - struct Unit* unit = proc->unit; +void ApplyTrapDamageAnim(struct ProcBmTrap * proc) +{ + struct Unit * unit = proc->unit; - switch (proc->unk_50) { - case 0: - MU_EndAll(); - break; + switch (proc->post_exec_type) { + case 0: + MU_EndAll(); + break; - case 1: - MU_EndAll(); - MU_Create(gActiveUnit); - MU_SetDefaultFacing_Auto(); - break; + case 1: + MU_EndAll(); + MU_Create(gActiveUnit); + MU_SetDefaultFacing_Auto(); + break; - case 2: - MU_End(MU_GetByUnit(unit)); - break; + case 2: + MU_End(MU_GetByUnit(unit)); + break; } gActionData.trapType = TRAP_TORCHLIGHT; BeginUnitCritDamageAnim(unit, TRAP_TORCHLIGHT); - - return; } -void sub_80375A0(struct UnknownBMTrapProc * proc) +void ApplyTrapDamageReal(struct ProcBmTrap * proc) { - struct Unit* unit = proc->unit; + struct Unit * unit = proc->unit; ApplyHazardHealing(proc, unit, -10, -1); - if (GetUnitCurrentHp(unit) == 0) { - struct Unit* tmp = gActiveUnit; + if (GetUnitCurrentHp(unit) == 0) + { + struct Unit * tmp = gActiveUnit; gActiveUnit = unit; PidStatsRecordDefeatInfo(unit->pCharacterData->number, 0, 3); - if (CheckForWaitEvents() != 0) { + if (CheckForWaitEvents() != 0) RunWaitEvents(); - } gActiveUnit = tmp; } - - return; } int GetPickTrapType(struct Unit * unit) { struct Trap * trap; - if ((trap = GetTrapAt(unit->xPos, unit->yPos)) == NULL) { - return 0; - } + if ((trap = GetTrapAt(unit->xPos, unit->yPos)) == NULL) + return TRAP_NONE; switch (trap->type) { - case TRAP_BALLISTA: - return 0; + case TRAP_BALLISTA: + return TRAP_NONE; - case TRAP_FIRETILE: - if ((UNIT_CATTRIBUTES(unit) & CA_THIEF)) { - return 0xF; - } - break; + case TRAP_FIRETILE: + if ((UNIT_CATTRIBUTES(unit) & CA_THIEF)) + return TRAP_FIRE_THIEF; - case TRAP_MINE: - if ((UNIT_CATTRIBUTES(unit) & CA_ASSASSIN)) { - if (GetUnitItemCount(unit) != 5) { - return 0x10; - } - return 0; - } else if ((UNIT_CATTRIBUTES(unit) & CA_STEAL)) { - return 0; - } - break; + break; + + case TRAP_MINE: + if ((UNIT_CATTRIBUTES(unit) & CA_ASSASSIN)) + { + if (GetUnitItemCount(unit) != UNIT_ITEM_COUNT) + return TRAP_MINE_ASSASSIN; + + return TRAP_NONE; + } else if ((UNIT_CATTRIBUTES(unit) & CA_STEAL)) + return TRAP_NONE; + + break; } return trap->type; } -int ExecTrap(ProcPtr proc, struct Unit * unit, int param_3) +int ExecTrap(ProcPtr proc, struct Unit * unit, int exec_type) { - struct UnknownBMTrapProc* proc2; + struct ProcBmTrap * proc2; switch (GetPickTrapType(unit)) { case TRAP_8: proc2 = Proc_StartBlocking(sProcScr_ExecTrap8, proc); - proc2->unk_50 = param_3; + proc2->post_exec_type = exec_type; proc2->unit = unit; break; case TRAP_MINE: RemoveTrap(GetTypedTrapAt(unit->xPos, unit->yPos, TRAP_MINE)); proc2 = Proc_StartBlocking(sProcScr_ExecTrapMine, proc); - proc2->unk_50 = param_3; + proc2->post_exec_type = exec_type; proc2->unit = unit; break; - case 0xF: + case TRAP_FIRE_THIEF: RemoveTrap(GetTrapAt(unit->xPos, unit->yPos)); PlaySoundEffect(0xB1); - NewPopup2_PlanA(proc, -1, GetStringFromIndex(0x20)); + NewPopup2_PlanA(proc, -1, GetStringFromIndex(0x20)); /* Disabled trap. */ break; - case 0x10: + case TRAP_MINE_ASSASSIN: RemoveTrap(GetTrapAt(unit->xPos, unit->yPos)); PlaySoundEffect(0xB1); - NewPopup2_PlanA(proc, -1, GetStringFromIndex(0x21)); + NewPopup2_PlanA(proc, -1, GetStringFromIndex(0x21)); /* Recovered mine. */ UnitAddItem(unit, MakeNewItem(ITEM_MINE)); break; } @@ -223,12 +218,12 @@ bool HandlePostActionTraps(ProcPtr proc) { return ExecTrap(proc, gActiveUnit, 0); } -bool sub_80377CC(ProcPtr proc) +bool ExecTrapAfterWarp(ProcPtr proc) { return ExecTrap(proc, GetUnit(gActionData.targetIndex), 1); } -bool sub_80377F0(ProcPtr proc, struct Unit * unit) +bool ExecTrapAfterDropAction(ProcPtr proc, struct Unit * unit) { if (!GetPickTrapType(unit)) { MU_End(MU_GetByUnit(unit)); @@ -241,57 +236,55 @@ bool sub_80377F0(ProcPtr proc, struct Unit * unit) return ExecTrap(proc, unit, 2); } -bool sub_8037830(ProcPtr proc, struct Unit * unit) +bool ExecTrapAfterDeathDrop(ProcPtr proc, struct Unit * unit) { return ExecTrap(proc, unit, 3); } void LoadTrapData(const struct TrapData * data) { - if (!data || !data->type) { + if (!data || !data->type) return; - } else { - while (data->type) { - switch (data->type) { - case TRAP_BALLISTA: - AddBallista(data->xPos, data->yPos, data->subtype); - break; - - case TRAP_FIRETILE: - AddFireTile(data->xPos, data->yPos, data->turn_counter, data->turn); - break; - - case TRAP_GAS: - AddGasTrap(data->xPos, data->yPos, data->subtype, data->turn_counter, data->turn); - break; - - case TRAP_8: - AddTrap8(data->xPos, data->yPos); - break; - - case TRAP_9: - AddTrap9(data->xPos, data->yPos, data->subtype); - break; - - case TRAP_MINE: - AddTrap(data->xPos, data->yPos, data->type, 0); - break; - - case TRAP_LIGHTARROW: - AddArrowTrap(data->xPos, data->turn_counter, data->turn); + + while (data->type) + { + switch (data->type) { + case TRAP_BALLISTA: + AddBallista(data->xPos, data->yPos, data->subtype); + break; + + case TRAP_FIRETILE: + AddFireTile(data->xPos, data->yPos, data->turn_counter, data->turn); + break; + + case TRAP_GAS: + AddGasTrap(data->xPos, data->yPos, data->subtype, data->turn_counter, data->turn); + break; + + case TRAP_8: + AddTrap8(data->xPos, data->yPos); + break; + + case TRAP_9: + AddTrap9(data->xPos, data->yPos, data->subtype); + break; + + case TRAP_MINE: + AddTrap(data->xPos, data->yPos, data->type, 0); + break; + + case TRAP_LIGHTARROW: + AddArrowTrap(data->xPos, data->turn_counter, data->turn); #if BUGFIX - break; + break; #endif - case TRAP_GORGON_EGG: - AddGorgonEggTrap(data->xPos, data->yPos, data->subtype, data->turn_counter, data->turn); - break; - } - data++; + case TRAP_GORGON_EGG: + AddGorgonEggTrap(data->xPos, data->yPos, data->subtype, data->turn_counter, data->turn); + break; } + data++; } - - return; } //! FE8U = 0x08037910 @@ -299,8 +292,6 @@ void LoadChapterTraps(void) { LoadTrapData(GetTrapPointer()); LoadTrapData(GetHardModeTrapPointer()); - - return; } //! FE8U = 0x08037928 @@ -308,6 +299,4 @@ void AddGorgonEggTrap(s8 x, s8 y, u8 meta, u8 delay, u8 level) { // The value of the "meta" parameter appears to be unused in the game logic AddDamagingTrap(x, y, TRAP_GORGON_EGG, meta, delay, 1, level); - - return; } diff --git a/src/bmusemind.c b/src/bmusemind.c index ed6ad3cda..165aff1b8 100644 --- a/src/bmusemind.c +++ b/src/bmusemind.c @@ -27,9 +27,9 @@ s8 CanUnitCrossTerrain(struct Unit* unit, int terrain); - struct ProcCmd CONST_DATA ProcScr_ExecWarpStaff[] = { + struct ProcCmd CONST_DATA ProcScr_PostWarpStaffAction[] = { PROC_SLEEP(0), - PROC_CALL_2(sub_802EF70), + PROC_CALL_2(PostWarpStaff_ExecTrap), PROC_CALL(sub_802EF80), PROC_END, @@ -232,8 +232,8 @@ void ExecRescueStaff(ProcPtr proc) { return; } -int sub_802EF70(ProcPtr proc) { - return sub_80377CC(proc); +int PostWarpStaff_ExecTrap(ProcPtr proc) { + return ExecTrapAfterWarp(proc); } int sub_802EF80() { @@ -262,7 +262,7 @@ void ExecWarpStaff(ProcPtr proc) { BattleApplyItemEffect(proc); BeginBattleAnimations(); - Proc_StartBlocking(ProcScr_ExecWarpStaff, proc); + Proc_StartBlocking(ProcScr_PostWarpStaffAction, proc); return; }