X-Git-Url: http://4ch.mooo.com/gitweb/?p=16.git;a=blobdiff_plain;f=16%2Fted5%2FTED5-2.C;fp=16%2Fted5%2FTED5-2.C;h=d778d69095be79f3b122af3419f1c99c1d98667f;hp=0000000000000000000000000000000000000000;hb=4c15d088479b9b6c4a8b298a9db585bc11582321;hpb=21ff8e5607ba86e91ed0d71f6261fd0fcc676e16 diff --git a/16/ted5/TED5-2.C b/16/ted5/TED5-2.C new file mode 100755 index 00000000..d778d690 --- /dev/null +++ b/16/ted5/TED5-2.C @@ -0,0 +1,2184 @@ +//////////////////////////////////////////////////// +//////////////////////////////////////////////////// +// +// TED5-2 : Menu Item Routines +// +//////////////////////////////////////////////////// +//////////////////////////////////////////////////// +#include "ted5.h" +#pragma hdrstop + +//////////////////////////////////////////////////// +// +// Toggle the INFOBAR on and off +// +//////////////////////////////////////////////////// +void Item_ToggleInfo(void) +{ + infobaron^=1; + MouseHide(); + InitDesktop(TED5MenuBar,0); + FigureScreenEdges(); + if (ybase+screenh>mapheight && mapheight>screenh) + ybase--; + DrawMap(); + DrawInfoBar(); + MouseShow(); +} + + +//////////////////////////////////////////////////// +// +// Tile Select +// +//////////////////////////////////////////////////// +btype SelTb[]={{" Tiles ",2,21,1}, + {" Masked ",11,21,1}, + {" Icons ",21,21,1}, + {" Exit ",30,21,2}}; +DialogDef SelTd={"",38,23,4,&SelTb[0],NULL}; + +void SelectTiles(int screen) +{ + int exitok=0,which,i,numrows,numcols,b0,b1,redraw=0; + + // + // if parameter passed, change the screen + // + if (screen) + whichscreen=screen-1; + + if (PasteMode || SelectMode) // RE-BLIT MAP IF WE ARE ENTERING WHILE + redraw=1; // FLOATING AN IMAGE + + PasteMode=SelectMode=0; + SelX1=SelX2=SelY1=SelY2=-1; + + switch(videomode) + { + case CGA: + case EGA1: + case VGA: + SelTd.height=23; + for(i=0;i<4;i++) + SelTb[i].yoff=21; + break; + case EGA2: + SelTd.height=58; + for(i=0;i<4;i++) + SelTb[i].yoff=56; + } + + DrawDialog(&SelTd,1); + DrawTileSelect(0,&numrows,&numcols); + selectcols=numcols; // VERY IMPORTANT TO PASTE-FROM-TILESELECT MODE + DrawCurrentTiles(); + while(keydown[0x39]); // WAIT FOR SPACE-UP + + do + { + which=CheckButtonsRet(&SelTd); + b0=MouseButton()&1; + b1=(MouseButton()>>1)&1; + + if (which<0) + { + // + // GRAB CURRENT TILE FROM MATRIX + // + if (b0 || b1) + { + int mx,my; + + MouseCoords(&mx,&my); + mx/=8; + if (mx>=left && mx=16 && my<=16+(numrows<<(2+tsize))) + { + int tile; + + tile=((my-16)>>(tsize+2))*numcols+ + ((mx-left)>>(tsize-1)); + + if (SelectMode) + { + int thebase; + switch(whichscreen) + { + case TILES: thebase=tilebase/numcols; break; + case MASKED: thebase=tilembase/numcols; + } + + if (b0) + { + sound(1000); + SelY1=((my-16)>>(tsize+2))+thebase; + SelX1=((mx-left)>>(tsize-1)); + if (SelX2==-1 && SelY2==-1) + { + SelX2=SelX1; + SelY2=SelY1; + } + DrawTileSelect(0,&numrows,&numcols); + nosound(); + } + else + if (b1) + { + sound(1000); + SelY2=((my-16)>>(tsize+2))+thebase; + SelX2=((mx-left)>>(tsize-1)); + if (SelX1==-1 && SelY1==-1) + { + SelX1=SelX2; + SelY1=SelY2; + } + DrawTileSelect(0,&numrows,&numcols); + nosound(); + } + } + else + { + switch(whichscreen) + { + case TILES: + if (XMSlookup[tile+tilebase]>=0) + whicht=tile+tilebase; + else + errsound(); + break; + case MASKED: + whichtm=tile+tilembase+numcols*maxiconrows+tilenum; + if (XMSlookup[whichtm]==-1) + whichtm=tilenum; + break; + case ICONS: + if (XMSlookup[tile+tilenum]>=0 || !tile) + whichi=tile+tilenum; + else + errsound(); + break; + } + DrawCurrentTiles(); + } + } + } + + if (keydown[0x48]) // UP + DrawTileSelect(-1,&numrows,&numcols); + else + if (keydown[0x50]) // DOWN + DrawTileSelect(1,&numrows,&numcols); + else + if (keydown[0x47]) // HOME + { + if (whichscreen==TILES) + DrawTileSelect(-tilebase/numcols,&numrows,&numcols); + else + if (whichscreen==MASKED) + DrawTileSelect(-tilembase/numcols,&numrows,&numcols); + } + else + if (keydown[0x4f]) // END + { + if (whichscreen==TILES) + DrawTileSelect(tilenum,&numrows,&numcols); + else + if (whichscreen==MASKED) + DrawTileSelect(tilemnum,&numrows,&numcols); + } + else + if (keydown[0x49]) // PgUP + { + DrawTileSelect(-numrows,&numrows,&numcols); + if (!keydown[0x1d]) // if not CTRL down, wait for keyup + while(keydown[0x49]); + } + else + if (keydown[0x51]) // PgDN + { + DrawTileSelect(numrows,&numrows,&numcols); + if (!keydown[0x1d]) // if not CTRL down, wait for keyup + while(keydown[0x51]); + } + else + if (keydown[0x39]) // SPACEBAR + { + RestoreBackground(); + while(keydown[0x39]); + SelectMode=0; + if (redraw) + DrawMap(); + DrawInfoBar(); + return; + } + else // 'C' TO COPY + if (keydown[0x2e] && (whichscreen==TILES || whichscreen==MASKED)) + { + char temp[]="COPY MODE"; + + sx=screencenterx-strlen(temp)/2; + SelectMode=sy=1; + print(temp); + + while(keydown[0x2e]); + } + } + else + switch(which) + { + case 0: + if (!SelectMode) + exitok=1; + else + { + char temp[]=" "; + + sx=screencenterx-strlen(temp)/2; + SelectMode=0; + SelX1=SelX2=SelY1=SelY2=-1; + sy=1; + print(temp); + DrawTileSelect(0,&numrows,&numcols); + } + break; + + case 4: + if (!SelectMode) + exitok=1; + // + // 'ENTER' TO FINALIZE COPY + // + else + { + char temp[]=" "; + + if (MouseButton()) // IF CLICKED ON 'EXIT' WITH MOUSE + break; + + sound(500); + sx=screencenterx-strlen(temp)/2; + PasteOK=sy=1; + print(temp); + + TileCopy.x=SelX1; + TileCopy.y=SelY1; + TileCopy.w=SelX2-SelX1+1; + TileCopy.h=SelY2-SelY1+1; + TileCopy.MapOrTileSelect=(whichscreen==TILES)+2*(whichscreen==MASKED); + + while(keydown[0x1c]); + nosound(); + SelectMode=0; + SelX1=SelX2=SelY1=SelY2=-1; + DrawTileSelect(0,&numrows,&numcols); + } + break; + // + // NORMAL TILE SELECT + // + case 1: + if (whichscreen!=TILES) + { + SelX1=SelX2=SelY1=SelY2=-1; + SelectMode=0; + whichscreen=TILES; + DrawDialog(&SelTd,0); + DrawCurrentTiles(); + DrawTileSelect(0,&numrows,&numcols); + } + else + errsound(); + GetButtonXY(&SelTd,0,&sx,&sy); + MouseHide(); + print(SelTb[0].text); + MouseShow(); + break; + // + // MASKED TILE SELECT + // + case 2: + if (tilemnum && whichscreen!=MASKED) + { + SelX1=SelX2=SelY1=SelY2=-1; + SelectMode=0; + whichscreen=MASKED; + DrawDialog(&SelTd,0); + DrawCurrentTiles(); + DrawTileSelect(0,&numrows,&numcols); + } + else + errsound(); + GetButtonXY(&SelTd,1,&sx,&sy); + MouseHide(); + print(SelTb[1].text); + MouseShow(); + break; + // + // ICON SELECT + // + case 3: + if (tilemnum && whichscreen!=ICONS) + { + whichscreen=ICONS; + DrawDialog(&SelTd,0); + DrawCurrentTiles(); + DrawTileSelect(0,&numrows,&numcols); + } + else + errsound(); + GetButtonXY(&SelTd,2,&sx,&sy); + MouseHide(); + print(SelTb[2].text); + MouseShow(); + } + + } while(!exitok); + RestoreBackground(); + SelectMode=0; + SelX1=SelX2=SelY1=SelY2=-1; + DrawInfoBar(); + if (redraw) + DrawMap(); +} + + +// +// DRAW THE CURRENT TILES IN THE TILE-SELECT WINDOW +// +void DrawCurrentTiles(void) +{ + MouseHide(); + GetButtonXY(&SelTd,0,&sx,&sy); + sy-=1+tsize; + CombineTiles(whicht,0,0,tsize); + DrawTile(sx,sy*8,tsize); + sx+=2; + printhex(whicht); + sy++; + sx-=5; + printint(whicht); + print(" "); + + if (tilemnum) + { + GetButtonXY(&SelTd,1,&sx,&sy); + sy-=1+tsize; + CombineTiles(-BkgndColor,whichtm,0,tsize); + DrawTile(sx,sy*8,tsize); + sx+=2; + (whichtm==tilenum)?print(" No "):printhex(whichtm-tilenum); + + sy++; + sx-=5; + (whichtm==tilenum)?print(" Tile "):printint(whichtm-tilenum); + print(" "); + + GetButtonXY(&SelTd,2,&sx,&sy); + sy-=1+tsize; + CombineTiles(-ICONBACK,whichi,0,tsize); + DrawTile(sx,sy*8,tsize); + sx+=2; + (whichi==tilenum)?print(" No "):printhex(whichi-tilenum); + sy++; + sx-=5; + (whichi==tilenum)?print(" Icon "):printint(whichi-tilenum); + print(" "); + } + MouseShow(); +} + + +// +// CHECK TILESELECT EDGES +// +void CheckTSelectEdges(int x,int y,int basey) +{ + int xx,yy,temp; + + xx=left+(x<<(tsize-1)); + yy=(y<<(tsize-1))+2; + + if (SelX2SelY1-basey && ySelX1 && xSelY1-basey && ySelX1 && xtilenum) + { + tilebase=0; + numrows=tilenum/numcols; + } + + if (whichscreen==MASKED && tilembase+numrows*numcols>tilemnum-maxiconrows*numcols) + { + tilembase=0; + numrows=tilemnum/numcols-maxiconrows; + } + + if (whichscreen==ICONS && numrows*numcols>maxiconrows*numcols) + { + tilembase=0; + numrows=maxiconrows; + } + + switch((deltarow<0?-1:deltarow>0?1:0)) + { + case -1: + switch(whichscreen) + { + case TILES: + tilebase+=deltarow*numcols; + if (tilebase<0) + tilebase=0; + break; + case MASKED: + tilembase+=deltarow*numcols; + if (tilembase<0) + tilembase=0; + } + break; + case 1: + switch(whichscreen) + { + case TILES: + tilebase+=deltarow*numcols; + if (tilebase+numrows*numcols>tilenum) + tilebase=tilenum-numcols*numrows; + break; + case MASKED: + tilembase+=deltarow*numcols; + if (tilembase+numrows*numcols>tilemnum-maxiconrows*numcols) + tilembase=(tilemnum-maxiconrows*numcols)-numcols*numrows; + } + } + + switch(whichscreen) + { + case TILES: + for(j=0;jmapwidth) + xbase=mapwidth-screenw; + if (mapwidthmapheight) + ybase=mapheight-screenh; + if (mapheightmaptype&BPLANE) + print("BACK"); + if (MapFileHeader->maptype&FPLANE) + print(",FORE"); + if (MapFileHeader->maptype&IPLANE) + print(",INFO"); + + // + // Count amount of unique background tiles + // + sx=ox-9; + sy=oy+4; + if (MapFileHeader->maptype&BPLANE) + { + int amount=0; + + print("Unique Bkgnd Tiles:"); + MMAllocate((memptr *)&unique,tilenum*2); + _fmemset(unique,0,tilenum*2); + for (i=0;imaptype&FPLANE) + { + int amount=0; + + print("Unique Frgnd Tiles:"); + MMAllocate((memptr *)&unique,tilemnum*2); + _fmemset(unique,0,tilemnum*2); + for (i=0;imaptype&IPLANE) + { + int amount=0; + + print("Amount of Icons:"); + for (i=0;imaptype&BPLANE) + length+=2L*mapwidth*mapheight; + if (MapFileHeader->maptype&FPLANE) + length+=2L*mapwidth*mapheight; + if (MapFileHeader->maptype&IPLANE) + length+=2L*mapwidth*mapheight; + length+=sizeof(MapHeaderStr); + + print("Size of map:"); + length=(length+1023)/1024; + printint(length); + print("K"); + } + + MouseShow(); + CheckButtons(&MapStatsd); + RestoreBackground(); +} + + +//////////////////////////////////////////////////// +// +// Item - Edit New Map +// +//////////////////////////////////////////////////// +btype DOSAVEb[]={{" Yes ",3,3,2}, + {" No! ",15,3,1}}; +DialogDef DOSAVEd={"Your map has changed!\n" + " Save it?", + 21,5,2,&DOSAVEb[0],NULL}; + +void Item_EditMap(void) +{ + int which,olddirt; + + olddirt=DirtyFlag; + if (DirtyFlag) + { + which=DoDialog(&DOSAVEd); + if (!which) + return; + if (which==1) + Item_SaveMap(); + DirtyFlag=0; + } + + if ((which=SelectMap(1,CREATED,"TO EDIT"))==-1) + { + DirtyFlag=olddirt; + return; + } + + TEDInfo->level=whichmap=which; + LoadMap(whichmap); + MouseHide(); + InitDesktop(TED5MenuBar,0); + DrawInfoBar(); + FigureScreenEdges(); + DrawMap(); + MouseShow(); +} + +//////////////////////////////////////////////////// +// +// Item - Save Map +// +//////////////////////////////////////////////////// +void Item_SaveMap(void) +{ + SaveMap(0); + DirtyFlag=0; +} + +//////////////////////////////////////////////////// +// +// Item - Create Map +// +//////////////////////////////////////////////////// +void Item_CreateMap(void) +{ + if (DirtyFlag) + { + int button; + + button=DoDialog(&DoCreated); + if (!button) + return; + if (button==1) + Item_SaveMap(); + DirtyFlag=0; + } + + CreateMap(1); + MouseHide(); + InitDesktop(TED5MenuBar,0); + DrawInfoBar(); + FigureScreenEdges(); + DrawMap(); + MouseShow(); +} + +//////////////////////////////////////////////////// +// +// Item - Delete Map +// +//////////////////////////////////////////////////// +btype AreSureB[]={{" Yes ",1,4,1}, + {" No ",11,4,2}}; +DialogDef AreSureD={"Are you sure you\n" + "you want to delete", + 18,6,2,&AreSureB[0],NULL}; + +void Item_DeleteMap(void) +{ + MapHeaderStr TempHead; + int whichdel,which,temp; + + if ((whichdel=SelectMap(1,CREATED,"TO DELETE"))==-1) + return; + + if (whichmap==whichdel) + { + ErrDialog("I'm just not gonna stand for\n" + "you deleting the map you're\n" + "currently editing. I'm not\n" + "gonna doit. Nope."," Gee... "); + return; + } + + LoadFile(mapname,(char huge *)&TempHead, + MapFileHeader->dataoffsets[whichdel],sizeof(MapHeaderStr)); + MouseHide(); + DrawDialog(&AreSureD,1); + GetDialogXY(&AreSureD,&sx,&sy); + sy+=2; + sx=screencenterx-(strlen(TempHead.name)+1)/2; + print(TempHead.name); + print("?"); + MouseShow(); + + which=CheckButtons(&AreSureD); + switch(which) + { + case 1: + temp=whichmap; + whichmap=whichdel; + RestoreBackground(); + SaveMap(1); + whichmap=temp; + return; + } + RestoreBackground(); +} + +//////////////////////////////////////////////////// +// +// Item - Amputate Maps +// +//////////////////////////////////////////////////// +void Item_Amputate(void) +{ + char tstr[40]; + MapHeaderStr TempHead; + int which1,which2,whichtemp,i,button; + long temp; + + + if ((which1 = SelectMap(1,CREATED,"TO START AMPUTATE"))==-1) + return; + + LoadFile(mapname,(char huge *)&TempHead, + MapFileHeader->dataoffsets[which1],sizeof(MapHeaderStr)); + + if ((which2 = SelectMap(1,ANYLIST,"TO END AMPUTATE"))==-1) + return; + + if (which2 < which1) + { + whichtemp = which1; + which1 = which2; + which2 = whichtemp; + } + + if (whichmap >= which1 && whichmap <= which2) + { + ErrDialog ( "The currently loaded map\n" + "is within that range!\n" + "NON-AMPUTATENESS!!","Wah!"); + return; + } + + DrawDialog(&AreSureD,1); + button = CheckButtons(&AreSureD); + switch (button) + { + case 1: + for (i = which1;i <= which2;i++) + { + MapFileHeader->dataoffsets[i] = -1; + MapFileHeader->datalengths[i] = 0; + } + + DirtyFlag = writeH = 1; + SaveMap(0); + } +} + + +//////////////////////////////////////////////////// +// +// Item - Switch Maps +// +//////////////////////////////////////////////////// +void Item_SwitchMap(void) +{ + char tstr[40]; + MapHeaderStr TempHead; + int which1,which2; + long temp; + + while(1) + { + if ((which1=SelectMap(1,CREATED,"TO SWAP"))==-1) + return; + LoadFile(mapname,(char huge *)&TempHead, + MapFileHeader->dataoffsets[which1],sizeof(MapHeaderStr)); + strcpy(tstr,"TO SWAP WITH '"); + strcat(tstr,TempHead.name); + strcat(tstr,"'"); + if ((which2=SelectMap(1,ANYLIST,tstr))==-1) + return; + + if (which1==whichmap) // MAKE SURE THE CURRENTLY EDITED MAP GETS CHANGED! + whichmap=which2; + else + if (which2==whichmap) + whichmap=which1; + + temp=MapFileHeader->dataoffsets[which1]; + + strcpy(tstr,MapNames[which1]); + strcpy(MapNames[which1],MapNames[which2]); + strcpy(MapNames[which2],tstr); + + MapFileHeader->dataoffsets[which1]=MapFileHeader->dataoffsets[which2]; + MapFileHeader->dataoffsets[which2]=temp; + writeH=DirtyFlag=1; + } +} + +//////////////////////////////////////////////////// +// +// Item - Quit +// +//////////////////////////////////////////////////// +btype Qbuttons[]={{" Yes ",4,2,2},{" No ",12,2,1}}, + DoSaveb[]={{" Yes ",7,4,2},{" No ",14,4,1}}; +DialogDef Qdialog={"Quit - Are you sure?",20,4,2,&Qbuttons[0],NULL}, + DoSaved={"The map has been modified.\n" + "Do you want to SAVE it\n" + "before exiting TED5?",26,6,2,&DoSaveb[0],NULL}, + DoCreated={"The map has been modified.\n" + "Do you want to SAVE it\n" + "before CREATING a new one?",26,6,2,&DoSaveb[0],NULL}; + +void Item_Quit(void) +{ + int button; + + button=DoDialog(&Qdialog); + + if (button==1) + { + TEDInfo->lastvid=videomode; + TEDInfo->level=whichmap; + TEDInfo->OldCgaXMS=0; + TEDInfo->OldEgaXMS=0; + TEDInfo->OldVgaXMS=0; + TEDInfo->OldCgaXMSsize=0; + TEDInfo->OldEgaXMSsize=0; + TEDInfo->OldVgaXMSsize=0; + + TEDInfo->pflags=((planeton&1)<<6)| + ((planemon&1)<<5)| + ((planeion&1)<<4)| + ((viewton&1)<<2)| + ((viewmon&1)<<1)| + (viewion&1); + + SaveTEDInfo(); + if (DirtyFlag) + { + button=DoDialog(&DoSaved); + if (button==1) + Item_SaveMap(); + if (!button) + return; // ESC exits + } + SaveOutputHeader(); + Quit(""); + } +} + +//////////////////////////////////////////////////// +// +// Item - Edit Map Names +// +//////////////////////////////////////////////////// +char EMNstring[16]; +btype EMNb[]={{EMNstring,1,4,1}, + {" ",1,8,1}, + {" Exit ",7,11,1}}; +DialogDef EMNd={" MAP RENAME\n\nChange...\n\n\n\nTo..." + ,20,13,3,&EMNb[0],NULL}; + +void Item_EditMapNames(void) +{ + int which,mapnum,redraw=0,omapnum,oxb,oyb; + MapHeaderStr TempHeader; + char temp[16]; + + + CheckForMapSave(); + omapnum=whichmap; + oxb=xbase; + oyb=ybase; + + if ((mapnum=SelectMap(1,CREATED,"TO RENAME"))<0) + return; + + whichmap=mapnum; + LoadMap(whichmap); + strcpy(EMNstring,MapHeader.name); + + MouseHide(); + DrawDialog(&EMNd,1); + GetDialogXY(&EMNd,&sx,&sy); + MouseShow(); + which=2; +#pragma warn -rch + goto badboy; + + do + { + which=CheckButtons(&EMNd); + +badboy: +#pragma warn +rch + switch(which) + { + case 1: + RestoreBackground(); + if ((mapnum=SelectMap(1,CREATED,"TO RENAME"))<0) + { + if (redraw) + DrawInfoBar(); + + whichmap=omapnum; + LoadMap(whichmap); + xbase=oxb; + ybase=oyb; + return; + } + + whichmap=mapnum; + LoadMap(whichmap); + strcpy(EMNstring,MapHeader.name); + MouseHide(); + DrawDialog(&EMNd,1); + MouseShow(); + + case 2: + MouseHide(); + GetButtonXY(&EMNd,1,&sx,&sy); + print(EMNb[1].text); + GetButtonXY(&EMNd,1,&sx,&sy); + if (input(temp,15)) + { + writeH=1; + strcpy(MapHeader.name,temp); + strcpy(MapNames[mapnum],temp); + DirtyFlag=1; + Item_SaveMap(); + } + else + { + GetButtonXY(&EMNd,1,&sx,&sy); + print(EMNb[1].text); + } + MouseShow(); + break; + + case 3: + which=0; + } + } while(which); + + RestoreBackground(); + if (redraw) + DrawInfoBar(); + + whichmap=omapnum; + LoadMap(whichmap); + xbase=oxb; + ybase=oyb; +} + +//////////////////////////////////////////////////// +// +// Item - Paste Mode +// +//////////////////////////////////////////////////// +void Item_Paste(void) +{ + if (!TileCopy.w) + return; + + ZeroModes(); + PasteMode=1; + DrawInfoBar(); + px=(pixelx>>(tsize+2))+xbase; + py=((pixely-8)>>(tsize+2))+ybase; +} + +//////////////////////////////////////////////////// +// +// Item - Copy Mode +// +//////////////////////////////////////////////////// +void Item_Copy(void) +{ + ZeroModes(); + SelectMode=1; + SelX1=SelY1=SelX2=SelY2=-1; + DrawInfoBar(); +} + +//////////////////////////////////////////////////// +// +// Item - LastVideo +// +//////////////////////////////////////////////////// +void Item_LastVideo(void) +{ + int temp=videomode; + + + videomode=lastvideo; + lastvideo=temp; + if (temp==EGA1) + videomode=EGA2; + else + videomode=EGA1; + + switch(videomode) + { + case CGA: + xmshandle=CgaXMS; + XMSlookup=CgaXMSlookup; + break; + case EGA1: + case EGA2: + xmshandle=EgaXMS; + XMSlookup=EgaXMSlookup; + break; + case VGA: + xmshandle=VgaXMS; + XMSlookup=VgaXMSlookup; + } + + MouseHide(); + setvideo(videomode); + InitDesktop(TED5MenuBar,0); + DrawInfoBar(); + FigureScreenEdges(); + + if (xbase+screenw>mapwidth) + xbase=mapwidth-screenw; + if (mapwidthmapheight) + ybase=mapheight-screenh; + if (mapheight1) + { + ErrDialog("I will only allow Flood Filling\n" + "one plane at a time; you have\n" + "more than one plane selected."," OK "); + return; + } + + for (i=0;iwidth || oby[0]>height) + { + FillMode=0; + DrawInfoBar(); + return; + } + + Ton=planeton; + Mon=planemon; + Ion=planeion; + + orgt=*(MapBkgnd+ptr); + orgm=*(MapFrgnd+ptr); + orgi=*(MapInfoPl+ptr); + + if (((Ton?whicht==orgt:0) || + (Mon?whichtm-tilenum==orgm:0) || + (Ion?whichi-tilenum==orgi:0)) && !ctrl) + { + FillMode=0; + DrawInfoBar(); + return; + } + + MouseHide(); + CopyUndoRegion(); + UndoRegion.x=UndoRegion.y=0; + UndoRegion.w=mapwidth; + UndoRegion.h=mapheight; + + if (ctrl) + { + unsigned from=(TileCopy.y+(y%TileCopy.h))*mapwidth+ + TileCopy.x+(x%TileCopy.w); + + switch(TileCopy.MapOrTileSelect) + { + case 0: // COPY BUFFER + Ton=TileCopy.PlanesCopied&BPLANE; + Mon=TileCopy.PlanesCopied&FPLANE; + Ion=TileCopy.PlanesCopied&IPLANE; + + newt=CutBkgnd[from]; + newm=CutFrgnd[from]; + newi=CutInfoPl[from]; + + break; + case 1: // TILES + Ton=1; + Mon=Ion=0; + + newt=((y%TileCopy.h)+TileCopy.y)*selectcols+ + TileCopy.x+(x%TileCopy.w); + if (XMSlookup[newt]<0) + Ton=0; + break; + case 2: // MASKED + Ton=Ion=0; + Mon=1; + + newm=((y%TileCopy.h)+TileCopy.y)*selectcols+ + TileCopy.x+(x%TileCopy.w)+tilenum+maxiconrows*selectcols; + if (XMSlookup[newm]<0) + Mon=0; + else + newm-=tilenum; + } + } + else + { + newt=whicht; + newm=whichtm-tilenum; + newi=whichi-tilenum; + } + + if (Ton) + *(MapBkgnd+newoff)=newt; + if (Mon) + *(MapFrgnd+newoff)=newm; + if (Ion) + *(MapInfoPl+newoff)=newi; + + do + { + for (i=0;i<=highest;i++) + // + // SEE IF SPORE EXISTS + // + if (obx[i]!=-1) + { + // + // DRAW TILE AT SPORE IF IT'S ONSCREEN + // + if (oby[i]>=ybase && oby[i]=xbase && obx[i]width || oby[k]<0 || oby[k]>height) + { + obx[k]=-1; + break; + } + + used++; + if (Ton) + *(MapBkgnd+newoff)=whicht; + if (Mon) + *(MapFrgnd+newoff)=whichtm-tilenum; + if (Ion) + *(MapInfoPl+newoff)=whichi-tilenum; + DirtyFlag=1; + if (k>highest) + highest=k; + break; + } + } + + if (keydown[1]) // ESC OUT + { + while(keydown[1]); + goto done; + } + } + else + for (j=0;j<4;j++) + { + unsigned from; + + ny=y+vecty[j]; + nx=x+vectx[j]; + + newoff=ny*mapwidth+nx; + + if ((Ton?*(MapBkgnd+newoff)==orgt:1) && + (Mon?*(MapFrgnd+newoff)==orgm:1) && + (Ion?*(MapInfoPl+newoff)==orgi:1)) + { + for (k=0;kwidth || oby[k]<0 || oby[k]>height) + { + obx[k]=-1; + break; + } + + from=(TileCopy.y+(ny%TileCopy.h))*mapwidth+ + TileCopy.x+(nx%TileCopy.w); + + switch(TileCopy.MapOrTileSelect) + { + case 0: // COPY BUFFER + Ton=TileCopy.PlanesCopied&BPLANE; + Mon=TileCopy.PlanesCopied&FPLANE; + Ion=TileCopy.PlanesCopied&IPLANE; + + newt=CutBkgnd[from]; + newm=CutFrgnd[from]; + newi=CutInfoPl[from]; + + break; + case 1: // TILES + Ton=1; + Mon=Ion=0; + + newt=((ny%TileCopy.h)+TileCopy.y)*selectcols+ + TileCopy.x+(nx%TileCopy.w); + if (XMSlookup[newt]<0) + Ton=0; + break; + case 2: // MASKED + Ton=Ion=0; + Mon=1; + + newm=((ny%TileCopy.h)+TileCopy.y)*selectcols+ + TileCopy.x+(nx%TileCopy.w)+tilenum+maxiconrows*selectcols; + if (XMSlookup[newm]<0) + Mon=0; + else + newm-=tilenum; + } + + if (Ton) + *(MapBkgnd+newoff)=newt; + if (Mon) + *(MapFrgnd+newoff)=newm; + if (Ion) + *(MapInfoPl+newoff)=newi; + used++; + + DirtyFlag=1; + if (k>highest) + highest=k; + break; + } + } + + if (keydown[1]) // ESC OUT + { + while(keydown[1]); + goto done; + } + } + } + } while(used); + +done: + DrawMap(); + MouseShow(); + FillMode=0; + DrawInfoBar(); +} + + + +//////////////////////////////////////////////////// +// +// If map has been changed, ask user if they want +// to SAVE it before continuing. +// +//////////////////////////////////////////////////// +btype oktosaveB[]={{" Yes ",10,2,2},{" No ",20,2,1}}; +DialogDef oktosaveD={"The map has been modified!\n" + "Save it?",26,4,2,&oktosaveB[0],NULL}; + +int CheckForMapSave(void) +{ + if (DirtyFlag) + { + int which=DoDialog(&oktosaveD); + if (!which) + return 0; + if (which==1) + Item_SaveMap(); + } + return 1; +} + + +//////////////////////////////////////////////////// +// +// Zero all special mode flags +// +//////////////////////////////////////////////////// +void ZeroModes(void) +{ + SelX1=SelX2=SelY1=SelY2=-1; + if (BfillMode || SelectMode || PasteMode || FillMode) + { + DrawMap(); + DrawInfoBar(); + } + + BfillMode=SelectMode=PasteMode=FillMode=0; +} + + +//////////////////////////////////////////////////// +// +// Item - Count Map Tiles +// +//////////////////////////////////////////////////// +btype CMTb[]={ + {" Exit ",9,20,2}, + {" TILE ",1,20,1}, + {" MASKED ",17,20,1}, + {" Rebuild ",27,20,1} + }; +DialogDef CMTd={" Count Unused Map Tiles",38,22,4,&CMTb[0],0}; +unsigned char _seg *tarray,_seg *tmarray,thesparse; + + +void Item_CountTiles(void) +{ + enum {TILE,TILEM}; + + unsigned i,j,dx,dy,max,exit=0,numt,numtm,oxbase,oybase,nsize,nmsize,redraw; + int which,dumrow,dumcol; + char pb,pf,pi; + + + CheckForMapSave(); + + oxbase=xbase; + oybase=ybase; + + // + // COMPUTE SIZE OF EACH TILE + // + switch(videomode) + { + case CGA: nsize=16; nmsize=32; break; + case EGA1: + case EGA2: nsize=32; nmsize=40; break; + case VGA: nsize=64; nmsize=128; + } + nsize=nsize<<((tsize-1)<<1); + nmsize=nmsize<<((tsize-1)<<1); + + + MouseHide(); + DrawDialog(&CMTd,1); + GetDialogXY(&CMTd,&dx,&dy); + sx=dx+4; + sy=dy+2; + print("Counting tiles in map:"); + MouseShow(); + + MMAllocate((memptr *)&tarray,tilenum); + MMAllocate((memptr *)&tmarray,tilemnum); + _fmemset(tarray,0,tilenum); + _fmemset(tmarray,0,tilemnum); + + // + // Now, load each map in & count the tiles + // + pb=MapFileHeader->maptype&BPLANE; + pf=MapFileHeader->maptype&FPLANE; + pi=MapFileHeader->maptype&IPLANE; + + for (i=0;i<100;i++) + if (MapFileHeader->dataoffsets[i]>=0) + { + sx=dx+26; + sy=dy+2; + printint(i); + + LoadMap(i); + max=mapwidth*mapheight; + for (j=0;j=0 && !tarray[i]) + numt++; + + numtm=0; + for (i=0;i=0 && !tmarray[i]) + numtm++; + + + // + // INPUT FROM DIALOG + // + do + { + MouseHide(); + xormask=0; + sx=dx+2; + sy=dy+17; + print("Unused TILES:"); + printint(numt); + print(", unused MASKED:"); + printint(numtm); + print(" "); + sx=dx+2; + sy=dy+18; + print("TILE Memory:"); + printint((1023l+(long)numt*nsize)/1024); + print("K, MASKED Memory:"); + printint((1023l+(long)numtm*nmsize)/1024); + print("K "); + MouseShow(); + DrawUnused(0); + redraw=0; + + do + { + if (!MouseButton()) + which=CheckButtonsRet(&CMTd); + MouseCoords(&pixelx,&pixely); + pixelx/=8; + pixely/=8; + if (MouseButton() && pixelx>dx && pixelxdy && pixely>(tsize-1))+((pixely-dy-1)>>(tsize-1))*(9<<(3-tsize)); + + switch(whichscreen) + { + case TILES: + if (!tarray[tile+tilebase] && XMSlookup[tile+tilebase]>=0) + { + tarray[tile+tilebase]=1; + numt--; + redraw=1; + } + break; + case MASKED: + if (!tmarray[tile+tilembase] && XMSlookup[tilenum+tile+tilembase]>=0) + { + tmarray[tile+tilembase]=1; + numtm--; + redraw=1; + } + } + continue; + } + + switch(which) + { + case 0: + case 1: + exit=1; + continue; + + case 2: + MouseHide(); + GetButtonXY(&CMTd,which-1,&sx,&sy); + print(CMTb[which-1].text); + whichscreen=TILES; + DrawUnused(0); + MouseShow(); + continue; + + case 3: + MouseHide(); + GetButtonXY(&CMTd,which-1,&sx,&sy); + print(CMTb[which-1].text); + whichscreen=MASKED; + DrawUnused(0); + MouseShow(); + continue; + + // + // REBUILD GRAPHICS FILE & HEADER + // + case 4: + { + char newgfx[13]="NEW?GA.", + newhead[13]="NEW?HEAD.", + newhobj[13]="NEW?HEAD.", + oldhead[13]="?GAHEAD."; + + char _seg *gfxhead; + + + newgfx[3]=format[0]; + newhead[3]=format[0]; + newhobj[3]=format[0]; + oldhead[0]=format[0]; + + + LoadIn(oldhead,(memptr *)&gfxhead); + for (i=0;itilenum) + { + tilebase=0; + numrows=tilenum/numcols; + } + + if (whichscreen==MASKED && tilembase+numrows*numcols>tilemnum) + { + tilembase=0; + numrows=tilemnum/numcols; + } + + switch((deltarow<0?-1:deltarow>0?1:0)) + { + case -1: + switch(whichscreen) + { + case TILES: + tilebase+=deltarow*numcols; + if (tilebase<0) + tilebase=0; + break; + case MASKED: + tilembase+=deltarow*numcols; + if (tilembase<0) + tilembase=0; + } + break; + case 1: + switch(whichscreen) + { + case TILES: + tilebase+=deltarow*numcols; + if (tilebase+numrows*numcols>tilenum) + tilebase=tilenum-numcols*numrows; + break; + case MASKED: + tilembase+=deltarow*numcols; + if (tilembase+numrows*numcols>tilemnum) + tilembase=tilemnum-numcols*numrows; + } + } + + switch(whichscreen) + { + case TILES: + for(j=0;j=0) + CombineTiles(tilebase+j*numcols+i,0,0,tsize); + else + CombineTiles(thesparse,0,0,tsize); + DrawTile(i*2+left,j*16+top,tsize); + } + break; + + case MASKED: + for(j=0;j=0) + CombineTiles(-BkgndColor,tilenum+tilembase+j*numcols+i,0,tsize); + else + CombineTiles(thesparse,0,0,tsize); + DrawTile(i*2+left,j*16+top,tsize); + } + } + MouseShow(); +}