Builder/tests/gentest.c

55 lines
1.5 KiB
C

# include <time.h>
# include <stdio.h>
# include <stdlib.h>
# define WORLD_WIDTH 256 // World width.
# define WORLD_HEIGHT 64 // World height.
void generateworld(unsigned short terrain[], int w, int h, int genstart, int genmin, int genmax, int someof, int type) {
int x = 0, y = genstart, n, i, a, t;
for(x=0;x!=w;x++){
srand(clock());
a = (int)rand() % 2;
if(a==0){
for(i=y;i!=h;i++){
srand(clock());
t = (int)rand() % 11;
if(t==0){
terrain[i*w+x] = someof;
}else{
terrain[i*w+x] = type;
}
}
}else if(a==1){
for(i=y;i!=h;i++){
terrain[i*w+x] = type;
}
}
srand(clock());
n = (int)rand() % 2;
if(n==0 && y<genmax){
y++;
}else if(n==1 && y>genmin){
y--;
}
}
}
int main() {
unsigned short terrain[WORLD_WIDTH*WORLD_HEIGHT];
int i, x, y;
for(i=0;i!=WORLD_WIDTH*WORLD_HEIGHT;i++){
terrain[i] = 0;
}
srand(clock());
generateworld(terrain, WORLD_WIDTH, WORLD_HEIGHT, (int)((rand() % ((WORLD_HEIGHT - 40) - (WORLD_HEIGHT - 60) + 1)) + WORLD_HEIGHT - 60), WORLD_HEIGHT - 60, WORLD_HEIGHT - 40, 0, 1);
srand(clock());
generateworld(terrain, WORLD_WIDTH, WORLD_HEIGHT, (int)((rand() % ((WORLD_HEIGHT - 25) - (WORLD_HEIGHT - 40) + 1)) + WORLD_HEIGHT - 40), WORLD_HEIGHT - 40, WORLD_HEIGHT - 25, 3, 2);
printf("! XPM2\n%d %d 4 1\n0 c #4dc4be\n1 c #6b4528\n2 c #787878\n3 c #000000\n", WORLD_WIDTH, WORLD_HEIGHT);
for(y=0;y!=WORLD_HEIGHT;y++){
for(x=0;x!=WORLD_WIDTH;x++){
printf("%d", terrain[y*WORLD_WIDTH+x]);
}
printf("\n");
}
return 0;
}