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.

main
Zed A. Shaw 7 days ago
parent 7acbd0379f
commit d2162910f6
  1. 5
      assets/config.json
  2. 26
      assets/devices.json
  3. 22
      assets/items.json
  4. 7
      components.hpp
  5. 3
      save.cpp
  6. 2
      status.txt
  7. 23
      systems.cpp
  8. 1
      systems.hpp
  9. 4
      tests/matrix.cpp
  10. 16
      worldbuilder.cpp

@ -6,7 +6,8 @@
}, },
"worldgen": { "worldgen": {
"enemy_probability": 60, "enemy_probability": 20,
"empty_room_probability": 20 "empty_room_probability": 20,
"device_probability": 20
} }
} }

@ -0,0 +1,26 @@
{
"STAIRS_DOWN": {
"id": "STAIRS_DOWN",
"name": "Stairs Down",
"foreground": [24, 205, 189],
"background": [24, 205, 189],
"description": "Stairs that go down further into the dungeon.",
"inventory_count": 0,
"components": [
{"type": "Tile", "config": {"chr": "\u2ac5"}},
{"type": "Device", "config": {"active": true}}
]
},
"STAIRS_UP": {
"id": "STAIRS_UP",
"name": "Stairs Up",
"foreground": [24, 205, 189],
"background": [24, 205, 189],
"description": "Stairs that go up, for the weak.",
"inventory_count": 0,
"components": [
{"type": "Tile", "config": {"chr": "\u2259"}},
{"type": "Device", "config": {"active": true}}
]
}
}

@ -71,27 +71,5 @@
{"type": "Tile", "config": {"chr": "\u03eb"}}, {"type": "Tile", "config": {"chr": "\u03eb"}},
{"type": "Curative", "config": {"hp": 20}} {"type": "Curative", "config": {"hp": 20}}
] ]
},
"STAIRS_DOWN": {
"id": "STAIRS_DOWN",
"name": "Stairs Down",
"foreground": [24, 205, 189],
"background": [24, 205, 189],
"description": "Stairs that go down further into the dungeon.",
"inventory_count": 0,
"components": [
{"type": "Tile", "config": {"chr": "\u2ac5"}}
]
},
"STAIRS_UP": {
"id": "STAIRS_UP",
"name": "Stairs Up",
"foreground": [24, 205, 189],
"background": [24, 205, 189],
"description": "Stairs that go up, for the weak.",
"inventory_count": 0,
"components": [
{"type": "Tile", "config": {"chr": "\u2259"}}
]
} }
} }

@ -6,6 +6,10 @@
#include "config.hpp" #include "config.hpp"
namespace components { namespace components {
struct Device {
bool active = 0;
};
struct Player { struct Player {
DinkyECS::Entity entity; DinkyECS::Entity entity;
DEFINE_SERIALIZABLE(Player, entity); DEFINE_SERIALIZABLE(Player, entity);
@ -38,6 +42,7 @@ namespace components {
Config enemies; Config enemies;
Config items; Config items;
Config tiles; Config tiles;
Config devices;
}; };
struct EnemyConfig { struct EnemyConfig {
@ -77,6 +82,8 @@ namespace components {
world.set<Curative>(entity, {config["hp"]}); world.set<Curative>(entity, {config["hp"]});
} else if(comp["type"] == "Motion") { } else if(comp["type"] == "Motion") {
world.set<Motion>(entity, {config["dx"], config["dy"], config["random"]}); world.set<Motion>(entity, {config["dx"], config["dy"], config["random"]});
} else if(comp["type"] == "Device") {
world.set<Device>(entity, {config["active"]});
} else { } else {
dbc::sentinel(fmt::format("ITEM COMPONENT TYPE MISSING: {}", dbc::sentinel(fmt::format("ITEM COMPONENT TYPE MISSING: {}",
std::string(comp["type"]))); std::string(comp["type"])));

@ -88,8 +88,9 @@ void save::load_configs(DinkyECS::World &world) {
Config enemies("./assets/enemies.json"); Config enemies("./assets/enemies.json");
Config items("./assets/items.json"); Config items("./assets/items.json");
Config tiles("./assets/tiles.json"); Config tiles("./assets/tiles.json");
Config devices("./assets/devices.json");
world.set_the<GameConfig>({ world.set_the<GameConfig>({
game, enemies, items, tiles game, enemies, items, tiles, devices
}); });
} }

@ -1,5 +1,7 @@
TODAY'S GOAL: TODAY'S GOAL:
* Linux on Arch catch2 fails with catch2-main missing and xwayland displays weird when small (gentoo plasma6 wayland).
* Position needs three types of collision: full, false, and none.
* Stairs \u2ac5 for stairs down, and \u2259 stairs up * Stairs \u2ac5 for stairs down, and \u2259 stairs up
* UNKNOWN COLLISION TYPE 6 * UNKNOWN COLLISION TYPE 6

@ -56,15 +56,16 @@ void System::init_positions(DinkyECS::World &world) {
// BUG: instead of separate things maybe just one // BUG: instead of separate things maybe just one
// BUG: Collision component that references what is collide // BUG: Collision component that references what is collide
world.query<Position, Combat>([&](const auto &ent, auto &pos, auto &combat) { world.query<Position>([&](const auto &ent, auto &pos) {
if(!combat.dead) { if(world.has<Combat>(ent)) {
const auto& combat = world.get<Combat>(ent);
if(!combat.dead) {
collider.insert(pos.location, ent);
}
} else {
collider.insert(pos.location, ent); collider.insert(pos.location, ent);
} }
}); });
world.query<Position>([&](const auto &ent, auto &pos) {
collider.insert(pos.location, ent);
});
} }
inline void move_entity(SpatialMap &collider, Map &game_map, Position &position, Motion &motion, DinkyECS::Entity ent) { inline void move_entity(SpatialMap &collider, Map &game_map, Position &position, Motion &motion, DinkyECS::Entity ent) {
@ -175,6 +176,8 @@ void System::collision(DinkyECS::World &world, Player &player) {
world.remove<Tile>(entity); world.remove<Tile>(entity);
world.remove<InventoryItem>(entity); world.remove<InventoryItem>(entity);
world.send<Events::GUI>(Events::GUI::LOOT, entity, item); world.send<Events::GUI>(Events::GUI::LOOT, entity, item);
} else if(world.has<Device>(entity)) {
System::device(world, player.entity, entity);
} else { } else {
println("UNKNOWN COLLISION TYPE {}", entity); println("UNKNOWN COLLISION TYPE {}", entity);
} }
@ -211,3 +214,11 @@ void System::pickup(DinkyECS::World &world, DinkyECS::Entity actor, DinkyECS::En
inventory.add(invitem); inventory.add(invitem);
} }
void System::device(DinkyECS::World &world, DinkyECS::Entity actor, DinkyECS::Entity item) {
auto& device = world.get<Device>(item);
if(device.active) {
println("entity {} INTERACTED WITH DEVICE {}", actor, item);
device.active = false;
}
}

@ -17,4 +17,5 @@ namespace System {
void draw_entities(DinkyECS::World &world, Map &game_map, const Matrix &lighting, ftxui::Canvas &canvas, const Point &cam_orig, size_t view_x, size_t view_y); void draw_entities(DinkyECS::World &world, Map &game_map, const Matrix &lighting, ftxui::Canvas &canvas, const Point &cam_orig, size_t view_x, size_t view_y);
void init_positions(DinkyECS::World &world); void init_positions(DinkyECS::World &world);
void pickup(DinkyECS::World &world, DinkyECS::Entity actor, DinkyECS::Entity item); void pickup(DinkyECS::World &world, DinkyECS::Entity actor, DinkyECS::Entity item);
void device(DinkyECS::World &world, DinkyECS::Entity actor, DinkyECS::Entity item);
} }

@ -305,7 +305,7 @@ TEST_CASE("random rectangle", "[matrix:rando_rect]") {
} }
} }
matrix::dump("WALLS FILLED", wall_copy); // matrix::dump("WALLS FILLED", wall_copy);
} }
} }
@ -339,6 +339,6 @@ TEST_CASE("standard rectangle", "[matrix:rectangle]") {
} }
} }
matrix::dump("WALLS FILLED", wall_copy); // matrix::dump("WALLS FILLED", wall_copy);
} }
} }

@ -185,17 +185,27 @@ DinkyECS::Entity configure_entity_in_map(DinkyECS::World &world, Map &game_map,
return item; 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) { void WorldBuilder::randomize_entities(DinkyECS::World &world, GameConfig &config) {
auto &gen_config = config.game["worldgen"]; auto &gen_config = config.game["worldgen"];
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 empty_room = Random::uniform<int>(0, 100); int empty_room = Random::uniform<int>(0, 100);
if(empty_room < gen_config["empty_room_probability"]) continue; if(empty_room < gen_config["empty_room_probability"]) continue;
int rand_type = Random::uniform<int>(0,100); json& entity_db = select_entity_type(config, gen_config);
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()) {

Loading…
Cancel
Save