diff --git a/polymer/eduke32/build/include/m32script.h b/polymer/eduke32/build/include/m32script.h index bcc06ecf4..62ba98ecb 100644 --- a/polymer/eduke32/build/include/m32script.h +++ b/polymer/eduke32/build/include/m32script.h @@ -169,11 +169,6 @@ extern uint32_t m32_drawlinepat; extern int32_t g_iReturnVar; extern int32_t m32_sortvar1, m32_sortvar2; -extern int32_t g_iReturnVarID; -extern int32_t g_iLoTagID; // var ID of "LOTAG" -extern int32_t g_iHiTagID; // var ID of "HITAG" -extern int32_t g_iTextureID; // var ID of "TEXTURE" -extern int32_t g_iThisActorID; // var ID of "I" ///"THISACTOR" //extern int32_t g_numRealPalettes; //extern int32_t g_scriptDebug; @@ -182,7 +177,7 @@ extern int32_t g_numQuoteRedefinitions; extern hashtable_t h_gamevars; extern hashtable_t h_arrays; -extern hashtable_t h_keywords; +//extern hashtable_t h_keywords; extern hashtable_t h_gamefuncs; @@ -232,4 +227,23 @@ extern int32_t numsprites; extern int32_t zoom; extern int32_t halfxdim16, midydim16; + +#define M32_FLAG_NEGATE (MAXGAMEVARS<<1) +#define M32_FLAG_ARRAY (MAXGAMEVARS<<2) +#define M32_FLAG_SPECIAL (MAXGAMEVARS<<3) + +// IDs of special vars +#define M32_SPRITE_VAR_ID 0 +#define M32_SECTOR_VAR_ID 1 +#define M32_WALL_VAR_ID 2 +#define M32_TSPRITE_VAR_ID 3 + +#define M32_THISACTOR_VAR_ID 4 +#define M32_RETURN_VAR_ID 5 +#define M32_LOTAG_VAR_ID 6 +#define M32_HITAG_VAR_ID 7 +#define M32_TEXTURE_VAR_ID 8 + +#define M32_PRINTERROR(Text, ...) OSD_Printf(OSD_ERROR "Line %d, %s: " Text "\n", g_errorLineNum, keyw[g_tw], ## __VA_ARGS__) + #endif diff --git a/polymer/eduke32/build/src/config.c b/polymer/eduke32/build/src/config.c index fbbe95b81..33a9d38c7 100644 --- a/polymer/eduke32/build/src/config.c +++ b/polymer/eduke32/build/src/config.c @@ -244,9 +244,10 @@ int32_t loadsetup(const char *fn) graphicsmode = min(max(Batoi(val),0),2); if (readconfig(fp, "ambiencetoggle", val, VL) > 0) AmbienceToggle = Batoi(val); - if (readconfig(fp, "parlock", val, VL) > 0) ParentalLock = Batoi(val); + if (readconfig(fp, "osdtryscript", val, VL) > 0) m32_osd_tryscript = Batoi(val); + for (i=0; i<256; i++) remap[i]=i; @@ -399,7 +400,12 @@ int32_t writesetup(const char *fn) "graphicsmode = %d\n\n" "; Ambient sounds in 3D mode (0:off, 1:on)\n" "ambiencetoggle = %d\n" - "parlock = %d\n\n" + "parlock = %d\n" + "\n" + "; Try executing m32script on invalid command in the OSD? This makes\n" + "; typing m32script commands into the OSD directly possible.\n" + "osdtryscript = %d\n" + "\n" #if 1 "; Key Settings\n" "; Here's a map of all the keyboard scan codes: NOTE: values are listed in hex!\n" @@ -470,6 +476,7 @@ int32_t writesetup(const char *fn) option[3], msens, unrealedlook, pk_uedaccel, quickmapcycling, revertCTRL,scrollamount,pk_turnaccel,pk_turndecel,autosave, showheightindicators,graphicsmode,AmbienceToggle,ParentalLock, + !!m32_osd_tryscript, #if 1 keys[0], keys[1], keys[2], keys[3], keys[4], keys[5], keys[6], keys[7], keys[8], keys[9], keys[10], keys[11], diff --git a/polymer/eduke32/build/src/osd.c b/polymer/eduke32/build/src/osd.c index f7d80e3ac..f4ade505f 100644 --- a/polymer/eduke32/build/src/osd.c +++ b/polymer/eduke32/build/src/osd.c @@ -124,6 +124,9 @@ static cvar_t *cvars = NULL; static uint32_t osdnumcvars = 0; static hashtable_t h_cvars = { MAXSYMBOLS<<1, NULL }; +int32_t m32_osd_tryscript=0; // whether to try executing m32script on unkown command in the osd +extern void M32RunScript(const char *s); + int32_t OSD_RegisterCvar(const cvar_t *cvar) { const char *cp; @@ -1653,8 +1656,14 @@ int32_t OSD_Dispatch(const char *cmd) if ((symb = findexactsymbol(wp)) == NULL) { - if (wp[0] != '/' || wp[1] != '/') // cheap hack for comments in cfgs + if ((wp[0] != '/' || wp[1] != '/') && !m32_osd_tryscript) // cheap hack for comments in cfgs + { OSD_Printf(OSDTEXT_RED "\"%s\" is not a valid command or cvar\n", wp); + } + else if (m32_osd_tryscript) + { + M32RunScript(cmd); + } Bfree(workbuf); return -1; } diff --git a/polymer/eduke32/m32script_ex.map b/polymer/eduke32/m32script_ex.map index babb2c915..4f50ae3ef 100755 Binary files a/polymer/eduke32/m32script_ex.map and b/polymer/eduke32/m32script_ex.map differ diff --git a/polymer/eduke32/source/astub.c b/polymer/eduke32/source/astub.c index 4dedc28df..0ad4c689e 100644 --- a/polymer/eduke32/source/astub.c +++ b/polymer/eduke32/source/astub.c @@ -4616,7 +4616,7 @@ static void Keys3d(void) { if (ASSERT_AIMING) { - AIMED_CF_SEL(shade) += tsign; + AIMED_CF_SEL(shade) += tsign*(1+3*eitherCTRL); message("%s %d shade %d", Typestr[searchstat], i, AIMED_CF_SEL(shade)); } } @@ -7310,6 +7310,7 @@ static int32_t osdcmd_noclip(const osdfuncparm_t *parm) { UNREFERENCED_PARAMETER(parm); noclip = !noclip; + OSD_Printf("Clipping %s\n", noclip?"disabled":"enabled"); return OSDCMD_OK; } @@ -7410,6 +7411,11 @@ static int32_t osdcmd_vars_pk(const osdfuncparm_t *parm) pk_uedaccel = pk_uedaccel>5 ? 5:pk_uedaccel; } } + else if (!Bstrcasecmp(parm->name, "osd_tryscript")) + { + m32_osd_tryscript = !m32_osd_tryscript; + OSD_Printf("Try M32 script execution on invalid OSD command: %s\n", m32_osd_tryscript?"on":"off"); + } return OSDCMD_OK; } @@ -7498,30 +7504,30 @@ static int32_t osdcmd_do(const osdfuncparm_t *parm) { intptr_t tscrofs; char *tp; - int32_t i, j, slen; + int32_t i, j, slen, ofs; int32_t onumconstants=g_numSavedConstants; - if (parm->numparms < 1) + if (parm->numparms==0) return OSDCMD_SHOWHELP; tscrofs = (g_scriptPtr-script); - slen = Bstrlen(parm->raw+2); + ofs = 2*(parm->numparms>0); // true if "do" command + slen = Bstrlen(parm->raw+ofs); tp = Bmalloc(slen+2); - if (!tp) - { - initprintf("OUT OF MEMORY!\n"); - return OSDCMD_OK; - } + if (!tp) goto OUTOFMEM; + Bmemcpy(tp, parm->raw+ofs, slen); - Bmemcpy(tp, parm->raw+2, slen); + // needed so that subsequent commands won't execute old stuff. tp[slen] = '\n'; tp[slen+1] = '\0'; g_didDefineSomething = 0; C_Compile(tp, 0); - Bfree(tp); + + if (parm->numparms>=0) + Bfree(tp); if (g_numCompilerErrors) { @@ -7547,12 +7553,24 @@ static int32_t osdcmd_do(const osdfuncparm_t *parm) } return OSDCMD_OK; +OUTOFMEM: + OSD_Printf("OUT OF MEMORY!\n"); + return OSDCMD_OK; +} + +void M32RunScript(const char *s) +{ + osdfuncparm_t parm; + + parm.numparms = -1; + parm.raw = s; + + osdcmd_do(&parm); } static int32_t osdcmd_endisableevent(const osdfuncparm_t *parm) { int32_t i, j, enable; - char buf[64] = "EVENT_"; if (!label) return OSDCMD_OK; @@ -7569,28 +7587,44 @@ static int32_t osdcmd_endisableevent(const osdfuncparm_t *parm) if (parm->numparms == 1) { - if (!Bstrcasecmp(parm->parms[0], "all")) + if (!Bstrcasecmp(parm->parms[0], "all") || !Bstrcasecmp(parm->parms[0], "a")) { for (i=0; inumparms; i++) { + char buf[64] = "EVENT_", buf2[64]; + if (isdigit(parm->parms[i][0])) + { j = atoi(parm->parms[i]); + Bsprintf(buf2, "event %d", j); + } else if (!Bstrncmp(parm->parms[i], "EVENT_", 6)) + { j = hash_find(&h_labels, parm->parms[i]); + Bstrncpy(buf2, parm->parms[i], sizeof(buf2)); + buf2[sizeof(buf2)-1] = '\0'; + } else { Bstrncat(buf, parm->parms[i], sizeof(buf)-6-1); j = hash_find(&h_labels, buf); + Bmemcpy(buf2, buf, sizeof(buf2)); } if (j>=0 && j", osdcmd_endisableevent); OSD_RegisterFunction("disableevent", "disableevent ", osdcmd_endisableevent); + OSD_RegisterFunction("osd_tryscript", "osd_tryscript: Toggles execution of M32 script on invalid OSD command", osdcmd_vars_pk); // OSD_RegisterFunction("disasm", "disasm [s|e] ", osdcmd_disasm); return 0; } diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index 75804e7ee..f53a6ebc4 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -198,6 +198,8 @@ uint32_t g_frameDelay = 0; extern char forcegl; #endif +void M32RunScript(const char *s) {}; // needed for linking since it's referenced from build/src/osd.c + int32_t kopen4loadfrommod(char *filename, char searchfirst) { static char fn[BMAX_PATH]; @@ -11776,6 +11778,9 @@ MAIN_LOOP_RESTART: } else G_UpdateScreenArea(); +// G_GameExit(" "); /// + +// ud.auto_run = ud.config.RunMode; ud.showweapons = ud.config.ShowOpponentWeapons; g_player[myconnectindex].ps->aim_mode = ud.mouseaiming; g_player[myconnectindex].ps->auto_aim = ud.config.AutoAim; diff --git a/polymer/eduke32/source/m32def.c b/polymer/eduke32/source/m32def.c index 509af7718..65e3b13b6 100644 --- a/polymer/eduke32/source/m32def.c +++ b/polymer/eduke32/source/m32def.c @@ -84,16 +84,6 @@ static char tlabel[MAXLABELLEN]; int32_t g_iReturnVar=0; int32_t m32_sortvar1, m32_sortvar2; -int32_t g_iReturnVarID=-1; // var ID of "RETURN" -int32_t g_iLoTagID=-1; // var ID of "LOTAG" -int32_t g_iHiTagID=-1; // var ID of "HITAG" -int32_t g_iTextureID=-1; // var ID of "TEXTURE" - -int32_t g_iThisActorID=-1; // var ID of "I" ///"THISACTOR" - -int32_t g_iSpriteVarID=-1; -int32_t g_iSectorVarID=-1; -int32_t g_iWallVarID=-1; char *ScriptQuotes[MAXQUOTES+1], *ScriptQuoteRedefinitions[MAXQUOTES+1]; int32_t g_numQuoteRedefinitions = 0; @@ -113,18 +103,17 @@ int32_t g_gameArrayCount=0, g_systemArrayCount=0; void C_ReportError(int32_t iError); - enum ScriptLabel_t { LABEL_ANY = -1, LABEL_DEFINE = 1, - LABEL_EVENT = 2, + LABEL_EVENT = 2 }; static const char *LabelTypeText[] = { "define", - "event", + "event" }; static const char *C_GetLabelType(int32_t type) @@ -516,13 +505,14 @@ const tokenmap_t iter_tokens[] = hashtable_t h_gamevars = { MAXGAMEVARS>>1, NULL }; hashtable_t h_arrays = { MAXGAMEARRAYS>>1, NULL }; hashtable_t h_labels = { 11262>>1, NULL }; -hashtable_t h_states = { 1264>>1, NULL }; -hashtable_t h_keywords = { CON_END>>1, NULL }; -hashtable_t iterH = { ITER_END, NULL }; -hashtable_t sectorH = { SECTOR_END>>1, NULL }; -hashtable_t wallH = { WALL_END>>1, NULL }; -hashtable_t spriteH = { SPRITE_END>>1, NULL }; +static hashtable_t h_states = { 1264>>1, NULL }; +static hashtable_t h_keywords = { CON_END>>1, NULL }; +static hashtable_t h_iter = { ITER_END, NULL }; + +static hashtable_t h_sector = { SECTOR_END>>1, NULL }; +static hashtable_t h_wall = { WALL_END>>1, NULL }; +static hashtable_t h_sprite = { SPRITE_END>>1, NULL }; static void C_InitHashes() @@ -540,23 +530,23 @@ static void C_InitHashes() for (i=0; i=0; i++) - hash_add(§orH,SectorLabels[i].name,i); - hash_add(§orH,"filler",SECTOR_ALIGNTO); + hash_add(&h_sector,SectorLabels[i].name,i); + hash_add(&h_sector,"filler", SECTOR_ALIGNTO); - hash_init(&wallH); + hash_init(&h_wall); for (i=0; WallLabels[i].lId >=0; i++) - hash_add(&wallH,WallLabels[i].name,i); + hash_add(&h_wall,WallLabels[i].name,i); - hash_init(&spriteH); + hash_init(&h_sprite); for (i=0; SpriteLabels[i].lId >=0; i++) - hash_add(&spriteH,SpriteLabels[i].name,i); - hash_add(&spriteH,"filler",SPRITE_DETAIL); + hash_add(&h_sprite,SpriteLabels[i].name,i); + hash_add(&h_sprite,"filler", SPRITE_DETAIL); - hash_init(&iterH); + hash_init(&h_iter); for (i=0; iter_tokens[i].val >=0; i++) - hash_add(&iterH, iter_tokens[i].token, iter_tokens[i].val); + hash_add(&h_iter, iter_tokens[i].token, iter_tokens[i].val); } static int32_t C_SetScriptSize(int32_t size) @@ -573,16 +563,16 @@ static int32_t C_SetScriptSize(int32_t size) //initprintf("offset: %d\n",(unsigned)(g_scriptPtr-script)); g_scriptSize = size; - initprintf("Resizing code buffer to %d*%d bytes\n",g_scriptSize, sizeof(instype)); + initprintf("Resizing code buffer to %d*%d bytes\n", g_scriptSize, sizeof(instype)); newscript = (instype *)Brealloc(script, g_scriptSize * sizeof(instype)); if (newscript == NULL) { C_ReportError(-1); - initprintf("%s:%d: out of memory: Aborted (%ud)\n",g_szScriptFileName,g_lineNumber,(unsigned)(g_scriptPtr-script)); - initprintf(tempbuf); + initprintf("%s:%d: out of memory: Aborted (%ud)\n", g_szScriptFileName, g_lineNumber, (unsigned)(g_scriptPtr-script)); g_numCompilerErrors++; +// initprintf(tempbuf); return 1; } @@ -606,31 +596,36 @@ static int32_t C_SetScriptSize(int32_t size) return 0; } +static inline int32_t ispecial(char c) +{ + return c==' ' || c=='\t' || c=='\n' || c=='\r' || c=='(' || c==')' || c==',' || c==';'; +} + +static inline int32_t isaltok(char c) +{ + return isalnum(c) || c == '#' || c == '{' || c == '}' || c == '/' || c == '\\' || + c == '*' || c == '-' || c == '_' || c == '.'; +} + static int32_t C_SkipComments(void) { char c = *textptr; do { - if (c == ' ' || c == '\t' || c == '\r') - textptr++; - else if (c == '\n') + if (ispecial(c)) { - g_lineNumber++; textptr++; + g_lineNumber += (c=='\n'); } else if (c == '/' && textptr[1] == '/') { -// if (!(g_numCompilerErrors || g_numCompilerWarnings) && g_scriptDebug > 1) -// initprintf("%s:%d: debug: got comment.\n",g_szScriptFileName,g_lineNumber); - - while (*textptr != 0x0a && *textptr != 0x0d && *textptr != 0) + while (*textptr && *textptr != 0x0a && *textptr != 0x0d) textptr++; } else if (c == '/' && textptr[1] == '*') { -// if (!(g_numCompilerErrors || g_numCompilerWarnings) && g_scriptDebug > 1) -// initprintf("%s:%d: debug: got start of comment block.\n",g_szScriptFileName,g_lineNumber); + textptr += 2; while (*textptr && !(textptr[0] == '*' && textptr[1] == '/')) { @@ -639,23 +634,18 @@ static int32_t C_SkipComments(void) textptr++; } -// if ((!(g_numCompilerErrors || g_numCompilerWarnings) && g_scriptDebug > 1) && (textptr[0] == '*' && textptr[1] == '/')) -// initprintf("%s:%d: debug: got end of comment block.\n",g_szScriptFileName,g_lineNumber); - if (!*textptr) { -// if (!(g_numCompilerErrors || g_numCompilerWarnings) && g_scriptDebug) -// initprintf("%s:%d: debug: EOF in comment!\n",g_szScriptFileName,g_lineNumber); - C_ReportError(-1); - initprintf("%s:%d: error: found `/*' with no `*/'.\n",g_szScriptFileName,g_lineNumber); + C_CUSTOMERROR("found `/*' with no `*/'."); cs.numBraces = 0; cs.currentStateIdx = -1; - g_numCompilerErrors++; break; } - else textptr += 2; + + textptr += 2; } - else break; + else + break; } while ((c = *textptr)); @@ -665,30 +655,14 @@ static int32_t C_SkipComments(void) return 0; } -static inline int32_t ispecial(const char c) -{ - if (c == ' ' || c == 0x0d || c == '(' || c == ')' || - c == ',' || c == ';' || (c == 0x0a /*&& ++g_lineNumber*/)) - return 1; - - return 0; -} - -static inline int32_t isaltok(const char c) -{ - return (isalnum(c) || c == '#' || c == '{' || c == '}' || c == '/' || c == '\\' || - c == '*' || c == '-' || c == '_' || c == '.'); -} - static inline int32_t C_GetLabelNameID(const memberlabel_t *pLabel, hashtable_t *tH, const char *psz) { // find the label psz in the table pLabel. // returns the ID for the label, or -1 - int32_t l=-1; - - l = hash_findcase(tH,psz); - if (l>=0) l=pLabel[l].lId; + int32_t l = hash_findcase(tH, psz); + if (l>=0) + l = pLabel[l].lId; return l; } @@ -699,16 +673,23 @@ static void C_GetNextLabelName(void) C_SkipComments(); - while (isalnum(*textptr) == 0) + if (*textptr == 0) { - if (*textptr == 0x0a) g_lineNumber++; + C_CUSTOMERROR("unexpected EOF where label was expected."); + return; + } + + while (!isalnum(*textptr)) + { + g_lineNumber += (*textptr == 0x0a); + textptr++; - if (*textptr == 0) + if (!*textptr) return; } i = 0; - while (!ispecial(*textptr) && *textptr!='['&& *textptr!=']' && *textptr!='\t' && *textptr!='\n' && *textptr!='\r') + while (!ispecial(*textptr) && *textptr!='['&& *textptr!=']') { if (i < MAXLABELLEN-1) tlabel[i++] = *(textptr++); @@ -728,6 +709,7 @@ static int32_t C_CopyLabel(void) label = Brealloc(label, 2*label_allocsize*MAXLABELLEN*sizeof(char)); labelval = Brealloc(labelval, 2*label_allocsize*sizeof(labelval[0])); labeltype = Brealloc(labeltype, 2*label_allocsize*sizeof(labeltype[0])); + if (label==NULL || labelval==NULL || labeltype==NULL) { label_allocsize = 0; @@ -748,12 +730,15 @@ static int32_t C_GetKeyword(void) C_SkipComments(); + if (*textptr == 0) + return -1; + temptextptr = textptr; - while (isaltok(*temptextptr) == 0) + while (!isaltok(*temptextptr)) { temptextptr++; - if (*temptextptr == 0) + if (!*temptextptr) return 0; } @@ -761,6 +746,7 @@ static int32_t C_GetKeyword(void) while (isaltok(*temptextptr)) tempbuf[i++] = *(temptextptr++); tempbuf[i] = 0; + return hash_find(&h_keywords, tempbuf); } @@ -770,11 +756,16 @@ static int32_t C_GetNextKeyword(void) //Returns its code # C_SkipComments(); - while (isaltok(*textptr) == 0) + if (*textptr == 0) + return -1; + + while (!isaltok(*textptr)) { - if (*textptr == 0x0a) g_lineNumber++; - if (*textptr == 0) + g_lineNumber += (*textptr == 0x0a); + + if (!*textptr) return -1; + textptr++; } @@ -796,7 +787,8 @@ static int32_t C_GetNextKeyword(void) //Returns its code # { if (i == CON_LEFTBRACE || i == CON_RIGHTBRACE || i == CON_NULLOP) *g_scriptPtr = i + (IFELSE_MAGIC<<12); - else *g_scriptPtr = i + (g_lineNumber<<12); + else + *g_scriptPtr = i + (g_lineNumber<<12); textptr += l; g_scriptPtr++; @@ -810,16 +802,18 @@ static int32_t C_GetNextKeyword(void) //Returns its code # if (tempbuf[0] == '{' && tempbuf[1] != 0) { - C_ReportError(-1); - initprintf("%s:%d: error: expected whitespace between `{' and `%s'.\n",g_szScriptFileName,g_lineNumber,tempbuf+1); + C_CUSTOMERROR("expected whitespace between `{' and `%s'", tempbuf+1); } else if (tempbuf[0] == '}' && tempbuf[1] != 0) { - C_ReportError(-1); - initprintf("%s:%d: error: expected whitespace between `}' and `%s'.\n",g_szScriptFileName,g_lineNumber,tempbuf+1); + C_CUSTOMERROR("expected whitespace between `}' and `%s'", tempbuf+1); } - else C_ReportError(ERROR_EXPECTEDKEYWORD); - g_numCompilerErrors++; + else + { + C_ReportError(ERROR_EXPECTEDKEYWORD); + g_numCompilerErrors++; + } + return -1; } @@ -832,11 +826,17 @@ static void C_GetNextVarType(int32_t type) C_SkipComments(); + if (*textptr == 0) + { + C_CUSTOMERROR("unexpected EOF where variable was expected."); + return; + } + g_wasConstant = 0; // constant where gamevar expected if ((type==0 || type==GAMEVAR_SPECIAL) && !cs.labelsOnly && - (isdigit(*textptr) || ((*textptr == '-') && isdigit(*(textptr+1))))) + (isdigit(textptr[0]) || (textptr[0]=='-' && isdigit(textptr[1])))) { // if (!(g_numCompilerErrors || g_numCompilerWarnings) && g_scriptDebug) // initprintf("%s:%d: debug: accepted constant %d in place of gamevar.\n",g_szScriptFileName,g_lineNumber,atol(textptr)); @@ -847,11 +847,7 @@ static void C_GetNextVarType(int32_t type) num = atoi(textptr); if (type==GAMEVAR_SPECIAL && (num<0 || num>=65536)) - { - C_ReportError(-1); - initprintf("%s:%d: error: array index %d out of bounds. (max: 65535)\n",g_szScriptFileName,g_lineNumber, num); - g_numCompilerErrors++; - } + C_CUSTOMERROR("array index %d out of bounds. (max: 65535)", num); if (g_numCompilerErrors==0 && type!=GAMEVAR_SPECIAL && num != (int16_t)num) { @@ -884,42 +880,47 @@ 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++; + while (!ispecial(*textptr) && *textptr != ']') + textptr++; return; } - else if (*textptr == '-' && *(textptr+1)!='.' /* && !isdigit(*(textptr+1))*/) + else if (textptr[0]=='-' && textptr[1] != '.') // && !isdigit(*(textptr+1)) { if (type==0) { // if (!(g_numCompilerErrors || g_numCompilerWarnings) && g_scriptDebug) // initprintf("%s:%d: debug: flagging gamevar as negative.\n",g_szScriptFileName,g_lineNumber,atol(textptr)); - flags = (MAXGAMEVARS<<1); + flags = M32_FLAG_NEGATE; } else { - g_numCompilerErrors++; - C_ReportError(ERROR_SYNTAXERROR); + C_CUSTOMERROR("error: syntax error. Tried negating written-to variable."); C_GetNextLabelName(); return; } } - else if (type!=GAMEVAR_SPECIAL && (*textptr == '.' || (*textptr == '-' && *(textptr+1)=='.'))) + else if (type != GAMEVAR_SPECIAL && + (textptr[0]=='.' || (textptr[0]=='-' && textptr[1]=='.'))) { - int32_t lLabelID = -1, aridx=g_iThisActorID; + int32_t lLabelID = -1, aridx = M32_THISACTOR_VAR_ID; + + flags |= M32_FLAG_SPECIAL; - flags |= (MAXGAMEVARS<<3); if (*textptr=='-') { - flags |= (MAXGAMEVARS<<1); + flags |= M32_FLAG_NEGATE; textptr++; } textptr++; + /// now pointing at 'xxx' + C_GetNextLabelName(); - lLabelID = C_GetLabelNameID(SpriteLabels, &spriteH, Bstrtolower(tlabel)); + lLabelID = C_GetLabelNameID(SpriteLabels, &h_sprite, Bstrtolower(tlabel)); if (lLabelID == -1) { @@ -928,8 +929,9 @@ static void C_GetNextVarType(int32_t type) return; } - id = g_iSpriteVarID; - *g_scriptPtr++ = (aridx<<16 | id | (lLabelID<<2) | flags); + id = M32_SPRITE_VAR_ID; + *g_scriptPtr++ = ((aridx<<16) | id | (lLabelID<<2) | flags); + return; } @@ -947,7 +949,7 @@ static void C_GetNextVarType(int32_t type) int32_t lLabelID = -1, aridx; textptr++; - flags |= (MAXGAMEVARS<<2); + flags |= M32_FLAG_ARRAY; if (type & GAMEVAR_SPECIAL) { @@ -969,12 +971,13 @@ static void C_GetNextVarType(int32_t type) C_ReportError(ERROR_NOTAGAMEARRAY); return; } - flags &= ~(MAXGAMEVARS<<2); // not an array - flags |= (MAXGAMEVARS<<3); + + flags &= ~M32_FLAG_ARRAY; // not an array + flags |= M32_FLAG_SPECIAL; } else { - if ((aGameArrays[id].dwFlags & GAMEARRAY_READONLY) && type&GAMEVAR_READONLY) + if ((aGameArrays[id].dwFlags & GAMEARRAY_READONLY) && (type&GAMEVAR_READONLY)) { C_ReportError(ERROR_ARRAYREADONLY); g_numCompilerErrors++; @@ -1004,28 +1007,32 @@ static void C_GetNextVarType(int32_t type) // return; // } - if (flags & (MAXGAMEVARS<<3)) + if (flags & M32_FLAG_SPECIAL) { while (*textptr && *textptr != 0x0a && *textptr != '.') textptr++; if (*textptr != '.') { - g_numCompilerErrors++; - C_ReportError(ERROR_SYNTAXERROR); + static const char *types[4] = {"sprite","sector","wall","tsprite"}; + C_CUSTOMERROR("error: syntax error. Expected `.