From 2e10d1803c742d31537cc05bb7ef1d2e8315e5aa Mon Sep 17 00:00:00 2001 From: Nabnut Date: Tue, 24 Sep 2024 20:13:35 +0200 Subject: [PATCH] Renaming Bundle --- include/prop.h | 2 +- src/BGS/code_3420.c | 4 +- src/core2/ba/marker.c | 2 +- src/core2/code_41FB0.c | 302 ++++++++++++++++++++++------------------- src/core2/code_9E370.c | 6 +- src/core2/code_AD5B0.c | 4 +- src/core2/code_CD6E0.c | 2 +- 7 files changed, 171 insertions(+), 151 deletions(-) diff --git a/include/prop.h b/include/prop.h index f72bc381..6f701bed 100644 --- a/include/prop.h +++ b/include/prop.h @@ -162,7 +162,7 @@ typedef struct actor_s{ u32 unk10_4:1; u32 unk10_3:2; u32 unk10_1:1; - u32 unk10_0:1; + u32 is_bundle:1; AnimCtrl *animctrl; ActorAnimationInfo *unk18; TUPLE(f32, unk1C); diff --git a/src/BGS/code_3420.c b/src/BGS/code_3420.c index b1b30acf..b2bec1c6 100644 --- a/src/BGS/code_3420.c +++ b/src/BGS/code_3420.c @@ -5,7 +5,7 @@ extern f32 func_80256AB4(f32, f32, f32, f32); extern f32 func_8025715C(f32, f32); extern f32 *chVile_getPostion(ActorMarker *); -extern void func_802C8F7C(f32); +extern void bundle_setRandomVelocity(f32); extern void func_802FDCB8(s32); enum chvilegame_piece_type_e { @@ -303,7 +303,7 @@ void func_80389F08(ActorMarker *marker) { for(i = 0; i < 3; i++){ if (var_s2 < 3) { bundle_setYaw(vile->yaw + (f32) (i * 30)); - func_802C8F7C(2.0f); + bundle_setRandomVelocity(2.0f); bundle_spawn_f32(6, vile->position); var_s2 += 1; } else { diff --git a/src/core2/ba/marker.c b/src/core2/ba/marker.c index 9c7dfe11..37fcf794 100644 --- a/src/core2/ba/marker.c +++ b/src/core2/ba/marker.c @@ -263,7 +263,7 @@ void __baMarker_resolveCollision(Prop *other_prop){ if(actor->despawn_flag) return; - if(actor->unk10_0 && func_802C9C14(actor)) + if(actor->is_bundle && func_802C9C14(actor)) return; }//L8028BD1C diff --git a/src/core2/code_41FB0.c b/src/core2/code_41FB0.c index ef5f8baf..dfaaab79 100644 --- a/src/core2/code_41FB0.c +++ b/src/core2/code_41FB0.c @@ -10,41 +10,47 @@ extern bool func_80309D58(f32[3], s32); extern void ml_vec3f_normalize(f32 [3]); typedef struct { - s16 unk0; + s16 flags; // u8 pad2[0x2]; s32 actor_id; s32 count; - s16 unkC; - s16 unkE; - s16 unk10; + s16 sfx_id; + s16 sfx_volume; + s16 sfx_sampleRate; // u8 pad12[0x2]; - f32 unk14; - f32 unk18; - f32 unk1C; - f32 unk20; - f32 unk24; - f32 unk28; - f32 unk2C; - f32 unk30; -} struct41FB0s; + f32 velocity_x; + f32 randomVelocity_x; + f32 velocity_y; + f32 randomVelocity_y; + f32 velocity_z; + f32 randomVelocity_z; + f32 bounce_factor; + f32 yaw; +} BundleInfo; typedef struct { - s32 unk0; - s16 unk4; + s32 index; + s16 flags; s16 unk6; - f32 unk8[3]; - f32 unk14[3]; - f32 unk20; - f32 unk24; - f32 unk28; + f32 position[3]; + f32 velocity[3]; + f32 yaw; + f32 yaw_speed; + f32 elapsed_time; u8 unk2C; u8 unk2D; u8 unk2E; - u8 unk2F; -} struct41FB0s_1; + u8 state; +} Bundle; /* .data */ -enum core2_41FB0_e{ +enum bundle_state_e { + BUNDLE_STATE_1_MOVING = 1, + BUNDLE_STATE_2_YAWING, + BUNDLE_STATE_3_IDLE +}; + +enum core2_41FB0_e { CORE2_41FB0_0_MM_HUT_NOTES, CORE2_41FB0_1_MM_HUT_EGGS, CORE2_41FB0_2_MM_HUT_GRUBLIN, @@ -59,12 +65,11 @@ enum core2_41FB0_e{ CORE2_41FB0_C_BGS_HUT_JIGGY, CORE2_41FB0_E_YUMYUM_EGG = 0xe, - CORE2_41FB0_F_YUMYUM_RED_FEATHER, - + CORE2_41FB0_F_YUMYUM_RED_FEATHER }; // #define 41FB0_FLAG_SET_YAW 0x0020 -struct41FB0s gBundle_array[] = { +BundleInfo gBundle_array[] = { /*MM HUT 1*/ {0x0021, ACTOR_51_MUSIC_NOTE, 5, SFX_3E9_UNKNOWN, 1, 16000, 125.0f, 25.0f, 725.0f, 125.0f, 125.0f, 25.0f, 0.6f, 0.0f}, /*MM HUT 2*/ {0x0021, ACTOR_52_BLUE_EGG, 5, SFX_21_EGG_BOUNCE_1, 1, 16000, 100.0f, 50.0f, 500.0f, 250.0f, 100.0f, 50.0f, 0.6f, 0.0f}, /*MM HUT 3*/ {0x0021, ACTOR_6_GRUBLIN, 1, SFX_8_BANJO_LANDING_04, 1, 20000, 0.0f, 0.0f, 550.0f, 250.0f, 200.0f, 0.0f, 0.6f, 0.0f}, @@ -107,31 +112,31 @@ struct41FB0s gBundle_array[] = { }; /* .bss */ -s32 D_8037DDB0; +s32 gBundle_sfxCooldown; f32 gBundle_yaw; -f32 D_8037DDB8; +f32 gBundle_randomVelocity; /* .public */ Actor *bundle_spawn_f32(s32 arg0, f32 position[3]); /* .code */ -void func_802C8F40(void){ - D_8037DDB0 = 0; +void bundle_reset(void) { + gBundle_sfxCooldown = 0; gBundle_yaw = 0.0f; - D_8037DDB8 = 1.0f; + gBundle_randomVelocity = 1.0f; } -void func_802C8F68(void){} +void bundle_free(void) {} -void bundle_setYaw(f32 yaw){ +void bundle_setYaw(f32 yaw) { gBundle_yaw = yaw; } -void func_802C8F7C(f32 arg0){ - D_8037DDB8 = arg0; +void bundle_setRandomVelocity(f32 velocity) { + gBundle_randomVelocity = velocity; } -Actor *bundle_spawn_s32(s32 index, s32 position[3]){ +Actor *bundle_spawn_s32(s32 index, s32 position[3]) { f32 pos_float[3]; pos_float[0] = position[0]; pos_float[1] = position[1]; @@ -141,55 +146,55 @@ Actor *bundle_spawn_s32(s32 index, s32 position[3]){ Actor *__bundle_spawnWithFirstActor(s32 index, f32 position[3], Actor *firstActor) { static f32 D_80366C4C = 400.0f; - struct41FB0s *bundle; //s2 + BundleInfo *bundle_info; //s2 Actor *actor; //s3 s32 i; - struct41FB0s_1 *s0; + Bundle *bundle; - bundle = gBundle_array + index; + bundle_info = gBundle_array + index; actor = NULL; - for (i = 0; i < bundle->count; i++) {//L802C90B0 - gBundle_yaw += 360.0 / bundle->count; + for (i = 0; i < bundle_info->count; i++) {//L802C90B0 + gBundle_yaw += 360.0 / bundle_info->count; while (360.0 <= gBundle_yaw) { gBundle_yaw -= 360.0; } //L802C9114 - actor = (i == 0 && firstActor) ? firstActor : actor_spawnWithYaw_f32(bundle->actor_id, position, 0); - actor->unk10_0 = 1; + actor = (i == 0 && firstActor) ? firstActor : actor_spawnWithYaw_f32(bundle_info->actor_id, position, 0); + actor->is_bundle = TRUE; - s0 = (struct41FB0s_1 *) &actor->unkBC; - s0->unk0 = index; - s0->unk2F = 1; - s0->unk6 = 1; - ml_vec3f_copy(s0->unk8, actor->position); - ml_vec3f_copy(actor->position, s0->unk8); + bundle = (Bundle *) &actor->unkBC; + bundle->index = index; + bundle->state = BUNDLE_STATE_1_MOVING; + bundle->unk6 = 1; + ml_vec3f_copy(bundle->position, actor->position); + ml_vec3f_copy(actor->position, bundle->position); - if (D_8037DDB8 != 1.0f) { - s0->unk14[0] = bundle->unk14 * D_8037DDB8; - s0->unk14[1] = bundle->unk1C + randf2(0.0f, bundle->unk20); - s0->unk14[2] = bundle->unk24 * D_8037DDB8; - D_8037DDB8 = 1.0f; + if (gBundle_randomVelocity != 1.0f) { + bundle->velocity[0] = bundle_info->velocity_x * gBundle_randomVelocity; + bundle->velocity[1] = bundle_info->velocity_y + randf2(0.0f, bundle_info->randomVelocity_y); + bundle->velocity[2] = bundle_info->velocity_z * gBundle_randomVelocity; + gBundle_randomVelocity = 1.0f; } else {//L802C91CC - s0->unk14[0] = bundle->unk14 + randf2(0.0f, bundle->unk18); - s0->unk14[1] = bundle->unk1C + randf2(0.0f, bundle->unk20); - s0->unk14[2] = bundle->unk24 + randf2(0.0f, bundle->unk28); + bundle->velocity[0] = bundle_info->velocity_x + randf2(0.0f, bundle_info->randomVelocity_x); + bundle->velocity[1] = bundle_info->velocity_y + randf2(0.0f, bundle_info->randomVelocity_y); + bundle->velocity[2] = bundle_info->velocity_z + randf2(0.0f, bundle_info->randomVelocity_z); }//L802C9210 - ml_vec3f_yaw_rotate_copy(s0->unk14, s0->unk14, gBundle_yaw); - s0->unk24 = D_80366C4C *= -1; - actor->yaw = s0->unk20 = (bundle->unk0 & 0x20) ? bundle->unk30 : randf2(0.0f, 360.0f); - s0->unk28 = 0.0f; - s0->unk2C = 0; - s0->unk2D = 1; - s0->unk4 = bundle->unk0; - s0->unk2E = (bundle->unk0 & 0x1) ? (0.5 < randf()) : 0; + ml_vec3f_yaw_rotate_copy(bundle->velocity, bundle->velocity, gBundle_yaw); + bundle->yaw_speed = D_80366C4C *= -1; + actor->yaw = bundle->yaw = (bundle_info->flags & 0x20) ? bundle_info->yaw : randf2(0.0f, 360.0f); + bundle->elapsed_time = 0.0f; + bundle->unk2C = 0; + bundle->unk2D = 1; + bundle->flags = bundle_info->flags; + bundle->unk2E = (bundle_info->flags & 0x1) ? (0.5 < randf()) : 0; - if (bundle->unk0 & 0x200) { - actor->unk5C = s0->unk8[1]; + if (bundle_info->flags & 0x200) { + actor->unk5C = bundle->position[1]; } }//L802C92E8 @@ -197,7 +202,7 @@ Actor *__bundle_spawnWithFirstActor(s32 index, f32 position[3], Actor *firstActo } Actor *__bundle_spawnFromFirstActor(s32 index, Actor *actor) { - gBundle_array[index].unk30 = actor->yaw; + gBundle_array[index].yaw = actor->yaw; return __bundle_spawnWithFirstActor(index, actor->position, actor); } @@ -206,7 +211,7 @@ Actor *bundle_spawn_f32(s32 index, f32 position[3]) { } bool func_802C939C(Actor *actor, f32 arg1[3], f32 arg2[3], f32 arg3[3], bool arg4) { - struct41FB0s_1 *sp64 = (struct41FB0s_1 *)&actor->unkBC; + Bundle *bundle = (Bundle *)&actor->unkBC; f32 sp60; bool var_v1; f32 sp50[3]; @@ -215,7 +220,7 @@ bool func_802C939C(Actor *actor, f32 arg1[3], f32 arg2[3], f32 arg3[3], bool arg s32 sp3C; - if (sp64->unk4 & 0x80) { + if (bundle->flags & 0x80) { if (actor->unk10_25 != 0) { if (func_80307258(arg2, actor->unk10_25 - 1, actor->unk10_18 - 1) == -1) { ml_vec3f_diff_copy(arg3, arg2, arg1); @@ -261,129 +266,144 @@ bool func_802C939C(Actor *actor, f32 arg1[3], f32 arg2[3], f32 arg3[3], bool arg } } } - if (var_v1 && sp64->unk2D && (actor->marker->modelId == ASSET_363_MODEL_HONEYCOMB)) { - ml_vec3f_scale_copy(sp44, arg3, sp60 / (f32) (1 << sp64->unk6)); + if (var_v1 && bundle->unk2D && (actor->marker->modelId == ASSET_363_MODEL_HONEYCOMB)) { + ml_vec3f_scale_copy(sp44, arg3, sp60 / (f32) (1 << bundle->unk6)); var_v1 = TRUE; arg2[0] += sp44[0]; arg2[1] += sp44[1]; arg2[2] += sp44[2]; if (actor->marker->modelId != ASSET_363_MODEL_HONEYCOMB) { - sp64->unk6++; + bundle->unk6++; } - if (sp64->unk6 == 5) { - sp64->unk2D = FALSE; + if (bundle->unk6 == 5) { + bundle->unk2D = FALSE; } else { var_v1 = FALSE; } } else { - sp64->unk2D = FALSE; + bundle->unk2D = FALSE; } arg1[1] -= sp60; arg2[1] -= sp60; return var_v1; } -void func_802C96E4(Actor *actor) { - f32 sp6C; - struct41FB0s_1 *sp68; - struct41FB0s *sp64; - f32 sp58[3]; +void bundle_update(Actor *actor) { + f32 tick; + Bundle *bundle; + BundleInfo *bundle_info; + f32 previous_position[3]; f32 sp4C[3]; f32 sp40[3]; s32 pad; s32 pad2; - f32 var_f0; + f32 speed; - sp6C = time_getDelta(); - sp68 = (struct41FB0s_1 *)&actor->unkBC; - sp64 = &gBundle_array[sp68->unk0]; + tick = time_getDelta(); + bundle = (Bundle *) &actor->unkBC; + bundle_info = &gBundle_array[bundle->index]; - if (D_8037DDB0 > 0) { - D_8037DDB0--; + if (gBundle_sfxCooldown > 0) { + gBundle_sfxCooldown--; } - - switch (sp68->unk2F) { - case 3: + + switch (bundle->state) { + case BUNDLE_STATE_3_IDLE: break; - case 1: - sp68->unk28 += sp6C; - ml_vec3f_copy(sp58, sp68->unk8); - ml_vec3f_scale_copy(sp4C, sp68->unk14, sp6C); - sp68->unk8[0] += sp4C[0]; - sp68->unk8[1] += sp4C[1]; - sp68->unk8[2] += sp4C[2]; - if (1.2 < sp68->unk28) { - sp68->unk2C = 1; + + case BUNDLE_STATE_1_MOVING: + bundle->elapsed_time += tick; + ml_vec3f_copy(previous_position, bundle->position); + ml_vec3f_scale_copy(sp4C, bundle->velocity, tick); + bundle->position[0] += sp4C[0]; + bundle->position[1] += sp4C[1]; + bundle->position[2] += sp4C[2]; + + if (1.2 < bundle->elapsed_time) { + bundle->unk2C = 1; } - if (!((sp64->unk0 & 0x40) && (sp68->unk28 < 1.2)) - && ( (func_802C939C(actor, sp58, sp68->unk8, sp40, sp64->unk0 & 8)) - || ((sp64->unk0 & 0x200) && (sp68->unk14[1] < -((sp64->unk20 / 2) + sp64->unk1C))) - ) + + if (!((bundle_info->flags & 0x40) && (bundle->elapsed_time < 1.2)) + && ((func_802C939C(actor, previous_position, bundle->position, sp40, bundle_info->flags & 8)) + || ((bundle_info->flags & 0x200) && (bundle->velocity[1] < -((bundle_info->randomVelocity_y / 2) + bundle_info->velocity_y)))) ) { - if (sp64->unk0 & 0x204) { + if (bundle_info->flags & 0x204) { sp40[0] = 0.0f; sp40[1] = 1.0f; sp40[2] = 0.0f; } - ml_vec3f_scale(sp68->unk14, -1.0f); - var_f0 = ((sp68->unk14[0] * sp40[0]) + (sp68->unk14[1] * sp40[1]) + (sp68->unk14[2] * sp40[2])); - ml_vec3f_scale(sp40, 2*var_f0); - ml_vec3f_diff_copy(sp68->unk14, sp40, sp68->unk14); - if (D_8037DDB0 == 0) { - if (sp64->unkC != 0) { - func_8030E878(sp64->unkC, (f32)sp64->unkE, sp64->unk10, sp68->unk8, 300.0f, 3000.0f); + + ml_vec3f_scale(bundle->velocity, -1.0f); + speed = ((bundle->velocity[0] * sp40[0]) + (bundle->velocity[1] * sp40[1]) + (bundle->velocity[2] * sp40[2])); + ml_vec3f_scale(sp40, 2 * speed); + ml_vec3f_diff_copy(bundle->velocity, sp40, bundle->velocity); + + if (gBundle_sfxCooldown == 0) { + if (bundle_info->sfx_id != 0) { + func_8030E878(bundle_info->sfx_id, (f32) bundle_info->sfx_volume, bundle_info->sfx_sampleRate, bundle->position, 300.0f, 3000.0f); } - D_8037DDB0 = sp64->count * 8; + gBundle_sfxCooldown = bundle_info->count * 8; } - ml_vec3f_scale(sp68->unk14, sp64->unk2C); - var_f0 = gu_sqrtf((sp68->unk14[0]*sp68->unk14[0]) + (sp68->unk14[1]*sp68->unk14[1]) + (sp68->unk14[2]*sp68->unk14[2])); - if (((var_f0 < 200.0f) && (sp40[1] > 0.75)) || (var_f0 < 10.0f)) { - sp68->unk2F = 2; - sp68->unk2C = 1; - if (sp64->unk0 & 0x10) { + + ml_vec3f_scale(bundle->velocity, bundle_info->bounce_factor); + speed = gu_sqrtf((bundle->velocity[0] * bundle->velocity[0]) + (bundle->velocity[1] * bundle->velocity[1]) + (bundle->velocity[2] * bundle->velocity[2])); + + if (((speed < 200.0f) && (sp40[1] > 0.75)) || (speed < 10.0f)) { + bundle->state = BUNDLE_STATE_2_YAWING; + bundle->unk2C = 1; + + if (bundle_info->flags & 0x10) { actor->marker->propPtr->unk8_3 = TRUE; } } - else{ + else { } - if (sp64->unk0 & 0x200) { - sp68->unk8[1] = actor->unk5C; - } - } else { - if (sp64->unk0 & 0x100) { - sp68->unk14[1] -= 4000.0 * sp6C; - } else { - sp68->unk14[1] -= 1500.0 * sp6C; + + if (bundle_info->flags & 0x200) { + bundle->position[1] = actor->unk5C; } } - ml_vec3f_copy(actor->position, sp68->unk8); + else { + if (bundle_info->flags & 0x100) { + bundle->velocity[1] -= 4000.0 * tick; + } + else { + bundle->velocity[1] -= 1500.0 * tick; + } + } + + ml_vec3f_copy(actor->position, bundle->position); break; - case 2: - if (sp64->unk0 & 2) { - sp68->unk20 += (sp68->unk24 * sp6C); - while (sp68->unk20 >= 360.0f) { sp68->unk20 -= 360.0f; } - while (sp68->unk20 < 0.0f) { sp68->unk20 += 360.0f; } - actor->yaw = sp68->unk20; + case BUNDLE_STATE_2_YAWING: + if (bundle_info->flags & 2) { + bundle->yaw += (bundle->yaw_speed * tick); + while (bundle->yaw >= 360.0f) { bundle->yaw -= 360.0f; } + while (bundle->yaw < 0.0f) { bundle->yaw += 360.0f; } + + actor->yaw = bundle->yaw; } - var_f0 = (sp68->unk24 >= 0.0f) ? sp68->unk24 : -sp68->unk24; - if (var_f0 < 0.1) { - sp68->unk2F = 3U; + + speed = (bundle->yaw_speed >= 0.0f) ? bundle->yaw_speed : -bundle->yaw_speed; + + if (speed < 0.1) { + bundle->state = BUNDLE_STATE_3_IDLE; } break; } + if (actor->position[1] < -5000.0f) { marker_despawn(actor->marker); } } -f32 *func_802C9C0C(Actor *actor){ - struct41FB0s_1 *ptr = (struct41FB0s_1 *)&actor->unkBC; - return ptr->unk14; +f32 *bundle_getVelocity(Actor *actor){ + Bundle *ptr = (Bundle *)&actor->unkBC; + return ptr->velocity; } bool func_802C9C14(Actor *actor){ - struct41FB0s_1 *ptr = (struct41FB0s_1 *)&actor->unkBC; + Bundle *ptr = (Bundle *)&actor->unkBC; return ptr->unk2C < 1U; } diff --git a/src/core2/code_9E370.c b/src/core2/code_9E370.c index 6b8db97b..2eaa28b2 100644 --- a/src/core2/code_9E370.c +++ b/src/core2/code_9E370.c @@ -588,9 +588,9 @@ void func_803268B4(void) { if ((actor_info->shadow_scale != 0.0f) && actor->unk124_6 && marker->unk14_21) { func_802D7124(actor, actor_info->shadow_scale); } - if (actor->unk10_0) { + if (actor->is_bundle) { actor = &suBaddieActorArray->data[temp_v1]; - func_802C96E4(actor); + bundle_update(actor); } } } @@ -837,7 +837,7 @@ Actor *actor_new(s32 position[3], s32 yaw, ActorInfo* actorInfo, u32 flags){ suLastBaddie->initialized = FALSE; suLastBaddie->volatile_initialized = FALSE; suLastBaddie->lifetime_value = 0.0f; - suLastBaddie->unk10_0 = 0; + suLastBaddie->is_bundle = FALSE; suLastBaddie->unk104 = NULL; suLastBaddie->unk100 = NULL; suLastBaddie->unk158[0] = NULL; diff --git a/src/core2/code_AD5B0.c b/src/core2/code_AD5B0.c index 42669e0b..c227554e 100644 --- a/src/core2/code_AD5B0.c +++ b/src/core2/code_AD5B0.c @@ -142,7 +142,7 @@ void func_80334910(void) { spawnQueue_free(); func_802F53D0(); func_802FAC3C(); - func_802C8F68(); + bundle_free(); func_8033E184(); func_8033FA24(); func_80344C80(); @@ -254,7 +254,7 @@ void func_80334B20(enum map_e arg0, s32 arg1, s32 arg2) { func_80322F9C(); func_80323120(); func_803223AC(); - func_802C8F40(); + bundle_reset(); func_8034F774(); func_80350174(); gcparade_init(); diff --git a/src/core2/code_CD6E0.c b/src/core2/code_CD6E0.c index 023a4785..f7122ce9 100644 --- a/src/core2/code_CD6E0.c +++ b/src/core2/code_CD6E0.c @@ -566,7 +566,7 @@ void func_80355B00(void) { projectile_indx = func_8033E8D0(); pad40 = func_8033E864(); sp38 = marker_getActor(pad40); - sp34 = func_802C9C0C(sp38); + sp34 = bundle_getVelocity(sp38); projectile_addRoll(projectile_indx, 7.0f); sp28[0] = sp38->position[0]; sp28[1] = sp38->position[1];