Merge branch 'bots-stop-spindashing' into 'master'

Make spindashing bots work better

See merge request KartKrew/Kart!419
This commit is contained in:
Sal 2021-04-16 20:34:15 -04:00
commit 2cbd0d0dcc
6 changed files with 42 additions and 6 deletions

View file

@ -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;
// ========================================================================

View file

@ -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);

View file

@ -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;

View file

@ -2699,22 +2699,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)
@ -2722,6 +2720,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:

View file

@ -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);

View file

@ -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
}