Merge branch 'bot-improvements-round-12' into 'master'

Bots Again: Round 12

See merge request KartKrew/Kart!1034
This commit is contained in:
James R 2023-03-09 10:29:14 +00:00
commit 600063f46b
4 changed files with 80 additions and 9 deletions

View file

@ -634,6 +634,60 @@ fixed_t K_DistanceOfLineFromPoint(fixed_t v1x, fixed_t v1y, fixed_t v2x, fixed_t
return R_PointToDist2(px, py, startx + vx, starty + vy);
}
/*--------------------------------------------------
static fixed_t K_GetBotWaypointRadius(waypoint_t *waypoint)
Calculates a new waypoint radius size to use, making it
thinner depending on how harsh the turn is.
Input Arguments:-
waypoint - Waypoint to retrieve the radius of.
Return:-
New radius value.
--------------------------------------------------*/
static fixed_t K_GetBotWaypointRadius(waypoint_t *const waypoint)
{
static const fixed_t maxReduce = FRACUNIT/32;
static const angle_t maxDelta = ANGLE_45;
fixed_t radius = waypoint->mobj->radius;
fixed_t reduce = FRACUNIT;
angle_t delta = 0;
size_t i, j;
for (i = 0; i < waypoint->numnextwaypoints; i++)
{
const waypoint_t *next = waypoint->nextwaypoints[i];
const angle_t nextAngle = R_PointToAngle2(
waypoint->mobj->x, waypoint->mobj->y,
next->mobj->x, next->mobj->y
);
for (j = 0; j < waypoint->numprevwaypoints; j++)
{
const waypoint_t *prev = waypoint->prevwaypoints[j];
const angle_t prevAngle = R_PointToAngle2(
prev->mobj->x, prev->mobj->y,
waypoint->mobj->x, waypoint->mobj->y
);
delta = max(delta, AngleDelta(nextAngle, prevAngle));
}
}
if (delta > maxDelta)
{
delta = maxDelta;
}
reduce = FixedDiv(delta, maxDelta);
reduce = FRACUNIT + FixedMul(reduce, maxReduce - FRACUNIT);
return FixedMul(radius, reduce);
}
/*--------------------------------------------------
static botprediction_t *K_CreateBotPrediction(player_t *player)
@ -695,6 +749,8 @@ static botprediction_t *K_CreateBotPrediction(player_t *player)
{
for (i = 0; i < pathtofinish.numnodes; i++)
{
fixed_t radius = 0;
wp = (waypoint_t *)pathtofinish.array[i].nodedata;
if (i == 0)
@ -716,9 +772,10 @@ static botprediction_t *K_CreateBotPrediction(player_t *player)
radreduce = FRACUNIT >> 1;
}
if (wp->mobj->radius < smallestradius)
radius = K_GetBotWaypointRadius(wp);
if (radius < smallestradius)
{
smallestradius = wp->mobj->radius;
smallestradius = radius;
}
distanceleft -= disttonext;
@ -1386,7 +1443,7 @@ void K_BuildBotTiccmd(player_t *player, ticcmd_t *cmd)
return;
}
if (botController != NULL && (botController->args[1] & TMBOT_NOCONTROL)) // FIXME: UDMF-ify
if (botController != NULL && (botController->args[1] & TMBOT_NOCONTROL))
{
// Disable bot controls entirely.
return;
@ -1394,7 +1451,7 @@ void K_BuildBotTiccmd(player_t *player, ticcmd_t *cmd)
destangle = player->mo->angle;
if (botController != NULL && (botController->args[1] & TMBOT_FORCEDIR)) // FIXME: UDMF-ify
if (botController != NULL && (botController->args[1] & TMBOT_FORCEDIR))
{
const fixed_t dist = DEFAULT_WAYPOINT_RADIUS * player->mo->scale;

View file

@ -4865,7 +4865,7 @@ static void K_DrawGPRankDebugger(void)
default: { break; }
}
V_DrawThinString(0, 80, V_SNAPTOTOP|V_SNAPTOLEFT|V_6WIDTHSPACE|V_ALLOWLOWERCASE|V_YELLOWMAP,
V_DrawThinString(0, 90, V_SNAPTOTOP|V_SNAPTOLEFT|V_6WIDTHSPACE|V_ALLOWLOWERCASE|V_YELLOWMAP,
va(" ** FINAL GRADE: %c", gradeChar));
}

View file

@ -3467,7 +3467,7 @@ fixed_t K_GetNewSpeed(player_t *player)
// Don't calculate the acceleration as ever being above top speed
if (oldspeed > p_speed)
oldspeed = p_speed;
newspeed = FixedDiv(FixedDiv(FixedMul(oldspeed, accelmax - p_accel) + FixedMul(p_speed, p_accel), accelmax), K_PlayerBaseFriction(ORIG_FRICTION));
newspeed = FixedDiv(FixedDiv(FixedMul(oldspeed, accelmax - p_accel) + FixedMul(p_speed, p_accel), accelmax), K_PlayerBaseFriction(player, ORIG_FRICTION));
finalspeed = newspeed - oldspeed;
@ -10209,7 +10209,7 @@ static void K_AirFailsafe(player_t *player)
//
// K_PlayerBaseFriction
//
fixed_t K_PlayerBaseFriction(fixed_t original)
fixed_t K_PlayerBaseFriction(player_t *player, fixed_t original)
{
fixed_t frict = original;
@ -10217,6 +10217,20 @@ fixed_t K_PlayerBaseFriction(fixed_t original)
{
frict -= FRACUNIT >> 4;
}
else if (K_PlayerUsesBotMovement(player) == true)
{
// A bit extra friction to help them without drifting.
// Remove this line once they can drift.
frict -= FRACUNIT >> 5;
// Bots gain more traction as they rubberband.
if (player->botvars.rubberband > FRACUNIT)
{
static const fixed_t extraFriction = FRACUNIT >> 5;
const fixed_t mul = player->botvars.rubberband - FRACUNIT;
frict -= FixedMul(extraFriction, mul);
}
}
if (frict > FRACUNIT) { frict = FRACUNIT; }
if (frict < 0) { frict = 0; }
@ -10229,7 +10243,7 @@ fixed_t K_PlayerBaseFriction(fixed_t original)
//
void K_AdjustPlayerFriction(player_t *player)
{
const fixed_t prevfriction = K_PlayerBaseFriction(player->mo->friction);
const fixed_t prevfriction = K_PlayerBaseFriction(player, player->mo->friction);
if (P_IsObjectOnGround(player->mo) == false)
{

View file

@ -179,7 +179,7 @@ fixed_t K_3dKartMovement(player_t *player);
boolean K_PlayerEBrake(player_t *player);
SINT8 K_Sliptiding(player_t *player);
boolean K_FastFallBounce(player_t *player);
fixed_t K_PlayerBaseFriction(fixed_t original);
fixed_t K_PlayerBaseFriction(player_t *player, fixed_t original);
void K_AdjustPlayerFriction(player_t *player);
void K_MoveKartPlayer(player_t *player, boolean onground);
void K_CheckSpectateStatus(void);