add worldgen variation

isolation_bkp/dynres
Dominik Madarász 2021-01-11 19:10:56 +01:00
parent b9b82ba6e6
commit 870a21fd9f
2 changed files with 19 additions and 3 deletions

View File

@ -17,6 +17,7 @@ int main(int argc, char** argv) {
zpl_opts_add(&opts, "?", "help", "the HELP section", ZPL_OPTS_FLAG);
zpl_opts_add(&opts, "p", "preview-map", "draw world preview", ZPL_OPTS_FLAG);
zpl_opts_add(&opts, "s", "seed", "world seed", ZPL_OPTS_INT);
zpl_opts_add(&opts, "r", "random-seed", "generate random world seed", ZPL_OPTS_FLAG);
uint32_t ok = zpl_opts_compile(&opts, argc, argv);
if (!ok) {
@ -26,6 +27,12 @@ int main(int argc, char** argv) {
}
int32_t seed = zpl_opts_integer(&opts, "seed", DEFAULT_WORLD_SEED);
if (zpl_opts_has_arg(&opts, "random-seed")) {
zpl_random rnd={0};
zpl_random_init(&rnd);
seed = zpl_random_gen_u32(&rnd);
}
if (zpl_opts_has_arg(&opts, "preview-map")) {
generate_minimap(seed);
return 0;

View File

@ -71,6 +71,8 @@ static WORLD_BLOCK_OBSERVER(shaper_noise33) {
return world_perlin_cond(block_idx, 0.33) ? shaper(id, block_idx) : BLOCK_INVALID;
}
#define RAND_RANGE(x,y) (x + (uint32_t)rand()%(y-(x)))
int32_t world_gen() {
// TODO: perform world gen
// atm, we will fill the world with ground and surround it by walls
@ -78,6 +80,8 @@ int32_t world_gen() {
uint32_t grnd_id = blocks_find(BLOCK_BIOME_DEV, BLOCK_KIND_GROUND);
uint32_t watr_id = blocks_find(BLOCK_BIOME_DEV, BLOCK_KIND_WATER);
srand(world_seed);
// walls
world_fill_rect(wall_id, 0, 0, world_width, world_height, NULL);
@ -85,12 +89,17 @@ int32_t world_gen() {
world_fill_rect(grnd_id, 1, 1, world_width-2, world_height-2, NULL);
// water
world_fill_rect_anchor(watr_id, 8, 8, 4, 4, 0.5f, 0.5f, NULL);
for (int i=0; i<RAND_RANGE(0, 8); i++) {
world_fill_rect_anchor(watr_id, RAND_RANGE(0, world_width), RAND_RANGE(0, world_height), 4+RAND_RANGE(0,3), 4+RAND_RANGE(0,3), 0.5f, 0.5f, shaper_noise33);
}
// hills
world_fill_rect_anchor(wall_id, 14, 21, 8, 8, 0.5f, 0.5f, shaper_noise80);
world_fill_rect_anchor(wall_id, 14, 21, 4, 4, 0.5f, 0.5f, shaper_noise50);
world_fill_rect_anchor(wall_id, 14+RAND_RANGE(-10, 10), 21+RAND_RANGE(-10, 10), 8+RAND_RANGE(-2,4), 8+RAND_RANGE(-2,4), 0.5f, 0.5f, shaper_noise80);
world_fill_rect_anchor(wall_id, 14+RAND_RANGE(-10, 10), 21+RAND_RANGE(-10, 10), 4+RAND_RANGE(-2,4), 4+RAND_RANGE(-2,4), 0.5f, 0.5f, shaper_noise50);
for (int i=0; i<RAND_RANGE(8, 24); i++) {
world_fill_rect_anchor(wall_id, RAND_RANGE(0, world_width), RAND_RANGE(0, world_height), 4+RAND_RANGE(-2,4), 4+RAND_RANGE(-2,4), 0.5f, 0.5f, shaper_noise50);
}
return WORLD_ERROR_NONE;
}