Artificial Intelligence. More...
#include "g_local.h"
#include "g_ai.h"
Go to the source code of this file.
Defines | |
#define | AI_MAX_DIST 30 |
Functions | |
static qboolean | AI_CheckFF (const edict_t *ent, const vec3_t target, float spread) |
Check whether friendly units are in the line of fire when shooting. | |
static qboolean | AI_FighterCheckShoot (const edict_t *ent, const edict_t *check, const fireDef_t *fd, float *dist) |
Check whether the fighter should perform the shoot. | |
qboolean | AI_CheckUsingDoor (const edict_t *ent, const edict_t *door) |
Checks whether the AI controlled actor wants to use a door. | |
static qboolean | AI_CheckCrouch (const edict_t *ent) |
Checks whether it would be smart to change the state to STATE_CROUCHED. | |
static qboolean | AI_HideNeeded (const edict_t *ent) |
Checks whether the given alien should try to hide because there are enemies close enough to shoot the alien. | |
static const item_t * | AI_GetItemFromInventory (const invList_t *ic) |
Returns useable item from the given inventory list. That means that the 'weapon' has ammunition left or must not be reloaded. | |
const item_t * | AI_GetItemForShootType (shoot_types_t shootType, const edict_t *ent) |
int | AI_GetHidingTeam (const edict_t *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 . | |
qboolean | AI_FindHidingLocation (int team, edict_t *ent, const pos3_t from, int *tuLeft) |
Tries to search a hiding spot. | |
qboolean | AI_FindHerdLocation (edict_t *ent, const pos3_t from, const vec3_t target, int tu) |
Tries to search a spot where actor will be more closer to the target and behind the target from enemy. | |
static edict_t * | AI_SearchDestroyableObject (const edict_t *ent, const fireDef_t *fd) |
static void | AI_SearchBestTarget (aiAction_t *aia, const edict_t *ent, edict_t *check, const item_t *item, shoot_types_t shootType, int tu, float *maxDmg, int *bestTime, const fireDef_t *fdArray) |
static float | AI_FighterCalcBestAction (edict_t *ent, pos3_t to, aiAction_t *aia) |
static float | AI_CivilianCalcBestAction (edict_t *ent, pos3_t to, aiAction_t *aia) |
Calculates possible actions for a civilian. | |
static int | AI_CheckForMissionTargets (const player_t *player, edict_t *ent, aiAction_t *aia) |
Searches the map for mission edicts and try to get there. | |
static aiAction_t | AI_PrepBestAction (const player_t *player, edict_t *ent) |
Attempts to find the best action for an alien. Moves the alien into the starting position for that action and returns the action. | |
void | G_AddToWayPointList (edict_t *ent) |
void | AI_TurnIntoDirection (edict_t *ent, const pos3_t pos) |
This function will turn the AI actor into the direction that is needed to walk to the given location. | |
static void | AI_TryToReloadWeapon (edict_t *ent, containerIndex_t containerID) |
if a weapon can be reloaded we attempt to do so if TUs permit, otherwise drop it | |
void | AI_ActorThink (player_t *player, edict_t *ent) |
The think function for the ai controlled aliens. | |
void | AI_Run (void) |
Every server frame one single actor is handled - always in the same order. | |
static void | AI_SetStats (edict_t *ent) |
Initializes the actor's stats like morals, strength and so on. | |
static void | AI_SetCharacterValues (edict_t *ent, int team) |
Sets an actor's character values. | |
static void | AI_SetEquipment (edict_t *ent, const equipDef_t *ed) |
Sets the actor's equipment. | |
static void | AI_InitPlayer (const player_t *player, edict_t *ent, const equipDef_t *ed) |
Initializes the actor. | |
static void | G_SpawnAIPlayer (const player_t *player, int numSpawn) |
Spawn civilians and aliens. | |
player_t * | AI_CreatePlayer (int team) |
Spawn civilians and aliens. | |
Variables | |
edict_t * | ai_waypointList |
Artificial Intelligence.
Definition in file g_ai.c.
The think function for the ai controlled aliens.
[in] | player | |
[in] | ent |
Definition at line 964 of file g_ai.c.
References AI_CheckCrouch(), AI_PrepBestAction(), AI_TryToReloadWeapon(), AI_TurnIntoDirection(), game_import_t::csi, aiAction_t::fd, fireDef_s::fdIdx, G_ClientGetWeaponFromInventory(), G_ClientMove(), G_ClientShoot(), G_ClientStateChange(), G_IsDead, G_IsPaniced, gi, edict_s::hiding, csi_s::idLeft, csi_s::idRight, LEFT, edict_s::pos, qfalse, qtrue, RIGHT, aiAction_t::shootType, aiAction_t::shots, STATE_CROUCHED, aiAction_t::stop, aiAction_t::target, edict_s::team, and aiAction_t::z_align.
Referenced by AI_Run(), G_MoralePanic(), and G_MoraleRage().
Checks whether it would be smart to change the state to STATE_CROUCHED.
[in] | ent | The AI controlled actor to chech the state change for |
Definition at line 157 of file g_ai.c.
References ACTOR_VIS_50, check, G_ActorVis(), G_EdictsGetNextLivingActor(), G_FrustumVis(), G_IsCivilian, MAX_SPOT_DIST, edict_s::origin, qfalse, qtrue, edict_s::team, and VectorDist.
Referenced by AI_ActorThink().
Check whether friendly units are in the line of fire when shooting.
[in] | ent | AI that is trying to shoot |
[in] | target | Shoot to this location |
[in] | spread |
Definition at line 35 of file g_ai.c.
References check, DotProduct, G_EdictsGetNextLivingActorOfTeam(), edict_s::origin, PLAYER_WIDTH, qfalse, qtrue, edict_s::team, torad, VectorAdd, VectorNormalize(), VectorScale, and VectorSubtract.
Referenced by AI_FighterCheckShoot().
static int AI_CheckForMissionTargets | ( | const player_t * | player, | |
edict_t * | ent, | |||
aiAction_t * | aia | |||
) | [static] |
Searches the map for mission edicts and try to get there.
Definition at line 761 of file g_ai.c.
References AI_ACTION_NOTHING_FOUND, ai_waypointList, byte, edict_s::count, ET_MISSION, G_EdictsGetNextInUse(), G_IsCrouched, gi, edict_s::groupChain, GUETE_MISSION_OPPONENT_TARGET, GUETE_MISSION_TARGET, i, edict_s::inuse, level, edict_s::origin, level_locals_t::pathingMap, player_s::pers, edict_s::pos, qtrue, ROUTING_NOT_REACHABLE, aiAction_t::target, client_persistant_t::team, edict_s::team, TEAM_ALIEN, TEAM_CIVILIAN, aiAction_t::to, edict_s::TU, edict_s::type, VectorCopy, VectorDist, and WAYPOINT_CIV_DIST.
Referenced by AI_PrepBestAction().
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 99 of file g_ai.c.
References ACTOR_VIS_0, check, edict_s::doorState, frand(), G_ActorVis(), G_EdictsGetNextLivingActor(), G_FrustumVis(), gi, edict_s::hiding, MAX_SPOT_DIST, edict_s::origin, qfalse, qtrue, STATE_OPENED, edict_s::team, TEAM_ALIEN, TEAM_CIVILIAN, edict_s::type, and VectorDist.
Referenced by Touch_DoorTrigger().
static float AI_CivilianCalcBestAction | ( | edict_t * | ent, | |
pos3_t | to, | |||
aiAction_t * | aia | |||
) | [static] |
Calculates possible actions for a civilian.
[in] | ent | Pointer to an edict being civilian. |
[in] | to | The grid position to walk to. |
[in] | aia | Pointer to aiAction containing informations about possible action. |
Definition at line 643 of file g_ai.c.
References AI_ACTION_NOTHING_FOUND, AI_FighterCalcBestAction(), byte, check, edict_s::chr, frand(), G_ActorVis(), G_EdictSetOrigin(), G_EdictsGetNextLivingActor(), G_IsAlien, G_IsCrouched, G_IsInsane, G_IsPaniced, G_IsVisibleForTeam, gi, GUETE_CIV_LAZINESS, GUETE_CIV_RANDOM, level, edict_s::origin, level_locals_t::pathingMap, qtrue, ROUTING_NOT_REACHABLE, RUN_AWAY_DIST, aiAction_t::stop, edict_s::team, TEAM_ALIEN, TEAM_CIVILIAN, TEAM_PHALANX, character_s::teamDef, aiAction_t::to, edict_s::TU, UNIT_SIZE, VectorCopy, VectorDist, and teamDef_s::weapons.
Referenced by AI_PrepBestAction().
player_t* AI_CreatePlayer | ( | int | team | ) |
Spawn civilians and aliens.
[in] | team |
Definition at line 1209 of file g_ai.c.
References client_persistant_t::ai, ai_numactors, ai_numaliens, ai_numcivilians, G_SetTeamForPlayer(), G_SpawnAIPlayer(), game, gi, i, cvar_s::integer, player_s::inuse, player_s::num, player_s::pers, game_locals_t::players, qtrue, sv_ai, sv_maxclients, game_locals_t::sv_maxplayersperteam, client_persistant_t::team, and TEAM_CIVILIAN.
Referenced by G_SpawnEntities(), and SVCmd_AI_Add_f().
static float AI_FighterCalcBestAction | ( | edict_t * | ent, | |
pos3_t | to, | |||
aiAction_t * | aia | |||
) | [static] |
fill z_align values
optimize this
Definition at line 532 of file g_ai.c.
References AI_ACTION_NOTHING_FOUND, AI_FindHidingLocation(), AI_GetHidingTeam(), AI_GetItemForShootType(), AI_HideNeeded(), AI_SearchBestTarget(), check, CLOSE_IN_DIST, FIRESH_FiredefForWeapon(), G_EdictSetOrigin(), G_EdictsGetNextLivingActor(), G_IsCivilian, G_IsCrouched, G_IsInsane, G_IsRaged, G_TestVis(), gi, GUETE_CLOSE_IN, GUETE_HIDE, cvar_s::integer, level, edict_s::origin, level_locals_t::pathingMap, edict_s::pos, qtrue, ROUTING_NOT_REACHABLE, ST_NUM_SHOOT_TYPES, ST_RIGHT, aiAction_t::stop, sv_maxclients, aiAction_t::target, edict_s::team, aiAction_t::to, edict_s::TU, TU_MOVE_STRAIGHT, VectorCopy, VectorDist, VIS_YES, VT_NOFRUSTUM, and VT_PERISH.
Referenced by AI_CivilianCalcBestAction(), and AI_PrepBestAction().
static qboolean AI_FighterCheckShoot | ( | const edict_t * | ent, | |
const edict_t * | check, | |||
const fireDef_t * | fd, | |||
float * | dist | |||
) | [static] |
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 73 of file g_ai.c.
References AI_CheckFF(), G_IsInsane, edict_s::origin, qfalse, qtrue, fireDef_s::range, fireDef_s::spread, and VectorDist.
Referenced by AI_SearchBestTarget(), and AI_SearchDestroyableObject().
Tries to search a spot where actor will be more closer to the target and behind the target from enemy.
[in] | ent | 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 |
Definition at line 340 of file g_ai.c.
References AI_GetHidingTeam(), byte, DotProduct, G_EdictCalcOrigin(), G_EdictsGetNextLivingActorOfTeam(), G_IsCrouched, G_MoveCalcLocal(), gi, HERD_DIST, next, edict_s::origin, PATHFINDING_WIDTH, edict_s::pos, qfalse, qtrue, ROUTING_NOT_REACHABLE, VectorCompare, VectorCopy, VectorDistSqr, VectorNormalize(), and VectorSubtract.
Referenced by AIL_positionherd().
Tries to search a hiding spot.
[out] | ent | 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 NULL . |
[in] | team | The team from which actor tries to hide |
true
if hiding is possible, false
otherwise Definition at line 295 of file g_ai.c.
References byte, G_EdictCalcOrigin(), G_IsCrouched, G_MoveCalcLocal(), G_TestVis(), gi, HIDE_DIST, PATHFINDING_WIDTH, edict_s::pos, qfalse, qtrue, ROUTING_NOT_REACHABLE, VIS_YES, VT_NOFRUSTUM, and VT_PERISH.
Referenced by AI_FighterCalcBestAction(), and AIL_positionhide().
int AI_GetHidingTeam | ( | const edict_t * | 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
.
Definition at line 279 of file g_ai.c.
References G_IsCivilian, edict_s::team, and TEAM_ALIEN.
Referenced by AI_FighterCalcBestAction(), AI_FindHerdLocation(), AI_HideNeeded(), and AIL_positionhide().
const item_t* AI_GetItemForShootType | ( | shoot_types_t | shootType, | |
const edict_t * | ent | |||
) |
Returns the item of the currently chosen shoot type of the ai actor.
shootType | The current selected shoot type | |
ent | The ai actor |
NULL
if no item was found. Definition at line 250 of file g_ai.c.
References AI_GetItemFromInventory(), IS_SHOT_HEADGEAR, IS_SHOT_LEFT, IS_SHOT_REACTION, IS_SHOT_RIGHT, LEFT, and RIGHT.
Referenced by actorL_shoot(), and AI_FighterCalcBestAction().
Returns useable item from the given inventory list. That means that the 'weapon' has ammunition left or must not be reloaded.
ic | The inventory to search a useable weapon in. |
Definition at line 233 of file g_ai.c.
References item_s::a, invList_s::item, item_s::m, objDef_s::reload, item_s::t, and objDef_s::weapon.
Referenced by AI_GetItemForShootType().
Checks whether the given alien should try to hide because there are enemies close enough to shoot the alien.
[in] | ent | 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 187 of file g_ai.c.
References AI_GetHidingTeam(), crand(), fireDef_s::damage, FIRESH_FiredefForWeapon(), G_EdictsGetNextLivingActor(), G_IsCivilian, G_IsVisibleForTeam, G_Vis(), edict_s::HP, cvar_s::integer, invList_s::item, LEFT, mor_brave, edict_s::morale, edict_s::origin, qfalse, qtrue, fireDef_s::range, RIGHT, item_s::t, edict_s::team, VectorDistSqr, and VT_NOFRUSTUM.
Referenced by AI_FighterCalcBestAction().
static void AI_InitPlayer | ( | const player_t * | player, | |
edict_t * | ent, | |||
const equipDef_t * | ed | |||
) | [static] |
Initializes the actor.
[in] | player | Player to which this actor belongs. |
[in,out] | ent | Pointer to edict_t representing actor. |
[in] | ed | Equipment definition for the new actor. Might be NULL . |
Definition at line 1129 of file g_ai.c.
References AI_SetCharacterValues(), AI_SetEquipment(), AI_SetStats(), AIL_InitActor(), edict_s::body, edict_s::chr, CHRSH_CharGetBody(), CHRSH_CharGetHead(), f, frand(), G_ClientStateChange(), gi, edict_s::head, player_s::pers, qfalse, STATE_REACTION_ONCE, client_persistant_t::team, TEAM_ALIEN, and TEAM_CIVILIAN.
Referenced by G_SpawnAIPlayer().
static aiAction_t AI_PrepBestAction | ( | const player_t * | player, | |
edict_t * | ent | |||
) | [static] |
Attempts to find the best action for an alien. Moves the alien into the starting position for that action and returns the action.
[in] | player | The AI player |
[in] | ent | The AI actor |
Definition at line 827 of file g_ai.c.
References AI_ACTION_NOTHING_FOUND, AI_CheckForMissionTargets(), AI_CivilianCalcBestAction(), AI_FighterCalcBestAction(), byte, Com_DPrintf(), DEBUG_ENGINE, G_ClientMove(), G_ClientStateChange(), G_IsCivilian, G_IsCrouched, G_IsDead, G_IsPaniced, G_MoveCalc(), gi, level, oldPos, edict_s::origin, PATHFINDING_HEIGHT, PATHFINDING_WIDTH, level_locals_t::pathingMap, edict_s::pos, qtrue, ROUTING_NOT_REACHABLE, STATE_CROUCHED, aiAction_t::target, aiAction_t::to, edict_s::TU, and VectorCopy.
Referenced by AI_ActorThink().
void AI_Run | ( | void | ) |
Every server frame one single actor is handled - always in the same order.
Definition at line 1031 of file g_ai.c.
References level_locals_t::activeTeam, AI_ActorThink(), AIL_ActorThink(), level_locals_t::framenum, g_ailua, G_ClientEndRound(), G_EdictsGetNextLivingActorOfTeam(), G_IsAIPlayer, game, i, cvar_s::integer, player_s::inuse, client_persistant_t::last, level, player_s::pers, game_locals_t::players, game_locals_t::sv_maxplayersperteam, client_persistant_t::team, and edict_s::TU.
Referenced by G_RunFrame().
static void AI_SearchBestTarget | ( | aiAction_t * | aia, | |
const edict_t * | ent, | |||
edict_t * | check, | |||
const item_t * | item, | |||
shoot_types_t | shootType, | |||
int | tu, | |||
float * | maxDmg, | |||
int * | bestTime, | |||
const fireDef_t * | fdArray | |||
) | [static] |
Definition at line 441 of file g_ai.c.
References ABILITY_ACCURACY, ACTOR_VIS_0, AI_FighterCheckShoot(), AI_SearchDestroyableObject(), edict_s::chr, CONTAINER, game_import_t::csi, fireDef_s::damage, objDef_s::dmgtype, aiAction_t::fd, frand(), G_ActorVis(), G_IsCivilian, G_IsInsane, G_IsReaction, GET_ACC, gi, GUETE_CIV_FACTOR, GUETE_KILL, GUETE_RANDOM, GUETE_REACTION_ERADICATION, edict_s::HP, csi_s::idArmour, item_s::m, objDef_s::numFiredefs, edict_s::origin, objDef_s::protection, qfalse, qtrue, character_s::score, aiAction_t::shootType, aiAction_t::shots, fireDef_s::shots, chrScoreGlobal_s::skills, fireDef_s::spldmg, fireDef_s::spread, SPREAD_NORM, aiAction_t::target, fireDef_s::time, fireDef_s::weapFdsIdx, and fireDef_s::weaponSkill.
Referenced by AI_FighterCalcBestAction().
Definition at line 411 of file g_ai.c.
References ACTOR_VIS_0, AI_FighterCheckShoot(), check, G_ActorVis(), G_EdictsGetNextInUse(), G_IsBreakable, edict_s::origin, and qtrue.
Referenced by AI_SearchBestTarget().
static void AI_SetCharacterValues | ( | edict_t * | ent, | |
int | team | |||
) | [static] |
Sets an actor's character values.
ent | Actor to set the model for. | |
[in] | team | Team to which actor belongs. |
Definition at line 1085 of file g_ai.c.
References csi_s::alienTeams, edict_s::chr, game_import_t::csi, game_import_t::Cvar_String(), gi, teamDef_s::id, csi_s::numAlienTeams, TEAM_CIVILIAN, and character_s::teamDef.
Referenced by AI_InitPlayer().
static void AI_SetEquipment | ( | edict_t * | ent, | |
const equipDef_t * | ed | |||
) | [static] |
Sets the actor's equipment.
ent | Actor to give equipment to. | |
[in] | ed | Equipment definition for the new actor. |
Definition at line 1110 of file g_ai.c.
References edict_s::chr, inventoryInterface_s::EquipActor, inventoryInterface_s::EquipActorMelee, game, gi, character_s::i, game_locals_t::i, character_s::teamDef, and teamDef_s::weapons.
Referenced by AI_InitPlayer().
static void AI_SetStats | ( | edict_t * | ent | ) | [static] |
Initializes the actor's stats like morals, strength and so on.
ent | Actor to set the stats for. |
Definition at line 1068 of file g_ai.c.
References edict_s::chr, CHRSH_CharGenAbilitySkills(), G_ActorGiveTimeUnits(), character_s::HP, edict_s::HP, cvar_s::integer, character_s::morale, edict_s::morale, edict_s::STUN, and sv_maxclients.
Referenced by AI_InitPlayer().
static void AI_TryToReloadWeapon | ( | edict_t * | ent, | |
containerIndex_t | containerID | |||
) | [static] |
if a weapon can be reloaded we attempt to do so if TUs permit, otherwise drop it
Definition at line 946 of file g_ai.c.
References CONTAINER, game_import_t::csi, G_ActorInvMove(), G_ActorReload(), G_ClientCanReload(), gi, csi_s::idFloor, INVDEF, NONE, and qtrue.
Referenced by AI_ActorThink().
This function will turn the AI actor into the direction that is needed to walk to the given location.
[in] | aiActor | The actor to turn |
[in] | pos | The position to set the direction for |
Definition at line 927 of file g_ai.c.
References byte, CORE_DIRECTIONS, FLYING_DIRECTIONS, G_ActorDoTurn(), G_IsCrouched, G_MoveCalc(), getDVdir, gi, level, level_locals_t::pathingMap, ROUTING_UNREACHABLE, edict_s::team, and edict_s::TU.
Referenced by actorL_face(), AI_ActorThink(), and pos3L_face().
void G_AddToWayPointList | ( | edict_t * | ent | ) |
Definition at line 904 of file g_ai.c.
References edict_s::groupChain, and i.
Referenced by SP_civilian_target().
static void G_SpawnAIPlayer | ( | const player_t * | player, | |
int | numSpawn | |||
) | [static] |
Spawn civilians and aliens.
[in] | player | |
[in] | numSpawn |
Definition at line 1166 of file g_ai.c.
References ACTOR_SIZE_NORMAL, AI_InitPlayer(), game_import_t::csi, game_import_t::Cvar_String(), csi_s::eds, G_CheckVis(), G_ClearVisFlags(), G_ClientGetFreeSpawnPointForActorSize(), gi, i, MAX_VAR, equipDef_s::name, name, csi_s::numEDs, player_s::pers, Q_strncpyz(), qfalse, client_persistant_t::team, and TEAM_CIVILIAN.
Referenced by AI_CreatePlayer().
Definition at line 902 of file g_ai.c.
Referenced by AI_CheckForMissionTargets(), and G_SpawnEntities().