|
|
@ -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) { |
|
|
|
void WorldBuilder::randomize_entities(DinkyECS::World &world, GameConfig &config) { |
|
|
|
int rand_type = Random::uniform<int>(0,1); |
|
|
|
auto &gen_config = config.game["worldgen"]; |
|
|
|
json entity_db = rand_type == 0 ? config.enemies.json() : config.items.json(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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--) { |
|
|
|
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_type = Random::uniform<int>(0,100); |
|
|
|
int rand_entity = Random::uniform<int>(0, keys.size() - 1); |
|
|
|
json& entity_db = rand_type < gen_config["enemy_probability"] ? config.enemies.json() : config.items.json(); |
|
|
|
std::string key = keys[rand_entity]; |
|
|
|
|
|
|
|
auto entity_data = entity_db[key]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// pass that to the config as it'll be a generic json
|
|
|
|
std::vector<std::string> keys; |
|
|
|
auto entity = configure_entity_in_map(world, $map, entity_data, room_num); |
|
|
|
for(auto &el : entity_db.items()) { |
|
|
|
(void)entity; |
|
|
|
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; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|