There's now a config to control the random world gen a bit.

This commit is contained in:
Zed A. Shaw 2025-01-14 15:16:24 -05:00
parent b16405cfdc
commit 7acbd0379f
4 changed files with 22 additions and 19 deletions

View file

@ -187,26 +187,28 @@ DinkyECS::Entity configure_entity_in_map(DinkyECS::World &world, Map &game_map,
void WorldBuilder::randomize_entities(DinkyECS::World &world, GameConfig &config) {
int rand_type = Random::uniform<int>(0,1);
json entity_db = rand_type == 0 ? config.enemies.json() : config.items.json();
auto &gen_config = config.game["worldgen"];
std::vector<std::string> keys;
for(auto &el : entity_db.items()) {
keys.push_back(el.key());
}
for(size_t room_num = $map.room_count() - 1; room_num > 0; room_num--) {
int has_entity = Random::uniform<int>(0, 1);
int empty_room = Random::uniform<int>(0, 100);
if(empty_room < gen_config["empty_room_probability"]) continue;
if(has_entity == 0) {
int rand_entity = Random::uniform<int>(0, keys.size() - 1);
std::string key = keys[rand_entity];
auto entity_data = entity_db[key];
int rand_type = Random::uniform<int>(0,100);
json& entity_db = rand_type < gen_config["enemy_probability"] ? config.enemies.json() : config.items.json();
// pass that to the config as it'll be a generic json
auto entity = configure_entity_in_map(world, $map, entity_data, room_num);
(void)entity;
std::vector<std::string> keys;
for(auto &el : entity_db.items()) {
keys.push_back(el.key());
}
int rand_entity = Random::uniform<int>(0, keys.size() - 1);
std::string key = keys[rand_entity];
auto entity_data = entity_db[key];
// pass that to the config as it'll be a generic json
auto entity = configure_entity_in_map(world, $map, entity_data, room_num);
(void)entity;
}
}