From 15bda7da2dafdcb06c17d334284110927ef8faf3 Mon Sep 17 00:00:00 2001 From: Sally Cochenour Date: Sat, 28 Mar 2020 14:57:49 -0400 Subject: [PATCH] Use K_MomentumToFacing to give bots a bit better traction --- src/k_bot.c | 35 ++++++----------------------------- src/k_bot.h | 1 - src/p_user.c | 18 ++++++------------ 3 files changed, 12 insertions(+), 42 deletions(-) diff --git a/src/k_bot.c b/src/k_bot.c index 577c9d260..ee910bd59 100644 --- a/src/k_bot.c +++ b/src/k_bot.c @@ -80,7 +80,7 @@ boolean K_PlayerUsesBotMovement(player_t *player) return false; } -fixed_t K_DistanceOfLineFromPoint(fixed_t v1x, fixed_t v1y, fixed_t v2x, fixed_t v2y, fixed_t cx, fixed_t cy) +static fixed_t K_DistanceOfLineFromPoint(fixed_t v1x, fixed_t v1y, fixed_t v2x, fixed_t v2y, fixed_t cx, fixed_t cy) { fixed_t v1toc[2] = {cx - v1x, cy - v1y}; fixed_t v1tov2[2] = {v2x - v1x, v2y - v1y}; @@ -121,30 +121,7 @@ void K_BuildBotTiccmd(player_t *player, ticcmd_t *cmd) INT16 anglediff; wpangle = R_PointToAngle2(player->mo->x, player->mo->y, player->nextwaypoint->mobj->x, player->nextwaypoint->mobj->y); - - if (player->mo->momx || player->mo->momy) - { - angle_t movevswp; - - moveangle = R_PointToAngle2(0, 0, player->mo->momx, player->mo->momy); - - movevswp = (moveangle - wpangle); - if (movevswp > ANGLE_180) - { - movevswp = InvAngle(movevswp); - } - - if (movevswp > ANGLE_45) - { - // Use facing direction when going the wrong way - moveangle = player->mo->angle; - } - } - else - { - // Default to facing direction - moveangle = player->mo->angle; - } + moveangle = player->mo->angle; angle = (moveangle - wpangle); @@ -184,9 +161,9 @@ void K_BuildBotTiccmd(player_t *player, ticcmd_t *cmd) // Full speed ahead! cmd->forwardmove = 50; - if (dirdist <= 3*rad/4) + if (dirdist <= rad) { - if (dirdist < rad/4) + if (dirdist < rad/2) { // Don't need to turn! turnamt = 0; @@ -197,12 +174,12 @@ void K_BuildBotTiccmd(player_t *player, ticcmd_t *cmd) turnamt /= 4; } } - else + /*else { // Actually, don't go too fast... cmd->forwardmove /= 2; cmd->buttons |= BT_BRAKE; - } + }*/ } if (turnamt != 0) diff --git a/src/k_bot.h b/src/k_bot.h index b4c703aa7..a9353f6e2 100644 --- a/src/k_bot.h +++ b/src/k_bot.h @@ -12,5 +12,4 @@ void K_AddBots(UINT8 numbots); boolean K_PlayerUsesBotMovement(player_t *player); -fixed_t K_DistanceOfLineFromPoint(fixed_t v1x, fixed_t v1y, fixed_t v2x, fixed_t v2y, fixed_t cx, fixed_t cy); void K_BuildBotTiccmd(player_t *player, ticcmd_t *cmd); diff --git a/src/p_user.c b/src/p_user.c index 6e1b826b0..e9459fb0a 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -4075,9 +4075,8 @@ static void P_3dMovement(player_t *player) player->aiming = cmd->aiming<exiting || mapreset) || (P_PlayerInPain(player) && !onground))) + if (!(P_PlayerInPain(player) && !onground)) { - //movepushforward = cmd->forwardmove * (thrustfactor * acceleration); movepushforward = K_3dKartMovement(player, onground, cmd->forwardmove); if (player->mo->movefactor != FRACUNIT) // Friction-scaled acceleration... @@ -4095,12 +4094,8 @@ static void P_3dMovement(player_t *player) movepushforward = 0; } -#ifdef ESLOPE totalthrust.x += P_ReturnThrustX(player->mo, movepushangle, movepushforward); totalthrust.y += P_ReturnThrustY(player->mo, movepushangle, movepushforward); -#else - P_Thrust(player->mo, movepushangle, movepushforward); -#endif } else if (!(player->kartstuff[k_spinouttimer])) { @@ -4115,15 +4110,10 @@ static void P_3dMovement(player_t *player) else movepushside = (cmd->sidemove * FRACUNIT/128) - FixedDiv(player->speed, K_GetKartSpeed(player, true)); -#ifdef ESLOPE totalthrust.x += P_ReturnThrustX(player->mo, movepushsideangle, movepushside); totalthrust.y += P_ReturnThrustY(player->mo, movepushsideangle, movepushside); -#else - P_Thrust(player->mo, movepushsideangle, movepushside); -#endif } -#ifdef ESLOPE if ((totalthrust.x || totalthrust.y) && player->mo->standingslope && (!(player->mo->standingslope->flags & SL_NOPHYSICS)) && abs(player->mo->standingslope->zdelta) > FRACUNIT/2) { // Factor thrust to slope, but only for the part pushing up it! @@ -4141,6 +4131,11 @@ static void P_3dMovement(player_t *player) } } + if (K_PlayerUsesBotMovement(player)) + { + K_MomentumToFacing(player); + } + player->mo->momx += totalthrust.x; player->mo->momy += totalthrust.y; @@ -4155,7 +4150,6 @@ static void P_3dMovement(player_t *player) player->mo->momy = FixedMul(FixedDiv(player->mo->momy, speed), newspeed); } } -#endif // Time to ask three questions: // 1) Are we over topspeed?