From fc287ec735b03bdef16d0816baa365f847e5c4c7 Mon Sep 17 00:00:00 2001 From: terminx Date: Sat, 21 Apr 2007 20:25:07 +0000 Subject: [PATCH] Prototype for user-defined tile groups git-svn-id: https://svn.eduke32.com/eduke32@536 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/build/src/build.c | 6 +- polymer/eduke32/source/astub.c | 257 +++++++++++++++++++++++++---- polymer/eduke32/source/game.c | 19 ++- polymer/eduke32/source/mapster32.h | 157 ++---------------- 4 files changed, 261 insertions(+), 178 deletions(-) diff --git a/polymer/build/src/build.c b/polymer/build/src/build.c index 7d19470ac..9f19869a6 100644 --- a/polymer/build/src/build.c +++ b/polymer/build/src/build.c @@ -1489,6 +1489,7 @@ void editinput(void) } } } +# if 0 if (keystatus[0x2f] > 0) //V { if (searchstat == 0) templong = wall[searchwall].picnum; @@ -1510,7 +1511,7 @@ void editinput(void) asksave = 1; keystatus[0x2f] = 0; } - +#endif if (keystatus[0x1a]) // [ { keystatus[0x1a] = 0; @@ -2439,7 +2440,7 @@ char changechar(char dachar, long dadir, char smooshyalign, char boundcheck) } return(dachar); } - +#if 0 long gettile(long tilenum) { char snotbuf[80], ch; @@ -2740,6 +2741,7 @@ long drawtilescreen(long pictopleft, long picbox) return(0); } +#endif void overheadeditor(void) { diff --git a/polymer/eduke32/source/astub.c b/polymer/eduke32/source/astub.c index a091b2c1f..cf18fe428 100644 --- a/polymer/eduke32/source/astub.c +++ b/polymer/eduke32/source/astub.c @@ -1755,13 +1755,13 @@ static long m32gettile(long idInitialTile) nYTiles = ydim / ZoomToThumbSize[s_Zoom]; nDisplayedTiles = nXTiles * nYTiles; - if (0 == nDisplayedTiles) + if (!nDisplayedTiles) { // Eh-up, resolution changed since we were last displaying tiles. s_Zoom--; } } - while (0 == nDisplayedTiles) ; + while (!nDisplayedTiles); keystatus[0x2F] = 0; @@ -1868,7 +1868,7 @@ static long m32gettile(long idInitialTile) // Check : If no tiles used at all then switch to displaying all tiles // - if (0 == localartfreq[0]) + if (!localartfreq[0]) { localartlookupnum = MAXTILES; @@ -1911,6 +1911,7 @@ static long m32gettile(long idInitialTile) { if (quitevent) quitevent = 0; } + idle(); // These two lines are so obvious I don't need to comment them ...;-) synctics = totalclock-lockclock; @@ -2005,14 +2006,14 @@ static long m32gettile(long idInitialTile) // Ensure tilenum is within valid range // - while (iTile < 0) + if (iTile < 0) { - iTile += nXTiles; + iTile = 0; } - while (iTile >= MAXTILES) // shouldn't this be the count of num tiles ??? + if (iTile >= MAXTILES) // shouldn't this be the count of num tiles ??? { - iTile -= nXTiles; + iTile = MAXTILES-1; } // 'V' KEYPRESS @@ -2037,6 +2038,7 @@ static long m32gettile(long idInitialTile) SelectAllTiles(iTile); iTile = FIRST_USER_ART_TILE; + keystatus[0x16] = 0; } // 'A' KEYPRESS : Go straight to start of Atomic edition's art @@ -2045,6 +2047,7 @@ static long m32gettile(long idInitialTile) SelectAllTiles(iTile); iTile = FIRST_ATOMIC_TILE; + keystatus[0x1e] = 0; } // 'T' KEYPRESS = Select from pre-defined tileset @@ -2055,6 +2058,18 @@ static long m32gettile(long idInitialTile) iTile = OnSelectTile(iTile); } + // 'E' KEYPRESS : Go straight to start of extended art + if (keystatus[0x12]) + { + SelectAllTiles(iTile); + + if (iTile == FIRST_EXTENDED_TILE) + iTile = SECOND_EXTENDED_TILE; + else iTile = FIRST_EXTENDED_TILE; + + keystatus[0x12] = 0; + } + // // Adjust top-left to ensure tilenum is within displayed range of tiles // @@ -2134,6 +2149,7 @@ static long OnGotoTile(long iTile) { if (quitevent) quitevent = 0; } + idle(); ch = bgetchar(); @@ -2195,6 +2211,15 @@ static long OnSelectTile(long iTile) long i, j; char ch; + for (i = 0; (unsigned)i < NUM_TILE_GROUPS; i++) + { + if (s_TileGroups[i].pIds != NULL) + break; + } + + if (i == NUM_TILE_GROUPS) // no tile groups + return (iTile); + SelectAllTiles(iTile); bflushchars(); @@ -2209,7 +2234,8 @@ static long OnSelectTile(long iTile) for (i = 0; (unsigned)i < NUM_TILE_GROUPS; i++) { - printext256(10L, (i+1)*16, whitecol, -1, s_TileGroups[i].szText, 0); + if (s_TileGroups[i].szText != NULL) + printext256(10L, (i+1)*16, whitecol, -1, s_TileGroups[i].szText, 0); } showframe(1); @@ -2219,22 +2245,24 @@ static long OnSelectTile(long iTile) bDone = 0; - while (keystatus[1] == 0 && (0 == bDone)) + while (keystatus[1] == 0 && (!bDone)) { if (handleevents()) { if (quitevent) quitevent = 0; } + idle(); ch = bgetchar(); for (i = 0; (unsigned)i < NUM_TILE_GROUPS; i++) { - if ((ch == s_TileGroups[i].key1) || (ch == s_TileGroups[i].key2)) - { - iTile = LoadTileSet(iTile, s_TileGroups[i].pIds, s_TileGroups[i].nIds); - bDone = 1; - } + if (s_TileGroups[i].pIds != NULL) + if ((ch == s_TileGroups[i].key1) || (ch == s_TileGroups[i].key2)) + { + iTile = LoadTileSet(iTile, s_TileGroups[i].pIds, s_TileGroups[i].nIds); + bDone = 1; + } } } @@ -2252,7 +2280,7 @@ const char * GetTilePixels(const long idTile) if ((idTile >= 0) && (idTile < MAXTILES)) { - if (0 == waloff[idTile]) + if (!waloff[idTile]) { loadtile(idTile); } @@ -3290,11 +3318,11 @@ static void Keys3d(void) sprite[searchwall].cstat = i; if (sprite[searchwall].cstat&16) - sprintf(getmessage,"Sprite (%d) wall aligned",searchwall); + sprintf(getmessage,"Sprite (%d) now wall aligned",searchwall); else if (sprite[searchwall].cstat&32) - sprintf(getmessage,"Sprite (%d) floor aligned",searchwall); + sprintf(getmessage,"Sprite (%d) now floor aligned",searchwall); else - sprintf(getmessage,"Sprite (%d) un-aligned",searchwall); + sprintf(getmessage,"Sprite (%d) now view aligned",searchwall); message(getmessage); asksave = 1; } @@ -4498,11 +4526,11 @@ static void Keys2d(void) sprite[cursprite].cstat = i; if (sprite[cursprite].cstat&16) - sprintf(getmessage,"Sprite (%d) is wall aligned",cursprite); + sprintf(getmessage,"Sprite (%d) now wall aligned",cursprite); else if (sprite[cursprite].cstat&32) - sprintf(getmessage,"Sprite (%d) is floor aligned",cursprite); + sprintf(getmessage,"Sprite (%d) now floor aligned",cursprite); else - sprintf(getmessage,"Sprite (%d) is un-aligned",cursprite); + sprintf(getmessage,"Sprite (%d) now view aligned",cursprite); message(getmessage); asksave = 1; @@ -5426,7 +5454,13 @@ enum { T_EOF = -2, T_ERROR = -1, T_INCLUDE = 0, - T_LOADGRP = 1, + T_DEFINE = 1, + T_LOADGRP, + T_TILEGROUP, + T_NAME, + T_TILE, + T_TILERANGE, + T_KEY }; typedef struct @@ -5456,17 +5490,14 @@ static int getatoken(scriptfile *sf, tokenlist *tl, int ntokens) static tokenlist grptokens[] = { { "include", T_INCLUDE }, + { "#include", T_INCLUDE }, { "loadgrp", T_LOADGRP }, }; -int loadgroupfiles(char *fn) +int parsegroupfiles(scriptfile *script) { int tokn; char *cmdtokptr; - scriptfile *script; - - script = scriptfile_fromfile(fn); - if (!script) return -1; while (1) { @@ -5502,7 +5533,7 @@ int loadgroupfiles(char *fn) } else { - loadgroupfiles((char *)included); + parsegroupfiles(included); scriptfile_close(included); } } @@ -5515,6 +5546,165 @@ int loadgroupfiles(char *fn) break; } } + return 0; +} + +int loadgroupfiles(char *fn) +{ + scriptfile *script; + + script = scriptfile_fromfile(fn); + if (!script) return -1; + + parsegroupfiles(script); + + scriptfile_close(script); + scriptfile_clearsymbols(); + + return 0; +} + +static tokenlist tgtokens[] = + { + { "include", T_INCLUDE }, + { "#include", T_INCLUDE }, + { "define", T_DEFINE }, + { "#define", T_DEFINE }, + { "tilegroup", T_TILEGROUP }, + }; + +static tokenlist tgtokens2[] = + { + { "tilegroup", T_TILEGROUP }, + { "name", T_NAME }, + { "tile", T_TILE }, + { "tilerange", T_TILERANGE }, + { "key", T_KEY }, + }; + +int parsetilegroups(scriptfile *script) +{ + int tokn; + char *cmdtokptr; + + while (1) + { + tokn = getatoken(script,tgtokens,sizeof(tgtokens)/sizeof(tokenlist)); + cmdtokptr = script->ltextptr; + switch (tokn) + { + case T_INCLUDE: + { + char *fn; + if (!scriptfile_getstring(script,&fn)) + { + 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 + { + parsetilegroups(included); + scriptfile_close(included); + } + } + break; + } + case T_DEFINE: + { + char *name; + int number; + + if (scriptfile_getstring(script,&name)) break; + if (scriptfile_getsymbol(script,&number)) break; + if (scriptfile_addsymbolvalue(name,number) < 0) + initprintf("Warning: Symbol %s was NOT redefined to %d on line %s:%d\n", + name,number,script->filename,scriptfile_getlinum(script,cmdtokptr)); + break; + } + case T_TILEGROUP: + { + char *end, *name; + int g, i; + + if (scriptfile_getnumber(script,&g)) break; + + if ((unsigned)g >= NUM_TILE_GROUPS) break; + + if (s_TileGroups[g].pIds == NULL) + s_TileGroups[g].pIds = Bcalloc(MAX_TILE_GROUP_ENTRIES,sizeof(long)); + +// if (scriptfile_getstring(script,&name)) break; + + if (scriptfile_getbraces(script,&end)) break; + while (script->textptr < end) + { + int token = getatoken(script,tgtokens2,sizeof(tgtokens2)/sizeof(tokenlist)); + switch (token) + { + case T_NAME: + { + if (scriptfile_getstring(script,&name)) break; + if (s_TileGroups[g].szText != NULL) + Bfree(s_TileGroups[g].szText); + + s_TileGroups[g].szText = strdup(name); + break; + } + case T_TILE: + { + if (scriptfile_getsymbol(script,&i)) break; + if (i >= 0 && i < MAXTILES && s_TileGroups[g].nIds < MAX_TILE_GROUP_ENTRIES) + s_TileGroups[g].pIds[s_TileGroups[g].nIds++] = i; +// OSD_Printf("added tile %d to group %d\n",i,g); + break; + } + case T_TILERANGE: + { + int j; + if (scriptfile_getsymbol(script,&i)) break; + if (scriptfile_getsymbol(script,&j)) break; + if (i < 0 || i >= MAXTILES || j < 0 || j >= MAXTILES) break; + while (s_TileGroups[g].nIds < MAX_TILE_GROUP_ENTRIES && i < j) + { + s_TileGroups[g].pIds[s_TileGroups[g].nIds++] = i++; +// OSD_Printf("added tile %d to group %d\n",i,g); + } + break; + } + case T_KEY: + { + char *c; + if (scriptfile_getstring(script,&c)) break; + s_TileGroups[g].key1 = Btoupper(c[0]); + s_TileGroups[g].key2 = Btolower(c[0]); + break; + } + } + } + break; + } + case T_EOF: + return(0); + default: + break; + } + } + return 0; +} + +int loadtilegroups(char *fn) +{ + scriptfile *script; + + script = scriptfile_fromfile(fn); + if (!script) return -1; + + parsetilegroups(script); scriptfile_close(script); scriptfile_clearsymbols(); @@ -5684,14 +5874,25 @@ int ExtInit(void) OSD_SetParameters(0,2, 0,0, 4,0); registerosdcommands(); + loadtilegroups("tiles.cfg"); + return rv; } void ExtUnInit(void) { + int i; // setvmode(0x03); uninitgroupfile(); writesetup(setupfilename); + + for (i = 0; (unsigned)i < NUM_TILE_GROUPS; i++) + { + if (s_TileGroups[i].pIds != NULL) + Bfree(s_TileGroups[i].pIds); + if (s_TileGroups[i].szText != NULL) + Bfree(s_TileGroups[i].szText); + } } void ExtPreCheckKeys(void) // just before drawrooms diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index ece042606..531c750f8 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -8443,11 +8443,10 @@ static void autoloadgrps(const char *fn) while (findfiles) { Bsprintf(tempbuf,"autoload/%s/%s",fn,findfiles->name); initprintf("Using group file '%s'.\n",tempbuf); initgroupfile(tempbuf); findfiles = findfiles->next; } } -static int loadgroupfiles(const char *fn) +static int parsegroupfiles(scriptfile *script) { int tokn; char *cmdtokptr; - scriptfile *script; tokenlist grptokens[] = { @@ -8457,9 +8456,6 @@ static int loadgroupfiles(const char *fn) { "cachesize", T_CACHESIZE }, }; - script = scriptfile_fromfile((char *)fn); - if (!script) return -1; - while (1) { tokn = getatoken(script,grptokens,sizeof(grptokens)/sizeof(tokenlist)); @@ -8510,7 +8506,7 @@ static int loadgroupfiles(const char *fn) } else { - loadgroupfiles((const char *)included); + parsegroupfiles(included); scriptfile_close(included); } } @@ -8522,6 +8518,17 @@ static int loadgroupfiles(const char *fn) break; } } + return 0; +} + +static int loadgroupfiles(const char *fn) +{ + scriptfile *script; + + script = scriptfile_fromfile((char *)fn); + if (!script) return -1; + + parsegroupfiles(script); scriptfile_close(script); scriptfile_clearsymbols(); diff --git a/polymer/eduke32/source/mapster32.h b/polymer/eduke32/source/mapster32.h index 017ab3275..e1a1807ba 100644 --- a/polymer/eduke32/source/mapster32.h +++ b/polymer/eduke32/source/mapster32.h @@ -178,164 +178,37 @@ static const long ZoomToThumbSize[] = #define INITIAL_ZOOM 2 - -// If I wasn't a lazy sod I'd have made these loadable from external config files. - - /////////////////// - // ACTOR SPRITES // - /////////////////// - -static const long s_idActors[] = +struct { - LIZTROOP, LIZTROOPRUNNING, LIZTROOPSTAYPUT, LIZTROOPSHOOT, LIZTROOPJETPACK, - LIZTROOPONTOILET, LIZTROOPJUSTSIT, LIZTROOPDUCKING, - PIGCOP, PIGCOPSTAYPUT, PIGCOPDIVE, - LIZMAN, LIZMANSTAYPUT, LIZMANSPITTING, LIZMANFEEDING, LIZMANJUMP, - COMMANDER, COMMANDERSTAYPUT, - OCTABRAIN, OCTABRAINSTAYPUT, - ORGANTIC, - NEWBEAST, NEWBEASTSTAYPUT, NEWBEASTJUMP, - EGG, GREENSLIME, ROTATEGUN, RECON, TANK, BOUNCEMINE, - FLOORFLAME, - // FEMS - FEM1, FEM2, FEM3, FEM4, FEM5, FEM6, FEM7, FEM8, FEM9, FEM10, NAKED1, - // Lil' critters - SHARK, - // BIG critters - BOSS1, BOSS1STAYPUT, BOSS1SHOOT, BOSS1LOB, - BOSS2, - BOSS3, - BOSS4, BOSS4STAYPUT -} ; - -#define NUM_ACTORS (sizeof(s_idActors)/sizeof(s_idActors[0])) - - ///////////////// - // DOOR TILES /// - ///////////////// - -// Not all of these are tuely door tiles but are useable as such - -static const long s_idDoors[] = -{ - DOORTILE1, DOORTILE2, DOORTILE3, DOORTILE4, DOORTILE5, - DOORTILE6, DOORTILE7, DOORTILE8, DOORTILE9, DOORTILE10, - 312, 313, 314, 345, - DOORTILE22, DOORTILE18, DOORTILE19, DOORTILE20, - 450, 455, 457, 458, 459, 469, 470, 477, - DOORTILE14, - 719, 735, 771, - DOORTILE16, - 843, 858, 883, - DOORTILE15, DOORTILE21, - 1173, - DOORTILE11,DOORTILE12, - 353, 355, - // Related items - DOORSHOCK, ACCESSCARD -}; - -#define NUM_DOORS (sizeof(s_idDoors)/sizeof(s_idDoors[0])) - - ////////////////// - // SWITCH TILES // - ////////////////// - -static const long s_idSwitches[] = -{ - ACCESSSWITCH,ACCESSSWITCH2, SLOTDOOR, LIGHTSWITCH, SPACEDOORSWITCH, SPACELIGHTSWITCH, - FRANKENSTINESWITCH, MULTISWITCH, - DIPSWITCH, DIPSWITCH2, DIPSWITCH3, TECHSWITCH, - LIGHTSWITCH2, LIGHTSWITCH2+1, - POWERSWITCH1, LOCKSWITCH1, POWERSWITCH2, HANDSWITCH, PULLSWITCH, - ALIENSWITCH, HANDPRINTSWITCH, NUKEBUTTON, - TARGET, - 4083, 4954 // Busted switches (Atomic) -} ; - -#define NUM_SWITCHES (sizeof(s_idSwitches)/sizeof(s_idSwitches[0])) - - /////////////////// - // GOODIES TILES // - /////////////////// - -static const long s_idGoodies[] = -{ - // Ammo - AMMO,SHOTGUNAMMO, BATTERYAMMO, RPGAMMO, HEAVYHBOMB, FREEZEAMMO, GROWAMMO, CRYSTALAMMO, - DEVISTATORAMMO, HBOMBAMMO, - - // Items (health,etc) - COLA, SIXPAK, FIRSTAID, SHIELD, STEROIDS, AIRTANK, JETPACK, HEATSENSOR, ACCESSCARD, - BOOTS, ATOMICHEALTH, - - // Weapons - FIRSTGUNSPRITE, CHAINGUNSPRITE, RPGSPRITE, FREEZESPRITE, SHRINKERSPRITE, - TRIPBOMBSPRITE, SHOTGUNSPRITE, DEVISTATORSPRITE - -} ; - -#define NUM_GOODIES (sizeof(s_idGoodies)/sizeof(s_idGoodies[0])) - - //////////////////////// - // ITEMS THAT RESPAWN // - //////////////////////// - -// Thought there were more than just these :-( - -static const long s_idRespawns[] = -{ - CANWITHSOMETHING, CANWITHSOMETHING2, CANWITHSOMETHING3, CANWITHSOMETHING4, - // FEMS - FEM1, FEM2, FEM3, FEM4, FEM5, FEM6, FEM7, FEM8, FEM9, FEM10, NAKED1, -} ; - -#define NUM_RESPAWNS (sizeof(s_idRespawns)/sizeof(s_idRespawns[0])) - - //////////////////////// - // EXPLOSION AND FIRE // - //////////////////////// - -static const long s_idExplosions[] = -{ - CRACK1, CRACK2, CRACK3, CRACK4, - FIREEXT, SEENINE, OOZFILTER, - EXPLODINGBARREL, EXPLODINGBARREL2, FIREBARREL, GUNPOWDERBARREL, - REACTOR2SPARK, BOLT1, SIDEBOLT1, - CEILINGSTEAM, - FIREVASE, 2066, BURNING, FIRE, BURNING2, FIRE2 -} ; - -#define NUM_EXPLOSIONS (sizeof(s_idExplosions)/sizeof(s_idExplosions[0])) - - //////////////////////////////////////////////////////////////// - // BUILD STRUCTURE USED IN SELECTING ONE OF ABOVE LTILE LISTS // - //////////////////////////////////////////////////////////////// - -const struct -{ - const long *pIds ; // ptr to list of tile Ids + long *pIds ; // ptr to list of tile Ids long nIds ; // num of tile ids char key1 ; // key1 and key2 are two alternative keypresses used to char key2 ; // select tile set. Bodge to do eary upper/lower case handling char *szText ; // description to present to user. } s_TileGroups[] = { - { s_idActors, NUM_ACTORS, 'A', 'a', "(A) Actor group" }, - { s_idDoors, NUM_DOORS, 'D', 'd', "(D) Door group" }, - { s_idGoodies, NUM_GOODIES, 'G', 'g', "(G) Goodies (ammo, weapons, etc)" }, - { s_idRespawns, NUM_RESPAWNS, 'R', 'r', "(R) Respawning Items" }, - { s_idSwitches, NUM_SWITCHES, 'S', 's', "(S) Switch group" }, - { s_idExplosions, NUM_EXPLOSIONS, 'X', 'x', "(X) eXplosions, fire, sparks, etc" } + { NULL, 0, 0, 0, NULL }, + { NULL, 0, 0, 0, NULL }, + { NULL, 0, 0, 0, NULL }, + { NULL, 0, 0, 0, NULL }, + { NULL, 0, 0, 0, NULL }, + { NULL, 0, 0, 0, NULL }, + { NULL, 0, 0, 0, NULL }, + { NULL, 0, 0, 0, NULL }, + { NULL, 0, 0, 0, NULL }, + { NULL, 0, 0, 0, NULL }, } ; #define NUM_TILE_GROUPS (sizeof(s_TileGroups)/sizeof(s_TileGroups[0])) +#define MAX_TILE_GROUP_ENTRIES 128 #define FIRST_USER_ART_TILE 3584 // Some atomic tiles are sprinkled in the V1.3d's area but // this is where the main atomic tiles start :- #define FIRST_ATOMIC_TILE 4096 +#define FIRST_EXTENDED_TILE 6144 +#define SECOND_EXTENDED_TILE 9216 extern short localartfreq[MAXTILES]; extern short localartlookup[MAXTILES], localartlookupnum;