Separate air_function chances for rooms and corridors

master
Elias Fleckenstein 2021-06-14 21:03:36 +02:00
parent 0f4153099c
commit 9d3ecc266d
5 changed files with 9 additions and 5 deletions

View 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,
});
}

View 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,
});
}

View 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);
}
}

View 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);
};

View 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,
});
}