Add P_GetTeamFlag and P_GetTeamFlagMapthing

This commit is contained in:
Lactozilla 2023-08-06 00:56:40 -03:00
parent 313f224311
commit 87e18d410c
8 changed files with 60 additions and 14 deletions

View file

@ -852,6 +852,28 @@ static int lib_pWeaponOrPanel(lua_State *L)
return 1; return 1;
} }
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
INLEVEL
LUA_PushUserdata(L, P_GetTeamFlag(team), META_MOBJ);
return 1;
}
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
INLEVEL
LUA_PushUserdata(L, P_GetTeamFlagMapthing(team), META_MAPTHING);
return 1;
}
static int lib_pFlashPal(lua_State *L) static int lib_pFlashPal(lua_State *L)
{ {
player_t *pl = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); player_t *pl = *((player_t **)luaL_checkudata(L, 1, META_PLAYER));
@ -4114,6 +4136,8 @@ static luaL_Reg lib[] = {
{"P_MobjFlip",lib_pMobjFlip}, {"P_MobjFlip",lib_pMobjFlip},
{"P_GetMobjGravity",lib_pGetMobjGravity}, {"P_GetMobjGravity",lib_pGetMobjGravity},
{"P_WeaponOrPanel",lib_pWeaponOrPanel}, {"P_WeaponOrPanel",lib_pWeaponOrPanel},
{"P_GetTeamFlag",lib_pGetTeamFlag},
{"P_GetTeamFlagMapthing",lib_pGetTeamFlagMapthing},
{"P_FlashPal",lib_pFlashPal}, {"P_FlashPal",lib_pFlashPal},
{"P_GetClosestAxis",lib_pGetClosestAxis}, {"P_GetClosestAxis",lib_pGetClosestAxis},
{"P_SpawnParaloop",lib_pSpawnParaloop}, {"P_SpawnParaloop",lib_pSpawnParaloop},

View file

@ -2386,7 +2386,7 @@ static int teamlist_set(lua_State *L)
if (i <= 0 || i > teamlist->num) if (i <= 0 || i > teamlist->num)
return luaL_error(L, "array index %d out of range (1 - %d)", i, teamlist->num); return luaL_error(L, "array index %d out of range (1 - %d)", i, teamlist->num);
if (team < 0 || team >= numteams) if (team < 0 || team >= numteams)
return luaL_error(L, "team index %d out of range (0 - %d)", i, numteams - 1); return luaL_error(L, "team index %d out of range (0 - %d)", team, numteams - 1);
teamlist->list[i - 1] = (UINT8)team; teamlist->list[i - 1] = (UINT8)team;
return 0; return 0;
} }

View file

@ -888,7 +888,7 @@ void P_TouchSpecialThing(mobj_t *special, mobj_t *toucher, boolean heightcheck)
player->gotflag |= teams[flagteam].flag; player->gotflag |= teams[flagteam].flag;
CONS_Printf(M_GetText("%s picked up the %s%s%c!\n"), plname, flagcolor, flagtext, 0x80); CONS_Printf(M_GetText("%s picked up the %s%s%c!\n"), plname, flagcolor, flagtext, 0x80);
flagmobjs[flagteam] = NULL; P_SetTarget(&flagmobjs[flagteam], NULL);
// code for dealing with abilities is handled elsewhere now // code for dealing with abilities is handled elsewhere now
break; break;
} }
@ -4443,7 +4443,7 @@ void P_PlayerFlagBurst(player_t *player, boolean toss)
} }
// Pointers set for displaying time value and for consistency restoration. // Pointers set for displaying time value and for consistency restoration.
flagmobjs[team] = flag; P_SetTarget(&flagmobjs[team], flag);
} }
player->gotflag = 0; player->gotflag = 0;

View file

@ -336,6 +336,9 @@ SINT8 P_MobjFlip(mobj_t *mobj);
fixed_t P_GetMobjGravity(mobj_t *mo); fixed_t P_GetMobjGravity(mobj_t *mo);
FUNCMATH boolean P_WeaponOrPanel(mobjtype_t type); FUNCMATH boolean P_WeaponOrPanel(mobjtype_t type);
mobj_t *P_GetTeamFlag(UINT8 team);
mapthing_t *P_GetTeamFlagMapthing(UINT8 team);
void P_CalcChasePostImg(player_t *player, camera_t *thiscam); void P_CalcChasePostImg(player_t *player, camera_t *thiscam);
boolean P_CameraThinker(player_t *player, camera_t *thiscam, boolean resetcalled); boolean P_CameraThinker(player_t *player, camera_t *thiscam, boolean resetcalled);

View file

@ -10037,7 +10037,7 @@ static void P_FlagFuseThink(mobj_t *mobj)
else if (players[consoleplayer].ctfteam != 0) else if (players[consoleplayer].ctfteam != 0)
S_StartSound(NULL, sfx_hoop3); S_StartSound(NULL, sfx_hoop3);
flagmobjs[team] = flagmo; P_SetTarget(&flagmobjs[team], flagmo);
} }
} }
@ -12069,7 +12069,7 @@ static boolean P_AllowMobjSpawn(mapthing_t* mthing, mobjtype_t i)
UINT8 team = mobjinfo[i].mass; UINT8 team = mobjinfo[i].mass;
if (team >= numteams) if (team >= numteams)
return false; return false;
else if (flagmobjs[team]) else if (flagmobjs[team] && !P_MobjWasRemoved(flagmobjs[team]))
{ {
CONS_Alert(CONS_ERROR, M_GetText("Only one flag per team allowed in CTF!\n")); CONS_Alert(CONS_ERROR, M_GetText("Only one flag per team allowed in CTF!\n"));
return false; return false;
@ -13171,11 +13171,11 @@ static boolean P_SetupSpawnedMapThing(mapthing_t *mthing, mobj_t *mobj, boolean
} }
break; break;
case MT_REDFLAG: case MT_REDFLAG:
flagmobjs[TEAM_RED] = mobj; P_SetTarget(&flagmobjs[TEAM_RED], mobj);
flagpoints[TEAM_RED] = mobj->spawnpoint; flagpoints[TEAM_RED] = mobj->spawnpoint;
break; break;
case MT_BLUEFLAG: case MT_BLUEFLAG:
flagmobjs[TEAM_BLUE] = mobj; P_SetTarget(&flagmobjs[TEAM_BLUE], mobj);
flagpoints[TEAM_BLUE] = mobj->spawnpoint; flagpoints[TEAM_BLUE] = mobj->spawnpoint;
break; break;
case MT_NIGHTSSTAR: case MT_NIGHTSSTAR:
@ -14185,3 +14185,19 @@ mobj_t *P_SpawnMobjFromMobj(mobj_t *mobj, fixed_t xofs, fixed_t yofs, fixed_t zo
return newmobj; return newmobj;
} }
mobj_t *P_GetTeamFlag(UINT8 team)
{
if (team >= teamsingame || P_MobjWasRemoved(flagmobjs[team]))
return NULL;
return flagmobjs[team];
}
mapthing_t *P_GetTeamFlagMapthing(UINT8 team)
{
if (team >= teamsingame)
return NULL;
return flagpoints[team];
}

View file

@ -3065,12 +3065,12 @@ static thinker_t* LoadMobjThinker(actionf_p1 thinker)
if (diff & MD_REDFLAG) if (diff & MD_REDFLAG)
{ {
flagmobjs[TEAM_RED] = mobj; P_SetTarget(&flagmobjs[TEAM_RED], mobj);
flagpoints[TEAM_RED] = mobj->spawnpoint; flagpoints[TEAM_RED] = mobj->spawnpoint;
} }
if (diff & MD_BLUEFLAG) if (diff & MD_BLUEFLAG)
{ {
flagmobjs[TEAM_BLUE] = mobj; P_SetTarget(&flagmobjs[TEAM_BLUE], mobj);
flagpoints[TEAM_BLUE] = mobj->spawnpoint; flagpoints[TEAM_BLUE] = mobj->spawnpoint;
} }

View file

@ -7040,7 +7040,7 @@ static void P_InitLevelSettings(void)
// clear ctf pointers // clear ctf pointers
for (i = 0; i < MAXTEAMS; i++) for (i = 0; i < MAXTEAMS; i++)
{ {
flagmobjs[i] = NULL; P_SetTarget(&flagmobjs[i], NULL);
flagpoints[i] = NULL; flagpoints[i] = NULL;
} }

View file

@ -2480,12 +2480,15 @@ static void ST_drawTeamHUD(void)
} }
// Display a countdown timer showing how much time left until the flag returns to base. // Display a countdown timer showing how much time left until the flag returns to base.
if (LUA_HudEnabled(hud_teamscores))
{ {
if (flagmobjs[G_GetTeam(2)] && flagmobjs[G_GetTeam(2)]->fuse > 1 && LUA_HudEnabled(hud_teamscores)) mobj_t *flagmobj = flagmobjs[G_GetTeam(2)];
V_DrawCenteredString(BASEVIDWIDTH/2 - SEP, 8, V_YELLOWMAP|V_HUDTRANS|V_PERPLAYER|V_SNAPTOTOP, va("%u", (flagmobjs[G_GetTeam(2)]->fuse / TICRATE))); if (flagmobj && !P_MobjWasRemoved(flagmobj) && flagmobj->fuse > 1)
V_DrawCenteredString(BASEVIDWIDTH/2 - SEP, 8, V_YELLOWMAP|V_HUDTRANS|V_PERPLAYER|V_SNAPTOTOP, va("%u", (flagmobj->fuse / TICRATE)));
if (flagmobjs[G_GetTeam(1)] && flagmobjs[G_GetTeam(1)]->fuse > 1 && LUA_HudEnabled(hud_teamscores)) flagmobj = flagmobjs[G_GetTeam(1)];
V_DrawCenteredString(BASEVIDWIDTH/2 + SEP, 8, V_YELLOWMAP|V_HUDTRANS|V_PERPLAYER|V_SNAPTOTOP, va("%u", (flagmobjs[G_GetTeam(1)]->fuse / TICRATE))); if (flagmobj && !P_MobjWasRemoved(flagmobj) && flagmobj->fuse > 1)
V_DrawCenteredString(BASEVIDWIDTH/2 + SEP, 8, V_YELLOWMAP|V_HUDTRANS|V_PERPLAYER|V_SNAPTOTOP, va("%u", (flagmobj->fuse / TICRATE)));
} }
} }