Split botvar and cmd handling for drifts

This commit is contained in:
Anonimus 2025-04-25 11:33:08 -04:00
parent 00470714c0
commit 360653e68d
2 changed files with 43 additions and 31 deletions

View file

@ -451,10 +451,10 @@ struct botvars_t
fixed_t driftskill; // The bot's "skill" at drifts.
// Determines how soon a bot starts to drift.
INT32 driftstate; // Drifting state
INT32 driftamt; // Turning severity for a drift
SINT8 driftturn; // Drifting turn direction
tic_t drifttime; // Time spent drifting
boolean powersliding; // Are we powersliding?
};
struct sonicloopcamvars_t

View file

@ -1068,18 +1068,17 @@ static void K_WaypointGetDirectionVector(waypoint_t *wp1, waypoint_t *wp2, vecto
}
/*--------------------------------------------------
static INT32 K_BotStartDrift(player_t* player, ticcmd_t* cmd)
static INT32 K_BotStartDrift(player_t* player)
Begins and ends "forced" drifts on a per-waypoint basis.
Input Arguments:-
player - Player to begin the drift for.
cmd - The player's ticcmd to modify.
Return:-
Override value for turn amount.
--------------------------------------------------*/
static INT32 K_BotStartDrift(player_t* player, ticcmd_t* cmd)
static INT32 K_BotStartDrift(player_t* player)
{
// Handle DRIFTING towards waypoints!
boolean shouldDrift;
@ -1297,52 +1296,31 @@ static INT32 K_HandleBotTrack(player_t *player, ticcmd_t *cmd, botprediction_t *
turnamt = 0;
}
// Figure out if we need to drift.
// Drift-ending waypoints will kill the drift timer,
// so no need to worry about doing that ourselves.
driftamt = K_BotStartDrift(player, cmd);
// Start or continue a drift.
if (player->botvars.drifttime)
{
// Continue the drift until we go over the threshold.
// Confirm our drift angle.
if ((player->botvars.driftturn)
&& (player->botvars.drifttime < 2))
&& (player->botvars.drifttime < 4))
{
turnamt = KART_FULLTURN * -player->botvars.driftturn;
player->botvars.drifttime++;
}
// Only increment when we're finishing our drift!
if (((player->botvars.driftstate == DRIFTSTATE_ENDING) ||
(player->botvars.driftstate == DRIFTSTATE_AUTO)))
{
player->botvars.drifttime++;
}
cmd->buttons |= BT_DRIFT;
if (player->botvars.drifttime > BOTDRIFTTICS + 1)
{
player->botvars.drifttime = 0;
player->botvars.driftstate = DRIFTSTATE_AUTO;
}
}
else if ((turnamt) && (player->botvars.driftstate == DRIFTSTATE_AUTO) &&
(turnpower > FixedPercentage(DRIFTSTARTPCT)))
{
// TODO: Figure out a drift prediction system.
}
else if ((driftamt) && (player->botvars.driftstate))
else if ((player->botvars.driftamt < 2) && (player->botvars.driftstate))
{
if (driftamt != INT32_MAX)
cmd->buttons |= BT_DRIFT;
if (player->botvars.driftamt != INT32_MAX)
{
turnamt = driftamt;
cmd->buttons |= BT_DRIFT;
}
player->botvars.drifttime++;
}
}
@ -1781,6 +1759,40 @@ void K_UpdateBotGameplayVars(player_t *player)
player->botvars.respawnconfirm = 0;
}
else
{
// Figure out if we need to drift.
// Drift-ending waypoints will kill the drift timer,
// so no need to worry about doing that ourselves.
player->botvars.driftamt = K_BotStartDrift(player);
if (player->botvars.drifttime)
{
// Continue the drift until we go over the threshold.
// Only increment when we're finishing our drift, or
// just starting it!
if (((player->botvars.driftstate == DRIFTSTATE_ENDING) ||
(player->botvars.driftstate == DRIFTSTATE_AUTO)) ||
(player->botvars.drifttime < 4))
{
player->botvars.drifttime++;
}
if (player->botvars.drifttime > BOTDRIFTTICS + 3)
{
player->botvars.drifttime = 0;
player->botvars.driftstate = DRIFTSTATE_AUTO;
}
}
else if ((player->botvars.driftamt) && (player->botvars.driftstate))
{
if (player->botvars.driftamt != INT32_MAX)
{
// Ready to drift!
player->botvars.drifttime++;
}
}
}
K_UpdateBotGameplayVarsItemUsage(player);
}