summaryrefslogtreecommitdiff
path: root/src/server.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/server.c')
-rw-r--r--src/server.c49
1 files changed, 42 insertions, 7 deletions
diff --git a/src/server.c b/src/server.c
index 30b5676..974e396 100644
--- a/src/server.c
+++ b/src/server.c
@@ -14,6 +14,8 @@
#include <errno.h>
#include <poll.h>
#include <png.h>
+#include <perlin.h>
+#include <math.h>
#include "array.h"
#include "content.h"
#include "net.h"
@@ -70,30 +72,63 @@ node *map_node(game *g, vec2 p, int8_t z)
return NULL;
}
+bool silly_noise(vec2 pos, uint32_t grid, double sillyness, int seed)
+{
+ int64_t x = (int64_t) pos.x+INT_MAX+1;
+ int64_t y = (int64_t) pos.y+INT_MAX+1;
+
+ if ((y/grid) % 2 == 0)
+ x += grid/2;
+
+ x += round(noise2d(x/grid, y/grid, 0, seed) * sillyness);
+ y += round(noise2d(y/grid, x/grid, 0, seed) * sillyness);
+
+ return x % grid == 0 && y % grid == 0;
+#undef SMOD
+}
+
void map_load_node(map *m, uvec2 v, color col)
{
uint32_t ucol = color_to_u32(col);
+ vec2 pos = vec2_add(m->chunk.bounds.pos, CVEC2(v));
+
node *n = chunk_index(m->chunk, v);
- n->present = ucol != 0xffffff;
+ *n = (node) { 0 };
+ n->present = ucol != 0xffffff;
if (!n->present)
return;
- n->z = 0;
- n->col = col;
switch (ucol) {
- case 0x00880d: n->type = N_GRASS; break; // TODO: color
+ case 0x00880d: n->type = N_GRASS;
+ n->variant = silly_noise(pos, 3, 1.0, 0);
+ break;
case 0x595959: n->type = N_ROCK; n->z = 1; break;
case 0x484848: n->type = N_ROCK; n->z = 2; break;
case 0x373737: n->type = N_ROCK; n->z = 3; break;
- case 0x00ffe8: n->type = N_MOUNTAIN_FLOWER; break;
+ case 0x00ffe8: n->type = N_MOUNTAIN_FLOWER;
+ n->variant = FLOWER_DANDELION;
+ n->z = 3;
+ break;
+ case 0x001b51: n->type = N_MOUNTAIN_FLOWER;
+ n->variant = FLOWER_DANDELION;
+ n->z = 2;
+ break;
case 0xa09700: n->type = N_PATH; break;
case 0x015100: n->type = N_NEEDLE_TREE; break;
- case 0x00c6ff: n->type = N_WATER; n->z = -1; break;
+ case 0x00c6ff: n->type = N_WATER;
+ n->variant = silly_noise(pos, 3, 0.7, 1);
+ n->z = -1;
+ break;
case 0x5c3b12: n->type = N_PLANK; break;
- case 0xff9de2: n->type = N_VALLEY_FLOWER; break; // TODO: color
+ case 0xff9de2: n->type = N_VALLEY_FLOWER;
+ n->variant = rand() % FLOWER_COUNT;
+ break;
case 0x016300: n->type = N_BIG_TREE; break;
+ case 0xfce84e: n->type = N_SAND;
+ n->variant = silly_noise(pos, 4, 1.0, 1);
+ break;
default:
fprintf(stderr, "invalid color in map %.*s at %"PRIu32" %"PRIu32": %06x\n",
PSTR(m->name), v.x, v.y, ucol);