1 ////////////////////////////////////////////////////
2 ////////////////////////////////////////////////////
4 // TED5-2 : Menu Item Routines
6 ////////////////////////////////////////////////////
7 ////////////////////////////////////////////////////
11 ////////////////////////////////////////////////////
13 // Toggle the INFOBAR on and off
15 ////////////////////////////////////////////////////
16 void Item_ToggleInfo(void)
20 InitDesktop(TED5MenuBar,0);
22 if (ybase+screenh>mapheight && mapheight>screenh)
30 ////////////////////////////////////////////////////
34 ////////////////////////////////////////////////////
35 btype SelTb[]={{" Tiles ",2,21,1},
39 DialogDef SelTd={"",38,23,4,&SelTb[0],NULL};
41 void SelectTiles(int screen)
43 int exitok=0,which,i,numrows,numcols,b0,b1,redraw=0;
46 // if parameter passed, change the screen
51 if (PasteMode || SelectMode) // RE-BLIT MAP IF WE ARE ENTERING WHILE
52 redraw=1; // FLOATING AN IMAGE
54 PasteMode=SelectMode=0;
55 SelX1=SelX2=SelY1=SelY2=-1;
73 DrawTileSelect(0,&numrows,&numcols);
74 selectcols=numcols; // VERY IMPORTANT TO PASTE-FROM-TILESELECT MODE
76 while(keydown[0x39]); // WAIT FOR SPACE-UP
80 which=CheckButtonsRet(&SelTd);
82 b1=(MouseButton()>>1)&1;
87 // GRAB CURRENT TILE FROM MATRIX
95 if (mx>=left && mx<left+(numcols<<(tsize-1)) &&
96 my>=16 && my<=16+(numrows<<(2+tsize)))
100 tile=((my-16)>>(tsize+2))*numcols+
101 ((mx-left)>>(tsize-1));
108 case TILES: thebase=tilebase/numcols; break;
109 case MASKED: thebase=tilembase/numcols;
115 SelY1=((my-16)>>(tsize+2))+thebase;
116 SelX1=((mx-left)>>(tsize-1));
117 if (SelX2==-1 && SelY2==-1)
122 DrawTileSelect(0,&numrows,&numcols);
129 SelY2=((my-16)>>(tsize+2))+thebase;
130 SelX2=((mx-left)>>(tsize-1));
131 if (SelX1==-1 && SelY1==-1)
136 DrawTileSelect(0,&numrows,&numcols);
145 if (XMSlookup[tile+tilebase]>=0)
146 whicht=tile+tilebase;
151 whichtm=tile+tilembase+numcols*maxiconrows+tilenum;
152 if (XMSlookup[whichtm]==-1)
156 if (XMSlookup[tile+tilenum]>=0 || !tile)
167 if (keydown[0x48]) // UP
168 DrawTileSelect(-1,&numrows,&numcols);
170 if (keydown[0x50]) // DOWN
171 DrawTileSelect(1,&numrows,&numcols);
173 if (keydown[0x47]) // HOME
175 if (whichscreen==TILES)
176 DrawTileSelect(-tilebase/numcols,&numrows,&numcols);
178 if (whichscreen==MASKED)
179 DrawTileSelect(-tilembase/numcols,&numrows,&numcols);
182 if (keydown[0x4f]) // END
184 if (whichscreen==TILES)
185 DrawTileSelect(tilenum,&numrows,&numcols);
187 if (whichscreen==MASKED)
188 DrawTileSelect(tilemnum,&numrows,&numcols);
191 if (keydown[0x49]) // PgUP
193 DrawTileSelect(-numrows,&numrows,&numcols);
194 if (!keydown[0x1d]) // if not CTRL down, wait for keyup
195 while(keydown[0x49]);
198 if (keydown[0x51]) // PgDN
200 DrawTileSelect(numrows,&numrows,&numcols);
201 if (!keydown[0x1d]) // if not CTRL down, wait for keyup
202 while(keydown[0x51]);
205 if (keydown[0x39]) // SPACEBAR
208 while(keydown[0x39]);
216 if (keydown[0x2e] && (whichscreen==TILES || whichscreen==MASKED))
218 char temp[]="COPY MODE";
220 sx=screencenterx-strlen(temp)/2;
224 while(keydown[0x2e]);
237 sx=screencenterx-strlen(temp)/2;
239 SelX1=SelX2=SelY1=SelY2=-1;
242 DrawTileSelect(0,&numrows,&numcols);
250 // 'ENTER' TO FINALIZE COPY
256 if (MouseButton()) // IF CLICKED ON 'EXIT' WITH MOUSE
260 sx=screencenterx-strlen(temp)/2;
266 TileCopy.w=SelX2-SelX1+1;
267 TileCopy.h=SelY2-SelY1+1;
268 TileCopy.MapOrTileSelect=(whichscreen==TILES)+2*(whichscreen==MASKED);
270 while(keydown[0x1c]);
273 SelX1=SelX2=SelY1=SelY2=-1;
274 DrawTileSelect(0,&numrows,&numcols);
278 // NORMAL TILE SELECT
281 if (whichscreen!=TILES)
283 SelX1=SelX2=SelY1=SelY2=-1;
286 DrawDialog(&SelTd,0);
288 DrawTileSelect(0,&numrows,&numcols);
292 GetButtonXY(&SelTd,0,&sx,&sy);
294 print(SelTb[0].text);
298 // MASKED TILE SELECT
301 if (tilemnum && whichscreen!=MASKED)
303 SelX1=SelX2=SelY1=SelY2=-1;
306 DrawDialog(&SelTd,0);
308 DrawTileSelect(0,&numrows,&numcols);
312 GetButtonXY(&SelTd,1,&sx,&sy);
314 print(SelTb[1].text);
321 if (tilemnum && whichscreen!=ICONS)
324 DrawDialog(&SelTd,0);
326 DrawTileSelect(0,&numrows,&numcols);
330 GetButtonXY(&SelTd,2,&sx,&sy);
332 print(SelTb[2].text);
339 SelX1=SelX2=SelY1=SelY2=-1;
347 // DRAW THE CURRENT TILES IN THE TILE-SELECT WINDOW
349 void DrawCurrentTiles(void)
352 GetButtonXY(&SelTd,0,&sx,&sy);
354 CombineTiles(whicht,0,0,tsize);
355 DrawTile(sx,sy*8,tsize);
365 GetButtonXY(&SelTd,1,&sx,&sy);
367 CombineTiles(-BkgndColor,whichtm,0,tsize);
368 DrawTile(sx,sy*8,tsize);
370 (whichtm==tilenum)?print(" No "):printhex(whichtm-tilenum);
374 (whichtm==tilenum)?print(" Tile "):printint(whichtm-tilenum);
377 GetButtonXY(&SelTd,2,&sx,&sy);
379 CombineTiles(-ICONBACK,whichi,0,tsize);
380 DrawTile(sx,sy*8,tsize);
382 (whichi==tilenum)?print(" No "):printhex(whichi-tilenum);
385 (whichi==tilenum)?print(" Icon "):printint(whichi-tilenum);
393 // CHECK TILESELECT EDGES
395 void CheckTSelectEdges(int x,int y,int basey)
399 xx=left+(x<<(tsize-1));
416 if (x==SelX1 && y==SelY1-basey)
420 case 1: drawchar(xx,yy,1); return;
421 case 2: drawchar(xx ,yy,1);
423 drawchar(xx ,yy+1,4);
425 case 3: drawchar(xx,yy,1);
438 if (x==SelX2 && y==SelY2-basey)
442 case 1: drawchar(xx,yy,8); return;
443 case 2: drawchar(xx+1,yy+1,8);
447 case 3: drawchar(xx+3,yy+3,8);
449 drawchar(xx+3,yy ,5);
450 drawchar(xx+3,yy+1,5);
451 drawchar(xx+3,yy+2,5);
453 drawchar(xx ,yy+3,7);
454 drawchar(xx+1,yy+3,7);
455 drawchar(xx+2,yy+3,7);
459 if (x==SelX2 && y==SelY1-basey)
463 case 1: drawchar(xx,yy,3); return;
464 case 2: drawchar(xx+1,yy,3);
466 drawchar(xx+1,yy+1,5);
468 case 3: drawchar(xx+3,yy,3);
474 drawchar(xx+3,yy+1,5);
475 drawchar(xx+3,yy+2,5);
476 drawchar(xx+3,yy+3,5);
480 if (x==SelX1 && y==SelY2-basey)
484 case 1: drawchar(xx,yy,6); return;
485 case 2: drawchar(xx,yy+1,6);
486 drawchar(xx+1,yy+1,7);
489 case 3: drawchar(xx,yy+3,6);
491 drawchar(xx ,yy+2,4);
492 drawchar(xx ,yy+1,4);
495 drawchar(xx+1,yy+3,7);
496 drawchar(xx+2,yy+3,7);
497 drawchar(xx+3,yy+3,7);
502 if (x==SelX1 && y>SelY1-basey && y<SelY2-basey)
506 case 3: drawchar(xx,yy+3,4);
508 case 2: drawchar(xx,yy+1,4);
509 case 1: drawchar(xx,yy,4);
514 if (y==SelY1-basey && x>SelX1 && x<SelX2)
518 case 3: drawchar(xx+3,yy,2);
520 case 2: drawchar(xx+1,yy,2);
521 case 1: drawchar(xx ,yy,2);
526 if (x==SelX2 && y>SelY1-basey && y<SelY2-basey)
530 case 1: drawchar(xx,yy,5); return;
531 case 2: drawchar(xx+1,yy,5);
532 drawchar(xx+1,yy+1,5);
534 case 3: drawchar(xx+3,yy,5);
535 drawchar(xx+3,yy+1,5);
536 drawchar(xx+3,yy+2,5);
537 drawchar(xx+3,yy+3,5);
542 if (y==SelY2-basey && x>SelX1 && x<SelX2)
546 case 1: drawchar(xx,yy,7); return;
547 case 2: drawchar(xx ,yy+1,7);
548 drawchar(xx+1,yy+1,7);
550 case 3: drawchar(xx ,yy+3,7);
551 drawchar(xx+1,yy+3,7);
552 drawchar(xx+2,yy+3,7);
553 drawchar(xx+3,yy+3,7);
562 // FILL THE TILE SELECT SCREEN WITH TILES
564 void DrawTileSelect(int deltarow,int *retrows,int *retcols)
567 int numcols,numrows,i,j;
575 numrows=18-10*(tsize==2)-15*(tsize==3);
579 numrows=49-23*(tsize==2)-34*(tsize==3);
585 case 1: numcols=36; break;
586 case 2: numcols=18; break;
590 if (whichscreen==TILES && tilebase+numrows*numcols>tilenum)
593 numrows=tilenum/numcols;
596 if (whichscreen==MASKED && tilembase+numrows*numcols>tilemnum-maxiconrows*numcols)
599 numrows=tilemnum/numcols-maxiconrows;
602 if (whichscreen==ICONS && numrows*numcols>maxiconrows*numcols)
608 switch((deltarow<0?-1:deltarow>0?1:0))
614 tilebase+=deltarow*numcols;
619 tilembase+=deltarow*numcols;
628 tilebase+=deltarow*numcols;
629 if (tilebase+numrows*numcols>tilenum)
630 tilebase=tilenum-numcols*numrows;
633 tilembase+=deltarow*numcols;
634 if (tilembase+numrows*numcols>tilemnum-maxiconrows*numcols)
635 tilembase=(tilemnum-maxiconrows*numcols)-numcols*numrows;
642 for(j=0;j<numrows;j++)
643 for(i=0;i<numcols;i++)
645 CombineTiles(tilebase+j*numcols+i,0,0,tsize);
648 DrawTile(i*2+left,j*16+16,tsize);
649 CheckTSelectEdges(i,j,tilebase/numcols);
654 for(j=0;j<numrows;j++)
655 for(i=0;i<numcols;i++)
657 CombineTiles(-BkgndColor,tilenum+numcols*maxiconrows+tilembase+j*numcols+i,0,tsize);
660 DrawTile(i*2+left,j*16+16,tsize);
661 CheckTSelectEdges(i,j,tilembase/numcols);
666 for(j=0;j<numrows;j++)
667 for(i=0;i<numcols;i++)
669 CombineTiles(-ICONBACK,tilenum+j*numcols+i,0,tsize);
672 DrawTile(i*2+left,j*16+16,tsize);
691 ////////////////////////////////////////////////////
695 ////////////////////////////////////////////////////
696 void Item_About(void)
698 char dstr[200]=IDSTSTR;
700 strcat(dstr,"\n\n IdWare by John Romero\n");
702 strcat(dstr,__DATE__);
703 strcat(dstr,"\n (C)1991 Id Software\n\n"
704 " DeluxePaint for Tile Maps! ");
706 ErrDialog(dstr," OK ");
709 ////////////////////////////////////////////////////
711 // Item - Video Mode Switch
713 ////////////////////////////////////////////////////
714 btype VMS1b[]={{" CGA 320x200 ",5,2,1},
715 {" EGA 320x200 ",5,5,1},
716 {" EGA 640x350 ",5,8,1},
717 {" VGA 320x200 ",5,11,1}};
718 DialogDef VMS1d={"Select the resolution:",22,14,4,&VMS1b[0],NULL};
720 void Item_ModeSwitch(void)
724 for(i=0;i<VMS1d.numbuttons;i++)
731 // which=DoDialog(&VMS1d);
733 // Keep track of last video mode!
755 rtn=LoadGraphStuff(1,CGA);
759 ErrDialog("There aren't any CGA\n"
760 "graphics files available!"," OK ");
770 XMSlookup=CgaXMSlookup;
777 rtn=LoadGraphStuff(1,EGA1);
781 ErrDialog("There aren't any EGA\n"
782 "graphics files available!"," OK ");
792 XMSlookup=EgaXMSlookup;
799 rtn=LoadGraphStuff(1,EGA1);
803 ErrDialog("There aren't any EGA\n"
804 "graphics files available!"," OK ");
814 XMSlookup=EgaXMSlookup;
821 rtn=LoadGraphStuff(1,VGA);
825 ErrDialog("There aren't any VGA\n"
826 "graphics files available!"," OK ");
836 XMSlookup=VgaXMSlookup;
841 InitDesktop(TED5MenuBar,0);
845 if (xbase+screenw>mapwidth)
846 xbase=mapwidth-screenw;
847 if (mapwidth<screenw)
849 if (ybase+screenh>mapheight)
850 ybase=mapheight-screenh;
851 if (mapheight<screenh)
858 ////////////////////////////////////////////////////
862 ////////////////////////////////////////////////////
863 btype MapStatsb={" OK ",11,11,2};
864 DialogDef MapStatsd={" MAP STATS\n\n"
869 24,13,1,&MapStatsb,NULL};
871 void Item_MapStats(void)
874 unsigned i,_seg *unique;
876 DrawDialog(&MapStatsd,1);
878 GetDialogXY(&MapStatsd,&sx,&sy);
889 print(MapHeader.name);
893 if (MapFileHeader->maptype&BPLANE)
895 if (MapFileHeader->maptype&FPLANE)
897 if (MapFileHeader->maptype&IPLANE)
901 // Count amount of unique background tiles
905 if (MapFileHeader->maptype&BPLANE)
909 print("Unique Bkgnd Tiles:");
910 MMAllocate((memptr *)&unique,tilenum*2);
911 _fmemset(unique,0,tilenum*2);
912 for (i=0;i<mapwidth*mapheight;i++)
913 unique[MapBkgnd[i]]=1;
914 for (i=0;i<tilenum;i++)
916 MMFreePtr((memptr *)&unique);
921 // Count amount of unique foreground tiles
925 if (MapFileHeader->maptype&FPLANE)
929 print("Unique Frgnd Tiles:");
930 MMAllocate((memptr *)&unique,tilemnum*2);
931 _fmemset(unique,0,tilemnum*2);
932 for (i=0;i<mapwidth*mapheight;i++)
934 unique[MapFrgnd[i]]=1;
935 for (i=0;i<tilemnum;i++)
937 MMFreePtr((memptr *)&unique);
942 // Count amount of icons
946 if (MapFileHeader->maptype&IPLANE)
950 print("Amount of Icons:");
951 for (i=0;i<mapwidth*mapheight;i++)
958 // Display amount of memory the map needs
965 if (MapFileHeader->maptype&BPLANE)
966 length+=2L*mapwidth*mapheight;
967 if (MapFileHeader->maptype&FPLANE)
968 length+=2L*mapwidth*mapheight;
969 if (MapFileHeader->maptype&IPLANE)
970 length+=2L*mapwidth*mapheight;
971 length+=sizeof(MapHeaderStr);
973 print("Size of map:");
974 length=(length+1023)/1024;
980 CheckButtons(&MapStatsd);
985 ////////////////////////////////////////////////////
987 // Item - Edit New Map
989 ////////////////////////////////////////////////////
990 btype DOSAVEb[]={{" Yes ",3,3,2},
992 DialogDef DOSAVEd={"Your map has changed!\n"
994 21,5,2,&DOSAVEb[0],NULL};
996 void Item_EditMap(void)
1003 which=DoDialog(&DOSAVEd);
1011 if ((which=SelectMap(1,CREATED,"TO EDIT"))==-1)
1017 TEDInfo->level=whichmap=which;
1020 InitDesktop(TED5MenuBar,0);
1022 FigureScreenEdges();
1027 ////////////////////////////////////////////////////
1031 ////////////////////////////////////////////////////
1032 void Item_SaveMap(void)
1038 ////////////////////////////////////////////////////
1040 // Item - Create Map
1042 ////////////////////////////////////////////////////
1043 void Item_CreateMap(void)
1049 button=DoDialog(&DoCreated);
1059 InitDesktop(TED5MenuBar,0);
1061 FigureScreenEdges();
1066 ////////////////////////////////////////////////////
1068 // Item - Delete Map
1070 ////////////////////////////////////////////////////
1071 btype AreSureB[]={{" Yes ",1,4,1},
1073 DialogDef AreSureD={"Are you sure you\n"
1074 "you want to delete",
1075 18,6,2,&AreSureB[0],NULL};
1077 void Item_DeleteMap(void)
1079 MapHeaderStr TempHead;
1080 int whichdel,which,temp;
1082 if ((whichdel=SelectMap(1,CREATED,"TO DELETE"))==-1)
1085 if (whichmap==whichdel)
1087 ErrDialog("I'm just not gonna stand for\n"
1088 "you deleting the map you're\n"
1089 "currently editing. I'm not\n"
1090 "gonna doit. Nope."," Gee... ");
1094 LoadFile(mapname,(char huge *)&TempHead,
1095 MapFileHeader->dataoffsets[whichdel],sizeof(MapHeaderStr));
1097 DrawDialog(&AreSureD,1);
1098 GetDialogXY(&AreSureD,&sx,&sy);
1100 sx=screencenterx-(strlen(TempHead.name)+1)/2;
1101 print(TempHead.name);
1105 which=CheckButtons(&AreSureD);
1111 RestoreBackground();
1116 RestoreBackground();
1119 ////////////////////////////////////////////////////
1121 // Item - Amputate Maps
1123 ////////////////////////////////////////////////////
1124 void Item_Amputate(void)
1127 MapHeaderStr TempHead;
1128 int which1,which2,whichtemp,i,button;
1132 if ((which1 = SelectMap(1,CREATED,"TO START AMPUTATE"))==-1)
1135 LoadFile(mapname,(char huge *)&TempHead,
1136 MapFileHeader->dataoffsets[which1],sizeof(MapHeaderStr));
1138 if ((which2 = SelectMap(1,ANYLIST,"TO END AMPUTATE"))==-1)
1141 if (which2 < which1)
1148 if (whichmap >= which1 && whichmap <= which2)
1150 ErrDialog ( "The currently loaded map\n"
1151 "is within that range!\n"
1152 "NON-AMPUTATENESS!!","Wah!");
1156 DrawDialog(&AreSureD,1);
1157 button = CheckButtons(&AreSureD);
1161 for (i = which1;i <= which2;i++)
1163 MapFileHeader->dataoffsets[i] = -1;
1164 MapFileHeader->datalengths[i] = 0;
1167 DirtyFlag = writeH = 1;
1173 ////////////////////////////////////////////////////
1175 // Item - Switch Maps
1177 ////////////////////////////////////////////////////
1178 void Item_SwitchMap(void)
1181 MapHeaderStr TempHead;
1187 if ((which1=SelectMap(1,CREATED,"TO SWAP"))==-1)
1189 LoadFile(mapname,(char huge *)&TempHead,
1190 MapFileHeader->dataoffsets[which1],sizeof(MapHeaderStr));
1191 strcpy(tstr,"TO SWAP WITH '");
1192 strcat(tstr,TempHead.name);
1194 if ((which2=SelectMap(1,ANYLIST,tstr))==-1)
1197 if (which1==whichmap) // MAKE SURE THE CURRENTLY EDITED MAP GETS CHANGED!
1200 if (which2==whichmap)
1203 temp=MapFileHeader->dataoffsets[which1];
1205 strcpy(tstr,MapNames[which1]);
1206 strcpy(MapNames[which1],MapNames[which2]);
1207 strcpy(MapNames[which2],tstr);
1209 MapFileHeader->dataoffsets[which1]=MapFileHeader->dataoffsets[which2];
1210 MapFileHeader->dataoffsets[which2]=temp;
1215 ////////////////////////////////////////////////////
1219 ////////////////////////////////////////////////////
1220 btype Qbuttons[]={{" Yes ",4,2,2},{" No ",12,2,1}},
1221 DoSaveb[]={{" Yes ",7,4,2},{" No ",14,4,1}};
1222 DialogDef Qdialog={"Quit - Are you sure?",20,4,2,&Qbuttons[0],NULL},
1223 DoSaved={"The map has been modified.\n"
1224 "Do you want to SAVE it\n"
1225 "before exiting TED5?",26,6,2,&DoSaveb[0],NULL},
1226 DoCreated={"The map has been modified.\n"
1227 "Do you want to SAVE it\n"
1228 "before CREATING a new one?",26,6,2,&DoSaveb[0],NULL};
1230 void Item_Quit(void)
1234 button=DoDialog(&Qdialog);
1238 TEDInfo->lastvid=videomode;
1239 TEDInfo->level=whichmap;
1240 TEDInfo->OldCgaXMS=0;
1241 TEDInfo->OldEgaXMS=0;
1242 TEDInfo->OldVgaXMS=0;
1243 TEDInfo->OldCgaXMSsize=0;
1244 TEDInfo->OldEgaXMSsize=0;
1245 TEDInfo->OldVgaXMSsize=0;
1247 TEDInfo->pflags=((planeton&1)<<6)|
1257 button=DoDialog(&DoSaved);
1261 return; // ESC exits
1268 ////////////////////////////////////////////////////
1270 // Item - Edit Map Names
1272 ////////////////////////////////////////////////////
1274 btype EMNb[]={{EMNstring,1,4,1},
1277 DialogDef EMNd={" MAP RENAME\n\nChange...\n\n\n\nTo..."
1278 ,20,13,3,&EMNb[0],NULL};
1280 void Item_EditMapNames(void)
1282 int which,mapnum,redraw=0,omapnum,oxb,oyb;
1283 MapHeaderStr TempHeader;
1292 if ((mapnum=SelectMap(1,CREATED,"TO RENAME"))<0)
1297 strcpy(EMNstring,MapHeader.name);
1300 DrawDialog(&EMNd,1);
1301 GetDialogXY(&EMNd,&sx,&sy);
1309 which=CheckButtons(&EMNd);
1316 RestoreBackground();
1317 if ((mapnum=SelectMap(1,CREATED,"TO RENAME"))<0)
1331 strcpy(EMNstring,MapHeader.name);
1333 DrawDialog(&EMNd,1);
1338 GetButtonXY(&EMNd,1,&sx,&sy);
1339 print(EMNb[1].text);
1340 GetButtonXY(&EMNd,1,&sx,&sy);
1344 strcpy(MapHeader.name,temp);
1345 strcpy(MapNames[mapnum],temp);
1351 GetButtonXY(&EMNd,1,&sx,&sy);
1352 print(EMNb[1].text);
1362 RestoreBackground();
1372 ////////////////////////////////////////////////////
1374 // Item - Paste Mode
1376 ////////////////////////////////////////////////////
1377 void Item_Paste(void)
1385 px=(pixelx>>(tsize+2))+xbase;
1386 py=((pixely-8)>>(tsize+2))+ybase;
1389 ////////////////////////////////////////////////////
1393 ////////////////////////////////////////////////////
1394 void Item_Copy(void)
1398 SelX1=SelY1=SelX2=SelY2=-1;
1402 ////////////////////////////////////////////////////
1406 ////////////////////////////////////////////////////
1407 void Item_LastVideo(void)
1412 videomode=lastvideo;
1423 XMSlookup=CgaXMSlookup;
1428 XMSlookup=EgaXMSlookup;
1432 XMSlookup=VgaXMSlookup;
1436 setvideo(videomode);
1437 InitDesktop(TED5MenuBar,0);
1439 FigureScreenEdges();
1441 if (xbase+screenw>mapwidth)
1442 xbase=mapwidth-screenw;
1443 if (mapwidth<screenw)
1445 if (ybase+screenh>mapheight)
1446 ybase=mapheight-screenh;
1447 if (mapheight<screenh)
1454 ////////////////////////////////////////////////////
1456 // Item - Switch to the Last Map
1458 ////////////////////////////////////////////////////
1459 void Item_LastMap(void)
1463 if (!CheckForMapSave())
1468 int which=SelectMap(1,CREATED,"TO EDIT");
1479 InitDesktop(TED5MenuBar,0);
1485 ////////////////////////////////////////////////////
1487 // Item - Flood Fill!
1489 ////////////////////////////////////////////////////
1490 void Item_FloodFill(void)
1497 void DoFloodFill(int x,int y,int whichb)
1499 #define NUMSPORES 500
1501 int obx[NUMSPORES],oby[NUMSPORES],i,used,j,width,k,highest,height,
1502 vectx[4]={0,1,0,-1},vecty[4]={-1,0,1,0},orgt,orgm,orgi,Ton,Mon,Ion;
1503 unsigned ptr,newoff,whichplanes=0,ctrl=0;
1504 int nx,ny,newt,newm,newi;
1507 if (keydown[0x1d] || whichb)
1510 whichplanes=planeton+planemon+planeion;
1513 ErrDialog("I will only allow Flood Filling\n"
1514 "one plane at a time; you have\n"
1515 "more than one plane selected."," OK ");
1519 for (i=0;i<NUMSPORES;i++)
1524 newoff=ptr=oby[0]*mapwidth+obx[0];
1525 width=MapHeader.width;
1526 height=MapHeader.height;
1529 if (obx[0]<0 || oby[0]<0 || obx[0]>width || oby[0]>height)
1540 orgt=*(MapBkgnd+ptr);
1541 orgm=*(MapFrgnd+ptr);
1542 orgi=*(MapInfoPl+ptr);
1544 if (((Ton?whicht==orgt:0) ||
1545 (Mon?whichtm-tilenum==orgm:0) ||
1546 (Ion?whichi-tilenum==orgi:0)) && !ctrl)
1555 UndoRegion.x=UndoRegion.y=0;
1556 UndoRegion.w=mapwidth;
1557 UndoRegion.h=mapheight;
1561 unsigned from=(TileCopy.y+(y%TileCopy.h))*mapwidth+
1562 TileCopy.x+(x%TileCopy.w);
1564 switch(TileCopy.MapOrTileSelect)
1566 case 0: // COPY BUFFER
1567 Ton=TileCopy.PlanesCopied&BPLANE;
1568 Mon=TileCopy.PlanesCopied&FPLANE;
1569 Ion=TileCopy.PlanesCopied&IPLANE;
1571 newt=CutBkgnd[from];
1572 newm=CutFrgnd[from];
1573 newi=CutInfoPl[from];
1580 newt=((y%TileCopy.h)+TileCopy.y)*selectcols+
1581 TileCopy.x+(x%TileCopy.w);
1582 if (XMSlookup[newt]<0)
1589 newm=((y%TileCopy.h)+TileCopy.y)*selectcols+
1590 TileCopy.x+(x%TileCopy.w)+tilenum+maxiconrows*selectcols;
1591 if (XMSlookup[newm]<0)
1600 newm=whichtm-tilenum;
1601 newi=whichi-tilenum;
1605 *(MapBkgnd+newoff)=newt;
1607 *(MapFrgnd+newoff)=newm;
1609 *(MapInfoPl+newoff)=newi;
1613 for (i=0;i<=highest;i++)
1615 // SEE IF SPORE EXISTS
1620 // DRAW TILE AT SPORE IF IT'S ONSCREEN
1622 if (oby[i]>=ybase && oby[i]<ybase+screenh &&
1623 obx[i]>=xbase && obx[i]<xbase+screenw)
1625 unsigned oldt,oldm,oldi,off;
1627 off=oby[i]*width+obx[i];
1629 oldt=*(MapBkgnd+off);
1630 oldm=*(MapFrgnd+off)+tilenum;
1631 oldi=*(MapInfoPl+off)+tilenum;
1633 CombineTiles(viewton?oldt:-BkgndColor,
1637 DrawTile((obx[i]-xbase)<<(tsize-1),((oby[i]-ybase)<<(tsize+2))+8,tsize);
1649 // SEARCH 4 QUADRANTS FOR A SPORE TO FILL
1650 // (ONLY 4 QUADS SO WE DON'T FILL THRU DIAGONALS)
1655 newoff=(y+vecty[j])*mapwidth+x+vectx[j];
1657 if ((Ton?*(MapBkgnd+newoff)==orgt:1) &&
1658 (Mon?*(MapFrgnd+newoff)==orgm:1) &&
1659 (Ion?*(MapInfoPl+newoff)==orgi:1))
1661 for (k=0;k<NUMSPORES;k++)
1666 if (obx[k]<0 || obx[k]>width || oby[k]<0 || oby[k]>height)
1674 *(MapBkgnd+newoff)=whicht;
1676 *(MapFrgnd+newoff)=whichtm-tilenum;
1678 *(MapInfoPl+newoff)=whichi-tilenum;
1686 if (keydown[1]) // ESC OUT
1700 newoff=ny*mapwidth+nx;
1702 if ((Ton?*(MapBkgnd+newoff)==orgt:1) &&
1703 (Mon?*(MapFrgnd+newoff)==orgm:1) &&
1704 (Ion?*(MapInfoPl+newoff)==orgi:1))
1706 for (k=0;k<NUMSPORES;k++)
1711 if (obx[k]<0 || obx[k]>width || oby[k]<0 || oby[k]>height)
1717 from=(TileCopy.y+(ny%TileCopy.h))*mapwidth+
1718 TileCopy.x+(nx%TileCopy.w);
1720 switch(TileCopy.MapOrTileSelect)
1722 case 0: // COPY BUFFER
1723 Ton=TileCopy.PlanesCopied&BPLANE;
1724 Mon=TileCopy.PlanesCopied&FPLANE;
1725 Ion=TileCopy.PlanesCopied&IPLANE;
1727 newt=CutBkgnd[from];
1728 newm=CutFrgnd[from];
1729 newi=CutInfoPl[from];
1736 newt=((ny%TileCopy.h)+TileCopy.y)*selectcols+
1737 TileCopy.x+(nx%TileCopy.w);
1738 if (XMSlookup[newt]<0)
1745 newm=((ny%TileCopy.h)+TileCopy.y)*selectcols+
1746 TileCopy.x+(nx%TileCopy.w)+tilenum+maxiconrows*selectcols;
1747 if (XMSlookup[newm]<0)
1754 *(MapBkgnd+newoff)=newt;
1756 *(MapFrgnd+newoff)=newm;
1758 *(MapInfoPl+newoff)=newi;
1768 if (keydown[1]) // ESC OUT
1786 ////////////////////////////////////////////////////
1788 // If map has been changed, ask user if they want
1789 // to SAVE it before continuing.
1791 ////////////////////////////////////////////////////
1792 btype oktosaveB[]={{" Yes ",10,2,2},{" No ",20,2,1}};
1793 DialogDef oktosaveD={"The map has been modified!\n"
1794 "Save it?",26,4,2,&oktosaveB[0],NULL};
1796 int CheckForMapSave(void)
1800 int which=DoDialog(&oktosaveD);
1810 ////////////////////////////////////////////////////
1812 // Zero all special mode flags
1814 ////////////////////////////////////////////////////
1815 void ZeroModes(void)
1817 SelX1=SelX2=SelY1=SelY2=-1;
1818 if (BfillMode || SelectMode || PasteMode || FillMode)
1824 BfillMode=SelectMode=PasteMode=FillMode=0;
1828 ////////////////////////////////////////////////////
1830 // Item - Count Map Tiles
1832 ////////////////////////////////////////////////////
1836 {" MASKED ",17,20,1},
1837 {" Rebuild ",27,20,1}
1839 DialogDef CMTd={" Count Unused Map Tiles",38,22,4,&CMTb[0],0};
1840 unsigned char _seg *tarray,_seg *tmarray,thesparse;
1843 void Item_CountTiles(void)
1847 unsigned i,j,dx,dy,max,exit=0,numt,numtm,oxbase,oybase,nsize,nmsize,redraw;
1848 int which,dumrow,dumcol;
1858 // COMPUTE SIZE OF EACH TILE
1862 case CGA: nsize=16; nmsize=32; break;
1864 case EGA2: nsize=32; nmsize=40; break;
1865 case VGA: nsize=64; nmsize=128;
1867 nsize=nsize<<((tsize-1)<<1);
1868 nmsize=nmsize<<((tsize-1)<<1);
1872 DrawDialog(&CMTd,1);
1873 GetDialogXY(&CMTd,&dx,&dy);
1876 print("Counting tiles in map:");
1879 MMAllocate((memptr *)&tarray,tilenum);
1880 MMAllocate((memptr *)&tmarray,tilemnum);
1881 _fmemset(tarray,0,tilenum);
1882 _fmemset(tmarray,0,tilemnum);
1885 // Now, load each map in & count the tiles
1887 pb=MapFileHeader->maptype&BPLANE;
1888 pf=MapFileHeader->maptype&FPLANE;
1889 pi=MapFileHeader->maptype&IPLANE;
1892 if (MapFileHeader->dataoffsets[i]>=0)
1899 max=mapwidth*mapheight;
1903 tarray[MapBkgnd[j]]=1;
1905 tmarray[MapFrgnd[j]]=1;
1907 tmarray[MapInfoPl[j]]=1;
1912 // Find a SPARSE tile
1914 for (i=0;i<tilenum;i++)
1922 // Count unused amount
1925 for (i=0;i<tilenum;i++)
1926 if (XMSlookup[i]>=0 && !tarray[i])
1930 for (i=0;i<tilemnum;i++)
1931 if (XMSlookup[i+tilenum]>=0 && !tmarray[i])
1936 // INPUT FROM DIALOG
1944 print("Unused TILES:");
1946 print(", unused MASKED:");
1951 print("TILE Memory:");
1952 printint((1023l+(long)numt*nsize)/1024);
1953 print("K, MASKED Memory:");
1954 printint((1023l+(long)numtm*nmsize)/1024);
1963 which=CheckButtonsRet(&CMTd);
1964 MouseCoords(&pixelx,&pixely);
1967 if (MouseButton() && pixelx>dx && pixelx<dx+37 && pixely>dy && pixely<dy+18)
1969 int tile=((pixelx-dx-1)>>(tsize-1))+((pixely-dy-1)>>(tsize-1))*(9<<(3-tsize));
1974 if (!tarray[tile+tilebase] && XMSlookup[tile+tilebase]>=0)
1976 tarray[tile+tilebase]=1;
1982 if (!tmarray[tile+tilembase] && XMSlookup[tilenum+tile+tilembase]>=0)
1984 tmarray[tile+tilembase]=1;
2001 GetButtonXY(&CMTd,which-1,&sx,&sy);
2002 print(CMTb[which-1].text);
2010 GetButtonXY(&CMTd,which-1,&sx,&sy);
2011 print(CMTb[which-1].text);
2018 // REBUILD GRAPHICS FILE & HEADER
2022 char newgfx[13]="NEW?GA.",
2023 newhead[13]="NEW?HEAD.",
2024 newhobj[13]="NEW?HEAD.",
2025 oldhead[13]="?GAHEAD.";
2030 newgfx[3]=format[0];
2031 newhead[3]=format[0];
2032 newhobj[3]=format[0];
2033 oldhead[0]=format[0];
2036 LoadIn(oldhead,(memptr *)&gfxhead);
2037 for (i=0;i<tilenum;i++)
2040 *(gfxhead+i*3)=*(gfxhead+i*3);
2065 while(keydown[0x49]);
2071 while(keydown[0x51]);
2074 } while(!redraw && !exit);
2077 RestoreBackground();
2079 tilebase=tilembase=0;
2087 // FILL THE "UNUSED TILES" SCREEN WITH TILES
2089 void DrawUnused(int deltarow)
2092 int numcols,numrows,i,j,top;
2094 if (whichscreen==ICONS)
2099 numrows=18-10*(tsize==2)-15*(tsize==3);
2102 if (videomode==EGA2)
2110 case 1: numcols=36; break;
2111 case 2: numcols=18; break;
2115 if (whichscreen==TILES && tilebase+numrows*numcols>tilenum)
2118 numrows=tilenum/numcols;
2121 if (whichscreen==MASKED && tilembase+numrows*numcols>tilemnum)
2124 numrows=tilemnum/numcols;
2127 switch((deltarow<0?-1:deltarow>0?1:0))
2133 tilebase+=deltarow*numcols;
2138 tilembase+=deltarow*numcols;
2147 tilebase+=deltarow*numcols;
2148 if (tilebase+numrows*numcols>tilenum)
2149 tilebase=tilenum-numcols*numrows;
2152 tilembase+=deltarow*numcols;
2153 if (tilembase+numrows*numcols>tilemnum)
2154 tilembase=tilemnum-numcols*numrows;
2161 for(j=0;j<numrows;j++)
2162 for(i=0;i<numcols;i++)
2164 if (!tarray[tilebase+j*numcols+i] && XMSlookup[tilebase+j*numcols+i]>=0)
2165 CombineTiles(tilebase+j*numcols+i,0,0,tsize);
2167 CombineTiles(thesparse,0,0,tsize);
2168 DrawTile(i*2+left,j*16+top,tsize);
2173 for(j=0;j<numrows;j++)
2174 for(i=0;i<numcols;i++)
2176 if (!tmarray[tilembase+j*numcols+i] && XMSlookup[tilenum+tilembase+j*numcols+i]>=0)
2177 CombineTiles(-BkgndColor,tilenum+tilembase+j*numcols+i,0,tsize);
2179 CombineTiles(thesparse,0,0,tsize);
2180 DrawTile(i*2+left,j*16+top,tsize);