diff --git a/config/rel_slices.yml b/config/rel_slices.yml index 7d9c18dd..1c9a1451 100644 --- a/config/rel_slices.yml +++ b/config/rel_slices.yml @@ -405,6 +405,11 @@ ef_room_sunshine_museum.c: .text: [0x804D0704, 0x804D0F3C] .rodata: [0x806464B8, 0x80646508] .data: [0x8069C0A0, 0x8069C0C8] +ef_room_sunshine_minsect.c: + .text: [0x804D0F3C,0x804D1BBC] + .rodata: [0x80646508,0x80646558] + .data: [0x8069C0C8, 0x8069C0F0] + .bss: [0x81300BD0, 0x81300BD8] m_huusui_room_ovl.c: .text: [0x804D1BBC, 0x804D2164] .rodata: [0x80646558, 0x806465C8] diff --git a/include/ef_room_sunshine_minsect.h b/include/ef_room_sunshine_minsect.h index 9c97e877..7c27ad42 100644 --- a/include/ef_room_sunshine_minsect.h +++ b/include/ef_room_sunshine_minsect.h @@ -3,6 +3,7 @@ #include "types.h" #include "m_actor.h" +#include "ef_room_sunshine.h" #ifdef __cplusplus extern "C" { @@ -10,6 +11,12 @@ extern "C" { extern ACTOR_PROFILE Room_Sunshine_Minsect_Profile; +typedef struct effect_room_sunshine_minsect_s{ + ROOMSUNSHINE_ACTOR ef_sunshine_class; +}ROOMSUNSHINEMINSECT_ACTOR; + +extern u8 draw_status; + #ifdef __cplusplus } #endif diff --git a/include/m_actor.h b/include/m_actor.h index 8a181445..dabe939e 100644 --- a/include/m_actor.h +++ b/include/m_actor.h @@ -445,7 +445,7 @@ typedef enum bank_id { ACTOR_OBJ_BANK_407, ACTOR_OBJ_BANK_408, ACTOR_OBJ_BANK_EF_MUSEUM, - ACTOR_OBJ_BANK_410, + ACTOR_OBJ_BANK_EF_MINSECT, ACTOR_OBJ_BANK_411, ACTOR_OBJ_BANK_412, ACTOR_OBJ_BANK_413, diff --git a/rel/ef_room_sunshine_minsect.c b/rel/ef_room_sunshine_minsect.c new file mode 100644 index 00000000..f7b0c0cd --- /dev/null +++ b/rel/ef_room_sunshine_minsect.c @@ -0,0 +1,323 @@ +#include "ef_room_sunshine_minsect.h" + +#include "m_common_data.h" +#include "m_name_table.h" +#include "m_debug.h" +#include "m_collision_bg.h" +#include "sys_matrix.h" + +void Ef_Room_Sunshine_Minsect_actor_ct(ACTOR* actor, GAME* play); +void Ef_Room_Sunshine_Minsect_actor_dt(ACTOR* actor, GAME* play); +void Ef_Room_Sunshine_MinsectL_actor_draw(ACTOR* actor, GAME* play); +void Ef_Room_Sunshine_MinsectL_actor_move(ACTOR* actor, GAME* play); +void Ef_Room_Sunshine_MinsectR_actor_draw(ACTOR* actor, GAME* play); +void Ef_Room_Sunshine_MinsectR_actor_move(ACTOR* actor, GAME* play); + +extern Gfx rom_museum4_ue_model[]; +extern Gfx rom_museum4_model[]; +extern Gfx obj_museum4_shine_1T_model[]; +extern Gfx obj_museum4_shine_2T_model[]; + +u8 draw_status; + +ACTOR_PROFILE Room_Sunshine_Minsect_Profile = { + mAc_PROFILE_ROOM_SUNSHINE_MINSECT, + ACTOR_PART_ITEM, + ACTOR_STATE_NO_MOVE_WHILE_CULLED | ACTOR_STATE_NO_DRAW_WHILE_CULLED, + EMPTY_NO, + ACTOR_OBJ_BANK_EF_MINSECT, + sizeof(ROOMSUNSHINEMINSECT_ACTOR), + Ef_Room_Sunshine_Minsect_actor_ct, + NONE_ACTOR_PROC, + Ef_Room_Sunshine_MinsectR_actor_move, + Ef_Room_Sunshine_MinsectR_actor_draw, + NULL, +}; + +void Ef_Room_Sunshine_Minsect_actor_ct(ACTOR* actor, GAME* game){ + ROOMSUNSHINEMINSECT_ACTOR* minsect = (ROOMSUNSHINEMINSECT_ACTOR*)actor; + xyz_t pos; + + minsect->ef_sunshine_class.unk_174 = 0; + draw_status = 0; + if(minsect->ef_sunshine_class.actor_class.actor_specific == 0){ + minsect->ef_sunshine_class.actor_class.mv_proc = Ef_Room_Sunshine_MinsectL_actor_move; + minsect->ef_sunshine_class.actor_class.dw_proc = Ef_Room_Sunshine_MinsectL_actor_draw; + } + else{ + minsect->ef_sunshine_class.actor_class.world.position.x -= 1.0f; + } + + pos = minsect->ef_sunshine_class.actor_class.world.position; + + minsect->ef_sunshine_class.actor_class.world.position.y = mCoBG_GetBgY_OnlyCenter_FromWpos(0.0f, &pos); + + minsect->ef_sunshine_class.actor_class.scale.x = 0.01f; + minsect->ef_sunshine_class.actor_class.scale.y = 0.01f; + minsect->ef_sunshine_class.actor_class.scale.z = 0.01f; + minsect->ef_sunshine_class.actor_class.cull_radius = 10000.0f; + + switch(minsect->ef_sunshine_class.actor_class.actor_specific){ + + case 2: + + minsect->ef_sunshine_class.actor_class.mv_proc = Ef_Room_Sunshine_MinsectL_actor_move; + minsect->ef_sunshine_class.actor_class.dw_proc = Ef_Room_Sunshine_MinsectL_actor_draw; + minsect->ef_sunshine_class.actor_class.world.position.x += 5.0f; + minsect->ef_sunshine_class.actor_class.world.position.x -= 6.0f; + break; + + case 3: + minsect->ef_sunshine_class.actor_class.world.position.x -= 5.0f; + minsect->ef_sunshine_class.actor_class.world.position.x += 6.0f; + break; + } +} + +f32 calc_scale_Ef_Room_Sunshine_Minsect(int flag, int sec){ + + if(flag == 0){ + return 0.01f * (1.5f * sin_s((sec << 14) / 28800.0f)); + } + else{ + return 0.01f * (1.5f * sin_s((sec << 14) / 14400.0f)); + } +} + +int calc_alpha_Ef_Room_SunshineMinsect(){ + f32 ret; + int sec; + + if(Common_Get(time.now_sec) < 14400){ + ret = 120.0f * ((14400 - Common_Get(time.now_sec)) / 14400.0f); + } + else if(Common_Get(time.now_sec) < 72000){ + //any other number matches codegen, but 43200 breaks + sec = (Common_Get(time.now_sec) - 43200) >= 0 ? + (Common_Get(time.now_sec) - 43200U) : -(Common_Get(time.now_sec) - 43200U); + + ret = 255.0f * ((28800 - sec) / 28800.0f); + } + else{ + ret = 120.0f * ((14400 - (86400 - Common_Get(time.now_sec))) / 14400.0f); + } + + if((Common_Get(weather) == 1) || (Common_Get(weather) == 2)){ + ret *= 0.6f; + } + + return (u8)ret; +} + +void Ef_Room_Sunshine_MinsectL_actor_move(ACTOR* actor, GAME* game){ + ROOMSUNSHINEMINSECT_ACTOR* minsect = (ROOMSUNSHINEMINSECT_ACTOR*)actor; + + if(Common_Get(time.now_sec) < 14400){ + minsect->ef_sunshine_class.actor_class.scale.x = calc_scale_Ef_Room_Sunshine_Minsect(1, Common_Get(time.now_sec)); + } + else if ((Common_Get(time.now_sec) >= 43200) && (Common_Get(time.now_sec) < 72000)){ + minsect->ef_sunshine_class.actor_class.scale.x = calc_scale_Ef_Room_Sunshine_Minsect(0, Common_Get(time.now_sec) - 43200); + } + else{ + minsect->ef_sunshine_class.actor_class.scale.x = 0.0f; + } + + minsect->ef_sunshine_class.actor_class.world.position.y = minsect->ef_sunshine_class.actor_class.home.position.y; + minsect->ef_sunshine_class.actor_class.world.position.y += 0.01f * GETREG(TAKREG,64); +} + +void Ef_Room_Sunshine_MinsectR_actor_move(ACTOR* actor, GAME* game){ + ROOMSUNSHINEMINSECT_ACTOR* minsect = (ROOMSUNSHINEMINSECT_ACTOR*)actor; + + if((Common_Get(time.now_sec) >= 14400) && (Common_Get(time.now_sec) < 43200)){ + minsect->ef_sunshine_class.actor_class.scale.x = -calc_scale_Ef_Room_Sunshine_Minsect(0, 43200 - Common_Get(time.now_sec)); + } + else if (Common_Get(time.now_sec) >= 72000){ + minsect->ef_sunshine_class.actor_class.scale.x = -calc_scale_Ef_Room_Sunshine_Minsect(1, 86400 -Common_Get(time.now_sec)); + } + else{ + minsect->ef_sunshine_class.actor_class.scale.x = 0.0f; + } + minsect->ef_sunshine_class.actor_class.world.position.y = minsect->ef_sunshine_class.actor_class.home.position.y; + minsect->ef_sunshine_class.actor_class.world.position.y += 0.01f * GETREG(TAKREG,64); +} + + +void setup_mode_Ef_Room_Sunshine_Minsect(ACTOR* actor, GAME_PLAY* play){ + ROOMSUNSHINE_ACTOR* sunshine = (ROOMSUNSHINE_ACTOR*)actor; + u8* color; + int calc; + + GRAPH* graph = play->game.graph; + + OPEN_DISP(graph); + + Matrix_translate(sunshine->actor_class.world.position.x, sunshine->actor_class.world.position.y, + sunshine->actor_class.world.position.z, 0); + Matrix_scale(sunshine->actor_class.scale.x, sunshine->actor_class.scale.y, sunshine->actor_class.scale.z,1); + + gDPPipeSync(NEXT_POLY_XLU_DISP); + + gSPMatrix(NEXT_POLY_XLU_DISP, _Matrix_to_Mtx_new(play->game.graph), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + + if((Common_Get(time.now_sec) >= 14400) && (Common_Get(time.now_sec) < 72000)){ + color =play->kankyo.base_light.sun_color_window; + } + else{ + color =play->kankyo.base_light.moon_color_window; + } + + calc = ((u8)calc_alpha_Ef_Room_SunshineMinsect() * mKK_windowlight_alpha_get()); + + gDPSetPrimColor(NEXT_POLY_XLU_DISP, 0, calc, color[0], color[1], color[2], 75); + CLOSE_DISP(graph); + +} + +void setup_mode_Ef_Room_Sunshine_Minsect_decal(ACTOR* actor, GAME_PLAY* play){ + ROOMSUNSHINE_ACTOR* sunshine = (ROOMSUNSHINE_ACTOR*)actor; + u8* color; + int calc; + + GRAPH* graph = play->game.graph; + + OPEN_DISP(graph); + + Matrix_translate(sunshine->actor_class.world.position.x, sunshine->actor_class.world.position.y, + sunshine->actor_class.world.position.z, 0); + Matrix_scale(sunshine->actor_class.scale.x, sunshine->actor_class.scale.y, sunshine->actor_class.scale.z,1); + + gDPPipeSync(NEXT_POLY_OPA_DISP); + + gSPMatrix(NEXT_POLY_OPA_DISP, _Matrix_to_Mtx_new(play->game.graph), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + + if((Common_Get(time.now_sec) >= 14400) && (Common_Get(time.now_sec) < 72000)){ + color =play->kankyo.base_light.sun_color_window; + } + else{ + color =play->kankyo.base_light.moon_color_window; + } + + calc = ((u8)calc_alpha_Ef_Room_SunshineMinsect() * mKK_windowlight_alpha_get()); + + gDPSetPrimColor(NEXT_POLY_OPA_DISP, 0, calc, color[0], color[1], color[2], 75); + CLOSE_DISP(graph); + +} + + +void BG_draw_Minsect(ACTOR* actor, GAME_PLAY* play){ + GRAPH* graph; + + if(!(draw_status & 4)){ + draw_status |= 4; + } + + if((draw_status & 1) && (draw_status & 2)){ + draw_status = 0; + } + + graph = play->game.graph; + Matrix_scale(0.0625f, 0.0625f, 0.0625f, 0); + Global_kankyo_set_room_prim(play); + OPEN_DISP(graph); + gSPMatrix(NEXT_POLY_OPA_DISP, _Matrix_to_Mtx_new(play->game.graph), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPDisplayList(NEXT_POLY_OPA_DISP, rom_museum4_ue_model); + + CLOSE_DISP(graph); +} + +void BG_draw_Minsect_niwa(ACTOR* actor, GAME_PLAY* play){ + GRAPH* graph; + + graph = play->game.graph; + Matrix_scale(0.0625f, 0.0625f, 0.0625f, 0); + Global_kankyo_set_room_prim(play); + OPEN_DISP(graph); + gSPMatrix(NEXT_POLY_OPA_DISP, _Matrix_to_Mtx_new(play->game.graph), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPDisplayList(NEXT_POLY_OPA_DISP, rom_museum4_model); + + CLOSE_DISP(graph); +} + +void Ef_Room_Sunshine_MinsectL_actor_draw(ACTOR* actor, GAME* game){ + GRAPH* graph; + + _texture_z_light_fog_prim(game->graph); + _texture_z_light_fog_prim_shadow(game->graph); + _texture_z_light_fog_prim_xlu(game->graph); + + draw_status |= 1; + + if(mKK_windowlight_alpha_get() < 9.99999974738e-05f){ + if ((draw_status & 1) && (draw_status & 2) && !(draw_status & 4)){ + BG_draw_Minsect_niwa(actor,(GAME_PLAY*)game); + BG_draw_Minsect(actor,(GAME_PLAY*)game); + } + } + else if(0.0f == actor->scale.x){ + if ((draw_status & 1) && (draw_status & 2) && !(draw_status & 4)){ + BG_draw_Minsect_niwa(actor,(GAME_PLAY*)game); + BG_draw_Minsect(actor,(GAME_PLAY*)game); + } + } + else{ + s16 reg; + graph = game->graph; + + BG_draw_Minsect_niwa(actor,(GAME_PLAY*)game); + setup_mode_Ef_Room_Sunshine_Minsect(actor,(GAME_PLAY*)game); + OPEN_DISP(graph); + + gSPDisplayList(NEXT_POLY_XLU_DISP, obj_museum4_shine_1T_model); + setup_mode_Ef_Room_Sunshine_Minsect_decal(actor,(GAME_PLAY*)game); + + if(REGADDR(TAKREG, 0) == 0){ + gSPDisplayList(NEXT_POLY_OPA_DISP, obj_museum4_shine_2T_model); + } + BG_draw_Minsect(actor,(GAME_PLAY*)game); + + CLOSE_DISP(graph); + } +} + +void Ef_Room_Sunshine_MinsectR_actor_draw(ACTOR* actor, GAME* game){ + GRAPH* graph; + + + _texture_z_light_fog_prim(game->graph); + _texture_z_light_fog_prim_shadow(game->graph); + _texture_z_light_fog_prim_xlu(game->graph); + + draw_status |= 2; + + if(mKK_windowlight_alpha_get() < 9.99999974738e-05f){ + if ((draw_status & 1) && (draw_status & 2) && !(draw_status & 4)){ + BG_draw_Minsect_niwa(actor,(GAME_PLAY*)game); + BG_draw_Minsect(actor,(GAME_PLAY*)game); + } + } + else if(0.0f == actor->scale.x){ + if ((draw_status & 1) && (draw_status & 2) && !(draw_status & 4)){ + BG_draw_Minsect_niwa(actor,(GAME_PLAY*)game); + BG_draw_Minsect(actor,(GAME_PLAY*)game); + } + } + else{ + graph = game->graph; + + BG_draw_Minsect_niwa(actor,(GAME_PLAY*)game); + setup_mode_Ef_Room_Sunshine_Minsect(actor,(GAME_PLAY*)game); + OPEN_DISP(graph); + + gSPDisplayList(NEXT_POLY_XLU_DISP, obj_museum4_shine_1T_model); + setup_mode_Ef_Room_Sunshine_Minsect_decal(actor,(GAME_PLAY*)game); + + if(REGADDR(TAKREG, 0) == 0){ + gSPDisplayList(NEXT_POLY_OPA_DISP, obj_museum4_shine_2T_model); + } + BG_draw_Minsect(actor,(GAME_PLAY*)game); + + CLOSE_DISP(graph); + } +} \ No newline at end of file