summaryrefslogtreecommitdiff
path: root/src/game/worldgen.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/worldgen.cpp')
-rw-r--r--src/game/worldgen.cpp41
1 files changed, 32 insertions, 9 deletions
diff --git a/src/game/worldgen.cpp b/src/game/worldgen.cpp
index 18a98b5..6ade1a6 100644
--- a/src/game/worldgen.cpp
+++ b/src/game/worldgen.cpp
@@ -4,29 +4,37 @@ namespace game {
using namespace world;
-void add_decoration(world_t *world, state_t *game, v2f_t x, float noise)
+void add_decoration(world_t *world, state_t *game, v2f_t x)
{
+ float noise;
deco_t *deco;
deco_type_t type;
v2f_t center, offset;
- if (noise < 0.3)
+ noise = world->perlin.get(x, 0.53213f) + world->perlin.get(x, 0.12994f);
+ noise = fabs(noise / 2);
+
+ if (noise < 0.16)
return;
offset[0] = world->perlin.get(x, 0.17331f);
offset[1] = world->perlin.get(x, 0.19571f);
center = x + v2f_t(0.5f, 0.5f) + offset.norm() * 0.1;
- if (noise > 0.5) {
+ if (noise > 0.39) {
unit_nest_t *nest = new unit_nest_t(game);
nest->place(world, center);
return;
}
- if (noise > 0.40)
+ if (noise > 0.36)
type = DECO_EYETHING;
- else if (noise > 0.35)
+ else if (noise > 0.33)
type = DECO_STONE;
+ else if (noise > 0.26)
+ type = DECO_SPIKE;
+ else if (noise > 0.20)
+ type = DECO_SPIKE_SMALL;
else
type = DECO_STONE_SMALL;
@@ -35,10 +43,14 @@ void add_decoration(world_t *world, state_t *game, v2f_t x, float noise)
deco->place(world, x);
}
-void worldgen(world_t *world, sector_index_t index, sector_t *sector, void *data)
+void worldgen(world_t *world, sector_index_t index, sector_t *sector,
+ bool gen_tiles, bool gen_decos, void *data)
{
state_t *game = (game::state_t*)data;
+ if (!gen_tiles)
+ goto decos;
+
for (coord_t ly = 0; ly < SECTOR_SIZE; ly++)
for (coord_t lx = 0; lx < SECTOR_SIZE; lx++) {
tile_t *tile = sector->tiles + ly * SECTOR_SIZE + lx;
@@ -46,7 +58,6 @@ void worldgen(world_t *world, sector_index_t index, sector_t *sector, void *data
index[1] * SECTOR_SIZE + ly);
v2f_t x;
float waterlevel, height;
- float deco_noise;
x = v2f_t(index) * SECTOR_SIZE + v2f_t(lx, ly);
@@ -67,11 +78,23 @@ void worldgen(world_t *world, sector_index_t index, sector_t *sector, void *data
tile->type = TILE_STONE;
else
tile->type = TILE_DIRT;
+ }
- deco_noise = world->perlin.get(x, 0.125559f);
+decos:
+ if (!gen_decos)
+ return;
+
+ for (coord_t ly = 0; ly < SECTOR_SIZE; ly++)
+ for (coord_t lx = 0; lx < SECTOR_SIZE; lx++) {
+ tile_t *tile = sector->tiles + ly * SECTOR_SIZE + lx;
+ tile_index_t tile_index(index[0] * SECTOR_SIZE + lx,
+ index[1] * SECTOR_SIZE + ly);
+ v2f_t x;
+
+ x = v2f_t(index) * SECTOR_SIZE + v2f_t(lx, ly);
if (tile->type == TILE_DIRT)
- add_decoration(world, game, x, deco_noise);
+ add_decoration(world, game, x);
}
}