]> git.lizzy.rs Git - dungeon_game.git/commitdiff
Separate air_function chances for rooms and corridors
authorElias Fleckenstein <eliasfleckenstein@web.de>
Mon, 14 Jun 2021 19:03:36 +0000 (21:03 +0200)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Mon, 14 Jun 2021 19:03:36 +0000 (21:03 +0200)
plugins/apple/apple.c
plugins/cherry/cherry.c
plugins/game/game.c
plugins/game/game.h
plugins/monster/monster.c

index 6adff086475be28f951f48de85b1efb8f6c785d7..8fbaf5be7090eae4741e006124379b4db38aef3c 100644 (file)
@@ -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,
        });
 }
index 1f96aca63986a9910e7b5866d98e24036165c645..1b0ac8a5c664c063c013dae6c8d84f74a7ba9f1f 100644 (file)
@@ -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,
        });
 }
index adcb59abf5e56746983fa0d3fcc42a3ddd95af01..cc6d21dffff5a163fba85636a2286f68db771152 100644 (file)
@@ -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);
        }
 }
index 74fea1c0eac4030549859eba3e154854f2d424e7..656217e53ac342694784db25edd8b8b34e02d739 100644 (file)
@@ -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);
 };
 
index a9e725c78eb8f4371229200a379ae638804f99ff..d140005dbddac22831cf5263681d0cef32c2d98d 100644 (file)
@@ -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,
        });
 }