2016-03-01 15:47:10 +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"
|
|
|
|
#include "d_event.h"
|
|
|
|
#include "p_enemy.h"
|
|
|
|
#include "d_player.h"
|
|
|
|
#include "p_spec.h"
|
|
|
|
#include "p_checkposition.h"
|
2016-03-11 14:45:47 +00:00
|
|
|
#include "math/cmath.h"
|
2016-03-01 15:47:10 +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];
|
|
|
|
|
|
|
|
//Called while the bot moves after its dest mobj
|
|
|
|
//which can be a weapon/enemy/item whatever.
|
|
|
|
void DBot::Roam (ticcmd_t *cmd)
|
|
|
|
{
|
|
|
|
int delta;
|
|
|
|
|
|
|
|
if (Reachable(dest))
|
|
|
|
{ // Straight towards it.
|
2016-03-16 23:07:37 +00:00
|
|
|
angle = player->mo->__f_AngleTo(dest);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
else if (player->mo->movedir < 8) // turn towards movement direction if not there yet
|
|
|
|
{
|
|
|
|
angle &= (angle_t)(7<<29);
|
|
|
|
delta = angle - (player->mo->movedir << 29);
|
|
|
|
|
|
|
|
if (delta > 0)
|
|
|
|
angle -= ANG45;
|
|
|
|
else if (delta < 0)
|
|
|
|
angle += ANG45;
|
|
|
|
}
|
|
|
|
|
|
|
|
// chase towards destination.
|
|
|
|
if (--player->mo->movecount < 0 || !Move (cmd))
|
|
|
|
{
|
|
|
|
NewChaseDir (cmd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DBot::Move (ticcmd_t *cmd)
|
|
|
|
{
|
|
|
|
fixed_t tryx, tryy;
|
|
|
|
bool try_ok;
|
|
|
|
int good;
|
|
|
|
|
|
|
|
if (player->mo->movedir == DI_NODIR)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if ((unsigned)player->mo->movedir >= 8)
|
|
|
|
I_Error ("Weird bot movedir!");
|
|
|
|
|
2016-03-19 23:54:18 +00:00
|
|
|
tryx = player->mo->_f_X() + 8*xspeed[player->mo->movedir];
|
|
|
|
tryy = player->mo->_f_Y() + 8*yspeed[player->mo->movedir];
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
try_ok = bglobal.CleanAhead (player->mo, tryx, tryy, cmd);
|
|
|
|
|
|
|
|
if (!try_ok) //Anything blocking that could be opened etc..
|
|
|
|
{
|
|
|
|
if (!spechit.Size ())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
player->mo->movedir = DI_NODIR;
|
|
|
|
|
|
|
|
good = 0;
|
|
|
|
spechit_t spechit1;
|
|
|
|
line_t *ld;
|
|
|
|
|
|
|
|
while (spechit.Pop (spechit1))
|
|
|
|
{
|
|
|
|
ld = spechit1.line;
|
|
|
|
bool tryit = true;
|
|
|
|
|
|
|
|
if (ld->special == Door_LockedRaise && !P_CheckKeys (player->mo, ld->args[3], false))
|
|
|
|
tryit = false;
|
|
|
|
else if (ld->special == Generic_Door && !P_CheckKeys (player->mo, ld->args[4], false))
|
|
|
|
tryit = false;
|
|
|
|
|
|
|
|
if (tryit &&
|
|
|
|
(P_TestActivateLine (ld, player->mo, 0, SPAC_Use) ||
|
|
|
|
P_TestActivateLine (ld, player->mo, 0, SPAC_Push)))
|
|
|
|
{
|
|
|
|
good |= ld == player->mo->BlockingLine ? 1 : 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DBot::TryWalk (ticcmd_t *cmd)
|
|
|
|
{
|
|
|
|
if (!Move (cmd))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
player->mo->movecount = pr_bottrywalk() & 60;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DBot::NewChaseDir (ticcmd_t *cmd)
|
|
|
|
{
|
|
|
|
dirtype_t d[3];
|
|
|
|
|
|
|
|
int tdir;
|
|
|
|
dirtype_t olddir;
|
|
|
|
|
|
|
|
dirtype_t turnaround;
|
|
|
|
|
|
|
|
if (!dest)
|
|
|
|
{
|
|
|
|
#ifndef BOT_RELEASE_COMPILE
|
|
|
|
Printf ("Bot tried move without destination\n");
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
olddir = (dirtype_t)player->mo->movedir;
|
|
|
|
turnaround = opposite[olddir];
|
|
|
|
|
2016-03-19 23:54:18 +00:00
|
|
|
fixedvec2 delta = player->mo->_f_Vec2To(dest);
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
if (delta.x > 10*FRACUNIT)
|
|
|
|
d[1] = DI_EAST;
|
|
|
|
else if (delta.x < -10*FRACUNIT)
|
|
|
|
d[1] = DI_WEST;
|
|
|
|
else
|
|
|
|
d[1] = DI_NODIR;
|
|
|
|
|
|
|
|
if (delta.y < -10*FRACUNIT)
|
|
|
|
d[2] = DI_SOUTH;
|
|
|
|
else if (delta.y > 10*FRACUNIT)
|
|
|
|
d[2] = DI_NORTH;
|
|
|
|
else
|
|
|
|
d[2] = DI_NODIR;
|
|
|
|
|
|
|
|
// try direct route
|
|
|
|
if (d[1] != DI_NODIR && d[2] != DI_NODIR)
|
|
|
|
{
|
|
|
|
player->mo->movedir = diags[((delta.y<0)<<1)+(delta.x>0)];
|
|
|
|
if (player->mo->movedir != turnaround && TryWalk(cmd))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// try other directions
|
|
|
|
if (pr_botnewchasedir() > 200
|
|
|
|
|| abs(delta.y)>abs(delta.x))
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
player->mo->movedir = d[1];
|
|
|
|
if (TryWalk (cmd))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d[2]!=DI_NODIR)
|
|
|
|
{
|
|
|
|
player->mo->movedir = d[2];
|
|
|
|
|
|
|
|
if (TryWalk(cmd))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// there is no direct path to the player,
|
|
|
|
// so pick another direction.
|
|
|
|
if (olddir!=DI_NODIR)
|
|
|
|
{
|
|
|
|
player->mo->movedir = olddir;
|
|
|
|
|
|
|
|
if (TryWalk(cmd))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// randomly determine direction of search
|
|
|
|
if (pr_botnewchasedir()&1)
|
|
|
|
{
|
|
|
|
for ( tdir=DI_EAST;
|
|
|
|
tdir<=DI_SOUTHEAST;
|
|
|
|
tdir++ )
|
|
|
|
{
|
|
|
|
if (tdir!=turnaround)
|
|
|
|
{
|
|
|
|
player->mo->movedir = tdir;
|
|
|
|
|
|
|
|
if (TryWalk(cmd))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for ( tdir=DI_SOUTHEAST;
|
|
|
|
tdir != (DI_EAST-1);
|
|
|
|
tdir-- )
|
|
|
|
{
|
|
|
|
if (tdir!=turnaround)
|
|
|
|
{
|
|
|
|
player->mo->movedir = tdir;
|
|
|
|
|
|
|
|
if (TryWalk(cmd))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (turnaround != DI_NODIR)
|
|
|
|
{
|
|
|
|
player->mo->movedir = turnaround;
|
|
|
|
if (TryWalk(cmd))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
player->mo->movedir = DI_NODIR; // can not move
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// B_CleanAhead
|
|
|
|
// Check if a place is ok to move towards.
|
|
|
|
// This is also a traverse function for
|
|
|
|
// bots pre-rocket fire (preventing suicide)
|
|
|
|
//
|
|
|
|
bool FCajunMaster::CleanAhead (AActor *thing, fixed_t x, fixed_t y, ticcmd_t *cmd)
|
|
|
|
{
|
|
|
|
FCheckPosition tm;
|
|
|
|
|
|
|
|
if (!SafeCheckPosition (thing, x, y, tm))
|
|
|
|
return false; // solid wall or thing
|
|
|
|
|
|
|
|
if (!(thing->flags & MF_NOCLIP) )
|
|
|
|
{
|
|
|
|
fixed_t maxstep = thing->MaxStepHeight;
|
2016-03-20 19:55:06 +00:00
|
|
|
if (tm.ceilingz - tm.floorz < thing->Height)
|
2016-03-01 15:47:10 +00:00
|
|
|
return false; // doesn't fit
|
|
|
|
|
|
|
|
if (!(thing->flags&MF_MISSILE))
|
|
|
|
{
|
2016-03-20 18:52:35 +00:00
|
|
|
if(tm._f_floorz() > (thing->Sector->floorplane.ZatPoint (x, y)+MAXMOVEHEIGHT)) //Too high wall
|
2016-03-01 15:47:10 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
//Jumpable
|
2016-03-20 18:52:35 +00:00
|
|
|
if(tm._f_floorz()>(thing->Sector->floorplane.ZatPoint (x, y)+thing->MaxStepHeight))
|
2016-03-01 15:47:10 +00:00
|
|
|
cmd->ucmd.buttons |= BT_JUMP;
|
|
|
|
|
|
|
|
|
|
|
|
if ( !(thing->flags & MF_TELEPORT) &&
|
2016-03-20 12:32:53 +00:00
|
|
|
tm.ceilingz < thing->Top())
|
2016-03-01 15:47:10 +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-03-20 18:52:35 +00:00
|
|
|
(tm._f_floorz() - thing->_f_Z() > maxstep ) )
|
2016-03-01 15:47:10 +00:00
|
|
|
return false; // too big a step up
|
|
|
|
|
|
|
|
|
|
|
|
if ( !(thing->flags&(MF_DROPOFF|MF_FLOAT))
|
2016-03-20 18:52:35 +00:00
|
|
|
&& tm._f_floorz() - tm.dropoffz > thing->MaxDropOffHeight )
|
2016-03-01 15:47:10 +00:00
|
|
|
return false; // don't stand over a dropoff
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-03-16 11:41:26 +00:00
|
|
|
#define OKAYRANGE (5) //counts *2, when angle is in range, turning is not executed.
|
|
|
|
#define MAXTURN (15) //Max degrees turned in one tic. Lower is smother but may cause the bot not getting where it should = crash
|
2016-03-01 15:47:10 +00:00
|
|
|
#define TURNSENS 3 //Higher is smoother but slower turn.
|
|
|
|
|
|
|
|
void DBot::TurnToAng ()
|
|
|
|
{
|
2016-03-16 11:41:26 +00:00
|
|
|
double maxturn = MAXTURN;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
if (player->ReadyWeapon != NULL)
|
|
|
|
{
|
|
|
|
if (player->ReadyWeapon->WeaponFlags & WIF_BOT_EXPLOSIVE)
|
|
|
|
{
|
|
|
|
if (t_roam && !missile)
|
|
|
|
{ //Keep angle that where when shot where decided.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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))
|
|
|
|
maxturn = 3;
|
|
|
|
}
|
|
|
|
|
2016-03-16 11:41:26 +00:00
|
|
|
DAngle distance = deltaangle(player->mo->Angles.Yaw, ANGLE2DBL(angle));
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2016-03-16 11:41:26 +00:00
|
|
|
if (fabs (distance) < OKAYRANGE && !enemy)
|
2016-03-01 15:47:10 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
distance /= TURNSENS;
|
2016-03-16 11:41:26 +00:00
|
|
|
if (fabs (distance) > maxturn)
|
2016-03-01 15:47:10 +00:00
|
|
|
distance = distance < 0 ? -maxturn : maxturn;
|
|
|
|
|
2016-03-16 11:41:26 +00:00
|
|
|
player->mo->Angles.Yaw += distance;
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DBot::Pitch (AActor *target)
|
|
|
|
{
|
|
|
|
double aim;
|
|
|
|
double diff;
|
|
|
|
|
2016-03-19 23:54:18 +00:00
|
|
|
diff = target->_f_Z() - player->mo->_f_Z();
|
2016-03-11 14:45:47 +00:00
|
|
|
aim = g_atan(diff / (double)player->mo->AproxDistance(target));
|
2016-03-16 11:41:26 +00:00
|
|
|
player->mo->Angles.Pitch = ToDegrees(aim);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//Checks if a sector is dangerous.
|
|
|
|
bool FCajunMaster::IsDangerous (sector_t *sec)
|
|
|
|
{
|
|
|
|
return sec->damageamount > 0;
|
|
|
|
}
|