Skip to content

Commit cc755ba

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

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

src/extensions/foot/footext_hooks.cpp

+63
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,64 @@
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+
DECLARE_PATCH(_FootClass_Approach_Target_Can_Recalc_Approach_Target_Patch)
54+
{
55+
GET_REGISTER_STATIC(FootClass *, this_ptr, ebp);
56+
GET_REGISTER_STATIC(bool, in_range, bl);
57+
GET_STACK_STATIC(int, maxrange, esp, 0x34);
58+
static TechnoTypeClassExtension *technotypeext;
59+
60+
if (Target_Legal(this_ptr->NavCom)) {
61+
62+
if (Target_Legal(this_ptr->TarCom)) {
63+
64+
technotypeext = TechnoTypeClassExtensions.find(this_ptr->Techno_Type_Class());
65+
if (technotypeext && technotypeext->IsCanRecalcApproachTarget) {
66+
67+
DEV_DEBUG_INFO("Approach_Target: CanRecalcApproachTarget branch.\n");
68+
69+
if (!in_range) {
70+
71+
static double reset_multiplier = 1.0;
72+
if (RulesExtension) {
73+
reset_multiplier = RulesExtension->ApproachTargetResetMultiplier;
74+
}
75+
76+
if (Distance(this_ptr->NavCom->Center_Coord(), this_ptr->TarCom->Center_Coord()) > (maxrange * reset_multiplier)) {
77+
DEV_DEBUG_INFO("Approach_Target: Clearing NavCom.\n");
78+
this_ptr->NavCom = nullptr;
79+
}
80+
81+
}
82+
83+
}
84+
85+
}
86+
87+
if (Target_Legal(this_ptr->NavCom)) {
88+
if (!this_ptr->In_Air()) {
89+
goto function_return;
90+
}
91+
}
92+
}
93+
94+
_asm { mov bl, byte ptr [in_range] } // restore BL register.
95+
96+
JMP(0x004A2004);
97+
98+
function_return:
99+
JMP(0x004A2813);
100+
}
101+
102+
41103
/**
42104
* #issue-595
43105
*
@@ -189,4 +251,5 @@ void FootClassExtension_Hooks()
189251
Patch_Jump(0x004A4D60, &_FootClass_Death_Announcement_IsInsignifcant_Patch);
190252
Patch_Jump(0x004A6866, &_FootClass_Is_Allowed_To_Recloak_Cloak_Stop_BugFix_Patch);
191253
Patch_Jump(0x004A1EA8, &_FootClass_Approach_Target_Can_Approach_Patch);
254+
Patch_Jump(0x004A1FEA, &_FootClass_Approach_Target_Can_Recalc_Approach_Target_Patch);
192255
}

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)