From ab7ff48d22dafe752a3cffba6243aabc8db4985e Mon Sep 17 00:00:00 2001 From: Cuyler36 Date: Fri, 14 Jul 2023 11:05:45 -0400 Subject: [PATCH] Implement & link m_fuusen --- config/rel_disasm_overrides.yml | 1 + config/rel_slices.yml | 4 ++ include/m_fuusen.h | 18 +++++++ include/m_private.h | 4 ++ rel/m_fuusen.c | 94 +++++++++++++++++++++++++++++++++ rel/m_private.c | 12 ++--- 6 files changed, 127 insertions(+), 6 deletions(-) create mode 100644 rel/m_fuusen.c diff --git a/config/rel_disasm_overrides.yml b/config/rel_disasm_overrides.yml index b59d4b45..c9473eeb 100644 --- a/config/rel_disasm_overrides.yml +++ b/config/rel_disasm_overrides.yml @@ -2,5 +2,6 @@ trim_ctors: true trim_dtors: true symbol_aligns: 0x8064d500 : 0x20 + 0x81295C80 : 0x20 # .bss m_handbill.o 0x8125a7c0 : 0x20 # construct_skip 0x81361820 : 0x20 # S_back_title_timer \ No newline at end of file diff --git a/config/rel_slices.yml b/config/rel_slices.yml index c4ce9410..c00d0aaa 100644 --- a/config/rel_slices.yml +++ b/config/rel_slices.yml @@ -45,6 +45,10 @@ m_fbdemo_fade.c: .text: [0x803A12F8, 0x803A1508] .rodata: [0x80641FC0, 0x80641FD8] .data: [0x80653558, 0x806535A0] +m_fuusen.c: + .text: [0x803B15E0, 0x803B1908] + .rodata: [0x80642258, 0x80642288] + .bss: [0x81295C70, 0x81295C80] m_huusui_room.c: .text: [0x803B1908, 0x803B1968] m_home.c: diff --git a/include/m_fuusen.h b/include/m_fuusen.h index 08ae2bc3..eb91afcc 100644 --- a/include/m_fuusen.h +++ b/include/m_fuusen.h @@ -2,13 +2,31 @@ #define M_FUUSEN_H #include "types.h" +#include "m_play_h.h" #ifdef __cplusplus extern "C" { #endif +enum { + Balloon_STATE_DEAD, /* Doesn't exist */ + Balloon_STATE_CHK_SPAWN, /* Check should spawn */ + Balloon_STATE_SPAWNED, /* Sucessfully spawned */ + Balloon_STATE_LOOK_UP, /* Flew away after hitting a tree? */ + Balloon_STATE_PENDING_SPAWN, /* Didn't successfully spawn, trying again */ + + Balloon_STATE_NUM +}; + extern int fuusen_DEBUG_mode_flag; +extern void Balloon_init(); +extern void Balloon_make_fuusen(GAME_PLAY* play); +extern void Balloon_chk_make_fuusen(GAME_PLAY* play); +extern void Balloon_move(GAME_PLAY* play); +extern void Balloon_kill(); +extern void Balloon_look_up(); + #ifdef __cplusplus } #endif diff --git a/include/m_private.h b/include/m_private.h index 16efe470..e1dc80c7 100644 --- a/include/m_private.h +++ b/include/m_private.h @@ -26,6 +26,10 @@ extern "C" { #define mPr_FLAG_POSTOFFICE_GIFT2 (1 << 4) // 100,000,000 Bells #define mPr_FLAG_POSTOFFICE_GIFT3 (1 << 5) // 999,999,999 Bells +#define mPr_MONEY_POWER_MIN -80 + +#define mPr_GOODS_POWER_MIN -30 +#define mPr_GOODS_POWER_MAX 50 enum { mPr_PLAYER_0, diff --git a/rel/m_fuusen.c b/rel/m_fuusen.c new file mode 100644 index 00000000..0bbda03f --- /dev/null +++ b/rel/m_fuusen.c @@ -0,0 +1,94 @@ +#include "m_fuusen.h" + +#include "m_name_table.h" +#include "m_play.h" +#include "m_field_assessment.h" +#include "m_private.h" +#include "m_event.h" +#include "m_common_data.h" + +int fuusen_DEBUG_mode_flag; + +extern void Balloon_init() { + Common_Set(balloon_state, Balloon_STATE_DEAD); + Common_Set(balloon_last_spawn_min, 0); + Common_Set(balloon_spawn_percent, 0.05f); +} + +extern void Balloon_make_fuusen(GAME_PLAY* play) { + ACTOR* balloon_actor = Actor_info_make_actor(&play->actor_info, (GAME*)play, mAc_PROFILE_FUUSEN, 0.0f, 0.0f, 0.0f, 0, 0, 0, -1, -1, -1, EMPTY_NO, 0, -1, -1); + if (balloon_actor != NULL) { + Common_Set(balloon_state, Balloon_STATE_SPAWNED); + Common_Set(balloon_spawn_percent, (1.0f - Common_Get(balloon_spawn_percent)) * 0.1f); + fuusen_DEBUG_mode_flag = TRUE; + } + else { + Common_Set(balloon_state, Balloon_STATE_PENDING_SPAWN); + } +} + +extern void Balloon_chk_make_fuusen(GAME_PLAY* play) { + f32 rng = fqrand(); + f32 spawn_percent = Common_Get(balloon_spawn_percent); + + if (rng < spawn_percent) { + Balloon_make_fuusen(play); + } + else { + f32 goods_power_mod; + f32 field_rank_mod; + f32 balloon_spawn_percentage_inc; + + field_rank_mod = (f32)mFAs_GetFieldRank() / (f32)mFAs_FIELDRANK_SIX; + goods_power_mod = (f32)mPr_GetGoodsPower() / (f32)mPr_GOODS_POWER_MAX; + balloon_spawn_percentage_inc = 0.025f + goods_power_mod * 0.025f + field_rank_mod * 0.025f + RANDOM_F(0.025f); + + Common_Get(balloon_spawn_percent) += balloon_spawn_percentage_inc; + } +} + +extern void Balloon_move(GAME_PLAY* play) { + s16 min; + + if (mFI_GET_TYPE(mFI_GetFieldId()) != mFI_FIELDTYPE_FG) { + return; + } + + if (mEv_CheckFirstIntro()) { + return; + } + + switch (Common_Get(balloon_state)) { + case Balloon_STATE_DEAD: + case Balloon_STATE_CHK_SPAWN: + case Balloon_STATE_LOOK_UP: + break; + + case Balloon_STATE_PENDING_SPAWN: + Balloon_make_fuusen(play); + /* Fallthrough */ + case Balloon_STATE_SPAWNED: + default: + return; + } + + min = Common_Get(time.rtc_time.min); + if ((min % 5) == 3 && min != Common_Get(balloon_last_spawn_min)) { + Common_Set(balloon_last_spawn_min, min); + + if (Common_Get(balloon_state) == Balloon_STATE_LOOK_UP) { + Common_Get(balloon_spawn_percent) += 0.25f; + } + + Common_Set(balloon_state, Balloon_STATE_CHK_SPAWN); + Balloon_chk_make_fuusen(play); + } +} + +extern void Balloon_kill() { + Common_Set(balloon_state, Balloon_STATE_DEAD); +} + +extern void Balloon_look_up() { + Common_Set(balloon_state, Balloon_STATE_LOOK_UP); +} diff --git a/rel/m_private.c b/rel/m_private.c index 8fdad98a..4b76135f 100644 --- a/rel/m_private.c +++ b/rel/m_private.c @@ -694,8 +694,8 @@ extern s16 mPr_GetMoneyPower() { } } - if (money_power < -80) { - money_power = -80; + if (money_power < mPr_MONEY_POWER_MIN) { + money_power = mPr_MONEY_POWER_MIN; } return money_power; @@ -721,12 +721,12 @@ extern s16 mPr_GetGoodsPower() { } } - if (goods_power > 50) { - return 50; + if (goods_power > mPr_GOODS_POWER_MAX) { + return mPr_GOODS_POWER_MAX; } - if (goods_power < -30) { - goods_power = -30; + if (goods_power < mPr_GOODS_POWER_MIN) { + goods_power = mPr_GOODS_POWER_MIN; } return goods_power;