35#include "../shared/cxx.h"
51#define POS3_METATABLE "pos3"
52#define ACTOR_METATABLE "actor"
53#define AI_METATABLE "ai"
59#define luaL_dobuffer(L, b, n, s) \
60 (luaL_loadbuffer(L, b, n, s) || lua_pcall(L, 0, LUA_MULTRET, 0))
61#define AIL_invalidparameter(n) \
62 gi.DPrintf("AIL: Invalid parameter #%d in '%s'.\n", n, __func__)
105 if (teamStr ==
nullptr)
120 if (!
gi.GetConstIntFromNamespace(
"luaaiteam", team, &teamInt))
134 if (lua_isstring(L,
index)) {
135 const char* s = lua_tostring(L,
index);
136 if (!
gi.GetConstIntFromNamespace(
"luaaivis", s, &visInt))
152 if (lua_isstring(L,
index)) {
153 const char* s = lua_tostring(L,
index);
154 if (!
gi.GetConstIntFromNamespace(
"luaaisort", s, &sortInt))
170 if (lua_isstring(L,
index)) {
171 const char* s = lua_tostring(L,
index);
172 if (!
gi.GetConstIntFromNamespace(
"luaaidist", s, &distInt))
188 if (lua_isstring(L,
index)) {
189 const char* s = lua_tostring(L,
index);
190 if (!
gi.GetConstIntFromNamespace(
"luaaishot", s, &spInt))
206 if (lua_isstring(L,
index)) {
207 const char* s = lua_tostring(L,
index);
208 if (!
gi.GetConstIntFromNamespace(
"luaaiwander", s, &wpInt))
218typedef struct aiActor_s {
243 int shotChecked =
NONE;
244 float bestDmg = 0.0f;
245 bestShots = bestType = bestFd =
NONE;
252 if (fdArray ==
nullptr)
259 const int shots = tu / time;
268 if (shotChecked != shotFlags) {
269 shotChecked = shotFlags;
280 bestType = shootType;
359static int AIL_see(lua_State* L);
436 lua_pushvalue(L, -1);
437 lua_setfield(L, -2,
"__index");
456 if (lua_getmetatable(L,
index) == 0)
461 if (lua_rawequal(L, -1, -2))
488 lua_setmetatable(L, -2);
504 lua_pushstring(L,
buf);
532 if (lua_gettop(L) > 1) {
533 assert(lua_isnumber(L, 2));
535 tu = std::min(
static_cast<int>(lua_tonumber(L, 2)), tu);
545 if (bestType ==
NONE) {
546 lua_pushboolean(L, 0);
551 while (bestShots > 0) {
559 lua_pushboolean(L, shot);
571 assert(target !=
nullptr);
573 lua_pushstring(L, team);
585 lua_pushboolean(L, 0);
589 assert(target !=
nullptr);
593 if (lua_gettop(L) > 1) {
594 if (!lua_isnumber(L, 2)) {
596 lua_pushboolean(L, 0);
599 minNum =
static_cast<int>(lua_tonumber(L, 2));
604 if (lua_gettop(L) > 2) {
605 if (!lua_isnumber(L, 3)) {
607 lua_pushboolean(L, 0);
610 tus = std::min(
static_cast<int>(lua_tonumber(L, 3)), tus);
619 lua_pushboolean(L, 0);
624 Item* grenade =
nullptr;
626 if (!fromCont || !grenade) {
627 lua_pushboolean(L, 0);
632 const int invMoveCost = fromCont->
out +
INVDEF(hand)->in;
654 lua_pushboolean(L, 0);
660 Actor* check =
nullptr;
666 if (dist > bestFd->
splrad)
670 lua_pushboolean(L, 0);
677 lua_pushboolean(L, 0);
684 lua_pushboolean(L, 0);
690 lua_pushboolean(L, result);
702 lua_pushboolean(L, 0);
706 assert(actor !=
nullptr);
720 lua_pushboolean(L, 0);
724 assert(actor !=
nullptr);
726 lua_pushnumber(L, actor->
actor->
HP);
738 lua_pushboolean(L, 0);
742 assert(actor !=
nullptr);
744 const char* morStat =
"normal";
754 lua_pushstring(L, morStat);
766 lua_pushboolean(L, 0);
770 assert(actor !=
nullptr);
785 lua_pushboolean(L, 0);
789 assert(actor !=
nullptr);
804 lua_pushboolean(L, 0);
808 assert(actor !=
nullptr);
822 assert(target !=
nullptr);
843 lua_pushvalue(L, -1);
844 lua_setfield(L, -2,
"__index");
863 if (lua_getmetatable(L,
index) == 0)
868 if (lua_rawequal(L, -1, -2))
893 memcpy(p, pos,
sizeof(*p));
895 lua_setmetatable(L, -2);
909 Com_sprintf(
buf,
sizeof(
buf),
"Pos3( x=%d, y=%d, z=%d )", (*p)[0], (*p)[1], (*p)[2]);
911 lua_pushstring(L,
buf);
954 lua_pushboolean(L, 1);
966 assert(pos !=
nullptr);
969 if (lua_gettop(L) > 1)
1002 const int n = lua_gettop(L);
1004 for (
int i = 1;
i <= n;
i++) {
1008 lua_pushvalue(L,
i);
1009 if (luaL_callmeta(L, -1,
"__tostring")) {
1010 s = lua_tostring(L, -1);
1013 switch (lua_type(L, -1)) {
1016 s = lua_tostring(L, -1);
1019 s = lua_toboolean(L, -1) ?
"true" :
"false";
1026 s =
"unknown lua type";
1030 gi.DPrintf(
"%s%s", (
i > 1) ?
"\t" :
"", s);
1050 gi.DPrintf(
"Problem while running lua: attempt to get the player's team while not in team mode.");
1059 Actor* check =
nullptr;
1063 lua_pushnumber(L,
i++);
1065 target.
actor = check;
1078 gi.DPrintf(
"Problem while running lua: attempt to select the active AI actor while not in team mode.");
1080 }
else if (lua_gettop(L) > 0 &&
lua_isactor(L, 1)) {
1087 lua_pushboolean(L,
false);
1105 bool invTeam =
false;
1108 if ((lua_gettop(L) > 0)) {
1113 if ((lua_gettop(L) > 1)) {
1114 if (lua_isstring(L, 2)) {
1115 const char* s = lua_tostring(L, 2);
1116 if (s[0] ==
'-' || s[0] ==
'~') {
1129 if ((lua_gettop(L) > 2)) {
1135 Actor* check =
nullptr;
1147 if ((team ==
TEAM_ALL || (check->
getTeam() == team ? !invTeam : invTeam))
1151 || (vision ==
AILVT_DIST && distance <= visDist * visDist))) {
1169 sortTable[n++].
data = check;
1174 std::sort(sortTable, sortTable + n);
1178 for (
int i = 0;
i < n;
i++) {
1179 lua_pushnumber(L,
i + 1);
1193 if (lua_gettop(L) > 0) {
1194 if (lua_isboolean(L, 1)) {
1195 const bool reqState = lua_toboolean(L, 1);
1197 if (reqState != state)
1212 if (lua_gettop(L) > 0) {
1213 int reactionState = 0;
1215 if (lua_isstring(L, 1)) {
1217 const char* cmd = lua_tostring(L, 1);
1221 if (reactionState) {
1271 if (lua_gettop(L) > 0) {
1272 if (lua_isstring(L, 1)) {
1273 const char* s = lua_tostring(L, 1);
1277 }
else if (
Q_streq(s,
"left")) {
1316 if ((lua_gettop(L) > 1))
1321 if (lua_gettop(L) > 2) {
1322 assert(lua_isnumber(L, 3));
1324 tus = std::min(
static_cast<int>(lua_tonumber(L, 3)), tus);
1329 lua_pushboolean(L, 0);
1335 if (item ==
nullptr) {
1341 if (item ==
nullptr) {
1342 lua_pushboolean(L, 0);
1346 if (fd ==
nullptr) {
1347 lua_pushboolean(L, 0);
1352 if (tus - fdTime <= 0) {
1353 lua_pushboolean(L, 0);
1371 float bestScore = 0.0f;
1375 while (searchArea.
getNext(to)) {
1388 const float bestDmg =
AIL_GetBestShot(*actor, *target->
actor, tus - move, dist, dummy, dummy, dummy);
1419 lua_pushboolean(L, 0);
1438 if (lua_gettop(L)) {
1439 if (lua_isstring(L, 1)) {
1440 const char* s = lua_tostring(L, 1);
1441 bool invTeam =
false;
1442 if (s[0] ==
'-' || s[0] ==
'~') {
1460 if (lua_gettop(L) > 1) {
1461 if (lua_isnumber(L, 2)) {
1462 tus = std::min(
static_cast<int>(lua_tonumber(L, 2)), tus);
1475 lua_pushboolean(L, 0);
1494 lua_pushboolean(L, 0);
1501 if (lua_gettop(L) > 1) {
1502 if (lua_isnumber(L, 2)) {
1503 tus = std::min(
static_cast<int>(lua_tonumber(L, 2)), tus);
1509 bool inverse =
false;
1510 if (lua_gettop(L) > 2) {
1511 if (lua_isboolean(L, 3))
1512 inverse = lua_toboolean(L, 3);
1522 lua_pushboolean(L, 0);
1536 lua_pushboolean(L, 0);
1541 assert(target !=
nullptr);
1544 if (lua_gettop(L) > 1) {
1545 if (lua_isnumber(L, 2))
1546 tus = std::min(
static_cast<int>(lua_tonumber(L, 2)), tus);
1552 if (lua_gettop(L) > 2){
1553 if (lua_isboolean(L, 3))
1554 hide = lua_toboolean(L, 3);
1566 lua_pushboolean(L, 0);
1574 PosSubDV(to, crouchingState, dvec);
1586 lua_pushboolean(L, 0);
1602 bool invTeam =
false;
1605 if ((lua_gettop(L) > 0)) {
1610 if ((lua_gettop(L) > 1)) {
1611 if (lua_isstring(L, 2)) {
1612 const char* s = lua_tostring(L, 2);
1613 if (s[0] ==
'-' || s[0] ==
'~') {
1626 if ((lua_gettop(L) > 2))
1634 Edict* mission =
nullptr;
1640 if ((team ==
TEAM_ALL || (mission->
getTeam() == team ? !invTeam : invTeam))
1643 || (vision ==
AILVT_DIST && distance <= visDist * visDist))) {
1658 sortTable[n++].
data = mission;
1663 std::sort(sortTable, sortTable + n);
1667 for (
int i = 0;
i < n;
i++) {
1668 lua_pushnumber(L,
i + 1);
1680 const float minEnemyDist = 160.0f;
1682 float minDist = 800.0f;
1683 if (lua_gettop(L) > 0) {
1684 if (lua_isnumber(L, 1))
1685 minDist = lua_tonumber(L, 1);
1692 if ((lua_gettop(L) > 1))
1698 if (checkPoint->inuse)
1703 Actor* check =
nullptr;
1704 bool ambush =
false;
1708 if (dist < minEnemyDist) {
1725 sortTable[++n].
data = checkPoint;
1737 sortTable[++n].
data = checkPoint;
1745 std::sort(sortTable, sortTable + n);
1749 for (
int i = 0;
i < n;
i++) {
1750 lua_pushnumber(L,
i + 1);
1766 lua_pushboolean(L, 0);
1771 if (lua_gettop(L) > 1) {
1772 if (lua_isnumber(L, 2))
1773 tus = lua_tonumber(L, 2);
1785 radius = mission->
radius;
1789 lua_pushboolean(L, 0);
1813 if (lua_gettop(L) > 0)
1815 if (lua_gettop(L) > 1) {
1816 if (lua_isnumber(L, 2))
1817 radius = lua_tonumber(L, 2);
1821 if (lua_gettop(L) > 2) {
1828 if (lua_gettop(L) > 3) {
1829 if (lua_isnumber(L, 4))
1830 tus = std::min(
static_cast<int>(lua_tonumber(L, 4)), tus);
1839 float bestScore = 0;
1843 while (searchArea.
getNext(pos)) {
1860 for (
int n = 1; n < 8; ++n) {
1862 score /= pow(n * 2.0f, 2);
1863 if ((method == 1 && dir ==
dvright[cDir]) || (method == 2 && dir ==
dvleft[cDir]))
1869 if (score > bestScore) {
1876 lua_pushboolean(L, 0);
1889 if (lua_gettop(L) > 0) {
1890 if (lua_isboolean(L, 1))
1891 full = lua_toboolean(L, 1);
1898 Edict* check =
nullptr;
1910 if (item->isWeapon() && (item->getAmmoLeft() > 0 || item->def()->ammo <= 0)) {
1911 sortTable[n].
data = check;
1920 std::sort(sortTable, sortTable + n);
1924 for (
int i = 0;
i < n;
i++) {
1925 lua_pushnumber(L,
i + 1);
1938 lua_pushboolean(L, result);
1948 if (lua_gettop(L) < 1 || lua_isnil(L, 1)) {
1950 lua_pushboolean(L, 1);
1955 if (waypoint !=
nullptr) {
1957 lua_pushboolean(L, 1);
1959 lua_pushboolean(L, 0);
1961 lua_pushboolean(L, 0);
1981 if (lua_gettop(L)) {
1982 if (lua_isnumber(L, 1))
1983 tus = std::min(
static_cast<int>(lua_tonumber(L, 1)), tus);
1994 float bestScore = -1;
2003 float minDistFoe = -1.0f, minDistFriend = -1.0f;
2004 Actor* check =
nullptr;
2008 if (dist < minDistFriend || minDistFriend < 0.0f)
2009 minDistFriend = dist;
2011 if (dist < minDistFoe || minDistFoe < 0.0f)
2015 float score = minDistFoe - (minDistFriend /
GRID_WIDTH);
2020 if (score > bestScore) {
2028 lua_pushboolean(L, 0);
2044 lua_pushstring(L, right ? right->
def()->
type :
"none");
2045 lua_pushstring(L, left ? left->
def()->
type :
"none");
2081 lua_pushnumber(L, bestTUs);
2117 lua_getfield(
ailState, -1,
"think");
2118 if (lua_pcall(
ailState, 0, 0, 0)) {
2119 gi.DPrintf(
"Error while running Lua: %s\n",
2120 lua_isstring(
ailState, -1) ? lua_tostring(
ailState, -1) :
"Unknown Error");
2123 gi.DPrintf(
"Error while running Lua: AI for %s not found!\n", actor->
AI.
type);
2162 bool thinkAgain =
false;
2166 lua_getfield(
ailState, -1,
"team_think");
2167 if (lua_pcall(
ailState, 0, 1, 0)) {
2168 gi.DPrintf(
"Error while running Lua: %s\n",
2169 lua_isstring(
ailState, -1) ? lua_tostring(
ailState, -1) :
"Unknown Error");
2171 thinkAgain = lua_toboolean(
ailState, -1);
2173 gi.DPrintf(
"Error while running Lua: AI for %s not found!\n",
AIL_toTeamString(player.getTeam()));
2187 lua_State* newState = luaL_newstate();
2215 gi.DPrintf(
"Unable to create Lua state.\n");
2225 const int size =
gi.FS_LoadFile(path, (
byte**) &fbuf);
2227 gi.DPrintf(
"Unable to load Lua file '%s'.\n", path);
2231 gi.DPrintf(
"Unable to parse Lua file '%s'\n", path);
2232 gi.DPrintf(
"%s\n", lua_isstring(
ailState, -1) ? lua_tostring(
ailState, -1) :
"Unknown Error");
2233 gi.FS_FreeFile(fbuf);
2237 gi.FS_FreeFile(fbuf);
2250 gi.RegisterConstInt(
"luaaiteam::all",
TEAM_ALL);
2259 gi.RegisterConstInt(
"luaaisort::HP",
AILSC_HP);
2266 gi.RegisterConstInt(
"luaaishot::farthest",
AILSP_FAR);
2267 gi.RegisterConstInt(
"luaaishot::best_dam",
AILSP_DMG);
2270 gi.RegisterConstInt(
"luaaiwander::CW",
AILPW_CW);
2271 gi.RegisterConstInt(
"luaaiwander::CCW",
AILPW_CCW);
2278 gi.UnregisterConstVariable(
"luaaiteam::phalanx");
2279 gi.UnregisterConstVariable(
"luaaiteam::civilian");
2280 gi.UnregisterConstVariable(
"luaaiteam::alien");
2281 gi.UnregisterConstVariable(
"luaaiteam::all");
2283 gi.UnregisterConstVariable(
"luaaivis::all");
2284 gi.UnregisterConstVariable(
"luaaivis::sight");
2285 gi.UnregisterConstVariable(
"luaaivis::team");
2286 gi.UnregisterConstVariable(
"luaaivis::extra");
2288 gi.UnregisterConstVariable(
"luaaisort::dist");
2289 gi.UnregisterConstVariable(
"luaaisort::path");
2290 gi.UnregisterConstVariable(
"luaaisort::HP");
2292 gi.UnregisterConstVariable(
"luaaidist::dist");
2293 gi.UnregisterConstVariable(
"luaaidist::path");
2295 gi.UnregisterConstVariable(
"luaaishot::fastest");
2296 gi.UnregisterConstVariable(
"luaaishot::nearest");
2297 gi.UnregisterConstVariable(
"luaaishot::farthest");
2298 gi.UnregisterConstVariable(
"luaaishot::best_dam");
2300 gi.UnregisterConstVariable(
"luaaiwander::rand");
2301 gi.UnregisterConstVariable(
"luaaiwander::CW");
2302 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
void calcOrigin()
Calculate the edict's origin vector from it's grid position.
bool isSamePosAs(const pos3_t cmpPos)
Check whether the edict is on the given position.
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 const luaL_reg pos3L_methods[]
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 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 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 const luaL_reg AIL_methods[]
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 const luaL_reg actorL_methods[]
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
const char *IMPORT * GetConstVariable(const char *space, int value)
inventory definition for our menus
const objDef_t * onlyWeapon
#define VectorSubtract(a, b, dest)
#define VectorCopy(src, dest)
#define VectorDistSqr(a, b)
#define VectorSet(v, x, y, z)