//////////////////////////////////////////////////// //////////////////////////////////////////////////// // // TED5-3 // //////////////////////////////////////////////////// //////////////////////////////////////////////////// #include "ted5.h" #pragma hdrstop int xms1; extern int tics; //////////////////////////////////////////////////// // // MAP SCROLLING // //////////////////////////////////////////////////// void CheckMapScroll(void) { // // LEFT // if (keydown[0x4b]) // left arrow { int i,j,imax,jmax,tilesmoved; tics=biostime(0,0); if (xbase) { EraseFloatPaste(); if (keydown[0x1d]) // CTRL-KEY { tilesmoved=screenw; if (keydown[0x38]) // ALT-KEY { xbase=0; DrawMap(); return; } } else switch(videomode) { case CGA: case EGA1: case VGA: tilesmoved=1; break; case EGA2: tilesmoved=2; } if (xbasemapheight) jmax=mapheight; for (i=0;i=mapwidth) tilesmoved=mapwidth-screenw-xbase; xbase+=tilesmoved; MouseHide(); if (tilesmovedmapheight) jmax=mapheight; for (i=0;imapwidth) imax=mapwidth; for (j=0;j=mapheight) tilesmoved=mapheight-screenh-ybase; ybase+=tilesmoved; MouseHide(); if (tilesmovedmapwidth) imax=mapwidth; for (j=0;jSelX1 && xSelX1 && xSelY1 && ySelY1 && y=8 || pixely=xbase+screenw) mx-=snapxsize; if (my>=ybase+screenh) my-=snapysize; } if (!PasteMode || (px==mx && py==my) || (pixely<8 || pixely>infoy*8)) return; if (mx>mapwidth || my>mapheight) return; MouseHide(); EraseFloatPaste(); // // FLOAT IT... // px=mx; py=my; DrawFloatPaste(); MouseShow(); } //////////////////////////////////////////////////// // // DRAW FLOATING PASTE REGION // void DrawFloatPaste(void) { int i,j,maxw,maxh; if (px==-1 || py==-1 || !PasteMode) return; // // NOW, DRAW IT IN A NEW LOCATION! // MouseHide(); maxh=TileCopy.h; if (py+maxh>mapheight) maxh=mapheight-py; if (py+maxh-ybase>screenh) maxh=screenh-(py-ybase); maxw=TileCopy.w; if (px+maxw>mapwidth) maxw=mapwidth-px; if (px+maxw-xbase>screenw) maxw=screenw-(px-xbase); switch(TileCopy.MapOrTileSelect) { case 0: // MAP PASTE DRAW for (j=0;jmapheight) maxh=mapheight-py; if (py+maxh-ybase>screenh) maxh=screenh-(py-ybase); maxw=TileCopy.w; if (px+maxw>mapwidth) maxw=mapwidth-px; if (px+maxw-xbase>screenw) maxw=screenw-(px-xbase); for (j=0;j0)+ ((TileCopy.PlanesCopied&FPLANE)>0)+((TileCopy.PlanesCopied&IPLANE)>0)); xms1=XMSAllocate(size); off=0; if (TileCopy.PlanesCopied&BPLANE) for (j=0;jmapwidth)?mapwidth:TileCopy.w; newheight=(TileCopy.h>mapheight)?mapheight:TileCopy.h; ToOff=off=0; if (TileCopy.PlanesCopied&BPLANE) for (j=0;j>8); sx-=2; sy++; printhexb(temp&0xff); break; case 3: printhex(temp); } } else if (viewion && tilei>lasticon) { switch(tsize) { case 1: print("#"); break; case 2: printhexb(tilei-tilenum>>8); sx-=2; sy++; printhexb(tilei-tilenum&0xff); break; case 3: printhex(tilei-tilenum); } } } //////////////////////////////////////////////////// // // Item - Edit Map Edges // //////////////////////////////////////////////////// btype MapEdgeB[]={{"\xb",7,3,1}, {"\xc",7,7,1}, {"\xe",4,5,1}, {"\x1f",10,5,1}, {" Exit ",5,16,2}}; DialogDef MapEdgeD={" PICK MAP EDGE\n" " TO CHANGE", 16,18,5,&MapEdgeB[0],NULL}; void Item_EditMapEdges(void) { int which,val,newwidth,newheight,b,f,i, _seg *tempB,_seg *tempF,_seg *tempI; unsigned dx,dy,obx,oby,k,j,modified=0; long size; b=MapFileHeader->maptype&BPLANE; f=MapFileHeader->maptype&FPLANE; i=MapFileHeader->maptype&IPLANE; DrawDialog(&MapEdgeD,1); GetDialogXY(&MapEdgeD,&dx,&dy); do { MouseHide(); sx=dx+2; sy=dy+14; print("W:"); printint(MapHeader.width); print(", H:"); printint(MapHeader.height); print(" "); MouseShow(); which=CheckButtons(&MapEdgeD); GetButtonXY(&MapEdgeD,which-1,&obx,&oby); MouseHide(); if (which>=1 && which<=4) { // DRAW INPUT BAR sx=dx; sy=dy+9; print("+ or - value"); DrawBorder(dx,dy+10,15,2,1); // INPUT VALUE sx=dx+1; sy=dy+11; val=inputint(9); // ERASE THE ARROW AND INPUT BAR sx=obx; sy=oby; print(MapEdgeB[which-1].text); bar(dx,dy+9,dx+15,dy+12,' '); // CHECK FOR ESC if (val==(int)ESCOUT) which=6; } MouseShow(); switch(which) { // // ADD OR DELETE FROM TOP // case 1: newheight=mapheight+val; size=2L*newheight*mapwidth; if (size<=0 || size>0x10000L) { RestoreBackground(); ErrDialog("Invalid Map height!"," OK "); return; } // FREE UP SOME MEMORY! SaveCutBuffers(); RemoveUndoBuffers(); if (b) { MMFreePtr((memptr *)&CutBkgnd); MMAllocate((memptr *)&tempB,size); } if (f) { MMFreePtr((memptr *)&CutFrgnd); MMAllocate((memptr *)&tempF,size); } if (i) { MMFreePtr((memptr *)&CutInfoPl); MMAllocate((memptr *)&tempI,size); } if (val<0) { // COPY MAP PLANES INTO TEMP MEMORY (CLIPPED, HERE) for (j=abs(val);j0x10000L) { RestoreBackground(); ErrDialog("Invalid Map height!"," OK "); return; } // FREE UP SOME MEMORY! SaveCutBuffers(); RemoveUndoBuffers(); if (b) { MMFreePtr((memptr *)&CutBkgnd); MMAllocate((memptr *)&tempB,size); } if (f) { MMFreePtr((memptr *)&CutFrgnd); MMAllocate((memptr *)&tempF,size); } if (i) { MMFreePtr((memptr *)&CutInfoPl); MMAllocate((memptr *)&tempI,size); } if (val<0) { // COPY MAP PLANES INTO TEMP MEMORY (CLIPPED, HERE) for (j=0;j=mapheight) { if (b) tempB[j*mapwidth+k]=whicht; if (f) tempF[j*mapwidth+k]=whichtm-tilenum; if (i) tempI[j*mapwidth+k]=whichi-tilenum; } else { if (b) tempB[j*mapwidth+k]=MapBkgnd[j*mapwidth+k]; if (f) tempF[j*mapwidth+k]=MapFrgnd[j*mapwidth+k]; if (i) tempI[j*mapwidth+k]=MapInfoPl[j*mapwidth+k]; } } } // DEALLOCATE & REALLOCATE THE MAP BUFFERS, RESIZED if (b) { MMFreePtr((memptr *)&MapBkgnd); MMAllocate((memptr *)&MapBkgnd,size); } if (f) { MMFreePtr((memptr *)&MapFrgnd); MMAllocate((memptr *)&MapFrgnd,size); } if (i) { MMFreePtr((memptr *)&MapInfoPl); MMAllocate((memptr *)&MapInfoPl,size); } // COPY THE REGION BACK IN... for (j=0;j0x10000L) { RestoreBackground(); ErrDialog("Invalid Map width!"," OK "); return; } // FREE UP SOME MEMORY! SaveCutBuffers(); RemoveUndoBuffers(); if (b) { MMFreePtr((memptr *)&CutBkgnd); MMAllocate((memptr *)&tempB,size); } if (f) { MMFreePtr((memptr *)&CutFrgnd); MMAllocate((memptr *)&tempF,size); } if (i) { MMFreePtr((memptr *)&CutInfoPl); MMAllocate((memptr *)&tempI,size); } if (val<0) { // COPY MAP PLANES INTO TEMP MEMORY (CLIPPED, HERE) for (j=0;j0x10000L) { RestoreBackground(); ErrDialog("Invalid Map width!"," OK "); return; } // FREE UP SOME MEMORY! SaveCutBuffers(); RemoveUndoBuffers(); if (b) { MMFreePtr((memptr *)&CutBkgnd); MMAllocate((memptr *)&tempB,size); } if (f) { MMFreePtr((memptr *)&CutFrgnd); MMAllocate((memptr *)&tempF,size); } if (i) { MMFreePtr((memptr *)&CutInfoPl); MMAllocate((memptr *)&tempI,size); } if (val<0) { // COPY MAP PLANES INTO TEMP MEMORY (CLIPPED, HERE) for (j=0;j=mapwidth) { if (b) tempB[j*newwidth+k]=whicht; if (f) tempF[j*newwidth+k]=whichtm-tilenum; if (i) tempI[j*newwidth+k]=whichi-tilenum; } else { if (b) tempB[j*newwidth+k]=MapBkgnd[j*mapwidth+k]; if (f) tempF[j*newwidth+k]=MapFrgnd[j*mapwidth+k]; if (i) tempI[j*newwidth+k]=MapInfoPl[j*mapwidth+k]; } } } // DEALLOCATE & REALLOCATE THE MAP BUFFERS, RESIZED if (b) { MMFreePtr((memptr *)&MapBkgnd); MMAllocate((memptr *)&MapBkgnd,size); } if (f) { MMFreePtr((memptr *)&MapFrgnd); MMAllocate((memptr *)&MapFrgnd,size); } if (i) { MMFreePtr((memptr *)&MapInfoPl); MMAllocate((memptr *)&MapInfoPl,size); } // COPY THE REGION BACK IN... for (j=0;jdataoffsets[i]!=-1) { // // LOAD MAP HEADER // sx=dx; printint(i); LoadFile(mapname,(char huge *)&TempHeader,MapFileHeader->dataoffsets[i],sizeof(MapHeaderStr)); // // COMPRESS EACH MAP PLANE // #pragma warn -sus if (MapFileHeader->maptype&BPLANE) { size=TempHeader.mapbkgndlen; MMAllocate(&block,size); MMAllocate(&block2,size); LoadFile(mapname,block,TempHeader.mapbkgndpl,size); *(int _seg *)block2=TempHeader.mapbkgndlen; nsize=CarmackCompress((unsigned char huge *)block,size,(unsigned char huge *)block2+2)+2; maplengths[i]+=nsize; if (nsize==2) { RestoreBackground(); MMFreePtr(&block2); MMFreePtr(&block); MMFreePtr(&block1); LoadMap(whichmap); xbase=oxb; ybase=oyb; ErrDialog("ESC out of this infernal thing!"," YES! "); return; } SaveFile(huffname,block2,fsize,nsize); TempHeader.mapbkgndpl=fsize; TempHeader.mapbkgndlen=nsize; MMFreePtr(&block2); MMFreePtr(&block); fsize+=nsize; } if (MapFileHeader->maptype&FPLANE) { size=TempHeader.mapfrgndlen; MMAllocate(&block,size); MMAllocate(&block2,size); LoadFile(mapname,block,TempHeader.mapfrgndpl,size); *(int _seg *)block2=TempHeader.mapfrgndlen; nsize=CarmackCompress((unsigned char huge *)block,size,(unsigned char huge *)block2+2)+2; maplengths[i]+=nsize; if (nsize==2) { RestoreBackground(); MMFreePtr(&block2); MMFreePtr(&block); MMFreePtr(&block1); LoadMap(whichmap); xbase=oxb; ybase=oyb; ErrDialog("ESC out of this infernal thing!"," YES! "); return; } SaveFile(huffname,block2,fsize,nsize); TempHeader.mapfrgndpl=fsize; TempHeader.mapfrgndlen=nsize; MMFreePtr(&block2); MMFreePtr(&block); fsize+=nsize; } if (MapFileHeader->maptype&IPLANE) { size=TempHeader.mapinfolen; MMAllocate(&block,size); MMAllocate(&block2,size); LoadFile(mapname,block,TempHeader.mapinfopl,size); *(int _seg *)block2=TempHeader.mapinfolen; nsize=CarmackCompress((unsigned char huge *)block,size,(unsigned char huge *)block2+2)+2; maplengths[i]+=nsize; if (nsize==2) { RestoreBackground(); MMFreePtr(&block2); MMFreePtr(&block); MMFreePtr(&block1); LoadMap(whichmap); xbase=oxb; ybase=oyb; ErrDialog("ESC out of this infernal thing!"," YES! "); return; } SaveFile(huffname,block2,fsize,nsize); TempHeader.mapinfopl=fsize; TempHeader.mapinfolen=nsize; MMFreePtr(&block2); MMFreePtr(&block); fsize+=nsize; } #pragma warn +sus // // SAVE MAP HEADER // nsize=sizeof(TempHeader); maplengths[i]+=nsize; SaveFile(huffname,(char huge *)&TempHeader,fsize,nsize); NewFileHeader.dataoffsets[i]=fsize; fsize+=nsize; SaveFile(huffname,"!ID!",fsize,4); fsize+=4; } MMFreePtr(&block1); // // COPY PERTINENT MAPFILEHEADER DATA TO NEWFILEHEADER // { char outname[14],tempname[14]="MTEMP.TMP",doutname[14]; strcpy(outname,ext); strcat(outname,"MHEAD.OBJ"); NewFileHeader.RLEWtag=MapFileHeader->RLEWtag; fsize=sizeof(OutputHeadStr); SaveFile(tempname,(char huge *)&NewFileHeader,0,fsize); for (i=0;idataoffsets[i]!=-1) { char tstr[16]; strcpy(tstr,MapNames[i]); while(strlen(tstr)<16) strcat(tstr," "); fprintf(stdprn,"%d\t%s\t%d\n",i,tstr,maplengths[i]); } fprintf(stdprn,"%c",12); } LoadMap(whichmap); xbase=oxb; ybase=oyb; } //////////////////////////////////////////////////// // // Item - Change the LAUNCH name // //////////////////////////////////////////////////// btype CLNb={" ",1,5,1}; DialogDef CLNd={"Current LAUNCH name:\n\n\nNew LAUNCH name:",38,7,1,&CLNb,NULL}; void Item_LAUNCHname(void) { char tempstr[40]; MouseHide(); DrawDialog(&CLNd,1); GetDialogXY(&CLNd,&sx,&sy); sy++; sx++; print(launchname); GetButtonXY(&CLNd,0,&sx,&sy); if (input(tempstr,36)) { strcpy(launchname,tempstr); SaveTEDInfo(); } MouseShow(); RestoreBackground(); } //////////////////////////////////////////////////// // // Item - Change the PARM string // //////////////////////////////////////////////////// btype CPSb={" ",1,5,1}; DialogDef CPSd={"Current PARM string:\n\n\nNew PARM string:",38,7,1,&CPSb,NULL}; void Item_PARMstring(void) { char tempstr[40]; MouseHide(); DrawDialog(&CPSd,1); GetDialogXY(&CPSd,&sx,&sy); sy++; sx++; print(parmstring); GetButtonXY(&CPSd,0,&sx,&sy); if (input(tempstr,36)) { strcpy(parmstring,tempstr); _fstrcpy(TEDInfo->parmstring,(char far *)parmstring); SaveTEDInfo(); } MouseShow(); RestoreBackground(); } //////////////////////////////////////////////////// // // Item - Change Icon Rows // //////////////////////////////////////////////////// btype CIRb={" ",8,4,1}; DialogDef CIRd={"Enter amount of icons\n" "to add/delete.\n" "Use + or -.",22,6,1,&CIRb,NULL}; void Item_ChangeIconRows(void) { unsigned i,j,dx,dy,max,oxbase,oybase,base; int value,owm; memptr block; if (!(MapFileHeader->maptype&IPLANE)) { ErrDialog("You don't have an icon plane!"," OK "); return; } CheckForMapSave(); oxbase=xbase; oybase=ybase; DrawDialog(&CIRd,1); GetButtonXY(&CIRd,0,&dx,&dy); sx=dx; sy=dy; MouseHide(); value=inputint(3); MouseShow(); if (!value || value==(int)ESCOUT) { RestoreBackground(); return; } value=SGN(value)*(18*((abs(value)+17)/18)); base=18*maxiconrows; maxiconrows+=value/18; MapFileHeader->NumIconRows+=value/18; owm=whichmap; RestoreBackground(); // // MAKE SURE WE ADJUST TILEINFOM! // MMAllocate(&block,tilemnum+value); for (i=0;ioldtilemnum=tilemnum+value; // // RUN THROUGH EACH MAP AND ADJUST TILEM VALUES // for (i=0;i<100;i++) if (MapFileHeader->dataoffsets[i]>=0) { whichmap=i; LoadMap(i); max=mapwidth*mapheight; for (j=0;j0) MapFrgnd[j]+=value; DirtyFlag=1; SaveMap(0); } DirtyFlag=0; whichmap=owm; LoadMap(whichmap); xbase=oxbase; ybase=oybase; DrawMap(); ErrDialog("If your map looks messed up,\n" "you need to change the amount\n" "of icons in your IGRAB script\n" "and re-grab your tiles!"," OK "); } //////////////////////////////////////////////////// // // Item - Change LAUNCH Icon // //////////////////////////////////////////////////// void Item_ChangeLaunchIcon(void) { sound(1700); TEDInfo->permicon=whichi-tilenum; delay(30); nosound(); } //////////////////////////////////////////////////// // // Item - Change Background color // //////////////////////////////////////////////////// btype CBCb[]={{"\xb",5,2,1}, {"\xc",16,2,1}, {"Exit",9,2,2}}; DialogDef CBCd={"Change Backgrnd Color!",22,4,3,&CBCb[0],0}; void Item_ChangeBkgndColor(void) { int which; do { which=DoDialog(&CBCd); switch(which) { case 1: sound(1700); if (--BkgndColor<0) BkgndColor=15; TEDInfo->BackgndColor=BkgndColor; DrawMap(); DrawInfoBar(); break; case 2: sound(1700); if (++BkgndColor>15) BkgndColor=0; TEDInfo->BackgndColor=BkgndColor; DrawMap(); DrawInfoBar(); } nosound(); } while(which>0 && which<3); }