From 8e9e536353106191f66379857f64f625791bb003 Mon Sep 17 00:00:00 2001 From: CCHyper <73803386+CCHyper@users.noreply.github.com> Date: Wed, 20 Oct 2021 00:28:50 +0100 Subject: [PATCH] Implements IsCanRecalcApproachTarget for TechnoTypes. --- src/extensions/foot/footext_hooks.cpp | 64 +++++++++++++++++++++ src/extensions/technotype/technotypeext.cpp | 2 + src/extensions/technotype/technotypeext.h | 6 ++ 3 files changed, 72 insertions(+) diff --git a/src/extensions/foot/footext_hooks.cpp b/src/extensions/foot/footext_hooks.cpp index 2867be894..c67493360 100644 --- a/src/extensions/foot/footext_hooks.cpp +++ b/src/extensions/foot/footext_hooks.cpp @@ -29,7 +29,11 @@ #include "foot.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" @@ -38,6 +42,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 * @@ -231,4 +294,5 @@ void FootClassExtension_Hooks() Patch_Jump(0x004A6866, &_FootClass_Is_Allowed_To_Recloak_Cloak_Stop_BugFix_Patch); Patch_Jump(0x004A59E1, &_FootClass_AI_IdleRate_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 e8eb6e2e7..c4d9ac46e 100644 --- a/src/extensions/technotype/technotypeext.cpp +++ b/src/extensions/technotype/technotypeext.cpp @@ -52,6 +52,7 @@ TechnoTypeClassExtension::TechnoTypeClassExtension(TechnoTypeClass *this_ptr) : IsShakeScreen(false), IsImmuneToEMP(false), IsCanApproachTarget(true), + IsCanRecalcApproachTarget(true), ShakePixelYHi(0), ShakePixelYLo(0), ShakePixelXHi(0), @@ -237,6 +238,7 @@ bool TechnoTypeClassExtension::Read_INI(CCINIClass &ini) VoiceDeploy = ini.Get_VocType_List(ini_name, "VoiceDeploy", VoiceDeploy); VoiceHarvest = ini.Get_VocType_List(ini_name, "VoiceHarvest", VoiceHarvest); IsCanApproachTarget = ini.Get_Bool(ini_name, "CanApproachTarget", IsCanApproachTarget); + IsCanRecalcApproachTarget = ini.Get_Bool(ini_name, "CanRecalcApproachTarget", IsCanRecalcApproachTarget); IdleRate = ini.Get_Int(ini_name, "IdleRate", IdleRate); IdleRate = ArtINI.Get_Int(graphic_name, "IdleRate", IdleRate); diff --git a/src/extensions/technotype/technotypeext.h b/src/extensions/technotype/technotypeext.h index ab19deb6a..b579bf2e0 100644 --- a/src/extensions/technotype/technotypeext.h +++ b/src/extensions/technotype/technotypeext.h @@ -83,6 +83,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. */