From 42b4c3db9d51aa4a85356cce743ee087bbc26214 Mon Sep 17 00:00:00 2001 From: Hexalotl <15166449+Hexalotl@users.noreply.github.com> Date: Mon, 25 Mar 2024 18:49:07 -0700 Subject: [PATCH] Implement & link ac_kamakura --- config/rel_slices.yml | 4 + include/ac_kamakura.h | 2 +- include/m_name_table.h | 1 + src/ac_kamakura.c | 98 ++++++++++++++++ src/ac_kamakura_draw.c_inc | 77 +++++++++++++ src/ac_kamakura_move.c_inc | 229 +++++++++++++++++++++++++++++++++++++ 6 files changed, 410 insertions(+), 1 deletion(-) create mode 100644 src/ac_kamakura.c create mode 100644 src/ac_kamakura_draw.c_inc create mode 100644 src/ac_kamakura_move.c_inc diff --git a/config/rel_slices.yml b/config/rel_slices.yml index 1f820f7e..93ba40ca 100644 --- a/config/rel_slices.yml +++ b/config/rel_slices.yml @@ -778,6 +778,10 @@ ac_fallSESW.c: ac_kago.c: .text: [0x805B1A08, 0x805B1D50] .data: [0x806C5750, 0x806C57A8] +ac_kamakura.c: + .text: [0x805B1D50, 0x805B27B8] + .rodata: [0x8064A948, 0x8064A978] + .data: [0x806C57A8, 0x806C58A0] ac_koinobori.c: .text: [0x805B27B8, 0x805B2AE0] .data: [0x806C58A0, 0x806C5940] diff --git a/include/ac_kamakura.h b/include/ac_kamakura.h index 410920bf..6cd5c85c 100644 --- a/include/ac_kamakura.h +++ b/include/ac_kamakura.h @@ -2,7 +2,7 @@ #define AC_KAMAKURA_H #include "types.h" -#include "m_actor.h" +#include "ac_structure.h" #ifdef __cplusplus extern "C" { diff --git a/include/m_name_table.h b/include/m_name_table.h index 1eeebd5c..28bd44e4 100644 --- a/include/m_name_table.h +++ b/include/m_name_table.h @@ -2720,6 +2720,7 @@ extern int mNT_check_unknown(mActor_name_t item_no); #define DUMMY_BROKER_SHOP 0xF104 #define DUMMY_BUGGY 0xF105 #define DUMMY_CAR 0xF106 +#define DUMMY_KAMAKURA 0xF107 #define DUMMY_RADIO 0xF109 #define DUMMY_YATAI 0xF10A #define DUMMY_TUKIMI 0xF10A diff --git a/src/ac_kamakura.c b/src/ac_kamakura.c new file mode 100644 index 00000000..845bab26 --- /dev/null +++ b/src/ac_kamakura.c @@ -0,0 +1,98 @@ +#include "ac_kamakura.h" + +#include "m_name_table.h" +#include "bg_item_h.h" +#include "m_common_data.h" +#include "m_house.h" +#include "m_player_lib.h" +#include "m_demo.h" +#include "ac_intro_demo.h" +#include "m_bgm.h" +#include "sys_matrix.h" +#include "m_rcp.h" +#include "libforest/gbi_extensions.h" + +enum { + aKKR_ACTION_WAIT, + aKKR_ACTION_DELETED1, + aKKR_ACTION_DELETED2, + aKKR_ACTION_DELETED3, + aKKR_ACTION_DELETED4, + aKKR_ACTION_DELETED5, + aKKR_ACTION_DELETED6, + aKKR_ACTION_DELETED7, + + aKKR_ACTION_NUM +}; + +static void aKKR_actor_ct(ACTOR* actor, GAME* game); +static void aKKR_actor_dt(ACTOR* actor, GAME* game); +static void aKKR_actor_init(ACTOR* actor, GAME* game); +static void aKKR_actor_draw(ACTOR* actor, GAME* game); + +// clang-format off +ACTOR_PROFILE Kamakura_Profile = { + mAc_PROFILE_KAMAKURA, + ACTOR_PART_ITEM, + ACTOR_STATE_TA_SET, + KAMAKURA, + ACTOR_OBJ_BANK_KEEP, + sizeof(STRUCTURE_ACTOR), + &aKKR_actor_ct, + &aKKR_actor_dt, + &aKKR_actor_init, + &aKKR_actor_draw, + NULL +}; +// clang-format on + +// clang-format off +static u8 aKKR_shadow_vtx_fix_flg_table[] = { + TRUE, FALSE, FALSE, TRUE, + TRUE, FALSE, FALSE, TRUE, + FALSE, TRUE, TRUE, FALSE, + TRUE, FALSE, TRUE, FALSE, + FALSE, TRUE, TRUE, FALSE +}; +// clang-format on + +extern Vtx obj_w_kamakura_shadow_v[]; +extern Gfx obj_e_kamakura_shadow_model[]; + +// clang-format off +static bIT_ShadowData_c aKKR_shadow_data = { + 20, + aKKR_shadow_vtx_fix_flg_table, + 60.0f, + obj_w_kamakura_shadow_v, + obj_e_kamakura_shadow_model +}; +// clang-format on + +static void change_FGUnit(STRUCTURE_ACTOR* kamakura, int type); +static void aKKR_setup_action(STRUCTURE_ACTOR* kamakura, int action); +static void aKKR_set_bgOffset(STRUCTURE_ACTOR* kamakura, int offs); +static int aKKR_ctrl_light(STRUCTURE_ACTOR* kamakura); + +static void aKKR_actor_ct(ACTOR* actor, GAME* game) { + STRUCTURE_ACTOR* kamakura; + + kamakura = (STRUCTURE_ACTOR*)actor; + change_FGUnit(kamakura, 1); + + aKKR_setup_action(kamakura, aKKR_ACTION_WAIT); + aKKR_set_bgOffset(kamakura, 1); + + kamakura->arg0_f = aKKR_ctrl_light(kamakura) ? 1.0f : 0.0f; +} + +static void aKKR_actor_dt(ACTOR* actor, GAME* game) { + STRUCTURE_ACTOR* kamakura; + + kamakura = (STRUCTURE_ACTOR*)actor; + change_FGUnit(kamakura, 0); +} + +#include "../src/ac_kamakura_move.c_inc" + +#include "../src/ac_kamakura_draw.c_inc" diff --git a/src/ac_kamakura_draw.c_inc b/src/ac_kamakura_draw.c_inc new file mode 100644 index 00000000..82c268fc --- /dev/null +++ b/src/ac_kamakura_draw.c_inc @@ -0,0 +1,77 @@ +extern Gfx kamakura_DL_model[]; +extern Gfx obj_w_kamakura_window_model[]; + +static void aKKR_actor_draw(ACTOR* actor, GAME* game) { + STRUCTURE_ACTOR* kamakura; + GRAPH* graph; + Mtx* mtx; + f32 color; + int r1; + int g1; + int b1; + int l2; + int r2; + int g2; + int b2; + u16* pal; + Gfx* poly_opa; + Gfx* poly_xlu; + + kamakura = (STRUCTURE_ACTOR*)actor; + graph = game->graph; + color = kamakura->arg0_f; + pal = Common_Get(clip).structure_clip->get_pal_segment_proc(aSTR_PAL_KAMAKURA); + mtx = _Matrix_to_Mtx_new(graph); + if (mtx == NULL) { + return; + } + + if (color > 0.0f) { + r2 = 255; + g2 = 255; + b2 = 150; + + r1 = (color * 255.0f) + 0.5f; + g1 = (color * 255.0f) + 0.5f; + b1 = (color * 150.0f) + 0.5f; + l2 = (color * 120.0f) + 0.5f; + } else { + r1 = 0; + g1 = 0; + b1 = 0; + + l2 = 0; + r2 = 0; + g2 = 0; + b2 = 0; + } + + OPEN_DISP(graph); + { + _texture_z_light_fog_prim_npc(graph); + + poly_opa = NOW_POLY_OPA_DISP; + + gSPMatrix(poly_opa++, mtx, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPSegment(poly_opa++, G_MWO_SEGMENT_8, pal); + gDPPipeSync(poly_opa++); + gDPSetEnvColor(poly_opa++, r1, g1, b1, 0); + gSPDisplayList(poly_opa++, kamakura_DL_model); + SET_POLY_OPA_DISP(poly_opa); + } + { + _texture_z_light_fog_prim_xlu(graph); + + poly_xlu = NOW_POLY_XLU_DISP; + + gSPMatrix(poly_xlu++, mtx, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gDPSetPrimColor(poly_xlu++, 0, l2, r2, g2, b2, 0); + + gSPDisplayList(poly_xlu++, obj_w_kamakura_window_model); + SET_POLY_XLU_DISP(poly_xlu); + } + CLOSE_DISP(graph); + + _texture_z_light_fog_prim_shadow(graph); + (*Common_Get(clip).bg_item_clip->draw_shadow_proc)(game, &aKKR_shadow_data, FALSE); +} diff --git a/src/ac_kamakura_move.c_inc b/src/ac_kamakura_move.c_inc new file mode 100644 index 00000000..c8fc9295 --- /dev/null +++ b/src/ac_kamakura_move.c_inc @@ -0,0 +1,229 @@ +// clang-format off +static Door_data_c aKKR_kamakura_enter_data = { + SCENE_KAMAKURA, + mSc_DIRECT_NORTH, + FALSE, + 0, + {160,0,300}, + EMPTY_NO, + 1, + {0,0,0}, +}; +// clang-format on + +static void change_FGUnit(STRUCTURE_ACTOR* kamakura, int type) { + int dug; + xyz_t pos; + mActor_name_t* unit_fg; + + xyz_t_move(&pos, &kamakura->actor_class.world.position); + pos.z += 80.0f; + + if (type == FALSE) { + mFI_SetFG_common(EMPTY_NO, pos, TRUE); + return; + } + + unit_fg = mFI_GetUnitFG(pos); + if (unit_fg == NULL) { + return; + } + + if (mSN_ClearSnowman(unit_fg) == FALSE) { + dug = FALSE; + if ((((*unit_fg >= BURIED_PITFALL_START) && (*unit_fg <= BURIED_PITFALL_END)) || (*unit_fg == SHINE_SPOT))) { + dug = TRUE; + } + + if (dug == TRUE) { + mPB_keep_item(bg_item_fg_sub_dig2take_conv(*unit_fg)); + mFI_SetFG_common(RSV_NO, pos, 1); + mFI_Wpos2DepositOFF(pos); + } else { + mFI_Wpos2DepositOFF(pos); + mPB_keep_item(*unit_fg); + mFI_SetFG_common(RSV_NO, pos, 1); + } + } else { + mFI_SetFG_common(RSV_NO, pos, 1); + } +} + +static void aKKR_set_bgOffset(STRUCTURE_ACTOR* kamakura, int offs) { + // clang-format off + static mCoBG_OffsetTable_c height_table_ct[] = { + { mCoBG_ATTRIBUTE_NONE, 6, 0, 6, 6, 6, 1 }, + { mCoBG_ATTRIBUTE_NONE, 6, 6, 6, 6, 6, 0 }, + { mCoBG_ATTRIBUTE_NONE, 6, 6, 6, 6, 0, 1 }, + { mCoBG_ATTRIBUTE_NONE, 6, 6, 6, 6, 6, 0 }, + { mCoBG_ATTRIBUTE_NONE, 8, 8, 8, 8, 8, 0 }, + { mCoBG_ATTRIBUTE_NONE, 6, 6, 6, 6, 6, 0 }, + { mCoBG_ATTRIBUTE_NONE, 6, 6, 0, 6, 6, 1 }, + { mCoBG_ATTRIBUTE_NONE, 6, 6, 6, 6, 6, 0 }, + { mCoBG_ATTRIBUTE_NONE, 6, 6, 6, 0, 6, 1 } + }; + // clang-format on + + static mCoBG_OffsetTable_c* height_table[] = { height_table_ct, height_table_ct }; + + static f32 addX[] = { -mFI_UT_WORLDSIZE_X_F, 0.0f, mFI_UT_WORLDSIZE_X_F }; + static f32 addZ[] = { -mFI_UT_WORLDSIZE_Z_F, 0.0f, mFI_UT_WORLDSIZE_Z_F }; + + mCoBG_OffsetTable_c* offset; + int i; + xyz_t pos; + + offset = height_table[offs]; + + for (i = 0; i < 3; i++) { + pos.z = kamakura->actor_class.home.position.z + addZ[i]; + + pos.x = kamakura->actor_class.home.position.x + addX[0]; + mCoBG_SetPluss5PointOffset_file(pos, offset[0], __FILE__, 202); + + pos.x = kamakura->actor_class.home.position.x + addX[1]; + mCoBG_SetPluss5PointOffset_file(pos, offset[1], __FILE__, 206); + + pos.x = kamakura->actor_class.home.position.x + addX[2]; + mCoBG_SetPluss5PointOffset_file(pos, offset[2], __FILE__, 210); + + offset += 3; + } +} + +static void aKKR_rewrite_out_data(ACTOR* actor, GAME_PLAY* play) { + Door_data_c* door_data; + xyz_t pos; + + door_data = Common_GetPointer(structure_exit_door_data); + if (play->fb_wipe_mode == 0) { + door_data->next_scene_id = Save_Get(scene_no); + door_data->exit_orientation = mSc_DIRECT_SOUTH; + door_data->exit_type = 0; + door_data->extra_data = 3; + + pos.x = actor->world.position.x; + pos.z = actor->world.position.z + 86.0f; + pos.y = mCoBG_GetBgY_OnlyCenter_FromWpos2(pos, 0.0f); + + door_data->exit_position.x = pos.x; + door_data->exit_position.y = pos.y; + door_data->exit_position.z = pos.z; + + door_data->door_actor_name = KAMAKURA; + + door_data->wipe_type = 1; + + mBGMPsComp_make_ps_wipe(0x2168); + } +} + +static int aKKR_check_player(ACTOR* actor, GAME_PLAY* play) { + u16 y; + f32 xOffs; + f32 zOffs; + f32 t; + int res; + PLAYER_ACTOR* player; + + player = GET_PLAYER_ACTOR(play); + res = 0; + + if (player == NULL) { + return 0; + } + + y = player->actor_class.shape_info.rotation.y; + xOffs = SQ(player->actor_class.world.position.x - actor->world.position.x); + zOffs = SQ(player->actor_class.world.position.z - (actor->world.position.z + 40.0f)); + t = (xOffs) + (zOffs); + + if ((y > DEG2SHORT_ANGLE2(135.0f)) && (y < DEG2SHORT_ANGLE2(225.0f)) && (t < 1600.0f)) { // 0x6000 && 0xA000 + res = 1; + } + + return res; +} + +static void aKKR_wait(STRUCTURE_ACTOR* kamakura, GAME_PLAY* play) { + ACTOR* actor; + GAME* game; + xyz_t pos; + + actor = &kamakura->actor_class; + game = &play->game; + + if (kamakura == GET_PLAYER_ACTOR_NOW()->get_door_label_proc(gamePT)) { + aKKR_rewrite_out_data(actor, play); + goto_other_scene(play, &aKKR_kamakura_enter_data, TRUE); + return; + } + + if (aKKR_check_player(actor, play) == 0) { + return; + } + + pos.x = actor->world.position.x; + pos.y = GET_PLAYER_ACTOR(play)->actor_class.world.position.y; + pos.z = actor->world.position.z + 68.0f; + mPlib_request_main_door_type1(game, &pos, -DEG2SHORT_ANGLE(180.0f), TRUE, actor); // 0x8000 +} + +static void aKKR_setup_action(STRUCTURE_ACTOR* kamakura, int action) { + static aSTR_MOVE_PROC process[] = { + &aKKR_wait, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + }; + + kamakura->action_proc = process[action]; + kamakura->action = action; +} + +static int aKKR_ctrl_light(STRUCTURE_ACTOR* kamakura) { + int now_sec = Common_Get(time.now_sec); + return !(now_sec < (64800) && now_sec >= (21600)); +} + +static void aKKR_actor_move(ACTOR* actor, GAME* game) { + GAME_PLAY* play; + STRUCTURE_ACTOR* kamakura; + PLAYER_ACTOR* player; + int bx1; + int bz1; + int bx2; + int bz2; + f32 window; + + play = (GAME_PLAY*)game; + kamakura = (STRUCTURE_ACTOR*)actor; + player = GET_PLAYER_ACTOR(play); + + mFI_Wpos2BlockNum(&bx1, &bz1, actor->world.position); + mFI_Wpos2BlockNum(&bx2, &bz2, player->actor_class.world.position); + + if ((mDemo_Check(mDemo_TYPE_SCROLL, &player->actor_class) == FALSE) && + (mDemo_Check(mDemo_TYPE_SCROLL2, &player->actor_class) == FALSE) && + (mDemo_Check(mDemo_TYPE_SCROLL3, &player->actor_class) == FALSE) && ((bx1 != bx2) || (bz1 != bz2))) { + Actor_delete(actor); + } else { + kamakura->action_proc(kamakura, play); + + window = (aKKR_ctrl_light(kamakura) != 0) ? 1.0f : 0.0f; + chase_f(&kamakura->arg0_f, window, 0.019532442f); + } +} + +static void aKKR_actor_init(ACTOR* actor, GAME* game) { + xyz_t pos; + + pos = actor->home.position; + mFI_SetFG_common(DUMMY_KAMAKURA, pos, FALSE); + aKKR_actor_move(actor, game); + actor->mv_proc = aKKR_actor_move; +}