From 1faf96890a137ad4aeda23e2d4708732b43bdc68 Mon Sep 17 00:00:00 2001 From: Prakxo Date: Wed, 9 Aug 2023 17:12:09 +0200 Subject: [PATCH] link m_snowman --- config/rel_slices.yml | 3 + include/m_common_data.h | 3 +- include/m_name_table.h | 9 +++ include/m_snowman.h | 17 ++++++ rel/m_snowman.c | 118 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 149 insertions(+), 1 deletion(-) create mode 100644 rel/m_snowman.c diff --git a/config/rel_slices.yml b/config/rel_slices.yml index 5e9fcde1..ce43852b 100644 --- a/config/rel_slices.yml +++ b/config/rel_slices.yml @@ -159,6 +159,9 @@ m_time.c: m_skin_matrix.c: .text: [0x803f1528, 0x803f1bb4] .rodata: [0x80643310, 0x80643318] +m_snowman.c: + .text: [0x803F1BB4, 0x803F1F94] + .rodata: [0x80643318, 0x80643330] m_view.c: .text: [0x803F3E58, 0x803F4E08] .rodata: [0x806433D8, 0x80643408] diff --git a/include/m_common_data.h b/include/m_common_data.h index b0833b34..266ffb96 100644 --- a/include/m_common_data.h +++ b/include/m_common_data.h @@ -188,7 +188,8 @@ typedef struct common_data_s { /* 0x0266A4 */ int scene_from_title_demo; /* next scene to be loaded when title demo finishes */ /* 0x0266A8 */ mNPS_schedule_c npc_schedule[SCHEDULE_NUM]; /* 0x0267A8 */ mNpc_walk_c npc_walk; - /* 0x026838 */ u8 _26838[0x2852C - 0x26838]; + /* 0x026838 */ u8 _26838[0x28528 - 0x26838]; + /* 0x028528 */ int snowman_msg_id; /* 0x02852C */ s16 money_power; /* 0x02852E */ s16 goods_power; /* 0x028530 */ Door_data_c door_data; /* misc door data */ diff --git a/include/m_name_table.h b/include/m_name_table.h index a4132ae2..95230cdd 100644 --- a/include/m_name_table.h +++ b/include/m_name_table.h @@ -1124,6 +1124,15 @@ extern int mNT_check_unknown(mActor_name_t item_no); #define ACTOR_PROP_HANIWA1 (ACTOR_PROP_HANIWA0 + 1) #define ACTOR_PROP_HANIWA2 (ACTOR_PROP_HANIWA1 + 1) #define ACTOR_PROP_HANIWA3 (ACTOR_PROP_HANIWA2 + 1) +#define SNOWMAN0 (ACTOR_PROP_HANIWA3 + 1) +#define SNOWMAN1 (SNOWMAN0 + 1) +#define SNOWMAN2 (SNOWMAN1 + 1) +#define SNOWMAN3 (SNOWMAN2 + 1) +#define SNOWMAN4 (SNOWMAN3 + 1) +#define SNOWMAN5 (SNOWMAN4 + 1) +#define SNOWMAN6 (SNOWMAN5 + 1) +#define SNOWMAN7 (SNOWMAN6 + 1) +#define SNOWMAN8 (SNOWMAN7 + 1) #define TRAIN_DOOR 0xA011 #define SP_NPC_START 0xD000 diff --git a/include/m_snowman.h b/include/m_snowman.h index 5fbef453..2b4c877e 100644 --- a/include/m_snowman.h +++ b/include/m_snowman.h @@ -2,6 +2,8 @@ #define M_SNOWMAN_H #include "types.h" +#include "m_lib.h" +#include "m_actor_type.h" #ifdef __cplusplus extern "C" { @@ -22,6 +24,21 @@ typedef struct snowman_save_data_s { /* 0x00 */ mSN_snowman_data_c snowmen_data[mSN_SAVE_COUNT]; } mSN_snowman_save_c; +/* sizeof(mSN_snowman_info_c) == 0xC */ +typedef struct snowman_info_s{ + /* 0x00 */ int scale; + /* 0x04 */ xyz_t pos; +}mSN_snowman_info_c; + +extern int mSN_check_life(mActor_name_t* ac, int idx); +extern int mSN_ClearSnowmanData(mActor_name_t* ac, int idx); +extern int mSN_ClearSnowman(mActor_name_t* ac); +extern int mSN_MeltSnowman(mActor_name_t* ac, int days); +extern int mSN_get_free_space(); +extern void mSN_regist_snowman_society(mSN_snowman_info_c* info); +extern void mSN_decide_msg(); +extern void mSN_snowman_init(); + #ifdef __cplusplus } #endif diff --git a/rel/m_snowman.c b/rel/m_snowman.c new file mode 100644 index 00000000..d9d58fe3 --- /dev/null +++ b/rel/m_snowman.c @@ -0,0 +1,118 @@ +#include "m_snowman.h" + +#include "m_common_data.h" +#include "libultra/libultra.h" +#include "m_field_info.h" +#include "m_police_box.h" +#include "m_name_table.h" +#include "m_time.h" + + +extern int mSN_check_life(mActor_name_t* ac, int idx){ + int ret = 0; + + if(Common_Get(time.season) == mTM_SEASON_WINTER){ + if((((*ac - SNOWMAN0) % 3) + idx) < mSN_SAVE_COUNT){ + ret = 1; + } + } + return ret; +} + +extern int mSN_ClearSnowmanData(mActor_name_t* ac, int idx){ + + bzero(Save_GetPointer(snowmen.snowmen_data[idx]), sizeof(mSN_snowman_data_c)); + *ac = 0; +} + +int mSN_ClearSnowman(u16* ac){ + int ret = 0; + u32 snowId = *ac; + + if((snowId >= SNOWMAN0) && (snowId <= SNOWMAN8)){ + mSN_ClearSnowmanData(ac, (int)(snowId - SNOWMAN0) / mSN_SAVE_COUNT); + ret = 1; + } + return ret; +} + +extern int mSN_MeltSnowman(mActor_name_t* ac, int days){ + int ret; + u32 snowId; + int snowmelt; + mSN_snowman_data_c* snowman; + snowId = *ac; + ret = 0; + + if((snowId >= SNOWMAN0) && (snowId <= SNOWMAN8)){ + snowmelt = ((int)(snowId - SNOWMAN0) / mSN_SAVE_COUNT); + if(days < 0){ + days = 1; + Save_Set(snowman_year, 0); + Save_Set(snowman_month, 0); + Save_Set(snowman_day, 0); + Save_Set(snowman_hour, 0); + + } + if(mSN_check_life(ac, days) == 0){ + mSN_ClearSnowmanData(ac, snowmelt); + } + else{ + snowman = Save_GetPointer(snowmen.snowmen_data[snowmelt]); + *ac += days; + for(; days != 0; days--){ + snowman->head_size = 0.8f * snowman->head_size; + snowman->body_size = 0.8f * snowman->body_size; + } + } + ret = 1; + } + + return ret; +} + +extern int mSN_get_free_space(void){ + int ret = 0; + int i; + mSN_snowman_data_c* snowman = Save_GetPointer(snowmen.snowmen_data[0]);; + + for(i = mSN_SAVE_COUNT; i != 0; i--){ + if(snowman->exists == 0){ + return ret; + } + snowman++; + ret++; + } + return -1; +} + +extern void mSN_regist_snowman_society(mSN_snowman_info_c* info){ + + xyz_t spos = info->pos; + mActor_name_t ac = *mFI_GetUnitFG(spos); + int snowId = mSN_get_free_space(); + xyz_t npos; + xyz_t ypos; + if(snowId != -1){ + mem_copy((u8*)Save_GetPointer(snowmen.snowmen_data[snowId]), (u8*)info, 4); + if(ac != 0){ + mPB_keep_item(ac); + npos = info->pos; + mFI_Wpos2DepositOFF(npos); + } + ypos = info->pos; + mFI_SetFG_common((u16)(snowId * mSN_SAVE_COUNT + SNOWMAN0),info->pos,1); + } + +} + +extern void mSN_decide_msg(){ + + Common_Set(snowman_msg_id, fqrand() * 3.0f); +} + +extern void mSN_snowman_init(){ + + bzero(Save_GetPointer(snowmen), sizeof(mSN_snowman_save_c)); + mSN_decide_msg(); +} \ No newline at end of file