diff --git a/include/common_structs.h b/include/common_structs.h index 960d45177..d73292ffa 100644 --- a/include/common_structs.h +++ b/include/common_structs.h @@ -299,7 +299,7 @@ typedef struct { /* 0x00C0 */ s16 unk_0C0; /* 0x00C2 */ s16 unk_0C2; /* 0x00C4 */ s16 slopeAccel; - /* 0x00C6 */ s16 unk_0C6; + /* 0x00C6 */ s16 alpha; /* 0x00C8 */ s16 unk_0C8; /* 0x00CA */ s16 unk_0CA; /* 0x00CC */ Vec4s unk_0CC; diff --git a/include/defines.h b/include/defines.h index e2172b4e2..41878ec12 100644 --- a/include/defines.h +++ b/include/defines.h @@ -355,6 +355,14 @@ enum PLACE { FIRST_PLACE, SECOND_PLACE, THIRD_PLACE, FOURTH_PLACE }; * @brief durations of effects */ #define STAR_EFFECT_DURATION 0xA +#define BOO_EFFECT_DURATION 0x7 + +/** + * @brief alpha relates values + */ +#define ALPHA_MAX 0xFF +#define ALPHA_MIN 0x0 +#define ALPHA_BOO_EFFECT 0x60 /** * @brief shell state diff --git a/src/effects.c b/src/effects.c index 77cfb9d05..95cdfa140 100644 --- a/src/effects.c +++ b/src/effects.c @@ -23,7 +23,7 @@ s32 D_8018D900[8]; s16 D_8018D920[8]; s32 gPlayerStarEffectStartTime[8]; s32 gPlayerBooEffectStartTime[8]; -s32 D_8018D970[8]; +s32 gPlayerOtherScreensAlpha[8]; // Used for the alpha of the other screens in split-screen mode s32 D_8018D990[8]; UNUSED void func_unnamed(void) { @@ -1422,36 +1422,38 @@ void func_8008F86C(Player* player, s8 playerIndex) { func_800CAACC(playerIndex); } -void apply_boo_effect(Player* arg0, s8 playerIndex) { +void apply_boo_effect(Player* player, s8 playerIndex) { s32 time_elapsed; time_elapsed = ((s32) gCourseTimer) - gPlayerBooEffectStartTime[playerIndex]; - if (time_elapsed < 7) { - arg0->unk_0C6 -= 2; + if (time_elapsed < BOO_EFFECT_DURATION) { + player->alpha -= 2; - if (arg0->unk_0C6 < 0x61) { - arg0->unk_0C6 = 0x60; + if (player->alpha <= ALPHA_BOO_EFFECT) { + player->alpha = ALPHA_BOO_EFFECT; } - D_8018D970[playerIndex] -= 2; - if (D_8018D970[playerIndex] <= 0) { - D_8018D970[playerIndex] = 0; + // Player becomes invisible to other players + gPlayerOtherScreensAlpha[playerIndex] -= 2; + if (gPlayerOtherScreensAlpha[playerIndex] <= 0) { + gPlayerOtherScreensAlpha[playerIndex] = 0; } } else { - arg0->unk_0C6 += 4; - if (arg0->unk_0C6 >= 0xF0) { - arg0->unk_0C6 = 0xFF; - D_8018D970[playerIndex] = 0xFF; - arg0->effects &= ~0x80000000; - if ((arg0->type & 0x4000) != 0) { + // Player returns to normal visibility + player->alpha += 4; + if (player->alpha >= 0xF0) { + player->alpha = ALPHA_MAX; + gPlayerOtherScreensAlpha[playerIndex] = ALPHA_MAX; + player->effects &= ~0x80000000; + if ((player->type & 0x4000) != 0) { func_800CB064(playerIndex); } } - D_8018D970[playerIndex] += 8; - if (D_8018D970[playerIndex] >= 0xF0) { - D_8018D970[playerIndex] = 0xFF; - arg0->unk_0C6 = 0xFF; - arg0->effects &= ~0x80000000; - if ((arg0->type & 0x4000) != 0) { + gPlayerOtherScreensAlpha[playerIndex] += 8; + if (gPlayerOtherScreensAlpha[playerIndex] >= 0xF0) { + gPlayerOtherScreensAlpha[playerIndex] = ALPHA_MAX; + player->alpha = ALPHA_MAX; + player->effects &= ~0x80000000; + if ((player->type & 0x4000) != 0) { func_800CB064(playerIndex); } } @@ -1476,32 +1478,32 @@ void apply_boo_sound_effect(Player* player, s8 playerIndex) { player->effects |= BOO_EFFECT; player->soundEffects &= ~BOO_SOUND_EFFECT; gPlayerBooEffectStartTime[playerIndex] = gCourseTimer; - D_8018D970[playerIndex] = 0xFF; + gPlayerOtherScreensAlpha[playerIndex] = ALPHA_MAX; if ((player->type & PLAYER_HUMAN) != 0) { func_800CAFC0(playerIndex); } } -void func_8008FB30(Player* arg0, s8 arg1) { - arg0->unk_0C6 += 8; - if (arg0->unk_0C6 >= 0xF0) { - arg0->unk_0C6 = 0xFF; - D_8018D970[arg1] = 0xFF; +void func_8008FB30(Player* player, s8 playerIndex) { + player->alpha += 8; + if (player->alpha >= 0xF0) { + player->alpha = ALPHA_MAX; + gPlayerOtherScreensAlpha[playerIndex] = ALPHA_MAX; - arg0->effects &= ~0x80000000; - if ((arg0->type & 0x4000) != 0) { - func_800CB064(arg1); + player->effects &= ~0x80000000; + if ((player->type & 0x4000) != 0) { + func_800CB064(playerIndex); } } - D_8018D970[arg1] += 0x10; - if (D_8018D970[arg1] >= 0xE0) { - D_8018D970[arg1] = 0xFF; - arg0->unk_0C6 = 0xFF; - arg0->effects &= ~0x80000000; - if ((arg0->type & 0x4000) != 0) { - func_800CB064(arg1); + gPlayerOtherScreensAlpha[playerIndex] += 0x10; + if (gPlayerOtherScreensAlpha[playerIndex] >= 0xE0) { + gPlayerOtherScreensAlpha[playerIndex] = ALPHA_MAX; + player->alpha = ALPHA_MAX; + player->effects &= ~0x80000000; + if ((player->type & 0x4000) != 0) { + func_800CB064(playerIndex); } } } @@ -1517,9 +1519,9 @@ void func_8008FC1C(Player* player) { } void func_8008FC64(Player* player, s8 arg1) { - player->unk_0C6 -= 4; - if (player->unk_0C6 < 5) { - player->unk_0C6 = 0; + player->alpha -= 4; + if (player->alpha < 5) { + player->alpha = ALPHA_MIN; player->soundEffects &= 0xFBFFFFFF; player->soundEffects |= 0x08000000; player->type |= PLAYER_UNKNOWN_0x40; @@ -1529,14 +1531,14 @@ void func_8008FC64(Player* player, s8 arg1) { } } -void func_8008FCDC(Player* player, s8 arg1) { - player->unk_0C6 += 2; - if (player->unk_0C6 >= 0xF0) { - player->unk_0C6 = 0xFF; +void func_8008FCDC(Player* player, s8 playerIndex) { + player->alpha += 2; + if (player->alpha >= 0xF0) { + player->alpha = ALPHA_MAX; player->soundEffects &= ~0x08000000; } - func_80056A40(arg1, (u32) player->unk_0C6); + func_80056A40(playerIndex, (u32) player->alpha); } void func_8008FD4C(Player* player, UNUSED s8 arg1) { @@ -1850,7 +1852,7 @@ void func_80090970(Player* player, s8 playerId, s8 arg2) { if ((D_801652A0[playerId] + 40.0f) <= player->pos[1]) { player->unk_222 = 1; player->unk_0CA |= 4; - player->unk_0C6 = 0x00FF; + player->alpha = 0x00FF; } } } else if ((player->unk_0CA & 2) == 2) { @@ -1859,7 +1861,7 @@ void func_80090970(Player* player, s8 playerId, s8 arg2) { if ((player->unk_074 + 40.0f) <= player->pos[1]) { player->unk_222 = 1; player->unk_0CA |= 4; - player->unk_0C6 = 0x00FF; + player->alpha = 0x00FF; } } if ((player->effects & BOO_EFFECT) == BOO_EFFECT) { @@ -1872,17 +1874,17 @@ void func_80090970(Player* player, s8 playerId, s8 arg2) { } if ((player->unk_0CA & 1) == 1) { move_f32_towards(&player->pos[1], D_801652A0[playerId] + 40.0f, 0.02f); - player->unk_0C6 -= 8; - if (player->unk_0C6 < 9) { - player->unk_0C6 = 0; + player->alpha -= 8; + if (player->alpha < 9) { + player->alpha = 0; player->unk_222 = 2; player->unk_0CA &= ~0x0001; } } else { 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; + player->alpha -= 8; + if (player->alpha < 9) { + player->alpha = 0; player->unk_222 = 2; } } @@ -1908,9 +1910,9 @@ void func_80090970(Player* player, s8 playerId, s8 arg2) { player->pos[2] = sp44[2]; player->pos[2] = player->pos[2] + coss((playerId * 0x1C70) - player->rotation[1]) * -5.0f; player->pos[0] = player->pos[0] + sins((playerId * 0x1C70) - player->rotation[1]) * -5.0f; - player->unk_0C6 += 8; - if (player->unk_0C6 >= 0xF0) { - player->unk_0C6 = 0x00FF; + player->alpha += 8; + if (player->alpha >= 0xF0) { + player->alpha = 0x00FF; player->unk_222 = 4; player->unk_0CA &= ~0x0004; player->unk_0C8 = 0; diff --git a/src/effects.h b/src/effects.h index bcf854298..5e8588770 100644 --- a/src/effects.h +++ b/src/effects.h @@ -127,7 +127,7 @@ extern s32 D_8018D900[]; extern s16 D_8018D920[]; extern s32 gPlayerStarEffectStartTime[]; extern s32 gPlayerBooEffectStartTime[]; -extern s32 D_8018D970[]; +extern s32 gPlayerOtherScreensAlpha[]; extern s32 D_8018D990[]; /* This is where I'd put my static data, if I had any */ diff --git a/src/player_controller.c b/src/player_controller.c index c5d5282c1..86eca4499 100644 --- a/src/player_controller.c +++ b/src/player_controller.c @@ -964,7 +964,7 @@ void func_80029B4C(Player* player, UNUSED f32 arg1, f32 arg2, UNUSED f32 arg3) { } } -void func_8002A194(Player* player, f32 arg1, f32 arg2, f32 arg3) { +void func_8002A194(Player* player, f32 x, f32 y, f32 z) { UNUSED s32 pad[2]; f32 temp_f12; f32 var_f20; @@ -981,28 +981,28 @@ void func_8002A194(Player* player, f32 arg1, f32 arg2, f32 arg3) { var_f20 = (((gCharacterSize[player->characterId] * 18) / 2) * player->size) - 1; } - player->tyres[FRONT_LEFT].pos[2] = (coss(temp_v1 + 0x2000) * var_f20) + arg3; - temp_f12 = (sins(temp_v1 + 0x2000) * var_f20) + arg1; + player->tyres[FRONT_LEFT].pos[2] = (coss(temp_v1 + 0x2000) * var_f20) + z; + temp_f12 = (sins(temp_v1 + 0x2000) * var_f20) + x; player->tyres[FRONT_LEFT].pos[0] = temp_f12; player->tyres[FRONT_LEFT].baseHeight = - calculate_surface_height(temp_f12, arg2, player->tyres[FRONT_LEFT].pos[2], player->collision.meshIndexZX); + calculate_surface_height(temp_f12, y, player->tyres[FRONT_LEFT].pos[2], player->collision.meshIndexZX); - player->tyres[FRONT_RIGHT].pos[2] = (coss(temp_v1 - 0x2000) * var_f20) + arg3; - temp_f12 = (sins(temp_v1 - 0x2000) * var_f20) + arg1; + player->tyres[FRONT_RIGHT].pos[2] = (coss(temp_v1 - 0x2000) * var_f20) + z; + temp_f12 = (sins(temp_v1 - 0x2000) * var_f20) + x; player->tyres[FRONT_RIGHT].pos[0] = temp_f12; player->tyres[FRONT_RIGHT].baseHeight = - calculate_surface_height(temp_f12, arg2, player->tyres[FRONT_RIGHT].pos[2], player->collision.meshIndexZX); + calculate_surface_height(temp_f12, y, player->tyres[FRONT_RIGHT].pos[2], player->collision.meshIndexZX); - player->tyres[BACK_LEFT].pos[2] = (coss(temp_v1 + 0x6000) * var_f20) + arg3; - temp_f12 = (sins(temp_v1 + 0x6000) * var_f20) + arg1; + player->tyres[BACK_LEFT].pos[2] = (coss(temp_v1 + 0x6000) * var_f20) + z; + temp_f12 = (sins(temp_v1 + 0x6000) * var_f20) + x; player->tyres[BACK_LEFT].pos[0] = temp_f12; player->tyres[BACK_LEFT].baseHeight = - calculate_surface_height(temp_f12, arg2, player->tyres[BACK_LEFT].pos[2], player->collision.meshIndexZX); + calculate_surface_height(temp_f12, y, player->tyres[BACK_LEFT].pos[2], player->collision.meshIndexZX); - player->tyres[BACK_RIGHT].pos[2] = (coss(temp_v1 - 0x6000) * var_f20) + arg3; - player->tyres[BACK_RIGHT].pos[0] = (sins(temp_v1 - 0x6000) * var_f20) + arg1; + player->tyres[BACK_RIGHT].pos[2] = (coss(temp_v1 - 0x6000) * var_f20) + z; + player->tyres[BACK_RIGHT].pos[0] = (sins(temp_v1 - 0x6000) * var_f20) + x; player->tyres[BACK_RIGHT].baseHeight = calculate_surface_height( - player->tyres[BACK_LEFT].pos[0], arg2, player->tyres[BACK_LEFT].pos[2], player->collision.meshIndexZX); + player->tyres[BACK_LEFT].pos[0], y, player->tyres[BACK_LEFT].pos[2], player->collision.meshIndexZX); if ((player->effects & 8) != 8) { player->unk_230 = (player->tyres[BACK_LEFT].baseHeight + player->tyres[FRONT_LEFT].baseHeight) / 2; @@ -1022,7 +1022,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->oldPos[1] - arg2; + temp_f0 = player->oldPos[1] - y; temp_v0 = func_802B7C40(temp_f0 / var_f20); if (temp_f0 >= 0.0f) { var_a1 = temp_v0 * 2; @@ -1538,9 +1538,9 @@ void func_8002B9CC(Player* player, s8 playerIndex, UNUSED s32 arg2) { } } } else { - temp_f0 = D_80165070[playerIndex][0] - player->velocity[0]; - temp_f2 = D_80165070[playerIndex][1] - player->velocity[1]; - temp_f14 = D_80165070[playerIndex][2] - player->velocity[2]; + temp_f0 = gPlayerLastVelocity[playerIndex][0] - player->velocity[0]; + temp_f2 = gPlayerLastVelocity[playerIndex][1] - player->velocity[1]; + temp_f14 = gPlayerLastVelocity[playerIndex][2] - player->velocity[2]; if (sqrtf((temp_f0 * temp_f0) + (temp_f2 * temp_f2) + (temp_f14 * temp_f14)) >= 4.2) { player->unk_08C /= 4; player->currentSpeed /= 4; @@ -1859,7 +1859,7 @@ void func_8002C7E4(Player* player, s8 playerIndex, s8 arg2) { } } -void func_8002C954(Player* player, s8 playerId, Vec3f arg2) { +void func_8002C954(Player* player, s8 playerId, Vec3f velocity) { f32 temp_f0; f32 var_f14; f32 xdist; @@ -1894,10 +1894,10 @@ void func_8002C954(Player* player, s8 playerId, Vec3f arg2) { player_decelerate_alternative(player, 18.0f); } if ((player->type & PLAYER_HUMAN) == PLAYER_HUMAN) { - xdist = D_80165070[playerId][0] - arg2[0]; - var_f14 = D_80165070[playerId][1] - arg2[1]; + xdist = gPlayerLastVelocity[playerId][0] - velocity[0]; + var_f14 = gPlayerLastVelocity[playerId][1] - velocity[1]; ydist = var_f14; // okay - zdist = D_80165070[playerId][2] - arg2[2]; + zdist = gPlayerLastVelocity[playerId][2] - velocity[2]; var_f14 = sqrtf((xdist * xdist) + (ydist * ydist) + (zdist * zdist)) / 3; if (var_f14 >= 1.0) { var_f14 = 1.0f; @@ -2063,12 +2063,12 @@ void func_8002D268(Player* player, UNUSED Camera* camera, s8 screenId, s8 player s32 temp3; f32 temp_f2_2; UNUSED s32 pad[8]; - f32 spB4; - f32 spB0; - f32 spAC; - f32 temp_var; + f32 gravityX; + f32 gravityY; + f32 gravityZ; + f32 surfaceDistance; UNUSED s32 pad2; - Vec3f sp98; + Vec3f newVelocity; Vec3f sp8C; UNUSED s32 pad3[3]; s32 sp7C = 0; @@ -2096,31 +2096,31 @@ void func_8002D268(Player* player, UNUSED Camera* camera, s8 screenId, s8 player player->unk_064[2] *= -1.0f; } if ((player->tyres[BACK_LEFT].surfaceType == ASPHALT) && (player->tyres[BACK_RIGHT].surfaceType == ASPHALT)) { - spB4 = (-1 * (player->unk_064[0] + sp16C[0])) + + gravityX = (-1 * (player->unk_064[0] + sp16C[0])) + ((-player->collision.orientationVector[0] * player->kartGravity) * 0.925); - spB0 = (-player->collision.orientationVector[1] * player->kartGravity); - spAC = (-1 * (player->unk_064[2] + sp16C[2])) + + gravityY = (-player->collision.orientationVector[1] * player->kartGravity); + gravityZ = (-1 * (player->unk_064[2] + sp16C[2])) + ((-player->collision.orientationVector[2] * player->kartGravity) * 0.925); } else { temp3 = (((player->speed / 18.0f) * 216.0f) / 10.0f); if (temp3 >= 10) { temp3 = 10; } - spB4 = -1 * (player->unk_064[0] + sp16C[0]) + + gravityX = -1 * (player->unk_064[0] + sp16C[0]) + ((-player->collision.orientationVector[0] * player->kartGravity) * sp104[temp3]); - spB0 = (-player->collision.orientationVector[1] * player->kartGravity); - spAC = -1 * (player->unk_064[2] + sp16C[2]) + + gravityY = (-player->collision.orientationVector[1] * player->kartGravity); + gravityZ = -1 * (player->unk_064[2] + sp16C[2]) + ((-player->collision.orientationVector[2] * player->kartGravity) * sp104[temp3]); } if (((player->effects & 8) != 8) && ((player->effects & 0x20) == 0x20)) { - spB4 = 0 * (player->unk_064[0] + sp16C[0]); - spB0 = -1 * player->kartGravity / 4; - spAC = 0 * (player->unk_064[2] + sp16C[2]); + gravityX = 0 * (player->unk_064[0] + sp16C[0]); + gravityY = -1 * player->kartGravity / 4; + gravityZ = 0 * (player->unk_064[2] + sp16C[2]); } if ((player->effects & 8) == 8) { - spB4 = 0 * (player->unk_064[0] + sp16C[0]); - spB0 = -1 * player->kartGravity; - spAC = 0 * (player->unk_064[2] + sp16C[2]); + gravityX = 0 * (player->unk_064[0] + sp16C[0]); + gravityY = -1 * player->kartGravity; + gravityZ = 0 * (player->unk_064[2] + sp16C[2]); } 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)); @@ -2137,50 +2137,50 @@ void func_8002D268(Player* player, UNUSED Camera* camera, s8 screenId, s8 player } sp178[1] = 0.0f; mtxf_translate_vec3f_mat3(sp178, player->orientationMatrix); - spB4 += sp178[0]; - spAC += sp178[2]; + gravityX += sp178[0]; + gravityZ += sp178[2]; func_8002C7E4(player, playerId, screenId); sp184[2] = func_80030150(player, playerId); mtxf_translate_vec3f_mat3(sp184, player->orientationMatrix); - sp98[0] = player->velocity[0]; - sp98[1] = player->velocity[1]; - sp98[2] = player->velocity[2]; + newVelocity[0] = player->velocity[0]; + newVelocity[1] = player->velocity[1]; + newVelocity[2] = player->velocity[2]; if (((player->unk_10C < 3) && (((s32) player->unk_256) < 3)) || ((player->effects & BOOST_EFFECT) == BOOST_EFFECT)) { if (((player->unk_07C >> 16) >= 0x28) || ((player->unk_07C >> 16) < (-0x27))) { - sp98[0] += (((((f64) ((sp184[0] + spB4) + sp160[0])) - (sp98[0] * (0.12 * ((f64) player->kartFriction)))) / + newVelocity[0] += (((((f64) ((sp184[0] + gravityX) + sp160[0])) - (newVelocity[0] * (0.12 * ((f64) player->kartFriction)))) / 6000.0) / (((((f64) player->unk_20C) * 0.6) + 1.0) + sp7C)); - sp98[2] += (((((f64) ((sp184[2] + spAC) + sp160[2])) - (sp98[2] * (0.12 * ((f64) player->kartFriction)))) / + newVelocity[2] += (((((f64) ((sp184[2] + gravityZ) + sp160[2])) - (newVelocity[2] * (0.12 * ((f64) player->kartFriction)))) / 6000.0) / (((((f64) player->unk_20C) * 0.6) + 1.0) + sp7C)); } else { - sp98[0] += (((((f64) ((sp184[0] + spB4) + sp160[0])) - (sp98[0] * (0.12 * ((f64) player->kartFriction)))) / + newVelocity[0] += (((((f64) ((sp184[0] + gravityX) + sp160[0])) - (newVelocity[0] * (0.12 * ((f64) player->kartFriction)))) / 6000.0) / (sp7C + 1)); - sp98[2] += (((((f64) ((sp184[2] + spAC) + sp160[2])) - (sp98[2] * (0.12 * ((f64) player->kartFriction)))) / + newVelocity[2] += (((((f64) ((sp184[2] + gravityZ) + sp160[2])) - (newVelocity[2] * (0.12 * ((f64) player->kartFriction)))) / 6000.0) / (sp7C + 1)); } } else { - sp98[0] += - (((((f64) ((sp184[0] + spB4) + sp160[0])) - (sp98[0] * (0.12 * ((f64) player->kartFriction)))) / 6000.0) / + newVelocity[0] += + (((((f64) ((sp184[0] + gravityX) + sp160[0])) - (newVelocity[0] * (0.12 * ((f64) player->kartFriction)))) / 6000.0) / 30.0); - sp98[2] += - (((((f64) ((sp184[2] + spAC) + sp160[2])) - (sp98[2] * (0.12 * ((f64) player->kartFriction)))) / 6000.0) / + newVelocity[2] += + (((((f64) ((sp184[2] + gravityZ) + sp160[2])) - (newVelocity[2] * (0.12 * ((f64) player->kartFriction)))) / 6000.0) / 30.0); } - sp98[1] += - (((((f64) ((sp184[1] + spB0) + sp160[1])) - (sp98[1] * (0.12 * ((f64) player->kartFriction)))) / 6000.0) / + newVelocity[1] += + (((((f64) ((sp184[1] + gravityY) + sp160[1])) - (newVelocity[1] * (0.12 * ((f64) player->kartFriction)))) / 6000.0) / ((f64) player->unk_DAC)); if (((((player->unk_0CA & 2) == 2) || ((player->unk_0CA & 8) == 8)) || ((player->effects & HIT_EFFECT) == HIT_EFFECT)) || (player->unk_0CA & 1)) { - sp98[0] = 0.0f; - sp98[1] = 0.0f; - sp98[2] = 0.0f; + newVelocity[0] = 0.0f; + newVelocity[1] = 0.0f; + newVelocity[2] = 0.0f; } if ((player->unk_044 & 0x10) == 0x10) { player->unk_044 &= 0xFFEF; @@ -2218,8 +2218,8 @@ void func_8002D268(Player* player, UNUSED Camera* camera, s8 screenId, s8 player } player->effects |= 8; player->unk_0C2 += 1; - temp_var = player->collision.surfaceDistance[2]; - if (temp_var <= 0.0f) { + surfaceDistance = player->collision.surfaceDistance[2]; + if (surfaceDistance <= 0.0f) { player->effects = player->effects & (~2); player->effects = player->effects & (~8); if (player->unk_0C2 >= 35) { @@ -2268,24 +2268,24 @@ void func_8002D268(Player* player, UNUSED Camera* camera, s8 screenId, s8 player player->unk_0C2 = 0; player->kartHopVelocity = player->unk_0C2; } - temp_var = player->collision.surfaceDistance[2]; - if (temp_var <= 0.0f) { - func_8003F46C(player, sp8C, sp98, sp178, &temp_var, &nextX, &nextY, &nextZ); + surfaceDistance = player->collision.surfaceDistance[2]; + if (surfaceDistance <= 0.0f) { + func_8003F46C(player, sp8C, newVelocity, sp178, &surfaceDistance, &nextX, &nextY, &nextZ); } - temp_var = player->collision.surfaceDistance[0]; - if (temp_var < 0.0f) { - func_8003F734(player, sp8C, sp98, &temp_var, &nextX, &nextY, &nextZ); - func_8002C954(player, playerId, sp98); + surfaceDistance = player->collision.surfaceDistance[0]; + if (surfaceDistance < 0.0f) { + func_8003F734(player, sp8C, newVelocity, &surfaceDistance, &nextX, &nextY, &nextZ); + func_8002C954(player, playerId, newVelocity); } - temp_var = player->collision.surfaceDistance[1]; - if (temp_var < 0.0f) { - func_8003FBAC(player, sp8C, sp98, &temp_var, &nextX, &nextY, &nextZ); - func_8002C954(player, playerId, sp98); + surfaceDistance = player->collision.surfaceDistance[1]; + if (surfaceDistance < 0.0f) { + func_8003FBAC(player, sp8C, newVelocity, &surfaceDistance, &nextX, &nextY, &nextZ); + func_8002C954(player, playerId, newVelocity); } - temp_var = player->collision.surfaceDistance[0]; - if (temp_var >= 0.0f) { - temp_var = player->collision.surfaceDistance[1]; - if (temp_var >= 0.0f) { + surfaceDistance = player->collision.surfaceDistance[0]; + if (surfaceDistance >= 0.0f) { + surfaceDistance = player->collision.surfaceDistance[1]; + if (surfaceDistance >= 0.0f) { player->unk_046 &= 0xFFDF; if (player->unk_256 != 0) { player->unk_256++; @@ -2314,30 +2314,30 @@ void func_8002D268(Player* player, UNUSED Camera* camera, s8 screenId, s8 player } func_8002AE38(player, playerId, posX, posZ, nextX, nextZ); - temp2 = (sp98[0] * sp98[0]) + (sp98[2] * sp98[2]); + temp2 = (newVelocity[0] * newVelocity[0]) + (newVelocity[2] * newVelocity[2]); player->previousSpeed = player->speed; player->speed = sqrtf(temp2); if ((player->unk_08C <= 0.0f) && (player->speed <= 0.08) && (D_8018CE10[playerId].unk_04[0] == 0.0f) && (D_8018CE10[playerId].unk_04[2] == 0.0f)) { - sp98[0] = sp98[0] + (-1 * sp98[0]); - sp98[2] = sp98[2] + (-1 * sp98[2]); + newVelocity[0] = newVelocity[0] + (-1 * newVelocity[0]); + newVelocity[2] = newVelocity[2] + (-1 * newVelocity[2]); } else { player->pos[0] = nextX; player->pos[2] = nextZ; } player->pos[1] = nextY; if ((player->type & PLAYER_HUMAN) && (!(player->type & PLAYER_CPU))) { - func_8002BB9C(player, &nextX, &nextZ, screenId, playerId, sp98); + func_8002BB9C(player, &nextX, &nextZ, screenId, playerId, newVelocity); } player->unk_064[0] = sp178[0]; player->unk_064[2] = sp178[2]; - player->velocity[0] = sp98[0]; - player->velocity[1] = sp98[1]; - player->velocity[2] = sp98[2]; - D_80165070[playerId][0] = sp98[0]; - D_80165070[playerId][1] = sp98[1]; - D_80165070[playerId][2] = sp98[2]; + player->velocity[0] = newVelocity[0]; + player->velocity[1] = newVelocity[1]; + player->velocity[2] = newVelocity[2]; + gPlayerLastVelocity[playerId][0] = newVelocity[0]; + gPlayerLastVelocity[playerId][1] = newVelocity[1]; + gPlayerLastVelocity[playerId][2] = newVelocity[2]; if ((player->type & PLAYER_HUMAN) == PLAYER_HUMAN) { if (gKartTopSpeedTable[player->characterId] < player->speed) { temp = gKartTopSpeedTable[player->characterId] / player->speed; @@ -2382,22 +2382,22 @@ void func_8002E594(Player* player, UNUSED Camera* camera, s8 screenId, s8 player Vec3f spEC = { 0.0f, 0.0f, 1.0f }; Vec3f spE0 = { 0.0f, 0.0f, 0.0f }; Vec3f spD4 = { 0.0f, 0.0f, 0.0f }; - f32 spD0; - f32 spCC; - f32 spC8; - f32 temp_f0_6; + f32 nextX; + f32 nextY; + f32 nextZ; + f32 topSpeedMultiplier; UNUSED s32 pad; f32 posX; f32 posY; f32 posZ; UNUSED s32 pad2[12]; - f32 sp80; - f32 sp7C; - f32 sp78; - f32 sp74; + f32 gravityX; + f32 gravityY; + f32 gravityZ; + f32 surfaceDistance; UNUSED s32 pad3[4]; f32 temp; - Vec3f sp54; + Vec3f newVelocity; Vec3f sp48; s16 sp46; func_8002B830(player, playerId, screenId); @@ -2416,13 +2416,13 @@ void func_8002E594(Player* player, UNUSED Camera* camera, s8 screenId, s8 player func_8002FCA8(player, playerId); if ((((player->effects & 0x80) == 0x80) || ((player->effects & 0x40) == 0x40)) || ((player->effects & 0x20000) == 0x20000)) { - sp80 = -1 * (player->unk_064[0]) + (((-player->collision.orientationVector[0]) * player->kartGravity) * 0.1); - sp7C = (-player->collision.orientationVector[1]) * player->kartGravity; - sp78 = -1 * (player->unk_064[2]) + (((-player->collision.orientationVector[2]) * player->kartGravity) * 0.1); + gravityX = -1 * (player->unk_064[0]) + (((-player->collision.orientationVector[0]) * player->kartGravity) * 0.1); + gravityY = (-player->collision.orientationVector[1]) * player->kartGravity; + gravityZ = -1 * (player->unk_064[2]) + (((-player->collision.orientationVector[2]) * player->kartGravity) * 0.1); } else { - sp80 = -1 * player->unk_064[0]; - sp7C = -1 * player->kartGravity; - sp78 = -1 * player->unk_064[2]; + gravityX = -1 * player->unk_064[0]; + gravityY = -1 * player->kartGravity; + gravityZ = -1 * player->unk_064[2]; } func_8002C7E4(player, playerId, screenId); if (sp46 == 1) { @@ -2440,28 +2440,28 @@ void func_8002E594(Player* player, UNUSED Camera* camera, s8 screenId, s8 player } else { mtxf_translate_vec3f_mat3(spEC, player->orientationMatrix); } - sp54[0] = player->velocity[0]; - sp54[1] = player->velocity[1]; - sp54[2] = player->velocity[2]; + newVelocity[0] = player->velocity[0]; + newVelocity[1] = player->velocity[1]; + newVelocity[2] = player->velocity[2]; if ((player->unk_10C < 3) && ((player->unk_256) < 3) && ((player->effects & 0x400) != 0x400) && ((player->effects & UNKNOWN_EFFECT_0x1000000) != UNKNOWN_EFFECT_0x1000000) && ((player->effects & HIT_BY_ITEM_EFFECT) != HIT_BY_ITEM_EFFECT)) { - sp54[0] += (((((spEC[0] + sp80) + spD4[0])) - (sp54[0] * (0.12 * player->kartFriction))) / 6000) / + newVelocity[0] += (((((spEC[0] + gravityX) + spD4[0])) - (newVelocity[0] * (0.12 * player->kartFriction))) / 6000) / ((player->unk_20C * 5.0f) + 1.0f); - sp54[2] += (((((spEC[2] + sp78) + spD4[2])) - (sp54[2] * (0.12 * player->kartFriction))) / 6000) / + newVelocity[2] += (((((spEC[2] + gravityZ) + spD4[2])) - (newVelocity[2] * (0.12 * player->kartFriction))) / 6000) / ((player->unk_20C * 5.0f) + 1.0f); } else { - sp54[0] += - ((((f64) (spEC[0] + sp80 + spD4[0]) - (sp54[0] * (0.2 * (f64) player->kartFriction))) / 6000) * 0.08); - sp54[2] += - ((((f64) (spEC[2] + sp78 + spD4[2]) - (sp54[2] * (0.2 * (f64) player->kartFriction))) / 6000) * 0.08); + newVelocity[0] += + ((((f64) (spEC[0] + gravityX + spD4[0]) - (newVelocity[0] * (0.2 * (f64) player->kartFriction))) / 6000) * 0.08); + newVelocity[2] += + ((((f64) (spEC[2] + gravityZ + spD4[2]) - (newVelocity[2] * (0.2 * (f64) player->kartFriction))) / 6000) * 0.08); } - sp54[1] += (((((spEC[1] + sp7C) + spD4[1])) - (sp54[1] * (0.12 * player->kartFriction))) / 6000) / player->unk_DAC; + newVelocity[1] += (((((spEC[1] + gravityY) + spD4[1])) - (newVelocity[1] * (0.12 * player->kartFriction))) / 6000) / player->unk_DAC; if (((player->unk_0CA & 2) == 2) || ((player->unk_0CA & 8) == 8)) { - sp54[0] = 0.0f; - sp54[1] = 0.0f; - sp54[2] = 0.0f; + newVelocity[0] = 0.0f; + newVelocity[1] = 0.0f; + newVelocity[2] = 0.0f; } posX = player->pos[0]; posY = player->pos[1]; @@ -2471,20 +2471,20 @@ void func_8002E594(Player* player, UNUSED Camera* camera, s8 screenId, s8 player 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]; + 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]; func_8002AAC0(player); - spCC += player->kartHopVelocity; - actor_terrain_collision(&player->collision, player->boundingBoxSize, spD0, spCC, spC8, player->oldPos[0], + nextY += player->kartHopVelocity; + actor_terrain_collision(&player->collision, player->boundingBoxSize, nextX, nextY, nextZ, player->oldPos[0], player->oldPos[1], player->oldPos[2]); player->effects |= 8; player->unk_0C2 += 1; player->unk_058 = 0.0f; player->unk_060 = 0.0f; player->unk_05C = 1.0f; - sp74 = player->collision.surfaceDistance[2]; - if (sp74 <= 0.0f) { + surfaceDistance = player->collision.surfaceDistance[2]; + if (surfaceDistance <= 0.0f) { player->effects &= ~2; player->effects &= ~8; if ((((player->effects & 0x400) != 0x400) && @@ -2548,26 +2548,26 @@ void func_8002E594(Player* player, UNUSED Camera* camera, s8 screenId, s8 player } player->kartHopVelocity = (f32) player->unk_0C2; } - sp74 = player->collision.surfaceDistance[2]; - if (sp74 <= 0.0f) { - func_8003F46C(player, sp48, sp54, spE0, &sp74, &spD0, &spCC, &spC8); + surfaceDistance = player->collision.surfaceDistance[2]; + if (surfaceDistance <= 0.0f) { + func_8003F46C(player, sp48, newVelocity, spE0, &surfaceDistance, &nextX, &nextY, &nextZ); } - sp74 = player->collision.surfaceDistance[0]; - if (sp74 < 0.0f) { - func_8003F734(player, sp48, sp54, &sp74, &spD0, &spCC, &spC8); - func_8002C954(player, playerId, sp54); + surfaceDistance = player->collision.surfaceDistance[0]; + if (surfaceDistance < 0.0f) { + func_8003F734(player, sp48, newVelocity, &surfaceDistance, &nextX, &nextY, &nextZ); + func_8002C954(player, playerId, newVelocity); player_decelerate_alternative(player, 6.0f); } - sp74 = player->collision.surfaceDistance[1]; - if (sp74 < 0.0f) { - func_8003FBAC(player, sp48, sp54, &sp74, &spD0, &spCC, &spC8); - func_8002C954(player, playerId, sp54); + surfaceDistance = player->collision.surfaceDistance[1]; + if (surfaceDistance < 0.0f) { + func_8003FBAC(player, sp48, newVelocity, &surfaceDistance, &nextX, &nextY, &nextZ); + func_8002C954(player, playerId, newVelocity); player_decelerate_alternative(player, 6.0f); } - sp74 = player->collision.surfaceDistance[0]; - if (sp74 >= 0.0f) { - sp74 = player->collision.surfaceDistance[1]; - if (sp74 >= 0.0f) { + surfaceDistance = player->collision.surfaceDistance[0]; + if (surfaceDistance >= 0.0f) { + surfaceDistance = player->collision.surfaceDistance[1]; + if (surfaceDistance >= 0.0f) { player->unk_046 &= 0xFFDF; if (player->unk_256 != 0) { player->unk_256++; @@ -2587,70 +2587,70 @@ void func_8002E594(Player* player, UNUSED Camera* camera, s8 screenId, s8 player (player->effects & UNKNOWN_EFFECT_0x10000)) { func_8008F5A4(player, playerId); } - player->unk_074 = calculate_surface_height(spD0, spCC, spC8, 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, spD0, spCC, spC8); + func_80029B4C(player, nextX, nextY, nextZ); } else { - func_8002A194(player, spD0, spCC, spC8); + func_8002A194(player, nextX, nextY, nextZ); } - func_8002AE38(player, playerId, posX, posZ, spD0, spC8); - temp = (sp54[0] * sp54[0]) + (sp54[2] * sp54[2]); + func_8002AE38(player, playerId, posX, posZ, nextX, nextZ); + temp = (newVelocity[0] * newVelocity[0]) + (newVelocity[2] * newVelocity[2]); player->previousSpeed = player->speed; player->speed = sqrtf(temp); if ((((player->effects & 0x400) != 0x400) && (player->unk_08C <= 0) && (player->speed < 0.13)) || (((player->effects & 0x400) != 0x400) && (player->unk_08C <= 0) && (player->speed < 0.20) && ((player->effects & 1) == 1))) { - sp54[0] = sp54[0] + (-1 * sp54[0]); - sp54[2] = sp54[2] + (-1 * sp54[2]); + newVelocity[0] = newVelocity[0] + (-1 * newVelocity[0]); + newVelocity[2] = newVelocity[2] + (-1 * newVelocity[2]); } else { - player->pos[0] = spD0; - player->pos[2] = spC8; + player->pos[0] = nextX; + player->pos[2] = nextZ; } - player->pos[1] = spCC; + player->pos[1] = nextY; player->unk_064[0] = spE0[0]; player->unk_064[2] = spE0[2]; - player->velocity[0] = sp54[0]; - player->velocity[1] = sp54[1]; - player->velocity[2] = sp54[2]; + player->velocity[0] = newVelocity[0]; + player->velocity[1] = newVelocity[1]; + player->velocity[2] = newVelocity[2]; if ((player->type & PLAYER_HUMAN) == PLAYER_HUMAN) { if (gKartTopSpeedTable[player->characterId] < player->speed) { - temp_f0_6 = gKartTopSpeedTable[player->characterId] / player->speed; - player->velocity[0] *= temp_f0_6; - player->velocity[1] *= temp_f0_6; - player->velocity[2] *= temp_f0_6; + topSpeedMultiplier = gKartTopSpeedTable[player->characterId] / player->speed; + player->velocity[0] *= topSpeedMultiplier; + player->velocity[1] *= topSpeedMultiplier; + player->velocity[2] *= topSpeedMultiplier; player->speed = gKartTopSpeedTable[player->characterId]; } } func_8002C4F8(player, playerId); } -void control_cpu_movement(Player* player, UNUSED Camera* camera, s8 arg2, s8 playerId) { +void control_cpu_movement(Player* player, UNUSED Camera* camera, s8 screenId, s8 playerId) { Vec3f spF4 = { 0.0f, 0.0f, 1.0f }; UNUSED Vec3f spE8 = { 0.0f, 0.0f, 0.0f }; Vec3f spDC = { 0.0f, 0.0f, 0.0f }; Vec3f spD0 = { 0.0f, 0.0f, 0.0f }; - f32 spCC; + f32 nextX; UNUSED s32 pad; - f32 spC4; + f32 nextZ; UNUSED s32 pad2[15]; f32 sp84; UNUSED s32 pad3; f32 sp7C; UNUSED s32 pad4[2]; - Vec3f sp68; + Vec3f newVelocity; UNUSED f32 pad5[7]; f32 toSqrt; - f32 temp_f0_2; - f32 test; + f32 topSpeedMultiplier; + f32 nextY; player->effects |= UNKNOWN_EFFECT_0x1000; player->unk_044 |= 0x10; - test = gPlayerPathY[playerId]; + nextY = gPlayerPathY[playerId]; player->unk_204 = 0; - player->effects &= ~0x10; - func_8002B830(player, playerId, arg2); - apply_effect(player, playerId, arg2); + player->effects &= ~UNKNOWN_EFFECT_0x10; + func_8002B830(player, playerId, screenId); + apply_effect(player, playerId, screenId); sp84 = 0 * player->unk_064[0] + spDC[0]; sp7C = 0 * player->unk_064[2] + spDC[2]; player->unk_10C = 0; @@ -2658,16 +2658,16 @@ void control_cpu_movement(Player* player, UNUSED Camera* camera, s8 arg2, s8 pla player->effects &= ~0x8000; spF4[2] = func_80030150(player, playerId); mtxf_translate_vec3f_mat3(spF4, player->orientationMatrix); - sp68[0] = player->velocity[0]; - sp68[1] = 0; - 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; + newVelocity[0] = player->velocity[0]; + newVelocity[1] = 0; + newVelocity[2] = player->velocity[2]; + newVelocity[0] += (((spF4[0] + sp84) + spD0[0]) - (newVelocity[0] * (0.12 * player->kartFriction))) / 6000.0; + newVelocity[2] += (((spF4[2] + sp7C) + spD0[2]) - (newVelocity[2] * (0.12 * player->kartFriction))) / 6000.0; player->oldPos[0] = player->pos[0]; - player->oldPos[1] = test; + player->oldPos[1] = nextY; player->oldPos[2] = player->pos[2]; - spCC = player->pos[0] + player->velocity[0]; - spC4 = player->pos[2] + player->velocity[2]; + nextX = player->pos[0] + player->velocity[0]; + nextZ = player->pos[2] + player->velocity[2]; player->unk_0C0 = 0; player->kartHopJerk = 0; player->kartHopAcceleration = 0; @@ -2679,25 +2679,25 @@ void control_cpu_movement(Player* player, UNUSED Camera* camera, s8 arg2, s8 pla player->effects &= ~8; player->slopeAccel = 0; player->unk_206 = 0; - toSqrt = (sp68[0] * sp68[0]) + (sp68[2] * sp68[2]); + toSqrt = (newVelocity[0] * newVelocity[0]) + (newVelocity[2] * newVelocity[2]); player->previousSpeed = player->speed; player->speed = sqrtf(toSqrt); - player->pos[0] = spCC; - player->pos[2] = spC4; - player->pos[1] = test; + player->pos[0] = nextX; + player->pos[2] = nextZ; + player->pos[1] = nextY; player->unk_064[0] = 0; player->unk_064[2] = 0; - player->velocity[0] = sp68[0]; - player->velocity[1] = sp68[1]; - player->velocity[2] = sp68[2]; - D_80165070[playerId][0] = sp68[0]; - D_80165070[playerId][1] = sp68[1]; - D_80165070[playerId][2] = sp68[2]; + player->velocity[0] = newVelocity[0]; + player->velocity[1] = newVelocity[1]; + player->velocity[2] = newVelocity[2]; + gPlayerLastVelocity[playerId][0] = newVelocity[0]; + gPlayerLastVelocity[playerId][1] = newVelocity[1]; + gPlayerLastVelocity[playerId][2] = newVelocity[2]; if (gKartTopSpeedTable[player->characterId] < player->speed) { - temp_f0_2 = gKartTopSpeedTable[player->characterId] / player->speed; - player->velocity[0] *= temp_f0_2; - player->velocity[1] *= temp_f0_2; - player->velocity[2] *= temp_f0_2; + topSpeedMultiplier = gKartTopSpeedTable[player->characterId] / player->speed; + player->velocity[0] *= topSpeedMultiplier; + player->velocity[1] *= topSpeedMultiplier; + player->velocity[2] *= topSpeedMultiplier; player->speed = gKartTopSpeedTable[player->characterId]; } } @@ -2707,21 +2707,22 @@ void func_8002F730(Player* player, UNUSED Camera* camera, UNUSED s8 screenId, s8 Vec3f spE8 = { 0.0f, 0.0f, 0.0f }; UNUSED Vec3f spDC = { 0.0f, 0.0f, 0.0f }; Vec3f spD0 = { 0.0f, 0.0f, 0.0f }; - f32 spCC; - f32 spC8; - f32 spC4; + // Next position is current position + current velocity + f32 nextX; + f32 nextY; + f32 nextZ; - f32 spC0; - f32 sp44; - f32 spB8; - f32 temp_f0_2; + f32 posX; + f32 posY; + f32 posZ; + f32 topSpeedMultiplier; UNUSED s32 pad[11]; f32 sp84; UNUSED s32 pad2; f32 sp7C; - f32 sp78; + f32 surfaceDistance; f32 sqrt; - Vec3f sp68; + Vec3f newVelocity; Vec3f sp5C; UNUSED s32 pad3[3]; @@ -2732,80 +2733,80 @@ void func_8002F730(Player* player, UNUSED Camera* camera, UNUSED s8 screenId, s8 mtxf_translate_vec3f_mat3(spF4, player->orientationMatrix); - sp68[0] = player->velocity[0]; - sp68[1] = player->velocity[1]; - sp68[2] = player->velocity[2]; + newVelocity[0] = player->velocity[0]; + newVelocity[1] = player->velocity[1]; + newVelocity[2] = player->velocity[2]; - sp68[0] += (((f64) (spF4[0] + sp84) - (sp68[0] * 780.0)) / 6500.0); - sp68[2] += (((f64) (spF4[2] + sp7C) - (sp68[2] * 780.0)) / 6500.0); - sp68[1] += (((f64) (spF4[1] + -1100.0f) - (sp68[1] * 780.0)) / 6500.0); + newVelocity[0] += (((f64) (spF4[0] + sp84) - (newVelocity[0] * 780.0)) / 6500.0); + newVelocity[2] += (((f64) (spF4[2] + sp7C) - (newVelocity[2] * 780.0)) / 6500.0); + newVelocity[1] += (((f64) (spF4[1] + -1100.0f) - (newVelocity[1] * 780.0)) / 6500.0); - spC0 = player->pos[0]; - sp44 = player->pos[1]; - spB8 = player->pos[2]; + posX = player->pos[0]; + posY = player->pos[1]; + posZ = 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; - spC4 = player->velocity[2] + spB8; + nextX = player->velocity[0] + posX; + nextY = player->velocity[1] + posY; + nextZ = player->velocity[2] + posZ; func_8002AAC0(player); - spC8 += player->kartHopVelocity; - actor_terrain_collision(&player->collision, player->boundingBoxSize, spCC, spC8, spC4, player->oldPos[0], + nextY += player->kartHopVelocity; + 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_05C = 1.0f; player->unk_060 = 0.0f; calculate_orientation_matrix(player->orientationMatrix, 0.0f, 1.0f, 0.0f, (s16) (s32) player->rotation[1]); player->effects &= ~8; - sp78 = player->collision.surfaceDistance[2]; - if (sp78 <= 0.0f) { + surfaceDistance = player->collision.surfaceDistance[2]; + if (surfaceDistance <= 0.0f) { if (1) {}; - func_8003F46C(player, sp5C, sp68, spE8, &sp78, &spCC, &spC8, &spC4); + func_8003F46C(player, sp5C, newVelocity, spE8, &surfaceDistance, &nextX, &nextY, &nextZ); } - player->unk_074 = calculate_surface_height(spCC, spC8, spC4, 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, spCC, spC8, spC4); + func_80029B4C(player, nextX, nextY, nextZ); } else { - func_8002A194(player, spCC, spC8, spC4); + func_8002A194(player, nextX, nextY, nextZ); } - func_8002AE38(player, playerId, spC0, spB8, spCC, spC4); - sqrt = (sp68[0] * sp68[0]) + (sp68[1] * sp68[1]) + (sp68[2] * sp68[2]); + func_8002AE38(player, playerId, posX, posZ, nextX, nextZ); + sqrt = (newVelocity[0] * newVelocity[0]) + (newVelocity[1] * newVelocity[1]) + (newVelocity[2] * newVelocity[2]); player->previousSpeed = player->speed; player->speed = sqrtf(sqrt); if (((player->unk_08C <= 0.0f) && ((f64) player->speed < 0.13)) || ((player->unk_08C <= 0.0f) && ((f64) player->speed < 0.2) && ((player->effects & 1) == 1))) { - sp68[0] = sp68[0] + (sp68[0] * -1.0f); - sp68[2] = sp68[2] + (sp68[2] * -1.0f); + newVelocity[0] = newVelocity[0] + (newVelocity[0] * -1.0f); + newVelocity[2] = newVelocity[2] + (newVelocity[2] * -1.0f); } else { - player->pos[0] = spCC; - player->pos[2] = spC4; + player->pos[0] = nextX; + player->pos[2] = nextZ; } - player->pos[1] = spC8 - 0.018; + player->pos[1] = nextY - 0.018; player->unk_064[0] = spE8[0]; player->unk_064[2] = spE8[2]; - player->velocity[0] = sp68[0]; - player->velocity[1] = sp68[1]; - player->velocity[2] = sp68[2]; + player->velocity[0] = newVelocity[0]; + player->velocity[1] = newVelocity[1]; + player->velocity[2] = newVelocity[2]; - D_80165070[playerId][0] = sp68[0]; - D_80165070[playerId][1] = sp68[1]; - D_80165070[playerId][2] = sp68[2]; + gPlayerLastVelocity[playerId][0] = newVelocity[0]; + gPlayerLastVelocity[playerId][1] = newVelocity[1]; + gPlayerLastVelocity[playerId][2] = newVelocity[2]; if ((player->type & PLAYER_HUMAN) == PLAYER_HUMAN) { if (gKartTopSpeedTable[player->characterId] < player->speed) { - temp_f0_2 = gKartTopSpeedTable[player->characterId] / player->speed; - player->velocity[0] *= temp_f0_2; - player->velocity[1] *= temp_f0_2; - player->velocity[2] *= temp_f0_2; + topSpeedMultiplier = gKartTopSpeedTable[player->characterId] / player->speed; + player->velocity[0] *= topSpeedMultiplier; + player->velocity[1] *= topSpeedMultiplier; + player->velocity[2] *= topSpeedMultiplier; player->speed = gKartTopSpeedTable[player->characterId]; } } @@ -4798,14 +4799,14 @@ void func_80038BE4(Player* player, s16 arg1) { player->unk_08C = (player->currentSpeed * player->currentSpeed) / 25.0f; } -void func_80038C6C(Player* player, UNUSED Camera* camera, s8 arg2, s8 playerId) { +void func_80038C6C(Player* player, UNUSED Camera* camera, s8 screenId, s8 playerId) { Vec3f sp114 = { 0.0, 0.0, 1.0 }; Vec3f sp108 = { 0.0, 0.0, 0.0 }; Vec3f spFC = { 0.0, 0.0, 0.0 }; Vec3f spF0 = { 0.0, 0.0, 0.0 }; - f32 spEC; - f32 spE8; - f32 spE4; + f32 nextX; + f32 nextY; + f32 nextZ; f32 posX; f32 posY; f32 posZ; @@ -4816,17 +4817,17 @@ void func_80038C6C(Player* player, UNUSED Camera* camera, s8 arg2, s8 playerId) f32 spA4; f32 spA0; f32 sp9C; - f32 sp98; + f32 surfaceDistance; UNUSED s32 pad3; - Vec3f sp88; + Vec3f newVelocity; Vec3f sp7C; UNUSED s32 pad[10]; player->unk_084 = -10.0f; player->unk_088 = 28.0f; player->topSpeed = 250.0f; - func_8002B830(player, playerId, arg2); - apply_effect(player, playerId, arg2); + func_8002B830(player, playerId, screenId); + apply_effect(player, playerId, screenId); player->rotation[1] += player->unk_078; spF0[0] = 0; spF0[1] = 0; @@ -4844,13 +4845,13 @@ void func_80038C6C(Player* player, UNUSED Camera* camera, s8 arg2, s8 playerId) sp114[2] = player->unk_08C; mtxf_translate_vec3f_mat3(sp114, player->orientationMatrix); - sp88[0] = player->velocity[0]; - sp88[1] = player->velocity[1]; - sp88[2] = player->velocity[2]; + newVelocity[0] = player->velocity[0]; + newVelocity[1] = player->velocity[1]; + newVelocity[2] = player->velocity[2]; - sp88[0] += ((((((sp114[0] + spA4) + spF0[0])) - (sp88[0] * (0.12 * (player->kartFriction)))) / 6000.0) / 1); - sp88[2] += ((((((sp114[2] + sp9C) + spF0[2])) - (sp88[2] * (0.12 * (player->kartFriction)))) / 6000.0) / 1); - sp88[1] += ((((((sp114[1] + spA0) + spF0[1])) - (sp88[1] * (0.12 * (player->kartFriction)))) / 6000.0) / 1); + newVelocity[0] += ((((((sp114[0] + spA4) + spF0[0])) - (newVelocity[0] * (0.12 * (player->kartFriction)))) / 6000.0) / 1); + newVelocity[2] += ((((((sp114[2] + sp9C) + spF0[2])) - (newVelocity[2] * (0.12 * (player->kartFriction)))) / 6000.0) / 1); + newVelocity[1] += ((((((sp114[1] + spA0) + spF0[1])) - (newVelocity[1] * (0.12 * (player->kartFriction)))) / 6000.0) / 1); if ((player->unk_044 & 0x10) == 0x10) { player->unk_044 &= 0xFFEF; } @@ -4863,13 +4864,13 @@ void func_80038C6C(Player* player, UNUSED Camera* camera, s8 arg2, s8 playerId) player->oldPos[1] = player->pos[1]; player->oldPos[2] = player->pos[2]; - spEC = posX + player->velocity[0]; - spE8 = posY + player->velocity[1]; - spE4 = posZ + player->velocity[2]; + nextX = posX + player->velocity[0]; + nextY = posY + player->velocity[1]; + nextZ = posZ + player->velocity[2]; func_8002AAC0(player); - spE8 += player->kartHopVelocity; - spE8 -= 0.02; - actor_terrain_collision(&player->collision, player->boundingBoxSize, spEC, spE8, spE4, player->oldPos[0], + nextY += player->kartHopVelocity; + nextY -= 0.02; + actor_terrain_collision(&player->collision, player->boundingBoxSize, nextX, nextY, nextZ, player->oldPos[0], player->oldPos[1], player->oldPos[2]); player->unk_058 = 0; player->unk_060 = 0; @@ -4877,55 +4878,55 @@ void func_80038C6C(Player* player, UNUSED Camera* camera, s8 arg2, s8 playerId) calculate_orientation_matrix(player->orientationMatrix, 0, 1.0f, 0, player->rotation[1]); player->effects |= 8; player->unk_0C2 += 1; - sp98 = player->collision.surfaceDistance[2]; - if (sp98 <= 0) { + surfaceDistance = player->collision.surfaceDistance[2]; + if (surfaceDistance <= 0) { player->unk_0C2 = 0; player->effects &= ~2; player->effects &= ~8; player->kartHopVelocity = player->unk_0C2; } - sp98 = player->collision.surfaceDistance[2]; - if (sp98 <= 0) { - func_8003F46C(player, sp7C, sp88, sp108, &sp98, &spEC, &spE8, &spE4); + surfaceDistance = player->collision.surfaceDistance[2]; + if (surfaceDistance <= 0) { + func_8003F46C(player, sp7C, newVelocity, sp108, &surfaceDistance, &nextX, &nextY, &nextZ); } - sp98 = player->collision.surfaceDistance[0]; - if (sp98 < 0) { - func_8003F734(player, sp7C, sp88, &sp98, &spEC, &spE8, &spE4); - func_8002C954(player, playerId, sp88); + surfaceDistance = player->collision.surfaceDistance[0]; + if (surfaceDistance < 0) { + func_8003F734(player, sp7C, newVelocity, &surfaceDistance, &nextX, &nextY, &nextZ); + func_8002C954(player, playerId, newVelocity); } - sp98 = player->collision.surfaceDistance[1]; - if (sp98 < 0) { - func_8003FBAC(player, sp7C, sp88, &sp98, &spEC, &spE8, &spE4); - func_8002C954(player, playerId, sp88); + surfaceDistance = player->collision.surfaceDistance[1]; + if (surfaceDistance < 0) { + func_8003FBAC(player, sp7C, newVelocity, &surfaceDistance, &nextX, &nextY, &nextZ); + func_8002C954(player, playerId, newVelocity); } - sp98 = player->collision.surfaceDistance[0]; - if (sp98 >= 0) { - sp98 = player->collision.surfaceDistance[1]; - if (sp98 >= 0) { + surfaceDistance = player->collision.surfaceDistance[0]; + if (surfaceDistance >= 0) { + surfaceDistance = player->collision.surfaceDistance[1]; + if (surfaceDistance >= 0) { player->unk_046 &= 0xFFDF; } } - player->unk_074 = calculate_surface_height(spEC, spE8, spE4, player->collision.meshIndexZX); - func_80029B4C(player, spEC, spE8, spE4); - func_8002AE38(player, playerId, posX, posZ, spEC, spE4); - sqrt = (sp88[0] * sp88[0]) + (sp88[2] * sp88[2]); + player->unk_074 = calculate_surface_height(nextX, nextY, nextZ, player->collision.meshIndexZX); + func_80029B4C(player, nextX, nextY, nextZ); + func_8002AE38(player, playerId, posX, posZ, nextX, nextZ); + sqrt = (newVelocity[0] * newVelocity[0]) + (newVelocity[2] * newVelocity[2]); player->previousSpeed = player->speed; player->speed = sqrtf(sqrt); - player->pos[0] = spEC; - player->pos[2] = spE4; - player->pos[1] = spE8; + player->pos[0] = nextX; + player->pos[2] = nextZ; + player->pos[1] = nextY; player->unk_064[0] = sp108[0]; player->unk_064[2] = sp108[2]; - player->velocity[0] = sp88[0]; - player->velocity[1] = sp88[1]; - player->velocity[2] = sp88[2]; + player->velocity[0] = newVelocity[0]; + player->velocity[1] = newVelocity[1]; + player->velocity[2] = newVelocity[2]; - D_80165070[playerId][0] = sp88[0]; - D_80165070[playerId][1] = sp88[1]; - D_80165070[playerId][2] = sp88[2]; + gPlayerLastVelocity[playerId][0] = newVelocity[0]; + gPlayerLastVelocity[playerId][1] = newVelocity[1]; + gPlayerLastVelocity[playerId][2] = newVelocity[2]; if ((player->type & PLAYER_HUMAN) == PLAYER_HUMAN) { if (gKartTopSpeedTable[player->characterId] < player->speed) { diff --git a/src/render_objects.c b/src/render_objects.c index decc90be1..21ac663f1 100644 --- a/src/render_objects.c +++ b/src/render_objects.c @@ -1801,7 +1801,7 @@ void render_texture_tile_rgba32_block(s16 x, s16 y, u8* texture, u32 width, u32 centerY += heightDiv; } - + gSPDisplayList(gDisplayListHead++, D_0D007EB8); // FAKE centerX++; @@ -4478,12 +4478,12 @@ void func_800569F4(s32 playerIndex) { gObjectList[objectIndex].primAlpha = 0; } -void func_80056A40(s32 playerIndex, s32 arg1) { +void func_80056A40(s32 playerIndex, s32 primAlpha) { s32 objectIndex; objectIndex = gIndexObjectBombKart[playerIndex]; init_object(objectIndex, 0); - gObjectList[objectIndex].primAlpha = (s16) arg1; + gObjectList[objectIndex].primAlpha = (s16) primAlpha; } void func_80056A94(s32 playerIndex) { diff --git a/src/render_player.c b/src/render_player.c index d9431dd72..652fdbbf7 100644 --- a/src/render_player.c +++ b/src/render_player.c @@ -49,7 +49,8 @@ u16 gPlayerYellowEffect[8]; UNUSED u16 gPlayerWhiteEffect[8]; s32 D_80164B80[296]; s16 D_80165020[40]; -Vec3f D_80165070[8]; +// Used to calculate difference between previous and current player velocity. +Vec3f gPlayerLastVelocity[8]; s16 gLastAnimFrameSelector[4][8]; s16 gLastAnimGroupSelector[4][8]; s16 D_80165150[4][8]; @@ -1479,7 +1480,7 @@ void render_kart(Player* player, s8 playerId, s8 arg2, s8 arg3) { gDPSetTextureLUT(gDisplayListHead++, G_TT_RGBA16); func_8004B614(gPlayerRedEffect[playerId], gPlayerGreenEffect[playerId], gPlayerBlueEffect[playerId], gPlayerCyanEffect[playerId], gPlayerMagentaEffect[playerId], gPlayerYellowEffect[playerId], - (s32) player->unk_0C6); + (s32) player->alpha); gDPSetRenderMode(gDisplayListHead++, AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_WRAP | ZMODE_XLU | CVG_X_ALPHA | FORCE_BL | GBL_c1(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA), @@ -1493,7 +1494,7 @@ void render_kart(Player* player, s8 playerId, s8 arg2, s8 arg3) { gDPSetTextureLUT(gDisplayListHead++, G_TT_RGBA16); func_8004B614(gPlayerRedEffect[playerId], gPlayerGreenEffect[playerId], gPlayerBlueEffect[playerId], gPlayerCyanEffect[playerId], gPlayerMagentaEffect[playerId], gPlayerYellowEffect[playerId], - D_8018D970[playerId]); + gPlayerOtherScreensAlpha[playerId]); gDPSetRenderMode(gDisplayListHead++, AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_WRAP | ZMODE_XLU | CVG_X_ALPHA | FORCE_BL | GBL_c1(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA), @@ -1509,7 +1510,7 @@ void render_kart(Player* player, s8 playerId, s8 arg2, s8 arg3) { gDPSetTextureLUT(gDisplayListHead++, G_TT_RGBA16); func_8004B614(gPlayerRedEffect[playerId], gPlayerGreenEffect[playerId], gPlayerBlueEffect[playerId], gPlayerCyanEffect[playerId], gPlayerMagentaEffect[playerId], gPlayerYellowEffect[playerId], - (s32) player->unk_0C6); + (s32) player->alpha); gDPSetAlphaCompare(gDisplayListHead++, G_AC_DITHER); gDPSetRenderMode(gDisplayListHead++, G_RM_ZB_XLU_SURF, G_RM_ZB_XLU_SURF2); } else { @@ -1520,7 +1521,7 @@ void render_kart(Player* player, s8 playerId, s8 arg2, s8 arg3) { gDPSetTextureLUT(gDisplayListHead++, G_TT_RGBA16); func_8004B614(gPlayerRedEffect[playerId], gPlayerGreenEffect[playerId], gPlayerBlueEffect[playerId], gPlayerCyanEffect[playerId], gPlayerMagentaEffect[playerId], gPlayerYellowEffect[playerId], - (s32) player->unk_0C6); + (s32) player->alpha); gDPSetRenderMode(gDisplayListHead++, G_RM_AA_ZB_TEX_EDGE, G_RM_AA_ZB_TEX_EDGE2); } @@ -1687,7 +1688,7 @@ void render_player_ice_reflection(Player* player, s8 playerId, s8 screenId, s8 a gDPSetTextureLUT(gDisplayListHead++, G_TT_RGBA16); func_8004B614(gPlayerRedEffect[playerId], gPlayerGreenEffect[playerId], gPlayerBlueEffect[playerId], gPlayerCyanEffect[playerId], gPlayerMagentaEffect[playerId], gPlayerYellowEffect[playerId], - (s16) player->unk_0C6 / 2); + (s16) player->alpha / 2); gDPSetRenderMode(gDisplayListHead++, G_RM_ZB_XLU_SURF, G_RM_ZB_XLU_SURF2); gDPLoadTextureBlock(gDisplayListHead++, sKartUpperTexture, G_IM_FMT_CI, G_IM_SIZ_8b, 64, 32, 0, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, diff --git a/src/render_player.h b/src/render_player.h index 829a6db91..ca8346b62 100644 --- a/src/render_player.h +++ b/src/render_player.h @@ -278,7 +278,7 @@ extern u8* gKartWario189Wheel0[]; extern u8* gKartWario189Wheel0[]; extern s16 D_80165020[40]; -extern Vec3f D_80165070[8]; +extern Vec3f gPlayerLastVelocity[8]; extern s16 gLastAnimFrameSelector[4][8]; extern s16 gLastAnimGroupSelector[4][8]; extern s16 D_80165150[4][8]; diff --git a/src/spawn_players.c b/src/spawn_players.c index 0112ac0db..d9d807220 100644 --- a/src/spawn_players.c +++ b/src/spawn_players.c @@ -157,7 +157,7 @@ void spawn_player(Player* player, s8 playerIndex, f32 startingRow, f32 startingC player->unk_044 = 0; player->unk_046 = 0; player->soundEffects = 0; - player->unk_0C6 = 0xFF; + player->alpha = ALPHA_MAX; player->unk_206 = 0; player->slopeAccel = 0; @@ -279,9 +279,9 @@ void spawn_player(Player* player, s8 playerIndex, f32 startingRow, f32 startingC D_801652E0[playerIndex] = 0; D_801652C0[playerIndex] = 0; D_80165020[playerIndex] = 0; - D_80165070[playerIndex][0] = 0.0f; - D_80165070[playerIndex][1] = 0.0f; - D_80165070[playerIndex][2] = 0.0f; + gPlayerLastVelocity[playerIndex][0] = 0.0f; + gPlayerLastVelocity[playerIndex][1] = 0.0f; + gPlayerLastVelocity[playerIndex][2] = 0.0f; gPlayerCurrentSpeed[playerIndex] = 0.0f; D_801652A0[playerIndex] = 0.0f; gPlayerIsThrottleActive[playerIndex] = 0; diff --git a/src/update_objects.c b/src/update_objects.c index 2dfea8758..0dc4d1586 100644 --- a/src/update_objects.c +++ b/src/update_objects.c @@ -3161,7 +3161,7 @@ void func_80079860(s32 playerId) { void func_8007993C(s32 objectIndex, Player* player) { if (player->unk_0CA & 4) { func_800722A4(objectIndex, 2); - gObjectList[objectIndex].primAlpha = player->unk_0C6; + gObjectList[objectIndex].primAlpha = player->alpha; return; } func_800722CC(objectIndex, 2);