From a28f822c9b779ada217f3ad9ac6e8ad8d995027b Mon Sep 17 00:00:00 2001 From: Cuyler36 Date: Wed, 11 Jun 2025 03:41:30 -0400 Subject: [PATCH] Implement & link ac_npc_majin2 --- configure.py | 2 +- include/ac_npc_majin2.h | 17 +- include/m_submenu.h | 2 + src/actor/npc/ac_npc_majin2.c | 120 ++++++++++++ src/actor/npc/ac_npc_majin2_schedule.c_inc | 202 +++++++++++++++++++++ src/actor/npc/ac_npc_majin2_talk.c_inc | 94 ++++++++++ src/game/m_submenu.c | 2 +- 7 files changed, 436 insertions(+), 3 deletions(-) create mode 100644 src/actor/npc/ac_npc_majin2.c create mode 100644 src/actor/npc/ac_npc_majin2_schedule.c_inc create mode 100644 src/actor/npc/ac_npc_majin2_talk.c_inc diff --git a/configure.py b/configure.py index 15582c0f..d7f30ba5 100644 --- a/configure.py +++ b/configure.py @@ -1118,7 +1118,7 @@ config.libs = [ Object(Matching, "actor/npc/ac_npc_guide2.c"), Object(NonMatching, "actor/npc/ac_npc_hem.c"), Object(Matching, "actor/npc/ac_npc_majin.c"), - Object(NonMatching, "actor/npc/ac_npc_majin2.c"), + Object(Matching, "actor/npc/ac_npc_majin2.c"), Object(NonMatching, "actor/npc/ac_npc_majin3.c"), Object(NonMatching, "actor/npc/ac_npc_majin4.c"), Object(Matching, "actor/npc/ac_npc_majin5.c"), diff --git a/include/ac_npc_majin2.h b/include/ac_npc_majin2.h index 81ef96e4..8e18ed8b 100644 --- a/include/ac_npc_majin2.h +++ b/include/ac_npc_majin2.h @@ -3,11 +3,27 @@ #include "types.h" #include "m_actor.h" +#include "ac_npc.h" #ifdef __cplusplus extern "C" { #endif +typedef struct npc_majin2_actor_s NPC_MAJIN2_ACTOR; + +typedef void (*aMJN2_THINK_PROC)(NPC_MAJIN2_ACTOR* actor, GAME_PLAY* play); +typedef void (*aMJN2_TALK_PROC)(NPC_MAJIN2_ACTOR* actor, GAME_PLAY* play); + +struct npc_majin2_actor_s { + NPC_ACTOR npc_class; + int think_idx; + int next_think_idx; + aMJN2_THINK_PROC think_proc; + int norm_talk_idx; + int force_talk_idx; + aMJN2_TALK_PROC talk_proc; +}; + extern ACTOR_PROFILE Npc_Majin2_Profile; #ifdef __cplusplus @@ -15,4 +31,3 @@ extern ACTOR_PROFILE Npc_Majin2_Profile; #endif #endif - diff --git a/include/m_submenu.h b/include/m_submenu.h index 3742a387..6d54b8c8 100644 --- a/include/m_submenu.h +++ b/include/m_submenu.h @@ -135,6 +135,8 @@ enum { mSM_BD_OPEN_NUM }; +#define mSM_CHECK_OPEN_MAP() (chkTrigger(mSM_MAP_BUTTON) && Common_Get(map_flag) == TRUE) + typedef struct submenu_item_s { mActor_name_t item; u8 slot_no; diff --git a/src/actor/npc/ac_npc_majin2.c b/src/actor/npc/ac_npc_majin2.c new file mode 100644 index 00000000..3d7f4f9f --- /dev/null +++ b/src/actor/npc/ac_npc_majin2.c @@ -0,0 +1,120 @@ +#include "ac_npc_majin2.h" + +#include "m_common_data.h" +#include "m_player_lib.h" +#include "m_font.h" +#include "m_msg.h" +#include "ac_reset_demo.h" +#include "m_bgm.h" +#include "m_house.h" + +enum { + aMJN2_THINK_START_WAIT, + aMJN2_THINK_START_WAIT_ST, + aMJN2_THINK_CALL, + aMJN2_THINK_WAIT, + aMJN2_THINK_FORCE_CALL, + aMJN2_THINK_FORCE_CALL_2, + aMJN2_THINK_EXIT, + + aMJN2_THINK_NUM +}; + +enum { + aMJN2_TALK_WAIT, + aMJN2_TALK_END_WAIT, + + aMJN2_TALK_NUM +}; + +static void aMJN2_actor_ct(ACTOR* actorx, GAME* game); +static void aMJN2_actor_dt(ACTOR* actorx, GAME* game); +static void aMJN2_actor_move(ACTOR* actorx, GAME* game); +static void aMJN2_actor_draw(ACTOR* actorx, GAME* game); +static void aMJN2_actor_save(ACTOR* actorx, GAME* game); +static void aMJN2_actor_init(ACTOR* actorx, GAME* game); + +// clang-format off +ACTOR_PROFILE Npc_Majin2_Profile = { + mAc_PROFILE_NPC_MAJIN2, + ACTOR_PART_NPC, + ACTOR_STATE_NO_MOVE_WHILE_CULLED | ACTOR_STATE_NO_DRAW_WHILE_CULLED, + SP_NPC_MAJIN2, + ACTOR_OBJ_BANK_KEEP, + sizeof(NPC_MAJIN2_ACTOR), + aMJN2_actor_ct, + aMJN2_actor_dt, + aMJN2_actor_init, + mActor_NONE_PROC1, + aMJN2_actor_save, +}; +// clang-format on + +static void aMJN2_force_talk_request(ACTOR* actorx, GAME* game); +static void aMJN2_norm_talk_request(ACTOR* actorx, GAME* game); +static int aMJN2_talk_init(ACTOR* actorx, GAME* game); +static int aMJN2_talk_end_chk(ACTOR* actorx, GAME* game); + +static void aMJN2_schedule_proc(NPC_ACTOR* nactorx, GAME_PLAY* play, int type); +static void aMJN2_setup_think_proc(NPC_MAJIN2_ACTOR* actor, GAME_PLAY* play, int think_idx); +static void aMJN2_change_talk_proc(NPC_MAJIN2_ACTOR* actor, int talk_idx); + +static void aMJN2_actor_ct(ACTOR* actorx, GAME* game) { + static aNPC_ct_data_c ct_data = { + aMJN2_actor_move, + aMJN2_actor_draw, + aNPC_CT_SCHED_TYPE_SPECIAL, + (aNPC_TALK_REQUEST_PROC)none_proc1, + aMJN2_talk_init, + aMJN2_talk_end_chk, + 0, + }; + + if (NPC_CLIP->birth_check_proc(actorx, game) == TRUE) { + NPC_MAJIN2_ACTOR* actor = (NPC_MAJIN2_ACTOR*)actorx; + + actor->npc_class.schedule.schedule_proc = aMJN2_schedule_proc; + NPC_CLIP->ct_proc(actorx, game, &ct_data); + } +} + +static void aMJN2_actor_save(ACTOR* actorx, GAME* game) { + NPC_CLIP->save_proc(actorx, game); +} + +static void aMJN2_actor_dt(ACTOR* actorx, GAME* game) { + NPC_CLIP->dt_proc(actorx, game); + eEC_CLIP->effect_kill_proc(eEC_EFFECT_RESET_HOLE, RSV_NO); + if (CLIP(demo_clip2) != NULL && CLIP(demo_clip2)->type == mDemo_CLIP_TYPE_RESET_DEMO) { + ACTOR* demox = (ACTOR*)CLIP(demo_clip2)->demo_class; + + if (demox != NULL) { + RESET_DEMO_ACTOR* reset_demo = (RESET_DEMO_ACTOR*)demox; + + reset_demo->reset_actor = NULL; + reset_demo->request_light = FALSE; + } + } +} + +static void aMJN2_actor_init(ACTOR* actorx, GAME* game) { + NPC_CLIP->init_proc(actorx, game); +} + +static void aMJN2_actor_move(ACTOR* actorx, GAME* game) { + NPC_CLIP->move_proc(actorx, game); + actorx->shape_info.draw_shadow = FALSE; +} + +static void aMJN2_set_animation(NPC_MAJIN2_ACTOR* actor, int think_idx) { + static s16 animeSeqNo[] = { aNPC_ANIM_WAIT_R1, aNPC_ANIM_WAIT_R1, aNPC_ANIM_WAIT_R1, aNPC_ANIM_WAIT_R1, aNPC_ANIM_WAIT_R1, aNPC_ANIM_WAIT_R1, aNPC_ANIM_GO_UG1}; + + NPC_CLIP->animation_init_proc((ACTOR*)actor, animeSeqNo[think_idx], FALSE); +} + +static void aMJN2_actor_draw(ACTOR* actorx, GAME* game) { + NPC_CLIP->draw_proc(actorx, game); +} + +#include "../src/actor/npc/ac_npc_majin2_talk.c_inc" +#include "../src/actor/npc/ac_npc_majin2_schedule.c_inc" diff --git a/src/actor/npc/ac_npc_majin2_schedule.c_inc b/src/actor/npc/ac_npc_majin2_schedule.c_inc new file mode 100644 index 00000000..0a707755 --- /dev/null +++ b/src/actor/npc/ac_npc_majin2_schedule.c_inc @@ -0,0 +1,202 @@ +static void aMJN2_set_request_act(NPC_MAJIN2_ACTOR* actor) { + actor->npc_class.request.act_priority = 1; + actor->npc_class.request.act_idx = aNPC_ACT_SPECIAL; + actor->npc_class.request.act_type = aNPC_ACT_TYPE_SEARCH; +} + +static void aMJN2_act_init_proc(NPC_ACTOR* nactorx, GAME_PLAY* play) { + nactorx->action.step = 0; +} + +static void aMJN2_act_proc(NPC_ACTOR* nactorx, GAME_PLAY* play, int type) { + static aNPC_SUB_PROC act_proc[] = { aMJN2_act_init_proc, (aNPC_SUB_PROC)none_proc1, (aNPC_SUB_PROC)none_proc1 }; + + (*act_proc[type])(nactorx, play); +} + +static int aMJN2_check_submenu(GAME_PLAY* play) { + int ret = FALSE; + + if (chkTrigger(BUTTON_START) || mSM_CHECK_OPEN_MAP() == TRUE) { + ret = TRUE; + } else { + ACTOR* playerx = GET_PLAYER_ACTOR_ACTOR(play); + + if (playerx != NULL) { + PLAYER_ACTOR* player = (PLAYER_ACTOR*)playerx; + + if (player->a_btn_pressed == TRUE && + ABS(DIFF_SHORT_ANGLE(playerx->shape_info.rotation.y, DEG2SHORT_ANGLE(-180.0f))) < DEG2SHORT_ANGLE2(45.0f)) { + switch (player->item_in_front) { + case MESSAGE_BOARD0: + case MESSAGE_BOARD1: + case MAP_BOARD0: + case MAP_BOARD1: + ret = TRUE; + break; + default: + break; + } + } + } + } + + return ret; +} + +static void aMJN2_start_wait(NPC_MAJIN2_ACTOR* actor, GAME_PLAY* play) { + if (!mPlib_check_player_actor_main_index_OutDoorMove2((GAME*)play)) { + aMJN2_setup_think_proc(actor, play, aMJN2_THINK_CALL); + } +} + +static void aMJN2_start_wait_st(NPC_MAJIN2_ACTOR* actor, GAME_PLAY* play) { + ACTOR* playerx = GET_PLAYER_ACTOR_ACTOR(play); + + if (playerx != NULL && playerx->world.position.z > 970.0f) { + aMJN2_setup_think_proc(actor, play, aMJN2_THINK_CALL); + } +} + +static void aMJN2_wait(NPC_MAJIN2_ACTOR* actor, GAME_PLAY* play) { + static int next_act_idx[] = { -1, aMJN2_THINK_FORCE_CALL, aMJN2_THINK_FORCE_CALL, aMJN2_THINK_FORCE_CALL_2, aMJN2_THINK_FORCE_CALL_2, aMJN2_THINK_FORCE_CALL_2 }; + int reset_type = Common_Get(reset_type); + + if (reset_type == 0) { + if (aMJN2_check_submenu(play) == TRUE) { + reset_type = 3; + } else if (GET_PLAYER_ACTOR_NOW()->excute_cancel_wade) { + reset_type = 2; + } + } + + if (reset_type != 0 && mDemo_CAN_ACTOR_TALK((ACTOR*)actor)) { + aMJN2_setup_think_proc(actor, play, next_act_idx[reset_type]); + } +} + +static void aMJN2_exit(NPC_MAJIN2_ACTOR* actor, GAME_PLAY* play) { + if (actor->npc_class.draw.main_animation_state == cKF_STATE_STOPPED) { + Actor_delete((ACTOR*)actor); + } +} + +static void aMJN2_think_main_proc(NPC_ACTOR* nactorx, GAME_PLAY* play) { + NPC_MAJIN2_ACTOR* actor = (NPC_MAJIN2_ACTOR*)nactorx; + + if (nactorx->action.idx == aNPC_ACT_SPECIAL) { + actor->think_proc(actor, play); + } else if (nactorx->action.step == aNPC_ACTION_END_STEP) { + aMJN2_set_request_act(actor); + } +} + +static void aMJN2_think_init_proc(NPC_ACTOR* nactorx, GAME_PLAY* play) { + static f32 def_posX[] = { 2220.0f, 2260.0f, 2220.0f, 2260.0f, 2220.0f }; + static f32 def_posZ[] = { 1460.0f, 1460.0f, 1740.0f, 1740.0f, 1020.0f }; + static s16 def_angl[] = { 0xD9F0, 0x2610, 0xD9F0, 0x2610, 0x4000 }; + static int def_think_idx[] = { aMJN2_THINK_START_WAIT, aMJN2_THINK_START_WAIT, aMJN2_THINK_START_WAIT, aMJN2_THINK_START_WAIT, aMJN2_THINK_START_WAIT_ST }; + NPC_MAJIN2_ACTOR* actor = (NPC_MAJIN2_ACTOR*)nactorx; + ACTOR* actorx = (ACTOR*)nactorx; + int pos_idx; + + actor->npc_class.action.act_proc = aMJN2_act_proc; + aMJN2_set_request_act(actor); + actorx->status_data.weight = MASSTYPE_HEAVY; + Common_Set(reset_type, 0); + + if (play->block_table.block_z == 1) { + pos_idx = 4; + } else { + pos_idx = mHS_get_arrange_idx(Common_Get(player_no)); + } + + actorx->world.position.x = def_posX[pos_idx]; + actorx->world.position.z = def_posZ[pos_idx]; + actorx->shape_info.rotation.y = def_angl[pos_idx]; + actorx->world.position.y = mCoBG_GetBgY_OnlyCenter_FromWpos(actorx->world.position, 0.0f); + aMJN2_setup_think_proc(actor, play, def_think_idx[pos_idx]); +} + +static void aMJN2_start_wait_init(NPC_MAJIN2_ACTOR* actor, GAME_PLAY* play) { + actor->npc_class.condition_info.hide_request = FALSE; + actor->npc_class.talk_info.default_turn_animation = aNPC_ANIM_WAIT_R1; + actor->npc_class.talk_info.default_animation = aNPC_ANIM_WAIT_R1; + + eEC_CLIP->effect_make_proc(eEC_EFFECT_RESET_HOLE, ((ACTOR*)actor)->world.position, 3, ((ACTOR*)actor)->shape_info.rotation.y, (GAME*)play, RSV_NO, 1, 0); + if (CLIP(demo_clip2) != NULL && CLIP(demo_clip2)->type == mDemo_CLIP_TYPE_RESET_DEMO) { + ACTOR* demox = (ACTOR*)CLIP(demo_clip2)->demo_class; + + if (demox != NULL) { + RESET_DEMO_ACTOR* reset_demo = (RESET_DEMO_ACTOR*)demox; + + reset_demo->request_light = TRUE; + } + } +} + +typedef void (*aMJN2_THINK_INIT_PROC)(NPC_MAJIN2_ACTOR* actor, GAME_PLAY* play); + +typedef struct { + aMJN2_THINK_PROC think_proc; + aMJN2_THINK_INIT_PROC think_init_proc; + aNPC_TALK_REQUEST_PROC talk_request_proc; + s8 norm_talk_idx; + s8 force_talk_idx; + u8 think_idx_when_talk_done; +} aMJN2_think_data_c; + +static void aMJN2_setup_think_proc(NPC_MAJIN2_ACTOR* actor, GAME_PLAY* play, int think_idx) { + // clang-format off + static aMJN2_think_data_c dt_tbl[] = { + {aMJN2_start_wait, aMJN2_start_wait_init, (aNPC_TALK_REQUEST_PROC)none_proc1, 0, 0, aMJN2_THINK_START_WAIT}, + {aMJN2_start_wait_st, aMJN2_start_wait_init, (aNPC_TALK_REQUEST_PROC)none_proc1, 0, 0, aMJN2_THINK_START_WAIT_ST}, + {(aMJN2_THINK_PROC)none_proc1, (aMJN2_THINK_INIT_PROC)none_proc1, aMJN2_force_talk_request, -1, 0, aMJN2_THINK_WAIT}, + {aMJN2_wait, (aMJN2_THINK_INIT_PROC)none_proc1, aMJN2_norm_talk_request, 0, -1, aMJN2_THINK_EXIT}, + {(aMJN2_THINK_PROC)none_proc1, (aMJN2_THINK_INIT_PROC)none_proc1, aMJN2_force_talk_request, -1, 1, aMJN2_THINK_WAIT}, + {(aMJN2_THINK_PROC)none_proc1, (aMJN2_THINK_INIT_PROC)none_proc1, aMJN2_force_talk_request, -1, 2, aMJN2_THINK_WAIT}, + {aMJN2_exit, (aMJN2_THINK_INIT_PROC)none_proc1, (aNPC_TALK_REQUEST_PROC)none_proc1, 0, 0, aMJN2_THINK_EXIT}, + }; + // clang-format on + + aMJN2_think_data_c* data_p = &dt_tbl[think_idx]; + + actor->think_idx = think_idx; + actor->think_proc = data_p->think_proc; + actor->npc_class.talk_info.talk_request_proc = data_p->talk_request_proc; + + if (data_p->norm_talk_idx >= 0) { + actor->norm_talk_idx = data_p->norm_talk_idx; + } + + if (data_p->force_talk_idx >= 0) { + actor->force_talk_idx = data_p->force_talk_idx; + } + + actor->next_think_idx = data_p->think_idx_when_talk_done; + aMJN2_set_animation(actor, think_idx); + (*data_p->think_init_proc)(actor, play); +} + +static void aMJN2_think_proc(NPC_ACTOR* nactorx, GAME_PLAY* play, int type) { + static aNPC_SUB_PROC think_proc[] = { aMJN2_think_init_proc, aMJN2_think_main_proc }; + + (*think_proc[type])(nactorx, play); +} + +static void aMJN2_schedule_init_proc(NPC_ACTOR* nactorx, GAME_PLAY* play) { + nactorx->think.think_proc = aMJN2_think_proc; + NPC_CLIP->think_proc(nactorx, play, aNPC_THINK_SPECIAL, aNPC_THINK_TYPE_INIT); +} + +static void aMJN2_schedule_main_proc(NPC_ACTOR* nactorx, GAME_PLAY* play) { + if (!NPC_CLIP->think_proc(nactorx, play, -1, aNPC_THINK_TYPE_CHK_INTERRUPT)) { + NPC_CLIP->think_proc(nactorx, play, -1, aNPC_THINK_TYPE_MAIN); + } +} + +static void aMJN2_schedule_proc(NPC_ACTOR* nactorx, GAME_PLAY* play, int type) { + static aNPC_SUB_PROC sche_proc[] = { aMJN2_schedule_init_proc, aMJN2_schedule_main_proc }; + + (*sche_proc[type])(nactorx, play); +} diff --git a/src/actor/npc/ac_npc_majin2_talk.c_inc b/src/actor/npc/ac_npc_majin2_talk.c_inc new file mode 100644 index 00000000..0479fb34 --- /dev/null +++ b/src/actor/npc/ac_npc_majin2_talk.c_inc @@ -0,0 +1,94 @@ +static void aMJN2_wait_talk_proc(NPC_MAJIN2_ACTOR* actor, GAME_PLAY* play) { + mMsg_Window_c* msg_p = mMsg_Get_base_window_p(); + + if (mMsg_Get_msg_num(msg_p) == 0x2364 && mMsg_Check_MainNormalContinue(msg_p) == TRUE) { + switch (mChoice_GET_CHOSENUM()) { + case mChoice_CHOICE0: + aMJN2_change_talk_proc(actor, aMJN2_TALK_END_WAIT); + break; + } + } +} + +static void aMJN2_change_talk_proc(NPC_MAJIN2_ACTOR* actor, int talk_idx) { + static aMJN2_TALK_PROC talk_proc[] = { aMJN2_wait_talk_proc, (aMJN2_TALK_PROC)none_proc1 }; + + actor->talk_proc = talk_proc[talk_idx]; +} + +typedef struct { + int msg_no; + aMJN2_TALK_PROC talk_proc; +} aMJN2_talk_data_c; + +static void aMJN2_set_force_talk_info(ACTOR* actorx) { + static aMJN2_talk_data_c dt_tbl[] = { + { 0x235D, (aMJN2_TALK_PROC)none_proc1 }, + { 0x235E, (aMJN2_TALK_PROC)none_proc1 }, + { 0x235F, (aMJN2_TALK_PROC)none_proc1 }, + }; + NPC_MAJIN2_ACTOR* actor = (NPC_MAJIN2_ACTOR*)actorx; + aMJN2_talk_data_c* data_p = &dt_tbl[actor->force_talk_idx]; + + mDemo_Set_msg_num(data_p->msg_no); + mDemo_Set_talk_turn(TRUE); + actor->talk_proc = data_p->talk_proc; + if (actorx->player_distance_xz > 140.0f) { + mDemo_Set_camera(CAMERA2_PROCESS_NORMAL); + } + mPlib_Set_able_hand_all_item_in_demo(TRUE); + mBGMPsComp_make_ps_quietField(0); + actor->next_think_idx = 3; +} + +static void aMJN2_force_talk_request(ACTOR* actorx, GAME* game) { + mDemo_Request(mDemo_TYPE_SPEAK, actorx, aMJN2_set_force_talk_info); +} + +static void aMJN2_set_norm_talk_info(ACTOR* actorx) { + static aMJN2_talk_data_c dt_tbl[] = { + { 0x2360, aMJN2_wait_talk_proc }, + }; + NPC_MAJIN2_ACTOR* actor = (NPC_MAJIN2_ACTOR*)actorx; + aMJN2_talk_data_c* data_p = &dt_tbl[actor->norm_talk_idx]; + + mDemo_Set_msg_num(data_p->msg_no); + mDemo_Set_talk_turn(TRUE); + actor->talk_proc = data_p->talk_proc; + mPlib_Set_able_hand_all_item_in_demo(TRUE); + mBGMPsComp_make_ps_quiet(0); + actor->next_think_idx = 6; +} + +static void aMJN2_norm_talk_request(ACTOR* actorx, GAME* game) { + mDemo_Request(mDemo_TYPE_TALK, actorx, aMJN2_set_norm_talk_info); +} + +static int aMJN2_talk_init(ACTOR* actorx, GAME* game) { + NPC_MAJIN2_ACTOR* actor = (NPC_MAJIN2_ACTOR*)actorx; + + actor->npc_class.talk_info.talk_request_proc = (aNPC_TALK_REQUEST_PROC)none_proc1; + mDemo_Set_ListenAble(); + return TRUE; +} + +static int aMJN2_talk_end_chk(ACTOR* actorx, GAME* game) { + NPC_MAJIN2_ACTOR* actor = (NPC_MAJIN2_ACTOR*)actorx; + GAME_PLAY* play = (GAME_PLAY*)game; + int ret = FALSE; + + actor->talk_proc(actor, play); + if (mDemo_CAN_ACTOR_TALK(actorx)) { + switch (actor->next_think_idx) { + case 3: + mBGMPsComp_delete_ps_quietField(); + break; + } + + Common_Set(reset_type, 0); + aMJN2_setup_think_proc(actor, play, actor->next_think_idx); + ret = TRUE; + } + + return ret; +} diff --git a/src/game/m_submenu.c b/src/game/m_submenu.c index 4aac8803..643be4e9 100644 --- a/src/game/m_submenu.c +++ b/src/game/m_submenu.c @@ -226,7 +226,7 @@ static int mSM_check_open_map_new(GAME_PLAY* play) { int bx; int bz; - if (chkTrigger(mSM_MAP_BUTTON) && Common_Get(map_flag) == TRUE) { + if (mSM_CHECK_OPEN_MAP()) { open_map = TRUE; }