--- mapgen.c.org Mon Aug 14 22:01:49 2000 +++ mapgen.c Sun Sep 24 04:20:28 2000 @@ -30,7 +30,8 @@ #include "mapgen.h" -#define hmap(x,y) &height_map[(y)*map.xsize+map_adjust_x(x)] +/* Wrapper for easy access. It's a macro so it can be a lvalue. */ +#define hmap(x,y) (height_map[(y) * map.xsize + map_adjust_x(x)]) static void make_huts(int number); static void add_specials(int prob); @@ -56,15 +57,6 @@ #define MAP_NCONT 255 /************************************************************************** - Just a wrapper function off the height_map, returns the height at x,y -**************************************************************************/ - -static int full_map(int x, int y) -{ - return height_map[y*map.xsize+x]; -} - -/************************************************************************** make_mountains() will convert all squares that are higher than thill to mountains and hills. Notice that thill will be adjusted according to the map.mountains value, so increase map.mountains and you'll get more @@ -80,7 +72,7 @@ mount=0; for (y=0;ythill) + if (hmap(x, y)>thill) mount++; if (mount<((map.xsize*map.ysize)*map.mountains)/1000) thill*=95; @@ -91,7 +83,7 @@ for (y=0;ythill &&map_get_terrain(x,y)!=T_OCEAN) { + if (hmap(x, y)>thill &&map_get_terrain(x,y)!=T_OCEAN) { if (myrand(100)>75) map_set_terrain(x, y, T_MOUNTAINS); else if (myrand(100)>25) @@ -109,7 +101,7 @@ for (y=0;ymyrand(maxval) && map_get_terrain(x,y)==T_GRASSLAND) || y==0) { + if ((hmap(x, y)+(map.ysize/10-y*25)>myrand(maxval) && map_get_terrain(x,y)==T_GRASSLAND) || y==0) { if (y<2) map_set_terrain(x, y, T_ARCTIC); else @@ -120,7 +112,7 @@ } for (y=map.ysize*9/10;ymyrand(maxval) && map_get_terrain(x, y)==T_GRASSLAND) || y==map.ysize-1) { + if ((hmap(x, y)+(map.ysize/10-(map.ysize-y)*25)>myrand(maxval) && map_get_terrain(x, y)==T_GRASSLAND) || y==map.ysize-1) { if (y>map.ysize-3) map_set_terrain(x, y, T_ARCTIC); else @@ -138,7 +130,7 @@ **************************************************************************/ static void make_desert(int x, int y, int height, int diff) { - if (abs(full_map(x, y)-height)5) make_forest(x-1,y, height, diff-5); if (myrand(10)>5) make_forest(x,y-1, height, diff-5); if (myrand(10)>5) make_forest(x+1,y, height, diff-5); @@ -186,13 +178,13 @@ x=myrand(map.xsize); y=myrand(map.ysize); if (map_get_terrain(x, y)==T_GRASSLAND) { - make_forest(x,y, full_map(x, y), 25); + make_forest(x,y, hmap(x, y), 25); } if (myrand(100)>75) { y=(myrand(map.ysize*2/10))+map.ysize*4/10; x=myrand(map.xsize); if (map_get_terrain(x, y)==T_GRASSLAND) { - make_forest(x,y, full_map(x, y), 25); + make_forest(x,y, hmap(x, y), 25); } } } while (forests1000) return; y=myrand(map.ysize); x=myrand(map.xsize); - if (map_get_terrain(x, y)==T_GRASSLAND && full_map(x, y)<(maxval*60)/100) { + if (map_get_terrain(x, y)==T_GRASSLAND && hmap(x, y)<(maxval*60)/100) { map_set_terrain(x, y, T_SWAMP); if (myrand(10)>5 && map_get_terrain(x-1, y)!=T_OCEAN) map_set_terrain(x-1,y, T_SWAMP); @@ -244,7 +236,7 @@ y=myrand(map.ysize/10)+map.ysize*45/100; x=myrand(map.xsize); if (map_get_terrain(x, y)==T_GRASSLAND) { - make_desert(x,y, full_map(x, y), 50); + make_desert(x,y, hmap(x, y), 50); i--; } } @@ -281,19 +273,19 @@ return 0; map_set_terrain(x, y, map_get_terrain(x,y)+16); - if (full_map(x, y-1)maxval) - maxval=full_map(x, y); - if (full_map(x, y)maxval) + maxval=hmap(x, y); + if (hmap(x, y)0) { y = myrand(s - n) + n; x = myrand(e - w) + w; - if ((!*hmap(x, y)) && ( - *hmap(x+1, y) || *hmap(x-1, y) || - *hmap(x, y+1) || *hmap(x, y-1) )) { - *hmap(x, y) = 1; + if ((!hmap(x, y)) && ( + hmap(x+1, y) || hmap(x-1, y) || + hmap(x, y+1) || hmap(x, y-1) )) { + hmap(x, y) = 1; i--; if (y >= s - 1 && s < map.ysize - 2) s++; if (x >= e - 1 && e < map.xsize - 2) e++; @@ -1267,10 +1259,10 @@ if (i < islemass / 10) { for (y = n ; y < s ; y++) for (x = w ; x < e ; x++) - if ((!*hmap(x, y)) && i && ( - *hmap(x+1, y) && *hmap(x-1, y) && - *hmap(x, y+1) && *hmap(x, y-1) )) { - *hmap(x, y) = 1; + if ((!hmap(x, y)) && i && ( + hmap(x+1, y) && hmap(x-1, y) && + hmap(x, y+1) && hmap(x, y-1) )) { + hmap(x, y) = 1; i--; } }