mirror of
https://github.com/sfall-team/sfall.git
synced 2026-07-27 16:52:34 -07:00
Added two fixes for NPC fleeing in combat.
* added fix to allow fleeing NPC to use drugs. * fixed NPC stuck in fleeing mode when the hit chance of a target was too low.
This commit is contained in:
@@ -29,6 +29,30 @@ typedef stdext::hash_map<DWORD, DWORD>::const_iterator iter;
|
||||
static stdext::hash_map<DWORD, DWORD> targets;
|
||||
static stdext::hash_map<DWORD, DWORD> sources;
|
||||
|
||||
static void __declspec(naked) ai_try_attack_hook_FleeFix() {
|
||||
__asm {
|
||||
call ai_run_away_;
|
||||
mov dword ptr [esi + 0x54], 0; // critter.who_hit_me
|
||||
and byte ptr [esi + 0x3C], ~4; // unset flee flag
|
||||
retn;
|
||||
}
|
||||
}
|
||||
|
||||
static const DWORD combat_ai_hook_flee_Ret = 0x42B22F;
|
||||
static void __declspec(naked) combat_ai_hook_FleeFix() {
|
||||
__asm {
|
||||
call ai_check_drugs_; // try to heal
|
||||
test byte ptr [ebp], 4; // flee flag? (critter.combat_state)
|
||||
jnz flee;
|
||||
add esp, 4;
|
||||
jmp combat_ai_hook_flee_Ret;
|
||||
flee:
|
||||
mov eax, esi
|
||||
call critter_name_;
|
||||
retn;
|
||||
}
|
||||
}
|
||||
|
||||
static DWORD RetryCombatLastAP;
|
||||
static DWORD RetryCombatMinAP;
|
||||
static void __declspec(naked) RetryCombatHook() {
|
||||
@@ -138,6 +162,16 @@ void AIInit() {
|
||||
HookCall(0x422B94, RetryCombatHook); // combat_turn_
|
||||
dlogr(" Done", DL_INIT);
|
||||
}
|
||||
|
||||
/////////////////////// Combat AI behavior fixes ///////////////////////
|
||||
|
||||
// Fix to allow fleeing NPC to use drugs
|
||||
HookCall(0x42B1E3, combat_ai_hook_FleeFix);
|
||||
// Fix for NPC stuck in fleeing mode when the hit chance of a target was too low
|
||||
HookCall(0x42ABA8, ai_try_attack_hook_FleeFix);
|
||||
HookCall(0x42ACE5, ai_try_attack_hook_FleeFix);
|
||||
// Disable fleeing when NPC cannot move closer to target
|
||||
BlockCall(0x42ADF6); // ai_try_attack_
|
||||
}
|
||||
|
||||
DWORD _stdcall AIGetLastAttacker(DWORD target) {
|
||||
|
||||
@@ -223,6 +223,10 @@ DWORD* ptr_YellowColor = reinterpret_cast<DWORD*>(_YellowColor);
|
||||
|
||||
// AI FUNCTIONS
|
||||
const DWORD ai_can_use_weapon_ = 0x4298EC; // (TGameObj *aCritter<eax>, int aWeapon<edx>, int a2Or3<ebx>) returns 1 or 0
|
||||
const DWORD ai_check_drugs_ = 0x428480;
|
||||
const DWORD ai_run_away_ = 0x428868;
|
||||
const DWORD ai_search_inven_armor_ = 0x429A6C;
|
||||
const DWORD ai_try_attack_ = 0x42A7D8;
|
||||
|
||||
// UI FUNCTIONS
|
||||
const DWORD interface_disable_ = 0x45EAFC;
|
||||
@@ -243,8 +247,6 @@ const DWORD add_bar_box_ = 0x4616F0;
|
||||
const DWORD AddHotLines_ = 0x4998C0;
|
||||
const DWORD adjust_ac_ = 0x4715F8;
|
||||
const DWORD adjust_fid_ = 0x4716E8;
|
||||
const DWORD ai_search_inven_armor_ = 0x429A6C;
|
||||
const DWORD ai_try_attack_ = 0x42A7D8;
|
||||
const DWORD art_alias_num_ = 0x419998;
|
||||
const DWORD art_exists_ = 0x4198C8; // eax - frameID, used for critter FIDs
|
||||
const DWORD art_flush_ = 0x41927C;
|
||||
|
||||
@@ -466,6 +466,8 @@ extern const DWORD AddHotLines_;
|
||||
extern const DWORD adjust_ac_;
|
||||
extern const DWORD adjust_fid_;
|
||||
extern const DWORD ai_can_use_weapon_; // (TGameObj *aCritter<eax>, int aWeapon<edx>, int a2Or3<ebx>) returns 1 or 0
|
||||
extern const DWORD ai_check_drugs_;
|
||||
extern const DWORD ai_run_away_;
|
||||
extern const DWORD ai_search_inven_armor_;
|
||||
extern const DWORD ai_try_attack_;
|
||||
extern const DWORD art_alias_num_;
|
||||
|
||||
Reference in New Issue
Block a user