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



block tiles[169];
block virtscreen;
color virtpalette[256];
block emsprite;
block screen2;
color screen2pal[256];
color tilepalette[256];
color normpalette[256];


int map[41][26];


char mapname[20]={"citymap\\CMAP"};
char tempf[20];



void readdata()
{
FILE *fpmonst;
int z,x,y,d;


	fpmonst=fopen("temp\\citym.tmp","rb");
	for(x=0;x<=40;x++){
	    for(y=0;y<=25;y++){
		 fread(&z,sizeof(int),1,fpmonst);
		 map[x][y]=z;
		}
	}
	fclose(fpmonst);
}





void print_map()
{

int x,y,tile,xx,yy;
int numb;
strcpy(tempf,mapname);
wcls(0);

wsetpalette(0,255,virtpalette);
wputblock(0,0,virtscreen,0);
wtextcolor(15);
wouttextxy(105,100,NULL,"Saving Maps...");
wtextcolor(0);
wsetscreen(virtscreen);
wcls(15);
numb=1;
wsetpalette(0,255,tilepalette);
wcls(15);
	xx=0;
	yy=0;
	for(y=1;y<=12;y++){
	  for(x=1;x<=20;x++){
			
			emsprite=wems_getsprite(numb,tiles);
			wputblock(xx,yy,emsprite,0);

			xx=xx+16;
			numb=numb+1;
			if(numb>137) {x=999;y=999;}
	  }
	  xx=0;
	  yy=yy+16;
	}
		strcat(mapname,"a.pcx");
		wsavepcx256(mapname,virtscreen,tilepalette);
		strcpy(mapname,tempf);

wcls(0);
wnormscreen();
}



void main()
{
  int mode;

       mode=wgetmode();
       vga256();
	wems_init();
	wems_open(16);
	wreadpalette(0,255,normpalette);


	setlib("graphics\\citygen.lib");
	wsetpalette(0,255,normpalette);
	wtexttransparent(0);
	wtextcolor(255);
	wouttextxy(120,100,NULL,"Loading...");
	virtscreen=wloadpcx256("citysav.pcx",virtpalette);

	wems_loadsprites(tilepalette,"city.spr",tiles,0,168);




      readdata();
      wcls(0);
      print_map();


 wfreeblock(virtscreen);

 wems_reset();
 wems_close();

 wsetmode(mode);
}
