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

main
Zed A. Shaw 7 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": { "player": {
}, },
"type": { "worldgen": {
"TEST": 1234 "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.", "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, "inventory_count": 1,
"components": [ "components": [
{"type": "LightSource", "config": {"strength": 100, "radius": 4.0}}, {"type": "LightSource", "config": {"strength": 70, "radius": 2.0}},
{"type": "Tile", "config": {"chr": "\u0f08"}} {"type": "Tile", "config": {"chr": "\u0f08"}}
] ]
}, },

@ -13,8 +13,8 @@ namespace lighting {
float radius = 1.0f; float radius = 1.0f;
}; };
const int MIN = 35; const int MIN = 30;
const int MAX = 95; const int MAX = 105;
class LightRender { class LightRender {
public: 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) { 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();
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; std::vector<std::string> keys;
for(auto &el : entity_db.items()) { for(auto &el : entity_db.items()) {
keys.push_back(el.key()); 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); int rand_entity = Random::uniform<int>(0, keys.size() - 1);
std::string key = keys[rand_entity]; std::string key = keys[rand_entity];
auto entity_data = entity_db[key]; auto entity_data = entity_db[key];
@ -208,7 +211,6 @@ void WorldBuilder::randomize_entities(DinkyECS::World &world, GameConfig &config
(void)entity; (void)entity;
} }
} }
}
void WorldBuilder::place_entities(DinkyECS::World &world) { void WorldBuilder::place_entities(DinkyECS::World &world) {
auto &config = world.get_the<GameConfig>(); auto &config = world.get_the<GameConfig>();

Loading…
Cancel
Save