diff --git a/src/d_player.h b/src/d_player.h index 08a0f1cde..3ccb6b258 100644 --- a/src/d_player.h +++ b/src/d_player.h @@ -475,6 +475,8 @@ typedef struct botvars_s tic_t itemconfirm; // When high enough, they will use their item SINT8 turnconfirm; // Confirm turn direction + + tic_t spindashconfirm; // When high enough, they will try spindashing } botvars_t; // ======================================================================== diff --git a/src/k_bot.c b/src/k_bot.c index f6d3a993f..9ed48ea96 100644 --- a/src/k_bot.c +++ b/src/k_bot.c @@ -716,9 +716,14 @@ static UINT8 K_TrySpindash(player_t *player) { const tic_t difficultyModifier = (TICRATE/6); + const fixed_t oldSpeed = R_PointToDist2(0, 0, player->rmomx, player->rmomy); + const fixed_t baseAccel = K_GetNewSpeed(player) - oldSpeed; + const fixed_t speedDiff = player->speed - player->lastspeed; + if (player->kartstuff[k_spindashboost] || player->kartstuff[k_tiregrease]) { // You just released a spindash, you don't need to try again yet, jeez. + player->botvars.spindashconfirm = 0; return 0; } @@ -756,8 +761,22 @@ static UINT8 K_TrySpindash(player_t *player) return 0; } - if (player->speed < 10*mapobjectscale // Below the speed threshold - && player->kartstuff[k_speedboost] < (FRACUNIT/8)) // If you have other boosts, you can probably trust it. + if (speedDiff < (3 * baseAccel / 4)) + { + if (player->botvars.spindashconfirm < BOTSPINDASHCONFIRM) + { + player->botvars.spindashconfirm++; + } + } + else + { + if (player->botvars.spindashconfirm > 0) + { + player->botvars.spindashconfirm--; + } + } + + if (player->botvars.spindashconfirm >= BOTSPINDASHCONFIRM) { INT32 chargingPoint = (K_GetSpindashChargeTime(player) + difficultyModifier); diff --git a/src/k_bot.h b/src/k_bot.h index 38408c6af..94694c2dd 100644 --- a/src/k_bot.h +++ b/src/k_bot.h @@ -23,6 +23,9 @@ // Made it as small as possible without making it look like the bots are twitching constantly. #define BOTTURNCONFIRM 4 +// How many tics without being able to accelerate before we'll let you spindash. +#define BOTSPINDASHCONFIRM (TICRATE/4) + // Point for bots to aim for typedef struct botprediction_s { fixed_t x, y; diff --git a/src/k_kart.c b/src/k_kart.c index 59b1ad0cf..eace37ad4 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -2696,22 +2696,20 @@ SINT8 K_GetForwardMove(player_t *player) return forwardmove; } -fixed_t K_3dKartMovement(player_t *player) +fixed_t K_GetNewSpeed(player_t *player) { const fixed_t accelmax = 4000; const fixed_t p_speed = K_GetKartSpeed(player, true); const fixed_t p_accel = K_GetKartAccel(player); + fixed_t newspeed, oldspeed, finalspeed; - fixed_t movemul = FRACUNIT; fixed_t orig = ORIG_FRICTION; - SINT8 forwardmove = K_GetForwardMove(player); if (K_PlayerUsesBotMovement(player)) { orig = K_BotFrictionRubberband(player, ORIG_FRICTION); } - // ACCELCODE!!!1!11! oldspeed = R_PointToDist2(0, 0, player->rmomx, player->rmomy); // FixedMul(P_AproxDistance(player->rmomx, player->rmomy), player->mo->scale); // Don't calculate the acceleration as ever being above top speed if (oldspeed > p_speed) @@ -2719,6 +2717,17 @@ fixed_t K_3dKartMovement(player_t *player) newspeed = FixedDiv(FixedDiv(FixedMul(oldspeed, accelmax - p_accel) + FixedMul(p_speed, p_accel), accelmax), orig); finalspeed = newspeed - oldspeed; + + return finalspeed; +} + +fixed_t K_3dKartMovement(player_t *player) +{ + fixed_t finalspeed = K_GetNewSpeed(player); + + fixed_t movemul = FRACUNIT; + SINT8 forwardmove = K_GetForwardMove(player); + movemul = abs(forwardmove * FRACUNIT) / 50; // forwardmove is: diff --git a/src/k_kart.h b/src/k_kart.h index 09665d8ab..9051f712f 100644 --- a/src/k_kart.h +++ b/src/k_kart.h @@ -105,6 +105,7 @@ UINT16 K_GetKartFlashing(player_t *player); boolean K_KartKickstart(player_t *player); UINT16 K_GetKartButtons(player_t *player); SINT8 K_GetForwardMove(player_t *player); +fixed_t K_GetNewSpeed(player_t *player); fixed_t K_3dKartMovement(player_t *player); boolean K_PlayerEBrake(player_t *player); SINT8 K_Sliptiding(player_t *player); diff --git a/src/p_saveg.c b/src/p_saveg.c index 87646d225..ab04f31b8 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -324,6 +324,7 @@ static void P_NetArchivePlayers(void) WRITEUINT32(save_p, players[i].botvars.itemdelay); WRITEUINT32(save_p, players[i].botvars.itemconfirm); WRITESINT8(save_p, players[i].botvars.turnconfirm); + WRITEUINT32(save_p, players[i].botvars.spindashconfirm); } } @@ -557,6 +558,7 @@ static void P_NetUnArchivePlayers(void) players[i].botvars.itemdelay = READUINT32(save_p); players[i].botvars.itemconfirm = READUINT32(save_p); players[i].botvars.turnconfirm = READSINT8(save_p); + players[i].botvars.spindashconfirm = READUINT32(save_p); //players[i].viewheight = P_GetPlayerViewHeight(players[i]); // scale cannot be factored in at this point }