2006-02-24 04:48:15 +00:00
|
|
|
/********************************
|
|
|
|
* B_Think.c *
|
|
|
|
* Description: *
|
|
|
|
* Movement/Roaming code for *
|
|
|
|
* the bot's *
|
|
|
|
*********************************/
|
|
|
|
|
|
|
|
#include "doomdef.h"
|
|
|
|
#include "doomstat.h"
|
|
|
|
#include "p_local.h"
|
|
|
|
#include "b_bot.h"
|
|
|
|
#include "g_game.h"
|
|
|
|
#include "d_ticcmd.h"
|
|
|
|
#include "m_random.h"
|
|
|
|
#include "i_system.h"
|
|
|
|
#include "p_lnspec.h"
|
|
|
|
#include "gi.h"
|
|
|
|
#include "a_keys.h"
|
2008-09-14 23:54:38 +00:00
|
|
|
#include "d_event.h"
|
2014-10-13 07:45:36 +00:00
|
|
|
#include "p_enemy.h"
|
2016-02-15 01:14:34 +00:00
|
|
|
#include "d_player.h"
|
|
|
|
#include "p_spec.h"
|
2016-02-15 12:40:31 +00:00
|
|
|
#include "p_checkposition.h"
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
static FRandom pr_botopendoor ("BotOpenDoor");
|
|
|
|
static FRandom pr_bottrywalk ("BotTryWalk");
|
|
|
|
static FRandom pr_botnewchasedir ("BotNewChaseDir");
|
|
|
|
|
|
|
|
// borrow some tables from p_enemy.cpp
|
|
|
|
extern dirtype_t opposite[9];
|
|
|
|
extern dirtype_t diags[4];
|
|
|
|
|
2014-11-29 17:03:58 +00:00
|
|
|
//Called while the bot moves after its dest mobj
|
2006-02-24 04:48:15 +00:00
|
|
|
//which can be a weapon/enemy/item whatever.
|
2014-11-29 17:03:58 +00:00
|
|
|
void DBot::Roam (ticcmd_t *cmd)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
int delta;
|
|
|
|
|
2014-11-29 17:03:58 +00:00
|
|
|
if (Reachable(dest))
|
2006-02-24 04:48:15 +00:00
|
|
|
{ // Straight towards it.
|
2016-01-10 19:46:26 +00:00
|
|
|
angle = player->mo->AngleTo(dest);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
2014-11-29 17:03:58 +00:00
|
|
|
else if (player->mo->movedir < 8) // turn towards movement direction if not there yet
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2014-11-29 17:03:58 +00:00
|
|
|
angle &= (angle_t)(7<<29);
|
|
|
|
delta = angle - (player->mo->movedir << 29);
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
if (delta > 0)
|
2014-11-29 17:03:58 +00:00
|
|
|
angle -= ANG45;
|
2006-02-24 04:48:15 +00:00
|
|
|
else if (delta < 0)
|
2014-11-29 17:03:58 +00:00
|
|
|
angle += ANG45;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// chase towards destination.
|
2014-11-29 17:03:58 +00:00
|
|
|
if (--player->mo->movecount < 0 || !Move (cmd))
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2014-11-29 17:03:58 +00:00
|
|
|
NewChaseDir (cmd);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-29 17:03:58 +00:00
|
|
|
bool DBot::Move (ticcmd_t *cmd)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
fixed_t tryx, tryy;
|
|
|
|
bool try_ok;
|
2006-09-14 00:02:31 +00:00
|
|
|
int good;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2014-11-29 17:03:58 +00:00
|
|
|
if (player->mo->movedir == DI_NODIR)
|
2006-02-24 04:48:15 +00:00
|
|
|
return false;
|
|
|
|
|
2014-11-29 17:03:58 +00:00
|
|
|
if ((unsigned)player->mo->movedir >= 8)
|
2006-02-24 04:48:15 +00:00
|
|
|
I_Error ("Weird bot movedir!");
|
|
|
|
|
2016-01-17 12:48:16 +00:00
|
|
|
tryx = player->mo->X() + 8*xspeed[player->mo->movedir];
|
|
|
|
tryy = player->mo->Y() + 8*yspeed[player->mo->movedir];
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2014-11-29 17:03:58 +00:00
|
|
|
try_ok = bglobal.CleanAhead (player->mo, tryx, tryy, cmd);
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
if (!try_ok) //Anything blocking that could be opened etc..
|
|
|
|
{
|
|
|
|
if (!spechit.Size ())
|
|
|
|
return false;
|
|
|
|
|
2014-11-29 17:03:58 +00:00
|
|
|
player->mo->movedir = DI_NODIR;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
good = 0;
|
2016-02-21 22:08:51 +00:00
|
|
|
spechit_t spechit1;
|
2006-02-24 04:48:15 +00:00
|
|
|
line_t *ld;
|
|
|
|
|
2016-02-21 22:08:51 +00:00
|
|
|
while (spechit.Pop (spechit1))
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2016-02-21 22:08:51 +00:00
|
|
|
ld = spechit1.line;
|
2006-02-24 04:48:15 +00:00
|
|
|
bool tryit = true;
|
|
|
|
|
2014-11-29 17:03:58 +00:00
|
|
|
if (ld->special == Door_LockedRaise && !P_CheckKeys (player->mo, ld->args[3], false))
|
2006-02-24 04:48:15 +00:00
|
|
|
tryit = false;
|
2014-11-29 17:03:58 +00:00
|
|
|
else if (ld->special == Generic_Door && !P_CheckKeys (player->mo, ld->args[4], false))
|
2006-02-24 04:48:15 +00:00
|
|
|
tryit = false;
|
|
|
|
|
|
|
|
if (tryit &&
|
2014-11-29 17:03:58 +00:00
|
|
|
(P_TestActivateLine (ld, player->mo, 0, SPAC_Use) ||
|
|
|
|
P_TestActivateLine (ld, player->mo, 0, SPAC_Push)))
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2014-11-29 17:03:58 +00:00
|
|
|
good |= ld == player->mo->BlockingLine ? 1 : 2;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (good && ((pr_botopendoor() >= 203) ^ (good & 1)))
|
|
|
|
{
|
|
|
|
cmd->ucmd.buttons |= BT_USE;
|
|
|
|
cmd->ucmd.forwardmove = FORWARDRUN;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else //Move forward.
|
|
|
|
cmd->ucmd.forwardmove = FORWARDRUN;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-11-29 17:03:58 +00:00
|
|
|
bool DBot::TryWalk (ticcmd_t *cmd)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2014-11-29 17:03:58 +00:00
|
|
|
if (!Move (cmd))
|
2006-02-24 04:48:15 +00:00
|
|
|
return false;
|
|
|
|
|
2014-11-29 17:03:58 +00:00
|
|
|
player->mo->movecount = pr_bottrywalk() & 60;
|
2006-02-24 04:48:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-11-29 17:03:58 +00:00
|
|
|
void DBot::NewChaseDir (ticcmd_t *cmd)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
dirtype_t d[3];
|
|
|
|
|
|
|
|
int tdir;
|
|
|
|
dirtype_t olddir;
|
|
|
|
|
|
|
|
dirtype_t turnaround;
|
|
|
|
|
2014-11-29 17:03:58 +00:00
|
|
|
if (!dest)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
#ifndef BOT_RELEASE_COMPILE
|
|
|
|
Printf ("Bot tried move without destination\n");
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-11-29 17:03:58 +00:00
|
|
|
olddir = (dirtype_t)player->mo->movedir;
|
2006-02-24 04:48:15 +00:00
|
|
|
turnaround = opposite[olddir];
|
|
|
|
|
2016-01-17 17:36:14 +00:00
|
|
|
fixedvec2 delta = player->mo->Vec2To(dest);
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2016-01-17 17:36:14 +00:00
|
|
|
if (delta.x > 10*FRACUNIT)
|
2006-02-24 04:48:15 +00:00
|
|
|
d[1] = DI_EAST;
|
2016-01-17 17:36:14 +00:00
|
|
|
else if (delta.x < -10*FRACUNIT)
|
2006-02-24 04:48:15 +00:00
|
|
|
d[1] = DI_WEST;
|
|
|
|
else
|
|
|
|
d[1] = DI_NODIR;
|
|
|
|
|
2016-01-17 17:36:14 +00:00
|
|
|
if (delta.y < -10*FRACUNIT)
|
2006-02-24 04:48:15 +00:00
|
|
|
d[2] = DI_SOUTH;
|
2016-01-17 17:36:14 +00:00
|
|
|
else if (delta.y > 10*FRACUNIT)
|
2006-02-24 04:48:15 +00:00
|
|
|
d[2] = DI_NORTH;
|
|
|
|
else
|
|
|
|
d[2] = DI_NODIR;
|
|
|
|
|
|
|
|
// try direct route
|
|
|
|
if (d[1] != DI_NODIR && d[2] != DI_NODIR)
|
|
|
|
{
|
2016-01-17 17:36:14 +00:00
|
|
|
player->mo->movedir = diags[((delta.y<0)<<1)+(delta.x>0)];
|
2014-11-29 17:03:58 +00:00
|
|
|
if (player->mo->movedir != turnaround && TryWalk(cmd))
|
2006-02-24 04:48:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// try other directions
|
|
|
|
if (pr_botnewchasedir() > 200
|
2016-01-17 17:36:14 +00:00
|
|
|
|| abs(delta.y)>abs(delta.x))
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
tdir=d[1];
|
|
|
|
d[1]=d[2];
|
|
|
|
d[2]=(dirtype_t)tdir;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d[1]==turnaround)
|
|
|
|
d[1]=DI_NODIR;
|
|
|
|
if (d[2]==turnaround)
|
|
|
|
d[2]=DI_NODIR;
|
|
|
|
|
|
|
|
if (d[1]!=DI_NODIR)
|
|
|
|
{
|
2014-11-29 17:03:58 +00:00
|
|
|
player->mo->movedir = d[1];
|
|
|
|
if (TryWalk (cmd))
|
2006-02-24 04:48:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d[2]!=DI_NODIR)
|
|
|
|
{
|
2014-11-29 17:03:58 +00:00
|
|
|
player->mo->movedir = d[2];
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2014-11-29 17:03:58 +00:00
|
|
|
if (TryWalk(cmd))
|
2006-02-24 04:48:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// there is no direct path to the player,
|
|
|
|
// so pick another direction.
|
|
|
|
if (olddir!=DI_NODIR)
|
|
|
|
{
|
2014-11-29 17:03:58 +00:00
|
|
|
player->mo->movedir = olddir;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2014-11-29 17:03:58 +00:00
|
|
|
if (TryWalk(cmd))
|
2006-02-24 04:48:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// randomly determine direction of search
|
|
|
|
if (pr_botnewchasedir()&1)
|
|
|
|
{
|
|
|
|
for ( tdir=DI_EAST;
|
|
|
|
tdir<=DI_SOUTHEAST;
|
|
|
|
tdir++ )
|
|
|
|
{
|
|
|
|
if (tdir!=turnaround)
|
|
|
|
{
|
2014-11-29 17:03:58 +00:00
|
|
|
player->mo->movedir = tdir;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2014-11-29 17:03:58 +00:00
|
|
|
if (TryWalk(cmd))
|
2006-02-24 04:48:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for ( tdir=DI_SOUTHEAST;
|
|
|
|
tdir != (DI_EAST-1);
|
|
|
|
tdir-- )
|
|
|
|
{
|
|
|
|
if (tdir!=turnaround)
|
|
|
|
{
|
2014-11-29 17:03:58 +00:00
|
|
|
player->mo->movedir = tdir;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2014-11-29 17:03:58 +00:00
|
|
|
if (TryWalk(cmd))
|
2006-02-24 04:48:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (turnaround != DI_NODIR)
|
|
|
|
{
|
2014-11-29 17:03:58 +00:00
|
|
|
player->mo->movedir = turnaround;
|
|
|
|
if (TryWalk(cmd))
|
2006-02-24 04:48:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-11-29 17:03:58 +00:00
|
|
|
player->mo->movedir = DI_NODIR; // can not move
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// B_CleanAhead
|
|
|
|
// Check if a place is ok to move towards.
|
|
|
|
// This is also a traverse function for
|
|
|
|
// bots pre-rocket fire (preventing suicide)
|
|
|
|
//
|
2008-03-28 00:38:17 +00:00
|
|
|
bool FCajunMaster::CleanAhead (AActor *thing, fixed_t x, fixed_t y, ticcmd_t *cmd)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-04-08 20:52:49 +00:00
|
|
|
FCheckPosition tm;
|
|
|
|
|
|
|
|
if (!SafeCheckPosition (thing, x, y, tm))
|
2006-02-24 04:48:15 +00:00
|
|
|
return false; // solid wall or thing
|
|
|
|
|
|
|
|
if (!(thing->flags & MF_NOCLIP) )
|
|
|
|
{
|
|
|
|
fixed_t maxstep = thing->MaxStepHeight;
|
2008-04-08 20:52:49 +00:00
|
|
|
if (tm.ceilingz - tm.floorz < thing->height)
|
2006-02-24 04:48:15 +00:00
|
|
|
return false; // doesn't fit
|
|
|
|
|
|
|
|
if (!(thing->flags&MF_MISSILE))
|
|
|
|
{
|
2008-04-08 20:52:49 +00:00
|
|
|
if(tm.floorz > (thing->Sector->floorplane.ZatPoint (x, y)+MAXMOVEHEIGHT)) //Too high wall
|
2006-02-24 04:48:15 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
//Jumpable
|
2008-04-08 20:52:49 +00:00
|
|
|
if(tm.floorz>(thing->Sector->floorplane.ZatPoint (x, y)+thing->MaxStepHeight))
|
2006-02-24 04:48:15 +00:00
|
|
|
cmd->ucmd.buttons |= BT_JUMP;
|
|
|
|
|
|
|
|
|
|
|
|
if ( !(thing->flags & MF_TELEPORT) &&
|
2016-01-17 12:48:16 +00:00
|
|
|
tm.ceilingz - thing->Z() < thing->height)
|
2006-02-24 04:48:15 +00:00
|
|
|
return false; // mobj must lower itself to fit
|
|
|
|
|
|
|
|
// jump out of water
|
|
|
|
// if((thing->eflags & (MF_UNDERWATER|MF_TOUCHWATER))==(MF_UNDERWATER|MF_TOUCHWATER))
|
|
|
|
// maxstep=37*FRACUNIT;
|
|
|
|
|
|
|
|
if ( !(thing->flags & MF_TELEPORT) &&
|
2016-01-17 12:48:16 +00:00
|
|
|
(tm.floorz - thing->Z() > maxstep ) )
|
2006-02-24 04:48:15 +00:00
|
|
|
return false; // too big a step up
|
|
|
|
|
|
|
|
|
|
|
|
if ( !(thing->flags&(MF_DROPOFF|MF_FLOAT))
|
2008-04-08 20:52:49 +00:00
|
|
|
&& tm.floorz - tm.dropoffz > thing->MaxDropOffHeight )
|
2006-02-24 04:48:15 +00:00
|
|
|
return false; // don't stand over a dropoff
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define OKAYRANGE (5*ANGLE_1) //counts *2, when angle is in range, turning is not executed.
|
|
|
|
#define MAXTURN (15*ANGLE_1) //Max degrees turned in one tic. Lower is smother but may cause the bot not getting where it should = crash
|
|
|
|
#define TURNSENS 3 //Higher is smoother but slower turn.
|
|
|
|
|
2014-11-29 17:03:58 +00:00
|
|
|
void DBot::TurnToAng ()
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2006-05-28 14:54:01 +00:00
|
|
|
int maxturn = MAXTURN;
|
|
|
|
|
2014-11-29 17:03:58 +00:00
|
|
|
if (player->ReadyWeapon != NULL)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2014-11-29 17:03:58 +00:00
|
|
|
if (player->ReadyWeapon->WeaponFlags & WIF_BOT_EXPLOSIVE)
|
2006-05-28 14:54:01 +00:00
|
|
|
{
|
2014-11-29 17:03:58 +00:00
|
|
|
if (t_roam && !missile)
|
2006-05-28 14:54:01 +00:00
|
|
|
{ //Keep angle that where when shot where decided.
|
|
|
|
return;
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-29 17:03:58 +00:00
|
|
|
if(enemy)
|
|
|
|
if(!dest) //happens when running after item in combat situations, or normal, prevents weak turns
|
|
|
|
if(player->ReadyWeapon->ProjectileType == NULL && !(player->ReadyWeapon->WeaponFlags & WIF_MELEEWEAPON))
|
|
|
|
if(Check_LOS(enemy, SHOOTFOV+5*ANGLE_1))
|
2006-05-28 14:54:01 +00:00
|
|
|
maxturn = 3;
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2014-11-29 17:03:58 +00:00
|
|
|
int distance = angle - player->mo->angle;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2014-11-29 17:03:58 +00:00
|
|
|
if (abs (distance) < OKAYRANGE && !enemy)
|
2006-02-24 04:48:15 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
distance /= TURNSENS;
|
|
|
|
if (abs (distance) > maxturn)
|
|
|
|
distance = distance < 0 ? -maxturn : maxturn;
|
|
|
|
|
2014-11-29 17:03:58 +00:00
|
|
|
player->mo->angle += distance;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
2014-11-29 17:03:58 +00:00
|
|
|
void DBot::Pitch (AActor *target)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
double aim;
|
|
|
|
double diff;
|
|
|
|
|
2016-01-17 12:48:16 +00:00
|
|
|
diff = target->Z() - player->mo->Z();
|
2016-01-10 16:52:41 +00:00
|
|
|
aim = atan(diff / (double)player->mo->AproxDistance(target));
|
2014-11-29 17:03:58 +00:00
|
|
|
player->mo->pitch = -(int)(aim * ANGLE_180/M_PI);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//Checks if a sector is dangerous.
|
2008-03-28 00:38:17 +00:00
|
|
|
bool FCajunMaster::IsDangerous (sector_t *sec)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2016-01-06 11:12:47 +00:00
|
|
|
return sec->damageamount > 0;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|