void CBot::BotFindItem( void )
{
CBaseEntity *pEntity = NULL;
CBasePlayerItem *pItem = NULL;
float radius = 100;
while ((pEntity = UTIL_FindEntityInSphere( pEntity, pev->origin, radius )) != NULL)
{
// check to make sure that the entity is visible and in field of view...
if (FVisible( pEntity ) && FInViewCone( pEntity ))
{
// check if entity is a weapon...
if (strncmp("weapon_", STRING(pEntity->pev->classname), 7) == 0)
{
CBasePlayerWeapon *pWeapon = (CBasePlayerWeapon *)pEntity;
if ((pWeapon->m_pPlayer) || (pWeapon->pev->effects & EF_NODRAW))
{
// someone owns this weapon or it hasn't respawned yet
continue;
}
if (g_pGameRules->CanHavePlayerItem( this, pWeapon ))
{
// let's head off toward that item...
Vector v_item = pEntity->pev->origin - pev->origin;
pev->v_angle = UTIL_VecToAngles( v_item );
}
}
// check if entity is ammo...
if (strncmp("ammo_", STRING(pEntity->pev->classname), 5) == 0)
{
CBasePlayerAmmo *pAmmo = (CBasePlayerAmmo *)pEntity;
char ammo_name[40];
int i;
BOOL can_pickup = FALSE;
// check if the item is not visible (i.e. has not respawned)
if (pAmmo->pev->effects & EF_NODRAW)
continue;
strcpy(ammo_name, STRING(pEntity->pev->classname));
i = 0;
while (ammo_check.ammo_name[1])
{
if (strcmp(ammo_check.ammo_name, ammo_name) == 0)
{
// see if we can pick up this item...
if (g_pGameRules->CanHaveAmmo( this,
ammo_check.weapon_name, ammo_check.max_carry))
{
can_pickup = TRUE;
break;
}
}
i++;
}
if (can_pickup)
{
// let's head off toward that item...
Vector v_item = pEntity->pev->origin - pev->origin;
pev->v_angle = UTIL_VecToAngles( v_item );
}
}
// check if entity is a battery...
if (strcmp("item_battery", STRING(pEntity->pev->classname)) == 0)
{
CItem *pBattery = (CItem *)pEntity;
// check if the item is not visible (i.e. has not respawned)
if (pBattery->pev->effects & EF_NODRAW)
continue;
// check if the bot can use this item...
if ((pev->armorvalue < MAX_NORMAL_BATTERY) &&
(pev->weapons & (1<< WEAPON_SUIT)))
{
// let's head off toward that item...
Vector v_item = pEntity->pev->origin - pev->origin;
pev->v_angle = UTIL_VecToAngles( v_item );
}
}
// check if entity is a healthkit...
if (strcmp("item_healthkit", STRING(pEntity->pev->classname)) == 0)
{
CItem *pHealthKit = (CItem *)pEntity;
// check if the item is not visible (i.e. has not respawned)
if (pHealthKit->pev->effects & EF_NODRAW)
continue;
// check if the bot can use this item...
if (pev->health <= 90)
{
// let's head off toward that item...
Vector v_item = pEntity->pev->origin - pev->origin;
pev->v_angle = UTIL_VecToAngles( v_item );
}
}
// check if entity is a packed up weapons box...
if (strcmp("weaponbox", STRING(pEntity->pev->classname)) == 0)
{
// let's head off toward that item...
Vector v_item = pEntity->pev->origin - pev->origin;
pev->v_angle = UTIL_VecToAngles( v_item );
}
}
}
}
{
CBaseEntity *pEntity = NULL;
CBasePlayerItem *pItem = NULL;
float radius = 100;
while ((pEntity = UTIL_FindEntityInSphere( pEntity, pev->origin, radius )) != NULL)
{
// check to make sure that the entity is visible and in field of view...
if (FVisible( pEntity ) && FInViewCone( pEntity ))
{
// check if entity is a weapon...
if (strncmp("weapon_", STRING(pEntity->pev->classname), 7) == 0)
{
CBasePlayerWeapon *pWeapon = (CBasePlayerWeapon *)pEntity;
if ((pWeapon->m_pPlayer) || (pWeapon->pev->effects & EF_NODRAW))
{
// someone owns this weapon or it hasn't respawned yet
continue;
}
if (g_pGameRules->CanHavePlayerItem( this, pWeapon ))
{
// let's head off toward that item...
Vector v_item = pEntity->pev->origin - pev->origin;
pev->v_angle = UTIL_VecToAngles( v_item );
}
}
// check if entity is ammo...
if (strncmp("ammo_", STRING(pEntity->pev->classname), 5) == 0)
{
CBasePlayerAmmo *pAmmo = (CBasePlayerAmmo *)pEntity;
char ammo_name[40];
int i;
BOOL can_pickup = FALSE;
// check if the item is not visible (i.e. has not respawned)
if (pAmmo->pev->effects & EF_NODRAW)
continue;
strcpy(ammo_name, STRING(pEntity->pev->classname));
i = 0;
while (ammo_check.ammo_name[1])
{
if (strcmp(ammo_check.ammo_name, ammo_name) == 0)
{
// see if we can pick up this item...
if (g_pGameRules->CanHaveAmmo( this,
ammo_check.weapon_name, ammo_check.max_carry))
{
can_pickup = TRUE;
break;
}
}
i++;
}
if (can_pickup)
{
// let's head off toward that item...
Vector v_item = pEntity->pev->origin - pev->origin;
pev->v_angle = UTIL_VecToAngles( v_item );
}
}
// check if entity is a battery...
if (strcmp("item_battery", STRING(pEntity->pev->classname)) == 0)
{
CItem *pBattery = (CItem *)pEntity;
// check if the item is not visible (i.e. has not respawned)
if (pBattery->pev->effects & EF_NODRAW)
continue;
// check if the bot can use this item...
if ((pev->armorvalue < MAX_NORMAL_BATTERY) &&
(pev->weapons & (1<< WEAPON_SUIT)))
{
// let's head off toward that item...
Vector v_item = pEntity->pev->origin - pev->origin;
pev->v_angle = UTIL_VecToAngles( v_item );
}
}
// check if entity is a healthkit...
if (strcmp("item_healthkit", STRING(pEntity->pev->classname)) == 0)
{
CItem *pHealthKit = (CItem *)pEntity;
// check if the item is not visible (i.e. has not respawned)
if (pHealthKit->pev->effects & EF_NODRAW)
continue;
// check if the bot can use this item...
if (pev->health <= 90)
{
// let's head off toward that item...
Vector v_item = pEntity->pev->origin - pev->origin;
pev->v_angle = UTIL_VecToAngles( v_item );
}
}
// check if entity is a packed up weapons box...
if (strcmp("weaponbox", STRING(pEntity->pev->classname)) == 0)
{
// let's head off toward that item...
Vector v_item = pEntity->pev->origin - pev->origin;
pev->v_angle = UTIL_VecToAngles( v_item );
}
}
}
}