#include <stdio.h>
#include <wgt4.h>
#include <stdlib.h>
#include <dos.h>


extern block smalltile[8];
extern color smalltpal[256];
extern color scpalette[256];



void showmap(int mnum)
{
	int x,y;  //coordinates
	int spot; //current terrain type
	int xx,yy; //pixel coordinates
	int ix,iy;
	int MAP[82][52];
	FILE *sav;
	block emsprite;

	wcls(0);
	wsetpalette(0,255,smalltpal);
	xx=0;
	yy=0;

	     if(mnum==1) sav=fopen("temp\\map1.dat","rb");
	     if(mnum==2) sav=fopen("temp\\map2.dat","rb");
	     if(mnum==3) sav=fopen("temp\\map3.dat","rb");
	     if(mnum==4) sav=fopen("temp\\map4.dat","rb");

		for(iy=1;iy<=50;iy++){
		  for(ix=1;ix<=80;ix++){
		    fread(&MAP[ix][iy],sizeof(int),1,sav);
		    }
		}
		fclose(sav);
	for(y=1;y<=50;y++){
		for(x=1;x<=80;x++){
			spot=MAP[x][y];

			emsprite=wems_getdata(smalltile[spot]);
			wputblock(xx,yy,emsprite,1);

			xx=xx+4;
		}
		xx=0;
		yy=yy+4;
	}
wfreeblock(emsprite);
return;
}

void savemaps(void)
{
int ix,iy,num;
block screen1;

   for(num=1;num<=4;num++){
	showmap(num);
	screen1=wnewblock(0,0,319,199);
	if(num==1) {
		wsavepcx256("worldmap\\map1.pcx",screen1,smalltpal);

	    }
	if(num==2) {
		wsavepcx256("worldmap\\map2.pcx",screen1,smalltpal);

	    }
	if(num==3) {
		wsavepcx256("worldmap\\map3.pcx",screen1,smalltpal);

	    }
	if(num==4) {
		wsavepcx256("worldmap\\map4.pcx",screen1,smalltpal);

	    }
	wfreeblock(screen1);
   }
return;
}
