From 57042cd9a7004e95ed963ee9e17fa9395372f0b7 Mon Sep 17 00:00:00 2001 From: terminx Date: Mon, 4 Dec 2006 22:05:30 +0000 Subject: [PATCH] This raises the max number of levels per episode to 32 and alters the game to use dynamically allocated memory for level and music names and filenames. No null pointer checks yet. git-svn-id: https://svn.eduke32.com/eduke32@381 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/duke3d.h | 13 +++++----- polymer/eduke32/source/game.c | 42 +++++++++++++++++++------------ polymer/eduke32/source/gamedef.c | 32 +++++++++++++++-------- polymer/eduke32/source/global.c | 8 +++--- polymer/eduke32/source/menus.c | 6 ++--- polymer/eduke32/source/premap.c | 18 ++++++------- polymer/eduke32/source/savegame.c | 2 +- 7 files changed, 71 insertions(+), 50 deletions(-) diff --git a/polymer/eduke32/source/duke3d.h b/polymer/eduke32/source/duke3d.h index 4455fecdc..e917371b5 100644 --- a/polymer/eduke32/source/duke3d.h +++ b/polymer/eduke32/source/duke3d.h @@ -77,6 +77,7 @@ extern int conversion, shareware, gametype; #define FOURSLEIGHT (1<<8) #define MAXVOLUMES 7 +#define MAXLEVELS 32 #include "types.h" #include "file_lib.h" @@ -473,8 +474,8 @@ extern long *actorLoadEventScrptr[MAXTILES]; extern char actortype[MAXTILES]; extern char *music_pointer; -extern char music_fn[MAXVOLUMES+1][11][13],music_select; -extern char env_music_fn[MAXVOLUMES+1][13]; +extern char *music_fn[MAXVOLUMES+1][MAXLEVELS],music_select; +extern char env_music_fn[MAXVOLUMES+1][BMAX_PATH]; extern short camsprite; // extern char gotz; @@ -527,14 +528,14 @@ extern char screencapt; extern short soundps[NUM_SOUNDS],soundpe[NUM_SOUNDS],soundvo[NUM_SOUNDS]; extern char soundpr[NUM_SOUNDS],soundm[NUM_SOUNDS]; extern long soundsiz[NUM_SOUNDS]; -extern char level_names[MAXVOLUMES*11][33]; -extern long partime[MAXVOLUMES*11],designertime[MAXVOLUMES*11]; +extern char *level_names[MAXVOLUMES*MAXLEVELS]; +extern long partime[MAXVOLUMES*MAXLEVELS],designertime[MAXVOLUMES*MAXLEVELS]; extern char volume_names[MAXVOLUMES][33]; extern char skill_names[5][33]; extern int framerate; -#define MAXGAMETYPES 32 +#define MAXGAMETYPES 16 extern char gametype_names[MAXGAMETYPES][33]; extern int gametype_flags[MAXGAMETYPES]; extern char num_gametypes; @@ -562,7 +563,7 @@ enum gametypeflags { #define GTFLAGS(x) (gametype_flags[ud.coop] & x) -extern char level_file_names[MAXVOLUMES*11][BMAX_PATH]; +extern char *level_file_names[MAXVOLUMES*MAXLEVELS]; extern char num_volumes; extern int32 SoundToggle,MusicToggle; diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index bc8850982..08ba5d713 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -580,7 +580,7 @@ void getpackets(void) voting = packbuf[2]; vote_episode = packbuf[3]; vote_map = packbuf[4]; - Bsprintf(tempbuf,"%s^00 HAS CALLED A VOTE TO CHANGE MAP TO %s (E%dL%d)",ud.user_name[(unsigned char)packbuf[2]],level_names[(unsigned char)(packbuf[3]*11 + packbuf[4])],packbuf[3]+1,packbuf[4]+1); + Bsprintf(tempbuf,"%s^00 HAS CALLED A VOTE TO CHANGE MAP TO %s (E%dL%d)",ud.user_name[(unsigned char)packbuf[2]],level_names[(unsigned char)(packbuf[3]*MAXLEVELS + packbuf[4])],packbuf[3]+1,packbuf[4]+1); adduserquote(tempbuf); Bsprintf(tempbuf,"PRESS F1 TO VOTE YES, F2 TO VOTE NO"); adduserquote(tempbuf); @@ -3360,7 +3360,7 @@ void displayrest(long smoothratio) else a = 182; minitext(1,a+6,volume_names[ud.volume_number],0,2+8+16); - minitext(1,a+12,level_names[ud.volume_number*11 + ud.level_number],0,2+8+16); + minitext(1,a+12,level_names[ud.volume_number*MAXLEVELS + ud.level_number],0,2+8+16); } } } @@ -7839,9 +7839,9 @@ void nonsharedkeys(void) { if (i == 5 && ps[myconnectindex].fta > 0 && ps[myconnectindex].ftq == 26) { - i = (VOLUMEALL?num_volumes*11:6); + i = (VOLUMEALL?num_volumes*MAXLEVELS:6); music_select++; - while (!music_fn[0][(unsigned char)music_select][0] && music_select < i) + while ((music_fn[0][(unsigned char)music_select] == NULL) && music_select < i) music_select++; if (music_select == i) music_select = 0; @@ -8739,7 +8739,7 @@ void checkcommandline(int argc,char **argv) case 'L': ud.warp_on = 1; c++; - ud.m_level_number = ud.level_number = (atol(c)-1)%11; + ud.m_level_number = ud.level_number = (atol(c)-1)%MAXLEVELS; break; case 'm': case 'M': @@ -9087,6 +9087,16 @@ void freeconmem(void) { int i; + for (i=0;i9; ii/=10, ij++) ; + for (ii=partime[ud.volume_number*MAXLEVELS+ud.last_level-1]/(26*60), ij=1; ii>9; ii/=10, ij++) ; clockpad = max(clockpad,ij); if (!NAM) { - for (ii=designertime[ud.volume_number*11+ud.last_level-1]/(26*60), ij=1; ii>9; ii/=10, ij++) ; + for (ii=designertime[ud.volume_number*MAXLEVELS+ud.last_level-1]/(26*60), ij=1; ii>9; ii/=10, ij++) ; clockpad = max(clockpad,ij); } } @@ -11945,16 +11955,16 @@ FRAGBONUS: if (!(ud.volume_number == 0 && ud.last_level-1 == 7)) { Bsprintf(tempbuf,"%0*ld:%02ld",clockpad, - (partime[ud.volume_number*11+ud.last_level-1]/(26*60)), - (partime[ud.volume_number*11+ud.last_level-1]/26)%60); + (partime[ud.volume_number*MAXLEVELS+ud.last_level-1]/(26*60)), + (partime[ud.volume_number*MAXLEVELS+ud.last_level-1]/26)%60); gametext((320>>2)+71,yy+9,tempbuf,0,2+8+16); yy+=10; if (!NAM) { Bsprintf(tempbuf,"%0*ld:%02ld",clockpad, - (designertime[ud.volume_number*11+ud.last_level-1]/(26*60)), - (designertime[ud.volume_number*11+ud.last_level-1]/26)%60); + (designertime[ud.volume_number*MAXLEVELS+ud.last_level-1]/(26*60)), + (designertime[ud.volume_number*MAXLEVELS+ud.last_level-1]/26)%60); gametext((320>>2)+71,yy+9,tempbuf,0,2+8+16); yy+=10; } diff --git a/polymer/eduke32/source/gamedef.c b/polymer/eduke32/source/gamedef.c index 7f53816d2..bd803804b 100644 --- a/polymer/eduke32/source/gamedef.c +++ b/polymer/eduke32/source/gamedef.c @@ -2370,6 +2370,8 @@ char parsecommand(void) if (*textptr == 0) break; } j = 0; + if (music_fn[k][i] == NULL) + music_fn[k][i] = Bcalloc(BMAX_PATH,sizeof(char)); while (isaltok(*(textptr+j))) { music_fn[k][i][j] = textptr[j]; @@ -2377,7 +2379,7 @@ char parsecommand(void) } music_fn[k][i][j] = '\0'; textptr += j; - if (i > 9) break; + if (i > MAXLEVELS-1) break; i++; } } @@ -2393,6 +2395,7 @@ char parsecommand(void) if (*textptr == 0) break; } j = 0; + while (isaltok(*(textptr+j))) { env_music_fn[i][j] = textptr[j]; @@ -2401,7 +2404,7 @@ char parsecommand(void) env_music_fn[i][j] = '\0'; textptr += j; - if (i > 9) break; + if (i > MAXVOLUMES-1) break; i++; } } @@ -4506,7 +4509,7 @@ repeatcase: while (*textptr != 0x0a && *textptr != 0) textptr++; break; } - if (k < 0 || k > 10) + if (k < 0 || k > MAXLEVELS-1) { initprintf("%s:%ld: error: level number exceeds maximum number of levels per episode.\n",compilefile,line_number); error++; @@ -4515,9 +4518,13 @@ repeatcase: } i = 0; + + if (level_file_names[j*MAXLEVELS+k] == NULL) + level_file_names[j*MAXLEVELS+k] = Bcalloc(BMAX_PATH,sizeof(char)); + while (*textptr != ' ' && *textptr != '\t' && *textptr != 0x0a) { - level_file_names[j*11+k][i] = *textptr; + level_file_names[j*MAXLEVELS+k][i] = *textptr; textptr++,i++; if (i >= BMAX_PATH) { @@ -4527,18 +4534,18 @@ repeatcase: break; } } - level_names[j*11+k][i] = '\0'; + level_file_names[j*MAXLEVELS+k][i] = '\0'; while (*textptr == ' ' || *textptr == '\t') textptr++; - partime[j*11+k] = + partime[j*MAXLEVELS+k] = (((*(textptr+0)-'0')*10+(*(textptr+1)-'0'))*26*60)+ (((*(textptr+3)-'0')*10+(*(textptr+4)-'0'))*26); textptr += 5; while (*textptr == ' ' || *textptr == '\t') textptr++; - designertime[j*11+k] = + designertime[j*MAXLEVELS+k] = (((*(textptr+0)-'0')*10+(*(textptr+1)-'0'))*26*60)+ (((*(textptr+3)-'0')*10+(*(textptr+4)-'0'))*26); @@ -4547,19 +4554,22 @@ repeatcase: i = 0; + if (level_names[j*MAXLEVELS+k] == NULL) + level_names[j*MAXLEVELS+k] = Bcalloc(32,sizeof(char)); + while (*textptr != 0x0a && *textptr != 0x0d && *textptr != 0) { - level_names[j*11+k][i] = toupper(*textptr); + level_names[j*MAXLEVELS+k][i] = toupper(*textptr); textptr++,i++; - if (i >= (signed)sizeof(level_names[j*11+k])-1) + if (i >= 32) { - initprintf("%s:%ld: error: level name exceeds limit of %ld characters.\n",compilefile,line_number,sizeof(level_names[j*11+k])-1); + initprintf("%s:%ld: error: level name exceeds limit of %ld characters.\n",compilefile,line_number,sizeof(level_names[j*MAXLEVELS+k])-1); error++; while (*textptr != 0x0a && *textptr != 0x0d && *textptr != 0) textptr++; break; } } - level_names[j*11+k][i] = '\0'; + level_names[j*MAXLEVELS+k][i] = '\0'; return 0; case CON_DEFINEQUOTE: diff --git a/polymer/eduke32/source/global.c b/polymer/eduke32/source/global.c index 82c3f83b2..37466b62e 100644 --- a/polymer/eduke32/source/global.c +++ b/polymer/eduke32/source/global.c @@ -53,8 +53,8 @@ short mirrorwall[64], mirrorsector[64], mirrorcnt; int current_menu; -char level_names[MAXVOLUMES*11][33],level_file_names[MAXVOLUMES*11][BMAX_PATH]; -long partime[MAXVOLUMES*11],designertime[MAXVOLUMES*11]; +char *level_names[MAXVOLUMES*MAXLEVELS],*level_file_names[MAXVOLUMES*MAXLEVELS]; +long partime[MAXVOLUMES*MAXLEVELS],designertime[MAXVOLUMES*MAXLEVELS]; char volume_names[MAXVOLUMES][33] = { "L.A. MELTDOWN", "LUNAR APOCALYPSE", "SHRAPNEL CITY" }; char skill_names[5][33] = { "PIECE OF CAKE", "LET'S ROCK", "COME GET SOME", "DAMN I'M GOOD" }; @@ -120,8 +120,8 @@ long script[MAXSCRIPTSIZE+16]; char display_mirror,typebuflen,typebuf[141]; -char music_fn[MAXVOLUMES+1][11][13],music_select; -char env_music_fn[MAXVOLUMES+1][13]; +char *music_fn[MAXVOLUMES+1][MAXLEVELS],music_select; +char env_music_fn[MAXVOLUMES+1][BMAX_PATH]; char rtsplaying; diff --git a/polymer/eduke32/source/menus.c b/polymer/eduke32/source/menus.c index 6a7280499..7b81d0770 100644 --- a/polymer/eduke32/source/menus.c +++ b/polymer/eduke32/source/menus.c @@ -909,7 +909,7 @@ void menus(void) gametext(90+60,60,gametype_names[ud.m_coop],0,26); minitext(90+60,60+8, volume_names[ud.m_volume_number],0,26); - minitext(90+60,60+8+8, level_names[11*ud.m_volume_number+ud.m_level_number],0,26); + minitext(90+60,60+8+8, level_names[MAXLEVELS*ud.m_volume_number+ud.m_level_number],0,26); if (ud.m_monsters_off == 0 || ud.m_player_skill > 0) minitext(90+60,60+8+8+8, skill_names[ud.m_player_skill],0,26); else minitext(90+60,60+8+8+8, "NONE",0,28); @@ -1012,7 +1012,7 @@ void menus(void) gametext(c+70,57+16-7-9,volume_names[ud.m_volume_number],0,2+8+16); - gametext(c+70,57+16+16-7-9,&level_names[11*ud.m_volume_number+ud.m_level_number][0],0,2+8+16); + gametext(c+70,57+16+16-7-9,&level_names[MAXLEVELS*ud.m_volume_number+ud.m_level_number][0],0,2+8+16); if (ud.m_monsters_off == 0 || ud.m_player_skill > 0) gametext(c+70,57+16+16+16-7-9,skill_names[ud.m_player_skill],0,2+8+16); @@ -4700,7 +4700,7 @@ VOLUME_ALL_40x: gametext(c+70,57+16-7-9,volume_names[ud.m_volume_number],MENUHIGHLIGHT(1),2+8+16); } - gametext(c+70,57+16+16-7-9,&level_names[11*ud.m_volume_number+ud.m_level_number][0],MENUHIGHLIGHT(2),2+8+16); + gametext(c+70,57+16+16-7-9,&level_names[MAXLEVELS*ud.m_volume_number+ud.m_level_number][0],MENUHIGHLIGHT(2),2+8+16); gametext(c+70,57+16+16+16-7-9,ud.m_monsters_off == 0 || ud.m_player_skill > 0?skill_names[ud.m_player_skill]:"NONE",MENUHIGHLIGHT(3),2+8+16); diff --git a/polymer/eduke32/source/premap.c b/polymer/eduke32/source/premap.c index f59ba7c57..77dc90c64 100644 --- a/polymer/eduke32/source/premap.c +++ b/polymer/eduke32/source/premap.c @@ -1491,7 +1491,7 @@ void dofrontscreens(char *statustext) else { menutext(160,90,0,0,"ENTERING"); - menutext(160,90+16+8,0,0,level_names[(ud.volume_number*11) + ud.level_number]); + menutext(160,90+16+8,0,0,level_names[(ud.volume_number*MAXLEVELS) + ud.level_number]); } if (statustext) gametext(160,180,statustext,0,2+8+16); @@ -1616,7 +1616,7 @@ int enterlevel(char g) Bstrcpy(levname, boardfilename); Bsprintf(apptitle," - %s",levname); } - else Bsprintf(apptitle," - %s",level_names[(ud.volume_number*11)+ud.level_number]); + else Bsprintf(apptitle," - %s",level_names[(ud.volume_number*MAXLEVELS)+ud.level_number]); Bstrcat(tempbuf,apptitle); wm_setapptitle(tempbuf); @@ -1657,16 +1657,16 @@ int enterlevel(char g) if (!loadmaphack(levname)) initprintf("Loaded map hack file %s\n",levname); } } - else if (loadboard(level_file_names[(ud.volume_number*11)+ud.level_number],0,&ps[0].posx, &ps[0].posy, &ps[0].posz, &ps[0].ang,&ps[0].cursectnum) == -1) + else if (loadboard(level_file_names[(ud.volume_number*MAXLEVELS)+ud.level_number],0,&ps[0].posx, &ps[0].posy, &ps[0].posz, &ps[0].ang,&ps[0].cursectnum) == -1) { - initprintf("Map %s not found!\n",level_file_names[(ud.volume_number*11)+ud.level_number]); + initprintf("Map %s not found!\n",level_file_names[(ud.volume_number*MAXLEVELS)+ud.level_number]); //gameexit(tempbuf); return 1; } else { char *p; - strcpy(levname, level_file_names[(ud.volume_number*11)+ud.level_number]); + strcpy(levname, level_file_names[(ud.volume_number*MAXLEVELS)+ud.level_number]); p = Bstrrchr(levname,'.'); if (!p) strcat(levname,".mhk"); else @@ -1683,14 +1683,14 @@ int enterlevel(char g) else { - l = strlen(level_file_names[(ud.volume_number*11)+ud.level_number]); - copybufbyte(level_file_names[(ud.volume_number*11)+ud.level_number],&levname[0],l); + l = strlen(level_file_names[(ud.volume_number*MAXLEVELS)+ud.level_number]); + copybufbyte(level_file_names[(ud.volume_number*MAXLEVELS)+ud.level_number],&levname[0],l); levname[l] = 255; levname[l+1] = 0; if (loadboard(levname,1,&ps[0].posx, &ps[0].posy, &ps[0].posz, &ps[0].ang,&ps[0].cursectnum) == -1) { - initprintf("Map %s not found!\n",level_file_names[(ud.volume_number*11)+ud.level_number]); + initprintf("Map %s not found!\n",level_file_names[(ud.volume_number*MAXLEVELS)+ud.level_number]); //gameexit(tempbuf); return 1; } @@ -1729,7 +1729,7 @@ int enterlevel(char g) if (ud.recstat != 2) { - music_select = (ud.volume_number*11) + ud.level_number; + music_select = (ud.volume_number*MAXLEVELS) + ud.level_number; playmusic(&music_fn[0][(unsigned char)music_select][0]); } diff --git a/polymer/eduke32/source/savegame.c b/polymer/eduke32/source/savegame.c index 2741317f3..57a95d321 100644 --- a/polymer/eduke32/source/savegame.c +++ b/polymer/eduke32/source/savegame.c @@ -353,7 +353,7 @@ int loadplayer(signed char spot) clearsoundlocks(); cacheit(); - music_select = (ud.volume_number*11) + ud.level_number; + music_select = (ud.volume_number*MAXLEVELS) + ud.level_number; playmusic(&music_fn[0][(unsigned char)music_select][0]); ps[myconnectindex].gm = MODE_GAME;