Implemented configurable randomization in the world builder, and then got the beginning of devices to work for the next part of going down a level through stairs.
This commit is contained in:
parent
7acbd0379f
commit
d2162910f6
10 changed files with 73 additions and 36 deletions
|
@ -185,17 +185,27 @@ DinkyECS::Entity configure_entity_in_map(DinkyECS::World &world, Map &game_map,
|
|||
return item;
|
||||
}
|
||||
|
||||
inline json &select_entity_type(GameConfig &config, json &gen_config) {
|
||||
int enemy_test = Random::uniform<int>(0,100);
|
||||
int device_test = Random::uniform<int>(0, 100);
|
||||
|
||||
if(enemy_test < gen_config["enemy_probability"]) {
|
||||
return config.enemies.json();
|
||||
} else if(device_test < gen_config["device_probability"]) {
|
||||
return config.devices.json();
|
||||
} else {
|
||||
return config.items.json();
|
||||
}
|
||||
}
|
||||
|
||||
void WorldBuilder::randomize_entities(DinkyECS::World &world, GameConfig &config) {
|
||||
auto &gen_config = config.game["worldgen"];
|
||||
|
||||
|
||||
for(size_t room_num = $map.room_count() - 1; room_num > 0; room_num--) {
|
||||
int empty_room = Random::uniform<int>(0, 100);
|
||||
if(empty_room < gen_config["empty_room_probability"]) continue;
|
||||
|
||||
int rand_type = Random::uniform<int>(0,100);
|
||||
json& entity_db = rand_type < gen_config["enemy_probability"] ? config.enemies.json() : config.items.json();
|
||||
json& entity_db = select_entity_type(config, gen_config);
|
||||
|
||||
std::vector<std::string> keys;
|
||||
for(auto &el : entity_db.items()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue