From a9c74501df72592e3ecda8a63469871d653818c6 Mon Sep 17 00:00:00 2001 From: NovaRain Date: Thu, 7 May 2020 09:47:57 +0800 Subject: [PATCH] Added checking AP cost to ai_pick_hit_mode_ engine function --- artifacts/ddraw.ini | 2 +- sfall/Modules/AI.cpp | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/artifacts/ddraw.ini b/artifacts/ddraw.ini index 5f68b62b..c35ce672 100644 --- a/artifacts/ddraw.ini +++ b/artifacts/ddraw.ini @@ -361,7 +361,7 @@ SingleCore=1 OverrideArtCacheSize=0 ;Prevents you from saving in combat except at the start of your turn to avoid a few bugs -;Note that even with this option enabled, it is still not advisable to save in combat at all. +;Note that even with this option enabled, it is still not advisable to save in combat at all (obsolete information) ;Set to 2 to block all saving in combat SaveInCombatFix=1 diff --git a/sfall/Modules/AI.cpp b/sfall/Modules/AI.cpp index 578279ab..81f68921 100644 --- a/sfall/Modules/AI.cpp +++ b/sfall/Modules/AI.cpp @@ -266,10 +266,12 @@ skip: } } -static long __fastcall CheckWeaponRangeAndDistToTarget(fo::GameObject* source, fo::GameObject* target) { +static long __fastcall CheckWeaponRangeAndApCost(fo::GameObject* source, fo::GameObject* target) { long weaponRange = fo::func::item_w_range(source, fo::ATKTYPE_RWEAPON_SECONDARY); long targetDist = fo::func::obj_dist(source, target); - return (weaponRange >= targetDist); // 0 - don't use secondary mode + if (targetDist > weaponRange) return 0; // don't use secondary mode + + return (source->critter.movePoints >= sf_item_w_mp_cost(source, fo::ATKTYPE_RWEAPON_SECONDARY, 0)); // 1 - allow secondary mode } static void __declspec(naked) ai_pick_hit_mode_hook() { @@ -281,7 +283,7 @@ static void __declspec(naked) ai_pick_hit_mode_hook() { evaluation: mov edx, edi; mov ecx, esi; - jmp CheckWeaponRangeAndDistToTarget; + jmp CheckWeaponRangeAndApCost; } } @@ -394,7 +396,7 @@ void AI::init() { 0x42A970, 0x42AA56, // ai_try_attack_ }); - // Adds a check for the weapon range and the distance to the target when AI is choosing weapon attack modes + // Adds a check for the weapon range and the AP cost when AI is choosing weapon attack modes HookCall(0x429F6D, ai_pick_hit_mode_hook); /////////////////////// Combat AI behavior fixes ///////////////////////