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

Artificial Intelligence. More...

#include "../shared/cxx.h"
#include "g_local.h"
#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_move.h"
#include "g_utils.h"
#include "g_vis.h"
#include <lauxlib.h>

Go to the source code of this file.

Data Structures

struct  aiActor_s
 Wrapper around edict. More...
 
struct  AilSortTable< T >
 

Macros

#define POS3_METATABLE   "pos3"
 
#define ACTOR_METATABLE   "actor"
 
#define AI_METATABLE   "ai"
 
#define luaL_dobuffer(L, b, n, s)   (luaL_loadbuffer(L, b, n, s) || lua_pcall(L, 0, LUA_MULTRET, 0))
 
#define AIL_invalidparameter(n)   gi.DPrintf("AIL: Invalid parameter #%d in '%s'.\n", n, __func__)
 

Typedefs

typedef struct aiActor_s aiActor_t
 Wrapper around edict. More...
 

Enumerations

enum  ailVisType_t { AILVT_ALL, AILVT_SIGHT, AILVT_TEAM, AILVT_DIST }
 vis check types More...
 
enum  ailSortCritType_t { AILSC_DIST, AILSC_PATH, AILSC_HP }
 target sorting criteria (lowest first) More...
 
enum  ailShootPosType_t { AILSP_FAST, AILSP_NEAR, AILSP_FAR, AILSP_DMG }
 Shooting position types. More...
 
enum  ailWanderPosType { AILPW_RAND, AILPW_CW, AILPW_CCW }
 

Functions

static const char * AIL_toTeamString (const int team)
 Converts integer team representation into string. More...
 
static int AIL_toTeamInt (const char *team, const int param)
 Converts team string into int representation. More...
 
static ailVisType_t AIL_toVisInt (lua_State *L, const int index)
 Return visibility mode int representation from the string representation in the lua stack. More...
 
static ailSortCritType_t AIL_toSortInt (lua_State *L, const int index)
 Return sort type int representation from the string representation in the lua stack. More...
 
static ailSortCritType_t AIL_toDistInt (lua_State *L, const int index)
 Return distance type int representation from the string representation in the lua stack. More...
 
static ailShootPosType_t AIL_toShotPInt (lua_State *L, const int index)
 Return shooting position type int representation from the string representation in the lua stack. More...
 
static ailWanderPosType AIL_toWanderPInt (lua_State *L, const int index)
 Return wander position type int representation from the string representation in the lua stack. More...
 
template<typename T >
bool operator< (AilSortTable< T > i, AilSortTable< T > j)
 
static float AIL_GetBestShot (const Actor &shooter, const Actor &target, const int tu, const float dist, shoot_types_t &bestType, fireDefIndex_t &bestFd, int &bestShots)
 
static int actorL_register (lua_State *L)
 Registers the actor metatable in the lua_State. More...
 
static int lua_isactor (lua_State *L, int index)
 Checks to see if there is a actor metatable at index in the lua_State. More...
 
static aiActor_tlua_toactor (lua_State *L, int index)
 Returns the actor from the metatable at index. More...
 
static aiActor_tlua_pushactor (lua_State *L, aiActor_t *actor)
 Pushes a actor as a metatable at the top of the stack. More...
 
static int actorL_tostring (lua_State *L)
 Pushes the actor as a string. More...
 
static int actorL_pos (lua_State *L)
 Gets the actors position. More...
 
static int actorL_shoot (lua_State *L)
 Shoots the actor. More...
 
static int actorL_team (lua_State *L)
 Gets the actor's team. More...
 
static int actorL_throwgrenade (lua_State *L)
 Throws a grenade to the actor. More...
 
static int actorL_TU (lua_State *L)
 Gets the number of usable TU the actor has left. More...
 
static int actorL_HP (lua_State *L)
 Gets the number of HP the actor has left. More...
 
static int actorL_morale (lua_State *L)
 Gets the current morale of the actor onto the stack. More...
 
static int actorL_isinjured (lua_State *L)
 Checks to see if the actor is seriously injured. More...
 
static int actorL_isarmed (lua_State *L)
 Check if actor has weapons. More...
 
static int actorL_isdead (lua_State *L)
 Check if the actor is dead. More...
 
static int actorL_isvalidtarget (lua_State *L)
 Check if the actor is a valid target to attack. More...
 
static int pos3L_register (lua_State *L)
 Registers the pos3 metatable in the lua_State. More...
 
static int lua_ispos3 (lua_State *L, int index)
 Checks to see if there is a pos3 metatable at index in the lua_State. More...
 
static pos3_tlua_topos3 (lua_State *L, int index)
 Returns the pos3 from the metatable at index. More...
 
static pos3_tlua_pushpos3 (lua_State *L, pos3_t *pos)
 Pushes a pos3 as a metatable at the top of the stack. More...
 
static int pos3L_tostring (lua_State *L)
 Puts the pos3 information in a string. More...
 
static int pos3L_goto (lua_State *L)
 Makes the actor head to the position. More...
 
static int pos3L_face (lua_State *L)
 Makes the actor face the position. More...
 
static int pos3L_distance (lua_State *L)
 Return the distance the position an the AI actor. More...
 
static int AIL_print (lua_State *L)
 Works more or less like Lua's builtin print. More...
 
static int AIL_squad (lua_State *L)
 Returns a table with the actors in the current player's team. More...
 
static int AIL_select (lua_State *L)
 Select an specific AI actor. More...
 
static int AIL_see (lua_State *L)
 Returns what the actor can see. More...
 
static int AIL_crouch (lua_State *L)
 Requests a crouch state (with true/false) and returns current crouch state. More...
 
static int AIL_reactionfire (lua_State *L)
 Sets the actor's reaction fire mode. More...
 
static int AIL_roundsleft (lua_State *L)
 Checks to see how many rounds the actor has left. More...
 
static int AIL_canreload (lua_State *L)
 Checks to see if the actor can reload. More...
 
static int AIL_reload (lua_State *L)
 Actor reloads his weapons. More...
 
static int AIL_positionshoot (lua_State *L)
 Moves the actor into a position in which he can shoot his target. More...
 
static int AIL_positionhide (lua_State *L)
 Moves the actor into a position in which he can hide. More...
 
static int AIL_positionherd (lua_State *L)
 Determine the position where actor is closest to the target and with the target located between the actor and the nemy enemy. More...
 
static int AIL_positionapproach (lua_State *L)
 Approach to a target actor. More...
 
static int AIL_grabweapon (lua_State *L)
 Actor tries to grab a weapon from inventory. More...
 
static int AIL_missiontargets (lua_State *L)
 Returns the positions of the available mission targets. More...
 
static int AIL_waypoints (lua_State *L)
 Return the positions of the next waypoints. More...
 
static int AIL_positionmission (lua_State *L)
 Try to find a position nearby to the given position. More...
 
static int AIL_positionwander (lua_State *L)
 Return a new position to move to. More...
 
static int AIL_findweapons (lua_State *L)
 Returns a table of the positions of nearby usable weapons on the floor. More...
 
static int AIL_isfighter (lua_State *L)
 Whether the current AI actor is a fighter or not. More...
 
static int AIL_setwaypoint (lua_State *L)
 Mark the current waypoint for a civ. More...
 
static int AIL_difficulty (lua_State *L)
 Return the difficulty number (in case we want different AI for different ones) More...
 
static int AIL_positionflee (lua_State *L)
 Return a position to flee to. More...
 
static int AIL_weapontype (lua_State *L)
 Returns the type of the weapons in the actors hands. More...
 
static int AIL_actor (lua_State *L)
 Returns the currently moving AI actor. More...
 
static int AIL_tusforshooting (lua_State *L)
 Returns the min TUs the actor needs to fire. More...
 
static int AIL_class (lua_State *L)
 Returns the AI actor's class. More...
 
static int AIL_hideneeded (lua_State *L)
 Check if the actor needs wants to hide. More...
 
void AIL_ActorThink (Player &player, Actor *actor)
 The think function for the ai controlled players. More...
 
static const char * AIL_GetAIType (const int team)
 Return the AI type for the given team (the lua file the team actors should run) More...
 
bool AIL_TeamThink (Player &player)
 The team think function for the ai controlled players. More...
 
static lua_State * AIL_InitLua ()
 
int AIL_InitActor (Actor *actor)
 Initializes the lua AI for an actor. More...
 
void AIL_Init (void)
 
void AIL_Shutdown (void)
 
void AIL_Cleanup (void)
 Closes the LUA AI. More...
 

Variables

static lua_State * ailState
 
static ActorAIL_ent
 
static Player * AIL_player
 
static const luaL_reg actorL_methods []
 
static const luaL_reg pos3L_methods []
 
static const luaL_reg AIL_methods []
 

Detailed Description

Artificial Intelligence.

You can find the reference lua manual at http://www.lua.org/manual/5.1/
-1 and -2 are pseudo indexes, they count backwards:
  • -1 is top
  • 1 is bottom
  • -2 is under the top
  • etc...

Definition in file g_ai_lua.cpp.

Macro Definition Documentation

#define ACTOR_METATABLE   "actor"

Actor Lua Metable name.

Definition at line 52 of file g_ai_lua.cpp.

Referenced by actorL_register(), lua_isactor(), lua_pushactor(), and lua_toactor().

#define AI_METATABLE   "ai"

AI Lua Metable name.

Definition at line 53 of file g_ai_lua.cpp.

Referenced by AIL_InitLua().

#define luaL_dobuffer (   L,
  b,
  n,
 
)    (luaL_loadbuffer(L, b, n, s) || lua_pcall(L, 0, LUA_MULTRET, 0))

Provides an api like luaL_dostring for buffers.

Definition at line 59 of file g_ai_lua.cpp.

Referenced by AIL_InitActor().

#define POS3_METATABLE   "pos3"

Pos3 Lua Metatable name.

Definition at line 51 of file g_ai_lua.cpp.

Referenced by lua_ispos3(), lua_pushpos3(), lua_topos3(), and pos3L_register().

Typedef Documentation

typedef struct aiActor_s aiActor_t

Wrapper around edict.

Enumeration Type Documentation

Shooting position types.

Enumerator
AILSP_FAST 
AILSP_NEAR 
AILSP_FAR 
AILSP_DMG 

Definition at line 80 of file g_ai_lua.cpp.

target sorting criteria (lowest first)

Enumerator
AILSC_DIST 
AILSC_PATH 
AILSC_HP 

Definition at line 73 of file g_ai_lua.cpp.

vis check types

Enumerator
AILVT_ALL 
AILVT_SIGHT 
AILVT_TEAM 
AILVT_DIST 

Definition at line 65 of file g_ai_lua.cpp.

Enumerator
AILPW_RAND 
AILPW_CW 
AILPW_CCW 

Definition at line 87 of file g_ai_lua.cpp.

Function Documentation

static int actorL_HP ( lua_State *  L)
static

Gets the number of HP the actor has left.

Definition at line 715 of file g_ai_lua.cpp.

References aiActor_s::actor, AIL_invalidparameter, Edict::HP, lua_isactor(), and lua_toactor().

static int actorL_isarmed ( lua_State *  L)
static

Check if actor has weapons.

Definition at line 780 of file g_ai_lua.cpp.

References aiActor_s::actor, AIL_invalidparameter, Edict::getLeftHandItem(), Edict::getRightHandItem(), lua_isactor(), and lua_toactor().

static int actorL_isdead ( lua_State *  L)
static

Check if the actor is dead.

Definition at line 799 of file g_ai_lua.cpp.

References aiActor_s::actor, AIL_invalidparameter, Actor::isDead(), lua_isactor(), and lua_toactor().

static int actorL_isinjured ( lua_State *  L)
static

Checks to see if the actor is seriously injured.

Definition at line 761 of file g_ai_lua.cpp.

References aiActor_s::actor, AIL_invalidparameter, Edict::chr, G_IsActorWounded(), Edict::HP, lua_isactor(), lua_toactor(), and character_s::maxHP.

static int actorL_isvalidtarget ( lua_State *  L)
static

Check if the actor is a valid target to attack.

Definition at line 817 of file g_ai_lua.cpp.

References aiActor_s::actor, AI_IsHostile(), lua_isactor(), and lua_toactor().

static int actorL_morale ( lua_State *  L)
static

Gets the current morale of the actor onto the stack.

Definition at line 733 of file g_ai_lua.cpp.

References aiActor_s::actor, AIL_invalidparameter, Actor::getMorale(), cvar_s::integer, Actor::isInsane(), Actor::isPanicked(), Actor::isRaged(), lua_isactor(), lua_toactor(), and mor_brave.

static int actorL_pos ( lua_State *  L)
static

Gets the actors position.

Definition at line 511 of file g_ai_lua.cpp.

References aiActor_s::actor, lua_isactor(), lua_pushpos3(), lua_toactor(), and Edict::pos.

static int actorL_register ( lua_State *  L)
static

Registers the actor metatable in the lua_State.

A C T O R L

Parameters
[in,out]LState to register the metatable in.
Returns
0 on success.

Definition at line 430 of file g_ai_lua.cpp.

References ACTOR_METATABLE, and actorL_methods.

Referenced by AIL_InitLua().

static int actorL_shoot ( lua_State *  L)
static
static int actorL_team ( lua_State *  L)
static

Gets the actor's team.

Definition at line 566 of file g_ai_lua.cpp.

References aiActor_s::actor, AIL_toTeamString(), Edict::getTeam(), lua_isactor(), and lua_toactor().

static int actorL_tostring ( lua_State *  L)
static

Pushes the actor as a string.

Definition at line 495 of file g_ai_lua.cpp.

References aiActor_s::actor, Edict::chr, Com_sprintf(), lua_isactor(), lua_toactor(), MAX_VAR, and character_s::name.

static int actorL_TU ( lua_State *  L)
static

Gets the number of usable TU the actor has left.

Definition at line 697 of file g_ai_lua.cpp.

References aiActor_s::actor, AIL_invalidparameter, Actor::getUsableTUs(), lua_isactor(), and lua_toactor().

static int AIL_actor ( lua_State *  L)
static

Returns the currently moving AI actor.

Definition at line 2053 of file g_ai_lua.cpp.

References lua_pushactor().

void AIL_ActorThink ( Player &  player,
Actor actor 
)

The think function for the ai controlled players.

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

static int AIL_canreload ( lua_State *  L)
static

Checks to see if the actor can reload.

Definition at line 1257 of file g_ai_lua.cpp.

References CID_LEFT, CID_RIGHT, and G_ClientCanReload().

static int AIL_class ( lua_State *  L)
static

Returns the AI actor's class.

Definition at line 2088 of file g_ai_lua.cpp.

References Edict::AI, and AI_s::subtype.

void AIL_Cleanup ( void  )

Closes the LUA AI.

Definition at line 2308 of file g_ai_lua.cpp.

References ailState.

Referenced by G_MatchDoEnd().

static int AIL_crouch ( lua_State *  L)
static

Requests a crouch state (with true/false) and returns current crouch state.

Definition at line 1191 of file g_ai_lua.cpp.

References AIL_invalidparameter, AIL_player, G_ClientStateChange(), Actor::isCrouched(), and STATE_CROUCHED.

static int AIL_difficulty ( lua_State *  L)
static

Return the difficulty number (in case we want different AI for different ones)

Definition at line 1969 of file g_ai_lua.cpp.

References g_difficulty, and cvar_s::value.

static int AIL_findweapons ( lua_State *  L)
static

Returns a table of the positions of nearby usable weapons on the floor.

Todo:
Check if can reload the weapon with carried ammo or from the floor itself?

Definition at line 1886 of file g_ai_lua.cpp.

References AI_CheckPosition(), AIL_invalidparameter, CID_FLOOR, CID_RIGHT, AilSortTable< T >::data, ET_ITEM, G_ActorMoveLength(), G_EdictsGetNextInUse(), G_FindPath(), Edict::getFloor(), Item::getNext(), i, INVDEF, Actor::isCrouched(), level, lua_pushpos3(), MAX_EDICTS, level_locals_s::pathingMap, Edict::pos, ROUTING_NOT_REACHABLE, AilSortTable< T >::sortLookup, and Edict::type.

static const char* AIL_GetAIType ( const int  team)
static

Return the AI type for the given team (the lua file the team actors should run)

Definition at line 2134 of file g_ai_lua.cpp.

References TEAM_ALIEN, TEAM_CIVILIAN, TEAM_PHALANX, and type.

Referenced by AIL_InitActor(), and AIL_TeamThink().

static float AIL_GetBestShot ( const Actor shooter,
const Actor target,
const int  tu,
const float  dist,
shoot_types_t bestType,
fireDefIndex_t bestFd,
int bestShots 
)
static
static int AIL_grabweapon ( lua_State *  L)
static

Actor tries to grab a weapon from inventory.

Definition at line 1296 of file g_ai_lua.cpp.

References G_ClientGetWeaponFromInventory().

static int AIL_hideneeded ( lua_State *  L)
static

Check if the actor needs wants to hide.

Definition at line 2097 of file g_ai_lua.cpp.

References AI_HideNeeded().

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

static lua_State* AIL_InitLua ( )
static

Initializes a new ai lua state.

Definition at line 2185 of file g_ai_lua.cpp.

References actorL_register(), AI_METATABLE, AIL_methods, and pos3L_register().

Referenced by AIL_InitActor().

static int AIL_isfighter ( lua_State *  L)
static

Whether the current AI actor is a fighter or not.

Definition at line 1935 of file g_ai_lua.cpp.

References Edict::chr, teamDef_s::onlyWeapon, character_s::teamDef, and teamDef_s::weapons.

static int AIL_positionherd ( lua_State *  L)
static

Determine the position where actor is closest to the target and with the target located between the actor and the nemy enemy.

Note
target (parameter is passed through the lua stack) The actor to which AI tries to become closer
inverse (passed through the lua stack) Try to shield the target instead of using it as shield

Definition at line 1489 of file g_ai_lua.cpp.

References aiActor_s::actor, AI_FindHerdLocation(), AIL_invalidparameter, Actor::getUsableTUs(), lua_isactor(), lua_pushpos3(), lua_toactor(), Edict::origin, Edict::pos, Edict::setOrigin(), and VectorCopy.

static int AIL_positionhide ( lua_State *  L)
static

Moves the actor into a position in which he can hide.

Note
team (parameter is passed through the lua stack) means that the AI tries to find a hide position from the team members, if parameter is empty - from any enemy

Definition at line 1433 of file g_ai_lua.cpp.

References AI_FindHidingLocation(), AI_GetHidingTeam(), AIL_invalidparameter, AIL_toTeamInt(), Actor::getUsableTUs(), lua_pushpos3(), Edict::pos, Edict::setOrigin(), TEAM_ALL, and VectorCopy.

static int AIL_positionmission ( lua_State *  L)
static

Try to find a position nearby to the given position.

Note
Intended to make aliens defend mission targets

Definition at line 1761 of file g_ai_lua.cpp.

References AI_FindMissionLocation(), AIL_invalidparameter, ET_MISSION, G_GetEdictFromPos(), G_MoveCalc(), Actor::getUsableTUs(), gi, level, lua_ispos3(), lua_pushpos3(), lua_topos3(), oldPos, level_locals_s::pathingMap, Edict::pos, Edict::radius, Edict::setOrigin(), and VectorCopy.

static int AIL_print ( lua_State *  L)
static

Works more or less like Lua's builtin print.

General AI bindings.

A I L

Definition at line 1000 of file g_ai_lua.cpp.

References gi, and i.

static int AIL_reactionfire ( lua_State *  L)
static

Sets the actor's reaction fire mode.

Definition at line 1210 of file g_ai_lua.cpp.

References AIL_invalidparameter, AIL_player, G_ClientStateChange(), Actor::isReaction(), Q_streq, and STATE_REACTION.

static int AIL_reload ( lua_State *  L)
static

Actor reloads his weapons.

Definition at line 1267 of file g_ai_lua.cpp.

References AI_TryToReloadWeapon(), AIL_invalidparameter, CID_LEFT, CID_RIGHT, and Q_streq.

static int AIL_roundsleft ( lua_State *  L)
static

Checks to see how many rounds the actor has left.

Definition at line 1235 of file g_ai_lua.cpp.

References objDef_s::ammo, Item::def(), Item::getAmmoLeft(), Edict::getLeftHandItem(), and Edict::getRightHandItem().

static int AIL_select ( lua_State *  L)
static

Select an specific AI actor.

Definition at line 1075 of file g_ai_lua.cpp.

References aiActor_s::actor, AIL_invalidparameter, AIL_player, g_ailua, Edict::getPlayerNum(), gi, cvar_s::integer, lua_isactor(), and lua_toactor().

static int AIL_setwaypoint ( lua_State *  L)
static

Mark the current waypoint for a civ.

Todo:
A better way to handle waypoints

Definition at line 1945 of file g_ai_lua.cpp.

References Edict::count, ET_CIVILIANTARGET, G_GetEdictFromPos(), and lua_ispos3().

void AIL_Shutdown ( void  )

Definition at line 2276 of file g_ai_lua.cpp.

References gi.

Referenced by G_Shutdown().

static int AIL_squad ( lua_State *  L)
static

Returns a table with the actors in the current player's team.

Definition at line 1047 of file g_ai_lua.cpp.

References aiActor_s::actor, AIL_player, g_ailua, G_EdictsGetNextActor(), Edict::getPlayerNum(), gi, i, cvar_s::integer, and lua_pushactor().

bool AIL_TeamThink ( Player &  player)

The team think function for the ai controlled players.

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

static ailSortCritType_t AIL_toDistInt ( lua_State *  L,
const int  index 
)
static

Return distance type int representation from the string representation in the lua stack.

Parameters
LThe lua state to use
indexIndex on the lua stack where the string representation is stored
Returns
The integer representation of the distance type

Definition at line 167 of file g_ai_lua.cpp.

References AIL_invalidparameter, AILSC_DIST, and gi.

Referenced by AIL_missiontargets(), AIL_waypoints(), and pos3L_distance().

static ailShootPosType_t AIL_toShotPInt ( lua_State *  L,
const int  index 
)
static

Return shooting position type int representation from the string representation in the lua stack.

Parameters
LThe lua state to use
indexIndex on the lua stack where the string representation is stored
Returns
The integer representation of the shooting position type

Definition at line 185 of file g_ai_lua.cpp.

References AIL_invalidparameter, AILSP_FAST, and gi.

Referenced by AIL_positionshoot().

static ailSortCritType_t AIL_toSortInt ( lua_State *  L,
const int  index 
)
static

Return sort type int representation from the string representation in the lua stack.

Parameters
LThe lua state to use
indexIndex on the lua stack where the string representation is stored
Returns
The integer representation of the sort type

Definition at line 149 of file g_ai_lua.cpp.

References AIL_invalidparameter, AILSC_DIST, and gi.

Referenced by AIL_see().

static int AIL_toTeamInt ( const char *  team,
const int  param 
)
static

Converts team string into int representation.

Parameters
teamThe team to convert (alien, phalanx, civilian, ...)
paramparameter index for the Lua error message
Returns
The integer representation of the given team string
See also
AIL_Init

Definition at line 117 of file g_ai_lua.cpp.

References AIL_invalidparameter, gi, and TEAM_DEFAULT.

Referenced by AIL_missiontargets(), AIL_positionhide(), and AIL_see().

static const char* AIL_toTeamString ( const int  team)
static

Converts integer team representation into string.

Parameters
teamThe team to convert to the string representation
Returns
The team string
See also
AIL_Init

Definition at line 102 of file g_ai_lua.cpp.

References AIL_invalidparameter, game_import_s::GetConstVariable(), and gi.

Referenced by actorL_team(), and AIL_TeamThink().

static ailVisType_t AIL_toVisInt ( lua_State *  L,
const int  index 
)
static

Return visibility mode int representation from the string representation in the lua stack.

Parameters
LThe lua state to use
indexIndex on the lua stack where the string representation is stored
Returns
The integer representation of the visibility mode

Definition at line 131 of file g_ai_lua.cpp.

References AIL_invalidparameter, AILVT_ALL, and gi.

Referenced by AIL_missiontargets(), and AIL_see().

static ailWanderPosType AIL_toWanderPInt ( lua_State *  L,
const int  index 
)
static

Return wander position type int representation from the string representation in the lua stack.

Parameters
LThe lua state to use
indexIndex on the lua stack where the string representation is stored
Returns
The integer representation of the wander position type

Definition at line 203 of file g_ai_lua.cpp.

References AIL_invalidparameter, AILPW_RAND, and gi.

Referenced by AIL_positionwander().

static int AIL_tusforshooting ( lua_State *  L)
static

Returns the min TUs the actor needs to fire.

Definition at line 2062 of file g_ai_lua.cpp.

References Item::getFastestFireDef(), Edict::getLeftHandItem(), Edict::getRightHandItem(), and fireDef_s::time.

static int AIL_weapontype ( lua_State *  L)
static

Returns the type of the weapons in the actors hands.

Definition at line 2039 of file g_ai_lua.cpp.

References Item::def(), Edict::getLeftHandItem(), Edict::getRightHandItem(), and objDef_s::type.

static int lua_isactor ( lua_State *  L,
int  index 
)
static

Checks to see if there is a actor metatable at index in the lua_State.

Parameters
[in,out]LLua state to check.
[in]indexIndex to check for a actor metatable.
Returns
1 if index has a actor metatable otherwise returns 0.

Definition at line 454 of file g_ai_lua.cpp.

References ACTOR_METATABLE.

Referenced by actorL_HP(), actorL_isarmed(), actorL_isdead(), actorL_isinjured(), actorL_isvalidtarget(), actorL_morale(), actorL_pos(), actorL_shoot(), actorL_team(), actorL_throwgrenade(), actorL_tostring(), actorL_TU(), AIL_positionherd(), AIL_positionshoot(), AIL_select(), and lua_toactor().

static int lua_ispos3 ( lua_State *  L,
int  index 
)
static

Checks to see if there is a pos3 metatable at index in the lua_State.

Parameters
[in]LLua state to check.
[in]indexIndex to check for a pos3 metatable.
Returns
1 if index has a pos3 metatable otherwise returns 0.

Definition at line 861 of file g_ai_lua.cpp.

References POS3_METATABLE.

Referenced by AIL_positionapproach(), AIL_positionmission(), AIL_positionwander(), AIL_setwaypoint(), lua_topos3(), pos3L_distance(), pos3L_face(), pos3L_goto(), and pos3L_tostring().

static aiActor_t * lua_pushactor ( lua_State *  L,
aiActor_t actor 
)
static

Pushes a actor as a metatable at the top of the stack.

Definition at line 483 of file g_ai_lua.cpp.

References ACTOR_METATABLE.

Referenced by AIL_actor(), AIL_see(), and AIL_squad().

static pos3_t * lua_pushpos3 ( lua_State *  L,
pos3_t pos 
)
static
static aiActor_t * lua_toactor ( lua_State *  L,
int  index 
)
static
static pos3_t * lua_topos3 ( lua_State *  L,
int  index 
)
static

Returns the pos3 from the metatable at index.

Definition at line 878 of file g_ai_lua.cpp.

References lua_ispos3(), and POS3_METATABLE.

Referenced by AIL_positionapproach(), AIL_positionmission(), AIL_positionwander(), pos3L_distance(), pos3L_face(), pos3L_goto(), and pos3L_tostring().

template<typename T >
bool operator< ( AilSortTable< T >  i,
AilSortTable< T >  j 
)

Definition at line 231 of file g_ai_lua.cpp.

References i.

static int pos3L_distance ( lua_State *  L)
static
static int pos3L_face ( lua_State *  L)
static

Makes the actor face the position.

Definition at line 947 of file g_ai_lua.cpp.

References AI_TurnIntoDirection(), lua_ispos3(), and lua_topos3().

static int pos3L_goto ( lua_State *  L)
static
static int pos3L_register ( lua_State *  L)
static

Registers the pos3 metatable in the lua_State.

pos3 metatable.

P O S 3 L

Parameters
[in]LState to register the metatable in.
Returns
0 on success.

Definition at line 837 of file g_ai_lua.cpp.

References POS3_METATABLE, and pos3L_methods.

Referenced by AIL_InitLua().

static int pos3L_tostring ( lua_State *  L)
static

Puts the pos3 information in a string.

Definition at line 902 of file g_ai_lua.cpp.

References Com_sprintf(), lua_ispos3(), lua_topos3(), and MAX_VAR.

Variable Documentation

const luaL_reg actorL_methods[]
static
Initial value:
= {
{"__tostring", actorL_tostring},
{"pos", actorL_pos},
{"shoot", actorL_shoot},
{"team", actorL_team},
{"throwgrenade", actorL_throwgrenade},
{"TU", actorL_TU},
{"HP", actorL_HP},
{"morale", actorL_morale},
{"isinjured", actorL_isinjured},
{"isarmed", actorL_isarmed},
{"isdead", actorL_isdead},
{"isvalidtarget", actorL_isvalidtarget},
{nullptr, nullptr}
}
static int actorL_team(lua_State *L)
Gets the actor's team.
Definition: g_ai_lua.cpp:566
static int actorL_tostring(lua_State *L)
Pushes the actor as a string.
Definition: g_ai_lua.cpp:495
static int actorL_shoot(lua_State *L)
Shoots the actor.
Definition: g_ai_lua.cpp:523
static int actorL_isvalidtarget(lua_State *L)
Check if the actor is a valid target to attack.
Definition: g_ai_lua.cpp:817
static int actorL_morale(lua_State *L)
Gets the current morale of the actor onto the stack.
Definition: g_ai_lua.cpp:733
static int actorL_TU(lua_State *L)
Gets the number of usable TU the actor has left.
Definition: g_ai_lua.cpp:697
static int actorL_HP(lua_State *L)
Gets the number of HP the actor has left.
Definition: g_ai_lua.cpp:715
static int actorL_pos(lua_State *L)
Gets the actors position.
Definition: g_ai_lua.cpp:511
static int actorL_isarmed(lua_State *L)
Check if actor has weapons.
Definition: g_ai_lua.cpp:780
static int actorL_isinjured(lua_State *L)
Checks to see if the actor is seriously injured.
Definition: g_ai_lua.cpp:761
static int actorL_throwgrenade(lua_State *L)
Throws a grenade to the actor.
Definition: g_ai_lua.cpp:580
static int actorL_isdead(lua_State *L)
Check if the actor is dead.
Definition: g_ai_lua.cpp:799

Lua Actor metatable methods. http://www.lua.org/manual/5.1/manual.html#lua_CFunction

Definition at line 312 of file g_ai_lua.cpp.

Referenced by actorL_register().

Actor* AIL_ent
static

Actor currently running the Lua AI.

Definition at line 238 of file g_ai_lua.cpp.

Referenced by AIL_positionshoot(), and AIL_see().

const luaL_reg AIL_methods[]
static

Lua AI module methods. http://www.lua.org/manual/5.1/manual.html#lua_CFunction

Definition at line 388 of file g_ai_lua.cpp.

Referenced by AIL_InitLua().

Player* AIL_player
static

Player currently running the Lua AI.

Definition at line 239 of file g_ai_lua.cpp.

Referenced by actorL_shoot(), actorL_throwgrenade(), AIL_ActorThink(), AIL_crouch(), AIL_reactionfire(), AIL_select(), AIL_squad(), AIL_TeamThink(), and pos3L_goto().

lua_State* ailState
static

Definition at line 55 of file g_ai_lua.cpp.

Referenced by AIL_ActorThink(), AIL_Cleanup(), AIL_Init(), AIL_InitActor(), and AIL_TeamThink().

const luaL_reg pos3L_methods[]
static
Initial value:
= {
{"__tostring", pos3L_tostring},
{"goto", pos3L_goto},
{"face", pos3L_face},
{"distance", pos3L_distance},
{nullptr, nullptr}
}
static int pos3L_face(lua_State *L)
Makes the actor face the position.
Definition: g_ai_lua.cpp:947
static int pos3L_distance(lua_State *L)
Return the distance the position an the AI actor.
Definition: g_ai_lua.cpp:961
static int pos3L_goto(lua_State *L)
Makes the actor head to the position.
Definition: g_ai_lua.cpp:918
static int pos3L_tostring(lua_State *L)
Puts the pos3 information in a string.
Definition: g_ai_lua.cpp:902

Lua Pos3 metatable methods. http://www.lua.org/manual/5.1/manual.html#lua_CFunction

Definition at line 344 of file g_ai_lua.cpp.

Referenced by pos3L_register().