From 5eb7f093467963deafd805faba61fb52e684b980 Mon Sep 17 00:00:00 2001 From: Lactozilla Date: Sun, 6 Aug 2023 23:51:52 -0300 Subject: [PATCH] Add P_PlayerHasTeamFlag --- src/lua_baselib.c | 37 ++++++++++++++++++++++++------------- src/lua_infolib.c | 8 ++++---- src/p_local.h | 1 + src/p_user.c | 8 ++++++++ 4 files changed, 37 insertions(+), 17 deletions(-) diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 2fedd3723..7f9afefd9 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -845,7 +845,6 @@ static int lib_pGetMobjGravity(lua_State *L) static int lib_pWeaponOrPanel(lua_State *L) { mobjtype_t type = luaL_checkinteger(L, 1); - //HUDSAFE if (type >= NUMMOBJTYPES) return luaL_error(L, "mobj type %d out of range (0 - %d)", type, NUMMOBJTYPES-1); lua_pushboolean(L, P_WeaponOrPanel(type)); @@ -855,9 +854,8 @@ static int lib_pWeaponOrPanel(lua_State *L) static int lib_pGetTeamFlag(lua_State *L) { int team = luaL_checkinteger(L, 1); - if (team < 0 || team >= numteams) - return luaL_error(L, "team index %d out of range (0 - %d)", team, numteams - 1); - NOHUD + if (team <= 0 || team >= numteams) + return luaL_error(L, "team index %d out of range (1 - %d)", team, numteams - 1); INLEVEL LUA_PushUserdata(L, P_GetTeamFlag(team), META_MOBJ); return 1; @@ -866,9 +864,8 @@ static int lib_pGetTeamFlag(lua_State *L) static int lib_pGetTeamFlagMapthing(lua_State *L) { int team = luaL_checkinteger(L, 1); - if (team < 0 || team >= numteams) - return luaL_error(L, "team index %d out of range (0 - %d)", team, numteams - 1); - NOHUD + if (team <= 0 || team >= numteams) + return luaL_error(L, "team index %d out of range (1 - %d)", team, numteams - 1); INLEVEL LUA_PushUserdata(L, P_GetTeamFlagMapthing(team), META_MAPTHING); return 1; @@ -1762,6 +1759,19 @@ static int lib_pPlayerShouldUseSpinHeight(lua_State *L) return 1; } +static int lib_pPlayerHasTeamFlag(lua_State *L) +{ + player_t *player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); + INT32 team = (INT32)luaL_checkinteger(L, 2); + INLEVEL + if (!player) + return LUA_ErrInvalid(L, "player_t"); + if (team <= 0 || team >= numteams) + luaL_error(L, "team index %d out of range (1 - %d)", team, numteams-1); + lua_pushboolean(L, P_PlayerHasTeamFlag(player, team)); + return 1; +} + // P_MAP /////////// @@ -2347,8 +2357,8 @@ static int lib_pMobjTouchingTeamBase(lua_State *L) INLEVEL if (!mo) return LUA_ErrInvalid(L, "mobj_t"); - if (team <= 0 || team >= teamsingame) - luaL_error(L, "team index %d out of range (1 - %d)", team, teamsingame-1); + if (team <= 0 || team >= numteams) + luaL_error(L, "team index %d out of range (1 - %d)", team, numteams-1); LUA_PushUserdata(L, P_MobjTouchingTeamBase(mo, team), META_SECTOR); return 1; } @@ -2514,8 +2524,8 @@ static int lib_pTeamHasFlagAtBase(lua_State *L) { INT32 team = luaL_checkinteger(L, 1); INLEVEL - if (team <= 0 || team >= teamsingame) - luaL_error(L, "team index %d out of range (1 - %d)", team, teamsingame-1); + if (team <= 0 || team >= numteams) + luaL_error(L, "team index %d out of range (1 - %d)", team, numteams-1); lua_pushboolean(L, P_TeamHasFlagAtBase(team)); return 1; } @@ -3554,8 +3564,8 @@ static int lib_gAddGametype(lua_State *L) if (idx >= 0 && idx < MAXTEAMS) { int team_index = luaL_checkinteger(L, -1); - if (team_index < 0 || team_index >= numteams) - luaL_error(L, "team index %d out of range (0 - %d)", team_index, numteams-1); + if (team_index <= 0 || team_index >= numteams) + luaL_error(L, "team index %d out of range (1 - %d)", team_index, numteams-1); teamlist[idx] = (UINT8)team_index; @@ -4265,6 +4275,7 @@ static luaL_Reg lib[] = { {"P_SwitchShield",lib_pSwitchShield}, {"P_PlayerCanEnterSpinGaps",lib_pPlayerCanEnterSpinGaps}, {"P_PlayerShouldUseSpinHeight",lib_pPlayerShouldUseSpinHeight}, + {"P_PlayerHasTeamFlag",lib_pPlayerHasTeamFlag}, // p_map {"P_CheckPosition",lib_pCheckPosition}, diff --git a/src/lua_infolib.c b/src/lua_infolib.c index d8b6c6d86..22f9a2218 100644 --- a/src/lua_infolib.c +++ b/src/lua_infolib.c @@ -2043,8 +2043,8 @@ static int gametype_set(lua_State *L) if (i >= 0 && i < MAXTEAMS) { int team_index = luaL_checkinteger(L, -1); - if (team_index < 0 || team_index >= numteams) - luaL_error(L, "team index %d out of range (0 - %d)", team_index, numteams-1); + if (team_index <= 0 || team_index >= numteams) + luaL_error(L, "team index %d out of range (1 - %d)", team_index, numteams-1); gt->teams.list[i] = (UINT8)team_index; @@ -2415,8 +2415,8 @@ static int teamlist_set(lua_State *L) int team = luaL_checkinteger(L, 3); if (i <= 0 || i > teamlist->num) return luaL_error(L, "array index %d out of range (1 - %d)", i, teamlist->num); - if (team < 0 || team >= numteams) - return luaL_error(L, "team index %d out of range (0 - %d)", team, numteams - 1); + if (team <= 0 || team >= numteams) + return luaL_error(L, "team index %d out of range (1 - %d)", team, numteams - 1); teamlist->list[i - 1] = (UINT8)team; return 0; } diff --git a/src/p_local.h b/src/p_local.h index 3e1c162ce..3bc35e50d 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -146,6 +146,7 @@ void P_ForceLocalAngle(player_t *player, angle_t angle); boolean P_PlayerFullbright(player_t *player); boolean P_PlayerCanEnterSpinGaps(player_t *player); boolean P_PlayerShouldUseSpinHeight(player_t *player); +boolean P_PlayerHasTeamFlag(player_t *player, UINT8 team); boolean P_IsObjectInGoop(mobj_t *mo); boolean P_IsObjectOnGround(mobj_t *mo); diff --git a/src/p_user.c b/src/p_user.c index df5e2adf1..e92fb15f2 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -13086,3 +13086,11 @@ boolean P_PlayerShouldUseSpinHeight(player_t *player) && player->dashmode >= DASHMODE_THRESHOLD && player->mo->state-states == S_PLAY_DASH) || JUMPCURLED(player)); } + +boolean P_PlayerHasTeamFlag(player_t *player, UINT8 team) +{ + if (!G_GametypeHasTeams() || team >= numteams) + return false; + + return player->gotflag & teams[team].flag; +}