Skip to content

Commit

Permalink
Implement & link ac_npc_shop_mastersp
Browse files Browse the repository at this point in the history
  • Loading branch information
Cuyler36 committed Dec 29, 2024
1 parent 6a945e1 commit eedc964
Show file tree
Hide file tree
Showing 10 changed files with 1,026 additions and 3 deletions.
2 changes: 1 addition & 1 deletion configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1130,7 +1130,7 @@ def MatchingFor(*versions):
Object(Matching, "actor/npc/ac_npc_sendo.c"),
Object(NonMatching, "actor/npc/ac_npc_shasho.c"),
Object(Matching, "actor/npc/ac_npc_shop_master.c"),
Object(NonMatching, "actor/npc/ac_npc_shop_mastersp.c"),
Object(Matching, "actor/npc/ac_npc_shop_mastersp.c"),
Object(NonMatching, "actor/npc/ac_npc_sleep_obaba.c"),
Object(NonMatching, "actor/npc/ac_npc_soncho.c"),
Object(NonMatching, "actor/npc/ac_npc_station_master.c"),
Expand Down
4 changes: 3 additions & 1 deletion include/ac_npc.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,11 +352,13 @@ typedef struct npc_action_s {
aNPC_ACTION_PROC act_proc;
} aNPC_action_c;

#define aNPC_REQUEST_ARG_NUM 6

typedef struct npc_request_s {
u8 act_priority;
u8 act_idx;
u8 act_type;
u16 act_args[6];
u16 act_args[aNPC_REQUEST_ARG_NUM];
u8 umb_flag;
u8 _11;
u8 head_priority;
Expand Down
34 changes: 33 additions & 1 deletion include/ac_npc_shop_mastersp.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,48 @@

#include "types.h"
#include "m_actor.h"
#include "ac_npc.h"
#include "m_shop.h"
#include "m_player_lib.h"

#ifdef __cplusplus
extern "C" {
#endif

#define aSHM_REQ_TICKET_NUM 5

#define aSHM_FIRST_PLACE_PERCENT 5
#define aSHM_SECOND_PLACE_PERCENT (10 + aSHM_FIRST_PLACE_PERCENT)
#define aSHM_THIRD_PLACE_PERCENT (20 + aSHM_SECOND_PLACE_PERCENT)

typedef struct npc_shop_mastersp_actor_s NPC_SHOP_MASTERSP_ACTOR;

typedef void (*aSHM_THINK_PROC)(NPC_SHOP_MASTERSP_ACTOR*, GAME_PLAY*);
typedef void (*aSHM_TALK_PROC)(NPC_SHOP_MASTERSP_ACTOR*, GAME_PLAY*);

struct npc_shop_mastersp_actor_s {
NPC_ACTOR npc_class;
int think_idx;
int next_think_idx;
int move_think_idx;
aSHM_THINK_PROC think_proc;
int talk_idx;
aSHM_TALK_PROC talk_proc;
s16 result;
s16 timer;
s16 root;
s16 root_idx;
s16 now_idx;
int month;
int ut[2];
int melody_bak;
s16 base_pos[11][2];
};

extern ACTOR_PROFILE Npc_Shop_Mastersp_Profile;

#ifdef __cplusplus
}
#endif

#endif

2 changes: 2 additions & 0 deletions include/audio_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ typedef enum audio_sound_effects {
NA_SE_STONECOIN_ROLL = 0x7D,
NA_SE_STONECOIN_DRAG = 0x7E,

NA_SE_7F = 0x7F,

NA_SE_TRAIN_RIDE = 0x8D,

NA_SE_GOKI_MOVE = 0xA8,
Expand Down
2 changes: 2 additions & 0 deletions include/m_demo.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ extern int mDemo_Check_ListenAble();
extern int mDemo_Check_DiffAngle_forTalk(s16 diff_angle);
extern void mDemo_KeepCamera(int camera_type);

#define mDemo_CAN_ACTOR_TALK(actor) (!mDemo_Check(mDemo_TYPE_SPEAK, (actor)) && !mDemo_Check(mDemo_TYPE_TALK, (actor)))

#ifdef __cplusplus
}
#endif
Expand Down
3 changes: 3 additions & 0 deletions include/m_name_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ extern int mNT_check_unknown(mActor_name_t item_no);

#define TICKET_MONTH(n) (1 + (((n) >> 3) & 0xF))
#define TICKET_COUNT(n) (1 + ((n) & 7))
#define TICKET_TO_MONTH(month) (((month) - 1) << 3)
#define TICKET_TO_COUNT(cnt) ((cnt) & 7)
#define TICKET_GET_ITEM(month, cnt) (ITM_TICKET_START | (((month) - 1) << 3) | ((cnt) & 7))
#define WISP_COUNT(n) (ITEM_IS_WISP(n) ? (1 + (n) - ITM_SPIRIT0) : 0)

#define ITEM_IS_INSECT(n) ((n) >= ITM_INSECT_START && (n) < ITM_INSECT_END)
Expand Down
135 changes: 135 additions & 0 deletions src/actor/npc/ac_npc_shop_mastersp.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
#include "ac_npc_shop_mastersp.h"

#include "m_common_data.h"
#include "libultra/libultra.h"
#include "m_item_name.h"
#include "m_msg.h"
#include "m_bgm.h"

enum {
aSHM_WON_FIRST_PLACE,
aSHM_WON_SECOND_PLACE,
aSHM_WON_THIRD_PLACE,
aSHM_DIDNT_WIN,

aSHM_WIN_NUM
};

enum {
aSHM_TALK_TALK_TRY,
aSHM_TALK_TALK_HAZURE,
aSHM_TALK_TALK_RETRY,
aSHM_TALK_STOP_PLAYER,
aSHM_TALK_GIVE_PLAYER,
aSHM_TALK_TALK_TAMAKESI,
aSHM_TALK_END_WAIT,
aSHM_TALK_SAY_GOODBYE,
aSHM_TALK_EXIT_WAIT,

aSHM_TALK_NUM
};

enum {
aSHM_THINK_NORMAL_WAIT,
aSHM_THINK_NORMAL_WAIT2,
aSHM_THINK_NORMAL_WAIT3,
aSHM_THINK_NORMAL_TURN,
aSHM_THINK_4,
aSHM_THINK_5,
aSHM_THINK_WIN1,
aSHM_THINK_WIN2,
aSHM_THINK_WIN3,
aSHM_THINK_LOSE,
aSHM_THINK_10,
aSHM_THINK_11,
aSHM_THINK_12,
aSHM_THINK_MOVE,
aSHM_THINK_MOVE_TURN,
aSHM_THINK_FADE_OUT,
aSHM_THINK_MOVE_PLAYER,
aSHM_THINK_WAIT_PLAYER,
aSHM_THINK_WAIT_PLAYER2,
aSHM_THINK_WAIT_PLAYER3,
aSHM_THINK_WAIT_PLAYER4,
aSHM_THINK_HIROU,
aSHM_THINK_HAPPY_ACADEMY,
aSHM_THINK_HAPPY_ACADEMY2,
aSHM_THINK_HAPPY_ACADEMY3,

aSHM_THINK_NUM
};

static void aSHM_actor_ct(ACTOR* actorx, GAME* game);
static void aSHM_actor_dt(ACTOR* actorx, GAME* game);
static void aSHM_actor_move(ACTOR* actorx, GAME* game);
static void aSHM_actor_init(ACTOR* actorx, GAME* game);
static void aSHM_actor_draw(ACTOR* actorx, GAME* game);
static void aSHM_actor_save(ACTOR* actorx, GAME* game);

// clang-format off
ACTOR_PROFILE Npc_Shop_Mastersp_Profile = {
mAc_PROFILE_NPC_SHOP_MASTERSP,
ACTOR_PART_NPC,
ACTOR_STATE_NONE,
SP_NPC_SHOP_MASTERSP,
ACTOR_OBJ_BANK_KEEP,
sizeof(NPC_SHOP_MASTERSP_ACTOR),
&aSHM_actor_ct,
&aSHM_actor_dt,
&aSHM_actor_init,
mActor_NONE_PROC1,
&aSHM_actor_save,
};
// clang-format on

static int aSHM_talk_init(ACTOR* actorx, GAME* game);
static int aSHM_talk_end_chk(ACTOR* actorx, GAME* game);

static void aSHM_schedule_proc(NPC_ACTOR* nactorx, GAME_PLAY* play, int type);
static int aSHM_change_talk_proc(NPC_SHOP_MASTERSP_ACTOR* shop_mastersp, int talk_proc_idx);
static void aSHM_setup_think_proc(NPC_SHOP_MASTERSP_ACTOR* shop_mastersp, GAME_PLAY* play, int think_idx);

static void aSHM_set_base_position(ACTOR* actorx, GAME_PLAY* play);

static void aSHM_actor_ct(ACTOR* actorx, GAME* game) {
// clang-format off
static aNPC_ct_data_c ct_data = {
&aSHM_actor_move,
&aSHM_actor_draw,
5,
(aNPC_TALK_REQUEST_PROC)&none_proc1,
&aSHM_talk_init,
&aSHM_talk_end_chk,
0,
};
// clang-format on

if (CLIP(npc_clip)->birth_check_proc(actorx, game) == TRUE) {
NPC_SHOP_MASTERSP_ACTOR* shop_mastersp = (NPC_SHOP_MASTERSP_ACTOR*)actorx;

shop_mastersp->npc_class.schedule.schedule_proc = &aSHM_schedule_proc;
CLIP(npc_clip)->ct_proc(actorx, game, &ct_data);
aSHM_set_base_position(actorx, (GAME_PLAY*)game);
shop_mastersp->melody_bak = 0;
}
}

static void aSHM_actor_save(ACTOR* actorx, GAME* game) {
mNpc_RenewalSetNpc(actorx);
}

static void aSHM_actor_dt(ACTOR* actorx, GAME* game) {
CLIP(npc_clip)->dt_proc(actorx, game);
}

static void aSHM_actor_init(ACTOR* actorx, GAME* game) {
CLIP(npc_clip)->init_proc(actorx, game);
}

static void aSHM_actor_draw(ACTOR* actorx, GAME* game) {
CLIP(npc_clip)->draw_proc(actorx, game);
}

#include "../src/actor/npc/ac_npc_shop_mastersp_move.c_inc"
#include "../src/actor/npc/ac_npc_shop_mastersp_talk.c_inc"
#include "../src/actor/npc/ac_npc_shop_mastersp_schedule.c_inc"
123 changes: 123 additions & 0 deletions src/actor/npc/ac_npc_shop_mastersp_move.c_inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
static s16 aSHM_ftr_revise_x(mActor_name_t item) {
if (mRmTp_ItemNo2FtrSize(item) == mRmTp_FTRSIZE_1x1) {
return -(mFI_UT_WORLDSIZE_X / 2);
}

return 0;
}

static s16 aSHM_ftr_revise_z(mActor_name_t item) {
if (mRmTp_ItemNo2FtrSize(item) == mRmTp_FTRSIZE_2x2) {
return 0;
}

return -mFI_UT_WORLDSIZE_Z;
}

static void aSHM_set_base_position(ACTOR* actorx, GAME_PLAY* play) {
NPC_SHOP_MASTERSP_ACTOR* shop_mastersp = (NPC_SHOP_MASTERSP_ACTOR*)actorx;
int level = mSP_GetShopLevel();
mActor_name_t* item_p = Save_Get(shop).lottery_items;
static s16 base_table_x[] = { 160, 240, 240, 240 };
static s16 base_table_z[] = { 140, 140, 300, 300 };
ACTOR* player = GET_PLAYER_ACTOR_ACTOR(play);

shop_mastersp->base_pos[0][0] = base_table_x[level];
shop_mastersp->base_pos[0][1] = base_table_z[level];

actorx->world.position.x = shop_mastersp->base_pos[0][0];
actorx->world.position.z = shop_mastersp->base_pos[0][1];

shop_mastersp->base_pos[1][0] = base_table_x[level];
shop_mastersp->base_pos[1][1] = base_table_z[level] - 2;
shop_mastersp->base_pos[1][0] += aSHM_ftr_revise_x(item_p[0]);
shop_mastersp->base_pos[1][1] += aSHM_ftr_revise_z(item_p[0]);

shop_mastersp->base_pos[2][0] = base_table_x[level] + 80;
shop_mastersp->base_pos[2][1] = base_table_z[level] - 2;
shop_mastersp->base_pos[2][0] += aSHM_ftr_revise_x(item_p[1]);
shop_mastersp->base_pos[2][1] += aSHM_ftr_revise_z(item_p[1]);

shop_mastersp->base_pos[3][0] = base_table_x[level] - 80;
shop_mastersp->base_pos[3][1] = base_table_z[level] - 2;
shop_mastersp->base_pos[3][0] += aSHM_ftr_revise_x(item_p[2]);
shop_mastersp->base_pos[3][1] += aSHM_ftr_revise_z(item_p[2]);

shop_mastersp->base_pos[4][0] = shop_mastersp->base_pos[0][0] - 80;
shop_mastersp->base_pos[4][1] = shop_mastersp->base_pos[0][1];

shop_mastersp->base_pos[5][0] = shop_mastersp->base_pos[4][0];
shop_mastersp->base_pos[5][1] = shop_mastersp->base_pos[4][1] + 80;

shop_mastersp->base_pos[6][0] = shop_mastersp->base_pos[5][0] + 40;
shop_mastersp->base_pos[6][1] = shop_mastersp->base_pos[5][1];

shop_mastersp->base_pos[7][0] = shop_mastersp->base_pos[0][0] + 80;
shop_mastersp->base_pos[7][1] = shop_mastersp->base_pos[0][1];

shop_mastersp->base_pos[8][0] = shop_mastersp->base_pos[7][0];
shop_mastersp->base_pos[8][1] = shop_mastersp->base_pos[7][1] + 80;

shop_mastersp->base_pos[9][0] = shop_mastersp->base_pos[8][0] - 40;
shop_mastersp->base_pos[9][1] = shop_mastersp->base_pos[8][1];

shop_mastersp->base_pos[10][0] = player->world.position.x;
shop_mastersp->base_pos[10][1] = player->world.position.z - 60.0f;
}

static void aSHM_set_avoid_pos(NPC_SHOP_MASTERSP_ACTOR* shop_mastersp) {
static u8 root1[1] = { 1 };
static u8 root2[3] = { 4, 5, 6 };
static u8 root3[3] = { 5, 4, 0 };
static u8 root4[2] = { 7, 2 };
static u8 root5[2] = { 8, 9 };
static u8 root6[3] = { 8, 7, 0 };
static u8 root7[2] = { 4, 3 };
static u8 root8[2] = { 5, 6 };
static u8 root10[3] = { 7, 8, 10 };
static u8* root_table[10] = { root1, root2, root3, root4, root5, root6, root7, root8, root3, root10 };

shop_mastersp->now_idx = root_table[shop_mastersp->root][shop_mastersp->root_idx];
}

static void aSHM_set_start_avoid_pos(NPC_SHOP_MASTERSP_ACTOR* shop_mastersp, s16 root) {
shop_mastersp->root = root;
shop_mastersp->root_idx = 0;
aSHM_set_avoid_pos(shop_mastersp);
}

static int aSHM_set_next_avoid_pos(NPC_SHOP_MASTERSP_ACTOR* shop_mastersp) {
static s16 root_max[] = { 1, 3, 3, 2, 2, 3, 2, 2, 3, 3 };

shop_mastersp->root_idx++;
if (shop_mastersp->root_idx < root_max[shop_mastersp->root]) {
aSHM_set_avoid_pos(shop_mastersp);
return FALSE;
}

return TRUE;
}

static int aSHM_set_request_act(NPC_SHOP_MASTERSP_ACTOR* shop_mastersp, u8 prio, u8 act_idx, u8 act_type, u16 act_obj, s16 pos_x, s16 pos_z) {
int ret = FALSE;

if (prio >= shop_mastersp->npc_class.request.act_priority) {
u16 args[aNPC_REQUEST_ARG_NUM];

bzero(args, sizeof(args));
args[0] = act_obj;
args[2] = pos_x;
args[3] = pos_z;
shop_mastersp->npc_class.request.act_priority = prio;
shop_mastersp->npc_class.request.act_idx = act_idx;
shop_mastersp->npc_class.request.act_type = act_type;
mem_copy((u8*)shop_mastersp->npc_class.request.act_args, (u8*)args, sizeof(args));
ret = TRUE;
}

return ret;
}

static void aSHM_actor_move(ACTOR* actorx, GAME* game) {
CLIP(npc_clip)->move_proc(actorx, game);
}
Loading

0 comments on commit eedc964

Please sign in to comment.