From fc8e65f4d6bd6c88104416b9ccb30f2b5781181b Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Fri, 22 Aug 2025 22:29:22 -0400 Subject: [PATCH] Enemies how fight back when cornered, either by being blocked by another enemy or when at a dead end walls. --- battle.cpp | 2 ++ gui/fsm.cpp | 1 - systems.cpp | 8 ++++++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/battle.cpp b/battle.cpp index e6066e7..4709f3d 100644 --- a/battle.cpp +++ b/battle.cpp @@ -15,8 +15,10 @@ namespace combat { if(enemy.ai.active()) { if(enemy.ai.wants_to("kill_enemy")) { + fmt::println(">> enemy {} wants to KILL", entity); pending_actions.emplace_back(enemy, BattleAction::ATTACK); } else if(enemy.ai.wants_to("run_away")) { + fmt::println(">> enemy {} wants to RUN", entity); pending_actions.emplace_back(enemy, BattleAction::ESCAPE); } } diff --git a/gui/fsm.cpp b/gui/fsm.cpp index 2c57a72..ae7b998 100644 --- a/gui/fsm.cpp +++ b/gui/fsm.cpp @@ -194,7 +194,6 @@ namespace gui { } } break; case MOUSE_CLICK: - fmt::println("CLICK: {}", $router.left_button); mouse_action(guecs::NO_MODS); break; case MOUSE_MOVE: { diff --git a/systems.cpp b/systems.cpp index c232fee..ac8d7b1 100644 --- a/systems.cpp +++ b/systems.cpp @@ -102,16 +102,20 @@ void System::enemy_pathing() { if(ent != level.player) { auto& enemy_ai = world.get(ent); Point out = position.location; // copy + bool found_path = false; if(enemy_ai.wants_to("find_enemy")) { - map.random_walk(out, motion.random, PATHING_TOWARD); + found_path = map.random_walk(out, motion.random, PATHING_TOWARD); } else if(enemy_ai.wants_to("run_away")) { - map.random_walk(out, motion.random, PATHING_AWAY); + found_path = map.random_walk(out, motion.random, PATHING_AWAY); } else { motion = {0,0}; return; // enemy doesn't want to move } + enemy_ai.set_state("cant_move", !found_path); + enemy_ai.update(); + motion = { int(out.x - position.location.x), int(out.y - position.location.y)}; } });