From cd6d55fe7502aa8c0f6d9bd85017d0620f6bcb2b Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Tue, 13 Aug 2024 22:31:23 +0000 Subject: [PATCH] Do not try to shoot at 2nd hex of wide creatures --- AI/BattleAI/AttackPossibility.cpp | 2 +- lib/CConsoleHandler.cpp | 6 ++++-- lib/battle/CBattleInfoCallback.cpp | 3 +++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/AI/BattleAI/AttackPossibility.cpp b/AI/BattleAI/AttackPossibility.cpp index d663a1bf4..ced430425 100644 --- a/AI/BattleAI/AttackPossibility.cpp +++ b/AI/BattleAI/AttackPossibility.cpp @@ -245,7 +245,7 @@ AttackPossibility AttackPossibility::evaluate( std::vector defenderHex; if(attackInfo.shooting) - defenderHex = defender->getHexes(); + defenderHex.push_back(defender->getPosition()); else defenderHex = CStack::meleeAttackHexes(attacker, defender, hex); diff --git a/lib/CConsoleHandler.cpp b/lib/CConsoleHandler.cpp index 8f1b0096e..c3dbd6fce 100644 --- a/lib/CConsoleHandler.cpp +++ b/lib/CConsoleHandler.cpp @@ -168,6 +168,7 @@ LONG WINAPI onUnhandledException(EXCEPTION_POINTERS* exception) #endif +#ifdef NDEBUG [[noreturn]] static void onTerminate() { logGlobal->error("Disaster happened."); @@ -205,6 +206,7 @@ LONG WINAPI onUnhandledException(EXCEPTION_POINTERS* exception) #endif std::abort(); } +#endif void CConsoleHandler::setColor(EConsoleTextColor::EConsoleTextColor color) { @@ -296,14 +298,14 @@ CConsoleHandler::CConsoleHandler(): GetConsoleScreenBufferInfo(handleErr, &csbi); defErrColor = csbi.wAttributes; -#ifndef _DEBUG +#ifdef NDEBUG SetUnhandledExceptionFilter(onUnhandledException); #endif #else defColor = "\x1b[0m"; #endif -#ifndef _DEBUG +#ifdef NDEBUG std::set_terminate(onTerminate); #endif } diff --git a/lib/battle/CBattleInfoCallback.cpp b/lib/battle/CBattleInfoCallback.cpp index 9e17542f1..ae1ca02cb 100644 --- a/lib/battle/CBattleInfoCallback.cpp +++ b/lib/battle/CBattleInfoCallback.cpp @@ -173,6 +173,9 @@ bool CBattleInfoCallback::battleIsInsideWalls(BattleHex from) const bool CBattleInfoCallback::battleHasPenaltyOnLine(BattleHex from, BattleHex dest, bool checkWall, bool checkMoat) const { + if (!from.isAvailable() || !dest.isAvailable()) + throw std::runtime_error("Invalid hex (" + std::to_string(from.hex) + " and " + std::to_string(dest.hex) + ") received in battleHasPenaltyOnLine!" ); + auto isTileBlocked = [&](BattleHex tile) { EWallPart wallPart = battleHexToWallPart(tile);