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

main
Zed A. Shaw 6 days ago
parent b16405cfdc
commit 7acbd0379f
  1. 5
      assets/config.json
  2. 2
      assets/items.json
  3. 4
      lights.hpp
  4. 16
      worldbuilder.cpp

@ -5,7 +5,8 @@
"player": {
},
"type": {
"TEST": 1234
"worldgen": {
"enemy_probability": 60,
"empty_room_probability": 20
}
}

@ -7,7 +7,7 @@
"description": "A torch that barely lights the way. You wonder if it'd be better to not see the person who murders you.",
"inventory_count": 1,
"components": [
{"type": "LightSource", "config": {"strength": 100, "radius": 4.0}},
{"type": "LightSource", "config": {"strength": 70, "radius": 2.0}},
{"type": "Tile", "config": {"chr": "\u0f08"}}
]
},

@ -13,8 +13,8 @@ namespace lighting {
float radius = 1.0f;
};
const int MIN = 35;
const int MAX = 95;
const int MIN = 30;
const int MAX = 105;
class LightRender {
public:

@ -187,18 +187,21 @@ 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"];
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();
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);
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];
@ -207,7 +210,6 @@ void WorldBuilder::randomize_entities(DinkyECS::World &world, GameConfig &config
auto entity = configure_entity_in_map(world, $map, entity_data, room_num);
(void)entity;
}
}
}
void WorldBuilder::place_entities(DinkyECS::World &world) {

Loading…
Cancel
Save