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

block characterscreen;
color characterpalette[256];
color pal[256];
block menuscreen;
color menupalette[256];
wgtfont font;


static int clevel;
static int level;
static int CUT;
static int NATURAL;
static int STOP;

int dt;   /*dungeon type*/

FILE *fp;

/*****************SELECT THE CHARACTER LEVEL****************/
void characterlevel(void)
{
	char ml[8];
	int stopp;

	stopp=0;
	wcls(0);
	wsetpalette(0,255,characterpalette);
	wfade_out(1,255,0,characterpalette);
	wputblock(0,0,characterscreen,0);
	wfade_in(0,255,0,characterpalette);
wtexttransparent(0);
wtextcolor(255);
itoa(clevel,ml,10);
wouttextxy(138,100,font,ml);

mon();
msetbounds(0,0,319,199);
msetxy(160,100);

	for(;;){
		if(but==1){
			noclick();
			if((mx>107)&&(mx<184)&&(my>58)&&(my<75)){
				clevel++;
				moff();
				wputblock(0,0,characterscreen,0);
				itoa(clevel,ml,10);
				wouttextxy(138,100,font,ml);
				mon();
				}
			if((mx>110)&&(mx<182)&&(my>133)&&(my<152)){
				clevel--;
				moff();
				if(clevel<=0) clevel=1;
				wputblock(0,0,characterscreen,0);
				itoa(clevel,ml,10);
				wouttextxy(138,100,font,ml);
				mon();
				}
			if((mx>119)&&(mx<172)&&(my>171)&&(my<187))
				 {
				 stopp=1;
				 }
		}

		if(stopp==1) break;
	}
	level=(clevel/3);
	if (level>10) level=10;
	if(level<1) level=1;
moff();

}

void dungeontype()
{
 int stopp;
 stopp=0;
	wsetpalette(0,255,menupalette);

	wfade_out(1,255,0,menupalette);
	wputblock(0,0,menuscreen,0);
	wfade_in(0,255,0,menupalette);

mon();
msetbounds(0,0,319,199);
msetxy(160,100);

	for(;;){
		if(but==1){
			noclick();
			if((mx>88)&&(mx<223)&&(my>65)&&(my<81)){
				     /*Manmade dungeon selection*/
				     CUT=1;
				     stopp=1;
				}
			if((mx>88)&&(mx<221)&&(my>105)&&(my<119)){
				    /*natural dungeon selection*/
				    NATURAL=1;
				    stopp=1;
				}
			if((mx>102)&&(mx<201)&&(my>165)&&(my<181))
				 {
				 stopp=1;
				 STOP=1;
				 }
		}

		if(stopp==1) break;
	}

moff();

}


void main()
{

  CUT=0;
  NATURAL=0;
  STOP=0;
  clevel=1;


  vga256();


  wloadpalette("graphics\\default.pal",pal);
  wsetpalette(0,255,pal);
  wcls(0);
	setlib("graphics\\dunmenu.lib");
	characterscreen=wloadpcx256("char.pcx",characterpalette);

	menuscreen=wloadpcx256("dunmenu.pcx",menupalette);

	font=wloadfont("font.3");

  minit();

  dungeontype();

  if(STOP!=1) characterlevel();

  if(CUT==1) dt=1;
  if(NATURAL==1) dt=2;
  if(STOP!=1) {
		fp=fopen("temp\\dundata.tmp","w");
			fprintf(fp,"%d\n",clevel);   /*character level*/
			fprintf(fp,"%d\n",0);        /*number of rooms*/
			fprintf(fp,"%d\n",level);    /*monster level*/
			fprintf(fp,"%d\n",dt);       /*dungeon type*/
		fclose(fp);
		}
  mdeinit();
  wfreefont(font);
  wfreeblock(menuscreen);
  wfreeblock(characterscreen);

  if(STOP==1) execv("start.exe",NULL);
  if(CUT==1) execv("cut",NULL);
  if(NATURAL==1) execv("natgen",NULL);
  exit(0);
}



