UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
g_ai.cpp File Reference

Artificial Intelligence for opponents or human controlled actors that are panicked. More...

#include "g_ai.h"
#include "g_actor.h"
#include "g_client.h"
#include "g_combat.h"
#include "g_edicts.h"
#include "g_health.h"
#include "g_inventory.h"
#include "g_move.h"
#include "g_utils.h"
#include "g_vis.h"
#include "g_reaction.h"

Go to the source code of this file.

Data Structures

class  AiAction
 

Macros

#define SCORE_HIDE   60
 
#define SCORE_CLOSE_IN   20
 
#define SCORE_KILL   30
 
#define SCORE_RANDOM   10
 
#define SCORE_REACTION_ERADICATION   30
 
#define SCORE_REACTION_FEAR_FACTOR   20
 
#define SCORE_NONHIDING_PLACE_PENALTY   25
 
#define SCORE_RAGE   40
 
#define SCORE_DAMAGE   100.0f
 
#define SCORE_DAMAGE_FACTOR   1.25f
 
#define SCORE_CIV_FACTOR   0.25f
 
#define SCORE_DISABLED_FACTOR   0.25f
 
#define SCORE_DAMAGE_WORTH_FACTOR   0.1f
 
#define SCORE_CIV_RANDOM   10
 
#define SCORE_RUN_AWAY   50
 
#define SCORE_CIV_LAZINESS   5
 
#define RUN_AWAY_DIST   160
 
#define WAYPOINT_CIV_DIST   768
 
#define HERD_THRESHOLD   128.0f
 
#define SCORE_HERDING_PENALTY   100
 
#define SCORE_NOSAFE_POSITION_PENALTY   500
 
#define SCORE_MISSION_OPPONENT_TARGET   50
 
#define SCORE_MISSION_TARGET   60
 
#define SCORE_MISSION_HOLD   25
 
#define MISSION_HOLD_DIST   96
 
#define SCORE_PANIC_RUN_TO_FRIENDS   300.0f
 
#define SCORE_PANIC_FLEE_FROM_STRANGERS   500.0f
 
#define SCORE_PANIC_RANDOM   25.0f
 
#define AI_ACTION_NOTHING_FOUND   -10000.0f
 
#define CLOSE_IN_DIST   1200.0f
 
#define SPREAD_FACTOR   8.0f
 
#define SPREAD_NORM(x)   ((x) > 0 ? SPREAD_FACTOR/((x)*torad) : 0)
 
#define HIDE_DIST   25
 distance for (ai) hiding in grid tiles More...
 
#define HERD_DIST   25
 
#define HOLD_DIST   3
 
#define CALC_DAMAGE_SAMPLES   10.0f
 
#define INVDEF_FOR_SHOOTTYPE(st)   (IS_SHOT_RIGHT(st)?INVDEF(CID_RIGHT):IS_SHOT_LEFT(st)?INVDEF(CID_LEFT):IS_SHOT_HEADGEAR(st)?INVDEF(CID_HEADGEAR):nullptr)
 
#define LOF_CHECK_PARTITIONS   4
 

Functions

void AI_Init (void)
 
bool AI_HasLineOfFire (const Actor *actor, const Edict *target)
 Check if actor has a line of fire to the target given. More...
 
static bool AI_IsExposed (int team, Actor *check)
 Test if check is exposed to the enemy team. More...
 
static bool AI_CheckFF (const Edict *ent, const vec3_t target, float spread, float radius)
 Check whether friendly units are in the line of fire when shooting. More...
 
bool AI_FighterCheckShoot (const Actor *actor, const Edict *check, const fireDef_t *fd, float dist)
 Check whether the fighter should perform the shoot. More...
 
bool AI_CheckUsingDoor (const Edict *ent, const Edict *door)
 Checks whether the AI controlled actor wants to use a door. More...
 
static bool AI_CheckCrouch (const Actor *actor)
 Checks whether it would be smart to change the state to STATE_CROUCHED. More...
 
bool AI_HideNeeded (const Actor *actor)
 Checks whether the given alien should try to hide because there are enemies close enough to shoot the alien. More...
 
static const ItemAI_GetItemFromInventory (const Item *ic)
 Returns useable item from the given inventory list. That means that the 'weapon' has ammunition left or must not be reloaded. More...
 
const ItemAI_GetItemForShootType (shoot_types_t shootType, const Edict *ent)
 
int AI_GetHidingTeam (const Edict *ent)
 Returns the value for the vis check whenever an ai actor tries to hide. For aliens this is the inverse team - see the vis check code for the inverse team rules to see how this works. For civilians we have to specify the alien team and can't use the inverse team rules. This is needed because the inverse team rules aren't working for the civilian team - see TEAM_CIVILIAN. More...
 
bool AI_CheckPosition (const Actor *const actor, const pos3_t pos)
 Checks if the given position is safe to stand on. More...
 
bool AI_FindHidingLocation (int team, Actor *actor, const pos3_t from, int tuLeft)
 Tries to search a hiding spot. More...
 
bool AI_FindHerdLocation (Actor *actor, const pos3_t from, const vec3_t target, int tu, bool inverse)
 Tries to search a spot where actor will be more closer to the target and behind the target from enemy (ie hide behind target) More...
 
static EdictAI_SearchDestroyableObject (const Actor *actor, const fireDef_t *fd)
 
bool AI_CheckLineOfFire (const Actor *shooter, const Edict *target, const fireDef_t *fd, int shots)
 
float AI_CalcShotDamage (Actor *actor, const Actor *target, const fireDef_t *fd, shoot_types_t shotType)
 Calculate estimated damage per single shoot. More...
 
static void AI_FindBestFiredef (AiAction *aia, Actor *actor, Actor *check, const Item *item, shoot_types_t shootType, int tu, float *maxDmg, int *bestTime, const fireDef_t *fdArray)
 
bool AI_IsHostile (const Actor *actor, const Edict *target)
 Check if actor perceives target as hostile. More...
 
const invDef_tAI_SearchGrenade (const Actor *actor, Item **ip)
 Search the edict's inventory for a grenade or other one-use weapon. More...
 
static bool AI_IsHandForForShootTypeFree (shoot_types_t shootType, Actor *actor)
 Check if the hand for the given shoot type is free. More...
 
static int AI_CheckForMissionTargets (Actor *actor, const pos3_t pos)
 Searches the map for mission edicts and try to get there. More...
 
static float AI_FighterCalcActionScore (Actor *actor, const pos3_t to, AiAction *aia)
 
static float AI_CivilianCalcActionScore (Actor *actor, const pos3_t to, AiAction *aia)
 Calculates possible actions for a civilian. More...
 
static float AI_PanicCalcActionScore (Actor *actor, const pos3_t to, AiAction *aia)
 Calculates possible actions for a panicking unit. More...
 
bool AI_FindMissionLocation (Actor *actor, const pos3_t to, int tus, int radius)
 Try to go close to a mission edict. More...
 
static AiAction AI_PrepBestAction (const Player &player, Actor *actor)
 Attempts to find the best action for an alien. Moves the alien into the starting position for that action and returns the action. More...
 
void G_AddToWayPointList (Edict *ent)
 
void AI_TurnIntoDirection (Actor *actor, const pos3_t pos)
 This function will turn the AI actor into the direction that is needed to walk to the given location. More...
 
bool AI_TryToReloadWeapon (Actor *actor, containerIndex_t containerID)
 if a weapon can be reloaded we attempt to do so if TUs permit, otherwise drop it More...
 
static void AI_ActorThink (Player &player, Actor *actor)
 The think function for the ai controlled aliens or panicked humans. More...
 
void AI_ActorRun (Player &player, Actor *actor)
 
static bool AI_TeamThink (Player &player)
 
static void AI_PlayerRun (Player &player)
 
void AI_Run (void)
 Every server frame one single actor is handled - always in the same order. More...
 
static void AI_SetStats (Actor *actor, int team)
 Initializes the actor's stats like morals, strength and so on. More...
 
static void AI_SetCharacterValues (Edict *ent, int team)
 Sets an actor's character values. More...
 
static void AI_SetEquipment (Edict *ent, const equipDef_t *ed)
 Sets the actor's equipment. More...
 
static void AI_InitPlayer (const Player &player, Actor *actor, const equipDef_t *ed)
 Initializes the actor. More...
 
static const equipDef_tG_GetEquipmentForAISpawn (int team)
 
static ActorG_SpawnAIPlayer (const Player &player, const equipDef_t *ed)
 
static void G_SpawnAIPlayers (const Player &player, int numSpawn)
 Spawn civilians and aliens. More...
 
void AI_CheckRespawn (int team)
 If the cvar g_endlessaliens is set we will endlessly respawn aliens. More...
 
Player * AI_CreatePlayer (int team)
 Spawn civilians and aliens. More...
 

Variables

static pathing_thidePathingTable
 
static pathing_therdPathingTable
 

Detailed Description

Artificial Intelligence for opponents or human controlled actors that are panicked.

Definition in file g_ai.cpp.

Macro Definition Documentation

#define AI_ACTION_NOTHING_FOUND   -10000.0f
#define CALC_DAMAGE_SAMPLES   10.0f

Definition at line 260 of file g_ai.cpp.

Referenced by AI_CalcShotDamage().

#define CLOSE_IN_DIST   1200.0f

Definition at line 252 of file g_ai.cpp.

Referenced by AI_FighterCalcActionScore().

#define HERD_DIST   25

Definition at line 257 of file g_ai.cpp.

Referenced by AI_FindHerdLocation().

#define HERD_THRESHOLD   128.0f

Definition at line 237 of file g_ai.cpp.

Referenced by AI_FighterCalcActionScore(), and AI_FindHerdLocation().

#define HIDE_DIST   25

distance for (ai) hiding in grid tiles

Definition at line 256 of file g_ai.cpp.

Referenced by AI_FindHidingLocation().

#define HOLD_DIST   3

Definition at line 258 of file g_ai.cpp.

#define INVDEF_FOR_SHOOTTYPE (   st)    (IS_SHOT_RIGHT(st)?INVDEF(CID_RIGHT):IS_SHOT_LEFT(st)?INVDEF(CID_LEFT):IS_SHOT_HEADGEAR(st)?INVDEF(CID_HEADGEAR):nullptr)

Definition at line 261 of file g_ai.cpp.

Referenced by AI_FighterCalcActionScore(), and AI_PrepBestAction().

#define LOF_CHECK_PARTITIONS   4

Definition at line 762 of file g_ai.cpp.

Referenced by AI_CheckLineOfFire().

#define MISSION_HOLD_DIST   96

Definition at line 244 of file g_ai.cpp.

#define RUN_AWAY_DIST   160
#define SCORE_CIV_FACTOR   0.25f

Definition at line 228 of file g_ai.cpp.

Referenced by AI_FindBestFiredef().

#define SCORE_CIV_LAZINESS   5

Definition at line 234 of file g_ai.cpp.

Referenced by AI_CivilianCalcActionScore().

#define SCORE_CIV_RANDOM   10

Definition at line 232 of file g_ai.cpp.

Referenced by AI_CivilianCalcActionScore().

#define SCORE_CLOSE_IN   20

Definition at line 219 of file g_ai.cpp.

Referenced by AI_FighterCalcActionScore().

#define SCORE_DAMAGE   100.0f

Definition at line 226 of file g_ai.cpp.

Referenced by AI_FindBestFiredef().

#define SCORE_DAMAGE_FACTOR   1.25f

Definition at line 227 of file g_ai.cpp.

Referenced by AI_FindBestFiredef().

#define SCORE_DAMAGE_WORTH_FACTOR   0.1f

Definition at line 230 of file g_ai.cpp.

Referenced by AI_FindBestFiredef().

#define SCORE_DISABLED_FACTOR   0.25f

Definition at line 229 of file g_ai.cpp.

Referenced by AI_FindBestFiredef().

#define SCORE_HERDING_PENALTY   100

Definition at line 238 of file g_ai.cpp.

Referenced by AI_FighterCalcActionScore().

#define SCORE_HIDE   60

Definition at line 218 of file g_ai.cpp.

Referenced by AI_FighterCalcActionScore().

#define SCORE_KILL   30

Definition at line 220 of file g_ai.cpp.

Referenced by AI_FindBestFiredef().

#define SCORE_MISSION_HOLD   25

Definition at line 243 of file g_ai.cpp.

#define SCORE_MISSION_OPPONENT_TARGET   50

Definition at line 241 of file g_ai.cpp.

Referenced by AI_CheckForMissionTargets().

#define SCORE_MISSION_TARGET   60

Definition at line 242 of file g_ai.cpp.

Referenced by AI_CheckForMissionTargets().

#define SCORE_NONHIDING_PLACE_PENALTY   25

Definition at line 224 of file g_ai.cpp.

Referenced by AI_CivilianCalcActionScore(), and AI_PanicCalcActionScore().

#define SCORE_NOSAFE_POSITION_PENALTY   500
#define SCORE_PANIC_FLEE_FROM_STRANGERS   500.0f

Definition at line 247 of file g_ai.cpp.

Referenced by AI_PanicCalcActionScore().

#define SCORE_PANIC_RANDOM   25.0f

Definition at line 248 of file g_ai.cpp.

Referenced by AI_PanicCalcActionScore().

#define SCORE_PANIC_RUN_TO_FRIENDS   300.0f

Definition at line 246 of file g_ai.cpp.

Referenced by AI_PanicCalcActionScore().

#define SCORE_RAGE   40

Definition at line 225 of file g_ai.cpp.

Referenced by AI_FighterCalcActionScore().

#define SCORE_RANDOM   10

Definition at line 221 of file g_ai.cpp.

Referenced by AI_FighterCalcActionScore(), and AI_FindBestFiredef().

#define SCORE_REACTION_ERADICATION   30

Definition at line 222 of file g_ai.cpp.

Referenced by AI_FindBestFiredef().

#define SCORE_REACTION_FEAR_FACTOR   20

Definition at line 223 of file g_ai.cpp.

Referenced by AI_FighterCalcActionScore(), and AI_FindBestFiredef().

#define SCORE_RUN_AWAY   50

Definition at line 233 of file g_ai.cpp.

Referenced by AI_CheckForMissionTargets().

#define SPREAD_FACTOR   8.0f

Definition at line 253 of file g_ai.cpp.

#define SPREAD_NORM (   x)    ((x) > 0 ? SPREAD_FACTOR/((x)*torad) : 0)

Definition at line 254 of file g_ai.cpp.

#define WAYPOINT_CIV_DIST   768

Definition at line 236 of file g_ai.cpp.

Referenced by AI_CheckForMissionTargets().

Function Documentation

void AI_ActorRun ( Player &  player,
Actor actor 
)

Definition at line 1655 of file g_ai.cpp.

References AI_ActorThink(), AIL_ActorThink(), g_ailua, and cvar_s::integer.

Referenced by AI_PlayerRun(), G_MoralePanic(), and G_MoraleRage().

static void AI_ActorThink ( Player &  player,
Actor actor 
)
static

The think function for the ai controlled aliens or panicked humans.

Parameters
[in]playerThe AI or human player object
[in]actorThe ai controlled edict or the human actor edict
See also
AI_FighterCalcActionScore
AI_CivilianCalcActionScore
Note
we need to re-check the items here because they may have been dropped in the previous step
Todo:
If possible targets that can shoot back (check their inventory for weapons, not for ammo) are close, go into reaction fire mode, too

Definition at line 1592 of file g_ai.cpp.

References AI_CheckCrouch(), AI_PrepBestAction(), AI_TryToReloadWeapon(), AI_TurnIntoDirection(), CID_LEFT, CID_RIGHT, AiAction::fd, fireDef_s::fdIdx, G_ClientGetWeaponFromInventory(), G_ClientMove(), G_ClientShoot(), G_ClientStateChange(), G_IsDead, Edict::getLeftHandItem(), Edict::getRightHandItem(), Edict::getTeam(), Edict::hiding, Actor::isDead(), Actor::isPanicked(), Item::mustReload(), Edict::pos, AiAction::shootType, AiAction::shots, STATE_CROUCHED, AiAction::stop, AiAction::target, and AiAction::z_align.

Referenced by AI_ActorRun().

static bool AI_CheckCrouch ( const Actor actor)
static

Checks whether it would be smart to change the state to STATE_CROUCHED.

Parameters
[in]actorThe AI controlled actor to chech the state change for
Returns
true if the actor should go into STATE_CROUCHED, false otherwise

Definition at line 452 of file g_ai.cpp.

References ACTOR_VIS_50, G_ActorVis(), G_EdictsGetNextLivingActor(), G_FrustumVis(), G_IsCivilian, G_IsCrouched, G_VisCheckDist(), Edict::isSameTeamAs(), Edict::origin, and VectorDist.

Referenced by AI_ActorThink().

static bool AI_CheckFF ( const Edict ent,
const vec3_t  target,
float  spread,
float  radius 
)
static

Check whether friendly units are in the line of fire when shooting.

Parameters
[in]entAI that is trying to shoot
[in]targetShoot to this location
[in]spreadThe spread of the weapon used (from fireDef)
[in]radiusThe splash radius of the weapon

Definition at line 322 of file g_ai.cpp.

References DotProduct, G_EdictsGetNextLivingActorOfTeam(), Edict::getTeam(), Edict::isSameAs(), Edict::origin, PLAYER_WIDTH, torad, UNIT_SIZE, VectorAdd, VectorDist, VectorNormalizeFast(), VectorScale, and VectorSubtract.

Referenced by AI_FighterCheckShoot().

bool AI_CheckPosition ( const Actor *const  actor,
const pos3_t  pos 
)
void AI_CheckRespawn ( int  team)

If the cvar g_endlessaliens is set we will endlessly respawn aliens.

Note
This can be used for rescue or collect missions where it is enough to do something, and then leave the map (rescue zone)

Definition at line 1908 of file g_ai.cpp.

References G_AppearPerishEvent(), g_endlessaliens, G_EventActorAdd(), G_GetEquipmentForAISpawn(), G_GetPlayerForTeam(), G_SpawnAIPlayer(), G_VisToPM(), level_locals_s::initialAlienActorsSpawned, cvar_s::integer, level, level_locals_s::num_alive, PM_ALL, TEAM_ALIEN, and Edict::visflags.

Referenced by G_ClientEndRound().

bool AI_CheckUsingDoor ( const Edict ent,
const Edict door 
)

Checks whether the AI controlled actor wants to use a door.

Parameters
[in]entThe AI controlled actor
[in]doorThe door edict
Returns
true if the AI wants to use (open/close) that door, false otherwise
Note
Don't start any new events in here, don't change the actor state
See also
Touch_DoorTrigger
Todo:
Finish implementation

Definition at line 396 of file g_ai.cpp.

References ACTOR_VIS_0, Edict::doorState, f, frand(), G_ActorVis(), G_EdictsGetNextLivingActor(), G_FrustumVis(), G_VisCheckDist(), Edict::getTeam(), gi, Edict::hiding, Edict::isSameTeamAs(), Edict::origin, STATE_OPENED, TEAM_ALIEN, TEAM_CIVILIAN, Edict::type, and VectorDist.

Referenced by Touch_DoorTrigger().

static float AI_CivilianCalcActionScore ( Actor actor,
const pos3_t  to,
AiAction aia 
)
static
Player* AI_CreatePlayer ( int  team)

Spawn civilians and aliens.

Parameters
[in]team
See also
G_SpawnAIPlayer
Returns
Player pointer
Note
see cvars ai_singleplayeraliens, ai_numcivilians, ai_multiplayeraliens

Definition at line 1944 of file g_ai.cpp.

References ai_multiplayeraliens, ai_numcivilians, ai_singleplayeraliens, G_IsSinglePlayer, G_PlayerGetNextAI(), G_SetTeamForPlayer(), G_SpawnAIPlayers(), game, gi, level_locals_s::initialAlienActorsSpawned, cvar_s::integer, level, level_locals_s::num_spawned, game_locals_s::players, sv_ai, and TEAM_CIVILIAN.

Referenced by G_SpawnEntities(), and SVCmd_AI_Add_f().

static float AI_FighterCalcActionScore ( Actor actor,
const pos3_t  to,
AiAction aia 
)
static
See also
AI_ActorThink
Todo:

fill z_align values

optimize this

Todo:
do this decently, only penalizing the visible part of walk and penalizing much more for reaction shooters around; now it may remove some tactical options from aliens, e.g. they may now choose only the closer doors; however it's still better than going three times around soldier and only then firing at him
Todo:
also add bonus for fleeing from reaction fire and a huge malus if more than 1 move under reaction

Definition at line 1089 of file g_ai.cpp.

References ACTOR_VIS_10, AI_ACTION_NOTHING_FOUND, AI_CheckForMissionTargets(), AI_CheckPosition(), AI_FindBestFiredef(), AI_FindHidingLocation(), AI_GetHidingTeam(), AI_GetItemForShootType(), AI_HideNeeded(), AI_IsHandForForShootTypeFree(), AI_IsHostile(), AI_SearchGrenade(), Edict::calcOrigin(), CLOSE_IN_DIST, frand(), G_ActorMoveLength(), G_ActorVis(), G_EdictsGetNextLivingActor(), G_EdictsGetNextLivingActorOfTeam(), G_IsVisibleForTeam, Item::getFiredefs(), Edict::getTeam(), Actor::getUsableTUs(), HERD_THRESHOLD, invDef_s::in, INVDEF_FOR_SHOOTTYPE, Actor::isRaged(), Edict::isSamePosAs(), Edict::isSameTeamAs(), level, Edict::origin, invDef_s::out, level_locals_s::pathingMap, Edict::pos, AiAction::reset(), ROUTING_NOT_REACHABLE, SCORE_CLOSE_IN, SCORE_HERDING_PENALTY, SCORE_HIDE, SCORE_NOSAFE_POSITION_PENALTY, SCORE_RAGE, SCORE_RANDOM, SCORE_REACTION_FEAR_FACTOR, Edict::setOrigin(), AiAction::shootType, AiAction::shots, ST_NUM_SHOOT_TYPES, ST_RIGHT, AiAction::stop, AiAction::target, AiAction::to, TU_MOVE_STRAIGHT, VectorCopy, and VectorDist.

Referenced by AI_CivilianCalcActionScore(), and AI_PrepBestAction().

bool AI_FighterCheckShoot ( const Actor actor,
const Edict check,
const fireDef_t fd,
float  dist 
)

Check whether the fighter should perform the shoot.

Todo:

Check whether radius and power of fd are to to big for dist

Check whether the alien will die when shooting

Definition at line 364 of file g_ai.cpp.

References AI_CheckFF(), G_CalcEffectiveSpread(), Actor::isInsane(), Edict::origin, fireDef_s::range, and fireDef_s::splrad.

Referenced by actorL_throwgrenade(), AI_FindBestFiredef(), AI_SearchDestroyableObject(), and AIL_GetBestShot().

bool AI_FindHerdLocation ( Actor actor,
const pos3_t  from,
const vec3_t  target,
int  tu,
bool  inverse 
)

Tries to search a spot where actor will be more closer to the target and behind the target from enemy (ie hide behind target)

Parameters
[in]actorThe actor edict.
[in]fromThe grid position the actor is (theoretically) standing at and searching the nearest location from
[in]targetTries to find the nearest position to this location
[in]tuThe available TUs of the actor
[in]inverseTry to shield the target instead of using target as shield

Definition at line 659 of file g_ai.cpp.

References AI_CheckPosition(), AI_GetHidingTeam(), Edict::calcOrigin(), DotProduct, f, G_ActorMoveLength(), G_EdictsGetNextLivingActor(), G_MoveCalcLocal(), G_TagMalloc, AiAreaSearch::getNext(), Edict::getTeam(), HERD_DIST, HERD_THRESHOLD, length, Edict::origin, PATHFINDING_HEIGHT, Edict::pos, ROUTING_NOT_REACHABLE, TAG_LEVEL, TU_MOVE_STRAIGHT, VectorCopy, VectorDistSqr, VectorNormalizeFast(), and VectorSubtract.

Referenced by AIL_positionherd().

bool AI_FindHidingLocation ( int  team,
Actor actor,
const pos3_t  from,
int  tuLeft 
)

Tries to search a hiding spot.

Parameters
[out]actorThe actor edict. The position of the actor is updated here to perform visibility checks
[in]fromThe grid position the actor is (theoretically) standing at and searching a hiding location from
[in,out]tuLeftThe amount of left TUs to find a hiding spot. The TUs needed to walk to the grid position is subtracted. May not be nullptr.
[in]teamThe team from which actor tries to hide
Returns
true if hiding is possible, false otherwise

Definition at line 606 of file g_ai.cpp.

References AI_ACTION_NOTHING_FOUND, AI_CheckPosition(), AI_IsExposed(), Edict::calcOrigin(), G_ActorMoveLength(), G_MoveCalcLocal(), G_TagMalloc, AiAreaSearch::getNext(), HIDE_DIST, PATHFINDING_HEIGHT, Edict::pos, ROUTING_NOT_REACHABLE, TAG_LEVEL, TU_MOVE_STRAIGHT, and VectorCopy.

Referenced by AI_FighterCalcActionScore(), and AIL_positionhide().

bool AI_FindMissionLocation ( Actor actor,
const pos3_t  to,
int  tus,
int  radius 
)

Try to go close to a mission edict.

Parameters
[in,out]actorThe actor edict.
[in]toThe target position.
[in]tusAvailable Time Units
[in]radiusRadius of the area to search
Returns
true if found a suitable position, false otherwise

Definition at line 1423 of file g_ai.cpp.

References AI_CheckPosition(), G_ActorMoveLength(), AiAreaSearch::getNext(), length, level, level_locals_s::pathingMap, Edict::pos, ROUTING_NOT_REACHABLE, VectorCompare, and VectorCopy.

Referenced by AIL_positionmission().

int AI_GetHidingTeam ( const Edict ent)

Returns the value for the vis check whenever an ai actor tries to hide. For aliens this is the inverse team - see the vis check code for the inverse team rules to see how this works. For civilians we have to specify the alien team and can't use the inverse team rules. This is needed because the inverse team rules aren't working for the civilian team - see TEAM_CIVILIAN.

Returns
A negative team number means "every other team" as the one from the given ent. See the vis check functions for the inverse team rules for more information.

Definition at line 570 of file g_ai.cpp.

References G_IsCivilian, Edict::getTeam(), and TEAM_ALIEN.

Referenced by AI_FighterCalcActionScore(), AI_FindHerdLocation(), AI_HideNeeded(), AIL_positionapproach(), AIL_positionflee(), and AIL_positionhide().

const Item* AI_GetItemForShootType ( shoot_types_t  shootType,
const Edict ent 
)

Returns the item of the currently chosen shoot type of the ai actor.

Parameters
shootTypeThe current selected shoot type
entThe ai actor
Returns
The item that was selected for the given shoot type. This might be nullptr if no item was found.

Definition at line 541 of file g_ai.cpp.

References AI_GetItemFromInventory(), Edict::getLeftHandItem(), Edict::getRightHandItem(), IS_SHOT_HEADGEAR, IS_SHOT_LEFT, IS_SHOT_REACTION, and IS_SHOT_RIGHT.

Referenced by AI_FighterCalcActionScore(), AI_HasLineOfFire(), AIL_GetBestShot(), and AIL_positionshoot().

static const Item* AI_GetItemFromInventory ( const Item ic)
inlinestatic

Returns useable item from the given inventory list. That means that the 'weapon' has ammunition left or must not be reloaded.

Parameters
icThe inventory to search a useable weapon in.
Returns
Ready to fire weapon.

Definition at line 522 of file g_ai.cpp.

References Item::ammoDef(), Item::isWeapon(), and Item::mustReload().

Referenced by AI_GetItemForShootType().

bool AI_HasLineOfFire ( const Actor actor,
const Edict target 
)

Check if actor has a line of fire to the target given.

Definition at line 275 of file g_ai.cpp.

References AI_CheckLineOfFire(), AI_GetItemForShootType(), Item::ammoDef(), Item::getFiredefs(), objDef_s::numFiredefs, ST_NUM_SHOOT_TYPES, ST_RIGHT, and fireDef_s::weapFdsIdx.

Referenced by AI_HideNeeded(), and AI_IsExposed().

bool AI_HideNeeded ( const Actor actor)

Checks whether the given alien should try to hide because there are enemies close enough to shoot the alien.

Parameters
[in]actorThe alien edict that should (maybe) hide
Returns
true if hide is needed or false if the alien thinks that it is not needed

Definition at line 484 of file g_ai.cpp.

References AI_GetHidingTeam(), AI_HasLineOfFire(), AI_IsHostile(), crand(), fireDef_s::damage, G_EdictsGetNextLivingActor(), G_Vis(), Item::getFiredefs(), Edict::getLeftHandItem(), Edict::getRightHandItem(), Edict::HP, cvar_s::integer, mor_brave, Edict::morale, Edict::origin, fireDef_s::range, fireDef_s::spldmg, VectorDistSqr, and VT_NOFRUSTUM.

Referenced by AI_FighterCalcActionScore(), and AIL_hideneeded().

void AI_Init ( void  )

Definition at line 266 of file g_ai.cpp.

Referenced by G_Init().

static void AI_InitPlayer ( const Player &  player,
Actor actor,
const equipDef_t ed 
)
static

Initializes the actor.

Parameters
[in]playerPlayer to which this actor belongs.
[in,out]actorPointer to Edict representing actor.
[in]edEquipment definition for the new actor. Might be nullptr.

Definition at line 1823 of file g_ai.cpp.

References AI_SetCharacterValues(), AI_SetEquipment(), AI_SetStats(), AIL_InitActor(), Edict::chr, CHRSH_CharGetBody(), CHRSH_CharGetHead(), frand(), G_ClientStateChange(), gi, Actor::setBody(), Actor::setHead(), and STATE_REACTION.

Referenced by G_SpawnAIPlayer().

static bool AI_IsExposed ( int  team,
Actor check 
)
static

Test if check is exposed to the enemy team.

Definition at line 298 of file g_ai.cpp.

References AI_HasLineOfFire(), G_EdictsGetNextLivingActor(), G_TestVis(), Edict::getTeam(), VS_YES, VT_NOFRUSTUM, and VT_PERISHCHK.

Referenced by AI_FindHidingLocation().

static bool AI_IsHandForForShootTypeFree ( shoot_types_t  shootType,
Actor actor 
)
static

Check if the hand for the given shoot type is free.

Returns
true if shoot type uses a hand and it is free, false if hand isn't free or shoot type doesn't use a hand.

Definition at line 987 of file g_ai.cpp.

References Edict::getLeftHandItem(), Edict::getRightHandItem(), IS_SHOT_LEFT, IS_SHOT_REACTION, IS_SHOT_RIGHT, and Item::isHeldTwoHanded().

Referenced by AI_FighterCalcActionScore(), and AI_PrepBestAction().

bool AI_IsHostile ( const Actor actor,
const Edict target 
)

Check if actor perceives target as hostile.

Note
Takes lose of sanity in consideration.
Parameters
[in]actorThe actor that checks for hostiles.
[in]targetThe possible hostile actor.
Returns
true if actor perceives target as hostile

Definition at line 933 of file g_ai.cpp.

References G_IsCivilian, G_IsMultiPlayer, Actor::isInsane(), and Edict::isOpponent().

Referenced by actorL_isvalidtarget(), actorL_throwgrenade(), AI_FighterCalcActionScore(), AI_HideNeeded(), AIL_positionflee(), and AIL_positionshoot().

static float AI_PanicCalcActionScore ( Actor actor,
const pos3_t  to,
AiAction aia 
)
static

Calculates possible actions for a panicking unit.

Parameters
[in]actorPointer to an edict which is panicking.
[in]toThe grid position to walk to.
[in]aiaPointer to aiAction containing information about possible action.
See also
AI_ActorThink
Note
Panicking units will run away from everyone other than their own team (e.g. aliens will run away even from civilians)

Definition at line 1351 of file g_ai.cpp.

References ACTOR_VIS_10, AI_ACTION_NOTHING_FOUND, AI_CheckPosition(), frand(), G_ActorMoveLength(), G_ActorVis(), G_EdictsGetNextLivingActor(), Actor::getUsableTUs(), Actor::isInsane(), Edict::isSameTeamAs(), level, Edict::origin, level_locals_s::pathingMap, Edict::pos, AiAction::reset(), ROUTING_NOT_REACHABLE, RUN_AWAY_DIST, SCORE_NONHIDING_PLACE_PENALTY, SCORE_NOSAFE_POSITION_PENALTY, SCORE_PANIC_FLEE_FROM_STRANGERS, SCORE_PANIC_RANDOM, SCORE_PANIC_RUN_TO_FRIENDS, Edict::setOrigin(), AiAction::stop, AiAction::to, UNIT_SIZE, VectorCopy, and VectorDist.

Referenced by AI_PrepBestAction().

static void AI_PlayerRun ( Player &  player)
static

Duke's playground for a completely new AI. While in developement, it is only available to Phalanx

Definition at line 1672 of file g_ai.cpp.

References level_locals_s::activeTeam, AI_ActorRun(), AI_TeamThink(), AIL_TeamThink(), g_aihumans, g_ailua, G_ClientEndRound(), G_EdictsGetNextLivingActorOfTeam(), Edict::getTeam(), Edict::getTus(), cvar_s::integer, level, and TEAM_PHALANX.

Referenced by AI_Run().

void AI_Run ( void  )

Every server frame one single actor is handled - always in the same order.

See also
G_RunFrame

Definition at line 1713 of file g_ai.cpp.

References AI_PlayerRun(), level_locals_s::framenum, g_aihumans, G_PlayerGetNextActiveAI(), G_PlayerGetNextActiveHuman(), cvar_s::integer, and level.

Referenced by G_RunFrame().

static Edict* AI_SearchDestroyableObject ( const Actor actor,
const fireDef_t fd 
)
static
Todo:
This feature causes the 'aliens shoot at walls'-bug. I considered adding a visibility check, but that wouldn't prevent aliens from shooting at the breakable parts of their own ship. So I disabled it for now. Duke, 23.10.09

Definition at line 737 of file g_ai.cpp.

References ACTOR_VIS_0, AI_FighterCheckShoot(), G_ActorVis(), G_EdictsGetNextInUse(), G_IsBreakable, and Edict::origin.

Referenced by AI_FindBestFiredef().

const invDef_t* AI_SearchGrenade ( const Actor actor,
Item **  ip 
)

Search the edict's inventory for a grenade or other one-use weapon.

Definition at line 954 of file g_ai.cpp.

References Edict::chr, Item::def(), Container::def(), Inventory::getNextCont(), Container::getNextItem(), character_s::inv, Item::isWeapon(), Item::mustReload(), invDef_s::out, and Q_streq.

Referenced by actorL_throwgrenade(), AI_FighterCalcActionScore(), and AI_PrepBestAction().

static void AI_SetCharacterValues ( Edict ent,
int  team 
)
static

Sets an actor's character values.

Parameters
entActor to set the model for.
[in]teamTeam to which actor belongs.

Definition at line 1784 of file g_ai.cpp.

References csi_s::alienTeams, Edict::chr, game_import_s::csi, game_import_s::Cvar_String(), gi, teamDef_s::id, csi_s::numAlienTeams, TEAM_CIVILIAN, and character_s::teamDef.

Referenced by AI_InitPlayer().

static void AI_SetEquipment ( Edict ent,
const equipDef_t ed 
)
static

Sets the actor's equipment.

Parameters
entActor to give equipment to.
[in]edEquipment definition for the new actor.

Definition at line 1811 of file g_ai.cpp.

References ABILITY_POWER, Edict::chr, InventoryInterface::EquipActor(), game, game_locals_s::invi, teamDef_s::onlyWeapon, character_s::score, chrScoreGlobal_s::skills, and character_s::teamDef.

Referenced by AI_InitPlayer().

static bool AI_TeamThink ( Player &  player)
static

Definition at line 1666 of file g_ai.cpp.

Referenced by AI_PlayerRun().

bool AI_TryToReloadWeapon ( Actor actor,
containerIndex_t  containerID 
)
void AI_TurnIntoDirection ( Actor actor,
const pos3_t  pos 
)

This function will turn the AI actor into the direction that is needed to walk to the given location.

Parameters
[in]actorThe actor to turn
[in]posThe position to set the direction for

Definition at line 1557 of file g_ai.cpp.

References CORE_DIRECTIONS, FLYING_DIRECTIONS, G_ActorDoTurn(), G_MoveCalc(), getDVdir, Edict::getTeam(), Actor::getUsableTUs(), gi, Actor::isCrouched(), level, level_locals_s::pathingMap, and ROUTING_UNREACHABLE.

Referenced by AI_ActorThink(), and pos3L_face().

void G_AddToWayPointList ( Edict ent)

Definition at line 1537 of file g_ai.cpp.

References level_locals_s::ai_waypointList, Edict::groupChain, and level.

Referenced by SP_civilian_target().

static const equipDef_t* G_GetEquipmentForAISpawn ( int  team)
static
static void G_SpawnAIPlayers ( const Player &  player,
int  numSpawn 
)
static

Spawn civilians and aliens.

Parameters
[in]player
[in]numSpawn
See also
AI_CreatePlayer

Definition at line 1889 of file g_ai.cpp.

References G_CheckVis(), G_GetEquipmentForAISpawn(), G_SpawnAIPlayer(), G_VisFlagsClear(), and i.

Referenced by AI_CreatePlayer().

Variable Documentation

pathing_t* herdPathingTable
static

Definition at line 264 of file g_ai.cpp.

pathing_t* hidePathingTable
static

Definition at line 263 of file g_ai.cpp.