diff --git a/assets/config.json b/assets/config.json index c85279e..655aba2 100644 --- a/assets/config.json +++ b/assets/config.json @@ -6,7 +6,8 @@ }, "worldgen": { - "enemy_probability": 60, - "empty_room_probability": 20 + "enemy_probability": 20, + "empty_room_probability": 20, + "device_probability": 20 } } diff --git a/assets/devices.json b/assets/devices.json new file mode 100644 index 0000000..0c4c0f5 --- /dev/null +++ b/assets/devices.json @@ -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}} + ] + } +} diff --git a/assets/items.json b/assets/items.json index ed7fac5..a80a419 100644 --- a/assets/items.json +++ b/assets/items.json @@ -71,27 +71,5 @@ {"type": "Tile", "config": {"chr": "\u03eb"}}, {"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"}} - ] } } diff --git a/components.hpp b/components.hpp index 77ebcac..6b41ff0 100644 --- a/components.hpp +++ b/components.hpp @@ -6,6 +6,10 @@ #include "config.hpp" namespace components { + struct Device { + bool active = 0; + }; + struct Player { DinkyECS::Entity entity; DEFINE_SERIALIZABLE(Player, entity); @@ -38,6 +42,7 @@ namespace components { Config enemies; Config items; Config tiles; + Config devices; }; struct EnemyConfig { @@ -77,6 +82,8 @@ namespace components { world.set(entity, {config["hp"]}); } else if(comp["type"] == "Motion") { world.set(entity, {config["dx"], config["dy"], config["random"]}); + } else if(comp["type"] == "Device") { + world.set(entity, {config["active"]}); } else { dbc::sentinel(fmt::format("ITEM COMPONENT TYPE MISSING: {}", std::string(comp["type"]))); diff --git a/save.cpp b/save.cpp index 7e7bad7..031c81b 100644 --- a/save.cpp +++ b/save.cpp @@ -88,8 +88,9 @@ void save::load_configs(DinkyECS::World &world) { Config enemies("./assets/enemies.json"); Config items("./assets/items.json"); Config tiles("./assets/tiles.json"); + Config devices("./assets/devices.json"); world.set_the({ - game, enemies, items, tiles + game, enemies, items, tiles, devices }); } diff --git a/status.txt b/status.txt index 6ebf0b7..635230a 100644 --- a/status.txt +++ b/status.txt @@ -1,5 +1,7 @@ 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 * UNKNOWN COLLISION TYPE 6 diff --git a/systems.cpp b/systems.cpp index f8cd347..ef42f28 100644 --- a/systems.cpp +++ b/systems.cpp @@ -56,15 +56,16 @@ void System::init_positions(DinkyECS::World &world) { // BUG: instead of separate things maybe just one // BUG: Collision component that references what is collide - world.query([&](const auto &ent, auto &pos, auto &combat) { - if(!combat.dead) { + world.query([&](const auto &ent, auto &pos) { + if(world.has(ent)) { + const auto& combat = world.get(ent); + if(!combat.dead) { + collider.insert(pos.location, ent); + } + } else { collider.insert(pos.location, ent); } }); - - world.query([&](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) { @@ -175,6 +176,8 @@ void System::collision(DinkyECS::World &world, Player &player) { world.remove(entity); world.remove(entity); world.send(Events::GUI::LOOT, entity, item); + } else if(world.has(entity)) { + System::device(world, player.entity, entity); } else { println("UNKNOWN COLLISION TYPE {}", entity); } @@ -211,3 +214,11 @@ void System::pickup(DinkyECS::World &world, DinkyECS::Entity actor, DinkyECS::En inventory.add(invitem); } + +void System::device(DinkyECS::World &world, DinkyECS::Entity actor, DinkyECS::Entity item) { + auto& device = world.get(item); + if(device.active) { + println("entity {} INTERACTED WITH DEVICE {}", actor, item); + device.active = false; + } +} diff --git a/systems.hpp b/systems.hpp index ff96b2e..4f7c72e 100644 --- a/systems.hpp +++ b/systems.hpp @@ -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 init_positions(DinkyECS::World &world); void pickup(DinkyECS::World &world, DinkyECS::Entity actor, DinkyECS::Entity item); + void device(DinkyECS::World &world, DinkyECS::Entity actor, DinkyECS::Entity item); } diff --git a/tests/matrix.cpp b/tests/matrix.cpp index 5dd3fb9..8f162c0 100644 --- a/tests/matrix.cpp +++ b/tests/matrix.cpp @@ -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); } } diff --git a/worldbuilder.cpp b/worldbuilder.cpp index 0d57755..d3595e6 100644 --- a/worldbuilder.cpp +++ b/worldbuilder.cpp @@ -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(0,100); + int device_test = Random::uniform(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(0, 100); if(empty_room < gen_config["empty_room_probability"]) continue; - int rand_type = Random::uniform(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 keys; for(auto &el : entity_db.items()) {