]> git.lizzy.rs Git - dungeon_game.git/commitdiff
Add mapgen contexts
authorElias Fleckenstein <eliasfleckenstein@web.de>
Mon, 14 Jun 2021 18:58:57 +0000 (20:58 +0200)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Mon, 14 Jun 2021 18:58:57 +0000 (20:58 +0200)
plugins/apple/apple.c
plugins/cherry/cherry.c
plugins/fireball/fireball.c
plugins/game/game.c
plugins/game/game.h
plugins/inventory/inventory.c
plugins/monster/monster.c
plugins/sword/sword.c

index 795800d48ae47c5edd88a0879c77f6b9fb0f7723..6adff086475be28f951f48de85b1efb8f6c785d7 100644 (file)
@@ -34,7 +34,7 @@ static struct entity apple_entity = {
        .on_damage = NULL,
 };
 
-static void spawn_apple(int x, int y)
+static void spawn_apple(int x, int y, enum mg_context ctx)
 {
        spawn(apple_entity, x, y, NULL);
 }
index f9987704b93af46fb7d79e9e557f6a255f8360cf..1f96aca63986a9910e7b5866d98e24036165c645 100644 (file)
@@ -6,8 +6,6 @@
 
 static bool use_cherry(struct itemstack *stack)
 {
-       (void) stack;
-
        add_health(&player, 2);
        return true;
 }
@@ -56,7 +54,7 @@ static struct entity cherry_entity = {
        .on_damage = NULL,
 };
 
-static void spawn_cherry(int x, int y)
+static void spawn_cherry(int x, int y, enum mg_context ctx)
 {
        spawn(cherry_entity, x, y, NULL);
 }
index 39e93fb586909d7c8429e6493ad3533b0f2d9713..a0e9a13fa8aa9d73b7ca7bd8d2cd285806fdad66 100644 (file)
@@ -33,8 +33,6 @@ static void fireball_step(struct entity *self, struct entity_step_data stepdata)
 
 static void fireball_collide(struct entity *self, int x, int y)
 {
-       (void) x, y;
-
        self->remove = true;
 }
 
@@ -82,8 +80,6 @@ static void shoot_fireball()
 
 static bool shoot_fireball_item(struct itemstack *stack)
 {
-       (void) stack;
-
        shoot_fireball();
        return true;
 }
index 94ad148d6930bd8266bcc4c415af76d34fb4f10f..adcb59abf5e56746983fa0d3fcc42a3ddd95af01 100644 (file)
@@ -129,12 +129,6 @@ double calculate_dtime(struct timespec from, struct timespec to)
        return (double) (to.tv_sec - from.tv_sec) + (double) (to.tv_nsec - from.tv_nsec) / 1000000000.0;
 }
 
-/*struct roman_conversion_rule
-{
-       int number;
-       const char *symbol;
-};*/
-
 static struct
 {
        int number;
@@ -327,7 +321,7 @@ struct entity player = {
 
 /* Mapgen */
 
-static void mapgen_set_air(int x, int y)
+static void mapgen_set_air(int x, int y, enum mg_context ctx)
 {
        if (is_outside(x, y))
                return;
@@ -341,7 +335,7 @@ static void mapgen_set_air(int x, int y)
                struct generator_function *func = ptr->element;
 
                if (rand() % func->chance == 0)
-                       func->callback(x, y);
+                       func->callback(x, y, ctx);
        }
 }
 
@@ -363,7 +357,7 @@ static void generate_room(int origin_x, int origin_y)
                }
 
                for (int y = -up; y <= down; y++)
-                       mapgen_set_air(origin_x + x, origin_y + y);
+                       mapgen_set_air(origin_x + x, origin_y + y, MG_CTX_ROOM);
        }
 }
 
@@ -385,7 +379,7 @@ static void generate_corridor(int lx, int ly, enum direction ldir)
                return;
        }
 
-       mapgen_set_air(lx, ly);
+       mapgen_set_air(lx, ly, MG_CTX_CORRIDOR);
 
        int x, y;
 
@@ -511,8 +505,6 @@ static void render()
 
 static void handle_interrupt(int signal)
 {
-       (void) signal;
-
        quit();
 }
 
@@ -526,8 +518,6 @@ static void handle_input(unsigned char c)
 
 static void *input_thread(void *unused)
 {
-       (void) unused;
-
        while (running)
                handle_input(tolower(fgetc(stdin)));
 
index 21a94339eb0969bf680f1bd4ba4e4ac6e773b3d2..74fea1c0eac4030549859eba3e154854f2d424e7 100644 (file)
@@ -63,10 +63,16 @@ struct list
        struct list *next;
 };
 
+enum mg_context
+{
+       MG_CTX_CORRIDOR,
+       MG_CTX_ROOM,
+};
+
 struct generator_function
 {
        int chance;
-       void (*callback)(int x, int y);
+       void (*callback)(int x, int y, enum mg_context ctx);
 };
 
 struct input_handler
index 66f663ea07c154b3ba7cb43c3fcc5b15c2f046c0..91130d81825085ade539fa054738c907b6e122de 100644 (file)
@@ -7,7 +7,6 @@ static struct color darkgray;
 
 static bool use_item(struct itemstack *stack)
 {
-       (void) stack;
        return true;
 }
 
index 02957da9abd6d52e2bbe5afd1c4524ff6b449c8a..a9e725c78eb8f4371229200a379ae638804f99ff 100644 (file)
@@ -10,8 +10,6 @@ struct monster_data
 
 static void monster_spawn(struct entity *self, void *data)
 {
-       (void) data;
-
        self->meta = malloc(sizeof(struct monster_data));
        ((struct monster_data *) self->meta)->timer = 0.5;
 }
@@ -62,7 +60,7 @@ static struct entity monster_entity = {
 };
 
 
-static void spawn_monster(int x, int y)
+static void spawn_monster(int x, int y, enum mg_context ctx)
 {
        spawn(monster_entity, x, y, NULL);
 }
index dc1118d2445f87bd3a6a0236c2fe21a58a0afa7c..bac963f44c73d76b9937df0bd2629666af3d2ac2 100644 (file)
@@ -7,8 +7,6 @@
 
 static bool use_broken_sword(struct itemstack *stack)
 {
-       (void) stack;
-
        return true;
 }