diff --git a/src/extensions/foot/footext_hooks.cpp b/src/extensions/foot/footext_hooks.cpp index 8c7cafe8a..e9d35c476 100644 --- a/src/extensions/foot/footext_hooks.cpp +++ b/src/extensions/foot/footext_hooks.cpp @@ -30,7 +30,11 @@ #include "technoext.h" #include "technotype.h" #include "technotypeext.h" +#include "tibsun_inline.h" #include "house.h" +#include "rules.h" +#include "rulesext.h" +#include "target.h" #include "fatal.h" #include "asserthandler.h" #include "debughandler.h" @@ -39,6 +43,65 @@ #include "hooker_macros.h" +/** + * #issue-595 + * + * Implements IsCanRecalcApproachTarget for TechnoTypes. + * + * @author: CCHyper + */ +static short NavCom_TarCom_Distance(FootClass *this_ptr) { return Distance(this_ptr->NavCom->Center_Coord(), this_ptr->TarCom->Center_Coord()); } +static int Multiply_Integer(int a, double b) { return (a * b); } +DECLARE_PATCH(_FootClass_Approach_Target_Can_Recalc_Approach_Target_Patch) +{ + GET_REGISTER_STATIC(FootClass *, this_ptr, ebp); + GET_REGISTER_STATIC(bool, in_range, bl); + GET_STACK_STATIC(int, maxrange, esp, 0x34); + static TechnoTypeClassExtension *technotypeext; + + if (Target_Legal(this_ptr->NavCom)) { + + if (Target_Legal(this_ptr->TarCom)) { + + technotypeext = TechnoTypeClassExtensions.find(this_ptr->Techno_Type_Class()); + if (technotypeext && technotypeext->IsCanRecalcApproachTarget) { + + //DEV_DEBUG_INFO("Approach_Target: CanRecalcApproachTarget branch.\n"); + + if (!in_range) { + + static double reset_multiplier = 1.0; + if (RulesExtension) { + reset_multiplier = RulesExtension->ApproachTargetResetMultiplier; + } + + if (NavCom_TarCom_Distance(this_ptr) > Multiply_Integer(maxrange, reset_multiplier)) { + DEV_DEBUG_INFO("Approach_Target: Clearing NavCom.\n"); + this_ptr->NavCom = nullptr; + } + + } + + } + + } + + if (Target_Legal(this_ptr->NavCom)) { + if (!this_ptr->In_Air()) { + goto function_return; + } + } + } + + _asm { mov bl, byte ptr [in_range] } // restore BL register. + + JMP(0x004A2004); + +function_return: + JMP(0x004A2813); +} + + /** * #issue-595 * @@ -335,4 +398,5 @@ void FootClassExtension_Hooks() Patch_Jump(0x004A1AAE, &_FootClass_Mission_Guard_Can_Passive_Acquire_Patch); Patch_Jump(0x004A102F, &_FootClass_Mission_Move_Can_Passive_Acquire_Patch); Patch_Jump(0x004A1EA8, &_FootClass_Approach_Target_Can_Approach_Patch); + Patch_Jump(0x004A1FEA, &_FootClass_Approach_Target_Can_Recalc_Approach_Target_Patch); } diff --git a/src/extensions/technotype/technotypeext.cpp b/src/extensions/technotype/technotypeext.cpp index 0257eb4f7..bc91c9133 100644 --- a/src/extensions/technotype/technotypeext.cpp +++ b/src/extensions/technotype/technotypeext.cpp @@ -58,6 +58,7 @@ TechnoTypeClassExtension::TechnoTypeClassExtension(TechnoTypeClass *this_ptr) : IsCanPassiveAcquire(true), IsCanRetaliate(true), IsCanApproachTarget(true), + IsCanRecalcApproachTarget(true), ShakePixelYHi(0), ShakePixelYLo(0), ShakePixelXHi(0), @@ -261,6 +262,7 @@ bool TechnoTypeClassExtension::Read_INI(CCINIClass &ini) IsCanPassiveAcquire = ini.Get_Bool(ini_name, "CanPassiveAcquire", IsCanPassiveAcquire); IsCanRetaliate = ini.Get_Bool(ini_name, "CanRetaliate", IsCanRetaliate); IsCanApproachTarget = ini.Get_Bool(ini_name, "CanApproachTarget", IsCanApproachTarget); + IsCanRecalcApproachTarget = ini.Get_Bool(ini_name, "CanRecalcApproachTarget", IsCanRecalcApproachTarget); ShakePixelYHi = ini.Get_Int(ini_name, "ShakeYhi", ShakePixelYHi); ShakePixelYLo = ini.Get_Int(ini_name, "ShakeYlo", ShakePixelYLo); ShakePixelXHi = ini.Get_Int(ini_name, "ShakeXhi", ShakePixelXHi); diff --git a/src/extensions/technotype/technotypeext.h b/src/extensions/technotype/technotypeext.h index 43845ddd5..daa71a2c0 100644 --- a/src/extensions/technotype/technotypeext.h +++ b/src/extensions/technotype/technotypeext.h @@ -95,6 +95,12 @@ class TechnoTypeClassExtension final : public Extension */ bool IsCanApproachTarget; + /** + * Can this unit recalculate what its next target will be when conducting + * its threat scan if its current target is out of range? + */ + bool IsCanRecalcApproachTarget; + /** * These values are used to shake the screen when the object is destroyed. */