PHP Code:
{
// Check if Bot 'sees' a SmokeGrenade to simulate the effect of being blinded by smoke
// + notice Bot of Grenades flying towards him
// TODO: Split this up and make it more reliable
static edict_t *pEdict;
static edict_t *pent;
static edict_t *pSmoke; // KWo - 26.03.2007
static Vector vecView;
static float fDistance;
static int iInField;
pEdict = pBot->pEdict;
pent = pBot->pAvoidGrenade;
pSmoke = pBot->pSmokeGrenade;
vecView = GetGunPosition (pEdict);
// Check if old ptr to Grenade is invalid
if (FNullEnt (pent))
{
pBot->pAvoidGrenade = NULL;
pBot->cAvoidGrenade = 0;
}
else if ((pent->v.flags & FL_ONGROUND) || (pent->v.effects & EF_NODRAW))
{
pBot->pAvoidGrenade = NULL;
pBot->cAvoidGrenade = 0;
}
if (FNullEnt (pSmoke)) // KWo - 26.03.2007
{
pSmoke = NULL;
pBot->pSmokeGrenade = NULL;
}
else if (!(pSmoke->v.flags & FL_ONGROUND) || (pSmoke->v.effects & EF_NODRAW))
{
pSmoke = NULL;
pBot->pSmokeGrenade = NULL;
}
if (!FNullEnt (pBot->pAvoidGrenade)) // KWo - 26.03.2007
{
Vector2D vec2DirToPoint;
Vector2D vec2RightSide;
// to start strafing, we have to first figure out if the target is on the left side or right side
MAKE_VECTORS (pEdict->v.angles);
vec2DirToPoint = (pEdict->v.origin - pent->v.origin).Make2D ().Normalize ();
vec2RightSide = gpGlobals->v_right.Make2D ().Normalize ();
if (DotProduct (vec2DirToPoint, vec2RightSide) > 0)
pBot->cAvoidGrenade = -1;
else
pBot->cAvoidGrenade = 1;
// ALERT(at_logged, "[DEBUG] Bot %s needs to avoid grenade.\n", pBot->name);
}
if (!FNullEnt (pSmoke)) // KWo - 13.09.2008
{
// Check if in field of view of the Bot
iInField = BotInFieldOfView (pBot, pSmoke->v.origin - vecView);
if (iInField < (pEdict->v.fov * 1.0 - 5.0)) // more wide - even +/-85 degress in this case...
{
// ALERT(at_logged, "[DEBUG] Bot %s checks a smoke grenade in his field of view.\n", pBot->name);
fDistance = (pSmoke->v.origin - pEdict->v.origin).Length ();
// Shrink Bots Viewing Distance to Smoke Grens Distance
if (pBot->f_view_distance > fDistance)
pBot->f_view_distance = fDistance;
}