From 3eaceb26ccba312699592095e9e1bd714a06a029 Mon Sep 17 00:00:00 2001 From: Cuyler36 Date: Wed, 3 Jan 2024 23:32:57 -0500 Subject: [PATCH] Implement & link ac_ev_castaway --- config/rel_slices.yml | 4 ++ include/ac_ev_castaway.h | 8 +++ include/ac_npc.h | 7 +-- src/ac_ev_castaway.c | 100 ++++++++++++++++++++++++++++++++++++++ src/ac_npc_rtc.c | 2 +- src/ac_npc_rtc_talk.c.inc | 4 +- 6 files changed, 119 insertions(+), 6 deletions(-) create mode 100644 src/ac_ev_castaway.c diff --git a/config/rel_slices.yml b/config/rel_slices.yml index dbf702a3..d7385f58 100644 --- a/config/rel_slices.yml +++ b/config/rel_slices.yml @@ -549,6 +549,10 @@ ac_aprilfool_control.c: ac_groundhog_control.c: .text: [0x805155C8, 0x80515C48] .data: [0x8069FD88, 0x8069FDD0] +ac_ev_castaway.c: + .text: [0x8051CAC4, 0x8051CDCC] + .rodata: [0x806491B0, 0x806491B8] + .data: [0x806A03A0, 0x806A03F8] ac_ev_dokutu.c: .text: [0x8051DFF4, 0x8051E228] .data: [0x806A05C8, 0x806A0608] diff --git a/include/ac_ev_castaway.h b/include/ac_ev_castaway.h index be48b6bc..08c49480 100644 --- a/include/ac_ev_castaway.h +++ b/include/ac_ev_castaway.h @@ -3,11 +3,19 @@ #include "types.h" #include "m_actor.h" +#include "ac_npc.h" #ifdef __cplusplus extern "C" { #endif +typedef struct ev_castaway_s EV_CASTAWAY_ACTOR; + +struct ev_castaway_s { + NPC_ACTOR npc_class; + s16 bobbing_cycle; +}; + extern ACTOR_PROFILE Ev_Castaway_Profile; #ifdef __cplusplus diff --git a/include/ac_npc.h b/include/ac_npc.h index 46f17a1e..9cb57488 100644 --- a/include/ac_npc.h +++ b/include/ac_npc.h @@ -16,6 +16,7 @@ extern "C" { #define aNPC_SPNPC_BIT_CURATOR 0 #define aNPC_SPNPC_BIT_GOHOME_NPC 1 #define aNPC_SPNPC_BIT_MASK_CAT 2 +#define aNPC_SPNPC_BIT_CASTAWAY 4 #define aNPC_SPNPC_BIT_EV_SONCHO 5 #define aNPC_SPNPC_BIT_GET(field, bit) (((field) >> (bit)) & 1) @@ -141,7 +142,7 @@ typedef struct npc_draw_info_s { /* 0x000 */ u8 _000[0x20 - 0]; /* 0x020 */ f32 _20; /* 0x024 */ f32 _24; - /* 0x024 */ u8 _028[0x534 - 0x028]; + /* 0x028 */ u8 _028[0x534 - 0x028]; /* 0x538 */ u8 _534; /* 0x538 */ u8 _535; /* 0x538 */ u8 _536; @@ -149,13 +150,13 @@ typedef struct npc_draw_info_s { /* 0x538 */ u8 _538; /* 0x538 */ u8 _539; /* 0x540 */ u8 _53A[0x580 - 0x53A]; - /* 0x580 */ int _580; + /* 0x580 */ int animation_id; /* 0x584 */ int texture_bank_idx; /* 0x588 */ u8 _588[0x5BD - 0x588]; /* 0x5BD */ u8 _5BD; /* 0x5BE */ u8 _5BE; /* 0x5BE */ u8 _5BF[0x630 - 0x5BF]; -} aNPC_draw_info_c; +} aNPC_draw_info_c; typedef void (*aNPC_THINK_PROC)(NPC_ACTOR*, GAME_PLAY*, int); diff --git a/src/ac_ev_castaway.c b/src/ac_ev_castaway.c new file mode 100644 index 00000000..2ab33b8c --- /dev/null +++ b/src/ac_ev_castaway.c @@ -0,0 +1,100 @@ +#include "ac_ev_castaway.h" + +#include "m_common_data.h" + +static void aECST_actor_ct(ACTOR* actorx, GAME* game); +static void aECST_actor_dt(ACTOR* actorx, GAME* game); +static void aECST_actor_init(ACTOR* actorx, GAME* game); +static void aECST_actor_move(ACTOR* actorx, GAME* game); +static void aECST_actor_draw(ACTOR* actorx, GAME* game); +static void aECST_actor_save(ACTOR* actorx, GAME* game); + +ACTOR_PROFILE Ev_Castaway_Profile = { + mAc_PROFILE_EV_CASTAWAY, + ACTOR_PART_NPC, + ACTOR_STATE_CAN_MOVE_IN_DEMO_SCENES | ACTOR_STATE_NO_MOVE_WHILE_CULLED, + EMPTY_NO, + ACTOR_OBJ_BANK_KEEP, + sizeof(EV_CASTAWAY_ACTOR), + &aECST_actor_ct, + &aECST_actor_dt, + &aECST_actor_init, + mActor_NONE_PROC1, + &aECST_actor_save +}; + +static void aECST_schedule_proc(NPC_ACTOR* actorx, GAME_PLAY* play, int type); + +static void aECST_actor_ct(ACTOR* actorx, GAME* game) { + static aNPC_ct_data_c ct_data = { + &aECST_actor_move, + &aECST_actor_draw, + 5, + NULL, + NULL, + NULL, + 0 + }; + + static xyz_t def_pos = { 3580.0f, 0.0f, 4670.0f }; // 'G-5' @ 9-4 + + EV_CASTAWAY_ACTOR* castaway = (EV_CASTAWAY_ACTOR*)actorx; + + if ((*Common_Get(clip).npc_clip->birth_check_proc)(actorx, game) == TRUE) { + castaway->npc_class.schedule.schedule_proc = &aECST_schedule_proc; + (*Common_Get(clip).npc_clip->ct_proc)(actorx, game, &ct_data); + castaway->npc_class.condition_info.demo_flg = ~aNPC_COND_DEMO_SKIP_MOVE_Y; // is this a mistake? + castaway->npc_class.condition_info.hide_request = FALSE; + castaway->npc_class.palActorIgnoreTimer = -1; + aNPC_SPNPC_BIT_SET(Common_Get(spnpc_first_talk_flags), aNPC_SPNPC_BIT_CASTAWAY); + actorx->status_data.weight = 254; + actorx->gravity = 0.0f; + actorx->max_velocity_y = 0.0f; + actorx->shape_info.rotation.y = DEG2SHORT_ANGLE(68.027344f); // 0x3060 + actorx->world.angle.y = DEG2SHORT_ANGLE(68.027344f); // 0x3060 + castaway->npc_class.movement.mv_angl = DEG2SHORT_ANGLE(68.027344f); // 0x3060 + actorx->world.position = def_pos; + actorx->home.position = def_pos; + } +} + +static void aECST_actor_save(ACTOR* actorx, GAME* game) { + (*Common_Get(clip).npc_clip->save_proc)(actorx, game); +} + +static void aECST_actor_dt(ACTOR* actorx, GAME* game) { + (*Common_Get(clip).npc_clip->dt_proc)(actorx, game); +} + +static void aECST_actor_init(ACTOR* actorx, GAME* game) { + (*Common_Get(clip).npc_clip->init_proc)(actorx, game); +} + +static void aECST_schedule_main_proc(NPC_ACTOR* actorx, GAME_PLAY* play) { + if (actorx->draw.animation_id != 116) { + (*Common_Get(clip).npc_clip->animation_init_proc)((ACTOR*)actorx, 116, 0); + } +} + +static void aECST_schedule_proc(NPC_ACTOR* actorx, GAME_PLAY* play, int type) { + static aNPC_SUB_PROC sched_proc[2] = { + (aNPC_SUB_PROC)&none_proc1, + aECST_schedule_main_proc + }; + + (*sched_proc[type])(actorx, play); +} + +static void aECST_actor_move(ACTOR* actorx, GAME* game) { + EV_CASTAWAY_ACTOR* castaway = (EV_CASTAWAY_ACTOR*)actorx; + s16 cycle = castaway->bobbing_cycle; + + cycle += 512; + actorx->position_speed.y = (actorx->home.position.y + 4.0f + sin_s(cycle) * 4.0f) - actorx->world.position.y; + castaway->bobbing_cycle = cycle; + (*Common_Get(clip).npc_clip->move_proc)(actorx, game); +} + +static void aECST_actor_draw(ACTOR* actorx, GAME* game) { + (*Common_Get(clip).npc_clip->draw_proc)(actorx, game); +} diff --git a/src/ac_npc_rtc.c b/src/ac_npc_rtc.c index cd19d9ff..6eef7e3d 100644 --- a/src/ac_npc_rtc.c +++ b/src/ac_npc_rtc.c @@ -108,7 +108,7 @@ void aNRTC_actor_move(ACTOR* actor, GAME* game){ GAME_PLAY* play = (GAME_PLAY*)game; - if(rtc->npc_class.draw._580 == 0x76){ + if(rtc->npc_class.draw.animation_id == 0x76){ sAdos_GetStaffRollInfo(&info); if(info.unk0 != 4){ val = 0.0f; diff --git a/src/ac_npc_rtc_talk.c.inc b/src/ac_npc_rtc_talk.c.inc index f5a40a98..ccb8c4e9 100644 --- a/src/ac_npc_rtc_talk.c.inc +++ b/src/ac_npc_rtc_talk.c.inc @@ -326,10 +326,10 @@ int aNRTC_talk_end_chk(ACTOR* actor,GAME* game){ } if (mDemo_Get_OrderValue(4, 0) == 0) { if (unk9AC >= 0x258) { - if ( rtc->npc_class.draw._580 != 0x76) { + if ( rtc->npc_class.draw.animation_id != 0x76) { mDemo_Set_OrderValue(4, 0, 0xFF); } - } else if (rtc->npc_class.draw._580 == 0x76) { + } else if (rtc->npc_class.draw.animation_id == 0x76) { mDemo_Set_OrderValue(4, 0, 0xFD); } }