From 4e84f00a25cd66f43d16af55d5772075779fd23f Mon Sep 17 00:00:00 2001 From: coco875 <59367621+coco875@users.noreply.github.com> Date: Fri, 15 Dec 2023 09:16:24 +0100 Subject: [PATCH] Rename Functions For Calculating Distance (#500) * Rename functions for calculating an objects distance to player/camera --- include/objects.h | 2 +- src/code_80071F00.c | 40 ++-- src/code_80086E70.c | 446 ++++++++++++++++++++++++++++---------------- src/code_80086E70.h | 28 +-- 4 files changed, 317 insertions(+), 199 deletions(-) diff --git a/include/objects.h b/include/objects.h index a4b4c4836..328c52841 100644 --- a/include/objects.h +++ b/include/objects.h @@ -55,7 +55,7 @@ typedef struct /* 0xBE */ Vec3su unk_0BE; /* 0xC4 */ u16 unk_0C4; /* 0xC6 */ u16 unk_0C6; - /* 0xC8 */ u16 unk_0C8; + /* 0xC8 */ u16 boundingBoxSize; /* 0xCA */ s8 unk_0CA; /* 0xCB */ s8 unk_0CB; /* 0xCC */ s8 unk_0CC; diff --git a/src/code_80071F00.c b/src/code_80071F00.c index 4528d45d8..609c8516c 100644 --- a/src/code_80071F00.c +++ b/src/code_80071F00.c @@ -4736,7 +4736,7 @@ void func_8007D6A8(s32 objectIndex, s32 arg1) { func_8007D360(objectIndex, arg1); temp_v0->sizeScaling = 0.1f; set_object_flag_unk_054_true(objectIndex, 0x00000200); - temp_v0->unk_0C8 = 3; + temp_v0->boundingBoxSize = 3; } void func_8007D714(s32 arg0) { @@ -5141,7 +5141,7 @@ s32 func_8007E50C(s32 objectIndex, Player *player, Camera *camera) { s32 sp24; sp24 = 0; - if ((func_80072354(objectIndex, 4) != 0) && (func_80088A58(objectIndex, player, 300.0f) != 0) && (func_8008A0B4(objectIndex, player, camera, 0x4000U) != 0) && (func_8008A060(objectIndex, camera, 0x1555U) != 0)) { + if ((func_80072354(objectIndex, 4) != 0) && (is_within_horizontal_distance_of_player(objectIndex, player, 300.0f) != 0) && (func_8008A0B4(objectIndex, player, camera, 0x4000U) != 0) && (func_8008A060(objectIndex, camera, 0x1555U) != 0)) { func_800722A4(objectIndex, 4); sp24 = 1; } @@ -5316,7 +5316,7 @@ void func_8007EC30(s32 objectIndex) { } init_texture_object(objectIndex, d_course_bowsers_castle_thwomp_tlut, d_course_bowsers_castle_thwomp_faces, 0x10U, (u16) 0x00000040); temp_s1->unk_070 = d_course_bowsers_castle_dl_thwomp; - temp_s1->unk_0C8 = 0x000C; + temp_s1->boundingBoxSize = 0x000C; temp_s1->sizeScaling = 1.0f; temp_s1->unk_01C[1] = 30.0f; set_object_flag_unk_054_true(objectIndex, 0x05000220); @@ -5361,7 +5361,7 @@ void func_8007EE5C(s32 objectIndex) { temp_s0 = &gObjectList[objectIndex]; temp_s0->sizeScaling = 1.0f; temp_s0->unk_070 = d_course_bowsers_castle_dl_thwomp; - temp_s0->unk_0C8 = 0x000C; + temp_s0->boundingBoxSize = 0x000C; set_object_flag_unk_054_true(objectIndex, 0x04000220); temp_s0->type = 0; temp_s0->unk_0DF = 6; @@ -5659,7 +5659,7 @@ void func_8007FA08(s32 objectIndex) { init_texture_object(objectIndex, d_course_bowsers_castle_thwomp_tlut, d_course_bowsers_castle_thwomp_faces, 0x10U, (u16) 0x00000040); temp_s0 = &gObjectList[objectIndex]; temp_s0->unk_070 = d_course_bowsers_castle_dl_thwomp; - temp_s0->unk_0C8 = 0x000C; + temp_s0->boundingBoxSize = 0x000C; temp_s0->sizeScaling = 1.0f; set_object_flag_unk_054_true(objectIndex, 0x04000220); temp_s0->type = 0; @@ -5819,7 +5819,7 @@ void func_80080078(s32 objectIndex) { init_texture_object(objectIndex, d_course_bowsers_castle_thwomp_tlut, d_course_bowsers_castle_thwomp_faces, 0x10U, (u16) 0x00000040); temp_s0 = &gObjectList[objectIndex]; temp_s0->unk_070 = d_course_bowsers_castle_dl_thwomp; - temp_s0->unk_0C8 = 0x000C; + temp_s0->boundingBoxSize = 0x000C; temp_s0->sizeScaling = 1.0f; set_object_flag_unk_054_true(objectIndex, 0x04000220); temp_s0->type = 2; @@ -5886,7 +5886,7 @@ void func_800802C0(s32 objectIndex) { init_texture_object(objectIndex, d_course_bowsers_castle_thwomp_tlut, d_course_bowsers_castle_thwomp_faces, 0x10U, (u16) 0x00000040); temp_s0->unk_070 = d_course_bowsers_castle_dl_thwomp; temp_s0->itemDisplay = 0; - temp_s0->unk_0C8 = 0x000C; + temp_s0->boundingBoxSize = 0x000C; temp_s0->sizeScaling = 1.5f; set_object_flag_unk_054_true(objectIndex, 0x05000220); temp_s0->type = 1; @@ -5943,7 +5943,7 @@ void func_80080524(s32 objectIndex) { init_texture_object(objectIndex, d_course_bowsers_castle_thwomp_tlut, d_course_bowsers_castle_thwomp_faces, 0x10U, (u16) 0x00000040); temp_s0 = &gObjectList[objectIndex]; temp_s0->unk_070 = d_course_bowsers_castle_dl_thwomp; - temp_s0->unk_0C8 = 0x000C; + temp_s0->boundingBoxSize = 0x000C; temp_s0->itemDisplay = 0; temp_s0->sizeScaling = 1.0f; set_object_flag_unk_054_true(objectIndex, 0x04000220); @@ -6050,7 +6050,7 @@ void func_800808CC(s32 objectIndex) { } void func_80080A14(s32 objectIndex, Player *player) { - if (func_80088A58(objectIndex, player, 12.0f) != 0) { + if (is_within_horizontal_distance_of_player(objectIndex, player, 12.0f) != 0) { player->boundingBoxCorners[0].unk_14 |= 3; } } @@ -6060,7 +6060,7 @@ void func_80080A4C(s32 objectIndex, s32 cameraPlayerId) { Player *player = &gPlayerOne[cameraPlayerId]; if (gScreenModeSelection != SCREEN_MODE_3P_4P_SPLITSCREEN) { - if ((func_80072320(objectIndex, 0x00000010) != 0) && (func_80088A58(objectIndex, player, 500.0f) != 0)) { + if ((func_80072320(objectIndex, 0x00000010) != 0) && (is_within_horizontal_distance_of_player(objectIndex, player, 500.0f) != 0)) { func_8001CA10(camera); func_800C98B8(gObjectList[objectIndex].pos, gObjectList[objectIndex].unk_038, 0x1900800FU); } @@ -6075,7 +6075,7 @@ void func_80080B28(s32 objectIndex, s32 playerId) { if (is_obj_index_flag_unk_054_active(objectIndex, 0x00000200) != 0) { if (!(temp_s0->statusEffects & 0x100)) { temp_f0 = func_80088F54(objectIndex, temp_s0); - if ((temp_f0 <= 9.0) && !(temp_s0->effects & 0x04000000) && (func_80088D18(objectIndex, temp_s0) != 0)) { + if ((temp_f0 <= 9.0) && !(temp_s0->effects & 0x04000000) && (has_collided_horizontally_with_player(objectIndex, temp_s0) != 0)) { if ((temp_s0->type & 0x8000) && !(temp_s0->type & 0x100)) { if (!(temp_s0->effects & 0x200)) { func_80089474(objectIndex, playerId, 1.4f, 1.1f, 0x1900A04CU); @@ -6093,7 +6093,7 @@ void func_80080B28(s32 objectIndex, s32 playerId) { func_800726CC(objectIndex, 0x000000C8); } } - } else if ((temp_f0 <= 17.5) && (func_80072320(objectIndex, 1) != 0) && (func_80088A58(objectIndex, temp_s0, (temp_s0->unk_094 * 0.5) + 7.0) != 0)) { + } else if ((temp_f0 <= 17.5) && (func_80072320(objectIndex, 1) != 0) && (is_within_horizontal_distance_of_player(objectIndex, temp_s0, (temp_s0->unk_094 * 0.5) + 7.0) != 0)) { if ((temp_s0->type & 0x8000) && !(temp_s0->type & 0x100)) { if (is_obj_index_flag_unk_054_active(objectIndex, 0x04000000) != 0) { func_80072180(); @@ -6339,7 +6339,7 @@ void func_80081848(s32 objectIndex) { func_8008B80C(objectIndex, 0.0f, 0.0f, 0.0f); func_8008B888(objectIndex, 0U, 0U, 0U); func_8008B8BC(objectIndex, 0U, 0U, 0x8000U); - gObjectList[objectIndex].unk_0C8 = 6; + gObjectList[objectIndex].boundingBoxSize = 6; gObjectList[objectIndex].unk_038[1] = 4.0f; set_object_flag_unk_054_true(objectIndex, 0x04000000); func_80072488(objectIndex); @@ -6470,7 +6470,7 @@ void func_80081D34(s32 objectIndex) { var_s1 = gPlayerOne; var_s4 = camera1; for (var_s2 = 0; var_s2 < D_8018D158; var_s2++, var_s1++, var_s4++) { - if ((is_obj_index_flag_unk_054_active(objectIndex, 0x00000200) != 0) && !(var_s1->effects & 0x80000000) && (func_80088DA4(objectIndex, var_s1) != 0)) { + if ((is_obj_index_flag_unk_054_active(objectIndex, 0x00000200) != 0) && !(var_s1->effects & 0x80000000) && (has_collided_with_player(objectIndex, var_s1) != 0)) { if ((var_s1->type & 0x8000) && !(var_s1->type & 0x100)) { var_s5 = 1; temp_s0 = &gObjectList[objectIndex]; @@ -6747,7 +6747,7 @@ void init_ktb_crab(s32 objectIndex) { object->sizeScaling = 0.15f; object->itemDisplay = 0; func_80072488(objectIndex); - object->unk_0C8 = 1; + object->boundingBoxSize = 1; set_object_flag_unk_054_true(objectIndex, 0x04000420); func_80086EAC(objectIndex, 0, 1); func_8008B80C(objectIndex, 0.0f, 0.0f, 0.0f); @@ -6897,7 +6897,7 @@ void func_8008311C(s32 objectIndex, s32 arg1) { temp_s0->unk_034 = ((arg1 % 6) * 0.1) + 0.5; func_80086E70(objectIndex); set_object_flag_unk_054_true(objectIndex, 0x04000600); - temp_s0->unk_0C8 = 2; + temp_s0->boundingBoxSize = 2; } void func_80083248(s32 objectIndex) { @@ -7095,7 +7095,7 @@ void func_80083B0C(s32 objectIndex) { gObjectList[objectIndex].unk_0B2[0] = 0; gObjectList[objectIndex].unk_0B2[1] = 0; gObjectList[objectIndex].unk_0B2[2] = 0x8000; - gObjectList[objectIndex].unk_0C8 = 2; + gObjectList[objectIndex].boundingBoxSize = 2; gObjectList[objectIndex].unk_034 = 1.5f; set_object_flag_unk_054_true(objectIndex, 0x04000210); } @@ -7269,7 +7269,7 @@ void func_80084430(s32 objectIndex, s32 arg1) { temp_s0->unk_070 = (Gfx *) d_course_sherbet_land_unk_data1; temp_s0->vertex = (Vtx *) d_course_sherbet_land_unk_data11; temp_s0->sizeScaling = 0.2f; - temp_s0->unk_0C8 = 0x000C; + temp_s0->boundingBoxSize = 0x000C; temp_s0->unk_09C = 1; func_8008B7D4(objectIndex, D_8018D01C * -383.0, 2.0f, -690.0f); func_8008B888(objectIndex, 0U, 0U, 0U); @@ -7303,7 +7303,7 @@ void func_800845C8(s32 objectIndex, s32 arg1) { temp_s0->unk_0D8 = 0; temp_s0->unk_070 = d_course_sherbet_land_unk_data1; temp_s0->vertex = d_course_sherbet_land_unk_data11; - temp_s0->unk_0C8 = 4; + temp_s0->boundingBoxSize = 4; temp_s0->unk_09C = 2; temp_s0->unk_04C = random_int(0x012CU); set_object_flag_unk_054_true(objectIndex, 0x04000220); @@ -7723,7 +7723,7 @@ void func_80085878(s32 objectIndex, s32 arg1) { temp_s0->unk_070 = d_rainbow_road_unk4; temp_s0->vertex = d_rainbow_road_unk3; temp_s0->sizeScaling = 0.03f; - temp_s0->unk_0C8 = 0x000A; + temp_s0->boundingBoxSize = 0x000A; set_object_flag_unk_054_true(objectIndex, 0x04000200); temp_s0->unk_084[8] = (arg1 * 0x12C) + 0x1F4; func_8008B7D4(objectIndex, 0.0f, -15.0f, 0.0f); diff --git a/src/code_80086E70.c b/src/code_80086E70.c index f2ce9f82e..c005292f8 100644 --- a/src/code_80086E70.c +++ b/src/code_80086E70.c @@ -65,7 +65,7 @@ s32 func_80087060(s32 objectIndex, s32 arg1) { s32 sp1C; sp1C = 0; - if (is_obj_index_flag_unk_054_inactive(objectIndex, 8) != 0) { + if (is_obj_index_flag_unk_054_inactive(objectIndex, 8) != FALSE) { set_object_flag_unk_054_true(objectIndex, 8); gObjectList[objectIndex].unk_0B0 = arg1; } @@ -81,7 +81,7 @@ s32 func_80087104(s32 objectIndex, u16 arg1) { s32 sp24; sp24 = 0; - if (is_obj_index_flag_unk_054_inactive(objectIndex, 8) != 0) { + if (is_obj_index_flag_unk_054_inactive(objectIndex, 8) != FALSE) { set_object_flag_unk_054_true(objectIndex, 8); gObjectList[objectIndex].unk_0B0 = random_int(arg1); } @@ -580,226 +580,344 @@ void func_800887C0(s32 objectIndex) { set_object_flag_unk_054_false(objectIndex, 0x00800000); } -UNUSED s32 func_80088880(s32 objectIndex, Player *player) { - s32 temp_f10; - s32 temp_f6; +/** + * @brief Returns the distance between the object and the player. + * + * @param objectIndex + * @param player + * @return UNUSED + */ +UNUSED s32 get_horizontal_distance_to_player(s32 objectIndex, Player *player) { + s32 x; + s32 y; - temp_f10 = gObjectList[objectIndex].pos[0] - player->pos[0]; - temp_f6 = gObjectList[objectIndex].pos[2] - player->pos[2]; - return (temp_f10 * temp_f10) + (temp_f6 * temp_f6); + x = gObjectList[objectIndex].pos[0] - player->pos[0]; + y = gObjectList[objectIndex].pos[2] - player->pos[2]; + return (x * x) + (y * y); } -UNUSED s32 func_800888E8(s32 objectIndex, Player *player) { - s32 temp_f10; - s32 temp_f18; - s32 temp_f6; +/** + * @brief Returns the distance between the object and the player. + * + * @param objectIndex + * @param player + * @return UNUSED + */ +UNUSED s32 get_distance_to_player(s32 objectIndex, Player *player) { + s32 x; + s32 z; + s32 y; - temp_f10 = gObjectList[objectIndex].pos[0] - player->pos[0]; - temp_f6 = gObjectList[objectIndex].pos[1] - player->pos[1]; - temp_f18 = gObjectList[objectIndex].pos[2] - player->pos[2]; - return (temp_f10 * temp_f10) + (temp_f6 * temp_f6) + (temp_f18 * temp_f18); + x = gObjectList[objectIndex].pos[0] - player->pos[0]; + y = gObjectList[objectIndex].pos[1] - player->pos[1]; + z = gObjectList[objectIndex].pos[2] - player->pos[2]; + return (x * x) + (y * y) + (z * z); } -u32 func_8008896C(s32 objectIndex, Camera *camera) { - s32 temp_f10; - s32 temp_f6; +/** + * @brief Returns the distance between the object and the camera. + * + * @param objectIndex + * @param camera + * @return UNUSED + */ +u32 get_horizontal_distance_to_camera(s32 objectIndex, Camera *camera) { + s32 x; + s32 y; - temp_f10 = gObjectList[objectIndex].pos[0] - camera->pos[0]; - temp_f6 = gObjectList[objectIndex].pos[2] - camera->pos[2]; - return (temp_f10 * temp_f10) + (temp_f6 * temp_f6); + x = gObjectList[objectIndex].pos[0] - camera->pos[0]; + y = gObjectList[objectIndex].pos[2] - camera->pos[2]; + return (x * x) + (y * y); } -UNUSED s32 func_800889D4(s32 objectIndex, Camera *camera) { - s32 temp_f10; - s32 temp_f18; - s32 temp_f6; +/** + * @brief Returns the distance between the object and the camera. + * + * @param objectIndex + * @param camera + * @return UNUSED + */ +UNUSED s32 get_distance_to_camera(s32 objectIndex, Camera *camera) { + s32 x; + s32 z; + s32 y; - temp_f10 = gObjectList[objectIndex].pos[0] - camera->pos[0]; - temp_f6 = gObjectList[objectIndex].pos[1] - camera->pos[1]; - temp_f18 = gObjectList[objectIndex].pos[2] - camera->pos[2]; - return (temp_f10 * temp_f10) + (temp_f6 * temp_f6) + (temp_f18 * temp_f18); + x = gObjectList[objectIndex].pos[0] - camera->pos[0]; + y = gObjectList[objectIndex].pos[1] - camera->pos[1]; + z = gObjectList[objectIndex].pos[2] - camera->pos[2]; + return (x * x) + (y * y) + (z * z); } -s32 func_80088A58(s32 objectIndex, Player *player, f32 arg2) { - f32 temp_f0; - f32 temp_f2; - s32 var_v1; +/** + * @brief Returns if the object is closer than the distance to the player. + * + * @param objectIndex + * @param player + * @param distance + * @return true + * @return false + */ +bool is_within_horizontal_distance_of_player(s32 objectIndex, Player *player, f32 distance) { + f32 x; + f32 y; + bool var_v1; - var_v1 = 0; - temp_f0 = gObjectList[objectIndex].pos[0] - player->pos[0]; - temp_f2 = gObjectList[objectIndex].pos[2] - player->pos[2]; - if (((temp_f0 * temp_f0) + (temp_f2 * temp_f2)) <= (arg2 * arg2)) { - var_v1 = 1; + var_v1 = FALSE; + x = gObjectList[objectIndex].pos[0] - player->pos[0]; + y = gObjectList[objectIndex].pos[2] - player->pos[2]; + if (((x * x) + (y * y)) <= (distance * distance)) { + var_v1 = TRUE; } return var_v1; } -s32 func_80088AC0(s32 objectIndex, Player *player, f32 arg2, f32 arg3) { - f32 temp_f0; - f32 temp_f12; - f32 temp_f2; - s32 var_v1; +/** + * @brief Returns if the object is between the distance_min and distance_max to the player. + * + * @param objectIndex + * @param player + * @param distance_min + * @param distance_max + * @return true + * @return false + */ +bool is_in_bounds_to_player(s32 objectIndex, Player *player, f32 distance_min, f32 distance_max) { + f32 x; + f32 distance; + f32 z; + bool var_v1; - var_v1 = 0; - temp_f0 = gObjectList[objectIndex].pos[0] - player->pos[0]; - temp_f2 = gObjectList[objectIndex].pos[2] - player->pos[2]; - temp_f12 = (temp_f0 * temp_f0) + (temp_f2 * temp_f2); - if (((arg2 * arg2) <= temp_f12) && (temp_f12 <= (arg3 * arg3))) { - var_v1 = 1; + var_v1 = FALSE; + x = gObjectList[objectIndex].pos[0] - player->pos[0]; + z = gObjectList[objectIndex].pos[2] - player->pos[2]; + distance = (x * x) + (z * z); + if (((distance_min * distance_min) <= distance) && (distance <= (distance_max * distance_max))) { + var_v1 = TRUE; } return var_v1; } -s32 func_80088B40(s32 objectIndex, Player *player, f32 arg2) { - f32 temp_f0; - f32 temp_f12; - f32 temp_f2; - s32 var_v1; +/** + * @brief Returns if the object is closer than the distance to the player. + * + * @param objectIndex + * @param player + * @param distance + * @return true + * @return false + */ +bool is_within_distance_to_player(s32 objectIndex, Player *player, f32 distance) { + f32 x; + f32 z; + f32 y; + bool var_v1; - var_v1 = 0; - temp_f0 = gObjectList[objectIndex].pos[0] - player->pos[0]; - temp_f2 = gObjectList[objectIndex].pos[1] - player->pos[1]; - temp_f12 = gObjectList[objectIndex].pos[2] - player->pos[2]; - if (((temp_f0 * temp_f0) + (temp_f2 * temp_f2) + (temp_f12 * temp_f12)) <= (arg2 * arg2)) { - var_v1 = 1; + var_v1 = FALSE; + x = gObjectList[objectIndex].pos[0] - player->pos[0]; + y = gObjectList[objectIndex].pos[1] - player->pos[1]; + z = gObjectList[objectIndex].pos[2] - player->pos[2]; + if (((x * x) + (y * y) + (z * z)) <= (distance * distance)) { + var_v1 = TRUE; } return var_v1; } -s32 func_80088BB8(s32 objectIndex, Camera *camera, f32 arg2) { - f32 temp_f0; - f32 temp_f2; - s32 var_v1; +/** + * @brief Returns if the object is between the distance_min and distance_max to the camera. + * + * @param objectIndex + * @param camera + * @param distance + * @return true + * @return false + */ +bool is_within_horizontal_distance_to_camera(s32 objectIndex, Camera *camera, f32 distance) { + f32 x; + f32 y; + bool var_v1; - var_v1 = 0; - temp_f0 = gObjectList[objectIndex].pos[0] - camera->pos[0]; - temp_f2 = gObjectList[objectIndex].pos[2] - camera->pos[2]; - if (((temp_f0 * temp_f0) + (temp_f2 * temp_f2)) <= (arg2 * arg2)) { - var_v1 = 1; + var_v1 = FALSE; + x = gObjectList[objectIndex].pos[0] - camera->pos[0]; + y = gObjectList[objectIndex].pos[2] - camera->pos[2]; + if (((x * x) + (y * y)) <= (distance * distance)) { + var_v1 = TRUE; } return var_v1; } -UNUSED s32 func_80088C20(s32 objectIndex, Camera *camera, f32 arg2, f32 arg3) { - f32 temp_f0; - f32 temp_f12; - f32 temp_f2; - s32 var_v1; +/** + * @brief Returns if the object is between the distance_min and distance_max to the camera. + * + * @param objectIndex + * @param camera + * @param distance_min + * @param distance_max + * @return UNUSED + */ +UNUSED bool is_within_bounds_to_camera(s32 objectIndex, Camera *camera, f32 distance_min, f32 distance_max) { + f32 x; + f32 distance; + f32 z; + bool var_v1; - var_v1 = 0; - temp_f0 = gObjectList[objectIndex].pos[0] - camera->pos[0]; - temp_f2 = gObjectList[objectIndex].pos[2] - camera->pos[2]; - temp_f12 = (temp_f0 * temp_f0) + (temp_f2 * temp_f2); - if (((arg2 * arg2) <= temp_f12) && (temp_f12 <= (arg3 * arg3))) { - var_v1 = 1; + var_v1 = FALSE; + x = gObjectList[objectIndex].pos[0] - camera->pos[0]; + z = gObjectList[objectIndex].pos[2] - camera->pos[2]; + distance = (x * x) + (z * z); + if (((distance_min * distance_min) <= distance) && (distance <= (distance_max * distance_max))) { + var_v1 = TRUE; } return var_v1; } -UNUSED s32 func_80088CA0(s32 objectIndex, Camera *camera, f32 arg2) { - f32 temp_f0; - f32 temp_f12; - f32 temp_f2; - s32 var_v1; +/** + * @brief Returns if the object is closer than the distance to the camera. + * + * @param objectIndex + * @param camera + * @param distance + * @return UNUSED + */ +UNUSED bool is_within_distance_to_camera(s32 objectIndex, Camera *camera, f32 distance) { + f32 x; + f32 z; + f32 y; + bool var_v1; - var_v1 = 0; - temp_f0 = gObjectList[objectIndex].pos[0] - camera->pos[0]; - temp_f2 = gObjectList[objectIndex].pos[1] - camera->pos[1]; - temp_f12 = gObjectList[objectIndex].pos[2] - camera->pos[2]; - if (((temp_f0 * temp_f0) + (temp_f2 * temp_f2) + (temp_f12 * temp_f12)) <= (arg2 * arg2)) { - var_v1 = 1; + var_v1 = FALSE; + x = gObjectList[objectIndex].pos[0] - camera->pos[0]; + y = gObjectList[objectIndex].pos[1] - camera->pos[1]; + z = gObjectList[objectIndex].pos[2] - camera->pos[2]; + if (((x * x) + (y * y) + (z * z)) <= (distance * distance)) { + var_v1 = TRUE; } return var_v1; } -s32 func_80088D18(s32 objectIndex, Player *player) { - f32 temp_f0; - f32 temp_f12; - f32 temp_f2; - s32 var_v1; +/** + * @brief Returns if the object collided with the player. + * + * @param objectIndex + * @param player + * @return true + * @return false + */ +bool has_collided_horizontally_with_player(s32 objectIndex, Player *player) { + f32 x; + f32 distance; + f32 z; + bool var_v1; - var_v1 = 0; - temp_f0 = gObjectList[objectIndex].pos[0] - player->pos[0]; - temp_f2 = gObjectList[objectIndex].pos[2] - player->pos[2]; - temp_f12 = gObjectList[objectIndex].unk_0C8 + player->boundingBoxSize; - if (((temp_f0 * temp_f0) + (temp_f2 * temp_f2)) <= (temp_f12 * temp_f12)) { - var_v1 = 1; + var_v1 = FALSE; + x = gObjectList[objectIndex].pos[0] - player->pos[0]; + z = gObjectList[objectIndex].pos[2] - player->pos[2]; + distance = gObjectList[objectIndex].boundingBoxSize + player->boundingBoxSize; + if (((x * x) + (z * z)) <= (distance * distance)) { + var_v1 = TRUE; } return var_v1; } -s32 func_80088DA4(s32 objectIndex, Player *player) { - f32 temp_f0; - f32 temp_f12; - f32 temp_f14; - f32 temp_f2; - s32 var_v1; +/** + * @brief Returns if the object collided with the player. + * + * @param objectIndex + * @param player + * @return true + * @return false + */ +bool has_collided_with_player(s32 objectIndex, Player *player) { + f32 x; + f32 z; + f32 distance; + f32 y; + bool var_v1; - var_v1 = 0; - temp_f0 = gObjectList[objectIndex].pos[0] - player->pos[0]; - temp_f2 = gObjectList[objectIndex].pos[1] - player->pos[1]; - temp_f12 = gObjectList[objectIndex].pos[2] - player->pos[2]; - temp_f14 = gObjectList[objectIndex].unk_0C8 + player->boundingBoxSize; - if (((temp_f0 * temp_f0) + (temp_f2 * temp_f2) + (temp_f12 * temp_f12)) <= (temp_f14 * temp_f14)) { - var_v1 = 1; + var_v1 = FALSE; + x = gObjectList[objectIndex].pos[0] - player->pos[0]; + y = gObjectList[objectIndex].pos[1] - player->pos[1]; + z = gObjectList[objectIndex].pos[2] - player->pos[2]; + distance = gObjectList[objectIndex].boundingBoxSize + player->boundingBoxSize; + if (((x * x) + (y * y) + (z * z)) <= (distance * distance)) { + var_v1 = TRUE; } return var_v1; } -UNUSED s32 func_80088E48(s32 objectIndex, Player *player, f32 arg2) { - f32 temp_f0; - s32 var_v1; +/** + * @brief Returns if the object collided with the player. + * + * @param objectIndex + * @param player + * @param distance + * @return UNUSED + */ +UNUSED bool has_collided_with_player_1d(s32 objectIndex, Player *player, f32 distance) { + f32 x; + bool var_v1; - var_v1 = 0; - temp_f0 = gObjectList[objectIndex].pos[1] - player->pos[1]; - if ((temp_f0 * temp_f0) <= (arg2 * arg2)) { - var_v1 = 1; + var_v1 = FALSE; + x = gObjectList[objectIndex].pos[1] - player->pos[1]; + if ((x * x) <= (distance * distance)) { + var_v1 = TRUE; } return var_v1; } -s32 func_80088E98(s32 objectIndex, Player *player, f32 arg2) { - f32 temp_f0; - f32 temp_f12; - f32 temp_f14; - f32 var_f2; - s32 var_v1; +/** + * @brief Returns if the object collided with the player and is closer than the distance in the y axis. + * + * @param objectIndex + * @param player + * @param distance_y + * @return true + * @return false + */ +bool has_collided_with_player_and_within_height(s32 objectIndex, Player *player, f32 distance_y) { + f32 x; + f32 z; + f32 distance; + f32 y; + bool var_v1; - var_v1 = 0; - temp_f0 = gObjectList[objectIndex].pos[0] - player->pos[0]; - var_f2 = gObjectList[objectIndex].pos[1] - player->pos[1]; - temp_f12 = gObjectList[objectIndex].pos[2] - player->pos[2]; - temp_f14 = gObjectList[objectIndex].unk_0C8 + player->boundingBoxSize; - if (var_f2 < 0.0f) { - var_f2 = -var_f2; + var_v1 = FALSE; + x = gObjectList[objectIndex].pos[0] - player->pos[0]; + y = gObjectList[objectIndex].pos[1] - player->pos[1]; + z = gObjectList[objectIndex].pos[2] - player->pos[2]; + distance = gObjectList[objectIndex].boundingBoxSize + player->boundingBoxSize; + // abs(y) + if (y < 0.0f) { + y = -y; } - if ((((temp_f0 * temp_f0) + (temp_f12 * temp_f12)) <= (temp_f14 * temp_f14)) && (var_f2 <= arg2)) { - var_v1 = 1; + if ((((x * x) + (z * z)) <= (distance * distance)) && (y <= distance_y)) { + var_v1 = TRUE; } return var_v1; } f32 func_80088F54(s32 objectIndex, Player *player) { - f32 var_f2; + f32 distance; - var_f2 = gObjectList[objectIndex].pos[1] - player->unk_074; - if (var_f2 < 0.0f) { - var_f2 = -var_f2; + distance = gObjectList[objectIndex].pos[1] - player->unk_074; + // abs(distance) + if (distance < 0.0f) { + distance = -distance; } - return var_f2; + return distance; } -UNUSED s32 func_80088F94(s32 objectIndex, Player *player, f32 arg2) { - f32 var_f0; - s32 var_v1; +UNUSED bool func_80088F94(s32 objectIndex, Player *player, f32 arg2) { + f32 distance; + bool var_v1; - var_f0 = gObjectList[objectIndex].pos[1] - player->unk_074; - var_v1 = 0; - if (var_f0 < 0.0f) { - var_f0 = -var_f0; + distance = gObjectList[objectIndex].pos[1] - player->unk_074; + var_v1 = FALSE; + // abs(distance) + if (distance < 0.0f) { + distance = -distance; } - if (var_f0 <= arg2) { - var_v1 = 1; + if (distance <= arg2) { + var_v1 = TRUE; } return var_v1; } @@ -944,7 +1062,7 @@ s32 func_800895E4(s32 objectIndex) { player = gPlayerOne; if (is_obj_index_flag_unk_054_active(objectIndex, 0x00000200) != 0) { for (var_s1 = 0; var_s1 < D_8018D158; var_s1++, player++) { - if ((gObjectList[objectIndex].state != 0) && (func_80088D18(objectIndex, player) != 0)) { + if ((gObjectList[objectIndex].state != 0) && (has_collided_horizontally_with_player(objectIndex, player) != 0)) { if (is_obj_index_flag_unk_054_active(objectIndex, 0x04000000) != 0) { func_80072180(); } @@ -962,7 +1080,7 @@ void func_800896D4(s32 objectIndex, f32 arg1, f32 arg2) { player = gPlayerOne; if (is_obj_index_flag_unk_054_active(objectIndex, 0x00000200) != 0) { for (var_s1 = 0; var_s1 < D_8018D158; var_s1++, player++) { - if ((gObjectList[objectIndex].state != 0) && !(player->effects & 0x80000200) && (func_80088D18(objectIndex, player) != 0)) { + if ((gObjectList[objectIndex].state != 0) && !(player->effects & 0x80000200) && (has_collided_horizontally_with_player(objectIndex, player) != 0)) { func_8008933C(player, objectIndex, arg1, arg2 * 1.1); if (is_obj_index_flag_unk_054_active(objectIndex, 0x04000000) != 0) { func_80072180(); @@ -981,7 +1099,7 @@ void func_80089820(s32 objectIndex, f32 arg1, f32 arg2, u32 arg3) { if (is_obj_index_flag_unk_054_active(objectIndex, 0x00000200) != 0) { for (var_s1 = 0; var_s1 < D_8018D158; var_s1++, player++) { if ((gObjectList[objectIndex].state != 0) && !(player->effects & 0x80000000)) { - if ((player->type & PLAYER_EXISTS) && !(player->type & PLAYER_INVISIBLE_OR_BOMB) && (func_80088D18(objectIndex, player) != 0)) { + if ((player->type & PLAYER_EXISTS) && !(player->type & PLAYER_INVISIBLE_OR_BOMB) && (has_collided_horizontally_with_player(objectIndex, player) != 0)) { if (player->effects & 0x200) { set_object_flag_unk_054_true(objectIndex, 0x02000000); } else { @@ -1005,7 +1123,7 @@ void func_80089A04(s32 objectIndex, f32 arg1, f32 arg2) { player = gPlayerOne; if (is_obj_index_flag_unk_054_active(objectIndex, 0x00000200) != 0) { for (var_s1 = 0; var_s1 < D_8018D158; var_s1++, player++) { - if ((gObjectList[objectIndex].state != 0) && !(player->effects & 0x80000200) && (func_80088DA4(objectIndex, player) != 0)) { + if ((gObjectList[objectIndex].state != 0) && !(player->effects & 0x80000200) && (has_collided_with_player(objectIndex, player) != 0)) { func_8008933C(player, objectIndex, arg1, arg2 * 1.1); if (is_obj_index_flag_unk_054_active(objectIndex, 0x04000000) != 0) { func_80072180(); @@ -1026,7 +1144,7 @@ s32 func_80089B50(s32 objectIndex) { player = gPlayerOne; if (is_obj_index_flag_unk_054_active(objectIndex, 0x00000200) != 0) { for (var_s1 = 0; var_s1 < D_8018D158; var_s1++, player++, test++) { - if ((gObjectList[objectIndex].state != 0) && !(player->effects & 0x81000000) && (player->type & PLAYER_EXISTS) && !(player->type & PLAYER_INVISIBLE_OR_BOMB) && (func_80088D18(objectIndex, player) != 0)) { + if ((gObjectList[objectIndex].state != 0) && !(player->effects & 0x81000000) && (player->type & PLAYER_EXISTS) && !(player->type & PLAYER_INVISIBLE_OR_BOMB) && (has_collided_horizontally_with_player(objectIndex, player) != 0)) { if (!(player->effects & 0x200)) { player->statusEffects |= REVERSE_EFFECT; if (is_obj_index_flag_unk_054_active(objectIndex, 0x04000000) != 0) { @@ -1052,7 +1170,7 @@ s32 func_80089CBC(s32 objectIndex, f32 arg1) { if (is_obj_index_flag_unk_054_active(objectIndex, 0x00000200) != 0) { for (var_s1 = 0; var_s1 < D_8018D158; var_s1++, player++) { if ((gObjectList[objectIndex].state != 0) && !(player->effects & 0x81000000)) { - if ((player->type & PLAYER_EXISTS) && !(player->type & PLAYER_INVISIBLE_OR_BOMB) && (func_80088E98(objectIndex, player, arg1) != 0)) { + if ((player->type & PLAYER_EXISTS) && !(player->type & PLAYER_INVISIBLE_OR_BOMB) && (has_collided_with_player_and_within_height(objectIndex, player, arg1) != 0)) { if (!(player->effects & 0x200)) { player->statusEffects |= REVERSE_EFFECT; if (is_obj_index_flag_unk_054_active(objectIndex, 0x04000000) != 0) { @@ -1076,7 +1194,7 @@ s32 func_80089E18(s32 objectIndex) { player = gPlayerOne; if (is_obj_index_flag_unk_054_active(objectIndex, 0x00000200) != 0) { for (var_s1 = 0; var_s1 < D_8018D158; var_s1++, player++) { - if ((gObjectList[objectIndex].state != 0) && !(player->effects & 0x800000C0) && (func_80088D18(objectIndex, player) != 0)) { + if ((gObjectList[objectIndex].state != 0) && !(player->effects & 0x800000C0) && (has_collided_horizontally_with_player(objectIndex, player) != 0)) { if (player->effects & 0x200) { var_s6 = 1; } else { @@ -1098,7 +1216,7 @@ s32 func_80089F24(s32 objectIndex) { if (is_obj_index_flag_unk_054_active(objectIndex, 0x00000200) != 0) { for (var_s1 = 0; var_s1 < D_8018D158; var_s1++, player++) { if ((gObjectList[objectIndex].state != 0) && !(player->effects & 0x800002C0)) { - if ((player->type & PLAYER_EXISTS) && !(player->type & PLAYER_INVISIBLE_OR_BOMB) && (func_80088D18(objectIndex, player) != 0)) { + if ((player->type & PLAYER_EXISTS) && !(player->type & PLAYER_INVISIBLE_OR_BOMB) && (has_collided_horizontally_with_player(objectIndex, player) != 0)) { var_s7 = 1; if (is_obj_index_flag_unk_054_active(objectIndex, 0x04000000) != 0) { func_80072180(); @@ -1160,7 +1278,7 @@ void func_8008A1D0(s32 objectIndex, s32 cameraId, s32 arg2, s32 arg3) { camera = &camera1[cameraId]; set_object_flag_unk_054_false(objectIndex, 0x00140000); - temp_v0 = func_8008896C(objectIndex, camera); + temp_v0 = get_horizontal_distance_to_camera(objectIndex, camera); if (temp_v0 < 0x2711U) { var_a2 = 0x5555; } else if (temp_v0 < 0x9C41U) { @@ -1203,7 +1321,7 @@ s32 func_8008A364(s32 objectIndex, s32 cameraId, u16 arg2, s32 arg3) { camera = &camera1[cameraId]; set_object_flag_unk_054_false(objectIndex, 0x00060000); - var_v1 = func_8008896C(objectIndex, camera); + var_v1 = get_horizontal_distance_to_camera(objectIndex, camera); if (var_v1 < (arg3 * arg3)) { set_object_flag_unk_054_true(objectIndex, 0x00020000); if (var_v1 < 0x2711U) { @@ -1221,7 +1339,7 @@ s32 func_8008A364(s32 objectIndex, s32 cameraId, u16 arg2, s32 arg3) { } void func_8008A454(s32 objectIndex, s32 cameraId, s32 arg2) { - if (func_8008896C(objectIndex, &camera1[cameraId]) < (u32) (arg2 * arg2)) { + if (get_horizontal_distance_to_camera(objectIndex, &camera1[cameraId]) < (u32) (arg2 * arg2)) { set_object_flag_unk_054_true(objectIndex, 0x00000020); } else { set_object_flag_unk_054_false(objectIndex, 0x00000020); @@ -1267,7 +1385,7 @@ void func_8008A6DC(s32 objectIndex, f32 arg1) { set_object_flag_unk_054_false(objectIndex, 0x00060000); for (camera = camera1, loopIndex = 0; loopIndex < gPlayerCountSelection1; loopIndex++, camera++) { - if ((gObjectList[objectIndex].state != 0) && (func_80088BB8(objectIndex, camera, arg1) != 0)) { + if ((gObjectList[objectIndex].state != 0) && (is_within_horizontal_distance_to_camera(objectIndex, camera, arg1) != 0)) { set_object_flag_unk_054_true(objectIndex, 0x00020000); if (arg1 <= 500.0) { var_a2 = 0x4000; diff --git a/src/code_80086E70.h b/src/code_80086E70.h index 9f6863596..86d7ab636 100644 --- a/src/code_80086E70.h +++ b/src/code_80086E70.h @@ -59,20 +59,20 @@ s32 func_80088538(s32); s32 func_8008861C(s32); void func_800886F4(s32); void func_800887C0(s32); -s32 func_80088880(s32, Player*); -s32 func_800888E8(s32, Player*); -u32 func_8008896C(s32, Camera*); -s32 func_800889D4(s32, Camera*); -s32 func_80088A58(s32, Player*, f32); -s32 func_80088AC0(s32, Player*, f32, f32); -s32 func_80088B40(s32, Player*, f32); -s32 func_80088BB8(s32, Camera*, f32); -s32 func_80088C20(s32, Camera*, f32, f32); -s32 func_80088CA0(s32, Camera*, f32); -s32 func_80088D18(s32, Player*); -s32 func_80088DA4(s32, Player*); -s32 func_80088E48(s32, Player*, f32); -s32 func_80088E98(s32, Player*, f32); +s32 get_horizontal_distance_to_player(s32, Player*); +s32 get_distance_to_player(s32, Player*); +u32 get_horizontal_distance_to_camera(s32, Camera*); +s32 get_distance_to_camera(s32, Camera*); +bool is_within_horizontal_distance_of_player(s32, Player*, f32); +s32 are_between_distance_2d(s32, Player*, f32, f32); +bool is_within_distance_to_player(s32, Player*, f32); +bool is_within_horizontal_distance_to_camera(s32, Camera*, f32); +s32 is_within_bounds_to_camera(s32, Camera*, f32, f32); +bool is_within_distance_to_camera(s32, Camera*, f32); +bool has_collided_horizontally_with_player(s32, Player*); +bool has_collided_with_player(s32, Player*); +bool has_collided_with_player_1d(s32, Player*, f32); +bool has_collided_with_player_and_within_height(s32, Player*, f32); f32 func_80088F54(s32, Player*); s32 func_80088F94(s32, Player*, f32); void func_80088FF0(Player*);