

//#define USE_BYTE

#define GEO_LEVEL	8		// 8
#define GEO_SIZE	257		// 257 =	( 2 ^  LEVEL   ) +1
#define GEO_SIZE2	513		// 513 =	( 2 ^ (LEVEL+1)) +1



#ifdef USE_BYTE
#define GEO_MIN_EL	0     	// minimum elevation
#define GEO_MAX_EL	64    	// maximum elevation
#define GEO_INIT_EL 32   	// average initial elevation
#define GEO_SEA_EL	36   	// sea level
#define GEO_NORM_EL 32  	// normal elevation (above sea level)
#else
#define GEO_MIN_EL	0     	// minimum elevation
#define GEO_MAX_EL	18000   // maximum elevation
#define GEO_INIT_EL 10000	// average initial elevation
#define GEO_SEA_EL	12000	// sea level
#define GEO_NORM_EL 10000	// normal elevation (above sea level)
#endif

#ifdef USE_BYTE
typedef signed char CELL;		// normal map cell
typedef signed int CELL2;		// can store a squared CELL (twice # of bits)
#else
typedef signed int CELL;		// normal map cell
typedef signed long CELL2;		// can store a squared CELL (twice # of bits)
#endif

extern int LEVEL;
extern int SIZE;
extern int SIZE2;
extern CELL MIN_EL;
extern CELL MAX_EL;
extern CELL INIT_EL;
extern CELL sea;

typedef unsigned char byte;
typedef struct
{
	CELL elev;		// geography
}
Cell;


#define MAP Cell huge	// map is 513x257 = 128K+ records

#define MAP_TABLE 11

#ifndef GEO_INIT

	extern MAP cell [GEO_SIZE2][GEO_SIZE];	// 513,257
//	extern unsigned char map_table [MAP_TABLE][4];
	extern int R;
	extern int colors;
	extern int rivers;
	extern int contours;
	extern int overlap;
	extern int wrap;

#else

	MAP cell [GEO_SIZE2][GEO_SIZE];

	/**********************************************************
	*
	*	Roughness factor R
	*
	*	roughness should typically be 70 or 80.  Lower values
	*	will result in more regular terrain, while higher values
	*	will cause greater variation.  Values above 100 will cause
	*	severe variation!
	*
	*	Divided by 100:		 80/100 = 0.8
	*						 70/100 = 0.7
	*						110/100 = 1.1
	*
	**********************************************************/

#endif

//----------------------------------------------------------------------

void	geo();
void	initialize();

void	getstr(int attr, int x, int y, char *buf, int maxlen);
void	geo_menu();			// user menu

void	save();				// save map file
void	load();				// load map file


		// various filters

void	rescale();				// rescales all locations: 0 <= CELL <= MAX
void 	square_filter();		// squares all land cells
void	sqrt_filter();			// takes square root of all land cells
void	map_smooth();			// smooths all locations
void    map_erode();			// erodes all land cells
void 	map_wrap(int wrap);		// fixes poles, east-west

		// map generation functions

void	new_map();
CELL	map_init();
void	map_calc(int level);
CELL	map_ave2(CELL,CELL);
CELL	map_ave4(CELL,CELL,CELL,CELL);
CELL	map_ave5(CELL,CELL,CELL,CELL,CELL);
CELL	map_ave8(CELL,CELL,CELL,CELL,CELL,CELL,CELL,CELL);

		// return value at (x,y)

CELL	val(int x,int y);

		// find correct (x1,y1) and (x2,y2) offsets from (x,y) at step size
		// wrap if necessary

void	delta(int x, int y, int &x1, int &y1, int &x2, int &y2, int step);


		// drawing functions

void	map_erase(); 		// erases map area on screen
void	map_plot(int color, int x, int y);
void	map_draw(int);		// draw mercator projection (correct shape)

int		get_color(int x, int y, int step);


