diff --git a/code/apps/server/source/main.c b/code/apps/server/source/main.c index f3c8db1..db5d12b 100644 --- a/code/apps/server/source/main.c +++ b/code/apps/server/source/main.c @@ -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; diff --git a/code/apps/server/source/world_gen.c b/code/apps/server/source/world_gen.c index dee8c12..441bef0 100644 --- a/code/apps/server/source/world_gen.c +++ b/code/apps/server/source/world_gen.c @@ -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