From 40f677db5234bddd77cebc83dc995dcfafd700ef Mon Sep 17 00:00:00 2001 From: coco875 <59367621+coco875@users.noreply.github.com> Date: Fri, 23 Aug 2024 07:56:57 +0200 Subject: [PATCH] Document Vehicles (#641) * start doc collision * fix merge * finish rename fonction related to vehicle * document around waypoint of vehicle * make some modification * make some change and rename one * copy_ to oldPos * doc smoke ferry and train * some rename * fix some renaming * precise index * rename a funciton * simplify waypoint_vehicles * change some name * change some name * rename move_to_point_direction * fix some conflict * Update code_80005FD0.c * Update code_80005FD0.h --------- Co-authored-by: MegaMech --- courses/dks_jungle_parkway/course_data.c | 2 +- courses/dks_jungle_parkway/course_data.h | 1 + courses/kalimari_desert/course_data.c | 2 +- courses/kalimari_desert/course_data.h | 2 +- include/common_structs.h | 4 +- include/vehicles.h | 6 +- include/waypoints.h | 2 +- src/code_80005FD0.c | 626 ++++++++++++----------- src/code_80005FD0.h | 60 +-- src/code_80057C60.c | 11 +- src/code_80086E70.c | 4 +- src/effects.c | 2 +- src/player_controller.c | 105 ++-- src/racing/actors.c | 6 +- src/racing/collision.c | 190 +++---- src/racing/collision.h | 4 +- src/racing/race_logic.c | 2 +- src/racing/render_courses.c | 6 +- src/render_objects.c | 4 +- src/render_objects.h | 2 +- src/spawn_players.c | 6 +- src/update_objects.c | 36 +- src/update_objects.h | 8 +- 23 files changed, 550 insertions(+), 541 deletions(-) diff --git a/courses/dks_jungle_parkway/course_data.c b/courses/dks_jungle_parkway/course_data.c index 9e2ed33c3..c0b7dbf54 100644 --- a/courses/dks_jungle_parkway/course_data.c +++ b/courses/dks_jungle_parkway/course_data.c @@ -4181,7 +4181,7 @@ TrackWaypoint d_course_dks_jungle_parkway_unknown_waypoints[] = { {-32768, 0, 0, 0}, }; -TrackWaypoint d_course_dks_jungle_parkway_unknown_waypoints2[] = { +TrackWaypoint d_course_dks_jungle_parkway_ferry_waypoints[] = { {1237, 0, -1373, 0}, {1206, 0, -1365, 0}, {877, 0, -1272, 0}, diff --git a/courses/dks_jungle_parkway/course_data.h b/courses/dks_jungle_parkway/course_data.h index 4513fcfb2..08ef186c3 100644 --- a/courses/dks_jungle_parkway/course_data.h +++ b/courses/dks_jungle_parkway/course_data.h @@ -113,6 +113,7 @@ extern Gfx d_course_dks_jungle_parkway_dl_7008[]; extern Gfx d_course_dks_jungle_parkway_dl_7080[]; extern Gfx d_course_dks_jungle_parkway_dl_7108[]; extern TrackWaypoint d_course_dks_jungle_parkway_unknown_waypoints[]; +extern TrackWaypoint d_course_dks_jungle_parkway_ferry_waypoints[]; extern TrackWaypoint d_course_dks_jungle_parkway_track_waypoints[]; extern Vtx d_course_dks_jungle_parkway_paddle_boat_model1[]; extern Vtx d_course_dks_jungle_parkway_paddle_boat_model2[]; diff --git a/courses/kalimari_desert/course_data.c b/courses/kalimari_desert/course_data.c index cac04ce9c..9e8b82b8c 100644 --- a/courses/kalimari_desert/course_data.c +++ b/courses/kalimari_desert/course_data.c @@ -3801,7 +3801,7 @@ TrackWaypoint d_course_kalimari_desert_unknown_waypoints[] = { {-32768, 0, 0, 0}, }; -TrackWaypoint d_course_kalimari_desert_track_unknown_waypoints[] = { +TrackWaypoint d_course_kalimari_desert_train_waypoints[] = { {-741, 0, 2114, 0}, {-741, 0, 2130, 0}, {-741, 0, 2364, 0}, diff --git a/courses/kalimari_desert/course_data.h b/courses/kalimari_desert/course_data.h index adf7e6936..9e98b9866 100644 --- a/courses/kalimari_desert/course_data.h +++ b/courses/kalimari_desert/course_data.h @@ -88,7 +88,7 @@ extern Gfx d_course_kalimari_desert_dl_66F0[]; extern Gfx d_course_kalimari_desert_dl_6838[]; extern Gfx d_course_kalimari_desert_dl_6940[]; extern TrackWaypoint d_course_kalimari_desert_unknown_waypoints[]; -extern TrackWaypoint d_course_kalimari_desert_track_unknown_waypoints[]; +extern TrackWaypoint d_course_kalimari_desert_train_waypoints[]; extern TrackWaypoint d_course_kalimari_desert_track_waypoints[]; extern u8 d_course_kalimari_desert_tree_tlut[]; extern Vtx d_course_kalimari_desert_cactus_model1[]; diff --git a/include/common_structs.h b/include/common_structs.h index 1c0bdb83e..84091aef0 100644 --- a/include/common_structs.h +++ b/include/common_structs.h @@ -263,9 +263,7 @@ typedef struct { /* 0x0010 */ s16 currentItemCopy; // Has no effect on what item the players has, It is just a synced copy /* 0x0012 */ s16 unk_012; /* 0x0014 */ Vec3f pos; - /* 0x0020 */ f32 copy_rotation_x; - /* 0x0024 */ f32 copy_rotation_y; - /* 0x0028 */ f32 copy_rotation_z; + /* 0x0020 */ Vec3f oldPos; /* 0x002C */ Vec3s rotation; /* 0x0032 */ char unk_032[0x2]; /* 0x0034 */ Vec3f velocity; diff --git a/include/vehicles.h b/include/vehicles.h index 87f0f2a39..f740213dd 100644 --- a/include/vehicles.h +++ b/include/vehicles.h @@ -49,7 +49,7 @@ typedef struct { /* 0x000 */ TrainCarStuff locomotive; /* 0x024 */ TrainCarStuff tender; /* 0x048 */ TrainCarStuff passengerCars[NUM_PASSENGER_CAR_ENTRIES]; - /* 0x0FC */ f32 someMultiplier; + /* 0x0FC */ f32 speed; /* 0x100 */ s32 someFlags; /* 0x104 */ s32 numCars; // Non-locomotive car count? /* 0x108 */ s32 unused; // Not read or written. Could be padding? @@ -62,7 +62,7 @@ typedef struct { /* 0x10 */ Vec3f velocity; // /* 0x1C */ u16 waypointIndex; // /* 0x1E */ s16 actorIndex; // - /* 0x20 */ f32 someMultiplier; // + /* 0x20 */ f32 speed; // /* 0x24 */ s16 rotY; // Only Y rotation is tracked in this struct /* 0x26 */ // s16 compilerPadding2; /** @@ -79,7 +79,7 @@ typedef struct { /* 0x10 */ Vec3f velocity; /* 0x1C */ u16 waypointIndex; /* 0x1E */ s16 actorIndex; - /* 0x20 */ f32 someMultiplier; // + /* 0x20 */ f32 speed; // /* 0x24 */ f32 someMultiplierTheSequel; // /* 0x28 */ Vec3s rotation; /* 0x2E */ s16 someType; // diff --git a/include/waypoints.h b/include/waypoints.h index 9fc38dbd6..d35e5413a 100644 --- a/include/waypoints.h +++ b/include/waypoints.h @@ -7,7 +7,7 @@ typedef struct { /* 0x00 */ s16 posX; /* 0x02 */ s16 posY; /* 0x04 */ s16 posZ; - /* 0x06 */ u16 trackSegment; + /* 0x06 */ u16 trackSectionId; } TrackWaypoint; // size = 0x08 /** diff --git a/src/code_80005FD0.c b/src/code_80005FD0.c index 43b86bec1..cb4c3f30f 100644 --- a/src/code_80005FD0.c +++ b/src/code_80005FD0.c @@ -50,7 +50,7 @@ s32 D_80162F90[4]; Vec3f D_80162FA0; Vec3f D_80162FB0; Vec3f D_80162FC0; -s16 D_80162FCC; +s16 gTrainSmokeTimer; s16 sSomeNearestWaypoint; s16 D_80162FD0; f32 gCourseCompletionPercentByRank[NUM_PLAYERS]; @@ -70,7 +70,7 @@ s32 D_801630B8[10]; u16 D_801630E0; s16 D_801630E2; s16 D_801630E8[10]; -s16 D_801630FC; +s16 gFerrySmokeTimer; s32 D_80163100[10]; s32 D_80163128[10]; s32 D_80163150[10]; @@ -134,8 +134,8 @@ s16 D_801634EC; s32 D_801634F0; s32 D_801634F4; Test D_801634F8[10]; -PathNoY *D_80163598; -s32 D_8016359C; +Path2D *gVehicle2DWaypoint; +s32 gVehicle2DWaypointLength; TrainStuff gTrainList[NUM_TRAINS]; u16 isCrossingTriggeredByIndex[NUM_CROSSINGS]; u16 sCrossingActiveTimer[NUM_CROSSINGS]; @@ -547,7 +547,7 @@ char *D_800ECF3C = "4位の人終了\n"; char *D_800ECF4C = "OGA 表彰 move 終了\n"; char *D_800ECF60 = "OGAWA DEBUG DRAW\n"; -s16 func_80005FD0(Vec3f arg0, Vec3f arg1) { +s16 get_angle_between_waypoints(Vec3f arg0, Vec3f arg1) { s16 temp_ret; s16 phi_v1; @@ -577,7 +577,7 @@ s32 func_80006018(f32 arg0, f32 arg1, f32 arg2, f32 arg3, f32 arg4, f32 arg5, f3 return 0; } -void func_80006114(Vec3f arg0, Vec3f arg1, s16 arg2) { +void adjust_position_by_angle(Vec3f newPos, Vec3f oldPos, s16 orientationY) { f32 x_dist; f32 z_dist; f32 temp1; @@ -586,16 +586,16 @@ void func_80006114(Vec3f arg0, Vec3f arg1, s16 arg2) { f32 cosine; if (gIsMirrorMode != 0) { - arg2 = -arg2; + orientationY = -orientationY; } - x_dist = arg0[0] - arg1[0]; - z_dist = arg0[2] - arg1[2]; - sine = sins(arg2); - cosine = coss(arg2); + x_dist = newPos[0] - oldPos[0]; + z_dist = newPos[2] - oldPos[2]; + sine = sins(orientationY); + cosine = coss(orientationY); temp1 = ((x_dist * cosine) + (z_dist * sine)); temp2 = ((z_dist * cosine) - (x_dist * sine)); - arg0[0] = arg1[0] + temp1; - arg0[2] = arg1[2] + temp2; + newPos[0] = oldPos[0] + temp1; + newPos[2] = oldPos[2] + temp2; } s32 set_vehicle_render_distance_flags(Vec3f vehiclePos, f32 renderDistance, s32 flags) { @@ -1309,7 +1309,7 @@ s32 func_80008E58(s32 payerId, s32 pathIndex) { f32 posY; f32 posZ; Player *player; - s32 trackSegment; + s32 trackSectionId; UNUSED s32 stackPadding; player = &gPlayers[payerId]; @@ -1317,9 +1317,9 @@ s32 func_80008E58(s32 payerId, s32 pathIndex) { posY = player->pos[1]; posZ = player->pos[2]; stackPadding = pathIndex; - trackSegment = get_section_id(player->collision.meshIndexZX); - D_80163318[payerId] = trackSegment; - sSomeNearestWaypoint = func_8000C0BC(posX, posY, posZ, trackSegment, &pathIndex); + trackSectionId = get_track_section_id(player->collision.meshIndexZX); + D_80163318[payerId] = trackSectionId; + sSomeNearestWaypoint = find_closest_waypoint_track_segment(posX, posY, posZ, trackSectionId, &pathIndex); gNearestWaypointByPlayerId[payerId] = sSomeNearestWaypoint; if(pathIndex) {}; gPathIndexByPlayerId[payerId] = pathIndex; @@ -1544,10 +1544,10 @@ void update_vehicles(void) { update_vehicle_paddle_boats(); break; case COURSE_TOADS_TURNPIKE: - func_8001487C(); - func_800149D0(); - func_80014B24(); - func_80014C78(); + update_vehicle_box_trucks(); + update_vehicle_school_bus(); + update_vehicle_tanker_trucks(); + update_vehicle_cars(); break; } } @@ -1674,16 +1674,16 @@ void func_80009B60(s32 playerId) { D_80163448 = gPathIndexByPlayerId[playerId]; func_80008DC0(D_80163448); switch (gCurrentCourseId) { /* irregular */ - case 11: + case COURSE_KALAMARI_DESERT: func_80012DC0(playerId, player); if (playerId == 0) { func_80013054(); } break; - case 18: + case COURSE_DK_JUNGLE: func_80013854(player); break; - case 10: + case COURSE_TOADS_TURNPIKE: func_800148C4(playerId, player); func_80014A18(playerId, player); func_80014B6C(playerId, player); @@ -1798,7 +1798,7 @@ void func_80009B60(s32 playerId) { player->effects |= 0x10; } if (D_801630E8[playerId] != 0) { - D_80163300[playerId] = -get_angle_between_two_vectors(&player->copy_rotation_x, player->pos); + D_80163300[playerId] = -get_angle_between_two_vectors(&player->oldPos[0], player->pos); var_a0_2 = (D_801631DC[(sSomeNearestWaypoint + 2) % D_80164430] * 0x168) / 65535; var_a1 = (D_80163300[playerId] * 0x168) / 65535; if (var_a0_2 < -0xB4) { @@ -2270,7 +2270,7 @@ s16 func_8000BD94(f32 posX, f32 posY, f32 posZ, s32 pathIndex) { return nearestWaypointIndex; } -s16 func_8000C0BC(f32 posX, f32 posY, f32 posZ, u16 trackSegment, s32 *pathIndex) { +s16 find_closest_waypoint_track_segment(f32 posX, f32 posY, f32 posZ, u16 trackSectionId, s32 *pathIndex) { TrackWaypoint *pathWaypoints; TrackWaypoint *considerWaypoint; f32 x_dist; @@ -2296,7 +2296,7 @@ s16 func_8000C0BC(f32 posX, f32 posY, f32 posZ, u16 trackSegment, s32 *pathIndex pathWaypointCount = gWaypointCountByPathIndex[temp_t0]; considerWaypoint = &pathWaypoints[0]; for (considerWaypointIndex = 0; considerWaypointIndex < pathWaypointCount; considerWaypointIndex++, considerWaypoint++) { - if ((considerWaypoint->trackSegment == trackSegment) || (gCurrentCourseId == COURSE_AWARD_CEREMONY)) { + if ((considerWaypoint->trackSectionId == trackSectionId) || (gCurrentCourseId == COURSE_AWARD_CEREMONY)) { var_t1 = 1; x_dist = (f32) considerWaypoint->posX - posX; y_dist = (f32) considerWaypoint->posY - posY; @@ -2316,7 +2316,7 @@ s16 func_8000C0BC(f32 posX, f32 posY, f32 posZ, u16 trackSegment, s32 *pathIndex considerWaypoint = &pathWaypoints[0]; pathWaypointCount = gWaypointCountByPathIndex[considerPathIndex]; for (considerWaypointIndex = 0; considerWaypointIndex < pathWaypointCount; considerWaypointIndex++, considerWaypoint++) { - if (considerWaypoint->trackSegment == trackSegment) { + if (considerWaypoint->trackSectionId == trackSectionId) { x_dist = (f32) considerWaypoint->posX - posX; y_dist = (f32) considerWaypoint->posY - posY; z_dist = (f32) considerWaypoint->posZ - posZ; @@ -2362,11 +2362,11 @@ s16 func_8000C0BC(f32 posX, f32 posY, f32 posZ, u16 trackSegment, s32 *pathIndex /** * Tries to find the waypoint nearest to (posX, posY, posZ) - * Only consider waypoints in the same segment as trackSegment + * Only consider waypoints in the same segment as trackSectionId * Only considers waypoints within 500 units of (posX, posY, posZ) * Looks 3 waypoints behind and 6 waypoints ahead of waypointIndex **/ -s16 func_8000C884(f32 posX, f32 posY, f32 posZ, s16 waypointIndex, s32 pathIndex, u16 trackSegment) { +s16 func_8000C884(f32 posX, f32 posY, f32 posZ, s16 waypointIndex, s32 pathIndex, u16 trackSectionId) { s16 nearestWaypointIndex; s16 searchIndex; s16 considerIndex; @@ -2388,7 +2388,7 @@ s16 func_8000C884(f32 posX, f32 posY, f32 posZ, s16 waypointIndex, s32 pathIndex // This is done to ensure we access D_80164550 at a valid index considerIndex = (searchIndex + pathWaypointCount) % pathWaypointCount; considerWaypoint = &pathWaypoints[considerIndex]; - if (considerWaypoint->trackSegment == trackSegment) { + if (considerWaypoint->trackSectionId == trackSectionId) { x_dist = considerWaypoint->posX - posX; y_dist = considerWaypoint->posY - posY; z_dist = considerWaypoint->posZ - posZ; @@ -2407,7 +2407,7 @@ s16 func_8000C884(f32 posX, f32 posY, f32 posZ, s16 waypointIndex, s32 pathIndex * Only considers waypoints within 400 units of (posX, posY, posZ) * Looks 3 waypoints behind and 6 waypoints ahead of waypointIndex **/ -s16 func_8000C9DC(f32 posX, f32 posY, f32 posZ, s16 waypointIndex, s32 pathIndex) { +s16 find_closest_waypoint_with_previous_waypoint(f32 posX, f32 posY, f32 posZ, s16 waypointIndex, s32 pathIndex) { s16 nearestWaypointIndex; s16 searchIndex; s16 considerIndex; @@ -2480,30 +2480,30 @@ void func_8000CBF8(UNUSED f32 posX, UNUSED f32 posY, f32 posZ, s16 *waypointInde } s16 func_8000CC88(f32 posX, f32 posY, f32 posZ, Player *player, s32 playerId, s32 *pathIndex) { - u16 trackSegment; + u16 trackSectionId; s16 ret; - trackSegment = get_section_id(player->collision.meshIndexZX); - if ((trackSegment <= 0) || (trackSegment >= 0x33)) { - trackSegment = D_80163318[playerId]; + trackSectionId = get_track_section_id(player->collision.meshIndexZX); + if ((trackSectionId <= 0) || (trackSectionId >= 0x33)) { + trackSectionId = D_80163318[playerId]; } - D_80163318[playerId] = trackSegment; - ret = func_8000C0BC(posX, posY, posZ, trackSegment, pathIndex); + D_80163318[playerId] = trackSectionId; + ret = find_closest_waypoint_track_segment(posX, posY, posZ, trackSectionId, pathIndex); gPathIndexByPlayerId[playerId] = *pathIndex; return ret; } s16 func_8000CD24(f32 posX, f32 posY, f32 posZ, s16 waypointIndex, Player *player, s32 playerId, s32 pathIndex) { - s16 sp5E; + s16 newWaypoint; UNUSED s16 stackPadding0; UNUSED s32 stackPadding1; UNUSED s32 stackPadding2; TrackWaypoint *temp_v1; if ((player->type & 0x4000) && !(player->type & 0x1000)) { - sp5E = func_8000C884(posX, posY, posZ, waypointIndex, pathIndex, (u16) get_section_id(player->collision.meshIndexZX)); - if (sp5E == -1) { - sp5E = func_8000CC88(posX, posY, posZ, player, playerId, &pathIndex); + newWaypoint = func_8000C884(posX, posY, posZ, waypointIndex, pathIndex, (u16) get_track_section_id(player->collision.meshIndexZX)); + if (newWaypoint == -1) { + newWaypoint = func_8000CC88(posX, posY, posZ, player, playerId, &pathIndex); } } else { if (D_801631E0[playerId] == 1) { @@ -2517,23 +2517,23 @@ s16 func_8000CD24(f32 posX, f32 posY, f32 posZ, s16 waypointIndex, Player *playe } if (playerId == ((s32) D_80163488 % 8)) { check_bounding_collision(&player->collision, 10.0f, posX, posY, posZ); - D_80163318[playerId] = get_section_id(player->collision.meshIndexZX); - sp5E = func_8000C884(posX, posY, posZ, waypointIndex, pathIndex, D_80163318[playerId]); - if (sp5E == -1) { - sp5E = func_8000C9DC(posX, posY, posZ, waypointIndex, pathIndex); + D_80163318[playerId] = get_track_section_id(player->collision.meshIndexZX); + newWaypoint = func_8000C884(posX, posY, posZ, waypointIndex, pathIndex, D_80163318[playerId]); + if (newWaypoint == -1) { + newWaypoint = find_closest_waypoint_with_previous_waypoint(posX, posY, posZ, waypointIndex, pathIndex); } - if (sp5E == -1) { - sp5E = func_8000C0BC(posX, posY, posZ, D_80163318[playerId], &pathIndex); - temp_v1 = &D_80164550[pathIndex][sp5E]; + if (newWaypoint == -1) { + newWaypoint = find_closest_waypoint_track_segment(posX, posY, posZ, D_80163318[playerId], &pathIndex); + temp_v1 = &D_80164550[pathIndex][newWaypoint]; player->pos[0] = (f32) temp_v1->posX; player->pos[1] = (f32) temp_v1->posY; player->pos[2] = (f32) temp_v1->posZ; } } else { - sp5E = func_8000C9DC(posX, posY, posZ, waypointIndex, pathIndex); - if (sp5E == -1) { - sp5E = func_8000BD94(posX, posY, posZ, pathIndex); - temp_v1 = &D_80164550[pathIndex][sp5E]; + newWaypoint = find_closest_waypoint_with_previous_waypoint(posX, posY, posZ, waypointIndex, pathIndex); + if (newWaypoint == -1) { + newWaypoint = func_8000BD94(posX, posY, posZ, pathIndex); + temp_v1 = &D_80164550[pathIndex][newWaypoint]; posX = (f32) temp_v1->posX; posY = (f32) temp_v1->posY; posZ = (f32) temp_v1->posZ; @@ -2541,22 +2541,22 @@ s16 func_8000CD24(f32 posX, f32 posY, f32 posZ, s16 waypointIndex, Player *playe player->pos[1] = posY; player->pos[2] = posZ; check_bounding_collision(&player->collision, 10.0f, posX, posY, posZ); - D_80163318[playerId] = get_section_id(player->collision.meshIndexZX); + D_80163318[playerId] = get_track_section_id(player->collision.meshIndexZX); } } } else { - sp5E = func_8000C9DC(posX, posY, posZ, waypointIndex, pathIndex); - if (sp5E == -1) { - sp5E = func_8000CC88(posX, posY, posZ, player, playerId, &pathIndex); + newWaypoint = find_closest_waypoint_with_previous_waypoint(posX, posY, posZ, waypointIndex, pathIndex); + if (newWaypoint == -1) { + newWaypoint = func_8000CC88(posX, posY, posZ, player, playerId, &pathIndex); } } - func_8000CBA4(posX, posY, posZ, &sp5E, pathIndex); - } - func_8000CBF8(posX, posY, posZ, &sp5E, pathIndex); - return sp5E; + func_8000CBA4(posX, posY, posZ, &newWaypoint, pathIndex); + } + func_8000CBF8(posX, posY, posZ, &newWaypoint, pathIndex); + return newWaypoint; } -s16 func_8000D100(f32 xPos, UNUSED f32 yPos, f32 zPos, s16 arg3) { +s16 find_closest_vehicles_waypoint(f32 xPos, UNUSED f32 yPos, f32 zPos, s16 waypointIndex) { f32 xdiff; f32 zdiff; f32 minimumDistance; @@ -2564,17 +2564,17 @@ s16 func_8000D100(f32 xPos, UNUSED f32 yPos, f32 zPos, s16 arg3) { s16 realIndex; s16 minimumIndex; s16 considerIndex; - PathNoY *considerWaypoint; + Path2D *considerWaypoint; minimumDistance = 250000.0f; minimumIndex = -1; - for (realIndex = arg3 - 2; realIndex < arg3 + 7; realIndex++) { + for (realIndex = waypointIndex - 2; realIndex < waypointIndex + 7; realIndex++) { considerIndex = realIndex; if (realIndex < 0) { - considerIndex = realIndex + D_8016359C; + considerIndex = realIndex + gVehicle2DWaypointLength; } - considerIndex %= D_8016359C; - considerWaypoint = &D_80163598[considerIndex]; + considerIndex %= gVehicle2DWaypointLength; + considerWaypoint = &gVehicle2DWaypoint[considerIndex]; xdiff = considerWaypoint->x - xPos; zdiff = considerWaypoint->z - zPos; considerSquaredDistance = (xdiff * xdiff) + (zdiff * zdiff); @@ -2584,7 +2584,7 @@ s16 func_8000D100(f32 xPos, UNUSED f32 yPos, f32 zPos, s16 arg3) { } } if (minimumIndex == -1) { - minimumIndex = arg3; + minimumIndex = waypointIndex; } return minimumIndex; } @@ -2594,28 +2594,28 @@ s16 func_8000D24C(f32 posX, f32 posY, f32 posZ, s32 *pathIndex) { Collision sp24; check_bounding_collision(&sp24, 10.0f, posX, posY, posZ); - return func_8000C0BC(posX, posY, posZ, get_section_id(sp24.meshIndexZX), pathIndex); + return find_closest_waypoint_track_segment(posX, posY, posZ, get_track_section_id(sp24.meshIndexZX), pathIndex); } s16 func_8000D2B4(f32 posX, f32 posY, f32 posZ, s16 waypointIndex, s32 pathIndex) { - s16 temp_v0; + s16 waypoint; - temp_v0 = func_8000C9DC(posX, posY, posZ, waypointIndex, pathIndex); - if (temp_v0 == -1) { - temp_v0 = func_8000D24C(posX, posY, posZ, &pathIndex); + waypoint = find_closest_waypoint_with_previous_waypoint(posX, posY, posZ, waypointIndex, pathIndex); + if (waypoint == -1) { + waypoint = func_8000D24C(posX, posY, posZ, &pathIndex); } - func_8000CBF8(posX, posY, posZ, &temp_v0, pathIndex); - return temp_v0; + func_8000CBF8(posX, posY, posZ, &waypoint, pathIndex); + return waypoint; } s16 func_8000D33C(f32 posX, f32 posY, f32 posZ, s16 waypointIndex, s32 pathIndex) { - s16 var_v1; + s16 waypoint; - var_v1 = func_8000C9DC(posX, posY, posZ, waypointIndex, pathIndex); - if (var_v1 == -1) { - var_v1 = func_8000D24C(posX, posY, posZ, &pathIndex); + waypoint = find_closest_waypoint_with_previous_waypoint(posX, posY, posZ, waypointIndex, pathIndex); + if (waypoint == -1) { + waypoint = func_8000D24C(posX, posY, posZ, &pathIndex); } - return var_v1; + return waypoint; } f32 func_8000D3B8(s32 playerId) { @@ -2706,7 +2706,7 @@ void func_8000D438(s32 arg0, u16 arg1) { D_80162FA0[2] = (sp44 + stackPadding4) * 0.5f; } -s16 func_8000D6D0(Vec3f arg0, s16 *waypointIndex, f32 arg2, f32 arg3, s16 pathIndex, s16 arg5) { +s16 func_8000D6D0(Vec3f position, s16 *waypointIndex, f32 speed, f32 arg3, s16 pathIndex, s16 arg5) { f32 temp1; f32 temp2; f32 midX; @@ -2718,9 +2718,9 @@ s16 func_8000D6D0(Vec3f arg0, s16 *waypointIndex, f32 arg2, f32 arg3, s16 pathIn f32 pad4; f32 midZ; f32 distance; - f32 temp_f20; - f32 temp_f22; - f32 temp_f24; + f32 oldPosX; + f32 oldPosY; + f32 oldPosZ; f32 var_f2; f32 var_f12; f32 var_f14; @@ -2729,17 +2729,17 @@ s16 func_8000D6D0(Vec3f arg0, s16 *waypointIndex, f32 arg2, f32 arg3, s16 pathIn f32 xdiff; f32 ydiff; f32 zdiff; - Vec3f sp50; + Vec3f oldPos; TrackWaypoint *path; path = D_80164550[pathIndex]; - sp50[0] = arg0[0]; - sp50[1] = arg0[1]; - sp50[2] = arg0[2]; - temp_f20 = arg0[0]; - temp_f22 = arg0[1]; - temp_f24 = arg0[2]; - temp_v0 = func_8000D2B4(temp_f20, temp_f22, temp_f24, *waypointIndex, (s32) pathIndex); + oldPos[0] = position[0]; + oldPos[1] = position[1]; + oldPos[2] = position[2]; + oldPosX = position[0]; + oldPosY = position[1]; + oldPosZ = position[2]; + temp_v0 = func_8000D2B4(oldPosX, oldPosY, oldPosZ, *waypointIndex, (s32) pathIndex); *waypointIndex = temp_v0; temp_v1 = temp_v0 + arg5; waypoint1 = temp_v1 % gWaypointCountByPathIndex[pathIndex]; @@ -2753,26 +2753,26 @@ s16 func_8000D6D0(Vec3f arg0, s16 *waypointIndex, f32 arg2, f32 arg3, s16 pathIn midY = (path[waypoint1].posY + path[waypoint2].posY) * 0.5f; midX = (pad3 + temp1) * 0.5f; midZ = (pad4 + temp2) * 0.5f; - xdiff = midX - temp_f20; - ydiff = midY - temp_f22; - zdiff = midZ - temp_f24; + xdiff = midX - oldPosX; + ydiff = midY - oldPosY; + zdiff = midZ - oldPosZ; distance = sqrtf((xdiff * xdiff) + (ydiff * ydiff) + (zdiff * zdiff)); if (distance > 0.01f) { - var_f2 = ((xdiff * arg2) / distance) + temp_f20; - var_f12 = ((ydiff * arg2) / distance) + temp_f22; - var_f14 = ((zdiff * arg2) / distance) + temp_f24; + var_f2 = ((xdiff * speed) / distance) + oldPosX; + var_f12 = ((ydiff * speed) / distance) + oldPosY; + var_f14 = ((zdiff * speed) / distance) + oldPosZ; } else { - var_f2 = temp_f20; - var_f12 = temp_f22; - var_f14 = temp_f24; + var_f2 = oldPosX; + var_f12 = oldPosY; + var_f14 = oldPosZ; } - arg0[0] = var_f2; - arg0[1] = var_f12; - arg0[2] = var_f14; - return func_80005FD0(sp50, arg0); + position[0] = var_f2; + position[1] = var_f12; + position[2] = var_f14; + return get_angle_between_waypoints(oldPos, position); } -s16 func_8000D940(Vec3f arg0, s16 *waypointIndex, f32 arg2, f32 arg3, s16 pathIndex) { +s16 func_8000D940(Vec3f pos, s16 *waypointIndex, f32 speed, f32 arg3, s16 pathIndex) { UNUSED f32 pad; f32 thing1; f32 thing2; @@ -2799,13 +2799,13 @@ s16 func_8000D940(Vec3f arg0, s16 *waypointIndex, f32 arg2, f32 arg3, s16 pathIn s32 waypointCount; Vec3f sp54; - sp54[0] = arg0[0]; - sp54[1] = arg0[1]; - sp54[2] = arg0[2]; + sp54[0] = pos[0]; + sp54[1] = pos[1]; + sp54[2] = pos[2]; waypointCount = gWaypointCountByPathIndex[pathIndex]; - temp_f20 = arg0[0]; - temp_f22 = arg0[1]; - temp_f24 = arg0[2]; + temp_f20 = pos[0]; + temp_f22 = pos[1]; + temp_f24 = pos[2]; temp_v0 = func_8000D2B4(temp_f20, temp_f22, temp_f24, *waypointIndex, (s32) pathIndex); *waypointIndex = temp_v0; waypoint1 = ((temp_v0 + waypointCount) - 3) % waypointCount; @@ -2824,21 +2824,21 @@ s16 func_8000D940(Vec3f arg0, s16 *waypointIndex, f32 arg2, f32 arg3, s16 pathIn zdiff = midZ - temp_f24; distance = sqrtf((xdiff * xdiff) + (ydiff * ydiff) + (zdiff * zdiff)); if (distance > 0.01f) { - var_f2 = ((xdiff * arg2) / distance) + temp_f20; - var_f12 = ((ydiff * arg2) / distance) + temp_f22; - var_f14 = ((zdiff * arg2) / distance) + temp_f24; + var_f2 = ((xdiff * speed) / distance) + temp_f20; + var_f12 = ((ydiff * speed) / distance) + temp_f22; + var_f14 = ((zdiff * speed) / distance) + temp_f24; } else { var_f2 = temp_f20; var_f12 = temp_f22; var_f14 = temp_f24; } - arg0[0] = var_f2; - arg0[1] = var_f12; - arg0[2] = var_f14; - return func_80005FD0(sp54, arg0); + pos[0] = var_f2; + pos[1] = var_f12; + pos[2] = var_f14; + return get_angle_between_waypoints(sp54, pos); } -s16 func_8000DBAC(Vec3f pos, s16 *waypointIndex, f32 speed) { +s16 update_vehicle_following_waypoint(Vec3f pos, s16 *waypointIndex, f32 speed) { f32 origXPos; f32 origYPos; f32 origZPos; @@ -2851,18 +2851,18 @@ s16 func_8000DBAC(Vec3f pos, s16 *waypointIndex, f32 speed) { UNUSED s32 stackPadding6; UNUSED s32 stackPadding7; UNUSED s32 stackPadding8; - f32 midX; - f32 midZ; + f32 farWaypointAverageX; + f32 farWaypointAverageZ; f32 x_dist; f32 y_dist; f32 distance; - f32 var_f12; - f32 var_f14; - s16 temp_v0; - s16 anIndex; - s16 anIndex2; - PathNoY *temp_a0; - PathNoY *temp_a2; + f32 newX; + f32 newZ; + s16 newWaypointIndex; + s16 farWaypoint1; + s16 farWaypoint2; + Path2D *temp_a0; + Path2D *temp_a2; Vec3f sp38; origXPos = pos[0]; @@ -2871,28 +2871,28 @@ s16 func_8000DBAC(Vec3f pos, s16 *waypointIndex, f32 speed) { sp38[0] = pos[0]; sp38[1] = pos[1]; sp38[2] = pos[2]; - temp_v0 = func_8000D100(origXPos, origYPos, origZPos, *waypointIndex); - *waypointIndex = temp_v0; - anIndex = (temp_v0 + 3) % D_8016359C; - anIndex2 = (temp_v0 + 4) % D_8016359C; - temp_a0 = &D_80163598[anIndex]; - temp_a2 = &D_80163598[anIndex2]; - midX = (temp_a0->x + temp_a2->x) * 0.5f; - midZ = (temp_a0->z + temp_a2->z) * 0.5f; - x_dist = midX - origXPos; - y_dist = midZ - origZPos; + newWaypointIndex = find_closest_vehicles_waypoint(origXPos, origYPos, origZPos, *waypointIndex); + *waypointIndex = newWaypointIndex; + farWaypoint1 = (newWaypointIndex + 3) % gVehicle2DWaypointLength; + farWaypoint2 = (newWaypointIndex + 4) % gVehicle2DWaypointLength; + temp_a0 = &gVehicle2DWaypoint[farWaypoint1]; + temp_a2 = &gVehicle2DWaypoint[farWaypoint2]; + farWaypointAverageX = (temp_a0->x + temp_a2->x) * 0.5f; + farWaypointAverageZ = (temp_a0->z + temp_a2->z) * 0.5f; + x_dist = farWaypointAverageX - origXPos; + y_dist = farWaypointAverageZ - origZPos; distance = sqrtf((x_dist * x_dist) + (y_dist * y_dist)); if (distance > 0.01f) { - var_f12 = ((x_dist * speed) / distance) + origXPos; - var_f14 = ((y_dist * speed) / distance) + origZPos; + newX = ((x_dist * speed) / distance) + origXPos; + newZ = ((y_dist * speed) / distance) + origZPos; } else { - var_f12 = origXPos; - var_f14 = origZPos; + newX = origXPos; + newZ = origZPos; } - pos[0] = var_f12; + pos[0] = newX; pos[1] = origYPos; - pos[2] = var_f14; - return func_80005FD0(sp38, pos); + pos[2] = newZ; + return get_angle_between_waypoints(sp38, pos); } void set_bomb_kart_spawn_positions(void) { @@ -3401,7 +3401,7 @@ void func_8000F2DC(void) { D_80163368[3] = (s32) ptr->unk6; temp = ptr->unk8; - D_80163598 = get_next_available_memory_addr(temp * 4); + gVehicle2DWaypoint = get_next_available_memory_addr(temp * 4); // Podium ceremony appears to allocate 1 * 8 bytes of data. Which would be aligned to 0x10. for (i = 0; i < 4; i++) { @@ -3444,18 +3444,18 @@ void func_8000F2DC(void) { D_80164430 = *gWaypointCountByPathIndex; switch (gCurrentCourseId) { case COURSE_KALAMARI_DESERT: - func_800120C8(); - func_800127E0(); + generate_train_waypoints(); + init_vehicles_trains(); break; case COURSE_DK_JUNGLE: - func_80012190(); - func_800132F4(); + generate_ferry_waypoints(); + init_vehicles_ferry(); break; case COURSE_TOADS_TURNPIKE: - func_800147E0(); - func_80014934(); - func_80014A88(); - func_80014BDC(); + init_vehicles_box_trucks(); + init_vehicles_school_buses(); + init_vehicles_trucks(); + init_vehicles_cars(); break; } set_bomb_kart_spawn_positions(); @@ -3979,7 +3979,7 @@ s32 func_80011014(TrackWaypoint *pathDest, TrackWaypoint *path, s32 numPathPoint pathDest->posZ = (s16) temp_f22; - pathDest->trackSegment = get_section_id(D_80162E70.meshIndexZX); + pathDest->trackSectionId = get_track_section_id(D_80162E70.meshIndexZX); if (var_f20_2 < -500.0) { var_f20_2 = var_f28; @@ -4041,7 +4041,7 @@ s32 process_path_data(TrackWaypoint *dest, TrackWaypoint *src) { temp_a0 = src->posX; temp_a2 = src->posY; temp_a3 = src->posZ; - temp_t0 = src->trackSegment; + temp_t0 = src->trackSectionId; src++; if (((temp_a0 & 0xFFFF) == 0x8000) && ((temp_a2 & 0xFFFF) == 0x8000) && ((temp_a3 & 0xFFFF) == 0x8000)) { break; } if (gIsMirrorMode != 0) { @@ -4052,13 +4052,13 @@ s32 process_path_data(TrackWaypoint *dest, TrackWaypoint *src) { var_v1++; dest->posY = temp_a2; dest->posZ = temp_a3; - dest->trackSegment = temp_t0; + dest->trackSectionId = temp_t0; dest++; } return var_v1; } -s32 func_8001168C(PathNoY *pathDest, TrackWaypoint *pathSrc, s32 numWaypoints) { +s32 generate_2d_path(Path2D *pathDest, TrackWaypoint *pathSrc, s32 numWaypoints) { f32 temp_f14_3; f32 temp_f16_2; UNUSED s32 pad; @@ -4086,12 +4086,12 @@ s32 func_8001168C(PathNoY *pathDest, TrackWaypoint *pathSrc, s32 numWaypoints) { TrackWaypoint *point3; s32 i; f32 temp_f6 = 0.0f; - s32 count; + s32 nbElement; f32 sp7C; spA8 = pathSrc[0].posX; spA0 = pathSrc[0].posZ; - count = 0; + nbElement = 0; for (i = 0; i < numWaypoints; i++) { point1 = &pathSrc[((i % numWaypoints))]; @@ -4123,13 +4123,13 @@ s32 func_8001168C(PathNoY *pathDest, TrackWaypoint *pathSrc, s32 numWaypoints) { pathDest->x = (s16) spA8; } pathDest->z = spA0; - count += 1; + nbElement += 1; pathDest++; temp_f6 = 0.0f; } } } - return count; + return nbElement; } void copy_courses_kart_ai_behaviour(void) { @@ -4302,40 +4302,39 @@ void func_80011EC0(s32 arg0, Player *player, s32 arg2, UNUSED u16 arg3) { } } -void func_800120C8(void) { - s32 i; - PathNoY *temp; - TrackWaypoint *waypoint = (TrackWaypoint *) VIRTUAL_TO_PHYSICAL2( - gSegmentTable[SEGMENT_NUMBER2(d_course_kalimari_desert_track_unknown_waypoints)] - + SEGMENT_OFFSET(d_course_kalimari_desert_track_unknown_waypoints)); - - for (i = 0; ; i++) { - if ((u16)waypoint[i].posX == 0x8000) { - break; - } +#define GET_PATH_LENGTH(waypoint) for (i = 0; ; i++) { \ + if ((u16)waypoint[i].posX == 0x8000) { \ + break; \ + } \ } - temp = D_80163598; - D_8016359C = func_8001168C(temp, waypoint, i - 1); +void generate_train_waypoints(void) { + s32 i; + Path2D *temp; + TrackWaypoint *waypoint = (TrackWaypoint *) VIRTUAL_TO_PHYSICAL2( + gSegmentTable[SEGMENT_NUMBER2(d_course_kalimari_desert_train_waypoints)] + + SEGMENT_OFFSET(d_course_kalimari_desert_train_waypoints)); + + GET_PATH_LENGTH(waypoint) + + temp = gVehicle2DWaypoint; + gVehicle2DWaypointLength = generate_2d_path(temp, waypoint, i - 1); D_80162EB0 = spawn_actor_on_surface(temp[0].x, 2000.0f, temp[0].z); } -void func_80012190(void) { - TrackWaypoint *tree; +void generate_ferry_waypoints(void) { + TrackWaypoint *waypoint; s32 i; - tree = (TrackWaypoint *) VIRTUAL_TO_PHYSICAL2(gSegmentTable[SEGMENT_NUMBER2(d_frappe_snowland_tree)] + (SEGMENT_OFFSET(d_frappe_snowland_tree))); + waypoint = (TrackWaypoint *) VIRTUAL_TO_PHYSICAL2(gSegmentTable[SEGMENT_NUMBER2(d_course_dks_jungle_parkway_ferry_waypoints)] + (SEGMENT_OFFSET(d_course_dks_jungle_parkway_ferry_waypoints))); - for (i = 0; ; i++) { - if ((u16)tree[i].posX == 0x8000) { - break; - } - } - D_8016359C = func_8001168C(D_80163598, tree, i - 1); + GET_PATH_LENGTH(waypoint) + + gVehicle2DWaypointLength = generate_2d_path(gVehicle2DWaypoint, waypoint, i - 1); D_80162EB2 = -40; } -void func_80012220(VehicleStuff *vehicle) { +void spawn_vehicle_on_road(VehicleStuff *vehicle) { f32 origXPos; UNUSED f32 pad; f32 origZPos; @@ -4343,12 +4342,12 @@ void func_80012220(VehicleStuff *vehicle) { origXPos = vehicle->position[0]; origZPos = vehicle->position[2]; if (D_8016347A == 0) { - func_8000D6D0(vehicle->position, (s16*)&vehicle->waypointIndex, vehicle->someMultiplier, vehicle->someMultiplierTheSequel, 0, 3); + func_8000D6D0(vehicle->position, (s16*)&vehicle->waypointIndex, vehicle->speed, vehicle->someMultiplierTheSequel, 0, 3); vehicle->rotation[0] = 0; vehicle->rotation[1] = -0x8000; vehicle->rotation[2] = 0; } else { - func_8000D940(vehicle->position, (s16*)&vehicle->waypointIndex, vehicle->someMultiplier, vehicle->someMultiplierTheSequel, 0); + func_8000D940(vehicle->position, (s16*)&vehicle->waypointIndex, vehicle->speed, vehicle->someMultiplierTheSequel, 0); vehicle->rotation[0] = 0; vehicle->rotation[1] = 0; vehicle->rotation[2] = 0; @@ -4357,7 +4356,7 @@ void func_80012220(VehicleStuff *vehicle) { vehicle->velocity[2] = vehicle->position[2] - origZPos; } -void init_course_vehicles(void) { +void spawn_course_vehicles(void) { s16 trainCarYRot; UNUSED Vec3f pad; TrainCarStuff *tempLocomotive; @@ -4381,7 +4380,7 @@ void init_course_vehicles(void) { tempLocomotive = &gTrainList[loopIndex].locomotive; origXPos = tempLocomotive->position[0]; origZPos = tempLocomotive->position[2]; - trainCarYRot = func_8000DBAC(tempLocomotive->position, (s16*)&tempLocomotive->waypointIndex, gTrainList[loopIndex].someMultiplier); + trainCarYRot = update_vehicle_following_waypoint(tempLocomotive->position, (s16*)&tempLocomotive->waypointIndex, gTrainList[loopIndex].speed); tempLocomotive->velocity[0] = tempLocomotive->position[0] - origXPos; tempLocomotive->velocity[2] = tempLocomotive->position[2] - origZPos; vec3s_set(trainCarRot, 0, trainCarYRot, 0); @@ -4391,7 +4390,7 @@ void init_course_vehicles(void) { if (tempTender->isActive == 1) { origXPos = tempTender->position[0]; origZPos = tempTender->position[2]; - trainCarYRot = func_8000DBAC(tempTender->position, (s16*)&tempTender->waypointIndex, gTrainList[loopIndex].someMultiplier); + trainCarYRot = update_vehicle_following_waypoint(tempTender->position, (s16*)&tempTender->waypointIndex, gTrainList[loopIndex].speed); tempTender->velocity[0] = tempTender->position[0] - origXPos; tempTender->velocity[2] = tempTender->position[2] - origZPos; vec3s_set(trainCarRot, 0, trainCarYRot, 0); @@ -4403,7 +4402,7 @@ void init_course_vehicles(void) { if (tempPassengerCar->isActive == 1) { origXPos = tempPassengerCar->position[0]; origZPos = tempPassengerCar->position[2]; - trainCarYRot = func_8000DBAC(tempPassengerCar->position, (s16*)&tempPassengerCar->waypointIndex, gTrainList[loopIndex].someMultiplier); + trainCarYRot = update_vehicle_following_waypoint(tempPassengerCar->position, (s16*)&tempPassengerCar->waypointIndex, gTrainList[loopIndex].speed); tempPassengerCar->velocity[0] = tempPassengerCar->position[0] - origXPos; tempPassengerCar->velocity[2] = tempPassengerCar->position[2] - origZPos; vec3s_set(trainCarRot, 0, trainCarYRot, 0); @@ -4418,7 +4417,7 @@ void init_course_vehicles(void) { if(tempPaddleWheelBoat->isActive == 1) { origXPos = tempPaddleWheelBoat->position[0]; origZPos = tempPaddleWheelBoat->position[2]; - tempPaddleWheelBoat->rotY = func_8000DBAC(tempPaddleWheelBoat->position, (s16*)&tempPaddleWheelBoat->waypointIndex, tempPaddleWheelBoat->someMultiplier); + tempPaddleWheelBoat->rotY = update_vehicle_following_waypoint(tempPaddleWheelBoat->position, (s16*)&tempPaddleWheelBoat->waypointIndex, tempPaddleWheelBoat->speed); tempPaddleWheelBoat->velocity[0] = tempPaddleWheelBoat->position[0] - origXPos; tempPaddleWheelBoat->velocity[2] = tempPaddleWheelBoat->position[2] - origZPos; vec3s_set(paddleWheelBoatRot, 0, tempPaddleWheelBoat->rotY, 0); @@ -4429,34 +4428,34 @@ void init_course_vehicles(void) { case COURSE_TOADS_TURNPIKE: for(loopIndex = 0; loopIndex < NUM_RACE_BOX_TRUCKS; loopIndex++) { tempBoxTruck = &gBoxTruckList[loopIndex]; - func_80012220(tempBoxTruck); + spawn_vehicle_on_road(tempBoxTruck); tempBoxTruck->actorIndex = add_actor_to_empty_slot(tempBoxTruck->position, tempBoxTruck->rotation, tempBoxTruck->velocity, ACTOR_BOX_TRUCK); } for(loopIndex = 0; loopIndex < NUM_RACE_SCHOOL_BUSES; loopIndex++) { tempSchoolBus = &gSchoolBusList[loopIndex]; - func_80012220(tempSchoolBus); + spawn_vehicle_on_road(tempSchoolBus); tempSchoolBus->actorIndex = add_actor_to_empty_slot(tempSchoolBus->position, tempSchoolBus->rotation, tempSchoolBus->velocity, ACTOR_SCHOOL_BUS); } for(loopIndex = 0; loopIndex < NUM_RACE_TANKER_TRUCKS; loopIndex++) { tempTankerTruck = &gTankerTruckList[loopIndex]; - func_80012220(tempTankerTruck); + spawn_vehicle_on_road(tempTankerTruck); tempTankerTruck->actorIndex = add_actor_to_empty_slot(tempTankerTruck->position, tempTankerTruck->rotation, tempTankerTruck->velocity, ACTOR_TANKER_TRUCK); } for(loopIndex = 0; loopIndex < NUM_RACE_CARS; loopIndex++) { tempCar = &gCarList[loopIndex]; - func_80012220(tempCar); + spawn_vehicle_on_road(tempCar); tempCar->actorIndex = add_actor_to_empty_slot(tempCar->position, tempCar->rotation, tempCar->velocity, ACTOR_CAR); } break; } } -void func_80012780(TrainCarStuff *trainCar, PathNoY *arg1, u16 arg2) { - trainCar->position[0] = (f32) arg1->x; +void set_vehicle_pos_waypoint(TrainCarStuff *trainCar, Path2D *posXZ, u16 waypoint) { + trainCar->position[0] = (f32) posXZ->x; trainCar->position[1] = (f32) D_80162EB0; - trainCar->position[2] = (f32) arg1->z; + trainCar->position[2] = (f32) posXZ->z; trainCar->actorIndex = -1; - trainCar->waypointIndex = arg2; + trainCar->waypointIndex = waypoint; trainCar->isActive = 0; trainCar->velocity[0] = 0.0f; trainCar->velocity[1] = 0.0f; @@ -4467,36 +4466,36 @@ void func_80012780(TrainCarStuff *trainCar, PathNoY *arg1, u16 arg2) { * Set waypoint spawn locations for each rolling stock * The railroad has 465 waypoints */ -void func_800127E0(void) { +void init_vehicles_trains(void) { u16 waypointOffset; TrainCarStuff *ptr1; - PathNoY *ptr2; + Path2D *pos; s32 i; s32 j; for (i = 0; i < NUM_TRAINS; i++) { // outputs 160 or 392 depending on the train. // Wraps the value around to always output a valid waypoint. - waypointOffset = (((i * D_8016359C) / NUM_TRAINS) + 160) % D_8016359C; + waypointOffset = (((i * gVehicle2DWaypointLength) / NUM_TRAINS) + 160) % gVehicle2DWaypointLength; // 120.0f is about the maximum usable value - gTrainList[i].someMultiplier = 5.0f; + gTrainList[i].speed = 5.0f; for (j = 0; j < NUM_PASSENGER_CAR_ENTRIES; j++) { waypointOffset += 4; ptr1 = &gTrainList[i].passengerCars[j]; - ptr2 = &D_80163598[waypointOffset]; - func_80012780(ptr1, ptr2, waypointOffset); + pos = &gVehicle2DWaypoint[waypointOffset]; + set_vehicle_pos_waypoint(ptr1, pos, waypointOffset); } // Smaller offset for the tender waypointOffset += 3; ptr1 = &gTrainList[i].tender; - ptr2 = &D_80163598[waypointOffset]; - func_80012780(ptr1, ptr2, waypointOffset); - + pos = &gVehicle2DWaypoint[waypointOffset]; + set_vehicle_pos_waypoint(ptr1, pos, waypointOffset); + waypointOffset += 4; ptr1 = &gTrainList[i].locomotive; - ptr2 = &D_80163598[waypointOffset]; - func_80012780(ptr1, ptr2, waypointOffset); + pos = &gVehicle2DWaypoint[waypointOffset]; + set_vehicle_pos_waypoint(ptr1, pos, waypointOffset); // Only use locomotive unless overwritten below. gTrainList[i].numCars = LOCOMOTIVE_ONLY; @@ -4528,11 +4527,16 @@ void func_800127E0(void) { break; } - - D_80162FCC = 0; + + gTrainSmokeTimer = 0; } - -void func_80012A48(TrainCarStuff *trainCar, s16 arg1) { +/** + * @brief sync the train components vehicle with the actor + * + * @param trainCar + * @param orientationY + */ +void sync_train_components(TrainCarStuff *trainCar, s16 orientationY) { struct TrainCar *trainCarActor; trainCarActor = (struct TrainCar *) &gActorList[trainCar->actorIndex]; @@ -4540,9 +4544,9 @@ void func_80012A48(TrainCarStuff *trainCar, s16 arg1) { trainCarActor->pos[1] = trainCar->position[1]; trainCarActor->pos[2] = trainCar->position[2]; if (gIsMirrorMode != 0) { - trainCarActor->rot[1] = -arg1; + trainCarActor->rot[1] = -orientationY; } else { - trainCarActor->rot[1] = arg1; + trainCarActor->rot[1] = orientationY; } trainCarActor->velocity[0] = trainCar->velocity[0]; trainCarActor->velocity[2] = trainCar->velocity[2]; @@ -4552,44 +4556,44 @@ void update_vehicle_trains(void) { UNUSED s32 pad[3]; f32 temp_f20; TrainCarStuff *car; - u16 temp_s0; - s16 temp_v0; + u16 oldWaypointIndex; + s16 orientationYUpdate; f32 temp_f22; s32 i; s32 j; - Vec3f sp90; + Vec3f smokePos; - D_80162FCC += 1; + gTrainSmokeTimer += 1; for (i = 0; i < NUM_TRAINS; i++) { - temp_s0 = (u16) gTrainList[i].locomotive.waypointIndex; + oldWaypointIndex = (u16) gTrainList[i].locomotive.waypointIndex; temp_f20 = gTrainList[i].locomotive.position[0]; temp_f22 = gTrainList[i].locomotive.position[2]; - temp_v0 = func_8000DBAC(gTrainList[i].locomotive.position, (s16*)&gTrainList[i].locomotive.waypointIndex, gTrainList[i].someMultiplier); + orientationYUpdate = update_vehicle_following_waypoint(gTrainList[i].locomotive.position, (s16*)&gTrainList[i].locomotive.waypointIndex, gTrainList[i].speed); gTrainList[i].locomotive.velocity[0] = gTrainList[i].locomotive.position[0] - temp_f20; gTrainList[i].locomotive.velocity[2] = gTrainList[i].locomotive.position[2] - temp_f22; - func_80012A48(&gTrainList[i].locomotive, temp_v0); + sync_train_components(&gTrainList[i].locomotive, orientationYUpdate); - if ((temp_s0 != gTrainList[i].locomotive.waypointIndex) + if ((oldWaypointIndex != gTrainList[i].locomotive.waypointIndex) && ((gTrainList[i].locomotive.waypointIndex == 0x00BE) - || (gTrainList[i].locomotive.waypointIndex == 0x0140))) { + || (gTrainList[i].locomotive.waypointIndex == 0x0140))) { // play crossing bell sound func_800C98B8(gTrainList[i].locomotive.position, gTrainList[i].locomotive.velocity, SOUND_ARG_LOAD(0x19, 0x01, 0x80, 0x0E)); - } else if (random_int(100) == 0) { + } else if (random_int(100) == 0) { // play train whistle sound func_800C98B8(gTrainList[i].locomotive.position, gTrainList[i].locomotive.velocity, SOUND_ARG_LOAD(0x19, 0x01, 0x80, 0x0D)); } gTrainList[i].someFlags = set_vehicle_render_distance_flags(gTrainList[i].locomotive.position, TRAIN_SMOKE_RENDER_DISTANCE, gTrainList[i].someFlags); // Renders locomotive smoke on all screens if any player is within range. - if ((((s16) D_80162FCC % 5) == 0) && (gTrainList[i].someFlags != 0)) { - sp90[0] = gTrainList[i].locomotive.position[0]; - sp90[1] = (f32) ((f64) gTrainList[i].locomotive.position[1] + 65.0); - sp90[2] = (f32) ((f64) gTrainList[i].locomotive.position[2] + 25.0); - func_80006114(sp90, gTrainList[i].locomotive.position, temp_v0); - func_800755FC(i, sp90, 1.1f); + if ((((s16) gTrainSmokeTimer % 5) == 0) && (gTrainList[i].someFlags != 0)) { + smokePos[0] = gTrainList[i].locomotive.position[0]; + smokePos[1] = (f32) ((f64) gTrainList[i].locomotive.position[1] + 65.0); + smokePos[2] = (f32) ((f64) gTrainList[i].locomotive.position[2] + 25.0); + adjust_position_by_angle(smokePos, gTrainList[i].locomotive.position, orientationYUpdate); + spawn_train_smoke(i, smokePos, 1.1f); } car = &gTrainList[i].tender; @@ -4597,10 +4601,10 @@ void update_vehicle_trains(void) { if (car->isActive == 1) { temp_f20 = car->position[0]; temp_f22 = car->position[2]; - temp_v0 = func_8000DBAC(car->position, (s16*)&car->waypointIndex, gTrainList[i].someMultiplier); + orientationYUpdate = update_vehicle_following_waypoint(car->position, (s16*)&car->waypointIndex, gTrainList[i].speed); car->velocity[0] = car->position[0] - temp_f20; car->velocity[2] = car->position[2] - temp_f22; - func_80012A48(car, temp_v0); + sync_train_components(car, orientationYUpdate); } for (j = 0; j < NUM_PASSENGER_CAR_ENTRIES; j++) { @@ -4609,10 +4613,10 @@ void update_vehicle_trains(void) { temp_f20 = car->position[0]; temp_f22 = car->position[2]; - temp_v0 = func_8000DBAC(car->position, (s16*)&car->waypointIndex, gTrainList[i].someMultiplier); + orientationYUpdate = update_vehicle_following_waypoint(car->position, (s16*)&car->waypointIndex, gTrainList[i].speed); car->velocity[0] = car->position[0] - temp_f20; car->velocity[2] = car->position[2] - temp_f22; - func_80012A48(car, temp_v0); + sync_train_components(car, orientationYUpdate); } } } @@ -4681,7 +4685,7 @@ void func_80013054(void) { isCrossingTriggeredByIndex[1] = 0; for (i = 0; i < NUM_TRAINS; i++) { - temp_f16 = gTrainList[i].locomotive.waypointIndex / ((f32) D_8016359C); + temp_f16 = gTrainList[i].locomotive.waypointIndex / ((f32) gVehicle2DWaypointLength); temp_f18 = 0.72017354f; temp_f12 = 0.42299348f; @@ -4728,38 +4732,38 @@ void check_ai_crossing_distance(s32 playerId) { } } -void func_800132F4(void) { - PaddleBoatStuff *var_a1; +void init_vehicles_ferry(void) { + PaddleBoatStuff *paddleBoat; s32 i; - PathNoY *temp_a2; + Path2D *temp_a2; u16 temp; for (i = 0; i < NUM_ACTIVE_PADDLE_BOATS; i++) { temp = i * 0xB4; - var_a1 = &gPaddleBoats[i]; - temp_a2 = &D_80163598[temp]; - var_a1->position[0] = temp_a2->x; - var_a1->position[1] = D_80162EB2; - var_a1->position[2] = temp_a2->z; - var_a1->waypointIndex = i * 0xB4; - var_a1->actorIndex = -1; + paddleBoat = &gPaddleBoats[i]; + temp_a2 = &gVehicle2DWaypoint[temp]; + paddleBoat->position[0] = temp_a2->x; + paddleBoat->position[1] = D_80162EB2; + paddleBoat->position[2] = temp_a2->z; + paddleBoat->waypointIndex = i * 0xB4; + paddleBoat->actorIndex = -1; if (gPlayerCount >= 3) { - var_a1->isActive = 0; + paddleBoat->isActive = 0; } else { - var_a1->isActive = 1; + paddleBoat->isActive = 1; } - var_a1->velocity[0] = 0.0f; - var_a1->velocity[1] = 0.0f; - var_a1->velocity[2] = 0.0f; - var_a1->someMultiplier = 1.6666666f; - var_a1->rotY = 0; + paddleBoat->velocity[0] = 0.0f; + paddleBoat->velocity[1] = 0.0f; + paddleBoat->velocity[2] = 0.0f; + paddleBoat->speed = 1.6666666f; + paddleBoat->rotY = 0; } - D_801630FC = 0; + gFerrySmokeTimer = 0; } void update_vehicle_paddle_boats(void) { PaddleBoatStuff *paddleBoat; - PathNoY *waypoint; + Path2D *waypoint; s32 i; struct Actor *paddleBoatActor; f32 temp_f26; @@ -4771,28 +4775,28 @@ void update_vehicle_paddle_boats(void) { Vec3f sp94; Vec3f sp88; UNUSED s32 pad; - Vec3f sp78; + Vec3f smokePos; UNUSED s32 pad2; - D_801630FC += 1; + gFerrySmokeTimer += 1; for (i = 0; i < NUM_ACTIVE_PADDLE_BOATS; i++) { paddleBoat = &gPaddleBoats[i]; if (paddleBoat->isActive == 1) { temp_f26 = paddleBoat->position[0]; temp_f28 = paddleBoat->position[1]; temp_f30 = paddleBoat->position[2]; - func_8000DBAC(paddleBoat->position, (s16*)&paddleBoat->waypointIndex, paddleBoat->someMultiplier); + update_vehicle_following_waypoint(paddleBoat->position, (s16*)&paddleBoat->waypointIndex, paddleBoat->speed); paddleBoat->someFlags = set_vehicle_render_distance_flags(paddleBoat->position, BOAT_SMOKE_RENDER_DISTANCE, paddleBoat->someFlags); - if ((((s16) D_801630FC % 10) == 0) && (paddleBoat->someFlags != 0)) { - sp78[0] = (f32) ((f64) paddleBoat->position[0] - 30.0); - sp78[1] = (f32) ((f64) paddleBoat->position[1] + 180.0); - sp78[2] = (f32) ((f64) paddleBoat->position[2] + 45.0); - func_80006114(sp78, paddleBoat->position, paddleBoat->rotY); - func_80075A6C(i, sp78, 1.1f); - sp78[0] = (f32) ((f64) paddleBoat->position[0] + 30.0); - sp78[1] = (f32) ((f64) paddleBoat->position[1] + 180.0); - sp78[2] = (f32) ((f64) paddleBoat->position[2] + 45.0); - func_80006114(sp78, paddleBoat->position, paddleBoat->rotY); - func_80075A6C(i, sp78, 1.1f); + if ((((s16) gFerrySmokeTimer % 10) == 0) && (paddleBoat->someFlags != 0)) { + smokePos[0] = (f32) ((f64) paddleBoat->position[0] - 30.0); + smokePos[1] = (f32) ((f64) paddleBoat->position[1] + 180.0); + smokePos[2] = (f32) ((f64) paddleBoat->position[2] + 45.0); + adjust_position_by_angle(smokePos, paddleBoat->position, paddleBoat->rotY); + spawn_ferry_smoke(i, smokePos, 1.1f); + smokePos[0] = (f32) ((f64) paddleBoat->position[0] + 30.0); + smokePos[1] = (f32) ((f64) paddleBoat->position[1] + 180.0); + smokePos[2] = (f32) ((f64) paddleBoat->position[2] + 45.0); + adjust_position_by_angle(smokePos, paddleBoat->position, paddleBoat->rotY); + spawn_ferry_smoke(i, smokePos, 1.1f); } if (random_int(100) == 0) { if (random_int(2) == 0) { @@ -4804,26 +4808,26 @@ void update_vehicle_paddle_boats(void) { sp94[0] = temp_f26; sp94[1] = temp_f28; sp94[2] = temp_f30; - waypoint = &D_80163598[(paddleBoat->waypointIndex + 5) % D_8016359C]; + waypoint = &gVehicle2DWaypoint[(paddleBoat->waypointIndex + 5) % gVehicle2DWaypointLength]; sp88[0] = (f32) waypoint->x; sp88[1] = (f32) D_80162EB0; sp88[2] = (f32) waypoint->z; - temp_a1 = func_80005FD0(sp94, sp88); + temp_a1 = get_angle_between_waypoints(sp94, sp88); temp = temp_a1 - paddleBoat->rotY; var_v1 = temp; if (var_v1 < 0) { var_v1 = -var_v1; } if (var_v1 >= 0x1771) { - if (paddleBoat->someMultiplier > 0.2) { - paddleBoat->someMultiplier -= 0.04; + if (paddleBoat->speed > 0.2) { + paddleBoat->speed -= 0.04; } if (var_v1 >= 0x3D) { var_v1 = 0x003C; } } else { - if (paddleBoat->someMultiplier < 2.0) { - paddleBoat->someMultiplier += 0.02; + if (paddleBoat->speed < 2.0) { + paddleBoat->speed += 0.02; } if (var_v1 >= 0x1F) { var_v1 = 0x001E; @@ -4889,15 +4893,15 @@ void func_80013854(Player *player) { } } -void func_800139E4(f32 arg0, f32 arg1, s32 arg2, s32 arg3, VehicleStuff *vehicle, TrackWaypoint *waypointList) { +void initialize_toads_turnpike_vehicle(f32 speedA, f32 speedB, s32 numVehicles, s32 arg3, VehicleStuff *vehicleList, TrackWaypoint *waypointList) { VehicleStuff *veh; TrackWaypoint *temp_v0; s32 i; u16 waypointOffset; s32 numWaypoints = gWaypointCountByPathIndex[0]; - for (i = 0; i < arg2; i++) { - waypointOffset = (((i * numWaypoints) / arg2) + arg3) % numWaypoints; - veh = &vehicle[i]; + for (i = 0; i < numVehicles; i++) { + waypointOffset = (((i * numWaypoints) / numVehicles) + arg3) % numWaypoints; + veh = &vehicleList[i]; temp_v0 = &waypointList[waypointOffset]; veh->position[0] = (f32) temp_v0->posX; veh->position[1] = (f32) temp_v0->posY; @@ -4917,27 +4921,27 @@ void func_800139E4(f32 arg0, f32 arg1, s32 arg2, s32 arg3, VehicleStuff *vehicle } veh->someMultiplierTheSequel = (f32) ((f64) (f32) (veh->someType - 1) * 0.6); if (((gCCSelection > CC_50) || (gModeSelection == TIME_TRIALS)) && (veh->someType == 2)) { - veh->someMultiplier = arg0; + veh->speed = speedA; } else { - veh->someMultiplier = arg1; + veh->speed = speedB; } veh->rotation[0] = 0; veh->rotation[2] = 0; if (D_8016347A == 0) { - veh->rotation[1] = func_8000D6D0(veh->position, (s16*)&veh->waypointIndex, veh->someMultiplier, veh->someMultiplierTheSequel, 0, 3); + veh->rotation[1] = func_8000D6D0(veh->position, (s16*)&veh->waypointIndex, veh->speed, veh->someMultiplierTheSequel, 0, 3); } else { - veh->rotation[1] = func_8000D940(veh->position, (s16*)&veh->waypointIndex, veh->someMultiplier, veh->someMultiplierTheSequel, 0); + veh->rotation[1] = func_8000D940(veh->position, (s16*)&veh->waypointIndex, veh->speed, veh->someMultiplierTheSequel, 0); } } D_801631C8 = 10; } -f32 func_80013C74(s16 arg0, s16 arg1) { +f32 func_80013C74(s16 someType, s16 waypointIndex) { f32 var_f2; var_f2 = 0.0f; - if (arg1 < 0x28A) { - switch (arg0) { + if (waypointIndex < 0x28A) { + switch (someType) { case 0: var_f2 = -0.7f; break; @@ -4950,7 +4954,7 @@ f32 func_80013C74(s16 arg0, s16 arg1) { break; } } else { - switch (arg0) { + switch (someType) { case 0: case 1: var_f2 = -0.5f; @@ -4965,7 +4969,7 @@ f32 func_80013C74(s16 arg0, s16 arg1) { return var_f2; } -void func_80013D20(VehicleStuff *vehicle) { +void update_vehicle_follow_waypoint(VehicleStuff *vehicle) { f32 temp_f0_2; f32 temp_f0_3; f32 sp5C; @@ -4998,9 +5002,9 @@ void func_80013D20(VehicleStuff *vehicle) { } } if (D_8016347A == 0) { - var_a1 = func_8000D6D0(vehicle->position, (s16*)&vehicle->waypointIndex, vehicle->someMultiplier, vehicle->someMultiplierTheSequel, 0, 3); + var_a1 = func_8000D6D0(vehicle->position, (s16*)&vehicle->waypointIndex, vehicle->speed, vehicle->someMultiplierTheSequel, 0, 3); } else { - var_a1 = func_8000D940(vehicle->position, (s16*)&vehicle->waypointIndex, vehicle->someMultiplier, vehicle->someMultiplierTheSequel, 0); + var_a1 = func_8000D940(vehicle->position, (s16*)&vehicle->waypointIndex, vehicle->speed, vehicle->someMultiplierTheSequel, 0); } adjust_angle(&vehicle->rotation[1], var_a1, 100); temp_f0_3 = vehicle->position[0] - sp5C; @@ -5092,7 +5096,7 @@ void func_80013F7C(s32 playerId, Player *player, VehicleStuff *vehicle, f32 arg3 switch (D_8016347A) { case 0: t1 = func_80007BF8(vehicle->waypointIndex, gNearestWaypointByPlayerId[playerId], 10, 0, path); - if ((D_80163270[playerId] == 0) && (t1 > 0) && (player->unk_094 < vehicle->someMultiplier)) { + if ((D_80163270[playerId] == 0) && (t1 > 0) && (player->unk_094 < vehicle->speed)) { var_s1 = 1; } if ((D_80163270[playerId] == 1) && (t1 > 0)) { @@ -5107,7 +5111,7 @@ void func_80013F7C(s32 playerId, Player *player, VehicleStuff *vehicle, f32 arg3 if (D_80163270[playerId] == 0) { var_s1 = 1; } - if ((D_80163270[playerId] == 1) && (player->unk_094 < vehicle->someMultiplier)) { + if ((D_80163270[playerId] == 1) && (player->unk_094 < vehicle->speed)) { var_s1 = 1; } } else { @@ -5225,20 +5229,20 @@ void func_800146B8(s32 playerId, s32 arg1, VehicleStuff *vehicle) { } } -void func_800147E0(void) { +void init_vehicles_box_trucks(void) { f32 a = ((gCCSelection * 90.0) / 216.0f) + 4.583333333333333; f32 b = ((gCCSelection * 90.0) / 216.0f) + 2.9166666666666665; s32 numTrucks = NUM_RACE_BOX_TRUCKS; if (gModeSelection == TIME_TRIALS) { numTrucks = NUM_TIME_TRIAL_BOX_TRUCKS; } - func_800139E4(a, b, numTrucks, 0, gBoxTruckList, &D_80164550[0][0]); + initialize_toads_turnpike_vehicle(a, b, numTrucks, 0, gBoxTruckList, &D_80164550[0][0]); } -void func_8001487C(void) { +void update_vehicle_box_trucks(void) { s32 loopIndex; for (loopIndex = 0; loopIndex < NUM_RACE_BOX_TRUCKS; loopIndex++) { - func_80013D20(&gBoxTruckList[loopIndex]); + update_vehicle_follow_waypoint(&gBoxTruckList[loopIndex]); } } @@ -5250,7 +5254,7 @@ void func_8001490C(s32 playerId) { func_800146B8(playerId, NUM_RACE_BOX_TRUCKS, gBoxTruckList); } -void func_80014934(void) { +void init_vehicles_school_buses(void) { s32 numBusses; f32 a = ((gCCSelection * 90.0) / 216.0f) + 4.583333333333333; f32 b = ((gCCSelection * 90.0) / 216.0f) + 2.9166666666666665; @@ -5259,13 +5263,13 @@ void func_80014934(void) { if (gModeSelection == TIME_TRIALS) { numBusses = NUM_TIME_TRIAL_SCHOOL_BUSES; } - func_800139E4(a, b, numBusses, 0x4B, gSchoolBusList, &D_80164550[0][0]); + initialize_toads_turnpike_vehicle(a, b, numBusses, 75, gSchoolBusList, &D_80164550[0][0]); } -void func_800149D0(void) { +void update_vehicle_school_bus(void) { s32 loopIndex; for (loopIndex = 0; loopIndex < NUM_RACE_SCHOOL_BUSES; loopIndex++) { - func_80013D20(&gSchoolBusList[loopIndex]); + update_vehicle_follow_waypoint(&gSchoolBusList[loopIndex]); } } @@ -5277,7 +5281,7 @@ void func_80014A60(s32 playerId) { func_800146B8(playerId, NUM_RACE_SCHOOL_BUSES, gSchoolBusList); } -void func_80014A88(void) { +void init_vehicles_trucks(void) { s32 numTrucks; f32 a = ((gCCSelection * 90.0) / 216.0f) + 4.583333333333333; f32 b = ((gCCSelection * 90.0) / 216.0f) + 2.9166666666666665; @@ -5286,13 +5290,13 @@ void func_80014A88(void) { if (gModeSelection == TIME_TRIALS) { numTrucks = NUM_TIME_TRIAL_TANKER_TRUCKS; } - func_800139E4(a, b, numTrucks, 50, gTankerTruckList, &D_80164550[0][0]); + initialize_toads_turnpike_vehicle(a, b, numTrucks, 50, gTankerTruckList, &D_80164550[0][0]); } -void func_80014B24(void) { +void update_vehicle_tanker_trucks(void) { s32 loopIndex; for (loopIndex = 0; loopIndex < NUM_RACE_TANKER_TRUCKS; loopIndex++) { - func_80013D20(&gTankerTruckList[loopIndex]); + update_vehicle_follow_waypoint(&gTankerTruckList[loopIndex]); } } @@ -5304,7 +5308,7 @@ void func_80014BB4(s32 playerId) { func_800146B8(playerId, NUM_RACE_TANKER_TRUCKS, gTankerTruckList); } -void func_80014BDC(void) { +void init_vehicles_cars(void) { s32 numCars; f32 a = ((gCCSelection * 90.0) / 216.0f) + 4.583333333333333; f32 b = ((gCCSelection * 90.0) / 216.0f) + 2.9166666666666665; @@ -5313,13 +5317,13 @@ void func_80014BDC(void) { if (gModeSelection == TIME_TRIALS) { numCars = NUM_TIME_TRIAL_CARS; } - func_800139E4(a, b, numCars, 25, gCarList, &D_80164550[0][0]); + initialize_toads_turnpike_vehicle(a, b, numCars, 25, gCarList, &D_80164550[0][0]); } -void func_80014C78(void) { +void update_vehicle_cars(void) { s32 loopIndex; for (loopIndex = 0; loopIndex < NUM_RACE_CARS; loopIndex++) { - func_80013D20(&gCarList[loopIndex]); + update_vehicle_follow_waypoint(&gCarList[loopIndex]); } } diff --git a/src/code_80005FD0.h b/src/code_80005FD0.h index 4b091cf97..cf31505b4 100644 --- a/src/code_80005FD0.h +++ b/src/code_80005FD0.h @@ -56,13 +56,13 @@ typedef struct { typedef struct { s16 x; s16 z; -} PathNoY; +} Path2D; /* Function Prototypes */ -s16 func_80005FD0(Vec3f, Vec3f); +s16 get_angle_between_waypoints(Vec3f, Vec3f); s32 func_80006018(f32, f32, f32, f32, f32, f32, f32, f32); -void func_80006114(Vec3f, Vec3f, s16); +void adjust_position_by_angle(Vec3f, Vec3f, s16); s32 set_vehicle_render_distance_flags(Vec3f, f32, s32); void func_800065D0(s32, Player*); void set_places(void); @@ -97,15 +97,15 @@ void func_8000BA14(u16, f32, f32, s16); void func_8000BBD8(u16, f32, s16); s16 func_8000BD94(f32, f32, f32, s32); -s16 func_8000C0BC(f32, f32, f32, u16, s32*); +s16 find_closest_waypoint_track_segment(f32, f32, f32, u16, s32*); s16 func_8000C884(f32, f32, f32, s16, s32, u16); -s16 func_8000C9DC(f32, f32, f32, s16, s32); +s16 find_closest_waypoint_with_previous_waypoint(f32, f32, f32, s16, s32); void func_8000CBA4(f32, f32, f32, s16*, s32); void func_8000CBF8(f32, f32, f32, s16*, s32); s16 func_8000CC88(f32, f32, f32, Player*, s32, s32*); s16 func_8000CD24(f32, f32, f32, s16, Player*, s32, s32); -s16 func_8000D100(f32, f32, f32, s16); +s16 find_closest_vehicles_waypoint(f32, f32, f32, s16); s16 func_8000D24C(f32, f32, f32, s32*); s16 func_8000D2B4(f32, f32, f32, s16, s32); s16 func_8000D33C(f32, f32, f32, s16, s32); @@ -113,7 +113,7 @@ f32 func_8000D3B8(s32); void func_8000D438(s32, u16); s16 func_8000D6D0(Vec3f, s16*, f32, f32, s16, s16); s16 func_8000D940(Vec3f, s16*, f32, f32, s16); -s16 func_8000DBAC(Vec3f, s16*, f32); +s16 update_vehicle_following_waypoint(Vec3f, s16*, f32); void set_bomb_kart_spawn_positions(void); void func_8000DF8C(s32); @@ -143,7 +143,7 @@ f32 func_80010FA0(f32, f32, f32, s32, s32); s32 func_80011014(TrackWaypoint *, TrackWaypoint *, s32, s32); s32 process_path_data(TrackWaypoint*, TrackWaypoint*); -s32 func_8001168C(PathNoY*, TrackWaypoint*, s32); +s32 generate_2d_path(Path2D*, TrackWaypoint*, s32); void copy_courses_kart_ai_behaviour(void); void reset_kart_ai_behaviour_none(s32); void reset_kart_ai_behaviour(s32); @@ -152,42 +152,42 @@ void kart_ai_behaviour_end(s32, Player*); void kart_ai_behaviour(s32); void func_80011EC0(s32, Player*, s32, u16); -void func_800120C8(void); -void func_80012190(void); -void func_80012220(VehicleStuff*); -void init_course_vehicles(void); -void func_80012780(TrainCarStuff*, PathNoY *, u16); -void func_800127E0(void); -void func_80012A48(TrainCarStuff*, s16); +void generate_train_waypoints(void); +void generate_ferry_waypoints(void); +void spawn_vehicle_on_road(VehicleStuff*); +void spawn_course_vehicles(void); +void set_vehicle_pos_waypoint(TrainCarStuff*, Path2D*, u16); +void init_vehicles_trains(void); +void sync_train_components(TrainCarStuff*, s16); void update_vehicle_trains(void); void func_80012DC0(s32, Player*); void func_80013054(void); void check_ai_crossing_distance(s32); -void func_800132F4(void); +void init_vehicles_ferry(void); void update_vehicle_paddle_boats(void); void func_80013854(Player*); -void func_800139E4(f32, f32, s32, s32, VehicleStuff*, TrackWaypoint*); +void initialize_toads_turnpike_vehicle(f32, f32, s32, s32, VehicleStuff*, TrackWaypoint*); f32 func_80013C74(s16, s16); -void func_80013D20(VehicleStuff*); +void update_vehicle_follow_waypoint(VehicleStuff*); void func_80013F7C(s32, Player*, VehicleStuff*, f32, f32, s32, u32); f32 func_800145A8(s16, f32, s16); void func_800146B8(s32, s32, VehicleStuff*); -void func_800147E0(void); -void func_8001487C(void); +void init_vehicles_box_trucks(void); +void update_vehicle_box_trucks(void); void func_800148C4(s32, Player*); void func_8001490C(s32); -void func_80014934(void); -void func_800149D0(void); +void init_vehicles_school_buses(void); +void update_vehicle_school_bus(void); void func_80014A18(s32, Player*); void func_80014A60(s32); -void func_80014A88(void); -void func_80014B24(void); +void init_vehicles_trucks(void); +void update_vehicle_tanker_trucks(void); void func_80014B6C(s32, Player*); void func_80014BB4(s32); -void func_80014BDC(void); -void func_80014C78(void); +void init_vehicles_cars(void); +void update_vehicle_cars(void); void func_80014CC0(s32, Player*); void func_80014D08(s32); void func_80014D30(s32, s32); @@ -264,7 +264,7 @@ extern s16 D_80162F50[]; extern Vec3f D_80162FA0; extern Vec3f D_80162FB0; extern Vec3f D_80162FC0; -extern s16 D_80162FCC; +extern s16 gTrainSmokeTimer; extern s16 D_80162FD0; extern f32 gCourseCompletionPercentByRank[]; // D_80162FD8 extern s16 D_80162FF8[]; @@ -277,7 +277,7 @@ extern s32 D_801630B8[]; extern u16 D_801630E0; extern s16 D_801630E2; extern s16 D_801630E8[]; -extern s16 D_801630FC; +extern s16 gFerrySmokeTimer; extern s32 D_80163100[]; extern s32 D_80163128[]; extern s32 D_80163150[]; @@ -357,8 +357,8 @@ extern s16 D_801634EC; extern s32 D_801634F0; extern s32 D_801634F4; extern Test D_801634F8[]; -extern PathNoY *D_80163598; -extern s32 D_8016359C; +extern Path2D *gVehicle2DWaypoint; +extern s32 gVehicle2DWaypointLength; extern u16 isCrossingTriggeredByIndex[]; extern u16 sCrossingActiveTimer[]; extern s32 D_80163DD8[]; diff --git a/src/code_80057C60.c b/src/code_80057C60.c index 83ea52128..7ccc13c57 100644 --- a/src/code_80057C60.c +++ b/src/code_80057C60.c @@ -310,11 +310,18 @@ s32 gObjectParticle1[gObjectParticle2_SIZE]; Collision D_8018C3B0; /** * List of object list indices used for: - * Bats in Banshee's Boardwalk (but only 1 player mode?) + * - Bats in Banshee's Boardwalk (but only 1 player mode?) + * - Train index 0 smoke in Kalimari Desert + * - Ferry index 0 smoke in DK Jungle */ s32 gObjectParticle2[gObjectParticle2_SIZE]; // Maybe some unused Collision? UNUSED Collision D_8018C5F0; +/** + * List of object list indices used for: + * - Train index 1 smoke in Kalimari Desert + * - Ferry index 1 smoke in DK Jungle + */ s32 gObjectParticle3[gObjectParticle3_SIZE]; Collision D_8018C830; /** @@ -760,7 +767,7 @@ void render_object_for_player(s32 cameraId) { case COURSE_TOADS_TURNPIKE: break; case COURSE_KALAMARI_DESERT: - render_object_train_smoke_particles(cameraId); + render_object_trains_smoke_particles(cameraId); break; case COURSE_SHERBET_LAND: if (gGamestate != CREDITS_SEQUENCE) { diff --git a/src/code_80086E70.c b/src/code_80086E70.c index 13818b6c5..76da44818 100644 --- a/src/code_80086E70.c +++ b/src/code_80086E70.c @@ -1415,11 +1415,11 @@ UNUSED void func_8008A850(s32 arg0) { } UNUSED s32 func_8008A870(Player *player) { - return get_section_id(player->collision.meshIndexZX); + return get_track_section_id(player->collision.meshIndexZX); } s32 func_8008A890(Camera *camera) { - return get_section_id(camera->collision.meshIndexZX); + return get_track_section_id(camera->collision.meshIndexZX); } s32 func_8008A8B0(s16 arg0, s16 arg1) { diff --git a/src/effects.c b/src/effects.c index 8818f4df7..95420b275 100644 --- a/src/effects.c +++ b/src/effects.c @@ -1897,7 +1897,7 @@ void func_80090970(Player *player, s8 playerId, s8 arg2) { player->unk_0CA &= ~0x0001; } } else { - move_f32_towards(&player->pos[1], player->copy_rotation_y + 40.0f, 0.02f); + move_f32_towards(&player->pos[1], player->oldPos[1] + 40.0f, 0.02f); player->unk_0C6 -= 8; if (player->unk_0C6 < 9) { player->unk_0C6 = 0; diff --git a/src/player_controller.c b/src/player_controller.c index 6f4cee1ec..7fd35c0ab 100644 --- a/src/player_controller.c +++ b/src/player_controller.c @@ -873,9 +873,9 @@ void func_8002934C(Player *player, Camera *camera, s8 screenId, s8 playerId) { } else { if (((player->animFrameSelector[screenId]) >= 0) && ((player->animFrameSelector[screenId]) < 0x101)) { - var_f0 = player->copy_rotation_y - player->pos[1]; + var_f0 = player->oldPos[1] - player->pos[1]; } else { - var_f0 = player->pos[1] - player->copy_rotation_y; + var_f0 = player->pos[1] - player->oldPos[1]; } player->unk_0D4[screenId] = (s16) ((s32) (((f64) func_802B7C40(var_f0 / temp_f2)) * 0.5)); } @@ -1028,8 +1028,7 @@ void func_80029B4C(Player *player, UNUSED f32 arg1, f32 arg2, UNUSED f32 arg3) { player->tyres[FRONT_LEFT].pos[0] = player->pos[0] + sp8C[0]; player->tyres[FRONT_LEFT].pos[1] = player->pos[1] + sp8C[1]; player->tyres[FRONT_LEFT].pos[2] = player->pos[2] + sp8C[2]; - process_collision(player, &player->tyres[FRONT_LEFT], sp80[0], sp80[1], sp80[2]); - + player_terrain_collision(player, &player->tyres[FRONT_LEFT], sp80[0], sp80[1], sp80[2]); sp8C[0] = (-var_f12) + 3.6; sp8C[1] = -player->boundingBoxSize; sp8C[2] = var_f12 - 2.0f; @@ -1040,7 +1039,7 @@ void func_80029B4C(Player *player, UNUSED f32 arg1, f32 arg2, UNUSED f32 arg3) { player->tyres[FRONT_RIGHT].pos[0] = player->pos[0] + sp8C[0]; player->tyres[FRONT_RIGHT].pos[1] = player->pos[1] + sp8C[1]; player->tyres[FRONT_RIGHT].pos[2] = player->pos[2] + sp8C[2]; - process_collision(player, &player->tyres[FRONT_RIGHT], sp80[0], sp80[1], sp80[2]); + player_terrain_collision(player, &player->tyres[FRONT_RIGHT], sp80[0], sp80[1], sp80[2]); sp8C[0] = var_f12 - 2.6; sp8C[1] = -player->boundingBoxSize; sp8C[2] = (-var_f12) + 4.0f; @@ -1051,8 +1050,7 @@ void func_80029B4C(Player *player, UNUSED f32 arg1, f32 arg2, UNUSED f32 arg3) { player->tyres[BACK_LEFT].pos[0] = player->pos[0] + sp8C[0]; player->tyres[BACK_LEFT].pos[1] = player->pos[1] + sp8C[1]; player->tyres[BACK_LEFT].pos[2] = player->pos[2] + sp8C[2]; - process_collision(player, &player->tyres[BACK_LEFT], sp80[0], sp80[1], sp80[2]); - + player_terrain_collision(player, &player->tyres[BACK_LEFT], sp80[0], sp80[1], sp80[2]); sp8C[0] = (-var_f12) + 2.6; sp8C[1] = -player->boundingBoxSize; sp8C[2] = (-var_f12) + 4.0f; @@ -1063,8 +1061,7 @@ void func_80029B4C(Player *player, UNUSED f32 arg1, f32 arg2, UNUSED f32 arg3) { player->tyres[BACK_RIGHT].pos[0] = player->pos[0] + sp8C[0]; player->tyres[BACK_RIGHT].pos[1] = player->pos[1] + sp8C[1]; player->tyres[BACK_RIGHT].pos[2] = player->pos[2] + sp8C[2]; - process_collision(player, &player->tyres[BACK_RIGHT], sp80[0], sp80[1], sp80[2]); - + player_terrain_collision(player, &player->tyres[BACK_RIGHT], sp80[0], sp80[1], sp80[2]); if (!(player->effects & 8)) { a = (player->tyres[BACK_LEFT].baseHeight + player->tyres[FRONT_LEFT].baseHeight) / 2; move_f32_towards(&player->unk_230, a, 0.5f); @@ -1089,7 +1086,7 @@ void func_80029B4C(Player *player, UNUSED f32 arg1, f32 arg2, UNUSED f32 arg3) { move_s16_towards(&player->slopeAccel, func_802B7C40(temp_f0_2 / temp_f2_3), 0.5f); } else { - temp_f0_2 = player->copy_rotation_y - arg2; + temp_f0_2 = player->oldPos[1] - arg2; temp_v0 = func_802B7C40(temp_f0_2 / temp_f2_3); if (temp_f0_2 >= 0.0f) { temp_v0 /= 4; @@ -1169,7 +1166,7 @@ void func_8002A194(Player *player, f32 arg1, f32 arg2, f32 arg3) { temp_f0 = (player->unk_1F8 - player->unk_1FC); move_s16_towards(&player->slopeAccel, func_802B7C40(temp_f0 / var_f20), 0.5f); } else { - temp_f0 = player->copy_rotation_y - arg2; + temp_f0 = player->oldPos[1] - arg2; temp_v0 = func_802B7C40(temp_f0 / var_f20); if (temp_f0 >= 0.0f) { var_a1 = temp_v0 * 2; @@ -1695,7 +1692,7 @@ void func_8002B9CC(Player *player, s8 arg1, UNUSED s32 arg2) { func_8008C73C(player, arg1); } } - temp = (-(s16)get_angle_between_two_vectors(player->pos, &player->copy_rotation_x)); + temp = (-(s16)get_angle_between_two_vectors(player->pos, &player->oldPos[0])); temp2 = (player->rotation[1] - player->unk_0C0); temp = temp - temp2; player->unk_234 = temp / 182; @@ -1732,9 +1729,9 @@ void func_8002BB9C(Player *player, f32 *arg1, f32 *arg2, UNUSED s8 arg3, UNUSED mtxf_translate_vec3f_mat3(sp58, sp64); - sp4C[0] = player->copy_rotation_x; + sp4C[0] = player->oldPos[0]; sp4C[1] = 0; - sp4C[2] = player->copy_rotation_z; + sp4C[2] = player->oldPos[2]; mtxf_translate_vec3f_mat3(sp4C, sp64); @@ -2207,9 +2204,9 @@ void func_8002D268(Player *player, UNUSED Camera *camera, s8 screenId, s8 player Vec3f sp160 = {0.0, 0.0, 0.0}; f32 sp104[] = {0.825, 0.8, 0.725, 0.625, 0.425, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3}; f32 temp; - f32 spFC; - f32 spF8; - f32 spF4; + f32 nextX; + f32 nextY; + f32 nextZ; f32 posX; f32 posY; f32 posZ; @@ -2273,7 +2270,7 @@ void func_8002D268(Player *player, UNUSED Camera *camera, s8 screenId, s8 player spB0 = -1 * player->kartGravity; spAC = 0 * (player->unk_064[2] + sp16C[2]); } - temp_f2_2 = ((player->copy_rotation_z - player->pos[2]) * coss(player->rotation[1] + player->unk_0C0)) + (-(player->copy_rotation_x - player->pos[0]) * sins(player->rotation[1] + player->unk_0C0)); + temp_f2_2 = ((player->oldPos[2] - player->pos[2]) * coss(player->rotation[1] + player->unk_0C0)) + (-(player->oldPos[0] - player->pos[0]) * sins(player->rotation[1] + player->unk_0C0)); if (temp_f2_2 > 0.1) { player->unk_044 |= 8; } else { @@ -2325,22 +2322,22 @@ void func_8002D268(Player *player, UNUSED Camera *camera, s8 screenId, s8 player posY = player->pos[1]; posZ = player->pos[2]; - player->copy_rotation_x = player->pos[0]; - player->copy_rotation_z = player->pos[2]; - player->copy_rotation_y = player->pos[1]; - spFC = posX + player->velocity[0] + D_8018CE10[playerId].unk_04[0]; - spF8 = posY + player->velocity[1]; - spF4 = posZ + player->velocity[2] + D_8018CE10[playerId].unk_04[2]; + player->oldPos[0] = player->pos[0]; + player->oldPos[2] = player->pos[2]; + player->oldPos[1] = player->pos[1]; + nextX = posX + player->velocity[0] + D_8018CE10[playerId].unk_04[0]; + nextY = posY + player->velocity[1]; + nextZ = posZ + player->velocity[2] + D_8018CE10[playerId].unk_04[2]; if (((((player->unk_0CA & 2) != 2) && ((player->unk_0CA & 8) != 8)) && ((player->effects & HIT_EFFECT) != HIT_EFFECT)) && (!(player->unk_0CA & 1))) { func_8002AAC0(player); - spF8 += player->kartHopVelocity; - spF8 -= 0.02; + nextY += player->kartHopVelocity; + nextY -= 0.02; } - actor_terrain_collision(&player->collision, player->boundingBoxSize, spFC, spF8, spF4, player->copy_rotation_x, player->copy_rotation_y, player->copy_rotation_z); + actor_terrain_collision(&player->collision, player->boundingBoxSize, nextX, nextY, nextZ, player->oldPos[0], player->oldPos[1], player->oldPos[2]); player->unk_058 = 0.0f; player->unk_060 = 0.0f; player->unk_05C = 1.0f; @@ -2404,16 +2401,16 @@ void func_8002D268(Player *player, UNUSED Camera *camera, s8 screenId, s8 player } temp_var = player->collision.surfaceDistance[2]; if (temp_var <= 0.0f) { - func_8003F46C(player, sp8C, sp98, sp178, &temp_var, &spFC, &spF8, &spF4); + func_8003F46C(player, sp8C, sp98, sp178, &temp_var, &nextX, &nextY, &nextZ); } temp_var = player->collision.surfaceDistance[0]; if (temp_var < 0.0f) { - func_8003F734(player, sp8C, sp98, &temp_var, &spFC, &spF8, &spF4); + func_8003F734(player, sp8C, sp98, &temp_var, &nextX, &nextY, &nextZ); func_8002C954(player, playerId, sp98); } temp_var = player->collision.surfaceDistance[1]; if (temp_var < 0.0f) { - func_8003FBAC(player, sp8C, sp98, &temp_var, &spFC, &spF8, &spF4); + func_8003FBAC(player, sp8C, sp98, &temp_var, &nextX, &nextY, &nextZ); func_8002C954(player, playerId, sp98); } temp_var = player->collision.surfaceDistance[0]; @@ -2437,13 +2434,13 @@ void func_8002D268(Player *player, UNUSED Camera *camera, s8 screenId, s8 player } else if (((!(player->effects & 8)) && (func_802ABDB8(player->collision.meshIndexZX) == 0)) && (player->effects & 0x10000)) { func_8008F5A4(player, playerId); } - player->unk_074 = calculate_surface_height(spFC, spF8, spF4, player->collision.meshIndexZX); + player->unk_074 = calculate_surface_height(nextX, nextY, nextZ, player->collision.meshIndexZX); if (((player->type & PLAYER_HUMAN) == PLAYER_HUMAN) && (((gActiveScreenMode == SCREEN_MODE_1P) || (gActiveScreenMode == SCREEN_MODE_2P_SPLITSCREEN_VERTICAL)) || (gActiveScreenMode == SCREEN_MODE_2P_SPLITSCREEN_HORIZONTAL))) { - func_80029B4C(player, spFC, spF8, spF4); + func_80029B4C(player, nextX, nextY, nextZ); } else { - func_8002A194(player, spFC, spF8, spF4); + func_8002A194(player, nextX, nextY, nextZ); } - func_8002AE38(player, playerId, posX, posZ, spFC, spF4); + func_8002AE38(player, playerId, posX, posZ, nextX, nextZ); temp2 = (sp98[0] * sp98[0]) + (sp98[2] * sp98[2]); player->unk_22C = player->unk_094; @@ -2456,12 +2453,12 @@ void func_8002D268(Player *player, UNUSED Camera *camera, s8 screenId, s8 player sp98[0] = sp98[0] + (-1 * sp98[0]); sp98[2] = sp98[2] + (-1 * sp98[2]); } else { - player->pos[0] = spFC; - player->pos[2] = spF4; + player->pos[0] = nextX; + player->pos[2] = nextZ; } - player->pos[1] = spF8; + player->pos[1] = nextY; if ((player->type & PLAYER_HUMAN) && (!(player->type & PLAYER_KART_AI))) { - func_8002BB9C(player, &spFC, &spF4, screenId, playerId, sp98); + func_8002BB9C(player, &nextX, &nextZ, screenId, playerId, sp98); } player->unk_064[0] = sp178[0]; player->unk_064[2] = sp178[2]; @@ -2504,7 +2501,7 @@ void func_8002E4C4(Player *player) { player->kartHopVelocity = 0.0f; player->pos[1] = spawn_actor_on_surface(player->pos[0], D_80164510[player_index] + 10.0f, player->pos[2]) + player->boundingBoxSize; if (((player->pos[1] - D_80164510[player_index]) > 1200.0f) || ((player->pos[1] - D_80164510[player_index]) < -1200.0f)) { - player->pos[1] = player->copy_rotation_y; + player->pos[1] = player->oldPos[1]; } player->velocity[1] = 0.0f; } @@ -2596,16 +2593,16 @@ void func_8002E594(Player *player, UNUSED Camera *camera, s8 screenId, s8 player posY = player->pos[1]; posZ = player->pos[2]; - player->copy_rotation_x = player->pos[0]; - player->copy_rotation_y = player->pos[1]; - player->copy_rotation_z = player->pos[2]; + player->oldPos[0] = player->pos[0]; + player->oldPos[1] = player->pos[1]; + player->oldPos[2] = player->pos[2]; spD0 = posX + player->velocity[0] + D_8018CE10[playerId].unk_04[0]; spCC = posY + player->velocity[1]; spC8 = posZ + player->velocity[2] + D_8018CE10[playerId].unk_04[2]; func_8002AAC0(player); spCC += player->kartHopVelocity; - actor_terrain_collision(&player->collision, player->boundingBoxSize, spD0, spCC, spC8, player->copy_rotation_x, player->copy_rotation_y, player->copy_rotation_z); + actor_terrain_collision(&player->collision, player->boundingBoxSize, spD0, spCC, spC8, player->oldPos[0], player->oldPos[1], player->oldPos[2]); player->effects |= 8; player->unk_0C2 += 1; player->unk_058 = 0.0f; @@ -2789,9 +2786,9 @@ void control_kart_ai_movement(Player *player, UNUSED Camera *camera, s8 arg2, s8 sp68[2] = player->velocity[2]; sp68[0] += (((spF4[0] + sp84) + spD0[0]) - (sp68[0] * (0.12 * player->kartFriction))) / 6000.0; sp68[2] += (((spF4[2] + sp7C) + spD0[2]) - (sp68[2] * (0.12 * player->kartFriction))) / 6000.0; - player->copy_rotation_x = player->pos[0]; - player->copy_rotation_y = test; - player->copy_rotation_z = player->pos[2]; + player->oldPos[0] = player->pos[0]; + player->oldPos[1] = test; + player->oldPos[2] = player->pos[2]; spCC = player->pos[0] + player->velocity[0]; spC4 = player->pos[2] + player->velocity[2]; player->unk_0C0 = 0; @@ -2870,9 +2867,9 @@ void func_8002F730(Player *player, UNUSED Camera *camera, UNUSED s8 screenId, s8 spB8 = player->pos[2]; - player->copy_rotation_x = player->pos[0]; - player->copy_rotation_y = player->pos[1]; - player->copy_rotation_z = player->pos[2]; + player->oldPos[0] = player->pos[0]; + player->oldPos[1] = player->pos[1]; + player->oldPos[2] = player->pos[2]; spCC = player->velocity[0] + spC0; spC8 = player->velocity[1] + sp44; @@ -2881,7 +2878,7 @@ void func_8002F730(Player *player, UNUSED Camera *camera, UNUSED s8 screenId, s8 func_8002AAC0(player); spC8 += player->kartHopVelocity; - actor_terrain_collision(&player->collision, player->boundingBoxSize, spCC, spC8, spC4, player->copy_rotation_x, player->copy_rotation_y, player->copy_rotation_z); + actor_terrain_collision(&player->collision, player->boundingBoxSize, spCC, spC8, spC4, player->oldPos[0], player->oldPos[1], player->oldPos[2]); player->unk_058 = 0.0f; player->unk_05C = 1.0f; player->unk_060 = 0.0f; @@ -5002,9 +4999,9 @@ void func_80038C6C(Player *player, UNUSED Camera *camera, s8 arg2, s8 playerId) posY = player->pos[1]; posZ = player->pos[2]; - player->copy_rotation_x = player->pos[0]; - player->copy_rotation_y = player->pos[1]; - player->copy_rotation_z = player->pos[2]; + player->oldPos[0] = player->pos[0]; + player->oldPos[1] = player->pos[1]; + player->oldPos[2] = player->pos[2]; spEC = posX + player->velocity[0]; spE8 = posY + player->velocity[1]; @@ -5012,7 +5009,7 @@ void func_80038C6C(Player *player, UNUSED Camera *camera, s8 arg2, s8 playerId) func_8002AAC0(player); spE8 += player->kartHopVelocity; spE8 -= 0.02; - actor_terrain_collision(&player->collision, player->boundingBoxSize, spEC, spE8, spE4, player->copy_rotation_x, player->copy_rotation_y, player->copy_rotation_z); + actor_terrain_collision(&player->collision, player->boundingBoxSize, spEC, spE8, spE4, player->oldPos[0], player->oldPos[1], player->oldPos[2]); player->unk_058 = 0; player->unk_060 = 0; player->unk_05C = 1.0f; diff --git a/src/racing/actors.c b/src/racing/actors.c index 27bb099b3..d80b82e0a 100644 --- a/src/racing/actors.c +++ b/src/racing/actors.c @@ -1155,8 +1155,8 @@ void spawn_course_actors(void) { /** * @brief Loads actor textures, course specific actor textures. - * Calls to init_course_vehicles and place_course_actors - * + * Calls to spawn_course_vehicles and place_course_actors + * */ void init_actors_and_load_textures(void) { set_segment_base_addr(3, (void *) gNextFreeMemoryAddress); @@ -1256,7 +1256,7 @@ void init_actors_and_load_textures(void) { init_red_shell_texture(); destroy_all_actors(); spawn_course_actors(); - init_course_vehicles(); + spawn_course_vehicles(); } void play_sound_before_despawn(struct Actor *actor) { diff --git a/src/racing/collision.c b/src/racing/collision.c index 4676e84d1..568b8f2ae 100644 --- a/src/racing/collision.c +++ b/src/racing/collision.c @@ -82,7 +82,7 @@ f32 func_802AAB4C(Player *player) { } return D_8015F8E4; case COURSE_DK_JUNGLE: - temp_v1 = get_section_id(player->collision.meshIndexZX) & 0xFF; + temp_v1 = get_track_section_id(player->collision.meshIndexZX) & 0xFF; if (temp_v1 == 0xFF) { if ((get_surface_type(player->collision.meshIndexZX) & 0xFF) == CAVE) { return -475.0f; @@ -496,7 +496,7 @@ s8 get_surface_type(u16 index) { return triangle->surfaceType; } -s16 get_section_id(u16 index) { +s16 get_track_section_id(u16 index) { CollisionTriangle *triangle = &gCollisionMesh[index]; return triangle->flags & 0xFF; } @@ -748,7 +748,7 @@ UNUSED s32 detect_tyre_collision(KartTyre *tyre) { // depending on which (if any) if statements were entered on the loop's last cycle } -s32 is_colliding_with_drivable_surface(Collision *collision, f32 boundingBoxSize, f32 x1, f32 y1, f32 z1, u16 index, f32 posX, f32 posY, f32 posZ) { +s32 is_colliding_with_drivable_surface(Collision *collision, f32 boundingBoxSize, f32 newX, f32 newY, f32 newZ, u16 index, f32 oldX, f32 oldY, f32 oldZ) { CollisionTriangle *triangle = &gCollisionMesh[index]; UNUSED s32 pad; f32 x4; @@ -768,19 +768,19 @@ s32 is_colliding_with_drivable_surface(Collision *collision, f32 boundingBoxSize f32 area3; s32 b = 1; - if (triangle->minX > x1) { + if (triangle->minX > newX) { return 0; } - if (triangle->minZ > z1) { + if (triangle->minZ > newZ) { return 0; } - if (triangle->maxX < x1) { + if (triangle->maxX < newX) { return 0; } - if (triangle->maxZ < z1) { + if (triangle->maxZ < newZ) { return 0; } - if ((triangle->minY - boundingBoxSize * 3.0f) > y1) { + if ((triangle->minY - boundingBoxSize * 3.0f) > newY) { return 0; } @@ -793,22 +793,22 @@ s32 is_colliding_with_drivable_surface(Collision *collision, f32 boundingBoxSize x4 = (f32) triangle->vtx3->v.ob[0]; z4 = (f32) triangle->vtx3->v.ob[2]; - area = (z2 - z1) * (x3 - x1) - (x2 - x1) * (z3 - z1); + area = (z2 - newZ) * (x3 - newX) - (x2 - newX) * (z3 - newZ); if (area == 0) { - area2 = (z3 - z1) * (x4 - x1) - (x3 - x1) * (z4 - z1); - area3 = (z4 - z1) * (x2 - x1) - (x4 - x1) * (z2 - z1); + area2 = (z3 - newZ) * (x4 - newX) - (x3 - newX) * (z4 - newZ); + area3 = (z4 - newZ) * (x2 - newX) - (x4 - newX) * (z2 - newZ); if (area2 * area3 < 0.0f) { b = 0; } } else { - area2 = (z3 - z1) * (x4 - x1) - (x3 - x1) * (z4 - z1); + area2 = (z3 - newZ) * (x4 - newX) - (x3 - newX) * (z4 - newZ); if (area2 == 0) { - area3 = (z4 - z1) * (x2 - x1) - (x4 - x1) * (z2 - z1); + area3 = (z4 - newZ) * (x2 - newX) - (x4 - newX) * (z2 - newZ); if (area * area3 < 0.0f) { b = 0; @@ -817,7 +817,7 @@ s32 is_colliding_with_drivable_surface(Collision *collision, f32 boundingBoxSize if ((area * area2) < 0.0f) { b = 0; } else { - area3 = (z4- z1) * (x2 - x1) - (x4 - x1) * (z2 - z1); + area3 = (z4- newZ) * (x2 - newX) - (x4 - newX) * (z2 - newZ); if (area3 != 0) { if (area2 * area3 < 0.0f) { b = 0; @@ -830,7 +830,7 @@ s32 is_colliding_with_drivable_surface(Collision *collision, f32 boundingBoxSize return 0; } - surfaceDistance = (triangle->normalX * x1) + (triangle->normalY * y1) + (triangle->normalZ * z1) + triangle->distance; + surfaceDistance = (triangle->normalX * newX) + (triangle->normalY * newY) + (triangle->normalZ * newZ) + triangle->distance; if (surfaceDistance > boundingBoxSize) { if (collision->surfaceDistance[2] > surfaceDistance) { @@ -844,25 +844,26 @@ s32 is_colliding_with_drivable_surface(Collision *collision, f32 boundingBoxSize return 0; } - temp = (triangle->normalX * posX) + (triangle->normalY * posY) + (triangle->normalZ * posZ) + triangle->distance; + temp = (triangle->normalX * oldX) + (triangle->normalY * oldY) + (triangle->normalZ * oldZ) + triangle->distance; if (temp < 0.0f) { return 0; } - collision->unk34 = 1; - collision->meshIndexZX = index; - collision->surfaceDistance[2] = surfaceDistance - boundingBoxSize; - collision->orientationVector[0] = triangle->normalX; - collision->orientationVector[1] = triangle->normalY; - collision->orientationVector[2] = triangle->normalZ; - return 1; + + collision->unk34 = 1; + collision->meshIndexZX = index; + collision->surfaceDistance[2] = surfaceDistance - boundingBoxSize; + collision->orientationVector[0] = triangle->normalX; + collision->orientationVector[1] = triangle->normalY; + collision->orientationVector[2] = triangle->normalZ; + return 1; } /** * Wall collision */ -s32 is_colliding_with_wall2(Collision *arg, f32 boundingBoxSize, f32 x1, f32 y1, f32 z1, u16 arg5, f32 arg6, f32 arg7, f32 arg8) { - CollisionTriangle *triangle = &gCollisionMesh[arg5]; +s32 is_colliding_with_wall2(Collision *arg, f32 boundingBoxSize, f32 x1, f32 y1, f32 z1, u16 surfaceIndex, f32 posX, f32 posY, f32 posZ) { + CollisionTriangle *triangle = &gCollisionMesh[surfaceIndex]; UNUSED s32 pad[6]; f32 x4; f32 y4; @@ -879,22 +880,22 @@ s32 is_colliding_with_wall2(Collision *arg, f32 boundingBoxSize, f32 x1, f32 y1, f32 area3; s32 b = true; if (triangle->minX > x1) { - return 0; + return NO_COLLISION; } if (triangle->maxX < x1) { - return 0; + return NO_COLLISION; } if (triangle->maxY < y1) { - return 0; + return NO_COLLISION; } if (triangle->minY > y1) { - return 0; + return NO_COLLISION; } if ((triangle->minZ - boundingBoxSize * 3.0f) > z1) { - return 0; + return NO_COLLISION; } if ((triangle->maxZ + boundingBoxSize * 3.0f) < z1) { - return 0; + return NO_COLLISION; } x2 = (f32) triangle->vtx1->v.ob[0]; @@ -941,107 +942,108 @@ s32 is_colliding_with_wall2(Collision *arg, f32 boundingBoxSize, f32 x1, f32 y1, } } } + if (!b) { - return 0; + return NO_COLLISION; } distanceToSurface = ((triangle->normalX * x1) + (triangle->normalY * y1) + (triangle->normalZ * z1)) + triangle->distance; if (triangle->flags & 0x200) { - distanceToSurface2 = ((triangle->normalX * arg6) + (triangle->normalY * arg7) + (triangle->normalZ * arg8)) + triangle->distance; + distanceToSurface2 = ((triangle->normalX * posX) + (triangle->normalY * posY) + (triangle->normalZ * posZ)) + triangle->distance; if ((distanceToSurface > 0.0f) && (distanceToSurface2 > 0.0f)) { if (distanceToSurface < boundingBoxSize) { arg->unk30 = 1; - arg->meshIndexYX = arg5; + arg->meshIndexYX = surfaceIndex; arg->surfaceDistance[0] = distanceToSurface - boundingBoxSize; arg->unk48[0] = triangle->normalX; arg->unk48[1] = triangle->normalY; arg->unk48[2] = triangle->normalZ; - return 1; + return COLLISION; } - return 0; + return NO_COLLISION; } if ((distanceToSurface < 0.0f) && (distanceToSurface2 < 0.0f)) { distanceToSurface *= -1.0f; if (distanceToSurface < boundingBoxSize) { arg->unk30 = 1; - arg->meshIndexYX = arg5; + arg->meshIndexYX = surfaceIndex; arg->surfaceDistance[0] = distanceToSurface - boundingBoxSize; arg->unk48[0] = -triangle->normalX; arg->unk48[1] = -triangle->normalY; arg->unk48[2] = -triangle->normalZ; return 1; } - return 0; + return NO_COLLISION; } if ((distanceToSurface > 0.0f) && (distanceToSurface2 < 0.0f)) { arg->unk30 = 1; - arg->meshIndexYX = arg5; + arg->meshIndexYX = surfaceIndex; arg->surfaceDistance[0] = -(distanceToSurface + boundingBoxSize); arg->unk48[0] = -triangle->normalX; arg->unk48[1] = -triangle->normalY; arg->unk48[2] = -triangle->normalZ; - return 1; + return COLLISION; } if ((distanceToSurface < 0.0f) && (distanceToSurface2 > 0.0f)) { arg->unk30 = 1; - arg->meshIndexYX = arg5; + arg->meshIndexYX = surfaceIndex; arg->surfaceDistance[0] = distanceToSurface + boundingBoxSize; arg->unk48[0] = triangle->normalX; arg->unk48[1] = triangle->normalY; arg->unk48[2] = triangle->normalZ; - return 1; + return COLLISION; } if (distanceToSurface == 0.0f) { if (distanceToSurface2 >= 0.0f) { arg->unk30 = 1; - arg->meshIndexYX = arg5; + arg->meshIndexYX = surfaceIndex; arg->surfaceDistance[0] = distanceToSurface2 + boundingBoxSize; arg->unk48[0] = triangle->normalX; arg->unk48[1] = triangle->normalY; arg->unk48[2] = triangle->normalZ; - return 1; + return COLLISION; } arg->unk30 = 1; - arg->meshIndexYX = arg5; + arg->meshIndexYX = surfaceIndex; arg->surfaceDistance[0] = -(distanceToSurface2 + boundingBoxSize); arg->unk48[0] = triangle->normalX; arg->unk48[1] = triangle->normalY; arg->unk48[2] = triangle->normalZ; - return 1; + return COLLISION; } - return 0; + return NO_COLLISION; } if (distanceToSurface > boundingBoxSize) { if (distanceToSurface < arg->surfaceDistance[0]) { arg->unk30 = 1; - arg->meshIndexYX = arg5; + arg->meshIndexYX = surfaceIndex; arg->surfaceDistance[0] = distanceToSurface - boundingBoxSize; arg->unk48[0] = triangle->normalX; arg->unk48[1] = triangle->normalY; arg->unk48[2] = triangle->normalZ; } - return 0; + return NO_COLLISION; } - distanceToSurface2 = (triangle->normalX * arg6) + (triangle->normalY * arg7) + (triangle->normalZ * arg8) + triangle->distance; + distanceToSurface2 = (triangle->normalX * posX) + (triangle->normalY * posY) + (triangle->normalZ * posZ) + triangle->distance; if (distanceToSurface2 < 0.0f) { - return 0; + return NO_COLLISION; } arg->unk30 = 1; - arg->meshIndexYX = arg5; + arg->meshIndexYX = surfaceIndex; arg->surfaceDistance[0] = distanceToSurface - boundingBoxSize; arg->unk48[0] = triangle->normalX; arg->unk48[1] = triangle->normalY; arg->unk48[2] = triangle->normalZ; - return 1; + return COLLISION; } /** * This is actually more like colliding with face X/Y/Z */ -s32 is_colliding_with_wall1(Collision *arg, f32 boundingBoxSize, f32 x1, f32 y1, f32 z1, u16 arg5, f32 arg6, f32 arg7, f32 arg8) { - CollisionTriangle *triangle = &gCollisionMesh[arg5]; +s32 is_colliding_with_wall1(Collision *arg, f32 boundingBoxSize, f32 x1, f32 y1, f32 z1, u16 surfaceIndex, f32 posX, f32 posY, f32 posZ) { + CollisionTriangle *triangle = &gCollisionMesh[surfaceIndex]; s32 b = 1; UNUSED s32 pad[7]; f32 y4; @@ -1059,22 +1061,22 @@ s32 is_colliding_with_wall1(Collision *arg, f32 boundingBoxSize, f32 x1, f32 y1, f32 area3; if (triangle->minZ > z1) { - return 0; + return NO_COLLISION; } if (triangle->maxZ < z1) { - return 0; + return NO_COLLISION; } if (triangle->maxY < y1) { - return 0; + return NO_COLLISION; } if (triangle->minY > y1) { - return 0; + return NO_COLLISION; } if ((triangle->minX - boundingBoxSize * 3.0f) > x1) { - return 0; + return NO_COLLISION; } if ((triangle->maxX + boundingBoxSize * 3.0f) < x1) { - return 0; + return NO_COLLISION; } z2 = (f32) triangle->vtx1->v.ob[2]; @@ -1122,103 +1124,103 @@ s32 is_colliding_with_wall1(Collision *arg, f32 boundingBoxSize, f32 x1, f32 y1, } } if (b == 0) { - return 0; + return NO_COLLISION; } distanceToSurface = ((triangle->normalX * x1) + (triangle->normalY * y1) + (triangle->normalZ * z1)) + triangle->distance; if (triangle->flags & 0x200) { - distanceToSurface2 = ((triangle->normalX * arg6) + (triangle->normalY * arg7) + (triangle->normalZ * arg8)) + triangle->distance; + distanceToSurface2 = ((triangle->normalX * posX) + (triangle->normalY * posY) + (triangle->normalZ * posZ)) + triangle->distance; //sp48 = temp_f4_2; if ((distanceToSurface > 0.0f) && (distanceToSurface2 > 0.0f)) { if (distanceToSurface < boundingBoxSize) { arg->unk32 = 1; - arg->meshIndexZY = arg5; + arg->meshIndexZY = surfaceIndex; arg->surfaceDistance[1] = distanceToSurface - boundingBoxSize; arg->unk54[0] = triangle->normalX; arg->unk54[1] = triangle->normalY; arg->unk54[2] = triangle->normalZ; - return 1; + return COLLISION; } - return 0; + return NO_COLLISION; } if ((distanceToSurface < 0.0f) && (distanceToSurface2 < 0.0f)) { distanceToSurface *= -1.0f; if (distanceToSurface < boundingBoxSize) { arg->unk32 = 1; - arg->meshIndexZY = arg5; + arg->meshIndexZY = surfaceIndex; arg->surfaceDistance[1] = distanceToSurface - boundingBoxSize; arg->unk54[0] = -triangle->normalX; arg->unk54[1] = -triangle->normalY; arg->unk54[2] = -triangle->normalZ; return 1; } - return 0; + return NO_COLLISION; } if ((distanceToSurface > 0.0f) && (distanceToSurface2 < 0.0f)) { arg->unk32 = 1; - arg->meshIndexZY = arg5; + arg->meshIndexZY = surfaceIndex; arg->surfaceDistance[1] = -(distanceToSurface + boundingBoxSize); arg->unk54[0] = -triangle->normalX; arg->unk54[1] = -triangle->normalY; arg->unk54[2] = -triangle->normalZ; - return 1; + return COLLISION; } if ((distanceToSurface < 0.0f) && (distanceToSurface2 > 0.0f)) { arg->unk32 = 1; - arg->meshIndexZY = arg5; + arg->meshIndexZY = surfaceIndex; arg->surfaceDistance[1] = distanceToSurface + boundingBoxSize; arg->unk54[0] = triangle->normalX; arg->unk54[1] = triangle->normalY; arg->unk54[2] = triangle->normalZ; - return 1; + return COLLISION; } if (distanceToSurface == 0.0f) { if (distanceToSurface2 >= 0.0f) { arg->unk32 = 1; - arg->meshIndexZY = arg5; + arg->meshIndexZY = surfaceIndex; arg->surfaceDistance[1] = distanceToSurface2 + boundingBoxSize; arg->unk54[0] = triangle->normalX; arg->unk54[1] = triangle->normalY; arg->unk54[2] = triangle->normalZ; - return 1; + return COLLISION; } arg->unk32 = 1; - arg->meshIndexZY = arg5; + arg->meshIndexZY = surfaceIndex; arg->surfaceDistance[1] = -(distanceToSurface2 + boundingBoxSize); arg->unk54[0] = triangle->normalX; arg->unk54[1] = triangle->normalY; arg->unk54[2] = triangle->normalZ; - return 1; + return COLLISION; } - return 0; + return NO_COLLISION; } if (distanceToSurface > boundingBoxSize) { if (arg->surfaceDistance[1] > distanceToSurface) { arg->unk32 = 1; - arg->meshIndexZY = arg5; + arg->meshIndexZY = surfaceIndex; arg->surfaceDistance[1] = distanceToSurface - boundingBoxSize; arg->unk54[0] = triangle->normalX; arg->unk54[1] = triangle->normalY; arg->unk54[2] = triangle->normalZ; } - return 0; + return NO_COLLISION; } - distanceToSurface2 = (triangle->normalX * arg6) + (triangle->normalY * arg7) + (triangle->normalZ * arg8) + triangle->distance; + distanceToSurface2 = (triangle->normalX * posX) + (triangle->normalY * posY) + (triangle->normalZ * posZ) + triangle->distance; if (distanceToSurface2 < 0.0f) { - return 0; + return NO_COLLISION; } arg->unk32 = 1; - arg->meshIndexZY = arg5; + arg->meshIndexZY = surfaceIndex; arg->surfaceDistance[1] = distanceToSurface - boundingBoxSize; arg->unk54[0] = triangle->normalX; arg->unk54[1] = triangle->normalY; arg->unk54[2] = triangle->normalZ; - return 1; + return COLLISION; } -u16 actor_terrain_collision(Collision *collision, f32 boundingBoxSize, f32 x1, f32 y1, f32 z1, f32 x2, f32 y2, f32 z2) { +u16 actor_terrain_collision(Collision *collision, f32 boundingBoxSize, f32 newX, f32 newY, f32 newZ, f32 oldX, f32 oldY, f32 oldZ) { s32 courseLengthX; s32 courseLengthZ; s16 sectionIndexX; @@ -1244,19 +1246,19 @@ u16 actor_terrain_collision(Collision *collision, f32 boundingBoxSize, f32 x1, f // Check if an intersection test has already been performed. if ((s32) collision->meshIndexZX < (s32) gCollisionMeshCount) { - if (is_colliding_with_drivable_surface(collision, boundingBoxSize, x1, y1, z1, collision->meshIndexZX, x2, y2, z2) == 1) { + if (is_colliding_with_drivable_surface(collision, boundingBoxSize, newX, newY, newZ, collision->meshIndexZX, oldX, oldY, oldZ) == COLLISION) { flags |= FACING_Y_AXIS; } } if ((s32) collision->meshIndexYX < (s32) gCollisionMeshCount) { - if (is_colliding_with_wall2(collision, boundingBoxSize, x1, y1, z1, collision->meshIndexYX, x2, y2, z2) == 1) { + if (is_colliding_with_wall2(collision, boundingBoxSize, newX, newY, newZ, collision->meshIndexYX, oldX, oldY, oldZ) == COLLISION) { flags |= FACING_Z_AXIS; } } if ((s32) collision->meshIndexZY < (s32) gCollisionMeshCount) { - if (is_colliding_with_wall1(collision, boundingBoxSize, x1, y1, z1, collision->meshIndexZY, x2, y2, z2) == 1) { + if (is_colliding_with_wall1(collision, boundingBoxSize, newX, newY, newZ, collision->meshIndexZY, oldX, oldY, oldZ) == COLLISION) { flags |= FACING_X_AXIS; } } @@ -1271,9 +1273,9 @@ u16 actor_terrain_collision(Collision *collision, f32 boundingBoxSize, f32 x1, f sectionX = courseLengthX / GRID_SIZE; sectionZ = courseLengthZ / GRID_SIZE; - sectionIndexX = (x1 - gCourseMinX) / sectionX; - sectionIndexZ = (z1 - gCourseMinZ) / sectionZ; - + sectionIndexX = (newX - gCourseMinX) / sectionX; + sectionIndexZ = (newZ - gCourseMinZ) / sectionZ; + if (sectionIndexX < 0) { return 0; } @@ -1306,7 +1308,7 @@ u16 actor_terrain_collision(Collision *collision, f32 boundingBoxSize, f32 x1, f if ((gCollisionMesh[collisionIndex].flags & FACING_Y_AXIS)) { if ((flags & FACING_Y_AXIS) == 0) { if (collisionIndex != collision->meshIndexZX) { - if (is_colliding_with_drivable_surface(collision, boundingBoxSize, x1, y1, z1, collisionIndex, x2, y2, z2) == 1) { + if (is_colliding_with_drivable_surface(collision, boundingBoxSize, newX, newY, newZ, collisionIndex, oldX, oldY, oldZ) == COLLISION) { flags |= FACING_Y_AXIS; } } @@ -1314,14 +1316,14 @@ u16 actor_terrain_collision(Collision *collision, f32 boundingBoxSize, f32 x1, f } else if ((gCollisionMesh[collisionIndex].flags & FACING_X_AXIS) != 0) { if ((flags & FACING_X_AXIS) == 0) { if (collisionIndex != collision->meshIndexZY) { - if (is_colliding_with_wall1(collision, boundingBoxSize, x1, y1, z1, collisionIndex, x2, y2, z2) == 1) { + if (is_colliding_with_wall1(collision, boundingBoxSize, newX, newY, newZ, collisionIndex, oldX, oldY, oldZ) == COLLISION) { flags |= FACING_X_AXIS; } } } } else if ((flags & FACING_Z_AXIS) == 0) { if (collisionIndex != collision->meshIndexYX) { - if (is_colliding_with_wall2(collision, boundingBoxSize, x1, y1, z1, collisionIndex, x2, y2, z2) == 1) { + if (is_colliding_with_wall2(collision, boundingBoxSize, newX, newY, newZ, collisionIndex, oldX, oldY, oldZ) == COLLISION) { flags |= FACING_Z_AXIS; } } @@ -2107,7 +2109,7 @@ void subtract_scaled_vector(Vec3f pos1, f32 boundingBoxSize, Vec3f pos2) { pos2[2] -= pos1[2] * boundingBoxSize; } -u16 process_collision(Player *player, KartTyre *tyre, f32 tyre2X, f32 tyre2Y, f32 tyre2Z) { +u16 player_terrain_collision(Player *player, KartTyre *tyre, f32 tyre2X, f32 tyre2Y, f32 tyre2Z) { Collision wtf; Collision *collision = &wtf; UNUSED s32 pad; diff --git a/src/racing/collision.h b/src/racing/collision.h index b93e4b4d4..7f07afc55 100644 --- a/src/racing/collision.h +++ b/src/racing/collision.h @@ -13,7 +13,7 @@ s32 check_collision_zx(Collision*, f32, f32, f32, f32, u16); s32 check_collision_yx(Collision*, f32, f32, f32, f32, u16); s32 check_collision_zy(Collision*, f32, f32, f32, f32, u16); s8 get_surface_type(u16); -s16 get_section_id(u16); +s16 get_track_section_id(u16); s16 func_802ABD7C(u16); s16 func_802ABDB8(u16); s16 func_802ABDF4(u16); @@ -21,7 +21,7 @@ f32 calculate_surface_height(f32, f32, f32, u16); f32 func_802ABEAC(Collision*, Vec3f); void shell_collision(Collision *, Vec3f); void process_shell_collision(Vec3f, f32, Vec3f, f32); -u16 process_collision(Player*, KartTyre*, f32, f32, f32); +u16 player_terrain_collision(Player*, KartTyre*, f32, f32, f32); void adjust_pos_orthogonally(Vec3f, f32, Vec3f, f32); s32 detect_tyre_collision(KartTyre*); u16 actor_terrain_collision(Collision*, f32, f32, f32, f32, f32, f32, f32); diff --git a/src/racing/race_logic.c b/src/racing/race_logic.c index 5c9772b71..7d436b6dd 100644 --- a/src/racing/race_logic.c +++ b/src/racing/race_logic.c @@ -501,7 +501,7 @@ void start_race(void) { f32 func_8028EE8C(s32 arg0) { f32 temp_v0 = gPlayers[arg0].pos[2]; - f32 temp_v1 = gPlayers[arg0].copy_rotation_z; + f32 temp_v1 = gPlayers[arg0].oldPos[2]; f32 temp_f14 = D_8015F8D0[2] - temp_v0; f32 temp_f16 = temp_v1 - D_8015F8D0[2]; return gCourseTimer - ((COURSE_TIMER_ITER_f * temp_f14) / (temp_f14 + temp_f16)); diff --git a/src/racing/render_courses.c b/src/racing/render_courses.c index b4c8caf6f..0f9b7099e 100644 --- a/src/racing/render_courses.c +++ b/src/racing/render_courses.c @@ -116,8 +116,8 @@ void render_course_segments(uintptr_t addr, struct UnkStruct_800DC5EC *arg1) { arg1->playerDirection = var_a3; if (D_80152300[camera - camera1] == 1) { - sp1E = get_section_id(camera->collision.meshIndexZX); - temp_v0_3 = get_section_id(player->collision.meshIndexZX); + sp1E = get_track_section_id(camera->collision.meshIndexZX); + temp_v0_3 = get_track_section_id(player->collision.meshIndexZX); index = sp1E - temp_v0_3; if ((index < 2) && (index >= -1)) { if (sp1E == 255) { @@ -170,7 +170,7 @@ void render_course_segments(uintptr_t addr, struct UnkStruct_800DC5EC *arg1) { } } } else { - index = get_section_id(camera->collision.meshIndexZX); + index = get_track_section_id(camera->collision.meshIndexZX); if (camera->collision.surfaceDistance[2] > 30.0f) { index = arg1->pathCounter; } else if (index == 255) { diff --git a/src/render_objects.c b/src/render_objects.c index 4c2392431..6da17a5d5 100644 --- a/src/render_objects.c +++ b/src/render_objects.c @@ -3575,8 +3575,8 @@ void render_object_train_smoke_particle(s32 objectIndex, s32 cameraId) { } } -// Train smoke? -void render_object_train_smoke_particles(s32 cameraId) { +// Trains smoke particles. +void render_object_trains_smoke_particles(s32 cameraId) { UNUSED s32 pad; UNUSED s32 j; Camera *camera; diff --git a/src/render_objects.h b/src/render_objects.h index e0c3c9471..39a026e33 100644 --- a/src/render_objects.h +++ b/src/render_objects.h @@ -349,7 +349,7 @@ void func_80053D74(s32, s32, s32); void func_80053E6C(s32); void render_object_train_smoke_particle(s32, s32); -void render_object_train_smoke_particles(s32); +void render_object_trains_smoke_particles(s32); void render_object_paddle_boat_smoke_particle(s32, s32); void render_object_paddle_boat_smoke_particles(s32); void render_object_bowser_flame_particle(s32, s32); diff --git a/src/spawn_players.c b/src/spawn_players.c index 76b257157..3c0925909 100644 --- a/src/spawn_players.c +++ b/src/spawn_players.c @@ -113,14 +113,14 @@ void spawn_player(Player *player, s8 playerIndex, f32 startingRow, f32 startingC ret = spawn_actor_on_surface(startingRow, arg4 + 50.0f, startingColumn) + player->boundingBoxSize; player->pos[2] = startingColumn; player->pos[1] = ret; - player->copy_rotation_x = startingRow; - player->copy_rotation_y = ret; + player->oldPos[0] = startingRow; + player->oldPos[1] = ret; D_80164510[playerIndex] = ret; player->rotation[0] = 0; - player->copy_rotation_z = startingColumn; + player->oldPos[2] = startingColumn; player->unk_05C = 1.0f; player->unk_058 = 0.0f; player->unk_060 = 0.0f; diff --git a/src/update_objects.c b/src/update_objects.c index ff92d1a35..f249cb14a 100644 --- a/src/update_objects.c +++ b/src/update_objects.c @@ -1515,31 +1515,31 @@ void func_8007542C(s32 arg0) { } } -void func_80075574(s32 objectIndex, Vec3f arg1, f32 arg2) { +void init_train_smoke(s32 objectIndex, Vec3f pos, f32 velocity) { Object *object; UNUSED s32 pad[2]; init_object(objectIndex, 0); object = &gObjectList[objectIndex]; - object->origin_pos[0] = arg1[0]; - object->origin_pos[1] = arg1[1]; - object->origin_pos[2] = arg1[2]; - object->velocity[1] = arg2; + object->origin_pos[0] = pos[0]; + object->origin_pos[1] = pos[1]; + object->origin_pos[2] = pos[2]; + object->velocity[1] = velocity; object->type = random_int(0x0064U) + 0x1E; } -s32 func_800755FC(s32 arg0, Vec3f arg1, f32 arg2) { +s32 spawn_train_smoke(s32 trainIndex, Vec3f pos, f32 velocity) { s32 objectIndex; - if (arg0 == 0) { + if (trainIndex == 0) { objectIndex = add_unused_obj_index(gObjectParticle2, &gNextFreeObjectParticle2, gObjectParticle2_SIZE); if (objectIndex != NULL_OBJECT_ID) { - func_80075574(objectIndex, arg1, arg2); + init_train_smoke(objectIndex, pos, velocity); } } else { objectIndex = add_unused_obj_index(gObjectParticle3, &gNextFreeObjectParticle3, gObjectParticle3_SIZE); if (objectIndex != NULL_OBJECT_ID) { - func_80075574(objectIndex, arg1, arg2); + init_train_smoke(objectIndex, pos, velocity); } } return objectIndex; @@ -1635,31 +1635,31 @@ void update_train_smoke(void) { } } -void func_800759EC(s32 objectIndex, Vec3f arg1, f32 arg2) { +void init_ferry_smoke(s32 objectIndex, Vec3f pos, f32 velocity) { Object *object; init_object(objectIndex, 0); object = &gObjectList[objectIndex]; - object->origin_pos[0] = arg1[0]; - object->origin_pos[1] = arg1[1]; - object->origin_pos[2] = arg1[2]; - object->velocity[1] = arg2; + object->origin_pos[0] = pos[0]; + object->origin_pos[1] = pos[1]; + object->origin_pos[2] = pos[2]; + object->velocity[1] = velocity; object->type = 0x00FF; object->unk_0A2 = 0x0096; } -s32 func_80075A6C(s32 arg0, Vec3f arg1, f32 arg2) { +s32 spawn_ferry_smoke(s32 ferryIndex, Vec3f pos, f32 velocity) { s32 objectIndex; - if (arg0 == 0) { + if (ferryIndex == 0) { objectIndex = add_unused_obj_index(gObjectParticle2, &gNextFreeObjectParticle2, gObjectParticle2_SIZE); if (objectIndex != NULL_OBJECT_ID) { - func_800759EC(objectIndex, arg1, arg2); + init_ferry_smoke(objectIndex, pos, velocity); } } else { objectIndex = add_unused_obj_index(gObjectParticle3, &gNextFreeObjectParticle3, gObjectParticle3_SIZE); if (objectIndex != NULL_OBJECT_ID) { - func_800759EC(objectIndex, arg1, arg2); + init_ferry_smoke(objectIndex, pos, velocity); } } diff --git a/src/update_objects.h b/src/update_objects.h index 6e284ebf8..3e047bfd9 100644 --- a/src/update_objects.h +++ b/src/update_objects.h @@ -120,14 +120,14 @@ void func_80074FD8(s32); void func_800750D8(s32, s32, Vec3f, s32, s32); void func_80075304(Vec3f, s32, s32, s32); void func_8007542C(s32); -void func_80075574(s32, Vec3f, f32); -s32 func_800755FC(s32, Vec3f, f32); +void init_train_smoke(s32, Vec3f, f32); +s32 spawn_train_smoke(s32, Vec3f, f32); void func_80075698(s32); void func_80075714(s32); void update_train_smoke(void); void func_80075838(void); -void func_800759EC(s32, Vec3f, f32); -s32 func_80075A6C(s32, Vec3f, f32); +void init_ferry_smoke(s32, Vec3f, f32); +s32 spawn_ferry_smoke(s32, Vec3f, f32); void func_80075B08(s32); void func_80075B84(s32); void update_ferries_smoke_particle(void);