#include "g_local.h"
#include "g_ai.h"
#include "lua/lauxlib.h"
Go to the source code of this file.
Data Structures | |
struct | aiActor_s |
Wrapper around edict. More... | |
Defines | |
#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. | |
Functions | |
static const char * | AIL_toTeamString (const int team) |
Converts integer team representation into string. | |
static int | AIL_toTeamInt (const char *team) |
Converts team string into int representation. | |
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_t * | lua_toactor (lua_State *L, int index) |
Returns the actor from the metatable at index. | |
static aiActor_t * | lua_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_face (lua_State *L) |
Makes the actor face the position. | |
static int | actorL_team (lua_State *L) |
Gets the actor's team. | |
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_t * | lua_topos3 (lua_State *L, int index) |
Returns the pos3 from the metatable at index. | |
static pos3_t * | lua_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 | AIL_print (lua_State *L) |
Works more or less like Lua's builtin print. | |
static int | AIL_see (lua_State *L) |
Returns what the actor can see. | |
static int | AIL_crouch (lua_State *L) |
Toggles crouch state with true/false and returns current crouch state. | |
static int | AIL_isinjured (lua_State *L) |
Checks to see if the actor is injured. | |
static int | AIL_TU (lua_State *L) |
Gets the number of TU the actor has left. | |
static int | AIL_HP (lua_State *L) |
Gets the number of HP the actor has left. | |
static int | AIL_morale (lua_State *L) |
Gets the current morale of the actor onto the stack. | |
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 more closer to the target and locate behind the target from enemy. | |
static int | AIL_distance (lua_State *L) |
Returns distance between AI and target. | |
void | AIL_ActorThink (player_t *player, edict_t *ent) |
The think function for the ai controlled aliens. | |
int | AIL_InitActor (edict_t *ent, char *type, char *subtype) |
Initializes the AI. | |
static void | AIL_CleanupActor (edict_t *ent) |
Cleans up the AI part of the actor. | |
void | AIL_Init (void) |
void | AIL_Shutdown (void) |
void | AIL_Cleanup (void) |
Purges all the AI from the entities. | |
Variables | |
static edict_t * | AIL_ent |
static player_t * | AIL_player |
static const luaL_reg | actorL_methods [] |
static const luaL_reg | pos3L_methods [] |
static const luaL_reg | AIL_methods [] |
#define ACTOR_METATABLE "actor" |
Actor Lua Metable name.
Definition at line 40 of file g_ai_lua.c.
Referenced by actorL_register(), lua_isactor(), lua_pushactor(), and lua_toactor().
#define AI_METATABLE "ai" |
#define AIL_invalidparameter | ( | n | ) | gi.DPrintf("AIL: Invalid parameter #%d in '%s'.\n", n, __func__) |
Definition at line 48 of file g_ai_lua.c.
Referenced by AIL_crouch(), AIL_positionherd(), AIL_positionhide(), AIL_reactionfire(), AIL_reload(), AIL_see(), AIL_toTeamInt(), and AIL_toTeamString().
#define luaL_dobuffer | ( | L, | |||
b, | |||||
n, | |||||
s | ) | (luaL_loadbuffer(L, b, n, s) || lua_pcall(L, 0, LUA_MULTRET, 0)) |
Provides an api like luaL_dostring for buffers.
Definition at line 46 of file g_ai_lua.c.
Referenced by AIL_InitActor().
#define POS3_METATABLE "pos3" |
Pos3 Lua Metatable name.
Definition at line 39 of file g_ai_lua.c.
Referenced by lua_ispos3(), lua_pushpos3(), lua_topos3(), and pos3L_register().
static int actorL_face | ( | lua_State * | L | ) | [static] |
Makes the actor face the position.
Definition at line 363 of file g_ai_lua.c.
References AI_TurnIntoDirection(), aiActor_s::ent, lua_isactor(), lua_pushboolean(), lua_toactor(), and edict_s::pos.
static int actorL_pos | ( | lua_State * | L | ) | [static] |
Gets the actors position.
Definition at line 283 of file g_ai_lua.c.
References aiActor_s::ent, lua_isactor(), lua_pushpos3(), lua_toactor(), and edict_s::pos.
static int actorL_register | ( | lua_State * | L | ) | [static] |
Registers the actor metatable in the lua_State.
A C T O R L
[in,out] | L | State to register the metatable in. |
Definition at line 198 of file g_ai_lua.c.
References ACTOR_METATABLE, actorL_methods, lua_pop, lua_pushvalue(), lua_setfield(), luaL_newmetatable(), and luaL_register().
Referenced by AIL_InitActor().
static int actorL_shoot | ( | lua_State * | L | ) | [static] |
Shoots the actor.
Definition at line 297 of file g_ai_lua.c.
References AI_GetItemForShootType(), aiActor_s::ent, FIRESH_FiredefForWeapon(), G_ClientShoot(), int(), lua_gettop(), lua_isactor(), lua_isnumber(), lua_pushboolean(), lua_toactor(), lua_tonumber(), item_s::m, edict_s::pos, qtrue, ST_LEFT, ST_RIGHT, item_s::t, fireDef_s::time, and edict_s::TU.
static int actorL_team | ( | lua_State * | L | ) | [static] |
Gets the actor's team.
Definition at line 382 of file g_ai_lua.c.
References AIL_toTeamString(), aiActor_s::ent, lua_isactor(), lua_pushstring(), lua_toactor(), and edict_s::team.
static int actorL_tostring | ( | lua_State * | L | ) | [static] |
Pushes the actor as a string.
Definition at line 266 of file g_ai_lua.c.
References edict_s::chr, Com_sprintf(), aiActor_s::ent, lua_isactor(), lua_pushstring(), lua_toactor(), MAX_VAR, and character_s::name.
The think function for the ai controlled aliens.
[in] | player | |
[in] | ent |
Definition at line 968 of file g_ai_lua.c.
References edict_s::AI, gi, AI_s::L, lua_getglobal, lua_isstring(), lua_pcall(), and lua_tostring.
Referenced by AI_Run().
static int AIL_canreload | ( | lua_State * | L | ) | [static] |
Checks to see if the actor can reload.
Definition at line 767 of file g_ai_lua.c.
References game_import_t::csi, G_ClientCanReload(), gi, csi_s::idLeft, csi_s::idRight, and lua_pushboolean().
void AIL_Cleanup | ( | void | ) |
Purges all the AI from the entities.
Definition at line 1076 of file g_ai_lua.c.
References AIL_CleanupActor(), and G_EdictsGetNextActor().
Referenced by G_MatchSendResults().
static void AIL_CleanupActor | ( | edict_t * | ent | ) | [static] |
Cleans up the AI part of the actor.
[in] | ent | Pointer to actor to cleanup AI. |
Definition at line 1046 of file g_ai_lua.c.
References edict_s::AI, AI_s::L, and lua_close().
Referenced by AIL_Cleanup().
static int AIL_crouch | ( | lua_State * | L | ) | [static] |
Toggles crouch state with true/false and returns current crouch state.
Definition at line 665 of file g_ai_lua.c.
References AIL_invalidparameter, G_ClientStateChange(), G_IsCrouched, lua_gettop(), lua_isboolean, lua_pushboolean(), lua_toboolean(), qfalse, qtrue, and STATE_CROUCHED.
static int AIL_distance | ( | lua_State * | L | ) | [static] |
Returns distance between AI and target.
target
(passed trough the lua stack) The target to which the distance is calculated Definition at line 944 of file g_ai_lua.c.
References aiActor_s::ent, lua_gettop(), lua_isactor(), lua_pushnumber(), lua_toactor(), edict_s::origin, and VectorDist.
static int AIL_HP | ( | lua_State * | L | ) | [static] |
Gets the number of HP the actor has left.
Definition at line 701 of file g_ai_lua.c.
References edict_s::HP, and lua_pushnumber().
void AIL_Init | ( | void | ) |
Definition at line 1057 of file g_ai_lua.c.
References gi, TEAM_ALIEN, TEAM_ALL, TEAM_CIVILIAN, and TEAM_PHALANX.
Referenced by G_Init().
int AIL_InitActor | ( | edict_t * | ent, | |
char * | type, | |||
char * | subtype | |||
) |
Initializes the AI.
[in] | ent | Pointer to actor to initialize AI for. |
[in] | type | Type of AI (Lua file name without .lua). |
[in] | subtype | Subtype of the AI. |
Definition at line 999 of file g_ai_lua.c.
References actorL_register(), edict_s::AI, AI_METATABLE, AIL_methods, byte, Com_sprintf(), gi, AI_s::L, luaL_dobuffer, luaL_newstate(), luaL_register(), MAX_VAR, pos3L_register(), Q_strncpyz(), AI_s::subtype, and AI_s::type.
Referenced by AI_InitPlayer().
static int AIL_isinjured | ( | lua_State * | L | ) | [static] |
Checks to see if the actor is injured.
Definition at line 683 of file g_ai_lua.c.
References edict_s::chr, edict_s::HP, lua_pushboolean(), and character_s::maxHP.
static int AIL_morale | ( | lua_State * | L | ) | [static] |
Gets the current morale of the actor onto the stack.
Definition at line 710 of file g_ai_lua.c.
References lua_pushnumber(), and edict_s::morale.
static int AIL_positionherd | ( | lua_State * | L | ) | [static] |
Determine the position where actor is more closer to the target and locate behind the target from enemy.
target
(parameter is passed through the lua stack) The actor to which AI tries to become closer Definition at line 917 of file g_ai_lua.c.
References AI_FindHerdLocation(), AIL_invalidparameter, aiActor_s::ent, G_EdictSetOrigin(), lua_gettop(), lua_isactor(), lua_pushboolean(), lua_pushpos3(), lua_toactor(), edict_s::origin, edict_s::pos, save(), edict_s::TU, and VectorCopy.
static int AIL_positionhide | ( | lua_State * | L | ) | [static] |
Moves the actor into a position in which he can hide.
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 879 of file g_ai_lua.c.
References AI_FindHidingLocation(), AI_GetHidingTeam(), AIL_invalidparameter, AIL_toTeamInt(), G_EdictSetOrigin(), lua_gettop(), lua_isstring(), lua_pushboolean(), lua_pushpos3(), lua_tostring, edict_s::pos, save(), TEAM_ALL, edict_s::TU, and VectorCopy.
static int AIL_positionshoot | ( | lua_State * | L | ) | [static] |
Moves the actor into a position in which he can shoot his target.
Definition at line 805 of file g_ai_lua.c.
References byte, check, aiActor_s::ent, edict_s::fieldSize, G_ActorVis(), G_IsCrouched, G_MoveCalc(), gi, int(), level, lua_isactor(), lua_pushboolean(), lua_pushpos3(), lua_toactor(), PATHFINDING_HEIGHT, PATHFINDING_WIDTH, level_locals_t::pathingMap, edict_s::pos, qtrue, ROUTING_NOT_REACHABLE, game_import_t::routingMap, edict_s::TU, 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 532 of file g_ai_lua.c.
References gi, i, lua_gettop(), lua_pop, lua_pushvalue(), LUA_TBOOLEAN, LUA_TNIL, LUA_TNUMBER, lua_toboolean(), lua_tostring, LUA_TSTRING, lua_type(), luaL_callmeta(), qfalse, and qtrue.
static int AIL_reactionfire | ( | lua_State * | L | ) | [static] |
Sets the actor's reaction fire mode.
Definition at line 719 of file g_ai_lua.c.
References AIL_invalidparameter, G_ClientStateChange(), G_IsReaction, lua_gettop(), lua_isboolean, lua_isstring(), lua_pushboolean(), lua_toboolean(), lua_tostring, qfalse, qtrue, STATE_REACTION, STATE_REACTION_MANY, and STATE_REACTION_ONCE.
static int AIL_reload | ( | lua_State * | L | ) | [static] |
Actor reloads his weapons.
Definition at line 777 of file g_ai_lua.c.
References AIL_invalidparameter, game_import_t::csi, G_ActorReload(), gi, csi_s::idLeft, csi_s::idRight, INVDEF, lua_gettop(), lua_isstring(), and lua_tostring.
static int AIL_roundsleft | ( | lua_State * | L | ) | [static] |
Checks to see how many rounds the actor has left.
Definition at line 748 of file g_ai_lua.c.
References LEFT, lua_pushnil(), lua_pushnumber(), and RIGHT.
static int AIL_see | ( | lua_State * | L | ) | [static] |
Returns what the actor can see.
Definition at line 576 of file g_ai_lua.c.
References AIL_invalidparameter, AIL_toTeamInt(), check, aiActor_s::ent, G_EdictsGetNextLivingActor(), G_Vis(), i, lua_gettop(), lua_isstring(), lua_newtable, lua_pushactor(), lua_pushnumber(), lua_rawset(), lua_tostring, MAX_EDICTS, edict_s::pos, edict_s::team, TEAM_ALL, VectorDistSqr, and VT_NOFRUSTUM.
void AIL_Shutdown | ( | void | ) |
static int AIL_toTeamInt | ( | const char * | team | ) | [static] |
Converts team string into int representation.
team | The team to convert (alien, phalanx, civilian, ...) |
Definition at line 75 of file g_ai_lua.c.
References AIL_invalidparameter, gi, and TEAM_DEFAULT.
Referenced by AIL_positionhide(), and AIL_see().
static const char* AIL_toTeamString | ( | const int | team | ) | [static] |
Converts integer team representation into string.
team | The team to convert to the string representation |
Definition at line 61 of file g_ai_lua.c.
References AIL_invalidparameter, game_import_t::GetConstVariable(), and gi.
Referenced by actorL_team().
static int AIL_TU | ( | lua_State * | L | ) | [static] |
Gets the number of TU the actor has left.
Definition at line 692 of file g_ai_lua.c.
References lua_pushnumber(), and edict_s::TU.
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.
[in,out] | L | Lua state to check. |
[in] | index | Index to check for a actor metatable. |
Definition at line 222 of file g_ai_lua.c.
References ACTOR_METATABLE, lua_getfield(), lua_getmetatable(), lua_pop, lua_rawequal(), and LUA_REGISTRYINDEX.
Referenced by actorL_face(), actorL_pos(), actorL_shoot(), actorL_team(), actorL_tostring(), AIL_distance(), AIL_positionherd(), AIL_positionshoot(), 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.
[in] | L | Lua state to check. |
[in] | index | Index to check for a pos3 metatable. |
Definition at line 430 of file g_ai_lua.c.
References lua_getfield(), lua_getmetatable(), lua_pop, lua_rawequal(), LUA_REGISTRYINDEX, and POS3_METATABLE.
Referenced by lua_topos3(), pos3L_face(), pos3L_goto(), and pos3L_tostring().
Pushes a actor as a metatable at the top of the stack.
Definition at line 253 of file g_ai_lua.c.
References ACTOR_METATABLE, lua_newuserdata(), lua_setmetatable(), and luaL_getmetatable.
Referenced by AIL_see().
Pushes a pos3 as a metatable at the top of the stack.
Definition at line 461 of file g_ai_lua.c.
References lua_newuserdata(), lua_setmetatable(), luaL_getmetatable, and POS3_METATABLE.
Referenced by actorL_pos(), AIL_positionherd(), AIL_positionhide(), and AIL_positionshoot().
Returns the actor from the metatable at index.
Definition at line 241 of file g_ai_lua.c.
References ACTOR_METATABLE, lua_isactor(), lua_touserdata(), and luaL_typerror().
Referenced by actorL_face(), actorL_pos(), actorL_shoot(), actorL_team(), actorL_tostring(), AIL_distance(), AIL_positionherd(), and AIL_positionshoot().
Returns the pos3 from the metatable at index.
Definition at line 449 of file g_ai_lua.c.
References lua_ispos3(), lua_touserdata(), luaL_typerror(), and POS3_METATABLE.
Referenced by pos3L_face(), pos3L_goto(), and pos3L_tostring().
static int pos3L_face | ( | lua_State * | L | ) | [static] |
Makes the actor face the position.
Definition at line 513 of file g_ai_lua.c.
References AI_TurnIntoDirection(), lua_ispos3(), lua_pushboolean(), lua_topos3(), and pos.
static int pos3L_goto | ( | lua_State * | L | ) | [static] |
Makes the actor head to the position.
Definition at line 491 of file g_ai_lua.c.
References byte, G_ClientMove(), G_IsCrouched, G_MoveCalc(), gi, level, lua_ispos3(), lua_pushboolean(), lua_topos3(), level_locals_t::pathingMap, edict_s::pos, pos, and edict_s::TU.
static int pos3L_register | ( | lua_State * | L | ) | [static] |
Registers the pos3 metatable in the lua_State.
pos3 metatable.
P O S 3 L
[in] | L | State to register the metatable in. |
Definition at line 406 of file g_ai_lua.c.
References lua_pop, lua_pushvalue(), lua_setfield(), luaL_newmetatable(), luaL_register(), POS3_METATABLE, and pos3L_methods.
Referenced by AIL_InitActor().
static int pos3L_tostring | ( | lua_State * | L | ) | [static] |
Puts the pos3 information in a string.
Definition at line 474 of file g_ai_lua.c.
References Com_sprintf(), lua_ispos3(), lua_pushstring(), lua_topos3(), and MAX_VAR.
const luaL_reg actorL_methods[] [static] |
{ {"__tostring", actorL_tostring}, {"pos", actorL_pos}, {"shoot", actorL_shoot}, {"face", actorL_face}, {"team", actorL_team}, {NULL, NULL} }
Lua Actor metatable methods. http://www.lua.org/manual/5.1/manual.html#lua_CFunction
Definition at line 115 of file g_ai_lua.c.
Referenced by actorL_register().
Actor currently running the Lua AI.
Definition at line 94 of file g_ai_lua.c.
const luaL_reg AIL_methods[] [static] |
{ {"print", AIL_print}, {"see", AIL_see}, {"crouch", AIL_crouch}, {"isinjured", AIL_isinjured}, {"TU", AIL_TU}, {"HP", AIL_HP}, {"morale", AIL_morale}, {"reactionfire", AIL_reactionfire}, {"roundsleft", AIL_roundsleft}, {"canreload", AIL_canreload}, {"reload", AIL_reload}, {"positionshoot", AIL_positionshoot}, {"positionhide", AIL_positionhide}, {"positionherd", AIL_positionherd}, {"distance", AIL_distance}, {NULL, NULL} }
Lua AI module methods. http://www.lua.org/manual/5.1/manual.html#lua_CFunction
Definition at line 169 of file g_ai_lua.c.
Referenced by AIL_InitActor().
player_t* AIL_player [static] |
Player currently running the Lua AI.
Definition at line 95 of file g_ai_lua.c.
const luaL_reg pos3L_methods[] [static] |
{ {"__tostring", pos3L_tostring}, {"goto", pos3L_goto}, {"face", pos3L_face}, {NULL, NULL} }
Lua Pos3 metatable methods. http://www.lua.org/manual/5.1/manual.html#lua_CFunction
Definition at line 140 of file g_ai_lua.c.
Referenced by pos3L_register().