diff --git a/polymer/eduke32/build/include/build.h b/polymer/eduke32/build/include/build.h index 21d1e7de6..c3a85a491 100644 --- a/polymer/eduke32/build/include/build.h +++ b/polymer/eduke32/build/include/build.h @@ -755,7 +755,11 @@ int32_t md_loadmodel(const char *fn); int32_t md_setmisc(int32_t modelid, float scale, int32_t shadeoff, float zadd, int32_t flags); // int32_t md_tilehasmodel(int32_t tilenume, int32_t pal); +extern char defsfilename[BMAX_PATH]; +extern char *g_defNamePtr; + #ifdef USE_OPENGL + typedef struct { // maps build tiles to particular animation frames of a model diff --git a/polymer/eduke32/build/include/editor.h b/polymer/eduke32/build/include/editor.h index 7840ba673..911072139 100644 --- a/polymer/eduke32/build/include/editor.h +++ b/polymer/eduke32/build/include/editor.h @@ -95,7 +95,6 @@ extern const char *mapster32_fullpath; extern char *testplay_addparam; extern const char *g_namesFileName; -extern const char *defsfilename; // set in bstub.c extern int32_t g_maxCacheSize; extern int32_t g_lazy_tileselector; diff --git a/polymer/eduke32/build/src/build.c b/polymer/eduke32/build/src/build.c index a141703ab..76e0af268 100644 --- a/polymer/eduke32/build/src/build.c +++ b/polymer/eduke32/build/src/build.c @@ -563,7 +563,7 @@ int32_t app_main(int32_t argc, const char **argv) Bstrcpy(kensig,"Uses BUILD technology by Ken Silverman"); initcrc(); - if (!loaddefinitionsfile(defsfilename)) + if (!loaddefinitionsfile(g_defNamePtr)) initprintf("Definitions file loaded.\n"); k = 0; diff --git a/polymer/eduke32/build/src/defs.c b/polymer/eduke32/build/src/defs.c index d54e8b775..f877fcdc8 100644 --- a/polymer/eduke32/build/src/defs.c +++ b/polymer/eduke32/build/src/defs.c @@ -80,7 +80,8 @@ enum scripttoken_t T_CACHESIZE, T_IMPORTTILE, T_MUSIC,T_ID,T_SOUND, - T_TILEFROMTEXTURE, T_XOFFSET, T_YOFFSET + T_TILEFROMTEXTURE, T_XOFFSET, T_YOFFSET, + T_INCLUDEDEFAULT }; typedef struct { const char *text; int32_t tokenid; } tokenlist; @@ -125,6 +126,8 @@ static int32_t defsparser(scriptfile *script) { { "include", T_INCLUDE }, { "#include", T_INCLUDE }, + { "includedefault", T_INCLUDEDEFAULT }, + { "#includedefault", T_INCLUDEDEFAULT }, { "define", T_DEFINE }, { "#define", T_DEFINE }, @@ -206,6 +209,23 @@ static int32_t defsparser(scriptfile *script) } break; } + case T_INCLUDEDEFAULT: + { + scriptfile *included; + + included = scriptfile_fromfile(defsfilename); + if (!included) + { + initprintf("Warning: Failed including %s on line %s:%d\n", + defsfilename, script->filename,scriptfile_getlinum(script,cmdtokptr)); + } + else + { + defsparser(included); + scriptfile_close(included); + } + break; + } case T_DEFINE: { char *name; diff --git a/polymer/eduke32/source/astub.c b/polymer/eduke32/source/astub.c index 6fea6d3d7..cfa909528 100644 --- a/polymer/eduke32/source/astub.c +++ b/polymer/eduke32/source/astub.c @@ -62,20 +62,36 @@ static int32_t g_fillCurSector = 0; static char g_modDir[BMAX_PATH]; // static char *startwin_labeltext = "Starting Mapster32..."; -static char setupfilename[]= "mapster32.cfg"; +static char *setupfilename = "mapster32.cfg"; static char defaultduke3dgrp[BMAX_PATH] = "duke3d.grp"; static char *g_grpNamePtr = defaultduke3dgrp; +char *g_defNamePtr = defsfilename; static int32_t fixmapbeforesaving = 0; static int32_t lastsave = -180*60; static int32_t NoAutoLoad = 0; static int32_t spnoclip=1; -static char default_tiles_cfg[] = "tiles.cfg"; +static char *default_tiles_cfg = "tiles.cfg"; static int32_t pathsearchmode_oninit; // Sound in Mapster32 -static char defaultgamecon[] = "game.con"; -static char *gamecon = defaultgamecon; +static char defaultgamecon[2][BMAX_PATH] = { "eduke.con", "game.con" }; + +char * defaultgameconfile(void) +{ + int32_t script; // scriptfile *script; + + script = kopen4load(defaultgamecon[0],0); // script = scriptfile_fromfile(defaultgamecon[0]); + + if (script >= 0) + return defaultgamecon[0]; + + return defaultgamecon[1]; +} + +static char *gamecon = "\0"; +static int32_t g_skipDefaultCons = 0; +static int32_t g_skipDefaultDefs = 0; // primarily for NAM/WWII GI appeasement #pragma pack(push,1) sound_t g_sounds[MAXSOUNDS]; @@ -8489,6 +8505,10 @@ static void G_CheckCommandLine(int32_t argc, const char **argv) if (!Bstrcasecmp(c+1,"nam")) { Bstrcpy(g_grpNamePtr, "nam.grp"); + Bstrcpy(defaultduke3dgrp, "nam.grp"); + Bstrcpy(defsfilename, "nam.def"); + // Bstrcpy(g_defNamePtr, "nam.def"); + Bstrcpy(defaultgamecon[0], "nam.con"); COPYARG(i); i++; continue; @@ -8508,6 +8528,10 @@ static void G_CheckCommandLine(int32_t argc, const char **argv) if (!Bstrcasecmp(c+1,"ww2gi")) { Bstrcpy(g_grpNamePtr, "ww2gi.grp"); + Bstrcpy(defaultduke3dgrp, "ww2gi.grp"); + Bstrcpy(defaultgamecon[0], "ww2gi.con"); + Bstrcpy(defsfilename, "ww2gi.def"); + // Bstrcpy(g_defNamePtr, "ww2gi.def"); COPYARG(i); i++; continue; @@ -8568,9 +8592,10 @@ static void G_CheckCommandLine(int32_t argc, const char **argv) c++; if (*c) { - defsfilename = c; + g_defNamePtr = c; + g_skipDefaultDefs = 1; COPYARG(i); - initprintf("Using DEF file: %s.\n",defsfilename); + initprintf("Using DEF file: %s.\n",g_defNamePtr); } break; case 'j': @@ -8592,7 +8617,9 @@ static void G_CheckCommandLine(int32_t argc, const char **argv) c++; if (!*c) break; gamecon = c; + g_skipDefaultCons = 1; COPYARG(i); + initprintf("Using CON file '%s'.\n",gamecon); break; } } @@ -8610,14 +8637,17 @@ static void G_CheckCommandLine(int32_t argc, const char **argv) else if (!Bstrcasecmp(k,".def")) { COPYARG(i); - defsfilename = (char *)argv[i++]; - initprintf("Using DEF file: %s.\n",defsfilename); + g_defNamePtr = (char *)argv[i++]; + g_skipDefaultDefs = 1; + initprintf("Using DEF file: %s.\n",g_defNamePtr); continue; } else if (!Bstrcasecmp(k,".con")) { COPYARG(i); gamecon = (char *)argv[i++]; + g_skipDefaultCons = 1; + initprintf("Using CON file '%s'.\n",gamecon); continue; } } @@ -9392,6 +9422,7 @@ enum T_OFFSETA, T_DEFINESOUND, + T_INCLUDEDEFAULT, }; typedef struct @@ -9447,6 +9478,8 @@ int32_t parsegroupfiles(scriptfile *script) { { "include", T_INCLUDE }, { "#include", T_INCLUDE }, + { "includedefault", T_INCLUDEDEFAULT }, + { "#includedefault", T_INCLUDEDEFAULT }, { "loadgrp", T_LOADGRP }, { "noautoload", T_NOAUTOLOAD } }; @@ -9501,6 +9534,24 @@ int32_t parsegroupfiles(scriptfile *script) break; } break; + case T_INCLUDEDEFAULT: + { + scriptfile *included; + + included = scriptfile_fromfile(defsfilename); + if (!included) + { + initprintf("Warning: Failed including %s on line %s:%d\n", + defsfilename, script->filename,scriptfile_getlinum(script,cmdtokptr)); + } + else + { + parsegroupfiles(included); + scriptfile_close(included); + } + break; + } + break; case T_NOAUTOLOAD: NoAutoLoad = 1; break; @@ -9883,6 +9934,8 @@ static int32_t parseconsounds(scriptfile *script) { { "include", T_INCLUDE }, { "#include", T_INCLUDE }, + { "includedefault", T_INCLUDEDEFAULT }, + { "#includedefault", T_INCLUDEDEFAULT }, { "define", T_DEFINE }, { "#define", T_DEFINE }, { "definesound", T_DEFINESOUND }, @@ -9916,6 +9969,25 @@ static int32_t parseconsounds(scriptfile *script) } break; } + case T_INCLUDEDEFAULT: + { + char * fn = defaultgameconfile(); + scriptfile *included; + + included = scriptfile_fromfile(fn); + if (!included) + { + initprintf("Warning: Failed including %s on line %s:%d\n", + fn, script->filename,scriptfile_getlinum(script,cmdtokptr)); + } + else + { + int32_t tmp = parseconsounds(included); + scriptfile_close(included); + if (tmp < 0) return tmp; + } + break; + } case T_DEFINE: { char *name; @@ -10178,10 +10250,15 @@ int32_t ExtInit(void) if (getenv("DUKE3DDEF")) { - defsfilename = getenv("DUKE3DDEF"); - initprintf("Using '%s' as definitions file\n", defsfilename); + g_defNamePtr = getenv("DUKE3DDEF"); + g_skipDefaultDefs = 1; + initprintf("Using '%s' as definitions file\n", g_defNamePtr); } - loadgroupfiles(defsfilename); + if (g_skipDefaultDefs == 0) + Bstrcpy(g_defNamePtr, defsfilename); // it MAY have changed, with NAM/WWII GI + + loadgroupfiles(g_defNamePtr); + // the defs are actually loaded in app_main in build.c { struct strllist *s; @@ -10922,7 +10999,12 @@ void ExtCheckKeys(void) if (!soundinit) { g_numsounds = 0; - loadconsounds(gamecon); + + if (g_skipDefaultCons == 0) + loadconsounds(defaultgameconfile()); // Bstrcpy(gamecon, defaultgameconfile()); + else + loadconsounds(gamecon); + if (g_numsounds > 0) { if (S_SoundStartup() != 0) diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index 85bd52af8..476959e60 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -105,6 +105,7 @@ uint8_t water_pal[768],slime_pal[768],title_pal[768],dre_alms[768],ending_pal[76 uint8_t *basepaltable[BASEPALCOUNT] = { palette, water_pal, slime_pal, dre_alms, title_pal, ending_pal, NULL }; static int32_t g_skipDefaultCons = 0; +static int32_t g_skipDefaultDefs = 0; // primarily for NAM/WWII GI appeasement int32_t voting = -1; int32_t vote_map = -1, vote_episode = -1; @@ -114,12 +115,12 @@ static int32_t g_noLogoAnim = 0; static int32_t g_noLogo = 0; char defaultduke3dgrp[BMAX_PATH] = "duke3d.grp"; -static char defaultduke3ddef[BMAX_PATH] = "duke3d.def"; -static char defaultconfilename[BMAX_PATH] = { "EDUKE.CON" }; +char defsfilename[BMAX_PATH] = "duke3d.def"; +static char defaultconfilename[2][BMAX_PATH] = { "EDUKE.CON", "GAME.CON" }; char *g_grpNamePtr = defaultduke3dgrp; -char *g_defNamePtr = defaultduke3ddef; -char *g_scriptNamePtr = defaultconfilename; +char *g_defNamePtr = defsfilename; +char *g_scriptNamePtr = defaultconfilename[0]; char *g_gameNamePtr = NULL; extern int32_t lastvisinc; @@ -183,6 +184,18 @@ int32_t kopen4loadfrommod(const char *filename, char searchfirst) return r; } +char * defaultconfile(void) +{ + int32_t i; + + i = kopen4load(defaultconfilename[0],0); + + if (i >= 0) + return defaultconfilename[0]; + + return defaultconfilename[1]; +} + enum gametokens { T_EOF = -2, @@ -194,6 +207,7 @@ enum gametokens T_CACHESIZE = 2, T_ALLOW = 2, T_NOAUTOLOAD, + T_INCLUDEDEFAULT, T_MUSIC, T_SOUND, T_FILE, @@ -1869,6 +1883,8 @@ void G_FadePalette(int32_t r,int32_t g,int32_t b,int32_t e) void fadepal(int32_t r, int32_t g, int32_t b, int32_t start, int32_t end, int32_t step) { + if (getrendermode() >= 3) return; + if (step > 0) { for (; start < end; start += step) @@ -8006,6 +8022,8 @@ static int32_t parsedefinitions_game(scriptfile *script, const int32_t preload) { { "include", T_INCLUDE }, { "#include", T_INCLUDE }, + { "includedefault", T_INCLUDEDEFAULT }, + { "#includedefault", T_INCLUDEDEFAULT }, { "loadgrp", T_LOADGRP }, { "cachesize", T_CACHESIZE }, { "noautoload", T_NOAUTOLOAD }, @@ -8075,6 +8093,22 @@ static int32_t parsedefinitions_game(scriptfile *script, const int32_t preload) } break; } + case T_INCLUDEDEFAULT: + { + scriptfile *included = scriptfile_fromfile(defsfilename); + + if (!included) + { +// initprintf("Warning: Failed including %s on line %s:%d\n", +// defsfilename, script->filename,scriptfile_getlinum(script,cmdtokptr)); + } + else + { + parsedefinitions_game(included, preload); + scriptfile_close(included); + } + break; + } case T_NOAUTOLOAD: if (preload) g_noAutoLoad = 1; @@ -8343,18 +8377,20 @@ static void G_CheckCommandLine(int32_t argc, const char **argv) } if (!Bstrcasecmp(c+1,"nam")) { - Bsprintf(defaultduke3dgrp, "nam.grp"); - Bsprintf(defaultduke3ddef, "nam.def"); - Bsprintf(defaultconfilename, "nam.con"); + Bstrcpy(defaultduke3dgrp, "nam.grp"); + Bstrcpy(defsfilename, "nam.def"); + // Bstrcpy(g_defNamePtr, "nam.def"); + Bstrcpy(defaultconfilename[0], "nam.con"); g_gameType = GAME_NAM; i++; continue; } if (!Bstrcasecmp(c+1,"ww2gi")) { - Bsprintf(defaultduke3dgrp, "ww2gi.grp"); - Bsprintf(defaultduke3ddef, "ww2gi.def"); - Bsprintf(defaultconfilename, "ww2gi.con"); + Bstrcpy(defaultduke3dgrp, "ww2gi.grp"); + Bstrcpy(defsfilename, "ww2gi.def"); + // Bstrcpy(g_defNamePtr, "ww2gi.def"); + Bstrcpy(defaultconfilename[0], "ww2gi.con"); g_gameType = GAME_WW2; i++; continue; @@ -8567,6 +8603,7 @@ static void G_CheckCommandLine(int32_t argc, const char **argv) if (*c) { g_defNamePtr = c; + g_skipDefaultDefs = 1; initprintf("Using DEF file: %s.\n",g_defNamePtr); } break; @@ -8739,6 +8776,7 @@ static void G_CheckCommandLine(int32_t argc, const char **argv) if (!Bstrcasecmp(k,".def")) { g_defNamePtr = (char *)argv[i++]; + g_skipDefaultDefs = 1; initprintf("Using DEF file: %s.\n",g_defNamePtr); continue; } @@ -9002,7 +9040,7 @@ void G_Shutdown(void) static void G_CompileScripts(void) { - int32_t i, psm = pathsearchmode; + int32_t psm = pathsearchmode; label = (char *)&sprite[0]; // V8: 16384*44/64 = 11264 V7: 4096*44/64 = 2816 labelcode = (intptr_t *)§or[0]; // V8: 4096*40/4 = 40960 V7: 1024*40/4 = 10240 @@ -9013,24 +9051,15 @@ static void G_CompileScripts(void) pathsearchmode = 1; if (g_skipDefaultCons == 0) { - i = kopen4loadfrommod(g_scriptNamePtr,0); - if (i!=-1) - kclose(i); - else Bsprintf(g_scriptNamePtr,"GAME.CON"); + Bsprintf(g_scriptNamePtr,defaultconfile()); } C_Compile(g_scriptNamePtr); - if (g_loadFromGroupOnly) + if (g_loadFromGroupOnly) // g_loadFromGroupOnly is true only when compiling fails and internal defaults are utilized { if (g_skipDefaultCons == 0) { - i = kopen4loadfrommod("EDUKE.CON",1); - if (i!=-1) - { - Bsprintf(g_scriptNamePtr,"EDUKE.CON"); - kclose(i); - } - else Bsprintf(g_scriptNamePtr,"GAME.CON"); + Bsprintf(g_scriptNamePtr,defaultconfile()); } C_Compile(g_scriptNamePtr); } @@ -9541,7 +9570,11 @@ int32_t app_main(int32_t argc,const char **argv) #endif i = CONFIG_ReadSetup(); - if (getenv("DUKE3DGRP")) g_grpNamePtr = getenv("DUKE3DGRP"); + if (getenv("DUKE3DGRP")) + { + g_grpNamePtr = getenv("DUKE3DGRP"); + initprintf("Using %s as main GRP file\n", g_grpNamePtr); + } #ifdef _WIN32 @@ -9649,12 +9682,13 @@ int32_t app_main(int32_t argc,const char **argv) { // overwrite the default GRP and CON so that if the user chooses // something different, they get what they asked for - Bsprintf(defaultduke3dgrp, WW2GI ? "ww2gi.grp" : "nam.grp"); - Bsprintf(defaultduke3ddef, WW2GI ? "ww2gi.def" : "nam.def"); - Bsprintf(defaultconfilename, WW2GI ? "ww2gi.con" : "nam.con"); + Bstrcpy(defaultduke3dgrp, WW2GI ? "ww2gi.grp" : "nam.grp"); + Bstrcpy(defsfilename, WW2GI ? "ww2gi.def" : "nam.def"); + // Bstrcpy(g_defNamePtr, WW2GI ? "ww2gi.def" : "nam.def"); + Bstrcpy(defaultconfilename[0], WW2GI ? "ww2gi.con" : "nam.con"); - Bsprintf(GametypeNames[0],"GRUNTMATCH (SPAWN)"); - Bsprintf(GametypeNames[2],"GRUNTMATCH (NO SPAWN)"); + Bstrcpy(GametypeNames[0],"GRUNTMATCH (SPAWN)"); + Bstrcpy(GametypeNames[2],"GRUNTMATCH (NO SPAWN)"); } if (g_modDir[0] != '/') @@ -9804,6 +9838,15 @@ CLEAN_DIRECTORY: } } + if (getenv("DUKE3DDEF")) + { + g_defNamePtr = getenv("DUKE3DDEF"); + g_skipDefaultDefs = 1; + initprintf("Using '%s' as definitions file\n", g_defNamePtr); + } + if (g_skipDefaultDefs == 0) + Bstrcpy(g_defNamePtr, defsfilename); // it MAY have changed, with NAM/WWII GI + flushlogwindow = 0; loaddefinitions_game(g_defNamePtr, TRUE); // flushlogwindow = 1; diff --git a/polymer/eduke32/source/game.h b/polymer/eduke32/source/game.h index 5c8a2b72f..b3c9d6b45 100644 --- a/polymer/eduke32/source/game.h +++ b/polymer/eduke32/source/game.h @@ -26,9 +26,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define USERQUOTE_LEFTOFFSET 5 #define USERQUOTE_RIGHTOFFSET 14 -#define MAXCHEATLEN 20 -#define NUMCHEATCODES (int32_t)(sizeof(CheatStrings)/sizeof(CheatStrings[0])) - enum GametypeFlags_t { GAMETYPE_COOP = 0x00000001, GAMETYPE_WEAPSTAY = 0x00000002, @@ -254,6 +251,7 @@ int32_t G_PrintGameText(int32_t f,int32_t tile,int32_t x,int32_t y,const char *t int32_t GetTime(void); int32_t _EnterText(int32_t small,int32_t x,int32_t y,char *t,int32_t dalen,int32_t c); int32_t kopen4loadfrommod(const char *filename,char searchfirst); +char * defaultconfile(void); int32_t minitext_(int32_t x,int32_t y,const char *t,int32_t s,int32_t p,int32_t sb); extern inline int32_t mpgametext(int32_t y,const char *t,int32_t s,int32_t dabits); int32_t startwin_run(void); diff --git a/polymer/eduke32/source/gamedef.c b/polymer/eduke32/source/gamedef.c index 22a262ad8..905b2d69e 100644 --- a/polymer/eduke32/source/gamedef.c +++ b/polymer/eduke32/source/gamedef.c @@ -81,6 +81,7 @@ static struct { uint32_t keyw; uint32_t date; } g_keywdate[] = { CON_IFSERVER, 20100722 }, { CON_CALCHYPOTENUSE, 20100927 }, { CON_CLIPMOVENOSLIDE, 20101009 }, + { CON_INCLUDEDEFAULT, 20110615 }, }; char g_szScriptFileName[BMAX_PATH] = "(none)"; // file we're currently compiling @@ -559,6 +560,7 @@ const char *keyw[] = "rayintersect", // 357 "calchypotenuse", // 358 "clipmovenoslide", // 359 + "includedefault", // 360 "" }; @@ -1113,7 +1115,7 @@ static int32_t C_SetScriptSize(int32_t newsize) if ((intptr_t)script[i] < (intptr_t)&script[0] || (intptr_t)script[i] >= (intptr_t)&script[g_scriptSize]) { g_numCompilerErrors++; - initprintf("Internal compiler error at %"PRIdPTR" (0x%"PRIxPTR")\n",i,i); + initprintf("Internal compiler error at %" PRIdPTR " (0x%" PRIxPTR ")\n",i,i); } scriptptrs[i] = 1; @@ -2356,7 +2358,7 @@ static int32_t C_ParseCommand(int32_t loop) { int32_t temp_ScriptLineNumber; - int32_t temp_ifelse_check; + int32_t temp_ifelse_check; char *origtptr, *mptr; char parentScriptFileName[255]; int32_t fp; @@ -2414,6 +2416,71 @@ static int32_t C_ParseCommand(int32_t loop) } continue; + case CON_INCLUDEDEFAULT: + C_SkipComments(); + + { + char * confile = defaultconfile(); + + int32_t temp_ScriptLineNumber; + int32_t temp_ifelse_check; + char *origtptr, *mptr; + char parentScriptFileName[255]; + int32_t fp; + + fp = kopen4loadfrommod(confile,g_loadFromGroupOnly); + if (fp < 0) + { + g_numCompilerErrors++; + initprintf("%s:%d: error: could not find file `%s'.\n",g_szScriptFileName,g_lineNumber,confile); + continue; + } + + j = kfilelength(fp); + + mptr = (char *)Bmalloc(j+1); + if (!mptr) + { + kclose(fp); + g_numCompilerErrors++; + initprintf("%s:%d: error: could not allocate %d bytes to include `%s'.\n", + g_szScriptFileName,g_lineNumber,j,confile); + continue; + } + + initprintf("Including: %s (%d bytes)\n",confile, j); + kread(fp, mptr, j); + kclose(fp); + mptr[j] = 0; + + if (*textptr == '"') // skip past the closing quote if it's there so we don't screw up the next line + textptr++; + origtptr = textptr; + + Bstrcpy(parentScriptFileName, g_szScriptFileName); + Bstrcpy(g_szScriptFileName, confile); + temp_ScriptLineNumber = g_lineNumber; + g_lineNumber = 1; + temp_ifelse_check = g_checkingIfElse; + g_checkingIfElse = 0; + + textptr = mptr; + + C_SkipComments(); + + C_ParseCommand(1); + + Bstrcpy(g_szScriptFileName, parentScriptFileName); + g_totalLines += g_lineNumber; + g_lineNumber = temp_ScriptLineNumber; + g_checkingIfElse = temp_ifelse_check; + + textptr = origtptr; + + Bfree(mptr); + } + continue; + case CON_AI: if (g_parsingActorPtr || g_processingState) { diff --git a/polymer/eduke32/source/gamedef.h b/polymer/eduke32/source/gamedef.h index b259c5ae6..d8fcd5197 100644 --- a/polymer/eduke32/source/gamedef.h +++ b/polymer/eduke32/source/gamedef.h @@ -27,6 +27,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define LABEL_HASPARM2 1 #define LABEL_ISSTRING 2 +#define MAXCHEATLEN 20 +#define NUMCHEATCODES (int32_t)(sizeof(CheatStrings)/sizeof(CheatStrings[0])) + extern hashtable_t h_gamevars; extern hashtable_t h_arrays; extern hashtable_t h_keywords; @@ -162,8 +165,7 @@ enum ScriptError_t WARNING_DUPLICATEDEFINITION, WARNING_EVENTSYNC, WARNING_LABELSONLY, - WARNING_NAMEMATCHESVAR, - WARNING_REVEVENTSYNC + WARNING_NAMEMATCHESVAR }; enum PlayerLabel_t @@ -926,11 +928,12 @@ enum ScriptKeywords_t CON_IFSERVER, // 352 CON_SECTSETINTERPOLATION, // 353 CON_SECTCLEARINTERPOLATION, // 354 - CON_CLIPMOVE, // 355 - CON_LINEINTERSECT, // 356 - CON_RAYINTERSECT, // 357 - CON_CALCHYPOTENUSE, // 358 - CON_CLIPMOVENOSLIDE, // 359 + CON_CLIPMOVE, // 355 + CON_LINEINTERSECT, // 356 + CON_RAYINTERSECT, // 357 + CON_CALCHYPOTENUSE, // 358 + CON_CLIPMOVENOSLIDE, // 359 + CON_INCLUDEDEFAULT, // 360 CON_END }; #endif diff --git a/polymer/eduke32/source/gameexec.c b/polymer/eduke32/source/gameexec.c index 7c96ceb28..af85cdb0d 100644 --- a/polymer/eduke32/source/gameexec.c +++ b/polymer/eduke32/source/gameexec.c @@ -51,10 +51,13 @@ int32_t g_errorLineNum; int32_t g_tw; extern int32_t ticrandomseed; -GAMEEXEC_STATIC int32_t VM_Execute(int32_t once); +GAMEEXEC_STATIC void VM_Execute(int32_t loop); #include "gamestructures.c" +#define VM_CONDITIONAL(xxx) { if ((xxx) || ((insptr = (intptr_t *)*(insptr+1)) && (((*insptr) & 0xfff) == CON_ELSE))) \ +{ insptr += 2; VM_Execute(0); } } + void VM_ScriptInfo(void) { intptr_t *p; @@ -97,7 +100,7 @@ void VM_OnEvent(register int32_t iEventID, register int32_t iActor, register int Bmemcpy(&vm_backup, &vm, sizeof(vmstate_t)); Bmemcpy(&vm, &tempvm, sizeof(vmstate_t)); - VM_Execute(0); + VM_Execute(1); if (vm.g_flags & VM_KILL) { @@ -127,7 +130,7 @@ static inline int32_t VM_CheckSquished(void) if (A_CheckEnemySprite(vm.g_sp)) vm.g_sp->xvel = 0; - if (vm.g_sp->pal == 1) + if (vm.g_sp->pal == 1) // frozen { actor[vm.g_i].picnum = SHOTSPARK1; actor[vm.g_i].extra = 1; @@ -386,10 +389,10 @@ int32_t G_GetAngleDelta(int32_t a,int32_t na) GAMEEXEC_STATIC GAMEEXEC_INLINE void VM_AlterAng(int32_t a) { - intptr_t *moveptr; + intptr_t *moveptr = (intptr_t *)vm.g_t[1]; int32_t ticselapsed = (vm.g_t[0])&31; - if ((moveptr = (intptr_t *)vm.g_t[1]) < &script[0] || moveptr > &script[g_scriptSize]) + if (moveptr < &script[0] || moveptr > &script[g_scriptSize]) { vm.g_t[1] = 0; OSD_Printf(OSD_ERROR "bad moveptr for actor %d (%d)!\n", vm.g_i, vm.g_sp->picnum); @@ -443,17 +446,14 @@ GAMEEXEC_STATIC GAMEEXEC_INLINE void VM_AlterAng(int32_t a) if (ticselapsed < 1) { - int32_t j = 2; if (a&furthestdir) { - vm.g_sp->ang = A_GetFurthestAngle(vm.g_i,j); + vm.g_sp->ang = A_GetFurthestAngle(vm.g_i, 2); vm.g_sp->owner = g_player[vm.g_p].ps->i; } if (a&fleeenemy) - { - vm.g_sp->ang = A_GetFurthestAngle(vm.g_i,j); // += angdif; // = G_GetAngleDelta(aang,goalang)>>1; - } + vm.g_sp->ang = A_GetFurthestAngle(vm.g_i, 2); } } @@ -480,7 +480,9 @@ GAMEEXEC_STATIC void VM_Move(void) return; } - if (a&face_player && !deadflag) + if (deadflag) goto dead; + + if (a&face_player) { if (g_player[vm.g_p].ps->newowner >= 0) goalang = getangle(g_player[vm.g_p].ps->opos.x-vm.g_sp->x,g_player[vm.g_p].ps->opos.y-vm.g_sp->y); @@ -491,10 +493,10 @@ GAMEEXEC_STATIC void VM_Move(void) vm.g_sp->ang += angdif; } - if (a&spin && !deadflag) + if (a&spin) vm.g_sp->ang += sintable[((vm.g_t[0]<<3)&2047)]>>6; - if (a&face_player_slow && !deadflag) + if (a&face_player_slow) { if (g_player[vm.g_p].ps->newowner >= 0) goalang = getangle(g_player[vm.g_p].ps->opos.x-vm.g_sp->x,g_player[vm.g_p].ps->opos.y-vm.g_sp->y); @@ -505,13 +507,13 @@ GAMEEXEC_STATIC void VM_Move(void) vm.g_sp->ang += angdif; } - if (((a&jumptoplayer) == jumptoplayer) && !deadflag) + if (((a&jumptoplayer) == jumptoplayer)) { if (vm.g_t[0] < 16) vm.g_sp->zvel -= (sintable[(512+(vm.g_t[0]<<4))&2047]>>5); } - if (a&face_player_smart && !deadflag) + if (a&face_player_smart) { int32_t newx = g_player[vm.g_p].ps->pos.x+(g_player[vm.g_p].ps->vel.x/768); int32_t newy = g_player[vm.g_p].ps->pos.y+(g_player[vm.g_p].ps->vel.y/768); @@ -523,10 +525,11 @@ GAMEEXEC_STATIC void VM_Move(void) vm.g_sp->ang += angdif; } +dead: if ((moveptr = (intptr_t *)vm.g_t[1]) < &script[0] || moveptr > &script[g_scriptSize]) { vm.g_t[1] = 0; - OSD_Printf(OSD_ERROR "bad moveptr for actor %d (%d)!\n", vm.g_i, vm.g_sp->picnum); + OSD_Printf(OSD_ERROR "clearing bad moveptr for actor %d (%d)\n", vm.g_i, vm.g_sp->picnum); return; } @@ -654,36 +657,19 @@ GAMEEXEC_STATIC void VM_Move(void) if (sector[vm.g_sp->sectnum].ceilingstat&1) vm.g_sp->shade += (sector[vm.g_sp->sectnum].ceilingshade-vm.g_sp->shade)>>1; else vm.g_sp->shade += (sector[vm.g_sp->sectnum].floorshade-vm.g_sp->shade)>>1; - -// wtf? - /* - if (sector[vm.g_sp->sectnum].floorpicnum == MIRROR) - deletesprite(vm.g_i); - */ } -GAMEEXEC_STATIC GAMEEXEC_INLINE void __fastcall VM_DoConditional(register int32_t condition) -{ - if (condition || ((insptr = (intptr_t *)*(insptr+1)) && (((*insptr) & 0xfff) == CON_ELSE))) - { - // skip 'else' pointer.. and... - insptr += 2; - VM_Execute(1); - return; - } -} - -GAMEEXEC_STATIC int32_t VM_Execute(int32_t once) +GAMEEXEC_STATIC void VM_Execute(int32_t loop) { register int32_t tw = *insptr; // jump directly into the loop, saving us from the checks during the first iteration goto skip_check; - while (!once) + while (loop) { if (vm.g_flags & (VM_RETURN|VM_KILL|VM_NOEXECUTE)) - return 1; + return; tw = *insptr; @@ -722,64 +708,72 @@ skip_check: } case CON_IFRND: - VM_DoConditional(rnd(*(++insptr))); + VM_CONDITIONAL(rnd(*(++insptr))); continue; case CON_IFCANSHOOTTARGET: { int32_t j; + if (vm.g_x > 1024) { - int16_t temphit, sclip = 768, angdif = 16; + int16_t temphit; - j = A_CheckHitSprite(vm.g_i,&temphit); - - if (A_CheckEnemySprite(vm.g_sp) && vm.g_sp->xrepeat > 56) + if ((j = A_CheckHitSprite(vm.g_i,&temphit)) == (1<<30)) { - sclip = 3084; - angdif = 48; + VM_CONDITIONAL(1); + continue; } - if (j == (1<<30)) { - VM_DoConditional(1); - break; - } - if (j > sclip) - { - if (temphit >= 0 && sprite[temphit].picnum == vm.g_sp->picnum) - j = 0; - else + int32_t sclip = 768, angdif = 16; + + if (A_CheckEnemySprite(vm.g_sp) && vm.g_sp->xrepeat > 56) { + sclip = 3084; + angdif = 48; + } + + if (j > sclip) + { + if (temphit >= 0 && sprite[temphit].picnum == vm.g_sp->picnum) + { + VM_CONDITIONAL(0); + continue; + } + vm.g_sp->ang += angdif; j = A_CheckHitSprite(vm.g_i,&temphit); vm.g_sp->ang -= angdif; + if (j > sclip) { if (temphit >= 0 && sprite[temphit].picnum == vm.g_sp->picnum) - j = 0; - else { - vm.g_sp->ang -= angdif; - j = A_CheckHitSprite(vm.g_i,&temphit); - vm.g_sp->ang += angdif; - if (j > 768) + VM_CONDITIONAL(0); + continue; + } + + vm.g_sp->ang -= angdif; + j = A_CheckHitSprite(vm.g_i,&temphit); + vm.g_sp->ang += angdif; + + if (j > 768) + { + if (temphit >= 0 && sprite[temphit].picnum == vm.g_sp->picnum) { - if (temphit >= 0 && sprite[temphit].picnum == vm.g_sp->picnum) - j = 0; - else j = 1; + VM_CONDITIONAL(0); + continue; } - else j = 0; + + VM_CONDITIONAL(1); + continue; } } - else j = 0; } } - else j = 0; } - else j = 1; - - VM_DoConditional(j); + VM_CONDITIONAL(1); } continue; @@ -788,13 +782,13 @@ skip_check: int32_t j = cansee(vm.g_sp->x,vm.g_sp->y,vm.g_sp->z-((krand()&41)<<8), vm.g_sp->sectnum,g_player[vm.g_p].ps->pos.x,g_player[vm.g_p].ps->pos.y, g_player[vm.g_p].ps->pos.z/*-((krand()&41)<<8)*/,sprite[g_player[vm.g_p].ps->i].sectnum); - VM_DoConditional(j); + VM_CONDITIONAL(j); if (j) actor[vm.g_i].timetosleep = SLEEPTIME; } continue; case CON_IFACTORNOTSTAYPUT: - VM_DoConditional(actor[vm.g_i].actorstayput == -1); + VM_CONDITIONAL(actor[vm.g_i].actorstayput == -1); continue; case CON_IFCANSEE: @@ -844,23 +838,23 @@ skip_check: if (j && (vm.g_sp->statnum == STAT_ACTOR || vm.g_sp->statnum == STAT_STANDABLE)) actor[vm.g_i].timetosleep = SLEEPTIME; - VM_DoConditional(j); + VM_CONDITIONAL(j); continue; } case CON_IFHITWEAPON: - VM_DoConditional(A_IncurDamage(vm.g_i) >= 0); + VM_CONDITIONAL(A_IncurDamage(vm.g_i) >= 0); continue; case CON_IFSQUISHED: - VM_DoConditional(VM_CheckSquished()); + VM_CONDITIONAL(VM_CheckSquished()); continue; case CON_IFDEAD: // j = vm.g_sp->extra; // if (vm.g_sp->picnum == APLAYER) // j--; - VM_DoConditional(vm.g_sp->extra <= 0); + VM_CONDITIONAL(vm.g_sp->extra <= 0); continue; case CON_AI: @@ -884,13 +878,13 @@ skip_check: continue; case CON_IFPDISTL: - VM_DoConditional(vm.g_x < *(++insptr)); + VM_CONDITIONAL(vm.g_x < *(++insptr)); if (vm.g_x > MAXSLEEPDIST && actor[vm.g_i].timetosleep == 0) actor[vm.g_i].timetosleep = SLEEPTIME; continue; case CON_IFPDISTG: - VM_DoConditional(vm.g_x > *(++insptr)); + VM_CONDITIONAL(vm.g_x > *(++insptr)); if (vm.g_x > MAXSLEEPDIST && actor[vm.g_i].timetosleep == 0) actor[vm.g_i].timetosleep = SLEEPTIME; continue; @@ -921,17 +915,17 @@ skip_check: if (g_player[vm.g_p].ps->weaprecs[j] == vm.g_sp->picnum) break; - VM_DoConditional(j < g_player[vm.g_p].ps->weapreccnt && vm.g_sp->owner == vm.g_i); + VM_CONDITIONAL(j < g_player[vm.g_p].ps->weapreccnt && vm.g_sp->owner == vm.g_i); continue; } else if (g_player[vm.g_p].ps->weapreccnt < MAX_WEAPONS) { g_player[vm.g_p].ps->weaprecs[g_player[vm.g_p].ps->weapreccnt++] = vm.g_sp->picnum; - VM_DoConditional(vm.g_sp->owner == vm.g_i); + VM_CONDITIONAL(vm.g_sp->owner == vm.g_i); continue; } } - VM_DoConditional(0); + VM_CONDITIONAL(0); continue; case CON_GETLASTPAL: @@ -1031,7 +1025,7 @@ skip_check: continue; } insptr--; - VM_DoConditional(A_CheckSoundPlaying(i,j)); + VM_CONDITIONAL(A_CheckSoundPlaying(i,j)); } continue; @@ -1042,7 +1036,7 @@ skip_check: insptr++; continue; } - VM_DoConditional(S_CheckSoundPlaying(vm.g_i,*insptr)); + VM_CONDITIONAL(S_CheckSoundPlaying(vm.g_i,*insptr)); // VM_DoConditional(SoundOwner[*insptr][0].i == vm.g_i); continue; @@ -1203,10 +1197,10 @@ skip_check: case CON_ENDA: case CON_BREAK: case CON_ENDS: - return 1; + return; case CON_RIGHTBRACE: insptr++; - return 1; + return; case CON_ADDAMMO: if (((unsigned)*(++insptr) >= MAX_WEAPONS)) { @@ -1377,14 +1371,14 @@ skip_check: intptr_t *tempscrptr=insptr+2; insptr = (intptr_t *) *(insptr+1); - VM_Execute(0); + VM_Execute(1); insptr = tempscrptr; } continue; case CON_LEFTBRACE: insptr++; - VM_Execute(0); + VM_Execute(1); continue; case CON_MOVE: @@ -1477,26 +1471,19 @@ skip_check: } case CON_OPERATERESPAWNS: + insptr++; + G_OperateRespawns(Gv_GetVarX(*insptr++)); + continue; + case CON_OPERATEMASTERSWITCHES: + insptr++; + G_OperateMasterSwitches(Gv_GetVarX(*insptr++)); + continue; + case CON_CHECKACTIVATORMOTION: insptr++; - { - int32_t var1 = Gv_GetVarX(*insptr++); - - switch (tw) - { - case CON_OPERATERESPAWNS: - G_OperateRespawns(var1); - break; - case CON_OPERATEMASTERSWITCHES: - G_OperateMasterSwitches(var1); - break; - case CON_CHECKACTIVATORMOTION: - Gv_SetVarX(g_iReturnVarID, G_CheckActivatorMotion(var1)); - break; - } - continue; - } + aGameVars[g_iReturnVarID].val.lValue = G_CheckActivatorMotion(Gv_GetVarX(*insptr++)); + continue; case CON_INSERTSPRITEQ: insptr++; @@ -1606,21 +1593,23 @@ skip_check: insptr++; { int32_t i = Gv_GetVarX(*insptr++), - f=Gv_GetVarX(*insptr++); - int32_t j=Gv_GetVarX(*insptr++); - if ((i<0 || i>=MAXQUOTES)) + f = Gv_GetVarX(*insptr++); + int32_t j = Gv_GetVarX(*insptr++); + + if ((unsigned)i >= MAXQUOTES) OSD_Printf(CON_ERROR "invalid quote ID %d\n",g_errorLineNum,keyw[g_tw],i); else if ((ScriptQuotes[i] == NULL)) OSD_Printf(CON_ERROR "null quote %d\n",g_errorLineNum,keyw[g_tw],i); - else if ((f<0 || f>=NUMGAMEFUNCTIONS)) + else if ((unsigned)f >= NUMGAMEFUNCTIONS) OSD_Printf(CON_ERROR "invalid function %d\n",g_errorLineNum,keyw[g_tw],f); else { - if (j<2) + if (j < 2) Bstrcpy(tempbuf,KB_ScanCodeToString(ud.config.KeyboardKeys[f][j])); else { Bstrcpy(tempbuf,KB_ScanCodeToString(ud.config.KeyboardKeys[f][0])); + if (!*tempbuf) Bstrcpy(tempbuf,KB_ScanCodeToString(ud.config.KeyboardKeys[f][1])); } @@ -1628,8 +1617,10 @@ skip_check: if (*tempbuf) Bstrcpy(ScriptQuotes[i],tempbuf); + continue; } + case CON_QSUBSTR: insptr++; { @@ -1887,11 +1878,10 @@ nullquote: // For each case: value, ptr to code //AddLog("Processing Switch..."); int32_t lValue=Gv_GetVarX(*insptr++), lEnd=*insptr++, lCases=*insptr++; - intptr_t *lpDefault=insptr++, *lpCases=insptr, *lTempInsPtr; + intptr_t *lpDefault=insptr++, *lpCases=insptr; int32_t bMatched=0, lCheckCase; int32_t left,right; insptr += lCases*2; - lTempInsPtr=insptr; //Bsprintf(g_szBuf,"lEnd= %d *lpDefault=%d",lEnd,*lpDefault); //AddLog(g_szBuf); @@ -1918,7 +1908,7 @@ nullquote: insptr=(intptr_t *)(lpCases[lCheckCase*2+1] + &script[0]); //Bsprintf(g_szBuf,"insptr=%d. ", (int32_t)insptr); //AddLog(g_szBuf); - VM_Execute(0); + VM_Execute(1); //AddLog("Done Executing Case"); bMatched=1; } @@ -1931,7 +1921,7 @@ nullquote: { //AddLog("No Matching Case: Using Default"); insptr=(intptr_t *)(*lpDefault + &script[0]); - VM_Execute(0); + VM_Execute(1); } else { @@ -1949,7 +1939,7 @@ nullquote: case CON_ENDSWITCH: case CON_ENDEVENT: insptr++; - return 1; + return; case CON_DISPLAYRAND: insptr++; @@ -2774,29 +2764,32 @@ nullquote: case CON_SPAWN: insptr++; - if ((unsigned)vm.g_sp->sectnum < MAXSECTORS) - A_Spawn(vm.g_i,*insptr); - insptr++; + if ((unsigned)vm.g_sp->sectnum >= MAXSECTORS) + { + insptr++; + continue; + } + A_Spawn(vm.g_i,*insptr++); continue; case CON_IFWASWEAPON: insptr++; - VM_DoConditional(actor[vm.g_i].picnum == *insptr); + VM_CONDITIONAL(actor[vm.g_i].picnum == *insptr); continue; case CON_IFAI: insptr++; - VM_DoConditional(vm.g_t[5] == *insptr); + VM_CONDITIONAL(vm.g_t[5] == *insptr); continue; case CON_IFACTION: insptr++; - VM_DoConditional(vm.g_t[4] == *insptr); + VM_CONDITIONAL(vm.g_t[4] == *insptr); continue; case CON_IFACTIONCOUNT: insptr++; - VM_DoConditional(vm.g_t[2] >= *insptr); + VM_CONDITIONAL(vm.g_t[2] >= *insptr); continue; case CON_RESETACTIONCOUNT: @@ -2897,7 +2890,7 @@ nullquote: case CON_IFMOVE: insptr++; - VM_DoConditional(vm.g_t[1] == *insptr); + VM_CONDITIONAL(vm.g_t[1] == *insptr); continue; case CON_RESETPLAYER: @@ -2947,21 +2940,21 @@ nullquote: continue; case CON_IFONWATER: - VM_DoConditional(sector[vm.g_sp->sectnum].lotag == 1 && klabs(vm.g_sp->z-sector[vm.g_sp->sectnum].floorz) < (32<<8)); + VM_CONDITIONAL(sector[vm.g_sp->sectnum].lotag == 1 && klabs(vm.g_sp->z-sector[vm.g_sp->sectnum].floorz) < (32<<8)); continue; case CON_IFINWATER: - VM_DoConditional(sector[vm.g_sp->sectnum].lotag == 2); + VM_CONDITIONAL(sector[vm.g_sp->sectnum].lotag == 2); continue; case CON_IFCOUNT: insptr++; - VM_DoConditional(vm.g_t[0] >= *insptr); + VM_CONDITIONAL(vm.g_t[0] >= *insptr); continue; case CON_IFACTOR: insptr++; - VM_DoConditional(vm.g_sp->picnum == *insptr); + VM_CONDITIONAL(vm.g_sp->picnum == *insptr); continue; case CON_RESETCOUNT: @@ -3100,13 +3093,13 @@ nullquote: else j = 0; } - VM_DoConditional((intptr_t) j); + VM_CONDITIONAL((intptr_t) j); } continue; case CON_IFSTRENGTH: insptr++; - VM_DoConditional(vm.g_sp->extra <= *insptr); + VM_CONDITIONAL(vm.g_sp->extra <= *insptr); continue; case CON_GUTS: @@ -3116,7 +3109,7 @@ nullquote: case CON_IFSPAWNEDBY: insptr++; - VM_DoConditional(actor[vm.g_i].picnum == *insptr); + VM_CONDITIONAL(actor[vm.g_i].picnum == *insptr); continue; case CON_WACKPLAYER: @@ -3166,27 +3159,27 @@ nullquote: case CON_IFGAPZL: insptr++; - VM_DoConditional(((actor[vm.g_i].floorz - actor[vm.g_i].ceilingz) >> 8) < *insptr); + VM_CONDITIONAL(((actor[vm.g_i].floorz - actor[vm.g_i].ceilingz) >> 8) < *insptr); continue; case CON_IFHITSPACE: - VM_DoConditional(TEST_SYNC_KEY(g_player[vm.g_p].sync->bits, SK_OPEN)); + VM_CONDITIONAL(TEST_SYNC_KEY(g_player[vm.g_p].sync->bits, SK_OPEN)); continue; case CON_IFOUTSIDE: - VM_DoConditional(sector[vm.g_sp->sectnum].ceilingstat&1); + VM_CONDITIONAL(sector[vm.g_sp->sectnum].ceilingstat&1); continue; case CON_IFMULTIPLAYER: - VM_DoConditional((g_netServer || g_netClient || ud.multimode > 1)); + VM_CONDITIONAL((g_netServer || g_netClient || ud.multimode > 1)); continue; case CON_IFCLIENT: - VM_DoConditional(g_netClient != NULL); + VM_CONDITIONAL(g_netClient != NULL); continue; case CON_IFSERVER: - VM_DoConditional(g_netServer != NULL); + VM_CONDITIONAL(g_netServer != NULL); continue; case CON_OPERATE: @@ -3214,7 +3207,7 @@ nullquote: continue; case CON_IFINSPACE: - VM_DoConditional(G_CheckForSpaceCeiling(vm.g_sp->sectnum)); + VM_CONDITIONAL(G_CheckForSpaceCeiling(vm.g_sp->sectnum)); continue; case CON_SPRITEPAL: @@ -3230,26 +3223,26 @@ nullquote: continue; case CON_IFBULLETNEAR: - VM_DoConditional(A_Dodge(vm.g_sp) == 1); + VM_CONDITIONAL(A_Dodge(vm.g_sp) == 1); continue; case CON_IFRESPAWN: if (A_CheckEnemySprite(vm.g_sp)) - VM_DoConditional(ud.respawn_monsters); + VM_CONDITIONAL(ud.respawn_monsters) else if (A_CheckInventorySprite(vm.g_sp)) - VM_DoConditional(ud.respawn_inventory); + VM_CONDITIONAL(ud.respawn_inventory) else - VM_DoConditional(ud.respawn_items); + VM_CONDITIONAL(ud.respawn_items) continue; case CON_IFFLOORDISTL: insptr++; - VM_DoConditional((actor[vm.g_i].floorz - vm.g_sp->z) <= ((*insptr)<<8)); + VM_CONDITIONAL((actor[vm.g_i].floorz - vm.g_sp->z) <= ((*insptr)<<8)); continue; case CON_IFCEILINGDISTL: insptr++; - VM_DoConditional((vm.g_sp->z - actor[vm.g_i].ceilingz) <= ((*insptr)<<8)); + VM_CONDITIONAL((vm.g_sp->z - actor[vm.g_i].ceilingz) <= ((*insptr)<<8)); continue; case CON_PALFROM: @@ -3954,6 +3947,12 @@ nullquote: case CON_SETVAR: insptr++; + if ((aGameVars[*insptr].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK)) == 0) + { + aGameVars[*insptr].val.lValue = *(insptr+1); + insptr += 2; + continue; + } Gv_SetVarX(*insptr, *(insptr+1)); insptr += 2; continue; @@ -4080,13 +4079,19 @@ nullquote: continue; case CON_INV: + if ((aGameVars[*(insptr+1)].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK)) == 0) + { + aGameVars[*(insptr+1)].val.lValue = -aGameVars[*(insptr+1)].val.lValue; + insptr += 2; + continue; + } Gv_SetVarX(*(insptr+1), -Gv_GetVarX(*(insptr+1))); insptr += 2; continue; case CON_MULVAR: insptr++; - Gv_SetVarX(*insptr, Gv_GetVarX(*insptr) * *(insptr+1)); + Gv_MulVar(*insptr, *(insptr+1)); insptr += 2; continue; @@ -4098,7 +4103,7 @@ nullquote: insptr += 2; continue; } - Gv_SetVarX(*insptr, Gv_GetVarX(*insptr) / *(insptr+1)); + Gv_DivVar(*insptr, *(insptr+1)); insptr += 2; continue; @@ -4110,25 +4115,26 @@ nullquote: insptr += 2; continue; } - Gv_SetVarX(*insptr,Gv_GetVarX(*insptr)%*(insptr+1)); + + Gv_ModVar(*insptr,*(insptr+1)); insptr += 2; continue; case CON_ANDVAR: insptr++; - Gv_SetVarX(*insptr,Gv_GetVarX(*insptr) & *(insptr+1)); + Gv_AndVar(*insptr,*(insptr+1)); insptr += 2; continue; case CON_ORVAR: insptr++; - Gv_SetVarX(*insptr,Gv_GetVarX(*insptr) | *(insptr+1)); + Gv_OrVar(*insptr,*(insptr+1)); insptr += 2; continue; case CON_XORVAR: insptr++; - Gv_SetVarX(*insptr,Gv_GetVarX(*insptr) ^ *(insptr+1)); + Gv_XorVar(*insptr,*(insptr+1)); insptr += 2; continue; @@ -4136,6 +4142,12 @@ nullquote: insptr++; { int32_t j=*insptr++; + if ((aGameVars[j].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK)) == 0) + { + aGameVars[j].val.lValue = Gv_GetVarX(*insptr++); + continue; + } + Gv_SetVarX(j, Gv_GetVarX(*insptr++)); } continue; @@ -4188,7 +4200,8 @@ nullquote: insptr++; { int32_t j=*insptr++; - Gv_SetVarX(j, Gv_GetVarX(j)*Gv_GetVarX(*insptr++)); + + Gv_MulVar(j, Gv_GetVarX(*insptr++)); } continue; @@ -4198,12 +4211,13 @@ nullquote: int32_t j=*insptr++; int32_t l2=Gv_GetVarX(*insptr++); - if (l2==0) + if (!l2) { OSD_Printf(CON_ERROR "Divide by zero.\n",g_errorLineNum,keyw[g_tw]); continue; } - Gv_SetVarX(j, Gv_GetVarX(j)/l2); + + Gv_DivVar(j, l2); continue; } @@ -4213,13 +4227,14 @@ nullquote: int32_t j=*insptr++; int32_t l2=Gv_GetVarX(*insptr++); - if (l2==0) + if (!l2) { OSD_Printf(CON_ERROR "Mod by zero.\n",g_errorLineNum,keyw[g_tw]); continue; } - Gv_SetVarX(j, Gv_GetVarX(j) % l2); + + Gv_ModVar(j, l2); continue; } @@ -4227,7 +4242,7 @@ nullquote: insptr++; { int32_t j=*insptr++; - Gv_SetVarX(j, Gv_GetVarX(j) & Gv_GetVarX(*insptr++)); + Gv_AndVar(j, Gv_GetVarX(*insptr++)); } continue; @@ -4235,7 +4250,7 @@ nullquote: insptr++; { int32_t j=*insptr++; - Gv_SetVarX(j, Gv_GetVarX(j) ^ Gv_GetVarX(*insptr++)); + Gv_XorVar(j, Gv_GetVarX(*insptr++)); } continue; @@ -4243,13 +4258,13 @@ nullquote: insptr++; { int32_t j=*insptr++; - Gv_SetVarX(j, Gv_GetVarX(j) | Gv_GetVarX(*insptr++)); + Gv_OrVar(j, Gv_GetVarX(*insptr++)); } continue; case CON_SUBVAR: insptr++; - Gv_SetVarX(*insptr, Gv_GetVarX(*insptr) - *(insptr+1)); + Gv_SubVar(*insptr, *(insptr+1)); insptr += 2; continue; @@ -4257,24 +4272,36 @@ nullquote: insptr++; { int32_t j=*insptr++; - Gv_SetVarX(j, Gv_GetVarX(j) - Gv_GetVarX(*insptr++)); + Gv_SubVar(j, Gv_GetVarX(*insptr++)); } continue; case CON_ADDVAR: insptr++; - Gv_SetVarX(*insptr, Gv_GetVarX(*insptr) + *(insptr+1)); + Gv_AddVar(*insptr, *(insptr+1)); insptr += 2; continue; case CON_SHIFTVARL: insptr++; + if ((aGameVars[*insptr].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK)) == 0) + { + aGameVars[*insptr].val.lValue <<= *(insptr+1); + insptr += 2; + continue; + } Gv_SetVarX(*insptr, Gv_GetVarX(*insptr) << *(insptr+1)); insptr += 2; continue; case CON_SHIFTVARR: insptr++; + if ((aGameVars[*insptr].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK)) == 0) + { + aGameVars[*insptr].val.lValue >>= *(insptr+1); + insptr += 2; + continue; + } Gv_SetVarX(*insptr, Gv_GetVarX(*insptr) >> *(insptr+1)); insptr += 2; continue; @@ -4295,33 +4322,33 @@ nullquote: insptr++; { int32_t j=*insptr++; - Gv_SetVarX(j, Gv_GetVarX(j) + Gv_GetVarX(*insptr++)); + Gv_AddVar(j, Gv_GetVarX(*insptr++)); } continue; case CON_SPGETLOTAG: insptr++; - Gv_SetVarX(g_iLoTagID, vm.g_sp->lotag); + aGameVars[g_iLoTagID].val.lValue = vm.g_sp->lotag; continue; case CON_SPGETHITAG: insptr++; - Gv_SetVarX(g_iHiTagID, vm.g_sp->hitag); + aGameVars[g_iHiTagID].val.lValue = vm.g_sp->hitag; continue; case CON_SECTGETLOTAG: insptr++; - Gv_SetVarX(g_iLoTagID, sector[vm.g_sp->sectnum].lotag); + aGameVars[g_iLoTagID].val.lValue = sector[vm.g_sp->sectnum].lotag; continue; case CON_SECTGETHITAG: insptr++; - Gv_SetVarX(g_iHiTagID, sector[vm.g_sp->sectnum].hitag); + aGameVars[g_iHiTagID].val.lValue = sector[vm.g_sp->sectnum].hitag; continue; case CON_GETTEXTUREFLOOR: insptr++; - Gv_SetVarX(g_iTextureID, sector[vm.g_sp->sectnum].floorpicnum); + aGameVars[g_iTextureID].val.lValue = sector[vm.g_sp->sectnum].floorpicnum; continue; case CON_STARTTRACK: @@ -4357,7 +4384,7 @@ nullquote: case CON_GETTEXTURECEILING: insptr++; - Gv_SetVarX(g_iTextureID, sector[vm.g_sp->sectnum].ceilingpicnum); + aGameVars[g_iTextureID].val.lValue = sector[vm.g_sp->sectnum].ceilingpicnum; continue; case CON_IFVARVARAND: @@ -4366,7 +4393,7 @@ nullquote: int32_t j = Gv_GetVarX(*insptr++); j &= Gv_GetVarX(*insptr++); insptr--; - VM_DoConditional(j); + VM_CONDITIONAL(j); } continue; @@ -4376,7 +4403,7 @@ nullquote: int32_t j = Gv_GetVarX(*insptr++); j |= Gv_GetVarX(*insptr++); insptr--; - VM_DoConditional(j); + VM_CONDITIONAL(j); } continue; @@ -4386,7 +4413,7 @@ nullquote: int32_t j = Gv_GetVarX(*insptr++); j ^= Gv_GetVarX(*insptr++); insptr--; - VM_DoConditional(j); + VM_CONDITIONAL(j); } continue; @@ -4396,7 +4423,7 @@ nullquote: int32_t j = Gv_GetVarX(*insptr++); int32_t l = Gv_GetVarX(*insptr++); insptr--; - VM_DoConditional(j || l); + VM_CONDITIONAL(j || l); } continue; @@ -4406,7 +4433,7 @@ nullquote: int32_t j = Gv_GetVarX(*insptr++); j = (j != Gv_GetVarX(*insptr++)); insptr--; - VM_DoConditional(j); + VM_CONDITIONAL(j); } continue; @@ -4416,7 +4443,7 @@ nullquote: int32_t j = Gv_GetVarX(*insptr++); j = (j == Gv_GetVarX(*insptr++)); insptr--; - VM_DoConditional(j); + VM_CONDITIONAL(j); } continue; @@ -4426,7 +4453,7 @@ nullquote: int32_t j = Gv_GetVarX(*insptr++); j = (j > Gv_GetVarX(*insptr++)); insptr--; - VM_DoConditional(j); + VM_CONDITIONAL(j); } continue; @@ -4436,7 +4463,7 @@ nullquote: int32_t j = Gv_GetVarX(*insptr++); j = (j < Gv_GetVarX(*insptr++)); insptr--; - VM_DoConditional(j); + VM_CONDITIONAL(j); } continue; @@ -4444,7 +4471,7 @@ nullquote: insptr++; { int32_t j=Gv_GetVarX(*insptr++); - VM_DoConditional(j == *insptr); + VM_CONDITIONAL(j == *insptr); } continue; @@ -4452,7 +4479,7 @@ nullquote: insptr++; { int32_t j=Gv_GetVarX(*insptr++); - VM_DoConditional(j != *insptr); + VM_CONDITIONAL(j != *insptr); } continue; @@ -4464,7 +4491,7 @@ nullquote: { insptr=savedinsptr; j = (Gv_GetVarX(*(insptr-1)) != *insptr); - VM_DoConditional(j); + VM_CONDITIONAL(j); } while (j); continue; @@ -4480,7 +4507,7 @@ nullquote: j = Gv_GetVarX(*(insptr-1)); j = (j != Gv_GetVarX(*insptr++)); insptr--; - VM_DoConditional(j); + VM_CONDITIONAL(j); } while (j); continue; @@ -4490,7 +4517,7 @@ nullquote: insptr++; { int32_t j=Gv_GetVarX(*insptr++); - VM_DoConditional(j & *insptr); + VM_CONDITIONAL(j & *insptr); } continue; @@ -4498,7 +4525,7 @@ nullquote: insptr++; { int32_t j=Gv_GetVarX(*insptr++); - VM_DoConditional(j | *insptr); + VM_CONDITIONAL(j | *insptr); } continue; @@ -4506,7 +4533,7 @@ nullquote: insptr++; { int32_t j=Gv_GetVarX(*insptr++); - VM_DoConditional(j ^ *insptr); + VM_CONDITIONAL(j ^ *insptr); } continue; @@ -4514,7 +4541,7 @@ nullquote: insptr++; { int32_t j=Gv_GetVarX(*insptr++); - VM_DoConditional(j || *insptr); + VM_CONDITIONAL(j || *insptr); } continue; @@ -4522,7 +4549,7 @@ nullquote: insptr++; { int32_t j=Gv_GetVarX(*insptr++); - VM_DoConditional(j > *insptr); + VM_CONDITIONAL(j > *insptr); } continue; @@ -4530,13 +4557,13 @@ nullquote: insptr++; { int32_t j=Gv_GetVarX(*insptr++); - VM_DoConditional(j < *insptr); + VM_CONDITIONAL(j < *insptr); } continue; case CON_IFPHEALTHL: insptr++; - VM_DoConditional(sprite[g_player[vm.g_p].ps->i].extra < *insptr); + VM_CONDITIONAL(sprite[g_player[vm.g_p].ps->i].extra < *insptr); continue; case CON_IFPINVENTORY: @@ -4589,7 +4616,7 @@ nullquote: OSD_Printf(CON_ERROR "invalid inventory ID: %d\n",g_errorLineNum,keyw[g_tw],(int32_t)*(insptr-1)); } - VM_DoConditional(j); + VM_CONDITIONAL(j); continue; } @@ -4635,7 +4662,7 @@ nullquote: } } } - VM_DoConditional(j); + VM_CONDITIONAL(j); } continue; @@ -4674,11 +4701,11 @@ nullquote: continue; case CON_IFINOUTERSPACE: - VM_DoConditional(G_CheckForSpaceFloor(vm.g_sp->sectnum)); + VM_CONDITIONAL(G_CheckForSpaceFloor(vm.g_sp->sectnum)); continue; case CON_IFNOTMOVING: - VM_DoConditional((actor[vm.g_i].movflag&49152) > 16384); + VM_CONDITIONAL((actor[vm.g_i].movflag&49152) > 16384); continue; case CON_RESPAWNHITAG: @@ -4708,14 +4735,14 @@ nullquote: case CON_IFSPRITEPAL: insptr++; - VM_DoConditional(vm.g_sp->pal == *insptr); + VM_CONDITIONAL(vm.g_sp->pal == *insptr); continue; case CON_IFANGDIFFL: insptr++; { int32_t j = klabs(G_GetAngleDelta(g_player[vm.g_p].ps->ang,vm.g_sp->ang)); - VM_DoConditional(j <= *insptr); + VM_CONDITIONAL(j <= *insptr); } continue; @@ -4736,7 +4763,7 @@ nullquote: break; } - VM_DoConditional(j < 0); + VM_CONDITIONAL(j < 0); } continue; @@ -4747,10 +4774,7 @@ nullquote: case CON_GETTICKS: insptr++; - { - int32_t j=*insptr++; - Gv_SetVarX(j, getticks()); - } + Gv_SetVarX(*insptr++, getticks()); continue; case CON_GETCURRADDRESS: @@ -4762,11 +4786,11 @@ nullquote: continue; case CON_JUMP: - insptr++; - { - int32_t j = Gv_GetVarX(*insptr++); - insptr = (intptr_t *)(j+script); - } + insptr++; + { + int32_t j = Gv_GetVarX(*insptr++); + insptr = (intptr_t *)(j+script); + } continue; default: @@ -4781,8 +4805,6 @@ nullquote: break; } } - - return 0; } void A_LoadActor(int32_t iActor) @@ -4807,7 +4829,7 @@ void A_LoadActor(int32_t iActor) return; } - VM_Execute(0); + VM_Execute(1); if (vm.g_flags & VM_KILL) deletesprite(vm.g_i); @@ -4858,7 +4880,7 @@ void A_Execute(int32_t iActor,int32_t iPlayer,int32_t lDist) vm.g_t[3] = 0; } - VM_Execute(0); + VM_Execute(1); if (vm.g_flags & VM_KILL) { diff --git a/polymer/eduke32/source/gamevars.c b/polymer/eduke32/source/gamevars.c index c3344ff95..f6519180a 100644 --- a/polymer/eduke32/source/gamevars.c +++ b/polymer/eduke32/source/gamevars.c @@ -669,8 +669,7 @@ void __fastcall Gv_SetVar(register int32_t id, register int32_t lValue, register //Bsprintf(g_szBuf,"SGVI: %d ('%s') to %d for %d %d",id,aGameVars[id].szLabel,lValue,iActor,iPlayer); //AddLog(g_szBuf); - switch (aGameVars[id].dwFlags & - (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK)) + switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK)) { default: aGameVars[id].val.lValue=lValue; @@ -780,8 +779,7 @@ int32_t __fastcall Gv_GetVarX(register int32_t id) goto badvarid; } - switch (aGameVars[id].dwFlags & - (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK)) + switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK)) { default: return ((aGameVars[id].val.lValue ^ -negateResult) + negateResult); @@ -813,8 +811,7 @@ wtf: void __fastcall Gv_SetVarX(register int32_t id, register int32_t lValue) { - switch (aGameVars[id].dwFlags & - (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK)) + switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK)) { default: aGameVars[id].val.lValue=lValue; diff --git a/polymer/eduke32/source/gamevars.h b/polymer/eduke32/source/gamevars.h index a091ffcbb..582f17a9f 100644 --- a/polymer/eduke32/source/gamevars.h +++ b/polymer/eduke32/source/gamevars.h @@ -23,6 +23,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef __gamevars_h__ #define __gamevars_h__ +#include "gamedef.h" + // store global game definitions enum GamevarFlags_t { MAXGAMEVARS = 2048, // must be a power of two @@ -43,6 +45,7 @@ enum GamevarFlags_t { GAMEVAR_NORESET = 0x00020000, // var values are not reset when restoring map state GAMEVAR_SPECIAL = 0x00040000, // flag for structure member shortcut vars GAMEVAR_NOMULTI = 0x00080000, // don't attach to multiplayer packets + GAMEVAR_NONGLOBAL = (GAMEVAR_INTPTR|GAMEVAR_SHORTPTR|GAMEVAR_CHARPTR|GAMEVAR_SPECIAL|MAXGAMEVARS<<1), }; enum GamearrayFlags_t { @@ -94,4 +97,221 @@ void Gv_RefreshPointers(void); void Gv_ResetSystemDefaults(void); void Gv_ResetVars(void); void Gv_WriteSave(FILE *fil,int32_t newbehav); + +static inline void __fastcall Gv_AddVar(register int32_t id, register int32_t lValue) +{ + switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK)) + { + default: + aGameVars[id].val.lValue += lValue; + return; + case GAMEVAR_PERPLAYER: + if ((unsigned)vm.g_p > MAXPLAYERS-1) return; + aGameVars[id].val.plValues[vm.g_p] += lValue; + return; + case GAMEVAR_PERACTOR: + if ((unsigned)vm.g_i > MAXSPRITES-1) return; + aGameVars[id].val.plValues[vm.g_i] += lValue; + return; + case GAMEVAR_INTPTR: + *((int32_t *)aGameVars[id].val.lValue) += (int32_t)lValue; + return; + case GAMEVAR_SHORTPTR: + *((int16_t *)aGameVars[id].val.lValue) += (int16_t)lValue; + return; + case GAMEVAR_CHARPTR: + *((uint8_t *)aGameVars[id].val.lValue) +=(uint8_t)lValue; + return; + } +} + +static inline void __fastcall Gv_SubVar(register int32_t id, register int32_t lValue) +{ + switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK)) + { + default: + aGameVars[id].val.lValue -= lValue; + return; + case GAMEVAR_PERPLAYER: + if ((unsigned)vm.g_p > MAXPLAYERS-1) return; + aGameVars[id].val.plValues[vm.g_p] -= lValue; + return; + case GAMEVAR_PERACTOR: + if ((unsigned)vm.g_i > MAXSPRITES-1) return; + aGameVars[id].val.plValues[vm.g_i] -= lValue; + return; + case GAMEVAR_INTPTR: + *((int32_t *)aGameVars[id].val.lValue) -= (int32_t)lValue; + return; + case GAMEVAR_SHORTPTR: + *((int16_t *)aGameVars[id].val.lValue) -= (int16_t)lValue; + return; + case GAMEVAR_CHARPTR: + *((uint8_t *)aGameVars[id].val.lValue) -=(uint8_t)lValue; + return; + } +} + +static inline void __fastcall Gv_MulVar(register int32_t id, register int32_t lValue) +{ + switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK)) + { + default: + aGameVars[id].val.lValue *= lValue; + return; + case GAMEVAR_PERPLAYER: + if ((unsigned)vm.g_p > MAXPLAYERS-1) return; + aGameVars[id].val.plValues[vm.g_p] *= lValue; + return; + case GAMEVAR_PERACTOR: + if ((unsigned)vm.g_i > MAXSPRITES-1) return; + aGameVars[id].val.plValues[vm.g_i] *= lValue; + return; + case GAMEVAR_INTPTR: + *((int32_t *)aGameVars[id].val.lValue) *= (int32_t)lValue; + return; + case GAMEVAR_SHORTPTR: + *((int16_t *)aGameVars[id].val.lValue) *= (int16_t)lValue; + return; + case GAMEVAR_CHARPTR: + *((uint8_t *)aGameVars[id].val.lValue) *=(uint8_t)lValue; + return; + } +} + +static inline void __fastcall Gv_DivVar(register int32_t id, register int32_t lValue) +{ + switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK)) + { + default: + aGameVars[id].val.lValue /= lValue; + return; + case GAMEVAR_PERPLAYER: + if ((unsigned)vm.g_p > MAXPLAYERS-1) return; + aGameVars[id].val.plValues[vm.g_p] /= lValue; + return; + case GAMEVAR_PERACTOR: + if ((unsigned)vm.g_i > MAXSPRITES-1) return; + aGameVars[id].val.plValues[vm.g_i] /= lValue; + return; + case GAMEVAR_INTPTR: + *((int32_t *)aGameVars[id].val.lValue) /= (int32_t)lValue; + return; + case GAMEVAR_SHORTPTR: + *((int16_t *)aGameVars[id].val.lValue) /= (int16_t)lValue; + return; + case GAMEVAR_CHARPTR: + *((uint8_t *)aGameVars[id].val.lValue) /=(uint8_t)lValue; + return; + } +} + +static inline void __fastcall Gv_ModVar(register int32_t id, register int32_t lValue) +{ + switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK)) + { + default: + aGameVars[id].val.lValue %= lValue; + return; + case GAMEVAR_PERPLAYER: + if ((unsigned)vm.g_p > MAXPLAYERS-1) return; + aGameVars[id].val.plValues[vm.g_p] %= lValue; + return; + case GAMEVAR_PERACTOR: + if ((unsigned)vm.g_i > MAXSPRITES-1) return; + aGameVars[id].val.plValues[vm.g_i] %= lValue; + return; + case GAMEVAR_INTPTR: + *((int32_t *)aGameVars[id].val.lValue) %= (int32_t)lValue; + return; + case GAMEVAR_SHORTPTR: + *((int16_t *)aGameVars[id].val.lValue) %= (int16_t)lValue; + return; + case GAMEVAR_CHARPTR: + *((uint8_t *)aGameVars[id].val.lValue) %=(uint8_t)lValue; + return; + } +} + +static inline void __fastcall Gv_AndVar(register int32_t id, register int32_t lValue) +{ + switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK)) + { + default: + aGameVars[id].val.lValue &= lValue; + return; + case GAMEVAR_PERPLAYER: + if ((unsigned)vm.g_p > MAXPLAYERS-1) return; + aGameVars[id].val.plValues[vm.g_p] &= lValue; + return; + case GAMEVAR_PERACTOR: + if ((unsigned)vm.g_i > MAXSPRITES-1) return; + aGameVars[id].val.plValues[vm.g_i] &= lValue; + return; + case GAMEVAR_INTPTR: + *((int32_t *)aGameVars[id].val.lValue) &= (int32_t)lValue; + return; + case GAMEVAR_SHORTPTR: + *((int16_t *)aGameVars[id].val.lValue) &= (int16_t)lValue; + return; + case GAMEVAR_CHARPTR: + *((uint8_t *)aGameVars[id].val.lValue) &=(uint8_t)lValue; + return; + } +} + +static inline void __fastcall Gv_XorVar(register int32_t id, register int32_t lValue) +{ + switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK)) + { + default: + aGameVars[id].val.lValue ^= lValue; + return; + case GAMEVAR_PERPLAYER: + if ((unsigned)vm.g_p > MAXPLAYERS-1) return; + aGameVars[id].val.plValues[vm.g_p] ^= lValue; + return; + case GAMEVAR_PERACTOR: + if ((unsigned)vm.g_i > MAXSPRITES-1) return; + aGameVars[id].val.plValues[vm.g_i] ^= lValue; + return; + case GAMEVAR_INTPTR: + *((int32_t *)aGameVars[id].val.lValue) ^= (int32_t)lValue; + return; + case GAMEVAR_SHORTPTR: + *((int16_t *)aGameVars[id].val.lValue) ^= (int16_t)lValue; + return; + case GAMEVAR_CHARPTR: + *((uint8_t *)aGameVars[id].val.lValue) ^=(uint8_t)lValue; + return; + } +} + +static inline void __fastcall Gv_OrVar(register int32_t id, register int32_t lValue) +{ + switch (aGameVars[id].dwFlags & (GAMEVAR_USER_MASK|GAMEVAR_PTR_MASK)) + { + default: + aGameVars[id].val.lValue |= lValue; + return; + case GAMEVAR_PERPLAYER: + if ((unsigned)vm.g_p > MAXPLAYERS-1) return; + aGameVars[id].val.plValues[vm.g_p] |= lValue; + return; + case GAMEVAR_PERACTOR: + if ((unsigned)vm.g_i > MAXSPRITES-1) return; + aGameVars[id].val.plValues[vm.g_i] |= lValue; + return; + case GAMEVAR_INTPTR: + *((int32_t *)aGameVars[id].val.lValue) |= (int32_t)lValue; + return; + case GAMEVAR_SHORTPTR: + *((int16_t *)aGameVars[id].val.lValue) |= (int16_t)lValue; + return; + case GAMEVAR_CHARPTR: + *((uint8_t *)aGameVars[id].val.lValue) |=(uint8_t)lValue; + return; + } +} + #endif diff --git a/polymer/eduke32/source/mapster32.h b/polymer/eduke32/source/mapster32.h index 639fbc4c6..355f69fdc 100644 --- a/polymer/eduke32/source/mapster32.h +++ b/polymer/eduke32/source/mapster32.h @@ -26,7 +26,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // #define VULGARITY -const char *defsfilename = "duke3d.def"; +char defsfilename[BMAX_PATH] = "duke3d.def"; #define COLOR_RED 248 #define COLOR_WHITE 31 diff --git a/polymer/eduke32/source/sector.c b/polymer/eduke32/source/sector.c index 608988c7d..e2eb39ec3 100644 --- a/polymer/eduke32/source/sector.c +++ b/polymer/eduke32/source/sector.c @@ -194,7 +194,8 @@ inline int32_t G_CheckPlayerInSector(int32_t sect) { int32_t i; TRAVERSE_CONNECT(i) - if (sprite[g_player[i].ps->i].sectnum == sect) return i; + if ((unsigned)g_player[i].ps->i < MAXSPRITES && sprite[g_player[i].ps->i].sectnum == sect) + return i; return -1; } @@ -484,38 +485,27 @@ int32_t G_ActivateWarpElevators(int32_t s,int32_t d) //Parm = sectoreffectornum while (i >= 0) { - if (SLT == 17) - if (SHT == sprite[s].hitag) - if ((klabs(sector[sn].floorz-actor[s].t_data[2]) > SP) || - (sector[SECT].hitag == (sector[sn].hitag-d))) - break; + if (SLT == 17 && SHT == sprite[s].hitag) + if ((klabs(sector[sn].floorz-actor[s].t_data[2]) > SP) || + (sector[SECT].hitag == (sector[sn].hitag-d))) + break; i = nextspritestat[i]; } - if (i==-1) - { - d = 0; + if (i == -1) return 1; // No find - } else - { - if (d == 0) - A_PlaySound(ELEVATOR_OFF,s); - else A_PlaySound(ELEVATOR_ON,s); - } - + A_PlaySound(d ? ELEVATOR_ON : ELEVATOR_OFF, s); i = headspritestat[STAT_EFFECTOR]; - while (i >= 0) + do { - if (SLT == 17) - if (SHT == sprite[s].hitag) - { - T1 = d; - T2 = d; //Make all check warp - } + if (SLT == 17 && SHT == sprite[s].hitag) + T1 = T2 = d; //Make all check warp i = nextspritestat[i]; } + while (i >= 0); + return 0; } @@ -530,8 +520,7 @@ void G_OperateSectors(int32_t sn, int32_t ii) case 30: j = sector[sn].hitag; - if (actor[j].tempang == 0 || - actor[j].tempang == 256) + if (actor[j].tempang == 0 || actor[j].tempang == 256) A_CallSound(sn,ii); if (sprite[j].extra == 1) sprite[j].extra = 3; @@ -548,8 +537,7 @@ void G_OperateSectors(int32_t sn, int32_t ii) break; case 26: //The split doors - i = GetAnimationGoal(&sptr->ceilingz); - if (i == -1) //if the door has stopped + if (GetAnimationGoal(&sptr->ceilingz) == -1) //if the door has stopped { g_haltSoundHack = 1; sptr->lotag &= 0xff00; diff --git a/polymer/eduke32/source/sounds.c b/polymer/eduke32/source/sounds.c index a5a5e10de..7ea578f85 100644 --- a/polymer/eduke32/source/sounds.c +++ b/polymer/eduke32/source/sounds.c @@ -57,14 +57,17 @@ void S_SoundStartup(void) initdata = (void *) win_gethwnd(); #endif - initprintf("Initializing sound...\n"); + initprintf("Initializing sound... "); if (FX_Init(fxdevicetype, ud.config.NumVoices, ud.config.NumChannels, ud.config.NumBits, ud.config.MixRate, initdata) != FX_Ok) { - initprintf("%s\n", FX_ErrorString(FX_Error)); + initprintf("failed! %s\n", FX_ErrorString(FX_Error)); return; } + initprintf("%d voices, %d channels, %d-bit %dKHz\n", ud.config.NumVoices, ud.config.NumChannels, + ud.config.NumBits, ud.config.MixRate); + for (i=g_maxSoundPos; i >= 0 ; i--) { int32_t j = MAXSOUNDINSTANCES-1;