From 9e0af0151c45fa0f28892ccdfa0c75fdfc9b36ff Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Fri, 29 Aug 2025 10:43:33 -0500 Subject: [PATCH] Monsters don't backtrack in combat move. fix #796 --- src/game/boe.combat.cpp | 5 ++++- src/game/boe.monster.cpp | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/game/boe.combat.cpp b/src/game/boe.combat.cpp index 94c2f2f0b..36602996e 100644 --- a/src/game/boe.combat.cpp +++ b/src/game/boe.combat.cpp @@ -2053,6 +2053,9 @@ static std::vector list_enemy_monsters(short m_num) { return enemies; } +std::set monst_path_this_turn; + +// This is for combat mode! See do_monsters() in boe.monster.cpp for peace behavior void do_monster_turn() { bool acted_yet, had_monst = false,printed_poison = false,printed_disease = false,printed_acid = false; bool redraw_not_yet_done = true; @@ -2165,7 +2168,7 @@ void do_monster_turn() { else pc_adj[j] = false; - + monst_path_this_turn = {cur_monst->cur_loc}; while((cur_monst->ap > 0) && (cur_monst->is_alive())) { // Spend each action point if(is_combat()) { // Pick target. If in town, target already picked diff --git a/src/game/boe.monster.cpp b/src/game/boe.monster.cpp index e8ff37963..fa93a7d77 100644 --- a/src/game/boe.monster.cpp +++ b/src/game/boe.monster.cpp @@ -28,6 +28,7 @@ extern location center; extern short boom_gr[8],futzing; extern bool processing_fields,monsters_going; extern cUniverse univ; +extern std::set monst_path_this_turn; short out_enc_lev_tot(short which) { short count = 0; @@ -190,6 +191,7 @@ void set_up_monst(eAttitude mode,mon_num_t m_num) { univ.town.monst[which].mobility = 1; } +// This is for peace mode! See do_monster_turn() in boe.combat.cpp for combat behavior void do_monsters() { short r1,target; location l1,l2; @@ -342,7 +344,9 @@ bool monst_hate_spot(short which_m,location *good_loc) { } if(hate_spot) { prospect = find_clear_spot(loc,1,univ.town.monst[which_m].x_width,univ.town.monst[which_m].y_width); - if(prospect.x > 0) { + // If the monster was already on that spot this turn, backtracking is not a good idea! + // It will probably just repeat the same move (i.e. walking onto a damaging field repeatedly) + if(prospect.x > 0 && monst_path_this_turn.find(prospect) == monst_path_this_turn.end()) { *good_loc = prospect; return true; } @@ -715,6 +719,7 @@ bool combat_move_monster(short which,location destination) { return false; } else { + monst_path_this_turn.insert(destination); univ.town.monst[which].direction = set_direction(univ.town.monst[which].cur_loc, destination); univ.town.monst[which].cur_loc = destination; monst_inflict_fields(which);