mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2025-12-24 08:52:33 +00:00
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:
parent
0e43a04dee
commit
cd0a259bbe
4 changed files with 84 additions and 45 deletions
108
src/k_bot.c
108
src/k_bot.c
|
|
@ -288,11 +288,10 @@ boolean K_BotCanTakeCut(player_t *player)
|
|||
}
|
||||
|
||||
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.
|
||||
|
||||
|
|
@ -300,9 +299,9 @@ boolean K_BotCanTakeCut(player_t *player)
|
|||
mo - The bot player's mobj.
|
||||
|
||||
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;
|
||||
ffloor_t *rover;
|
||||
|
|
@ -324,7 +323,7 @@ static INT16 K_FindBotController(mobj_t *mo)
|
|||
|
||||
if (lineNum != -1)
|
||||
{
|
||||
return lineNum;
|
||||
break;
|
||||
}
|
||||
|
||||
for (rover = node->m_sector->ffloors; rover; rover = rover->next)
|
||||
|
|
@ -347,12 +346,19 @@ static INT16 K_FindBotController(mobj_t *mo)
|
|||
|
||||
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 max, min;
|
||||
player_t *firstplace = NULL;
|
||||
INT16 botController = -1;
|
||||
line_t *botController = NULL;
|
||||
UINT8 i;
|
||||
|
||||
if (player->exiting)
|
||||
|
|
@ -429,12 +435,10 @@ fixed_t K_BotRubberband(player_t *player)
|
|||
|
||||
botController = K_FindBotController(player->mo);
|
||||
|
||||
if (botController != -1)
|
||||
if (botController != NULL)
|
||||
{
|
||||
line_t *controllerLine = &lines[botController];
|
||||
|
||||
// No Climb Flag: Disable rubberbanding
|
||||
if (controllerLine->flags & ML_NOCLIMB)
|
||||
if (botController->flags & ML_NOCLIMB)
|
||||
{
|
||||
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)
|
||||
|
||||
|
|
@ -973,7 +1021,7 @@ void K_BuildBotTiccmd(player_t *player, ticcmd_t *cmd)
|
|||
boolean trySpindash = true;
|
||||
UINT8 spindash = 0;
|
||||
INT32 turnamt = 0;
|
||||
INT16 botController = -1;
|
||||
line_t *botController = NULL;
|
||||
|
||||
// Can't build a ticcmd if we aren't spawned...
|
||||
if (!player->mo)
|
||||
|
|
@ -996,7 +1044,7 @@ void K_BuildBotTiccmd(player_t *player, ticcmd_t *cmd)
|
|||
}
|
||||
|
||||
// Complete override of all ticcmd functionality
|
||||
if (LUAh_BotTiccmd(player, cmd))
|
||||
if (LUAh_BotTiccmd(player, cmd) == true)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
@ -1005,30 +1053,7 @@ void K_BuildBotTiccmd(player_t *player, ticcmd_t *cmd)
|
|||
|
||||
if (player->trickpanel != 0)
|
||||
{
|
||||
// Trick panel state -- do nothing until a controller line is found, in which case do a trick.
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
K_BotTrick(player, cmd, botController);
|
||||
|
||||
// Don't do anything else.
|
||||
return;
|
||||
|
|
@ -1037,20 +1062,19 @@ void K_BuildBotTiccmd(player_t *player, ticcmd_t *cmd)
|
|||
if ((player->nextwaypoint != NULL
|
||||
&& player->nextwaypoint->mobj != NULL
|
||||
&& !P_MobjWasRemoved(player->nextwaypoint->mobj))
|
||||
|| (botController != -1))
|
||||
|| (botController != NULL))
|
||||
{
|
||||
// Handle steering towards waypoints!
|
||||
SINT8 turnsign = 0;
|
||||
angle_t destangle, moveangle, angle;
|
||||
INT16 anglediff;
|
||||
|
||||
if (botController != -1)
|
||||
if (botController != NULL)
|
||||
{
|
||||
const fixed_t dist = (player->mo->radius * 4);
|
||||
line_t *controllerLine = &lines[botController];
|
||||
|
||||
// X Offset: Movement direction
|
||||
destangle = FixedAngle(sides[controllerLine->sidenum[0]].textureoffset);
|
||||
destangle = FixedAngle(sides[botController->sidenum[0]].textureoffset);
|
||||
|
||||
// Overwritten prediction
|
||||
predict = Z_Calloc(sizeof(botprediction_t), PU_STATIC, NULL);
|
||||
|
|
|
|||
|
|
@ -223,8 +223,8 @@ void K_NudgePredictionTowardsObjects(botprediction_t *predict, player_t *player)
|
|||
/*--------------------------------------------------
|
||||
void K_BuildBotTiccmd(player_t *player, ticcmd_t *cmd);
|
||||
|
||||
Gives a multiplier for a bot's rubberbanding. Meant to be used for top speed,
|
||||
acceleration, and handling.
|
||||
Creates a bot's ticcmd, looking at its surroundings to
|
||||
try and figure out what it should do.
|
||||
|
||||
Input Arguments:-
|
||||
player - Player to generate the ticcmd for.
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
#include "r_state.h"
|
||||
|
||||
#include "k_bot.h" // K_BotHatesThisSector
|
||||
#include "k_kart.h" // K_TripwirePass
|
||||
|
||||
//
|
||||
// P_CheckSight
|
||||
|
|
|
|||
16
src/p_user.c
16
src/p_user.c
|
|
@ -2502,6 +2502,8 @@ static void P_ConsiderAllGone(void)
|
|||
//
|
||||
static void P_DeathThink(player_t *player)
|
||||
{
|
||||
boolean playerGone = false;
|
||||
|
||||
player->deltaviewheight = 0;
|
||||
|
||||
if (player->deadtimer < INT32_MAX)
|
||||
|
|
@ -2522,7 +2524,19 @@ static void P_DeathThink(player_t *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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue