Added additional check to AI weapon switching fix

This commit is contained in:
NovaRain
2024-02-29 13:19:30 +08:00
parent 42ab38a333
commit 71a7545445
5 changed files with 11 additions and 8 deletions
+2 -2
View File
@@ -19,13 +19,13 @@ namespace game
namespace sf = sfall; namespace sf = sfall;
static const long aiUseItemAPCost = 2; static const long aiUseItemAPCost = 2;
/*
// Implementation of ai_can_use_weapon_ engine function with the HOOK_CANUSEWEAPON hook // Implementation of ai_can_use_weapon_ engine function with the HOOK_CANUSEWEAPON hook
bool CombatAI::ai_can_use_weapon(fo::GameObject* source, fo::GameObject* weapon, long hitMode) { bool CombatAI::ai_can_use_weapon(fo::GameObject* source, fo::GameObject* weapon, long hitMode) {
bool result = fo::func::ai_can_use_weapon(source, weapon, hitMode); bool result = fo::func::ai_can_use_weapon(source, weapon, hitMode);
return sf::CanUseWeaponHook_Invoke(result, source, weapon, hitMode); return sf::CanUseWeaponHook_Invoke(result, source, weapon, hitMode);
} }
*/
static long drugUsePerfFixMode; static long drugUsePerfFixMode;
void __stdcall CombatAI::ai_check_drugs(fo::GameObject* source) { void __stdcall CombatAI::ai_check_drugs(fo::GameObject* source) {
+1 -1
View File
@@ -15,7 +15,7 @@ class CombatAI {
public: public:
static void init(); static void init();
//static bool ai_can_use_weapon(fo::GameObject* source, fo::GameObject* weapon, long hitMode); static bool ai_can_use_weapon(fo::GameObject* source, fo::GameObject* weapon, long hitMode);
static void __stdcall ai_check_drugs(fo::GameObject* source); static void __stdcall ai_check_drugs(fo::GameObject* source);
}; };
+5 -2
View File
@@ -243,10 +243,13 @@ static long __fastcall ai_try_attack_switch_fix(fo::GameObject* target, long &hi
} }
} }
bool canUseCurr = game::CombatAI::ai_can_use_weapon(source, weapon, hitMode);
// does the NPC have other weapons in inventory? // does the NPC have other weapons in inventory?
fo::GameObject* item = fo::func::ai_search_inven_weap(source, 1, target); // search based on AP fo::GameObject* item = fo::func::ai_search_inven_weap(source, 1, target); // search based on AP
if (item) { if (item) {
// is using a close range weapon? if (!canUseCurr) return 1; // can't use current weapon, so switch anyway
// is it a close-range weapon?
long wType = fo::func::item_w_subtype(item, fo::AttackType::ATKTYPE_RWEAPON_PRIMARY); long wType = fo::func::item_w_subtype(item, fo::AttackType::ATKTYPE_RWEAPON_PRIMARY);
if (wType <= fo::AttackSubType::MELEE) { // unarmed and melee weapons, check the distance before switching if (wType <= fo::AttackSubType::MELEE) { // unarmed and melee weapons, check the distance before switching
if (!game::ai::AIHelpers::AttackInRange(source, item, target)) return -1; // target out of range, exit ai_try_attack_ if (!game::ai::AIHelpers::AttackInRange(source, item, target)) return -1; // target out of range, exit ai_try_attack_
@@ -255,7 +258,7 @@ static long __fastcall ai_try_attack_switch_fix(fo::GameObject* target, long &hi
} }
// no other weapon in inventory // no other weapon in inventory
if (fo::func::item_w_range(source, fo::AttackType::ATKTYPE_PUNCH) >= fo::func::obj_dist(source, target)) { if (!canUseCurr || fo::func::item_w_range(source, fo::AttackType::ATKTYPE_PUNCH) >= fo::func::obj_dist(source, target)) {
hitMode = fo::AttackType::ATKTYPE_PUNCH; hitMode = fo::AttackType::ATKTYPE_PUNCH;
return 0; // change hit mode, continue attack cycle return 0; // change hit mode, continue attack cycle
} }
+2 -2
View File
@@ -680,13 +680,13 @@ static void __declspec(naked) CanUseWeaponHook() {
retn; retn;
} }
} }
/*
bool CanUseWeaponHook_Invoke(bool result, fo::GameObject* source, fo::GameObject* weapon, long hitMode) { bool CanUseWeaponHook_Invoke(bool result, fo::GameObject* source, fo::GameObject* weapon, long hitMode) {
return (HookScripts::HookHasScript(HOOK_CANUSEWEAPON)) return (HookScripts::HookHasScript(HOOK_CANUSEWEAPON))
? CanUseWeaponHook_Script(result, source, weapon, hitMode) ? CanUseWeaponHook_Script(result, source, weapon, hitMode)
: result; : result;
} }
*/
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void Inject_ToHitHook() { void Inject_ToHitHook() {
+1 -1
View File
@@ -26,6 +26,6 @@ int __fastcall AmmoCostHook_Script(DWORD hookType, fo::GameObject* weapon, DWORD
long CalcApCostHook_Invoke(fo::GameObject* source, long hitMode, long isCalled, long cost, fo::GameObject* weapon); long CalcApCostHook_Invoke(fo::GameObject* source, long hitMode, long isCalled, long cost, fo::GameObject* weapon);
//void FindTargetHook_Invoke(fo::GameObject* targets[], fo::GameObject* attacker); //void FindTargetHook_Invoke(fo::GameObject* targets[], fo::GameObject* attacker);
//fo::GameObject* BestWeaponHook_Invoke(fo::GameObject* bestWeapon, fo::GameObject* source, fo::GameObject* weapon1, fo::GameObject* weapon2, fo::GameObject* target); //fo::GameObject* BestWeaponHook_Invoke(fo::GameObject* bestWeapon, fo::GameObject* source, fo::GameObject* weapon1, fo::GameObject* weapon2, fo::GameObject* target);
//bool CanUseWeaponHook_Invoke(bool result, fo::GameObject* source, fo::GameObject* weapon, long hitMode); bool CanUseWeaponHook_Invoke(bool result, fo::GameObject* source, fo::GameObject* weapon, long hitMode);
} }