From 9d3ecc266d2e06f6cc8f2a310543b16edb8cbd56 Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Mon, 14 Jun 2021 21:03:36 +0200 Subject: [PATCH] Separate air_function chances for rooms and corridors --- plugins/apple/apple.c | 3 ++- plugins/cherry/cherry.c | 3 ++- plugins/game/game.c | 2 +- plugins/game/game.h | 3 ++- plugins/monster/monster.c | 3 ++- 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/plugins/apple/apple.c b/plugins/apple/apple.c index 6adff08..8fbaf5b 100644 --- a/plugins/apple/apple.c +++ b/plugins/apple/apple.c @@ -42,7 +42,8 @@ static void spawn_apple(int x, int y, enum mg_context ctx) __attribute__((constructor)) static void init() { register_air_function((struct generator_function) { - .chance = 25, + .corridor_chance = 25, + .room_chance = 50, .callback = &spawn_apple, }); } diff --git a/plugins/cherry/cherry.c b/plugins/cherry/cherry.c index 1f96aca..1b0ac8a 100644 --- a/plugins/cherry/cherry.c +++ b/plugins/cherry/cherry.c @@ -62,7 +62,8 @@ static void spawn_cherry(int x, int y, enum mg_context ctx) __attribute__((constructor)) static void init() { register_air_function((struct generator_function) { - .chance = 100, + .corridor_chance = 100, + .room_chance = 100, .callback = &spawn_cherry, }); } diff --git a/plugins/game/game.c b/plugins/game/game.c index adcb59a..cc6d21d 100644 --- a/plugins/game/game.c +++ b/plugins/game/game.c @@ -334,7 +334,7 @@ static void mapgen_set_air(int x, int y, enum mg_context ctx) for (struct list *ptr = air_functions; ptr != NULL; ptr = ptr->next) { struct generator_function *func = ptr->element; - if (rand() % func->chance == 0) + if (rand() % (ctx == MG_CTX_CORRIDOR ? func->corridor_chance : func->room_chance) == 0) func->callback(x, y, ctx); } } diff --git a/plugins/game/game.h b/plugins/game/game.h index 74fea1c..656217e 100644 --- a/plugins/game/game.h +++ b/plugins/game/game.h @@ -71,7 +71,8 @@ enum mg_context struct generator_function { - int chance; + int corridor_chance; + int room_chance; void (*callback)(int x, int y, enum mg_context ctx); }; diff --git a/plugins/monster/monster.c b/plugins/monster/monster.c index a9e725c..d140005 100644 --- a/plugins/monster/monster.c +++ b/plugins/monster/monster.c @@ -68,7 +68,8 @@ static void spawn_monster(int x, int y, enum mg_context ctx) __attribute__((constructor)) static void init() { register_air_function((struct generator_function) { - .chance = 50, + .corridor_chance = 50, + .room_chance = 200, .callback = &spawn_monster, }); } -- 2.44.0