mapster-script stuff

git-svn-id: https://svn.eduke32.com/eduke32@1500 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2009-09-18 21:44:46 +00:00
parent e7acafc9e7
commit 293367e844
8 changed files with 236 additions and 56 deletions

View file

@ -27,7 +27,9 @@ definequote 4 ASPECT: VR=%d, YX=%d
definequote 5 KEY:%d
definequote 6 time: %d ms
definequote 7 SPRITES:
definequote 7 door sector not an island sector!
definequote 8 door sector has no SE sprite!
gamearray ar 128
gamearray parm 8
@ -160,14 +162,69 @@ onevent EVENT_KEYS3D
}
}
ife searchstat 0
ifhitkey KEY_SPACE // SE11 ST23 up:ccw
{
set k wall[searchwall].nextsector
ifl k 0 return
ifn sector[k].lotag 23 return
set tmp 0
for i loopofwall searchwall
{
ifl wall[i].nextsector 0 set tmp 1 else
ifn wall[i].nextsector k set tmp 1
}
// a weaker condition
// for i loopofwall wall[searchwall].nextwall
// {
// ifl wall[i].nextsector 0 set tmp 1 else
// ifn wall[i].nextsector searchsector set tmp 1
// }
ifn tmp 0
{
quote 7
return
}
set l -1
for i spritesofsector k
{
ifactor SECTOREFFECTOR ife sprite[i].lotag 11
{
set l i
ifn sprite[i].ang 512 ifn sprite[i].ang 1024 ifn sprite[i].ang 1536 set l -1
}
}
ifl l 0
{
quote 8
return
}
for tmp wallsofsector k
{
rotatepoint (sprite[l].x sprite[l].y) (wall[tmp].x wall[tmp].y) sprite[l].ang (i j)
dragpoint tmp i j
}
for tmp spritesofsector k
{
ifn tmp l
{
rotatepoint (sprite[l].x sprite[l].y) (sprite[tmp].x sprite[tmp].y) sprite[l].ang (i j)
bsetsprite tmp i j sprite[tmp].z
}
}
inv sprite[l].ang
}
ife searchstat 3
ifhitkey KEY_SPACE
{
ifn searchstat 3 break
ifn sprite[searchwall].picnum SECTOREFFECTOR break
ifn sprite[searchwall].picnum SECTOREFFECTOR return
set tmp 0
ife sprite[searchwall].lotag 7 set tmp 1
ife sprite[searchwall].lotag 17 set tmp 1
ife tmp 0 break
ife tmp 0 return
for i allsprites
{
@ -180,7 +237,7 @@ onevent EVENT_KEYS3D
updatecursectnum
break
return
}
}
}
@ -197,7 +254,7 @@ onevent EVENT_KEYS3D
}
endevent
defstate itertest
defstate replacestuff
for i spritesofsector searchsector
// ife sprite[i].picnum AMMO set sprite[i].picnum BATTERYAMMO
ifactor parm[0] cactor parm[1]

View file

@ -50,6 +50,7 @@ extern int32_t X_DoExecute(int32_t once);
extern void X_OnEvent(register int32_t iEventID, register int32_t iActor);
extern void X_ScriptInfo(void);
extern void X_Disasm(ofstype beg, int32_t size);
extern void C_ReportError(int32_t iError);
extern int32_t Gv_NewVar(const char *pszLabel, intptr_t lValue, uint32_t dwFlags);
@ -97,11 +98,13 @@ enum GameEvent_t {
};
extern ofstype aEventOffsets[MAXEVENTS];
extern int32_t aEventSizes[MAXEVENTS];
extern uint8_t aEventEnabled[MAXEVENTS];
enum GamevarFlags_t {
MAXGAMEVARS = 1024, // must be a power of two between 256 and 4096, inclusive
LOG2MAXGV = 10,
MAXVARLABEL = MAXLABELLEN, //26,
GAMEVAR_PERBLOCK = 0x00000001, // per-block (state, event, or top-level) variable
@ -186,6 +189,7 @@ extern int16_t asksave;
extern vec3_t pos;
extern int16_t ang;
extern int32_t horiz;
extern int16_t cursectnum;
extern int32_t searchx;
/*

View file

@ -8863,6 +8863,33 @@ static int32_t osdcmd_scriptinfo(const osdfuncparm_t *parm)
return OSDCMD_OK;
}
#if 0
static int32_t osdcmd_disasm(const osdfuncparm_t *parm)
{
int32_t i;
if (parm->numparms != 2)
return OSDCMD_SHOWHELP;
if (!isdigit(parm->parms[1][0]))
return OSDCMD_SHOWHELP;
i=atoi(parm->parms[1]);
if (parm->parms[0][0]=='s')
{
if (i>=0 && i<g_stateCount)
X_Disasm(statesinfo[i].ofs, statesinfo[i].codesize);
}
else
{
if (i>=0 && i<MAXEVENTS && aEventOffsets[i]>=0)
X_Disasm(aEventOffsets[i], aEventSizes[i]);
}
return OSDCMD_OK;
}
#endif
static int32_t osdcmd_do(const osdfuncparm_t *parm)
{
intptr_t tscrofs;
@ -8998,6 +9025,7 @@ static int32_t registerosdcommands(void)
OSD_RegisterFunction("scriptinfo", "scriptinfo: shows information about compiled M32 script", osdcmd_scriptinfo);
OSD_RegisterFunction("enableevent", "enableevent <all|EVENT_...|(event number)>", osdcmd_endisableevent);
OSD_RegisterFunction("disableevent", "disableevent <all|EVENT_...|(event number)>", osdcmd_endisableevent);
// OSD_RegisterFunction("disasm", "disasm [s|e] <state or event number>", osdcmd_disasm);
return 0;
}
#define DUKEOSD

View file

@ -66,7 +66,7 @@ int32_t g_scriptSize = 65536;
int32_t *constants, constants_allocsize=1024;
int32_t g_numSavedConstants=0;
static int32_t g_tooBigConstant=0;
static int32_t g_wasConstant=0;
char *label;
int32_t *labelval;
@ -98,7 +98,7 @@ char *ScriptQuotes[MAXQUOTES+1], *ScriptQuoteRedefinitions[MAXQUOTES+1];
int32_t g_numQuoteRedefinitions = 0;
ofstype aEventOffsets[MAXEVENTS];
static int32_t aEventSizes[MAXEVENTS];
int32_t aEventSizes[MAXEVENTS];
gamevar_t aGameVars[MAXGAMEVARS];
gamearray_t aGameArrays[MAXGAMEARRAYS];
@ -322,6 +322,8 @@ const char *keyw[] =
"dragpoint",
"getceilzofslope",
"getflorzofslope",
"alignceilslope",
"alignflorslope",
"bsetsprite", // *
"setfirstwall",
"changespritestat",
@ -482,6 +484,7 @@ const tokenmap_t iter_tokens[] =
{ "selwalls", ITER_SELWALLS },
{ "drawnsprites", ITER_DRAWNSPRITES },
{ "spritesofsector", ITER_SPRITESOFSECTOR },
{ "loopofwall", ITER_LOOPOFWALL },
{ "wallsofsector", ITER_WALLSOFSECTOR },
{ "range", ITER_RANGE },
// vvv alternatives go here vvv
@ -812,6 +815,8 @@ static void C_GetNextVarType(int32_t type)
C_SkipComments();
g_wasConstant = 0;
// constant where gamevar expected
if ((type==0 || type==GAMEVAR_SPECIAL) && !cs.labelsOnly &&
(isdigit(*textptr) || ((*textptr == '-') && isdigit(*(textptr+1)))))
@ -833,7 +838,6 @@ static void C_GetNextVarType(int32_t type)
if (g_numCompilerErrors==0 && type!=GAMEVAR_SPECIAL && num != (int16_t)num)
{
g_tooBigConstant = 1;
indirect = 1;
for (i=g_numSavedConstants-1; i>=0; i--)
@ -861,6 +865,8 @@ static void C_GetNextVarType(int32_t type)
}
}
if (type!=GAMEVAR_SPECIAL)
g_wasConstant = 1;
*g_scriptPtr++ = MAXGAMEVARS | (num<<16) | indirect;
while (!ispecial(*textptr) && *textptr != ']') textptr++;
@ -1021,11 +1027,12 @@ static void C_GetNextVarType(int32_t type)
}
else if (num != (int16_t)num)
{
g_tooBigConstant = 1;
indirect = 2;
num = id;
}
if (type!=GAMEVAR_SPECIAL)
g_wasConstant = 1;
*g_scriptPtr++ = MAXGAMEVARS | (num<<16) | indirect;
return;
}
@ -1547,6 +1554,7 @@ static int32_t C_ParseCommand(void)
g_stateCount++;
initprintf(" Defined state `%s' (index %d).\n", g_szCurrentBlockName, j);
// initprintf(" o:%d s:%d\n", statesinfo[j].ofs, statesinfo[j].codesize);
}
else // we were redefining a state
{
@ -1557,20 +1565,34 @@ static int32_t C_ParseCommand(void)
if (nsize == osize)
{
int ii, equal=1;
int ii, equal=2, linedif, ow, nw;
for (ii=0; ii<nsize; ii++)
if (*(script+oofs+ii) != *(script+nofs+ii))
{
equal = 0;
break;
}
if (!equal)
{
Bmemcpy(script+oofs, script+nofs, nsize*sizeof(instype));
initprintf(" Redefined state `%s' (index %d).\n", g_szCurrentBlockName, j);
ow = *(script+oofs+ii);
nw = *(script+nofs+ii);
if (ow != nw)
{
int32_t ld = (nw>>12) - (ow>>12);
if (equal==2)
{
equal = 1;
linedif = ld;
}
if (linedif != ld || ((nw&0xFFF) != (ow&0xFFF)))
{
equal = 0;
break;
}
}
}
if (equal!=2)
Bmemcpy(script+oofs, script+nofs, nsize*sizeof(instype));
if (equal==0)
initprintf(" Redefined state `%s' (index %d).\n", g_szCurrentBlockName, j);
// initprintf(" oo:%d os:%d, no:%d ns:%d\n", oofs, osize, nofs, nsize);
}
else
{
@ -1592,6 +1614,7 @@ static int32_t C_ParseCommand(void)
statesinfo[j].codesize = nsize;
initprintf(" Redefined state `%s' (index %d).\n", g_szCurrentBlockName, j);
// initprintf(" oo:%d os:%d, no:%d ns:%d\n", oofs, osize, nofs, nsize);
}
g_scriptPtr -= osize;
}
@ -1735,20 +1758,34 @@ static int32_t C_ParseCommand(void)
if (osize == nsize)
{
int ii, equal=1;
int ii, equal=2, linedif, nw, ow;
for (ii=0; ii<nsize; ii++)
if (*(script+oofs+ii) != *(script+nofs+ii))
for (ii=0; ii<nsize; ii++)
{
ow = *(script+oofs+ii);
nw = *(script+nofs+ii);
if (ow != nw)
{
int32_t ld = (nw>>12) - (ow>>12);
if (equal==2)
{
equal = 1;
linedif = ld;
}
if (linedif != ld || ((nw&0xFFF) != (ow&0xFFF)))
{
equal = 0;
break;
}
if (!equal)
{
Bmemcpy(script+oofs, script+nofs, nsize*sizeof(instype));
initprintf(" Redefined event `%s' (index %d).\n", g_szCurrentBlockName, j);
}
}
if (equal!=2)
Bmemcpy(script+oofs, script+nofs, nsize*sizeof(instype));
if (equal==0)
initprintf(" Redefined event `%s' (index %d).\n", g_szCurrentBlockName, j);
// initprintf(" oo:%d os:%d, no:%d ns:%d\n", oofs, osize, nofs, nsize);
}
else
{
@ -1770,6 +1807,7 @@ static int32_t C_ParseCommand(void)
aEventSizes[j] = nsize;
initprintf(" Redefined event `%s' (index %d).\n", g_szCurrentBlockName, j);
// initprintf(" oo:%d os:%d, no:%d ns:%d\n", oofs, osize, nofs, nsize);
}
g_scriptPtr -= osize;
}
@ -1779,6 +1817,7 @@ static int32_t C_ParseCommand(void)
aEventSizes[j] = (g_scriptPtr-script) - cs.parsingEventOfs;
initprintf(" Defined event `%s' (index %d).\n", g_szCurrentBlockName, j);
// initprintf(" o:%d s:%d\n", aEventOffsets[j], aEventSizes[j]);
}
g_didDefineSomething = 1;
@ -2449,10 +2488,10 @@ repeatcase:
otextptr = textptr;
g_tooBigConstant = 0;
g_wasConstant = 0;
C_GetNextVar();
if (!g_numCompilerErrors && g_tooBigConstant)
if (!g_numCompilerErrors && g_wasConstant)
{
textptr = otextptr;
g_scriptPtr--;
@ -2616,10 +2655,10 @@ repeatcase:
otextptr = textptr;
g_tooBigConstant = 0;
g_wasConstant = 0;
C_GetNextVar();
if (!g_numCompilerErrors && g_tooBigConstant)
if (!g_numCompilerErrors && g_wasConstant)
{
textptr = otextptr;
g_scriptPtr--;
@ -2720,6 +2759,8 @@ repeatcase:
C_GetNextVarType(GAMEVAR_READONLY);
return 0;
case CON_ALIGNCEILSLOPE:
case CON_ALIGNFLORSLOPE:
case CON_BSETSPRITE: // was CON_SETSPRITE
C_GetManyVars(4);
break;
@ -2861,7 +2902,7 @@ repeatcase:
while (C_GetKeyword() == -1 && j < 32)
C_GetNextVar(), j++;
*g_scriptPtr++ = CON_NULLOP + (g_lineNumber<<12);
*g_scriptPtr++ = -1; //CON_NULLOP + (g_lineNumber<<12);
return 0;
case CON_QSTRCAT:
@ -3209,7 +3250,7 @@ void C_Compile(const char *filenameortext, int32_t isfilename)
}
if ((sizeof(keyw)/sizeof(keyw[0]))-1 != CON_END)
initprintf("INTERNAL WARNING: keyw[] and CON_END don't match!");
initprintf("INTERNAL WARNING: keyw[] and CON_END don't match!\n");
g_scriptPtr = script+1;
@ -3263,7 +3304,7 @@ void C_Compile(const char *filenameortext, int32_t isfilename)
mptr = (char *)Bmalloc(fs+1);
if (!mptr)
{
initprintf("Failed allocating %d byte CON text buffer.", fs+1);
initprintf("Failed allocating %d byte CON text buffer.\n", fs+1);
return;
}
@ -3331,7 +3372,9 @@ void C_Compile(const char *filenameortext, int32_t isfilename)
// C_SetScriptSize(g_scriptPtr-script+8);
if (isfilename)
{
initprintf("Script compiled in %dms\n", getticks() - startcompiletime);
int32_t ct = getticks() - startcompiletime;
if (ct > 50)
initprintf("Script compiled in %dms\n", ct);
C_CompilationInfo();
}
/// for (i=MAXQUOTES-1; i>=0; i--)

View file

@ -225,6 +225,7 @@ enum IterationTypes_t
ITER_DRAWNSPRITES,
ITER_SPRITESOFSECTOR,
ITER_WALLSOFSECTOR,
ITER_LOOPOFWALL,
ITER_RANGE,
ITER_END
};
@ -397,6 +398,8 @@ enum ScriptKeywords_t
CON_DRAGPOINT,
CON_GETCEILZOFSLOPE,
CON_GETFLORZOFSLOPE,
CON_ALIGNCEILSLOPE,
CON_ALIGNFLORSLOPE,
CON_BSETSPRITE, // was CON_SETSPRITE
CON_SETFIRSTWALL,
CON_CHANGESPRITESTAT,

View file

@ -88,6 +88,24 @@ static int32_t dist(spritetype *s1,spritetype *s2)
}
///
void X_Disasm(ofstype beg, int32_t size)
{
instype *p;
if (!script) return;
if (beg<0 || beg+size>g_scriptSize) return;
initprintf("beg=%d, size=%d: ", beg, size);
for (p=script+beg; p<script+beg+size; p++)
{
if (*p>>12 && (*p&0xFFF)<CON_END)
initprintf("%s ", keyw[*p&0xFFF]);
else
initprintf("%d ", *p);
}
initprintf("\n");
}
void X_ScriptInfo(void)
{
if (script)
@ -105,7 +123,7 @@ void X_ScriptInfo(void)
if (p==insptr) initprintf(">>");
}
initprintf(" \n");
if (vm.g_i != MAXSPRITES-1)
if (vm.g_i >= 0)
initprintf("current sprite: %d\n",vm.g_i);
if (g_tw>=0 && g_tw<CON_END)
initprintf("g_errorLineNum: %d, g_tw: %s\n",g_errorLineNum,keyw[g_tw]);
@ -1202,6 +1220,16 @@ skip_check:
X_DoExecute(1);
}
break;
case ITER_LOOPOFWALL:
if (parm2 < 0 || parm2 >= numwalls)
goto badindex;
for (ii=parm2, jj=wall[parm2].point2; jj!=ii; jj=wall[jj].point2)
{
Gv_SetVarX(var, jj);
insptr = beg;
X_DoExecute(1);
}
break;
case ITER_RANGE:
for (jj=0; jj<parm2; jj++)
{
@ -1661,20 +1689,28 @@ badindex:
insptr++;
{
int32_t sectnum = Gv_GetVarX(*insptr++), x = Gv_GetVarX(*insptr++), y = Gv_GetVarX(*insptr++);
if (sectnum<0 || sectnum>=numsectors)
{
OSD_Printf(CON_ERROR "Invalid sector %d\n",g_errorLineNum,keyw[g_tw],sectnum);
vm.g_errorFlag = 1;
insptr++;
continue;
}
int32_t var=*insptr++;
X_ERROR_INVALIDSECT(sectnum);
if (tw == CON_GETFLORZOFSLOPE)
{
Gv_SetVarX(*insptr++, getflorzofslope(sectnum,x,y));
continue;
}
Gv_SetVarX(*insptr++, getceilzofslope(sectnum,x,y));
Gv_SetVarX(var, getflorzofslope(sectnum,x,y));
else
Gv_SetVarX(var, getceilzofslope(sectnum,x,y));
continue;
}
case CON_ALIGNFLORSLOPE:
case CON_ALIGNCEILSLOPE:
insptr++;
{
int32_t sectnum = Gv_GetVarX(*insptr++), x = Gv_GetVarX(*insptr++), y = Gv_GetVarX(*insptr++);
int32_t z=Gv_GetVarX(*insptr++);
X_ERROR_INVALIDSECT(sectnum);
if (tw == CON_ALIGNFLORSLOPE)
alignflorslope(sectnum, x,y,z);
else
alignceilslope(sectnum, x,y,z);
continue;
}
@ -1922,7 +1958,7 @@ badindex:
}
}
else if (code&(MAXGAMEVARS<<2))
Bsprintf(buf, "(array) %s[%s]", aGameArrays[code&(MAXGAMEARRAYS-1)].szLabel?
Bsprintf(buf, "%s[%s]", aGameArrays[code&(MAXGAMEARRAYS-1)].szLabel?
aGameArrays[code&(MAXGAMEARRAYS-1)].szLabel:"???", buf2);
else if (code&(MAXGAMEVARS<<3))
Bsprintf(buf, "%s[%s].%s", pp1[code&3], buf2, pp2[code&3][(code>>2)&31].name);
@ -2125,7 +2161,7 @@ badindex:
int32_t len = Bstrlen(ScriptQuotes[sq]);
char tmpbuf[MAXQUOTELEN<<1];
while ((*insptr & 0xFFF) != CON_NULLOP && numvals < 32)
while (*insptr != -1 && numvals < 32)
arg[numvals++] = Gv_GetVarX(*insptr++);
insptr++; // skip the NOP

View file

@ -163,19 +163,27 @@ static int32_t __fastcall X_AccessSector(int32_t how, int32_t lVar1, int32_t lLa
case SECTOR_CEILINGZ: sector[i].ceilingz=lValue; break;
case SECTOR_FLOORZ: sector[i].floorz=lValue; break;
case SECTOR_CEILINGSTAT:
sector[i].ceilingstat = lValue&0x01ff;
sector[i].ceilingstat = lValue&0x01fd;
break;
case SECTOR_FLOORSTAT:
sector[i].floorstat = lValue&0x01ff;
sector[i].floorstat = lValue&0x01fd;
break;
case SECTOR_CEILINGPICNUM: sector[i].ceilingpicnum=lValue; break;
case SECTOR_CEILINGSLOPE: sector[i].ceilingheinum=lValue; break;
case SECTOR_CEILINGSLOPE:
sector[i].ceilingheinum = lValue;
if (lValue) sector[i].ceilingstat |= 2;
else sector[i].ceilingstat &= ~2;
break;
case SECTOR_CEILINGSHADE: sector[i].ceilingshade=lValue; break;
case SECTOR_CEILINGPAL: sector[i].ceilingpal=lValue; break;
case SECTOR_CEILINGXPANNING: sector[i].ceilingxpanning=lValue; break;
case SECTOR_CEILINGYPANNING: sector[i].ceilingypanning=lValue; break;
case SECTOR_FLOORPICNUM: sector[i].floorpicnum=lValue; break;
case SECTOR_FLOORSLOPE: sector[i].floorheinum=lValue; break;
case SECTOR_FLOORSLOPE:
sector[i].floorheinum = lValue;
if (lValue) sector[i].floorstat |= 2;
else sector[i].floorstat &= ~2;
break;
case SECTOR_FLOORSHADE: sector[i].floorshade=lValue; break;
case SECTOR_FLOORPAL: sector[i].floorpal=lValue; break;
case SECTOR_FLOORXPANNING: sector[i].floorxpanning=lValue; break;

View file

@ -274,7 +274,7 @@ int32_t __fastcall Gv_GetVarX(register int32_t id)
}
{
register int32_t negateResult = id&(MAXGAMEVARS<<1);
register int32_t negateResult = (id&(MAXGAMEVARS<<1))>>(LOG2MAXGV+1);
if (id & (0xFFFFFFFF-(MAXGAMEVARS-1)))
{
@ -554,6 +554,7 @@ static void Gv_AddSystemVars(void)
Gv_NewVar("posy",(intptr_t)&pos.y, GAMEVAR_INTPTR | GAMEVAR_SYSTEM);
Gv_NewVar("posz",(intptr_t)&pos.z, GAMEVAR_INTPTR | GAMEVAR_SYSTEM);
Gv_NewVar("ang",(intptr_t)&ang, GAMEVAR_SHORTPTR | GAMEVAR_SYSTEM);
Gv_NewVar("horiz",(intptr_t)&horiz, GAMEVAR_INTPTR | GAMEVAR_SYSTEM);
Gv_NewVar("cursectnum",(intptr_t)&cursectnum, GAMEVAR_READONLY | GAMEVAR_SHORTPTR | GAMEVAR_SYSTEM);
Gv_NewVar("searchx",(intptr_t)&searchx, GAMEVAR_READONLY | GAMEVAR_INTPTR | GAMEVAR_SYSTEM);