diff --git a/common.py b/common.py index 0e7adb98..b6b29a9d 100644 --- a/common.py +++ b/common.py @@ -375,6 +375,7 @@ BASE_REL_CFLAGS = CFLAGS + [ "-sdata 0", f"-sdata2 {REL_SDATA2_SIZE}", "-enum int", + "-requireprotos", #"-pool off", "-sym on" ] + REL_DEFINES diff --git a/include/bg_item.h b/include/bg_item.h index 37193505..7e2dd382 100644 --- a/include/bg_item.h +++ b/include/bg_item.h @@ -3,11 +3,386 @@ #include "types.h" #include "m_actor.h" +#include "m_field_info.h" +#include "bg_item_h.h" #ifdef __cplusplus extern "C" { #endif +#define bIT_PIT_NUM 13 +#define bIT_DROP_NUM 19 +#define bIT_FRUIT_DROP_NUM 6 +#define bIT_HOLE_NUM 1 +#define bIT_SHIN_NUM 1 +#define bIT_TEN_COIN_NUM 5 +#define bIT_FADE_NUM 3 + +enum { + bIT_TYPE_CAT_BG_ITEM, + bIT_TYPE_CAT_BG_ITEM2, + bIT_TYPE_CAT_FTR, + bIT_TYPE_CAT_ITEM1, + bIT_TYPE_CAT_CRACK, + bIT_TYPE_CAT_DUMMY, + + bIT_TYPE_CAT_NUM +}; + +enum { + bIT_DRAW_TYPE_STUMP1, + bIT_DRAW_TYPE_STUMP2, + bIT_DRAW_TYPE_STUMP3, + bIT_DRAW_TYPE_STUMP4, + bIT_DRAW_TYPE_FENCE, + bIT_DRAW_TYPE_NOTICE, + bIT_DRAW_TYPE_GRASS, + bIT_DRAW_TYPE_MAPBOARD, + bIT_DRAW_TYPE_MELODY, + bIT_DRAW_TYPE_FENCES, + bIT_DRAW_TYPE_HONYCOMB, + bIT_DRAW_TYPE_HOLE00_G, + bIT_DRAW_TYPE_HOLE00_S, + bIT_DRAW_TYPE_CRACK00_G, + bIT_DRAW_TYPE_CRACK00_S, + bIT_DRAW_TYPE_HOLE00_SHIN_G, + bIT_DRAW_TYPE_STONE_A, + bIT_DRAW_TYPE_STONE_B, + bIT_DRAW_TYPE_STONE_C, + bIT_DRAW_TYPE_STONE_D, + bIT_DRAW_TYPE_STONE_E, + bIT_DRAW_TYPE_TANE, + bIT_DRAW_TYPE_TREE0, + bIT_DRAW_TYPE_TREE1, + bIT_DRAW_TYPE_TREE2, + bIT_DRAW_TYPE_TREE3, + bIT_DRAW_TYPE_TREE4, + bIT_DRAW_TYPE_TREE4_AP, + bIT_DRAW_TYPE_TREE4_OR, + bIT_DRAW_TYPE_TREE4_PH, + bIT_DRAW_TYPE_TREE4_PR, + bIT_DRAW_TYPE_TREE4_NT, + bIT_DRAW_TYPE_TREE4_BG, + bIT_DRAW_TYPE_FLOWER_LEAF, + bIT_DRAW_TYPE_FLOWER00, + bIT_DRAW_TYPE_FLOWER01, + bIT_DRAW_TYPE_FLOWER02, + bIT_DRAW_TYPE_TREE0_DEAD, + bIT_DRAW_TYPE_PALM000, + bIT_DRAW_TYPE_PALM001, + bIT_DRAW_TYPE_PALM002, + bIT_DRAW_TYPE_PALM003, + bIT_DRAW_TYPE_PALM004, + bIT_DRAW_TYPE_PALM004_CC, + bIT_DRAW_TYPE_PALM_STUMP001, + bIT_DRAW_TYPE_PALM_STUMP002, + bIT_DRAW_TYPE_PALM_STUMP003, + bIT_DRAW_TYPE_PALM_STUMP004, + bIT_DRAW_TYPE_PALM000_DEAD, + bIT_DRAW_TYPE_CEDAR000, + bIT_DRAW_TYPE_CEDAR001, + bIT_DRAW_TYPE_CEDAR002, + bIT_DRAW_TYPE_CEDAR003, + bIT_DRAW_TYPE_CEDAR004, + bIT_DRAW_TYPE_CEDAR_STUMP001, + bIT_DRAW_TYPE_CEDAR_STUMP002, + bIT_DRAW_TYPE_CEDAR_STUMP003, + bIT_DRAW_TYPE_CEDAR_STUMP004, + bIT_DRAW_TYPE_CEDAR000_DEAD, + bIT_DRAW_TYPE_GOLD_TREE000, + bIT_DRAW_TYPE_GOLD_TREE001, + bIT_DRAW_TYPE_GOLD_TREE002, + bIT_DRAW_TYPE_GOLD_TREE003, + bIT_DRAW_TYPE_GOLD_TREE004, + bIT_DRAW_TYPE_GOLD_TREE_STUMP001, + bIT_DRAW_TYPE_GOLD_TREE_STUMP002, + bIT_DRAW_TYPE_GOLD_TREE_STUMP003, + bIT_DRAW_TYPE_GOLD_TREE_STUMP004, + bIT_DRAW_TYPE_GOLD_TREE000_DEAD, + bIT_DRAW_TYPE_APPLE, + bIT_DRAW_TYPE_ORANGE, + bIT_DRAW_TYPE_PEACH, + bIT_DRAW_TYPE_PEAR, + bIT_DRAW_TYPE_NUTS, + bIT_DRAW_TYPE_MATUTAKE, + bIT_DRAW_TYPE_KABU, + bIT_DRAW_TYPE_FISH, + bIT_DRAW_TYPE_BAG, + bIT_DRAW_TYPE_LEAF, + bIT_DRAW_TYPE_ROLL, + bIT_DRAW_TYPE_BOX, + bIT_DRAW_TYPE_PACK, + bIT_DRAW_TYPE_PRESENT, + bIT_DRAW_TYPE_SEED, + bIT_DRAW_TYPE_HANIWA, + bIT_DRAW_TYPE_OTHER, + bIT_DRAW_TYPE_86, + bIT_DRAW_TYPE_TOOL, + bIT_DRAW_TYPE_FOSSIL, + bIT_DRAW_TYPE_TRASH, + bIT_DRAW_TYPE_90, + bIT_DRAW_TYPE_OTOSI, + bIT_DRAW_TYPE_SHELL_A, + bIT_DRAW_TYPE_SHELL_B, + bIT_DRAW_TYPE_SHELL_C, + bIT_DRAW_TYPE_CANDY, + bIT_DRAW_TYPE_COCONUT, + bIT_DRAW_TYPE_97, + bIT_DRAW_TYPE_CLOTH, + bIT_DRAW_TYPE_CARPET, + bIT_DRAW_TYPE_WALL, + bIT_DRAW_TYPE_AXE, + bIT_DRAW_TYPE_NET, + bIT_DRAW_TYPE_ROD, + bIT_DRAW_TYPE_SCOOP, + bIT_DRAW_TYPE_GOLD_AXE, + bIT_DRAW_TYPE_GOLD_NET, + bIT_DRAW_TYPE_GOLD_ROD, + bIT_DRAW_TYPE_GOLD_SCOOP, + bIT_DRAW_TYPE_UMBRELLA, + bIT_DRAW_TYPE_PINWHEEL, + bIT_DRAW_TYPE_FAN, + bIT_DRAW_TYPE_PAPER, + bIT_DRAW_TYPE_SEEDBAG, + bIT_DRAW_TYPE_LUCKBAG, + bIT_DRAW_TYPE_GYMCARD, + bIT_DRAW_TYPE_MUSIC, + bIT_DRAW_TYPE_LOTTERY, + bIT_DRAW_TYPE_BONE, + bIT_DRAW_TYPE_DIARY, + bIT_DRAW_TYPE_FORK, + bIT_DRAW_TYPE_FISH2, + bIT_DRAW_TYPE_NONE, + + bIT_DRAW_TYPE_MAX +}; + +enum { + bIT_PAL_FLOWER_A, + bIT_PAL_FLOWER_B, + bIT_PAL_FLOWER_C, + bIT_PAL_GRASS, + bIT_PAL_HOLE_G, + bIT_PAL_HOLE_S, + bIT_PAL_TREE, + bIT_PAL_PALM_TREE, + bIT_PAL_GOLD_TREE, + + bIT_PAL_NUM +}; + +/* sizeof(bg_item_tbl_c) == 0x100 */ +typedef struct bg_item_tbl_s { + u8 info[UT_TOTAL_NUM]; +} bg_item_tbl_c; + +/* sizeof(bg_item_block_info_tbl_c) == 0x404 */ +typedef struct block_info_tbl_s { + /* 0x000 */ int _000; + /* 0x004 */ bg_item_tbl_c info_tbl[mFM_VISIBLE_BLOCK_NUM]; +} bg_item_block_info_tbl_c; + +/* sizeof(bg_item_type_data_c) == 0xC */ +typedef struct type_data_s { + /* 0x00 */ s8 _00; + /* 0x02 */ s16 type; + /* 0x04 */ f32* pos_x_tbl_p; + /* 0x08 */ f32* pos_z_tbl_p; +} bg_item_type_data_c; + +typedef struct draw_pos_s { + MtxF mtxf; + int _04; + s16 next_add_cnt; // this isn't right + u8 cull_flag; + s8 sub_idx; +} bg_item_draw_pos_c; + +typedef struct draw_list_s { + void* draw_proc; + u8 gfx_idx; + u8 mat_idx; +} bg_item_draw_list_c; + +typedef struct draw_part_s { + Gfx** display_list_table_p; + int draw_list_count; + bg_item_draw_list_c** draw_list_table_p; + int shadow_vtx_count; + Vtx* shadow_vtx_p; + f32 shadow_len; + u8* shadow_vtx_fix_table_p; + bg_item_draw_list_c* shadow_draw_list; +} bg_item_draw_part_c; + +typedef struct draw_part_table_s { + bg_item_draw_part_c* draw_part_p; + u16 flags; +} bg_item_draw_part_table_c; + +typedef struct draw_data_s { + bg_item_draw_pos_c draw_pos[UT_TOTAL_NUM + 1]; + u16* idx_p; + u16 val; +} bg_item_draw_data_c; + +typedef struct draw_table_s { + bg_item_draw_data_c draw_data; + s16 draw_flag; + u8 bx; + u8 bz; +} bg_item_draw_table_c; + +typedef struct common_info_s { + bg_item_draw_part_table_c* draw_part_table_p; + bg_item_type_data_c** type_data_table_p; + f32* pos_table_p; + u16* pal_p[bIT_PAL_NUM]; + u16 _30; +} bg_item_common_info_c; + +typedef void (*bIT_ACTOR_DROP_MOVE_PROC)(bg_item_drop_c*); +typedef void (*bIT_ACTOR_DROP_DRAW_PROC)(GAME*, bg_item_common_info_c*, bg_item_drop_c*); +typedef void (*bIT_ACTOR_DROP_DESTRUCT_PROC)(bg_item_drop_c*); + +struct drop_s { + bIT_ACTOR_DROP_MOVE_PROC move_proc; + bIT_ACTOR_DROP_DRAW_PROC draw_proc; + bIT_ACTOR_DROP_DESTRUCT_PROC dt_proc; + s16 mode; + mActor_name_t fg_item; + mActor_name_t display_fg_item; + xyz_t position; + xyz_t target_position; + xyz_t scale; + xyz_t offset; + s_xyz angle; + s16 _4A; + f32 _4C; + s16 drop_speed; + f32 _54; + s16 _58; + s16 _5A; + s16 _5C; + f32 velocity_xz; + f32 velocity_y; + f32 acceleration_y; + u16 flags; + s16 _6E; + s16 _70; + u8 _72; + mActor_name_t target_pos_fg_item; + u16 _76; + u16 _78; + f32 _7C; + s16 wait_counter; + f32 total_distance_y; + u16 _88; + s16 _8A; + ACTOR* actorx_p; + s16 _90; + s16 layer; + xyz_t last_position; + f32 last_velocity_xz; + f32 last_velocity_y; +}; + +typedef struct drop_table_s { + bg_item_drop_c* drop_p; + s16 count; +} bg_item_drop_table_c; + +typedef struct pit_s { + xyz_t position; + f32 scale; + s16 mode; + mActor_name_t hole_fg_item; + s16 hole_timer; + s16 wait_counter; + s16 wait_type; + mActor_name_t fg_item_in_pit; +} bg_item_pit_c; + +struct hole_s { + xyz_t position; + f32 scale; + s_xyz angle; + s16 mode; + mActor_name_t hole_fg_item; + mActor_name_t fg_item; + u16 counter; + u16 max_counter; + u16 wait_counter; + s16 wait_type; +}; + +typedef struct shin_s { + xyz_t position; + mActor_name_t fg_item; + u16 mode; +} bg_item_shin_c; + +typedef struct ten_coin_s { + u8 _00[0x30]; + xyz_t position; + f32 scale; + s16 angle; + mActor_name_t fg_item; + u16 _44; + s16 _46; + s16 _48; + s16 _4A; + s16 _4C; + s16 _4E; + s16 _50; + s16 left_frames; + s16 total_frames; + s16 hit_count; +} bg_item_ten_coin_c; + +typedef struct fade_s { + xyz_t position; + mActor_name_t fg_item; + u8 alpha; + u8 mode; + u8 _10; +} bg_item_fade_c; + +typedef int (*bIT_TALK_DISPLAY_LIMIT_CHECK_PROC)(int); + +struct bg_common_s { + bg_item_draw_table_c draw_table[mFM_VISIBLE_BLOCK_NUM]; + bg_item_block_info_tbl_c block_info_table; + mFI_item_table_c item_table; + bg_item_common_info_c common_info; + bg_item_drop_table_c drop_info; + bg_item_drop_table_c fruit_drop_info; + bg_item_pit_c pit[bIT_PIT_NUM]; + bg_item_drop_c drop[bIT_DROP_NUM]; + bg_item_drop_c fruit_drop[bIT_FRUIT_DROP_NUM]; + bg_item_hole_c hole[bIT_HOLE_NUM]; + bg_item_shin_c shin[bIT_SHIN_NUM]; + bg_item_ten_coin_c ten_coin[bIT_TEN_COIN_NUM]; + bg_item_fade_c fade[bIT_FADE_NUM]; + bIT_TALK_DISPLAY_LIMIT_CHECK_PROC talk_display_limit_check_proc; + ACTOR* bg_item_actorx_p; + u16 flags; + int _139E0[mFM_VISIBLE_BLOCK_NUM]; + int _139F4[mFM_VISIBLE_BLOCK_NUM]; +}; + +typedef struct blk_idx_info_s { + u16 idx[bIT_DRAW_TYPE_MAX]; +} bg_item_idx_info_c; + +typedef struct bg_item_actor_s BG_ITEM_ACTOR; + +struct bg_item_actor_s { + ACTOR actor_class; + bg_item_common_c common; + bg_item_idx_info_c item_idx_info[mFM_VISIBLE_BLOCK_NUM]; +}; + extern ACTOR_PROFILE BgItem_Profile; #ifdef __cplusplus @@ -15,4 +390,3 @@ extern ACTOR_PROFILE BgItem_Profile; #endif #endif - diff --git a/include/bg_item_h.h b/include/bg_item_h.h index 2d315eab..f9f6ee0b 100644 --- a/include/bg_item_h.h +++ b/include/bg_item_h.h @@ -10,27 +10,60 @@ extern "C" { #endif typedef struct background_item_shadow_s { - u32 vtx_num; - u8* vtx_fix_flags; - f32 size; - Vtx* vtx; - Gfx* gfx; + u32 vtx_num; + u8* vtx_fix_flags; + f32 size; + Vtx* vtx; + Gfx* gfx; } bIT_ShadowData_c; +typedef int (*bIT_DRAW_BF_PROC)(Gfx**, rgba_t*); +typedef int (*bIT_DRAW_AF_PROC)(Gfx**, rgba_t*); + +typedef struct bg_common_s bg_item_common_c; +typedef struct drop_s bg_item_drop_c; +typedef struct hole_s bg_item_hole_c; + typedef void (*bIT_SHADOW_DRAW_PROC)(GAME*, bIT_ShadowData_c*, int); - -typedef int (*bIT_FRUIT_SET_PROC)(mActor_name_t item, int ut_x, int ut_z, s16 p0, s16 p1); +typedef void (*bIT_SINGLE_DRAW_PROC)(GAME* game, mActor_name_t fg_no, xyz_t* pos, f32 scale_f, bIT_DRAW_BF_PROC draw_bf, + bIT_DRAW_AF_PROC draw_af, rgba_t* col); +typedef int (*bIT_TREE_CUTCOUNT_CHECK_PROC)(GAME* game, int ut_x, int ut_z); +typedef void (*bIT_DIG_HOLE_EFFECT_ENTRY_PROC)(mActor_name_t fg_item, xyz_t* pos, u16 frames, u16 wait_frames); +typedef void (*bIT_BURY_HOLE_EFFECT_ENTRY_PROC)(mActor_name_t fg_item, xyz_t* pos, u16 frames); +typedef int (*bIT_PIT_FALL_PROC)(mActor_name_t pit_fg_item, int ut_x, int ut_z, mActor_name_t fg_item_in_pit); +typedef int (*bIT_PIT_FALL_STOP_PROC)(mActor_name_t pit_fg_item, int ut_x, int ut_z, mActor_name_t fg_item_in_pit); +typedef int (*bIT_PIT_EXIT_PROC)(mActor_name_t pit_fg_item, int ut_x, int ut_z, mActor_name_t fg_item_in_pit); +typedef int (*bIT_RAND_POS_GET_PROC)(xyz_t* pos, const xyz_t* check_pos); +typedef int (*bIT_TEN_COIN_ENTRY_EX_PROC)(xyz_t* pos, s16 angle); +typedef int (*bIT_FRUIT_SET_PROC)(mActor_name_t fg_item, int ut_x, int ut_z, s16 count, int type); +typedef void (*bIT_FLY_ENTRY_PROC)(mActor_name_t fg_item, xyz_t* pos, s16 angle_y); typedef void (*bIT_ITEM_TREE_FRUIT_DROP_PROC)(mActor_name_t item, int ut_x, int ut_z, xyz_t* pos); - +typedef int (*bIT_PLAYER_DROP_ENTRY_PROC)(GAME* game, mActor_name_t fg_item, int ut_x, int ut_z, s16 layer); +typedef int (*bIT_DROP_ENTRY_V1_PROC)(mActor_name_t fg_item, xyz_t* pos, xyz_t* target_pos); +typedef int (*bIT_FADE_ENTRY_PROC)(mActor_name_t fg_name, xyz_t* pos); typedef struct background_item_clip_s { - void* _00; - bIT_SHADOW_DRAW_PROC draw_shadow_proc; - void* _08[(0x30 - 0x08) / sizeof(void*)]; - bIT_FRUIT_SET_PROC fruit_set_proc; - void* _34; - bIT_ITEM_TREE_FRUIT_DROP_PROC item_tree_fruit_drop_proc; - void* _3C[(0x54 - 0x3C) / sizeof(void*)]; + bg_item_common_c* bg_item_common_p; + bIT_SHADOW_DRAW_PROC draw_shadow_proc; + bIT_SINGLE_DRAW_PROC single_draw_proc; + bIT_TREE_CUTCOUNT_CHECK_PROC tree_cutcount_check_proc; + bIT_DIG_HOLE_EFFECT_ENTRY_PROC dig_hole_effect_entry_proc; + bIT_BURY_HOLE_EFFECT_ENTRY_PROC bury_hole_effect_entry_proc; + bIT_PIT_FALL_PROC pit_fall_proc; + bIT_PIT_FALL_STOP_PROC pit_fall_stop_proc; + bIT_PIT_EXIT_PROC pit_exit_proc; + void* _24; + bIT_RAND_POS_GET_PROC rand_pos_get_proc; + bIT_TEN_COIN_ENTRY_EX_PROC ten_coin_entry_ex_proc; + bIT_FRUIT_SET_PROC fruit_set_proc; + bIT_FLY_ENTRY_PROC fly_entry_proc; + bIT_ITEM_TREE_FRUIT_DROP_PROC item_tree_fruit_drop_proc; + bIT_PLAYER_DROP_ENTRY_PROC player_drop_entry_proc; + bIT_DROP_ENTRY_V1_PROC drop_entry_v1_proc; + void* _44; + void* _48; + ACTOR* bg_item_actorx; + bIT_FADE_ENTRY_PROC fade_entry_proc; } bIT_Clip_c; #ifdef __cplusplus diff --git a/include/libc64/__osMalloc.h b/include/libc64/__osMalloc.h index 68a3c720..895b498d 100644 --- a/include/libc64/__osMalloc.h +++ b/include/libc64/__osMalloc.h @@ -16,7 +16,7 @@ typedef struct Arena { /* 0x20 */ u8 unk_20; /* 0x21 */ u8 isInit; /* 0x22 */ u8 flag; - /* 0x24 */ u8 pad[0x2C-0x24]; + /* 0x24 */ u8 pad[0x2C - 0x24]; } Arena; // size = 0x2C typedef struct ArenaNode { @@ -30,8 +30,8 @@ typedef struct ArenaNode { /* 0x18 */ OSId threadId; /* 0x1C */ Arena* arena; /* 0x20 */ OSTime time; - /* 0x28 */ u8 unk_28[0x30-0x28]; // probably padding -} ArenaNode; // size = 0x30 + /* 0x28 */ u8 unk_28[0x30 - 0x28]; // probably padding +} ArenaNode; // size = 0x30 void setDebugInfo(ArenaNode*, const char*, s32, Arena*); void arena_lock_init(Arena*); @@ -61,8 +61,8 @@ u32 __osGetFreeSize(Arena*); u32 __osGetMemBlockSize(Arena*, void*); void __osDisplayArena(Arena*); int __osCheckArena(Arena*); +extern int __osMallocIsInitalized(Arena*); extern int __osMalloc_FreeBlockTest_Enable; - #endif diff --git a/include/m_actor.h b/include/m_actor.h index ce02a3d3..060560ce 100644 --- a/include/m_actor.h +++ b/include/m_actor.h @@ -16,7 +16,7 @@ extern "C" { #endif typedef void (*mActor_proc)(ACTOR*, GAME*); -#define NONE_ACTOR_PROC ((mActor_proc)&none_proc1) +#define NONE_ACTOR_PROC ((mActor_proc) & none_proc1) #define mAc_MAX_ACTORS 200 @@ -42,7 +42,7 @@ typedef enum bank_id { ACTOR_OBJ_BANK_1, ACTOR_OBJ_BANK_2, ACTOR_OBJ_BANK_KEEP, - ACTOR_OBJ_BANK_4, + ACTOR_OBJ_BANK_BGITEM, ACTOR_OBJ_BANK_ROOM_SUNSHINE, ACTOR_OBJ_BANK_6, ACTOR_OBJ_BANK_AIRPLANE, diff --git a/include/m_bgm.h b/include/m_bgm.h index 32c22a43..bad34b58 100644 --- a/include/m_bgm.h +++ b/include/m_bgm.h @@ -22,7 +22,7 @@ extern void mBGMPsComp_make_ps_quietField(u16 stop_type); extern void mBGMPsComp_make_ps_fc_quietField(u16 stop_type); extern void mBGMPsComp_make_ps_fieldSuddenEv(u8 bgm_num, u16 stop_type, u8 priority); extern void mBGMPsComp_delete_ps_fanfare(u8 bgm_num, u16 stop_type); -extern void mBGMPsComp_delete_ps_wipe(); +extern void mBGMPsComp_delete_ps_quiet(); extern void mBGMPsComp_delete_ps_demo(u8 bgm_num, u16 stop_type); extern void mBGMPsComp_delete_ps_happening(u8 bgm_num, u16 stop_type); extern void mBGMPsComp_delete_ps_room(u8 bgm_num, u16 stop_type); diff --git a/include/m_card.h b/include/m_card.h index b83a7d11..f961dea2 100644 --- a/include/m_card.h +++ b/include/m_card.h @@ -53,6 +53,7 @@ extern void mCD_toNextLand(); extern int mCD_EraseBrokenLand_bg(void*); extern int mCD_card_format_bg(u8); +extern void mCD_ReCheckLoadLand(GAME_PLAY* play); #ifdef __cplusplus } diff --git a/include/m_collision_bg.h b/include/m_collision_bg.h index 29eafbe5..c18518f8 100644 --- a/include/m_collision_bg.h +++ b/include/m_collision_bg.h @@ -271,6 +271,12 @@ extern int mCoBG_RegistMoveBg(mCoBG_bg_regist_c* bg_regist, xyz_t* wpos, xyz_t* mCoBG_bg_size_c* bg_size, f32* scale_percent, mCoBG_bg_contact_c* bg_contact, xyz_t* ofs, int type, u32 attribute, f32 check_dist); extern void mCoBG_CrossOffMoveBg(int move_bg_idx); +extern int mCoBG_CheckPlace(xyz_t wpos); +extern int mCoBG_CheckSandHole_ClData(mCoBG_Collision_u* col); +extern int mCoBG_GetHoleNumber_ClData(mCoBG_Collision_u* col); +extern void mCoBG_GetBgNorm_FromWpos(xyz_t* norm, xyz_t wpos); +extern int mCoBG_GetWaterFlow(xyz_t* water_flow, u32 attr); +extern void mCoBG_SetAttribute(xyz_t pos, u32 attr); extern void mCoBG_InitMoveBgData(); extern void mCoBG_InitBlockBgCheckMode(); diff --git a/include/m_design_ovl.h b/include/m_design_ovl.h new file mode 100644 index 00000000..13e0998a --- /dev/null +++ b/include/m_design_ovl.h @@ -0,0 +1,17 @@ +#ifndef M_DESIGN_OVL_H +#define M_DESIGN_OVL_H + +#include "types.h" +#include "m_mask_cat.h" + +#ifdef __cplusplus +extern "C" { +#endif + +extern void mDE_maskcat_init(MaskCat_c* mask_cat); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/m_event.h b/include/m_event.h index 86900144..09cca249 100644 --- a/include/m_event.h +++ b/include/m_event.h @@ -15,7 +15,7 @@ extern "C" { #define mEv_TODAY_EVENT_NUM 16 #define mEv_SCHEDULE_LAST_WEEKDAY_OF_MONTH 6 /* day of last weekday of the month */ -#define mEv_SCHEDULE_EVERY_WEEK 7 /* scheduled for the desired day this week (e.g. this saturday) */ +#define mEv_SCHEDULE_EVERY_WEEK 7 /* scheduled for the desired day this week (e.g. this saturday) */ /* Month flags */ #define mEv_SCHEDULE_HARVEST_MOON_DATE 0x40 /* Use this year's lunisolar harvest moon date */ @@ -26,12 +26,14 @@ extern "C" { #define mEv_SCHEDULE_LUNAR(m) (mEv_SCHEDULE_HARVEST_MOON_DATE | ((m) & 0xF)) /* Day flags */ -#define mEv_SCHEDULE_WEEKLY 0x80 /* Event happens on a given weekday and week of the month */ +#define mEv_SCHEDULE_WEEKLY 0x80 /* Event happens on a given weekday and week of the month */ #define mEv_SCHEDULE_TOWN_DAY 0x40 /* Use save data 'town day' day */ -#define mEv_SCHEDULE_DAY_AFTER 0x40 /* When used in conjunction with the 'weekly' flag, it schedules on the day after the Nth weekday */ +#define mEv_SCHEDULE_DAY_AFTER \ + 0x40 /* When used in conjunction with the 'weekly' flag, it schedules on the day after the Nth weekday */ #define mEv_SCHEDULE_LAST_DAY_OF_MONTH 0x20 -#define mEv_SCHEDULE_MAKE_WEEKLY_DATA(week, weekday) (mEv_SCHEDULE_WEEKLY | ((((week) & 0b111) << 3) | ((weekday) & 0b111))) +#define mEv_SCHEDULE_MAKE_WEEKLY_DATA(week, weekday) \ + (mEv_SCHEDULE_WEEKLY | ((((week) & 0b111) << 3) | ((weekday) & 0b111))) #define mEv_SCHEDULE_1ST_WEEKDAY(weekday) mEv_SCHEDULE_MAKE_WEEKLY_DATA(1, weekday) #define mEv_SCHEDULE_2ND_WEEKDAY(weekday) mEv_SCHEDULE_MAKE_WEEKLY_DATA(2, weekday) #define mEv_SCHEDULE_3RD_WEEKDAY(weekday) mEv_SCHEDULE_MAKE_WEEKLY_DATA(3, weekday) @@ -41,7 +43,7 @@ extern "C" { #define mEv_SCHEDULE_EVERY_WEEKDAY(weekday) mEv_SCHEDULE_MAKE_WEEKLY_DATA(mEv_SCHEDULE_EVERY_WEEK, weekday) /* Hour flags */ -#define mEv_SCHEDULE_TODAY 0x80 /* event will be active on the day loaded */ +#define mEv_SCHEDULE_TODAY 0x80 /* event will be active on the day loaded */ #define mEv_SCHEDULE_MULTIDAY 0x40 /* event scheduled over more than a single day */ #define mEv_SCHEDULE_USE_SAVE_SLOT_VALUE 0x20 @@ -51,39 +53,39 @@ extern "C" { #define mEv_TO_MONTH(month_day) ((lbRTC_month_t)((month_day) >> 8)) typedef union event_monthday_s { - struct { - u8 month; - u8 day; - }; - u16 raw; + struct { + u8 month; + u8 day; + }; + u16 raw; } mEv_MonthDay_u; typedef struct event_today_s { - int type; - u32 active_hours; /* bitfield (24 bits) */ - mEv_MonthDay_u begin_date; - mEv_MonthDay_u end_date; - s16 status; - u16 pad; + int type; + u32 active_hours; /* bitfield (24 bits) */ + mEv_MonthDay_u begin_date; + mEv_MonthDay_u end_date; + s16 status; + u16 pad; } mEv_event_today_c; typedef struct event_date_s { - u8 month; - u8 day; - u8 _2; - u8 hour; + u8 month; + u8 day; + u8 _2; + u8 hour; } mEv_schedule_date_c; typedef union { - mEv_schedule_date_c d; - u16 md, _h; - u32 raw; + mEv_schedule_date_c d; + u16 md, _h; + u32 raw; } mEv_schedule_date_u; typedef struct event_schedule_s { - mEv_schedule_date_u date[2]; /* 0 = begin, 1 = end */ - s16 _8; - s16 type; /* event type */ + mEv_schedule_date_u date[2]; /* 0 = begin, 1 = end */ + s16 _8; + s16 type; /* event type */ } mEv_schedule_c; #define mEv_EVENT_HOUR_START_EVENT (1 << 28) @@ -93,7 +95,7 @@ typedef struct event_schedule_s { /** * Event type definition * xxxyyyyy yyyyyyyy yyyyyyyy yyyyyyyy - * + * * x: event type (e.g. special event, 'first job' (chores) event, holidays, ...) (0-7) * y: sub-type (specific event) **/ @@ -111,460 +113,460 @@ typedef struct event_schedule_s { #define mEv_SET(type, subtype) (mEv_SET_TYPE(type) | mEv_SET_TYPE(subtype)) enum event_type { - mEv_SPNPC_EVENT, /* special NPC events */ - mEv_SAVED_EVENT, /* events saved to data */ - mEv_TYPE2_EVENT, /* unused? */ - mEv_TYPE3_EVENT, /* unused? */ - mEv_TYPE4_EVENT, /* unused? */ - mEv_DAILY_EVENT, /* checked daily always? aSL_ReportShopOpen2Event has event 3 */ - mEv_SPECL_EVENT, /* ??? secondary special npc event data? */ + mEv_SPNPC_EVENT, /* special NPC events */ + mEv_SAVED_EVENT, /* events saved to data */ + mEv_TYPE2_EVENT, /* unused? */ + mEv_TYPE3_EVENT, /* unused? */ + mEv_TYPE4_EVENT, /* unused? */ + mEv_DAILY_EVENT, /* checked daily always? aSL_ReportShopOpen2Event has event 3 */ + mEv_SPECL_EVENT, /* ??? secondary special npc event data? */ - mEv_EVENT_TYPE_NUM + mEv_EVENT_TYPE_NUM }; enum events { - mEv_SPNPC_SHOP = (int)mEv_SET(mEv_SPNPC_EVENT, 0), - mEv_SPNPC_DESIGNER, - mEv_SPNPC_BROKER, - mEv_SPNPC_ARTIST, - mEv_SPNPC_ARABIAN, - mEv_SPNPC_GYPSY, - mEv_SPNPC_END, + mEv_SPNPC_SHOP = (int)mEv_SET(mEv_SPNPC_EVENT, 0), + mEv_SPNPC_DESIGNER, + mEv_SPNPC_BROKER, + mEv_SPNPC_ARTIST, + mEv_SPNPC_ARABIAN, + mEv_SPNPC_GYPSY, + mEv_SPNPC_END, - mEv_SAVED_RENEWSHOP = (int)mEv_SET(mEv_SAVED_EVENT, 0), /* renew shop */ - mEv_SAVED_UNK1, /* unused */ - - /* intro through chores */ - mEv_SAVED_FIRSTJOB_PLR0, - mEv_SAVED_FIRSTJOB_PLR1, - mEv_SAVED_FIRSTJOB_PLR2, - mEv_SAVED_FIRSTJOB_PLR3, + mEv_SAVED_RENEWSHOP = (int)mEv_SET(mEv_SAVED_EVENT, 0), /* renew shop */ + mEv_SAVED_UNK1, /* unused */ - /* selecting house */ - mEv_SAVED_FIRSTINTRO_PLR0, - mEv_SAVED_FIRSTINTRO_PLR1, - mEv_SAVED_FIRSTINTRO_PLR2, - mEv_SAVED_FIRSTINTRO_PLR3, + /* intro through chores */ + mEv_SAVED_FIRSTJOB_PLR0, + mEv_SAVED_FIRSTJOB_PLR1, + mEv_SAVED_FIRSTJOB_PLR2, + mEv_SAVED_FIRSTJOB_PLR3, - /* wait for next day to talk about HRA */ - mEv_SAVED_HRAWAIT_PLR0, - mEv_SAVED_HRAWAIT_PLR1, - mEv_SAVED_HRAWAIT_PLR2, - mEv_SAVED_HRAWAIT_PLR3, + /* selecting house */ + mEv_SAVED_FIRSTINTRO_PLR0, + mEv_SAVED_FIRSTINTRO_PLR1, + mEv_SAVED_FIRSTINTRO_PLR2, + mEv_SAVED_FIRSTINTRO_PLR3, - /* Nook will talk about HRA when entering the shop */ - mEv_SAVED_HRATALK_PLR0, - mEv_SAVED_HRATALK_PLR1, - mEv_SAVED_HRATALK_PLR2, - mEv_SAVED_HRATALK_PLR3, + /* wait for next day to talk about HRA */ + mEv_SAVED_HRAWAIT_PLR0, + mEv_SAVED_HRAWAIT_PLR1, + mEv_SAVED_HRAWAIT_PLR2, + mEv_SAVED_HRAWAIT_PLR3, - /* Do a 'favor' for a villager during chores */ - mEv_SAVED_FJOPENQUEST_PLR0, - mEv_SAVED_FJOPENQUEST_PLR1, - mEv_SAVED_FJOPENQUEST_PLR2, - mEv_SAVED_FJOPENQUEST_PLR3, + /* Nook will talk about HRA when entering the shop */ + mEv_SAVED_HRATALK_PLR0, + mEv_SAVED_HRATALK_PLR1, + mEv_SAVED_HRATALK_PLR2, + mEv_SAVED_HRATALK_PLR3, - /* Player going to another town, set at train station */ - mEv_SAVED_GATEWAY_PLR0, - mEv_SAVED_GATEWAY_PLR1, - mEv_SAVED_GATEWAY_PLR2, - mEv_SAVED_GATEWAY_PLR3, - mEv_SAVED_GATEWAY_FRGN, /* Foreigner */ + /* Do a 'favor' for a villager during chores */ + mEv_SAVED_FJOPENQUEST_PLR0, + mEv_SAVED_FJOPENQUEST_PLR1, + mEv_SAVED_FJOPENQUEST_PLR2, + mEv_SAVED_FJOPENQUEST_PLR3, - mEv_DAILY_0 = (int)mEv_SET(mEv_DAILY_EVENT, 0), /* unused */ - mEv_DAILY_1, /* unused */ - mEv_DAILY_2, /* unused */ - mEv_DAILY_OPEN_SHOP, /* shop opened */ + /* Player going to another town, set at train station */ + mEv_SAVED_GATEWAY_PLR0, + mEv_SAVED_GATEWAY_PLR1, + mEv_SAVED_GATEWAY_PLR2, + mEv_SAVED_GATEWAY_PLR3, + mEv_SAVED_GATEWAY_FRGN, /* Foreigner */ - mEv_SPECL_DESIGNER_COMPLETE = (int)mEv_SET(mEv_SPECL_EVENT, 0) + mEv_DAILY_0 = (int)mEv_SET(mEv_DAILY_EVENT, 0), /* unused */ + mEv_DAILY_1, /* unused */ + mEv_DAILY_2, /* unused */ + mEv_DAILY_OPEN_SHOP, /* shop opened */ + + mEv_SPECL_DESIGNER_COMPLETE = (int)mEv_SET(mEv_SPECL_EVENT, 0) }; enum week_type { - mEv_WEEKTYPE_NONE, - mEv_WEEKTYPE_1ST, - mEv_WEEKTYPE_2ND, - mEv_WEEKTYPE_3RD, - mEv_WEEKTYPE_4TH, - mEv_WEEKTYPE_5TH, - mEv_WEEKTYPE_LAST, - mEv_WEEKTYPE_SPECIAL + mEv_WEEKTYPE_NONE, + mEv_WEEKTYPE_1ST, + mEv_WEEKTYPE_2ND, + mEv_WEEKTYPE_3RD, + mEv_WEEKTYPE_4TH, + mEv_WEEKTYPE_5TH, + mEv_WEEKTYPE_LAST, + mEv_WEEKTYPE_SPECIAL }; enum event_table { - mEv_EVENT_RUMOR_NEW_YEARS_DAY, - mEv_EVENT_NEW_YEARS_DAY, - mEv_EVENT_RUMOR_KAMAKURA, - mEv_EVENT_KAMAKURA, - mEv_EVENT_SONCHO_VACATION_JANUARY, - mEv_EVENT_SONCHO_VACATION_FEBRUARY, - mEv_EVENT_RUMOR_GROUNDHOG_DAY, - mEv_EVENT_GROUNDHOG_DAY, - mEv_EVENT_RUMOR_VALENTINES_DAY, - mEv_EVENT_VALENTINES_DAY, - mEv_EVENT_RUMOR_SPRING_SPORTS_FAIR, - mEv_EVENT_SPRING_EQUINOX, - mEv_EVENT_SPORTS_FAIR_BALL_TOSS, - mEv_EVENT_SPORTS_FAIR_AEROBICS, - mEv_EVENT_SPORTS_FAIR_TUG_OF_WAR, - mEv_EVENT_SPORTS_FAIR_FOOT_RACE, - mEv_EVENT_SPORTS_FAIR, - mEv_EVENT_APRILFOOLS_DAY, - mEv_EVENT_RUMOR_APRILFOOLS_DAY, - mEv_EVENT_RUMOR_CHERRY_BLOSSOM_FESTIVAL, - mEv_EVENT_CHERRY_BLOSSOM_FESTIVAL, - mEv_EVENT_NATURE_DAY, - mEv_EVENT_SPRING_CLEANING, - mEv_EVENT_MOTHERS_DAY, - mEv_EVENT_SUMMER_CAMPER, - mEv_EVENT_GRADUATION_DAY, - mEv_EVENT_FATHERS_DAY, - mEv_EVENT_RUMOR_FISHING_TOURNEY_1, - mEv_EVENT_TALK_FISHING_TOURNEY_1, // for dialog? - mEv_EVENT_FISHING_TOURNEY_1, - mEv_EVENT_TOWN_DAY, - mEv_EVENT_RUMOR_FIREWORKS_SHOW, - mEv_EVENT_FIREWORKS_SHOW, - mEv_EVENT_RUMOR_MORNING_AEROBICS, - mEv_EVENT_TALK_MORNING_AEROBICS, - mEv_EVENT_MORNING_AEROBICS, - mEv_EVENT_RUMOR_METEOR_SHOWER, - mEv_EVENT_METEOR_SHOWER, - mEv_EVENT_FOUNDERS_DAY, - mEv_EVENT_LABOR_DAY, - mEv_EVENT_RUMOR_FALL_SPORTS_FAIR, - mEv_EVENT_AUTUMN_EQUINOX, - mEv_EVENT_RUMOR_HARVEST_MOON_DAY, - mEv_EVENT_HARVEST_MOON_FESTIVAL, - mEv_EVENT_EXPLORERS_DAY, - mEv_EVENT_RUMOR_MUSHROOM_SEASON, - mEv_EVENT_TALK_MUSHROOM_SEASON, - mEv_EVENT_MUSHROOM_SEASON, - mEv_EVENT_RUMOR_HALLOWEEN, - mEv_EVENT_HALLOWEEN, - mEv_EVENT_MAYORS_DAY, - mEv_EVENT_OFFICERS_DAY, - mEv_EVENT_RUMOR_FISHING_TOURNEY_2, - mEv_EVENT_TALK_FISHING_TOURNEY_2, - mEv_EVENT_FISHING_TOURNEY_2, - mEv_EVENT_RUMOR_HARVEST_FESTIVAL, - mEv_EVENT_HARVEST_FESTIVAL, - mEv_EVENT_SALE_DAY, - mEv_EVENT_SNOW_DAY, - mEv_EVENT_TOY_DAY_SONCHO, - mEv_EVENT_RUMOR_TOY_DAY, - mEv_EVENT_TOY_DAY_JINGLE, - mEv_EVENT_SNOWMAN_SEASON, - mEv_EVENT_RUMOR_NEW_YEARS_EVE_COUNTDOWN, - mEv_EVENT_NEW_YEARS_EVE_COUNTDOWN, - mEv_EVENT_CHERRY_BLOSSOM_PETALS, - mEv_EVENT_TALK_TOY_DAY, - - mEv_EVENT_PLAYER_BIRTHDAY, - - mEv_EVENT_DOZAEMON, - mEv_EVENT_KABU_PEDDLER, - mEv_EVENT_LOTTERY, - mEv_EVENT_KK_SLIDER, - - mEv_EVENT_HANDBILL_BROKER, - mEv_EVENT_HANDBILL_SHOP_SALE, - - mEv_EVENT_ARTIST, - mEv_EVENT_BROKER_SALE, - mEv_EVENT_DESIGNER, - mEv_EVENT_GYPSY, - mEv_EVENT_SHOP_SALE, - mEv_EVENT_CARPET_PEDDLER, + mEv_EVENT_RUMOR_NEW_YEARS_DAY, + mEv_EVENT_NEW_YEARS_DAY, + mEv_EVENT_RUMOR_KAMAKURA, + mEv_EVENT_KAMAKURA, + mEv_EVENT_SONCHO_VACATION_JANUARY, + mEv_EVENT_SONCHO_VACATION_FEBRUARY, + mEv_EVENT_RUMOR_GROUNDHOG_DAY, + mEv_EVENT_GROUNDHOG_DAY, + mEv_EVENT_RUMOR_VALENTINES_DAY, + mEv_EVENT_VALENTINES_DAY, + mEv_EVENT_RUMOR_SPRING_SPORTS_FAIR, + mEv_EVENT_SPRING_EQUINOX, + mEv_EVENT_SPORTS_FAIR_BALL_TOSS, + mEv_EVENT_SPORTS_FAIR_AEROBICS, + mEv_EVENT_SPORTS_FAIR_TUG_OF_WAR, + mEv_EVENT_SPORTS_FAIR_FOOT_RACE, + mEv_EVENT_SPORTS_FAIR, + mEv_EVENT_APRILFOOLS_DAY, + mEv_EVENT_RUMOR_APRILFOOLS_DAY, + mEv_EVENT_RUMOR_CHERRY_BLOSSOM_FESTIVAL, + mEv_EVENT_CHERRY_BLOSSOM_FESTIVAL, + mEv_EVENT_NATURE_DAY, + mEv_EVENT_SPRING_CLEANING, + mEv_EVENT_MOTHERS_DAY, + mEv_EVENT_SUMMER_CAMPER, + mEv_EVENT_GRADUATION_DAY, + mEv_EVENT_FATHERS_DAY, + mEv_EVENT_RUMOR_FISHING_TOURNEY_1, + mEv_EVENT_TALK_FISHING_TOURNEY_1, // for dialog? + mEv_EVENT_FISHING_TOURNEY_1, + mEv_EVENT_TOWN_DAY, + mEv_EVENT_RUMOR_FIREWORKS_SHOW, + mEv_EVENT_FIREWORKS_SHOW, + mEv_EVENT_RUMOR_MORNING_AEROBICS, + mEv_EVENT_TALK_MORNING_AEROBICS, + mEv_EVENT_MORNING_AEROBICS, + mEv_EVENT_RUMOR_METEOR_SHOWER, + mEv_EVENT_METEOR_SHOWER, + mEv_EVENT_FOUNDERS_DAY, + mEv_EVENT_LABOR_DAY, + mEv_EVENT_RUMOR_FALL_SPORTS_FAIR, + mEv_EVENT_AUTUMN_EQUINOX, + mEv_EVENT_RUMOR_HARVEST_MOON_DAY, + mEv_EVENT_HARVEST_MOON_FESTIVAL, + mEv_EVENT_EXPLORERS_DAY, + mEv_EVENT_RUMOR_MUSHROOM_SEASON, + mEv_EVENT_TALK_MUSHROOM_SEASON, + mEv_EVENT_MUSHROOM_SEASON, + mEv_EVENT_RUMOR_HALLOWEEN, + mEv_EVENT_HALLOWEEN, + mEv_EVENT_MAYORS_DAY, + mEv_EVENT_OFFICERS_DAY, + mEv_EVENT_RUMOR_FISHING_TOURNEY_2, + mEv_EVENT_TALK_FISHING_TOURNEY_2, + mEv_EVENT_FISHING_TOURNEY_2, + mEv_EVENT_RUMOR_HARVEST_FESTIVAL, + mEv_EVENT_HARVEST_FESTIVAL, + mEv_EVENT_SALE_DAY, + mEv_EVENT_SNOW_DAY, + mEv_EVENT_TOY_DAY_SONCHO, + mEv_EVENT_RUMOR_TOY_DAY, + mEv_EVENT_TOY_DAY_JINGLE, + mEv_EVENT_SNOWMAN_SEASON, + mEv_EVENT_RUMOR_NEW_YEARS_EVE_COUNTDOWN, + mEv_EVENT_NEW_YEARS_EVE_COUNTDOWN, + mEv_EVENT_CHERRY_BLOSSOM_PETALS, + mEv_EVENT_TALK_TOY_DAY, - mEv_EVENT_SONCHO_NEW_YEARS_DAY, - mEv_EVENT_SONCHO_GROUNDHOG_DAY, - mEv_EVENT_SONCHO_SPRING_SPORTS_FAIR, - mEv_EVENT_SONCHO_APRILFOOLS_DAY, - mEv_EVENT_SONCHO_CHERRY_BLOSSOM_FESTIVAL, - mEv_EVENT_SONCHO_NATURE_DAY, - mEv_EVENT_SONCHO_SPRING_CLEANING, - mEv_EVENT_SONCHO_MOTHERS_DAY, - mEv_EVENT_SONCHO_GRADUATION_DAY, - mEv_EVENT_SONCHO_FATHERS_DAY, - mEv_EVENT_SONCHO_FISHING_TOURNEY_1, - mEv_EVENT_SONCHO_TOWN_DAY, - mEv_EVENT_SONCHO_FIREWORKS_SHOW, - mEv_EVENT_SONCHO_METEOR_SHOWER, - mEv_EVENT_SONCHO_FOUNDERS_DAY, - mEv_EVENT_SONCHO_LABOR_DAY, - mEv_EVENT_SONCHO_FALL_SPORTS_FAIR, - mEv_EVENT_SONCHO_HARVEST_MOON_FESTIVAL, - mEv_EVENT_SONCHO_EXPLORERS_DAY, - mEv_EVENT_SONCHO_HALLOWEEN, - mEv_EVENT_SONCHO_MAYORS_DAY, - mEv_EVENT_SONCHO_OFFICERS_DAY, - mEv_EVENT_SONCHO_FISHING_TOURNEY_2, - mEv_EVENT_SONCHO_HARVEST_FESTIVAL, - mEv_EVENT_SONCHO_SALE_DAY, - mEv_EVENT_SONCHO_SNOW_DAY, - mEv_EVENT_SONCHO_TOY_DAY, + mEv_EVENT_PLAYER_BIRTHDAY, - mEv_EVENT_TALK_NEW_YEARS_COUNTDOWN, - mEv_EVENT_HARVEST_FESTIVAL_FRANKLIN, + mEv_EVENT_DOZAEMON, + mEv_EVENT_KABU_PEDDLER, + mEv_EVENT_LOTTERY, + mEv_EVENT_KK_SLIDER, - mEv_EVENT_WEATHER_CLEAR, - mEv_EVENT_WEATHER_SNOW, - mEv_EVENT_WEATHER_SPORTS_FAIR, + mEv_EVENT_HANDBILL_BROKER, + mEv_EVENT_HANDBILL_SHOP_SALE, - mEv_EVENT_BRIDGE_MAKE, - mEv_EVENT_SONCHO_BRIDGE_MAKE, + mEv_EVENT_ARTIST, + mEv_EVENT_BROKER_SALE, + mEv_EVENT_DESIGNER, + mEv_EVENT_GYPSY, + mEv_EVENT_SHOP_SALE, + mEv_EVENT_CARPET_PEDDLER, - mEv_EVENT_GHOST, - mEv_EVENT_MASK_NPC, // "Go Home Npc" & "Blanca" events + mEv_EVENT_SONCHO_NEW_YEARS_DAY, + mEv_EVENT_SONCHO_GROUNDHOG_DAY, + mEv_EVENT_SONCHO_SPRING_SPORTS_FAIR, + mEv_EVENT_SONCHO_APRILFOOLS_DAY, + mEv_EVENT_SONCHO_CHERRY_BLOSSOM_FESTIVAL, + mEv_EVENT_SONCHO_NATURE_DAY, + mEv_EVENT_SONCHO_SPRING_CLEANING, + mEv_EVENT_SONCHO_MOTHERS_DAY, + mEv_EVENT_SONCHO_GRADUATION_DAY, + mEv_EVENT_SONCHO_FATHERS_DAY, + mEv_EVENT_SONCHO_FISHING_TOURNEY_1, + mEv_EVENT_SONCHO_TOWN_DAY, + mEv_EVENT_SONCHO_FIREWORKS_SHOW, + mEv_EVENT_SONCHO_METEOR_SHOWER, + mEv_EVENT_SONCHO_FOUNDERS_DAY, + mEv_EVENT_SONCHO_LABOR_DAY, + mEv_EVENT_SONCHO_FALL_SPORTS_FAIR, + mEv_EVENT_SONCHO_HARVEST_MOON_FESTIVAL, + mEv_EVENT_SONCHO_EXPLORERS_DAY, + mEv_EVENT_SONCHO_HALLOWEEN, + mEv_EVENT_SONCHO_MAYORS_DAY, + mEv_EVENT_SONCHO_OFFICERS_DAY, + mEv_EVENT_SONCHO_FISHING_TOURNEY_2, + mEv_EVENT_SONCHO_HARVEST_FESTIVAL, + mEv_EVENT_SONCHO_SALE_DAY, + mEv_EVENT_SONCHO_SNOW_DAY, + mEv_EVENT_SONCHO_TOY_DAY, - mEv_EVENT_74, // unused? + mEv_EVENT_TALK_NEW_YEARS_COUNTDOWN, + mEv_EVENT_HARVEST_FESTIVAL_FRANKLIN, - mEv_EVENT_KOINOBORI, + mEv_EVENT_WEATHER_CLEAR, + mEv_EVENT_WEATHER_SNOW, + mEv_EVENT_WEATHER_SPORTS_FAIR, - mEv_EVENT_76, // unused? + mEv_EVENT_BRIDGE_MAKE, + mEv_EVENT_SONCHO_BRIDGE_MAKE, - mEv_EVENT_NUM + mEv_EVENT_GHOST, + mEv_EVENT_MASK_NPC, // "Go Home Npc" & "Blanca" events + + mEv_EVENT_74, // unused? + + mEv_EVENT_KOINOBORI, + + mEv_EVENT_76, // unused? + + mEv_EVENT_NUM }; enum { - mEv_SAVE_DATE_TODAY, - mEv_SAVE_DATE_LAST_PLAY_DATE, - mEv_SAVE_DATE_BIRTHDAY, - mEv_SAVE_DATE_SPECIAL0, /* Initialized to rtc month-day in init_special_event */ - mEv_SAVE_DATE_SPECIAL1, /* Initialized to beginning month-day of special event in init_special_event */ - mEv_SAVE_DATE_SPECIAL2, /* Initialized to ending month-day of special event in init_special_event */ - mEv_SAVE_DATE_WEEKLY, - mEv_SAVE_DATE_SPECIAL3, /* Initialized to opening hours for shop sale in init_special_event */ + mEv_SAVE_DATE_TODAY, + mEv_SAVE_DATE_LAST_PLAY_DATE, + mEv_SAVE_DATE_BIRTHDAY, + mEv_SAVE_DATE_SPECIAL0, /* Initialized to rtc month-day in init_special_event */ + mEv_SAVE_DATE_SPECIAL1, /* Initialized to beginning month-day of special event in init_special_event */ + mEv_SAVE_DATE_SPECIAL2, /* Initialized to ending month-day of special event in init_special_event */ + mEv_SAVE_DATE_WEEKLY, + mEv_SAVE_DATE_SPECIAL3, /* Initialized to opening hours for shop sale in init_special_event */ - mEv_SAVE_DATE_NUM + mEv_SAVE_DATE_NUM }; enum { - mEv_SPECIAL_STATE_UNSCHEDULED, - mEv_SPECIAL_STATE_SCHEDULED_LATER, - mEv_SPECIAL_STATE_SCHEDULED_TODAY, - mEv_SPECIAL_STATE_ACTIVE, - - mEv_SPECIAL_STATE_NUM + mEv_SPECIAL_STATE_UNSCHEDULED, + mEv_SPECIAL_STATE_SCHEDULED_LATER, + mEv_SPECIAL_STATE_SCHEDULED_TODAY, + mEv_SPECIAL_STATE_ACTIVE, + + mEv_SPECIAL_STATE_NUM }; -#define mEv_STATUS_ACTIVE (1 << 0) /* event is active */ -#define mEv_STATUS_STOP (1 << 1) /* event is stopped */ -#define mEv_STATUS_SHOW (1 << 2) /* event is shown */ -#define mEv_STATUS_PLAYSOUND (1 << 3) /* event should play sound */ -#define mEv_STATUS_RUN (1 << 4) /* event should run */ -#define mEv_STATUS_ERROR (1 << 5) /* event is in error state */ -#define mEv_STATUS_TALK (1 << 6) /* event requires talking to player */ -#define mEv_STATUS_EXIST (1 << 7) /* event is scheduled */ +#define mEv_STATUS_ACTIVE (1 << 0) /* event is active */ +#define mEv_STATUS_STOP (1 << 1) /* event is stopped */ +#define mEv_STATUS_SHOW (1 << 2) /* event is shown */ +#define mEv_STATUS_PLAYSOUND (1 << 3) /* event should play sound */ +#define mEv_STATUS_RUN (1 << 4) /* event should run */ +#define mEv_STATUS_ERROR (1 << 5) /* event is in error state */ +#define mEv_STATUS_TALK (1 << 6) /* event requires talking to player */ +#define mEv_STATUS_EXIST (1 << 7) /* event is scheduled */ #define mEv_GHOST_HITODAMA_NUM 5 typedef struct ghost_spirit_block_data_s { - u8 block_x[mEv_GHOST_HITODAMA_NUM]; - u8 block_z[mEv_GHOST_HITODAMA_NUM]; + u8 block_x[mEv_GHOST_HITODAMA_NUM]; + u8 block_z[mEv_GHOST_HITODAMA_NUM]; } mEv_gst_hitodama_block_c; #define mEv_GHOST_FLAG_ACTIVE 0x4000 // TODO: do these live in the ghost actor itself? #define mEv_GHOST_FLAG_RETURNED_SPIRITS 0x8000 typedef struct ghost_common_s { - mEv_gst_hitodama_block_c hitodama_block_data; - u16 flags; - u8 _0C[0x2C - 0x0C]; + mEv_gst_hitodama_block_c hitodama_block_data; + u16 flags; + u8 _0C[0x2C - 0x0C]; } mEv_gst_common_c; typedef struct ghost_event_s { - u16 okoruhito_str_no; - u16 flags; - lbRTC_ymd_c renew_time; + u16 okoruhito_str_no; + u16 flags; + lbRTC_ymd_c renew_time; } mEv_gst_c; #define mEv_DESGINER_NUM 3 typedef struct designer_common_s { - int button_presses; - int _04; + int button_presses; + int _04; } mEv_dsg_common_c; typedef struct kabu_peddler_event_s { - PersonalID_c spoken_pids[TOTAL_PLAYER_NUM]; + PersonalID_c spoken_pids[TOTAL_PLAYER_NUM]; } mEv_kabu_peddler_c; typedef struct dozaemon_event_s { - u16 flags; + u16 flags; } mEv_dozaemon_c; typedef union { - mEv_kabu_peddler_c kabu_peddler; - mEv_dozaemon_c dozaemon; + mEv_kabu_peddler_c kabu_peddler; + mEv_dozaemon_c dozaemon; } mEv_weekly_u; typedef struct bargin_event_s { - lbRTC_time_c start_time; - lbRTC_time_c end_time; - mActor_name_t items[5]; - int kind; + lbRTC_time_c start_time; + lbRTC_time_c end_time; + mActor_name_t items[5]; + int kind; } mEv_bargin_c; typedef struct designer_event_s { - PersonalID_c pids[mEv_DESGINER_NUM]; - int used; - mActor_name_t gifted_cloths[mEv_DESGINER_NUM]; + PersonalID_c pids[mEv_DESGINER_NUM]; + int used; + mActor_name_t gifted_cloths[mEv_DESGINER_NUM]; } mEv_designer_c; typedef struct broker_event_s { - PersonalID_c pid[2]; - lbRTC_time_c end_time; - int used; - mActor_name_t sold_items[2]; - mActor_name_t items[3]; + PersonalID_c pid[2]; + lbRTC_time_c end_time; + int used; + mActor_name_t sold_items[2]; + mActor_name_t items[3]; } mEv_broker_c; typedef struct artist_event_s { - PersonalID_c pids[2]; - int used; - mActor_name_t walls[2]; + PersonalID_c pids[2]; + int used; + mActor_name_t walls[2]; } mEv_artist_c; typedef struct arabian_event_s { - int used; - mActor_name_t carpet; + int used; + mActor_name_t carpet; } mEv_arabian_c; typedef struct gypsy_event_s { - int _00; - int block_z; - int block_x; - int ut_z; - int ut_x; + int _00; + int block_z; + int block_x; + int ut_z; + int ut_x; } mEv_gypsy_c; typedef union { - mEv_bargin_c bargin; - mEv_designer_c designer; - mEv_broker_c broker; - mEv_artist_c artist; - mEv_arabian_c arabian; - mEv_gypsy_c gypsy; + mEv_bargin_c bargin; + mEv_designer_c designer; + mEv_broker_c broker; + mEv_artist_c artist; + mEv_arabian_c arabian; + mEv_gypsy_c gypsy; } mEv_special_u; typedef struct special_event_s { - lbRTC_time_c scheduled; - u32 type; - mEv_special_u event; + lbRTC_time_c scheduled; + u32 type; + mEv_special_u event; } mEv_special_c; typedef struct save_event_data_s { - mEv_special_c special; - mEv_weekly_u weekly; - u32 flags; + mEv_special_c special; + mEv_weekly_u weekly; + u32 flags; } mEv_event_save_c; typedef struct broker_event_common_s { - PersonalID_c entered_pid; - int hide_npc; + PersonalID_c entered_pid; + int hide_npc; } mEv_broker_common_c; typedef struct santa_event_common_s { - u8 present; - u8 talk_counter; - s8 bx; - s8 bz; - mActor_name_t last_talk_cloth; + u8 present; + u8 talk_counter; + s8 bx; + s8 bz; + mActor_name_t last_talk_cloth; } mEv_santa_event_common_c; #define mEv_SANTA_CLOTH_NUM_MAX 10 /* How many different shirts can the player trick Jingle with */ typedef struct santa_event_s { - PersonalID_c pid; - u8 present_count; - mActor_name_t cloth[mEv_SANTA_CLOTH_NUM_MAX]; + PersonalID_c pid; + u8 present_count; + mActor_name_t cloth[mEv_SANTA_CLOTH_NUM_MAX]; } mEv_santa_event_c; typedef union { - mEv_broker_common_c broker; - mEv_santa_event_common_c santa; + mEv_broker_common_c broker; + mEv_santa_event_common_c santa; } mEv_event_common_u; typedef struct event_s { - u8 day; - u8 hour; - u8 _02; - u8 state; - u8 month; - u8 year; - s16 changed_num; - int block_z; - int block_x; - int unused[5]; + u8 day; + u8 hour; + u8 _02; + u8 state; + u8 month; + u8 year; + s16 changed_num; + int block_z; + int block_x; + int unused[5]; } Event_c; typedef struct event_info_s { - u8 type; - u8 id; - u16 year; - mEv_MonthDay_u start_date; - mEv_MonthDay_u end_date; + u8 type; + u8 id; + u16 year; + mEv_MonthDay_u start_date; + mEv_MonthDay_u end_date; } mEv_info_c; typedef struct event_place_data_s { - BlockOrUnit_c block; - BlockOrUnit_c unit; - mActor_name_t actor_name; - s16 flag; + BlockOrUnit_c block; + BlockOrUnit_c unit; + mActor_name_t actor_name; + s16 flag; } mEv_place_data_c; typedef struct event_place_s { - mEv_info_c info; - mEv_place_data_c data; + mEv_info_c info; + mEv_place_data_c data; } mEv_place_c; typedef struct event_area_s { - mEv_info_c info; - int data[11]; + mEv_info_c info; + int data[11]; } mEv_area_c; #define mEv_AREA_NUM 5 #define mEv_PLACE_NUM 10 typedef struct event_common_s { - s16 _00; - s16 area_use_bitfield; - mEv_area_c area[mEv_AREA_NUM]; - s16 too_short; - s16 place_use_bitfield; - mEv_place_c place[mEv_PLACE_NUM]; - s16 fieldday_event_id; - s16 fieldday_event_over_status; - u32 unused[2]; + s16 _00; + s16 area_use_bitfield; + mEv_area_c area[mEv_AREA_NUM]; + s16 too_short; + s16 place_use_bitfield; + mEv_place_c place[mEv_PLACE_NUM]; + s16 fieldday_event_id; + s16 fieldday_event_over_status; + u32 unused[2]; } mEv_common_data_c; typedef struct event_save_event_info_s { - u8 type; - u8 flags; + u8 type; + u8 flags; } mEv_event_save_info_c; typedef struct event_common_save_data { - mEv_event_save_info_c special_event; - mEv_event_save_info_c weekly_event; - u16 dates[mEv_SAVE_DATE_NUM]; - int area_use_bitfield; - mEv_area_c area[mEv_AREA_NUM]; - int last_date; - int delete_event_id; - u32 valentines_day_date; - u32 white_day_date; /* unused in AC */ - u16 ghost_day; - u16 bridge_day; // last date suspension bridge event was active - union { - struct { - u8 used_all_locations:1; // set to true when tortimer has cycled through all possible bridge locations? - u8 locations_used:7; // index of river acre w/ possible bridge location currently at - }; + mEv_event_save_info_c special_event; + mEv_event_save_info_c weekly_event; + u16 dates[mEv_SAVE_DATE_NUM]; + int area_use_bitfield; + mEv_area_c area[mEv_AREA_NUM]; + int last_date; + int delete_event_id; + u32 valentines_day_date; + u32 white_day_date; /* unused in AC */ + u16 ghost_day; + u16 bridge_day; // last date suspension bridge event was active + union { + struct { + u8 used_all_locations : 1; // set to true when tortimer has cycled through all possible bridge locations? + u8 locations_used : 7; // index of river acre w/ possible bridge location currently at + }; - u8 raw; - } bridge_flags; - u8 ghost_event_type; // 0x72 will spawn wisp, 0x77 won't? - u8 soncho_event_type; // checked not equal to 0xFF for summer & fall fishing tournies - u8 dozaemon_completed; // used to signal when you've received an item from gulliver + u8 raw; + } bridge_flags; + u8 ghost_event_type; // 0x72 will spawn wisp, 0x77 won't? + u8 soncho_event_type; // checked not equal to 0xFF for summer & fall fishing tournies + u8 dozaemon_completed; // used to signal when you've received an item from gulliver } mEv_save_common_data_c; extern void mEv_clear_status(int event, s16 status); @@ -606,13 +608,20 @@ extern void mEv_SetTitleDemo(int titledemo_no); extern int mGH_check_birth2(); extern int mMC_check_birth(); +extern void mGH_animal_return_init(); +extern void mMC_mask_cat_init(); +extern void mEv_init_force(Event_c* event); +extern void mEv_SetGateway(); +extern void mEv_UnSetGateway(); +extern void mGH_check_delete(); +extern void mMC_check_delete(); +extern void mEv_special_event_soldout(int type); extern void mEv_debug_print4f(gfxprint_t* gfxprint); extern void mEv_sp_debug_print4f(gfxprint_t* gfxprint); #define mEv_IsEventActive(event) mEv_check_status(event, mEv_STATUS_ACTIVE) - #ifdef __cplusplus } #endif diff --git a/include/m_event_map_npc.h b/include/m_event_map_npc.h index 7b9f2017..fc42e768 100644 --- a/include/m_event_map_npc.h +++ b/include/m_event_map_npc.h @@ -10,8 +10,10 @@ extern "C" { #endif extern int mEvMN_GetJointEventRandomNpc(mActor_name_t* selected_npc_id); -extern int mEvNM_CheckJointEvent(); +extern int mEvNM_CheckJointEvent(u32 id); extern void mEvMN_GetEventNpcName(mActor_name_t* npc_name, int event, int idx, int param_4); +extern int mEvMN_GetEventTypeMap(void); +extern int mEvMN_GetMapIdx(int event_type); #ifdef __cplusplus } diff --git a/include/m_flashrom.h b/include/m_flashrom.h index bdc4c444..74a9e08e 100644 --- a/include/m_flashrom.h +++ b/include/m_flashrom.h @@ -15,35 +15,36 @@ extern "C" { #define mFRm_NO_ERROR_NO 7 enum save_error_type { - mFRm_ERROR_BAD_RTC, /* RTC returned abnormal value */ - mFRm_ERROR_MEMCARD_TRAVELDATA_CONFLICT, /* travel data is on the same memory card as requesting to save town data */ - mFRm_ERROR_DATA_CORRUPTED, /* save data is corrupt */ - mFRm_ERROR_MEMCARD_NO_FILES, /* memory card is out of "files" */ - mFRm_ERROR_MEMCARD_DAMAGED, /* memory card is damaged */ - mFRm_ERROR_MEMCARD_FORMAT, /* memory card requires formatting (corrupt or different region?) */ - mFRm_ERROR_MEMCARD_INVALID, /* memory card type "cannot be used with Animal Crossing" */ - mFRm_ERROR_MEMCARD_NO_SPACE, /* memory card has free files, but not enough free space for save */ - mFRm_ERROR_NOT_MEMCARD, /* device in card slot is not a memory card */ - mFRm_ERROR_NO_MEMCARD, /* nothing inserted in either Slot A or Slot B */ - - mFRm_ERROR_NUM + mFRm_ERROR_BAD_RTC, /* RTC returned abnormal value */ + mFRm_ERROR_MEMCARD_TRAVELDATA_CONFLICT, /* travel data is on the same memory card as requesting to save town data */ + mFRm_ERROR_DATA_CORRUPTED, /* save data is corrupt */ + mFRm_ERROR_MEMCARD_NO_FILES, /* memory card is out of "files" */ + mFRm_ERROR_MEMCARD_DAMAGED, /* memory card is damaged */ + mFRm_ERROR_MEMCARD_FORMAT, /* memory card requires formatting (corrupt or different region?) */ + mFRm_ERROR_MEMCARD_INVALID, /* memory card type "cannot be used with Animal Crossing" */ + mFRm_ERROR_MEMCARD_NO_SPACE, /* memory card has free files, but not enough free space for save */ + mFRm_ERROR_NOT_MEMCARD, /* device in card slot is not a memory card */ + mFRm_ERROR_NO_MEMCARD, /* nothing inserted in either Slot A or Slot B */ + + mFRm_ERROR_NUM }; typedef struct mFRm_chk_s { - /* 0x00 */ int version; - /* 0x04 */ u32 code; - /* 0x08 */ u16 land_id; - /* 0x0A */ lbRTC_time_c time; - /* 0x12 */ u16 checksum; + /* 0x00 */ int version; + /* 0x04 */ u32 code; + /* 0x08 */ u16 land_id; + /* 0x0A */ lbRTC_time_c time; + /* 0x12 */ u16 checksum; } mFRm_chk_t; typedef struct flashrom_error_info { - int err_no; - int proc_idx; + int err_no; + int proc_idx; } mFRm_err_info_c; -typedef int (save_check_proc)(void); +typedef int(save_check_proc)(void); +extern MATCH_FORCESTRIP void mFRm_PrintErrInfo(gfxprint_t* gfxprint); extern void mFRm_set_msg_idx(int idx); extern int mFRm_get_msg_idx(); extern u16 mFRm_ReturnCheckSum(u16* data, int size); @@ -57,7 +58,7 @@ extern void mFRm_PrintSavedDebug(gfxprint_t* gfxprint); extern void mFRm_clear_err_info(); extern void mFRm_save_data_check(); extern void mFRm_display_errInfo(gfxprint_t* gfxprint); - + #ifdef __cplusplus } #endif diff --git a/include/m_handbill.h b/include/m_handbill.h index 9940377d..f5f60cbb 100644 --- a/include/m_handbill.h +++ b/include/m_handbill.h @@ -19,79 +19,82 @@ extern "C" { #define mHandbill_MAIL_NUM 982 enum { - mHandbill_FREE_STR0, - mHandbill_FREE_STR1, - mHandbill_FREE_STR2, - mHandbill_FREE_STR3, - mHandbill_FREE_STR4, - mHandbill_FREE_STR5, - mHandbill_FREE_STR6, - mHandbill_FREE_STR7, - mHandbill_FREE_STR8, - mHandbill_FREE_STR9, - mHandbill_FREE_STR10, - mHandbill_FREE_STR11, - mHandbill_FREE_STR12, - mHandbill_FREE_STR13, - mHandbill_FREE_STR14, - mHandbill_FREE_STR15, - mHandbill_FREE_STR16, - mHandbill_FREE_STR17, - mHandbill_FREE_STR18, - mHandbill_FREE_STR19, + mHandbill_FREE_STR0, + mHandbill_FREE_STR1, + mHandbill_FREE_STR2, + mHandbill_FREE_STR3, + mHandbill_FREE_STR4, + mHandbill_FREE_STR5, + mHandbill_FREE_STR6, + mHandbill_FREE_STR7, + mHandbill_FREE_STR8, + mHandbill_FREE_STR9, + mHandbill_FREE_STR10, + mHandbill_FREE_STR11, + mHandbill_FREE_STR12, + mHandbill_FREE_STR13, + mHandbill_FREE_STR14, + mHandbill_FREE_STR15, + mHandbill_FREE_STR16, + mHandbill_FREE_STR17, + mHandbill_FREE_STR18, + mHandbill_FREE_STR19, - mHandbill_FREE_STR_NUM + mHandbill_FREE_STR_NUM }; enum { - mHandbill_FILL_NONE, - mHandbill_FILL_RETURN, - mHandbill_FILL_SPACE, + mHandbill_FILL_NONE, + mHandbill_FILL_RETURN, + mHandbill_FILL_SPACE, - mHandbill_FILL_NUM + mHandbill_FILL_NUM }; typedef struct handbill_data_s mHandbill_Data_c; struct handbill_data_s { - u8 free_str[mHandbill_FREE_STR_NUM][mHandbill_FREE_STR_LEN]; - int free_str_art[mHandbill_FREE_STR_NUM]; - int force_art; - int capital_flag; + u8 free_str[mHandbill_FREE_STR_NUM][mHandbill_FREE_STR_LEN]; + int free_str_art[mHandbill_FREE_STR_NUM]; + int force_art; + int capital_flag; }; -extern void mHandbill_Load_HandbillFromRom(u8* header, int* header_back_pos, u8* footer, u8* body, int handbill_no); -extern void mHandbill_Load_HandbillFromRom2(u8* header, int header_size, int* header_back_pos, u8* footer, int footer_size, u8* body, int handbill_no); -extern void mHandbill_Set_free_str(int free_str_no, u8* str, int str_len); -extern void mHandbill_Set_free_str_art(int free_str_no, u8* str, int str_len, int article_no); +extern void mHandbill_aram_init(); +extern void mHandbill_Set_free_str(int str_num, u8* str, int str_len); +extern void mHandbill_Set_free_str_art(int str_num, u8* str, int str_len, int article); +extern int mHandbill_MoveDataCut(u8* data, int buf_size, int dst_idx, int src_idx, int data_len, int fill_type); +extern void mHandbill_Load_HandbillFromRom(u8* header, int* header_back_start, u8* footer, u8* body, int mail_no); +extern void mHandbill_Load_HandbillFromRom2(u8* header, int header_size, int* header_back_start, u8* footer, + int footer_size, u8* body, int mail_no); enum { - mHandbillz_TYPE_SUPER, - mHandbillz_TYPE_MAILA, - mHandbillz_TYPE_MAILB, - mHandbillz_TYPE_MAILC, - mHandbillz_TYPE_PS, + mHandbillz_TYPE_SUPER, + mHandbillz_TYPE_MAILA, + mHandbillz_TYPE_MAILB, + mHandbillz_TYPE_MAILC, + mHandbillz_TYPE_PS, - mHandbillz_TYPE_NUM + mHandbillz_TYPE_NUM }; typedef struct mHandbillz_info_s { - u8* super_buf_p; - size_t super_buf_size; + u8* super_buf_p; + size_t super_buf_size; - u8* mail_buf_p; - size_t mail_buf_size; + u8* mail_buf_p; + size_t mail_buf_size; - u8* ps_buf_p; - size_t ps_buf_size; + u8* ps_buf_p; + size_t ps_buf_size; - int super_no; - int maila_no; - int mailb_no; - int mailc_no; - int ps_no; + int super_no; + int maila_no; + int mailb_no; + int mailc_no; + int ps_no; - int header_back_start; + int header_back_start; } mHandbillz_Info_c; extern int mHandbillz_load(mHandbillz_Info_c* info); diff --git a/include/m_haniwaPortrait_ovl.h b/include/m_haniwaPortrait_ovl.h index bba8dd3d..935a8b39 100644 --- a/include/m_haniwaPortrait_ovl.h +++ b/include/m_haniwaPortrait_ovl.h @@ -14,14 +14,17 @@ typedef void (*mHP_SET_HANIWAPORTRAIT_PROC)(Submenu*, mSM_MenuInfo_c*, GRAPH*, G typedef void (*mHP_HANIWAPORTRAIT_SHAPE_MOVE_PROC)(Submenu*); struct haniwaPortrait_ovl_s { - cKF_SkeletonInfo_R_c keyframe; - s_xyz keyframe_work[8]; - s_xyz keyframe_morph[8]; - u8 _0D0[72]; - mHP_SET_HANIWAPORTRAIT_PROC set_haniwaPortrait_proc; - mHP_HANIWAPORTRAIT_SHAPE_MOVE_PROC haniwaPortrait_shape_move_proc; + cKF_SkeletonInfo_R_c keyframe; + s_xyz keyframe_work[8]; + s_xyz keyframe_morph[8]; + u8 _0D0[72]; + mHP_SET_HANIWAPORTRAIT_PROC set_haniwaPortrait_proc; + mHP_HANIWAPORTRAIT_SHAPE_MOVE_PROC haniwaPortrait_shape_move_proc; }; +extern void mHP_haniwaPortrait_ovl_construct(Submenu* submenu); +extern void mHP_haniwaPortrait_ovl_destruct(Submenu* submenu); + #ifdef __cplusplus } #endif diff --git a/include/m_lib.h b/include/m_lib.h index f3bcdc55..c7ed5f3a 100644 --- a/include/m_lib.h +++ b/include/m_lib.h @@ -40,6 +40,7 @@ extern "C" { /* short angle -> radians */ #define SHORT2RAD_ANGLE(s) ((((f32)(s)) / (65536.0f / (2.0f * F_PI)))) +#define SHORT2RAD_ANGLE2(s) ((f32)(s) * ((2.0f * F_PI) / 65536.0f)) #define SHORTANGLE2RAD(sangle) ((F_PI / 32768.0f) * ((f32)(sangle))) /* degrees -> short angle */ diff --git a/include/m_name_table.h b/include/m_name_table.h index c9ce2064..1a2f1e66 100644 --- a/include/m_name_table.h +++ b/include/m_name_table.h @@ -555,6 +555,7 @@ extern int mNT_check_unknown(mActor_name_t item_no); #define FTR0_START 0x1000 #define FTR_CLASSIC_WARDROBE 0x1004 +#define FTR_FAN 0x1088 #define FTR_PAPA_BEAR 0x10E8 #define FTR_PAPA_BEAR_EAST 0x10E9 #define FTR_PAPA_BEAR_NORTH 0x10EA diff --git a/include/m_player_lib.h b/include/m_player_lib.h index 3ccd6215..c2ae63ce 100644 --- a/include/m_player_lib.h +++ b/include/m_player_lib.h @@ -60,6 +60,9 @@ extern int mPlib_check_player_actor_main_index_RecieveMove(GAME* game); extern int mPlib_check_label_player_demo_wait(GAME* game, void* label); extern int mPlib_check_player_outdoor_start(GAME* game); extern void mPlib_Set_change_color_request(); +extern int mPlib_check_player_open_umbrella(GAME_PLAY* play); +extern int mPlib_Check_UKI_COMEBACK_STATUS(); +extern int mPlib_check_player_actor_main_index_OutDoorMove(GAME_PLAY* play); extern mPlayer_change_data_from_submenu_c* mPlib_Get_change_data_from_submenu_p(); @@ -67,6 +70,7 @@ extern void mPlib_Object_Exchange_keep_new_PlayerMdl(GAME_PLAY* play); extern void mPlib_Object_Exchange_keep_new_PlayerTex(GAME_PLAY* play, int bank_id, int base_idx); extern void mPlib_Object_Exchange_keep_new_PlayerFaceTex(GAME_PLAY* play); extern void mPlib_Object_Exchange_keep_new_PlayerFacePallet(GAME_PLAY* play, int bank_id, int base_idx); +extern void mPlib_Object_Exchange_keep_new_PlayerPallet(GAME_PLAY* play, int bank_id, int base_idx); extern void mPlib_request_main_give_type1(GAME* game, mActor_name_t item, int mode, int present, int on_surface); #define GET_PLAYER_ACTOR(play) get_player_actor_withoutCheck(play) diff --git a/include/m_rcp.h b/include/m_rcp.h index a6542bd6..ea30cd04 100644 --- a/include/m_rcp.h +++ b/include/m_rcp.h @@ -30,15 +30,19 @@ extern Gfx* gfx_softsprite_prim_xlu(Gfx* gfx); extern Gfx* gfx_tex_scroll2(Gfx** gfxpp, int x, int y, int width, int height); extern Gfx* tex_scroll2(GRAPH* graph, u32 x, u32 y, int width, int height); extern Gfx* tex_scroll2_dolphin(GRAPH* graph, int x, int y, int width, int height); -extern Gfx* two_tex_scroll(GRAPH* graph, int tile1, int x1, int y1, int width1, int height1, int tile2, int x2, int y2, int width2, int height2); -extern Gfx* two_tex_scroll_dolphin(GRAPH* graph, int tile1, int x1, int y1, int width1, int height1, int tile2, int x2, int y2, int width2, int height2); -extern void DisplayList_initialize(GRAPH* graph, u32 clear_r, u32 clear_g, u32 clear_b, GAME* game); +extern Gfx* two_tex_scroll(GRAPH* graph, int tile1, int x1, int y1, int width1, int height1, int tile2, int x2, int y2, + int width2, int height2); +extern Gfx* two_tex_scroll_dolphin(GRAPH* graph, int tile1, int x1, int y1, int width1, int height1, int tile2, int x2, + int y2, int width2, int height2); +extern void DisplayList_initialize(GRAPH* graph, u8 clear_r, u8 clear_g, u8 clear_b, GAME* game); extern void fade_rgba8888_draw(Gfx** gfxp, u32 color); extern void fade_black_draw(Gfx** gfx, u32 color); extern Gfx* gfx_gDPFillRectangle1(Gfx* gfx, u32 ulx, u32 uly, u32 lrx, u32 lry); extern Gfx* gfx_gDPFillRectangleF(Gfx* gfx, u32 ulx, u32 uly, u32 lrx, u32 lry); -extern Gfx* gfx_gSPTextureRectangle1(Gfx* gfx, int xl, int yl, int xh, int yh, int tile, int s, int t, int dsdx, int dtdy); -extern Gfx* gfx_gSPScisTextureRectangle1(Gfx* gfx, int xl, int yl, int xh, int yh, int tile, int s, int t, int dsdx, int dtdy); +extern Gfx* gfx_gSPTextureRectangle1(Gfx* gfx, int xl, int yl, int xh, int yh, int tile, int s, int t, int dsdx, + int dtdy); +extern Gfx* gfx_gSPScisTextureRectangle1(Gfx* gfx, int xl, int yl, int xh, int yh, int tile, int s, int t, int dsdx, + int dtdy); extern Gfx RSP_RDP_clear_data[]; extern int fbdemo_mode; diff --git a/include/m_repay_ovl.h b/include/m_repay_ovl.h index 5e413cb6..00a95eb4 100644 --- a/include/m_repay_ovl.h +++ b/include/m_repay_ovl.h @@ -10,26 +10,30 @@ extern "C" { #endif enum { - mRP_CURSOR_100000, - mRP_CURSOR_10000, - mRP_CURSOR_1000, - mRP_CURSOR_100, - mRP_CURSOR_10, - mRP_CURSOR_1, - mRP_CURSOR_OK, + mRP_CURSOR_100000, + mRP_CURSOR_10000, + mRP_CURSOR_1000, + mRP_CURSOR_100, + mRP_CURSOR_10, + mRP_CURSOR_1, + mRP_CURSOR_OK, - mRP_CURSOR_NUM + mRP_CURSOR_NUM }; struct repay_ovl_s { - u32 money; - u32 loan; - u32 repay_amount; - u32 max_money; - u32 max_repay; - int cursor_idx; + u32 money; + u32 loan; + u32 repay_amount; + u32 max_money; + u32 max_repay; + int cursor_idx; }; +extern void mRP_repay_ovl_set_proc(Submenu* submenu); +extern void mRP_repay_ovl_construct(Submenu* submenu); +extern void mRP_repay_ovl_destruct(Submenu* submenu); + #ifdef __cplusplus } #endif diff --git a/include/m_timeIn_ovl.h b/include/m_timeIn_ovl.h index 03059fb7..0d2b518d 100644 --- a/include/m_timeIn_ovl.h +++ b/include/m_timeIn_ovl.h @@ -13,32 +13,36 @@ extern "C" { #define mTI_MAX_YEAR 30 enum { - mTI_IDX_HOUR, - mTI_IDX_MIN, - mTI_IDX_MONTH, - mTI_IDX_DAY, - mTI_IDX_YEAR, - mTI_IDX_OK, + mTI_IDX_HOUR, + mTI_IDX_MIN, + mTI_IDX_MONTH, + mTI_IDX_DAY, + mTI_IDX_YEAR, + mTI_IDX_OK, - mTI_IDX_NUM = mTI_IDX_OK + mTI_IDX_NUM = mTI_IDX_OK }; enum { - mTI_OVL_OPEN_NORMAL, - mTI_OVL_OPEN_INITIAL, + mTI_OVL_OPEN_NORMAL, + mTI_OVL_OPEN_INITIAL, - mTI_OVL_OPEN_NUM + mTI_OVL_OPEN_NUM }; struct timeIn_ovl_s { - u16 values[mTI_IDX_NUM]; - int sel_idx; - u16 saved_min; - u16 input_disabled_flag; - lbRTC_time_c original_time; - int init_flag; + u16 values[mTI_IDX_NUM]; + int sel_idx; + u16 saved_min; + u16 input_disabled_flag; + lbRTC_time_c original_time; + int init_flag; }; +extern void mTI_timeIn_ovl_set_proc(Submenu* submenu); +extern void mTI_timeIn_ovl_construct(Submenu* submenu); +extern void mTI_timeIn_ovl_destruct(Submenu* submenu); + #ifdef __cplusplus } #endif diff --git a/include/m_vibctl.h b/include/m_vibctl.h index dce81525..031e4370 100644 --- a/include/m_vibctl.h +++ b/include/m_vibctl.h @@ -12,77 +12,83 @@ extern "C" { #define mVibctl_FLAG_FORCE_STOP1 (1 << 1) // 2 #define mVibctl_FLAG_FORCE_STOP2 (1 << 2) // 4 #define mVibctl_FLAG_FORCE_STOP3 (1 << 3) // 8 -#define mVibctl_FLAG_FORCE_STOP_ALL (mVibctl_FLAG_FORCE_STOP0 | mVibctl_FLAG_FORCE_STOP1 | mVibctl_FLAG_FORCE_STOP2 | mVibctl_FLAG_FORCE_STOP3) // 15 +#define mVibctl_FLAG_FORCE_STOP_ALL \ + (mVibctl_FLAG_FORCE_STOP0 | mVibctl_FLAG_FORCE_STOP1 | mVibctl_FLAG_FORCE_STOP2 | mVibctl_FLAG_FORCE_STOP3) // 15 enum { - mVibctl_ELEM_ENTRY_ATTACK, // fade-in program - mVibctl_ELEM_ENTRY_SUSTAIN, // sustain program - mVibctl_ELEM_ENTRY_RELEASE, // fade-out program - mVibctl_ELEM_ENTRY_END, // program has finished + mVibctl_ELEM_ENTRY_ATTACK, // fade-in program + mVibctl_ELEM_ENTRY_SUSTAIN, // sustain program + mVibctl_ELEM_ENTRY_RELEASE, // fade-out program + mVibctl_ELEM_ENTRY_END, // program has finished - mVibctl_ELEM_ENTRY_NUM = mVibctl_ELEM_ENTRY_END + mVibctl_ELEM_ENTRY_NUM = mVibctl_ELEM_ENTRY_END }; enum { - mVibctl_VIB_PROG_NON, // rumble config attack, shake tree attack - mVibctl_VIB_PROG_FFF, // fish touch bobber, fishing rod cast, rumble config sustain, Mouth of Truth furniture interaction attack & sustain, shovel hits soft object, net swing, axe cut attack & release, trip attack, pick weed sustain & release - mVibctl_VIB_PROG_F, // unused? - mVibctl_VIB_PROG_MF, // unused? - mVibctl_VIB_PROG_MP, // unused? - mVibctl_VIB_PROG_P, // rumble config release, shake tree release - mVibctl_VIB_PROG_FUNBARI, // unused? - mVibctl_VIB_PROG_ANAHORI, // digging with shovel - mVibctl_VIB_PROG_ANAUME, // filling hole with shovel - mVibctl_VIB_PROG_IMPACT, // fish bite bobber, shovel hits hard object - mVibctl_VIB_PROG_KI_GA_TAORERU, // axe cut sustain - mVibctl_VIB_PROG_KI_WO_YUSURU, // shake tree sustain - mVibctl_VIB_PROG_KORONODA, // trip sustain - mVibctl_VIB_PROG_SURPRISE, // Mouth of Truth furniture interaction release - mVibctl_VIB_PROG_DUMMY_B, // unused? - mVibctl_VIB_PROG_SAMPLE, // unused? + mVibctl_VIB_PROG_NON, // rumble config attack, shake tree attack + mVibctl_VIB_PROG_FFF, // fish touch bobber, fishing rod cast, rumble config sustain, Mouth of Truth furniture + // interaction attack & sustain, shovel hits soft object, net swing, axe cut attack & release, + // trip attack, pick weed sustain & release + mVibctl_VIB_PROG_F, // unused? + mVibctl_VIB_PROG_MF, // unused? + mVibctl_VIB_PROG_MP, // unused? + mVibctl_VIB_PROG_P, // rumble config release, shake tree release + mVibctl_VIB_PROG_FUNBARI, // unused? + mVibctl_VIB_PROG_ANAHORI, // digging with shovel + mVibctl_VIB_PROG_ANAUME, // filling hole with shovel + mVibctl_VIB_PROG_IMPACT, // fish bite bobber, shovel hits hard object + mVibctl_VIB_PROG_KI_GA_TAORERU, // axe cut sustain + mVibctl_VIB_PROG_KI_WO_YUSURU, // shake tree sustain + mVibctl_VIB_PROG_KORONODA, // trip sustain + mVibctl_VIB_PROG_SURPRISE, // Mouth of Truth furniture interaction release + mVibctl_VIB_PROG_DUMMY_B, // unused? + mVibctl_VIB_PROG_SAMPLE, // unused? - mVibctl_VIB_PROG_NUM + mVibctl_VIB_PROG_NUM }; #define mVibctl_ELEM_NUM 4 typedef struct vibration_element_entry_s { - int type; - int frames; - f32 step; + int type; + int frames; + f32 step; } mVibInfo_elem_entry_c; typedef struct vibration_element_s { - mVibInfo_elem_entry_c entries[mVibctl_ELEM_ENTRY_NUM]; - f32 step0; - f32 step1; - int now_entry; - int state_idx; - f32 frame_intensity; - int entry_frame; - f32 now_intensity; - int command; // for padmgr, PAD_MOTOR_* + mVibInfo_elem_entry_c entries[mVibctl_ELEM_ENTRY_NUM]; + f32 step0; + f32 step1; + int now_entry; + int state_idx; + f32 frame_intensity; + int entry_frame; + f32 now_intensity; + int command; // for padmgr, PAD_MOTOR_* } mVibElem_c; typedef struct vibration_info_s { - mVibElem_c* target_elem; - mVibElem_c elements[mVibctl_ELEM_NUM]; - int num_elements; - int force_stop; - int last_force_stop; + mVibElem_c* target_elem; + mVibElem_c elements[mVibctl_ELEM_NUM]; + int num_elements; + int force_stop; + int last_force_stop; } mVibInfo_c; typedef struct vibration_work_data_S { - const u8* data; - int count; + const u8* data; + int count; } mVibWorkData_c; extern void mVibctl_ct(); extern void mVibctl_init0(); extern void mVibctl_init(); +extern void mVibctl_cleanup(); extern void mVibctl_reset(); -extern void mVibctl_entry(int total_frames, int attack_type, int sustain_type, int release_type, int attack_frames, int sustain_frames, int release_frames, f32 step); -extern void mVibctl_simple_entry(int total_frames, int type, int attack_frames, int sustain_frames, int release_frames, f32 step); +extern void mVibctl_entry(int total_frames, int attack_type, int sustain_type, int release_type, int attack_frames, + int sustain_frames, int release_frames, f32 step); +extern void mVibctl_simple_entry(int total_frames, int type, int attack_frames, int sustain_frames, int release_frames, + f32 step); extern void mVibctl_set_force_stop(int force_stop); extern void mVibctl_clr_force_stop(int force_stop); diff --git a/include/main.h b/include/main.h index d395446c..9c31fac9 100644 --- a/include/main.h +++ b/include/main.h @@ -21,6 +21,7 @@ extern OSThread graphThread; extern u8 SegmentBaseAddress[0x40]; void foresta_main(); +extern void mainproc(void* val); #ifdef __cplusplus } diff --git a/include/padmgr.h b/include/padmgr.h index 5973542e..c6ffc24b 100644 --- a/include/padmgr.h +++ b/include/padmgr.h @@ -14,52 +14,52 @@ extern "C" { #define PADMSGBUFCNT 8 enum pads { - PAD0, - PAD1, - PAD2, - PAD3, + PAD0, + PAD1, + PAD2, + PAD3, - PAD_NUM + PAD_NUM }; typedef struct { - u8 last_command; // PAD_MOTOR_* - u8 now_command; // PAD_MOTOR_* - u8 frames; - u8 _pad; + u8 last_command; // PAD_MOTOR_* + u8 now_command; // PAD_MOTOR_* + u8 frames; + u8 _pad; } Motor_t; typedef struct { - Motor_t motors[MAXCONTROLLERS]; - s16 cooldown_frames; - u8 rumble_frames; - u8 _pad0; - u8 reset; + Motor_t motors[MAXCONTROLLERS]; + s16 cooldown_frames; + u8 rumble_frames; + u8 _pad0; + u8 reset; } Rumble_t; typedef struct { - /* 0x0000 */ u8 pad_pattern; - /* 0x0004 */ void (*callback)(void*); - /* 0x0008 */ void* callback_param; - /* 0x000C */ void (*callback2)(void*); - /* 0x0010 */ void* callback2_param; + /* 0x0000 */ u8 pad_pattern; + /* 0x0004 */ void (*callback)(void*); + /* 0x0008 */ void* callback_param; + /* 0x000C */ void (*callback2)(void*); + /* 0x0010 */ void* callback2_param; - /* 0x0014 */ OSContStatus pad_status[MAXCONTROLLERS]; - /* 0x0024 */ OSMessage _msg24; - /* 0x0028 */ OSMessage _msg28; - /* 0x002C */ OSMessage _msgBuf2C[PADMSGBUFCNT]; - /* 0x004C */ OSMessageQueue _msgQueue4C; - /* 0x006C */ OSMessageQueue _msgQueue6C; - /* 0x008C */ OSMessageQueue _msgQueue8C; - /* 0x00AC */ irqmgr_client_t irqclient; - /* 0x00B4 */ u32 _unk0; /* maybe additional value in irqmgr_client_t? */ - /* 0x00B8 */ OSThread thread; - /* 0x03C8 */ u8 _tmp[0x60]; //pad_t pads[MAXCONTROLLERS]; // TODO: figure out what's going on here. - /* 0x0428 */ OSContPad n64_pads[MAXCONTROLLERS]; /* Converted from PADStatus via JUTGamePad */ - /* 0x0440 */ u8 num_controllers; - /* 0x0441 */ u8 device_type[4]; - /* 0x0445 */ u8 pak_type[4]; - /* 0x044A */ Rumble_t rumble; + /* 0x0014 */ OSContStatus pad_status[MAXCONTROLLERS]; + /* 0x0024 */ OSMessage _msg24; + /* 0x0028 */ OSMessage _msg28; + /* 0x002C */ OSMessage _msgBuf2C[PADMSGBUFCNT]; + /* 0x004C */ OSMessageQueue _msgQueue4C; + /* 0x006C */ OSMessageQueue _msgQueue6C; + /* 0x008C */ OSMessageQueue _msgQueue8C; + /* 0x00AC */ irqmgr_client_t irqclient; + /* 0x00B4 */ u32 _unk0; /* maybe additional value in irqmgr_client_t? */ + /* 0x00B8 */ OSThread thread; + /* 0x03C8 */ u8 _tmp[0x60]; // pad_t pads[MAXCONTROLLERS]; // TODO: figure out what's going on here. + /* 0x0428 */ OSContPad n64_pads[MAXCONTROLLERS]; /* Converted from PADStatus via JUTGamePad */ + /* 0x0440 */ u8 num_controllers; + /* 0x0441 */ u8 device_type[4]; + /* 0x0445 */ u8 pak_type[4]; + /* 0x044A */ Rumble_t rumble; } padmgr; extern padmgr padmgr_class; @@ -70,38 +70,40 @@ extern void padmgr_force_stop_OFF(); extern void padmgr_RumbleSet(int pad, int intensity); extern void padmgr_Create(OSMessageQueue* queue, OSId id, OSPri priority, void* stack, size_t stackSize); extern void padmgr_Init(OSMessageQueue* queue); +extern void padmgr_RequestPadData(pad_t* pad, int count); +extern void padmgr_ClearPadData(pad_t* pad); #define padmgr_setClient(callback_proc, param) \ -do { \ - padmgr* mgr = &padmgr_class; \ - mgr->callback = callback_proc; \ - mgr->callback_param = param; \ -} while (0) + do { \ + padmgr* mgr = &padmgr_class; \ + mgr->callback = callback_proc; \ + mgr->callback_param = param; \ + } while (0) -#define padmgr_removeClient(callback_proc, param) \ -do { \ - padmgr* mgr = &padmgr_class; \ - if (mgr->callback == (callback_proc) && mgr->callback_param == (param)) { \ - mgr->callback = NULL; \ - mgr->callback_param = NULL; \ - } \ -} while (0) +#define padmgr_removeClient(callback_proc, param) \ + do { \ + padmgr* mgr = &padmgr_class; \ + if (mgr->callback == (callback_proc) && mgr->callback_param == (param)) { \ + mgr->callback = NULL; \ + mgr->callback_param = NULL; \ + } \ + } while (0) #define padmgr_setClient2(callback, param) \ -do { \ - padmgr* mgr = &padmgr_class; \ - mgr->callback2 = callback; \ - mgr->callback2_param = param; \ -} while (0) + do { \ + padmgr* mgr = &padmgr_class; \ + mgr->callback2 = callback; \ + mgr->callback2_param = param; \ + } while (0) -#define padmgr_removeClient2(callback, param) \ -do { \ - padmgr* mgr = &padmgr_class; \ - if (mgr->callback2 == (callback) && mgr->callback2_param == (param)) { \ - mgr->callback2 = NULL; \ - mgr->callback2_param = NULL; \ - } \ -} while (0) +#define padmgr_removeClient2(callback, param) \ + do { \ + padmgr* mgr = &padmgr_class; \ + if (mgr->callback2 == (callback) && mgr->callback2_param == (param)) { \ + mgr->callback2 = NULL; \ + mgr->callback2_param = NULL; \ + } \ + } while (0) #ifdef __cplusplus } diff --git a/include/save_menu.h b/include/save_menu.h index ad990a04..2be23ce3 100644 --- a/include/save_menu.h +++ b/include/save_menu.h @@ -10,35 +10,36 @@ extern "C" { #endif enum save_mode { - SAVE_MODE_BEGIN, + SAVE_MODE_BEGIN, - SAVE_MODE_FLASHROM = SAVE_MODE_BEGIN, - SAVE_MODE_CPAK, + SAVE_MODE_FLASHROM = SAVE_MODE_BEGIN, + SAVE_MODE_CPAK, - SAVE_MODE_NUM + SAVE_MODE_NUM }; enum save_error { - SAVE_ERROR_NONE, - SAVE_ERROR_FLASHROM, - SAVE_ERROR_CPAK, - SAVE_ERROR_EXIT, + SAVE_ERROR_NONE, + SAVE_ERROR_FLASHROM, + SAVE_ERROR_CPAK, + SAVE_ERROR_EXIT, - SAVE_ERROR_NUM + SAVE_ERROR_NUM }; /* sizeof(struct game_save_menu_s) == 0x0228 */ typedef struct game_save_menu_s { - /* 0x0000 */ GAME game; - /* 0x00E0 */ View view; - /* 0x0200 */ u32 frame; - /* 0x0204 */ int mode; - /* 0x0208 */ int error; - /* 0x020C */ int cursor_col[SAVE_MODE_NUM][3]; + /* 0x0000 */ GAME game; + /* 0x00E0 */ View view; + /* 0x0200 */ u32 frame; + /* 0x0204 */ int mode; + /* 0x0208 */ int error; + /* 0x020C */ int cursor_col[SAVE_MODE_NUM][3]; } GAME_SAVE_MENU; -extern void save_menu_init(GAME* game); +extern void save_menu_draw_main(GAME_SAVE_MENU* save_menu); extern void save_menu_cleanup(GAME* game); +extern void save_menu_init(GAME* game); #ifdef __cplusplus } diff --git a/src/ac_airplane.c b/src/ac_airplane.c index 7c174ba4..c9d8f5e3 100644 --- a/src/ac_airplane.c +++ b/src/ac_airplane.c @@ -11,252 +11,255 @@ #include "m_name_table.h" #include "m_common_data.h" #include "m_actor_shadow.h" +#include "m_rcp.h" static void Airplane_Actor_ct(ACTOR* actor, GAME* game); static void Airplane_Actor_dt(ACTOR* actor, GAME* game); static void Airplane_Actor_move(ACTOR* actor, GAME* game); static void Airplane_Actor_draw(ACTOR* actor, GAME* game); -/* TODO: ct, dt, & draw go in this TU, while all others go in a separate TU. Probably something like ac_airplane_move.c_inc */ +/* TODO: ct, dt, & draw go in this TU, while all others go in a separate TU. Probably something like + * ac_airplane_move.c_inc */ ACTOR_PROFILE Airplane_Profile = { - mAc_PROFILE_AIRPLANE, - ACTOR_PART_BG, - ACTOR_STATE_NO_MOVE_WHILE_CULLED | ACTOR_STATE_NO_DRAW_WHILE_CULLED, - ETC_AIRPLANE, - ACTOR_OBJ_BANK_AIRPLANE, - sizeof(AIRPLANE_ACTOR), - &Airplane_Actor_ct, - &Airplane_Actor_dt, - &Airplane_Actor_move, - &Airplane_Actor_draw, - NULL + mAc_PROFILE_AIRPLANE, + ACTOR_PART_BG, + ACTOR_STATE_NO_MOVE_WHILE_CULLED | ACTOR_STATE_NO_DRAW_WHILE_CULLED, + ETC_AIRPLANE, + ACTOR_OBJ_BANK_AIRPLANE, + sizeof(AIRPLANE_ACTOR), + &Airplane_Actor_ct, + &Airplane_Actor_dt, + &Airplane_Actor_move, + &Airplane_Actor_draw, + NULL, }; static void Airplane_Actor_ct(ACTOR* actor, GAME* game) { - AIRPLANE_ACTOR* airplane = (AIRPLANE_ACTOR*)actor; + AIRPLANE_ACTOR* airplane = (AIRPLANE_ACTOR*)actor; - Shape_Info_init(actor, 0.0f, &mAc_ActorShadowEllipse, 6.5f, 6.5f); - airplane->status = 5; - - airplane->speed = 6.2f; - airplane->y_speed = 0.0f; - airplane->actor_class.speed = airplane->speed; - - airplane->rotY = RAD2DEG(SHORTANGLE2RAD((f32)actor->world.angle.y)); - airplane->rotY_goal = airplane->rotY; - airplane->rotY_min = airplane->rotY; - airplane->rotZ = 0.0f; - airplane->rotX = 0.0f; + Shape_Info_init(actor, 0.0f, &mAc_ActorShadowEllipse, 6.5f, 6.5f); + airplane->status = 5; - airplane->ground_timer = 0; - airplane->wind_frame = 0; - airplane->wind_change_frame = 0; - airplane->wind = NULL; + airplane->speed = 6.2f; + airplane->y_speed = 0.0f; + airplane->actor_class.speed = airplane->speed; - actor->world.position.y = mCoBG_GetBgY_AngleS_FromWpos(NULL, actor->world.position, -5.5f); + airplane->rotY = RAD2DEG(SHORTANGLE2RAD((f32)actor->world.angle.y)); + airplane->rotY_goal = airplane->rotY; + airplane->rotY_min = airplane->rotY; + airplane->rotZ = 0.0f; + airplane->rotX = 0.0f; + + airplane->ground_timer = 0; + airplane->wind_frame = 0; + airplane->wind_change_frame = 0; + airplane->wind = NULL; + + actor->world.position.y = mCoBG_GetBgY_AngleS_FromWpos(NULL, actor->world.position, -5.5f); } -static void Airplane_Actor_dt(ACTOR* actor, GAME* game) { } +static void Airplane_Actor_dt(ACTOR* actor, GAME* game) { +} extern Gfx glider_model[]; static void Airplane_Actor_draw(ACTOR* actor, GAME* game) { - AIRPLANE_ACTOR* airplane = (AIRPLANE_ACTOR*)actor; + AIRPLANE_ACTOR* airplane = (AIRPLANE_ACTOR*)actor; - if (airplane->status != aAp_STATUS_PLAYER_CATCH && airplane->status != aAp_STATUS_START_FLY_MOVE) { - GRAPH* g = game->graph; + if (airplane->status != aAp_STATUS_PLAYER_CATCH && airplane->status != aAp_STATUS_START_FLY_MOVE) { + GRAPH* g = game->graph; - _texture_z_light_fog_prim(g); - Matrix_RotateX(RAD2SHORTANGLE(DEG2RAD(airplane->rotX)), 1); - Matrix_RotateZ(RAD2SHORTANGLE(DEG2RAD(airplane->rotZ)), 1); - Matrix_scale(50.0f, 50.0f, 50.0f, 1); + _texture_z_light_fog_prim(g); + Matrix_RotateX(RAD2SHORTANGLE(DEG2RAD(airplane->rotX)), 1); + Matrix_RotateZ(RAD2SHORTANGLE(DEG2RAD(airplane->rotZ)), 1); + Matrix_scale(50.0f, 50.0f, 50.0f, 1); - OPEN_DISP(g); - gSPMatrix(NOW_POLY_OPA_DISP++, _Matrix_to_Mtx_new(game->graph), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); - gSPDisplayList(NOW_POLY_OPA_DISP++, glider_model); - CLOSE_DISP(g); - } + OPEN_DISP(g); + gSPMatrix(NOW_POLY_OPA_DISP++, _Matrix_to_Mtx_new(game->graph), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPDisplayList(NOW_POLY_OPA_DISP++, glider_model); + CLOSE_DISP(g); + } } static void aAp_RubberMove(f32* now, f32 target, f32 step) { - *now += step * (target - *now); + *now += step * (target - *now); } static void aAp_FallByWall(ACTOR* actor) { - AIRPLANE_ACTOR* airplane = (AIRPLANE_ACTOR*)actor; - if (actor->bg_collision_check.result.hit_wall == 0) { - return; - } + AIRPLANE_ACTOR* airplane = (AIRPLANE_ACTOR*)actor; + if (actor->bg_collision_check.result.hit_wall == 0) { + return; + } - airplane->status = aAp_STATUS_FALL_FLY_MOVE; + airplane->status = aAp_STATUS_FALL_FLY_MOVE; } static void aAp_GroundFriction(ACTOR* actor, GAME* game) { - AIRPLANE_ACTOR* airplane = (AIRPLANE_ACTOR*)actor; - if (actor->bg_collision_check.result.on_ground) { - /* slow down speed since we're on the ground */ - aAp_RubberMove(&airplane->speed, 0.0f, 0.6f); + AIRPLANE_ACTOR* airplane = (AIRPLANE_ACTOR*)actor; + if (actor->bg_collision_check.result.on_ground) { + /* slow down speed since we're on the ground */ + aAp_RubberMove(&airplane->speed, 0.0f, 0.6f); - if (airplane->speed < 1.0f) { - airplane->speed = 0.0f; - airplane->status = aAp_STATUS_STOP_FLY_MOVE; + if (airplane->speed < 1.0f) { + airplane->speed = 0.0f; + airplane->status = aAp_STATUS_STOP_FLY_MOVE; - if (airplane->ground_timer >= 5) { - airplane->ground_timer = 0; + if (airplane->ground_timer >= 5) { + airplane->ground_timer = 0; - (*Common_Get(clip.effect_clip)->effect_make_proc)(eEC_EFFECT_DUST, actor->world.position, 1, actor->world.angle.y, game, actor->npc_id, 0, 8); - } + (*Common_Get(clip.effect_clip)->effect_make_proc)(eEC_EFFECT_DUST, actor->world.position, 1, + actor->world.angle.y, game, actor->npc_id, 0, 8); + } - airplane->ground_timer++; + airplane->ground_timer++; + } } - } } static void aAp_FreeFlyMove(ACTOR* actor, GAME* game) { - AIRPLANE_ACTOR* airplane = (AIRPLANE_ACTOR*)actor; + AIRPLANE_ACTOR* airplane = (AIRPLANE_ACTOR*)actor; - aAp_RubberMove(&airplane->speed, 3.0f, 0.01f); - aAp_RubberMove(&airplane->rotX, 19.0f, 0.045f); - aAp_RubberMove(&airplane->rotZ, 0.0f, 0.05f); - aAp_GroundFriction(actor, game); - aAp_FallByWall(actor); + aAp_RubberMove(&airplane->speed, 3.0f, 0.01f); + aAp_RubberMove(&airplane->rotX, 19.0f, 0.045f); + aAp_RubberMove(&airplane->rotZ, 0.0f, 0.05f); + aAp_GroundFriction(actor, game); + aAp_FallByWall(actor); } static void aAp_SomerFlyMove(ACTOR* actor, GAME* game) { - AIRPLANE_ACTOR* airplane = (AIRPLANE_ACTOR*)actor; - switch (airplane->tilt_status) { - case aAp_TILT_DOWN: - { - aAp_RubberMove(&airplane->rotX, -89.0f, 0.2f); - aAp_RubberMove(&airplane->speed, 9.0f, 0.1f); + AIRPLANE_ACTOR* airplane = (AIRPLANE_ACTOR*)actor; + switch (airplane->tilt_status) { + case aAp_TILT_DOWN: { + aAp_RubberMove(&airplane->rotX, -89.0f, 0.2f); + aAp_RubberMove(&airplane->speed, 9.0f, 0.1f); - if (airplane->rotX < -87.0f) { - airplane->tilt_status = aAp_TILT_UP; - airplane->rotX = 60.0f; - } + if (airplane->rotX < -87.0f) { + airplane->tilt_status = aAp_TILT_UP; + airplane->rotX = 60.0f; + } - break; + break; + } + + case aAp_TILT_UP: { + aAp_RubberMove(&airplane->rotX, 0.0f, 0.04f); + aAp_RubberMove(&airplane->speed, 10.0f, 0.1f); + + if (ABS(airplane->rotX) < 3.0f) { + airplane->status = aAp_STATUS_FREE_FLY_MOVE; + airplane->tilt_status = aAp_TILT_DOWN; + } + + aAp_GroundFriction(actor, game); + break; + } } - case aAp_TILT_UP: - { - aAp_RubberMove(&airplane->rotX, 0.0f, 0.04f); - aAp_RubberMove(&airplane->speed, 10.0f, 0.1f); - - if (ABS(airplane->rotX) < 3.0f) { - airplane->status = aAp_STATUS_FREE_FLY_MOVE; - airplane->tilt_status = aAp_TILT_DOWN; - } - - aAp_GroundFriction(actor, game); - break; - } - } - - aAp_FallByWall(actor); + aAp_FallByWall(actor); } static int aAp_SelectFly(AIRPLANE_ACTOR* actor, int stick_y) { - int mode = (int)(fqrand() * 7.0f) & 1; - if (stick_y > 67) { - if (mode != 0) { - actor->status = aAp_STATUS_FALL_FLY_MOVE2; + int mode = (int)(fqrand() * 7.0f) & 1; + if (stick_y > 67) { + if (mode != 0) { + actor->status = aAp_STATUS_FALL_FLY_MOVE2; + } else { + actor->status = aAp_STATUS_SOMER_FLY_MOVE; + actor->tilt_status = aAp_TILT_DOWN; + } + } else { + actor->status = aAp_STATUS_FREE_FLY_MOVE; } - else { - actor->status = aAp_STATUS_SOMER_FLY_MOVE; - actor->tilt_status = aAp_TILT_DOWN; - } - } - else { - actor->status = aAp_STATUS_FREE_FLY_MOVE; - } - return TRUE; + return TRUE; } static void aAp_StartFlyMove(ACTOR* actor, GAME* game) { - static s16 goal_angle_random[8] = { 2366, 2002, -1092, -2366, 0, 4368, -4186, 4186 }; - static s16 goal_angle_random2[8] = { 12740, 8190, -9100, -8190, -10920, 10920, 9100, 0 }; + static s16 goal_angle_random[8] = { 2366, 2002, -1092, -2366, 0, 4368, -4186, 4186 }; + static s16 goal_angle_random2[8] = { 12740, 8190, -9100, -8190, -10920, 10920, 9100, 0 }; - AIRPLANE_ACTOR* airplane = (AIRPLANE_ACTOR*)actor; - int now_stick_y = getJoystick_Y(); - PLAYER_ACTOR* player = get_player_actor_withoutCheck((GAME_PLAY*)game); - int goal = fqrand() * 8.0f; - GAME_PLAY* play = (GAME_PLAY*)game; - int last_stick_y = airplane->joystick_y; - s16* goal_angle_random_tbl; + AIRPLANE_ACTOR* airplane = (AIRPLANE_ACTOR*)actor; + int now_stick_y = getJoystick_Y(); + PLAYER_ACTOR* player = get_player_actor_withoutCheck((GAME_PLAY*)game); + int goal = fqrand() * 8.0f; + GAME_PLAY* play = (GAME_PLAY*)game; + int last_stick_y = airplane->joystick_y; + s16* goal_angle_random_tbl; - if (now_stick_y - last_stick_y > 30) { - f32 stick_y = ABS((f32)last_stick_y); - int adjusted_y = ABS(last_stick_y); + if (now_stick_y - last_stick_y > 30) { + f32 stick_y = ABS((f32)last_stick_y); + int adjusted_y = ABS(last_stick_y); - airplane->speed = ABS((f32)last_stick_y) * 0.0875f + 3.0f; - aAp_SelectFly(airplane, adjusted_y); + airplane->speed = ABS((f32)last_stick_y) * 0.0875f + 3.0f; + aAp_SelectFly(airplane, adjusted_y); - goal_angle_random_tbl = adjusted_y > 50 ? goal_angle_random2 : goal_angle_random; + goal_angle_random_tbl = adjusted_y > 50 ? goal_angle_random2 : goal_angle_random; - actor->world.position.y = player->actor_class.world.position.y + 25.0f; - actor->world.position.x = player->actor_class.world.position.x; - actor->world.position.z = player->actor_class.world.position.z; + actor->world.position.y = player->actor_class.world.position.y + 25.0f; + actor->world.position.x = player->actor_class.world.position.x; + actor->world.position.z = player->actor_class.world.position.z; - airplane->rotY = RAD2DEG(SHORTANGLE2RAD(player->actor_class.shape_info.rotation.y)); - airplane->rotY_goal = airplane->rotY + (RAD2DEG(SHORTANGLE2RAD(goal_angle_random_tbl[goal]))); - airplane->rotX = airplane->speed * RAD2DEG(-0.14959965f) + 30.0f; - airplane->rotZ = 0.0f; - airplane->y_speed = 0.0f; + airplane->rotY = RAD2DEG(SHORTANGLE2RAD(player->actor_class.shape_info.rotation.y)); + airplane->rotY_goal = airplane->rotY + (RAD2DEG(SHORTANGLE2RAD(goal_angle_random_tbl[goal]))); + airplane->rotX = airplane->speed * RAD2DEG(-0.14959965f) + 30.0f; + airplane->rotZ = 0.0f; + airplane->y_speed = 0.0f; - mPlib_request_main_wait_type3((GAME*)play); - } + mPlib_request_main_wait_type3((GAME*)play); + } } -static void aAp_PlayerCatch(ACTOR* actor, GAME* game) { } +static void aAp_PlayerCatch(ACTOR* actor, GAME* game) { +} static void aAp_StopFlyMove(ACTOR* actor, GAME* game) { - AIRPLANE_ACTOR* airplane = (AIRPLANE_ACTOR*)actor; - airplane->speed = 0.0f; + AIRPLANE_ACTOR* airplane = (AIRPLANE_ACTOR*)actor; + airplane->speed = 0.0f; - if (actor->player_distance_xz <= 30.0f && chkTrigger(BUTTON_A)) { - airplane->status = aAp_STATUS_PLAYER_CATCH; // player is now "holding" the airplane - } + if (actor->player_distance_xz <= 30.0f && chkTrigger(BUTTON_A)) { + airplane->status = aAp_STATUS_PLAYER_CATCH; // player is now "holding" the airplane + } } static void aAp_FallFlyMove(ACTOR* actor, GAME* game) { - AIRPLANE_ACTOR* airplane = (AIRPLANE_ACTOR*)actor; - aAp_RubberMove(&airplane->rotX, 60.0f, 0.04f); - aAp_RubberMove(&airplane->speed, 5.0f, 0.02f); + AIRPLANE_ACTOR* airplane = (AIRPLANE_ACTOR*)actor; + aAp_RubberMove(&airplane->rotX, 60.0f, 0.04f); + aAp_RubberMove(&airplane->speed, 5.0f, 0.02f); - actor->world.position.y -= 0.15f; + actor->world.position.y -= 0.15f; - if (actor->bg_collision_check.result.on_ground) { - Common_Get(clip.effect_clip)->effect_make_proc(eEC_EFFECT_DUST, actor->world.position, 1, actor->world.angle.y, game, actor->npc_id, 0, 8); - airplane->status = aAp_STATUS_STOP_FLY_MOVE; - } + if (actor->bg_collision_check.result.on_ground) { + Common_Get(clip.effect_clip) + ->effect_make_proc(eEC_EFFECT_DUST, actor->world.position, 1, actor->world.angle.y, game, actor->npc_id, 0, + 8); + airplane->status = aAp_STATUS_STOP_FLY_MOVE; + } } static void aAp_FallFlyMove2(ACTOR* actor, GAME* game) { - AIRPLANE_ACTOR* airplane = (AIRPLANE_ACTOR*)actor; - aAp_RubberMove(&airplane->rotX, 70.0f, 0.15f); - aAp_RubberMove(&airplane->speed, 10.0f, 0.02f); + AIRPLANE_ACTOR* airplane = (AIRPLANE_ACTOR*)actor; + aAp_RubberMove(&airplane->rotX, 70.0f, 0.15f); + aAp_RubberMove(&airplane->speed, 10.0f, 0.02f); - actor->world.position.y -= 0.15f; + actor->world.position.y -= 0.15f; - if (actor->bg_collision_check.result.on_ground) { - Common_Get(clip.effect_clip)->effect_make_proc(eEC_EFFECT_DUST, actor->world.position, 1, actor->world.angle.y, game, actor->npc_id, 0, 8); - airplane->status = aAp_STATUS_STOP_FLY_MOVE; - } + if (actor->bg_collision_check.result.on_ground) { + Common_Get(clip.effect_clip) + ->effect_make_proc(eEC_EFFECT_DUST, actor->world.position, 1, actor->world.angle.y, game, actor->npc_id, 0, + 8); + airplane->status = aAp_STATUS_STOP_FLY_MOVE; + } } static void aAp_LeanAirplane(AIRPLANE_ACTOR* airplane) { - if (airplane->status == aAp_STATUS_FREE_FLY_MOVE) { - aAp_RubberMove(&airplane->rotZ, 0.0f, 0.05f); - } - else if (airplane->rotY_min - airplane->rotY > 0.0f) { - aAp_RubberMove(&airplane->rotZ, 50.0f, 0.05f); - } - else { - aAp_RubberMove(&airplane->rotZ, -50.0f, 0.05f); - } + if (airplane->status == aAp_STATUS_FREE_FLY_MOVE) { + aAp_RubberMove(&airplane->rotZ, 0.0f, 0.05f); + } else if (airplane->rotY_min - airplane->rotY > 0.0f) { + aAp_RubberMove(&airplane->rotZ, 50.0f, 0.05f); + } else { + aAp_RubberMove(&airplane->rotZ, -50.0f, 0.05f); + } } static xyz_t wind1 = { 2.0f, 1.0f, 4.0f }; @@ -266,122 +269,107 @@ static xyz_t wind4 = { -1.0f, 3.0f, -4.0f }; static xyz_t* wind_table[4] = { &wind1, &wind2, &wind3, &wind4 }; -static int wind_change_frame_table[10] = { - 300, 20, 500, 1000, 100, - 700, 20, 200, 80, 70 -}; +static int wind_change_frame_table[10] = { 300, 20, 500, 1000, 100, 700, 20, 200, 80, 70 }; static void aAp_WindSystem(ACTOR* actor, GAME* game) { - AIRPLANE_ACTOR* airplane = (AIRPLANE_ACTOR*)actor; - xyz_t dir = { 0.0f, 1.0f, 0.0f }; + AIRPLANE_ACTOR* airplane = (AIRPLANE_ACTOR*)actor; + xyz_t dir = { 0.0f, 1.0f, 0.0f }; - airplane->wind_frame++; - if (airplane->wind_frame > airplane->wind_change_frame) { - int table_rng = fqrand() * 4.0f; - int change_frame_rng = fqrand() * 10.0f; + airplane->wind_frame++; + if (airplane->wind_frame > airplane->wind_change_frame) { + int table_rng = fqrand() * 4.0f; + int change_frame_rng = fqrand() * 10.0f; - airplane->wind_frame = 0; - airplane->wind_change_frame = wind_change_frame_table[change_frame_rng]; - airplane->wind = wind_table[table_rng]; - } + airplane->wind_frame = 0; + airplane->wind_change_frame = wind_change_frame_table[change_frame_rng]; + airplane->wind = wind_table[table_rng]; + } - if (airplane->status != aAp_STATUS_STOP_FLY_MOVE && - airplane->status != aAp_STATUS_START_FLY_MOVE && - airplane->status != aAp_STATUS_PLAYER_CATCH && - airplane->wind != NULL - ) { - sMath_RotateX(&dir, DEG2RAD(airplane->rotX)); - sMath_RotateZ(&dir, DEG2RAD(airplane->rotZ)); - sMath_RotateY(&dir, DEG2RAD(airplane->rotY)); - } + if (airplane->status != aAp_STATUS_STOP_FLY_MOVE && airplane->status != aAp_STATUS_START_FLY_MOVE && + airplane->status != aAp_STATUS_PLAYER_CATCH && airplane->wind != NULL) { + sMath_RotateX(&dir, DEG2RAD(airplane->rotX)); + sMath_RotateZ(&dir, DEG2RAD(airplane->rotZ)); + sMath_RotateY(&dir, DEG2RAD(airplane->rotY)); + } } static void aAp_CommonHandle(ACTOR* actor, AIRPLANE_ACTOR* airplane, GAME* game) { - aAp_LeanAirplane(airplane); - - actor->speed = airplane->speed * cosf_table(DEG2RAD(airplane->rotX)); - airplane->y_speed = airplane->speed * sinf_table(DEG2RAD(airplane->rotX)); + aAp_LeanAirplane(airplane); - actor->world.position.y -= airplane->y_speed; - actor->world.angle.y = RAD2SHORTANGLE(DEG2RAD(airplane->rotY)); - actor->shape_info.rotation.y = RAD2SHORTANGLE(DEG2RAD(airplane->rotY)); + actor->speed = airplane->speed * cosf_table(DEG2RAD(airplane->rotX)); + airplane->y_speed = airplane->speed * sinf_table(DEG2RAD(airplane->rotX)); - Actor_position_moveF(actor); + actor->world.position.y -= airplane->y_speed; + actor->world.angle.y = RAD2SHORTANGLE(DEG2RAD(airplane->rotY)); + actor->shape_info.rotation.y = RAD2SHORTANGLE(DEG2RAD(airplane->rotY)); - airplane->joystick_x = getJoystick_X(); - airplane->joystick_y = getJoystick_Y(); + Actor_position_moveF(actor); - switch (airplane->status) { - case aAp_STATUS_START_FLY_MOVE: - case aAp_STATUS_PLAYER_CATCH: - { - actor->shape_info.draw_shadow = FALSE; - break; - } - - case aAp_STATUS_FREE_FLY_MOVE: - case aAp_STATUS_FALL_FLY_MOVE: - case aAp_STATUS_FALL_FLY_MOVE2: - case aAp_STATUS_SOMER_FLY_MOVE: - { - aAp_RubberMove(&airplane->rotY, airplane->rotY_goal, 0.07f); - actor->shape_info.draw_shadow = TRUE; - break; + airplane->joystick_x = getJoystick_X(); + airplane->joystick_y = getJoystick_Y(); + + switch (airplane->status) { + case aAp_STATUS_START_FLY_MOVE: + case aAp_STATUS_PLAYER_CATCH: { + actor->shape_info.draw_shadow = FALSE; + break; + } + + case aAp_STATUS_FREE_FLY_MOVE: + case aAp_STATUS_FALL_FLY_MOVE: + case aAp_STATUS_FALL_FLY_MOVE2: + case aAp_STATUS_SOMER_FLY_MOVE: { + aAp_RubberMove(&airplane->rotY, airplane->rotY_goal, 0.07f); + actor->shape_info.draw_shadow = TRUE; + break; + } + + default: { + actor->shape_info.draw_shadow = TRUE; + break; + } } - default: - { - actor->shape_info.draw_shadow = TRUE; - break; - } - } - - aAp_WindSystem(actor, game); + aAp_WindSystem(actor, game); } static void aAp_ZbuttonChangeStatus(AIRPLANE_ACTOR* actor, GAME* game) { - GAME_PLAY* play = (GAME_PLAY*)game; + GAME_PLAY* play = (GAME_PLAY*)game; - if (chkButton(BUTTON_Z)) { - if (actor->status == aAp_STATUS_PLAYER_CATCH) { - mPlib_request_main_refuse_type1(play); - actor->status = aAp_STATUS_START_FLY_MOVE; + if (chkButton(BUTTON_Z)) { + if (actor->status == aAp_STATUS_PLAYER_CATCH) { + mPlib_request_main_refuse_type1(play); + actor->status = aAp_STATUS_START_FLY_MOVE; + } + } else if (actor->status == aAp_STATUS_START_FLY_MOVE) { + mPlib_request_main_wait_type3((GAME*)play); + actor->status = aAp_STATUS_PLAYER_CATCH; } - } - else if (actor->status == aAp_STATUS_START_FLY_MOVE) { - mPlib_request_main_wait_type3((GAME*)play); - actor->status = aAp_STATUS_PLAYER_CATCH; - } } static f32 aAp_GetBgCheckOffsetY(s16 status) { - if (status == aAp_STATUS_FALL_FLY_MOVE || status == aAp_STATUS_STOP_FLY_MOVE) { - return -5.5f; - } + if (status == aAp_STATUS_FALL_FLY_MOVE || status == aAp_STATUS_STOP_FLY_MOVE) { + return -5.5f; + } - return 0.0f; + return 0.0f; } typedef void (*AIRPLANE_ACTOR_MOVE_PROC)(ACTOR*, GAME*); static void Airplane_Actor_move(ACTOR* actor, GAME* game) { - static AIRPLANE_ACTOR_MOVE_PROC AirplaneMove[aAp_STATUS_NUM] = { - &aAp_FreeFlyMove, - &aAp_FallFlyMove, - &aAp_FallFlyMove2, - &aAp_SomerFlyMove, - &aAp_StartFlyMove, - &aAp_StopFlyMove, - &aAp_PlayerCatch - }; + static AIRPLANE_ACTOR_MOVE_PROC AirplaneMove[aAp_STATUS_NUM] = { &aAp_FreeFlyMove, &aAp_FallFlyMove, + &aAp_FallFlyMove2, &aAp_SomerFlyMove, + &aAp_StartFlyMove, &aAp_StopFlyMove, + &aAp_PlayerCatch }; - AIRPLANE_ACTOR* airplane = (AIRPLANE_ACTOR*)actor; - f32 offset_y; + AIRPLANE_ACTOR* airplane = (AIRPLANE_ACTOR*)actor; + f32 offset_y; - airplane->rotY_min = airplane->rotY; - (*AirplaneMove[airplane->status])(actor, game); - aAp_ZbuttonChangeStatus(airplane, game); - aAp_CommonHandle(actor, airplane, game); + airplane->rotY_min = airplane->rotY; + (*AirplaneMove[airplane->status])(actor, game); + aAp_ZbuttonChangeStatus(airplane, game); + aAp_CommonHandle(actor, airplane, game); - offset_y = aAp_GetBgCheckOffsetY(airplane->status); - mCoBG_BgCheckControll(NULL, actor, 15.0f, offset_y, FALSE, FALSE, 0); + offset_y = aAp_GetBgCheckOffsetY(airplane->status); + mCoBG_BgCheckControll(NULL, actor, 15.0f, offset_y, FALSE, FALSE, 0); } diff --git a/src/ac_animal_logo_misc.c b/src/ac_animal_logo_misc.c index b9970490..64a2d1b2 100644 --- a/src/ac_animal_logo_misc.c +++ b/src/ac_animal_logo_misc.c @@ -10,112 +10,109 @@ #include "m_titledemo.h" #include "m_event.h" #include "m_scene_table.h" +#include "libultra/libultra.h" +#include "m_cpak.h" extern void flash_rom_and_player_info_clear() { - Save* save = Common_GetPointer(save); - Private_c* priv_p; - int i; + Save* save = Common_GetPointer(save); + Private_c* priv_p; + int i; - bzero(save, sizeof(Save)); - mFRm_ClearSaveCheckData(Save_GetPointer(save_check)); + bzero(save, sizeof(Save)); + mFRm_ClearSaveCheckData(Save_GetPointer(save_check)); - priv_p = Save_GetPointer(private[0]); - for (i = 0; i < PLAYER_NUM; i++) { - mPr_ClearPrivateInfo(priv_p); - priv_p++; - } + priv_p = Save_GetPointer(private[0]); + for (i = 0; i < PLAYER_NUM; i++) { + mPr_ClearPrivateInfo(priv_p); + priv_p++; + } - Save_Set(land_info.exists, TRUE); + Save_Set(land_info.exists, TRUE); } extern int decide_next_scene_no() { - int is_first_game; - int bad_save; - int next_scene_no; - - is_first_game = mFRm_CheckSaveData() == FALSE; + int is_first_game; + int bad_save; + int next_scene_no; - // this is weird, can't get it as a ternary or a switch - switch ((int)Common_Get(save_error_type)) { - case mFRm_ERROR_MEMCARD_TRAVELDATA_CONFLICT: - case mFRm_ERROR_DATA_CORRUPTED: - case mFRm_ERROR_MEMCARD_NO_FILES: - case mFRm_ERROR_MEMCARD_DAMAGED: - case mFRm_ERROR_MEMCARD_FORMAT: - case mFRm_ERROR_MEMCARD_INVALID: - case mFRm_ERROR_MEMCARD_NO_SPACE: - case mFRm_ERROR_NOT_MEMCARD: - case mFRm_ERROR_NO_MEMCARD: - { - bad_save = TRUE; - break; - } - default: - { - bad_save = FALSE; - break; - } - } + is_first_game = mFRm_CheckSaveData() == FALSE; - if (lbRTC_IsAbnormal()) { - const lbRTC_time_c* src; - - Common_Set(time.rtc_crashed, TRUE); - Common_Set(time.add_sec, 1); - - if (is_first_game == TRUE || bad_save == TRUE) { - src = &mTM_rtcTime_default_code; - } - else { - src = Save_GetPointer(save_check.time); + // this is weird, can't get it as a ternary or a switch + switch ((int)Common_Get(save_error_type)) { + case mFRm_ERROR_MEMCARD_TRAVELDATA_CONFLICT: + case mFRm_ERROR_DATA_CORRUPTED: + case mFRm_ERROR_MEMCARD_NO_FILES: + case mFRm_ERROR_MEMCARD_DAMAGED: + case mFRm_ERROR_MEMCARD_FORMAT: + case mFRm_ERROR_MEMCARD_INVALID: + case mFRm_ERROR_MEMCARD_NO_SPACE: + case mFRm_ERROR_NOT_MEMCARD: + case mFRm_ERROR_NO_MEMCARD: { + bad_save = TRUE; + break; + } + default: { + bad_save = FALSE; + break; + } } - lbRTC_TimeCopy(Common_GetPointer(newly_set_time), src); - } + if (lbRTC_IsAbnormal()) { + const lbRTC_time_c* src; - if (bad_save == TRUE || Common_Get(time.rtc_crashed) == TRUE) { - if (bad_save == TRUE) { - flash_rom_and_player_info_clear(); + Common_Set(time.rtc_crashed, TRUE); + Common_Set(time.add_sec, 1); + + if (is_first_game == TRUE || bad_save == TRUE) { + src = &mTM_rtcTime_default_code; + } else { + src = Save_GetPointer(save_check.time); + } + + lbRTC_TimeCopy(Common_GetPointer(newly_set_time), src); } - Common_Set(house_owner_name, RSV_NO); - Common_Set(last_field_id, -1); - next_scene_no = SCENE_PLAYERSELECT_3; - } - else if (is_first_game == TRUE) { - flash_rom_and_player_info_clear(); - Common_Set(house_owner_name, RSV_NO); - Common_Set(last_field_id, -1); - next_scene_no = SCENE_PLAYERSELECT; - } - else { - next_scene_no = SCENE_PLAYERSELECT_2; - } + if (bad_save == TRUE || Common_Get(time.rtc_crashed) == TRUE) { + if (bad_save == TRUE) { + flash_rom_and_player_info_clear(); + } - return next_scene_no; + Common_Set(house_owner_name, RSV_NO); + Common_Set(last_field_id, -1); + next_scene_no = SCENE_PLAYERSELECT_3; + } else if (is_first_game == TRUE) { + flash_rom_and_player_info_clear(); + Common_Set(house_owner_name, RSV_NO); + Common_Set(last_field_id, -1); + next_scene_no = SCENE_PLAYERSELECT; + } else { + next_scene_no = SCENE_PLAYERSELECT_2; + } + + return next_scene_no; } extern void title_action_data_init_start_select(GAME_PLAY* play) { - mCD_LoadLand(); - mCPk_InitPak(0); + mCD_LoadLand(); + mCPk_InitPak(0); - Common_Set(now_private, Save_GetPointer(private[0])); - Common_Set(player_no, 0); - - mTD_rtc_reserve(); - mTM_clear_renew_is(); - mNpc_ClearAnimalInfo(mNpc_GetInAnimalP()); - play->next_scene_no = decide_next_scene_no(); + Common_Set(now_private, Save_GetPointer(private[0])); + Common_Set(player_no, 0); - { - int rtc_enabled = Common_Get(time.rtc_enabled); - Common_Set(time.rtc_enabled, TRUE); - mTM_rtcTime_limit_check(); - Common_Set(time.rtc_enabled, rtc_enabled); - } + mTD_rtc_reserve(); + mTM_clear_renew_is(); + mNpc_ClearAnimalInfo(mNpc_GetInAnimalP()); + play->next_scene_no = decide_next_scene_no(); - mEv_ClearEventInfo(); - Common_Set(scene_from_title_demo, -1); - Common_Set(door_data.next_scene_id, 0); - Common_Set(submenu_disabled, TRUE); + { + int rtc_enabled = Common_Get(time.rtc_enabled); + Common_Set(time.rtc_enabled, TRUE); + mTM_rtcTime_limit_check(); + Common_Set(time.rtc_enabled, rtc_enabled); + } + + mEv_ClearEventInfo(); + Common_Set(scene_from_title_demo, -1); + Common_Set(door_data.next_scene_id, 0); + Common_Set(submenu_disabled, TRUE); } diff --git a/src/ac_aprilfool_control.c b/src/ac_aprilfool_control.c index 86609f7a..9d49344f 100644 --- a/src/ac_aprilfool_control.c +++ b/src/ac_aprilfool_control.c @@ -3,22 +3,23 @@ #include "m_event.h" #include "m_name_table.h" #include "m_common_data.h" +#include "libultra/libultra.h" static void aAPC_actor_ct(ACTOR* actor, GAME* game); static void aAPC_actor_dt(ACTOR* actor, GAME* game); ACTOR_PROFILE Aprilfool_Control_Profile = { - mAc_PROFILE_APRILFOOL_CONTROL, - ACTOR_PART_CONTROL, - ACTOR_STATE_NO_MOVE_WHILE_CULLED, - EMPTY_NO, - ACTOR_OBJ_BANK_KEEP, - sizeof(APRILFOOL_CONTROL_ACTOR), - &aAPC_actor_ct, - &aAPC_actor_dt, - mActor_NONE_PROC1, - mActor_NONE_PROC1, - NULL + mAc_PROFILE_APRILFOOL_CONTROL, + ACTOR_PART_CONTROL, + ACTOR_STATE_NO_MOVE_WHILE_CULLED, + EMPTY_NO, + ACTOR_OBJ_BANK_KEEP, + sizeof(APRILFOOL_CONTROL_ACTOR), + &aAPC_actor_ct, + &aAPC_actor_dt, + mActor_NONE_PROC1, + mActor_NONE_PROC1, + NULL, }; static int aAPC_talk_chk_proc(mActor_name_t actor_name); @@ -26,122 +27,114 @@ static void aAPC_talk_set_proc(mActor_name_t actor_name); static int aAPC_get_msg_num_proc(mActor_name_t actor_name, int update_talked); static void aAPC_actor_ct(ACTOR* actor, GAME* game) { - APRILFOOL_CONTROL_ACTOR* aprilfool_control = (APRILFOOL_CONTROL_ACTOR*)actor; - aAPC_event_save_data_c* save_data; + APRILFOOL_CONTROL_ACTOR* aprilfool_control = (APRILFOOL_CONTROL_ACTOR*)actor; + aAPC_event_save_data_c* save_data; - if (Common_Get(clip).aprilfool_control_clip == NULL) { - Common_Get(clip).aprilfool_control_clip = &aprilfool_control->clip; - } + if (Common_Get(clip).aprilfool_control_clip == NULL) { + Common_Get(clip).aprilfool_control_clip = &aprilfool_control->clip; + } - save_data = (aAPC_event_save_data_c*)mEv_get_save_area(mEv_EVENT_APRILFOOLS_DAY, 0); - if (save_data == NULL) { - save_data = (aAPC_event_save_data_c*)mEv_reserve_save_area(mEv_EVENT_APRILFOOLS_DAY, 0); - bzero(save_data, sizeof(aAPC_event_save_data_c)); - } - - Common_Get(clip).aprilfool_control_clip->talk_chk_proc = &aAPC_talk_chk_proc; - Common_Get(clip).aprilfool_control_clip->talk_set_proc = &aAPC_talk_set_proc; - Common_Get(clip).aprilfool_control_clip->get_msg_num_proc = &aAPC_get_msg_num_proc; - Common_Get(clip).aprilfool_control_clip->event_save_data_p = save_data; + save_data = (aAPC_event_save_data_c*)mEv_get_save_area(mEv_EVENT_APRILFOOLS_DAY, 0); + if (save_data == NULL) { + save_data = (aAPC_event_save_data_c*)mEv_reserve_save_area(mEv_EVENT_APRILFOOLS_DAY, 0); + bzero(save_data, sizeof(aAPC_event_save_data_c)); + } + + Common_Get(clip).aprilfool_control_clip->talk_chk_proc = &aAPC_talk_chk_proc; + Common_Get(clip).aprilfool_control_clip->talk_set_proc = &aAPC_talk_set_proc; + Common_Get(clip).aprilfool_control_clip->get_msg_num_proc = &aAPC_get_msg_num_proc; + Common_Get(clip).aprilfool_control_clip->event_save_data_p = save_data; } static void aAPC_actor_dt(ACTOR* actor, GAME* game) { - Common_Get(clip).aprilfool_control_clip = NULL; - mEv_actor_dying_message(mEv_EVENT_APRILFOOLS_DAY, actor); + Common_Get(clip).aprilfool_control_clip = NULL; + mEv_actor_dying_message(mEv_EVENT_APRILFOOLS_DAY, actor); } typedef struct aprilfool_npc_data_s { - mActor_name_t actor_name; - u16 data_idx; + mActor_name_t actor_name; + u16 data_idx; } aAPC_npc_data_c; static int aAPC_get_data_idx(mActor_name_t actor_name) { - static aAPC_npc_data_c npc_data_table[11] = { - { SP_NPC_STATION_MASTER, 0x0000 }, /* Porter */ - { SP_NPC_SHOP_MASTER, 0x0001 }, /* Tom Nook */ - { SP_NPC_CURATOR, 0x0002 }, /* Blathers */ - { SP_NPC_NEEDLEWORK0, 0x0003 }, /* Mable */ - { SP_NPC_NEEDLEWORK1, 0x0004 }, /* Sable */ - { SP_NPC_POLICE, 0x0005 }, /* Copper */ - { SP_NPC_POLICE2, 0x0006 }, /* Booker */ - { SP_NPC_POST_GIRL, 0x0007 }, /* Pelly */ - { SP_NPC_POST_GIRL2, 0x0008 }, /* Phyllis */ - { SP_NPC_POST_MAN, 0x0009 }, /* Pete */ - { SP_NPC_SENDO, 0x000A } /* Kapp'n */ - }; + static aAPC_npc_data_c npc_data_table[11] = { + { SP_NPC_STATION_MASTER, 0x0000 }, /* Porter */ + { SP_NPC_SHOP_MASTER, 0x0001 }, /* Tom Nook */ + { SP_NPC_CURATOR, 0x0002 }, /* Blathers */ + { SP_NPC_NEEDLEWORK0, 0x0003 }, /* Mable */ + { SP_NPC_NEEDLEWORK1, 0x0004 }, /* Sable */ + { SP_NPC_POLICE, 0x0005 }, /* Copper */ + { SP_NPC_POLICE2, 0x0006 }, /* Booker */ + { SP_NPC_POST_GIRL, 0x0007 }, /* Pelly */ + { SP_NPC_POST_GIRL2, 0x0008 }, /* Phyllis */ + { SP_NPC_POST_MAN, 0x0009 }, /* Pete */ + { SP_NPC_SENDO, 0x000A } /* Kapp'n */ + }; - aAPC_npc_data_c* npc_data_p = npc_data_table; - int i; - int res = -1; + aAPC_npc_data_c* npc_data_p = npc_data_table; + int i; + int res = -1; - for (i = 0; i < 11; i++) { - if (npc_data_p->actor_name == actor_name) { - res = npc_data_p->data_idx; - break; + for (i = 0; i < 11; i++) { + if (npc_data_p->actor_name == actor_name) { + res = npc_data_p->data_idx; + break; + } + + npc_data_p++; } - npc_data_p++; - } - - return res; + return res; } static int aAPC_talk_chk_proc(mActor_name_t actor_name) { - int res = TRUE; + int res = TRUE; - if (mLd_PlayerManKindCheck() == FALSE) { - int data_idx = aAPC_get_data_idx(actor_name); + if (mLd_PlayerManKindCheck() == FALSE) { + int data_idx = aAPC_get_data_idx(actor_name); - if (data_idx != -1) { - u16 bitfield = Common_Get(clip).aprilfool_control_clip->event_save_data_p->talk_bitfield[Common_Get(player_no)]; + if (data_idx != -1) { + u16 bitfield = + Common_Get(clip).aprilfool_control_clip->event_save_data_p->talk_bitfield[Common_Get(player_no)]; - if (aAPC_GET_NPC_BIT(bitfield, data_idx) == 0) { - res = FALSE; - } + if (aAPC_GET_NPC_BIT(bitfield, data_idx) == 0) { + res = FALSE; + } + } } - } - return res; + return res; } static void aAPC_talk_set_proc(mActor_name_t actor_name) { - int data_idx = aAPC_get_data_idx(actor_name); + int data_idx = aAPC_get_data_idx(actor_name); - if (data_idx != -1) { - u16* bitfield = &Common_Get(clip).aprilfool_control_clip->event_save_data_p->talk_bitfield[Common_Get(player_no)]; - data_idx = 1 << data_idx; - - bitfield[0] |= data_idx; - } + if (data_idx != -1) { + u16* bitfield = + &Common_Get(clip).aprilfool_control_clip->event_save_data_p->talk_bitfield[Common_Get(player_no)]; + data_idx = 1 << data_idx; + + bitfield[0] |= data_idx; + } } static int aAPC_get_msg_num_proc(mActor_name_t actor_name, int update_talked) { - static int msg_num_table[11] = { - 0x3BB5, - 0x3BAC, - 0x3BB0, - 0x3BB1, - 0x3BB2, - 0x3BB3, - 0x3BB4, - 0x3BAE, - 0x3BAF, - 0x3BAD, - 0x3BB6 - }; + static int msg_num_table[11] = { 0x3BB5, 0x3BAC, 0x3BB0, 0x3BB1, 0x3BB2, 0x3BB3, + 0x3BB4, 0x3BAE, 0x3BAF, 0x3BAD, 0x3BB6 }; - int data_idx = aAPC_get_data_idx(actor_name); - int msg_num = -1; + int data_idx = aAPC_get_data_idx(actor_name); + int msg_num = -1; - if (data_idx != -1) { - if (update_talked == TRUE) { - u16* bitfield = &Common_Get(clip).aprilfool_control_clip->event_save_data_p->talk_bitfield[Common_Get(player_no)]; + if (data_idx != -1) { + if (update_talked == TRUE) { + u16* bitfield = + &Common_Get(clip).aprilfool_control_clip->event_save_data_p->talk_bitfield[Common_Get(player_no)]; - bitfield[0] = aAPC_SET_NPC_BIT(bitfield[0], data_idx); + bitfield[0] = aAPC_SET_NPC_BIT(bitfield[0], data_idx); + } + + msg_num = msg_num_table[data_idx]; } - msg_num = msg_num_table[data_idx]; - } - - return msg_num; + return msg_num; } diff --git a/src/ac_ball.c b/src/ac_ball.c index eb6b8e8d..e4bfb823 100644 --- a/src/ac_ball.c +++ b/src/ac_ball.c @@ -11,6 +11,7 @@ #include "m_random_field.h" #include "m_roll_lib.h" #include "sys_matrix.h" +#include "m_collision_bg.h" extern Gfx act_ball_b_model[]; extern Gfx act_ball_d_model[]; @@ -44,15 +45,15 @@ ACTOR_PROFILE Ball_Profile = { BALL_ACTOR* Global_Actor_p; ClObjPipeData_c aBALL_CoInfoData = { - {0x39, 0x20, ClObj_TYPE_PIPE}, // collision data - {1}, // element data + { 0x39, 0x20, ClObj_TYPE_PIPE }, // collision data + { 1 }, // element data // Pipe specs { - 13, // radius - 30, // height - -10, // offset + 13, // radius + 30, // height + -10, // offset - {0, 0, 0}, // center + { 0, 0, 0 }, // center }, }; @@ -60,15 +61,15 @@ StatusData_c aBALL_StatusData = { 0, 13, 30, -10, 100, }; -void aBALL_process_ground_init(ACTOR*, GAME*); -void aBALL_process_air_water(ACTOR*, GAME*); -void aBALL_process_ground_water(ACTOR*, GAME*); -void aBALL_process_ground(ACTOR*, GAME*); -void aBALL_process_air(ACTOR*, GAME*); -void aBALL_process_air_water_init(ACTOR* actor, GAME*); -void aBALL_process_ground_water_init(ACTOR* actor, GAME*); +static void aBALL_process_ground_init(ACTOR*, GAME*); +static void aBALL_process_air_water(ACTOR*, GAME*); +static void aBALL_process_ground_water(ACTOR*, GAME*); +static void aBALL_process_ground(ACTOR*, GAME*); +static void aBALL_process_air(ACTOR*, GAME*); +static void aBALL_process_air_water_init(ACTOR* actor, GAME*); +static void aBALL_process_ground_water_init(ACTOR* actor, GAME*); -int aBALL_Random_pos_set(xyz_t* pos) { +static int aBALL_Random_pos_set(xyz_t* pos) { int x_max; int z_max; int random_x; @@ -111,7 +112,7 @@ int aBALL_Random_pos_set(xyz_t* pos) { return FALSE; } -void aBALL_actor_ct(ACTOR* actor, GAME* game) { +static void aBALL_actor_ct(ACTOR* actor, GAME* game) { BALL_ACTOR* ball = (BALL_ACTOR*)actor; GAME_PLAY* play = (GAME_PLAY*)game; @@ -157,7 +158,7 @@ void aBALL_actor_ct(ACTOR* actor, GAME* game) { ball->unk20C = 0; } -void aBALL_actor_dt(ACTOR* actor, GAME* game) { +static void aBALL_actor_dt(ACTOR* actor, GAME* game) { BALL_ACTOR* ball = (BALL_ACTOR*)actor; if ((ball->unk208 & 1) || (ball->unk208 & 2) || (mRlib_Set_Position_Check(actor) == 0)) { @@ -169,7 +170,7 @@ void aBALL_actor_dt(ACTOR* actor, GAME* game) { ClObjPipe_dt(game, &ball->ball_pipe); } -void aBALL_position_move(BALL_ACTOR* actor) { +static void aBALL_position_move(BALL_ACTOR* actor) { xyz_t pos; s_xyz angle; @@ -195,7 +196,7 @@ void aBALL_position_move(BALL_ACTOR* actor) { } } -void aBALL_BGcheck(BALL_ACTOR* actor) { +static void aBALL_BGcheck(BALL_ACTOR* actor) { f32 speed_y; s16 hit_angle; s16 rot; @@ -266,7 +267,7 @@ void aBALL_BGcheck(BALL_ACTOR* actor) { } } -void aBALL_OBJcheck(BALL_ACTOR* actor, GAME*) { +static void aBALL_OBJcheck(BALL_ACTOR* actor, GAME*) { int wade; ACTOR* collided; xyz_t pos_speed; @@ -373,14 +374,14 @@ void aBALL_OBJcheck(BALL_ACTOR* actor, GAME*) { } } -void aBALL_House_Tree_Rev_Check(BALL_ACTOR* actor) { +static void aBALL_House_Tree_Rev_Check(BALL_ACTOR* actor) { if (mRlib_HeightGapCheck_And_ReversePos(&actor->actor_class) != 1) { actor->unk208 |= 1; Actor_delete(&actor->actor_class); } } -void aBALL_process_air_init(ACTOR* actor, GAME* game) { +static void aBALL_process_air_init(ACTOR* actor, GAME* game) { BALL_ACTOR* ball = (BALL_ACTOR*)actor; f32 angle; @@ -395,7 +396,7 @@ void aBALL_process_air_init(ACTOR* actor, GAME* game) { ball->process_proc = aBALL_process_air; } -void aBALL_process_air(ACTOR* actor, GAME* game) { +static void aBALL_process_air(ACTOR* actor, GAME* game) { BALL_ACTOR* ball = (BALL_ACTOR*)actor; ball->ball_acceleration = 0.0f; @@ -414,7 +415,7 @@ void aBALL_process_air(ACTOR* actor, GAME* game) { } } -void aBALL_process_ground_init(ACTOR* actor, GAME* game) { +static void aBALL_process_ground_init(ACTOR* actor, GAME* game) { BALL_ACTOR* ball = (BALL_ACTOR*)actor; actor->shape_info.draw_shadow = 1; @@ -426,7 +427,7 @@ void aBALL_process_ground_init(ACTOR* actor, GAME* game) { } } -void aBALL_process_ground(ACTOR* actor, GAME* game) { +static void aBALL_process_ground(ACTOR* actor, GAME* game) { BALL_ACTOR* ball = (BALL_ACTOR*)actor; f32 temp; xyz_t norm; @@ -518,7 +519,7 @@ void aBALL_process_ground(ACTOR* actor, GAME* game) { } } -void aBALL_set_spd_relations_in_water(ACTOR* actor, GAME* game) { +static void aBALL_set_spd_relations_in_water(ACTOR* actor, GAME* game) { static s16 angl_add_table[] = { 0x100, 0x400, @@ -559,14 +560,14 @@ void aBALL_set_spd_relations_in_water(ACTOR* actor, GAME* game) { ball->ball_acceleration = 0.1f; } -void aBALL_process_air_water_init(ACTOR* actor, GAME*) { +static void aBALL_process_air_water_init(ACTOR* actor, GAME* game) { BALL_ACTOR* ball = (BALL_ACTOR*)actor; actor->shape_info.draw_shadow = 0; ball->process_proc = aBALL_process_air_water; } -void aBALL_process_air_water(ACTOR* actor, GAME* game) { +static void aBALL_process_air_water(ACTOR* actor, GAME* game) { BALL_ACTOR* ball = (BALL_ACTOR*)actor; GAME_PLAY* play = (GAME_PLAY*)game; f32 ball_speed; @@ -595,7 +596,7 @@ void aBALL_process_air_water(ACTOR* actor, GAME* game) { } } -void aBALL_process_ground_water_init(ACTOR* actor, GAME*) { +static void aBALL_process_ground_water_init(ACTOR* actor, GAME* game) { BALL_ACTOR* ball = (BALL_ACTOR*)actor; actor->shape_info.draw_shadow = 0; @@ -603,7 +604,7 @@ void aBALL_process_ground_water_init(ACTOR* actor, GAME*) { ball->process_proc = aBALL_process_ground_water; } -void aBALL_process_ground_water(ACTOR* actor, GAME* game) { +static void aBALL_process_ground_water(ACTOR* actor, GAME* game) { BALL_ACTOR* ball = (BALL_ACTOR*)actor; u32 currentUT; @@ -643,7 +644,7 @@ void aBALL_process_ground_water(ACTOR* actor, GAME* game) { } } -void aBALL_calc_axis(ACTOR* actor) { +static void aBALL_calc_axis(ACTOR* actor) { BALL_ACTOR* ball = (BALL_ACTOR*)actor; s16 angle; f32 speed_fact; @@ -658,7 +659,7 @@ void aBALL_calc_axis(ACTOR* actor) { mRlib_Roll_Matrix_to_s_xyz(actor, &ball->angle, angle); } -int aBALL_player_angle_distance_check(ACTOR* actor, PLAYER_ACTOR* player) { +static int aBALL_player_angle_distance_check(ACTOR* actor, PLAYER_ACTOR* player) { f32 distance; s16 angle; int abs_angle; @@ -678,7 +679,7 @@ int aBALL_player_angle_distance_check(ACTOR* actor, PLAYER_ACTOR* player) { return 0; } -void aBALL_status_check(ACTOR* actor, GAME* game) { +static void aBALL_status_check(ACTOR* actor, GAME* game) { BALL_ACTOR* ball = (BALL_ACTOR*)actor; GAME_PLAY* play = (GAME_PLAY*)game; PLAYER_ACTOR* player; @@ -731,7 +732,7 @@ void aBALL_status_check(ACTOR* actor, GAME* game) { } } -void aBALL_actor_move(ACTOR* actor, GAME* game) { +static void aBALL_actor_move(ACTOR* actor, GAME* game) { BALL_ACTOR* ball = (BALL_ACTOR*)actor; GAME_PLAY* play = (GAME_PLAY*)game; @@ -757,7 +758,7 @@ void aBALL_actor_move(ACTOR* actor, GAME* game) { aBALL_status_check(actor, game); } -void aBALL_actor_draw(ACTOR* actor, GAME* game) { +static void aBALL_actor_draw(ACTOR* actor, GAME* game) { BALL_ACTOR* ball = (BALL_ACTOR*)actor; GRAPH* graph; Gfx* gfx; diff --git a/src/ac_br_shop.c b/src/ac_br_shop.c index afe14368..86a12d72 100644 --- a/src/ac_br_shop.c +++ b/src/ac_br_shop.c @@ -3,6 +3,8 @@ #include "m_name_table.h" #include "m_player_lib.h" #include "sys_matrix.h" +#include "m_bgm.h" +#include "m_rcp.h" static void aBRS_actor_ct(ACTOR*, GAME*); static void aBRS_actor_dt(ACTOR*, GAME*); @@ -43,6 +45,7 @@ extern Gfx obj_w_yamishop_window_model[]; static void aBRS_set_bgOffset(STRUCTURE_ACTOR*, int); static void aBRS_setup_action(STRUCTURE_ACTOR* actor, int type); static void change_FGUnit(ACTOR*, int); +static int aBRS_ctrl_light(STRUCTURE_ACTOR* shop); static void aBRS_actor_ct(ACTOR* actor, GAME* game) { static cKF_Skeleton_R_c* skl[] = { @@ -90,7 +93,7 @@ static void aBRS_actor_ct(ACTOR* actor, GAME* game) { aBRS_setup_action(&shop->structure_class, action); cKF_SkeletonInfo_R_play(&shop->structure_class.keyframe); - shop->structure_class.arg0_f = aBRS_ctrl_light(actor) != 0 ? 1.0f : 0.0f; + shop->structure_class.arg0_f = aBRS_ctrl_light((STRUCTURE_ACTOR*)actor) != 0 ? 1.0f : 0.0f; } Door_data_c aBRS_br_shop_door_data = { @@ -104,7 +107,7 @@ static void aBRS_actor_dt(ACTOR* actor, GAME* game) { cKF_SkeletonInfo_R_dt(&shop->structure_class.keyframe); if (Save_Get(event_save_data.special.event.broker.used) >= 3) { - mEv_special_event_soldout(75); + mEv_special_event_soldout(mEv_EVENT_BROKER_SALE); } } diff --git a/src/ac_fallS.c b/src/ac_fallS.c index ace260b4..5da6bd69 100644 --- a/src/ac_fallS.c +++ b/src/ac_fallS.c @@ -6,6 +6,7 @@ #include "audio.h" #include "sys_math3d.h" #include "sys_matrix.h" +#include "m_rcp.h" extern Gfx obj_fallS_model[]; extern Gfx obj_fallS_rainbowT_model[]; diff --git a/src/ac_fallSESW.c b/src/ac_fallSESW.c index 1e66c038..1b5c05b8 100644 --- a/src/ac_fallSESW.c +++ b/src/ac_fallSESW.c @@ -6,12 +6,12 @@ #include "audio.h" #include "sys_math3d.h" #include "sys_matrix.h" +#include "m_rcp.h" extern Gfx obj_fallSESW_model[]; extern Gfx obj_fallSE_rainbowT_model[]; extern EVW_ANIME_DATA obj_fallSE_evw_anime; - static void aFLEW_actor_move(ACTOR* actor, GAME* game); static void aFLEW_actor_draw(ACTOR* actor, GAME* game); @@ -32,4 +32,3 @@ ACTOR_PROFILE FallSESW_Profile = { #include "../src/ac_fallSESW_move.c_inc" #include "../src/ac_fallSESW_draw.c_inc" - diff --git a/src/ac_flag.c b/src/ac_flag.c index ee334fe7..30d5a028 100644 --- a/src/ac_flag.c +++ b/src/ac_flag.c @@ -8,17 +8,20 @@ #include "m_player_lib.h" #include "m_msg.h" #include "m_debug.h" +#include "m_needlework.h" +#include "m_needlework_ovl.h" +#include "libultra/libultra.h" enum { - aFLAG_ACTION_WAIT, - aFLAG_ACTION_TALK, - aFLAG_ACTION_TALK_END, - aFLAG_ACTION_OPEN_WAIT, - aFLAG_ACTION_END_WAIT, - aFLAG_ACTION_UP, - aFLAG_ACTION_DOWN, + aFLAG_ACTION_WAIT, + aFLAG_ACTION_TALK, + aFLAG_ACTION_TALK_END, + aFLAG_ACTION_OPEN_WAIT, + aFLAG_ACTION_END_WAIT, + aFLAG_ACTION_UP, + aFLAG_ACTION_DOWN, - aFLAG_ACTION_NUM + aFLAG_ACTION_NUM }; static void aFLAG_actor_ct(ACTOR* actor, GAME* game); @@ -37,20 +40,15 @@ ACTOR_PROFILE Flag_Profile = { &aFLAG_actor_dt, &aFLAG_actor_init, &aFLAG_actor_draw, - NULL + NULL, }; static u8 aFLAG_shadow_vtx_fix_flg_table[8] = { FALSE, TRUE, TRUE, FALSE, TRUE, FALSE, FALSE, TRUE }; extern Vtx obj_frag_shadow_v[]; extern Gfx obj_frag_shadowT_model[]; -static bIT_ShadowData_c aFLAG_shadow_data = { - 8, - aFLAG_shadow_vtx_fix_flg_table, - 60.0f, - obj_frag_shadow_v, - obj_frag_shadowT_model -}; +static bIT_ShadowData_c aFLAG_shadow_data = { 8, aFLAG_shadow_vtx_fix_flg_table, 60.0f, obj_frag_shadow_v, + obj_frag_shadowT_model }; extern cKF_Skeleton_R_c cKF_bs_r_obj_s_frag; extern cKF_Skeleton_R_c cKF_bs_r_obj_w_frag; @@ -248,12 +246,17 @@ static void aFLAG_up(STRUCTURE_ACTOR* flag, GAME_PLAY* game_play) { flag->arg1_f = starting_x + (normalized_x_length * flag->arg1 * flag->arg1); } else if (flag->arg1 <= second_point_frame) { normalized_x_length = (middle_x - starting_x) / (second_point_frame * (first_point_frame - second_point_frame)); - flag->arg1_f = middle_x + (normalized_x_length * (flag->arg1 - second_point_frame) * (flag->arg1 - second_point_frame)); + flag->arg1_f = + middle_x + (normalized_x_length * (flag->arg1 - second_point_frame) * (flag->arg1 - second_point_frame)); } else if (flag->arg1 <= third_point_frame) { - normalized_x_length = (ending_x - middle_x) / ((third_point_frame - second_point_frame) * (ending_frame - second_point_frame)); - flag->arg1_f = middle_x + (normalized_x_length * (flag->arg1 - second_point_frame) * (flag->arg1 - second_point_frame)); + normalized_x_length = + (ending_x - middle_x) / ((third_point_frame - second_point_frame) * (ending_frame - second_point_frame)); + flag->arg1_f = + middle_x + (normalized_x_length * (flag->arg1 - second_point_frame) * (flag->arg1 - second_point_frame)); } else { - normalized_x_length = (ending_x - middle_x) / ((ending_frame - second_point_frame) * ((third_point_frame - second_point_frame) - (ending_frame - second_point_frame))); + normalized_x_length = + (ending_x - middle_x) / ((ending_frame - second_point_frame) * + ((third_point_frame - second_point_frame) - (ending_frame - second_point_frame))); flag->arg1_f = ending_x + (normalized_x_length * (flag->arg1 - ending_frame) * (flag->arg1 - ending_frame)); } @@ -307,7 +310,8 @@ static void aFLAG_down(STRUCTURE_ACTOR* flag, GAME_PLAY* game_play) { flag->arg1_f = ending_x + (flag->arg1 * (normalized_x_length * flag->arg1)); } else { normalized_x_length = -(x_length / (ending_frame * (midpoint_frame - ending_frame))); - flag->arg1_f = starting_x + (normalized_x_length * (flag->arg1 - ending_frame) * (flag->arg1 - ending_frame)); + flag->arg1_f = + starting_x + (normalized_x_length * (flag->arg1 - ending_frame) * (flag->arg1 - ending_frame)); } flag->arg1 += 1; @@ -320,13 +324,7 @@ static void aFLAG_down(STRUCTURE_ACTOR* flag, GAME_PLAY* game_play) { static void aFLAG_setup_action(STRUCTURE_ACTOR* flag, int action) { static aSTR_MOVE_PROC process[aFLAG_ACTION_NUM] = { - &aFLAG_wait, - &aFLAG_talk, - &aFLAG_talk_end, - &aFLAG_menu_open_wait, - &aFLAG_menu_end_wait, - &aFLAG_up, - &aFLAG_down + &aFLAG_wait, &aFLAG_talk, &aFLAG_talk_end, &aFLAG_menu_open_wait, &aFLAG_menu_end_wait, &aFLAG_up, &aFLAG_down }; flag->action_proc = process[action]; diff --git a/src/ac_kago.c b/src/ac_kago.c index 504ce8b2..1cdb8f6f 100644 --- a/src/ac_kago.c +++ b/src/ac_kago.c @@ -6,11 +6,11 @@ #include "m_collision_bg.h" #include "sys_matrix.h" #include "m_player_lib.h" +#include "m_rcp.h" -static void aKAG_actor_ct(ACTOR*,GAME*); -static void aKAG_actor_init(ACTOR*,GAME*); -static void aKAG_actor_draw(ACTOR*,GAME*); - +static void aKAG_actor_ct(ACTOR*, GAME*); +static void aKAG_actor_init(ACTOR*, GAME*); +static void aKAG_actor_draw(ACTOR*, GAME*); ACTOR_PROFILE Kago_Profile = { mAc_PROFILE_KAGO, @@ -23,34 +23,30 @@ ACTOR_PROFILE Kago_Profile = { NONE_ACTOR_PROC, &aKAG_actor_init, &aKAG_actor_draw, - NULL + NULL, }; extern Vtx obj_e_kago_shadow_v[]; extern Gfx obj_e_kago_shadow_model[]; -u8 aKAG_shadow_vtx_fix_flg_table[] = {1,0,0,1,1,0,0,1,0,1,0,0,1}; +u8 aKAG_shadow_vtx_fix_flg_table[] = { 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1 }; bIT_ShadowData_c aKAG_shadow_data = { - 13, - aKAG_shadow_vtx_fix_flg_table, - 60.0f, - obj_e_kago_shadow_v, - obj_e_kago_shadow_model, + 13, aKAG_shadow_vtx_fix_flg_table, 60.0f, obj_e_kago_shadow_v, obj_e_kago_shadow_model, }; -void aKAG_set_bgOffset(KAGO_ACTOR*, int); -void aKAG_setup_action(KAGO_ACTOR*, int); +static void aKAG_set_bgOffset(KAGO_ACTOR*, int); +static void aKAG_setup_action(KAGO_ACTOR*, int); -void aKAG_actor_ct(ACTOR* actor, GAME*){ +static void aKAG_actor_ct(ACTOR* actor, GAME* game) { KAGO_ACTOR* kago = (KAGO_ACTOR*)actor; kago->structure_class.action = actor->npc_id - SPORTSFAIR_BASKET_RED; kago->structure_class.structure_type = kago->structure_class.action + aSTR_TYPE_SPORTSFAIR_A; kago->structure_class.structure_pal = kago->structure_class.action + aSTR_PAL_KAGO_R; - aKAG_setup_action(kago,0); - aKAG_set_bgOffset(kago,1); + aKAG_setup_action(kago, 0); + aKAG_set_bgOffset(kago, 1); } #include "../src/ac_kago_move.c_inc" -#include "../src/ac_kago_draw.c_inc" \ No newline at end of file +#include "../src/ac_kago_draw.c_inc" diff --git a/src/ac_kago_move.c_inc b/src/ac_kago_move.c_inc index 13dcb676..ee26022d 100644 --- a/src/ac_kago_move.c_inc +++ b/src/ac_kago_move.c_inc @@ -1,13 +1,13 @@ -void aKAG_set_bgOffset(KAGO_ACTOR* actor, int id) { +static void aKAG_set_bgOffset(KAGO_ACTOR* actor, int id) { id = id == 0 ? 10 : 10; mCoBG_SetPlussOffset(actor->structure_class.actor_class.home.position, id, 100); } -void aKAG_wait(STRUCTURE_ACTOR* actorx, GAME_PLAY* play) { +static void aKAG_wait(STRUCTURE_ACTOR* actorx, GAME_PLAY* play) { } -void aKAG_setup_action(KAGO_ACTOR* kago, int id) { +static void aKAG_setup_action(KAGO_ACTOR* kago, int id) { static aSTR_MOVE_PROC process[] = { aKAG_wait, }; @@ -16,7 +16,7 @@ void aKAG_setup_action(KAGO_ACTOR* kago, int id) { kago->structure_class.arg0 = id; } -void aKAG_actor_move(ACTOR* actor, GAME* game) { +static void aKAG_actor_move(ACTOR* actor, GAME* game) { GAME_PLAY* play = (GAME_PLAY*)game; KAGO_ACTOR* kago = (KAGO_ACTOR*)actor; @@ -40,9 +40,9 @@ void aKAG_actor_move(ACTOR* actor, GAME* game) { } } -void aKAG_actor_init(ACTOR* actor, GAME* game) { +static void aKAG_actor_init(ACTOR* actor, GAME* game) { mFI_SetFG_common(0xF111, actor->home.position, 0); aKAG_actor_move(actor, game); actor->mv_proc = aKAG_actor_move; -} \ No newline at end of file +} diff --git a/src/ac_nameplate.c b/src/ac_nameplate.c index 381f8726..02e6329e 100644 --- a/src/ac_nameplate.c +++ b/src/ac_nameplate.c @@ -5,6 +5,7 @@ #include "m_field_info.h" #include "m_demo.h" #include "m_player_lib.h" +#include "m_msg.h" extern void aNP_actor_init(ACTOR* actor, GAME* game); @@ -34,7 +35,7 @@ static void aNP_set_talk_info(ACTOR* actor) { mDemo_Set_camera(TRUE); mPlib_Set_able_hand_all_item_in_demo(TRUE); color.r = 205; - color.g = 120; + color.g = 120; color.b = 0; color.a = 255; mDemo_Set_talk_window_color(&color); @@ -45,9 +46,9 @@ static void aNP_actor_move(ACTOR* actor, GAME_PLAY* play) { s16 player_angle; int angle; - if ((mDemo_Check(7, actor) == 0) && (mDemo_Check(8,actor) == 0)) { + if ((mDemo_Check(7, actor) == 0) && (mDemo_Check(8, actor) == 0)) { player = GET_PLAYER_ACTOR(play); - if ((player != NULL) && (player->actor_class.world.position.z >= actor->world.position.z)) { + if ((player != NULL) && (player->actor_class.world.position.z >= actor->world.position.z)) { player_angle = actor->player_angle_y; angle = (player_angle >= 0) ? player_angle : -player_angle; if (angle < 0x2000) { @@ -59,7 +60,7 @@ static void aNP_actor_move(ACTOR* actor, GAME_PLAY* play) { extern void aNP_actor_init(ACTOR* actor, GAME* game) { GAME_PLAY* play = (GAME_PLAY*)game; - + mFI_SetFG_common(DUMMY_NAMEPLATE, actor->home.position, 0); aNP_actor_move(actor, play); actor->mv_proc = (mActor_proc)(aNP_actor_move); diff --git a/src/ac_npc_rtc.c b/src/ac_npc_rtc.c index 5d01b8bf..36069570 100644 --- a/src/ac_npc_rtc.c +++ b/src/ac_npc_rtc.c @@ -7,6 +7,9 @@ #include "m_bgm.h" #include "m_soncho.h" #include "m_card.h" +#include "boot.h" +#include "m_string.h" +#include "libultra/libultra.h" extern void aNRTC_actor_ct(ACTOR*, GAME*); extern void aNRTC_actor_dt(ACTOR*, GAME*); @@ -111,4 +114,4 @@ void aNRTC_actor_draw(ACTOR* actor, GAME* game) { #include "../src/ac_npc_rtc_think.c.inc" -#include "../src/ac_npc_rtc_talk.c.inc" \ No newline at end of file +#include "../src/ac_npc_rtc_talk.c.inc" diff --git a/src/ac_npc_rtc_talk.c.inc b/src/ac_npc_rtc_talk.c.inc index b32d3a47..fb990e47 100644 --- a/src/ac_npc_rtc_talk.c.inc +++ b/src/ac_npc_rtc_talk.c.inc @@ -1,33 +1,30 @@ - -void aNRTC_set_slot_name(int slot_id, int str_no) { +static void aNRTC_set_slot_name(int slot_id, int str_no) { u8 name[mIN_ITEM_NAME_LEN]; mString_Load_StringFromRom(name, sizeof(name), 0x6CD + slot_id); - mMsg_Set_free_str(mMsg_Get_base_window_p(),str_no, name, sizeof(name)); + mMsg_Set_free_str(mMsg_Get_base_window_p(), str_no, name, sizeof(name)); } - -void aNRTC_rtc_err(NPCRTC_ACTOR* rtc, GAME_PLAY*) { +static void aNRTC_rtc_err(NPCRTC_ACTOR* rtc, GAME_PLAY* play) { int num; - - if (mMsg_Check_MainNormalContinue(mMsg_Get_base_window_p()) == 1) { + + if (mMsg_Check_MainNormalContinue(mMsg_Get_base_window_p()) == 1) { num = mChoice_Get_ChoseNum(mChoice_Get_base_window_p()); - switch (num) { - case 0: - aNRTC_change_talk_proc(rtc, 3); - break; - case 1: - rtc->unk9A8 = 1; - aNRTC_change_talk_proc(rtc, 10); - break; + switch (num) { + case 0: + aNRTC_change_talk_proc(rtc, 3); + break; + case 1: + rtc->unk9A8 = 1; + aNRTC_change_talk_proc(rtc, 10); + break; } } } - -void aNRTC_timer_open_msg_wait(NPCRTC_ACTOR* rtc, GAME_PLAY*) { +static void aNRTC_timer_open_msg_wait(NPCRTC_ACTOR* rtc, GAME_PLAY* play) { int order = mDemo_Get_OrderValue(4, 9); - + if (order == 1) { if (mMsg_Check_MainNormalContinue(mMsg_Get_base_window_p()) == 1) { mDemo_Set_OrderValue(4, 9, 0); @@ -37,30 +34,28 @@ void aNRTC_timer_open_msg_wait(NPCRTC_ACTOR* rtc, GAME_PLAY*) { } } -void aNRTC_timer_open_wait(NPCRTC_ACTOR* rtc, GAME_PLAY* play){ - Submenu* submenu = &play->submenu; +static void aNRTC_timer_open_wait(NPCRTC_ACTOR* rtc, GAME_PLAY* play) { + Submenu* submenu = &play->submenu; if (mMsg_Check_main_wait(mMsg_Get_base_window_p()) == 1) { aNRTC_change_talk_proc(rtc, 5); mSM_open_submenu(submenu, 3, 1, 0); mMsg_request_main_appear_wait_type1(mMsg_Get_base_window_p()); - } + } } - -void aNRTC_timer_close_wait(NPCRTC_ACTOR* rtc, GAME_PLAY* play) { - if (play->submenu.open_flag == FALSE) { +static void aNRTC_timer_close_wait(NPCRTC_ACTOR* rtc, GAME_PLAY* play) { + if (play->submenu.open_flag == FALSE) { if (mMsg_Check_not_series_main_wait(mMsg_Get_base_window_p()) == 1) { - mMsg_Set_ForceNext(mMsg_Get_base_window_p()); + mMsg_Set_ForceNext(mMsg_Get_base_window_p()); rtc->unk9A8 = 2; aNRTC_change_talk_proc(rtc, 0xA); } } } +static void aNRTC_delete_bf(NPCRTC_ACTOR* rtc, GAME_PLAY* play) { + int order = mDemo_Get_OrderValue(4, 9); -void aNRTC_delete_bf(NPCRTC_ACTOR* rtc, GAME_PLAY* play) { - int order = mDemo_Get_OrderValue(4, 9); - if ((mMsg_Check_MainNormalContinue(mMsg_Get_base_window_p()) == 1) && (order != 0)) { mMsg_Set_LockContinue(mMsg_Get_base_window_p()); @@ -68,8 +63,7 @@ void aNRTC_delete_bf(NPCRTC_ACTOR* rtc, GAME_PLAY* play) { } } - -void aNRTC_delete(NPCRTC_ACTOR* rtc, GAME_PLAY* play){ +static void aNRTC_delete(NPCRTC_ACTOR* rtc, GAME_PLAY* play) { mMsg_Window_c* window; int card; int card_ret; @@ -77,7 +71,7 @@ void aNRTC_delete(NPCRTC_ACTOR* rtc, GAME_PLAY* play){ window = mMsg_Get_base_window_p(); card_ret = mCD_EraseBrokenLand_bg(&card); - switch(card_ret){ + switch (card_ret) { case 0: rtc->unk9A8 = 3; mMsg_Set_continue_msg_num(window, 0x9DE); @@ -97,135 +91,138 @@ void aNRTC_delete(NPCRTC_ACTOR* rtc, GAME_PLAY* play){ rtc->unk9A8 = 1; mMsg_Set_continue_msg_num(window, 0x9DF); break; - } + } - if(card_ret != 0x19){ + if (card_ret != 0x19) { mMsg_Unset_LockContinue(window); - aNRTC_change_talk_proc(rtc,10); + aNRTC_change_talk_proc(rtc, 10); } } - -void aNRTC_format_chk(NPCRTC_ACTOR* rtc, GAME_PLAY* play) { +static void aNRTC_format_chk(NPCRTC_ACTOR* rtc, GAME_PLAY* play) { int num; - + if (mMsg_Check_MainNormalContinue(mMsg_Get_base_window_p()) == 1) { aNRTC_change_talk_proc(rtc, 0xA); num = mChoice_Get_ChoseNum(mChoice_Get_base_window_p()); - switch (num) { - case 0: - rtc->unk9A8 = 3; - break; - case 1: - rtc->unk9A8 = 2; - break; - case 2: - rtc->unk9A8 = 1; - break; - case 3: - rtc->unk9A8 = 3; - aNRTC_change_talk_proc(rtc, 9); - break; + switch (num) { + case 0: + rtc->unk9A8 = 3; + break; + case 1: + rtc->unk9A8 = 2; + break; + case 2: + rtc->unk9A8 = 1; + break; + case 3: + rtc->unk9A8 = 3; + aNRTC_change_talk_proc(rtc, 9); + break; } } } -void aNRTC_format(NPCRTC_ACTOR* rtc, GAME_PLAY* play) { +static void aNRTC_format(NPCRTC_ACTOR* rtc, GAME_PLAY* play) { int order; mMsg_Window_c* window; int card_ret; window = mMsg_Get_base_window_p(); order = mDemo_Get_OrderValue(4, 9); - switch (order) { - case 1: - mDemo_Set_OrderValue(4, 9, 2); - mMsg_Set_LockContinue(window); - break; - case 2: - card_ret = mCD_card_format_bg(Common_Get(memcard_slot)); - switch (card_ret) { - case 1: - mMsg_Set_continue_msg_num(window, 0x9E9); - mMsg_Unset_LockContinue(window); - aNRTC_change_talk_proc(rtc, 0xA); - rtc->unk9A8 = 3; - mDemo_Set_OrderValue(4, 9, 0); - break; - case -1: - mMsg_Unset_LockContinue(window); - aNRTC_change_talk_proc(rtc, 0xA); - rtc->unk9A8 = 1; - mMsg_Set_continue_msg_num(window, 0x9E7); - mDemo_Set_OrderValue(4, 9, 0); - case 0: - break; - } - break; - } -} - - -void aNRTC_break_data(NPCRTC_ACTOR* rtc, GAME_PLAY* play) { - int num; - - if (mMsg_Check_MainNormalContinue(mMsg_Get_base_window_p()) == 1) { - aNRTC_change_talk_proc(rtc, 0xA); - num = mChoice_Get_ChoseNum(mChoice_Get_base_window_p()); - switch (num) { - case 0: - rtc->unk9A8 = 3; - break; + switch (order) { case 1: - aNRTC_change_talk_proc(rtc, 6); - break; - } - } -} - -void aNRTC_break_data_2(NPCRTC_ACTOR* rtc, GAME_PLAY* play) { - int num; - - if (mMsg_Check_MainNormalContinue(mMsg_Get_base_window_p()) == 1) { - aNRTC_change_talk_proc(rtc, 0xA); - num = mChoice_Get_ChoseNum(mChoice_Get_base_window_p()); - switch (num) { - case 0: - rtc->unk9A8 = 3; - break; - case 1: - rtc->unk9A8 = 2; + mDemo_Set_OrderValue(4, 9, 2); + mMsg_Set_LockContinue(window); break; case 2: - rtc->unk9A8 = 1; + card_ret = mCD_card_format_bg(Common_Get(memcard_slot)); + switch (card_ret) { + case 1: + mMsg_Set_continue_msg_num(window, 0x9E9); + mMsg_Unset_LockContinue(window); + aNRTC_change_talk_proc(rtc, 0xA); + rtc->unk9A8 = 3; + mDemo_Set_OrderValue(4, 9, 0); + break; + case -1: + mMsg_Unset_LockContinue(window); + aNRTC_change_talk_proc(rtc, 0xA); + rtc->unk9A8 = 1; + mMsg_Set_continue_msg_num(window, 0x9E7); + mDemo_Set_OrderValue(4, 9, 0); + case 0: + break; + } break; - case 3: - rtc->unk9A8 = 4; - break; - } - } + } } +static void aNRTC_break_data(NPCRTC_ACTOR* rtc, GAME_PLAY* play) { + int num; + if (mMsg_Check_MainNormalContinue(mMsg_Get_base_window_p()) == 1) { + aNRTC_change_talk_proc(rtc, 0xA); + num = mChoice_Get_ChoseNum(mChoice_Get_base_window_p()); + switch (num) { + case 0: + rtc->unk9A8 = 3; + break; + case 1: + aNRTC_change_talk_proc(rtc, 6); + break; + } + } +} -void aNRTC_change_talk_proc(NPCRTC_ACTOR* rtc, int idx) { +static void aNRTC_break_data_2(NPCRTC_ACTOR* rtc, GAME_PLAY* play) { + int num; + + if (mMsg_Check_MainNormalContinue(mMsg_Get_base_window_p()) == 1) { + aNRTC_change_talk_proc(rtc, 0xA); + num = mChoice_Get_ChoseNum(mChoice_Get_base_window_p()); + switch (num) { + case 0: + rtc->unk9A8 = 3; + break; + case 1: + rtc->unk9A8 = 2; + break; + case 2: + rtc->unk9A8 = 1; + break; + case 3: + rtc->unk9A8 = 4; + break; + } + } +} + +static void aNRTC_change_talk_proc(NPCRTC_ACTOR* rtc, int idx) { static aNPCRTC_SUB_PROC process[] = { - aNRTC_break_data, aNRTC_break_data_2, aNRTC_rtc_err, aNRTC_timer_open_msg_wait, - aNRTC_timer_open_wait, aNRTC_timer_close_wait, aNRTC_delete_bf, aNRTC_delete, - aNRTC_format_chk, aNRTC_format, (aNPCRTC_SUB_PROC)none_proc1, + aNRTC_break_data, + aNRTC_break_data_2, + aNRTC_rtc_err, + aNRTC_timer_open_msg_wait, + aNRTC_timer_open_wait, + aNRTC_timer_close_wait, + aNRTC_delete_bf, + aNRTC_delete, + aNRTC_format_chk, + aNRTC_format, + (aNPCRTC_SUB_PROC)none_proc1, }; rtc->unk994 = idx; - rtc->unk99C = process[idx]; + rtc->unk99C = process[idx]; } - -void aNRTC_set_talk_info_talk_request(){ +static void aNRTC_set_talk_info_talk_request() { int msg; - - switch(Common_Get(save_error_type)){ + + switch (Common_Get(save_error_type)) { case 0: msg = 0x9CC; - break; + break; case 2: msg = 0x9D1; break; @@ -257,81 +254,77 @@ void aNRTC_set_talk_info_talk_request(){ msg = 0x9D4; break; } - mDemo_Set_msg_num(msg); + mDemo_Set_msg_num(msg); mDemo_Set_camera(1); } - -void aNRTC_talk_request(ACTOR* actor,GAME*) { +static void aNRTC_talk_request(ACTOR* actor, GAME* game) { mDemo_Request(8, actor, aNRTC_set_talk_info_talk_request); } - -int aNRTC_talk_init(ACTOR* actor, GAME* game) { +static int aNRTC_talk_init(ACTOR* actor, GAME* game) { NPCRTC_ACTOR* rtc = (NPCRTC_ACTOR*)actor; - + mDemo_Set_ListenAble(); aNRTC_set_slot_name(Common_Get(memcard_slot), mMsg_FREE_STR4); - switch (Common_Get(save_error_type)) { - case 0: - aNRTC_change_talk_proc(rtc, 2); - break; - case 2: - aNRTC_change_talk_proc(rtc, 0); - break; - case 5: - aNRTC_change_talk_proc(rtc, 8); - break; - default: - aNRTC_change_talk_proc(rtc, 1); - break; + switch (Common_Get(save_error_type)) { + case 0: + aNRTC_change_talk_proc(rtc, 2); + break; + case 2: + aNRTC_change_talk_proc(rtc, 0); + break; + case 5: + aNRTC_change_talk_proc(rtc, 8); + break; + default: + aNRTC_change_talk_proc(rtc, 1); + break; } rtc->npc_class.talk_info.talk_request_proc = mActor_NONE_PROC1; mMsg_Set_idling_req(mMsg_Get_base_window_p()); return 1; } - -int aNRTC_talk_end_chk(ACTOR* actor,GAME* game){ - NPCRTC_ACTOR* rtc = (NPCRTC_ACTOR*)actor; - GAME_PLAY* play = (GAME_PLAY*)game; - int res = 0; - mMsg_Window_c* window; +static int aNRTC_talk_end_chk(ACTOR* actor, GAME* game) { + NPCRTC_ACTOR* rtc = (NPCRTC_ACTOR*)actor; + GAME_PLAY* play = (GAME_PLAY*)game; + int res = 0; + mMsg_Window_c* window; window = mMsg_Get_base_window_p(); - rtc->unk99C(rtc,play); - - if(mMsg_Check_idling_now(window) == 1){ + rtc->unk99C(rtc, play); + + if (mMsg_Check_idling_now(window) == 1) { mMsg_request_main_disappear_wait_type1(window); - aNRTC_think_init_proc(&rtc->npc_class,play); - rtc->unk9A0 = 0; + aNRTC_think_init_proc(&rtc->npc_class, play); + rtc->unk9A0 = 0; res = 1; - rtc->unk9B4 = 0x32; - rtc->unk9B0 = 0x4B; - bzero(&play->fade_color_value, sizeof(rgba8888_t)); - } - else{ - int unk9AC; + rtc->unk9B4 = 0x32; + rtc->unk9B0 = 0x4B; + bzero(&play->fade_color_value, sizeof(rgba8888_t)); + } else { + int unk9AC; unk9AC = rtc->unk9AC; - if ((mMsg_Check_MainNormal(mMsg_Get_base_window_p()) == 1) || (((mChoice_check_main_normal(mChoice_Get_base_window_p()) == 1) != 0))) { + if ((mMsg_Check_MainNormal(mMsg_Get_base_window_p()) == 1) || + (((mChoice_check_main_normal(mChoice_Get_base_window_p()) == 1) != 0))) { unk9AC++; if (unk9AC > 0x258) { unk9AC = 0x258; } } else { unk9AC = 0; - } + } if (mDemo_Get_OrderValue(4, 0) == 0) { - if (unk9AC >= 0x258) { - if ( rtc->npc_class.draw.animation_id != 0x76) { + if (unk9AC >= 0x258) { + if (rtc->npc_class.draw.animation_id != 0x76) { mDemo_Set_OrderValue(4, 0, 0xFF); } } else if (rtc->npc_class.draw.animation_id == 0x76) { mDemo_Set_OrderValue(4, 0, 0xFD); } } - rtc->unk9AC = unk9AC; + rtc->unk9AC = unk9AC; } return res; } - diff --git a/src/ac_npc_rtc_think.c.inc b/src/ac_npc_rtc_think.c.inc index 6c75d8c2..0a879161 100644 --- a/src/ac_npc_rtc_think.c.inc +++ b/src/ac_npc_rtc_think.c.inc @@ -1,116 +1,101 @@ -void aNRTC_talk_request(ACTOR* actor,GAME*); +static void aNRTC_talk_request(ACTOR* actor, GAME*); -void aNRTC_think_start(NPC_ACTOR* actor, GAME_PLAY* play){ +static void aNRTC_think_start(NPC_ACTOR* actor, GAME_PLAY* play) { NPCRTC_ACTOR* rtc = (NPCRTC_ACTOR*)actor; - if(rtc->unk9B8 > 0){ + if (rtc->unk9B8 > 0) { rtc->unk9B8--; - } - else{ + } else { rtc->unk9A0 = 1; rtc->npc_class.talk_info.talk_request_proc = aNRTC_talk_request; rtc->npc_class.condition_info.demo_flg = 0x100; } } -void aNRTC_think_title(NPC_ACTOR* actor, GAME_PLAY* play){ +static void aNRTC_think_title(NPC_ACTOR* actor, GAME_PLAY* play) { NPCRTC_ACTOR* rtc = (NPCRTC_ACTOR*)actor; - + play->fb_wipe_type = 3; play->fb_fade_type = 4; mPlib_request_main_invade_type1(play); Actor_info_save_actor(play); - rtc->unk9A8 = 5; + rtc->unk9A8 = 5; } -Door_data_c door_data = { - SCENE_PLAYERSELECT, - 4, - FALSE, - 0, - {100,0,120}, - EMPTY_NO, - 3, - {0,0,0} -}; -void aNRTC_think_door(NPC_ACTOR* actor, GAME_PLAY* play) { - +Door_data_c door_data = { SCENE_PLAYERSELECT, 4, FALSE, 0, { 100, 0, 120 }, EMPTY_NO, 3, { 0, 0, 0 } }; + +static void aNRTC_think_door(NPC_ACTOR* actor, GAME_PLAY* play) { + if (sAdo_BgmFadeoutCheck() != 0) { goto_other_scene(play, &door_data, 1); - Common_Set(transition.wipe_type,3); + Common_Set(transition.wipe_type, 3); } } -void aNRTC_think_check(NPC_ACTOR* actor, GAME_PLAY* play){ +static void aNRTC_think_check(NPC_ACTOR* actor, GAME_PLAY* play) { NPCRTC_ACTOR* rtc = (NPCRTC_ACTOR*)actor; if (sAdo_BgmFadeoutCheck() != 0) { goto_other_scene(play, &door_data, 1); mCD_ReCheckLoadLand(play); - Common_Set(transition.wipe_type,3); + Common_Set(transition.wipe_type, 3); rtc->unk9A8 = 5; } } -void aNRTC_think_ipmenu(NPC_ACTOR* actor, GAME_PLAY* play) { +static void aNRTC_think_ipmenu(NPC_ACTOR* actor, GAME_PLAY* play) { NPCRTC_ACTOR* rtc = (NPCRTC_ACTOR*)actor; if (sAdo_BgmFadeoutCheck() != 0) { HotResetIplMenu(); rtc->unk9A8 = 5; - } + } } - aNPC_SUB_PROC aNRTC_proc_table[] = { - aNRTC_think_start, - aNRTC_think_title, - aNRTC_think_door, - aNRTC_think_check, - aNRTC_think_ipmenu, - (aNPC_SUB_PROC)mActor_NONE_PROC1, + aNRTC_think_start, aNRTC_think_title, aNRTC_think_door, + aNRTC_think_check, aNRTC_think_ipmenu, (aNPC_SUB_PROC)mActor_NONE_PROC1, }; -void aNRTC_think_main_proc(NPC_ACTOR* actor, GAME_PLAY* play){ +static void aNRTC_think_main_proc(NPC_ACTOR* actor, GAME_PLAY* play) { NPCRTC_ACTOR* rtc = (NPCRTC_ACTOR*)actor; - if(rtc->unk9B0 > 0){ + if (rtc->unk9B0 > 0) { rtc->unk9B0--; - if(rtc->unk9B0 == 0){ - play->fade_color_value.c.a = -1; - } - else if(rtc->unk9B0 < 25){ - play->fade_color_value.c.a = 255.0f * (1.0f - (0.04f * rtc->unk9B0)); + if (rtc->unk9B0 == 0) { + play->fade_color_value.c.a = -1; + } else if (rtc->unk9B0 < 25) { + play->fade_color_value.c.a = 255.0f * (1.0f - (0.04f * rtc->unk9B0)); } + } else if (rtc->unk9A0 == 0) { + aNRTC_proc_table[rtc->unk9A8](actor, play); } - else if(rtc->unk9A0 == 0){ - aNRTC_proc_table[rtc->unk9A8](actor,play); - } - if(rtc->unk9B4 == 0){ - if(rtc->unk9A8 == 1){ + if (rtc->unk9B4 == 0) { + if (rtc->unk9A8 == 1) { mBGMPsComp_make_ps_wipe(0x21C2); } else { mBGMPsComp_make_ps_wipe(0x621C); - } + } rtc->unk9B4 = -2; - } - else if(rtc->unk9B4 > 0){ + } else if (rtc->unk9B4 > 0) { rtc->unk9B4--; } } -void aNRTC_think_init_proc(NPC_ACTOR* actor, GAME_PLAY* play){ +static void aNRTC_think_init_proc(NPC_ACTOR* actor, GAME_PLAY* play) { NPCRTC_ACTOR* rtc = (NPCRTC_ACTOR*)actor; rtc->npc_class.request.act_priority = 4; rtc->npc_class.request.act_idx = 8; rtc->npc_class.request.act_type = 0; } -void aNRTC_think_proc(NPC_ACTOR* actor, GAME_PLAY* play,int idx){ - static aNPC_SUB_PROC think_proc[] = { aNRTC_think_init_proc, aNRTC_think_main_proc,}; +static void aNRTC_think_proc(NPC_ACTOR* actor, GAME_PLAY* play, int idx) { + static aNPC_SUB_PROC think_proc[] = { + aNRTC_think_init_proc, + aNRTC_think_main_proc, + }; - think_proc[idx](actor,play); + think_proc[idx](actor, play); } - -void aNRTC_schedule_init_proc(NPC_ACTOR* actor, GAME_PLAY* play){ +static void aNRTC_schedule_init_proc(NPC_ACTOR* actor, GAME_PLAY* play) { NPCRTC_ACTOR* rtc = (NPCRTC_ACTOR*)actor; rtc->npc_class.draw._5BE = 1; rtc->npc_class.talk_info.default_animation = 0x76; @@ -118,20 +103,19 @@ void aNRTC_schedule_init_proc(NPC_ACTOR* actor, GAME_PLAY* play){ rtc->unk9B0 = 0; rtc->unk9B8 = 0x5A; rtc->npc_class.think.think_proc = aNRTC_think_proc; - rtc->unk9A8 = 0; - Common_Get(clip.npc_clip)->think_proc(actor,play,6,0); + rtc->unk9A8 = 0; + Common_Get(clip.npc_clip)->think_proc(actor, play, 6, 0); } - -void aNRTC_schedule_main_proc(NPC_ACTOR* actor, GAME_PLAY* play){ + +static void aNRTC_schedule_main_proc(NPC_ACTOR* actor, GAME_PLAY* play) { NPCRTC_ACTOR* rtc = (NPCRTC_ACTOR*)actor; - if(Common_Get(clip.npc_clip)->think_proc(actor,play,-1,1) == 0){ - Common_Get(clip.npc_clip)->think_proc(actor,play,-1,2); + if (Common_Get(clip.npc_clip)->think_proc(actor, play, -1, 1) == 0) { + Common_Get(clip.npc_clip)->think_proc(actor, play, -1, 2); } } +static void aNRTC_schedule_proc(NPC_ACTOR* actor, GAME_PLAY* play, int idx) { + static aNPC_SUB_PROC sche_proc[] = { aNRTC_schedule_init_proc, aNRTC_schedule_main_proc }; -void aNRTC_schedule_proc(NPC_ACTOR* actor, GAME_PLAY* play, int idx){ - static aNPC_SUB_PROC sche_proc[] = {aNRTC_schedule_init_proc,aNRTC_schedule_main_proc}; - - sche_proc[idx](actor,play); -} + sche_proc[idx](actor, play); +} diff --git a/src/ac_psnowman.c b/src/ac_psnowman.c index e42e75d3..90f03d39 100644 --- a/src/ac_psnowman.c +++ b/src/ac_psnowman.c @@ -11,7 +11,7 @@ #include "m_snowman.h" #include "m_quest.h" #include "sys_matrix.h" - +#include "m_rcp.h" static void aPSM_actor_ct(ACTOR* actor, GAME* game); static void aPSM_actor_dt(ACTOR* actor, GAME* game); @@ -75,8 +75,8 @@ static void aPSM_actor_ct(ACTOR* actor, GAME* game) { mCoBG_SetPlussOffset(actor->home.position, 3, 100); } -static void aPSM_actor_dt(ACTOR* actor, GAME* game) { - mCoBG_SetPlussOffset(actor->home.position, 0, 100); +static void aPSM_actor_dt(ACTOR* actor, GAME* game) { + mCoBG_SetPlussOffset(actor->home.position, 0, 100); } static void aPSM_set_talk_info(ACTOR* actor) { diff --git a/src/ac_reserve.c b/src/ac_reserve.c index 38b3abe9..3f60e511 100644 --- a/src/ac_reserve.c +++ b/src/ac_reserve.c @@ -3,6 +3,9 @@ #include "m_common_data.h" #include "m_player_lib.h" #include "sys_matrix.h" +#include "m_item_name.h" +#include "m_msg.h" +#include "m_rcp.h" static void aRSV_actor_ct(ACTOR* actor, GAME* game); static void aRSV_actor_init(ACTOR* actor, GAME* game); diff --git a/src/ac_rope.c b/src/ac_rope.c index 688b8bc2..1021ec81 100644 --- a/src/ac_rope.c +++ b/src/ac_rope.c @@ -4,6 +4,7 @@ #include "m_name_table.h" #include "m_field_info.h" #include "m_event.h" +#include "sys_matrix.h" static void aRP_actor_ct(ACTOR* actor, GAME* game); static void aRP_actor_dt(ACTOR* actor, GAME* game); @@ -24,93 +25,85 @@ ACTOR_PROFILE Rope_Profile = { }; extern Vtx tol_rope_1_v[0x3C]; -extern Gfx tol_rope_1T_model[]; +extern Gfx tol_rope_1T_model[]; extern Gfx tol_rope_1_shadowT_model[]; -void aRP_actor_ct(ACTOR* actor, GAME* game){ +static void aRP_actor_ct(ACTOR* actor, GAME* game) { - xyz_t world; + xyz_t world; xyz_t pos = actor->world.position; int i; mFI_Wpos2UtCenterWpos(&world, pos); - world.x -= 40.0f; - for(i = 0; i < 3; i++){ + world.x -= 40.0f; + for (i = 0; i < 3; i++) { mCoBG_SetPlussOffset(world, 2, 100); world.x += 40.0f; } } -void aRP_actor_dt(ACTOR* actor, GAME* game){ +static void aRP_actor_dt(ACTOR* actor, GAME* game) { - xyz_t world; + xyz_t world; xyz_t pos = actor->world.position; int i; mFI_Wpos2UtCenterWpos(&world, pos); - world.x -= 40.0f; - for(i = 0; i < 3; i++){ + world.x -= 40.0f; + for (i = 0; i < 3; i++) { mCoBG_SetPlussOffset(world, 0, 100); world.x += 40.0f; } } -void aRP_make_vtx(Vtx* vtx){ +static void aRP_make_vtx(Vtx* vtx) { static u8 flg[] = { - FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, - FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, - TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, - TRUE, TRUE, TRUE, TRUE, FALSE, TRUE, TRUE, FALSE, - FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, - FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, - FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, TRUE, TRUE, - TRUE, TRUE, TRUE, TRUE + FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, + FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, TRUE, + TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, + FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, }; - + Vtx* make; int fact; u8* flag; int i; - flag = flg; fact = (*(f32*)mEv_get_save_area(0xE, 9) * 100.0f); make = tol_rope_1_v; - - for(i = 0; i < ARRAY_SIZE(tol_rope_1_v, Vtx); i++, vtx++, flag++){ + + for (i = 0; i < ARRAY_SIZE(tol_rope_1_v, Vtx); i++, vtx++, flag++) { vtx[0] = make[0]; if (flag[0] == 1) { vtx->v.ob[0] = make->v.ob[0] + fact; - } - else { + } else { vtx->v.ob[0] = make->v.ob[0]; } - + make++; - } + } } -void aRP_actor_draw(ACTOR* actor, GAME* game){ +static void aRP_actor_draw(ACTOR* actor, GAME* game) { Vtx* work; Vtx* vtx; Gfx* gfxp; Gfx* gfxp2; GRAPH* graph = game->graph; - _texture_z_light_fog_prim_npc(graph); vtx = GRAPH_ALLOC_TYPE(graph, Vtx, ARRAY_SIZE(tol_rope_1_v, Vtx)); work = vtx; - if(vtx != NULL){ + if (vtx != NULL) { aRP_make_vtx(vtx); - } - else{ + } else { work = tol_rope_1_v; } @@ -118,16 +111,15 @@ void aRP_actor_draw(ACTOR* actor, GAME* game){ gfxp = NOW_POLY_OPA_DISP; gSPMatrix(gfxp++, _Matrix_to_Mtx_new(graph), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); - gSPSegment(gfxp++, 8, work); + gSPSegment(gfxp++, 8, work); gSPDisplayList(gfxp++, tol_rope_1T_model); SET_POLY_OPA_DISP(gfxp); - - _texture_z_light_fog_prim_shadow(graph); - gfxp2 = NOW_SHADOW_DISP; + _texture_z_light_fog_prim_shadow(graph); + gfxp2 = NOW_SHADOW_DISP; gSPMatrix(gfxp2++, _Matrix_to_Mtx_new(graph), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); - gSPDisplayList(gfxp2++, tol_rope_1_shadowT_model); + gSPDisplayList(gfxp2++, tol_rope_1_shadowT_model); SET_SHADOW_DISP(gfxp2); CLOSE_DISP(graph); -} \ No newline at end of file +} diff --git a/src/ac_s_car.c b/src/ac_s_car.c index 866e553c..b951255f 100644 --- a/src/ac_s_car.c +++ b/src/ac_s_car.c @@ -6,33 +6,30 @@ #include "m_rcp.h" #include "m_common_data.h" #include "m_player_lib.h" +#include "m_event.h" static void aSCR_actor_ct(ACTOR* actor, GAME* game); static void aSCR_actor_dt(ACTOR* actor, GAME* game); static void aSCR_actor_init(ACTOR* actor, GAME* game); static void aSCR_actor_draw(ACTOR* actor, GAME* game); -ACTOR_PROFILE S_Car_Profile = { - mAc_PROFILE_S_CAR, - ACTOR_PART_ITEM, - ACTOR_STATE_TA_SET, - DESIGNER_CAR, - ACTOR_OBJ_BANK_KEEP, - sizeof(STRUCTURE_ACTOR), - &aSCR_actor_ct, - &aSCR_actor_dt, - &aSCR_actor_init, - &aSCR_actor_draw, - NULL +ACTOR_PROFILE S_Car_Profile = { + mAc_PROFILE_S_CAR, + ACTOR_PART_ITEM, + ACTOR_STATE_TA_SET, + DESIGNER_CAR, + ACTOR_OBJ_BANK_KEEP, + sizeof(STRUCTURE_ACTOR), + &aSCR_actor_ct, + &aSCR_actor_dt, + &aSCR_actor_init, + &aSCR_actor_draw, + NULL, }; -u8 aSCR_shadow_vtx_fix_flg_table0[24] = { - FALSE, FALSE, FALSE, FALSE, - FALSE, FALSE, TRUE, TRUE, - TRUE, TRUE, TRUE, TRUE, - TRUE, TRUE, TRUE, TRUE, - FALSE, FALSE, FALSE, FALSE, - FALSE, FALSE, FALSE, FALSE +u8 aSCR_shadow_vtx_fix_flg_table0[24] = { + FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, + TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, }; extern Vtx obj_car_shadow_v[]; diff --git a/src/ac_t_hanabi.c b/src/ac_t_hanabi.c index 6baaa9b3..e075efe1 100644 --- a/src/ac_t_hanabi.c +++ b/src/ac_t_hanabi.c @@ -9,90 +9,85 @@ static void aTHB_actor_dt(ACTOR* actor, GAME* game); static void aTHB_actor_move(ACTOR* actor, GAME* game); static void aTHB_actor_draw(ACTOR* actor, GAME* game); -ACTOR_PROFILE T_Hanabi_Profile = { - mAc_PROFILE_T_HANABI, - ACTOR_PART_BG, - ACTOR_STATE_NO_DRAW_WHILE_CULLED | ACTOR_STATE_NO_MOVE_WHILE_CULLED, - EMPTY_NO, - ACTOR_OBJ_BANK_HANABI, - sizeof(HANABI_ACTOR), - &aTHB_actor_ct, - &aTHB_actor_dt, - &aTHB_actor_move, - &aTHB_actor_draw, - NULL -}; +ACTOR_PROFILE T_Hanabi_Profile = { mAc_PROFILE_T_HANABI, + ACTOR_PART_BG, + ACTOR_STATE_NO_DRAW_WHILE_CULLED | ACTOR_STATE_NO_MOVE_WHILE_CULLED, + EMPTY_NO, + ACTOR_OBJ_BANK_HANABI, + sizeof(HANABI_ACTOR), + &aTHB_actor_ct, + &aTHB_actor_dt, + &aTHB_actor_move, + &aTHB_actor_draw, + NULL }; static void aTHB_setupAction(ACTOR* actor, int idx); extern Gfx main_utiwa1_model[]; -static void aTHB_actor_ct(ACTOR* actor, GAME* game){ +static void aTHB_actor_ct(ACTOR* actor, GAME* game) { aTHB_setupAction(actor, 1); } -static void aTHB_actor_dt(ACTOR* actor, GAME* game){ - +static void aTHB_actor_dt(ACTOR* actor, GAME* game) { } -static void aTHB_calc_scale(ACTOR* actor, int idx){ +static void aTHB_calc_scale(ACTOR* actor, int idx) { - static f32 aim[] = {1.0f, 0.0f}; + static f32 aim[] = { 1.0f, 0.0f }; f32 hanabi_scale = actor->scale.x; - - chase_f(&hanabi_scale, aim[idx],0.05f); + + chase_f(&hanabi_scale, aim[idx], 0.05f); actor->scale.x = hanabi_scale; actor->scale.y = hanabi_scale; actor->scale.z = hanabi_scale; - } -void aTHB_takeout(ACTOR* actor){ +static void aTHB_takeout(ACTOR* actor) { aTHB_calc_scale(actor, 0); } -void aTHB_putaway(ACTOR* actor){ +static void aTHB_putaway(ACTOR* actor) { aTHB_calc_scale(actor, 1); } -void aTHB_destruct(ACTOR* actor){ +static void aTHB_destruct(ACTOR* actor) { Actor_delete(actor); } -static void aTHB_setupAction(ACTOR* actor, int idx){ +static void aTHB_setupAction(ACTOR* actor, int idx) { HANABI_ACTOR* hanabi = (HANABI_ACTOR*)actor; - static HANABI_PROC process[] = {(HANABI_PROC)none_proc1, aTHB_takeout,aTHB_putaway,aTHB_destruct, - (HANABI_PROC)none_proc1,NULL}; - static f32 start_scale[] = {0.0f, 0.0f, 1.0f,1.0f,1.0f,0.0f,0.0f}; + static HANABI_PROC process[] = { (HANABI_PROC)none_proc1, aTHB_takeout, aTHB_putaway, aTHB_destruct, + (HANABI_PROC)none_proc1, NULL }; + static f32 start_scale[] = { 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f }; f32 scale; hanabi->proc = process[idx]; - hanabi->current_id = idx; + hanabi->current_id = idx; hanabi->tools_class.work0 = idx; scale = start_scale[idx]; hanabi->tools_class.actor_class.scale.x = scale; hanabi->tools_class.actor_class.scale.y = scale; hanabi->tools_class.actor_class.scale.z = scale; - } -static void aTHB_actor_move(ACTOR* actor, GAME* game){ +static void aTHB_actor_move(ACTOR* actor, GAME* game) { HANABI_ACTOR* hanabi = (HANABI_ACTOR*)actor; - + int t = hanabi->tools_class.work0; - if(t!= hanabi->current_id){ + if (t != hanabi->current_id) { aTHB_setupAction(actor, t); } hanabi->proc(actor); } -static void aTHB_actor_draw(ACTOR* actor, GAME* game){ +static void aTHB_actor_draw(ACTOR* actor, GAME* game) { HANABI_ACTOR* hanabi = (HANABI_ACTOR*)actor; GRAPH* graph = game->graph; @@ -100,27 +95,25 @@ static void aTHB_actor_draw(ACTOR* actor, GAME* game){ OPEN_DISP(graph); - if(hanabi->tools_class.init_matrix == 1){ + if (hanabi->tools_class.init_matrix == 1) { Matrix_put(&hanabi->tools_class.matrix_work); Matrix_Position_Zero(&hanabi->tools_class.actor_class.world.position); hanabi->tools_class.init_matrix = 0; - } - else{ - Matrix_translate(hanabi->tools_class.actor_class.world.position.x, hanabi->tools_class.actor_class.world.position.y, - hanabi->tools_class.actor_class.world.position.z, FALSE); - Matrix_scale(0.01f, 0.01f, 0.01f, TRUE); + } else { + Matrix_translate(hanabi->tools_class.actor_class.world.position.x, + hanabi->tools_class.actor_class.world.position.y, + hanabi->tools_class.actor_class.world.position.z, FALSE); + Matrix_scale(0.01f, 0.01f, 0.01f, TRUE); } - Matrix_scale(hanabi->tools_class.actor_class.scale.x, hanabi->tools_class.actor_class.scale.y, hanabi->tools_class.actor_class.scale.z, TRUE); - _texture_z_light_fog_prim_npc(graph); + Matrix_scale(hanabi->tools_class.actor_class.scale.x, hanabi->tools_class.actor_class.scale.y, + hanabi->tools_class.actor_class.scale.z, TRUE); + _texture_z_light_fog_prim_npc(graph); gfxp = NOW_POLY_OPA_DISP; - gSPMatrix(gfxp++, _Matrix_to_Mtx_new(graph),G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPMatrix(gfxp++, _Matrix_to_Mtx_new(graph), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); gSPDisplayList(gfxp++, main_utiwa1_model); SET_POLY_OPA_DISP(gfxp); CLOSE_DISP(graph); - } - - diff --git a/src/ac_t_npc_sao.c b/src/ac_t_npc_sao.c index fdcb800d..f7e09fcc 100644 --- a/src/ac_t_npc_sao.c +++ b/src/ac_t_npc_sao.c @@ -2,104 +2,99 @@ #include "m_name_table.h" #include "sys_matrix.h" +#include "m_rcp.h" static void aTNS_setupAction(ACTOR* actorx, u8 action); ACTOR_PROFILE T_NpcSao_Profile = { - mAc_PROFILE_T_NPCSAO, - ACTOR_PART_BG, - ACTOR_STATE_NO_DRAW_WHILE_CULLED | ACTOR_STATE_NO_MOVE_WHILE_CULLED, - EMPTY_NO, - ACTOR_OBJ_BANK_NPC_SAO, - sizeof(NPC_SAO_TOOL_ACTOR), - &aTNS_actor_ct, - NONE_ACTOR_PROC, - &aTNS_actor_move, - &aTNS_actor_draw, - NULL + mAc_PROFILE_T_NPCSAO, + ACTOR_PART_BG, + ACTOR_STATE_NO_DRAW_WHILE_CULLED | ACTOR_STATE_NO_MOVE_WHILE_CULLED, + EMPTY_NO, + ACTOR_OBJ_BANK_NPC_SAO, + sizeof(NPC_SAO_TOOL_ACTOR), + &aTNS_actor_ct, + NONE_ACTOR_PROC, + &aTNS_actor_move, + &aTNS_actor_draw, + NULL, }; extern void aTNS_actor_ct(ACTOR* actorx, GAME* game) { - aTNS_setupAction(actorx, 1); + aTNS_setupAction(actorx, 1); } static void aTNS_destruct(NPC_SAO_TOOL_ACTOR* npc_sao) { - Actor_delete((ACTOR*)npc_sao); + Actor_delete((ACTOR*)npc_sao); } static void aTNS_setupAction(ACTOR* actorx, u8 action) { - NPC_SAO_TOOL_ACTOR* npc_sao = (NPC_SAO_TOOL_ACTOR*)actorx; - - static aTNS_ACTION_PROC process[] = { - (aTNS_ACTION_PROC)&none_proc1, - (aTNS_ACTION_PROC)&none_proc1, - (aTNS_ACTION_PROC)&none_proc1, - &aTNS_destruct, - (aTNS_ACTION_PROC)&none_proc1, - NULL - }; + NPC_SAO_TOOL_ACTOR* npc_sao = (NPC_SAO_TOOL_ACTOR*)actorx; - npc_sao->action_proc = process[action]; - npc_sao->action = action; - npc_sao->tool_class.work0 = action; + static aTNS_ACTION_PROC process[] = { (aTNS_ACTION_PROC)&none_proc1, (aTNS_ACTION_PROC)&none_proc1, + (aTNS_ACTION_PROC)&none_proc1, &aTNS_destruct, + (aTNS_ACTION_PROC)&none_proc1, NULL }; + + npc_sao->action_proc = process[action]; + npc_sao->action = action; + npc_sao->tool_class.work0 = action; } extern void aTNS_actor_move(ACTOR* actorx, GAME* game) { - NPC_SAO_TOOL_ACTOR* npc_sao = (NPC_SAO_TOOL_ACTOR*)actorx; - s16 rotation_y; - ACTOR* parent_actor; - s16 parent_rotation_y; - int temp; - f32 pos_offset; + NPC_SAO_TOOL_ACTOR* npc_sao = (NPC_SAO_TOOL_ACTOR*)actorx; + s16 rotation_y; + ACTOR* parent_actor; + s16 parent_rotation_y; + int temp; + f32 pos_offset; - if (npc_sao->tool_class.work0 != npc_sao->action) { - aTNS_setupAction(actorx, npc_sao->tool_class.work0); - } + if (npc_sao->tool_class.work0 != npc_sao->action) { + aTNS_setupAction(actorx, npc_sao->tool_class.work0); + } - (npc_sao->action_proc)(npc_sao); - - parent_actor = actorx->parent_actor; - temp = npc_sao->rotation_y; - parent_rotation_y = parent_actor->shape_info.rotation.y; - rotation_y = temp + ((int)(fqrand() * 6.0f + 2.0f) * 256); - - npc_sao->pos_x = parent_actor->world.position.x + sin_s(parent_rotation_y) * 100.0f; - npc_sao->pos_y = parent_actor->world.position.y + -20.0f + sin_s(rotation_y) * 1.5f; - npc_sao->pos_z = parent_actor->world.position.z + cos_s(parent_rotation_y) * 100.0f; - - npc_sao->rotation_y = rotation_y; + (npc_sao->action_proc)(npc_sao); + + parent_actor = actorx->parent_actor; + temp = npc_sao->rotation_y; + parent_rotation_y = parent_actor->shape_info.rotation.y; + rotation_y = temp + ((int)(fqrand() * 6.0f + 2.0f) * 256); + + npc_sao->pos_x = parent_actor->world.position.x + sin_s(parent_rotation_y) * 100.0f; + npc_sao->pos_y = parent_actor->world.position.y + -20.0f + sin_s(rotation_y) * 1.5f; + npc_sao->pos_z = parent_actor->world.position.z + cos_s(parent_rotation_y) * 100.0f; + + npc_sao->rotation_y = rotation_y; } extern Gfx tol_npcsao_1_sao_model[]; extern Gfx tol_npcsao_1_uki_model[]; extern void aTNS_actor_draw(ACTOR* actorx, GAME* game) { - NPC_SAO_TOOL_ACTOR* npc_sao = (NPC_SAO_TOOL_ACTOR*)actorx; - GRAPH* g = game->graph; - Gfx* gfx; + NPC_SAO_TOOL_ACTOR* npc_sao = (NPC_SAO_TOOL_ACTOR*)actorx; + GRAPH* g = game->graph; + Gfx* gfx; - if (npc_sao->tool_class.init_matrix == TRUE) { - Matrix_put(&npc_sao->tool_class.matrix_work); - Matrix_Position_Zero(&actorx->world.position); - npc_sao->tool_class.init_matrix = FALSE; - } - else { - Matrix_translate(actorx->world.position.x, actorx->world.position.y, actorx->world.position.z, FALSE); - Matrix_scale(0.01f, 0.01f, 0.01f, TRUE); - } - - _texture_z_light_fog_prim_npc(g); + if (npc_sao->tool_class.init_matrix == TRUE) { + Matrix_put(&npc_sao->tool_class.matrix_work); + Matrix_Position_Zero(&actorx->world.position); + npc_sao->tool_class.init_matrix = FALSE; + } else { + Matrix_translate(actorx->world.position.x, actorx->world.position.y, actorx->world.position.z, FALSE); + Matrix_scale(0.01f, 0.01f, 0.01f, TRUE); + } - OPEN_DISP(g); - gfx = NOW_POLY_OPA_DISP; + _texture_z_light_fog_prim_npc(g); - gSPMatrix(gfx++, _Matrix_to_Mtx_new(g), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); - gSPDisplayList(gfx++, tol_npcsao_1_sao_model); - Matrix_translate(npc_sao->pos_x, npc_sao->pos_y, npc_sao->pos_z, FALSE); - Matrix_scale(0.01f, 0.01f, 0.01f, 1); - gSPMatrix(gfx++, _Matrix_to_Mtx_new(g), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); - gSPDisplayList(gfx++, tol_npcsao_1_uki_model); + OPEN_DISP(g); + gfx = NOW_POLY_OPA_DISP; - SET_POLY_OPA_DISP(gfx); - CLOSE_DISP(g); + gSPMatrix(gfx++, _Matrix_to_Mtx_new(g), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPDisplayList(gfx++, tol_npcsao_1_sao_model); + Matrix_translate(npc_sao->pos_x, npc_sao->pos_y, npc_sao->pos_z, FALSE); + Matrix_scale(0.01f, 0.01f, 0.01f, 1); + gSPMatrix(gfx++, _Matrix_to_Mtx_new(g), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPDisplayList(gfx++, tol_npcsao_1_uki_model); + + SET_POLY_OPA_DISP(gfx); + CLOSE_DISP(g); } diff --git a/src/ac_t_tumbler.c b/src/ac_t_tumbler.c index 8560ee08..31b593d8 100644 --- a/src/ac_t_tumbler.c +++ b/src/ac_t_tumbler.c @@ -2,119 +2,106 @@ #include "m_name_table.h" #include "sys_matrix.h" +#include "m_rcp.h" ACTOR_PROFILE T_Tumbler_Profile = { - mAc_PROFILE_T_TUMBLER, - ACTOR_PART_BG, - ACTOR_STATE_NO_DRAW_WHILE_CULLED | ACTOR_STATE_NO_MOVE_WHILE_CULLED, - EMPTY_NO, - ACTOR_OBJ_BANK_TUMBLER, - sizeof(TOOL_TUMBLER_ACTOR), - &aTTB_actor_ct, - NONE_ACTOR_PROC, - &aTTB_actor_move, - &aTTB_actor_draw, - NULL + mAc_PROFILE_T_TUMBLER, + ACTOR_PART_BG, + ACTOR_STATE_NO_DRAW_WHILE_CULLED | ACTOR_STATE_NO_MOVE_WHILE_CULLED, + EMPTY_NO, + ACTOR_OBJ_BANK_TUMBLER, + sizeof(TOOL_TUMBLER_ACTOR), + &aTTB_actor_ct, + NONE_ACTOR_PROC, + &aTTB_actor_move, + &aTTB_actor_draw, + NULL, }; static void aTTB_setupAction(TOOL_TUMBLER_ACTOR* tumbler_actor, int action); extern void aTTB_actor_ct(ACTOR* actorx, GAME* game) { - TOOL_TUMBLER_ACTOR* tumbler = (TOOL_TUMBLER_ACTOR*)actorx; + TOOL_TUMBLER_ACTOR* tumbler = (TOOL_TUMBLER_ACTOR*)actorx; - aTTB_setupAction(tumbler, 1); + aTTB_setupAction(tumbler, 1); } static void aTTB_calc_scale(TOOL_TUMBLER_ACTOR* tumbler_actor, int goal_idx) { - static f32 aim[] = { 1.0f, 0.0f }; + static f32 aim[] = { 1.0f, 0.0f }; - f32 scale = tumbler_actor->tools_class.actor_class.scale.x; + f32 scale = tumbler_actor->tools_class.actor_class.scale.x; - chase_f(&scale, aim[goal_idx], 0.05f); - tumbler_actor->tools_class.actor_class.scale.x = scale; - tumbler_actor->tools_class.actor_class.scale.y = scale; - tumbler_actor->tools_class.actor_class.scale.z = scale; + chase_f(&scale, aim[goal_idx], 0.05f); + tumbler_actor->tools_class.actor_class.scale.x = scale; + tumbler_actor->tools_class.actor_class.scale.y = scale; + tumbler_actor->tools_class.actor_class.scale.z = scale; } static void aTTB_takeout(TOOL_TUMBLER_ACTOR* tumbler_actor) { - aTTB_calc_scale(tumbler_actor, 0); + aTTB_calc_scale(tumbler_actor, 0); } static void aTTB_putaway(TOOL_TUMBLER_ACTOR* tumbler_actor) { - aTTB_calc_scale(tumbler_actor, 1); + aTTB_calc_scale(tumbler_actor, 1); } static void aTTB_destruct(TOOL_TUMBLER_ACTOR* tumbler_actor) { - Actor_delete((ACTOR*)tumbler_actor); + Actor_delete((ACTOR*)tumbler_actor); } static void aTTB_setupAction(TOOL_TUMBLER_ACTOR* tumbler_actor, int action) { - static aTTB_ACTION_PROC process[] = { - (aTTB_ACTION_PROC)&none_proc1, - &aTTB_takeout, - &aTTB_putaway, - &aTTB_destruct, - (aTTB_ACTION_PROC)&none_proc1, - NULL - }; + static aTTB_ACTION_PROC process[] = { (aTTB_ACTION_PROC)&none_proc1, &aTTB_takeout, &aTTB_putaway, &aTTB_destruct, + (aTTB_ACTION_PROC)&none_proc1, NULL }; - static f32 start_scale[] = { - 0.0f, - 0.0f, - 1.0f, - 1.0f, - 1.0f, - 0.0f - }; + static f32 start_scale[] = { 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f }; - f32 scale; + f32 scale; - tumbler_actor->action_proc = process[action]; - tumbler_actor->action = action; + tumbler_actor->action_proc = process[action]; + tumbler_actor->action = action; - scale = start_scale[action]; - tumbler_actor->tools_class.actor_class.scale.x = scale; - tumbler_actor->tools_class.actor_class.scale.y = scale; - tumbler_actor->tools_class.actor_class.scale.z = scale; + scale = start_scale[action]; + tumbler_actor->tools_class.actor_class.scale.x = scale; + tumbler_actor->tools_class.actor_class.scale.y = scale; + tumbler_actor->tools_class.actor_class.scale.z = scale; } extern void aTTB_actor_move(ACTOR* actorx, GAME* game) { - TOOL_TUMBLER_ACTOR* tumbler = (TOOL_TUMBLER_ACTOR*)actorx; + TOOL_TUMBLER_ACTOR* tumbler = (TOOL_TUMBLER_ACTOR*)actorx; - if (tumbler->tools_class.work0 != tumbler->action) { - aTTB_setupAction(tumbler, tumbler->tools_class.work0); - } + if (tumbler->tools_class.work0 != tumbler->action) { + aTTB_setupAction(tumbler, tumbler->tools_class.work0); + } - (*tumbler->action_proc)(tumbler); + (*tumbler->action_proc)(tumbler); } extern Gfx tol_kamicup_1T_model[]; extern void aTTB_actor_draw(ACTOR* actorx, GAME* game) { - TOOL_TUMBLER_ACTOR* tumbler = (TOOL_TUMBLER_ACTOR*)actorx; - GRAPH* graph = game->graph; + TOOL_TUMBLER_ACTOR* tumbler = (TOOL_TUMBLER_ACTOR*)actorx; + GRAPH* graph = game->graph; - Gfx* gfx; + Gfx* gfx; - if (tumbler->tools_class.init_matrix == TRUE) { - Matrix_put(&tumbler->tools_class.matrix_work); - Matrix_Position_Zero(&actorx->world.position); - tumbler->tools_class.init_matrix = FALSE; - } - else { - Matrix_translate(actorx->world.position.x, actorx->world.position.y, actorx->world.position.z, 0); - Matrix_scale(0.01f, 0.01f, 0.01f, 1); - } - - Matrix_scale(actorx->scale.x, actorx->scale.y, actorx->scale.z, 1); - _texture_z_light_fog_prim_npc(graph); + if (tumbler->tools_class.init_matrix == TRUE) { + Matrix_put(&tumbler->tools_class.matrix_work); + Matrix_Position_Zero(&actorx->world.position); + tumbler->tools_class.init_matrix = FALSE; + } else { + Matrix_translate(actorx->world.position.x, actorx->world.position.y, actorx->world.position.z, 0); + Matrix_scale(0.01f, 0.01f, 0.01f, 1); + } - OPEN_DISP(graph); - gfx = NOW_POLY_OPA_DISP; + Matrix_scale(actorx->scale.x, actorx->scale.y, actorx->scale.z, 1); + _texture_z_light_fog_prim_npc(graph); - gSPMatrix(gfx++, _Matrix_to_Mtx_new(graph), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); - gSPDisplayList(gfx++, tol_kamicup_1T_model); + OPEN_DISP(graph); + gfx = NOW_POLY_OPA_DISP; - SET_POLY_OPA_DISP(gfx); - CLOSE_DISP(graph); + gSPMatrix(gfx++, _Matrix_to_Mtx_new(graph), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPDisplayList(gfx++, tol_kamicup_1T_model); + + SET_POLY_OPA_DISP(gfx); + CLOSE_DISP(graph); } diff --git a/src/ac_tent.c b/src/ac_tent.c index 647b7937..545219eb 100644 --- a/src/ac_tent.c +++ b/src/ac_tent.c @@ -5,6 +5,8 @@ #include "m_field_info.h" #include "sys_matrix.h" #include "m_common_data.h" +#include "m_bgm.h" +#include "m_rcp.h" static void aTnt_actor_ct(ACTOR* actor, GAME* game); static void aTnt_actor_dt(ACTOR* actor, GAME* game); @@ -12,42 +14,24 @@ static void aTnt_actor_init(ACTOR* actor, GAME* game); static void aTnt_actor_draw(ACTOR* actor, GAME* game); ACTOR_PROFILE Tent_Profile = { - mAc_PROFILE_TENT, - ACTOR_PART_ITEM, - ACTOR_STATE_TA_SET, - TENT, - ACTOR_OBJ_BANK_KEEP, - sizeof(TENT_ACTOR), - aTnt_actor_ct, - aTnt_actor_dt, - aTnt_actor_init, - aTnt_actor_draw, - NULL, + mAc_PROFILE_TENT, ACTOR_PART_ITEM, ACTOR_STATE_TA_SET, TENT, ACTOR_OBJ_BANK_KEEP, sizeof(TENT_ACTOR), aTnt_actor_ct, + aTnt_actor_dt, aTnt_actor_init, aTnt_actor_draw, NULL, }; extern Vtx obj_s_tent_shadow_v[]; extern Gfx obj_s_tent_shadow_modelT[]; -u8 aTNT_shadow_vtx_fix_flg_table[] = { FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE,FALSE,TRUE,TRUE,FALSE,FALSE,TRUE,TRUE -,FALSE,FALSE,TRUE,TRUE,FALSE,FALSE,TRUE,TRUE,FALSE,FALSE,TRUE,TRUE,FALSE }; - +u8 aTNT_shadow_vtx_fix_flg_table[] = { + FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, TRUE, TRUE, FALSE, FALSE, TRUE, + TRUE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, FALSE, +}; + bIT_ShadowData_c aTnt_shadow_data = { - 28, - aTNT_shadow_vtx_fix_flg_table, - 60.0f, - obj_s_tent_shadow_v, - obj_s_tent_shadow_modelT, + 28, aTNT_shadow_vtx_fix_flg_table, 60.0f, obj_s_tent_shadow_v, obj_s_tent_shadow_modelT, }; Door_data_c aTnt_tent_enter_data = { - SCENE_TENT, - 4, - FALSE, - 0, - {120,0,220}, - EMPTY_NO, - 1, - {0,0,0}, + SCENE_TENT, 4, FALSE, 0, { 120, 0, 220 }, EMPTY_NO, 1, { 0, 0, 0 }, }; static void aTnt_ChangeFg(ACTOR* actor, int type); @@ -55,7 +39,6 @@ static void aTnt_SetupAction(ACTOR* actor, int type); static void aTnt_SetBgOffset(ACTOR* actor, int offset); static int aTnt_ControlLight(ACTOR* actor); - static void aTnt_actor_ct(ACTOR* actor, GAME* game) { TENT_ACTOR* tent = (TENT_ACTOR*)actor; f32 t; @@ -73,8 +56,8 @@ static void aTnt_actor_ct(ACTOR* actor, GAME* game) { tent->structure_class.arg0_f = t; } -static void aTnt_actor_dt(ACTOR* actor, GAME* game) { - aTnt_ChangeFg(actor, 0); +static void aTnt_actor_dt(ACTOR* actor, GAME* game) { + aTnt_ChangeFg(actor, 0); } static void aTnt_ChangeFg(ACTOR* actor, int type) { @@ -114,17 +97,11 @@ static void aTnt_ChangeFg(ACTOR* actor, int type) { static void aTnt_SetBgOffset(ACTOR* actor, int type) { static mCoBG_OffsetTable_c height_table_ct[] = { - {100, 3, 1, 1, 7, 7, 0}, - {100, 10, 10, 10, 10, 10, 0}, - {100, 3, 7, 7, 1, 1, 0}, - {100, 3, 1, 1, 7, 7, 0}, - {100, 10, 10, 10, 10, 10, 0}, - {100, 3, 7, 7, 1, 1, 0}, - {100, 3, 3, 3, 3, 3, 0}, - {100, 10, 10, 10, 10, 10, 0}, - {100, 3, 3, 3, 3, 3, 0}, + { 100, 3, 1, 1, 7, 7, 0 }, { 100, 10, 10, 10, 10, 10, 0 }, { 100, 3, 7, 7, 1, 1, 0 }, + { 100, 3, 1, 1, 7, 7, 0 }, { 100, 10, 10, 10, 10, 10, 0 }, { 100, 3, 7, 7, 1, 1, 0 }, + { 100, 3, 3, 3, 3, 3, 0 }, { 100, 10, 10, 10, 10, 10, 0 }, { 100, 3, 3, 3, 3, 3, 0 }, }; - static mCoBG_OffsetTable_c* height_table[] = {height_table_ct, height_table_ct}; + static mCoBG_OffsetTable_c* height_table[] = { height_table_ct, height_table_ct }; mCoBG_OffsetTable_c* tbl = height_table[type]; int j; int i; @@ -290,4 +267,3 @@ static void aTnt_actor_draw(ACTOR* actor, GAME* game) { CLOSE_DISP(game->graph); } } - diff --git a/src/ac_toudai.c b/src/ac_toudai.c index 94601880..f7e271e5 100644 --- a/src/ac_toudai.c +++ b/src/ac_toudai.c @@ -7,7 +7,7 @@ #include "m_player_lib.h" #include "m_common_data.h" #include "m_bgm.h" - +#include "m_soncho.h" static void aTOU_actor_ct(ACTOR*, GAME*); static void aTOU_actor_dt(ACTOR*, GAME*); @@ -31,48 +31,42 @@ ACTOR_PROFILE Toudai_Profile = { extern Vtx obj_s_toudai_shadow_v[]; extern Gfx obj_s_toudai_shadow_1_model[]; -u8 aTOU_shadow_vtx_fix_flg_table[] = {1,0,1,0, - 0,1,1,0, - 1,0,0,0,}; -bIT_ShadowData_c aTOU_shadow_data = { - 10, - aTOU_shadow_vtx_fix_flg_table, - 60.0f, - obj_s_toudai_shadow_v, - obj_s_toudai_shadow_1_model, +u8 aTOU_shadow_vtx_fix_flg_table[] = { + 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, }; +bIT_ShadowData_c aTOU_shadow_data = { + 10, aTOU_shadow_vtx_fix_flg_table, 60.0f, obj_s_toudai_shadow_v, obj_s_toudai_shadow_1_model, +}; static void aTOU_set_bgOffset(TOUDAI_ACTOR*, int); static void aTOU_setup_action(ACTOR*, int); -static void aTOU_fgunit_on(ACTOR* actor){ +static void aTOU_fgunit_on(ACTOR* actor) { TOUDAI_ACTOR* light = (TOUDAI_ACTOR*)actor; xyz_t pos; int i; mActor_name_t* nameptr; - - xyz_t_move(&pos, &light->actor_class.home.position); + + xyz_t_move(&pos, &light->actor_class.home.position); pos.x -= 40.0f; pos.z -= 80.0f; - for(i = 0; i < 2; i++){ + for (i = 0; i < 2; i++) { nameptr = mFI_GetUnitFG(pos); - if(nameptr != NULL){ - if(mSN_ClearSnowman(nameptr) == 0){ + if (nameptr != NULL) { + if (mSN_ClearSnowman(nameptr) == 0) { if (((*nameptr >= 0x2A) && (*nameptr <= 0x42)) || (*nameptr == 0x5C)) { mPB_keep_item(bg_item_fg_sub_dig2take_conv(*nameptr)); mFI_SetFG_common(RSV_NO, pos, 1); mFI_Wpos2DepositOFF(pos); - } - else{ + } else { mFI_Wpos2DepositOFF(pos); mPB_keep_item(*nameptr); mFI_SetFG_common(RSV_NO, pos, 1); } - } - else{ + } else { mFI_SetFG_common(RSV_NO, pos, 1); } } @@ -80,17 +74,17 @@ static void aTOU_fgunit_on(ACTOR* actor){ } } -static void aTOU_fgunit_off(ACTOR* actor){ +static void aTOU_fgunit_off(ACTOR* actor) { TOUDAI_ACTOR* light = (TOUDAI_ACTOR*)actor; int i; xyz_t pos; - - xyz_t_move(&pos, &light->actor_class.home.position); + + xyz_t_move(&pos, &light->actor_class.home.position); pos.x -= 40.0f; pos.z -= 80.0f; - for (i = 0; i < 2; i++){ + for (i = 0; i < 2; i++) { mFI_SetFG_common(EMPTY_NO, pos, 1); pos.x += 40.0f; } @@ -98,9 +92,9 @@ static void aTOU_fgunit_off(ACTOR* actor){ extern cKF_Skeleton_R_c cKF_bs_r_obj_s_toudai; extern cKF_Skeleton_R_c cKF_bs_r_obj_w_toudai; - -static void aTOU_actor_ct(ACTOR* actor, GAME* game){ - static cKF_Skeleton_R_c* skl[] = {&cKF_bs_r_obj_s_toudai, &cKF_bs_r_obj_w_toudai}; + +static void aTOU_actor_ct(ACTOR* actor, GAME* game) { + static cKF_Skeleton_R_c* skl[] = { &cKF_bs_r_obj_s_toudai, &cKF_bs_r_obj_w_toudai }; TOUDAI_ACTOR* light = (TOUDAI_ACTOR*)actor; light->season = Common_Get(time.season); @@ -113,14 +107,13 @@ static void aTOU_actor_ct(ACTOR* actor, GAME* game){ actor->world.position.z -= 20.0f; } -static void aTOU_actor_dt(ACTOR* actor, GAME* game){ +static void aTOU_actor_dt(ACTOR* actor, GAME* game) { TOUDAI_ACTOR* light = (TOUDAI_ACTOR*)actor; - + aTOU_fgunit_off(&light->actor_class); cKF_SkeletonInfo_R_dt(&light->keyframe); light->actor_class.world.position.x += 20.0f; light->actor_class.world.position.z += 20.0f; - } #include "../src/ac_toudai_move.c_inc" diff --git a/src/ac_train0.c b/src/ac_train0.c index 26e0e38b..f2f2cdde 100644 --- a/src/ac_train0.c +++ b/src/ac_train0.c @@ -6,6 +6,7 @@ #include "m_event.h" #include "sys_matrix.h" #include "m_play.h" +#include "m_rcp.h" static void aTR0_actor_ct(ACTOR* actor, GAME* game); static void aTR0_actor_dt(ACTOR* actor, GAME* game); @@ -23,7 +24,7 @@ ACTOR_PROFILE Train0_Profile = { &aTR0_actor_dt, &aTR0_actor_move, &aTR0_actor_draw, - NULL + NULL, }; extern cKF_Skeleton_R_c cKF_bs_r_obj_train1_1; @@ -31,19 +32,19 @@ extern cKF_Animation_R_c cKF_ba_r_obj_train1_1; extern Gfx obj_train1_2_model[]; -static void aTR0_actor_ct(ACTOR* actor, GAME* GAME){ +static void aTR0_actor_ct(ACTOR* actor, GAME* GAME) { TRAIN0_ACTOR* train0 = (TRAIN0_ACTOR*)actor; - cKF_SkeletonInfo_R_ct(&train0->keyframe, &cKF_bs_r_obj_train1_1,NULL, train0->work, train0->target); - cKF_SkeletonInfo_R_init(&train0->keyframe, train0->keyframe.skeleton, &cKF_ba_r_obj_train1_1, - 1.0f, 25.0f, 1.0f, 0.5f, 0.0f, 1, NULL); + cKF_SkeletonInfo_R_ct(&train0->keyframe, &cKF_bs_r_obj_train1_1, NULL, train0->work, train0->target); + cKF_SkeletonInfo_R_init(&train0->keyframe, train0->keyframe.skeleton, &cKF_ba_r_obj_train1_1, 1.0f, 25.0f, 1.0f, + 0.5f, 0.0f, 1, NULL); cKF_SkeletonInfo_R_play(&train0->keyframe); train0->actor_class.cull_width = 600.0f; train0->actor_class.world.angle.y = 16384; train0->tr_action = 5; } -static void aTR0_actor_dt(ACTOR* actor, GAME* game){ +static void aTR0_actor_dt(ACTOR* actor, GAME* game) { TRAIN0_ACTOR* train0 = (TRAIN0_ACTOR*)actor; @@ -53,9 +54,9 @@ static void aTR0_actor_dt(ACTOR* actor, GAME* game){ mFI_SetFG_common(0, tr_home_pos, 0); - if(train0->tr_actor_p != NULL){ + if (train0->tr_actor_p != NULL) { Actor_delete(train0->tr_actor_p); - train0->tr_actor_p = NULL; + train0->tr_actor_p = NULL; } cKF_SkeletonInfo_R_dt(&train0->keyframe); Common_Set(train_exists_flag, 0); diff --git a/src/ac_train1_move.c_inc b/src/ac_train1_move.c_inc index 1cce22c0..57a47b13 100644 --- a/src/ac_train1_move.c_inc +++ b/src/ac_train1_move.c_inc @@ -1,4 +1,4 @@ -static void aTR1_OngenTrgStart(ACTOR* actor, u16 id){ +static void aTR1_OngenTrgStart(ACTOR* actor, u16 id) { TRAIN1_ACTOR* train1 = (TRAIN1_ACTOR*)actor; sAdo_OngenTrgStart(id, &train1->actor_class.world.position); @@ -12,138 +12,132 @@ static f32 calc_speed1(ACTOR* actor0, ACTOR* actor1) { return 0.8f + train0->tr_speed; } - if (actor1->speed < train0->tr_speed){ - return train0->tr_speed + (0.5f * - (actor1->speed - train0->tr_speed)); + if (actor1->speed < train0->tr_speed) { + return train0->tr_speed + (0.5f * -(actor1->speed - train0->tr_speed)); } return train0->tr_speed; } -static f32 calc_speed2(ACTOR* actor){ +static f32 calc_speed2(ACTOR* actor) { TRAIN1_ACTOR* train1 = (TRAIN1_ACTOR*)actor; int should_stop = F32_IS_ZERO(train1->tr0_pos); - + return should_stop == FALSE ? train1->tr0_pos : -0.23f; } -static void aTR1_position_move(ACTOR* actor){ +static void aTR1_position_move(ACTOR* actor) { TRAIN1_ACTOR* train1 = (TRAIN1_ACTOR*)actor; TRAIN0_ACTOR* train0 = (TRAIN0_ACTOR*)actor->parent_actor; f32 diff; f32 tr_back_calc; f32 base_x_pos; - + tr_back_calc = train1->actor_class.world.position.x; base_x_pos = -125.0f + train0->tr1_pos; tr_back_calc += 0.5f * train1->actor_class.speed; - + diff = tr_back_calc - base_x_pos; - if((diff) <= 0.0f){ + if ((diff) <= 0.0f) { train1->actor_class.speed = calc_speed1(actor->parent_actor, actor); train1->actor_class.world.position.x = base_x_pos; - } - else if((diff) > 2.0f){ + } else if ((diff) > 2.0f) { train1->actor_class.speed = calc_speed2(actor->parent_actor); train1->actor_class.world.position.x = 2.0f + base_x_pos; - } - else{ + } else { chase_f(&train1->actor_class.speed, 0.0f, 0.0025f); train1->actor_class.world.position.x = tr_back_calc; } } -static void aTR1_chg_station_attr(int station){ +static void aTR1_chg_station_attr(int station) { static xyz_t doorway_pos = { 2180.0f, 0.0f, 820.0f }; - xyz_t soil_pos; - xyz_t unk20_pos; - if(mEv_CheckFirstIntro() == 0){ - if(station == 5){ - soil_pos = doorway_pos; - mCoBG_SetAttribute(&soil_pos, 7); - } - else if(station == 6){ - unk20_pos = doorway_pos; - mCoBG_SetAttribute(&unk20_pos, 0x20); + if (mEv_CheckFirstIntro() == 0) { + if (station == 5) { + mCoBG_SetAttribute(doorway_pos, mCoBG_ATTRIBUTE_STONE); + } else if (station == 6) { + mCoBG_SetAttribute(doorway_pos, 0x20); } } } -static void aTR1_passenger_ctrl(ACTOR* actor){ +static void aTR1_passenger_ctrl(ACTOR* actor) { TRAIN1_ACTOR* train1 = (TRAIN1_ACTOR*)actor; GAME_PLAY* play = (GAME_PLAY*)gamePT; xyz_t pos; s_xyz rot; - if(train1->player_pass_exists == 1){ + if (train1->player_pass_exists == 1) { pos.x = train1->actor_class.world.position.x + 60.0f; pos.y = train1->actor_class.world.position.y + 20.0f; pos.z = train1->actor_class.world.position.z + 20.0f; rot.x = ZeroSVec.x; rot.y = ZeroSVec.y; rot.z = ZeroSVec.z; - get_player_actor_withoutCheck((GAME_PLAY*)gamePT)->Set_force_position_angle_proc(gamePT, &pos, &rot, mPlayer_FORCE_POSITION_ANGLE_POSX | mPlayer_FORCE_POSITION_ANGLE_POSY | mPlayer_FORCE_POSITION_ANGLE_POSZ | mPlayer_FORCE_POSITION_ANGLE_ROTY); - } - else if(train1->player_pass_leaving == 1){ + get_player_actor_withoutCheck((GAME_PLAY*)gamePT) + ->Set_force_position_angle_proc(gamePT, &pos, &rot, + mPlayer_FORCE_POSITION_ANGLE_POSX | mPlayer_FORCE_POSITION_ANGLE_POSY | + mPlayer_FORCE_POSITION_ANGLE_POSZ | mPlayer_FORCE_POSITION_ANGLE_ROTY); + } else if (train1->player_pass_leaving == 1) { pos.x = train1->actor_class.world.position.x + 2.0f; pos.y = train1->actor_class.world.position.y + 16.0f; pos.z = train1->actor_class.world.position.z + 20.0f; - get_player_actor_withoutCheck((GAME_PLAY*)gamePT)->Set_force_position_angle_proc(gamePT, &pos, NULL, mPlayer_FORCE_POSITION_ANGLE_POSX | mPlayer_FORCE_POSITION_ANGLE_POSY | mPlayer_FORCE_POSITION_ANGLE_POSZ); - + get_player_actor_withoutCheck((GAME_PLAY*)gamePT) + ->Set_force_position_angle_proc(gamePT, &pos, NULL, + mPlayer_FORCE_POSITION_ANGLE_POSX | mPlayer_FORCE_POSITION_ANGLE_POSY | + mPlayer_FORCE_POSITION_ANGLE_POSZ); } } - -static void aTR1_setupAction(ACTOR* actor, int action){ +static void aTR1_setupAction(ACTOR* actor, int action) { TRAIN1_ACTOR* train1 = (TRAIN1_ACTOR*)actor; - - static cKF_Animation_R_c* anime_table[] = {&cKF_ba_r_obj_train1_3_open, &cKF_ba_r_obj_train1_3_close}; - static f32 anime_end[] = {24.0f, 32.0f}; - static int animeSeqNoTable[] = {0,0,0,0,0,1,1,0,0}; - static f32 anime_spd[] = {0.0f,0.0f,0.0f,0.0f, 0.5f, 0.0f,0.5f,0.0f,0.0f}; - + + static cKF_Animation_R_c* anime_table[] = { &cKF_ba_r_obj_train1_3_open, &cKF_ba_r_obj_train1_3_close }; + static f32 anime_end[] = { 24.0f, 32.0f }; + static int animeSeqNoTable[] = { 0, 0, 0, 0, 0, 1, 1, 0, 0 }; + static f32 anime_spd[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.5f, 0.0f, 0.5f, 0.0f, 0.0f }; + cKF_Animation_R_c* anime_pt; f32 speed; f32 end; f32 tr_speed; int seq_no = animeSeqNoTable[action]; - + anime_pt = anime_table[seq_no]; speed = anime_spd[action]; end = anime_end[seq_no]; tr_speed = 1.0f; train1->tr_action = action; - - if((train1->tr_action == 6) || (train1->tr_action == 4)){ - if((mEv_CheckTitleDemo() == 0) && (tr_speed != train1->tr_speed)){ + + if ((train1->tr_action == 6) || (train1->tr_action == 4)) { + if ((mEv_CheckTitleDemo() == 0) && (tr_speed != train1->tr_speed)) { aTR1_OngenTrgStart(actor, 43); - } - else{ + } else { tr_speed = end; } } - cKF_SkeletonInfo_R_init(&train1->keyframe, train1->keyframe.skeleton, anime_pt, - 1.0f, end, tr_speed, speed, 0.0f, 0, NULL ); + cKF_SkeletonInfo_R_init(&train1->keyframe, train1->keyframe.skeleton, anime_pt, 1.0f, end, tr_speed, speed, 0.0f, 0, + NULL); aTR1_chg_station_attr(action); } -static void aTR1_actor_move(ACTOR* actor, GAME* game){ +static void aTR1_actor_move(ACTOR* actor, GAME* game) { TRAIN1_ACTOR* train1 = (TRAIN1_ACTOR*)actor; TRAIN0_ACTOR* train0 = (TRAIN0_ACTOR*)actor->parent_actor; cKF_SkeletonInfo_R_c* keyframe = &train1->keyframe; - train1->anim_state = cKF_SkeletonInfo_R_play(keyframe); - if(mEv_CheckTitleDemo() <= 0){ - aTR1_position_move((ACTOR*)train1); + if (mEv_CheckTitleDemo() <= 0) { + aTR1_position_move((ACTOR*)train1); } aTR1_passenger_ctrl((ACTOR*)train1); - if(train0->tr_action != train1->tr_action){ - aTR1_setupAction((ACTOR*)train1, train0->tr_action); + if (train0->tr_action != train1->tr_action) { + aTR1_setupAction((ACTOR*)train1, train0->tr_action); } train1->tr_speed = 0.0f; diff --git a/src/ac_weather.c b/src/ac_weather.c index 345dfe52..dd86a1ec 100644 --- a/src/ac_weather.c +++ b/src/ac_weather.c @@ -12,6 +12,7 @@ #include "m_malloc.h" #include "m_player_lib.h" #include "m_event.h" +#include "libultra/libultra.h" static void Weather_Actor_ct(ACTOR* actor, GAME* game); static void Weather_Actor_dt(ACTOR* actor, GAME* game); @@ -19,6 +20,7 @@ static void Weather_Actor_move(ACTOR* actor, GAME* game); static void Weather_Actor_draw(ACTOR* actor, GAME* game); static void aWeather_SetNowProfile(WEATHER_ACTOR* weather, s16 id); +static int aWeather_CountWeatherPrivate(WEATHER_ACTOR* weather); static aWeather_Profile_c* profile_tbl[] = { &iam_weather_fine, &iam_weather_rain, &iam_weather_snow, &iam_weather_sakura, &iam_weather_leaf, @@ -105,7 +107,7 @@ extern void aWeather_RequestChangeWeatherFromIsland() { mEnv_SAVE_GET_WEATHER_INTENSITY(Save_Get(weather))); } -int aWeather_GetWeatherPrvNum(ACTOR* actor) { +static int aWeather_GetWeatherPrvNum(ACTOR* actor) { WEATHER_ACTOR* weather = (WEATHER_ACTOR*)actor; aWeather_Priv* priv = weather->priv; int i; @@ -120,7 +122,7 @@ int aWeather_GetWeatherPrvNum(ACTOR* actor) { return -1; } -void aWeather_AbolishPrivate(ACTOR* actor, int num) { +static void aWeather_AbolishPrivate(ACTOR* actor, int num) { WEATHER_ACTOR* weather = (WEATHER_ACTOR*)actor; aWeather_Priv* priv = weather->priv; @@ -132,7 +134,7 @@ void aWeather_AbolishPrivate(ACTOR* actor, int num) { } } -aWeather_Priv* aWeather_GetWeatherPrv(u8 status, s16 timer, xyz_t* pos, xyz_t* speed, ACTOR* actor, int id) { +static aWeather_Priv* aWeather_GetWeatherPrv(u8 status, s16 timer, xyz_t* pos, xyz_t* speed, ACTOR* actor, int id) { WEATHER_ACTOR* weather = (WEATHER_ACTOR*)actor; aWeather_Priv* priv = weather->priv; @@ -155,7 +157,7 @@ aWeather_Priv* aWeather_GetWeatherPrv(u8 status, s16 timer, xyz_t* pos, xyz_t* s return NULL; } -int aWeather_StopSysLevSE() { +static int aWeather_StopSysLevSE() { WEATHER_ACTOR* weather = Common_Get(clip.weather_clip)->actor; u8 current = weather->current_sound_effect; @@ -171,7 +173,7 @@ int aWeather_StopSysLevSE() { } } -int aWeather_StartSysLevSE() { +static int aWeather_StartSysLevSE() { WEATHER_ACTOR* weather = Common_Get(clip.weather_clip)->actor; u8 current = weather->current_sound_effect; @@ -200,7 +202,7 @@ int aWeather_StartSysLevSE() { return 0; } -void aWeather_ChangeWeatherInstance(WEATHER_ACTOR* weather, s16 status, s16 level) { +static void aWeather_ChangeWeatherInstance(WEATHER_ACTOR* weather, s16 status, s16 level) { weather->next_status = status; weather->next_level = level; @@ -218,7 +220,7 @@ void aWeather_ChangeWeatherInstance(WEATHER_ACTOR* weather, s16 status, s16 leve } } -int aWeather_IsLand_Event_Check() { +static int aWeather_IsLand_Event_Check() { if (((mFI_CheckBeforeScenePerpetual() != 0) || (mFI_GetClimate() == 1)) && (Common_Get(island_weather) != (s16)mEnv_SAVE_GET_WEATHER_TYPE(Save_Get(weather)))) { @@ -227,7 +229,7 @@ int aWeather_IsLand_Event_Check() { return 0; } -int aWeather_Basement_Event_Check(WEATHER_ACTOR* weather) { +static int aWeather_Basement_Event_Check(WEATHER_ACTOR* weather) { if ((weather->basement_event == 1) || (weather->basement_event == 2)) { return 1; @@ -303,7 +305,7 @@ static void aWeather_EndEnvSE(ACTOR* actor) { aWeather_SysLevCall_MoveEnd(weather); } -void aWeather_SetNowProfile(WEATHER_ACTOR* weather, s16 id) { +static void aWeather_SetNowProfile(WEATHER_ACTOR* weather, s16 id) { if (!mFI_GET_TYPE(mFI_GetFieldId())) { weather->current_profile = profile_tbl[id]; @@ -312,7 +314,7 @@ void aWeather_SetNowProfile(WEATHER_ACTOR* weather, s16 id) { } } -void aWeather_SecureWeatherPrivateWork(WEATHER_ACTOR* weather) { +static void aWeather_SecureWeatherPrivateWork(WEATHER_ACTOR* weather) { int i; weather->priv = zelda_malloc(sizeof(aWeather_Priv) * 100); @@ -344,7 +346,7 @@ static void aWeather_SetClip(WEATHER_ACTOR* weather, int flag) { } } -void aWeather_RenewWindInfo(WEATHER_ACTOR* weather) { +static void aWeather_RenewWindInfo(WEATHER_ACTOR* weather) { s_xyz pos = Common_Get(wind); // multiply by 1 means inline ? f32 speed = Common_Get(wind_speed) * 0.01f; f32 factor = 1.0f; @@ -354,7 +356,7 @@ void aWeather_RenewWindInfo(WEATHER_ACTOR* weather) { weather->wind_info.z = pos.z * speed * factor; } -void aWeather_SnowInAdvance(WEATHER_ACTOR* weather, GAME_PLAY* play, int moves) { +static void aWeather_SnowInAdvance(WEATHER_ACTOR* weather, GAME_PLAY* play, int moves) { int i; @@ -363,7 +365,7 @@ void aWeather_SnowInAdvance(WEATHER_ACTOR* weather, GAME_PLAY* play, int moves) } } -void Weather_Actor_ct(ACTOR* actor, GAME* game) { +static void Weather_Actor_ct(ACTOR* actor, GAME* game) { static s16 DemoWeatherTbl[5][2] = { 3, 1, 1, 2, 0, 0, 0, 0, 2, 1, }; @@ -481,7 +483,7 @@ static void Weather_Actor_draw(ACTOR* actor, GAME* game) { aWeather_DrawWeatherPrv(actor, game); } -void aWeather_MakeWeatherPrv(ACTOR* actor, GAME* game) { +static void aWeather_MakeWeatherPrv(ACTOR* actor, GAME* game) { WEATHER_ACTOR* weather = (WEATHER_ACTOR*)actor; if (weather->current_level != 0) { @@ -515,7 +517,7 @@ static void aWeather_MoveWeatherPrv(WEATHER_ACTOR* weather, GAME* game) { } } -int aWeather_CountWeatherPrivate(WEATHER_ACTOR* weather) { +static int aWeather_CountWeatherPrivate(WEATHER_ACTOR* weather) { int i; int count; aWeather_Priv* priv = weather->priv; @@ -554,13 +556,13 @@ static void aWeather_ChangeWeather(WEATHER_ACTOR* weather, GAME_PLAY* play) { } } -void aWeather_CheckWeatherTimer() { +static void aWeather_CheckWeatherTimer() { s_xyz dir; mEnv_DecideWindDirect(&dir, 0x3000, 0x3000); } -void aWeather_RenewWeatherLevel(WEATHER_ACTOR* weather, GAME_PLAY* play) { +static void aWeather_RenewWeatherLevel(WEATHER_ACTOR* weather, GAME_PLAY* play) { s16 level; if (weather->current_level != weather->current_aim_level) { diff --git a/src/ac_yatai.c b/src/ac_yatai.c index 0af54cf4..5bc6220c 100644 --- a/src/ac_yatai.c +++ b/src/ac_yatai.c @@ -6,58 +6,47 @@ #include "m_rcp.h" #include "m_common_data.h" #include "m_player_lib.h" +#include "m_handbill.h" static void aYAT_actor_ct(ACTOR* actor, GAME* game); static void aYAT_actor_init(ACTOR* actor, GAME* game); static void aYAT_actor_draw(ACTOR* actor, GAME* game); ACTOR_PROFILE Yatai_Profile = { - mAc_PROFILE_YATAI, - ACTOR_PART_ITEM, - ACTOR_STATE_TA_SET, - FIREWORKS_STALL0, - ACTOR_OBJ_BANK_KEEP, - sizeof(YATAI_ACTOR), - &aYAT_actor_ct, - NONE_ACTOR_PROC, - &aYAT_actor_init, - &aYAT_actor_draw, - NULL + mAc_PROFILE_YATAI, + ACTOR_PART_ITEM, + ACTOR_STATE_TA_SET, + FIREWORKS_STALL0, + ACTOR_OBJ_BANK_KEEP, + sizeof(YATAI_ACTOR), + &aYAT_actor_ct, + NONE_ACTOR_PROC, + &aYAT_actor_init, + &aYAT_actor_draw, + NULL, }; -static u8 aYAT_shadow_vtx_fix_flg_table[] = { - TRUE, FALSE, TRUE, FALSE, - FALSE, FALSE, TRUE, FALSE -}; +static u8 aYAT_shadow_vtx_fix_flg_table[] = { TRUE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE }; extern Vtx obj_e_yatai_shadow_l_v[]; extern Gfx obj_e_yatai_shadow_l_modelT[]; -static bIT_ShadowData_c aYAT_shadow_data_l = { - 7, aYAT_shadow_vtx_fix_flg_table, - 60.0f, - obj_e_yatai_shadow_l_v, - obj_e_yatai_shadow_l_modelT -}; +static bIT_ShadowData_c aYAT_shadow_data_l = { 7, aYAT_shadow_vtx_fix_flg_table, 60.0f, obj_e_yatai_shadow_l_v, + obj_e_yatai_shadow_l_modelT }; extern Vtx obj_e_yatai_shadow_r_v[]; extern Gfx obj_e_yatai_shadow_r_modelT[]; -static bIT_ShadowData_c aYAT_shadow_data_r = { - 10, aYAT_shadow_vtx_fix_flg_table, - 60.0f, - obj_e_yatai_shadow_r_v, - obj_e_yatai_shadow_r_modelT -}; +static bIT_ShadowData_c aYAT_shadow_data_r = { 10, aYAT_shadow_vtx_fix_flg_table, 60.0f, obj_e_yatai_shadow_r_v, + obj_e_yatai_shadow_r_modelT }; static void aYAT_set_bgOffset(STRUCTURE_ACTOR* yatai, int idx); -static void aYAT_actor_ct(ACTOR* actor, GAME* game) -{ - STRUCTURE_ACTOR* yatai = (STRUCTURE_ACTOR*)actor; +static void aYAT_actor_ct(ACTOR* actor, GAME* game) { + STRUCTURE_ACTOR* yatai = (STRUCTURE_ACTOR*)actor; - yatai->arg0 = actor->npc_id - FIREWORKS_STALL0; - aYAT_set_bgOffset(yatai, yatai->arg0 + 2); + yatai->arg0 = actor->npc_id - FIREWORKS_STALL0; + aYAT_set_bgOffset(yatai, yatai->arg0 + 2); } - #include "../src/ac_yatai_move.c_inc" +#include "../src/ac_yatai_move.c_inc" - #include "../src/ac_yatai_draw.c_inc" +#include "../src/ac_yatai_draw.c_inc" diff --git a/src/audio.c b/src/audio.c index 71476ab3..ac8e3679 100644 --- a/src/audio.c +++ b/src/audio.c @@ -8,6 +8,8 @@ #include "m_common_data.h" #include "m_camera2.h" #include "sys_math.h" +#include "jaudio_NES/kappa.h" +#include "jaudio_NES/staff.h" int S_ongenpos_refuse_fg; @@ -297,7 +299,6 @@ extern void sAdos_KishaStatusLevel(f32 speed, u32 ongenNum1, u16 angle1, f32 dis } extern void sAdos_GetRadioCounter(void* p) { - Na_GetRadioCounter(p); } diff --git a/src/bg_item.c b/src/bg_item.c new file mode 100644 index 00000000..22328450 --- /dev/null +++ b/src/bg_item.c @@ -0,0 +1,132 @@ +#include "bg_item.h" + +#include "m_common_data.h" +#include "m_name_table.h" +#include "m_malloc.h" +#include "libultra/libultra.h" +#include "m_player_lib.h" +#include "sys_matrix.h" +#include "m_skin_matrix.h" +#include "gfxalloc.h" +#include "m_rcp.h" +#include "m_event_map_npc.h" + +#define bIT_CLIP (Common_Get(clip).bg_item_clip) + +static void bIT_actor_ct(ACTOR* actorx, GAME* game); +static void bIT_actor_dt(ACTOR* actorx, GAME* game); +static void bIT_actor_move(ACTOR* actorx, GAME* game); +static void bIT_actor_draw(ACTOR* actorx, GAME* game); + +ACTOR_PROFILE BgItem_Profile = { + mAc_PROFILE_BGITEM, + ACTOR_PART_ITEM, + ACTOR_STATE_NO_DRAW_WHILE_CULLED | ACTOR_STATE_NO_MOVE_WHILE_CULLED, + EMPTY_NO, + ACTOR_OBJ_BANK_BGITEM, + sizeof(BG_ITEM_ACTOR), + &bIT_actor_ct, + &bIT_actor_dt, + &bIT_actor_move, + &bIT_actor_draw, + NULL, +}; + +static f32 pos_table[] = { + 20.0f, 60.0f, 100.0f, 140.0f, 180.0f, 220.0f, 260.0f, 300.0f, + 340.0f, 380.0f, 420.0f, 460.0f, 500.0f, 540.0f, 580.0f, 620.0f, +}; + +static f32 pos_table2[] = { + 0.0f, 40.0f, 80.0f, 120.0f, 160.0f, 200.0f, 240.0f, 280.0f, + 320.0f, 360.0f, 400.0f, 440.0f, 480.0f, 520.0f, 560.0f, 600.0f, +}; + +#include "bg_item_data.c_inc" + +// TODO: +static bg_item_draw_part_table_c draw_part_table_a[]; + +#include "../src/bg_item_clip.c_inc" +#include "../src/bg_item_common.c_inc" + +extern u16 obj_g_hole_pal[]; +extern u16 obj_s_hole_pal[]; + +static void bIT_actor_ct(ACTOR* actorx, GAME* game) { + BG_ITEM_ACTOR* bg_item = (BG_ITEM_ACTOR*)actorx; + bg_item_common_c* common; + bg_item_common_info_c* common_info; + int i; + int max; + int event_type; + PLAYER_ACTOR* player; + mFI_block_tbl_c* block_table; + bg_item_tbl_c* info_table; + + common = &bg_item->common; + common_info = &common->common_info; + bIT_clip_ct(actorx); + mFI_InitItemTable(&common->item_table); + player = GET_PLAYER_ACTOR((GAME_PLAY*)game); + event_type = mEvMN_GetEventTypeMap(); + + if (player != NULL) { + mFI_GetItemTable(&bg_item->common.item_table, player->actor_class.world.position, __FILE__, 257); + mFI_BornItemON(); + } + + max = common->item_table.count; + block_table = common->item_table.block_info_tbl; + info_table = common->block_info_table.info_tbl; + for (i = 0; i < max; i++, block_table++, info_table++) { + bIT_common_clear_treeatr(block_table->block_x, block_table->block_z, info_table); + + if (event_type == -1 || mEvMN_GetMapIdx(event_type) == -1) { + mFI_ClearHoleBlock(block_table->block_x, block_table->block_z); + } + } + + for (i = 0; i < mFM_VISIBLE_BLOCK_NUM; i++) { + common->_139F4[i] = i; + } + + common_info->_30 = 4; + common_info->draw_part_table_p = draw_part_table_a; + + common_info->pal_p[bIT_PAL_FLOWER_A] = g_fdinfo->field_palette.flower0_pal; + common_info->pal_p[bIT_PAL_FLOWER_B] = g_fdinfo->field_palette.flower1_pal; + common_info->pal_p[bIT_PAL_FLOWER_C] = g_fdinfo->field_palette.flower2_pal; + common_info->pal_p[bIT_PAL_GRASS] = g_fdinfo->field_palette.grass_pal; + common_info->pal_p[bIT_PAL_TREE] = g_fdinfo->field_palette.cedar_tree_pal; + common_info->pal_p[bIT_PAL_PALM_TREE] = g_fdinfo->field_palette.palm_tree_pal; + common_info->pal_p[bIT_PAL_GOLD_TREE] = g_fdinfo->field_palette.golden_tree_pal; + common_info->pal_p[bIT_PAL_HOLE_G] = obj_g_hole_pal; + common_info->pal_p[bIT_PAL_HOLE_S] = obj_s_hole_pal; + + common->bg_item_actorx_p = actorx; + + { + bg_item_draw_table_c* draw_tbl = common->draw_table; + bg_item_idx_info_c* start_idx = bg_item->item_idx_info; + + for (i = 0; i < mFM_VISIBLE_BLOCK_NUM; i++, draw_tbl++, start_idx++) { + draw_tbl->draw_data.val = bIT_DRAW_TYPE_MAX - 1; + draw_tbl->draw_data.idx_p = start_idx->idx; + } + } + + common_info->pos_table_p = pos_table; + bg_item_common_chg_BGDataR(common); + bg_item_common_construct(game, common); +} + +static void bIT_actor_dt(ACTOR* actorx, GAME* game) { + BG_ITEM_ACTOR* bg_item = (BG_ITEM_ACTOR*)actorx; + + bg_item_common_destruct((GAME_PLAY*)game, actorx, &bg_item->common); + bIT_clip_dt(); +} + +#include "../src/bg_item_move.c_inc" +#include "../src/bg_item_draw.c_inc" diff --git a/src/bg_item_clip.c_inc b/src/bg_item_clip.c_inc new file mode 100644 index 00000000..ec59cac0 --- /dev/null +++ b/src/bg_item_clip.c_inc @@ -0,0 +1,109 @@ +static void bIT_copy_vtx(Vtx* dst, Vtx* src, u32 count, u8* fix_table, int fix_adjust_pos) { + int i; + + for (i = 0; i != count; i++, src++, dst++, fix_table++) { + *dst = *src; + + /* Adjust vertex by sun position */ + if (*fix_table == TRUE) { + dst->v.ob[0] = src->v.ob[0] + fix_adjust_pos; + } else { + dst->v.ob[0] = src->v.ob[0]; + } + } +} + +static void bIT_draw_shadow(GAME* game, bIT_ShadowData_c* data, int type) { + GRAPH* graph = game->graph; + Kankyo* kankyo = &((GAME_PLAY*)game)->kankyo; + Vtx* vtx = (Vtx*)GRAPH_ALLOC_TYPE(graph, Vtx, data->vtx_num); + Gfx* gfx; + u8 r; + u8 g; + u8 b; + u8 a; + + if (vtx != NULL) { + bIT_copy_vtx(vtx, data->vtx, data->vtx_num, data->vtx_fix_flags, (int)(kankyo->shadow_pos * data->size)); + } else { + vtx = data->vtx; + } + + OPEN_DISP(graph); + gfx = NOW_SHADOW_DISP; + + gDPPipeSync(gfx++); + gSPMatrix(gfx++, _Matrix_to_Mtx_new(graph), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPSegment(gfx++, G_MWO_SEGMENT_8, vtx); + r = kankyo->base_light.shadow_color[0]; + g = kankyo->base_light.shadow_color[1]; + b = kankyo->base_light.shadow_color[2]; + a = kankyo->shadow_alpha; + gDPSetPrimColor(gfx++, 0, kankyo->shadow_alpha, r, g, b, a); + if (type == 1) { + gSPLoadGeometryMode(gfx++, G_ZBUFFER | G_SHADE | G_CULL_BACK | G_FOG | G_SHADING_SMOOTH | 0x00000050); + } + + gSPDisplayList(gfx++, data->gfx); + + if (type == 1) { + gSPLoadGeometryMode(gfx++, G_ZBUFFER | G_SHADE | G_CULL_BACK | G_FOG | G_SHADING_SMOOTH | 0x00000040); + gSPDisplayList(gfx++, data->gfx); + } + + gSPClearGeometryMode(gfx++, 0x00000050); + + SET_SHADOW_DISP(gfx); + CLOSE_DISP(graph); +} + +static void bIT_draw_shadow(GAME* game, bIT_ShadowData_c* data, int type); +static void bit_cmn_single_draw(GAME* game, mActor_name_t fg_no, xyz_t* pos, f32 scale_f, bIT_DRAW_BF_PROC draw_bf, + bIT_DRAW_AF_PROC draw_af, rgba_t* col); +static int bIT_actor_player_drop_entry(GAME* game, mActor_name_t fg_item, int ut_x, int ut_z, s16 layer); +static int BIT_actor_tree_cutcount_check(GAME* game, int ut_x, int ut_z); +static void bIT_actor_dig_hole_effect_entry(mActor_name_t fg_item, xyz_t* pos, u16 frames, u16 wait_frames); +static void bIT_actor_bury_hole_effect_entry(mActor_name_t fg_item, xyz_t* pos, u16 frames); +static void bIT_actor_fly_entry(mActor_name_t fg_item, xyz_t* pos, s16 angle_y); +static int bIT_drop_entry_v1(mActor_name_t fg_item, xyz_t* pos, xyz_t* target_pos); +static void bg_item_tree_fruit_drop(mActor_name_t fg_item, int ut_x, int ut_z, xyz_t* drop_pos); +static int bIT_actor_pit_fall(mActor_name_t pit_fg_item, int ut_x, int ut_z, mActor_name_t fg_item_in_pit); +static int bIT_actor_pit_fall_stop(mActor_name_t pit_fg_item, int ut_x, int ut_z, mActor_name_t fg_item_in_pit); +static int bIT_actor_pit_exit(mActor_name_t pit_fg_item, int ut_x, int ut_z, mActor_name_t fg_item_in_pit); +static int bIT_actor_rand_pos_get(xyz_t* pos, const xyz_t* check_pos); +static int bg_item_ten_coin_entry_ex(xyz_t* pos, s16 angle); +static int bIT_fruit_set(mActor_name_t fg_item, int ut_x, int ut_z, s16 count, int type); +static int bIT_actor_fade_entry(mActor_name_t fg_name, xyz_t* pos); + +static void bIT_clip_ct(ACTOR* actorx) { + BG_ITEM_ACTOR* bg_item = (BG_ITEM_ACTOR*)actorx; + + if (bIT_CLIP == NULL) { + bIT_CLIP = (bIT_Clip_c*)zelda_malloc(sizeof(bIT_Clip_c)); + bIT_CLIP->draw_shadow_proc = &bIT_draw_shadow; + bIT_CLIP->single_draw_proc = &bit_cmn_single_draw; + bIT_CLIP->player_drop_entry_proc = &bIT_actor_player_drop_entry; + bIT_CLIP->tree_cutcount_check_proc = &BIT_actor_tree_cutcount_check; + bIT_CLIP->dig_hole_effect_entry_proc = &bIT_actor_dig_hole_effect_entry; + bIT_CLIP->bury_hole_effect_entry_proc = &bIT_actor_bury_hole_effect_entry; + bIT_CLIP->fly_entry_proc = &bIT_actor_fly_entry; + bIT_CLIP->drop_entry_v1_proc = &bIT_drop_entry_v1; + bIT_CLIP->item_tree_fruit_drop_proc = &bg_item_tree_fruit_drop; + bIT_CLIP->pit_fall_proc = &bIT_actor_pit_fall; + bIT_CLIP->pit_fall_stop_proc = &bIT_actor_pit_fall_stop; + bIT_CLIP->pit_exit_proc = &bIT_actor_pit_exit; + bIT_CLIP->rand_pos_get_proc = &bIT_actor_rand_pos_get; + bIT_CLIP->ten_coin_entry_ex_proc = &bg_item_ten_coin_entry_ex; + bIT_CLIP->fruit_set_proc = &bIT_fruit_set; + bIT_CLIP->fade_entry_proc = &bIT_actor_fade_entry; + bIT_CLIP->bg_item_common_p = &bg_item->common; + bIT_CLIP->bg_item_actorx = actorx; + } +} + +static void bIT_clip_dt(void) { + if (bIT_CLIP != NULL) { + zelda_free(bIT_CLIP); + bIT_CLIP = NULL; + } +} diff --git a/src/bg_item_common.c_inc b/src/bg_item_common.c_inc new file mode 100644 index 00000000..3ed031c9 --- /dev/null +++ b/src/bg_item_common.c_inc @@ -0,0 +1,3145 @@ +static void bit_cmn_single_drawS(GAME* game, bg_item_common_info_c* common_info, mActor_name_t fg_item, xyz_t* pos, + s_xyz* angle, xyz_t* scale, u8 alpha, bIT_DRAW_BF_PROC draw_bf, + bIT_DRAW_AF_PROC draw_af, rgba_t* col); + +static void bit_draw_ta_set(GAME* game) { + OPEN_DISP(game->graph); + + gDPSetTextureAdjustMode(NEXT_POLY_OPA_DISP, G_TA_DOLPHIN); + gDPSetTextureAdjustMode(NEXT_SHADOW_DISP, G_TA_DOLPHIN); + gDPSetTextureAdjustMode(NEXT_POLY_XLU_DISP, G_TA_DOLPHIN); + + CLOSE_DISP(game->graph); +} + +static void bit_draw_ta_clr(GAME* game) { + OPEN_DISP(game->graph); + + gDPSetTextureAdjustMode(NEXT_POLY_OPA_DISP, G_TA_N64); + gDPSetTextureAdjustMode(NEXT_SHADOW_DISP, G_TA_N64); + gDPSetTextureAdjustMode(NEXT_POLY_XLU_DISP, G_TA_N64); + + CLOSE_DISP(game->graph); +} + +static int bIT_individual_draw_check(mActor_name_t fg_name) { + int type = ITEM_NAME_GET_TYPE(fg_name); + + if (fg_name != EMPTY_NO && ITEM_NAME_GET_TYPE(fg_name) < NAME_TYPE_WARP && + (type != NAME_TYPE_ITEM0 || (type == NAME_TYPE_ITEM0 && ITEM_NAME_GET_CAT(fg_name) != 9))) { + return TRUE; + } + + return FALSE; +} + +static f32 rnd_data_x[][4] = { + { 7.5f, 0.0f, -5.0f, 5.0f }, + { -5.0f, -7.5f, 2.5f, -2.5f }, + { 7.5f, 10.0f, -2.5f, 5.0f }, + { -2.5f, 5.0f, 7.5f, -2.5f }, +}; + +static f32 rnd_data_z[][4] = { + { -5.0f, 0.0f, 5.0f, 0.0f }, + { -5.0f, 2.5f, 0.0f, 5.0f }, + { -2.5f, 0.0f, 7.5f, 5.0f }, + { 7.5f, -7.5f, -2.5f, -5.0f }, +}; + +static int mFI_search_unit_around_high(xyz_t* pos, mActor_name_t item, xyz_t* cur_pos) { + static f32 BI_chk_pos[9 * 2] = { + -40.0f, -40.0f, // x - 1, z - 1 (top-left) + -40.0f, 40.0f, // x - 1, z + 1 (bottom-left) + 40.0f, 40.0f, // x + 1, z + 1 (bottom-right) + 40.0f, -40.0f, // x + 1, z - 1 (top-right) + -40.0f, 0.0f, // x - 1, z (left) + 0.0f, 40.0f, // x, z + 1 (below) + 40.0f, 0.0f, // x + 1, z (right) + 0.0f, -40.0f, // x, z - 1 (above) + 0.0f, 0.0f // x, z (origin) + }; + mActor_name_t* item_p; + xyz_t tpos; + f32* around = BI_chk_pos; + int i = 9; + int res = FALSE; + + while (i != 0) { + i--; + + tpos.x = pos->x + around[i * 2 + 0]; + tpos.z = pos->z + around[i * 2 + 1]; + + item_p = mFI_GetUnitFG(tpos); + tpos.y = mCoBG_GetBgY_OnlyCenter_FromWpos2(tpos, 0.0f); + if (item_p != NULL && item_p[0] == item && tpos.y <= (cur_pos->y + 40.0f) && tpos.y >= (cur_pos->y - 40.0f) && + mCoBG_CheckPlace(tpos)) { + xyz_t_move(pos, &tpos); + res = TRUE; + break; + } + } + + return res; +} + +static int bIT_actor_fade_entry(mActor_name_t fg_name, xyz_t* pos) { + bg_item_fade_c* bg_item_fade = bIT_CLIP->bg_item_common_p->fade; + u8 min_alpha = 255; + bg_item_fade_c* selected_fade = NULL; + int i; + + for (i = 0; i < bIT_FADE_NUM; i++, bg_item_fade++) { + if (bg_item_fade->mode == 0) { + selected_fade = bg_item_fade; + break; + } else if (bg_item_fade->mode == 1 && bg_item_fade->alpha < min_alpha) { + min_alpha = bg_item_fade->alpha; + selected_fade = bg_item_fade; + } + } + + if (selected_fade != NULL) { + selected_fade->mode = 1; + selected_fade->fg_item = fg_name; + selected_fade->alpha = 255; + mFI_Wpos2UtCenterWpos(&selected_fade->position, *pos); + selected_fade->position.y = mCoBG_GetBgY_OnlyCenter_FromWpos2(selected_fade->position, 0.0f); + selected_fade->_10 = 0; + mFI_SetFG_common(EMPTY_NO, selected_fade->position, TRUE); + return TRUE; + } + + return FALSE; +} + +static void bIT_actor_fade_move(GAME* game, bg_item_fade_c* bg_item_fade) { + int i; + + for (i = 0; i < bIT_FADE_NUM; i++, bg_item_fade++) { + if (bg_item_fade->mode != 0) { + bg_item_fade->_10++; + + if (bg_item_fade->alpha < 20) { + bg_item_fade->mode = 0; // delete + } else { + bg_item_fade->alpha -= 20; + } + } + } +} + +static void bIT_actor_fade_draw(GAME* game, bg_item_common_info_c* common_info, bg_item_fade_c* bg_item_fade) { + static xyz_t d_size = { 0.01f, 0.01f, 0.01f }; + int i; + + for (i = 0; i < bIT_FADE_NUM; i++, bg_item_fade++) { + if (bg_item_fade->mode != 0) { + bit_cmn_single_drawS(game, common_info, bg_item_fade->fg_item, &bg_item_fade->position, &ZeroSVec, &d_size, + bg_item_fade->alpha, NULL, NULL, NULL); + } + } +} + +static int bIT_actor_ten_coin_entryR(bg_item_ten_coin_c* ten_coin, mActor_name_t fg_item, xyz_t* pos, s16 angle) { + int mode; + bg_item_ten_coin_c* sel_ten_coin; + int money_stone_flag; + int set_pos_valid; + xyz_t set_pos; + xyz_t target_pos; + int i; + + money_stone_flag = FALSE; + mode = 0; + if ((fg_item >= MONEY_ROCK_A && fg_item <= MONEY_ROCK_E) || fg_item == MONEY_FLOWER_SEED) { + money_stone_flag = TRUE; + } + + sel_ten_coin = NULL; + + mFI_Wpos2UtCenterWpos(&target_pos, *pos); + target_pos.y = mCoBG_GetBgY_OnlyCenter_FromWpos2(target_pos, -1.0f); + xyz_t_move(&set_pos, &target_pos); + set_pos_valid = mFI_search_unit_around_high(&set_pos, EMPTY_NO, &target_pos); + + for (i = 0; i < bIT_TEN_COIN_NUM; i++, ten_coin++) { + if (ten_coin->_4C != 0 && ten_coin->position.x == target_pos.x && ten_coin->position.z == target_pos.z && + ten_coin->left_frames > 0) { + mode = 2; + sel_ten_coin = ten_coin; + break; + } + + if (money_stone_flag) { + if (ten_coin->_4C == 0) { + mode = 1; + sel_ten_coin = ten_coin; + } else if (mode == 0) { + // won't this case always be true since _44 is a u16? + if ((int)ten_coin->_44 > (int)-0x80000000) { + sel_ten_coin = ten_coin; + } + } + } + } + + if (sel_ten_coin != NULL) { + sel_ten_coin->_44 = 0; + sel_ten_coin->_4E = 10; + sel_ten_coin->_50 = sel_ten_coin->_4E; + sel_ten_coin->_46 = 0; + sel_ten_coin->_48 = (int)(32767.0f / ((f32)(int)sel_ten_coin->_4E)); + sel_ten_coin->angle = angle; + sel_ten_coin->_4C = 1; + + if (mode != 2) { + s16 swing_time; + + xyz_t_move(&sel_ten_coin->position, &target_pos); + sel_ten_coin->scale = 15.0f; + sel_ten_coin->fg_item = fg_item; + swing_time = mPr_GetMoneyPower(); + + /* @BUG - shouldn't this be += 100? */ + if ((int)Common_Get(now_private)->destiny.type == mPr_DESTINY_MONEY_LUCK) { + swing_time -= 100; + } + + if (swing_time > 100) { + swing_time = 100; + } + + sel_ten_coin->left_frames = (int)(386.0f + ((f32)(int)swing_time) * 0.6f); + sel_ten_coin->total_frames = sel_ten_coin->left_frames; + sel_ten_coin->hit_count = 0; + mFI_SetFG_common(MONEY_FLOWER_SEED, target_pos, TRUE); + } else { + sel_ten_coin->hit_count++; + } + + /* There must be a valid place to drop the item */ + if (set_pos_valid) { + mActor_name_t fg_money_item; + u16 sfx_no; + + /* Drop money out of rock & play sfx */ + mFI_SetFG_common(RSV_NO, set_pos, FALSE); + switch (sel_ten_coin->hit_count) { + case 0: + case 1: + case 2: + fg_money_item = ITM_MONEY_100; + if (Common_Get(now_private)->destiny.type == mPr_DESTINY_MONEY_LUCK) { + fg_money_item = ITM_MONEY_1000; + } + + sfx_no = 0x426; + break; + case 3: + case 4: + case 5: + fg_money_item = Common_Get(now_private)->destiny.type == mPr_DESTINY_MONEY_LUCK + ? (mActor_name_t)ITM_MONEY_10000 + : (mActor_name_t)ITM_MONEY_1000; + sfx_no = 0x447; + break; + case 6: + default: + fg_money_item = Common_Get(now_private)->destiny.type == mPr_DESTINY_MONEY_LUCK + ? (mActor_name_t)ITM_MONEY_30000 + : (mActor_name_t)ITM_MONEY_10000; + sfx_no = 0x447; + break; + } + + bIT_actor_drop_entry(&bIT_CLIP->bg_item_common_p->drop_info, fg_money_item, &target_pos, &set_pos, 1, 0); + sAdo_OngenTrgStart(sfx_no, &target_pos); + } + return TRUE; + } + + return FALSE; +} + +static int bIT_actor_ten_coin_entry(bg_item_ten_coin_c* ten_coin, xyz_t* pos, s16 angle) { + int res = FALSE; + mActor_name_t* fg_item_p = mFI_GetUnitFG(*pos); + + if (fg_item_p != NULL) { + res = bIT_actor_ten_coin_entryR(ten_coin, *fg_item_p, pos, angle); + } + + return res; +} + +static int bg_item_ten_coin_entry_ex(xyz_t* pos, s16 angle) { + return bIT_actor_ten_coin_entry(bIT_CLIP->bg_item_common_p->ten_coin, pos, angle); +} + +static void bIT_actor_ten_coin_move(GAME* game, bg_item_ten_coin_c* ten_coin) { + int save; + int cmp0; + int cmp1; + int i; + + for (i = 0; i < bIT_TEN_COIN_NUM; i++, ten_coin++) { + if (ten_coin->_4C != 0) { + if (ten_coin->_4C == 1) { + ten_coin->_4E--; + + if (ten_coin->_4E < 0) { + ten_coin->_4E = 0; + } + + save = ten_coin->_46; + ten_coin->_46 += ten_coin->_48; + cmp0 = save >= 0 ? 1 : -1; + cmp1 = ten_coin->_46 >= 0 ? 1 : -1; + + if (cmp1 != cmp0) { + ten_coin->_46 = 0; + ten_coin->_4C = 2; + } + } + + if (ten_coin->left_frames > 0) { + ten_coin->left_frames--; + } + + /* Check if we should reset the money rock to a normal rock */ + if (ten_coin->left_frames <= 0 && ten_coin->_4C == 2) { + mFI_SetFG_common(ten_coin->fg_item - 7, ten_coin->position, TRUE); + ten_coin->_4C = 0; + } + } + } +} + +static int bIT_actor_ten_coin_draw_af(Gfx** gfx_pp) { + gDPPipeSync((*gfx_pp)++); + gDPSetPrimColor((*gfx_pp)++, 0, 128, 255, 255, 255, 255); + return TRUE; +} + +static int bIT_actor_ten_coin_draw_bf(Gfx** gfx_pp, rgba_t* color) { + gDPPipeSync((*gfx_pp)++); + gDPSetPrimColor((*gfx_pp)++, 0, 128, color->r, color->g, color->b, color->a); + return TRUE; +} + +static void bIT_actor_ten_coin_draw(GAME* game, bg_item_common_info_c* common_info, bg_item_ten_coin_c* ten_coin, + f32 shadow_pos, rgba_t* shadow_color) { + static xyz_t d_size = { 0.01f, 0.01f, 0.01f }; + int i; + + for (i = 0; i < bIT_TEN_COIN_NUM; i++, ten_coin++) { + if (ten_coin->_4C != 0) { + xyz_t add_pos; + rgba_t color; + xyz_t display_pos; + f32 percent; + f32 scale; + + add_pos.y = 0.0f; + if (ten_coin->_50 != 0) { + percent = 1.0f - ((f32)(int)ten_coin->left_frames / (f32)(int)ten_coin->total_frames); + } else { + percent = 0.0f; + } + + percent = percent * percent * percent * percent; + color.r = 255; + color.g = (int)(55.0f + 200.0f * percent); + color.b = (int)(255.0f * percent); + color.a = 255; + + scale = sin_s(ten_coin->_46) * ten_coin->scale; + add_pos.x = sin_s(ten_coin->angle) * scale; + add_pos.z = cos_s(ten_coin->angle) * scale; + + xyz_t_add(&ten_coin->position, &add_pos, &display_pos); + bit_cmn_single_drawS(game, common_info, ten_coin->fg_item, &display_pos, &ZeroSVec, &d_size, 255, + &bIT_actor_ten_coin_draw_bf, &bIT_actor_ten_coin_draw_af, &color); + bit_cmn_single_drawS_shadow(game, common_info, ten_coin->fg_item, &display_pos, &ZeroSVec, &d_size, 255, + shadow_pos, shadow_color); + } + } +} + +static void bIT_actor_ten_coin_destruct(bg_item_ten_coin_c* ten_coin) { + int i; + + for (i = 0; i < bIT_TEN_COIN_NUM; i++, ten_coin++) { + if (ten_coin->_4C != 0) { + mFI_SetFG_common(ten_coin->fg_item - 7, ten_coin->position, TRUE); + ten_coin->_4C = 0; + } + } +} + +static void bg_item_common_palload(Gfx** gfx_pp, u16** pal_pp) { + int i; + + for (i = 0; i < bIT_PAL_NUM; i++) { + gDPLoadTLUT_Dolphin((*gfx_pp)++, i, 16, 1, pal_pp[i]); + } +} + +static void bIT_actor_rand_pos_get_blk_correct(f32* x, f32* z, int ut_x, int ut_z) { + *x = rnd_data_x[ut_x & 3][ut_z & 3]; + *z = rnd_data_z[ut_x & 3][ut_z & 3]; +} + +static void bIT_actor_rand_pos_get_plus(mActor_name_t fg_item, xyz_t* pos, const xyz_t* check_pos) { + int ut_x; + int ut_z; + f32 x; + f32 z; + xyz_t tpos; + int valid = mFI_Wpos2UtNum(&ut_x, &ut_z, *check_pos); + + xyz_t_move(&tpos, check_pos); + + /* If the item is a weed or a shell then slightly offset their position */ + if (valid && (IS_ITEM_GRASS(fg_item) || (fg_item >= ITM_SHELL_START && fg_item <= ITM_SHELL7))) { + bIT_actor_rand_pos_get_blk_correct(&x, &z, ut_x, ut_z); + tpos.x += x; + tpos.z += z; + } + + xyz_t_move(pos, &tpos); +} + +static int bIT_actor_rand_pos_get(xyz_t* pos, const xyz_t* check_pos) { + int ut_x; + int ut_z; + int res = FALSE; + int valid = mFI_Wpos2UtNum(&ut_x, &ut_z, *check_pos); + + if (valid) { + mActor_name_t* fg_item_p = mFI_UtNum2UtFG(ut_x, ut_z); + + if (fg_item_p != NULL) { + bIT_actor_rand_pos_get_plus(*fg_item_p, pos, check_pos); + res = TRUE; + } + } + + if (res == FALSE) { + pos->x = 0.0f; + pos->y = 0.0f; + pos->z = 0.0f; + } + + return res; +} + +static void bIT_actor_shin_effect_entry(bg_item_shin_c* shin, mActor_name_t fg_item, xyz_t* pos, u16 mode) { + int exit = FALSE; + int i; + + for (i = 0; exit == FALSE && i < bIT_SHIN_NUM; i++, shin++) { + switch (shin->mode) { + case 0: + shin->fg_item = fg_item; + shin->mode = mode; + xyz_t_move(&shin->position, pos); + exit = TRUE; + break; + + case 5: + if (pos->x == shin->position.x && pos->z == shin->position.z) { + if (mode == 1) { + shin->mode = 3; + exit = TRUE; + } else if (mode == 2) { + shin->mode = 2; + exit = TRUE; + } + } + break; + + case 6: + if (pos->x == shin->position.x && pos->z == shin->position.z) { + if (mode == 1) { + shin->mode = 1; + exit = TRUE; + } else if (mode == 2) { + shin->mode = 4; + exit = TRUE; + } + } + break; + } + } +} + +static int bIT_actor_shin_effect_check(bg_item_shin_c* shin) { + int i; + + for (i = 0; i < bIT_SHIN_NUM; i++) { + switch (shin->mode) { + case 0: + case 1: + case 2: + break; + case 3: + shin->mode = 5; + break; + case 4: + shin->mode = 6; + break; + case 5: + case 6: + break; + } + } + + return FALSE; +} + +static int bIT_actor_shin_effect_move(GAME* game, bg_item_shin_c* shin) { + int exit = FALSE; + int i; + + for (i = 0; exit == FALSE && i < bIT_SHIN_NUM; i++, shin++) { + switch (shin->mode) { + case 1: + eEC_CLIP->effect_make_proc(eEC_EFFECT_ANAHIKARI, shin->position, 1, 0, game, (u16)i, 0, 0); + shin->mode = 3; + exit = TRUE; + break; + case 2: + eEC_CLIP->effect_make_proc(eEC_EFFECT_ANAHIKARI, shin->position, 1, 0, game, (u16)i, 1, 0); + shin->mode = 4; + exit = TRUE; + break; + case 4: + sAdo_OngenPos((u32)shin, 0x2C, &shin->position); + break; + case 5: + eEC_CLIP->effect_kill_proc(eEC_EFFECT_ANAHIKARI, (u16)i); + shin->mode = 0; + break; + case 6: + eEC_CLIP->effect_kill_proc(eEC_EFFECT_ANAHIKARI, (u16)i); + shin->mode = 0; + break; + } + } + + return exit; +} + +static void bIT_actor_drop_move_plant_destruct(bg_item_drop_c* drop) { + if (drop->move_proc != NULL) { + mFI_SetFG_common(drop->fg_item, drop->position, TRUE); + drop->move_proc = NULL; + drop->draw_proc = NULL; + drop->dt_proc = NULL; + } +} + +static int bIT_common_moneytree_check(void) { + int res = FALSE; + f32 rnd = RANDOM_F(100.0f); + + if (rnd <= (50.0f + (f32)(int)mPr_GetMoneyPower() * 0.5f) || + (int)Common_Get(now_private)->destiny.type == mPr_DESTINY_MONEY_LUCK) { + res = TRUE; + } + + return res; +} + +typedef struct fruit2tree_s { + mActor_name_t fruit; + mActor_name_t tree; +} bIT_fr2tr_c; + +enum { + bIT_BURY_ACTION_BURY, + bIT_BURY_ACTION_PLANT, + bIT_BURY_ACTION_PITFALL, + + bIT_BURY_ACTION_NUM +}; + +static int bIT_common_bury_after(mActor_name_t fg_bury_item, mActor_name_t fg_hole_item, xyz_t* bury_pos, + mActor_name_t* buried_item_p) { + int res = bIT_BURY_ACTION_BURY; + int i; + + *buried_item_p = fg_bury_item; + if (fg_bury_item == ITM_FOOD_APPLE || fg_bury_item == ITM_FOOD_CHERRY || fg_bury_item == ITM_FOOD_PEAR || + fg_bury_item == ITM_FOOD_PEACH || fg_bury_item == ITM_FOOD_ORANGE || fg_bury_item == ITM_FOOD_COCONUT) { + static bIT_fr2tr_c fr2tr_f[] = { + { ITM_FOOD_APPLE, TREE_APPLE_SAPLING }, { ITM_FOOD_CHERRY, TREE_CHERRY_SAPLING }, + { ITM_FOOD_PEAR, TREE_PEAR_SAPLING }, { ITM_FOOD_PEACH, TREE_PEACH_SAPLING }, + { ITM_FOOD_ORANGE, TREE_ORANGE_SAPLING }, { ITM_FOOD_COCONUT, TREE_PALM_SAPLING }, + }; + + *buried_item_p = EMPTY_NO; + for (i = 0; i < ARRAY_COUNT(fr2tr_f); i++) { + if (fg_bury_item == fr2tr_f[i].fruit) { + *buried_item_p = fr2tr_f[i].tree; + return bIT_BURY_ACTION_PLANT; + } + } + } else if (fg_bury_item == ITM_MONEY_1000 || fg_bury_item == ITM_MONEY_10000 || fg_bury_item == ITM_MONEY_30000 || + fg_bury_item == ITM_MONEY_100) { + if (fg_hole_item == HOLE_SHINE) { + if (bIT_common_moneytree_check() != FALSE) { + static bIT_fr2tr_c fr2tr_f[] = { + { ITM_MONEY_1000, TREE_1000BELLS_SAPLING }, + { ITM_MONEY_10000, TREE_10000BELLS_SAPLING }, + { ITM_MONEY_30000, TREE_30000BELLS_SAPLING }, + { ITM_MONEY_100, TREE_100BELLS_SAPLING }, + }; + + for (i = 0; i < ARRAY_COUNT(fr2tr_f); i++) { + if (fg_bury_item == fr2tr_f[i].fruit) { + *buried_item_p = fr2tr_f[i].tree; + break; + } + } + } else { + *buried_item_p = TREE_SAPLING; + } + + res = bIT_BURY_ACTION_PLANT; + } + } else if (fg_bury_item >= ITM_WHITE_PANSY_BAG && fg_bury_item <= ITM_YELLOW_TULIP_BAG) { + *buried_item_p = FLOWER_PANSIES0 + (fg_bury_item - ITM_WHITE_PANSY_BAG); + res = bIT_BURY_ACTION_PLANT; + } else if (fg_bury_item == ITM_SAPLING) { + *buried_item_p = TREE_SAPLING; + res = bIT_BURY_ACTION_PLANT; + } else if (fg_bury_item == ITM_CEDAR_SAPLING) { + *buried_item_p = CEDAR_TREE_SAPLING; + res = bIT_BURY_ACTION_PLANT; + } else if (fg_bury_item == ITM_PITFALL) { + int hole_no = mCoBG_GetHoleNumber(*bury_pos); + + if (hole_no != -1) { + *buried_item_p = BURIED_PITFALL_START + hole_no; + } else { + *buried_item_p = EMPTY_NO; + } + + res = bIT_BURY_ACTION_PITFALL; + } else if (fg_bury_item == ITM_SHOVEL) { + if (fg_hole_item == HOLE_SHINE) { + *buried_item_p = GOLD_TREE_SAPLING; + res = bIT_BURY_ACTION_PLANT; + } + } + + return res; +} + +static void bIT_common_hole_throw(mActor_name_t fg_item, mActor_name_t fg_hole_item, xyz_t* pos, int mode) { + mActor_name_t buried_item; + int bury_action = bIT_common_bury_after(fg_item, fg_hole_item, pos, &buried_item); + + if (mode != 1) { + switch (bury_action) { + case bIT_BURY_ACTION_BURY: + default: + mFI_SetFG_common(buried_item, *pos, TRUE); + if (fg_item != EMPTY_NO) { + mFI_Wpos2DepositON(*pos); + } + break; + case bIT_BURY_ACTION_PLANT: + bIT_actor_drop_entry(&bIT_CLIP->bg_item_common_p->drop_info, buried_item, pos, pos, 131, 0); + break; + case bIT_BURY_ACTION_PITFALL: + mFI_SetFG_common(buried_item, *pos, TRUE); + break; + } + } else { + switch (bury_action) { + case bIT_BURY_ACTION_BURY: + default: + mFI_SetFG_common(fg_item, *pos, TRUE); + if (fg_item != EMPTY_NO) { + mFI_Wpos2DepositON(*pos); + } + break; + case bIT_BURY_ACTION_PLANT: + case bIT_BURY_ACTION_PITFALL: + mFI_SetFG_common(buried_item, *pos, TRUE); + break; + } + } +} + +static void bIT_actor_drop_move_fly_destruct(bg_item_drop_c* drop) { + if (drop->move_proc != NULL) { + if ((drop->flags & 4) == 0) { + mActor_name_t* fg_item_p = mFI_GetUnitFG(drop->target_position); + + if (fg_item_p != NULL && ((*fg_item_p >= HOLE00 && *fg_item_p <= HOLE24) || *fg_item_p == HOLE_SHINE)) { + bIT_common_hole_throw(drop->fg_item, *fg_item_p, &drop->target_position, 1); + } else { + mFI_SetFG_common(drop->fg_item, drop->target_position, FALSE); + } + } + + drop->move_proc = NULL; + drop->draw_proc = NULL; + } +} + +static void func_calc_spec_drop_time(f32 distance_xz, f32 distance_y, f32 drop_time, f32 acceleration_y, + f32* velocity_xz, f32* velocity_y) { + if (drop_time > 0.0f) { + *velocity_xz = distance_xz / drop_time; + *velocity_y = (distance_y - (drop_time * 0.5f) * (drop_time * acceleration_y)) / drop_time; + } else { + *velocity_xz = 0.0f; + *velocity_y = 0.0f; + } +} + +// Part 1 +static void bIT_actor_drop_draw_nrm(GAME* game, bg_item_common_info_c* common_info, bg_item_drop_c* drop); +static void bIT_actor_drop_move_plant(bg_item_drop_c* drop); +static void bIT_actor_drop_move_fly(bg_item_drop_c* drop); +static void bIT_actor_drop_move_wait(bg_item_drop_c* drop); + +static int bIT_actor_drop_entry_main(bg_item_drop_table_c* drop_info, bg_item_drop_c* src_drop) { + int res = FALSE; + bg_item_drop_c* drop = drop_info->drop_p; + int i; + + for (i = 0; i < drop_info->count; i++, drop++) { + if (drop->move_proc == NULL) { + bcopy(src_drop, drop, sizeof(bg_item_drop_c)); + drop->display_fg_item = src_drop->fg_item; + drop->mode = 0; + + if ((src_drop->flags & 1)) { + xyz_t_move(&drop->scale, &ZeroVec); + } else { + drop->scale.x = 1.0f; + drop->scale.y = 1.0f; + drop->scale.z = 1.0f; + } + + drop->angle.x = 0; + drop->angle.y = 0; + drop->angle.z = 0; + drop->_4C = 0; + xyz_t_move(&drop->offset, &ZeroVec); + drop->target_pos_fg_item = EMPTY_NO; + drop->draw_proc = &bIT_actor_drop_draw_nrm; + + if ((drop->flags & 2)) { + xyz_t_move(&drop->position, &src_drop->target_position); + drop->_58 = 0; + drop->_5A = 6000; + drop->_54 = 0.4f; + drop->_72 = 255; + drop->move_proc = &bIT_actor_drop_move_plant; + drop->dt_proc = &bIT_actor_drop_move_plant_destruct; + drop->_6E = 0; + } else { + xyz_t_move(&drop->last_position, &src_drop->position); + + if (drop->fg_item != HONEYCOMB) { + mActor_name_t* fg_item_p = mFI_GetUnitFG(src_drop->target_position); + + if (fg_item_p != NULL) { + drop->target_pos_fg_item = *fg_item_p; + + if ((drop->flags & 4) == 0) { + if ((drop->target_pos_fg_item >= HOLE_START && drop->target_pos_fg_item <= HOLE_END) || + drop->target_pos_fg_item == HOLE_SHINE) { + drop->flags |= 8; // target item is a hole + + if (drop->fg_item >= ITM_WHITE_PANSY_BAG && drop->fg_item <= ITM_YELLOW_TULIP_BAG) { + drop->display_fg_item = FLOWER_SEED; + } else if (drop->fg_item == ITM_SAPLING) { + drop->display_fg_item = TREE_SAPLING; + } else if (drop->fg_item == ITM_CEDAR_SAPLING) { + drop->display_fg_item = CEDAR_TREE_SAPLING; + } + } + } + } + } + + drop->flags |= 0x2000; + drop->_5C = search_position_angleY(&drop->position, &drop->target_position); + drop->_72 = 255; + drop->move_proc = &bIT_actor_drop_move_fly; + drop->dt_proc = &bIT_actor_drop_move_fly_destruct; + drop->_76 = 0; + drop->total_distance_y = fabsf(drop->target_position.y - drop->position.y); + drop->last_velocity_xz = src_drop->velocity_xz; + drop->last_velocity_y = src_drop->velocity_y; + } + + res = TRUE; + break; + } + } + + return res; +} + +static int fruit_set(mActor_name_t fg_item, int ut_x, int ut_z, s16 num, int drop_type, xyz_t* pos, + ACTOR* parent_actor) { + xyz_t drop_pos; + xyz_t fruit_pos; + xyz_t target_wpos; + bg_item_drop_c drop; + int flag; + int start; + int drop_res; + int i; + + mFI_UtNum2CenterWpos(&target_wpos, ut_x, ut_z); + target_wpos.y = mCoBG_GetBgY_OnlyCenter_FromWpos2(target_wpos, -1.0f); + + flag = FALSE; + if (fg_item != ITM_PRESENT && num == 1) { + PLAYER_ACTOR* player = GET_PLAYER_ACTOR_NOW(); + if (target_wpos.x > player->actor_class.world.position.x) { + flag = TRUE; + } + } + + start = 0; + if (flag) { + start = 1; + } + + for (i = start; i < start + (int)num; i++) { + static int unit_offset_part[3][2] = { { -1, 0 }, { 1, 0 }, { 0, 1 } }; + static xyz_t pos_part[3] = { + { -22.5f, 65.0f, 17.5f }, + { 22.5f, 72.0f, 12.5f }, + { -2.5f, 97.5f, 7.5f }, + }; + static xyz_t pos_part_honey_comb[3] = { + { -37.5f, 65.0f, 17.5f }, + { 37.5f, 72.0f, 12.5f }, + { -2.5f, 97.5f, 7.5f }, + }; + static xyz_t pos_part_present[3] = { + { -2.5f, 97.5f, 7.5f }, + { -37.5f, 65.0f, 17.5f }, + { 37.5f, 72.5f, 12.5f }, + }; + static xyz_t pos_part_palm_cc[2] = { + { -10.0f, 70.0f, 2.5f }, + { 10.0f, 75.0f, 0.0f }, + }; + static xyz_t fade_out = { -1.0f, -1.0f, -1.0f }; + + f32 dist_xz; + + if (drop_type == 1) { + mFI_UtNum2CenterWpos(&drop_pos, ut_x, ut_z + 1); + } else { + mFI_UtNum2CenterWpos(&drop_pos, ut_x + unit_offset_part[i][0], ut_z + unit_offset_part[i][1]); + } + + if (fg_item == ITM_PRESENT) { + drop_res = mFI_search_unit_around_high(&drop_pos, EMPTY_NO, &target_wpos); + xyz_t_add(&pos_part_present[i], &target_wpos, &fruit_pos); + } else if (fg_item == HONEYCOMB) { + drop_res = TRUE; + xyz_t_add(&pos_part_honey_comb[i], &target_wpos, &fruit_pos); + } else if (fg_item == ITM_FOOD_COCONUT) { + drop_res = mFI_search_unit_around_high(&drop_pos, EMPTY_NO, &target_wpos); + xyz_t_add(&pos_part_palm_cc[i], &target_wpos, &fruit_pos); + } else { + drop_res = mFI_search_unit_around_high(&drop_pos, EMPTY_NO, &target_wpos); + xyz_t_add(&pos_part[i], &target_wpos, &fruit_pos); + } + + drop_pos.y = mCoBG_GetBgY_OnlyCenter_FromWpos2(drop_pos, -1.0f); + drop.actorx_p = parent_actor; + drop.fg_item = fg_item; + xyz_t_move(&drop.position, &fruit_pos); + xyz_t_move(&drop.target_position, &drop_pos); + drop._8A = 0; + drop.flags = 0; + + if (drop_res || drop.fg_item == HONEYCOMB) { + if (ITEM_IS_FTR(drop.fg_item)) { + drop.flags = 0x200; // hidden furniture flag + } else if (drop.fg_item == ITM_MONEY_100) { + drop.flags |= 0x1000; // hidden money flag + } else { + drop.flags = 0x100; // standard drop flag? + + if (drop.fg_item == HONEYCOMB && drop_res) { + drop.flags |= 0x400; // honeycomb flag + } + } + + drop.layer = 0; + drop._7C = 0.25f; + + if ((drop.flags & 0x200)) { + /* dropped item is furniture leaf */ + drop._8A = 1; + drop.drop_speed = 26; + drop.acceleration_y = 0.15f; + drop._6E = 0; + } else if ((drop.flags & 0x400)) { + /* dropped item is honeycomb? */ + drop.drop_speed = 5; + drop.acceleration_y = -1.2f; + drop._6E = 1; + } else { + drop.drop_speed = 14 + i * 4; + drop._8A = 1 + i * 4; + drop.acceleration_y = -1.2f; + drop._6E = 1; + } + + drop.wait_counter = 0; + + /* If the item is something that has offset positions, apply that */ + if (IS_ITEM_GRASS(drop.fg_item) || (drop.fg_item >= ITM_SHELL0 && drop.fg_item <= ITM_SHELL7)) { + xyz_t temp_pos; + + bIT_actor_rand_pos_get_plus(drop.fg_item, &temp_pos, &drop.target_position); + xyz_t_move(&drop.target_position, &temp_pos); + } + + dist_xz = search_position_distanceXZ(&drop.target_position, &drop.position); + func_calc_spec_drop_time(dist_xz, drop.target_position.y - drop.position.y, drop.drop_speed, + drop.acceleration_y, &drop.velocity_xz, &drop.velocity_y); + + if (bIT_actor_drop_entry_main(&bIT_CLIP->bg_item_common_p->fruit_drop_info, &drop) && + drop.fg_item != HONEYCOMB) { + mFI_SetFG_common(RSV_NO, drop_pos, FALSE); + } + + xyz_t_move(pos, &drop_pos); + } else { + drop.flags = 0; + if (ITEM_IS_FTR(drop.fg_item)) { + drop._8A = 1; + drop.flags = 0x200; + } + + if ((drop.flags & 0x200)) { + drop.drop_speed = 26; + drop.acceleration_y = 0.15f; + } else { + drop.drop_speed = 14 + i * 4; + drop._8A = 1 + i * 4; + drop.acceleration_y = -1.2f; + } + + drop.target_position.y = target_wpos.y; + drop.flags |= 0x20 | 0x4; + drop._7C = 0.0f; + drop._78 = 12; + drop._70 = 27; + drop.layer = 0; + + // duplicate set in these if-else blocks + if ((drop.flags & 0x200)) { + drop.drop_speed = 26; + drop.acceleration_y = 0.15f; + } else { + drop.drop_speed = 14 + i * 4; + drop.acceleration_y = -1.2f; + } + + drop._6E = 0; + drop.wait_counter = 0; + + if (IS_ITEM_GRASS(drop.fg_item) || (drop.fg_item >= ITM_SHELL0 && drop.fg_item <= ITM_SHELL7)) { + xyz_t temp_pos; + + bIT_actor_rand_pos_get_plus(drop.fg_item, &temp_pos, &drop.target_position); + xyz_t_move(&drop.target_position, &temp_pos); + } + + dist_xz = search_position_distanceXZ(&drop.target_position, &drop.position); + func_calc_spec_drop_time(dist_xz, drop.target_position.y - drop.position.y, drop.drop_speed, + drop.acceleration_y, &drop.velocity_xz, &drop.velocity_y); + + bIT_actor_drop_entry_main(&bIT_CLIP->bg_item_common_p->fruit_drop_info, &drop); + xyz_t_move(pos, &fade_out); + } + } + + return FALSE; +} + +static int bIT_fruit_set(mActor_name_t fg_item, int ut_x, int ut_z, s16 count, int type) { + xyz_t tmp; + + return fruit_set(fg_item, ut_x, ut_z, count, type, &tmp, NULL); +} + +typedef struct fruit_drop_s { + mActor_name_t src_tree_item; + mActor_name_t dropped_item; + mActor_name_t dst_tree_item; + s16 drop_count; +} bIT_fruit_drop_c; + +static void drop_fruit(mActor_name_t fg_item, int ut_x, int ut_z, xyz_t* drop_pos, ACTOR* parent_actor) { + static bIT_fruit_drop_c fg_ytable[] = { + { TREE_APPLE_FRUIT, ITM_FOOD_APPLE, TREE_APPLE_NOFRUIT_0, 3 }, + { TREE_ORANGE_FRUIT, ITM_FOOD_ORANGE, TREE_ORANGE_NOFRUIT_0, 3 }, + { TREE_PEACH_FRUIT, ITM_FOOD_PEACH, TREE_PEACH_NOFRUIT_0, 3 }, + { TREE_PEAR_FRUIT, ITM_FOOD_PEAR, TREE_PEAR_NOFRUIT_0, 3 }, + { TREE_CHERRY_FRUIT, ITM_FOOD_CHERRY, TREE_CHERRY_NOFRUIT_0, 3 }, + { TREE_1000BELLS, ITM_MONEY_1000, TREE, 3 }, + { TREE_10000BELLS, ITM_MONEY_10000, TREE, 3 }, + { TREE_30000BELLS, ITM_MONEY_30000, TREE, 3 }, + { TREE_100BELLS, ITM_MONEY_100, TREE, 3 }, + { TREE_FTR, FTR_FAN, TREE, 1 }, + { TREE_BEES, HONEYCOMB, 1 }, + { TREE_PRESENT, ITM_PRESENT, 1 }, + { TREE_BELLS, ITM_MONEY_100, TREE, 1 }, + { TREE_PALM_FRUIT, ITM_FOOD_COCONUT, TREE_PALM_NOFRUIT_0, 2 }, + { CEDAR_TREE_BELLS, ITM_MONEY_100, CEDAR_TREE, 1 }, + { CEDAR_TREE_FTR, FTR_FAN, CEDAR_TREE, 1 }, + { CEDAR_TREE_BEES, HONEYCOMB, CEDAR_TREE, 1 }, + { GOLD_TREE_BELLS, ITM_MONEY_100, GOLD_TREE, 1 }, + { GOLD_TREE_FTR, FTR_FAN, GOLD_TREE, 1 }, + { GOLD_TREE_BEES, HONEYCOMB, GOLD_TREE, 1 }, + { GOLD_TREE_SHOVEL, ITM_GOLDEN_SHOVEL, 1 }, + }; + + xyz_t tree_pos; + int i; + + for (i = 0; i < ARRAY_COUNT(fg_ytable); i++) { + if (fg_item == fg_ytable[i].src_tree_item) { + mActor_name_t item = fg_ytable[i].dropped_item; + + if (item == FTR_FAN) { + int list = mSP_LISTTYPE_ABC; + mActor_name_t ftr_item; + + if (Common_Get(now_private)->destiny.type == mPr_DESTINY_GOODS_LUCK) { + if (fqrand() >= 0.5f) { + list = mSP_LISTTYPE_EVENT; // pull from Crazy Redd's list + } else { + list = mSP_LISTTYPE_LOTTERY; // pull from raffle list + } + } + + mSP_SelectRandomItem_New(NULL, &ftr_item, 1, NULL, 0, mSP_KIND_FURNITURE, list, FALSE); + fruit_set(ftr_item, ut_x, ut_z, fg_ytable[i].drop_count, 0, drop_pos, parent_actor); + } else { + mActor_name_t drop_item = item; + + if (fg_item == TREE_BELLS || fg_item == CEDAR_TREE_BELLS || fg_item == GOLD_TREE_BELLS) { + if (Common_Get(now_private)->destiny.type == mPr_DESTINY_MONEY_LUCK) { + drop_item = ITM_MONEY_1000; + } + } + + fruit_set(drop_item, ut_x, ut_z, fg_ytable[i].drop_count, 0, drop_pos, parent_actor); + } + + mFI_UtNum2CenterWpos(&tree_pos, ut_x, ut_z); + tree_pos.y = mCoBG_GetBgY_OnlyCenter_FromWpos2(tree_pos, -1.0f); + mFI_SetFG_common(fg_ytable[i].dst_tree_item, tree_pos, TRUE); + break; + } + } +} + +static int BIT_actor_tree_cutcount_check(GAME* game, int ut_x, int ut_z) { + bg_item_common_c* common_p = bIT_CLIP->bg_item_common_p; + int res = 0; + int bx; + int i; + int bz; + + for (i = 0; i < common_p->item_table.count; i++) { + bx = common_p->item_table.block_info_tbl[i].block_x; + bz = common_p->item_table.block_info_tbl[i].block_z; + + if (ut_x >= bx * UT_X_NUM && ut_x < (bx + 1) * UT_X_NUM && ut_z >= bz * UT_Z_NUM && + ut_z < (bz + 1) * UT_Z_NUM) { + int z = (ut_z - bz * UT_Z_NUM); + int idx = z * UT_X_NUM + (ut_x - bx * UT_X_NUM); + + res = common_p->block_info_table.info_tbl[i].info[idx]; + if (res > 0) { + common_p->block_info_table.info_tbl[i].info[idx] = res - 1; + res--; + } + + break; + } + } + + return res; +} + +static void bg_item_tree_fruit_drop(mActor_name_t fg_item, int ut_x, int ut_z, xyz_t* drop_pos) { + if (fg_item == TREE || fg_item == CEDAR_TREE || fg_item == GOLD_TREE) { + if (Common_Get(clip).insect_clip != NULL && Common_Get(clip).insect_clip->set_pl_act_tim_proc != NULL) { + Common_Get(clip).insect_clip->set_pl_act_tim_proc(4, ut_x, ut_z); + } + } else if (fg_item == TREE_BEES || fg_item == CEDAR_TREE_BEES || fg_item == GOLD_TREE_BEES) { + ACTOR* actor; + static xyz_t wait_pos = { -1.0f, -1.0f, -1.0f }; + GAME_PLAY* play = (GAME_PLAY*)gamePT; + + actor = Actor_info_make_actor(&play->actor_info, (GAME*)play, mAc_PROFILE_BEE, wait_pos.x, wait_pos.y, + wait_pos.z, 0, 0, 0, play->block_table.block_x, play->block_table.block_z, -1, + EMPTY_NO, 0, -1, -1); + if (actor != NULL) { + drop_fruit(fg_item, ut_x, ut_z, drop_pos, actor); + + if (drop_pos->x == -1.0f && drop_pos->y == -1.0f && drop_pos->z == -1.0f) { + Actor_delete(actor); + } + } else { + xyz_t_move(drop_pos, &wait_pos); + } + } else { + drop_fruit(fg_item, ut_x, ut_z, drop_pos, NULL); + } +} + +static void bIT_actor_dig_hole_effect_entry(mActor_name_t fg_item, xyz_t* pos, u16 frames, u16 wait_frames) { + int ut_x; + int ut_z; + + if (mFI_Wpos2UtNum(&ut_x, &ut_z, *pos)) { + mFI_UtNumtoFGSet_common(RSV_NO, ut_x, ut_z, FALSE); + mFI_UtNum2DepositOFF(ut_x, ut_z); + } + + bIT_actor_hole_effect_entry(bIT_CLIP->bg_item_common_p->hole, fg_item, pos, frames, wait_frames, 1, 0); +} + +static void bIT_actor_bury_hole_effect_entry(mActor_name_t fg_item, xyz_t* pos, u16 frames) { + bIT_actor_hole_effect_entry(bIT_CLIP->bg_item_common_p->hole, fg_item, pos, frames, 0, 2, 0); +} + +static int bIT_actor_hole_effect_entry(bg_item_hole_c* hole, mActor_name_t fg_item, xyz_t* pos, u16 frames, + u16 wait_frames, s16 mode, s16 wait_type) { + int i; + int hole_no; + int res; + + res = FALSE; + hole_no = -1; + + switch (mode) { + case 1: + if (fg_item == SHINE_SPOT) { + hole_no = HOLE_SHINE; + } else { + int hole_num = mCoBG_GetHoleNumber(*pos); + if (hole_num >= 0) { + hole_no = HOLE_START + hole_num; + } + } + break; + case 2: { + mActor_name_t* fg_p = mFI_GetUnitFG(*pos); + + if (fg_p != NULL) { + hole_no = *fg_p; + mFI_SetFG_common(RSV_NO, *pos, TRUE); + } + break; + } + } + + if (hole_no >= 0) { + xyz_t target_pos; + + mFI_Wpos2UtCenterWpos(&target_pos, *pos); + target_pos.y = mCoBG_GetBgY_OnlyCenter_FromWpos2(*pos, -1.0f); + for (i = 0; res == FALSE && i < bIT_HOLE_NUM; i++, hole++) { + if (hole->mode == 0) { + switch (mode) { + case 1: + hole->fg_item = fg_item; + hole->hole_fg_item = hole_no; + hole->scale = 0.0f; + res = TRUE; + break; + case 2: + hole->fg_item = fg_item; + hole->hole_fg_item = hole_no; + hole->scale = 1.0f; + xyz_t_move(&hole->position, &target_pos); + mFI_SetFG_common(RSV_NO, hole->position, TRUE); + res = TRUE; + break; + } + + if (res) { + hole->mode = mode; + xyz_t_move(&hole->position, &target_pos); + hole->counter = 0; + hole->max_counter = frames; + hole->wait_counter = wait_frames + 1; + hole->wait_type = wait_type; + } + } + } + } + + return res; +} + +static void bIT_actor_hole_effect_destruct(bg_item_hole_c* hole) { + switch (hole->mode) { + case 1: + mFI_SetFG_common(hole->hole_fg_item, hole->position, TRUE); + mFI_Wpos2DepositOFF(hole->position); + break; + case 2: + bIT_common_hole_throw(hole->fg_item, hole->hole_fg_item, &hole->position, 1); + + if (hole->fg_item == EMPTY_NO && hole->hole_fg_item == HOLE_SHINE) { + mFI_SetFG_common(SHINE_SPOT, hole->position, TRUE); + } + + break; + } + + hole->mode = 0; +} + +static void bIT_actor_hole_effect_move(bg_item_hole_c* hole) { + if (hole->wait_counter != 0) { + hole->wait_counter--; + } + + if (hole->wait_counter == 0) { + switch (hole->mode) { + case 1: + hole->scale = (f32)hole->counter / (f32)hole->max_counter; + hole->counter++; + + if (hole->counter > hole->max_counter) { + mFI_SetFG_common(hole->hole_fg_item, hole->position, TRUE); + mFI_Wpos2DepositOFF(hole->position); + hole->mode = 0; + } + + break; + case 2: + hole->scale = 1.0f - (f32)hole->counter / (f32)hole->max_counter; + hole->counter++; + + if (hole->counter > hole->max_counter) { + bIT_common_hole_throw(hole->fg_item, hole->hole_fg_item, &hole->position, 0); + if (hole->fg_item == EMPTY_NO && hole->hole_fg_item == HOLE_SHINE) { + mFI_SetFG_common(EMPTY_NO, hole->position, TRUE); + } + + hole->mode = 0; + } + + break; + } + } +} + +static void bIT_actor_hole_effect_draw(GAME* game, bg_item_common_info_c* common_info, bg_item_hole_c* hole) { + if (hole->wait_counter == 0 && hole->mode != 0) { + xyz_t scale; + + scale.x = hole->scale * 0.01f; + scale.y = hole->scale * 0.01f; + scale.z = hole->scale * 0.01f; + bit_cmn_single_drawS(game, common_info, hole->hole_fg_item, &hole->position, &hole->angle, &scale, 255, NULL, + NULL, NULL); + } +} + +static int bIT_actor_player_drop_entry(GAME* game, mActor_name_t fg_item, int ut_x, int ut_z, s16 layer) { + PLAYER_ACTOR* player = GET_PLAYER_ACTOR((GAME_PLAY*)game); + int res; + xyz_t target_pos; + xyz_t pos; + mActor_name_t* fg_p; + u16 drop_type; + + res = 0; + pos.x = 0.0f; + pos.y = 0.0f; + pos.z = 0.0f; + + mFI_UtNum2CenterWpos(&pos, ut_x, ut_z); + pos.y = mCoBG_GetBgY_OnlyCenter_FromWpos2(pos, -1.0f); + fg_p = mFI_GetUnitFG(pos); + + if (fg_p != NULL) { + if (*fg_p == EMPTY_NO || (*fg_p >= HOLE_START && *fg_p <= HOLE_END) || *fg_p == HOLE_SHINE) { + drop_type = 0; + xyz_t_move(&target_pos, &player->actor_class.world.position); + target_pos.y += 50.0f; + + if (ITEM_NAME_GET_TYPE(fg_item) == NAME_TYPE_ITEM0) { + if (ITEM_NAME_GET_CAT(fg_item) == 8) { + drop_type |= 3; + } else if (ITEM_NAME_GET_CAT(fg_item) == 0) { + drop_type |= 1; + } + } else { + drop_type |= 1; + } + + if (bIT_actor_drop_entry(&bIT_CLIP->bg_item_common_p->drop_info, fg_item, &target_pos, &pos, drop_type, + layer)) { + if (!((*fg_p >= HOLE_START && *fg_p <= HOLE_END) || *fg_p == HOLE_SHINE)) { + mFI_SetFG_common(RSV_NO, pos, FALSE); + } + + res = 1; + } + } + } else { + res = -1; + } + + return res; +} + +static int bIT_drop_entry_v1(mActor_name_t fg_item, xyz_t* pos, xyz_t* target_pos) { + int res = 0; + mActor_name_t* fg_p = mFI_GetUnitFG(*target_pos); + + if (*fg_p == EMPTY_NO || (*fg_p >= HOLE_START && *fg_p <= HOLE_END) || *fg_p == HOLE_SHINE) { + u16 drop_type = 0; + + if (ITEM_NAME_GET_TYPE(fg_item) == NAME_TYPE_ITEM0) { + if (ITEM_NAME_GET_CAT(fg_item) == 8) { + drop_type = 3; + } else if (ITEM_NAME_GET_CAT(fg_item) == 0) { + drop_type = 1; + } + } + + if (bIT_actor_drop_entry(&bIT_CLIP->bg_item_common_p->drop_info, fg_item, pos, target_pos, drop_type, 0)) { + if (!((*fg_p >= HOLE_START && *fg_p <= HOLE_END) || *fg_p == HOLE_SHINE)) { + mFI_SetFG_common(RSV_NO, *target_pos, FALSE); + } + + res = 1; + } + } else { + res = -1; + } + + return res; +} + +static void bIT_actor_fly_entry(mActor_name_t fg_item, xyz_t* pos, s16 angle_y) { + xyz_t target_pos; + bg_item_drop_c drop; + f32 dist_xz; + + target_pos.x = pos->x + 40.0f * sin_s(angle_y); + target_pos.z = pos->z + 40.0f * cos_s(angle_y); + target_pos.y = pos->y; + + if (fg_item != EMPTY_NO && fg_item != RSV_NO) { + mFI_SetFG_common(EMPTY_NO, *pos, TRUE); + } + + drop.fg_item = fg_item; + xyz_t_move(&drop.position, pos); + xyz_t_move(&drop.target_position, &target_pos); + drop._78 = 7; + drop._7C = 0.25f; + drop._70 = 17; + drop.layer = 0; + + if (angle_y > 0) { + drop.flags = 0x40 | 0x20 | 0x10 | 0x4; + } else { + drop.flags = 0x20 | 0x10 | 0x4; + } + + if ((drop.flags & 0x200)) { + drop.drop_speed = 26; + drop.acceleration_y = 0.15f; + } else { + drop.drop_speed = 17; + drop.acceleration_y = -1.2f; + } + + drop._6E = 0; + drop.actorx_p = NULL; + drop.wait_counter = 0; + + if (IS_ITEM_GRASS(drop.fg_item) || (drop.fg_item >= ITM_SHELL0 && drop.fg_item <= ITM_SHELL7)) { + xyz_t tpos; + + bIT_actor_rand_pos_get_plus(drop.fg_item, &tpos, &drop.target_position); + xyz_t_move(&drop.target_position, &tpos); + } + + dist_xz = search_position_distanceXZ(&drop.target_position, &drop.position); + func_calc_spec_drop_time(dist_xz, drop.target_position.y - drop.position.y, (f32)(int)drop.drop_speed, + drop.acceleration_y, &drop.velocity_xz, &drop.velocity_y); + bIT_actor_drop_entry_main(&bIT_CLIP->bg_item_common_p->drop_info, &drop); +} + +static int bIT_actor_drop_entry(bg_item_drop_table_c* drop_info, mActor_name_t fg_item, xyz_t* pos, xyz_t* target_pos, + u16 flags, s16 layer) { + bg_item_drop_c drop; + f32 dist_xz; + + drop.fg_item = fg_item; + xyz_t_move(&drop.position, pos); + xyz_t_move(&drop.target_position, target_pos); + + drop.flags = flags; + drop.layer = layer; + drop._7C = 0.25f; + + if ((flags & 0x80)) { + drop.wait_counter = 46; + } else { + drop.wait_counter = 0; + } + + if ((flags & 0x200)) { + drop.drop_speed = 26; + drop.acceleration_y = 0.15f; + drop._6E = 0; + } else { + drop.drop_speed = 14; + drop.acceleration_y = -1.2f; + drop._6E = 1; + } + + drop.actorx_p = NULL; + + if (IS_ITEM_GRASS(drop.fg_item) || (drop.fg_item >= ITM_SHELL0 && drop.fg_item <= ITM_SHELL7)) { + xyz_t tpos; + + bIT_actor_rand_pos_get_plus(drop.fg_item, &tpos, &drop.target_position); + xyz_t_move(&drop.target_position, &tpos); + } + + dist_xz = search_position_distanceXZ(&drop.target_position, &drop.position); + func_calc_spec_drop_time(dist_xz, drop.target_position.y - drop.position.y, (f32)(int)drop.drop_speed, + drop.acceleration_y, &drop.velocity_xz, &drop.velocity_y); + return bIT_actor_drop_entry_main(drop_info, &drop); +} + +static void bIT_actor_drop_move(bg_item_drop_table_c* drop_info) { + bg_item_drop_c* drop = drop_info->drop_p; + int i; + + for (i = 0; i < drop_info->count; i++, drop++) { + if (drop->layer > 0) { + drop->layer--; + } else if (drop->wait_counter > 0) { + drop->wait_counter--; + + if (drop->wait_counter == 0 && (drop->flags & 0x80)) { + sAdo_OngenTrgStart(0x2A, &drop->position); + } + } else if (drop->move_proc != NULL) { + xyz_t_move(&drop->offset, &ZeroVec); + drop->move_proc(drop); + } + } +} + +static void bIT_actor_drop_destruct(bg_item_drop_table_c* drop_info) { + bg_item_drop_c* drop = drop_info->drop_p; + int i; + + for (i = 0; i < drop_info->count; i++, drop++) { + if (drop->move_proc != NULL && drop->dt_proc != NULL) { + drop->dt_proc(drop); + drop->dt_proc = NULL; + } + } +} + +static void bIT_actor_drop_move_plant(bg_item_drop_c* drop) { + s16 last_58 = drop->_58; + s16 now_58; + + drop->_58 = last_58 + drop->_5A; + now_58 = drop->_58; + + if ((drop->flags & 1)) { + f32 scale = sinf_table(SHORT2RAD_ANGLE2(now_58)) * drop->_54; + f32 x = 1.0f - scale; + + scale += 1.0f; + drop->scale.x = x; + drop->scale.y = scale; + drop->scale.z = 1.0f; + } + + if ((last_58 < 0 && now_58 >= 0) || ((u16)last_58 < (u16)SHT_MAX_S && (u16)now_58 >= (u16)SHT_MIN_S)) { + f32 tmp; + + drop->_54 *= 0.2f; + tmp = (f32)(int)drop->_5A + 1500.0f; + drop->_5A = (int)tmp; + } + + if (ABS(drop->_54) < 0.02f) { + if (drop->fg_item == GOLD_TREE_SAPLING) { + xyz_t effect_pos; + + effect_pos.x = drop->position.x + 13.0f; + effect_pos.y = drop->position.y + 33.0f; + effect_pos.z = drop->position.z + 10.0f; + + eEC_CLIP->effect_make_proc(eEC_EFFECT_KIGAE_LIGHT, effect_pos, 2, 0, gamePT, RSV_NO, -1, 0); + } + + mFI_SetFG_common(drop->fg_item, drop->position, TRUE); + drop->move_proc = NULL; + drop->draw_proc = NULL; + drop->dt_proc = NULL; + } +} + +static void bIT_actor_drop_move_bury_destruct(bg_item_drop_c* drop) { + if (drop->move_proc != NULL) { + drop->move_proc = NULL; + drop->draw_proc = NULL; + drop->dt_proc = NULL; + } +} + +static void bIT_actor_drop_move_bury(bg_item_drop_c* drop) { + if (drop->scale.x > 0.0f) { + drop->scale.x += -0.1f; + drop->scale.y = drop->scale.x; + drop->scale.z = drop->scale.x; + } else { + drop->move_proc = NULL; + drop->draw_proc = NULL; + drop->dt_proc = NULL; + } +} + +static void bIT_actor_drop_move_bury_change(bg_item_drop_c* drop) { + drop->scale.x = 1.0f; + drop->scale.y = 1.0f; + drop->scale.z = 1.0f; + bIT_actor_bury_hole_effect_entry(drop->fg_item, &drop->target_position, 46); + drop->velocity_xz = 0.0f; + drop->velocity_y = 0.0f; + drop->position.y = drop->target_position.y; + drop->move_proc = &bIT_actor_drop_move_bury; + drop->dt_proc = &bIT_actor_drop_move_bury_destruct; +} + +// Part 2 + +static void bIT_actor_drop_wait_bee(bg_item_drop_c* drop) { + drop->_90--; + + if (drop->_90 == 0) { + if (drop->actorx_p != NULL) { + xyz_t_move(&drop->actorx_p->world.position, &drop->position); + } + + drop->_88 = 120; + drop->move_proc = &bIT_actor_drop_move_wait; + } +} + +static void bIT_actor_drop_move_wait(bg_item_drop_c* drop) { + if (drop->_88 != 0) { + drop->_88--; + drop->_76 = 0; + drop->_70 = 5; + } else if (drop->_76 <= 255) { + drop->_72 = 255 - drop->_76; + drop->_76 += drop->_70; + } else { + drop->_72 = 0; + drop->move_proc = NULL; + drop->draw_proc = NULL; + drop->dt_proc = NULL; + } +} + +static void bIT_actor_drop_move_fly(bg_item_drop_c* drop) { + f32 vel_x; + f32 vel_z; + f32 scale = drop->_4C / (f32)(int)drop->drop_speed; + + if (drop->_8A > 0) { + if (drop->_8A == 1) { + if ((drop->flags & 0x100)) { + sAdo_OngenTrgStart(0x43D, &drop->position); + } else if ((drop->flags & 0x200)) { + sAdo_OngenTrgStart(0x40C, &drop->position); + } + } + + drop->_8A--; + } + + if ((drop->flags & 0x200)) { + f32 dist_y = fabsf(drop->target_position.y - drop->position.y); + f32 percent_y = dist_y / drop->total_distance_y; + f32 temp0 = scale * 65536.0f; + int dir0 = (int)(temp0 * (1.0f / 65536.0f)); + s16 angle = (s16)(temp0 - dir0 * 65536.0f); + + drop->offset.x = 18.0f * sin_s(angle) * percent_y; + } + + if ((drop->flags & 1)) { + f32 t = 1.0f - (1.0f - scale) * (1.0f - scale); + f32 s = 0.1f + t * 0.9f; + + drop->scale.x = s; + drop->scale.y = s; + drop->scale.z = s; + } + + vel_x = drop->velocity_xz * sin_s(drop->_5C); + vel_z = drop->velocity_xz * cos_s(drop->_5C); + + drop->velocity_y = drop->acceleration_y * drop->_4C; + + drop->position.x = drop->last_position.x + vel_x * drop->_4C; + drop->position.y = drop->last_position.y + drop->last_velocity_y * drop->_4C + + (drop->acceleration_y * 0.5f) * drop->_4C * drop->_4C; + drop->position.z = drop->last_position.z + vel_z * drop->_4C; + + if ((drop->flags & 0x20) && drop->_4C > (f32)drop->_78) { + if (drop->_76 <= 255) { + drop->_72 = 255 - drop->_76; + drop->_76 += drop->_70; + } else { + drop->_72 = 0; + drop->move_proc = NULL; + drop->draw_proc = NULL; + } + } + + if ((drop->flags & 0x10)) { + if ((drop->flags & 0x40)) { + drop->angle.z -= 0x123; + } else { + drop->angle.z += 0x123; + } + } + + if (drop->_4C == (f32)(drop->drop_speed - 1) && (drop->flags & 0x2000)) { + drop->flags &= ~0x2000; + + if ((drop->flags & 0x20) == 0) { + if (drop->fg_item == ITM_FOOD_APPLE || drop->fg_item == ITM_FOOD_CHERRY || drop->fg_item == ITM_FOOD_PEAR || + drop->fg_item == ITM_FOOD_PEACH || drop->fg_item == ITM_FOOD_ORANGE || + drop->fg_item == ITM_FOOD_COCONUT) { + sAdo_OngenTrgStart(0x127, &drop->position); + } else if (drop->fg_item >= ITM_MONEY_START && drop->fg_item <= (ITM_MONEY_END + 1)) { + sAdo_OngenTrgStart(0x444, &drop->position); + } else if ((drop->flags & 0x200) == 0) { + sAdo_OngenTrgStart(0x128, &drop->position); + } + } + } + + if (((drop->flags & 0x200) && drop->_4C >= (f32)drop->drop_speed) || + (drop->velocity_y < 0.0f && drop->position.y <= drop->target_position.y)) { + xyz_t_move(&drop->position, &drop->target_position); + + if ((drop->flags & 8)) { + bIT_actor_drop_move_bury_change(drop); + } else if (drop->_6E) { + f32 xz; + f32 vel_y; + + drop->flags &= ~1; + xyz_t_move(&drop->position, &drop->target_position); + drop->velocity_xz = 0.0f; + drop->drop_speed = (f32)drop->drop_speed * drop->_7C; + xyz_t_move(&drop->last_position, &drop->position); + func_calc_spec_drop_time(0.0f, 0.0f, drop->drop_speed, drop->acceleration_y, &xz, &vel_y); + drop->velocity_y = vel_y; + drop->last_velocity_xz = drop->velocity_xz; + drop->last_velocity_y = drop->velocity_y; + drop->_4C = 1.0f; + drop->_6E--; + } else if (drop->fg_item == HONEYCOMB) { + drop->_90 = 1; + drop->move_proc = &bIT_actor_drop_wait_bee; + } else { + drop->move_proc = NULL; + drop->draw_proc = NULL; + + if ((drop->flags & 4) == 0) { + mFI_SetFG_common(drop->fg_item, drop->target_position, TRUE); + } + } + } else { + drop->_4C += 0.5f; + } +} + +static void bIT_actor_drop_draw(GAME* game, bg_item_common_info_c* common_info, bg_item_drop_table_c* drop_info) { + bg_item_drop_c* drop = drop_info->drop_p; + int i; + + for (i = 0; i < drop_info->count; i++, drop++) { + if (drop->draw_proc != NULL) { + drop->draw_proc(game, common_info, drop); + } + } +} + +static void bIT_actor_drop_draw_nrm(GAME* game, bg_item_common_info_c* common_info, bg_item_drop_c* drop) { + xyz_t pos; + xyz_t scale; + + scale.x = drop->scale.x * 0.01f; + scale.y = drop->scale.y * 0.01f; + scale.z = drop->scale.z * 0.01f; + xyz_t_add(&drop->position, &drop->offset, &pos); + bit_cmn_single_drawS(game, common_info, drop->display_fg_item, &pos, &drop->angle, &scale, drop->_72, NULL, NULL, + NULL); +} + +typedef struct draw_pos_entry_s { + MtxF mtx; + u16 cull_flag; + u8 alpha; + u8 pal_no; + s8 gfx_no; +} bIT_draw_pos_entry_c; + +static void bit_cmn_s_single_draw_loop_type1(GRAPH* graph, Gfx** gfx_pp, bg_item_draw_list_c* shadow_draw_list, + int shadow_vtx_num, Vtx* shadow_vtx, bIT_draw_pos_entry_c* draw_pos_entry, + Gfx** display_list_tbl) { + Gfx* dl = display_list_tbl[shadow_draw_list->mat_idx + draw_pos_entry->gfx_no]; + Matrix_put(&draw_pos_entry->mtx); + + gSPMatrix((*gfx_pp)++, _Matrix_to_Mtx_new(graph), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPVertex((*gfx_pp)++, shadow_vtx, shadow_vtx_num, 0); + gSPDisplayList((*gfx_pp)++, dl); +} + +static void bit_cmn_single_draw_loop_type1(GRAPH* graph, Gfx** gfx_pp, bIT_draw_pos_entry_c* draw_pos_entry, + bg_item_draw_list_c* draw_list, Gfx** display_list_table) { + Gfx* dl = display_list_table[draw_list->mat_idx + draw_pos_entry->gfx_no]; + + gSPDisplayList((*gfx_pp)++, display_list_table[draw_list->gfx_idx]); + if (draw_pos_entry->alpha == 255) { + gDPSetRenderMode((*gfx_pp)++, G_RM_FOG_SHADE_A, G_RM_AA_ZB_TEX_EDGE2); + gDPSetCombineLERP((*gfx_pp)++, TEXEL0, 0, SHADE, 0, 0, 0, 0, TEXEL0, PRIMITIVE, 0, COMBINED, 0, 0, 0, 0, + COMBINED); + } else { + gDPSetRenderMode((*gfx_pp)++, G_RM_FOG_SHADE_A, G_RM_AA_ZB_XLU_SURF2); + gDPSetCombineLERP((*gfx_pp)++, TEXEL0, 0, SHADE, 0, TEXEL0, 0, ENVIRONMENT, 0, PRIMITIVE, 0, COMBINED, 0, 0, 0, + 0, COMBINED); + gDPSetEnvColor((*gfx_pp)++, 255, 255, 255, draw_pos_entry->alpha); + } + + Matrix_put(&draw_pos_entry->mtx); + + gSPMatrix((*gfx_pp)++, _Matrix_to_Mtx_new(graph), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPDisplayList((*gfx_pp)++, dl); +} + +static void bit_cmn_single_draw_item_shadow(GRAPH* graph, bg_item_draw_part_c* draw_part, + bIT_draw_pos_entry_c* draw_pos_entry, f32 shadow_pos, rgba_t* color) { + bg_item_draw_list_c* draw_list = draw_part->shadow_draw_list; + + if (draw_list != NULL) { + Vtx* vtx; + Gfx* gfx; + Gfx* gfx2; + + OPEN_DISP(graph); + gfx = NOW_SHADOW_DISP; + vtx = (Vtx*)GRAPH_ALLOC_TYPE(graph, Vtx, draw_part->shadow_vtx_count); + + if (vtx != NULL) { + bIT_copy_vtx(vtx, draw_part->shadow_vtx_p, draw_part->shadow_vtx_count, draw_part->shadow_vtx_fix_table_p, + (int)(shadow_pos * draw_part->shadow_len)); + } else { + vtx = draw_part->shadow_vtx_p; + } + + gSPDisplayList(gfx++, draw_part->display_list_table_p[draw_list->gfx_idx]); + gDPSetPrimColor(gfx++, 0, color->a, color->r, color->g, color->b, 255); + gfx2 = gfx; + bit_cmn_s_single_draw_loop_type1(graph, &gfx2, draw_list, draw_part->shadow_vtx_count, vtx, draw_pos_entry, + draw_part->display_list_table_p); + + SET_SHADOW_DISP(gfx2); + CLOSE_DISP(graph); + } +} + +static void bit_cmn_single_draw_BT_shadow(GAME* game, bg_item_common_info_c* common_info, + bg_item_type_data_c* type_data, xyz_t* pos, s_xyz* angle, xyz_t* scale, + u8 alpha, f32 shadow_pos, rgba_t* shadow_color) { + static bIT_draw_pos_entry_c draw_pos; + bg_item_draw_part_c* draw_part; + + if (type_data == NULL || type_data->type == bIT_DRAW_TYPE_NONE || type_data->type < 0) { + return; + } + + Matrix_push(); + // ISSUE + draw_part = draw_part_table_a[type_data->type].draw_part_p; + draw_pos.gfx_no = type_data->_00; + draw_pos.cull_flag = FALSE; + draw_pos.alpha = alpha; + + Matrix_translate(pos->x, pos->y, pos->z, 0); + Matrix_RotateY(angle->y, 1); + Matrix_RotateX(angle->x, 1); + Matrix_RotateZ(angle->z, 1); + Matrix_scale(scale->x, scale->y, scale->z, 1); + Matrix_get(&draw_pos.mtx); + bit_cmn_single_draw_item_shadow(game->graph, draw_part, &draw_pos, shadow_pos, shadow_color); + Matrix_pull(); +} + +static void fg_no2fg_type(mActor_name_t fg_no, bg_item_type_data_c* type_data, mCoBG_Collision_u* collision, + bg_item_type_data_c** type_data_table) { + int fg_type = ITEM_NAME_GET_TYPE((mActor_name_t)fg_no); + + switch (fg_type) { + case NAME_TYPE_ITEM0: { + bg_item_type_data_c* src; + + switch (ITEM_NAME_GET_CAT((mActor_name_t)fg_no)) { + case 0: { + src = type_data_table[bIT_TYPE_CAT_BG_ITEM] + fg_no; + type_data->_00 = src->_00; + type_data->type = src->type; + type_data->pos_x_tbl_p = src->pos_x_tbl_p; + type_data->pos_z_tbl_p = src->pos_z_tbl_p; + + /* Convert grass to sand if necessary */ + if (mCoBG_CheckSandHole_ClData(collision)) { + if (type_data->type == bIT_DRAW_TYPE_HOLE00_G) { + type_data->type = bIT_DRAW_TYPE_HOLE00_S; + } else if (type_data->type == bIT_DRAW_TYPE_CRACK00_G) { + type_data->type = bIT_DRAW_TYPE_CRACK00_S; + } + } + + break; + } + + case 8: { + src = type_data_table[bIT_TYPE_CAT_BG_ITEM2] + fg_no - ENV_START; + type_data->_00 = src->_00; + type_data->type = src->type; + type_data->pos_x_tbl_p = src->pos_x_tbl_p; + type_data->pos_z_tbl_p = src->pos_z_tbl_p; + + break; + } + + default: { + src = type_data_table[bIT_TYPE_CAT_DUMMY]; + type_data->_00 = src->_00; + type_data->type = src->type; + type_data->pos_x_tbl_p = src->pos_x_tbl_p; + type_data->pos_z_tbl_p = src->pos_z_tbl_p; + + break; + } + } + break; + } + + case NAME_TYPE_FTR0: + case NAME_TYPE_FTR1: { + bg_item_type_data_c* src; + + src = type_data_table[bIT_TYPE_CAT_FTR]; + type_data->_00 = src->_00; + type_data->type = src->type; + type_data->pos_x_tbl_p = src->pos_x_tbl_p; + type_data->pos_z_tbl_p = src->pos_z_tbl_p; + + type_data->type = 68 + mNT_get_itemTableNo(fg_no); + + break; + } + + case NAME_TYPE_ITEM1: { + bg_item_type_data_c* src; + + src = type_data_table[bIT_TYPE_CAT_ITEM1]; + type_data->_00 = src->_00; + type_data->type = src->type; + type_data->pos_x_tbl_p = src->pos_x_tbl_p; + type_data->pos_z_tbl_p = src->pos_z_tbl_p; + + type_data->type = 68 + mNT_get_itemTableNo(fg_no); + + break; + } + + default: { + bg_item_type_data_c* src; + + src = type_data_table[bIT_TYPE_CAT_DUMMY]; + type_data->_00 = src->_00; + type_data->type = src->type; + type_data->pos_x_tbl_p = src->pos_x_tbl_p; + type_data->pos_z_tbl_p = src->pos_z_tbl_p; + + break; + } + } +} + +static void bit_cmn_single_drawS_shadow(GAME* game, bg_item_common_info_c* common_info, mActor_name_t fg_no, xyz_t* pos, + s_xyz* angle, xyz_t* scale, u8 alpha, f32 shadow_pos, rgba_t* shadow_color) { + if (bIT_individual_draw_check(fg_no)) { + bg_item_type_data_c type_data; + int ut_x; + int ut_z; + mCoBG_Collision_u* col; + + mFI_Wpos2UtNum(&ut_x, &ut_z, *pos); + col = mFI_UtNum2UtCol(ut_x, ut_z); + fg_no2fg_type(fg_no, &type_data, col, common_info->type_data_table_p); + bit_cmn_single_draw_BT_shadow(game, common_info, &type_data, pos, angle, scale, alpha, shadow_pos, + shadow_color); + } +} + +static void bit_cmn_single_draw_item_body(GRAPH* graph, bIT_draw_pos_entry_c* draw_pos_entry, + bg_item_draw_part_c* draw_part, Gfx** display_list_table) { + Gfx* gfx; + bg_item_draw_list_c* draw_list; + int i = draw_part->draw_list_count; + + while (i != 0) { + i--; + draw_list = draw_part->draw_list_table_p[i]; + + OPEN_DISP(graph); + + if (draw_pos_entry->alpha == 255) { + gfx = NOW_POLY_OPA_DISP; + bit_cmn_single_draw_loop_type1(graph, &gfx, draw_pos_entry, draw_list, display_list_table); + SET_POLY_OPA_DISP(gfx); + } else { + gfx = NOW_POLY_XLU_DISP; + bit_cmn_single_draw_loop_type1(graph, &gfx, draw_pos_entry, draw_list, display_list_table); + SET_POLY_XLU_DISP(gfx); + } + + CLOSE_DISP(graph); + } +} + +static void bit_cmn_single_draw(GAME* game, mActor_name_t fg_no, xyz_t* pos, f32 scale_f, bIT_DRAW_BF_PROC draw_bf, + bIT_DRAW_AF_PROC draw_af, rgba_t* col) { + bg_item_common_info_c* common_info; + xyz_t scale; + + scale.x = scale_f; + scale.y = scale_f; + scale.z = scale_f; + common_info = &bIT_CLIP->bg_item_common_p->common_info; + + bit_draw_ta_set(game); + bit_cmn_single_drawS(game, common_info, fg_no, pos, &ZeroSVec, &scale, 255, draw_bf, draw_af, col); + bit_draw_ta_clr(game); +} + +static void bit_cmn_single_draw_BT(GAME* game, bg_item_common_info_c* common_info, bg_item_type_data_c* type_data, + xyz_t* pos, s_xyz* angle, xyz_t* scale, u8 alpha, bIT_DRAW_BF_PROC draw_bf, + bIT_DRAW_AF_PROC draw_af, rgba_t* col) { + if (type_data == NULL || type_data->type == bIT_DRAW_TYPE_NONE || type_data->type < 0) { + return; + } else { + static bIT_draw_pos_entry_c draw_pos; + bg_item_draw_part_table_c* table_p; + bg_item_draw_part_c* draw_part; + Gfx** display_list_table; + Gfx* gfx; + + Matrix_push(); + // ISSUE + table_p = &draw_part_table_a[type_data->type]; + draw_part = table_p->draw_part_p; + display_list_table = (Gfx**)draw_part->display_list_table_p; + draw_pos.gfx_no = type_data->_00; + draw_pos.cull_flag = FALSE; + draw_pos.alpha = alpha; + + Matrix_translate(pos->x, pos->y, pos->z, 0); + Matrix_RotateY(angle->y, 1); + Matrix_RotateX(angle->x, 1); + Matrix_RotateZ(angle->z, 1); + Matrix_scale(scale->x, scale->y, scale->z, 1); + Matrix_get(&draw_pos.mtx); + + if (draw_bf != NULL) { + if (alpha == 255) { + OPEN_DISP(game->graph); + gfx = NOW_POLY_OPA_DISP; + + draw_bf(&gfx, col); + + SET_POLY_OPA_DISP(gfx); + CLOSE_DISP(game->graph); + } else { + OPEN_DISP(game->graph); + gfx = NOW_POLY_XLU_DISP; + + draw_bf(&gfx, col); + + SET_POLY_XLU_DISP(gfx); + CLOSE_DISP(game->graph); + } + } + + bit_cmn_single_draw_item_body(game->graph, &draw_pos, draw_part, display_list_table); + + if (draw_af != NULL) { + if (alpha == 255) { + OPEN_DISP(game->graph); + gfx = NOW_POLY_OPA_DISP; + + draw_af(&gfx, col); + + SET_POLY_OPA_DISP(gfx); + CLOSE_DISP(game->graph); + } else { + OPEN_DISP(game->graph); + gfx = NOW_POLY_XLU_DISP; + + draw_af(&gfx, col); + + SET_POLY_XLU_DISP(gfx); + CLOSE_DISP(game->graph); + } + } + + Matrix_pull(); + } +} + +static void bit_cmn_single_drawS(GAME* game, bg_item_common_info_c* common_info, mActor_name_t fg_no, xyz_t* pos, + s_xyz* angle, xyz_t* scale, u8 alpha, bIT_DRAW_BF_PROC draw_bf, + bIT_DRAW_AF_PROC draw_af, rgba_t* color) { + if (bIT_individual_draw_check(fg_no)) { + bg_item_type_data_c type_data; + int ut_x; + int ut_z; + mCoBG_Collision_u* col; + + mFI_Wpos2UtNum(&ut_x, &ut_z, *pos); + col = mFI_UtNum2UtCol(ut_x, ut_z); + fg_no2fg_type(fg_no, &type_data, col, common_info->type_data_table_p); + bit_cmn_single_draw_BT(game, common_info, &type_data, pos, angle, scale, alpha, draw_bf, draw_af, color); + } +} + +static void bIT_common_info_tbl_copy(bg_item_tbl_c* dst, bg_item_tbl_c* src) { + u8* src_p = src->info; + u8* dst_p = dst->info; + int i; + + for (i = 0; i < UT_TOTAL_NUM; i++) { + *dst_p++ = *src_p++; + } +} + +typedef struct tree_cut_info_s { + mActor_name_t tree; + s16 cut_count; +} bIT_tree_cut_info_c; + +static void bIT_common_clear_treeatr(int bx, int bz, bg_item_tbl_c* tbl) { + static bIT_tree_cut_info_c tree_cut_tbl[] = { + { TREE_S0, 1 }, + { TREE_S1, 2 }, + { TREE_S2, 3 }, + { TREE, 3 }, + { TREE_APPLE_S0, 1 }, + { TREE_APPLE_S1, 2 }, + { TREE_APPLE_S2, 3 }, + { TREE_APPLE_NOFRUIT_0, 3 }, + { TREE_APPLE_NOFRUIT_1, 3 }, + { TREE_APPLE_NOFRUIT_2, 3 }, + { TREE_APPLE_FRUIT, 3 }, + { TREE_ORANGE_S0, 1 }, + { TREE_ORANGE_S1, 2 }, + { TREE_ORANGE_S2, 3 }, + { TREE_ORANGE_NOFRUIT_0, 3 }, + { TREE_ORANGE_NOFRUIT_1, 3 }, + { TREE_ORANGE_NOFRUIT_2, 3 }, + { TREE_ORANGE_FRUIT, 3 }, + { TREE_PEACH_S0, 1 }, + { TREE_PEACH_S1, 2 }, + { TREE_PEACH_S2, 3 }, + { TREE_PEACH_NOFRUIT_0, 3 }, + { TREE_PEACH_NOFRUIT_1, 3 }, + { TREE_PEACH_NOFRUIT_2, 3 }, + { TREE_PEACH_FRUIT, 3 }, + { TREE_PEAR_S0, 1 }, + { TREE_PEAR_S1, 2 }, + { TREE_PEAR_S2, 3 }, + { TREE_PEAR_NOFRUIT_0, 3 }, + { TREE_PEAR_NOFRUIT_1, 3 }, + { TREE_PEAR_NOFRUIT_2, 3 }, + { TREE_PEAR_FRUIT, 3 }, + { TREE_CHERRY_S0, 1 }, + { TREE_CHERRY_S1, 2 }, + { TREE_CHERRY_S2, 3 }, + { TREE_CHERRY_NOFRUIT_0, 3 }, + { TREE_CHERRY_NOFRUIT_1, 3 }, + { TREE_CHERRY_NOFRUIT_2, 3 }, + { TREE_CHERRY_FRUIT, 3 }, + { TREE_1000BELLS_S0, 1 }, + { TREE_1000BELLS_S1, 2 }, + { TREE_1000BELLS_S2, 3 }, + { TREE_1000BELLS, 3 }, + { TREE_10000BELLS_S0, 1 }, + { TREE_10000BELLS_S1, 2 }, + { TREE_10000BELLS_S2, 3 }, + { TREE_10000BELLS, 3 }, + { TREE_30000BELLS_S0, 1 }, + { TREE_30000BELLS_S1, 2 }, + { TREE_30000BELLS_S2, 3 }, + { TREE_30000BELLS, 3 }, + { TREE_BEES, 3 }, + { TREE_FTR, 3 }, + { TREE_LIGHTS, 3 }, + { TREE_PRESENT, 3 }, + { TREE_BELLS, 3 }, + { TREE_100BELLS_S0, 1 }, + { TREE_100BELLS_S1, 2 }, + { TREE_100BELLS_S2, 3 }, + { TREE_100BELLS, 3 }, + { TREE_PALM_S0, 1 }, + { TREE_PALM_S1, 2 }, + { TREE_PALM_S2, 3 }, + { TREE_PALM_NOFRUIT_0, 3 }, + { TREE_PALM_NOFRUIT_1, 3 }, + { TREE_PALM_NOFRUIT_2, 3 }, + { TREE_PALM_FRUIT, 3 }, + { CEDAR_TREE_S0, 1 }, + { CEDAR_TREE_S1, 2 }, + { CEDAR_TREE_S2, 3 }, + { CEDAR_TREE, 3 }, + { CEDAR_TREE_BELLS, 3 }, + { CEDAR_TREE_FTR, 3 }, + { CEDAR_TREE_BEES, 3 }, + { CEDAR_TREE_LIGHTS, 3 }, + { GOLD_TREE_S0, 1 }, + { GOLD_TREE_S1, 2 }, + { GOLD_TREE_S2, 3 }, + { GOLD_TREE_SHOVEL, 3 }, + { GOLD_TREE, 3 }, + { GOLD_TREE_BELLS, 3 }, + { GOLD_TREE_FTR, 3 }, + { GOLD_TREE_BEES, 3 }, + }; + + int ut_z; + int ut_x; + int i; + mActor_name_t* fg_p = mFI_UtNum2UtFG(bx * UT_X_NUM, bz * UT_Z_NUM); + bIT_tree_cut_info_c* tree_cut_table_p; + u8* atr = tbl->info; + + for (ut_z = 0; ut_z < UT_Z_NUM; ut_z++) { + for (ut_x = 0; ut_x < UT_X_NUM; ut_x++, atr++) { + tree_cut_table_p = tree_cut_tbl; + + for (i = 0; i < ARRAY_COUNT(tree_cut_tbl); i++, tree_cut_table_p++) { + if (*fg_p == tree_cut_table_p->tree) { + *atr = tree_cut_table_p->cut_count; + break; + } + } + + if (i == ARRAY_COUNT(tree_cut_tbl)) { + *atr = 255; + } + + fg_p++; + } + } +} + +typedef struct { + int bx; + int bz; +} bIT_block_info_c; + +typedef struct { + int count; + bIT_block_info_c info[mFM_VISIBLE_BLOCK_NUM]; +} bIT_block_c; + +static void m_GetCItTable_TreeTblChk(bg_item_block_info_tbl_c* block_info_table, mFI_item_table_c* item_table, + xyz_t wpos) { + int remove_cut_tree_info_bitfield; + mFI_block_tbl_c* block_table; + bIT_block_c block_info[2]; + int dst_idx_tbl[mFM_VISIBLE_BLOCK_NUM]; + int update_flag; + int i; + + block_info[0].count = item_table->count; + for (i = 0; i < mFM_VISIBLE_BLOCK_NUM; i++) { + if (i < block_info[0].count) { + block_info[0].info[i].bx = item_table->block_info_tbl[i].block_x; + block_info[0].info[i].bz = item_table->block_info_tbl[i].block_z; + } else { + block_info[0].info[i].bx = -1; + block_info[0].info[i].bz = -1; + } + } + + mFI_GetItemTable(item_table, wpos, __FILE__, 4856); + remove_cut_tree_info_bitfield = Common_Get(remove_cut_tree_info_bitfield); + block_info[1].count = item_table->count; + + for (i = 0; i < mFM_VISIBLE_BLOCK_NUM; i++) { + if (i < block_info[1].count) { + block_info[1].info[i].bx = item_table->block_info_tbl[i].block_x; + block_info[1].info[i].bz = item_table->block_info_tbl[i].block_z; + } else { + block_info[1].info[i].bx = -1; + block_info[1].info[i].bz = -1; + } + } + + update_flag = FALSE; + for (i = 0; i < mFM_VISIBLE_BLOCK_NUM; i++) { + dst_idx_tbl[i] = i; + } + + for (i = 0; i < mFM_VISIBLE_BLOCK_NUM; i++) { + int j; + + if (block_info[0].info[i].bx != -1) { + for (j = 0; j < mFM_VISIBLE_BLOCK_NUM; j++) { + if (i != j && block_info[1].info[j].bx != -1) { + if (block_info[0].info[i].bx == block_info[1].info[j].bx && + block_info[0].info[i].bz == block_info[1].info[j].bz) { + dst_idx_tbl[j] = i; + update_flag = TRUE; + break; + } + } + } + } + } + + if (update_flag) { + static bg_item_tbl_c tmp_info_tbl[mFM_VISIBLE_BLOCK_NUM]; + + for (i = 0; i < mFM_VISIBLE_BLOCK_NUM; i++) { + bIT_common_info_tbl_copy(&tmp_info_tbl[i], &block_info_table->info_tbl[dst_idx_tbl[i]]); + } + + for (i = 0; i < mFM_VISIBLE_BLOCK_NUM; i++) { + bIT_common_info_tbl_copy(&block_info_table->info_tbl[i], &tmp_info_tbl[i]); + } + } + + { + int bx; + int bz; + bg_item_tbl_c* info_table; + + block_table = item_table->block_info_tbl; + info_table = block_info_table->info_tbl; + for (i = 0; i < item_table->count; i++) { + if ((remove_cut_tree_info_bitfield & (1 << i)) != 0) { + bx = block_table->block_x; + bz = block_table->block_z; + + bIT_common_clear_treeatr(bx, bz, info_table); + mFI_ClearHoleBlock(bx, bz); + mFI_ClearBeecomb(bx, bz); + } + + block_table++; + info_table++; + } + } +} + +static int bIT_actor_pit_entry(bg_item_pit_c* pit, s16 mode, mActor_name_t fg_no, xyz_t* pos, + mActor_name_t fg_item_in_pit) { + int res = FALSE; + int i; + + for (i = 0; res == FALSE && i < bIT_PIT_NUM; i++, pit++) { + if (pit->mode == 0) { + pit->mode = mode; + pit->fg_item_in_pit = fg_item_in_pit; + pit->hole_fg_item = fg_no; + pit->wait_counter = 0; + xyz_t_move(&pit->position, pos); + + switch (mode) { + case 1: + pit->scale = 0.0f; + pit->hole_timer = 1; + res = TRUE; + break; + case 4: + mFI_SetFG_common(RSV_NO, pit->position, TRUE); + pit->scale = 1.0f; + pit->hole_timer = 0; + res = TRUE; + break; + } + } + } + + return res; +} + +static void bIT_actor_pit_move(GAME* game, bg_item_pit_c* pit) { + int i; + + for (i = 0; i < bIT_PIT_NUM; i++, pit++) { + switch (pit->mode) { + case 0: { + break; + } + + case 1: { + if (pit->hole_timer > 0) { + pit->hole_timer--; + } else { + mFI_SetFG_common(RSV_NO, pit->position, FALSE); + pit->mode = 2; + pit->hole_timer = 17; + } + + break; + } + + case 2: { + if (pit->hole_timer <= 0) { + pit->hole_timer = 0; + pit->mode = 3; + } else { + pit->hole_timer--; + } + + break; + } + + case 3: { + pit->scale = (f32)(int)pit->hole_timer / 26.0f; + + if (pit->hole_timer == 6) { + sAdo_OngenTrgStart(0x13C, &pit->position); + eEC_CLIP->effect_make_proc(eEC_EFFECT_OTOSIANA, pit->position, 1, 0, game, pit->fg_item_in_pit, + mCoBG_Wpos2Attribute(pit->position, NULL), 0); + } + + if (pit->scale >= 1.0f) { + mFI_SetFG_common(pit->hole_fg_item, pit->position, TRUE); + pit->mode = 0; + } + + pit->hole_timer++; + break; + } + + case 4: { + pit->scale = 1.0f - (f32)(int)pit->hole_timer / 14.0f; + + if (pit->hole_timer == 0) { + sAdo_OngenTrgStart(0x15B, &pit->position); + eEC_CLIP->effect_make_proc(eEC_EFFECT_OTOSIANA, pit->position, 1, 0, game, pit->fg_item_in_pit, + mCoBG_Wpos2Attribute(pit->position, NULL), 0); + } + + if (pit->scale <= 0.0f) { + mFI_SetFG_common(EMPTY_NO, pit->position, TRUE); + pit->mode = 0; + } + + pit->hole_timer++; + break; + } + } + } +} + +static void bIT_actor_pit_destruct(bg_item_pit_c* pit) { + int i; + + for (i = 0; i < bIT_PIT_NUM; i++, pit++) { + if (pit->mode != 0) { + mFI_SetFG_common(EMPTY_NO, pit->position, FALSE); + pit->mode = 0; + } + } +} + +static int bg_item_common_chg_BGDataR_b(bg_item_common_c* common, int bx, int bz) { + f32 block_pos_x; + f32 block_pos_z; + int ut_z; + int ut_x; + f32* pos_table; + mActor_name_t* fg_p = mFI_BkNumtoUtFGTop(bx, bz); + + if (fg_p == NULL) { + return FALSE; + } + + if (mFI_BkNum2WposXZ(&block_pos_x, &block_pos_z, bx, bz) == FALSE) { + return FALSE; + } + + pos_table = common->common_info.pos_table_p; + for (ut_z = 0; ut_z < UT_Z_NUM; ut_z++) { + for (ut_x = 0; ut_x < UT_X_NUM; ut_x++, fg_p++) { + switch (ITEM_NAME_GET_TYPE(*fg_p)) { + case NAME_TYPE_ITEM0: { + if (*fg_p != EMPTY_NO) { + mNT_offset_table_c* ofs_tbl = obj_hight_table_item0_nogrow(*fg_p); + xyz_t pos; + + pos.x = block_pos_x + pos_table[ut_x]; + pos.z = block_pos_z + pos_table[ut_z]; + + if (ofs_tbl->type != 0) { + mCoBG_SetPluss5PointOffset_file(pos, ofs_tbl->table, __FILE__, 5243); + } else { + mCoBG_SetPlussOffset(pos, ofs_tbl->table.centerRight_offset, ofs_tbl->table.unit_attribute); + } + } + + break; + } + } + } + } + + return TRUE; +} + +static void bg_item_common_chg_BGDataR(bg_item_common_c* common) { + int bz; + int bx; + int bx_max = mFI_GetBlockXMax(); + int bz_max = mFI_GetBlockZMax(); + + for (bz = 0; bz < bz_max; bz++) { + for (bx = 0; bx < bx_max; bx++) { + bg_item_common_chg_BGDataR_b(common, bx, bz); + } + } +} + +static void bg_item_common_outPutData(GAME_PLAY* play, bg_item_draw_pos_c* draw_pos, s16 next, int gfx_idx, + xyz_t* pos) { + Matrix_translate(pos->x, pos->y, pos->z, 0); + Matrix_scale(0.01f, 0.01f, 0.01f, 1); + Matrix_get(&draw_pos->mtxf); + draw_pos->next_add_cnt = next; + draw_pos->sub_idx = gfx_idx; +} + +static void bg_item_common_classifyitemDataTable(GAME_PLAY* play, bg_item_draw_table_c* draw_table, + mFI_block_tbl_c* block_table, u16* start_idx_tbl, + bg_item_type_data_c** type_data_table, + bg_item_draw_part_table_c* draw_part_table) { + Matrix_push(); + { + int flag; + bg_item_draw_pos_c* draw_pos; + mActor_name_t* fg_p; + mCoBG_Collision_u* col; + int bx; + int bz; + int base_ut_x; + int base_ut_z; + f32 bx_pos; + f32 bz_pos; + f32 block_height; + int idx; + int ut_z; + int ut_x; + u16* deposit; + u8* height_p; + int block; + + draw_pos = &draw_table->draw_data.draw_pos[1]; + idx = 1; + bx = block_table->block_x; + bz = block_table->block_z; + bx_pos = block_table->pos_x; + bz_pos = block_table->pos_z; + base_ut_x = bx * UT_X_NUM; + base_ut_z = bz * UT_Z_NUM; + block_height = 1.0f + mFI_UtNum2BaseHeight(base_ut_x, base_ut_z); + block = mFI_GetBlockNum(bx, bz); + height_p = (u8*)g_fdinfo->block_info[block].bg_info.keep_h; + col = mFI_UtNum2UtCol(base_ut_x, base_ut_z); + deposit = mFI_GetDepositP(bx, bz); + fg_p = block_table->items; + + for (ut_z = 0; ut_z < UT_Z_NUM; ut_z++) { + for (ut_x = 0; ut_x < UT_X_NUM; ut_x++, fg_p++, draw_pos++, idx++, col++, height_p++) { + if (bIT_individual_draw_check(*fg_p)) { + xyz_t pos; + bg_item_type_data_c type_data; + flag = TRUE; + + fg_no2fg_type(*fg_p, &type_data, col, type_data_table); + if (deposit == NULL || ((*deposit >> ut_x) & 1) == 0 || type_data.type == bIT_DRAW_TYPE_FISH2) { + if (*fg_p != EMPTY_NO) { + fg_no2fg_type(*fg_p, &type_data, col, type_data_table); + } else { + flag = FALSE; + } + } else { + int hole_no = mCoBG_GetHoleNumber_ClData(col); + + if (hole_no >= 0) { + bg_item_type_data_c* src_data = type_data_table[bIT_TYPE_CAT_CRACK]; + + type_data._00 = src_data->_00; + type_data.type = src_data->type; + type_data.pos_x_tbl_p = src_data->pos_x_tbl_p; + type_data.pos_z_tbl_p = src_data->pos_z_tbl_p; + + if (mCoBG_CheckSandHole_ClData(col)) { + type_data.type = bIT_DRAW_TYPE_CRACK00_S; + } + + type_data._00 = hole_no; + } else { + flag = FALSE; + } + } + + if (flag) { + int type = type_data.type; + int before_start; + int diff; + + pos.x = bx_pos + type_data.pos_x_tbl_p[ut_x]; + pos.z = bz_pos + type_data.pos_z_tbl_p[ut_z]; + + if ((draw_part_table[type].flags & 2)) { + pos.x += rnd_data_x[ut_x & 3][ut_z & 3]; + pos.z += rnd_data_z[ut_x & 3][ut_z & 3]; + } + + if (*fg_p == ITM_KNIFE_AND_FORK) { + pos.y = mCoBG_GetBgY_OnlyCenter_FromWpos(pos, 0.0f); + } else { + pos.y = (f32)*height_p * 10.0f + block_height; + } + + before_start = start_idx_tbl[type]; + diff = before_start - idx; + start_idx_tbl[type] = idx; + bg_item_common_outPutData(play, draw_pos, diff, type_data._00, &pos); + } + } + } + + if (deposit != NULL) { + deposit++; + } + } + } + Matrix_pull(); +} + +// Part 3 + +static void bg_item_common_set_draw_tbl(GAME_PLAY* play, bg_item_draw_table_c* draw_tbl, mFI_block_tbl_c* block_tbl, + bg_item_type_data_c** type_data_table, + bg_item_draw_part_table_c* draw_part_table) { + bg_item_draw_pos_c* draw_pos; + u16 start_idx_tbl[bIT_DRAW_TYPE_MAX]; + u16* start_idx_p = start_idx_tbl; + u16* draw_start_idx_p; + int i; + + for (i = 0; i < bIT_DRAW_TYPE_MAX; i++, start_idx_p++) { + *start_idx_p = 0; + } + + draw_pos = draw_tbl->draw_data.draw_pos; + for (i = 0; i < (UT_TOTAL_NUM + 1); i++, draw_pos++) { + draw_pos->next_add_cnt = 256; + } + + bg_item_common_classifyitemDataTable(play, draw_tbl, block_tbl, start_idx_tbl, type_data_table, draw_part_table); + + start_idx_p = start_idx_tbl; + draw_start_idx_p = draw_tbl->draw_data.idx_p; + for (i = 0; i < bIT_DRAW_TYPE_MAX; i++, start_idx_p++, draw_start_idx_p++) { + *draw_start_idx_p = *start_idx_p; + } + + draw_tbl->draw_flag = TRUE; +} + +static void bg_shin_effect_being_check(bg_item_common_c* common, int count) { + xyz_t pos; + xyz_t shine_pos; + f32 x_start_save; + int i; + int ut_z; + int ut_x; + mFI_block_tbl_c* block_info_tbl = common->item_table.block_info_tbl; + mActor_name_t shin_fg_item = EMPTY_NO; + mActor_name_t* fg_p; + u16 mode = 0; + + pos.y = 0.0f; + for (i = 0; i < count; i++, block_info_tbl++) { + fg_p = block_info_tbl->items; + + mFI_BkNum2WposXZ(&pos.x, &pos.z, block_info_tbl->block_x, block_info_tbl->block_z); + pos.x += mFI_UT_WORLDSIZE_HALF_X_F; + pos.z += mFI_UT_WORLDSIZE_HALF_Z_F; + x_start_save = pos.x; + + for (ut_z = 0; ut_z < UT_Z_NUM; ut_z++) { + pos.x = x_start_save; + for (ut_x = 0; ut_x < UT_X_NUM; ut_x++, fg_p++) { + mActor_name_t fg_item = *fg_p; + + if (fg_item == SHINE_SPOT) { + shin_fg_item = fg_item; + xyz_t_move(&shine_pos, &pos); + mode = 1; + } else if (fg_item == HOLE_SHINE) { + shin_fg_item = fg_item; + xyz_t_move(&shine_pos, &pos); + mode = 2; + } + + pos.x += mFI_UT_WORLDSIZE_X_F; + } + + pos.z += mFI_UT_WORLDSIZE_Z_F; + } + } + + if (mode != 0) { + shine_pos.y = mCoBG_GetBgY_OnlyCenter_FromWpos2(shine_pos, -1.0f); + bIT_actor_shin_effect_entry(common->shin, shin_fg_item, &shine_pos, mode); + } +} + +static void bg_item_common_chg_draw_tbl_perfect(GAME_PLAY* play, bg_item_common_c* common, int flags) { + int count; + bg_item_type_data_c** type_data_table = common->common_info.type_data_table_p; + int* order_tbl = common->_139F4; + mFI_block_tbl_c* block_tbl; + int flag0; + u8 clear_tree_cut_flags; + int t0[mFM_VISIBLE_BLOCK_NUM]; + int t1[mFM_VISIBLE_BLOCK_NUM]; + int t2[mFM_VISIBLE_BLOCK_NUM]; + int i; + int j; + + count = common->item_table.count; + + for (i = 0; i < mFM_VISIBLE_BLOCK_NUM; i++, order_tbl++) { + common->draw_table[*order_tbl].draw_flag = FALSE; + } + + if ((flags & (2 | 1))) { + bIT_actor_shin_effect_check(common->shin); + } + + for (i = 0; i < mFM_VISIBLE_BLOCK_NUM; i++) { + t0[i] = -2; + t1[i] = -2; + t2[i] = FALSE; + } + + if ((flags & 2)) { + for (i = 0; i < count; i++) { + t0[i] = mFI_GetOldItemTableIdx(i); + + if (t0[i] >= 0) { + t1[i] = common->_139F4[t0[i]]; + t2[t1[i]] = TRUE; + } + } + + for (i = 0; i < count; i++) { + if (t0[i] < 0) { + for (j = 0; j < mFM_VISIBLE_BLOCK_NUM; j++) { + if (t2[j] == FALSE) { + t2[j] = TRUE; + t1[i] = j; + common->draw_table[j].bx = common->item_table.block_info_tbl[i].block_x; + common->draw_table[j].bz = common->item_table.block_info_tbl[i].block_z; + break; + } + } + } + } + + flag0 = FALSE; + for (i = 0; i < count; i++) { + common->_139F4[i] = t1[i]; + if (t0[i] < 0) { + flag0 = TRUE; + } + + common->draw_table[common->_139F4[i]].draw_flag = TRUE; + } + + clear_tree_cut_flags = Common_Get(remove_cut_tree_info_bitfield); + if (flag0 || clear_tree_cut_flags != 0) { + for (i = 0; i < count; i++) { + if (t0[i] < 0 || (clear_tree_cut_flags & (1 << i)) != 0) { + bg_item_common_set_draw_tbl(play, &common->draw_table[common->_139F4[i]], + &common->item_table.block_info_tbl[i], type_data_table, + common->common_info.draw_part_table_p); + } + } + } + } + + if ((flags & 1)) { + for (i = 0; i < count; i++) { + bg_item_common_set_draw_tbl(play, &common->draw_table[common->_139F4[i]], + &common->item_table.block_info_tbl[i], type_data_table, + common->common_info.draw_part_table_p); + } + } + + if ((flags & (2 | 1))) { + bg_shin_effect_being_check(common, count); + } +} + +static void bg_item_common_renew_draw_and_crs_data_perfect(GAME_PLAY* play, bg_item_common_c* common, int flags) { + PLAYER_ACTOR* player = GET_PLAYER_ACTOR(play); + + if (player != NULL) { + m_GetCItTable_TreeTblChk(&common->block_info_table, &common->item_table, player->actor_class.world.position); + } + + bg_item_common_chg_draw_tbl_perfect(play, common, flags); +} + +static void bg_item_common_destruct(GAME_PLAY* play, ACTOR* actorx, bg_item_common_c* common) { + bIT_actor_drop_destruct(&common->drop_info); + bIT_actor_drop_destruct(&common->fruit_drop_info); + bIT_actor_hole_effect_destruct(common->hole); + bIT_actor_pit_destruct(common->pit); + bIT_actor_ten_coin_destruct(common->ten_coin); +} + +static int bg_item_common_culling_check(GAME_PLAY* play, ACTOR* actorx, xyz_t* pos) { + xyz_t camera_pos; + f32 camera_w; + + Skin_Matrix_PrjMulVector(&play->projection_matrix, pos, &camera_pos, &camera_w); + return Actor_draw_actor_no_culling_check2(actorx, &camera_pos, camera_w); +} + +static int bg_item_common_culling_check_talk(GAME_PLAY* play, ACTOR* actorx, xyz_t* pos) { + int res = FALSE; + + if (bg_item_common_culling_check(play, actorx, pos) == TRUE) { + if (Camera2_CheckEnterCullingArea(pos->x, pos->z, 65.0f) == TRUE) { + res = FALSE; + } else { + res = TRUE; + } + } + + return res; +} + +static void bg_item_common_culling_check_loop(GAME_PLAY* play, ACTOR* actorx, bg_item_draw_pos_c* draw_pos) { + while (draw_pos->next_add_cnt != 256) { + xyz_t pos; + + Matrix_put(&draw_pos->mtxf); + Matrix_Position(&ZeroVec, &pos); + + if (bg_item_common_culling_check(play, actorx, &pos) == TRUE) { + draw_pos->cull_flag = FALSE; + } else { + draw_pos->cull_flag = TRUE; + } + + draw_pos += draw_pos->next_add_cnt; + } +} + +static void bg_item_common_culling_check_talk_loop(GAME_PLAY* play, ACTOR* actorx, bg_item_draw_pos_c* draw_pos) { + while (draw_pos->next_add_cnt != 256) { + xyz_t pos; + + Matrix_put(&draw_pos->mtxf); + Matrix_Position(&ZeroVec, &pos); + + if (bg_item_common_culling_check_talk(play, actorx, &pos) == TRUE) { + draw_pos->cull_flag = FALSE; + } else { + draw_pos->cull_flag = TRUE; + } + + draw_pos += draw_pos->next_add_cnt; + } +} + +static int bg_item_common_check_talk_tree(bg_item_common_c* common, int idx) { + int res = FALSE; + + if ((common->flags & 1) && common->talk_display_limit_check_proc(idx)) { + res = TRUE; + } + + return res; +} + +static void bg_item_common_draw_check(GAME_PLAY* play, bg_item_common_c* common, ACTOR* actorx, + bg_item_draw_table_c* draw_tbl) { + u16* start_idx_p = draw_tbl->draw_data.idx_p; + int count = draw_tbl->draw_data.val; + bg_item_draw_pos_c* draw_pos; + int i; + + for (i = 0; i < count; i++, start_idx_p++) { + if (*start_idx_p != 0) { + draw_pos = &draw_tbl->draw_data.draw_pos[*start_idx_p]; + + if (bg_item_common_check_talk_tree(common, i) == TRUE) { + bg_item_common_culling_check_talk_loop(play, actorx, draw_pos); + } else { + bg_item_common_culling_check_loop(play, actorx, draw_pos); + } + } + } +} + +static void bg_item_common_move(GAME_PLAY* play, ACTOR* actorx, bg_item_common_c* common) { + int flags; + int i; + bg_item_draw_table_c* draw_tbl; + + bIT_actor_drop_move(&common->drop_info); + bIT_actor_drop_move(&common->fruit_drop_info); + bIT_actor_hole_effect_move(common->hole); + bIT_actor_shin_effect_move((GAME*)play, common->shin); + bIT_actor_pit_move((GAME*)play, common->pit); + bIT_actor_ten_coin_move((GAME*)play, common->ten_coin); + bIT_actor_fade_move((GAME*)play, common->fade); + + flags = 0; + if (mFI_ItemisBorn() == TRUE || mFI_CheckPlayerWade(mFI_WADE_END)) { + flags |= 2; + } + + if (mFI_FGisUpDate() == TRUE) { + flags |= 1; + } + + if (flags != 0) { + bg_item_common_renew_draw_and_crs_data_perfect(play, common, flags); + } + + draw_tbl = common->draw_table; + for (i = 0; i < mFM_VISIBLE_BLOCK_NUM; i++, draw_tbl++) { + if (draw_tbl->draw_flag == TRUE) { + bg_item_common_draw_check(play, common, actorx, draw_tbl); + } + } +} + +static int bIT_actor_pit_entry_del(bg_item_pit_c* pit, int param_2, int param_3, xyz_t* pos, + mActor_name_t fg_item_in_pit) { + int res = FALSE; + int i; + + for (i = 0; i < bIT_PIT_NUM; i++, pit++) { + if (fg_item_in_pit == pit->fg_item_in_pit && pos->x == pit->position.x && pos->y == pit->position.y && + pos->z == pit->position.z) { + pit->mode = 0; + res = TRUE; + break; + } + } + + return res; +} + +static int bIT_actor_pit_fall(mActor_name_t pit_fg_item, int ut_x, int ut_z, mActor_name_t fg_item_in_pit) { + xyz_t pos; + bg_item_common_c* common = bIT_CLIP->bg_item_common_p; + mActor_name_t pitfall_fg_no; + mActor_name_t hole_fg_no; + + mFI_UtNum2CenterWpos(&pos, ut_x, ut_z); + pos.y = mCoBG_GetBgY_OnlyCenter_FromWpos2(pos, -1.0f); + pitfall_fg_no = pit_fg_item - BURIED_PITFALL_START; + mFI_SetFG_common(pitfall_fg_no + 0x43, pos, FALSE); + hole_fg_no = pitfall_fg_no + HOLE_START; + bIT_actor_pit_entry(common->pit, 1, hole_fg_no, &pos, fg_item_in_pit); + return FALSE; +} + +static int bIT_actor_pit_fall_stop(mActor_name_t pit_fg_item, int ut_x, int ut_z, mActor_name_t fg_item_in_pit) { + xyz_t pos; + bg_item_common_c* common = bIT_CLIP->bg_item_common_p; + + pit_fg_item = pit_fg_item - 0x19; + mFI_UtNum2CenterWpos(&pos, ut_x, ut_z); + pos.y = mCoBG_GetBgY_OnlyCenter_FromWpos2(pos, -1.0f); + mFI_SetFG_common(pit_fg_item, pos, FALSE); + bIT_actor_pit_entry_del(common->pit, 3, HOLE00, &pos, fg_item_in_pit); + return FALSE; +} + +static int bIT_actor_pit_exit(mActor_name_t pit_fg_item, int ut_x, int ut_z, mActor_name_t fg_item_in_pit) { + xyz_t pos; + bg_item_common_c* common = bIT_CLIP->bg_item_common_p; + mActor_name_t relative_fg_no; + + mFI_UtNum2CenterWpos(&pos, ut_x, ut_z); + pos.y = mCoBG_GetBgY_OnlyCenter_FromWpos2(pos, -1.0f); + relative_fg_no = pit_fg_item - HOLE_START; + bIT_actor_pit_entry(common->pit, 4, relative_fg_no + HOLE_START, &pos, fg_item_in_pit); + return FALSE; +} + +static void bg_item_common_draw_loop_type1(GRAPH* graph, Gfx** gfx_pp, bg_item_draw_list_c* draw_list, + bg_item_draw_pos_c* draw_pos, Gfx** display_list_table) { + int base_idx = draw_list->mat_idx; + + gSPDisplayList((*gfx_pp)++, display_list_table[draw_list->gfx_idx]); + + while (draw_pos->next_add_cnt != 256) { + if (draw_pos->cull_flag == FALSE) { + Matrix_put(&draw_pos->mtxf); + gSPMatrix((*gfx_pp)++, _Matrix_to_Mtx_new(graph), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPDisplayList((*gfx_pp)++, display_list_table[base_idx + draw_pos->sub_idx]); + } + + draw_pos += draw_pos->next_add_cnt; + } +} + +static void bg_item_common_s_draw_loop_type1(GRAPH* graph, Gfx** gfx_pp, bg_item_draw_list_c* draw_list, + int shadow_vtx_count, Vtx* shadow_vtx, bg_item_draw_pos_c* draw_pos, + Gfx** display_list_table) { + Gfx* base_gfx = display_list_table[draw_list->mat_idx + draw_pos->sub_idx]; + + while (draw_pos->next_add_cnt != 256) { + if (draw_pos->cull_flag == FALSE) { + Matrix_put(&draw_pos->mtxf); + gSPMatrix((*gfx_pp)++, _Matrix_to_Mtx_new(graph), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPVertex((*gfx_pp)++, shadow_vtx, shadow_vtx_count, 0); + gSPDisplayList((*gfx_pp)++, base_gfx); + } + + draw_pos += draw_pos->next_add_cnt; + } +} + +typedef void (*bIT_DRAW_PROC)(GRAPH*, Gfx**, bg_item_draw_list_c*, bg_item_draw_pos_c*, Gfx**); + +static void bg_item_common_draw_item_body(GRAPH* graph, Gfx** gfx_pp, bg_item_draw_part_c* draw_part, + bg_item_draw_pos_c* draw_pos) { + bg_item_draw_list_c** draw_list_table; + int count; + int i; + Gfx** display_list_table; + + count = draw_part->draw_list_count; + draw_list_table = draw_part->draw_list_table_p; + display_list_table = draw_part->display_list_table_p; + + for (i = 0; i < count; i++, draw_list_table++) { + ((bIT_DRAW_PROC)(*draw_list_table)->draw_proc)(graph, gfx_pp, *draw_list_table, draw_pos, display_list_table); + } +} + +typedef void (*bIT_DRAW_SHADOW_PROC)(GRAPH*, Gfx**, bg_item_draw_list_c*, int, Vtx*, bg_item_draw_pos_c*, Gfx**); + +static void bg_item_common_draw_item_shadow(GRAPH* graph, Gfx** gfx_pp, bg_item_draw_part_c* draw_part, + bg_item_draw_pos_c* draw_pos, f32 shadow_pos, rgba_t* shadow_color) { + bg_item_draw_list_c* draw_list = draw_part->shadow_draw_list; + + if (draw_list != NULL) { + Vtx* vtx = (Vtx*)GRAPH_ALLOC_TYPE(graph, Vtx, draw_part->shadow_vtx_count); + + if (vtx != NULL) { + bIT_copy_vtx(vtx, draw_part->shadow_vtx_p, draw_part->shadow_vtx_count, draw_part->shadow_vtx_fix_table_p, + shadow_pos * draw_part->shadow_len); + } else { + vtx = draw_part->shadow_vtx_p; + } + + gSPDisplayList((*gfx_pp)++, draw_part->display_list_table_p[draw_list->mat_idx]); + gDPSetPrimColor((*gfx_pp)++, 0, shadow_color->a, shadow_color->r, shadow_color->g, shadow_color->b, 255); + ((bIT_DRAW_SHADOW_PROC)draw_list->draw_proc)(graph, gfx_pp, draw_list, draw_part->shadow_vtx_count, vtx, + draw_pos, draw_part->display_list_table_p); + } +} + +static void bg_item_common_draw_item(GAME_PLAY* play, bg_item_draw_table_c* draw_tbl, f32 shadow_pos, + rgba_t* shadow_color, bg_item_draw_part_table_c* draw_part_table) { + u16* start_idx; + GRAPH* graph; + int i; + Gfx* gfx; + bg_item_draw_part_table_c* draw_part_table_p; + Gfx* start_gfx_p; + + draw_part_table_p = draw_part_table; + start_idx = draw_tbl->draw_data.idx_p; + graph = play->game.graph; + + OPEN_DISP(graph); + gfx = NOW_POLY_OPA_DISP; + + for (i = 0; i < draw_tbl->draw_data.val; i++, start_idx++, draw_part_table_p++) { + if (*start_idx != 0) { + bg_item_common_draw_item_body(graph, &gfx, draw_part_table_p->draw_part_p, + draw_tbl->draw_data.draw_pos + *start_idx); + } + } + + SET_POLY_OPA_DISP(gfx); + start_gfx_p = NOW_POLY_OPA_DISP; + gfx = gfxopen(start_gfx_p); + gSPDisplayList(NEXT_SHADOW_DISP, gfx); + + start_idx = draw_tbl->draw_data.idx_p; + draw_part_table_p = draw_part_table; + for (i = 0; i < draw_tbl->draw_data.val; i++, start_idx++, draw_part_table_p++) { + if (*start_idx != 0) { + bg_item_common_draw_item_shadow(graph, &gfx, draw_part_table_p->draw_part_p, + draw_tbl->draw_data.draw_pos + *start_idx, shadow_pos, shadow_color); + } + } + + gSPEndDisplayList(gfx++); + gfxclose(start_gfx_p, gfx); + SET_POLY_OPA_DISP(gfx); + CLOSE_DISP(graph); +} + +static void bIT_actor_pit_draw_nrm(GAME* game, bg_item_common_info_c* common_info, bg_item_pit_c* pit, + bIT_DRAW_BF_PROC draw_bf, bIT_DRAW_AF_PROC draw_af, rgba_t* color) { + xyz_t scale; + + scale.x = pit->scale * 0.01f; + scale.y = pit->scale * 0.01f; + scale.z = pit->scale * 0.01f; + bit_cmn_single_drawS(game, common_info, pit->hole_fg_item, &pit->position, &ZeroSVec, &scale, 255, draw_bf, draw_af, + color); +} + +static void bIT_actor_pit_draw(GAME* game, bg_item_common_info_c* common_info, bg_item_pit_c* pit) { + int i; + + for (i = 0; i < bIT_PIT_NUM; i++, pit++) { + if (pit->hole_fg_item != 0 && pit->mode != 0) { + bIT_actor_pit_draw_nrm(game, common_info, pit, NULL, NULL, NULL); + } + } +} + +static void bg_item_common_draw(GAME_PLAY* play, bg_item_common_c* common, bg_item_draw_part_table_c* draw_part_table) { + GAME* game = (GAME*)play; + Kankyo* kankyo = &play->kankyo; + f32 shadow_pos; + rgba_t shadow_color; + + OPEN_DISP(game->graph); + + SET_POLY_OPA_DISP(texture_z_light_fog_prim_bb_pal_opa(NOW_POLY_OPA_DISP)); + SET_POLY_XLU_DISP(texture_z_light_fog_prim_bb_pal_xlu(NOW_POLY_XLU_DISP)); + SET_SHADOW_DISP(texture_z_fog_lod_alpha_shadow(NOW_SHADOW_DISP)); + + CLOSE_DISP(game->graph); + + bit_draw_ta_set(game); + + shadow_pos = kankyo->shadow_pos; + shadow_color.a = kankyo->shadow_alpha; + shadow_color.r = kankyo->base_light.shadow_color[0]; + shadow_color.g = kankyo->base_light.shadow_color[1]; + shadow_color.b = kankyo->base_light.shadow_color[2]; + + OPEN_DISP(game->graph); + { + Gfx* opa = NOW_POLY_OPA_DISP; + Gfx* xlu = NOW_POLY_XLU_DISP; + + bg_item_common_palload(&opa, common->common_info.pal_p); + bg_item_common_palload(&xlu, common->common_info.pal_p); + + SET_POLY_OPA_DISP(opa); + SET_POLY_XLU_DISP(xlu); + } + CLOSE_DISP(game->graph); + + { + int i; + bg_item_draw_table_c* draw_table = common->draw_table; + + for (i = 0; i < mFM_VISIBLE_BLOCK_NUM; i++, draw_table++) { + if (draw_table->draw_flag == TRUE) { + bg_item_common_draw_item(play, draw_table, shadow_pos, &shadow_color, draw_part_table); + } + } + } + + bIT_actor_drop_draw(game, &common->common_info, &common->drop_info); + bIT_actor_drop_draw(game, &common->common_info, &common->fruit_drop_info); + bIT_actor_hole_effect_draw(game, &common->common_info, common->hole); + bIT_actor_pit_draw(game, &common->common_info, common->pit); + bIT_actor_ten_coin_draw(game, &common->common_info, common->ten_coin, shadow_pos, &shadow_color); + bIT_actor_fade_draw(game, &common->common_info, common->fade); + + bit_draw_ta_clr(game); +} + +static void bg_item_common_construct(GAME* game, bg_item_common_c* common) { + common->drop_info.drop_p = common->drop; + common->drop_info.count = bIT_DROP_NUM; + common->fruit_drop_info.drop_p = common->fruit_drop; + common->fruit_drop_info.count = bIT_FRUIT_DROP_NUM; +} diff --git a/src/bg_item_data.c_inc b/src/bg_item_data.c_inc new file mode 100644 index 00000000..c17c000b --- /dev/null +++ b/src/bg_item_data.c_inc @@ -0,0 +1,260 @@ +static bg_item_type_data_c typeData_table_bgItem[] = { + { 0, bIT_DRAW_TYPE_NONE, NULL, NULL }, // 0x0000 + { 0, bIT_DRAW_TYPE_STUMP1, pos_table, pos_table }, // 0x0001 + { 0, bIT_DRAW_TYPE_STUMP2, pos_table, pos_table }, // 0x0002 + { 0, bIT_DRAW_TYPE_STUMP3, pos_table, pos_table }, // 0x0003 + { 0, bIT_DRAW_TYPE_STUMP4, pos_table, pos_table }, // 0x0004 + { 0, bIT_DRAW_TYPE_FENCE, pos_table2, pos_table2 }, // 0x0005 + { 0, bIT_DRAW_TYPE_NONE, pos_table, pos_table }, // 0x0006 + { 0, bIT_DRAW_TYPE_NOTICE, pos_table2, pos_table2 }, // 0x0007 + { 0, bIT_DRAW_TYPE_GRASS, pos_table, pos_table }, // 0x0008 + { 1, bIT_DRAW_TYPE_GRASS, pos_table, pos_table }, // 0x0009 + { 2, bIT_DRAW_TYPE_GRASS, pos_table, pos_table }, // 0x000A + { 0, bIT_DRAW_TYPE_NONE, pos_table, pos_table }, // 0x000B + { 0, bIT_DRAW_TYPE_MAPBOARD, pos_table2, pos_table2 }, // 0x000C + { 0, bIT_DRAW_TYPE_NONE, pos_table, pos_table }, // 0x000D + { 0, bIT_DRAW_TYPE_MELODY, pos_table2, pos_table2 }, // 0x000E + { 0, bIT_DRAW_TYPE_NONE, pos_table, pos_table }, // 0x000F + { 0, bIT_DRAW_TYPE_FENCES, pos_table, pos_table }, // 0x0010 + { 0, bIT_DRAW_TYPE_HOLE00_G, pos_table, pos_table }, // 0x0011 + { 1, bIT_DRAW_TYPE_HOLE00_G, pos_table, pos_table }, // 0x0012 + { 2, bIT_DRAW_TYPE_HOLE00_G, pos_table, pos_table }, // 0x0013 + { 3, bIT_DRAW_TYPE_HOLE00_G, pos_table, pos_table }, // 0x0014 + { 4, bIT_DRAW_TYPE_HOLE00_G, pos_table, pos_table }, // 0x0015 + { 5, bIT_DRAW_TYPE_HOLE00_G, pos_table, pos_table }, // 0x0016 + { 6, bIT_DRAW_TYPE_HOLE00_G, pos_table, pos_table }, // 0x0017 + { 7, bIT_DRAW_TYPE_HOLE00_G, pos_table, pos_table }, // 0x0018 + { 8, bIT_DRAW_TYPE_HOLE00_G, pos_table, pos_table }, // 0x0019 + { 9, bIT_DRAW_TYPE_HOLE00_G, pos_table, pos_table }, // 0x001A + { 10, bIT_DRAW_TYPE_HOLE00_G, pos_table, pos_table }, // 0x001B + { 11, bIT_DRAW_TYPE_HOLE00_G, pos_table, pos_table }, // 0x001C + { 12, bIT_DRAW_TYPE_HOLE00_G, pos_table, pos_table }, // 0x001D + { 13, bIT_DRAW_TYPE_HOLE00_G, pos_table, pos_table }, // 0x001E + { 14, bIT_DRAW_TYPE_HOLE00_G, pos_table, pos_table }, // 0x001F + { 15, bIT_DRAW_TYPE_HOLE00_G, pos_table, pos_table }, // 0x0020 + { 16, bIT_DRAW_TYPE_HOLE00_G, pos_table, pos_table }, // 0x0021 + { 17, bIT_DRAW_TYPE_HOLE00_G, pos_table, pos_table }, // 0x0022 + { 18, bIT_DRAW_TYPE_HOLE00_G, pos_table, pos_table }, // 0x0023 + { 19, bIT_DRAW_TYPE_HOLE00_G, pos_table, pos_table }, // 0x0024 + { 20, bIT_DRAW_TYPE_HOLE00_G, pos_table, pos_table }, // 0x0025 + { 21, bIT_DRAW_TYPE_HOLE00_G, pos_table, pos_table }, // 0x0026 + { 22, bIT_DRAW_TYPE_HOLE00_G, pos_table, pos_table }, // 0x0027 + { 23, bIT_DRAW_TYPE_HOLE00_G, pos_table, pos_table }, // 0x0028 + { 24, bIT_DRAW_TYPE_HOLE00_G, pos_table, pos_table }, // 0x0029 + { 0, bIT_DRAW_TYPE_CRACK00_G, pos_table, pos_table }, // 0x002A + { 1, bIT_DRAW_TYPE_CRACK00_G, pos_table, pos_table }, // 0x002B + { 2, bIT_DRAW_TYPE_CRACK00_G, pos_table, pos_table }, // 0x002C + { 3, bIT_DRAW_TYPE_CRACK00_G, pos_table, pos_table }, // 0x002D + { 4, bIT_DRAW_TYPE_CRACK00_G, pos_table, pos_table }, // 0x002E + { 5, bIT_DRAW_TYPE_CRACK00_G, pos_table, pos_table }, // 0x002F + { 6, bIT_DRAW_TYPE_CRACK00_G, pos_table, pos_table }, // 0x0030 + { 7, bIT_DRAW_TYPE_CRACK00_G, pos_table, pos_table }, // 0x0031 + { 8, bIT_DRAW_TYPE_CRACK00_G, pos_table, pos_table }, // 0x0032 + { 9, bIT_DRAW_TYPE_CRACK00_G, pos_table, pos_table }, // 0x0033 + { 10, bIT_DRAW_TYPE_CRACK00_G, pos_table, pos_table }, // 0x0034 + { 11, bIT_DRAW_TYPE_CRACK00_G, pos_table, pos_table }, // 0x0035 + { 12, bIT_DRAW_TYPE_CRACK00_G, pos_table, pos_table }, // 0x0036 + { 13, bIT_DRAW_TYPE_CRACK00_G, pos_table, pos_table }, // 0x0037 + { 14, bIT_DRAW_TYPE_CRACK00_G, pos_table, pos_table }, // 0x0038 + { 15, bIT_DRAW_TYPE_CRACK00_G, pos_table, pos_table }, // 0x0039 + { 16, bIT_DRAW_TYPE_CRACK00_G, pos_table, pos_table }, // 0x003A + { 17, bIT_DRAW_TYPE_CRACK00_G, pos_table, pos_table }, // 0x003B + { 18, bIT_DRAW_TYPE_CRACK00_G, pos_table, pos_table }, // 0x003C + { 19, bIT_DRAW_TYPE_CRACK00_G, pos_table, pos_table }, // 0x003D + { 20, bIT_DRAW_TYPE_CRACK00_G, pos_table, pos_table }, // 0x003E + { 21, bIT_DRAW_TYPE_CRACK00_G, pos_table, pos_table }, // 0x003F + { 22, bIT_DRAW_TYPE_CRACK00_G, pos_table, pos_table }, // 0x0040 + { 23, bIT_DRAW_TYPE_CRACK00_G, pos_table, pos_table }, // 0x0041 + { 24, bIT_DRAW_TYPE_CRACK00_G, pos_table, pos_table }, // 0x0042 + { 0, bIT_DRAW_TYPE_CRACK00_G, pos_table, pos_table }, // 0x0043 + { 1, bIT_DRAW_TYPE_CRACK00_G, pos_table, pos_table }, // 0x0044 + { 2, bIT_DRAW_TYPE_CRACK00_G, pos_table, pos_table }, // 0x0045 + { 3, bIT_DRAW_TYPE_CRACK00_G, pos_table, pos_table }, // 0x0046 + { 4, bIT_DRAW_TYPE_CRACK00_G, pos_table, pos_table }, // 0x0047 + { 5, bIT_DRAW_TYPE_CRACK00_G, pos_table, pos_table }, // 0x0048 + { 6, bIT_DRAW_TYPE_CRACK00_G, pos_table, pos_table }, // 0x0049 + { 7, bIT_DRAW_TYPE_CRACK00_G, pos_table, pos_table }, // 0x004A + { 8, bIT_DRAW_TYPE_CRACK00_G, pos_table, pos_table }, // 0x004B + { 9, bIT_DRAW_TYPE_CRACK00_G, pos_table, pos_table }, // 0x004C + { 10, bIT_DRAW_TYPE_CRACK00_G, pos_table, pos_table }, // 0x004D + { 11, bIT_DRAW_TYPE_CRACK00_G, pos_table, pos_table }, // 0x004E + { 12, bIT_DRAW_TYPE_CRACK00_G, pos_table, pos_table }, // 0x004F + { 13, bIT_DRAW_TYPE_CRACK00_G, pos_table, pos_table }, // 0x0050 + { 14, bIT_DRAW_TYPE_CRACK00_G, pos_table, pos_table }, // 0x0051 + { 15, bIT_DRAW_TYPE_CRACK00_G, pos_table, pos_table }, // 0x0052 + { 16, bIT_DRAW_TYPE_CRACK00_G, pos_table, pos_table }, // 0x0053 + { 17, bIT_DRAW_TYPE_CRACK00_G, pos_table, pos_table }, // 0x0054 + { 18, bIT_DRAW_TYPE_CRACK00_G, pos_table, pos_table }, // 0x0055 + { 19, bIT_DRAW_TYPE_CRACK00_G, pos_table, pos_table }, // 0x0056 + { 20, bIT_DRAW_TYPE_CRACK00_G, pos_table, pos_table }, // 0x0057 + { 21, bIT_DRAW_TYPE_CRACK00_G, pos_table, pos_table }, // 0x0058 + { 22, bIT_DRAW_TYPE_CRACK00_G, pos_table, pos_table }, // 0x0059 + { 23, bIT_DRAW_TYPE_CRACK00_G, pos_table, pos_table }, // 0x005A + { 24, bIT_DRAW_TYPE_CRACK00_G, pos_table, pos_table }, // 0x005B + { 0, bIT_DRAW_TYPE_NONE, pos_table, pos_table }, // 0x005C + { 0, bIT_DRAW_TYPE_HOLE00_SHIN_G, pos_table, pos_table }, // 0x005D + { 0, bIT_DRAW_TYPE_TREE4, pos_table, pos_table }, // 0x005E + { 0, bIT_DRAW_TYPE_TREE4, pos_table, pos_table }, // 0x005F + { 0, bIT_DRAW_TYPE_TREE4, pos_table, pos_table }, // 0x0060 + { 0, bIT_DRAW_TYPE_TREE4, pos_table, pos_table }, // 0x0061 + { 0, bIT_DRAW_TYPE_HONYCOMB, pos_table, pos_table }, // 0x0062 + { 0, bIT_DRAW_TYPE_STONE_A, pos_table, pos_table }, // 0x0063 + { 1, bIT_DRAW_TYPE_STONE_B, pos_table, pos_table }, // 0x0064 + { 2, bIT_DRAW_TYPE_STONE_C, pos_table, pos_table }, // 0x0065 + { 3, bIT_DRAW_TYPE_STONE_D, pos_table, pos_table }, // 0x0066 + { 4, bIT_DRAW_TYPE_STONE_E, pos_table, pos_table }, // 0x0067 + { 0, bIT_DRAW_TYPE_TANE, pos_table, pos_table }, // 0x0068 + { 0, bIT_DRAW_TYPE_TREE4, pos_table, pos_table }, // 0x0069 + { 0, bIT_DRAW_TYPE_STONE_A, pos_table, pos_table }, // 0x006A + { 1, bIT_DRAW_TYPE_STONE_B, pos_table, pos_table }, // 0x006B + { 2, bIT_DRAW_TYPE_STONE_C, pos_table, pos_table }, // 0x006C + { 3, bIT_DRAW_TYPE_STONE_D, pos_table, pos_table }, // 0x006D + { 4, bIT_DRAW_TYPE_STONE_E, pos_table, pos_table }, // 0x006E + { 0, bIT_DRAW_TYPE_NONE, pos_table, pos_table }, // 0x006F + { 0, bIT_DRAW_TYPE_PALM_STUMP001, pos_table, pos_table }, // 0x0070 + { 0, bIT_DRAW_TYPE_PALM_STUMP002, pos_table, pos_table }, // 0x0071 + { 0, bIT_DRAW_TYPE_PALM_STUMP003, pos_table, pos_table }, // 0x0072 + { 0, bIT_DRAW_TYPE_PALM_STUMP004, pos_table, pos_table }, // 0x0073 + { 0, bIT_DRAW_TYPE_CEDAR_STUMP001, pos_table, pos_table }, // 0x0074 + { 0, bIT_DRAW_TYPE_CEDAR_STUMP002, pos_table, pos_table }, // 0x0075 + { 0, bIT_DRAW_TYPE_CEDAR_STUMP003, pos_table, pos_table }, // 0x0076 + { 0, bIT_DRAW_TYPE_CEDAR_STUMP004, pos_table, pos_table }, // 0x0077 + { 0, bIT_DRAW_TYPE_CEDAR004, pos_table, pos_table }, // 0x0078 + { 0, bIT_DRAW_TYPE_CEDAR004, pos_table, pos_table }, // 0x0079 + { 0, bIT_DRAW_TYPE_CEDAR004, pos_table, pos_table }, // 0x007A + { 0, bIT_DRAW_TYPE_GOLD_TREE_STUMP001, pos_table, pos_table }, // 0x007B + { 0, bIT_DRAW_TYPE_GOLD_TREE_STUMP002, pos_table, pos_table }, // 0x007C + { 0, bIT_DRAW_TYPE_GOLD_TREE_STUMP003, pos_table, pos_table }, // 0x007D + { 0, bIT_DRAW_TYPE_GOLD_TREE_STUMP004, pos_table, pos_table }, // 0x007E + { 0, bIT_DRAW_TYPE_GOLD_TREE004, pos_table, pos_table }, // 0x007F + { 0, bIT_DRAW_TYPE_GOLD_TREE004, pos_table, pos_table }, // 0x0080 + { 0, bIT_DRAW_TYPE_GOLD_TREE004, pos_table, pos_table }, // 0x0081 + { 0, bIT_DRAW_TYPE_CEDAR004, pos_table, pos_table }, // 0x0082 +}; + +static bg_item_type_data_c typeData_table_bgItem2[] = { + { 0, bIT_DRAW_TYPE_TREE0, pos_table, pos_table }, // 0x0800 + { 0, bIT_DRAW_TYPE_TREE1, pos_table, pos_table }, // 0x0801 + { 0, bIT_DRAW_TYPE_TREE2, pos_table, pos_table }, // 0x0802 + { 0, bIT_DRAW_TYPE_TREE3, pos_table, pos_table }, // 0x0803 + { 0, bIT_DRAW_TYPE_TREE4, pos_table, pos_table }, // 0x0804 + { 0, bIT_DRAW_TYPE_TREE0, pos_table, pos_table }, // 0x0805 + { 0, bIT_DRAW_TYPE_TREE1, pos_table, pos_table }, // 0x0806 + { 0, bIT_DRAW_TYPE_TREE2, pos_table, pos_table }, // 0x0807 + { 0, bIT_DRAW_TYPE_TREE3, pos_table, pos_table }, // 0x0808 + { 0, bIT_DRAW_TYPE_TREE4, pos_table, pos_table }, // 0x0809 + { 0, bIT_DRAW_TYPE_TREE4, pos_table, pos_table }, // 0x080A + { 0, bIT_DRAW_TYPE_TREE4, pos_table, pos_table }, // 0x080B + { 0, bIT_DRAW_TYPE_TREE4_AP, pos_table, pos_table }, // 0x080C + { 0, bIT_DRAW_TYPE_TREE0, pos_table, pos_table }, // 0x080D + { 0, bIT_DRAW_TYPE_TREE1, pos_table, pos_table }, // 0x080E + { 0, bIT_DRAW_TYPE_TREE2, pos_table, pos_table }, // 0x080F + { 0, bIT_DRAW_TYPE_TREE3, pos_table, pos_table }, // 0x0810 + { 0, bIT_DRAW_TYPE_TREE4, pos_table, pos_table }, // 0x0811 + { 0, bIT_DRAW_TYPE_TREE4, pos_table, pos_table }, // 0x0812 + { 0, bIT_DRAW_TYPE_TREE4, pos_table, pos_table }, // 0x0813 + { 0, bIT_DRAW_TYPE_TREE4_OR, pos_table, pos_table }, // 0x0814 + { 0, bIT_DRAW_TYPE_TREE0, pos_table, pos_table }, // 0x0815 + { 0, bIT_DRAW_TYPE_TREE1, pos_table, pos_table }, // 0x0816 + { 0, bIT_DRAW_TYPE_TREE2, pos_table, pos_table }, // 0x0817 + { 0, bIT_DRAW_TYPE_TREE3, pos_table, pos_table }, // 0x0818 + { 0, bIT_DRAW_TYPE_TREE4, pos_table, pos_table }, // 0x0819 + { 0, bIT_DRAW_TYPE_TREE4, pos_table, pos_table }, // 0x081A + { 0, bIT_DRAW_TYPE_TREE4, pos_table, pos_table }, // 0x081B + { 0, bIT_DRAW_TYPE_TREE4_PH, pos_table, pos_table }, // 0x081C + { 0, bIT_DRAW_TYPE_TREE0, pos_table, pos_table }, // 0x081D + { 0, bIT_DRAW_TYPE_TREE1, pos_table, pos_table }, // 0x081E + { 0, bIT_DRAW_TYPE_TREE2, pos_table, pos_table }, // 0x081F + { 0, bIT_DRAW_TYPE_TREE3, pos_table, pos_table }, // 0x0820 + { 0, bIT_DRAW_TYPE_TREE4, pos_table, pos_table }, // 0x0821 + { 0, bIT_DRAW_TYPE_TREE4, pos_table, pos_table }, // 0x0822 + { 0, bIT_DRAW_TYPE_TREE4, pos_table, pos_table }, // 0x0823 + { 0, bIT_DRAW_TYPE_TREE4_PR, pos_table, pos_table }, // 0x0824 + { 0, bIT_DRAW_TYPE_TREE0, pos_table, pos_table }, // 0x0825 + { 0, bIT_DRAW_TYPE_TREE1, pos_table, pos_table }, // 0x0826 + { 0, bIT_DRAW_TYPE_TREE2, pos_table, pos_table }, // 0x0827 + { 0, bIT_DRAW_TYPE_TREE3, pos_table, pos_table }, // 0x0828 + { 0, bIT_DRAW_TYPE_TREE4, pos_table, pos_table }, // 0x0829 + { 0, bIT_DRAW_TYPE_TREE4, pos_table, pos_table }, // 0x082A + { 0, bIT_DRAW_TYPE_TREE4, pos_table, pos_table }, // 0x082B + { 0, bIT_DRAW_TYPE_TREE4_NT, pos_table, pos_table }, // 0x082C + { 0, bIT_DRAW_TYPE_TREE0, pos_table, pos_table }, // 0x082D + { 0, bIT_DRAW_TYPE_TREE1, pos_table, pos_table }, // 0x082E + { 0, bIT_DRAW_TYPE_TREE2, pos_table, pos_table }, // 0x082F + { 0, bIT_DRAW_TYPE_TREE3, pos_table, pos_table }, // 0x0830 + { 0, bIT_DRAW_TYPE_TREE4_BG, pos_table, pos_table }, // 0x0831 + { 0, bIT_DRAW_TYPE_TREE0, pos_table, pos_table }, // 0x0832 + { 0, bIT_DRAW_TYPE_TREE1, pos_table, pos_table }, // 0x0833 + { 0, bIT_DRAW_TYPE_TREE2, pos_table, pos_table }, // 0x0834 + { 0, bIT_DRAW_TYPE_TREE3, pos_table, pos_table }, // 0x0835 + { 0, bIT_DRAW_TYPE_TREE4_BG, pos_table, pos_table }, // 0x0836 + { 0, bIT_DRAW_TYPE_TREE0, pos_table, pos_table }, // 0x0837 + { 0, bIT_DRAW_TYPE_TREE1, pos_table, pos_table }, // 0x0838 + { 0, bIT_DRAW_TYPE_TREE2, pos_table, pos_table }, // 0x0839 + { 0, bIT_DRAW_TYPE_TREE3, pos_table, pos_table }, // 0x083A + { 0, bIT_DRAW_TYPE_TREE4_BG, pos_table, pos_table }, // 0x083B + { 0, bIT_DRAW_TYPE_FLOWER_LEAF, pos_table, pos_table }, // 0x083C + { 0, bIT_DRAW_TYPE_FLOWER_LEAF, pos_table, pos_table }, // 0x083D + { 0, bIT_DRAW_TYPE_FLOWER_LEAF, pos_table, pos_table }, // 0x083E + { 0, bIT_DRAW_TYPE_FLOWER_LEAF, pos_table, pos_table }, // 0x083F + { 0, bIT_DRAW_TYPE_FLOWER_LEAF, pos_table, pos_table }, // 0x0840 + { 0, bIT_DRAW_TYPE_FLOWER_LEAF, pos_table, pos_table }, // 0x0841 + { 0, bIT_DRAW_TYPE_FLOWER_LEAF, pos_table, pos_table }, // 0x0842 + { 0, bIT_DRAW_TYPE_FLOWER_LEAF, pos_table, pos_table }, // 0x0843 + { 0, bIT_DRAW_TYPE_FLOWER_LEAF, pos_table, pos_table }, // 0x0844 + { 0, bIT_DRAW_TYPE_FLOWER00, pos_table, pos_table }, // 0x0845 + { 0, bIT_DRAW_TYPE_FLOWER01, pos_table, pos_table }, // 0x0846 + { 0, bIT_DRAW_TYPE_FLOWER02, pos_table, pos_table }, // 0x0847 + { 1, bIT_DRAW_TYPE_FLOWER00, pos_table, pos_table }, // 0x0848 + { 1, bIT_DRAW_TYPE_FLOWER01, pos_table, pos_table }, // 0x0849 + { 1, bIT_DRAW_TYPE_FLOWER02, pos_table, pos_table }, // 0x084A + { 2, bIT_DRAW_TYPE_FLOWER00, pos_table, pos_table }, // 0x084B + { 2, bIT_DRAW_TYPE_FLOWER01, pos_table, pos_table }, // 0x084C + { 2, bIT_DRAW_TYPE_FLOWER02, pos_table, pos_table }, // 0x084D + { 0, bIT_DRAW_TYPE_TREE0_DEAD, pos_table, pos_table }, // 0x084E + { 0, bIT_DRAW_TYPE_TREE0, pos_table, pos_table }, // 0x084F + { 0, bIT_DRAW_TYPE_TREE1, pos_table, pos_table }, // 0x0850 + { 0, bIT_DRAW_TYPE_TREE2, pos_table, pos_table }, // 0x0851 + { 0, bIT_DRAW_TYPE_TREE3, pos_table, pos_table }, // 0x0852 + { 0, bIT_DRAW_TYPE_TREE4_BG, pos_table, pos_table }, // 0x0853 + { 0, bIT_DRAW_TYPE_PALM000, pos_table, pos_table }, // 0x0854 + { 0, bIT_DRAW_TYPE_PALM001, pos_table, pos_table }, // 0x0855 + { 0, bIT_DRAW_TYPE_PALM002, pos_table, pos_table }, // 0x0856 + { 0, bIT_DRAW_TYPE_PALM003, pos_table, pos_table }, // 0x0857 + { 0, bIT_DRAW_TYPE_PALM004, pos_table, pos_table }, // 0x0858 + { 0, bIT_DRAW_TYPE_PALM004, pos_table, pos_table }, // 0x0859 + { 0, bIT_DRAW_TYPE_PALM004, pos_table, pos_table }, // 0x085A + { 0, bIT_DRAW_TYPE_PALM004_CC, pos_table, pos_table }, // 0x085B + { 0, bIT_DRAW_TYPE_PALM000_DEAD, pos_table, pos_table }, // 0x085C + { 0, bIT_DRAW_TYPE_CEDAR000, pos_table, pos_table }, // 0x085D + { 0, bIT_DRAW_TYPE_CEDAR001, pos_table, pos_table }, // 0x085E + { 0, bIT_DRAW_TYPE_CEDAR002, pos_table, pos_table }, // 0x085F + { 0, bIT_DRAW_TYPE_CEDAR003, pos_table, pos_table }, // 0x0860 + { 0, bIT_DRAW_TYPE_CEDAR004, pos_table, pos_table }, // 0x0861 + { 0, bIT_DRAW_TYPE_CEDAR000_DEAD, pos_table, pos_table }, // 0x0862 + { 0, bIT_DRAW_TYPE_GOLD_TREE000, pos_table, pos_table }, // 0x0863 + { 0, bIT_DRAW_TYPE_GOLD_TREE001, pos_table, pos_table }, // 0x0864 + { 0, bIT_DRAW_TYPE_GOLD_TREE002, pos_table, pos_table }, // 0x0865 + { 0, bIT_DRAW_TYPE_GOLD_TREE003, pos_table, pos_table }, // 0x0866 + { 0, bIT_DRAW_TYPE_GOLD_TREE004, pos_table, pos_table }, // 0x0867 + { 0, bIT_DRAW_TYPE_GOLD_TREE004, pos_table, pos_table }, // 0x0868 + { 0, bIT_DRAW_TYPE_GOLD_TREE000_DEAD, pos_table, pos_table }, // 0x0869 +}; + +static bg_item_type_data_c typeData_table_dummy[] = { + { 0, bIT_DRAW_TYPE_FISH2, pos_table, pos_table }, +}; + +// BG draw data here + +static bg_item_type_data_c typeData_table_item1[] = { + { 0, bIT_DRAW_TYPE_APPLE, pos_table, pos_table }, // 2XXX +}; + +static bg_item_type_data_c typeData_table_ftr[] = { + { 0, bIT_DRAW_TYPE_LEAF, pos_table, pos_table }, // 1XXX, 3XXX +}; + +static bg_item_type_data_c typeData_table_crack[] = { + { 0, bIT_DRAW_TYPE_CRACK00_G, pos_table, pos_table }, +}; diff --git a/src/bg_item_draw.c_inc b/src/bg_item_draw.c_inc new file mode 100644 index 00000000..b7594a23 --- /dev/null +++ b/src/bg_item_draw.c_inc @@ -0,0 +1,6 @@ +static void bIT_actor_draw(ACTOR* actorx, GAME* game) { + BG_ITEM_ACTOR* bg_item = (BG_ITEM_ACTOR*)actorx; + GAME_PLAY* play = (GAME_PLAY*)game; + + bg_item_common_draw(play, &bg_item->common, draw_part_table_a); +} diff --git a/src/bg_item_move.c_inc b/src/bg_item_move.c_inc new file mode 100644 index 00000000..1892d3f1 --- /dev/null +++ b/src/bg_item_move.c_inc @@ -0,0 +1,35 @@ +static bg_item_type_data_c type_data_table_p_a[bIT_TYPE_CAT_NUM] = { + // TODO +}; + +static int bg_item_talking_display_limit_check(int idx) { + int res = FALSE; + + if ((idx >= bIT_DRAW_TYPE_TREE2 && idx <= bIT_DRAW_TYPE_TREE4_BG) || + (idx >= bIT_DRAW_TYPE_PALM002 && idx <= bIT_DRAW_TYPE_PALM004_CC) || + (idx >= bIT_DRAW_TYPE_CEDAR002 && idx <= bIT_DRAW_TYPE_CEDAR004) || + (idx >= bIT_DRAW_TYPE_GOLD_TREE002 && idx <= bIT_DRAW_TYPE_GOLD_TREE004) || idx == bIT_DRAW_TYPE_NOTICE || + idx == bIT_DRAW_TYPE_MAPBOARD || idx == bIT_DRAW_TYPE_MELODY) { + res = TRUE; + } + + return res; +} + +static void bIT_actor_move(ACTOR* actorx, GAME* game) { + BG_ITEM_ACTOR* bg_item = (BG_ITEM_ACTOR*)actorx; + GAME_PLAY* play = (GAME_PLAY*)game; + bg_item_common_c* common = &bg_item->common; + bg_item_common_info_c* common_info = &common->common_info; + + common_info->type_data_table_p = type_data_table_p_a; + common_info->pos_table_p = pos_table; + common->flags = 0; + + if (Camera2_CheckCullingMode() != FALSE) { + common->flags |= 1; + } + + common->talk_display_limit_check_proc = &bg_item_talking_display_limit_check; + bg_item_common_move(play, actorx, &bg_item->common); +} diff --git a/src/ef_room_sunshine.c b/src/ef_room_sunshine.c index a3df47d7..c764606a 100644 --- a/src/ef_room_sunshine.c +++ b/src/ef_room_sunshine.c @@ -17,7 +17,7 @@ extern Vtx light_floorL01_vtx[]; extern Vtx light_floorR01_vtx[]; extern Gfx light_shine01_mode[]; extern Vtx light_shineL01_vtx[]; -extern Vtx light_shineR01_vtx[]; +extern Vtx light_shineR01_vtx[]; ACTOR_PROFILE Room_Sunshine_Profile = { mAc_PROFILE_ROOM_SUNSHINE, @@ -33,111 +33,105 @@ ACTOR_PROFILE Room_Sunshine_Profile = { NULL, }; -void Ef_Room_Sunshine_actor_ct(ACTOR* actor, GAME* game){ +static void Ef_Room_Sunshine_actor_ct(ACTOR* actor, GAME* game) { ROOMSUNSHINE_ACTOR* sunshine = (ROOMSUNSHINE_ACTOR*)actor; xyz_t pos; - xyz_t pos2; + xyz_t pos2; xyz_t pos3; - + sunshine->unk_174 = 0; - if(sunshine->actor_class.actor_specific == 0){ + if (sunshine->actor_class.actor_specific == 0) { sunshine->actor_class.mv_proc = Ef_Room_SunshineL_actor_move; sunshine->actor_class.dw_proc = Ef_Room_SunshineL_actor_draw; - } - else{ + } else { sunshine->actor_class.world.position.x -= 1.0f; } - sunshine->actor_class.world.position.y = mCoBG_GetBgY_OnlyCenter_FromWpos(sunshine->actor_class.world.position, 0.0f); + sunshine->actor_class.world.position.y = + mCoBG_GetBgY_OnlyCenter_FromWpos(sunshine->actor_class.world.position, 0.0f); sunshine->actor_class.scale.x = 1.0f; sunshine->actor_class.scale.y = 1.0f; sunshine->actor_class.scale.z = 1.0f; - switch(sunshine->actor_class.actor_specific){ + switch (sunshine->actor_class.actor_specific) { case 2: - + sunshine->actor_class.mv_proc = Ef_Room_SunshineL_actor_move; sunshine->actor_class.dw_proc = Ef_Room_SunshineL_actor_draw; sunshine->actor_class.world.position.x += 5.0f; - sunshine->actor_class.world.position.y = 1.0f + mCoBG_GetBgY_OnlyCenter_FromWpos(sunshine->actor_class.world.position, 0.0f); + sunshine->actor_class.world.position.y = + 1.0f + mCoBG_GetBgY_OnlyCenter_FromWpos(sunshine->actor_class.world.position, 0.0f); sunshine->actor_class.world.position.x -= 6.0f; - break; + break; case 3: sunshine->actor_class.world.position.x -= 5.0f; - sunshine->actor_class.world.position.y = 1.0f + mCoBG_GetBgY_OnlyCenter_FromWpos(sunshine->actor_class.world.position, 0.0f); + sunshine->actor_class.world.position.y = + 1.0f + mCoBG_GetBgY_OnlyCenter_FromWpos(sunshine->actor_class.world.position, 0.0f); sunshine->actor_class.world.position.x += 6.0f; - break; + break; } } +static f32 calc_scale_Ef_Room_Sunshine(int flag, int sec) { -f32 calc_scale_Ef_Room_Sunshine(int flag, int sec){ - - if(flag == 0){ + if (flag == 0) { return 1.5f * sin_s((sec << 14) / 28800.0f); - } - else{ + } else { return 1.5f * sin_s((sec << 14) / 14400.0f); } } -int calc_alpha_Ef_Room_Sunshine(){ +static int calc_alpha_Ef_Room_Sunshine() { f32 ret; int sec; - - if(Common_Get(time.now_sec) < 14400){ - ret = (120.0f + GETREG(TAKREG,30)) * ((14400 - Common_Get(time.now_sec)) / 14400.0f); - } - else if(Common_Get(time.now_sec) < 72000){ - sec = (Common_Get(time.now_sec) - 43200) >= 0 ? - (Common_Get(time.now_sec) - 43200U) : -(Common_Get(time.now_sec) - 43200U); + + if (Common_Get(time.now_sec) < 14400) { + ret = (120.0f + GETREG(TAKREG, 30)) * ((14400 - Common_Get(time.now_sec)) / 14400.0f); + } else if (Common_Get(time.now_sec) < 72000) { + sec = (Common_Get(time.now_sec) - 43200) >= 0 ? (Common_Get(time.now_sec) - 43200U) + : -(Common_Get(time.now_sec) - 43200U); ret = 255.0f * ((28800 - sec) / 28800.0f); - } - else{ - ret = (120.0f + GETREG(TAKREG,30)) * ((14400 - (86400 - Common_Get(time.now_sec))) / 14400.0f); + } else { + ret = (120.0f + GETREG(TAKREG, 30)) * ((14400 - (86400 - Common_Get(time.now_sec))) / 14400.0f); } - if((Common_Get(weather) == 1) || (Common_Get(weather) == 2)){ + if ((Common_Get(weather) == 1) || (Common_Get(weather) == 2)) { ret *= 0.6f; } - + return (u8)ret; } -void Ef_Room_SunshineL_actor_move(ACTOR* actor, GAME* game){ +static void Ef_Room_SunshineL_actor_move(ACTOR* actor, GAME* game) { ROOMSUNSHINE_ACTOR* sunshine = (ROOMSUNSHINE_ACTOR*)actor; - - if(Common_Get(time.now_sec) < 14400){ + + if (Common_Get(time.now_sec) < 14400) { sunshine->actor_class.scale.x = calc_scale_Ef_Room_Sunshine(1, Common_Get(time.now_sec)); - } - else if ((Common_Get(time.now_sec) >= 43200) && (Common_Get(time.now_sec) < 72000)){ + } else if ((Common_Get(time.now_sec) >= 43200) && (Common_Get(time.now_sec) < 72000)) { sunshine->actor_class.scale.x = calc_scale_Ef_Room_Sunshine(0, Common_Get(time.now_sec) - 43200); - } - else{ - sunshine->actor_class.scale.x = 0.0f; + } else { + sunshine->actor_class.scale.x = 0.0f; } } -void Ef_Room_SunshineR_actor_move(ACTOR* actor, GAME* game){ +static void Ef_Room_SunshineR_actor_move(ACTOR* actor, GAME* game) { ROOMSUNSHINE_ACTOR* sunshine = (ROOMSUNSHINE_ACTOR*)actor; - - if((Common_Get(time.now_sec) >= 14400) && (Common_Get(time.now_sec) < 43200)){ + + if ((Common_Get(time.now_sec) >= 14400) && (Common_Get(time.now_sec) < 43200)) { sunshine->actor_class.scale.x = calc_scale_Ef_Room_Sunshine(0, 43200 - Common_Get(time.now_sec)); - } - else if (Common_Get(time.now_sec) >= 72000){ - sunshine->actor_class.scale.x = calc_scale_Ef_Room_Sunshine(1, 86400 -Common_Get(time.now_sec)); - } - else{ - sunshine->actor_class.scale.x = 0.0f; + } else if (Common_Get(time.now_sec) >= 72000) { + sunshine->actor_class.scale.x = calc_scale_Ef_Room_Sunshine(1, 86400 - Common_Get(time.now_sec)); + } else { + sunshine->actor_class.scale.x = 0.0f; } } -void setup_mode_Ef_Room_Sunshine(ACTOR* actor, GAME_PLAY* play){ +static void setup_mode_Ef_Room_Sunshine(ACTOR* actor, GAME_PLAY* play) { ROOMSUNSHINE_ACTOR* sunshine = (ROOMSUNSHINE_ACTOR*)actor; u8* color; f32 alpha; @@ -146,41 +140,39 @@ void setup_mode_Ef_Room_Sunshine(ACTOR* actor, GAME_PLAY* play){ OPEN_DISP(graph); - Matrix_translate(sunshine->actor_class.world.position.x, 0.1f +sunshine->actor_class.world.position.y, - sunshine->actor_class.world.position.z, 0); - Matrix_scale(sunshine->actor_class.scale.x, sunshine->actor_class.scale.y, sunshine->actor_class.scale.z,1); + Matrix_translate(sunshine->actor_class.world.position.x, 0.1f + sunshine->actor_class.world.position.y, + sunshine->actor_class.world.position.z, 0); + Matrix_scale(sunshine->actor_class.scale.x, sunshine->actor_class.scale.y, sunshine->actor_class.scale.z, 1); gDPPipeSync(NEXT_POLY_XLU_DISP); gSPMatrix(NEXT_POLY_XLU_DISP, _Matrix_to_Mtx_new(play->game.graph), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); - if((Common_Get(time.now_sec) >= 14400) && (Common_Get(time.now_sec) < 72000)){ - color =play->kankyo.base_light.sun_color_window; - } - else{ - color =play->kankyo.base_light.moon_color_window; + if ((Common_Get(time.now_sec) >= 14400) && (Common_Get(time.now_sec) < 72000)) { + color = play->kankyo.base_light.sun_color_window; + } else { + color = play->kankyo.base_light.moon_color_window; } alpha = (u8)calc_alpha_Ef_Room_Sunshine() * mKK_windowlight_alpha_get(); - - gDPSetPrimColor(NEXT_POLY_XLU_DISP, 0,0, color[0], color[1], color[2], (int)(alpha)); + + gDPSetPrimColor(NEXT_POLY_XLU_DISP, 0, 0, color[0], color[1], color[2], (int)(alpha)); CLOSE_DISP(graph); - } -void Ef_Room_SunshineL_actor_draw(ACTOR* actor, GAME* game){ +static void Ef_Room_SunshineL_actor_draw(ACTOR* actor, GAME* game) { GAME_PLAY* play = (GAME_PLAY*)game; GRAPH* graph; - - if((mKK_windowlight_alpha_get() < 9.99999974738e-05f) || (actor->scale.x == 0.0f)){ - return; + + if ((mKK_windowlight_alpha_get() < 9.99999974738e-05f) || (actor->scale.x == 0.0f)) { + return; } graph = play->game.graph; setup_mode_Ef_Room_Sunshine(actor, play); OPEN_DISP(graph); - + gSPDisplayList(NEXT_POLY_XLU_DISP, light_floor01_mode); gSPDisplayList(NEXT_POLY_XLU_DISP, light_floorL01_vtx); gSPDisplayList(NEXT_POLY_XLU_DISP, light_shine01_mode); @@ -189,14 +181,13 @@ void Ef_Room_SunshineL_actor_draw(ACTOR* actor, GAME* game){ CLOSE_DISP(graph); } - -void Ef_Room_SunshineR_actor_draw(ACTOR* actor, GAME* game){ +static void Ef_Room_SunshineR_actor_draw(ACTOR* actor, GAME* game) { GAME_PLAY* play = (GAME_PLAY*)game; GRAPH* graph; - - if((mKK_windowlight_alpha_get() < 9.99999974738e-05f) || (actor->scale.x == 0.0f)){ - return; + + if ((mKK_windowlight_alpha_get() < 9.99999974738e-05f) || (actor->scale.x == 0.0f)) { + return; } graph = play->game.graph; setup_mode_Ef_Room_Sunshine(actor, play); @@ -207,6 +198,6 @@ void Ef_Room_SunshineR_actor_draw(ACTOR* actor, GAME* game){ gSPDisplayList(NEXT_POLY_XLU_DISP, light_floorR01_vtx); gSPDisplayList(NEXT_POLY_XLU_DISP, light_shine01_mode); gSPDisplayList(NEXT_POLY_XLU_DISP, light_shineR01_vtx); - + CLOSE_DISP(graph); -} \ No newline at end of file +} diff --git a/src/ef_room_sunshine_minsect.c b/src/ef_room_sunshine_minsect.c index 879ef833..5e88f9db 100644 --- a/src/ef_room_sunshine_minsect.c +++ b/src/ef_room_sunshine_minsect.c @@ -5,6 +5,7 @@ #include "m_debug.h" #include "m_collision_bg.h" #include "sys_matrix.h" +#include "m_rcp.h" void Ef_Room_Sunshine_Minsect_actor_ct(ACTOR* actor, GAME* play); void Ef_Room_Sunshine_Minsect_actor_dt(ACTOR* actor, GAME* play); @@ -34,114 +35,110 @@ ACTOR_PROFILE Room_Sunshine_Minsect_Profile = { NULL, }; -void Ef_Room_Sunshine_Minsect_actor_ct(ACTOR* actor, GAME* game){ +static void Ef_Room_Sunshine_Minsect_actor_ct(ACTOR* actor, GAME* game) { ROOMSUNSHINEMINSECT_ACTOR* minsect = (ROOMSUNSHINEMINSECT_ACTOR*)actor; xyz_t pos; - + minsect->ef_sunshine_class.unk_174 = 0; draw_status = 0; - if(minsect->ef_sunshine_class.actor_class.actor_specific == 0){ + if (minsect->ef_sunshine_class.actor_class.actor_specific == 0) { minsect->ef_sunshine_class.actor_class.mv_proc = Ef_Room_Sunshine_MinsectL_actor_move; minsect->ef_sunshine_class.actor_class.dw_proc = Ef_Room_Sunshine_MinsectL_actor_draw; - } - else{ + } else { minsect->ef_sunshine_class.actor_class.world.position.x -= 1.0f; } - - minsect->ef_sunshine_class.actor_class.world.position.y = mCoBG_GetBgY_OnlyCenter_FromWpos(minsect->ef_sunshine_class.actor_class.world.position, 0.0f); + + minsect->ef_sunshine_class.actor_class.world.position.y = + mCoBG_GetBgY_OnlyCenter_FromWpos(minsect->ef_sunshine_class.actor_class.world.position, 0.0f); minsect->ef_sunshine_class.actor_class.scale.x = 0.01f; minsect->ef_sunshine_class.actor_class.scale.y = 0.01f; minsect->ef_sunshine_class.actor_class.scale.z = 0.01f; - minsect->ef_sunshine_class.actor_class.cull_radius = 10000.0f; + minsect->ef_sunshine_class.actor_class.cull_radius = 10000.0f; - switch(minsect->ef_sunshine_class.actor_class.actor_specific){ + switch (minsect->ef_sunshine_class.actor_class.actor_specific) { case 2: - + minsect->ef_sunshine_class.actor_class.mv_proc = Ef_Room_Sunshine_MinsectL_actor_move; minsect->ef_sunshine_class.actor_class.dw_proc = Ef_Room_Sunshine_MinsectL_actor_draw; minsect->ef_sunshine_class.actor_class.world.position.x += 5.0f; minsect->ef_sunshine_class.actor_class.world.position.x -= 6.0f; - break; + break; case 3: minsect->ef_sunshine_class.actor_class.world.position.x -= 5.0f; minsect->ef_sunshine_class.actor_class.world.position.x += 6.0f; - break; + break; } } -f32 calc_scale_Ef_Room_Sunshine_Minsect(int flag, int sec){ - - if(flag == 0){ +static f32 calc_scale_Ef_Room_Sunshine_Minsect(int flag, int sec) { + + if (flag == 0) { return 0.01f * (1.5f * sin_s((sec << 14) / 28800.0f)); - } - else{ + } else { return 0.01f * (1.5f * sin_s((sec << 14) / 14400.0f)); } } -int calc_alpha_Ef_Room_SunshineMinsect(){ +static int calc_alpha_Ef_Room_SunshineMinsect() { f32 ret; int sec; - - if(Common_Get(time.now_sec) < 14400){ - ret = 120.0f * ((14400 - Common_Get(time.now_sec)) / 14400.0f); - } - else if(Common_Get(time.now_sec) < 72000){ - //any other number matches codegen, but 43200 breaks - sec = (Common_Get(time.now_sec) - 43200) >= 0 ? - (Common_Get(time.now_sec) - 43200U) : -(Common_Get(time.now_sec) - 43200U); + + if (Common_Get(time.now_sec) < 14400) { + ret = 120.0f * ((14400 - Common_Get(time.now_sec)) / 14400.0f); + } else if (Common_Get(time.now_sec) < 72000) { + // any other number matches codegen, but 43200 breaks + sec = (Common_Get(time.now_sec) - 43200) >= 0 ? (Common_Get(time.now_sec) - 43200U) + : -(Common_Get(time.now_sec) - 43200U); ret = 255.0f * ((28800 - sec) / 28800.0f); - } - else{ - ret = 120.0f * ((14400 - (86400 - Common_Get(time.now_sec))) / 14400.0f); + } else { + ret = 120.0f * ((14400 - (86400 - Common_Get(time.now_sec))) / 14400.0f); } - if((Common_Get(weather) == 1) || (Common_Get(weather) == 2)){ + if ((Common_Get(weather) == 1) || (Common_Get(weather) == 2)) { ret *= 0.6f; } - + return (u8)ret; } -void Ef_Room_Sunshine_MinsectL_actor_move(ACTOR* actor, GAME* game){ +static void Ef_Room_Sunshine_MinsectL_actor_move(ACTOR* actor, GAME* game) { ROOMSUNSHINEMINSECT_ACTOR* minsect = (ROOMSUNSHINEMINSECT_ACTOR*)actor; - - if(Common_Get(time.now_sec) < 14400){ - minsect->ef_sunshine_class.actor_class.scale.x = calc_scale_Ef_Room_Sunshine_Minsect(1, Common_Get(time.now_sec)); - } - else if ((Common_Get(time.now_sec) >= 43200) && (Common_Get(time.now_sec) < 72000)){ - minsect->ef_sunshine_class.actor_class.scale.x = calc_scale_Ef_Room_Sunshine_Minsect(0, Common_Get(time.now_sec) - 43200); - } - else{ - minsect->ef_sunshine_class.actor_class.scale.x = 0.0f; + + if (Common_Get(time.now_sec) < 14400) { + minsect->ef_sunshine_class.actor_class.scale.x = + calc_scale_Ef_Room_Sunshine_Minsect(1, Common_Get(time.now_sec)); + } else if ((Common_Get(time.now_sec) >= 43200) && (Common_Get(time.now_sec) < 72000)) { + minsect->ef_sunshine_class.actor_class.scale.x = + calc_scale_Ef_Room_Sunshine_Minsect(0, Common_Get(time.now_sec) - 43200); + } else { + minsect->ef_sunshine_class.actor_class.scale.x = 0.0f; } - minsect->ef_sunshine_class.actor_class.world.position.y = minsect->ef_sunshine_class.actor_class.home.position.y; - minsect->ef_sunshine_class.actor_class.world.position.y += 0.01f * GETREG(TAKREG,64); + minsect->ef_sunshine_class.actor_class.world.position.y = minsect->ef_sunshine_class.actor_class.home.position.y; + minsect->ef_sunshine_class.actor_class.world.position.y += 0.01f * GETREG(TAKREG, 64); } -void Ef_Room_Sunshine_MinsectR_actor_move(ACTOR* actor, GAME* game){ +static void Ef_Room_Sunshine_MinsectR_actor_move(ACTOR* actor, GAME* game) { ROOMSUNSHINEMINSECT_ACTOR* minsect = (ROOMSUNSHINEMINSECT_ACTOR*)actor; - - if((Common_Get(time.now_sec) >= 14400) && (Common_Get(time.now_sec) < 43200)){ - minsect->ef_sunshine_class.actor_class.scale.x = -calc_scale_Ef_Room_Sunshine_Minsect(0, 43200 - Common_Get(time.now_sec)); + + if ((Common_Get(time.now_sec) >= 14400) && (Common_Get(time.now_sec) < 43200)) { + minsect->ef_sunshine_class.actor_class.scale.x = + -calc_scale_Ef_Room_Sunshine_Minsect(0, 43200 - Common_Get(time.now_sec)); + } else if (Common_Get(time.now_sec) >= 72000) { + minsect->ef_sunshine_class.actor_class.scale.x = + -calc_scale_Ef_Room_Sunshine_Minsect(1, 86400 - Common_Get(time.now_sec)); + } else { + minsect->ef_sunshine_class.actor_class.scale.x = 0.0f; } - else if (Common_Get(time.now_sec) >= 72000){ - minsect->ef_sunshine_class.actor_class.scale.x = -calc_scale_Ef_Room_Sunshine_Minsect(1, 86400 -Common_Get(time.now_sec)); - } - else{ - minsect->ef_sunshine_class.actor_class.scale.x = 0.0f; - } - minsect->ef_sunshine_class.actor_class.world.position.y = minsect->ef_sunshine_class.actor_class.home.position.y; - minsect->ef_sunshine_class.actor_class.world.position.y += 0.01f * GETREG(TAKREG,64); + minsect->ef_sunshine_class.actor_class.world.position.y = minsect->ef_sunshine_class.actor_class.home.position.y; + minsect->ef_sunshine_class.actor_class.world.position.y += 0.01f * GETREG(TAKREG, 64); } - -void setup_mode_Ef_Room_Sunshine_Minsect(ACTOR* actor, GAME_PLAY* play){ +static void setup_mode_Ef_Room_Sunshine_Minsect(ACTOR* actor, GAME_PLAY* play) { ROOMSUNSHINE_ACTOR* sunshine = (ROOMSUNSHINE_ACTOR*)actor; u8* color; int calc; @@ -150,29 +147,27 @@ void setup_mode_Ef_Room_Sunshine_Minsect(ACTOR* actor, GAME_PLAY* play){ OPEN_DISP(graph); - Matrix_translate(sunshine->actor_class.world.position.x, sunshine->actor_class.world.position.y, - sunshine->actor_class.world.position.z, 0); - Matrix_scale(sunshine->actor_class.scale.x, sunshine->actor_class.scale.y, sunshine->actor_class.scale.z,1); + Matrix_translate(sunshine->actor_class.world.position.x, sunshine->actor_class.world.position.y, + sunshine->actor_class.world.position.z, 0); + Matrix_scale(sunshine->actor_class.scale.x, sunshine->actor_class.scale.y, sunshine->actor_class.scale.z, 1); gDPPipeSync(NEXT_POLY_XLU_DISP); gSPMatrix(NEXT_POLY_XLU_DISP, _Matrix_to_Mtx_new(play->game.graph), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); - if((Common_Get(time.now_sec) >= 14400) && (Common_Get(time.now_sec) < 72000)){ - color =play->kankyo.base_light.sun_color_window; - } - else{ - color =play->kankyo.base_light.moon_color_window; + if ((Common_Get(time.now_sec) >= 14400) && (Common_Get(time.now_sec) < 72000)) { + color = play->kankyo.base_light.sun_color_window; + } else { + color = play->kankyo.base_light.moon_color_window; } calc = ((u8)calc_alpha_Ef_Room_SunshineMinsect() * mKK_windowlight_alpha_get()); - + gDPSetPrimColor(NEXT_POLY_XLU_DISP, 0, calc, color[0], color[1], color[2], 75); CLOSE_DISP(graph); - } -void setup_mode_Ef_Room_Sunshine_Minsect_decal(ACTOR* actor, GAME_PLAY* play){ +static void setup_mode_Ef_Room_Sunshine_Minsect_decal(ACTOR* actor, GAME_PLAY* play) { ROOMSUNSHINE_ACTOR* sunshine = (ROOMSUNSHINE_ACTOR*)actor; u8* color; int calc; @@ -181,52 +176,49 @@ void setup_mode_Ef_Room_Sunshine_Minsect_decal(ACTOR* actor, GAME_PLAY* play){ OPEN_DISP(graph); - Matrix_translate(sunshine->actor_class.world.position.x, sunshine->actor_class.world.position.y, - sunshine->actor_class.world.position.z, 0); - Matrix_scale(sunshine->actor_class.scale.x, sunshine->actor_class.scale.y, sunshine->actor_class.scale.z,1); + Matrix_translate(sunshine->actor_class.world.position.x, sunshine->actor_class.world.position.y, + sunshine->actor_class.world.position.z, 0); + Matrix_scale(sunshine->actor_class.scale.x, sunshine->actor_class.scale.y, sunshine->actor_class.scale.z, 1); gDPPipeSync(NEXT_POLY_OPA_DISP); gSPMatrix(NEXT_POLY_OPA_DISP, _Matrix_to_Mtx_new(play->game.graph), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); - if((Common_Get(time.now_sec) >= 14400) && (Common_Get(time.now_sec) < 72000)){ - color =play->kankyo.base_light.sun_color_window; - } - else{ - color =play->kankyo.base_light.moon_color_window; + if ((Common_Get(time.now_sec) >= 14400) && (Common_Get(time.now_sec) < 72000)) { + color = play->kankyo.base_light.sun_color_window; + } else { + color = play->kankyo.base_light.moon_color_window; } calc = ((u8)calc_alpha_Ef_Room_SunshineMinsect() * mKK_windowlight_alpha_get()); - + gDPSetPrimColor(NEXT_POLY_OPA_DISP, 0, calc, color[0], color[1], color[2], 75); CLOSE_DISP(graph); - } +static void BG_draw_Minsect(ACTOR* actor, GAME_PLAY* play) { + GRAPH* graph; -void BG_draw_Minsect(ACTOR* actor, GAME_PLAY* play){ - GRAPH* graph; - - if(!(draw_status & 4)){ + if (!(draw_status & 4)) { draw_status |= 4; } - if((draw_status & 1) && (draw_status & 2)){ - draw_status = 0; + if ((draw_status & 1) && (draw_status & 2)) { + draw_status = 0; } graph = play->game.graph; Matrix_scale(0.0625f, 0.0625f, 0.0625f, 0); Global_kankyo_set_room_prim(play); - OPEN_DISP(graph); + OPEN_DISP(graph); gSPMatrix(NEXT_POLY_OPA_DISP, _Matrix_to_Mtx_new(play->game.graph), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); gSPDisplayList(NEXT_POLY_OPA_DISP, rom_museum4_ue_model); - CLOSE_DISP(graph); + CLOSE_DISP(graph); } -void BG_draw_Minsect_niwa(ACTOR* actor, GAME_PLAY* play){ - GRAPH* graph; +static void BG_draw_Minsect_niwa(ACTOR* actor, GAME_PLAY* play) { + GRAPH* graph; graph = play->game.graph; Matrix_scale(0.0625f, 0.0625f, 0.0625f, 0); @@ -235,10 +227,10 @@ void BG_draw_Minsect_niwa(ACTOR* actor, GAME_PLAY* play){ gSPMatrix(NEXT_POLY_OPA_DISP, _Matrix_to_Mtx_new(play->game.graph), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); gSPDisplayList(NEXT_POLY_OPA_DISP, rom_museum4_model); - CLOSE_DISP(graph); + CLOSE_DISP(graph); } -void Ef_Room_Sunshine_MinsectL_actor_draw(ACTOR* actor, GAME* game){ +static void Ef_Room_Sunshine_MinsectL_actor_draw(ACTOR* actor, GAME* game) { GRAPH* graph; _texture_z_light_fog_prim(game->graph); @@ -247,75 +239,70 @@ void Ef_Room_Sunshine_MinsectL_actor_draw(ACTOR* actor, GAME* game){ draw_status |= 1; - if(mKK_windowlight_alpha_get() < 9.99999974738e-05f){ - if ((draw_status & 1) && (draw_status & 2) && !(draw_status & 4)){ - BG_draw_Minsect_niwa(actor,(GAME_PLAY*)game); - BG_draw_Minsect(actor,(GAME_PLAY*)game); + if (mKK_windowlight_alpha_get() < 9.99999974738e-05f) { + if ((draw_status & 1) && (draw_status & 2) && !(draw_status & 4)) { + BG_draw_Minsect_niwa(actor, (GAME_PLAY*)game); + BG_draw_Minsect(actor, (GAME_PLAY*)game); } + } else if (0.0f == actor->scale.x) { + if ((draw_status & 1) && (draw_status & 2) && !(draw_status & 4)) { + BG_draw_Minsect_niwa(actor, (GAME_PLAY*)game); + BG_draw_Minsect(actor, (GAME_PLAY*)game); + } + } else { + s16 reg; + graph = game->graph; + + BG_draw_Minsect_niwa(actor, (GAME_PLAY*)game); + setup_mode_Ef_Room_Sunshine_Minsect(actor, (GAME_PLAY*)game); + OPEN_DISP(graph); + + gSPDisplayList(NEXT_POLY_XLU_DISP, obj_museum4_shine_1T_model); + setup_mode_Ef_Room_Sunshine_Minsect_decal(actor, (GAME_PLAY*)game); + + if (REGADDR(TAKREG, 0) == 0) { + gSPDisplayList(NEXT_POLY_OPA_DISP, obj_museum4_shine_2T_model); + } + BG_draw_Minsect(actor, (GAME_PLAY*)game); + + CLOSE_DISP(graph); } - else if(0.0f == actor->scale.x){ - if ((draw_status & 1) && (draw_status & 2) && !(draw_status & 4)){ - BG_draw_Minsect_niwa(actor,(GAME_PLAY*)game); - BG_draw_Minsect(actor,(GAME_PLAY*)game); - } - } - else{ - s16 reg; - graph = game->graph; - - BG_draw_Minsect_niwa(actor,(GAME_PLAY*)game); - setup_mode_Ef_Room_Sunshine_Minsect(actor,(GAME_PLAY*)game); - OPEN_DISP(graph); - - gSPDisplayList(NEXT_POLY_XLU_DISP, obj_museum4_shine_1T_model); - setup_mode_Ef_Room_Sunshine_Minsect_decal(actor,(GAME_PLAY*)game); - - if(REGADDR(TAKREG, 0) == 0){ - gSPDisplayList(NEXT_POLY_OPA_DISP, obj_museum4_shine_2T_model); - } - BG_draw_Minsect(actor,(GAME_PLAY*)game); - - CLOSE_DISP(graph); - } } -void Ef_Room_Sunshine_MinsectR_actor_draw(ACTOR* actor, GAME* game){ +static void Ef_Room_Sunshine_MinsectR_actor_draw(ACTOR* actor, GAME* game) { GRAPH* graph; - _texture_z_light_fog_prim(game->graph); _texture_z_light_fog_prim_shadow(game->graph); _texture_z_light_fog_prim_xlu(game->graph); draw_status |= 2; - if(mKK_windowlight_alpha_get() < 9.99999974738e-05f){ - if ((draw_status & 1) && (draw_status & 2) && !(draw_status & 4)){ - BG_draw_Minsect_niwa(actor,(GAME_PLAY*)game); - BG_draw_Minsect(actor,(GAME_PLAY*)game); + if (mKK_windowlight_alpha_get() < 9.99999974738e-05f) { + if ((draw_status & 1) && (draw_status & 2) && !(draw_status & 4)) { + BG_draw_Minsect_niwa(actor, (GAME_PLAY*)game); + BG_draw_Minsect(actor, (GAME_PLAY*)game); } - } - else if(0.0f == actor->scale.x){ - if ((draw_status & 1) && (draw_status & 2) && !(draw_status & 4)){ - BG_draw_Minsect_niwa(actor,(GAME_PLAY*)game); - BG_draw_Minsect(actor,(GAME_PLAY*)game); + } else if (0.0f == actor->scale.x) { + if ((draw_status & 1) && (draw_status & 2) && !(draw_status & 4)) { + BG_draw_Minsect_niwa(actor, (GAME_PLAY*)game); + BG_draw_Minsect(actor, (GAME_PLAY*)game); } - } - else{ - graph = game->graph; + } else { + graph = game->graph; - BG_draw_Minsect_niwa(actor,(GAME_PLAY*)game); - setup_mode_Ef_Room_Sunshine_Minsect(actor,(GAME_PLAY*)game); - OPEN_DISP(graph); + BG_draw_Minsect_niwa(actor, (GAME_PLAY*)game); + setup_mode_Ef_Room_Sunshine_Minsect(actor, (GAME_PLAY*)game); + OPEN_DISP(graph); - gSPDisplayList(NEXT_POLY_XLU_DISP, obj_museum4_shine_1T_model); - setup_mode_Ef_Room_Sunshine_Minsect_decal(actor,(GAME_PLAY*)game); - - if(REGADDR(TAKREG, 0) == 0){ - gSPDisplayList(NEXT_POLY_OPA_DISP, obj_museum4_shine_2T_model); - } - BG_draw_Minsect(actor,(GAME_PLAY*)game); - - CLOSE_DISP(graph); + gSPDisplayList(NEXT_POLY_XLU_DISP, obj_museum4_shine_1T_model); + setup_mode_Ef_Room_Sunshine_Minsect_decal(actor, (GAME_PLAY*)game); + + if (REGADDR(TAKREG, 0) == 0) { + gSPDisplayList(NEXT_POLY_OPA_DISP, obj_museum4_shine_2T_model); } + BG_draw_Minsect(actor, (GAME_PLAY*)game); + + CLOSE_DISP(graph); + } } diff --git a/src/ef_room_sunshine_police.c b/src/ef_room_sunshine_police.c index d86a2201..76f9459b 100644 --- a/src/ef_room_sunshine_police.c +++ b/src/ef_room_sunshine_police.c @@ -6,12 +6,12 @@ #include "m_collision_bg.h" #include "sys_matrix.h" -void Ef_Room_Sunshine_Police_actor_ct(ACTOR* actor, GAME* play); -void Ef_Room_Sunshine_Police_actor_dt(ACTOR* actor, GAME* play); -void Ef_Room_Sunshine_PoliceL_actor_draw(ACTOR* actor, GAME* play); -void Ef_Room_Sunshine_PoliceL_actor_move(ACTOR* actor, GAME* play); -void Ef_Room_Sunshine_PoliceR_actor_draw(ACTOR* actor, GAME* play); -void Ef_Room_Sunshine_PoliceR_actor_move(ACTOR* actor, GAME* play); +static void Ef_Room_Sunshine_Police_actor_ct(ACTOR* actor, GAME* play); +static void Ef_Room_Sunshine_Police_actor_dt(ACTOR* actor, GAME* play); +static void Ef_Room_Sunshine_PoliceL_actor_draw(ACTOR* actor, GAME* play); +static void Ef_Room_Sunshine_PoliceL_actor_move(ACTOR* actor, GAME* play); +static void Ef_Room_Sunshine_PoliceR_actor_draw(ACTOR* actor, GAME* play); +static void Ef_Room_Sunshine_PoliceR_actor_move(ACTOR* actor, GAME* play); extern Gfx obj_koban_shine_modelT[]; @@ -29,119 +29,119 @@ ACTOR_PROFILE Room_Sunshine_Police_Profile = { NULL, }; -void Ef_Room_Sunshine_Police_actor_ct(ACTOR* actor, GAME* game){ +static void Ef_Room_Sunshine_Police_actor_ct(ACTOR* actor, GAME* game) { ROOMSUNSHINEPOLICE_ACTOR* police = (ROOMSUNSHINEPOLICE_ACTOR*)actor; xyz_t pos; - xyz_t pos2; + xyz_t pos2; xyz_t pos3; - + police->ef_sunshine_class.unk_174 = 0; - if(police->ef_sunshine_class.actor_class.actor_specific == 0){ + if (police->ef_sunshine_class.actor_class.actor_specific == 0) { police->ef_sunshine_class.actor_class.mv_proc = Ef_Room_Sunshine_PoliceL_actor_move; police->ef_sunshine_class.actor_class.dw_proc = Ef_Room_Sunshine_PoliceL_actor_draw; - } - else{ + } else { police->ef_sunshine_class.actor_class.world.position.x -= 1.0f; } - police->ef_sunshine_class.actor_class.world.position.y = mCoBG_GetBgY_OnlyCenter_FromWpos(police->ef_sunshine_class.actor_class.world.position, 0.0f); + police->ef_sunshine_class.actor_class.world.position.y = + mCoBG_GetBgY_OnlyCenter_FromWpos(police->ef_sunshine_class.actor_class.world.position, 0.0f); police->ef_sunshine_class.actor_class.scale.x = 0.01f; police->ef_sunshine_class.actor_class.scale.y = 0.01f; police->ef_sunshine_class.actor_class.scale.z = 0.01f; - switch(police->ef_sunshine_class.actor_class.actor_specific){ + switch (police->ef_sunshine_class.actor_class.actor_specific) { case 2: - + police->ef_sunshine_class.actor_class.mv_proc = Ef_Room_Sunshine_PoliceL_actor_move; police->ef_sunshine_class.actor_class.dw_proc = Ef_Room_Sunshine_PoliceL_actor_draw; police->ef_sunshine_class.actor_class.world.position.x += 5.0f; - police->ef_sunshine_class.actor_class.world.position.y = 1.0f + mCoBG_GetBgY_OnlyCenter_FromWpos(police->ef_sunshine_class.actor_class.world.position, 0.0f) - 40.0f; + police->ef_sunshine_class.actor_class.world.position.y = + 1.0f + mCoBG_GetBgY_OnlyCenter_FromWpos(police->ef_sunshine_class.actor_class.world.position, 0.0f) - + 40.0f; police->ef_sunshine_class.actor_class.world.position.x -= 6.0f; - break; + break; case 3: police->ef_sunshine_class.actor_class.world.position.x -= 5.0f; - police->ef_sunshine_class.actor_class.world.position.y = 1.0f + mCoBG_GetBgY_OnlyCenter_FromWpos(police->ef_sunshine_class.actor_class.world.position, 0.0f) - 40.0f; + police->ef_sunshine_class.actor_class.world.position.y = + 1.0f + mCoBG_GetBgY_OnlyCenter_FromWpos(police->ef_sunshine_class.actor_class.world.position, 0.0f) - + 40.0f; police->ef_sunshine_class.actor_class.world.position.x += 6.0f; - break; + break; } } -f32 calc_scale_Ef_Room_Sunshine_Police(int flag, int sec){ - - if(flag == 0){ +static f32 calc_scale_Ef_Room_Sunshine_Police(int flag, int sec) { + + if (flag == 0) { return 0.01f * (1.5f * sin_s((sec << 14) / 28800.0f)); - } - else{ + } else { return 0.01f * (1.5f * sin_s((sec << 14) / 14400.0f)); } } -int calc_alpha_Ef_Room_SunshinePolice(){ +static int calc_alpha_Ef_Room_SunshinePolice() { f32 ret; int sec; - - if(Common_Get(time.now_sec) < 14400){ - ret = 120.0f * ((14400 - Common_Get(time.now_sec)) / 14400.0f); - } - else if(Common_Get(time.now_sec) < 72000){ - sec = (Common_Get(time.now_sec) - 43200) >= 0 ? - (Common_Get(time.now_sec) - 43200U) : -(Common_Get(time.now_sec) - 43200U); + + if (Common_Get(time.now_sec) < 14400) { + ret = 120.0f * ((14400 - Common_Get(time.now_sec)) / 14400.0f); + } else if (Common_Get(time.now_sec) < 72000) { + sec = (Common_Get(time.now_sec) - 43200) >= 0 ? (Common_Get(time.now_sec) - 43200U) + : -(Common_Get(time.now_sec) - 43200U); ret = 255.0f * ((28800 - sec) / 28800.0f); - } - else{ - ret = 120.0f * ((14400 - (86400 - Common_Get(time.now_sec))) / 14400.0f); + } else { + ret = 120.0f * ((14400 - (86400 - Common_Get(time.now_sec))) / 14400.0f); } - if((Common_Get(weather) == 1) || (Common_Get(weather) == 2)){ + if ((Common_Get(weather) == 1) || (Common_Get(weather) == 2)) { ret *= 0.6f; } - + return (u8)ret; } -void Ef_Room_Sunshine_PoliceL_actor_move(ACTOR* actor, GAME* game){ +static void Ef_Room_Sunshine_PoliceL_actor_move(ACTOR* actor, GAME* game) { ROOMSUNSHINEPOLICE_ACTOR* police = (ROOMSUNSHINEPOLICE_ACTOR*)actor; - - if(Common_Get(time.now_sec) < 14400){ + + if (Common_Get(time.now_sec) < 14400) { police->ef_sunshine_class.actor_class.scale.x = calc_scale_Ef_Room_Sunshine_Police(1, Common_Get(time.now_sec)); - } - else if ((Common_Get(time.now_sec) >= 43200) && (Common_Get(time.now_sec) < 72000)){ - police->ef_sunshine_class.actor_class.scale.x = calc_scale_Ef_Room_Sunshine_Police(0, Common_Get(time.now_sec) - 43200); - } - else{ - police->ef_sunshine_class.actor_class.scale.x = 0.0f; + } else if ((Common_Get(time.now_sec) >= 43200) && (Common_Get(time.now_sec) < 72000)) { + police->ef_sunshine_class.actor_class.scale.x = + calc_scale_Ef_Room_Sunshine_Police(0, Common_Get(time.now_sec) - 43200); + } else { + police->ef_sunshine_class.actor_class.scale.x = 0.0f; } } -void Ef_Room_Sunshine_PoliceR_actor_move(ACTOR* actor, GAME* game){ +static void Ef_Room_Sunshine_PoliceR_actor_move(ACTOR* actor, GAME* game) { ROOMSUNSHINEPOLICE_ACTOR* police = (ROOMSUNSHINEPOLICE_ACTOR*)actor; - - if((Common_Get(time.now_sec) >= 14400) && (Common_Get(time.now_sec) < 43200)){ - police->ef_sunshine_class.actor_class.scale.x = -calc_scale_Ef_Room_Sunshine_Police(0, 43200 - Common_Get(time.now_sec)); - } - else if (Common_Get(time.now_sec) >= 72000){ - police->ef_sunshine_class.actor_class.scale.x = -calc_scale_Ef_Room_Sunshine_Police(1, 86400 -Common_Get(time.now_sec)); - } - else{ - police->ef_sunshine_class.actor_class.scale.x = 0.0f; + + if ((Common_Get(time.now_sec) >= 14400) && (Common_Get(time.now_sec) < 43200)) { + police->ef_sunshine_class.actor_class.scale.x = + -calc_scale_Ef_Room_Sunshine_Police(0, 43200 - Common_Get(time.now_sec)); + } else if (Common_Get(time.now_sec) >= 72000) { + police->ef_sunshine_class.actor_class.scale.x = + -calc_scale_Ef_Room_Sunshine_Police(1, 86400 - Common_Get(time.now_sec)); + } else { + police->ef_sunshine_class.actor_class.scale.x = 0.0f; } } -int cull_check_from_camera(ACTOR* actor, GAME_PLAY* play, int flag){ +static int cull_check_from_camera(ACTOR* actor, GAME_PLAY* play, int flag) { - if(((play->camera.lookat.eye.x >= actor->world.position.x) && (flag == 1)) || - (play->camera.lookat.eye.x <= actor->world.position.x) && (flag == 0)){ - return 1; + if (((play->camera.lookat.eye.x >= actor->world.position.x) && (flag == 1)) || + (play->camera.lookat.eye.x <= actor->world.position.x) && (flag == 0)) { + return 1; } return 0; } -void setup_mode_Ef_Room_Sunshine_Police(ACTOR* actor, GAME_PLAY* play){ +static void setup_mode_Ef_Room_Sunshine_Police(ACTOR* actor, GAME_PLAY* play) { ROOMSUNSHINE_ACTOR* sunshine = (ROOMSUNSHINE_ACTOR*)actor; u8* color; int calc; @@ -150,67 +150,62 @@ void setup_mode_Ef_Room_Sunshine_Police(ACTOR* actor, GAME_PLAY* play){ OPEN_DISP(graph); - Matrix_translate(sunshine->actor_class.world.position.x, sunshine->actor_class.world.position.y, - sunshine->actor_class.world.position.z, 0); - Matrix_scale(sunshine->actor_class.scale.x, sunshine->actor_class.scale.y, sunshine->actor_class.scale.z,1); + Matrix_translate(sunshine->actor_class.world.position.x, sunshine->actor_class.world.position.y, + sunshine->actor_class.world.position.z, 0); + Matrix_scale(sunshine->actor_class.scale.x, sunshine->actor_class.scale.y, sunshine->actor_class.scale.z, 1); gDPPipeSync(NEXT_POLY_XLU_DISP); gSPMatrix(NEXT_POLY_XLU_DISP, _Matrix_to_Mtx_new(play->game.graph), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); - if((Common_Get(time.now_sec) >= 14400) && (Common_Get(time.now_sec) < 72000)){ - color =play->kankyo.base_light.sun_color_window; - } - else{ - color =play->kankyo.base_light.moon_color_window; + if ((Common_Get(time.now_sec) >= 14400) && (Common_Get(time.now_sec) < 72000)) { + color = play->kankyo.base_light.sun_color_window; + } else { + color = play->kankyo.base_light.moon_color_window; } calc = ((u8)calc_alpha_Ef_Room_SunshinePolice() * mKK_windowlight_alpha_get()); - + gDPSetPrimColor(NEXT_POLY_XLU_DISP, 0, calc, color[0], color[1], color[2], 255); CLOSE_DISP(graph); - } -void Ef_Room_Sunshine_PoliceL_actor_draw(ACTOR* actor, GAME* game){ +static void Ef_Room_Sunshine_PoliceL_actor_draw(ACTOR* actor, GAME* game) { GRAPH* graph; GAME_PLAY* play = (GAME_PLAY*)game; - if((mKK_windowlight_alpha_get() < 9.99999974738e-05f) || (actor->scale.x == 0.0f)){ - return; + if ((mKK_windowlight_alpha_get() < 9.99999974738e-05f) || (actor->scale.x == 0.0f)) { + return; } - - if(cull_check_from_camera(actor,play,0) == 0){ + + if (cull_check_from_camera(actor, play, 0) == 0) { graph = play->game.graph; setup_mode_Ef_Room_Sunshine_Police(actor, play); - - OPEN_DISP(graph); - - gSPDisplayList(NEXT_POLY_XLU_DISP, obj_koban_shine_modelT); - - CLOSE_DISP(graph); - - } + OPEN_DISP(graph); + + gSPDisplayList(NEXT_POLY_XLU_DISP, obj_koban_shine_modelT); + + CLOSE_DISP(graph); + } } -void Ef_Room_Sunshine_PoliceR_actor_draw(ACTOR* actor, GAME* game){ +static void Ef_Room_Sunshine_PoliceR_actor_draw(ACTOR* actor, GAME* game) { GRAPH* graph; GAME_PLAY* play = (GAME_PLAY*)game; - if((mKK_windowlight_alpha_get() < 9.99999974738e-05f) || (actor->scale.x == 0.0f)){ - return; + if ((mKK_windowlight_alpha_get() < 9.99999974738e-05f) || (actor->scale.x == 0.0f)) { + return; } - - if(cull_check_from_camera(actor,play,1) == 0){ + + if (cull_check_from_camera(actor, play, 1) == 0) { graph = play->game.graph; setup_mode_Ef_Room_Sunshine_Police(actor, play); - + OPEN_DISP(graph); - + gSPDisplayList(NEXT_POLY_XLU_DISP, obj_koban_shine_modelT); - + CLOSE_DISP(graph); - } -} \ No newline at end of file +} diff --git a/src/ef_room_sunshine_posthouse.c b/src/ef_room_sunshine_posthouse.c index 3792ecf1..2cdb8cf4 100644 --- a/src/ef_room_sunshine_posthouse.c +++ b/src/ef_room_sunshine_posthouse.c @@ -5,15 +5,14 @@ #include "m_debug.h" #include "m_collision_bg.h" #include "sys_matrix.h" +#include "libultra/libultra.h" - -void Ef_Room_Sunshine_Posthouse_actor_ct(ACTOR* actor, GAME* play); -void Ef_Room_Sunshine_Posthouse_actor_dt(ACTOR* actor, GAME* play); -void Ef_Room_Sunshine_PosthouseL_actor_draw(ACTOR* actor, GAME* play); -void Ef_Room_Sunshine_PosthouseL_actor_move(ACTOR* actor, GAME* play); -void Ef_Room_Sunshine_PosthouseR_actor_draw(ACTOR* actor, GAME* play); -void Ef_Room_Sunshine_PosthouseR_actor_move(ACTOR* actor, GAME* play); - +static void Ef_Room_Sunshine_Posthouse_actor_ct(ACTOR* actor, GAME* play); +static void Ef_Room_Sunshine_Posthouse_actor_dt(ACTOR* actor, GAME* play); +static void Ef_Room_Sunshine_PosthouseL_actor_draw(ACTOR* actor, GAME* play); +static void Ef_Room_Sunshine_PosthouseL_actor_move(ACTOR* actor, GAME* play); +static void Ef_Room_Sunshine_PosthouseR_actor_draw(ACTOR* actor, GAME* play); +static void Ef_Room_Sunshine_PosthouseR_actor_move(ACTOR* actor, GAME* play); extern Gfx obj_yubinkyoku_shine_modelT[]; @@ -31,111 +30,110 @@ ACTOR_PROFILE Room_Sunshine_Posthouse_Profile = { NULL, }; -void Ef_Room_Sunshine_Posthouse_actor_ct(ACTOR* actor, GAME* game){ +static void Ef_Room_Sunshine_Posthouse_actor_ct(ACTOR* actor, GAME* game) { ROOMSUNSHINEPOSTHOUSE_ACTOR* posthouse = (ROOMSUNSHINEPOSTHOUSE_ACTOR*)actor; xyz_t pos; - xyz_t pos2; + xyz_t pos2; xyz_t pos3; - + posthouse->ef_sunshine_class.unk_174 = 0; - if(posthouse->ef_sunshine_class.actor_class.actor_specific == 0){ + if (posthouse->ef_sunshine_class.actor_class.actor_specific == 0) { posthouse->ef_sunshine_class.actor_class.mv_proc = Ef_Room_Sunshine_PosthouseL_actor_move; posthouse->ef_sunshine_class.actor_class.dw_proc = Ef_Room_Sunshine_PosthouseL_actor_draw; - } - else{ + } else { posthouse->ef_sunshine_class.actor_class.world.position.x -= 1.0f; } - - posthouse->ef_sunshine_class.actor_class.world.position.y = mCoBG_GetBgY_OnlyCenter_FromWpos(posthouse->ef_sunshine_class.actor_class.world.position, 0.0f); + + posthouse->ef_sunshine_class.actor_class.world.position.y = + mCoBG_GetBgY_OnlyCenter_FromWpos(posthouse->ef_sunshine_class.actor_class.world.position, 0.0f); posthouse->ef_sunshine_class.actor_class.scale.x = 0.05f; posthouse->ef_sunshine_class.actor_class.scale.y = 0.05f; posthouse->ef_sunshine_class.actor_class.scale.z = 0.05f; - switch(posthouse->ef_sunshine_class.actor_class.actor_specific){ + switch (posthouse->ef_sunshine_class.actor_class.actor_specific) { case 2: - + posthouse->ef_sunshine_class.actor_class.mv_proc = Ef_Room_Sunshine_PosthouseL_actor_move; posthouse->ef_sunshine_class.actor_class.dw_proc = Ef_Room_Sunshine_PosthouseL_actor_draw; posthouse->ef_sunshine_class.actor_class.world.position.x += 5.0f; - posthouse->ef_sunshine_class.actor_class.world.position.y = 1.0f + mCoBG_GetBgY_OnlyCenter_FromWpos(posthouse->ef_sunshine_class.actor_class.world.position, 0.0f); + posthouse->ef_sunshine_class.actor_class.world.position.y = + 1.0f + mCoBG_GetBgY_OnlyCenter_FromWpos(posthouse->ef_sunshine_class.actor_class.world.position, 0.0f); posthouse->ef_sunshine_class.actor_class.world.position.x -= 6.0f; - break; + break; case 3: posthouse->ef_sunshine_class.actor_class.world.position.x -= 5.0f; - posthouse->ef_sunshine_class.actor_class.world.position.y = 1.0f + mCoBG_GetBgY_OnlyCenter_FromWpos(posthouse->ef_sunshine_class.actor_class.world.position, 0.0f); + posthouse->ef_sunshine_class.actor_class.world.position.y = + 1.0f + mCoBG_GetBgY_OnlyCenter_FromWpos(posthouse->ef_sunshine_class.actor_class.world.position, 0.0f); posthouse->ef_sunshine_class.actor_class.world.position.x += 6.0f; - break; + break; } } -f32 calc_scale_Ef_Room_Sunshine_Posthouse(int flag, int sec){ - - if(flag == 0){ +static f32 calc_scale_Ef_Room_Sunshine_Posthouse(int flag, int sec) { + + if (flag == 0) { return 0.05f * (1.5f * sin_s((sec << 14) / 28800.0f)); - } - else{ + } else { return 0.05f * (1.5f * sin_s((sec << 14) / 14400.0f)); } } -int calc_alpha_Ef_Room_SunshinePosthouse(){ +static int calc_alpha_Ef_Room_SunshinePosthouse() { f32 ret; int sec; - - if(Common_Get(time.now_sec) < 14400){ - ret = 120.0f * ((14400 - Common_Get(time.now_sec)) / 14400.0f); - } - else if(Common_Get(time.now_sec) < 72000){ - //any other number matches codegen, but 43200 breaks - sec = (Common_Get(time.now_sec) - 43200) >= 0 ? - (Common_Get(time.now_sec) - 43200U) : -(Common_Get(time.now_sec) - 43200U); + + if (Common_Get(time.now_sec) < 14400) { + ret = 120.0f * ((14400 - Common_Get(time.now_sec)) / 14400.0f); + } else if (Common_Get(time.now_sec) < 72000) { + // any other number matches codegen, but 43200 breaks + sec = (Common_Get(time.now_sec) - 43200) >= 0 ? (Common_Get(time.now_sec) - 43200U) + : -(Common_Get(time.now_sec) - 43200U); ret = 255.0f * ((28800 - sec) / 28800.0f); - } - else{ - ret = 120.0f * ((14400 - (86400 - Common_Get(time.now_sec))) / 14400.0f); + } else { + ret = 120.0f * ((14400 - (86400 - Common_Get(time.now_sec))) / 14400.0f); } - if((Common_Get(weather) == 1) || (Common_Get(weather) == 2)){ + if ((Common_Get(weather) == 1) || (Common_Get(weather) == 2)) { ret *= 0.6f; } - + return (u8)ret; } -void Ef_Room_Sunshine_PosthouseL_actor_move(ACTOR* actor, GAME* game){ +static void Ef_Room_Sunshine_PosthouseL_actor_move(ACTOR* actor, GAME* game) { ROOMSUNSHINEPOSTHOUSE_ACTOR* posthouse = (ROOMSUNSHINEPOSTHOUSE_ACTOR*)actor; - - if(Common_Get(time.now_sec) < 14400){ - posthouse->ef_sunshine_class.actor_class.scale.x = calc_scale_Ef_Room_Sunshine_Posthouse(1, Common_Get(time.now_sec)); - } - else if ((Common_Get(time.now_sec) >= 43200) && (Common_Get(time.now_sec) < 72000)){ - posthouse->ef_sunshine_class.actor_class.scale.x = calc_scale_Ef_Room_Sunshine_Posthouse(0, Common_Get(time.now_sec) - 43200); - } - else{ - posthouse->ef_sunshine_class.actor_class.scale.x = 0.0f; + + if (Common_Get(time.now_sec) < 14400) { + posthouse->ef_sunshine_class.actor_class.scale.x = + calc_scale_Ef_Room_Sunshine_Posthouse(1, Common_Get(time.now_sec)); + } else if ((Common_Get(time.now_sec) >= 43200) && (Common_Get(time.now_sec) < 72000)) { + posthouse->ef_sunshine_class.actor_class.scale.x = + calc_scale_Ef_Room_Sunshine_Posthouse(0, Common_Get(time.now_sec) - 43200); + } else { + posthouse->ef_sunshine_class.actor_class.scale.x = 0.0f; } } -void Ef_Room_Sunshine_PosthouseR_actor_move(ACTOR* actor, GAME* game){ +static void Ef_Room_Sunshine_PosthouseR_actor_move(ACTOR* actor, GAME* game) { ROOMSUNSHINEPOSTHOUSE_ACTOR* posthouse = (ROOMSUNSHINEPOSTHOUSE_ACTOR*)actor; - - if((Common_Get(time.now_sec) >= 14400) && (Common_Get(time.now_sec) < 43200)){ - posthouse->ef_sunshine_class.actor_class.scale.x = -calc_scale_Ef_Room_Sunshine_Posthouse(0, 43200 - Common_Get(time.now_sec)); - } - else if (Common_Get(time.now_sec) >= 72000){ - posthouse->ef_sunshine_class.actor_class.scale.x = -calc_scale_Ef_Room_Sunshine_Posthouse(1, 86400 -Common_Get(time.now_sec)); - } - else{ - posthouse->ef_sunshine_class.actor_class.scale.x = 0.0f; + + if ((Common_Get(time.now_sec) >= 14400) && (Common_Get(time.now_sec) < 43200)) { + posthouse->ef_sunshine_class.actor_class.scale.x = + -calc_scale_Ef_Room_Sunshine_Posthouse(0, 43200 - Common_Get(time.now_sec)); + } else if (Common_Get(time.now_sec) >= 72000) { + posthouse->ef_sunshine_class.actor_class.scale.x = + -calc_scale_Ef_Room_Sunshine_Posthouse(1, 86400 - Common_Get(time.now_sec)); + } else { + posthouse->ef_sunshine_class.actor_class.scale.x = 0.0f; } } -void setup_mode_Ef_Room_Sunshine_Posthouse(ACTOR* actor, GAME_PLAY* play){ +static void setup_mode_Ef_Room_Sunshine_Posthouse(ACTOR* actor, GAME_PLAY* play) { ROOMSUNSHINE_ACTOR* sunshine = (ROOMSUNSHINE_ACTOR*)actor; u8* color; int calc; @@ -144,61 +142,57 @@ void setup_mode_Ef_Room_Sunshine_Posthouse(ACTOR* actor, GAME_PLAY* play){ OPEN_DISP(graph); - Matrix_translate(sunshine->actor_class.world.position.x, sunshine->actor_class.world.position.y, - sunshine->actor_class.world.position.z, 0); - Matrix_scale(sunshine->actor_class.scale.x, sunshine->actor_class.scale.y, sunshine->actor_class.scale.z,1); + Matrix_translate(sunshine->actor_class.world.position.x, sunshine->actor_class.world.position.y, + sunshine->actor_class.world.position.z, 0); + Matrix_scale(sunshine->actor_class.scale.x, sunshine->actor_class.scale.y, sunshine->actor_class.scale.z, 1); gDPPipeSync(NEXT_POLY_XLU_DISP); gSPMatrix(NEXT_POLY_XLU_DISP, _Matrix_to_Mtx_new(play->game.graph), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); - if((Common_Get(time.now_sec) >= 14400) && (Common_Get(time.now_sec) < 72000)){ - color =play->kankyo.base_light.sun_color_window; - } - else{ - color =play->kankyo.base_light.moon_color_window; + if ((Common_Get(time.now_sec) >= 14400) && (Common_Get(time.now_sec) < 72000)) { + color = play->kankyo.base_light.sun_color_window; + } else { + color = play->kankyo.base_light.moon_color_window; } calc = ((u8)calc_alpha_Ef_Room_SunshinePosthouse() * mKK_windowlight_alpha_get()); - + gDPSetPrimColor(NEXT_POLY_XLU_DISP, 0, calc, color[0], color[1], color[2], 255); CLOSE_DISP(graph); - } -void Ef_Room_Sunshine_PosthouseL_actor_draw(ACTOR* actor, GAME* game){ +static void Ef_Room_Sunshine_PosthouseL_actor_draw(ACTOR* actor, GAME* game) { GRAPH* graph; GAME_PLAY* play = (GAME_PLAY*)game; - if((mKK_windowlight_alpha_get() < 9.99999974738e-05f) || (actor->scale.x == 0.0f)){ - return; + if ((mKK_windowlight_alpha_get() < 9.99999974738e-05f) || (actor->scale.x == 0.0f)) { + return; } - graph = play->game.graph; - setup_mode_Ef_Room_Sunshine_Posthouse(actor, play); - - OPEN_DISP(graph); - - gSPDisplayList(NEXT_POLY_XLU_DISP, obj_yubinkyoku_shine_modelT); - - CLOSE_DISP(graph); + graph = play->game.graph; + setup_mode_Ef_Room_Sunshine_Posthouse(actor, play); + OPEN_DISP(graph); + + gSPDisplayList(NEXT_POLY_XLU_DISP, obj_yubinkyoku_shine_modelT); + + CLOSE_DISP(graph); } -void Ef_Room_Sunshine_PosthouseR_actor_draw(ACTOR* actor, GAME* game){ +static void Ef_Room_Sunshine_PosthouseR_actor_draw(ACTOR* actor, GAME* game) { GRAPH* graph; GAME_PLAY* play = (GAME_PLAY*)game; - if((mKK_windowlight_alpha_get() < 9.99999974738e-05f) || (actor->scale.x == 0.0f)){ - return; + if ((mKK_windowlight_alpha_get() < 9.99999974738e-05f) || (actor->scale.x == 0.0f)) { + return; } - - graph = play->game.graph; - setup_mode_Ef_Room_Sunshine_Posthouse(actor, play); - - OPEN_DISP(graph); - - gSPDisplayList(NEXT_POLY_XLU_DISP, obj_yubinkyoku_shine_modelT); - - CLOSE_DISP(graph); - -} \ No newline at end of file + + graph = play->game.graph; + setup_mode_Ef_Room_Sunshine_Posthouse(actor, play); + + OPEN_DISP(graph); + + gSPDisplayList(NEXT_POLY_XLU_DISP, obj_yubinkyoku_shine_modelT); + + CLOSE_DISP(graph); +} diff --git a/src/ftr/ac_nog_fan01.c b/src/ftr/ac_nog_fan01.c index 8623120d..f5ec2d55 100644 --- a/src/ftr/ac_nog_fan01.c +++ b/src/ftr/ac_nog_fan01.c @@ -11,25 +11,26 @@ extern u8 int_nog_fan_fan2_TA_tex_txt[]; extern u8 int_nog_fan_fan3_TA_tex_txt[]; static u8* aNogFan_nog_fan01_anim[] = { - int_nog_fan_fan1_TA_tex_txt,int_nog_fan_fan2_TA_tex_txt,int_nog_fan_fan3_TA_tex_txt, + int_nog_fan_fan1_TA_tex_txt, + int_nog_fan_fan2_TA_tex_txt, + int_nog_fan_fan3_TA_tex_txt, }; -void aNogFan_ControlSwitchSE(FTR_ACTOR* ftr_actor){ - if (ftr_actor->switch_bit != FALSE){ - sAdo_OngenTrgStart(0x16,&ftr_actor->position); - } - else{ - sAdo_OngenTrgStart(0x17,&ftr_actor->position); +static void aNogFan_ControlSwitchSE(FTR_ACTOR* ftr_actor) { + if (ftr_actor->switch_bit != FALSE) { + sAdo_OngenTrgStart(0x16, &ftr_actor->position); + } else { + sAdo_OngenTrgStart(0x17, &ftr_actor->position); } } -void aNogFan_ChangeSwitch(FTR_ACTOR* ftr_actor){ - if (ftr_actor->switch_changed_flag != FALSE){ +static void aNogFan_ChangeSwitch(FTR_ACTOR* ftr_actor) { + if (ftr_actor->switch_changed_flag != FALSE) { aNogFan_ControlSwitchSE(ftr_actor); } -} +} -static void aNogFan_ct(FTR_ACTOR* ftr_actor, u8* data){ +static void aNogFan_ct(FTR_ACTOR* ftr_actor, u8* data) { cKF_SkeletonInfo_R_c* keyf; keyf = &ftr_actor->keyframe; @@ -40,41 +41,37 @@ static void aNogFan_ct(FTR_ACTOR* ftr_actor, u8* data){ ftr_actor->dynamic_work_s[0] = 0; - if(ftr_actor->switch_bit != FALSE){ + if (ftr_actor->switch_bit != FALSE) { ftr_actor->dynamic_work_f[0] = 0.5f; - } - else{ + } else { ftr_actor->dynamic_work_f[0] = 0.0f; } +} -} - -static void aNogFan_mv(FTR_ACTOR* ftr_actor, ACTOR* my_room_actor, GAME* game, u8* data){ +static void aNogFan_mv(FTR_ACTOR* ftr_actor, ACTOR* my_room_actor, GAME* game, u8* data) { static int fan_kurukuru_data[] = { - 1,1,1,2,2,2,2,2,3,0xFFFFFFFF, + 1, 1, 1, 2, 2, 2, 2, 2, 3, 0xFFFFFFFF, }; int num; int idx; - + cKF_SkeletonInfo_R_c* keyf; keyf = &ftr_actor->keyframe; aNogFan_ChangeSwitch(ftr_actor); - if(ftr_actor->switch_bit != FALSE){ + if (ftr_actor->switch_bit != FALSE) { f32 step = sqrtf(0.94999998807907); - add_calc(&ftr_actor->dynamic_work_f[0],0.5f, 1.0f - step, 0.25f,0.0005f); + add_calc(&ftr_actor->dynamic_work_f[0], 0.5f, 1.0f - step, 0.25f, 0.0005f); - if(aFTR_CAN_PLAY_SE(ftr_actor)){ - sAdo_OngenPos((u32) ftr_actor, 1, &ftr_actor->position); + if (aFTR_CAN_PLAY_SE(ftr_actor)) { + sAdo_OngenPos((u32)ftr_actor, 1, &ftr_actor->position); } - } - else{ + } else { f32 step = sqrtf(0.94999998807907); - add_calc(&ftr_actor->dynamic_work_f[0],0.0f, 1.0f - step, 0.25f,0.0005f); - + add_calc(&ftr_actor->dynamic_work_f[0], 0.0f, 1.0f - step, 0.25f, 0.0005f); } keyf->frame_control.speed = ftr_actor->dynamic_work_f[0]; @@ -83,75 +80,51 @@ static void aNogFan_mv(FTR_ACTOR* ftr_actor, ACTOR* my_room_actor, GAME* game, u idx = 9.0f - (2.0f * (ftr_actor->dynamic_work_f[0] * 9.0f)); ftr_actor->dynamic_work_s[0]++; - num = fan_kurukuru_data[idx]; - if((num != -1) && (ftr_actor->dynamic_work_s[0] >= num )){ + if ((num != -1) && (ftr_actor->dynamic_work_s[0] >= num)) { ftr_actor->dynamic_work_s[0] = 0; ftr_actor->tex_animation.frame++; - if(ftr_actor->tex_animation.frame >= 6 || ftr_actor->tex_animation.frame < 0){ + if (ftr_actor->tex_animation.frame >= 6 || ftr_actor->tex_animation.frame < 0) { ftr_actor->tex_animation.frame = 0; } } - } static void aNogFan_dw(FTR_ACTOR* ftr_actor, ACTOR* my_room_actor, GAME* game, u8* data) { int idx; cKF_SkeletonInfo_R_c* keyf; Mtx* mtx; - + keyf = &ftr_actor->keyframe; mtx = ftr_actor->skeleton_mtx[game->frame_counter & 1]; - if(ftr_actor->ctr_type == aFTR_CTR_TYPE_GAME_PLAY){ + if (ftr_actor->ctr_type == aFTR_CTR_TYPE_GAME_PLAY) { idx = ftr_actor->tex_animation.frame >> 1; - } - else{ + } else { int fctr = ABS((int)game->frame_counter % 6); - idx = fctr >> 1; + idx = fctr >> 1; } OPEN_DISP(game->graph); - gSPMatrix(NEXT_POLY_OPA_DISP,_Matrix_to_Mtx_new(game->graph), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); - gSPSegment(NEXT_POLY_OPA_DISP, G_MWO_SEGMENT_8,aNogFan_nog_fan01_anim[idx]); + gSPMatrix(NEXT_POLY_OPA_DISP, _Matrix_to_Mtx_new(game->graph), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPSegment(NEXT_POLY_OPA_DISP, G_MWO_SEGMENT_8, aNogFan_nog_fan01_anim[idx]); cKF_Si3_draw_R_SV(game, keyf, mtx, NULL, NULL, NULL); - CLOSE_DISP(game->graph); } -static void aNogFan_dt(FTR_ACTOR* ftr_actor, u8* data){ - +static void aNogFan_dt(FTR_ACTOR* ftr_actor, u8* data) { } static aFTR_vtable_c aNogFan_func = { - &aNogFan_ct, - &aNogFan_mv, - &aNogFan_dw, - &aNogFan_dt, - NULL, + &aNogFan_ct, &aNogFan_mv, &aNogFan_dw, &aNogFan_dt, NULL, }; aFTR_PROFILE iam_nog_fan01 = { - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - 40.0f, - 0.01f, - aFTR_SHAPE_TYPEA, - mCoBG_FTR_TYPEA, - 0, - 0, - 0, - 0, - &aNogFan_func, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 40.0f, 0.01f, aFTR_SHAPE_TYPEA, mCoBG_FTR_TYPEA, + 0, 0, 0, 0, &aNogFan_func, }; diff --git a/src/game.c b/src/game.c index ca83f0fd..4894770b 100644 --- a/src/game.c +++ b/src/game.c @@ -9,6 +9,13 @@ #include "gamealloc.h" #include "THA_GA.h" #include "jsyswrap.h" +#include "m_debug_mode.h" +#include "padmgr.h" +#include "m_bgm.h" +#include "libu64/debug.h" +#include "libc64/malloc.h" +#include "GBA/gba.h" +#include "m_vibctl.h" GAME* gamePT = NULL; @@ -24,227 +31,222 @@ f32 game_GameFrame__1F; GAME* game_class_p; static void game_move_first(GAME* this) { - if (zurumode_flag) { - Debug_mode_input(&this->pads[1]); - } + if (zurumode_flag) { + Debug_mode_input(&this->pads[1]); + } - JC_JUTProcBar_setVisible(JC_JUTProcBar_getManager(), GETREG(SREG, 0) != 0); - JC_JUTProcBar_setVisibleHeapBar(JC_JUTProcBar_getManager(), GETREG(SREG, 0) != 0); + JC_JUTProcBar_setVisible(JC_JUTProcBar_getManager(), GETREG(SREG, 0) != 0); + JC_JUTProcBar_setVisibleHeapBar(JC_JUTProcBar_getManager(), GETREG(SREG, 0) != 0); } extern void game_debug_draw_last(GAME* this, GRAPH* graph) { - int i; - Gfx* gfx; - Gfx* close; + int i; + Gfx* gfx; + Gfx* close; - if (zurumode_flag) { - OPEN_DISP(graph); + if (zurumode_flag) { + OPEN_DISP(graph); - gfx = NOW_POLY_OPA_DISP; - close = gfxopen(gfx); - gSPDisplayList(NOW_OVERLAY_DISP++, close); + gfx = NOW_POLY_OPA_DISP; + close = gfxopen(gfx); + gSPDisplayList(NOW_OVERLAY_DISP++, close); - for (i = 0; i < MAXCONTROLLERS; i++) { - pad_t* pad = &this->pads[i]; - if (pad->now.errno == 0) { - last_now_button[i] = pad->now.button; - last_on_trigger[i] = pad->on.button; - last_button[i] = last_now_button[i] | last_on_trigger[i]; - } - else { - last_now_button[i] = 0; - last_on_trigger[i] = 0; - last_button[i] = i == 0 ? 0xffff : 0; - } + for (i = 0; i < MAXCONTROLLERS; i++) { + pad_t* pad = &this->pads[i]; + if (pad->now.errno == 0) { + last_now_button[i] = pad->now.button; + last_on_trigger[i] = pad->on.button; + last_button[i] = last_now_button[i] | last_on_trigger[i]; + } else { + last_now_button[i] = 0; + last_on_trigger[i] = 0; + last_button[i] = i == 0 ? 0xffff : 0; + } - SETREG(HREG, 40 + i, last_button[i]); + SETREG(HREG, 40 + i, last_button[i]); + } + + gSPEndDisplayList(close++); + gfxclose(gfx, close); + SET_POLY_OPA_DISP(close); + + CLOSE_DISP(graph); } - gSPEndDisplayList(close++); - gfxclose(gfx, close); - SET_POLY_OPA_DISP(close); - - CLOSE_DISP(graph); - } - - if (zurumode_flag) { - Debug_mode_output(graph); - } + if (zurumode_flag) { + Debug_mode_output(graph); + } } static void game_draw_first(GRAPH* graph) { - OPEN_DISP(graph); + OPEN_DISP(graph); - gSPSegment(NOW_BG_OPA_DISP++, G_MWO_NUMLIGHT, 0x80000000); + gSPSegment(NOW_BG_OPA_DISP++, G_MWO_NUMLIGHT, 0x80000000); - CLOSE_DISP(graph); + CLOSE_DISP(graph); } extern void game_draw_last(GRAPH* graph) { - Gfx* close; - Gfx* poly_gfx; + Gfx* close; + Gfx* poly_gfx; - OPEN_DISP(graph); + OPEN_DISP(graph); - poly_gfx = NOW_POLY_OPA_DISP; - close = gfxopen(poly_gfx); + poly_gfx = NOW_POLY_OPA_DISP; + close = gfxopen(poly_gfx); - gSPDisplayList(NOW_OVERLAY_DISP++, close); - gSPEndDisplayList(close++); + gSPDisplayList(NOW_OVERLAY_DISP++, close); + gSPEndDisplayList(close++); - gfxclose(poly_gfx, close); - SET_POLY_OPA_DISP(close); + gfxclose(poly_gfx, close); + SET_POLY_OPA_DISP(close); - CLOSE_DISP(graph); + CLOSE_DISP(graph); } extern void game_get_controller(GAME* this) { - if (this->pad_initialized == TRUE) { - padmgr_RequestPadData(this->pads, 1); - } - else { - padmgr_ClearPadData(this->pads); - } + if (this->pad_initialized == TRUE) { + padmgr_RequestPadData(this->pads, 1); + } else { + padmgr_ClearPadData(this->pads); + } } extern void SetGameFrame(int frame) { - if (game_GameFrame != frame) { - game_GameFrame = frame; - game_GameFrameF = (int)(u8)frame; - game_GameFrame_2F = game_GameFrameF * 0.5f; - game_GameFrame__1F = 1.0f / game_GameFrameF; + if (game_GameFrame != frame) { + game_GameFrame = frame; + game_GameFrameF = (int)(u8)frame; + game_GameFrame_2F = game_GameFrameF * 0.5f; + game_GameFrame__1F = 1.0f / game_GameFrameF; - SETREG(SREG, 30, (u16)frame); + SETREG(SREG, 30, (u16)frame); - if (GETREG(SREG, 29) > 0) { - frame = GETREG(SREG, 29); + if (GETREG(SREG, 29) > 0) { + frame = GETREG(SREG, 29); + } + + JC_JFWDisplay_setFrameRate(JC_JFWDisplay_getManager(), frame); } - - JC_JFWDisplay_setFrameRate(JC_JFWDisplay_getManager(), frame); - } } extern void game_main(GAME* this) { - GRAPH* graph = this->graph; + GRAPH* graph = this->graph; - if (GETREG(SREG, 30) != game_GameFrame || GETREG(SREG, 29)) { - SetGameFrame(GETREG(SREG, 30)); - } + if (GETREG(SREG, 30) != game_GameFrame || GETREG(SREG, 29)) { + SetGameFrame(GETREG(SREG, 30)); + } - game_draw_first(graph); - GRAPH_SET_DOING_POINT(graph, GAME_TIME); - mTM_time(); - GRAPH_SET_DOING_POINT(graph, GAME_TIME_FINISHED); - GRAPH_SET_DOING_POINT(graph, GAME_EXEC); - this->exec(this); - GRAPH_SET_DOING_POINT(graph, GAME_EXEC_FINISHED); - GRAPH_SET_DOING_POINT(graph, GAME_BGM); - mBGM_main(this); - GRAPH_SET_DOING_POINT(graph, GAME_BGM_FINISHED); - game_move_first(this); - this->frame_counter++; + game_draw_first(graph); + GRAPH_SET_DOING_POINT(graph, GAME_TIME); + mTM_time(); + GRAPH_SET_DOING_POINT(graph, GAME_TIME_FINISHED); + GRAPH_SET_DOING_POINT(graph, GAME_EXEC); + this->exec(this); + GRAPH_SET_DOING_POINT(graph, GAME_EXEC_FINISHED); + GRAPH_SET_DOING_POINT(graph, GAME_BGM); + mBGM_main(this); + GRAPH_SET_DOING_POINT(graph, GAME_BGM_FINISHED); + game_move_first(this); + this->frame_counter++; } static void game_init_hyral(GAME* this, size_t size) { - u8* hyral = (u8*)gamealloc_malloc(&this->gamealloc, size); - if (hyral != NULL) { - THA_ct(&this->tha, (char*)hyral, size); - } - else { - THA_ct(&this->tha, NULL, 0); - _dbg_hungup(__FILE__, 559); - } + u8* hyral = (u8*)gamealloc_malloc(&this->gamealloc, size); + if (hyral != NULL) { + THA_ct(&this->tha, (char*)hyral, size); + } else { + THA_ct(&this->tha, NULL, 0); + _dbg_hungup(__FILE__, 559); + } } extern void game_resize_hyral(GAME* this, int size) { - size_t max_size, free_size, alloc_size; - u8* old_hyral; - u8* hyral; + size_t max_size, free_size, alloc_size; + u8* old_hyral; + u8* hyral; - old_hyral = (u8*)this->tha.buf_p; - THA_dt(&this->tha); - gamealloc_free(&this->gamealloc, old_hyral); - GetFreeArena(&max_size, &free_size, &alloc_size); - max_size -= 0x50; + old_hyral = (u8*)this->tha.buf_p; + THA_dt(&this->tha); + gamealloc_free(&this->gamealloc, old_hyral); + GetFreeArena(&max_size, &free_size, &alloc_size); + max_size -= 0x50; - if (size <= 0) { - size = max_size + size; - if (size < 0) { - size = 0; + if (size <= 0) { + size = max_size + size; + if (size < 0) { + size = 0; + } + } else { + if (size > max_size) { + size = max_size; + } } - } - else { - if (size > max_size) { - size = max_size; - } - } - hyral = (u8*)gamealloc_malloc(&this->gamealloc, (u32)size); - if (hyral != NULL) { - THA_ct(&this->tha, (char*)hyral, (u32)size); - } - else { - THA_ct(&this->tha, NULL, 0); - _dbg_hungup(__FILE__, 633); - } + hyral = (u8*)gamealloc_malloc(&this->gamealloc, (u32)size); + if (hyral != NULL) { + THA_ct(&this->tha, (char*)hyral, (u32)size); + } else { + THA_ct(&this->tha, NULL, 0); + _dbg_hungup(__FILE__, 633); + } } extern void game_ct(GAME* this, void (*init)(GAME*), GRAPH* graph) { - gamePT = this; - graph->need_viupdate = TRUE; - mCon_ct(); - this->graph = graph; - this->frame_counter = 0; - this->exec = NULL; - this->cleanup = NULL; - this->doing = TRUE; - this->pad_initialized = TRUE; - GAME_NEXT_GAME_NULL(this); - gamealloc_init(&this->gamealloc); - game_init_hyral(this, GAME_HYRAL_SIZE); - SetGameFrame(GAME_FRAME); - __gfxprint_default_flags |= GFXPRINT_FLAG_HIGHRES; - init(this); - mBGM_init(); - GBAInit(); - mVibctl_init(); + gamePT = this; + graph->need_viupdate = TRUE; + mCon_ct(); + this->graph = graph; + this->frame_counter = 0; + this->exec = NULL; + this->cleanup = NULL; + this->doing = TRUE; + this->pad_initialized = TRUE; + GAME_NEXT_GAME_NULL(this); + gamealloc_init(&this->gamealloc); + game_init_hyral(this, GAME_HYRAL_SIZE); + SetGameFrame(GAME_FRAME); + __gfxprint_default_flags |= GFXPRINT_FLAG_HIGHRES; + init(this); + mBGM_init(); + GBAInit(); + mVibctl_init(); } extern void game_dt(GAME* this) { - mCon_dt(); - mBGM_cleanup(); - if (this->cleanup != NULL) { - this->cleanup(this); - } - - mVibctl_cleanup(); - THA_dt(&this->tha); - gamealloc_cleanup(&this->gamealloc); - gamePT = NULL; + mCon_dt(); + mBGM_cleanup(); + if (this->cleanup != NULL) { + this->cleanup(this); + } + + mVibctl_cleanup(); + THA_dt(&this->tha); + gamealloc_cleanup(&this->gamealloc); + gamePT = NULL; } extern void (*game_get_next_game_init(GAME* this))(GAME*) { - return this->next_game_init; + return this->next_game_init; } /* @fabricated */ MATCH_FORCESTRIP extern size_t game_get_next_game_class_size(GAME* this) { - return this->next_game_class_size; + return this->next_game_class_size; } extern int game_is_doing(GAME* this) { - return this->doing; + return this->doing; } extern int game_getFreeBytes(GAME* this) { - return THA_getFreeBytes16(&this->tha); + return THA_getFreeBytes16(&this->tha); } extern void game_goto_next_game_play(GAME* this) { - GAME_GOTO_NEXT(this, play, PLAY); + GAME_GOTO_NEXT(this, play, PLAY); } /* @fabricated */ MATCH_FORCESTRIP extern void game_goto_next_game_famicom_emu(GAME* this) { - GAME_GOTO_NEXT(this, famicom_emu, FAMICOM_EMU); + GAME_GOTO_NEXT(this, famicom_emu, FAMICOM_EMU); } diff --git a/src/m_actor.c b/src/m_actor.c index 18b0bfc1..5aec1060 100644 --- a/src/m_actor.c +++ b/src/m_actor.c @@ -24,1011 +24,955 @@ void _savefpr_29(); void _restfpr_29(); -//#include "orderstrings/8064d600_8064d604.inc" +// #include "orderstrings/8064d600_8064d604.inc" static char lbl_8064d600[] = ""; #endif #ifdef MUST_MATCH /* @unused | necessary for proper float ordering*/ -extern void __declspec(section "forcestrip") projection_pos_set(GAME_PLAY* play, xyz_t* pos, xyz_t* proj_pos, f32* proj_w) { - Skin_Matrix_PrjMulVector(&play->projection_matrix, pos, proj_pos, proj_w); - *proj_w = *proj_w < 1.0f ? 1.0f : 1.0f / *proj_w; +extern void __declspec(section "forcestrip") projection_pos_set(GAME_PLAY* play, xyz_t* pos, xyz_t* proj_pos, + f32* proj_w) { + Skin_Matrix_PrjMulVector(&play->projection_matrix, pos, proj_pos, proj_w); + *proj_w = *proj_w < 1.0f ? 1.0f : 1.0f / *proj_w; } #endif extern void Actor_world_to_eye(ACTOR* actor, f32 eye_height) { - /* Update position */ - actor->eye.position.x = actor->world.position.x; - actor->eye.position.y = actor->world.position.y + eye_height; - actor->eye.position.z = actor->world.position.z; + /* Update position */ + actor->eye.position.x = actor->world.position.x; + actor->eye.position.y = actor->world.position.y + eye_height; + actor->eye.position.z = actor->world.position.z; - /* Update rotation */ - actor->eye.angle.x = actor->world.angle.x; - actor->eye.angle.y = actor->world.angle.y; - actor->eye.angle.z = actor->world.angle.z; + /* Update rotation */ + actor->eye.angle.x = actor->world.angle.x; + actor->eye.angle.y = actor->world.angle.y; + actor->eye.angle.z = actor->world.angle.z; } extern void Actor_position_move(ACTOR* actor) { - (*((GAME_PLAY*)gamePT)->kankyo.nature.proc)(actor); + (*((GAME_PLAY*)gamePT)->kankyo.nature.proc)(actor); - /* divide by 2 because of 30fps -> 60fps? */ - actor->world.position.x += 0.5f * actor->position_speed.x + actor->status_data.collision_vec.x; - actor->world.position.y += 0.5f * actor->position_speed.y + actor->status_data.collision_vec.y; - actor->world.position.z += 0.5f * actor->position_speed.z + actor->status_data.collision_vec.z; + /* divide by 2 because of 30fps -> 60fps? */ + actor->world.position.x += 0.5f * actor->position_speed.x + actor->status_data.collision_vec.x; + actor->world.position.y += 0.5f * actor->position_speed.y + actor->status_data.collision_vec.y; + actor->world.position.z += 0.5f * actor->position_speed.z + actor->status_data.collision_vec.z; } extern void Actor_position_speed_set(ACTOR* actor) { - actor->position_speed.x = actor->speed * sin_s(actor->world.angle.y); - actor->position_speed.z = actor->speed * cos_s(actor->world.angle.y); - - /* divide by 2 because of 30fps -> 60fps? */ - chase_f(&actor->position_speed.y, actor->max_velocity_y, 0.5f * actor->gravity); + actor->position_speed.x = actor->speed * sin_s(actor->world.angle.y); + actor->position_speed.z = actor->speed * cos_s(actor->world.angle.y); + + /* divide by 2 because of 30fps -> 60fps? */ + chase_f(&actor->position_speed.y, actor->max_velocity_y, 0.5f * actor->gravity); } extern void Actor_position_moveF(ACTOR* actor) { - Actor_position_speed_set(actor); - Actor_position_move(actor); + Actor_position_speed_set(actor); + Actor_position_move(actor); } extern int Actor_player_look_direction_check(ACTOR* actor, s16 angle, GAME_PLAY* play) { - s16 player_rot_y = get_player_actor_withoutCheck(play)->actor_class.shape_info.rotation.y; - s16 inv_angle = actor->player_angle_y - -0x8000; - s16 diff = inv_angle - player_rot_y; - int delta = ABS(diff); + s16 player_rot_y = get_player_actor_withoutCheck(play)->actor_class.shape_info.rotation.y; + s16 inv_angle = actor->player_angle_y - -0x8000; + s16 diff = inv_angle - player_rot_y; + int delta = ABS(diff); - return delta < angle; + return delta < angle; } /* @unused ? Actor_display_position_set(... ?) */ static int Actor_data_bank_dma_end_check(ACTOR* actor, GAME_PLAY* play) { - switch (ITEM_NAME_GET_TYPE(actor->npc_id)) { - case NAME_TYPE_SPNPC: - case NAME_TYPE_NPC: - return TRUE; - } + switch (ITEM_NAME_GET_TYPE(actor->npc_id)) { + case NAME_TYPE_SPNPC: + case NAME_TYPE_NPC: + return TRUE; + } - return TRUE; + return TRUE; } -extern void Shape_Info_init(ACTOR* actor, f32 ofs_y, mActor_shadow_proc shadow_proc, f32 shadow_size_x, f32 shadow_size_z) { - actor->shape_info.ofs_y = ofs_y; - actor->shape_info.shadow_proc = shadow_proc; - actor->shape_info.shadow_size_x = shadow_size_x; - actor->shape_info.shadow_size_z = shadow_size_z; - actor->shape_info.draw_shadow = TRUE; - actor->shape_info.shadow_position = &actor->world.position; - actor->shape_info.unk_20 = 0; - actor->shape_info.shadow_size_change_rate = 1.0f; - actor->shape_info.shadow_alpha_change_rate = 1.0f; - actor->shape_info.force_shadow_position = FALSE; +extern void Shape_Info_init(ACTOR* actor, f32 ofs_y, mActor_shadow_proc shadow_proc, f32 shadow_size_x, + f32 shadow_size_z) { + actor->shape_info.ofs_y = ofs_y; + actor->shape_info.shadow_proc = shadow_proc; + actor->shape_info.shadow_size_x = shadow_size_x; + actor->shape_info.shadow_size_z = shadow_size_z; + actor->shape_info.draw_shadow = TRUE; + actor->shape_info.shadow_position = &actor->world.position; + actor->shape_info.unk_20 = 0; + actor->shape_info.shadow_size_change_rate = 1.0f; + actor->shape_info.shadow_alpha_change_rate = 1.0f; + actor->shape_info.force_shadow_position = FALSE; - #ifndef BUGFIXES - actor->shape_info.shadow_position = &actor->world.position; // ??? - #endif +#ifndef BUGFIXES + actor->shape_info.shadow_position = &actor->world.position; // ??? +#endif - actor->shape_info.unk_28 = -1; - actor->shape_info.unk_2D = 0; + actor->shape_info.unk_28 = -1; + actor->shape_info.unk_2D = 0; } extern void Actor_delete(ACTOR* actor) { - if (actor == NULL) { - return; - } + if (actor == NULL) { + return; + } - actor->mv_proc = NULL; - actor->dw_proc = NULL; + actor->mv_proc = NULL; + actor->dw_proc = NULL; } static void Actor_ct(ACTOR* actor, GAME* game) { - GAME_PLAY* play = (GAME_PLAY*)game; - Object_Exchange_c* exchange; - Object_Bank_c* bank; + GAME_PLAY* play = (GAME_PLAY*)game; + Object_Exchange_c* exchange; + Object_Bank_c* bank; - exchange = &play->object_exchange; - bank = &exchange->banks[actor->data_bank_id]; + exchange = &play->object_exchange; + bank = &exchange->banks[actor->data_bank_id]; - bank->num_exist++; - if (actor->part == ACTOR_PART_NPC) { - NPC_ACTOR* npc_actor = (NPC_ACTOR*)actor; - aNPC_draw_data_c draw_data; - int tex_bank_id; - - (*Common_Get(clip).npc_clip->dma_draw_data_proc)(&draw_data, actor->npc_id); - tex_bank_id = mSc_bank_regist_check(exchange, draw_data.texture_bank); - npc_actor->draw.texture_bank_idx = tex_bank_id; - - bank = &exchange->banks[tex_bank_id]; bank->num_exist++; - } + if (actor->part == ACTOR_PART_NPC) { + NPC_ACTOR* npc_actor = (NPC_ACTOR*)actor; + aNPC_draw_data_c draw_data; + int tex_bank_id; - /* Initialize world position & rotation to home position & rotation */ - actor->world = actor->home; - actor->shape_info.rotation = actor->world.angle; - Actor_world_to_eye(actor, 0.0f); - xyz_t_move(&actor->last_world_position, &actor->world.position); + (*Common_Get(clip).npc_clip->dma_draw_data_proc)(&draw_data, actor->npc_id); + tex_bank_id = mSc_bank_regist_check(exchange, draw_data.texture_bank); + npc_actor->draw.texture_bank_idx = tex_bank_id; - actor->scale.x = 0.01f; - actor->scale.y = 0.01f; - actor->scale.z = 0.01f; - actor->max_velocity_y = -20.0f; - actor->player_distance = 3.4028235E+38; - actor->cull_width = 350.0f; - actor->cull_height = 700.0f; - actor->cull_distance = 1000.0f; - actor->cull_radius = 350.0f; - actor->talk_distance = 55.0f; - actor->shape_info.shadow_size_change_rate = 1.0f; - actor->shape_info.shadow_alpha_change_rate = 1.0f; - CollisionCheck_Status_ct(&actor->status_data); - Shape_Info_init(actor, 0.0f, NULL, 0.0f, 0.0f); + bank = &exchange->banks[tex_bank_id]; + bank->num_exist++; + } - if (Actor_data_bank_dma_end_check(actor, play) == TRUE) { - (*actor->ct_proc)(actor, game); - actor->ct_proc = NULL; - } + /* Initialize world position & rotation to home position & rotation */ + actor->world = actor->home; + actor->shape_info.rotation = actor->world.angle; + Actor_world_to_eye(actor, 0.0f); + xyz_t_move(&actor->last_world_position, &actor->world.position); + + actor->scale.x = 0.01f; + actor->scale.y = 0.01f; + actor->scale.z = 0.01f; + actor->max_velocity_y = -20.0f; + actor->player_distance = 3.4028235E+38; + actor->cull_width = 350.0f; + actor->cull_height = 700.0f; + actor->cull_distance = 1000.0f; + actor->cull_radius = 350.0f; + actor->talk_distance = 55.0f; + actor->shape_info.shadow_size_change_rate = 1.0f; + actor->shape_info.shadow_alpha_change_rate = 1.0f; + CollisionCheck_Status_ct(&actor->status_data); + Shape_Info_init(actor, 0.0f, NULL, 0.0f, 0.0f); + + if (Actor_data_bank_dma_end_check(actor, play) == TRUE) { + (*actor->ct_proc)(actor, game); + actor->ct_proc = NULL; + } } static void Actor_dt(ACTOR* actor, GAME* game) { - GAME_PLAY* play = (GAME_PLAY*)game; - Object_Exchange_c* exchange; - ACTOR* t; + GAME_PLAY* play = (GAME_PLAY*)game; + Object_Exchange_c* exchange; + ACTOR* t; - if (actor->sv_proc != NULL) { - (*actor->sv_proc)(actor, game); - actor->sv_proc = NULL; - } - - if (actor->dt_proc != NULL) { - (*actor->dt_proc)(actor, game); - actor->dt_proc = NULL; - } - - t = actor->child_actor; - if (t != NULL && t->parent_actor == actor) { - t->parent_actor = NULL; - } - - t = actor->parent_actor; - if (t != NULL && t->child_actor == actor) { - t->child_actor = NULL; - } - - exchange = &play->object_exchange; - if (ITEM_NAME_GET_TYPE(actor->npc_id) >= NAME_TYPE_PAD15 || ITEM_NAME_GET_TYPE(actor->npc_id) < NAME_TYPE_SPNPC) { - int bank_id = actor->data_bank_id; - - if (bank_id >= exchange->exchange_id && exchange->banks[bank_id].num_exist > 0) { - actor->data_bank_id = -1; - exchange->banks[bank_id].num_exist--; + if (actor->sv_proc != NULL) { + (*actor->sv_proc)(actor, game); + actor->sv_proc = NULL; + } + + if (actor->dt_proc != NULL) { + (*actor->dt_proc)(actor, game); + actor->dt_proc = NULL; + } + + t = actor->child_actor; + if (t != NULL && t->parent_actor == actor) { + t->parent_actor = NULL; + } + + t = actor->parent_actor; + if (t != NULL && t->child_actor == actor) { + t->child_actor = NULL; + } + + exchange = &play->object_exchange; + if (ITEM_NAME_GET_TYPE(actor->npc_id) >= NAME_TYPE_PAD15 || ITEM_NAME_GET_TYPE(actor->npc_id) < NAME_TYPE_SPNPC) { + int bank_id = actor->data_bank_id; + + if (bank_id >= exchange->exchange_id && exchange->banks[bank_id].num_exist > 0) { + actor->data_bank_id = -1; + exchange->banks[bank_id].num_exist--; + } } - } } static void Actor_draw_ta_set(ACTOR* actor, GAME_PLAY* play) { - GRAPH* g; + GRAPH* g; - if ((actor->state_bitfield & ACTOR_STATE_TA_SET) == 0) { - return; - } + if ((actor->state_bitfield & ACTOR_STATE_TA_SET) == 0) { + return; + } - g = play->game.graph; - OPEN_DISP(g); + g = play->game.graph; + OPEN_DISP(g); - gDPSetTextureAdjustMode(NOW_POLY_OPA_DISP++, G_TA_DOLPHIN); - gDPSetTextureAdjustMode(NOW_SHADOW_DISP++, G_TA_DOLPHIN); - gDPSetTextureAdjustMode(NOW_POLY_XLU_DISP++, G_TA_DOLPHIN); + gDPSetTextureAdjustMode(NOW_POLY_OPA_DISP++, G_TA_DOLPHIN); + gDPSetTextureAdjustMode(NOW_SHADOW_DISP++, G_TA_DOLPHIN); + gDPSetTextureAdjustMode(NOW_POLY_XLU_DISP++, G_TA_DOLPHIN); - gDPSetTexEdgeAlpha(NOW_POLY_OPA_DISP++, 127); - gDPSetTexEdgeAlpha(NOW_SHADOW_DISP++, 127); - gDPSetTexEdgeAlpha(NOW_POLY_XLU_DISP++, 127); + gDPSetTexEdgeAlpha(NOW_POLY_OPA_DISP++, 127); + gDPSetTexEdgeAlpha(NOW_SHADOW_DISP++, 127); + gDPSetTexEdgeAlpha(NOW_POLY_XLU_DISP++, 127); - CLOSE_DISP(g); + CLOSE_DISP(g); } static void Actor_draw_ta_clr(ACTOR* actor, GAME_PLAY* play) { - GRAPH* g; + GRAPH* g; - if ((actor->state_bitfield & ACTOR_STATE_TA_SET) == 0) { - return; - } + if ((actor->state_bitfield & ACTOR_STATE_TA_SET) == 0) { + return; + } - g = play->game.graph; - OPEN_DISP(g); + g = play->game.graph; + OPEN_DISP(g); - gDPSetTextureAdjustMode(NOW_POLY_OPA_DISP++, G_TA_N64); - gDPSetTextureAdjustMode(NOW_SHADOW_DISP++, G_TA_N64); - gDPSetTextureAdjustMode(NOW_POLY_XLU_DISP++, G_TA_N64); + gDPSetTextureAdjustMode(NOW_POLY_OPA_DISP++, G_TA_N64); + gDPSetTextureAdjustMode(NOW_SHADOW_DISP++, G_TA_N64); + gDPSetTextureAdjustMode(NOW_POLY_XLU_DISP++, G_TA_N64); - gDPSetTexEdgeAlpha(NOW_POLY_OPA_DISP++, 144); - gDPSetTexEdgeAlpha(NOW_SHADOW_DISP++, 144); - gDPSetTexEdgeAlpha(NOW_POLY_XLU_DISP++, 144); + gDPSetTexEdgeAlpha(NOW_POLY_OPA_DISP++, 144); + gDPSetTexEdgeAlpha(NOW_SHADOW_DISP++, 144); + gDPSetTexEdgeAlpha(NOW_POLY_XLU_DISP++, 144); - CLOSE_DISP(g); + CLOSE_DISP(g); } static void Actor_draw(GAME_PLAY* play, ACTOR* actor) { - LightsN* lights = Global_light_read(&play->global_light, play->game.graph); + LightsN* lights = Global_light_read(&play->global_light, play->game.graph); - /* Light actor */ - LightsN_list_check(lights, play->global_light.list, (actor->state_bitfield & ACTOR_STATE_LIGHTING) ? NULL : &actor->world.position); - LightsN_disp(lights, play->game.graph); - LightsN_disp_BG(lights, play->game.graph); - - /* Load actor position/scale matrix */ - Matrix_softcv3_load(&actor->shape_info.rotation, actor->world.position.x, actor->world.position.y + actor->shape_info.ofs_y * actor->scale.y, actor->world.position.z); - Matrix_scale(actor->scale.x, actor->scale.y, actor->scale.z, 1); + /* Light actor */ + LightsN_list_check(lights, play->global_light.list, + (actor->state_bitfield & ACTOR_STATE_LIGHTING) ? NULL : &actor->world.position); + LightsN_disp(lights, play->game.graph); + LightsN_disp_BG(lights, play->game.graph); - /* Draw actor */ - Actor_draw_ta_set(actor, play); - (*actor->dw_proc)(actor, &play->game); - Actor_draw_ta_clr(actor, play); + /* Load actor position/scale matrix */ + Matrix_softcv3_load(&actor->shape_info.rotation, actor->world.position.x, + actor->world.position.y + actor->shape_info.ofs_y * actor->scale.y, actor->world.position.z); + Matrix_scale(actor->scale.x, actor->scale.y, actor->scale.z, 1); - /* Draw shadow */ - if (actor->shape_info.shadow_proc != NULL) { - (*actor->shape_info.shadow_proc)(actor, lights, play); - } + /* Draw actor */ + Actor_draw_ta_set(actor, play); + (*actor->dw_proc)(actor, &play->game); + Actor_draw_ta_clr(actor, play); + + /* Draw shadow */ + if (actor->shape_info.shadow_proc != NULL) { + (*actor->shape_info.shadow_proc)(actor, lights, play); + } } extern int Actor_draw_actor_no_culling_check(ACTOR* actor) { - return Actor_draw_actor_no_culling_check2(actor, &actor->camera_position, actor->camera_w); + return Actor_draw_actor_no_culling_check2(actor, &actor->camera_position, actor->camera_w); } extern int Actor_draw_actor_no_culling_check2(ACTOR* actor, xyz_t* camera_pos, f32 camera_w) { - int res = FALSE; + int res = FALSE; - if (-actor->cull_radius < camera_pos->z && camera_pos->z < actor->cull_distance + actor->cull_radius) { - f32 m = camera_w < 1.0f ? 1.0f : 1.0f / camera_w; + if (-actor->cull_radius < camera_pos->z && camera_pos->z < actor->cull_distance + actor->cull_radius) { + f32 m = camera_w < 1.0f ? 1.0f : 1.0f / camera_w; - if ((m * (fabsf(camera_pos->x) - actor->cull_width)) < 1.0f && - (m * (camera_pos->y + actor->cull_height)) > -1.0f && - (m * (camera_pos->y - actor->cull_radius) < 1.0f) - ) { - res = TRUE; + if ((m * (fabsf(camera_pos->x) - actor->cull_width)) < 1.0f && + (m * (camera_pos->y + actor->cull_height)) > -1.0f && (m * (camera_pos->y - actor->cull_radius) < 1.0f)) { + res = TRUE; + } } - } - return res; + return res; } static void Actor_cull_check(ACTOR* actor) { - if (Actor_draw_actor_no_culling_check(actor) == TRUE) { - actor->state_bitfield |= ACTOR_STATE_NO_CULL; - } - else { - actor->state_bitfield &= ~ACTOR_STATE_NO_CULL; - } + if (Actor_draw_actor_no_culling_check(actor) == TRUE) { + actor->state_bitfield |= ACTOR_STATE_NO_CULL; + } else { + actor->state_bitfield &= ~ACTOR_STATE_NO_CULL; + } } static void Actor_delete_check(ACTOR* actor, GAME* game) { - GAME_PLAY* play = (GAME_PLAY*)game; + GAME_PLAY* play = (GAME_PLAY*)game; - if ((actor->state_bitfield & (ACTOR_STATE_NO_MOVE_WHILE_CULLED | ACTOR_STATE_NO_DRAW_WHILE_CULLED | ACTOR_STATE_NO_CULL)) == 0) { - if (actor->npc_id != EMPTY_NO) { - if (actor->block_x >= 0 && actor->block_z >= 0) { - if (actor->block_x != play->block_table.block_x || actor->block_z != play->block_table.block_z) { - Actor_delete(actor); + if ((actor->state_bitfield & + (ACTOR_STATE_NO_MOVE_WHILE_CULLED | ACTOR_STATE_NO_DRAW_WHILE_CULLED | ACTOR_STATE_NO_CULL)) == 0) { + if (actor->npc_id != EMPTY_NO) { + if (actor->block_x >= 0 && actor->block_z >= 0) { + if (actor->block_x != play->block_table.block_x || actor->block_z != play->block_table.block_z) { + Actor_delete(actor); + } + } } - } } - } } extern void Actor_info_ct(GAME* game, Actor_info* actor_info, Actor_data* player_data) { - GAME_PLAY* play = (GAME_PLAY*)game; - ACTOR* player_actor; - ACTOR_DLFTBL* dlftbl; - int i; + GAME_PLAY* play = (GAME_PLAY*)game; + ACTOR* player_actor; + ACTOR_DLFTBL* dlftbl; + int i; - bzero(actor_info, sizeof(Actor_info)); - actor_dlftbls_init(); + bzero(actor_info, sizeof(Actor_info)); + actor_dlftbls_init(); - Matrix_copy_MtxF(&play->billboard_matrix, &MtxF_clear); - Matrix_copy_MtxF(&play->projection_matrix, &MtxF_clear); + Matrix_copy_MtxF(&play->billboard_matrix, &MtxF_clear); + Matrix_copy_MtxF(&play->projection_matrix, &MtxF_clear); - /* Reset the actor dlf table info */ - dlftbl = actor_dlftbls; - for (i = 0; i < mAc_PROFILE_NUM; i++) { - dlftbl->alloc_buf = NULL; - dlftbl->num_actors = 0; - dlftbl++; - } - - if (mEv_CheckFirstJob() == TRUE) { - Common_Set(demo_profiles[0], mAc_PROFILE_INTRO_DEMO); // force intro demo to spawn - } - - /* Spawn any demo actors */ - for (i = 0; i < 2; i++) { - s16 demo_profile = Common_Get(demo_profiles[i]); - - if (demo_profile != mAc_PROFILE_NUM) { - Actor_info_make_actor( - actor_info, - game, - demo_profile, - 0.0f, 0.0f, 0.0f, - 0, 0, 0, - -1, -1, - -1, - EMPTY_NO, - -1, - -1, - -1 - ); - } - - Common_Set(demo_profiles[i], mAc_PROFILE_NUM); - } - - /* Try spawning the player actor */ - player_actor = Actor_info_make_actor( - actor_info, - game, - player_data->profile, - player_data->position.x, player_data->position.y, player_data->position.z, - player_data->rotation.x, player_data->rotation.y, player_data->rotation.z, - -1, -1, - -1, - EMPTY_NO, - player_data->arg, - -1, - -1 - ); - - if (player_actor != NULL) { - player_actor->world.position.y = mCoBG_GetBgY_OnlyCenter_FromWpos2(player_actor->world.position, 0.0f); - mFI_SetBearActor(play, player_actor->world.position, FALSE); - } - - /* Spawn the current bg item type actor */ - if (Common_Get(bg_item_profile) != 0) { - Actor_info_make_actor( - actor_info, - game, - Common_Get(bg_item_profile), - 0.0f, 0.0f, 0.0f, - 0, 0, 0, - -1, -1, - -1, - EMPTY_NO, - -1, - -1, - -1 - ); - } - - /* Spawn all pending control actors */ - if (play->ctrl_actor_data_num != 0) { - s16* ctrl_actor_data = play->ctrl_actor_data; - for (i = 0; i < play->ctrl_actor_data_num; i++) { - Actor_info_make_actor( - &play->actor_info, - game, - *ctrl_actor_data, - 0.0f, 0.0f, 0.0f, - 0, 0, 0, - -1, -1, - -1, - EMPTY_NO, - -1, - -1, - -1 - ); - - ctrl_actor_data++; + /* Reset the actor dlf table info */ + dlftbl = actor_dlftbls; + for (i = 0; i < mAc_PROFILE_NUM; i++) { + dlftbl->alloc_buf = NULL; + dlftbl->num_actors = 0; + dlftbl++; } - play->ctrl_actor_data_num = 0; - } - - mSc_regist_initial_exchange_bank(play); - - /* Spawn all pending actors */ - if (play->actor_data_num != 0) { - Actor_data* actor_data = play->actor_data; - for (i = 0; i < play->actor_data_num; i++) { - - Actor_info_make_actor( - &play->actor_info, - (GAME*)play, - actor_data->profile, - actor_data->position.x, actor_data->position.y, actor_data->position.z, - actor_data->rotation.x, actor_data->rotation.y, actor_data->rotation.z, - -1, -1, - -1, - EMPTY_NO, - actor_data->arg, - -1, - -1 - ); - - actor_data++; + if (mEv_CheckFirstJob() == TRUE) { + Common_Set(demo_profiles[0], mAc_PROFILE_INTRO_DEMO); // force intro demo to spawn } - play->actor_data_num = 0; - } + /* Spawn any demo actors */ + for (i = 0; i < 2; i++) { + s16 demo_profile = Common_Get(demo_profiles[i]); + + if (demo_profile != mAc_PROFILE_NUM) { + Actor_info_make_actor(actor_info, game, demo_profile, 0.0f, 0.0f, 0.0f, 0, 0, 0, -1, -1, -1, EMPTY_NO, -1, + -1, -1); + } + + Common_Set(demo_profiles[i], mAc_PROFILE_NUM); + } + + /* Try spawning the player actor */ + player_actor = + Actor_info_make_actor(actor_info, game, player_data->profile, player_data->position.x, player_data->position.y, + player_data->position.z, player_data->rotation.x, player_data->rotation.y, + player_data->rotation.z, -1, -1, -1, EMPTY_NO, player_data->arg, -1, -1); + + if (player_actor != NULL) { + player_actor->world.position.y = mCoBG_GetBgY_OnlyCenter_FromWpos2(player_actor->world.position, 0.0f); + mFI_SetBearActor(play, player_actor->world.position, FALSE); + } + + /* Spawn the current bg item type actor */ + if (Common_Get(bg_item_profile) != 0) { + Actor_info_make_actor(actor_info, game, Common_Get(bg_item_profile), 0.0f, 0.0f, 0.0f, 0, 0, 0, -1, -1, -1, + EMPTY_NO, -1, -1, -1); + } + + /* Spawn all pending control actors */ + if (play->ctrl_actor_data_num != 0) { + s16* ctrl_actor_data = play->ctrl_actor_data; + for (i = 0; i < play->ctrl_actor_data_num; i++) { + Actor_info_make_actor(&play->actor_info, game, *ctrl_actor_data, 0.0f, 0.0f, 0.0f, 0, 0, 0, -1, -1, -1, + EMPTY_NO, -1, -1, -1); + + ctrl_actor_data++; + } + + play->ctrl_actor_data_num = 0; + } + + mSc_regist_initial_exchange_bank(play); + + /* Spawn all pending actors */ + if (play->actor_data_num != 0) { + Actor_data* actor_data = play->actor_data; + for (i = 0; i < play->actor_data_num; i++) { + + Actor_info_make_actor(&play->actor_info, (GAME*)play, actor_data->profile, actor_data->position.x, + actor_data->position.y, actor_data->position.z, actor_data->rotation.x, + actor_data->rotation.y, actor_data->rotation.z, -1, -1, -1, EMPTY_NO, actor_data->arg, + -1, -1); + + actor_data++; + } + + play->actor_data_num = 0; + } } extern void Actor_info_dt(Actor_info* actor_info, GAME_PLAY* play) { - int i; + int i; - for (i = 0; i < ACTOR_PART_NUM; i++) { - ACTOR* actor; + for (i = 0; i < ACTOR_PART_NUM; i++) { + ACTOR* actor; - while (actor = actor_info->list[i].actor, actor != NULL) { - Actor_info_delete(actor_info, actor, (GAME*)play); + while (actor = actor_info->list[i].actor, actor != NULL) { + Actor_info_delete(actor_info, actor, (GAME*)play); + } } - } - actor_dlftbls_cleanup(); + actor_dlftbls_cleanup(); } extern void Actor_info_call_actor(GAME_PLAY* play, Actor_info* actor_info) { - //GAME* game = (GAME*)play; - PLAYER_ACTOR* player_actor = get_player_actor_withoutCheck(play); - ACTOR* actor; - int i; + // GAME* game = (GAME*)play; + PLAYER_ACTOR* player_actor = get_player_actor_withoutCheck(play); + ACTOR* actor; + int i; - mFI_FieldMove(player_actor->actor_class.world.position); - mBI_move(play); + mFI_FieldMove(player_actor->actor_class.world.position); + mBI_move(play); - for (i = 0; i < ACTOR_PART_NUM; i++) { - ACTOR* next; - actor = actor_info->list[i].actor; + for (i = 0; i < ACTOR_PART_NUM; i++) { + ACTOR* next; + actor = actor_info->list[i].actor; - while (actor != NULL) { - play->game.doing_point = actor->id; - play->game.doing_point_specific = 151; + while (actor != NULL) { + play->game.doing_point = actor->id; + play->game.doing_point_specific = 151; - if (actor->world.position.y < -25000.0f) { - actor->world.position.y = -25000.0f; - } + if (actor->world.position.y < -25000.0f) { + actor->world.position.y = -25000.0f; + } - if (actor->ct_proc != NULL) { - if (Actor_data_bank_dma_end_check(actor, play) == TRUE) { - play->game.doing_point_specific = 152; - (*actor->ct_proc)(actor, (GAME*)play); - play->game.doing_point_specific = 153; - actor->ct_proc = NULL; + if (actor->ct_proc != NULL) { + if (Actor_data_bank_dma_end_check(actor, play) == TRUE) { + play->game.doing_point_specific = 152; + (*actor->ct_proc)(actor, (GAME*)play); + play->game.doing_point_specific = 153; + actor->ct_proc = NULL; + } + + next = actor->next_actor; + } else { + if (Actor_data_bank_dma_end_check(actor, play) == FALSE) { + play->game.doing_point_specific = 154; + Actor_delete(actor); + play->game.doing_point_specific = 155; + next = actor->next_actor; + } else if (actor->mv_proc == NULL) { + if (actor->drawn == FALSE) { + play->game.doing_point_specific = 156; + next = Actor_info_delete(&play->actor_info, actor, (GAME*)play); + play->game.doing_point_specific = 157; + } else { + play->game.doing_point_specific = 158; + Actor_dt(actor, (GAME*)play); + play->game.doing_point_specific = 159; + next = actor->next_actor; + } + } else { + play->game.doing_point_specific = 160; + xyz_t_move(&actor->last_world_position, &actor->world.position); + actor->player_distance_xz = + search_position_distanceXZ(&actor->world.position, &player_actor->actor_class.world.position); + actor->player_distance_y = player_actor->actor_class.world.position.y - actor->world.position.y; + actor->player_distance = actor->player_distance_xz * actor->player_distance_xz + + actor->player_distance_y * actor->player_distance_y; + actor->player_angle_y = + search_position_angleY(&actor->world.position, &player_actor->actor_class.world.position); + actor->state_bitfield &= ~ACTOR_STATE_24; + + if ((actor->state_bitfield & (ACTOR_STATE_NO_MOVE_WHILE_CULLED | ACTOR_STATE_NO_CULL)) || + actor->part == ACTOR_PART_NPC) { + play->game.doing_point_specific = 161; + (*actor->mv_proc)(actor, (GAME*)play); + play->game.doing_point_specific = 162; + } + + CollisionCheck_Status_Clear(&actor->status_data); + next = actor->next_actor; + } + } + + actor = next; } - - next = actor->next_actor; - } - else { - if (Actor_data_bank_dma_end_check(actor, play) == FALSE) { - play->game.doing_point_specific = 154; - Actor_delete(actor); - play->game.doing_point_specific = 155; - next = actor->next_actor; - } - else if (actor->mv_proc == NULL) { - if (actor->drawn == FALSE) { - play->game.doing_point_specific = 156; - next = Actor_info_delete(&play->actor_info, actor, (GAME*)play); - play->game.doing_point_specific = 157; - } - else { - play->game.doing_point_specific = 158; - Actor_dt(actor, (GAME*)play); - play->game.doing_point_specific = 159; - next = actor->next_actor; - } - } - else { - play->game.doing_point_specific = 160; - xyz_t_move(&actor->last_world_position, &actor->world.position); - actor->player_distance_xz = search_position_distanceXZ(&actor->world.position, &player_actor->actor_class.world.position); - actor->player_distance_y = player_actor->actor_class.world.position.y - actor->world.position.y; - actor->player_distance = actor->player_distance_xz * actor->player_distance_xz + actor->player_distance_y * actor->player_distance_y; - actor->player_angle_y = search_position_angleY(&actor->world.position, &player_actor->actor_class.world.position); - actor->state_bitfield &= ~ACTOR_STATE_24; - - if ((actor->state_bitfield & (ACTOR_STATE_NO_MOVE_WHILE_CULLED | ACTOR_STATE_NO_CULL)) || actor->part == ACTOR_PART_NPC) { - play->game.doing_point_specific = 161; - (*actor->mv_proc)(actor, (GAME*)play); - play->game.doing_point_specific = 162; - } - - CollisionCheck_Status_Clear(&actor->status_data); - next = actor->next_actor; - } - } - - actor = next; } - } - play->game.doing_point_specific = 163; + play->game.doing_point_specific = 163; } extern void Actor_info_draw_actor(GAME_PLAY* play, Actor_info* actor_info) { - Actor_list* list; - ACTOR* actor; - int i; - DRAW_CHK_PROC draw_chk_proc = play->draw_chk_proc; + Actor_list* list; + ACTOR* actor; + int i; + DRAW_CHK_PROC draw_chk_proc = play->draw_chk_proc; - list = actor_info->list; - for (i = 0; i < ACTOR_PART_NUM; i++) { - int do_not_draw; + list = actor_info->list; + for (i = 0; i < ACTOR_PART_NUM; i++) { + int do_not_draw; - for (actor = list->actor; actor != NULL; actor = actor->next_actor) { - /* Apply projection matrix to actor position */ - Skin_Matrix_PrjMulVector(&play->projection_matrix, &actor->world.position, &actor->camera_position, &actor->camera_w); + for (actor = list->actor; actor != NULL; actor = actor->next_actor) { + /* Apply projection matrix to actor position */ + Skin_Matrix_PrjMulVector(&play->projection_matrix, &actor->world.position, &actor->camera_position, + &actor->camera_w); - Actor_cull_check(actor); - do_not_draw = (*draw_chk_proc)(actor, play); - actor->drawn = FALSE; + Actor_cull_check(actor); + do_not_draw = (*draw_chk_proc)(actor, play); + actor->drawn = FALSE; - if (do_not_draw == FALSE && actor->ct_proc == NULL && actor->dw_proc != NULL) { - if ((actor->state_bitfield & (ACTOR_STATE_NO_DRAW_WHILE_CULLED | ACTOR_STATE_NO_CULL))) { - if ((actor->state_bitfield & ACTOR_STATE_INVISIBLE) == 0 && actor->cull_while_talking == FALSE && actor->skip_drawing == FALSE) { - Actor_draw(play, actor); - actor->drawn = TRUE; - } + if (do_not_draw == FALSE && actor->ct_proc == NULL && actor->dw_proc != NULL) { + if ((actor->state_bitfield & (ACTOR_STATE_NO_DRAW_WHILE_CULLED | ACTOR_STATE_NO_CULL))) { + if ((actor->state_bitfield & ACTOR_STATE_INVISIBLE) == 0 && actor->cull_while_talking == FALSE && + actor->skip_drawing == FALSE) { + Actor_draw(play, actor); + actor->drawn = TRUE; + } + } else { + Actor_delete_check(actor, (GAME*)play); + } + } } - else { - Actor_delete_check(actor, (GAME*)play); - } - } + + list++; } - list++; - } - - Light_list_point_draw(play); + Light_list_point_draw(play); } static void Actor_info_part_new(Actor_info* actor_info, ACTOR* actor, u8 part) { - ACTOR* next; + ACTOR* next; - actor->part = part; - actor_info->total_num++; - actor_info->list[part].num_actors++; + actor->part = part; + actor_info->total_num++; + actor_info->list[part].num_actors++; - next = actor_info->list[part].actor; - if (next != NULL) { - next->prev_actor = actor; - } + next = actor_info->list[part].actor; + if (next != NULL) { + next->prev_actor = actor; + } - actor_info->list[part].actor = actor; - actor->next_actor = next; + actor_info->list[part].actor = actor; + actor->next_actor = next; } static ACTOR* Actor_info_part_delete(Actor_info* actor_info, ACTOR* actor) { - ACTOR* next; + ACTOR* next; - actor_info->total_num--; - actor_info->list[actor->part].num_actors--; + actor_info->total_num--; + actor_info->list[actor->part].num_actors--; - if (actor->prev_actor != NULL) { - actor->prev_actor->next_actor = actor->next_actor; - } - else { - actor_info->list[actor->part].actor = actor->next_actor; - } + if (actor->prev_actor != NULL) { + actor->prev_actor->next_actor = actor->next_actor; + } else { + actor_info->list[actor->part].actor = actor->next_actor; + } - next = actor->next_actor; - if (next != NULL) { - next->prev_actor = actor->prev_actor; - } + next = actor->next_actor; + if (next != NULL) { + next->prev_actor = actor->prev_actor; + } - actor->prev_actor = NULL; - actor->next_actor = NULL; + actor->prev_actor = NULL; + actor->next_actor = NULL; - return next; + return next; } extern void Actor_free_overlay_area(ACTOR_DLFTBL* dlftbl) { - if ((dlftbl->flags & 2) == 0) { - if ((dlftbl->flags & 1)) { - dlftbl->alloc_buf = NULL; + if ((dlftbl->flags & 2) == 0) { + if ((dlftbl->flags & 1)) { + dlftbl->alloc_buf = NULL; + } else { + zelda_free(dlftbl->alloc_buf); + dlftbl->alloc_buf = NULL; + } } - else { - zelda_free(dlftbl->alloc_buf); - dlftbl->alloc_buf = NULL; - } - } } static void actor_free_check(ACTOR_DLFTBL* dlftbl, mActor_name_t id) { - if (dlftbl->num_actors == 0 && dlftbl->alloc_buf != NULL) { - switch (ITEM_NAME_GET_TYPE(id)) { - case NAME_TYPE_SPNPC: - case NAME_TYPE_NPC: - (*Common_Get(clip).npc_clip->free_overlay_area_proc)(dlftbl); - break; + if (dlftbl->num_actors == 0 && dlftbl->alloc_buf != NULL) { + switch (ITEM_NAME_GET_TYPE(id)) { + case NAME_TYPE_SPNPC: + case NAME_TYPE_NPC: + (*Common_Get(clip).npc_clip->free_overlay_area_proc)(dlftbl); + break; - case NAME_TYPE_STRUCT: - (*Common_Get(clip).structure_clip->free_overlay_area_proc)(dlftbl); - break; + case NAME_TYPE_STRUCT: + (*Common_Get(clip).structure_clip->free_overlay_area_proc)(dlftbl); + break; - default: - Actor_free_overlay_area(dlftbl); - break; + default: + Actor_free_overlay_area(dlftbl); + break; + } } - } } extern void Actor_get_overlay_area(ACTOR_DLFTBL* dlftbl, int unused, size_t alloc_size) { - if ((dlftbl->flags & 2)) { - dlftbl->alloc_buf = (u8*)zelda_malloc_r(alloc_size); - } - else { - dlftbl->alloc_buf = (u8*)zelda_malloc(alloc_size); - } + if ((dlftbl->flags & 2)) { + dlftbl->alloc_buf = (u8*)zelda_malloc_r(alloc_size); + } else { + dlftbl->alloc_buf = (u8*)zelda_malloc(alloc_size); + } } -static int Actor_data_bank_regist_check_npc(int* bank_id, ACTOR_PROFILE* profile, ACTOR_DLFTBL* dlftbl, GAME* game, mActor_name_t name_id) { - return TRUE; +static int Actor_data_bank_regist_check_npc(int* bank_id, ACTOR_PROFILE* profile, ACTOR_DLFTBL* dlftbl, GAME* game, + mActor_name_t name_id) { + return TRUE; } -static int Actor_data_bank_regist_check(int* bank_id, ACTOR_PROFILE* profile, ACTOR_DLFTBL* dlftbl, GAME* game, mActor_name_t name_id) { - int res = TRUE; +static int Actor_data_bank_regist_check(int* bank_id, ACTOR_PROFILE* profile, ACTOR_DLFTBL* dlftbl, GAME* game, + mActor_name_t name_id) { + int res = TRUE; - if (*bank_id == -1) { - if (profile->part == ACTOR_PART_NPC) { - res = Actor_data_bank_regist_check_npc(bank_id, profile, dlftbl, game, name_id); + if (*bank_id == -1) { + if (profile->part == ACTOR_PART_NPC) { + res = Actor_data_bank_regist_check_npc(bank_id, profile, dlftbl, game, name_id); + } else { + // in DnM, this was another func call + res = TRUE; + } } - else { - // in DnM, this was another func call - res = TRUE; - } - } - return res; + return res; } -static int Actor_malloc_actor_class(ACTOR** actor_pp, ACTOR_PROFILE* profile, ACTOR_DLFTBL* dlftbl, const char* unk, mActor_name_t id) { - aNPC_draw_data_c draw_data; +static int Actor_malloc_actor_class(ACTOR** actor_pp, ACTOR_PROFILE* profile, ACTOR_DLFTBL* dlftbl, const char* unk, + mActor_name_t id) { + aNPC_draw_data_c draw_data; - switch (ITEM_NAME_GET_TYPE(id)) { - case NAME_TYPE_SPNPC: - case NAME_TYPE_NPC: - { - *actor_pp = (*Common_Get(clip).npc_clip->get_actor_area_proc)(profile->class_size, unk, 1); - (*Common_Get(clip).npc_clip->dma_draw_data_proc)(&draw_data, id); // leftover? - break; + switch (ITEM_NAME_GET_TYPE(id)) { + case NAME_TYPE_SPNPC: + case NAME_TYPE_NPC: { + *actor_pp = (*Common_Get(clip).npc_clip->get_actor_area_proc)(profile->class_size, unk, 1); + (*Common_Get(clip).npc_clip->dma_draw_data_proc)(&draw_data, id); // leftover? + break; + } + + case NAME_TYPE_STRUCT: { + *actor_pp = (ACTOR*)((*Common_Get(clip).structure_clip->get_actor_area_proc)()); + break; + } + + default: { + *actor_pp = (ACTOR*)zelda_malloc(profile->class_size); + break; + } } - case NAME_TYPE_STRUCT: - { - *actor_pp = (ACTOR*)((*Common_Get(clip).structure_clip->get_actor_area_proc)()); - break; + if (*actor_pp == NULL) { + actor_free_check(dlftbl, id); + return FALSE; } - default: - { - *actor_pp = (ACTOR*)zelda_malloc(profile->class_size); - break; - } - } - - if (*actor_pp == NULL) { - actor_free_check(dlftbl, id); - return FALSE; - } - - return TRUE; + return TRUE; } -extern void Actor_init_actor_class(ACTOR* actor, ACTOR_PROFILE* profile, ACTOR_DLFTBL* dlftbl, GAME_PLAY* play, int bank_idx, f32 x, f32 y, f32 z, s16 rot_x, s16 rot_y, s16 rot_z, s8 block_x, s8 block_z, s16 move_actor_list_idx, mActor_name_t name_id, s16 arg) { - mem_clear((u8*)actor, profile->class_size, 0); - actor->dlftbl = dlftbl; - actor->id = profile->id; - actor->state_bitfield = profile->initial_flags_state; - actor->data_bank_id = bank_idx; - actor->ct_proc = profile->ct_proc; - actor->dt_proc = profile->dt_proc; - actor->mv_proc = profile->mv_proc; - actor->dw_proc = profile->dw_proc; - actor->sv_proc = profile->sv_proc; - actor->actor_specific = arg; - actor->scene_id = play->scene_id; - actor->home.position.x = x; - actor->home.position.y = y; - actor->home.position.z = z; - actor->home.angle.x = rot_x; - actor->home.angle.y = rot_y; - actor->home.angle.z = rot_z; - actor->block_x = block_x; - actor->block_z = block_z; - actor->move_actor_list_idx = move_actor_list_idx; - actor->npc_id = name_id; +extern void Actor_init_actor_class(ACTOR* actor, ACTOR_PROFILE* profile, ACTOR_DLFTBL* dlftbl, GAME_PLAY* play, + int bank_idx, f32 x, f32 y, f32 z, s16 rot_x, s16 rot_y, s16 rot_z, s8 block_x, + s8 block_z, s16 move_actor_list_idx, mActor_name_t name_id, s16 arg) { + mem_clear((u8*)actor, profile->class_size, 0); + actor->dlftbl = dlftbl; + actor->id = profile->id; + actor->state_bitfield = profile->initial_flags_state; + actor->data_bank_id = bank_idx; + actor->ct_proc = profile->ct_proc; + actor->dt_proc = profile->dt_proc; + actor->mv_proc = profile->mv_proc; + actor->dw_proc = profile->dw_proc; + actor->sv_proc = profile->sv_proc; + actor->actor_specific = arg; + actor->scene_id = play->scene_id; + actor->home.position.x = x; + actor->home.position.y = y; + actor->home.position.z = z; + actor->home.angle.x = rot_x; + actor->home.angle.y = rot_y; + actor->home.angle.z = rot_z; + actor->block_x = block_x; + actor->block_z = block_z; + actor->move_actor_list_idx = move_actor_list_idx; + actor->npc_id = name_id; } #ifndef MUST_MATCH /* @nonmatching */ -extern ACTOR* Actor_info_make_actor(Actor_info* actor_info, GAME* game, s16 profile_no, f32 x, f32 y, f32 z, s16 rot_x, s16 rot_y, s16 rot_z, s8 block_x, s8 block_z, s16 move_actor_list_idx, mActor_name_t name_id, s16 arg, s8 npc_info_idx, int data_bank_idx) { - const char* test = ""; - GAME_PLAY* play = (GAME_PLAY*)game; - ACTOR* actor; - ACTOR_PROFILE* profile; - ACTOR_DLFTBL* dlftbl; +extern ACTOR* Actor_info_make_actor(Actor_info* actor_info, GAME* game, s16 profile_no, f32 x, f32 y, f32 z, s16 rot_x, + s16 rot_y, s16 rot_z, s8 block_x, s8 block_z, s16 move_actor_list_idx, + mActor_name_t name_id, s16 arg, s8 npc_info_idx, int data_bank_idx) { + const char* test = ""; + GAME_PLAY* play = (GAME_PLAY*)game; + ACTOR* actor; + ACTOR_PROFILE* profile; + ACTOR_DLFTBL* dlftbl; - test = ""; // removing this line helps a bit... + test = ""; // removing this line helps a bit... - dlftbl = &actor_dlftbls[profile_no]; + dlftbl = &actor_dlftbls[profile_no]; - if (actor_info->total_num > mAc_MAX_ACTORS) { - return NULL; - } + if (actor_info->total_num > mAc_MAX_ACTORS) { + return NULL; + } - profile = dlftbl->profile; - if (Actor_data_bank_regist_check(&data_bank_idx, profile, dlftbl, game, name_id) == FALSE) { - return NULL; - } + profile = dlftbl->profile; + if (Actor_data_bank_regist_check(&data_bank_idx, profile, dlftbl, game, name_id) == FALSE) { + return NULL; + } - if (Actor_malloc_actor_class(&actor, profile, dlftbl, test, name_id) == FALSE) { - return NULL; - } + if (Actor_malloc_actor_class(&actor, profile, dlftbl, test, name_id) == FALSE) { + return NULL; + } - dlftbl->num_actors++; - Actor_init_actor_class(actor, profile, dlftbl, play, data_bank_idx, x, y, z, rot_x, rot_y, rot_z, block_x, block_z, move_actor_list_idx, name_id, arg); - Actor_info_part_new(actor_info, actor, profile->part); - mNpc_SetNpcinfo(actor, npc_info_idx); - Actor_ct(actor, (GAME*)play); + dlftbl->num_actors++; + Actor_init_actor_class(actor, profile, dlftbl, play, data_bank_idx, x, y, z, rot_x, rot_y, rot_z, block_x, block_z, + move_actor_list_idx, name_id, arg); + Actor_info_part_new(actor_info, actor, profile->part); + mNpc_SetNpcinfo(actor, npc_info_idx); + Actor_ct(actor, (GAME*)play); - return actor; + return actor; } #else -extern asm ACTOR* Actor_info_make_actor(Actor_info* actor_info, GAME* game, s16 profile_no, f32 x, f32 y, f32 z, s16 rot_x, s16 rot_y, s16 rot_z, s8 block_x, s8 block_z, s16 move_actor_list_idx, mActor_name_t name_id, s16 arg, s8 npc_info_idx, int data_bank_idx) { - #include "asm/80375830.s" +extern asm ACTOR* Actor_info_make_actor(Actor_info* actor_info, GAME* game, s16 profile_no, f32 x, f32 y, f32 z, + s16 rot_x, s16 rot_y, s16 rot_z, s8 block_x, s8 block_z, + s16 move_actor_list_idx, mActor_name_t name_id, s16 arg, s8 npc_info_idx, + int data_bank_idx) { +#include "asm/80375830.s" } #endif -extern ACTOR* Actor_info_make_child_actor(Actor_info* actor_info, ACTOR* parent_actor, GAME* game, s16 profile, f32 x, f32 y, f32 z, s16 rot_x, s16 rot_y, s16 rot_z, s16 move_actor_list_idx, mActor_name_t name_id, s16 arg, int data_bank_idx) { - ACTOR* actor = Actor_info_make_actor(actor_info, game, profile, x, y, z, rot_x, rot_y, rot_z, -1, -1, move_actor_list_idx, name_id, arg, -1, data_bank_idx); +extern ACTOR* Actor_info_make_child_actor(Actor_info* actor_info, ACTOR* parent_actor, GAME* game, s16 profile, f32 x, + f32 y, f32 z, s16 rot_x, s16 rot_y, s16 rot_z, s16 move_actor_list_idx, + mActor_name_t name_id, s16 arg, int data_bank_idx) { + ACTOR* actor = Actor_info_make_actor(actor_info, game, profile, x, y, z, rot_x, rot_y, rot_z, -1, -1, + move_actor_list_idx, name_id, arg, -1, data_bank_idx); - if (actor != NULL) { - parent_actor->child_actor = actor; - actor->parent_actor = parent_actor; - } + if (actor != NULL) { + parent_actor->child_actor = actor; + actor->parent_actor = parent_actor; + } - return actor; + return actor; } static void restore_fgdata(ACTOR* actor, GAME_PLAY* play) { - mActor_name_t name = actor->npc_id; - - if (name != EMPTY_NO && actor->move_actor_list_idx == -1 && actor->block_x >= 0 && actor->block_z >= 0) { - if (ITEM_NAME_GET_TYPE(name) == NAME_TYPE_ITEM2) { - xyz_t pos; + mActor_name_t name = actor->npc_id; - xyz_t_move(&pos, &actor->home.position); - if (mFI_search_unit_around(&pos, EMPTY_NO) == TRUE) { - /* pos now holds the position of the empty unit */ - mFI_SetFG_common(actor->npc_id, pos, FALSE); /* This causes the airplane duplication "bug" */ - } + if (name != EMPTY_NO && actor->move_actor_list_idx == -1 && actor->block_x >= 0 && actor->block_z >= 0) { + if (ITEM_NAME_GET_TYPE(name) == NAME_TYPE_ITEM2) { + xyz_t pos; + + xyz_t_move(&pos, &actor->home.position); + if (mFI_search_unit_around(&pos, EMPTY_NO) == TRUE) { + /* pos now holds the position of the empty unit */ + mFI_SetFG_common(actor->npc_id, pos, FALSE); /* This causes the airplane duplication "bug" */ + } + } else { + mFI_SetFG_common(name, actor->home.position, FALSE); + } } - else { - mFI_SetFG_common(name, actor->home.position, FALSE); - } - } } static int restore_flag[ACTOR_PART_NUM] = { - TRUE, /* FG */ - TRUE, /* ITEM */ - FALSE, /* PLAYER */ - FALSE, /* 3 */ - FALSE, /* NPC */ - FALSE, /* BG */ - FALSE, /* EFFECT */ - FALSE /* CONTROL */ + TRUE, /* FG */ + TRUE, /* ITEM */ + FALSE, /* PLAYER */ + FALSE, /* 3 */ + FALSE, /* NPC */ + FALSE, /* BG */ + FALSE, /* EFFECT */ + FALSE /* CONTROL */ }; static void restore_fgdata_one(ACTOR* actor, GAME_PLAY* play) { - if (restore_flag[actor->part] == TRUE) { - restore_fgdata(actor, play); - } - else if (actor->restore_fg == TRUE) { - restore_fgdata(actor, play); - } + if (restore_flag[actor->part] == TRUE) { + restore_fgdata(actor, play); + } else if (actor->restore_fg == TRUE) { + restore_fgdata(actor, play); + } } extern void restore_fgdata_all(GAME_PLAY* play) { - Actor_info* info; - ACTOR* actor; - int i; + Actor_info* info; + ACTOR* actor; + int i; - info = &play->actor_info; - for (i = 0; i < ACTOR_PART_NUM; i++) { - if (restore_flag[i] == TRUE) { - for (actor = info->list[i].actor; actor != NULL; actor = actor->next_actor) { - restore_fgdata(actor, play); - } - } - else { - for (actor = info->list[i].actor; actor != NULL; actor = actor->next_actor) { - if (actor->restore_fg == TRUE) { - restore_fgdata(actor, play); + info = &play->actor_info; + for (i = 0; i < ACTOR_PART_NUM; i++) { + if (restore_flag[i] == TRUE) { + for (actor = info->list[i].actor; actor != NULL; actor = actor->next_actor) { + restore_fgdata(actor, play); + } + } else { + for (actor = info->list[i].actor; actor != NULL; actor = actor->next_actor) { + if (actor->restore_fg == TRUE) { + restore_fgdata(actor, play); + } + } } - } } - } } extern void Actor_info_save_actor(GAME_PLAY* play) { - Actor_info* info; - ACTOR* actor; - int i; + Actor_info* info; + ACTOR* actor; + int i; - info = &play->actor_info; - for (i = 0; i < ACTOR_PART_NUM; i++) { - for (actor = info->list[i].actor; actor != NULL; actor = actor->next_actor) { - if (actor->sv_proc != NULL) { - (*actor->sv_proc)(actor, (GAME*)play); - actor->sv_proc = NULL; - } + info = &play->actor_info; + for (i = 0; i < ACTOR_PART_NUM; i++) { + for (actor = info->list[i].actor; actor != NULL; actor = actor->next_actor) { + if (actor->sv_proc != NULL) { + (*actor->sv_proc)(actor, (GAME*)play); + actor->sv_proc = NULL; + } + } } - } - restore_fgdata_all(play); + restore_fgdata_all(play); } extern ACTOR* Actor_info_delete(Actor_info* actor_info, ACTOR* actor, GAME* game) { - mActor_name_t name_id = actor->npc_id; - ACTOR_DLFTBL* dlftbl = actor->dlftbl; - ACTOR* next_actor; + mActor_name_t name_id = actor->npc_id; + ACTOR_DLFTBL* dlftbl = actor->dlftbl; + ACTOR* next_actor; - restore_fgdata_one(actor, (GAME_PLAY*)game); - Actor_dt(actor, game); - next_actor = Actor_info_part_delete(actor_info, actor); + restore_fgdata_one(actor, (GAME_PLAY*)game); + Actor_dt(actor, game); + next_actor = Actor_info_part_delete(actor_info, actor); - switch (ITEM_NAME_GET_TYPE(name_id)) { - case NAME_TYPE_SPNPC: - case NAME_TYPE_NPC: - { - (*Common_Get(clip).npc_clip->free_actor_area_proc)(actor); - break; + switch (ITEM_NAME_GET_TYPE(name_id)) { + case NAME_TYPE_SPNPC: + case NAME_TYPE_NPC: { + (*Common_Get(clip).npc_clip->free_actor_area_proc)(actor); + break; + } + + case NAME_TYPE_STRUCT: { + (*Common_Get(clip).structure_clip->free_actor_area_proc)((STRUCTURE_ACTOR*)actor); + break; + } + + default: { + zelda_free(actor); + break; + } } - case NAME_TYPE_STRUCT: - { - (*Common_Get(clip).structure_clip->free_actor_area_proc)((STRUCTURE_ACTOR*)actor); - break; + if (dlftbl->ram_start == NULL) { + dlftbl->num_actors--; + } else { + dlftbl->num_actors--; + actor_free_check(dlftbl, actor->npc_id); } - default: - { - zelda_free(actor); - break; - } - } - - if (dlftbl->ram_start == NULL) { - dlftbl->num_actors--; - } - else { - dlftbl->num_actors--; - actor_free_check(dlftbl, actor->npc_id); - } - - return next_actor; + return next_actor; } extern ACTOR* Actor_info_name_search_sub(ACTOR* actor, s16 name) { - while (actor != NULL) { - if (actor->id == name) { - return actor; + while (actor != NULL) { + if (actor->id == name) { + return actor; + } + + actor = actor->next_actor; } - actor = actor->next_actor; - } - - return actor; + return actor; } extern ACTOR* Actor_info_name_search(Actor_info* actor_info, s16 name, int part) { - ACTOR* actor = actor_info->list[part].actor; + ACTOR* actor = actor_info->list[part].actor; - if (actor != NULL) { - return Actor_info_name_search_sub(actor, name); - } + if (actor != NULL) { + return Actor_info_name_search_sub(actor, name); + } - return NULL; + return NULL; } extern ACTOR* Actor_info_fgName_search_sub(ACTOR* actor, mActor_name_t fgName) { - while (actor != NULL) { - if (actor->npc_id == fgName) { - return actor; + while (actor != NULL) { + if (actor->npc_id == fgName) { + return actor; + } + + actor = actor->next_actor; } - actor = actor->next_actor; - } - - return actor; + return actor; } extern ACTOR* Actor_info_fgName_search(Actor_info* actor_info, mActor_name_t fgName, int part) { - ACTOR* actor = actor_info->list[part].actor; + ACTOR* actor = actor_info->list[part].actor; - if (actor != NULL) { - return Actor_info_fgName_search_sub(actor, fgName); - } + if (actor != NULL) { + return Actor_info_fgName_search_sub(actor, fgName); + } - return NULL; + return NULL; } extern Gfx* HiliteReflect_new(xyz_t* pos, xyz_t* eye, xyz_t* light_direction, GRAPH* graph, Gfx* gfx, Hilite** hilite) { - static Mtx work_view_matrix; + static Mtx work_view_matrix; - LookAt* lookat = GRAPH_ALLOC_TYPE(graph, LookAt, 1); - int pos_eye_equal = FALSE; - f32 eye_x = eye->x; + LookAt* lookat = GRAPH_ALLOC_TYPE(graph, LookAt, 1); + int pos_eye_equal = FALSE; + f32 eye_x = eye->x; - if (eye_x == pos->x && eye->z == pos->z) { - pos_eye_equal = TRUE; - } + if (eye_x == pos->x && eye->z == pos->z) { + pos_eye_equal = TRUE; + } - if (pos_eye_equal) { - eye_x = 0.001f + eye_x; - } + if (pos_eye_equal) { + eye_x = 0.001f + eye_x; + } - *hilite = GRAPH_ALLOC_TYPE(graph, Hilite, 1); - guLookAtHilite( - &work_view_matrix, - lookat, - *hilite, - eye_x, eye->y, eye->z, - pos->x, pos->y, pos->z, - 0.0f, 1.0f, 0.0f, - light_direction->x, light_direction->y, light_direction->z, - light_direction->x, light_direction->y, light_direction->z, - 16, 16 - ); + *hilite = GRAPH_ALLOC_TYPE(graph, Hilite, 1); + guLookAtHilite(&work_view_matrix, lookat, *hilite, eye_x, eye->y, eye->z, pos->x, pos->y, pos->z, 0.0f, 1.0f, 0.0f, + light_direction->x, light_direction->y, light_direction->z, light_direction->x, light_direction->y, + light_direction->z, 16, 16); - gSPLookAt(gfx++, lookat); - gDPPipeSync(gfx++); - gDPSetTileSize(gfx++, 1, (*hilite)->h.x1, (*hilite)->h.y1, (*hilite)->h.x1 + 60, (*hilite)->h.y1 + 60); + gSPLookAt(gfx++, lookat); + gDPPipeSync(gfx++); + gDPSetTileSize(gfx++, 1, (*hilite)->h.x1, (*hilite)->h.y1, (*hilite)->h.x1 + 60, (*hilite)->h.y1 + 60); - return gfx; + return gfx; } extern Hilite* HiliteReflect_init(xyz_t* pos, xyz_t* eye, xyz_t* light_direction, GRAPH* graph) { - Hilite* hilite; - - OPEN_DISP(graph); + Hilite* hilite; - SET_POLY_OPA_DISP(HiliteReflect_new(pos, eye, light_direction, graph, NOW_POLY_OPA_DISP, &hilite)); + OPEN_DISP(graph); - CLOSE_DISP(graph); + SET_POLY_OPA_DISP(HiliteReflect_new(pos, eye, light_direction, graph, NOW_POLY_OPA_DISP, &hilite)); - return hilite; + CLOSE_DISP(graph); + + return hilite; } extern Hilite* HiliteReflect_xlu_init(xyz_t* pos, xyz_t* eye, xyz_t* light_direction, GRAPH* graph) { - Hilite* hilite; - - OPEN_DISP(graph); + Hilite* hilite; - SET_POLY_XLU_DISP(HiliteReflect_new(pos, eye, light_direction, graph, NOW_POLY_XLU_DISP, &hilite)); + OPEN_DISP(graph); - CLOSE_DISP(graph); + SET_POLY_XLU_DISP(HiliteReflect_new(pos, eye, light_direction, graph, NOW_POLY_XLU_DISP, &hilite)); - return hilite; + CLOSE_DISP(graph); + + return hilite; } extern void Setpos_HiliteReflect_init(xyz_t* pos, GAME_PLAY* play) { - Kankyo* kankyo = &play->kankyo; - xyz_t sun_pos; + Kankyo* kankyo = &play->kankyo; + xyz_t sun_pos; - sun_pos.x = (int)kankyo->sun_light.lights.diffuse.x; - sun_pos.y = (int)kankyo->sun_light.lights.diffuse.y; - sun_pos.z = (int)kankyo->sun_light.lights.diffuse.z; + sun_pos.x = (int)kankyo->sun_light.lights.diffuse.x; + sun_pos.y = (int)kankyo->sun_light.lights.diffuse.y; + sun_pos.z = (int)kankyo->sun_light.lights.diffuse.z; - HiliteReflect_init(pos, &play->view.eye, &sun_pos, play->game.graph); + HiliteReflect_init(pos, &play->view.eye, &sun_pos, play->game.graph); } extern void Setpos_HiliteReflect_xlu_init(xyz_t* pos, GAME_PLAY* play) { - Kankyo* kankyo = &play->kankyo; - xyz_t sun_pos; + Kankyo* kankyo = &play->kankyo; + xyz_t sun_pos; - sun_pos.x = (int)kankyo->sun_light.lights.diffuse.x; - sun_pos.y = (int)kankyo->sun_light.lights.diffuse.y; - sun_pos.z = (int)kankyo->sun_light.lights.diffuse.z; + sun_pos.x = (int)kankyo->sun_light.lights.diffuse.x; + sun_pos.y = (int)kankyo->sun_light.lights.diffuse.y; + sun_pos.z = (int)kankyo->sun_light.lights.diffuse.z; - HiliteReflect_xlu_init(pos, &play->view.eye, &sun_pos, play->game.graph); + HiliteReflect_xlu_init(pos, &play->view.eye, &sun_pos, play->game.graph); } diff --git a/src/m_actor_shadow.c b/src/m_actor_shadow.c index 0a955160..ce997b13 100644 --- a/src/m_actor_shadow.c +++ b/src/m_actor_shadow.c @@ -6,12 +6,11 @@ #include "sys_matrix.h" #include "m_lib.h" #include "m_lights.h" - +#include "libultra/libultra.h" extern Gfx ef_shadow_out_modelT[]; extern Gfx ef_shadow_in_modelT[]; - int mActorShadow_OperateScrollLimit(int value, int step, int limit) { if (step != 0) { if (step > 0) { @@ -29,11 +28,10 @@ int mActorShadow_OperateScrollLimit(int value, int step, int limit) { return value; } -Gfx* mActorShadow_TileScroll2(u32* x1, u32* y1, int step1, int step2, int limit1, int limit2, int width1, -int height1, u32* x2, u32* y2, int step3, int step4, int limit3, int limit4, -int width2, int height2, GAME* game){ +Gfx* mActorShadow_TileScroll2(u32* x1, u32* y1, int step1, int step2, int limit1, int limit2, int width1, int height1, + u32* x2, u32* y2, int step3, int step4, int limit3, int limit4, int width2, int height2, + GAME* game) { - *x1 = mActorShadow_OperateScrollLimit(*x1, step1, limit1); *y1 = mActorShadow_OperateScrollLimit(*y1, step2, limit2); *x2 = mActorShadow_OperateScrollLimit(*x2, step3, limit3); @@ -42,7 +40,6 @@ int width2, int height2, GAME* game){ return two_tex_scroll(game->graph, 0, *x1, *y1, width1, height1, 1, *x2, *y2, width2, height2); } - void mActorShadow_AdjustRate(f32* rate) { if (*rate < 0.0f) { *rate = 0.0f; @@ -51,43 +48,42 @@ void mActorShadow_AdjustRate(f32* rate) { } } -void mActorShadow_GetTimeAngleY_TimeAlpha(Shadow_Info* shadow, GAME_PLAY* play){ +void mActorShadow_GetTimeAngleY_TimeAlpha(Shadow_Info* shadow, GAME_PLAY* play) { f32 timef; int timesec = Common_Get(time.now_sec); shadow->unk1C = play->kankyo.shadow_alpha; // Between 4 a.m and 8 p.m - if((timesec >= 14400) && ( timesec < 72000)){ + if ((timesec >= 14400) && (timesec < 72000)) { timef = (timesec - 14400) / 57600.0f; - } //Between 12 a.m and 4 a.m - else if (timesec < 14400){ + } // Between 12 a.m and 4 a.m + else if (timesec < 14400) { timef = 0.5f + timesec / 28800.0f; } // Between 8 p.m and 12 a.m - else{ - timef = (timesec - 72000)/ 28800.0f; + else { + timef = (timesec - 72000) / 28800.0f; } - shadow->unk26 = 0x8000 - ((s16)(16384.0f * timef) + 0x6000); + shadow->unk26 = 0x8000 - ((s16)(16384.0f * timef) + 0x6000); } - -void mActorShadow_GetGroundAverageAngle(Shadow_Info* shadow){ +void mActorShadow_GetGroundAverageAngle(Shadow_Info* shadow) { static xyz_t angle_range_table[4] = { { 10.0f, 0.0f, 10.0f }, { 10.0f, 0.0f, -10.0f }, { -10.0f, 0.0f, 10.0f }, { -10.0f, 0.0f, -10.0f }, }; - + int x = 0; int y = 0; int z = 0; int i; - + for (i = 0; i < 4; i++) { xyz_t pos = shadow->position; - s_xyz sangle = {0, 0, 0}; - + s_xyz sangle = { 0, 0, 0 }; + pos.x += angle_range_table[i].x; pos.y += angle_range_table[i].y; pos.z += angle_range_table[i].z; @@ -98,7 +94,7 @@ void mActorShadow_GetGroundAverageAngle(Shadow_Info* shadow){ y += sangle.y; z += sangle.z; } - + shadow->unk20 = x >> 2; shadow->unk22 = y >> 2; shadow->unk24 = z >> 2; @@ -107,16 +103,16 @@ void mActorShadow_GetGroundAverageAngle(Shadow_Info* shadow){ void mActorShadow_GetDistanceRate(Shadow_Info* shadow, f32 rate) { f32 xcalc; f32 disty = shadow->position.y - shadow->groundY; - + disty = disty >= 0.0f ? disty : -disty; xcalc = rate + 100.0f; - if (disty > xcalc){ + if (disty > xcalc) { shadow->unk14 = 0.600000023842f; shadow->unk18 = 0; return; } - + xcalc = (xcalc - disty) / xcalc; shadow->unk14 = xcalc * 0.399999976158f + 0.6f; shadow->unk18 = xcalc; @@ -124,8 +120,8 @@ void mActorShadow_GetDistanceRate(Shadow_Info* shadow, f32 rate) { f32 mActorShadow_GetAbsBigger(f32 a, f32 b) { a = a >= 0.0f ? a : -a; b = b >= 0.0f ? b : -b; - - if(a > b){ + + if (a > b) { return a; } return b; @@ -137,7 +133,7 @@ void mActorShadow_RadiusScaleRate(ACTOR* actor, Shadow_Info* shadow) { } void mActorShadow_GetShadowTopPos_GetSlideS(Shadow_Info* shadow) { - + xyz_t wpos; xyz_t base; f32 bg_y; @@ -147,7 +143,7 @@ void mActorShadow_GetShadowTopPos_GetSlideS(Shadow_Info* shadow) { base.x = 0.0f; base.y = 0.0f; base.z = -40.0f; - sMath_RotateY(&base, shadow->unk26 * (9.58738019108e-05f)); + sMath_RotateY(&base, shadow->unk26 * (9.58738019108e-05f)); wpos.x = shadow->position.x + base.x; wpos.y = shadow->position.y + base.y; wpos.z = shadow->position.z + base.z; @@ -161,29 +157,27 @@ void mActorShadow_GetShadowTopPos_GetSlideS(Shadow_Info* shadow) { shadow->unk34 = 0; } -Gfx* mActorShadow_SetTexScroll(ACTOR* actor, Shadow_Info* shadow, GAME* game){ - +Gfx* mActorShadow_SetTexScroll(ACTOR* actor, Shadow_Info* shadow, GAME* game) { + u32 y1 = 0; u32 x1 = 0; u32 y2 = 0; int step; - - if(actor->shape_info.unk_20 < shadow->unk34){ + + if (actor->shape_info.unk_20 < shadow->unk34) { step = 0xD; - } - else if(actor->shape_info.unk_20 > shadow->unk34){ + } else if (actor->shape_info.unk_20 > shadow->unk34) { step = -0xD; - } - else{ + } else { step = 0; } - mActorShadow_TileScroll2(&x1, &y1, 0, 0, 0, 0, 0x20, 0x10, (u32*)&actor->shape_info.unk_20, &y2, step, 0, shadow->unk34, 0, 0x20, 0x10, game); + mActorShadow_TileScroll2(&x1, &y1, 0, 0, 0, 0, 0x20, 0x10, (u32*)&actor->shape_info.unk_20, &y2, step, 0, + shadow->unk34, 0, 0x20, 0x10, game); } - void mActorShadow_GetLastAlphaScale(f32* scale, u8* alpha, ACTOR* actor, Shadow_Info* shadow) { - + f32 alph = shadow->unk1C * shadow->unk18 * actor->shape_info.shadow_alpha_change_rate * 0.75f; *scale = shadow->unk10 * shadow->unk14 * actor->shape_info.shadow_size_change_rate; @@ -194,7 +188,6 @@ void mActorShadow_GetLastAlphaScale(f32* scale, u8* alpha, ACTOR* actor, Shadow_ *alpha = alph; } - void mActorShadow_DrawActorShadow(ACTOR* actor, Shadow_Info* shadow, GAME_PLAY* play, int id, xyz_t ofs, f32 rad) { f32 x, y, z; f32 y_adjust; @@ -206,17 +199,17 @@ void mActorShadow_DrawActorShadow(ACTOR* actor, Shadow_Info* shadow, GAME_PLAY* GRAPH* graph; GAME* game = (GAME*)play; - scene = Save_Get(scene_no); - - mActorShadow_GetLastAlphaScale(&scale, &alpha, actor, shadow); + + mActorShadow_GetLastAlphaScale(&scale, &alpha, actor, shadow); graph = game->graph; _texture_z_light_fog_prim_shadow(graph); OPEN_DISP(graph); - - y_adjust = (scene == 19 || scene == 27 || scene == 28 || scene == 34) ? 0.5f : - ((scene == 15 || scene == 16 || scene == 49) ? 0.6f : 2.0f); + + y_adjust = (scene == 19 || scene == 27 || scene == 28 || scene == 34) + ? 0.5f + : ((scene == 15 || scene == 16 || scene == 49) ? 0.6f : 2.0f); switch (actor->shape_info.force_shadow_position) { case 1: @@ -243,7 +236,7 @@ void mActorShadow_DrawActorShadow(ACTOR* actor, Shadow_Info* shadow, GAME_PLAY* Matrix_RotateX(shadow->unk20, 1); break; } - + if ((shadow->kind == 0) && (id == 0)) { Matrix_RotateY(shadow->unk26, 1); } @@ -263,13 +256,13 @@ void mActorShadow_DrawActorShadow(ACTOR* actor, Shadow_Info* shadow, GAME_PLAY* } break; } - + gSPMatrix(NEXT_SHADOW_DISP, _Matrix_to_Mtx_new(game->graph), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); mEnv_GetShadowPrimColor_Light(&r, &g, &b, game); gDPSetPrimColor(NEXT_SHADOW_DISP, 0, 0xFF, r, g, b, (u8)alpha); if ((shadow->kind == 0) && (id == 0)) { - texscroll = mActorShadow_SetTexScroll(actor, shadow, game); + texscroll = mActorShadow_SetTexScroll(actor, shadow, game); if (texscroll != NULL) { gSPSegment(NEXT_SHADOW_DISP, 0x08, texscroll); gSPDisplayList(NEXT_SHADOW_DISP, ef_shadow_out_modelT); @@ -277,17 +270,15 @@ void mActorShadow_DrawActorShadow(ACTOR* actor, Shadow_Info* shadow, GAME_PLAY* } else { gSPDisplayList(NEXT_SHADOW_DISP, ef_shadow_in_modelT); } - + CLOSE_DISP(graph); - } -void mActorShadow_GetShadowPosition(ACTOR* actor, xyz_t* position){ +void mActorShadow_GetShadowPosition(ACTOR* actor, xyz_t* position) { - if(actor->shape_info.shadow_position != NULL){ + if (actor->shape_info.shadow_position != NULL) { *position = *actor->shape_info.shadow_position; - } - else { + } else { *position = actor->world.position; } } @@ -300,12 +291,12 @@ int mActorShadow_GetShadowKind(void) { } } -f32 mAc_GetShadowGroundY_NoneForce(const Shadow_Info* shadow){ - f32 res = mCoBG_GetShadowBgY_AngleS_FromWpos(0.0f, NULL, shadow->position); - return res; +f32 mAc_GetShadowGroundY_NoneForce(const Shadow_Info* shadow) { + f32 res = mCoBG_GetShadowBgY_AngleS_FromWpos(0.0f, NULL, shadow->position); + return res; } -f32 mAc_GetShadowGroundY_Force(const Shadow_Info* shadow){ +f32 mAc_GetShadowGroundY_Force(const Shadow_Info* shadow) { return mCoBG_GetBgY_OnlyCenter_FromWpos2(shadow->position, 0.0f); } @@ -319,11 +310,10 @@ void mAc_DecideShadowRadius_IamFish(Shadow_Info* shadow, ACTOR* actor, f32* radi *radius = (actor->shape_info.shadow_size_z / 19.0f) * 0.018f; } -void mAc_ActorShadowDraw_ShadowDrawFlagOff(ACTOR* actor, GAME_PLAY* play, int arg2, xyz_t arg3, f32 arg6){ - +void mAc_ActorShadowDraw_ShadowDrawFlagOff(ACTOR* actor, GAME_PLAY* play, int arg2, xyz_t arg3, f32 arg6) { } -void mAc_ActorShadowDraw_ShadowDrawFlagOn(ACTOR* actor, GAME_PLAY* play, int proc, xyz_t pos, f32 rate){ +void mAc_ActorShadowDraw_ShadowDrawFlagOn(ACTOR* actor, GAME_PLAY* play, int proc, xyz_t pos, f32 rate) { static void (*set_raius_proc[])(Shadow_Info*, ACTOR*, f32*) = { mAc_DecideShadowRadius_IamNotFish, mAc_DecideShadowRadius_IamFish, @@ -345,7 +335,7 @@ void mAc_ActorShadowDraw_ShadowDrawFlagOn(ACTOR* actor, GAME_PLAY* play, int pro ground_y_proc = actor->shape_info.force_shadow_position & 1; shadow.groundY = get_ground_y_proc[ground_y_proc](&shadow); - + mActorShadow_GetTimeAngleY_TimeAlpha(&shadow, play); mActorShadow_GetGroundAverageAngle(&shadow); mActorShadow_GetDistanceRate(&shadow, rate); @@ -358,10 +348,10 @@ void mAc_ActorShadowDraw_ShadowDrawFlagOn(ACTOR* actor, GAME_PLAY* play, int pro void mAc_ActorShadowDraw(ACTOR* actor, GAME_PLAY* play, int arg2, xyz_t arg3, f32 arg6) { static void (*shadwo_draw_proc[])(ACTOR* actor, GAME_PLAY* play, int arg2, xyz_t arg3, f32 arg6) = { - mAc_ActorShadowDraw_ShadowDrawFlagOff, - mAc_ActorShadowDraw_ShadowDrawFlagOn, -}; - + mAc_ActorShadowDraw_ShadowDrawFlagOff, + mAc_ActorShadowDraw_ShadowDrawFlagOn, + }; + if (actor->id == 0x4A) { mActorShadow_UnSetForceShadowPos(actor); actor->shape_info.shadow_position = &actor->world.position; @@ -373,7 +363,6 @@ void mAc_ActorShadowDraw(ACTOR* actor, GAME_PLAY* play, int arg2, xyz_t arg3, f3 xyz_t mActorShadow_offset0 = { 0.0f, 0.0f, 0.0f }; - void mActorShadow_SetForceShadowPos(ACTOR* actor, xyz_t* pos) { actor->shape_info.force_shadow_position = 1; actor->shape_info.shadow_position = pos; @@ -384,28 +373,26 @@ void mActorShadow_UnSetForceShadowPos(ACTOR* actor) { actor->shape_info.shadow_position = &actor->world.position; } - -void mAc_NormalActorShadow(ACTOR* actor, GAME_PLAY* play, f32 rad){ +void mAc_NormalActorShadow(ACTOR* actor, GAME_PLAY* play, f32 rad) { mAc_ActorShadowDraw(actor, play, 0, mActorShadow_offset0, rad); } -void mAc_UnagiActorShadow(ACTOR* actor, GAME_PLAY* play, xyz_t pos){ +void mAc_UnagiActorShadow(ACTOR* actor, GAME_PLAY* play, xyz_t pos) { mAc_ActorShadowDraw(actor, play, 1, pos, 1.0f); } -void mAc_ActorShadowCircle(ACTOR* actor, LightsN* lights, GAME_PLAY* play){ +void mAc_ActorShadowCircle(ACTOR* actor, LightsN* lights, GAME_PLAY* play) { mAc_ActorShadowDraw(actor, play, 0, mActorShadow_offset0, 1.0f); } -void mAc_ActorShadowEllipse(ACTOR* actor, LightsN* lights, GAME_PLAY* play){ - +void mAc_ActorShadowEllipse(ACTOR* actor, LightsN* lights, GAME_PLAY* play) { + static xyz_t tunekiti_offset = { 0.0f, 1.0f, 0.0f }; - - if(actor->id == 0x79){ - mAc_ActorShadowDraw(actor, play, 0, tunekiti_offset, 1.0f); - - } - else{ + + if (actor->id == 0x79) { + mAc_ActorShadowDraw(actor, play, 0, tunekiti_offset, 1.0f); + + } else { mAc_ActorShadowDraw(actor, play, 0, mActorShadow_offset0, 1.0f); } -} \ No newline at end of file +} diff --git a/src/m_bgm.c b/src/m_bgm.c index e696f64d..daeee328 100644 --- a/src/m_bgm.c +++ b/src/m_bgm.c @@ -19,63 +19,63 @@ #define mBGMPs_FLAG_LOST (1 << 8) enum { - mBGM_KATEGORIE_FANFARE, - mBGM_KATEGORIE_WIPE, - mBGM_KATEGORIE_QUIET, - mBGM_KATEGORIE_DEMO, - mBGM_KATEGORIE_HAPPENING, - mBGM_KATEGORIE_QUIETROOM, - mBGM_KATEGORIE_ROOM, - mBGM_KATEGORIE_TIME, - mBGM_KATEGORIE_QUIETFIELD, - mBGM_KATEGORIE_FIELDSUDDENEV, - mBGM_KATEGORIE_FIELDSCHEDEV, - mBGM_KATEGORIE_FIELDNORM, - - mBGM_KATEGORIE_NUM + mBGM_KATEGORIE_FANFARE, + mBGM_KATEGORIE_WIPE, + mBGM_KATEGORIE_QUIET, + mBGM_KATEGORIE_DEMO, + mBGM_KATEGORIE_HAPPENING, + mBGM_KATEGORIE_QUIETROOM, + mBGM_KATEGORIE_ROOM, + mBGM_KATEGORIE_TIME, + mBGM_KATEGORIE_QUIETFIELD, + mBGM_KATEGORIE_FIELDSUDDENEV, + mBGM_KATEGORIE_FIELDSCHEDEV, + mBGM_KATEGORIE_FIELDNORM, + + mBGM_KATEGORIE_NUM }; enum { - mBGMForce_INFORM_0, - mBGMForce_INFORM_1, - mBGMForce_INFORM_2, - mBGMForce_INFORM_3, - mBGMForce_INFORM_4, - mBGMForce_INFORM_5, - mBGMForce_INFORM_6, - mBGMForce_INFORM_7, + mBGMForce_INFORM_0, + mBGMForce_INFORM_1, + mBGMForce_INFORM_2, + mBGMForce_INFORM_3, + mBGMForce_INFORM_4, + mBGMForce_INFORM_5, + mBGMForce_INFORM_6, + mBGMForce_INFORM_7, - mBGMForce_INFORM_NUM + mBGMForce_INFORM_NUM }; typedef struct bgm_elem_s { - u8 bgm_num; - u8 _pad0; - u16 _pad1; - u16 stop_type0; - u16 stop_type1; + u8 bgm_num; + u8 _pad0; + u16 _pad1; + u16 stop_type0; + u16 stop_type1; } mBGMElem; typedef struct bgm_clock_s { - u32 now; - u32 before; + u32 now; + u32 before; } mBGMClock; typedef struct bgm_demo_s { - mBGMElem elem; - u8 make_flag; - u8 delete_flag; - u16 _pad; + mBGMElem elem; + u8 make_flag; + u8 delete_flag; + u16 _pad; } mBGMDemo; typedef struct bgm_room_s { - mBGMElem elem; - u8 make_flag; - u8 delete_flag; - u8 shop_fadeout_flag; - u8 _pad; - u32 shop_close_time0; - u32 shop_close_time1; + mBGMElem elem; + u8 make_flag; + u8 delete_flag; + u8 shop_fadeout_flag; + u8 _pad; + u32 shop_close_time0; + u32 shop_close_time1; } mBGMRoom; typedef struct bgm_time_s mBGMTime; @@ -83,672 +83,602 @@ typedef struct bgm_time_s mBGMTime; typedef void (*mBGMTime_MOVE_PROC)(mBGMTime*, GAME*); struct bgm_time_s { - mBGMTime_MOVE_PROC move_proc; - u8 new_year_ev_flag; - u8 _pad; + mBGMTime_MOVE_PROC move_proc; + u8 new_year_ev_flag; + u8 _pad; }; typedef struct bgm_field_sudden_ev_s { - u32 flag; - u32 old_flag; + u32 flag; + u32 old_flag; } mBGMFieldSuddenEv; typedef struct bgm_field_schedule_ev_info_s { - u32 flag; - int attr; - int old_attr; + u32 flag; + int attr; + int old_attr; } mBGMFieldSchedEv_Info; typedef struct bgm_field_schedule_ev_s { - mBGMFieldSchedEv_Info info[24]; // every hour has its own info + mBGMFieldSchedEv_Info info[24]; // every hour has its own info } mBGMFieldSchedEv; typedef struct bgm_field_normal_s { - mBGMElem elem; - u8 make_flag; - u8 delete_flag; - u16 _pad; + mBGMElem elem; + u8 make_flag; + u8 delete_flag; + u16 _pad; } mBGMFieldNorm; typedef struct bgm_ps_s { - mBGMElem elem; - int kategorie; - s16 counter; - u16 cf_flags; - u8 priority; - u8 _pad; + mBGMElem elem; + int kategorie; + s16 counter; + u16 cf_flags; + u8 priority; + u8 _pad; } mBGMPs; typedef struct bgm_ps_comp_stop_s { - u8 req_flag; - u16 type; - u8 _pad; + u8 req_flag; + u16 type; + u8 _pad; } mBGMPsComp_Stop; typedef struct bgm_ps_comp_start_s { - u8 req_flag; - u8 bgm_num; - u8 flags; - u8 _pad; + u8 req_flag; + u8 bgm_num; + u8 flags; + u8 _pad; } mBGMPsComp_Start; typedef struct bgm_ps_comp_volume_s { - f32 main_volume; - u16 main_volume_move_ctr; - u8 main_req_flag; - u8 _pad0; + f32 main_volume; + u16 main_volume_move_ctr; + u8 main_req_flag; + u8 _pad0; - f32 ps_volume; - u16 ps_volume_move_ctr; - u8 ps_req_flag; - u8 _pad1; + f32 ps_volume; + u16 ps_volume_move_ctr; + u8 ps_req_flag; + u8 _pad1; - f32 fishing_volume; - u16 fishing_volume_move_ctr; - u8 fishing_req_flag; - u8 _pad2; + f32 fishing_volume; + u16 fishing_volume_move_ctr; + u8 fishing_req_flag; + u8 _pad2; - f32 collect_insects_volume; - u16 collect_insects_volume_move_ctr; - u8 collect_insects_req_flag; - u8 _pad3; + f32 collect_insects_volume; + u16 collect_insects_volume_move_ctr; + u8 collect_insects_req_flag; + u8 _pad3; - f32 talk_volume; - u8 talk_req_flag; - u8 _pad4; + f32 talk_volume; + u8 talk_req_flag; + u8 _pad4; - f32 boat_volume; - u8 boat_req_flag; - u8 _pad5; + f32 boat_volume; + u8 boat_req_flag; + u8 _pad5; - f32 pause_volume; - u16 pause_volume_move_ctr; - u8 pause_req_flag; - u8 _pad6; + f32 pause_volume; + u16 pause_volume_move_ctr; + u8 pause_req_flag; + u8 _pad6; } mBGMPsComp_Volume; typedef struct bgm_ps_comp_pause_s { - u8 req_flag; - u8 mode; - u16 _pad; + u8 req_flag; + u8 mode; + u16 _pad; } mBGMPsComp_Pause; typedef struct bgm_ps_comp_md_player_pos_s { - u8 req_flag; - u8 make_flag; - u8 delete_flag; - u8 move_flag; - xyz_t pos; - u16 angle; - u16 md_type_no; - u32 ongen_no; + u8 req_flag; + u8 make_flag; + u8 delete_flag; + u8 move_flag; + xyz_t pos; + u16 angle; + u16 md_type_no; + u32 ongen_no; } mBGMPsComp_MDPlayerPos; #define mBGM_BGMPs_NUM 14 typedef struct bgm_ps_comp_arm_s { - u8 req_flag; - u8 arm_state; - u16 _pad; + u8 req_flag; + u8 arm_state; + u16 _pad; } mBGMPsComp_Arm; typedef struct bgm_ps_comp_museum_s { - u8 req_flag; - u8 type; - u16 _pad; + u8 req_flag; + u8 type; + u16 _pad; } mBGMPsComp_Museum; typedef struct bgm_ps_comp_s { - mBGMPs ps[mBGM_BGMPs_NUM]; - int ps_num; - int fishing_state; - int collect_insects_state; - int talk_state; - int boat_state; - int pause_state; - mBGMPsComp_Stop stop; - mBGMPsComp_Start start; - mBGMPsComp_Volume volume; - mBGMPsComp_Pause pause; - mBGMPsComp_MDPlayerPos md; - mBGMPsComp_Arm arm; - mBGMPsComp_Museum museum; + mBGMPs ps[mBGM_BGMPs_NUM]; + int ps_num; + int fishing_state; + int collect_insects_state; + int talk_state; + int boat_state; + int pause_state; + mBGMPsComp_Stop stop; + mBGMPsComp_Start start; + mBGMPsComp_Volume volume; + mBGMPsComp_Pause pause; + mBGMPsComp_MDPlayerPos md; + mBGMPsComp_Arm arm; + mBGMPsComp_Museum museum; } mBGMPsComp; typedef struct bgm_force_s { - int inform; - u8 flag; - int room_nonstop; + int inform; + u8 flag; + int room_nonstop; } mBGMForce; typedef struct bgm_s { - mBGMClock clock; - mBGMDemo demo; - mBGMRoom room; - mBGMTime time; - mBGMFieldSuddenEv field_sudden_ev; - mBGMFieldSchedEv field_sched_ev; - mBGMFieldNorm field_norm; - mBGMPsComp ps_comp; - mBGMForce force; + mBGMClock clock; + mBGMDemo demo; + mBGMRoom room; + mBGMTime time; + mBGMFieldSuddenEv field_sudden_ev; + mBGMFieldSchedEv field_sched_ev; + mBGMFieldNorm field_norm; + mBGMPsComp ps_comp; + mBGMForce force; } mBGM; static mBGM M_bgm; static int mBGM_check_MD(u8 bgm_num) { - int res = FALSE; + int res = FALSE; - if ((bgm_num >= 0x80 && bgm_num <= 0xB3) || (bgm_num >= 0xB4 && bgm_num <= 0xB6)) { - res = TRUE; - } + if ((bgm_num >= 0x80 && bgm_num <= 0xB3) || (bgm_num >= 0xB4 && bgm_num <= 0xB6)) { + res = TRUE; + } - return res; + return res; } static int mBGM_check_ignore_talk_volume(u8 bgm_num) { - /* TODO: defines/enums for these ids */ - static const u8 bgm_data[44] = { - 40, - 73, - 68, - 74, - 76, - 75, - 49, - 50, - 71, - 64, - 66, - 78, - 122, - 125, - 92, - 93, - 94, - 95, - 96, - 97, - 98, - 99, - 100, - 101, - 102, - 103, - 104, - 105, - 106, - 107, - 108, - 109, - 110, - 111, - 112, - 113, - 114, - 115, - 116, - 117, - 118, - 119, - 120, - 121 - }; + /* TODO: defines/enums for these ids */ + static const u8 bgm_data[44] = { 40, 73, 68, 74, 76, 75, 49, 50, 71, 64, 66, 78, 122, 125, 92, + 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, + 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121 }; - const u8* bgm_data_p = bgm_data; - int i; + const u8* bgm_data_p = bgm_data; + int i; - for (i = 0; i < ARRAY_COUNT(bgm_data); i++) { - if (bgm_num == *bgm_data_p) { - return TRUE; + for (i = 0; i < ARRAY_COUNT(bgm_data); i++) { + if (bgm_num == *bgm_data_p) { + return TRUE; + } + + bgm_data_p++; } - bgm_data_p++; - } - - return FALSE; + return FALSE; } static int mBGM_check_ignore_collect_insects_volume(u8 bgm_num) { - if (bgm_num == 40) { - return TRUE; - } + if (bgm_num == 40) { + return TRUE; + } - return FALSE; + return FALSE; } static mBGMElem_default_set(mBGMElem* elem) { - static mBGMElem default_data = { 127, 0, 0, 0x168, 0x168 }; + static mBGMElem default_data = { 127, 0, 0, 0x168, 0x168 }; - bcopy(&default_data, elem, sizeof(mBGMElem)); + bcopy(&default_data, elem, sizeof(mBGMElem)); } /* mBGMClock */ -#define mBGMClock_CHK_ss (((1 << 6) - 1) << 0) -#define mBGMClock_CHK_mm (((1 << 6) - 1) << 6) +#define mBGMClock_CHK_ss (((1 << 6) - 1) << 0) +#define mBGMClock_CHK_mm (((1 << 6) - 1) << 6) #define mBGMClock_CHK_hh (((1 << 5) - 1) << 12) #define mBGMClock_CHK_DD (((1 << 5) - 1) << 17) #define mBGMClock_CHK_MM (((1 << 4) - 1) << 22) static int mBGMClock_after_time_check(mBGMClock* clock, u32 check_time, u32 check_mask) { - u32 t_now = clock->now & check_mask; - u32 t_check = check_time & check_mask; + u32 t_now = clock->now & check_mask; + u32 t_check = check_time & check_mask; - if (t_now >= t_check) { - return TRUE; - } + if (t_now >= t_check) { + return TRUE; + } - return FALSE; + return FALSE; } static int mBGMClock_over_time_check(mBGMClock* clock, u32 check_time, u32 check_mask) { - u32 t_now = clock->now & check_mask; - u32 t_before = clock->before & check_mask; - u32 t_check = check_time & check_mask; - - if (t_now >= t_before) { - int res = FALSE; - if (t_check > t_before && t_check <= t_now) { - res = TRUE; + u32 t_now = clock->now & check_mask; + u32 t_before = clock->before & check_mask; + u32 t_check = check_time & check_mask; + + if (t_now >= t_before) { + int res = FALSE; + if (t_check > t_before && t_check <= t_now) { + res = TRUE; + } + + return res; + } else { + int res = FALSE; + if (t_check > t_before || t_check <= t_now) { + res = TRUE; + } + + return res; } - - return res; - } - else { - int res = FALSE; - if (t_check > t_before || t_check <= t_now) { - res = TRUE; - } - - return res; - } } static int mBGMClock_range_time_check(mBGMClock* clock, u32 check_time0, u32 check_time1, u32 check_mask) { - u32 t_now = clock->now & check_mask; - u32 t_check0 = check_time0 & check_mask; - u32 t_check1 = check_time1 & check_mask; - int res; + u32 t_now = clock->now & check_mask; + u32 t_check0 = check_time0 & check_mask; + u32 t_check1 = check_time1 & check_mask; + int res; - if (t_check1 >= t_check0) { - res = FALSE; - if (t_now >= t_check0 && t_now < t_check1) { - res = TRUE; + if (t_check1 >= t_check0) { + res = FALSE; + if (t_now >= t_check0 && t_now < t_check1) { + res = TRUE; + } + + return res; + } else { + res = FALSE; + if (t_now >= t_check0 || t_now < t_check1) { + res = TRUE; + } + + return res; } - - return res; - } - else { - res = FALSE; - if (t_now >= t_check0 || t_now < t_check1) { - res = TRUE; - } - - return res; - } } static void mBGMClock_now_set(mBGMClock* clock) { - clock->before = clock->now; - clock->now = - ((Common_Get(time.rtc_time).month & 0x0F) << 22) | - ((Common_Get(time.rtc_time).day & 0x1F) << 17) | - ((Common_Get(time.rtc_time).hour & 0x1F) << 12) | - ((Common_Get(time.rtc_time).min & 0x3F) << 6) | - ((Common_Get(time.rtc_time).sec & 0x3F) << 0); + clock->before = clock->now; + clock->now = ((Common_Get(time.rtc_time).month & 0x0F) << 22) | ((Common_Get(time.rtc_time).day & 0x1F) << 17) | + ((Common_Get(time.rtc_time).hour & 0x1F) << 12) | ((Common_Get(time.rtc_time).min & 0x3F) << 6) | + ((Common_Get(time.rtc_time).sec & 0x3F) << 0); } static void mBGMClock_move(mBGMClock* clock, GAME* game) { - mBGMClock_now_set(clock); + mBGMClock_now_set(clock); } static void mBGMClock_ct(mBGMClock* clock) { - bzero(clock, sizeof(mBGMClock)); - mBGMClock_now_set(clock); - clock->before = clock->now; + bzero(clock, sizeof(mBGMClock)); + mBGMClock_now_set(clock); + clock->before = clock->now; } /* mBGMDemo */ static void mBGMDemo_make_scene_bgm(mBGMDemo* demo) { - if (demo->elem.bgm_num == 127 && mFI_CheckFieldData()) { - mActor_name_t field_id = mFI_GetFieldId(); - u8 bgm_num; + if (demo->elem.bgm_num == 127 && mFI_CheckFieldData()) { + mActor_name_t field_id = mFI_GetFieldId(); + u8 bgm_num; - switch (field_id) { - case mFI_FIELD_DEMO_STARTDEMO: - case mFI_FIELD_DEMO_STARTDEMO2: - bgm_num = 42; - break; + switch (field_id) { + case mFI_FIELD_DEMO_STARTDEMO: + case mFI_FIELD_DEMO_STARTDEMO2: + bgm_num = 42; + break; - case mFI_FIELD_DEMO_STARTDEMO3: - bgm_num = 123; - break; + case mFI_FIELD_DEMO_STARTDEMO3: + bgm_num = 123; + break; - case mFI_FIELD_DEMO_PLAYERSELECT: - if (Save_Get(scene_no) == SCENE_PLAYERSELECT_SAVE) { - bgm_num = 46; + case mFI_FIELD_DEMO_PLAYERSELECT: + if (Save_Get(scene_no) == SCENE_PLAYERSELECT_SAVE) { + bgm_num = 46; + } else { + bgm_num = 43; + } + break; + + default: + bgm_num = 127; + break; } - else { - bgm_num = 43; + + if (bgm_num != 127) { + mBGMElem_default_set(&demo->elem); + demo->elem.bgm_num = bgm_num; + mBGMPsComp_make_ps_demo(bgm_num, 0x168); } - break; - - default: - bgm_num = 127; - break; } - - if (bgm_num != 127) { - mBGMElem_default_set(&demo->elem); - demo->elem.bgm_num = bgm_num; - mBGMPsComp_make_ps_demo(bgm_num, 0x168); - } - } } static void mBGMDemo_delete_scene_bgm(mBGMDemo* demo) { - if (demo->elem.bgm_num != 127) { - mBGMPsComp_delete_ps_demo(demo->elem.bgm_num, 0x168); - demo->elem.bgm_num = 127; - } + if (demo->elem.bgm_num != 127) { + mBGMPsComp_delete_ps_demo(demo->elem.bgm_num, 0x168); + demo->elem.bgm_num = 127; + } } static void mBGMDemo_move(mBGMDemo* demo, GAME* game) { - if (demo->delete_flag) { - mBGMDemo_delete_scene_bgm(demo); - } + if (demo->delete_flag) { + mBGMDemo_delete_scene_bgm(demo); + } - if (demo->make_flag) { - mBGMDemo_make_scene_bgm(demo); - } + if (demo->make_flag) { + mBGMDemo_make_scene_bgm(demo); + } - demo->make_flag = FALSE; - demo->delete_flag = FALSE; + demo->make_flag = FALSE; + demo->delete_flag = FALSE; } static void mBGMDemo_scene_bgm_make_req() { - M_bgm.demo.make_flag = TRUE; + M_bgm.demo.make_flag = TRUE; } static void mBGMDemo_scene_bgm_delete_req() { - M_bgm.demo.delete_flag = TRUE; + M_bgm.demo.delete_flag = TRUE; } static void mBGMDemo_ct(mBGMDemo* demo) { - bzero(demo, sizeof(mBGMDemo)); - mBGMElem_default_set(&demo->elem); + bzero(demo, sizeof(mBGMDemo)); + mBGMElem_default_set(&demo->elem); } /* mBGMRoom */ static void mBGMRoom_shop_close_time_set(mBGMRoom* room) { - if (mFI_CheckFieldData()) { - mActor_name_t field_id = mFI_GetFieldId(); + if (mFI_CheckFieldData()) { + mActor_name_t field_id = mFI_GetFieldId(); - if ( - field_id == mFI_FIELD_ROOM_SHOP0 || - field_id == mFI_FIELD_ROOM_SHOP1 || - field_id == mFI_FIELD_ROOM_SHOP2 || - field_id == mFI_FIELD_ROOM_SHOP3_1 || - field_id == mFI_FIELD_ROOM_SHOP3_2 - ) { - lbRTC_time_c time; + if (field_id == mFI_FIELD_ROOM_SHOP0 || field_id == mFI_FIELD_ROOM_SHOP1 || field_id == mFI_FIELD_ROOM_SHOP2 || + field_id == mFI_FIELD_ROOM_SHOP3_1 || field_id == mFI_FIELD_ROOM_SHOP3_2) { + lbRTC_time_c time; - bzero(&time, sizeof(lbRTC_time_c)); - time.hour = mSP_GetShopCloseTime_Bgm(); - - lbRTC_Sub_mm(&time, 5); - room->shop_close_time1 = ((time.hour & 0x1F) << 12) | ((time.min & 0x3F) << 6) | ((time.sec & 0x3F) << 0); + bzero(&time, sizeof(lbRTC_time_c)); + time.hour = mSP_GetShopCloseTime_Bgm(); - lbRTC_Sub_ss(&time, 5); - room->shop_close_time0 = ((time.hour & 0x1F) << 12) | ((time.min & 0x3F) << 6) | ((time.sec & 0x3F) << 0); + lbRTC_Sub_mm(&time, 5); + room->shop_close_time1 = ((time.hour & 0x1F) << 12) | ((time.min & 0x3F) << 6) | ((time.sec & 0x3F) << 0); + + lbRTC_Sub_ss(&time, 5); + room->shop_close_time0 = ((time.hour & 0x1F) << 12) | ((time.min & 0x3F) << 6) | ((time.sec & 0x3F) << 0); + } } - } } static u8 mBGMRoom_make_scene_bgm_shop_get(mBGMRoom* room, mActor_name_t field_id) { - u8 bgm_num; + u8 bgm_num; - if ( - mEv_CheckRealArbeit() == FALSE && - mBGMClock_after_time_check(&M_bgm.clock, room->shop_close_time1, mBGMClock_CHK_hh | mBGMClock_CHK_mm | mBGMClock_CHK_ss) - ) { - /* Play 'almost closing' music */ - if (field_id == mFI_FIELD_ROOM_SHOP0) { - bgm_num = 79; + if (mEv_CheckRealArbeit() == FALSE && + mBGMClock_after_time_check(&M_bgm.clock, room->shop_close_time1, + mBGMClock_CHK_hh | mBGMClock_CHK_mm | mBGMClock_CHK_ss)) { + /* Play 'almost closing' music */ + if (field_id == mFI_FIELD_ROOM_SHOP0) { + bgm_num = 79; + } else if (field_id == mFI_FIELD_ROOM_SHOP1) { + bgm_num = 80; + } else if (field_id == mFI_FIELD_ROOM_SHOP2) { + bgm_num = 81; + } else { + bgm_num = 82; + } + } else { + /* Play normal music */ + if (field_id == mFI_FIELD_ROOM_SHOP0) { + bgm_num = 44; + } else if (field_id == mFI_FIELD_ROOM_SHOP1) { + bgm_num = 37; + } else if (field_id == mFI_FIELD_ROOM_SHOP2) { + bgm_num = 38; + } else { + bgm_num = 39; + } } - else if (field_id == mFI_FIELD_ROOM_SHOP1) { - bgm_num = 80; - } - else if (field_id == mFI_FIELD_ROOM_SHOP2) { - bgm_num = 81; - } - else { - bgm_num = 82; - } - } - else { - /* Play normal music */ - if (field_id == mFI_FIELD_ROOM_SHOP0) { - bgm_num = 44; - } - else if (field_id == mFI_FIELD_ROOM_SHOP1) { - bgm_num = 37; - } - else if (field_id == mFI_FIELD_ROOM_SHOP2) { - bgm_num = 38; - } - else { - bgm_num = 39; - } - } - return bgm_num; + return bgm_num; } static void mBGMRoom_make_scene_bgm(mBGMRoom* room) { - if (room->elem.bgm_num == 127 && mFI_CheckFieldData()) { - mActor_name_t field_id = mFI_GetFieldId(); - u8 bgm_num; + if (room->elem.bgm_num == 127 && mFI_CheckFieldData()) { + mActor_name_t field_id = mFI_GetFieldId(); + u8 bgm_num; - switch (field_id) { - case mFI_FIELD_ROOM_SHOP0: - case mFI_FIELD_ROOM_SHOP1: - case mFI_FIELD_ROOM_SHOP2: - case mFI_FIELD_ROOM_SHOP3_1: - case mFI_FIELD_ROOM_SHOP3_2: - bgm_num = mBGMRoom_make_scene_bgm_shop_get(room, field_id); - break; - - case mFI_FIELD_ROOM_BROKER_SHOP: - bgm_num = 25; - break; - - case mFI_FIELD_ROOM_POST_OFFICE: - if (Common_Get(post_girl_npc_type) != 0) { - bgm_num = 62; + switch (field_id) { + case mFI_FIELD_ROOM_SHOP0: + case mFI_FIELD_ROOM_SHOP1: + case mFI_FIELD_ROOM_SHOP2: + case mFI_FIELD_ROOM_SHOP3_1: + case mFI_FIELD_ROOM_SHOP3_2: + bgm_num = mBGMRoom_make_scene_bgm_shop_get(room, field_id); + break; + + case mFI_FIELD_ROOM_BROKER_SHOP: + bgm_num = 25; + break; + + case mFI_FIELD_ROOM_POST_OFFICE: + if (Common_Get(post_girl_npc_type) != 0) { + bgm_num = 62; + } else { + bgm_num = 41; + } + break; + + case mFI_FIELD_ROOM_POLICE_BOX: + bgm_num = 45; + break; + + case mFI_FIELD_ROOM_BUGGY: + bgm_num = 26; + break; + + case mFI_FIELD_ROOM_KAMAKURA: + bgm_num = 77; + break; + + case mFI_FIELD_ROOM_TENT: + bgm_num = 254; + break; + + case mFI_FIELD_ROOM_MUSEUM_ENTRANCE: + case mFI_FIELD_ROOM_MUSEUM_PAINTING: + case mFI_FIELD_ROOM_MUSEUM_FOSSIL: + case mFI_FIELD_ROOM_MUSEUM_INSECT: + case mFI_FIELD_ROOM_MUSEUM_FISH: + bgm_num = 88; + break; + + case mFI_FIELD_ROOM_NEEDLEWORK: + bgm_num = 89; + break; + + case mFI_FIELD_ROOM_LIGHTHOUSE: + bgm_num = 90; + break; + + default: + bgm_num = 127; + break; } - else { - bgm_num = 41; + + if (bgm_num != 127) { + mBGMElem_default_set(&room->elem); + room->elem.bgm_num = bgm_num; + mBGMPsComp_make_ps_room(bgm_num, 0x168); } - break; - - case mFI_FIELD_ROOM_POLICE_BOX: - bgm_num = 45; - break; - - case mFI_FIELD_ROOM_BUGGY: - bgm_num = 26; - break; - - case mFI_FIELD_ROOM_KAMAKURA: - bgm_num = 77; - break; - - case mFI_FIELD_ROOM_TENT: - bgm_num = 254; - break; - - case mFI_FIELD_ROOM_MUSEUM_ENTRANCE: - case mFI_FIELD_ROOM_MUSEUM_PAINTING: - case mFI_FIELD_ROOM_MUSEUM_FOSSIL: - case mFI_FIELD_ROOM_MUSEUM_INSECT: - case mFI_FIELD_ROOM_MUSEUM_FISH: - bgm_num = 88; - break; - - case mFI_FIELD_ROOM_NEEDLEWORK: - bgm_num = 89; - break; - - case mFI_FIELD_ROOM_LIGHTHOUSE: - bgm_num = 90; - break; - - default: - bgm_num = 127; - break; } - - if (bgm_num != 127) { - mBGMElem_default_set(&room->elem); - room->elem.bgm_num = bgm_num; - mBGMPsComp_make_ps_room(bgm_num, 0x168); - } - } } static void mBGMRoom_delete_scene_bgm(mBGMRoom* room) { - if (room->elem.bgm_num != 127) { - mBGMPsComp_delete_ps_room(room->elem.bgm_num, 0x168); - room->elem.bgm_num = 127; - } + if (room->elem.bgm_num != 127) { + mBGMPsComp_delete_ps_room(room->elem.bgm_num, 0x168); + room->elem.bgm_num = 127; + } } static void mBGMPsComp_make_ps_quietRoom(u16 stop_type); static void mBGMPsComp_delete_ps_quietRoom(); static int mBGMRoom_shop_close_check(mBGMRoom* room) { - int res = FALSE; - int time1_flag = FALSE; - int fadeout_flag = FALSE; - int temp_flag2; + int res = FALSE; + int time1_flag = FALSE; + int fadeout_flag = FALSE; + int temp_flag2; - if (mFI_CheckFieldData()) { - mActor_name_t field_id = mFI_GetFieldId(); + if (mFI_CheckFieldData()) { + mActor_name_t field_id = mFI_GetFieldId(); - if ( - field_id == mFI_FIELD_ROOM_SHOP0 || - field_id == mFI_FIELD_ROOM_SHOP1 || - field_id == mFI_FIELD_ROOM_SHOP2 || - field_id == mFI_FIELD_ROOM_SHOP3_1 || - field_id == mFI_FIELD_ROOM_SHOP3_2 - ) { - int real_arbeit = mEv_CheckRealArbeit(); - - temp_flag2 = FALSE; - if (real_arbeit == FALSE && mBGMClock_range_time_check(&M_bgm.clock, room->shop_close_time0, room->shop_close_time1, mBGMClock_CHK_hh | mBGMClock_CHK_mm | mBGMClock_CHK_ss)) { - temp_flag2 = TRUE; - } - fadeout_flag = temp_flag2; + if (field_id == mFI_FIELD_ROOM_SHOP0 || field_id == mFI_FIELD_ROOM_SHOP1 || field_id == mFI_FIELD_ROOM_SHOP2 || + field_id == mFI_FIELD_ROOM_SHOP3_1 || field_id == mFI_FIELD_ROOM_SHOP3_2) { + int real_arbeit = mEv_CheckRealArbeit(); - time1_flag = FALSE; - if (real_arbeit == FALSE && mBGMClock_over_time_check(&M_bgm.clock, room->shop_close_time1, mBGMClock_CHK_hh | mBGMClock_CHK_mm | mBGMClock_CHK_ss)) { - time1_flag = TRUE; - } + temp_flag2 = FALSE; + if (real_arbeit == FALSE && + mBGMClock_range_time_check(&M_bgm.clock, room->shop_close_time0, room->shop_close_time1, + mBGMClock_CHK_hh | mBGMClock_CHK_mm | mBGMClock_CHK_ss)) { + temp_flag2 = TRUE; + } + fadeout_flag = temp_flag2; - res = time1_flag; + time1_flag = FALSE; + if (real_arbeit == FALSE && + mBGMClock_over_time_check(&M_bgm.clock, room->shop_close_time1, + mBGMClock_CHK_hh | mBGMClock_CHK_mm | mBGMClock_CHK_ss)) { + time1_flag = TRUE; + } + + res = time1_flag; + } } - } - if (fadeout_flag && room->shop_fadeout_flag == FALSE) { - mBGMPsComp_make_ps_quietRoom(0x13DE); - room->shop_fadeout_flag = TRUE; - } - else if (!fadeout_flag && room->shop_fadeout_flag) { - mBGMPsComp_delete_ps_quietRoom(); - room->shop_fadeout_flag = FALSE; - } + if (fadeout_flag && room->shop_fadeout_flag == FALSE) { + mBGMPsComp_make_ps_quietRoom(0x13DE); + room->shop_fadeout_flag = TRUE; + } else if (!fadeout_flag && room->shop_fadeout_flag) { + mBGMPsComp_delete_ps_quietRoom(); + room->shop_fadeout_flag = FALSE; + } - return res; + return res; } static void mBGMRoom_move(mBGMRoom* room, GAME* game) { - if (mBGMRoom_shop_close_check(room)) { - room->delete_flag = TRUE; - room->make_flag = TRUE; - } + if (mBGMRoom_shop_close_check(room)) { + room->delete_flag = TRUE; + room->make_flag = TRUE; + } - if (room->delete_flag) { - mBGMRoom_delete_scene_bgm(room); - } + if (room->delete_flag) { + mBGMRoom_delete_scene_bgm(room); + } - if (room->make_flag) { - mBGMRoom_make_scene_bgm(room); - } + if (room->make_flag) { + mBGMRoom_make_scene_bgm(room); + } - room->make_flag = FALSE; - room->delete_flag = FALSE; + room->make_flag = FALSE; + room->delete_flag = FALSE; } static void mBGMRoom_scene_bgm_make_req() { - M_bgm.room.make_flag = TRUE; + M_bgm.room.make_flag = TRUE; } static void mBGMRoom_scene_bgm_delete_req() { - M_bgm.room.delete_flag = TRUE; + M_bgm.room.delete_flag = TRUE; } static void mBGMRoom_ct(mBGMRoom* room) { - bzero(room, sizeof(mBGMRoom)); - mBGMElem_default_set(&room->elem); + bzero(room, sizeof(mBGMRoom)); + mBGMElem_default_set(&room->elem); } /* mBGMTime */ static void mBGMTime_signal_melody(mBGMTime* time, GAME* game) { - static u8 signal_melody_buf[mMld_MELODY_LEN]; + static u8 signal_melody_buf[mMld_MELODY_LEN]; - if ( - mEv_CheckFirstIntro() == FALSE && - mEv_CheckTitleDemo() != -9 && - mFI_CheckFieldData() && - mFI_GET_TYPE(mFI_GetFieldId()) != mFI_FIELD_DEMO_STARTDEMO && - time->new_year_ev_flag == FALSE && - mPlib_get_player_actor_main_index(game) != mPlayer_INDEX_DEMO_GETON_BOAT && - mPlib_get_player_actor_main_index(game) != mPlayer_INDEX_DEMO_GETON_BOAT_SITDOWN && - mPlib_get_player_actor_main_index(game) != mPlayer_INDEX_DEMO_GETON_BOAT_WAIT && - mPlib_get_player_actor_main_index(game) != mPlayer_INDEX_DEMO_GETON_BOAT_WADE && - mPlib_get_player_actor_main_index(game) != mPlayer_INDEX_DEMO_GETOFF_BOAT_STANDUP && - mPlib_get_player_actor_main_index(game) != mPlayer_INDEX_DEMO_GETOFF_BOAT - ) { - mMld_GetMelody(signal_melody_buf); + if (mEv_CheckFirstIntro() == FALSE && mEv_CheckTitleDemo() != -9 && mFI_CheckFieldData() && + mFI_GET_TYPE(mFI_GetFieldId()) != mFI_FIELD_DEMO_STARTDEMO && time->new_year_ev_flag == FALSE && + mPlib_get_player_actor_main_index(game) != mPlayer_INDEX_DEMO_GETON_BOAT && + mPlib_get_player_actor_main_index(game) != mPlayer_INDEX_DEMO_GETON_BOAT_SITDOWN && + mPlib_get_player_actor_main_index(game) != mPlayer_INDEX_DEMO_GETON_BOAT_WAIT && + mPlib_get_player_actor_main_index(game) != mPlayer_INDEX_DEMO_GETON_BOAT_WADE && + mPlib_get_player_actor_main_index(game) != mPlayer_INDEX_DEMO_GETOFF_BOAT_STANDUP && + mPlib_get_player_actor_main_index(game) != mPlayer_INDEX_DEMO_GETOFF_BOAT) { + mMld_GetMelody(signal_melody_buf); - if (mFI_CheckInIsland()) { - sAdo_Inst(0xFE, signal_melody_buf); + if (mFI_CheckInIsland()) { + sAdo_Inst(0xFE, signal_melody_buf); + } else { + sAdo_Inst(0xFF, signal_melody_buf); + } } - else { - sAdo_Inst(0xFF, signal_melody_buf); - } - } } static int mBGMTime_silent_check(mBGMTime* time) { - if (time->new_year_ev_flag) { - return FALSE; - } + if (time->new_year_ev_flag) { + return FALSE; + } - /* Silent between XX:59:52 and XX:00:16 */ - return mBGMClock_range_time_check(&M_bgm.clock, (59 << 6) | (52 << 0), (0 << 6) | (16 << 0), mBGMClock_CHK_mm | mBGMClock_CHK_ss); + /* Silent between XX:59:52 and XX:00:16 */ + return mBGMClock_range_time_check(&M_bgm.clock, (59 << 6) | (52 << 0), (0 << 6) | (16 << 0), + mBGMClock_CHK_mm | mBGMClock_CHK_ss); } static void mBGMTime_new_year_ev_flag_set() { - M_bgm.time.new_year_ev_flag = TRUE; + M_bgm.time.new_year_ev_flag = TRUE; } static void mBGMTime_new_year_ev_flag_clr() { - M_bgm.time.new_year_ev_flag = FALSE; + M_bgm.time.new_year_ev_flag = FALSE; } static void mBGMTime_move_wait(mBGMTime* time, GAME* game); @@ -756,2214 +686,1981 @@ static void mBGMTime_move_change(mBGMTime* time, GAME* game); static void mBGMPsComp_make_ps_time(); static void mBGMTime_move_wait(mBGMTime* time, GAME* game) { - if (mBGMTime_silent_check(time)) { - mBGMPsComp_make_ps_time(); - time->move_proc = &mBGMTime_move_change; - } + if (mBGMTime_silent_check(time)) { + mBGMPsComp_make_ps_time(); + time->move_proc = &mBGMTime_move_change; + } } static void mBGMPsComp_delete_ps_time(); static void mBGMTime_move_change(mBGMTime* time, GAME* game) { - /* Wait until XX:00:00 and then play the town tune melody */ - if (mBGMClock_over_time_check(&M_bgm.clock, 0, mBGMClock_CHK_mm | mBGMClock_CHK_ss)) { - mBGMTime_signal_melody(time, game); - } + /* Wait until XX:00:00 and then play the town tune melody */ + if (mBGMClock_over_time_check(&M_bgm.clock, 0, mBGMClock_CHK_mm | mBGMClock_CHK_ss)) { + mBGMTime_signal_melody(time, game); + } - if (mBGMTime_silent_check(time) == FALSE) { - mBGMPsComp_delete_ps_time(); - time->move_proc = &mBGMTime_move_wait; - } + if (mBGMTime_silent_check(time) == FALSE) { + mBGMPsComp_delete_ps_time(); + time->move_proc = &mBGMTime_move_wait; + } } static void mBGMTime_move(mBGMTime* time, GAME* game) { - (*time->move_proc)(time, game); + (*time->move_proc)(time, game); } static void mBGMTime_ct(mBGMTime* time) { - bzero(time, sizeof(mBGMTime)); - time->move_proc = &mBGMTime_move_wait; + bzero(time, sizeof(mBGMTime)); + time->move_proc = &mBGMTime_move_wait; } /* mBGMFieldSuddenEv */ static int mBGMFieldSuddenEv_flag_check_island(mBGMFieldSuddenEv* field_sudden_ev, GAME* game) { - return mFI_CheckInJustIslandOutdoor(); + return mFI_CheckInJustIslandOutdoor(); } static int mBGMFieldSuddenEv_flag_check_arbeit(mBGMFieldSuddenEv* field_sudden_ev, GAME* game) { - return mEv_CheckFirstJob(); + return mEv_CheckFirstJob(); } typedef int (*mBGMFieldSuddenEv_EV_CHK_PROC)(mBGMFieldSuddenEv*, GAME*); static void mBGMFieldSuddenEv_flag_set(mBGMFieldSuddenEv* field_sudden_ev, GAME* game) { - static mBGMFieldSuddenEv_EV_CHK_PROC ev_chk[] = { - &mBGMFieldSuddenEv_flag_check_island, - NULL, - &mBGMFieldSuddenEv_flag_check_arbeit - }; + static mBGMFieldSuddenEv_EV_CHK_PROC ev_chk[] = { &mBGMFieldSuddenEv_flag_check_island, NULL, + &mBGMFieldSuddenEv_flag_check_arbeit }; - field_sudden_ev->old_flag = field_sudden_ev->flag; - field_sudden_ev->flag = 0; + field_sudden_ev->old_flag = field_sudden_ev->flag; + field_sudden_ev->flag = 0; - if (mFI_CheckFieldData() && mFI_GET_TYPE(mFI_GetFieldId()) == mFI_FIELD_FG) { - int i = 0; - u32 mask = 1; + if (mFI_CheckFieldData() && mFI_GET_TYPE(mFI_GetFieldId()) == mFI_FIELD_FG) { + int i = 0; + u32 mask = 1; - for (i; i < 3; i++) { - if (ev_chk[i] != NULL && (*ev_chk[i])(field_sudden_ev, game) != FALSE) { - field_sudden_ev->flag |= mask; - } + for (i; i < 3; i++) { + if (ev_chk[i] != NULL && (*ev_chk[i])(field_sudden_ev, game) != FALSE) { + field_sudden_ev->flag |= mask; + } - mask <<= 1; + mask <<= 1; + } } - } } static void mBGMFieldSuddenEv_ps_compose(mBGMFieldSuddenEv* field_sudden_ev, GAME* game) { - static u8 bgm_num_data[3] = { 91, 127, 52 }; - int now; - int old; - int i = 0; - int mask = 1; + static u8 bgm_num_data[3] = { 91, 127, 52 }; + int now; + int old; + int i = 0; + int mask = 1; - for (i; i < 3; i++) { - now = (field_sudden_ev->flag & mask) != 0; - old = (field_sudden_ev->old_flag & mask) != 0; + for (i; i < 3; i++) { + now = (field_sudden_ev->flag & mask) != 0; + old = (field_sudden_ev->old_flag & mask) != 0; - if (!now && old) { - mBGMPsComp_delete_ps_fieldSuddenEv(bgm_num_data[i], 0x168); + if (!now && old) { + mBGMPsComp_delete_ps_fieldSuddenEv(bgm_num_data[i], 0x168); + } + + if (now && !old) { + mBGMPsComp_make_ps_fieldSuddenEv(bgm_num_data[i], 0x168, i); + } + + mask <<= 1; } - - if (now && !old) { - mBGMPsComp_make_ps_fieldSuddenEv(bgm_num_data[i], 0x168, i); - } - - mask <<= 1; - } } static void mBGMFieldSuddenEv_move(mBGMFieldSuddenEv* field_sudden_ev, GAME* game) { - mBGMFieldSuddenEv_flag_set(field_sudden_ev, game); - mBGMFieldSuddenEv_ps_compose(field_sudden_ev, game); + mBGMFieldSuddenEv_flag_set(field_sudden_ev, game); + mBGMFieldSuddenEv_ps_compose(field_sudden_ev, game); } static void mBGMFieldSuddenEv_ct(mBGMFieldSuddenEv* field_sudden_ev) { - bzero(field_sudden_ev, sizeof(mBGMFieldSuddenEv)); + bzero(field_sudden_ev, sizeof(mBGMFieldSuddenEv)); } /* mBGMFieldSchedEv */ -static int mbgm_pattern_data[3][3] = { - { 2, 2, 2 }, - { 0, 1, 2 }, - { 0, 0, 2 } -}; +static int mbgm_pattern_data[3][3] = { { 2, 2, 2 }, { 0, 1, 2 }, { 0, 0, 2 } }; #define mBGMEventArea_ALL 0 /* Happens everywhere */ #define mBGMEventArea_BLOCK 1 /* Happens at a specific block */ enum { - mBGMFieldSchedEv_EVENT_SILENCE_0, - mBGMFieldSchedEv_EVENT_FIREWORKS, - mBGMFieldSchedEv_EVENT_HALLOWEEN, - mBGMFieldSchedEv_EVENT_TOY_DAY, - mBGMFieldSchedEv_EVENT_CHERRY_BLOSSOM_FESTIVAL, - mBGMFieldSchedEv_EVENT_MORNING_AEROBICS, - mBGMFieldSchedEv_EVENT_HARVEST_MOON_13, - mBGMFieldSchedEv_EVENT_HARVEST_FESTIVAL, - mBGMFieldSchedEv_EVENT_SPORTS_FAIR_AEROBICS, - mBGMFieldSchedEv_EVENT_SPORTS_FAIR_FOOT_RACE, - mBGMFieldSchedEv_EVENT_SPORTS_FAIR_BALL_TOSS, - mBGMFieldSchedEv_EVENT_SPORTS_FAIR_TUG_OF_WAR, - mBGMFieldSchedEv_EVENT_COUNTDOWN_1, - mBGMFieldSchedEv_EVENT_COUNTDOWN_2, - mBGMFieldSchedEv_EVENT_COUNTDOWN_3, - mBGMFieldSchedEv_EVENT_COUNTDOWN_4, - mBGMFieldSchedEv_EVENT_COUNTDOWN_5, - mBGMFieldSchedEv_EVENT_COUNTDOWN_6, - mBGMFieldSchedEv_EVENT_NEW_YEARS, - mBGMFieldSchedEv_EVENT_HOTARU, - mBGMFieldSchedEv_EVENT_NEWYEAR01, - mBGMFieldSchedEv_EVENT_NEWYEAR02, - mBGMFieldSchedEv_EVENT_GROUNDHOG_DAY, - mBGMFieldSchedEv_EVENT_METEOR_SHOWER, + mBGMFieldSchedEv_EVENT_SILENCE_0, + mBGMFieldSchedEv_EVENT_FIREWORKS, + mBGMFieldSchedEv_EVENT_HALLOWEEN, + mBGMFieldSchedEv_EVENT_TOY_DAY, + mBGMFieldSchedEv_EVENT_CHERRY_BLOSSOM_FESTIVAL, + mBGMFieldSchedEv_EVENT_MORNING_AEROBICS, + mBGMFieldSchedEv_EVENT_HARVEST_MOON_13, + mBGMFieldSchedEv_EVENT_HARVEST_FESTIVAL, + mBGMFieldSchedEv_EVENT_SPORTS_FAIR_AEROBICS, + mBGMFieldSchedEv_EVENT_SPORTS_FAIR_FOOT_RACE, + mBGMFieldSchedEv_EVENT_SPORTS_FAIR_BALL_TOSS, + mBGMFieldSchedEv_EVENT_SPORTS_FAIR_TUG_OF_WAR, + mBGMFieldSchedEv_EVENT_COUNTDOWN_1, + mBGMFieldSchedEv_EVENT_COUNTDOWN_2, + mBGMFieldSchedEv_EVENT_COUNTDOWN_3, + mBGMFieldSchedEv_EVENT_COUNTDOWN_4, + mBGMFieldSchedEv_EVENT_COUNTDOWN_5, + mBGMFieldSchedEv_EVENT_COUNTDOWN_6, + mBGMFieldSchedEv_EVENT_NEW_YEARS, + mBGMFieldSchedEv_EVENT_HOTARU, + mBGMFieldSchedEv_EVENT_NEWYEAR01, + mBGMFieldSchedEv_EVENT_NEWYEAR02, + mBGMFieldSchedEv_EVENT_GROUNDHOG_DAY, + mBGMFieldSchedEv_EVENT_METEOR_SHOWER, - mBGMFieldSchedEv_EVENT_NUM + mBGMFieldSchedEv_EVENT_NUM }; typedef struct bgm_event_data_s { - s16 event_type; - u8 bgm_num; - u8 event_area; - u32 block_type; + s16 event_type; + u8 bgm_num; + u8 event_area; + u32 block_type; } mBGMEventData; static mBGMEventData mbgm_event_data[mBGMFieldSchedEv_EVENT_NUM] = { - { - -1, - 127, - mBGMEventArea_BLOCK, - mRF_BLOCKKIND_POOL - }, - { - mEv_EVENT_FIREWORKS_SHOW, - 55, - mBGMEventArea_BLOCK, - mRF_BLOCKKIND_POOL - }, - { - mEv_EVENT_HALLOWEEN, - 53, - mBGMEventArea_ALL, - mRF_BLOCKKIND_NONE - }, - { - mEv_EVENT_TALK_TOY_DAY, - 54, - mBGMEventArea_ALL, - mRF_BLOCKKIND_NONE - }, - { - mEv_EVENT_CHERRY_BLOSSOM_FESTIVAL, - 56, - mBGMEventArea_BLOCK, - mRF_BLOCKKIND_SHRINE - }, - { - mEv_EVENT_MORNING_AEROBICS, - 27, - mBGMEventArea_BLOCK, - mRF_BLOCKKIND_SHRINE - }, - { - mEv_EVENT_HARVEST_MOON_FESTIVAL, - 30, - mBGMEventArea_BLOCK, - mRF_BLOCKKIND_POOL - }, - { - mEv_EVENT_HARVEST_FESTIVAL, - 253, - mBGMEventArea_BLOCK, - mRF_BLOCKKIND_SHRINE - }, - { - mEv_EVENT_SPORTS_FAIR_AEROBICS, - 27, - mBGMEventArea_BLOCK, - mRF_BLOCKKIND_SHRINE - }, - { - mEv_EVENT_SPORTS_FAIR_FOOT_RACE, - 28, - mBGMEventArea_BLOCK, - mRF_BLOCKKIND_SHRINE - }, - { - mEv_EVENT_SPORTS_FAIR_BALL_TOSS, - 29, - mBGMEventArea_BLOCK, - mRF_BLOCKKIND_SHRINE - }, - { - mEv_EVENT_SPORTS_FAIR_TUG_OF_WAR, - 60, - mBGMEventArea_BLOCK, - mRF_BLOCKKIND_SHRINE - }, - { - mEv_EVENT_NEW_YEARS_EVE_COUNTDOWN, - 31, - mBGMEventArea_BLOCK, - mRF_BLOCKKIND_POOL - }, - { - -1, - 32, - mBGMEventArea_BLOCK, - mRF_BLOCKKIND_POOL - }, - { - -1, - 33, - mBGMEventArea_BLOCK, - mRF_BLOCKKIND_POOL - }, - { - -1, - 34, - mBGMEventArea_BLOCK, - mRF_BLOCKKIND_POOL - }, - { - -1, - 35, - mBGMEventArea_BLOCK, - mRF_BLOCKKIND_POOL - }, - { - -1, - 57, - mBGMEventArea_BLOCK, - mRF_BLOCKKIND_POOL - }, - { - mEv_EVENT_NEW_YEARS_DAY, - 59, - mBGMEventArea_BLOCK, - mRF_BLOCKKIND_SHRINE - }, - { - -1, - 255, - mBGMEventArea_ALL, - mRF_BLOCKKIND_NONE - }, - { - -1, - 36, - mBGMEventArea_ALL, - mRF_BLOCKKIND_NONE - }, - { - -1, - 61, - mBGMEventArea_ALL, - mRF_BLOCKKIND_NONE - }, - { - mEv_EVENT_GROUNDHOG_DAY, - 251, - mBGMEventArea_BLOCK, - mRF_BLOCKKIND_SHRINE - }, - { - mEv_EVENT_METEOR_SHOWER, - 250, - mBGMEventArea_BLOCK, - mRF_BLOCKKIND_POOL - } + { -1, 127, mBGMEventArea_BLOCK, mRF_BLOCKKIND_POOL }, + { mEv_EVENT_FIREWORKS_SHOW, 55, mBGMEventArea_BLOCK, mRF_BLOCKKIND_POOL }, + { mEv_EVENT_HALLOWEEN, 53, mBGMEventArea_ALL, mRF_BLOCKKIND_NONE }, + { mEv_EVENT_TALK_TOY_DAY, 54, mBGMEventArea_ALL, mRF_BLOCKKIND_NONE }, + { mEv_EVENT_CHERRY_BLOSSOM_FESTIVAL, 56, mBGMEventArea_BLOCK, mRF_BLOCKKIND_SHRINE }, + { mEv_EVENT_MORNING_AEROBICS, 27, mBGMEventArea_BLOCK, mRF_BLOCKKIND_SHRINE }, + { mEv_EVENT_HARVEST_MOON_FESTIVAL, 30, mBGMEventArea_BLOCK, mRF_BLOCKKIND_POOL }, + { mEv_EVENT_HARVEST_FESTIVAL, 253, mBGMEventArea_BLOCK, mRF_BLOCKKIND_SHRINE }, + { mEv_EVENT_SPORTS_FAIR_AEROBICS, 27, mBGMEventArea_BLOCK, mRF_BLOCKKIND_SHRINE }, + { mEv_EVENT_SPORTS_FAIR_FOOT_RACE, 28, mBGMEventArea_BLOCK, mRF_BLOCKKIND_SHRINE }, + { mEv_EVENT_SPORTS_FAIR_BALL_TOSS, 29, mBGMEventArea_BLOCK, mRF_BLOCKKIND_SHRINE }, + { mEv_EVENT_SPORTS_FAIR_TUG_OF_WAR, 60, mBGMEventArea_BLOCK, mRF_BLOCKKIND_SHRINE }, + { mEv_EVENT_NEW_YEARS_EVE_COUNTDOWN, 31, mBGMEventArea_BLOCK, mRF_BLOCKKIND_POOL }, + { -1, 32, mBGMEventArea_BLOCK, mRF_BLOCKKIND_POOL }, + { -1, 33, mBGMEventArea_BLOCK, mRF_BLOCKKIND_POOL }, + { -1, 34, mBGMEventArea_BLOCK, mRF_BLOCKKIND_POOL }, + { -1, 35, mBGMEventArea_BLOCK, mRF_BLOCKKIND_POOL }, + { -1, 57, mBGMEventArea_BLOCK, mRF_BLOCKKIND_POOL }, + { mEv_EVENT_NEW_YEARS_DAY, 59, mBGMEventArea_BLOCK, mRF_BLOCKKIND_SHRINE }, + { -1, 255, mBGMEventArea_ALL, mRF_BLOCKKIND_NONE }, + { -1, 36, mBGMEventArea_ALL, mRF_BLOCKKIND_NONE }, + { -1, 61, mBGMEventArea_ALL, mRF_BLOCKKIND_NONE }, + { mEv_EVENT_GROUNDHOG_DAY, 251, mBGMEventArea_BLOCK, mRF_BLOCKKIND_SHRINE }, + { mEv_EVENT_METEOR_SHOWER, 250, mBGMEventArea_BLOCK, mRF_BLOCKKIND_POOL } }; enum { - mBGM_BL_ATTR_INACTIVE, - mBGM_BL_ATTR_NEARBY, - mBGM_BL_ATTR_ACTIVE, + mBGM_BL_ATTR_INACTIVE, + mBGM_BL_ATTR_NEARBY, + mBGM_BL_ATTR_ACTIVE, - mBGM_BL_ATTR_NUM + mBGM_BL_ATTR_NUM }; static int mBGMFieldSchedEv_bl_attr_get(int bx, int bz, int area, u32 block_type) { - int attr = mBGM_BL_ATTR_INACTIVE; + int attr = mBGM_BL_ATTR_INACTIVE; - if (area == mBGMEventArea_ALL) { - attr = mBGM_BL_ATTR_ACTIVE; - } - else if (block_type != mRF_BLOCKKIND_NONE) { - int ev_bx; - int ev_bz; - - if (mFI_BlockKind2BkNum(&ev_bx, &ev_bz, block_type)) { - int d_bx = ev_bx - bx; - int d_bz = ev_bz - bz; - - if (d_bx == 0 && d_bz == 0) { + if (area == mBGMEventArea_ALL) { attr = mBGM_BL_ATTR_ACTIVE; - } - else if (area == mBGMEventArea_BLOCK) { - d_bx = ABS(d_bx); - d_bz = ABS(d_bz); - - if ((d_bx == 0 && d_bz == 1) || (d_bx == 1 && d_bz == 0)) { - attr = mBGM_BL_ATTR_NEARBY; - } - } - } - } + } else if (block_type != mRF_BLOCKKIND_NONE) { + int ev_bx; + int ev_bz; - return attr; + if (mFI_BlockKind2BkNum(&ev_bx, &ev_bz, block_type)) { + int d_bx = ev_bx - bx; + int d_bz = ev_bz - bz; + + if (d_bx == 0 && d_bz == 0) { + attr = mBGM_BL_ATTR_ACTIVE; + } else if (area == mBGMEventArea_BLOCK) { + d_bx = ABS(d_bx); + d_bz = ABS(d_bz); + + if ((d_bx == 0 && d_bz == 1) || (d_bx == 1 && d_bz == 0)) { + attr = mBGM_BL_ATTR_NEARBY; + } + } + } + } + + return attr; } static int mBGMFieldSchedEv_bl_attr_evdata_get(mBGMEventData* data, GAME* game) { - PLAYER_ACTOR* player = GET_PLAYER_ACTOR((GAME_PLAY*)game); - int attr = mBGM_BL_ATTR_NUM; + PLAYER_ACTOR* player = GET_PLAYER_ACTOR((GAME_PLAY*)game); + int attr = mBGM_BL_ATTR_NUM; - if (player != NULL) { - int not_wading = mFI_CheckPlayerWade(mFI_WADE_NONE) || mFI_CheckPlayerWade(mFI_WADE_END); - int pos_valid; - int bx; - int bz; + if (player != NULL) { + int not_wading = mFI_CheckPlayerWade(mFI_WADE_NONE) || mFI_CheckPlayerWade(mFI_WADE_END); + int pos_valid; + int bx; + int bz; - if (not_wading) { - int inform = M_bgm.force.inform; + if (not_wading) { + int inform = M_bgm.force.inform; - if ( - inform == mBGMForce_INFORM_3 || - inform == mBGMForce_INFORM_4 || - inform == mBGMForce_INFORM_5 || - inform == mBGMForce_INFORM_6 - ) { - xyz_t original_pos; + if (inform == mBGMForce_INFORM_3 || inform == mBGMForce_INFORM_4 || inform == mBGMForce_INFORM_5 || + inform == mBGMForce_INFORM_6) { + xyz_t original_pos; - xyz_t_move_s_xyz(&original_pos, &Common_Get(event_door_data).exit_position); - pos_valid = mFI_Wpos2BlockNum(&bx, &bz, original_pos); - } - else { - pos_valid = mFI_Wpos2BlockNum(&bx, &bz, player->actor_class.world.position); - } - } - else { - pos_valid = mFI_GetNextBlockNum(&bx, &bz); + xyz_t_move_s_xyz(&original_pos, &Common_Get(event_door_data).exit_position); + pos_valid = mFI_Wpos2BlockNum(&bx, &bz, original_pos); + } else { + pos_valid = mFI_Wpos2BlockNum(&bx, &bz, player->actor_class.world.position); + } + } else { + pos_valid = mFI_GetNextBlockNum(&bx, &bz); + } + + if (pos_valid) { + attr = mBGMFieldSchedEv_bl_attr_get(bx, bz, data->event_area, data->block_type); + } } - if (pos_valid) { - attr = mBGMFieldSchedEv_bl_attr_get(bx, bz, data->event_area, data->block_type); - } - } - - return attr; + return attr; } static void mBGMFieldSchedEv_Info_old_copy(mBGMFieldSchedEv_Info* sched_ev_info) { - if ((sched_ev_info->flag & 1)) { - sched_ev_info->flag |= 2; - } - else { - sched_ev_info->flag &= ~2; - } - - if ((sched_ev_info->flag & 4)) { - sched_ev_info->flag |= 8; - } - else { - sched_ev_info->flag &= ~8; - } - - sched_ev_info->old_attr = sched_ev_info->attr; -} - -static void mBGMFieldSchedEv_Info_ev_now_set_standard(mBGMFieldSchedEv_Info* sched_ev_info, mBGMEventData* data, GAME* game, int ev_start_flag) { - if (ev_start_flag || (sched_ev_info->flag & 1)) { - if (mEv_check_status(data->event_type, mEv_STATUS_ACTIVE)) { - sched_ev_info->flag |= 1; - } - else { - sched_ev_info->flag &= ~1; - } - } -} - -static void mBGMFieldSchedEv_Info_ev_now_set_Silence_0(mBGMFieldSchedEv_Info* sched_ev_info, mBGMEventData* data, GAME* game, int ev_start_flag) { - int event_now = FALSE; - - if ( - (sched_ev_info->flag & 4) && - mBGMClock_over_time_check(&M_bgm.clock, (12 << 22) | (31 << 17) | (23 << 12) | (59 << 6) | (0 << 0), mBGMClock_CHK_MM | mBGMClock_CHK_DD | mBGMClock_CHK_hh | mBGMClock_CHK_mm | mBGMClock_CHK_ss) && - mBGMFieldSchedEv_bl_attr_evdata_get(&mbgm_event_data[mBGMFieldSchedEv_EVENT_SILENCE_0], game) == mBGM_BL_ATTR_ACTIVE - ) { - sched_ev_info->flag |= 0x10; - } - - if ( - mBGMClock_range_time_check( - &M_bgm.clock, - (12 << 22) | (31 << 17) | (23 << 12) | (59 << 6) | (0 << 0), - ( 1 << 22) | ( 1 << 17) | ( 0 << 12) | ( 0 << 6) | (0 << 0), - mBGMClock_CHK_MM | mBGMClock_CHK_DD | mBGMClock_CHK_hh | mBGMClock_CHK_mm | mBGMClock_CHK_ss - ) - ) { - if ((sched_ev_info->flag & 0x10)) { - if (mEv_check_status(mEv_EVENT_NEW_YEARS_EVE_COUNTDOWN, mEv_STATUS_PLAYSOUND)) { - event_now = TRUE; - } - } - else { - event_now = TRUE; - } - } - else { - sched_ev_info->flag &= ~0x10; - } - - if (event_now) { - sched_ev_info->flag |= 1; - } - else { - sched_ev_info->flag &= ~1; - } -} - -static void mBGMFieldSchedEv_Info_ev_now_set_CountDown_1(mBGMFieldSchedEv_Info* sched_ev_info, mBGMEventData* data, GAME* game, int ev_start_flag) { - if ( - mEv_check_status(mEv_EVENT_NEW_YEARS_EVE_COUNTDOWN, mEv_STATUS_ACTIVE) && - mBGMClock_range_time_check( - &M_bgm.clock, - (12 << 22) | (31 << 17) | (23 << 12) | ( 0 << 6) | (0 << 0), - (12 << 22) | (31 << 17) | (23 << 12) | (30 << 6) | (0 << 0), - mBGMClock_CHK_MM | mBGMClock_CHK_DD | mBGMClock_CHK_hh | mBGMClock_CHK_mm | mBGMClock_CHK_ss - ) - ) { - sched_ev_info->flag |= 1; - } - else { - sched_ev_info->flag &= ~1; - } -} - -static void mBGMFieldSchedEv_Info_ev_now_set_CountDown_2(mBGMFieldSchedEv_Info* sched_ev_info, mBGMEventData* data, GAME* game, int ev_start_flag) { - if ( - mEv_check_status(mEv_EVENT_NEW_YEARS_EVE_COUNTDOWN, mEv_STATUS_ACTIVE) && - mBGMClock_range_time_check( - &M_bgm.clock, - (12 << 22) | (31 << 17) | (23 << 12) | (30 << 6) | (0 << 0), - (12 << 22) | (31 << 17) | (23 << 12) | (50 << 6) | (0 << 0), - mBGMClock_CHK_MM | mBGMClock_CHK_DD | mBGMClock_CHK_hh | mBGMClock_CHK_mm | mBGMClock_CHK_ss - ) - ) { - sched_ev_info->flag |= 1; - } - else { - sched_ev_info->flag &= ~1; - } -} - -static void mBGMFieldSchedEv_Info_ev_now_set_CountDown_3(mBGMFieldSchedEv_Info* sched_ev_info, mBGMEventData* data, GAME* game, int ev_start_flag) { - if ( - mEv_check_status(mEv_EVENT_NEW_YEARS_EVE_COUNTDOWN, mEv_STATUS_ACTIVE) && - mBGMClock_range_time_check( - &M_bgm.clock, - (12 << 22) | (31 << 17) | (23 << 12) | (50 << 6) | (0 << 0), - (12 << 22) | (31 << 17) | (23 << 12) | (55 << 6) | (0 << 0), - mBGMClock_CHK_MM | mBGMClock_CHK_DD | mBGMClock_CHK_hh | mBGMClock_CHK_mm | mBGMClock_CHK_ss - ) - ) { - sched_ev_info->flag |= 1; - } - else { - sched_ev_info->flag &= ~1; - } -} - -static void mBGMFieldSchedEv_Info_ev_now_set_CountDown_4(mBGMFieldSchedEv_Info* sched_ev_info, mBGMEventData* data, GAME* game, int ev_start_flag) { - if ( - mEv_check_status(mEv_EVENT_NEW_YEARS_EVE_COUNTDOWN, mEv_STATUS_ACTIVE) && - mBGMClock_range_time_check( - &M_bgm.clock, - (12 << 22) | (31 << 17) | (23 << 12) | (55 << 6) | (0 << 0), - ( 1 << 22) | ( 1 << 17) | ( 0 << 12) | ( 0 << 6) | (0 << 0), - mBGMClock_CHK_MM | mBGMClock_CHK_DD | mBGMClock_CHK_hh | mBGMClock_CHK_mm | mBGMClock_CHK_ss - ) - ) { - sched_ev_info->flag |= 1; - } - else { - sched_ev_info->flag &= ~1; - } -} - -static void mBGMFieldSchedEv_Info_ev_now_set_CountDown_5(mBGMFieldSchedEv_Info* sched_ev_info, mBGMEventData* data, GAME* game, int ev_start_flag) { - int event_now = FALSE; - - if ( - mBGMClock_range_time_check( - &M_bgm.clock, - (1 << 22) | (1 << 17) | (0 << 12) | (0 << 6) | (0 << 0), - (1 << 22) | (1 << 17) | (1 << 12) | (0 << 6) | (0 << 0), - mBGMClock_CHK_MM | mBGMClock_CHK_DD | mBGMClock_CHK_hh | mBGMClock_CHK_mm | mBGMClock_CHK_ss - ) - ) { - if ( - (sched_ev_info->flag & 4) && - mBGMClock_over_time_check( - &M_bgm.clock, - (1 << 22) | (1 << 17) | (0 << 12) | (0 << 6) | (0 << 0), - mBGMClock_CHK_MM | mBGMClock_CHK_DD | mBGMClock_CHK_hh | mBGMClock_CHK_mm | mBGMClock_CHK_ss - ) && - mBGMFieldSchedEv_bl_attr_evdata_get(&mbgm_event_data[mBGMFieldSchedEv_EVENT_COUNTDOWN_5], game) != mBGM_BL_ATTR_INACTIVE - ) { - sched_ev_info->flag |= 0x20; + if ((sched_ev_info->flag & 1)) { + sched_ev_info->flag |= 2; + } else { + sched_ev_info->flag &= ~2; } - if ( - (sched_ev_info->flag & 0x20) && - mBGMFieldSchedEv_bl_attr_evdata_get(&mbgm_event_data[mBGMFieldSchedEv_EVENT_COUNTDOWN_5], game) == mBGM_BL_ATTR_INACTIVE - ) { - sched_ev_info->flag &= ~0x20; + if ((sched_ev_info->flag & 4)) { + sched_ev_info->flag |= 8; + } else { + sched_ev_info->flag &= ~8; } - if ((sched_ev_info->flag & 0x20) && mEv_check_status(mEv_EVENT_NEW_YEARS_EVE_COUNTDOWN, mEv_STATUS_ACTIVE)) { - event_now = TRUE; - } - } - else { - sched_ev_info->flag &= ~0x20; - } - - if (event_now) { - sched_ev_info->flag |= 1; - } - else { - sched_ev_info->flag &= ~1; - } + sched_ev_info->old_attr = sched_ev_info->attr; } -static void mBGMFieldSchedEv_Info_ev_now_set_CountDown_6(mBGMFieldSchedEv_Info* sched_ev_info, mBGMEventData* data, GAME* game, int ev_start_flag) { - int event_now = FALSE; - - if ( - mBGMClock_range_time_check( - &M_bgm.clock, - (1 << 22) | (1 << 17) | (0 << 12) | (0 << 6) | (0 << 0), - (1 << 22) | (1 << 17) | (1 << 12) | (0 << 6) | (0 << 0), - mBGMClock_CHK_MM | mBGMClock_CHK_DD | mBGMClock_CHK_hh | mBGMClock_CHK_mm | mBGMClock_CHK_ss - ) - ) { - if ( - (sched_ev_info->flag & 4) && - mBGMClock_over_time_check( - &M_bgm.clock, - (1 << 22) | (1 << 17) | (0 << 12) | (0 << 6) | (0 << 0), - mBGMClock_CHK_MM | mBGMClock_CHK_DD | mBGMClock_CHK_hh | mBGMClock_CHK_mm | mBGMClock_CHK_ss - ) && - mBGMFieldSchedEv_bl_attr_evdata_get(&mbgm_event_data[mBGMFieldSchedEv_EVENT_COUNTDOWN_6], game) != mBGM_BL_ATTR_INACTIVE - ) { - sched_ev_info->flag |= 0x20; +static void mBGMFieldSchedEv_Info_ev_now_set_standard(mBGMFieldSchedEv_Info* sched_ev_info, mBGMEventData* data, + GAME* game, int ev_start_flag) { + if (ev_start_flag || (sched_ev_info->flag & 1)) { + if (mEv_check_status(data->event_type, mEv_STATUS_ACTIVE)) { + sched_ev_info->flag |= 1; + } else { + sched_ev_info->flag &= ~1; + } } - - if ( - (sched_ev_info->flag & 0x20) && - mBGMFieldSchedEv_bl_attr_evdata_get(&mbgm_event_data[mBGMFieldSchedEv_EVENT_COUNTDOWN_6], game) == mBGM_BL_ATTR_INACTIVE - ) { - sched_ev_info->flag &= ~0x20; - } - - if ((sched_ev_info->flag & 0x20) == 0 && mEv_check_status(mEv_EVENT_NEW_YEARS_EVE_COUNTDOWN, mEv_STATUS_ACTIVE)) { - event_now = TRUE; - } - } - else { - sched_ev_info->flag &= ~0x20; - } - - if (event_now) { - sched_ev_info->flag |= 1; - } - else { - sched_ev_info->flag &= ~1; - } } -static void mBGMFieldSchedEv_Info_ev_now_set_Hotaru(mBGMFieldSchedEv_Info* sched_ev_info, mBGMEventData* data, GAME* game, int ev_start_flag) { - if ( - mBGMClock_range_time_check( - &M_bgm.clock, - (1 << 22) | (1 << 17) | (0 << 12) | (0 << 6) | (0 << 0), - (1 << 22) | (1 << 17) | (1 << 12) | (0 << 6) | (0 << 0), - mBGMClock_CHK_MM | mBGMClock_CHK_DD | mBGMClock_CHK_hh | mBGMClock_CHK_mm | mBGMClock_CHK_ss - ) - ) { - sched_ev_info->flag |= 1; - } - else { - sched_ev_info->flag &= ~1; - } +static void mBGMFieldSchedEv_Info_ev_now_set_Silence_0(mBGMFieldSchedEv_Info* sched_ev_info, mBGMEventData* data, + GAME* game, int ev_start_flag) { + int event_now = FALSE; + + if ((sched_ev_info->flag & 4) && + mBGMClock_over_time_check(&M_bgm.clock, (12 << 22) | (31 << 17) | (23 << 12) | (59 << 6) | (0 << 0), + mBGMClock_CHK_MM | mBGMClock_CHK_DD | mBGMClock_CHK_hh | mBGMClock_CHK_mm | + mBGMClock_CHK_ss) && + mBGMFieldSchedEv_bl_attr_evdata_get(&mbgm_event_data[mBGMFieldSchedEv_EVENT_SILENCE_0], game) == + mBGM_BL_ATTR_ACTIVE) { + sched_ev_info->flag |= 0x10; + } + + if (mBGMClock_range_time_check(&M_bgm.clock, (12 << 22) | (31 << 17) | (23 << 12) | (59 << 6) | (0 << 0), + (1 << 22) | (1 << 17) | (0 << 12) | (0 << 6) | (0 << 0), + mBGMClock_CHK_MM | mBGMClock_CHK_DD | mBGMClock_CHK_hh | mBGMClock_CHK_mm | + mBGMClock_CHK_ss)) { + if ((sched_ev_info->flag & 0x10)) { + if (mEv_check_status(mEv_EVENT_NEW_YEARS_EVE_COUNTDOWN, mEv_STATUS_PLAYSOUND)) { + event_now = TRUE; + } + } else { + event_now = TRUE; + } + } else { + sched_ev_info->flag &= ~0x10; + } + + if (event_now) { + sched_ev_info->flag |= 1; + } else { + sched_ev_info->flag &= ~1; + } } -static void mBGMFieldSchedEv_Info_ev_now_set_NewYear01(mBGMFieldSchedEv_Info* sched_ev_info, mBGMEventData* data, GAME* game, int ev_start_flag) { - if ( - mBGMClock_range_time_check( - &M_bgm.clock, - (1 << 22) | (1 << 17) | ( 1 << 12) | (0 << 6) | (0 << 0), - (1 << 22) | (1 << 17) | (18 << 12) | (0 << 6) | (0 << 0), - mBGMClock_CHK_MM | mBGMClock_CHK_DD | mBGMClock_CHK_hh | mBGMClock_CHK_mm | mBGMClock_CHK_ss - ) - ) { - sched_ev_info->flag |= 1; - } - else { - sched_ev_info->flag &= ~1; - } +static void mBGMFieldSchedEv_Info_ev_now_set_CountDown_1(mBGMFieldSchedEv_Info* sched_ev_info, mBGMEventData* data, + GAME* game, int ev_start_flag) { + if (mEv_check_status(mEv_EVENT_NEW_YEARS_EVE_COUNTDOWN, mEv_STATUS_ACTIVE) && + mBGMClock_range_time_check(&M_bgm.clock, (12 << 22) | (31 << 17) | (23 << 12) | (0 << 6) | (0 << 0), + (12 << 22) | (31 << 17) | (23 << 12) | (30 << 6) | (0 << 0), + mBGMClock_CHK_MM | mBGMClock_CHK_DD | mBGMClock_CHK_hh | mBGMClock_CHK_mm | + mBGMClock_CHK_ss)) { + sched_ev_info->flag |= 1; + } else { + sched_ev_info->flag &= ~1; + } } -static void mBGMFieldSchedEv_Info_ev_now_set_NewYear02(mBGMFieldSchedEv_Info* sched_ev_info, mBGMEventData* data, GAME* game, int ev_start_flag) { - if ( - mBGMClock_range_time_check( - &M_bgm.clock, - (1 << 22) | (1 << 17) | (18 << 12) | (0 << 6) | (0 << 0), - (1 << 22) | (2 << 17) | ( 0 << 12) | (0 << 6) | (0 << 0), - mBGMClock_CHK_MM | mBGMClock_CHK_DD | mBGMClock_CHK_hh | mBGMClock_CHK_mm | mBGMClock_CHK_ss - ) - ) { - sched_ev_info->flag |= 1; - } - else { - sched_ev_info->flag &= ~1; - } +static void mBGMFieldSchedEv_Info_ev_now_set_CountDown_2(mBGMFieldSchedEv_Info* sched_ev_info, mBGMEventData* data, + GAME* game, int ev_start_flag) { + if (mEv_check_status(mEv_EVENT_NEW_YEARS_EVE_COUNTDOWN, mEv_STATUS_ACTIVE) && + mBGMClock_range_time_check(&M_bgm.clock, (12 << 22) | (31 << 17) | (23 << 12) | (30 << 6) | (0 << 0), + (12 << 22) | (31 << 17) | (23 << 12) | (50 << 6) | (0 << 0), + mBGMClock_CHK_MM | mBGMClock_CHK_DD | mBGMClock_CHK_hh | mBGMClock_CHK_mm | + mBGMClock_CHK_ss)) { + sched_ev_info->flag |= 1; + } else { + sched_ev_info->flag &= ~1; + } +} + +static void mBGMFieldSchedEv_Info_ev_now_set_CountDown_3(mBGMFieldSchedEv_Info* sched_ev_info, mBGMEventData* data, + GAME* game, int ev_start_flag) { + if (mEv_check_status(mEv_EVENT_NEW_YEARS_EVE_COUNTDOWN, mEv_STATUS_ACTIVE) && + mBGMClock_range_time_check(&M_bgm.clock, (12 << 22) | (31 << 17) | (23 << 12) | (50 << 6) | (0 << 0), + (12 << 22) | (31 << 17) | (23 << 12) | (55 << 6) | (0 << 0), + mBGMClock_CHK_MM | mBGMClock_CHK_DD | mBGMClock_CHK_hh | mBGMClock_CHK_mm | + mBGMClock_CHK_ss)) { + sched_ev_info->flag |= 1; + } else { + sched_ev_info->flag &= ~1; + } +} + +static void mBGMFieldSchedEv_Info_ev_now_set_CountDown_4(mBGMFieldSchedEv_Info* sched_ev_info, mBGMEventData* data, + GAME* game, int ev_start_flag) { + if (mEv_check_status(mEv_EVENT_NEW_YEARS_EVE_COUNTDOWN, mEv_STATUS_ACTIVE) && + mBGMClock_range_time_check(&M_bgm.clock, (12 << 22) | (31 << 17) | (23 << 12) | (55 << 6) | (0 << 0), + (1 << 22) | (1 << 17) | (0 << 12) | (0 << 6) | (0 << 0), + mBGMClock_CHK_MM | mBGMClock_CHK_DD | mBGMClock_CHK_hh | mBGMClock_CHK_mm | + mBGMClock_CHK_ss)) { + sched_ev_info->flag |= 1; + } else { + sched_ev_info->flag &= ~1; + } +} + +static void mBGMFieldSchedEv_Info_ev_now_set_CountDown_5(mBGMFieldSchedEv_Info* sched_ev_info, mBGMEventData* data, + GAME* game, int ev_start_flag) { + int event_now = FALSE; + + if (mBGMClock_range_time_check(&M_bgm.clock, (1 << 22) | (1 << 17) | (0 << 12) | (0 << 6) | (0 << 0), + (1 << 22) | (1 << 17) | (1 << 12) | (0 << 6) | (0 << 0), + mBGMClock_CHK_MM | mBGMClock_CHK_DD | mBGMClock_CHK_hh | mBGMClock_CHK_mm | + mBGMClock_CHK_ss)) { + if ((sched_ev_info->flag & 4) && + mBGMClock_over_time_check(&M_bgm.clock, (1 << 22) | (1 << 17) | (0 << 12) | (0 << 6) | (0 << 0), + mBGMClock_CHK_MM | mBGMClock_CHK_DD | mBGMClock_CHK_hh | mBGMClock_CHK_mm | + mBGMClock_CHK_ss) && + mBGMFieldSchedEv_bl_attr_evdata_get(&mbgm_event_data[mBGMFieldSchedEv_EVENT_COUNTDOWN_5], game) != + mBGM_BL_ATTR_INACTIVE) { + sched_ev_info->flag |= 0x20; + } + + if ((sched_ev_info->flag & 0x20) && + mBGMFieldSchedEv_bl_attr_evdata_get(&mbgm_event_data[mBGMFieldSchedEv_EVENT_COUNTDOWN_5], game) == + mBGM_BL_ATTR_INACTIVE) { + sched_ev_info->flag &= ~0x20; + } + + if ((sched_ev_info->flag & 0x20) && mEv_check_status(mEv_EVENT_NEW_YEARS_EVE_COUNTDOWN, mEv_STATUS_ACTIVE)) { + event_now = TRUE; + } + } else { + sched_ev_info->flag &= ~0x20; + } + + if (event_now) { + sched_ev_info->flag |= 1; + } else { + sched_ev_info->flag &= ~1; + } +} + +static void mBGMFieldSchedEv_Info_ev_now_set_CountDown_6(mBGMFieldSchedEv_Info* sched_ev_info, mBGMEventData* data, + GAME* game, int ev_start_flag) { + int event_now = FALSE; + + if (mBGMClock_range_time_check(&M_bgm.clock, (1 << 22) | (1 << 17) | (0 << 12) | (0 << 6) | (0 << 0), + (1 << 22) | (1 << 17) | (1 << 12) | (0 << 6) | (0 << 0), + mBGMClock_CHK_MM | mBGMClock_CHK_DD | mBGMClock_CHK_hh | mBGMClock_CHK_mm | + mBGMClock_CHK_ss)) { + if ((sched_ev_info->flag & 4) && + mBGMClock_over_time_check(&M_bgm.clock, (1 << 22) | (1 << 17) | (0 << 12) | (0 << 6) | (0 << 0), + mBGMClock_CHK_MM | mBGMClock_CHK_DD | mBGMClock_CHK_hh | mBGMClock_CHK_mm | + mBGMClock_CHK_ss) && + mBGMFieldSchedEv_bl_attr_evdata_get(&mbgm_event_data[mBGMFieldSchedEv_EVENT_COUNTDOWN_6], game) != + mBGM_BL_ATTR_INACTIVE) { + sched_ev_info->flag |= 0x20; + } + + if ((sched_ev_info->flag & 0x20) && + mBGMFieldSchedEv_bl_attr_evdata_get(&mbgm_event_data[mBGMFieldSchedEv_EVENT_COUNTDOWN_6], game) == + mBGM_BL_ATTR_INACTIVE) { + sched_ev_info->flag &= ~0x20; + } + + if ((sched_ev_info->flag & 0x20) == 0 && + mEv_check_status(mEv_EVENT_NEW_YEARS_EVE_COUNTDOWN, mEv_STATUS_ACTIVE)) { + event_now = TRUE; + } + } else { + sched_ev_info->flag &= ~0x20; + } + + if (event_now) { + sched_ev_info->flag |= 1; + } else { + sched_ev_info->flag &= ~1; + } +} + +static void mBGMFieldSchedEv_Info_ev_now_set_Hotaru(mBGMFieldSchedEv_Info* sched_ev_info, mBGMEventData* data, + GAME* game, int ev_start_flag) { + if (mBGMClock_range_time_check(&M_bgm.clock, (1 << 22) | (1 << 17) | (0 << 12) | (0 << 6) | (0 << 0), + (1 << 22) | (1 << 17) | (1 << 12) | (0 << 6) | (0 << 0), + mBGMClock_CHK_MM | mBGMClock_CHK_DD | mBGMClock_CHK_hh | mBGMClock_CHK_mm | + mBGMClock_CHK_ss)) { + sched_ev_info->flag |= 1; + } else { + sched_ev_info->flag &= ~1; + } +} + +static void mBGMFieldSchedEv_Info_ev_now_set_NewYear01(mBGMFieldSchedEv_Info* sched_ev_info, mBGMEventData* data, + GAME* game, int ev_start_flag) { + if (mBGMClock_range_time_check(&M_bgm.clock, (1 << 22) | (1 << 17) | (1 << 12) | (0 << 6) | (0 << 0), + (1 << 22) | (1 << 17) | (18 << 12) | (0 << 6) | (0 << 0), + mBGMClock_CHK_MM | mBGMClock_CHK_DD | mBGMClock_CHK_hh | mBGMClock_CHK_mm | + mBGMClock_CHK_ss)) { + sched_ev_info->flag |= 1; + } else { + sched_ev_info->flag &= ~1; + } +} + +static void mBGMFieldSchedEv_Info_ev_now_set_NewYear02(mBGMFieldSchedEv_Info* sched_ev_info, mBGMEventData* data, + GAME* game, int ev_start_flag) { + if (mBGMClock_range_time_check(&M_bgm.clock, (1 << 22) | (1 << 17) | (18 << 12) | (0 << 6) | (0 << 0), + (1 << 22) | (2 << 17) | (0 << 12) | (0 << 6) | (0 << 0), + mBGMClock_CHK_MM | mBGMClock_CHK_DD | mBGMClock_CHK_hh | mBGMClock_CHK_mm | + mBGMClock_CHK_ss)) { + sched_ev_info->flag |= 1; + } else { + sched_ev_info->flag &= ~1; + } } static void mBGMFieldSchedEv_Info_attr_now_set(mBGMFieldSchedEv_Info* sched_ev_info, GAME* game, mBGMEventData* data) { - sched_ev_info->attr = mBGM_BL_ATTR_INACTIVE; + sched_ev_info->attr = mBGM_BL_ATTR_INACTIVE; - if ((sched_ev_info->flag & (4 | 1)) == (4 | 1)) { - int attr = mBGMFieldSchedEv_bl_attr_evdata_get(data, game); + if ((sched_ev_info->flag & (4 | 1)) == (4 | 1)) { + int attr = mBGMFieldSchedEv_bl_attr_evdata_get(data, game); - if (attr < mBGM_BL_ATTR_NUM) { - sched_ev_info->attr = attr; + if (attr < mBGM_BL_ATTR_NUM) { + sched_ev_info->attr = attr; + } } - } } typedef void (*mBGMFieldSchedEv_INFO_CHK_PROC)(mBGMFieldSchedEv_Info*, mBGMEventData*, GAME*, int); static void mBGMFieldSchedEv_info_set(mBGMFieldSchedEv* sched_ev, GAME* game) { - static mBGMFieldSchedEv_INFO_CHK_PROC ev_chk[mBGMFieldSchedEv_EVENT_NUM] = { - &mBGMFieldSchedEv_Info_ev_now_set_Silence_0, - &mBGMFieldSchedEv_Info_ev_now_set_standard, - &mBGMFieldSchedEv_Info_ev_now_set_standard, - &mBGMFieldSchedEv_Info_ev_now_set_standard, - &mBGMFieldSchedEv_Info_ev_now_set_standard, - &mBGMFieldSchedEv_Info_ev_now_set_standard, - &mBGMFieldSchedEv_Info_ev_now_set_standard, - &mBGMFieldSchedEv_Info_ev_now_set_standard, - &mBGMFieldSchedEv_Info_ev_now_set_standard, - &mBGMFieldSchedEv_Info_ev_now_set_standard, - &mBGMFieldSchedEv_Info_ev_now_set_standard, - &mBGMFieldSchedEv_Info_ev_now_set_standard, - &mBGMFieldSchedEv_Info_ev_now_set_CountDown_1, - &mBGMFieldSchedEv_Info_ev_now_set_CountDown_2, - &mBGMFieldSchedEv_Info_ev_now_set_CountDown_3, - &mBGMFieldSchedEv_Info_ev_now_set_CountDown_4, - &mBGMFieldSchedEv_Info_ev_now_set_CountDown_5, - &mBGMFieldSchedEv_Info_ev_now_set_CountDown_6, - &mBGMFieldSchedEv_Info_ev_now_set_standard, - &mBGMFieldSchedEv_Info_ev_now_set_Hotaru, - &mBGMFieldSchedEv_Info_ev_now_set_NewYear01, - &mBGMFieldSchedEv_Info_ev_now_set_NewYear02, - &mBGMFieldSchedEv_Info_ev_now_set_standard, - &mBGMFieldSchedEv_Info_ev_now_set_standard - }; + static mBGMFieldSchedEv_INFO_CHK_PROC ev_chk[mBGMFieldSchedEv_EVENT_NUM] = { + &mBGMFieldSchedEv_Info_ev_now_set_Silence_0, &mBGMFieldSchedEv_Info_ev_now_set_standard, + &mBGMFieldSchedEv_Info_ev_now_set_standard, &mBGMFieldSchedEv_Info_ev_now_set_standard, + &mBGMFieldSchedEv_Info_ev_now_set_standard, &mBGMFieldSchedEv_Info_ev_now_set_standard, + &mBGMFieldSchedEv_Info_ev_now_set_standard, &mBGMFieldSchedEv_Info_ev_now_set_standard, + &mBGMFieldSchedEv_Info_ev_now_set_standard, &mBGMFieldSchedEv_Info_ev_now_set_standard, + &mBGMFieldSchedEv_Info_ev_now_set_standard, &mBGMFieldSchedEv_Info_ev_now_set_standard, + &mBGMFieldSchedEv_Info_ev_now_set_CountDown_1, &mBGMFieldSchedEv_Info_ev_now_set_CountDown_2, + &mBGMFieldSchedEv_Info_ev_now_set_CountDown_3, &mBGMFieldSchedEv_Info_ev_now_set_CountDown_4, + &mBGMFieldSchedEv_Info_ev_now_set_CountDown_5, &mBGMFieldSchedEv_Info_ev_now_set_CountDown_6, + &mBGMFieldSchedEv_Info_ev_now_set_standard, &mBGMFieldSchedEv_Info_ev_now_set_Hotaru, + &mBGMFieldSchedEv_Info_ev_now_set_NewYear01, &mBGMFieldSchedEv_Info_ev_now_set_NewYear02, + &mBGMFieldSchedEv_Info_ev_now_set_standard, &mBGMFieldSchedEv_Info_ev_now_set_standard + }; - mBGMFieldSchedEv_Info* info; - mBGMEventData* data; - int i; - const int event_active_on_edge = mEv_check_status_edge(mEv_STATUS_ACTIVE); - const int valid_field = mFI_CheckFieldData() && mFI_GET_TYPE(mFI_GetFieldId()) == mFI_FIELD_FG; + mBGMFieldSchedEv_Info* info; + mBGMEventData* data; + int i; + const int event_active_on_edge = mEv_check_status_edge(mEv_STATUS_ACTIVE); + const int valid_field = mFI_CheckFieldData() && mFI_GET_TYPE(mFI_GetFieldId()) == mFI_FIELD_FG; - info = sched_ev->info; - data = mbgm_event_data; + info = sched_ev->info; + data = mbgm_event_data; - for (i = 0; i < ARRAY_COUNT(mbgm_event_data); i++, info++, data++) { - mBGMFieldSchedEv_Info_old_copy(info); - info->flag &= ~4; + for (i = 0; i < ARRAY_COUNT(mbgm_event_data); i++, info++, data++) { + mBGMFieldSchedEv_Info_old_copy(info); + info->flag &= ~4; - if (valid_field) { - info->flag |= 4; + if (valid_field) { + info->flag |= 4; + } + + (*ev_chk[i])(info, data, game, event_active_on_edge); + mBGMFieldSchedEv_Info_attr_now_set(info, game, data); } - - (*ev_chk[i])(info, data, game, event_active_on_edge); - mBGMFieldSchedEv_Info_attr_now_set(info, game, data); - } } static void mBGMPsComp_delete_ps_fieldSchedEv(u8 bgm_num, u16 stop_type); static void mBGMPsComp_search_cf_set_field(u8 bgm_num, int kategorie); static void mBGMFieldSchedEv_Info_ps_delete(mBGMFieldSchedEv_Info* sched_ev_info, mBGMEventData* data, int flag) { - mBGMPsComp_delete_ps_fieldSchedEv(data->bgm_num, 0x168); + mBGMPsComp_delete_ps_fieldSchedEv(data->bgm_num, 0x168); - if (flag && data->bgm_num == mBGMPsComp_execute_bgm_num_get()) { - mBGMPsComp_search_cf_set_field(data->bgm_num, 10); - } + if (flag && data->bgm_num == mBGMPsComp_execute_bgm_num_get()) { + mBGMPsComp_search_cf_set_field(data->bgm_num, 10); + } } -static void mBGMPsComp_make_ps_fieldSchedEv(u8 bgm_num, int update_volume_move_ctr, int update_volume_level, int cf_flag, u16 stop_type, u8 priority); +static void mBGMPsComp_make_ps_fieldSchedEv(u8 bgm_num, int update_volume_move_ctr, int update_volume_level, + int cf_flag, u16 stop_type, u8 priority); static void mBGMFieldSchedEv_Info_ps_make(mBGMFieldSchedEv_Info* sched_ev_info, mBGMEventData* data, int priority) { - int update_volume_move_ctr = sched_ev_info->attr != mBGM_BL_ATTR_INACTIVE && sched_ev_info->old_attr == mBGM_BL_ATTR_INACTIVE; - int update_volume_level = mbgm_pattern_data[data->event_area][sched_ev_info->attr] == 1; - int crossfade = mBGMPsComp_execute_bgm_num_get() < 0 ? FALSE : TRUE; - u16 stop_type = priority == 0 ? (u16)0xA8C : (u16)0x168; + int update_volume_move_ctr = + sched_ev_info->attr != mBGM_BL_ATTR_INACTIVE && sched_ev_info->old_attr == mBGM_BL_ATTR_INACTIVE; + int update_volume_level = mbgm_pattern_data[data->event_area][sched_ev_info->attr] == 1; + int crossfade = mBGMPsComp_execute_bgm_num_get() < 0 ? FALSE : TRUE; + u16 stop_type = priority == 0 ? (u16)0xA8C : (u16)0x168; - mBGMPsComp_make_ps_fieldSchedEv(data->bgm_num, update_volume_move_ctr, update_volume_level, crossfade, stop_type, priority); + mBGMPsComp_make_ps_fieldSchedEv(data->bgm_num, update_volume_move_ctr, update_volume_level, crossfade, stop_type, + priority); } static void mBGMPsComp_volume_change_fieldSchedEv(u8 bgm_num, int update_volume_move_ctr, int update_volume_level); static void mBGMFieldSchedEv_Info_ps_volume_change(mBGMFieldSchedEv_Info* sched_ev_info, mBGMEventData* data) { - int flag = mbgm_pattern_data[data->event_area][sched_ev_info->attr] == 1; + int flag = mbgm_pattern_data[data->event_area][sched_ev_info->attr] == 1; - mBGMPsComp_volume_change_fieldSchedEv(data->bgm_num, TRUE, flag); + mBGMPsComp_volume_change_fieldSchedEv(data->bgm_num, TRUE, flag); } static void mBGMFieldSchedEv_ps_compose(mBGMFieldSchedEv* sched_ev, GAME* game) { - mBGMFieldSchedEv_Info* info = sched_ev->info; - mBGMEventData* data = mbgm_event_data; - int i; - int flag = TRUE; - int now_flag; - int old_flag; + mBGMFieldSchedEv_Info* info = sched_ev->info; + mBGMEventData* data = mbgm_event_data; + int i; + int flag = TRUE; + int now_flag; + int old_flag; - for (i = 0; i < ARRAY_COUNT(mbgm_event_data); i++) { - now_flag = (info->flag & (4 | 1)) == (4 | 1) && info->attr != mBGM_BL_ATTR_INACTIVE; - old_flag = (info->flag & (8 | 2)) == (8 | 2) && info->old_attr != mBGM_BL_ATTR_INACTIVE; + for (i = 0; i < ARRAY_COUNT(mbgm_event_data); i++) { + now_flag = (info->flag & (4 | 1)) == (4 | 1) && info->attr != mBGM_BL_ATTR_INACTIVE; + old_flag = (info->flag & (8 | 2)) == (8 | 2) && info->old_attr != mBGM_BL_ATTR_INACTIVE; - if (!now_flag && old_flag) { - mBGMFieldSchedEv_Info_ps_delete(info, data, flag); + if (!now_flag && old_flag) { + mBGMFieldSchedEv_Info_ps_delete(info, data, flag); + } + + if (now_flag && !old_flag) { + mBGMFieldSchedEv_Info_ps_make(info, data, i); + } + + if (now_flag && old_flag) { + int now_vol = mbgm_pattern_data[data->event_area][info->attr]; + int old_vol = mbgm_pattern_data[data->event_area][info->old_attr]; + + if (now_vol != old_vol && now_vol != 0 && old_vol != 0 && data->bgm_num != 127) { + mBGMFieldSchedEv_Info_ps_volume_change(info, data); + } + } + + if (flag && old_flag) { + flag = FALSE; + } + + info++; + data++; } - - if (now_flag && !old_flag) { - mBGMFieldSchedEv_Info_ps_make(info, data, i); - } - - if (now_flag && old_flag) { - int now_vol = mbgm_pattern_data[data->event_area][info->attr]; - int old_vol = mbgm_pattern_data[data->event_area][info->old_attr]; - - if (now_vol != old_vol && now_vol != 0 && old_vol != 0 && data->bgm_num != 127) { - mBGMFieldSchedEv_Info_ps_volume_change(info, data); - } - } - - if (flag && old_flag) { - flag = FALSE; - } - - info++; - data++; - } } static void mBGMFieldSchedEv_sp_flag(mBGMFieldSchedEv* sched_ev) { - mBGMFieldSchedEv_Info* info0 = &sched_ev->info[mBGMFieldSchedEv_EVENT_COUNTDOWN_5]; - mBGMFieldSchedEv_Info* info1 = &sched_ev->info[mBGMFieldSchedEv_EVENT_COUNTDOWN_6]; + mBGMFieldSchedEv_Info* info0 = &sched_ev->info[mBGMFieldSchedEv_EVENT_COUNTDOWN_5]; + mBGMFieldSchedEv_Info* info1 = &sched_ev->info[mBGMFieldSchedEv_EVENT_COUNTDOWN_6]; - if ( - ( - ((info0->flag & (4 | 1)) == (4 | 1) && info0->attr != mBGM_BL_ATTR_INACTIVE) || - ((info1->flag & (4 | 1)) == (4 | 1) && info1->attr != mBGM_BL_ATTR_INACTIVE) - ) && - mBGMClock_range_time_check( - &M_bgm.clock, - (1 << 22) | (1 << 17) | (0 << 12) | (0 << 6) | (0 << 0), - (1 << 22) | (1 << 17) | (0 << 12) | (1 << 6) | (0 << 0), - mBGMClock_CHK_MM | mBGMClock_CHK_DD | mBGMClock_CHK_hh | mBGMClock_CHK_mm | mBGMClock_CHK_ss - ) - ) { - mBGMTime_new_year_ev_flag_set(); - } - else { - mBGMTime_new_year_ev_flag_clr(); - } + if ((((info0->flag & (4 | 1)) == (4 | 1) && info0->attr != mBGM_BL_ATTR_INACTIVE) || + ((info1->flag & (4 | 1)) == (4 | 1) && info1->attr != mBGM_BL_ATTR_INACTIVE)) && + mBGMClock_range_time_check(&M_bgm.clock, (1 << 22) | (1 << 17) | (0 << 12) | (0 << 6) | (0 << 0), + (1 << 22) | (1 << 17) | (0 << 12) | (1 << 6) | (0 << 0), + mBGMClock_CHK_MM | mBGMClock_CHK_DD | mBGMClock_CHK_hh | mBGMClock_CHK_mm | + mBGMClock_CHK_ss)) { + mBGMTime_new_year_ev_flag_set(); + } else { + mBGMTime_new_year_ev_flag_clr(); + } } static void mBGMFieldSchedEv_move(mBGMFieldSchedEv* sched_ev, GAME* game) { - mBGMFieldSchedEv_info_set(sched_ev, game); - mBGMFieldSchedEv_ps_compose(sched_ev, game); - mBGMFieldSchedEv_sp_flag(sched_ev); + mBGMFieldSchedEv_info_set(sched_ev, game); + mBGMFieldSchedEv_ps_compose(sched_ev, game); + mBGMFieldSchedEv_sp_flag(sched_ev); } static void mBGMFieldSchedEv_ct(mBGMFieldSchedEv* sched_ev) { - int i; + int i; - bzero(sched_ev, sizeof(mBGMFieldSchedEv)); - for (i = 0; i < ARRAY_COUNT(sched_ev->info); i++) { - sched_ev->info[i].old_attr = mBGM_BL_ATTR_INACTIVE; - sched_ev->info[i].attr = mBGM_BL_ATTR_INACTIVE; - } + bzero(sched_ev, sizeof(mBGMFieldSchedEv)); + for (i = 0; i < ARRAY_COUNT(sched_ev->info); i++) { + sched_ev->info[i].old_attr = mBGM_BL_ATTR_INACTIVE; + sched_ev->info[i].attr = mBGM_BL_ATTR_INACTIVE; + } } /* mBGMFieldNorm */ static u8 mBGMFieldNorm_bgm_num_get(int hour) { - static u8 bgm_table[24] = { - 1, 2, 3, 4, - 5, 6, 7, 8, - 9, 10, 11, 12, - 13, 14, 15, 16, - 17, 18, 19, 20, - 21, 22, 23, 24 - }; + static u8 bgm_table[24] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24 }; - return bgm_table[hour]; + return bgm_table[hour]; } static void mBGMFieldNorm_elem_set(mBGMFieldNorm* norm) { - int hour = Common_Get(time.rtc_time.hour) % 24; + int hour = Common_Get(time.rtc_time.hour) % 24; - mBGMElem_default_set(&norm->elem); - norm->elem.bgm_num = mBGMFieldNorm_bgm_num_get(hour); + mBGMElem_default_set(&norm->elem); + norm->elem.bgm_num = mBGMFieldNorm_bgm_num_get(hour); } static void mBGMPsComp_make_ps_fieldNorm(u8 bgm_num, u16 stop_type); static void mBGMFieldNorm_make_bgm(mBGMFieldNorm* norm, GAME* game) { - if (norm->elem.bgm_num == 127) { - mBGMFieldNorm_elem_set(norm); - mBGMPsComp_make_ps_fieldNorm(norm->elem.bgm_num, 0x168); - } + if (norm->elem.bgm_num == 127) { + mBGMFieldNorm_elem_set(norm); + mBGMPsComp_make_ps_fieldNorm(norm->elem.bgm_num, 0x168); + } } static void mBGMPsComp_delete_ps_fieldNorm(u8 bgm_num, u16 stop_type); static void mBGMFieldNorm_delete_bgm(mBGMFieldNorm* norm) { - if (norm->elem.bgm_num != 127) { - mBGMPsComp_delete_ps_fieldNorm(norm->elem.bgm_num, norm->elem.stop_type0); - norm->elem.bgm_num = 127; - } + if (norm->elem.bgm_num != 127) { + mBGMPsComp_delete_ps_fieldNorm(norm->elem.bgm_num, norm->elem.stop_type0); + norm->elem.bgm_num = 127; + } } static void mBGMFieldNorm_move(mBGMFieldNorm* norm, GAME* game) { - if ( - mBGMClock_over_time_check(&M_bgm.clock, 0, mBGMClock_CHK_mm | mBGMClock_CHK_ss) && - mFI_CheckFieldData() && - mFI_GET_TYPE(mFI_GetFieldId()) == mFI_FIELD_FG - ) { - norm->delete_flag = TRUE; - norm->make_flag = TRUE; - } + if (mBGMClock_over_time_check(&M_bgm.clock, 0, mBGMClock_CHK_mm | mBGMClock_CHK_ss) && mFI_CheckFieldData() && + mFI_GET_TYPE(mFI_GetFieldId()) == mFI_FIELD_FG) { + norm->delete_flag = TRUE; + norm->make_flag = TRUE; + } - if (norm->delete_flag) { - mBGMFieldNorm_delete_bgm(norm); - } + if (norm->delete_flag) { + mBGMFieldNorm_delete_bgm(norm); + } - if (norm->make_flag) { - mBGMFieldNorm_make_bgm(norm, game); - } + if (norm->make_flag) { + mBGMFieldNorm_make_bgm(norm, game); + } - norm->make_flag = FALSE; - norm->delete_flag = FALSE; + norm->make_flag = FALSE; + norm->delete_flag = FALSE; } static void mBGMFieldNorm_make_req() { - M_bgm.field_norm.make_flag = TRUE; + M_bgm.field_norm.make_flag = TRUE; } static void mBGMFieldNorm_delete_req() { - M_bgm.field_norm.delete_flag = TRUE; + M_bgm.field_norm.delete_flag = TRUE; } static void mBGMFieldNorm_ct(mBGMFieldNorm* norm) { - bzero(norm, sizeof(mBGMFieldNorm)); - mBGMElem_default_set(&norm->elem); + bzero(norm, sizeof(mBGMFieldNorm)); + mBGMElem_default_set(&norm->elem); } /* mBGMPs[Comp] */ static void mBGMPs_counter_dec(mBGMPs* ps) { - if (ps->counter > 0) { - ps->counter--; + if (ps->counter > 0) { + ps->counter--; - if (ps->counter == 0) { - ps->cf_flags |= mBGMPs_FLAG_REMOVE; + if (ps->counter == 0) { + ps->cf_flags |= mBGMPs_FLAG_REMOVE; + } } - } } static void mBGMPsComp_ps_remove(mBGMPsComp* ps_comp, int remove_pos) { - if (remove_pos >= 0 && remove_pos < mBGM_BGMPs_NUM) { + if (remove_pos >= 0 && remove_pos < mBGM_BGMPs_NUM) { - if (remove_pos < ps_comp->ps_num && ps_comp->ps_num > 0) { - int max = ps_comp->ps_num - 1; - int i; - - for (i = remove_pos; i < max; i++) { - ps_comp->ps[i] = ps_comp->ps[i + 1]; - } + if (remove_pos < ps_comp->ps_num && ps_comp->ps_num > 0) { + int max = ps_comp->ps_num - 1; + int i; - bzero(&ps_comp->ps[max], sizeof(mBGMPs)); - ps_comp->ps_num = max; + for (i = remove_pos; i < max; i++) { + ps_comp->ps[i] = ps_comp->ps[i + 1]; + } + + bzero(&ps_comp->ps[max], sizeof(mBGMPs)); + ps_comp->ps_num = max; + } } - } } static int mBGMPsComp_search_insert_pos_kategorie(mBGMPsComp* ps_comp, int kategorie, u8 priority) { - mBGMPs* ps = ps_comp->ps; - int max = ps_comp->ps_num; - int i; - int res; + mBGMPs* ps = ps_comp->ps; + int max = ps_comp->ps_num; + int i; + int res; - if (max < mBGM_BGMPs_NUM) { - res = max; - for (i = 0; i < max; i++, ps++) { - if ((kategorie == ps->kategorie && priority < ps->priority) || kategorie < ps->kategorie) { - res = i; - break; - } + if (max < mBGM_BGMPs_NUM) { + res = max; + for (i = 0; i < max; i++, ps++) { + if ((kategorie == ps->kategorie && priority < ps->priority) || kategorie < ps->kategorie) { + res = i; + break; + } + } + } else { + res = -1; } - } - else { - res = -1; - } - return res; + return res; } -static int mBGMPsComp_search_pos_kategorie_bgm_num(mBGMPsComp* ps_comp, int kategorie, u8 bgm_num, int counter_flag, int del_pass) { - int kategorie_valid = kategorie < mBGM_KATEGORIE_NUM; - int bgm_is_reset = bgm_num != 127; - int res = -1; - u8 delete_mask = del_pass == 0; +static int mBGMPsComp_search_pos_kategorie_bgm_num(mBGMPsComp* ps_comp, int kategorie, u8 bgm_num, int counter_flag, + int del_pass) { + int kategorie_valid = kategorie < mBGM_KATEGORIE_NUM; + int bgm_is_reset = bgm_num != 127; + int res = -1; + u8 delete_mask = del_pass == 0; - if (kategorie_valid || bgm_is_reset) { - mBGMPs* ps = ps_comp->ps; - int i = 0; - int max = ps_comp->ps_num; + if (kategorie_valid || bgm_is_reset) { + mBGMPs* ps = ps_comp->ps; + int i = 0; + int max = ps_comp->ps_num; - for (i; i < max; i++, ps++) { - if ( - (!kategorie_valid || ps->kategorie == kategorie) && - (!bgm_is_reset || ps->elem.bgm_num == bgm_num) && - (counter_flag == FALSE || (ps->counter < 0 && (ps->cf_flags & mBGMPs_FLAG_FADEOUT) == 0)) && - ((ps->cf_flags & delete_mask) == 0) - ) { - res = i; - break; - } + for (i; i < max; i++, ps++) { + if ((!kategorie_valid || ps->kategorie == kategorie) && (!bgm_is_reset || ps->elem.bgm_num == bgm_num) && + (counter_flag == FALSE || (ps->counter < 0 && (ps->cf_flags & mBGMPs_FLAG_FADEOUT) == 0)) && + ((ps->cf_flags & delete_mask) == 0)) { + res = i; + break; + } + } } - } - return res; + return res; } static void mBGMPsComp_shift_behind(mBGMPsComp* ps_comp, int shift_idx) { - if (ps_comp->ps_num != 0) { - int i; + if (ps_comp->ps_num != 0) { + int i; - for (i = ps_comp->ps_num - 1; i >= shift_idx; i--) { - bcopy(&ps_comp->ps[i], &ps_comp->ps[i + 1], sizeof(mBGMPs)); + for (i = ps_comp->ps_num - 1; i >= shift_idx; i--) { + bcopy(&ps_comp->ps[i], &ps_comp->ps[i + 1], sizeof(mBGMPs)); + } } - } - bzero(&ps_comp->ps[shift_idx], sizeof(mBGMPs)); - ps_comp->ps_num++; + bzero(&ps_comp->ps[shift_idx], sizeof(mBGMPs)); + ps_comp->ps_num++; } static void mBGMPsComp_all_ps_bitclr(mBGMPsComp* ps_comp, u8 bits) { - mBGMPs* ps = ps_comp->ps; - int max = ps_comp->ps_num; - int i; + mBGMPs* ps = ps_comp->ps; + int max = ps_comp->ps_num; + int i; - for (i = 0; i < max; i++, ps++) { - ps->cf_flags &= ~bits; - } + for (i = 0; i < max; i++, ps++) { + ps->cf_flags &= ~bits; + } } static int mBGMPsComp_execute_ps_pos_get(mBGMPsComp* ps_comp) { - mBGMPs* ps = ps_comp->ps; - int max = ps_comp->ps_num; - int i; - int idx = -1; + mBGMPs* ps = ps_comp->ps; + int max = ps_comp->ps_num; + int i; + int idx = -1; - for (i = 0; i < max; i++, ps++) { - if ((ps->cf_flags & mBGMPs_FLAG_EXECUTE)) { - idx = i; - break; + for (i = 0; i < max; i++, ps++) { + if ((ps->cf_flags & mBGMPs_FLAG_EXECUTE)) { + idx = i; + break; + } } - } - return idx; + return idx; } static mBGMPs* mBGMPsComp_high_ps_not_delete(mBGMPsComp* ps_comp, int max_pos) { - mBGMPs* ps = ps_comp->ps; - mBGMPs* high_ps = NULL; - int i; + mBGMPs* ps = ps_comp->ps; + mBGMPs* high_ps = NULL; + int i; - for (i = 0; i < max_pos; i++, ps++) { - if ((ps->cf_flags & mBGMPs_FLAG_REMOVE) == 0) { - high_ps = ps; - break; + for (i = 0; i < max_pos; i++, ps++) { + if ((ps->cf_flags & mBGMPs_FLAG_REMOVE) == 0) { + high_ps = ps; + break; + } } - } - return high_ps; + return high_ps; } static void mBGMPsComp_main_req_stop(mBGMPsComp* ps_comp) { - mBGMPs* ps = ps_comp->ps; - int execute_pos = mBGMPsComp_execute_ps_pos_get(ps_comp); + mBGMPs* ps = ps_comp->ps; + int execute_pos = mBGMPsComp_execute_ps_pos_get(ps_comp); - if (execute_pos >= 0) { - ps += execute_pos; - - if ((ps->cf_flags & mBGMPs_FLAG_SILENT) == 0) { - if (execute_pos > 0) { - mBGMPs* high_ps = mBGMPsComp_high_ps_not_delete(ps_comp, execute_pos); + if (execute_pos >= 0) { + ps += execute_pos; - if (high_ps != NULL) { - ps_comp->stop.req_flag = TRUE; - ps_comp->stop.type = high_ps->elem.stop_type1; - return; + if ((ps->cf_flags & mBGMPs_FLAG_SILENT) == 0) { + if (execute_pos > 0) { + mBGMPs* high_ps = mBGMPsComp_high_ps_not_delete(ps_comp, execute_pos); + + if (high_ps != NULL) { + ps_comp->stop.req_flag = TRUE; + ps_comp->stop.type = high_ps->elem.stop_type1; + return; + } + } + + if ((ps->cf_flags & mBGMPs_FLAG_REMOVE) && (ps->cf_flags & mBGMPs_FLAG_LOST) == 0) { + ps_comp->stop.req_flag = TRUE; + ps_comp->stop.type = ps->elem.stop_type0; + } } - } - - if ((ps->cf_flags & mBGMPs_FLAG_REMOVE) && (ps->cf_flags & mBGMPs_FLAG_LOST) == 0) { - ps_comp->stop.req_flag = TRUE; - ps_comp->stop.type = ps->elem.stop_type0; - } } - } } static void mBGMPsComp_main_remove(mBGMPsComp* ps_comp) { - mBGMPs* ps; - int i; + mBGMPs* ps; + int i; - for (i = ps_comp->ps_num - 1, ps = &ps_comp->ps[i]; i >= 0; i--, ps--) { - if ((ps->cf_flags & mBGMPs_FLAG_REMOVE)) { - ps->cf_flags &= ~mBGMPs_FLAG_REMOVE; - mBGMPsComp_ps_remove(ps_comp, i); + for (i = ps_comp->ps_num - 1, ps = &ps_comp->ps[i]; i >= 0; i--, ps--) { + if ((ps->cf_flags & mBGMPs_FLAG_REMOVE)) { + ps->cf_flags &= ~mBGMPs_FLAG_REMOVE; + mBGMPsComp_ps_remove(ps_comp, i); + } } - } } static void mBGMPsComp_main_req_start(mBGMPsComp* ps_comp) { - if (ps_comp->ps_num > 0) { - if ((ps_comp->ps[0].cf_flags & mBGMPs_FLAG_EXECUTE) == 0) { - if ((ps_comp->ps[0].cf_flags & mBGMPs_FLAG_SILENT) == 0) { - ps_comp->start.req_flag = TRUE; - ps_comp->start.flags = (ps_comp->ps[0].cf_flags >> 3) & 1; // crossfade (mBGMPs_FLAG_CROSSFADE) - ps_comp->start.bgm_num = ps_comp->ps[0].elem.bgm_num; + if (ps_comp->ps_num > 0) { + if ((ps_comp->ps[0].cf_flags & mBGMPs_FLAG_EXECUTE) == 0) { + if ((ps_comp->ps[0].cf_flags & mBGMPs_FLAG_SILENT) == 0) { + ps_comp->start.req_flag = TRUE; + ps_comp->start.flags = (ps_comp->ps[0].cf_flags >> 3) & 1; // crossfade (mBGMPs_FLAG_CROSSFADE) + ps_comp->start.bgm_num = ps_comp->ps[0].elem.bgm_num; - if (mBGM_check_MD(ps_comp->ps[0].elem.bgm_num) == FALSE) { - ps_comp->ps[0].cf_flags |= mBGMPs_FLAG_UPDATE_VOLUME; + if (mBGM_check_MD(ps_comp->ps[0].elem.bgm_num) == FALSE) { + ps_comp->ps[0].cf_flags |= mBGMPs_FLAG_UPDATE_VOLUME; + } + } + + mBGMPsComp_all_ps_bitclr(ps_comp, mBGMPs_FLAG_EXECUTE); + ps_comp->ps[0].cf_flags |= mBGMPs_FLAG_EXECUTE; } - } - mBGMPsComp_all_ps_bitclr(ps_comp, mBGMPs_FLAG_EXECUTE); - ps_comp->ps[0].cf_flags |= mBGMPs_FLAG_EXECUTE; + mBGMPsComp_all_ps_bitclr(ps_comp, mBGMPs_FLAG_CROSSFADE); } - - mBGMPsComp_all_ps_bitclr(ps_comp, mBGMPs_FLAG_CROSSFADE); - } } static void mBGMPsComp_main_req_pause(mBGMPsComp* ps_comp) { - if (ps_comp->pause_state == 1 || ps_comp->pause_state == 3) { - ps_comp->pause.mode = 1; - ps_comp->pause.req_flag = TRUE; - } - else if (ps_comp->pause_state == 2) { - ps_comp->pause.mode = 2; - ps_comp->pause.req_flag = TRUE; - } - else if (ps_comp->pause_state == 5) { - ps_comp->pause.mode = 0; - ps_comp->pause.req_flag = TRUE; - } + if (ps_comp->pause_state == 1 || ps_comp->pause_state == 3) { + ps_comp->pause.mode = 1; + ps_comp->pause.req_flag = TRUE; + } else if (ps_comp->pause_state == 2) { + ps_comp->pause.mode = 2; + ps_comp->pause.req_flag = TRUE; + } else if (ps_comp->pause_state == 5) { + ps_comp->pause.mode = 0; + ps_comp->pause.req_flag = TRUE; + } } static void mBGMPsComp_main_req_md(mBGMPsComp* ps_comp) { - if (ps_comp->md.move_flag) { - ps_comp->md.req_flag = TRUE; - } + if (ps_comp->md.move_flag) { + ps_comp->md.req_flag = TRUE; + } } static void mBGMPsComp_main_md_move(mBGMPsComp* ps_comp) { - if (ps_comp->md.delete_flag) { - ps_comp->md.move_flag = FALSE; - ps_comp->md.delete_flag = FALSE; - } + if (ps_comp->md.delete_flag) { + ps_comp->md.move_flag = FALSE; + ps_comp->md.delete_flag = FALSE; + } - if (ps_comp->md.make_flag) { - ps_comp->md.move_flag = TRUE; - ps_comp->md.make_flag = FALSE; - } + if (ps_comp->md.make_flag) { + ps_comp->md.move_flag = TRUE; + ps_comp->md.make_flag = FALSE; + } } static void mBGMPsComp_main_req_volume_ps(mBGMPsComp* ps_comp) { - if (ps_comp->ps_num > 0) { - if ((ps_comp->ps[0].cf_flags & mBGMPs_FLAG_UPDATE_VOLUME)) { - if ((ps_comp->ps[0].cf_flags & mBGMPs_FLAG_UPDATE_VOLUME_MOVE_CTR)) { - ps_comp->volume.ps_volume_move_ctr = 90; - } - else { - ps_comp->volume.ps_volume_move_ctr = 0; - } + if (ps_comp->ps_num > 0) { + if ((ps_comp->ps[0].cf_flags & mBGMPs_FLAG_UPDATE_VOLUME)) { + if ((ps_comp->ps[0].cf_flags & mBGMPs_FLAG_UPDATE_VOLUME_MOVE_CTR)) { + ps_comp->volume.ps_volume_move_ctr = 90; + } else { + ps_comp->volume.ps_volume_move_ctr = 0; + } - if ((ps_comp->ps[0].cf_flags & mBGMPs_FLAG_UPDATE_VOLUME_LEVEL)) { - ps_comp->volume.ps_volume = 0.5f; - } - else { - ps_comp->volume.ps_volume = 1.0f; - } + if ((ps_comp->ps[0].cf_flags & mBGMPs_FLAG_UPDATE_VOLUME_LEVEL)) { + ps_comp->volume.ps_volume = 0.5f; + } else { + ps_comp->volume.ps_volume = 1.0f; + } - ps_comp->volume.ps_req_flag = TRUE; + ps_comp->volume.ps_req_flag = TRUE; + } + + mBGMPsComp_all_ps_bitclr(ps_comp, mBGMPs_FLAG_UPDATE_VOLUME_MOVE_CTR | mBGMPs_FLAG_UPDATE_VOLUME); } - mBGMPsComp_all_ps_bitclr(ps_comp, mBGMPs_FLAG_UPDATE_VOLUME_MOVE_CTR | mBGMPs_FLAG_UPDATE_VOLUME); - } - - if (mBGMPsComp_execute_bgm_num_get() < 0) { - ps_comp->volume.ps_volume = -1.0f; - } + if (mBGMPsComp_execute_bgm_num_get() < 0) { + ps_comp->volume.ps_volume = -1.0f; + } } static void mBGMPsComp_main_req_volume_fishing(mBGMPsComp* ps_comp) { - if (ps_comp->fishing_state == 1) { - ps_comp->fishing_state = 2; - ps_comp->volume.fishing_volume = 0.6f; - ps_comp->volume.fishing_volume_move_ctr = 300; - ps_comp->volume.fishing_req_flag = TRUE; - } - else if (ps_comp->fishing_state == 3) { - ps_comp->fishing_state = 0; - ps_comp->volume.fishing_volume = -1.0f; - ps_comp->volume.fishing_volume_move_ctr = 35; - - if (ps_comp->ps_num <= 0 || mBGM_check_MD(ps_comp->ps[0].elem.bgm_num) == FALSE) { - ps_comp->volume.fishing_req_flag = TRUE; + if (ps_comp->fishing_state == 1) { + ps_comp->fishing_state = 2; + ps_comp->volume.fishing_volume = 0.6f; + ps_comp->volume.fishing_volume_move_ctr = 300; + ps_comp->volume.fishing_req_flag = TRUE; + } else if (ps_comp->fishing_state == 3) { + ps_comp->fishing_state = 0; + ps_comp->volume.fishing_volume = -1.0f; + ps_comp->volume.fishing_volume_move_ctr = 35; + + if (ps_comp->ps_num <= 0 || mBGM_check_MD(ps_comp->ps[0].elem.bgm_num) == FALSE) { + ps_comp->volume.fishing_req_flag = TRUE; + } } - } } static void mBGMPsComp_main_req_volume_collect_insects(mBGMPsComp* ps_comp) { - if (ps_comp->collect_insects_state == 1) { - ps_comp->collect_insects_state = 2; - ps_comp->volume.collect_insects_volume = 0.65f; - ps_comp->volume.collect_insects_volume_move_ctr = 100; - ps_comp->volume.collect_insects_req_flag = TRUE; - } - else if (ps_comp->collect_insects_state == 3) { - ps_comp->collect_insects_state = 0; - ps_comp->volume.collect_insects_volume = -1.0f; - ps_comp->volume.collect_insects_volume_move_ctr = 17; - - if (ps_comp->ps_num <= 0 || mBGM_check_MD(ps_comp->ps[0].elem.bgm_num) == FALSE) { - ps_comp->volume.collect_insects_req_flag = TRUE; + if (ps_comp->collect_insects_state == 1) { + ps_comp->collect_insects_state = 2; + ps_comp->volume.collect_insects_volume = 0.65f; + ps_comp->volume.collect_insects_volume_move_ctr = 100; + ps_comp->volume.collect_insects_req_flag = TRUE; + } else if (ps_comp->collect_insects_state == 3) { + ps_comp->collect_insects_state = 0; + ps_comp->volume.collect_insects_volume = -1.0f; + ps_comp->volume.collect_insects_volume_move_ctr = 17; + + if (ps_comp->ps_num <= 0 || mBGM_check_MD(ps_comp->ps[0].elem.bgm_num) == FALSE) { + ps_comp->volume.collect_insects_req_flag = TRUE; + } } - } } static void mBGMPsComp_main_req_volume_talk(mBGMPsComp* ps_comp) { - if (ps_comp->talk_state == 1) { - ps_comp->talk_state = 2; - ps_comp->volume.talk_volume = 0.7f; - ps_comp->volume.talk_req_flag = TRUE; - } - else if (ps_comp->talk_state == 3) { - ps_comp->talk_state = 0; - ps_comp->volume.talk_volume = -1.0f; - - if (ps_comp->ps_num <= 0 || mBGM_check_MD(ps_comp->ps[0].elem.bgm_num) == FALSE) { - ps_comp->volume.talk_req_flag = TRUE; + if (ps_comp->talk_state == 1) { + ps_comp->talk_state = 2; + ps_comp->volume.talk_volume = 0.7f; + ps_comp->volume.talk_req_flag = TRUE; + } else if (ps_comp->talk_state == 3) { + ps_comp->talk_state = 0; + ps_comp->volume.talk_volume = -1.0f; + + if (ps_comp->ps_num <= 0 || mBGM_check_MD(ps_comp->ps[0].elem.bgm_num) == FALSE) { + ps_comp->volume.talk_req_flag = TRUE; + } } - } } static void mBGMPsComp_main_req_volume_boat(mBGMPsComp* ps_comp) { - if (ps_comp->boat_state == 1) { - ps_comp->boat_state = 2; - ps_comp->volume.boat_volume = 0.7f; - ps_comp->volume.boat_req_flag = TRUE; - } - else if (ps_comp->boat_state == 3) { - ps_comp->boat_state = 0; - ps_comp->volume.boat_volume = -1.0f; - - if (ps_comp->ps_num <= 0 || mBGM_check_MD(ps_comp->ps[0].elem.bgm_num) == FALSE) { - ps_comp->volume.boat_req_flag = TRUE; + if (ps_comp->boat_state == 1) { + ps_comp->boat_state = 2; + ps_comp->volume.boat_volume = 0.7f; + ps_comp->volume.boat_req_flag = TRUE; + } else if (ps_comp->boat_state == 3) { + ps_comp->boat_state = 0; + ps_comp->volume.boat_volume = -1.0f; + + if (ps_comp->ps_num <= 0 || mBGM_check_MD(ps_comp->ps[0].elem.bgm_num) == FALSE) { + ps_comp->volume.boat_req_flag = TRUE; + } } - } } static void mBGMPsComp_main_req_volume_pause(mBGMPsComp* ps_comp) { - if (ps_comp->pause_state == 1) { - ps_comp->pause_state = 4; - ps_comp->volume.pause_volume = 0.5f; - ps_comp->volume.pause_volume_move_ctr = 2; - ps_comp->volume.pause_req_flag = TRUE; - } - else if (ps_comp->pause_state == 2) { - ps_comp->pause_state = 4; - ps_comp->volume.pause_volume = 0.0f; - ps_comp->volume.pause_volume_move_ctr = 2; - ps_comp->volume.pause_req_flag = TRUE; - } - else if (ps_comp->pause_state == 3) { - ps_comp->pause_state = 4; - ps_comp->volume.pause_volume = 0.5f; - ps_comp->volume.pause_volume_move_ctr = 2; - ps_comp->volume.pause_req_flag = TRUE; - } - else if (ps_comp->pause_state == 5) { - ps_comp->pause_state = 0; - ps_comp->volume.pause_volume = -1.0f; - ps_comp->volume.pause_volume_move_ctr = 2; - - if (ps_comp->ps_num <= 0 || mBGM_check_MD(ps_comp->ps[0].elem.bgm_num) == FALSE) { - ps_comp->volume.pause_req_flag = TRUE; + if (ps_comp->pause_state == 1) { + ps_comp->pause_state = 4; + ps_comp->volume.pause_volume = 0.5f; + ps_comp->volume.pause_volume_move_ctr = 2; + ps_comp->volume.pause_req_flag = TRUE; + } else if (ps_comp->pause_state == 2) { + ps_comp->pause_state = 4; + ps_comp->volume.pause_volume = 0.0f; + ps_comp->volume.pause_volume_move_ctr = 2; + ps_comp->volume.pause_req_flag = TRUE; + } else if (ps_comp->pause_state == 3) { + ps_comp->pause_state = 4; + ps_comp->volume.pause_volume = 0.5f; + ps_comp->volume.pause_volume_move_ctr = 2; + ps_comp->volume.pause_req_flag = TRUE; + } else if (ps_comp->pause_state == 5) { + ps_comp->pause_state = 0; + ps_comp->volume.pause_volume = -1.0f; + ps_comp->volume.pause_volume_move_ctr = 2; + + if (ps_comp->ps_num <= 0 || mBGM_check_MD(ps_comp->ps[0].elem.bgm_num) == FALSE) { + ps_comp->volume.pause_req_flag = TRUE; + } } - } } static void mBGMPsComp_main_req_volume(mBGMPsComp* ps_comp) { - f32 t_ps_vol; - f32 t_talk_vol; - f32 t_pause_vol; - f32 t_collect_insects_vol; - f32 t_fishing_vol; - f32 t_boat_vol; - f32 final_vol; - u16 final_vol_move_ctr; - mBGMPs* ps = &ps_comp->ps[0]; - int ignore_talk = ps_comp->ps_num > 0 ? mBGM_check_ignore_talk_volume(ps->elem.bgm_num) : FALSE; - int ignore_collect_insects = ps_comp->ps_num > 0 ? mBGM_check_ignore_collect_insects_volume(ps->elem.bgm_num) : FALSE; + f32 t_ps_vol; + f32 t_talk_vol; + f32 t_pause_vol; + f32 t_collect_insects_vol; + f32 t_fishing_vol; + f32 t_boat_vol; + f32 final_vol; + u16 final_vol_move_ctr; + mBGMPs* ps = &ps_comp->ps[0]; + int ignore_talk = ps_comp->ps_num > 0 ? mBGM_check_ignore_talk_volume(ps->elem.bgm_num) : FALSE; + int ignore_collect_insects = + ps_comp->ps_num > 0 ? mBGM_check_ignore_collect_insects_volume(ps->elem.bgm_num) : FALSE; - mBGMPsComp_main_req_volume_ps(ps_comp); - mBGMPsComp_main_req_volume_fishing(ps_comp); - mBGMPsComp_main_req_volume_collect_insects(ps_comp); - mBGMPsComp_main_req_volume_talk(ps_comp); - mBGMPsComp_main_req_volume_boat(ps_comp); - mBGMPsComp_main_req_volume_pause(ps_comp); + mBGMPsComp_main_req_volume_ps(ps_comp); + mBGMPsComp_main_req_volume_fishing(ps_comp); + mBGMPsComp_main_req_volume_collect_insects(ps_comp); + mBGMPsComp_main_req_volume_talk(ps_comp); + mBGMPsComp_main_req_volume_boat(ps_comp); + mBGMPsComp_main_req_volume_pause(ps_comp); - t_ps_vol = ps_comp->volume.ps_volume; - if (t_ps_vol < 0.0f) { - t_fishing_vol = -1.0f; - t_collect_insects_vol = -1.0f; - t_talk_vol = -1.0f; - t_boat_vol = -1.0f; - t_pause_vol = -1.0f; - } - else { - t_fishing_vol = (ps_comp->volume.fishing_volume < 0.0f || ps_comp->volume.fishing_volume > t_ps_vol || ignore_collect_insects) ? t_ps_vol : ps_comp->volume.fishing_volume; - t_collect_insects_vol = (ps_comp->volume.collect_insects_volume < 0.0f || ps_comp->volume.collect_insects_volume > t_fishing_vol || ignore_collect_insects) ? t_fishing_vol : ps_comp->volume.collect_insects_volume; - t_talk_vol = (ps_comp->volume.talk_volume < 0.0f || ps_comp->volume.talk_volume > t_collect_insects_vol || ignore_talk) ? t_collect_insects_vol : ps_comp->volume.talk_volume; - t_boat_vol = (ps_comp->volume.boat_volume < 0.0f || ps_comp->volume.boat_volume > t_talk_vol) ? t_talk_vol : ps_comp->volume.boat_volume; - t_pause_vol = (ps_comp->volume.pause_volume < 0.0f || ps_comp->volume.pause_volume > t_boat_vol) ? t_boat_vol : ps_comp->volume.pause_volume; - } - - final_vol = -1.0f; - final_vol_move_ctr = 0; - - if (ps_comp->volume.ps_req_flag) { - final_vol = t_ps_vol; - final_vol_move_ctr = ps_comp->volume.ps_volume_move_ctr; - } - - if (ps_comp->volume.fishing_req_flag && !ignore_collect_insects) { - final_vol = t_fishing_vol; - final_vol_move_ctr = ps_comp->volume.fishing_volume_move_ctr; - } - - if (ps_comp->volume.collect_insects_req_flag && !ignore_collect_insects) { - final_vol = t_collect_insects_vol; - final_vol_move_ctr = ps_comp->volume.collect_insects_volume_move_ctr; - } - - if (ps_comp->volume.talk_req_flag && !ignore_talk) { - final_vol = t_talk_vol; - final_vol_move_ctr = 30; - } - - if (ps_comp->volume.boat_req_flag) { - final_vol = t_boat_vol; - final_vol_move_ctr = 30; - } - - if (ps_comp->volume.pause_req_flag) { - final_vol = t_pause_vol; - final_vol_move_ctr = ps_comp->volume.pause_volume_move_ctr; - } - - if (ps_comp->pause_state == 4) { - if ((final_vol < 0.0f) == FALSE) { - final_vol = t_pause_vol; + t_ps_vol = ps_comp->volume.ps_volume; + if (t_ps_vol < 0.0f) { + t_fishing_vol = -1.0f; + t_collect_insects_vol = -1.0f; + t_talk_vol = -1.0f; + t_boat_vol = -1.0f; + t_pause_vol = -1.0f; + } else { + t_fishing_vol = (ps_comp->volume.fishing_volume < 0.0f || ps_comp->volume.fishing_volume > t_ps_vol || + ignore_collect_insects) + ? t_ps_vol + : ps_comp->volume.fishing_volume; + t_collect_insects_vol = (ps_comp->volume.collect_insects_volume < 0.0f || + ps_comp->volume.collect_insects_volume > t_fishing_vol || ignore_collect_insects) + ? t_fishing_vol + : ps_comp->volume.collect_insects_volume; + t_talk_vol = + (ps_comp->volume.talk_volume < 0.0f || ps_comp->volume.talk_volume > t_collect_insects_vol || ignore_talk) + ? t_collect_insects_vol + : ps_comp->volume.talk_volume; + t_boat_vol = (ps_comp->volume.boat_volume < 0.0f || ps_comp->volume.boat_volume > t_talk_vol) + ? t_talk_vol + : ps_comp->volume.boat_volume; + t_pause_vol = (ps_comp->volume.pause_volume < 0.0f || ps_comp->volume.pause_volume > t_boat_vol) + ? t_boat_vol + : ps_comp->volume.pause_volume; } - } - else if (ps_comp->boat_state == 2) { - if ((final_vol < 0.0f) == FALSE) { - final_vol = t_boat_vol; - } - } - else if (ps_comp->talk_state == 2) { - if ((final_vol < 0.0f) == FALSE) { - final_vol = t_talk_vol; - } - } - else if (ps_comp->collect_insects_state == 2) { - if ((final_vol < 0.0f) == FALSE) { - final_vol = t_collect_insects_vol; - } - } - else if (ps_comp->fishing_state == 2) { - if ((final_vol < 0.0f) == FALSE) { - final_vol = t_fishing_vol; - } - } - if ((final_vol < 0.0f) == FALSE) { - ps_comp->volume.main_volume = final_vol; - ps_comp->volume.main_volume_move_ctr = final_vol_move_ctr; - ps_comp->volume.main_req_flag = TRUE; - } + final_vol = -1.0f; + final_vol_move_ctr = 0; - ps_comp->volume.ps_req_flag = FALSE; - ps_comp->volume.fishing_req_flag = FALSE; - ps_comp->volume.collect_insects_req_flag = FALSE; - ps_comp->volume.talk_req_flag = FALSE; - ps_comp->volume.boat_req_flag = FALSE; - ps_comp->volume.pause_req_flag = FALSE; + if (ps_comp->volume.ps_req_flag) { + final_vol = t_ps_vol; + final_vol_move_ctr = ps_comp->volume.ps_volume_move_ctr; + } + + if (ps_comp->volume.fishing_req_flag && !ignore_collect_insects) { + final_vol = t_fishing_vol; + final_vol_move_ctr = ps_comp->volume.fishing_volume_move_ctr; + } + + if (ps_comp->volume.collect_insects_req_flag && !ignore_collect_insects) { + final_vol = t_collect_insects_vol; + final_vol_move_ctr = ps_comp->volume.collect_insects_volume_move_ctr; + } + + if (ps_comp->volume.talk_req_flag && !ignore_talk) { + final_vol = t_talk_vol; + final_vol_move_ctr = 30; + } + + if (ps_comp->volume.boat_req_flag) { + final_vol = t_boat_vol; + final_vol_move_ctr = 30; + } + + if (ps_comp->volume.pause_req_flag) { + final_vol = t_pause_vol; + final_vol_move_ctr = ps_comp->volume.pause_volume_move_ctr; + } + + if (ps_comp->pause_state == 4) { + if ((final_vol < 0.0f) == FALSE) { + final_vol = t_pause_vol; + } + } else if (ps_comp->boat_state == 2) { + if ((final_vol < 0.0f) == FALSE) { + final_vol = t_boat_vol; + } + } else if (ps_comp->talk_state == 2) { + if ((final_vol < 0.0f) == FALSE) { + final_vol = t_talk_vol; + } + } else if (ps_comp->collect_insects_state == 2) { + if ((final_vol < 0.0f) == FALSE) { + final_vol = t_collect_insects_vol; + } + } else if (ps_comp->fishing_state == 2) { + if ((final_vol < 0.0f) == FALSE) { + final_vol = t_fishing_vol; + } + } + + if ((final_vol < 0.0f) == FALSE) { + ps_comp->volume.main_volume = final_vol; + ps_comp->volume.main_volume_move_ctr = final_vol_move_ctr; + ps_comp->volume.main_req_flag = TRUE; + } + + ps_comp->volume.ps_req_flag = FALSE; + ps_comp->volume.fishing_req_flag = FALSE; + ps_comp->volume.collect_insects_req_flag = FALSE; + ps_comp->volume.talk_req_flag = FALSE; + ps_comp->volume.boat_req_flag = FALSE; + ps_comp->volume.pause_req_flag = FALSE; } static void mBGMPsComp_MDPlayerPos_main_inform_sound(mBGMPsComp_MDPlayerPos* md) { - if (md->req_flag) { - sAdo_MDPlayerPos(&md->pos, md->angle, md->md_type_no, md->ongen_no); - md->req_flag = FALSE; - } + if (md->req_flag) { + sAdo_MDPlayerPos(&md->pos, md->angle, md->md_type_no, md->ongen_no); + md->req_flag = FALSE; + } } static void mBGMPsComp_arm_delete(); static void mBGMPsComp_Arm_main_inform_sound(mBGMPsComp_Arm* arm) { - if (arm->req_flag) { - if (mBGMPsComp_execute_bgm_num_get() == 43) { - sAdos_TTKK_ARM(arm->arm_state); + if (arm->req_flag) { + if (mBGMPsComp_execute_bgm_num_get() == 43) { + sAdos_TTKK_ARM(arm->arm_state); - if (arm->arm_state == 0) { - mBGMPsComp_arm_delete(); - } + if (arm->arm_state == 0) { + mBGMPsComp_arm_delete(); + } + } else { + mBGMPsComp_arm_delete(); + } } - else { - mBGMPsComp_arm_delete(); - } - } } static void mBGMPsComp_Stop_main_inform_sound(mBGMPsComp_Stop* stop) { - if (stop->req_flag) { - sAdo_BgmStop(stop->type); - stop->req_flag = FALSE; - } + if (stop->req_flag) { + sAdo_BgmStop(stop->type); + stop->req_flag = FALSE; + } } static void mBGMPsComp_arm_make(u8 state); static void mBGMPsComp_Start_main_inform_sound(mBGMPsComp_Start* start) { - if (start->req_flag) { - if (start->flags != 0) { - sAdo_BgmCrossfadeStart(start->bgm_num); - } - else { - sAdo_BgmStart(start->bgm_num); + if (start->req_flag) { + if (start->flags != 0) { + sAdo_BgmCrossfadeStart(start->bgm_num); + } else { + sAdo_BgmStart(start->bgm_num); - if (start->bgm_num == 43) { - if (Save_Get(scene_no) == SCENE_PLAYERSELECT_2) { - mBGMPsComp_arm_make(1); + if (start->bgm_num == 43) { + if (Save_Get(scene_no) == SCENE_PLAYERSELECT_2) { + mBGMPsComp_arm_make(1); + } else { + mBGMPsComp_arm_make(0); + } + } } - else { - mBGMPsComp_arm_make(0); - } - } - } - start->req_flag = FALSE; - } + start->req_flag = FALSE; + } } static void mBGMPsComp_Volume_main_inform_sound(mBGMPsComp_Volume* volume) { - if (volume->main_req_flag) { - sAdo_BGMVolume(volume->main_volume, volume->main_volume_move_ctr); - volume->main_req_flag = FALSE; - } + if (volume->main_req_flag) { + sAdo_BGMVolume(volume->main_volume, volume->main_volume_move_ctr); + volume->main_req_flag = FALSE; + } } static void mBGMPsComp_Pause_main_inform_sound(mBGMPsComp_Pause* pause) { - if (pause->req_flag) { - sAdo_Pause(pause->mode); - pause->req_flag = FALSE; - } + if (pause->req_flag) { + sAdo_Pause(pause->mode); + pause->req_flag = FALSE; + } } static void mBGMPsComp_Museum_main_inform_sound(mBGMPsComp_Museum* museum) { - if (museum->req_flag) { - museum->req_flag--; + if (museum->req_flag) { + museum->req_flag--; - if (museum->req_flag == 0) { - sAdo_Museum(museum->type); + if (museum->req_flag == 0) { + sAdo_Museum(museum->type); + } } - } } static void mBGMPsComp_main_inform_sound(mBGMPsComp* ps_comp) { - mBGMPsComp_MDPlayerPos_main_inform_sound(&ps_comp->md); - mBGMPsComp_Arm_main_inform_sound(&ps_comp->arm); - mBGMPsComp_Stop_main_inform_sound(&ps_comp->stop); - mBGMPsComp_Start_main_inform_sound(&ps_comp->start); - mBGMPsComp_Pause_main_inform_sound(&ps_comp->pause); - mBGMPsComp_Volume_main_inform_sound(&ps_comp->volume); - mBGMPsComp_Museum_main_inform_sound(&ps_comp->museum); + mBGMPsComp_MDPlayerPos_main_inform_sound(&ps_comp->md); + mBGMPsComp_Arm_main_inform_sound(&ps_comp->arm); + mBGMPsComp_Stop_main_inform_sound(&ps_comp->stop); + mBGMPsComp_Start_main_inform_sound(&ps_comp->start); + mBGMPsComp_Pause_main_inform_sound(&ps_comp->pause); + mBGMPsComp_Volume_main_inform_sound(&ps_comp->volume); + mBGMPsComp_Museum_main_inform_sound(&ps_comp->museum); } static void mBGMPsComp_main_counter_dec(mBGMPsComp* ps_comp) { - mBGMPs* ps = ps_comp->ps; - int i; - int max = ps_comp->ps_num; + mBGMPs* ps = ps_comp->ps; + int i; + int max = ps_comp->ps_num; - for (i = 0; i < max; i++, ps++) { - mBGMPs_counter_dec(ps); - } + for (i = 0; i < max; i++, ps++) { + mBGMPs_counter_dec(ps); + } } static void mBGMPsComp_main_fo_check(mBGMPsComp* ps_comp) { - mBGMPs* ps = ps_comp->ps; - int i; - int max = ps_comp->ps_num; + mBGMPs* ps = ps_comp->ps; + int i; + int max = ps_comp->ps_num; - for (i = 0; i < max; i++, ps++) { - if (ps->cf_flags & mBGMPs_FLAG_FADEOUT) { - int execute_pos = mBGMPsComp_execute_ps_pos_get(ps_comp); + for (i = 0; i < max; i++, ps++) { + if (ps->cf_flags & mBGMPs_FLAG_FADEOUT) { + int execute_pos = mBGMPsComp_execute_ps_pos_get(ps_comp); - if ( - (execute_pos >= i || execute_pos < 0) || - (ps_comp->ps[execute_pos].elem.bgm_num == 127) || - (ps_comp->ps[execute_pos].cf_flags & mBGMPs_FLAG_SILENT) - ) { - if (sAdo_BgmFadeoutCheck() == FALSE) { - continue; /* don't clear the fadeout flag */ + if ((execute_pos >= i || execute_pos < 0) || (ps_comp->ps[execute_pos].elem.bgm_num == 127) || + (ps_comp->ps[execute_pos].cf_flags & mBGMPs_FLAG_SILENT)) { + if (sAdo_BgmFadeoutCheck() == FALSE) { + continue; /* don't clear the fadeout flag */ + } + } + + ps->cf_flags &= ~mBGMPs_FLAG_FADEOUT; + ps->cf_flags |= mBGMPs_FLAG_REMOVE; } - } - - ps->cf_flags &= ~mBGMPs_FLAG_FADEOUT; - ps->cf_flags |= mBGMPs_FLAG_REMOVE; } - } } static void mBGMPsComp_main_lost(mBGMPsComp* ps_comp) { - mBGMPs* ps = ps_comp->ps; - int i; - int max = ps_comp->ps_num; + mBGMPs* ps = ps_comp->ps; + int i; + int max = ps_comp->ps_num; - for (i = 0; i < max; i++, ps++) { - if ((ps->cf_flags & mBGMPs_FLAG_LOST)) { - ps->cf_flags |= mBGMPs_FLAG_REMOVE; + for (i = 0; i < max; i++, ps++) { + if ((ps->cf_flags & mBGMPs_FLAG_LOST)) { + ps->cf_flags |= mBGMPs_FLAG_REMOVE; + } } - } } -static int mBGMPsComp_make_ps(mBGMPsComp* ps_comp, mBGMElem* elem, int kategorie, s16 counter, u16 cf_flags, u8 priority) { - int pos = mBGMPsComp_search_insert_pos_kategorie(ps_comp, kategorie, priority); +static int mBGMPsComp_make_ps(mBGMPsComp* ps_comp, mBGMElem* elem, int kategorie, s16 counter, u16 cf_flags, + u8 priority) { + int pos = mBGMPsComp_search_insert_pos_kategorie(ps_comp, kategorie, priority); - if (pos >= 0) { - mBGMPs* dst_ps = &ps_comp->ps[pos]; + if (pos >= 0) { + mBGMPs* dst_ps = &ps_comp->ps[pos]; - mBGMPsComp_shift_behind(ps_comp, pos); - bcopy(elem, &dst_ps->elem, sizeof(mBGMElem)); - dst_ps->kategorie = kategorie; - dst_ps->counter = counter; - dst_ps->cf_flags = cf_flags; - dst_ps->priority = priority; - } + mBGMPsComp_shift_behind(ps_comp, pos); + bcopy(elem, &dst_ps->elem, sizeof(mBGMElem)); + dst_ps->kategorie = kategorie; + dst_ps->counter = counter; + dst_ps->cf_flags = cf_flags; + dst_ps->priority = priority; + } - return pos; + return pos; } static void _mBGMPsComp_make_ps_fanfare(u8 bgm_num, u16 stop_type) { - mBGMElem elem; + mBGMElem elem; - mBGMElem_default_set(&elem); - elem.bgm_num = bgm_num; - elem.stop_type1 = stop_type; - mBGMPsComp_make_ps(&M_bgm.ps_comp, &elem, mBGM_KATEGORIE_FANFARE, -1, 0, 0xFF); + mBGMElem_default_set(&elem); + elem.bgm_num = bgm_num; + elem.stop_type1 = stop_type; + mBGMPsComp_make_ps(&M_bgm.ps_comp, &elem, mBGM_KATEGORIE_FANFARE, -1, 0, 0xFF); } extern void mBGMPsComp_make_ps_fanfare(u8 bgm_num, u16 stop_type) { - _mBGMPsComp_make_ps_fanfare(bgm_num, stop_type); + _mBGMPsComp_make_ps_fanfare(bgm_num, stop_type); } static void _mBGMPsComp_make_ps_lost_fanfare(u8 bgm_num, u16 stop_type) { - mBGMElem elem; + mBGMElem elem; - mBGMElem_default_set(&elem); - elem.bgm_num = bgm_num; - elem.stop_type1 = stop_type; - mBGMPsComp_make_ps(&M_bgm.ps_comp, &elem, mBGM_KATEGORIE_FANFARE, -1, mBGMPs_FLAG_LOST, 0xFF); + mBGMElem_default_set(&elem); + elem.bgm_num = bgm_num; + elem.stop_type1 = stop_type; + mBGMPsComp_make_ps(&M_bgm.ps_comp, &elem, mBGM_KATEGORIE_FANFARE, -1, mBGMPs_FLAG_LOST, 0xFF); } extern void mBGMPsComp_make_ps_lost_fanfare(u8 bgm_num, u16 stop_type) { - _mBGMPsComp_make_ps_lost_fanfare(bgm_num, stop_type); + _mBGMPsComp_make_ps_lost_fanfare(bgm_num, stop_type); } -static void _mBGMPsComp_make_ps_wipe(u16 stop_type) { - mBGMForce* force = &M_bgm.force; - mBGMPsComp* ps_comp = &M_bgm.ps_comp; - mBGMElem elem; +static int mBGMForce_wipe_ps_make_permit(mBGMForce* force); - if (mBGMForce_wipe_ps_make_permit(force) && mBGMPsComp_search_pos_kategorie_bgm_num(ps_comp, mBGM_KATEGORIE_WIPE, 127, FALSE, FALSE) < 0) { - mBGMElem_default_set(&elem); - elem.stop_type1 = stop_type; - mBGMPsComp_make_ps(&M_bgm.ps_comp, &elem, mBGM_KATEGORIE_WIPE, -1, mBGMPs_FLAG_SILENT, 0xFF); - } +static void _mBGMPsComp_make_ps_wipe(u16 stop_type) { + mBGMForce* force = &M_bgm.force; + mBGMPsComp* ps_comp = &M_bgm.ps_comp; + mBGMElem elem; + + if (mBGMForce_wipe_ps_make_permit(force) && + mBGMPsComp_search_pos_kategorie_bgm_num(ps_comp, mBGM_KATEGORIE_WIPE, 127, FALSE, FALSE) < 0) { + mBGMElem_default_set(&elem); + elem.stop_type1 = stop_type; + mBGMPsComp_make_ps(&M_bgm.ps_comp, &elem, mBGM_KATEGORIE_WIPE, -1, mBGMPs_FLAG_SILENT, 0xFF); + } } extern void mBGMPsComp_make_ps_wipe(u16 stop_type) { - _mBGMPsComp_make_ps_wipe(stop_type); + _mBGMPsComp_make_ps_wipe(stop_type); } static void _mBGMPsComp_make_ps_quiet(u16 stop_type) { - mBGMElem elem; + mBGMElem elem; - mBGMElem_default_set(&elem); - elem.stop_type1 = stop_type; - mBGMPsComp_make_ps(&M_bgm.ps_comp, &elem, mBGM_KATEGORIE_QUIET, -1, mBGMPs_FLAG_SILENT, 0xFF); + mBGMElem_default_set(&elem); + elem.stop_type1 = stop_type; + mBGMPsComp_make_ps(&M_bgm.ps_comp, &elem, mBGM_KATEGORIE_QUIET, -1, mBGMPs_FLAG_SILENT, 0xFF); } extern void mBGMPsComp_make_ps_quiet(u16 stop_type) { - _mBGMPsComp_make_ps_quiet(stop_type); + _mBGMPsComp_make_ps_quiet(stop_type); } static void _mBGMPsComp_make_ps_co_quiet(u16 stop_type, s16 counter) { - mBGMElem elem; + mBGMElem elem; - mBGMElem_default_set(&elem); - elem.stop_type1 = stop_type; - mBGMPsComp_make_ps(&M_bgm.ps_comp, &elem, mBGM_KATEGORIE_QUIET, counter, mBGMPs_FLAG_SILENT, 0xFF); + mBGMElem_default_set(&elem); + elem.stop_type1 = stop_type; + mBGMPsComp_make_ps(&M_bgm.ps_comp, &elem, mBGM_KATEGORIE_QUIET, counter, mBGMPs_FLAG_SILENT, 0xFF); } extern void mBGMPsComp_make_ps_co_quiet(u16 stop_type, s16 counter) { - _mBGMPsComp_make_ps_co_quiet(stop_type, counter); + _mBGMPsComp_make_ps_co_quiet(stop_type, counter); } static void _mBGMPsComp_make_ps_fc_quiet(u16 stop_type) { - mBGMElem elem; + mBGMElem elem; - mBGMElem_default_set(&elem); - elem.stop_type1 = stop_type; - mBGMPsComp_make_ps(&M_bgm.ps_comp, &elem, mBGM_KATEGORIE_QUIET, -1, mBGMPs_FLAG_SILENT | mBGMPs_FLAG_FADEOUT, 0xFF); + mBGMElem_default_set(&elem); + elem.stop_type1 = stop_type; + mBGMPsComp_make_ps(&M_bgm.ps_comp, &elem, mBGM_KATEGORIE_QUIET, -1, mBGMPs_FLAG_SILENT | mBGMPs_FLAG_FADEOUT, 0xFF); } extern void mBGMPsComp_make_ps_fc_quiet(u16 stop_type) { - _mBGMPsComp_make_ps_fc_quiet(stop_type); + _mBGMPsComp_make_ps_fc_quiet(stop_type); } static void _mBGMPsComp_make_ps_demo(u8 bgm_num, u16 stop_type) { - mBGMElem elem; + mBGMElem elem; - mBGMElem_default_set(&elem); - elem.bgm_num = bgm_num; - elem.stop_type1 = stop_type; - mBGMPsComp_make_ps(&M_bgm.ps_comp, &elem, mBGM_KATEGORIE_DEMO, -1, 0, 0xFF); + mBGMElem_default_set(&elem); + elem.bgm_num = bgm_num; + elem.stop_type1 = stop_type; + mBGMPsComp_make_ps(&M_bgm.ps_comp, &elem, mBGM_KATEGORIE_DEMO, -1, 0, 0xFF); } extern void mBGMPsComp_make_ps_demo(u8 bgm_num, u16 stop_type) { - _mBGMPsComp_make_ps_demo(bgm_num, stop_type); + _mBGMPsComp_make_ps_demo(bgm_num, stop_type); } static void _mBGMPsComp_make_ps_happening(u8 bgm_num, u16 stop_type) { - mBGMElem elem; + mBGMElem elem; - mBGMElem_default_set(&elem); - elem.bgm_num = bgm_num; - elem.stop_type1 = stop_type; - mBGMPsComp_make_ps(&M_bgm.ps_comp, &elem, mBGM_KATEGORIE_HAPPENING, -1, 0, 0xFF); + mBGMElem_default_set(&elem); + elem.bgm_num = bgm_num; + elem.stop_type1 = stop_type; + mBGMPsComp_make_ps(&M_bgm.ps_comp, &elem, mBGM_KATEGORIE_HAPPENING, -1, 0, 0xFF); } extern void mBGMPsComp_make_ps_happening(u8 bgm_num, u16 stop_type) { - _mBGMPsComp_make_ps_happening(bgm_num, stop_type); + _mBGMPsComp_make_ps_happening(bgm_num, stop_type); } static void mBGMPsComp_make_ps_quietRoom(u16 stop_type) { - mBGMElem elem; + mBGMElem elem; - mBGMElem_default_set(&elem); - elem.stop_type1 = stop_type; - mBGMPsComp_make_ps(&M_bgm.ps_comp, &elem, mBGM_KATEGORIE_QUIETROOM, -1, mBGMPs_FLAG_SILENT, 0xFF); + mBGMElem_default_set(&elem); + elem.stop_type1 = stop_type; + mBGMPsComp_make_ps(&M_bgm.ps_comp, &elem, mBGM_KATEGORIE_QUIETROOM, -1, mBGMPs_FLAG_SILENT, 0xFF); } static void _mBGMPsComp_make_ps_room(u8 bgm_num, u16 stop_type) { - mBGMElem elem; + mBGMElem elem; - mBGMElem_default_set(&elem); - elem.bgm_num = bgm_num; - elem.stop_type1 = stop_type; - mBGMPsComp_make_ps(&M_bgm.ps_comp, &elem, mBGM_KATEGORIE_ROOM, -1, 0, 0xFF); + mBGMElem_default_set(&elem); + elem.bgm_num = bgm_num; + elem.stop_type1 = stop_type; + mBGMPsComp_make_ps(&M_bgm.ps_comp, &elem, mBGM_KATEGORIE_ROOM, -1, 0, 0xFF); } extern void mBGMPsComp_make_ps_room(u8 bgm_num, u16 stop_type) { - _mBGMPsComp_make_ps_room(bgm_num, stop_type); + _mBGMPsComp_make_ps_room(bgm_num, stop_type); } static void mBGMPsComp_make_ps_time() { - mBGMElem elem; + mBGMElem elem; - mBGMElem_default_set(&elem); - elem.stop_type1 = 0x870; - mBGMPsComp_make_ps(&M_bgm.ps_comp, &elem, mBGM_KATEGORIE_TIME, -1, mBGMPs_FLAG_SILENT, 0xFF); + mBGMElem_default_set(&elem); + elem.stop_type1 = 0x870; + mBGMPsComp_make_ps(&M_bgm.ps_comp, &elem, mBGM_KATEGORIE_TIME, -1, mBGMPs_FLAG_SILENT, 0xFF); } static void _mBGMPsComp_make_ps_quietField(u16 stop_type) { - mBGMElem elem; + mBGMElem elem; - mBGMElem_default_set(&elem); - elem.stop_type1 = stop_type; - mBGMPsComp_make_ps(&M_bgm.ps_comp, &elem, mBGM_KATEGORIE_QUIETFIELD, -1, mBGMPs_FLAG_SILENT, 0xFF); + mBGMElem_default_set(&elem); + elem.stop_type1 = stop_type; + mBGMPsComp_make_ps(&M_bgm.ps_comp, &elem, mBGM_KATEGORIE_QUIETFIELD, -1, mBGMPs_FLAG_SILENT, 0xFF); } extern void mBGMPsComp_make_ps_quietField(u16 stop_type) { - _mBGMPsComp_make_ps_quietField(stop_type); + _mBGMPsComp_make_ps_quietField(stop_type); } static void _mBGMPsComp_make_ps_fc_quietField(u16 stop_type) { - mBGMElem elem; + mBGMElem elem; - mBGMElem_default_set(&elem); - elem.stop_type1 = stop_type; - mBGMPsComp_make_ps(&M_bgm.ps_comp, &elem, mBGM_KATEGORIE_QUIETFIELD, -1, mBGMPs_FLAG_SILENT | mBGMPs_FLAG_FADEOUT, 0xFF); + mBGMElem_default_set(&elem); + elem.stop_type1 = stop_type; + mBGMPsComp_make_ps(&M_bgm.ps_comp, &elem, mBGM_KATEGORIE_QUIETFIELD, -1, mBGMPs_FLAG_SILENT | mBGMPs_FLAG_FADEOUT, + 0xFF); } extern void mBGMPsComp_make_ps_fc_quietField(u16 stop_type) { - _mBGMPsComp_make_ps_fc_quietField(stop_type); + _mBGMPsComp_make_ps_fc_quietField(stop_type); } static void _mBGMPsComp_make_ps_fieldSuddenEv(u8 bgm_num, u16 stop_type, u8 priority) { - mBGMElem elem; + mBGMElem elem; - mBGMElem_default_set(&elem); - elem.bgm_num = bgm_num; - elem.stop_type1 = stop_type; - mBGMPsComp_make_ps(&M_bgm.ps_comp, &elem, mBGM_KATEGORIE_FIELDSUDDENEV, -1, 0, priority); + mBGMElem_default_set(&elem); + elem.bgm_num = bgm_num; + elem.stop_type1 = stop_type; + mBGMPsComp_make_ps(&M_bgm.ps_comp, &elem, mBGM_KATEGORIE_FIELDSUDDENEV, -1, 0, priority); } extern void mBGMPsComp_make_ps_fieldSuddenEv(u8 bgm_num, u16 stop_type, u8 priority) { - _mBGMPsComp_make_ps_fieldSuddenEv(bgm_num, stop_type, priority); + _mBGMPsComp_make_ps_fieldSuddenEv(bgm_num, stop_type, priority); } -static void mBGMPsComp_make_ps_fieldSchedEv(u8 bgm_num, int update_volume_move_ctr, int update_volume_level, int cf_flag, u16 stop_type, u8 priority) { - mBGMPsComp* ps_comp = &M_bgm.ps_comp; - mBGMElem elem; - u16 flags; +static void mBGMPsComp_make_ps_fieldSchedEv(u8 bgm_num, int update_volume_move_ctr, int update_volume_level, + int cf_flag, u16 stop_type, u8 priority) { + mBGMPsComp* ps_comp = &M_bgm.ps_comp; + mBGMElem elem; + u16 flags; - mBGMElem_default_set(&elem); - elem.bgm_num = bgm_num; - elem.stop_type1 = stop_type; - flags = 0; + mBGMElem_default_set(&elem); + elem.bgm_num = bgm_num; + elem.stop_type1 = stop_type; + flags = 0; - if (update_volume_move_ctr) { - flags |= mBGMPs_FLAG_UPDATE_VOLUME_MOVE_CTR; - } - - if (update_volume_level) { - flags |= mBGMPs_FLAG_UPDATE_VOLUME_LEVEL; - } - - if (cf_flag) { - flags |= mBGMPs_FLAG_CROSSFADE; - } - - if (bgm_num == 127) { - flags |= mBGMPs_FLAG_SILENT; - } - - mBGMPsComp_make_ps(ps_comp, &elem, mBGM_KATEGORIE_FIELDSCHEDEV, -1, flags, priority); -} - -static void mBGMPsComp_make_ps_fieldNorm(u8 bgm_num, u16 stop_type) { - mBGMElem elem; - - mBGMElem_default_set(&elem); - elem.bgm_num = bgm_num; - elem.stop_type1 = stop_type; - mBGMPsComp_make_ps(&M_bgm.ps_comp, &elem, mBGM_KATEGORIE_FIELDNORM, -1, 0, 255); -} - -static void mBGMPsComp_delete_ps(mBGMPsComp* ps_comp, int kategorie, u8 bgm_num, u16 stop_type, int counter_flag) { - int num = mBGMPsComp_search_pos_kategorie_bgm_num(ps_comp, kategorie, bgm_num, counter_flag, FALSE); - - if (num >= 0 && num < ps_comp->ps_num) { - ps_comp->ps[num].cf_flags |= mBGMPs_FLAG_REMOVE; - ps_comp->ps[num].elem.stop_type0 = stop_type; - } -} - -static void _mBGMPsComp_delete_ps_fanfare(u8 bgm_num, u16 stop_type) { - mBGMPsComp_delete_ps(&M_bgm.ps_comp, mBGM_KATEGORIE_FANFARE, bgm_num, stop_type, FALSE); -} - -extern void mBGMPsComp_delete_ps_fanfare(u8 bgm_num, u16 stop_type) { - _mBGMPsComp_delete_ps_fanfare(bgm_num, stop_type); -} - -static void mBGMPsComp_delete_ps_wipe() { - mBGMPsComp_delete_ps(&M_bgm.ps_comp, mBGM_KATEGORIE_WIPE, 127, 0x168, FALSE); -} - -static void _mBGMPsComp_delete_ps_quiet() { - mBGMPsComp_delete_ps(&M_bgm.ps_comp, mBGM_KATEGORIE_QUIET, 127, 0x168, TRUE); -} - -extern void mBGMPsComp_delete_ps_quiet() { - _mBGMPsComp_delete_ps_quiet(); -} - -static void _mBGMPsComp_delete_ps_demo(u8 bgm_num, u16 stop_type) { - mBGMPsComp_delete_ps(&M_bgm.ps_comp, mBGM_KATEGORIE_DEMO, bgm_num, stop_type, FALSE); -} - -extern void mBGMPsComp_delete_ps_demo(u8 bgm_num, u16 stop_type) { - _mBGMPsComp_delete_ps_demo(bgm_num, stop_type); -} - -static void _mBGMPsComp_delete_ps_happening(u8 bgm_num, u16 stop_type) { - mBGMPsComp_delete_ps(&M_bgm.ps_comp, mBGM_KATEGORIE_HAPPENING, bgm_num, stop_type, FALSE); -} - -extern void mBGMPsComp_delete_ps_happening(u8 bgm_num, u16 stop_type) { - _mBGMPsComp_delete_ps_happening(bgm_num, stop_type); -} - -static void mBGMPsComp_delete_ps_quietRoom() { - mBGMPsComp_delete_ps(&M_bgm.ps_comp, mBGM_KATEGORIE_QUIETROOM, 127, 0x168, TRUE); -} - -static void _mBGMPsComp_delete_ps_room(u8 bgm_num, u16 stop_type) { - mBGMPsComp_delete_ps(&M_bgm.ps_comp, mBGM_KATEGORIE_ROOM, bgm_num, stop_type, FALSE); -} - -extern void mBGMPsComp_delete_ps_room(u8 bgm_num, u16 stop_type) { - _mBGMPsComp_delete_ps_room(bgm_num, stop_type); -} - -static void mBGMPsComp_delete_ps_time() { - mBGMPsComp_delete_ps(&M_bgm.ps_comp, mBGM_KATEGORIE_TIME, 127, 0x168, FALSE); -} - -static void _mBGMPsComp_delete_ps_quietField() { - mBGMPsComp_delete_ps(&M_bgm.ps_comp, mBGM_KATEGORIE_QUIETFIELD, 127, 0x168, TRUE); -} - -extern void mBGMPsComp_delete_ps_quietField() { - _mBGMPsComp_delete_ps_quietField(); -} - -static void _mBGMPsComp_delete_ps_fieldSuddenEv(u8 bgm_num, u16 stop_type) { - mBGMPsComp_delete_ps(&M_bgm.ps_comp, mBGM_KATEGORIE_FIELDSUDDENEV, bgm_num, stop_type, FALSE); -} - -extern void mBGMPsComp_delete_ps_fieldSuddenEv(u8 bgm_num, u16 stop_type) { - _mBGMPsComp_delete_ps_fieldSuddenEv(bgm_num, stop_type); -} - -static void mBGMPsComp_delete_ps_fieldSchedEv(u8 bgm_num, u16 stop_type) { - mBGMPsComp_delete_ps(&M_bgm.ps_comp, mBGM_KATEGORIE_FIELDSCHEDEV, bgm_num, stop_type, FALSE); -} - -static void mBGMPsComp_delete_ps_fieldNorm(u8 bgm_num, u16 stop_type) { - mBGMPsComp_delete_ps(&M_bgm.ps_comp, mBGM_KATEGORIE_FIELDNORM, bgm_num, stop_type, FALSE); -} - -static void mBGMPsComp_volume_change_fieldSchedEv(u8 bgm_num, int update_volume_move_ctr, int update_volume_level) { - mBGMPsComp* ps_comp = &M_bgm.ps_comp; - int idx = mBGMPsComp_search_pos_kategorie_bgm_num(ps_comp, mBGM_KATEGORIE_FIELDSCHEDEV, bgm_num, FALSE, FALSE); - - if (idx >= 0) { - mBGMPs* ps = &ps_comp->ps[idx]; - if (update_volume_move_ctr) { - ps->cf_flags |= mBGMPs_FLAG_UPDATE_VOLUME_MOVE_CTR; + flags |= mBGMPs_FLAG_UPDATE_VOLUME_MOVE_CTR; } if (update_volume_level) { - ps->cf_flags |= mBGMPs_FLAG_UPDATE_VOLUME_LEVEL; - } - else { - ps->cf_flags &= ~mBGMPs_FLAG_UPDATE_VOLUME_LEVEL; + flags |= mBGMPs_FLAG_UPDATE_VOLUME_LEVEL; } - ps->cf_flags |= mBGMPs_FLAG_UPDATE_VOLUME; - } + if (cf_flag) { + flags |= mBGMPs_FLAG_CROSSFADE; + } + + if (bgm_num == 127) { + flags |= mBGMPs_FLAG_SILENT; + } + + mBGMPsComp_make_ps(ps_comp, &elem, mBGM_KATEGORIE_FIELDSCHEDEV, -1, flags, priority); +} + +static void mBGMPsComp_make_ps_fieldNorm(u8 bgm_num, u16 stop_type) { + mBGMElem elem; + + mBGMElem_default_set(&elem); + elem.bgm_num = bgm_num; + elem.stop_type1 = stop_type; + mBGMPsComp_make_ps(&M_bgm.ps_comp, &elem, mBGM_KATEGORIE_FIELDNORM, -1, 0, 255); +} + +static void mBGMPsComp_delete_ps(mBGMPsComp* ps_comp, int kategorie, u8 bgm_num, u16 stop_type, int counter_flag) { + int num = mBGMPsComp_search_pos_kategorie_bgm_num(ps_comp, kategorie, bgm_num, counter_flag, FALSE); + + if (num >= 0 && num < ps_comp->ps_num) { + ps_comp->ps[num].cf_flags |= mBGMPs_FLAG_REMOVE; + ps_comp->ps[num].elem.stop_type0 = stop_type; + } +} + +static void _mBGMPsComp_delete_ps_fanfare(u8 bgm_num, u16 stop_type) { + mBGMPsComp_delete_ps(&M_bgm.ps_comp, mBGM_KATEGORIE_FANFARE, bgm_num, stop_type, FALSE); +} + +extern void mBGMPsComp_delete_ps_fanfare(u8 bgm_num, u16 stop_type) { + _mBGMPsComp_delete_ps_fanfare(bgm_num, stop_type); +} + +static void mBGMPsComp_delete_ps_wipe() { + mBGMPsComp_delete_ps(&M_bgm.ps_comp, mBGM_KATEGORIE_WIPE, 127, 0x168, FALSE); +} + +static void _mBGMPsComp_delete_ps_quiet() { + mBGMPsComp_delete_ps(&M_bgm.ps_comp, mBGM_KATEGORIE_QUIET, 127, 0x168, TRUE); +} + +extern void mBGMPsComp_delete_ps_quiet() { + _mBGMPsComp_delete_ps_quiet(); +} + +static void _mBGMPsComp_delete_ps_demo(u8 bgm_num, u16 stop_type) { + mBGMPsComp_delete_ps(&M_bgm.ps_comp, mBGM_KATEGORIE_DEMO, bgm_num, stop_type, FALSE); +} + +extern void mBGMPsComp_delete_ps_demo(u8 bgm_num, u16 stop_type) { + _mBGMPsComp_delete_ps_demo(bgm_num, stop_type); +} + +static void _mBGMPsComp_delete_ps_happening(u8 bgm_num, u16 stop_type) { + mBGMPsComp_delete_ps(&M_bgm.ps_comp, mBGM_KATEGORIE_HAPPENING, bgm_num, stop_type, FALSE); +} + +extern void mBGMPsComp_delete_ps_happening(u8 bgm_num, u16 stop_type) { + _mBGMPsComp_delete_ps_happening(bgm_num, stop_type); +} + +static void mBGMPsComp_delete_ps_quietRoom() { + mBGMPsComp_delete_ps(&M_bgm.ps_comp, mBGM_KATEGORIE_QUIETROOM, 127, 0x168, TRUE); +} + +static void _mBGMPsComp_delete_ps_room(u8 bgm_num, u16 stop_type) { + mBGMPsComp_delete_ps(&M_bgm.ps_comp, mBGM_KATEGORIE_ROOM, bgm_num, stop_type, FALSE); +} + +extern void mBGMPsComp_delete_ps_room(u8 bgm_num, u16 stop_type) { + _mBGMPsComp_delete_ps_room(bgm_num, stop_type); +} + +static void mBGMPsComp_delete_ps_time() { + mBGMPsComp_delete_ps(&M_bgm.ps_comp, mBGM_KATEGORIE_TIME, 127, 0x168, FALSE); +} + +static void _mBGMPsComp_delete_ps_quietField() { + mBGMPsComp_delete_ps(&M_bgm.ps_comp, mBGM_KATEGORIE_QUIETFIELD, 127, 0x168, TRUE); +} + +extern void mBGMPsComp_delete_ps_quietField() { + _mBGMPsComp_delete_ps_quietField(); +} + +static void _mBGMPsComp_delete_ps_fieldSuddenEv(u8 bgm_num, u16 stop_type) { + mBGMPsComp_delete_ps(&M_bgm.ps_comp, mBGM_KATEGORIE_FIELDSUDDENEV, bgm_num, stop_type, FALSE); +} + +extern void mBGMPsComp_delete_ps_fieldSuddenEv(u8 bgm_num, u16 stop_type) { + _mBGMPsComp_delete_ps_fieldSuddenEv(bgm_num, stop_type); +} + +static void mBGMPsComp_delete_ps_fieldSchedEv(u8 bgm_num, u16 stop_type) { + mBGMPsComp_delete_ps(&M_bgm.ps_comp, mBGM_KATEGORIE_FIELDSCHEDEV, bgm_num, stop_type, FALSE); +} + +static void mBGMPsComp_delete_ps_fieldNorm(u8 bgm_num, u16 stop_type) { + mBGMPsComp_delete_ps(&M_bgm.ps_comp, mBGM_KATEGORIE_FIELDNORM, bgm_num, stop_type, FALSE); +} + +static void mBGMPsComp_volume_change_fieldSchedEv(u8 bgm_num, int update_volume_move_ctr, int update_volume_level) { + mBGMPsComp* ps_comp = &M_bgm.ps_comp; + int idx = mBGMPsComp_search_pos_kategorie_bgm_num(ps_comp, mBGM_KATEGORIE_FIELDSCHEDEV, bgm_num, FALSE, FALSE); + + if (idx >= 0) { + mBGMPs* ps = &ps_comp->ps[idx]; + + if (update_volume_move_ctr) { + ps->cf_flags |= mBGMPs_FLAG_UPDATE_VOLUME_MOVE_CTR; + } + + if (update_volume_level) { + ps->cf_flags |= mBGMPs_FLAG_UPDATE_VOLUME_LEVEL; + } else { + ps->cf_flags &= ~mBGMPs_FLAG_UPDATE_VOLUME_LEVEL; + } + + ps->cf_flags |= mBGMPs_FLAG_UPDATE_VOLUME; + } } static void mBGMPsComp_search_cf_set_field(u8 bgm_num, int kategorie) { - mBGMPsComp* ps_comp = &M_bgm.ps_comp; - int pos = mBGMPsComp_search_pos_kategorie_bgm_num(ps_comp, kategorie, bgm_num, FALSE, TRUE); + mBGMPsComp* ps_comp = &M_bgm.ps_comp; + int pos = mBGMPsComp_search_pos_kategorie_bgm_num(ps_comp, kategorie, bgm_num, FALSE, TRUE); - if (pos >= 0) { - int i; + if (pos >= 0) { + int i; - for (i = pos + 1; i < ps_comp->ps_num; i++) { - if ( - ps_comp->ps[i].kategorie == mBGM_KATEGORIE_FIELDSUDDENEV || - ps_comp->ps[i].kategorie == mBGM_KATEGORIE_FIELDSCHEDEV || - ps_comp->ps[i].kategorie == mBGM_KATEGORIE_FIELDNORM - ) { - ps_comp->ps[i].cf_flags |= (mBGMPs_FLAG_UPDATE_VOLUME_MOVE_CTR | mBGMPs_FLAG_CROSSFADE); - } + for (i = pos + 1; i < ps_comp->ps_num; i++) { + if (ps_comp->ps[i].kategorie == mBGM_KATEGORIE_FIELDSUDDENEV || + ps_comp->ps[i].kategorie == mBGM_KATEGORIE_FIELDSCHEDEV || + ps_comp->ps[i].kategorie == mBGM_KATEGORIE_FIELDNORM) { + ps_comp->ps[i].cf_flags |= (mBGMPs_FLAG_UPDATE_VOLUME_MOVE_CTR | mBGMPs_FLAG_CROSSFADE); + } + } } - } } extern void mBGMPsComp_volume_fishing_start() { - M_bgm.ps_comp.fishing_state = 1; + M_bgm.ps_comp.fishing_state = 1; } extern void mBGMPsComp_volume_fishing_end() { - M_bgm.ps_comp.fishing_state = 3; + M_bgm.ps_comp.fishing_state = 3; } extern void mBGMPsComp_volume_collect_insects_start() { - M_bgm.ps_comp.collect_insects_state = 1; + M_bgm.ps_comp.collect_insects_state = 1; } extern void mBGMPsComp_volume_collect_insects_end() { - M_bgm.ps_comp.collect_insects_state = 3; + M_bgm.ps_comp.collect_insects_state = 3; } extern void mBGMPsComp_volume_talk_start() { - M_bgm.ps_comp.talk_state = 1; + M_bgm.ps_comp.talk_state = 1; } extern void mBGMPsComp_volume_talk_end() { - if (M_bgm.ps_comp.talk_state != 0) { - M_bgm.ps_comp.talk_state = 3; - } + if (M_bgm.ps_comp.talk_state != 0) { + M_bgm.ps_comp.talk_state = 3; + } } /* @unused */ extern void mBGMPsComp_volume_boat_start() { - M_bgm.ps_comp.boat_state = 1; + M_bgm.ps_comp.boat_state = 1; } extern void mBGMPsComp_volume_boat_end() { - mBGMPsComp* ps_comp = &M_bgm.ps_comp; + mBGMPsComp* ps_comp = &M_bgm.ps_comp; - if (ps_comp->boat_state != 0) { - ps_comp->boat_state = 3; - } + if (ps_comp->boat_state != 0) { + ps_comp->boat_state = 3; + } } extern void mBGMPsComp_pause(int state) { - M_bgm.ps_comp.pause_state = state; + M_bgm.ps_comp.pause_state = state; } extern void mBGMPsComp_MDPlayerPos_make() { - M_bgm.ps_comp.md.make_flag = TRUE; + M_bgm.ps_comp.md.make_flag = TRUE; } extern void mBGMPsComp_MDPlayerPos_delete() { - M_bgm.ps_comp.md.delete_flag = TRUE; + M_bgm.ps_comp.md.delete_flag = TRUE; } extern void mBGMPsComp_MDPlayerPos_param_set(const xyz_t* pos, u16 angle, u16 md_type, u32 ongen_no) { - mBGMPsComp* ps_comp = &M_bgm.ps_comp; + mBGMPsComp* ps_comp = &M_bgm.ps_comp; - xyz_t_move(&ps_comp->md.pos, pos); - ps_comp->md.angle = angle; - ps_comp->md.md_type_no = md_type; - ps_comp->md.ongen_no = ongen_no; + xyz_t_move(&ps_comp->md.pos, pos); + ps_comp->md.angle = angle; + ps_comp->md.md_type_no = md_type; + ps_comp->md.ongen_no = ongen_no; } extern void mBGMPsComp_scene_mode(u8 mode) { - sAdo_SceneMode(mode); + sAdo_SceneMode(mode); } static void mBGMPsComp_arm_make(u8 state) { - mBGMPsComp* ps_comp = &M_bgm.ps_comp; + mBGMPsComp* ps_comp = &M_bgm.ps_comp; - ps_comp->arm.req_flag = TRUE; - ps_comp->arm.arm_state = state; + ps_comp->arm.req_flag = TRUE; + ps_comp->arm.arm_state = state; } static void mBGMPsComp_arm_delete() { - mBGMPsComp* ps_comp = &M_bgm.ps_comp; + mBGMPsComp* ps_comp = &M_bgm.ps_comp; - ps_comp->arm.req_flag = FALSE; - ps_comp->arm.arm_state = 0; + ps_comp->arm.req_flag = FALSE; + ps_comp->arm.arm_state = 0; } extern void mBGMPsComp_museum_status(u8 status) { - mBGMPsComp* ps_comp = &M_bgm.ps_comp; + mBGMPsComp* ps_comp = &M_bgm.ps_comp; - if (status == 0) { - ps_comp->museum.req_flag = 1; - } - else { - ps_comp->museum.req_flag = 2; - } + if (status == 0) { + ps_comp->museum.req_flag = 1; + } else { + ps_comp->museum.req_flag = 2; + } - ps_comp->museum.type = status; + ps_comp->museum.type = status; } extern int mBGMPsComp_execute_bgm_num_get() { - mBGMPsComp* ps_comp = &M_bgm.ps_comp; - int pos = mBGMPsComp_execute_ps_pos_get(ps_comp); + mBGMPsComp* ps_comp = &M_bgm.ps_comp; + int pos = mBGMPsComp_execute_ps_pos_get(ps_comp); - if (pos >= 0 && ps_comp->ps[pos].elem.bgm_num != 127 && (ps_comp->ps[pos].cf_flags & mBGMPs_FLAG_SILENT) == 0) { - return ps_comp->ps[pos].elem.bgm_num; - } + if (pos >= 0 && ps_comp->ps[pos].elem.bgm_num != 127 && (ps_comp->ps[pos].cf_flags & mBGMPs_FLAG_SILENT) == 0) { + return ps_comp->ps[pos].elem.bgm_num; + } - return -1; + return -1; } static void mBGMPsComp_ct(mBGMPsComp* ps_comp) { - bzero(ps_comp, sizeof(mBGMPsComp)); + bzero(ps_comp, sizeof(mBGMPsComp)); - ps_comp->volume.main_volume = -1.0f; - ps_comp->volume.main_volume_move_ctr = 0; - ps_comp->volume.ps_volume = -1.0f; - ps_comp->volume.ps_volume_move_ctr = 0; - ps_comp->volume.fishing_volume = -1.0f; - ps_comp->volume.fishing_volume_move_ctr = 100; - ps_comp->volume.collect_insects_volume = -1.0f; - ps_comp->volume.collect_insects_volume_move_ctr = 100; - ps_comp->volume.talk_volume = -1.0f; - ps_comp->volume.boat_volume = -1.0f; - ps_comp->volume.pause_volume = -1.0f; - ps_comp->volume.pause_volume_move_ctr = 2; + ps_comp->volume.main_volume = -1.0f; + ps_comp->volume.main_volume_move_ctr = 0; + ps_comp->volume.ps_volume = -1.0f; + ps_comp->volume.ps_volume_move_ctr = 0; + ps_comp->volume.fishing_volume = -1.0f; + ps_comp->volume.fishing_volume_move_ctr = 100; + ps_comp->volume.collect_insects_volume = -1.0f; + ps_comp->volume.collect_insects_volume_move_ctr = 100; + ps_comp->volume.talk_volume = -1.0f; + ps_comp->volume.boat_volume = -1.0f; + ps_comp->volume.pause_volume = -1.0f; + ps_comp->volume.pause_volume_move_ctr = 2; } /* mBGMForce */ static int mBGMForce_wipe_ps_make_permit(mBGMForce* force) { - if (force->room_nonstop != 0) { - return FALSE; - } - else { - return TRUE; - } + if (force->room_nonstop != 0) { + return FALSE; + } else { + return TRUE; + } } static void mBGMForce_move_inform(mBGMForce* force) { - if (force->inform == mBGMForce_INFORM_1) { - int field_ok = mFI_CheckFieldData(); + if (force->inform == mBGMForce_INFORM_1) { + int field_ok = mFI_CheckFieldData(); - if (field_ok == FALSE || (field_ok != FALSE && mFI_GET_TYPE(mFI_GetFieldId()) != mFI_FIELD_FG)) { - force->flag = TRUE; - mBGMPsComp_make_ps_wipe(0x195); + if (field_ok == FALSE || (field_ok != FALSE && mFI_GET_TYPE(mFI_GetFieldId()) != mFI_FIELD_FG)) { + force->flag = TRUE; + mBGMPsComp_make_ps_wipe(0x195); + } + + force->inform = mBGMForce_INFORM_2; + } else if (force->inform == mBGMForce_INFORM_3) { + force->inform = mBGMForce_INFORM_4; + } else if (force->inform == mBGMForce_INFORM_5) { + if (force->flag) { + mBGMPsComp_make_ps_wipe(0x249); + } + + force->inform = mBGMForce_INFORM_6; + } else if (force->inform == mBGMForce_INFORM_7) { + force->inform = mBGMForce_INFORM_0; + force->flag = FALSE; } - - force->inform = mBGMForce_INFORM_2; - } - else if (force->inform == mBGMForce_INFORM_3) { - force->inform = mBGMForce_INFORM_4; - } - else if (force->inform == mBGMForce_INFORM_5) { - if (force->flag) { - mBGMPsComp_make_ps_wipe(0x249); - } - - force->inform = mBGMForce_INFORM_6; - } - else if (force->inform == mBGMForce_INFORM_7) { - force->inform = mBGMForce_INFORM_0; - force->flag = FALSE; - } } static void mBGMForce_move_room_nonstop(mBGMForce* force) { - if (force->room_nonstop == 1) { - force->room_nonstop = 2; - } - else if (force->room_nonstop == 3) { - force->room_nonstop = 0; - } + if (force->room_nonstop == 1) { + force->room_nonstop = 2; + } else if (force->room_nonstop == 3) { + force->room_nonstop = 0; + } } static void mBGMForce_move(mBGMForce* force) { - mBGMForce_move_inform(force); - mBGMForce_move_room_nonstop(force); + mBGMForce_move_inform(force); + mBGMForce_move_room_nonstop(force); } static void mBGMForce_ct(mBGMForce* force) { - bzero(force, sizeof(mBGMForce)); + bzero(force, sizeof(mBGMForce)); } static void mBGMForce_inform_cleanup(mBGMForce* force) { - if (force->inform == mBGMForce_INFORM_2) { - force->inform = mBGMForce_INFORM_3; - } - else if (force->inform == mBGMForce_INFORM_6) { - force->inform = mBGMForce_INFORM_7; - } + if (force->inform == mBGMForce_INFORM_2) { + force->inform = mBGMForce_INFORM_3; + } else if (force->inform == mBGMForce_INFORM_6) { + force->inform = mBGMForce_INFORM_7; + } } static void mBGMForce_room_nonstop_cleanup(mBGMForce* force) { - if (force->room_nonstop == 2) { - force->room_nonstop = 3; - } + if (force->room_nonstop == 2) { + force->room_nonstop = 3; + } } static void mBGMForce_cleanup(mBGMForce* force) { - mBGMForce_inform_cleanup(force); - mBGMForce_room_nonstop_cleanup(force); + mBGMForce_inform_cleanup(force); + mBGMForce_room_nonstop_cleanup(force); } extern void mBGMForce_inform_start() { - M_bgm.force.inform = mBGMForce_INFORM_1; + M_bgm.force.inform = mBGMForce_INFORM_1; } extern void mBGMForce_inform_end() { - M_bgm.force.inform = mBGMForce_INFORM_5; + M_bgm.force.inform = mBGMForce_INFORM_5; } static void _mBGMForce_room_nonstop_start() { - M_bgm.force.room_nonstop = 1; + M_bgm.force.room_nonstop = 1; } extern void mBGMForce_room_nonstop_start() { - _mBGMForce_room_nonstop_start(); + _mBGMForce_room_nonstop_start(); } static void mBGM_main_control(mBGM* bgm) { - mBGMPsComp* ps_comp = &bgm->ps_comp; + mBGMPsComp* ps_comp = &bgm->ps_comp; - mBGMPsComp_main_req_md(ps_comp); - mBGMPsComp_main_req_stop(ps_comp); - mBGMPsComp_main_remove(ps_comp); - mBGMPsComp_main_req_start(ps_comp); - mBGMPsComp_main_req_pause(ps_comp); - mBGMPsComp_main_req_volume(ps_comp); - mBGMPsComp_main_inform_sound(ps_comp); - mBGMPsComp_main_md_move(ps_comp); - mBGMPsComp_main_counter_dec(ps_comp); - mBGMPsComp_main_fo_check(ps_comp); - mBGMPsComp_main_lost(ps_comp); + mBGMPsComp_main_req_md(ps_comp); + mBGMPsComp_main_req_stop(ps_comp); + mBGMPsComp_main_remove(ps_comp); + mBGMPsComp_main_req_start(ps_comp); + mBGMPsComp_main_req_pause(ps_comp); + mBGMPsComp_main_req_volume(ps_comp); + mBGMPsComp_main_inform_sound(ps_comp); + mBGMPsComp_main_md_move(ps_comp); + mBGMPsComp_main_counter_dec(ps_comp); + mBGMPsComp_main_fo_check(ps_comp); + mBGMPsComp_main_lost(ps_comp); } static void mBGM_weather_set() { - s16 weather = Common_Get(weather); + s16 weather = Common_Get(weather); - if (weather >= mEnv_WEATHER_LEAVES) { - weather = mEnv_WEATHER_SAKURA; - } - else if (weather < 0) { - weather = mEnv_WEATHER_CLEAR; - } + if (weather >= mEnv_WEATHER_LEAVES) { + weather = mEnv_WEATHER_SAKURA; + } else if (weather < 0) { + weather = mEnv_WEATHER_CLEAR; + } - sAdo_Tenki(weather); + sAdo_Tenki(weather); } extern void mBGM_main(GAME* game) { - mBGMClock_move(&M_bgm.clock, game); - mBGMDemo_move(&M_bgm.demo, game); - mBGMRoom_move(&M_bgm.room, game); - mBGMFieldSuddenEv_move(&M_bgm.field_sudden_ev, game); - mBGMFieldSchedEv_move(&M_bgm.field_sched_ev, game); - mBGMFieldNorm_move(&M_bgm.field_norm, game); - mBGMTime_move(&M_bgm.time, game); - mBGM_main_control(&M_bgm); - mBGMForce_move(&M_bgm.force); - mBGM_weather_set(); + mBGMClock_move(&M_bgm.clock, game); + mBGMDemo_move(&M_bgm.demo, game); + mBGMRoom_move(&M_bgm.room, game); + mBGMFieldSuddenEv_move(&M_bgm.field_sudden_ev, game); + mBGMFieldSchedEv_move(&M_bgm.field_sched_ev, game); + mBGMFieldNorm_move(&M_bgm.field_norm, game); + mBGMTime_move(&M_bgm.time, game); + mBGM_main_control(&M_bgm); + mBGMForce_move(&M_bgm.force); + mBGM_weather_set(); } extern void mBGM_ct() { - mBGMClock_ct(&M_bgm.clock); - mBGMDemo_ct(&M_bgm.demo); - mBGMRoom_ct(&M_bgm.room); - mBGMTime_ct(&M_bgm.time); - mBGMFieldSuddenEv_ct(&M_bgm.field_sudden_ev); - mBGMFieldSchedEv_ct(&M_bgm.field_sched_ev); - mBGMFieldNorm_ct(&M_bgm.field_norm); - mBGMPsComp_ct(&M_bgm.ps_comp); - mBGMForce_ct(&M_bgm.force); + mBGMClock_ct(&M_bgm.clock); + mBGMDemo_ct(&M_bgm.demo); + mBGMRoom_ct(&M_bgm.room); + mBGMTime_ct(&M_bgm.time); + mBGMFieldSuddenEv_ct(&M_bgm.field_sudden_ev); + mBGMFieldSchedEv_ct(&M_bgm.field_sched_ev); + mBGMFieldNorm_ct(&M_bgm.field_norm); + mBGMPsComp_ct(&M_bgm.ps_comp); + mBGMForce_ct(&M_bgm.force); } extern void mBGM_init() { - mBGMPsComp_delete_ps_wipe(); + mBGMPsComp_delete_ps_wipe(); - if (mFI_CheckFieldData()) { - mActor_name_t field_id = mFI_GetFieldId(); - mActor_name_t field_type = mFI_GET_TYPE(field_id); - mBGMForce* force = &M_bgm.force; + if (mFI_CheckFieldData()) { + mActor_name_t field_id = mFI_GetFieldId(); + mActor_name_t field_type = mFI_GET_TYPE(field_id); + mBGMForce* force = &M_bgm.force; - if (field_type == mFI_FIELD_FG) { - if (mEv_CheckTitleDemo() > 0) { - mBGMPsComp_make_ps_demo(70, 0x168); // Play title music - } - else { - if ((force->inform != mBGMForce_INFORM_3 && force->inform != mBGMForce_INFORM_7) || force->flag) { - mBGMFieldNorm_make_req(); + if (field_type == mFI_FIELD_FG) { + if (mEv_CheckTitleDemo() > 0) { + mBGMPsComp_make_ps_demo(70, 0x168); // Play title music + } else { + if ((force->inform != mBGMForce_INFORM_3 && force->inform != mBGMForce_INFORM_7) || force->flag) { + mBGMFieldNorm_make_req(); + } + + if (force->inform == mBGMForce_INFORM_3 && force->flag) { + mBGMPsComp_make_ps_quiet(0x168); + } + } + } else if (field_type == mFI_FIELD_ROOM0 || field_type == mFI_FIELD_NPCROOM0 || + field_type == mFI_FIELD_PLAYER0_ROOM) { + if (force->room_nonstop != 3) { + mBGMRoom_shop_close_time_set(&M_bgm.room); + mBGMRoom_scene_bgm_make_req(); + } + } else { + mBGMDemo_scene_bgm_make_req(); } - - if (force->inform == mBGMForce_INFORM_3 && force->flag) { - mBGMPsComp_make_ps_quiet(0x168); - } - } } - else if (field_type == mFI_FIELD_ROOM0 || field_type == mFI_FIELD_NPCROOM0 || field_type == mFI_FIELD_PLAYER0_ROOM) { - if (force->room_nonstop != 3) { - mBGMRoom_shop_close_time_set(&M_bgm.room); - mBGMRoom_scene_bgm_make_req(); - } - } - else { - mBGMDemo_scene_bgm_make_req(); - } - } } extern void mBGM_cleanup() { - mBGMForce* force = &M_bgm.force; + mBGMForce* force = &M_bgm.force; - mBGMForce_cleanup(force); - if (mFI_CheckFieldData()) { - mActor_name_t field_id = mFI_GetFieldId(); - mActor_name_t field_type = mFI_GET_TYPE(field_id); + mBGMForce_cleanup(force); + if (mFI_CheckFieldData()) { + mActor_name_t field_id = mFI_GetFieldId(); + mActor_name_t field_type = mFI_GET_TYPE(field_id); - if (field_type == mFI_FIELD_FG) { - if (mEv_CheckTitleDemo() > 0) { - mBGMPsComp_delete_ps_demo(70, 0x168); // Stop title music - } - else { - if ((force->inform != mBGMForce_INFORM_3 && force->inform != mBGMForce_INFORM_7) || force->flag) { - mBGMFieldNorm_delete_req(); + if (field_type == mFI_FIELD_FG) { + if (mEv_CheckTitleDemo() > 0) { + mBGMPsComp_delete_ps_demo(70, 0x168); // Stop title music + } else { + if ((force->inform != mBGMForce_INFORM_3 && force->inform != mBGMForce_INFORM_7) || force->flag) { + mBGMFieldNorm_delete_req(); + } + + if (force->inform == mBGMForce_INFORM_7 && force->flag) { + mBGMPsComp_delete_ps_quiet(); + } + } + } else if (field_type == mFI_FIELD_ROOM0 || field_type == mFI_FIELD_NPCROOM0 || + field_type == mFI_FIELD_PLAYER0_ROOM) { + if (force->room_nonstop != 3) { + mBGMRoom_scene_bgm_delete_req(); + } + } else { + mBGMDemo_scene_bgm_delete_req(); } - - if (force->inform == mBGMForce_INFORM_7 && force->flag) { - mBGMPsComp_delete_ps_quiet(); - } - } } - else if (field_type == mFI_FIELD_ROOM0 || field_type == mFI_FIELD_NPCROOM0 || field_type == mFI_FIELD_PLAYER0_ROOM) { - if (force->room_nonstop != 3) { - mBGMRoom_scene_bgm_delete_req(); - } - } - else { - mBGMDemo_scene_bgm_delete_req(); - } - } } extern void mBGM_reset() { - mBGM* bgm = &M_bgm; - mBGMPsComp* ps_comp = &bgm->ps_comp; - mBGMPs* ps = ps_comp->ps; - int i; - int max = ps_comp->ps_num; + mBGM* bgm = &M_bgm; + mBGMPsComp* ps_comp = &bgm->ps_comp; + mBGMPs* ps = ps_comp->ps; + int i; + int max = ps_comp->ps_num; - for (i = 0; i < max; i++, ps++) { - ps->cf_flags |= mBGMPs_FLAG_REMOVE; - ps->elem.stop_type0 = 0x168; - } + for (i = 0; i < max; i++, ps++) { + ps->cf_flags |= mBGMPs_FLAG_REMOVE; + ps->elem.stop_type0 = 0x168; + } - if (ps_comp->fishing_state != 0) { - mBGMPsComp_volume_fishing_end(); - } + if (ps_comp->fishing_state != 0) { + mBGMPsComp_volume_fishing_end(); + } - if (ps_comp->collect_insects_state != 0) { - mBGMPsComp_volume_collect_insects_end(); - } + if (ps_comp->collect_insects_state != 0) { + mBGMPsComp_volume_collect_insects_end(); + } - if (ps_comp->talk_state != 0) { - mBGMPsComp_volume_talk_end(); - } + if (ps_comp->talk_state != 0) { + mBGMPsComp_volume_talk_end(); + } - if (ps_comp->boat_state != 0) { - mBGMPsComp_volume_boat_end(); - } + if (ps_comp->boat_state != 0) { + mBGMPsComp_volume_boat_end(); + } - if (ps_comp->pause_state != 0) { - mBGMPsComp_pause(5); - } + if (ps_comp->pause_state != 0) { + mBGMPsComp_pause(5); + } - mBGMDemo_ct(&bgm->demo); - mBGMRoom_ct(&bgm->room); - mBGMTime_ct(&bgm->time); - mBGMFieldSuddenEv_ct(&bgm->field_sudden_ev); - mBGMFieldSchedEv_ct(&bgm->field_sched_ev); - mBGMFieldNorm_ct(&bgm->field_norm); - mBGMForce_ct(&bgm->force); + mBGMDemo_ct(&bgm->demo); + mBGMRoom_ct(&bgm->room); + mBGMTime_ct(&bgm->time); + mBGMFieldSuddenEv_ct(&bgm->field_sudden_ev); + mBGMFieldSchedEv_ct(&bgm->field_sched_ev); + mBGMFieldNorm_ct(&bgm->field_norm); + mBGMForce_ct(&bgm->force); } diff --git a/src/m_fbdemo.c b/src/m_fbdemo.c index efd539ea..7bfd4d31 100644 --- a/src/m_fbdemo.c +++ b/src/m_fbdemo.c @@ -4,205 +4,194 @@ #include "libc64/sleep.h" #include "libultra/gu.h" #include "m_play.h" +#include "libultra/libultra.h" Gfx fbdemo_gfx_init[] = { gsDPPipeSync(), gsSPTexture(0x8000, 0x8000, 0, G_TX_RENDERTILE, G_ON), - gsSPClearGeometryMode(G_ZBUFFER | G_SHADE | G_CULL_BOTH | G_FOG | - G_LIGHTING | G_TEXTURE_GEN | G_TEXTURE_GEN_LINEAR | - G_LOD | G_SHADING_SMOOTH), + gsSPClearGeometryMode(G_ZBUFFER | G_SHADE | G_CULL_BOTH | G_FOG | G_LIGHTING | G_TEXTURE_GEN | + G_TEXTURE_GEN_LINEAR | G_LOD | G_SHADING_SMOOTH), gsDPSetCombineMode(G_CC_DECALRGB, G_CC_DECALRGB), - gsDPSetOtherMode( - G_AD_DISABLE | G_CD_MAGICSQ | G_CK_NONE | G_TC_FILT | G_TF_BILERP | - G_TT_NONE | G_TL_TILE | G_TD_CLAMP | G_TP_PERSP | G_CYC_1CYCLE | - G_PM_1PRIMITIVE, - G_AC_NONE | G_ZS_PIXEL | G_RM_AA_OPA_SURF | G_RM_AA_OPA_SURF2), + gsDPSetOtherMode(G_AD_DISABLE | G_CD_MAGICSQ | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_NONE | G_TL_TILE | + G_TD_CLAMP | G_TP_PERSP | G_CYC_1CYCLE | G_PM_1PRIMITIVE, + G_AC_NONE | G_ZS_PIXEL | G_RM_AA_OPA_SURF | G_RM_AA_OPA_SURF2), gsSPEndDisplayList(), }; extern void fbdemo_init_gfx(fbdemo_c* this) { - int col; - int col2; - int colTex; - int rowTex; + int col; + int col2; + int colTex; + int rowTex; - int row; - int frame; + int row; + int frame; - Vtx* vtx; - Gfx* gfx; + Vtx* vtx; + Gfx* gfx; - guMtxIdent(&this->modelView1); - guMtxIdent(&this->modelView2); - guOrtho(&this->projection, 0.0f, 320, 240, 0.0f, -1000.0f, 1000.0f, 1.0f); + guMtxIdent(&this->modelView1); + guMtxIdent(&this->modelView2); + guOrtho(&this->projection, 0.0f, 320, 240, 0.0f, -1000.0f, 1000.0f, 1.0f); - for (frame = 0; frame < 2; frame++) { - this->frame = frame; - vtx = (this->frame == 0) ? this->vtxFrame1 : this->vtxFrame2; - for (rowTex = 0, row = 0; row < (this->rows + 1); rowTex += 0x20, row++) { - for (colTex = 0, col = 0; col < (this->cols + 1); colTex += 0x20, col++) { - Vtx_tn* vtxn = &vtx->n; - vtx++; - vtxn->ob[0] = col * 0x20; - vtxn->ob[1] = row * 0x20; - vtxn->ob[2] = -5; - vtxn->flag = 0; - vtxn->tc[0] = colTex << 6; - vtxn->tc[1] = rowTex << 6; - vtxn->n[0] = 0; - vtxn->n[1] = 0; - vtxn->n[2] = 120; - vtxn->a = 255; - } + for (frame = 0; frame < 2; frame++) { + this->frame = frame; + vtx = (this->frame == 0) ? this->vtxFrame1 : this->vtxFrame2; + for (rowTex = 0, row = 0; row < (this->rows + 1); rowTex += 0x20, row++) { + for (colTex = 0, col = 0; col < (this->cols + 1); colTex += 0x20, col++) { + Vtx_tn* vtxn = &vtx->n; + vtx++; + vtxn->ob[0] = col * 0x20; + vtxn->ob[1] = row * 0x20; + vtxn->ob[2] = -5; + vtxn->flag = 0; + vtxn->tc[0] = colTex << 6; + vtxn->tc[1] = rowTex << 6; + vtxn->n[0] = 0; + vtxn->n[1] = 0; + vtxn->n[2] = 120; + vtxn->a = 255; + } + } } - } - gfx = this->gfx; - for (rowTex = 0, row = 0; row < this->rows; rowTex += 0x20, row++) { - gSPVertex(gfx++, - SEGMENT_ADDR(0xA, (u32)row * (this->cols + 1) * sizeof(Vtx)), - 2 * (this->cols + 1), 0); + gfx = this->gfx; + for (rowTex = 0, row = 0; row < this->rows; rowTex += 0x20, row++) { + gSPVertex(gfx++, SEGMENT_ADDR(0xA, (u32)row * (this->cols + 1) * sizeof(Vtx)), 2 * (this->cols + 1), 0); - colTex = 0; - col = 0; - col2 = 0; - while (col < this->cols) { - gDPPipeSync(gfx++); + colTex = 0; + col = 0; + col2 = 0; + while (col < this->cols) { + gDPPipeSync(gfx++); - gDPLoadTextureTile(gfx++, SEGMENT_ADDR(0xB, 0), G_IM_FMT_RGBA, - G_IM_SIZ_16b, 320, 240, colTex, rowTex, colTex + 0x20, - rowTex + 0x20, 0, G_TX_NOMIRROR | G_TX_WRAP, - G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, - G_TX_NOLOD, G_TX_NOLOD); + gDPLoadTextureTile(gfx++, SEGMENT_ADDR(0xB, 0), G_IM_FMT_RGBA, G_IM_SIZ_16b, 320, 240, colTex, rowTex, + colTex + 0x20, rowTex + 0x20, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, + G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); - gSP1Quadrangle(gfx++, col2, col2 + 1, +(this->cols) + 2 + col2, - this->cols + 1 + col2, 0); + gSP1Quadrangle(gfx++, col2, col2 + 1, +(this->cols) + 2 + col2, this->cols + 1 + col2, 0); - colTex += 0x20; - col2++; - col++; + colTex += 0x20; + col2++; + col++; + } } - } - gDPPipeSync(gfx++); - gSPEndDisplayList(gfx++); + gDPPipeSync(gfx++); + gSPEndDisplayList(gfx++); } extern void fbdemo_init_data(fbdemo_c* this) { - int col; - int row; + int col; + int row; - for (row = 0; row < this->rows + 1; row++) { - for (col = 0; col < this->cols + 1; col++) { - (this->vtxData + col + row * (this->cols + 1))->x = col * 0x20; - (this->vtxData + col + row * (this->cols + 1))->y = row * 0x20; + for (row = 0; row < this->rows + 1; row++) { + for (col = 0; col < this->cols + 1; col++) { + (this->vtxData + col + row * (this->cols + 1))->x = col * 0x20; + (this->vtxData + col + row * (this->cols + 1))->y = row * 0x20; + } } - } } extern void fbdemo_cleanup(fbdemo_c* this) { - msleep(100); + msleep(100); - if (this->vtxData != NULL) { - free(this->vtxData); - this->vtxData = NULL; - } - if (this->vtxFrame1 != NULL) { - free(this->vtxFrame1); - this->vtxFrame1 = NULL; - } - if (this->vtxFrame2 != NULL) { - free(this->vtxFrame2); - this->vtxFrame2 = NULL; - } - if (this->gfx != NULL) { - free(this->gfx); - this->gfx = NULL; - } + if (this->vtxData != NULL) { + free(this->vtxData); + this->vtxData = NULL; + } + if (this->vtxFrame1 != NULL) { + free(this->vtxFrame1); + this->vtxFrame1 = NULL; + } + if (this->vtxFrame2 != NULL) { + free(this->vtxFrame2); + this->vtxFrame2 = NULL; + } + if (this->gfx != NULL) { + free(this->gfx); + this->gfx = NULL; + } } extern fbdemo_c* fbdemo_init(fbdemo_c* this, int cols, int rows) { - s32 gridsize; + s32 gridsize; - bzero(this, sizeof(fbdemo)); + bzero(this, sizeof(fbdemo)); - this->cols = cols; - this->rows = rows; + this->cols = cols; + this->rows = rows; - this->frame = 0; - this->vtxData = malloc((cols + 1) * sizeof(xy_t) * (rows + 1)); + this->frame = 0; + this->vtxData = malloc((cols + 1) * sizeof(xy_t) * (rows + 1)); - this->vtxFrame1 = malloc((cols + 1) * sizeof(Vtx) * (rows + 1)); - this->vtxFrame2 = malloc((cols + 1) * sizeof(Vtx) * (rows + 1)); + this->vtxFrame1 = malloc((cols + 1) * sizeof(Vtx) * (rows + 1)); + this->vtxFrame2 = malloc((cols + 1) * sizeof(Vtx) * (rows + 1)); - this->gfx = malloc(((this->cols * 9 + 1) * this->rows + 2) * sizeof(Gfx)); + this->gfx = malloc(((this->cols * 9 + 1) * this->rows + 2) * sizeof(Gfx)); - if ((this->vtxData == NULL) || (this->vtxFrame1 == NULL) || - (this->vtxFrame2 == NULL) || (this->gfx == NULL)) { - if (this->vtxData != NULL) { - free(this->vtxData); - this->vtxData = NULL; + if ((this->vtxData == NULL) || (this->vtxFrame1 == NULL) || (this->vtxFrame2 == NULL) || (this->gfx == NULL)) { + if (this->vtxData != NULL) { + free(this->vtxData); + this->vtxData = NULL; + } + + if (this->vtxFrame1 != NULL) { + free(this->vtxFrame1); + this->vtxFrame1 = NULL; + } + + if (this->vtxFrame2 != NULL) { + free(this->vtxFrame2); + this->vtxFrame2 = NULL; + } + + if (this->gfx != NULL) { + free(this->gfx); + this->gfx = NULL; + } + + return NULL; } - if (this->vtxFrame1 != NULL) { - free(this->vtxFrame1); - this->vtxFrame1 = NULL; - } + fbdemo_init_gfx(this); + fbdemo_init_data(this); + this->frame = 0; - if (this->vtxFrame2 != NULL) { - free(this->vtxFrame2); - this->vtxFrame2 = NULL; - } - - if (this->gfx != NULL) { - free(this->gfx); - this->gfx = NULL; - } - - return NULL; - } - - fbdemo_init_gfx(this); - fbdemo_init_data(this); - this->frame = 0; - - return this; + return this; } extern void fbdemo_update(fbdemo_c* this) { - int col; - int row; - Vtx* vtx; + int col; + int row; + Vtx* vtx; - for (row = 0; row < this->rows + 1; row++) { - for (col = 0; col < this->cols + 1; col++) { - vtx = (this->frame == 0) ? this->vtxFrame1 : this->vtxFrame2; - (vtx + col + row * (this->cols + 1))->n.ob[0] = - (this->vtxData + col + row * (this->cols + 1))->x; + for (row = 0; row < this->rows + 1; row++) { + for (col = 0; col < this->cols + 1; col++) { + vtx = (this->frame == 0) ? this->vtxFrame1 : this->vtxFrame2; + (vtx + col + row * (this->cols + 1))->n.ob[0] = (this->vtxData + col + row * (this->cols + 1))->x; - vtx = (this->frame == 0) ? this->vtxFrame1 : this->vtxFrame2; - (vtx + col + row * (this->cols + 1))->n.ob[1] = - (this->vtxData + col + row * (this->cols + 1))->y; + vtx = (this->frame == 0) ? this->vtxFrame1 : this->vtxFrame2; + (vtx + col + row * (this->cols + 1))->n.ob[1] = (this->vtxData + col + row * (this->cols + 1))->y; + } } - } } void fbdemo_draw(fbdemo_c* this, Gfx** gfxP) { - Gfx* gfx = *gfxP; + Gfx* gfx = *gfxP; - gSPDisplayList(gfx++, fbdemo_gfx_init); - fbdemo_update(this); - gSPMatrix(gfx++, &this->projection, - G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION); - gSPMatrix(gfx++, &this->modelView1, - G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); - gSPSegment(gfx++, 0xA, this->frame == 0 ? this->vtxFrame1 : this->vtxFrame2); - gSPSegment(gfx++, 0xB, this->zBuffer); - gSPDisplayList(gfx++, fbdemo_gfx_init); - gSPDisplayList(gfx++, this->gfx); - gDPPipeSync(gfx++); - this->frame ^= 1; - *gfxP = gfx; + gSPDisplayList(gfx++, fbdemo_gfx_init); + fbdemo_update(this); + gSPMatrix(gfx++, &this->projection, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION); + gSPMatrix(gfx++, &this->modelView1, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPSegment(gfx++, 0xA, this->frame == 0 ? this->vtxFrame1 : this->vtxFrame2); + gSPSegment(gfx++, 0xB, this->zBuffer); + gSPDisplayList(gfx++, fbdemo_gfx_init); + gSPDisplayList(gfx++, this->gfx); + gDPPipeSync(gfx++); + this->frame ^= 1; + *gfxP = gfx; } -extern void fbdemo_move(fbdemo_c* this) {} +extern void fbdemo_move(fbdemo_c* this) { +} diff --git a/src/m_flashrom.c b/src/m_flashrom.c index 0a12b08a..c1d99ff8 100644 --- a/src/m_flashrom.c +++ b/src/m_flashrom.c @@ -37,313 +37,312 @@ #include "m_time.h" #include "m_land.h" #include "m_name_table.h" +#include "libultra/libultra.h" #include "zurumode.h" static int l_mfrm_msg_idx = 0; static int l_mfrm_now_color = 0; static mFRm_err_info_c l_mfrm_err_info[mFRm_ERROR_INFO_NUM]; -static int l_mfrm_err_debug[] = {0, 0, 0, 0, 0, 0}; - +static int l_mfrm_err_debug[] = { 0, 0, 0, 0, 0, 0 }; /** * @brief Set the current message index value. - * + * * This function sets the global message index value to the provided input. - * + * * @param idx The message index value to be set. */ extern void mFRm_set_msg_idx(int idx) { - l_mfrm_msg_idx = idx; + l_mfrm_msg_idx = idx; } /** * @brief Get the current message index value. - * + * * This function returns the global message index value. - * + * * @return int The current message index value. */ extern int mFRm_get_msg_idx() { - return l_mfrm_msg_idx; + return l_mfrm_msg_idx; } /* @fabricated - necessary for including some strings in .data & taken from DnM */ extern MATCH_FORCESTRIP void mFRm_PrintErrInfo(gfxprint_t* gfxprint) { - gfxprint_color(gfxprint, 250, 100, 250, 255); - gfxprint_locate8x8(gfxprint, 22, 3); + gfxprint_color(gfxprint, 250, 100, 250, 255); + gfxprint_locate8x8(gfxprint, 22, 3); - if (l_mfrm_err_debug[0] != 0) { - gfxprint_printf(gfxprint, "N"); - } + if (l_mfrm_err_debug[0] != 0) { + gfxprint_printf(gfxprint, "N"); + } - if (l_mfrm_err_debug[1] != 0) { - gfxprint_printf(gfxprint, "A"); - } + if (l_mfrm_err_debug[1] != 0) { + gfxprint_printf(gfxprint, "A"); + } - if (l_mfrm_err_debug[2] != 0) { - gfxprint_printf(gfxprint, "W"); - } + if (l_mfrm_err_debug[2] != 0) { + gfxprint_printf(gfxprint, "W"); + } - if (l_mfrm_err_debug[3] != 0) { - gfxprint_printf(gfxprint, "R"); - } + if (l_mfrm_err_debug[3] != 0) { + gfxprint_printf(gfxprint, "R"); + } - if (l_mfrm_err_debug[4] != 0) { - gfxprint_printf(gfxprint, "C"); - } + if (l_mfrm_err_debug[4] != 0) { + gfxprint_printf(gfxprint, "C"); + } - if (l_mfrm_err_debug[5] != 0) { - gfxprint_printf(gfxprint, "O"); - } + if (l_mfrm_err_debug[5] != 0) { + gfxprint_printf(gfxprint, "O"); + } } /** * @brief Calculate the checksum of the given data. - * + * * This function calculates the checksum of the provided data by adding * all the 16-bit data elements together. - * + * * @param data A pointer to the data buffer. * @param size The size of the data buffer in bytes. * @return u16 The calculated checksum. */ extern u16 mFRm_ReturnCheckSum(u16* data, int size) { - u16 checksum = 0; + u16 checksum = 0; - // Check if the size is even - if ((size & 1) == 0) { - // Calculate the checksum by adding all 16-bit data elements - while (size != 0) { - checksum += *data; - data++; - size -= sizeof(u16); + // Check if the size is even + if ((size & 1) == 0) { + // Calculate the checksum by adding all 16-bit data elements + while (size != 0) { + checksum += *data; + data++; + size -= sizeof(u16); + } } - } - return checksum; + return checksum; } /** * @brief Calculate the flat checksum of the given data. - * + * * This function calculates the flat checksum of the provided data by * subtracting the current checksum from the calculated checksum and * then performing a bitwise complement and incrementing by 1. - * + * * @param data A pointer to the data buffer. * @param size The size of the data buffer in bytes. * @param now_checksum The current checksum of the data buffer. * @return u16 The calculated flat checksum. */ extern u16 mFRm_GetFlatCheckSum(u16* data, int size, u16 now_checksum) { - // Calculate the checksum - u16 checksum = mFRm_ReturnCheckSum(data, size) - now_checksum; + // Calculate the checksum + u16 checksum = mFRm_ReturnCheckSum(data, size) - now_checksum; - // Perform bitwise complement and increment by 1 - return (u16)(((~checksum & 0xFFFF) + 1) & 0xFFFF); + // Perform bitwise complement and increment by 1 + return (u16)(((~checksum & 0xFFFF) + 1) & 0xFFFF); } /** * @brief Check if the save data ID is valid. - * + * * This function checks if the provided save_check structure contains a valid * save data ID. - * + * * @param save_check A pointer to the mFRm_chk_t structure containing the save data ID. * @return int Returns TRUE if the save data ID is valid, otherwise FALSE. */ extern int mFRm_CheckSaveData_ID(mFRm_chk_t* save_check) { - int ret = FALSE; - - // Check if the save data ID is valid - if ((save_check->code == mFRm_SAVE_ID)) { - ret = TRUE; - } - - return ret; + int ret = FALSE; + + // Check if the save data ID is valid + if ((save_check->code == mFRm_SAVE_ID)) { + ret = TRUE; + } + + return ret; } /** * @brief Check if the save data is valid. - * + * * This function checks if the provided save_check structure contains valid save data, * comparing the land ID with the provided land_id parameter. - * + * * @param save_check A pointer to the mFRm_chk_t structure containing the save data. * @param land_id The land ID to check against the save data. * @return int Returns TRUE if the save data is valid, otherwise FALSE. */ extern int mFRm_CheckSaveData_common(mFRm_chk_t* save_check, u16 land_id) { - int ret = FALSE; + int ret = FALSE; - // Check if the save data ID is valid and land IDs match - if (mFRm_CheckSaveData_ID(save_check) != 0 && - mLd_CHECK_LAND_ID(save_check->land_id) && - save_check->land_id == land_id) { - ret = TRUE; - } + // Check if the save data ID is valid and land IDs match + if (mFRm_CheckSaveData_ID(save_check) != 0 && mLd_CHECK_LAND_ID(save_check->land_id) && + save_check->land_id == land_id) { + ret = TRUE; + } - return ret; + return ret; } /** * @brief Check if the current save data is valid. - * + * * This function checks if the current save data is valid using mFRm_CheckSaveData_common. - * + * * @return int Returns TRUE if the save data is valid, otherwise FALSE. */ extern int mFRm_CheckSaveData() { - return mFRm_CheckSaveData_common(Save_GetPointer(save_check), Save_Get(land_info.id)); + return mFRm_CheckSaveData_common(Save_GetPointer(save_check), Save_Get(land_info.id)); } /** * @brief Clear the save check data. - * + * * This function clears the provided save_check structure by setting its fields to their * default values. - * + * * @param save_check A pointer to the mFRm_chk_t structure to be cleared. */ extern void mFRm_ClearSaveCheckData(mFRm_chk_t* save_check) { - // Set the save check data fields to their default values - save_check->code = -1; - save_check->land_id = 0xFFFF; - bcopy((lbRTC_time_c*)&mTM_rtcTime_clear_code, &save_check->time, sizeof(lbRTC_time_c)); - save_check->checksum = 0; + // Set the save check data fields to their default values + save_check->code = -1; + save_check->land_id = 0xFFFF; + bcopy((lbRTC_time_c*)&mTM_rtcTime_clear_code, &save_check->time, sizeof(lbRTC_time_c)); + save_check->checksum = 0; } /** * @brief Set the save check data. - * + * * This function sets the save check data fields based on the current save data * and real-time clock values. - * + * * @param save_check A pointer to the mFRm_chk_t structure to be set. */ extern void mFRm_SetSaveCheckData(mFRm_chk_t* save_check) { - u16 land_id = Save_Get(land_info.id); + u16 land_id = Save_Get(land_info.id); - // Set the save check data fields - save_check->code = mFRm_SAVE_ID; - save_check->land_id = land_id; - lbRTC_TimeCopy(&save_check->time, &common_data.time.rtc_time); + // Set the save check data fields + save_check->code = mFRm_SAVE_ID; + save_check->land_id = land_id; + lbRTC_TimeCopy(&save_check->time, &common_data.time.rtc_time); } /** * @brief Print the saved debug information. - * + * * This function prints an 'X' to the screen if the saved debug information is available. - * + * * @param gfxprint A pointer to the gfxprint_t structure for screen printing. */ extern void mFRm_PrintSavedDebug(gfxprint_t* gfxprint) { - // Check if the saved debug information is available - if (Save_Get(saved_rom_debug) == TRUE) { - // Set the print color and location - gfxprint_color(gfxprint, 50, 250, 100, 255); - gfxprint_locate8x8(gfxprint, 29, 3); - // Print an 'X' to the screen - gfxprint_printf(gfxprint, "X"); - } + // Check if the saved debug information is available + if (Save_Get(saved_rom_debug) == TRUE) { + // Set the print color and location + gfxprint_color(gfxprint, 50, 250, 100, 255); + gfxprint_locate8x8(gfxprint, 29, 3); + // Print an 'X' to the screen + gfxprint_printf(gfxprint, "X"); + } } /* Color table for displaying error information */ static u32 l_mfrm_color_table[7][3] = { - { 0, 0, 0}, /* Black */ - {255, 0, 0}, /* Red */ - {255, 255, 255}, /* White */ - { 0, 190, 0}, /* Green */ - {100, 100, 100}, /* Gray */ - { 0, 0, 255}, /* Blue */ - {255, 0, 255} /* Magenta */ + { 0, 0, 0 }, /* Black */ + { 255, 0, 0 }, /* Red */ + { 255, 255, 255 }, /* White */ + { 0, 190, 0 }, /* Green */ + { 100, 100, 100 }, /* Gray */ + { 0, 0, 255 }, /* Blue */ + { 255, 0, 255 } /* Magenta */ }; /** * @brief Clear the error information. - * + * * This function clears the error information by setting all error numbers * to mFRm_NO_ERROR_NO. */ extern void mFRm_clear_err_info() { - int i; - // Zero out the error information array - bzero(l_mfrm_err_info, sizeof(mFRm_err_info_c) * mFRm_ERROR_INFO_NUM); + int i; + // Zero out the error information array + bzero(l_mfrm_err_info, sizeof(mFRm_err_info_c) * mFRm_ERROR_INFO_NUM); - // Set all error numbers to mFRm_NO_ERROR_NO - for (i = 0; i < mFRm_ERROR_INFO_NUM; i++) { - l_mfrm_err_info[i].err_no = mFRm_NO_ERROR_NO; - } + // Set all error numbers to mFRm_NO_ERROR_NO + for (i = 0; i < mFRm_ERROR_INFO_NUM; i++) { + l_mfrm_err_info[i].err_no = mFRm_NO_ERROR_NO; + } } /** * @brief Get a free error information slot. - * + * * This function returns a pointer to the first available error information slot. - * + * * @param err_info A pointer to the error information array. * @param count The number of error information slots. * @return mFRm_err_info_c* A pointer to the first available error information slot or NULL if none are available. */ static mFRm_err_info_c* mFRm_get_free_errInfo(mFRm_err_info_c* err_info, int count) { - mFRm_err_info_c* ret = NULL; + mFRm_err_info_c* ret = NULL; - // Iterate through the error information slots - while (count != 0) { - // Check if the current slot is available - if (err_info->err_no == mFRm_NO_ERROR_NO) { - ret = err_info; - break; + // Iterate through the error information slots + while (count != 0) { + // Check if the current slot is available + if (err_info->err_no == mFRm_NO_ERROR_NO) { + ret = err_info; + break; + } + err_info++; + count--; } - err_info++; - count--; - } - return ret; + return ret; } /** * @brief Set the error information for a specific process. - * + * * This function sets the error information for the specified process index and error number. - * + * * @param err_info A pointer to the error information array. * @param proc_idx The process index for which the error occurred. * @param err_no The error number to be set. */ static void mFRm_set_errInfo(mFRm_err_info_c* err_info, int proc_idx, int err_no) { - // Get a free error information slot - mFRm_err_info_c* free = mFRm_get_free_errInfo(err_info, mFRm_ERROR_INFO_NUM); + // Get a free error information slot + mFRm_err_info_c* free = mFRm_get_free_errInfo(err_info, mFRm_ERROR_INFO_NUM); - // Set the error information if a free slot is available - if (free != NULL) { - free->err_no = err_no; - free->proc_idx = proc_idx; - } + // Set the error information if a free slot is available + if (free != NULL) { + free->err_no = err_no; + free->proc_idx = proc_idx; + } } /** * @brief Get the number of error information slots with errors. - * + * * This function returns the number of error information slots with error numbers * different from mFRm_NO_ERROR_NO. - * + * * @param err_info A pointer to the error information array. * @param count The number of error information slots. * @return int The number of error information slots with errors. */ static int mFRm_get_errInfoNum(mFRm_err_info_c* err_info, int count) { - int ret = 0; + int ret = 0; - // Loop through the error information slots - while (count != 0) { - // Increment the count if the error number is not mFRm_NO_ERROR_NO - if (err_info->err_no != mFRm_NO_ERROR_NO) { - ret++; + // Loop through the error information slots + while (count != 0) { + // Increment the count if the error number is not mFRm_NO_ERROR_NO + if (err_info->err_no != mFRm_NO_ERROR_NO) { + ret++; + } + err_info++; + count--; } - err_info++; - count--; - } - return ret; + return ret; } #define mFRm_ERRORLINE(line) mFRm_set_errInfo(l_mfrm_err_info, (line), l_mfrm_now_color) @@ -359,82 +358,70 @@ static int mFRm_get_errInfoNum(mFRm_err_info_c* err_info, int count) { /** * @brief Perform save data checks. - * + * * This function performs save data checks for different procedures and * increments the color index upon each check. */ extern void mFRm_save_data_check() { - // Define save data check procedures - static save_check_proc* proc[] = { - &sChk_check_save_data, &sChk_check_save_gen, &sChk_CheckSaveData_MYK, - &sChk_CheckSaveData_NSW, &sChk_check_save_take, &sChk_CheckSaveData_YSD, - &sChk_CheckSaveData_komatu - }; + // Define save data check procedures + static save_check_proc* proc[] = { &sChk_check_save_data, &sChk_check_save_gen, &sChk_CheckSaveData_MYK, + &sChk_CheckSaveData_NSW, &sChk_check_save_take, &sChk_CheckSaveData_YSD, + &sChk_CheckSaveData_komatu }; - int i = 0; - mFRm_err_info_c* err_info = l_mfrm_err_info; - l_mfrm_now_color = 0; + int i = 0; + mFRm_err_info_c* err_info = l_mfrm_err_info; + l_mfrm_now_color = 0; - // If zurumode_flag is greater or equal to 2 and scene_no is 7, perform save data checks - if ((zurumode_flag >= 2) && (Save_Get(scene_no) == 7)) { - // If there are no errors, perform the save data checks - if (mFRm_get_errInfoNum(err_info, mFRm_ERROR_INFO_NUM) == 0) { - while (i < 7) { - (*proc[i])(); - l_mfrm_now_color++; - i++; - } + // If zurumode_flag is greater or equal to 2 and scene_no is 7, perform save data checks + if ((zurumode_flag >= 2) && (Save_Get(scene_no) == 7)) { + // If there are no errors, perform the save data checks + if (mFRm_get_errInfoNum(err_info, mFRm_ERROR_INFO_NUM) == 0) { + while (i < 7) { + (*proc[i])(); + l_mfrm_now_color++; + i++; + } + } } - } } /** * @brief Display error information on the screen. - * + * * This function displays the error information on the screen if there are * any errors and if the zurumode_flag is greater than or equal to 2. - * + * * @param gfxprint A pointer to the gfxprint_t structure for screen printing. */ extern void mFRm_display_errInfo(gfxprint_t* gfxprint) { - mFRm_err_info_c* err_info = l_mfrm_err_info; - int i; + mFRm_err_info_c* err_info = l_mfrm_err_info; + int i; - // If zurumode_flag is greater or equal to 2 and scene_no is 7, display - // error information - if ((zurumode_flag >= 2) && (Save_Get(scene_no) == 7)) { - gfxprint_locate8x8(gfxprint, 37, 17); - gfxprint_color(gfxprint, 255, 255, 255, 255); - gfxprint_printf(gfxprint, "-"); + // If zurumode_flag is greater or equal to 2 and scene_no is 7, display + // error information + if ((zurumode_flag >= 2) && (Save_Get(scene_no) == 7)) { + gfxprint_locate8x8(gfxprint, 37, 17); + gfxprint_color(gfxprint, 255, 255, 255, 255); + gfxprint_printf(gfxprint, "-"); - // If there are errors, display them on the screen - if (mFRm_get_errInfoNum(err_info, mFRm_ERROR_INFO_NUM) > 0) { - for (i = 0; i < 10; i++) { - gfxprint_locate8x8(gfxprint, 30, i + 18); + // If there are errors, display them on the screen + if (mFRm_get_errInfoNum(err_info, mFRm_ERROR_INFO_NUM) > 0) { + for (i = 0; i < 10; i++) { + gfxprint_locate8x8(gfxprint, 30, i + 18); - // Break the loop if no error is found - if (err_info->err_no == mFRm_NO_ERROR_NO) { - break; + // Break the loop if no error is found + if (err_info->err_no == mFRm_NO_ERROR_NO) { + break; + } + + // Set the color for displaying the error information + gfxprint_color(gfxprint, l_mfrm_color_table[err_info->err_no][0], + l_mfrm_color_table[err_info->err_no][1], l_mfrm_color_table[err_info->err_no][2], 255); + + // Display the error information + gfxprint_printf(gfxprint, "x%dx %d", err_info->err_no, err_info->proc_idx); + err_info++; + } } - - // Set the color for displaying the error information - gfxprint_color( - gfxprint, - l_mfrm_color_table[err_info->err_no][0], - l_mfrm_color_table[err_info->err_no][1], - l_mfrm_color_table[err_info->err_no][2], - 255 - ); - - // Display the error information - gfxprint_printf( - gfxprint, - "x%dx %d", - err_info->err_no, - err_info->proc_idx - ); - err_info++; - } } - } } diff --git a/src/m_font.c b/src/m_font.c index c38450c7..43996b13 100644 --- a/src/m_font.c +++ b/src/m_font.c @@ -12,8 +12,9 @@ #include "MSL_C/w_math.h" #include "m_rcp.h" #include "libc/math.h" +#include "libultra/libultra.h" -#define mFont_CC_FONT 0, 0, 0, PRIMITIVE, PRIMITIVE, 0, TEXEL0, 0 +#define mFont_CC_FONT 0, 0, 0, PRIMITIVE, PRIMITIVE, 0, TEXEL0, 0 #define mFont_CC_NOFONT 0, 0, 0, PRIMITIVE, 0, PRIMITIVE, TEXEL0, PRIMITIVE #include "../src/m_font_offset.c_inc" @@ -24,200 +25,190 @@ /* @unused static u8* mFont_Get_end_load_texture() */ extern void mFont_ct() { - // code removed probably + // code removed probably } static int mMsg_CutLeftSpace(u8* str, int str_len) { - // This should've been renamed or moved to m_message.h - - u8* dst; - u8* src; - int i, j; + // This should've been renamed or moved to m_message.h - for (i = 0; i < str_len; i++) { - if (str[i] != CHAR_SPACE) { - break; + u8* dst; + u8* src; + int i, j; + + for (i = 0; i < str_len; i++) { + if (str[i] != CHAR_SPACE) { + break; + } } - } - if (i == str_len) { - return 0; - } - else if (i == 0) { - return str_len; - } + if (i == str_len) { + return 0; + } else if (i == 0) { + return str_len; + } - dst = str; - src = str + i; - for (j = i; j < str_len; j++) { - *dst++ = *src++; - } + dst = str; + src = str + i; + for (j = i; j < str_len; j++) { + *dst++ = *src++; + } - for (j = 0; j < i; j++) { - *dst++ = CHAR_SPACE; - } + for (j = 0; j < i; j++) { + *dst++ = CHAR_SPACE; + } - return str_len - i; + return str_len - i; } static u8 mFont_suji_data[] = "0123456789"; static int mFont_suji_check(u8 c) { - u8* suji = mFont_suji_data; - int i; + u8* suji = mFont_suji_data; + int i; - for (i = 0; i < 10; i++) { - if (c == suji[i]) { - return TRUE; + for (i = 0; i < 10; i++) { + if (c == suji[i]) { + return TRUE; + } } - } - return FALSE; + return FALSE; } -extern int mFont_UnintToString( - u8* str, - int figure, - u32 num, - int figure_start, - int left_cut, - int fill_zero, - int separator -) { - int i; - int j; - u32 cur_num; - int next; - - int temp2; - int last_figure; +extern int mFont_UnintToString(u8* str, int figure, u32 num, int figure_start, int left_cut, int fill_zero, + int separator) { + int i; + int j; + u32 cur_num; + int next; - int l = figure - figure_start; - u8 fill_char = fill_zero ? CHAR_ZERO : CHAR_SPACE; - u8 left_fill_char = fill_zero && !left_cut ? CHAR_ZERO : CHAR_SPACE; + int temp2; + int last_figure; - cur_num = num; - for (last_figure = figure - 1; last_figure >= l; last_figure--) { - next = cur_num / 10; - temp2 = cur_num - next * 10; - if (cur_num == 0) { - if (num == 0 && last_figure == figure - 1) { - str[last_figure] = CHAR_ZERO; - } - else { - str[last_figure] = fill_char; - } - } - else { - str[last_figure] = mFont_suji_data[temp2]; - } - cur_num = next; - } + int l = figure - figure_start; + u8 fill_char = fill_zero ? CHAR_ZERO : CHAR_SPACE; + u8 left_fill_char = fill_zero && !left_cut ? CHAR_ZERO : CHAR_SPACE; - for (i = last_figure; i >= 0; i--) { - str[i] = left_fill_char; - } - - if (separator) { - int count = 0; - for (i = figure - 1; i >= 0; i--) { - if (mFont_suji_check(str[i])) { - count++; - if (count > 3) { - for (j = 0; j < i; j++) { - str[j] = str[j + 1]; - } - - str[i] = CHAR_COMMA; - count = 0; + cur_num = num; + for (last_figure = figure - 1; last_figure >= l; last_figure--) { + next = cur_num / 10; + temp2 = cur_num - next * 10; + if (cur_num == 0) { + if (num == 0 && last_figure == figure - 1) { + str[last_figure] = CHAR_ZERO; + } else { + str[last_figure] = fill_char; + } + } else { + str[last_figure] = mFont_suji_data[temp2]; } - } + cur_num = next; } - } - if (left_cut) { - return mMsg_CutLeftSpace(str, figure); - } + for (i = last_figure; i >= 0; i--) { + str[i] = left_fill_char; + } - return figure; + if (separator) { + int count = 0; + for (i = figure - 1; i >= 0; i--) { + if (mFont_suji_check(str[i])) { + count++; + if (count > 3) { + for (j = 0; j < i; j++) { + str[j] = str[j + 1]; + } + + str[i] = CHAR_COMMA; + count = 0; + } + } + } + } + + if (left_cut) { + return mMsg_CutLeftSpace(str, figure); + } + + return figure; } extern int mFont_char_save_data_check(u8 c) { - return c == CHAR_CONTROL_CODE || c == CHAR_MESSAGE_TAG; + return c == CHAR_CONTROL_CODE || c == CHAR_MESSAGE_TAG; } extern u8 mFont_small_to_capital(u8 small) { - static const u8 tbl[56][2] = { - { CHAR_a, CHAR_A }, - { CHAR_b, CHAR_B }, - { CHAR_c, CHAR_C }, - { CHAR_d, CHAR_D }, - { CHAR_e, CHAR_E }, - { CHAR_f, CHAR_F }, - { CHAR_g, CHAR_G }, - { CHAR_h, CHAR_H }, - { CHAR_i, CHAR_I }, - { CHAR_j, CHAR_J }, - { CHAR_k, CHAR_K }, - { CHAR_l, CHAR_L }, - { CHAR_m, CHAR_M }, - { CHAR_n, CHAR_N }, - { CHAR_o, CHAR_O }, - { CHAR_p, CHAR_P }, - { CHAR_q, CHAR_Q }, - { CHAR_r, CHAR_R }, - { CHAR_s, CHAR_S }, - { CHAR_t, CHAR_T }, - { CHAR_u, CHAR_U }, - { CHAR_v, CHAR_V }, - { CHAR_w, CHAR_W }, - { CHAR_x, CHAR_X }, - { CHAR_y, CHAR_Y }, - { CHAR_z, CHAR_Z }, - { CHAR_DIARESIS_a, CHAR_DIAERESIS_A }, - { CHAR_GRAVE_a, CHAR_GRAVE_A }, - { CHAR_ACUTE_a, CHAR_ACUTE_A }, - { CHAR_CIRCUMFLEX_a, CHAR_CIRCUMFLEX_A }, - { CHAR_TILDE_a, CHAR_TILDE_A }, - { CHAR_ANGSTROM_a, CHAR_ANGSTROM_A }, - { CHAR_LOWER_CEDILLA, CHAR_CEDILLA }, - { CHAR_GRAVE_e, CHAR_GRAVE_E }, - { CHAR_ACUTE_e, CHAR_ACUTE_E }, - { CHAR_CIRCUMFLEX_e, CHAR_CIRCUMFLEX_E }, - { CHAR_DIARESIS_e, CHAR_DIARESIS_E }, - { CHAR_GRAVE_i, CHAR_GRAVE_I }, - { CHAR_ACUTE_i, CHAR_ACUTE_I }, - { CHAR_CIRCUMFLEX_i, CHAR_CIRCUMFLEX_I }, - { CHAR_DIARESIS_i, CHAR_DIARESIS_I }, - { CHAR_LOWER_ETH, CHAR_ETH }, - { CHAR_TILDE_n, CHAR_TILDE_N }, - { CHAR_GRAVE_o, CHAR_GRAVE_O }, - { CHAR_ACUTE_o, CHAR_ACUTE_O }, - { CHAR_CIRCUMFLEX_o, CHAR_CIRCUMFLEX_O }, - { CHAR_TILDE_o, CHAR_TILDE_O }, - { CHAR_DIARESIS_o, CHAR_DIARESIS_O }, - { CHAR_oe, CHAR_OE }, - { CHAR_GRAVE_u, CHAR_GRAVE_U }, - { CHAR_ACUTE_u, CHAR_ACUTE_U }, - { CHAR_CIRCUMFLEX_u, CHAR_CIRCUMFLEX_U }, - { CHAR_DIARESIS_u, CHAR_DIARESIS_U }, - { CHAR_ACUTE_y, CHAR_ACUTE_Y }, - { CHAR_LOWER_THORN, CHAR_THORN }, - { CHAR_LOWER_ASH, CHAR_ASH } - }; + static const u8 tbl[56][2] = { + { CHAR_a, CHAR_A }, + { CHAR_b, CHAR_B }, + { CHAR_c, CHAR_C }, + { CHAR_d, CHAR_D }, + { CHAR_e, CHAR_E }, + { CHAR_f, CHAR_F }, + { CHAR_g, CHAR_G }, + { CHAR_h, CHAR_H }, + { CHAR_i, CHAR_I }, + { CHAR_j, CHAR_J }, + { CHAR_k, CHAR_K }, + { CHAR_l, CHAR_L }, + { CHAR_m, CHAR_M }, + { CHAR_n, CHAR_N }, + { CHAR_o, CHAR_O }, + { CHAR_p, CHAR_P }, + { CHAR_q, CHAR_Q }, + { CHAR_r, CHAR_R }, + { CHAR_s, CHAR_S }, + { CHAR_t, CHAR_T }, + { CHAR_u, CHAR_U }, + { CHAR_v, CHAR_V }, + { CHAR_w, CHAR_W }, + { CHAR_x, CHAR_X }, + { CHAR_y, CHAR_Y }, + { CHAR_z, CHAR_Z }, + { CHAR_DIARESIS_a, CHAR_DIAERESIS_A }, + { CHAR_GRAVE_a, CHAR_GRAVE_A }, + { CHAR_ACUTE_a, CHAR_ACUTE_A }, + { CHAR_CIRCUMFLEX_a, CHAR_CIRCUMFLEX_A }, + { CHAR_TILDE_a, CHAR_TILDE_A }, + { CHAR_ANGSTROM_a, CHAR_ANGSTROM_A }, + { CHAR_LOWER_CEDILLA, CHAR_CEDILLA }, + { CHAR_GRAVE_e, CHAR_GRAVE_E }, + { CHAR_ACUTE_e, CHAR_ACUTE_E }, + { CHAR_CIRCUMFLEX_e, CHAR_CIRCUMFLEX_E }, + { CHAR_DIARESIS_e, CHAR_DIARESIS_E }, + { CHAR_GRAVE_i, CHAR_GRAVE_I }, + { CHAR_ACUTE_i, CHAR_ACUTE_I }, + { CHAR_CIRCUMFLEX_i, CHAR_CIRCUMFLEX_I }, + { CHAR_DIARESIS_i, CHAR_DIARESIS_I }, + { CHAR_LOWER_ETH, CHAR_ETH }, + { CHAR_TILDE_n, CHAR_TILDE_N }, + { CHAR_GRAVE_o, CHAR_GRAVE_O }, + { CHAR_ACUTE_o, CHAR_ACUTE_O }, + { CHAR_CIRCUMFLEX_o, CHAR_CIRCUMFLEX_O }, + { CHAR_TILDE_o, CHAR_TILDE_O }, + { CHAR_DIARESIS_o, CHAR_DIARESIS_O }, + { CHAR_oe, CHAR_OE }, + { CHAR_GRAVE_u, CHAR_GRAVE_U }, + { CHAR_ACUTE_u, CHAR_ACUTE_U }, + { CHAR_CIRCUMFLEX_u, CHAR_CIRCUMFLEX_U }, + { CHAR_DIARESIS_u, CHAR_DIARESIS_U }, + { CHAR_ACUTE_y, CHAR_ACUTE_Y }, + { CHAR_LOWER_THORN, CHAR_THORN }, + { CHAR_LOWER_ASH, CHAR_ASH }, + }; - u8 res = small; - u8* t = (u8*)tbl; - int i; + u8 res = small; + u8* t = (u8*)tbl; + int i; - for (i = 0; i < 56; i++) { - if (t[0] == small) { - res = t[1]; - break; + for (i = 0; i < 56; i++) { + if (t[0] == small) { + res = t[1]; + break; + } + + t += 2; } - t += 2; - } - - return res; + return res; } diff --git a/src/m_kankyo.c b/src/m_kankyo.c index 81e4da15..3eb8b0e0 100644 --- a/src/m_kankyo.c +++ b/src/m_kankyo.c @@ -6,14 +6,15 @@ #include "m_debug.h" #include "m_npc_schedule.h" #include "m_player_lib.h" +#include "libultra/libultra.h" #define mEnv_TIME_TO_SECS(hour, min, sec) ((hour) * mTM_SECONDS_IN_HOUR + (min) * mTM_SECONDS_IN_MINUTE + (sec)) -static int klight_chg_time[mEnv_TERM_NUM + 1] = { mEnv_TIME_TO_SECS(0, 0, 0), mEnv_TIME_TO_SECS(4, 0, 0), - mEnv_TIME_TO_SECS(6, 0, 0), mEnv_TIME_TO_SECS(8, 0, 0), - mEnv_TIME_TO_SECS(12, 0, 0), mEnv_TIME_TO_SECS(16, 0, 0), - mEnv_TIME_TO_SECS(18, 0, 0), mEnv_TIME_TO_SECS(20, 0, 0), - mEnv_TIME_TO_SECS(24, 0, 0) }; +static int klight_chg_time[mEnv_TERM_NUM + 1] = { + mEnv_TIME_TO_SECS(0, 0, 0), mEnv_TIME_TO_SECS(4, 0, 0), mEnv_TIME_TO_SECS(6, 0, 0), + mEnv_TIME_TO_SECS(8, 0, 0), mEnv_TIME_TO_SECS(12, 0, 0), mEnv_TIME_TO_SECS(16, 0, 0), + mEnv_TIME_TO_SECS(18, 0, 0), mEnv_TIME_TO_SECS(20, 0, 0), mEnv_TIME_TO_SECS(24, 0, 0), +}; static BaseLight l_mEnv_kcolor_fine_data[mEnv_TERM_NUM] = { /* 00:00 -> 03:59 */ diff --git a/src/m_mail_password_check.c b/src/m_mail_password_check.c index 954c4211..f52449dc 100644 --- a/src/m_mail_password_check.c +++ b/src/m_mail_password_check.c @@ -8,51 +8,33 @@ #include "m_shop.h" #include "_mem.h" #include "m_common_data.h" +#include "libultra/libultra.h" static u8 usable_to_fontnum[64] = { - CHAR_b, CHAR_K, CHAR_z, CHAR_FIVE, CHAR_c, CHAR_q, CHAR_Y, CHAR_Z, - CHAR_O, CHAR_d, CHAR_t, CHAR_SIX, CHAR_n, CHAR_l, CHAR_B, CHAR_y, - CHAR_o, CHAR_EIGHT, CHAR_FOUR, CHAR_L, CHAR_k, CHAR_PERCENT, CHAR_A, CHAR_Q, - CHAR_m, CHAR_D, CHAR_P, CHAR_I, CHAR_SEVEN, CHAR_AMPERSAND, CHAR_R, CHAR_s, - CHAR_w, CHAR_U, CHAR_HASHTAG, CHAR_r, CHAR_THREE, CHAR_E, CHAR_x, CHAR_M, - CHAR_C, CHAR_AT_SIGN, CHAR_e, CHAR_NINE, CHAR_g, CHAR_v, CHAR_V, CHAR_G, - CHAR_u, CHAR_N, CHAR_i, CHAR_X, CHAR_W, CHAR_f, CHAR_T, CHAR_J, - CHAR_F, CHAR_S, CHAR_H, CHAR_p, CHAR_TWO, CHAR_a, CHAR_j, CHAR_h + CHAR_b, CHAR_K, CHAR_z, CHAR_FIVE, CHAR_c, CHAR_q, CHAR_Y, CHAR_Z, CHAR_O, CHAR_d, + CHAR_t, CHAR_SIX, CHAR_n, CHAR_l, CHAR_B, CHAR_y, CHAR_o, CHAR_EIGHT, CHAR_FOUR, CHAR_L, + CHAR_k, CHAR_PERCENT, CHAR_A, CHAR_Q, CHAR_m, CHAR_D, CHAR_P, CHAR_I, CHAR_SEVEN, CHAR_AMPERSAND, + CHAR_R, CHAR_s, CHAR_w, CHAR_U, CHAR_HASHTAG, CHAR_r, CHAR_THREE, CHAR_E, CHAR_x, CHAR_M, + CHAR_C, CHAR_AT_SIGN, CHAR_e, CHAR_NINE, CHAR_g, CHAR_v, CHAR_V, CHAR_G, CHAR_u, CHAR_N, + CHAR_i, CHAR_X, CHAR_W, CHAR_f, CHAR_T, CHAR_J, CHAR_F, CHAR_S, CHAR_H, CHAR_p, + CHAR_TWO, CHAR_a, CHAR_j, CHAR_h, }; static int mMpswd_prime_number[256] = { - 17, 19, 23, 29, 31, 37, 41, 43, - 47, 53, 59, 61, 67, 71, 73, 79, - 83, 89, 97, 101, 103, 107, 109, 113, - 127, 131, 137, 139, 149, 151, 157, 163, - 167, 173, 179, 181, 191, 193, 197, 199, - 211, 223, 227, 229, 233, 239, 241, 251, - 257, 263, 269, 271, 277, 281, 283, 293, - 307, 311, 313, 317, 331, 337, 347, 349, - 353, 359, 367, 373, 379, 383, 389, 397, - 401, 409, 419, 421, 431, 433, 439, 443, - 449, 457, 461, 463, 467, 479, 487, 491, - 499, 503, 509, 521, 523, 541, 547, 557, - 563, 569, 571, 577, 587, 593, 599, 601, - 607, 613, 617, 619, 631, 641, 643, 647, - 653, 659, 661, 673, 677, 683, 691, 701, - 709, 719, 727, 733, 739, 743, 751, 757, - 761, 769, 773, 787, 797, 809, 811, 821, - 823, 827, 829, 839, 853, 857, 859, 863, - 877, 881, 883, 887, 907, 911, 919, 929, - 937, 941, 947, 953, 967, 971, 977, 983, - 991, 997, 1009, 1013, 1019, 1021, 1031, 1033, - 1039, 1049, 1051, 1061, 1063, 1069, 1087, 1091, - 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151, - 1153, 1163, 1171, 1181, 1187, 1193, 1201, 1213, - 1217, 1223, 1229, 1231, 1237, 1249, 1259, 1277, - 1279, 1283, 1289, 1291, 1297, 1301, 1303, 1307, - 1319, 1321, 1327, 1361, 1367, 1373, 1381, 1399, - 1409, 1423, 1427, 1429, 1433, 1439, 1447, 1451, - 1453, 1459, 1471, 1481, 1483, 1487, 1489, 1493, - 1499, 1511, 1523, 1531, 1543, 1549, 1553, 1559, - 1567, 1571, 1579, 1583, 1597, 1601, 1607, 1609, - 1613, 1619, 1621, 1627, 1637, 1657, 1663, 1667 + 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, + 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, + 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, + 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, + 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, + 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, + 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, + 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, + 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, + 1061, 1063, 1069, 1087, 1091, 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151, 1153, 1163, 1171, 1181, 1187, 1193, + 1201, 1213, 1217, 1223, 1229, 1231, 1237, 1249, 1259, 1277, 1279, 1283, 1289, 1291, 1297, 1301, 1303, 1307, 1319, + 1321, 1327, 1361, 1367, 1373, 1381, 1399, 1409, 1423, 1427, 1429, 1433, 1439, 1447, 1451, 1453, 1459, 1471, 1481, + 1483, 1487, 1489, 1493, 1499, 1511, 1523, 1531, 1543, 1549, 1553, 1559, 1567, 1571, 1579, 1583, 1597, 1601, 1607, + 1609, 1613, 1619, 1621, 1627, 1637, 1657, 1663, 1667, }; static u8 mMpswd_transposition_cipher_char0_0[9] = "NiiMasaru"; @@ -90,670 +72,634 @@ static u8 mMpswd_transposition_cipher_char1_14[11] = "YossyIsland"; static u8 mMpswd_transposition_cipher_char1_15[14] = "KedamonoNoMori"; typedef struct { - u8* str; - int len; + u8* str; + int len; } mMpswd_transposition_cipher_str_c; static mMpswd_transposition_cipher_str_c mMpswd_transposition_cipher_char0_table[16] = { - { mMpswd_transposition_cipher_char0_0, sizeof(mMpswd_transposition_cipher_char0_0) }, - { mMpswd_transposition_cipher_char0_1, sizeof(mMpswd_transposition_cipher_char0_1) }, - { mMpswd_transposition_cipher_char0_2, sizeof(mMpswd_transposition_cipher_char0_2) }, - { mMpswd_transposition_cipher_char0_3, sizeof(mMpswd_transposition_cipher_char0_3) }, - { mMpswd_transposition_cipher_char0_4, sizeof(mMpswd_transposition_cipher_char0_4) }, - { mMpswd_transposition_cipher_char0_5, sizeof(mMpswd_transposition_cipher_char0_5) }, - { mMpswd_transposition_cipher_char0_6, sizeof(mMpswd_transposition_cipher_char0_6) }, - { mMpswd_transposition_cipher_char0_7, sizeof(mMpswd_transposition_cipher_char0_7) }, - { mMpswd_transposition_cipher_char0_8, sizeof(mMpswd_transposition_cipher_char0_8) }, - { mMpswd_transposition_cipher_char0_9, sizeof(mMpswd_transposition_cipher_char0_9) }, - { mMpswd_transposition_cipher_char0_10, sizeof(mMpswd_transposition_cipher_char0_10) }, - { mMpswd_transposition_cipher_char0_11, sizeof(mMpswd_transposition_cipher_char0_11) }, - { mMpswd_transposition_cipher_char0_12, sizeof(mMpswd_transposition_cipher_char0_12) }, - { mMpswd_transposition_cipher_char0_13, sizeof(mMpswd_transposition_cipher_char0_13) }, - { mMpswd_transposition_cipher_char0_14, sizeof(mMpswd_transposition_cipher_char0_14) }, - { mMpswd_transposition_cipher_char0_15, sizeof(mMpswd_transposition_cipher_char0_15) } + { mMpswd_transposition_cipher_char0_0, sizeof(mMpswd_transposition_cipher_char0_0) }, + { mMpswd_transposition_cipher_char0_1, sizeof(mMpswd_transposition_cipher_char0_1) }, + { mMpswd_transposition_cipher_char0_2, sizeof(mMpswd_transposition_cipher_char0_2) }, + { mMpswd_transposition_cipher_char0_3, sizeof(mMpswd_transposition_cipher_char0_3) }, + { mMpswd_transposition_cipher_char0_4, sizeof(mMpswd_transposition_cipher_char0_4) }, + { mMpswd_transposition_cipher_char0_5, sizeof(mMpswd_transposition_cipher_char0_5) }, + { mMpswd_transposition_cipher_char0_6, sizeof(mMpswd_transposition_cipher_char0_6) }, + { mMpswd_transposition_cipher_char0_7, sizeof(mMpswd_transposition_cipher_char0_7) }, + { mMpswd_transposition_cipher_char0_8, sizeof(mMpswd_transposition_cipher_char0_8) }, + { mMpswd_transposition_cipher_char0_9, sizeof(mMpswd_transposition_cipher_char0_9) }, + { mMpswd_transposition_cipher_char0_10, sizeof(mMpswd_transposition_cipher_char0_10) }, + { mMpswd_transposition_cipher_char0_11, sizeof(mMpswd_transposition_cipher_char0_11) }, + { mMpswd_transposition_cipher_char0_12, sizeof(mMpswd_transposition_cipher_char0_12) }, + { mMpswd_transposition_cipher_char0_13, sizeof(mMpswd_transposition_cipher_char0_13) }, + { mMpswd_transposition_cipher_char0_14, sizeof(mMpswd_transposition_cipher_char0_14) }, + { mMpswd_transposition_cipher_char0_15, sizeof(mMpswd_transposition_cipher_char0_15) } }; static mMpswd_transposition_cipher_str_c mMpswd_transposition_cipher_char1_table[16] = { - { mMpswd_transposition_cipher_char1_0, sizeof(mMpswd_transposition_cipher_char1_0) }, - { mMpswd_transposition_cipher_char1_1, sizeof(mMpswd_transposition_cipher_char1_1) }, - { mMpswd_transposition_cipher_char1_2, sizeof(mMpswd_transposition_cipher_char1_2) }, - { mMpswd_transposition_cipher_char1_3, sizeof(mMpswd_transposition_cipher_char1_3) }, - { mMpswd_transposition_cipher_char1_4, sizeof(mMpswd_transposition_cipher_char1_4) }, - { mMpswd_transposition_cipher_char1_5, sizeof(mMpswd_transposition_cipher_char1_5) }, - { mMpswd_transposition_cipher_char1_6, sizeof(mMpswd_transposition_cipher_char1_6) }, - { mMpswd_transposition_cipher_char1_7, sizeof(mMpswd_transposition_cipher_char1_7) }, - { mMpswd_transposition_cipher_char1_8, sizeof(mMpswd_transposition_cipher_char1_8) }, - { mMpswd_transposition_cipher_char1_9, sizeof(mMpswd_transposition_cipher_char1_9) }, - { mMpswd_transposition_cipher_char1_10, sizeof(mMpswd_transposition_cipher_char1_10) }, - { mMpswd_transposition_cipher_char1_11, sizeof(mMpswd_transposition_cipher_char1_11) }, - { mMpswd_transposition_cipher_char1_12, sizeof(mMpswd_transposition_cipher_char1_12) }, - { mMpswd_transposition_cipher_char1_13, sizeof(mMpswd_transposition_cipher_char1_13) }, - { mMpswd_transposition_cipher_char1_14, sizeof(mMpswd_transposition_cipher_char1_14) }, - { mMpswd_transposition_cipher_char1_15, sizeof(mMpswd_transposition_cipher_char1_15) } + { mMpswd_transposition_cipher_char1_0, sizeof(mMpswd_transposition_cipher_char1_0) }, + { mMpswd_transposition_cipher_char1_1, sizeof(mMpswd_transposition_cipher_char1_1) }, + { mMpswd_transposition_cipher_char1_2, sizeof(mMpswd_transposition_cipher_char1_2) }, + { mMpswd_transposition_cipher_char1_3, sizeof(mMpswd_transposition_cipher_char1_3) }, + { mMpswd_transposition_cipher_char1_4, sizeof(mMpswd_transposition_cipher_char1_4) }, + { mMpswd_transposition_cipher_char1_5, sizeof(mMpswd_transposition_cipher_char1_5) }, + { mMpswd_transposition_cipher_char1_6, sizeof(mMpswd_transposition_cipher_char1_6) }, + { mMpswd_transposition_cipher_char1_7, sizeof(mMpswd_transposition_cipher_char1_7) }, + { mMpswd_transposition_cipher_char1_8, sizeof(mMpswd_transposition_cipher_char1_8) }, + { mMpswd_transposition_cipher_char1_9, sizeof(mMpswd_transposition_cipher_char1_9) }, + { mMpswd_transposition_cipher_char1_10, sizeof(mMpswd_transposition_cipher_char1_10) }, + { mMpswd_transposition_cipher_char1_11, sizeof(mMpswd_transposition_cipher_char1_11) }, + { mMpswd_transposition_cipher_char1_12, sizeof(mMpswd_transposition_cipher_char1_12) }, + { mMpswd_transposition_cipher_char1_13, sizeof(mMpswd_transposition_cipher_char1_13) }, + { mMpswd_transposition_cipher_char1_14, sizeof(mMpswd_transposition_cipher_char1_14) }, + { mMpswd_transposition_cipher_char1_15, sizeof(mMpswd_transposition_cipher_char1_15) } }; static mMpswd_transposition_cipher_str_c* mMpswd_transposition_cipher_char_table[2] = { - mMpswd_transposition_cipher_char0_table, mMpswd_transposition_cipher_char1_table + mMpswd_transposition_cipher_char0_table, mMpswd_transposition_cipher_char1_table }; static u8 mMpswd_chg_code_table[256] = { - 0xf0, 0x83, 0xfd, 0x62, 0x93, 0x49, 0x0d, 0x3e, 0xe1, 0xa4, 0x2b, 0xaf, 0x3a, 0x25, 0xd0, 0x82, - 0x7f, 0x97, 0xd2, 0x03, 0xb2, 0x32, 0xb4, 0xe6, 0x09, 0x42, 0x57, 0x27, 0x60, 0xea, 0x76, 0xab, - 0x2d, 0x65, 0xa8, 0x4d, 0x8b, 0x95, 0x01, 0x37, 0x59, 0x79, 0x33, 0xac, 0x2f, 0xae, 0x9f, 0xfe, - 0x56, 0xd9, 0x04, 0xc6, 0xb9, 0x28, 0x06, 0x5c, 0x54, 0x8d, 0xe5, 0x00, 0xb3, 0x7b, 0x5e, 0xa7, - 0x3c, 0x78, 0xcb, 0x2e, 0x6d, 0xe4, 0xe8, 0xdc, 0x40, 0xa0, 0xde, 0x2c, 0xf5, 0x1f, 0xcc, 0x85, - 0x71, 0x3d, 0x26, 0x74, 0x9c, 0x13, 0x7d, 0x7e, 0x66, 0xf2, 0x9e, 0x02, 0xa1, 0x53, 0x15, 0x4f, - 0x51, 0x20, 0xd5, 0x39, 0x1a, 0x67, 0x99, 0x41, 0xc7, 0xc3, 0xa6, 0xc4, 0xbc, 0x38, 0x8c, 0xaa, - 0x81, 0x12, 0xdd, 0x17, 0xb7, 0xef, 0x2a, 0x80, 0x9d, 0x50, 0xdf, 0xcf, 0x89, 0xc8, 0x91, 0x1b, - 0xbb, 0x73, 0xf8, 0x14, 0x61, 0xc2, 0x45, 0xc5, 0x55, 0xfc, 0x8e, 0xe9, 0x8a, 0x46, 0xdb, 0x4e, - 0x05, 0xc1, 0x64, 0xd1, 0xe0, 0x70, 0x16, 0xf9, 0xb6, 0x36, 0x44, 0x8f, 0x0c, 0x29, 0xd3, 0x0e, - 0x6f, 0x7c, 0xd7, 0x4a, 0xff, 0x75, 0x6c, 0x11, 0x10, 0x77, 0x3b, 0x98, 0xba, 0x69, 0x5b, 0xa3, - 0x6a, 0x72, 0x94, 0xd6, 0xd4, 0x22, 0x08, 0x86, 0x31, 0x47, 0xbe, 0x87, 0x63, 0x34, 0x52, 0x3f, - 0x68, 0xf6, 0x0f, 0xbf, 0xeb, 0xc0, 0xce, 0x24, 0xa5, 0x9a, 0x90, 0xed, 0x19, 0xb8, 0xb5, 0x96, - 0xfa, 0x88, 0x6e, 0xfb, 0x84, 0x23, 0x5d, 0xcd, 0xee, 0x92, 0x58, 0x4c, 0x0b, 0xf7, 0x0a, 0xb1, - 0xda, 0x35, 0x5f, 0x9b, 0xc9, 0xa9, 0xe7, 0x07, 0x1d, 0x18, 0xf3, 0xe3, 0xf1, 0xf4, 0xca, 0xb0, - 0x6b, 0x30, 0xec, 0x4b, 0x48, 0x1c, 0xad, 0xe2, 0x21, 0x1e, 0xa2, 0xbd, 0x5a, 0xd8, 0x43, 0x7a + 0xf0, 0x83, 0xfd, 0x62, 0x93, 0x49, 0x0d, 0x3e, 0xe1, 0xa4, 0x2b, 0xaf, 0x3a, 0x25, 0xd0, 0x82, 0x7f, 0x97, 0xd2, + 0x03, 0xb2, 0x32, 0xb4, 0xe6, 0x09, 0x42, 0x57, 0x27, 0x60, 0xea, 0x76, 0xab, 0x2d, 0x65, 0xa8, 0x4d, 0x8b, 0x95, + 0x01, 0x37, 0x59, 0x79, 0x33, 0xac, 0x2f, 0xae, 0x9f, 0xfe, 0x56, 0xd9, 0x04, 0xc6, 0xb9, 0x28, 0x06, 0x5c, 0x54, + 0x8d, 0xe5, 0x00, 0xb3, 0x7b, 0x5e, 0xa7, 0x3c, 0x78, 0xcb, 0x2e, 0x6d, 0xe4, 0xe8, 0xdc, 0x40, 0xa0, 0xde, 0x2c, + 0xf5, 0x1f, 0xcc, 0x85, 0x71, 0x3d, 0x26, 0x74, 0x9c, 0x13, 0x7d, 0x7e, 0x66, 0xf2, 0x9e, 0x02, 0xa1, 0x53, 0x15, + 0x4f, 0x51, 0x20, 0xd5, 0x39, 0x1a, 0x67, 0x99, 0x41, 0xc7, 0xc3, 0xa6, 0xc4, 0xbc, 0x38, 0x8c, 0xaa, 0x81, 0x12, + 0xdd, 0x17, 0xb7, 0xef, 0x2a, 0x80, 0x9d, 0x50, 0xdf, 0xcf, 0x89, 0xc8, 0x91, 0x1b, 0xbb, 0x73, 0xf8, 0x14, 0x61, + 0xc2, 0x45, 0xc5, 0x55, 0xfc, 0x8e, 0xe9, 0x8a, 0x46, 0xdb, 0x4e, 0x05, 0xc1, 0x64, 0xd1, 0xe0, 0x70, 0x16, 0xf9, + 0xb6, 0x36, 0x44, 0x8f, 0x0c, 0x29, 0xd3, 0x0e, 0x6f, 0x7c, 0xd7, 0x4a, 0xff, 0x75, 0x6c, 0x11, 0x10, 0x77, 0x3b, + 0x98, 0xba, 0x69, 0x5b, 0xa3, 0x6a, 0x72, 0x94, 0xd6, 0xd4, 0x22, 0x08, 0x86, 0x31, 0x47, 0xbe, 0x87, 0x63, 0x34, + 0x52, 0x3f, 0x68, 0xf6, 0x0f, 0xbf, 0xeb, 0xc0, 0xce, 0x24, 0xa5, 0x9a, 0x90, 0xed, 0x19, 0xb8, 0xb5, 0x96, 0xfa, + 0x88, 0x6e, 0xfb, 0x84, 0x23, 0x5d, 0xcd, 0xee, 0x92, 0x58, 0x4c, 0x0b, 0xf7, 0x0a, 0xb1, 0xda, 0x35, 0x5f, 0x9b, + 0xc9, 0xa9, 0xe7, 0x07, 0x1d, 0x18, 0xf3, 0xe3, 0xf1, 0xf4, 0xca, 0xb0, 0x6b, 0x30, 0xec, 0x4b, 0x48, 0x1c, 0xad, + 0xe2, 0x21, 0x1e, 0xa2, 0xbd, 0x5a, 0xd8, 0x43, 0x7a, }; -static int mMpswd_select_idx0[8] = {17, 11, 0, 10, 12, 6, 8, 4}; -static int mMpswd_select_idx1[8] = {3, 8, 11, 16, 4, 6, 9, 19}; -static int mMpswd_select_idx2[8] = {9, 14, 17, 18, 11, 10, 12, 2}; -static int mMpswd_select_idx3[8] = {0, 2, 1, 4, 18, 10, 12, 8}; -static int mMpswd_select_idx4[8] = {17, 19, 16, 7, 12, 8, 2, 9}; -static int mMpswd_select_idx5[8] = {16, 3, 1, 8, 18, 4, 7, 6}; -static int mMpswd_select_idx6[8] = {19, 6, 10, 17, 3, 16, 8, 9}; -static int mMpswd_select_idx7[8] = {17, 7, 18, 16, 12, 2, 11, 0}; -static int mMpswd_select_idx8[8] = {6, 2, 12, 1, 8, 14, 0, 16}; -static int mMpswd_select_idx9[8] = {19, 16, 11, 8, 17, 3, 6, 14}; -static int mMpswd_select_idx10[8] = {18, 12, 2, 7, 10, 11, 1, 14}; -static int mMpswd_select_idx11[8] = {8, 0, 14, 2, 7, 11, 12, 17}; -static int mMpswd_select_idx12[8] = {9, 3, 2, 0, 11, 8, 14, 10}; -static int mMpswd_select_idx13[8] = {10, 11, 12, 16, 19, 7, 17, 8}; -static int mMpswd_select_idx14[8] = {19, 8, 6, 1, 17, 9, 14, 10}; -static int mMpswd_select_idx15[8] = {9, 7, 17, 12, 19, 10, 1, 11}; +static int mMpswd_select_idx0[8] = { 17, 11, 0, 10, 12, 6, 8, 4 }; +static int mMpswd_select_idx1[8] = { 3, 8, 11, 16, 4, 6, 9, 19 }; +static int mMpswd_select_idx2[8] = { 9, 14, 17, 18, 11, 10, 12, 2 }; +static int mMpswd_select_idx3[8] = { 0, 2, 1, 4, 18, 10, 12, 8 }; +static int mMpswd_select_idx4[8] = { 17, 19, 16, 7, 12, 8, 2, 9 }; +static int mMpswd_select_idx5[8] = { 16, 3, 1, 8, 18, 4, 7, 6 }; +static int mMpswd_select_idx6[8] = { 19, 6, 10, 17, 3, 16, 8, 9 }; +static int mMpswd_select_idx7[8] = { 17, 7, 18, 16, 12, 2, 11, 0 }; +static int mMpswd_select_idx8[8] = { 6, 2, 12, 1, 8, 14, 0, 16 }; +static int mMpswd_select_idx9[8] = { 19, 16, 11, 8, 17, 3, 6, 14 }; +static int mMpswd_select_idx10[8] = { 18, 12, 2, 7, 10, 11, 1, 14 }; +static int mMpswd_select_idx11[8] = { 8, 0, 14, 2, 7, 11, 12, 17 }; +static int mMpswd_select_idx12[8] = { 9, 3, 2, 0, 11, 8, 14, 10 }; +static int mMpswd_select_idx13[8] = { 10, 11, 12, 16, 19, 7, 17, 8 }; +static int mMpswd_select_idx14[8] = { 19, 8, 6, 1, 17, 9, 14, 10 }; +static int mMpswd_select_idx15[8] = { 9, 7, 17, 12, 19, 10, 1, 11 }; static int* mMpswd_select_idx_table[16] = { - mMpswd_select_idx0, - mMpswd_select_idx1, - mMpswd_select_idx2, - mMpswd_select_idx3, - mMpswd_select_idx4, - mMpswd_select_idx5, - mMpswd_select_idx6, - mMpswd_select_idx7, - mMpswd_select_idx8, - mMpswd_select_idx9, - mMpswd_select_idx10, - mMpswd_select_idx11, - mMpswd_select_idx12, - mMpswd_select_idx13, - mMpswd_select_idx14, - mMpswd_select_idx15 + mMpswd_select_idx0, mMpswd_select_idx1, mMpswd_select_idx2, mMpswd_select_idx3, + mMpswd_select_idx4, mMpswd_select_idx5, mMpswd_select_idx6, mMpswd_select_idx7, + mMpswd_select_idx8, mMpswd_select_idx9, mMpswd_select_idx10, mMpswd_select_idx11, + mMpswd_select_idx12, mMpswd_select_idx13, mMpswd_select_idx14, mMpswd_select_idx15, }; static void mMpswd_bit_shift(u8* pswd, int shift) { - u8 buf[mMpswd_PASSWORD_DATA_LEN-1]; - u8 shifted_buf[mMpswd_PASSWORD_DATA_LEN-1]; - int bytes_shifted; - int bits_shifted; + u8 buf[mMpswd_PASSWORD_DATA_LEN - 1]; + u8 shifted_buf[mMpswd_PASSWORD_DATA_LEN - 1]; + int bytes_shifted; + int bits_shifted; - /* copy password data into work buffer while skipping key index byte */ - memcpy(buf, pswd, 1); - memcpy(buf + 1, pswd + 2, (mMpswd_PASSWORD_DATA_LEN - 2)); + /* copy password data into work buffer while skipping key index byte */ + memcpy(buf, pswd, 1); + memcpy(buf + 1, pswd + 2, (mMpswd_PASSWORD_DATA_LEN - 2)); - // this has to be a fakematch - bytes_shifted = __abs(shift); - bytes_shifted /= 8; // degenerate code - bits_shifted = ABS(shift) % 8; + // this has to be a fakematch + bytes_shifted = __abs(shift); + bytes_shifted /= 8; // degenerate code + bits_shifted = ABS(shift) % 8; - while (bytes_shifted > mMpswd_PASSWORD_DATA_LEN - 1) { - bytes_shifted -= (mMpswd_PASSWORD_DATA_LEN - 1); - } - - if (shift > 0) { - /* positive shift */ - int dst; - int byte; - int shift_mask = 0; - int i; - for (i = 0; i < bits_shifted; i++) { - shift_mask = shift_mask * 2 + 1; + while (bytes_shifted > mMpswd_PASSWORD_DATA_LEN - 1) { + bytes_shifted -= (mMpswd_PASSWORD_DATA_LEN - 1); } - byte = (buf[bits_shifted == 0 ? 0 : mMpswd_PASSWORD_DATA_LEN-2] >> (8 - bits_shifted)) & shift_mask; - dst = bytes_shifted; - for (i = 0; i < mMpswd_PASSWORD_DATA_LEN-1; i++) { - u8 now_byte = buf[i]; + if (shift > 0) { + /* positive shift */ + int dst; + int byte; + int shift_mask = 0; + int i; + for (i = 0; i < bits_shifted; i++) { + shift_mask = shift_mask * 2 + 1; + } - shifted_buf[dst] = byte | (now_byte << bits_shifted); - byte = (now_byte >> (8 - bits_shifted)) & shift_mask; - dst = (dst + 1) % (mMpswd_PASSWORD_DATA_LEN-1); - } - } - else if (shift < 0) { - /* negative shift */ - int shift_idx; - int shift; - int shift_mask = 0; - int byte; - int i; - - for (i = 0; i < bits_shifted; i++) { - shift_mask = shift_mask * 2 + 1; + byte = (buf[bits_shifted == 0 ? 0 : mMpswd_PASSWORD_DATA_LEN - 2] >> (8 - bits_shifted)) & shift_mask; + dst = bytes_shifted; + for (i = 0; i < mMpswd_PASSWORD_DATA_LEN - 1; i++) { + u8 now_byte = buf[i]; + + shifted_buf[dst] = byte | (now_byte << bits_shifted); + byte = (now_byte >> (8 - bits_shifted)) & shift_mask; + dst = (dst + 1) % (mMpswd_PASSWORD_DATA_LEN - 1); + } + } else if (shift < 0) { + /* negative shift */ + int shift_idx; + int shift; + int shift_mask = 0; + int byte; + int i; + + for (i = 0; i < bits_shifted; i++) { + shift_mask = shift_mask * 2 + 1; + } + + // fakematch? + byte = 0; + byte += (buf[bits_shifted == 0 ? mMpswd_PASSWORD_DATA_LEN - 2 : 0]); // start byte + + shift = 8 - bits_shifted; // invert shift + shift_idx = (mMpswd_PASSWORD_DATA_LEN - 2 - bytes_shifted) % (mMpswd_PASSWORD_DATA_LEN - 1); // dst index + byte &= shift_mask; + byte <<= shift; // move bits into position + + for (i = mMpswd_PASSWORD_DATA_LEN - 2; i >= 0; i--) { + int now_byte = buf[i]; + + shifted_buf[shift_idx] = byte | (now_byte >> bits_shifted); // save shifted byte + byte = (now_byte & shift_mask) << shift; // update initial bits + + shift_idx--; + if (shift_idx < 0) { + shift_idx = mMpswd_PASSWORD_DATA_LEN - 2; + } + } + } else { + /* no shift (shift == 0) */ + memcpy(shifted_buf, buf, mMpswd_PASSWORD_DATA_LEN - 1); } - // fakematch? - byte = 0; - byte += (buf[bits_shifted == 0 ? mMpswd_PASSWORD_DATA_LEN-2 : 0]) ; // start byte - - shift = 8 - bits_shifted; // invert shift - shift_idx = (mMpswd_PASSWORD_DATA_LEN-2 - bytes_shifted) % (mMpswd_PASSWORD_DATA_LEN-1); // dst index - byte &= shift_mask; - byte <<= shift ; // move bits into position - - for (i = mMpswd_PASSWORD_DATA_LEN-2; i >= 0 ; i--) { - int now_byte = buf[i]; - - shifted_buf[shift_idx] = byte | (now_byte >> bits_shifted); // save shifted byte - byte = (now_byte & shift_mask) << shift; // update initial bits - - shift_idx--; - if (shift_idx < 0) { - shift_idx = mMpswd_PASSWORD_DATA_LEN-2; - } - } - } - else { - /* no shift (shift == 0) */ - memcpy(shifted_buf, buf, mMpswd_PASSWORD_DATA_LEN-1); - } - - /* copy shifted buffer back into main password buffer */ - memcpy(pswd, shifted_buf, 1); - memcpy(pswd + 2, shifted_buf + 1, mMpswd_PASSWORD_DATA_LEN-2); + /* copy shifted buffer back into main password buffer */ + memcpy(pswd, shifted_buf, 1); + memcpy(pswd + 2, shifted_buf + 1, mMpswd_PASSWORD_DATA_LEN - 2); } static void mMpswd_bit_reverse(u8* pswd) { - int i; + int i; - for (i = 0; i < mMpswd_PASSWORD_DATA_LEN; i++) { - if (i != mMpswd_PASSWORD_KEY_IDX) { - pswd[i] ^= 0xFF; + for (i = 0; i < mMpswd_PASSWORD_DATA_LEN; i++) { + if (i != mMpswd_PASSWORD_KEY_IDX) { + pswd[i] ^= 0xFF; + } } - } } static void mMpswd_bit_arrange_reverse(u8* pswd) { - u8 buf[mMpswd_PASSWORD_DATA_LEN-1]; - u8 reversed_buf[mMpswd_PASSWORD_DATA_LEN-1]; - u8 reversed; - int i; - int j; - int b; + u8 buf[mMpswd_PASSWORD_DATA_LEN - 1]; + u8 reversed_buf[mMpswd_PASSWORD_DATA_LEN - 1]; + u8 reversed; + int i; + int j; + int b; - /* copy password data into work buffer while skipping key index byte */ - memcpy(buf, pswd, 1); - memcpy(buf + 1, pswd + 2, (mMpswd_PASSWORD_DATA_LEN - 2)); + /* copy password data into work buffer while skipping key index byte */ + memcpy(buf, pswd, 1); + memcpy(buf + 1, pswd + 2, (mMpswd_PASSWORD_DATA_LEN - 2)); - for (i = mMpswd_PASSWORD_DATA_LEN-2, j = 0; i >= 0; i--) { - - reversed = 0; + for (i = mMpswd_PASSWORD_DATA_LEN - 2, j = 0; i >= 0; i--) { - for (b = 7; b >= 0; b--) { - reversed |= ((buf[i] >> b) & 1) << (7 - b); + reversed = 0; + + for (b = 7; b >= 0; b--) { + reversed |= ((buf[i] >> b) & 1) << (7 - b); + } + + reversed_buf[j] = reversed; + j++; } - - reversed_buf[j] = reversed; - j++; - } - memcpy(pswd, reversed_buf, 1); - memcpy(pswd + 2, reversed_buf + 1, mMpswd_PASSWORD_DATA_LEN-2); + memcpy(pswd, reversed_buf, 1); + memcpy(pswd + 2, reversed_buf + 1, mMpswd_PASSWORD_DATA_LEN - 2); } static int mMpswd_check_opening_sentence(const u8* sentence) { - int res = TRUE; - if (sentence[0] != CHAR_SYMBOL_KEY) { - res = FALSE; - } + int res = TRUE; + if (sentence[0] != CHAR_SYMBOL_KEY) { + res = FALSE; + } - return res; + return res; } static u8* mMpswd_get_password_pointer(u8* sentence) { - int i; - u8* ptr = NULL; + int i; + u8* ptr = NULL; - for (i = 0; i < 32; i++) { - if (sentence[0] == CHAR_NEW_LINE) { - if (sentence[15] == CHAR_NEW_LINE) { - ptr = sentence + 1; - } + for (i = 0; i < 32; i++) { + if (sentence[0] == CHAR_NEW_LINE) { + if (sentence[15] == CHAR_NEW_LINE) { + ptr = sentence + 1; + } - break; + break; + } + + sentence++; } - sentence++; - } - - return ptr; + return ptr; } static void mMpswd_except_return_code(u8* dst, u8* src) { - int i; + int i; - for (i = 0; i < 29; i++, src++) { - // src[14] is always going to be the newline character - if (i != 14) { - dst[0] = src[0]; - dst++; + for (i = 0; i < 29; i++, src++) { + // src[14] is always going to be the newline character + if (i != 14) { + dst[0] = src[0]; + dst++; + } } - } } static void mMpswd_adjust_letter(u8* pswd_str) { - int i; - - for (i = 0; i < mMpswd_PASSWORD_STR_LEN; i++) { - switch (pswd_str[i]) { - case CHAR_ZERO: - { - pswd_str[i] = CHAR_O; // 0 -> O - break; - } - - case CHAR_ONE: - { - pswd_str[i] = CHAR_l; // 1 -> l - break; - } - } - } -} - -static void mMpswd_make_passcode( - u8* passcode, - int type, - int hit_rate, - u8* str0, - u8* str1, - mActor_name_t item, - int npc_type, - int npc_code -) { - int checksum; - - switch (type) { - case mMpswd_CODETYPE_FAMICOM: - case mMpswd_CODETYPE_USER: - case mMpswd_CODETYPE_CARD_E_MINI: - { - hit_rate = 1; - npc_code = 0xFF; - break; - } - - case mMpswd_CODETYPE_POPULAR: - { - hit_rate = 4; // potential bug? when code is set to popularity contest, hitrate interferes with checksum bits - break; - } - - case mMpswd_CODETYPE_CARD_E: - { - break; - } - - case mMpswd_CODETYPE_MAGAZINE: - { - npc_type = (hit_rate >> 2) & 1; - hit_rate &= 3; - npc_code = 0xFF; - break; - } - - default: - { - type = mMpswd_CODETYPE_USER; - break; - } - } - - passcode[0] = type << 5; - passcode[0] |= hit_rate << 1; - passcode[0] |= npc_type & 1; - passcode[1] = npc_code; - - memcpy(passcode + 2, str0, PLAYER_NAME_LEN); - memcpy(passcode + 10, str1, PLAYER_NAME_LEN); - - checksum = 0; - passcode[18] = (item >> 8); - passcode[19] = item; - - { int i; - for (i = 0; i < PLAYER_NAME_LEN; i++) { - checksum += str0[i]; + for (i = 0; i < mMpswd_PASSWORD_STR_LEN; i++) { + switch (pswd_str[i]) { + case CHAR_ZERO: { + pswd_str[i] = CHAR_O; // 0 -> O + break; + } + + case CHAR_ONE: { + pswd_str[i] = CHAR_l; // 1 -> l + break; + } + } + } +} + +static void mMpswd_make_passcode(u8* passcode, int type, int hit_rate, u8* str0, u8* str1, mActor_name_t item, + int npc_type, int npc_code) { + int checksum; + + switch (type) { + case mMpswd_CODETYPE_FAMICOM: + case mMpswd_CODETYPE_USER: + case mMpswd_CODETYPE_CARD_E_MINI: { + hit_rate = 1; + npc_code = 0xFF; + break; + } + + case mMpswd_CODETYPE_POPULAR: { + hit_rate = + 4; // potential bug? when code is set to popularity contest, hitrate interferes with checksum bits + break; + } + + case mMpswd_CODETYPE_CARD_E: { + break; + } + + case mMpswd_CODETYPE_MAGAZINE: { + npc_type = (hit_rate >> 2) & 1; + hit_rate &= 3; + npc_code = 0xFF; + break; + } + + default: { + type = mMpswd_CODETYPE_USER; + break; + } } - for (i = 0; i < PLAYER_NAME_LEN; i++) { - checksum += str1[i]; - } - } + passcode[0] = type << 5; + passcode[0] |= hit_rate << 1; + passcode[0] |= npc_type & 1; + passcode[1] = npc_code; - checksum += item; - checksum += npc_code; - passcode[0] |= (checksum & 3) << 3; + memcpy(passcode + 2, str0, PLAYER_NAME_LEN); + memcpy(passcode + 10, str1, PLAYER_NAME_LEN); + + checksum = 0; + passcode[18] = (item >> 8); + passcode[19] = item; + + { + int i; + + for (i = 0; i < PLAYER_NAME_LEN; i++) { + checksum += str0[i]; + } + + for (i = 0; i < PLAYER_NAME_LEN; i++) { + checksum += str1[i]; + } + } + + checksum += item; + checksum += npc_code; + passcode[0] |= (checksum & 3) << 3; } static void mMpswd_chg_6bits_code(u8* sixbits, u8* eightbits) { - u8 six_byte; - int six_idx; - int eight_bit; - int six_bit; + u8 six_byte; + int six_idx; + int eight_bit; + int six_bit; - six_idx = 0; - eight_bit = 0; - six_bit = 0; - six_byte = 0; + six_idx = 0; + eight_bit = 0; + six_bit = 0; + six_byte = 0; - do { - u8 bit = ((eightbits[0] >> eight_bit) & 1) << six_bit; - eight_bit++; - six_bit++; - six_byte |= bit; + do { + u8 bit = ((eightbits[0] >> eight_bit) & 1) << six_bit; + eight_bit++; + six_bit++; + six_byte |= bit; - if (six_bit >= 6) { - six_idx++; - sixbits[0] = six_byte; - six_bit = 0; - sixbits++; + if (six_bit >= 6) { + six_idx++; + sixbits[0] = six_byte; + six_bit = 0; + sixbits++; - if (six_idx >= mMpswd_PASSWORD_STR_LEN) { - return; - } + if (six_idx >= mMpswd_PASSWORD_STR_LEN) { + return; + } - six_byte = 0; - } + six_byte = 0; + } - if (eight_bit >= 8) { - eight_bit = 0; - eightbits++; - } - } while (TRUE); + if (eight_bit >= 8) { + eight_bit = 0; + eightbits++; + } + } while (TRUE); } static void mMpswd_chg_8bits_code(u8* eightbits, u8* sixbits) { - u8 eight_byte; - int eight_idx; - int six_bit; - int eight_bit; + u8 eight_byte; + int eight_idx; + int six_bit; + int eight_bit; - eight_idx = 0; - six_bit = 0; - eight_bit = 0; - eight_byte = 0; + eight_idx = 0; + six_bit = 0; + eight_bit = 0; + eight_byte = 0; - do { - u8 bit = ((sixbits[0] >> six_bit) & 1) << eight_bit; - six_bit++; - eight_bit++; - eight_byte |= bit; + do { + u8 bit = ((sixbits[0] >> six_bit) & 1) << eight_bit; + six_bit++; + eight_bit++; + eight_byte |= bit; - if (eight_bit >= 8) { - eight_idx++; - eightbits[0] = eight_byte; - eight_bit = 0; - eightbits++; + if (eight_bit >= 8) { + eight_idx++; + eightbits[0] = eight_byte; + eight_bit = 0; + eightbits++; - if (eight_idx >= mMpswd_PASSWORD_DATA_LEN) { - return; - } + if (eight_idx >= mMpswd_PASSWORD_DATA_LEN) { + return; + } - eight_byte = 0; - } + eight_byte = 0; + } - if (six_bit >= 6) { - six_bit = 0; - sixbits++; - } - } while (TRUE); + if (six_bit >= 6) { + six_bit = 0; + sixbits++; + } + } while (TRUE); } static void mMpswd_get_RSA_key_code(int* p, int* q, int* r, int** select_table, const u8* pswd) { - u32 rsa_info = pswd[mMpswd_RSA_INFO_IDX]; - int p_idx = rsa_info & 3; - int q_idx = (rsa_info >> 2) & 3; + u32 rsa_info = pswd[mMpswd_RSA_INFO_IDX]; + int p_idx = rsa_info & 3; + int q_idx = (rsa_info >> 2) & 3; - if (p_idx == 3) { - p_idx = (p_idx ^ q_idx) & 3; if (p_idx == 3) { - p_idx = 0; + p_idx = (p_idx ^ q_idx) & 3; + if (p_idx == 3) { + p_idx = 0; + } } - } - if (q_idx == 3) { - q_idx = (p_idx + 1) & 3; if (q_idx == 3) { - q_idx = 1; + q_idx = (p_idx + 1) & 3; + if (q_idx == 3) { + q_idx = 1; + } } - } - if (p_idx == q_idx) { - q_idx = (p_idx + 1) & 3; - if (q_idx == 3) { - q_idx = 1; + if (p_idx == q_idx) { + q_idx = (p_idx + 1) & 3; + if (q_idx == 3) { + q_idx = 1; + } } - } - *p = mMpswd_prime_number[p_idx]; - *q = mMpswd_prime_number[q_idx]; - *select_table = mMpswd_select_idx_table[(rsa_info >> 4) & 0xF]; - *r = mMpswd_prime_number[pswd[mMpswd_RSA_R_PRIME_IDX]]; + *p = mMpswd_prime_number[p_idx]; + *q = mMpswd_prime_number[q_idx]; + *select_table = mMpswd_select_idx_table[(rsa_info >> 4) & 0xF]; + *r = mMpswd_prime_number[pswd[mMpswd_RSA_R_PRIME_IDX]]; } static void mMpswd_chg_RSA_cipher(u8* pswd) { - int r; - int p; - int q; - int* select_idx_table; - int b; - int pq; - int rsa_keysave; - int i; - int idx; - int pow; - int chg; + int r; + int p; + int q; + int* select_idx_table; + int b; + int pq; + int rsa_keysave; + int i; + int idx; + int pow; + int chg; - mMpswd_get_RSA_key_code(&p, &q, &r, &select_idx_table, pswd); + mMpswd_get_RSA_key_code(&p, &q, &r, &select_idx_table, pswd); - rsa_keysave = 0; - pq = p * q; + rsa_keysave = 0; + pq = p * q; - for (i = 0; i < 8; i++) { - idx = select_idx_table[0]; - b = pswd[idx]; - chg = b; - - for (pow = r - 1; pow > 0; pow--) { - chg = (chg * b) % pq; + for (i = 0; i < 8; i++) { + idx = select_idx_table[0]; + b = pswd[idx]; + chg = b; + + for (pow = r - 1; pow > 0; pow--) { + chg = (chg * b) % pq; + } + + pswd[idx] = chg; + // save the 9th bit state + rsa_keysave |= ((chg >> 8) & 1) << i; + select_idx_table++; } - pswd[idx] = chg; - // save the 9th bit state - rsa_keysave |= ((chg >> 8) & 1) << i; - select_idx_table++; - } - - pswd[mMpswd_RSA_KEYSAVE_IDX] = rsa_keysave; + pswd[mMpswd_RSA_KEYSAVE_IDX] = rsa_keysave; } static void mMpswd_decode_RSA_cipher(u8* pswd) { - int n; - int r; - int p; - int q; - int pq_1; - int* select_idx_table; - int decrypted; - int i; - int b; - int pq; - int pow; - int rsa_keysave; - int d; - - mMpswd_get_RSA_key_code(&p, &q, &r, &select_idx_table, pswd); - pq = p * q; - pq_1 = (p - 1) * (q - 1); - pow = 1; - - /* Calculate exponent d for decryption */ - do { - n = pow * pq_1 + 1; - if (n % r == 0) { - r = n / r; - break; + int n; + int r; + int p; + int q; + int pq_1; + int* select_idx_table; + int decrypted; + int i; + int b; + int pq; + int pow; + int rsa_keysave; + int d; + + mMpswd_get_RSA_key_code(&p, &q, &r, &select_idx_table, pswd); + pq = p * q; + pq_1 = (p - 1) * (q - 1); + pow = 1; + + /* Calculate exponent d for decryption */ + do { + n = pow * pq_1 + 1; + if (n % r == 0) { + r = n / r; + break; + } + + pow++; + } while (TRUE); + + rsa_keysave = pswd[mMpswd_RSA_KEYSAVE_IDX]; + for (i = 0; i < 8; i++) { + b = pswd[select_idx_table[0]] | (((rsa_keysave >> i) & 1) << 8); + decrypted = b; + + /* Do decryption c^d = (m^e)^d = m (% n) */ + for (d = r - 1; d > 0; d--) { + decrypted = (decrypted * b) % pq; + } + + pswd[select_idx_table[0]] = decrypted; + select_idx_table++; } - - pow++; - } while (TRUE); - - rsa_keysave = pswd[mMpswd_RSA_KEYSAVE_IDX]; - for (i = 0; i < 8; i++) { - b = pswd[select_idx_table[0]] | (((rsa_keysave >> i) & 1) << 8); - decrypted = b; - - /* Do decryption c^d = (m^e)^d = m (% n) */ - for (d = r - 1; d > 0; d--) { - decrypted = (decrypted * b) % pq; - } - - pswd[select_idx_table[0]] = decrypted; - select_idx_table++; - } } static void mMpswd_bit_mix_code(u8* pswd) { - int bit_mix_code = pswd[mMpswd_BITMIX_CODE_IDX] & 0xF; + int bit_mix_code = pswd[mMpswd_BITMIX_CODE_IDX] & 0xF; - if (bit_mix_code > 12) { // [13, 15] (3 or 18.75%) - mMpswd_bit_arrange_reverse(pswd); - mMpswd_bit_reverse(pswd); - mMpswd_bit_shift(pswd, bit_mix_code * 3); - } - else if (bit_mix_code > 8) { // [9, 12] (4 or 25%) - mMpswd_bit_arrange_reverse(pswd); - mMpswd_bit_shift(pswd, -bit_mix_code * 5); - } - else if (bit_mix_code > 4) { // [5, 8] (4 or 25%) - mMpswd_bit_shift(pswd, -bit_mix_code * 5); - mMpswd_bit_reverse(pswd); - } - else { // [0, 4] (5 or 31.25%) - mMpswd_bit_shift(pswd, bit_mix_code * 3); - mMpswd_bit_arrange_reverse(pswd); - } + if (bit_mix_code > 12) { // [13, 15] (3 or 18.75%) + mMpswd_bit_arrange_reverse(pswd); + mMpswd_bit_reverse(pswd); + mMpswd_bit_shift(pswd, bit_mix_code * 3); + } else if (bit_mix_code > 8) { // [9, 12] (4 or 25%) + mMpswd_bit_arrange_reverse(pswd); + mMpswd_bit_shift(pswd, -bit_mix_code * 5); + } else if (bit_mix_code > 4) { // [5, 8] (4 or 25%) + mMpswd_bit_shift(pswd, -bit_mix_code * 5); + mMpswd_bit_reverse(pswd); + } else { // [0, 4] (5 or 31.25%) + mMpswd_bit_shift(pswd, bit_mix_code * 3); + mMpswd_bit_arrange_reverse(pswd); + } } static void mMpswd_decode_bit_code(u8* pswd) { - int bit_mix_code = pswd[mMpswd_BITMIX_CODE_IDX] & 0xF; + int bit_mix_code = pswd[mMpswd_BITMIX_CODE_IDX] & 0xF; - if (bit_mix_code > 12) { // [13, 15] (3 or 18.75%) - mMpswd_bit_shift(pswd, -bit_mix_code * 3); - mMpswd_bit_reverse(pswd); - mMpswd_bit_arrange_reverse(pswd); - } - else if (bit_mix_code > 8) { // [9, 12] (4 or 25%) - mMpswd_bit_shift(pswd, bit_mix_code * 5); - mMpswd_bit_arrange_reverse(pswd); - } - else if (bit_mix_code > 4) { // [5, 8] (4 or 25%) - mMpswd_bit_reverse(pswd); - mMpswd_bit_shift(pswd, bit_mix_code * 5); - } - else { // [0, 4] (5 or 31.25%) - mMpswd_bit_arrange_reverse(pswd); - mMpswd_bit_shift(pswd, -bit_mix_code * 3); - } + if (bit_mix_code > 12) { // [13, 15] (3 or 18.75%) + mMpswd_bit_shift(pswd, -bit_mix_code * 3); + mMpswd_bit_reverse(pswd); + mMpswd_bit_arrange_reverse(pswd); + } else if (bit_mix_code > 8) { // [9, 12] (4 or 25%) + mMpswd_bit_shift(pswd, bit_mix_code * 5); + mMpswd_bit_arrange_reverse(pswd); + } else if (bit_mix_code > 4) { // [5, 8] (4 or 25%) + mMpswd_bit_reverse(pswd); + mMpswd_bit_shift(pswd, bit_mix_code * 5); + } else { // [0, 4] (5 or 31.25%) + mMpswd_bit_arrange_reverse(pswd); + mMpswd_bit_shift(pswd, -bit_mix_code * 3); + } } static void mMpswd_substitution_cipher(u8* pswd) { - int i; + int i; - for (i = 0; i < mMpswd_PASSWORD_DATA_LEN; i++) { - pswd[i] = mMpswd_chg_code_table[pswd[i]]; - } + for (i = 0; i < mMpswd_PASSWORD_DATA_LEN; i++) { + pswd[i] = mMpswd_chg_code_table[pswd[i]]; + } } static void mMpswd_decode_substitution_cipher(u8* pswd) { - int i; - int idx; - - for (i = 0, idx = 0; i < mMpswd_PASSWORD_DATA_LEN; i++) { - int j; + int i; + int idx; - for (j = 0; j < 256; j++) { - if (mMpswd_chg_code_table[j] == pswd[idx]) { - pswd[idx] = j; - idx++; - break; - } + for (i = 0, idx = 0; i < mMpswd_PASSWORD_DATA_LEN; i++) { + int j; + + for (j = 0; j < 256; j++) { + if (mMpswd_chg_code_table[j] == pswd[idx]) { + pswd[idx] = j; + idx++; + break; + } + } } - } } static void mMpswd_transposition_cipher(u8* pswd, int dir, int char_idx) { - static int key_idx[2] = { 18, 9 }; - mMpswd_transposition_cipher_str_c* cipher; - u8* trans_str; - int len; + static int key_idx[2] = { 18, 9 }; + mMpswd_transposition_cipher_str_c* cipher; + u8* trans_str; + int len; - int m; - int i; - int str_idx; + int m; + int i; + int str_idx; - cipher = &mMpswd_transposition_cipher_char_table[char_idx][pswd[key_idx[char_idx]] & 0xF]; - trans_str = cipher->str; - len = cipher->len; + cipher = &mMpswd_transposition_cipher_char_table[char_idx][pswd[key_idx[char_idx]] & 0xF]; + trans_str = cipher->str; + len = cipher->len; - m = 1; - if (dir == 1) { - m = -1; - } - str_idx = 0; - for (i = 0; i < mMpswd_PASSWORD_DATA_LEN; i++) { - if (i != key_idx[char_idx]) { - *pswd += trans_str[str_idx++] * m; - - if (str_idx >= len) { - str_idx = 0; - } + m = 1; + if (dir == 1) { + m = -1; } + str_idx = 0; + for (i = 0; i < mMpswd_PASSWORD_DATA_LEN; i++) { + if (i != key_idx[char_idx]) { + *pswd += trans_str[str_idx++] * m; - pswd++; - } + if (str_idx >= len) { + str_idx = 0; + } + } + + pswd++; + } } // @fakematch static void mMpswd_bit_shuffle(u8* pswd, int stage) { - u8 buf[mMpswd_PASSWORD_DATA_LEN - 1]; - u8 work_buf[mMpswd_PASSWORD_DATA_LEN - 1]; + u8 buf[mMpswd_PASSWORD_DATA_LEN - 1]; + u8 work_buf[mMpswd_PASSWORD_DATA_LEN - 1]; - int key_idx; - int test2; - u8* test; - int count; + int key_idx; + int test2; + u8* test; + int count; - count = mMpswd_PASSWORD_DATA_LEN - 1; - key_idx = 2; + count = mMpswd_PASSWORD_DATA_LEN - 1; + key_idx = 2; - if (stage == 0) { - key_idx = 13; - count = mMpswd_PASSWORD_DATA_LEN - 2; - } + if (stage == 0) { + key_idx = 13; + count = mMpswd_PASSWORD_DATA_LEN - 2; + } memcpy(buf, pswd, key_idx); test = pswd + key_idx + 1; @@ -761,24 +707,24 @@ static void mMpswd_bit_shuffle(u8* pswd, int stage) { bzero(work_buf, count); { - int* select_idx_table = mMpswd_select_idx_table[pswd[key_idx] & 3]; - int dst_idx; - int i; + int* select_idx_table = mMpswd_select_idx_table[pswd[key_idx] & 3]; + int dst_idx; + int i; - for (i = 0; i < count; i++) { - u8 b = buf[i]; - int bit; - - for (bit = 0; bit < 8; bit++) { - dst_idx = i + select_idx_table[bit]; + for (i = 0; i < count; i++) { + u8 b = buf[i]; + int bit; - if (dst_idx >= count) { - dst_idx -= count; - } + for (bit = 0; bit < 8; bit++) { + dst_idx = i + select_idx_table[bit]; - work_buf[dst_idx] |= (u8)(((b >> bit) & 1) << bit); + if (dst_idx >= count) { + dst_idx -= count; + } + + work_buf[dst_idx] |= (u8)(((b >> bit) & 1) << bit); + } } - } } memcpy(pswd, work_buf, key_idx); @@ -787,570 +733,519 @@ static void mMpswd_bit_shuffle(u8* pswd, int stage) { // @fakematch static void mMpswd_decode_bit_shuffle(u8* pswd, int stage) { - u8 work_buf[mMpswd_PASSWORD_DATA_LEN - 1]; - u8 buf[mMpswd_PASSWORD_DATA_LEN - 1]; - int key_idx; - int test2; - u8* test; - int count; - int* select_idx_table; - int i; - - count = mMpswd_PASSWORD_DATA_LEN - 1; - key_idx = 2; + u8 work_buf[mMpswd_PASSWORD_DATA_LEN - 1]; + u8 buf[mMpswd_PASSWORD_DATA_LEN - 1]; + int key_idx; + int test2; + u8* test; + int count; + int* select_idx_table; + int i; - if (stage == 0) { - key_idx = 13; - count = mMpswd_PASSWORD_DATA_LEN - 2; - } + count = mMpswd_PASSWORD_DATA_LEN - 1; + key_idx = 2; + + if (stage == 0) { + key_idx = 13; + count = mMpswd_PASSWORD_DATA_LEN - 2; + } - memcpy(work_buf, pswd, key_idx); test = pswd + key_idx + 1; memcpy(work_buf + key_idx, test, test2 = (mMpswd_PASSWORD_DATA_LEN - 1) - key_idx); // TODO: fakematch bzero(buf, count); - select_idx_table = mMpswd_select_idx_table[pswd[key_idx] & 3]; + select_idx_table = mMpswd_select_idx_table[pswd[key_idx] & 3]; - for (i = 0; i < count; i++) { + for (i = 0; i < count; i++) { int bit; - + for (bit = 0; bit < 8; bit++) { - int dst_idx = i + select_idx_table[bit]; + int dst_idx = i + select_idx_table[bit]; - if (dst_idx >= count) { - dst_idx -= count; - } + if (dst_idx >= count) { + dst_idx -= count; + } - buf[i] |= (u8)(((work_buf[dst_idx] >> bit) & 1) << bit); + buf[i] |= (u8)(((work_buf[dst_idx] >> bit) & 1) << bit); } - } + } memcpy(pswd, buf, key_idx); memcpy(test, buf + key_idx, test2); } static void mMpswd_chg_common_font_code(u8* pswd) { - u8 changed_pswd[mMpswd_PASSWORD_STR_LEN]; - int i; + u8 changed_pswd[mMpswd_PASSWORD_STR_LEN]; + int i; - for (i = 0; i < mMpswd_PASSWORD_STR_LEN; i++) { - changed_pswd[i] = usable_to_fontnum[pswd[i]]; - } + for (i = 0; i < mMpswd_PASSWORD_STR_LEN; i++) { + changed_pswd[i] = usable_to_fontnum[pswd[i]]; + } - memcpy(pswd, changed_pswd, mMpswd_PASSWORD_STR_LEN); + memcpy(pswd, changed_pswd, mMpswd_PASSWORD_STR_LEN); } static u8 mMpswd_chg_password_font_code_sub(u8 c) { - int i; - int res = 0xFF; + int i; + int res = 0xFF; - for (i = 0; i < 64; i++) { - if (c == usable_to_fontnum[i]) { - res = i; // probably should've used a break; here + for (i = 0; i < 64; i++) { + if (c == usable_to_fontnum[i]) { + res = i; // probably should've used a break; here + } } - } - return res; + return res; } static int mMpswd_chg_password_font_code(u8* pswd) { - u8 changed_pswd[mMpswd_PASSWORD_STR_LEN]; - int i; - int res = TRUE; + u8 changed_pswd[mMpswd_PASSWORD_STR_LEN]; + int i; + int res = TRUE; - for (i = 0; i < mMpswd_PASSWORD_STR_LEN; i++) { - u8 new_code = mMpswd_chg_password_font_code_sub(pswd[i]); + for (i = 0; i < mMpswd_PASSWORD_STR_LEN; i++) { + u8 new_code = mMpswd_chg_password_font_code_sub(pswd[i]); - if (new_code == 0xFF) { - res = FALSE; - break; + if (new_code == 0xFF) { + res = FALSE; + break; + } + + changed_pswd[i] = new_code; } - changed_pswd[i] = new_code; - } + if (res == TRUE) { + memcpy(pswd, changed_pswd, mMpswd_PASSWORD_STR_LEN); + } - if (res == TRUE) { - memcpy(pswd, changed_pswd, mMpswd_PASSWORD_STR_LEN); - } - - return res; + return res; } -extern void mMpswd_make_password( - u8* password_buf, - int type, - int hit_rate, - u8* str0, - u8* str1, - mActor_name_t item, - int npc_type, - int npc_code -) { - u8 work_buf[mMpswd_PASSWORD_STR_LEN]; +extern void mMpswd_make_password(u8* password_buf, int type, int hit_rate, u8* str0, u8* str1, mActor_name_t item, + int npc_type, int npc_code) { + u8 work_buf[mMpswd_PASSWORD_STR_LEN]; - bzero(work_buf, mMpswd_PASSWORD_STR_LEN); - mMpswd_make_passcode(work_buf, type, hit_rate, str0, str1, item, npc_type, npc_code); - mMpswd_substitution_cipher(work_buf); - mMpswd_transposition_cipher(work_buf, 1, 0); - mMpswd_bit_shuffle(work_buf, 0); - mMpswd_chg_RSA_cipher(work_buf); - mMpswd_bit_mix_code(work_buf); - mMpswd_bit_shuffle(work_buf, 1); - mMpswd_transposition_cipher(work_buf, 0, 1); - mMpswd_chg_6bits_code(password_buf, work_buf); - mMpswd_chg_common_font_code(password_buf); + bzero(work_buf, mMpswd_PASSWORD_STR_LEN); + mMpswd_make_passcode(work_buf, type, hit_rate, str0, str1, item, npc_type, npc_code); + mMpswd_substitution_cipher(work_buf); + mMpswd_transposition_cipher(work_buf, 1, 0); + mMpswd_bit_shuffle(work_buf, 0); + mMpswd_chg_RSA_cipher(work_buf); + mMpswd_bit_mix_code(work_buf); + mMpswd_bit_shuffle(work_buf, 1); + mMpswd_transposition_cipher(work_buf, 0, 1); + mMpswd_chg_6bits_code(password_buf, work_buf); + mMpswd_chg_common_font_code(password_buf); } extern int mMpswd_decode_code(u8* password_data, u8* password_str) { - u8 work_buf[mMpswd_PASSWORD_STR_LEN]; - int res = FALSE; + u8 work_buf[mMpswd_PASSWORD_STR_LEN]; + int res = FALSE; - memcpy(work_buf, password_str, mMpswd_PASSWORD_STR_LEN); - mMpswd_adjust_letter(work_buf); - if (mMpswd_chg_password_font_code(work_buf) == TRUE) { - mMpswd_chg_8bits_code(password_data, work_buf); - mMpswd_transposition_cipher(password_data, 1, 1); - mMpswd_decode_bit_shuffle(password_data, 1); - mMpswd_decode_bit_code(password_data); - mMpswd_decode_RSA_cipher(password_data); - mMpswd_decode_bit_shuffle(password_data, 0); - mMpswd_transposition_cipher(password_data, 0, 0); - mMpswd_decode_substitution_cipher(password_data); + memcpy(work_buf, password_str, mMpswd_PASSWORD_STR_LEN); + mMpswd_adjust_letter(work_buf); + if (mMpswd_chg_password_font_code(work_buf) == TRUE) { + mMpswd_chg_8bits_code(password_data, work_buf); + mMpswd_transposition_cipher(password_data, 1, 1); + mMpswd_decode_bit_shuffle(password_data, 1); + mMpswd_decode_bit_code(password_data); + mMpswd_decode_RSA_cipher(password_data); + mMpswd_decode_bit_shuffle(password_data, 0); + mMpswd_transposition_cipher(password_data, 0, 0); + mMpswd_decode_substitution_cipher(password_data); - res = TRUE; - } + res = TRUE; + } - return res; + return res; } extern int mMpswd_restore_code(u8* body, u8* password) { - u8 password_str[mMpswd_PASSWORD_STR_LEN]; - int res = FALSE; + u8 password_str[mMpswd_PASSWORD_STR_LEN]; + int res = FALSE; - if (mMpswd_check_opening_sentence(body) == TRUE) { - u8* password_str_p = mMpswd_get_password_pointer(body); - if (password_str_p != NULL) { - mMpswd_except_return_code(password_str, password_str_p); - res = mMpswd_decode_code(password, password_str); + if (mMpswd_check_opening_sentence(body) == TRUE) { + u8* password_str_p = mMpswd_get_password_pointer(body); + if (password_str_p != NULL) { + mMpswd_except_return_code(password_str, password_str_p); + res = mMpswd_decode_code(password, password_str); + } } - } - return res; + return res; } extern void mMpswd_password(u8* password_data, mMpswd_password_c* password) { - u32 b0 = password_data[0]; + u32 b0 = password_data[0]; - password->checksum = (b0 >> 3) & 3; - memcpy(password->str0, password_data + 2, PLAYER_NAME_LEN); - memcpy(password->str1, password_data + 10, PLAYER_NAME_LEN); - password->item = (password_data[18] << 8) + password_data[19]; - password->type = (b0 >> 5) & 7; + password->checksum = (b0 >> 3) & 3; + memcpy(password->str0, password_data + 2, PLAYER_NAME_LEN); + memcpy(password->str1, password_data + 10, PLAYER_NAME_LEN); + password->item = (password_data[18] << 8) + password_data[19]; + password->type = (b0 >> 5) & 7; - switch (password->type) { - case mMpswd_CODETYPE_POPULAR: - { - password->hit_rate_index = (b0 >> 1) & 3; - password->npc_type = b0 & 1; - password->npc_code = password_data[1]; - break; + switch (password->type) { + case mMpswd_CODETYPE_POPULAR: { + password->hit_rate_index = (b0 >> 1) & 3; + password->npc_type = b0 & 1; + password->npc_code = password_data[1]; + break; + } + + case mMpswd_CODETYPE_CARD_E: { + password->hit_rate_index = (b0 >> 1) & 3; + password->npc_type = b0 & 1; + password->npc_code = password_data[1]; + break; + } + + case mMpswd_CODETYPE_MAGAZINE: { + password->hit_rate_index = ((b0 >> 1) & 3) | (b0 & 1) << 2; + password->npc_type = -1; + password->npc_code = -1; + break; + } + + default: { + password->hit_rate_index = (b0 >> 1) & 3; + password->npc_type = -1; + password->npc_code = -1; + break; + } } - - case mMpswd_CODETYPE_CARD_E: - { - password->hit_rate_index = (b0 >> 1) & 3; - password->npc_type = b0 & 1; - password->npc_code = password_data[1]; - break; - } - - case mMpswd_CODETYPE_MAGAZINE: - { - password->hit_rate_index = ((b0 >> 1) & 3) | (b0 & 1) << 2; - password->npc_type = -1; - password->npc_code = -1; - break; - } - - default: - { - password->hit_rate_index = (b0 >> 1) & 3; - password->npc_type = -1; - password->npc_code = -1; - break; - } - } } extern int mMpswd_password_zuru_check(mMpswd_password_c* password) { - int cheated = TRUE; + int cheated = TRUE; - if (password->type < mMpswd_CODETYPE_NUM) { - int checksum = 0; - int i; + if (password->type < mMpswd_CODETYPE_NUM) { + int checksum = 0; + int i; - for (i = 0; i < PLAYER_NAME_LEN; i++) { - checksum += password->str0[i]; + for (i = 0; i < PLAYER_NAME_LEN; i++) { + checksum += password->str0[i]; + } + + for (i = 0; i < PLAYER_NAME_LEN; i++) { + checksum += password->str1[i]; + } + + checksum += password->item; + checksum += password->npc_code; + + if ((checksum & 3) == password->checksum) { + cheated = FALSE; + } } - for (i = 0; i < PLAYER_NAME_LEN; i++) { - checksum += password->str1[i]; - } - - checksum += password->item; - checksum += password->npc_code; - - if ((checksum & 3) == password->checksum) { - cheated = FALSE; - } - } - - return cheated; + return cheated; } static int mMpswd_check_present_famicom(mActor_name_t item) { - int i; - int res = FALSE; + int i; + int res = FALSE; - for (i = 0; i < pswd_famicom_list_max; i++) { - if (item == mRmTp_FtrIdx2FtrItemNo(pswd_famicom_list[i], 0)) { - res = TRUE; - break; + for (i = 0; i < pswd_famicom_list_max; i++) { + if (item == mRmTp_FtrIdx2FtrItemNo(pswd_famicom_list[i], 0)) { + res = TRUE; + break; + } } - } - return res; + return res; } extern int mMpswd_check_present_user(mActor_name_t item) { - mActor_name_t full_stack_item; - u32 price = 0; - int res = FALSE; + mActor_name_t full_stack_item; + u32 price = 0; + int res = FALSE; - switch (ITEM_NAME_GET_TYPE(item)) { - case NAME_TYPE_FTR0: - case NAME_TYPE_FTR1: - { - if (item >= FTR_CLOTH_MANNIQUIN000_SOUTH && item <= FTR_CLOTH_MANNIQUIN254_WEST) { - item = mRmTp_FtrItemNo2Item1ItemNo(item, FALSE); - if ( - mSP_SearchItemCategoryPriority(item, mSP_KIND_CLOTH, mSP_LISTTYPE_COMMON, NULL) || - mSP_SearchItemCategoryPriority(item, mSP_KIND_CLOTH, mSP_LISTTYPE_UNCOMMON, NULL) || - mSP_SearchItemCategoryPriority(item, mSP_KIND_CLOTH, mSP_LISTTYPE_RARE, NULL) - ) { - price = mSP_ItemNo2ItemPrice(item); + switch (ITEM_NAME_GET_TYPE(item)) { + case NAME_TYPE_FTR0: + case NAME_TYPE_FTR1: { + if (item >= FTR_CLOTH_MANNIQUIN000_SOUTH && item <= FTR_CLOTH_MANNIQUIN254_WEST) { + item = mRmTp_FtrItemNo2Item1ItemNo(item, FALSE); + if (mSP_SearchItemCategoryPriority(item, mSP_KIND_CLOTH, mSP_LISTTYPE_COMMON, NULL) || + mSP_SearchItemCategoryPriority(item, mSP_KIND_CLOTH, mSP_LISTTYPE_UNCOMMON, NULL) || + mSP_SearchItemCategoryPriority(item, mSP_KIND_CLOTH, mSP_LISTTYPE_RARE, NULL)) { + price = mSP_ItemNo2ItemPrice(item); + } + } else if (item >= FTR_UMBRELLA00_SOUTH && item <= FTR_UMBRELLA31_WEST) { + price = mSP_ItemNo2ItemPrice(mRmTp_FtrItemNo2Item1ItemNo(item, FALSE)); + } else if ( // TODO: furniture index values need to be declared in some header file as defines + (mRmTp_FtrItemNo2FtrIdx(item) >= 0x3FC && mRmTp_FtrItemNo2FtrIdx(item) <= 0x403) || // balloons + (item >= FTR_COLLEGERULE && item <= FTR_CALLIGRAPHY_PAD_WEST) || // diaries + (mRmTp_FtrItemNo2FtrIdx(item) >= 0x453 && mRmTp_FtrItemNo2FtrIdx(item) <= 0x45A) || // fans + (mRmTp_FtrItemNo2FtrIdx(item) >= 0x45B && mRmTp_FtrItemNo2FtrIdx(item) <= 0x462) || // pinwheels + (mRmTp_FtrItemNo2FtrIdx(item) >= 0x44F && mRmTp_FtrItemNo2FtrIdx(item) <= 0x452) || // golden tools + (mRmTp_FtrItemNo2FtrIdx(item) >= 0x463 && mRmTp_FtrItemNo2FtrIdx(item) <= 0x466) // regular tools + ) { + /* Convert furniture to their item1 variants */ + price = mSP_ItemNo2ItemPrice(mRmTp_FtrItemNo2Item1ItemNo(item, FALSE)); + } else if (mSP_SearchItemCategoryPriority(item, mSP_KIND_FURNITURE, mSP_LISTTYPE_COMMON, NULL) || + mSP_SearchItemCategoryPriority(item, mSP_KIND_FURNITURE, mSP_LISTTYPE_UNCOMMON, NULL) || + mSP_SearchItemCategoryPriority(item, mSP_KIND_FURNITURE, mSP_LISTTYPE_RARE, NULL) || + mSP_SearchItemCategoryPriority(item, mSP_KIND_FURNITURE, mSP_LISTTYPE_TRAIN, NULL) || + mSP_SearchItemCategoryPriority(item, mSP_KIND_FURNITURE, mSP_LISTTYPE_EVENT, NULL) || + mSP_SearchItemCategoryPriority(item, mSP_KIND_FURNITURE, mSP_LISTTYPE_LOTTERY, NULL) || + mSP_SearchItemCategoryPriority(item, mSP_KIND_FURNITURE, mSP_LISTTYPE_EVENTPRESENTCHUMON, + NULL)) { + price = mSP_ItemNo2ItemPrice(item); + } + + break; } - } - else if (item >= FTR_UMBRELLA00_SOUTH && item <= FTR_UMBRELLA31_WEST) { - price = mSP_ItemNo2ItemPrice(mRmTp_FtrItemNo2Item1ItemNo(item, FALSE)); - } - else if ( // TODO: furniture index values need to be declared in some header file as defines - (mRmTp_FtrItemNo2FtrIdx(item) >= 0x3FC && mRmTp_FtrItemNo2FtrIdx(item) <= 0x403) || // balloons - (item >= FTR_COLLEGERULE && item <= FTR_CALLIGRAPHY_PAD_WEST) || // diaries - (mRmTp_FtrItemNo2FtrIdx(item) >= 0x453 && mRmTp_FtrItemNo2FtrIdx(item) <= 0x45A) || // fans - (mRmTp_FtrItemNo2FtrIdx(item) >= 0x45B && mRmTp_FtrItemNo2FtrIdx(item) <= 0x462) || // pinwheels - (mRmTp_FtrItemNo2FtrIdx(item) >= 0x44F && mRmTp_FtrItemNo2FtrIdx(item) <= 0x452) || // golden tools - (mRmTp_FtrItemNo2FtrIdx(item) >= 0x463 && mRmTp_FtrItemNo2FtrIdx(item) <= 0x466) // regular tools - ) { - /* Convert furniture to their item1 variants */ - price = mSP_ItemNo2ItemPrice(mRmTp_FtrItemNo2Item1ItemNo(item, FALSE)); - } - else if ( - mSP_SearchItemCategoryPriority(item, mSP_KIND_FURNITURE, mSP_LISTTYPE_COMMON, NULL) || - mSP_SearchItemCategoryPriority(item, mSP_KIND_FURNITURE, mSP_LISTTYPE_UNCOMMON, NULL) || - mSP_SearchItemCategoryPriority(item, mSP_KIND_FURNITURE, mSP_LISTTYPE_RARE, NULL) || - mSP_SearchItemCategoryPriority(item, mSP_KIND_FURNITURE, mSP_LISTTYPE_TRAIN, NULL) || - mSP_SearchItemCategoryPriority(item, mSP_KIND_FURNITURE, mSP_LISTTYPE_EVENT, NULL) || - mSP_SearchItemCategoryPriority(item, mSP_KIND_FURNITURE, mSP_LISTTYPE_LOTTERY, NULL) || - mSP_SearchItemCategoryPriority(item, mSP_KIND_FURNITURE, mSP_LISTTYPE_EVENTPRESENTCHUMON, NULL) - ) { - price = mSP_ItemNo2ItemPrice(item); - } - break; + case NAME_TYPE_ITEM1: { + if (item >= ITM_CLOTH_START && item < ITM_CLOTH_END) { + if (mSP_SearchItemCategoryPriority(item, mSP_KIND_CLOTH, mSP_LISTTYPE_COMMON, NULL) || + mSP_SearchItemCategoryPriority(item, mSP_KIND_CLOTH, mSP_LISTTYPE_UNCOMMON, NULL) || + mSP_SearchItemCategoryPriority(item, mSP_KIND_CLOTH, mSP_LISTTYPE_RARE, NULL)) { + price = mSP_ItemNo2ItemPrice(item); + } + } else if (item >= ITM_UMBRELLA00 && item <= ITM_MY_ORG_UMBRELLA7) { + price = mSP_ItemNo2ItemPrice(item); + } else if ((item >= ITM_RED_BALLOON && item <= ITM_BUNNY_O_BALLOON) || + (item >= ITM_DIARY00 && item <= ITM_DIARY15) || + (item >= ITM_BLUEBELL_FAN && item <= ITM_LEAF_FAN) || + (item >= ITM_YELLOW_PINWHEEL && item <= ITM_FANCY_PINWHEEL) || + (item >= ITM_GOLDEN_NET && item <= ITM_GOLDEN_ROD) || (item >= ITM_NET && item <= ITM_ROD)) { + price = mSP_ItemNo2ItemPrice(item); + } else { + switch (ITEM_NAME_GET_CAT(item)) { + case ITEM1_CAT_FRUIT: { + price = mSP_ItemNo2ItemPrice(item); + break; + } + + case ITEM1_CAT_PAPER: { + full_stack_item = ITM_PAPER_STACK_FOUR_START + (item & 0x3F); + if (mSP_SearchItemCategoryPriority(full_stack_item, mSP_KIND_PAPER, mSP_LISTTYPE_COMMON, + NULL) || + mSP_SearchItemCategoryPriority(full_stack_item, mSP_KIND_PAPER, mSP_LISTTYPE_UNCOMMON, + NULL) || + mSP_SearchItemCategoryPriority(full_stack_item, mSP_KIND_PAPER, mSP_LISTTYPE_RARE, NULL)) { + price = mSP_ItemNo2ItemPrice(full_stack_item); + } + + break; + } + + case ITEM1_CAT_WALL: { + if (mSP_SearchItemCategoryPriority(item, mSP_KIND_WALLPAPER, mSP_LISTTYPE_COMMON, NULL) || + mSP_SearchItemCategoryPriority(item, mSP_KIND_WALLPAPER, mSP_LISTTYPE_UNCOMMON, NULL) || + mSP_SearchItemCategoryPriority(item, mSP_KIND_WALLPAPER, mSP_LISTTYPE_RARE, NULL)) { + price = mSP_ItemNo2ItemPrice(item); + } + + break; + } + + case ITEM1_CAT_CARPET: { + if (mSP_SearchItemCategoryPriority(item, mSP_KIND_CARPET, mSP_LISTTYPE_COMMON, NULL) || + mSP_SearchItemCategoryPriority(item, mSP_KIND_CARPET, mSP_LISTTYPE_UNCOMMON, NULL) || + mSP_SearchItemCategoryPriority(item, mSP_KIND_CARPET, mSP_LISTTYPE_RARE, NULL)) { + price = mSP_ItemNo2ItemPrice(item); + } + + break; + } + } + } + + break; + } } - case NAME_TYPE_ITEM1: - { - if (item >= ITM_CLOTH_START && item < ITM_CLOTH_END) { - if ( - mSP_SearchItemCategoryPriority(item, mSP_KIND_CLOTH, mSP_LISTTYPE_COMMON, NULL) || - mSP_SearchItemCategoryPriority(item, mSP_KIND_CLOTH, mSP_LISTTYPE_UNCOMMON, NULL) || - mSP_SearchItemCategoryPriority(item, mSP_KIND_CLOTH, mSP_LISTTYPE_RARE, NULL) - ) { - price = mSP_ItemNo2ItemPrice(item); - } - } - else if (item >= ITM_UMBRELLA00 && item <= ITM_MY_ORG_UMBRELLA7) { - price = mSP_ItemNo2ItemPrice(item); - } - else if ( - (item >= ITM_RED_BALLOON && item <= ITM_BUNNY_O_BALLOON) || - (item >= ITM_DIARY00 && item <= ITM_DIARY15) || - (item >= ITM_BLUEBELL_FAN && item <= ITM_LEAF_FAN) || - (item >= ITM_YELLOW_PINWHEEL && item <= ITM_FANCY_PINWHEEL) || - (item >= ITM_GOLDEN_NET && item <= ITM_GOLDEN_ROD) || - (item >= ITM_NET && item <= ITM_ROD) - ) { - price = mSP_ItemNo2ItemPrice(item); - } - else { - switch (ITEM_NAME_GET_CAT(item)) { - case ITEM1_CAT_FRUIT: - { - price = mSP_ItemNo2ItemPrice(item); - break; - } - - case ITEM1_CAT_PAPER: - { - full_stack_item = ITM_PAPER_STACK_FOUR_START + (item & 0x3F); - if ( - mSP_SearchItemCategoryPriority(full_stack_item, mSP_KIND_PAPER, mSP_LISTTYPE_COMMON, NULL) || - mSP_SearchItemCategoryPriority(full_stack_item, mSP_KIND_PAPER, mSP_LISTTYPE_UNCOMMON, NULL) || - mSP_SearchItemCategoryPriority(full_stack_item, mSP_KIND_PAPER, mSP_LISTTYPE_RARE, NULL) - ) { - price = mSP_ItemNo2ItemPrice(full_stack_item); - } - - break; - } - - case ITEM1_CAT_WALL: - { - if ( - mSP_SearchItemCategoryPriority(item, mSP_KIND_WALLPAPER, mSP_LISTTYPE_COMMON, NULL) || - mSP_SearchItemCategoryPriority(item, mSP_KIND_WALLPAPER, mSP_LISTTYPE_UNCOMMON, NULL) || - mSP_SearchItemCategoryPriority(item, mSP_KIND_WALLPAPER, mSP_LISTTYPE_RARE, NULL) - ) { - price = mSP_ItemNo2ItemPrice(item); - } - - break; - } - - case ITEM1_CAT_CARPET: - { - if ( - mSP_SearchItemCategoryPriority(item, mSP_KIND_CARPET, mSP_LISTTYPE_COMMON, NULL) || - mSP_SearchItemCategoryPriority(item, mSP_KIND_CARPET, mSP_LISTTYPE_UNCOMMON, NULL) || - mSP_SearchItemCategoryPriority(item, mSP_KIND_CARPET, mSP_LISTTYPE_RARE, NULL) - ) { - price = mSP_ItemNo2ItemPrice(item); - } - - break; - } - } - } - - break; + if (price != 0) { + res = TRUE; } - } - if (price != 0) { - res = TRUE; - } - - return res; + return res; } static int mMpswd_check_present_other(mActor_name_t item) { - int res = FALSE; + int res = FALSE; - switch (ITEM_NAME_GET_TYPE(item)) { - case NAME_TYPE_FTR0: - case NAME_TYPE_FTR1: - { - switch (mRmTp_FurnitureIdx2FurnitureKind(mRmTp_FtrItemNo2FtrIdx(item))) { - case mRmTp_BIRTH_TYPE_FTR_CLOTH: - case mRmTp_BIRTH_TYPE_FTR_UMBRELLA: - case mRmTp_BIRTH_TYPE_FTR_INSECT: - case mRmTp_BIRTH_TYPE_FTR_FISH: - case mRmTp_BIRTH_TYPE_UNOBTAINABLE: - case mRmTp_BIRTH_TYPE_FAMICOM_EREADER: - case mRmTp_BIRTH_TYPE_MY_ORIGINAL: - case mRmTp_BIRTH_TYPE_FAMICOM_CODE: - case mRmTp_BIRTH_TYPE_FTR_DIARY: - { - break; + switch (ITEM_NAME_GET_TYPE(item)) { + case NAME_TYPE_FTR0: + case NAME_TYPE_FTR1: { + switch (mRmTp_FurnitureIdx2FurnitureKind(mRmTp_FtrItemNo2FtrIdx(item))) { + case mRmTp_BIRTH_TYPE_FTR_CLOTH: + case mRmTp_BIRTH_TYPE_FTR_UMBRELLA: + case mRmTp_BIRTH_TYPE_FTR_INSECT: + case mRmTp_BIRTH_TYPE_FTR_FISH: + case mRmTp_BIRTH_TYPE_UNOBTAINABLE: + case mRmTp_BIRTH_TYPE_FAMICOM_EREADER: + case mRmTp_BIRTH_TYPE_MY_ORIGINAL: + case mRmTp_BIRTH_TYPE_FAMICOM_CODE: + case mRmTp_BIRTH_TYPE_FTR_DIARY: { + break; + } + + default: { + res = TRUE; + break; + } + } + + break; } - default: - { - res = TRUE; - break; - } - } + case NAME_TYPE_ITEM1: { + switch (ITEM_NAME_GET_CAT(item)) { + case ITEM1_CAT_TOOL: { + /* allow umbrellas */ + if (item >= ITM_UMBRELLA00 && item <= ITM_UMBRELLA31) { + res = TRUE; + break; + } - break; + /* allow balloons */ + if ((item >= ITM_RED_BALLOON && item <= ITM_BUNNY_O_BALLOON) == TRUE) { + res = TRUE; + break; + } + + /* allow fans */ + if ((item >= ITM_BLUEBELL_FAN && item <= ITM_LEAF_FAN) == TRUE) { + res = TRUE; + break; + } + + /* allow pinwheels */ + if ((item >= ITM_YELLOW_PINWHEEL && item <= ITM_FANCY_PINWHEEL) == TRUE) { + res = TRUE; + break; + } + + break; + } + + case ITEM1_CAT_PAPER: { + int amount = item - ITM_PAPER_START; + if (amount / 64 + 1 >= 4) { + res = TRUE; // Paper in stacks of 4 + } + + break; + } + + case ITEM1_CAT_FISH: { + /* fish are not allowed */ + break; + } + + case ITEM1_CAT_INSECT: { + /* insects are not allowed */ + break; + } + + default: { + /* allow everything else in the 2XXX range through */ + res = TRUE; + break; + } + } + break; + } } - - case NAME_TYPE_ITEM1: - { - switch (ITEM_NAME_GET_CAT(item)) { - case ITEM1_CAT_TOOL: - { - /* allow umbrellas */ - if (item >= ITM_UMBRELLA00 && item <= ITM_UMBRELLA31) { - res = TRUE; - break; - } - - /* allow balloons */ - if ((item >= ITM_RED_BALLOON && item <= ITM_BUNNY_O_BALLOON) == TRUE) { - res = TRUE; - break; - } - /* allow fans */ - if ((item >= ITM_BLUEBELL_FAN && item <= ITM_LEAF_FAN) == TRUE) { - res = TRUE; - break; - } - - /* allow pinwheels */ - if ((item >= ITM_YELLOW_PINWHEEL && item <= ITM_FANCY_PINWHEEL) == TRUE) { - res = TRUE; - break; - } - - break; - } - - case ITEM1_CAT_PAPER: - { - int amount = item - ITM_PAPER_START; - if (amount / 64 + 1 >= 4) { - res = TRUE; // Paper in stacks of 4 - } - - break; - } - - case ITEM1_CAT_FISH: - { - /* fish are not allowed */ - break; - } - - case ITEM1_CAT_INSECT: - { - /* insects are not allowed */ - break; - } - - default: - { - /* allow everything else in the 2XXX range through */ - res = TRUE; - break; - } - } - break; - } - } - - return res; + return res; } extern int mMpswd_check_present(mMpswd_password_c* password) { - mActor_name_t present = password->item; - int valid; - - if (present == RSV_NO) { - valid = TRUE; - } - else { - switch (password->type) { - case mMpswd_CODETYPE_FAMICOM: - { - valid = mMpswd_check_present_famicom(present); - break; - } + mActor_name_t present = password->item; + int valid; - case mMpswd_CODETYPE_USER: - { - valid = mMpswd_check_present_user(present); - break; - } + if (present == RSV_NO) { + valid = TRUE; + } else { + switch (password->type) { + case mMpswd_CODETYPE_FAMICOM: { + valid = mMpswd_check_present_famicom(present); + break; + } - default: - { - valid = mMpswd_check_present_other(present); - break; - } + case mMpswd_CODETYPE_USER: { + valid = mMpswd_check_present_user(present); + break; + } + + default: { + valid = mMpswd_check_present_other(present); + break; + } + } } - } - return valid; + return valid; } extern mActor_name_t mMpswd_get_sp_npc_num(int sp_npc) { - static mActor_name_t sp_npc_code_table[mMpswd_SPECIAL_NPC_NUM] = { - SP_NPC_SHOP_MASTER, // Tom Nook - SP_NPC_ARTIST, // Wendell - SP_NPC_CARPETPEDDLER, // Saharah - SP_NPC_DESIGNER, // Gracie - SP_NPC_KABUPEDDLER, // Joan - SP_NPC_GYPSY, // Katrina - SP_NPC_POLICE, // Copper - SP_NPC_HALLOWEEN, // Jack - SP_NPC_SANTA, // Jingle - SP_NPC_POST_MAN, // Pete - SP_NPC_POST_GIRL, // Pelly - SP_NPC_POST_GIRL2, // Phyllis - SP_NPC_GUIDE, // Rover - SP_NPC_TOTAKEKE, // K.K. Slider - SP_NPC_ANGLER, // Chip - SP_NPC_POLICE2, // Booker - SP_NPC_MAMEDANUKI0, // Timmy - SP_NPC_MAMEDANUKI1, // Tommy - SP_NPC_BROKER, // Redd - SP_NPC_MAJIN, // Resetti - SP_NPC_EV_DOZAEMON, // Gulliver - SP_NPC_STATION_MASTER, // Porter - SP_NPC_CURATOR, // Blathers - SP_NPC_SENDO, // Kapp'n - SP_NPC_NEEDLEWORK0, // Mable - SP_NPC_NEEDLEWORK1, // Sable - SP_NPC_EV_SONCHO, // Tortimer - SP_NPC_EV_GHOST, // Wisp - SP_NPC_MAJIN_BROTHER, // Don - SP_NPC_MASK_CAT, // Blanca - SP_NPC_TURKEY, // Franklin - SP_NPC_HEM, // Farley - }; + static mActor_name_t sp_npc_code_table[mMpswd_SPECIAL_NPC_NUM] = { + SP_NPC_SHOP_MASTER, // Tom Nook + SP_NPC_ARTIST, // Wendell + SP_NPC_CARPETPEDDLER, // Saharah + SP_NPC_DESIGNER, // Gracie + SP_NPC_KABUPEDDLER, // Joan + SP_NPC_GYPSY, // Katrina + SP_NPC_POLICE, // Copper + SP_NPC_HALLOWEEN, // Jack + SP_NPC_SANTA, // Jingle + SP_NPC_POST_MAN, // Pete + SP_NPC_POST_GIRL, // Pelly + SP_NPC_POST_GIRL2, // Phyllis + SP_NPC_GUIDE, // Rover + SP_NPC_TOTAKEKE, // K.K. Slider + SP_NPC_ANGLER, // Chip + SP_NPC_POLICE2, // Booker + SP_NPC_MAMEDANUKI0, // Timmy + SP_NPC_MAMEDANUKI1, // Tommy + SP_NPC_BROKER, // Redd + SP_NPC_MAJIN, // Resetti + SP_NPC_EV_DOZAEMON, // Gulliver + SP_NPC_STATION_MASTER, // Porter + SP_NPC_CURATOR, // Blathers + SP_NPC_SENDO, // Kapp'n + SP_NPC_NEEDLEWORK0, // Mable + SP_NPC_NEEDLEWORK1, // Sable + SP_NPC_EV_SONCHO, // Tortimer + SP_NPC_EV_GHOST, // Wisp + SP_NPC_MAJIN_BROTHER, // Don + SP_NPC_MASK_CAT, // Blanca + SP_NPC_TURKEY, // Franklin + SP_NPC_HEM, // Farley + }; - if (sp_npc < 0 || sp_npc >= mMpswd_SPECIAL_NPC_NUM) { - sp_npc = 0; - } + if (sp_npc < 0 || sp_npc >= mMpswd_SPECIAL_NPC_NUM) { + sp_npc = 0; + } - return sp_npc_code_table[sp_npc]; + return sp_npc_code_table[sp_npc]; } extern int mMpswd_check_npc_code(mMpswd_password_c* password) { - int res = FALSE; + int res = FALSE; - if ((password->npc_type == mMpswd_NPCTYPE_NORMAL && password->npc_code < NPC_NUM) || - (password->npc_type == mMpswd_NPCTYPE_SPECIAL && password->npc_code < mMpswd_SPECIAL_NPC_NUM) - ) { - res = TRUE; - } + if ((password->npc_type == mMpswd_NPCTYPE_NORMAL && password->npc_code < NPC_NUM) || + (password->npc_type == mMpswd_NPCTYPE_SPECIAL && password->npc_code < mMpswd_SPECIAL_NPC_NUM)) { + res = TRUE; + } - return res; + return res; } extern int mMpswd_check_name(mMpswd_password_c* password) { - int res = FALSE; - Private_c* priv_data = Common_Get(now_private); + int res = FALSE; + Private_c* priv_data = Common_Get(now_private); - if (mPr_CheckCmpPlayerName(password->str0, Common_Get(now_private)->player_ID.player_name) == TRUE) { - if (mLd_CheckCmpLandName(password->str1, Common_Get(now_private)->player_ID.land_name) == TRUE) { - res = TRUE; + if (mPr_CheckCmpPlayerName(password->str0, Common_Get(now_private)->player_ID.player_name) == TRUE) { + if (mLd_CheckCmpLandName(password->str1, Common_Get(now_private)->player_ID.land_name) == TRUE) { + res = TRUE; + } } - } - - return res; + + return res; } diff --git a/src/m_msg.c b/src/m_msg.c index ab48387b..07987f06 100644 --- a/src/m_msg.c +++ b/src/m_msg.c @@ -24,27 +24,28 @@ typedef void (*mMsg_MAIN_PROC)(mMsg_Window_c*, GAME*); #ifndef __INTELLISENSE__ /* Force assetrip to detect these assets. They're used in a .c_inc file. */ FORCESTRIP static u8 __unused_msg0[] = { - #include "assets/msg/con_kaiwa2_w1_tex.inc" +#include "assets/msg/con_kaiwa2_w1_tex.inc" }; FORCESTRIP static u8 __unused_msg1[] = { - #include "assets/msg/con_kaiwa2_w2_tex.inc" +#include "assets/msg/con_kaiwa2_w2_tex.inc" }; FORCESTRIP static u8 __unused_msg2[] = { - #include "assets/msg/con_kaiwa2_w3_tex.inc" +#include "assets/msg/con_kaiwa2_w3_tex.inc" }; FORCESTRIP static Vtx __unused_msg3[] = { - #include "assets/msg/con_kaiwa2_v.inc" +#include "assets/msg/con_kaiwa2_v.inc" }; FORCESTRIP static u8 __unused_msg4[] = { - #include "assets/msg/con_namefuti_TXT.inc" +#include "assets/msg/con_namefuti_TXT.inc" }; FORCESTRIP static Vtx __unused_msg5[] = { - #include "assets/msg/con_kaiwaname_v.inc" +#include "assets/msg/con_kaiwaname_v.inc" }; #endif #endif static void mMsg_MainSetup_Window(mMsg_Window_c* msg_p, GAME* game); +static int mMsg_end_to_disappear(mMsg_Window_c* msg_p); #include "../src/m_msg_ctrl.c_inc" @@ -67,100 +68,88 @@ static void mMsg_sound_MessageStatus(u8 status); #include "../src/m_msg_draw_font.c_inc" static void mMsg_MainSetup_Window(mMsg_Window_c* msg_p, GAME* game) { - static mMsg_MAIN_PROC proc[mMsg_INDEX_NUM] = { - &mMsg_MainSetup_Hide, - &mMsg_MainSetup_Appear, - &mMsg_MainSetup_Normal, - &mMsg_MainSetup_Cursol, - &mMsg_MainSetup_Disappear, - &mMsg_MainSetup_Appear_Wait, - &mMsg_MainSetup_Wait, - &mMsg_MainSetup_Disappear_wait - }; + static mMsg_MAIN_PROC proc[mMsg_INDEX_NUM] = { + &mMsg_MainSetup_Hide, &mMsg_MainSetup_Appear, &mMsg_MainSetup_Normal, &mMsg_MainSetup_Cursol, + &mMsg_MainSetup_Disappear, &mMsg_MainSetup_Appear_Wait, &mMsg_MainSetup_Wait, &mMsg_MainSetup_Disappear_wait, + }; - int idx = msg_p->requested_main_index; + int idx = msg_p->requested_main_index; - if (idx >= 0) { - if (idx >= mMsg_INDEX_NUM || proc[idx] == NULL) { - return; + if (idx >= 0) { + if (idx >= mMsg_INDEX_NUM || proc[idx] == NULL) { + return; + } + + (*proc[idx])(msg_p, game); } - - (*proc[idx])(msg_p, game); - } } static void mMsg_Main_Window(mMsg_Window_c* msg_p, GAME* game) { - static mMsg_MAIN_PROC proc[mMsg_INDEX_NUM] = { - &mMsg_Main_Hide, - &mMsg_Main_Appear, - &mMsg_Main_Normal, - &mMsg_Main_Cursol, - &mMsg_Main_Disappear, - &mMsg_Main_Appear_wait, - &mMsg_Main_Wait, - &mMsg_Main_Disappear_wait - }; + static mMsg_MAIN_PROC proc[mMsg_INDEX_NUM] = { + &mMsg_Main_Hide, &mMsg_Main_Appear, &mMsg_Main_Normal, &mMsg_Main_Cursol, + &mMsg_Main_Disappear, &mMsg_Main_Appear_wait, &mMsg_Main_Wait, &mMsg_Main_Disappear_wait, + }; - int idx = msg_p->main_index; + int idx = msg_p->main_index; - if (idx >= 0) { - if (idx >= mMsg_INDEX_NUM || proc[idx] == NULL) { - return; + if (idx >= 0) { + if (idx >= mMsg_INDEX_NUM || proc[idx] == NULL) { + return; + } + + (*proc[idx])(msg_p, game); } - - (*proc[idx])(msg_p, game); - } } static void mMsg_Draw_Window(mMsg_Window_c* msg_p, GAME* game) { - if (msg_p->draw_flag && msg_p->data_loaded) { - mFont_SetMatrix(game->graph, mFont_MODE_FONT); - mMsg_SetMatrix(msg_p, game, mFont_MODE_FONT); - mMsg_DrawWindowBody(msg_p, game, mFont_MODE_FONT); - mMsg_UnSetMatrix(); - mFont_UnSetMatrix(game->graph, mFont_MODE_FONT); + if (msg_p->draw_flag && msg_p->data_loaded) { + mFont_SetMatrix(game->graph, mFont_MODE_FONT); + mMsg_SetMatrix(msg_p, game, mFont_MODE_FONT); + mMsg_DrawWindowBody(msg_p, game, mFont_MODE_FONT); + mMsg_UnSetMatrix(); + mFont_UnSetMatrix(game->graph, mFont_MODE_FONT); - if (msg_p->msg_data->data_loaded) { - mMsg_draw_font(msg_p, game); + if (msg_p->msg_data->data_loaded) { + mMsg_draw_font(msg_p, game); + } + + mChoice_Draw(&msg_p->choice_window, game, mFont_MODE_FONT); } - - mChoice_Draw(&msg_p->choice_window, game, mFont_MODE_FONT); - } } extern void mMsg_aram_init() { - mChoice_aram_init(); - mString_aram_init(); - mHandbill_aram_init(); + mChoice_aram_init(); + mString_aram_init(); + mHandbill_aram_init(); } extern void mMsg_aram_init2() { - Msg_table_rom_start = JW_GetAramAddress(RESOURCE_MESSAGE_TABLE); - Msg_rom_start = JW_GetAramAddress(RESOURCE_MESSAGE); + Msg_table_rom_start = JW_GetAramAddress(RESOURCE_MESSAGE_TABLE); + Msg_rom_start = JW_GetAramAddress(RESOURCE_MESSAGE); } extern void mMsg_ct(GAME* game) { - mMsg_init(game); - mChoice_ct(&mMsg_window.choice_window, game); + mMsg_init(game); + mChoice_ct(&mMsg_window.choice_window, game); } extern void mMsg_dt(GAME* game) { - mChoice_dt(&mMsg_window.choice_window, game); + mChoice_dt(&mMsg_window.choice_window, game); } extern void mMsg_debug_draw(gfxprint_t* gfxprint) { - if (mMsg_window.msg_data != NULL) { - gfxprint_color(gfxprint, 245, 255, 250, 255); - gfxprint_locate8x8(gfxprint, 3, 6); - gfxprint_printf(gfxprint, "%5d", mMsg_window.msg_data->msg_no); - } + if (mMsg_window.msg_data != NULL) { + gfxprint_color(gfxprint, 245, 255, 250, 255); + gfxprint_locate8x8(gfxprint, 3, 6); + gfxprint_printf(gfxprint, "%5d", mMsg_window.msg_data->msg_no); + } } extern void mMsg_Main(GAME* game) { - mMsg_Main_Window(&mMsg_window, game); - mChoice_Main(&mMsg_window.choice_window, game); + mMsg_Main_Window(&mMsg_window, game); + mChoice_Main(&mMsg_window.choice_window, game); } extern void mMsg_Draw(GAME* game) { - mMsg_Draw_Window(&mMsg_window, game); + mMsg_Draw_Window(&mMsg_window, game); } diff --git a/src/m_name_table.c b/src/m_name_table.c index ed5e964a..ec73b22d 100644 --- a/src/m_name_table.c +++ b/src/m_name_table.c @@ -5,1085 +5,430 @@ #include "m_common_data.h" s16 move_obj_profile_table[] = { - mAc_PROFILE_AIRPLANE, - mAc_PROFILE_BALL, - mAc_PROFILE_MY_ROOM, - mAc_PROFILE_MBG, - mAc_PROFILE_BOXMANAGER, - mAc_PROFILE_BOXTRICK01, - mAc_PROFILE_ARRANGE_ROOM, - mAc_PROFILE_ARRANGE_FURNITURE, - mAc_PROFILE_EFFECT_CONTROL, - mAc_PROFILE_SHOP_DESIGN, - mAc_PROFILE_SHOP_MANEKIN, - mAc_PROFILE_SHOP_INDOOR, - mAc_PROFILE_SHOP_GOODS, - mAc_PROFILE_SNOWMAN, - mAc_PROFILE_SNOWMAN, - mAc_PROFILE_BROKER_DESIGN, - mAc_PROFILE_MY_INDOOR, - mAc_PROFILE_TRAIN_WINDOW, - mAc_PROFILE_UKI, - mAc_PROFILE_SHOP_UMBRELLA, - mAc_PROFILE_KAMAKURA_INDOOR, - mAc_PROFILE_HOUSE_CLOCK + mAc_PROFILE_AIRPLANE, mAc_PROFILE_BALL, mAc_PROFILE_MY_ROOM, mAc_PROFILE_MBG, + mAc_PROFILE_BOXMANAGER, mAc_PROFILE_BOXTRICK01, mAc_PROFILE_ARRANGE_ROOM, mAc_PROFILE_ARRANGE_FURNITURE, + mAc_PROFILE_EFFECT_CONTROL, mAc_PROFILE_SHOP_DESIGN, mAc_PROFILE_SHOP_MANEKIN, mAc_PROFILE_SHOP_INDOOR, + mAc_PROFILE_SHOP_GOODS, mAc_PROFILE_SNOWMAN, mAc_PROFILE_SNOWMAN, mAc_PROFILE_BROKER_DESIGN, + mAc_PROFILE_MY_INDOOR, mAc_PROFILE_TRAIN_WINDOW, mAc_PROFILE_UKI, mAc_PROFILE_SHOP_UMBRELLA, + mAc_PROFILE_KAMAKURA_INDOOR, mAc_PROFILE_HOUSE_CLOCK }; -s16 actor_profile_table[] = { - mAc_PROFILE_SAMPLE -}; +s16 actor_profile_table[] = { mAc_PROFILE_SAMPLE }; s16 props_profile_table[] = { - mAc_PROFILE_MAILBOX, - mAc_PROFILE_MAILBOX, - mAc_PROFILE_MAILBOX, - mAc_PROFILE_MAILBOX, - mAc_PROFILE_HANIWA, - mAc_PROFILE_HANIWA, - mAc_PROFILE_HANIWA, - mAc_PROFILE_HANIWA, - mAc_PROFILE_PSNOWMAN, - mAc_PROFILE_PSNOWMAN, - mAc_PROFILE_PSNOWMAN, - mAc_PROFILE_PSNOWMAN, - mAc_PROFILE_PSNOWMAN, - mAc_PROFILE_PSNOWMAN, - mAc_PROFILE_PSNOWMAN, - mAc_PROFILE_PSNOWMAN, - mAc_PROFILE_PSNOWMAN, - mAc_PROFILE_TRAINDOOR, - mAc_PROFILE_NAMEPLATE + mAc_PROFILE_MAILBOX, mAc_PROFILE_MAILBOX, mAc_PROFILE_MAILBOX, mAc_PROFILE_MAILBOX, mAc_PROFILE_HANIWA, + mAc_PROFILE_HANIWA, mAc_PROFILE_HANIWA, mAc_PROFILE_HANIWA, mAc_PROFILE_PSNOWMAN, mAc_PROFILE_PSNOWMAN, + mAc_PROFILE_PSNOWMAN, mAc_PROFILE_PSNOWMAN, mAc_PROFILE_PSNOWMAN, mAc_PROFILE_PSNOWMAN, mAc_PROFILE_PSNOWMAN, + mAc_PROFILE_PSNOWMAN, mAc_PROFILE_PSNOWMAN, mAc_PROFILE_TRAINDOOR, mAc_PROFILE_NAMEPLATE, }; u8 npc_looks_table[NPC_NUM + 2] = { - mNpc_LOOKS_BOY, - mNpc_LOOKS_NANIWA_LADY, - mNpc_LOOKS_GIRL, - mNpc_LOOKS_GIRL, - mNpc_LOOKS_KO_GIRL, - mNpc_LOOKS_GRIM_MAN, - mNpc_LOOKS_KO_GIRL, - mNpc_LOOKS_NANIWA_LADY, - mNpc_LOOKS_SPORT_MAN, - mNpc_LOOKS_NANIWA_LADY, - mNpc_LOOKS_NANIWA_LADY, - mNpc_LOOKS_GRIM_MAN, - mNpc_LOOKS_KO_GIRL, - mNpc_LOOKS_GIRL, - mNpc_LOOKS_GIRL, - mNpc_LOOKS_KO_GIRL, - mNpc_LOOKS_GRIM_MAN, - mNpc_LOOKS_NANIWA_LADY, - mNpc_LOOKS_SPORT_MAN, - mNpc_LOOKS_GRIM_MAN, - mNpc_LOOKS_BOY, - mNpc_LOOKS_BOY, - mNpc_LOOKS_GRIM_MAN, - mNpc_LOOKS_KO_GIRL, - mNpc_LOOKS_NANIWA_LADY, - mNpc_LOOKS_GRIM_MAN, - mNpc_LOOKS_KO_GIRL, - mNpc_LOOKS_SPORT_MAN, - mNpc_LOOKS_KO_GIRL, - mNpc_LOOKS_BOY, - mNpc_LOOKS_KO_GIRL, - mNpc_LOOKS_GRIM_MAN, - mNpc_LOOKS_BOY, - mNpc_LOOKS_NANIWA_LADY, - mNpc_LOOKS_GIRL, - mNpc_LOOKS_SPORT_MAN, - mNpc_LOOKS_GRIM_MAN, - mNpc_LOOKS_GRIM_MAN, - mNpc_LOOKS_BOY, - mNpc_LOOKS_SPORT_MAN, - mNpc_LOOKS_GIRL, - mNpc_LOOKS_SPORT_MAN, - mNpc_LOOKS_BOY, - mNpc_LOOKS_GIRL, - mNpc_LOOKS_SPORT_MAN, - mNpc_LOOKS_KO_GIRL, - mNpc_LOOKS_NANIWA_LADY, - mNpc_LOOKS_GRIM_MAN, - mNpc_LOOKS_GRIM_MAN, - mNpc_LOOKS_NANIWA_LADY, - mNpc_LOOKS_SPORT_MAN, - mNpc_LOOKS_GIRL, - mNpc_LOOKS_BOY, - mNpc_LOOKS_GIRL, - mNpc_LOOKS_SPORT_MAN, - mNpc_LOOKS_KO_GIRL, - mNpc_LOOKS_KO_GIRL, - mNpc_LOOKS_NANIWA_LADY, - mNpc_LOOKS_GIRL, - mNpc_LOOKS_KO_GIRL, - mNpc_LOOKS_BOY, - mNpc_LOOKS_SPORT_MAN, - mNpc_LOOKS_GIRL, - mNpc_LOOKS_BOY, - mNpc_LOOKS_GIRL, - mNpc_LOOKS_GIRL, - mNpc_LOOKS_BOY, - mNpc_LOOKS_NANIWA_LADY, - mNpc_LOOKS_KO_GIRL, - mNpc_LOOKS_GRIM_MAN, - mNpc_LOOKS_SPORT_MAN, - mNpc_LOOKS_KO_GIRL, - mNpc_LOOKS_BOY, - mNpc_LOOKS_SPORT_MAN, - mNpc_LOOKS_BOY, - mNpc_LOOKS_KO_GIRL, - mNpc_LOOKS_BOY, - mNpc_LOOKS_BOY, - mNpc_LOOKS_SPORT_MAN, - mNpc_LOOKS_GIRL, - mNpc_LOOKS_SPORT_MAN, - mNpc_LOOKS_GRIM_MAN, - mNpc_LOOKS_SPORT_MAN, - mNpc_LOOKS_KO_GIRL, - mNpc_LOOKS_GIRL, - mNpc_LOOKS_BOY, - mNpc_LOOKS_BOY, - mNpc_LOOKS_GRIM_MAN, - mNpc_LOOKS_SPORT_MAN, - mNpc_LOOKS_BOY, - mNpc_LOOKS_GIRL, - mNpc_LOOKS_SPORT_MAN, - mNpc_LOOKS_GIRL, - mNpc_LOOKS_SPORT_MAN, - mNpc_LOOKS_GRIM_MAN, - mNpc_LOOKS_BOY, - mNpc_LOOKS_NANIWA_LADY, - mNpc_LOOKS_NANIWA_LADY, - mNpc_LOOKS_GRIM_MAN, - mNpc_LOOKS_SPORT_MAN, - mNpc_LOOKS_GRIM_MAN, - mNpc_LOOKS_BOY, - mNpc_LOOKS_KO_GIRL, - mNpc_LOOKS_GIRL, - mNpc_LOOKS_BOY, - mNpc_LOOKS_KO_GIRL, - mNpc_LOOKS_GIRL, - mNpc_LOOKS_SPORT_MAN, - mNpc_LOOKS_NANIWA_LADY, - mNpc_LOOKS_GIRL, - mNpc_LOOKS_SPORT_MAN, - mNpc_LOOKS_GIRL, - mNpc_LOOKS_NANIWA_LADY, - mNpc_LOOKS_KO_GIRL, - mNpc_LOOKS_GIRL, - mNpc_LOOKS_NANIWA_LADY, - mNpc_LOOKS_NANIWA_LADY, - mNpc_LOOKS_GIRL, - mNpc_LOOKS_GRIM_MAN, - mNpc_LOOKS_BOY, - mNpc_LOOKS_NANIWA_LADY, - mNpc_LOOKS_KO_GIRL, - mNpc_LOOKS_BOY, - mNpc_LOOKS_SPORT_MAN, - mNpc_LOOKS_SPORT_MAN, - mNpc_LOOKS_SPORT_MAN, - mNpc_LOOKS_KO_GIRL, - mNpc_LOOKS_GIRL, - mNpc_LOOKS_BOY, - mNpc_LOOKS_KO_GIRL, - mNpc_LOOKS_GRIM_MAN, - mNpc_LOOKS_KO_GIRL, - mNpc_LOOKS_GRIM_MAN, - mNpc_LOOKS_NANIWA_LADY, - mNpc_LOOKS_GRIM_MAN, - mNpc_LOOKS_GIRL, - mNpc_LOOKS_SPORT_MAN, - mNpc_LOOKS_KO_GIRL, - mNpc_LOOKS_NANIWA_LADY, - mNpc_LOOKS_GRIM_MAN, - mNpc_LOOKS_GRIM_MAN, - mNpc_LOOKS_SPORT_MAN, - mNpc_LOOKS_NANIWA_LADY, - mNpc_LOOKS_SPORT_MAN, - mNpc_LOOKS_SPORT_MAN, - mNpc_LOOKS_GIRL, - mNpc_LOOKS_GRIM_MAN, - mNpc_LOOKS_BOY, - mNpc_LOOKS_BOY, - mNpc_LOOKS_NANIWA_LADY, - mNpc_LOOKS_NANIWA_LADY, - mNpc_LOOKS_SPORT_MAN, - mNpc_LOOKS_KO_GIRL, - mNpc_LOOKS_BOY, - mNpc_LOOKS_BOY, - mNpc_LOOKS_GRIM_MAN, - mNpc_LOOKS_NANIWA_LADY, - mNpc_LOOKS_SPORT_MAN, - mNpc_LOOKS_GIRL, - mNpc_LOOKS_SPORT_MAN, - mNpc_LOOKS_GRIM_MAN, - mNpc_LOOKS_KO_GIRL, - mNpc_LOOKS_BOY, - mNpc_LOOKS_GRIM_MAN, - mNpc_LOOKS_GIRL, - mNpc_LOOKS_KO_GIRL, - mNpc_LOOKS_KO_GIRL, - mNpc_LOOKS_SPORT_MAN, - mNpc_LOOKS_SPORT_MAN, - mNpc_LOOKS_BOY, - mNpc_LOOKS_SPORT_MAN, - mNpc_LOOKS_GRIM_MAN, - mNpc_LOOKS_NANIWA_LADY, - mNpc_LOOKS_GIRL, - mNpc_LOOKS_BOY, - mNpc_LOOKS_GIRL, - mNpc_LOOKS_KO_GIRL, - mNpc_LOOKS_NANIWA_LADY, - mNpc_LOOKS_GRIM_MAN, - mNpc_LOOKS_GRIM_MAN, - mNpc_LOOKS_NANIWA_LADY, - mNpc_LOOKS_KO_GIRL, - mNpc_LOOKS_SPORT_MAN, - mNpc_LOOKS_GRIM_MAN, - mNpc_LOOKS_KO_GIRL, - mNpc_LOOKS_GRIM_MAN, - mNpc_LOOKS_NANIWA_LADY, - mNpc_LOOKS_GRIM_MAN, - mNpc_LOOKS_BOY, - mNpc_LOOKS_NANIWA_LADY, - mNpc_LOOKS_GRIM_MAN, - mNpc_LOOKS_BOY, - mNpc_LOOKS_GRIM_MAN, - mNpc_LOOKS_BOY, - mNpc_LOOKS_SPORT_MAN, - mNpc_LOOKS_NANIWA_LADY, - mNpc_LOOKS_BOY, - mNpc_LOOKS_GIRL, - mNpc_LOOKS_NANIWA_LADY, - mNpc_LOOKS_GRIM_MAN, - mNpc_LOOKS_KO_GIRL, - mNpc_LOOKS_NANIWA_LADY, - mNpc_LOOKS_GIRL, - mNpc_LOOKS_GIRL, - mNpc_LOOKS_NANIWA_LADY, - mNpc_LOOKS_NANIWA_LADY, - mNpc_LOOKS_KO_GIRL, - mNpc_LOOKS_GIRL, - mNpc_LOOKS_NANIWA_LADY, - mNpc_LOOKS_GRIM_MAN, - mNpc_LOOKS_GIRL, - mNpc_LOOKS_KO_GIRL, - mNpc_LOOKS_GIRL, - mNpc_LOOKS_NANIWA_LADY, - mNpc_LOOKS_SPORT_MAN, - mNpc_LOOKS_KO_GIRL, - mNpc_LOOKS_NANIWA_LADY, - mNpc_LOOKS_GRIM_MAN, - mNpc_LOOKS_GIRL, - mNpc_LOOKS_SPORT_MAN, - mNpc_LOOKS_SPORT_MAN, - mNpc_LOOKS_BOY, - mNpc_LOOKS_KO_GIRL, - mNpc_LOOKS_GRIM_MAN, - mNpc_LOOKS_BOY, - mNpc_LOOKS_KO_GIRL, - mNpc_LOOKS_NANIWA_LADY, - mNpc_LOOKS_KO_GIRL, - mNpc_LOOKS_GIRL, - mNpc_LOOKS_BOY, - mNpc_LOOKS_GRIM_MAN, - mNpc_LOOKS_GIRL, - mNpc_LOOKS_KO_GIRL, - mNpc_LOOKS_SPORT_MAN, - mNpc_LOOKS_NANIWA_LADY, - mNpc_LOOKS_BOY, - mNpc_LOOKS_BOY, - mNpc_LOOKS_KO_GIRL + mNpc_LOOKS_BOY, mNpc_LOOKS_NANIWA_LADY, mNpc_LOOKS_GIRL, mNpc_LOOKS_GIRL, + mNpc_LOOKS_KO_GIRL, mNpc_LOOKS_GRIM_MAN, mNpc_LOOKS_KO_GIRL, mNpc_LOOKS_NANIWA_LADY, + mNpc_LOOKS_SPORT_MAN, mNpc_LOOKS_NANIWA_LADY, mNpc_LOOKS_NANIWA_LADY, mNpc_LOOKS_GRIM_MAN, + mNpc_LOOKS_KO_GIRL, mNpc_LOOKS_GIRL, mNpc_LOOKS_GIRL, mNpc_LOOKS_KO_GIRL, + mNpc_LOOKS_GRIM_MAN, mNpc_LOOKS_NANIWA_LADY, mNpc_LOOKS_SPORT_MAN, mNpc_LOOKS_GRIM_MAN, + mNpc_LOOKS_BOY, mNpc_LOOKS_BOY, mNpc_LOOKS_GRIM_MAN, mNpc_LOOKS_KO_GIRL, + mNpc_LOOKS_NANIWA_LADY, mNpc_LOOKS_GRIM_MAN, mNpc_LOOKS_KO_GIRL, mNpc_LOOKS_SPORT_MAN, + mNpc_LOOKS_KO_GIRL, mNpc_LOOKS_BOY, mNpc_LOOKS_KO_GIRL, mNpc_LOOKS_GRIM_MAN, + mNpc_LOOKS_BOY, mNpc_LOOKS_NANIWA_LADY, mNpc_LOOKS_GIRL, mNpc_LOOKS_SPORT_MAN, + mNpc_LOOKS_GRIM_MAN, mNpc_LOOKS_GRIM_MAN, mNpc_LOOKS_BOY, mNpc_LOOKS_SPORT_MAN, + mNpc_LOOKS_GIRL, mNpc_LOOKS_SPORT_MAN, mNpc_LOOKS_BOY, mNpc_LOOKS_GIRL, + mNpc_LOOKS_SPORT_MAN, mNpc_LOOKS_KO_GIRL, mNpc_LOOKS_NANIWA_LADY, mNpc_LOOKS_GRIM_MAN, + mNpc_LOOKS_GRIM_MAN, mNpc_LOOKS_NANIWA_LADY, mNpc_LOOKS_SPORT_MAN, mNpc_LOOKS_GIRL, + mNpc_LOOKS_BOY, mNpc_LOOKS_GIRL, mNpc_LOOKS_SPORT_MAN, mNpc_LOOKS_KO_GIRL, + mNpc_LOOKS_KO_GIRL, mNpc_LOOKS_NANIWA_LADY, mNpc_LOOKS_GIRL, mNpc_LOOKS_KO_GIRL, + mNpc_LOOKS_BOY, mNpc_LOOKS_SPORT_MAN, mNpc_LOOKS_GIRL, mNpc_LOOKS_BOY, + mNpc_LOOKS_GIRL, mNpc_LOOKS_GIRL, mNpc_LOOKS_BOY, mNpc_LOOKS_NANIWA_LADY, + mNpc_LOOKS_KO_GIRL, mNpc_LOOKS_GRIM_MAN, mNpc_LOOKS_SPORT_MAN, mNpc_LOOKS_KO_GIRL, + mNpc_LOOKS_BOY, mNpc_LOOKS_SPORT_MAN, mNpc_LOOKS_BOY, mNpc_LOOKS_KO_GIRL, + mNpc_LOOKS_BOY, mNpc_LOOKS_BOY, mNpc_LOOKS_SPORT_MAN, mNpc_LOOKS_GIRL, + mNpc_LOOKS_SPORT_MAN, mNpc_LOOKS_GRIM_MAN, mNpc_LOOKS_SPORT_MAN, mNpc_LOOKS_KO_GIRL, + mNpc_LOOKS_GIRL, mNpc_LOOKS_BOY, mNpc_LOOKS_BOY, mNpc_LOOKS_GRIM_MAN, + mNpc_LOOKS_SPORT_MAN, mNpc_LOOKS_BOY, mNpc_LOOKS_GIRL, mNpc_LOOKS_SPORT_MAN, + mNpc_LOOKS_GIRL, mNpc_LOOKS_SPORT_MAN, mNpc_LOOKS_GRIM_MAN, mNpc_LOOKS_BOY, + mNpc_LOOKS_NANIWA_LADY, mNpc_LOOKS_NANIWA_LADY, mNpc_LOOKS_GRIM_MAN, mNpc_LOOKS_SPORT_MAN, + mNpc_LOOKS_GRIM_MAN, mNpc_LOOKS_BOY, mNpc_LOOKS_KO_GIRL, mNpc_LOOKS_GIRL, + mNpc_LOOKS_BOY, mNpc_LOOKS_KO_GIRL, mNpc_LOOKS_GIRL, mNpc_LOOKS_SPORT_MAN, + mNpc_LOOKS_NANIWA_LADY, mNpc_LOOKS_GIRL, mNpc_LOOKS_SPORT_MAN, mNpc_LOOKS_GIRL, + mNpc_LOOKS_NANIWA_LADY, mNpc_LOOKS_KO_GIRL, mNpc_LOOKS_GIRL, mNpc_LOOKS_NANIWA_LADY, + mNpc_LOOKS_NANIWA_LADY, mNpc_LOOKS_GIRL, mNpc_LOOKS_GRIM_MAN, mNpc_LOOKS_BOY, + mNpc_LOOKS_NANIWA_LADY, mNpc_LOOKS_KO_GIRL, mNpc_LOOKS_BOY, mNpc_LOOKS_SPORT_MAN, + mNpc_LOOKS_SPORT_MAN, mNpc_LOOKS_SPORT_MAN, mNpc_LOOKS_KO_GIRL, mNpc_LOOKS_GIRL, + mNpc_LOOKS_BOY, mNpc_LOOKS_KO_GIRL, mNpc_LOOKS_GRIM_MAN, mNpc_LOOKS_KO_GIRL, + mNpc_LOOKS_GRIM_MAN, mNpc_LOOKS_NANIWA_LADY, mNpc_LOOKS_GRIM_MAN, mNpc_LOOKS_GIRL, + mNpc_LOOKS_SPORT_MAN, mNpc_LOOKS_KO_GIRL, mNpc_LOOKS_NANIWA_LADY, mNpc_LOOKS_GRIM_MAN, + mNpc_LOOKS_GRIM_MAN, mNpc_LOOKS_SPORT_MAN, mNpc_LOOKS_NANIWA_LADY, mNpc_LOOKS_SPORT_MAN, + mNpc_LOOKS_SPORT_MAN, mNpc_LOOKS_GIRL, mNpc_LOOKS_GRIM_MAN, mNpc_LOOKS_BOY, + mNpc_LOOKS_BOY, mNpc_LOOKS_NANIWA_LADY, mNpc_LOOKS_NANIWA_LADY, mNpc_LOOKS_SPORT_MAN, + mNpc_LOOKS_KO_GIRL, mNpc_LOOKS_BOY, mNpc_LOOKS_BOY, mNpc_LOOKS_GRIM_MAN, + mNpc_LOOKS_NANIWA_LADY, mNpc_LOOKS_SPORT_MAN, mNpc_LOOKS_GIRL, mNpc_LOOKS_SPORT_MAN, + mNpc_LOOKS_GRIM_MAN, mNpc_LOOKS_KO_GIRL, mNpc_LOOKS_BOY, mNpc_LOOKS_GRIM_MAN, + mNpc_LOOKS_GIRL, mNpc_LOOKS_KO_GIRL, mNpc_LOOKS_KO_GIRL, mNpc_LOOKS_SPORT_MAN, + mNpc_LOOKS_SPORT_MAN, mNpc_LOOKS_BOY, mNpc_LOOKS_SPORT_MAN, mNpc_LOOKS_GRIM_MAN, + mNpc_LOOKS_NANIWA_LADY, mNpc_LOOKS_GIRL, mNpc_LOOKS_BOY, mNpc_LOOKS_GIRL, + mNpc_LOOKS_KO_GIRL, mNpc_LOOKS_NANIWA_LADY, mNpc_LOOKS_GRIM_MAN, mNpc_LOOKS_GRIM_MAN, + mNpc_LOOKS_NANIWA_LADY, mNpc_LOOKS_KO_GIRL, mNpc_LOOKS_SPORT_MAN, mNpc_LOOKS_GRIM_MAN, + mNpc_LOOKS_KO_GIRL, mNpc_LOOKS_GRIM_MAN, mNpc_LOOKS_NANIWA_LADY, mNpc_LOOKS_GRIM_MAN, + mNpc_LOOKS_BOY, mNpc_LOOKS_NANIWA_LADY, mNpc_LOOKS_GRIM_MAN, mNpc_LOOKS_BOY, + mNpc_LOOKS_GRIM_MAN, mNpc_LOOKS_BOY, mNpc_LOOKS_SPORT_MAN, mNpc_LOOKS_NANIWA_LADY, + mNpc_LOOKS_BOY, mNpc_LOOKS_GIRL, mNpc_LOOKS_NANIWA_LADY, mNpc_LOOKS_GRIM_MAN, + mNpc_LOOKS_KO_GIRL, mNpc_LOOKS_NANIWA_LADY, mNpc_LOOKS_GIRL, mNpc_LOOKS_GIRL, + mNpc_LOOKS_NANIWA_LADY, mNpc_LOOKS_NANIWA_LADY, mNpc_LOOKS_KO_GIRL, mNpc_LOOKS_GIRL, + mNpc_LOOKS_NANIWA_LADY, mNpc_LOOKS_GRIM_MAN, mNpc_LOOKS_GIRL, mNpc_LOOKS_KO_GIRL, + mNpc_LOOKS_GIRL, mNpc_LOOKS_NANIWA_LADY, mNpc_LOOKS_SPORT_MAN, mNpc_LOOKS_KO_GIRL, + mNpc_LOOKS_NANIWA_LADY, mNpc_LOOKS_GRIM_MAN, mNpc_LOOKS_GIRL, mNpc_LOOKS_SPORT_MAN, + mNpc_LOOKS_SPORT_MAN, mNpc_LOOKS_BOY, mNpc_LOOKS_KO_GIRL, mNpc_LOOKS_GRIM_MAN, + mNpc_LOOKS_BOY, mNpc_LOOKS_KO_GIRL, mNpc_LOOKS_NANIWA_LADY, mNpc_LOOKS_KO_GIRL, + mNpc_LOOKS_GIRL, mNpc_LOOKS_BOY, mNpc_LOOKS_GRIM_MAN, mNpc_LOOKS_GIRL, + mNpc_LOOKS_KO_GIRL, mNpc_LOOKS_SPORT_MAN, mNpc_LOOKS_NANIWA_LADY, mNpc_LOOKS_BOY, + mNpc_LOOKS_BOY, mNpc_LOOKS_KO_GIRL }; static u8 item1_0_tableNo[] = { - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44, - 44, 44, 44, 44 + 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, + 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, + 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, + 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, + 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, + 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, + 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, + 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, + 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, }; -static u8 item1_1_tableNo[] = { - 9, 9, 9, 9 -}; +static u8 item1_1_tableNo[] = { 9, 9, 9, 9 }; static u8 item1_2_tableNo[] = { - 34, 33, 36, 35, - 41, 41, 41, 41, - 41, 41, 41, 41, - 41, 41, 41, 41, - 41, 41, 41, 41, - 41, 41, 41, 41, - 41, 41, 41, 41, - 41, 41, 41, 41, - 41, 41, 41, 41, - 41, 41, 41, 41, - 41, 41, 41, 41, - 19, 19, 19, 19, - 19, 19, 19, 19, - 19, 19, 19, 19, - 19, 38, 37, 40, - 39, 33, 33, 33, - 33, 33, 33, 33, - 19, 19, 19, 19, - 19, 19, 19, 19, - 42, 42, 42, 42, - 42, 42, 42, 42, - 43, 43, 43, 43, - 43, 43, 43, 43 + 34, 33, 36, 35, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, + 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 19, 19, + 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 38, 37, 40, 39, 33, 33, 33, 33, 33, 33, 33, 19, + 19, 19, 19, 19, 19, 19, 19, 42, 42, 42, 42, 42, 42, 42, 42, 43, 43, 43, 43, 43, 43, 43, 43, }; static u8 item1_3_tableNo[] = { - 8, 8, 8, 8, - 8, 8, 8, 8, - 8, 8, 8, 8, - 8, 8, 8, 8, - 8, 8, 8, 8, - 8, 8, 8, 8, - 8, 8, 8, 8, - 8, 8, 8, 8, - 8, 8, 8, 8, - 8, 8, 8, 8 + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, }; static u8 item1_4_tableNo[] = { - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30, 30, - 30, 30, 30 + 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, + 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, + 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, + 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, + 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, + 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, + 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, + 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, + 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, }; static u8 item1_5_tableNo[] = { - 22, 13, 13, 13, - 13, 13, 13, 13, - 13, 13, 13, 13, - 13, 9, 21, 21, - 21, 20, 23, 29, - 25, 24, 24, 24, - 25, 25, 24, 26, - 14, 11, 19, 14, - 14, 14, 14, 47, - 47, 47, 47, 47, - 47, 47, 47, 47, - 47, 47, 47, 47, - 52 + 22, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 9, 21, 21, 21, 20, 23, 29, 25, 24, 24, 24, 25, + 25, 24, 26, 14, 11, 19, 14, 14, 14, 14, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 52, }; static u8 item1_6_tableNo[] = { - 31, 31, 31, 31, - 31, 31, 31, 31, - 31, 31, 31, 31, - 31, 31, 31, 31, - 31, 31, 31, 31, - 31, 31, 31, 31, - 31, 31, 31, 31, - 31, 31, 31, 31, - 31, 31, 31, 31, - 31, 31, 31, 31, - 31, 31, 31, 31, - 31, 31, 31, 31, - 31, 31, 31, 31, - 31, 31, 31, 31, - 31, 31, 31, 31, - 31, 31, 31, 31, - 31, 31, 31 + 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, + 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, + 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, }; static u8 item1_7_tableNo[] = { - 32, 32, 32, 32, - 32, 32, 32, 32, - 32, 32, 32, 32, - 32, 32, 32, 32, - 32, 32, 32, 32, - 32, 32, 32, 32, - 32, 32, 32, 32, - 32, 32, 32, 32, - 32, 32, 32, 32, - 32, 32, 32, 32, - 32, 32, 32, 32, - 32, 32, 32, 32, - 32, 32, 32, 32, - 32, 32, 32, 32, - 32, 32, 32, 32, - 32, 32, 32, 32, - 32, 32, 32 + 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, + 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, + 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, }; -static u8 item1_8_tableNo[] = { - 1, 5, 4, 3, - 2, 6, 27, 28 -}; +static u8 item1_8_tableNo[] = { 1, 5, 4, 3, 2, 6, 27, 28 }; -static u8 item1_9_tableNo[] = { - 17, 17, 45, 45, - 45, 45, 45, 45, - 45, 45, 45 -}; +static u8 item1_9_tableNo[] = { 17, 17, 45, 45, 45, 45, 45, 45, 45, 45, 45 }; static u8 item1_A_tableNo[] = { - 48, 48, 48, 48, - 48, 48, 48, 48, - 48, 48, 48, 48, - 48, 48, 48, 48, - 48, 48, 48, 48, - 48, 48, 48, 48, - 48, 48, 48, 48, - 48, 48, 48, 48, - 48, 48, 48, 48, - 48, 48, 48, 48, - 48, 48, 48, 48, - 48, 48, 48, 48, - 48, 48, 48, 48, - 48, 48, 48 + 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, + 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, }; // ?? Shouldn't these be different from saplings? -static u8 item1_B_tableNo[] = { - 17, 17, 17, 17, - 17, 17, 17, 17, - 17, 17, 17, 17, - 17, 17, 17, 17 -}; +static u8 item1_B_tableNo[] = { 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17 }; static u8 item1_C_tableNo[] = { - 49, 49, 49, 49, - 49, 49, 49, 49, - 49, 49, 49, 49, - 49, 49, 49, 49, - 49, 49, 49, 49, - 49, 49, 49, 49, - 49, 49, 49, 49, - 49, 49, 49, 49, - 49, 49, 49, 49, - 49, 49, 49, 49, - 49, 49, 49, 49, - 49, 49, 49, 49, - 49, 49, 49, 49, - 49, 49, 49, 49, - 49, 49, 49, 49, - 49, 49, 49, 49, - 49, 49, 49, 49, - 49, 49, 49, 49, - 49, 49, 49, 49, - 49, 49, 49, 49, - 49, 49, 49, 49, - 49, 49, 49, 49, - 49, 49, 49, 49, - 49, 49, 49, 49 + 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, + 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, + 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, + 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, }; static u8 item1_D_tableNo[] = { - 18, 18, 18, 18, - 18, 18, 18, 18, - 18, 18, 18, 18, - 18, 18, 18, 18, - 18, 18, 18, 18, - 18, 18, 18, 18, - 18, 18, 18, 18, - 18, 18, 18, 18, - 18, 18, 18, 18, - 18, 18, 18, 18, - 18, 18, 18, 18, - 18 + 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, + 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, }; -static u8 item1_E_tableNo[] = { - 46, 46 -}; +static u8 item1_E_tableNo[] = { 46, 46 }; -static u8 item1_F_tableNo[] = { - 7, 7, 7, 7 -}; +static u8 item1_F_tableNo[] = { 7, 7, 7, 7 }; extern int mNT_get_itemTableNo(mActor_name_t item) { - static u8* item1_tableNo[ITEM1_CAT_NUM] = { - item1_0_tableNo, - item1_1_tableNo, - item1_2_tableNo, - item1_3_tableNo, - item1_4_tableNo, - item1_5_tableNo, - item1_6_tableNo, - item1_7_tableNo, - item1_8_tableNo, - item1_9_tableNo, - item1_A_tableNo, - item1_B_tableNo, - item1_C_tableNo, - item1_D_tableNo, - item1_E_tableNo, - item1_F_tableNo - }; + static u8* item1_tableNo[ITEM1_CAT_NUM] = { item1_0_tableNo, item1_1_tableNo, item1_2_tableNo, item1_3_tableNo, + item1_4_tableNo, item1_5_tableNo, item1_6_tableNo, item1_7_tableNo, + item1_8_tableNo, item1_9_tableNo, item1_A_tableNo, item1_B_tableNo, + item1_C_tableNo, item1_D_tableNo, item1_E_tableNo, item1_F_tableNo }; - switch (ITEM_NAME_GET_TYPE(item)) { - case NAME_TYPE_FTR0: - case NAME_TYPE_FTR1: - { - if (item >= FTR_DINO_START && item <= FTR_DINO_END) { - return mNT_ITEM_TYPE_BONE; - } - else if (item >= HANIWA_START && item <= HANIWA_END) { - return mNT_ITEM_TYPE_HANIWA; - } - else if (item >= ITM_DIARY_START && item <= ITM_DIARY15) { - return mNT_ITEM_TYPE_DIARY; - } + switch (ITEM_NAME_GET_TYPE(item)) { + case NAME_TYPE_FTR0: + case NAME_TYPE_FTR1: { + if (item >= FTR_DINO_START && item <= FTR_DINO_END) { + return mNT_ITEM_TYPE_BONE; + } else if (item >= HANIWA_START && item <= HANIWA_END) { + return mNT_ITEM_TYPE_HANIWA; + } else if (item >= ITM_DIARY_START && item <= ITM_DIARY15) { + return mNT_ITEM_TYPE_DIARY; + } - return mNT_ITEM_TYPE_LEAF; + return mNT_ITEM_TYPE_LEAF; + } + + case NAME_TYPE_ITEM1: { + int category = ITEM_NAME_GET_CAT((mActor_name_t)item); + int idx = ITEM_NAME_GET_INDEX((mActor_name_t)item); + + return item1_tableNo[category][idx]; + } + + default: + return mNT_ITEM_TYPE_NONE; } - - case NAME_TYPE_ITEM1: - { - int category = ITEM_NAME_GET_CAT((mActor_name_t)item); - int idx = ITEM_NAME_GET_INDEX((mActor_name_t)item); - - return item1_tableNo[category][idx]; - } - - default: - return mNT_ITEM_TYPE_NONE; - } } extern mActor_name_t mNT_FishIdx2FishItemNo(int idx) { - if (idx >= 0 && idx <= (FISH_NUM + 1)) { - return ITM_FISH_START + idx; - } + if (idx >= 0 && idx <= (FISH_NUM + 1)) { + return ITM_FISH_START + idx; + } - return EMPTY_NO; + return EMPTY_NO; } extern mActor_name_t bg_item_fg_sub(mActor_name_t item, s16 flag) { - static mActor_name_t cnvfg[mNT_TREE_SIZE_NUM][mNT_TREE_TYPE_NUM] = { - { TREE_STUMP004, TREE_PALM_STUMP004, CEDAR_TREE_STUMP004, GOLD_TREE_STUMP004 }, - { TREE_STUMP003, TREE_PALM_STUMP003, CEDAR_TREE_STUMP003, GOLD_TREE_STUMP003 }, - { TREE_STUMP002, TREE_PALM_STUMP002, CEDAR_TREE_STUMP002, GOLD_TREE_STUMP002 }, - { TREE_STUMP001, TREE_PALM_STUMP001, CEDAR_TREE_STUMP001, GOLD_TREE_STUMP001 } - }; + static mActor_name_t cnvfg[mNT_TREE_SIZE_NUM][mNT_TREE_TYPE_NUM] = { + { TREE_STUMP004, TREE_PALM_STUMP004, CEDAR_TREE_STUMP004, GOLD_TREE_STUMP004 }, + { TREE_STUMP003, TREE_PALM_STUMP003, CEDAR_TREE_STUMP003, GOLD_TREE_STUMP003 }, + { TREE_STUMP002, TREE_PALM_STUMP002, CEDAR_TREE_STUMP002, GOLD_TREE_STUMP002 }, + { TREE_STUMP001, TREE_PALM_STUMP001, CEDAR_TREE_STUMP001, GOLD_TREE_STUMP001 } + }; - u32 what = item; - int tree_type = FGTreeType_check(what); - mActor_name_t stump = what; + u32 what = item; + int tree_type = FGTreeType_check(what); + mActor_name_t stump = what; - if (flag != 0) { - stump = what; - } - else if ( - item == TREE || - item == TREE_1000BELLS || - item == TREE_10000BELLS || - item == TREE_30000BELLS || - item == TREE_100BELLS || - item == CEDAR_TREE || - item == GOLD_TREE_SHOVEL || - item == GOLD_TREE || - item == TREE_APPLE_NOFRUIT_0 || - item == TREE_APPLE_NOFRUIT_1 || - item == TREE_APPLE_NOFRUIT_2 || - item == TREE_APPLE_FRUIT || - item == TREE_ORANGE_NOFRUIT_0 || - item == TREE_ORANGE_NOFRUIT_1 || - item == TREE_ORANGE_NOFRUIT_2 || - item == TREE_ORANGE_FRUIT || - item == TREE_PEACH_NOFRUIT_0 || - item == TREE_PEACH_NOFRUIT_1 || - item == TREE_PEACH_NOFRUIT_2 || - item == TREE_PEACH_FRUIT || - item == TREE_PEAR_NOFRUIT_0 || - item == TREE_PEAR_NOFRUIT_1 || - item == TREE_PEAR_NOFRUIT_2 || - item == TREE_PEAR_FRUIT || - item == TREE_CHERRY_NOFRUIT_0 || - item == TREE_CHERRY_NOFRUIT_1 || - item == TREE_CHERRY_NOFRUIT_2 || - item == TREE_CHERRY_FRUIT || - item == TREE_PALM_NOFRUIT_0 || - item == TREE_PALM_NOFRUIT_1 || - item == TREE_PALM_NOFRUIT_2 || - item == TREE_PALM_FRUIT || - item == TREE_BEES || - item == TREE_FTR || - item == TREE_LIGHTS || - item == TREE_PRESENT || - item == TREE_BELLS || - item == CEDAR_TREE_BELLS || - item == CEDAR_TREE_FTR || - item == CEDAR_TREE_BEES || - item == CEDAR_TREE_LIGHTS || - item == GOLD_TREE_BELLS || - item == GOLD_TREE_FTR || - item == GOLD_TREE_BEES - ) { - stump = cnvfg[mNT_TREE_SIZE_FULL][tree_type]; - } - else if ( - item == TREE_S2 || - item == TREE_APPLE_S2 || - item == TREE_ORANGE_S2 || - item == TREE_PEACH_S2 || - item == TREE_PEAR_S2 || - item == TREE_CHERRY_S2 || - item == TREE_1000BELLS_S2 || - item == TREE_10000BELLS_S2 || - item == TREE_30000BELLS_S2 || - item == TREE_100BELLS_S2 || - item == TREE_PALM_S2 || - item == CEDAR_TREE_S2 || - item == GOLD_TREE_S2 - ) { - stump = cnvfg[mNT_TREE_SIZE_S2][tree_type]; - } - else if ( - item == TREE_S1 || - item == TREE_APPLE_S1 || - item == TREE_ORANGE_S1 || - item == TREE_PEACH_S1 || - item == TREE_PEAR_S1 || - item == TREE_CHERRY_S1 || - item == TREE_1000BELLS_S1 || - item == TREE_10000BELLS_S1 || - item == TREE_30000BELLS_S1 || - item == TREE_100BELLS_S1 || - item == TREE_PALM_S1 || - item == CEDAR_TREE_S1 || - item == GOLD_TREE_S1 - ) { - stump = cnvfg[mNT_TREE_SIZE_S1][tree_type]; - } - else if ( - item == TREE_S0 || - item == TREE_APPLE_S0 || - item == TREE_ORANGE_S0 || - item == TREE_PEACH_S0 || - item == TREE_PEAR_S0 || - item == TREE_CHERRY_S0 || - item == TREE_1000BELLS_S0 || - item == TREE_10000BELLS_S0 || - item == TREE_30000BELLS_S0 || - item == TREE_100BELLS_S0 || - item == TREE_PALM_S0 || - item == CEDAR_TREE_S0 || - item == GOLD_TREE_S0 - ) { - stump = cnvfg[mNT_TREE_SIZE_S0][tree_type]; - } + if (flag != 0) { + stump = what; + } else if (item == TREE || item == TREE_1000BELLS || item == TREE_10000BELLS || item == TREE_30000BELLS || + item == TREE_100BELLS || item == CEDAR_TREE || item == GOLD_TREE_SHOVEL || item == GOLD_TREE || + item == TREE_APPLE_NOFRUIT_0 || item == TREE_APPLE_NOFRUIT_1 || item == TREE_APPLE_NOFRUIT_2 || + item == TREE_APPLE_FRUIT || item == TREE_ORANGE_NOFRUIT_0 || item == TREE_ORANGE_NOFRUIT_1 || + item == TREE_ORANGE_NOFRUIT_2 || item == TREE_ORANGE_FRUIT || item == TREE_PEACH_NOFRUIT_0 || + item == TREE_PEACH_NOFRUIT_1 || item == TREE_PEACH_NOFRUIT_2 || item == TREE_PEACH_FRUIT || + item == TREE_PEAR_NOFRUIT_0 || item == TREE_PEAR_NOFRUIT_1 || item == TREE_PEAR_NOFRUIT_2 || + item == TREE_PEAR_FRUIT || item == TREE_CHERRY_NOFRUIT_0 || item == TREE_CHERRY_NOFRUIT_1 || + item == TREE_CHERRY_NOFRUIT_2 || item == TREE_CHERRY_FRUIT || item == TREE_PALM_NOFRUIT_0 || + item == TREE_PALM_NOFRUIT_1 || item == TREE_PALM_NOFRUIT_2 || item == TREE_PALM_FRUIT || + item == TREE_BEES || item == TREE_FTR || item == TREE_LIGHTS || item == TREE_PRESENT || + item == TREE_BELLS || item == CEDAR_TREE_BELLS || item == CEDAR_TREE_FTR || item == CEDAR_TREE_BEES || + item == CEDAR_TREE_LIGHTS || item == GOLD_TREE_BELLS || item == GOLD_TREE_FTR || + item == GOLD_TREE_BEES) { + stump = cnvfg[mNT_TREE_SIZE_FULL][tree_type]; + } else if (item == TREE_S2 || item == TREE_APPLE_S2 || item == TREE_ORANGE_S2 || item == TREE_PEACH_S2 || + item == TREE_PEAR_S2 || item == TREE_CHERRY_S2 || item == TREE_1000BELLS_S2 || + item == TREE_10000BELLS_S2 || item == TREE_30000BELLS_S2 || item == TREE_100BELLS_S2 || + item == TREE_PALM_S2 || item == CEDAR_TREE_S2 || item == GOLD_TREE_S2) { + stump = cnvfg[mNT_TREE_SIZE_S2][tree_type]; + } else if (item == TREE_S1 || item == TREE_APPLE_S1 || item == TREE_ORANGE_S1 || item == TREE_PEACH_S1 || + item == TREE_PEAR_S1 || item == TREE_CHERRY_S1 || item == TREE_1000BELLS_S1 || + item == TREE_10000BELLS_S1 || item == TREE_30000BELLS_S1 || item == TREE_100BELLS_S1 || + item == TREE_PALM_S1 || item == CEDAR_TREE_S1 || item == GOLD_TREE_S1) { + stump = cnvfg[mNT_TREE_SIZE_S1][tree_type]; + } else if (item == TREE_S0 || item == TREE_APPLE_S0 || item == TREE_ORANGE_S0 || item == TREE_PEACH_S0 || + item == TREE_PEAR_S0 || item == TREE_CHERRY_S0 || item == TREE_1000BELLS_S0 || + item == TREE_10000BELLS_S0 || item == TREE_30000BELLS_S0 || item == TREE_100BELLS_S0 || + item == TREE_PALM_S0 || item == CEDAR_TREE_S0 || item == GOLD_TREE_S0) { + stump = cnvfg[mNT_TREE_SIZE_S0][tree_type]; + } - return stump; + return stump; } extern mActor_name_t bg_item_fg_sub_tree_grow(mActor_name_t item, int past_days, int check_plant) { - static s16 grow_check[84][2] = { - { -1, mCoBG_PLANT0 }, - { -1, mCoBG_PLANT1 }, - { -1, mCoBG_PLANT2 }, - { -1, mCoBG_PLANT3 }, - { 0, mCoBG_PLANT4 }, - { -1, mCoBG_PLANT0 }, - { -1, mCoBG_PLANT1 }, - { -1, mCoBG_PLANT2 }, - { -4, mCoBG_PLANT3 }, - { -1, mCoBG_PLANT4 }, - { -1, mCoBG_PLANT4 }, - { -1, mCoBG_PLANT4 }, - { 0, mCoBG_PLANT4 }, - { -1, mCoBG_PLANT0 }, - { -1, mCoBG_PLANT1 }, - { -1, mCoBG_PLANT2 }, - { -4, mCoBG_PLANT3 }, - { -1, mCoBG_PLANT4 }, - { -1, mCoBG_PLANT4 }, - { -1, mCoBG_PLANT4 }, - { 0, mCoBG_PLANT4 }, - { -1, mCoBG_PLANT0 }, - { -1, mCoBG_PLANT1 }, - { -1, mCoBG_PLANT2 }, - { -4, mCoBG_PLANT3 }, - { -1, mCoBG_PLANT4 }, - { -1, mCoBG_PLANT4 }, - { -1, mCoBG_PLANT4 }, - { 0, mCoBG_PLANT4 }, - { -1, mCoBG_PLANT0 }, - { -1, mCoBG_PLANT1 }, - { -1, mCoBG_PLANT2 }, - { -4, mCoBG_PLANT3 }, - { -1, mCoBG_PLANT4 }, - { -1, mCoBG_PLANT4 }, - { -1, mCoBG_PLANT4 }, - { 0, mCoBG_PLANT4 }, - { -1, mCoBG_PLANT0 }, - { -1, mCoBG_PLANT1 }, - { -1, mCoBG_PLANT2 }, - { -4, mCoBG_PLANT3 }, - { -1, mCoBG_PLANT4 }, - { -1, mCoBG_PLANT4 }, - { -1, mCoBG_PLANT4 }, - { 0, mCoBG_PLANT4 }, - { -1, mCoBG_PLANT0 }, - { -1, mCoBG_PLANT1 }, - { -1, mCoBG_PLANT2 }, - { -1, mCoBG_PLANT3 }, - { 0, mCoBG_PLANT4 }, - { -1, mCoBG_PLANT0 }, - { -1, mCoBG_PLANT1 }, - { -1, mCoBG_PLANT2 }, - { -1, mCoBG_PLANT3 }, - { 0, mCoBG_PLANT4 }, - { -1, mCoBG_PLANT0 }, - { -1, mCoBG_PLANT1 }, - { -1, mCoBG_PLANT2 }, - { -1, mCoBG_PLANT3 }, - { 0, mCoBG_PLANT4 }, - { -1, mCoBG_PLANT0 }, - { -1, mCoBG_PLANT1 }, - { -1, mCoBG_PLANT2 }, - { -1, mCoBG_PLANT3 }, - { 0, mCoBG_PLANT4 }, - { -1, mCoBG_PLANT0 }, - { -1, mCoBG_PLANT1 }, - { -1, mCoBG_PLANT2 }, - { -4, mCoBG_PLANT3 }, - { -1, mCoBG_PLANT4 }, - { -1, mCoBG_PLANT4 }, - { -1, mCoBG_PLANT4 }, - { 0, mCoBG_PLANT4 }, - { -1, mCoBG_PLANT0 }, - { -1, mCoBG_PLANT1 }, - { -1, mCoBG_PLANT2 }, - { -1, mCoBG_PLANT3 }, - { 0, mCoBG_PLANT4 }, - { -1, mCoBG_PLANT0 }, - { -1, mCoBG_PLANT1 }, - { -1, mCoBG_PLANT2 }, - { -1, mCoBG_PLANT3 }, - { 0, mCoBG_PLANT4 }, - { 0, mCoBG_PLANT4 } - }; + static s16 grow_check[84][2] = { + { -1, mCoBG_PLANT0 }, { -1, mCoBG_PLANT1 }, { -1, mCoBG_PLANT2 }, { -1, mCoBG_PLANT3 }, { 0, mCoBG_PLANT4 }, + { -1, mCoBG_PLANT0 }, { -1, mCoBG_PLANT1 }, { -1, mCoBG_PLANT2 }, { -4, mCoBG_PLANT3 }, { -1, mCoBG_PLANT4 }, + { -1, mCoBG_PLANT4 }, { -1, mCoBG_PLANT4 }, { 0, mCoBG_PLANT4 }, { -1, mCoBG_PLANT0 }, { -1, mCoBG_PLANT1 }, + { -1, mCoBG_PLANT2 }, { -4, mCoBG_PLANT3 }, { -1, mCoBG_PLANT4 }, { -1, mCoBG_PLANT4 }, { -1, mCoBG_PLANT4 }, + { 0, mCoBG_PLANT4 }, { -1, mCoBG_PLANT0 }, { -1, mCoBG_PLANT1 }, { -1, mCoBG_PLANT2 }, { -4, mCoBG_PLANT3 }, + { -1, mCoBG_PLANT4 }, { -1, mCoBG_PLANT4 }, { -1, mCoBG_PLANT4 }, { 0, mCoBG_PLANT4 }, { -1, mCoBG_PLANT0 }, + { -1, mCoBG_PLANT1 }, { -1, mCoBG_PLANT2 }, { -4, mCoBG_PLANT3 }, { -1, mCoBG_PLANT4 }, { -1, mCoBG_PLANT4 }, + { -1, mCoBG_PLANT4 }, { 0, mCoBG_PLANT4 }, { -1, mCoBG_PLANT0 }, { -1, mCoBG_PLANT1 }, { -1, mCoBG_PLANT2 }, + { -4, mCoBG_PLANT3 }, { -1, mCoBG_PLANT4 }, { -1, mCoBG_PLANT4 }, { -1, mCoBG_PLANT4 }, { 0, mCoBG_PLANT4 }, + { -1, mCoBG_PLANT0 }, { -1, mCoBG_PLANT1 }, { -1, mCoBG_PLANT2 }, { -1, mCoBG_PLANT3 }, { 0, mCoBG_PLANT4 }, + { -1, mCoBG_PLANT0 }, { -1, mCoBG_PLANT1 }, { -1, mCoBG_PLANT2 }, { -1, mCoBG_PLANT3 }, { 0, mCoBG_PLANT4 }, + { -1, mCoBG_PLANT0 }, { -1, mCoBG_PLANT1 }, { -1, mCoBG_PLANT2 }, { -1, mCoBG_PLANT3 }, { 0, mCoBG_PLANT4 }, + { -1, mCoBG_PLANT0 }, { -1, mCoBG_PLANT1 }, { -1, mCoBG_PLANT2 }, { -1, mCoBG_PLANT3 }, { 0, mCoBG_PLANT4 }, + { -1, mCoBG_PLANT0 }, { -1, mCoBG_PLANT1 }, { -1, mCoBG_PLANT2 }, { -4, mCoBG_PLANT3 }, { -1, mCoBG_PLANT4 }, + { -1, mCoBG_PLANT4 }, { -1, mCoBG_PLANT4 }, { 0, mCoBG_PLANT4 }, { -1, mCoBG_PLANT0 }, { -1, mCoBG_PLANT1 }, + { -1, mCoBG_PLANT2 }, { -1, mCoBG_PLANT3 }, { 0, mCoBG_PLANT4 }, { -1, mCoBG_PLANT0 }, { -1, mCoBG_PLANT1 }, + { -1, mCoBG_PLANT2 }, { -1, mCoBG_PLANT3 }, { 0, mCoBG_PLANT4 }, { 0, mCoBG_PLANT4 } + }; - int idx; - int i; + int idx; + int i; - if ( - (item >= TREE_SAPLING && item <= TREE_30000BELLS) || - (item >= TREE_100BELLS_SAPLING && item <= TREE_PALM_FRUIT) || - (item >= CEDAR_TREE_SAPLING && item <= CEDAR_TREE) || - (item >= GOLD_TREE_SAPLING && item <= GOLD_TREE) - ) { - if (item >= TREE_PALM_SAPLING && item <= TREE_PALM_FRUIT) { - idx = item - 0x0813; - } - else if (item >= CEDAR_TREE_SAPLING && item <= CEDAR_TREE) { - idx = item - 0x0814; - } - else if (item == GOLD_TREE || (item >= GOLD_TREE_SAPLING && item <= GOLD_TREE_SHOVEL)) { - idx = item - 0x0815; - } - else if (item >= TREE_100BELLS_SAPLING) { - idx = item - 0x0813; - } - else { - idx = item - 0x0800; + if ((item >= TREE_SAPLING && item <= TREE_30000BELLS) || + (item >= TREE_100BELLS_SAPLING && item <= TREE_PALM_FRUIT) || + (item >= CEDAR_TREE_SAPLING && item <= CEDAR_TREE) || (item >= GOLD_TREE_SAPLING && item <= GOLD_TREE)) { + if (item >= TREE_PALM_SAPLING && item <= TREE_PALM_FRUIT) { + idx = item - 0x0813; + } else if (item >= CEDAR_TREE_SAPLING && item <= CEDAR_TREE) { + idx = item - 0x0814; + } else if (item == GOLD_TREE || (item >= GOLD_TREE_SAPLING && item <= GOLD_TREE_SHOVEL)) { + idx = item - 0x0815; + } else if (item >= TREE_100BELLS_SAPLING) { + idx = item - 0x0813; + } else { + idx = item - 0x0800; + } + + for (i = 0; i <= past_days; i++) { + int diff = -grow_check[idx][0]; + + if (grow_check[idx + diff][1] > check_plant) { + break; + } + + idx += diff; + item += diff; + } } - for (i = 0; i <= past_days; i++) { - int diff = -grow_check[idx][0]; - - if (grow_check[idx + diff][1] > check_plant) { - break; - } - - idx += diff; - item += diff; - } - } - - return item; + return item; } extern mActor_name_t bg_item_fg_sub_dig2take_conv(mActor_name_t item) { - mActor_name_t dig_item; - - dig_item = item; - if ((item >= BURIED_PITFALL_START) && (item <= BURIED_PITFALL_END)) { - dig_item = ITM_PITFALL; - } + mActor_name_t dig_item; - if (item == SHINE_SPOT) { - f32 rng_val = RANDOM_F(100.0f); - f32 money_power = mPr_GetMoneyPower(); - f32 max_bells_roll = 2.0f * (money_power / 40.0f); // 30k - f32 large_bells_roll = 10.0f * (money_power / 40.0f); // 10k - - if ((rng_val <= max_bells_roll) || ((int)Common_Get(now_private)->destiny.type == mPr_DESTINY_MONEY_LUCK)) { - dig_item = ITM_MONEY_30000; + dig_item = item; + if ((item >= BURIED_PITFALL_START) && (item <= BURIED_PITFALL_END)) { + dig_item = ITM_PITFALL; } - else if (rng_val <= (large_bells_roll + max_bells_roll)) { - dig_item = ITM_MONEY_10000; + + if (item == SHINE_SPOT) { + f32 rng_val = RANDOM_F(100.0f); + f32 money_power = mPr_GetMoneyPower(); + f32 max_bells_roll = 2.0f * (money_power / 40.0f); // 30k + f32 large_bells_roll = 10.0f * (money_power / 40.0f); // 10k + + if ((rng_val <= max_bells_roll) || ((int)Common_Get(now_private)->destiny.type == mPr_DESTINY_MONEY_LUCK)) { + dig_item = ITM_MONEY_30000; + } else if (rng_val <= (large_bells_roll + max_bells_roll)) { + dig_item = ITM_MONEY_10000; + } else { + dig_item = ITM_MONEY_1000; + } } - else { - dig_item = ITM_MONEY_1000; - } - } - return dig_item; + return dig_item; } static mNT_offset_table_c height_table[3] = { - { 0, { 100, 0, 0, 0, 0, 0, 0 } }, - { 0, { mCoBG_ATTRIBUTE_WOOD, 4, 4, 4, 4, 4, 0 } }, - { 0, { mCoBG_ATTRIBUTE_WOOD, 7, 7, 7, 7, 7, 0 } }, + { 0, { mCoBG_ATTRIBUTE_NONE, 0, 0, 0, 0, 0, 0 } }, + { 0, { mCoBG_ATTRIBUTE_WOOD, 4, 4, 4, 4, 4, 0 } }, + { 0, { mCoBG_ATTRIBUTE_WOOD, 7, 7, 7, 7, 7, 0 } }, }; extern mNT_offset_table_c* obj_hight_table_item0_nogrow(mActor_name_t item) { - mNT_offset_table_c* table = &height_table[0]; + mNT_offset_table_c* table = &height_table[0]; - if ( - item == FENCE0 || - item == FENCE1 || - item == MESSAGE_BOARD0 || - item == MESSAGE_BOARD1 || - item == WOOD_FENCE - ) { - table = &height_table[1]; - } - else if ( - item == MAP_BOARD0 || - item == MAP_BOARD1 || - item == MUSIC_BOARD0 || - item == MUSIC_BOARD1 - ) { - table = &height_table[2]; - } + if (item == FENCE0 || item == FENCE1 || item == MESSAGE_BOARD0 || item == MESSAGE_BOARD1 || item == WOOD_FENCE) { + table = &height_table[1]; + } else if (item == MAP_BOARD0 || item == MAP_BOARD1 || item == MUSIC_BOARD0 || item == MUSIC_BOARD1) { + table = &height_table[2]; + } - return table; + return table; } extern int FGTreeType_check(mActor_name_t tree) { - if ( - (tree >= TREE_PALM_SAPLING && tree <= TREE_PALM_FRUIT) || - (tree == DEAD_PALM_SAPLING) || - (tree >= TREE_PALM_STUMP001 && tree <= TREE_PALM_STUMP004) - ) { - return mNT_TREE_TYPE_PALM; - } - - if ( - (tree >= CEDAR_TREE_SAPLING && tree <= CEDAR_TREE) || - (tree == DEAD_CEDAR_SAPLING) || - (tree == CEDAR_TREE_BELLS) || - (tree == CEDAR_TREE_FTR) || - (tree == CEDAR_TREE_BEES) || - (tree == CEDAR_TREE_LIGHTS) || - (tree >= CEDAR_TREE_STUMP001 && tree <= CEDAR_TREE_STUMP004) - ) { - return mNT_TREE_TYPE_CEDAR; - } + if ((tree >= TREE_PALM_SAPLING && tree <= TREE_PALM_FRUIT) || (tree == DEAD_PALM_SAPLING) || + (tree >= TREE_PALM_STUMP001 && tree <= TREE_PALM_STUMP004)) { + return mNT_TREE_TYPE_PALM; + } - if ( - (tree == GOLD_TREE) || - (tree >= GOLD_TREE_SAPLING && tree <= GOLD_TREE_SHOVEL) || - (tree == DEAD_GOLD_SAPLING) || - (tree == GOLD_TREE_BELLS) || - (tree == GOLD_TREE_FTR) || - (tree == GOLD_TREE_BEES) || - (tree >= GOLD_TREE_STUMP001 && tree <= GOLD_TREE_STUMP004) - ) { - return mNT_TREE_TYPE_GOLD; - } + if ((tree >= CEDAR_TREE_SAPLING && tree <= CEDAR_TREE) || (tree == DEAD_CEDAR_SAPLING) || + (tree == CEDAR_TREE_BELLS) || (tree == CEDAR_TREE_FTR) || (tree == CEDAR_TREE_BEES) || + (tree == CEDAR_TREE_LIGHTS) || (tree >= CEDAR_TREE_STUMP001 && tree <= CEDAR_TREE_STUMP004)) { + return mNT_TREE_TYPE_CEDAR; + } - return mNT_TREE_TYPE_NORMAL; + if ((tree == GOLD_TREE) || (tree >= GOLD_TREE_SAPLING && tree <= GOLD_TREE_SHOVEL) || (tree == DEAD_GOLD_SAPLING) || + (tree == GOLD_TREE_BELLS) || (tree == GOLD_TREE_FTR) || (tree == GOLD_TREE_BEES) || + (tree >= GOLD_TREE_STUMP001 && tree <= GOLD_TREE_STUMP004)) { + return mNT_TREE_TYPE_GOLD; + } + + return mNT_TREE_TYPE_NORMAL; } extern int mNT_ItIsStump(mActor_name_t actor) { - if ( - (actor >= TREE_STUMP001 && actor <= TREE_STUMP004) || - (actor >= TREE_PALM_STUMP001 && actor <= TREE_PALM_STUMP004) || - (actor >= CEDAR_TREE_STUMP001 && actor <= CEDAR_TREE_STUMP004) || - (actor >= GOLD_TREE_STUMP001 && actor <= GOLD_TREE_STUMP004) - ) { - return TRUE; - } - - return FALSE; + if ((actor >= TREE_STUMP001 && actor <= TREE_STUMP004) || + (actor >= TREE_PALM_STUMP001 && actor <= TREE_PALM_STUMP004) || + (actor >= CEDAR_TREE_STUMP001 && actor <= CEDAR_TREE_STUMP004) || + (actor >= GOLD_TREE_STUMP001 && actor <= GOLD_TREE_STUMP004)) { + return TRUE; + } + + return FALSE; } extern int mNT_ItIsStoneCoin10(mActor_name_t actor) { - int res = FALSE; + int res = FALSE; - if ((actor >= MONEY_ROCK_A) && (actor <= MONEY_FLOWER_SEED)) { - res = TRUE; - } + if ((actor >= MONEY_ROCK_A) && (actor <= MONEY_FLOWER_SEED)) { + res = TRUE; + } - return res != FALSE; + return res != FALSE; } extern int mNT_ItIsReserveDummy(mActor_name_t actor) { - return actor == DUMMY_RESERVE; + return actor == DUMMY_RESERVE; } extern int mNT_check_unknown(mActor_name_t item_no) { - static s16 item1_kinds[ITEM1_CAT_NUM] = { - PAPER_NUM, - MONEY_NUM, - TOOL_NUM, - FISH_NUM, - CLOTH_NUM, - ETC_NUM, - CARPET_NUM, - WALL_NUM, - FRUIT_NUM, - PLANT_NUM, - MINIDISK_NUM, - DIARY_NUM, - TICKET_NUM, - INSECT_NUM, - HUKUBUKURO_NUM, - KABU_NUM - }; + static s16 item1_kinds[ITEM1_CAT_NUM] = { + PAPER_NUM, MONEY_NUM, TOOL_NUM, FISH_NUM, CLOTH_NUM, ETC_NUM, CARPET_NUM, WALL_NUM, + FRUIT_NUM, PLANT_NUM, MINIDISK_NUM, DIARY_NUM, TICKET_NUM, INSECT_NUM, HUKUBUKURO_NUM, KABU_NUM, + }; - int index = ITEM_NAME_GET_INDEX(item_no); - int res = FALSE; + int index = ITEM_NAME_GET_INDEX(item_no); + int res = FALSE; - switch (ITEM_NAME_GET_TYPE(item_no)) { - case NAME_TYPE_ITEM1: - { - int category = ITEM_NAME_GET_CAT(item_no); - - if (index < 0 || index >= item1_kinds[category]) { - res = TRUE; - } - break; + switch (ITEM_NAME_GET_TYPE(item_no)) { + case NAME_TYPE_ITEM1: { + int category = ITEM_NAME_GET_CAT(item_no); + + if (index < 0 || index >= item1_kinds[category]) { + res = TRUE; + } + break; + } + + case NAME_TYPE_FTR1: { + int FtrIdx = mRmTp_FtrItemNo2FtrIdx(item_no); + + if (FtrIdx < 0 || FtrIdx >= FTR_NUM) { + res = TRUE; + } + + break; + } } - - case NAME_TYPE_FTR1: - { - int FtrIdx = mRmTp_FtrItemNo2FtrIdx(item_no); - - if (FtrIdx < 0 || FtrIdx >= FTR_NUM) { - res = TRUE; - } - break; - } - } - - return res; + return res; } diff --git a/src/m_npc.c b/src/m_npc.c index 359bbefc..e0af6a8d 100644 --- a/src/m_npc.c +++ b/src/m_npc.c @@ -15,297 +15,296 @@ #include "libultra/libultra.h" #include "jsyswrap.h" +static int mNpc_CheckIslandAnimalID(AnmPersonalID_c* anm_id); + extern mNpc_Default_Data_c npc_def_list[]; extern s8 npc_grow_list[]; extern mNpc_NpcHouseData_c npc_house_list[]; typedef struct sp_actor_name_data_s { - mActor_name_t sp_npc_id; - u16 sex; - int name_str_no; - int sound_id; + mActor_name_t sp_npc_id; + u16 sex; + int name_str_no; + int sound_id; } mNpc_Sp_Npc_Name_c; static mNpc_Sp_Npc_Name_c l_sp_actor_name[] = { - // Tom Nook - { SP_NPC_SHOP_MASTER, mPr_SEX_MALE, 0x205, 2 }, - { SP_NPC_SHOP_MASTERSP, mPr_SEX_MALE, 0x205, 2 }, - { SP_NPC_SHOP_MASTERSP_2, mPr_SEX_MALE, 0x205, 2 }, - { SP_NPC_SHOP_MASTERSP_3, mPr_SEX_MALE, 0x205, 2 }, - { SP_NPC_SHOP_MASTERSP_4, mPr_SEX_MALE, 0x205, 2 }, - { SP_NPC_CONV_MASTER, mPr_SEX_MALE, 0x205, 2 }, - { SP_NPC_SUPER_MASTER, mPr_SEX_MALE, 0x205, 2 }, - { SP_NPC_DEPART_MASTER, mPr_SEX_MALE, 0x205, 2 }, - { SP_NPC_RCN_GUIDE, mPr_SEX_MALE, 0x205, 2 }, - { SP_NPC_RCN_GUIDE2, mPr_SEX_MALE, 0x205, 2 }, - { SP_NPC_RCN_GUIDE_1, mPr_SEX_MALE, 0x205, 2 }, - { SP_NPC_RCN_GUIDE2_1, mPr_SEX_MALE, 0x205, 2 }, - { SP_NPC_RCN_GUIDE_2, mPr_SEX_MALE, 0x205, 2 }, - { SP_NPC_RCN_GUIDE2_2, mPr_SEX_MALE, 0x205, 2 }, - { SP_NPC_RCN_GUIDE_3, mPr_SEX_MALE, 0x205, 2 }, - { SP_NPC_RCN_GUIDE2_3, mPr_SEX_MALE, 0x205, 2 }, - // Redd - { SP_NPC_BROKER, mPr_SEX_MALE, 0x206, 2 }, - { SP_NPC_EV_BROKER2, mPr_SEX_MALE, 0x206, 2 }, - { SP_NPC_EV_YOMISE, mPr_SEX_MALE, 0x206, 2 }, - { SP_NPC_EV_YOMISE2, mPr_SEX_MALE, 0x206, 2 }, - // Katrina - { SP_NPC_GYPSY, mPr_SEX_FEMALE, 0x207, 2 }, - { SP_NPC_EV_MIKO, mPr_SEX_FEMALE, 0x207, 2 }, - // Saharah - { SP_NPC_CARPETPEDDLER, mPr_SEX_MALE, 0x208, 2 }, - // Wendell - { SP_NPC_ARTIST, mPr_SEX_MALE, 0x209, 3 }, - // Jingle - { SP_NPC_SANTA, mPr_SEX_MALE, 0x20A, 2 }, - // Gracie - { SP_NPC_DESIGNER, mPr_SEX_MALE, 0x20B, 2 }, - // Joan - { SP_NPC_KABUPEDDLER, mPr_SEX_FEMALE, 0x20C, 8 }, - // Pelly - { SP_NPC_POST_GIRL, mPr_SEX_FEMALE, 0x20D, 4 }, - // Phyllis - { SP_NPC_POST_GIRL2, mPr_SEX_FEMALE, 0x20E, 4 }, - // Pete - { SP_NPC_POST_MAN, mPr_SEX_MALE, 0x20F, 3 }, - // Copper - { SP_NPC_POLICE, mPr_SEX_MALE, 0x210, 2 }, - // Booker - { SP_NPC_POLICE2, mPr_SEX_MALE, 0x6D9, 3 }, - // Copper - { SP_NPC_EV_TAISOU_0, mPr_SEX_MALE, 0x210, 2 }, - // Porter - { SP_NPC_STATION_MASTER, mPr_SEX_MALE, 0x211, 2 }, - // Jack - { SP_NPC_HALLOWEEN, mPr_SEX_MALE, 0x212, 3 }, - // Gyroid - { ACTOR_PROP_HANIWA0, mPr_SEX_OTHER, 0x213, 2 }, - { ACTOR_PROP_HANIWA1, mPr_SEX_OTHER, 0x213, 2 }, - { ACTOR_PROP_HANIWA2, mPr_SEX_OTHER, 0x213, 2 }, - { ACTOR_PROP_HANIWA3, mPr_SEX_OTHER, 0x213, 2 }, - // K.K. Slider - { SP_NPC_P_SEL, mPr_SEX_OTHER, 0x214, 2 }, - { SP_NPC_TOTAKEKE, mPr_SEX_OTHER, 0x214, 2 }, - { SP_NPC_RTC, mPr_SEX_OTHER, 0x214, 2 }, - // Rover - { SP_NPC_GUIDE, mPr_SEX_MALE, 0x215, 2 }, - { SP_NPC_GUIDE2, mPr_SEX_MALE, 0x215, 2 }, - // Chip - { SP_NPC_ANGLER, mPr_SEX_MALE, 0x216, 2 }, - // Timmy - { SP_NPC_MAMEDANUKI0, mPr_SEX_MALE, 0x217, 2 }, - // Tommy - { SP_NPC_MAMEDANUKI1, mPr_SEX_MALE, 0x218, 2 }, - // Resetti - { SP_NPC_MAJIN, mPr_SEX_MALE, 0x4E0, 2 }, - { SP_NPC_MAJIN2, mPr_SEX_MALE, 0x4E0, 2 }, - { SP_NPC_MAJIN3, mPr_SEX_MALE, 0x4E0, 2 }, - { SP_NPC_MAJIN4, mPr_SEX_MALE, 0x4E0, 2 }, - { SP_NPC_MAJIN5, mPr_SEX_MALE, 0x4E0, 2 }, - { SP_NPC_MAJIN_D07C, mPr_SEX_MALE, 0x4E0, 2 }, - { SP_NPC_MAJIN_D07D, mPr_SEX_MALE, 0x4E0, 2 }, - // Don - { SP_NPC_MAJIN_BROTHER, mPr_SEX_MALE, 0x6D8, 2 }, - // Resetti - { SP_NPC_MAJIN_D080, mPr_SEX_MALE, 0x4E0, 2 }, - { SP_NPC_EV_MAJIN, mPr_SEX_MALE, 0x4E0, 2 }, - // Gulliver - { SP_NPC_EV_DOZAEMON, mPr_SEX_MALE, 0x4E1, 2 }, - // Snowman - { ETC_SNOWMAN_BALL_A, mPr_SEX_MALE, 0x4E2, 2 }, - { ETC_SNOWMAN_BALL_B, mPr_SEX_MALE, 0x4E2, 2 }, - { SNOWMAN0, mPr_SEX_MALE, 0x4E2, 2 }, - { SNOWMAN1, mPr_SEX_MALE, 0x4E2, 2 }, - { SNOWMAN2, mPr_SEX_MALE, 0x4E2, 2 }, - { SNOWMAN3, mPr_SEX_MALE, 0x4E2, 2 }, - { SNOWMAN4, mPr_SEX_MALE, 0x4E2, 2 }, - { SNOWMAN5, mPr_SEX_MALE, 0x4E2, 2 }, - { SNOWMAN6, mPr_SEX_MALE, 0x4E2, 2 }, - { SNOWMAN7, mPr_SEX_MALE, 0x4E2, 2 }, - { SNOWMAN8, mPr_SEX_MALE, 0x4E2, 2 }, - // Tortimer - { SP_NPC_EV_SONCHO, mPr_SEX_MALE, 0x4E3, 2 }, - { SP_NPC_EV_SONCHO2, mPr_SEX_MALE, 0x4E3, 2 }, - { SP_NPC_SONCHO_D078, mPr_SEX_MALE, 0x4E3, 2 }, - { SP_NPC_SONCHO_D079, mPr_SEX_MALE, 0x4E3, 2 }, - { SP_NPC_SONCHO, mPr_SEX_MALE, 0x4E3, 2 }, - { SP_NPC_EV_SPEECH_SONCHO, mPr_SEX_MALE, 0x4E3, 2 }, - // Blathers - { SP_NPC_CURATOR, mPr_SEX_MALE, 0x4E4, 2 }, - // Mabel - { SP_NPC_NEEDLEWORK0, mPr_SEX_FEMALE, 0x4E5, 4 }, - // Sabel - { SP_NPC_NEEDLEWORK1, mPr_SEX_FEMALE, 0x4E6, 4 }, - // Kapp'n - { SP_NPC_SENDO, mPr_SEX_MALE, 0x4E7, 2 }, - // Wisp - { SP_NPC_EV_GHOST, mPr_SEX_MALE, 0x4E8, 2 }, - // Blanca - { SP_NPC_MASK_CAT, mPr_SEX_MALE, 0x4E9, 4 }, - { SP_NPC_MASK_CAT2, mPr_SEX_MALE, 0x4E9, 4 }, - // Franklin - { SP_NPC_TURKEY, mPr_SEX_MALE, 0x6DA, 2 }, - // Farley - { SP_NPC_HEM, mPr_SEX_MALE, 0x6DB, 9 } + // Tom Nook + { SP_NPC_SHOP_MASTER, mPr_SEX_MALE, 0x205, 2 }, + { SP_NPC_SHOP_MASTERSP, mPr_SEX_MALE, 0x205, 2 }, + { SP_NPC_SHOP_MASTERSP_2, mPr_SEX_MALE, 0x205, 2 }, + { SP_NPC_SHOP_MASTERSP_3, mPr_SEX_MALE, 0x205, 2 }, + { SP_NPC_SHOP_MASTERSP_4, mPr_SEX_MALE, 0x205, 2 }, + { SP_NPC_CONV_MASTER, mPr_SEX_MALE, 0x205, 2 }, + { SP_NPC_SUPER_MASTER, mPr_SEX_MALE, 0x205, 2 }, + { SP_NPC_DEPART_MASTER, mPr_SEX_MALE, 0x205, 2 }, + { SP_NPC_RCN_GUIDE, mPr_SEX_MALE, 0x205, 2 }, + { SP_NPC_RCN_GUIDE2, mPr_SEX_MALE, 0x205, 2 }, + { SP_NPC_RCN_GUIDE_1, mPr_SEX_MALE, 0x205, 2 }, + { SP_NPC_RCN_GUIDE2_1, mPr_SEX_MALE, 0x205, 2 }, + { SP_NPC_RCN_GUIDE_2, mPr_SEX_MALE, 0x205, 2 }, + { SP_NPC_RCN_GUIDE2_2, mPr_SEX_MALE, 0x205, 2 }, + { SP_NPC_RCN_GUIDE_3, mPr_SEX_MALE, 0x205, 2 }, + { SP_NPC_RCN_GUIDE2_3, mPr_SEX_MALE, 0x205, 2 }, + // Redd + { SP_NPC_BROKER, mPr_SEX_MALE, 0x206, 2 }, + { SP_NPC_EV_BROKER2, mPr_SEX_MALE, 0x206, 2 }, + { SP_NPC_EV_YOMISE, mPr_SEX_MALE, 0x206, 2 }, + { SP_NPC_EV_YOMISE2, mPr_SEX_MALE, 0x206, 2 }, + // Katrina + { SP_NPC_GYPSY, mPr_SEX_FEMALE, 0x207, 2 }, + { SP_NPC_EV_MIKO, mPr_SEX_FEMALE, 0x207, 2 }, + // Saharah + { SP_NPC_CARPETPEDDLER, mPr_SEX_MALE, 0x208, 2 }, + // Wendell + { SP_NPC_ARTIST, mPr_SEX_MALE, 0x209, 3 }, + // Jingle + { SP_NPC_SANTA, mPr_SEX_MALE, 0x20A, 2 }, + // Gracie + { SP_NPC_DESIGNER, mPr_SEX_MALE, 0x20B, 2 }, + // Joan + { SP_NPC_KABUPEDDLER, mPr_SEX_FEMALE, 0x20C, 8 }, + // Pelly + { SP_NPC_POST_GIRL, mPr_SEX_FEMALE, 0x20D, 4 }, + // Phyllis + { SP_NPC_POST_GIRL2, mPr_SEX_FEMALE, 0x20E, 4 }, + // Pete + { SP_NPC_POST_MAN, mPr_SEX_MALE, 0x20F, 3 }, + // Copper + { SP_NPC_POLICE, mPr_SEX_MALE, 0x210, 2 }, + // Booker + { SP_NPC_POLICE2, mPr_SEX_MALE, 0x6D9, 3 }, + // Copper + { SP_NPC_EV_TAISOU_0, mPr_SEX_MALE, 0x210, 2 }, + // Porter + { SP_NPC_STATION_MASTER, mPr_SEX_MALE, 0x211, 2 }, + // Jack + { SP_NPC_HALLOWEEN, mPr_SEX_MALE, 0x212, 3 }, + // Gyroid + { ACTOR_PROP_HANIWA0, mPr_SEX_OTHER, 0x213, 2 }, + { ACTOR_PROP_HANIWA1, mPr_SEX_OTHER, 0x213, 2 }, + { ACTOR_PROP_HANIWA2, mPr_SEX_OTHER, 0x213, 2 }, + { ACTOR_PROP_HANIWA3, mPr_SEX_OTHER, 0x213, 2 }, + // K.K. Slider + { SP_NPC_P_SEL, mPr_SEX_OTHER, 0x214, 2 }, + { SP_NPC_TOTAKEKE, mPr_SEX_OTHER, 0x214, 2 }, + { SP_NPC_RTC, mPr_SEX_OTHER, 0x214, 2 }, + // Rover + { SP_NPC_GUIDE, mPr_SEX_MALE, 0x215, 2 }, + { SP_NPC_GUIDE2, mPr_SEX_MALE, 0x215, 2 }, + // Chip + { SP_NPC_ANGLER, mPr_SEX_MALE, 0x216, 2 }, + // Timmy + { SP_NPC_MAMEDANUKI0, mPr_SEX_MALE, 0x217, 2 }, + // Tommy + { SP_NPC_MAMEDANUKI1, mPr_SEX_MALE, 0x218, 2 }, + // Resetti + { SP_NPC_MAJIN, mPr_SEX_MALE, 0x4E0, 2 }, + { SP_NPC_MAJIN2, mPr_SEX_MALE, 0x4E0, 2 }, + { SP_NPC_MAJIN3, mPr_SEX_MALE, 0x4E0, 2 }, + { SP_NPC_MAJIN4, mPr_SEX_MALE, 0x4E0, 2 }, + { SP_NPC_MAJIN5, mPr_SEX_MALE, 0x4E0, 2 }, + { SP_NPC_MAJIN_D07C, mPr_SEX_MALE, 0x4E0, 2 }, + { SP_NPC_MAJIN_D07D, mPr_SEX_MALE, 0x4E0, 2 }, + // Don + { SP_NPC_MAJIN_BROTHER, mPr_SEX_MALE, 0x6D8, 2 }, + // Resetti + { SP_NPC_MAJIN_D080, mPr_SEX_MALE, 0x4E0, 2 }, + { SP_NPC_EV_MAJIN, mPr_SEX_MALE, 0x4E0, 2 }, + // Gulliver + { SP_NPC_EV_DOZAEMON, mPr_SEX_MALE, 0x4E1, 2 }, + // Snowman + { ETC_SNOWMAN_BALL_A, mPr_SEX_MALE, 0x4E2, 2 }, + { ETC_SNOWMAN_BALL_B, mPr_SEX_MALE, 0x4E2, 2 }, + { SNOWMAN0, mPr_SEX_MALE, 0x4E2, 2 }, + { SNOWMAN1, mPr_SEX_MALE, 0x4E2, 2 }, + { SNOWMAN2, mPr_SEX_MALE, 0x4E2, 2 }, + { SNOWMAN3, mPr_SEX_MALE, 0x4E2, 2 }, + { SNOWMAN4, mPr_SEX_MALE, 0x4E2, 2 }, + { SNOWMAN5, mPr_SEX_MALE, 0x4E2, 2 }, + { SNOWMAN6, mPr_SEX_MALE, 0x4E2, 2 }, + { SNOWMAN7, mPr_SEX_MALE, 0x4E2, 2 }, + { SNOWMAN8, mPr_SEX_MALE, 0x4E2, 2 }, + // Tortimer + { SP_NPC_EV_SONCHO, mPr_SEX_MALE, 0x4E3, 2 }, + { SP_NPC_EV_SONCHO2, mPr_SEX_MALE, 0x4E3, 2 }, + { SP_NPC_SONCHO_D078, mPr_SEX_MALE, 0x4E3, 2 }, + { SP_NPC_SONCHO_D079, mPr_SEX_MALE, 0x4E3, 2 }, + { SP_NPC_SONCHO, mPr_SEX_MALE, 0x4E3, 2 }, + { SP_NPC_EV_SPEECH_SONCHO, mPr_SEX_MALE, 0x4E3, 2 }, + // Blathers + { SP_NPC_CURATOR, mPr_SEX_MALE, 0x4E4, 2 }, + // Mabel + { SP_NPC_NEEDLEWORK0, mPr_SEX_FEMALE, 0x4E5, 4 }, + // Sabel + { SP_NPC_NEEDLEWORK1, mPr_SEX_FEMALE, 0x4E6, 4 }, + // Kapp'n + { SP_NPC_SENDO, mPr_SEX_MALE, 0x4E7, 2 }, + // Wisp + { SP_NPC_EV_GHOST, mPr_SEX_MALE, 0x4E8, 2 }, + // Blanca + { SP_NPC_MASK_CAT, mPr_SEX_MALE, 0x4E9, 4 }, + { SP_NPC_MASK_CAT2, mPr_SEX_MALE, 0x4E9, 4 }, + // Franklin + { SP_NPC_TURKEY, mPr_SEX_MALE, 0x6DA, 2 }, + // Farley + { SP_NPC_HEM, mPr_SEX_MALE, 0x6DB, 9 } }; static u8 l_no_name_npc_name[ANIMAL_NAME_LEN] = { 0xD4, 0x8E, 0xA6, 0x90, 0x85, 0x42 }; // never translated -static u8 l_no_ending_npc_ending[ANIMAL_CATCHPHRASE_LEN] = { 0xD3, 0xAF, 0x9D, 0x20 }; // never translated +static u8 l_no_ending_npc_ending[ANIMAL_CATCHPHRASE_LEN] = { 0xD3, 0xAF, 0x9D, 0x20 }; // never translated static void mNpc_MakeRandTable(int* table, int count, int swap_num) { - int a; - int b; - int i; - f32 c = count; - - for (i = 0; i < count; i++) { - table[i] = i; - } + int a; + int b; + int i; + f32 c = count; - while (swap_num--) { - int temp; - - a = RANDOM_F(c); - b = RANDOM_F(c); - temp = table[a]; + for (i = 0; i < count; i++) { + table[i] = i; + } - table[a] = table[b]; - table[b] = temp; - } + while (swap_num--) { + int temp; + + a = RANDOM_F(c); + b = RANDOM_F(c); + temp = table[a]; + + table[a] = table[b]; + table[b] = temp; + } } static void mNpc_ClearBufSpace1(u8* buf, int size) { - mem_clear(buf, size, CHAR_SPACE); + mem_clear(buf, size, CHAR_SPACE); } extern void mNpc_AddNowNpcMax(u8* npc_max) { - if (npc_max[0] < ANIMAL_NUM_MAX) { - npc_max[0]++; - } + if (npc_max[0] < ANIMAL_NUM_MAX) { + npc_max[0]++; + } } extern void mNpc_SubNowNpcMax(u8* npc_max) { - if (npc_max[0] > ANIMAL_NUM_MIN) { - npc_max[0]--; - } + if (npc_max[0] > ANIMAL_NUM_MIN) { + npc_max[0]--; + } } extern void mNpc_ClearAnimalPersonalID(AnmPersonalID_c* pid) { - pid->npc_id = EMPTY_NO; - pid->name_id = 0xFF; - pid->land_id = 0xFFFF; - pid->looks = mNpc_LOOKS_UNSET; - mNPS_reset_schedule_area(pid); - mLd_ClearLandName(pid->land_name); + pid->npc_id = EMPTY_NO; + pid->name_id = 0xFF; + pid->land_id = 0xFFFF; + pid->looks = mNpc_LOOKS_UNSET; + mNPS_reset_schedule_area(pid); + mLd_ClearLandName(pid->land_name); } extern int mNpc_CheckFreeAnimalPersonalID(AnmPersonalID_c* pid) { - int res = FALSE; + int res = FALSE; - if ((pid->npc_id == EMPTY_NO && pid->name_id == 0xFF) || (ITEM_NAME_GET_TYPE(pid->npc_id) != NAME_TYPE_NPC)) { - res = TRUE; - } + if ((pid->npc_id == EMPTY_NO && pid->name_id == 0xFF) || (ITEM_NAME_GET_TYPE(pid->npc_id) != NAME_TYPE_NPC)) { + res = TRUE; + } - return res; + return res; } extern void mNpc_CopyAnimalPersonalID(AnmPersonalID_c* dst, AnmPersonalID_c* src) { - if (src != NULL && ITEM_NAME_GET_TYPE(src->npc_id) == NAME_TYPE_NPC) { - dst->npc_id = src->npc_id; - dst->name_id = src->name_id; - dst->land_id = src->land_id; - dst->looks = src->looks; - mLd_CopyLandName(dst->land_name, src->land_name); - } + if (src != NULL && ITEM_NAME_GET_TYPE(src->npc_id) == NAME_TYPE_NPC) { + dst->npc_id = src->npc_id; + dst->name_id = src->name_id; + dst->land_id = src->land_id; + dst->looks = src->looks; + mLd_CopyLandName(dst->land_name, src->land_name); + } } extern int mNpc_CheckCmpAnimalPersonalID(AnmPersonalID_c* pid0, AnmPersonalID_c* pid1) { - int res = FALSE; + int res = FALSE; - if ( - (pid0 != NULL && pid1 != NULL) && - (pid0->npc_id == pid1->npc_id) && - (pid0->name_id == pid1->name_id) && - (pid0->land_id == pid1->land_id) && - mLd_CheckCmpLandName(pid0->land_name, pid1->land_name) == TRUE - ) { - res = TRUE; - } + if ((pid0 != NULL && pid1 != NULL) && (pid0->npc_id == pid1->npc_id) && (pid0->name_id == pid1->name_id) && + (pid0->land_id == pid1->land_id) && mLd_CheckCmpLandName(pid0->land_name, pid1->land_name) == TRUE) { + res = TRUE; + } - return res; + return res; } extern int mNpc_GetAnimalNum() { - Animal_c* animal = Save_Get(animals); - int num = 0; - int i; + Animal_c* animal = Save_Get(animals); + int num = 0; + int i; - for (i = 0; i < ANIMAL_NUM_MAX; i++) { - if (mNpc_CheckFreeAnimalPersonalID(&animal->id) == FALSE) { - num++; + for (i = 0; i < ANIMAL_NUM_MAX; i++) { + if (mNpc_CheckFreeAnimalPersonalID(&animal->id) == FALSE) { + num++; + } + + animal++; } - animal++; - } - - return num; + return num; } extern int mNpc_CheckRemoveExp(Animal_c* animal) { - return (animal->remove_info >> 13) & 0b111; + return (animal->remove_info >> 13) & 0b111; } extern int mNpc_GetRemoveTime(Animal_c* animal) { - return animal->remove_info & 0x1FFF; + return animal->remove_info & 0x1FFF; } /* @unused */ extern void mNpc_AddRemoveTime(Animal_c* animal) { - if ((animal->remove_info & 0x1FFF) < 0x1FFF) { - animal->remove_info++; - } + if ((animal->remove_info & 0x1FFF) < 0x1FFF) { + animal->remove_info++; + } } /* @unused */ #ifdef MUST_MATCH extern void mNpc_SetRemoveExp(Animal_c* animal, u16 remove_exp) { - animal->remove_info = ((((animal->remove_info >> 13) & 0b111) >> 13) | remove_exp) << 13; // what the... "official" impl from DnM + animal->remove_info = ((((animal->remove_info >> 13) & 0b111) >> 13) | remove_exp) + << 13; // what the... "official" impl from DnM } #else extern void mNpc_SetRemoveExp(Animal_c* animal, u16 remove_exp) { - animal->remove_info |= (remove_exp & 0b111) << 13; + animal->remove_info |= (remove_exp & 0b111) << 13; } #endif extern void mNpc_SetParentName(Animal_c* animal, PersonalID_c* parent_id) { - if (parent_id != NULL && mPr_NullCheckPersonalID(parent_id) == FALSE && mPr_NullCheckPlayerName(animal->parent_name) == TRUE) { - mPr_CopyPlayerName(animal->parent_name, parent_id->player_name); - } + if (parent_id != NULL && mPr_NullCheckPersonalID(parent_id) == FALSE && + mPr_NullCheckPlayerName(animal->parent_name) == TRUE) { + mPr_CopyPlayerName(animal->parent_name, parent_id->player_name); + } } extern void mNpc_SetParentNameAllAnimal() { - Private_c* priv = Common_Get(now_private); + Private_c* priv = Common_Get(now_private); - if (priv != NULL) { - PersonalID_c* parent_id = &priv->player_ID; - Animal_c* animal = Save_Get(animals); - int i; + if (priv != NULL) { + PersonalID_c* parent_id = &priv->player_ID; + Animal_c* animal = Save_Get(animals); + int i; - for (i = 0; i < ANIMAL_NUM_MAX; i++) { - mNpc_SetParentName(animal, parent_id); - animal++; + for (i = 0; i < ANIMAL_NUM_MAX; i++) { + mNpc_SetParentName(animal, parent_id); + animal++; + } } - } } extern void mNpc_ClearAnimalMail(Anmplmail_c* mail) { - mail->font = 0xFF; - mail->paper_type = 0; - mail->present = EMPTY_NO; - mem_clear(mail->body, sizeof(mail->body), CHAR_SPACE); - mail->date.year = mTM_rtcTime_ymd_clear_code.year; - mail->date.month = mTM_rtcTime_ymd_clear_code.month; - mail->date.day = mTM_rtcTime_ymd_clear_code.day; + mail->font = 0xFF; + mail->paper_type = 0; + mail->present = EMPTY_NO; + mem_clear(mail->body, sizeof(mail->body), CHAR_SPACE); + mail->date.year = mTM_rtcTime_ymd_clear_code.year; + mail->date.month = mTM_rtcTime_ymd_clear_code.month; + mail->date.day = mTM_rtcTime_ymd_clear_code.day; } /* @unused */ @@ -316,43 +315,43 @@ extern void mNpc_CopyAnimalMail(Anmplmail_c* dst, Anmplmail_c* src) { */ extern void mNpc_ClearAnimalMemory(Anmmem_c* memory, int num) { - for (num; num != 0; num--) { - if (memory != NULL) { - mPr_ClearPersonalID(&memory->memory_player_id); - lbRTC_TimeCopy(&memory->last_speak_time, &mTM_rtcTime_clear_code); - mLd_ClearLandName(memory->memuni.land.name); - memory->memuni.land.id = 0; - memory->saved_town_tune = 0; - memory->friendship = 0; - memory->letter_info.exists = FALSE; - memory->letter_info.cond = mNpc_LETTER_RANK_BAD; - memory->letter_info.send_reply = FALSE; - memory->letter_info.has_present_cloth = FALSE; - mNpc_ClearAnimalMail(&memory->letter); - } + for (num; num != 0; num--) { + if (memory != NULL) { + mPr_ClearPersonalID(&memory->memory_player_id); + lbRTC_TimeCopy(&memory->last_speak_time, &mTM_rtcTime_clear_code); + mLd_ClearLandName(memory->memuni.land.name); + memory->memuni.land.id = 0; + memory->saved_town_tune = 0; + memory->friendship = 0; + memory->letter_info.exists = FALSE; + memory->letter_info.cond = mNpc_LETTER_RANK_BAD; + memory->letter_info.send_reply = FALSE; + memory->letter_info.has_present_cloth = FALSE; + mNpc_ClearAnimalMail(&memory->letter); + } - memory++; - } + memory++; + } } /* TODO: this probably implies the union is on the memory itself and not a struct inside it */ extern void mNpc_ClearIslandAnimalMemory(Anmmem_c* memory, int num) { - for (num; num != 0; num--) { - if (memory != NULL) { - mPr_ClearPersonalID(&memory->memory_player_id); - lbRTC_TimeCopy(&memory->last_speak_time, &mTM_rtcTime_clear_code); - bzero(&memory->memuni.island, sizeof(memuni_u)); - memory->saved_town_tune = 0; - memory->friendship = 0; - memory->letter_info.exists = FALSE; - memory->letter_info.cond = mNpc_LETTER_RANK_BAD; - memory->letter_info.send_reply = FALSE; - memory->letter_info.has_present_cloth = FALSE; - mNpc_ClearAnimalMail(&memory->letter); - } + for (num; num != 0; num--) { + if (memory != NULL) { + mPr_ClearPersonalID(&memory->memory_player_id); + lbRTC_TimeCopy(&memory->last_speak_time, &mTM_rtcTime_clear_code); + bzero(&memory->memuni.island, sizeof(memuni_u)); + memory->saved_town_tune = 0; + memory->friendship = 0; + memory->letter_info.exists = FALSE; + memory->letter_info.cond = mNpc_LETTER_RANK_BAD; + memory->letter_info.send_reply = FALSE; + memory->letter_info.has_present_cloth = FALSE; + mNpc_ClearAnimalMail(&memory->letter); + } - memory++; - } + memory++; + } } /* @unused */ @@ -363,75 +362,75 @@ extern void mNpc_CopyAnimalMemory(Anmmem_c* dst, Anmmem_c* src) { */ extern void mNpc_AddFriendship(Anmmem_c* memory, int amount) { - /* @BUG - devs checked for memory being NULL *after* deferencing it */ - #ifdef BUGFIXES - if (memory == NULL) { - return; - } - #endif +/* @BUG - devs checked for memory being NULL *after* deferencing it */ +#ifdef BUGFIXES + if (memory == NULL) { + return; + } +#endif - int friendship = memory->friendship + amount; + int friendship = memory->friendship + amount; - #ifndef BUGFIXES - if (memory == NULL) { - return; //??? - } - #endif +#ifndef BUGFIXES + if (memory == NULL) { + return; //??? + } +#endif - if (friendship > 127) { - memory->friendship = 127; - } - else if (friendship < 0) { - memory->friendship = 0; - } - else { - memory->friendship = friendship; - } + if (friendship > 127) { + memory->friendship = 127; + } else if (friendship < 0) { + memory->friendship = 0; + } else { + memory->friendship = friendship; + } } extern int mNpc_CheckFreeAnimalMemory(Anmmem_c* memory) { - int res = FALSE; + int res = FALSE; - if (mPr_NullCheckPersonalID(&memory->memory_player_id) == TRUE) { - res = TRUE; - } + if (mPr_NullCheckPersonalID(&memory->memory_player_id) == TRUE) { + res = TRUE; + } - return res; + return res; } extern void mNpc_RenewalAnimalMemory() { - Private_c* priv; - Animal_c* animal = Save_Get(animals); - Anmmem_c* memory; - int i; - int j; - int k; + Private_c* priv; + Animal_c* animal = Save_Get(animals); + Anmmem_c* memory; + int i; + int j; + int k; - for (i = 0; i < ANIMAL_NUM_MAX; i++) { - memory = animal->memories; + for (i = 0; i < ANIMAL_NUM_MAX; i++) { + memory = animal->memories; - for (j = 0; j < ANIMAL_MEMORY_NUM; j++) { - if (mNpc_CheckFreeAnimalMemory(memory) == FALSE && mLd_CheckThisLand(memory->memory_player_id.land_name, memory->memory_player_id.land_id) == TRUE) { - priv = Save_Get(private); + for (j = 0; j < ANIMAL_MEMORY_NUM; j++) { + if (mNpc_CheckFreeAnimalMemory(memory) == FALSE && + mLd_CheckThisLand(memory->memory_player_id.land_name, memory->memory_player_id.land_id) == TRUE) { + priv = Save_Get(private); - for (k = 0; k < PLAYER_NUM; k++) { - if (mPr_NullCheckPersonalID(&priv->player_ID) == FALSE && mPr_CheckCmpPersonalID(&priv->player_ID, &memory->memory_player_id) == TRUE) { - break; - } + for (k = 0; k < PLAYER_NUM; k++) { + if (mPr_NullCheckPersonalID(&priv->player_ID) == FALSE && + mPr_CheckCmpPersonalID(&priv->player_ID, &memory->memory_player_id) == TRUE) { + break; + } - priv++; + priv++; + } + + if (k == PLAYER_NUM) { + mNpc_ClearAnimalMemory(memory, 1); // player was deleted so free the memory + } + } + + memory++; } - if (k == PLAYER_NUM) { - mNpc_ClearAnimalMemory(memory, 1); // player was deleted so free the memory - } - } - - memory++; + animal++; } - - animal++; - } } /* @unused */ @@ -458,1492 +457,1429 @@ extern int mNpc_GetOldAnimalMemoryIdx(Anmmem_c* memory, int num) { */ extern int mNpc_GetFreeAnimalMemoryIdx(Anmmem_c* memory, int num) { - int res = -1; - int i; + int res = -1; + int i; - for (i = 0; i < num; i++) { - if (mNpc_CheckFreeAnimalMemory(memory) == TRUE) { - res = i; - break; + for (i = 0; i < num; i++) { + if (mNpc_CheckFreeAnimalMemory(memory) == TRUE) { + res = i; + break; + } + + memory++; } - memory++; - } - - return res; + return res; } extern int mNpc_GetOldPlayerAnimalMemoryIdx(Anmmem_c* memory, int num) { - Private_c* priv; - int res = -1; - int i; - int j; + Private_c* priv; + int res = -1; + int i; + int j; - for (i = 0; i < num; i++) { - if (mNpc_CheckFreeAnimalMemory(memory) == FALSE && mLd_CheckThisLand(memory->memory_player_id.land_name, memory->memory_player_id.land_id) == TRUE) { - priv = Save_Get(private); + for (i = 0; i < num; i++) { + if (mNpc_CheckFreeAnimalMemory(memory) == FALSE && + mLd_CheckThisLand(memory->memory_player_id.land_name, memory->memory_player_id.land_id) == TRUE) { + priv = Save_Get(private); - for (j = 0; j < PLAYER_NUM; j++) { - if (mPr_NullCheckPersonalID(&priv->player_ID) == FALSE && mPr_CheckCmpPersonalID(&priv->player_ID, &memory->memory_player_id) == TRUE) { - break; + for (j = 0; j < PLAYER_NUM; j++) { + if (mPr_NullCheckPersonalID(&priv->player_ID) == FALSE && + mPr_CheckCmpPersonalID(&priv->player_ID, &memory->memory_player_id) == TRUE) { + break; + } + + priv++; + } + + /* memory belongs to a player from this town which was deleted */ + if (j == PLAYER_NUM) { + res = i; + break; + } } - priv++; - } - - /* memory belongs to a player from this town which was deleted */ - if (j == PLAYER_NUM) { - res = i; - break; - } + memory++; } - memory++; - } - - return res; + return res; } extern int mNpc_ForceGetFreeAnimalMemoryIdx(Animal_c* animal, Anmmem_c* memory, int num) { - Anmmem_c* mem_p = memory; - Anmmem_c* chosen_mem = NULL; - int free_idx = mNpc_GetFreeAnimalMemoryIdx(memory, num); - int i; - - if (free_idx == -1) { - for (i = 0; i < num; i++) { - if (mLd_CheckThisLand(memory->memory_player_id.land_name, memory->memory_player_id.land_id) == FALSE) { - if (chosen_mem != NULL) { - if (chosen_mem->letter_info.exists == memory->letter_info.exists) { - if (chosen_mem->friendship > memory->friendship) { - chosen_mem = memory; - free_idx = i; - } - else if (chosen_mem->friendship == memory->friendship) { - if (lbRTC_IsOverTime(&chosen_mem->last_speak_time, &memory->last_speak_time) == lbRTC_LESS) { - chosen_mem = memory; - free_idx = i; - } - } - } - else if (memory->letter_info.exists == FALSE) { - chosen_mem = memory; - free_idx = i; - } - } - else { - chosen_mem = memory; - free_idx = i; - } - } - - memory++; - } - } - else { - chosen_mem = memory + free_idx; - } - - if (free_idx == -1 || chosen_mem == NULL) { - free_idx = mNpc_GetOldPlayerAnimalMemoryIdx(mem_p, num); + Anmmem_c* mem_p = memory; + Anmmem_c* chosen_mem = NULL; + int free_idx = mNpc_GetFreeAnimalMemoryIdx(memory, num); + int i; if (free_idx == -1) { - free_idx = 0; // all else failed, so pick the first memory + for (i = 0; i < num; i++) { + if (mLd_CheckThisLand(memory->memory_player_id.land_name, memory->memory_player_id.land_id) == FALSE) { + if (chosen_mem != NULL) { + if (chosen_mem->letter_info.exists == memory->letter_info.exists) { + if (chosen_mem->friendship > memory->friendship) { + chosen_mem = memory; + free_idx = i; + } else if (chosen_mem->friendship == memory->friendship) { + if (lbRTC_IsOverTime(&chosen_mem->last_speak_time, &memory->last_speak_time) == + lbRTC_LESS) { + chosen_mem = memory; + free_idx = i; + } + } + } else if (memory->letter_info.exists == FALSE) { + chosen_mem = memory; + free_idx = i; + } + } else { + chosen_mem = memory; + free_idx = i; + } + } + + memory++; + } + } else { + chosen_mem = memory + free_idx; } - chosen_mem = mem_p + free_idx; - } + if (free_idx == -1 || chosen_mem == NULL) { + free_idx = mNpc_GetOldPlayerAnimalMemoryIdx(mem_p, num); - if (chosen_mem != NULL) { - if (mNpc_CheckIslandAnimalID(&animal->id) == FALSE) { - mNpc_ClearAnimalMemory(chosen_mem, 1); - } - else { - mNpc_ClearIslandAnimalMemory(chosen_mem, 1); - } - } + if (free_idx == -1) { + free_idx = 0; // all else failed, so pick the first memory + } - return free_idx; + chosen_mem = mem_p + free_idx; + } + + if (chosen_mem != NULL) { + if (mNpc_CheckIslandAnimalID(&animal->id) == FALSE) { + mNpc_ClearAnimalMemory(chosen_mem, 1); + } else { + mNpc_ClearIslandAnimalMemory(chosen_mem, 1); + } + } + + return free_idx; } static void mNpc_ResetAnimalRelation(int idx) { - Animal_c* animal = Save_Get(animals); - u8* this_relations = animal[idx].animal_relations; - int i; + Animal_c* animal = Save_Get(animals); + u8* this_relations = animal[idx].animal_relations; + int i; - for (i = 0; i < ANIMAL_NUM_MAX; i++) { - this_relations[0] = 128; - this_relations++; - } - - for (i = 0; i < ANIMAL_NUM_MAX; i++) { - if (i != idx) { - animal->animal_relations[idx] = 128; + for (i = 0; i < ANIMAL_NUM_MAX; i++) { + this_relations[0] = 128; + this_relations++; } - animal++; - } + for (i = 0; i < ANIMAL_NUM_MAX; i++) { + if (i != idx) { + animal->animal_relations[idx] = 128; + } + + animal++; + } } static void mNpc_SetAnimalMemory_NotSetDay(PersonalID_c* pid, AnmPersonalID_c* anm_id, Anmmem_c* memory) { - if (memory != NULL) { - if (mNpc_CheckIslandAnimalID(anm_id) == FALSE) { - mNpc_ClearAnimalMemory(memory, 1); - } - else { - mNpc_ClearIslandAnimalMemory(memory, 1); - } + if (memory != NULL) { + if (mNpc_CheckIslandAnimalID(anm_id) == FALSE) { + mNpc_ClearAnimalMemory(memory, 1); + } else { + mNpc_ClearIslandAnimalMemory(memory, 1); + } - mPr_CopyPersonalID(&memory->memory_player_id, pid); - memory->friendship = 1; - } + mPr_CopyPersonalID(&memory->memory_player_id, pid); + memory->friendship = 1; + } } extern void mNpc_SetAnimalMemory(PersonalID_c* pid, AnmPersonalID_c* anm_id, Anmmem_c* memory) { - lbRTC_time_c* rtc_time = Common_GetPointer(time.rtc_time); + lbRTC_time_c* rtc_time = Common_GetPointer(time.rtc_time); - if (memory != NULL) { - mNpc_SetAnimalMemory_NotSetDay(pid, anm_id, memory); - lbRTC_TimeCopy(&memory->last_speak_time, rtc_time); - } + if (memory != NULL) { + mNpc_SetAnimalMemory_NotSetDay(pid, anm_id, memory); + lbRTC_TimeCopy(&memory->last_speak_time, rtc_time); + } } extern int mNpc_GetAnimalMemoryIdx(PersonalID_c* pid, Anmmem_c* memory, int num) { - int res = -1; - int i; + int res = -1; + int i; - for (i = 0; i < num; i++) { - if (mPr_CheckCmpPersonalID(&memory->memory_player_id, pid) == TRUE) { - res = i; - break; + for (i = 0; i < num; i++) { + if (mPr_CheckCmpPersonalID(&memory->memory_player_id, pid) == TRUE) { + res = i; + break; + } + + memory++; } - memory++; - } - - return res; + return res; } extern void mNpc_SetAnimalLastTalk(Animal_c* animal) { - Private_c* priv = Common_Get(now_private); - Anmmem_c* memory = NULL; + Private_c* priv = Common_Get(now_private); + Anmmem_c* memory = NULL; - if (priv != NULL && animal != NULL) { - int memory_idx = mNpc_GetAnimalMemoryIdx(&priv->player_ID, animal->memories, ANIMAL_MEMORY_NUM); + if (priv != NULL && animal != NULL) { + int memory_idx = mNpc_GetAnimalMemoryIdx(&priv->player_ID, animal->memories, ANIMAL_MEMORY_NUM); - if (memory_idx != -1) { - memory = animal->memories + memory_idx; + if (memory_idx != -1) { + memory = animal->memories + memory_idx; + } else { + memory_idx = mNpc_ForceGetFreeAnimalMemoryIdx(animal, animal->memories, ANIMAL_MEMORY_NUM); + + if (memory_idx != -1) { + memory = animal->memories + memory_idx; + mNpc_SetAnimalMemory(&priv->player_ID, &animal->id, memory); + } + } + + if (memory != NULL) { + lbRTC_TimeCopy(&memory->last_speak_time, Common_GetPointer(time.rtc_time)); + mLd_CopyLandName(memory->memuni.land.name, Save_Get(land_info).name); + memory->memuni.land.id = Save_Get(land_info).id; + memory->saved_town_tune = Save_Get(melody); + } } - else { - memory_idx = mNpc_ForceGetFreeAnimalMemoryIdx(animal, animal->memories, ANIMAL_MEMORY_NUM); - - if (memory_idx != -1) { - memory = animal->memories + memory_idx; - mNpc_SetAnimalMemory(&priv->player_ID, &animal->id, memory); - } - } - - if (memory != NULL) { - lbRTC_TimeCopy(&memory->last_speak_time, Common_GetPointer(time.rtc_time)); - mLd_CopyLandName(memory->memuni.land.name, Save_Get(land_info).name); - memory->memuni.land.id = Save_Get(land_info).id; - memory->saved_town_tune = Save_Get(melody); - } - } } extern void mNpc_SetAnimalPersonalID2Memory(AnmPersonalID_c* anm_id) { - Private_c* priv = Common_Get(now_private); + Private_c* priv = Common_Get(now_private); - if (priv != NULL) { - int anm_idx = mNpc_SearchAnimalPersonalID(anm_id); + if (priv != NULL) { + int anm_idx = mNpc_SearchAnimalPersonalID(anm_id); - if (anm_idx != -1) { - Animal_c* animal = Save_Get(animals) + anm_idx; - int mem_idx = mNpc_GetAnimalMemoryIdx(&priv->player_ID, animal->memories, ANIMAL_MEMORY_NUM); + if (anm_idx != -1) { + Animal_c* animal = Save_Get(animals) + anm_idx; + int mem_idx = mNpc_GetAnimalMemoryIdx(&priv->player_ID, animal->memories, ANIMAL_MEMORY_NUM); - if (mem_idx == -1) { - int free_idx = mNpc_ForceGetFreeAnimalMemoryIdx(animal, animal->memories, ANIMAL_MEMORY_NUM); + if (mem_idx == -1) { + int free_idx = mNpc_ForceGetFreeAnimalMemoryIdx(animal, animal->memories, ANIMAL_MEMORY_NUM); - if (free_idx != -1) { - mNpc_SetAnimalMemory_NotSetDay(&priv->player_ID, &animal->id, animal->memories + free_idx); + if (free_idx != -1) { + mNpc_SetAnimalMemory_NotSetDay(&priv->player_ID, &animal->id, animal->memories + free_idx); + } + } } - } } - } } extern int mNpc_GetHighestFriendshipIdx(Anmmem_c* memory, int num) { - s8 max = 0; - int res = -1; - int i; + s8 max = 0; + int res = -1; + int i; - for (i = 0; i < num; i++) { - if (mNpc_CheckFreeAnimalMemory(memory) == FALSE) { - if (max <= memory->friendship) { - max = memory->friendship; - res = i; - } + for (i = 0; i < num; i++) { + if (mNpc_CheckFreeAnimalMemory(memory) == FALSE) { + if (max <= memory->friendship) { + max = memory->friendship; + res = i; + } + } + + memory++; } - memory++; - } - - return res; + return res; } static int mNpc_SelectBestFriend(Anmmem_c** best_friend_mem, Anmmem_c* memory, s8* best_friend_friendship) { - int res = FALSE; - Anmmem_c* best_friend; + int res = FALSE; + Anmmem_c* best_friend; - if (memory->friendship > best_friend_friendship[0]) { - best_friend_friendship[0] = memory->friendship; - best_friend_mem[0] = memory; - res = TRUE; - } - else if (memory->friendship == best_friend_friendship[0]) { - best_friend = best_friend_mem[0]; - - if (best_friend != NULL) { - if (best_friend->letter_info.exists == memory->letter_info.exists) { - if (lbRTC_IsOverTime(&best_friend->last_speak_time, &memory->last_speak_time) == lbRTC_LESS) { - best_friend_mem[0] = memory; - res = TRUE; - } - } - else if (memory->letter_info.exists == TRUE) { + if (memory->friendship > best_friend_friendship[0]) { + best_friend_friendship[0] = memory->friendship; best_friend_mem[0] = memory; res = TRUE; - } - } - else { - best_friend_mem[0] = memory; - res = TRUE; - } - } + } else if (memory->friendship == best_friend_friendship[0]) { + best_friend = best_friend_mem[0]; - return res; + if (best_friend != NULL) { + if (best_friend->letter_info.exists == memory->letter_info.exists) { + if (lbRTC_IsOverTime(&best_friend->last_speak_time, &memory->last_speak_time) == lbRTC_LESS) { + best_friend_mem[0] = memory; + res = TRUE; + } + } else if (memory->letter_info.exists == TRUE) { + best_friend_mem[0] = memory; + res = TRUE; + } + } else { + best_friend_mem[0] = memory; + res = TRUE; + } + } + + return res; } extern int mNpc_GetAnimalMemoryBestFriend(Anmmem_c* memory, int num) { - Anmmem_c* memory_p = memory; - Anmmem_c* best_friend = NULL; - s8 best_friendship = 0; - int res = -1; - int i; + Anmmem_c* memory_p = memory; + Anmmem_c* best_friend = NULL; + s8 best_friendship = 0; + int res = -1; + int i; - for (i = 0; i < num; i++) { - if (mNpc_CheckFreeAnimalMemory(memory) == FALSE && mNpc_SelectBestFriend(&best_friend, memory, &best_friendship) == TRUE) { - res = i; + for (i = 0; i < num; i++) { + if (mNpc_CheckFreeAnimalMemory(memory) == FALSE && + mNpc_SelectBestFriend(&best_friend, memory, &best_friendship) == TRUE) { + res = i; + } + + memory++; } - memory++; - } + memory = memory_p; + if (res != -1) { + memory = &memory[res]; - memory = memory_p; - if (res != -1) { - memory = &memory[res]; - - if (memory->friendship < 80) { - res = -1; // minimum best friend friendship value failed + if (memory->friendship < 80) { + res = -1; // minimum best friend friendship value failed + } } - } - return res; + return res; } static int mNpc_GetAnimalMemoryFriend_Land_Sex(Anmmem_c* memory, int num, int sex) { - Anmmem_c* best_friend = NULL; - s8 best_friendship = 0; - int priv_idx; - int res = -1; - int i; + Anmmem_c* best_friend = NULL; + s8 best_friendship = 0; + int priv_idx; + int res = -1; + int i; - for (i = 0; i < num; i++) { - if (mNpc_CheckFreeAnimalMemory(memory) == FALSE) { - priv_idx = mPr_GetPrivateIdx(&memory->memory_player_id); + for (i = 0; i < num; i++) { + if (mNpc_CheckFreeAnimalMemory(memory) == FALSE) { + priv_idx = mPr_GetPrivateIdx(&memory->memory_player_id); - if (priv_idx != -1 && Save_Get(private[priv_idx]).gender == sex && mNpc_SelectBestFriend(&best_friend, memory, &best_friendship) == TRUE) { - res = i; - } + if (priv_idx != -1 && Save_Get(private[priv_idx]).gender == sex && + mNpc_SelectBestFriend(&best_friend, memory, &best_friendship) == TRUE) { + res = i; + } + } + + memory++; } - memory++; - } - - return res; + return res; } extern int mNpc_GetAnimalMemoryNum(Anmmem_c* memory, int count) { - int num = 0; - int i; + int num = 0; + int i; - for (i = 0; i < count; i++) { - if (mNpc_CheckFreeAnimalMemory(memory) == FALSE) { - num++; + for (i = 0; i < count; i++) { + if (mNpc_CheckFreeAnimalMemory(memory) == FALSE) { + num++; + } + + memory++; } - memory++; - } - - return num; + return num; } extern int mNpc_GetAnimalMemoryLetterNum(Anmmem_c* memory, int count) { - int num = 0; - int i; + int num = 0; + int i; - for (i = 0; i < count; i++) { - if (mNpc_CheckFreeAnimalMemory(memory) == FALSE && memory->letter_info.exists == TRUE) { - num++; + for (i = 0; i < count; i++) { + if (mNpc_CheckFreeAnimalMemory(memory) == FALSE && memory->letter_info.exists == TRUE) { + num++; + } + + memory++; } - memory++; - } - - return num; + return num; } extern int mNpc_GetAnimalMemoryLandKindNum(Anmmem_c* memory, int count) { - Anmmem_c* memory2; - Anmlnd_c* land; - Anmlnd_c* land2; - u8 bitfield = 0b11111111; - int num = 0; - int i; - int j; + Anmmem_c* memory2; + Anmlnd_c* land; + Anmlnd_c* land2; + u8 bitfield = 0b11111111; + int num = 0; + int i; + int j; - for (i = 0; i < count; i++) { - land = &memory->memuni.land; - - if (mNpc_CheckFreeAnimalMemory(memory) == FALSE) { - if (((bitfield >> i) & 1) == 1) { - memory2 = memory + 1; - land2 = &memory2->memuni.land; + for (i = 0; i < count; i++) { + land = &memory->memuni.land; - for (j = i + 1; j < count; j++) { - if (((bitfield >> j) & 1) == 1) { - if (mLd_CheckCmpLand(land->name, land->id, land2->name, land2->id) == TRUE) { - bitfield &= ~(1 << j); // duplicate town here, so remove this memory from being checked + if (mNpc_CheckFreeAnimalMemory(memory) == FALSE) { + if (((bitfield >> i) & 1) == 1) { + memory2 = memory + 1; + land2 = &memory2->memuni.land; + + for (j = i + 1; j < count; j++) { + if (((bitfield >> j) & 1) == 1) { + if (mLd_CheckCmpLand(land->name, land->id, land2->name, land2->id) == TRUE) { + bitfield &= ~(1 << j); // duplicate town here, so remove this memory from being checked + } + } + + memory2++; + } } - } - memory2++; + num++; + } else { + bitfield &= ~(1 << i); } - } - num++; - } - else { - bitfield &= ~(1 << i); + memory++; } - memory++; - } - - return num; + return num; } extern void mNpc_ClearAnimalInfo(Animal_c* animal) { - bzero(animal, sizeof(Animal_c)); - mNpc_ClearAnimalPersonalID(&animal->id); - mNpc_ClearAnimalMemory(animal->memories, ANIMAL_MEMORY_NUM); - animal->cloth = EMPTY_NO; - animal->home_info.type_unused = 0; - animal->home_info.block_x = 0xFF; - animal->home_info.block_z = 0xFF; - animal->home_info.ut_x = 0xFF; - animal->home_info.ut_z = 0xFF; - mNpc_ClearBufSpace1(animal->catchphrase, ANIMAL_CATCHPHRASE_LEN); - mQst_ClearContest(&animal->contest_quest); - mLd_ClearLandName(animal->anmuni.previous_land_name); - animal->previous_land_id = 0; - animal->remove_info = 0; - animal->is_home = TRUE; - mPr_ClearPlayerName(animal->parent_name); + bzero(animal, sizeof(Animal_c)); + mNpc_ClearAnimalPersonalID(&animal->id); + mNpc_ClearAnimalMemory(animal->memories, ANIMAL_MEMORY_NUM); + animal->cloth = EMPTY_NO; + animal->home_info.type_unused = 0; + animal->home_info.block_x = 0xFF; + animal->home_info.block_z = 0xFF; + animal->home_info.ut_x = 0xFF; + animal->home_info.ut_z = 0xFF; + mNpc_ClearBufSpace1(animal->catchphrase, ANIMAL_CATCHPHRASE_LEN); + mQst_ClearContest(&animal->contest_quest); + mLd_ClearLandName(animal->anmuni.previous_land_name); + animal->previous_land_id = 0; + animal->remove_info = 0; + animal->is_home = TRUE; + mPr_ClearPlayerName(animal->parent_name); } extern void mNpc_ClearIslandAnimalInfo(Animal_c* animal) { - bzero(animal, sizeof(Animal_c)); - mNpc_ClearAnimalPersonalID(&animal->id); - mNpc_ClearIslandAnimalMemory(animal->memories, ANIMAL_MEMORY_NUM); - animal->cloth = EMPTY_NO; - animal->home_info.type_unused = 0; - animal->home_info.block_x = 0xFF; - animal->home_info.block_z = 0xFF; - animal->home_info.ut_x = 0xFF; - animal->home_info.ut_z = 0xFF; - mNpc_ClearBufSpace1(animal->catchphrase, ANIMAL_CATCHPHRASE_LEN); - mQst_ClearContest(&animal->contest_quest); - animal->remove_info = 0; - animal->is_home = TRUE; - mPr_ClearPlayerName(animal->parent_name); + bzero(animal, sizeof(Animal_c)); + mNpc_ClearAnimalPersonalID(&animal->id); + mNpc_ClearIslandAnimalMemory(animal->memories, ANIMAL_MEMORY_NUM); + animal->cloth = EMPTY_NO; + animal->home_info.type_unused = 0; + animal->home_info.block_x = 0xFF; + animal->home_info.block_z = 0xFF; + animal->home_info.ut_x = 0xFF; + animal->home_info.ut_z = 0xFF; + mNpc_ClearBufSpace1(animal->catchphrase, ANIMAL_CATCHPHRASE_LEN); + mQst_ClearContest(&animal->contest_quest); + animal->remove_info = 0; + animal->is_home = TRUE; + mPr_ClearPlayerName(animal->parent_name); } extern void mNpc_ClearAnyAnimalInfo(Animal_c* animal, int count) { - int i; + int i; - for (i = 0; i < count; i++) { - mNpc_ClearAnimalInfo(animal); - animal++; - } + for (i = 0; i < count; i++) { + mNpc_ClearAnimalInfo(animal); + animal++; + } } extern int mNpc_CheckFreeAnimalInfo(Animal_c* animal) { - int res = FALSE; + int res = FALSE; - if ((animal->home_info.block_x == 0xFF && animal->home_info.block_z == 0xFF) && ITEM_NAME_GET_TYPE(animal->id.npc_id) != NAME_TYPE_NPC) { - res = TRUE; - } + if ((animal->home_info.block_x == 0xFF && animal->home_info.block_z == 0xFF) && + ITEM_NAME_GET_TYPE(animal->id.npc_id) != NAME_TYPE_NPC) { + res = TRUE; + } - return res; + return res; } extern int mNpc_GetFreeAnimalInfo(Animal_c* animal, int count) { - int res = -1; - int i; + int res = -1; + int i; - for (i = 0; i < count; i++) { - if (mNpc_CheckFreeAnimalInfo(animal) == TRUE) { - res = i; - break; + for (i = 0; i < count; i++) { + if (mNpc_CheckFreeAnimalInfo(animal) == TRUE) { + res = i; + break; + } + + animal++; } - animal++; - } - - return res; + return res; } extern int mNpc_UseFreeAnimalInfo(Animal_c* animal, int count) { - int free_idx = mNpc_GetFreeAnimalInfo(animal, count); - - if (free_idx != -1) { - mNpc_ClearAnimalInfo(animal + free_idx); - mNpc_ResetAnimalRelation(free_idx); - } + int free_idx = mNpc_GetFreeAnimalInfo(animal, count); - return free_idx; + if (free_idx != -1) { + mNpc_ClearAnimalInfo(animal + free_idx); + mNpc_ResetAnimalRelation(free_idx); + } + + return free_idx; } extern void mNpc_CopyAnimalInfo(Animal_c* dst, Animal_c* src) { - mem_copy((u8*)dst, (u8*)src, sizeof(Animal_c)); + mem_copy((u8*)dst, (u8*)src, sizeof(Animal_c)); } extern int mNpc_SearchAnimalinfo(Animal_c* animal, mActor_name_t npc_id, int count) { - int i; - - animal = animal + (count - 1); - for (i = count - 1; i >= 0; i--) { - if (animal->id.npc_id == npc_id) { - return i; + int i; + + animal = animal + (count - 1); + for (i = count - 1; i >= 0; i--) { + if (animal->id.npc_id == npc_id) { + return i; + } + + animal--; } - animal--; - } - - return -1; + return -1; } extern Animal_c* mNpc_GetAnimalInfoP(mActor_name_t npc_id) { - Animal_c* animal = NULL; - int idx = mNpc_SearchAnimalinfo(Save_Get(animals), npc_id, ANIMAL_NUM_MAX); + Animal_c* animal = NULL; + int idx = mNpc_SearchAnimalinfo(Save_Get(animals), npc_id, ANIMAL_NUM_MAX); - if (idx != -1) { - animal = Save_Get(animals) + idx; - } + if (idx != -1) { + animal = Save_Get(animals) + idx; + } - return animal; + return animal; } extern int mNpc_SearchAnimalPersonalID(AnmPersonalID_c* anm_pid) { - Animal_c* animal = Save_Get(animals); - int res = -1; - int i; + Animal_c* animal = Save_Get(animals); + int res = -1; + int i; - if (anm_pid != NULL && !mNpc_CheckFreeAnimalPersonalID(anm_pid)) { - for (i = 0; i < ANIMAL_NUM_MAX; i++) { - if (mNpc_CheckCmpAnimalPersonalID(anm_pid, &animal->id) == TRUE) { - res = i; - break; - } + if (anm_pid != NULL && !mNpc_CheckFreeAnimalPersonalID(anm_pid)) { + for (i = 0; i < ANIMAL_NUM_MAX; i++) { + if (mNpc_CheckCmpAnimalPersonalID(anm_pid, &animal->id) == TRUE) { + res = i; + break; + } - animal++; + animal++; + } } - } - return res; + return res; } -extern AnmPersonalID_c* mNpc_GetOtherAnimalPersonalIDOtherBlock(AnmPersonalID_c* pids, int count, int bx, int bz, int check_flag) { - Animal_c* animal; - AnmPersonalID_c* other_id; - int npc_max; - int homes_in_block; - int ids = count; - u16 bitfield; - int j; - int i; +extern AnmPersonalID_c* mNpc_GetOtherAnimalPersonalIDOtherBlock(AnmPersonalID_c* pids, int count, int bx, int bz, + int check_flag) { + Animal_c* animal; + AnmPersonalID_c* other_id; + int npc_max; + int homes_in_block; + int ids = count; + u16 bitfield; + int j; + int i; - other_id = NULL; - npc_max = Save_Get(now_npc_max); - animal = Save_Get(animals); - homes_in_block = 0; - ids = count; - bitfield = 0xFFFF; + other_id = NULL; + npc_max = Save_Get(now_npc_max); + animal = Save_Get(animals); + homes_in_block = 0; + ids = count; + bitfield = 0xFFFF; - if (bx == 0xFF || bz == 0xFF) { - check_flag = FALSE; - } - - if (pids == NULL && count != 0) { - count = 0; - } - - /* clear any uninitialized personal ids */ - for (i = 0; i < count; i++) { - if (mNpc_CheckFreeAnimalPersonalID(pids + i) == TRUE) { - ids--; - bitfield &= ~(1 << i); + if (bx == 0xFF || bz == 0xFF) { + check_flag = FALSE; } - } - /* clear any npcs who are in the list and live in the acre */ - if (check_flag == TRUE) { - for (j = 0; j < ANIMAL_NUM_MAX; j++) { - if (animal->home_info.block_x == bx && animal->home_info.block_z == bz) { - homes_in_block++; + if (pids == NULL && count != 0) { + count = 0; + } - for (i = 0; i < count; i++) { - if (((bitfield >> i) & 1) == 1 && mNpc_CheckCmpAnimalPersonalID(&animal->id, &pids[i]) == TRUE) { + /* clear any uninitialized personal ids */ + for (i = 0; i < count; i++) { + if (mNpc_CheckFreeAnimalPersonalID(pids + i) == TRUE) { ids--; bitfield &= ~(1 << i); - break; - } } - } - - animal++; } - } - if (npc_max > (ids + homes_in_block) && count < ANIMAL_NUM_MAX) { - int valid; - int t; + /* clear any npcs who are in the list and live in the acre */ + if (check_flag == TRUE) { + for (j = 0; j < ANIMAL_NUM_MAX; j++) { + if (animal->home_info.block_x == bx && animal->home_info.block_z == bz) { + homes_in_block++; - animal = Save_Get(animals); - homes_in_block = RANDOM((npc_max - ids) - homes_in_block); + for (i = 0; i < count; i++) { + if (((bitfield >> i) & 1) == 1 && mNpc_CheckCmpAnimalPersonalID(&animal->id, &pids[i]) == TRUE) { + ids--; + bitfield &= ~(1 << i); + break; + } + } + } - for (j = 0; j < ANIMAL_NUM_MAX; j++) { - i = 0; - valid = TRUE; - - if (!mNpc_CheckFreeAnimalPersonalID(&animal->id)) { - for (npc_max = 0; npc_max < count; npc_max++) { - if (((bitfield >> npc_max) & 1) == 1 && !mNpc_CheckCmpAnimalPersonalID(&animal->id, &pids[npc_max])) { - i++; - } + animal++; } - - if (i != ids) { - valid = FALSE; - } - else if (check_flag == TRUE && animal->home_info.block_x == bx && animal->home_info.block_z == bz) { - if (homes_in_block > 0) { - homes_in_block--; - } - - valid = FALSE; - } - - if (valid == TRUE) { - if (homes_in_block == 0) { - other_id = &animal->id; - break; - } - else { - homes_in_block--; - } - } - } - - animal++; } - } - return other_id; + if (npc_max > (ids + homes_in_block) && count < ANIMAL_NUM_MAX) { + int valid; + int t; + + animal = Save_Get(animals); + homes_in_block = RANDOM((npc_max - ids) - homes_in_block); + + for (j = 0; j < ANIMAL_NUM_MAX; j++) { + i = 0; + valid = TRUE; + + if (!mNpc_CheckFreeAnimalPersonalID(&animal->id)) { + for (npc_max = 0; npc_max < count; npc_max++) { + if (((bitfield >> npc_max) & 1) == 1 && + !mNpc_CheckCmpAnimalPersonalID(&animal->id, &pids[npc_max])) { + i++; + } + } + + if (i != ids) { + valid = FALSE; + } else if (check_flag == TRUE && animal->home_info.block_x == bx && animal->home_info.block_z == bz) { + if (homes_in_block > 0) { + homes_in_block--; + } + + valid = FALSE; + } + + if (valid == TRUE) { + if (homes_in_block == 0) { + other_id = &animal->id; + break; + } else { + homes_in_block--; + } + } + } + + animal++; + } + } + + return other_id; } extern AnmPersonalID_c* mNpc_GetOtherAnimalPersonalID(AnmPersonalID_c* pids, int count) { - return mNpc_GetOtherAnimalPersonalIDOtherBlock(pids, count, 0, 0, FALSE); + return mNpc_GetOtherAnimalPersonalIDOtherBlock(pids, count, 0, 0, FALSE); } extern void mNpc_SetAnimalThisLand(Animal_c* animal, int count) { - mLd_land_info_c* land_info = Save_GetPointer(land_info); + mLd_land_info_c* land_info = Save_GetPointer(land_info); - for (count; count != 0; count--) { - if (!mNpc_CheckFreeAnimalPersonalID(&animal->id)) { - animal->id.land_id = land_info->id; - mLd_CopyLandName(animal->id.land_name, land_info->name); + for (count; count != 0; count--) { + if (!mNpc_CheckFreeAnimalPersonalID(&animal->id)) { + animal->id.land_id = land_info->id; + mLd_CopyLandName(animal->id.land_name, land_info->name); + } + + animal++; } - - animal++; - } } extern int mNpc_GetSameLooksNum(u8 looks) { - Animal_c* animal = Save_Get(animals); - int i; - int num = 0; + Animal_c* animal = Save_Get(animals); + int i; + int num = 0; - if (looks < mNpc_LOOKS_UNSET) { - for (i = 0; i < ANIMAL_NUM_MAX; i++) { - if (looks == animal->id.looks) { - num++; - } + if (looks < mNpc_LOOKS_UNSET) { + for (i = 0; i < ANIMAL_NUM_MAX; i++) { + if (looks == animal->id.looks) { + num++; + } - animal++; + animal++; + } } - } - return num; + return num; } extern int mNpc_CheckNpcExistBlock(int idx, int check_bx, int check_bz) { - int bx; - int bz; - int res = FALSE; + int bx; + int bz; + int res = FALSE; - if (idx >= 0 && idx < (ANIMAL_NUM_MAX + 1)) { - mNpc_NpcList_c* list = Common_GetPointer(npclist[idx]); - - if (mFI_Wpos2BlockNum(&bx, &bz, list->position) == TRUE && bx == check_bx && bz == check_bz) { - res = TRUE; + if (idx >= 0 && idx < (ANIMAL_NUM_MAX + 1)) { + mNpc_NpcList_c* list = Common_GetPointer(npclist[idx]); + + if (mFI_Wpos2BlockNum(&bx, &bz, list->position) == TRUE && bx == check_bx && bz == check_bz) { + res = TRUE; + } } - } - return res; + return res; } extern void mNpc_Mail2AnimalMail(Anmplmail_c* animal_mail, Mail_c* mail) { - mem_copy(animal_mail->body, mail->content.body, MAIL_BODY_LEN); - mem_copy(animal_mail->header, mail->content.header, MAIL_HEADER_LEN); - mem_copy(animal_mail->footer, mail->content.footer, MAIL_FOOTER_LEN); + mem_copy(animal_mail->body, mail->content.body, MAIL_BODY_LEN); + mem_copy(animal_mail->header, mail->content.header, MAIL_HEADER_LEN); + mem_copy(animal_mail->footer, mail->content.footer, MAIL_FOOTER_LEN); - animal_mail->header_back_start = mail->content.header_back_start; - animal_mail->font = mail->content.font; - animal_mail->present = mail->present; - animal_mail->paper_type = mail->content.paper_type; + animal_mail->header_back_start = mail->content.header_back_start; + animal_mail->font = mail->content.font; + animal_mail->present = mail->present; + animal_mail->paper_type = mail->content.paper_type; } extern void mNpc_AnimalMail2Mail(Mail_c* mail, Anmplmail_c* animal_mail, PersonalID_c* pid, AnmPersonalID_c* anm_id) { - mem_copy(mail->content.body, animal_mail->body, MAIL_BODY_LEN); - mem_copy(mail->content.header, animal_mail->header, MAIL_HEADER_LEN); - mem_copy(mail->content.footer, animal_mail->footer, MAIL_FOOTER_LEN); + mem_copy(mail->content.body, animal_mail->body, MAIL_BODY_LEN); + mem_copy(mail->content.header, animal_mail->header, MAIL_HEADER_LEN); + mem_copy(mail->content.footer, animal_mail->footer, MAIL_FOOTER_LEN); - mail->content.header_back_start = animal_mail->header_back_start; - mail->content.font = animal_mail->font; - mail->present = animal_mail->present; - mail->content.paper_type = animal_mail->paper_type; + mail->content.header_back_start = animal_mail->header_back_start; + mail->content.font = animal_mail->font; + mail->present = animal_mail->present; + mail->content.paper_type = animal_mail->paper_type; - if (pid != NULL) { - mPr_CopyPersonalID(&mail->header.sender.personalID, pid); - mail->header.sender.type = mMl_NAME_TYPE_PLAYER; - } + if (pid != NULL) { + mPr_CopyPersonalID(&mail->header.sender.personalID, pid); + mail->header.sender.type = mMl_NAME_TYPE_PLAYER; + } - if (anm_id != NULL) { - mMl_set_mail_name_npcinfo(&mail->header.recipient, anm_id); - } + if (anm_id != NULL) { + mMl_set_mail_name_npcinfo(&mail->header.recipient, anm_id); + } } static int mNpc_CheckMailChar(u8 c) { - if ( - (c == CHAR_EXCLAMATION) || - (c == CHAR_QUOTATION) || - (c == CHAR_UNDERSCORE) || - (c == CHAR_HYPHEN) || - (c == CHAR_SYMBOL_ANNOYED) || - ((c >= CHAR_PERCENT) && (c <= CHAR_AT_SIGN)) || - ((c >= CHAR_CONTROL_CODE) && (c <= CHAR_INTERPUNCT)) - ) { - return TRUE; - } + if ((c == CHAR_EXCLAMATION) || (c == CHAR_QUOTATION) || (c == CHAR_UNDERSCORE) || (c == CHAR_HYPHEN) || + (c == CHAR_SYMBOL_ANNOYED) || ((c >= CHAR_PERCENT) && (c <= CHAR_AT_SIGN)) || + ((c >= CHAR_CONTROL_CODE) && (c <= CHAR_INTERPUNCT))) { + return TRUE; + } - return FALSE; + return FALSE; } extern int mNpc_CheckNormalMail_sub(int* char_num, u8* body) { - u8 last_char = CHAR_SPACE; - int run_len = 1; - int consecutive_chars = FALSE; - int t = 0; - int i; + u8 last_char = CHAR_SPACE; + int run_len = 1; + int consecutive_chars = FALSE; + int t = 0; + int i; - char_num[0] = 0; + char_num[0] = 0; - for (i = 0; i < MAIL_BODY_LEN; i++) { - if (body[0] != CHAR_SPACE) { + for (i = 0; i < MAIL_BODY_LEN; i++) { + if (body[0] != CHAR_SPACE) { - if (last_char == body[0]) { - run_len++; - - if (run_len >= 3) { - if (mNpc_CheckMailChar(body[0]) == TRUE) { - if (run_len >= 8) { - consecutive_chars = TRUE; - break; + if (last_char == body[0]) { + run_len++; + + if (run_len >= 3) { + if (mNpc_CheckMailChar(body[0]) == TRUE) { + if (run_len >= 8) { + consecutive_chars = TRUE; + break; + } + } else { + consecutive_chars = TRUE; + break; + } + } + } else { + run_len = 0; + last_char = body[0]; } - } - else { - consecutive_chars = TRUE; - break; - } + + char_num[0]++; } - } - else { - run_len = 0; - last_char = body[0]; - } - char_num[0]++; + body++; + t++; } - body++; - t++; - } + for (i = t; i < MAIL_BODY_LEN; i++) { + if (body[0] != CHAR_SPACE) { + char_num[0]++; + } - for (i = t; i < MAIL_BODY_LEN; i++) { - if (body[0] != CHAR_SPACE) { - char_num[0]++; + body++; } - body++; - } - - return consecutive_chars; + return consecutive_chars; } extern u8 mNpc_CheckNormalMail_length(int* len, u8* body) { - int hit_chars; - u8 rank = mNpc_LETTER_RANK_NUM; - int hit_rate = mMC_get_mail_hit_rate(&hit_chars, body, NULL); - int run_on = mNpc_CheckNormalMail_sub(len, body); + int hit_chars; + u8 rank = mNpc_LETTER_RANK_NUM; + int hit_rate = mMC_get_mail_hit_rate(&hit_chars, body, NULL); + int run_on = mNpc_CheckNormalMail_sub(len, body); - if (hit_chars < 3) { - if (len[0] < 5) { - rank = mNpc_LETTER_RANK_BAD; + if (hit_chars < 3) { + if (len[0] < 5) { + rank = mNpc_LETTER_RANK_BAD; + } else if (run_on == TRUE) { + rank = mNpc_LETTER_RANK_BAD; + } + } else if (hit_rate >= 30) { + rank = mNpc_LETTER_RANK_OK; + } else if (run_on == TRUE) { + rank = mNpc_LETTER_RANK_BAD; } - else if (run_on == TRUE) { - rank = mNpc_LETTER_RANK_BAD; - } - } - else if (hit_rate >= 30) { - rank = mNpc_LETTER_RANK_OK; - } - else if (run_on == TRUE) { - rank = mNpc_LETTER_RANK_BAD; - } - return rank; + return rank; } extern u8 mNpc_CheckNormalMail_nes(u8* body) { - u8 rank = mNpc_LETTER_RANK_NUM; - int key_hit = mMck_check_key_hit_nes(body); + u8 rank = mNpc_LETTER_RANK_NUM; + int key_hit = mMck_check_key_hit_nes(body); - if (key_hit >= 100) { - rank = mNpc_LETTER_RANK_OK; - } - else if (key_hit < 50) { - rank = mNpc_LETTER_RANK_BAD; - } + if (key_hit >= 100) { + rank = mNpc_LETTER_RANK_OK; + } else if (key_hit < 50) { + rank = mNpc_LETTER_RANK_BAD; + } - return rank; + return rank; } static u8 mNpc_CheckNormalMail(u8* body) { - return mNpc_CheckNormalMail_nes(body); + return mNpc_CheckNormalMail_nes(body); } static int mNpc_SetMailCondThisLand(Anmmem_c* memory, u8* body) { - u8 letter_rank; + u8 letter_rank; - memory->letter.date.year = Common_Get(time.rtc_time).year; - memory->letter.date.month = Common_Get(time.rtc_time).month; - memory->letter.date.day = Common_Get(time.rtc_time).day; + memory->letter.date.year = Common_Get(time.rtc_time).year; + memory->letter.date.month = Common_Get(time.rtc_time).month; + memory->letter.date.day = Common_Get(time.rtc_time).day; - letter_rank = mNpc_CheckNormalMail(body); + letter_rank = mNpc_CheckNormalMail(body); - if (letter_rank < mNpc_LETTER_RANK_NUM) { - memory->letter_info.cond = letter_rank; - memory->letter_info.send_reply = TRUE; - } + if (letter_rank < mNpc_LETTER_RANK_NUM) { + memory->letter_info.cond = letter_rank; + memory->letter_info.send_reply = TRUE; + } - return letter_rank; + return letter_rank; } static int mNpc_SetMailCondOtherLand(Animal_c* animal, u8* body) { - u8 letter_rank = mNpc_CheckNormalMail(body); + u8 letter_rank = mNpc_CheckNormalMail(body); - if (letter_rank < mNpc_LETTER_RANK_NUM) { - Private_c* priv = Common_Get(now_private); - Anmremail_c* remail = &priv->remail; + if (letter_rank < mNpc_LETTER_RANK_NUM) { + Private_c* priv = Common_Get(now_private); + Anmremail_c* remail = &priv->remail; - remail->date.year = Common_Get(time.rtc_time).year; - remail->date.month = Common_Get(time.rtc_time).month; - remail->date.day = Common_Get(time.rtc_time).day; - remail->flags.cond = letter_rank; - remail->flags.looks = animal->id.looks; + remail->date.year = Common_Get(time.rtc_time).year; + remail->date.month = Common_Get(time.rtc_time).month; + remail->date.day = Common_Get(time.rtc_time).day; + remail->flags.cond = letter_rank; + remail->flags.looks = animal->id.looks; - mNpc_GetNpcWorldNameAnm(remail->name, &animal->id); - mLd_CopyLandName(remail->land_name, mLd_GetLandName()); - } + mNpc_GetNpcWorldNameAnm(remail->name, &animal->id); + mLd_CopyLandName(remail->land_name, mLd_GetLandName()); + } - return letter_rank; + return letter_rank; } static int mNpc_SetRemailCond(Animal_c* animal, Anmmem_c* memory, u8* body) { - if (mLd_PlayerManKindCheck() == FALSE) { - return mNpc_SetMailCondThisLand(memory, body); - } - else { - return mNpc_SetMailCondOtherLand(animal, body); - } + if (mLd_PlayerManKindCheck() == FALSE) { + return mNpc_SetMailCondThisLand(memory, body); + } else { + return mNpc_SetMailCondOtherLand(animal, body); + } } static int mNpc_SetPresentCloth(Animal_c* animal, PersonalID_c* player_id, mActor_name_t cloth) { - Anmmem_c* mem; - int res = FALSE; + Anmmem_c* mem; + int res = FALSE; - if ( - animal != NULL && - player_id != NULL && - ITEM_NAME_GET_TYPE(cloth) == NAME_TYPE_ITEM1 && - ITEM_NAME_GET_CAT(cloth) == ITEM1_CAT_CLOTH && - !mNpc_CheckFreeAnimalPersonalID(&animal->id) && - !mPr_NullCheckPersonalID(player_id) - ) { - int memory_idx = mNpc_GetAnimalMemoryIdx(player_id, animal->memories, ANIMAL_MEMORY_NUM); + if (animal != NULL && player_id != NULL && ITEM_NAME_GET_TYPE(cloth) == NAME_TYPE_ITEM1 && + ITEM_NAME_GET_CAT(cloth) == ITEM1_CAT_CLOTH && !mNpc_CheckFreeAnimalPersonalID(&animal->id) && + !mPr_NullCheckPersonalID(player_id)) { + int memory_idx = mNpc_GetAnimalMemoryIdx(player_id, animal->memories, ANIMAL_MEMORY_NUM); - if (memory_idx != -1) { - Anmmem_c* m = &animal->memories[memory_idx]; - - if (m->friendship > 30) { - Anmmem_c* memory = animal->memories; - int i; + if (memory_idx != -1) { + Anmmem_c* m = &animal->memories[memory_idx]; - for (i = 0; i < ANIMAL_MEMORY_NUM; i++) { - if (i == memory_idx) { - memory->letter_info.has_present_cloth = TRUE; - } - else { - memory->letter_info.has_present_cloth = FALSE; - } + if (m->friendship > 30) { + Anmmem_c* memory = animal->memories; + int i; - memory->letter_info.wearing_present_cloth = FALSE; - memory++; + for (i = 0; i < ANIMAL_MEMORY_NUM; i++) { + if (i == memory_idx) { + memory->letter_info.has_present_cloth = TRUE; + } else { + memory->letter_info.has_present_cloth = FALSE; + } + + memory->letter_info.wearing_present_cloth = FALSE; + memory++; + } + + animal->present_cloth = cloth; + res = TRUE; + } } - - animal->present_cloth = cloth; - res = TRUE; - } } - } - return res; + return res; } extern int mNpc_SendMailtoNpc(Mail_c* mail) { - int res = FALSE; - Animal_c* animal; - AnmPersonalID_c anm_id; - int anm_idx; - int memory_idx; - Anmmem_c* memory; - Anmplmail_c* plmail; - int letter_rank; - Animal_c* anm; + int res = FALSE; + Animal_c* animal; + AnmPersonalID_c anm_id; + int anm_idx; + int memory_idx; + Anmmem_c* memory; + Anmplmail_c* plmail; + int letter_rank; + Animal_c* anm; - if (mMl_get_npcinfo_from_mail_name(&anm_id, &mail->header.recipient) == TRUE) { - anm = Save_Get(animals); - anm_idx = mNpc_SearchAnimalPersonalID(&anm_id); + if (mMl_get_npcinfo_from_mail_name(&anm_id, &mail->header.recipient) == TRUE) { + anm = Save_Get(animals); + anm_idx = mNpc_SearchAnimalPersonalID(&anm_id); - if (anm_idx != -1) { - animal = anm + anm_idx; - memory_idx = mNpc_GetAnimalMemoryIdx(&mail->header.sender.personalID, animal->memories, ANIMAL_MEMORY_NUM); + if (anm_idx != -1) { + animal = anm + anm_idx; + memory_idx = mNpc_GetAnimalMemoryIdx(&mail->header.sender.personalID, animal->memories, ANIMAL_MEMORY_NUM); - if (memory_idx == -1) { - memory_idx = mNpc_ForceGetFreeAnimalMemoryIdx(anm, animal->memories, ANIMAL_MEMORY_NUM); + if (memory_idx == -1) { + memory_idx = mNpc_ForceGetFreeAnimalMemoryIdx(anm, animal->memories, ANIMAL_MEMORY_NUM); - if (memory_idx >= 0) { - mPr_CopyPersonalID(&animal->memories[memory_idx].memory_player_id, &mail->header.sender.personalID); + if (memory_idx >= 0) { + mPr_CopyPersonalID(&animal->memories[memory_idx].memory_player_id, &mail->header.sender.personalID); + } + } else { + mNpc_SetPresentCloth(animal, &mail->header.sender.personalID, mail->present); + } + + memory = animal->memories + memory_idx; + plmail = &memory->letter; + memory->letter_info.exists = TRUE; + mNpc_ClearAnimalMail(plmail); + mNpc_Mail2AnimalMail(plmail, mail); + letter_rank = mNpc_SetRemailCond(animal, memory, mail->content.body); + + if (mEv_CheckFirstJob() == TRUE) { + mQst_errand_c* first_job = mQst_GetFirstJobData(); + + if ((first_job->base.quest_kind == mQst_ERRAND_FIRSTJOB_SEND_LETTER || + first_job->base.quest_kind == mQst_ERRAND_FIRSTJOB_SEND_LETTER2) && + first_job->base.progress != 0) { + first_job->base.progress = 3; + memory->letter_info.send_reply = FALSE; + } + } else { + int friendship = 0; + + if (mLd_PlayerManKindCheck() == FALSE) { + int occur_idx = mQst_GetOccuredContestIdx(mQst_CONTEST_KIND_LETTER); + if (occur_idx == anm_idx) { + mQst_SetReceiveLetter(&animal->contest_quest, &mail->header.sender.personalID, + mail->content.body, mail->present); + memory->letter_info.send_reply = FALSE; + } + } + + friendship += 3; + + if (letter_rank == mNpc_LETTER_RANK_BAD) { + friendship += -5; + } + + if (mail->present != EMPTY_NO) { + friendship += 3; + } + + mNpc_AddFriendship(memory, friendship); + } + + res = TRUE; } - } - else { - mNpc_SetPresentCloth(animal, &mail->header.sender.personalID, mail->present); - } - - memory = animal->memories + memory_idx; - plmail = &memory->letter; - memory->letter_info.exists = TRUE; - mNpc_ClearAnimalMail(plmail); - mNpc_Mail2AnimalMail(plmail, mail); - letter_rank = mNpc_SetRemailCond(animal, memory, mail->content.body); - - if (mEv_CheckFirstJob() == TRUE) { - mQst_errand_c* first_job = mQst_GetFirstJobData(); - - if ( - (first_job->base.quest_kind == mQst_ERRAND_FIRSTJOB_SEND_LETTER || first_job->base.quest_kind == mQst_ERRAND_FIRSTJOB_SEND_LETTER2) && - first_job->base.progress != 0 - ) { - first_job->base.progress = 3; - memory->letter_info.send_reply = FALSE; - } - } - else { - int friendship = 0; - - if (mLd_PlayerManKindCheck() == FALSE) { - int occur_idx = mQst_GetOccuredContestIdx(mQst_CONTEST_KIND_LETTER); - if (occur_idx == anm_idx) { - mQst_SetReceiveLetter(&animal->contest_quest, &mail->header.sender.personalID, mail->content.body, mail->present); - memory->letter_info.send_reply = FALSE; - } - } - - friendship += 3; - - if (letter_rank == mNpc_LETTER_RANK_BAD) { - friendship += -5; - } - - if (mail->present != EMPTY_NO) { - friendship += 3; - } - - mNpc_AddFriendship(memory, friendship); - } - - res = TRUE; } - } - return res; + return res; } extern void mNpc_ClearRemail(Anmremail_c* remail) { - remail->date = mTM_rtcTime_ymd_clear_code; - mPr_ClearPlayerName(remail->name); - mLd_ClearLandName(remail->land_name); - remail->flags.cond = mNpc_LETTER_RANK_BAD; - remail->flags.looks = 0x7F; + remail->date = mTM_rtcTime_ymd_clear_code; + mPr_ClearPlayerName(remail->name); + mLd_ClearLandName(remail->land_name); + remail->flags.cond = mNpc_LETTER_RANK_BAD; + remail->flags.looks = 0x7F; } static void mNpc_GetRemailPresent(mActor_name_t* present) { - static int category_table[2] = { mSP_KIND_FURNITURE, mSP_KIND_CLOTH }; + static int category_table[2] = { mSP_KIND_FURNITURE, mSP_KIND_CLOTH }; - mSP_SelectRandomItem_New(NULL, present, 1, NULL, 0, category_table[RANDOM(4) & 1], mSP_LISTTYPE_ABC, FALSE); + mSP_SelectRandomItem_New(NULL, present, 1, NULL, 0, category_table[RANDOM(4) & 1], mSP_LISTTYPE_ABC, FALSE); } static int mNpc_GetHandbillz(Mail_c* mail, int super_num, int mail_a_num, int mail_b_num, int mail_c_num, int ps_num) { - static u8 tmp_super[MAIL_HEADER2_LEN]; - static u8 tmp_ps[MAIL_FOOTER2_LEN]; + static u8 tmp_super[MAIL_HEADER2_LEN]; + static u8 tmp_ps[MAIL_FOOTER2_LEN]; - mHandbillz_Info_c handbill_info; - int res; + mHandbillz_Info_c handbill_info; + int res; - handbill_info.super_buf_p = tmp_super; - handbill_info.super_buf_size = MAIL_HEADER2_LEN; - handbill_info.mail_buf_p = mail->content.body; - handbill_info.mail_buf_size = MAIL_BODY_LEN; - handbill_info.ps_buf_p = tmp_ps; - handbill_info.ps_buf_size = MAIL_FOOTER2_LEN; - handbill_info.super_no = super_num; - handbill_info.maila_no = mail_a_num; - handbill_info.mailb_no = mail_b_num; - handbill_info.mailc_no = mail_c_num; - handbill_info.ps_no = ps_num; + handbill_info.super_buf_p = tmp_super; + handbill_info.super_buf_size = MAIL_HEADER2_LEN; + handbill_info.mail_buf_p = mail->content.body; + handbill_info.mail_buf_size = MAIL_BODY_LEN; + handbill_info.ps_buf_p = tmp_ps; + handbill_info.ps_buf_size = MAIL_FOOTER2_LEN; + handbill_info.super_no = super_num; + handbill_info.maila_no = mail_a_num; + handbill_info.mailb_no = mail_b_num; + handbill_info.mailc_no = mail_c_num; + handbill_info.ps_no = ps_num; - res = mHandbillz_load(&handbill_info); - if (res == TRUE) { - mail->content.header_back_start = handbill_info.header_back_start; - mem_copy(mail->content.header, tmp_super, MAIL_HEADER_LEN); - mem_copy(mail->content.footer, tmp_ps, MAIL_FOOTER_LEN); - } + res = mHandbillz_load(&handbill_info); + if (res == TRUE) { + mail->content.header_back_start = handbill_info.header_back_start; + mem_copy(mail->content.header, tmp_super, MAIL_HEADER_LEN); + mem_copy(mail->content.footer, tmp_ps, MAIL_FOOTER_LEN); + } - return res; + return res; } static void mNpc_SetRemailFreeString(PersonalID_c* pid, AnmPersonalID_c* anm_id, Anmremail_c* remail) { - static int base_str_no[11] = { - 0x314, // food - 0x334, // sports - 0x2F4, // hobby games - 0x6A1, // fish - 0x679, // insects - 0x354, // food tastes (sweet, spicy, ...) - 0x374, // feelings - 0x394, // music genres - 0x3D4, // food satisfaction feelings (delicious, stuffed, satisfying, ...) - 0x3F4, // "good" descriptors (brilliant, splendid, ...) - 0x3B4 // "bad" descriptors (unimpressive, awful, ...) - }; + static int base_str_no[11] = { + 0x314, // food + 0x334, // sports + 0x2F4, // hobby games + 0x6A1, // fish + 0x679, // insects + 0x354, // food tastes (sweet, spicy, ...) + 0x374, // feelings + 0x394, // music genres + 0x3D4, // food satisfaction feelings (delicious, stuffed, satisfying, ...) + 0x3F4, // "good" descriptors (brilliant, splendid, ...) + 0x3B4 // "bad" descriptors (unimpressive, awful, ...) + }; - /* number of string entries per type */ - static f32 rand_max_table[11] = { - 32.0f, - 32.0f, - 32.0f, - 40.0f, - 40.0f, - 32.0f, - 32.0f, - 32.0f, - 32.0f, - 32.0f, - 32.0f - }; + /* number of string entries per type */ + static f32 rand_max_table[11] = { 32.0f, 32.0f, 32.0f, 40.0f, 40.0f, 32.0f, 32.0f, 32.0f, 32.0f, 32.0f, 32.0f }; - u8 free_str[16]; - AnmPersonalID_c* other_id; - int i; + u8 free_str[16]; + AnmPersonalID_c* other_id; + int i; - mHandbill_Set_free_str(mHandbill_FREE_STR0, pid->player_name, PLAYER_NAME_LEN); - - if (remail == NULL) { - mNpc_GetNpcWorldNameAnm(free_str, anm_id); - mHandbill_Set_free_str(mHandbill_FREE_STR1, free_str, ANIMAL_NAME_LEN); - other_id = mNpc_GetOtherAnimalPersonalID(anm_id, 1); + mHandbill_Set_free_str(mHandbill_FREE_STR0, pid->player_name, PLAYER_NAME_LEN); - if (other_id != NULL) { - mNpc_GetNpcWorldNameAnm(free_str, other_id); - mHandbill_Set_free_str(mHandbill_FREE_STR2, free_str, ANIMAL_NAME_LEN); + if (remail == NULL) { + mNpc_GetNpcWorldNameAnm(free_str, anm_id); + mHandbill_Set_free_str(mHandbill_FREE_STR1, free_str, ANIMAL_NAME_LEN); + other_id = mNpc_GetOtherAnimalPersonalID(anm_id, 1); + + if (other_id != NULL) { + mNpc_GetNpcWorldNameAnm(free_str, other_id); + mHandbill_Set_free_str(mHandbill_FREE_STR2, free_str, ANIMAL_NAME_LEN); + } + } else { + mHandbill_Set_free_str(mHandbill_FREE_STR1, remail->name, ANIMAL_NAME_LEN); // foreign npc name + other_id = mNpc_GetOtherAnimalPersonalID(NULL, 0); + mNpc_GetNpcWorldNameAnm(free_str, other_id); + mHandbill_Set_free_str(mHandbill_FREE_STR2, free_str, ANIMAL_NAME_LEN); // random player town npc name + mHandbill_Set_free_str(mHandbill_FREE_STR14, remail->land_name, LAND_NAME_SIZE); // foreign town name + mHandbill_Set_free_str(mHandbill_FREE_STR15, mLd_GetLandName(), LAND_NAME_SIZE); // player town name } - } - else { - mHandbill_Set_free_str(mHandbill_FREE_STR1, remail->name, ANIMAL_NAME_LEN); // foreign npc name - other_id = mNpc_GetOtherAnimalPersonalID(NULL, 0); - mNpc_GetNpcWorldNameAnm(free_str, other_id); - mHandbill_Set_free_str(mHandbill_FREE_STR2, free_str, ANIMAL_NAME_LEN); // random player town npc name - mHandbill_Set_free_str(mHandbill_FREE_STR14, remail->land_name, LAND_NAME_SIZE); // foreign town name - mHandbill_Set_free_str(mHandbill_FREE_STR15, mLd_GetLandName(), LAND_NAME_SIZE); // player town name - } - for (i = 0; i < ARRAY_COUNT(base_str_no); i++) { - int rand = RANDOM_F(rand_max_table[i]); - - mString_Load_StringFromRom(free_str, ARRAY_COUNT(free_str), base_str_no[i] + rand); - mHandbill_Set_free_str(mHandbill_FREE_STR3 + i, free_str, ARRAY_COUNT(free_str)); - } + for (i = 0; i < ARRAY_COUNT(base_str_no); i++) { + int rand = RANDOM_F(rand_max_table[i]); + + mString_Load_StringFromRom(free_str, ARRAY_COUNT(free_str), base_str_no[i] + rand); + mHandbill_Set_free_str(mHandbill_FREE_STR3 + i, free_str, ARRAY_COUNT(free_str)); + } } -static void mNpc_GetRemailGoodData(Mail_c* mail, PersonalID_c* pid, AnmPersonalID_c* anm_id, Anmremail_c* remail, u8 foreign) { - static int start_no[mNpc_LOOKS_NUM] = { - 0x020, - 0x040, - 0x000, - 0x060, - 0x080, - 0x0A0 - }; +static void mNpc_GetRemailGoodData(Mail_c* mail, PersonalID_c* pid, AnmPersonalID_c* anm_id, Anmremail_c* remail, + u8 foreign) { + static int start_no[mNpc_LOOKS_NUM] = { 0x020, 0x040, 0x000, 0x060, 0x080, 0x0A0 }; - static int ohter_start_no[mNpc_LOOKS_NUM] = { - 0x0E0, - 0x100, - 0x0C0, - 0x120, - 0x140, - 0x160 - }; + static int ohter_start_no[mNpc_LOOKS_NUM] = { 0x0E0, 0x100, 0x0C0, 0x120, 0x140, 0x160 }; - static int* start_no_table[2] = { - start_no, - ohter_start_no - }; + static int* start_no_table[2] = { start_no, ohter_start_no }; - mActor_name_t present = EMPTY_NO; - int msg_no; - int* msg_tbl; - int looks; - int give_present; + mActor_name_t present = EMPTY_NO; + int msg_no; + int* msg_tbl; + int looks; + int give_present; - if (remail == NULL) { - looks = anm_id->looks; - } - else { - looks = remail->flags.looks; - } + if (remail == NULL) { + looks = anm_id->looks; + } else { + looks = remail->flags.looks; + } - msg_tbl = start_no_table[foreign]; + msg_tbl = start_no_table[foreign]; - give_present = RANDOM(4) & 1; - if (give_present == 0) { - mNpc_GetRemailPresent(&present); - } + give_present = RANDOM(4) & 1; + if (give_present == 0) { + mNpc_GetRemailPresent(&present); + } - mNpc_SetRemailFreeString(pid, anm_id, remail); - msg_no = msg_tbl[looks]; - mNpc_GetHandbillz(mail, msg_no + RANDOM(32), msg_no + RANDOM(32), msg_no + RANDOM(16) + give_present * 16, msg_no + RANDOM(32), msg_no + RANDOM(32)); - mail->present = present; + mNpc_SetRemailFreeString(pid, anm_id, remail); + msg_no = msg_tbl[looks]; + mNpc_GetHandbillz(mail, msg_no + RANDOM(32), msg_no + RANDOM(32), msg_no + RANDOM(16) + give_present * 16, + msg_no + RANDOM(32), msg_no + RANDOM(32)); + mail->present = present; } -static void mNpc_GetRemailWrongData(Mail_c* mail, PersonalID_c* pid, AnmPersonalID_c* anm_id, Anmremail_c* remail, u8 foreign) { - static int mail_no[2] = { 0xC5, 0xD8 }; - static u8 tmp_super[MAIL_HEADER2_LEN]; - static u8 tmp_ps[MAIL_FOOTER2_LEN]; +static void mNpc_GetRemailWrongData(Mail_c* mail, PersonalID_c* pid, AnmPersonalID_c* anm_id, Anmremail_c* remail, + u8 foreign) { + static int mail_no[2] = { 0xC5, 0xD8 }; + static u8 tmp_super[MAIL_HEADER2_LEN]; + static u8 tmp_ps[MAIL_FOOTER2_LEN]; - int looks; - int header_back_start; - int msg_no; + int looks; + int header_back_start; + int msg_no; - if (remail == NULL) { - looks = anm_id->looks; - } - else { - looks = remail->flags.looks; - } + if (remail == NULL) { + looks = anm_id->looks; + } else { + looks = remail->flags.looks; + } - mNpc_SetRemailFreeString(pid, anm_id, remail); - msg_no = mail_no[foreign] + looks * 3; - msg_no += RANDOM(3); - mHandbill_Load_HandbillFromRom(tmp_super, &header_back_start, tmp_ps, mail->content.body, msg_no); - mail->content.header_back_start = header_back_start; - mem_copy(mail->content.header, tmp_super, MAIL_HEADER_LEN); - mem_copy(mail->content.footer, tmp_ps, MAIL_FOOTER_LEN); - mail->present = EMPTY_NO; + mNpc_SetRemailFreeString(pid, anm_id, remail); + msg_no = mail_no[foreign] + looks * 3; + msg_no += RANDOM(3); + mHandbill_Load_HandbillFromRom(tmp_super, &header_back_start, tmp_ps, mail->content.body, msg_no); + mail->content.header_back_start = header_back_start; + mem_copy(mail->content.header, tmp_super, MAIL_HEADER_LEN); + mem_copy(mail->content.footer, tmp_ps, MAIL_FOOTER_LEN); + mail->present = EMPTY_NO; } typedef void (*mNPC_GET_REMAIL_PROC)(Mail_c*, PersonalID_c*, AnmPersonalID_c*, Anmremail_c*, u8); -static void mNpc_GetRemailData(Mail_c* mail, PersonalID_c* pid, AnmPersonalID_c* anm_id, Anmremail_c* remail, int cond, u8 foreign) { - static mNPC_GET_REMAIL_PROC get_remail[mNpc_LETTER_RANK_NUM] = { - &mNpc_GetRemailWrongData, - &mNpc_GetRemailGoodData - }; +static void mNpc_GetRemailData(Mail_c* mail, PersonalID_c* pid, AnmPersonalID_c* anm_id, Anmremail_c* remail, int cond, + u8 foreign) { + static mNPC_GET_REMAIL_PROC get_remail[mNpc_LETTER_RANK_NUM] = { &mNpc_GetRemailWrongData, + &mNpc_GetRemailGoodData }; - mActor_name_t paper; - int paper_no; + mActor_name_t paper; + int paper_no; - (*get_remail[cond])(mail, pid, anm_id, remail, foreign); - mail->content.font = mMl_FONT_0; - mail->content.mail_type = mMl_TYPE_MAIL; - mPr_CopyPersonalID(&mail->header.recipient.personalID, pid); - mail->header.recipient.type = mMl_NAME_TYPE_PLAYER; + (*get_remail[cond])(mail, pid, anm_id, remail, foreign); + mail->content.font = mMl_FONT_0; + mail->content.mail_type = mMl_TYPE_MAIL; + mPr_CopyPersonalID(&mail->header.recipient.personalID, pid); + mail->header.recipient.type = mMl_NAME_TYPE_PLAYER; - if (remail == NULL) { - mMl_set_mail_name_npcinfo(&mail->header.sender, anm_id); - } - else { - mPr_CopyPlayerName(mail->header.sender.personalID.player_name, remail->name); - mLd_CopyLandName(mail->header.sender.personalID.land_name, remail->land_name); - mail->header.sender.type = mMl_NAME_TYPE_NPC; - } + if (remail == NULL) { + mMl_set_mail_name_npcinfo(&mail->header.sender, anm_id); + } else { + mPr_CopyPlayerName(mail->header.sender.personalID.player_name, remail->name); + mLd_CopyLandName(mail->header.sender.personalID.land_name, remail->land_name); + mail->header.sender.type = mMl_NAME_TYPE_NPC; + } - mSP_SelectRandomItem_New(NULL, &paper, 1, NULL, 0, mSP_KIND_PAPER, mSP_LISTTYPE_ABC, FALSE); - mail->content.paper_type = (paper - ITM_PAPER_START) % PAPER_UNIQUE_NUM; + mSP_SelectRandomItem_New(NULL, &paper, 1, NULL, 0, mSP_KIND_PAPER, mSP_LISTTYPE_ABC, FALSE); + mail->content.paper_type = (paper - ITM_PAPER_START) % PAPER_UNIQUE_NUM; } static Mail_c l_npc_mail; -static int mNpc_SendRemailPostOffice(PersonalID_c* pid, AnmPersonalID_c* anm_id, Anmremail_c* remail, int cond, u8 foreign) { - Mail_c* mail = &l_npc_mail; - int res = FALSE; +static int mNpc_SendRemailPostOffice(PersonalID_c* pid, AnmPersonalID_c* anm_id, Anmremail_c* remail, int cond, + u8 foreign) { + Mail_c* mail = &l_npc_mail; + int res = FALSE; - if (mPO_get_keep_mail_sum() < mPO_MAIL_STORAGE_SIZE) { - mMl_clear_mail(mail); - mNpc_GetRemailData(mail, pid, anm_id, remail, cond, foreign); - res = mPO_receipt_proc(mail, mPO_SENDTYPE_MAIL); - } - - return res; + if (mPO_get_keep_mail_sum() < mPO_MAIL_STORAGE_SIZE) { + mMl_clear_mail(mail); + mNpc_GetRemailData(mail, pid, anm_id, remail, cond, foreign); + res = mPO_receipt_proc(mail, mPO_SENDTYPE_MAIL); + } + + return res; } static int mNpc_CheckLetterTime(lbRTC_ymd_c* letter_date, lbRTC_time_c* rtc_time) { - int res = FALSE; + int res = FALSE; - if (letter_date->day != 0xFF && (letter_date->year != rtc_time->year || letter_date->month != rtc_time->month || letter_date->day != rtc_time->day)) { - res = TRUE; - } + if (letter_date->day != 0xFF && (letter_date->year != rtc_time->year || letter_date->month != rtc_time->month || + letter_date->day != rtc_time->day)) { + res = TRUE; + } - return res; + return res; } // 25% extern void mNpc_Remail() { - Animal_c* animal = Save_Get(animals); - Anmremail_c* remail; - Private_c* priv = Common_Get(now_private); - Anmmem_c* memory; - lbRTC_time_c* rtc_time; + Animal_c* animal = Save_Get(animals); + Anmremail_c* remail; + Private_c* priv = Common_Get(now_private); + Anmmem_c* memory; + lbRTC_time_c* rtc_time; - rtc_time = Common_GetPointer(time.rtc_time); - - if (mPr_NullCheckPersonalID(&priv->player_ID) == FALSE && mLd_PlayerManKindCheck() == FALSE) { - int i; + rtc_time = Common_GetPointer(time.rtc_time); - /* process replies from town villagers first */ - for (i = 0; i < ANIMAL_NUM_MAX; i++) { - if (mNpc_CheckFreeAnimalPersonalID(&animal->id) == FALSE) { - int mem_idx = mNpc_GetAnimalMemoryIdx(&priv->player_ID, animal->memories, ANIMAL_MEMORY_NUM); + if (mPr_NullCheckPersonalID(&priv->player_ID) == FALSE && mLd_PlayerManKindCheck() == FALSE) { + int i; - if (mem_idx != -1) { - memory = animal->memories + mem_idx; + /* process replies from town villagers first */ + for (i = 0; i < ANIMAL_NUM_MAX; i++) { + if (mNpc_CheckFreeAnimalPersonalID(&animal->id) == FALSE) { + int mem_idx = mNpc_GetAnimalMemoryIdx(&priv->player_ID, animal->memories, ANIMAL_MEMORY_NUM); - if (memory->letter_info.send_reply && mNpc_CheckLetterTime(&memory->letter.date, rtc_time) == TRUE) { - if (mNpc_SendRemailPostOffice(&priv->player_ID, &animal->id, NULL, memory->letter_info.cond, FALSE) != TRUE) { - break; + if (mem_idx != -1) { + memory = animal->memories + mem_idx; + + if (memory->letter_info.send_reply && + mNpc_CheckLetterTime(&memory->letter.date, rtc_time) == TRUE) { + if (mNpc_SendRemailPostOffice(&priv->player_ID, &animal->id, NULL, memory->letter_info.cond, + FALSE) != TRUE) { + break; + } + + memory->letter_info.send_reply = FALSE; + } + } } - memory->letter_info.send_reply = FALSE; - } + animal++; } - } - animal++; + /* process info from the last foreign villager (if any) */ + remail = &priv->remail; + if (remail->flags.looks != 0x7F && + mNpc_SendRemailPostOffice(&priv->player_ID, &animal->id, remail, remail->flags.cond, TRUE) == TRUE) { + mNpc_ClearRemail(remail); + } } - - /* process info from the last foreign villager (if any) */ - remail = &priv->remail; - if (remail->flags.looks != 0x7F && mNpc_SendRemailPostOffice(&priv->player_ID, &animal->id, remail, remail->flags.cond, TRUE) == TRUE) { - mNpc_ClearRemail(remail); - } - } } extern u8 mNpc_GetPaperType() { - mActor_name_t paper; + mActor_name_t paper; - mSP_SelectRandomItem_New(NULL, &paper, 1, NULL, 0, mSP_KIND_PAPER, mSP_LISTTYPE_ABC, FALSE); - return (paper - ITM_PAPER_START) % PAPER_UNIQUE_NUM; + mSP_SelectRandomItem_New(NULL, &paper, 1, NULL, 0, mSP_KIND_PAPER, mSP_LISTTYPE_ABC, FALSE); + return (paper - ITM_PAPER_START) % PAPER_UNIQUE_NUM; } -static void mNpc_LoadMailDataCommon2(Mail_c* mail, PersonalID_c* pid, AnmPersonalID_c* anm_id, mActor_name_t present, u8 paper_type, int mail_no) { - u8 super[MAIL_HEADER2_LEN]; - u8 ps[MAIL_FOOTER2_LEN]; - int header_back_start; +static void mNpc_LoadMailDataCommon2(Mail_c* mail, PersonalID_c* pid, AnmPersonalID_c* anm_id, mActor_name_t present, + u8 paper_type, int mail_no) { + u8 super[MAIL_HEADER2_LEN]; + u8 ps[MAIL_FOOTER2_LEN]; + int header_back_start; - mMl_clear_mail(mail); - mHandbill_Load_HandbillFromRom2(super, MAIL_HEADER2_LEN, &header_back_start, ps, MAIL_FOOTER2_LEN, mail->content.body, mail_no); - mem_copy(mail->content.header, super, MAIL_HEADER_LEN); - mem_copy(mail->content.footer, ps, MAIL_FOOTER_LEN); - mail->content.header_back_start = header_back_start; - mail->content.font = mMl_FONT_0; - mail->content.mail_type = mMl_TYPE_MAIL; - mPr_CopyPersonalID(&mail->header.recipient.personalID, pid); - mail->header.recipient.type = mMl_NAME_TYPE_PLAYER; - mMl_set_mail_name_npcinfo(&mail->header.sender, anm_id); - mail->present = present; - mail->content.paper_type = paper_type; + mMl_clear_mail(mail); + mHandbill_Load_HandbillFromRom2(super, MAIL_HEADER2_LEN, &header_back_start, ps, MAIL_FOOTER2_LEN, + mail->content.body, mail_no); + mem_copy(mail->content.header, super, MAIL_HEADER_LEN); + mem_copy(mail->content.footer, ps, MAIL_FOOTER_LEN); + mail->content.header_back_start = header_back_start; + mail->content.font = mMl_FONT_0; + mail->content.mail_type = mMl_TYPE_MAIL; + mPr_CopyPersonalID(&mail->header.recipient.personalID, pid); + mail->header.recipient.type = mMl_NAME_TYPE_PLAYER; + mMl_set_mail_name_npcinfo(&mail->header.sender, anm_id); + mail->present = present; + mail->content.paper_type = paper_type; } static void mNpc_GetEventPresent(mActor_name_t* present, int type) { - static int priority_table[mNpc_EVENT_MAIL_FRIEND_NUM] = { - mSP_LISTTYPE_RARE, - mSP_LISTTYPE_UNCOMMON, - mSP_LISTTYPE_COMMON - }; + static int priority_table[mNpc_EVENT_MAIL_FRIEND_NUM] = { mSP_LISTTYPE_RARE, mSP_LISTTYPE_UNCOMMON, + mSP_LISTTYPE_COMMON }; - static int category_table[mNpc_EVENT_MAIL_FRIEND_NUM] = { - mSP_KIND_FURNITURE, - mSP_KIND_FURNITURE, - mSP_KIND_CLOTH - }; + static int category_table[mNpc_EVENT_MAIL_FRIEND_NUM] = { mSP_KIND_FURNITURE, mSP_KIND_FURNITURE, mSP_KIND_CLOTH }; - mSP_SelectRandomItem_New(NULL, present, 1, NULL, 0, category_table[type], priority_table[type], FALSE); + mSP_SelectRandomItem_New(NULL, present, 1, NULL, 0, category_table[type], priority_table[type], FALSE); } static void mNpc_GetEventMail(Mail_c* mail, PersonalID_c* pid, AnmPersonalID_c* anm_id, int type, int looks) { - static u8 animal_name[ANIMAL_NAME_LEN]; + static u8 animal_name[ANIMAL_NAME_LEN]; - mActor_name_t present; + mActor_name_t present; - mHandbill_Set_free_str(mHandbill_FREE_STR0, pid->player_name, PLAYER_NAME_LEN); - mNpc_GetNpcWorldNameAnm(animal_name, anm_id); - mHandbill_Set_free_str(mHandbill_FREE_STR6, animal_name, ANIMAL_NAME_LEN); - mNpc_GetEventPresent(&present, type); - mNpc_LoadMailDataCommon2(mail, pid, anm_id, present, mNpc_GetPaperType(), 0x60 + looks * mNpc_EVENT_MAIL_FRIEND_NUM + type); + mHandbill_Set_free_str(mHandbill_FREE_STR0, pid->player_name, PLAYER_NAME_LEN); + mNpc_GetNpcWorldNameAnm(animal_name, anm_id); + mHandbill_Set_free_str(mHandbill_FREE_STR6, animal_name, ANIMAL_NAME_LEN); + mNpc_GetEventPresent(&present, type); + mNpc_LoadMailDataCommon2(mail, pid, anm_id, present, mNpc_GetPaperType(), + 0x60 + looks * mNpc_EVENT_MAIL_FRIEND_NUM + type); } static int mNpc_SendEventPresentMail(PersonalID_c* pid, int player_no, AnmPersonalID_c* anm_id, int type) { - Mail_c* mail = &l_npc_mail; - mHm_hs_c* home; - int looks = anm_id->looks; - int res = FALSE; + Mail_c* mail = &l_npc_mail; + mHm_hs_c* home; + int looks = anm_id->looks; + int res = FALSE; - home = Save_GetPointer(homes[mHS_get_arrange_idx(player_no)]); + home = Save_GetPointer(homes[mHS_get_arrange_idx(player_no)]); - if (mPr_CheckCmpPersonalID(pid, &home->ownerID) == TRUE) { - int free_idx; + if (mPr_CheckCmpPersonalID(pid, &home->ownerID) == TRUE) { + int free_idx; - mMl_clear_mail(mail); - free_idx = mMl_chk_mail_free_space(home->mailbox, HOME_MAILBOX_SIZE); + mMl_clear_mail(mail); + free_idx = mMl_chk_mail_free_space(home->mailbox, HOME_MAILBOX_SIZE); - if (free_idx != -1) { - mNpc_GetEventMail(mail, pid, anm_id, type, looks); - mMl_copy_mail(home->mailbox + free_idx, mail); - res = TRUE; + if (free_idx != -1) { + mNpc_GetEventMail(mail, pid, anm_id, type, looks); + mMl_copy_mail(home->mailbox + free_idx, mail); + res = TRUE; + } else if (mPO_get_keep_mail_sum() < mPO_MAIL_STORAGE_SIZE) { + mNpc_GetEventMail(mail, pid, anm_id, type, looks); + res = mPO_receipt_proc(mail, mPO_SENDTYPE_MAIL); + } } - else if (mPO_get_keep_mail_sum() < mPO_MAIL_STORAGE_SIZE) { - mNpc_GetEventMail(mail, pid, anm_id, type, looks); - res = mPO_receipt_proc(mail, mPO_SENDTYPE_MAIL); - } - } - return res; + return res; } static void mNpc_SendEventPresentMailSex(int* selected, u8* type, Animal_c* animal, int animal_sex) { - int best_friend_idx = mNpc_GetAnimalMemoryBestFriend(animal->memories, ANIMAL_MEMORY_NUM); - int other_sex_best_friend_idx = mNpc_GetAnimalMemoryFriend_Land_Sex(animal->memories, ANIMAL_MEMORY_NUM, (~animal_sex) & 1); + int best_friend_idx = mNpc_GetAnimalMemoryBestFriend(animal->memories, ANIMAL_MEMORY_NUM); + int other_sex_best_friend_idx = + mNpc_GetAnimalMemoryFriend_Land_Sex(animal->memories, ANIMAL_MEMORY_NUM, (~animal_sex) & 1); - if (best_friend_idx != -1 && other_sex_best_friend_idx == best_friend_idx) { - selected[0] = other_sex_best_friend_idx; - type[0] = mNpc_EVENT_MAIL_BEST_FRIEND; - } - else if (other_sex_best_friend_idx != -1) { - selected[0] = other_sex_best_friend_idx; + if (best_friend_idx != -1 && other_sex_best_friend_idx == best_friend_idx) { + selected[0] = other_sex_best_friend_idx; + type[0] = mNpc_EVENT_MAIL_BEST_FRIEND; + } else if (other_sex_best_friend_idx != -1) { + selected[0] = other_sex_best_friend_idx; - if (animal->memories[other_sex_best_friend_idx].friendship >= 80) { - type[0] = mNpc_EVENT_MAIL_OK_FRIEND; + if (animal->memories[other_sex_best_friend_idx].friendship >= 80) { + type[0] = mNpc_EVENT_MAIL_OK_FRIEND; + } else { + type[0] = mNpc_EVENT_MAIL_NOT_FRIEND; + } } - else { - type[0] = mNpc_EVENT_MAIL_NOT_FRIEND; - } - } } /* this used to be mNpc_SendEventPresentMail_common in DnM and DnM+ (handled both valentine's day & white day) */ extern int mNpc_SendVtdayMail() { - u8 types[ANIMAL_NUM_MAX]; - int other_sex_best_friends[ANIMAL_NUM_MAX]; - Animal_c* animal_p; - int sent; - u8 player_bitfield; - int mem_idx; - PersonalID_c* pid; - int player_no; - int i; - int j; + u8 types[ANIMAL_NUM_MAX]; + int other_sex_best_friends[ANIMAL_NUM_MAX]; + Animal_c* animal_p; + int sent; + u8 player_bitfield; + int mem_idx; + PersonalID_c* pid; + int player_no; + int i; + int j; - animal_p = Save_Get(animals); - sent = 0; - player_bitfield = 0b1111; - - for (i = 0; i < ANIMAL_NUM_MAX; i++) { - other_sex_best_friends[i] = -1; - - if (mNpc_CheckFreeAnimalPersonalID(&animal_p->id) == FALSE) { - mNpc_SendEventPresentMailSex(&other_sex_best_friends[i], &types[i], animal_p, mNpc_GetAnimalSex(animal_p)); - } - - animal_p++; - } - - for (i = 0; i < mNpc_EVENT_MAIL_FRIEND_NUM; i++) { animal_p = Save_Get(animals); + sent = 0; + player_bitfield = 0b1111; - for (j = 0; j < ANIMAL_NUM_MAX; j++) { - if (other_sex_best_friends[j] >= 0 && types[j] == i) { - pid = &animal_p->memories[other_sex_best_friends[j]].memory_player_id; - player_no = mPr_GetPrivateIdx(pid); + for (i = 0; i < ANIMAL_NUM_MAX; i++) { + other_sex_best_friends[i] = -1; - if (((player_bitfield >> player_no) & 1) == 1) { - if (mNpc_SendEventPresentMail(pid, player_no, &animal_p->id, i) == TRUE) { - other_sex_best_friends[j] = -1; - sent++; - } - else { - player_bitfield &= ~(1 << player_no); // remove player from bitfield because they can't receive letters - } + if (mNpc_CheckFreeAnimalPersonalID(&animal_p->id) == FALSE) { + mNpc_SendEventPresentMailSex(&other_sex_best_friends[i], &types[i], animal_p, mNpc_GetAnimalSex(animal_p)); } - } - if (player_bitfield == 0) { - return sent; // all players cannot receive any further mail - } - - animal_p++; + animal_p++; } - } - return sent; + for (i = 0; i < mNpc_EVENT_MAIL_FRIEND_NUM; i++) { + animal_p = Save_Get(animals); + + for (j = 0; j < ANIMAL_NUM_MAX; j++) { + if (other_sex_best_friends[j] >= 0 && types[j] == i) { + pid = &animal_p->memories[other_sex_best_friends[j]].memory_player_id; + player_no = mPr_GetPrivateIdx(pid); + + if (((player_bitfield >> player_no) & 1) == 1) { + if (mNpc_SendEventPresentMail(pid, player_no, &animal_p->id, i) == TRUE) { + other_sex_best_friends[j] = -1; + sent++; + } else { + player_bitfield &= + ~(1 << player_no); // remove player from bitfield because they can't receive letters + } + } + } + + if (player_bitfield == 0) { + return sent; // all players cannot receive any further mail + } + + animal_p++; + } + } + + return sent; } static void mNpc_GetBirthdayPresent(mActor_name_t* present) { - static u8 category_table[5] = { mSP_KIND_FURNITURE, mSP_KIND_FURNITURE, mSP_KIND_CLOTH, mSP_KIND_CLOTH, 0xFF }; + static u8 category_table[5] = { mSP_KIND_FURNITURE, mSP_KIND_FURNITURE, mSP_KIND_CLOTH, mSP_KIND_CLOTH, 0xFF }; - int selected = category_table[RANDOM(ARRAY_COUNT(category_table))]; + int selected = category_table[RANDOM(ARRAY_COUNT(category_table))]; - if (selected == 0xFF) { - mSP_RandomUmbSelect(present, 1); - } - else { - mSP_SelectRandomItem_New(NULL, present, 1, NULL, 0, selected, mSP_LISTTYPE_RARE, FALSE); - } + if (selected == 0xFF) { + mSP_RandomUmbSelect(present, 1); + } else { + mSP_SelectRandomItem_New(NULL, present, 1, NULL, 0, selected, mSP_LISTTYPE_RARE, FALSE); + } } static void mNpc_GetBirthdayCard(Mail_c* mail, PersonalID_c* pid, AnmPersonalID_c* anm_id) { - static u8 animal_name[ANIMAL_NAME_LEN]; + static u8 animal_name[ANIMAL_NAME_LEN]; - u8 item_name[mIN_ITEM_NAME_LEN]; - int mail_no = 0xEA + anm_id->looks * 3 + RANDOM(3); - mActor_name_t present; + u8 item_name[mIN_ITEM_NAME_LEN]; + int mail_no = 0xEA + anm_id->looks * 3 + RANDOM(3); + mActor_name_t present; - mHandbill_Set_free_str(mHandbill_FREE_STR0, pid->player_name, PLAYER_NAME_LEN); - mNpc_GetNpcWorldNameAnm(animal_name, anm_id); - mHandbill_Set_free_str(mHandbill_FREE_STR1, animal_name, ANIMAL_NAME_LEN); - mNpc_GetBirthdayPresent(&present); - mIN_copy_name_str(item_name, present); - mHandbill_Set_free_str(mHandbill_FREE_STR2, item_name, mIN_ITEM_NAME_LEN); - mNpc_LoadMailDataCommon2(mail, pid, anm_id, present, mNpc_GetPaperType(), mail_no); + mHandbill_Set_free_str(mHandbill_FREE_STR0, pid->player_name, PLAYER_NAME_LEN); + mNpc_GetNpcWorldNameAnm(animal_name, anm_id); + mHandbill_Set_free_str(mHandbill_FREE_STR1, animal_name, ANIMAL_NAME_LEN); + mNpc_GetBirthdayPresent(&present); + mIN_copy_name_str(item_name, present); + mHandbill_Set_free_str(mHandbill_FREE_STR2, item_name, mIN_ITEM_NAME_LEN); + mNpc_LoadMailDataCommon2(mail, pid, anm_id, present, mNpc_GetPaperType(), mail_no); } static int mNpc_SendBirthdayCard(PersonalID_c* pid, int player_no, AnmPersonalID_c* anm_id) { - Mail_c* mail = &l_npc_mail; - mHm_hs_c* home; - int free_idx; - int res = FALSE; + Mail_c* mail = &l_npc_mail; + mHm_hs_c* home; + int free_idx; + int res = FALSE; - home = Save_GetPointer(homes[mHS_get_arrange_idx(player_no)]); + home = Save_GetPointer(homes[mHS_get_arrange_idx(player_no)]); - if (mPr_NullCheckPersonalID(pid) == FALSE && mPr_CheckCmpPersonalID(pid, &home->ownerID) == TRUE) { - mMl_clear_mail(mail); - free_idx = mMl_chk_mail_free_space(home->mailbox, HOME_MAILBOX_SIZE); - - if (free_idx != -1) { - mNpc_GetBirthdayCard(mail, pid, anm_id); - mMl_copy_mail(home->mailbox + free_idx, mail); - res = TRUE; + if (mPr_NullCheckPersonalID(pid) == FALSE && mPr_CheckCmpPersonalID(pid, &home->ownerID) == TRUE) { + mMl_clear_mail(mail); + free_idx = mMl_chk_mail_free_space(home->mailbox, HOME_MAILBOX_SIZE); + + if (free_idx != -1) { + mNpc_GetBirthdayCard(mail, pid, anm_id); + mMl_copy_mail(home->mailbox + free_idx, mail); + res = TRUE; + } else if (mPO_get_keep_mail_sum() < mPO_MAIL_STORAGE_SIZE) { + mNpc_GetBirthdayCard(mail, pid, anm_id); + res = mPO_receipt_proc(mail, mPO_SENDTYPE_MAIL); + } } - else if (mPO_get_keep_mail_sum() < mPO_MAIL_STORAGE_SIZE) { - mNpc_GetBirthdayCard(mail, pid, anm_id); - res = mPO_receipt_proc(mail, mPO_SENDTYPE_MAIL); - } - } - return res; + return res; } extern int mNpc_CheckFriendship(PersonalID_c* pid, Animal_c* animal) { - int best_idx; - int idx = -1; - - if (mNpc_CheckFreeAnimalPersonalID(&animal->id) == FALSE) { - best_idx = mNpc_GetHighestFriendshipIdx(animal->memories, ANIMAL_MEMORY_NUM); + int best_idx; + int idx = -1; - if ( - best_idx != -1 && - mPr_CheckCmpPersonalID(pid, &animal->memories[best_idx].memory_player_id) && - Common_Get(now_private)->birthday_present_npc != animal->id.npc_id - ) { - idx = best_idx; + if (mNpc_CheckFreeAnimalPersonalID(&animal->id) == FALSE) { + best_idx = mNpc_GetHighestFriendshipIdx(animal->memories, ANIMAL_MEMORY_NUM); + + if (best_idx != -1 && mPr_CheckCmpPersonalID(pid, &animal->memories[best_idx].memory_player_id) && + Common_Get(now_private)->birthday_present_npc != animal->id.npc_id) { + idx = best_idx; + } } - } - return idx; + return idx; } /* @unused */ @@ -1954,3422 +1890,3315 @@ extern int mNpc_SendEventBirthdayCard(PersonalID_c* pid) { */ extern int mNpc_SendEventBirthdayCard2(PersonalID_c* pid, int player_no) { - Animal_c* animal = Save_Get(animals); - int res = FALSE; - int i; + Animal_c* animal = Save_Get(animals); + int res = FALSE; + int i; - if (pid != NULL && mLd_CheckThisLand(pid->land_name, pid->land_id) == TRUE) { - for (i = 0; i < ANIMAL_NUM_MAX; i++) { - if (mNpc_CheckFriendship(pid, animal) != -1 && mNpc_SendBirthdayCard(pid, player_no, &animal->id) == TRUE) { - res = TRUE; - } + if (pid != NULL && mLd_CheckThisLand(pid->land_name, pid->land_id) == TRUE) { + for (i = 0; i < ANIMAL_NUM_MAX; i++) { + if (mNpc_CheckFriendship(pid, animal) != -1 && mNpc_SendBirthdayCard(pid, player_no, &animal->id) == TRUE) { + res = TRUE; + } - animal++; + animal++; + } + + if (Common_Get(now_private)->celebrated_birthday_year != Common_Get(time.rtc_time).year) { + Common_Get(now_private)->birthday_present_npc = EMPTY_NO; + Common_Get(now_private)->celebrated_birthday_year = Common_Get(time.rtc_time).year; + } } - if (Common_Get(now_private)->celebrated_birthday_year != Common_Get(time.rtc_time).year) { - Common_Get(now_private)->birthday_present_npc = EMPTY_NO; - Common_Get(now_private)->celebrated_birthday_year = Common_Get(time.rtc_time).year; - } - } - - return res; + return res; } static void mNpc_GetXmasCardData(Mail_c* mail, PersonalID_c* pid) { - int header_back_start; + int header_back_start; - mHandbill_Load_HandbillFromRom(mail->content.header, &header_back_start, mail->content.footer, mail->content.body, 0xD7); - mail->content.header_back_start = header_back_start; - mail->content.font = mMl_FONT_0; - mail->content.mail_type = mMl_TYPE_XMAS; - mPr_CopyPersonalID(&mail->header.recipient.personalID, pid); - mail->header.recipient.type = mMl_NAME_TYPE_PLAYER; - mail->present = FTR_FAMICOM_BALLOON_FIGHT; - mail->content.paper_type = 22; // festive paper + mHandbill_Load_HandbillFromRom(mail->content.header, &header_back_start, mail->content.footer, mail->content.body, + 0xD7); + mail->content.header_back_start = header_back_start; + mail->content.font = mMl_FONT_0; + mail->content.mail_type = mMl_TYPE_XMAS; + mPr_CopyPersonalID(&mail->header.recipient.personalID, pid); + mail->header.recipient.type = mMl_NAME_TYPE_PLAYER; + mail->present = FTR_FAMICOM_BALLOON_FIGHT; + mail->content.paper_type = 22; // festive paper } extern int mNpc_SendEventXmasCard(PersonalID_c* pid, int player_no) { - Mail_c* mail = &l_npc_mail; - mHm_hs_c* home; - int res = FALSE; + Mail_c* mail = &l_npc_mail; + mHm_hs_c* home; + int res = FALSE; - if (mPr_NullCheckPersonalID(pid) == FALSE) { - home = Save_GetPointer(homes[mHS_get_arrange_idx(player_no)]); + if (mPr_NullCheckPersonalID(pid) == FALSE) { + home = Save_GetPointer(homes[mHS_get_arrange_idx(player_no)]); - if (mPr_CheckCmpPersonalID(pid, &home->ownerID) == TRUE) { - int free_space = mMl_chk_mail_free_space(home->mailbox, HOME_MAILBOX_SIZE); + if (mPr_CheckCmpPersonalID(pid, &home->ownerID) == TRUE) { + int free_space = mMl_chk_mail_free_space(home->mailbox, HOME_MAILBOX_SIZE); - if (free_space != -1) { - mMl_clear_mail(mail); - mNpc_GetXmasCardData(mail, pid); - mMl_copy_mail(home->mailbox + free_space, mail); - res = TRUE; - } + if (free_space != -1) { + mMl_clear_mail(mail); + mNpc_GetXmasCardData(mail, pid); + mMl_copy_mail(home->mailbox + free_space, mail); + res = TRUE; + } + } } - } - return res; + return res; } extern int mNpc_GetPresentClothMemoryIdx(Anmmem_c* memory) { - int i; - int res = -1; + int i; + int res = -1; - if (memory != NULL) { - for (i = 0; i < ANIMAL_MEMORY_NUM; i++) { - if (memory->letter_info.wearing_present_cloth == TRUE) { - res = i; - break; - } + if (memory != NULL) { + for (i = 0; i < ANIMAL_MEMORY_NUM; i++) { + if (memory->letter_info.wearing_present_cloth == TRUE) { + res = i; + break; + } - memory++; + memory++; + } } - } - return res; + return res; } extern int mNpc_GetPresentClothMemoryIdx_rnd(Anmmem_c* memory) { - Anmmem_c* mem_p = memory; - int selected; - int cloth_mem = 0; - int res = -1; - int i; + Anmmem_c* mem_p = memory; + int selected; + int cloth_mem = 0; + int res = -1; + int i; - if (memory != NULL) { - for (i = 0; i < ANIMAL_MEMORY_NUM; i++) { - if (mNpc_CheckFreeAnimalMemory(memory) == FALSE && memory->letter_info.wearing_present_cloth == TRUE) { - cloth_mem++; - } + if (memory != NULL) { + for (i = 0; i < ANIMAL_MEMORY_NUM; i++) { + if (mNpc_CheckFreeAnimalMemory(memory) == FALSE && memory->letter_info.wearing_present_cloth == TRUE) { + cloth_mem++; + } - memory++; - } - - if (cloth_mem > 0) { - selected = RANDOM(cloth_mem); - memory = mem_p; - for (i = 0; i < ANIMAL_MEMORY_NUM; i++) { - if (mNpc_CheckFreeAnimalMemory(memory) == FALSE && memory->letter_info.wearing_present_cloth == TRUE) { - if (selected <= 0) { - res = i; - break; - } - else { - selected--; - } + memory++; } - memory++; - } - } - } + if (cloth_mem > 0) { + selected = RANDOM(cloth_mem); + memory = mem_p; + for (i = 0; i < ANIMAL_MEMORY_NUM; i++) { + if (mNpc_CheckFreeAnimalMemory(memory) == FALSE && memory->letter_info.wearing_present_cloth == TRUE) { + if (selected <= 0) { + res = i; + break; + } else { + selected--; + } + } - return res; + memory++; + } + } + } + + return res; } extern int mNpc_CheckTalkPresentCloth(Animal_c* animal) { - int res = FALSE; + int res = FALSE; - if (animal != NULL && mNpc_GetPresentClothMemoryIdx(animal->memories) != -1) { - res = TRUE; - } + if (animal != NULL && mNpc_GetPresentClothMemoryIdx(animal->memories) != -1) { + res = TRUE; + } - return res; + return res; } extern void mNpc_ChangePresentCloth() { - Animal_c* animal = Save_Get(animals); - Anmmem_c* memory; - mActor_name_t present_cloth; - int i; - int j; + Animal_c* animal = Save_Get(animals); + Anmmem_c* memory; + mActor_name_t present_cloth; + int i; + int j; - for (i = 0; i < ANIMAL_NUM_MAX; i++) { - present_cloth = animal->present_cloth; + for (i = 0; i < ANIMAL_NUM_MAX; i++) { + present_cloth = animal->present_cloth; - if ( - mNpc_CheckFreeAnimalPersonalID(&animal->id) == FALSE && - present_cloth != EMPTY_NO && - ITEM_NAME_GET_TYPE(present_cloth) == NAME_TYPE_ITEM1 && - ITEM_NAME_GET_CAT(present_cloth) == ITEM1_CAT_CLOTH - ) { - memory = animal->memories; + if (mNpc_CheckFreeAnimalPersonalID(&animal->id) == FALSE && present_cloth != EMPTY_NO && + ITEM_NAME_GET_TYPE(present_cloth) == NAME_TYPE_ITEM1 && + ITEM_NAME_GET_CAT(present_cloth) == ITEM1_CAT_CLOTH) { + memory = animal->memories; - for (j = 0; j < ANIMAL_MEMORY_NUM; j++) { - if (mNpc_CheckFreeAnimalMemory(memory) == FALSE && memory->letter_info.has_present_cloth == TRUE) { - memory->letter_info.wearing_present_cloth = TRUE; - memory->letter_info.has_present_cloth = FALSE; - animal->cloth = present_cloth; - break; + for (j = 0; j < ANIMAL_MEMORY_NUM; j++) { + if (mNpc_CheckFreeAnimalMemory(memory) == FALSE && memory->letter_info.has_present_cloth == TRUE) { + memory->letter_info.wearing_present_cloth = TRUE; + memory->letter_info.has_present_cloth = FALSE; + animal->cloth = present_cloth; + break; + } + + memory++; + } } - memory++; - } + animal++; } - - animal++; - } } extern u8* mNpc_GetWordEnding(ACTOR* actor) { - NPC_ACTOR* npc; - u8* word_ending; + NPC_ACTOR* npc; + u8* word_ending; - /* @BUG - devs used & instead of && */ - #ifndef BUGFIXES - if (actor != NULL & actor->part == ACTOR_PART_NPC) { - #else - if (actor != NULL && actor->part == ACTOR_PART_NPC) { - #endif - npc = (NPC_ACTOR*)actor; +/* @BUG - devs used & instead of && */ +#ifndef BUGFIXES + if (actor != NULL & actor->part == ACTOR_PART_NPC) { +#else + if (actor != NULL && actor->part == ACTOR_PART_NPC) { +#endif + npc = (NPC_ACTOR*)actor; - if (npc->npc_info.animal != NULL) { - word_ending = npc->npc_info.animal->catchphrase; + if (npc->npc_info.animal != NULL) { + word_ending = npc->npc_info.animal->catchphrase; + } else { + word_ending = l_no_ending_npc_ending; + } + } else { + word_ending = l_no_ending_npc_ending; } - else { - word_ending = l_no_ending_npc_ending; - } - } - else { - word_ending = l_no_ending_npc_ending; - } - return word_ending; + return word_ending; } extern void mNpc_ResetWordEnding(ACTOR* actor) { - if (actor != NULL && actor->part == ACTOR_PART_NPC) { - NPC_ACTOR* npc = (NPC_ACTOR*)actor; - Animal_c* animal = npc->npc_info.animal; + if (actor != NULL && actor->part == ACTOR_PART_NPC) { + NPC_ACTOR* npc = (NPC_ACTOR*)actor; + Animal_c* animal = npc->npc_info.animal; - if (animal != NULL) { - mString_Load_StringFromRom(animal->catchphrase, ANIMAL_CATCHPHRASE_LEN, npc_def_list[animal->id.npc_id & 0xFFF].catchphrase_str_idx); + if (animal != NULL) { + mString_Load_StringFromRom(animal->catchphrase, ANIMAL_CATCHPHRASE_LEN, + npc_def_list[animal->id.npc_id & 0xFFF].catchphrase_str_idx); + } } - } } extern int mNpc_GetFreeEventNpcIdx() { - mNpc_EventNpc_c* event_npc = Common_Get(event_npc); - int i; + mNpc_EventNpc_c* event_npc = Common_Get(event_npc); + int i; - for (i = 0; i < mNpc_EVENT_NPC_NUM; i++) { - if (event_npc->in_use == FALSE) { - return i; + for (i = 0; i < mNpc_EVENT_NPC_NUM; i++) { + if (event_npc->in_use == FALSE) { + return i; + } + + event_npc++; } - event_npc++; - } - - return -1; + return -1; } -extern int mNpc_RegistEventNpc(mActor_name_t event_id, mActor_name_t texture_id, mActor_name_t npc_id, mActor_name_t cloth_id) { - int free_idx = mNpc_GetFreeEventNpcIdx(); - int res = FALSE; +extern int mNpc_RegistEventNpc(mActor_name_t event_id, mActor_name_t texture_id, mActor_name_t npc_id, + mActor_name_t cloth_id) { + int free_idx = mNpc_GetFreeEventNpcIdx(); + int res = FALSE; - if (free_idx != -1) { - mNpc_EventNpc_c* event_npc = Common_GetPointer(event_npc[free_idx]); + if (free_idx != -1) { + mNpc_EventNpc_c* event_npc = Common_GetPointer(event_npc[free_idx]); - if (cloth_id != EMPTY_NO) { - int valid = (cloth_id == RSV_CLOTH) || (cloth_id >= ITM_CLOTH_START && cloth_id < ITM_CLOTH_END); - - if (valid == FALSE) { - cloth_id = ITM_CLOTH000; - } + if (cloth_id != EMPTY_NO) { + int valid = (cloth_id == RSV_CLOTH) || (cloth_id >= ITM_CLOTH_START && cloth_id < ITM_CLOTH_END); + + if (valid == FALSE) { + cloth_id = ITM_CLOTH000; + } + } + + event_npc->event_id = event_id; + event_npc->texture_id = texture_id; + event_npc->npc_id = npc_id; + event_npc->cloth_id = cloth_id; + event_npc->exists = FALSE; + event_npc->in_use = TRUE; + + res = TRUE; } - event_npc->event_id = event_id; - event_npc->texture_id = texture_id; - event_npc->npc_id = npc_id; - event_npc->cloth_id = cloth_id; - event_npc->exists = FALSE; - event_npc->in_use = TRUE; - - res = TRUE; - } - - return res; + return res; } extern void mNpc_UnRegistEventNpc(mNpc_EventNpc_c* npc) { - mNpc_EventNpc_c* event_npc = Common_Get(event_npc); - int i; + mNpc_EventNpc_c* event_npc = Common_Get(event_npc); + int i; - for (i = 0; i < mNpc_EVENT_NPC_NUM; i++) { - if (event_npc == npc) { - bzero(npc, sizeof(mNpc_EventNpc_c)); - break; + for (i = 0; i < mNpc_EVENT_NPC_NUM; i++) { + if (event_npc == npc) { + bzero(npc, sizeof(mNpc_EventNpc_c)); + break; + } + + event_npc++; } - - event_npc++; - } } extern void mNpc_ClearEventNpc() { - bzero(Common_Get(event_npc), mNpc_EVENT_NPC_NUM * sizeof(mNpc_EventNpc_c)); + bzero(Common_Get(event_npc), mNpc_EVENT_NPC_NUM * sizeof(mNpc_EventNpc_c)); } extern mNpc_EventNpc_c* mNpc_GetSameEventNpc(mActor_name_t event_id) { - mNpc_EventNpc_c* event_npc = Common_Get(event_npc); - int i; + mNpc_EventNpc_c* event_npc = Common_Get(event_npc); + int i; - for (i = 0; i < mNpc_EVENT_NPC_NUM; i++) { - if (event_npc->event_id == event_id) { - return event_npc; + for (i = 0; i < mNpc_EVENT_NPC_NUM; i++) { + if (event_npc->event_id == event_id) { + return event_npc; + } + + event_npc++; } - event_npc++; - } - - return NULL; + return NULL; } extern int mNpc_GetFreeMaskNpcIdx() { - mNpc_MaskNpc_c* mask_npc = Common_Get(mask_npc); - int i; + mNpc_MaskNpc_c* mask_npc = Common_Get(mask_npc); + int i; - for (i = 0; i < mNpc_MASK_NPC_NUM; i++) { - if (mask_npc->in_use == FALSE) { - return i; + for (i = 0; i < mNpc_MASK_NPC_NUM; i++) { + if (mask_npc->in_use == FALSE) { + return i; + } + + mask_npc++; } - mask_npc++; - } - - return -1; + return -1; } extern int mNpc_RegistMaskNpc(mActor_name_t mask_id, mActor_name_t npc_id, mActor_name_t cloth_id) { - int free_idx = mNpc_GetFreeMaskNpcIdx(); - int res = FALSE; + int free_idx = mNpc_GetFreeMaskNpcIdx(); + int res = FALSE; - if (free_idx != -1) { - mNpc_MaskNpc_c* mask_npc = Common_GetPointer(mask_npc[free_idx]); + if (free_idx != -1) { + mNpc_MaskNpc_c* mask_npc = Common_GetPointer(mask_npc[free_idx]); - if (cloth_id != EMPTY_NO) { - int valid = (cloth_id == RSV_CLOTH) || (cloth_id >= ITM_CLOTH_START && cloth_id < ITM_CLOTH_END); - - if (valid == FALSE) { - cloth_id = ITM_CLOTH000; - } + if (cloth_id != EMPTY_NO) { + int valid = (cloth_id == RSV_CLOTH) || (cloth_id >= ITM_CLOTH_START && cloth_id < ITM_CLOTH_END); + + if (valid == FALSE) { + cloth_id = ITM_CLOTH000; + } + } + + mask_npc->mask_id = mask_id; + mask_npc->npc_id = npc_id; + mask_npc->exists = FALSE; + mask_npc->in_use = TRUE; + + if (ITEM_NAME_GET_TYPE(npc_id) == NAME_TYPE_NPC) { + int animal_idx = mNpc_SearchAnimalinfo(Save_Get(animals), npc_id, ANIMAL_NUM_MAX); + + if (animal_idx != -1) { + mNpc_CopyAnimalInfo(&mask_npc->animal_data, Save_GetPointer(animals[animal_idx])); + } else { + mNpc_ClearAnimalInfo(&mask_npc->animal_data); + mNpc_SetDefAnimal(&mask_npc->animal_data, npc_id, npc_def_list); + } + + if (cloth_id == EMPTY_NO) { + mask_npc->cloth_id = mask_npc->animal_data.cloth; + } else { + mask_npc->cloth_id = cloth_id; + } + } else { + mask_npc->cloth_id = cloth_id; + } + + res = TRUE; } - mask_npc->mask_id = mask_id; - mask_npc->npc_id = npc_id; - mask_npc->exists = FALSE; - mask_npc->in_use = TRUE; - - if (ITEM_NAME_GET_TYPE(npc_id) == NAME_TYPE_NPC) { - int animal_idx = mNpc_SearchAnimalinfo(Save_Get(animals), npc_id, ANIMAL_NUM_MAX); - - if (animal_idx != -1) { - mNpc_CopyAnimalInfo(&mask_npc->animal_data, Save_GetPointer(animals[animal_idx])); - } - else { - mNpc_ClearAnimalInfo(&mask_npc->animal_data); - mNpc_SetDefAnimal(&mask_npc->animal_data, npc_id, npc_def_list); - } - - if (cloth_id == EMPTY_NO) { - mask_npc->cloth_id = mask_npc->animal_data.cloth; - } - else { - mask_npc->cloth_id = cloth_id; - } - } - else { - mask_npc->cloth_id = cloth_id; - } - - res = TRUE; - } - - return res; + return res; } extern void mNpc_UnRegistMaskNpc(mNpc_MaskNpc_c* npc) { - mNpc_MaskNpc_c* mask_npc = Common_Get(mask_npc); - int i; + mNpc_MaskNpc_c* mask_npc = Common_Get(mask_npc); + int i; - for (i = 0; i < mNpc_MASK_NPC_NUM; i++) { - if (mask_npc == npc) { - bzero(npc, sizeof(mNpc_MaskNpc_c)); - break; + for (i = 0; i < mNpc_MASK_NPC_NUM; i++) { + if (mask_npc == npc) { + bzero(npc, sizeof(mNpc_MaskNpc_c)); + break; + } + + mask_npc++; } - - mask_npc++; - } } extern void mNpc_ClearMaskNpc() { - bzero(Common_Get(mask_npc), mNpc_MASK_NPC_NUM * sizeof(mNpc_MaskNpc_c)); + bzero(Common_Get(mask_npc), mNpc_MASK_NPC_NUM * sizeof(mNpc_MaskNpc_c)); } extern mNpc_MaskNpc_c* mNpc_GetSameMaskNpc(mActor_name_t mask_id) { - mNpc_MaskNpc_c* mask_npc = Common_Get(mask_npc); - int i; + mNpc_MaskNpc_c* mask_npc = Common_Get(mask_npc); + int i; - for (i = 0; i < mNpc_MASK_NPC_NUM; i++) { - if (mask_npc->mask_id == mask_id) { - return mask_npc; + for (i = 0; i < mNpc_MASK_NPC_NUM; i++) { + if (mask_npc->mask_id == mask_id) { + return mask_npc; + } + + mask_npc++; } - mask_npc++; - } - - return NULL; + return NULL; } extern u8 mNpc_GetLooks(mActor_name_t npc_id) { - u8 looks = mNpc_LOOKS_GIRL; + u8 looks = mNpc_LOOKS_GIRL; - if (ITEM_NAME_GET_TYPE(npc_id) == NAME_TYPE_NPC) { - looks = npc_looks_table[npc_id & 0xFFF]; - } + if (ITEM_NAME_GET_TYPE(npc_id) == NAME_TYPE_NPC) { + looks = npc_looks_table[npc_id & 0xFFF]; + } - return looks; + return looks; } static void mNpc_SetDefAnimalInfo(Animal_c* animal, mActor_name_t npc_id, u8 looks, mNpc_Default_Data_c* def_data) { - mLd_land_info_c* land_info = Save_GetPointer(land_info); + mLd_land_info_c* land_info = Save_GetPointer(land_info); - if (ITEM_NAME_GET_TYPE(npc_id) == NAME_TYPE_NPC) { - animal->id.npc_id = npc_id; - animal->id.looks = looks; - animal->cloth = def_data->cloth; - animal->umbrella_id = def_data->umbrella; - mString_Load_StringFromRom(animal->catchphrase, ANIMAL_CATCHPHRASE_LEN, def_data->catchphrase_str_idx); - animal->id.land_id = land_info->id; - mLd_CopyLandName(animal->id.land_name, land_info->name); - } + if (ITEM_NAME_GET_TYPE(npc_id) == NAME_TYPE_NPC) { + animal->id.npc_id = npc_id; + animal->id.looks = looks; + animal->cloth = def_data->cloth; + animal->umbrella_id = def_data->umbrella; + mString_Load_StringFromRom(animal->catchphrase, ANIMAL_CATCHPHRASE_LEN, def_data->catchphrase_str_idx); + animal->id.land_id = land_info->id; + mLd_CopyLandName(animal->id.land_name, land_info->name); + } } extern void mNpc_SetDefAnimalCloth(Animal_c* animal) { - mActor_name_t npc_id = animal->id.npc_id; + mActor_name_t npc_id = animal->id.npc_id; - if (ITEM_NAME_GET_TYPE(npc_id) != NAME_TYPE_NPC) { - return; - } + if (ITEM_NAME_GET_TYPE(npc_id) != NAME_TYPE_NPC) { + return; + } - if ((npc_id & 0xFFF) < 0) { - return; - } + if ((npc_id & 0xFFF) < 0) { + return; + } - if ((npc_id & 0xFFF) >= NPC_NUM) { - return; - } + if ((npc_id & 0xFFF) >= NPC_NUM) { + return; + } - animal->cloth = npc_def_list[npc_id & 0xFFF].cloth; - animal->cloth_original_id = 0xFF; + animal->cloth = npc_def_list[npc_id & 0xFFF].cloth; + animal->cloth_original_id = 0xFF; } extern void mNpc_SetDefAnimalUmbrella(Animal_c* animal) { - mActor_name_t npc_id = animal->id.npc_id; + mActor_name_t npc_id = animal->id.npc_id; - if (ITEM_NAME_GET_TYPE(npc_id) != NAME_TYPE_NPC) { - return; - } + if (ITEM_NAME_GET_TYPE(npc_id) != NAME_TYPE_NPC) { + return; + } - if ((npc_id & 0xFFF) < 0) { - return; - } + if ((npc_id & 0xFFF) < 0) { + return; + } - if ((npc_id & 0xFFF) >= NPC_NUM) { - return; - } + if ((npc_id & 0xFFF) >= NPC_NUM) { + return; + } - animal->umbrella_id = npc_def_list[npc_id & 0xFFF].umbrella; + animal->umbrella_id = npc_def_list[npc_id & 0xFFF].umbrella; } extern void mNpc_SetDefAnimal(Animal_c* animal, mActor_name_t npc_id, mNpc_Default_Data_c* def_data) { - int idx = npc_id & 0xFFF; + int idx = npc_id & 0xFFF; - if (ITEM_NAME_GET_TYPE(npc_id) == NAME_TYPE_NPC) { - mNpc_SetDefAnimalInfo(animal, npc_id, npc_looks_table[idx], &def_data[idx]); - } + if (ITEM_NAME_GET_TYPE(npc_id) == NAME_TYPE_NPC) { + mNpc_SetDefAnimalInfo(animal, npc_id, npc_looks_table[idx], &def_data[idx]); + } } static void mNpc_SetHaveAppeared(mActor_name_t npc_id) { - u8 v; - int idx; - int bit; - u8* used_tbl = Save_Get(npc_used_tbl); - int i; + u8 v; + int idx; + int bit; + u8* used_tbl = Save_Get(npc_used_tbl); + int i; - if (ITEM_NAME_GET_TYPE(npc_id) == NAME_TYPE_NPC) { - idx = npc_id & 0xFFF; - i = idx / 8; - - if (i < ARRAY_COUNT(Save_Get(npc_used_tbl))) { - /* what in the fuck */ - v = used_tbl[i]; - bit = idx & 7; - bit = 1 << bit; - v |= bit; - used_tbl[i] = v; + if (ITEM_NAME_GET_TYPE(npc_id) == NAME_TYPE_NPC) { + idx = npc_id & 0xFFF; + i = idx / 8; + + if (i < ARRAY_COUNT(Save_Get(npc_used_tbl))) { + /* what in the fuck */ + v = used_tbl[i]; + bit = idx & 7; + bit = 1 << bit; + v |= bit; + used_tbl[i] = v; + } } - } } static int mNpc_GetHaveAppeared_idx(int idx) { - u8* used_tbl = Save_Get(npc_used_tbl); - int i = idx / 8; - int res = TRUE; + u8* used_tbl = Save_Get(npc_used_tbl); + int i = idx / 8; + int res = TRUE; - if (i < ARRAY_COUNT(Save_Get(npc_used_tbl))) { - res = (used_tbl[i] >> (idx & 7)) & 1; - } + if (i < ARRAY_COUNT(Save_Get(npc_used_tbl))) { + res = (used_tbl[i] >> (idx & 7)) & 1; + } - return res; + return res; } static int mNpc_GetDefGrowPermission(int idx, s8* grow_list, int count) { - int res = mNpc_GROW_MOVE_IN; + int res = mNpc_GROW_MOVE_IN; - if (idx < count) { - res = grow_list[idx]; - } + if (idx < count) { + res = grow_list[idx]; + } - return res; + return res; } static int mNpc_GetLooks2NotHaveAppearedNum(u8 looks) { - u8* looks_tbl; - s8* grow_list = npc_grow_list; - int num = 0; - int i; + u8* looks_tbl; + s8* grow_list = npc_grow_list; + int num = 0; + int i; - if (looks < mNpc_LOOKS_NUM) { - looks_tbl = npc_looks_table; - - for (i = 0; i < NPC_NUM; i++) { - if (looks == looks_tbl[0]) { - int grow_type = mNpc_GetDefGrowPermission(i, grow_list, NPC_NUM); + if (looks < mNpc_LOOKS_NUM) { + looks_tbl = npc_looks_table; - if (mNpc_GetHaveAppeared_idx(i) == FALSE && (grow_type == mNpc_GROW_STARTER || grow_type == mNpc_GROW_MOVE_IN)) { - num++; + for (i = 0; i < NPC_NUM; i++) { + if (looks == looks_tbl[0]) { + int grow_type = mNpc_GetDefGrowPermission(i, grow_list, NPC_NUM); + + if (mNpc_GetHaveAppeared_idx(i) == FALSE && + (grow_type == mNpc_GROW_STARTER || grow_type == mNpc_GROW_MOVE_IN)) { + num++; + } + } + + looks_tbl++; } - } - - looks_tbl++; } - } - return num; + return num; } static void mNpc_ResetHaveAppeared_common(u8* npc_used_tbl, Animal_c* animal) { - int i; + int i; - bzero(npc_used_tbl, sizeof(Save_Get(npc_used_tbl))); - for (i = 0; i < ANIMAL_NUM_MAX; i++) { - if (mNpc_CheckFreeAnimalInfo(animal) == FALSE) { - mNpc_SetHaveAppeared(animal->id.npc_id); + bzero(npc_used_tbl, sizeof(Save_Get(npc_used_tbl))); + for (i = 0; i < ANIMAL_NUM_MAX; i++) { + if (mNpc_CheckFreeAnimalInfo(animal) == FALSE) { + mNpc_SetHaveAppeared(animal->id.npc_id); + } + + animal++; } - - animal++; - } } static void mNpc_ResetHaveAppeared() { - s8* grow_list = npc_grow_list; - int i; + s8* grow_list = npc_grow_list; + int i; - for (i = 0; i < NPC_NUM; i++) { - u32 grow_perm = mNpc_GetDefGrowPermission(i, grow_list, NPC_NUM); + for (i = 0; i < NPC_NUM; i++) { + u32 grow_perm = mNpc_GetDefGrowPermission(i, grow_list, NPC_NUM); - if (mNpc_GetHaveAppeared_idx(i) == FALSE && grow_perm <= mNpc_GROW_MOVE_IN) { - break; + if (mNpc_GetHaveAppeared_idx(i) == FALSE && grow_perm <= mNpc_GROW_MOVE_IN) { + break; + } } - } - /* All animals have appeared in town (islanders excluded) */ - if (i == NPC_NUM) { - mNpc_ResetHaveAppeared_common(Save_Get(npc_used_tbl), Save_Get(animals)); - } + /* All animals have appeared in town (islanders excluded) */ + if (i == NPC_NUM) { + mNpc_ResetHaveAppeared_common(Save_Get(npc_used_tbl), Save_Get(animals)); + } } static void mNpc_DecideLivingNpcMax(Animal_c* animal, u8 count, int malloc_flag) { - static int fakeTable[NPC_NUM]; + static int fakeTable[NPC_NUM]; - mNpc_Default_Data_c* def_list; - s8* grow_list; - u8 looks_bitfield = 0; - int i = 0; - int animal_idx = 0; + mNpc_Default_Data_c* def_list; + s8* grow_list; + u8 looks_bitfield = 0; + int i = 0; + int animal_idx = 0; - bzero(fakeTable, sizeof(fakeTable)); - mNpc_MakeRandTable(fakeTable, NPC_NUM, NPC_NUM); - def_list = npc_def_list; - grow_list = npc_grow_list; + bzero(fakeTable, sizeof(fakeTable)); + mNpc_MakeRandTable(fakeTable, NPC_NUM, NPC_NUM); + def_list = npc_def_list; + grow_list = npc_grow_list; - while (count != 0) { - if (animal == NULL) { - break; - } - - if (animal->id.npc_id == EMPTY_NO) { - int idx = fakeTable[i]; - mActor_name_t npc_id = NPC_START | idx; - int grow_perm = mNpc_GetDefGrowPermission(idx, grow_list, NPC_NUM); - - if (grow_perm == mNpc_GROW_STARTER) { - int looks = npc_looks_table[idx]; - - if (((looks_bitfield >> looks) & 1) == 0) { - mNpc_SetDefAnimal(animal, npc_id, def_list); - looks_bitfield |= (1 << looks); - mNpc_SetHaveAppeared(npc_id); - mNpc_ResetAnimalRelation(animal_idx); - animal++; - animal_idx++; - count--; + while (count != 0) { + if (animal == NULL) { + break; } - } - else if (grow_perm == -1) { - mNpc_SetHaveAppeared(npc_id); - } + + if (animal->id.npc_id == EMPTY_NO) { + int idx = fakeTable[i]; + mActor_name_t npc_id = NPC_START | idx; + int grow_perm = mNpc_GetDefGrowPermission(idx, grow_list, NPC_NUM); + + if (grow_perm == mNpc_GROW_STARTER) { + int looks = npc_looks_table[idx]; + + if (((looks_bitfield >> looks) & 1) == 0) { + mNpc_SetDefAnimal(animal, npc_id, def_list); + looks_bitfield |= (1 << looks); + mNpc_SetHaveAppeared(npc_id); + mNpc_ResetAnimalRelation(animal_idx); + animal++; + animal_idx++; + count--; + } + } else if (grow_perm == -1) { + mNpc_SetHaveAppeared(npc_id); + } + } else { + animal++; + ; + animal_idx++; + count--; + } + + i++; } - else { - animal++;; - animal_idx++; - count--; - } - - i++; - } } extern void mNpc_SetAnimalTitleDemo(mNpc_demo_npc_c* demo_npc, Animal_c* animal, GAME* game) { - mNpc_Default_Data_c* def_list = npc_def_list; - int i; + mNpc_Default_Data_c* def_list = npc_def_list; + int i; - for (i = 0; i < ANIMAL_NUM_MAX; i++) { - mNpc_SetDefAnimal(animal, demo_npc->npc_name, def_list); - animal->home_info.type_unused = 0; - animal->home_info.block_x = demo_npc->block_x; - animal->home_info.block_z = demo_npc->block_z; - animal->home_info.ut_x = demo_npc->ut_x; - animal->home_info.ut_z = demo_npc->ut_z; + for (i = 0; i < ANIMAL_NUM_MAX; i++) { + mNpc_SetDefAnimal(animal, demo_npc->npc_name, def_list); + animal->home_info.type_unused = 0; + animal->home_info.block_x = demo_npc->block_x; + animal->home_info.block_z = demo_npc->block_z; + animal->home_info.ut_x = demo_npc->ut_x; + animal->home_info.ut_z = demo_npc->ut_z; - animal++; - demo_npc++; - } + animal++; + demo_npc++; + } } /* @unused */ extern int mNpc_GetReservedUtNum(int* ut_x, int* ut_z, mActor_name_t* item) { - f32 reserve_num = 0.0f; - int rand; - int res = FALSE; - int i; - - for (i = 0; i < UT_TOTAL_NUM; i++) { - if ((*item >= SIGN00 && *item < WISHING_WELL) || *item == DUMMY_RESERVE) { - reserve_num++; - } - - item++; - } - - if (reserve_num > 0.0f) { - item -= UT_TOTAL_NUM; - rand = RANDOM(reserve_num); + f32 reserve_num = 0.0f; + int rand; + int res = FALSE; + int i; for (i = 0; i < UT_TOTAL_NUM; i++) { - if ((*item >= SIGN00 && *item < WISHING_WELL) || *item == DUMMY_RESERVE) { - if (rand == 0) { - *ut_x = i % UT_Z_NUM; - *ut_z = i / UT_X_NUM; - res = TRUE; - - break; + if ((*item >= SIGN00 && *item < WISHING_WELL) || *item == DUMMY_RESERVE) { + reserve_num++; } - else { - rand--; - } - } - item++; + item++; } - } - return res; + if (reserve_num > 0.0f) { + item -= UT_TOTAL_NUM; + rand = RANDOM(reserve_num); + + for (i = 0; i < UT_TOTAL_NUM; i++) { + if ((*item >= SIGN00 && *item < WISHING_WELL) || *item == DUMMY_RESERVE) { + if (rand == 0) { + *ut_x = i % UT_Z_NUM; + *ut_z = i / UT_X_NUM; + res = TRUE; + + break; + } else { + rand--; + } + } + + item++; + } + } + + return res; } /* @unused */ extern int mNpc_BlockNum2ReservedUtNum(int* ut_x, int* ut_z, int bx, int bz) { - mActor_name_t* items = mFI_BkNumtoUtFGTop(bx, bz); - int res = FALSE; + mActor_name_t* items = mFI_BkNumtoUtFGTop(bx, bz); + int res = FALSE; - if (items != NULL) { - res = mNpc_GetReservedUtNum(ut_x, ut_z, items); - } + if (items != NULL) { + res = mNpc_GetReservedUtNum(ut_x, ut_z, items); + } - return res; + return res; } extern void mNpc_MakeReservedListBeforeFieldct(Anmhome_c* reserved, int reserved_num, u8* reserved_count) { - mFM_fg_c* fg = Save_GetPointer(fg[0][0]); - Anmhome_c* reserved_p = reserved; - mActor_name_t* item; - u8 num = 0; - u8 i; - u8 j; - u8 k; - u8 l; + mFM_fg_c* fg = Save_GetPointer(fg[0][0]); + Anmhome_c* reserved_p = reserved; + mActor_name_t* item; + u8 num = 0; + u8 i; + u8 j; + u8 k; + u8 l; - for (i = 0; i < reserved_num; i++) { - reserved->block_x = -1; - reserved->block_z = -1; - reserved->ut_x = -1; - reserved->ut_z = -1; - reserved++; - } - - reserved = reserved_p; - for (i = 0; i < FG_BLOCK_Z_NUM; i++) { - for (j = 0; j < FG_BLOCK_X_NUM; j++) { - item = &fg->items[0][0]; - - for (k = 0; k < UT_Z_NUM; k++) { - for (l = 0; l < UT_X_NUM; l++) { - if (mNT_IS_RESERVE(*item)) { - num++; - reserved->block_x = j + 1; - reserved->block_z = i + 1; - reserved->ut_x = l; - reserved->ut_z = k; - reserved++; - if (num >= reserved_num) { - *reserved_count = num; - return; - } - } - - item++; - } - } - - fg++; + for (i = 0; i < reserved_num; i++) { + reserved->block_x = -1; + reserved->block_z = -1; + reserved->ut_x = -1; + reserved->ut_z = -1; + reserved++; } - } - *reserved_count = num; + reserved = reserved_p; + for (i = 0; i < FG_BLOCK_Z_NUM; i++) { + for (j = 0; j < FG_BLOCK_X_NUM; j++) { + item = &fg->items[0][0]; + + for (k = 0; k < UT_Z_NUM; k++) { + for (l = 0; l < UT_X_NUM; l++) { + if (mNT_IS_RESERVE(*item)) { + num++; + reserved->block_x = j + 1; + reserved->block_z = i + 1; + reserved->ut_x = l; + reserved->ut_z = k; + reserved++; + if (num >= reserved_num) { + *reserved_count = num; + return; + } + } + + item++; + } + } + + fg++; + } + } + + *reserved_count = num; } -extern void mNpc_MakeReservedListAfterFieldct(Anmhome_c* reserved, int reserved_num, u8* reserved_count, u8 bx_max, u8 bz_max) { - mFM_block_info_c* block_info = mFI_GetBlockTopP(); - Anmhome_c* reserved_p = reserved; - mActor_name_t* item; - u8 num = 0; - u8 i; - u8 j; - u8 k; - u8 l; +extern void mNpc_MakeReservedListAfterFieldct(Anmhome_c* reserved, int reserved_num, u8* reserved_count, u8 bx_max, + u8 bz_max) { + mFM_block_info_c* block_info = mFI_GetBlockTopP(); + Anmhome_c* reserved_p = reserved; + mActor_name_t* item; + u8 num = 0; + u8 i; + u8 j; + u8 k; + u8 l; - for (i = 0; i < reserved_num; i++) { - reserved->block_x = -1; - reserved->block_z = -1; - reserved->ut_x = -1; - reserved->ut_z = -1; - reserved++; - } - - reserved = reserved_p; - for (i = 0; i < bz_max; i++) { - for (j = 0; j < bx_max; j++) { - item = block_info->fg_info.items_p; - - for (k = 0; k < UT_Z_NUM; k++) { - for (l = 0; l < UT_X_NUM; l++) { - if (mNT_IS_RESERVE(*item)) { - num++; - reserved->block_x = j; - reserved->block_z = i; - reserved->ut_x = l; - reserved->ut_z = k; - reserved++; - if (num >= reserved_num) { - *reserved_count = num; - return; - } - } - - item++; - } - } - - block_info++; + for (i = 0; i < reserved_num; i++) { + reserved->block_x = -1; + reserved->block_z = -1; + reserved->ut_x = -1; + reserved->ut_z = -1; + reserved++; } - } - *reserved_count = num; + reserved = reserved_p; + for (i = 0; i < bz_max; i++) { + for (j = 0; j < bx_max; j++) { + item = block_info->fg_info.items_p; + + for (k = 0; k < UT_Z_NUM; k++) { + for (l = 0; l < UT_X_NUM; l++) { + if (mNT_IS_RESERVE(*item)) { + num++; + reserved->block_x = j; + reserved->block_z = i; + reserved->ut_x = l; + reserved->ut_z = k; + reserved++; + if (num >= reserved_num) { + *reserved_count = num; + return; + } + } + + item++; + } + } + + block_info++; + } + } + + *reserved_count = num; } static void mNpc_BuildHouseBeforeFieldct(mActor_name_t npc_id, int bx, int bz, int ut_x, int ut_z) { - static int ut_d[9][2] = { - { 0, 0 }, - { -1, 1 }, - { 0, 1 }, - { 1, 1 }, - { -1, 0 }, - { 1, 0 }, - { -1, -1 }, - { 0, -1 }, - { 1, -1 } - }; + static int ut_d[9][2] = { { 0, 0 }, { -1, 1 }, { 0, 1 }, { 1, 1 }, { -1, 0 }, + { 1, 0 }, { -1, -1 }, { 0, -1 }, { 1, -1 } }; - static mActor_name_t set_fg[9] = { - EMPTY_NO, // npc house id - ACTOR_PROP_VILLAGER_SIGNBOARD, - RSV_NO, - RSV_NO, - RSV_NO, - RSV_NO, - RSV_NO, - RSV_NO, - RSV_NO - }; + static mActor_name_t set_fg[9] = { EMPTY_NO, // npc house id + ACTOR_PROP_VILLAGER_SIGNBOARD, + RSV_NO, + RSV_NO, + RSV_NO, + RSV_NO, + RSV_NO, + RSV_NO, + RSV_NO }; - u16* deposit; - mFM_fg_c* fg; - int x; - int z; - int i; - mActor_name_t house = npc_id - 0x10000 + 0x7000; // this shifts it to the house range 0x50XX + u16* deposit; + mFM_fg_c* fg; + int x; + int z; + int i; + mActor_name_t house = npc_id - 0x10000 + 0x7000; // this shifts it to the house range 0x50XX - if ( - bx >= 0 && bx < FG_BLOCK_X_NUM && - bz >= 0 && bz < FG_BLOCK_Z_NUM && - ut_x > 0 && ut_x < (UT_X_NUM - 1) && - ut_z > 0 && ut_z < (UT_Z_NUM - 1) - ) { - set_fg[0] = house; - fg = Save_GetPointer(fg[bz][bx]); + if (bx >= 0 && bx < FG_BLOCK_X_NUM && bz >= 0 && bz < FG_BLOCK_Z_NUM && ut_x > 0 && ut_x < (UT_X_NUM - 1) && + ut_z > 0 && ut_z < (UT_Z_NUM - 1)) { + set_fg[0] = house; + fg = Save_GetPointer(fg[bz][bx]); - deposit = mFI_GetDepositP(bx + 1, bz + 1); + deposit = mFI_GetDepositP(bx + 1, bz + 1); - for (i = 0; i < ARRAY_COUNT(set_fg); i++) { - x = ut_d[i][0] + ut_x; - z = ut_d[i][1] + ut_z; + for (i = 0; i < ARRAY_COUNT(set_fg); i++) { + x = ut_d[i][0] + ut_x; + z = ut_d[i][1] + ut_z; - mPB_keep_item(fg->items[z][x]); - if (deposit != NULL) { - mFI_BlockDepositOFF(deposit, x, z); - } + mPB_keep_item(fg->items[z][x]); + if (deposit != NULL) { + mFI_BlockDepositOFF(deposit, x, z); + } - fg->items[z][x] = set_fg[i]; + fg->items[z][x] = set_fg[i]; + } } - } } static void mNpc_DestroyHouse(Anmhome_c* home) { - u8 bx = home->block_x - 1; - u8 bz = home->block_z - 1; - u8 ut_x = home->ut_x; - u8 ut_z = home->ut_z - 1; + u8 bx = home->block_x - 1; + u8 bz = home->block_z - 1; + u8 ut_x = home->ut_x; + u8 ut_z = home->ut_z - 1; - if (bx < FG_BLOCK_X_NUM && bz < FG_BLOCK_Z_NUM && ut_x > 0 && ut_x < (UT_X_NUM - 1) && ut_z > 0 && ut_z < (UT_Z_NUM - 1)) { - mActor_name_t reserve_no = mFM_GetReseveName(home->block_x, home->block_z); + if (bx < FG_BLOCK_X_NUM && bz < FG_BLOCK_Z_NUM && ut_x > 0 && ut_x < (UT_X_NUM - 1) && ut_z > 0 && + ut_z < (UT_Z_NUM - 1)) { + mActor_name_t reserve_no = mFM_GetReseveName(home->block_x, home->block_z); - Save_Get(fg[bz][bx]).items[ut_z][ut_x] = reserve_no; - Save_Get(fg[bz][bx]).items[ut_z + 1][ut_x - 1] = EMPTY_NO; - Save_Get(fg[bz][bx]).items[ut_z + 1][ut_x] = EMPTY_NO; - Save_Get(fg[bz][bx]).items[ut_z + 1][ut_x + 1] = EMPTY_NO; - Save_Get(fg[bz][bx]).items[ut_z][ut_x - 1] = EMPTY_NO; - Save_Get(fg[bz][bx]).items[ut_z][ut_x + 1] = EMPTY_NO; - Save_Get(fg[bz][bx]).items[ut_z - 1][ut_x - 1] = EMPTY_NO; - Save_Get(fg[bz][bx]).items[ut_z - 1][ut_x] = EMPTY_NO; - Save_Get(fg[bz][bx]).items[ut_z - 1][ut_x + 1] = EMPTY_NO; - } + Save_Get(fg[bz][bx]).items[ut_z][ut_x] = reserve_no; + Save_Get(fg[bz][bx]).items[ut_z + 1][ut_x - 1] = EMPTY_NO; + Save_Get(fg[bz][bx]).items[ut_z + 1][ut_x] = EMPTY_NO; + Save_Get(fg[bz][bx]).items[ut_z + 1][ut_x + 1] = EMPTY_NO; + Save_Get(fg[bz][bx]).items[ut_z][ut_x - 1] = EMPTY_NO; + Save_Get(fg[bz][bx]).items[ut_z][ut_x + 1] = EMPTY_NO; + Save_Get(fg[bz][bx]).items[ut_z - 1][ut_x - 1] = EMPTY_NO; + Save_Get(fg[bz][bx]).items[ut_z - 1][ut_x] = EMPTY_NO; + Save_Get(fg[bz][bx]).items[ut_z - 1][ut_x + 1] = EMPTY_NO; + } } static void mNpc_SetNpcHome(Animal_c* animal, Anmhome_c* reserved, u8 reserved_num) { - static int fake_table[60]; + static int fake_table[60]; - Anmhome_c* home; - int* fake_table_p = fake_table; - int n = 0; - int i; - int idx; + Anmhome_c* home; + int* fake_table_p = fake_table; + int n = 0; + int i; + int idx; - if (reserved_num > ARRAY_COUNT(fake_table)) { - reserved_num = ARRAY_COUNT(fake_table); - } - - - if (reserved_num > 0) { - bzero(fake_table_p, sizeof(fake_table)); - mNpc_MakeRandTable(fake_table_p, reserved_num, ARRAY_COUNT(fake_table) / 2); - - for (i = 0; i < ANIMAL_NUM_MAX; i++) { - if (ITEM_NAME_GET_TYPE(animal->id.npc_id) == NAME_TYPE_NPC && animal->home_info.block_x == 0xFF && animal->home_info.block_z == 0xFF) { - idx = fake_table_p[n]; - - if (idx >= reserved_num) { - /* I don't like this */ - while ((idx = fake_table_p[n], idx >= reserved_num) && n < reserved_num) { - n++; - } - - if (n >= reserved_num) { - return; - } - } - - if (idx < reserved_num) { - home = &reserved[idx]; - - animal->home_info.block_x = home->block_x; - animal->home_info.block_z = home->block_z; - animal->home_info.ut_x = home->ut_x; - animal->home_info.ut_z = home->ut_z + 1; - mNpc_BuildHouseBeforeFieldct(animal->id.npc_id, animal->home_info.block_x - 1, animal->home_info.block_z - 1, animal->home_info.ut_x, home->ut_z); - } - - n++; - } - - if (n >= reserved_num) { - break; - } - - animal++; + if (reserved_num > ARRAY_COUNT(fake_table)) { + reserved_num = ARRAY_COUNT(fake_table); + } + + if (reserved_num > 0) { + bzero(fake_table_p, sizeof(fake_table)); + mNpc_MakeRandTable(fake_table_p, reserved_num, ARRAY_COUNT(fake_table) / 2); + + for (i = 0; i < ANIMAL_NUM_MAX; i++) { + if (ITEM_NAME_GET_TYPE(animal->id.npc_id) == NAME_TYPE_NPC && animal->home_info.block_x == 0xFF && + animal->home_info.block_z == 0xFF) { + idx = fake_table_p[n]; + + if (idx >= reserved_num) { + /* I don't like this */ + while ((idx = fake_table_p[n], idx >= reserved_num) && n < reserved_num) { + n++; + } + + if (n >= reserved_num) { + return; + } + } + + if (idx < reserved_num) { + home = &reserved[idx]; + + animal->home_info.block_x = home->block_x; + animal->home_info.block_z = home->block_z; + animal->home_info.ut_x = home->ut_x; + animal->home_info.ut_z = home->ut_z + 1; + mNpc_BuildHouseBeforeFieldct(animal->id.npc_id, animal->home_info.block_x - 1, + animal->home_info.block_z - 1, animal->home_info.ut_x, home->ut_z); + } + + n++; + } + + if (n >= reserved_num) { + break; + } + + animal++; + } } - } } extern mNpc_InitNpcData() { - static Anmhome_c reserved[60]; + static Anmhome_c reserved[60]; - u8 reserved_num = 0; + u8 reserved_num = 0; - mNpc_MakeReservedListBeforeFieldct(reserved, ARRAY_COUNT(reserved), &reserved_num); - mNpc_SetNpcHome(Save_Get(animals), reserved, reserved_num); + mNpc_MakeReservedListBeforeFieldct(reserved, ARRAY_COUNT(reserved), &reserved_num); + mNpc_SetNpcHome(Save_Get(animals), reserved, reserved_num); } extern void mNpc_InitNpcList(mNpc_NpcList_c* npclist, int count) { - int i; + int i; - if (npclist != NULL) { - bzero(npclist, count * sizeof(mNpc_NpcList_c)); + if (npclist != NULL) { + bzero(npclist, count * sizeof(mNpc_NpcList_c)); - for (i = 0; i < count; i++) { - npclist->name = EMPTY_NO; - npclist->field_name = RSV_NO; - mQst_ClearQuestInfo(&npclist->quest_info); - npclist->house_data.type = 0xFF; - npclist->house_data.palette = 0xFF; - npclist->house_data.wall_id = 0xFF; - npclist->house_data.floor_id = 0xFF; - npclist->house_data.main_layer_id = 203; + for (i = 0; i < count; i++) { + npclist->name = EMPTY_NO; + npclist->field_name = RSV_NO; + mQst_ClearQuestInfo(&npclist->quest_info); + npclist->house_data.type = 0xFF; + npclist->house_data.palette = 0xFF; + npclist->house_data.wall_id = 0xFF; + npclist->house_data.floor_id = 0xFF; + npclist->house_data.main_layer_id = 203; - npclist++; + npclist++; + } } - } } extern void mNpc_SetNpcList(mNpc_NpcList_c* npclist, Animal_c* animal, int count, int malloc_flag) { - xyz_t pos; - mActor_name_t npc_id; - int i; - mNpc_NpcHouseData_c* house_list = npc_house_list; + xyz_t pos; + mActor_name_t npc_id; + int i; + mNpc_NpcHouseData_c* house_list = npc_house_list; - for (i = 0; i < count; i++) { - npc_id = animal->id.npc_id; + for (i = 0; i < count; i++) { + npc_id = animal->id.npc_id; - if (ITEM_NAME_GET_TYPE(npc_id) == NAME_TYPE_NPC && animal->home_info.block_x != 0xFF) { - npclist->name = npc_id; + if (ITEM_NAME_GET_TYPE(npc_id) == NAME_TYPE_NPC && animal->home_info.block_x != 0xFF) { + npclist->name = npc_id; - npclist->house_position.x = animal->home_info.block_x * mFI_BK_WORLDSIZE_X_F; - npclist->house_position.z = animal->home_info.block_z * mFI_BK_WORLDSIZE_Z_F; - mFI_UtNum2PosXZInBk(&pos.x, &pos.z, animal->home_info.ut_x, animal->home_info.ut_z); - npclist->house_position.x += pos.x; - npclist->house_position.z += pos.z; - npclist->house_position.y = 0.0f; + npclist->house_position.x = animal->home_info.block_x * mFI_BK_WORLDSIZE_X_F; + npclist->house_position.z = animal->home_info.block_z * mFI_BK_WORLDSIZE_Z_F; + mFI_UtNum2PosXZInBk(&pos.x, &pos.z, animal->home_info.ut_x, animal->home_info.ut_z); + npclist->house_position.x += pos.x; + npclist->house_position.z += pos.z; + npclist->house_position.y = 0.0f; - npclist->position.x = npclist->house_position.x; - npclist->position.y = npclist->house_position.y; - npclist->position.z = npclist->house_position.z; + npclist->position.x = npclist->house_position.x; + npclist->position.y = npclist->house_position.y; + npclist->position.z = npclist->house_position.z; - npclist->appear_flag = TRUE; - npclist->reward_furniture = EMPTY_NO; + npclist->appear_flag = TRUE; + npclist->reward_furniture = EMPTY_NO; - npclist->house_data.type = house_list[npc_id & 0xFFF].type; - npclist->house_data.palette = house_list[npc_id & 0xFFF].palette; - npclist->house_data.wall_id = house_list[npc_id & 0xFFF].wall_id; - npclist->house_data.floor_id = house_list[npc_id & 0xFFF].floor_id; - npclist->house_data.main_layer_id = house_list[npc_id & 0xFFF].main_layer_id; - npclist->house_data.secondary_layer_id = house_list[npc_id & 0xFFF].secondary_layer_id; + npclist->house_data.type = house_list[npc_id & 0xFFF].type; + npclist->house_data.palette = house_list[npc_id & 0xFFF].palette; + npclist->house_data.wall_id = house_list[npc_id & 0xFFF].wall_id; + npclist->house_data.floor_id = house_list[npc_id & 0xFFF].floor_id; + npclist->house_data.main_layer_id = house_list[npc_id & 0xFFF].main_layer_id; + npclist->house_data.secondary_layer_id = house_list[npc_id & 0xFFF].secondary_layer_id; + } + + npclist++; + animal++; } - - npclist++; - animal++; - } } extern void mNpc_SetNpcinfo(ACTOR* actor, s8 npc_info_idx) { - if (actor->part == ACTOR_PART_NPC) { - NPC_ACTOR* npc = (NPC_ACTOR*)actor; - mActor_name_t npc_id = actor->npc_id; + if (actor->part == ACTOR_PART_NPC) { + NPC_ACTOR* npc = (NPC_ACTOR*)actor; + mActor_name_t npc_id = actor->npc_id; - if (ITEM_NAME_GET_TYPE(npc_id) == NAME_TYPE_SPNPC) { - mNpc_EventNpc_c* event_npc = mNpc_GetSameEventNpc(npc_id); + if (ITEM_NAME_GET_TYPE(npc_id) == NAME_TYPE_SPNPC) { + mNpc_EventNpc_c* event_npc = mNpc_GetSameEventNpc(npc_id); - if (event_npc != NULL) { - npc_info_idx = mNpc_SearchAnimalinfo(Save_Get(animals), event_npc->npc_id, ANIMAL_NUM_MAX); - } - } - - if (npc_info_idx >= 0 && npc_info_idx < ANIMAL_NUM_MAX) { - npc->npc_info.animal = Save_GetPointer(animals[npc_info_idx]); - npc->npc_info.list = Common_GetPointer(npclist[npc_info_idx]); - } - else if (npc_info_idx == -ANIMAL_NUM_MAX) { - npc->npc_info.animal = &Save_Get(island).animal; - npc->npc_info.list = Common_GetPointer(island_npclist[0]); - } - else { - mNpc_MaskNpc_c* mask_npc = mNpc_GetSameMaskNpc(npc_id); - - if (mask_npc != NULL) { - if (ITEM_NAME_GET_TYPE(mask_npc->npc_id) == NAME_TYPE_NPC) { - npc->npc_info.animal = &mask_npc->animal_data; - npc->npc_info.list = NULL; + if (event_npc != NULL) { + npc_info_idx = mNpc_SearchAnimalinfo(Save_Get(animals), event_npc->npc_id, ANIMAL_NUM_MAX); + } } - else { - npc->npc_info.animal = NULL; - npc->npc_info.list = NULL; + + if (npc_info_idx >= 0 && npc_info_idx < ANIMAL_NUM_MAX) { + npc->npc_info.animal = Save_GetPointer(animals[npc_info_idx]); + npc->npc_info.list = Common_GetPointer(npclist[npc_info_idx]); + } else if (npc_info_idx == -ANIMAL_NUM_MAX) { + npc->npc_info.animal = &Save_Get(island).animal; + npc->npc_info.list = Common_GetPointer(island_npclist[0]); + } else { + mNpc_MaskNpc_c* mask_npc = mNpc_GetSameMaskNpc(npc_id); + + if (mask_npc != NULL) { + if (ITEM_NAME_GET_TYPE(mask_npc->npc_id) == NAME_TYPE_NPC) { + npc->npc_info.animal = &mask_npc->animal_data; + npc->npc_info.list = NULL; + } else { + npc->npc_info.animal = NULL; + npc->npc_info.list = NULL; + } + } else { + npc->npc_info.animal = NULL; + npc->npc_info.list = NULL; + } } - } - else { - npc->npc_info.animal = NULL; - npc->npc_info.list = NULL; - } } - } } static void mNpc_AddNpc_inNpcRoom(mFM_move_actor_c* move_actor, int move_actor_idx, u8 bx, u8 bz) { - u32 owner_id = Common_Get(house_owner_name); - mActor_name_t id = owner_id; + u32 owner_id = Common_Get(house_owner_name); + mActor_name_t id = owner_id; - if (id != RSV_NO) { - if (id != EMPTY_NO && mEvNM_CheckJointEvent(owner_id) != TRUE) { - int idx = mNpc_SearchAnimalinfo(Save_Get(animals), id, ANIMAL_NUM_MAX); + if (id != RSV_NO) { + if (id != EMPTY_NO && mEvNM_CheckJointEvent(owner_id) != TRUE) { + int idx = mNpc_SearchAnimalinfo(Save_Get(animals), id, ANIMAL_NUM_MAX); - if (idx != -1) { - move_actor->name_id = id; + if (idx != -1) { + move_actor->name_id = id; + move_actor->ut_x = 4; + move_actor->ut_z = 7; + move_actor->npc_info_idx = idx; + move_actor->arg = -1; + mFI_SetMoveActorBitData_ON(move_actor_idx, bx, bz); + } + } + } +} + +static void mNpc_AddNpc_inNpcRoomIsland(mFM_move_actor_c* move_actor, int move_actor_idx, u8 bx, u8 bz) { + move_actor->name_id = Save_Get(island).animal.id.npc_id; + move_actor->ut_x = 4; + move_actor->ut_z = 7; + move_actor->npc_info_idx = -ANIMAL_NUM_MAX; + move_actor->arg = -1; + mFI_SetMoveActorBitData_ON(move_actor_idx, bx, bz); +} + +static void mNpc_AddNpc_inKamakura(mFM_move_actor_c* move_actor, int move_actor_idx, u8 bx, u8 bz) { + u8* kamakura_event = (u8*)mEv_get_save_area(mEv_EVENT_KAMAKURA, 15); + + if (kamakura_event != NULL) { + int idx = *kamakura_event; + mActor_name_t npc_id = Save_Get(animals[idx]).id.npc_id; + + mEvMN_GetEventNpcName(&npc_id, mEv_EVENT_KAMAKURA, idx, 0); + move_actor->name_id = npc_id; move_actor->ut_x = 4; move_actor->ut_z = 7; move_actor->npc_info_idx = idx; move_actor->arg = -1; mFI_SetMoveActorBitData_ON(move_actor_idx, bx, bz); - } } - } -} - -static void mNpc_AddNpc_inNpcRoomIsland(mFM_move_actor_c* move_actor, int move_actor_idx, u8 bx, u8 bz) { - move_actor->name_id = Save_Get(island).animal.id.npc_id; - move_actor->ut_x = 4; - move_actor->ut_z = 7; - move_actor->npc_info_idx = -ANIMAL_NUM_MAX; - move_actor->arg = -1; - mFI_SetMoveActorBitData_ON(move_actor_idx, bx, bz); -} - -static void mNpc_AddNpc_inKamakura(mFM_move_actor_c* move_actor, int move_actor_idx, u8 bx, u8 bz) { - u8* kamakura_event = (u8*)mEv_get_save_area(mEv_EVENT_KAMAKURA, 15); - - if (kamakura_event != NULL) { - int idx = *kamakura_event; - mActor_name_t npc_id = Save_Get(animals[idx]).id.npc_id; - - mEvMN_GetEventNpcName(&npc_id, mEv_EVENT_KAMAKURA, idx, 0); - move_actor->name_id = npc_id; - move_actor->ut_x = 4; - move_actor->ut_z = 7; - move_actor->npc_info_idx = idx; - move_actor->arg = -1; - mFI_SetMoveActorBitData_ON(move_actor_idx, bx, bz); - } } extern void mNpc_AddNpc_inBlock(mFM_move_actor_c* move_actor_list, u8 bx, u8 bz) { - int scene = Save_Get(scene_no); + int scene = Save_Get(scene_no); - if ((scene == SCENE_NPC_HOUSE || scene == SCENE_KAMAKURA || scene == SCENE_COTTAGE_NPC) && move_actor_list != NULL) { - mActor_name_t field_id = mFI_GetFieldId(); // unused - int move_actor_idx = mFI_GetMoveActorListIdx(move_actor_list, mFM_MOVE_ACTOR_NUM, EMPTY_NO); + if ((scene == SCENE_NPC_HOUSE || scene == SCENE_KAMAKURA || scene == SCENE_COTTAGE_NPC) && + move_actor_list != NULL) { + mActor_name_t field_id = mFI_GetFieldId(); // unused + int move_actor_idx = mFI_GetMoveActorListIdx(move_actor_list, mFM_MOVE_ACTOR_NUM, EMPTY_NO); - if (move_actor_idx != -1 && move_actor_idx < ANIMAL_NUM_MAX) { - move_actor_list += move_actor_idx; + if (move_actor_idx != -1 && move_actor_idx < ANIMAL_NUM_MAX) { + move_actor_list += move_actor_idx; - switch (scene) { - case SCENE_NPC_HOUSE: - mNpc_AddNpc_inNpcRoom(move_actor_list, move_actor_idx, bx, bz); - break; - case SCENE_COTTAGE_NPC: - mNpc_AddNpc_inNpcRoomIsland(move_actor_list, move_actor_idx, bx, bz); - break; - case SCENE_KAMAKURA: - mNpc_AddNpc_inKamakura(move_actor_list, move_actor_idx, bx, bz); - break; - } + switch (scene) { + case SCENE_NPC_HOUSE: + mNpc_AddNpc_inNpcRoom(move_actor_list, move_actor_idx, bx, bz); + break; + case SCENE_COTTAGE_NPC: + mNpc_AddNpc_inNpcRoomIsland(move_actor_list, move_actor_idx, bx, bz); + break; + case SCENE_KAMAKURA: + mNpc_AddNpc_inKamakura(move_actor_list, move_actor_idx, bx, bz); + break; + } + } } - } } extern void mNpc_RenewalNpcRoom(s16* wall_floor) { - mActor_name_t field_id = mFI_GetFieldId(); - mActor_name_t owner_id = Common_Get(house_owner_name); - int island_wall = 0; - int island_floor = 0; - u8 wall = 0; - u8 floor = 0; - int island_room_ftr_num; + mActor_name_t field_id = mFI_GetFieldId(); + mActor_name_t owner_id = Common_Get(house_owner_name); + int island_wall = 0; + int island_floor = 0; + u8 wall = 0; + u8 floor = 0; + int island_room_ftr_num; - if (Save_Get(scene_no) == SCENE_COTTAGE_NPC) { - wall = 8; // exotic wall - floor = 32; // bamboo flooring - island_room_ftr_num = mNpc_GetIslandRoomFtrNum(); + if (Save_Get(scene_no) == SCENE_COTTAGE_NPC) { + wall = 8; // exotic wall + floor = 32; // bamboo flooring + island_room_ftr_num = mNpc_GetIslandRoomFtrNum(); - if (island_room_ftr_num >= 2) { - mNpc_GetIslandWallFloorIdx(&island_wall, &island_floor, Save_Get(island).animal.id.npc_id); - wall = island_wall; + if (island_room_ftr_num >= 2) { + mNpc_GetIslandWallFloorIdx(&island_wall, &island_floor, Save_Get(island).animal.id.npc_id); + wall = island_wall; - if (island_room_ftr_num >= 5) { - floor = island_floor; - } - } - } - else if (mFI_GET_TYPE(field_id) == mFI_FIELD_NPCROOM0 && owner_id != EMPTY_NO && owner_id != RSV_NO) { - int idx = mNpc_SearchAnimalinfo(Save_Get(animals), owner_id, ANIMAL_NUM_MAX); - mNpc_NpcList_c* npclist; + if (island_room_ftr_num >= 5) { + floor = island_floor; + } + } + } else if (mFI_GET_TYPE(field_id) == mFI_FIELD_NPCROOM0 && owner_id != EMPTY_NO && owner_id != RSV_NO) { + int idx = mNpc_SearchAnimalinfo(Save_Get(animals), owner_id, ANIMAL_NUM_MAX); + mNpc_NpcList_c* npclist; - if (idx == -1) { - idx = 0; + if (idx == -1) { + idx = 0; + } + + npclist = Common_GetPointer(npclist[idx]); + + wall = npclist->house_data.wall_id; + floor = npclist->house_data.floor_id; } - npclist = Common_GetPointer(npclist[idx]); - - wall = npclist->house_data.wall_id; - floor = npclist->house_data.floor_id; - } - - wall_floor[0] = (wall << 8) | floor; + wall_floor[0] = (wall << 8) | floor; } extern void mNpc_RenewalSetNpc(ACTOR* actor) { - NPC_ACTOR* npc = (NPC_ACTOR*)actor; - Animal_c* animal; + NPC_ACTOR* npc = (NPC_ACTOR*)actor; + Animal_c* animal; - if (npc->npc_info.list != NULL) { - mActor_name_t field_id = mFI_GetFieldId(); - mNpc_NpcList_c* npclist = npc->npc_info.list; - xyz_t* npc_pos = &npclist->position; + if (npc->npc_info.list != NULL) { + mActor_name_t field_id = mFI_GetFieldId(); + mNpc_NpcList_c* npclist = npc->npc_info.list; + xyz_t* npc_pos = &npclist->position; - if (mFI_GET_TYPE(field_id) == mFI_FIELD_FG) { - xyz_t_move(npc_pos, &actor->world.position); - npclist->appear_flag = TRUE; - animal = &Save_Get(island).animal; + if (mFI_GET_TYPE(field_id) == mFI_FIELD_FG) { + xyz_t_move(npc_pos, &actor->world.position); + npclist->appear_flag = TRUE; + animal = &Save_Get(island).animal; - if (actor->npc_id == animal->id.npc_id) { - int bnum = mFI_GetBlockNum(actor->block_x, actor->block_z); - mFM_move_actor_c* move_actor_list = g_fdinfo->block_info[bnum].fg_info.move_actors; + if (actor->npc_id == animal->id.npc_id) { + int bnum = mFI_GetBlockNum(actor->block_x, actor->block_z); + mFM_move_actor_c* move_actor_list = g_fdinfo->block_info[bnum].fg_info.move_actors; - if (move_actor_list != NULL) { - int move_actor_idx = mFI_GetMoveActorListIdx(move_actor_list, mFM_MOVE_ACTOR_NUM, actor->npc_id); + if (move_actor_list != NULL) { + int move_actor_idx = mFI_GetMoveActorListIdx(move_actor_list, mFM_MOVE_ACTOR_NUM, actor->npc_id); - if (move_actor_idx != -1) { - int bx; - int bz; - int ut_x; - int ut_z; - - if (mFI_Wpos2BkandUtNuminBlock(&bx, &bz, &ut_x, &ut_z, npclist->position) == FALSE) { - ut_x = animal->home_info.ut_x; - ut_z = animal->home_info.ut_z; + if (move_actor_idx != -1) { + int bx; + int bz; + int ut_x; + int ut_z; + + if (mFI_Wpos2BkandUtNuminBlock(&bx, &bz, &ut_x, &ut_z, npclist->position) == FALSE) { + ut_x = animal->home_info.ut_x; + ut_z = animal->home_info.ut_z; + } else if (mNpc_CheckNpcSet(bx, bz, ut_x, ut_z) == FALSE && + mNpc_GetMakeUtNuminBlock_area(&ut_x, &ut_z, bx, bz, 0) == FALSE) { + ut_x = animal->home_info.ut_x; + ut_z = animal->home_info.ut_z; + } + + move_actor_list[move_actor_idx].ut_x = ut_x; + move_actor_list[move_actor_idx].ut_z = ut_z; + } + } + + mFI_MyMoveActorBitData_ON(actor); } - else if (mNpc_CheckNpcSet(bx, bz, ut_x, ut_z) == FALSE && mNpc_GetMakeUtNuminBlock_area(&ut_x, &ut_z, bx, bz, 0) == FALSE) { - ut_x = animal->home_info.ut_x; - ut_z = animal->home_info.ut_z; - } - - move_actor_list[move_actor_idx].ut_x = ut_x; - move_actor_list[move_actor_idx].ut_z = ut_z; - } } - + } else { mFI_MyMoveActorBitData_ON(actor); - } } - } - else { - mFI_MyMoveActorBitData_ON(actor); - } } extern int mNpc_GetFriendAnimalNum(PersonalID_c* pid) { - Animal_c* animal = Save_Get(animals); - int num = 0; - int i; + Animal_c* animal = Save_Get(animals); + int num = 0; + int i; - if (pid != NULL) { - for (i = 0; i < ANIMAL_NUM_MAX; i++) { - if (mNpc_CheckFreeAnimalPersonalID(&animal->id) == FALSE && mNpc_GetAnimalMemoryIdx(pid, animal->memories, ANIMAL_MEMORY_NUM) != -1) { - num++; - } + if (pid != NULL) { + for (i = 0; i < ANIMAL_NUM_MAX; i++) { + if (mNpc_CheckFreeAnimalPersonalID(&animal->id) == FALSE && + mNpc_GetAnimalMemoryIdx(pid, animal->memories, ANIMAL_MEMORY_NUM) != -1) { + num++; + } - animal++; + animal++; + } } - } - return num; + return num; } extern int mNpc_CheckFriendAllAnimal(PersonalID_c* pid) { - int now_npc_max = Save_Get(now_npc_max); - int friend_num = mNpc_GetFriendAnimalNum(pid); + int now_npc_max = Save_Get(now_npc_max); + int friend_num = mNpc_GetFriendAnimalNum(pid); - if (now_npc_max <= friend_num) { - return TRUE; - } + if (now_npc_max <= friend_num) { + return TRUE; + } - return FALSE; + return FALSE; } static int mNpc_CheckSelectFurniture(mActor_name_t item) { - int res = FALSE; + int res = FALSE; - if ( - !(item >= FTR_CLOTH_START && item <= FTR_CLOTH_END ) && // Clothing (furniture) - !(item >= FTR_UMBRELLA_START && item <= FTR_UMBRELLA_END) && // Umbrellas (furniture) - !(item >= FTR_INSECT_START && item <= FTR_INSECT_END ) && // Insects (furniture) - !(item >= FTR_FISH_START && item <= FTR_FISH_END ) && // Fish (furniture) - !(item >= HANIWA_START && item <= HANIWA_END ) && // Gyroids - !(item >= FTR_DINO_START && item <= FTR_DINO_END ) && // Idenitfied fossils - !(item >= FTR_FAMICOM_START && item <= FTR_FAMICOM_END ) // NES/Famicom games - ) { - res = TRUE; - } + if (!(item >= FTR_CLOTH_START && item <= FTR_CLOTH_END) && // Clothing (furniture) + !(item >= FTR_UMBRELLA_START && item <= FTR_UMBRELLA_END) && // Umbrellas (furniture) + !(item >= FTR_INSECT_START && item <= FTR_INSECT_END) && // Insects (furniture) + !(item >= FTR_FISH_START && item <= FTR_FISH_END) && // Fish (furniture) + !(item >= HANIWA_START && item <= HANIWA_END) && // Gyroids + !(item >= FTR_DINO_START && item <= FTR_DINO_END) && // Idenitfied fossils + !(item >= FTR_FAMICOM_START && item <= FTR_FAMICOM_END) // NES/Famicom games + ) { + res = TRUE; + } - return res; + return res; } static mActor_name_t mNpc_DecideNpcFurniture(mFM_fg_data_c** fg_data_table, mNpc_NpcList_c* npclist, int fg_base_id) { - int data_idx = npclist->house_data.main_layer_id - fg_base_id; - mActor_name_t* fg_items; - u8 num = 0; - int ut_z; - int ut_x; + int data_idx = npclist->house_data.main_layer_id - fg_base_id; + mActor_name_t* fg_items; + u8 num = 0; + int ut_z; + int ut_x; - if (data_idx < 0) { - data_idx = 0; - } - - fg_items = fg_data_table[data_idx]->items[0]; - - for (ut_z = 0; ut_z < 10; ut_z++) { - for (ut_x = 0; ut_x < 10; ut_x++) { - if (ITEM_IS_FTR(*fg_items) && mNpc_CheckSelectFurniture(*fg_items) == TRUE) { - num++; - } - - fg_items++; + if (data_idx < 0) { + data_idx = 0; } - fg_items += UT_X_NUM - 10; - } - - if (num != 0) { - num = RANDOM(num); - fg_items = fg_data_table[data_idx]->items[0]; + for (ut_z = 0; ut_z < 10; ut_z++) { - for (ut_x = 0; ut_x < 10; ut_x++) { - if (ITEM_IS_FTR(*fg_items) && mNpc_CheckSelectFurniture(*fg_items) == TRUE) { - if (num <= 0) { - return *fg_items; - } - else { - num--; - } + for (ut_x = 0; ut_x < 10; ut_x++) { + if (ITEM_IS_FTR(*fg_items) && mNpc_CheckSelectFurniture(*fg_items) == TRUE) { + num++; + } + + fg_items++; } - fg_items++; - } - - fg_items += UT_X_NUM - 10; + fg_items += UT_X_NUM - 10; } - } - return EMPTY_NO; + if (num != 0) { + num = RANDOM(num); + + fg_items = fg_data_table[data_idx]->items[0]; + for (ut_z = 0; ut_z < 10; ut_z++) { + for (ut_x = 0; ut_x < 10; ut_x++) { + if (ITEM_IS_FTR(*fg_items) && mNpc_CheckSelectFurniture(*fg_items) == TRUE) { + if (num <= 0) { + return *fg_items; + } else { + num--; + } + } + + fg_items++; + } + + fg_items += UT_X_NUM - 10; + } + } + + return EMPTY_NO; } extern void mNpc_SetNpcFurnitureRandom(mFM_fg_data_c** fg_data_table, int fg_base_id) { - mNpc_NpcList_c* npclist = Common_Get(npclist); - Animal_c* animal = Save_Get(animals); - int i; + mNpc_NpcList_c* npclist = Common_Get(npclist); + Animal_c* animal = Save_Get(animals); + int i; - for (i = 0; i < ANIMAL_NUM_MAX; i++) { - if (mNpc_CheckFreeAnimalPersonalID(&animal->id) == FALSE) { - npclist->reward_furniture = mNpc_DecideNpcFurniture(fg_data_table, npclist, fg_base_id); + for (i = 0; i < ANIMAL_NUM_MAX; i++) { + if (mNpc_CheckFreeAnimalPersonalID(&animal->id) == FALSE) { + npclist->reward_furniture = mNpc_DecideNpcFurniture(fg_data_table, npclist, fg_base_id); + } + + npclist++; + animal++; } - - npclist++; - animal++; - } } extern mActor_name_t mNpc_GetNpcFurniture(AnmPersonalID_c* anm_id) { - mActor_name_t furniture = EMPTY_NO; - int idx = mNpc_SearchAnimalPersonalID(anm_id); + mActor_name_t furniture = EMPTY_NO; + int idx = mNpc_SearchAnimalPersonalID(anm_id); - if (idx != -1) { - furniture = Common_Get(npclist[idx]).reward_furniture; - } + if (idx != -1) { + furniture = Common_Get(npclist[idx]).reward_furniture; + } - return furniture; + return furniture; } static Animal_c l_mnpc_remove_in_animal; extern void mNpc_ClearInAnimal() { - mNpc_ClearAnimalInfo(&l_mnpc_remove_in_animal); + mNpc_ClearAnimalInfo(&l_mnpc_remove_in_animal); } extern Animal_c* mNpc_GetInAnimalP() { - return &l_mnpc_remove_in_animal; + return &l_mnpc_remove_in_animal; } static void mNpc_RenewRemoveHistory() { - mTM_set_renew_time(Save_GetPointer(force_remove_date), Common_GetPointer(time.rtc_time)); + mTM_set_renew_time(Save_GetPointer(force_remove_date), Common_GetPointer(time.rtc_time)); } static int mNpc_DecideRemoveAnimalNo_Friend(Animal_c* animal, int ignored_idx, int met_all_flag) { - int res; - Private_c* priv_p; - int n_players; - int num_possible; - u16 remove_bitfield; - int met; - int selected; - int i; - int j; + int res; + Private_c* priv_p; + int n_players; + int num_possible; + u16 remove_bitfield; + int met; + int selected; + int i; + int j; - res = -1; - n_players = 0; - num_possible = 0; - remove_bitfield = 0; - priv_p = Save_Get(private); + res = -1; + n_players = 0; + num_possible = 0; + remove_bitfield = 0; + priv_p = Save_Get(private); - for (i = 0; i < PLAYER_NUM; i++) { - if (mPr_NullCheckPersonalID(&priv_p->player_ID) == FALSE) { - n_players++; + for (i = 0; i < PLAYER_NUM; i++) { + if (mPr_NullCheckPersonalID(&priv_p->player_ID) == FALSE) { + n_players++; + } + + priv_p++; } - priv_p++; - } + if (n_players > 0) { + for (i = 0; i < ANIMAL_NUM_MAX; i++) { + if (mNpc_CheckFreeAnimalInfo(animal) == FALSE && i != ignored_idx) { + met = 0; + priv_p = Save_Get(private); - if (n_players > 0) { - for (i = 0; i < ANIMAL_NUM_MAX; i++) { - if (mNpc_CheckFreeAnimalInfo(animal) == FALSE && i != ignored_idx) { - met = 0; - priv_p = Save_Get(private); + for (j = 0; j < PLAYER_NUM; j++) { + if (mPr_NullCheckPersonalID(&priv_p->player_ID) == FALSE) { + if (mNpc_GetAnimalMemoryIdx(&priv_p->player_ID, animal->memories, ANIMAL_MEMORY_NUM) == -1) { + break; + } - for (j = 0; j < PLAYER_NUM; j++) { - if (mPr_NullCheckPersonalID(&priv_p->player_ID) == FALSE) { - if (mNpc_GetAnimalMemoryIdx(&priv_p->player_ID, animal->memories, ANIMAL_MEMORY_NUM) == -1) { - break; + met++; + } + + priv_p++; + } + + if (met_all_flag == TRUE) { + if (met == n_players) { + remove_bitfield |= (1 << i); + num_possible++; + } + } else if (met > 0) { + remove_bitfield |= (1 << i); + num_possible++; + } } - met++; - } - - priv_p++; + animal++; } - - if (met_all_flag == TRUE) { - if (met == n_players) { - remove_bitfield |= (1 << i); - num_possible++; - } - } - else if (met > 0) { - remove_bitfield |= (1 << i); - num_possible++; - } - } - - animal++; } - } - if (num_possible > 0) { - selected = RANDOM(num_possible); + if (num_possible > 0) { + selected = RANDOM(num_possible); - for (i = 0; i < ANIMAL_NUM_MAX; i++) { - if (((remove_bitfield >> i) & 1) == 1) { - if (selected <= 0) { - res = i; - break; + for (i = 0; i < ANIMAL_NUM_MAX; i++) { + if (((remove_bitfield >> i) & 1) == 1) { + if (selected <= 0) { + res = i; + break; + } else { + selected--; + } + } } - else { - selected--; - } - } } - } - return res; + return res; } static int mNpc_DecideRemoveAnimalNo(Animal_c* animal, int ignored_idx, int now_npc_max) { - int i; - int selected; - int res = -1; + int i; + int selected; + int res = -1; - if (ignored_idx >= 0 || ignored_idx < ANIMAL_NUM_MAX) { - now_npc_max--; - } - - if (now_npc_max > 0 && now_npc_max <= ANIMAL_NUM_MAX) { - selected = RANDOM(now_npc_max); - - for (i = 0; i < ANIMAL_NUM_MAX; i++) { - if (mNpc_CheckFreeAnimalInfo(animal) == FALSE) { - if (selected <= 0 && ignored_idx != i) { - res = i; - break; - } - else { - selected--; - } - } - - animal++; + if (ignored_idx >= 0 || ignored_idx < ANIMAL_NUM_MAX) { + now_npc_max--; } - } - return res; + if (now_npc_max > 0 && now_npc_max <= ANIMAL_NUM_MAX) { + selected = RANDOM(now_npc_max); + + for (i = 0; i < ANIMAL_NUM_MAX; i++) { + if (mNpc_CheckFreeAnimalInfo(animal) == FALSE) { + if (selected <= 0 && ignored_idx != i) { + res = i; + break; + } else { + selected--; + } + } + + animal++; + } + } + + return res; } /* 50% */ extern void mNpc_SetRemoveAnimalNo(u8* remove_animal_no, Animal_c* animal, int ignored_idx) { - u8 now_npc_max = Save_Get(now_npc_max); + u8 now_npc_max = Save_Get(now_npc_max); - if (now_npc_max > ANIMAL_NUM_MIN && remove_animal_no[0] == 0xFF) { - /* First, try to pick an animal which all players have met before */ - int remove_no = mNpc_DecideRemoveAnimalNo_Friend(animal, ignored_idx, TRUE); + if (now_npc_max > ANIMAL_NUM_MIN && remove_animal_no[0] == 0xFF) { + /* First, try to pick an animal which all players have met before */ + int remove_no = mNpc_DecideRemoveAnimalNo_Friend(animal, ignored_idx, TRUE); - if (remove_no == -1) { - /* Next, try to pick an animal which at least one player has met before */ - remove_no = mNpc_DecideRemoveAnimalNo_Friend(animal, ignored_idx, FALSE); + if (remove_no == -1) { + /* Next, try to pick an animal which at least one player has met before */ + remove_no = mNpc_DecideRemoveAnimalNo_Friend(animal, ignored_idx, FALSE); - if (remove_no == -1) { - /* Finally, forcefully find an animal to remove */ - remove_no = mNpc_DecideRemoveAnimalNo(animal, ignored_idx, now_npc_max); - } + if (remove_no == -1) { + /* Finally, forcefully find an animal to remove */ + remove_no = mNpc_DecideRemoveAnimalNo(animal, ignored_idx, now_npc_max); + } + } + + if (remove_no != -1) { + remove_animal_no[0] = remove_no; + } } - - if (remove_no != -1) { - remove_animal_no[0] = remove_no; - } - } } static int mNpc_CheckGoodbyAnimalMemoryNum(Animal_c* a0, Animal_c* a1) { - Anmmem_c* memories0 = a0->memories; - Anmmem_c* memories1 = a1->memories; - int res = 0; - int res0; - int res1; + Anmmem_c* memories0 = a0->memories; + Anmmem_c* memories1 = a1->memories; + int res = 0; + int res0; + int res1; - res0 = mNpc_GetAnimalMemoryNum(memories0, ANIMAL_MEMORY_NUM); - res1 = mNpc_GetAnimalMemoryNum(memories1, ANIMAL_MEMORY_NUM); - - /* Check the total number of memories first */ - if (res1 > res0) { - res = 1; - } - else if (res1 == res0) { - /* Next, check the number of memories which have a letter associated with them */ - res0 = mNpc_GetAnimalMemoryLetterNum(memories0, ANIMAL_MEMORY_NUM); - res1 = mNpc_GetAnimalMemoryLetterNum(memories1, ANIMAL_MEMORY_NUM); + res0 = mNpc_GetAnimalMemoryNum(memories0, ANIMAL_MEMORY_NUM); + res1 = mNpc_GetAnimalMemoryNum(memories1, ANIMAL_MEMORY_NUM); + /* Check the total number of memories first */ if (res1 > res0) { - res = 1; - } - else if (res1 == res0) { - /* Next, check the number of unique towns each animal's memories contains */ - res0 = mNpc_GetAnimalMemoryLandKindNum(memories0, ANIMAL_MEMORY_NUM); - res1 = mNpc_GetAnimalMemoryLandKindNum(memories1, ANIMAL_MEMORY_NUM); - - if (res1 > res0) { res = 1; - } - else if (res1 == res0) { - /* Finally, check the total number of animals in town with the same personality and pick the one with more */ - res0 = mNpc_GetSameLooksNum(a0->id.looks); - res1 = mNpc_GetSameLooksNum(a1->id.looks); + } else if (res1 == res0) { + /* Next, check the number of memories which have a letter associated with them */ + res0 = mNpc_GetAnimalMemoryLetterNum(memories0, ANIMAL_MEMORY_NUM); + res1 = mNpc_GetAnimalMemoryLetterNum(memories1, ANIMAL_MEMORY_NUM); - if (res1 < res0) { - res = 1; + if (res1 > res0) { + res = 1; + } else if (res1 == res0) { + /* Next, check the number of unique towns each animal's memories contains */ + res0 = mNpc_GetAnimalMemoryLandKindNum(memories0, ANIMAL_MEMORY_NUM); + res1 = mNpc_GetAnimalMemoryLandKindNum(memories1, ANIMAL_MEMORY_NUM); + + if (res1 > res0) { + res = 1; + } else if (res1 == res0) { + /* Finally, check the total number of animals in town with the same personality and pick the one with + * more */ + res0 = mNpc_GetSameLooksNum(a0->id.looks); + res1 = mNpc_GetSameLooksNum(a1->id.looks); + + if (res1 < res0) { + res = 1; + } else { + res = -1; + } + } } - else { - res = -1; - } - } } - } - return res; + return res; } extern int mNpc_GetGoodbyAnimalIdx(int ignored_idx) { - Animal_c* animal; - Animal_c* other_animal = NULL; - int res0; - int res1; - int selected; - u16 remove_bitfield; - int candidate_num; - int goodby_animal_idx; - int i; + Animal_c* animal; + Animal_c* other_animal = NULL; + int res0; + int res1; + int selected; + u16 remove_bitfield; + int candidate_num; + int goodby_animal_idx; + int i; - animal = Save_Get(animals); - remove_bitfield = 0; - candidate_num = 0; - goodby_animal_idx = -1; - - for (i = 0; i < ANIMAL_NUM_MAX; i++) { - if ( - i != Save_Get(remove_animal_idx) && - ((ignored_idx >= 0 && ignored_idx < ANIMAL_NUM_MAX && i != ignored_idx) || ignored_idx == -1) && - mNpc_CheckFreeAnimalInfo(animal) == FALSE - ) { - if (other_animal != NULL) { - /* Compare remove experience first (unused feature) */ - if (mNpc_CheckRemoveExp(animal) == 0) { - if (mNpc_CheckRemoveExp(other_animal) != 0) { - candidate_num = 1; - remove_bitfield = (1 << i); - other_animal = animal; - goodby_animal_idx = i; - } - else { - /* Compare total memories in each animal */ - res1 = mNpc_CheckGoodbyAnimalMemoryNum(animal, other_animal); - switch (res1) { - case -1: - candidate_num++; - remove_bitfield |= (1 << i); - break; - case 1: - candidate_num = 1; - remove_bitfield = (1 << i); - other_animal = animal; - goodby_animal_idx = i; - break; - } - } - } - else if (mNpc_CheckRemoveExp(other_animal) != 0) { - /* NOTE: this path can never be taken due to remove experiences never being set */ - /* Compare times removed (unused feature) */ - res0 = mNpc_GetRemoveTime(animal); - res1 = mNpc_GetRemoveTime(other_animal); - if (res1 > res0) { - candidate_num = 1; - remove_bitfield = (1 << i); - other_animal = animal; - goodby_animal_idx = i; - } - else if (res1 == res0) { - /* Compare total memories in each animal */ - res1 = mNpc_CheckGoodbyAnimalMemoryNum(animal, other_animal); - switch (res1) { - case -1: - candidate_num++; - remove_bitfield |= (1 << i); - break; - case 1: - candidate_num = 1; - remove_bitfield = (1 << i); - other_animal = animal; - goodby_animal_idx = i; - break; - } - } - } - } - else { - candidate_num = 1; - remove_bitfield = (1 << i); - other_animal = animal; - goodby_animal_idx = i; - } - } - - animal++; - } - - animal = Save_Get(animals); - if (candidate_num > 1) { - selected = RANDOM(candidate_num); + animal = Save_Get(animals); + remove_bitfield = 0; + candidate_num = 0; + goodby_animal_idx = -1; for (i = 0; i < ANIMAL_NUM_MAX; i++) { - if (((remove_bitfield >> i) & 1) == 1) { - if (selected == 0) { - goodby_animal_idx = i; - break; + if (i != Save_Get(remove_animal_idx) && + ((ignored_idx >= 0 && ignored_idx < ANIMAL_NUM_MAX && i != ignored_idx) || ignored_idx == -1) && + mNpc_CheckFreeAnimalInfo(animal) == FALSE) { + if (other_animal != NULL) { + /* Compare remove experience first (unused feature) */ + if (mNpc_CheckRemoveExp(animal) == 0) { + if (mNpc_CheckRemoveExp(other_animal) != 0) { + candidate_num = 1; + remove_bitfield = (1 << i); + other_animal = animal; + goodby_animal_idx = i; + } else { + /* Compare total memories in each animal */ + res1 = mNpc_CheckGoodbyAnimalMemoryNum(animal, other_animal); + switch (res1) { + case -1: + candidate_num++; + remove_bitfield |= (1 << i); + break; + case 1: + candidate_num = 1; + remove_bitfield = (1 << i); + other_animal = animal; + goodby_animal_idx = i; + break; + } + } + } else if (mNpc_CheckRemoveExp(other_animal) != 0) { + /* NOTE: this path can never be taken due to remove experiences never being set */ + /* Compare times removed (unused feature) */ + res0 = mNpc_GetRemoveTime(animal); + res1 = mNpc_GetRemoveTime(other_animal); + if (res1 > res0) { + candidate_num = 1; + remove_bitfield = (1 << i); + other_animal = animal; + goodby_animal_idx = i; + } else if (res1 == res0) { + /* Compare total memories in each animal */ + res1 = mNpc_CheckGoodbyAnimalMemoryNum(animal, other_animal); + switch (res1) { + case -1: + candidate_num++; + remove_bitfield |= (1 << i); + break; + case 1: + candidate_num = 1; + remove_bitfield = (1 << i); + other_animal = animal; + goodby_animal_idx = i; + break; + } + } + } + } else { + candidate_num = 1; + remove_bitfield = (1 << i); + other_animal = animal; + goodby_animal_idx = i; + } } - else { - selected--; - } - } - animal++; + animal++; } - } - return goodby_animal_idx; + animal = Save_Get(animals); + if (candidate_num > 1) { + selected = RANDOM(candidate_num); + + for (i = 0; i < ANIMAL_NUM_MAX; i++) { + if (((remove_bitfield >> i) & 1) == 1) { + if (selected == 0) { + goodby_animal_idx = i; + break; + } else { + selected--; + } + } + + animal++; + } + } + + return goodby_animal_idx; } typedef struct animal_goodbye_mail_s { - AnmPersonalID_c id; - u8 deliver_to_bitfield; + AnmPersonalID_c id; + u8 deliver_to_bitfield; } Anm_GoodbyMail_c; static Anm_GoodbyMail_c l_mnpc_goodby_mail; static void mNpc_ClearGoodbyMail(Anm_GoodbyMail_c* goodby_mail) { - mNpc_ClearAnimalPersonalID(&goodby_mail->id); - goodby_mail->deliver_to_bitfield = 0; + mNpc_ClearAnimalPersonalID(&goodby_mail->id); + goodby_mail->deliver_to_bitfield = 0; } extern void mNpc_FirstClearGoodbyMail() { - mNpc_ClearGoodbyMail(&l_mnpc_goodby_mail); + mNpc_ClearGoodbyMail(&l_mnpc_goodby_mail); } static void mNpc_SetGoodbyAnimalMail(Anm_GoodbyMail_c* goodby_mail, AnmPersonalID_c* anm_id) { - Private_c* priv = Save_Get(private); - int i; + Private_c* priv = Save_Get(private); + int i; - if (anm_id != NULL && mNpc_CheckFreeAnimalPersonalID(anm_id) == FALSE) { - mNpc_ClearGoodbyMail(goodby_mail); - mNpc_CopyAnimalPersonalID(&goodby_mail->id, anm_id); + if (anm_id != NULL && mNpc_CheckFreeAnimalPersonalID(anm_id) == FALSE) { + mNpc_ClearGoodbyMail(goodby_mail); + mNpc_CopyAnimalPersonalID(&goodby_mail->id, anm_id); - for (i = 0; i < PLAYER_NUM; i++) { - if (mPr_NullCheckPersonalID(&priv->player_ID) == FALSE) { - goodby_mail->deliver_to_bitfield |= (1 << i); - } + for (i = 0; i < PLAYER_NUM; i++) { + if (mPr_NullCheckPersonalID(&priv->player_ID) == FALSE) { + goodby_mail->deliver_to_bitfield |= (1 << i); + } - priv++; + priv++; + } } - } } static int mNpc_SetGoodbyMailData(Mail_c* mail, PersonalID_c* pid, AnmPersonalID_c* anm_id) { - static u8 animal_name[ANIMAL_NAME_LEN]; + static u8 animal_name[ANIMAL_NAME_LEN]; - u8 looks = anm_id->looks; - int mail_no; - int res = FALSE; + u8 looks = anm_id->looks; + int mail_no; + int res = FALSE; - if (looks < mNpc_LOOKS_NUM) { - mail_no = 0x20E + looks * 3; - mail_no += mQst_GetRandom(3); - mNpc_GetNpcWorldNameAnm(animal_name, anm_id); - mHandbill_Set_free_str(mHandbill_FREE_STR0, pid->player_name, PLAYER_NAME_LEN); - mHandbill_Set_free_str(mHandbill_FREE_STR1, animal_name, ANIMAL_NAME_LEN); - mHandbill_Set_free_str(mHandbill_FREE_STR3, Save_Get(land_info).name, LAND_NAME_SIZE); - mNpc_LoadMailDataCommon2(mail, pid, anm_id, EMPTY_NO, mNpc_GetPaperType(), mail_no); - res = TRUE; - } + if (looks < mNpc_LOOKS_NUM) { + mail_no = 0x20E + looks * 3; + mail_no += mQst_GetRandom(3); + mNpc_GetNpcWorldNameAnm(animal_name, anm_id); + mHandbill_Set_free_str(mHandbill_FREE_STR0, pid->player_name, PLAYER_NAME_LEN); + mHandbill_Set_free_str(mHandbill_FREE_STR1, animal_name, ANIMAL_NAME_LEN); + mHandbill_Set_free_str(mHandbill_FREE_STR3, Save_Get(land_info).name, LAND_NAME_SIZE); + mNpc_LoadMailDataCommon2(mail, pid, anm_id, EMPTY_NO, mNpc_GetPaperType(), mail_no); + res = TRUE; + } - return res; + return res; } static int mNpc_SendGoodbyAnimalMailOne(Mail_c* mail, PersonalID_c* pid, int player_no, Anm_GoodbyMail_c* goodby_mail) { - int free_space; - mHm_hs_c* home; - int res = FALSE; + int free_space; + mHm_hs_c* home; + int res = FALSE; - home = Save_GetPointer(homes[mHS_get_arrange_idx(player_no)]); + home = Save_GetPointer(homes[mHS_get_arrange_idx(player_no)]); - if (mPr_NullCheckPersonalID(pid) == FALSE && mPr_CheckCmpPersonalID(pid, &home->ownerID) == TRUE) { - free_space = mMl_chk_mail_free_space(home->mailbox, HOME_MAILBOX_SIZE); + if (mPr_NullCheckPersonalID(pid) == FALSE && mPr_CheckCmpPersonalID(pid, &home->ownerID) == TRUE) { + free_space = mMl_chk_mail_free_space(home->mailbox, HOME_MAILBOX_SIZE); - if (free_space != -1) { - if (mNpc_SetGoodbyMailData(mail, pid, &goodby_mail->id) == TRUE) { - mMl_copy_mail(home->mailbox + free_space, mail); - res = TRUE; - } + if (free_space != -1) { + if (mNpc_SetGoodbyMailData(mail, pid, &goodby_mail->id) == TRUE) { + mMl_copy_mail(home->mailbox + free_space, mail); + res = TRUE; + } + } else if (mPO_get_keep_mail_sum() < mPO_MAIL_STORAGE_SIZE && + mNpc_SetGoodbyMailData(mail, pid, &goodby_mail->id) == TRUE) { + res = mPO_receipt_proc(mail, mPO_SENDTYPE_MAIL); + } } - else if (mPO_get_keep_mail_sum() < mPO_MAIL_STORAGE_SIZE && mNpc_SetGoodbyMailData(mail, pid, &goodby_mail->id) == TRUE) { - res = mPO_receipt_proc(mail, mPO_SENDTYPE_MAIL); - } - } - return res; + return res; } static void mNpc_SendGoodbyAnimalMail(Anm_GoodbyMail_c* goodby_mail) { - Private_c* priv = Save_Get(private); - int i; + Private_c* priv = Save_Get(private); + int i; - if (mNpc_CheckFreeAnimalPersonalID(&goodby_mail->id) == FALSE) { - for (i = 0; i < PLAYER_NUM; i++) { - if (((goodby_mail->deliver_to_bitfield >> i) & 1) == 1) { - mMl_clear_mail(&l_npc_mail); + if (mNpc_CheckFreeAnimalPersonalID(&goodby_mail->id) == FALSE) { + for (i = 0; i < PLAYER_NUM; i++) { + if (((goodby_mail->deliver_to_bitfield >> i) & 1) == 1) { + mMl_clear_mail(&l_npc_mail); - if (mNpc_SendGoodbyAnimalMailOne(&l_npc_mail, &priv->player_ID, i, goodby_mail) == TRUE) { - goodby_mail->deliver_to_bitfield &= ~(1 << i); // player received goodbye letter + if (mNpc_SendGoodbyAnimalMailOne(&l_npc_mail, &priv->player_ID, i, goodby_mail) == TRUE) { + goodby_mail->deliver_to_bitfield &= ~(1 << i); // player received goodbye letter + } + } + + priv++; } - } - priv++; + if (goodby_mail->deliver_to_bitfield == 0) { + mNpc_ClearGoodbyMail(goodby_mail); // all players received goodbye letter + } } - - if (goodby_mail->deliver_to_bitfield == 0) { - mNpc_ClearGoodbyMail(goodby_mail); // all players received goodbye letter - } - } } extern void mNpc_SendRegisteredGoodbyMail() { - mNpc_SendGoodbyAnimalMail(&l_mnpc_goodby_mail); + mNpc_SendGoodbyAnimalMail(&l_mnpc_goodby_mail); } extern void mNpc_GetRemoveAnimal(Animal_c* transferring_animal, int moving_out) { - Private_c* priv = Common_Get(now_private); - u8* now_npc_max = Save_GetPointer(now_npc_max); - int new_animal; - Animal_c* animal2; - Animal_c* animal = Save_Get(animals); - int free_animal_idx; - u8* remove_animal_idx = Save_GetPointer(remove_animal_idx); - int bruh; - int i; + Private_c* priv = Common_Get(now_private); + u8* now_npc_max = Save_GetPointer(now_npc_max); + int new_animal; + Animal_c* animal2; + Animal_c* animal = Save_Get(animals); + int free_animal_idx; + u8* remove_animal_idx = Save_GetPointer(remove_animal_idx); + int bruh; + int i; - new_animal = TRUE; + new_animal = TRUE; - if (mLd_PlayerManKindCheck() == FALSE) { - if (moving_out == TRUE) { - if (*remove_animal_idx != 0xFF) { - animal2 = Save_GetPointer(animals[*remove_animal_idx]); - animal2->removing = FALSE; - mNpc_CopyAnimalInfo(transferring_animal, animal2); - mNpc_DestroyHouse(&animal2->home_info); - mNpc_ClearAnimalInfo(animal2); - now_npc_max[0]--; - *remove_animal_idx = 0xFF; - } - } - } - else { - if (mNpc_CheckFreeAnimalInfo(transferring_animal) == FALSE && transferring_animal->removing == FALSE) { - mActor_name_t* summercamper_id; - - /* The incoming animal cannot be present in the town already */ - for (i = 0; i < ANIMAL_NUM_MAX; i++) { - if (transferring_animal->id.npc_id == animal->id.npc_id) { - new_animal = FALSE; - break; + if (mLd_PlayerManKindCheck() == FALSE) { + if (moving_out == TRUE) { + if (*remove_animal_idx != 0xFF) { + animal2 = Save_GetPointer(animals[*remove_animal_idx]); + animal2->removing = FALSE; + mNpc_CopyAnimalInfo(transferring_animal, animal2); + mNpc_DestroyHouse(&animal2->home_info); + mNpc_ClearAnimalInfo(animal2); + now_npc_max[0]--; + *remove_animal_idx = 0xFF; + } } + } else { + if (mNpc_CheckFreeAnimalInfo(transferring_animal) == FALSE && transferring_animal->removing == FALSE) { + mActor_name_t* summercamper_id; - animal++; - } + /* The incoming animal cannot be present in the town already */ + for (i = 0; i < ANIMAL_NUM_MAX; i++) { + if (transferring_animal->id.npc_id == animal->id.npc_id) { + new_animal = FALSE; + break; + } - /* The last animal who left the town cannot be the next animal to transfer in */ - if (transferring_animal->id.npc_id == Save_Get(last_removed_animal_id).npc_id) { - new_animal = FALSE; - } + animal++; + } - /* Ensure that the animal moving in is not the same one that's currently visiting as a summer camper */ - summercamper_id = (mActor_name_t*)mEv_get_save_area(mEv_EVENT_SUMMER_CAMPER, 0); - if (summercamper_id != NULL) { - if (ITEM_NAME_GET_TYPE(summercamper_id[0]) == NAME_TYPE_NPC) { - mActor_name_t id = transferring_animal->id.npc_id; - - if (id == summercamper_id[0]) { + /* The last animal who left the town cannot be the next animal to transfer in */ + if (transferring_animal->id.npc_id == Save_Get(last_removed_animal_id).npc_id) { + new_animal = FALSE; + } + + /* Ensure that the animal moving in is not the same one that's currently visiting as a summer camper */ + summercamper_id = (mActor_name_t*)mEv_get_save_area(mEv_EVENT_SUMMER_CAMPER, 0); + if (summercamper_id != NULL) { + if (ITEM_NAME_GET_TYPE(summercamper_id[0]) == NAME_TYPE_NPC) { + mActor_name_t id = transferring_animal->id.npc_id; + + if (id == summercamper_id[0]) { + new_animal = FALSE; + } + } + } + } else { + /* The new animal was unintialized or was scheduled to move out */ new_animal = FALSE; - } - } - } - } - else { - /* The new animal was unintialized or was scheduled to move out */ - new_animal = FALSE; - } - - if (new_animal == TRUE) { - animal = Save_Get(animals); - - /* Try to find an unused slot in the animal data */ - free_animal_idx = mNpc_GetFreeAnimalInfo(Save_Get(animals), ANIMAL_NUM_MAX); - - if (free_animal_idx == -1) { - /* No slot, so we're going to replace a villager from in town */ - free_animal_idx = mNpc_GetGoodbyAnimalIdx(-1); - - if (free_animal_idx == -1) { - /* Final fallback, delete the first villager */ - free_animal_idx = 0; - } - - animal += free_animal_idx; - mNpc_DestroyHouse(&animal->home_info); - mNpc_SetGoodbyAnimalMail(&l_mnpc_goodby_mail, &animal->id); - mNpc_SendRegisteredGoodbyMail(); - } - else { - animal += free_animal_idx; - mNpc_AddNowNpcMax(now_npc_max); } - mNpc_ClearAnimalInfo(animal); - mNpc_CopyAnimalInfo(animal, transferring_animal); - animal->home_info.block_x = 0xFF; - animal->home_info.block_z = 0xFF; - animal->home_info.ut_x = 0xFF; - animal->home_info.ut_z = 0xFF; - mLd_CopyLandName(animal->anmuni.previous_land_name, Common_Get(now_private)->player_ID.land_name); - animal->previous_land_id = Common_Get(now_private)->player_ID.land_id; - mQst_ClearContest(&animal->contest_quest); - mNpc_ClearHPMail(animal->hp_mail, ANIMAL_HP_MAIL_NUM); - transferring_animal->removing = TRUE; - priv->animal_memory.npc_id = animal->id.npc_id; - mLd_CopyLandName(priv->animal_memory.land_name, mLd_GetLandName()); - mNpc_SetHaveAppeared(animal->id.npc_id); - mNpc_ResetAnimalRelation(free_animal_idx); - mNpc_RenewRemoveHistory(); + if (new_animal == TRUE) { + animal = Save_Get(animals); + + /* Try to find an unused slot in the animal data */ + free_animal_idx = mNpc_GetFreeAnimalInfo(Save_Get(animals), ANIMAL_NUM_MAX); + + if (free_animal_idx == -1) { + /* No slot, so we're going to replace a villager from in town */ + free_animal_idx = mNpc_GetGoodbyAnimalIdx(-1); + + if (free_animal_idx == -1) { + /* Final fallback, delete the first villager */ + free_animal_idx = 0; + } + + animal += free_animal_idx; + mNpc_DestroyHouse(&animal->home_info); + mNpc_SetGoodbyAnimalMail(&l_mnpc_goodby_mail, &animal->id); + mNpc_SendRegisteredGoodbyMail(); + } else { + animal += free_animal_idx; + mNpc_AddNowNpcMax(now_npc_max); + } + + mNpc_ClearAnimalInfo(animal); + mNpc_CopyAnimalInfo(animal, transferring_animal); + animal->home_info.block_x = 0xFF; + animal->home_info.block_z = 0xFF; + animal->home_info.ut_x = 0xFF; + animal->home_info.ut_z = 0xFF; + mLd_CopyLandName(animal->anmuni.previous_land_name, Common_Get(now_private)->player_ID.land_name); + animal->previous_land_id = Common_Get(now_private)->player_ID.land_id; + mQst_ClearContest(&animal->contest_quest); + mNpc_ClearHPMail(animal->hp_mail, ANIMAL_HP_MAIL_NUM); + transferring_animal->removing = TRUE; + priv->animal_memory.npc_id = animal->id.npc_id; + mLd_CopyLandName(priv->animal_memory.land_name, mLd_GetLandName()); + mNpc_SetHaveAppeared(animal->id.npc_id); + mNpc_ResetAnimalRelation(free_animal_idx); + mNpc_RenewRemoveHistory(); + } } - } } static int mNpc_CheckBuildHouse(int bx, int bz, u8 ut_x, u8 ut_z) { - int res = FALSE; + int res = FALSE; - if (bx >= 0 && bx < FG_BLOCK_X_NUM && bz >= 0 && bz < FG_BLOCK_Z_NUM && ut_x < UT_X_NUM && ut_z < UT_Z_NUM) { - mActor_name_t item = Save_Get(fg[bz][bx]).items[ut_z][ut_x]; + if (bx >= 0 && bx < FG_BLOCK_X_NUM && bz >= 0 && bz < FG_BLOCK_Z_NUM && ut_x < UT_X_NUM && ut_z < UT_Z_NUM) { + mActor_name_t item = Save_Get(fg[bz][bx]).items[ut_z][ut_x]; - if (mNT_IS_RESERVE(item)) { - res = TRUE; + if (mNT_IS_RESERVE(item)) { + res = TRUE; + } } - } - return res; + return res; } extern void mNpc_SetReturnAnimal(Animal_c* return_animal) { - Anmhome_c* home_info; - Animal_c* animals = Save_Get(animals); - Animal_c* found_animal = NULL; - u8* now_npc_max = Save_GetPointer(now_npc_max); - Anmret_c* return_animal_p = Save_GetPointer(return_animal); - int found_animal_idx; - int ignored_idx = -1; + Anmhome_c* home_info; + Animal_c* animals = Save_Get(animals); + Animal_c* found_animal = NULL; + u8* now_npc_max = Save_GetPointer(now_npc_max); + Anmret_c* return_animal_p = Save_GetPointer(return_animal); + int found_animal_idx; + int ignored_idx = -1; - if (mLd_PlayerManKindCheck() == FALSE && mNpc_CheckFreeAnimalInfo(return_animal) == FALSE) { - if (return_animal->removing == FALSE) { - found_animal_idx = mNpc_SearchAnimalinfo(animals, return_animal->id.npc_id, ANIMAL_NUM_MAX); + if (mLd_PlayerManKindCheck() == FALSE && mNpc_CheckFreeAnimalInfo(return_animal) == FALSE) { + if (return_animal->removing == FALSE) { + found_animal_idx = mNpc_SearchAnimalinfo(animals, return_animal->id.npc_id, ANIMAL_NUM_MAX); - if (found_animal_idx != -1) { - found_animal = &animals[found_animal_idx]; - mNpc_DestroyHouse(&found_animal->home_info); - (*now_npc_max)--; + if (found_animal_idx != -1) { + found_animal = &animals[found_animal_idx]; + mNpc_DestroyHouse(&found_animal->home_info); + (*now_npc_max)--; - if (Save_Get(remove_animal_idx) == found_animal_idx) { - Save_Set(remove_animal_idx, 0xFF); - } - } - else if ((*now_npc_max) >= ANIMAL_NUM_MAX) { - if (Save_Get(scene_no) == SCENE_PLAYERSELECT_2) { - /* Don't remove the animal we just saw on the player select screen */ - ignored_idx = Common_Get(player_select_animal_no); + if (Save_Get(remove_animal_idx) == found_animal_idx) { + Save_Set(remove_animal_idx, 0xFF); + } + } else if ((*now_npc_max) >= ANIMAL_NUM_MAX) { + if (Save_Get(scene_no) == SCENE_PLAYERSELECT_2) { + /* Don't remove the animal we just saw on the player select screen */ + ignored_idx = Common_Get(player_select_animal_no); + } + + found_animal_idx = mNpc_GetGoodbyAnimalIdx(ignored_idx); + + if (found_animal_idx == -1) { + found_animal_idx = 0; // fallback + } + + found_animal = &animals[found_animal_idx]; + mNpc_SetGoodbyAnimalMail(&l_mnpc_goodby_mail, &found_animal->id); + mNpc_DestroyHouse(&found_animal->home_info); + (*now_npc_max)--; + + if (Save_Get(remove_animal_idx) == found_animal_idx) { + Save_Set(remove_animal_idx, 0xFF); + } + } else { + found_animal_idx = mNpc_GetFreeAnimalInfo(animals, ANIMAL_NUM_MAX); + + if (found_animal_idx != -1) { + found_animal = &animals[found_animal_idx]; + } + } + + if (found_animal != NULL) { + mNpc_ClearAnimalInfo(found_animal); + mNpc_CopyAnimalInfo(found_animal, return_animal); + mNpc_ResetAnimalRelation(found_animal_idx); + home_info = &found_animal->home_info; + + if (mNpc_CheckBuildHouse(home_info->block_x - 1, home_info->block_z - 1, home_info->ut_x, + home_info->ut_z - 1) == TRUE) { + mNpc_BuildHouseBeforeFieldct(found_animal->id.npc_id, home_info->block_x - 1, + home_info->block_z - 1, home_info->ut_x, home_info->ut_z - 1); + } else { + home_info->block_x = 0xFF; + home_info->block_z = 0xFF; + home_info->ut_x = 0xFF; + home_info->ut_z = 0xFF; + } + + (*now_npc_max)++; + + if ((*now_npc_max) > ANIMAL_NUM_MAX) { + (*now_npc_max) = ANIMAL_NUM_MAX; + } + } + } else { + return_animal_p->npc_id = return_animal->id.npc_id; + return_animal_p->talk_bit = 0b000; + return_animal_p->exist = FALSE; + lbRTC_TimeCopy(&return_animal_p->renew_time, Common_GetPointer(time.rtc_time)); + mNpc_CopyAnimalPersonalID(Save_GetPointer(last_removed_animal_id), &return_animal->id); } - found_animal_idx = mNpc_GetGoodbyAnimalIdx(ignored_idx); - - if (found_animal_idx == -1) { - found_animal_idx = 0; // fallback - } - - found_animal = &animals[found_animal_idx]; - mNpc_SetGoodbyAnimalMail(&l_mnpc_goodby_mail, &found_animal->id); - mNpc_DestroyHouse(&found_animal->home_info); - (*now_npc_max)--; - - if (Save_Get(remove_animal_idx) == found_animal_idx) { - Save_Set(remove_animal_idx, 0xFF); - } - } - else { - found_animal_idx = mNpc_GetFreeAnimalInfo(animals, ANIMAL_NUM_MAX); - - if (found_animal_idx != -1) { - found_animal = &animals[found_animal_idx]; - } - } - - if (found_animal != NULL) { - mNpc_ClearAnimalInfo(found_animal); - mNpc_CopyAnimalInfo(found_animal, return_animal); - mNpc_ResetAnimalRelation(found_animal_idx); - home_info = &found_animal->home_info; - - if ( - mNpc_CheckBuildHouse( - home_info->block_x - 1, home_info->block_z - 1, - home_info->ut_x, home_info->ut_z - 1 - ) == TRUE) { - mNpc_BuildHouseBeforeFieldct( - found_animal->id.npc_id, - home_info->block_x - 1, home_info->block_z - 1, - home_info->ut_x, home_info->ut_z - 1 - ); - } - else { - home_info->block_x = 0xFF; - home_info->block_z = 0xFF; - home_info->ut_x = 0xFF; - home_info->ut_z = 0xFF; - } - - (*now_npc_max)++; - - if ((*now_npc_max) > ANIMAL_NUM_MAX) { - (*now_npc_max) = ANIMAL_NUM_MAX; - } - } + mNpc_ClearAnimalInfo(return_animal); } - else { - return_animal_p->npc_id = return_animal->id.npc_id; - return_animal_p->talk_bit = 0b000; - return_animal_p->exist = FALSE; - lbRTC_TimeCopy(&return_animal_p->renew_time, Common_GetPointer(time.rtc_time)); - mNpc_CopyAnimalPersonalID(Save_GetPointer(last_removed_animal_id), &return_animal->id); - } - - mNpc_ClearAnimalInfo(return_animal); - } } extern void mNpc_AddActor_inBlock(mFM_move_actor_c* move_actor_list, u8 bx, u8 bz) { - mNpc_AddNpc_inBlock(move_actor_list, bx, bz); + mNpc_AddNpc_inBlock(move_actor_list, bx, bz); } static void mNpc_SetNpcNameID(Animal_c* animal, int num) { - int i; - - for (i = 0; i < num; i++) { - if (animal != NULL && ITEM_NAME_GET_TYPE(animal->id.npc_id) == NAME_TYPE_NPC) { - animal->id.name_id = (u8)animal->id.npc_id; - } + int i; - animal++; - } + for (i = 0; i < num; i++) { + if (animal != NULL && ITEM_NAME_GET_TYPE(animal->id.npc_id) == NAME_TYPE_NPC) { + animal->id.name_id = (u8)animal->id.npc_id; + } + + animal++; + } } extern void mNpc_LoadNpcNameString(u8* dst, u8 name_id) { - static u8 dma_area[64] ATTRIBUTE_ALIGN(32); - u32 addr; - u32 ofs; - u32 base_addr; + static u8 dma_area[64] ATTRIBUTE_ALIGN(32); + u32 addr; + u32 ofs; + u32 base_addr; - mem_clear(dma_area, sizeof(dma_area), CHAR_SPACE); - addr = JW_GetAramAddress(RESOURCE_NPC_NAME_STR_TABLE); + mem_clear(dma_area, sizeof(dma_area), CHAR_SPACE); + addr = JW_GetAramAddress(RESOURCE_NPC_NAME_STR_TABLE); - if (name_id < 0xFF && dst != NULL && addr != 0) { - ofs = (name_id) * ANIMAL_NAME_LEN; /* offset into dma table */ - base_addr = ALIGN_PREV(ofs, 32); /* align it to the nearest 32 bytes for DMA */ - - _JW_GetResourceAram(base_addr + addr, dma_area, sizeof(dma_area)); // DMA transfer from ARAM - bcopy(dma_area + (ofs - base_addr), dst, ANIMAL_NAME_LEN); // perform final copy - } + if (name_id < 0xFF && dst != NULL && addr != 0) { + ofs = (name_id)*ANIMAL_NAME_LEN; /* offset into dma table */ + base_addr = ALIGN_PREV(ofs, 32); /* align it to the nearest 32 bytes for DMA */ + + _JW_GetResourceAram(base_addr + addr, dma_area, sizeof(dma_area)); // DMA transfer from ARAM + bcopy(dma_area + (ofs - base_addr), dst, ANIMAL_NAME_LEN); // perform final copy + } } static u8* mNpc_GetNpcWorldNamePTableNo(mActor_name_t npc_id) { - static u8 npc_name[ANIMAL_NAME_LEN]; + static u8 npc_name[ANIMAL_NAME_LEN]; - u8* world_name_p = NULL; + u8* world_name_p = NULL; - if (ITEM_NAME_GET_TYPE(npc_id) == NAME_TYPE_NPC && (u8)(npc_id & 0xFF) < 0xFF) { - mNpc_LoadNpcNameString(npc_name, npc_id & 0xFF); - world_name_p = npc_name; - } + if (ITEM_NAME_GET_TYPE(npc_id) == NAME_TYPE_NPC && (u8)(npc_id & 0xFF) < 0xFF) { + mNpc_LoadNpcNameString(npc_name, npc_id & 0xFF); + world_name_p = npc_name; + } - return world_name_p; + return world_name_p; } extern void mNpc_GetNpcWorldNameTableNo(u8* dst, mActor_name_t npc_id) { - u8* world_name_p = mNpc_GetNpcWorldNamePTableNo(npc_id); + u8* world_name_p = mNpc_GetNpcWorldNamePTableNo(npc_id); - if (world_name_p == NULL) { - world_name_p = l_no_name_npc_name; - } + if (world_name_p == NULL) { + world_name_p = l_no_name_npc_name; + } - mPr_CopyPlayerName(dst, world_name_p); + mPr_CopyPlayerName(dst, world_name_p); } typedef struct npc_name_cache_s { - mActor_name_t npc_id; - u8 name[ANIMAL_NAME_LEN]; - u8 npc_type; // 0? = Special NPC, 1 = Regular NPC + mActor_name_t npc_id; + u8 name[ANIMAL_NAME_LEN]; + u8 npc_type; // 0? = Special NPC, 1 = Regular NPC } mNpc_NameCache_c; static mNpc_NameCache_c l_npc_name_cache; extern void mNpc_ClearCacheName() { - mPr_ClearPlayerName(l_npc_name_cache.name); - l_npc_name_cache.npc_id = RSV_NO; - l_npc_name_cache.npc_type = 0; + mPr_ClearPlayerName(l_npc_name_cache.name); + l_npc_name_cache.npc_id = RSV_NO; + l_npc_name_cache.npc_type = 0; } static int mNpc_GetCacheName(u8* dst, mActor_name_t npc_id, u8 npc_type) { - int res = FALSE; + int res = FALSE; - if (npc_id == l_npc_name_cache.npc_id && dst != NULL && npc_type == l_npc_name_cache.npc_type) { - mPr_CopyPlayerName(dst, l_npc_name_cache.name); - res = TRUE; - } + if (npc_id == l_npc_name_cache.npc_id && dst != NULL && npc_type == l_npc_name_cache.npc_type) { + mPr_CopyPlayerName(dst, l_npc_name_cache.name); + res = TRUE; + } - return res; + return res; } static void mNpc_SetCacheName(u8* name, mActor_name_t npc_id, u8 npc_type) { - mNpc_NameCache_c* name_cache = &l_npc_name_cache; + mNpc_NameCache_c* name_cache = &l_npc_name_cache; - if (name != NULL) { - mPr_CopyPlayerName(name_cache->name, name); - name_cache->npc_id = npc_id; - name_cache->npc_type = npc_type; - } + if (name != NULL) { + mPr_CopyPlayerName(name_cache->name, name); + name_cache->npc_id = npc_id; + name_cache->npc_type = npc_type; + } } extern void mNpc_GetNpcWorldNameAnm(u8* dst, AnmPersonalID_c* anm_id) { - u8 animal_name[ANIMAL_NAME_LEN]; - u8* name = l_no_name_npc_name; + u8 animal_name[ANIMAL_NAME_LEN]; + u8* name = l_no_name_npc_name; - if (anm_id != NULL) { - if (anm_id->npc_id != RSV_NO && mNpc_GetCacheName(animal_name, anm_id->npc_id, mNpc_NAME_TYPE_NPC) != FALSE) { - name = animal_name; + if (anm_id != NULL) { + if (anm_id->npc_id != RSV_NO && mNpc_GetCacheName(animal_name, anm_id->npc_id, mNpc_NAME_TYPE_NPC) != FALSE) { + name = animal_name; + } else if (ITEM_NAME_GET_TYPE(anm_id->npc_id) == NAME_TYPE_NPC) { + mNpc_GetNpcWorldNameTableNo(animal_name, anm_id->npc_id); + name = animal_name; + mNpc_SetCacheName(name, anm_id->npc_id, mNpc_NAME_TYPE_NPC); + } } - else if (ITEM_NAME_GET_TYPE(anm_id->npc_id) == NAME_TYPE_NPC) { - mNpc_GetNpcWorldNameTableNo(animal_name, anm_id->npc_id); - name = animal_name; - mNpc_SetCacheName(name, anm_id->npc_id, mNpc_NAME_TYPE_NPC); - } - } - mPr_CopyPlayerName(dst, name); + mPr_CopyPlayerName(dst, name); } static u8* mNpc_GetActorWorldNameP(mActor_name_t npc_id) { - static u8 load_name[ANIMAL_NAME_LEN]; + static u8 load_name[ANIMAL_NAME_LEN]; - mNpc_Sp_Npc_Name_c* sp_npc_name = l_sp_actor_name; - u8* name_p = NULL; - int i; + mNpc_Sp_Npc_Name_c* sp_npc_name = l_sp_actor_name; + u8* name_p = NULL; + int i; - if (npc_id != RSV_NO && mNpc_GetCacheName(load_name, npc_id, mNpc_NAME_TYPE_NPC) != FALSE) { - name_p = load_name; - } - else if (ITEM_NAME_GET_TYPE(npc_id) == NAME_TYPE_NPC) { - mNpc_GetNpcWorldNameTableNo(load_name, npc_id); - name_p = load_name; - mNpc_SetCacheName(load_name, npc_id, mNpc_NAME_TYPE_NPC); - } - else { - for (i = 0; i < ARRAY_COUNT(l_sp_actor_name); i++) { - if (npc_id == sp_npc_name->sp_npc_id) { - mString_Load_StringFromRom(load_name, ANIMAL_NAME_LEN, sp_npc_name->name_str_no); + if (npc_id != RSV_NO && mNpc_GetCacheName(load_name, npc_id, mNpc_NAME_TYPE_NPC) != FALSE) { + name_p = load_name; + } else if (ITEM_NAME_GET_TYPE(npc_id) == NAME_TYPE_NPC) { + mNpc_GetNpcWorldNameTableNo(load_name, npc_id); name_p = load_name; mNpc_SetCacheName(load_name, npc_id, mNpc_NAME_TYPE_NPC); + } else { + for (i = 0; i < ARRAY_COUNT(l_sp_actor_name); i++) { + if (npc_id == sp_npc_name->sp_npc_id) { + mString_Load_StringFromRom(load_name, ANIMAL_NAME_LEN, sp_npc_name->name_str_no); + name_p = load_name; + mNpc_SetCacheName(load_name, npc_id, mNpc_NAME_TYPE_NPC); - break; - } + break; + } - sp_npc_name++; + sp_npc_name++; + } } - } - return name_p; + return name_p; } extern void mNpc_GetActorWorldName(u8* dst, mActor_name_t npc_id) { - u8* name_p = mNpc_GetActorWorldNameP(npc_id); + u8* name_p = mNpc_GetActorWorldNameP(npc_id); - if (name_p == NULL) { - name_p = l_no_name_npc_name; - } + if (name_p == NULL) { + name_p = l_no_name_npc_name; + } - mPr_CopyPlayerName(dst, name_p); + mPr_CopyPlayerName(dst, name_p); } extern u8* mNpc_GetNpcWorldNameP(mActor_name_t npc_id) { - u8* name_p = mNpc_GetNpcWorldNamePTableNo(npc_id); - - if (name_p == NULL) { - name_p = mNpc_GetActorWorldNameP(npc_id); + u8* name_p = mNpc_GetNpcWorldNamePTableNo(npc_id); if (name_p == NULL) { - name_p = l_no_name_npc_name; - } - } + name_p = mNpc_GetActorWorldNameP(npc_id); - return name_p; + if (name_p == NULL) { + name_p = l_no_name_npc_name; + } + } + + return name_p; } extern void mNpc_GetNpcWorldName(u8* dst, ACTOR* actor) { - u8 npc_name[ANIMAL_NAME_LEN]; - u8* name_p = l_no_name_npc_name; + u8 npc_name[ANIMAL_NAME_LEN]; + u8* name_p = l_no_name_npc_name; - if (dst != NULL && actor != NULL) { - if (actor->part == ACTOR_PART_NPC) { - NPC_ACTOR* npc = (NPC_ACTOR*)actor; - Animal_c* animal = npc->npc_info.animal; + if (dst != NULL && actor != NULL) { + if (actor->part == ACTOR_PART_NPC) { + NPC_ACTOR* npc = (NPC_ACTOR*)actor; + Animal_c* animal = npc->npc_info.animal; - if (animal != NULL) { - mNpc_GetNpcWorldNameAnm(npc_name, &animal->id); - } - else { - mActor_name_t npc_id; - mNpc_EventNpc_c* event_npc; - mNpc_MaskNpc_c* mask_npc; + if (animal != NULL) { + mNpc_GetNpcWorldNameAnm(npc_name, &animal->id); + } else { + mActor_name_t npc_id; + mNpc_EventNpc_c* event_npc; + mNpc_MaskNpc_c* mask_npc; - event_npc = mNpc_GetSameEventNpc(actor->npc_id); + event_npc = mNpc_GetSameEventNpc(actor->npc_id); - if (event_npc != NULL) { - npc_id = event_npc->npc_id; - } - else { - mask_npc = mNpc_GetSameMaskNpc(actor->npc_id); + if (event_npc != NULL) { + npc_id = event_npc->npc_id; + } else { + mask_npc = mNpc_GetSameMaskNpc(actor->npc_id); - if (mask_npc != NULL) { - npc_id = mask_npc->npc_id; - } - else { - npc_id = actor->npc_id; - } - } + if (mask_npc != NULL) { + npc_id = mask_npc->npc_id; + } else { + npc_id = actor->npc_id; + } + } - if (npc_id == SP_NPC_EV_GHOST) { - u8 arg = actor->actor_specific; + if (npc_id == SP_NPC_EV_GHOST) { + u8 arg = actor->actor_specific; - if (mNpc_GetCacheName(npc_name, npc_id, arg) == FALSE) { - if (arg != 1) { - /* Load the ?????? name */ - mString_Load_StringFromRom(npc_name, ANIMAL_NAME_LEN, 0x6D7); - mNpc_SetCacheName(npc_name, npc_id, arg); + if (mNpc_GetCacheName(npc_name, npc_id, arg) == FALSE) { + if (arg != 1) { + /* Load the ?????? name */ + mString_Load_StringFromRom(npc_name, ANIMAL_NAME_LEN, 0x6D7); + mNpc_SetCacheName(npc_name, npc_id, arg); + } else { + mNpc_GetActorWorldName(npc_name, npc_id); + } + } + } else { + mNpc_GetActorWorldName(npc_name, npc_id); + } } - else { - mNpc_GetActorWorldName(npc_name, npc_id); - } - } + } else { + mNpc_GetActorWorldName(npc_name, actor->npc_id); } - else { - mNpc_GetActorWorldName(npc_name, npc_id); - } - } - } - else { - mNpc_GetActorWorldName(npc_name, actor->npc_id); + + name_p = npc_name; } - name_p = npc_name; - } - - mPr_CopyPlayerName(dst, name_p); + mPr_CopyPlayerName(dst, name_p); } extern void mNpc_GetRandomAnimalName(u8* dst) { - Animal_c* animal = Save_Get(animals); - Animal_c* animal_p = animal; - u16 candidate_bitfield = 0; - int candidate_num = 0; - int i; + Animal_c* animal = Save_Get(animals); + Animal_c* animal_p = animal; + u16 candidate_bitfield = 0; + int candidate_num = 0; + int i; - if (dst != NULL) { - for (i = 0; i < ANIMAL_NUM_MAX; i++) { - if (mNpc_CheckFreeAnimalInfo(animal_p) == FALSE) { - candidate_bitfield |= (1 << i); - candidate_num++; - } + if (dst != NULL) { + for (i = 0; i < ANIMAL_NUM_MAX; i++) { + if (mNpc_CheckFreeAnimalInfo(animal_p) == FALSE) { + candidate_bitfield |= (1 << i); + candidate_num++; + } - animal_p++; - } - - if (candidate_num > 0) { - int selected = RANDOM(candidate_num); - - for (i = 0; i < ANIMAL_NUM_MAX; i++) { - if (((candidate_bitfield >> i) & 1) == 1) { - if (selected == 0) { - mNpc_GetNpcWorldNameAnm(dst, &animal->id); - break; - } - else { - selected--; - } + animal_p++; } - animal++; - } + if (candidate_num > 0) { + int selected = RANDOM(candidate_num); + + for (i = 0; i < ANIMAL_NUM_MAX; i++) { + if (((candidate_bitfield >> i) & 1) == 1) { + if (selected == 0) { + mNpc_GetNpcWorldNameAnm(dst, &animal->id); + break; + } else { + selected--; + } + } + + animal++; + } + } } - } } extern void mNpc_GetAnimalPlateName(u8* dst, xyz_t wpos) { - Animal_c* animal = Save_Get(animals); - int bx; - int bz; - int ut_x; - int ut_z; + Animal_c* animal = Save_Get(animals); + int bx; + int bz; + int ut_x; + int ut_z; - if (mFI_Wpos2BkandUtNuminBlock(&bx, &bz, &ut_x, &ut_z, wpos) == TRUE) { - if (mFI_CheckBlockKind_OR(bx, bz, mRF_BLOCKKIND_OCEAN) == TRUE) { - mNpc_GetNpcWorldNameAnm(dst, &Save_Get(island).animal.id); - } - else { - int i; + if (mFI_Wpos2BkandUtNuminBlock(&bx, &bz, &ut_x, &ut_z, wpos) == TRUE) { + if (mFI_CheckBlockKind_OR(bx, bz, mRF_BLOCKKIND_OCEAN) == TRUE) { + mNpc_GetNpcWorldNameAnm(dst, &Save_Get(island).animal.id); + } else { + int i; - ut_x++; - - for (i = 0; i < ANIMAL_NUM_MAX; i++) { - - if (mNpc_CheckFreeAnimalInfo(animal) == FALSE) { - Anmhome_c* home = &animal->home_info; - - if ( - home->block_x == bx && - home->block_z == bz && - home->ut_x == ut_x && - home->ut_z == ut_z - ) { - mNpc_GetNpcWorldNameAnm(dst, &animal->id); - break; - } + ut_x++; + + for (i = 0; i < ANIMAL_NUM_MAX; i++) { + + if (mNpc_CheckFreeAnimalInfo(animal) == FALSE) { + Anmhome_c* home = &animal->home_info; + + if (home->block_x == bx && home->block_z == bz && home->ut_x == ut_x && home->ut_z == ut_z) { + mNpc_GetNpcWorldNameAnm(dst, &animal->id); + break; + } + } + + animal++; + } } - - animal++; - } } - } } extern int mNpc_GetNpcLooks(ACTOR* actor) { - int looks = mNpc_LOOKS_BOY; + int looks = mNpc_LOOKS_BOY; - if (actor != NULL && actor->part == ACTOR_PART_NPC) { - NPC_ACTOR* npc = (NPC_ACTOR*)actor; + if (actor != NULL && actor->part == ACTOR_PART_NPC) { + NPC_ACTOR* npc = (NPC_ACTOR*)actor; - if (npc->npc_info.animal != NULL) { - looks = npc->npc_info.animal->id.looks; + if (npc->npc_info.animal != NULL) { + looks = npc->npc_info.animal->id.looks; + } } - } - return looks; + return looks; } static int mNpc_GetActorSex(mActor_name_t npc_id) { - mNpc_Sp_Npc_Name_c* sp_name_info = l_sp_actor_name; - int sex = mPr_SEX_MALE; - int i; + mNpc_Sp_Npc_Name_c* sp_name_info = l_sp_actor_name; + int sex = mPr_SEX_MALE; + int i; - for (i = 0; i < ARRAY_COUNT(l_sp_actor_name); i++) { - if (npc_id == sp_name_info->sp_npc_id) { - sex = sp_name_info->sex; - break; + for (i = 0; i < ARRAY_COUNT(l_sp_actor_name); i++) { + if (npc_id == sp_name_info->sp_npc_id) { + sex = sp_name_info->sex; + break; + } + + sp_name_info++; } - sp_name_info++; - } - - return sex; + return sex; } extern int mNpc_GetLooks2Sex(int looks) { - int sex = mPr_SEX_OTHER; + int sex = mPr_SEX_OTHER; - if (looks == mNpc_LOOKS_GIRL || looks == mNpc_LOOKS_KO_GIRL || looks == mNpc_LOOKS_NANIWA_LADY) { - sex = mPr_SEX_FEMALE; - } - else if (looks == mNpc_LOOKS_BOY || looks == mNpc_LOOKS_SPORT_MAN || looks == mNpc_LOOKS_GRIM_MAN) { - sex = mPr_SEX_MALE; - } + if (looks == mNpc_LOOKS_GIRL || looks == mNpc_LOOKS_KO_GIRL || looks == mNpc_LOOKS_NANIWA_LADY) { + sex = mPr_SEX_FEMALE; + } else if (looks == mNpc_LOOKS_BOY || looks == mNpc_LOOKS_SPORT_MAN || looks == mNpc_LOOKS_GRIM_MAN) { + sex = mPr_SEX_MALE; + } - return sex; + return sex; } extern int mNpc_GetAnimalSex(Animal_c* animal) { - int sex = mPr_SEX_OTHER; + int sex = mPr_SEX_OTHER; - if (animal != NULL) { - sex = mNpc_GetLooks2Sex(animal->id.looks); - } + if (animal != NULL) { + sex = mNpc_GetLooks2Sex(animal->id.looks); + } - return sex; + return sex; } extern int mNpc_GetNpcSex(ACTOR* actor) { - if (actor != NULL && actor->part == ACTOR_PART_NPC) { - NPC_ACTOR* npc = (NPC_ACTOR*)actor; + if (actor != NULL && actor->part == ACTOR_PART_NPC) { + NPC_ACTOR* npc = (NPC_ACTOR*)actor; - return mNpc_GetAnimalSex(npc->npc_info.animal); - } - + return mNpc_GetAnimalSex(npc->npc_info.animal); + } - return mNpc_GetActorSex(actor->npc_id); + return mNpc_GetActorSex(actor->npc_id); } static int mNpc_GetNpcSoundSpecNotAnimal(mActor_name_t npc_id) { - mNpc_Sp_Npc_Name_c* sp_name_info = l_sp_actor_name; - int sound_spec = 2; - int i; + mNpc_Sp_Npc_Name_c* sp_name_info = l_sp_actor_name; + int sound_spec = 2; + int i; - for (i = 0; i < ARRAY_COUNT(l_sp_actor_name); i++) { - if (npc_id == sp_name_info->sp_npc_id) { - sound_spec = sp_name_info->sound_id; - break; + for (i = 0; i < ARRAY_COUNT(l_sp_actor_name); i++) { + if (npc_id == sp_name_info->sp_npc_id) { + sound_spec = sp_name_info->sound_id; + break; + } + + sp_name_info++; } - sp_name_info++; - } - - return sound_spec; + return sound_spec; } extern int mNpc_GetNpcSoundSpec(ACTOR* actor) { - static int spec_table[mNpc_LOOKS_NUM] = { - 4, - 4, - 2, - 2, - 3, - 4 - }; + static int spec_table[mNpc_LOOKS_NUM] = { 4, 4, 2, 2, 3, 4 }; - int sound_spec = 2; + int sound_spec = 2; - if (actor != NULL) { - if (actor->part == ACTOR_PART_NPC) { - NPC_ACTOR* npc = (NPC_ACTOR*)actor; + if (actor != NULL) { + if (actor->part == ACTOR_PART_NPC) { + NPC_ACTOR* npc = (NPC_ACTOR*)actor; - if (npc->npc_info.animal != NULL) { - int looks = npc->npc_info.animal->id.looks; + if (npc->npc_info.animal != NULL) { + int looks = npc->npc_info.animal->id.looks; - if (looks >= mNpc_LOOKS_NUM) { - looks = mNpc_LOOKS_BOY; + if (looks >= mNpc_LOOKS_NUM) { + looks = mNpc_LOOKS_BOY; + } + + sound_spec = spec_table[looks]; + } else { + sound_spec = mNpc_GetNpcSoundSpecNotAnimal(actor->npc_id); + } + } else { + sound_spec = mNpc_GetNpcSoundSpecNotAnimal(actor->npc_id); } - - sound_spec = spec_table[looks]; - } - else { - sound_spec = mNpc_GetNpcSoundSpecNotAnimal(actor->npc_id); - } } - else { - sound_spec = mNpc_GetNpcSoundSpecNotAnimal(actor->npc_id); - } - } - return sound_spec; + return sound_spec; } static void mNpc_InitRemoveHistory() { - lbRTC_ymd_c* ymd = Save_GetPointer(force_remove_date); + lbRTC_ymd_c* ymd = Save_GetPointer(force_remove_date); - ymd->year = 0xFFFF; - ymd->month = 0xFF; - ymd->day = 0xFF; + ymd->year = 0xFFFF; + ymd->month = 0xFF; + ymd->day = 0xFF; } extern void mNpc_InitNpcAllInfo(int malloc_flag) { - Animal_c* animals = Save_Get(animals); + Animal_c* animals = Save_Get(animals); - Save_Set(now_npc_max, mNpc_LOOKS_NUM); - Save_Set(remove_animal_idx, 0xFF); - mNpc_InitRemoveHistory(); - mNpc_ClearAnimalPersonalID(Save_GetPointer(last_removed_animal_id)); - mNpc_ClearAnyAnimalInfo(animals, ANIMAL_NUM_MAX); - mNpc_DecideLivingNpcMax(animals, mNpc_LOOKS_NUM, malloc_flag); - mNpc_SetNpcNameID(animals, ANIMAL_NUM_MAX); + Save_Set(now_npc_max, mNpc_LOOKS_NUM); + Save_Set(remove_animal_idx, 0xFF); + mNpc_InitRemoveHistory(); + mNpc_ClearAnimalPersonalID(Save_GetPointer(last_removed_animal_id)); + mNpc_ClearAnyAnimalInfo(animals, ANIMAL_NUM_MAX); + mNpc_DecideLivingNpcMax(animals, mNpc_LOOKS_NUM, malloc_flag); + mNpc_SetNpcNameID(animals, ANIMAL_NUM_MAX); } static int mNpc_CheckGrowFieldRank() { - static int npc_grow_prob[mFAs_FIELDRANK_NUM] = { - 40, - 50, - 60, - 70, - 80, - 90, - 100 - }; + static int npc_grow_prob[mFAs_FIELDRANK_NUM] = { 40, 50, 60, 70, 80, 90, 100 }; - int rank = mFAs_GetFieldRank(); - int res = FALSE; + int rank = mFAs_GetFieldRank(); + int res = FALSE; - if (rank >= 0 && rank < mFAs_FIELDRANK_NUM) { - if (RANDOM(100) < npc_grow_prob[rank]) { - res = TRUE; + if (rank >= 0 && rank < mFAs_FIELDRANK_NUM) { + if (RANDOM(100) < npc_grow_prob[rank]) { + res = TRUE; + } } - } - return res; + return res; } static int mNpc_CheckGrow() { - lbRTC_time_c* rtc_time = Common_GetPointer(time.rtc_time); - lbRTC_time_c* last_grow_time = Save_GetPointer(last_grow_time); - int res = FALSE; - - if (Save_Get(now_npc_max) < ANIMAL_NUM_MAX) { - if (lbRTC_IsEqualTime(&mTM_rtcTime_clear_code, last_grow_time, lbRTC_CHECK_ALL) == TRUE) { - lbRTC_TimeCopy(last_grow_time, rtc_time); // first initialization + lbRTC_time_c* rtc_time = Common_GetPointer(time.rtc_time); + lbRTC_time_c* last_grow_time = Save_GetPointer(last_grow_time); + int res = FALSE; + + if (Save_Get(now_npc_max) < ANIMAL_NUM_MAX) { + if (lbRTC_IsEqualTime(&mTM_rtcTime_clear_code, last_grow_time, lbRTC_CHECK_ALL) == TRUE) { + lbRTC_TimeCopy(last_grow_time, rtc_time); // first initialization + } else if (mNpc_CheckGrowFieldRank() == TRUE) { + u32 interval; + + if (lbRTC_IsOverTime(last_grow_time, rtc_time) == lbRTC_OVER) { + interval = lbRTC_IntervalTime(rtc_time, last_grow_time); + } else { + interval = lbRTC_IntervalTime(last_grow_time, rtc_time); + } + + if (interval >= (lbRTC_HOURS_PER_DAY * lbRTC_MINUTES_PER_HOUR) && /* Only one new villager per day */ + mLd_PlayerManKindCheck() == FALSE && /* Player must be from the town being loaded */ + mNpc_CheckFriendAllAnimal(&Common_Get(now_private)->player_ID) == + TRUE /* The player loading must have talked to all current villagers */ + ) { + res = TRUE; + } + } } - else if (mNpc_CheckGrowFieldRank() == TRUE) { - u32 interval; - if (lbRTC_IsOverTime(last_grow_time, rtc_time) == lbRTC_OVER) { - interval = lbRTC_IntervalTime(rtc_time, last_grow_time); - } - else { - interval = lbRTC_IntervalTime(last_grow_time, rtc_time); - } - - if ( - interval >= (lbRTC_HOURS_PER_DAY * lbRTC_MINUTES_PER_HOUR) && /* Only one new villager per day */ - mLd_PlayerManKindCheck() == FALSE && /* Player must be from the town being loaded */ - mNpc_CheckFriendAllAnimal(&Common_Get(now_private)->player_ID) == TRUE /* The player loading must have talked to all current villagers */ - ) { - res = TRUE; - } - } - } - - return res; + return res; } static u8 mNpc_GetMinLooks(u8* min_looks_bitfield, int* min_looks_num) { - int min_looks_animals; - u8 min_looks; - u8 i; - - min_looks_bitfield[0] = 0; - min_looks_num[0] = 0; - min_looks_animals = ANIMAL_NUM_MAX; - min_looks = mNpc_LOOKS_UNSET; + int min_looks_animals; + u8 min_looks; + u8 i; - for (i = 0; i < mNpc_LOOKS_NUM; i++) { - int not_appear_num = mNpc_GetLooks2NotHaveAppearedNum(i); - - if (not_appear_num > 0) { - int same_looks_num = mNpc_GetSameLooksNum(i); - - if (min_looks_animals > same_looks_num) { - min_looks_animals = same_looks_num; - min_looks = i; - min_looks_bitfield[0] = 0; - min_looks_bitfield[0] |= (1 << i); - min_looks_num[0] = 1; - } - else if (min_looks_animals == same_looks_num) { - min_looks_bitfield[0] |= (1 << i); - min_looks_num[0]++; - } - } - } - - if (min_looks_bitfield[0] == 0 && min_looks_num[0] == 0) { - /* All animals have appeared before, so reset the list */ - mNpc_ResetHaveAppeared_common(Save_Get(npc_used_tbl), Save_Get(animals)); + min_looks_bitfield[0] = 0; + min_looks_num[0] = 0; + min_looks_animals = ANIMAL_NUM_MAX; + min_looks = mNpc_LOOKS_UNSET; for (i = 0; i < mNpc_LOOKS_NUM; i++) { - min_looks_bitfield[0] |= (1 << i); - min_looks_num[0]++; + int not_appear_num = mNpc_GetLooks2NotHaveAppearedNum(i); + + if (not_appear_num > 0) { + int same_looks_num = mNpc_GetSameLooksNum(i); + + if (min_looks_animals > same_looks_num) { + min_looks_animals = same_looks_num; + min_looks = i; + min_looks_bitfield[0] = 0; + min_looks_bitfield[0] |= (1 << i); + min_looks_num[0] = 1; + } else if (min_looks_animals == same_looks_num) { + min_looks_bitfield[0] |= (1 << i); + min_looks_num[0]++; + } + } } - } - if (min_looks_num[0] > 1) { - min_looks = mNpc_LOOKS_UNSET; - } + if (min_looks_bitfield[0] == 0 && min_looks_num[0] == 0) { + /* All animals have appeared before, so reset the list */ + mNpc_ResetHaveAppeared_common(Save_Get(npc_used_tbl), Save_Get(animals)); - return min_looks; + for (i = 0; i < mNpc_LOOKS_NUM; i++) { + min_looks_bitfield[0] |= (1 << i); + min_looks_num[0]++; + } + } + + if (min_looks_num[0] > 1) { + min_looks = mNpc_LOOKS_UNSET; + } + + return min_looks; } static int mNpc_GetMinSex() { - Animal_c* animal = Save_Get(animals); - int males = 0; - int females = 0; - int res; - int i; + Animal_c* animal = Save_Get(animals); + int males = 0; + int females = 0; + int res; + int i; - for (i = 0; i < ANIMAL_NUM_MAX; i++) { - if (mNpc_CheckFreeAnimalInfo(animal) == FALSE) { - switch (mNpc_GetAnimalSex(animal)) { - case mPr_SEX_MALE: - males++; - break; - case mPr_SEX_FEMALE: - females++; - break; - } + for (i = 0; i < ANIMAL_NUM_MAX; i++) { + if (mNpc_CheckFreeAnimalInfo(animal) == FALSE) { + switch (mNpc_GetAnimalSex(animal)) { + case mPr_SEX_MALE: + males++; + break; + case mPr_SEX_FEMALE: + females++; + break; + } + } + + animal++; } - animal++; - } + /* TODO: is this bugged? Shouldn't this check be inverted? */ + if (females < males) { + res = mPr_SEX_MALE; + } else { + res = mPr_SEX_FEMALE; + } - /* TODO: is this bugged? Shouldn't this check be inverted? */ - if (females < males) { - res = mPr_SEX_MALE; - } - else { - res = mPr_SEX_FEMALE; - } - - return res; + return res; } static int mNpc_GrowLooksNpcIdx(u8 looks) { - static u8 candidate_table[ALIGN_NEXT(NPC_NUM, 8) / 8]; + static u8 candidate_table[ALIGN_NEXT(NPC_NUM, 8) / 8]; - u8* looks_table = npc_looks_table; - s8* grow_list = npc_grow_list; - int npc_idx; - int candidates; - int res; - int i; - int j; - int selected; - - npc_idx = 0; - candidates = 0; - res = -1; + u8* looks_table = npc_looks_table; + s8* grow_list = npc_grow_list; + int npc_idx; + int candidates; + int res; + int i; + int j; + int selected; - if (looks < mNpc_LOOKS_UNSET) { - bzero(candidate_table, sizeof(candidate_table)); - - for (i = 0; i < ARRAY_COUNT(candidate_table); i++) { - for (j = 0; j < 8; j++) { - if (looks == *looks_table) { - int grow_perm = mNpc_GetDefGrowPermission(npc_idx, grow_list, NPC_NUM); - - if ( - (mNpc_SearchAnimalinfo(Save_Get(animals), npc_idx | NPC_START, ANIMAL_NUM_MAX) == -1) && - (mNpc_GetHaveAppeared_idx(npc_idx) == FALSE) && - (grow_perm == mNpc_GROW_STARTER || grow_perm == mNpc_GROW_MOVE_IN) - ) { - candidates++; - candidate_table[i] |= 1 << j; - } - } - - npc_idx++; - looks_table++; - - if (npc_idx >= NPC_NUM) { - break; - } - } - - if (npc_idx >= NPC_NUM) { - break; - } - } - } - - if (candidates > 0) { - selected = RANDOM(candidates); npc_idx = 0; + candidates = 0; + res = -1; - for (i = 0; i < ARRAY_COUNT(candidate_table); i++) { - if (npc_idx >= NPC_NUM) { - break; - } + if (looks < mNpc_LOOKS_UNSET) { + bzero(candidate_table, sizeof(candidate_table)); - for (j = 0; j < 8; j++) { - if (npc_idx >= NPC_NUM) { - break; + for (i = 0; i < ARRAY_COUNT(candidate_table); i++) { + for (j = 0; j < 8; j++) { + if (looks == *looks_table) { + int grow_perm = mNpc_GetDefGrowPermission(npc_idx, grow_list, NPC_NUM); + + if ((mNpc_SearchAnimalinfo(Save_Get(animals), npc_idx | NPC_START, ANIMAL_NUM_MAX) == -1) && + (mNpc_GetHaveAppeared_idx(npc_idx) == FALSE) && + (grow_perm == mNpc_GROW_STARTER || grow_perm == mNpc_GROW_MOVE_IN)) { + candidates++; + candidate_table[i] |= 1 << j; + } + } + + npc_idx++; + looks_table++; + + if (npc_idx >= NPC_NUM) { + break; + } + } + + if (npc_idx >= NPC_NUM) { + break; + } } - - if (((candidate_table[i] >> j) & 1) == 1) { - if (selected <= 0) { - res = npc_idx; - break; - } - else { - selected--; - } - } - - npc_idx++; - } - - if (res != -1) { - break; - } } - } - return res; + if (candidates > 0) { + selected = RANDOM(candidates); + npc_idx = 0; + + for (i = 0; i < ARRAY_COUNT(candidate_table); i++) { + if (npc_idx >= NPC_NUM) { + break; + } + + for (j = 0; j < 8; j++) { + if (npc_idx >= NPC_NUM) { + break; + } + + if (((candidate_table[i] >> j) & 1) == 1) { + if (selected <= 0) { + res = npc_idx; + break; + } else { + selected--; + } + } + + npc_idx++; + } + + if (res != -1) { + break; + } + } + } + + return res; } static void mNpc_SetAnimalInfoNpcIdx(Animal_c* animal, int idx) { - if (idx >= 0 && idx < NPC_NUM) { - mNpc_SetDefAnimalInfo(animal, NPC_START | idx, npc_looks_table[idx], &npc_def_list[idx]); - } + if (idx >= 0 && idx < NPC_NUM) { + mNpc_SetDefAnimalInfo(animal, NPC_START | idx, npc_looks_table[idx], &npc_def_list[idx]); + } } static int mNpc_SetGrowNpc(u8 looks) { - Animal_c* animal = Save_Get(animals); - int idx = mNpc_UseFreeAnimalInfo(animal, ANIMAL_NUM_MAX); - int npc_idx; + Animal_c* animal = Save_Get(animals); + int idx = mNpc_UseFreeAnimalInfo(animal, ANIMAL_NUM_MAX); + int npc_idx; - if (idx != -1) { - animal += idx; - npc_idx = mNpc_GrowLooksNpcIdx(looks); + if (idx != -1) { + animal += idx; + npc_idx = mNpc_GrowLooksNpcIdx(looks); - if (npc_idx != -1) { - mNpc_SetAnimalInfoNpcIdx(animal, npc_idx); - mNpc_SetHaveAppeared(animal->id.npc_id); - animal->moved_in = TRUE; + if (npc_idx != -1) { + mNpc_SetAnimalInfoNpcIdx(animal, npc_idx); + mNpc_SetHaveAppeared(animal->id.npc_id); + animal->moved_in = TRUE; + } else { + idx = -1; + } } - else { - idx = -1; - } - } - return idx; + return idx; } extern void mNpc_Grow() { - int selected; - int grow_idx; + int selected; + int grow_idx; - if (mNpc_CheckGrow() == TRUE) { - lbRTC_time_c* rtc_time = Common_GetPointer(time.rtc_time); - lbRTC_time_c* last_grow_time = Save_GetPointer(last_grow_time); - u8 min_looks_bitfield; - int min_looks_num; - u8 min_looks; - u8 selected_looks; + if (mNpc_CheckGrow() == TRUE) { + lbRTC_time_c* rtc_time = Common_GetPointer(time.rtc_time); + lbRTC_time_c* last_grow_time = Save_GetPointer(last_grow_time); + u8 min_looks_bitfield; + int min_looks_num; + u8 min_looks; + u8 selected_looks; - mNpc_ResetHaveAppeared(); - lbRTC_TimeCopy(last_grow_time, rtc_time); + mNpc_ResetHaveAppeared(); + lbRTC_TimeCopy(last_grow_time, rtc_time); - min_looks = mNpc_GetMinLooks(&min_looks_bitfield, &min_looks_num); - selected_looks = min_looks; + min_looks = mNpc_GetMinLooks(&min_looks_bitfield, &min_looks_num); + selected_looks = min_looks; - /* Multiple personalities are tied for minimum */ - if (min_looks == mNpc_LOOKS_UNSET) { - int min_sex = mNpc_GetMinSex(); - u8 min_looks_bitfield_save; - int min_looks_num_save; - u8 looks; + /* Multiple personalities are tied for minimum */ + if (min_looks == mNpc_LOOKS_UNSET) { + int min_sex = mNpc_GetMinSex(); + u8 min_looks_bitfield_save; + int min_looks_num_save; + u8 looks; - if (min_sex != mPr_SEX_OTHER) { - min_looks_bitfield_save = min_looks_bitfield; - min_looks_num_save = min_looks_num; - - /* Clear any tied minimum personalities which are of the greater sex */ - for (looks = 0; looks < mNpc_LOOKS_NUM; looks++) { - if (((min_looks_bitfield >> looks) & 1) == 1 && mNpc_GetLooks2Sex(looks) != min_sex) { - min_looks_bitfield &= ~(1 << looks); - min_looks_num--; - } + if (min_sex != mPr_SEX_OTHER) { + min_looks_bitfield_save = min_looks_bitfield; + min_looks_num_save = min_looks_num; + + /* Clear any tied minimum personalities which are of the greater sex */ + for (looks = 0; looks < mNpc_LOOKS_NUM; looks++) { + if (((min_looks_bitfield >> looks) & 1) == 1 && mNpc_GetLooks2Sex(looks) != min_sex) { + min_looks_bitfield &= ~(1 << looks); + min_looks_num--; + } + } + + if (min_looks_num == 0 || min_looks_num == min_looks_num_save) { + /* Either all personalities were cleared or none were, so restore the prior state */ + min_looks_bitfield = min_looks_bitfield_save; + min_looks_num = min_looks_num_save; + } + } + + selected = RANDOM(min_looks_num); + + for (looks = 0; looks < mNpc_LOOKS_NUM; looks++) { + if (((min_looks_bitfield >> looks) & 1) == 1) { + if (selected <= 0) { + selected_looks = looks; + break; + } else { + selected--; + } + } + } } - if (min_looks_num == 0 || min_looks_num == min_looks_num_save) { - /* Either all personalities were cleared or none were, so restore the prior state */ - min_looks_bitfield = min_looks_bitfield_save; - min_looks_num = min_looks_num_save; - } - } + grow_idx = mNpc_SetGrowNpc(selected_looks); - selected = RANDOM(min_looks_num); - - for (looks = 0; looks < mNpc_LOOKS_NUM; looks++) { - if (((min_looks_bitfield >> looks) & 1) == 1) { - if (selected <= 0) { - selected_looks = looks; - break; - } - else { - selected--; - } + if (grow_idx >= 0 && grow_idx < ANIMAL_NUM_MAX) { + mNpc_SetNpcNameID(Save_GetPointer(animals[grow_idx]), 1); + mNpc_AddNowNpcMax(Save_GetPointer(now_npc_max)); + mNpc_RenewRemoveHistory(); } - } } - - grow_idx = mNpc_SetGrowNpc(selected_looks); - - if (grow_idx >= 0 && grow_idx < ANIMAL_NUM_MAX) { - mNpc_SetNpcNameID(Save_GetPointer(animals[grow_idx]), 1); - mNpc_AddNowNpcMax(Save_GetPointer(now_npc_max)); - mNpc_RenewRemoveHistory(); - } - } } extern void mNpc_ForceRemove() { - lbRTC_time_c force_remove_time; - lbRTC_time_c* rtc_time = Common_GetPointer(time.rtc_time); - lbRTC_ymd_c* force_remove_date = Save_GetPointer(force_remove_date); - Animal_c* animal = Save_Get(animals); - int interval; - int animal_num = mNpc_GetAnimalNum(); - int ignored_idx = -1; - int idx; + lbRTC_time_c force_remove_time; + lbRTC_time_c* rtc_time = Common_GetPointer(time.rtc_time); + lbRTC_ymd_c* force_remove_date = Save_GetPointer(force_remove_date); + Animal_c* animal = Save_Get(animals); + int interval; + int animal_num = mNpc_GetAnimalNum(); + int ignored_idx = -1; + int idx; - if ( - animal_num == ANIMAL_NUM_MAX && - force_remove_date->year != 0xFFFF && - force_remove_date->month != 0xFF && - force_remove_date->day != 0xFF - ) { - mTM_ymd_2_time(&force_remove_time, force_remove_date); - - if (lbRTC_IsOverTime(&force_remove_time, rtc_time) == lbRTC_OVER) { - interval = lbRTC_GetIntervalDays(&force_remove_time, rtc_time); - } - else { - interval = lbRTC_GetIntervalDays(rtc_time, &force_remove_time); - } + if (animal_num == ANIMAL_NUM_MAX && force_remove_date->year != 0xFFFF && force_remove_date->month != 0xFF && + force_remove_date->day != 0xFF) { + mTM_ymd_2_time(&force_remove_time, force_remove_date); - - if (interval >= mNpc_MINIMUM_DAYS_BEFORE_FORCE_REMOVAL) { - if (Save_Get(scene_no) == SCENE_PLAYERSELECT_2) { - ignored_idx = Common_Get(player_select_animal_no); - } - - idx = mNpc_GetGoodbyAnimalIdx(ignored_idx); - - if (idx != -1) { - animal += idx; - - if (mNpc_CheckFreeAnimalInfo(animal) == FALSE) { - mNpc_DestroyHouse(&animal->home_info); - mNpc_SetGoodbyAnimalMail(&l_mnpc_goodby_mail, &animal->id); - mNpc_SendRegisteredGoodbyMail(); - mNpc_ClearAnimalInfo(animal); - mNpc_SubNowNpcMax(Save_GetPointer(now_npc_max)); - mNpc_RenewRemoveHistory(); + if (lbRTC_IsOverTime(&force_remove_time, rtc_time) == lbRTC_OVER) { + interval = lbRTC_GetIntervalDays(&force_remove_time, rtc_time); + } else { + interval = lbRTC_GetIntervalDays(rtc_time, &force_remove_time); + } + + if (interval >= mNpc_MINIMUM_DAYS_BEFORE_FORCE_REMOVAL) { + if (Save_Get(scene_no) == SCENE_PLAYERSELECT_2) { + ignored_idx = Common_Get(player_select_animal_no); + } + + idx = mNpc_GetGoodbyAnimalIdx(ignored_idx); + + if (idx != -1) { + animal += idx; + + if (mNpc_CheckFreeAnimalInfo(animal) == FALSE) { + mNpc_DestroyHouse(&animal->home_info); + mNpc_SetGoodbyAnimalMail(&l_mnpc_goodby_mail, &animal->id); + mNpc_SendRegisteredGoodbyMail(); + mNpc_ClearAnimalInfo(animal); + mNpc_SubNowNpcMax(Save_GetPointer(now_npc_max)); + mNpc_RenewRemoveHistory(); + } + } } - } } - } } extern int mNpc_DecideMaskNpc_summercamp(mActor_name_t* npc_id) { - static int looks_table[mNpc_LOOKS_NUM]; + static int looks_table[mNpc_LOOKS_NUM]; - u8 looks; - int i; - int res = FALSE; + u8 looks; + int i; + int res = FALSE; - if (npc_id != NULL) { - npc_id[0] = EMPTY_NO; - mNpc_ResetHaveAppeared(); - mNpc_MakeRandTable(looks_table, mNpc_LOOKS_NUM, NPC_NUM); // why are we swapping this 'NPC_NUM' times??? + if (npc_id != NULL) { + npc_id[0] = EMPTY_NO; + mNpc_ResetHaveAppeared(); + mNpc_MakeRandTable(looks_table, mNpc_LOOKS_NUM, NPC_NUM); // why are we swapping this 'NPC_NUM' times??? - for (i = 0; i < mNpc_LOOKS_NUM; i++) { - looks = looks_table[i]; + for (i = 0; i < mNpc_LOOKS_NUM; i++) { + looks = looks_table[i]; - if (mNpc_GetLooks2NotHaveAppearedNum(looks) > 0) { - int idx = mNpc_GrowLooksNpcIdx(looks); + if (mNpc_GetLooks2NotHaveAppearedNum(looks) > 0) { + int idx = mNpc_GrowLooksNpcIdx(looks); - if (idx != -1) { - npc_id[0] = NPC_START | idx; - /* This makes summer campers impossible to appear by 'natural growth' in your town - unless you've seen every non-islander in your town as a villager or summer camper... */ - mNpc_SetHaveAppeared(npc_id[0]); - res = TRUE; + if (idx != -1) { + npc_id[0] = NPC_START | idx; + /* This makes summer campers impossible to appear by 'natural growth' in your town + unless you've seen every non-islander in your town as a villager or summer camper... */ + mNpc_SetHaveAppeared(npc_id[0]); + res = TRUE; - break; + break; + } + } } - } } - } - return res; + return res; } extern int mNpc_RegistMaskNpc_summercamp(mActor_name_t mask_id, mActor_name_t npc_id, mActor_name_t cloth_id) { - int free_mask_idx = mNpc_GetFreeMaskNpcIdx(); - int res = FALSE; + int free_mask_idx = mNpc_GetFreeMaskNpcIdx(); + int res = FALSE; - if (free_mask_idx != -1) { - mNpc_MaskNpc_c* mask_npc = Common_GetPointer(mask_npc[free_mask_idx]); + if (free_mask_idx != -1) { + mNpc_MaskNpc_c* mask_npc = Common_GetPointer(mask_npc[free_mask_idx]); - if (cloth_id != EMPTY_NO) { - int valid_cloth = (cloth_id == RSV_CLOTH) || (cloth_id >= ITM_CLOTH_START && cloth_id < ITM_CLOTH_END); + if (cloth_id != EMPTY_NO) { + int valid_cloth = (cloth_id == RSV_CLOTH) || (cloth_id >= ITM_CLOTH_START && cloth_id < ITM_CLOTH_END); - if (valid_cloth == FALSE) { - cloth_id = ITM_CLOTH_START; - } + if (valid_cloth == FALSE) { + cloth_id = ITM_CLOTH_START; + } + } + + if (ITEM_NAME_GET_TYPE(npc_id) == NAME_TYPE_NPC) { + mask_npc->mask_id = mask_id; + mask_npc->npc_id = npc_id; + mask_npc->exists = FALSE; + mask_npc->in_use = TRUE; + mNpc_ClearAnimalInfo(&mask_npc->animal_data); + mNpc_SetDefAnimal(&mask_npc->animal_data, npc_id, npc_def_list); + + if (cloth_id == EMPTY_NO) { + mask_npc->cloth_id = mask_npc->animal_data.cloth; + } else { + mask_npc->cloth_id = cloth_id; + } + + if (Common_Get(npc_is_summercamper) == TRUE) { + mNpc_ClearAnimalMemory(mask_npc->animal_data.memories, 1); + mNpc_SetAnimalMemory(&Common_Get(now_private)->player_ID, &mask_npc->animal_data.id, + &mask_npc->animal_data.memories[0]); + } + + res = TRUE; + } } - if (ITEM_NAME_GET_TYPE(npc_id) == NAME_TYPE_NPC) { - mask_npc->mask_id = mask_id; - mask_npc->npc_id = npc_id; - mask_npc->exists = FALSE; - mask_npc->in_use = TRUE; - mNpc_ClearAnimalInfo(&mask_npc->animal_data); - mNpc_SetDefAnimal(&mask_npc->animal_data, npc_id, npc_def_list); - - if (cloth_id == EMPTY_NO) { - mask_npc->cloth_id = mask_npc->animal_data.cloth; - } - else { - mask_npc->cloth_id = cloth_id; - } - - if (Common_Get(npc_is_summercamper) == TRUE) { - mNpc_ClearAnimalMemory(mask_npc->animal_data.memories, 1); - mNpc_SetAnimalMemory(&Common_Get(now_private)->player_ID, &mask_npc->animal_data.id, &mask_npc->animal_data.memories[0]); - } - - res = TRUE; - } - } - - return res; + return res; } extern int mNpc_CheckNpcSet_fgcol(mActor_name_t fg_item, u32 attribute) { - int res = FALSE; + int res = FALSE; - if (mFI_CheckFGNpcOn(fg_item)) { - res = mCoBG_Attr2CheckPlaceNpc(attribute); - } + if (mFI_CheckFGNpcOn(fg_item)) { + res = mCoBG_Attr2CheckPlaceNpc(attribute); + } - return res; + return res; } static int mNpc_CheckNpcSet_fgcol_hard(mActor_name_t fg_item, u32 attribute) { - int res = FALSE; + int res = FALSE; - if (mFI_CheckFGNpcOn(fg_item) && (attribute <= mCoBG_ATTRIBUTE_GRASS2 || (attribute >= mCoBG_ATTRIBUTE_SOIL0 && attribute <= mCoBG_ATTRIBUTE_SOIL2) || attribute == mCoBG_ATTRIBUTE_STONE)) { - res = TRUE; - } + if (mFI_CheckFGNpcOn(fg_item) && (attribute <= mCoBG_ATTRIBUTE_GRASS2 || + (attribute >= mCoBG_ATTRIBUTE_SOIL0 && attribute <= mCoBG_ATTRIBUTE_SOIL2) || + attribute == mCoBG_ATTRIBUTE_STONE)) { + res = TRUE; + } - return res; + return res; } extern int mNpc_CheckNpcSet(int bx, int bz, int ut_x, int ut_z) { - mCoBG_Collision_u* collision = mFI_GetBkNum2ColTop(bx, bz); - mActor_name_t* items = mFI_BkNumtoUtFGTop(bx, bz); - int res = FALSE; + mCoBG_Collision_u* collision = mFI_GetBkNum2ColTop(bx, bz); + mActor_name_t* items = mFI_BkNumtoUtFGTop(bx, bz); + int res = FALSE; - if (collision != NULL && items != NULL) { - res = mNpc_CheckNpcSet_fgcol(items[ut_z * UT_X_NUM + ut_x], collision[ut_z * UT_X_NUM + ut_x].data.unit_attribute); - } + if (collision != NULL && items != NULL) { + res = mNpc_CheckNpcSet_fgcol(items[ut_z * UT_X_NUM + ut_x], + collision[ut_z * UT_X_NUM + ut_x].data.unit_attribute); + } - return res; + return res; } extern int mNpc_GetMakeUtNuminBlock_hard_area(int* ut_x, int* ut_z, int bx, int bz, int restrict_area) { - int now_ut_x; - int now_ut_z; - mCoBG_Collision_u* col; - mCoBG_Collision_u* col_p; - mActor_name_t* items; - int min_ut_x; - int min_ut_z; - int res; - u32 center; - int i; - int j; + int now_ut_x; + int now_ut_z; + mCoBG_Collision_u* col; + mCoBG_Collision_u* col_p; + mActor_name_t* items; + int min_ut_x; + int min_ut_z; + int res; + u32 center; + int i; + int j; - col = mFI_GetBkNum2ColTop(bx, bz); - items = mFI_BkNumtoUtFGTop(bx, bz); - min_ut_x = UT_X_NUM; - min_ut_z = UT_Z_NUM; - res = FALSE; + col = mFI_GetBkNum2ColTop(bx, bz); + items = mFI_BkNumtoUtFGTop(bx, bz); + min_ut_x = UT_X_NUM; + min_ut_z = UT_Z_NUM; + res = FALSE; - if (restrict_area < 0 || restrict_area > 9) { - return FALSE; - } - - if (items != NULL && col != NULL) { - for (i = restrict_area; i < UT_Z_NUM - restrict_area; i++) { - for (j = restrict_area; j < UT_X_NUM - restrict_area; j++) { - col_p = &col[i * UT_X_NUM + j]; - - if (mNpc_CheckNpcSet_fgcol_hard(items[i * UT_X_NUM + j], col_p->data.unit_attribute) == TRUE) { - center = col_p->data.center; - - /* Check that the height of each point on the unit is equal*/ - if ( - (int)center == col_p->data.top_left && - center == col_p->data.bot_left && - center == col_p->data.top_right && - (int)center == col_p->data.bot_right - ) { - - now_ut_x = 8 - j; - now_ut_z = 8 - i; - - now_ut_x = ABS(now_ut_x); - now_ut_z = ABS(now_ut_z); - - if (min_ut_x > now_ut_x && min_ut_z > now_ut_z) { - *ut_x = j; - *ut_z = i; - min_ut_x = now_ut_x; - min_ut_z = now_ut_z; - res = TRUE; - } - } - } - } + if (restrict_area < 0 || restrict_area > 9) { + return FALSE; } - } - return res; + if (items != NULL && col != NULL) { + for (i = restrict_area; i < UT_Z_NUM - restrict_area; i++) { + for (j = restrict_area; j < UT_X_NUM - restrict_area; j++) { + col_p = &col[i * UT_X_NUM + j]; + + if (mNpc_CheckNpcSet_fgcol_hard(items[i * UT_X_NUM + j], col_p->data.unit_attribute) == TRUE) { + center = col_p->data.center; + + /* Check that the height of each point on the unit is equal*/ + if ((int)center == col_p->data.top_left && center == col_p->data.bot_left && + center == col_p->data.top_right && (int)center == col_p->data.bot_right) { + + now_ut_x = 8 - j; + now_ut_z = 8 - i; + + now_ut_x = ABS(now_ut_x); + now_ut_z = ABS(now_ut_z); + + if (min_ut_x > now_ut_x && min_ut_z > now_ut_z) { + *ut_x = j; + *ut_z = i; + min_ut_x = now_ut_x; + min_ut_z = now_ut_z; + res = TRUE; + } + } + } + } + } + } + + return res; } extern int mNpc_GetMakeUtNuminBlock_area(int* ut_x, int* ut_z, int bx, int bz, int restrict_area) { - static u16 fg_flag[UT_Z_NUM]; + static u16 fg_flag[UT_Z_NUM]; - mCoBG_Collision_u* col_top; - mActor_name_t* fg_top; - u16* fg_flag_p = fg_flag; - int candidates; - int res; - int i; - int j; - int rand; + mCoBG_Collision_u* col_top; + mActor_name_t* fg_top; + u16* fg_flag_p = fg_flag; + int candidates; + int res; + int i; + int j; + int rand; - col_top = mFI_GetBkNum2ColTop(bx, bz); - fg_top = mFI_BkNumtoUtFGTop(bx, bz); - candidates = 0; - res = FALSE; + col_top = mFI_GetBkNum2ColTop(bx, bz); + fg_top = mFI_BkNumtoUtFGTop(bx, bz); + candidates = 0; + res = FALSE; - if (restrict_area < 0 || restrict_area > 9) { - return FALSE; - } - - bzero(fg_flag, sizeof(fg_flag)); - - if (fg_top != NULL && col_top != NULL) { - for (i = restrict_area; i < UT_Z_NUM - restrict_area; i++) { - for (j = restrict_area; j < UT_X_NUM - restrict_area; j++) { - if (mNpc_CheckNpcSet_fgcol(fg_top[i * UT_X_NUM + j], col_top[i * UT_X_NUM + j].data.unit_attribute) == TRUE) { - *fg_flag_p |= 1 << j; - candidates++; - } - } - - fg_flag_p++; + if (restrict_area < 0 || restrict_area > 9) { + return FALSE; } - } - fg_flag_p = fg_flag; - if (candidates > 0) { - rand = RANDOM(candidates); + bzero(fg_flag, sizeof(fg_flag)); - for (i = restrict_area; i < UT_Z_NUM - restrict_area; i++) { - for (j = restrict_area; j < UT_X_NUM - restrict_area; j++) { - if (((*fg_flag_p >> j) & 1) == 1) { - if (rand == 0) { - *ut_x = j; - *ut_z = i; - res = TRUE; + if (fg_top != NULL && col_top != NULL) { + for (i = restrict_area; i < UT_Z_NUM - restrict_area; i++) { + for (j = restrict_area; j < UT_X_NUM - restrict_area; j++) { + if (mNpc_CheckNpcSet_fgcol(fg_top[i * UT_X_NUM + j], col_top[i * UT_X_NUM + j].data.unit_attribute) == + TRUE) { + *fg_flag_p |= 1 << j; + candidates++; + } + } - break; - } - else { - rand--; - } + fg_flag_p++; } - } - - if (res == TRUE) { - break; - } - - fg_flag_p++; } - } - return res; + fg_flag_p = fg_flag; + if (candidates > 0) { + rand = RANDOM(candidates); + + for (i = restrict_area; i < UT_Z_NUM - restrict_area; i++) { + for (j = restrict_area; j < UT_X_NUM - restrict_area; j++) { + if (((*fg_flag_p >> j) & 1) == 1) { + if (rand == 0) { + *ut_x = j; + *ut_z = i; + res = TRUE; + + break; + } else { + rand--; + } + } + } + + if (res == TRUE) { + break; + } + + fg_flag_p++; + } + } + + return res; } extern int mNpc_GetMakeUtNuminBlock(int* ut_x, int* ut_z, int bx, int bz) { - return mNpc_GetMakeUtNuminBlock_area(ut_x, ut_z, bx, bz, 1); // can't spawn in the outer-most square of units + return mNpc_GetMakeUtNuminBlock_area(ut_x, ut_z, bx, bz, 1); // can't spawn in the outer-most square of units } static int mNpc_CheckNpcSet_height(int bx, int bz, int ut_x, int ut_z, mActor_name_t item, mCoBG_Collision_u* col) { - int res = FALSE; + int res = FALSE; - if (col != NULL && mNpc_CheckNpcSet_fgcol(item, col->data.unit_attribute)) { - xyz_t wpos; + if (col != NULL && mNpc_CheckNpcSet_fgcol(item, col->data.unit_attribute)) { + xyz_t wpos; - mFI_BkandUtNum2Wpos(&wpos, bx, bz, ut_x, ut_z); + mFI_BkandUtNum2Wpos(&wpos, bx, bz, ut_x, ut_z); - if (mCoBG_ExistHeightGap_KeepAndNow(wpos) == FALSE) { - res = TRUE; + if (mCoBG_ExistHeightGap_KeepAndNow(wpos) == FALSE) { + res = TRUE; + } } - } - return res; + return res; } extern int mNpc_GetMakeUtNuminBlock33(int* make_ut_x, int* make_ut_z, int ut_x, int ut_z, int bx, int bz) { - static int ut_xnum_table[9] = { 0, 1, -1, 0, 1, -1, 0, 1, -1 }; - static int ut_znum_table[9] = { 0, 0, 0, 1, 1, 1, -1, -1, -1 }; + static int ut_xnum_table[9] = { 0, 1, -1, 0, 1, -1, 0, 1, -1 }; + static int ut_znum_table[9] = { 0, 0, 0, 1, 1, 1, -1, -1, -1 }; - mCoBG_Collision_u* col_top; - mActor_name_t* fg_top; - int res; - int x; - int z; - int idx; - int i; + mCoBG_Collision_u* col_top; + mActor_name_t* fg_top; + int res; + int x; + int z; + int idx; + int i; - col_top = mFI_GetBkNum2ColTop(bx, bz); - fg_top = mFI_BkNumtoUtFGTop(bx, bz); - res = FALSE; + col_top = mFI_GetBkNum2ColTop(bx, bz); + fg_top = mFI_BkNumtoUtFGTop(bx, bz); + res = FALSE; - if (col_top != NULL && fg_top != NULL) { - for (i = 0; i < 9; i++) { - x = ut_x + ut_xnum_table[i]; - z = ut_z + ut_znum_table[i]; + if (col_top != NULL && fg_top != NULL) { + for (i = 0; i < 9; i++) { + x = ut_x + ut_xnum_table[i]; + z = ut_z + ut_znum_table[i]; - if (x >= 1 && x < (UT_X_NUM - 1) && z >= 1 && z < (UT_Z_NUM - 1)) { - idx = z * UT_X_NUM + x; - - if (mNpc_CheckNpcSet_height(bx, bz, x, z, fg_top[idx], &col_top[idx]) == TRUE) { - make_ut_x[0] = x; - make_ut_z[0] = z; - res = TRUE; + if (x >= 1 && x < (UT_X_NUM - 1) && z >= 1 && z < (UT_Z_NUM - 1)) { + idx = z * UT_X_NUM + x; - break; + if (mNpc_CheckNpcSet_height(bx, bz, x, z, fg_top[idx], &col_top[idx]) == TRUE) { + make_ut_x[0] = x; + make_ut_z[0] = z; + res = TRUE; + + break; + } + } } - } } - } - return res; + return res; } extern int mNpc_GetMakeUtNuminBlock_hide_hard_area(int* ut_x, int* ut_z, int bx, int bz, int restrict_area) { - static u16 hide_ut_bit[UT_Z_NUM]; + static u16 hide_ut_bit[UT_Z_NUM]; - int now_ut_z; - int now_ut_x; - mCoBG_Collision_u* col_top; - mCoBG_Collision_u* col_p; - mActor_name_t* fg_top; - mActor_name_t* item_p; - u32 center; - int min_ut_x; - int min_ut_z; - int res; - int i; - int j; + int now_ut_z; + int now_ut_x; + mCoBG_Collision_u* col_top; + mCoBG_Collision_u* col_p; + mActor_name_t* fg_top; + mActor_name_t* item_p; + u32 center; + int min_ut_x; + int min_ut_z; + int res; + int i; + int j; - col_top = mFI_GetBkNum2ColTop(bx, bz); - fg_top = mFI_BkNumtoUtFGTop(bx, bz); - min_ut_x = UT_X_NUM; - min_ut_z = UT_Z_NUM; - res = FALSE; + col_top = mFI_GetBkNum2ColTop(bx, bz); + fg_top = mFI_BkNumtoUtFGTop(bx, bz); + min_ut_x = UT_X_NUM; + min_ut_z = UT_Z_NUM; + res = FALSE; - if (restrict_area < 0 || restrict_area > 9) { - return FALSE; - } - - if (fg_top != NULL && col_top != NULL) { - bzero(hide_ut_bit, sizeof(hide_ut_bit)); - mAGrw_SetHideUtInfo(hide_ut_bit, fg_top); - - for (i = restrict_area; i < UT_Z_NUM - restrict_area; i++) { - for (j = restrict_area; j < UT_X_NUM - restrict_area; j++) { - item_p = &fg_top[i * UT_X_NUM + j]; - col_p = &col_top[i * UT_X_NUM + j]; - - if (mNpc_CheckNpcSet_fgcol_hard(item_p[0], col_p->data.unit_attribute) == TRUE) { - center = col_p->data.center; - - /* Check that the height of each point on the unit is equal*/ - if ( - (int)center == col_p->data.top_left && - center == col_p->data.bot_left && - center == col_p->data.top_right && - (int)center == col_p->data.bot_right && - ((hide_ut_bit[i] >> j) & 1) == 1 - ) { - - now_ut_x = 8 - j; - now_ut_z = 8 - i; - - now_ut_x = ABS(now_ut_x); - now_ut_z = ABS(now_ut_z); - - if (min_ut_x > now_ut_x && min_ut_z > now_ut_z) { - *ut_x = j; - *ut_z = i; - min_ut_x = now_ut_x; - min_ut_z = now_ut_z; - res = TRUE; - } - } - } - } + if (restrict_area < 0 || restrict_area > 9) { + return FALSE; } - } - return res; + if (fg_top != NULL && col_top != NULL) { + bzero(hide_ut_bit, sizeof(hide_ut_bit)); + mAGrw_SetHideUtInfo(hide_ut_bit, fg_top); + + for (i = restrict_area; i < UT_Z_NUM - restrict_area; i++) { + for (j = restrict_area; j < UT_X_NUM - restrict_area; j++) { + item_p = &fg_top[i * UT_X_NUM + j]; + col_p = &col_top[i * UT_X_NUM + j]; + + if (mNpc_CheckNpcSet_fgcol_hard(item_p[0], col_p->data.unit_attribute) == TRUE) { + center = col_p->data.center; + + /* Check that the height of each point on the unit is equal*/ + if ((int)center == col_p->data.top_left && center == col_p->data.bot_left && + center == col_p->data.top_right && (int)center == col_p->data.bot_right && + ((hide_ut_bit[i] >> j) & 1) == 1) { + + now_ut_x = 8 - j; + now_ut_z = 8 - i; + + now_ut_x = ABS(now_ut_x); + now_ut_z = ABS(now_ut_z); + + if (min_ut_x > now_ut_x && min_ut_z > now_ut_z) { + *ut_x = j; + *ut_z = i; + min_ut_x = now_ut_x; + min_ut_z = now_ut_z; + res = TRUE; + } + } + } + } + } + } + + return res; } typedef struct npc_temper_s { - u16 unlock_timer; - u8 over_impatient_num; - u8 talk_num_max; + u16 unlock_timer; + u8 over_impatient_num; + u8 talk_num_max; } mNpc_Temper_c; typedef struct npc_talk_info_s { - u16 timer; - u8 talk_num; - u8 quest_request; - u16 unlock_timer; - u16 reset_timer; + u16 timer; + u8 talk_num; + u8 quest_request; + u16 unlock_timer; + u16 reset_timer; } mNpc_Talk_Info_c; static mNpc_Talk_Info_c l_npc_talk_info[ANIMAL_NUM_MAX + mISL_ISLANDER_NUM]; static mNpc_Temper_c l_npc_temper[mNpc_FEEL_NUM] = { - { 4000, 12, 15 }, // mNpc_FEEL_NORMAL - { 3000, 10, 13 }, // mNpc_FEEL_HAPPY - { 4000, 12, 15 }, // mNpc_FEEL_ANGRY - { 4000, 10, 13 }, // mNpc_FEEL_SAD - { 5000, 9, 12 }, // mNpc_FEEL_SLEEPY - { 5000, 9, 12 } // mNpc_FEEL_PITFALL + { 4000, 12, 15 }, // mNpc_FEEL_NORMAL + { 3000, 10, 13 }, // mNpc_FEEL_HAPPY + { 4000, 12, 15 }, // mNpc_FEEL_ANGRY + { 4000, 10, 13 }, // mNpc_FEEL_SAD + { 5000, 9, 12 }, // mNpc_FEEL_SLEEPY + { 5000, 9, 12 } // mNpc_FEEL_PITFALL }; extern void mNpc_ClearTalkInfo() { - mNpc_Talk_Info_c* talk_info_p = l_npc_talk_info; - int i; + mNpc_Talk_Info_c* talk_info_p = l_npc_talk_info; + int i; - bzero(talk_info_p, sizeof(l_npc_talk_info)); + bzero(talk_info_p, sizeof(l_npc_talk_info)); - for (i = 0; i < ARRAY_COUNT(l_npc_talk_info); i++) { - talk_info_p->quest_request = TRUE; - talk_info_p++; - } + for (i = 0; i < ARRAY_COUNT(l_npc_talk_info); i++) { + talk_info_p->quest_request = TRUE; + talk_info_p++; + } } static void mNpc_TimerCountDown(mNpc_Talk_Info_c* talk_info) { - if (talk_info->timer > 0) { - talk_info->timer--; - } + if (talk_info->timer > 0) { + talk_info->timer--; + } } static void mNpc_SetUnlockTimer(u16* unlock_timer, u16* reset_timer, int looks) { - unlock_timer[0] = l_npc_temper[looks].unlock_timer; - reset_timer[0] = unlock_timer[0]; + unlock_timer[0] = l_npc_temper[looks].unlock_timer; + reset_timer[0] = unlock_timer[0]; } static int mNpc_CountTalkNum(int animal_idx, int looks) { - int res = FALSE; + int res = FALSE; - if (animal_idx >= 0 && animal_idx < ARRAY_COUNT(l_npc_talk_info)) { - mNpc_Talk_Info_c* talk_info = &l_npc_talk_info[animal_idx]; - - if (talk_info->talk_num < l_npc_temper[looks].talk_num_max && talk_info->timer > 0) { - talk_info->talk_num++; - res = TRUE; + if (animal_idx >= 0 && animal_idx < ARRAY_COUNT(l_npc_talk_info)) { + mNpc_Talk_Info_c* talk_info = &l_npc_talk_info[animal_idx]; + + if (talk_info->talk_num < l_npc_temper[looks].talk_num_max && talk_info->timer > 0) { + talk_info->talk_num++; + res = TRUE; + } } - } - return res; + return res; } extern int mNpc_CheckOverImpatient(int animal_idx, int looks) { - int res = FALSE; + int res = FALSE; - if (animal_idx >= 0 && animal_idx < ARRAY_COUNT(l_npc_talk_info)) { - mNpc_Talk_Info_c* talk_info = &l_npc_talk_info[animal_idx]; - - if (talk_info->talk_num >= l_npc_temper[looks].over_impatient_num) { - res = TRUE; + if (animal_idx >= 0 && animal_idx < ARRAY_COUNT(l_npc_talk_info)) { + mNpc_Talk_Info_c* talk_info = &l_npc_talk_info[animal_idx]; + + if (talk_info->talk_num >= l_npc_temper[looks].over_impatient_num) { + res = TRUE; + } } - } - return res; + return res; } extern int mNpc_GetOverImpatient(int animal_idx, int looks) { - int patience = mNpc_PATIENCE_NORMAL; + int patience = mNpc_PATIENCE_NORMAL; - if (animal_idx >= 0 && animal_idx < ARRAY_COUNT(l_npc_talk_info)) { - mNpc_Talk_Info_c* talk_info = &l_npc_talk_info[animal_idx]; - - if (talk_info->talk_num >= l_npc_temper[looks].over_impatient_num) { - if (talk_info->talk_num >= l_npc_temper[looks].talk_num_max) { - patience = mNpc_PATIENCE_ANNOYED; // refuse to talk - } - else { - patience = mNpc_PATIENCE_MILDLY_ANNOYED; // dialog shows mild annoyance - } + if (animal_idx >= 0 && animal_idx < ARRAY_COUNT(l_npc_talk_info)) { + mNpc_Talk_Info_c* talk_info = &l_npc_talk_info[animal_idx]; + + if (talk_info->talk_num >= l_npc_temper[looks].over_impatient_num) { + if (talk_info->talk_num >= l_npc_temper[looks].talk_num_max) { + patience = mNpc_PATIENCE_ANNOYED; // refuse to talk + } else { + patience = mNpc_PATIENCE_MILDLY_ANNOYED; // dialog shows mild annoyance + } + } } - } - return patience; + return patience; } extern int mNpc_CheckQuestRequest(int animal_idx) { - int res = FALSE; + int res = FALSE; - if (animal_idx >= 0 && animal_idx < ARRAY_COUNT(l_npc_talk_info)) { - mNpc_Talk_Info_c* talk_info = &l_npc_talk_info[animal_idx]; - - if (talk_info->quest_request == TRUE) { - res = TRUE; + if (animal_idx >= 0 && animal_idx < ARRAY_COUNT(l_npc_talk_info)) { + mNpc_Talk_Info_c* talk_info = &l_npc_talk_info[animal_idx]; + + if (talk_info->quest_request == TRUE) { + res = TRUE; + } } - } - return res; + return res; } extern void mNpc_SetQuestRequestOFF(int animal_idx, int looks) { - mNpc_Talk_Info_c* talk_info = &l_npc_talk_info[animal_idx]; + mNpc_Talk_Info_c* talk_info = &l_npc_talk_info[animal_idx]; - if (animal_idx >= 0 && animal_idx < ARRAY_COUNT(l_npc_talk_info)) { - if (talk_info->quest_request == TRUE) { - mNpc_SetUnlockTimer(&talk_info->unlock_timer, &talk_info->reset_timer, looks); + if (animal_idx >= 0 && animal_idx < ARRAY_COUNT(l_npc_talk_info)) { + if (talk_info->quest_request == TRUE) { + mNpc_SetUnlockTimer(&talk_info->unlock_timer, &talk_info->reset_timer, looks); + } + + talk_info->quest_request = FALSE; } - - talk_info->quest_request = FALSE; - } } static void mNpc_UnlockTimerCountDown(mNpc_Talk_Info_c* talk_info) { - if (talk_info != NULL && talk_info->unlock_timer > 0 && talk_info->unlock_timer > (talk_info->reset_timer - 1000)) { - talk_info->unlock_timer--; - } + if (talk_info != NULL && talk_info->unlock_timer > 0 && talk_info->unlock_timer > (talk_info->reset_timer - 1000)) { + talk_info->unlock_timer--; + } } extern void mNpc_TalkInfoMove() { - mNpc_Talk_Info_c* talk_info_p = l_npc_talk_info; - int i; + mNpc_Talk_Info_c* talk_info_p = l_npc_talk_info; + int i; - if (mFI_CheckPlayerWade(mFI_WADE_START) == TRUE) { + if (mFI_CheckPlayerWade(mFI_WADE_START) == TRUE) { + for (i = 0; i < ARRAY_COUNT(l_npc_talk_info); i++) { + talk_info_p->reset_timer = talk_info_p->unlock_timer; + talk_info_p++; + } + } + + talk_info_p = l_npc_talk_info; for (i = 0; i < ARRAY_COUNT(l_npc_talk_info); i++) { - talk_info_p->reset_timer = talk_info_p->unlock_timer; - talk_info_p++; + mNpc_TimerCountDown(talk_info_p); + mNpc_UnlockTimerCountDown(talk_info_p); + + if (talk_info_p->unlock_timer == 0 && talk_info_p->reset_timer > 0) { + talk_info_p->talk_num = 0; + talk_info_p->quest_request = TRUE; + talk_info_p->reset_timer = 0; + } + + talk_info_p++; } - } - - talk_info_p = l_npc_talk_info; - for (i = 0; i < ARRAY_COUNT(l_npc_talk_info); i++) { - mNpc_TimerCountDown(talk_info_p); - mNpc_UnlockTimerCountDown(talk_info_p); - - if (talk_info_p->unlock_timer == 0 && talk_info_p->reset_timer > 0) { - talk_info_p->talk_num = 0; - talk_info_p->quest_request = TRUE; - talk_info_p->reset_timer = 0; - } - - talk_info_p++; - } } extern void mNpc_TalkEndMove(int animal_idx, int looks) { - if (animal_idx >= 0 && animal_idx < ARRAY_COUNT(l_npc_talk_info) && looks >= 0 && looks < mNpc_LOOKS_NUM) { - mNpc_Talk_Info_c* talk_info = &l_npc_talk_info[animal_idx]; - talk_info->timer = 1000; + if (animal_idx >= 0 && animal_idx < ARRAY_COUNT(l_npc_talk_info) && looks >= 0 && looks < mNpc_LOOKS_NUM) { + mNpc_Talk_Info_c* talk_info = &l_npc_talk_info[animal_idx]; + talk_info->timer = 1000; - if (mNpc_CountTalkNum(animal_idx, looks) == TRUE && mNpc_CheckOverImpatient(animal_idx, looks) == TRUE) { - mNpc_SetUnlockTimer(&talk_info->unlock_timer, &talk_info->reset_timer, looks); + if (mNpc_CountTalkNum(animal_idx, looks) == TRUE && mNpc_CheckOverImpatient(animal_idx, looks) == TRUE) { + mNpc_SetUnlockTimer(&talk_info->unlock_timer, &talk_info->reset_timer, looks); + } } - } } extern int mNpc_GetNpcFloorNo() { - mActor_name_t field_id = mFI_GetFieldId(); - mActor_name_t owner_name = Common_Get(house_owner_name); - int floor_no = -1; + mActor_name_t field_id = mFI_GetFieldId(); + mActor_name_t owner_name = Common_Get(house_owner_name); + int floor_no = -1; - if (mFI_GET_TYPE(field_id) == mFI_FIELD_NPCROOM0) { + if (mFI_GET_TYPE(field_id) == mFI_FIELD_NPCROOM0) { - if (owner_name != EMPTY_NO && owner_name != RSV_NO) { - int idx = mNpc_SearchAnimalinfo(Save_Get(animals), owner_name, ANIMAL_NUM_MAX); - - floor_no = Common_Get(npclist[idx]).house_data.floor_id; + if (owner_name != EMPTY_NO && owner_name != RSV_NO) { + int idx = mNpc_SearchAnimalinfo(Save_Get(animals), owner_name, ANIMAL_NUM_MAX); + + floor_no = Common_Get(npclist[idx]).house_data.floor_id; + } } - } - return floor_no; + return floor_no; } extern int mNpc_GetNpcWallNo() { - mActor_name_t field_id = mFI_GetFieldId(); - mActor_name_t owner_name = Common_Get(house_owner_name); - int wall_no = -1; + mActor_name_t field_id = mFI_GetFieldId(); + mActor_name_t owner_name = Common_Get(house_owner_name); + int wall_no = -1; - if (mFI_GET_TYPE(field_id) == mFI_FIELD_NPCROOM0) { + if (mFI_GET_TYPE(field_id) == mFI_FIELD_NPCROOM0) { - if (owner_name != EMPTY_NO && owner_name != RSV_NO) { - int idx = mNpc_SearchAnimalinfo(Save_Get(animals), owner_name, ANIMAL_NUM_MAX); - - wall_no = Common_Get(npclist[idx]).house_data.wall_id; + if (owner_name != EMPTY_NO && owner_name != RSV_NO) { + int idx = mNpc_SearchAnimalinfo(Save_Get(animals), owner_name, ANIMAL_NUM_MAX); + + wall_no = Common_Get(npclist[idx]).house_data.wall_id; + } } - } - return wall_no; + return wall_no; } /* 75% */ extern void mNpc_SetTalkBee() { - if (Common_Get(player_bee_swell_flag) != TRUE) { + if (Common_Get(player_bee_swell_flag) != TRUE) { + Animal_c* animal = Save_Get(animals); + mNpc_NpcList_c* npclist = Common_Get(npclist); + int i; + + for (i = 0; i < ANIMAL_NUM_MAX; i++) { + if (mNpc_CheckFreeAnimalInfo(animal) == FALSE) { + npclist->conversation_flags.beesting = TRUE; + } + + animal++; + npclist++; + } + + if (mNpc_CheckFreeAnimalInfo(&Save_Get(island).animal) == FALSE) { + Common_Get(island_npclist[0]).conversation_flags.beesting = TRUE; + } + } +} + +extern u8 mNpc_GetFishCompleteTalk(mNpc_NpcList_c* npclist) { + u8 res = TRUE; + + if (npclist != NULL) { + res = npclist->conversation_flags.fish_complete; + } + + return res; +} + +extern u8 mNpc_GetInsectCompleteTalk(mNpc_NpcList_c* npclist) { + u8 res = TRUE; + + if (npclist != NULL) { + res = npclist->conversation_flags.insect_complete; + } + + return res; +} + +extern void mNpc_SetFishCompleteTalk(mNpc_NpcList_c* npclist) { + if (npclist != NULL) { + npclist->conversation_flags.fish_complete = TRUE; + } +} + +extern void mNpc_SetInsectCompleteTalk(mNpc_NpcList_c* npclist) { + if (npclist != NULL) { + npclist->conversation_flags.insect_complete = TRUE; + } +} + +extern void mNpc_SetNpcHomeYpos() { Animal_c* animal = Save_Get(animals); mNpc_NpcList_c* npclist = Common_Get(npclist); int i; for (i = 0; i < ANIMAL_NUM_MAX; i++) { - if (mNpc_CheckFreeAnimalInfo(animal) == FALSE) { - npclist->conversation_flags.beesting = TRUE; - } + if (mNpc_CheckFreeAnimalInfo(animal) == FALSE) { + npclist->house_position.y = mCoBG_GetBgY_OnlyCenter_FromWpos2(npclist->house_position, 0.0f); + } - animal++; - npclist++; + animal++; + npclist++; } - - if (mNpc_CheckFreeAnimalInfo(&Save_Get(island).animal) == FALSE) { - Common_Get(island_npclist[0]).conversation_flags.beesting = TRUE; - } - } -} - -extern u8 mNpc_GetFishCompleteTalk(mNpc_NpcList_c* npclist) { - u8 res = TRUE; - - if (npclist != NULL) { - res = npclist->conversation_flags.fish_complete; - } - - return res; -} - -extern u8 mNpc_GetInsectCompleteTalk(mNpc_NpcList_c* npclist) { - u8 res = TRUE; - - if (npclist != NULL) { - res = npclist->conversation_flags.insect_complete; - } - - return res; -} - -extern void mNpc_SetFishCompleteTalk(mNpc_NpcList_c* npclist) { - if (npclist != NULL) { - npclist->conversation_flags.fish_complete = TRUE; - } -} - -extern void mNpc_SetInsectCompleteTalk(mNpc_NpcList_c* npclist) { - if (npclist != NULL) { - npclist->conversation_flags.insect_complete = TRUE; - } -} - -extern void mNpc_SetNpcHomeYpos() { - Animal_c* animal = Save_Get(animals); - mNpc_NpcList_c* npclist = Common_Get(npclist); - int i; - - for (i = 0; i < ANIMAL_NUM_MAX; i++) { - if (mNpc_CheckFreeAnimalInfo(animal) == FALSE) { - npclist->house_position.y = mCoBG_GetBgY_OnlyCenter_FromWpos2(npclist->house_position, 0.0f); - } - - animal++; - npclist++; - } } static void mNpc_SetIslandAnimalHouse(Anmhome_c* home) { - int island_x_blocks[mISL_FG_BLOCK_X_NUM]; - int set = FALSE; - int bx; - int ut; + int island_x_blocks[mISL_FG_BLOCK_X_NUM]; + int set = FALSE; + int bx; + int ut; - mFI_GetIslandBlockNumX(island_x_blocks); + mFI_GetIslandBlockNumX(island_x_blocks); - for (bx = 0; bx < mISL_FG_BLOCK_X_NUM; bx++) { - mActor_name_t* items = &Save_Get(island).fgblock[0][bx].items[0][0]; + for (bx = 0; bx < mISL_FG_BLOCK_X_NUM; bx++) { + mActor_name_t* items = &Save_Get(island).fgblock[0][bx].items[0][0]; - if (items != NULL) { - for (ut = 0; ut < UT_TOTAL_NUM; ut++) { - if (*items == COTTAGE_NPC) { - home->block_x = island_x_blocks[bx]; - home->block_z = mISL_BLOCK_Z; - home->ut_x = ut & 15; - home->ut_z = (ut >> 4) + 1; - set = TRUE; + if (items != NULL) { + for (ut = 0; ut < UT_TOTAL_NUM; ut++) { + if (*items == COTTAGE_NPC) { + home->block_x = island_x_blocks[bx]; + home->block_z = mISL_BLOCK_Z; + home->ut_x = ut & 15; + home->ut_z = (ut >> 4) + 1; + set = TRUE; - break; + break; + } + + items++; + } + + if (set == TRUE) { + break; + } } - - items++; - } - - if (set == TRUE) { - break; - } } - } } extern void mNpc_DecideIslandNpc(Animal_c* animal) { - static int cand_table[NPC_ISLANDER_NUM]; + static int cand_table[NPC_ISLANDER_NUM]; - int* cand_p = cand_table; - int candidates = 0; - mNpc_Default_Data_c* def_list; - mActor_name_t npc_id; - s8* grow_list; - int i; + int* cand_p = cand_table; + int candidates = 0; + mNpc_Default_Data_c* def_list; + mActor_name_t npc_id; + s8* grow_list; + int i; - bzero(cand_p, sizeof(cand_table)); - mNpc_ClearIslandAnimalInfo(animal); - def_list = npc_def_list; - grow_list = npc_grow_list; + bzero(cand_p, sizeof(cand_table)); + mNpc_ClearIslandAnimalInfo(animal); + def_list = npc_def_list; + grow_list = npc_grow_list; - for (i = 0; i < NPC_NUM; i++) { - if (*grow_list == mNpc_GROW_ISLANDER) { - cand_p[0] = i; - cand_p++; - candidates++; + for (i = 0; i < NPC_NUM; i++) { + if (*grow_list == mNpc_GROW_ISLANDER) { + cand_p[0] = i; + cand_p++; + candidates++; + } + + if (candidates >= NPC_ISLANDER_NUM) { + break; + } + + grow_list++; } - if (candidates >= NPC_ISLANDER_NUM) { - break; + if (candidates <= 0) { + candidates = 1; } - grow_list++; - } - - if (candidates <= 0) { - candidates = 1; - } - - npc_id = NPC_START | cand_table[RANDOM(candidates)]; - mNpc_SetDefAnimal(animal, npc_id, def_list); - mNpc_SetHaveAppeared(npc_id); - mNpc_SetIslandAnimalHouse(&animal->home_info); + npc_id = NPC_START | cand_table[RANDOM(candidates)]; + mNpc_SetDefAnimal(animal, npc_id, def_list); + mNpc_SetHaveAppeared(npc_id); + mNpc_SetIslandAnimalHouse(&animal->home_info); } static mActor_name_t l_mnpc_get_ftr = EMPTY_NO; @@ -5377,2035 +5206,1956 @@ static int l_mnpc_get_letter = FALSE; static int l_mnpc_chk_ftr_msg = FALSE; typedef struct island_ftr_s { - u16 set_ftr_bitfield; - mActor_name_t trade_list[mNpc_ISLAND_FTR_SAVE_NUM]; - mActor_name_t item_list[mNpc_ISLAND_FTR_NUM]; + u16 set_ftr_bitfield; + mActor_name_t trade_list[mNpc_ISLAND_FTR_SAVE_NUM]; + mActor_name_t item_list[mNpc_ISLAND_FTR_NUM]; } mNpc_Island_Ftr_c; static mNpc_Island_Ftr_c l_mnpc_island_ftr; static void mNpc_ClearIslandItemList(mActor_name_t* item_list, int count) { - bzero(item_list, count * sizeof(mActor_name_t)); + bzero(item_list, count * sizeof(mActor_name_t)); } static int mNpc_GetFreeIslandItemListIdx(mActor_name_t* item_list, int count) { - int idx = -1; - int i; + int idx = -1; + int i; - for (i = 0; i < count; i++) { - if (*item_list == EMPTY_NO) { - idx = i; - break; + for (i = 0; i < count; i++) { + if (*item_list == EMPTY_NO) { + idx = i; + break; + } + + item_list++; } - item_list++; - } - - return idx; + return idx; } static int mNpc_SetIslandItemList(mActor_name_t* item_list, int count, mActor_name_t item) { - int res = FALSE; - int free_idx = mNpc_GetFreeIslandItemListIdx(item_list, count); + int res = FALSE; + int free_idx = mNpc_GetFreeIslandItemListIdx(item_list, count); - if (free_idx != -1) { - item_list[free_idx] = item; - res = TRUE; - } + if (free_idx != -1) { + item_list[free_idx] = item; + res = TRUE; + } - return res; + return res; } extern void mNpc_SetIslandRoomFtr(Animal_c* animal) { - mNpc_Island_Ftr_c* island_ftr_p = &l_mnpc_island_ftr; + mNpc_Island_Ftr_c* island_ftr_p = &l_mnpc_island_ftr; - if (animal != NULL) { - Anmmem_c* memory = animal->memories; - int i; + if (animal != NULL) { + Anmmem_c* memory = animal->memories; + int i; - island_ftr_p->set_ftr_bitfield = 0; - for (i = 0; i < ANIMAL_MEMORY_NUM; i++) { - if (mNpc_CheckFreeAnimalMemory(memory) == FALSE) { - island_ftr_p->set_ftr_bitfield |= memory->memuni.island.have_bitfield; - } + island_ftr_p->set_ftr_bitfield = 0; + for (i = 0; i < ANIMAL_MEMORY_NUM; i++) { + if (mNpc_CheckFreeAnimalMemory(memory) == FALSE) { + island_ftr_p->set_ftr_bitfield |= memory->memuni.island.have_bitfield; + } - memory++; + memory++; + } + + bcopy(&animal->anmuni.island_ftr, island_ftr_p->trade_list, mNpc_ISLAND_FTR_SAVE_NUM * sizeof(mActor_name_t)); + mNpc_ClearIslandItemList(island_ftr_p->item_list, mNpc_ISLAND_FTR_NUM); } - - bcopy(&animal->anmuni.island_ftr, island_ftr_p->trade_list, mNpc_ISLAND_FTR_SAVE_NUM * sizeof(mActor_name_t)); - mNpc_ClearIslandItemList(island_ftr_p->item_list, mNpc_ISLAND_FTR_NUM); - } } static int mNpc_GetIslandFtrIdx(mActor_name_t item) { - mActor_name_t* island_room = mNpc_GetIslandRoomP(Save_Get(island).animal.id.npc_id); - int n = 0; - int idx = -1; - int i; + mActor_name_t* island_room = mNpc_GetIslandRoomP(Save_Get(island).animal.id.npc_id); + int n = 0; + int idx = -1; + int i; - if (island_room != NULL && ITEM_IS_FTR(item)) { - if (mNpc_CheckFtrIsIslandBestFtr(item) == TRUE) { - for (i = 0; i < UT_TOTAL_NUM; i++) { - if (ITEM_IS_FTR(*island_room)) { - if (aMR_CorrespondFurniture(item, *island_room) == TRUE) { - idx = n; - break; - } + if (island_room != NULL && ITEM_IS_FTR(item)) { + if (mNpc_CheckFtrIsIslandBestFtr(item) == TRUE) { + for (i = 0; i < UT_TOTAL_NUM; i++) { + if (ITEM_IS_FTR(*island_room)) { + if (aMR_CorrespondFurniture(item, *island_room) == TRUE) { + idx = n; + break; + } - n++; - } - else if (*island_room >= RSV_ISLAND_FTR0 && *island_room <= RSV_ISLAND_FTR15) { - n++; - } + n++; + } else if (*island_room >= RSV_ISLAND_FTR0 && *island_room <= RSV_ISLAND_FTR15) { + n++; + } - if (n == mNpc_ISLAND_FTR_NUM) { - break; - } + if (n == mNpc_ISLAND_FTR_NUM) { + break; + } - island_room++; - } - } - else { - int ftr_unit = aMR_GetFurnitureUnit(item); - u32 ftr_variant0; - u32 ftr_variant1; - int j; - - if (ftr_unit == mRmTp_FTRSIZE_1x1) { - ftr_variant0 = RSV_ISLAND_FTR0; - ftr_variant1 = RSV_ISLAND_FTR4; - } - else { - ftr_variant0 = (mActor_name_t)(RSV_ISLAND_FTR0 + (ftr_unit + 1) * mRmTp_DIRECT_NUM); - ftr_variant1 = EMPTY_NO; - } - - for (i = 0; i < UT_TOTAL_NUM; i++) { - if (ITEM_IS_FTR(*island_room)) { - n++; - } - else if (*island_room >= RSV_ISLAND_FTR0 && *island_room <= RSV_ISLAND_FTR15) { - for (j = 0; j < mRmTp_DIRECT_NUM; j++) { - if (*island_room == (mActor_name_t)(ftr_variant0 + j) || *island_room == (mActor_name_t)(ftr_variant1 + j)) { - idx = n; - break; + island_room++; } - } + } else { + int ftr_unit = aMR_GetFurnitureUnit(item); + u32 ftr_variant0; + u32 ftr_variant1; + int j; - if (idx != -1) { - break; - } + if (ftr_unit == mRmTp_FTRSIZE_1x1) { + ftr_variant0 = RSV_ISLAND_FTR0; + ftr_variant1 = RSV_ISLAND_FTR4; + } else { + ftr_variant0 = (mActor_name_t)(RSV_ISLAND_FTR0 + (ftr_unit + 1) * mRmTp_DIRECT_NUM); + ftr_variant1 = EMPTY_NO; + } - n++; + for (i = 0; i < UT_TOTAL_NUM; i++) { + if (ITEM_IS_FTR(*island_room)) { + n++; + } else if (*island_room >= RSV_ISLAND_FTR0 && *island_room <= RSV_ISLAND_FTR15) { + for (j = 0; j < mRmTp_DIRECT_NUM; j++) { + if (*island_room == (mActor_name_t)(ftr_variant0 + j) || + *island_room == (mActor_name_t)(ftr_variant1 + j)) { + idx = n; + break; + } + } + + if (idx != -1) { + break; + } + + n++; + } + + if (n == mNpc_ISLAND_FTR_NUM) { + break; + } + + island_room++; + } } - - if (n == mNpc_ISLAND_FTR_NUM) { - break; - } - - island_room++; - } } - } - return idx; + return idx; } extern void mNpc_SetIslandGetFtr(mActor_name_t ftr) { - int n; - mNpc_Island_Ftr_c* island_ftr_p = &l_mnpc_island_ftr; - mActor_name_t* island_room = mNpc_GetIslandRoomP(Save_Get(island).animal.id.npc_id); - int set; - int variant; - int slot; - int i; + int n; + mNpc_Island_Ftr_c* island_ftr_p = &l_mnpc_island_ftr; + mActor_name_t* island_room = mNpc_GetIslandRoomP(Save_Get(island).animal.id.npc_id); + int set; + int variant; + int slot; + int i; - n = 0; - set = FALSE; - - if (ftr != EMPTY_NO && ITEM_IS_FTR(ftr) && island_room != NULL) { - if (mNpc_CheckFtrIsIslandBestFtr(ftr) == TRUE) { - int idx = mNpc_GetIslandFtrIdx(ftr); + n = 0; + set = FALSE; - if (idx >= 0 && idx < mNpc_ISLAND_FTR_NUM && ((island_ftr_p->set_ftr_bitfield >> idx) & 1) == 0) { - island_ftr_p->set_ftr_bitfield |= (1 << idx); - set = TRUE; - } - } - else { - int ftr_unit = aMR_GetFurnitureUnit(ftr); - mActor_name_t ftr_variant0; - mActor_name_t ftr_variant1; - int j; + if (ftr != EMPTY_NO && ITEM_IS_FTR(ftr) && island_room != NULL) { + if (mNpc_CheckFtrIsIslandBestFtr(ftr) == TRUE) { + int idx = mNpc_GetIslandFtrIdx(ftr); - if (ftr_unit == mRmTp_FTRSIZE_1x1) { - ftr_variant0 = RSV_ISLAND_FTR0; - ftr_variant1 = RSV_ISLAND_FTR4; - } - else { - ftr_variant0 = RSV_ISLAND_FTR0 + (ftr_unit + 1) * 4; - ftr_variant1 = EMPTY_NO; - } - - for (i = 0; i < UT_TOTAL_NUM; i++) { - if (ITEM_IS_FTR(*island_room)) { - n++; - } - else if (*island_room >= RSV_ISLAND_FTR0 && *island_room <= RSV_ISLAND_FTR15) { - variant = -1; - - for (j = 0; j < mRmTp_DIRECT_NUM; j++) { - if (*island_room == (mActor_name_t)(ftr_variant0 + j)) { - variant = 0; - break; + if (idx >= 0 && idx < mNpc_ISLAND_FTR_NUM && ((island_ftr_p->set_ftr_bitfield >> idx) & 1) == 0) { + island_ftr_p->set_ftr_bitfield |= (1 << idx); + set = TRUE; } - else if (*island_room == (mActor_name_t)(ftr_variant1 + j)) { - variant = 1; - break; - } - } + } else { + int ftr_unit = aMR_GetFurnitureUnit(ftr); + mActor_name_t ftr_variant0; + mActor_name_t ftr_variant1; + int j; - if (variant != -1 && n >= 0 && n < mNpc_ISLAND_FTR_NUM && ((island_ftr_p->set_ftr_bitfield >> n) & 1) == 0) { - island_ftr_p->set_ftr_bitfield |= (1 << n); - - if (variant == 0) { - slot = (ftr_variant0 - RSV_ISLAND_FTR0) / mNpc_ISLAND_FTR_SAVE_NUM; - } - else { - slot = (ftr_variant1 - RSV_ISLAND_FTR0) / mNpc_ISLAND_FTR_SAVE_NUM; + if (ftr_unit == mRmTp_FTRSIZE_1x1) { + ftr_variant0 = RSV_ISLAND_FTR0; + ftr_variant1 = RSV_ISLAND_FTR4; + } else { + ftr_variant0 = RSV_ISLAND_FTR0 + (ftr_unit + 1) * 4; + ftr_variant1 = EMPTY_NO; } - if (slot < mNpc_ISLAND_FTR_SAVE_NUM) { - ftr = aMR_FurnitureFg_to_FurnitureFgWithDirect(ftr, j); - island_ftr_p->trade_list[slot] = ftr; - set = TRUE; + for (i = 0; i < UT_TOTAL_NUM; i++) { + if (ITEM_IS_FTR(*island_room)) { + n++; + } else if (*island_room >= RSV_ISLAND_FTR0 && *island_room <= RSV_ISLAND_FTR15) { + variant = -1; + + for (j = 0; j < mRmTp_DIRECT_NUM; j++) { + if (*island_room == (mActor_name_t)(ftr_variant0 + j)) { + variant = 0; + break; + } else if (*island_room == (mActor_name_t)(ftr_variant1 + j)) { + variant = 1; + break; + } + } + + if (variant != -1 && n >= 0 && n < mNpc_ISLAND_FTR_NUM && + ((island_ftr_p->set_ftr_bitfield >> n) & 1) == 0) { + island_ftr_p->set_ftr_bitfield |= (1 << n); + + if (variant == 0) { + slot = (ftr_variant0 - RSV_ISLAND_FTR0) / mNpc_ISLAND_FTR_SAVE_NUM; + } else { + slot = (ftr_variant1 - RSV_ISLAND_FTR0) / mNpc_ISLAND_FTR_SAVE_NUM; + } + + if (slot < mNpc_ISLAND_FTR_SAVE_NUM) { + ftr = aMR_FurnitureFg_to_FurnitureFgWithDirect(ftr, j); + island_ftr_p->trade_list[slot] = ftr; + set = TRUE; + } + + break; + } + + n++; + } + + if (n == mNpc_ISLAND_FTR_NUM) { + break; + } + + island_room++; } - - break; - } - - n++; } - if (n == mNpc_ISLAND_FTR_NUM) { - break; + if (set == TRUE) { + mNpc_SetIslandItemList(island_ftr_p->item_list, mNpc_ISLAND_FTR_NUM, ftr); } - - island_room++; - } } - - if (set == TRUE) { - mNpc_SetIslandItemList(island_ftr_p->item_list, mNpc_ISLAND_FTR_NUM, ftr); - } - } } extern void mNpc_SetIslandGetFtrtoRoom() { - mActor_name_t* item_list = l_mnpc_island_ftr.item_list; - Animal_c* animal = &Save_Get(island).animal; + mActor_name_t* item_list = l_mnpc_island_ftr.item_list; + Animal_c* animal = &Save_Get(island).animal; - if (Common_Get(now_private) != NULL) { - Private_c* priv = Common_Get(now_private); - int i; - - for (i = 0; i < mNpc_ISLAND_FTR_NUM; i++) { - if (*item_list != EMPTY_NO && ITEM_IS_FTR(*item_list)) { - mNpc_SetIslandFtr(&priv->player_ID, *item_list); - } + if (Common_Get(now_private) != NULL) { + Private_c* priv = Common_Get(now_private); + int i; - item_list++; + for (i = 0; i < mNpc_ISLAND_FTR_NUM; i++) { + if (*item_list != EMPTY_NO && ITEM_IS_FTR(*item_list)) { + mNpc_SetIslandFtr(&priv->player_ID, *item_list); + } + + item_list++; + } + + mNpc_RestoreIslandPresentFtr(); + mNpc_ClearIslandPresentFtrInfo(); + mNpc_SetIslandRoomFtr(animal); } - - mNpc_RestoreIslandPresentFtr(); - mNpc_ClearIslandPresentFtrInfo(); - mNpc_SetIslandRoomFtr(animal); - } } extern void mNpc_SetIslandGetLetter(int get) { - l_mnpc_get_letter = get; + l_mnpc_get_letter = get; } extern int mNpc_GetIslandGetLetter() { - return l_mnpc_get_letter; + return l_mnpc_get_letter; } extern void mNpc_SetIslandCheckFtrMsg(int set) { - l_mnpc_chk_ftr_msg = set; + l_mnpc_chk_ftr_msg = set; } extern int mNpc_GetIslandCheckFtrMsg() { - return l_mnpc_chk_ftr_msg; + return l_mnpc_chk_ftr_msg; } typedef struct npc_island_room_data_s { - mActor_name_t items[UT_Z_NUM][UT_X_NUM]; - int wall_no; - int floor_no; - mActor_name_t npc_id; + mActor_name_t items[UT_Z_NUM][UT_X_NUM]; + int wall_no; + int floor_no; + mActor_name_t npc_id; } mNpc_Island_Npc_Room_Data_c; static mNpc_Island_Npc_Room_Data_c l_island_npc_room_data[NPC_ISLANDER_NUM]; static mActor_name_t l_island_npc_best_fg_id[NPC_ISLANDER_NUM][2] = { - { 0x0250, 0x0251 }, - { 0x0346, 0x0347 }, - { 0x0372, 0x0373 }, - { 0x027C, 0x027D }, - { 0x02EA, 0x02EB }, - { 0x0326, 0x0327 }, - { 0x0270, 0x0271 }, - { 0x01C0, 0x01C1 }, - { 0x039A, 0x039B }, - { 0x02F0, 0x02F1 }, - { 0x02C4, 0x02C5 }, - { 0x0224, 0x0225 }, - { 0x02D4, 0x02D5 }, - { 0x02A4, 0x02A5 }, - { 0x038C, 0x038D }, - { 0x01FE, 0x01FF }, - { 0x032E, 0x032F }, - { 0x01E6, 0x01E7 } + { 0x0250, 0x0251 }, { 0x0346, 0x0347 }, { 0x0372, 0x0373 }, { 0x027C, 0x027D }, { 0x02EA, 0x02EB }, + { 0x0326, 0x0327 }, { 0x0270, 0x0271 }, { 0x01C0, 0x01C1 }, { 0x039A, 0x039B }, { 0x02F0, 0x02F1 }, + { 0x02C4, 0x02C5 }, { 0x0224, 0x0225 }, { 0x02D4, 0x02D5 }, { 0x02A4, 0x02A5 }, { 0x038C, 0x038D }, + { 0x01FE, 0x01FF }, { 0x032E, 0x032F }, { 0x01E6, 0x01E7 } }; extern void mNpc_ClearIslandNpcRoomData() { - bzero(l_island_npc_room_data, sizeof(l_island_npc_room_data)); + bzero(l_island_npc_room_data, sizeof(l_island_npc_room_data)); } extern void mNpc_IslandNpcRoomDataSet(mFM_fg_data_c** data_table, int base_idx) { - mNpc_Island_Npc_Room_Data_c* dst = l_island_npc_room_data; - s8* grow_list = npc_grow_list; - mNpc_NpcHouseData_c* house_list = npc_house_list; - int islander = 0; - int i; + mNpc_Island_Npc_Room_Data_c* dst = l_island_npc_room_data; + s8* grow_list = npc_grow_list; + mNpc_NpcHouseData_c* house_list = npc_house_list; + int islander = 0; + int i; - for (i = 0; i < NPC_NUM; i++) { - if (*grow_list == mNpc_GROW_ISLANDER) { - int idx = l_island_npc_best_fg_id[islander][0] - base_idx; - mFM_fg_data_c* best_id_p = data_table[idx]; + for (i = 0; i < NPC_NUM; i++) { + if (*grow_list == mNpc_GROW_ISLANDER) { + int idx = l_island_npc_best_fg_id[islander][0] - base_idx; + mFM_fg_data_c* best_id_p = data_table[idx]; - if (best_id_p != NULL) { - dst->wall_no = house_list->wall_id; - dst->floor_no = house_list->floor_id; - bcopy(data_table[idx]->items, dst->items, sizeof(best_id_p->items)); - dst->npc_id = NPC_START | i; + if (best_id_p != NULL) { + dst->wall_no = house_list->wall_id; + dst->floor_no = house_list->floor_id; + bcopy(data_table[idx]->items, dst->items, sizeof(best_id_p->items)); + dst->npc_id = NPC_START | i; - islander++; - dst++; - } + islander++; + dst++; + } + } + + if (islander >= NPC_ISLANDER_NUM) { + break; + } + + grow_list++; + house_list++; } - - if (islander >= NPC_ISLANDER_NUM) { - break; - } - - grow_list++; - house_list++; - } } static mNpc_Island_Npc_Room_Data_c* mNpc_GetIslandRoomInfoP(mActor_name_t npc_id) { - mNpc_Island_Npc_Room_Data_c* room_p = l_island_npc_room_data; - mNpc_Island_Npc_Room_Data_c* res = NULL; - int i; + mNpc_Island_Npc_Room_Data_c* room_p = l_island_npc_room_data; + mNpc_Island_Npc_Room_Data_c* res = NULL; + int i; - for (i = 0; i < NPC_ISLANDER_NUM; i++) { - /* @BUG - devs used & instead of && */ - #ifndef BUGFIXES - if (npc_id != EMPTY_NO & room_p->npc_id == npc_id) { - #else - if (npc_id != EMPTY_NO && room_p->npc_id == npc_id) { - #endif - res = room_p; - break; + for (i = 0; i < NPC_ISLANDER_NUM; i++) { +/* @BUG - devs used & instead of && */ +#ifndef BUGFIXES + if (npc_id != EMPTY_NO & room_p->npc_id == npc_id) { +#else + if (npc_id != EMPTY_NO && room_p->npc_id == npc_id) { +#endif + res = room_p; + break; + } + + room_p++; } - room_p++; - } - - return res; + return res; } extern mActor_name_t* mNpc_GetIslandRoomP(mActor_name_t npc_id) { - mActor_name_t* res = NULL; - mNpc_Island_Npc_Room_Data_c* room_info = mNpc_GetIslandRoomInfoP(npc_id); + mActor_name_t* res = NULL; + mNpc_Island_Npc_Room_Data_c* room_info = mNpc_GetIslandRoomInfoP(npc_id); - if (room_info != NULL) { - res = room_info->items[0]; - } + if (room_info != NULL) { + res = room_info->items[0]; + } - return res; + return res; } extern void mNpc_GetIslandWallFloorIdx(int* wall, int* floor, mActor_name_t npc_id) { - mNpc_Island_Npc_Room_Data_c* room_info; + mNpc_Island_Npc_Room_Data_c* room_info; - if (wall != NULL && floor != NULL) { - wall[0] = 8; - floor[0] = 32; + if (wall != NULL && floor != NULL) { + wall[0] = 8; + floor[0] = 32; - room_info = mNpc_GetIslandRoomInfoP(npc_id); + room_info = mNpc_GetIslandRoomInfoP(npc_id); - if (room_info != NULL) { - wall[0] = room_info->wall_no; - floor[0] = room_info->floor_no; + if (room_info != NULL) { + wall[0] = room_info->wall_no; + floor[0] = room_info->floor_no; + } } - } } static mActor_name_t mNpc_getNormalFtr(mActor_name_t rsv_name, Animal_c* animal) { - mActor_name_t ftr = EMPTY_NO; - int idx; + mActor_name_t ftr = EMPTY_NO; + int idx; - if (rsv_name >= RSV_ISLAND_FTR0 && rsv_name <= RSV_ISLAND_FTR15) { - int rsv = rsv_name - RSV_ISLAND_FTR0; - - idx = (rsv - (rsv % mNpc_ISLAND_FTR_SAVE_NUM)) / mNpc_ISLAND_FTR_SAVE_NUM; - if (idx >= mNpc_ISLAND_FTR_SAVE_NUM) { - idx = 0; + if (rsv_name >= RSV_ISLAND_FTR0 && rsv_name <= RSV_ISLAND_FTR15) { + int rsv = rsv_name - RSV_ISLAND_FTR0; + + idx = (rsv - (rsv % mNpc_ISLAND_FTR_SAVE_NUM)) / mNpc_ISLAND_FTR_SAVE_NUM; + if (idx >= mNpc_ISLAND_FTR_SAVE_NUM) { + idx = 0; + } + + ftr = animal->anmuni.island_ftr[idx]; } - - ftr = animal->anmuni.island_ftr[idx]; - } - return ftr; + return ftr; } static int mNpc_CheckIslandNpcRoomFtrIdx(int ftr_idx) { - Animal_c* animal = &Save_Get(island).animal; - Anmmem_c* memory; - int i; - int res = -1; + Animal_c* animal = &Save_Get(island).animal; + Anmmem_c* memory; + int i; + int res = -1; - if (mNpc_CheckFreeAnimalInfo(animal) == FALSE && ftr_idx >= 0 && ftr_idx < mNpc_ISLAND_FTR_NUM) { - memory = animal->memories; + if (mNpc_CheckFreeAnimalInfo(animal) == FALSE && ftr_idx >= 0 && ftr_idx < mNpc_ISLAND_FTR_NUM) { + memory = animal->memories; - for (i = 0; i < ANIMAL_MEMORY_NUM; i++) { - if ( - mPr_NullCheckPersonalID(&memory->memory_player_id) == FALSE && - ((memory->memuni.island.have_bitfield >> ftr_idx) & 1) == 1 - ) { - res = i; - break; - } + for (i = 0; i < ANIMAL_MEMORY_NUM; i++) { + if (mPr_NullCheckPersonalID(&memory->memory_player_id) == FALSE && + ((memory->memuni.island.have_bitfield >> ftr_idx) & 1) == 1) { + res = i; + break; + } - memory++; + memory++; + } } - } - return res; + return res; } extern int mNpc_CheckIslandNpcRoomFtrItemNo_keep(mActor_name_t ftr) { - mActor_name_t* island_room; - int keep; - mActor_name_t* trade_list; - mNpc_Island_Ftr_c* island_ftr_p; - mActor_name_t rsv_item; - int n; - int found; - int i; - int j; + mActor_name_t* island_room; + int keep; + mActor_name_t* trade_list; + mNpc_Island_Ftr_c* island_ftr_p; + mActor_name_t rsv_item; + int n; + int found; + int i; + int j; - island_ftr_p = &l_mnpc_island_ftr; - trade_list = l_mnpc_island_ftr.trade_list; - rsv_item = EMPTY_NO; - found = FALSE; - n = 0; - keep = FALSE; - island_room = mNpc_GetIslandRoomP(Save_Get(island).animal.id.npc_id); - - if (ITEM_IS_FTR(ftr) && island_room != NULL) { - if (mNpc_CheckFtrIsIslandBestFtr(ftr) == TRUE) { - int idx = mNpc_GetIslandFtrIdx(ftr); + island_ftr_p = &l_mnpc_island_ftr; + trade_list = l_mnpc_island_ftr.trade_list; + rsv_item = EMPTY_NO; + found = FALSE; + n = 0; + keep = FALSE; + island_room = mNpc_GetIslandRoomP(Save_Get(island).animal.id.npc_id); - /* @BUG & should've been && */ - #ifndef BUGFIXES - if (((idx >= 0) & (idx < mNpc_ISLAND_FTR_NUM)) && ((island_ftr_p->set_ftr_bitfield >> idx) & 1) == 0) { - #else - if (((idx >= 0) && (idx < mNpc_ISLAND_FTR_NUM)) && ((island_ftr_p->set_ftr_bitfield >> idx) & 1) == 0) { - #endif - keep = TRUE; - } - } - else { - for (i = 0; i < mNpc_ISLAND_FTR_SAVE_NUM; i++) { - /* Why loop through each direction instead of just masking off the rotation bits */ - for (j = 0; j < mRmTp_DIRECT_NUM; j++) { - mActor_name_t dir_item = aMR_FurnitureFg_to_FurnitureFgWithDirect(ftr, j); + if (ITEM_IS_FTR(ftr) && island_room != NULL) { + if (mNpc_CheckFtrIsIslandBestFtr(ftr) == TRUE) { + int idx = mNpc_GetIslandFtrIdx(ftr); - if (dir_item == trade_list[i]) { - found = TRUE; - break; - } - } +/* @BUG & should've been && */ +#ifndef BUGFIXES + if (((idx >= 0) & (idx < mNpc_ISLAND_FTR_NUM)) && ((island_ftr_p->set_ftr_bitfield >> idx) & 1) == 0) { +#else + if (((idx >= 0) && (idx < mNpc_ISLAND_FTR_NUM)) && ((island_ftr_p->set_ftr_bitfield >> idx) & 1) == 0) { +#endif + keep = TRUE; + } + } else { + for (i = 0; i < mNpc_ISLAND_FTR_SAVE_NUM; i++) { + /* Why loop through each direction instead of just masking off the rotation bits */ + for (j = 0; j < mRmTp_DIRECT_NUM; j++) { + mActor_name_t dir_item = aMR_FurnitureFg_to_FurnitureFgWithDirect(ftr, j); - if (found == TRUE) { - break; - } - } - - if (found == FALSE) { - int ftr_unit = aMR_GetFurnitureUnit(ftr); - - if (ftr_unit == mRmTp_FTRSIZE_1x1) { - if (trade_list[0] == EMPTY_NO) { - rsv_item = RSV_ISLAND_FTR0; - } - else if (trade_list[1] == EMPTY_NO) { - rsv_item = RSV_ISLAND_FTR4; - } - } - else if (ftr_unit != -1) { - ftr_unit++; - - if (trade_list[ftr_unit] == EMPTY_NO) { - rsv_item = RSV_ISLAND_FTR0 + ftr_unit * mRmTp_DIRECT_NUM; - } - } - - if (rsv_item != EMPTY_NO) { - for (i = 0; i < UT_TOTAL_NUM; i++) { - if (*island_room >= RSV_ISLAND_FTR0 && *island_room <= RSV_ISLAND_FTR15) { - for (j = 0; j < mRmTp_DIRECT_NUM; j++) { - if (*island_room == (mActor_name_t)(rsv_item + j)) { - keep = TRUE; - break; + if (dir_item == trade_list[i]) { + found = TRUE; + break; + } + } + + if (found == TRUE) { + break; } - } } - if (keep == TRUE) { - break; - } + if (found == FALSE) { + int ftr_unit = aMR_GetFurnitureUnit(ftr); - island_room++; - } + if (ftr_unit == mRmTp_FTRSIZE_1x1) { + if (trade_list[0] == EMPTY_NO) { + rsv_item = RSV_ISLAND_FTR0; + } else if (trade_list[1] == EMPTY_NO) { + rsv_item = RSV_ISLAND_FTR4; + } + } else if (ftr_unit != -1) { + ftr_unit++; + + if (trade_list[ftr_unit] == EMPTY_NO) { + rsv_item = RSV_ISLAND_FTR0 + ftr_unit * mRmTp_DIRECT_NUM; + } + } + + if (rsv_item != EMPTY_NO) { + for (i = 0; i < UT_TOTAL_NUM; i++) { + if (*island_room >= RSV_ISLAND_FTR0 && *island_room <= RSV_ISLAND_FTR15) { + for (j = 0; j < mRmTp_DIRECT_NUM; j++) { + if (*island_room == (mActor_name_t)(rsv_item + j)) { + keep = TRUE; + break; + } + } + } + + if (keep == TRUE) { + break; + } + + island_room++; + } + } + } } - } } - } - return keep; + return keep; } extern void mNpc_ChangeIslandRoom(mActor_name_t* items) { - Animal_c* animal = &Save_Get(island).animal; - int n = 0; - int i; + Animal_c* animal = &Save_Get(island).animal; + int n = 0; + int i; - if (items != NULL) { - for (i = 0; i < UT_TOTAL_NUM; i++) { - if (ITEM_IS_FTR(*items)) { - if (mNpc_CheckIslandNpcRoomFtrIdx(n) == -1) { - items[0] = RSV_NO; // cleared because the item hasn't been "obtained" by the islander yet + if (items != NULL) { + for (i = 0; i < UT_TOTAL_NUM; i++) { + if (ITEM_IS_FTR(*items)) { + if (mNpc_CheckIslandNpcRoomFtrIdx(n) == -1) { + items[0] = RSV_NO; // cleared because the item hasn't been "obtained" by the islander yet + } + + n++; + } else if (*items >= RSV_ISLAND_FTR0 && *items <= RSV_ISLAND_FTR15) { + if (mNpc_CheckIslandNpcRoomFtrIdx(n) == -1) { + items[0] = RSV_NO; // cleared because the item hasn't been "obtained" by the islander yet + } else { + items[0] = mNpc_getNormalFtr(*items, animal); // update with "not best" furniture + } + + n++; + } + + if (n >= mNpc_ISLAND_FTR_NUM) { + break; + } + + items++; } - - n++; - } - else if (*items >= RSV_ISLAND_FTR0 && *items <= RSV_ISLAND_FTR15) { - if (mNpc_CheckIslandNpcRoomFtrIdx(n) == -1) { - items[0] = RSV_NO; // cleared because the item hasn't been "obtained" by the islander yet - } - else { - items[0] = mNpc_getNormalFtr(*items, animal); // update with "not best" furniture - } - - n++; - } - - if (n >= mNpc_ISLAND_FTR_NUM) { - break; - } - - items++; } - } } extern int mNpc_CheckFtrIsIslandBestFtr(mActor_name_t ftr) { - mActor_name_t* island_room; - int i; - int res = FALSE; - - island_room = mNpc_GetIslandRoomP(Save_Get(island).animal.id.npc_id); - if (island_room != NULL && ITEM_IS_FTR(ftr)) { - for (i = 0; i < UT_TOTAL_NUM; i++) { - if (aMR_CorrespondFurniture(ftr, *island_room) == TRUE) { - res = TRUE; - break; - } + mActor_name_t* island_room; + int i; + int res = FALSE; - island_room++; + island_room = mNpc_GetIslandRoomP(Save_Get(island).animal.id.npc_id); + if (island_room != NULL && ITEM_IS_FTR(ftr)) { + for (i = 0; i < UT_TOTAL_NUM; i++) { + if (aMR_CorrespondFurniture(ftr, *island_room) == TRUE) { + res = TRUE; + break; + } + + island_room++; + } } - } - return res; + return res; } extern int mNpc_CheckFtrIsIslandNormalFtr(mActor_name_t ftr) { - int res = FALSE; + int res = FALSE; - if (ITEM_IS_FTR(ftr) && mNpc_CheckFtrIsIslandBestFtr(ftr) == FALSE) { - res = TRUE; - } + if (ITEM_IS_FTR(ftr) && mNpc_CheckFtrIsIslandBestFtr(ftr) == FALSE) { + res = TRUE; + } - return res; + return res; } extern int mNpc_SetIslandFtr(PersonalID_c* pid, mActor_name_t ftr) { - int n; - Anmmem_c* memory; - mActor_name_t* island_room; - int slot; - Animal_c* animal; - mActor_name_t rsv_item; - int i; - int j; - int variant; - int set; - int direct; - - memory = Save_Get(island).animal.memories; - animal = &Save_Get(island).animal; - island_room = mNpc_GetIslandRoomP(animal->id.npc_id); - n = 0; - rsv_item = EMPTY_NO; - set = FALSE; - slot = 0; - direct = 0; - - if (ITEM_IS_FTR(ftr) && island_room != NULL && pid != NULL && mPr_NullCheckPersonalID(pid) == FALSE) { - int mem_idx = mNpc_GetAnimalMemoryIdx(pid, memory, ANIMAL_MEMORY_NUM); + int n; + Anmmem_c* memory; + mActor_name_t* island_room; + int slot; + Animal_c* animal; + mActor_name_t rsv_item; + int i; + int j; + int variant; + int set; + int direct; - if (mem_idx == -1) { - memory = &memory[mNpc_ForceGetFreeAnimalMemoryIdx(animal, memory, ANIMAL_MEMORY_NUM)]; - mNpc_SetAnimalMemory(pid, &animal->id, memory); - } - else { - memory = &memory[mem_idx]; - } + memory = Save_Get(island).animal.memories; + animal = &Save_Get(island).animal; + island_room = mNpc_GetIslandRoomP(animal->id.npc_id); + n = 0; + rsv_item = EMPTY_NO; + set = FALSE; + slot = 0; + direct = 0; - /* Unnecessary NULL check, memory is guaranteed to exist */ - if (memory != NULL) { - if (mNpc_CheckFtrIsIslandBestFtr(ftr) == TRUE) { - int idx = mNpc_GetIslandFtrIdx(ftr); + if (ITEM_IS_FTR(ftr) && island_room != NULL && pid != NULL && mPr_NullCheckPersonalID(pid) == FALSE) { + int mem_idx = mNpc_GetAnimalMemoryIdx(pid, memory, ANIMAL_MEMORY_NUM); - if (idx != -1 && mNpc_CheckIslandNpcRoomFtrIdx(idx) == -1) { - memory->memuni.island.have_bitfield |= (1 << idx); - set = TRUE; - } - } - else { - mActor_name_t ftr_variant0; - mActor_name_t ftr_variant1; - int ftr_unit = aMR_GetFurnitureUnit(ftr); - - if (ftr_unit == mRmTp_FTRSIZE_1x1) { - ftr_variant0 = RSV_ISLAND_FTR0; - ftr_variant1 = RSV_ISLAND_FTR4; - } - else { - ftr_variant0 = RSV_ISLAND_FTR0 + (ftr_unit + 1) * 4; - ftr_variant1 = EMPTY_NO; + if (mem_idx == -1) { + memory = &memory[mNpc_ForceGetFreeAnimalMemoryIdx(animal, memory, ANIMAL_MEMORY_NUM)]; + mNpc_SetAnimalMemory(pid, &animal->id, memory); + } else { + memory = &memory[mem_idx]; } - for (i = 0; i < UT_TOTAL_NUM; i++) { - if (ITEM_IS_FTR(*island_room)) { - n++; - } - else if (*island_room >= RSV_ISLAND_FTR0 && *island_room <= RSV_ISLAND_FTR15) { - variant = -1; + /* Unnecessary NULL check, memory is guaranteed to exist */ + if (memory != NULL) { + if (mNpc_CheckFtrIsIslandBestFtr(ftr) == TRUE) { + int idx = mNpc_GetIslandFtrIdx(ftr); - for (j = 0; j < mRmTp_DIRECT_NUM; j++) { - if (*island_room == (mActor_name_t)(ftr_variant0 + j)) { - direct = j; - variant = 0; - break; - } - else if (*island_room == (mActor_name_t)(ftr_variant1 + j)) { - direct = j; - variant = 1; - break; - } + if (idx != -1 && mNpc_CheckIslandNpcRoomFtrIdx(idx) == -1) { + memory->memuni.island.have_bitfield |= (1 << idx); + set = TRUE; + } + } else { + mActor_name_t ftr_variant0; + mActor_name_t ftr_variant1; + int ftr_unit = aMR_GetFurnitureUnit(ftr); + + if (ftr_unit == mRmTp_FTRSIZE_1x1) { + ftr_variant0 = RSV_ISLAND_FTR0; + ftr_variant1 = RSV_ISLAND_FTR4; + } else { + ftr_variant0 = RSV_ISLAND_FTR0 + (ftr_unit + 1) * 4; + ftr_variant1 = EMPTY_NO; + } + + for (i = 0; i < UT_TOTAL_NUM; i++) { + if (ITEM_IS_FTR(*island_room)) { + n++; + } else if (*island_room >= RSV_ISLAND_FTR0 && *island_room <= RSV_ISLAND_FTR15) { + variant = -1; + + for (j = 0; j < mRmTp_DIRECT_NUM; j++) { + if (*island_room == (mActor_name_t)(ftr_variant0 + j)) { + direct = j; + variant = 0; + break; + } else if (*island_room == (mActor_name_t)(ftr_variant1 + j)) { + direct = j; + variant = 1; + break; + } + } + + if (variant != -1 && mNpc_CheckIslandNpcRoomFtrIdx(n) == -1) { + memory->memuni.island.have_bitfield |= (1 << n); + + if (variant == 0) { + slot = (ftr_variant0 - RSV_ISLAND_FTR0) / mNpc_ISLAND_FTR_SAVE_NUM; + } else { + slot = (ftr_variant1 - RSV_ISLAND_FTR0) / mNpc_ISLAND_FTR_SAVE_NUM; + } + + if (slot < mNpc_ISLAND_FTR_SAVE_NUM) { + Save_Get(island).animal.anmuni.island_ftr[slot] = + aMR_FurnitureFg_to_FurnitureFgWithDirect(ftr, direct); + set = TRUE; + } + + break; + } + + n++; + } + + if (n == mNpc_ISLAND_FTR_NUM) { + break; + } + + island_room++; + } } - - if (variant != -1 && mNpc_CheckIslandNpcRoomFtrIdx(n) == -1) { - memory->memuni.island.have_bitfield |= (1 << n); - - if (variant == 0) { - slot = (ftr_variant0 - RSV_ISLAND_FTR0) / mNpc_ISLAND_FTR_SAVE_NUM; - } - else { - slot = (ftr_variant1 - RSV_ISLAND_FTR0) / mNpc_ISLAND_FTR_SAVE_NUM; - } - - if (slot < mNpc_ISLAND_FTR_SAVE_NUM) { - Save_Get(island).animal.anmuni.island_ftr[slot] = aMR_FurnitureFg_to_FurnitureFgWithDirect(ftr, direct); - set = TRUE; - } - - break; - } - - n++; - } - - if (n == mNpc_ISLAND_FTR_NUM) { - break; - } - - island_room++; } - } } - } - return set; + return set; } extern int mNpc_EraseIslandFtr(mActor_name_t ftr) { - int n; - Animal_c* animal; - mActor_name_t* island_room; - mActor_name_t* island_ftr; - mActor_name_t rsv_no; - int i; - int j; - int variant; - int set; + int n; + Animal_c* animal; + mActor_name_t* island_room; + mActor_name_t* island_ftr; + mActor_name_t rsv_no; + int i; + int j; + int variant; + int set; - animal = &Save_Get(island).animal; - island_room = mNpc_GetIslandRoomP(animal->id.npc_id); - island_ftr = Save_Get(island).animal.anmuni.island_ftr; - rsv_no = EMPTY_NO; - n = 0; - set = FALSE; - - if (ITEM_IS_FTR(ftr) && island_room != NULL) { - if (mNpc_CheckFtrIsIslandBestFtr(ftr) == TRUE) { - int idx = mNpc_GetIslandFtrIdx(ftr); - int mem_idx = mNpc_CheckIslandNpcRoomFtrIdx(idx); + animal = &Save_Get(island).animal; + island_room = mNpc_GetIslandRoomP(animal->id.npc_id); + island_ftr = Save_Get(island).animal.anmuni.island_ftr; + rsv_no = EMPTY_NO; + n = 0; + set = FALSE; - if (idx != -1 && mem_idx != -1) { - Anmmem_c* memory = &Save_Get(island).animal.memories[mem_idx]; - u16* have_bitfield_p = &memory->memuni.island.have_bitfield; - u16 have_bitfield = have_bitfield_p[0] & ~(1 << idx); - have_bitfield_p[0] = have_bitfield; - set = TRUE; - } - } - else { - for (i = 0; i < mNpc_ISLAND_FTR_SAVE_NUM; i++) { - for (j = 0; j < mRmTp_DIRECT_NUM; j++) { - mActor_name_t ftr_rot = aMR_FurnitureFg_to_FurnitureFgWithDirect(ftr, j); + if (ITEM_IS_FTR(ftr) && island_room != NULL) { + if (mNpc_CheckFtrIsIslandBestFtr(ftr) == TRUE) { + int idx = mNpc_GetIslandFtrIdx(ftr); + int mem_idx = mNpc_CheckIslandNpcRoomFtrIdx(idx); - if (ftr_rot == island_ftr[i]) { - rsv_no = RSV_ISLAND_FTR0 + i * mRmTp_DIRECT_NUM; - island_ftr[i] = EMPTY_NO; - break; - } - } - - if (rsv_no != EMPTY_NO) { - break; - } - } - - if (rsv_no != EMPTY_NO) { - for (i = 0; i < UT_TOTAL_NUM; i++) { - if (ITEM_IS_FTR(*island_room)) { - n++; - } - else if (*island_room >= RSV_ISLAND_FTR0 && *island_room <= RSV_ISLAND_FTR15) { - variant = -1; - - for (j = 0; j < mRmTp_DIRECT_NUM; j++) { - if (*island_room == (mActor_name_t)(rsv_no + j)) { - variant = 1; - break; - } - } - - if (variant != -1) { - int mem_idx = mNpc_CheckIslandNpcRoomFtrIdx(n); - - if (mem_idx != -1) { + if (idx != -1 && mem_idx != -1) { Anmmem_c* memory = &Save_Get(island).animal.memories[mem_idx]; u16* have_bitfield_p = &memory->memuni.island.have_bitfield; - u16 have_bitfield = have_bitfield_p[0] & ~(1 << n); + u16 have_bitfield = have_bitfield_p[0] & ~(1 << idx); have_bitfield_p[0] = have_bitfield; set = TRUE; + } + } else { + for (i = 0; i < mNpc_ISLAND_FTR_SAVE_NUM; i++) { + for (j = 0; j < mRmTp_DIRECT_NUM; j++) { + mActor_name_t ftr_rot = aMR_FurnitureFg_to_FurnitureFgWithDirect(ftr, j); - break; - } + if (ftr_rot == island_ftr[i]) { + rsv_no = RSV_ISLAND_FTR0 + i * mRmTp_DIRECT_NUM; + island_ftr[i] = EMPTY_NO; + break; + } + } + + if (rsv_no != EMPTY_NO) { + break; + } } - n++; - } + if (rsv_no != EMPTY_NO) { + for (i = 0; i < UT_TOTAL_NUM; i++) { + if (ITEM_IS_FTR(*island_room)) { + n++; + } else if (*island_room >= RSV_ISLAND_FTR0 && *island_room <= RSV_ISLAND_FTR15) { + variant = -1; - if (n == mNpc_ISLAND_FTR_NUM) { - break; - } + for (j = 0; j < mRmTp_DIRECT_NUM; j++) { + if (*island_room == (mActor_name_t)(rsv_no + j)) { + variant = 1; + break; + } + } - island_room++; + if (variant != -1) { + int mem_idx = mNpc_CheckIslandNpcRoomFtrIdx(n); + + if (mem_idx != -1) { + Anmmem_c* memory = &Save_Get(island).animal.memories[mem_idx]; + u16* have_bitfield_p = &memory->memuni.island.have_bitfield; + u16 have_bitfield = have_bitfield_p[0] & ~(1 << n); + have_bitfield_p[0] = have_bitfield; + set = TRUE; + + break; + } + } + + n++; + } + + if (n == mNpc_ISLAND_FTR_NUM) { + break; + } + + island_room++; + } + } } - } } - } - return set; + return set; } extern int mNpc_EraseIslandFtr_keep(mActor_name_t ftr) { - int n; - Animal_c* animal; - mNpc_Island_Ftr_c* island_ftr_p; - mActor_name_t* island_room; - mActor_name_t* trade_list; - int set; - mActor_name_t rsv_no; - int i; - int j; + int n; + Animal_c* animal; + mNpc_Island_Ftr_c* island_ftr_p; + mActor_name_t* island_room; + mActor_name_t* trade_list; + int set; + mActor_name_t rsv_no; + int i; + int j; - animal = &Save_Get(island).animal; - island_ftr_p = &l_mnpc_island_ftr; - island_room = mNpc_GetIslandRoomP(animal->id.npc_id); - trade_list = l_mnpc_island_ftr.trade_list; - rsv_no = EMPTY_NO; - n = 0; - set = FALSE; - - if (ITEM_IS_FTR(ftr) && island_room != NULL) { - if (mNpc_CheckFtrIsIslandBestFtr(ftr) == TRUE) { - int idx = mNpc_GetIslandFtrIdx(ftr); + animal = &Save_Get(island).animal; + island_ftr_p = &l_mnpc_island_ftr; + island_room = mNpc_GetIslandRoomP(animal->id.npc_id); + trade_list = l_mnpc_island_ftr.trade_list; + rsv_no = EMPTY_NO; + n = 0; + set = FALSE; - if (idx >= 0 && idx < mNpc_ISLAND_FTR_NUM && ((island_ftr_p->set_ftr_bitfield >> idx) & 1) == 1) { - u16* set_ftr_bitfield_p = &island_ftr_p->set_ftr_bitfield; - u16 set_bitfield = set_ftr_bitfield_p[0] & ~(1 << idx); - set_ftr_bitfield_p[0] = set_bitfield; - set = TRUE; - } - } - else { - for (i = 0; i < mNpc_ISLAND_FTR_SAVE_NUM; i++) { - for (j = 0; j < mRmTp_DIRECT_NUM; j++) { - mActor_name_t ftr_rot = aMR_FurnitureFg_to_FurnitureFgWithDirect(ftr, j); + if (ITEM_IS_FTR(ftr) && island_room != NULL) { + if (mNpc_CheckFtrIsIslandBestFtr(ftr) == TRUE) { + int idx = mNpc_GetIslandFtrIdx(ftr); - if (ftr_rot == trade_list[i]) { - rsv_no = RSV_ISLAND_FTR0 + i * mRmTp_DIRECT_NUM; - trade_list[i] = EMPTY_NO; - break; - } - } + if (idx >= 0 && idx < mNpc_ISLAND_FTR_NUM && ((island_ftr_p->set_ftr_bitfield >> idx) & 1) == 1) { + u16* set_ftr_bitfield_p = &island_ftr_p->set_ftr_bitfield; + u16 set_bitfield = set_ftr_bitfield_p[0] & ~(1 << idx); + set_ftr_bitfield_p[0] = set_bitfield; + set = TRUE; + } + } else { + for (i = 0; i < mNpc_ISLAND_FTR_SAVE_NUM; i++) { + for (j = 0; j < mRmTp_DIRECT_NUM; j++) { + mActor_name_t ftr_rot = aMR_FurnitureFg_to_FurnitureFgWithDirect(ftr, j); - if (rsv_no != EMPTY_NO) { - break; - } - } + if (ftr_rot == trade_list[i]) { + rsv_no = RSV_ISLAND_FTR0 + i * mRmTp_DIRECT_NUM; + trade_list[i] = EMPTY_NO; + break; + } + } - if (rsv_no != EMPTY_NO) { - for (i = 0; i < UT_TOTAL_NUM; i++) { - if (ITEM_IS_FTR(*island_room)) { - n++; - } - else if (*island_room >= RSV_ISLAND_FTR0 && *island_room <= RSV_ISLAND_FTR15) { - int variant = -1; - - for (j = 0; j < mRmTp_DIRECT_NUM; j++) { - if (*island_room == (mActor_name_t)(rsv_no + j)) { - variant = 1; - break; - } + if (rsv_no != EMPTY_NO) { + break; + } } - if (variant != -1 && n >= 0 && n < mNpc_ISLAND_FTR_NUM && ((island_ftr_p->set_ftr_bitfield >> n) & 1) == 1) { - u16* set_ftr_bitfield_p = &island_ftr_p->set_ftr_bitfield; - u16 set_bitfield = set_ftr_bitfield_p[0] & ~(1 << n); - set_ftr_bitfield_p[0] = set_bitfield; - set = TRUE; + if (rsv_no != EMPTY_NO) { + for (i = 0; i < UT_TOTAL_NUM; i++) { + if (ITEM_IS_FTR(*island_room)) { + n++; + } else if (*island_room >= RSV_ISLAND_FTR0 && *island_room <= RSV_ISLAND_FTR15) { + int variant = -1; - break; + for (j = 0; j < mRmTp_DIRECT_NUM; j++) { + if (*island_room == (mActor_name_t)(rsv_no + j)) { + variant = 1; + break; + } + } + + if (variant != -1 && n >= 0 && n < mNpc_ISLAND_FTR_NUM && + ((island_ftr_p->set_ftr_bitfield >> n) & 1) == 1) { + u16* set_ftr_bitfield_p = &island_ftr_p->set_ftr_bitfield; + u16 set_bitfield = set_ftr_bitfield_p[0] & ~(1 << n); + set_ftr_bitfield_p[0] = set_bitfield; + set = TRUE; + + break; + } + + n++; + } + + if (n == mNpc_ISLAND_FTR_NUM) { + break; + } + + island_room++; + } } - - n++; - } - - if (n == mNpc_ISLAND_FTR_NUM) { - break; - } - - island_room++; } - } } - } - return set; + return set; } typedef struct island_present_ftr_s { - PersonalID_c pid; - mActor_name_t present; + PersonalID_c pid; + mActor_name_t present; } mNpc_IslandPresentFtr_c; static mNpc_IslandPresentFtr_c l_mnpc_island_present_ftr; static void mNpc_ClearIslandPresentFtrInfo_common(mNpc_IslandPresentFtr_c* info) { - mPr_ClearPersonalID(&info->pid); - info->present = EMPTY_NO; + mPr_ClearPersonalID(&info->pid); + info->present = EMPTY_NO; } extern void mNpc_ClearIslandPresentFtrInfo() { - mNpc_ClearIslandPresentFtrInfo_common(&l_mnpc_island_present_ftr); + mNpc_ClearIslandPresentFtrInfo_common(&l_mnpc_island_present_ftr); } extern void mNpc_SetIslandPresentFtr() { - Animal_c* animal; - AnmPersonalID_c* anm_id; - mNpc_IslandPresentFtr_c* present_ftr_p; - Anmmem_c* memory; - int ftr_num; - mActor_name_t* island_room; - int selected; - int n; - int i; + Animal_c* animal; + AnmPersonalID_c* anm_id; + mNpc_IslandPresentFtr_c* present_ftr_p; + Anmmem_c* memory; + int ftr_num; + mActor_name_t* island_room; + int selected; + int n; + int i; - ftr_num = 0; - n = 0; - animal = &Save_Get(island).animal; - anm_id = &Save_Get(island).animal.id; - memory = Save_Get(island).animal.memories; - present_ftr_p = &l_mnpc_island_present_ftr; + ftr_num = 0; + n = 0; + animal = &Save_Get(island).animal; + anm_id = &Save_Get(island).animal.id; + memory = Save_Get(island).animal.memories; + present_ftr_p = &l_mnpc_island_present_ftr; - mNpc_ClearIslandPresentFtrInfo_common(present_ftr_p); + mNpc_ClearIslandPresentFtrInfo_common(present_ftr_p); - for (i = 0; i < mNpc_ISLAND_FTR_NUM; i++) { - if (mNpc_CheckIslandNpcRoomFtrIdx(i) != -1) { - ftr_num++; - } - } - - if (ftr_num > 1) { - selected = RANDOM(ftr_num); - island_room = mNpc_GetIslandRoomP(anm_id->npc_id); - - if (island_room != NULL) { - for (i = 0; i < UT_TOTAL_NUM; i++) { - if (ITEM_IS_FTR(*island_room)) { - if (mNpc_CheckIslandNpcRoomFtrIdx(n) != -1) { - if (selected == 0) { - int mem_idx; - - present_ftr_p->present = aMR_FurnitureFg_to_FurnitureFgWithDirect(*island_room, mRmTp_DIRECT_SOUTH); - mem_idx = mNpc_CheckIslandNpcRoomFtrIdx(n); - - if (mem_idx != -1) { - memory = &memory[mem_idx]; - mPr_CopyPersonalID(&present_ftr_p->pid, &memory->memory_player_id); - } - - break; - } - else { - selected--; - } - } - - n++; + for (i = 0; i < mNpc_ISLAND_FTR_NUM; i++) { + if (mNpc_CheckIslandNpcRoomFtrIdx(i) != -1) { + ftr_num++; } - else if (*island_room >= RSV_ISLAND_FTR0 && *island_room <= RSV_ISLAND_FTR15) { - if (mNpc_CheckIslandNpcRoomFtrIdx(n) != -1) { - if (selected == 0) { - int mem_idx; - - present_ftr_p->present = mNpc_getNormalFtr(*island_room, animal); - mem_idx = mNpc_CheckIslandNpcRoomFtrIdx(n); - - if (mem_idx != -1) { - memory = &memory[mem_idx]; - mPr_CopyPersonalID(&present_ftr_p->pid, &memory->memory_player_id); - } - - break; - } - else { - selected--; - } - } - - n++; - } - - island_room++; - } } - } - if (mNpc_CheckIslandPresentFtrIs() == TRUE) { - mNpc_EraseIslandFtr(mNpc_GetIslandPresentFtr()); - } + if (ftr_num > 1) { + selected = RANDOM(ftr_num); + island_room = mNpc_GetIslandRoomP(anm_id->npc_id); + + if (island_room != NULL) { + for (i = 0; i < UT_TOTAL_NUM; i++) { + if (ITEM_IS_FTR(*island_room)) { + if (mNpc_CheckIslandNpcRoomFtrIdx(n) != -1) { + if (selected == 0) { + int mem_idx; + + present_ftr_p->present = + aMR_FurnitureFg_to_FurnitureFgWithDirect(*island_room, mRmTp_DIRECT_SOUTH); + mem_idx = mNpc_CheckIslandNpcRoomFtrIdx(n); + + if (mem_idx != -1) { + memory = &memory[mem_idx]; + mPr_CopyPersonalID(&present_ftr_p->pid, &memory->memory_player_id); + } + + break; + } else { + selected--; + } + } + + n++; + } else if (*island_room >= RSV_ISLAND_FTR0 && *island_room <= RSV_ISLAND_FTR15) { + if (mNpc_CheckIslandNpcRoomFtrIdx(n) != -1) { + if (selected == 0) { + int mem_idx; + + present_ftr_p->present = mNpc_getNormalFtr(*island_room, animal); + mem_idx = mNpc_CheckIslandNpcRoomFtrIdx(n); + + if (mem_idx != -1) { + memory = &memory[mem_idx]; + mPr_CopyPersonalID(&present_ftr_p->pid, &memory->memory_player_id); + } + + break; + } else { + selected--; + } + } + + n++; + } + + island_room++; + } + } + } + + if (mNpc_CheckIslandPresentFtrIs() == TRUE) { + mNpc_EraseIslandFtr(mNpc_GetIslandPresentFtr()); + } } extern void mNpc_RestoreIslandPresentFtr() { - PersonalID_c* pid; - mActor_name_t present; - - if (mNpc_CheckIslandPresentFtrIs() == TRUE) { - present = mNpc_GetIslandPresentFtr(); - pid = mNpc_GetIslandPresentFtrPersonalID(); + PersonalID_c* pid; + mActor_name_t present; - if (present != EMPTY_NO && pid != NULL && mPr_NullCheckPersonalID(pid) == FALSE) { - mNpc_SetIslandFtr(pid, present); + if (mNpc_CheckIslandPresentFtrIs() == TRUE) { + present = mNpc_GetIslandPresentFtr(); + pid = mNpc_GetIslandPresentFtrPersonalID(); + + if (present != EMPTY_NO && pid != NULL && mPr_NullCheckPersonalID(pid) == FALSE) { + mNpc_SetIslandFtr(pid, present); + } } - } } extern int mNpc_GetIslandRoomFtrNum() { - int num = 0; - int i; + int num = 0; + int i; - for (i = 0; i < mNpc_ISLAND_FTR_NUM; i++) { - if (mNpc_CheckIslandNpcRoomFtrIdx(i) != -1) { - num++; + for (i = 0; i < mNpc_ISLAND_FTR_NUM; i++) { + if (mNpc_CheckIslandNpcRoomFtrIdx(i) != -1) { + num++; + } } - } - return num; + return num; } extern int mNpc_CheckIslandPresentFtrIs() { - mNpc_IslandPresentFtr_c* present_ftr_p = &l_mnpc_island_present_ftr; - int res = FALSE; + mNpc_IslandPresentFtr_c* present_ftr_p = &l_mnpc_island_present_ftr; + int res = FALSE; - if (present_ftr_p->present != EMPTY_NO && mPr_NullCheckPersonalID(&present_ftr_p->pid) == FALSE) { - res = TRUE; - } + if (present_ftr_p->present != EMPTY_NO && mPr_NullCheckPersonalID(&present_ftr_p->pid) == FALSE) { + res = TRUE; + } - return res; + return res; } extern mActor_name_t mNpc_GetIslandPresentFtr() { - return l_mnpc_island_present_ftr.present; + return l_mnpc_island_present_ftr.present; } extern PersonalID_c* mNpc_GetIslandPresentFtrPersonalID() { - PersonalID_c* pid = NULL; + PersonalID_c* pid = NULL; - if (mNpc_CheckIslandPresentFtrIs() == TRUE) { - pid = &l_mnpc_island_present_ftr.pid; - } + if (mNpc_CheckIslandPresentFtrIs() == TRUE) { + pid = &l_mnpc_island_present_ftr.pid; + } - return pid; + return pid; } extern mActor_name_t mNpc_GetRandomBestFtr() { - Animal_c* animal = &Save_Get(island).animal; - mActor_name_t* island_room = mNpc_GetIslandRoomP(animal->id.npc_id); - mNpc_Island_Ftr_c* island_ftr_p = &l_mnpc_island_ftr; - mActor_name_t* island_room_p = island_room; - int other_ftr_num = 0; - int n = 0; - mActor_name_t best_ftr = EMPTY_NO; - mActor_name_t present = mNpc_GetIslandPresentFtr(); - int selected; - int i; + Animal_c* animal = &Save_Get(island).animal; + mActor_name_t* island_room = mNpc_GetIslandRoomP(animal->id.npc_id); + mNpc_Island_Ftr_c* island_ftr_p = &l_mnpc_island_ftr; + mActor_name_t* island_room_p = island_room; + int other_ftr_num = 0; + int n = 0; + mActor_name_t best_ftr = EMPTY_NO; + mActor_name_t present = mNpc_GetIslandPresentFtr(); + int selected; + int i; - if (island_room != NULL) { - for (i = 0; i < UT_TOTAL_NUM; i++) { - if (ITEM_IS_FTR(*island_room)) { - if (n >= 0 && n < mNpc_ISLAND_FTR_NUM && - ((island_ftr_p->set_ftr_bitfield >> n) & 1) == 0 && - aMR_CorrespondFurniture(present, *island_room) == FALSE - ) { - other_ftr_num++; + if (island_room != NULL) { + for (i = 0; i < UT_TOTAL_NUM; i++) { + if (ITEM_IS_FTR(*island_room)) { + if (n >= 0 && n < mNpc_ISLAND_FTR_NUM && ((island_ftr_p->set_ftr_bitfield >> n) & 1) == 0 && + aMR_CorrespondFurniture(present, *island_room) == FALSE) { + other_ftr_num++; + } + + n++; + } else if (*island_room >= RSV_ISLAND_FTR0 && *island_room <= RSV_ISLAND_FTR15) { + n++; + } + + island_room++; } - n++; - } - else if (*island_room >= RSV_ISLAND_FTR0 && *island_room <= RSV_ISLAND_FTR15) { - n++; - } + island_room = island_room_p; + n = 0; - island_room++; + if (island_room != NULL && other_ftr_num > 0) { + selected = RANDOM(other_ftr_num); + + for (i = 0; i < UT_TOTAL_NUM; i++) { + if (ITEM_IS_FTR(*island_room)) { + if (n >= 0 && n < mNpc_ISLAND_FTR_NUM && ((island_ftr_p->set_ftr_bitfield >> n) & 1) == 0 && + aMR_CorrespondFurniture(present, *island_room) == FALSE) { + if (selected == 0) { + best_ftr = aMR_FurnitureFg_to_FurnitureFgWithDirect(*island_room, mRmTp_DIRECT_SOUTH); + break; + } else { + selected--; + } + } + + n++; + } else if (*island_room >= RSV_ISLAND_FTR0 && *island_room <= RSV_ISLAND_FTR15) { + n++; + } + + island_room++; + } + } } - island_room = island_room_p; - n = 0; - - if (island_room != NULL && other_ftr_num > 0) { - selected = RANDOM(other_ftr_num); - - for (i = 0; i < UT_TOTAL_NUM; i++) { - if (ITEM_IS_FTR(*island_room)) { - if (n >= 0 && n < mNpc_ISLAND_FTR_NUM && - ((island_ftr_p->set_ftr_bitfield >> n) & 1) == 0 && - aMR_CorrespondFurniture(present, *island_room) == FALSE - ) { - if (selected == 0) { - best_ftr = aMR_FurnitureFg_to_FurnitureFgWithDirect(*island_room, mRmTp_DIRECT_SOUTH); - break; - } - else { - selected--; - } - } - - n++; - } - else if (*island_room >= RSV_ISLAND_FTR0 && *island_room <= RSV_ISLAND_FTR15) { - n++; - } - - island_room++; - } - } - } - - return best_ftr; + return best_ftr; } extern Anmmem_c* mNpc_GetOtherBestFtr(PersonalID_c* pid, mActor_name_t* other_best_ftr, mActor_name_t exist_ftr) { - Animal_c* animal; - mActor_name_t* island_room; - Anmmem_c* memory; - Anmmem_c* memories; - mActor_name_t* island_room_p; - int other_ftr_num; - int n; - int mem_idx; - int i; + Animal_c* animal; + mActor_name_t* island_room; + Anmmem_c* memory; + Anmmem_c* memories; + mActor_name_t* island_room_p; + int other_ftr_num; + int n; + int mem_idx; + int i; - animal = &Save_Get(island).animal; - memories = Save_Get(island).animal.memories; - memory = NULL; - island_room = mNpc_GetIslandRoomP(animal->id.npc_id); - island_room_p = island_room; - other_ftr_num = 0; - n = 0; - - if (island_room != NULL && other_best_ftr != NULL) { - other_best_ftr[0] = EMPTY_NO; - mem_idx = mNpc_GetAnimalMemoryIdx(pid, memories, ANIMAL_MEMORY_NUM); - - for (i = 0; i < UT_TOTAL_NUM; i++) { - if (ITEM_IS_FTR(*island_room)) { - if (aMR_CorrespondFurniture(*island_room, exist_ftr) == FALSE) { - int ftr_idx = mNpc_CheckIslandNpcRoomFtrIdx(n); - - /* The item must not have been gifted by the current player */ - if (ftr_idx != -1 && ftr_idx != mem_idx) { - other_ftr_num++; - } - } - - n++; - } - else if (*island_room >= RSV_ISLAND_FTR0 && *island_room <= RSV_ISLAND_FTR15) { - n++; - } - - island_room++; - } - - island_room = island_room_p; + animal = &Save_Get(island).animal; + memories = Save_Get(island).animal.memories; + memory = NULL; + island_room = mNpc_GetIslandRoomP(animal->id.npc_id); + island_room_p = island_room; + other_ftr_num = 0; n = 0; - if (island_room != NULL && other_ftr_num > 0) { - int selected = RANDOM(other_ftr_num); + if (island_room != NULL && other_best_ftr != NULL) { + other_best_ftr[0] = EMPTY_NO; + mem_idx = mNpc_GetAnimalMemoryIdx(pid, memories, ANIMAL_MEMORY_NUM); - for (i = 0; i < UT_TOTAL_NUM; i++) { - if (ITEM_IS_FTR(*island_room)) { - if (aMR_CorrespondFurniture(*island_room, exist_ftr) == FALSE) { - int ftr_idx = mNpc_CheckIslandNpcRoomFtrIdx(n); - - /* The item must not have been gifted by the current player */ - if (ftr_idx != -1 && ftr_idx != mem_idx) { - if (selected == 0) { - other_best_ftr[0] = aMR_FurnitureFg_to_FurnitureFgWithDirect(*island_room, mRmTp_DIRECT_SOUTH); - memory = &memories[ftr_idx]; /* Memory of the other player who gave it */ - break; - } - else { - selected--; - } + for (i = 0; i < UT_TOTAL_NUM; i++) { + if (ITEM_IS_FTR(*island_room)) { + if (aMR_CorrespondFurniture(*island_room, exist_ftr) == FALSE) { + int ftr_idx = mNpc_CheckIslandNpcRoomFtrIdx(n); + + /* The item must not have been gifted by the current player */ + if (ftr_idx != -1 && ftr_idx != mem_idx) { + other_ftr_num++; + } + } + + n++; + } else if (*island_room >= RSV_ISLAND_FTR0 && *island_room <= RSV_ISLAND_FTR15) { + n++; } - } - n++; - } - else if (*island_room >= RSV_ISLAND_FTR0 && *island_room <= RSV_ISLAND_FTR15) { - n++; + island_room++; } - island_room++; - } + island_room = island_room_p; + n = 0; + + if (island_room != NULL && other_ftr_num > 0) { + int selected = RANDOM(other_ftr_num); + + for (i = 0; i < UT_TOTAL_NUM; i++) { + if (ITEM_IS_FTR(*island_room)) { + if (aMR_CorrespondFurniture(*island_room, exist_ftr) == FALSE) { + int ftr_idx = mNpc_CheckIslandNpcRoomFtrIdx(n); + + /* The item must not have been gifted by the current player */ + if (ftr_idx != -1 && ftr_idx != mem_idx) { + if (selected == 0) { + other_best_ftr[0] = + aMR_FurnitureFg_to_FurnitureFgWithDirect(*island_room, mRmTp_DIRECT_SOUTH); + memory = &memories[ftr_idx]; /* Memory of the other player who gave it */ + break; + } else { + selected--; + } + } + } + + n++; + } else if (*island_room >= RSV_ISLAND_FTR0 && *island_room <= RSV_ISLAND_FTR15) { + n++; + } + + island_room++; + } + } } - } - return memory; + return memory; } extern mActor_name_t mNpc_GetPlayerBestFtr(PersonalID_c* pid, mActor_name_t exist_ftr) { - AnmPersonalID_c* anm_id; - Anmmem_c* memories; - mActor_name_t* island_room; - mActor_name_t* island_room_p; - int mem_idx; - int other_ftr_num; - int n; - int selected; - int i; - mActor_name_t best_ftr; + AnmPersonalID_c* anm_id; + Anmmem_c* memories; + mActor_name_t* island_room; + mActor_name_t* island_room_p; + int mem_idx; + int other_ftr_num; + int n; + int selected; + int i; + mActor_name_t best_ftr; - anm_id = &Save_Get(island).animal.id; - memories = Save_Get(island).animal.memories; - island_room = mNpc_GetIslandRoomP(anm_id->npc_id); - other_ftr_num = 0; - n = 0; - best_ftr = EMPTY_NO; - island_room_p = island_room; + anm_id = &Save_Get(island).animal.id; + memories = Save_Get(island).animal.memories; + island_room = mNpc_GetIslandRoomP(anm_id->npc_id); + other_ftr_num = 0; + n = 0; + best_ftr = EMPTY_NO; + island_room_p = island_room; - if (island_room != NULL && pid != NULL) { - mem_idx = mNpc_GetAnimalMemoryIdx(pid, memories, ANIMAL_MEMORY_NUM); + if (island_room != NULL && pid != NULL) { + mem_idx = mNpc_GetAnimalMemoryIdx(pid, memories, ANIMAL_MEMORY_NUM); - if (mem_idx != -1) { - for (i = 0; i < UT_TOTAL_NUM; i++) { - if (ITEM_IS_FTR(*island_room)) { - if (aMR_CorrespondFurniture(*island_room, exist_ftr) == FALSE) { - int ftr_idx = mNpc_CheckIslandNpcRoomFtrIdx(n); - - /* The item must have been gifted by the current player */ - if (ftr_idx == mem_idx) { - other_ftr_num++; - } - } + if (mem_idx != -1) { + for (i = 0; i < UT_TOTAL_NUM; i++) { + if (ITEM_IS_FTR(*island_room)) { + if (aMR_CorrespondFurniture(*island_room, exist_ftr) == FALSE) { + int ftr_idx = mNpc_CheckIslandNpcRoomFtrIdx(n); - n++; - } - else if (*island_room >= RSV_ISLAND_FTR0 && *island_room <= RSV_ISLAND_FTR15) { - n++; - } + /* The item must have been gifted by the current player */ + if (ftr_idx == mem_idx) { + other_ftr_num++; + } + } - island_room++; - } - - n = 0; - - if (island_room_p != NULL && other_ftr_num > 0) { - selected = RANDOM(other_ftr_num); - island_room = island_room_p; - - for (i = 0; i < UT_TOTAL_NUM; i++) { - if (ITEM_IS_FTR(*island_room)) { - if (aMR_CorrespondFurniture(*island_room, exist_ftr) == FALSE) { - int ftr_idx = mNpc_CheckIslandNpcRoomFtrIdx(n); - - /* The item must have been gifted by the current player */ - if (ftr_idx == mem_idx) { - if (selected == 0) { - best_ftr = aMR_FurnitureFg_to_FurnitureFgWithDirect(*island_room, mRmTp_DIRECT_SOUTH); - break; + n++; + } else if (*island_room >= RSV_ISLAND_FTR0 && *island_room <= RSV_ISLAND_FTR15) { + n++; } - else { - selected--; - } - } + + island_room++; } - n++; - } - else if (*island_room >= RSV_ISLAND_FTR0 && *island_room <= RSV_ISLAND_FTR15) { - n++; - } + n = 0; - island_room++; + if (island_room_p != NULL && other_ftr_num > 0) { + selected = RANDOM(other_ftr_num); + island_room = island_room_p; + + for (i = 0; i < UT_TOTAL_NUM; i++) { + if (ITEM_IS_FTR(*island_room)) { + if (aMR_CorrespondFurniture(*island_room, exist_ftr) == FALSE) { + int ftr_idx = mNpc_CheckIslandNpcRoomFtrIdx(n); + + /* The item must have been gifted by the current player */ + if (ftr_idx == mem_idx) { + if (selected == 0) { + best_ftr = + aMR_FurnitureFg_to_FurnitureFgWithDirect(*island_room, mRmTp_DIRECT_SOUTH); + break; + } else { + selected--; + } + } + } + + n++; + } else if (*island_room >= RSV_ISLAND_FTR0 && *island_room <= RSV_ISLAND_FTR15) { + n++; + } + + island_room++; + } + } } - } } - } - return best_ftr; + return best_ftr; } extern mActor_name_t mNpc_GetPlayerFtr(PersonalID_c* pid) { - Animal_c* animal = &Save_Get(island).animal; - mActor_name_t* island_room = mNpc_GetIslandRoomP(Save_Get(island).animal.id.npc_id); - mActor_name_t best_ftr = EMPTY_NO; - mActor_name_t* island_room_p = island_room; - int other_ftr_num = 0; - int n = 0; - int mem_idx = mNpc_GetAnimalMemoryIdx(pid, animal->memories, ANIMAL_MEMORY_NUM); - int selected; - int i; + Animal_c* animal = &Save_Get(island).animal; + mActor_name_t* island_room = mNpc_GetIslandRoomP(Save_Get(island).animal.id.npc_id); + mActor_name_t best_ftr = EMPTY_NO; + mActor_name_t* island_room_p = island_room; + int other_ftr_num = 0; + int n = 0; + int mem_idx = mNpc_GetAnimalMemoryIdx(pid, animal->memories, ANIMAL_MEMORY_NUM); + int selected; + int i; - if (island_room != NULL && mem_idx != -1) { - for (i = 0; i < UT_TOTAL_NUM; i++) { - if (ITEM_IS_FTR(*island_room) || (*island_room >= RSV_ISLAND_FTR0 && *island_room <= RSV_ISLAND_FTR15)) { - int ftr_idx = mNpc_CheckIslandNpcRoomFtrIdx(n); - - /* The item must have been gifted by the current player */ - if (ftr_idx == mem_idx) { - other_ftr_num++; - } + if (island_room != NULL && mem_idx != -1) { + for (i = 0; i < UT_TOTAL_NUM; i++) { + if (ITEM_IS_FTR(*island_room) || (*island_room >= RSV_ISLAND_FTR0 && *island_room <= RSV_ISLAND_FTR15)) { + int ftr_idx = mNpc_CheckIslandNpcRoomFtrIdx(n); - n++; - } + /* The item must have been gifted by the current player */ + if (ftr_idx == mem_idx) { + other_ftr_num++; + } - island_room++; - } - - island_room = island_room_p; - n = 0; - - if (island_room != NULL && other_ftr_num > 0) { - selected = RANDOM(other_ftr_num); - - for (i = 0; i < UT_TOTAL_NUM; i++) { - if (ITEM_IS_FTR(*island_room) || (*island_room >= RSV_ISLAND_FTR0 && *island_room <= RSV_ISLAND_FTR15)) { - int ftr_idx = mNpc_CheckIslandNpcRoomFtrIdx(n); - - /* The item must have been gifted by the current player */ - if (ftr_idx == mem_idx) { - if (selected == 0) { - mActor_name_t ftr = *island_room; - - if (ftr >= RSV_ISLAND_FTR0 && ftr <= RSV_ISLAND_FTR15) { - ftr = mNpc_getNormalFtr(ftr, animal); - } - - best_ftr = aMR_FurnitureFg_to_FurnitureFgWithDirect(ftr, mRmTp_DIRECT_SOUTH); - break; + n++; } - else { - selected--; - } - } - n++; + island_room++; } - island_room++; - } - } - } + island_room = island_room_p; + n = 0; - return best_ftr; + if (island_room != NULL && other_ftr_num > 0) { + selected = RANDOM(other_ftr_num); + + for (i = 0; i < UT_TOTAL_NUM; i++) { + if (ITEM_IS_FTR(*island_room) || + (*island_room >= RSV_ISLAND_FTR0 && *island_room <= RSV_ISLAND_FTR15)) { + int ftr_idx = mNpc_CheckIslandNpcRoomFtrIdx(n); + + /* The item must have been gifted by the current player */ + if (ftr_idx == mem_idx) { + if (selected == 0) { + mActor_name_t ftr = *island_room; + + if (ftr >= RSV_ISLAND_FTR0 && ftr <= RSV_ISLAND_FTR15) { + ftr = mNpc_getNormalFtr(ftr, animal); + } + + best_ftr = aMR_FurnitureFg_to_FurnitureFgWithDirect(ftr, mRmTp_DIRECT_SOUTH); + break; + } else { + selected--; + } + } + + n++; + } + + island_room++; + } + } + } + + return best_ftr; } static int mNpc_CheckIslandAnimalTableNo(mActor_name_t npc_id) { - int res = FALSE; + int res = FALSE; - if ( - ITEM_NAME_GET_TYPE(npc_id) == NAME_TYPE_NPC && - (npc_id & 0xFFF) < NPC_NUM && - npc_grow_list[npc_id & 0xFFF] == mNpc_GROW_ISLANDER - ) { - res = TRUE; - } + if (ITEM_NAME_GET_TYPE(npc_id) == NAME_TYPE_NPC && (npc_id & 0xFFF) < NPC_NUM && + npc_grow_list[npc_id & 0xFFF] == mNpc_GROW_ISLANDER) { + res = TRUE; + } - return res; + return res; } static int mNpc_CheckIslandAnimalID(AnmPersonalID_c* anm_id) { - int res = FALSE; + int res = FALSE; - if (anm_id != NULL && mNpc_CheckFreeAnimalPersonalID(anm_id) == FALSE) { - res = mNpc_CheckIslandAnimalTableNo(anm_id->npc_id); - } + if (anm_id != NULL && mNpc_CheckFreeAnimalPersonalID(anm_id) == FALSE) { + res = mNpc_CheckIslandAnimalTableNo(anm_id->npc_id); + } - return res; + return res; } extern int mNpc_CheckIslandAnimal(Animal_c* animal) { - int res = FALSE; + int res = FALSE; - if (animal != NULL) { - res = mNpc_CheckIslandAnimalID(&animal->id); - } + if (animal != NULL) { + res = mNpc_CheckIslandAnimalID(&animal->id); + } - return res; + return res; } static mActor_name_t l_mnpc_island_md_table[NPC_ISLANDER_NUM] = { - ITM_MINIDISK16, // K.K. Tango - ITM_MINIDISK08, // K.K. Aria - ITM_MINIDISK06, // K.K. Etude - ITM_MINIDISK33, // K.K. Soul - ITM_MINIDISK26, // K.K. Rock - ITM_MINIDISK15, // K.K. Ska - ITM_MINIDISK07, // K.K. Lullaby - ITM_MINIDISK05, // K.K. Fusion - ITM_MINIDISK43, // Comrade K.K. - ITM_MINIDISK09, // K.K. Samba - ITM_MINIDISK49, // Cafe K.K. - ITM_MINIDISK13, // K.K. Mambo - ITM_MINIDISK01, // K.K. March - ITM_MINIDISK44, // K.K. Lament - ITM_MINIDISK40, // K.K. Country - ITM_MINIDISK10, // K.K. Bossa - ITM_MINIDISK18, // Aloha K.K. - ITM_MINIDISK46 // K.K. Dirge + ITM_MINIDISK16, // K.K. Tango + ITM_MINIDISK08, // K.K. Aria + ITM_MINIDISK06, // K.K. Etude + ITM_MINIDISK33, // K.K. Soul + ITM_MINIDISK26, // K.K. Rock + ITM_MINIDISK15, // K.K. Ska + ITM_MINIDISK07, // K.K. Lullaby + ITM_MINIDISK05, // K.K. Fusion + ITM_MINIDISK43, // Comrade K.K. + ITM_MINIDISK09, // K.K. Samba + ITM_MINIDISK49, // Cafe K.K. + ITM_MINIDISK13, // K.K. Mambo + ITM_MINIDISK01, // K.K. March + ITM_MINIDISK44, // K.K. Lament + ITM_MINIDISK40, // K.K. Country + ITM_MINIDISK10, // K.K. Bossa + ITM_MINIDISK18, // Aloha K.K. + ITM_MINIDISK46 // K.K. Dirge }; extern u32 mNpc_GetMDIdx(mActor_name_t npc_id) { - mNpc_Island_Npc_Room_Data_c* room_data = l_island_npc_room_data; - u32 idx = 0; - int i; + mNpc_Island_Npc_Room_Data_c* room_data = l_island_npc_room_data; + u32 idx = 0; + int i; - for (i = 0; i < NPC_ISLANDER_NUM; i++) { - if (room_data->npc_id == npc_id) { - idx = (u16)(l_mnpc_island_md_table[i] - ITM_MINIDISK_START); - // TODO: Bug? missing break here + for (i = 0; i < NPC_ISLANDER_NUM; i++) { + if (room_data->npc_id == npc_id) { + idx = (u16)(l_mnpc_island_md_table[i] - ITM_MINIDISK_START); + // TODO: Bug? missing break here + } + + room_data++; } - room_data++; - } - - return idx; + return idx; } extern u32 mNpc_GetIslandMDIdx() { - return mNpc_GetMDIdx(Save_Get(island).animal.id.npc_id); + return mNpc_GetMDIdx(Save_Get(island).animal.id.npc_id); } static Mail_c l_npc_hp_mail; extern void mNpc_ClearHPMail(AnmHPMail_c* hp_mail, int count) { - bzero(hp_mail, count * sizeof(AnmHPMail_c)); + bzero(hp_mail, count * sizeof(AnmHPMail_c)); } extern void mNpc_AllClearHPMailPlayerIdx(int player_no) { - Animal_c* animal = Save_Get(animals); - int i; + Animal_c* animal = Save_Get(animals); + int i; - if (player_no >= 0 && player_no < PLAYER_NUM) { - for (i = 0; i < ANIMAL_NUM_MAX; i++) { - mNpc_ClearHPMail(&animal->hp_mail[player_no], 1); - animal++; + if (player_no >= 0 && player_no < PLAYER_NUM) { + for (i = 0; i < ANIMAL_NUM_MAX; i++) { + mNpc_ClearHPMail(&animal->hp_mail[player_no], 1); + animal++; + } } - } } extern int mNpc_ReceiveHPMail(Mail_c* mail) { - static u8 password[mMpswd_PASSWORD_DATA_LEN]; + static u8 password[mMpswd_PASSWORD_DATA_LEN]; - Animal_c* animal = Save_Get(animals); - AnmPersonalID_c anm_id; - int res = FALSE; - int private_idx = mPr_GetPrivateIdx(&mail->header.sender.personalID); + Animal_c* animal = Save_Get(animals); + AnmPersonalID_c anm_id; + int res = FALSE; + int private_idx = mPr_GetPrivateIdx(&mail->header.sender.personalID); - if (mail->header.sender.type == mMl_NAME_TYPE_PLAYER && private_idx >= 0 && private_idx < PLAYER_NUM) { - int is_password = mMpswd_restore_code(mail->content.body, password); + if (mail->header.sender.type == mMl_NAME_TYPE_PLAYER && private_idx >= 0 && private_idx < PLAYER_NUM) { + int is_password = mMpswd_restore_code(mail->content.body, password); - if (is_password == TRUE && mMl_get_npcinfo_from_mail_name(&anm_id, &mail->header.recipient) == TRUE) { - int npc_idx = mNpc_SearchAnimalinfo(animal, anm_id.npc_id, ANIMAL_NUM_MAX); + if (is_password == TRUE && mMl_get_npcinfo_from_mail_name(&anm_id, &mail->header.recipient) == TRUE) { + int npc_idx = mNpc_SearchAnimalinfo(animal, anm_id.npc_id, ANIMAL_NUM_MAX); - if (npc_idx != -1) { - animal = &animal[npc_idx]; + if (npc_idx != -1) { + animal = &animal[npc_idx]; - if (animal != NULL) { - /* @BUG - the final byte of the password should not be stored. */ - #ifndef BUGFIXES - bcopy(password, animal->hp_mail[private_idx].password, mMpswd_PASSWORD_DATA_LEN); - #else - bcopy(password, animal->hp_mail[private_idx].password, sizeof(animal->hp_mail[private_idx].password)); - #endif - lbRTC_TimeCopy(&animal->hp_mail[private_idx].receive_time, Common_GetPointer(time.rtc_time)); - res = TRUE; + if (animal != NULL) { +/* @BUG - the final byte of the password should not be stored. */ +#ifndef BUGFIXES + bcopy(password, animal->hp_mail[private_idx].password, mMpswd_PASSWORD_DATA_LEN); +#else + bcopy(password, animal->hp_mail[private_idx].password, + sizeof(animal->hp_mail[private_idx].password)); +#endif + lbRTC_TimeCopy(&animal->hp_mail[private_idx].receive_time, Common_GetPointer(time.rtc_time)); + res = TRUE; + } + } } - } } - } - return res; + return res; } static int mNpc_SendHPMailNum_famicom(PersonalID_c* pid, AnmPersonalID_c* anm_id, mMpswd_password_c* password) { - static u8 name_str[mIN_ITEM_NAME_LEN]; + static u8 name_str[mIN_ITEM_NAME_LEN]; - Mail_c* hp_mail = &l_npc_hp_mail; - int mail_no; - mActor_name_t present = EMPTY_NO; - int res = FALSE; + Mail_c* hp_mail = &l_npc_hp_mail; + int mail_no; + mActor_name_t present = EMPTY_NO; + int res = FALSE; - if (mPO_get_keep_mail_sum() < mPO_MAIL_STORAGE_SIZE) { - mMl_clear_mail(hp_mail); + if (mPO_get_keep_mail_sum() < mPO_MAIL_STORAGE_SIZE) { + mMl_clear_mail(hp_mail); - if ( - password->hit_rate_index == 1 && // hit rate index must be 1 - mMpswd_password_zuru_check(password) == FALSE && // checksum is valid - mMpswd_check_present(password) == TRUE && // present is valid - mMpswd_check_name(password) == TRUE // player & town name match - ) { - mail_no = 0x24A + anm_id->looks; // valid password - present = password->item; - } - else { - mail_no = 0x250 + anm_id->looks; // invalid password + if (password->hit_rate_index == 1 && // hit rate index must be 1 + mMpswd_password_zuru_check(password) == FALSE && // checksum is valid + mMpswd_check_present(password) == TRUE && // present is valid + mMpswd_check_name(password) == TRUE // player & town name match + ) { + mail_no = 0x24A + anm_id->looks; // valid password + present = password->item; + } else { + mail_no = 0x250 + anm_id->looks; // invalid password + } + + mHandbill_Set_free_str(mHandbill_FREE_STR0, pid->player_name, PLAYER_NAME_LEN); + mNpc_ClearBufSpace1(name_str, ANIMAL_NAME_LEN); + mNpc_GetNpcWorldNameAnm(name_str, anm_id); + mHandbill_Set_free_str(mHandbill_FREE_STR1, name_str, ANIMAL_NAME_LEN); + mHandbill_Set_free_str(mHandbill_FREE_STR2, password->str1, PLAYER_NAME_LEN); + mHandbill_Set_free_str(mHandbill_FREE_STR3, password->str0, PLAYER_NAME_LEN); + + if (present != EMPTY_NO) { + mNpc_ClearBufSpace1(name_str, mIN_ITEM_NAME_LEN); + mIN_copy_name_str(name_str, present); + mHandbill_Set_free_str(mHandbill_FREE_STR4, name_str, mIN_ITEM_NAME_LEN); + } + + /* Why is free string 6 the same as free string 1? */ + mNpc_ClearBufSpace1(name_str, ANIMAL_NAME_LEN); + mNpc_GetNpcWorldNameAnm(name_str, anm_id); + mHandbill_Set_free_str(mHandbill_FREE_STR6, name_str, ANIMAL_NAME_LEN); + + mNpc_LoadMailDataCommon2(hp_mail, pid, anm_id, present, mNpc_GetPaperType(), mail_no); + res = mPO_receipt_proc(hp_mail, mPO_SENDTYPE_MAIL); } - mHandbill_Set_free_str(mHandbill_FREE_STR0, pid->player_name, PLAYER_NAME_LEN); - mNpc_ClearBufSpace1(name_str, ANIMAL_NAME_LEN); - mNpc_GetNpcWorldNameAnm(name_str, anm_id); - mHandbill_Set_free_str(mHandbill_FREE_STR1, name_str, ANIMAL_NAME_LEN); - mHandbill_Set_free_str(mHandbill_FREE_STR2, password->str1, PLAYER_NAME_LEN); - mHandbill_Set_free_str(mHandbill_FREE_STR3, password->str0, PLAYER_NAME_LEN); - - if (present != EMPTY_NO) { - mNpc_ClearBufSpace1(name_str, mIN_ITEM_NAME_LEN); - mIN_copy_name_str(name_str, present); - mHandbill_Set_free_str(mHandbill_FREE_STR4, name_str, mIN_ITEM_NAME_LEN); - } - - /* Why is free string 6 the same as free string 1? */ - mNpc_ClearBufSpace1(name_str, ANIMAL_NAME_LEN); - mNpc_GetNpcWorldNameAnm(name_str, anm_id); - mHandbill_Set_free_str(mHandbill_FREE_STR6, name_str, ANIMAL_NAME_LEN); - - mNpc_LoadMailDataCommon2(hp_mail, pid, anm_id, present, mNpc_GetPaperType(), mail_no); - res = mPO_receipt_proc(hp_mail, mPO_SENDTYPE_MAIL); - } - - return res; + return res; } static int mNpc_SendHPMailNum_popular(PersonalID_c* pid, AnmPersonalID_c* anm_id, mMpswd_password_c* password) { - static u8 name_str[mIN_ITEM_NAME_LEN]; - static u8 submenu_name_str[mIN_ITEM_NAME_LEN]; + static u8 name_str[mIN_ITEM_NAME_LEN]; + static u8 submenu_name_str[mIN_ITEM_NAME_LEN]; - Mail_c* hp_mail = &l_npc_hp_mail; - mActor_name_t npc_id; - int mail_no; - mActor_name_t present; - u8 valid; - u8 special; - mActor_name_t target_npc_id; - int npc_idx; - int looks; - int res; + Mail_c* hp_mail = &l_npc_hp_mail; + mActor_name_t npc_id; + int mail_no; + mActor_name_t present; + u8 valid; + u8 special; + mActor_name_t target_npc_id; + int npc_idx; + int looks; + int res; - present = EMPTY_NO; - res = FALSE; - valid = FALSE; - special = FALSE; + present = EMPTY_NO; + res = FALSE; + valid = FALSE; + special = FALSE; - if (mPO_get_keep_mail_sum() < mPO_MAIL_STORAGE_SIZE) { - mMl_clear_mail(hp_mail); + if (mPO_get_keep_mail_sum() < mPO_MAIL_STORAGE_SIZE) { + mMl_clear_mail(hp_mail); - if ( - mMpswd_password_zuru_check(password) == FALSE && // checksum is valid - mMpswd_check_npc_code(password) == TRUE && // valid npc code - mMpswd_check_present(password) == TRUE && // present is valid - mMpswd_check_name(password) == TRUE // player & town name match - ) { - /* Valid password */ - mNpc_ClearBufSpace1(name_str, ANIMAL_NAME_LEN); - mNpc_ClearBufSpace1(submenu_name_str, ANIMAL_NAME_LEN); + if (mMpswd_password_zuru_check(password) == FALSE && // checksum is valid + mMpswd_check_npc_code(password) == TRUE && // valid npc code + mMpswd_check_present(password) == TRUE && // present is valid + mMpswd_check_name(password) == TRUE // player & town name match + ) { + /* Valid password */ + mNpc_ClearBufSpace1(name_str, ANIMAL_NAME_LEN); + mNpc_ClearBufSpace1(submenu_name_str, ANIMAL_NAME_LEN); - if (password->npc_type == mMpswd_NPCTYPE_NORMAL) { - mActor_name_t npc_id = anm_id->npc_id; - - npc_idx = npc_id & 0xFFF; - target_npc_id = NPC_START | password->npc_code; - looks = mNpc_GetLooks(target_npc_id); + if (password->npc_type == mMpswd_NPCTYPE_NORMAL) { + mActor_name_t npc_id = anm_id->npc_id; - if (npc_idx == password->npc_code) { - mail_no = 0x256 + looks; - } - else if (mNpc_CheckIslandAnimalTableNo(target_npc_id) == TRUE) { - mail_no = 0x262 + looks; - } - else { - looks = mNpc_GetLooks(target_npc_id); // re-calling the function? - mail_no = 0x25C + looks; + npc_idx = npc_id & 0xFFF; + target_npc_id = NPC_START | password->npc_code; + looks = mNpc_GetLooks(target_npc_id); + + if (npc_idx == password->npc_code) { + mail_no = 0x256 + looks; + } else if (mNpc_CheckIslandAnimalTableNo(target_npc_id) == TRUE) { + mail_no = 0x262 + looks; + } else { + looks = mNpc_GetLooks(target_npc_id); // re-calling the function? + mail_no = 0x25C + looks; + } + + mNpc_GetNpcWorldNameTableNo(name_str, NPC_START | password->npc_code); + mNpc_GetNpcWorldNameTableNo(submenu_name_str, NPC_START | password->npc_code); + valid = TRUE; + } else { + /* Special NPC */ + mail_no = 0x268 + password->npc_code; + npc_id = mMpswd_get_sp_npc_num(password->npc_code); + mNpc_GetActorWorldName(name_str, npc_id); + mNpc_GetActorWorldName(submenu_name_str, npc_id); + + /* Leftover from JP, replace ちん (-san) honorific with spaces */ + if (submenu_name_str[4] == 0x0A && submenu_name_str[5] == 0xC3) { + submenu_name_str[4] = CHAR_SPACE; + submenu_name_str[5] = CHAR_SPACE; + } + + valid = TRUE; + special = TRUE; + } + + if (password->item != RSV_NO) { + present = password->item; + } + } else { + /* Invalid password */ + mail_no = 0x288 + anm_id->looks; } - mNpc_GetNpcWorldNameTableNo(name_str, NPC_START | password->npc_code); - mNpc_GetNpcWorldNameTableNo(submenu_name_str, NPC_START | password->npc_code); - valid = TRUE; - } - else { - /* Special NPC */ - mail_no = 0x268 + password->npc_code; - npc_id = mMpswd_get_sp_npc_num(password->npc_code); - mNpc_GetActorWorldName(name_str, npc_id); - mNpc_GetActorWorldName(submenu_name_str, npc_id); + mHandbill_Set_free_str(mHandbill_FREE_STR0, pid->player_name, PLAYER_NAME_LEN); + mHandbill_Set_free_str(mHandbill_FREE_STR1, name_str, ANIMAL_NAME_LEN); + mHandbill_Set_free_str(mHandbill_FREE_STR2, password->str1, PLAYER_NAME_LEN); + mHandbill_Set_free_str(mHandbill_FREE_STR3, password->str0, PLAYER_NAME_LEN); - /* Leftover from JP, replace ちん (-san) honorific with spaces */ - if (submenu_name_str[4] == 0x0A && submenu_name_str[5] == 0xC3) { - submenu_name_str[4] = CHAR_SPACE; - submenu_name_str[5] = CHAR_SPACE; + if (present != EMPTY_NO) { + mNpc_ClearBufSpace1(name_str, mIN_ITEM_NAME_LEN); + mIN_copy_name_str(name_str, present); + mHandbill_Set_free_str(mHandbill_FREE_STR4, name_str, mIN_ITEM_NAME_LEN); } - valid = TRUE; - special = TRUE; - } + /* Why is free string 6 the same as free string 1? */ + mNpc_ClearBufSpace1(name_str, ANIMAL_NAME_LEN); + mNpc_GetNpcWorldNameAnm(name_str, anm_id); + mHandbill_Set_free_str(mHandbill_FREE_STR6, name_str, ANIMAL_NAME_LEN); + mNpc_LoadMailDataCommon2(hp_mail, pid, anm_id, present, mNpc_GetPaperType(), mail_no); - if (password->item != RSV_NO) { - present = password->item; - } - } - else { - /* Invalid password */ - mail_no = 0x288 + anm_id->looks; + if (valid == TRUE) { + // Overwrite the sender name with the name of the password's embedded villager name + bcopy(submenu_name_str, hp_mail->header.sender.personalID.player_name, PLAYER_NAME_LEN); + bcopy(pid->player_name, hp_mail->header.recipient.personalID.player_name, PLAYER_NAME_LEN); + + if (special == TRUE) { + hp_mail->content.mail_type = mMl_TYPE_SPNPC_PASSWORD; + } + } + + res = mPO_receipt_proc(hp_mail, mPO_SENDTYPE_MAIL); } - mHandbill_Set_free_str(mHandbill_FREE_STR0, pid->player_name, PLAYER_NAME_LEN); - mHandbill_Set_free_str(mHandbill_FREE_STR1, name_str, ANIMAL_NAME_LEN); - mHandbill_Set_free_str(mHandbill_FREE_STR2, password->str1, PLAYER_NAME_LEN); - mHandbill_Set_free_str(mHandbill_FREE_STR3, password->str0, PLAYER_NAME_LEN); - - if (present != EMPTY_NO) { - mNpc_ClearBufSpace1(name_str, mIN_ITEM_NAME_LEN); - mIN_copy_name_str(name_str, present); - mHandbill_Set_free_str(mHandbill_FREE_STR4, name_str, mIN_ITEM_NAME_LEN); - } - - /* Why is free string 6 the same as free string 1? */ - mNpc_ClearBufSpace1(name_str, ANIMAL_NAME_LEN); - mNpc_GetNpcWorldNameAnm(name_str, anm_id); - mHandbill_Set_free_str(mHandbill_FREE_STR6, name_str, ANIMAL_NAME_LEN); - - mNpc_LoadMailDataCommon2(hp_mail, pid, anm_id, present, mNpc_GetPaperType(), mail_no); - - if (valid == TRUE) { - // Overwrite the sender name with the name of the password's embedded villager name - bcopy(submenu_name_str, hp_mail->header.sender.personalID.player_name, PLAYER_NAME_LEN); - bcopy(pid->player_name, hp_mail->header.recipient.personalID.player_name, PLAYER_NAME_LEN); - - if (special == TRUE) { - hp_mail->content.mail_type = mMl_TYPE_SPNPC_PASSWORD; - } - } - - res = mPO_receipt_proc(hp_mail, mPO_SENDTYPE_MAIL); - } - - return res; + return res; } static int mNpc_CheckHit_Rate(u8 hitrate, int n) { - u8 perfect_bit = 0xFF; - int res = FALSE; - int i; + u8 perfect_bit = 0xFF; + int res = FALSE; + int i; - for (i = 0; i < n; i++) { - perfect_bit &= ~(1 << i); - } + for (i = 0; i < n; i++) { + perfect_bit &= ~(1 << i); + } - if ((hitrate & perfect_bit) == 0) { - res = TRUE; - } + if ((hitrate & perfect_bit) == 0) { + res = TRUE; + } - return res; + return res; } static int mNpc_GetHit(u8 hitrate) { - static u8 prob_table[] = { 80, 60, 30, 0, 100 }; + static u8 prob_table[] = { 80, 60, 30, 0, 100 }; - int res = FALSE; - - if (hitrate < ARRAY_COUNT(prob_table)) { - u8 hit = RANDOM(100); + int res = FALSE; - if (hit < prob_table[hitrate]) { - res = TRUE; + if (hitrate < ARRAY_COUNT(prob_table)) { + u8 hit = RANDOM(100); + + if (hit < prob_table[hitrate]) { + res = TRUE; + } } - } - return res; + return res; } static void mNPC_get_gobi_str_from_name(u8* str, mActor_name_t npc_id) { - if (str != NULL && ITEM_NAME_GET_TYPE(npc_id) == NAME_TYPE_NPC) { - int idx = npc_id & 0xFFF; + if (str != NULL && ITEM_NAME_GET_TYPE(npc_id) == NAME_TYPE_NPC) { + int idx = npc_id & 0xFFF; - /* @BUG - devs used && instead of || */ - #ifndef BUGFIXES - if (idx < 0 && idx >= NPC_NUM) { - #else - if (idx < 0 || idx >= NPC_NUM) { - #endif - idx = 0; +/* @BUG - devs used && instead of || */ +#ifndef BUGFIXES + if (idx < 0 && idx >= NPC_NUM) { +#else + if (idx < 0 || idx >= NPC_NUM) { +#endif + idx = 0; + } + + mString_Load_StringFromRom(str, ANIMAL_CATCHPHRASE_LEN, npc_def_list[idx].catchphrase_str_idx); } - - mString_Load_StringFromRom(str, ANIMAL_CATCHPHRASE_LEN, npc_def_list[idx].catchphrase_str_idx); - } } static int mNpc_GetHit_cardE(u8 hitrate) { - static int prob_table[] = { 80, 60, 40, 20 }; + static int prob_table[] = { 80, 60, 40, 20 }; - int res = FALSE; + int res = FALSE; - if (hitrate < ARRAY_COUNT(prob_table)) { - u8 hit = RANDOM(100); + if (hitrate < ARRAY_COUNT(prob_table)) { + u8 hit = RANDOM(100); - if (hit < prob_table[hitrate]) { - res = TRUE; + if (hit < prob_table[hitrate]) { + res = TRUE; + } } - } - return res; + return res; } static int mNpc_SendHPMailNum_cardE(PersonalID_c* pid, AnmPersonalID_c* anm_id, mMpswd_password_c* password) { - static u8 submenu_name_str[mIN_ITEM_NAME_LEN]; - static u8 name_str[mIN_ITEM_NAME_LEN]; - static u8 gobi_str[ANIMAL_CATCHPHRASE_LEN]; + static u8 submenu_name_str[mIN_ITEM_NAME_LEN]; + static u8 name_str[mIN_ITEM_NAME_LEN]; + static u8 gobi_str[ANIMAL_CATCHPHRASE_LEN]; - Mail_c* hp_mail = &l_npc_hp_mail; - int mail_no; - mActor_name_t present = EMPTY_NO; - int res = FALSE; - u8 valid = FALSE; - u8 special = FALSE; - int famicom_hit; + Mail_c* hp_mail = &l_npc_hp_mail; + int mail_no; + mActor_name_t present = EMPTY_NO; + int res = FALSE; + u8 valid = FALSE; + u8 special = FALSE; + int famicom_hit; - if (mPO_get_keep_mail_sum() < mPO_MAIL_STORAGE_SIZE) { - mMl_clear_mail(hp_mail); + if (mPO_get_keep_mail_sum() < mPO_MAIL_STORAGE_SIZE) { + mMl_clear_mail(hp_mail); - if ( - mMpswd_password_zuru_check(password) == FALSE && // checksum is valid - mMpswd_check_present(password) == TRUE && // present is valid - mMpswd_check_npc_code(password) == TRUE // valid npc code - ) { - /* Valid password */ - famicom_hit = FALSE; - mNpc_ClearBufSpace1(submenu_name_str, ANIMAL_NAME_LEN); - mNpc_ClearBufSpace1(name_str, ANIMAL_NAME_LEN); - mNpc_ClearBufSpace1(gobi_str, ANIMAL_CATCHPHRASE_LEN); - - if (password->npc_type == mMpswd_NPCTYPE_NORMAL) { - mActor_name_t target_npc_id = NPC_START | password->npc_code; - int villager_idx = mNpc_SearchAnimalinfo(Save_Get(animals), target_npc_id, ANIMAL_NUM_MAX); - int islander_idx = mNpc_SearchAnimalinfo(&Save_Get(island).animal, target_npc_id, 1); - - if ( - (villager_idx != -1 || islander_idx != -1) && - ( - mNpc_GetAnimalMemoryIdx(&Common_Get(now_private)->player_ID, Save_Get(animals[villager_idx]).memories, ANIMAL_MEMORY_NUM) != -1 || - mNpc_GetAnimalMemoryIdx(&Common_Get(now_private)->player_ID, Save_Get(island).animal.memories, ANIMAL_MEMORY_NUM) != -1 - ) + if (mMpswd_password_zuru_check(password) == FALSE && // checksum is valid + mMpswd_check_present(password) == TRUE && // present is valid + mMpswd_check_npc_code(password) == TRUE // valid npc code ) { - int looks = mNpc_GetLooks(target_npc_id); + /* Valid password */ + famicom_hit = FALSE; + mNpc_ClearBufSpace1(submenu_name_str, ANIMAL_NAME_LEN); + mNpc_ClearBufSpace1(name_str, ANIMAL_NAME_LEN); + mNpc_ClearBufSpace1(gobi_str, ANIMAL_CATCHPHRASE_LEN); - if (mNpc_GetHit_cardE(password->hit_rate_index)) { - famicom_hit = TRUE; - mail_no = mNpc_CheckIslandAnimalTableNo(target_npc_id) == TRUE ? 0x3CA + looks : 0x3C4 + looks; - mNpc_GetNpcWorldNameTableNo(name_str, NPC_START | password->npc_code); - mNpc_GetNpcWorldNameTableNo(submenu_name_str, NPC_START | password->npc_code); - valid = TRUE; - } + if (password->npc_type == mMpswd_NPCTYPE_NORMAL) { + mActor_name_t target_npc_id = NPC_START | password->npc_code; + int villager_idx = mNpc_SearchAnimalinfo(Save_Get(animals), target_npc_id, ANIMAL_NUM_MAX); + int islander_idx = mNpc_SearchAnimalinfo(&Save_Get(island).animal, target_npc_id, 1); + + if ((villager_idx != -1 || islander_idx != -1) && + (mNpc_GetAnimalMemoryIdx(&Common_Get(now_private)->player_ID, + Save_Get(animals[villager_idx]).memories, ANIMAL_MEMORY_NUM) != -1 || + mNpc_GetAnimalMemoryIdx(&Common_Get(now_private)->player_ID, Save_Get(island).animal.memories, + ANIMAL_MEMORY_NUM) != -1)) { + int looks = mNpc_GetLooks(target_npc_id); + + if (mNpc_GetHit_cardE(password->hit_rate_index)) { + famicom_hit = TRUE; + mail_no = mNpc_CheckIslandAnimalTableNo(target_npc_id) == TRUE ? 0x3CA + looks : 0x3C4 + looks; + mNpc_GetNpcWorldNameTableNo(name_str, NPC_START | password->npc_code); + mNpc_GetNpcWorldNameTableNo(submenu_name_str, NPC_START | password->npc_code); + valid = TRUE; + } + } + + if (famicom_hit == FALSE) { + mail_no = 0x2B2 + password->npc_code; + mNpc_GetNpcWorldNameTableNo(name_str, NPC_START | password->npc_code); + mNpc_GetNpcWorldNameTableNo(submenu_name_str, NPC_START | password->npc_code); + valid = TRUE; + } + + mNPC_get_gobi_str_from_name(gobi_str, target_npc_id); + mHandbill_Set_free_str(mHandbill_FREE_STR5, gobi_str, ANIMAL_CATCHPHRASE_LEN); + } else { + /* Special NPC */ + mActor_name_t npc_id; + + mail_no = 0x39E + password->npc_code; + npc_id = mMpswd_get_sp_npc_num(password->npc_code); + mNpc_GetActorWorldName(name_str, npc_id); + mNpc_GetActorWorldName(submenu_name_str, npc_id); + + /* Leftover from JP, replace ちん (-san) honorific with spaces */ + if (submenu_name_str[4] == 0x0A && submenu_name_str[5] == 0xC3) { + submenu_name_str[4] = CHAR_SPACE; + submenu_name_str[5] = CHAR_SPACE; + } + + valid = TRUE; + special = TRUE; + } + + if (famicom_hit == FALSE && mMpswd_check_present(password) == TRUE) { + mActor_name_t item = password->item; + + if (item == RSV_NO) { + present = EMPTY_NO; + } else { + present = item; + } + } else if (famicom_hit == TRUE) { + int famicom_idx = RANDOM_F(8); + + present = mRmTp_FtrIdx2FtrItemNo(pswd_famicom_list[famicom_idx], mRmTp_DIRECT_SOUTH); + } + } else { + /* Invalid password */ + mail_no = 0x3BE + anm_id->looks; } - if (famicom_hit == FALSE) { - mail_no = 0x2B2 + password->npc_code; - mNpc_GetNpcWorldNameTableNo(name_str, NPC_START | password->npc_code); - mNpc_GetNpcWorldNameTableNo(submenu_name_str, NPC_START | password->npc_code); - valid = TRUE; + mHandbill_Set_free_str(mHandbill_FREE_STR0, pid->player_name, PLAYER_NAME_LEN); + mHandbill_Set_free_str(mHandbill_FREE_STR1, name_str, ANIMAL_NAME_LEN); + mHandbill_Set_free_str(mHandbill_FREE_STR2, password->str1, PLAYER_NAME_LEN); + mHandbill_Set_free_str(mHandbill_FREE_STR3, password->str0, PLAYER_NAME_LEN); + + if (present != EMPTY_NO) { + mNpc_ClearBufSpace1(name_str, mIN_ITEM_NAME_LEN); + mIN_copy_name_str(name_str, present); + mHandbill_Set_free_str(mHandbill_FREE_STR4, name_str, mIN_ITEM_NAME_LEN); } - mNPC_get_gobi_str_from_name(gobi_str, target_npc_id); - mHandbill_Set_free_str(mHandbill_FREE_STR5, gobi_str, ANIMAL_CATCHPHRASE_LEN); - } - else { - /* Special NPC */ - mActor_name_t npc_id; + /* Why is free string 6 the same as free string 1? */ + mNpc_ClearBufSpace1(name_str, ANIMAL_NAME_LEN); + mNpc_GetNpcWorldNameAnm(name_str, anm_id); + mHandbill_Set_free_str(mHandbill_FREE_STR6, name_str, ANIMAL_NAME_LEN); - mail_no = 0x39E + password->npc_code; - npc_id = mMpswd_get_sp_npc_num(password->npc_code); - mNpc_GetActorWorldName(name_str, npc_id); - mNpc_GetActorWorldName(submenu_name_str, npc_id); + mNpc_LoadMailDataCommon2(hp_mail, pid, anm_id, present, mNpc_GetPaperType(), mail_no); - /* Leftover from JP, replace ちん (-san) honorific with spaces */ - if (submenu_name_str[4] == 0x0A && submenu_name_str[5] == 0xC3) { - submenu_name_str[4] = CHAR_SPACE; - submenu_name_str[5] = CHAR_SPACE; + if (valid == TRUE) { + // Overwrite the sender name with the name of the password's embedded villager name + bcopy(submenu_name_str, hp_mail->header.sender.personalID.player_name, PLAYER_NAME_LEN); + bcopy(pid->player_name, hp_mail->header.recipient.personalID.player_name, PLAYER_NAME_LEN); + + if (special == TRUE) { + hp_mail->content.mail_type = mMl_TYPE_SPNPC_PASSWORD; + } } - valid = TRUE; - special = TRUE; - } - - if (famicom_hit == FALSE && mMpswd_check_present(password) == TRUE) { - mActor_name_t item = password->item; - - if (item == RSV_NO) { - present = EMPTY_NO; - } - else { - present = item; - } - } - else if (famicom_hit == TRUE) { - int famicom_idx = RANDOM_F(8); - - present = mRmTp_FtrIdx2FtrItemNo(pswd_famicom_list[famicom_idx], mRmTp_DIRECT_SOUTH); - } - } - else { - /* Invalid password */ - mail_no = 0x3BE + anm_id->looks; + res = mPO_receipt_proc(hp_mail, mPO_SENDTYPE_MAIL); } - mHandbill_Set_free_str(mHandbill_FREE_STR0, pid->player_name, PLAYER_NAME_LEN); - mHandbill_Set_free_str(mHandbill_FREE_STR1, name_str, ANIMAL_NAME_LEN); - mHandbill_Set_free_str(mHandbill_FREE_STR2, password->str1, PLAYER_NAME_LEN); - mHandbill_Set_free_str(mHandbill_FREE_STR3, password->str0, PLAYER_NAME_LEN); - - if (present != EMPTY_NO) { - mNpc_ClearBufSpace1(name_str, mIN_ITEM_NAME_LEN); - mIN_copy_name_str(name_str, present); - mHandbill_Set_free_str(mHandbill_FREE_STR4, name_str, mIN_ITEM_NAME_LEN); - } - - /* Why is free string 6 the same as free string 1? */ - mNpc_ClearBufSpace1(name_str, ANIMAL_NAME_LEN); - mNpc_GetNpcWorldNameAnm(name_str, anm_id); - mHandbill_Set_free_str(mHandbill_FREE_STR6, name_str, ANIMAL_NAME_LEN); - - mNpc_LoadMailDataCommon2(hp_mail, pid, anm_id, present, mNpc_GetPaperType(), mail_no); - - if (valid == TRUE) { - // Overwrite the sender name with the name of the password's embedded villager name - bcopy(submenu_name_str, hp_mail->header.sender.personalID.player_name, PLAYER_NAME_LEN); - bcopy(pid->player_name, hp_mail->header.recipient.personalID.player_name, PLAYER_NAME_LEN); - - if (special == TRUE) { - hp_mail->content.mail_type = mMl_TYPE_SPNPC_PASSWORD; - } - } - - res = mPO_receipt_proc(hp_mail, mPO_SENDTYPE_MAIL); - } - - return res; + return res; } static int mNpc_SendHPMailNum_NG(PersonalID_c* pid, AnmPersonalID_c* anm_id) { - static u8 name_str[mIN_ITEM_NAME_LEN]; + static u8 name_str[mIN_ITEM_NAME_LEN]; - Mail_c* hp_mail = &l_npc_hp_mail; - int mail_no; - int res = FALSE; + Mail_c* hp_mail = &l_npc_hp_mail; + int mail_no; + int res = FALSE; - if (anm_id != NULL && mPO_get_keep_mail_sum() < mPO_MAIL_STORAGE_SIZE) { - mMl_clear_mail(hp_mail); - mail_no = 0x3BE + anm_id->looks; - mHandbill_Set_free_str(mHandbill_FREE_STR0, pid->player_name, PLAYER_NAME_LEN); - mNpc_ClearBufSpace1(name_str, ANIMAL_NAME_LEN); - mNpc_GetNpcWorldNameAnm(name_str, anm_id); - mHandbill_Set_free_str(mHandbill_FREE_STR6, name_str, ANIMAL_NAME_LEN); - mNpc_LoadMailDataCommon2(hp_mail, pid, anm_id, EMPTY_NO, mNpc_GetPaperType(), mail_no); - res = mPO_receipt_proc(hp_mail, mPO_SENDTYPE_MAIL); - } + if (anm_id != NULL && mPO_get_keep_mail_sum() < mPO_MAIL_STORAGE_SIZE) { + mMl_clear_mail(hp_mail); + mail_no = 0x3BE + anm_id->looks; + mHandbill_Set_free_str(mHandbill_FREE_STR0, pid->player_name, PLAYER_NAME_LEN); + mNpc_ClearBufSpace1(name_str, ANIMAL_NAME_LEN); + mNpc_GetNpcWorldNameAnm(name_str, anm_id); + mHandbill_Set_free_str(mHandbill_FREE_STR6, name_str, ANIMAL_NAME_LEN); + mNpc_LoadMailDataCommon2(hp_mail, pid, anm_id, EMPTY_NO, mNpc_GetPaperType(), mail_no); + res = mPO_receipt_proc(hp_mail, mPO_SENDTYPE_MAIL); + } - return res; + return res; } static int mNpc_SendHPMailNum_cardE_mini_user_password_common(PersonalID_c* pid, AnmPersonalID_c* anm_id) { - static u8 name_str[ANIMAL_NAME_LEN]; + static u8 name_str[ANIMAL_NAME_LEN]; - Mail_c* hp_mail = &l_npc_hp_mail; - int looks = anm_id->looks; - int res = FALSE; + Mail_c* hp_mail = &l_npc_hp_mail; + int looks = anm_id->looks; + int res = FALSE; - if (mPO_get_keep_mail_sum() < mPO_MAIL_STORAGE_SIZE && looks < mNpc_LOOKS_NUM) { - mMl_clear_mail(hp_mail); - mNpc_ClearBufSpace1(name_str, ANIMAL_NAME_LEN); - mNpc_GetNpcWorldNameAnm(name_str, anm_id); - mHandbill_Set_free_str(mHandbill_FREE_STR6, name_str, ANIMAL_NAME_LEN); - mNpc_LoadMailDataCommon2(hp_mail, pid, anm_id, EMPTY_NO, mNpc_GetPaperType(), 0x3D0 + looks); - res = mPO_receipt_proc(hp_mail, mPO_SENDTYPE_MAIL); - } + if (mPO_get_keep_mail_sum() < mPO_MAIL_STORAGE_SIZE && looks < mNpc_LOOKS_NUM) { + mMl_clear_mail(hp_mail); + mNpc_ClearBufSpace1(name_str, ANIMAL_NAME_LEN); + mNpc_GetNpcWorldNameAnm(name_str, anm_id); + mHandbill_Set_free_str(mHandbill_FREE_STR6, name_str, ANIMAL_NAME_LEN); + mNpc_LoadMailDataCommon2(hp_mail, pid, anm_id, EMPTY_NO, mNpc_GetPaperType(), 0x3D0 + looks); + res = mPO_receipt_proc(hp_mail, mPO_SENDTYPE_MAIL); + } - return res; + return res; } static int mNpc_SendHPMailNum_user_password(PersonalID_c* pid, AnmPersonalID_c* anm_id, mMpswd_password_c* password) { - if ( - mMpswd_password_zuru_check(password) == FALSE && - mMpswd_check_present(password) == TRUE && - mMpswd_check_name(password) == TRUE - ) { - return mNpc_SendHPMailNum_cardE_mini_user_password_common(pid, anm_id); - } - - return mNpc_SendHPMailNum_NG(pid, anm_id); + if (mMpswd_password_zuru_check(password) == FALSE && mMpswd_check_present(password) == TRUE && + mMpswd_check_name(password) == TRUE) { + return mNpc_SendHPMailNum_cardE_mini_user_password_common(pid, anm_id); + } + + return mNpc_SendHPMailNum_NG(pid, anm_id); } static int mNpc_SendHPMailNum_cardE_mini(PersonalID_c* pid, AnmPersonalID_c* anm_id, mMpswd_password_c* password) { - if (mMpswd_password_zuru_check(password) == FALSE) { - return mNpc_SendHPMailNum_cardE_mini_user_password_common(pid, anm_id); - } - - return mNpc_SendHPMailNum_NG(pid, anm_id); + if (mMpswd_password_zuru_check(password) == FALSE) { + return mNpc_SendHPMailNum_cardE_mini_user_password_common(pid, anm_id); + } + + return mNpc_SendHPMailNum_NG(pid, anm_id); } static int mNpc_SendHPMailNum_magazine(PersonalID_c* pid, AnmPersonalID_c* anm_id, mMpswd_password_c* password) { - static u8 name_str[mIN_ITEM_NAME_LEN]; + static u8 name_str[mIN_ITEM_NAME_LEN]; - Mail_c* hp_mail = &l_npc_hp_mail; - int mail_no; - mActor_name_t present = EMPTY_NO; - int res = FALSE; + Mail_c* hp_mail = &l_npc_hp_mail; + int mail_no; + mActor_name_t present = EMPTY_NO; + int res = FALSE; - if (mPO_get_keep_mail_sum() < mPO_MAIL_STORAGE_SIZE) { - mMl_clear_mail(hp_mail); + if (mPO_get_keep_mail_sum() < mPO_MAIL_STORAGE_SIZE) { + mMl_clear_mail(hp_mail); - if ( - mNpc_CheckHit_Rate(password->hit_rate_index, 3) == TRUE && // hitrate index is valid - mMpswd_password_zuru_check(password) == FALSE && // checksum is valid - mMpswd_check_present(password) == TRUE // present is valid - ) { - /* Valid password */ - if (mNpc_GetHit(password->hit_rate_index) == TRUE) { - /* Player "won" */ - mail_no = 0x2A0 + anm_id->looks; + if (mNpc_CheckHit_Rate(password->hit_rate_index, 3) == TRUE && // hitrate index is valid + mMpswd_password_zuru_check(password) == FALSE && // checksum is valid + mMpswd_check_present(password) == TRUE // present is valid + ) { + /* Valid password */ + if (mNpc_GetHit(password->hit_rate_index) == TRUE) { + /* Player "won" */ + mail_no = 0x2A0 + anm_id->looks; - if (password->item != RSV_NO) { - present = password->item; + if (password->item != RSV_NO) { + present = password->item; + } + } else { + /* Player did not "win" */ + mail_no = 0x2A6 + anm_id->looks; + } + } else { + /* Invalid password */ + mail_no = 0x2AC + anm_id->looks; } - } - else { - /* Player did not "win" */ - mail_no = 0x2A6 + anm_id->looks; - } - } - else { - /* Invalid password */ - mail_no = 0x2AC + anm_id->looks; + + mHandbill_Set_free_str(mHandbill_FREE_STR0, pid->player_name, PLAYER_NAME_LEN); + mNpc_ClearBufSpace1(name_str, ANIMAL_NAME_LEN); + mNpc_GetNpcWorldNameAnm(name_str, anm_id); + mHandbill_Set_free_str(mHandbill_FREE_STR1, name_str, ANIMAL_NAME_LEN); + mHandbill_Set_free_str(mHandbill_FREE_STR2, password->str1, PLAYER_NAME_LEN); + mHandbill_Set_free_str(mHandbill_FREE_STR3, password->str0, PLAYER_NAME_LEN); + + if (present != EMPTY_NO) { + mNpc_ClearBufSpace1(name_str, mIN_ITEM_NAME_LEN); + mIN_copy_name_str(name_str, present); + mHandbill_Set_free_str(mHandbill_FREE_STR4, name_str, mIN_ITEM_NAME_LEN); + } + + /* Why is free string 6 the same as free string 1? */ + mNpc_ClearBufSpace1(name_str, ANIMAL_NAME_LEN); + mNpc_GetNpcWorldNameAnm(name_str, anm_id); + mHandbill_Set_free_str(mHandbill_FREE_STR6, name_str, ANIMAL_NAME_LEN); + + mNpc_LoadMailDataCommon2(hp_mail, pid, anm_id, present, mNpc_GetPaperType(), mail_no); + res = mPO_receipt_proc(hp_mail, mPO_SENDTYPE_MAIL); } - mHandbill_Set_free_str(mHandbill_FREE_STR0, pid->player_name, PLAYER_NAME_LEN); - mNpc_ClearBufSpace1(name_str, ANIMAL_NAME_LEN); - mNpc_GetNpcWorldNameAnm(name_str, anm_id); - mHandbill_Set_free_str(mHandbill_FREE_STR1, name_str, ANIMAL_NAME_LEN); - mHandbill_Set_free_str(mHandbill_FREE_STR2, password->str1, PLAYER_NAME_LEN); - mHandbill_Set_free_str(mHandbill_FREE_STR3, password->str0, PLAYER_NAME_LEN); - - if (present != EMPTY_NO) { - mNpc_ClearBufSpace1(name_str, mIN_ITEM_NAME_LEN); - mIN_copy_name_str(name_str, present); - mHandbill_Set_free_str(mHandbill_FREE_STR4, name_str, mIN_ITEM_NAME_LEN); - } - - /* Why is free string 6 the same as free string 1? */ - mNpc_ClearBufSpace1(name_str, ANIMAL_NAME_LEN); - mNpc_GetNpcWorldNameAnm(name_str, anm_id); - mHandbill_Set_free_str(mHandbill_FREE_STR6, name_str, ANIMAL_NAME_LEN); - - mNpc_LoadMailDataCommon2(hp_mail, pid, anm_id, present, mNpc_GetPaperType(), mail_no); - res = mPO_receipt_proc(hp_mail, mPO_SENDTYPE_MAIL); - } - - return res; + return res; } typedef int (*mNpc_HPMAIL_SEND_PROC)(PersonalID_c*, AnmPersonalID_c*, mMpswd_password_c*); static int mNpc_SendHPMail_analysis(PersonalID_c* pid, AnmPersonalID_c* anm_id, AnmHPMail_c* hp_mail) { - static mNpc_HPMAIL_SEND_PROC send_proc[mMpswd_CODETYPE_NUM] = { - &mNpc_SendHPMailNum_famicom, - &mNpc_SendHPMailNum_popular, - &mNpc_SendHPMailNum_cardE, - &mNpc_SendHPMailNum_magazine, - &mNpc_SendHPMailNum_user_password, - &mNpc_SendHPMailNum_cardE_mini - }; + static mNpc_HPMAIL_SEND_PROC send_proc[mMpswd_CODETYPE_NUM] = { + &mNpc_SendHPMailNum_famicom, &mNpc_SendHPMailNum_popular, &mNpc_SendHPMailNum_cardE, + &mNpc_SendHPMailNum_magazine, &mNpc_SendHPMailNum_user_password, &mNpc_SendHPMailNum_cardE_mini + }; - mMpswd_password_c password; + mMpswd_password_c password; - mMpswd_password(hp_mail->password, &password); + mMpswd_password(hp_mail->password, &password); - if (password.type < mMpswd_CODETYPE_NUM) { - return (*send_proc[password.type])(pid, anm_id, &password); - } + if (password.type < mMpswd_CODETYPE_NUM) { + return (*send_proc[password.type])(pid, anm_id, &password); + } - return mNpc_SendHPMailNum_NG(pid, anm_id); + return mNpc_SendHPMailNum_NG(pid, anm_id); } extern void mNpc_SendHPMail() { - Private_c* priv = Save_Get(private); - Private_c* priv_p; - Animal_c* animal = Save_Get(animals); - AnmHPMail_c* hp_mail; - lbRTC_time_c* rtc_time = Common_GetPointer(time.rtc_time); - int i; - int j; + Private_c* priv = Save_Get(private); + Private_c* priv_p; + Animal_c* animal = Save_Get(animals); + AnmHPMail_c* hp_mail; + lbRTC_time_c* rtc_time = Common_GetPointer(time.rtc_time); + int i; + int j; - for (i = 0; i < ANIMAL_NUM_MAX; i++) { - if (mNpc_CheckFreeAnimalPersonalID(&animal->id) == FALSE) { - hp_mail = animal->hp_mail; - priv_p = priv; + for (i = 0; i < ANIMAL_NUM_MAX; i++) { + if (mNpc_CheckFreeAnimalPersonalID(&animal->id) == FALSE) { + hp_mail = animal->hp_mail; + priv_p = priv; - for (j = 0; j < ANIMAL_HP_MAIL_NUM; j++) { - if (hp_mail->receive_time.year != 0 && hp_mail->receive_time.day != 0 && mPr_NullCheckPersonalID(&priv_p->player_ID) == FALSE) { - int days; + for (j = 0; j < ANIMAL_HP_MAIL_NUM; j++) { + if (hp_mail->receive_time.year != 0 && hp_mail->receive_time.day != 0 && + mPr_NullCheckPersonalID(&priv_p->player_ID) == FALSE) { + int days; - if (lbRTC_IsOverTime(&hp_mail->receive_time, rtc_time) == lbRTC_OVER) { - days = lbRTC_GetIntervalDays(&hp_mail->receive_time, rtc_time); - } - else { - days = lbRTC_GetIntervalDays(rtc_time, &hp_mail->receive_time); - } + if (lbRTC_IsOverTime(&hp_mail->receive_time, rtc_time) == lbRTC_OVER) { + days = lbRTC_GetIntervalDays(&hp_mail->receive_time, rtc_time); + } else { + days = lbRTC_GetIntervalDays(rtc_time, &hp_mail->receive_time); + } - if (days >= 1 && mNpc_SendHPMail_analysis(&priv_p->player_ID, &animal->id, hp_mail) == TRUE) { - mNpc_ClearHPMail(hp_mail, 1); - } + if (days >= 1 && mNpc_SendHPMail_analysis(&priv_p->player_ID, &animal->id, hp_mail) == TRUE) { + mNpc_ClearHPMail(hp_mail, 1); + } + } + + priv_p++; + hp_mail++; + } } - priv_p++; - hp_mail++; - } + animal++; } - - animal++; - } } extern void mNpc_PrintRemoveInfo(gfxprint_t* gfxprint) { - Animal_c* remove_anm = NULL; - Animal_c* in_anm = mNpc_GetInAnimalP(); - u8 remove_idx = Save_Get(remove_animal_idx); + Animal_c* remove_anm = NULL; + Animal_c* in_anm = mNpc_GetInAnimalP(); + u8 remove_idx = Save_Get(remove_animal_idx); - gfxprint_color(gfxprint, 200, 150, 50, 255); - gfxprint_locate8x8(gfxprint, 3, 10); + gfxprint_color(gfxprint, 200, 150, 50, 255); + gfxprint_locate8x8(gfxprint, 3, 10); - if (remove_idx < ANIMAL_NUM_MAX) { - remove_anm = Save_GetPointer(animals[remove_idx]); - } - - if (remove_anm != NULL) { - if (in_anm != NULL) { - gfxprint_printf(gfxprint, "%4x %3d %3d", remove_idx, remove_anm->id.name_id, in_anm->id.name_id); + if (remove_idx < ANIMAL_NUM_MAX) { + remove_anm = Save_GetPointer(animals[remove_idx]); } - else { - gfxprint_printf(gfxprint, "%4x %3d ---", remove_idx, remove_anm->id.name_id); + + if (remove_anm != NULL) { + if (in_anm != NULL) { + gfxprint_printf(gfxprint, "%4x %3d %3d", remove_idx, remove_anm->id.name_id, in_anm->id.name_id); + } else { + gfxprint_printf(gfxprint, "%4x %3d ---", remove_idx, remove_anm->id.name_id); + } + } else if (in_anm != NULL) { + gfxprint_printf(gfxprint, "%4x --- %3d", remove_idx, in_anm->id.name_id); + } else { + gfxprint_printf(gfxprint, "%4x --- ---", remove_idx); } - } - else if (in_anm != NULL) { - gfxprint_printf(gfxprint, "%4x --- %3d", remove_idx, in_anm->id.name_id); - } - else { - gfxprint_printf(gfxprint, "%4x --- ---", remove_idx); - } } static int l_mnpc_display = 0; typedef struct npc_add_debug_s { - int add_switch; - u16 memory; - u8 count; - u8 add_bit; - u8 edit_bit; - int mtype; - int disp_add; + int add_switch; + u16 memory; + u8 count; + u8 add_bit; + u8 edit_bit; + int mtype; + int disp_add; } mNpc_Add_Debug_c; static mNpc_Add_Debug_c l_mnpc_addd; @@ -7416,121 +7166,114 @@ static mNpc_Add_Debug_c l_mnpc_addd; /* @unused @fabricated */ extern void mNpc_set_addd_bit(int bit) { - l_mnpc_addd.add_bit |= (1 << bit); + l_mnpc_addd.add_bit |= (1 << bit); } /* @unused */ extern void mNpc_set_addd_edit_bit(int bit) { - l_mnpc_addd.edit_bit |= (1 << bit); + l_mnpc_addd.edit_bit |= (1 << bit); } /* @unused */ extern void mNpc_set_addd_edit_info(int mtype, int disp_add) { - l_mnpc_addd.mtype = mtype; - l_mnpc_addd.disp_add = disp_add; + l_mnpc_addd.mtype = mtype; + l_mnpc_addd.disp_add = disp_add; } /* @unused mNpc_set_addd_memory 1.2.5 size: 0x34 */ /* @unused mNpc_set_addd_count 1.2.5 size: 0x10 */ static void mNpc_PrintFriendship_fdebug_1(gfxprint_t* gfxprint) { - int add_switch = l_mnpc_addd.add_switch; - int i; - - gfxprint_color(gfxprint, 250, 100, 170, 255); - gfxprint_locate8x8(gfxprint, 3, 18); + int add_switch = l_mnpc_addd.add_switch; + int i; - if (add_switch == 0) { - gfxprint_printf(gfxprint, "----------------------- %d", l_mnpc_addd.add_switch); - } - else if (add_switch == 1) { - gfxprint_printf(gfxprint, "*********************** %d", l_mnpc_addd.add_switch); - } - else if (add_switch == 2) { - gfxprint_printf(gfxprint, ">>>>>>>>>>>>>>>>>>>>>>> %d", l_mnpc_addd.add_switch); - } - else { - gfxprint_printf(gfxprint, "%2d ", l_mnpc_addd.count); - for (i = 0; i < ANIMAL_NUM_MAX; i++) { - gfxprint_printf(gfxprint, "%1d", (l_mnpc_addd.memory >> i) & 1); + gfxprint_color(gfxprint, 250, 100, 170, 255); + gfxprint_locate8x8(gfxprint, 3, 18); + + if (add_switch == 0) { + gfxprint_printf(gfxprint, "----------------------- %d", l_mnpc_addd.add_switch); + } else if (add_switch == 1) { + gfxprint_printf(gfxprint, "*********************** %d", l_mnpc_addd.add_switch); + } else if (add_switch == 2) { + gfxprint_printf(gfxprint, ">>>>>>>>>>>>>>>>>>>>>>> %d", l_mnpc_addd.add_switch); + } else { + gfxprint_printf(gfxprint, "%2d ", l_mnpc_addd.count); + for (i = 0; i < ANIMAL_NUM_MAX; i++) { + gfxprint_printf(gfxprint, "%1d", (l_mnpc_addd.memory >> i) & 1); + } + + gfxprint_locate8x8(gfxprint, 3, 19); + gfxprint_printf(gfxprint, "add bit "); + for (i = 0; i < 8; i++) { + gfxprint_printf(gfxprint, "%1d", (l_mnpc_addd.add_bit >> i) & 1); + } + + gfxprint_printf(gfxprint, " edit bit "); + for (i = 0; i < 8; i++) { + gfxprint_printf(gfxprint, "%1d", (l_mnpc_addd.edit_bit >> i) & 1); + } + + gfxprint_locate8x8(gfxprint, 3, 20); + gfxprint_printf(gfxprint, "mtype %d disp_add 0x%x", l_mnpc_addd.mtype, l_mnpc_addd.disp_add); } - - gfxprint_locate8x8(gfxprint, 3, 19); - gfxprint_printf(gfxprint, "add bit "); - for (i = 0; i < 8; i++) { - gfxprint_printf(gfxprint, "%1d", (l_mnpc_addd.add_bit >> i) & 1); - } - - gfxprint_printf(gfxprint, " edit bit "); - for (i = 0; i < 8; i++) { - gfxprint_printf(gfxprint, "%1d", (l_mnpc_addd.edit_bit >> i) & 1); - } - - gfxprint_locate8x8(gfxprint, 3, 20); - gfxprint_printf(gfxprint, "mtype %d disp_add 0x%x", l_mnpc_addd.mtype, l_mnpc_addd.disp_add); - } } static int l_mnpc_animal_idx = -1; extern void mNpc_SetTalkAnimalIdx_fdebug(AnmPersonalID_c* anm_id) { - if (anm_id != NULL) { - l_mnpc_animal_idx = mNpc_SearchAnimalPersonalID(anm_id); - } + if (anm_id != NULL) { + l_mnpc_animal_idx = mNpc_SearchAnimalPersonalID(anm_id); + } } static void mNpc_PrintFriendship_fdebug_0(gfxprint_t* gfxprint) { - Anmmem_c* memory; - Private_c* priv; - int x = 3; - int y = 19; - int i; + Anmmem_c* memory; + Private_c* priv; + int x = 3; + int y = 19; + int i; - if (l_mnpc_animal_idx >= 0 && l_mnpc_animal_idx < ANIMAL_NUM_MAX) { - memory = Save_Get(animals[l_mnpc_animal_idx]).memories; + if (l_mnpc_animal_idx >= 0 && l_mnpc_animal_idx < ANIMAL_NUM_MAX) { + memory = Save_Get(animals[l_mnpc_animal_idx]).memories; - if (memory != NULL) { - gfxprint_color(gfxprint, 250, 100, 170, 255); - gfxprint_locate8x8(gfxprint, 3, 18); - priv = Common_Get(now_private); + if (memory != NULL) { + gfxprint_color(gfxprint, 250, 100, 170, 255); + gfxprint_locate8x8(gfxprint, 3, 18); + priv = Common_Get(now_private); - if (priv != NULL) { - gfxprint_printf(gfxprint, "%4x ", priv->player_ID.player_id); - } - else { - gfxprint_printf(gfxprint, "**** "); - } + if (priv != NULL) { + gfxprint_printf(gfxprint, "%4x ", priv->player_ID.player_id); + } else { + gfxprint_printf(gfxprint, "**** "); + } - gfxprint_color(gfxprint, 50, 150, 50, 255); + gfxprint_color(gfxprint, 50, 150, 50, 255); - for (i = 0; i < ANIMAL_MEMORY_NUM; i++) { - if (i == 4) { - y++; - x = 3; + for (i = 0; i < ANIMAL_MEMORY_NUM; i++) { + if (i == 4) { + y++; + x = 3; + } + + gfxprint_locate8x8(gfxprint, x, y); + if (mNpc_CheckFreeAnimalMemory(memory) == FALSE) { + gfxprint_printf(gfxprint, "%4x %3d ", memory->memory_player_id.player_id, memory->friendship); + } else { + gfxprint_printf(gfxprint, "**** *** "); + } + + memory++; + x += 9; + } } - - gfxprint_locate8x8(gfxprint, x, y); - if (mNpc_CheckFreeAnimalMemory(memory) == FALSE) { - gfxprint_printf(gfxprint, "%4x %3d ", memory->memory_player_id.player_id, memory->friendship); - } - else { - gfxprint_printf(gfxprint, "**** *** "); - } - - memory++; - x += 9; - } } - } } typedef void (*mNpc_PRINT_FRIENDSHIP_PROC)(gfxprint_t*); extern void mNpc_PrintFriendship_fdebug(gfxprint_t* gfxprint) { - static mNpc_PRINT_FRIENDSHIP_PROC print_proc[2] = { - &mNpc_PrintFriendship_fdebug_0, - &mNpc_PrintFriendship_fdebug_1 - }; + static mNpc_PRINT_FRIENDSHIP_PROC print_proc[2] = { &mNpc_PrintFriendship_fdebug_0, + &mNpc_PrintFriendship_fdebug_1 }; - (*print_proc[l_mnpc_display & 1])(gfxprint); + (*print_proc[l_mnpc_display & 1])(gfxprint); } diff --git a/src/m_play.c b/src/m_play.c index 667da5f4..70b41ef9 100644 --- a/src/m_play.c +++ b/src/m_play.c @@ -35,6 +35,8 @@ #include "m_trademark.h" #include "zurumode.h" #include "m_scene_table.h" +#include "m_player_lib.h" +#include "m_skin_matrix.h" u16 S_back_title_timer; u16 S_se_endcheck_timeout; diff --git a/src/m_player_call.c b/src/m_player_call.c index 1b010915..fb09332d 100644 --- a/src/m_player_call.c +++ b/src/m_player_call.c @@ -17,8 +17,8 @@ void Player_actor_draw_call(ACTOR* actor, GAME* game); ACTOR_PROFILE Player_Profile = { mAc_PROFILE_PLAYER, ACTOR_PART_PLAYER, - ACTOR_STATE_CAN_MOVE_IN_DEMO_SCENES | ACTOR_STATE_26 | ACTOR_STATE_25 | - ACTOR_STATE_NO_MOVE_WHILE_CULLED | ACTOR_STATE_NO_DRAW_WHILE_CULLED | ACTOR_STATE_2 | ACTOR_STATE_0, + ACTOR_STATE_CAN_MOVE_IN_DEMO_SCENES | ACTOR_STATE_26 | ACTOR_STATE_25 | ACTOR_STATE_NO_MOVE_WHILE_CULLED | + ACTOR_STATE_NO_DRAW_WHILE_CULLED | ACTOR_STATE_2 | ACTOR_STATE_0, EMPTY_NO, ACTOR_OBJ_BANK_KEEP, sizeof(PLAYER_ACTOR), @@ -29,16 +29,16 @@ ACTOR_PROFILE Player_Profile = { NULL, }; -void initfunc(GAME_PLAY* play){ +static void initfunc(GAME_PLAY* play) { Submenu* submenu = &play->submenu; - Player_actor_ct_func = mSM_ovlptr_dllcnv(&Player_actor_ct, submenu , 1); + Player_actor_ct_func = mSM_ovlptr_dllcnv(&Player_actor_ct, submenu, 1); Player_actor_dt_func = mSM_ovlptr_dllcnv(&Player_actor_dt, submenu, 1); - Player_actor_move_func = mSM_ovlptr_dllcnv(&Player_actor_move, submenu,1); - Player_actor_draw_func = mSM_ovlptr_dllcnv(&Player_actor_draw, submenu,1); + Player_actor_move_func = mSM_ovlptr_dllcnv(&Player_actor_move, submenu, 1); + Player_actor_draw_func = mSM_ovlptr_dllcnv(&Player_actor_draw, submenu, 1); } -static void Player_actor_ct_call(ACTOR* actor, GAME* game){ +static void Player_actor_ct_call(ACTOR* actor, GAME* game) { GAME_PLAY* play = (GAME_PLAY*)game; load_player(&play->submenu); @@ -46,21 +46,21 @@ static void Player_actor_ct_call(ACTOR* actor, GAME* game){ Player_actor_ct_func(actor, game); } -static void Player_actor_dt_call(ACTOR* actor, GAME* game){ +static void Player_actor_dt_call(ACTOR* actor, GAME* game) { GAME_PLAY* play = (GAME_PLAY*)game; load_player(&play->submenu); Player_actor_dt_func(actor, game); } -static void Player_actor_move_call(ACTOR* actor, GAME* game){ +static void Player_actor_move_call(ACTOR* actor, GAME* game) { GAME_PLAY* play = (GAME_PLAY*)game; - + load_player(&play->submenu); Player_actor_move_func(actor, game); } -static void Player_actor_draw_call(ACTOR* actor, GAME* game){ +static void Player_actor_draw_call(ACTOR* actor, GAME* game) { GAME_PLAY* play = (GAME_PLAY*)game; load_player(&play->submenu); diff --git a/src/m_rcp.c b/src/m_rcp.c index a8dee82e..aabdc15c 100644 --- a/src/m_rcp.c +++ b/src/m_rcp.c @@ -2,455 +2,479 @@ #include "gfxalloc.h" #include "libu64/u64types.h" +#include "jsyswrap.h" +#include "m_font.h" #define G_CC_POLY_Z_LIGHT_PRIM PRIMITIVE, 0, SHADE, 0, 0, 0, 0, PRIMITIVE #define G_CC_MODULATEIDECALA_PRIM2 PRIMITIVE, 0, COMBINED, 0, 0, 0, 0, COMBINED #define G_CC_PRIMLERP 0, 0, 0, PRIMITIVE, TEXEL0, 0, PRIM_LOD_FRAC, 0 static Gfx z_gsCPModeSet_Data[15][6] = { - { - gsDPPipeSync(), - gsSPTexture(65535, 65535, 0, 0, G_OFF), - gsDPSetCombineMode(G_CC_POLY_Z_LIGHT_PRIM, G_CC_POLY_Z_LIGHT_PRIM), - gsDPSetOtherMode(G_AD_NOTPATTERN | G_CD_MAGICSQ | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_NONE | G_TL_TILE | G_TD_CLAMP | G_TP_PERSP | G_CYC_1CYCLE | G_PM_NPRIMITIVE, G_AC_NONE | G_ZS_PIXEL | G_RM_AA_ZB_XLU_SURF | G_RM_AA_ZB_XLU_SURF2), - gsSPLoadGeometryMode(G_ZBUFFER | G_SHADE | G_CULL_BACK | G_LIGHTING | G_SHADING_SMOOTH), - gsSPEndDisplayList(), - }, - { - gsDPPipeSync(), - gsSPTexture(65535, 65535, 0, 0, G_ON), - gsDPSetCombineMode(G_CC_MODULATEIA_PRIM, G_CC_MODULATEIA_PRIM), - gsDPSetOtherMode(G_AD_NOTPATTERN | G_CD_MAGICSQ | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_NONE | G_TL_TILE | G_TD_CLAMP | G_TP_PERSP | G_CYC_1CYCLE | G_PM_NPRIMITIVE, G_AC_THRESHOLD | G_ZS_PIXEL | G_RM_ZB_CLD_SURF | G_RM_ZB_CLD_SURF2), - gsSPLoadGeometryMode(G_ZBUFFER | G_SHADE | G_SHADING_SMOOTH), - gsSPEndDisplayList(), - }, - { - gsDPPipeSync(), - gsSPTexture(65535, 65535, 0, 0, G_ON), - gsDPSetCombineMode(G_CC_MODULATEIDECALA, G_CC_MODULATEIA_PRIM2), - gsDPSetOtherMode(G_AD_NOTPATTERN | G_CD_MAGICSQ | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_NONE | G_TL_TILE | G_TD_CLAMP | G_TP_PERSP | G_CYC_2CYCLE | G_PM_NPRIMITIVE, G_AC_NONE | G_ZS_PIXEL | G_RM_FOG_SHADE_A | G_RM_AA_ZB_OPA_SURF2), - gsSPLoadGeometryMode(G_ZBUFFER | G_SHADE | G_CULL_BACK | G_FOG | G_LIGHTING | G_SHADING_SMOOTH), - gsSPEndDisplayList(), - }, - { - gsDPPipeSync(), - gsSPTexture(65535, 65535, 0, 0, G_ON), - gsDPSetCombineMode(G_CC_MODULATEI_PRIM, G_CC_MODULATEI_PRIM), - gsDPSetOtherMode(G_AD_NOTPATTERN | G_CD_MAGICSQ | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_NONE | G_TL_TILE | G_TD_CLAMP | G_TP_PERSP | G_CYC_1CYCLE | G_PM_NPRIMITIVE, G_AC_NONE | G_ZS_PIXEL | G_RM_AA_ZB_OPA_SURF | G_RM_AA_ZB_OPA_SURF2), - gsSPLoadGeometryMode(G_ZBUFFER | G_SHADE | G_CULL_BACK | G_LIGHTING | G_SHADING_SMOOTH), - gsSPEndDisplayList(), - }, - { - gsDPPipeSync(), - gsSPTexture(65535, 65535, 0, 0, G_ON), - gsDPSetCombineMode(G_CC_MODULATEIDECALA_PRIM, G_CC_MODULATEIDECALA_PRIM), - gsDPSetOtherMode(G_AD_DISABLE | G_CD_MAGICSQ | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_RGBA16 | G_TL_TILE | G_TD_CLAMP | G_TP_NONE | G_CYC_1CYCLE | G_PM_NPRIMITIVE, G_AC_THRESHOLD | G_ZS_PIXEL | G_RM_AA_TEX_EDGE | G_RM_AA_TEX_EDGE2), - gsSPLoadGeometryMode(G_SHADE | G_SHADING_SMOOTH), - gsSPEndDisplayList(), - }, - { - gsDPPipeSync(), - gsSPTexture(65535, 65535, 0, 0, G_OFF), - gsDPSetCombineMode(G_CC_SHADE, G_CC_SHADE), - gsDPSetOtherMode(G_AD_DISABLE | G_CD_MAGICSQ | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_NONE | G_TL_TILE | G_TD_CLAMP | G_TP_NONE | G_CYC_FILL | G_PM_NPRIMITIVE, G_AC_THRESHOLD | G_ZS_PIXEL | G_RM_NOOP | G_RM_NOOP2), - gsSPLoadGeometryMode(G_SHADE | G_SHADING_SMOOTH), - gsSPEndDisplayList(), - }, - { - gsDPPipeSync(), - gsSPTexture(65535, 65535, 0, 0, G_ON), - gsDPSetCombineMode(G_CC_MODULATEI_PRIM, G_CC_MODULATEI_PRIM), - gsDPSetOtherMode(G_AD_NOTPATTERN | G_CD_MAGICSQ | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_NONE | G_TL_TILE | G_TD_CLAMP | G_TP_PERSP | G_CYC_1CYCLE | G_PM_NPRIMITIVE, G_AC_NONE | G_ZS_PIXEL | G_RM_ZB_XLU_SURF | G_RM_ZB_XLU_SURF2), - gsSPLoadGeometryMode(G_ZBUFFER | G_SHADE | G_SHADING_SMOOTH), - gsSPEndDisplayList(), - }, - { - gsDPPipeSync(), - gsSPTexture(65535, 65535, 0, 0, G_OFF), - gsDPSetCombineMode(G_CC_PRIMITIVE, G_CC_PRIMITIVE), - gsDPSetOtherMode(G_AD_DISABLE | G_CD_MAGICSQ | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_NONE | G_TL_TILE | G_TD_CLAMP | G_TP_NONE | G_CYC_1CYCLE | G_PM_NPRIMITIVE, G_AC_THRESHOLD | G_ZS_PIXEL | G_RM_CLD_SURF | G_RM_CLD_SURF2), - gsSPLoadGeometryMode(G_SHADING_SMOOTH), - gsSPEndDisplayList(), - }, - { - gsDPPipeSync(), - gsSPTexture(65535, 65535, 0, 0, G_ON), - gsDPSetCombineMode(G_CC_MODULATEIA_PRIM, G_CC_MODULATEIA_PRIM), - gsDPSetOtherMode(G_AD_NOTPATTERN | G_CD_MAGICSQ | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_NONE | G_TL_TILE | G_TD_CLAMP | G_TP_PERSP | G_CYC_1CYCLE | G_PM_NPRIMITIVE, G_AC_THRESHOLD | G_ZS_PIXEL | G_RM_CLD_SURF | G_RM_CLD_SURF2), - gsSPLoadGeometryMode(G_SHADE | G_SHADING_SMOOTH), - gsSPEndDisplayList(), - }, - { - gsDPPipeSync(), - gsSPTexture(65535, 65535, 0, 0, G_ON), - gsDPSetCombineMode(G_CC_MODULATEIA_PRIM, G_CC_PASS2), - gsDPSetOtherMode(G_AD_NOTPATTERN | G_CD_MAGICSQ | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_NONE | G_TL_TILE | G_TD_CLAMP | G_TP_PERSP | G_CYC_2CYCLE | G_PM_NPRIMITIVE, G_AC_NONE | G_ZS_PIXEL | G_RM_PASS | G_RM_ZB_CLD_SURF2), - gsSPLoadGeometryMode(G_ZBUFFER | G_SHADE | G_CULL_BACK | G_SHADING_SMOOTH), - gsSPEndDisplayList(), - }, - { - gsDPPipeSync(), - gsSPTexture(65535, 65535, 0, 0, G_ON), - gsDPSetCombineMode(G_CC_MODULATEIDECALA, G_CC_MODULATEIDECALA_PRIM2), - gsDPSetOtherMode(G_AD_NOTPATTERN | G_CD_MAGICSQ | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_RGBA16 | G_TL_TILE | G_TD_CLAMP | G_TP_PERSP | G_CYC_2CYCLE | G_PM_NPRIMITIVE, G_AC_NONE | G_ZS_PIXEL | G_RM_FOG_SHADE_A | G_RM_AA_ZB_TEX_EDGE2), - gsSPLoadGeometryMode(G_ZBUFFER | G_SHADE | G_CULL_BACK | G_FOG | G_LIGHTING | G_SHADING_SMOOTH), - gsSPEndDisplayList(), - }, - { - gsDPPipeSync(), - gsSPTexture(65535, 65535, 0, 0, G_ON), - gsDPSetCombineMode(G_CC_MODULATEIDECALA, G_CC_MODULATEIDECALA_PRIM2), - gsDPSetOtherMode(G_AD_NOTPATTERN | G_CD_MAGICSQ | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_RGBA16 | G_TL_TILE | G_TD_CLAMP | G_TP_PERSP | G_CYC_2CYCLE | G_PM_NPRIMITIVE, G_AC_NONE | G_ZS_PIXEL | AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_FULL | ZMODE_OPA | CVG_X_ALPHA | ALPHA_CVG_SEL | G_RM_FOG_SHADE_A | GBL_c2(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM)), - gsSPLoadGeometryMode(G_ZBUFFER | G_SHADE | G_CULL_BACK | G_FOG | G_LIGHTING | G_SHADING_SMOOTH), - gsSPEndDisplayList(), - }, - { - gsDPPipeSync(), - gsSPTexture(65535, 65535, 0, 0, G_ON), - gsDPSetCombineMode(G_CC_MODULATEIDECALA, G_CC_MODULATEIDECALA_PRIM2), - gsDPSetOtherMode(G_AD_NOTPATTERN | G_CD_MAGICSQ | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_RGBA16 | G_TL_TILE | G_TD_CLAMP | G_TP_PERSP | G_CYC_2CYCLE | G_PM_NPRIMITIVE, G_AC_NONE | G_ZS_PIXEL | G_RM_FOG_SHADE_A | G_RM_AA_ZB_TEX_EDGE2), - gsSPLoadGeometryMode(G_ZBUFFER | G_SHADE | G_FOG | G_LIGHTING | G_SHADING_SMOOTH), - gsSPEndDisplayList(), - }, - { - gsDPPipeSync(), - gsSPTexture(65535, 65535, 0, 0, G_ON), - gsDPSetCombineMode(G_CC_MODULATEIDECALA, G_CC_MODULATEIDECALA_PRIM2), - gsDPSetOtherMode(G_AD_NOTPATTERN | G_CD_MAGICSQ | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_RGBA16 | G_TL_TILE | G_TD_CLAMP | G_TP_PERSP | G_CYC_2CYCLE | G_PM_NPRIMITIVE, G_AC_NONE | G_ZS_PIXEL | G_RM_FOG_SHADE_A | G_RM_CLD_SURF2), - gsSPLoadGeometryMode(G_ZBUFFER | G_SHADE | G_FOG | G_LIGHTING | G_SHADING_SMOOTH), - gsSPEndDisplayList(), - }, - { - gsDPPipeSync(), - gsSPTexture(65535, 65535, 0, 0, G_ON), - gsDPSetCombineMode(G_CC_PRIMLERP, G_CC_PASS2), - gsDPSetOtherMode(G_AD_NOTPATTERN | G_CD_MAGICSQ | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_NONE | G_TL_TILE | G_TD_CLAMP | G_TP_PERSP | G_CYC_2CYCLE | G_PM_NPRIMITIVE, G_AC_NONE | G_ZS_PIXEL | G_RM_FOG_SHADE_A | G_RM_ZB_OVL_SURF2), - gsSPLoadGeometryMode(G_ZBUFFER | G_SHADE | G_FOG | G_SHADING_SMOOTH), - gsSPEndDisplayList(), - } + { + gsDPPipeSync(), + gsSPTexture(65535, 65535, 0, 0, G_OFF), + gsDPSetCombineMode(G_CC_POLY_Z_LIGHT_PRIM, G_CC_POLY_Z_LIGHT_PRIM), + gsDPSetOtherMode(G_AD_NOTPATTERN | G_CD_MAGICSQ | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_NONE | G_TL_TILE | + G_TD_CLAMP | G_TP_PERSP | G_CYC_1CYCLE | G_PM_NPRIMITIVE, + G_AC_NONE | G_ZS_PIXEL | G_RM_AA_ZB_XLU_SURF | G_RM_AA_ZB_XLU_SURF2), + gsSPLoadGeometryMode(G_ZBUFFER | G_SHADE | G_CULL_BACK | G_LIGHTING | G_SHADING_SMOOTH), + gsSPEndDisplayList(), + }, + { + gsDPPipeSync(), + gsSPTexture(65535, 65535, 0, 0, G_ON), + gsDPSetCombineMode(G_CC_MODULATEIA_PRIM, G_CC_MODULATEIA_PRIM), + gsDPSetOtherMode(G_AD_NOTPATTERN | G_CD_MAGICSQ | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_NONE | G_TL_TILE | + G_TD_CLAMP | G_TP_PERSP | G_CYC_1CYCLE | G_PM_NPRIMITIVE, + G_AC_THRESHOLD | G_ZS_PIXEL | G_RM_ZB_CLD_SURF | G_RM_ZB_CLD_SURF2), + gsSPLoadGeometryMode(G_ZBUFFER | G_SHADE | G_SHADING_SMOOTH), + gsSPEndDisplayList(), + }, + { + gsDPPipeSync(), + gsSPTexture(65535, 65535, 0, 0, G_ON), + gsDPSetCombineMode(G_CC_MODULATEIDECALA, G_CC_MODULATEIA_PRIM2), + gsDPSetOtherMode(G_AD_NOTPATTERN | G_CD_MAGICSQ | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_NONE | G_TL_TILE | + G_TD_CLAMP | G_TP_PERSP | G_CYC_2CYCLE | G_PM_NPRIMITIVE, + G_AC_NONE | G_ZS_PIXEL | G_RM_FOG_SHADE_A | G_RM_AA_ZB_OPA_SURF2), + gsSPLoadGeometryMode(G_ZBUFFER | G_SHADE | G_CULL_BACK | G_FOG | G_LIGHTING | G_SHADING_SMOOTH), + gsSPEndDisplayList(), + }, + { + gsDPPipeSync(), + gsSPTexture(65535, 65535, 0, 0, G_ON), + gsDPSetCombineMode(G_CC_MODULATEI_PRIM, G_CC_MODULATEI_PRIM), + gsDPSetOtherMode(G_AD_NOTPATTERN | G_CD_MAGICSQ | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_NONE | G_TL_TILE | + G_TD_CLAMP | G_TP_PERSP | G_CYC_1CYCLE | G_PM_NPRIMITIVE, + G_AC_NONE | G_ZS_PIXEL | G_RM_AA_ZB_OPA_SURF | G_RM_AA_ZB_OPA_SURF2), + gsSPLoadGeometryMode(G_ZBUFFER | G_SHADE | G_CULL_BACK | G_LIGHTING | G_SHADING_SMOOTH), + gsSPEndDisplayList(), + }, + { + gsDPPipeSync(), + gsSPTexture(65535, 65535, 0, 0, G_ON), + gsDPSetCombineMode(G_CC_MODULATEIDECALA_PRIM, G_CC_MODULATEIDECALA_PRIM), + gsDPSetOtherMode(G_AD_DISABLE | G_CD_MAGICSQ | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_RGBA16 | G_TL_TILE | + G_TD_CLAMP | G_TP_NONE | G_CYC_1CYCLE | G_PM_NPRIMITIVE, + G_AC_THRESHOLD | G_ZS_PIXEL | G_RM_AA_TEX_EDGE | G_RM_AA_TEX_EDGE2), + gsSPLoadGeometryMode(G_SHADE | G_SHADING_SMOOTH), + gsSPEndDisplayList(), + }, + { + gsDPPipeSync(), + gsSPTexture(65535, 65535, 0, 0, G_OFF), + gsDPSetCombineMode(G_CC_SHADE, G_CC_SHADE), + gsDPSetOtherMode(G_AD_DISABLE | G_CD_MAGICSQ | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_NONE | G_TL_TILE | + G_TD_CLAMP | G_TP_NONE | G_CYC_FILL | G_PM_NPRIMITIVE, + G_AC_THRESHOLD | G_ZS_PIXEL | G_RM_NOOP | G_RM_NOOP2), + gsSPLoadGeometryMode(G_SHADE | G_SHADING_SMOOTH), + gsSPEndDisplayList(), + }, + { + gsDPPipeSync(), + gsSPTexture(65535, 65535, 0, 0, G_ON), + gsDPSetCombineMode(G_CC_MODULATEI_PRIM, G_CC_MODULATEI_PRIM), + gsDPSetOtherMode(G_AD_NOTPATTERN | G_CD_MAGICSQ | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_NONE | G_TL_TILE | + G_TD_CLAMP | G_TP_PERSP | G_CYC_1CYCLE | G_PM_NPRIMITIVE, + G_AC_NONE | G_ZS_PIXEL | G_RM_ZB_XLU_SURF | G_RM_ZB_XLU_SURF2), + gsSPLoadGeometryMode(G_ZBUFFER | G_SHADE | G_SHADING_SMOOTH), + gsSPEndDisplayList(), + }, + { + gsDPPipeSync(), + gsSPTexture(65535, 65535, 0, 0, G_OFF), + gsDPSetCombineMode(G_CC_PRIMITIVE, G_CC_PRIMITIVE), + gsDPSetOtherMode(G_AD_DISABLE | G_CD_MAGICSQ | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_NONE | G_TL_TILE | + G_TD_CLAMP | G_TP_NONE | G_CYC_1CYCLE | G_PM_NPRIMITIVE, + G_AC_THRESHOLD | G_ZS_PIXEL | G_RM_CLD_SURF | G_RM_CLD_SURF2), + gsSPLoadGeometryMode(G_SHADING_SMOOTH), + gsSPEndDisplayList(), + }, + { + gsDPPipeSync(), + gsSPTexture(65535, 65535, 0, 0, G_ON), + gsDPSetCombineMode(G_CC_MODULATEIA_PRIM, G_CC_MODULATEIA_PRIM), + gsDPSetOtherMode(G_AD_NOTPATTERN | G_CD_MAGICSQ | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_NONE | G_TL_TILE | + G_TD_CLAMP | G_TP_PERSP | G_CYC_1CYCLE | G_PM_NPRIMITIVE, + G_AC_THRESHOLD | G_ZS_PIXEL | G_RM_CLD_SURF | G_RM_CLD_SURF2), + gsSPLoadGeometryMode(G_SHADE | G_SHADING_SMOOTH), + gsSPEndDisplayList(), + }, + { + gsDPPipeSync(), + gsSPTexture(65535, 65535, 0, 0, G_ON), + gsDPSetCombineMode(G_CC_MODULATEIA_PRIM, G_CC_PASS2), + gsDPSetOtherMode(G_AD_NOTPATTERN | G_CD_MAGICSQ | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_NONE | G_TL_TILE | + G_TD_CLAMP | G_TP_PERSP | G_CYC_2CYCLE | G_PM_NPRIMITIVE, + G_AC_NONE | G_ZS_PIXEL | G_RM_PASS | G_RM_ZB_CLD_SURF2), + gsSPLoadGeometryMode(G_ZBUFFER | G_SHADE | G_CULL_BACK | G_SHADING_SMOOTH), + gsSPEndDisplayList(), + }, + { + gsDPPipeSync(), + gsSPTexture(65535, 65535, 0, 0, G_ON), + gsDPSetCombineMode(G_CC_MODULATEIDECALA, G_CC_MODULATEIDECALA_PRIM2), + gsDPSetOtherMode(G_AD_NOTPATTERN | G_CD_MAGICSQ | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_RGBA16 | + G_TL_TILE | G_TD_CLAMP | G_TP_PERSP | G_CYC_2CYCLE | G_PM_NPRIMITIVE, + G_AC_NONE | G_ZS_PIXEL | G_RM_FOG_SHADE_A | G_RM_AA_ZB_TEX_EDGE2), + gsSPLoadGeometryMode(G_ZBUFFER | G_SHADE | G_CULL_BACK | G_FOG | G_LIGHTING | G_SHADING_SMOOTH), + gsSPEndDisplayList(), + }, + { + gsDPPipeSync(), + gsSPTexture(65535, 65535, 0, 0, G_ON), + gsDPSetCombineMode(G_CC_MODULATEIDECALA, G_CC_MODULATEIDECALA_PRIM2), + gsDPSetOtherMode(G_AD_NOTPATTERN | G_CD_MAGICSQ | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_RGBA16 | + G_TL_TILE | G_TD_CLAMP | G_TP_PERSP | G_CYC_2CYCLE | G_PM_NPRIMITIVE, + G_AC_NONE | G_ZS_PIXEL | AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_FULL | ZMODE_OPA | + CVG_X_ALPHA | ALPHA_CVG_SEL | G_RM_FOG_SHADE_A | + GBL_c2(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM)), + gsSPLoadGeometryMode(G_ZBUFFER | G_SHADE | G_CULL_BACK | G_FOG | G_LIGHTING | G_SHADING_SMOOTH), + gsSPEndDisplayList(), + }, + { + gsDPPipeSync(), + gsSPTexture(65535, 65535, 0, 0, G_ON), + gsDPSetCombineMode(G_CC_MODULATEIDECALA, G_CC_MODULATEIDECALA_PRIM2), + gsDPSetOtherMode(G_AD_NOTPATTERN | G_CD_MAGICSQ | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_RGBA16 | + G_TL_TILE | G_TD_CLAMP | G_TP_PERSP | G_CYC_2CYCLE | G_PM_NPRIMITIVE, + G_AC_NONE | G_ZS_PIXEL | G_RM_FOG_SHADE_A | G_RM_AA_ZB_TEX_EDGE2), + gsSPLoadGeometryMode(G_ZBUFFER | G_SHADE | G_FOG | G_LIGHTING | G_SHADING_SMOOTH), + gsSPEndDisplayList(), + }, + { + gsDPPipeSync(), + gsSPTexture(65535, 65535, 0, 0, G_ON), + gsDPSetCombineMode(G_CC_MODULATEIDECALA, G_CC_MODULATEIDECALA_PRIM2), + gsDPSetOtherMode(G_AD_NOTPATTERN | G_CD_MAGICSQ | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_RGBA16 | + G_TL_TILE | G_TD_CLAMP | G_TP_PERSP | G_CYC_2CYCLE | G_PM_NPRIMITIVE, + G_AC_NONE | G_ZS_PIXEL | G_RM_FOG_SHADE_A | G_RM_CLD_SURF2), + gsSPLoadGeometryMode(G_ZBUFFER | G_SHADE | G_FOG | G_LIGHTING | G_SHADING_SMOOTH), + gsSPEndDisplayList(), + }, + { + gsDPPipeSync(), + gsSPTexture(65535, 65535, 0, 0, G_ON), + gsDPSetCombineMode(G_CC_PRIMLERP, G_CC_PASS2), + gsDPSetOtherMode(G_AD_NOTPATTERN | G_CD_MAGICSQ | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_NONE | G_TL_TILE | + G_TD_CLAMP | G_TP_PERSP | G_CYC_2CYCLE | G_PM_NPRIMITIVE, + G_AC_NONE | G_ZS_PIXEL | G_RM_FOG_SHADE_A | G_RM_ZB_OVL_SURF2), + gsSPLoadGeometryMode(G_ZBUFFER | G_SHADE | G_FOG | G_SHADING_SMOOTH), + gsSPEndDisplayList(), + } }; Gfx RSP_RDP_clear_data[12] = { - gsDPPipeSync(), - gsSPTexture(65535, 65535, 0, 0, G_OFF), - gsDPSetCombineMode(G_CC_SHADE, G_CC_SHADE), - gsDPSetOtherMode(G_AD_DISABLE | G_CD_MAGICSQ | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_NONE | G_TL_TILE | G_TD_CLAMP | G_TP_PERSP | G_CYC_FILL | G_PM_NPRIMITIVE, G_AC_NONE | G_ZS_PIXEL | G_RM_NOOP | G_RM_NOOP2), - gsSPLoadGeometryMode(G_ZBUFFER | G_SHADE | G_CULL_BACK | G_LIGHTING | G_SHADING_SMOOTH), - gsDPSetScissor(G_SC_NON_INTERLACE, 0, 0, 640, 480), - gsDPSetBlendColor(0x00, 0x00, 0x00, 0x08), - gsSPClipRatio(FRUSTRATIO_2), - gsSPEndDisplayList(), + gsDPPipeSync(), + gsSPTexture(65535, 65535, 0, 0, G_OFF), + gsDPSetCombineMode(G_CC_SHADE, G_CC_SHADE), + gsDPSetOtherMode(G_AD_DISABLE | G_CD_MAGICSQ | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_NONE | G_TL_TILE | + G_TD_CLAMP | G_TP_PERSP | G_CYC_FILL | G_PM_NPRIMITIVE, + G_AC_NONE | G_ZS_PIXEL | G_RM_NOOP | G_RM_NOOP2), + gsSPLoadGeometryMode(G_ZBUFFER | G_SHADE | G_CULL_BACK | G_LIGHTING | G_SHADING_SMOOTH), + gsDPSetScissor(G_SC_NON_INTERLACE, 0, 0, 640, 480), + gsDPSetBlendColor(0x00, 0x00, 0x00, 0x08), + gsSPClipRatio(FRUSTRATIO_2), + gsSPEndDisplayList(), }; int fbdemo_mode; extern void gfx_set_fog_position(Gfx** gfxp, int near, int far) { - Gfx* gfx; + Gfx* gfx; - if (near == far) { + if (near == far) { + gfx = (*gfxp)++; + gSPFogPosition(gfx++, 0, 10000000); + return; + } gfx = (*gfxp)++; - gSPFogPosition(gfx++, 0, 10000000); - return; - } - gfx = (*gfxp)++; - gSPFogPosition(gfx++, near, far); + gSPFogPosition(gfx++, near, far); } -extern Gfx* gfx_set_fog_nosync(Gfx* gfx, int r, int g, int b, int a, int near, - int far) { - gDPSetFogColor(gfx++, r, g, b, a); - gfx_set_fog_position(&gfx, near, far); +extern Gfx* gfx_set_fog_nosync(Gfx* gfx, int r, int g, int b, int a, int near, int far) { + gDPSetFogColor(gfx++, r, g, b, a); + gfx_set_fog_position(&gfx, near, far); - return gfx; + return gfx; } extern void texture_z_light_prim_xlu_disp(GRAPH* graph) { - OPEN_DISP(graph); + OPEN_DISP(graph); - gSPDisplayList(NOW_POLY_XLU_DISP++, z_gsCPModeSet_Data[2]); + gSPDisplayList(NOW_POLY_XLU_DISP++, z_gsCPModeSet_Data[2]); - CLOSE_DISP(graph); + CLOSE_DISP(graph); } extern void _texture_z_light_fog_prim_bg(GRAPH* graph) { - OPEN_DISP(graph); + OPEN_DISP(graph); - gSPDisplayList(NOW_BG_OPA_DISP++, z_gsCPModeSet_Data[2]); + gSPDisplayList(NOW_BG_OPA_DISP++, z_gsCPModeSet_Data[2]); - CLOSE_DISP(graph); + CLOSE_DISP(graph); } extern void _texture_z_light_fog_prim(GRAPH* graph) { - OPEN_DISP(graph); + OPEN_DISP(graph); - gSPDisplayList(NOW_POLY_OPA_DISP++, z_gsCPModeSet_Data[2]); + gSPDisplayList(NOW_POLY_OPA_DISP++, z_gsCPModeSet_Data[2]); - CLOSE_DISP(graph); + CLOSE_DISP(graph); } extern void _texture_z_light_fog_prim_shadow(GRAPH* graph) { - OPEN_DISP(graph); + OPEN_DISP(graph); - gSPDisplayList(NOW_SHADOW_DISP++, z_gsCPModeSet_Data[2]); + gSPDisplayList(NOW_SHADOW_DISP++, z_gsCPModeSet_Data[2]); - CLOSE_DISP(graph); + CLOSE_DISP(graph); } extern void _texture_z_light_fog_prim_xlu(GRAPH* graph) { - OPEN_DISP(graph); + OPEN_DISP(graph); - gSPDisplayList(NOW_POLY_XLU_DISP++, z_gsCPModeSet_Data[2]); + gSPDisplayList(NOW_POLY_XLU_DISP++, z_gsCPModeSet_Data[2]); - CLOSE_DISP(graph); + CLOSE_DISP(graph); } extern void _texture_z_light_fog_prim_light(GRAPH* graph) { - OPEN_DISP(graph); + OPEN_DISP(graph); - gSPDisplayList(NOW_LIGHT_DISP++, z_gsCPModeSet_Data[2]); + gSPDisplayList(NOW_LIGHT_DISP++, z_gsCPModeSet_Data[2]); - CLOSE_DISP(graph); + CLOSE_DISP(graph); } extern void _texture_z_light_fog_prim_npc(GRAPH* graph) { - OPEN_DISP(graph); + OPEN_DISP(graph); - gSPDisplayList(NOW_POLY_OPA_DISP++, z_gsCPModeSet_Data[10]); - gDPPipeSync(NOW_POLY_OPA_DISP++); - gDPSetPrimColor(NOW_POLY_OPA_DISP++, 0, 128, 255, 255, 255, 255); + gSPDisplayList(NOW_POLY_OPA_DISP++, z_gsCPModeSet_Data[10]); + gDPPipeSync(NOW_POLY_OPA_DISP++); + gDPSetPrimColor(NOW_POLY_OPA_DISP++, 0, 128, 255, 255, 255, 255); - CLOSE_DISP(graph); + CLOSE_DISP(graph); } extern Gfx* texture_z_light_fog_prim_bb_pal_opa(Gfx* gfx) { - gSPDisplayList(gfx++, z_gsCPModeSet_Data[12]); - gDPSetPrimColor(gfx++, 0, 128, 255, 255, 255, 255); + gSPDisplayList(gfx++, z_gsCPModeSet_Data[12]); + gDPSetPrimColor(gfx++, 0, 128, 255, 255, 255, 255); - return gfx; + return gfx; } extern Gfx* texture_z_light_fog_prim_bb_pal_xlu(Gfx* gfx) { - gSPDisplayList(gfx++, z_gsCPModeSet_Data[13]); - gDPSetPrimColor(gfx++, 0, 128, 255, 255, 255, 255); + gSPDisplayList(gfx++, z_gsCPModeSet_Data[13]); + gDPSetPrimColor(gfx++, 0, 128, 255, 255, 255, 255); - return gfx; + return gfx; } extern Gfx* texture_z_fog_lod_alpha_shadow(Gfx* gfx) { - gSPDisplayList(gfx++, z_gsCPModeSet_Data[14]); + gSPDisplayList(gfx++, z_gsCPModeSet_Data[14]); - return gfx; + return gfx; } extern Gfx* gfx_rect_moji(Gfx* gfx) { - gSPDisplayList(gfx++, z_gsCPModeSet_Data[4]); + gSPDisplayList(gfx++, z_gsCPModeSet_Data[4]); - return gfx; + return gfx; } extern void rect_moji(GRAPH* graph) { - OPEN_DISP(graph); + OPEN_DISP(graph); - gSPDisplayList(NOW_POLY_OPA_DISP++, z_gsCPModeSet_Data[4]); + gSPDisplayList(NOW_POLY_OPA_DISP++, z_gsCPModeSet_Data[4]); - CLOSE_DISP(graph); + CLOSE_DISP(graph); } extern void polygon_z_light_prim(GRAPH* graph) { - OPEN_DISP(graph); + OPEN_DISP(graph); - gSPDisplayList(NOW_POLY_XLU_DISP++, z_gsCPModeSet_Data[0]); + gSPDisplayList(NOW_POLY_XLU_DISP++, z_gsCPModeSet_Data[0]); - CLOSE_DISP(graph); + CLOSE_DISP(graph); } extern void softsprite_prim(GRAPH* graph) { - OPEN_DISP(graph); + OPEN_DISP(graph); - gSPDisplayList(NOW_POLY_XLU_DISP++, z_gsCPModeSet_Data[6]); + gSPDisplayList(NOW_POLY_XLU_DISP++, z_gsCPModeSet_Data[6]); - CLOSE_DISP(graph); + CLOSE_DISP(graph); } extern Gfx* gfx_softsprite_prim_xlu(Gfx* gfx) { - gSPDisplayList(gfx++, z_gsCPModeSet_Data[8]); - gDPSetColorDither(gfx++, G_CD_DISABLE); + gSPDisplayList(gfx++, z_gsCPModeSet_Data[8]); + gDPSetColorDither(gfx++, G_CD_DISABLE); - return gfx++; + return gfx++; } extern Gfx* gfx_tex_scroll2(Gfx** gfxpp, int x, int y, int width, int height) { - Gfx* dl = gfxalloc(gfxpp, 3 * sizeof(Gfx)); + Gfx* dl = gfxalloc(gfxpp, 3 * sizeof(Gfx)); - gDPTileSync(dl); - gDPSetTileSize(dl + 1, G_TX_RENDERTILE, x, y, x + ((width - 1) << 2), - y + ((height - 1) << 2)); - gSPEndDisplayList(dl + 2); + gDPTileSync(dl); + gDPSetTileSize(dl + 1, G_TX_RENDERTILE, x, y, x + ((width - 1) << 2), y + ((height - 1) << 2)); + gSPEndDisplayList(dl + 2); } extern Gfx* tex_scroll2(GRAPH* graph, u32 x, u32 y, int width, int height) { - Gfx* dl = GRAPH_ALLOC_TYPE(graph, Gfx, 3); - if (dl != NULL) { - gDPTileSync(dl); - gDPSetTileSize(dl + 1, G_TX_RENDERTILE, x & 0x7FF, y & 0x7FF, - ((x & 0x7FF) + ((width - 1) << 2)), - ((y & 0x7FF) + ((height - 1) << 2))); - gSPEndDisplayList(dl + 2); - } + Gfx* dl = GRAPH_ALLOC_TYPE(graph, Gfx, 3); + if (dl != NULL) { + gDPTileSync(dl); + gDPSetTileSize(dl + 1, G_TX_RENDERTILE, x & 0x7FF, y & 0x7FF, ((x & 0x7FF) + ((width - 1) << 2)), + ((y & 0x7FF) + ((height - 1) << 2))); + gSPEndDisplayList(dl + 2); + } - return dl; + return dl; } extern Gfx* tex_scroll2_dolphin(GRAPH* graph, int x, int y, int width, int height) { - Gfx* dl = GRAPH_ALLOC_TYPE(graph, Gfx, 2); + Gfx* dl = GRAPH_ALLOC_TYPE(graph, Gfx, 2); - if (dl != NULL) { - gDPSetTileSize_Dolphin(dl, 0, x << 1, y << 1, width, height); - gSPEndDisplayList(dl + 1); - } + if (dl != NULL) { + gDPSetTileSize_Dolphin(dl, 0, x << 1, y << 1, width, height); + gSPEndDisplayList(dl + 1); + } - return dl; + return dl; } -extern Gfx* two_tex_scroll(GRAPH* graph, int tile1, int x1, int y1, int width1, - int height1, int tile2, int x2, int y2, int width2, - int height2) { - Gfx* dl = GRAPH_ALLOC_TYPE(graph, Gfx, 5); +extern Gfx* two_tex_scroll(GRAPH* graph, int tile1, int x1, int y1, int width1, int height1, int tile2, int x2, int y2, + int width2, int height2) { + Gfx* dl = GRAPH_ALLOC_TYPE(graph, Gfx, 5); - if (dl != NULL) { - gDPTileSync(dl); - gDPSetTileSize(dl + 1, tile1, x1 & 0x7FF, y1 & 0x7FF, - (x1 & 0x7FF) + ((width1 - 1) << 2), - (y1 & 0x7FF) + ((height1 - 1) << 2)); - gDPTileSync(dl + 2); - gDPSetTileSize(dl + 3, tile2, x2 & 0x7FF, y2 & 0x7FF, - (x2 & 0x7FF) + ((width2 - 1) << 2), - (y2 & 0x7FF) + ((height2 - 1) << 2)); - gSPEndDisplayList(dl + 4); - } + if (dl != NULL) { + gDPTileSync(dl); + gDPSetTileSize(dl + 1, tile1, x1 & 0x7FF, y1 & 0x7FF, (x1 & 0x7FF) + ((width1 - 1) << 2), + (y1 & 0x7FF) + ((height1 - 1) << 2)); + gDPTileSync(dl + 2); + gDPSetTileSize(dl + 3, tile2, x2 & 0x7FF, y2 & 0x7FF, (x2 & 0x7FF) + ((width2 - 1) << 2), + (y2 & 0x7FF) + ((height2 - 1) << 2)); + gSPEndDisplayList(dl + 4); + } - return dl; + return dl; } -extern Gfx* two_tex_scroll_dolphin(GRAPH* graph, int tile1, int x1, int y1, int width1, - int height1, int tile2, int x2, int y2, int width2, - int height2) { - Gfx* dl = GRAPH_ALLOC_TYPE(graph, Gfx, 3); +extern Gfx* two_tex_scroll_dolphin(GRAPH* graph, int tile1, int x1, int y1, int width1, int height1, int tile2, int x2, + int y2, int width2, int height2) { + Gfx* dl = GRAPH_ALLOC_TYPE(graph, Gfx, 3); - if (dl != NULL) { - gDPSetTileSize_Dolphin(dl, tile1, x1 << 1, y1 << 1, width1, height1); - gDPSetTileSize_Dolphin(dl + 1, tile2, x2 << 1, y2 << 1, width2, height2); - gSPEndDisplayList(dl + 2); - } + if (dl != NULL) { + gDPSetTileSize_Dolphin(dl, tile1, x1 << 1, y1 << 1, width1, height1); + gDPSetTileSize_Dolphin(dl + 1, tile2, x2 << 1, y2 << 1, width2, height2); + gSPEndDisplayList(dl + 2); + } - return dl; + return dl; } -extern void DisplayList_initialize(GRAPH* graph, u32 clear_r, u32 clear_g, - u32 clear_b, GAME* game) { - OPEN_DISP(graph); +extern void DisplayList_initialize(GRAPH* graph, u8 clear_r, u8 clear_g, u8 clear_b, GAME* game) { + OPEN_DISP(graph); - gSPDisplayList(NOW_POLY_OPA_DISP++, RSP_RDP_clear_data); - gSPDisplayList(NOW_POLY_XLU_DISP++, RSP_RDP_clear_data); - gSPDisplayList(NOW_OVERLAY_DISP++, RSP_RDP_clear_data); - gSPDisplayList(NOW_FONT_DISP++, RSP_RDP_clear_data); - gSPDisplayList(NOW_BG_OPA_DISP++, RSP_RDP_clear_data); - gSPDisplayList(NOW_BG_XLU_DISP++, z_gsCPModeSet_Data[2]); - gSPDisplayList(NOW_SHADOW_DISP++, z_gsCPModeSet_Data[2]); - gSPDisplayList(NOW_LIGHT_DISP++, z_gsCPModeSet_Data[2]); + gSPDisplayList(NOW_POLY_OPA_DISP++, RSP_RDP_clear_data); + gSPDisplayList(NOW_POLY_XLU_DISP++, RSP_RDP_clear_data); + gSPDisplayList(NOW_OVERLAY_DISP++, RSP_RDP_clear_data); + gSPDisplayList(NOW_FONT_DISP++, RSP_RDP_clear_data); + gSPDisplayList(NOW_BG_OPA_DISP++, RSP_RDP_clear_data); + gSPDisplayList(NOW_BG_XLU_DISP++, z_gsCPModeSet_Data[2]); + gSPDisplayList(NOW_SHADOW_DISP++, z_gsCPModeSet_Data[2]); + gSPDisplayList(NOW_LIGHT_DISP++, z_gsCPModeSet_Data[2]); - gDPSetScissor(NOW_POLY_OPA_DISP++, G_SC_NON_INTERLACE, 0, 0, 640, 480); - gDPSetScissor(NOW_POLY_XLU_DISP++, G_SC_NON_INTERLACE, 0, 0, 640, 480); - gDPSetScissor(NOW_OVERLAY_DISP++, G_SC_NON_INTERLACE, 0, 0, 640, 480); - gDPSetScissor(NOW_FONT_DISP++, G_SC_NON_INTERLACE, 0, 0, 640, 480); - gDPSetScissor(NOW_SHADOW_DISP++, G_SC_NON_INTERLACE, 0, 0, 640, 480); - gDPSetScissor(NOW_LIGHT_DISP++, G_SC_NON_INTERLACE, 0, 0, 640, 480); - gDPSetScissor(NOW_BG_OPA_DISP++, G_SC_NON_INTERLACE, 0, 0, 640, 480); - gDPSetScissor(NOW_BG_XLU_DISP++, G_SC_NON_INTERLACE, 0, 0, 640, 480); + gDPSetScissor(NOW_POLY_OPA_DISP++, G_SC_NON_INTERLACE, 0, 0, 640, 480); + gDPSetScissor(NOW_POLY_XLU_DISP++, G_SC_NON_INTERLACE, 0, 0, 640, 480); + gDPSetScissor(NOW_OVERLAY_DISP++, G_SC_NON_INTERLACE, 0, 0, 640, 480); + gDPSetScissor(NOW_FONT_DISP++, G_SC_NON_INTERLACE, 0, 0, 640, 480); + gDPSetScissor(NOW_SHADOW_DISP++, G_SC_NON_INTERLACE, 0, 0, 640, 480); + gDPSetScissor(NOW_LIGHT_DISP++, G_SC_NON_INTERLACE, 0, 0, 640, 480); + gDPSetScissor(NOW_BG_OPA_DISP++, G_SC_NON_INTERLACE, 0, 0, 640, 480); + gDPSetScissor(NOW_BG_XLU_DISP++, G_SC_NON_INTERLACE, 0, 0, 640, 480); - if (((game == NULL) || (fbdemo_mode < 2)) && - (JW_setClearColor(clear_r, clear_g, clear_b))) { - gDPSetCycleType(NOW_POLY_OPA_DISP++, G_CYC_FILL); - gDPSetRenderMode(NOW_POLY_OPA_DISP++, G_RM_NOOP, G_RM_NOOP2); - gDPSetFillColor(NOW_POLY_OPA_DISP++, - (GPACK_RGBA5551(clear_r, clear_g, clear_b, 1) << 16) | - GPACK_RGBA5551(clear_r, clear_g, clear_b, 1)); - gDPFillRectangle(NOW_POLY_OPA_DISP++, 0, 0, 639, 479); - gDPPipeSync(NOW_POLY_OPA_DISP++); - } + if (((game == NULL) || (fbdemo_mode < 2)) && (JW_setClearColor(clear_r, clear_g, clear_b))) { + gDPSetCycleType(NOW_POLY_OPA_DISP++, G_CYC_FILL); + gDPSetRenderMode(NOW_POLY_OPA_DISP++, G_RM_NOOP, G_RM_NOOP2); + gDPSetFillColor(NOW_POLY_OPA_DISP++, (GPACK_RGBA5551(clear_r, clear_g, clear_b, 1) << 16) | + GPACK_RGBA5551(clear_r, clear_g, clear_b, 1)); + gDPFillRectangle(NOW_POLY_OPA_DISP++, 0, 0, 639, 479); + gDPPipeSync(NOW_POLY_OPA_DISP++); + } - CLOSE_DISP(graph); + CLOSE_DISP(graph); - mFont_Main_start(graph); + mFont_Main_start(graph); } extern void fade_rgba8888_draw(Gfx** gfxp, u32 color) { - static Gfx fade_gfx[6] = { - gsDPPipeSync(), - gsDPSetOtherMode(G_AD_DISABLE | G_CD_MAGICSQ | G_CK_NONE | G_TC_FILT | - G_TF_BILERP | G_TT_NONE | G_TL_TILE | G_TD_CLAMP | - G_TP_NONE | G_CYC_1CYCLE | G_PM_1PRIMITIVE, - G_AC_NONE | G_ZS_PIXEL | G_RM_CLD_SURF | G_RM_CLD_SURF2), - gsDPSetCombineMode(G_CC_PRIMITIVE, G_CC_PRIMITIVE), - gsDPFillRectangle(0, 0, 640, 480), - gsDPPipeSync(), - gsSPEndDisplayList(), - }; + static Gfx fade_gfx[6] = { + gsDPPipeSync(), + gsDPSetOtherMode(G_AD_DISABLE | G_CD_MAGICSQ | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_NONE | G_TL_TILE | + G_TD_CLAMP | G_TP_NONE | G_CYC_1CYCLE | G_PM_1PRIMITIVE, + G_AC_NONE | G_ZS_PIXEL | G_RM_CLD_SURF | G_RM_CLD_SURF2), + gsDPSetCombineMode(G_CC_PRIMITIVE, G_CC_PRIMITIVE), + gsDPFillRectangle(0, 0, 640, 480), + gsDPPipeSync(), + gsSPEndDisplayList(), + }; - static Gfx fill_gfx[5] = { - gsDPPipeSync(), - gsDPSetOtherMode(G_AD_DISABLE | G_CD_MAGICSQ | G_CK_NONE | G_TC_FILT | - G_TF_BILERP | G_TT_NONE | G_TL_TILE | G_TD_CLAMP | - G_TP_NONE | G_CYC_FILL | G_PM_1PRIMITIVE, - G_AC_NONE | G_ZS_PIXEL | G_RM_NOOP | G_RM_NOOP2), - gsDPFillRectangle(0, 0, 639, 479), - gsDPPipeSync(), - gsSPEndDisplayList(), - }; + static Gfx fill_gfx[5] = { + gsDPPipeSync(), + gsDPSetOtherMode(G_AD_DISABLE | G_CD_MAGICSQ | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_NONE | G_TL_TILE | + G_TD_CLAMP | G_TP_NONE | G_CYC_FILL | G_PM_1PRIMITIVE, + G_AC_NONE | G_ZS_PIXEL | G_RM_NOOP | G_RM_NOOP2), + gsDPFillRectangle(0, 0, 639, 479), + gsDPPipeSync(), + gsSPEndDisplayList(), + }; - Gfx* gfx; + Gfx* gfx; - if ((color & 0xFF) == 255) { - u32 r = ((color >> 16) & 0xF800); - u32 g = ((color >> 13) & 0x7FFC0); - u32 b = (color >> 10) & 0x7FFFFF; - u32 c = ((r | g | b | 1)); - u32 f = c | ((c & 0xFFFF) << 16); + if ((color & 0xFF) == 255) { + u32 r = ((color >> 16) & 0xF800); + u32 g = ((color >> 13) & 0x7FFC0); + u32 b = (color >> 10) & 0x7FFFFF; + u32 c = ((r | g | b | 1)); + u32 f = c | ((c & 0xFFFF) << 16); - gfx = *gfxp; - gDPSetFillColor(gfx, f); - gSPDisplayList(gfx + 1, fill_gfx); - *gfxp = gfx + 2; - } else if ((color & 0xFF) != 0) { - gfx = *gfxp; - gDPSetColor(gfx, G_SETPRIMCOLOR, color); - gSPDisplayList(gfx + 1, fade_gfx); - *gfxp = gfx + 2; - } + gfx = *gfxp; + gDPSetFillColor(gfx, f); + gSPDisplayList(gfx + 1, fill_gfx); + *gfxp = gfx + 2; + } else if ((color & 0xFF) != 0) { + gfx = *gfxp; + gDPSetColor(gfx, G_SETPRIMCOLOR, color); + gSPDisplayList(gfx + 1, fade_gfx); + *gfxp = gfx + 2; + } } -extern void fade_black_draw(Gfx** gfx, u32 color) { fade_rgba8888_draw(gfx, color); } +extern void fade_black_draw(Gfx** gfx, u32 color) { + fade_rgba8888_draw(gfx, color); +} extern Gfx* gfx_gDPFillRectangle1(Gfx* gfx, u32 ulx, u32 uly, u32 lrx, u32 lry) { - gDPFillRectangle(gfx++, ulx << 1, uly << 1, lrx << 1, lry << 1); - return gfx; + gDPFillRectangle(gfx++, ulx << 1, uly << 1, lrx << 1, lry << 1); + return gfx; } extern Gfx* gfx_gDPFillRectangleF(Gfx* gfx, u32 ulx, u32 uly, u32 lrx, u32 lry) { - gDPFillRectangle(gfx++, ulx << 1, uly << 1, (lrx << 1) - 1, (lry << 1) - 1); - return gfx; + gDPFillRectangle(gfx++, ulx << 1, uly << 1, (lrx << 1) - 1, (lry << 1) - 1); + return gfx; } -extern Gfx* gfx_gSPTextureRectangle1(Gfx* gfx, int xl, int yl, int xh, int yh, - int tile, int s, int t, int dsdx, int dtdy) { - gSPTextureRectangle(gfx++, xl << 1, yl << 1, xh << 1, yh << 1, tile, s, t, - dsdx >> 1, dtdy >> 1); - return gfx; +extern Gfx* gfx_gSPTextureRectangle1(Gfx* gfx, int xl, int yl, int xh, int yh, int tile, int s, int t, int dsdx, + int dtdy) { + gSPTextureRectangle(gfx++, xl << 1, yl << 1, xh << 1, yh << 1, tile, s, t, dsdx >> 1, dtdy >> 1); + return gfx; } -extern Gfx* gfx_gSPScisTextureRectangle1(Gfx* gfx, int xl, int yl, int xh, int yh, - int tile, int s, int t, int dsdx, int dtdy) { - gSPScisTextureRectangle(gfx++, (s16)(xl << 1), (s16)(yl << 1), xh << 1, - yh << 1, tile, s, t, dsdx >> 1, dtdy >> 1); - return gfx; +extern Gfx* gfx_gSPScisTextureRectangle1(Gfx* gfx, int xl, int yl, int xh, int yh, int tile, int s, int t, int dsdx, + int dtdy) { + gSPScisTextureRectangle(gfx++, (s16)(xl << 1), (s16)(yl << 1), xh << 1, yh << 1, tile, s, t, dsdx >> 1, dtdy >> 1); + return gfx; } diff --git a/src/m_start_data_init.c b/src/m_start_data_init.c index c43e23aa..9826b687 100644 --- a/src/m_start_data_init.c +++ b/src/m_start_data_init.c @@ -23,503 +23,489 @@ #include "m_notice.h" #include "m_event.h" #include "m_common_data.h" +#include "m_design_ovl.h" static void famicom_emu_initial_common_data() { - // stubbed + // stubbed } static void decide_fruit(mActor_name_t* fruit_p) { - *fruit_p = RANDOM(mAGrw_FRUIT_NUM) | ITM_FOOD_START; + *fruit_p = RANDOM(mAGrw_FRUIT_NUM) | ITM_FOOD_START; } static void decide_fish_location(u8* location) { - *location = RANDOM(3); + *location = RANDOM(3); } static void title_game_haniwa_data_init() { - static int haniwa_msg[4] = { mString_HANIWA_MSG0, mString_HANIWA_MSG1, mString_HANIWA_MSG2, mString_HANIWA_MSG3 }; - u8 haniwa_buf[HANIWA_MESSAGE_LEN]; + static int haniwa_msg[4] = { mString_HANIWA_MSG0, mString_HANIWA_MSG1, mString_HANIWA_MSG2, mString_HANIWA_MSG3 }; + u8 haniwa_buf[HANIWA_MESSAGE_LEN]; - int line_len; - int haniwa_msg_len; - int i; - u8* dst; + int line_len; + int haniwa_msg_len; + int i; + u8* dst; - /* Load message line-by-line */ - dst = haniwa_buf; - haniwa_msg_len = 0; - for (i = 0; i < 4; i++) { + /* Load message line-by-line */ + dst = haniwa_buf; + haniwa_msg_len = 0; + for (i = 0; i < 4; i++) { - mString_Load_StringFromRom(dst, HANIWA_MESSAGE_LEN - haniwa_msg_len, haniwa_msg[i]); - line_len = mMl_strlen(dst, HANIWA_MESSAGE_LEN - haniwa_msg_len, CHAR_SPACE); + mString_Load_StringFromRom(dst, HANIWA_MESSAGE_LEN - haniwa_msg_len, haniwa_msg[i]); + line_len = mMl_strlen(dst, HANIWA_MESSAGE_LEN - haniwa_msg_len, CHAR_SPACE); - if (i < 3) { - dst[line_len] = CHAR_NEW_LINE; - haniwa_msg_len += line_len + 1; - dst += line_len + 1; + if (i < 3) { + dst[line_len] = CHAR_NEW_LINE; + haniwa_msg_len += line_len + 1; + dst += line_len + 1; + } } - } - for (i = 0; i < mHS_HOUSE_NUM; i++) { - Haniwa_c* haniwa = &Save_Get(homes + i)->haniwa; - mHm_hs_c* house = Save_Get(homes + i); - int j; + for (i = 0; i < mHS_HOUSE_NUM; i++) { + Haniwa_c* haniwa = &Save_Get(homes + i)->haniwa; + mHm_hs_c* house = Save_Get(homes + i); + int j; - /* Copy default message */ - mem_copy(house->haniwa.message, haniwa_buf, HANIWA_MESSAGE_LEN); - - /* Clear held items */ - for (j = 0; j < HANIWA_ITEM_HOLD_NUM; j++) { - haniwa->items[j].item = EMPTY_NO; + /* Copy default message */ + mem_copy(house->haniwa.message, haniwa_buf, HANIWA_MESSAGE_LEN); + + /* Clear held items */ + for (j = 0; j < HANIWA_ITEM_HOLD_NUM; j++) { + haniwa->items[j].item = EMPTY_NO; + } + + haniwa->bells = 0; } - - haniwa->bells = 0; - } } static void mSDI_ClearMoneyPlayerHomeStationBlock() { - static int block_num[2][2] = { - { 2, 1 }, /* Player home */ - { 2, 0 } /* Station */ - }; + static int block_num[2][2] = { + { 2, 1 }, /* Player home */ + { 2, 0 } /* Station */ + }; - int block_z; - int block_x; - mActor_name_t* items; - u16* deposit; - int ut_x; - int ut_z; - mActor_name_t item; - int i; + int block_z; + int block_x; + mActor_name_t* items; + u16* deposit; + int ut_x; + int ut_z; + mActor_name_t item; + int i; - for (i = 0; i < 2; i++) { - block_z = block_num[i][1]; - block_x = block_num[i][0]; + for (i = 0; i < 2; i++) { + block_z = block_num[i][1]; + block_x = block_num[i][0]; - items = Save_Get(fg[block_z][block_x]).items[0]; - deposit = Save_Get(deposit[block_z * FG_BLOCK_X_NUM + block_x]); + items = Save_Get(fg[block_z][block_x]).items[0]; + deposit = Save_Get(deposit[block_z * FG_BLOCK_X_NUM + block_x]); - if (items != NULL) { - for (ut_z = 0; ut_z < UT_Z_NUM; ut_z++) { - for (ut_x = 0; ut_x < UT_X_NUM; ut_x++) { - item = *items; + if (items != NULL) { + for (ut_z = 0; ut_z < UT_Z_NUM; ut_z++) { + for (ut_x = 0; ut_x < UT_X_NUM; ut_x++) { + item = *items; - if (item >= ITM_MONEY_START && item <= ITM_MONEY_END) { - mPB_keep_item(item); - *items = EMPTY_NO; + if (item >= ITM_MONEY_START && item <= ITM_MONEY_END) { + mPB_keep_item(item); + *items = EMPTY_NO; - if (deposit != NULL) { - mFI_BlockDepositOFF(deposit, ut_x, ut_z); + if (deposit != NULL) { + mFI_BlockDepositOFF(deposit, ut_x, ut_z); + } + } + + items++; + } } - } - - items++; } - } } - } } static void mSDI_PullTreeUT(mActor_name_t* item_p) { - mActor_name_t item = *item_p; + mActor_name_t item = *item_p; - if ( - (item >= TREE_SAPLING && item <= TREE_30000BELLS) || - (item >= TREE_100BELLS_SAPLING && item <= TREE_PALM_FRUIT) || - (item >= CEDAR_TREE_SAPLING && item <= CEDAR_TREE) || - (item >= GOLD_TREE_SAPLING && item <= GOLD_TREE) - ) { - *item_p = EMPTY_NO; - } + if ((item >= TREE_SAPLING && item <= TREE_30000BELLS) || + (item >= TREE_100BELLS_SAPLING && item <= TREE_PALM_FRUIT) || + (item >= CEDAR_TREE_SAPLING && item <= CEDAR_TREE) || (item >= GOLD_TREE_SAPLING && item <= GOLD_TREE)) { + *item_p = EMPTY_NO; + } } static void mSDI_PullTreeBlock(mActor_name_t* items_p, int ut) { - int i; - for (i = ut; i < UT_TOTAL_NUM; i += UT_X_NUM) { - mSDI_PullTreeUT(&items_p[i]); - } + int i; + for (i = ut; i < UT_TOTAL_NUM; i += UT_X_NUM) { + mSDI_PullTreeUT(&items_p[i]); + } } static void mSDI_PullTree() { - mFM_fg_c* fg_block; - int block_z; + mFM_fg_c* fg_block; + int block_z; - for (block_z = 0; block_z < FG_BLOCK_Z_NUM; block_z++) { - /* Clear trees against the cliffs on the left and right town cliff borders */ - fg_block = Save_GetPointer(fg[block_z][0]); - mSDI_PullTreeBlock(fg_block->items[0], 0); - mSDI_PullTreeBlock((fg_block + FG_BLOCK_X_NUM - 1)->items[0], UT_X_NUM - 1); - } + for (block_z = 0; block_z < FG_BLOCK_Z_NUM; block_z++) { + /* Clear trees against the cliffs on the left and right town cliff borders */ + fg_block = Save_GetPointer(fg[block_z][0]); + mSDI_PullTreeBlock(fg_block->items[0], 0); + mSDI_PullTreeBlock((fg_block + FG_BLOCK_X_NUM - 1)->items[0], UT_X_NUM - 1); + } } static void mSDI_PullTreeUnderPlayerBlock() { - /** - * Cleared tree diagram - * - * -------xx------- - * -------xx------- - * ---------------- - * ... - **/ + /** + * Cleared tree diagram + * + * -------xx------- + * -------xx------- + * ---------------- + * ... + **/ - mActor_name_t* items = &Save_Get(fg[2][2].items[0][0]); - if (items != NULL) { - mSDI_PullTreeUT(&items[7]); - mSDI_PullTreeUT(&items[8]); - mSDI_PullTreeUT(&items[16 + 7]); - mSDI_PullTreeUT(&items[16 + 8]); - } + mActor_name_t* items = &Save_Get(fg[2][2].items[0][0]); + if (items != NULL) { + mSDI_PullTreeUT(&items[7]); + mSDI_PullTreeUT(&items[8]); + mSDI_PullTreeUT(&items[16 + 7]); + mSDI_PullTreeUT(&items[16 + 8]); + } } static int mSDI_StartInitNew(GAME* game, int player_no, int malloc_flag) { - int town_day; - Private_c* priv; - int i; - Private_c* priv_p; - Animal_c* animals = Save_Get(animals); - GAME_PLAY* play = (GAME_PLAY*)game; - GAME* g = NULL; + int town_day; + Private_c* priv; + int i; + Private_c* priv_p; + Animal_c* animals = Save_Get(animals); + GAME_PLAY* play = (GAME_PLAY*)game; + GAME* g = NULL; - Common_Set(scene_from_title_demo, SCENE_START_DEMO); - lbRTC_GetTime(Common_GetPointer(time.rtc_time)); - osSyncPrintf("player no -- %d\n", player_no); - Common_Set(player_no, player_no); + Common_Set(scene_from_title_demo, SCENE_START_DEMO); + lbRTC_GetTime(Common_GetPointer(time.rtc_time)); + osSyncPrintf("player no -- %d\n", player_no); + Common_Set(player_no, player_no); - priv = Save_GetPointer(private[player_no]); - Common_Set(now_private, priv); - priv->gender = mPr_SEX_MALE; - decide_fruit(Save_GetPointer(fruit)); - mFM_DecideBgTexIdx(Save_GetPointer(bg_tex_idx)); - mFAs_ClearGoodField(); + priv = Save_GetPointer(private[player_no]); + Common_Set(now_private, priv); + priv->gender = mPr_SEX_MALE; + decide_fruit(Save_GetPointer(fruit)); + mFM_DecideBgTexIdx(Save_GetPointer(bg_tex_idx)); + mFAs_ClearGoodField(); - if (malloc_flag == FALSE) { - g = game; - } + if (malloc_flag == FALSE) { + g = game; + } - bzero(Save_Get(deposit), sizeof(Save_Get(deposit))); - Save_Set(dust_flag, FALSE); - bzero(Save_GetPointer(island), sizeof(Island_c)); - mFM_InitFgCombiSaveData(g); + bzero(Save_Get(deposit), sizeof(Save_Get(deposit))); + Save_Set(dust_flag, FALSE); + bzero(Save_GetPointer(island), sizeof(Island_c)); + mFM_InitFgCombiSaveData(g); - /* Remove trees */ - mSDI_PullTree(); - mSDI_PullTreeUnderPlayerBlock(); + /* Remove trees */ + mSDI_PullTree(); + mSDI_PullTreeUnderPlayerBlock(); - mFM_SetBlockKindLoadCombi(g); - - /* Tree -> Fruit Tree */ - mAGrw_ChangeTree2FruitTree(); - - /* Tree -> Cedar Tree */ - mAGrw_ChangeTree2Cedar(); + mFM_SetBlockKindLoadCombi(g); - priv_p = Save_Get(private); + /* Tree -> Fruit Tree */ + mAGrw_ChangeTree2FruitTree(); - mMld_SetDefaultMelody(); - mLd_LandDataInit(); - mEv_ClearEventSaveInfo(Save_GetPointer(event_save_data)); - mEv_init(&play->event); - mNpc_InitNpcAllInfo(malloc_flag); + /* Tree -> Cedar Tree */ + mAGrw_ChangeTree2Cedar(); - for (i = 0; i < PLAYER_NUM; i++) { - mPr_ClearPrivateInfo(priv_p); + priv_p = Save_Get(private); - Save_Get(homes[i]).outlook_pal = i; - Save_Get(homes[i]).next_outlook_pal = i; - bzero(&Save_Get(homes[i]).size_info, sizeof(mHm_rmsz_c)); - - mPr_ClearMotherMailInfo(&Save_Get(mother_mail[i])); - priv_p++; - } + mMld_SetDefaultMelody(); + mLd_LandDataInit(); + mEv_ClearEventSaveInfo(Save_GetPointer(event_save_data)); + mEv_init(&play->event); + mNpc_InitNpcAllInfo(malloc_flag); - mPr_InitPrivateInfo(priv_p - PLAYER_NUM + player_no); - mNpc_SetRemoveAnimalNo(Save_GetPointer(remove_animal_idx), animals, -1); - title_game_haniwa_data_init(); - mPB_police_box_init(g); - mSN_snowman_init(); // - mHS_house_init(); - mGH_animal_return_init(); // - mMC_mask_cat_init(); // - mDE_maskcat_init(Save_GetPointer(mask_cat)); // - - lbRTC_TimeCopy(Save_GetPointer(last_grow_time), &mTM_rtcTime_clear_code); - lbRTC_TimeCopy(Save_GetPointer(treasure_buried_time), &mTM_rtcTime_clear_code); - lbRTC_TimeCopy(Save_GetPointer(treasure_checked_time), &mTM_rtcTime_clear_code); - lbRTC_TimeCopy(Save_GetPointer(saved_auto_nwrite_time), &mTM_rtcTime_clear_code); + for (i = 0; i < PLAYER_NUM; i++) { + mPr_ClearPrivateInfo(priv_p); - Save_Set(station_type, RANDOM(15)); - Save_Set(island.last_song_to_island, -1); - Save_Set(island.last_song_from_island, -1); + Save_Get(homes[i]).outlook_pal = i; + Save_Get(homes[i]).next_outlook_pal = i; + bzero(&Save_Get(homes[i]).size_info, sizeof(mHm_rmsz_c)); - mPr_SetPossessionItem(Common_Get(now_private), 0, ITM_MONEY_1000, mPr_ITEM_COND_QUEST); - - town_day = RANDOM(30) + 1; /* Initial spread is [1, 30] */ - if (town_day >= 4) { - town_day++; /* Add an extra day so that 4th of July is never chosen, so [1, 3] U [5, 31] */ - } + mPr_ClearMotherMailInfo(&Save_Get(mother_mail[i])); + priv_p++; + } - Save_Set(town_day, town_day); - - mCkRh_InitGokiSaveData_AllRoom(); - - mNW_InitMyOriginal(); - mNW_InitNeedleworkData(); + mPr_InitPrivateInfo(priv_p - PLAYER_NUM + player_no); + mNpc_SetRemoveAnimalNo(Save_GetPointer(remove_animal_idx), animals, -1); + title_game_haniwa_data_init(); + mPB_police_box_init(g); + mSN_snowman_init(); // + mHS_house_init(); + mGH_animal_return_init(); // + mMC_mask_cat_init(); // + mDE_maskcat_init(Save_GetPointer(mask_cat)); // - mEv_2nd_init(&play->event); + lbRTC_TimeCopy(Save_GetPointer(last_grow_time), &mTM_rtcTime_clear_code); + lbRTC_TimeCopy(Save_GetPointer(treasure_buried_time), &mTM_rtcTime_clear_code); + lbRTC_TimeCopy(Save_GetPointer(treasure_checked_time), &mTM_rtcTime_clear_code); + lbRTC_TimeCopy(Save_GetPointer(saved_auto_nwrite_time), &mTM_rtcTime_clear_code); - mISL_init(Save_GetPointer(island)); + Save_Set(station_type, RANDOM(15)); + Save_Set(island.last_song_to_island, -1); + Save_Set(island.last_song_from_island, -1); - famicom_emu_initial_common_data(); + mPr_SetPossessionItem(Common_Get(now_private), 0, ITM_MONEY_1000, mPr_ITEM_COND_QUEST); - mRmTp_SetDefaultLightSwitchData(1); // TODO: lightswitch enum + town_day = RANDOM(30) + 1; /* Initial spread is [1, 30] */ + if (town_day >= 4) { + town_day++; /* Add an extra day so that 4th of July is never chosen, so [1, 3] U [5, 31] */ + } - mFI_PullTanukiPathTrees(); + Save_Set(town_day, town_day); - Common_Set(_2dbe1, 0); + mCkRh_InitGokiSaveData_AllRoom(); - return TRUE; + mNW_InitMyOriginal(); + mNW_InitNeedleworkData(); + + mEv_2nd_init(&play->event); + + mISL_init(Save_GetPointer(island)); + + famicom_emu_initial_common_data(); + + mRmTp_SetDefaultLightSwitchData(1); // TODO: lightswitch enum + + mFI_PullTanukiPathTrees(); + + Common_Set(_2dbe1, 0); + + return TRUE; } static int mSDI_StartInitFrom(GAME* game, int player_no, int malloc_flag) { - GAME_PLAY* play = (GAME_PLAY*)game; - int res = FALSE; - GAME* g = game; - Animal_c* animals = Save_Get(animals); + GAME_PLAY* play = (GAME_PLAY*)game; + int res = FALSE; + GAME* g = game; + Animal_c* animals = Save_Get(animals); - if (malloc_flag) { - g = NULL; - } - - Common_Set(scene_from_title_demo, SCENE_FG); - lbRTC_GetTime(Common_GetPointer(time.rtc_time)); - - if (mFRm_CheckSaveData() == TRUE) { - Private_c* priv = Save_Get(private + player_no); - - if (mPr_CheckPrivate(priv) == TRUE) { - - if (priv->exists == TRUE) { - Common_Set(now_private, priv); - Common_Set(player_no, player_no); - mFM_SetBlockKindLoadCombi(g); // - mEv_init_force(&play->event); // - mHsRm_GetHuusuiRoom(g, player_no); - mCkRh_DecideNowGokiFamilyCount(player_no); - mSP_ExchangeLineUp_InGame(g); // - mNpc_SetRemoveAnimalNo(Save_GetPointer(remove_animal_idx), animals, -1); - mMkRm_MarkRoom(g); - mRmTp_SetDefaultLightSwitchData(2); // TODO: enum - res = TRUE; - } - else { - /* Player loaded their player data while "out travelling" */ - Common_Set(player_decoy_flag, TRUE); // set "gyroid face" flag - priv->exists = TRUE; - Common_Set(now_private, priv); - Common_Set(player_no, player_no); - mFM_SetBlockKindLoadCombi(g); // - mEv_init_force(&play->event); // - mHsRm_GetHuusuiRoom(g, player_no); - mCkRh_DecideNowGokiFamilyCount(player_no); - mSP_ExchangeLineUp_InGame(g); // - mNpc_SetRemoveAnimalNo(Save_GetPointer(remove_animal_idx), animals, -1); - - /* Punish player by deleting their pockets and some pending items */ - bzero(&priv->inventory.pockets, sizeof(priv->inventory.pockets)); - priv->inventory.lotto_ticket_expiry_month = 0; - priv->inventory.lotto_ticket_mail_storage = 0; - priv->inventory.item_conditions = 0; - priv->inventory.wallet = 0; - mQst_ClearDelivery(priv->deliveries, mPr_DELIVERY_QUEST_NUM); // - mQst_ClearErrand(priv->errands, mPr_ERRAND_QUEST_NUM); // - - mMkRm_MarkRoom(g); - mRmTp_SetDefaultLightSwitchData(2); // TODO: enum - res = TRUE; - } + if (malloc_flag) { + g = NULL; } - } - return res; + Common_Set(scene_from_title_demo, SCENE_FG); + lbRTC_GetTime(Common_GetPointer(time.rtc_time)); + + if (mFRm_CheckSaveData() == TRUE) { + Private_c* priv = Save_Get(private + player_no); + + if (mPr_CheckPrivate(priv) == TRUE) { + + if (priv->exists == TRUE) { + Common_Set(now_private, priv); + Common_Set(player_no, player_no); + mFM_SetBlockKindLoadCombi(g); // + mEv_init_force(&play->event); // + mHsRm_GetHuusuiRoom(g, player_no); + mCkRh_DecideNowGokiFamilyCount(player_no); + mSP_ExchangeLineUp_InGame(g); // + mNpc_SetRemoveAnimalNo(Save_GetPointer(remove_animal_idx), animals, -1); + mMkRm_MarkRoom(g); + mRmTp_SetDefaultLightSwitchData(2); // TODO: enum + res = TRUE; + } else { + /* Player loaded their player data while "out travelling" */ + Common_Set(player_decoy_flag, TRUE); // set "gyroid face" flag + priv->exists = TRUE; + Common_Set(now_private, priv); + Common_Set(player_no, player_no); + mFM_SetBlockKindLoadCombi(g); // + mEv_init_force(&play->event); // + mHsRm_GetHuusuiRoom(g, player_no); + mCkRh_DecideNowGokiFamilyCount(player_no); + mSP_ExchangeLineUp_InGame(g); // + mNpc_SetRemoveAnimalNo(Save_GetPointer(remove_animal_idx), animals, -1); + + /* Punish player by deleting their pockets and some pending items */ + bzero(&priv->inventory.pockets, sizeof(priv->inventory.pockets)); + priv->inventory.lotto_ticket_expiry_month = 0; + priv->inventory.lotto_ticket_mail_storage = 0; + priv->inventory.item_conditions = 0; + priv->inventory.wallet = 0; + mQst_ClearDelivery(priv->deliveries, mPr_DELIVERY_QUEST_NUM); // + mQst_ClearErrand(priv->errands, mPr_ERRAND_QUEST_NUM); // + + mMkRm_MarkRoom(g); + mRmTp_SetDefaultLightSwitchData(2); // TODO: enum + res = TRUE; + } + } + } + + return res; } static int mSDI_StartInitNewPlayer(GAME* game, int player_no, int malloc_flag) { - GAME_PLAY* play = (GAME_PLAY*)game; - Animal_c* animals = Save_Get(animals); - int res = FALSE; + GAME_PLAY* play = (GAME_PLAY*)game; + Animal_c* animals = Save_Get(animals); + int res = FALSE; - Common_Set(scene_from_title_demo, SCENE_START_DEMO2); - lbRTC_GetTime(Common_GetPointer(time.rtc_time)); + Common_Set(scene_from_title_demo, SCENE_START_DEMO2); + lbRTC_GetTime(Common_GetPointer(time.rtc_time)); - if (mFRm_CheckSaveData() == TRUE) { - Private_c* priv = Save_Get(private + player_no); + if (mFRm_CheckSaveData() == TRUE) { + Private_c* priv = Save_Get(private + player_no); - if (mPr_CheckPrivate(priv) != TRUE) { - mPr_InitPrivateInfo(priv); - Common_Set(now_private, priv); - mPr_SetPossessionItem(priv, 0, ITM_MONEY_1000, mPr_ITEM_COND_QUEST); - Common_Set(player_no, player_no); - Common_Get(now_private)->gender = mPr_SEX_MALE; - mNW_InitOneMyOriginal(Common_Get(player_no)); - mCkRh_InitGokiSaveData_InitNewPlayer(); + if (mPr_CheckPrivate(priv) != TRUE) { + mPr_InitPrivateInfo(priv); + Common_Set(now_private, priv); + mPr_SetPossessionItem(priv, 0, ITM_MONEY_1000, mPr_ITEM_COND_QUEST); + Common_Set(player_no, player_no); + Common_Get(now_private)->gender = mPr_SEX_MALE; + mNW_InitOneMyOriginal(Common_Get(player_no)); + mCkRh_InitGokiSaveData_InitNewPlayer(); - if (malloc_flag == FALSE) { - mFM_SetBlockKindLoadCombi(game); - mEv_init_force(&play->event); - mSP_ExchangeLineUp_InGame(game); - } - else { - mFM_SetBlockKindLoadCombi(NULL); - mEv_init_force(&play->event); - mSP_ExchangeLineUp_InGame(NULL); - } + if (malloc_flag == FALSE) { + mFM_SetBlockKindLoadCombi(game); + mEv_init_force(&play->event); + mSP_ExchangeLineUp_InGame(game); + } else { + mFM_SetBlockKindLoadCombi(NULL); + mEv_init_force(&play->event); + mSP_ExchangeLineUp_InGame(NULL); + } - mNpc_SetRemoveAnimalNo(Save_GetPointer(remove_animal_idx), animals, -1); - mSDI_ClearMoneyPlayerHomeStationBlock(); - mRmTp_SetDefaultLightSwitchData(1); // TODO: enum - mFI_PullTanukiPathTrees(); - res = TRUE; + mNpc_SetRemoveAnimalNo(Save_GetPointer(remove_animal_idx), animals, -1); + mSDI_ClearMoneyPlayerHomeStationBlock(); + mRmTp_SetDefaultLightSwitchData(1); // TODO: enum + mFI_PullTanukiPathTrees(); + res = TRUE; + } } - } - return res; + return res; } static int mSDI_StartInitPak(GAME* game, int player_no, int malloc_flag) { - GAME_PLAY* play = (GAME_PLAY*)game; - GAME* g = game; - Animal_c* animals = Save_Get(animals); - int res = FALSE; - - if (malloc_flag == TRUE) { - g = NULL; - } + GAME_PLAY* play = (GAME_PLAY*)game; + GAME* g = game; + Animal_c* animals = Save_Get(animals); + int res = FALSE; - if (player_no < mPr_PLAYER_NUM) { - Common_Set(scene_from_title_demo, SCENE_FG); - } + if (malloc_flag == TRUE) { + g = NULL; + } - if (mFRm_CheckSaveData() == TRUE) { - mFM_SetBlockKindLoadCombi(g); - mEv_init_force(&play->event); - mHsRm_GetHuusuiRoom(g, player_no); - mCkRh_DecideNowGokiFamilyCount(player_no); - mSP_ExchangeLineUp_InGame(g); - mNpc_SetRemoveAnimalNo(Save_GetPointer(remove_animal_idx), animals, -1); - mNpc_SetReturnAnimal(mNpc_GetInAnimalP()); // - mNpc_SendRegisteredGoodbyMail(); // - mMkRm_MarkRoom(g); - mEv_SetGateway(); // - mRmTp_SetDefaultLightSwitchData(2); // TODO: enum - res = TRUE; - } + if (player_no < mPr_PLAYER_NUM) { + Common_Set(scene_from_title_demo, SCENE_FG); + } - return res; + if (mFRm_CheckSaveData() == TRUE) { + mFM_SetBlockKindLoadCombi(g); + mEv_init_force(&play->event); + mHsRm_GetHuusuiRoom(g, player_no); + mCkRh_DecideNowGokiFamilyCount(player_no); + mSP_ExchangeLineUp_InGame(g); + mNpc_SetRemoveAnimalNo(Save_GetPointer(remove_animal_idx), animals, -1); + mNpc_SetReturnAnimal(mNpc_GetInAnimalP()); // + mNpc_SendRegisteredGoodbyMail(); // + mMkRm_MarkRoom(g); + mEv_SetGateway(); // + mRmTp_SetDefaultLightSwitchData(2); // TODO: enum + res = TRUE; + } + + return res; } static int mSDI_StartInitErr(GAME* game, int player_no, int malloc_flag) { - return TRUE; + return TRUE; } extern void mSDI_StartInitAfter(GAME* game, int renew_mode, int malloc_flag) { - GAME_PLAY* play = (GAME_PLAY*)game; - Animal_c* animals = Save_Get(animals); + GAME_PLAY* play = (GAME_PLAY*)game; + Animal_c* animals = Save_Get(animals); - Common_Set(house_owner_name, -1); - mEA_InitLetterCardE(); - Common_Set(last_field_id, -1); - mHm_SetNowHome(); - mNpc_RenewalAnimalMemory(); // - mNpc_ForceRemove(); // - mTM_renewal_renew_time(); - mEv_ClearEventInfo(); - mEnv_DecideWeather_NormalGameStart(); // - mMl_start_send_mail(); - mPO_first_work(play); - mTM_set_season(); - mAGrw_ClearAllShine_Stone(); // - mAGrw_RestoreStoneShine(Common_Get(player_no)); - mFAs_SetFieldRank(); - mEv_2nd_init(&play->event); - mNpc_Grow(); // - Kabu_manager(); - mNpc_InitNpcData(); - mNpc_InitNpcList(Common_Get(npclist), ANIMAL_NUM_MAX); // - mNpc_SetNpcList(Common_Get(npclist), animals, ANIMAL_NUM_MAX, malloc_flag); - mNpc_InitNpcList(Common_Get(island_npclist), 1); - mNpc_ClearTalkInfo(); // + Common_Set(house_owner_name, -1); + mEA_InitLetterCardE(); + Common_Set(last_field_id, -1); + mHm_SetNowHome(); + mNpc_RenewalAnimalMemory(); // + mNpc_ForceRemove(); // + mTM_renewal_renew_time(); + mEv_ClearEventInfo(); + mEnv_DecideWeather_NormalGameStart(); // + mMl_start_send_mail(); + mPO_first_work(play); + mTM_set_season(); + mAGrw_ClearAllShine_Stone(); // + mAGrw_RestoreStoneShine(Common_Get(player_no)); + mFAs_SetFieldRank(); + mEv_2nd_init(&play->event); + mNpc_Grow(); // + Kabu_manager(); + mNpc_InitNpcData(); + mNpc_InitNpcList(Common_Get(npclist), ANIMAL_NUM_MAX); // + mNpc_SetNpcList(Common_Get(npclist), animals, ANIMAL_NUM_MAX, malloc_flag); + mNpc_InitNpcList(Common_Get(island_npclist), 1); + mNpc_ClearTalkInfo(); // - if (renew_mode == 1) { - mFM_RenewalReserve(); // - } + if (renew_mode == 1) { + mFM_RenewalReserve(); // + } - mNpc_ChangePresentCloth(); // - mQst_ClearNotSaveQuest(Common_GetPointer(quest)); // - mGH_check_delete(); // - mMC_check_delete(); // - mFM_SetIslandNpcRoomData(game, malloc_flag); // - mCD_calendar_wellcome_on(); // - mPr_SetItemCollectBit(FTR_TAPEDECK); - mPr_SetItemCollectBit(FTR_COLLEGERULE); - mPr_SetItemCollectBit(FTR_ORANGEBOX); - mNPS_set_all_schedule_area(); // - mNpcW_InitNpcWalk(Common_GetPointer(npc_walk)); // - mHm_CheckRehouseOrder(); - decide_fish_location(Common_GetPointer(fish_location)); - mTRC_init(game); - Common_Set(goki_shocked_flag, FALSE); - mNtc_auto_nwrite_time_ct(); // - mPr_SendMailFromMother(); - mNpc_Remail(); // - mPr_SendForeingerAnimalMail(Common_Get(now_private)); - mPr_StartSetCompleteTalkInfo(); - mMsm_SendInformationMail(); // - mMsm_SendCompMail(); // - mFI_SetFirstSetShell(); // - mMsr_FirstClearMushroom(); - mSN_decide_msg(); // - mPr_RenewalMapInfo(Common_Get(now_private)->maps, mPr_FOREIGN_MAP_COUNT, Save_GetPointer(land_info)); - mSP_SetTanukiShopStatus(); // - mEnv_DecideTodayWindPowerRange(); // - mFI_SetClimate(mFI_CLIMATE_0); - mISL_RestoreIsland(); // - mNpc_SendHPMail(); // + mNpc_ChangePresentCloth(); // + mQst_ClearNotSaveQuest(Common_GetPointer(quest)); // + mGH_check_delete(); // + mMC_check_delete(); // + mFM_SetIslandNpcRoomData(game, malloc_flag); // + mCD_calendar_wellcome_on(); // + mPr_SetItemCollectBit(FTR_TAPEDECK); + mPr_SetItemCollectBit(FTR_COLLEGERULE); + mPr_SetItemCollectBit(FTR_ORANGEBOX); + mNPS_set_all_schedule_area(); // + mNpcW_InitNpcWalk(Common_GetPointer(npc_walk)); // + mHm_CheckRehouseOrder(); + decide_fish_location(Common_GetPointer(fish_location)); + mTRC_init(game); + Common_Set(goki_shocked_flag, FALSE); + mNtc_auto_nwrite_time_ct(); // + mPr_SendMailFromMother(); + mNpc_Remail(); // + mPr_SendForeingerAnimalMail(Common_Get(now_private)); + mPr_StartSetCompleteTalkInfo(); + mMsm_SendInformationMail(); // + mMsm_SendCompMail(); // + mFI_SetFirstSetShell(); // + mMsr_FirstClearMushroom(); + mSN_decide_msg(); // + mPr_RenewalMapInfo(Common_Get(now_private)->maps, mPr_FOREIGN_MAP_COUNT, Save_GetPointer(land_info)); + mSP_SetTanukiShopStatus(); // + mEnv_DecideTodayWindPowerRange(); // + mFI_SetClimate(mFI_CLIMATE_0); + mISL_RestoreIsland(); // + mNpc_SendHPMail(); // } typedef int (*mSDI_INIT_PROC)(GAME*, int, int); extern int mSDI_StartInitBefore(GAME* game, int player_no, int init_mode, int malloc_flag) { - static mSDI_INIT_PROC init_proc[mSDI_INIT_MODE_NUM] = { - &mSDI_StartInitNew, - &mSDI_StartInitNewPlayer, - &mSDI_StartInitFrom, - &mSDI_StartInitPak, - &mSDI_StartInitErr - }; - - mEv_UnSetGateway(); // - return (*init_proc[init_mode])(game, player_no, malloc_flag); + static mSDI_INIT_PROC init_proc[mSDI_INIT_MODE_NUM] = { &mSDI_StartInitNew, &mSDI_StartInitNewPlayer, + &mSDI_StartInitFrom, &mSDI_StartInitPak, + &mSDI_StartInitErr }; + + mEv_UnSetGateway(); // + return (*init_proc[init_mode])(game, player_no, malloc_flag); } extern int mSDI_StartDataInit(GAME* game, int player_no, int init_mode) { - static int renew_reserve_mode_table[mSDI_INIT_MODE_NUM] = { - TRUE, - FALSE, - FALSE, - FALSE, - FALSE - }; + static int renew_reserve_mode_table[mSDI_INIT_MODE_NUM] = { TRUE, FALSE, FALSE, FALSE, FALSE }; - int res; + int res; - if (init_mode < mSDI_INIT_MODE_NEW || init_mode >= mSDI_INIT_MODE_NUM) { - init_mode = mSDI_INIT_MODE_NEW; - } + if (init_mode < mSDI_INIT_MODE_NEW || init_mode >= mSDI_INIT_MODE_NUM) { + init_mode = mSDI_INIT_MODE_NEW; + } - res = mSDI_StartInitBefore(game, player_no, init_mode, mSDI_MALLOC_FLAG_ZELDA); - if (res == TRUE) { - mSDI_StartInitAfter(game, renew_reserve_mode_table[init_mode], mSDI_MALLOC_FLAG_ZELDA); - } + res = mSDI_StartInitBefore(game, player_no, init_mode, mSDI_MALLOC_FLAG_ZELDA); + if (res == TRUE) { + mSDI_StartInitAfter(game, renew_reserve_mode_table[init_mode], mSDI_MALLOC_FLAG_ZELDA); + } - return res; + return res; } diff --git a/src/main.c b/src/main.c index 3ab608c7..4a4afa76 100644 --- a/src/main.c +++ b/src/main.c @@ -16,28 +16,28 @@ #include "m_debug.h" #include "dolphin/os.h" #include "libforest/osreport.h" +#include "m_land.h" -//TODO: actually add all the stacks and headers +// TODO: actually add all the stacks and headers OSThread graphThread; static OSMessage serialMsgBuf; static OSMessageQueue l_serialMsgQ; u8 SegmentBaseAddress[0x40]; - int ScreenWidth = SCREEN_WIDTH; int ScreenHeight = SCREEN_HEIGHT; -extern void mainproc (void* val){ +extern void mainproc(void* val) { irqmgr_client_t irqClient; OSMessageQueue irqMgrMsgQueue; OSMessage irqMsgBuf[10]; OSMessage msg; - + ScreenWidth = SCREEN_WIDTH; ScreenHeight = SCREEN_HEIGHT; - + JW_BeginFrame(); JW_EndFrame(); mCD_init_card(); @@ -48,14 +48,13 @@ extern void mainproc (void* val){ irqmgr_AddClient(&irqClient, &irqMgrMsgQueue); memset(padmgrStack, 0xEB, PADMGR_STACK_SIZE); - padmgr_Create(&l_serialMsgQ, 7, 15, padmgrStack + PADMGR_STACK_SIZE, PADMGR_STACK_SIZE); - + osCreateThread2(&graphThread, 4, graph_proc, val, graphStack + GRAPH_STACK_SIZE, GRAPH_STACK_SIZE, 8); - + JW_BeginFrame(); JW_EndFrame(); - + osStartThread(&graphThread); osSetThreadPri(NULL, 5); @@ -63,7 +62,7 @@ extern void mainproc (void* val){ mMsg_aram_init2(); mLd_StartFlagOn(); famicom_mount_archive(); - + JC_JKRAramHeap_dump(JC_JKRAram_getAramHeap()); osSetThreadPri(NULL, 13); @@ -77,20 +76,17 @@ extern void mainproc (void* val){ } while (msg != NULL); } - u32 entry(void) { padmgr_Init(NULL); new_Debug_mode(); - + SETREG(SREG, 0, 0); mainproc(NULL); return 0; } - - -void foresta_main(void){ +void foresta_main(void) { OSReport("どうぶつの森 main2 開始\n"); HotStartEntry = &entry; }