Lunatic: implement passing string label to 'spawn' OSD command.

Unlike in C-CON, it only tries an exact match with the given and uppercased
label, not "full" case-insensitive search.

git-svn-id: https://svn.eduke32.com/eduke32@4370 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2014-03-15 14:10:45 +00:00
parent 69d906c4f7
commit 55d6b9c5c7
3 changed files with 36 additions and 12 deletions

View file

@ -614,6 +614,7 @@ char *g_elSavecode;
void El_FreeSaveCode(void);
const char *(*El_SerializeGamevars)(int32_t *slenptr, int32_t levelnum);
int32_t (*El_RestoreGamevars)(const char *savecode);
int32_t (*El_GetLabelValue)(const char *label);
const char *s_buildRev;
const char *g_sizes_of_what[];
@ -2517,7 +2518,7 @@ ffiC.El_RestoreGamevars = function(savecode)
end
-- Run the CON code translated into Lua.
if (concode) then
if (assert(concode ~= nil)) then
local confunc, conerrmsg = loadstring(concode, "CON")
if (confunc == nil) then
error("Failure loading translated CON code: "..conerrmsg, 0)
@ -2547,6 +2548,12 @@ if (concode) then
-- Propagate potentially remapped defines to the control module.
con._setuplabels(conlabels)
ffiC.El_GetLabelValue = function(label)
local str = ffi.string(label)
local val = conlabels[str] or conlabels[string.upper(str)]
return type(val)=="number" and val or bit.tobit(0x80000000)
end
end
-- When starting a map, load Lua modules given on the command line.

View file

@ -114,6 +114,7 @@ g_elSavecode;
El_FreeSaveCode;
El_SerializeGamevars;
El_RestoreGamevars;
El_GetLabelValue;
s_buildRev;
g_sizes_of_what;

View file

@ -451,9 +451,15 @@ static int32_t osdcmd_vidmode(const osdfuncparm_t *parm)
return OSDCMD_OK;
}
#ifdef LUNATIC
// Returns: INT32_MIN if no such CON label, its value else.
LUNATIC_CB int32_t (*El_GetLabelValue)(const char *label);
#endif
static int32_t osdcmd_spawn(const osdfuncparm_t *parm)
{
uint16_t cstat=0,picnum=0;
int32_t picnum = 0;
uint16_t cstat=0;
char pal=0;
int16_t ang=0;
int16_t set=0, idx;
@ -484,26 +490,35 @@ static int32_t osdcmd_spawn(const osdfuncparm_t *parm)
case 1: // tile number
if (isdigit(parm->parms[0][0]))
{
picnum = (uint16_t)Batol(parm->parms[0]);
picnum = Batol(parm->parms[0]);
}
else
{
int32_t i,j;
int32_t i;
#ifdef LUNATIC
i = g_numLabels;
picnum = El_GetLabelValue(parm->parms[0]);
if (picnum != INT32_MIN)
i = !i;
#else
int32_t j;
for (j=0; j<2; j++)
{
for (i=0; i<g_numLabels; i++)
{
if (
(j == 0 && !Bstrcmp(label+(i<<6), parm->parms[0])) ||
(j == 1 && !Bstrcasecmp(label+(i<<6), parm->parms[0]))
)
if ((j == 0 && !Bstrcmp(label+(i<<6), parm->parms[0])) ||
(j == 1 && !Bstrcasecmp(label+(i<<6), parm->parms[0])))
{
picnum = (uint16_t)labelcode[i];
picnum = labelcode[i];
break;
}
}
if (i<g_numLabels) break;
if (i < g_numLabels)
break;
}
#endif
if (i==g_numLabels)
{
OSD_Printf("spawn: Invalid tile label given\n");
@ -511,17 +526,18 @@ static int32_t osdcmd_spawn(const osdfuncparm_t *parm)
}
}
if (picnum >= MAXTILES)
if ((uint32_t)picnum >= MAXUSERTILES)
{
OSD_Printf("spawn: Invalid tile number\n");
return OSDCMD_OK;
}
break;
default:
return OSDCMD_SHOWHELP;
}
idx = A_Spawn(g_player[myconnectindex].ps->i, (int16_t)picnum);
idx = A_Spawn(g_player[myconnectindex].ps->i, picnum);
if (set & 1) sprite[idx].pal = (uint8_t)pal;
if (set & 2) sprite[idx].cstat = (int16_t)cstat;
if (set & 4) sprite[idx].ang = ang;