51#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM < 504
52LUALIB_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"
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__)
112 const char* teamStr =
gi.GetConstVariable(
"luaaiteam", team);
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))
226typedef struct aiActor_s {
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;
369static 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);
541 int tu =
AIL_ent->getUsableTUs();
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));
613 int tus =
AIL_ent->getUsableTUs();
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);
934 gi.MoveStore(
level.pathingMap);
943 if (
AIL_ent->isSamePosAs(*pos))
950 lua_pushboolean(L,
AIL_ent->isSamePosAs(*pos));
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))) {
1167 move =
gi.MoveLength(
level.pathingMap, check->
pos, 0,
false);
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);
1206 const bool state =
AIL_ent->isCrouched();
1207 if (reqState != state)
1213 lua_pushboolean(L,
AIL_ent->isCrouched());
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) {
1238 lua_pushboolean(L,
AIL_ent->isReaction());
1248 const Item* rightHand =
AIL_ent->getRightHandItem();
1256 const Item* leftHand =
AIL_ent->getLeftHandItem();
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);
1369 gi.MoveStore(
level.pathingMap);
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] ==
'~') {
1468 int tus =
AIL_ent->getUsableTUs();
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);
1509 int tus =
AIL_ent->getUsableTUs();
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);
1553 int tus =
AIL_ent->getUsableTUs();
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);
1573 byte crouchingState =
AIL_ent->isCrouched() ? 1 : 0;
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))) {
1659 move =
gi.MoveLength(
level.pathingMap, mission->
pos, 0,
false);
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))
1707 for (
Edict* checkPoint =
level.ai_waypointList; checkPoint !=
nullptr; checkPoint = checkPoint->groupChain) {
1708 if (checkPoint->inuse)
1710 if (checkPoint->getTeam() !=
AIL_ent->getTeam())
1713 Actor* check =
nullptr;
1714 bool ambush =
false;
1718 if (dist < minEnemyDist) {
1730 move =
gi.MoveLength(
level.pathingMap, checkPoint->pos, 0,
false);
1733 if (checkPoint->count <
AIL_ent->count) {
1735 sortTable[++n].
data = checkPoint;
1745 if (checkPoint->count <
AIL_ent->count) {
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);
1780 int tus =
AIL_ent->getUsableTUs();
1781 if (lua_gettop(L) > 1) {
1782 if (lua_isnumber(L, 2))
1783 tus = lua_tonumber(L, 2);
1788 gi.MoveStore(
level.pathingMap);
1795 radius = mission->
radius;
1799 lua_pushboolean(L, 0);
1813 gi.MoveStore(
level.pathingMap);
1820 int tus =
AIL_ent->getUsableTUs();
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.0f, 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);
1947 const bool result =
AIL_ent->chr.teamDef->weapons ||
AIL_ent->chr.teamDef->onlyWeapon;
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);
1990 int tus =
AIL_ent->getUsableTUs();
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.0f)
2019 minDistFriend = dist;
2021 if (dist < minDistFoe || minDistFoe < 0.0f)
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");
2081 weapon =
AIL_ent->getLeftHandItem();
2091 lua_pushnumber(L, bestTUs);
2100 lua_pushstring(L,
AIL_ent->AI.subtype);
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");
#define INVDEF(containerID)
int getUsableTUs() const
Calculates the amount of usable TUs. This is without the reserved TUs.
AiAreaSearch class, used to get an area of the map around a certain position for the AI to check poss...
bool getNext(pos3_t pos)
Get next position in the search area.
bool isSameTeamAs(const Edict *other) const
Item * getRightHandItem() const
void setOrigin(const pos3_t newPos)
Set the edict's pos and origin vector to the given grid position.
Item * getLeftHandItem() const
item instance data, with linked list capability
const objDef_t * ammoDef(void) const
const fireDef_t * getFastestFireDef() const
const objDef_t * def(void) const
const fireDef_t * getFiredefs() const
Returns the firedefinitions for a given weapon/ammo.
bool isHeldTwoHanded() const
#define ROUTING_NOT_REACHABLE
#define GRID_WIDTH
absolute max - -GRID_WIDTH up tp +GRID_WIDTH
#define ROUTING_UNREACHABLE
#define PATHFINDING_HEIGHT
15 max, adjusting above 8 will require a rewrite to the DV code
int G_ActorGetModifiedTimeForFiredef(const Edict *const ent, const fireDef_t *const fd, const bool reaction)
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.
bool AI_FindMissionLocation(Actor *actor, const pos3_t to, int tus, int radius)
Try to go close to a mission edict.
bool AI_CheckLineOfFire(const Actor *shooter, const Edict *target, const fireDef_t *fd, int shots)
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
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.
bool AI_HideNeeded(const Actor *actor)
Checks whether the given alien should try to hide because there are enemies close enough to shoot the...
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...
bool AI_CheckPosition(const Actor *const actor, const pos3_t pos)
Checks if the given position is safe to stand on.
const Item * AI_GetItemForShootType(shoot_types_t shootType, const Edict *ent)
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...
float AI_CalcShotDamage(Actor *actor, const Actor *target, const fireDef_t *fd, shoot_types_t shotType)
Calculate estimated damage per single shoot.
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.
bool AI_IsHostile(const Actor *actor, const Edict *target)
Check if actor perceives target as hostile.
const invDef_t * AI_SearchGrenade(const Actor *actor, Item **ip)
Search the edict's inventory for a grenade or other one-use weapon.
Artificial Intelligence functions.
static int AIL_class(lua_State *L)
Returns the AI actor's class.
static ailWanderPosType AIL_toWanderPInt(lua_State *L, const int index)
Return wander position type int representation from the string representation in the lua stack.
static int AIL_toTeamInt(const char *team, const int param)
Converts team string into int representation.
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 operator<(AilSortTable< T > i, AilSortTable< T > j)
static int AIL_positionhide(lua_State *L)
Moves the actor into a position in which he can hide.
static int AIL_setwaypoint(lua_State *L)
Mark the current waypoint for a civ.
static int actorL_isinjured(lua_State *L)
Checks to see if the actor is seriously injured.
static int AIL_reload(lua_State *L)
Actor reloads his weapons.
static lua_State * AIL_InitLua()
ailSortCritType_t
target sorting criteria (lowest first)
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 int AIL_reactionfire(lua_State *L)
Sets the actor's reaction fire mode.
static int actorL_pos(lua_State *L)
Gets the actors position.
static int AIL_roundsleft(lua_State *L)
Checks to see how many rounds the actor has left.
#define luaL_dobuffer(L, b, n, s)
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...
#define AIL_invalidparameter(n)
static int actorL_morale(lua_State *L)
Gets the current morale of the actor onto the stack.
static int AIL_missiontargets(lua_State *L)
Returns the positions of the available mission targets.
static int AIL_grabweapon(lua_State *L)
Actor tries to grab a weapon from inventory.
static int AIL_actor(lua_State *L)
Returns the currently moving AI actor.
static int actorL_HP(lua_State *L)
Gets the number of HP the actor has left.
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
static const luaL_Reg AIL_methods[]
static ailVisType_t AIL_toVisInt(lua_State *L, const int index)
Return visibility mode int representation from the string representation in the lua stack.
int AIL_InitActor(Actor *actor)
Initializes the lua AI for an actor.
static int actorL_isdead(lua_State *L)
Check if the actor is dead.
static int AIL_positionapproach(lua_State *L)
Approach to a target actor.
static int actorL_isvalidtarget(lua_State *L)
Check if the actor is a valid target to attack.
static int pos3L_goto(lua_State *L)
Makes the actor head to the position.
static int AIL_hideneeded(lua_State *L)
Check if the actor needs wants to hide.
static int AIL_difficulty(lua_State *L)
Return the difficulty number (in case we want different AI for different ones).
static const char * AIL_toTeamString(const int team)
Converts integer team representation into string.
static const luaL_Reg actorL_methods[]
static const luaL_Reg pos3L_methods[]
static int AIL_findweapons(lua_State *L)
Returns a table of the positions of nearby usable weapons on the floor.
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 int AIL_positionshoot(lua_State *L)
Moves the actor into a position in which he can shoot his target.
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 actorL_shoot(lua_State *L)
Shoots the actor.
static int actorL_register(lua_State *L)
Registers the actor metatable in the lua_State.
static int AIL_weapontype(lua_State *L)
Returns the type of the weapons in the actors hands.
void AIL_Cleanup(void)
Closes the LUA AI.
static int pos3L_register(lua_State *L)
Registers the pos3 metatable in the lua_State.
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 int AIL_select(lua_State *L)
Select an specific AI actor.
static int AIL_tusforshooting(lua_State *L)
Returns the min TUs the actor needs to fire.
static int AIL_print(lua_State *L)
Works more or less like Lua's builtin print.
static int AIL_positionflee(lua_State *L)
Return a position to flee to.
static int actorL_team(lua_State *L)
Gets the actor's team.
static int AIL_crouch(lua_State *L)
Requests a crouch state (with true/false) and returns current crouch state.
static const char * AIL_GetAIType(const int team)
Return the AI type for the given team (the lua file the team actors should run).
static int AIL_see(lua_State *L)
Returns what the actor can see.
bool AIL_TeamThink(Player &player)
The team think function for the ai controlled players.
static int actorL_throwgrenade(lua_State *L)
Throws a grenade to the actor.
static int AIL_waypoints(lua_State *L)
Return the positions of the next waypoints.
static int pos3L_distance(lua_State *L)
Return the distance the position an the AI actor.
static int pos3L_face(lua_State *L)
Makes the actor face the position.
static int AIL_squad(lua_State *L)
Returns a table with the actors in the current player's team.
static int actorL_tostring(lua_State *L)
Pushes the actor as a string.
static pos3_t * lua_topos3(lua_State *L, int index)
Returns the pos3 from the metatable at index.
static int actorL_TU(lua_State *L)
Gets the number of usable TU the actor has left.
static int AIL_positionwander(lua_State *L)
Return a new position to move to.
static Player * AIL_player
static int pos3L_tostring(lua_State *L)
Puts the pos3 information in a string.
static aiActor_t * lua_toactor(lua_State *L, int index)
Returns the actor from the metatable at index.
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 AIL_canreload(lua_State *L)
Checks to see if the actor can reload.
ailShootPosType_t
Shooting position types.
static int AIL_positionmission(lua_State *L)
Try to find a position nearby to the given position.
void AIL_ActorThink(Player &player, Actor *actor)
The think function for the ai controlled players.
static int actorL_isarmed(lua_State *L)
Check if actor has weapons.
static aiActor_t * lua_pushactor(lua_State *L, aiActor_t *actor)
Pushes a actor as a metatable at the top of the stack.
static lua_State * ailState
static int AIL_isfighter(lua_State *L)
Whether the current AI actor is a fighter or not.
void G_ClientStateChange(const Player &player, Actor *actor, int reqState, bool checkaction)
Changes the state of a player/soldier.
bool G_ClientCanReload(Actor *actor, containerIndex_t containerID)
Returns true if actor can reload weapon.
bool G_ClientGetWeaponFromInventory(Actor *actor)
Retrieve or collect a loaded weapon from any linked container for the actor's right hand.
Interface for g_client.cpp.
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.
All parts of the main game logic that are combat related.
Actor * G_EdictsGetNextLivingActorOfTeam(Actor *lastEnt, const int team)
Iterate through the living actor entities of the given team.
Actor * G_EdictsGetNextActor(Actor *lastEnt)
Iterate through the actor entities (even the dead!).
Actor * G_EdictsGetNextLivingActor(Actor *lastEnt)
Iterate through the living actor entities.
Edict * G_EdictsGetNextInUse(Edict *lastEnt)
Iterate through the entities that are in use.
functions to handle the storage and lifecycle of all edicts in the game module.
bool G_IsActorWounded(const Edict *ent, bool serious)
Local definitions for game module.
#define G_IsVisibleForTeam(ent, team)
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.
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.
bool G_FindPath(int team, const Edict *movingActor, const pos3_t from, const pos3_t targetPos, bool crouched, int maxTUs)
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...
Edict * G_GetEdictFromPos(const pos3_t pos, const entity_type_t type)
Searches an edict of the given type at the given grid location.
bool G_TestLineWithEnts(const vec3_t start, const vec3_t end)
fast version of a line trace including entities
Misc utility functions for game module.
int G_TestVis(const int team, Edict *check, const vischeckflags_t flags)
test if check is visible by team (or if visibility changed?)
int G_VisCheckDist(const Edict *const ent)
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_Vis(const int team, const Edict *from, const Edict *check, const vischeckflags_t flags)
test if check is visible by from
float G_ActorVis(const Edict *ent, const Edict *check, bool full)
calculate how much check is "visible" by ent
const byte dvleft[CORE_DIRECTIONS]
const byte dvright[CORE_DIRECTIONS]
int AngleToDir(int angle)
Returns the index of array directionAngles[DIRECTIONS] whose value is the closest to angle.
#define PosSubDV(p, crouch, dv)
#define PosToVec(p, v)
Pos boundary size is +/- 128 - to get into the positive area we add the possible max negative value a...
#define ST_NUM_SHOOT_TYPES
Amount of shoottypes available.
int32_t shoot_types_t
Available shoot types - also see the ST_ constants.
#define ST_RIGHT
The right hand should be used for shooting.
#define ST_LEFT
The left hand should be used for shooting.
QGL_EXTERN GLsizei const GLvoid * data
QGL_EXTERN GLuint GLsizei GLsizei * length
QGL_EXTERN GLint GLenum type
void Q_strncpyz(char *dest, const char *src, size_t destsize)
Safe strncpy that ensures a trailing zero.
bool Com_sprintf(char *dest, size_t size, const char *fmt,...)
copies formatted string with buffer-size checking
Artificial intelligence of a character.
const teamDef_t * teamDef
this is a fire definition for our weapons/ammo
weaponFireDefIndex_t weapFdsIdx
inventory definition for our menus
#define VectorSubtract(a, b, dest)
#define VectorCopy(src, dest)
#define VectorDistSqr(a, b)
#define VectorSet(v, x, y, z)