SRB2/src/b_bot.c

613 lines
17 KiB
C
Raw Normal View History

2014-03-15 16:59:03 +00:00
// SONIC ROBO BLAST 2
//-----------------------------------------------------------------------------
// Copyright (C) 2007-2016 by John "JTE" Muniz.
2021-05-07 15:45:56 +00:00
// Copyright (C) 2011-2021 by Sonic Team Junior.
2014-03-15 16:59:03 +00:00
//
// This program is free software distributed under the
// terms of the GNU General Public License, version 2.
// See the 'LICENSE' file for more details.
//-----------------------------------------------------------------------------
/// \file b_bot.c
/// \brief Basic bot handling
#include "doomdef.h"
#include "d_player.h"
#include "g_game.h"
#include "r_main.h"
#include "p_local.h"
#include "b_bot.h"
#include "lua_hook.h"
2021-01-23 15:25:35 +00:00
void B_UpdateBotleader(player_t *player)
2019-11-18 05:30:07 +00:00
{
2021-01-23 15:25:35 +00:00
UINT32 i;
fixed_t dist;
fixed_t neardist = INT32_MAX;
player_t *nearplayer = NULL;
//Find new botleader
for (i = 0; i < MAXPLAYERS; i++)
{
if (players[i].bot || players[i].playerstate != PST_LIVE || players[i].spectator || !players[i].mo)
continue;
if (!player->mo) //Can't do distance calculations if there's no player object, so we'll just take the first we find
{
player->botleader = &players[i];
return;
}
//Update best candidate based on nearest distance
dist = R_PointToDist2(player->mo->x, player->mo->y, players[i].mo->x, players[i].mo->y);
if (neardist > dist)
{
neardist = dist;
nearplayer = &players[i];
}
}
//Set botleader to best candidate (or null if none available)
player->botleader = nearplayer;
}
static inline void B_ResetAI(botmem_t *mem)
{
mem->thinkstate = AI_FOLLOW;
mem->catchup_tics = 0;
2019-11-18 05:30:07 +00:00
}
2019-12-02 17:12:26 +00:00
static void B_BuildTailsTiccmd(mobj_t *sonic, mobj_t *tails, ticcmd_t *cmd)
2014-03-15 16:59:03 +00:00
{
boolean forward=false, backward=false, left=false, right=false, jump=false, spin=false;
2019-10-03 04:49:46 +00:00
player_t *player = sonic->player, *bot = tails->player;
ticcmd_t *pcmd = &player->cmd;
2021-01-23 15:25:35 +00:00
botmem_t *mem = &bot->botmem;
boolean water = (tails->eflags & MFE_UNDERWATER);
2019-11-18 23:55:21 +00:00
SINT8 flip = P_MobjFlip(tails);
2019-10-03 04:49:46 +00:00
boolean _2d = (tails->flags2 & MF2_TWOD) || twodlevel;
fixed_t scale = tails->scale;
2021-01-23 15:25:35 +00:00
boolean jump_last = (bot->lastbuttons & BT_JUMP);
boolean spin_last = (bot->lastbuttons & BT_SPIN);
2019-10-03 04:49:46 +00:00
fixed_t dist = P_AproxDistance(sonic->x - tails->x, sonic->y - tails->y);
fixed_t zdist = flip * (sonic->z - tails->z);
angle_t ang = sonic->angle;
2019-10-03 04:49:46 +00:00
fixed_t pmom = P_AproxDistance(sonic->momx, sonic->momy);
fixed_t bmom = P_AproxDistance(tails->momx, tails->momy);
2021-01-23 15:25:35 +00:00
fixed_t followmax = 128 * 8 * scale; // Max follow distance before AI begins to enter catchup state
fixed_t followthres = 92 * scale; // Distance that AI will try to reach
2019-10-03 04:49:46 +00:00
fixed_t followmin = 32 * scale;
fixed_t comfortheight = 96 * scale;
fixed_t touchdist = 24 * scale;
boolean stalled = (bmom < scale >> 1) && dist > followthres; // Helps to see if the AI is having trouble catching up
boolean samepos = (sonic->x == tails->x && sonic->y == tails->y);
2021-01-23 15:25:35 +00:00
boolean blocked = bot->blocked;
if (!samepos)
ang = R_PointToAngle2(tails->x, tails->y, sonic->x, sonic->y);
2014-03-15 16:59:03 +00:00
// Lua can handle it!
if (LUA_HookBotAI(sonic, tails, cmd))
2014-03-15 16:59:03 +00:00
return;
2021-01-23 15:25:35 +00:00
// We can't follow Sonic if he's not around!
if (!sonic || sonic->health <= 0)
{
mem->thinkstate = AI_STANDBY;
return;
}
else if (mem->thinkstate == AI_STANDBY)
mem->thinkstate = AI_FOLLOW;
if (tails->player->powers[pw_carry] == CR_MACESPIN || tails->player->powers[pw_carry] == CR_GENERIC)
2014-03-15 16:59:03 +00:00
{
boolean isrelevant = (sonic->player->powers[pw_carry] == CR_MACESPIN || sonic->player->powers[pw_carry] == CR_GENERIC);
if (sonic->player->cmd.buttons & BT_JUMP && (sonic->player->pflags & PF_JUMPED) && isrelevant)
2014-03-15 16:59:03 +00:00
cmd->buttons |= BT_JUMP;
if (isrelevant)
2014-03-15 16:59:03 +00:00
{
cmd->forwardmove = sonic->player->cmd.forwardmove;
cmd->angleturn = abs((signed)(tails->angle - sonic->angle))>>16;
2014-03-15 16:59:03 +00:00
if (sonic->angle < tails->angle)
cmd->angleturn = -cmd->angleturn;
} else if (dist > FixedMul(512*FRACUNIT, tails->scale))
cmd->buttons |= BT_JUMP;
return;
}
2019-10-03 04:49:46 +00:00
// Adapted from CobaltBW's tails_AI.wad
2019-10-03 04:49:46 +00:00
// Check water
if (water)
{
followmin = 0;
followthres = 16*scale;
followmax >>= 1;
2021-01-23 15:25:35 +00:00
if (mem->thinkstate == AI_THINKFLY)
mem->thinkstate = AI_FOLLOW;
2019-10-03 04:49:46 +00:00
}
2021-01-23 15:25:35 +00:00
// Update catchup_tics
if (mem->thinkstate == AI_SPINFOLLOW)
2019-10-03 04:49:46 +00:00
{
2021-01-23 15:25:35 +00:00
mem-> catchup_tics = 0;
2019-10-03 04:49:46 +00:00
}
else if (dist > followmax || zdist > comfortheight || stalled)
2019-10-03 04:49:46 +00:00
{
2021-01-23 15:25:35 +00:00
mem-> catchup_tics = min(mem-> catchup_tics + 2, 70);
if (mem-> catchup_tics >= 70)
mem->thinkstate = AI_CATCHUP;
2019-10-03 04:49:46 +00:00
}
2014-03-15 16:59:03 +00:00
else
2019-10-03 04:49:46 +00:00
{
2021-01-23 15:25:35 +00:00
mem-> catchup_tics = max(mem-> catchup_tics - 1, 0);
if (mem->thinkstate == AI_CATCHUP)
mem->thinkstate = AI_FOLLOW;
2014-03-15 16:59:03 +00:00
}
2019-10-03 04:49:46 +00:00
// Orientation
2021-01-23 15:25:35 +00:00
// cmd->angleturn won't be relative to player angle, since we're not going through G_BuildTiccmd.
if (bot->pflags & (PF_SPINNING|PF_STARTDASH))
2019-10-03 04:49:46 +00:00
{
2021-01-23 15:25:35 +00:00
cmd->angleturn = (sonic->angle) >> 16; // NOT FRACBITS DAMNIT
}
2021-01-23 15:25:35 +00:00
else if (mem->thinkstate == AI_FLYCARRY)
{
2021-01-23 15:25:35 +00:00
cmd->angleturn = sonic->player->cmd.angleturn;
2019-10-03 04:49:46 +00:00
}
else
{
2021-01-23 15:25:35 +00:00
cmd->angleturn = (ang) >> 16; // NOT FRACBITS DAMNIT
2019-10-03 04:49:46 +00:00
}
2019-10-03 04:49:46 +00:00
// ********
// FLY MODE
2021-01-23 15:25:35 +00:00
// exiting check
if (player->exiting && mem->thinkstate == AI_THINKFLY)
mem->thinkstate = AI_FOLLOW;
2019-10-03 04:49:46 +00:00
else
{
// Activate co-op flight
2021-01-23 15:25:35 +00:00
if (mem->thinkstate == AI_THINKFLY && player->pflags & PF_JUMPED)
2019-10-03 04:49:46 +00:00
{
if (!jump_last)
{
jump = true;
2021-01-23 15:25:35 +00:00
mem->thinkstate = AI_FLYSTANDBY;
2019-11-18 05:30:07 +00:00
bot->pflags |= PF_CANCARRY;
2019-10-03 04:49:46 +00:00
}
}
2019-10-03 04:49:46 +00:00
// Check positioning
// Thinker for co-op flight
if (!(water || pmom || bmom)
&& (dist < touchdist && !samepos)
2019-10-03 04:49:46 +00:00
&& !(pcmd->forwardmove || pcmd->sidemove || player->dashspeed)
&& P_IsObjectOnGround(sonic) && P_IsObjectOnGround(tails)
&& !(player->pflags & PF_STASIS)
&& bot->charability == CA_FLY)
2021-01-23 15:25:35 +00:00
mem->thinkstate = AI_THINKFLY;
else if (mem->thinkstate == AI_THINKFLY)
mem->thinkstate = AI_FOLLOW;
2019-11-18 03:22:27 +00:00
// Set carried state
if (player->powers[pw_carry] == CR_PLAYER && sonic->tracer == tails)
{
2021-01-23 15:25:35 +00:00
mem->thinkstate = AI_FLYCARRY;
}
2019-10-03 04:49:46 +00:00
// Ready for takeoff
2021-01-23 15:25:35 +00:00
if (mem->thinkstate == AI_FLYSTANDBY)
2019-10-03 04:49:46 +00:00
{
if (zdist < -64*scale || (flip * tails->momz) > scale) // Make sure we're not too high up
spin = true;
else if (!jump_last)
jump = true;
2019-12-06 18:49:42 +00:00
2019-10-03 04:49:46 +00:00
// Abort if the player moves away or spins
if (dist > followthres || player->dashspeed)
2021-01-23 15:25:35 +00:00
mem->thinkstate = AI_FOLLOW;
2019-10-03 04:49:46 +00:00
}
2019-11-18 03:22:27 +00:00
// Read player inputs while carrying
2021-01-23 15:25:35 +00:00
else if (mem->thinkstate == AI_FLYCARRY)
2019-10-03 04:49:46 +00:00
{
cmd->forwardmove = pcmd->forwardmove;
cmd->sidemove = pcmd->sidemove;
if (pcmd->buttons & BT_SPIN)
2019-10-03 04:49:46 +00:00
{
spin = true;
jump = false;
}
else if (!jump_last)
jump = true;
// End flymode
if (player->powers[pw_carry] != CR_PLAYER)
2019-10-03 04:49:46 +00:00
{
2021-01-23 15:25:35 +00:00
mem->thinkstate = AI_FOLLOW;
2019-10-03 04:49:46 +00:00
}
}
}
2019-11-18 03:22:27 +00:00
2021-01-23 15:25:35 +00:00
if (P_IsObjectOnGround(tails) && !(pcmd->buttons & BT_JUMP) && (mem->thinkstate == AI_FLYSTANDBY || mem->thinkstate == AI_FLYCARRY))
mem->thinkstate = AI_FOLLOW;
2019-11-18 03:22:27 +00:00
2019-10-03 04:49:46 +00:00
// ********
// SPINNING
2021-01-23 15:25:35 +00:00
if (!(player->pflags & (PF_SPINNING|PF_STARTDASH)) && mem->thinkstate == AI_SPINFOLLOW)
mem->thinkstate = AI_FOLLOW;
else if (mem->thinkstate == AI_FOLLOW || mem->thinkstate == AI_SPINFOLLOW)
2019-10-03 04:49:46 +00:00
{
if (!_2d)
{
// Spindash
if (player->dashspeed)
{
if (dist < followthres && dist > touchdist) // Do positioning
{
2021-01-23 15:25:35 +00:00
cmd->angleturn = (ang) >> 16; // NOT FRACBITS DAMNIT
2019-10-03 04:49:46 +00:00
cmd->forwardmove = 50;
2021-01-23 15:25:35 +00:00
mem->thinkstate = AI_SPINFOLLOW;
2019-10-03 04:49:46 +00:00
}
2019-10-04 19:02:27 +00:00
else if (dist < touchdist)
2019-10-03 04:49:46 +00:00
{
2019-10-04 19:02:27 +00:00
if (!bmom && (!(bot->pflags & PF_SPINNING) || (bot->dashspeed && bot->pflags & PF_SPINNING)))
{
2021-01-23 15:25:35 +00:00
cmd->angleturn = (sonic->angle) >> 16; // NOT FRACBITS DAMNIT
2019-10-04 19:02:27 +00:00
spin = true;
}
2021-01-23 15:25:35 +00:00
mem->thinkstate = AI_SPINFOLLOW;
2019-10-03 04:49:46 +00:00
}
else
2021-01-23 15:25:35 +00:00
mem->thinkstate = AI_FOLLOW;
2019-10-03 04:49:46 +00:00
}
// Spin
else if (player->dashspeed == bot->dashspeed && player->pflags & PF_SPINNING)
{
if (bot->pflags & PF_SPINNING || !spin_last)
{
spin = true;
2021-01-23 15:25:35 +00:00
cmd->angleturn = (sonic->angle) >> 16; // NOT FRACBITS DAMNIT
2019-10-03 04:49:46 +00:00
cmd->forwardmove = MAXPLMOVE;
2021-01-23 15:25:35 +00:00
mem->thinkstate = AI_SPINFOLLOW;
2019-10-03 04:49:46 +00:00
}
else
2021-01-23 15:25:35 +00:00
mem->thinkstate = AI_FOLLOW;
2019-10-03 04:49:46 +00:00
}
}
// 2D mode
else
{
2019-11-18 03:22:27 +00:00
if (((player->dashspeed && !bmom) || (player->dashspeed == bot->dashspeed && (player->pflags & PF_SPINNING)))
&& ((bot->pflags & PF_SPINNING) || !spin_last))
2019-10-03 04:49:46 +00:00
{
spin = true;
2021-01-23 15:25:35 +00:00
mem->thinkstate = AI_SPINFOLLOW;
2019-10-03 04:49:46 +00:00
}
2021-01-23 15:25:35 +00:00
else
mem->thinkstate = AI_FOLLOW;
2019-10-03 04:49:46 +00:00
}
2014-03-15 16:59:03 +00:00
}
2019-11-18 03:22:27 +00:00
2019-10-03 04:49:46 +00:00
// ********
// FOLLOW
2021-01-23 15:25:35 +00:00
if (mem->thinkstate == AI_FOLLOW || mem->thinkstate == AI_CATCHUP)
2019-10-03 04:49:46 +00:00
{
// Too far
2021-01-23 15:25:35 +00:00
if (mem->thinkstate == AI_CATCHUP || dist > followthres)
2019-10-03 04:49:46 +00:00
{
if (!_2d)
cmd->forwardmove = MAXPLMOVE;
else if (sonic->x > tails->x)
cmd->sidemove = MAXPLMOVE;
else
cmd->sidemove = -MAXPLMOVE;
}
// Within threshold
2021-01-23 15:25:35 +00:00
else if (dist > followmin && abs(zdist) < 192*scale)
2019-10-03 04:49:46 +00:00
{
if (!_2d)
cmd->forwardmove = FixedHypot(pcmd->forwardmove, pcmd->sidemove);
else
cmd->sidemove = pcmd->sidemove;
}
// Below min
else if (dist < followmin)
{
// Copy inputs
2021-01-23 15:25:35 +00:00
cmd->angleturn = (sonic->angle) >> 16; // NOT FRACBITS DAMNIT
2019-11-18 03:22:27 +00:00
bot->drawangle = ang;
2019-10-03 04:49:46 +00:00
cmd->forwardmove = 8 * pcmd->forwardmove / 10;
cmd->sidemove = 8 * pcmd->sidemove / 10;
}
}
2019-12-06 18:49:42 +00:00
2019-10-03 04:49:46 +00:00
// ********
// JUMP
2021-01-23 15:25:35 +00:00
if (mem->thinkstate == AI_FOLLOW || mem->thinkstate == AI_CATCHUP || (mem->thinkstate == AI_SPINFOLLOW && player->pflags & PF_JUMPED))
2019-10-03 04:49:46 +00:00
{
// Flying catch-up
if (bot->pflags & PF_THOKKED)
{
2019-11-18 03:22:27 +00:00
cmd->forwardmove = min(MAXPLMOVE, (dist/scale)>>3);
2019-10-03 04:49:46 +00:00
if (zdist < -64*scale)
spin = true;
else if (zdist > 0 && !jump_last)
jump = true;
}
2019-11-18 03:22:27 +00:00
2019-10-03 04:49:46 +00:00
// Just landed
if (tails->eflags & MFE_JUSTHITFLOOR)
jump = false;
// Start jump
2019-11-18 03:22:27 +00:00
else if (!jump_last && !(bot->pflags & PF_JUMPED) //&& !(player->pflags & PF_SPINNING)
2019-10-03 04:49:46 +00:00
&& ((zdist > 32*scale && player->pflags & PF_JUMPED) // Following
2021-01-23 15:25:35 +00:00
|| (zdist > 64*scale && mem->thinkstate == AI_CATCHUP) // Vertical catch-up
|| (stalled && mem-> catchup_tics > 20 && bot->powers[pw_carry] == CR_NONE)
2019-11-18 03:22:27 +00:00
//|| (bmom < scale>>3 && dist > followthres && !(bot->powers[pw_carry])) // Stopped & not in carry state
2019-10-03 04:49:46 +00:00
|| (bot->pflags & PF_SPINNING && !(bot->pflags & PF_JUMPED)))) // Spinning
jump = true;
// Hold jump
2021-01-23 15:25:35 +00:00
else if (bot->pflags & PF_JUMPED && jump_last && tails->momz*flip > 0 && (zdist > 0 || mem->thinkstate == AI_CATCHUP))
2014-03-15 16:59:03 +00:00
jump = true;
2019-10-03 04:49:46 +00:00
// Start flying
2021-01-23 15:25:35 +00:00
else if (bot->pflags & PF_JUMPED && mem->thinkstate == AI_CATCHUP && !jump_last && bot->charability == CA_FLY)
2014-03-15 16:59:03 +00:00
jump = true;
}
2019-11-18 03:22:27 +00:00
2019-10-03 04:49:46 +00:00
// ********
// HISTORY
2021-01-23 15:25:35 +00:00
//jump_last = jump;
//spin_last = spin;
2019-11-18 03:22:27 +00:00
2014-03-15 16:59:03 +00:00
// Turn the virtual keypresses into ticcmd_t.
B_KeysToTiccmd(tails, cmd, forward, backward, left, right, false, false, jump, spin);
// Update our status
2021-01-23 15:25:35 +00:00
mem->lastForward = forward;
mem->lastBlocked = blocked;
2014-03-15 16:59:03 +00:00
}
void B_BuildTiccmd(player_t *player, ticcmd_t *cmd)
{
// Can't build a ticcmd if we aren't spawned...
if (!player->mo)
return;
if (player->playerstate == PST_DEAD)
{
if (B_CheckRespawn(player))
cmd->buttons |= BT_JUMP;
return;
}
// Bot AI isn't programmed in analog.
CV_SetValue(&cv_analog[1], false);
2014-03-15 16:59:03 +00:00
// Let Lua scripts build ticcmds
if (LUA_HookTiccmd(player, cmd, HOOK(BotTiccmd)))
2014-03-15 16:59:03 +00:00
return;
2021-01-23 15:25:35 +00:00
// Make sure we have a valid main character to follow
B_UpdateBotleader(player);
if (!player->botleader)
2014-03-15 16:59:03 +00:00
return;
2021-01-23 15:25:35 +00:00
// Single Player Tails AI
//B_BuildTailsTiccmd(players[consoleplayer].mo, player->mo, cmd);
B_BuildTailsTiccmd(player->botleader->mo, player->mo, cmd);
2014-03-15 16:59:03 +00:00
}
void B_KeysToTiccmd(mobj_t *mo, ticcmd_t *cmd, boolean forward, boolean backward, boolean left, boolean right, boolean strafeleft, boolean straferight, boolean jump, boolean spin)
{
2021-01-23 15:25:35 +00:00
player_t *player = mo->player;
// don't try to do stuff if your sonic is in a minecart or something
2021-01-23 15:25:35 +00:00
if (&player->botleader && player->botleader->powers[pw_carry] && player->botleader->powers[pw_carry] != CR_PLAYER)
return;
2014-03-15 16:59:03 +00:00
// Turn the virtual keypresses into ticcmd_t.
if (twodlevel || mo->flags2 & MF2_TWOD) {
2021-01-23 15:25:35 +00:00
if (player->botleader->climbing
2014-03-15 16:59:03 +00:00
|| mo->player->pflags & PF_GLIDING) {
// Don't mess with bot inputs during these unhandled movement conditions.
// The normal AI doesn't use abilities, so custom AI should be sending us exactly what it wants anyway.
if (forward)
cmd->forwardmove += MAXPLMOVE<<FRACBITS>>16;
if (backward)
cmd->forwardmove -= MAXPLMOVE<<FRACBITS>>16;
if (left || strafeleft)
cmd->sidemove -= MAXPLMOVE<<FRACBITS>>16;
if (right || straferight)
cmd->sidemove += MAXPLMOVE<<FRACBITS>>16;
} else {
// In standard 2D mode, interpret "forward" as "the way you're facing" and everything else as "the way you're not facing"
if (left || right)
backward = true;
left = right = false;
if (forward) {
if (mo->angle < ANGLE_90 || mo->angle > ANGLE_270)
right = true;
else
left = true;
} else if (backward) {
if (mo->angle < ANGLE_90 || mo->angle > ANGLE_270)
left = true;
else
right = true;
}
if (left || strafeleft)
cmd->sidemove -= MAXPLMOVE<<FRACBITS>>16;
if (right || straferight)
cmd->sidemove += MAXPLMOVE<<FRACBITS>>16;
}
} else {
angle_t angle;
2014-03-15 16:59:03 +00:00
if (forward)
cmd->forwardmove += MAXPLMOVE<<FRACBITS>>16;
if (backward)
cmd->forwardmove -= MAXPLMOVE<<FRACBITS>>16;
2021-01-23 15:25:35 +00:00
if (left)
2014-03-15 16:59:03 +00:00
cmd->angleturn += 1280;
if (right)
2021-01-23 15:25:35 +00:00
cmd->angleturn -= 1280;
2014-03-15 16:59:03 +00:00
if (strafeleft)
cmd->sidemove -= MAXPLMOVE<<FRACBITS>>16;
if (straferight)
cmd->sidemove += MAXPLMOVE<<FRACBITS>>16;
2019-12-06 18:49:42 +00:00
2019-10-03 04:49:46 +00:00
// cap inputs so the bot can't accelerate faster diagonally
angle = R_PointToAngle2(0, 0, cmd->sidemove << FRACBITS, cmd->forwardmove << FRACBITS);
2019-11-18 23:52:14 +00:00
{
INT32 maxforward = abs(P_ReturnThrustY(NULL, angle, MAXPLMOVE));
INT32 maxside = abs(P_ReturnThrustX(NULL, angle, MAXPLMOVE));
cmd->forwardmove = max(min(cmd->forwardmove, maxforward), -maxforward);
cmd->sidemove = max(min(cmd->sidemove, maxside), -maxside);
}
2014-03-15 16:59:03 +00:00
}
if (jump)
cmd->buttons |= BT_JUMP;
if (spin)
cmd->buttons |= BT_SPIN;
2014-03-15 16:59:03 +00:00
}
void B_MoveBlocked(player_t *player)
{
(void)player;
2021-01-23 15:25:35 +00:00
player->blocked = true;
2014-03-15 16:59:03 +00:00
}
boolean B_CheckRespawn(player_t *player)
{
2021-01-23 15:25:35 +00:00
mobj_t *sonic;
2014-03-15 16:59:03 +00:00
mobj_t *tails = player->mo;
2021-01-23 15:25:35 +00:00
//We don't have a main player to spawn to!
if (!player->botleader)
return false;
sonic = player->botleader->mo;
2014-03-15 16:59:03 +00:00
// We can't follow Sonic if he's not around!
if (!sonic || sonic->health <= 0)
return false;
// B_RespawnBot doesn't do anything if the condition above this isn't met
{
UINT8 shouldForce = LUA_Hook2Mobj(sonic, tails, MOBJ_HOOK(BotRespawn));
if (P_MobjWasRemoved(sonic) || P_MobjWasRemoved(tails))
return (shouldForce == 1); // mobj was removed
if (shouldForce == 1)
return true;
else if (shouldForce == 2)
return false;
}
2014-03-15 16:59:03 +00:00
// Check if Sonic is busy first.
// If he's doing any of these things, he probably doesn't want to see us.
if (sonic->player->pflags & (PF_GLIDING|PF_SLIDING|PF_BOUNCING)
|| (sonic->player->panim != PA_IDLE && sonic->player->panim != PA_WALK)
2019-11-18 05:30:07 +00:00
|| (sonic->player->powers[pw_carry] && sonic->player->powers[pw_carry] != CR_PLAYER))
2014-03-15 16:59:03 +00:00
return false;
// Low ceiling, do not want!
if (sonic->eflags & MFE_VERTICALFLIP)
{
if (sonic->z - sonic->floorz < (sonic->player->exiting ? 5 : 2)*sonic->height)
return false;
}
else if (sonic->ceilingz - sonic->z < (sonic->player->exiting ? 6 : 3)*sonic->height)
2014-03-15 16:59:03 +00:00
return false;
// If you're dead, wait a few seconds to respawn.
if (player->playerstate == PST_DEAD) {
if (player->deadtimer > 4*TICRATE)
return true;
return false;
}
// If you can't see Sonic, I guess we should?
if (!P_CheckSight(sonic, tails) && P_AproxDistance(P_AproxDistance(tails->x-sonic->x, tails->y-sonic->y), tails->z-sonic->z) > FixedMul(1024*FRACUNIT, tails->scale))
return true;
return false;
}
void B_RespawnBot(INT32 playernum)
{
player_t *player = &players[playernum];
fixed_t x,y,z;
2021-01-23 15:25:35 +00:00
mobj_t *sonic;
2014-03-15 16:59:03 +00:00
mobj_t *tails;
2021-01-23 15:25:35 +00:00
if (!player->botleader)
return;
sonic = player->botleader->mo;
2014-03-15 16:59:03 +00:00
if (!sonic || sonic->health <= 0)
return;
2021-01-23 15:25:35 +00:00
B_ResetAI(&player->botmem);
2019-11-18 05:30:07 +00:00
2021-01-23 15:25:35 +00:00
player->bot = BOT_2PAI;
2014-03-15 16:59:03 +00:00
P_SpawnPlayer(playernum);
tails = player->mo;
x = sonic->x;
y = sonic->y;
if (sonic->eflags & MFE_VERTICALFLIP) {
tails->eflags |= MFE_VERTICALFLIP;
z = sonic->z - (512*sonic->scale);
2014-03-15 16:59:03 +00:00
if (z < sonic->floorz)
z = sonic->floorz;
} else {
z = sonic->z + sonic->height + (512*sonic->scale);
2014-03-15 16:59:03 +00:00
if (z > sonic->ceilingz - sonic->height)
z = sonic->ceilingz - sonic->height;
}
if (sonic->flags2 & MF2_OBJECTFLIP)
tails->flags2 |= MF2_OBJECTFLIP;
if (sonic->flags2 & MF2_TWOD)
tails->flags2 |= MF2_TWOD;
if (sonic->eflags & MFE_UNDERWATER)
tails->eflags |= MFE_UNDERWATER;
player->powers[pw_underwater] = sonic->player->powers[pw_underwater];
player->powers[pw_spacetime] = sonic->player->powers[pw_spacetime];
player->powers[pw_gravityboots] = sonic->player->powers[pw_gravityboots];
player->powers[pw_nocontrol] = sonic->player->powers[pw_nocontrol];
player->pflags |= PF_AUTOBRAKE|(sonic->player->pflags & PF_DIRECTIONCHAR);
2014-03-15 16:59:03 +00:00
P_TeleportMove(tails, x, y, z);
if (player->charability == CA_FLY)
{
P_SetPlayerMobjState(tails, S_PLAY_FLY);
2014-03-15 16:59:03 +00:00
tails->player->powers[pw_tailsfly] = (UINT16)-1;
}
else
P_SetPlayerMobjState(tails, S_PLAY_FALL);
2014-03-15 16:59:03 +00:00
P_SetScale(tails, sonic->scale);
tails->destscale = sonic->destscale;
}
void B_HandleFlightIndicator(player_t *player)
{
2019-12-31 08:55:36 +00:00
mobj_t *tails = player->mo;
2021-01-23 15:25:35 +00:00
botmem_t *mem = &player->botmem;
if (!tails)
return;
2021-01-23 15:25:35 +00:00
if (mem->thinkstate == AI_THINKFLY && player->bot == BOT_2PAI && tails->health)
{
if (!tails->hnext)
{
P_SetTarget(&tails->hnext, P_SpawnMobjFromMobj(tails, 0, 0, 0, MT_OVERLAY));
if (tails->hnext)
{
P_SetTarget(&tails->hnext->target, tails);
P_SetTarget(&tails->hnext->hprev, tails);
P_SetMobjState(tails->hnext, S_FLIGHTINDICATOR);
}
}
}
else if (tails->hnext && tails->hnext->type == MT_OVERLAY && tails->hnext->state == states+S_FLIGHTINDICATOR)
{
P_RemoveMobj(tails->hnext);
P_SetTarget(&tails->hnext, NULL);
}
}