UFO: Alien Invasion
|
Artificial Intelligence functions. More...
#include "g_local.h"
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. More... | |
void | G_AddToWayPointList (Edict *ent) |
void | AI_Run (void) |
Every server frame one single actor is handled - always in the same order. More... | |
void | AI_ActorRun (Player &player, Actor *actor) |
Player * | AI_CreatePlayer (int team) |
Spawn civilians and aliens. More... | |
bool | AI_CheckUsingDoor (const Edict *ent, const Edict *door) |
Checks whether the AI controlled actor wants to use a door. More... | |
bool | AI_HasLineOfFire (const Actor *actor, const Edict *target) |
Check if actor has a line of fire to the target given. More... | |
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_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... | |
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... | |
const Item * | AI_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. More... | |
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... | |
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... | |
bool | AI_IsHostile (const Actor *actor, const Edict *target) |
Check if actor perceives target as hostile. More... | |
const invDef_t * | AI_SearchGrenade (const Actor *actor, Item **ip) |
Search the edict's inventory for a grenade or other one-use weapon. More... | |
bool | AI_FindMissionLocation (Actor *actor, const pos3_t to, int tus, int radius=0) |
Try to go close to a mission edict. More... | |
bool | AI_CheckPosition (const Actor *const ent, const pos3_t pos) |
Checks if the given position is safe to stand on. 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... | |
bool | AIL_TeamThink (Player &player) |
The team think function for the ai controlled players. More... | |
void | AIL_ActorThink (Player &player, Actor *actor) |
The think function for the ai controlled players. More... | |
int | AIL_InitActor (Actor *actor) |
Initializes the lua AI for an actor. More... | |
void | AIL_Cleanup (void) |
Closes the LUA AI. More... | |
void | AIL_Init (void) |
void | AIL_Shutdown (void) |
Variables | |
Edict * | ai_waypointList |
Artificial Intelligence functions.
Definition in file g_ai.h.
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().
float AI_CalcShotDamage | ( | Actor * | actor, |
const Actor * | target, | ||
const fireDef_t * | fd, | ||
shoot_types_t | shotType | ||
) |
Calculate estimated damage per single shoot.
Definition at line 811 of file g_ai.cpp.
References CALC_DAMAGE_SAMPLES, shot_mock_s::civilian, shot_mock_s::damage, shot_mock_s::enemyCount, fireDef_s::fdIdx, shot_mock_s::friendCount, G_ClientShoot(), G_IsAlien, Edict::getPlayer(), fireDef_s::gravity, GROUND_DELTA, i, Actor::isInsane(), Actor::isStunned(), Edict::pos, fireDef_s::shots, and fireDef_s::splrad.
Referenced by AI_FindBestFiredef(), and AIL_GetBestShot().
bool AI_CheckLineOfFire | ( | const Actor * | shooter, |
const Edict * | target, | ||
const fireDef_t * | fd, | ||
int | shots | ||
) |
Definition at line 763 of file g_ai.cpp.
References fireDef_s::bounce, fireDef_s::damage, trace_s::entNum, f, trace_s::fraction, G_EdictsGetByNum(), G_IsBreakable, G_IsBrushModel, G_Trace(), fireDef_s::getShotOrigin(), gi, fireDef_s::gravity, GRAVITY, GROUND_DELTA, Edict::HP, i, Actor::isCrouched(), fireDef_s::launched, LOF_CHECK_PARTITIONS, MASK_SHOT, Edict::origin, Edict::pos, fireDef_s::range, fireDef_s::rolled, fireDef_s::shots, fireDef_s::splrad, v, VectorAdd, VectorCompare, VectorCopy, VectorScale, and VectorSubtract.
Referenced by actorL_throwgrenade(), AI_FindBestFiredef(), AI_HasLineOfFire(), and AIL_GetBestShot().
Checks if the given position is safe to stand on.
true
if the actor's position is deemed safe. Definition at line 581 of file g_ai.cpp.
References Edict::dmg, Edict::dmgtype, G_ApplyProtection(), G_EdictsGetNextInUse(), Actor::isInsane(), and Edict::isSamePosAs().
Referenced by AI_CivilianCalcActionScore(), AI_FighterCalcActionScore(), AI_FindHerdLocation(), AI_FindHidingLocation(), AI_FindMissionLocation(), AI_PanicCalcActionScore(), AIL_findweapons(), AIL_positionapproach(), AIL_positionflee(), AIL_positionshoot(), and AIL_positionwander().
If the cvar g_endlessaliens is set we will endlessly respawn aliens.
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().
Checks whether the AI controlled actor wants to use a door.
[in] | ent | The AI controlled actor |
[in] | door | The door edict |
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().
Player* AI_CreatePlayer | ( | int | team | ) |
Spawn civilians and aliens.
[in] | team |
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().
bool AI_FighterCheckShoot | ( | const Actor * | actor, |
const Edict * | check, | ||
const fireDef_t * | fd, | ||
float | dist | ||
) |
Check whether the fighter should perform the shoot.
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)
[in] | actor | The actor edict. |
[in] | from | The grid position the actor is (theoretically) standing at and searching the nearest location from |
[in] | target | Tries to find the nearest position to this location |
[in] | tu | The available TUs of the actor |
[in] | inverse | Try 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().
Tries to search a hiding spot.
[out] | actor | The actor edict. The position of the actor is updated here to perform visibility checks |
[in] | from | The grid position the actor is (theoretically) standing at and searching a hiding location from |
[in,out] | tuLeft | The 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] | team | The team from which actor tries to hide |
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().
Try to go close to a mission edict.
[in,out] | actor | The actor edict. |
[in] | to | The target position. |
[in] | tus | Available Time Units |
[in] | radius | Radius of the area to search |
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().
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
.
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.
shootType | The current selected shoot type |
ent | The ai actor |
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().
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.
[in] | actor | The alien edict that should (maybe) hide |
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().
Check if actor
perceives target
as hostile.
[in] | actor | The actor that checks for hostiles. |
[in] | target | The possible hostile actor. |
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().
Every server frame one single actor is handled - always in the same order.
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().
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().
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
Definition at line 1574 of file g_ai.cpp.
References Edict::chr, CID_FLOOR, G_ActorInvMove(), G_ActorReload(), G_ClientCanReload(), G_ReactionFireSettingsUpdate(), Edict::getContainer(), FiremodeSettings::getFmIdx(), FiremodeSettings::getHand(), FiremodeSettings::getWeapon(), INVDEF, NONE, and character_s::RFmode.
Referenced by AI_ActorThink(), and AIL_reload().
This function will turn the AI actor into the direction that is needed to walk to the given location.
[in] | actor | The actor to turn |
[in] | pos | The 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().
The think function for the ai controlled players.
[in] | player | |
[in] | actor |
Definition at line 2108 of file g_ai_lua.cpp.
References Edict::AI, AIL_player, ailState, gi, and AI_s::type.
Referenced by AI_ActorRun().
Closes the LUA AI.
Definition at line 2308 of file g_ai_lua.cpp.
References ailState.
Referenced by G_MatchDoEnd().
Definition at line 2245 of file g_ai_lua.cpp.
References AILPW_CCW, AILPW_CW, AILPW_RAND, AILSC_DIST, AILSC_HP, AILSC_PATH, AILSP_DMG, AILSP_FAR, AILSP_FAST, AILSP_NEAR, ailState, AILVT_ALL, AILVT_DIST, AILVT_SIGHT, AILVT_TEAM, gi, TEAM_ALIEN, TEAM_ALL, TEAM_CIVILIAN, and TEAM_PHALANX.
Referenced by G_Init().
Initializes the lua AI for an actor.
[in] | actor | Pointer to actor to initialize AI for. |
0
on success. Definition at line 2203 of file g_ai_lua.cpp.
References Edict::AI, AIL_GetAIType(), AIL_InitLua(), ailState, Edict::chr, Com_sprintf(), Edict::getTeam(), gi, teamDef_s::id, luaL_dobuffer, MAX_VAR, Q_strncpyz(), AI_s::subtype, character_s::teamDef, and AI_s::type.
Referenced by AI_InitPlayer(), and G_ClientTeamInfo().
bool AIL_TeamThink | ( | Player & | player | ) |
The team think function for the ai controlled players.
[in] | player |
Definition at line 2156 of file g_ai_lua.cpp.
References AIL_GetAIType(), AIL_player, AIL_toTeamString(), ailState, and gi.
Referenced by AI_PlayerRun().
Definition at line 1537 of file g_ai.cpp.
References level_locals_s::ai_waypointList, Edict::groupChain, and level.
Referenced by SP_civilian_target().
Edict* ai_waypointList |