Code cleanup

- K_FindBotController returns the line_t directly, instead of a linedef index.
- Trick panel code is in its own function.
- Try to fix infinite bot heat death
This commit is contained in:
Sally Coolatta 2021-12-12 02:32:03 -05:00
parent 0e43a04dee
commit cd0a259bbe
4 changed files with 84 additions and 45 deletions

View file

@ -288,11 +288,10 @@ boolean K_BotCanTakeCut(player_t *player)
} }
return false; return false;
#endif
} }
/*-------------------------------------------------- /*--------------------------------------------------
static INT16 K_FindBotController(mobj_t *mo) static line_t *K_FindBotController(mobj_t *mo)
Finds if any bot controller linedefs are tagged to the bot's sector. Finds if any bot controller linedefs are tagged to the bot's sector.
@ -300,9 +299,9 @@ boolean K_BotCanTakeCut(player_t *player)
mo - The bot player's mobj. mo - The bot player's mobj.
Return:- Return:-
Line number of the bot controller. -1 if it doesn't exist. Linedef of the bot controller. NULL if it doesn't exist.
--------------------------------------------------*/ --------------------------------------------------*/
static INT16 K_FindBotController(mobj_t *mo) static line_t *K_FindBotController(mobj_t *mo)
{ {
msecnode_t *node; msecnode_t *node;
ffloor_t *rover; ffloor_t *rover;
@ -324,7 +323,7 @@ static INT16 K_FindBotController(mobj_t *mo)
if (lineNum != -1) if (lineNum != -1)
{ {
return lineNum; break;
} }
for (rover = node->m_sector->ffloors; rover; rover = rover->next) for (rover = node->m_sector->ffloors; rover; rover = rover->next)
@ -347,12 +346,19 @@ static INT16 K_FindBotController(mobj_t *mo)
if (lineNum != -1) if (lineNum != -1)
{ {
return lineNum; break;
} }
} }
} }
return -1; if (lineNum != -1)
{
return &lines[lineNum];
}
else
{
return NULL;
}
} }
/*-------------------------------------------------- /*--------------------------------------------------
@ -418,7 +424,7 @@ fixed_t K_BotRubberband(player_t *player)
fixed_t rubberband = FRACUNIT; fixed_t rubberband = FRACUNIT;
fixed_t max, min; fixed_t max, min;
player_t *firstplace = NULL; player_t *firstplace = NULL;
INT16 botController = -1; line_t *botController = NULL;
UINT8 i; UINT8 i;
if (player->exiting) if (player->exiting)
@ -429,12 +435,10 @@ fixed_t K_BotRubberband(player_t *player)
botController = K_FindBotController(player->mo); botController = K_FindBotController(player->mo);
if (botController != -1) if (botController != NULL)
{ {
line_t *controllerLine = &lines[botController];
// No Climb Flag: Disable rubberbanding // No Climb Flag: Disable rubberbanding
if (controllerLine->flags & ML_NOCLIMB) if (botController->flags & ML_NOCLIMB)
{ {
return FRACUNIT; return FRACUNIT;
} }
@ -962,6 +966,50 @@ static void K_DrawPredictionDebug(botprediction_t *predict, player_t *player)
} }
} }
/*--------------------------------------------------
static void K_BotTrick(player_t *player, ticcmd_t *cmd, line_t *botController)
Determines inputs for trick panels.
Input Arguments:-
player - Player to generate the ticcmd for.
cmd - The player's ticcmd to modify.
botController - Linedef for the bot controller.
Return:-
None
--------------------------------------------------*/
static void K_BotTrick(player_t *player, ticcmd_t *cmd, line_t *botController)
{
// Trick panel state -- do nothing until a controller line is found, in which case do a trick.
if (botController == NULL)
{
return;
}
if (player->trickpanel == 1)
{
INT32 type = (sides[botController->sidenum[0]].rowoffset / FRACUNIT);
// Y Offset: Trick type
switch (type)
{
case 1:
cmd->turning = KART_FULLTURN;
break;
case 2:
cmd->turning = -KART_FULLTURN;
break;
case 3:
cmd->buttons |= BT_FORWARD;
break;
case 4:
cmd->buttons |= BT_BACKWARD;
break;
}
}
}
/*-------------------------------------------------- /*--------------------------------------------------
void K_BuildBotTiccmd(player_t *player, ticcmd_t *cmd) void K_BuildBotTiccmd(player_t *player, ticcmd_t *cmd)
@ -973,7 +1021,7 @@ void K_BuildBotTiccmd(player_t *player, ticcmd_t *cmd)
boolean trySpindash = true; boolean trySpindash = true;
UINT8 spindash = 0; UINT8 spindash = 0;
INT32 turnamt = 0; INT32 turnamt = 0;
INT16 botController = -1; line_t *botController = NULL;
// Can't build a ticcmd if we aren't spawned... // Can't build a ticcmd if we aren't spawned...
if (!player->mo) if (!player->mo)
@ -996,7 +1044,7 @@ void K_BuildBotTiccmd(player_t *player, ticcmd_t *cmd)
} }
// Complete override of all ticcmd functionality // Complete override of all ticcmd functionality
if (LUAh_BotTiccmd(player, cmd)) if (LUAh_BotTiccmd(player, cmd) == true)
{ {
return; return;
} }
@ -1005,30 +1053,7 @@ void K_BuildBotTiccmd(player_t *player, ticcmd_t *cmd)
if (player->trickpanel != 0) if (player->trickpanel != 0)
{ {
// Trick panel state -- do nothing until a controller line is found, in which case do a trick. K_BotTrick(player, cmd, botController);
if (player->trickpanel == 1 && botController != -1)
{
line_t *controllerLine = &lines[botController];
INT32 type = (sides[controllerLine->sidenum[0]].rowoffset / FRACUNIT);
// Y Offset: Trick type
switch (type)
{
case 1:
cmd->turning = KART_FULLTURN;
break;
case 2:
cmd->turning = -KART_FULLTURN;
break;
case 3:
cmd->buttons |= BT_FORWARD;
break;
case 4:
cmd->buttons |= BT_BACKWARD;
break;
}
}
// Don't do anything else. // Don't do anything else.
return; return;
@ -1037,20 +1062,19 @@ void K_BuildBotTiccmd(player_t *player, ticcmd_t *cmd)
if ((player->nextwaypoint != NULL if ((player->nextwaypoint != NULL
&& player->nextwaypoint->mobj != NULL && player->nextwaypoint->mobj != NULL
&& !P_MobjWasRemoved(player->nextwaypoint->mobj)) && !P_MobjWasRemoved(player->nextwaypoint->mobj))
|| (botController != -1)) || (botController != NULL))
{ {
// Handle steering towards waypoints! // Handle steering towards waypoints!
SINT8 turnsign = 0; SINT8 turnsign = 0;
angle_t destangle, moveangle, angle; angle_t destangle, moveangle, angle;
INT16 anglediff; INT16 anglediff;
if (botController != -1) if (botController != NULL)
{ {
const fixed_t dist = (player->mo->radius * 4); const fixed_t dist = (player->mo->radius * 4);
line_t *controllerLine = &lines[botController];
// X Offset: Movement direction // X Offset: Movement direction
destangle = FixedAngle(sides[controllerLine->sidenum[0]].textureoffset); destangle = FixedAngle(sides[botController->sidenum[0]].textureoffset);
// Overwritten prediction // Overwritten prediction
predict = Z_Calloc(sizeof(botprediction_t), PU_STATIC, NULL); predict = Z_Calloc(sizeof(botprediction_t), PU_STATIC, NULL);

View file

@ -223,8 +223,8 @@ void K_NudgePredictionTowardsObjects(botprediction_t *predict, player_t *player)
/*-------------------------------------------------- /*--------------------------------------------------
void K_BuildBotTiccmd(player_t *player, ticcmd_t *cmd); void K_BuildBotTiccmd(player_t *player, ticcmd_t *cmd);
Gives a multiplier for a bot's rubberbanding. Meant to be used for top speed, Creates a bot's ticcmd, looking at its surroundings to
acceleration, and handling. try and figure out what it should do.
Input Arguments:- Input Arguments:-
player - Player to generate the ticcmd for. player - Player to generate the ticcmd for.

View file

@ -19,6 +19,7 @@
#include "r_state.h" #include "r_state.h"
#include "k_bot.h" // K_BotHatesThisSector #include "k_bot.h" // K_BotHatesThisSector
#include "k_kart.h" // K_TripwirePass
// //
// P_CheckSight // P_CheckSight

View file

@ -2502,6 +2502,8 @@ static void P_ConsiderAllGone(void)
// //
static void P_DeathThink(player_t *player) static void P_DeathThink(player_t *player)
{ {
boolean playerGone = false;
player->deltaviewheight = 0; player->deltaviewheight = 0;
if (player->deadtimer < INT32_MAX) if (player->deadtimer < INT32_MAX)
@ -2522,7 +2524,19 @@ static void P_DeathThink(player_t *player)
K_KartPlayerHUDUpdate(player); K_KartPlayerHUDUpdate(player);
if (player->lives > 0 && !(player->pflags & PF_NOCONTEST) && player->deadtimer > TICRATE) if (player->pflags & PF_NOCONTEST)
{
playerGone = true;
}
else if (player->bot == false)
{
if (G_GametypeUsesLives() == true && player->lives == 0)
{
playerGone = true;
}
}
if (playerGone == false && player->deadtimer > TICRATE)
{ {
player->playerstate = PST_REBORN; player->playerstate = PST_REBORN;
} }