From 9c50266d463b586736d16418dcd8a60dab7dff41 Mon Sep 17 00:00:00 2001 From: Rainchus Date: Fri, 29 Nov 2024 12:48:36 -0600 Subject: [PATCH 1/3] decompile ef_young_tree.c --- configure.py | 2 +- include/m_field_make.h | 22 ++--- src/effect/ef_young_tree.c | 166 ++++++++++++++++++++++++++++++++++++- 3 files changed, 174 insertions(+), 16 deletions(-) diff --git a/configure.py b/configure.py index b1c956e7..e003315d 100644 --- a/configure.py +++ b/configure.py @@ -1346,7 +1346,7 @@ config.libs = [ Object(NonMatching, "effect/ef_walk_asimoto.c"), Object(NonMatching, "effect/ef_warau.c"), Object(NonMatching, "effect/ef_yajirushi.c"), - Object(NonMatching, "effect/ef_young_tree.c"), + Object(Matching, "effect/ef_young_tree.c"), Object(Matching, "effect/ef_yukidama.c"), Object(Matching, "effect/ef_yukidaruma.c"), Object(Matching, "effect/ef_yukihane.c"), diff --git a/include/m_field_make.h b/include/m_field_make.h index 614f4b61..1ac5254a 100644 --- a/include/m_field_make.h +++ b/include/m_field_make.h @@ -192,17 +192,17 @@ typedef struct field_display_list_info_s { } mFM_field_draw_info_c; typedef struct field_pal_s { - u16* earth_pal; - u16* cliff_pal; - u16* bush_pal; - u16* flower0_pal; - u16* flower1_pal; - u16* flower2_pal; - u16* grass_pal; - u16* tree_pal; - u16* cedar_tree_pal; // probably? - u16* palm_tree_pal; - u16* golden_tree_pal; +/* 0x00 */ u16* earth_pal; +/* 0x04 */ u16* cliff_pal; +/* 0x08 */ u16* bush_pal; +/* 0x0C */ u16* flower0_pal; +/* 0x10 */ u16* flower1_pal; +/* 0x14 */ u16* flower2_pal; +/* 0x18 */ u16* grass_pal; +/* 0x1C */ u16* tree_pal; +/* 0x20 */ u16* cedar_tree_pal; // probably? +/* 0x24 */ u16* palm_tree_pal; +/* 0x28 */ u16* golden_tree_pal; } mFM_field_pal_c; typedef struct field_bg_sound_source_s { diff --git a/src/effect/ef_young_tree.c b/src/effect/ef_young_tree.c index e9b11e91..023c661c 100644 --- a/src/effect/ef_young_tree.c +++ b/src/effect/ef_young_tree.c @@ -1,4 +1,8 @@ #include "ef_effect_control.h" +#include "m_common_data.h" +#include "m_debug.h" +#include "m_rcp.h" +#include "sys_matrix.h" static void eYoung_Tree_init(xyz_t pos, int prio, s16 angle, GAME* game, u16 item_name, s16 arg0, s16 arg1); static void eYoung_Tree_ct(eEC_Effect_c* effect, GAME* game, void* ct_arg); @@ -18,17 +22,171 @@ eEC_PROFILE_c iam_ef_young_tree = { }; static void eYoung_Tree_init(xyz_t pos, int prio, s16 angle, GAME* game, u16 item_name, s16 arg0, s16 arg1) { - // TODO + eEC_CLIP->make_effect_proc(eEC_EFFECT_YOUNG_TREE, pos, NULL, game, NULL, item_name, prio, arg0, arg1); } static void eYoung_Tree_ct(eEC_Effect_c* effect, GAME* game, void* ct_arg) { - // TODO + GAME_PLAY* play = (GAME_PLAY*)game; + Camera2* camera = &play->camera; + + f32 dist = search_position_distance(&camera->lookat.eye, &camera->lookat.center); + + effect->scale.x = 0.010299999f; + effect->scale.y = 0.0095f; + effect->scale.z = 0.0095f; + + if (effect->arg0 == 2 || effect->arg0 == 1) { + effect->velocity = ZeroVec; + effect->velocity.y = 0.75f; + effect->acceleration = ZeroVec; + effect->acceleration.y = -0.05f; + effect->timer = 40; + } else if (effect->arg0 == 3) { + effect->velocity = ZeroVec; + effect->acceleration = ZeroVec; + effect->timer = 14; + } else { + effect->velocity = ZeroVec; + effect->acceleration = ZeroVec; + effect->timer = 82; + } + effect->effect_specific[1] = 0; + effect->effect_specific[2] = 0; + + xyz_t_sub(&camera->lookat.eye, &camera->lookat.center, &effect->offset); + xyz_t_mult_v(&effect->offset, 1.0f / dist); + effect->effect_specific[0] = Common_Get(time.season); } static void eYoung_Tree_mv(eEC_Effect_c* effect, GAME* game) { - // TODO + f32 fVar4; + f32 dVar3; + xyz_t effPos; + xyz_t effPos2; + s16 uVar2; + + xyz_t_add(&effect->velocity, &effect->acceleration, &effect->velocity); + xyz_t_add(&effect->position, &effect->velocity, &effect->position); + if (effect->arg0 == 1) { + effect->effect_specific[1] = effect->effect_specific[1] + 384; + } else if (effect->arg0 == 2) { + effect->effect_specific[1] = effect->effect_specific[1] - 384; + } else { + dVar3 = eEC_CLIP->calc_adjust_proc(effect->timer, 0, 0x28, 0.0f, 2184.0f); + fVar4 = sin_s(effect->effect_specific[2]); + + effect->effect_specific[1] = dVar3 * fVar4; + effect->effect_specific[2] = effect->effect_specific[2] + 0xC68; + if ((effect->timer & 0x1F) == 0) { + effPos = effect->position; + if (Common_Get(time).term_idx == mTM_TERM_4) { + uVar2 = 6; + } else { + uVar2 = 4; + } + + if (effect->arg1 == 1) { + uVar2 |= 0x2000; + } else if (effect->arg1 == 2) { + uVar2 |= 0x4000; + } else if (effect->arg1 == 3) { + uVar2 |= 0x6000; + } + + effPos.x = effPos.x + fqrand2() * 30.0f; + effPos.y = effPos.y + fqrand() * 30.0f; + uVar2 |= 0x8000; + + (*Common_Get(clip.effect_clip)->effect_make_proc)( + 0x33, effPos, 2, 0, game, 0xFFFF, 0, uVar2 + ); + + if (effect->effect_specific[0] == 3) { + effPos2 = effect->position; + effPos2.x = effPos2.x + fqrand2() * 30.0f; + effPos2.y = effPos2.y + fqrand() * 30.0f; + (*Common_Get(clip.effect_clip)->effect_make_proc)( + 0x34, effPos2, 2, 0, game, 0xFFFF, 0, 0 + ); + } + } + } } +extern Gfx ef_w_young_palm_modelT[]; +extern Gfx ef_s_young_palm_modelT[]; +extern Gfx ef_w_young_cedar_modelT[]; +extern Gfx ef_s_young_cedar_modelT[]; +extern Gfx ef_w_youngtree_00_modelT[]; +extern Gfx ef_f_youngtree_00_modelT[]; +extern Gfx ef_s_youngtree_00_modelT[]; + static void eYoung_Tree_dw(eEC_Effect_c* effect, GAME* game) { - // TODO + GRAPH* graph; + mFM_field_pal_c* field_pal = mFI_GetFieldPal(); + u16* cedar_pal = field_pal->cedar_tree_pal; + u16* palm_pal = field_pal->palm_tree_pal; + u16* golden_pal = field_pal->golden_tree_pal; + s16 remain = 0x28 - effect->timer; + u8 alpha; + + if (effect->arg0 == 2 || effect->arg0 == 1) { + alpha = (int)eEC_CLIP->calc_adjust_proc(remain, 0, 0x28, 255.0f, 0.0f); + } else { + alpha = (int)eEC_CLIP->calc_adjust_proc(effect->timer, 0, 8, 0.0f, 255.0f); + } + + graph = game->graph; + _texture_z_light_fog_prim_xlu(graph); + Matrix_translate(effect->position.x, effect->position.y + 3.0f, effect->position.z + 3.0f, 0); + + if (effect->arg1 == 0 || effect->arg1 == 3) { + Matrix_RotateVector(effect->effect_specific[1], &effect->offset, 1); + } else if (effect->arg1 == 1) { + Matrix_translate(0.0f, (f32)GETREG(TAKREG, 20) + 5.0f, 0.0f, 1); + Matrix_RotateVector(effect->effect_specific[1], &effect->offset, 1); + Matrix_translate(0.0f, -5.0f - (f32)GETREG(TAKREG, 20), 0.0f, 1); + } else { + Matrix_translate(0.0f, 15.0f, 0.0f, 1); + Matrix_RotateVector(effect->effect_specific[1], &effect->offset, 1); + Matrix_translate(0.0f, -15.0f, 0.0f, 1); + } + Matrix_scale(effect->scale.x, effect->scale.y, effect->scale.z, 1); + + OPEN_DISP(graph); + gSPMatrix(NEXT_POLY_XLU_DISP, _Matrix_to_Mtx_new(game->graph), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + + if (effect->arg1 == 0) { + gSPSegment(NEXT_POLY_XLU_DISP, ANIME_1_TXT_SEG, cedar_pal); + } else if (effect->arg1 == 3) { + gSPSegment(NEXT_POLY_XLU_DISP, ANIME_1_TXT_SEG, golden_pal); + } else { + gSPSegment(NEXT_POLY_XLU_DISP, ANIME_1_TXT_SEG, palm_pal); + } + + gDPSetPrimColor(NEXT_POLY_XLU_DISP, 0, 255, 255, 255, 255, alpha); + gDPSetTextureAdjustMode(NEXT_POLY_XLU_DISP, G_TA_DOLPHIN); + + if (effect->arg1 == 1) { + if (effect->effect_specific[0] == 3) { + gSPDisplayList(NEXT_POLY_XLU_DISP, &ef_w_young_palm_modelT); + } else { + gSPDisplayList(NEXT_POLY_XLU_DISP, &ef_s_young_palm_modelT); + } + } else if (effect->arg1 == 2) { + if (effect->effect_specific[0] == 3) { + gSPDisplayList(NEXT_POLY_XLU_DISP, &ef_w_young_cedar_modelT); + } else{ + gSPDisplayList(NEXT_POLY_XLU_DISP, &ef_s_young_cedar_modelT); + } + } else if (effect->effect_specific[0] == 3) { + gSPDisplayList(NEXT_POLY_XLU_DISP, &ef_w_youngtree_00_modelT); + } else if (Common_Get(time).term_idx == mTM_TERM_4) { + gSPDisplayList(NEXT_POLY_XLU_DISP, &ef_f_youngtree_00_modelT); + } else { + gSPDisplayList(NEXT_POLY_XLU_DISP, &ef_s_youngtree_00_modelT); + } + + gDPSetTextureAdjustMode(NEXT_POLY_XLU_DISP, G_TA_N64); + CLOSE_DISP(graph); } From ed18ce257068804cb119f990230f0d66b15eece2 Mon Sep 17 00:00:00 2001 From: Rainchus Date: Fri, 29 Nov 2024 13:21:31 -0600 Subject: [PATCH 2/3] implement some enums related to eEC_BUSH_HAPPA --- include/ef_effect_control.h | 5 +++++ src/actor/ac_effectbg.c | 14 +++++++------- src/effect/ef_young_tree.c | 24 ++++++++++-------------- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/include/ef_effect_control.h b/include/ef_effect_control.h index 97160b35..4d851886 100644 --- a/include/ef_effect_control.h +++ b/include/ef_effect_control.h @@ -20,6 +20,11 @@ extern "C" { #define eEC_DEFAULT_DEATH_DIST (800.0f) #define eEC_IGNORE_DEATH_DIST (-1000.203064f) // ignore death range check when set to this +#define eEC_BUSH_HAPPA_TREE (0 << 13) +#define eEC_BUSH_HAPPA_PALM (1 << 13) +#define eEC_BUSH_HAPPA_CEDAR (2 << 13) +#define eEC_BUSH_HAPPA_GOLD (3 << 13) + enum effect_type { eEC_EFFECT_SHOCK, eEC_EFFECT_DUST, diff --git a/src/actor/ac_effectbg.c b/src/actor/ac_effectbg.c index db80bed0..a2706b44 100644 --- a/src/actor/ac_effectbg.c +++ b/src/actor/ac_effectbg.c @@ -646,17 +646,17 @@ static void EffectBG_Make_Leafs(EffectBg_c* efbg, GAME* game, xyz_t pos, s16 cou } } else if (type == EffectBG_EFFECT_CUT_RIGHT_PALM) { bush_yuki_type = 0; - bush_happa_type = 0x2000 | 4; + bush_happa_type = eEC_BUSH_HAPPA_PALM | 4; } else if (type == EffectBG_EFFECT_CUT_RIGHT_CEDAR) { bush_yuki_type = 0; - bush_happa_type = 0x4000 | 4; + bush_happa_type = eEC_BUSH_HAPPA_CEDAR | 4; } else if (type == EffectBG_EFFECT_CUT_RIGHT_GOLD) { bush_yuki_type = 0; if (Common_Get(time).term_idx == mTM_TERM_4) { - bush_happa_type = 0x4000 | 0x2000 | 6; + bush_happa_type = eEC_BUSH_HAPPA_CEDAR | eEC_BUSH_HAPPA_PALM | 6; } else { - bush_happa_type = 0x4000 | 0x2000 | 4; + bush_happa_type = eEC_BUSH_HAPPA_CEDAR | eEC_BUSH_HAPPA_PALM | 4; } } else { if (Common_Get(time).term_idx == 4) { @@ -669,11 +669,11 @@ static void EffectBG_Make_Leafs(EffectBg_c* efbg, GAME* game, xyz_t pos, s16 cou } if ((efbg->status & EffectBg_STATUS_GOLD) != 0 || efbg->variant == EffectBG_VARIANT_GOLD_SMALL) { - bush_happa_type |= 0x4000 | 0x2000; + bush_happa_type |= eEC_BUSH_HAPPA_CEDAR | eEC_BUSH_HAPPA_PALM; } else if ((efbg->status & EffectBg_STATUS_PALM) != 0 || efbg->variant == EffectBG_VARIANT_PALM_SMALL) { - bush_happa_type |= 0x2000; + bush_happa_type |= eEC_BUSH_HAPPA_PALM; } else if ((efbg->status & EffectBg_STATUS_CEDAR) != 0 || efbg->variant == EffectBG_VARIANT_CEDAR_SMALL) { - bush_happa_type |= 0x4000; + bush_happa_type |= eEC_BUSH_HAPPA_CEDAR; } while (count-- != 0) { diff --git a/src/effect/ef_young_tree.c b/src/effect/ef_young_tree.c index 023c661c..4e795775 100644 --- a/src/effect/ef_young_tree.c +++ b/src/effect/ef_young_tree.c @@ -84,30 +84,26 @@ static void eYoung_Tree_mv(eEC_Effect_c* effect, GAME* game) { } else { uVar2 = 4; } - + if (effect->arg1 == 1) { - uVar2 |= 0x2000; + uVar2 |= eEC_BUSH_HAPPA_PALM; } else if (effect->arg1 == 2) { - uVar2 |= 0x4000; + uVar2 |= eEC_BUSH_HAPPA_CEDAR; } else if (effect->arg1 == 3) { - uVar2 |= 0x6000; + uVar2 |= eEC_BUSH_HAPPA_PALM | eEC_BUSH_HAPPA_CEDAR; } - + effPos.x = effPos.x + fqrand2() * 30.0f; effPos.y = effPos.y + fqrand() * 30.0f; uVar2 |= 0x8000; - - (*Common_Get(clip.effect_clip)->effect_make_proc)( - 0x33, effPos, 2, 0, game, 0xFFFF, 0, uVar2 - ); - + + eEC_CLIP->effect_make_proc(eEC_EFFECT_BUSH_HAPPA, effPos, 2, 0, game, 0xFFFF, 0, uVar2); + if (effect->effect_specific[0] == 3) { effPos2 = effect->position; effPos2.x = effPos2.x + fqrand2() * 30.0f; effPos2.y = effPos2.y + fqrand() * 30.0f; - (*Common_Get(clip.effect_clip)->effect_make_proc)( - 0x34, effPos2, 2, 0, game, 0xFFFF, 0, 0 - ); + eEC_CLIP->effect_make_proc(eEC_EFFECT_BUSH_YUKI, effPos2, 2, 0, game, 0xFFFF, 0, 0); } } } @@ -176,7 +172,7 @@ static void eYoung_Tree_dw(eEC_Effect_c* effect, GAME* game) { } else if (effect->arg1 == 2) { if (effect->effect_specific[0] == 3) { gSPDisplayList(NEXT_POLY_XLU_DISP, &ef_w_young_cedar_modelT); - } else{ + } else { gSPDisplayList(NEXT_POLY_XLU_DISP, &ef_s_young_cedar_modelT); } } else if (effect->effect_specific[0] == 3) { From fa496838179fa77a4ba235a9f0ba497ff80382ad Mon Sep 17 00:00:00 2001 From: Rainchus Date: Sat, 30 Nov 2024 04:25:46 -0600 Subject: [PATCH 3/3] fix some enum usage --- src/actor/ac_effectbg.c | 6 +++--- src/effect/ef_young_tree.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/actor/ac_effectbg.c b/src/actor/ac_effectbg.c index a2706b44..cfb198f7 100644 --- a/src/actor/ac_effectbg.c +++ b/src/actor/ac_effectbg.c @@ -654,9 +654,9 @@ static void EffectBG_Make_Leafs(EffectBg_c* efbg, GAME* game, xyz_t pos, s16 cou bush_yuki_type = 0; if (Common_Get(time).term_idx == mTM_TERM_4) { - bush_happa_type = eEC_BUSH_HAPPA_CEDAR | eEC_BUSH_HAPPA_PALM | 6; + bush_happa_type = eEC_BUSH_HAPPA_GOLD | 6; } else { - bush_happa_type = eEC_BUSH_HAPPA_CEDAR | eEC_BUSH_HAPPA_PALM | 4; + bush_happa_type = eEC_BUSH_HAPPA_GOLD | 4; } } else { if (Common_Get(time).term_idx == 4) { @@ -669,7 +669,7 @@ static void EffectBG_Make_Leafs(EffectBg_c* efbg, GAME* game, xyz_t pos, s16 cou } if ((efbg->status & EffectBg_STATUS_GOLD) != 0 || efbg->variant == EffectBG_VARIANT_GOLD_SMALL) { - bush_happa_type |= eEC_BUSH_HAPPA_CEDAR | eEC_BUSH_HAPPA_PALM; + bush_happa_type |= eEC_BUSH_HAPPA_GOLD; } else if ((efbg->status & EffectBg_STATUS_PALM) != 0 || efbg->variant == EffectBG_VARIANT_PALM_SMALL) { bush_happa_type |= eEC_BUSH_HAPPA_PALM; } else if ((efbg->status & EffectBg_STATUS_CEDAR) != 0 || efbg->variant == EffectBG_VARIANT_CEDAR_SMALL) { diff --git a/src/effect/ef_young_tree.c b/src/effect/ef_young_tree.c index 4e795775..7ed1dcc4 100644 --- a/src/effect/ef_young_tree.c +++ b/src/effect/ef_young_tree.c @@ -90,7 +90,7 @@ static void eYoung_Tree_mv(eEC_Effect_c* effect, GAME* game) { } else if (effect->arg1 == 2) { uVar2 |= eEC_BUSH_HAPPA_CEDAR; } else if (effect->arg1 == 3) { - uVar2 |= eEC_BUSH_HAPPA_PALM | eEC_BUSH_HAPPA_CEDAR; + uVar2 |= eEC_BUSH_HAPPA_GOLD; } effPos.x = effPos.x + fqrand2() * 30.0f;