Skip to content

Commit d75f9ef

Browse files
committed
Implements IsCanRecalcApproachTarget for TechnoTypes.
1 parent bb93481 commit d75f9ef

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

src/extensions/foot/footext_hooks.cpp

+64
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@
2929
#include "foot.h"
3030
#include "technotype.h"
3131
#include "technotypeext.h"
32+
#include "tibsun_inline.h"
3233
#include "house.h"
34+
#include "rules.h"
35+
#include "rulesext.h"
36+
#include "target.h"
3337
#include "fatal.h"
3438
#include "asserthandler.h"
3539
#include "debughandler.h"
@@ -38,6 +42,65 @@
3842
#include "hooker_macros.h"
3943

4044

45+
/**
46+
* #issue-595
47+
*
48+
* Implements IsCanRecalcApproachTarget for TechnoTypes.
49+
*
50+
* @author: CCHyper
51+
*/
52+
static short NavCom_TarCom_Distance(FootClass *this_ptr) { return Distance(this_ptr->NavCom->Center_Coord(), this_ptr->TarCom->Center_Coord()); }
53+
static int Multiply_Integer(int a, double b) { return (a * b); }
54+
DECLARE_PATCH(_FootClass_Approach_Target_Can_Recalc_Approach_Target_Patch)
55+
{
56+
GET_REGISTER_STATIC(FootClass *, this_ptr, ebp);
57+
GET_REGISTER_STATIC(bool, in_range, bl);
58+
GET_STACK_STATIC(int, maxrange, esp, 0x34);
59+
static TechnoTypeClassExtension *technotypeext;
60+
61+
if (Target_Legal(this_ptr->NavCom)) {
62+
63+
if (Target_Legal(this_ptr->TarCom)) {
64+
65+
technotypeext = TechnoTypeClassExtensions.find(this_ptr->Techno_Type_Class());
66+
if (technotypeext && technotypeext->IsCanRecalcApproachTarget) {
67+
68+
//DEV_DEBUG_INFO("Approach_Target: CanRecalcApproachTarget branch.\n");
69+
70+
if (!in_range) {
71+
72+
static double reset_multiplier = 1.0;
73+
if (RulesExtension) {
74+
reset_multiplier = RulesExtension->ApproachTargetResetMultiplier;
75+
}
76+
77+
if (NavCom_TarCom_Distance(this_ptr) > Multiply_Integer(maxrange, reset_multiplier)) {
78+
DEV_DEBUG_INFO("Approach_Target: Clearing NavCom.\n");
79+
this_ptr->NavCom = nullptr;
80+
}
81+
82+
}
83+
84+
}
85+
86+
}
87+
88+
if (Target_Legal(this_ptr->NavCom)) {
89+
if (!this_ptr->In_Air()) {
90+
goto function_return;
91+
}
92+
}
93+
}
94+
95+
_asm { mov bl, byte ptr [in_range] } // restore BL register.
96+
97+
JMP(0x004A2004);
98+
99+
function_return:
100+
JMP(0x004A2813);
101+
}
102+
103+
41104
/**
42105
* #issue-595
43106
*
@@ -189,4 +252,5 @@ void FootClassExtension_Hooks()
189252
Patch_Jump(0x004A4D60, &_FootClass_Death_Announcement_IsInsignifcant_Patch);
190253
Patch_Jump(0x004A6866, &_FootClass_Is_Allowed_To_Recloak_Cloak_Stop_BugFix_Patch);
191254
Patch_Jump(0x004A1EA8, &_FootClass_Approach_Target_Can_Approach_Patch);
255+
Patch_Jump(0x004A1FEA, &_FootClass_Approach_Target_Can_Recalc_Approach_Target_Patch);
192256
}

src/extensions/technotype/technotypeext.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ TechnoTypeClassExtension::TechnoTypeClassExtension(TechnoTypeClass *this_ptr) :
5252
IsShakeScreen(false),
5353
IsImmuneToEMP(false),
5454
IsCanApproachTarget(true),
55+
IsCanRecalcApproachTarget(true),
5556
ShakePixelYHi(0),
5657
ShakePixelYLo(0),
5758
ShakePixelXHi(0),
@@ -236,6 +237,7 @@ bool TechnoTypeClassExtension::Read_INI(CCINIClass &ini)
236237
VoiceDeploy = ini.Get_VocType_List(ini_name, "VoiceDeploy", VoiceDeploy);
237238
VoiceHarvest = ini.Get_VocType_List(ini_name, "VoiceHarvest", VoiceHarvest);
238239
IsCanApproachTarget = ini.Get_Bool(ini_name, "CanApproachTarget", IsCanApproachTarget);
240+
IsCanRecalcApproachTarget = ini.Get_Bool(ini_name, "CanRecalcApproachTarget", IsCanRecalcApproachTarget);
239241

240242
return true;
241243
}

src/extensions/technotype/technotypeext.h

+6
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ class TechnoTypeClassExtension final : public Extension<TechnoTypeClass>
8383
*/
8484
bool IsCanApproachTarget;
8585

86+
/**
87+
* Can this unit recalculate what its next target will be when conducting
88+
* its threat scan if its current target is out of range?
89+
*/
90+
bool IsCanRecalcApproachTarget;
91+
8692
/**
8793
* These values are used to shake the screen when the object is destroyed.
8894
*/

0 commit comments

Comments
 (0)