Skip to content

Commit

Permalink
Implements IsCanRecalcApproachTarget for TechnoTypes.
Browse files Browse the repository at this point in the history
  • Loading branch information
CCHyper committed Oct 20, 2021
1 parent bb93481 commit d75f9ef
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
64 changes: 64 additions & 0 deletions src/extensions/foot/footext_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
*
Expand Down Expand Up @@ -189,4 +252,5 @@ void FootClassExtension_Hooks()
Patch_Jump(0x004A4D60, &_FootClass_Death_Announcement_IsInsignifcant_Patch);
Patch_Jump(0x004A6866, &_FootClass_Is_Allowed_To_Recloak_Cloak_Stop_BugFix_Patch);
Patch_Jump(0x004A1EA8, &_FootClass_Approach_Target_Can_Approach_Patch);
Patch_Jump(0x004A1FEA, &_FootClass_Approach_Target_Can_Recalc_Approach_Target_Patch);
}
2 changes: 2 additions & 0 deletions src/extensions/technotype/technotypeext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ TechnoTypeClassExtension::TechnoTypeClassExtension(TechnoTypeClass *this_ptr) :
IsShakeScreen(false),
IsImmuneToEMP(false),
IsCanApproachTarget(true),
IsCanRecalcApproachTarget(true),
ShakePixelYHi(0),
ShakePixelYLo(0),
ShakePixelXHi(0),
Expand Down Expand Up @@ -236,6 +237,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);

return true;
}
6 changes: 6 additions & 0 deletions src/extensions/technotype/technotypeext.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ class TechnoTypeClassExtension final : public Extension<TechnoTypeClass>
*/
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.
*/
Expand Down

0 comments on commit d75f9ef

Please sign in to comment.