mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2025-10-30 08:01:28 +00:00
Rubberbanding!
This commit is contained in:
parent
dbb52e4aa5
commit
3f639b4f8a
3 changed files with 70 additions and 6 deletions
50
src/k_bot.c
50
src/k_bot.c
|
|
@ -100,6 +100,56 @@ boolean K_BotCanTakeCut(player_t *player)
|
|||
return false;
|
||||
}
|
||||
|
||||
fixed_t K_BotRubberband(player_t *player)
|
||||
{
|
||||
fixed_t rubberband = FRACUNIT;
|
||||
player_t *besthumanplayer = NULL;
|
||||
UINT8 i;
|
||||
|
||||
for (i = 0; i < MAXPLAYERS; i++)
|
||||
{
|
||||
if (!playeringame[i] || players[i].spectator || players[i].exiting)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (&players[i] == player || players[i].bot)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (besthumanplayer == NULL || players[i].distancetofinish < besthumanplayer->distancetofinish)
|
||||
{
|
||||
besthumanplayer = &players[i];
|
||||
}
|
||||
}
|
||||
|
||||
if (besthumanplayer != NULL)
|
||||
{
|
||||
UINT32 wanteddist = besthumanplayer->distancetofinish; // TODO: Add difficulty here
|
||||
|
||||
if (wanteddist > player->distancetofinish)
|
||||
{
|
||||
rubberband = FRACUNIT + (2 * (player->distancetofinish - wanteddist));
|
||||
}
|
||||
else
|
||||
{
|
||||
rubberband = FRACUNIT + (8 * (player->distancetofinish - wanteddist));
|
||||
}
|
||||
}
|
||||
|
||||
if (rubberband > 2*FRACUNIT)
|
||||
{
|
||||
rubberband = 2*FRACUNIT;
|
||||
}
|
||||
else if (rubberband < 2*FRACUNIT/3)
|
||||
{
|
||||
rubberband = 2*FRACUNIT/3;
|
||||
}
|
||||
|
||||
return rubberband;
|
||||
}
|
||||
|
||||
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};
|
||||
|
|
|
|||
|
|
@ -22,4 +22,5 @@ typedef struct botprediction_s {
|
|||
void K_AddBots(SINT8 numbots);
|
||||
boolean K_PlayerUsesBotMovement(player_t *player);
|
||||
boolean K_BotCanTakeCut(player_t *player);
|
||||
fixed_t K_BotRubberband(player_t *player);
|
||||
void K_BuildBotTiccmd(player_t *player, ticcmd_t *cmd);
|
||||
|
|
|
|||
25
src/k_kart.c
25
src/k_kart.c
|
|
@ -2693,13 +2693,11 @@ fixed_t K_GetKartSpeed(player_t *player, boolean doboostpower)
|
|||
|
||||
if (K_PlayerUsesBotMovement(player))
|
||||
{
|
||||
fixed_t speedmul = FRACUNIT;
|
||||
fixed_t speedmul = K_BotRubberband(player);
|
||||
|
||||
// Give top speed a buff for bots, since it's a fairly weak stat without drifting
|
||||
speedmul += ((kartspeed-1) * FRACUNIT / 8) / 10; // +10% for speed 9
|
||||
|
||||
// TODO: Rubberbanding goes here. Do it for accel too!
|
||||
|
||||
finalspeed = FixedMul(finalspeed, speedmul);
|
||||
}
|
||||
|
||||
|
|
@ -2722,6 +2720,11 @@ fixed_t K_GetKartAccel(player_t *player)
|
|||
//k_accel += 3 * (9 - kartspeed); // 36 - 60
|
||||
k_accel += 4 * (9 - kartspeed); // 32 - 64
|
||||
|
||||
if (K_PlayerUsesBotMovement(player))
|
||||
{
|
||||
k_accel = FixedMul(k_accel, K_BotRubberband(player));
|
||||
}
|
||||
|
||||
return FixedMul(k_accel, FRACUNIT+player->kartstuff[k_accelboost]);
|
||||
}
|
||||
|
||||
|
|
@ -6474,6 +6477,13 @@ static waypoint_t *K_GetPlayerNextWaypoint(player_t *player)
|
|||
angle_t nextbestmomdelta = momdelta;
|
||||
size_t i = 0U;
|
||||
|
||||
if (K_PlayerUsesBotMovement(player))
|
||||
{
|
||||
// Try to force bots to use a next waypoint
|
||||
nextbestdelta = ANGLE_MAX;
|
||||
nextbestmomdelta = ANGLE_MAX;
|
||||
}
|
||||
|
||||
if ((waypoint->nextwaypoints != NULL) && (waypoint->numnextwaypoints > 0U))
|
||||
{
|
||||
for (i = 0U; i < waypoint->numnextwaypoints; i++)
|
||||
|
|
@ -6806,6 +6816,12 @@ INT16 K_GetKartTurnValue(player_t *player, INT16 turnvalue)
|
|||
if (player->spectator)
|
||||
return turnvalue;
|
||||
|
||||
if (K_PlayerUsesBotMovement(player))
|
||||
{
|
||||
turnvalue = FixedMul(turnvalue, (5*FRACUNIT)/4); // Base increase to turning
|
||||
turnvalue = FixedMul(turnvalue, K_BotRubberband(player));
|
||||
}
|
||||
|
||||
if (player->kartstuff[k_drift] != 0 && P_IsObjectOnGround(player->mo))
|
||||
{
|
||||
// If we're drifting we have a completely different turning value
|
||||
|
|
@ -6826,9 +6842,6 @@ INT16 K_GetKartTurnValue(player_t *player, INT16 turnvalue)
|
|||
if (EITHERSNEAKER(player) || player->kartstuff[k_invincibilitytimer] || player->kartstuff[k_growshrinktimer] > 0)
|
||||
turnvalue = FixedMul(turnvalue, (5*FRACUNIT)/4);
|
||||
|
||||
if (K_PlayerUsesBotMovement(player))
|
||||
turnvalue = FixedMul(turnvalue, (5*FRACUNIT)/4);
|
||||
|
||||
return turnvalue;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue