35 #include "../shared/cxx.h" 51 #if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM < 504 52 LUALIB_API
int luaL_typeerror (lua_State *L,
int narg,
const char *tname) {
53 const char *msg = lua_pushfstring(L,
"%s expected, got %s",
54 tname, luaL_typename(L, narg));
55 return luaL_argerror(L, narg, msg);
59 #define POS3_METATABLE "pos3" 60 #define ACTOR_METATABLE "actor" 61 #define AI_METATABLE "ai" 63 static lua_State* ailState; 67 #define luaL_dobuffer(L, b, n, s) \ 68 (luaL_loadbuffer(L, b, n, s) || lua_pcall(L, 0, LUA_MULTRET, 0)) 69 #define AIL_invalidparameter(n) \ 70 gi.DPrintf("AIL: Invalid parameter #%d in '%s'.\n", n, __func__) 113 if (teamStr ==
nullptr)
128 if (!
gi.GetConstIntFromNamespace(
"luaaiteam", team, &teamInt))
142 if (lua_isstring(L,
index)) {
143 const char* s = lua_tostring(L,
index);
144 if (!
gi.GetConstIntFromNamespace(
"luaaivis", s, &visInt))
160 if (lua_isstring(L,
index)) {
161 const char* s = lua_tostring(L,
index);
162 if (!
gi.GetConstIntFromNamespace(
"luaaisort", s, &sortInt))
178 if (lua_isstring(L,
index)) {
179 const char* s = lua_tostring(L,
index);
180 if (!
gi.GetConstIntFromNamespace(
"luaaidist", s, &distInt))
196 if (lua_isstring(L,
index)) {
197 const char* s = lua_tostring(L,
index);
198 if (!
gi.GetConstIntFromNamespace(
"luaaishot", s, &spInt))
214 if (lua_isstring(L,
index)) {
215 const char* s = lua_tostring(L,
index);
216 if (!
gi.GetConstIntFromNamespace(
"luaaiwander", s, &wpInt))
226 typedef struct aiActor_s {
240 return (
i.sortLookup < j.sortLookup);
251 int shotChecked =
NONE;
252 float bestDmg = 0.0f;
253 bestShots = bestType = bestFd =
NONE;
260 if (fdArray ==
nullptr)
267 const int shots = tu / time;
276 if (shotChecked != shotFlags) {
277 shotChecked = shotFlags;
288 bestType = shootType;
369 static int AIL_see(lua_State* L);
446 lua_pushvalue(L, -1);
447 lua_setfield(L, -2,
"__index");
466 if (lua_getmetatable(L,
index) == 0)
471 if (lua_rawequal(L, -1, -2))
498 lua_setmetatable(L, -2);
514 lua_pushstring(L,
buf);
542 if (lua_gettop(L) > 1) {
543 assert(lua_isnumber(L, 2));
545 tu = std::min(static_cast<int>(lua_tonumber(L, 2)), tu);
555 if (bestType ==
NONE) {
556 lua_pushboolean(L, 0);
561 while (bestShots > 0) {
569 lua_pushboolean(L, shot);
581 assert(target !=
nullptr);
583 lua_pushstring(L, team);
595 lua_pushboolean(L, 0);
599 assert(target !=
nullptr);
603 if (lua_gettop(L) > 1) {
604 if (!lua_isnumber(L, 2)) {
606 lua_pushboolean(L, 0);
609 minNum =
static_cast<int>(lua_tonumber(L, 2));
614 if (lua_gettop(L) > 2) {
615 if (!lua_isnumber(L, 3)) {
617 lua_pushboolean(L, 0);
620 tus = std::min(static_cast<int>(lua_tonumber(L, 3)), tus);
629 lua_pushboolean(L, 0);
634 Item* grenade =
nullptr;
636 if (!fromCont || !grenade) {
637 lua_pushboolean(L, 0);
642 const int invMoveCost = fromCont->
out +
INVDEF(hand)->in;
664 lua_pushboolean(L, 0);
670 Actor* check =
nullptr;
676 if (dist > bestFd->
splrad)
680 lua_pushboolean(L, 0);
687 lua_pushboolean(L, 0);
694 lua_pushboolean(L, 0);
700 lua_pushboolean(L, result);
712 lua_pushboolean(L, 0);
716 assert(actor !=
nullptr);
730 lua_pushboolean(L, 0);
734 assert(actor !=
nullptr);
736 lua_pushnumber(L, actor->
actor->
HP);
748 lua_pushboolean(L, 0);
752 assert(actor !=
nullptr);
754 const char* morStat =
"normal";
764 lua_pushstring(L, morStat);
776 lua_pushboolean(L, 0);
780 assert(actor !=
nullptr);
795 lua_pushboolean(L, 0);
799 assert(actor !=
nullptr);
814 lua_pushboolean(L, 0);
818 assert(actor !=
nullptr);
832 assert(target !=
nullptr);
853 lua_pushvalue(L, -1);
854 lua_setfield(L, -2,
"__index");
873 if (lua_getmetatable(L,
index) == 0)
878 if (lua_rawequal(L, -1, -2))
903 memcpy(p, pos,
sizeof(*p));
905 lua_setmetatable(L, -2);
919 Com_sprintf(
buf,
sizeof(
buf),
"Pos3( x=%d, y=%d, z=%d )", (*p)[0], (*p)[1], (*p)[2]);
921 lua_pushstring(L,
buf);
964 lua_pushboolean(L, 1);
976 assert(pos !=
nullptr);
979 if (lua_gettop(L) > 1)
1012 const int n = lua_gettop(L);
1014 for (
int i = 1;
i <= n;
i++) {
1018 lua_pushvalue(L,
i);
1019 if (luaL_callmeta(L, -1,
"__tostring")) {
1020 s = lua_tostring(L, -1);
1023 switch (lua_type(L, -1)) {
1026 s = lua_tostring(L, -1);
1029 s = lua_toboolean(L, -1) ?
"true" :
"false";
1036 s =
"unknown lua type";
1040 gi.DPrintf(
"%s%s", (
i > 1) ?
"\t" :
"", s);
1060 gi.DPrintf(
"Problem while running lua: attempt to get the player's team while not in team mode.");
1069 Actor* check =
nullptr;
1073 lua_pushnumber(L,
i++);
1075 target.
actor = check;
1088 gi.DPrintf(
"Problem while running lua: attempt to select the active AI actor while not in team mode.");
1090 }
else if (lua_gettop(L) > 0 &&
lua_isactor(L, 1)) {
1097 lua_pushboolean(L,
false);
1115 bool invTeam =
false;
1118 if ((lua_gettop(L) > 0)) {
1123 if ((lua_gettop(L) > 1)) {
1124 if (lua_isstring(L, 2)) {
1125 const char* s = lua_tostring(L, 2);
1126 if (s[0] ==
'-' || s[0] ==
'~') {
1139 if ((lua_gettop(L) > 2)) {
1145 Actor* check =
nullptr;
1157 if ((team ==
TEAM_ALL || (check->
getTeam() == team ? !invTeam : invTeam))
1161 || (vision ==
AILVT_DIST && distance <= visDist * visDist))) {
1179 sortTable[n++].
data = check;
1184 std::sort(sortTable, sortTable + n);
1188 for (
int i = 0;
i < n;
i++) {
1189 lua_pushnumber(L,
i + 1);
1203 if (lua_gettop(L) > 0) {
1204 if (lua_isboolean(L, 1)) {
1205 const bool reqState = lua_toboolean(L, 1);
1207 if (reqState != state)
1222 if (lua_gettop(L) > 0) {
1223 int reactionState = 0;
1225 if (lua_isstring(L, 1)) {
1227 const char* cmd = lua_tostring(L, 1);
1231 if (reactionState) {
1281 if (lua_gettop(L) > 0) {
1282 if (lua_isstring(L, 1)) {
1283 const char* s = lua_tostring(L, 1);
1287 }
else if (
Q_streq(s,
"left")) {
1326 if ((lua_gettop(L) > 1))
1331 if (lua_gettop(L) > 2) {
1332 assert(lua_isnumber(L, 3));
1334 tus = std::min(static_cast<int>(lua_tonumber(L, 3)), tus);
1339 lua_pushboolean(L, 0);
1345 if (item ==
nullptr) {
1351 if (item ==
nullptr) {
1352 lua_pushboolean(L, 0);
1356 if (fd ==
nullptr) {
1357 lua_pushboolean(L, 0);
1362 if (tus - fdTime <= 0) {
1363 lua_pushboolean(L, 0);
1381 float bestScore = 0.0f;
1385 while (searchArea.
getNext(to)) {
1398 const float bestDmg =
AIL_GetBestShot(*actor, *target->
actor, tus - move, dist, dummy, dummy, dummy);
1429 lua_pushboolean(L, 0);
1448 if (lua_gettop(L)) {
1449 if (lua_isstring(L, 1)) {
1450 const char* s = lua_tostring(L, 1);
1451 bool invTeam =
false;
1452 if (s[0] ==
'-' || s[0] ==
'~') {
1470 if (lua_gettop(L) > 1) {
1471 if (lua_isnumber(L, 2)) {
1472 tus = std::min(static_cast<int>(lua_tonumber(L, 2)), tus);
1485 lua_pushboolean(L, 0);
1504 lua_pushboolean(L, 0);
1511 if (lua_gettop(L) > 1) {
1512 if (lua_isnumber(L, 2)) {
1513 tus = std::min(static_cast<int>(lua_tonumber(L, 2)), tus);
1519 bool inverse =
false;
1520 if (lua_gettop(L) > 2) {
1521 if (lua_isboolean(L, 3))
1522 inverse = lua_toboolean(L, 3);
1532 lua_pushboolean(L, 0);
1546 lua_pushboolean(L, 0);
1551 assert(target !=
nullptr);
1554 if (lua_gettop(L) > 1) {
1555 if (lua_isnumber(L, 2))
1556 tus = std::min(static_cast<int>(lua_tonumber(L, 2)), tus);
1562 if (lua_gettop(L) > 2){
1563 if (lua_isboolean(L, 3))
1564 hide = lua_toboolean(L, 3);
1576 lua_pushboolean(L, 0);
1584 PosSubDV(to, crouchingState, dvec);
1596 lua_pushboolean(L, 0);
1612 bool invTeam =
false;
1615 if ((lua_gettop(L) > 0)) {
1620 if ((lua_gettop(L) > 1)) {
1621 if (lua_isstring(L, 2)) {
1622 const char* s = lua_tostring(L, 2);
1623 if (s[0] ==
'-' || s[0] ==
'~') {
1636 if ((lua_gettop(L) > 2))
1644 Edict* mission =
nullptr;
1650 if ((team ==
TEAM_ALL || (mission->
getTeam() == team ? !invTeam : invTeam))
1653 || (vision ==
AILVT_DIST && distance <= visDist * visDist))) {
1668 sortTable[n++].
data = mission;
1673 std::sort(sortTable, sortTable + n);
1677 for (
int i = 0;
i < n;
i++) {
1678 lua_pushnumber(L,
i + 1);
1690 const float minEnemyDist = 160.0f;
1692 float minDist = 800.0f;
1693 if (lua_gettop(L) > 0) {
1694 if (lua_isnumber(L, 1))
1695 minDist = lua_tonumber(L, 1);
1702 if ((lua_gettop(L) > 1))
1708 if (checkPoint->inuse)
1713 Actor* check =
nullptr;
1714 bool ambush =
false;
1718 if (dist < minEnemyDist) {
1735 sortTable[++n].
data = checkPoint;
1747 sortTable[++n].
data = checkPoint;
1755 std::sort(sortTable, sortTable + n);
1759 for (
int i = 0;
i < n;
i++) {
1760 lua_pushnumber(L,
i + 1);
1776 lua_pushboolean(L, 0);
1781 if (lua_gettop(L) > 1) {
1782 if (lua_isnumber(L, 2))
1783 tus = lua_tonumber(L, 2);
1795 radius = mission->
radius;
1799 lua_pushboolean(L, 0);
1823 if (lua_gettop(L) > 0)
1825 if (lua_gettop(L) > 1) {
1826 if (lua_isnumber(L, 2))
1827 radius = lua_tonumber(L, 2);
1831 if (lua_gettop(L) > 2) {
1838 if (lua_gettop(L) > 3) {
1839 if (lua_isnumber(L, 4))
1840 tus = std::min(static_cast<int>(lua_tonumber(L, 4)), tus);
1849 float bestScore = 0;
1853 while (searchArea.
getNext(pos)) {
1870 for (
int n = 1; n < 8; ++n) {
1872 score /= pow(n * 2.0
f, 2);
1873 if ((method == 1 && dir ==
dvright[cDir]) || (method == 2 && dir ==
dvleft[cDir]))
1879 if (score > bestScore) {
1886 lua_pushboolean(L, 0);
1899 if (lua_gettop(L) > 0) {
1900 if (lua_isboolean(L, 1))
1901 full = lua_toboolean(L, 1);
1908 Edict* check =
nullptr;
1920 if (item->isWeapon() && (item->getAmmoLeft() > 0 || item->def()->ammo <= 0)) {
1921 sortTable[n].
data = check;
1930 std::sort(sortTable, sortTable + n);
1934 for (
int i = 0;
i < n;
i++) {
1935 lua_pushnumber(L,
i + 1);
1948 lua_pushboolean(L, result);
1958 if (lua_gettop(L) < 1 || lua_isnil(L, 1)) {
1960 lua_pushboolean(L, 1);
1965 if (waypoint !=
nullptr) {
1967 lua_pushboolean(L, 1);
1969 lua_pushboolean(L, 0);
1971 lua_pushboolean(L, 0);
1991 if (lua_gettop(L)) {
1992 if (lua_isnumber(L, 1))
1993 tus = std::min(static_cast<int>(lua_tonumber(L, 1)), tus);
2004 float bestScore = -1;
2013 float minDistFoe = -1.0f, minDistFriend = -1.0f;
2014 Actor* check =
nullptr;
2018 if (dist < minDistFriend || minDistFriend < 0.0
f)
2019 minDistFriend = dist;
2021 if (dist < minDistFoe || minDistFoe < 0.0
f)
2025 float score = minDistFoe - (minDistFriend /
GRID_WIDTH);
2030 if (score > bestScore) {
2038 lua_pushboolean(L, 0);
2054 lua_pushstring(L, right ? right->
def()->
type :
"none");
2055 lua_pushstring(L, left ? left->
def()->
type :
"none");
2091 lua_pushnumber(L, bestTUs);
2127 lua_getfield(
ailState, -1,
"think");
2128 if (lua_pcall(
ailState, 0, 0, 0)) {
2129 gi.DPrintf(
"Error while running Lua: %s\n",
2130 lua_isstring(
ailState, -1) ? lua_tostring(
ailState, -1) :
"Unknown Error");
2133 gi.DPrintf(
"Error while running Lua: AI for %s not found!\n", actor->
AI.
type);
2172 bool thinkAgain =
false;
2176 lua_getfield(
ailState, -1,
"team_think");
2177 if (lua_pcall(
ailState, 0, 1, 0)) {
2178 gi.DPrintf(
"Error while running Lua: %s\n",
2179 lua_isstring(
ailState, -1) ? lua_tostring(
ailState, -1) :
"Unknown Error");
2181 thinkAgain = lua_toboolean(
ailState, -1);
2183 gi.DPrintf(
"Error while running Lua: AI for %s not found!\n",
AIL_toTeamString(player.getTeam()));
2197 lua_State* newState = luaL_newstate();
2204 lua_newtable(newState);
2205 lua_pushvalue(newState, -1);
2228 gi.DPrintf(
"Unable to create Lua state.\n");
2238 const int size =
gi.FS_LoadFile(path, (
byte**) &fbuf);
2240 gi.DPrintf(
"Unable to load Lua file '%s'.\n", path);
2244 gi.DPrintf(
"Unable to parse Lua file '%s'\n", path);
2245 gi.DPrintf(
"%s\n", lua_isstring(
ailState, -1) ? lua_tostring(
ailState, -1) :
"Unknown Error");
2246 gi.FS_FreeFile(fbuf);
2250 gi.FS_FreeFile(fbuf);
2263 gi.RegisterConstInt(
"luaaiteam::all",
TEAM_ALL);
2272 gi.RegisterConstInt(
"luaaisort::HP",
AILSC_HP);
2279 gi.RegisterConstInt(
"luaaishot::farthest",
AILSP_FAR);
2280 gi.RegisterConstInt(
"luaaishot::best_dam",
AILSP_DMG);
2283 gi.RegisterConstInt(
"luaaiwander::CW",
AILPW_CW);
2284 gi.RegisterConstInt(
"luaaiwander::CCW",
AILPW_CCW);
2291 gi.UnregisterConstVariable(
"luaaiteam::phalanx");
2292 gi.UnregisterConstVariable(
"luaaiteam::civilian");
2293 gi.UnregisterConstVariable(
"luaaiteam::alien");
2294 gi.UnregisterConstVariable(
"luaaiteam::all");
2296 gi.UnregisterConstVariable(
"luaaivis::all");
2297 gi.UnregisterConstVariable(
"luaaivis::sight");
2298 gi.UnregisterConstVariable(
"luaaivis::team");
2299 gi.UnregisterConstVariable(
"luaaivis::extra");
2301 gi.UnregisterConstVariable(
"luaaisort::dist");
2302 gi.UnregisterConstVariable(
"luaaisort::path");
2303 gi.UnregisterConstVariable(
"luaaisort::HP");
2305 gi.UnregisterConstVariable(
"luaaidist::dist");
2306 gi.UnregisterConstVariable(
"luaaidist::path");
2308 gi.UnregisterConstVariable(
"luaaishot::fastest");
2309 gi.UnregisterConstVariable(
"luaaishot::nearest");
2310 gi.UnregisterConstVariable(
"luaaishot::farthest");
2311 gi.UnregisterConstVariable(
"luaaishot::best_dam");
2313 gi.UnregisterConstVariable(
"luaaiwander::rand");
2314 gi.UnregisterConstVariable(
"luaaiwander::CW");
2315 gi.UnregisterConstVariable(
"luaaiwander::CCW");
static int AIL_tusforshooting(lua_State *L)
Returns the min TUs the actor needs to fire.
static int AIL_squad(lua_State *L)
Returns a table with the actors in the current player's team.
static int actorL_team(lua_State *L)
Gets the actor's team.
static Player * AIL_player
#define ST_RIGHT
The right hand should be used for shooting.
static const luaL_Reg AIL_methods[]
const objDef_t * def(void) const
bool AI_HideNeeded(const Actor *actor)
Checks whether the given alien should try to hide because there are enemies close enough to shoot the...
Edict * G_EdictsGetNextInUse(Edict *lastEnt)
Iterate through the entities that are in use.
float AI_CalcShotDamage(Actor *actor, const Actor *target, const fireDef_t *fd, shoot_types_t shotType)
Calculate estimated damage per single shoot.
static int AIL_waypoints(lua_State *L)
Return the positions of the next waypoints.
#define VectorCopy(src, dest)
static int actorL_tostring(lua_State *L)
Pushes the actor as a string.
bool G_ClientGetWeaponFromInventory(Actor *actor)
Retrieve or collect a loaded weapon from any linked container for the actor's right hand...
static int actorL_shoot(lua_State *L)
Shoots the actor.
void AIL_ActorThink(Player &player, Actor *actor)
The think function for the ai controlled players.
#define AIL_invalidparameter(n)
static int actorL_isvalidtarget(lua_State *L)
Check if the actor is a valid target to attack.
#define VectorSet(v, x, y, z)
#define luaL_dobuffer(L, b, n, s)
Actor * G_EdictsGetNextLivingActor(Actor *lastEnt)
Iterate through the living actor entities.
void AI_TurnIntoDirection(Actor *actor, const pos3_t pos)
This function will turn the AI actor into the direction that is needed to walk to the given location...
QGL_EXTERN GLint GLenum type
bool AI_FighterCheckShoot(const Actor *actor, const Edict *check, const fireDef_t *fd, float dist)
Check whether the fighter should perform the shoot.
bool AI_FindHidingLocation(int team, Actor *actor, const pos3_t from, int tuLeft)
Tries to search a hiding spot.
static int AIL_see(lua_State *L)
Returns what the actor can see.
Artificial intelligence of a character.
static lua_State * ailState
Edict * G_GetEdictFromPos(const pos3_t pos, const entity_type_t type)
Searches an edict of the given type at the given grid location.
Artificial Intelligence functions.
static int AIL_positionshoot(lua_State *L)
Moves the actor into a position in which he can shoot his target.
static int AIL_reactionfire(lua_State *L)
Sets the actor's reaction fire mode.
static int AIL_grabweapon(lua_State *L)
Actor tries to grab a weapon from inventory.
static int AIL_positionapproach(lua_State *L)
Approach to a target actor.
static int AIL_positionflee(lua_State *L)
Return a position to flee to.
Misc utility functions for game module.
bool AI_CheckPosition(const Actor *const actor, const pos3_t pos)
Checks if the given position is safe to stand on.
const fireDef_t * getFiredefs() const
Returns the firedefinitions for a given weapon/ammo.
Item * getRightHandItem() const
void G_ClientStateChange(const Player &player, Actor *actor, int reqState, bool checkaction)
Changes the state of a player/soldier.
bool Com_sprintf(char *dest, size_t size, const char *fmt,...)
copies formatted string with buffer-size checking
static int actorL_register(lua_State *L)
Registers the actor metatable in the lua_State.
AiAreaSearch class, used to get an area of the map around a certain position for the AI to check poss...
const char *IMPORT * GetConstVariable(const char *space, int value)
void G_ClientMove(const Player &player, int visTeam, Actor *actor, const pos3_t to)
Generates the client events that are send over the netchannel to move an actor.
int AI_GetHidingTeam(const Edict *ent)
Returns the value for the vis check whenever an ai actor tries to hide. For aliens this is the invers...
bool G_ClientCanReload(Actor *actor, containerIndex_t containerID)
Returns true if actor can reload weapon.
static int AIL_findweapons(lua_State *L)
Returns a table of the positions of nearby usable weapons on the floor.
bool AI_FindMissionLocation(Actor *actor, const pos3_t to, int tus, int radius)
Try to go close to a mission edict.
static int actorL_morale(lua_State *L)
Gets the current morale of the actor onto the stack.
QGL_EXTERN GLsizei const GLvoid * data
static int actorL_TU(lua_State *L)
Gets the number of usable TU the actor has left.
#define GRID_WIDTH
absolute max - -GRID_WIDTH up tp +GRID_WIDTH
static int AIL_canreload(lua_State *L)
Checks to see if the actor can reload.
const teamDef_t * teamDef
static ailVisType_t AIL_toVisInt(lua_State *L, const int index)
Return visibility mode int representation from the string representation in the lua stack...
const objDef_t * ammoDef(void) const
Item * getLeftHandItem() const
ailShootPosType_t
Shooting position types.
inventory definition for our menus
bool isSameTeamAs(const Edict *other) const
const fireDef_t * getFastestFireDef() const
const byte dvleft[CORE_DIRECTIONS]
bool getNext(pos3_t pos)
Get next position in the search area.
float G_ActorVis(const Edict *ent, const Edict *check, bool full)
calculate how much check is "visible" by ent
static int AIL_roundsleft(lua_State *L)
Checks to see how many rounds the actor has left.
static int AIL_positionmission(lua_State *L)
Try to find a position nearby to the given position.
int AngleToDir(int angle)
Returns the index of array directionAngles[DIRECTIONS] whose value is the closest to angle...
static int AIL_positionherd(lua_State *L)
Determine the position where actor is closest to the target and with the target located between the a...
bool AIL_TeamThink(Player &player)
The team think function for the ai controlled players.
void Q_strncpyz(char *dest, const char *src, size_t destsize)
Safe strncpy that ensures a trailing zero.
bool AI_CheckLineOfFire(const Actor *shooter, const Edict *target, const fireDef_t *fd, int shots)
static int AIL_missiontargets(lua_State *L)
Returns the positions of the available mission targets.
const objDef_t * onlyWeapon
static int actorL_HP(lua_State *L)
Gets the number of HP the actor has left.
#define PosSubDV(p, crouch, dv)
static aiActor_t * lua_pushactor(lua_State *L, aiActor_t *actor)
Pushes a actor as a metatable at the top of the stack.
int32_t shoot_types_t
Available shoot types - also see the ST_ constants.
QGL_EXTERN GLuint GLsizei GLsizei * length
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 pos3L_face(lua_State *L)
Makes the actor face the position.
static int AIL_toTeamInt(const char *team, const int param)
Converts team string into int representation.
#define ST_LEFT
The left hand should be used for shooting.
static const char * AIL_GetAIType(const int team)
Return the AI type for the given team (the lua file the team actors should run)
All parts of the main game logic that are combat related.
const invDef_t * AI_SearchGrenade(const Actor *actor, Item **ip)
Search the edict's inventory for a grenade or other one-use weapon.
int G_ActorGetModifiedTimeForFiredef(const Edict *const ent, const fireDef_t *const fd, const bool reaction)
static ailSortCritType_t AIL_toDistInt(lua_State *L, const int index)
Return distance type int representation from the string representation in the lua stack...
bool isHeldTwoHanded() const
static int AIL_weapontype(lua_State *L)
Returns the type of the weapons in the actors hands.
#define PosToVec(p, v)
Pos boundary size is +/- 128 - to get into the positive area we add the possible max negative value a...
static aiActor_t * lua_toactor(lua_State *L, int index)
Returns the actor from the metatable at index.
static int actorL_pos(lua_State *L)
Gets the actors position.
static int AIL_hideneeded(lua_State *L)
Check if the actor needs wants to hide.
item instance data, with linked list capability
pos_t G_ActorMoveLength(const Actor *actor, const pathing_t *path, const pos3_t to, bool stored)
Return the needed TUs to walk to a given position.
static pos3_t * lua_pushpos3(lua_State *L, pos3_t *pos)
Pushes a pos3 as a metatable at the top of the stack.
bool AI_IsHostile(const Actor *actor, const Edict *target)
Check if actor perceives target as hostile.
#define INVDEF(containerID)
static int AIL_positionwander(lua_State *L)
Return a new position to move to.
bool G_ActorInvMove(Actor *actor, const invDef_t *fromContType, Item *fItem, const invDef_t *toContType, int tx, int ty, bool checkaction)
Moves an item inside an inventory. Floors are handled special.
ailSortCritType_t
target sorting criteria (lowest first)
static int pos3L_distance(lua_State *L)
Return the distance the position an the AI actor.
static int AIL_class(lua_State *L)
Returns the AI actor's class.
int G_CheckVisTeamAll(const int team, const vischeckflags_t visFlags, const Edict *ent)
Do G_CheckVisTeam for all entities ent is the one that is looking at the others.
bool G_FindPath(int team, const Edict *movingActor, const pos3_t from, const pos3_t targetPos, bool crouched, int maxTUs)
static ailSortCritType_t AIL_toSortInt(lua_State *L, const int index)
Return sort type int representation from the string representation in the lua stack.
int G_TestVis(const int team, Edict *check, const vischeckflags_t flags)
test if check is visible by team (or if visibility changed?)
#define PATHFINDING_HEIGHT
15 max, adjusting above 8 will require a rewrite to the DV code
static int AIL_print(lua_State *L)
Works more or less like Lua's builtin print.
bool G_IsActorWounded(const Edict *ent, bool serious)
static int pos3L_goto(lua_State *L)
Makes the actor head to the position.
void calcOrigin()
Calculate the edict's origin vector from it's grid position.
bool G_ClientShoot(const Player &player, Actor *actor, const pos3_t at, shoot_types_t shootType, fireDefIndex_t firemode, shot_mock_t *mock, bool allowReaction, int z_align)
Setup for shooting, either real or mock.
Actor * G_EdictsGetNextLivingActorOfTeam(Actor *lastEnt, const int team)
Iterate through the living actor entities of the given team.
const byte dvright[CORE_DIRECTIONS]
bool AI_FindHerdLocation(Actor *actor, const pos3_t from, const vec3_t target, int tu, bool inverse)
Tries to search a spot where actor will be more closer to the target and behind the target from enemy...
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...
Actor * G_EdictsGetNextActor(Actor *lastEnt)
Iterate through the actor entities (even the dead!)
Local definitions for game module.
weaponFireDefIndex_t weapFdsIdx
static int AIL_reload(lua_State *L)
Actor reloads his weapons.
static int AIL_difficulty(lua_State *L)
Return the difficulty number (in case we want different AI for different ones)
static int AIL_actor(lua_State *L)
Returns the currently moving AI actor.
fireDefIndex_t numFiredefs[MAX_WEAPONS_PER_OBJDEF]
functions to handle the storage and lifecycle of all edicts in the game module.
bool G_Vis(const int team, const Edict *from, const Edict *check, const vischeckflags_t flags)
test if check is visible by from
bool AI_TryToReloadWeapon(Actor *actor, containerIndex_t containerID)
if a weapon can be reloaded we attempt to do so if TUs permit, otherwise drop it
bool isSamePosAs(const pos3_t cmpPos)
Check whether the edict is on the given position.
static lua_State * AIL_InitLua()
static int pos3L_register(lua_State *L)
Registers the pos3 metatable in the lua_State.
int getUsableTUs() const
Calculates the amount of usable TUs. This is without the reserved TUs.
const Item * AI_GetItemForShootType(shoot_types_t shootType, const Edict *ent)
this is a fire definition for our weapons/ammo
static const luaL_Reg pos3L_methods[]
static ailWanderPosType AIL_toWanderPInt(lua_State *L, const int index)
Return wander position type int representation from the string representation in the lua stack...
#define G_IsVisibleForTeam(ent, team)
static int lua_isactor(lua_State *L, int index)
Checks to see if there is a actor metatable at index in the lua_State.
void AIL_Cleanup(void)
Closes the LUA AI.
static int lua_ispos3(lua_State *L, int index)
Checks to see if there is a pos3 metatable at index in the lua_State.
ailVisType_t
vis check types
#define ROUTING_UNREACHABLE
void G_MoveCalc(int team, const Actor *movingActor, const pos3_t from, int distance)
Precalculates a move table for a given team and a given starting position. This will calculate a rout...
static int AIL_crouch(lua_State *L)
Requests a crouch state (with true/false) and returns current crouch state.
bool G_TestLineWithEnts(const vec3_t start, const vec3_t end)
fast version of a line trace including entities
#define ST_NUM_SHOOT_TYPES
Amount of shoottypes available.
static int AIL_positionhide(lua_State *L)
Moves the actor into a position in which he can hide.
static pos3_t * lua_topos3(lua_State *L, int index)
Returns the pos3 from the metatable at index.
static const char * AIL_toTeamString(const int team)
Converts integer team representation into string.
static int pos3L_tostring(lua_State *L)
Puts the pos3 information in a string.
int AIL_InitActor(Actor *actor)
Initializes the lua AI for an actor.
#define ROUTING_NOT_REACHABLE
static int AIL_isfighter(lua_State *L)
Whether the current AI actor is a fighter or not.
void setOrigin(const pos3_t newPos)
Set the edict's pos and origin vector to the given grid position.
static int actorL_isarmed(lua_State *L)
Check if actor has weapons.
#define VectorDistSqr(a, b)
static int actorL_isinjured(lua_State *L)
Checks to see if the actor is seriously injured.
#define VectorSubtract(a, b, dest)
static int AIL_setwaypoint(lua_State *L)
Mark the current waypoint for a civ.
int G_VisCheckDist(const Edict *const ent)
static int actorL_throwgrenade(lua_State *L)
Throws a grenade to the actor.
Interface for g_client.cpp.
static int actorL_isdead(lua_State *L)
Check if the actor is dead.
static const luaL_Reg actorL_methods[]
static int AIL_select(lua_State *L)
Select an specific AI actor.