UFO: Alien Invasion
Loading...
Searching...
No Matches
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>
Include dependency graph for g_ai_lua.cpp:

Go to the source code of this file.

Data Structures

struct  aiActor_t
 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)
#define AIL_invalidparameter(n)

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

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/
-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

◆ ACTOR_METATABLE

#define ACTOR_METATABLE   "actor"

Actor Lua Metable name.

Definition at line 60 of file g_ai_lua.cpp.

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

◆ AI_METATABLE

#define AI_METATABLE   "ai"

AI Lua Metable name.

Definition at line 61 of file g_ai_lua.cpp.

Referenced by AIL_InitLua().

◆ AIL_invalidparameter

◆ luaL_dobuffer

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

Provides an api like luaL_dostring for buffers.

Definition at line 67 of file g_ai_lua.cpp.

Referenced by AIL_InitActor().

◆ POS3_METATABLE

#define POS3_METATABLE   "pos3"

Pos3 Lua Metatable name.

Definition at line 59 of file g_ai_lua.cpp.

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

Enumeration Type Documentation

◆ ailShootPosType_t

Shooting position types.

Enumerator
AILSP_FAST 
AILSP_NEAR 
AILSP_FAR 
AILSP_DMG 

Definition at line 88 of file g_ai_lua.cpp.

◆ ailSortCritType_t

target sorting criteria (lowest first)

Enumerator
AILSC_DIST 
AILSC_PATH 
AILSC_HP 

Definition at line 81 of file g_ai_lua.cpp.

◆ ailVisType_t

vis check types

Enumerator
AILVT_ALL 
AILVT_SIGHT 
AILVT_TEAM 
AILVT_DIST 

Definition at line 73 of file g_ai_lua.cpp.

◆ ailWanderPosType

Enumerator
AILPW_RAND 
AILPW_CW 
AILPW_CCW 

Definition at line 95 of file g_ai_lua.cpp.

Function Documentation

◆ actorL_HP()

int actorL_HP ( lua_State * L)
static

Gets the number of HP the actor has left.

Definition at line 725 of file g_ai_lua.cpp.

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

◆ actorL_isarmed()

int actorL_isarmed ( lua_State * L)
static

Check if actor has weapons.

Definition at line 790 of file g_ai_lua.cpp.

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

◆ actorL_isdead()

int actorL_isdead ( lua_State * L)
static

Check if the actor is dead.

Definition at line 809 of file g_ai_lua.cpp.

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

◆ actorL_isinjured()

int actorL_isinjured ( lua_State * L)
static

Checks to see if the actor is seriously injured.

Definition at line 771 of file g_ai_lua.cpp.

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

◆ actorL_isvalidtarget()

int actorL_isvalidtarget ( lua_State * L)
static

Check if the actor is a valid target to attack.

Definition at line 827 of file g_ai_lua.cpp.

References aiActor_t::actor, AI_IsHostile(), AIL_ent, lua_isactor(), and lua_toactor().

◆ actorL_morale()

int actorL_morale ( lua_State * L)
static

Gets the current morale of the actor onto the stack.

Definition at line 743 of file g_ai_lua.cpp.

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

◆ actorL_pos()

int actorL_pos ( lua_State * L)
static

Gets the actors position.

Definition at line 521 of file g_ai_lua.cpp.

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

◆ actorL_register()

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 440 of file g_ai_lua.cpp.

References ACTOR_METATABLE, and actorL_methods.

Referenced by AIL_InitLua().

◆ actorL_shoot()

int actorL_shoot ( lua_State * L)
static

◆ actorL_team()

int actorL_team ( lua_State * L)
static

Gets the actor's team.

Definition at line 576 of file g_ai_lua.cpp.

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

◆ actorL_throwgrenade()

◆ actorL_tostring()

int actorL_tostring ( lua_State * L)
static

Pushes the actor as a string.

Definition at line 505 of file g_ai_lua.cpp.

References aiActor_t::actor, Edict::chr, Com_sprintf(), lua_isactor(), lua_toactor(), MAX_VAR, and character_t::name.

◆ actorL_TU()

int actorL_TU ( lua_State * L)
static

Gets the number of usable TU the actor has left.

Definition at line 707 of file g_ai_lua.cpp.

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

◆ AIL_actor()

int AIL_actor ( lua_State * L)
static

Returns the currently moving AI actor.

Definition at line 2063 of file g_ai_lua.cpp.

References AIL_ent, and lua_pushactor().

◆ 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_canreload()

int AIL_canreload ( lua_State * L)
static

Checks to see if the actor can reload.

Definition at line 1267 of file g_ai_lua.cpp.

References AIL_ent, CID_LEFT, CID_RIGHT, and G_ClientCanReload().

◆ AIL_class()

int AIL_class ( lua_State * L)
static

Returns the AI actor's class.

Definition at line 2098 of file g_ai_lua.cpp.

References AIL_ent.

◆ 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_crouch()

int AIL_crouch ( lua_State * L)
static

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

Definition at line 1201 of file g_ai_lua.cpp.

References AIL_ent, AIL_invalidparameter, AIL_player, G_ClientStateChange(), and STATE_CROUCHED.

◆ AIL_difficulty()

int AIL_difficulty ( lua_State * L)
static

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

Definition at line 1979 of file g_ai_lua.cpp.

References g_difficulty.

◆ AIL_findweapons()

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 1896 of file g_ai_lua.cpp.

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

◆ AIL_GetAIType()

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 2144 of file g_ai_lua.cpp.

References TEAM_ALIEN, TEAM_CIVILIAN, TEAM_PHALANX, and type.

Referenced by AIL_InitActor(), and AIL_TeamThink().

◆ AIL_GetBestShot()

◆ AIL_grabweapon()

int AIL_grabweapon ( lua_State * L)
static

Actor tries to grab a weapon from inventory.

Definition at line 1306 of file g_ai_lua.cpp.

References AIL_ent, and G_ClientGetWeaponFromInventory().

◆ AIL_hideneeded()

int AIL_hideneeded ( lua_State * L)
static

Check if the actor needs wants to hide.

Definition at line 2107 of file g_ai_lua.cpp.

References AI_HideNeeded(), and AIL_ent.

◆ 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_InitLua()

lua_State * AIL_InitLua ( )
static

Initializes a new ai lua state.

Definition at line 2195 of file g_ai_lua.cpp.

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

Referenced by AIL_InitActor().

◆ AIL_isfighter()

int AIL_isfighter ( lua_State * L)
static

Whether the current AI actor is a fighter or not.

Definition at line 1945 of file g_ai_lua.cpp.

References AIL_ent.

◆ AIL_missiontargets()

◆ AIL_positionapproach()

◆ AIL_positionflee()

◆ AIL_positionherd()

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 1499 of file g_ai_lua.cpp.

References aiActor_t::actor, AI_FindHerdLocation(), AIL_ent, AIL_invalidparameter, lua_isactor(), lua_pushpos3(), lua_toactor(), Edict::origin, and VectorCopy.

◆ AIL_positionhide()

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 1443 of file g_ai_lua.cpp.

References AI_FindHidingLocation(), AI_GetHidingTeam(), AIL_ent, AIL_invalidparameter, AIL_toTeamInt(), lua_pushpos3(), TEAM_ALL, and VectorCopy.

◆ AIL_positionmission()

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 1771 of file g_ai_lua.cpp.

References AI_FindMissionLocation(), AIL_ent, AIL_invalidparameter, ET_MISSION, G_GetEdictFromPos(), G_MoveCalc(), gi, level, lua_ispos3(), lua_pushpos3(), lua_topos3(), oldPos, Edict::radius, and VectorCopy.

◆ AIL_positionshoot()

◆ AIL_positionwander()

◆ AIL_print()

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 1010 of file g_ai_lua.cpp.

References gi, and i.

◆ AIL_reactionfire()

int AIL_reactionfire ( lua_State * L)
static

Sets the actor's reaction fire mode.

Definition at line 1220 of file g_ai_lua.cpp.

References AIL_ent, AIL_invalidparameter, AIL_player, G_ClientStateChange(), Q_streq, and STATE_REACTION.

◆ AIL_reload()

int AIL_reload ( lua_State * L)
static

Actor reloads his weapons.

Definition at line 1277 of file g_ai_lua.cpp.

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

◆ AIL_roundsleft()

int AIL_roundsleft ( lua_State * L)
static

Checks to see how many rounds the actor has left.

Definition at line 1245 of file g_ai_lua.cpp.

References AIL_ent, objDef_t::ammo, Item::def(), and Item::getAmmoLeft().

◆ AIL_see()

◆ AIL_select()

int AIL_select ( lua_State * L)
static

Select an specific AI actor.

Definition at line 1085 of file g_ai_lua.cpp.

References aiActor_t::actor, AIL_ent, AIL_invalidparameter, AIL_player, g_ailua, Edict::getPlayerNum(), gi, lua_isactor(), and lua_toactor().

◆ AIL_setwaypoint()

int AIL_setwaypoint ( lua_State * L)
static

Mark the current waypoint for a civ.

Todo
A better way to handle waypoints

Definition at line 1955 of file g_ai_lua.cpp.

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

◆ AIL_Shutdown()

void AIL_Shutdown ( void )

Definition at line 2289 of file g_ai_lua.cpp.

References gi.

Referenced by G_Shutdown().

◆ AIL_squad()

int AIL_squad ( lua_State * L)
static

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

Definition at line 1057 of file g_ai_lua.cpp.

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

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

◆ AIL_toDistInt()

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 175 of file g_ai_lua.cpp.

References AIL_invalidparameter, AILSC_DIST, gi, and index.

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

◆ AIL_toShotPInt()

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 193 of file g_ai_lua.cpp.

References AIL_invalidparameter, AILSP_FAST, gi, and index.

Referenced by AIL_positionshoot().

◆ AIL_toSortInt()

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 157 of file g_ai_lua.cpp.

References AIL_invalidparameter, AILSC_DIST, gi, and index.

Referenced by AIL_see().

◆ AIL_toTeamInt()

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 125 of file g_ai_lua.cpp.

References AIL_invalidparameter, gi, and TEAM_DEFAULT.

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

◆ AIL_toTeamString()

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 110 of file g_ai_lua.cpp.

References AIL_invalidparameter, and gi.

Referenced by actorL_team(), and AIL_TeamThink().

◆ AIL_toVisInt()

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 139 of file g_ai_lua.cpp.

References AIL_invalidparameter, AILVT_ALL, gi, and index.

Referenced by AIL_missiontargets(), and AIL_see().

◆ AIL_toWanderPInt()

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 211 of file g_ai_lua.cpp.

References AIL_invalidparameter, AILPW_RAND, gi, and index.

Referenced by AIL_positionwander().

◆ AIL_tusforshooting()

int AIL_tusforshooting ( lua_State * L)
static

Returns the min TUs the actor needs to fire.

Definition at line 2072 of file g_ai_lua.cpp.

References AIL_ent, Item::getFastestFireDef(), and fireDef_t::time.

◆ AIL_waypoints()

◆ AIL_weapontype()

int AIL_weapontype ( lua_State * L)
static

Returns the type of the weapons in the actors hands.

Definition at line 2049 of file g_ai_lua.cpp.

References AIL_ent, Item::def(), and objDef_t::type.

◆ lua_isactor()

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 464 of file g_ai_lua.cpp.

References ACTOR_METATABLE, and index.

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

◆ lua_ispos3()

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 871 of file g_ai_lua.cpp.

References index, and POS3_METATABLE.

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

◆ lua_pushactor()

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 493 of file g_ai_lua.cpp.

References ACTOR_METATABLE.

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

◆ lua_pushpos3()

pos3_t * lua_pushpos3 ( lua_State * L,
pos3_t * pos )
static

◆ lua_toactor()

aiActor_t * lua_toactor ( lua_State * L,
int index )
static

◆ lua_topos3()

pos3_t * lua_topos3 ( lua_State * L,
int index )
static

Returns the pos3 from the metatable at index.

Definition at line 888 of file g_ai_lua.cpp.

References index, lua_ispos3(), and POS3_METATABLE.

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

◆ operator<()

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

Definition at line 239 of file g_ai_lua.cpp.

References i, and AilSortTable< T >::sortLookup.

◆ pos3L_distance()

int pos3L_distance ( lua_State * L)
static

Return the distance the position an the AI actor.

Definition at line 971 of file g_ai_lua.cpp.

References AIL_ent, AIL_toDistInt(), AILSC_DIST, AILSC_PATH, G_ActorMoveLength(), G_FindPath(), level, lua_ispos3(), lua_topos3(), PosToVec, ROUTING_NOT_REACHABLE, and VectorDist.

◆ pos3L_face()

int pos3L_face ( lua_State * L)
static

Makes the actor face the position.

Definition at line 957 of file g_ai_lua.cpp.

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

◆ pos3L_goto()

int pos3L_goto ( lua_State * L)
static

Makes the actor head to the position.

Definition at line 928 of file g_ai_lua.cpp.

References AIL_ent, AIL_player, G_ActorMoveLength(), G_ClientMove(), G_MoveCalc(), gi, length, level, lua_ispos3(), lua_topos3(), and ROUTING_NOT_REACHABLE.

◆ pos3L_register()

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 847 of file g_ai_lua.cpp.

References POS3_METATABLE, and pos3L_methods.

Referenced by AIL_InitLua().

◆ pos3L_tostring()

int pos3L_tostring ( lua_State * L)
static

Puts the pos3 information in a string.

Definition at line 912 of file g_ai_lua.cpp.

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

Variable Documentation

◆ actorL_methods

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_isinjured(lua_State *L)
Checks to see if the actor is seriously injured.
Definition g_ai_lua.cpp:771
static int actorL_pos(lua_State *L)
Gets the actors position.
Definition g_ai_lua.cpp:521
static int actorL_morale(lua_State *L)
Gets the current morale of the actor onto the stack.
Definition g_ai_lua.cpp:743
static int actorL_HP(lua_State *L)
Gets the number of HP the actor has left.
Definition g_ai_lua.cpp:725
static int actorL_isdead(lua_State *L)
Check if the actor is dead.
Definition g_ai_lua.cpp:809
static int actorL_isvalidtarget(lua_State *L)
Check if the actor is a valid target to attack.
Definition g_ai_lua.cpp:827
static int actorL_shoot(lua_State *L)
Shoots the actor.
Definition g_ai_lua.cpp:533
static int actorL_team(lua_State *L)
Gets the actor's team.
Definition g_ai_lua.cpp:576
static int actorL_throwgrenade(lua_State *L)
Throws a grenade to the actor.
Definition g_ai_lua.cpp:590
static int actorL_tostring(lua_State *L)
Pushes the actor as a string.
Definition g_ai_lua.cpp:505
static int actorL_TU(lua_State *L)
Gets the number of usable TU the actor has left.
Definition g_ai_lua.cpp:707
static int actorL_isarmed(lua_State *L)
Check if actor has weapons.
Definition g_ai_lua.cpp:790

Lua Actor metatable methods.

Definition at line 321 of file g_ai_lua.cpp.

Referenced by actorL_register().

◆ AIL_ent

◆ AIL_methods

const luaL_Reg AIL_methods[]
static

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

Definition at line 398 of file g_ai_lua.cpp.

Referenced by AIL_InitLua().

◆ AIL_player

Player* AIL_player
static

Player currently running the Lua AI.

Definition at line 247 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().

◆ ailState

lua_State* ailState
static

Definition at line 63 of file g_ai_lua.cpp.

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

◆ pos3L_methods

const luaL_Reg pos3L_methods[]
static
Initial value:
= {
{"__tostring", pos3L_tostring},
{"go", pos3L_goto},
{"face", pos3L_face},
{"distance", pos3L_distance},
{nullptr, nullptr}
}
static int pos3L_goto(lua_State *L)
Makes the actor head to the position.
Definition g_ai_lua.cpp:928
static int pos3L_distance(lua_State *L)
Return the distance the position an the AI actor.
Definition g_ai_lua.cpp:971
static int pos3L_face(lua_State *L)
Makes the actor face the position.
Definition g_ai_lua.cpp:957
static int pos3L_tostring(lua_State *L)
Puts the pos3 information in a string.
Definition g_ai_lua.cpp:912

Lua Pos3 metatable methods.

Definition at line 354 of file g_ai_lua.cpp.

Referenced by pos3L_register().