diff --git a/include/audio_defs.h b/include/audio_defs.h index c79fbe40..8a730450 100644 --- a/include/audio_defs.h +++ b/include/audio_defs.h @@ -17,16 +17,19 @@ extern "C" { #define SE_FLAG_15(id) ((id) | 0x8000) // TODO: Make the rest of Sound Effects with parameters -#define SE_REGISTER MONO(0x50) +#define SE_REGISTER MONO(NA_SE_REGISTER) typedef enum audio_sound_effects { NA_SE_START, NA_SE_CURSOL, NA_SE_MENU_EXIT, + NA_SE_3 = 3, + NA_SE_ZOOMUP = 4, NA_SE_ZOOMDOWN_SHORT, + NA_SE_A = 0xA, NA_SE_PAGE_OKURI = 0xB, NA_SE_SENTAKU_OPEN, @@ -39,9 +42,13 @@ typedef enum audio_sound_effects { NA_SE_25 = 0x25, NA_SE_26 = 0x26, + NA_SE_2A = 0x2A, + NA_SE_MENU_PAUSE = 0x30, NA_SE_31 = 0x31, + NA_SE_33 = 0x33, + NA_SE_DRAWER_SHUT = 0x3A, NA_SE_ITEM_GET = 0x40, @@ -52,6 +59,8 @@ typedef enum audio_sound_effects { NA_SE_COIN, NA_SE_TEMOCHI_KAZAGURUMA, + NA_SE_REGISTER = 0x50, + NA_SE_52 = 0x52, NA_SE_ITEM_HORIDASHI = 0x57, @@ -61,6 +70,7 @@ typedef enum audio_sound_effects { NA_SE_AMI_HIT = 0x5C, NA_SE_TOOL_GET, + NA_SE_5F = 0x5F, NA_SE_60 = 0x60, NA_SE_GASAGOSO = 0x69, @@ -158,6 +168,9 @@ typedef enum audio_sound_effects { NA_SE_UMBRELLA_ROTATE = 0x432, + NA_SE_435 = 0x435, + NA_SE_436 = 0x436, + NA_SE_KARABURI = 0x43A, NA_SE_ROD_STROKE_SMALL = 0x445, diff --git a/include/m_common_data.h b/include/m_common_data.h index 192cd1e5..5a9674e1 100644 --- a/include/m_common_data.h +++ b/include/m_common_data.h @@ -356,6 +356,19 @@ extern common_data_t common_data; #define Get_Island() (Save_Get(island)) #define Get_Island_Villager() (Get_Island().animal) +#define GetRoomMusicBox() (Save_Get(scene_no) == SCENE_COTTAGE_MY \ + ? Save_Get(island).cottage.music_box \ + : Save_Get(homes[mHS_get_arrange_idx(Common_Get(player_no))]).music_box) +#define ChkMusicBox(box, n) (((box)[((n) / 32) & 1] >> ((n) & 31)) & 1) +#define SetMusicBox(box, n) ((box)[((n) / 32) & 1] |= (1 << ((n) & 31))) +#define ClrMusicBox(box, n) ((box)[((n) / 32) & 1] &= ~(u32)(1 << ((n) & 31))) +#define ChkRoomMusicBox(n) ChkMusicBox(GetRoomMusicBox(), n) +#define SetRoomMusicBox(n) SetMusicBox(GetRoomMusicBox(), n) +#define ClrRoomMusicBox(n) ClrMusicBox(GetRoomMusicBox(), n) + +#define CLIP(n) (Common_Get(clip).n) +#define aMR_CLIP (Common_Get(clip).my_room_clip) + extern void common_data_reinit(); extern void common_data_init(); extern void common_data_clear(); diff --git a/include/m_cpmail_ovl.h b/include/m_cpmail_ovl.h index f6c0b3a6..a771e9f5 100644 --- a/include/m_cpmail_ovl.h +++ b/include/m_cpmail_ovl.h @@ -24,7 +24,10 @@ struct cpmail_ovl_s { mCD_mail_c* card_mail; Mail_c player_mail[mPr_INVENTORY_MAIL_COUNT]; u8 page_order[mCM_PAGE_COUNT]; - u8 _BB0[0xBC4 - 0xBB0]; + u32 _BB0; + u32 mark_bitfield; + int mark_flag; + u8 _BBC[0xBC4 - 0xBBC]; }; extern void mCM_cpmail_ovl_construct(Submenu* submenu); diff --git a/include/m_haniwa_ovl.h b/include/m_haniwa_ovl.h index 18c9b07a..f01de02a 100644 --- a/include/m_haniwa_ovl.h +++ b/include/m_haniwa_ovl.h @@ -2,11 +2,30 @@ #define M_HANIWA_OVL_H #include "types.h" +#include "m_haniwa_ovl_h.h" +#include "m_tag_ovl.h" #ifdef __cplusplus extern "C" { #endif +#define mHW_OVL_MSG_SIZE 22 + +typedef void (*mHW_SET_INTERRUPT_MESSAGE_PROC)(Submenu*, mTG_tag_c*, int); + +struct haniwa_ovl_s { + int msg_idx; + int msg_interrupt_idx; + int table_idx; + int sub_idx; + int msg_time; + int msg_counter; + u32 msg_price; + u32 price; + u8 msg[mHW_OVL_MSG_SIZE]; + mHW_SET_INTERRUPT_MESSAGE_PROC set_interrupt_message_proc; +}; + extern void mHW_haniwa_ovl_construct(Submenu* submenu); extern void mHW_haniwa_ovl_destruct(Submenu* submenu); extern void mHW_haniwa_ovl_set_proc(Submenu* submenu); diff --git a/include/m_haniwa_ovl_h.h b/include/m_haniwa_ovl_h.h index accb48d5..c3c052ec 100644 --- a/include/m_haniwa_ovl_h.h +++ b/include/m_haniwa_ovl_h.h @@ -7,6 +7,8 @@ extern "C" { #endif +typedef struct haniwa_ovl_s mHW_Ovl_c; + #ifdef __cplusplus } #endif diff --git a/include/m_inventory_ovl.h b/include/m_inventory_ovl.h index 757d3a0d..d9cd9cce 100644 --- a/include/m_inventory_ovl.h +++ b/include/m_inventory_ovl.h @@ -96,8 +96,8 @@ struct inventory_ovl_s { mIV_pl_eff_c pl_eff[mIV_PLAYER_EFFECT_NUM]; mIV_SET_COLLECT_ITEMNO_PROC set_collect_itemNo_proc; u16 item_mark_bitfield; - u16 _5E2; - s16 _5E4; + u16 mail_mark_bitfield2; + s16 mail_mark_flag; u8 _5E6[2]; u16 mail_mark_bitfield; u8 original_flag; diff --git a/include/m_mailbox_ovl.h b/include/m_mailbox_ovl.h index 5e85bd13..0737d341 100644 --- a/include/m_mailbox_ovl.h +++ b/include/m_mailbox_ovl.h @@ -2,11 +2,25 @@ #define M_MAILBOX_OVL_H #include "types.h" +#include "m_mailbox_ovl_h.h" #ifdef __cplusplus extern "C" { #endif +typedef int (*mMB_GET_LAST_MAIL_IDX_PROC)(void); + +struct mailbox_ovl_s { + u8 open_flag; + u8 _01; + u8 display_flag; + u8 _03; + int _04; + u16 mark_bitfield; + int mark_flag; + mMB_GET_LAST_MAIL_IDX_PROC get_last_mail_idx_proc; +}; + extern void mMB_mailbox_ovl_construct(Submenu* submenu); extern void mMB_mailbox_ovl_destruct(Submenu* submenu); extern void mMB_mailbox_ovl_set_proc(Submenu* submenu); diff --git a/include/m_mailbox_ovl_h.h b/include/m_mailbox_ovl_h.h index 97c14269..6a709aec 100644 --- a/include/m_mailbox_ovl_h.h +++ b/include/m_mailbox_ovl_h.h @@ -7,6 +7,8 @@ extern "C" { #endif +typedef struct mailbox_ovl_s mMB_Ovl_c; + #ifdef __cplusplus } #endif diff --git a/include/m_music_ovl.h b/include/m_music_ovl.h index ec30c545..a589892c 100644 --- a/include/m_music_ovl.h +++ b/include/m_music_ovl.h @@ -9,7 +9,12 @@ extern "C" { #endif -struct music_ovl_s; +struct music_ovl_s { + u8 title[mIN_ITEM_NAME_LEN]; + s16 title_width; + mActor_name_t title_md_item; + u32 mark_flg[2]; +}; extern void mMU_music_ovl_set_proc(Submenu* submenu); extern void mMU_music_ovl_construct(Submenu* submenu); diff --git a/include/m_music_ovl_h.h b/include/m_music_ovl_h.h index f05013af..94c8200c 100644 --- a/include/m_music_ovl_h.h +++ b/include/m_music_ovl_h.h @@ -7,7 +7,7 @@ extern "C" { #endif -typedef struct music_ovl_s mMU_Overlay_c; +typedef struct music_ovl_s mMU_Ovl_c; #ifdef __cplusplus } diff --git a/include/m_name_table.h b/include/m_name_table.h index 344146f3..20beb1f6 100644 --- a/include/m_name_table.h +++ b/include/m_name_table.h @@ -526,6 +526,11 @@ extern int mNT_check_unknown(mActor_name_t item_no); #define ITEM_IS_SIGNBOARD(item) ((item) >= SIGNBOARD_START && (item) <= SIGNBOARD_END) +#define ITEM_IS_FLOWER_BAG(item) ((item) >= ITM_WHITE_PANSY_BAG && (item) <= ITM_YELLOW_TULIP_BAG) +#define ITEM_IS_EXERCISE_CARD(item) ((item) >= ITM_EXCERCISE_CARD00 && (item) <= ITM_EXCERCISE_CARD12) +#define ITEM_IS_BALLOON(item) ((item) >= ITM_BALLOON_START && (item) <= ITM_BUNNY_O_BALLOON) +#define ITEM_IS_UMBRELLA(item) ((item) >= ITM_UMBRELLA_START && (item) <= ITM_UMBRELLA_END) + #define BG_CATEGORY 0 #define ENV_CATEGORY 8 diff --git a/include/m_needlework.h b/include/m_needlework.h index 29b0b8a3..d69132cd 100644 --- a/include/m_needlework.h +++ b/include/m_needlework.h @@ -42,6 +42,13 @@ enum { mNW_PALETTE_NUM }; +enum { + mNW_TYPE_MANEKIN, + mNW_TYPE_UMBRELLA, + + mNW_TYPE_NUM +}; + typedef struct original_texture_s { u8 data[mNW_DESIGN_TEX_SIZE]; } ATTRIBUTE_ALIGN(32) mNW_original_tex_c; diff --git a/include/m_needlework_ovl.h b/include/m_needlework_ovl.h index 4c5076a8..4230ceba 100644 --- a/include/m_needlework_ovl.h +++ b/include/m_needlework_ovl.h @@ -3,11 +3,20 @@ #include "types.h" #include "m_submenu.h" +#include "m_needlework_ovl_h.h" +#include "m_needlework.h" #ifdef __cplusplus extern "C" { #endif +struct needlework_ovl_s { + u16 mark_flg; + u16 hide_flg; + mNW_original_design_c my_org[mPr_ORIGINAL_DESIGN_COUNT]; + u8 my_org_no_table[mPr_ORIGINAL_DESIGN_COUNT]; +}; + extern u8 mNW_get_image_no(Submenu* submenu, int slot_no); extern u8* mNW_get_image_name(Submenu* submenu, int idx); extern int mNW_check_hide_flg(Submenu* submenu, int idx); diff --git a/include/m_needlework_ovl_h.h b/include/m_needlework_ovl_h.h new file mode 100644 index 00000000..2dcd5d6c --- /dev/null +++ b/include/m_needlework_ovl_h.h @@ -0,0 +1,16 @@ +#ifndef M_NEEDLEWORK_OVL_H_H +#define M_NEEDLEWORK_OVL_H_H + +#include "types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct needlework_ovl_s mNW_Ovl_c; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/m_private.h b/include/m_private.h index aa52f30b..ba6acb74 100644 --- a/include/m_private.h +++ b/include/m_private.h @@ -291,14 +291,14 @@ extern int mPr_GetPossessionItemIdxItem1CategoryWithCond_cancel(Private_c* priv, mActor_name_t cancel_item); extern int mPr_GetPossessionItemIdxKindWithCond(Private_c* priv, mActor_name_t kind_start, mActor_name_t kind_end, u32 cond); -extern int mPr_GetPossessionItemSum(Private_c* priv, mActor_name_t item); -extern int mPr_GetPossessionItemSumWithCond(Private_c* priv, mActor_name_t item, u32 cond); -extern int mPr_GetPossessionItemSumFGTypeWithCond_cancel(Private_c* priv, mActor_name_t fg_type, u32 cond, +extern u32 mPr_GetPossessionItemSum(Private_c* priv, mActor_name_t item); +extern u32 mPr_GetPossessionItemSumWithCond(Private_c* priv, mActor_name_t item, u32 cond); +extern u32 mPr_GetPossessionItemSumFGTypeWithCond_cancel(Private_c* priv, mActor_name_t fg_type, u32 cond, mActor_name_t cancel_item); -extern int mPr_GetPossessionItemSumItemCategoryWithCond_cancel(Private_c* priv, u8 item1_type, u32 cond, +extern u32 mPr_GetPossessionItemSumItemCategoryWithCond_cancel(Private_c* priv, u8 item1_type, u32 cond, mActor_name_t cancel_item); -extern int mPr_GetPossessionItemSumItemCategoryWithCond(Private_c* priv, u8 item1_type, u32 cond); -extern int mPr_GetPossessionItemSumKindWithCond(Private_c* priv, mActor_name_t kind_start, mActor_name_t kind_end, +extern u32 mPr_GetPossessionItemSumItemCategoryWithCond(Private_c* priv, u8 item1_type, u32 cond); +extern u32 mPr_GetPossessionItemSumKindWithCond(Private_c* priv, mActor_name_t kind_start, mActor_name_t kind_end, u32 cond); extern void mPr_SetItemCollectBit(mActor_name_t item); extern mActor_name_t mPr_DummyPresentToTruePresent(); diff --git a/include/m_submenu_ovl.h b/include/m_submenu_ovl.h index 4227bbfa..dfd55e9e 100644 --- a/include/m_submenu_ovl.h +++ b/include/m_submenu_ovl.h @@ -31,6 +31,9 @@ #include "m_player.h" #include "m_cpmail_ovl_h.h" #include "m_cporiginal_ovl_h.h" +#include "m_haniwa_ovl_h.h" +#include "m_mailbox_ovl_h.h" +#include "m_needlework_ovl_h.h" #ifdef __cplusplus extern "C" { @@ -175,8 +178,8 @@ struct submenu_overlay_s { /* 0x98C */ mED_Ovl_c* editor_ovl; /* 0x990 */ mBD_Ovl_c* board_ovl; /* 0x994 */ mAD_Ovl_c* address_ovl; - /* 0x998 */ void* _998; - /* 0x99C */ void* _99C; + /* 0x998 */ mMB_Ovl_c* mailbox_ovl; + /* 0x99C */ mHW_Ovl_c* haniwa_ovl; /* 0x9A0 */ mTI_Ovl_c* timeIn_ovl; /* 0x9A4 */ mEE_Ovl_c* editEndChk_ovl; /* 0x9A8 */ mWR_Ovl_c* warning_ovl; @@ -189,9 +192,9 @@ struct submenu_overlay_s { /* 0x9C4 */ void* _9C4; /* 0x9C8 */ void* _9C8; /* 0x9CC */ mCL_Ovl_c* catalog_ovl; - /* 0x9D0 */ mMU_Overlay_c* music_ovl; + /* 0x9D0 */ mMU_Ovl_c* music_ovl; /* 0x9D4 */ mBN_Overlay_c* bank_ovl; - /* 0x9D8 */ void* needlework_ovl; + /* 0x9D8 */ mNW_Ovl_c* needlework_ovl; /* 0x9DC */ mCO_Ovl_c* cporiginal_ovl; /* 0x9E0 */ void* _9E0; /* 0x9E4 */ void* _9E4; diff --git a/include/m_tag_ovl.h b/include/m_tag_ovl.h index 068437f0..ba031322 100644 --- a/include/m_tag_ovl.h +++ b/include/m_tag_ovl.h @@ -15,6 +15,39 @@ extern "C" { #define mTG_TAG_FLAG_EDGE_FOOT_SELECT (1 << 0) +#define mTG_MAIL_FLAG_PRESENT (1 << 0) +#define mTG_MAIL_FLAG_RECV (1 << 1) + +enum { + mTG_MARK_CHK, + mTG_MARK_ON, + mTG_MARK_OFF, + mTG_MARK_RVS, + mTG_MARK_CLR, + mTG_MARK_CHK_ALL0, + + mTG_MARK_NUM +}; + +enum { + mTG_MARK_TYPE_NONE, + mTG_MARK_TYPE_INV_FG_ITEM, + mTG_MARK_TYPE_INV_PLAYERROOM_ITEM, + mTG_MARK_TYPE_INV_OTHERROOM_ITEM, + mTG_MARK_TYPE_INV_SELL_ITEM, + mTG_MARK_TYPE_INV_FG_MAIL, + mTG_MARK_TYPE_INV_MAILBOX, + mTG_MARK_TYPE_CPMAIL_MAIL, + mTG_MARK_TYPE_MAILBOX, + mTG_MARK_TYPE_CPMAIL_CPMAIL, + mTG_MARK_TYPE_MUSIC, + mTG_MARK_TYPE_NEEDLEWORK_ORIGINAL, + mTG_MARK_TYPE_CPORIGINAL_ORIGINAL, + + mTG_MARK_TYPE_NUM +}; + + enum { mTG_TYPE_NONE, mTG_TYPE_FIELD_DEFAULT, @@ -175,8 +208,8 @@ struct tag_ovl_s { /* 0x2F2 */ u8 _2F2[0x3C4 - 0x2F2]; }; -extern int mTG_mark_main(Submenu*, mSM_MenuInfo_c*, int, int); -extern int mTG_mark_mainX(Submenu*, mSM_MenuInfo_c*, int, int, int, int); +extern int mTG_mark_main(Submenu*, mSM_MenuInfo_c*, int, int*); +extern int mTG_mark_mainX(Submenu*, mSM_MenuInfo_c*, int, int, int, int*); extern void mTG_tag_ovl_construct(Submenu* submenu); extern void mTG_tag_ovl_destruct(Submenu* submenu); diff --git a/include/m_warning_ovl.h b/include/m_warning_ovl.h index a86f74ca..fa37463e 100644 --- a/include/m_warning_ovl.h +++ b/include/m_warning_ovl.h @@ -31,7 +31,7 @@ enum { mWR_WARNING_5, mWR_WARNING_6, mWR_WARNING_7, - mWR_WARNING_8, + mWR_WARNING_SELL_QUEST_ITEM, mWR_WARNING_PUT_MAX_FURNITURE, mWR_WARNING_PUT_FURNITURE, mWR_WARNING_PUT_ITEM, diff --git a/src/ac_my_room.c b/src/ac_my_room.c index cf152b2d..cd3e5c23 100644 --- a/src/ac_my_room.c +++ b/src/ac_my_room.c @@ -37,7 +37,6 @@ enum { #define aMR_FTR_BANK_NUM 100 #define aMR_FTR_BANK_SIZE 0x800 -#define aMR_CLIP (Common_Get(clip).my_room_clip) #define aMR_BOUNDS_OK(x, z) \ ((x) > (aMR_MIN_BOUND - 1) && (x) < (aMR_MAX_BOUND + 1) && (z) > (aMR_MIN_BOUND - 1) && (z) < (aMR_MAX_BOUND + 1)) diff --git a/src/m_hand_ovl.c b/src/m_hand_ovl.c index 8ad9a644..027dadab 100644 --- a/src/m_hand_ovl.c +++ b/src/m_hand_ovl.c @@ -564,8 +564,8 @@ static void mHD_open_end_proc_item_type6(Submenu* submenu, int idx, int table) { mHD_drop_item(submenu, tag, &Save_Get(homes[menu_info->data1]).haniwa.items[idx].item, NULL); if (flag == TRUE) { submenu->overlay->tag_ovl->item_name_wait_time = 0; - submenu->overlay->tag_ovl->chg_tag_func_proc(submenu, tag->table, mTG_TYPE_HANIWA_PUT_ITEM, 0, tag->pos[0], - tag->pos[1]); + submenu->overlay->tag_ovl->chg_tag_func_proc(submenu, tag->table, mTG_TYPE_HANIWA_PUT_ITEM, 0, tag->base_pos[0], + tag->base_pos[1]); } } diff --git a/src/m_inventory_ovl.c b/src/m_inventory_ovl.c index 59ef3b92..b30d6c55 100644 --- a/src/m_inventory_ovl.c +++ b/src/m_inventory_ovl.c @@ -1274,7 +1274,7 @@ static void mIV_move_Play(Submenu* submenu, mSM_MenuInfo_c* menu_info) { 0.0f, 0.0f); tag_ovl->item_name_wait_time = 0; submenu->overlay->tag_ovl->chg_tag_func_proc(submenu, mTG_TABLE_ITEM, mTG_TYPE_QUEST_ITEM, 0, - tag_ovl->tags[0].pos[0], tag_ovl->tags[0].pos[1]); + tag_ovl->tags[0].base_pos[0], tag_ovl->tags[0].base_pos[1]); break; case mSM_IV_OPEN_SEND_MAIL: submenu->overlay->tag_ovl->chg_tag_func_proc(submenu, mTG_TABLE_MAIL, mTG_TYPE_NONE, unselected_num, @@ -1708,10 +1708,10 @@ static void mIV_set_mail(Submenu* submenu, mSM_MenuInfo_c* menu_info, GRAPH* gra int menu_flag; int mark_flag; - if (inv_ovl->remove_timer > 0 && (tag->table == mTG_TABLE_MAIL || inv_ovl->_5E4 == 1)) { - if (inv_ovl->_5E4 == 1) { - select_mask = inv_ovl->_5E2; - } else if (inv_ovl->_5E4 == 0) { + if (inv_ovl->remove_timer > 0 && (tag->table == mTG_TABLE_MAIL || inv_ovl->mail_mark_flag == TRUE)) { + if (inv_ovl->mail_mark_flag == TRUE) { + select_mask = inv_ovl->mail_mark_bitfield2; + } else if (inv_ovl->mail_mark_flag == FALSE) { select_mask = 1 << tag_ovl->get_table_idx_proc(tag); } } @@ -1739,7 +1739,7 @@ static void mIV_set_mail(Submenu* submenu, mSM_MenuInfo_c* menu_info, GRAPH* gra scale = 1.0f; } - if ((inv_ovl->_5E2 & (1 << i)) != 0 && inv_ovl->_5E4 == 0) { + if ((inv_ovl->mail_mark_bitfield2 & (1 << i)) != 0 && inv_ovl->mail_mark_flag == FALSE) { mark_flag = TRUE; } else { mark_flag = FALSE; @@ -2079,9 +2079,9 @@ static void mIV_inventory_ovl_init(Submenu* submenu, mSM_MenuInfo_c* menu_info, inv_ovl->page_order[1] = mIV_PAGE_FISH_COLLECTION; inv_ovl->page_order[2] = mIV_PAGE_INSECT_COLLECTION; inv_ovl->page_move_timer = 0; - inv_ovl->_5E4 = 0; + inv_ovl->mail_mark_flag = FALSE; inv_ovl->item_mark_bitfield = 0; - inv_ovl->_5E2 = 0; + inv_ovl->mail_mark_bitfield2 = 0; inv_ovl->wc_flag = FALSE; if (menu_info->data0 == mSM_IV_OPEN_MAILBOX) { diff --git a/src/m_private.c b/src/m_private.c index e4a55652..aa80240c 100644 --- a/src/m_private.c +++ b/src/m_private.c @@ -436,7 +436,7 @@ extern int mPr_GetPossessionItemIdxKindWithCond(Private_c* priv, mActor_name_t k return idx; } -extern int mPr_GetPossessionItemSum(Private_c* priv, mActor_name_t item) { +extern u32 mPr_GetPossessionItemSum(Private_c* priv, mActor_name_t item) { int sum = 0; if (priv != NULL) { @@ -454,7 +454,7 @@ extern int mPr_GetPossessionItemSum(Private_c* priv, mActor_name_t item) { return sum; } -extern int mPr_GetPossessionItemSumWithCond(Private_c* priv, mActor_name_t item, u32 cond) { +extern u32 mPr_GetPossessionItemSumWithCond(Private_c* priv, mActor_name_t item, u32 cond) { int sum = 0; if (priv != NULL) { @@ -472,7 +472,7 @@ extern int mPr_GetPossessionItemSumWithCond(Private_c* priv, mActor_name_t item, return sum; } -extern int mPr_GetPossessionItemSumFGTypeWithCond_cancel(Private_c* priv, mActor_name_t fg_type, u32 cond, +extern u32 mPr_GetPossessionItemSumFGTypeWithCond_cancel(Private_c* priv, mActor_name_t fg_type, u32 cond, mActor_name_t cancel_item) { int sum = 0; @@ -492,7 +492,7 @@ extern int mPr_GetPossessionItemSumFGTypeWithCond_cancel(Private_c* priv, mActor return sum; } -extern int mPr_GetPossessionItemSumItemCategoryWithCond_cancel(Private_c* priv, u8 item1_type, u32 cond, +extern u32 mPr_GetPossessionItemSumItemCategoryWithCond_cancel(Private_c* priv, u8 item1_type, u32 cond, mActor_name_t cancel_item) { int sum = 0; @@ -512,7 +512,7 @@ extern int mPr_GetPossessionItemSumItemCategoryWithCond_cancel(Private_c* priv, return sum; } -extern int mPr_GetPossessionItemSumItemCategoryWithCond(Private_c* priv, u8 item1_type, u32 cond) { +extern u32 mPr_GetPossessionItemSumItemCategoryWithCond(Private_c* priv, u8 item1_type, u32 cond) { int sum = 0; if (priv != NULL) { @@ -531,7 +531,7 @@ extern int mPr_GetPossessionItemSumItemCategoryWithCond(Private_c* priv, u8 item return sum; } -extern int mPr_GetPossessionItemSumKindWithCond(Private_c* priv, mActor_name_t kind_start, mActor_name_t kind_end, +extern u32 mPr_GetPossessionItemSumKindWithCond(Private_c* priv, mActor_name_t kind_start, mActor_name_t kind_end, u32 cond) { int sum = 0; diff --git a/src/m_soncho.c b/src/m_soncho.c index 3dfdf8dd..7619467b 100644 --- a/src/m_soncho.c +++ b/src/m_soncho.c @@ -377,7 +377,9 @@ static mActor_name_t mSC_Radio_have_taisou_card() { Private_c* priv = Common_Get(now_private); for (i = 0; i < 13; i++) { - if (mPr_GetPossessionItemSumWithCond(priv, ITM_EXCERCISE_CARD00 + i, mPr_ITEM_COND_NORMAL) > 0) { + int sum = mPr_GetPossessionItemSumWithCond(priv, ITM_EXCERCISE_CARD00 + i, mPr_ITEM_COND_NORMAL); + + if (sum > 0) { return ITM_EXCERCISE_CARD00 + i; } } @@ -550,7 +552,7 @@ extern int mSC_Radio_Set_Talk_Proc(TAISOU_NPC0_ACTOR* taisou_actor) { msg_no = 0x3423; } - if ((u32)mPr_GetPossessionItemSumWithCond(Common_Get(now_private), EMPTY_NO, + if (mPr_GetPossessionItemSumWithCond(Common_Get(now_private), EMPTY_NO, mPr_ITEM_COND_NORMAL) == 0) { taisou_actor->talk_proc = mSCR_TALK_NEXT; } else { @@ -574,7 +576,7 @@ extern int mSC_Radio_Set_Talk_Proc(TAISOU_NPC0_ACTOR* taisou_actor) { msg_no = 0x342F; } - if ((u32)mPr_GetPossessionItemSumWithCond(Common_Get(now_private), EMPTY_NO, + if (mPr_GetPossessionItemSumWithCond(Common_Get(now_private), EMPTY_NO, mPr_ITEM_COND_NORMAL) == 0) { taisou_actor->talk_proc = mSCR_TALK_NEXT; } else { @@ -628,7 +630,7 @@ extern int mSC_Radio_Set_Talk_Proc(TAISOU_NPC0_ACTOR* taisou_actor) { msg_no = 0x342F; } - if ((u32)mPr_GetPossessionItemSumWithCond(Common_Get(now_private), EMPTY_NO, + if (mPr_GetPossessionItemSumWithCond(Common_Get(now_private), EMPTY_NO, mPr_ITEM_COND_NORMAL) == 0) { taisou_actor->talk_proc = mSCR_TALK_NEXT; } else { @@ -785,7 +787,7 @@ static void mSCR_talk_before_give(TAISOU_NPC0_ACTOR* taisou_actor, GAME_PLAY* pl mMsg_Window_c* msg_win = mMsg_Get_base_window_p(); if (mMsg_Check_MainNormalContinue(msg_win)) { - if ((u32)mPr_GetPossessionItemSumWithCond(Common_Get(now_private), EMPTY_NO, mPr_ITEM_COND_NORMAL) == 0) { + if (mPr_GetPossessionItemSumWithCond(Common_Get(now_private), EMPTY_NO, mPr_ITEM_COND_NORMAL) == 0) { mMsg_Set_continue_msg_num(msg_win, mSC_Radio_msg(taisou_actor, 2)); taisou_actor->talk_proc = mSCR_TALK_9; } else { diff --git a/src/m_tag_ovl.c b/src/m_tag_ovl.c index b4b070e2..6ef5f79a 100644 --- a/src/m_tag_ovl.c +++ b/src/m_tag_ovl.c @@ -12,6 +12,14 @@ #include "_mem.h" #include "m_lib.h" #include "m_item_name.h" +#include "ac_my_room.h" +#include "m_needlework.h" +#include "m_haniwa_ovl.h" +#include "m_player_lib.h" +#include "m_warning_ovl.h" +#include "m_mailbox_ovl.h" +#include "m_music_ovl.h" +#include "m_mark_room.h" static mTG_Ovl_c tag_ovl_data; @@ -21,8 +29,8 @@ typedef struct tag_word_s { } mTG_tag_word_c; typedef struct tag_data_s { - mTG_tag_word_c* words; /* array of words for each line */ - int lines; /* # of lines */ + mTG_tag_word_c** words; /* array of words for each line */ + int lines; /* # of lines */ } mTG_tag_data_c; typedef struct tag_table_data_s { @@ -59,7 +67,6 @@ static s16 mTG_cporiginal_ti_col_pos[] = { 32 }; static s16 mTG_gba_col_pos[] = { -97, -67, -37, -7 }; static s16 mTG_gba_nw_col_pos[] = { 48, 80 }; static s16 mTG_card_col_pos[] = { -45 }; -static s16 mTG_gba_nw_col_pos[] = { 48, 80 }; /* rows */ static s16 mTG_item_line_pos[] = { -10, -34, -58 }; @@ -71,7 +78,6 @@ static s16 mTG_mbox_line_pos[] = { 39, 15, -9, -33, -57 }; static s16 mTG_haniwa_line_pos[] = { 46 }; static s16 mTG_collect_line_pos[] = { 42, 18, -6, -30, -54 }; static s16 mTG_wchange_line_pos[] = { 37, 0, -37 }; -static s16 mTG_mail_line_pos[] = { 38, 14, -10, -34, -58 }; static s16 mTG_cpmail_wc_line_pos[] = { 50, 35, 20, 5, -10, -25, -40, -55 }; static s16 mTG_cpmail_ti_line_pos[] = { 71 }; static s16 mTG_cpedit_line_pos[] = { 50, 18, -14 }; @@ -88,7 +94,6 @@ static s16 mTG_cporiginal_ti_line_pos[] = { 74 }; static s16 mTG_gba_line_pos[] = { 6, -25 }; static s16 mTG_gba_nw_line_pos[] = { 40, 11, -18, -47 }; static s16 mTG_card_line_pos[] = { -10 }; -static s16 mTG_gba_nw_line_pos[] = { 40, 11, -18, -47 }; /* Data table */ static mTG_tag_data_table_c mTG_table_data[] = { @@ -1105,30 +1110,36 @@ static int mTG_check_hand_condition(Submenu* submenu) { } static f32 mTG_set_hand_pos_offset(Submenu* submenu, int table) { + f32 res = 0.0f; + if (submenu->overlay->needlework_ovl != NULL) { int nw_type = submenu->overlay->menu_info[mSM_OVL_NEEDLEWORK].data0; if (nw_type == 0) { - return 21.0f; + res = 21.0f; } else if (nw_type == 1 && table == mTG_TABLE_NEEDLEWORK) { - return 46.0f; + res = 46.0f; } } else if (submenu->overlay->inventory_ovl != NULL) { - if (submenu->overlay->menu_info[mSM_OVL_INVENTORY].data0 == mSM_IV_OPEN_MAILBOX) { - return -155.0f; + if (submenu->overlay->menu_info[mSM_OVL_INVENTORY].data0 == mSM_IV_OPEN_CPMAIL && table == mTG_TABLE_MAIL) { + res = -155.0f; } } - return 0.0f; + return res; } static void mTG_set_hand_pos(Submenu* submenu, f32* pos, int table, int idx) { mTG_tag_data_table_c* data_p = &mTG_table_data[table]; f32 ofs = mTG_set_hand_pos_offset(submenu, table); int col = idx % data_p->col_num; - int row = idx / data_p->col_num; + int row; + f32 pos_x = data_p->col_pos[col]; - pos[0] = data_p->col_pos[col] + ofs; + pos_x += ofs; + pos[0] = pos_x; + + row = idx / data_p->col_num; pos[1] = data_p->row_pos[row]; } @@ -1148,9 +1159,11 @@ static int mTG_get_tag_idx(Submenu* submenu, int type) { return -1; } -static void mTG_return_tag_init(Submenu* submenu, int ret_type, int type) { +static int mTG_return_tag_init(Submenu* submenu, int ret_type, int type) { mTG_Ovl_c* tag_ovl = submenu->overlay->tag_ovl; + mTG_tag_c* tag; int ret_idx = mTG_get_tag_idx(submenu, ret_type); + int i; if (ret_idx >= 0) { if (ret_idx == 0) { @@ -1160,8 +1173,7 @@ static void mTG_return_tag_init(Submenu* submenu, int ret_type, int type) { } if (type == mTG_TYPE_NONE) { - mTG_tag_c* tag = &tag_ovl->tags[tag_ovl->sel_tag_idx]; - int i; + tag = &tag_ovl->tags[tag_ovl->sel_tag_idx]; for (i = tag_ovl->sel_tag_idx - tag_ovl->ret_tag_idx; i != 0; i--) { tag->base_pos[0] += tag->body_ofs[0]; @@ -1172,36 +1184,41 @@ static void mTG_return_tag_init(Submenu* submenu, int ret_type, int type) { } } } + + return ret_idx; } static u16 mTG_get_item_name_wait_time(mTG_tag_c* tag) { - u16 time = 20; + u16 time; tag->scale = 0.0f; if (tag->table == mTG_TABLE_CATALOG_WC) { time = 16; + } else { + time = 20; } return time; } static void mTG_return_tag_func(Submenu* submenu, mTG_Ovl_c* tag_ovl, mTG_tag_c* tag) { + mTG_tag_c* now_tag = tag; int count = 0; int tag_num = tag_ovl->sel_tag_idx - tag_ovl->ret_tag_idx; int i; - for (i = tag_num; i >= 0; i--) { - tag->scale -= 0.125f; - if (tag->scale <= 0.0f) { - if (tag->type == mTG_TYPE_NONE) { - tag_ovl->item_name_wait_time = mTG_get_item_name_wait_time(tag); + for (i = tag_num; i != 0; i--) { + now_tag->scale -= 0.125f; + if (now_tag->scale <= 0.0f) { + if (now_tag->type == mTG_TYPE_NONE) { + tag_ovl->item_name_wait_time = mTG_get_item_name_wait_time(now_tag); } - tag->scale = 0.0f; + now_tag->scale = 0.0f; count++; } - tag--; + now_tag--; } if (count == tag_num) { @@ -1335,7 +1352,7 @@ static void mTG_set_tag_win_scale_p(mTG_tag_c* tag, int win_type, f32 x, f32 y) tag->arrow_scale[i] = 1.0f; tag->text_ofs[i] = win_data->_1C[i] + win_data->_24[i] * tag->_04[i] + win_data->_08[i] * tag->body_scale[i]; tag->body_ofs[i] = - arrow_data->ofs[i] + arrow_data->scale[i] * tag->_04[i] + win_data->_08[i] * tag->body_scale[i]; + (arrow_data->ofs[i] + arrow_data->scale[i] * tag->_04[i]) - win_data->_08[i] * tag->body_scale[i]; } } @@ -1359,7 +1376,7 @@ static int mTG_check_edge_right_item(mTG_tag_c* tag) { edge = 92.0f; } - if (tag->base_pos[0] + tag->body_ofs[0] + tag->body_scale[0] * edge >= 146.0f) { + if (tag->base_pos[0] + tag->body_ofs[0] + tag->body_scale[0] * edge <= 146.0f) { res = TRUE; } @@ -1367,28 +1384,32 @@ static int mTG_check_edge_right_item(mTG_tag_c* tag) { } static void mTG_calc_right_edge_select(mTG_tag_c* tag, f32* right_edge) { - f32 margin = tag->body_scale[0] * 122.5f; + f32 margin = tag->body_scale[0] * 122.5f * 0.5f; - *right_edge = margin * 0.5 + tag->base_pos[0] + tag->body_ofs[0]; + *right_edge = tag->base_pos[0] + tag->body_ofs[0] + margin; } static int mTG_check_edge_right_select(mTG_tag_c* tag, f32* right_edge) { - f32 margin = tag->body_scale[0] * 122.5f; + f32 margin = tag->body_scale[0] * 122.5f * 0.5f; + int res = FALSE; - *right_edge = (margin * 0.5 + tag->base_pos[0] + tag->body_ofs[0]) - 134.0f; + *right_edge = (tag->base_pos[0] + tag->body_ofs[0] + margin) - 134.0f; if (*right_edge <= 0.0f) { - return TRUE; + res = TRUE; } - return FALSE; + return res; } static int mTG_check_edge_foot_select(mTG_tag_c* tag) { + f32 margin = (tag->body_scale[1] * 129.5f) * 0.5f; + f32 tmp; int res = FALSE; + tmp = (tag->base_pos[1] + tag->body_ofs[1]) - margin; tag->flags &= ~mTG_TAG_FLAG_EDGE_FOOT_SELECT; - if ((tag->base_pos[1] + tag->body_ofs[1]) - (tag->body_scale[1] * 129.5f) * 0.5f - 3.0f >= -120.0f) { + if (tmp - 3.0f >= -120.0f) { tag->flags |= mTG_TAG_FLAG_EDGE_FOOT_SELECT; res = TRUE; } @@ -1396,16 +1417,16 @@ static int mTG_check_edge_foot_select(mTG_tag_c* tag) { return res; } -static int mTG_get_max_col_width_data(mTG_tag_word_c* tag_word, int lines) { +static int mTG_get_max_col_width_data(mTG_tag_word_c** tag_word, int lines) { int max_col_width = 0; int i; if (tag_word != NULL) { for (i = 0; i < lines; i++) { - int len = mMl_strlen(tag_word[i].str, mTG_TAG_STR_LEN, CHAR_SPACE); - int width = mFont_GetStringWidth(tag_word[i].str, len, TRUE); + int len = mMl_strlen(tag_word[i]->str, mTG_TAG_STR_LEN, CHAR_SPACE); + int width = mFont_GetStringWidth(tag_word[i]->str, len, TRUE); - if (max_col_width < width) { + if (width > max_col_width) { max_col_width = width; } } @@ -1433,7 +1454,7 @@ static void mTG_get_col_width_and_line_select(mTG_tag_c* tag, mTG_tag_data_c* ta *max_height = (f32)(tag_data->lines + 1) * 16.0f; width = mFont_GetStringWidth(mTG_tag_str_suteruno, sizeof(mTG_tag_str_suteruno), TRUE); - if (*max_width < width) { + if (width > *max_width) { *max_width = width; } break; @@ -1489,7 +1510,7 @@ static int mTG_strcat(u8* str0, u8* str1, int str0_max, int str1_max) { int str0_len = mMl_strlen(str0, str0_max, CHAR_SPACE); int str1_len = mMl_strlen(str1, str1_max, CHAR_SPACE); - if (str0_max < (str0_len + str1_len)) { + if ((str0_len + str1_len) > str0_max) { str1_len -= (str0_len + str1_len) - str0_max; } @@ -1524,16 +1545,15 @@ static int mTG_strcat_color(u8* str, u8* src, int str_max, int src_max, rgba_t* if ((str_max - src_len) - str_len > 1) { int col_len = mTG_strcat(str, font_color_base, str_max, sizeof(font_color_base)); - if (str_max < (col_len + src_len)) { + if ((col_len + src_len) > str_max) { src_len -= (col_len + src_len) - str_max; } - str += col_len; - str[-4] = color->r; - str[-3] = color->g; - str[-2] = color->b; - str[-1] = (u8)src_len; - memcpy(str, src, src_len); + str[col_len - 4] = color->r; + str[col_len - 3] = color->g; + str[col_len - 2] = color->b; + str[col_len - 1] = (u8)src_len; + memcpy(str + col_len, src, src_len); str_len = col_len + src_len; } @@ -1592,10 +1612,7 @@ static int mTG_init_tag_data_item_win_sub_mail_item_mail(mTG_tag_c* tag, mTG_str } static int mTG_init_tag_data_item_win_sub_mail_item_xmas(mTG_tag_c* tag, mTG_str_info_c* str_infos, Mail_c* mail) { - u8* src; - - src = mNpc_GetNpcWorldNameP(SP_NPC_SANTA); - mTG_strcpy(str_infos[1].str, src, mTG_TAG_SEL_STRING_LEN, PLAYER_NAME_LEN); + mTG_strcpy(str_infos[1].str, mNpc_GetNpcWorldNameP(SP_NPC_SANTA), mTG_TAG_SEL_STRING_LEN, PLAYER_NAME_LEN); str_infos[1].str_len = PLAYER_NAME_LEN; str_infos[1].color_idx = mTG_MAIL_NAME_COLOR_PURPLE; tag->str2_type = 5; @@ -1604,10 +1621,7 @@ static int mTG_init_tag_data_item_win_sub_mail_item_xmas(mTG_tag_c* tag, mTG_str } static int mTG_init_tag_data_item_win_sub_mail_item_tanukiti(mTG_tag_c* tag, mTG_str_info_c* str_infos, Mail_c* mail) { - u8* src; - - src = mNpc_GetNpcWorldNameP(SP_NPC_SHOP_MASTER); - mTG_strcpy(str_infos[1].str, src, mTG_TAG_SEL_STRING_LEN, PLAYER_NAME_LEN); + mTG_strcpy(str_infos[1].str, mNpc_GetNpcWorldNameP(SP_NPC_SHOP_MASTER), mTG_TAG_SEL_STRING_LEN, PLAYER_NAME_LEN); str_infos[1].str_len = PLAYER_NAME_LEN; str_infos[1].color_idx = mTG_MAIL_NAME_COLOR_INDIGO; tag->str2_type = 6; @@ -1616,10 +1630,7 @@ static int mTG_init_tag_data_item_win_sub_mail_item_tanukiti(mTG_tag_c* tag, mTG } static int mTG_init_tag_data_item_win_sub_mail_item_tunekiti(mTG_tag_c* tag, mTG_str_info_c* str_infos, Mail_c* mail) { - u8* src; - - src = mNpc_GetNpcWorldNameP(SP_NPC_BROKER); - mTG_strcpy(str_infos[1].str, src, mTG_TAG_SEL_STRING_LEN, PLAYER_NAME_LEN); + mTG_strcpy(str_infos[1].str, mNpc_GetNpcWorldNameP(SP_NPC_BROKER), mTG_TAG_SEL_STRING_LEN, PLAYER_NAME_LEN); str_infos[1].str_len = PLAYER_NAME_LEN; str_infos[1].color_idx = mTG_MAIL_NAME_COLOR_INDIGO; tag->str2_type = 6; @@ -1637,10 +1648,7 @@ static int mTG_init_tag_data_item_win_sub_mail_item_mother(mTG_tag_c* tag, mTG_s } static int mTG_init_tag_data_item_win_sub_mail_item_omikuji(mTG_tag_c* tag, mTG_str_info_c* str_infos, Mail_c* mail) { - u8* src; - - src = mNpc_GetNpcWorldNameP(SP_NPC_EV_MIKO); - mTG_strcpy(str_infos[1].str, src, mTG_TAG_SEL_STRING_LEN, PLAYER_NAME_LEN); + mTG_strcpy(str_infos[1].str, mNpc_GetNpcWorldNameP(SP_NPC_EV_MIKO), mTG_TAG_SEL_STRING_LEN, PLAYER_NAME_LEN); str_infos[1].str_len = PLAYER_NAME_LEN; str_infos[1].color_idx = mTG_MAIL_NAME_COLOR_INDIGO; tag->str2_type = 9; @@ -1658,10 +1666,7 @@ static int mTG_init_tag_data_item_win_sub_mail_item_happy(mTG_tag_c* tag, mTG_st } static int mTG_init_tag_data_item_win_sub_mail_item_snowman(mTG_tag_c* tag, mTG_str_info_c* str_infos, Mail_c* mail) { - u8* src; - - src = mNpc_GetNpcWorldNameP(ETC_SNOWMAN_BALL_A); - mTG_strcpy(str_infos[1].str, src, mTG_TAG_SEL_STRING_LEN, PLAYER_NAME_LEN); + mTG_strcpy(str_infos[1].str, mNpc_GetNpcWorldNameP(ETC_SNOWMAN_BALL_A), mTG_TAG_SEL_STRING_LEN, PLAYER_NAME_LEN); str_infos[1].str_len = PLAYER_NAME_LEN; str_infos[1].color_idx = mTG_MAIL_NAME_COLOR_PURPLE; tag->str2_type = 5; @@ -1670,10 +1675,7 @@ static int mTG_init_tag_data_item_win_sub_mail_item_snowman(mTG_tag_c* tag, mTG_ } static int mTG_init_tag_data_item_win_sub_mail_item_angler(mTG_tag_c* tag, mTG_str_info_c* str_infos, Mail_c* mail) { - u8* src; - - src = mNpc_GetNpcWorldNameP(SP_NPC_ANGLER); - mTG_strcpy(str_infos[1].str, src, mTG_TAG_SEL_STRING_LEN, PLAYER_NAME_LEN); + mTG_strcpy(str_infos[1].str, mNpc_GetNpcWorldNameP(SP_NPC_ANGLER), mTG_TAG_SEL_STRING_LEN, PLAYER_NAME_LEN); str_infos[1].str_len = PLAYER_NAME_LEN; str_infos[1].color_idx = mTG_MAIL_NAME_COLOR_PURPLE; tag->str2_type = 8; @@ -1869,15 +1871,16 @@ static void mTG_init_tag_data_item_win_sub_mail_item(Submenu* submenu, mTG_tag_c f32 str1_width = mFont_GetStringWidth2(tag->str1, str1_len, TRUE); f32 str2_width = mFont_GetStringWidth2(tag->str2, str2_len, TRUE); - if (width < str1_width) { + if (str1_width > width) { width = str1_width; } - if (width < str2_width) { + if (str2_width > width) { width = str2_width; } - mTG_set_tag_win_scale_p(tag, win_type, width * scale, 0.0f); + width *= scale; + mTG_set_tag_win_scale_p(tag, win_type, width, 0.0f); } if (win_type == mTG_WIN_TYPE_SELECT && mTG_quest_disp_up_check(tag) == FALSE && @@ -1931,11 +1934,12 @@ static void mTG_init_tag_data_set_itemNo(mActor_name_t* itemNo, Mail_c** mail_pp case mTG_TABLE_HANIWA: *itemNo = Save_Get(homes[submenu->overlay->menu_info[mSM_OVL_HANIWA].data1]).haniwa.items[idx].item; break; - case mTG_TABLE_COLLECT: + case mTG_TABLE_COLLECT: { mIV_Ovl_c* inv_ovl = submenu->overlay->inventory_ovl; *itemNo = inv_ovl->set_collect_itemNo_proc(idx, inv_ovl->page_order[0]); break; + } case mTG_TABLE_MAIL: case mTG_TABLE_MBOX: case mTG_TABLE_CPMAIL: @@ -2011,8 +2015,7 @@ static void mTG_init_tag_data_needlework_win(Submenu* submenu, int idx) { tag->str2_type = 0; if (tag->table == mTG_TABLE_CPORIGINAL) { - int top = mCO_top_folder(submenu); - int hide = mCO_check_hide_flg(submenu, top, idx); + int hide = mCO_check_hide_flg(submenu, mCO_top_folder(submenu), idx); if (hide) { tag->arrow_dir = 0; @@ -2120,9 +2123,9 @@ static void mTG_init_tag_data_select_win_only(mTG_tag_c* tag, mTG_tag_data_c* da { -0.875f, -26.25f }, }; + f32 dist_right; f32 max_width; f32 max_height; - f32 dist_right; int edge_right; int edge_foot; f32* min_ofs_p; @@ -2162,7 +2165,7 @@ static void mTG_init_tag_data_select_win_only(mTG_tag_c* tag, mTG_tag_data_c* da ofs_dis_p = other_arrow_offset_dis[idx]; tag->body_ofs[0] = min_ofs_p[0] + ofs_dis_p[0] * tag->_04[0] + tag->body_scale[0] * 61.25f * dir_x; - tag->body_ofs[1] = min_ofs_p[1] + ofs_dis_p[1] * tag->_04[1] + (tag->body_scale[1] * 61.25f - 6.0f) * dir_y; + tag->body_ofs[1] = min_ofs_p[1] + ofs_dis_p[1] * tag->_04[1] + (tag->body_scale[1] * 64.75f - 6.0f) * dir_y; } typedef struct add_item_data_s { @@ -2193,29 +2196,31 @@ static void mTG_init_tag_data_select_win_after_item(mTG_tag_c* tag, mTG_tag_c* i }; // clang-format on + int left_flag; mTG_add_item_data_c* data_p; - f32 max_width; - f32 max_height; f32 scale_x; f32 scale_y; - int left_flag; + f32 dist_right; + f32 max_width; + f32 max_height; + int tmp; + int idx; mTG_get_col_width_and_line_select(tag, tag_data, &max_width, &max_height); mTG_set_tag_win_scale_p(tag, mTG_WIN_TYPE_SELECT2, max_width * 0.875f, max_height * 0.875f); + left_flag = FALSE; if (item_tag->body_ofs[0] < 0.0f) { left_flag = TRUE; - } else { - left_flag = FALSE; } if (item_tag->str2_type != 0) { - scale_y = 68.0f; - scale_x = 184.0f; + scale_x = 68.0f; + scale_y = 184.0f; data_p = &tag_add_item_data[1]; } else { - scale_y = 28.0f; - scale_x = 129.5f; + scale_x = 28.0f; + scale_y = 129.5f; data_p = &tag_add_item_data[0]; } @@ -2226,5 +2231,2402 @@ static void mTG_init_tag_data_select_win_after_item(mTG_tag_c* tag, mTG_tag_c* i tag->base_pos[0] += item_tag->body_ofs[0] - item_tag->body_scale[0] * scale_x * 0.5f; tag->body_ofs[0] = tag->body_scale[0] * 122.5f * 0.5f; - // TODO + tmp = mTG_check_edge_foot_select(tag); + if (tmp && item_tag->table == mTG_TABLE_ITEM && item_tag->tag_row == 1 && mTG_label_table[tag->type].lines == 2) { + tmp = FALSE; + } + + if (tmp) { + tag->base_pos[0] += data_p->down_min[0][0] + item_tag->_04[0] * data_p->down_min[1][0]; + tag->body_ofs[0] += data_p->up_min[0][0] + tag->_04[0] * data_p->up_min[1][0]; + mTG_calc_right_edge_select(tag, &dist_right); + + idx = 0; + if (dist_right >= 131.0f) { + if (dist_right >= 167.0f) { + idx = 2; + } else { + idx = 1; + } + } + + if (idx == 2 || left_flag) { + f32 xofs; + + tag->base_pos[0] = + (item_tag->base_pos[0] + item_tag->body_ofs[0] + item_tag->body_scale[0] * scale_x * 0.5f) - + (data_p->down_min[0][0] + item_tag->_04[0] * data_p->down_min[1][0]); + tag->body_ofs[0] = + -(tag->body_scale[0] * 122.5f * 0.5f) - (data_p->up_min[0][0] + tag->_04[0] * data_p->up_min[1][0]); + xofs = (tag->base_pos[0] + tag->body_ofs[0] - tag->body_scale[0] * 122.5f * 0.5f) - -134.0f; + + if (xofs < 0.0f) { + tag->body_ofs[0] -= xofs; + } + } else if (idx == 1) { + tag->base_pos[0] -= (dist_right - 131.0f); + } + } else { + f32 yofs; + + tag->base_pos[1] = item_tag->base_pos[1] + item_tag->body_ofs[1] + item_tag->body_scale[1] * scale_y * 0.5f + + data_p->down_ofs[0][1] + item_tag->_04[1] * data_p->down_ofs[1][1]; + tag->body_ofs[1] = + (tag->body_scale[1] * 129.5f * 0.5f) + (data_p->up_ofs[0][1] + tag->_04[1] * data_p->up_ofs[1][1]); + yofs = (tag->base_pos[1] + tag->body_ofs[1] + tag->body_scale[1] * 129.5f * 0.5f); + + if (yofs > 120.0f) { + tag->base_pos[1] -= yofs - 120.0f; + } + + tag->base_pos[0] += data_p->down_ofs[0][0] + item_tag->_04[0] * data_p->down_ofs[1][0]; + tag->body_ofs[0] += data_p->up_ofs[0][0] + tag->_04[0] * data_p->up_ofs[1][0]; + + mTG_calc_right_edge_select(tag, &dist_right); + + idx = 0; + if (dist_right >= 131.0f) { + if (dist_right >= 167.0f) { + idx = 2; + } else { + idx = 1; + } + } + + if (idx == 2 || left_flag) { + f32 xofs; + + tag->base_pos[0] = + (item_tag->base_pos[0] + item_tag->body_ofs[0] + item_tag->body_scale[0] * scale_x * 0.5f) - + (data_p->down_ofs[0][0] + item_tag->_04[0] * data_p->down_ofs[1][0]); + tag->body_ofs[0] = + -(tag->body_scale[0] * 122.5f * 0.5f) - (data_p->up_ofs[0][0] + tag->_04[0] * data_p->up_ofs[1][0]); + xofs = (tag->base_pos[0] + tag->body_ofs[0] - tag->body_scale[0] * 122.5f * 0.5f) - -134.0f; + + if (xofs < 0.0f) { + tag->body_ofs[0] -= xofs; + } + } else if (idx == 1) { + tag->base_pos[0] -= (dist_right - 131.0f); + } + } + + tag->arrow_dir = 0; +} + +static void mTG_init_tag_data_select_win_after_select(mTG_tag_c* tag, mTG_tag_c* parent_tag, mTG_tag_data_c* tag_data) { + f32 dist_right; + f32 line; + f32 col; + f32 pos; + + mTG_get_col_width_and_line_select(tag, tag_data, &col, &line); + mTG_set_tag_win_scale_p(tag, mTG_WIN_TYPE_SELECT2, col * 0.875f, line * 0.875f); + tag->arrow_dir = 0; + pos = tag->base_pos[1]; + + tag->base_pos[0] += tag->_04[0] * -0.875f + -0.875f; + tag->base_pos[1] += tag->_04[1] * 8.75f + 6.125f; + tag->base_pos[1] -= 7.0f; + tag->body_ofs[0] = tag->body_scale[0] * 61.25f; + tag->body_ofs[1] = tag->body_scale[1] * -64.75f; + + if (mTG_check_edge_right_select(tag, &dist_right) == FALSE) { + tag->body_ofs[0] -= dist_right; + } + + if (mTG_check_edge_foot_select(tag) == FALSE) { + f32 tmp; + + tag->body_ofs[1] *= -1.0f; + tag->base_pos[1] = pos - (tag->_04[1] * 8.75f + 6.125f); + tag->base_pos[1] += 7.0f; + + tmp = tag->body_scale[1] * 129.5f * 0.5f + (tag->base_pos[1] + tag->body_ofs[1]); + if (tmp > 120.0f) { + tag->base_pos[1] -= tmp - 120.0f; + } + } +} + +static void mTG_init_tag_data(Submenu* submenu, int table, int type, f32 base_x, f32 base_y, int idx_x, int idx_y) { + mTG_Ovl_c* tag_ovl = submenu->overlay->tag_ovl; + mTG_tag_data_c* tag_data = &mTG_label_table[type]; + mTG_tag_c* tag = &tag_ovl->tags[tag_ovl->sel_tag_idx]; + mTG_tag_c* item_tag = &tag_ovl->tags[0]; + mTG_tag_c* parent_tag; + + if (tag_ovl->sel_tag_idx > 0) { + parent_tag = &tag_ovl->tags[tag_ovl->sel_tag_idx - 1]; + } else { + parent_tag = NULL; + } + + tag->type = type; + tag->table = table; + tag->tag_col = idx_x; + tag->tag_row = idx_y; + tag->scale = 0.0f; + + if (tag_ovl->sel_tag_idx == 0) { + mHD_Ovl_c* hand_ovl = submenu->overlay->hand_ovl; + int table_idx = mTG_get_table_idx(item_tag); + + hand_ovl->info.type = 1; + mTG_init_tag_data_item_win(submenu); + mTG_set_hand_pos(submenu, hand_ovl->info.pos, item_tag->table, table_idx); + } else { + tag->base_pos[0] = base_x; + tag->base_pos[1] = base_y; + + if (tag_ovl->sel_tag_idx == 1) { + if (item_tag->arrow_dir != 0) { + mTG_init_tag_data_select_win_after_item(tag, item_tag, tag_data); + } else { + mTG_init_tag_data_select_win_only(tag, tag_data); + } + } else { + mTG_init_tag_data_select_win_after_select(tag, parent_tag, tag_data); + } + } +} + +static void mTG_chg_tag_func(Submenu* submenu, int table, int type, int idx, f32 base_x, f32 base_y) { + mTG_Ovl_c* tag_ovl = submenu->overlay->tag_ovl; + mTG_tag_data_table_c* data_table = &mTG_table_data[table]; + int idx_x; + int idx_y; + + idx_y = idx / data_table->col_num; + idx_x = idx - (idx_y * data_table->col_num); + + if (tag_ovl->sel_tag_idx < 3) { + tag_ovl->sel_tag_idx++; + tag_ovl->ret_tag_idx = tag_ovl->sel_tag_idx; + mTG_init_tag_data(submenu, table, type, base_x, base_y, idx_x, idx_y); + } +} + +static void mTG_chg_tag_func2(Submenu* submenu, mSM_MenuInfo_c* menu_info, mTG_tag_c* tag, int type) { + // clang-format off + mTG_chg_tag_func( + submenu, + tag->table, + type, + 0, + tag->base_pos[0] + menu_info->position[0] + (tag->body_ofs[0] + tag->text_ofs[0] + -3.5f), + tag->base_pos[1] + menu_info->position[1] + ((tag->body_ofs[1] + tag->text_ofs[1] - tag->tag_row * 16.0f) - 8.0f) * 0.875f + ); + // clang-format on +} + +static int mTG_check_item_on_mail(mActor_name_t item, int cond) { + int res = TRUE; + + if (cond != mPr_ITEM_COND_NORMAL || + ((item >= ITM_EXCERCISE_CARD00 && item <= ITM_EXCERCISE_CARD12) || item == ITM_KNIFE_AND_FORK)) { + res = FALSE; + } else if (ITEM_IS_ITEM1(item)) { + int cat = ITEM_NAME_GET_CAT(item); + + if (cat == ITEM1_CAT_KABU || cat == ITEM1_CAT_FISH || cat == ITEM1_CAT_INSECT) { + res = FALSE; + } + } + + return res; +} + +static int mTG_check_put_unit(xyz_t* pos_p) { + GAME_PLAY* play = (GAME_PLAY*)gamePT; + int ux; + int uz; + int res = TRUE; + + mFI_Wpos2UtNum(&ux, &uz, *pos_p); + + if (mRlib_snowman_ball_unit_check_from_pos(play, pos_p)) { + res = FALSE; + } else if (mCoBG_CheckAcceptDesignSign(pos_p) == FALSE) { + res = FALSE; + } else { + mCoBG_Collision_u* col = mFI_UtNum2UtCol(ux, uz); + + if (mCoBG_GetHoleNumber_ClData(col) > 0) { + res = FALSE; + } + } + + return res; +} + +static int mTG_put_place_check(xyz_t* pos_p, int plant_flag, int unit_flag) { + int res = TRUE; + + if (unit_flag) { + res = mTG_check_put_unit(pos_p); + } + + if (res == TRUE) { + if (plant_flag) { + if (mCoBG_CheckPlant(*pos_p) == -1) { + res = FALSE; + } + } else { + res = mCoBG_CheckPlace(*pos_p); + } + } + + return res; +} + +static void mTG_check_direction_put_pos(int* dir_p) { + if (*dir_p < 0) { + (*dir_p) += 8; + } else if (*dir_p >= 8) { + (*dir_p) -= 8; + } +} + +static int mTG_check_wall_put_pos(const xyz_t* start_pos_p, const xyz_t* end_pos_p) { + mCoBG_Check_c bg_check; + int res = FALSE; + + bg_check.result.hit_wall = 0; + bg_check.result.hit_attribute_wall = 0; + + mCoBG_VirtualBGCheck(NULL, &bg_check, start_pos_p, end_pos_p, 0, FALSE, TRUE, 10.0f, -20.0f, 1, 1, 0); + if (bg_check.result.hit_wall != 0 || bg_check.result.hit_attribute_wall != 0) { + res = TRUE; + } + + return res; +} + +static int mTG_check_pos_slope(xyz_t* pos_p) { + // clang-format off + static f32 offset_pos[][2] = { + { 0.0f, mFI_UT_WORLDSIZE_Z_F }, + { mFI_UT_WORLDSIZE_X_F, mFI_UT_WORLDSIZE_Z_F }, + { mFI_UT_WORLDSIZE_X_F, 0.0f }, + { mFI_UT_WORLDSIZE_X_F, -mFI_UT_WORLDSIZE_Z_F }, + { 0.0f, -mFI_UT_WORLDSIZE_Z_F }, + { -mFI_UT_WORLDSIZE_X_F, -mFI_UT_WORLDSIZE_Z_F }, + { -mFI_UT_WORLDSIZE_X_F, 0.0f }, + { -mFI_UT_WORLDSIZE_X_F, mFI_UT_WORLDSIZE_Z_F }, + }; + // clang-format on + + int res = TRUE; + int i; + + for (i = 0; i < 8; i++) { + xyz_t pos; + mCoBG_Collision_u* col; + + pos.x = pos_p->x + offset_pos[i][0]; + pos.z = pos_p->z + offset_pos[i][1]; + pos.y = mCoBG_GetBgY_OnlyCenter_FromWpos2(pos, 0.0f); + + col = mFI_GetUnitCol(pos); + if (mCoBG_GetHoleNumber_ClData(col) > 0 || pos_p->y != pos.y) { + res = FALSE; + break; + } + } + + return res; +} + +// clang-format off +#define mTG_SEARCH_BAD_ITEM(item) ( \ + (item) == TREE_S0 || \ + (item) == TREE_S1 || \ + (item) == TREE_S2 || \ + (item) == TREE || \ + (item) == TREE_1000BELLS_S0 || \ + (item) == TREE_1000BELLS_S1 || \ + (item) == TREE_1000BELLS_S2 || \ + (item) == TREE_1000BELLS || \ + (item) == TREE_10000BELLS_S0 || \ + (item) == TREE_10000BELLS_S1 || \ + (item) == TREE_10000BELLS_S2 || \ + (item) == TREE_10000BELLS || \ + (item) == TREE_30000BELLS_S0 || \ + (item) == TREE_30000BELLS_S1 || \ + (item) == TREE_30000BELLS_S2 || \ + (item) == TREE_30000BELLS || \ + (item) == TREE_100BELLS_S0 || \ + (item) == TREE_100BELLS_S1 || \ + (item) == TREE_100BELLS_S2 || \ + (item) == TREE_100BELLS || \ + (item) == CEDAR_TREE_S0 || \ + (item) == CEDAR_TREE_S1 || \ + (item) == CEDAR_TREE_S2 || \ + (item) == CEDAR_TREE || \ + (item) == GOLD_TREE_S0 || \ + (item) == GOLD_TREE_S1 || \ + (item) == GOLD_TREE_S2 || \ + (item) == GOLD_TREE || \ + (item) == GOLD_TREE_SHOVEL || \ + (item) == TREE_APPLE_S0 || \ + (item) == TREE_APPLE_S1 || \ + (item) == TREE_APPLE_S2 || \ + (item) == TREE_APPLE_NOFRUIT_0 || \ + (item) == TREE_APPLE_NOFRUIT_1 || \ + (item) == TREE_APPLE_NOFRUIT_2 || \ + (item) == TREE_APPLE_FRUIT || \ + (item) == TREE_ORANGE_S0 || \ + (item) == TREE_ORANGE_S1 || \ + (item) == TREE_ORANGE_S2 || \ + (item) == TREE_ORANGE_NOFRUIT_0 || \ + (item) == TREE_ORANGE_NOFRUIT_1 || \ + (item) == TREE_ORANGE_NOFRUIT_2 || \ + (item) == TREE_ORANGE_FRUIT || \ + (item) == TREE_PEACH_S0 || \ + (item) == TREE_PEACH_S1 || \ + (item) == TREE_PEACH_S2 || \ + (item) == TREE_PEACH_NOFRUIT_0 || \ + (item) == TREE_PEACH_NOFRUIT_1 || \ + (item) == TREE_PEACH_NOFRUIT_2 || \ + (item) == TREE_PEACH_FRUIT || \ + (item) == TREE_PEAR_S0 || \ + (item) == TREE_PEAR_S1 || \ + (item) == TREE_PEAR_S2 || \ + (item) == TREE_PEAR_NOFRUIT_0 || \ + (item) == TREE_PEAR_NOFRUIT_1 || \ + (item) == TREE_PEAR_NOFRUIT_2 || \ + (item) == TREE_PEAR_FRUIT || \ + (item) == TREE_CHERRY_S0 || \ + (item) == TREE_CHERRY_S1 || \ + (item) == TREE_CHERRY_S2 || \ + (item) == TREE_CHERRY_NOFRUIT_0 || \ + (item) == TREE_CHERRY_NOFRUIT_1 || \ + (item) == TREE_CHERRY_NOFRUIT_2 || \ + (item) == TREE_CHERRY_FRUIT || \ + (item) == TREE_PALM_S0 || \ + (item) == TREE_PALM_S1 || \ + (item) == TREE_PALM_S2 || \ + (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) == GOLD_TREE_BELLS || \ + (item) == GOLD_TREE_FTR || \ + (item) == GOLD_TREE_BEES || \ + (item) == CEDAR_TREE_LIGHTS || \ + ITEM_IS_HOLE((item)) || \ + (item) == HOLE_SHINE || \ + IS_ITEM_TREE_STUMP((item)) \ +) +// clang-format on + +static int mTG_search_put_pos2(ACTOR* player_actor, xyz_t* pos_tbl, int plant_flag, int param_4, int num_pos, + int param_6, int unit_flag, int param_8) { + // clang-format off + static f32 offset_pos[][2] = { + { 0.0f, mFI_UT_WORLDSIZE_Z_F }, + { mFI_UT_WORLDSIZE_X_F, mFI_UT_WORLDSIZE_Z_F }, + { mFI_UT_WORLDSIZE_X_F, 0.0f }, + { mFI_UT_WORLDSIZE_X_F, -mFI_UT_WORLDSIZE_Z_F }, + { 0.0f, -mFI_UT_WORLDSIZE_Z_F }, + { -mFI_UT_WORLDSIZE_X_F, -mFI_UT_WORLDSIZE_Z_F }, + { -mFI_UT_WORLDSIZE_X_F, 0.0f }, + { -mFI_UT_WORLDSIZE_X_F, mFI_UT_WORLDSIZE_Z_F }, + }; + // clang-format on + xyz_t pos; + xyz_t center_pos; + xyz_t pos2; + xyz_t start_pos; + int unit; + int next_unit; + mActor_name_t* fg_p; + s16 player_angle_y; + int max; + int i; + int count; + + pos2.x = player_actor->world.position.x; + pos2.z = player_actor->world.position.z; + pos2.y = player_actor->world.position.y; + count = 0; + + mFI_Wpos2UtCenterWpos(¢er_pos, pos2); + center_pos.y = mCoBG_Wpos2BgUtCenterHeight_AddColumn(center_pos); + fg_p = mFI_GetUnitFG(center_pos); + + if (param_6 == 0 && param_4 == 0 && fg_p != NULL && *fg_p == EMPTY_NO && + mTG_put_place_check(¢er_pos, plant_flag, unit_flag)) { + xyz_t_move(pos_tbl, ¢er_pos); + pos_tbl++; + count = 1; + } + + player_angle_y = player_actor->shape_info.rotation.y; + + if (player_angle_y > DEG2SHORT_ANGLE2(157.5f) || player_angle_y <= DEG2SHORT_ANGLE2(-157.5f)) { + unit = 4; + } else if (player_angle_y > DEG2SHORT_ANGLE2(112.5f)) { + unit = 3; + } else if (player_angle_y > DEG2SHORT_ANGLE2(67.5f)) { + unit = 2; + } else if (player_angle_y > DEG2SHORT_ANGLE2(22.5f)) { + unit = 1; + } else if (player_angle_y > DEG2SHORT_ANGLE2(-22.5f)) { + unit = 0; + } else if (player_angle_y > DEG2SHORT_ANGLE2(-67.5f)) { + unit = 7; + } else if (player_angle_y > DEG2SHORT_ANGLE2(-112.5f)) { + unit = 6; + } else { + unit = 5; + } + + max = param_8 ? 5 : 8; + for (i = 0; i < max && count < num_pos; i++) { + mActor_name_t* fg_p; + + if (i & 1) { + unit += i; + } else { + unit -= i; + } + + mTG_check_direction_put_pos(&unit); + pos.x = center_pos.x + offset_pos[unit][0]; + pos.z = center_pos.z + offset_pos[unit][1]; + pos.y = mCoBG_Wpos2BgUtCenterHeight_AddColumn(pos); + + fg_p = mFI_GetUnitFG(pos); + if (fg_p != NULL && *fg_p == EMPTY_NO && mTG_put_place_check(&pos, plant_flag, unit_flag) && + (unit_flag == FALSE || (unit_flag != FALSE && mTG_check_pos_slope(&pos)))) { + start_pos = player_actor->world.position; + start_pos.y -= 20.0f; + + if ((unit & 1)) { + mActor_name_t* fg_p; + + next_unit = unit + 1; + mTG_check_direction_put_pos(&next_unit); + + pos2.x = center_pos.x + offset_pos[next_unit][0]; + pos2.z = center_pos.z + offset_pos[next_unit][1]; + pos2.y = mCoBG_Wpos2BgUtCenterHeight_AddColumn(pos2); + + fg_p = mFI_GetUnitFG(pos2); + if (fg_p != NULL && !mTG_SEARCH_BAD_ITEM(*fg_p) && mTG_check_wall_put_pos(&start_pos, &pos2) == FALSE && + mTG_check_wall_put_pos(&pos2, &pos) == FALSE) { + xyz_t_move(pos_tbl, &pos); + count++; + pos_tbl++; + } else { + next_unit = unit - 1; + mTG_check_direction_put_pos(&next_unit); + + pos2.x = center_pos.x + offset_pos[next_unit][0]; + pos2.z = center_pos.z + offset_pos[next_unit][1]; + pos2.y = mCoBG_Wpos2BgUtCenterHeight_AddColumn(pos2); + + fg_p = mFI_GetUnitFG(pos2); + if (fg_p != NULL && !mTG_SEARCH_BAD_ITEM(*fg_p) && + mTG_check_wall_put_pos(&start_pos, &pos2) == FALSE && + mTG_check_wall_put_pos(&pos2, &pos) == FALSE) { + xyz_t_move(pos_tbl, &pos); + count++; + pos_tbl++; + } + } + } else { + if (mTG_check_wall_put_pos(&start_pos, &pos) == FALSE) { + xyz_t_move(pos_tbl, &pos); + count++; + pos_tbl++; + } + } + } + } + + return count; +} + +static int mTG_search_put_pos(ACTOR* player_actor, xyz_t* pos_tbl, int plant_flag, int param_4, int param_5, + int unit_flag, int param_7) { + return mTG_search_put_pos2(player_actor, pos_tbl, plant_flag, param_4, 1, param_5, unit_flag, param_7); +} + +static void mTG_open_warning_window(Submenu* submenu, mSM_MenuInfo_c* menu_info, int type) { + mSM_open_submenu(submenu, mSM_OVL_WARNING, type, 0); + menu_info->proc_status = mSM_OVL_PROC_WAIT; + menu_info->next_proc_status = mSM_OVL_PROC_WAIT; + mTG_return_tag_init(submenu, mTG_TYPE_NONE, mTG_TYPE_NONE); + sAdo_SysTrgStart(MONO(NA_SE_3)); +} + +static int mTG_common_throw_put_field(GAME_PLAY* play, mActor_name_t item, xyz_t* pos_p, s16 layer) { + int res = FALSE; + + if (item == ITM_SIGNBOARD) { + res = aSIGN_set_white_sign(&play->game, pos_p); + } else { + int ux; + int uz; + + if (mFI_Wpos2UtNum(&ux, &uz, *pos_p) && Common_Get(clip).bg_item_clip != NULL && + Common_Get(clip).bg_item_clip->player_drop_entry_proc != NULL) { + res = Common_Get(clip).bg_item_clip->player_drop_entry_proc(&play->game, item, ux, uz, layer); + } + } + + return res; +} + +static int mTG_common_throw_put_room(GAME_PLAY* play, mActor_name_t item, xyz_t* pos_p, int layer, int delay_timer) { + int ux; + int uz; + int res = FALSE; + + if (mFI_Wpos2UtNum(&ux, &uz, *pos_p) && Common_Get(clip).shop_goods_clip != NULL && + Common_Get(clip).shop_goods_clip->player_drop_entry_proc != NULL) { + res = Common_Get(clip).shop_goods_clip->player_drop_entry_proc(&play->game, item, ux, uz, layer, delay_timer); + } + + return res; +} + +static void mTG_close_window(Submenu* submenu, mSM_MenuInfo_c* menu_info, int se_flag) { + submenu->overlay->move_chg_base_proc(menu_info, mSM_OVL_PROC_MOVE); + if (se_flag) { + sAdo_SysTrgStart(NA_SE_31); + } +} + +static void mTG_open_board_init(Submenu* submenu, mSM_MenuInfo_c* menu_info, int mail_idx, int type, int item_idx) { + mTG_Ovl_c* tag_ovl = submenu->overlay->tag_ovl; + mTG_tag_c* item_tag = &tag_ovl->tags[0]; + Mail_c* mail; + + if (mail_idx == -1) { + mail = mTG_get_mail_pointer(submenu, NULL); + } else { + mail = &Now_Private->mail[mail_idx]; + } + + tag_ovl->sel_tag_idx = 0; + tag_ovl->ret_tag_idx = 0; + tag_ovl->item_name_wait_time = mTG_get_item_name_wait_time(item_tag); + + mSM_open_submenu_new(submenu, mSM_OVL_BOARD, type, item_idx, mail); + + menu_info->proc_status = mSM_OVL_PROC_MOVE; + menu_info->next_proc_status = mSM_OVL_PROC_WAIT; + menu_info->move_drt = mSM_MOVE_OUT_LEFT; + sAdo_SysTrgStart(NA_SE_5F); +} + +static void mTG_set_catch_se(Submenu* submenu) { + if (submenu->overlay->tag_ovl->sel_tag_idx == 0) { + sAdo_SysTrgStart(NA_SE_33); + } else { + sAdo_SysTrgStart(NA_SE_33); + } +} + +static void mTG_catch_item_from_table(Submenu* submenu, Mail_c* mail, mActor_name_t* item, int item_cond, int table, + int table_idx) { + mHD_Ovl_c* hand_ovl = submenu->overlay->hand_ovl; + + if (table == mTG_TABLE_PLAYER) { + hand_ovl->info.wait_timer = 16; + submenu->overlay->segment.change_player_main_anime_idx = mIV_ANIM_CATCH; + } else if (table == mTG_TABLE_NEEDLEWORK || table == mTG_TABLE_CPORIGINAL_NW) { + hand_ovl->info.next_act = mHD_ACTION_CLOSE; + hand_ovl->info.hold_tbl = table; + hand_ovl->info.hold_idx = table_idx; + hand_ovl->info.item = *item; + hand_ovl->info.item_cond = item_cond; + *item = EMPTY_NO; + mNW_on_hide_flg(submenu, table_idx); + } else if (table == mTG_TABLE_CPORIGINAL) { + int top = mCO_top_folder(submenu); + + hand_ovl->info.next_act = mHD_ACTION_CLOSE; + hand_ovl->info.hold_tbl = table; + hand_ovl->info.hold_idx = table_idx; + hand_ovl->info.item = *item; + hand_ovl->info.item_cond = item_cond; + hand_ovl->info.catch_pg = top; + *item = EMPTY_NO; + mCO_on_hide_flg(submenu, top, table_idx); + } else { + hand_ovl->info.next_act = mHD_ACTION_CLOSE; + hand_ovl->info.hold_tbl = table; + hand_ovl->info.hold_idx = table_idx; + + if (table == mTG_TABLE_CPMAIL) { + hand_ovl->info.catch_pg = submenu->overlay->cpmail_ovl->page_order[0]; + } else { + hand_ovl->info.catch_pg = 0; + } + + if (mail != NULL) { + mMl_copy_mail(&hand_ovl->info.mail, mail); + mMl_clear_mail(mail); + } else { + hand_ovl->info.item = *item; + hand_ovl->info.item_cond = item_cond; + + if (table == mTG_TABLE_ITEM) { + mPr_SetPossessionItem(Now_Private, table_idx, EMPTY_NO, mPr_ITEM_COND_NORMAL); + } else { + *item = EMPTY_NO; + } + } + } + + mTG_return_tag_init(submenu, mTG_TYPE_NONE, mTG_TYPE_NONE); + mTG_set_catch_se(submenu); +} + +static int mTG_itemNo_to_amount(mActor_name_t itemNo) { + switch (itemNo) { + case ITM_MONEY_1000: + return 1000; + case ITM_MONEY_10000: + return 10000; + case ITM_MONEY_30000: + return 30000; + case ITM_MONEY_100: + return 100; + default: + return 0; + } +} + +static int mTG_make_money_sack(Submenu* submenu, mSM_MenuInfo_c* menu_info, mActor_name_t item) { + u32* money_p = &Now_Private->inventory.wallet; + int amount = mTG_itemNo_to_amount(item); + int res = FALSE; + + if ((int)*money_p >= amount) { + mHD_Ovl_c* hand_ovl = submenu->overlay->hand_ovl; + + *money_p -= amount; + hand_ovl->info.next_act = mHD_ACTION_CLOSE; + hand_ovl->info.item = item; + hand_ovl->info.item_cond = mPr_ITEM_COND_NORMAL; + hand_ovl->info.wait_timer = 42; + hand_ovl->info.hold_tbl = mTG_TABLE_MONEY; + hand_ovl->info.hold_idx = 0; + hand_ovl->info.catch_pg = 0; + mTG_mark_main_CLR(submenu, menu_info); + mTG_return_tag_init(submenu, mTG_TYPE_NONE, mTG_TYPE_NONE); + submenu->overlay->inventory_ovl->disp_money_change_frames = -(amount / 42); + sAdo_SysTrgStart(MONO(NA_SE_52)); + res = TRUE; + } + + return res; +} + +static int mTG_drop_furniture(GAME_PLAY* play, mActor_name_t item) { + int idx = -1; + + if (aMR_CLIP != NULL) { + GAME* game = (GAME*)play; + int sq_ofs; + int layer; + int ux; + int uz; + u16 rot; + u16 ftrIdx = mRmTp_FtrItemNo2FtrIdx(item); + + idx = aMR_CLIP->judge_breed_new_ftr_proc(game, ftrIdx, &ux, &uz, &rot, &sq_ofs, &layer); + if (idx >= 0) { + aMR_CLIP->reserve_ftr_proc(game, ftrIdx, idx, ux, uz, rot, sq_ofs, layer); + } + } + + return idx; +} + +static int mTG_nw_drop_furniture(GAME_PLAY* play, int image_no, mActor_name_t itemNo) { + GAME* game = (GAME*)play; + int idx = -1; + int sq_ofs; + int layer; + int ux; + int uz; + u16 rot; + + switch (image_no) { + case mNW_TYPE_MANEKIN: + idx = aMR_CLIP->judge_breed_new_ftr_proc(game, 0x2EA + (itemNo & 7), &ux, &uz, &rot, &sq_ofs, &layer); + break; + case mNW_TYPE_UMBRELLA: + idx = aMR_CLIP->judge_breed_new_ftr_proc(game, 0x362 + (itemNo & 7), &ux, &uz, &rot, &sq_ofs, &layer); + break; + } + + if (idx >= 0) { + switch (image_no) { + case mNW_TYPE_MANEKIN: + aMR_CLIP->reserve_ftr_proc(game, 0x2EA + (itemNo & 7), idx, ux, uz, rot, sq_ofs, layer); + break; + case mNW_TYPE_UMBRELLA: + aMR_CLIP->reserve_ftr_proc(game, 0x362 + (itemNo & 7), idx, ux, uz, rot, sq_ofs, layer); + break; + } + } + + return idx; +} + +static int mTG_get_unit_front_player(xyz_t* pos_p, const xyz_t* player_pos, s16 angle_y) { + int dir; + static f32 offset_pos[][2] = { + // clang-format off + { 0.0f, mFI_UT_WORLDSIZE_Z_F }, + { mFI_UT_WORLDSIZE_X_F, mFI_UT_WORLDSIZE_Z_F }, + { mFI_UT_WORLDSIZE_X_F, 0.0f }, + { mFI_UT_WORLDSIZE_X_F, -mFI_UT_WORLDSIZE_Z_F }, + { 0.0f, -mFI_UT_WORLDSIZE_Z_F }, + { -mFI_UT_WORLDSIZE_X_F, -mFI_UT_WORLDSIZE_Z_F }, + { -mFI_UT_WORLDSIZE_X_F, 0.0f }, + { -mFI_UT_WORLDSIZE_X_F, mFI_UT_WORLDSIZE_Z_F }, + // clang-format on + }; + + if (angle_y > DEG2SHORT_ANGLE2(157.5f) || angle_y <= DEG2SHORT_ANGLE2(-157.5f)) { + dir = 4; + } else if (angle_y > DEG2SHORT_ANGLE2(112.5f)) { + dir = 3; + } else if (angle_y > DEG2SHORT_ANGLE2(67.5f)) { + dir = 2; + } else if (angle_y > DEG2SHORT_ANGLE2(22.5f)) { + dir = 1; + } else if (angle_y > DEG2SHORT_ANGLE2(-22.5f)) { + dir = 0; + } else if (angle_y > DEG2SHORT_ANGLE2(-67.5f)) { + dir = 7; + } else if (angle_y > DEG2SHORT_ANGLE2(-112.5f)) { + dir = 6; + } else { + dir = 5; + } + + pos_p->x = player_pos->x + offset_pos[dir][0]; + pos_p->y = player_pos->y; + pos_p->z = player_pos->z + offset_pos[dir][1]; +} + +static int mTG_check_free_2nd_layer(const xyz_t* pos_p) { + int bx; + int bz; + int ux; + int uz; + mActor_name_t* fg_p; + int res = FALSE; + + if (mFI_Wpos2BlockNum(&bx, &bz, *pos_p) && mFI_Wpos2UtNum_inBlock(&ux, &uz, *pos_p)) { + fg_p = mFI_BkNum2UtFGTop_layer(bx, bz, mCoBG_LAYER1); + if (fg_p != NULL && fg_p[ux + uz * UT_X_NUM] == EMPTY_NO) { + res = TRUE; + } + } + + return res; +} + +static void mTG_set_trade_cond(Submenu* submenu, mSM_MenuInfo_c* menu_info, s16 cond, u32 arg) { + mTG_tag_c* tag = &submenu->overlay->tag_ovl->tags[0]; + + Save_Get(homes[menu_info->data1]).haniwa.items[tag->tag_col].exchange_type = cond; + Save_Get(homes[menu_info->data1]).haniwa.items[tag->tag_col].extra_data = arg; + mTG_return_tag_init(submenu, mTG_TYPE_NONE, mTG_TYPE_NONE); + sAdo_SysTrgStart(NA_SE_33); + submenu->overlay->haniwa_ovl->set_interrupt_message_proc(submenu, tag, 4); +} + +static void mTG_present_open_proc(Submenu* submenu, mSM_MenuInfo_c* menu_info) { + int table_idx; + + table_idx = mTG_get_table_idx(&submenu->overlay->tag_ovl->tags[0]); + mTG_return_tag_init(submenu, mTG_TYPE_NONE, mTG_TYPE_FIELD_DEFAULT); + sAdo_SysTrgStart(NA_SE_436); + mPr_SetItemCollectBit(Now_Private->inventory.pockets[table_idx]); + submenu->overlay->inventory_ovl->item_scale_type[table_idx] = 5; + submenu->overlay->inventory_ovl->remove_timer = 48; +} + +static void mTG_nw_select_this_proc(Submenu* submenu, mSM_MenuInfo_c* menu_info) { + int table_idx; + Submenu_Item_c* item_p; + + table_idx = mTG_get_table_idx(&submenu->overlay->tag_ovl->tags[0]); + item_p = submenu->item_p; + item_p->item = RSV_NO; + item_p->slot_no = table_idx; + submenu->selected_item_num = 1; + mTG_close_window(submenu, menu_info, TRUE); +} + +static void mTG_give_proc(Submenu* submenu, mSM_MenuInfo_c* menu_info) { + int table_idx; + Submenu_Item_c* item_p; + int category; + + table_idx = mTG_get_table_idx(&submenu->overlay->tag_ovl->tags[0]); + item_p = submenu->item_p; + item_p->item = Now_Private->inventory.pockets[table_idx]; + item_p->slot_no = table_idx; + submenu->selected_item_num = 1; + + category = ITEM_NAME_GET_CAT(item_p->item); + if (menu_info->data1 == 2) { + submenu->after_mode = aHOI_REQUEST_GET_PULL_WAIT; + } else if (menu_info->data1 == 1) { + submenu->after_mode = aHOI_REQUEST_PUTAWAY; + } else if (ITEM_NAME_GET_TYPE(item_p->item) == NAME_TYPE_ITEM1 && + (category == ITEM1_CAT_FRUIT || category == ITEM1_CAT_FISH)) { + submenu->after_mode = aHOI_REQUEST_EAT; + } else { + submenu->after_mode = aHOI_REQUEST_PUTAWAY; + } + + mPlib_request_main_give_from_submenu(item_p->item, submenu->after_mode, + mPr_GET_ITEM_COND(Now_Private->inventory.item_conditions, item_p->slot_no) & 1, + FALSE); + mTG_close_window(submenu, menu_info, TRUE); +} + +static void mTG_sell_proc(Submenu* submenu, mSM_MenuInfo_c* menu_info) { + mTG_Ovl_c* tag_ovl = submenu->overlay->tag_ovl; + mTG_tag_c* tag = &tag_ovl->tags[0]; + int table_idx = mTG_get_table_idx(tag); + Submenu_Item_c* item_p = submenu->item_p; + + if (mPr_GET_ITEM_COND(Now_Private->inventory.item_conditions, table_idx) == mPr_ITEM_COND_QUEST) { + mTG_open_warning_window(submenu, menu_info, mWR_WARNING_SELL_QUEST_ITEM); + } else { + item_p->item = Now_Private->inventory.pockets[table_idx]; + item_p->slot_no = table_idx; + submenu->selected_item_num = 1; + mTG_close_window(submenu, menu_info, TRUE); + } +} + +static void mTG_sell_all_proc(Submenu* submenu, mSM_MenuInfo_c* menu_info) { + mIV_Ovl_c* inventory_ovl; + int table_idx; + Submenu_Item_c* item_p; + int count; + int i; + + inventory_ovl = submenu->overlay->inventory_ovl; + table_idx = mTG_get_table_idx(&submenu->overlay->tag_ovl->tags[0]); + + if (mPr_GET_ITEM_COND(Now_Private->inventory.item_conditions, table_idx) == mPr_ITEM_COND_QUEST) { + mTG_open_warning_window(submenu, menu_info, mWR_WARNING_SELL_QUEST_ITEM); + } else { + item_p = submenu->item_p; + count = 0; + + for (i = 0; i < mPr_POCKETS_SLOT_COUNT; i++) { + item_p->item = EMPTY_NO; + item_p->slot_no = 0; + item_p++; + } + + item_p = submenu->item_p; + for (i = 0; i < mPr_POCKETS_SLOT_COUNT; i++) { + if ((inventory_ovl->item_mark_bitfield & (1 << i)) != 0) { + count++; + item_p->item = Now_Private->inventory.pockets[i]; + item_p->slot_no = i; + item_p++; + } + } + + submenu->selected_item_num = count; + mTG_close_window(submenu, menu_info, TRUE); + } +} + +static void mTG_get_proc(Submenu* submenu, mSM_MenuInfo_c* menu_info) { + static mActor_name_t mTG_money_name[] = { ITM_MONEY_100, ITM_MONEY_1000, ITM_MONEY_10000, ITM_MONEY_30000 }; + static u32 mTG_money_amount[] = { 100, 1000, 10000, 30000 }; + int money; + mActor_name_t* item_p2; + int k; + mTG_tag_c* tag = &submenu->overlay->tag_ovl->tags[0]; + int idx = mPr_GetPossessionItemIdxWithCond(Now_Private, EMPTY_NO, mPr_ITEM_COND_NORMAL); + mHW_Ovl_c* haniwa_ovl; + Haniwa_Item_c* haniwa_item_p; + mActor_name_t* item_p; + int changed_money; + int keep_money; + int i; + int j; + mIV_Ovl_c* inventory_ovl; + mActor_name_t* money_name_p; + u32* money_amount_p; + int change_money; + + if (idx == -1) { + haniwa_ovl = submenu->overlay->haniwa_ovl; + + haniwa_ovl->msg_interrupt_idx = 6; + haniwa_ovl->table_idx = tag->table; + haniwa_ovl->sub_idx = tag->tag_col; + haniwa_ovl->msg_time = 120; + mTG_return_tag_init(submenu, mTG_TYPE_NONE, mTG_TYPE_NONE); + sAdo_SysTrgStart(MONO(NA_SE_3)); + } else { + haniwa_item_p = &Save_Get(homes[menu_info->data1]).haniwa.items[tag->tag_col]; + item_p = Now_Private->inventory.pockets; + + money = Now_Private->inventory.wallet; + changed_money = money; + for (i = 0; i < mPr_POCKETS_SLOT_COUNT; i++, item_p++) { + if (mPr_GET_ITEM_COND(Now_Private->inventory.item_conditions, i) == mPr_ITEM_COND_NORMAL) { + changed_money += mTG_itemNo_to_amount(*item_p); + } + } + + changed_money -= haniwa_item_p->extra_data; + if (changed_money < 0) { + submenu->overlay->haniwa_ovl->set_interrupt_message_proc(submenu, tag, 7); + mTG_return_tag_init(submenu, mTG_TYPE_NONE, mTG_TYPE_NONE); + sAdo_SysTrgStart(MONO(NA_SE_3)); + } else { + inventory_ovl = submenu->overlay->inventory_ovl; + money_name_p = mTG_money_name; + money_amount_p = mTG_money_amount; + + keep_money = money - haniwa_item_p->extra_data; + for (j = 0; j < ARRAY_COUNT(mTG_money_name) && keep_money < 0; j++, money_name_p++, money_amount_p++) { + item_p2 = Now_Private->inventory.pockets; + for (k = 0; k < mPr_POCKETS_SLOT_COUNT; k++, item_p2++) { + if (mPr_GET_ITEM_COND(Now_Private->inventory.item_conditions, k) == mPr_ITEM_COND_NORMAL && + *item_p2 == *money_name_p) { + keep_money += *money_amount_p; + mPr_SetPossessionItem(Now_Private, k, EMPTY_NO, mPr_ITEM_COND_NORMAL); + + if (keep_money >= 0) { + break; + } + } + } + } + + Now_Private->inventory.wallet = keep_money; + mPr_SetPossessionItem(Now_Private, idx, haniwa_item_p->item, mPr_ITEM_COND_NORMAL); + submenu->overlay->haniwa_ovl->set_interrupt_message_proc(submenu, tag, 8); + mTG_return_tag_init(submenu, mTG_TYPE_NONE, mTG_TYPE_NONE); + Save_Get(homes[menu_info->data1]).haniwa.bells += haniwa_item_p->extra_data; + haniwa_item_p->item = EMPTY_NO; + + if (haniwa_item_p->exchange_type == mHm_HANIWA_TRADE_0) { + sAdo_SysTrgStart(NA_SE_5F); + } else { + change_money = (int)keep_money - (int)money; + + if (ABS(change_money) < 42) { + sAdo_SysTrgStart(MONO(NA_SE_REGISTER)); + inventory_ovl->disp_money = keep_money; + } else { + sAdo_SysTrgStart(MONO(NA_SE_52)); + submenu->overlay->hand_ovl->info.wait_timer = 42; + inventory_ovl->disp_money_change_frames = change_money / 42; + + if (ABS(inventory_ovl->disp_money_change_frames) % 5 == 0) { + if (inventory_ovl->disp_money_change_frames > 0) { + inventory_ovl->disp_money_change_frames--; + } else { + inventory_ovl->disp_money_change_frames++; + } + } + } + } + } + } +} + +static void mTG_dump_mail_mark_exe_proc(Submenu* submenu, mSM_MenuInfo_c* menu_info) { + mIV_Ovl_c* inv_ovl = submenu->overlay->inventory_ovl; + mMB_Ovl_c* mailbox_ovl = submenu->overlay->mailbox_ovl; + mCM_Ovl_c* cpmail_ovl = submenu->overlay->cpmail_ovl; + int delete_flag; + int i; + + if (menu_info->menu_type == mSM_OVL_MAILBOX) { + mailbox_ovl->mark_flag = FALSE; + for (i = 0; i < HOME_MAILBOX_SIZE; i++) { + Mail_c* mail = &Common_Get(now_home)->mailbox[i]; + + // clear selected mail if it has a present or is from the player (sending) + if (mail->present != EMPTY_NO || (mail->content.font != mMl_FONT_2 && mail->content.font != mMl_FONT_4)) { + mailbox_ovl->mark_bitfield &= ~(1 << i); + } + } + + if (mailbox_ovl->mark_bitfield != 0) { + mailbox_ovl->mark_flag = TRUE; + } + } else if (menu_info->menu_type == mSM_OVL_CPMAIL) { + int page = cpmail_ovl->page_order[0]; + + for (i = 0; i < mCM_MAIL_COUNT; i++) { + Mail_c* mail = &cpmail_ovl->card_mail->mail[page][i]; + + // clear selected mail if it has a present or is from the player (sending) + if (mail->present != EMPTY_NO || (mail->content.font != mMl_FONT_2 && mail->content.font != mMl_FONT_4)) { + cpmail_ovl->mark_bitfield &= ~(1 << i); + } + } + + cpmail_ovl->mark_flag = FALSE; + if (cpmail_ovl->mark_bitfield != 0) { + cpmail_ovl->mark_flag = TRUE; + } + } + + for (i = 0; i < mPr_INVENTORY_MAIL_COUNT; i++) { + Mail_c* mail = &Now_Private->mail[i]; + + // clear selected mail if it has a present or is from the player (sending) + if (mail->present != EMPTY_NO || (mail->content.font != mMl_FONT_2 && mail->content.font != mMl_FONT_4)) { + inv_ovl->mail_mark_bitfield2 &= ~(1 << i); + } + } + + inv_ovl->mail_mark_flag = FALSE; + if (inv_ovl->mail_mark_bitfield2 != 0) { + inv_ovl->mail_mark_flag = TRUE; + } + + delete_flag = FALSE; + if (inv_ovl->mail_mark_flag == TRUE) { + delete_flag = TRUE; + } else if (menu_info->menu_type == mSM_OVL_MAILBOX) { + if (mailbox_ovl->mark_flag == TRUE) { + delete_flag = TRUE; + } + } else if (menu_info->menu_type == mSM_OVL_CPMAIL) { + if (cpmail_ovl->mark_flag == TRUE) { + delete_flag = TRUE; + } + } + + if (delete_flag) { + inv_ovl->remove_timer = 24; + sAdo_SysTrgStart(NA_SE_435); + } else { + sAdo_SysTrgStart(MONO(NA_SE_A)); + } + + mTG_return_tag_init(submenu, mTG_TYPE_NONE, mTG_TYPE_NONE); +} + +static void mTG_mailbox_change_mail_proc(Submenu* submenu, mSM_MenuInfo_c* menu_info) { + mMB_Ovl_c* mailbox_ovl = submenu->overlay->mailbox_ovl; + mIV_Ovl_c* inv_ovl = submenu->overlay->inventory_ovl; + int idx = mMl_chk_mail_free_space(Now_Private->mail, mPr_INVENTORY_MAIL_COUNT); + + inv_ovl->mail_mark_bitfield2 = 0; + if (idx != -1) { + mailbox_ovl->mark_flag = 2; + sAdo_SysTrgStart(NA_SE_MENU_EXIT); + } else { + mailbox_ovl->mark_bitfield = 0; + sAdo_SysTrgStart(MONO(NA_SE_A)); + } + + mTG_return_tag_init(submenu, mTG_TYPE_NONE, mTG_TYPE_NONE); +} + +static void mTG_cpmail_change_mail_proc(Submenu* submenu, mSM_MenuInfo_c* menu_info) { + mCM_Ovl_c* cpmail_ovl = submenu->overlay->cpmail_ovl; + mIV_Ovl_c* inv_ovl = submenu->overlay->inventory_ovl; + int inv_free_cnt; + int inv_mark_cnt; + int cpmail_mark_cnt; + int cpmail_free_cnt; + int inv_cnt; + int cpmail_cnt; + int page; + int i; + + inv_mark_cnt = 0; + for (i = 0; i < mPr_INVENTORY_MAIL_COUNT; i++) { + if ((inv_ovl->mail_mark_bitfield2 & (1 << i)) != 0) { + inv_mark_cnt++; + } + } + + cpmail_mark_cnt = 0; + for (i = 0; i < mCM_MAIL_COUNT; i++) { + if ((cpmail_ovl->mark_bitfield & (1 << i)) != 0) { + cpmail_mark_cnt++; + } + } + + inv_free_cnt = 0; + for (i = 0; i < mPr_INVENTORY_MAIL_COUNT; i++) { + if (mMl_check_not_used_mail(&Now_Private->mail[i])) { + inv_free_cnt++; + } + } + + cpmail_free_cnt = 0; + page = cpmail_ovl->page_order[0]; + for (i = 0; i < mCM_MAIL_COUNT; i++) { + if (mMl_check_not_used_mail(&cpmail_ovl->card_mail->mail[page][i]) == TRUE) { + cpmail_free_cnt++; + } + } + + inv_cnt = 0; + cpmail_cnt = 0; + if (inv_mark_cnt > cpmail_mark_cnt && (inv_mark_cnt - cpmail_mark_cnt) > cpmail_free_cnt) { + inv_cnt = (inv_mark_cnt - cpmail_mark_cnt) - cpmail_free_cnt; + } else if (cpmail_mark_cnt > inv_mark_cnt && (cpmail_mark_cnt - inv_mark_cnt) > inv_free_cnt) { + cpmail_cnt = (cpmail_mark_cnt - inv_mark_cnt) - inv_free_cnt; + } + + if (inv_cnt == inv_mark_cnt && cpmail_cnt == cpmail_mark_cnt) { + cpmail_ovl->mark_bitfield = 0; + inv_ovl->mail_mark_bitfield2 = 0; + sAdo_SysTrgStart(MONO(NA_SE_A)); + } else { + int i; + int cnt; + if (inv_cnt > 0) { + for (cnt = 0, i = 0; cnt < inv_cnt && i < mPr_INVENTORY_MAIL_COUNT; i++) { + if ((inv_ovl->mail_mark_bitfield2 & (1 << i)) != 0) { + inv_ovl->mail_mark_bitfield2 &= ~(1 << i); + cnt++; + } + } + } + + if (cpmail_cnt > 0) { + for (cnt = 0, i = 0; cnt < cpmail_cnt && i < mCM_MAIL_COUNT; i++) { + if ((cpmail_ovl->mark_bitfield & (1 << i)) != 0) { + cpmail_ovl->mark_bitfield &= ~(1 << i); + cnt++; + } + } + } + + inv_ovl->mail_mark_flag = 2; + cpmail_ovl->mark_flag = 2; + sAdo_SysTrgStart(NA_SE_MENU_EXIT); + } + + mTG_return_tag_init(submenu, mTG_TYPE_NONE, mTG_TYPE_NONE); +} + +static void mTG_dump_mail_proc(Submenu* submenu, mSM_MenuInfo_c* menu_info) { + mIV_Ovl_c* inv_ovl = submenu->overlay->inventory_ovl; + + inv_ovl->remove_timer = 24; + mTG_return_tag_init(submenu, mTG_TYPE_NONE, mTG_TYPE_NONE); + sAdo_SysTrgStart(NA_SE_435); +} + +static void mTG_dump_item_proc(Submenu* submenu, mSM_MenuInfo_c* menu_info) { + mTG_tag_c* tag = &submenu->overlay->tag_ovl->tags[0]; + int idx = mTG_get_table_idx(tag); + mIV_Ovl_c* inv_ovl = submenu->overlay->inventory_ovl; + + inv_ovl->remove_timer = 12; + inv_ovl->item_scale_type[idx] = mIV_ITEM_SCALE_TYPE_SHRINK; + mTG_return_tag_init(submenu, mTG_TYPE_NONE, mTG_TYPE_NONE); + sAdo_SysTrgStart(NA_SE_435); +} + +static void mTG_send_proc(Submenu* submenu, mSM_MenuInfo_c* menu_info) { + mTG_tag_c* tag = &submenu->overlay->tag_ovl->tags[0]; + int idx = mTG_get_table_idx(tag); + Mail_c* mail = &Now_Private->mail[idx]; + Submenu_Item_c* item_p = submenu->item_p; + + mail->content.font = mMl_FONT_0; + mMl_copy_mail(&submenu->mail, mail); + mMl_clear_mail(mail); + item_p->slot_no = idx; + item_p->item = ITM_QST_LETTER; + submenu->selected_item_num = 1; + submenu->after_mode = aHOI_REQUEST_PUTAWAY; + mPlib_request_main_give_from_submenu(item_p->item, submenu->after_mode, FALSE, TRUE); + mTG_close_window(submenu, menu_info, TRUE); +} + +static void mTG_rewrite_proc(Submenu* submenu, mSM_MenuInfo_c* menu_info) { + mTG_open_board_init(submenu, menu_info, -1, mSM_BD_OPEN_REWRITE, -1); +} + +static void mTG_stick_select_proc(Submenu* submenu, mSM_MenuInfo_c* menu_info) { + mTG_Ovl_c* tag_ovl = submenu->overlay->tag_ovl; + mTG_tag_c* tag = &tag_ovl->tags[tag_ovl->sel_tag_idx]; + + mTG_chg_tag_func2(submenu, menu_info, tag, mTG_TYPE_TAG_NW_SEL_STK_PATTERN); + sAdo_SysTrgStart(NA_SE_33); +} + +static void mTG_nw_carpet_proc(Submenu* submenu, mSM_MenuInfo_c* menu_info) { + mTG_Ovl_c* tag_ovl = submenu->overlay->tag_ovl; + mIV_Ovl_c* inv_ovl = submenu->overlay->inventory_ovl; + mTG_tag_c* tag = &tag_ovl->tags[0]; + int idx = mTG_get_table_idx(tag); + int changed_flag = TRUE; + int change_org_flag = FALSE; + int img_no; + + if (tag_ovl->tags[3].tag_row == 1) { + change_org_flag = TRUE; + } + + if (mRmTp_CheckFloorIsMyOriginalInThisScene()) { + if (change_org_flag) { + img_no = mNW_get_image_no(submenu, idx) & 7; + CLIP(my_indoor_clip)->floor_idx_2_change_floor_proc(FLOOR_MY_ORIG_START + img_no, TRUE); + } else { + img_no = mNW_get_image_no(submenu, idx) & 7; + CLIP(my_indoor_clip)->floor_idx_2_change_floor_proc(FLOOR_MY_ORIG_START + img_no, FALSE); + } + } else { + int free_idx = mPr_GetPossessionItemIdx(Now_Private, EMPTY_NO); + + if (free_idx >= 0) { + mActor_name_t* item_p = &Now_Private->inventory.pockets[free_idx]; + + if (change_org_flag) { + img_no = mNW_get_image_no(submenu, idx) & 7; + *item_p = CLIP(my_indoor_clip)->floor_idx_2_change_floor_proc(FLOOR_MY_ORIG_START + img_no, TRUE); + } else { + img_no = mNW_get_image_no(submenu, idx) & 7; + *item_p = CLIP(my_indoor_clip)->floor_idx_2_change_floor_proc(FLOOR_MY_ORIG_START + img_no, FALSE); + } + } else { + mTG_open_warning_window(submenu, menu_info, mWR_WARNING_ORIGINAL); + changed_flag = FALSE; + } + } + + if (changed_flag) { + if (inv_ovl != NULL) { + inv_ovl->original_flag = TRUE; + } + + mTG_return_tag_init(submenu, mTG_TYPE_NONE, mTG_TYPE_NONE); + mTG_close_window(submenu, menu_info, FALSE); + } +} + +static void mTG_carpet_proc(Submenu* submenu, mSM_MenuInfo_c* menu_info) { + mTG_tag_c* tag = &submenu->overlay->tag_ovl->tags[0]; + int idx = mTG_get_table_idx(tag); + + if (CLIP(my_indoor_clip) != NULL) { + mActor_name_t* item_p = &Now_Private->inventory.pockets[idx]; + + if (mRmTp_CheckFloorIsMyOriginalInThisScene()) { + CLIP(my_indoor_clip)->change_carpet_proc(*item_p); + *item_p = EMPTY_NO; + } else { + mActor_name_t item; + + item = CLIP(my_indoor_clip)->change_carpet_proc(*item_p); + *item_p = item; + } + + mTG_return_tag_init(submenu, mTG_TYPE_NONE, mTG_TYPE_NONE); + mTG_close_window(submenu, menu_info, FALSE); + } +} + +static void mTG_nw_cover_proc(Submenu* submenu, mSM_MenuInfo_c* menu_info) { + mTG_Ovl_c* tag_ovl = submenu->overlay->tag_ovl; + mIV_Ovl_c* inv_ovl = submenu->overlay->inventory_ovl; + mTG_tag_c* tag = &tag_ovl->tags[0]; + int idx = mTG_get_table_idx(tag); + int changed_flag = TRUE; + int change_org_flag = FALSE; + int img_no; + + if (tag_ovl->tags[3].tag_row == 1) { + change_org_flag = TRUE; + } + + if (mRmTp_CheckWallIsMyOriginalInThisScene()) { + if (change_org_flag) { + img_no = mNW_get_image_no(submenu, idx) & 7; + CLIP(my_indoor_clip)->wall_idx_2_change_wall_proc(WALL_MY_ORIG_START + img_no, TRUE); + } else { + img_no = mNW_get_image_no(submenu, idx) & 7; + CLIP(my_indoor_clip)->wall_idx_2_change_wall_proc(WALL_MY_ORIG_START + img_no, FALSE); + } + } else { + int free_idx = mPr_GetPossessionItemIdx(Now_Private, EMPTY_NO); + + if (free_idx >= 0) { + mActor_name_t* item_p = &Now_Private->inventory.pockets[free_idx]; + + if (change_org_flag) { + img_no = mNW_get_image_no(submenu, idx) & 7; + *item_p = CLIP(my_indoor_clip)->wall_idx_2_change_wall_proc(WALL_MY_ORIG_START + img_no, TRUE); + } else { + img_no = mNW_get_image_no(submenu, idx) & 7; + *item_p = CLIP(my_indoor_clip)->wall_idx_2_change_wall_proc(WALL_MY_ORIG_START + img_no, FALSE); + } + } else { + mTG_open_warning_window(submenu, menu_info, mWR_WARNING_ORIGINAL); + changed_flag = FALSE; + } + } + + if (changed_flag) { + if (inv_ovl != NULL) { + inv_ovl->original_flag = TRUE; + } + + mTG_return_tag_init(submenu, mTG_TYPE_NONE, mTG_TYPE_NONE); + mTG_close_window(submenu, menu_info, FALSE); + } +} + +static void mTG_cover_proc(Submenu* submenu, mSM_MenuInfo_c* menu_info) { + mTG_tag_c* tag = &submenu->overlay->tag_ovl->tags[0]; + int idx = mTG_get_table_idx(tag); + + if (CLIP(my_indoor_clip) != NULL) { + mActor_name_t* item_p = &Now_Private->inventory.pockets[idx]; + + if (mRmTp_CheckWallIsMyOriginalInThisScene()) { + CLIP(my_indoor_clip)->change_wall_proc(*item_p); + *item_p = EMPTY_NO; + } else { + mActor_name_t item; + + item = CLIP(my_indoor_clip)->change_wall_proc(*item_p); + *item_p = item; + } + + mTG_return_tag_init(submenu, mTG_TYPE_NONE, mTG_TYPE_NONE); + mTG_close_window(submenu, menu_info, FALSE); + } +} + +static void mTG_putin_proc(Submenu* submenu, mSM_MenuInfo_c* menu_info) { + mTG_tag_c* tag = &submenu->overlay->tag_ovl->tags[0]; + int idx = mTG_get_table_idx(tag); + Submenu_Item_c* item_p = submenu->item_p; + + item_p->item = Now_Private->inventory.pockets[idx]; + item_p->slot_no = idx; + submenu->selected_item_num = 1; + + if (menu_info->data0 == 10) { + if (ChkRoomMusicBox((u32)(item_p->item - ITM_MINIDISK_START))) { + item_p->item = EMPTY_NO; + mTG_open_warning_window(submenu, menu_info, mWR_WARNING_MUSIC2); + } else { + SetRoomMusicBox((u32)(item_p->item - ITM_MINIDISK_START)); + mPr_SetPossessionItem(Now_Private, idx, EMPTY_NO, mPr_ITEM_COND_NORMAL); + mTG_close_window(submenu, menu_info, TRUE); + } + } else { + if (menu_info->data0 != 11) { + mPr_SetPossessionItem(Now_Private, idx, EMPTY_NO, mPr_ITEM_COND_NORMAL); + } + + mTG_close_window(submenu, menu_info, TRUE); + } +} + +static void mTG_music_listen_proc(Submenu* submenu, mSM_MenuInfo_c* menu_info) { + mTG_tag_c* tag = &submenu->overlay->tag_ovl->tags[0]; + int idx = mTG_get_table_idx(tag); + Submenu_Item_c* item_p = submenu->item_p; + + item_p->item = ITM_MINIDISK_START + idx; + item_p->slot_no = idx; + submenu->selected_item_num = 1; + mTG_close_window(submenu, menu_info, TRUE); +} + +static void mTG_music_takeout_proc(Submenu* submenu, mSM_MenuInfo_c* menu_info) { + mTG_tag_c* tag = &submenu->overlay->tag_ovl->tags[0]; + int idx = mTG_get_table_idx(tag); + mMU_Ovl_c* music_ovl = submenu->overlay->music_ovl; + u32 mark_cnt = 0; + int free_idx; + int i; + + for (i = 0; i < MINIDISK_NUM; i++) { + if (ChkMusicBox(music_ovl->mark_flg, i)) { + mark_cnt++; + } + } + + if (mark_cnt == 0 || ChkMusicBox(music_ovl->mark_flg, idx) == FALSE) { + if (mPr_GetPossessionItemSum(Now_Private, EMPTY_NO) >= 1) { + free_idx = mPr_GetPossessionItemIdx(Now_Private, EMPTY_NO); + + if (free_idx >= 0) { + ClrRoomMusicBox(idx); + mPr_SetPossessionItem(Now_Private, free_idx, ITM_MINIDISK_START + idx, mPr_ITEM_COND_NORMAL); + } + + mTG_return_tag_init(submenu, mTG_TYPE_NONE, mTG_TYPE_NONE); + mTG_close_window(submenu, menu_info, TRUE); + } else { + mTG_open_warning_window(submenu, menu_info, mWR_WARNING_MUSIC); + } + } else { + if (mPr_GetPossessionItemSum(Now_Private, EMPTY_NO) >= 1) { + for (i = 0; i < MINIDISK_NUM; i++) { + if (ChkMusicBox(music_ovl->mark_flg, i)) { + free_idx = mPr_GetPossessionItemIdx(Now_Private, EMPTY_NO); + + if (free_idx >= 0) { + ClrRoomMusicBox(i); + mPr_SetPossessionItem(Now_Private, free_idx, ITM_MINIDISK_START + i, mPr_ITEM_COND_NORMAL); + } + } + } + + mTG_return_tag_init(submenu, mTG_TYPE_NONE, mTG_TYPE_NONE); + mTG_close_window(submenu, menu_info, TRUE); + } else { + mTG_open_warning_window(submenu, menu_info, mWR_WARNING_MUSIC); + } + } +} + +static void mTG_island_check_plant_plant(mActor_name_t item) { + if (item == ITM_SAPLING || item == ITM_CEDAR_SAPLING) { + mISL_SetNowPlayerAction(mISL_PLAYER_ACTION_PLANT_TREE); + } else if (ITEM_IS_FLOWER_BAG(item)) { + mISL_SetNowPlayerAction(mISL_PLAYER_ACTION_PLANT_FLOWER); + } +} + +static void mTG_island_check_fruit_plant(mActor_name_t item) { + switch (item) { + case ITM_FOOD_APPLE: + mISL_SetNowPlayerAction(mISL_PLAYER_ACTION_PLANT_APPLE_TREE); + mISL_SetNowPlayerAction(mISL_PLAYER_ACTION_PLANT_TREE); + break; + case ITM_FOOD_CHERRY: + mISL_SetNowPlayerAction(mISL_PLAYER_ACTION_PLANT_CHERRY_TREE); + mISL_SetNowPlayerAction(mISL_PLAYER_ACTION_PLANT_TREE); + break; + case ITM_FOOD_PEAR: + mISL_SetNowPlayerAction(mISL_PLAYER_ACTION_PLANT_PEAR_TREE); + mISL_SetNowPlayerAction(mISL_PLAYER_ACTION_PLANT_TREE); + break; + case ITM_FOOD_PEACH: + mISL_SetNowPlayerAction(mISL_PLAYER_ACTION_PLANT_PEACH_TREE); + mISL_SetNowPlayerAction(mISL_PLAYER_ACTION_PLANT_TREE); + break; + case ITM_FOOD_ORANGE: + mISL_SetNowPlayerAction(mISL_PLAYER_ACTION_PLANT_ORANGE_TREE); + mISL_SetNowPlayerAction(mISL_PLAYER_ACTION_PLANT_TREE); + break; + case ITM_FOOD_COCONUT: + mISL_SetNowPlayerAction(mISL_PLAYER_ACTION_PLANT_COCONUT_TREE); + mISL_SetNowPlayerAction(mISL_PLAYER_ACTION_PLANT_TREE); + break; + } +} + +static void mTG_island_check_fruit_eat(mActor_name_t item) { + if (item == ITM_FOOD_COCONUT) { + mISL_SetNowPlayerAction(mISL_PLAYER_ACTION_EAT_COCONUT); + } +} + +static void mTG_plant_proc(Submenu* submenu, mSM_MenuInfo_c* menu_info) { + GAME_PLAY* play = (GAME_PLAY*)gamePT; + ACTOR* player = GET_PLAYER_ACTOR_ACTOR(play); + mTG_tag_c* tag = &submenu->overlay->tag_ovl->tags[0]; + int idx = mTG_get_table_idx(tag); + mActor_name_t plant_item; + mIV_Ovl_c* inv_ovl = submenu->overlay->inventory_ovl; + xyz_t pos; + + plant_item = Now_Private->inventory.pockets[idx]; + + if (((Now_Private->equipment >= ITM_SHOVEL && Now_Private->equipment <= ITM_SHOVEL) || + (Now_Private->equipment >= ITM_GOLDEN_SHOVEL && Now_Private->equipment <= ITM_GOLDEN_SHOVEL)) && + inv_ovl->shovel_flag == TRUE) { + mTG_island_check_plant_plant(plant_item); + mTG_island_check_fruit_plant(plant_item); + mPlib_request_main_putin_scoop_from_submenu(&inv_ovl->shovel_pos, Now_Private->inventory.pockets[idx], FALSE); + mPr_SetPossessionItem(Now_Private, idx, EMPTY_NO, mPr_ITEM_COND_NORMAL); + mTG_return_tag_init(submenu, mTG_TYPE_NONE, mTG_TYPE_NONE); + mTG_close_window(submenu, menu_info, TRUE); + return; + } else { + if (mTG_search_put_pos(player, &pos, TRUE, plant_item == ITM_SIGNBOARD, plant_item == ITM_SIGNBOARD, FALSE, + FALSE)) { + mActor_name_t item = Now_Private->inventory.pockets[idx]; + mActor_name_t throw_item; + + mTG_island_check_plant_plant(item); + if (item == ITM_SAPLING) { + throw_item = TREE_SAPLING; + } else if (item == ITM_CEDAR_SAPLING) { + throw_item = CEDAR_TREE_SAPLING; + } else { + throw_item = FLOWER_PANSIES0 + (item - ITM_WHITE_PANSY_BAG); + } + + if (mTG_common_throw_put_field(play, throw_item, &pos, mCoBG_LAYER0)) { + mPr_SetPossessionItem(Now_Private, idx, EMPTY_NO, mPr_ITEM_COND_NORMAL); + pos.y = mCoBG_GetBgY_OnlyCenter_FromWpos2(pos, 0.0f); + sAdo_OngenTrgStart(NA_SE_2A, &pos); + mTG_return_tag_init(submenu, mTG_TYPE_NONE, mTG_TYPE_NONE); + mTG_close_window(submenu, menu_info, TRUE); + return; + } + } + } + + mTG_open_warning_window(submenu, menu_info, mWR_WARNING_PUT_PLANT); +} + +static int mTG_check_island_famicom(mActor_name_t item) { + int res = TRUE; + + if (mFI_CheckInIsland() && + (mSP_SearchItemCategoryPriority(item, mSP_KIND_FURNITURE, mSP_LISTTYPE_HOMEPAGE, NULL) || + mSP_SearchItemCategoryPriority(item, mSP_KIND_FURNITURE, mSP_LISTTYPE_SPECIALPRESENT, NULL))) { + res = FALSE; + } + + return res; +} + +static void mTG_field_put_proc(Submenu* submenu, mSM_MenuInfo_c* menu_info) { + GAME_PLAY* play = (GAME_PLAY*)gamePT; + ACTOR* player = GET_PLAYER_ACTOR_ACTOR(play); + mTG_tag_c* tag = &submenu->overlay->tag_ovl->tags[0]; + int idx = mTG_get_table_idx(tag); + mActor_name_t put_item = Now_Private->inventory.pockets[idx]; + mIV_Ovl_c* inv_ovl = submenu->overlay->inventory_ovl; + xyz_t pos; + + if (inv_ovl->item_mark_bitfield != 0 && (inv_ovl->item_mark_bitfield & (1 << idx)) != 0) { + int i; + int put_cnt = 0; + int bad_famicom_cnt = 0; + + for (i = 0; i < mPr_POCKETS_SLOT_COUNT; i++) { + if ((inv_ovl->item_mark_bitfield & (1 << i)) != 0) { + mActor_name_t item = Now_Private->inventory.pockets[i]; + + if (mTG_check_island_famicom(item)) { + if (mTG_search_put_pos(player, &pos, item == ITM_SIGNBOARD, FALSE, item == ITM_SIGNBOARD, + item == ITM_SIGNBOARD, item == ITM_SIGNBOARD) && + mTG_common_throw_put_field(play, item, &pos, put_cnt)) { + mPr_SetPossessionItem(Now_Private, i, EMPTY_NO, mPr_ITEM_COND_NORMAL); + put_cnt++; + } + } else { + bad_famicom_cnt++; + } + } + } + + if (put_cnt != 0) { + mTG_return_tag_init(submenu, mTG_TYPE_NONE, mTG_TYPE_NONE); + mTG_close_window(submenu, menu_info, TRUE); + } else if (bad_famicom_cnt != 0) { + mTG_open_warning_window(submenu, menu_info, mWR_WARNING_PUT_FAMI); + } else { + mTG_open_warning_window(submenu, menu_info, mWR_WARNING_PUT_ITEM); + } + + inv_ovl->item_mark_bitfield = 0; + } else { + if (put_item == ITM_SIGNBOARD && (mFI_CheckInIsland() || mLd_PlayerManKindCheck())) { + if (mFI_CheckInIsland()) { + mTG_open_warning_window(submenu, menu_info, mWR_WARNING_PUT_SIGN_ISLAND); + } else { + mTG_open_warning_window(submenu, menu_info, mWR_WARNING_PUT_SIGN_OTHER); + } + } else if ((mSP_SearchItemCategoryPriority(put_item, mSP_KIND_FURNITURE, mSP_LISTTYPE_HOMEPAGE, NULL) || + mSP_SearchItemCategoryPriority(put_item, mSP_KIND_FURNITURE, mSP_LISTTYPE_SPECIALPRESENT, NULL)) && + mFI_CheckInIsland()) { + mTG_open_warning_window(submenu, menu_info, mWR_WARNING_PUT_FAMI); + } else { + if (mTG_search_put_pos(player, &pos, put_item == ITM_SIGNBOARD, FALSE, put_item == ITM_SIGNBOARD, + put_item == ITM_SIGNBOARD, put_item == ITM_SIGNBOARD) && + mTG_common_throw_put_field(play, put_item, &pos, mCoBG_LAYER0)) { + if (menu_info->data0 == 13) { + mPr_SetPossessionItem(Now_Private, idx, (mActor_name_t)menu_info->data1, mPr_ITEM_COND_NORMAL); + mPlib_request_main_wait_from_submenu(); + } else { + mPr_SetPossessionItem(Now_Private, idx, EMPTY_NO, mPr_ITEM_COND_NORMAL); + } + + mTG_return_tag_init(submenu, mTG_TYPE_NONE, mTG_TYPE_NONE); + mTG_close_window(submenu, menu_info, FALSE); + } else { + if (put_item == ITM_SIGNBOARD) { + mTG_open_warning_window(submenu, menu_info, mWR_WARNING_PUT_SIGN); + } else { + mTG_open_warning_window(submenu, menu_info, mWR_WARNING_PUT_ITEM); + } + } + } + } +} + +static void mTG_room_put_proc(Submenu* submenu, mSM_MenuInfo_c* menu_info) { + GAME_PLAY* play = (GAME_PLAY*)gamePT; + ACTOR* player = GET_PLAYER_ACTOR_ACTOR(play); + mTG_tag_c* tag = &submenu->overlay->tag_ovl->tags[0]; + int idx; + mActor_name_t put_item; + mIV_Ovl_c* inv_ovl; + int ftrID; + xyz_t pos; + xyz_t ut_pos; + int ux; + int uz; + + idx = mTG_get_table_idx(tag); + put_item = mRmTp_Item1ItemNo2FtrItemNo_AtPlayerRoom(Now_Private->inventory.pockets[idx], TRUE); + inv_ovl = submenu->overlay->inventory_ovl; + + switch (ITEM_NAME_GET_TYPE(put_item)) { + case NAME_TYPE_FTR0: + case NAME_TYPE_FTR1: + if (!mFI_CheckInIsland() || + !(mSP_SearchItemCategoryPriority(put_item, mSP_KIND_FURNITURE, mSP_LISTTYPE_HOMEPAGE, NULL) || + mSP_SearchItemCategoryPriority(put_item, mSP_KIND_FURNITURE, mSP_LISTTYPE_SPECIALPRESENT, NULL))) { + ftrID = mTG_drop_furniture(play, put_item); + if (ftrID >= 0) { + mPr_SetPossessionItem(Now_Private, idx, EMPTY_NO, mPr_ITEM_COND_NORMAL); + mTG_return_tag_init(submenu, mTG_TYPE_NONE, mTG_TYPE_NONE); + mTG_close_window(submenu, menu_info, FALSE); + mMkRm_ReportChangePlayerRoom(); + } else { + if (ftrID == -1) { + mTG_open_warning_window(submenu, menu_info, mWR_WARNING_PUT_MAX_FURNITURE); + } else { + mTG_open_warning_window(submenu, menu_info, mWR_WARNING_PUT_FURNITURE); + } + } + } else { + mTG_open_warning_window(submenu, menu_info, mWR_WARNING_PUT_FAMI); + } + break; + case NAME_TYPE_ITEM1: + xyz_t_move(&pos, &player->world.position); + if (inv_ovl->item_mark_bitfield != 0 && (inv_ovl->item_mark_bitfield & (1 << idx)) != 0) { + int i; + int cnt = 0; + + for (i = 0; i < mPr_POCKETS_SLOT_COUNT; i++) { + if ((inv_ovl->item_mark_bitfield & (1 << i)) != 0) { + mActor_name_t item = + mRmTp_Item1ItemNo2FtrItemNo_AtPlayerRoom(Now_Private->inventory.pockets[i], TRUE); + + if (mTG_search_put_pos(player, &pos, FALSE, FALSE, cnt, FALSE, FALSE) && + mTG_common_throw_put_room(play, item, &pos, mCoBG_LAYER0, cnt)) { + mPr_SetPossessionItem(Now_Private, i, EMPTY_NO, mPr_ITEM_COND_NORMAL); + cnt++; + } + } + } + + if (cnt > 0) { + mTG_return_tag_init(submenu, mTG_TYPE_NONE, mTG_TYPE_NONE); + mMkRm_ReportChangePlayerRoom(); + mTG_close_window(submenu, menu_info, FALSE); + } else { + mTG_open_warning_window(submenu, menu_info, mWR_WARNING_PUT_ITEM); + } + } else { + if (aMR_CLIP != NULL) { + mTG_get_unit_front_player(&ut_pos, &pos, player->shape_info.rotation.y); + if (mTG_check_free_2nd_layer(&ut_pos)) { + if (mFI_Wpos2UtNum(&ux, &uz, ut_pos) && aMR_CLIP->judge_place_2nd_layer_proc(ux, uz) && + mTG_common_throw_put_room(play, put_item, &ut_pos, mCoBG_LAYER1, 0)) { + mPr_SetPossessionItem(Now_Private, idx, EMPTY_NO, mPr_ITEM_COND_NORMAL); + mTG_return_tag_init(submenu, mTG_TYPE_NONE, mTG_TYPE_NONE); + mTG_close_window(submenu, menu_info, FALSE); + mMkRm_ReportChangePlayerRoom(); + return; + } + } + } + + if (mTG_search_put_pos(player, &pos, FALSE, FALSE, 0, FALSE, FALSE) && + mTG_common_throw_put_room(play, put_item, &pos, mCoBG_LAYER0, 0)) { + mPr_SetPossessionItem(Now_Private, idx, EMPTY_NO, mPr_ITEM_COND_NORMAL); + mTG_return_tag_init(submenu, mTG_TYPE_NONE, mTG_TYPE_NONE); + mMkRm_ReportChangePlayerRoom(); + mTG_close_window(submenu, menu_info, FALSE); + } else { + mTG_open_warning_window(submenu, menu_info, mWR_WARNING_PUT_ITEM); + } + } + break; + } +} + +static void mTG_put_all_proc(Submenu* submenu, mSM_MenuInfo_c* menu_info) { + switch (Common_Get(field_type)) { + case mFI_FIELDTYPE2_FG: + mTG_field_put_proc(submenu, menu_info); + break; + case mFI_FIELDTYPE2_PLAYER_ROOM: + mTG_room_put_proc(submenu, menu_info); + break; + case mFI_FIELDTYPE2_NPC_ROOM: + break; + case mFI_FIELDTYPE2_ROOM: + break; + default: + break; + } +} + +static void mTG_dump_mail_mark_conf_proc(Submenu* submenu, mSM_MenuInfo_c* menu_info) { + mTG_Ovl_c* tag_ovl = submenu->overlay->tag_ovl; + mTG_tag_c* tag = &tag_ovl->tags[tag_ovl->sel_tag_idx]; + + mTG_chg_tag_func2(submenu, menu_info, tag, mTG_TYPE_DUMP_MAIL_MARK_CONF); + sAdo_SysTrgStart(NA_SE_33); +} + +static void mTG_next_open_proc(Submenu* submenu, mSM_MenuInfo_c* menu_info) { + mTG_Ovl_c* tag_ovl = submenu->overlay->tag_ovl; + mTG_tag_c* tag = &tag_ovl->tags[tag_ovl->sel_tag_idx]; + int next_type; + + if (tag->type == mTG_TYPE_CP_DELETE) { + next_type = mTG_TYPE_CP_DELETE2; + } else if (tag->type == mTG_TYPE_TAISOU_CARD || tag->type == mTG_TYPE_FIELD_SIGN) { + next_type = mTG_TYPE_DUMP_ITEM; + } else { + next_type = mTG_TYPE_DUMP_MAIL; + } + + mTG_chg_tag_func2(submenu, menu_info, tag, next_type); + sAdo_SysTrgStart(NA_SE_33); +} + +static void mTG_next_open_needlework_sel_stick_proc(Submenu* submenu, mSM_MenuInfo_c* menu_info) { + mTG_Ovl_c* tag_ovl = submenu->overlay->tag_ovl; + mTG_tag_c* tag = &tag_ovl->tags[tag_ovl->sel_tag_idx]; + int next_type; + + /* @BUG - if Save::field_type is out of the normal enum value range then next_type will be undefined */ + switch (Common_Get(field_type)) { + case mFI_FIELDTYPE2_PLAYER_ROOM: + if (Save_Get(scene_no) == SCENE_COTTAGE_MY || mSc_IS_SCENE_BASEMENT(Save_Get(scene_no))) { + next_type = mTG_TYPE_TAG_NW_OR_SEL_STICK; + } else { + next_type = mTG_TYPE_TAG_NW_MR_SEL_STICK; + } + break; + case mFI_FIELDTYPE2_FG: + case mFI_FIELDTYPE2_NPC_ROOM: + case mFI_FIELDTYPE2_ROOM: +#ifdef BUGFIXES + default: +#endif + next_type = mTG_TYPE_TAG_NW_OR_SEL_STICK; + break; + } + + mTG_chg_tag_func2(submenu, menu_info, tag, next_type); + sAdo_SysTrgStart(NA_SE_33); +} + +static void mTG_next_open_needlework_sel_put_proc(Submenu* submenu, mSM_MenuInfo_c* menu_info) { + mTG_Ovl_c* tag_ovl = submenu->overlay->tag_ovl; + mTG_tag_c* tag = &tag_ovl->tags[tag_ovl->sel_tag_idx]; + + mTG_chg_tag_func2(submenu, menu_info, tag, mTG_TYPE_TAG_NW_SEL_PUT); + sAdo_SysTrgStart(NA_SE_33); +} + +static void mTG_free_proc(Submenu* submenu, mSM_MenuInfo_c* menu_info) { + mTG_set_trade_cond(submenu, menu_info, mHm_HANIWA_TRADE_0, 0); +} + +static void mTG_catch_proc(Submenu* submenu, mSM_MenuInfo_c* menu_info) { + mTG_Ovl_c* tag_ovl = submenu->overlay->tag_ovl; + mTG_tag_c* tag = &tag_ovl->tags[0]; + mTG_tag_c* cur_tag = &tag_ovl->tags[tag_ovl->sel_tag_idx]; + int idx = 0; + int item_cond = mPr_ITEM_COND_NORMAL; + mActor_name_t* item_p = NULL; + Mail_c* mail_p = NULL; + + if (cur_tag->table == mTG_TABLE_ITEM) { + idx = mTG_get_table_idx(tag); + item_p = &Now_Private->inventory.pockets[idx]; + item_cond = mPr_GET_ITEM_COND(Now_Private->inventory.item_conditions, idx); + if (*item_p != EMPTY_NO) { + mQst_CheckGrabItem(*item_p, idx); + } + } else if (cur_tag->table == mTG_TABLE_MAIL || cur_tag->table == mTG_TABLE_MBOX || + cur_tag->table == mTG_TABLE_CPMAIL) { + idx = mTG_get_table_idx(tag); + mail_p = mTG_get_mail_pointer(submenu, NULL); + + if (mMl_check_not_used_mail(mail_p) == TRUE) { + return; + } + + if (submenu->overlay->tag_ovl->sel_tag_idx == 0 && menu_info->menu_type != mSM_OVL_MAILBOX && + menu_info->menu_type != mSM_OVL_CPMAIL) { + item_p = &mail_p->present; + if (*item_p != EMPTY_NO) { + if (mMl_check_set_present_myself(mail_p)) { + item_cond = mPr_ITEM_COND_NORMAL; + mail_p = NULL; + } else if (mPr_GetPossessionItemIdx(Now_Private, EMPTY_NO) != -1) { + item_cond = mPr_ITEM_COND_PRESENT; + mail_p = NULL; + } else { + item_p = NULL; + } + } else { + item_p = NULL; + } + } + } else { + mActor_name_t item; + + switch (cur_tag->table) { + case mTG_TABLE_HANIWA: + idx = tag->tag_col; + item_p = &Save_Get(homes[menu_info->data1]).haniwa.items[idx].item; + break; + case mTG_TABLE_PLAYER: + item_p = &Now_Private->equipment; + break; + case mTG_TABLE_MONEY: + mTG_make_money_sack(submenu, menu_info, ITM_MONEY_100); + return; + case mTG_TABLE_NEEDLEWORK: + case mTG_TABLE_CPORIGINAL_NW: + idx = mTG_get_table_idx(tag); + item_p = &item; + item = RSV_NW_ORIGINAL0 + idx; + break; + case mTG_TABLE_CPORIGINAL: + idx = mTG_get_table_idx(tag); + item = RSV_CPORIGINAL_FLD0_00 + mCO_top_folder(submenu) * mCO_ORIGINAL_NUM + idx; + item_p = &item; + break; + case mTG_TABLE_GBA: + case mTG_TABLE_CARD: + idx = mTG_get_table_idx(tag); + item_p = &item; + item = RSV_GBAORIGINAL0 + idx; + break; + } + } + + if (mail_p != NULL || (item_p != NULL && *item_p != EMPTY_NO)) { + mHD_Ovl_c* hand_ovl = submenu->overlay->hand_ovl; + + mTG_mark_main_CLR(submenu, menu_info); + if (cur_tag->table == mTG_TABLE_HANIWA) { + hand_ovl->info.haniwa_item_cond = Save_Get(homes[menu_info->data1]).haniwa.items[idx].exchange_type; + hand_ovl->info.haniwa_item_price = Save_Get(homes[menu_info->data1]).haniwa.items[idx].extra_data; + } else { + hand_ovl->info.haniwa_item_cond = mPr_ITEM_COND_PRESENT; + hand_ovl->info.haniwa_item_price = 0; + } + + mTG_catch_item_from_table(submenu, mail_p, item_p, item_cond, cur_tag->table, idx); + mTG_return_tag_init(submenu, mTG_TYPE_NONE, mTG_TYPE_NONE); + } +} + +static int mTG_mail_check(Mail_c* mail) { + int flags = 0; + + if (mail->present != EMPTY_NO) { + flags |= mTG_MAIL_FLAG_PRESENT; + } + + if (!mMl_check_send_mail(mail)) { + flags |= mTG_MAIL_FLAG_RECV; + } + + return flags; +} + +static void mTG_password_item_proc(Submenu* submenu, mSM_MenuInfo_c* menu_info) { + mTG_Ovl_c* tag_ovl = submenu->overlay->tag_ovl; + mTG_tag_c* tag = &tag_ovl->tags[0]; + int idx = mTG_get_table_idx(tag); + Submenu_Item_c* item_p = submenu->item_p; + + if (mPr_GET_ITEM_COND(Now_Private->inventory.item_conditions, idx) == mPr_ITEM_COND_QUEST) { + mTG_open_warning_window(submenu, menu_info, mWR_WARNING_SELL_QUEST_ITEM); + } else { + item_p->item = Now_Private->inventory.pockets[idx]; + item_p->slot_no = idx; + submenu->selected_item_num = 1; + mTG_close_window(submenu, menu_info, TRUE); + } +} + +static int mTG_mark_enable_check(int menu_type, int param, int table, u8 field_type) { + int res = mTG_MARK_TYPE_NONE; + + switch (menu_type) { + case mSM_OVL_INVENTORY: + switch (param) { + case mSM_IV_OPEN_NORMAL: + switch (table) { + case mTG_TABLE_ITEM: + switch (field_type) { + case mFI_FIELDTYPE2_FG: + res = mTG_MARK_TYPE_INV_FG_ITEM; + break; + case mFI_FIELDTYPE2_PLAYER_ROOM: + res = mTG_MARK_TYPE_INV_PLAYERROOM_ITEM; + break; + default: + res = mTG_MARK_TYPE_INV_OTHERROOM_ITEM; + break; + } + break; + case mTG_TABLE_MAIL: + if (field_type == mFI_FIELDTYPE2_FG) { + res = mTG_MARK_TYPE_INV_FG_MAIL; + } + break; + } + break; + case mSM_IV_OPEN_MAILBOX: + res = mTG_MARK_TYPE_INV_MAILBOX; + break; + case mSM_IV_OPEN_SELL: + if (table == mTG_TABLE_ITEM) { + res = mTG_MARK_TYPE_INV_SELL_ITEM; + } + break; + } + break; + case mSM_OVL_MAILBOX: + res = mTG_MARK_TYPE_MAILBOX; + break; + case mSM_OVL_CPMAIL: + switch (table) { + case mTG_TABLE_CPMAIL: + res = mTG_MARK_TYPE_CPMAIL_CPMAIL; + break; + case mTG_TABLE_MAIL: + res = mTG_MARK_TYPE_CPMAIL_MAIL; + break; + } + break; + case mSM_OVL_MUSIC: + res = mTG_MARK_TYPE_MUSIC; + break; + case mSM_OVL_NEEDLEWORK: + // scrapped? + break; + case mSM_OVL_CPORIGINAL: + // scrapped? + break; + } + + return res; +} + +typedef union tag_mark_field_u { + u16 field16; + u32 field32; + u32 music_box[2]; + u8 u8array[8]; +} mTG_mark_field_u; + +static int mTG_mark_main_sub(Submenu* submenu, int menu_type, int param, int table, int table_idx, Mail_c* mail, + int mode, mTG_mark_field_u** mark_bitfield_p, int* max_mark_count, + mTG_mark_field_u* updated_mark_bitfield) { + mIV_Ovl_c* inv_ovl = submenu->overlay->inventory_ovl; + mMB_Ovl_c* mailbox_ovl = submenu->overlay->mailbox_ovl; + mCM_Ovl_c* cpmail_ovl = submenu->overlay->cpmail_ovl; + mMU_Ovl_c* music_ovl = submenu->overlay->music_ovl; + mNW_Ovl_c* needlework_ovl = submenu->overlay->needlework_ovl; + mCO_Ovl_c* cporiginal_ovl = submenu->overlay->cporiginal_ovl; + int mark_type; + + mark_type = mTG_mark_enable_check(menu_type, param, table, Common_Get(field_type)); + switch (mark_type) { + case mTG_MARK_TYPE_NONE: + return FALSE; + case mTG_MARK_TYPE_INV_FG_ITEM: + case mTG_MARK_TYPE_INV_PLAYERROOM_ITEM: { + mActor_name_t item = Now_Private->inventory.pockets[table_idx]; + u32 cond = mPr_GET_ITEM_COND(Now_Private->inventory.item_conditions, table_idx); + int type; + int category; + + category = ITEM_NAME_GET_CAT(item); + type = ITEM_NAME_GET_TYPE(item); + *(u16**)mark_bitfield_p = &inv_ovl->item_mark_bitfield; + updated_mark_bitfield->field16 = 1 << table_idx; + *max_mark_count = mPr_POCKETS_SLOT_COUNT; + + if ((mode == mTG_MARK_CHK || mode == mTG_MARK_OFF || mode == mTG_MARK_CLR) || + (item != EMPTY_NO && cond == mPr_ITEM_COND_NORMAL && !ITEM_IS_EXERCISE_CARD(item) && + item != ITM_KNIFE_AND_FORK && !ITEM_IS_BALLOON(item) && + (type != NAME_TYPE_ITEM1 || (category != ITEM1_CAT_FISH && category != ITEM1_CAT_INSECT)) && + (mark_type != mTG_MARK_TYPE_INV_FG_ITEM || + (mark_type == mTG_MARK_TYPE_INV_FG_ITEM && item != ITM_SIGNBOARD)) && + (mark_type != mTG_MARK_TYPE_INV_PLAYERROOM_ITEM || + ((mark_type == mTG_MARK_TYPE_INV_PLAYERROOM_ITEM && type != NAME_TYPE_FTR0 && + type != NAME_TYPE_FTR1) && + (!ITEM_IS_UMBRELLA(item) && !ITEM_IS_CLOTH(item)))) && + (mEv_CheckFirstJob() == FALSE || mark_type == mTG_MARK_TYPE_INV_PLAYERROOM_ITEM || + type != NAME_TYPE_ITEM1 || category != ITEM1_CAT_PLANT))) { + return TRUE; + } + return FALSE; + } + case mTG_MARK_TYPE_INV_OTHERROOM_ITEM: + return FALSE; + case mTG_MARK_TYPE_INV_SELL_ITEM: { + mActor_name_t item = Now_Private->inventory.pockets[table_idx]; + + *(u16**)mark_bitfield_p = &inv_ovl->item_mark_bitfield; + updated_mark_bitfield->field16 = 1 << table_idx; + *max_mark_count = mPr_POCKETS_SLOT_COUNT; + + if ((mode == mTG_MARK_CHK || mode == mTG_MARK_OFF || mode == mTG_MARK_CLR) || + (item != EMPTY_NO && !ITEM_IS_EXERCISE_CARD(item) && item != ITM_KNIFE_AND_FORK && + (ITEM_NAME_GET_TYPE(item) != NAME_TYPE_ITEM1 || (ITEM_NAME_GET_CAT(item) != ITEM1_CAT_MONEY)) && + (Common_Get(time.rtc_time).weekday != lbRTC_SUNDAY || + (ITEM_NAME_GET_TYPE(item) != NAME_TYPE_ITEM1 || (ITEM_NAME_GET_CAT(item) != ITEM1_CAT_KABU))))) { + return TRUE; + } + return FALSE; + } + case mTG_MARK_TYPE_INV_FG_MAIL: + case mTG_MARK_TYPE_INV_MAILBOX: + case mTG_MARK_TYPE_CPMAIL_MAIL: + case mTG_MARK_TYPE_MAILBOX: + case mTG_MARK_TYPE_CPMAIL_CPMAIL: { + if (table == mTG_TABLE_MAIL) { + *(u16**)mark_bitfield_p = &inv_ovl->mail_mark_bitfield2; + updated_mark_bitfield->field16 = 1 << table_idx; + *max_mark_count = mPr_INVENTORY_MAIL_COUNT; + + if (mode != mTG_MARK_CHK && mode != mTG_MARK_OFF && mode != mTG_MARK_CLR) { + if (mMl_check_not_used_mail(mail) == TRUE) { + return FALSE; + } + + if (menu_type == mSM_OVL_MAILBOX) { + if (mail->present != EMPTY_NO || + (mail->content.font != mMl_FONT_2 && mail->content.font != mMl_FONT_4) || + (mTG_mail_check(mail) & mTG_MAIL_FLAG_RECV) != mTG_MAIL_FLAG_RECV) { + return FALSE; + } + } else if (menu_type == mSM_OVL_CPMAIL) { + if ((mTG_mail_check(mail) & mTG_MAIL_FLAG_RECV) != mTG_MAIL_FLAG_RECV) { + return FALSE; + } + } else { + if ((mail->content.font != mMl_FONT_2 && mail->content.font != mMl_FONT_4) || + (mTG_mail_check(mail) & mTG_MAIL_FLAG_RECV) != mTG_MAIL_FLAG_RECV || + (mTG_mail_check(mail) & mTG_MAIL_FLAG_PRESENT) == mTG_MAIL_FLAG_PRESENT) { + return FALSE; + } + } + } + + return TRUE; + } else if (table == mTG_TABLE_MBOX) { + *(u16**)mark_bitfield_p = &mailbox_ovl->mark_bitfield; + updated_mark_bitfield->field16 = 1 << table_idx; + *max_mark_count = HOME_MAILBOX_SIZE; + + if ((mode != mTG_MARK_CHK || mode != mTG_MARK_OFF || mode != mTG_MARK_CLR)) { + if (mMl_check_not_used_mail(mail) == TRUE || + (mTG_mail_check(mail) & mTG_MAIL_FLAG_RECV) != mTG_MAIL_FLAG_RECV) { + return FALSE; + } + return TRUE; + } + } else if (table == mTG_TABLE_CPMAIL) { + if ((mode != mTG_MARK_CHK || mode != mTG_MARK_OFF || mode != mTG_MARK_CLR)) { + if (mMl_check_not_used_mail(mail) == TRUE || + (mTG_mail_check(mail) & mTG_MAIL_FLAG_RECV) != mTG_MAIL_FLAG_RECV) { + return FALSE; + } + } + + *(u32**)mark_bitfield_p = &cpmail_ovl->mark_bitfield; + updated_mark_bitfield->field32 = 1 << table_idx; + *max_mark_count = mCM_MAIL_COUNT; + } else { + return FALSE; + } + break; + } + case mTG_MARK_TYPE_MUSIC: { + *(u32**)mark_bitfield_p = music_ovl->mark_flg; + updated_mark_bitfield->music_box[(table_idx / 32)] = 1 << ((u32)table_idx - (table_idx / 32) * 32); + // SetMusicBox(updated_mark_bitfield->music_box, table_idx); + *max_mark_count = MINIDISK_NUM; + + if ((mode != mTG_MARK_CHK || mode != mTG_MARK_OFF || mode != mTG_MARK_CLR)) { + if (!ChkRoomMusicBox(table_idx)) { + return FALSE; + } + } + break; + } + case mTG_MARK_TYPE_NEEDLEWORK_ORIGINAL: + *(u16**)mark_bitfield_p = &needlework_ovl->mark_flg; + updated_mark_bitfield->field16 = 1 << table_idx; + *max_mark_count = mPr_ORIGINAL_DESIGN_COUNT; + + if (mode == mTG_MARK_CHK || mode == mTG_MARK_OFF || mode == mTG_MARK_CLR) { + if (mNW_check_hide_flg(submenu, table_idx)) { + return FALSE; + } + } + break; + case mTG_MARK_TYPE_CPORIGINAL_ORIGINAL: + *(u16**)mark_bitfield_p = &cporiginal_ovl->mark_flg; + updated_mark_bitfield->field16 = 1 << table_idx; + *max_mark_count = mCO_ORIGINAL_NUM; + + if (mode == mTG_MARK_CHK || mode == mTG_MARK_OFF || mode == mTG_MARK_CLR) { + if (mCO_check_hide_flg(submenu, mCO_top_folder(submenu), table_idx)) { + return FALSE; + } + } + break; + } + + return TRUE; +} + +static int mTG_bit_chk(u8* flags, u8* masks, int count) { + int res = 0; + int i; + + for (i = 0; i < count; i++) { + res |= *flags++ & *masks++; + } + + return res; +} + +static void mTG_bit_on(u8* flags, u8* bits, int count) { + int i; + + for (i = 0; i < count; i++) { + *flags++ |= *bits++; + } +} + +static void mTG_bit_off(u8* flags, u8* bits, int count) { + int i; + + for (i = 0; i < count; i++) { + *flags++ &= ~*bits++; + } +} + +static void mTG_bit_rvs(u8* flags, u8* bits, int count) { + int i; + + for (i = 0; i < count; i++) { + *flags++ ^= *bits++; + } +} + +static void mTG_bit_clr(u8* flags, u8* bits, int count) { + int i; + + for (i = 0; i < count; i++) { + *flags++ = 0; + } +} + +static int mTG_bit_chk_all0(u8* flags, u8* bits, int count) { + int res = 0; + int i; + + for (i = 0; i < count; i++) { + res |= *flags++ == 0; + } + + return res; +} + +static int mTG_mark_mainX(Submenu* submenu, mSM_MenuInfo_c* menu_info, int table, int table_idx, int mode, + int* chk_result) { + int mark_res; + Mail_c* mail; + mTG_mark_field_u set_flags; + mTG_mark_field_u* current_flags_p; + int max_flag_count; + int chk_res = FALSE; + int i; + + for (i = 0; i < 8; i++) { + set_flags.u8array[i] = 0; + } + + mail = mTG_get_mail_pointer(submenu, NULL); + mark_res = mTG_mark_main_sub(submenu, menu_info->menu_type, menu_info->data0, table, table_idx, mail, mode, + ¤t_flags_p, &max_flag_count, &set_flags); + if (mark_res) { + int byte_count = ((max_flag_count + 15) / 16) * 2; + + switch (mode) { + case mTG_MARK_CHK: + chk_res = mTG_bit_chk(current_flags_p->u8array, set_flags.u8array, byte_count); + break; + case mTG_MARK_ON: + mTG_bit_on(current_flags_p->u8array, set_flags.u8array, byte_count); + break; + case mTG_MARK_OFF: + mTG_bit_off(current_flags_p->u8array, set_flags.u8array, byte_count); + break; + case mTG_MARK_RVS: + mTG_bit_rvs(current_flags_p->u8array, set_flags.u8array, byte_count); + break; + case mTG_MARK_CLR: + mTG_bit_clr(current_flags_p->u8array, set_flags.u8array, byte_count); + break; + case mTG_MARK_CHK_ALL0: + chk_res = mTG_bit_chk_all0(current_flags_p->u8array, set_flags.u8array, byte_count); + break; + } + + if (mode != mTG_MARK_CHK) { + mTG_mark_mainX(submenu, menu_info, table, table_idx, mTG_MARK_CHK, &chk_res); + } + } + + if (chk_result != NULL) { + *chk_result = chk_res; + } + + return mark_res; +} + +static void mTG_mark_main_CLR(Submenu* submenu, mSM_MenuInfo_c* menu_info) { + switch (menu_info->menu_type) { + case mSM_OVL_INVENTORY: + mTG_mark_mainX(submenu, menu_info, mTG_TABLE_ITEM, 0, mTG_MARK_CLR, NULL); + mTG_mark_mainX(submenu, menu_info, mTG_TABLE_MAIL, 0, mTG_MARK_CLR, NULL); + break; + case mSM_OVL_MAILBOX: + mTG_mark_mainX(submenu, menu_info, mTG_TABLE_MAIL, 0, mTG_MARK_CLR, NULL); + mTG_mark_mainX(submenu, menu_info, mTG_TABLE_MBOX, 0, mTG_MARK_CLR, NULL); + break; + case mSM_OVL_CPMAIL: + mTG_mark_mainX(submenu, menu_info, mTG_TABLE_MAIL, 0, mTG_MARK_CLR, NULL); + mTG_mark_mainX(submenu, menu_info, mTG_TABLE_CPMAIL, 0, mTG_MARK_CLR, NULL); + break; + case mSM_OVL_CPORIGINAL: + mTG_mark_mainX(submenu, menu_info, mTG_TABLE_CPORIGINAL_NW, 0, mTG_MARK_CLR, NULL); + mTG_mark_mainX(submenu, menu_info, mTG_TABLE_CPORIGINAL, 0, mTG_MARK_CLR, NULL); + break; + } +} + +static int mTG_mark_main(Submenu* submenu, mSM_MenuInfo_c* menu_info, int mode, int* chk_result) { + mTG_Ovl_c* tag_ovl = submenu->overlay->tag_ovl; + mTG_tag_c* tag = &tag_ovl->tags[0]; + int idx = mTG_get_table_idx(tag); + + return mTG_mark_mainX(submenu, menu_info, tag->table, idx, mode, chk_result); +} + +static void mTG_write_proc(Submenu* submenu, mSM_MenuInfo_c* menu_info) { + mTG_Ovl_c* tag_ovl = submenu->overlay->tag_ovl; + mTG_tag_c* tag = &tag_ovl->tags[0]; + int idx = mTG_get_table_idx(tag); + int mail_idx = mMl_chk_mail_free_space(Now_Private->mail, mPr_INVENTORY_MAIL_COUNT); + + if (mail_idx >= 0) { + mTG_open_board_init(submenu, menu_info, mail_idx, mSM_BD_OPEN_WRITE, idx); + } else { + mTG_open_warning_window(submenu, menu_info, mWR_WARNING_WRITE); + } +} + +static void mTG_priceset_proc(Submenu* submenu, mSM_MenuInfo_c* menu_info) { + mTG_Ovl_c* tag_ovl = submenu->overlay->tag_ovl; + mTG_tag_c* tag = &tag_ovl->tags[0]; + mTG_tag_c* sel_tag = &tag_ovl->tags[tag_ovl->sel_tag_idx]; + + mTG_chg_tag_func2(submenu, menu_info, sel_tag, mTG_TYPE_HANIWA_PRICE); + submenu->overlay->haniwa_ovl->price = Save_Get(homes[menu_info->data1]).haniwa.items[tag->tag_col].extra_data; + sAdo_SysTrgStart(NA_SE_33); +} + +static void mTG_present_proc(Submenu* submenu, mSM_MenuInfo_c* menu_info) { + mTG_Ovl_c* tag_ovl = submenu->overlay->tag_ovl; + mTG_tag_c* tag = &tag_ovl->tags[0]; + int idx = mTG_get_table_idx(tag); + Mail_c* mail = &Now_Private->mail[idx]; + int present_myself = mMl_check_set_present_myself(mail); + + if (present_myself == FALSE && mPr_GetPossessionItemIdx(Now_Private, EMPTY_NO) == -1) { + mTG_open_warning_window(submenu, menu_info, mWR_WARNING_PR_LEAVE); + } else { + mTG_catch_item_from_table(submenu, NULL, &mail->present, + present_myself ? mPr_ITEM_COND_NORMAL : mPr_ITEM_COND_PRESENT, mTG_TABLE_MAIL, idx); + } +} + +static void mTG_show_proc(Submenu* submenu, mSM_MenuInfo_c* menu_info) { + mTG_set_trade_cond(submenu, menu_info, mHm_HANIWA_TRADE_1, 0); +} + +static void mTG_cancel_proc(Submenu* submenu, mSM_MenuInfo_c* menu_info) { + if (menu_info->menu_type == mSM_OVL_INVENTORY) { + mIV_Ovl_c* inv_ovl = submenu->overlay->inventory_ovl; + + if (menu_info->data0 == mSM_IV_OPEN_QUEST) { + mTG_close_window(submenu, menu_info, TRUE); + } else { + if (inv_ovl != NULL) { + inv_ovl->mail_mark_flag = 0; + } + + mTG_return_tag_init(submenu, mTG_TYPE_NONE, mTG_TYPE_FIELD_DEFAULT); + sAdo_SysTrgStart(MONO(NA_SE_3)); + } + } else { + mTG_return_tag_init(submenu, mTG_TYPE_NONE, mTG_TYPE_FIELD_DEFAULT); + sAdo_SysTrgStart(MONO(NA_SE_3)); + } }