neingeist
/
cscape
Archived
1
0
Fork 0
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

52 lines
1.1 KiB
C

/* $Revision$ */
#include <stdlib.h>
void map_init (char *map, int x, int y) {
int i;
for (i=0;i<x*y;i++) {
map[i]=0;
}
}
char map_ncol (int mc, int n, int dvd);
void map_generate (char *map, int x1,int y1,int x2,int y2) {
int xn,yn,dxy,p1,p2,p3,p4;
if ((x2-x1<2) && (y2-y1<2)) return;
p1 = map[x1*256+y1];
p2 = map[x1*256+y2];
p3 = map[x2*256+y1];
p4 = map[x2*256+y2];
xn = (x2+x1)/2;
yn = (y2+y1)/2;
dxy = 5*(x2-x1+y2-y1)/3;
if (map[xn*256+y1] <= 0) map[xn*256+y1] = map_ncol(p1+p3,dxy,2);
if (map[x1*256+yn] <= 0) map[x1*256+yn] = map_ncol(p1+p2,dxy,2);
if (map[x2*256+yn] <= 0) map[x2*256+yn] = map_ncol(p3+p4,dxy,2);
if (map[xn*256+y2] <= 0) map[xn*256+y2] = map_ncol(p2+p4,dxy,2);
map[xn*256+yn] = map_ncol(p1+p2+p3+p4,dxy,4);
map_generate(map, x1,y1,xn,yn);
map_generate(map, xn,y1,x2,yn);
map_generate(map, x1,yn,xn,y2);
map_generate(map, xn,yn,x2,y2);
}
char map_ncol (int mc, int n, int dvd) {
char loc = 0;
loc = (mc+n-(int) (2.0*n*rand()/(RAND_MAX+1.0)) )/dvd;
if (loc < 5) loc = 5;
return loc;
}