From ff991d5114f8ff29b81ff00aa6e43fab4bdcf8da Mon Sep 17 00:00:00 2001 From: Cuyler36 Date: Fri, 7 Feb 2025 12:20:37 -0500 Subject: [PATCH] Implement & link ac_present_demo --- configure.py | 2 +- include/ac_present_demo.h | 27 ++++- include/m_soncho.h | 12 +- src/actor/ac_present_demo.c | 57 +++++++++ src/actor/ac_present_demo_move.c_inc | 174 +++++++++++++++++++++++++++ src/game/m_soncho.c | 18 +-- 6 files changed, 278 insertions(+), 12 deletions(-) create mode 100644 src/actor/ac_present_demo.c create mode 100644 src/actor/ac_present_demo_move.c_inc diff --git a/configure.py b/configure.py index e066b914..0e6ddb6f 100644 --- a/configure.py +++ b/configure.py @@ -1033,7 +1033,7 @@ config.libs = [ Object(Matching, "actor/ac_needlework_shop.c"), Object(Matching, "actor/ac_police_box.c"), Object(Matching, "actor/ac_post_office.c"), - Object(NonMatching, "actor/ac_present_demo.c"), + Object(Matching, "actor/ac_present_demo.c"), Object(Matching, "actor/ac_psnowman.c"), Object(NonMatching, "actor/ac_pterminal.c"), Object(Matching, "actor/ac_quest_manager.c"), diff --git a/include/ac_present_demo.h b/include/ac_present_demo.h index a8512823..acc405da 100644 --- a/include/ac_present_demo.h +++ b/include/ac_present_demo.h @@ -8,6 +8,32 @@ extern "C" { #endif +enum { + aPRD_TYPE_BIRTHDAY, + aPRD_TYPE_GOLDEN_ROD, + aPRD_TYPE_GOLDEN_NET, + aPRD_TYPE_SONCHO_VACATION0_CONTRIBUTED, + aPRD_TYPE_SONCHO_VACATION1_CONTRIBUTED, + aPRD_TYPE_SONCHO_VACATION0_STARTED, + aPRD_TYPE_SONCHO_VACATION1_STARTED, + + aPRD_TYPE_NUM +}; + +typedef struct present_demo_actor_s PRESENT_DEMO_ACTOR; + +typedef void (*aPRD_ACTION_PROC)(PRESENT_DEMO_ACTOR* present_demo, GAME* game); + +struct present_demo_actor_s { + ACTOR actor_class; + int action; + aPRD_ACTION_PROC action_proc; + ACTOR* world_actor; + int _180; + int type; + mActor_name_t present; +}; + extern ACTOR_PROFILE Present_Demo_Profile; #ifdef __cplusplus @@ -15,4 +41,3 @@ extern ACTOR_PROFILE Present_Demo_Profile; #endif #endif - diff --git a/include/m_soncho.h b/include/m_soncho.h index df975c7e..214d207e 100644 --- a/include/m_soncho.h +++ b/include/m_soncho.h @@ -18,6 +18,16 @@ extern "C" { #define mSC_TROPHY_GOLDEN_SCOOP 30 // assumed #define mSC_TROPHY_GOLDEN_ROD 31 +enum { + mSC_LIGHTHOUSE_EVENT_NONE, + mSC_LIGHTHOUSE_EVENT_JAN_CONTRIBUTED, + mSC_LIGHTHOUSE_EVENT_JAN_STARTED, + mSC_LIGHTHOUSE_EVENT_FEB_CONTRIBUTED, + mSC_LIGHTHOUSE_EVENT_FEB_STARTED, + + mSC_LIGHTHOUSE_EVENT_NUM +}; + enum { mSC_EVENT_NEW_YEARS_DAY, mSC_EVENT_FOUNDERS_DAY, @@ -125,7 +135,7 @@ extern int mSC_LightHouse_get_period(lbRTC_time_c* time); extern int mSC_LightHouse_day(const lbRTC_time_c* time); extern int mSC_LightHouse_Event_Check(int player_no); extern void mSC_LightHouse_Event_Clear(int player_no); -extern mActor_name_t mSC_LightHouse_Event_Present_Item(); +extern mActor_name_t mSC_LightHouse_Event_Present_Item(u32 player_no); extern int mSC_LightHouse_Event_Start(); extern int mSC_LightHouse_Talk_After_Check(); extern void mSC_LightHouse_Quest_Start(); diff --git a/src/actor/ac_present_demo.c b/src/actor/ac_present_demo.c new file mode 100644 index 00000000..b379da37 --- /dev/null +++ b/src/actor/ac_present_demo.c @@ -0,0 +1,57 @@ +#include "ac_present_demo.h" + +#include "libultra/libultra.h" +#include "m_common_data.h" +#include "m_soncho.h" +#include "m_player_lib.h" + +enum { + aPRD_ACTION_FIRST_SET, + aPRD_ACTION_PL_COME_OUT_WAIT, + aPRD_ACTION_PRESENT_WAIT, + aPRD_ACTION_RETIRE_NPC_WAIT, + + aPRD_ACTION_NUM +}; + +static void aPRD_actor_ct(ACTOR* actorx, GAME* game); +static void aPRD_actor_dt(ACTOR* actorx, GAME* game); +static void aPRD_actor_move(ACTOR* actorx, GAME* game); + +// clang-format off +ACTOR_PROFILE Present_Demo_Profile = { + mAc_PROFILE_PRESENT_DEMO, + ACTOR_PART_CONTROL, + ACTOR_STATE_CAN_MOVE_IN_DEMO_SCENES | ACTOR_STATE_NO_MOVE_WHILE_CULLED, + EMPTY_NO, + ACTOR_OBJ_BANK_KEEP, + sizeof(PRESENT_DEMO_ACTOR), + aPRD_actor_ct, + aPRD_actor_dt, + aPRD_actor_move, + mActor_NONE_PROC1, + NULL, +}; +// clang-format on + +static mDemo_Clip_c aPRD_clip; + +static void aPRD_setupAction(PRESENT_DEMO_ACTOR* present_demo, GAME* game, int action); + +static void aPRD_actor_ct(ACTOR* actorx, GAME* game) { + PRESENT_DEMO_ACTOR* actor = (PRESENT_DEMO_ACTOR*)actorx; + + CLIP(demo_clip2) = &aPRD_clip; + bzero(CLIP(demo_clip2), sizeof(aPRD_clip)); + CLIP(demo_clip2)->demo_class = actorx; + CLIP(demo_clip2)->type = mDemo_CLIP_TYPE_PRESENT_DEMO; + aPRD_setupAction(actor, game, aPRD_ACTION_FIRST_SET); +} + +static void aPRD_actor_dt(ACTOR* actorx, GAME* game) { + if (CLIP(demo_clip2) != NULL) { + CLIP(demo_clip2) = NULL; + } +} + +#include "../src/actor/ac_present_demo_move.c_inc" diff --git a/src/actor/ac_present_demo_move.c_inc b/src/actor/ac_present_demo_move.c_inc new file mode 100644 index 00000000..c8ea6972 --- /dev/null +++ b/src/actor/ac_present_demo_move.c_inc @@ -0,0 +1,174 @@ +static void aPRD_setup_present(PRESENT_DEMO_ACTOR* present_demo) { + int type = aPRD_TYPE_GOLDEN_ROD; + mActor_name_t present = ITM_GOLDEN_ROD; + + if (Common_Get(time.rtc_time.month) == Now_Private->birthday.month && Common_Get(time.rtc_time.day) == Now_Private->birthday.day && Now_Private->birthday_present_npc != EMPTY_NO) { + type = aPRD_TYPE_BIRTHDAY; + present = FTR_FAMICOM_DONKEY_KONG; + } else if (mSC_LightHouse_Event_Check(Common_Get(player_no)) != mSC_LIGHTHOUSE_EVENT_NONE) { + switch (mSC_LightHouse_Event_Check(Common_Get(player_no))) { + case mSC_LIGHTHOUSE_EVENT_JAN_CONTRIBUTED: + type = aPRD_TYPE_SONCHO_VACATION0_CONTRIBUTED; + present = mSC_LightHouse_Event_Present_Item(Common_Get(player_no)); + break; + case mSC_LIGHTHOUSE_EVENT_FEB_CONTRIBUTED: + type = aPRD_TYPE_SONCHO_VACATION1_CONTRIBUTED; + present = mSC_LightHouse_Event_Present_Item(Common_Get(player_no)); + break; + case mSC_LIGHTHOUSE_EVENT_JAN_STARTED: + type = aPRD_TYPE_SONCHO_VACATION0_STARTED; + present = EMPTY_NO; + break; + case mSC_LIGHTHOUSE_EVENT_FEB_STARTED: + type = aPRD_TYPE_SONCHO_VACATION1_STARTED; + present = EMPTY_NO; + break; + } + } else { + if (mSM_CHECK_ALL_FISH_GET() && mSC_trophy_get(mSC_TROPHY_GOLDEN_ROD) == FALSE) { + type = aPRD_TYPE_GOLDEN_ROD; + present = ITM_GOLDEN_ROD; + } else if (mSM_CHECK_ALL_INSECT_GET() && mSC_trophy_get(mSC_TROPHY_GOLDEN_NET) == FALSE) { + type = aPRD_TYPE_GOLDEN_NET; + present = ITM_GOLDEN_NET; + } else { + type = aPRD_TYPE_SONCHO_VACATION1_STARTED; + present = EMPTY_NO; + } + } + + present_demo->type = type; + present_demo->present = present; +} + +static int aPRD_setup_present_normal_npc_info(void) { + int ret = TRUE; + mNpc_MaskNpc_c* mask_npc = mNpc_GetSameMaskNpc(SP_NPC_PRESENT_NPC); + + if (mask_npc == NULL) { + if (ITEM_NAME_GET_TYPE(Now_Private->birthday_present_npc) != NAME_TYPE_NPC) { + ret = FALSE; + } else { + ret = mNpc_RegistMaskNpc(SP_NPC_PRESENT_NPC, Now_Private->birthday_present_npc, EMPTY_NO); + } + } + + return ret; +} + +static int aPRD_setup_present_soncho_info(void) { + return mNpc_RegistMaskNpc(SP_NPC_PRESENT_NPC, SP_NPC_EV_SONCHO, EMPTY_NO); +} + +static int aPRD_setup_present_npc_info(PRESENT_DEMO_ACTOR* present_demo) { + if (present_demo->type == aPRD_TYPE_BIRTHDAY) { + return aPRD_setup_present_normal_npc_info(); + } else { + return aPRD_setup_present_soncho_info(); + } +} + +static void aPRD_first_set(PRESENT_DEMO_ACTOR* present_demo, GAME* game) { + GAME_PLAY* play = (GAME_PLAY*)game; + + if (aPRD_setup_present_npc_info(present_demo) == FALSE) { + Actor_delete((ACTOR*)present_demo); + return; + } + + if (CLIP(npc_clip) != NULL && CLIP(npc_clip)->setupActor_proc != NULL) { + int res = CLIP(npc_clip)->setupActor_proc(play, SP_NPC_PRESENT_NPC, -1, -1, -1, play->block_table.block_x, play->block_table.block_z, 6, 6); + + if (res == TRUE) { + present_demo->world_actor = Actor_info_fgName_search(&play->actor_info, SP_NPC_PRESENT_NPC, ACTOR_PART_NPC); + aPRD_setupAction(present_demo, game, aPRD_ACTION_PL_COME_OUT_WAIT); + } + } +} + +static void aPRD_pl_come_out_wait(PRESENT_DEMO_ACTOR* present_demo, GAME* game) { + if (mPlib_check_player_actor_main_index_OutDoorMove2(game) == FALSE) { + aPRD_setupAction(present_demo, game, aPRD_ACTION_PRESENT_WAIT); + } +} + +static void aPRD_present_wait(PRESENT_DEMO_ACTOR* present_demo, GAME* game) { + if (present_demo->_180 == TRUE) { + aPRD_setupAction(present_demo, game, aPRD_ACTION_RETIRE_NPC_WAIT); + } +} + +static void aPRD_retire_npc_wait(PRESENT_DEMO_ACTOR* present_demo, GAME* game) { + GAME_PLAY* play = (GAME_PLAY*)game; + + if (present_demo->world_actor != NULL) { + return; + } + + play->submenu.start_refuse = FALSE; + switch (present_demo->type) { + case aPRD_TYPE_BIRTHDAY: + Now_Private->birthday_present_npc = EMPTY_NO; + mPlib_request_main_wait_type3(game); + break; + case aPRD_TYPE_GOLDEN_ROD: + mSC_trophy_set(mSC_TROPHY_GOLDEN_ROD); + mPlib_request_main_demo_get_golden_item2_type1(game, mPlayer_GOLDEN_ITEM_TYPE_ROD); + break; + case aPRD_TYPE_GOLDEN_NET: + mSC_trophy_set(mSC_TROPHY_GOLDEN_NET); + mPlib_request_main_demo_get_golden_item2_type1(game, mPlayer_GOLDEN_ITEM_TYPE_NET); + break; + default: + mPlib_request_main_wait_type3(game); + break; + } + + Actor_delete((ACTOR*)present_demo); +} + +static void aPRD_first_set_init(PRESENT_DEMO_ACTOR* present_demo, GAME* game) { + aPRD_setup_present(present_demo); +} + +static void aPRD_pl_come_out_wait_init(PRESENT_DEMO_ACTOR* present_demo, GAME* game) { + GAME_PLAY* play = (GAME_PLAY*)game; + + play->submenu.start_refuse = TRUE; +} + +static void aPRD_present_wait_init(PRESENT_DEMO_ACTOR* present_demo, GAME* game) { + mPlib_request_main_demo_wait_type1(game, FALSE, NULL); +} + +typedef void (*aPRD_INIT_PROC)(PRESENT_DEMO_ACTOR* present_demo, GAME* game); + +static void aPRD_init_proc(PRESENT_DEMO_ACTOR* present_demo, GAME* game, int action) { + static aPRD_INIT_PROC init_proc[] = { + aPRD_first_set_init, + aPRD_pl_come_out_wait_init, + aPRD_present_wait_init, + aPRD_present_wait_init, + }; + + init_proc[action](present_demo, game); +} + +static void aPRD_setupAction(PRESENT_DEMO_ACTOR* present_demo, GAME* game, int action) { + static aPRD_ACTION_PROC process[] = { + aPRD_first_set, + aPRD_pl_come_out_wait, + aPRD_present_wait, + aPRD_retire_npc_wait, + }; + + present_demo->action_proc = process[action]; + present_demo->action = action; + aPRD_init_proc(present_demo, game, action); +} + +static void aPRD_actor_move(ACTOR* actorx, GAME* game) { + PRESENT_DEMO_ACTOR* present_demo = (PRESENT_DEMO_ACTOR*)actorx; + + present_demo->action_proc(present_demo, game); +} diff --git a/src/game/m_soncho.c b/src/game/m_soncho.c index 7619467b..e69696f1 100644 --- a/src/game/m_soncho.c +++ b/src/game/m_soncho.c @@ -911,34 +911,34 @@ extern int mSC_LightHouse_Event_Check(int player_no) { } if (player_no >= mPr_FOREIGNER) { - return 0; + return mSC_LIGHTHOUSE_EVENT_NONE; } if (mSC_LightHouse_get_period(Common_GetPointer(time.rtc_time)) != mSC_LIGHTHOUSE_PERIOD_2) { - return 0; + return mSC_LIGHTHOUSE_EVENT_NONE; } if ((lh->players_completed & (1 << player_no)) != 0) { - return 0; + return mSC_LIGHTHOUSE_EVENT_NONE; } if ((lh->days_switched_on & 0x7F) == 0x7F) { if ((lh->players_quest_started & (u8)(1 << (player_no + 4))) != 0) { if (lh->renew_time.month == lbRTC_JANUARY) { - return 1; + return mSC_LIGHTHOUSE_EVENT_JAN_CONTRIBUTED; } else { - return 3; + return mSC_LIGHTHOUSE_EVENT_FEB_CONTRIBUTED; } } } else if ((lh->players_quest_started & (u8)(1 << Common_Get(player_no))) != 0) { if (lh->renew_time.month == lbRTC_JANUARY) { - return 2; + return mSC_LIGHTHOUSE_EVENT_JAN_STARTED; } else { - return 4; + return mSC_LIGHTHOUSE_EVENT_FEB_STARTED; } } - return 0; + return mSC_LIGHTHOUSE_EVENT_NONE; } extern void mSC_LightHouse_Event_Clear(int player_no) { @@ -960,7 +960,7 @@ extern void mSC_LightHouse_Event_Clear(int player_no) { } } -extern mActor_name_t mSC_LightHouse_Event_Present_Item() { +extern mActor_name_t mSC_LightHouse_Event_Present_Item(u32 player_no) { if (Save_Get(LightHouse).renew_time.month == lbRTC_JANUARY) { return FTR_LIGHTHOUSE_MODEL; }