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












void initland(void)
{
extern int MAP[81][51];
	int x,y;

	for(y=0;y<=50;y++){
		for(x=0;x<=80;x++){
			MAP[x][y]=0;
			}
	}
return;
}

void makemapl(int mnum)
{
extern int LDIR;
extern int RDIR;

extern int MAP[81][51];
	int r;                //random number
	int x,y;              //temp location
	int t,chance;         //temp
	int left;             //temp left variable
	int top;              //temp top variable
	int topr;             //temp top right variable
	int topl;             //temp top left variable
	int right;
	int chancel,chancet,chancetr,chancetl,chancer;  //1=yes 0=no
	int tm;               //temp variable
	int z;
	int MAP1r[52];
	int MAP3r[52];
	int MAP2b[82];
	int MAP1b[82];

	FILE *tempload;
	LDIR=1;
	RDIR=0;

	x=0;
	y=0;

   if(mnum==2) {
		tempload=fopen("temp\\map1r.dat","rb");
			for(y=1;y<=50;y++){
			fread(&MAP1r[y],sizeof(int),1,tempload);
			}
			fclose(tempload);
		}
   if(mnum==3) {
		tempload=fopen("temp\\map1b.dat","rb");
			for(t=1;t<=80;t++){
			fread(&MAP1b[t],sizeof(int),1,tempload);
			}
			fclose(tempload);
		}
   if(mnum==4) {
		tempload=fopen("temp\\map3r.dat","rb");
			for(y=1;y<=50;y++){
			fread(&MAP3r[y],sizeof(int),1,tempload);
			}
			fclose(tempload);
		tempload=fopen("temp\\map2b.dat","rb");
			for(t=1;t<=80;t++){
			fread(&MAP2b[t],sizeof(int),1,tempload);
			}
			fclose(tempload);
		}

   for(y=1;y<=50;y++){
      for(t=1;t<=80;t++){
	if(LDIR==1) x++;
	if(x>80) {RDIR=1;LDIR=0;}
	if(RDIR==1) x--;
	if(x<1) {LDIR=1;RDIR=0;x=1;}

		      for(;;){
			chancel=0;
			chancet=0;
			r=(random(8)+1);
			if(mnum==1) left=MAP[x-1][y];
			if((mnum==2)&&(x<=1)) left=MAP1r[y];
			if((mnum==2)&&(x>1)) left=MAP[x-1][y];
			if(mnum==3) left=MAP[x-1][y];
			if((mnum==4)&&(x<=1)) left=MAP3r[y];
			if((mnum==4)&&(x>1)) left=MAP[x-1][y];
			if(mnum==1) top=MAP[x][y-1];
			if(mnum==2) top=MAP[x][y-1];
			if((mnum==3)&&(y<=1)) top=MAP1b[x];
			if((mnum==3)&&(y>1)) top=MAP[x][y-1];
			if((mnum==4)&&(y<=1)) top=MAP2b[x];
			if((mnum==4)&&(y>1)) top=MAP[x][y-1];
			if((mnum==3)&&(y<=1)) topr=MAP1b[x+1];
			if((mnum==3)&&(y>1)) topr=MAP[x+1][y-1];
			if((mnum==4)&&(y<=1)) topr=MAP2b[x+1];
			if((mnum==4)&&(y>1)) topr=MAP[x+1][y-1];
			if((mnum==1)||(mnum==2)) topr=MAP[x+1][y-1];
			if((mnum==3)&&(y<=1)) topl=MAP1b[x-1];
			if((mnum==3)&&(y>1)) topl=MAP[x-1][y-1];
			if((mnum==4)&&(y<=1)) topl=MAP2b[x-1];
			if((mnum==4)&&(y>1)) topl=MAP[x-1][y-1];
			if((mnum==1)||(mnum==2)) topl=MAP[x-1][y-1];
			right=MAP[x+1][y];

		if(LDIR==1){
			/*OCEAN*/
			if(left==0){
				if(r==1) chance=0;  //ocean near desert
				if(r==2) chance=10; //ocean near plains
				if(r==3) chance=6; //ocean near light forest
				if(r==4) chance=1;  //ocean near forest
				if(r==5) chance=2;  //ocean near hills
				if(r==6) chance=3;  //ocean near mountains
				if(r==7) chance=8; //ocean near ice
				if(r==8) chance=75; //ocean near ocean
				if((mnum==1)||(mnum==3)){
				   if(x<20) {
				       if(r==8) chance=85; //ocean near ocean
				   }
				 }
				 if((mnum==2)||(mnum==4)){
				   if(x>65) {
				       if(r==8) chance=85; //ocean near ocean
				   }
				 }
				 if((mnum==1)||(mnum==2)){
				   if(y<=15){
				      if(r==8) chance=85;
				      }
				 }
				 if((mnum==3)||(mnum==4)){
				   if(y>=35){
				      if(r==8) chance=85;
				      }
				 }
			}
			/*DESERT*/
			if(left==1){
				if(r==1) {
					if((mnum==1)||(mnum==2)){
					   if(y>=30){
					     chance=80; //desert near desert
					     }
					   if(y<30) chance=0;
					 }
					if((mnum==3)||(mnum==4)){
					   if(y<=30) chance=80;
					   if(y>30) chance=0;
					 }
				  }
				if(r==2) chance=5;  //desert near plains
				if(r==3) chance=0;  //desert near light forest
				if(r==4) chance=0;  //desert near forest
				if(r==5) chance=10; //desert near hills
				if(r==6) chance=5;  //desert near mountains
				if(r==7) chance=0;  //desert near ice
				if(r==8) chance=0;  //desert near ocean
				}

			/*PLAINS*/
			if(left==2){
				if(r==1) chance=6;  //plains near desert
				if(r==2) chance=80; //plains near plains
				if(r==3) chance=10; //plains near light forest
				if(r==4) chance=10; //plains near forest
				if(r==5) chance=10; //plains near hills
				if(r==6) chance=3;  //plains near mountains
				if(r==7) chance=1;  //plains near ice
				if(r==8) chance=10; //plains near ocean
				}

			/*LIGHT FOREST*/
			if(left==3){
				if(r==1) chance=0;  //light forest near desert
				if(r==2) chance=10; //light forest near plains
				if(r==3) chance=70; //light forest near light forest
				if(r==4) chance=20; //light forest near forest
				if(r==5) chance=3; //light forest near hills
				if(r==6) chance=1;  //light forest near mountains
				if(r==7) chance=0;  //light forest near ice
				if(r==8) chance=6;  //light forest near ocean
				}

			/*FOREST*/
			if(left==4){
				if(r==1) chance=0;  //forest near desert
				if(r==2) chance=10; //forest near plains
				if(r==3) chance=20; //forest near light forest
				if(r==4) chance=70; //forest near forest
				if(r==5) chance=1;  //forest near hills
				if(r==6) chance=8;  //forest near mountains
				if(r==7) chance=0;  //forest near ice
				if(r==8) chance=1;  //forest near ocean
				}

			/*HILLS*/
			if(left==5){
				if(r==1) chance=10;  //hills near desert
				if(r==2) chance=10;  //hills near plains
				if(r==3) chance=3;   //hills near light forest
				if(r==4) chance=1;   //hills near forest
				if(r==5) chance=60;  //hills near hills
				if(r==6) chance=23;  //hills near mountains
				if(r==7) chance=1;   //hills near ice
				if(r==8) chance=2;   //hills near ocean
				}

			/*MOUNTAINS*/
			if(left==6){
				if(r==1) chance=5;   //mountains near desert
				if(r==2) chance=3;   //mountains near plains
				if(r==3) chance=1;   //mountains near light forest
				if(r==4) chance=8;   //mountains near forest
				if(r==5) chance=23;  //mountains near hills
				if(r==6) chance=57;  //mountains near mountains
				if(r==7) chance=20;  //mountains near ice
				if(r==8) chance=3;   //mountains near ocean
				}

			/*ICE*/
			if(left==7){
				if(r==1) chance=0;   //ice near desert
				if(r==2) chance=1;   //ice near plains
				if(r==3) chance=0;   //ice near light forest
				if(r==4) chance=0;   //ice near forest
				if(r==5) chance=1;   //ice near hills
				if(r==6) chance=20;  //ice near mountains
				if(r==7) chance=70;  //ice near ice
				if(r==8) chance=8;   //ice near ocean
				}
				if(r==1){
				   if((mnum==1)||(mnum==2)){
				       if(y<20) chance=0;
				       }
				   if((mnum==3)||(mnum==4)){
				       if(y>38) chance=0;
				       }
				}
				if(r==7){
				    if((mnum==1)||(mnum==2)){
					if(y>10) chance=0;
				    }
				    if((mnum==3)||(mnum==4)){
					if(y<40) chance=0;
				    }
				}

				tm=(random(100)+1);
				if(tm<=chance) chancel=1;
		}

		if(RDIR==1){
			/*OCEAN*/
			if(right==0){
				if(r==1) chance=0;  //ocean near desert
				if(r==2) chance=10; //ocean near plains
				if(r==3) chance=6; //ocean near light forest
				if(r==4) chance=1;  //ocean near forest
				if(r==5) chance=2;  //ocean near hills
				if(r==6) chance=3;  //ocean near mountains
				if(r==7) chance=8; //ocean near ice
				if(r==8) chance=75; //ocean near ocean
				if((mnum==1)||(mnum==3)){
				   if(x<20) {
				       if(r==8) chance=85; //ocean near ocean
				   }
				 }
				 if((mnum==2)||(mnum==4)){
				   if(x>65) {
				       if(r==8) chance=85; //ocean near ocean
				   }
				 }
				 if((mnum==1)||(mnum==2)){
				   if(y<=15){
				      if(r==8) chance=85;
				      }
				 }
				 if((mnum==3)||(mnum==4)){
				   if(y>=35){
				      if(r==8) chance=85;
				      }
				 }
				}
			/*DESERT*/
			if(right==1){
				if(r==1) {
					if((mnum==1)||(mnum==2)){
					   if(y>=30){
					     chance=80; //desert near desert
					     }
					   if(y<30) chance=0;
					 }
					if((mnum==3)||(mnum==4)){
					   if(y<=30) chance=80;
					   if(y>30) chance=0;
					 }
				  }
				if(r==2) chance=5;  //desert near plains
				if(r==3) chance=0;  //desert near light forest
				if(r==4) chance=0;  //desert near forest
				if(r==5) chance=10; //desert near hills
				if(r==6) chance=5;  //desert near mountains
				if(r==7) chance=0;  //desert near ice
				if(r==8) chance=0;  //desert near ocean
				}

			/*PLAINS*/
			if(right==2){
				if(r==1) chance=6;  //plains near desert
				if(r==2) chance=80; //plains near plains
				if(r==3) chance=10; //plains near light forest
				if(r==4) chance=10; //plains near forest
				if(r==5) chance=10; //plains near hills
				if(r==6) chance=3;  //plains near mountains
				if(r==7) chance=1;  //plains near ice
				if(r==8) chance=10; //plains near ocean
				}

			/*LIGHT FOREST*/
			if(right==3){
				if(r==1) chance=0;  //light forest near desert
				if(r==2) chance=10; //light forest near plains
				if(r==3) chance=70; //light forest near light forest
				if(r==4) chance=20; //light forest near forest
				if(r==5) chance=3; //light forest near hills
				if(r==6) chance=1;  //light forest near mountains
				if(r==7) chance=0;  //light forest near ice
				if(r==8) chance=6;  //light forest near ocean
				}

			/*FOREST*/
			if(right==4){
				if(r==1) chance=0;  //forest near desert
				if(r==2) chance=10; //forest near plains
				if(r==3) chance=20; //forest near light forest
				if(r==4) chance=70; //forest near forest
				if(r==5) chance=1;  //forest near hills
				if(r==6) chance=8;  //forest near mountains
				if(r==7) chance=0;  //forest near ice
				if(r==8) chance=1;  //forest near ocean
				}

			/*HILLS*/
			if(right==5){
				if(r==1) chance=10;  //hills near desert
				if(r==2) chance=10;  //hills near plains
				if(r==3) chance=3;   //hills near light forest
				if(r==4) chance=1;   //hills near forest
				if(r==5) chance=60;  //hills near hills
				if(r==6) chance=23;  //hills near mountains
				if(r==7) chance=1;   //hills near ice
				if(r==8) chance=2;   //hills near ocean
				}

			/*MOUNTAINS*/
			if(right==6){
				if(r==1) chance=5;   //mountains near desert
				if(r==2) chance=3;   //mountains near plains
				if(r==3) chance=1;   //mountains near light forest
				if(r==4) chance=8;   //mountains near forest
				if(r==5) chance=23;  //mountains near hills
				if(r==6) chance=57;  //mountains near mountains
				if(r==7) chance=20;  //mountains near ice
				if(r==8) chance=3;   //mountains near ocean
				}

			/*ICE*/
			if(right==7){
				if(r==1) chance=0;   //ice near desert
				if(r==2) chance=1;   //ice near plains
				if(r==3) chance=0;   //ice near light forest
				if(r==4) chance=0;   //ice near forest
				if(r==5) chance=1;   //ice near hills
				if(r==6) chance=20;  //ice near mountains
				if(r==7) chance=70;  //ice near ice
				if(r==8) chance=8;   //ice near ocean
				}
				if(r==1){
				   if((mnum==1)||(mnum==2)){
				       if(y<20) chance=0;
				       }
				   if((mnum==3)||(mnum==4)){
				       if(y>38) chance=0;
				       }
				}
				if(r==7){
				    if((mnum==1)||(mnum==2)){
					if(y>10) chance=0;
				    }
				    if((mnum==3)||(mnum==4)){
					if(y<40) chance=0;
				    }
				}


				tm=(random(100)+1);
				if(tm<=chance) chancer=1;

		}



			/*OCEAN*/
			if(top==0){
				if(r==1) chance=0;  //ocean near desert
				if(r==2) chance=10; //ocean near plains
				if(r==3) chance=6; //ocean near light forest
				if(r==4) chance=1;  //ocean near forest
				if(r==5) chance=2;  //ocean near hills
				if(r==6) chance=3;  //ocean near mountains
				if(r==7) chance=8; //ocean near ice
				if(r==8) chance=75; //ocean near ocean
				if((mnum==1)||(mnum==3)){
				   if(x<20) {
				       if(r==8) chance=85; //ocean near ocean
				   }
				 }
				 if((mnum==2)||(mnum==4)){
				   if(x>65) {
				       if(r==8) chance=85; //ocean near ocean
				   }
				 }
				 if((mnum==1)||(mnum==2)){
				   if(y<=15){
				      if(r==8) chance=85;
				      }
				 }
				 if((mnum==3)||(mnum==4)){
				   if(y>=35){
				      if(r==8) chance=85;
				      }
				 }
				}
			/*DESERT*/
			if(top==1){
				if(r==1) {
					if((mnum==1)||(mnum==2)){
					   if(y>=30){
					     chance=80; //desert near desert
					     }
					   if(y<30) chance=0;
					 }
					if((mnum==3)||(mnum==4)){
					   if(y<=30) chance=80;
					   if(y>30) chance=0;
					 }
				  }
				if(r==2) chance=5;  //desert near plains
				if(r==3) chance=0;  //desert near light forest
				if(r==4) chance=0;  //desert near forest
				if(r==5) chance=10; //desert near hills
				if(r==6) chance=5;  //desert near mountains
				if(r==7) chance=0;  //desert near ice
				if(r==8) chance=0;  //desert near ocean
				}

			/*PLAINS*/
			if(top==2){
				if(r==1) chance=6;  //plains near desert
				if(r==2) chance=80; //plains near plains
				if(r==3) chance=10; //plains near light forest
				if(r==4) chance=10; //plains near forest
				if(r==5) chance=10; //plains near hills
				if(r==6) chance=3;  //plains near mountains
				if(r==7) chance=1;  //plains near ice
				if(r==8) chance=10; //plains near ocean
				}

			/*LIGHT FOREST*/
			if(top==3){
				if(r==1) chance=0;  //light forest near desert
				if(r==2) chance=10; //light forest near plains
				if(r==3) chance=70; //light forest near light forest
				if(r==4) chance=20; //light forest near forest
				if(r==5) chance=3; //light forest near hills
				if(r==6) chance=1;  //light forest near mountains
				if(r==7) chance=0;  //light forest near ice
				if(r==8) chance=6;  //light forest near ocean
				}

			/*FOREST*/
			if(top==4){
				if(r==1) chance=0;  //forest near desert
				if(r==2) chance=10; //forest near plains
				if(r==3) chance=20; //forest near light forest
				if(r==4) chance=70; //forest near forest
				if(r==5) chance=1;  //forest near hills
				if(r==6) chance=8;  //forest near mountains
				if(r==7) chance=0;  //forest near ice
				if(r==8) chance=1;  //forest near ocean
				}

			/*HILLS*/
			if(top==5){
				if(r==1) chance=10;  //hills near desert
				if(r==2) chance=10;  //hills near plains
				if(r==3) chance=3;   //hills near light forest
				if(r==4) chance=1;   //hills near forest
				if(r==5) chance=60;  //hills near hills
				if(r==6) chance=23;  //hills near mountains
				if(r==7) chance=1;   //hills near ice
				if(r==8) chance=2;   //hills near ocean
				}

			/*MOUNTAINS*/
			if(top==6){
				if(r==1) chance=5;   //mountains near desert
				if(r==2) chance=3;   //mountains near plains
				if(r==3) chance=1;   //mountains near light forest
				if(r==4) chance=8;   //mountains near forest
				if(r==5) chance=23;  //mountains near hills
				if(r==6) chance=57;  //mountains near mountains
				if(r==7) chance=20;  //mountains near ice
				if(r==8) chance=3;   //mountains near ocean
				}

			/*ICE*/
			if(top==7){
				if(r==1) chance=0;   //ice near desert
				if(r==2) chance=1;   //ice near plains
				if(r==3) chance=0;   //ice near light forest
				if(r==4) chance=0;   //ice near forest
				if(r==5) chance=1;   //ice near hills
				if(r==6) chance=20;  //ice near mountains
				if(r==7) chance=70;  //ice near ice
				if(r==8) chance=8;   //ice near ocean
				}
				if(r==1){
				   if((mnum==1)||(mnum==2)){
				       if(y<20) chance=0;
				       }
				   if((mnum==3)||(mnum==4)){
				       if(y>38) chance=0;
				       }
				}
				if(r==7){
				    if((mnum==1)||(mnum==2)){
					if(y>10) chance=0;
				    }
				    if((mnum==3)||(mnum==4)){
					if(y<40) chance=0;
				    }
				}
				/*if(r==8){
					if(x>75) chance=chance+15;
					if(y>34) chance=chance+10;
					}   */
				tm=(random(100)+1);
				if(tm<=chance) chancet=1;

			/*OCEAN*/
			if(topr==0){
				if(r==1) chance=0;  //ocean near desert
				if(r==2) chance=10; //ocean near plains
				if(r==3) chance=6; //ocean near light forest
				if(r==4) chance=1;  //ocean near forest
				if(r==5) chance=2;  //ocean near hills
				if(r==6) chance=3;  //ocean near mountains
				if(r==7) chance=8; //ocean near ice
				if(r==8) chance=75; //ocean near ocean
				if((mnum==1)||(mnum==3)){
				   if(x<20) {
				       if(r==8) chance=85; //ocean near ocean
				   }
				 }
				 if((mnum==2)||(mnum==4)){
				   if(x>65) {
				       if(r==8) chance=85; //ocean near ocean
				   }
				 }
				 if((mnum==1)||(mnum==2)){
				   if(y<=15){
				      if(r==8) chance=85;
				      }
				 }
				 if((mnum==3)||(mnum==4)){
				   if(y>=35){
				      if(r==8) chance=85;
				      }
				 }
				}
			/*DESERT*/
			if(topr==1){
				if(r==1) {
					if((mnum==1)||(mnum==2)){
					   if(y>=30){
					     chance=80; //desert near desert
					     }
					   if(y<30) chance=0;
					 }
					if((mnum==3)||(mnum==4)){
					   if(y<=30) chance=80;
					   if(y>30) chance=0;
					 }
				  }
				if(r==2) chance=5;  //desert near plains
				if(r==3) chance=0;  //desert near light forest
				if(r==4) chance=0;  //desert near forest
				if(r==5) chance=10; //desert near hills
				if(r==6) chance=5;  //desert near mountains
				if(r==7) chance=0;  //desert near ice
				if(r==8) chance=0;  //desert near ocean
				}

			/*PLAINS*/
			if(topr==2){
				if(r==1) chance=6;  //plains near desert
				if(r==2) chance=80; //plains near plains
				if(r==3) chance=10; //plains near light forest
				if(r==4) chance=10; //plains near forest
				if(r==5) chance=10; //plains near hills
				if(r==6) chance=3;  //plains near mountains
				if(r==7) chance=1;  //plains near ice
				if(r==8) chance=10; //plains near ocean
				}

			/*LIGHT FOREST*/
			if(topr==3){
				if(r==1) chance=0;  //light forest near desert
				if(r==2) chance=10; //light forest near plains
				if(r==3) chance=70; //light forest near light forest
				if(r==4) chance=20; //light forest near forest
				if(r==5) chance=3; //light forest near hills
				if(r==6) chance=1;  //light forest near mountains
				if(r==7) chance=0;  //light forest near ice
				if(r==8) chance=6;  //light forest near ocean
				}

			/*FOREST*/
			if(topr==4){
				if(r==1) chance=0;  //forest near desert
				if(r==2) chance=10; //forest near plains
				if(r==3) chance=20; //forest near light forest
				if(r==4) chance=70; //forest near forest
				if(r==5) chance=1;  //forest near hills
				if(r==6) chance=8;  //forest near mountains
				if(r==7) chance=0;  //forest near ice
				if(r==8) chance=1;  //forest near ocean
				}

			/*HILLS*/
			if(topr==5){
				if(r==1) chance=10;  //hills near desert
				if(r==2) chance=10;  //hills near plains
				if(r==3) chance=3;   //hills near light forest
				if(r==4) chance=1;   //hills near forest
				if(r==5) chance=70;  //hills near hills
				if(r==6) chance=23;  //hills near mountains
				if(r==7) chance=1;   //hills near ice
				if(r==8) chance=2;   //hills near ocean
				}

			/*MOUNTAINS*/
			if(topr==6){
				if(r==1) chance=5;   //mountains near desert
				if(r==2) chance=3;   //mountains near plains
				if(r==3) chance=1;   //mountains near light forest
				if(r==4) chance=8;   //mountains near forest
				if(r==5) chance=23;  //mountains near hills
				if(r==6) chance=57;  //mountains near mountains
				if(r==7) chance=20;  //mountains near ice
				if(r==8) chance=3;   //mountains near ocean
				}

			/*ICE*/
			if(topr==7){
				if(r==1) chance=0;   //ice near desert
				if(r==2) chance=1;   //ice near plains
				if(r==3) chance=0;   //ice near light forest
				if(r==4) chance=0;   //ice near forest
				if(r==5) chance=1;   //ice near hills
				if(r==6) chance=20;  //ice near mountains
				if(r==7) chance=70;  //ice near ice
				if(r==8) chance=8;   //ice near ocean
				}
				if(r==1){
				   if((mnum==1)||(mnum==2)){
				       if(y<20) chance=0;
				       }
				   if((mnum==3)||(mnum==4)){
				       if(y>38) chance=0;
				       }
				}
				if(r==7){
				    if((mnum==1)||(mnum==2)){
					if(y>10) chance=0;
				    }
				    if((mnum==3)||(mnum==4)){
					if(y<40) chance=0;
				    }
				}

				tm=(random(100)+1);
				if(tm<=chance) chancetr=1;
			/*OCEAN*/
			if(topl==0){
				if(r==1) chance=0;  //ocean near desert
				if(r==2) chance=10; //ocean near plains
				if(r==3) chance=6; //ocean near light forest
				if(r==4) chance=1;  //ocean near forest
				if(r==5) chance=2;  //ocean near hills
				if(r==6) chance=3;  //ocean near mountains
				if(r==7) chance=8; //ocean near ice
				if(r==8) chance=75; //ocean near ocean
				if((mnum==1)||(mnum==3)){
				   if(x<20) {
				       if(r==8) chance=85; //ocean near ocean
				   }
				 }
				 if((mnum==2)||(mnum==4)){
				   if(x>65) {
				       if(r==8) chance=85; //ocean near ocean
				   }
				 }
				 if((mnum==1)||(mnum==2)){
				   if(y<=15){
				      if(r==8) chance=85;
				      }
				 }
				 if((mnum==3)||(mnum==4)){
				   if(y>=35){
				      if(r==8) chance=85;
				      }
				 }
			}
			/*DESERT*/
			if(topl==1){
				if(r==1) {
					if((mnum==1)||(mnum==2)){
					   if(y>=30){
					     chance=80; //desert near desert
					     }
					   if(y<30) chance=0;
					 }
					if((mnum==3)||(mnum==4)){
					   if(y<=30) chance=80;
					   if(y>30) chance=0;
					 }
				  }
				if(r==2) chance=5;  //desert near plains
				if(r==3) chance=0;  //desert near light forest
				if(r==4) chance=0;  //desert near forest
				if(r==5) chance=10; //desert near hills
				if(r==6) chance=5;  //desert near mountains
				if(r==7) chance=0;  //desert near ice
				if(r==8) chance=0;  //desert near ocean
				}

			/*PLAINS*/
			if(topl==2){
				if(r==1) chance=6;  //plains near desert
				if(r==2) chance=80; //plains near plains
				if(r==3) chance=10; //plains near light forest
				if(r==4) chance=10; //plains near forest
				if(r==5) chance=10; //plains near hills
				if(r==6) chance=3;  //plains near mountains
				if(r==7) chance=1;  //plains near ice
				if(r==8) chance=10; //plains near ocean
				}

			/*LIGHT FOREST*/
			if(topl==3){
				if(r==1) chance=0;  //light forest near desert
				if(r==2) chance=10; //light forest near plains
				if(r==3) chance=70; //light forest near light forest
				if(r==4) chance=20; //light forest near forest
				if(r==5) chance=3; //light forest near hills
				if(r==6) chance=1;  //light forest near mountains
				if(r==7) chance=0;  //light forest near ice
				if(r==8) chance=6;  //light forest near ocean
				}

			/*FOREST*/
			if(topl==4){
				if(r==1) chance=0;  //forest near desert
				if(r==2) chance=10; //forest near plains
				if(r==3) chance=20; //forest near light forest
				if(r==4) chance=70; //forest near forest
				if(r==5) chance=1;  //forest near hills
				if(r==6) chance=8;  //forest near mountains
				if(r==7) chance=0;  //forest near ice
				if(r==8) chance=1;  //forest near ocean
				}

			/*HILLS*/
			if(topl==5){
				if(r==1) chance=10;  //hills near desert
				if(r==2) chance=10;  //hills near plains
				if(r==3) chance=3;   //hills near light forest
				if(r==4) chance=1;   //hills near forest
				if(r==5) chance=60;  //hills near hills
				if(r==6) chance=23;  //hills near mountains
				if(r==7) chance=1;   //hills near ice
				if(r==8) chance=2;   //hills near ocean
				}

			/*MOUNTAINS*/
			if(topl==6){
				if(r==1) chance=5;   //mountains near desert
				if(r==2) chance=3;   //mountains near plains
				if(r==3) chance=1;   //mountains near light forest
				if(r==4) chance=8;   //mountains near forest
				if(r==5) chance=23;  //mountains near hills
				if(r==6) chance=57;  //mountains near mountains
				if(r==7) chance=20;  //mountains near ice
				if(r==8) chance=3;   //mountains near ocean
				}

			/*ICE*/
			if(topl==7){
				if(r==1) chance=0;   //ice near desert
				if(r==2) chance=1;   //ice near plains
				if(r==3) chance=0;   //ice near light forest
				if(r==4) chance=0;   //ice near forest
				if(r==5) chance=1;   //ice near hills
				if(r==6) chance=20;  //ice near mountains
				if(r==7) chance=70;  //ice near ice
				if(r==8) chance=10;   //ice near ocean
				}
				if(r==1){
				   if((mnum==1)||(mnum==2)){
				       if(y<20) chance=0;
				       }
				   if((mnum==3)||(mnum==4)){
				       if(y>38) chance=0;
				       }
				}
				if(r==7){
				    if((mnum==1)||(mnum==2)){
					if(y>10) chance=0;
				    }
				    if((mnum==3)||(mnum==4)){
					if(y<40) chance=0;
				    }
				}
				tm=(random(100)+1);
				if(tm<=chance) chancetl=1;
				if(LDIR==0) chancel=1;
				if(RDIR==0) chancer=1;
				if((chancet==1)&&(chancel==1)&&
				  (chancetr==1)&&(chancetl==1)&&
				  (chancer==1)) break;
		      }
		      chancet=0;
		      chancel=0;
		      chancetr=0;
		      chancetl=0;
		      chancer=0;
		      if((mnum==2)||(mnum==4)){
			if(x>75) r=8;
			}
		      if(r==8) r=0;
		      MAP[x][y]=r;

		}

	}
return;
}

void makemapr(int mnum)
{
extern int LDIR;
extern int RDIR;

extern int MAP[81][51];
	int r;                //random number
	int x,y;              //temp location
	int t,chance;         //temp
	int left;             //temp left variable
	int top;              //temp top variable
	int topr;             //temp top right variable
	int topl;             //temp top left variable
	int right;
	int bottom;
	int chancel,chancet,chancetr,chancetl,chancer,chanceb;  //1=yes 0=no
	int tm;               //temp variable
	int z;
	int MAP1r[52];
	int MAP3r[52];
	int MAP2b[82];
	int MAP1b[82];

	FILE *tempload;
	LDIR=1;
	RDIR=0;

	x=0;
	y=0;
   if(mnum==2) {
		tempload=fopen("temp\\map1r.dat","rb");
			for(y=1;y<=50;y++){
			fread(&MAP1r[y],sizeof(int),1,tempload);
			}
			fclose(tempload);
		}
   if(mnum==3) {
		tempload=fopen("temp\\map1b.dat","rb");
			for(t=1;t<=80;t++){
			fread(&MAP1b[t],sizeof(int),1,tempload);
			}
			fclose(tempload);
		}
   if(mnum==4) {
		tempload=fopen("temp\\map3r.dat","rb");
			for(y=1;y<=50;y++){
			fread(&MAP3r[y],sizeof(int),1,tempload);
			}
			fclose(tempload);
		tempload=fopen("temp\\map2b.dat","rb");
			for(t=1;t<=80;t++){
			fread(&MAP2b[t],sizeof(int),1,tempload);
			}
			fclose(tempload);
		}


   for(y=50;y>=1;y--){

      for(t=1;t<=80;t++){
	if(LDIR==1) x++;
	if(x>80) {RDIR=1;LDIR=0;}
	if(RDIR==1) x--;
	if(x<1) {LDIR=1;RDIR=0;x=1;}

		      for(;;){
			chancel=0;
			chancet=0;
			r=(random(8)+1);
			if(mnum==1) left=MAP[x-1][y];
			if((mnum==2)&&(x<=1)) left=MAP1r[y];
			if((mnum==2)&&(x>1)) left=MAP[x-1][y];
			if(mnum==3) left=MAP[x-1][y];
			if((mnum==4)&&(x<=1)) left=MAP3r[y];
			if((mnum==4)&&(x>1)) left=MAP[x-1][y];
			if(mnum==1) top=MAP[x][y-1];
			if(mnum==2) top=MAP[x][y-1];
			if((mnum==3)&&(y<=1)) top=MAP1b[x];
			if((mnum==3)&&(y>1)) top=MAP[x][y-1];
			if((mnum==4)&&(y<=1)) top=MAP2b[x];
			if((mnum==4)&&(y>1)) top=MAP[x][y-1];
			if((mnum==3)&&(y<=1)) topr=MAP1b[x+1];
			if((mnum==3)&&(y>1)) topr=MAP[x+1][y-1];
			if((mnum==4)&&(y<=1)) topr=MAP2b[x+1];
			if((mnum==4)&&(y>1)) topr=MAP[x+1][y-1];
			if((mnum==1)||(mnum==2)) topr=MAP[x+1][y-1];
			if((mnum==3)&&(y<=1)) topl=MAP1b[x-1];
			if((mnum==3)&&(y>1)) topl=MAP[x-1][y-1];
			if((mnum==4)&&(y<=1)) topl=MAP2b[x-1];
			if((mnum==4)&&(y>1)) topl=MAP[x-1][y-1];
			if((mnum==1)||(mnum==2)) topl=MAP[x-1][y-1];
			right=MAP[x+1][y];
			bottom=MAP[x][y+1];

			/*OCEAN*/
			if(left==0){
				if(r==1) chance=0;  //ocean near desert
				if(r==2) chance=10; //ocean near plains
				if(r==3) chance=6; //ocean near light forest
				if(r==4) chance=1;  //ocean near forest
				if(r==5) chance=2;  //ocean near hills
				if(r==6) chance=3;  //ocean near mountains
				if(r==7) chance=8; //ocean near ice
				if(r==8) chance=75; //ocean near ocean
				if((mnum==1)||(mnum==3)){
				   if(x<20) {
				       if(r==8) chance=85; //ocean near ocean
				   }
				 }
				 if((mnum==2)||(mnum==4)){
				   if(x>65) {
				       if(r==8) chance=85; //ocean near ocean
				   }
				 }
				 if((mnum==1)||(mnum==2)){
				   if(y<=15){
				      if(r==8) chance=85;
				      }
				 }
				 if((mnum==3)||(mnum==4)){
				   if(y>=35){
				      if(r==8) chance=85;
				      }
				 }
			}
			/*DESERT*/
			if(left==1){
				if(r==1) {
					if((mnum==1)||(mnum==2)){
					   if(y>=30){
					     chance=80; //desert near desert
					     }
					   if(y<30) chance=0;
					 }
					if((mnum==3)||(mnum==4)){
					   if(y<=30) chance=80;
					   if(y>30) chance=0;
					 }
				  }
				if(r==2) chance=5;  //desert near plains
				if(r==3) chance=0;  //desert near light forest
				if(r==4) chance=0;  //desert near forest
				if(r==5) chance=10; //desert near hills
				if(r==6) chance=5;  //desert near mountains
				if(r==7) chance=0;  //desert near ice
				if(r==8) chance=0;  //desert near ocean
				}

			/*PLAINS*/
			if(left==2){
				if(r==1) chance=6;  //plains near desert
				if(r==2) chance=80; //plains near plains
				if(r==3) chance=10; //plains near light forest
				if(r==4) chance=10; //plains near forest
				if(r==5) chance=10; //plains near hills
				if(r==6) chance=3;  //plains near mountains
				if(r==7) chance=1;  //plains near ice
				if(r==8) chance=10; //plains near ocean
				}

			/*LIGHT FOREST*/
			if(left==3){
				if(r==1) chance=0;  //light forest near desert
				if(r==2) chance=10; //light forest near plains
				if(r==3) chance=70; //light forest near light forest
				if(r==4) chance=20; //light forest near forest
				if(r==5) chance=3; //light forest near hills
				if(r==6) chance=1;  //light forest near mountains
				if(r==7) chance=0;  //light forest near ice
				if(r==8) chance=6;  //light forest near ocean
				}

			/*FOREST*/
			if(left==4){
				if(r==1) chance=0;  //forest near desert
				if(r==2) chance=10; //forest near plains
				if(r==3) chance=20; //forest near light forest
				if(r==4) chance=70; //forest near forest
				if(r==5) chance=1;  //forest near hills
				if(r==6) chance=8;  //forest near mountains
				if(r==7) chance=0;  //forest near ice
				if(r==8) chance=1;  //forest near ocean
				}

			/*HILLS*/
			if(left==5){
				if(r==1) chance=10;  //hills near desert
				if(r==2) chance=10;  //hills near plains
				if(r==3) chance=3;   //hills near light forest
				if(r==4) chance=1;   //hills near forest
				if(r==5) chance=60;  //hills near hills
				if(r==6) chance=23;  //hills near mountains
				if(r==7) chance=1;   //hills near ice
				if(r==8) chance=2;   //hills near ocean
				}

			/*MOUNTAINS*/
			if(left==6){
				if(r==1) chance=5;   //mountains near desert
				if(r==2) chance=3;   //mountains near plains
				if(r==3) chance=1;   //mountains near light forest
				if(r==4) chance=8;   //mountains near forest
				if(r==5) chance=23;  //mountains near hills
				if(r==6) chance=57;  //mountains near mountains
				if(r==7) chance=20;  //mountains near ice
				if(r==8) chance=3;   //mountains near ocean
				}

			/*ICE*/
			if(left==7){
				if(r==1) chance=0;   //ice near desert
				if(r==2) chance=1;   //ice near plains
				if(r==3) chance=0;   //ice near light forest
				if(r==4) chance=0;   //ice near forest
				if(r==5) chance=1;   //ice near hills
				if(r==6) chance=20;  //ice near mountains
				if(r==7) chance=70;  //ice near ice
				if(r==8) chance=8;   //ice near ocean
				}
				if(r==1){
				   if((mnum==1)||(mnum==2)){
				       if(y<20) chance=0;
				       }
				   if((mnum==3)||(mnum==4)){
				       if(y>38) chance=0;
				       }
				}
				if(r==7){
				    if((mnum==1)||(mnum==2)){
					if(y>10) chance=0;
				    }
				    if((mnum==3)||(mnum==4)){
					if(y<40) chance=0;
				    }
				}

				tm=(random(100)+1);
				if(tm<=chance) chancel=1;



			/*OCEAN*/
			if(right==0){
				if(r==1) chance=0;  //ocean near desert
				if(r==2) chance=10; //ocean near plains
				if(r==3) chance=6; //ocean near light forest
				if(r==4) chance=1;  //ocean near forest
				if(r==5) chance=2;  //ocean near hills
				if(r==6) chance=3;  //ocean near mountains
				if(r==7) chance=8; //ocean near ice
				if(r==8) chance=75; //ocean near ocean
				if((mnum==1)||(mnum==3)){
				   if(x<20) {
				       if(r==8) chance=85; //ocean near ocean
				   }
				 }
				 if((mnum==2)||(mnum==4)){
				   if(x>65) {
				       if(r==8) chance=85; //ocean near ocean
				   }
				 }
				 if((mnum==1)||(mnum==2)){
				   if(y<=15){
				      if(r==8) chance=85;
				      }
				 }
				 if((mnum==3)||(mnum==4)){
				   if(y>=35){
				      if(r==8) chance=85;
				      }
				 }
			}
			/*DESERT*/
			if(right==1){
				if(r==1) {
					if((mnum==1)||(mnum==2)){
					   if(y>=30){
					     chance=80; //desert near desert
					     }
					   if(y<30) chance=0;
					 }
					if((mnum==3)||(mnum==4)){
					   if(y<=30) chance=80;
					   if(y>30) chance=0;
					 }
				  }
				if(r==2) chance=5;  //desert near plains
				if(r==3) chance=0;  //desert near light forest
				if(r==4) chance=0;  //desert near forest
				if(r==5) chance=10; //desert near hills
				if(r==6) chance=5;  //desert near mountains
				if(r==7) chance=0;  //desert near ice
				if(r==8) chance=0;  //desert near ocean
				}

			/*PLAINS*/
			if(right==2){
				if(r==1) chance=6;  //plains near desert
				if(r==2) chance=80; //plains near plains
				if(r==3) chance=10; //plains near light forest
				if(r==4) chance=10; //plains near forest
				if(r==5) chance=10; //plains near hills
				if(r==6) chance=3;  //plains near mountains
				if(r==7) chance=1;  //plains near ice
				if(r==8) chance=10; //plains near ocean
				}

			/*LIGHT FOREST*/
			if(right==3){
				if(r==1) chance=0;  //light forest near desert
				if(r==2) chance=10; //light forest near plains
				if(r==3) chance=70; //light forest near light forest
				if(r==4) chance=20; //light forest near forest
				if(r==5) chance=3; //light forest near hills
				if(r==6) chance=1;  //light forest near mountains
				if(r==7) chance=0;  //light forest near ice
				if(r==8) chance=6;  //light forest near ocean
				}

			/*FOREST*/
			if(right==4){
				if(r==1) chance=0;  //forest near desert
				if(r==2) chance=10; //forest near plains
				if(r==3) chance=20; //forest near light forest
				if(r==4) chance=70; //forest near forest
				if(r==5) chance=1;  //forest near hills
				if(r==6) chance=8;  //forest near mountains
				if(r==7) chance=0;  //forest near ice
				if(r==8) chance=1;  //forest near ocean
				}

			/*HILLS*/
			if(right==5){
				if(r==1) chance=10;  //hills near desert
				if(r==2) chance=10;  //hills near plains
				if(r==3) chance=3;   //hills near light forest
				if(r==4) chance=1;   //hills near forest
				if(r==5) chance=60;  //hills near hills
				if(r==6) chance=23;  //hills near mountains
				if(r==7) chance=1;   //hills near ice
				if(r==8) chance=2;   //hills near ocean
				}

			/*MOUNTAINS*/
			if(right==6){
				if(r==1) chance=5;   //mountains near desert
				if(r==2) chance=3;   //mountains near plains
				if(r==3) chance=1;   //mountains near light forest
				if(r==4) chance=8;   //mountains near forest
				if(r==5) chance=23;  //mountains near hills
				if(r==6) chance=57;  //mountains near mountains
				if(r==7) chance=20;  //mountains near ice
				if(r==8) chance=3;   //mountains near ocean
				}

			/*ICE*/
			if(right==7){
				if(r==1) chance=0;   //ice near desert
				if(r==2) chance=1;   //ice near plains
				if(r==3) chance=0;   //ice near light forest
				if(r==4) chance=0;   //ice near forest
				if(r==5) chance=1;   //ice near hills
				if(r==6) chance=20;  //ice near mountains
				if(r==7) chance=70;  //ice near ice
				if(r==8) chance=8;   //ice near ocean
				}
				if(r==1){
				   if((mnum==1)||(mnum==2)){
				       if(y<20) chance=0;
				       }
				   if((mnum==3)||(mnum==4)){
				       if(y>38) chance=0;
				       }
				}
				if(r==7){
				    if((mnum==1)||(mnum==2)){
					if(y>10) chance=0;
				    }
				    if((mnum==3)||(mnum==4)){
					if(y<40) chance=0;
				    }
				}

				tm=(random(100)+1);
				if(tm<=chance) chancer=1;





			/*OCEAN*/
			if(top==0){
				if(r==1) chance=0;  //ocean near desert
				if(r==2) chance=10; //ocean near plains
				if(r==3) chance=6; //ocean near light forest
				if(r==4) chance=1;  //ocean near forest
				if(r==5) chance=2;  //ocean near hills
				if(r==6) chance=3;  //ocean near mountains
				if(r==7) chance=8; //ocean near ice
				if(r==8) chance=75; //ocean near ocean
				if((mnum==1)||(mnum==3)){
				   if(x<20) {
				       if(r==8) chance=85; //ocean near ocean
				   }
				 }
				 if((mnum==2)||(mnum==4)){
				   if(x>65) {
				       if(r==8) chance=85; //ocean near ocean
				   }
				 }
				 if((mnum==1)||(mnum==2)){
				   if(y<=15){
				      if(r==8) chance=85;
				      }
				 }
				 if((mnum==3)||(mnum==4)){
				   if(y>=35){
				      if(r==8) chance=85;
				      }
				 }
			}
			/*DESERT*/
			if(top==1){
				if(r==1) {
					if((mnum==1)||(mnum==2)){
					   if(y>=30){
					     chance=80; //desert near desert
					     }
					   if(y<30) chance=0;
					 }
					if((mnum==3)||(mnum==4)){
					   if(y<=30) chance=80;
					   if(y>30) chance=0;
					 }
				  }
				if(r==2) chance=5;  //desert near plains
				if(r==3) chance=0;  //desert near light forest
				if(r==4) chance=0;  //desert near forest
				if(r==5) chance=10; //desert near hills
				if(r==6) chance=5;  //desert near mountains
				if(r==7) chance=0;  //desert near ice
				if(r==8) chance=0;  //desert near ocean
				}

			/*PLAINS*/
			if(top==2){
				if(r==1) chance=6;  //plains near desert
				if(r==2) chance=80; //plains near plains
				if(r==3) chance=10; //plains near light forest
				if(r==4) chance=10; //plains near forest
				if(r==5) chance=10; //plains near hills
				if(r==6) chance=3;  //plains near mountains
				if(r==7) chance=1;  //plains near ice
				if(r==8) chance=10; //plains near ocean
				}

			/*LIGHT FOREST*/
			if(top==3){
				if(r==1) chance=0;  //light forest near desert
				if(r==2) chance=10; //light forest near plains
				if(r==3) chance=70; //light forest near light forest
				if(r==4) chance=20; //light forest near forest
				if(r==5) chance=3; //light forest near hills
				if(r==6) chance=1;  //light forest near mountains
				if(r==7) chance=0;  //light forest near ice
				if(r==8) chance=6;  //light forest near ocean
				}

			/*FOREST*/
			if(top==4){
				if(r==1) chance=0;  //forest near desert
				if(r==2) chance=10; //forest near plains
				if(r==3) chance=20; //forest near light forest
				if(r==4) chance=70; //forest near forest
				if(r==5) chance=1;  //forest near hills
				if(r==6) chance=8;  //forest near mountains
				if(r==7) chance=0;  //forest near ice
				if(r==8) chance=1;  //forest near ocean
				}

			/*HILLS*/
			if(top==5){
				if(r==1) chance=10;  //hills near desert
				if(r==2) chance=10;  //hills near plains
				if(r==3) chance=3;   //hills near light forest
				if(r==4) chance=1;   //hills near forest
				if(r==5) chance=60;  //hills near hills
				if(r==6) chance=23;  //hills near mountains
				if(r==7) chance=1;   //hills near ice
				if(r==8) chance=2;   //hills near ocean
				}

			/*MOUNTAINS*/
			if(top==6){
				if(r==1) chance=5;   //mountains near desert
				if(r==2) chance=3;   //mountains near plains
				if(r==3) chance=1;   //mountains near light forest
				if(r==4) chance=8;   //mountains near forest
				if(r==5) chance=23;  //mountains near hills
				if(r==6) chance=57;  //mountains near mountains
				if(r==7) chance=20;  //mountains near ice
				if(r==8) chance=3;   //mountains near ocean
				}

			/*ICE*/
			if(top==7){
				if(r==1) chance=0;   //ice near desert
				if(r==2) chance=1;   //ice near plains
				if(r==3) chance=0;   //ice near light forest
				if(r==4) chance=0;   //ice near forest
				if(r==5) chance=1;   //ice near hills
				if(r==6) chance=20;  //ice near mountains
				if(r==7) chance=70;  //ice near ice
				if(r==8) chance=8;   //ice near ocean
				}
				if(r==1){
				   if((mnum==1)||(mnum==2)){
				       if(y<20) chance=0;
				       }
				   if((mnum==3)||(mnum==4)){
				       if(y>38) chance=0;
				       }
				}
				if(r==7){
				    if((mnum==1)||(mnum==2)){
					if(y>10) chance=0;
				    }
				    if((mnum==3)||(mnum==4)){
					if(y<40) chance=0;
				    }
				}


				tm=(random(100)+1);
				if(tm<=chance) chancet=1;

			/*OCEAN*/
			if(topr==0){
				if(r==1) chance=0;  //ocean near desert
				if(r==2) chance=10; //ocean near plains
				if(r==3) chance=6; //ocean near light forest
				if(r==4) chance=1;  //ocean near forest
				if(r==5) chance=2;  //ocean near hills
				if(r==6) chance=3;  //ocean near mountains
				if(r==7) chance=8; //ocean near ice
				if(r==8) chance=75; //ocean near ocean
				if((mnum==1)||(mnum==3)){
				   if(x<20) {
				       if(r==8) chance=85; //ocean near ocean
				   }
				 }
				 if((mnum==2)||(mnum==4)){
				   if(x>65) {
				       if(r==8) chance=85; //ocean near ocean
				   }
				 }
				 if((mnum==1)||(mnum==2)){
				   if(y<=15){
				      if(r==8) chance=85;
				      }
				 }
				 if((mnum==3)||(mnum==4)){
				   if(y>=35){
				      if(r==8) chance=85;
				      }
				 }
			}
			/*DESERT*/
			if(topr==1){
				if(r==1) {
					if((mnum==1)||(mnum==2)){
					   if(y>=30){
					     chance=80; //desert near desert
					     }
					   if(y<30) chance=0;
					 }
					if((mnum==3)||(mnum==4)){
					   if(y<=30) chance=80;
					   if(y>30) chance=0;
					 }
				  }
				if(r==2) chance=5;  //desert near plains
				if(r==3) chance=0;  //desert near light forest
				if(r==4) chance=0;  //desert near forest
				if(r==5) chance=10; //desert near hills
				if(r==6) chance=5;  //desert near mountains
				if(r==7) chance=0;  //desert near ice
				if(r==8) chance=0;  //desert near ocean
				}

			/*PLAINS*/
			if(topr==2){
				if(r==1) chance=6;  //plains near desert
				if(r==2) chance=80; //plains near plains
				if(r==3) chance=10; //plains near light forest
				if(r==4) chance=10; //plains near forest
				if(r==5) chance=10; //plains near hills
				if(r==6) chance=3;  //plains near mountains
				if(r==7) chance=1;  //plains near ice
				if(r==8) chance=10; //plains near ocean
				}

			/*LIGHT FOREST*/
			if(topr==3){
				if(r==1) chance=0;  //light forest near desert
				if(r==2) chance=10; //light forest near plains
				if(r==3) chance=70; //light forest near light forest
				if(r==4) chance=20; //light forest near forest
				if(r==5) chance=3; //light forest near hills
				if(r==6) chance=1;  //light forest near mountains
				if(r==7) chance=0;  //light forest near ice
				if(r==8) chance=6;  //light forest near ocean
				}

			/*FOREST*/
			if(topr==4){
				if(r==1) chance=0;  //forest near desert
				if(r==2) chance=10; //forest near plains
				if(r==3) chance=20; //forest near light forest
				if(r==4) chance=70; //forest near forest
				if(r==5) chance=1;  //forest near hills
				if(r==6) chance=8;  //forest near mountains
				if(r==7) chance=0;  //forest near ice
				if(r==8) chance=1;  //forest near ocean
				}

			/*HILLS*/
			if(topr==5){
				if(r==1) chance=10;  //hills near desert
				if(r==2) chance=10;  //hills near plains
				if(r==3) chance=3;   //hills near light forest
				if(r==4) chance=1;   //hills near forest
				if(r==5) chance=60;  //hills near hills
				if(r==6) chance=23;  //hills near mountains
				if(r==7) chance=1;   //hills near ice
				if(r==8) chance=2;   //hills near ocean
				}

			/*MOUNTAINS*/
			if(topr==6){
				if(r==1) chance=5;   //mountains near desert
				if(r==2) chance=3;   //mountains near plains
				if(r==3) chance=1;   //mountains near light forest
				if(r==4) chance=8;   //mountains near forest
				if(r==5) chance=23;  //mountains near hills
				if(r==6) chance=57;  //mountains near mountains
				if(r==7) chance=20;  //mountains near ice
				if(r==8) chance=3;   //mountains near ocean
				}

			/*ICE*/
			if(topr==7){
				if(r==1) chance=0;   //ice near desert
				if(r==2) chance=1;   //ice near plains
				if(r==3) chance=0;   //ice near light forest
				if(r==4) chance=0;   //ice near forest
				if(r==5) chance=1;   //ice near hills
				if(r==6) chance=20;  //ice near mountains
				if(r==7) chance=70;  //ice near ice
				if(r==8) chance=8;   //ice near ocean
				}
				if(r==1){
				   if((mnum==1)||(mnum==2)){
				       if(y<20) chance=0;
				       }
				   if((mnum==3)||(mnum==4)){
				       if(y>38) chance=0;
				       }
				}
				if(r==7){
				    if((mnum==1)||(mnum==2)){
					if(y>10) chance=0;
				    }
				    if((mnum==3)||(mnum==4)){
					if(y<40) chance=0;
				    }
				}

				tm=(random(100)+1);
				if(tm<=chance) chancetr=1;

			/*OCEAN*/
			if(bottom==0){
				if(r==1) chance=0;  //ocean near desert
				if(r==2) chance=10; //ocean near plains
				if(r==3) chance=6; //ocean near light forest
				if(r==4) chance=1;  //ocean near forest
				if(r==5) chance=2;  //ocean near hills
				if(r==6) chance=3;  //ocean near mountains
				if(r==7) chance=8; //ocean near ice
				if(r==8) chance=75; //ocean near ocean
				if((mnum==1)||(mnum==3)){
				   if(x<20) {
				       if(r==8) chance=85; //ocean near ocean
				   }
				 }
				 if((mnum==2)||(mnum==4)){
				   if(x>65) {
				       if(r==8) chance=85; //ocean near ocean
				   }
				 }
				 if((mnum==1)||(mnum==2)){
				   if(y<=15){
				      if(r==8) chance=85;
				      }
				 }
				 if((mnum==3)||(mnum==4)){
				   if(y>=35){
				      if(r==8) chance=85;
				      }
				 }
			}
			/*DESERT*/
			if(bottom==1){
				if(r==1) {
					if((mnum==1)||(mnum==2)){
					   if(y>=30){
					     chance=80; //desert near desert
					     }
					   if(y<30) chance=0;
					 }
					if((mnum==3)||(mnum==4)){
					   if(y<=30) chance=80;
					   if(y>30) chance=0;
					 }
				  }
				if(r==2) chance=5;  //desert near plains
				if(r==3) chance=0;  //desert near light forest
				if(r==4) chance=0;  //desert near forest
				if(r==5) chance=10; //desert near hills
				if(r==6) chance=5;  //desert near mountains
				if(r==7) chance=0;  //desert near ice
				if(r==8) chance=0;  //desert near ocean
				}

			/*PLAINS*/
			if(bottom==2){
				if(r==1) chance=6;  //plains near desert
				if(r==2) chance=80; //plains near plains
				if(r==3) chance=10; //plains near light forest
				if(r==4) chance=10; //plains near forest
				if(r==5) chance=10; //plains near hills
				if(r==6) chance=3;  //plains near mountains
				if(r==7) chance=1;  //plains near ice
				if(r==8) chance=10; //plains near ocean
				}

			/*LIGHT FOREST*/
			if(bottom==3){
				if(r==1) chance=0;  //light forest near desert
				if(r==2) chance=10; //light forest near plains
				if(r==3) chance=70; //light forest near light forest
				if(r==4) chance=20; //light forest near forest
				if(r==5) chance=3; //light forest near hills
				if(r==6) chance=1;  //light forest near mountains
				if(r==7) chance=0;  //light forest near ice
				if(r==8) chance=6;  //light forest near ocean
				}

			/*FOREST*/
			if(bottom==4){
				if(r==1) chance=0;  //forest near desert
				if(r==2) chance=10; //forest near plains
				if(r==3) chance=20; //forest near light forest
				if(r==4) chance=70; //forest near forest
				if(r==5) chance=1;  //forest near hills
				if(r==6) chance=8;  //forest near mountains
				if(r==7) chance=0;  //forest near ice
				if(r==8) chance=1;  //forest near ocean
				}

			/*HILLS*/
			if(bottom==5){
				if(r==1) chance=10;  //hills near desert
				if(r==2) chance=10;  //hills near plains
				if(r==3) chance=3;   //hills near light forest
				if(r==4) chance=1;   //hills near forest
				if(r==5) chance=60;  //hills near hills
				if(r==6) chance=23;  //hills near mountains
				if(r==7) chance=1;   //hills near ice
				if(r==8) chance=2;   //hills near ocean
				}

			/*MOUNTAINS*/
			if(bottom==6){
				if(r==1) chance=5;   //mountains near desert
				if(r==2) chance=3;   //mountains near plains
				if(r==3) chance=1;   //mountains near light forest
				if(r==4) chance=8;   //mountains near forest
				if(r==5) chance=23;  //mountains near hills
				if(r==6) chance=57;  //mountains near mountains
				if(r==7) chance=20;  //mountains near ice
				if(r==8) chance=3;   //mountains near ocean
				}

			/*ICE*/
			if(bottom==7){
				if(r==1) chance=0;   //ice near desert
				if(r==2) chance=1;   //ice near plains
				if(r==3) chance=0;   //ice near light forest
				if(r==4) chance=0;   //ice near forest
				if(r==5) chance=1;   //ice near hills
				if(r==6) chance=20;  //ice near mountains
				if(r==7) chance=70;  //ice near ice
				if(r==8) chance=8;   //ice near ocean
				}
				if(r==1){
				   if((mnum==1)||(mnum==2)){
				       if(y<20) chance=0;
				       }
				   if((mnum==3)||(mnum==4)){
				       if(y>38) chance=0;
				       }
				}
				if(r==7){
				    if((mnum==1)||(mnum==2)){
					if(y>10) chance=0;
				    }
				    if((mnum==3)||(mnum==4)){
					if(y<40) chance=0;
				    }
				}

				tm=(random(100)+1);
				if(tm<=chance) chanceb=1;

			/*OCEAN*/
			if(topl==0){
				if(r==1) chance=0;  //ocean near desert
				if(r==2) chance=10; //ocean near plains
				if(r==3) chance=6; //ocean near light forest
				if(r==4) chance=1;  //ocean near forest
				if(r==5) chance=2;  //ocean near hills
				if(r==6) chance=3;  //ocean near mountains
				if(r==7) chance=8; //ocean near ice
				if(r==8) chance=75; //ocean near ocean
				if((mnum==1)||(mnum==3)){
				   if(x<20) {
				       if(r==8) chance=85; //ocean near ocean
				   }
				 }
				 if((mnum==2)||(mnum==4)){
				   if(x>65) {
				       if(r==8) chance=85; //ocean near ocean
				   }
				 }
				 if((mnum==1)||(mnum==2)){
				   if(y<=15){
				      if(r==8) chance=85;
				      }
				 }
				 if((mnum==3)||(mnum==4)){
				   if(y>=35){
				      if(r==8) chance=85;
				      }
				 }
			}
			/*DESERT*/
			if(topl==1){
				if(r==1) {
					if((mnum==1)||(mnum==2)){
					   if(y>=30){
					     chance=80; //desert near desert
					     }
					   if(y<30) chance=0;
					 }
					if((mnum==3)||(mnum==4)){
					   if(y<=30) chance=80;
					   if(y>30) chance=0;
					 }
				  }
				if(r==2) chance=5;  //desert near plains
				if(r==3) chance=0;  //desert near light forest
				if(r==4) chance=0;  //desert near forest
				if(r==5) chance=10; //desert near hills
				if(r==6) chance=5;  //desert near mountains
				if(r==7) chance=0;  //desert near ice
				if(r==8) chance=0;  //desert near ocean
				}

			/*PLAINS*/
			if(topl==2){
				if(r==1) chance=6;  //plains near desert
				if(r==2) chance=80; //plains near plains
				if(r==3) chance=10; //plains near light forest
				if(r==4) chance=10; //plains near forest
				if(r==5) chance=10; //plains near hills
				if(r==6) chance=3;  //plains near mountains
				if(r==7) chance=1;  //plains near ice
				if(r==8) chance=10; //plains near ocean
				}

			/*LIGHT FOREST*/
			if(topl==3){
				if(r==1) chance=0;  //light forest near desert
				if(r==2) chance=10; //light forest near plains
				if(r==3) chance=70; //light forest near light forest
				if(r==4) chance=20; //light forest near forest
				if(r==5) chance=3; //light forest near hills
				if(r==6) chance=1;  //light forest near mountains
				if(r==7) chance=0;  //light forest near ice
				if(r==8) chance=6;  //light forest near ocean
				}

			/*FOREST*/
			if(topl==4){
				if(r==1) chance=0;  //forest near desert
				if(r==2) chance=10; //forest near plains
				if(r==3) chance=20; //forest near light forest
				if(r==4) chance=70; //forest near forest
				if(r==5) chance=1;  //forest near hills
				if(r==6) chance=8;  //forest near mountains
				if(r==7) chance=0;  //forest near ice
				if(r==8) chance=1;  //forest near ocean
				}

			/*HILLS*/
			if(topl==5){
				if(r==1) chance=10;  //hills near desert
				if(r==2) chance=10;  //hills near plains
				if(r==3) chance=3;   //hills near light forest
				if(r==4) chance=1;   //hills near forest
				if(r==5) chance=60;  //hills near hills
				if(r==6) chance=23;  //hills near mountains
				if(r==7) chance=1;   //hills near ice
				if(r==8) chance=2;   //hills near ocean
				}

			/*MOUNTAINS*/
			if(topl==6){
				if(r==1) chance=5;   //mountains near desert
				if(r==2) chance=3;   //mountains near plains
				if(r==3) chance=1;   //mountains near light forest
				if(r==4) chance=8;   //mountains near forest
				if(r==5) chance=23;  //mountains near hills
				if(r==6) chance=57;  //mountains near mountains
				if(r==7) chance=20;  //mountains near ice
				if(r==8) chance=3;   //mountains near ocean
				}

			/*ICE*/
			if(topl==7){
				if(r==1) chance=0;   //ice near desert
				if(r==2) chance=1;   //ice near plains
				if(r==3) chance=0;   //ice near light forest
				if(r==4) chance=0;   //ice near forest
				if(r==5) chance=1;   //ice near hills
				if(r==6) chance=20;  //ice near mountains
				if(r==7) chance=70;  //ice near ice
				if(r==8) chance=8;   //ice near ocean
				}
				if(r==1){
				   if((mnum==1)||(mnum==2)){
				       if(y<20) chance=0;
				       }
				   if((mnum==3)||(mnum==4)){
				       if(y>38) chance=0;
				       }
				}
				if(r==7){
				    if((mnum==1)||(mnum==2)){
					if(y>10) chance=0;
				    }
				    if((mnum==3)||(mnum==4)){
					if(y<40) chance=0;
				    }
				}

				tm=(random(100)+1);
				if(tm<=chance) chancetl=1;
				if(LDIR==0) chancel=1;
				if(RDIR==0) chancer=1;
				if((chancet==1)&&(chancel==1)&&
				  (chancetr==1)&&(chancetl==1)&&
				  (chancer==1)&&(chanceb==1)) break;
		      }
		      chancet=0;
		      chancel=0;
		      chancetr=0;
		      chancetl=0;
		      chancer=0;
		      chanceb=0;
		      if(r==8) r=0;
		      if((MAP[x][y]>0)&&(r==0)) r=MAP[x][y];
		      if((mnum==2)||(mnum==4)){
			if(x>75) r=0;
			}
		      MAP[x][y]=r;

		}

	}
return;
}

void landremoval(void)
{
extern int LDIR;
extern int RDIR;

extern int MAP[81][51];
	int x,y;    //coordinates
	int m;
	int left,right,top,bottom,chance;
	int topleft,topright,bottomleft,bottomright;

	int hitsx,hitsy,hits;


	for(y=1;y<=50;y++){
		for(x=1;x<=80;x++){
			m=MAP[x][y];
			left=MAP[x-1][y];
			right=MAP[x+1][y];
			top=MAP[x][y-1];
			bottom=MAP[x][y+1];

			chance=0;
			if(m>0){
				if(left==0) chance=chance+25;
				if(right==0) chance=chance+25;
				if(top==0)   chance=chance+25;
				if(bottom==0) chance=chance+25;

				if(chance==100) MAP[x][y]=0;
			}
		}
	}
	for(y=1;y<=50;y++){
		for(x=1;x<=80;x++){
			m=MAP[x][y];
			topleft=MAP[x-1][y-1];
			topright=MAP[x+1][y-1];
			bottomleft=MAP[x-1][y+1];
			bottomright=MAP[x+1][y+1];

			chance=0;
			if(m>0){
				if(topleft==0) chance=chance+25;
				if(topright==0) chance=chance+25;
				if(bottomleft==0)   chance=chance+25;
				if(bottomright==0) chance=chance+25;

				if(chance==100) MAP[x][y]=0;
			}
		}
	}
	for(y=1;y<=50;y++){
		for(x=1;x<=80;x++){
			m=MAP[x][y];
			topleft=MAP[x-1][y-1];
			topright=MAP[x+1][y-1];
			bottomleft=MAP[x-1][y+1];
			bottomright=MAP[x+1][y+1];
			left=MAP[x-1][y];
			right=MAP[x+1][y];
			top=MAP[x][y-1];
			bottom=MAP[x][y+1];
			hits=0;
			chance=0;
			if(m>0){
				if(topleft>0) {hitsx=x-1;hitsy=y-1;hits++;}
				if(topright>0) {hitsx=x+1;hitsy=y-1;hits++;}
				if(bottomleft>0) {hitsx=x-1;hitsy=y+1;hits++;}
				if(bottomright>0){hitsx=x+1;hitsy=y+1;hits++;}
				if(left>0) {hitsx=x-1;hitsy=y;hits++;}
				if(right>0){hitsx=x+1;hitsy=y;hits++;}
				if(top>0)  {hitsx=x;hitsy=y-1;hits++;}
				if(bottom>0) {hitsx=x;hitsy=y+1;hits++;}



			}
		   if(hits==1){
			m=MAP[hitsx][hitsy];
			topleft=MAP[hitsx-1][hitsy-1];
			topright=MAP[hitsx+1][hitsy-1];
			bottomleft=MAP[hitsx-1][hitsy+1];
			bottomright=MAP[hitsx+1][hitsy+1];
			left=MAP[hitsx-1][hitsy];
			right=MAP[hitsx+1][hitsy];
			top=MAP[x][hitsy-1];
			bottom=MAP[hitsx][hitsy+1];
			hits=0;
			chance=0;
			if(m>0){
				if(topleft>0) hits++;
				if(topright>0) hits++;
				if(bottomleft>0) hits++;
				if(bottomright>0)hits++;
				if(left>0) hits++;
				if(right>0) hits++;
				if(top>0)  hits++;
				if(bottom>0) hits++;
				if(hits==1){
				     MAP[x][y]=0;
				}
			}
		   }
		}
	}
	for(y=1;y<=50;y++){
		for(x=1;x<=80;x++){
			m=MAP[x][y];
			left=MAP[x-1][y];
			right=MAP[x+1][y];
			top=MAP[x][y-1];
			bottom=MAP[x][y+1];

			chance=0;
			if(m>0){
				if(left==0) chance=chance+25;
				if(right==0) chance=chance+25;
				if(top==0)   chance=chance+25;
				if(bottom==0) chance=chance+25;
				if(chance==100) MAP[x][y]=0;
			}
		}
	}
			/*single desert removal*/
	for(y=1;y<=50;y++){
		for(x=1;x<=80;x++){
			m=MAP[x][y];
			left=MAP[x-1][y];
			right=MAP[x+1][y];
			top=MAP[x][y-1];
			bottom=MAP[x][y+1];

			chance=0;
			if(m==1){
				if(left!=1) chance=chance+25;
				if(right!=1) chance=chance+25;
				if(top!=1)   chance=chance+25;
				if(bottom!=1) chance=chance+25;
				if(chance==100) MAP[x][y]=right;
			}
		}
	}
return;
}




void minimap(int mnum)
{
extern int MAP[81][51];
extern color scpalette[256];

	int x,y;  //coordinates
	int spot; //current terrain type
	int xx,yy; //pixel coordinates
	int xxdum; //dummy x coordinates
	int ix,iy;
	FILE *sav;
	wsetpalette(0,255,scpalette);

	if(mnum==1){ xx=80;
		     yy=50;
		}
	if(mnum==2){ xx=160;
		     yy=50;
		}
	if(mnum==3){ xx=80;
		     yy=100;
		}
	if(mnum==4){ xx=160;
		     yy=100;
		}

	     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);
	xxdum=xx;
	for(y=1;y<=50;y++){
		for(x=1;x<=80;x++){
			spot=MAP[x][y];
			if(spot==0) wsetcolor(1);
			if(spot==1) wsetcolor(6);
			if(spot==2) wsetcolor(14);
			if(spot==3) wsetcolor(10);
			if(spot==4) wsetcolor(2);
			if(spot==5) wsetcolor(7);
			if(spot==6) wsetcolor(8);
			if(spot==7) wsetcolor(15);

			wputpixel(xx,yy);
			xx=xx+1;
		}
		xx=xxdum;
		yy=yy+1;
	}

return;
}

