diff --git a/config/rel_slices.yml b/config/rel_slices.yml index 1a040186..30d97da0 100644 --- a/config/rel_slices.yml +++ b/config/rel_slices.yml @@ -785,6 +785,10 @@ ac_my_house.c: ac_nameplate.c: .text: [0x805B63FC, 0x805B65C4] .data: [0x806C6110, 0x806C6138] +ac_needlework_shop.c: + .text: [0x805B65C4, 0x805B7338] + .rodata: [0x8064AAA0, 0x8064AAE8] + .data: [0x806C6138, 0x806C62D0] ac_radio.c: .text: [0x805B887C, 0x805B8C7C] .rodata: [0x8064AB58, 0x8064AB68] diff --git a/include/ac_needlework_shop.h b/include/ac_needlework_shop.h index fd3c5228..c59342c1 100644 --- a/include/ac_needlework_shop.h +++ b/include/ac_needlework_shop.h @@ -2,7 +2,7 @@ #define AC_NEEDLEWORK_SHOP_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 1a2f1e66..61f90eb4 100644 --- a/include/m_name_table.h +++ b/include/m_name_table.h @@ -2712,6 +2712,7 @@ extern int mNT_check_unknown(mActor_name_t item_no); #define DUMMY_HANIWA1 (DUMMY_HANIWA0 + 1) #define DUMMY_HANIWA2 (DUMMY_HANIWA1 + 1) #define DUMMY_HANIWA3 (DUMMY_HANIWA2 + 1) +#define DUMMY_NEEDLEWORK_SHOP 0xF0FF #define DUMMY_RESERVE 0xF102 #define DUMMY_SHRINE 0xF103 #define DUMMY_BROKER_SHOP 0xF104 diff --git a/src/ac_needlework_shop.c b/src/ac_needlework_shop.c new file mode 100644 index 00000000..30c07cf2 --- /dev/null +++ b/src/ac_needlework_shop.c @@ -0,0 +1,107 @@ +#include "ac_needlework_shop.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 { + aNW_ACTION_WAIT, + aNW_ACTION_OPEN_DOOR_WAIT, + aNW_ACTION_OPEN_DOOR, + aNW_ACTION_OPEN_UNKNOWN, + + aNW_ACTION_NUM +}; + +static void aNW_actor_ct(ACTOR* actor, GAME* game); +static void aNW_actor_dt(ACTOR* actor, GAME* game); +static void aNW_actor_init(ACTOR* actor, GAME* game); +static void aNW_actor_draw(ACTOR* actor, GAME* game); + +// clang-format off +ACTOR_PROFILE Needlework_Shop_Profile = { + mAc_PROFILE_NEEDLEWORK_SHOP, + ACTOR_PART_ITEM, + ACTOR_STATE_TA_SET, + NEEDLEWORK_SHOP, + ACTOR_OBJ_BANK_KEEP, + sizeof(STRUCTURE_ACTOR), + &aNW_actor_ct, + &aNW_actor_dt, + &aNW_actor_init, + &aNW_actor_draw, + NULL +}; +// clang-format on + +static u8 aNW_shadow_vtx_fix_flg_table[8] = { TRUE, FALSE, TRUE, FALSE, TRUE, FALSE, FALSE, FALSE }; + +extern Vtx obj_s_tailor_shadow_v[]; +extern Gfx obj_s_tailor_shadowT_model[]; + +// clang-format off +static bIT_ShadowData_c aNW_shadow_data = { + 6, + aNW_shadow_vtx_fix_flg_table, + 60.0f, + obj_s_tailor_shadow_v, + obj_s_tailor_shadowT_model +}; +// clang-format on + +static void aNW_set_bgOffset(STRUCTURE_ACTOR* shop, int idx); +static void aNW_setup_animation(STRUCTURE_ACTOR* shop, f32 speed); +static void aNW_setup_action(STRUCTURE_ACTOR* shop, int action); +static int aNW_ctrl_light(STRUCTURE_ACTOR* shop); + +extern cKF_Skeleton_R_c cKF_bs_r_obj_s_tailor; +extern cKF_Skeleton_R_c cKF_bs_r_obj_w_tailor; + +static void aNW_actor_ct(ACTOR* actor, GAME* game) { + static cKF_Skeleton_R_c* skl[] = { &cKF_bs_r_obj_s_tailor, &cKF_bs_r_obj_w_tailor }; + + STRUCTURE_ACTOR* shop; + + shop = (STRUCTURE_ACTOR*)actor; + shop->season = Common_Get(time.season); + cKF_SkeletonInfo_R_ct(&shop->keyframe, skl[shop->season == mTM_SEASON_WINTER], NULL, shop->work_area, + shop->morph_area); + + aNW_set_bgOffset(shop, 1); + + actor->world.position.x = actor->world.position.x + -20.0f; + actor->world.position.z = actor->world.position.z + 20.0f; + actor->cull_height = 800.0f; + actor->cull_radius = 400.0f; + actor->cull_width = 450.0f; + + shop->request_type = 0; + aNW_setup_animation(shop, 0.0f); + aNW_setup_action(shop, aNW_ACTION_WAIT); + + shop->keyframe_state = cKF_SkeletonInfo_R_play(&shop->keyframe); + shop->keyframe_saved_keyframe = 1; + + shop->arg0_f = aNW_ctrl_light(shop) != FALSE ? 1.0f : 0.0f; +} + +static void aNW_actor_dt(ACTOR* actor, GAME* game) { + STRUCTURE_ACTOR* shop; + + shop = (STRUCTURE_ACTOR*)actor; + cKF_SkeletonInfo_R_dt(&shop->keyframe); + actor->world.position.x -= -20.0f; + actor->world.position.z -= 20.0f; +} + +#include "../src/ac_needlework_shop_move.c_inc" + +#include "../src/ac_needlework_shop_draw.c_inc" diff --git a/src/ac_needlework_shop_draw.c_inc b/src/ac_needlework_shop_draw.c_inc new file mode 100644 index 00000000..678ea184 --- /dev/null +++ b/src/ac_needlework_shop_draw.c_inc @@ -0,0 +1,115 @@ +extern Gfx obj_s_tailor_window_model[]; +extern Gfx obj_w_tailor_window_model[]; + +static int aNW_actor_draw_before(GAME* game, cKF_SkeletonInfo_R_c* keyframe, int joint_idx, Gfx** joint_shape, + u8* joint_flags, void* arg, s_xyz* joint_rot, xyz_t* joint_pos) { + GRAPH* graph; + STRUCTURE_ACTOR* shop; + int rg; + int b; + Gfx* gfx; + + graph = game->graph; + shop = (STRUCTURE_ACTOR*)arg; + if (joint_idx == 5) { + OPEN_DISP(graph); + gfx = NOW_POLY_OPA_DISP; + + b = (shop->arg0_f * 150.0f) + 0.5f; + rg = (shop->arg0_f * 255.0f) + 0.5f; + + gDPSetPrimColor(gfx++, 0, 0, rg, rg, b, 255); + + SET_POLY_OPA_DISP(gfx); + CLOSE_DISP(graph); + } + + if (joint_idx == 6) { + *joint_shape = NULL; + } + + return TRUE; +} + +static int aNW_actor_draw_after(GAME* game, cKF_SkeletonInfo_R_c* keyframe, int joint_idx, Gfx** joint_shape, + u8* joint_flags, void* arg, s_xyz* joint_rot, xyz_t* joint_pos) { + static Gfx* mdl[] = { obj_s_tailor_window_model, obj_w_tailor_window_model }; + + STRUCTURE_ACTOR* shop; + GRAPH* graph; + Mtx* mtx; + int winter; + int l; + int r; + int g; + int b; + Gfx* gfx; + + shop = (STRUCTURE_ACTOR*)arg; + graph = game->graph; + + if (joint_idx == 6) { + mtx = _Matrix_to_Mtx_new(graph); + if (mtx != NULL) { + if (shop->arg0_f > 0.0f) { + r = 255; + g = 255; + b = 150; + l = (shop->arg0_f * 120.0f + 0.5f); + } else { + l = 0; + r = 0; + g = 0; + b = 0; + } + + winter = shop->season == mTM_SEASON_WINTER; + _texture_z_light_fog_prim_shadow(graph); + + OPEN_DISP(graph); + gfx = NOW_SHADOW_DISP; + + gDPSetPrimColor(gfx++, 0, l, r, g, b, 0); + gSPMatrix(gfx++, mtx, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPDisplayList(gfx++, mdl[winter]); + + SET_SHADOW_DISP(gfx); + CLOSE_DISP(graph); + } + } + + return TRUE; +} + +static void aNW_actor_draw(ACTOR* actor, GAME* game) { + STRUCTURE_ACTOR* shop; + GRAPH* graph; + cKF_SkeletonInfo_R_c* keyframe; + Mtx* mtx; + Gfx* gfx; + u16* pal; + + shop = (STRUCTURE_ACTOR*)actor; + graph = game->graph; + keyframe = &shop->keyframe; + + mtx = GRAPH_ALLOC_TYPE(graph, Mtx, (u32)keyframe->skeleton->num_shown_joints); + if (mtx != NULL) { + pal = Common_Get(clip).structure_clip->get_pal_segment_proc(aSTR_PAL_TAILOR); + if (mtx != NULL) { + _texture_z_light_fog_prim(graph); + + OPEN_DISP(graph); + gfx = NOW_POLY_OPA_DISP; + + gSPSegment(gfx++, 8, pal); + + SET_POLY_OPA_DISP(gfx); + CLOSE_DISP(graph); + + cKF_Si3_draw_R_SV(game, keyframe, mtx, &aNW_actor_draw_before, &aNW_actor_draw_after, actor); + Matrix_translate(0.0f, 60.0f, 0.0f, TRUE); + (*Common_Get(clip).bg_item_clip->draw_shadow_proc)(game, &aNW_shadow_data, FALSE); + } + } +} diff --git a/src/ac_needlework_shop_move.c_inc b/src/ac_needlework_shop_move.c_inc new file mode 100644 index 00000000..4634e55c --- /dev/null +++ b/src/ac_needlework_shop_move.c_inc @@ -0,0 +1,301 @@ +// clang-format off +static Door_data_c aNW_needlework_shop_door_data = { + SCENE_NEEDLEWORK, + 4, + FALSE, + 0, + {160,0,300}, + EMPTY_NO, + 1, + {0,0,0}, +}; +// clang-format on + +extern cKF_Animation_R_c cKF_ba_r_obj_s_tailor; +extern cKF_Animation_R_c cKF_ba_r_obj_s_tailor_out; +extern cKF_Animation_R_c cKF_ba_r_obj_w_tailor; +extern cKF_Animation_R_c cKF_ba_r_obj_w_tailor_out; + +static void aNW_set_door_SE_sub(STRUCTURE_ACTOR* shop, u16 se_no) { + sAdo_OngenTrgStart(se_no, &shop->actor_class.world.position); +} + +static void aNW_set_doorSE(STRUCTURE_ACTOR* shop) { + static f32 chk_pat_in[4] = { 10.0f, 14.0f, 35.0f, 50.0f }; + static f32 chk_pat_out[4] = { 2.0f, 8.0f, 33.0f, 40.0f }; + static u16 se_no[4] = { 6, 7, 8, 9 }; + + f32* chk_pat_p; + int i; + + switch (shop->request_type) { + case 1: + case 3: + chk_pat_p = chk_pat_in; + break; + default: + chk_pat_p = chk_pat_out; + break; + } + + for (i = 0; i < 4; i++, chk_pat_p++) { + if (cKF_FrameControl_passCheck_now(&shop->keyframe.frame_control, *chk_pat_p) != FALSE) { + aNW_set_door_SE_sub(shop, se_no[i]); + break; + } + } +} + +static void aNW_rewrite_out_data(STRUCTURE_ACTOR* shop, 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_WEST; + door_data->exit_type = 0; + door_data->extra_data = 2; + + pos.x = shop->actor_class.world.position.x - 64.0f; + pos.z = shop->actor_class.world.position.z + 64.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 = NEEDLEWORK_SHOP; + + door_data->wipe_type = 1; + } +} + +static int aNW_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 - 40.0f)); + zOffs = SQ(player->actor_class.world.position.z - (actor->world.position.z + 50.0f)); + t = (xOffs) + (zOffs); + + if ((y > 0x4000) && (y < 0x8000) && (t < 360.0f) && chkTrigger(BUTTON_A) != 0) { + res = 2; + } + + return res; +} + +static int aNW_check_open(STRUCTURE_ACTOR* shop, GAME_PLAY* play) { + static int cond[] = { 1, 1, 2, 3 }; + + switch (shop->request_type) { + case 0: + return aNW_check_player(&shop->actor_class, play); + case 5: + return 0; + default: + return cond[shop->request_type - 1]; + } +} + +static void aNW_set_bgOffset(STRUCTURE_ACTOR* shop, int idx) { + // clang-format off + static mCoBG_OffsetTable_c height_table_ct[] = { + { mCoBG_ATTRIBUTE_NONE, 0, 0, 0, 0, 0, 0 }, + { mCoBG_ATTRIBUTE_NONE, 13, 13, 0, 13, 13, 1 }, + { mCoBG_ATTRIBUTE_NONE, 13, 13, 13, 0, 13, 1 }, + { mCoBG_ATTRIBUTE_NONE, 0, 0, 0, 0, 0, 0 }, + { mCoBG_ATTRIBUTE_NONE, 13, 13, 0, 13, 13, 1 }, + { mCoBG_ATTRIBUTE_NONE, 13, 13, 13, 13, 14, 0 }, + { mCoBG_ATTRIBUTE_NONE, 13, 14, 13, 13, 13, 0 }, + { mCoBG_ATTRIBUTE_NONE, 13, 13, 13, 0, 13, 1 }, + { mCoBG_ATTRIBUTE_NONE, 13, 0, 13, 13, 13, 1 }, + { mCoBG_ATTRIBUTE_NONE, 13, 13, 13, 14, 13, 0 }, + { mCoBG_ATTRIBUTE_NONE, 13, 13, 14, 13, 13, 0 }, + { mCoBG_ATTRIBUTE_NONE, 13, 13, 13, 13, 0, 1 }, + { mCoBG_ATTRIBUTE_NONE, 0, 0, 0, 0, 0, 0 }, + { mCoBG_ATTRIBUTE_NONE, 13, 0, 13, 13, 13, 1 }, + { mCoBG_ATTRIBUTE_NONE, 13, 13, 13, 13, 0, 1 }, + { mCoBG_ATTRIBUTE_NONE, 0, 0, 0, 0, 0, 0 } + }; + // clang-format on + + static mCoBG_OffsetTable_c* height_table[] = { height_table_ct, height_table_ct }; + + static f32 addX[] = { -80.0f, -40.0f, 0.0f, 40.0f }; + static f32 addZ[] = { 80.0f, 40.0f, 0.0f, -40.0f }; + + mCoBG_OffsetTable_c* offset; + int i; + int j; + xyz_t pos; + + offset = height_table[idx]; + for (i = 0; i < 4; i++) { + pos.z = shop->actor_class.home.position.z + addZ[i]; + + for (j = 0; j < 4; j++) { + if (j + i * 4 != 0 && j + i * 4 != 3 && j + i * 4 != 12 && j + i * 4 != 15) { + pos.x = shop->actor_class.home.position.x + addX[j]; + mCoBG_SetPluss5PointOffset_file(pos, *offset, __FILE__, 315); + } + + offset++; + } + } +} + +static void aNW_setup_animation(STRUCTURE_ACTOR* shop, f32 speed) { + // clang-format off + static cKF_Animation_R_c* animation[2][2] = { + { &cKF_ba_r_obj_s_tailor, &cKF_ba_r_obj_s_tailor_out }, + { &cKF_ba_r_obj_w_tailor, &cKF_ba_r_obj_w_tailor_out } + }; + // clang-format on + + static f32 start_idx[] = { 1.0f, 25.0f, 1.0f, 1.0f }; + static f32 end_idx[] = { 51.0f, 51.0f, 51.0f, 51.0f }; + + int winter; + int idx; + + winter = shop->season == mTM_SEASON_WINTER; + switch (shop->request_type) { + case 2: + idx = 2; + break; + case 4: + idx = 1; + break; + default: + idx = 0; + break; + } + + cKF_SkeletonInfo_R_init(&shop->keyframe, shop->keyframe.skeleton, animation[winter][idx != 0], start_idx[idx], + end_idx[idx], start_idx[idx], speed, 0.0f, cKF_FRAMECONTROL_STOP, NULL); +} + +static void aNW_open_door_demo_ct() { + mDemo_Set_house_info(40.0f, 5); + mDemo_Set_camera(CAMERA2_PROCESS_DOOR); +} + +static void aNW_talk_door_demo_ct() { + static rgba_t window_color = { 145, 60, 40, 255 }; + + mDemo_Set_msg_num(0x7DA); + mDemo_Set_talk_display_name(FALSE); + mDemo_Set_camera(CAMERA2_PROCESS_NORMAL); + mPlib_Set_able_hand_all_item_in_demo(TRUE); + mDemo_Set_ListenAble(); + mDemo_Set_talk_window_color(&window_color); +} + +static int aNW_check_opend() { + int now_sec = Common_Get(time.now_sec); + return !(now_sec < (25200) && now_sec >= (7200)); +} + +static int aNW_ctrl_light(STRUCTURE_ACTOR* shop) { + int now_sec = Common_Get(time.now_sec); + return !(now_sec < (64800) && now_sec >= (18000)) && (aNW_check_opend() != 0); +} + +static void aNW_wait(STRUCTURE_ACTOR* shop, GAME_PLAY* play) { + ACTOR* actor; + int request_type; + int check_open; + + actor = (ACTOR*)shop; + request_type = shop->request_type; + + if (mDemo_Check(mDemo_TYPE_DOOR, actor) != FALSE) { + if (request_type == 4) { + aNW_setup_animation(shop, 0.5f); + } + + aNW_setup_action(shop, aNW_ACTION_OPEN_DOOR_WAIT); + return; + } + + if (mDemo_Check(mDemo_TYPE_SPEAK, actor) == FALSE) { + check_open = aNW_check_open(shop, play); + if (check_open == 2) { + if (aNW_check_opend() != FALSE) { + mDemo_Request(mDemo_TYPE_DOOR, actor, &aNW_open_door_demo_ct); + } else { + mDemo_Request(mDemo_TYPE_SPEAK, actor, &aNW_talk_door_demo_ct); + } + } else if (check_open == 3) { + if (request_type == 4) { + aNW_setup_animation(shop, 0.5f); + } + + aNW_setup_action(shop, aNW_ACTION_OPEN_DOOR); + } + } +} + +static void aNW_open_door_wait(STRUCTURE_ACTOR* shop, GAME_PLAY* play) { + if (shop == GET_PLAYER_ACTOR_NOW()->get_door_label_proc(gamePT)) { + shop->request_type = 3; + aNW_setup_animation(shop, 0.5f); + aNW_setup_action(shop, aNW_ACTION_OPEN_DOOR); + mBGMPsComp_make_ps_wipe(0x249); // TODO: enum/define + } +} + +static void aNW_open_door(STRUCTURE_ACTOR* shop, GAME_PLAY* play) { + if (cKF_SkeletonInfo_R_play(&shop->keyframe) == TRUE) { + if (shop->request_type == 3) { + aNW_rewrite_out_data(shop, play); + goto_other_scene(play, &aNW_needlework_shop_door_data, FALSE); + aNW_setup_action(shop, aNW_ACTION_OPEN_UNKNOWN); + mDemo_End((ACTOR*)shop); + } else { + aNW_setup_action(shop, aNW_ACTION_WAIT); + } + + shop->request_type = 0; + } +} + +static void aNW_setup_action(STRUCTURE_ACTOR* shop, int action) { + static aSTR_MOVE_PROC process[] = { &aNW_wait, &aNW_open_door_wait, &aNW_open_door, (aSTR_MOVE_PROC)&none_proc1 }; + + shop->action_proc = process[action]; +} + +static void aNW_actor_move(ACTOR* actor, GAME* game) { + STRUCTURE_ACTOR* shop; + GAME_PLAY* play; + f32 target; + + shop = (STRUCTURE_ACTOR*)actor; + play = (GAME_PLAY*)game; + + aNW_set_doorSE(shop); + (*shop->action_proc)(shop, play); + target = (aNW_ctrl_light(shop) != 0) ? 1.0f : 0.0f; + chase_f(&shop->arg0_f, target, 0.019532442f); +} + +static void aNW_actor_init(ACTOR* actor, GAME* game) { + mFI_SetFG_common(DUMMY_NEEDLEWORK_SHOP, actor->home.position, 0); + aNW_actor_move(actor, game); + actor->mv_proc = aNW_actor_move; +}