#include #include "fractal.h" void Segment(u_char map[MAP_SIZE][MAP_SIZE], int x1, int y1, int x2, int y2); void NewHeight(u_char map[MAP_SIZE][MAP_SIZE], int x,int y, int a,int b, int c,int d); void GenerateMap(u_char map[MAP_SIZE][MAP_SIZE], int seed) { int i, j, k, a, b, c, d; u_char map2[MAP_SIZE][MAP_SIZE]; srand(seed); for (j=0; j>1; int ym = (y1+y2)>>1; //All this is working out the height of the landscape at each point if ((x2-x1)<2 && (y2-y1)<2) return; NewHeight(map, xm, y1, x1, y1, x2, y1); NewHeight(map, x2, ym, x2, y1, x2, y2); NewHeight(map, xm, y2, x1, y2, x2, y2); NewHeight(map, x1, ym, x1, y1, x1, y2); col = (map[x1][y1] + map[x2%MAP_SIZE][y1] + map[x1][y2%MAP_SIZE] + map[x2%MAP_SIZE][y2%MAP_SIZE])>>2; if (map[xm][ym]==0) map[xm][ym] = col; Segment(map, x1,y1,xm,ym); Segment(map, xm,y1,x2,ym); Segment(map, x1,ym,xm,y2); Segment(map, xm,ym,x2,y2); } void NewHeight(u_char map[MAP_SIZE][MAP_SIZE], int x,int y, int a,int b, int c,int d) { int col = (Abs(a-c) + Abs(b-d))<<6; if (map[x%MAP_SIZE][y%MAP_SIZE] != 0) return; if (col<2) col = 2; a = a % MAP_SIZE; b = b % MAP_SIZE; c = c % MAP_SIZE; d = d % MAP_SIZE; col = (rand() % col)-(col>>1); col = col + ((map[a][b] + map[c][d] + 1)>>1); if (col<1) col = 1; if (col>255) col = 255; map[x%MAP_SIZE][y%MAP_SIZE] = col; }