From 0f4153099c2a0d8fa4480dcd690820976df4a939 Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Mon, 14 Jun 2021 20:58:57 +0200 Subject: [PATCH] Add mapgen contexts --- plugins/apple/apple.c | 2 +- plugins/cherry/cherry.c | 4 +--- plugins/fireball/fireball.c | 4 ---- plugins/game/game.c | 18 ++++-------------- plugins/game/game.h | 8 +++++++- plugins/inventory/inventory.c | 1 - plugins/monster/monster.c | 4 +--- plugins/sword/sword.c | 2 -- 8 files changed, 14 insertions(+), 29 deletions(-) diff --git a/plugins/apple/apple.c b/plugins/apple/apple.c index 795800d..6adff08 100644 --- a/plugins/apple/apple.c +++ b/plugins/apple/apple.c @@ -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); } diff --git a/plugins/cherry/cherry.c b/plugins/cherry/cherry.c index f998770..1f96aca 100644 --- a/plugins/cherry/cherry.c +++ b/plugins/cherry/cherry.c @@ -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); } diff --git a/plugins/fireball/fireball.c b/plugins/fireball/fireball.c index 39e93fb..a0e9a13 100644 --- a/plugins/fireball/fireball.c +++ b/plugins/fireball/fireball.c @@ -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; } diff --git a/plugins/game/game.c b/plugins/game/game.c index 94ad148..adcb59a 100644 --- a/plugins/game/game.c +++ b/plugins/game/game.c @@ -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))); diff --git a/plugins/game/game.h b/plugins/game/game.h index 21a9433..74fea1c 100644 --- a/plugins/game/game.h +++ b/plugins/game/game.h @@ -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 diff --git a/plugins/inventory/inventory.c b/plugins/inventory/inventory.c index 66f663e..91130d8 100644 --- a/plugins/inventory/inventory.c +++ b/plugins/inventory/inventory.c @@ -7,7 +7,6 @@ static struct color darkgray; static bool use_item(struct itemstack *stack) { - (void) stack; return true; } diff --git a/plugins/monster/monster.c b/plugins/monster/monster.c index 02957da..a9e725c 100644 --- a/plugins/monster/monster.c +++ b/plugins/monster/monster.c @@ -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); } diff --git a/plugins/sword/sword.c b/plugins/sword/sword.c index dc1118d..bac963f 100644 --- a/plugins/sword/sword.c +++ b/plugins/sword/sword.c @@ -7,8 +7,6 @@ static bool use_broken_sword(struct itemstack *stack) { - (void) stack; - return true; } -- 2.44.0