From dfde99aa63ee99acb12e9d1b76f0c323cb9c9949 Mon Sep 17 00:00:00 2001 From: Cuyler36 Date: Wed, 11 Oct 2023 18:03:20 -0400 Subject: [PATCH] Implement & link m_mark_room.c --- config/rel_slices.yml | 9 +- include/m_mail.h | 2 + include/m_mark_room.h | 4 + include/m_mark_room_ovl.h | 16 ++++ rel/m_mark_room.c | 175 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 203 insertions(+), 3 deletions(-) create mode 100644 include/m_mark_room_ovl.h create mode 100644 rel/m_mark_room.c diff --git a/config/rel_slices.yml b/config/rel_slices.yml index 1a81a260..8c87646b 100644 --- a/config/rel_slices.yml +++ b/config/rel_slices.yml @@ -127,6 +127,9 @@ m_kankyo.c: .rodata: [0x806424C0, 0x80642640] .data: [0x80655D78, 0x80656670] .bss: [0x81297A68, 0x81297B18] +m_lib.c: + .text: [0x803BAB0C, 0x803BB960] + .rodata: [0x80642640, 0x80642680] m_lights.c: .text: [0x803BB960, 0x803BC510] .rodata: [0x80642680, 0x806426D8] @@ -143,9 +146,9 @@ m_mail_check.c: m_mail_password_check.c: .text: [0x803BD250, 0x803BEC9C] .data: [0x806566C0, 0x806571D8] -m_lib.c: - .text: [0x803BAB0C, 0x803BB960] - .rodata: [0x80642640, 0x80642680] +m_mark_room.c: + .text: [0x803BEC9C, 0x803BF210] + .rodata: [0x806426D8, 0x806426E8] m_museum.c: .text: [0x803C6228, 0x803C74C0] .rodata: [0x80642938, 0x80642950] diff --git a/include/m_mail.h b/include/m_mail.h index 08656634..3fa21a0c 100644 --- a/include/m_mail.h +++ b/include/m_mail.h @@ -53,6 +53,8 @@ enum { mMl_TYPE_SHOP_SALE_LEAFLET = 2, mMl_TYPE_BROKER_SALE_LEAFLET = 3, + mMl_TYPE_HRA = 6, + mMl_TYPE_FISHING_CONTENST = 9, mMl_TYPE_12 = 12 diff --git a/include/m_mark_room.h b/include/m_mark_room.h index e0da5dcd..6fb31590 100644 --- a/include/m_mark_room.h +++ b/include/m_mark_room.h @@ -3,11 +3,15 @@ #include "types.h" #include "game_h.h" +#include "m_mark_room_ovl.h" #ifdef __cplusplus extern "C" { #endif +#define mMkRm_HINT_NUM 19 + +extern void mMkRm_ReportChangePlayerRoom(); extern void mMkRm_MarkRoom(GAME* game); #ifdef __cplusplus diff --git a/include/m_mark_room_ovl.h b/include/m_mark_room_ovl.h new file mode 100644 index 00000000..79163e8e --- /dev/null +++ b/include/m_mark_room_ovl.h @@ -0,0 +1,16 @@ +#ifndef M_MARK_ROOM_OVL_H +#define M_MARK_ROOM_OVL_H + +#include "types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +extern int mMkRm_MarkRoomOvl(int player_no); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/rel/m_mark_room.c b/rel/m_mark_room.c new file mode 100644 index 00000000..ef536c33 --- /dev/null +++ b/rel/m_mark_room.c @@ -0,0 +1,175 @@ +#include "m_mark_room.h" + +#include "m_house.h" +#include "m_common_data.h" +#include "m_scene_table.h" +#include "m_handbill.h" + +static int mMkRm_GetMarkOrder(int player_no) { + if (mEv_CheckArbeit() == FALSE && player_no < PLAYER_NUM) { + int arrange_idx = mHS_get_arrange_idx(player_no); + mHm_hs_c* house = Save_GetPointer(homes[arrange_idx]); + lbRTC_time_c now_time = Common_Get(time.rtc_time); + + lbRTC_year_t year = Save_Get(homes[arrange_idx]).hra_mark_time.year; + lbRTC_month_t month = Save_Get(homes[arrange_idx]).hra_mark_time.month; + lbRTC_day_t day = Save_Get(homes[arrange_idx]).hra_mark_time.day; + + if ( + year != now_time.year || + month != now_time.month || + day != now_time.day + ) { + return TRUE; + } + } + + return FALSE; +} + +static void mMkRm_ReportMarkEnd(int player_no) { + if (player_no < PLAYER_NUM) { + int arrange_idx = mHS_get_arrange_idx(player_no); + lbRTC_time_c now_time = Common_Get(time.rtc_time); + + Save_Get(homes[arrange_idx]).hra_mark_time.year = now_time.year; + Save_Get(homes[arrange_idx]).hra_mark_time.month = now_time.month; + Save_Get(homes[arrange_idx]).hra_mark_time.day = now_time.day; + Save_Get(homes[arrange_idx]).flags.house_updated = FALSE; + } +} + +extern void mMkRm_ReportChangePlayerRoom() { + int player_no = Common_Get(player_no); + + if (Save_Get(scene_no) == SCENE_COTTAGE_MY || mSc_IS_SCENE_BASEMENT(Save_Get(scene_no))) { + return; + } + + if (player_no < PLAYER_NUM) { + int arrange_idx = mHS_get_arrange_idx(player_no); + mActor_name_t field_id = mFI_GetFieldId(); + + if (mFI_GET_TYPE(field_id) == mFI_FIELD_PLAYER0_ROOM && (mActor_name_t)(field_id - mFI_FIELD_PLAYER0_ROOM) == arrange_idx) { + lbRTC_time_c now_time = Common_Get(time.rtc_time); + + Save_Get(homes[arrange_idx]).flags.house_updated = TRUE; + Save_Get(homes[arrange_idx]).hra_mark_time.year = now_time.year; + Save_Get(homes[arrange_idx]).hra_mark_time.month = now_time.month; + Save_Get(homes[arrange_idx]).hra_mark_time.day = now_time.day; + } + } +} + +static int mMkRm_NoMarkLetter(int arrange_idx, int handbill_no) { + int free_idx = mMl_chk_mail_free_space(Save_Get(homes[arrange_idx]).mailbox, HOME_MAILBOX_SIZE); + + if (free_idx >= 0) { + Mail_c mail; + int header_back_start; + + mMl_clear_mail(&mail); + mHandbill_Load_HandbillFromRom(mail.content.header, &header_back_start, mail.content.footer, mail.content.body, handbill_no); + mail.content.font = mMl_FONT_0; + mail.content.header_back_start = header_back_start; + mail.content.mail_type = mMl_TYPE_HRA; + mail.content.paper_type = 51; /* wing paper */ + mMl_set_to_plname(&mail, &Common_Get(now_private)->player_ID); + mMl_copy_mail(Save_Get(homes[arrange_idx]).mailbox + free_idx, &mail); + + return TRUE; + } + + return FALSE; +} + +static void mMkRm_NoMarkLetter_Hint(int arrange_idx, int player_no) { + u32* hint_info_bitfield = &Save_Get(homes[arrange_idx]).hra_mark_info; + int free_hint_num = 0; + int i; + + #ifndef IMPROVEMENTS + u32 all_mark = 0; + for (i = 0; i < mMkRm_HINT_NUM; i++) { + all_mark |= (1 << i); // ??? + } + #else + u32 all_mark = (1 << mMkRm_HINT_NUM) - 1; // lol + #endif + + + if (hint_info_bitfield[0] == all_mark) { + hint_info_bitfield[0] = 0; // clear all hints + free_hint_num = mMkRm_HINT_NUM; + } + else { + for (i = 0; i < mMkRm_HINT_NUM; i++) { + if (((hint_info_bitfield[0] >> i) & 1) == 0) { + free_hint_num++; + } + } + } + + if (free_hint_num != 0) { + int selected_hint = RANDOM(free_hint_num); + int n = 0; + + for (i = 0; i < mMkRm_HINT_NUM; i++) { + if (((hint_info_bitfield[0] >> i) & 1) == 0) { + if (n == selected_hint) { + if (mMkRm_NoMarkLetter(arrange_idx, 0x1DC + i)) { + hint_info_bitfield[0] |= (1 << i); + mMkRm_ReportMarkEnd(player_no); + } + + break; + } + else { + n++; + } + } + } + } +} + +extern void mMkRm_MarkRoom(GAME* game) { + int player_no = Common_Get(player_no); + int arrange_idx = 0; + int i; + + if (player_no < PLAYER_NUM) { + if (mEv_CheckArbeit() == FALSE) { + mHm_flg_c* flags; + + arrange_idx = mHS_get_arrange_idx(player_no); + flags = &Save_Get(homes[arrange_idx]).flags; + + if (flags->hra_member == FALSE) { + /* Send welcome letter & save HRA member status */ + if (mMkRm_NoMarkLetter(arrange_idx, 0x1EF)) { + flags->hra_member = TRUE; + mMkRm_ReportMarkEnd(player_no); + + return; + } + + return; + } + } + + if (mMkRm_GetMarkOrder(player_no)) { + if (Save_Get(homes[arrange_idx]).flags.house_updated == TRUE) { + mMkRm_MarkRoomOvl(player_no); + mMkRm_ReportMarkEnd(player_no); + } + else { + int rng = RANDOM(10); + + if (rng == 5 || rng == 9) { + mMkRm_NoMarkLetter_Hint(arrange_idx, player_no); + mMkRm_ReportMarkEnd(player_no); + } + } + } + } +}