mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2025-10-30 08:01:28 +00:00
Reduce waypoint radius for bots on turns
This commit is contained in:
parent
df00ed4f64
commit
cd2dd1315a
1 changed files with 61 additions and 4 deletions
65
src/k_bot.c
65
src/k_bot.c
|
|
@ -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);
|
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)
|
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++)
|
for (i = 0; i < pathtofinish.numnodes; i++)
|
||||||
{
|
{
|
||||||
|
fixed_t radius = 0;
|
||||||
|
|
||||||
wp = (waypoint_t *)pathtofinish.array[i].nodedata;
|
wp = (waypoint_t *)pathtofinish.array[i].nodedata;
|
||||||
|
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
|
|
@ -716,9 +772,10 @@ static botprediction_t *K_CreateBotPrediction(player_t *player)
|
||||||
radreduce = FRACUNIT >> 1;
|
radreduce = FRACUNIT >> 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wp->mobj->radius < smallestradius)
|
radius = K_GetBotWaypointRadius(wp);
|
||||||
|
if (radius < smallestradius)
|
||||||
{
|
{
|
||||||
smallestradius = wp->mobj->radius;
|
smallestradius = radius;
|
||||||
}
|
}
|
||||||
|
|
||||||
distanceleft -= disttonext;
|
distanceleft -= disttonext;
|
||||||
|
|
@ -1386,7 +1443,7 @@ void K_BuildBotTiccmd(player_t *player, ticcmd_t *cmd)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (botController != NULL && (botController->args[1] & TMBOT_NOCONTROL)) // FIXME: UDMF-ify
|
if (botController != NULL && (botController->args[1] & TMBOT_NOCONTROL))
|
||||||
{
|
{
|
||||||
// Disable bot controls entirely.
|
// Disable bot controls entirely.
|
||||||
return;
|
return;
|
||||||
|
|
@ -1394,7 +1451,7 @@ void K_BuildBotTiccmd(player_t *player, ticcmd_t *cmd)
|
||||||
|
|
||||||
destangle = player->mo->angle;
|
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;
|
const fixed_t dist = DEFAULT_WAYPOINT_RADIUS * player->mo->scale;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue