mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-03-09 19:02:01 +00:00
Add teamscores to Lua
This commit is contained in:
parent
fecf5616cc
commit
313f224311
4 changed files with 67 additions and 15 deletions
|
@ -2368,19 +2368,12 @@ static int team_num(lua_State *L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int teamlist_len(lua_State *L)
|
||||
{
|
||||
teamlist_t *teamlist = *((teamlist_t **)luaL_checkudata(L, 1, META_TEAMLIST));
|
||||
lua_pushinteger(L, teamlist->num);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int teamlist_get(lua_State *L)
|
||||
{
|
||||
teamlist_t *teamlist = *((teamlist_t **)luaL_checkudata(L, 1, META_TEAMLIST));
|
||||
int i = luaL_checkinteger(L, 2);
|
||||
if (i < 0 || i > teamlist->num)
|
||||
return luaL_error(L, "list index %d out of range (1 - %d)", i, teamlist->num);
|
||||
if (i <= 0 || i > teamlist->num)
|
||||
return luaL_error(L, "array index %d out of range (1 - %d)", i, teamlist->num);
|
||||
lua_pushinteger(L, teamlist->list[i - 1]);
|
||||
return 1;
|
||||
}
|
||||
|
@ -2389,15 +2382,49 @@ static int teamlist_set(lua_State *L)
|
|||
{
|
||||
teamlist_t *teamlist = *((teamlist_t **)luaL_checkudata(L, 1, META_TEAMLIST));
|
||||
int i = luaL_checkinteger(L, 2);
|
||||
if (i < 0 || i > teamlist->num)
|
||||
return luaL_error(L, "list index %d out of range (1 - %d)", i, teamlist->num);
|
||||
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)", i, numteams - 1);
|
||||
teamlist->list[i - 1] = (UINT8)team;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int teamlist_len(lua_State *L)
|
||||
{
|
||||
teamlist_t *teamlist = *((teamlist_t **)luaL_checkudata(L, 1, META_TEAMLIST));
|
||||
lua_pushinteger(L, teamlist->num);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int teamscores_get(lua_State *L)
|
||||
{
|
||||
UINT32 *scoreslist = *((UINT32 **)luaL_checkudata(L, 1, META_TEAMSCORES));
|
||||
int i = luaL_checkinteger(L, 2);
|
||||
if (i < 0 || i >= numteams)
|
||||
return luaL_error(L, "array index %d out of range (0 - %d)", i, numteams - 1);
|
||||
lua_pushinteger(L, scoreslist[i]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int teamscores_set(lua_State *L)
|
||||
{
|
||||
UINT32 *scoreslist = *((UINT32 **)luaL_checkudata(L, 1, META_TEAMSCORES));
|
||||
int i = luaL_checkinteger(L, 2);
|
||||
UINT32 score = (UINT32)luaL_checkinteger(L, 3);
|
||||
if (i < 0 || i >= numteams)
|
||||
return luaL_error(L, "array index %d out of range (0 - %d)", i, numteams - 1);
|
||||
scoreslist[i] = score;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int teamscores_len(lua_State *L)
|
||||
{
|
||||
lua_pushinteger(L, numteams);
|
||||
return 1;
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
//
|
||||
// Now push all these functions into the Lua state!
|
||||
|
@ -2474,6 +2501,17 @@ int LUA_InfoLib(lua_State *L)
|
|||
lua_setfield(L, -2, "__len");
|
||||
lua_pop(L, 1);
|
||||
|
||||
luaL_newmetatable(L, META_TEAMSCORES);
|
||||
lua_pushcfunction(L, teamscores_get);
|
||||
lua_setfield(L, -2, "__index");
|
||||
|
||||
lua_pushcfunction(L, teamscores_set);
|
||||
lua_setfield(L, -2, "__newindex");
|
||||
|
||||
lua_pushcfunction(L, teamscores_len);
|
||||
lua_setfield(L, -2, "__len");
|
||||
lua_pop(L, 1);
|
||||
|
||||
luaL_newmetatable(L, META_SKINCOLOR);
|
||||
lua_pushcfunction(L, skincolor_get);
|
||||
lua_setfield(L, -2, "__index");
|
||||
|
|
|
@ -31,6 +31,7 @@ extern boolean mousegrabbedbylua;
|
|||
#define META_GAMETYPE "GAMETYPE_T*"
|
||||
#define META_TEAM "TEAM_T*"
|
||||
#define META_TEAMLIST "TEAMLIST_T*"
|
||||
#define META_TEAMSCORES "TEAMSCORES"
|
||||
#define META_PIVOTLIST "SPRITEFRAMEPIVOT_T[]"
|
||||
#define META_FRAMEPIVOT "SPRITEFRAMEPIVOT_T*"
|
||||
|
||||
|
|
|
@ -219,6 +219,9 @@ int LUA_PushGlobals(lua_State *L, const char *word)
|
|||
} else if (fastcmp(word,"redscore")) {
|
||||
lua_pushinteger(L, teamscores[G_GetTeam(1)]);
|
||||
return 1;
|
||||
} else if (fastcmp(word,"teamscores")) {
|
||||
LUA_PushUserdata(L, teamscores, META_TEAMSCORES);
|
||||
return 1;
|
||||
} else if (fastcmp(word,"timelimit")) {
|
||||
lua_pushinteger(L, cv_timelimit.value);
|
||||
return 1;
|
||||
|
@ -998,6 +1001,7 @@ enum
|
|||
ARCH_SKIN,
|
||||
ARCH_GAMETYPE,
|
||||
ARCH_TEAM,
|
||||
ARCH_TEAMSCORES,
|
||||
|
||||
ARCH_TEND=0xFF,
|
||||
};
|
||||
|
@ -1029,6 +1033,7 @@ static const struct {
|
|||
{META_SKIN, ARCH_SKIN},
|
||||
{META_GAMETYPE, ARCH_GAMETYPE},
|
||||
{META_TEAM, ARCH_TEAM},
|
||||
{META_TEAMSCORES, ARCH_TEAMSCORES},
|
||||
{NULL, ARCH_NULL}
|
||||
};
|
||||
|
||||
|
@ -1371,6 +1376,11 @@ static UINT8 ArchiveValue(int TABLESINDEX, int myindex)
|
|||
WRITEUINT8(save_p, team - teams);
|
||||
break;
|
||||
}
|
||||
case ARCH_TEAMSCORES:
|
||||
{
|
||||
WRITEUINT8(save_p, ARCH_TEAMSCORES);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
WRITEUINT8(save_p, ARCH_NULL);
|
||||
return 2;
|
||||
|
@ -1626,6 +1636,9 @@ static UINT8 UnArchiveValue(int TABLESINDEX)
|
|||
case ARCH_TEAM:
|
||||
LUA_PushUserdata(gL, &teams[READUINT8(save_p)], META_TEAM);
|
||||
break;
|
||||
case ARCH_TEAMSCORES:
|
||||
LUA_PushUserdata(gL, teamscores, META_TEAMSCORES);
|
||||
break;
|
||||
case ARCH_TEND:
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -2436,13 +2436,13 @@ static void ST_drawTeamHUD(void)
|
|||
|
||||
if (gametyperules & GTR_TEAMFLAGS)
|
||||
{
|
||||
bmatcico = ST_GetCurrentTeamIconImage(1, TEAM_ICON_FLAG);
|
||||
rmatcico = ST_GetCurrentTeamIconImage(2, TEAM_ICON_FLAG);
|
||||
rmatcico = ST_GetCurrentTeamIconImage(1, TEAM_ICON_FLAG);
|
||||
bmatcico = ST_GetCurrentTeamIconImage(2, TEAM_ICON_FLAG);
|
||||
}
|
||||
else
|
||||
{
|
||||
bmatcico = ST_GetCurrentTeamIconImage(1, TEAM_ICON);
|
||||
rmatcico = ST_GetCurrentTeamIconImage(2, TEAM_ICON);
|
||||
rmatcico = ST_GetCurrentTeamIconImage(1, TEAM_ICON);
|
||||
bmatcico = ST_GetCurrentTeamIconImage(2, TEAM_ICON);
|
||||
}
|
||||
|
||||
V_DrawSmallScaledPatch(BASEVIDWIDTH/2 - SEP - (bmatcico->width / 4), 4, V_HUDTRANS|V_PERPLAYER|V_SNAPTOTOP, bmatcico);
|
||||
|
|
Loading…
Reference in a new issue