1 ////////////////////////////////////////////////////
2 ////////////////////////////////////////////////////
6 ////////////////////////////////////////////////////
7 ////////////////////////////////////////////////////
11 void InputMap(char *lvlname,unsigned *levelw,unsigned *levelh,int exitok);
12 void MNameOn(int x,int y,int i);
13 void MNameOff(int x,int y,int i);
14 void DnarOn(int x,int y);
15 void DnarOff(int x,int y);
16 void UparOn(int x,int y);
17 void UparOff(int x,int y);
18 void ExitOn(int x,int y);
19 void ExitOff(int x,int y);
20 void TInfoNon(int x,int y,int b);
21 void TInfoNoff(int x,int y,int b);
22 void TInfoMNon(int x,int y,int b);
23 void TInfoMNoff(int x,int y,int b);
24 void TIDoneOn(int x,int y);
25 void TIDoneOff(int x,int y);
28 ////////////////////////////////////////////////////
30 // SAVE the current map
32 ////////////////////////////////////////////////////
33 void SaveMap(int delmap)
36 long fsize,size,nsize,change;
37 MapHeaderStr TempHeader;
39 char string[100],TEDid[]=IDSTRING;
46 LoadFile(mapname,(char huge *)&TempHeader,
47 MapFileHeader->dataoffsets[whichmap],sizeof(MapHeaderStr));
48 strcpy(string,"Deleting Map, '");
49 strcat(string,TempHeader.name);
53 strcpy(string,"Saving Map, '");
54 strcat(string,MapHeader.name);
61 BackupFile(mapheadname);
62 BackupFile(SM_loadname);
65 if (delmap || DirtyFlag)
68 // SAVE MAP FILE HEADER
71 MapFileHeader->dataoffsets[whichmap]=-1;
73 SaveFile(mapheadname,MK_FP(MapFileHeader,0),0,sizeof(MapFileHeaderStr));
74 fsize=sizeof(MapFileHeaderStr);
77 // COMPRESS & SAVE TILEINFOS
79 MMAllocate(&block,tilenum);
80 for (i=0;i<numtplanes;i++)
82 MapFileHeader->tileinfooff[i]=fsize;
83 nsize=RLEBCompress(MK_FP(Tinfo[i],0),tilenum,MK_FP(block,0),MapFileHeader->RLEWtag);
84 MapFileHeader->tileinfolen[i]=nsize;
85 SaveFile(mapheadname,MK_FP(block,0),fsize,nsize);
90 MMAllocate(&block,tilemnum);
91 for (i=0;i<numtmplanes;i++)
93 MapFileHeader->tileinfomoff[i]=fsize;
94 nsize=RLEBCompress(MK_FP(TMinfo[i],0),tilemnum,MK_FP(block,0),MapFileHeader->RLEWtag);
95 MapFileHeader->tileinfomlen[i]=nsize;
96 SaveFile(mapheadname,MK_FP(block,0),fsize,nsize);
101 MapFileHeader->oldtilenum=tilenum;
102 MapFileHeader->oldtilemnum=tilemnum;
104 SaveFile(mapheadname,MK_FP(MapFileHeader,2),2,sizeof(MapFileHeaderStr)-2);
106 // SAVE ALREADY COMPRESSED MAPS
110 // IF MAPS ARE IN XMS ALREADY, ALLOCATE A NEW BUFFER
111 // TO SHUFFLE ALREADY-COMPRESSED MAPS INTO
116 long len=filelen(SM_loadname);
119 planes=(MapFileHeader->maptype&BPLANE>0)+
120 (MapFileHeader->maptype&FPLANE>0)+
121 (MapFileHeader->maptype&IPLANE>0);
122 len+=2L*mapwidth*mapheight*planes;
124 if (1024L*XMSTotalFree()<len)
130 XMStemp=XMSAllocate(len);
134 // NOTE: I AM STORING "TED5" AT THE START OF THE FILE BECAUSE
135 // SAVING THE FILE AT OFFSET 0 WILL TRASH IT (I HAVE TO RE-SAVE THE HEADER!)
138 XMSmove(0,(long)&TEDid,XMStemp,0,strlen(TEDid));
140 SaveFile(SM_name,(char huge *)TEDid,0,strlen(TEDid));
147 if (MapFileHeader->dataoffsets[i]==-1 || i==whichmap)
150 oldoff=MapFileHeader->dataoffsets[i];
153 XMSmove(XMSmaps,oldoff,0,(long)&TempHeader,sizeof(MapHeaderStr));
155 LoadFile(SM_loadname,(char huge *)&TempHeader,oldoff,sizeof(MapHeaderStr));
157 strcpy(TempHeader.name,MapNames[i]);
158 MapFileHeader->dataoffsets[i]=fsize;
159 size=TempHeader.mapbkgndlen+TempHeader.mapfrgndlen+TempHeader.mapinfolen;
160 change=TempHeader.mapbkgndpl-fsize-sizeof(MapHeaderStr);
161 TempHeader.mapbkgndpl-=change;
162 TempHeader.mapfrgndpl-=change;
163 TempHeader.mapinfopl-=change;
166 XMSmove(0,(long)&TempHeader,XMStemp,fsize,sizeof(MapHeaderStr));
168 SaveFile(SM_name,(char huge *)&TempHeader,fsize,sizeof(MapHeaderStr));
169 fsize+=sizeof(MapHeaderStr);
173 XMSmove(XMSmaps,oldoff+sizeof(MapHeaderStr),XMStemp,fsize,size);
175 XMSmove(0,(long)"!ID!",XMStemp,fsize,4);
180 MMAllocate(&block,size);
181 LoadFile(SM_loadname,MK_FP(block,0),oldoff+sizeof(MapHeaderStr),size);
182 SaveFile(SM_name,MK_FP(block,0),fsize,size);
184 SaveFile(SM_name,"!ID!",fsize,4);
191 // SAVE CURRENT MAP AT END OF FILE
195 MapFileHeader->dataoffsets[whichmap]=fsize;
196 MapFileHeader->datalengths[whichmap]=sizeof(MapHeaderStr);
198 XMSmove(0,(long)&MapHeader,XMStemp,fsize,sizeof(MapHeaderStr));
200 SaveFile(SM_name,(char huge *)&MapHeader,fsize,sizeof(MapHeaderStr));
201 fsize+=sizeof(MapHeaderStr);
203 size=MapHeader.width*MapHeader.height*sizeof(int);
204 MMAllocate(&block,size);
205 if (MapFileHeader->maptype & BPLANE)
207 MapHeader.mapbkgndpl=fsize;
208 nsize=RLEWCompress(MK_FP(MapBkgnd,0),size,MK_FP(block,0),MapFileHeader->RLEWtag);
210 MapHeader.mapbkgndlen=nsize+2;
213 XMSmove(0,(long)&size,XMStemp,fsize,2);
215 SaveFile(SM_name,(char huge *)&size,fsize,2);
220 XMSmove(0,(long)MK_FP(block,0),XMStemp,fsize,nsize);
222 SaveFile(SM_name,MK_FP(block,0),fsize,nsize);
227 MapHeader.mapbkgndlen=0;
229 if (MapFileHeader->maptype & FPLANE)
231 MapHeader.mapfrgndpl=fsize;
232 nsize=RLEWCompress(MK_FP(MapFrgnd,0),size,MK_FP(block,0),MapFileHeader->RLEWtag);
234 MapHeader.mapfrgndlen=nsize+2;
237 XMSmove(0,(long)&size,XMStemp,fsize,2);
239 SaveFile(SM_name,(char huge *)&size,fsize,2);
244 XMSmove(0,(long)MK_FP(block,0),XMStemp,fsize,nsize);
246 SaveFile(SM_name,MK_FP(block,0),fsize,nsize);
251 MapHeader.mapfrgndlen=0;
253 if (MapFileHeader->maptype & IPLANE)
255 MapHeader.mapinfopl=fsize;
256 nsize=RLEWCompress(MK_FP(MapInfoPl,0),size,MK_FP(block,0),MapFileHeader->RLEWtag);
258 MapHeader.mapinfolen=nsize+2;
261 XMSmove(0,(long)&size,XMStemp,fsize,2);
263 SaveFile(SM_name,(char huge *)&size,fsize,2);
268 XMSmove(0,(long)MK_FP(block,0),XMStemp,fsize,nsize);
270 SaveFile(SM_name,MK_FP(block,0),fsize,nsize);
275 MapHeader.mapinfolen=0;
278 XMSmove(0,(long)"!ID!",XMStemp,fsize,4);
280 SaveFile(SM_name,"!ID!",fsize,4);
288 XMSmove(0,(long)&MapHeader,XMStemp,
289 MapFileHeader->dataoffsets[whichmap],sizeof(MapHeaderStr));
291 SaveFile(SM_name,(char huge *)&MapHeader,
292 MapFileHeader->dataoffsets[whichmap],sizeof(MapHeaderStr));
295 // RE-SAVE FILE HEADER
296 // NOTE: The "2" is so SaveFile doesn't truncate the fucking file!
298 SaveFile(mapheadname,MK_FP(MapFileHeader,2),2,sizeof(MapFileHeaderStr)-2);
303 #define BCSIZE 0x4000
304 long size=fsize,clen,coff;
307 // SAVE ENTIRE MAPFILE IN XMS TO DISK!
312 MMAllocate(&block,BCSIZE);
320 XMSmove(XMSmaps,coff,0,(long)MK_FP(block,0),clen);
321 SaveFile(SM_loadname,MK_FP(block,0),coff,clen);
332 rename(SM_name,SM_loadname);
336 AllocateUndoBuffers();
338 SaveUndo(0,0,mapwidth,mapheight);
347 ////////////////////////////////////////////////////
351 ////////////////////////////////////////////////////
352 void BackupFile(char *filename)
354 #define BUFSIZE 0x8000
361 size = filelen(filename);
365 strcpy(backupname,filename);
366 for (i=strlen(backupname);i;i--)
367 if (backupname[i] == '.')
369 strcat(backupname,"BAK");
371 MMAllocate(&block,BUFSIZE);
379 LoadFile(filename,(char far *)block,coff,clen);
380 SaveFile(backupname,MK_FP(block,0),coff,clen);
390 ////////////////////////////////////////////////////
392 // SAVE OUT TEDINFO FILE
394 ////////////////////////////////////////////////////
395 void SaveTEDInfo(void)
397 BackupFile(infoname);
399 TEDInfo->oscrx=xbase;
400 TEDInfo->oscry=ybase;
401 _fstrcpy(TEDInfo->launchname,(char far *)launchname);
402 SaveFile(infoname,MK_FP(TEDInfo,0),0,sizeof(InfoStruct));
406 ////////////////////////////////////////////////////
408 // WRITE OUT THE OUTPUT HEADER FILE
410 ////////////////////////////////////////////////////
411 char * _nfstrcpy(char *dest,char far *source)
415 for (i=0;i<_fstrlen(source);i++)
416 *(dest+i)=*(source+i);
422 void SaveOutputHeader(void)
424 char outhead[14]="MAPHEAD.",dot_h[14]="MAPS",t[15],tm[15],temp[40],temp1[40];
426 OutputHeadStr OutHead;
431 ErrDialog("Saving header...","");
437 memset(&OutHead,0,sizeof(OutputHeadStr));
439 OutHead.RLEWtag=MapFileHeader->RLEWtag;
442 OutHead.dataoffsets[i]=MapFileHeader->dataoffsets[i];
444 fsize=sizeof(OutputHeadStr);
445 SaveFile(outhead,(char huge *)&OutHead,0,fsize);
446 for (i=0;i<numtplanes;i++)
448 SaveFile(outhead,MK_FP(Tinfo[i],0),fsize,tilenum);
451 for (i=0;i<numtmplanes;i++)
453 SaveFile(outhead,MK_FP(TMinfo[i],0),fsize,tilemnum);
460 // DUMP OUT A MAPSext.H HEADER FILE
464 ErrDialog("Saving .h file...","");
470 if ((fp=fopen(dot_h,"wt"))==NULL)
473 fprintf(fp,"///////////////////////////////////////\n");
475 fprintf(fp,"// TED5 Map Header for %s\n",ext);
477 fprintf(fp,"///////////////////////////////////////\n");
481 if (MapFileHeader->dataoffsets[i]>=0)
490 fprintf(fp,"// Map Names\n");
493 fprintf(fp,"typedef enum {\n");
495 if (MapFileHeader->dataoffsets[i]>=0)
501 strcpy(temp,&MapNames[i][0]);
504 for (j=0;j<strlen(temp);j++)
509 while(strlen(temp)<25)
512 fprintf(fp,"\t\t%s// %d\n",strupr(temp),i);
516 fprintf(fp,"\t\tEMPTYMAP%d,\n",i);
518 fprintf(fp,"\t\tLASTMAP\n\t } mapnames;\n");
523 strcpy(t,"NUMTILE8");
524 strcpy(tm,"NUMTILE8M");
527 strcpy(t,"NUMTILE16");
528 strcpy(tm,"NUMTILE16M");
531 strcpy(t,"NUMTILE32");
532 strcpy(tm,"NUMTILE32M");
540 fprintf(fp,"// TILEINFO offsets\n");
543 memset(temp,0,sizeof(temp));
544 memset(temp1,0,sizeof(temp1));
545 fprintf(fp,"#define %s\x9\x9%d\n",
546 strupr(_nfstrcpy(temp,MapFileHeader->tnames[0])),
547 sizeof(OutputHeadStr));
548 for (i=1;i<numtplanes;i++)
550 memset(temp,0,sizeof(temp));
551 memset(temp1,0,sizeof(temp1));
553 fprintf(fp,"#define %s\x9\x9(%s+%s)\n",
554 strupr(_nfstrcpy(temp,MapFileHeader->tnames[i])),
555 strupr(_nfstrcpy(temp1,MapFileHeader->tnames[i-1])),
564 fprintf(fp,"// TILEINFOM offsets\n");
567 memset(temp,0,sizeof(temp));
568 memset(temp1,0,sizeof(temp1));
569 fprintf(fp,"#define %s\x9\x9(%s+%s)\n",
570 strupr(_nfstrcpy(temp,MapFileHeader->tmnames[0])),
571 strupr(_nfstrcpy(temp1,MapFileHeader->tnames[numtplanes-1])),
573 for (i=1;i<numtmplanes;i++)
575 memset(temp,0,sizeof(temp));
576 memset(temp1,0,sizeof(temp1));
578 fprintf(fp,"#define %s\x9\x9(%s+%s)\n",
579 strupr(_nfstrcpy(temp,MapFileHeader->tmnames[i])),
580 strupr(_nfstrcpy(temp1,MapFileHeader->tmnames[i-1])),
593 ////////////////////////////////////////////////////
595 // Initialize the TILEINFO/M arrays
597 ////////////////////////////////////////////////////
598 btype TIb[]={{" ",1,2,1},
601 DialogDef TId={" How many TILEINFO planes?\n\n\n\n"
602 " How many TILEINFOM planes?",
603 27,11,3,&TIb[0],NULL};
605 void InitTileinfo(void)
607 unsigned temp,which,oktoexit=0,ox,oy,i,j;
610 numtplanes=numtmplanes=0;
612 GetButtonXY(&TId,0,&sx,&sy);
613 printint(numtplanes);
614 if (MapFileHeader->maptype&FPLANE)
616 GetButtonXY(&TId,1,&sx,&sy);
617 printint(numtmplanes);
621 which=CheckButtons(&TId);
626 GetButtonXY(&TId,0,&sx,&sy);
632 if ((temp=inputint(9))!=ESCOUT && temp<11 && temp)
639 printint(numtplanes);
644 GetButtonXY(&TId,1,&sx,&sy);
650 if (MapFileHeader->maptype&FPLANE)
652 if ((temp=inputint(9))!=ESCOUT && temp<11 && temp)
659 printint(numtmplanes);
667 GetButtonXY(&TId,2,&sx,&sy);
679 fsize=sizeof(MapFileHeaderStr);
681 for (i=0;i<numtplanes;i++)
683 MMAllocate((memptr *)&Tinfo[i],tilenum);
684 MapFileHeader->tileinfooff[i]=fsize; // THIS DOESN'T REALLY MATTER
685 fsize+=tilenum; // ....YET!
686 for(j=0;j<tilenum;j++)
690 for (i=0;i<numtmplanes;i++)
692 MMAllocate((memptr *)&TMinfo[i],tilemnum);
693 MapFileHeader->tileinfomoff[i]=fsize;
695 for(j=0;j<tilemnum;j++)
699 MapFileHeader->numtplanes=numtplanes;
700 MapFileHeader->numtmplanes=numtmplanes;
702 MapFileHeader->oldtilenum=tilenum;
703 MapFileHeader->oldtilemnum=tilemnum;
708 ////////////////////////////////////////////////////
710 // Item - Edit the TILEINFO names
712 ////////////////////////////////////////////////////
713 btype TINb={" Done ",8,15,1};
714 DialogDef TINd={" Enter plane names:\n"
715 " TILEINFO TILEINFOM",
718 void Item_EditTinfoNames(void)
720 unsigned ox,oy,i,oktoexit=0;
725 GetDialogXY(&TINd,&sx,&sy);
728 DrawBorder(sx,sy+2,10,11,1);
731 DrawBorder(sx+11,sy+2,10,11,1);
737 fprint(MapFileHeader->tnames[i]);
740 fprint(MapFileHeader->tmnames[i]);
746 if ((which=CheckList(ox+1,oy+3,8,numtplanes,TInfoNon,TInfoNoff,0))>=0)
760 MapFileHeader->tnames[which][i]=temp[i];
763 if (which<numtplanes)
767 TInfoNoff(ox+1,oy+3+which,which);
771 if ((which=CheckList(ox+12,oy+3,8,numtmplanes,TInfoMNon,TInfoMNoff,0))>=0)
785 MapFileHeader->tmnames[which][i]=temp[i];
788 if (which<numtmplanes)
792 TInfoMNoff(ox+12,oy+3+which,which);
796 GetButtonXY(&TINd,0,&sx,&sy);
797 if (!CheckList(sx,sy,6,1,TIDoneOn,TIDoneOff,1))
810 void TInfoNon(int x,int y,int b)
815 if (!MapFileHeader->tnames[b][0])
818 fprint(MapFileHeader->tnames[b]);
821 void TInfoNoff(int x,int y,int b)
825 if (!MapFileHeader->tnames[b][0])
828 fprint(MapFileHeader->tnames[b]);
830 void TInfoMNon(int x,int y,int b)
835 if (!MapFileHeader->tmnames[b][0])
838 fprint(MapFileHeader->tmnames[b]);
841 void TInfoMNoff(int x,int y,int b)
845 if (!MapFileHeader->tmnames[b][0])
848 fprint(MapFileHeader->tmnames[b]);
850 void TIDoneOn(int x,int y)
858 void TIDoneOff(int x,int y)
865 ////////////////////////////////////////////////////
869 ////////////////////////////////////////////////////
870 void CreateMap(int exitok)
872 unsigned lwidth,lheight,i;
877 if ((mapnum=SelectMap(exitok,NOTCREATED,"TO CREATE"))==-1)
880 InputMap(lname,&lwidth,&lheight,exitok);
889 MMFreePtr((memptr *)&MapBkgnd);
890 MMFreePtr((memptr *)&CutBkgnd);
894 MMFreePtr((memptr *)&MapFrgnd);
895 MMFreePtr((memptr *)&CutFrgnd);
899 MMFreePtr((memptr *)&MapInfoPl);
900 MMFreePtr((memptr *)&CutInfoPl);
903 size=2L*(lwidth*lheight);
905 if (MapFileHeader->maptype&BPLANE)
907 MMAllocate((memptr *)&MapBkgnd,size);
908 MMAllocate((memptr *)&CutBkgnd,size);
909 for(i=0;i<lwidth*lheight;i++)
910 *(MapBkgnd+i)=*(CutBkgnd+i)=0;
912 if (MapFileHeader->maptype&FPLANE)
914 MMAllocate((memptr *)&MapFrgnd,size);
915 MMAllocate((memptr *)&CutFrgnd,size);
916 for(i=0;i<lwidth*lheight;i++)
917 *(MapFrgnd+i)=*(CutFrgnd+i)=0;
919 if (MapFileHeader->maptype&IPLANE)
921 MMAllocate((memptr *)&MapInfoPl,size);
922 MMAllocate((memptr *)&CutInfoPl,size);
923 for(i=0;i<lwidth*lheight;i++)
924 *(MapInfoPl+i)=*(CutInfoPl+i)=0;
928 strcpy(MapHeader.name,lname);
929 MapHeader.width=mapwidth=lwidth;
930 MapHeader.height=mapheight=lheight;
931 strcpy(MapNames[mapnum],MapHeader.name);
932 AllocateUndoBuffers();
937 SelectMode=PasteMode=xbase=ybase=0;
938 SelX1=SelX2=SelY1=SelY2=-1;
943 ////////////////////////////////////////////////////
947 ////////////////////////////////////////////////////
948 void LoadMap(int mapnum)
950 unsigned long csize,size=0;
955 // DEALLOCATE ALL CURRENT MAP MEMORY
961 MMFreePtr((memptr *)&MapBkgnd);
962 MMFreePtr((memptr *)&CutBkgnd);
966 MMFreePtr((memptr *)&MapFrgnd);
967 MMFreePtr((memptr *)&CutFrgnd);
971 MMFreePtr((memptr *)&MapInfoPl);
972 MMFreePtr((memptr *)&CutInfoPl);
979 XMSmove(XMSmaps,MapFileHeader->dataoffsets[mapnum],0,(long)&MapHeader,sizeof(MapHeaderStr));
981 LoadFile(mapname,(char huge *)&MapHeader,MapFileHeader->dataoffsets[mapnum],sizeof(MapHeaderStr));
984 // LOAD & DECOMPRESS MAP PLANES
986 if (MapFileHeader->maptype & BPLANE)
989 XMSmove(XMSmaps,MapHeader.mapbkgndpl,0,(long)&size,2);
991 LoadFile(mapname,(char huge *)&size,MapHeader.mapbkgndpl,2);
993 MMAllocate((memptr *)&MapBkgnd,size);
994 MMAllocate((memptr *)&CutBkgnd,size);
995 csize=MapHeader.mapbkgndlen-2;
996 MMAllocate(&block,csize);
999 XMSmove(XMSmaps,MapHeader.mapbkgndpl+2,0,(long)MK_FP(block,0),csize);
1001 LoadFile(mapname,MK_FP(block,0),MapHeader.mapbkgndpl+2,csize);
1003 RLEWExpand(MK_FP(block,0),MK_FP(MapBkgnd,0),size,MapFileHeader->RLEWtag);
1006 if (MapFileHeader->maptype & FPLANE)
1009 XMSmove(XMSmaps,MapHeader.mapfrgndpl,0,(long)&size,2);
1011 LoadFile(mapname,(char huge *)&size,MapHeader.mapfrgndpl,2);
1013 MMAllocate((memptr *)&MapFrgnd,size);
1014 MMAllocate((memptr *)&CutFrgnd,size);
1015 csize=MapHeader.mapfrgndlen-2;
1016 MMAllocate(&block,csize);
1019 XMSmove(XMSmaps,MapHeader.mapfrgndpl+2,0,(long)MK_FP(block,0),csize);
1021 LoadFile(mapname,MK_FP(block,0),MapHeader.mapfrgndpl+2,csize);
1023 RLEWExpand(MK_FP(block,0),MK_FP(MapFrgnd,0),size,MapFileHeader->RLEWtag);
1026 if (MapFileHeader->maptype & IPLANE)
1029 XMSmove(XMSmaps,MapHeader.mapinfopl,0,(long)&size,2);
1031 LoadFile(mapname,(char huge *)&size,MapHeader.mapinfopl,2);
1033 MMAllocate((memptr *)&MapInfoPl,size);
1034 MMAllocate((memptr *)&CutInfoPl,size);
1035 csize=MapHeader.mapinfolen-2;
1036 MMAllocate(&block,csize);
1039 XMSmove(XMSmaps,MapHeader.mapinfopl+2,0,(long)MK_FP(block,0),csize);
1041 LoadFile(mapname,MK_FP(block,0),MapHeader.mapinfopl+2,csize);
1043 RLEWExpand(MK_FP(block,0),MK_FP(MapInfoPl,0),size,MapFileHeader->RLEWtag);
1047 mapwidth=MapHeader.width;
1048 mapheight=MapHeader.height;
1049 strcpy(MapNames[mapnum],MapHeader.name);
1051 AllocateUndoBuffers();
1053 SaveUndo(0,0,mapwidth,mapheight);
1054 RestoreCutBuffers();
1056 SelectMode=PasteMode=xbase=ybase=0;
1057 SelX1=SelX2=SelY1=SelY2=-1;
1061 ////////////////////////////////////////////////////
1063 // Select a new map!
1065 ////////////////////////////////////////////////////
1066 btype ClvlB[]={{"\xb",28,5,1},
1068 {" Exit ",12,17,1}};
1069 DialogDef ClvlD={" SELECT MAP",
1070 30,19,2,&ClvlB[0],NULL};
1073 int SelectMap(int exitok,int createflg,char *title)
1075 MapHeaderStr TempMapHeader;
1076 unsigned ox,oy,i,dx,dy;
1077 int select=-1,redraw;
1090 DrawDialog(&ClvlD,1);
1091 GetDialogXY(&ClvlD,&dx,&dy);
1093 sx=screencenterx-strlen(title)/2;
1100 GetButtonXY(&ClvlD,0,&sx,&sy);
1103 print("Map Name\n");
1106 DrawBorder(sx,sy,26,11,2);
1122 if (i+smbase==whichmap)
1137 GetButtonXY(&ClvlD,0,&(unsigned)mx,&(unsigned)my);
1138 if (!CheckList(mx,my,1,1,UparOn,UparOff,0) || keydown[0x48])
1141 GetButtonXY(&ClvlD,0,&sx,&sy);
1142 print(ClvlB[0].text);
1149 while(keydown[0x48]);
1153 GetButtonXY(&ClvlD,1,&(unsigned)mx,&(unsigned)my);
1154 if (!CheckList(mx,my,1,1,DnarOn,DnarOff,0) || keydown[0x50])
1157 GetButtonXY(&ClvlD,1,&sx,&sy);
1158 print(ClvlB[1].text);
1165 while(keydown[0x50]);
1171 GetButtonXY(&ClvlD,2,&(unsigned)mx,&(unsigned)my);
1172 if (!CheckList(mx,my,6,1,ExitOn,ExitOff,0))
1174 RestoreBackground();
1179 if (exitok && keydown[1])
1181 RestoreBackground();
1185 select=CheckList(ox+5,oy,20,10,MNameOn,MNameOff,0);
1191 MNameOff(sx,sy,select);
1193 if ((MapFileHeader->dataoffsets[select+smbase]!=-1 && createflg==NOTCREATED)||
1194 (MapFileHeader->dataoffsets[select+smbase]==-1 && createflg==CREATED))
1198 } while(!redraw && select<0);
1201 RestoreBackground();
1202 return select+smbase;
1208 void DnarOn(int x,int y)
1213 drawchar(sx,sy,0xc);
1216 void DnarOff(int x,int y)
1220 drawchar(sx,sy,0xc);
1222 void UparOn(int x,int y)
1227 drawchar(sx,sy,0xb);
1230 void UparOff(int x,int y)
1234 drawchar(sx,sy,0xb);
1236 void ExitOn(int x,int y)
1244 void ExitOff(int x,int y)
1252 // Highlight Map Name
1254 void MNameOn(int x,int y,int i)
1262 // De-Highlight Map Name
1264 void MNameOff(int x,int y,int i)
1266 MapHeaderStr TempMapHeader;
1270 if (MapFileHeader->dataoffsets[i+smbase]!=-1)
1274 print(MapNames[i+smbase]);
1277 print("--not created yet--");
1282 ////////////////////////////////////////////////////
1284 // Pick more planes for the map set
1286 ////////////////////////////////////////////////////
1287 btype PickPlaneb[]={{"X",1,3,1},
1290 DialogDef PickPlaneD={"Which other planes\n"
1294 ,18,11,3,&PickPlaneb[0],NULL};
1296 int PickMorePlanes(void)
1299 char planes=7; // 1=bkgnd/2=frgnd/4=info
1301 DrawDialog(&PickPlaneD,1);
1304 which=CheckButtons(&PickPlaneD);
1308 RestoreBackground();
1311 GetButtonXY(&PickPlaneD,0,&sx,&sy);
1321 GetButtonXY(&PickPlaneD,1,&sx,&sy);
1332 RestoreBackground();
1333 MapFileHeader->maptype=planes;
1337 ////////////////////////////////////////////////////
1339 // Get map dimensions
1341 ////////////////////////////////////////////////////
1342 btype LvlSpecb[]={{" ",1,3,1},
1346 DialogDef LvlSpec={" MAP DIMENSIONS\n"
1347 " Map Name:\n\n\n\n"
1348 " Map Width:\n\n\n\n"
1350 20,16,4,&LvlSpecb[0],NULL};
1352 void InputMap(char *lvlname,unsigned *levelw,unsigned *levelh,int exitok)
1354 unsigned butn,ok=0,nameok=0,widok=0,heightok=0,
1355 ox,oy,width=0,height=0,oldwidth=0,oldheight=0;
1356 char oldname[16]="",name[16]="";
1359 DrawDialog(&LvlSpec,1);
1360 GetButtonXY(&LvlSpec,1,&sx,&sy);
1362 GetButtonXY(&LvlSpec,2,&sx,&sy);
1367 // START INPUT IMMEDIATELY
1376 butn=CheckButtons(&LvlSpec);
1380 RestoreBackground();
1390 GetButtonXY(&LvlSpec,butn-1,&sx,&sy);
1394 print(LvlSpecb[butn-1].text);
1401 if (!input(name,15))
1403 strcpy(name,oldname);
1406 print(LvlSpecb[butn-1].text);
1408 strcpy(oldname,name);
1422 GetButtonXY(&LvlSpec,butn-1,&sx,&sy);
1425 print(LvlSpecb[butn-1].text);
1434 if ((width=inputint(9))==ESCOUT)
1445 print(LvlSpecb[butn-1].text);
1452 GetButtonXY(&LvlSpec,butn-1,&sx,&sy);
1455 print(LvlSpecb[butn-1].text);
1464 if ((height=inputint(9))==ESCOUT)
1475 print(LvlSpecb[butn-1].text);
1482 if (2L*height*width>0x10000) // TOO BIG! TRIM IT!
1489 if (nameok && widok && heightok)
1496 RestoreBackground();
1500 strcpy(lvlname,name);
1503 ////////////////////////////////////////////////////
1505 // Item - Input INFOPLANE value
1507 ////////////////////////////////////////////////////
1508 btype EnterIVb={" ",1,3,1};
1509 DialogDef EnterIV={"Enter a value for\nthe INFO plane:\n\n\n",18,5,1,&EnterIVb,NULL};
1511 void Item_InputInfoplane(void)
1516 if (TsearchMode || BfillMode || FillMode || PasteMode || SelectMode)
1520 DrawDialog(&EnterIV,1);
1522 GetButtonXY(&EnterIV,0,&sx,&sy);
1523 if ((val=inputint(9))!=ESCOUT)
1525 RestoreBackground();
1530 ////////////////////////////////////////////////////
1532 // Item - Select Tile
1534 ////////////////////////////////////////////////////
1535 void Item_SelectTile(void)
1540 ////////////////////////////////////////////////////
1542 // Item - Block Fill
1544 ////////////////////////////////////////////////////
1545 void Item_BlockFill(void)
1553 // DO THE ACTUAL BLOCK FILL
1555 void DoBlockFill(void)
1557 unsigned loc,i,j,ctrl=0,newt,newm,newi,tton,tmon,tion,from;
1567 UndoRegion.w=SelX2-SelX1+1;
1568 UndoRegion.h=SelY2-SelY1+1;
1572 for (j=SelY1;j<=SelY2;j++)
1573 for (i=SelX1;i<=SelX2;i++)
1576 from=(TileCopy.y+((j-SelY1)%TileCopy.h))*mapwidth+
1577 TileCopy.x+((i-SelX1)%TileCopy.w);
1579 switch(TileCopy.MapOrTileSelect)
1581 case 0: // COPY BUFFER
1582 tton=TileCopy.PlanesCopied&BPLANE;
1583 tmon=TileCopy.PlanesCopied&FPLANE;
1584 tion=TileCopy.PlanesCopied&IPLANE;
1586 newt=CutBkgnd[from];
1587 newm=CutFrgnd[from];
1588 newi=CutInfoPl[from];
1595 newt=((j%TileCopy.h)+TileCopy.y)*selectcols+
1596 TileCopy.x+(i%TileCopy.w);
1597 if (XMSlookup[newt]<0)
1604 newm=((j%TileCopy.h)+TileCopy.y)*selectcols+
1605 TileCopy.x+(i%TileCopy.w)+tilenum+maxiconrows*selectcols;
1606 if (XMSlookup[newm]<0)
1613 *(MapBkgnd+loc)=newt;
1615 *(MapFrgnd+loc)=newm;
1617 *(MapInfoPl+loc)=newi;
1619 if (j>=ybase && j<ybase+screenh &&
1620 i>=xbase && i<xbase+screenw)
1622 int tempt,tempm,tempi;
1624 tempt=*(MapBkgnd+loc);
1625 tempm=*(MapFrgnd+loc)+tilenum;
1626 tempi=*(MapInfoPl+loc)+tilenum;
1628 CombineTiles(viewton?tempt:-BkgndColor,viewmon*tempm,viewion*tempi,tsize);
1631 DrawTile((i-xbase)<<(tsize-1),((j-ybase)<<(tsize+2))+8,tsize);
1636 for (j=SelY1;j<=SelY2;j++)
1637 for (i=SelX1;i<=SelX2;i++)
1642 *(MapBkgnd+loc)=whicht;
1644 *(MapFrgnd+loc)=whichtm-tilenum;
1646 *(MapInfoPl+loc)=whichi-tilenum;
1648 if (j>=ybase && j<ybase+screenh &&
1649 i>=xbase && i<xbase+screenw)
1651 int tempt,tempm,tempi;
1653 tempt=*(MapBkgnd+loc);
1654 tempm=*(MapFrgnd+loc)+tilenum;
1655 tempi=*(MapInfoPl+loc)+tilenum;
1657 CombineTiles(viewton?tempt:-BkgndColor,viewmon*tempm,viewion*tempi,tsize);
1660 DrawTile((i-xbase)<<(tsize-1),((j-ybase)<<(tsize+2))+8,tsize);
1669 ////////////////////////////////////////////////////
1671 // Remove the XMS undo buffers
1673 ////////////////////////////////////////////////////
1674 void RemoveUndoBuffers(void)
1677 XMSFreeMem(XMSundoB);
1679 XMSFreeMem(XMSundoF);
1681 XMSFreeMem(XMSundoI);
1683 XMSundoB=XMSundoF=XMSundoI=0;
1687 ////////////////////////////////////////////////////
1689 // Allocate XMS undo buffers
1690 // NOTE: uses "mapwidth" & "mapheight"
1692 ////////////////////////////////////////////////////
1693 void AllocateUndoBuffers(void)
1695 long size=2L*mapwidth*mapheight;
1697 if (MapFileHeader->maptype&BPLANE)
1698 XMSundoB=XMSAllocate(size);
1699 if (MapFileHeader->maptype&FPLANE)
1700 XMSundoF=XMSAllocate(size);
1701 if (MapFileHeader->maptype&IPLANE)
1702 XMSundoI=XMSAllocate(size);
1706 ////////////////////////////////////////////////////
1708 // Save Undo buffers
1710 ////////////////////////////////////////////////////
1711 void SaveUndo(int x,int y,int w,int h)
1713 unsigned hsize=w*2,j;
1717 unsigned off=2*(j*mapwidth+x);
1719 if (MapFileHeader->maptype&BPLANE)
1720 XMSmove(0,(long)MK_FP(MapBkgnd,off),XMSundoB,off,hsize);
1721 if (MapFileHeader->maptype&FPLANE)
1722 XMSmove(0,(long)MK_FP(MapFrgnd,off),XMSundoF,off,hsize);
1723 if (MapFileHeader->maptype&IPLANE)
1724 XMSmove(0,(long)MK_FP(MapInfoPl,off),XMSundoI,off,hsize);
1729 ////////////////////////////////////////////////////
1731 // Restore Undo buffers
1733 ////////////////////////////////////////////////////
1734 void RestoreUndo(void)
1736 long size=2L*UndoRegion.w;
1740 for (j=UndoRegion.y;j<UndoRegion.y+UndoRegion.h;j++)
1742 unsigned loc=2*(j*mapwidth+UndoRegion.x);
1744 if (MapFileHeader->maptype&BPLANE)
1745 XMSmove(XMSundoB,loc,0,(long)MK_FP(MapBkgnd,loc),size);
1746 if (MapFileHeader->maptype&FPLANE)
1747 XMSmove(XMSundoF,loc,0,(long)MK_FP(MapFrgnd,loc),size);
1748 if (MapFileHeader->maptype&IPLANE)
1749 XMSmove(XMSundoI,loc,0,(long)MK_FP(MapInfoPl,loc),size);
1756 ////////////////////////////////////////////////////
1758 // Copy the current UNDO region to the undo buffers
1760 ////////////////////////////////////////////////////
1761 void CopyUndoRegion(void)
1763 if (UndoRegion.x==-1)
1766 SaveUndo(UndoRegion.x,UndoRegion.y,UndoRegion.w,UndoRegion.h);
1770 ////////////////////////////////////////////////////
1774 ////////////////////////////////////////////////////
1775 void Item_Undo(void)
1777 if (UndoRegion.x==-1)
1779 ErrDialog("You don't have anything to UNDO!"," Oh, yeah. ");
1788 ////////////////////////////////////////////////////
1790 // Item - Tile Search!
1792 ////////////////////////////////////////////////////
1793 void Item_TileSearch(void)
1795 int num=planeton+planemon+planeion;
1800 ErrDialog("TILE SEARCH will only work\n"
1801 "with ONE active plane! Make\n"
1802 "sure that the tile you're\n"
1803 "searching for is selected!"," OK ");
1812 ////////////////////////////////////////////////////
1816 ////////////////////////////////////////////////////
1819 void Item_Launch(void)
1821 TempStruct LaunchInfo;
1822 char ename[64],*envstr[15],temp[40],temp1[40],temp2[40],tiname[14]="TEDINFO.TMP",i,j;
1830 if (!TEDInfo->launchname[0])
1832 ErrDialog("You didn't specify a launching\n"
1833 "name on the command line? What\n"
1834 "do I launch, Einstein? Geez!"," What a goober. ");
1839 // Save the handles for all XMS memory so we don't
1840 // have to re-install this shit!
1842 TEDInfo->OldCgaXMS=CgaXMS;
1843 TEDInfo->OldEgaXMS=EgaXMS;
1844 TEDInfo->OldVgaXMS=VgaXMS;
1846 TEDInfo->OldCgaXMSsize=CgaXMSsize;
1847 TEDInfo->OldEgaXMSsize=EgaXMSsize;
1848 TEDInfo->OldVgaXMSsize=VgaXMSsize;
1850 size=4L*(tilenum+tilemnum);
1853 if (1024L*XMSTotalFree()<size)
1856 TEDInfo->OldCgaXMS=TEDInfo->OldCgaXMSsize=0;
1860 TEDInfo->CgaXMSlook=XMSAllocate(size);
1861 XMSmove(0,(long)MK_FP(CgaXMSlookup,0),TEDInfo->CgaXMSlook,0,size);
1867 if (1024L*XMSTotalFree()<size)
1870 TEDInfo->OldEgaXMS=TEDInfo->OldEgaXMSsize=0;
1874 TEDInfo->EgaXMSlook=XMSAllocate(size);
1875 XMSmove(0,(long)MK_FP(EgaXMSlookup,0),TEDInfo->EgaXMSlook,0,size);
1881 if (1024L*XMSTotalFree()<size)
1884 TEDInfo->OldVgaXMS=TEDInfo->OldVgaXMSsize=0;
1888 TEDInfo->VgaXMSlook=XMSAllocate(size);
1889 XMSmove(0,(long)MK_FP(VgaXMSlookup,0),TEDInfo->VgaXMSlook,0,size);
1894 // SAVE CURRENT VIDEOMODE FOR LAUNCH RETURN
1896 LaunchInfo.lastmode=videomode;
1897 strcpy(LaunchInfo.ext,ext);
1898 SaveFile(tiname,(char huge *)&LaunchInfo,0,sizeof(TempStruct));
1901 // ICON CHANGE ON LAUNCH?
1907 mx=xbase+(pixelx>>(tsize+2));
1908 my=ybase+((pixely-8)>>(tsize+2));
1912 if (pixely>=8 && pixely<infoy*8 && TEDInfo->permicon
1913 && MapFileHeader->maptype&IPLANE && !usingbat && keydown[0x1d])
1917 mx=xbase+(pixelx>>(tsize+2));
1918 my=ybase+((pixely-8)>>(tsize+2));
1920 for (j=0;j<mapheight;j++)
1921 for (i=0;i<mapwidth;i++)
1922 if (MapInfoPl[j*mapwidth+i]==TEDInfo->permicon)
1924 MapInfoPl[j*mapwidth+i]=0;
1930 MapInfoPl[my*mapwidth+mx]=TEDInfo->permicon;
1935 TEDInfo->oscrx=xbase;
1936 TEDInfo->oscry=ybase;
1937 TEDInfo->pflags=((planeton&1)<<6)|
1944 _fmemcpy((void far *)TEDInfo->parmstring,(void far *)parmstring,64);
1951 XMSFreeMem(XMSmaps);
1953 strcpy(temp,"Launching ");
1954 _fstrcat((char far *)temp,(char far *)TEDInfo->launchname);
1961 _fmemcpy((char far *)ename,(char far *)TEDInfo->launchname,14);
1964 envstr[1] = "/TEDLEVEL";
1965 itoa(whichmap,temp,10);
1975 // CHOP UP THE PARMSTRING FOR 'EXECV'
1977 strcpy(tempparm,parmstring);
1978 envstr[startp]=&tempparm[0];
1979 for(j=startp+1,i=0;i<strlen(tempparm);i++)
1980 if (tempparm[i]==' ')
1982 envstr[j]=&tempparm[i+1];
1988 RemoveUndoBuffers();
1992 // ARE WE EXITING WITH A BATCH FILE?
2003 execv(ename,envstr);
2006 RestoreBackground();
2008 ErrDialog("LAUNCHing failed. TED5 will\n"
2009 "now restart."," I have gubs ");
2011 execlp("TED5.EXE","TED5.EXE","/LAUNCH",NULL);
2013 printf("Couldn't find TED5 for some reason!");
2018 ////////////////////////////////////////////////////
2020 // Item - TILEINFO Copy
2022 ////////////////////////////////////////////////////
2024 {"TILEINFOM Copy Kludge\n\n"
2030 void Item_TINFOCopy(void)
2032 unsigned dx,dy,i,from,to,amt;
2037 DrawDialog(&TICd,1);
2038 GetDialogXY(&TICd,&dx,&dy);
2046 RestoreBackground();
2057 RestoreBackground();
2068 RestoreBackground();
2075 MMAllocate(&block,amt);
2077 for (i=0;i<numtmplanes;i++)
2079 movedata((unsigned)TMinfo[i],from,(unsigned)block,0,amt);
2080 movedata((unsigned)block,0,(unsigned)TMinfo[i],to,amt);
2084 RestoreBackground();