UFO: Alien Invasion
Loading...
Searching...
No Matches
g_ai.h File Reference

Artificial Intelligence functions. More...

#include "g_local.h"
Include dependency graph for g_ai.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

class  AiAreaSearch
 AiAreaSearch class, used to get an area of the map around a certain position for the AI to check possible moving positions. More...
class  AiAreaSearch::LQueue
 A simple queue class. More...
struct  AiAreaSearch::LQueue::qnode_s

Functions

void AI_Init (void)
void AI_CheckRespawn (int team)
 If the cvar g_endlessaliens is set we will endlessly respawn aliens.
void G_AddToWayPointList (Edict *ent)
void AI_Run (void)
 Every server frame one single actor is handled - always in the same order.
void AI_ActorRun (Player &player, Actor *actor)
Player * AI_CreatePlayer (int team)
 Spawn civilians and aliens.
bool AI_CheckUsingDoor (const Edict *ent, const Edict *door)
 Checks whether the AI controlled actor wants to use a door.
bool AI_HasLineOfFire (const Actor *actor, const Edict *target)
 Check if actor has a line of fire to the target given.
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.
bool AI_FindHidingLocation (int team, Actor *actor, const pos3_t from, int tuLeft)
 Tries to search a hiding spot.
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).
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.
const ItemAI_GetItemForShootType (shoot_types_t shootType, const Edict *ent)
bool AI_FighterCheckShoot (const Actor *actor, const Edict *check, const fireDef_t *fd, float dist)
 Check whether the fighter should perform the shoot.
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.
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
bool AI_IsHostile (const Actor *actor, const Edict *target)
 Check if actor perceives target as hostile.
const invDef_tAI_SearchGrenade (const Actor *actor, Item **ip)
 Search the edict's inventory for a grenade or other one-use weapon.
bool AI_FindMissionLocation (Actor *actor, const pos3_t to, int tus, int radius=0)
 Try to go close to a mission edict.
bool AI_CheckPosition (const Actor *const ent, const pos3_t pos)
 Checks if the given position is safe to stand on.
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.
bool AIL_TeamThink (Player &player)
 The team think function for the ai controlled players.
void AIL_ActorThink (Player &player, Actor *actor)
 The think function for the ai controlled players.
int AIL_InitActor (Actor *actor)
 Initializes the lua AI for an actor.
void AIL_Cleanup (void)
 Closes the LUA AI.
void AIL_Init (void)
void AIL_Shutdown (void)

Variables

Edictai_waypointList

Detailed Description

Artificial Intelligence functions.

Definition in file g_ai.h.

Function Documentation

◆ AI_ActorRun()

void AI_ActorRun ( Player & player,
Actor * actor )

Definition at line 1655 of file g_ai.cpp.

References AI_ActorThink(), AIL_ActorThink(), and g_ailua.

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

◆ AI_CalcShotDamage()

◆ AI_CheckLineOfFire()

◆ AI_CheckPosition()

bool AI_CheckPosition ( const Actor *const actor,
const pos3_t pos )

◆ AI_CheckRespawn()

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, PM_ALL, TEAM_ALIEN, and Edict::visflags.

Referenced by G_ClientEndRound().

◆ AI_CheckUsingDoor()

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, 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().

◆ AI_CreatePlayer()

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, sv_ai, and TEAM_CIVILIAN.

Referenced by G_SpawnEntities(), and SVCmd_AI_Add_f().

◆ AI_FighterCheckShoot()

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_t::range, and fireDef_t::splrad.

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

◆ AI_FindHerdLocation()

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, G_ActorMoveLength(), G_EdictsGetNextLivingActor(), G_MoveCalcLocal(), G_TagMalloc, AiAreaSearch::getNext(), Edict::getTeam(), HERD_DIST, HERD_THRESHOLD, herdPathingTable, length, Edict::origin, PATHFINDING_HEIGHT, Edict::pos, ROUTING_NOT_REACHABLE, TAG_LEVEL, TU_MOVE_STRAIGHT, VectorCopy, VectorDistSqr, VectorNormalizeFast(), and VectorSubtract.

Referenced by AIL_positionherd().

◆ AI_FindHidingLocation()

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, hidePathingTable, PATHFINDING_HEIGHT, Edict::pos, ROUTING_NOT_REACHABLE, TAG_LEVEL, TU_MOVE_STRAIGHT, and VectorCopy.

Referenced by AI_FighterCalcActionScore(), and AIL_positionhide().

◆ AI_FindMissionLocation()

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, Edict::pos, ROUTING_NOT_REACHABLE, VectorCompare, and VectorCopy.

Referenced by AIL_positionmission().

◆ AI_GetHidingTeam()

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().

◆ AI_GetItemForShootType()

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().

◆ AI_HasLineOfFire()

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(), ST_NUM_SHOOT_TYPES, ST_RIGHT, and fireDef_t::weapFdsIdx.

Referenced by AI_HideNeeded(), and AI_IsExposed().

◆ AI_HideNeeded()

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_t::damage, G_EdictsGetNextLivingActor(), G_Vis(), Item::getFiredefs(), Edict::getLeftHandItem(), Edict::getRightHandItem(), Edict::HP, mor_brave, Edict::morale, Edict::origin, fireDef_t::range, fireDef_t::spldmg, VectorDistSqr, and VT_NOFRUSTUM.

Referenced by AI_FighterCalcActionScore(), and AIL_hideneeded().

◆ AI_Init()

void AI_Init ( void )

Definition at line 266 of file g_ai.cpp.

References herdPathingTable, and hidePathingTable.

Referenced by G_Init().

◆ AI_IsHostile()

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().

◆ 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(), g_aihumans, G_PlayerGetNextActiveAI(), G_PlayerGetNextActiveHuman(), and level.

Referenced by G_RunFrame().

◆ AI_SearchGrenade()

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

◆ AI_TryToReloadWeapon()

bool AI_TryToReloadWeapon ( Actor * actor,
containerIndex_t containerID )

◆ AI_TurnIntoDirection()

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, and ROUTING_UNREACHABLE.

Referenced by AI_ActorThink(), and pos3L_face().

◆ AIL_ActorThink()

void AIL_ActorThink ( Player & player,
Actor * actor )

The think function for the ai controlled players.

Parameters
[in]player
[in]actor

Definition at line 2118 of file g_ai_lua.cpp.

References Edict::AI, AIL_ent, AIL_player, ailState, gi, and AI_t::type.

Referenced by AI_ActorRun().

◆ AIL_Cleanup()

void AIL_Cleanup ( void )

Closes the LUA AI.

Definition at line 2321 of file g_ai_lua.cpp.

References ailState.

Referenced by G_MatchDoEnd().

◆ AIL_Init()

◆ AIL_InitActor()

int AIL_InitActor ( Actor * actor)

Initializes the lua AI for an actor.

Parameters
[in]actorPointer to actor to initialize AI for.
Returns
0 on success.

Definition at line 2216 of file g_ai_lua.cpp.

References Edict::AI, AIL_GetAIType(), AIL_InitLua(), ailState, Edict::chr, Com_sprintf(), Edict::getTeam(), gi, teamDef_t::id, luaL_dobuffer, MAX_VAR, Q_strncpyz(), AI_t::subtype, character_t::teamDef, and AI_t::type.

Referenced by AI_InitPlayer(), and G_ClientTeamInfo().

◆ AIL_Shutdown()

void AIL_Shutdown ( void )

Definition at line 2289 of file g_ai_lua.cpp.

References gi.

Referenced by G_Shutdown().

◆ AIL_TeamThink()

bool AIL_TeamThink ( Player & player)

The team think function for the ai controlled players.

Parameters
[in]player

Definition at line 2166 of file g_ai_lua.cpp.

References AIL_ent, AIL_GetAIType(), AIL_player, AIL_toTeamString(), ailState, and gi.

Referenced by AI_PlayerRun().

◆ G_AddToWayPointList()

void G_AddToWayPointList ( Edict * ent)

Definition at line 1537 of file g_ai.cpp.

References Edict::groupChain, and level.

Referenced by SP_civilian_target().

Variable Documentation

◆ ai_waypointList

Edict* ai_waypointList
extern