diff --git a/assets/enemies.json b/assets/enemies.json index 538119d..6693d80 100644 --- a/assets/enemies.json +++ b/assets/enemies.json @@ -33,7 +33,8 @@ "components": [ {"type": "Tile", "config": {"chr": "\u17a5"}}, {"type": "Combat", "config": {"hp": 100, "damage": 5}}, - {"type": "EnemyConfig", "config": {"hearing_distance": 3}} + {"type": "EnemyConfig", "config": {"hearing_distance": 15}}, + {"type": "Motion", "config": {"dx": 0, "dy": 0, "random": true}} ] }, "RAT": { diff --git a/components.hpp b/components.hpp index ad1fa7c..514eaa2 100644 --- a/components.hpp +++ b/components.hpp @@ -19,6 +19,7 @@ namespace components { struct Motion { int dx; int dy; + bool random=false; DEFINE_SERIALIZABLE(Motion, dx, dy); }; @@ -68,6 +69,8 @@ namespace components { world.set(entity, {config["hearing_distance"]}); } else if(comp["type"] == "Combat") { world.set(entity, {config["hp"], config["damage"]}); + } else if(comp["type"] == "Motion") { + world.set(entity, {config["dx"], config["dy"], config["random"]}); } else { dbc::sentinel(fmt::format("ITEM COMPONENT TYPE MISSING: {}", std::string(comp["type"]))); diff --git a/systems.cpp b/systems.cpp index 9a182df..20acb57 100644 --- a/systems.cpp +++ b/systems.cpp @@ -43,7 +43,7 @@ void System::enemy_pathing(DinkyECS::World &world, Map &game_map, Player &player Point out = position.location; // copy if(game_map.distance(out) < config.hearing_distance) { - game_map.neighbors(out); + game_map.neighbors(out, motion.random); motion = { int(out.x - position.location.x), int(out.y - position.location.y)}; } } diff --git a/worldbuilder.cpp b/worldbuilder.cpp index 376d210..297b981 100644 --- a/worldbuilder.cpp +++ b/worldbuilder.cpp @@ -192,11 +192,15 @@ DinkyECS::Entity place_combatant(DinkyECS::World &world, Map &game_map, std::str auto enemy = world.entity(); auto enemy_data = config.enemies[name]; world.set(enemy, {game_map.place_entity(in_room)}); - world.set(enemy, {0,0}); if(enemy_data.contains("components")) { components::configure(world, enemy, enemy_data); } + + if(!world.has(enemy)) { + world.set(enemy, {0,0}); + } + return enemy; }