From e74f1255a6a9d396fb8bf02cfe4c3a21dbf84bae Mon Sep 17 00:00:00 2001 From: N0VA Date: Tue, 17 Feb 2026 14:39:19 +0100 Subject: [PATCH] Create world.c --- iris_c/world.c | 40 ++++++++++++++++++++++++++++++++++++++++ iris_c/world.h | 6 +++--- 2 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 iris_c/world.c diff --git a/iris_c/world.c b/iris_c/world.c new file mode 100644 index 0000000..5718903 --- /dev/null +++ b/iris_c/world.c @@ -0,0 +1,40 @@ +#include "world.h" + +#include + +#include "random.h" + +static quadrant_type random_quadrant_type(void) { + uint8_t roll = random_range(100); + + if (roll < 30) return Q_EMPTY; + if (roll < 40) return Q_ASTEROID_FIELD; + if (roll < 50) return Q_STAR_SYSTEM; + if (roll < 60) return Q_NEBULA; + if (roll < 70) return Q_BLACK_HOLE; + if (roll < 80) return Q_WHITE_HOLE; + if (roll < 85) return Q_PULSAR; + if (roll < 90) return Q_SUPERNOVA; + if (roll < 95) return Q_ANOMALY; + return Q_SINGULARITY; +} + +void world_generate(world_t *w) { + if (w == NULL) return; + + for (uint16_t y = 0; y < WORLD_HEIGHT; y++) { + for (uint16_t x = 0; x < WORLD_WIDTH; x++) { + quadrant_t *q = &w->quadrants[y][x]; + q->type = random_quadrant_type(); + q->is_old = (random_range(100) < 20); + q->is_visited = false; + q->is_discovered = false; + } + } +} + +const quadrant_t *world_get_quadrant(const world_t *w, uint16_t x, uint16_t y) { + if (w == NULL) return NULL; + if (x >= WORLD_WIDTH || y >= WORLD_HEIGHT) return NULL; + return &w->quadrants[y][x]; +} diff --git a/iris_c/world.h b/iris_c/world.h index f6fc460..0bce6f1 100644 --- a/iris_c/world.h +++ b/iris_c/world.h @@ -27,13 +27,13 @@ typedef struct { bool is_visited; bool is_discovered; bool is_old; -} quadrant; +} quadrant_t; typedef struct { - quadrant quadrants[WORLD_HEIGHT][WORLD_WIDTH]; + quadrant_t quadrants[WORLD_HEIGHT][WORLD_WIDTH]; } world_t; void world_generate(world_t *w); -const quadrant * world_get_quadrant(const world_t *w, uint16_t x, uint16_t y); +const quadrant_t * world_get_quadrant(const world_t *w, uint16_t x, uint16_t y); #endif