Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implements CanApproachTarget and CanRecalcApproachTarget for TechnoTypes and ApproachTargetResetMultiplier for Rules. #679

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 115 additions & 0 deletions src/extensions/foot/footext_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +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"
Expand All @@ -38,6 +43,114 @@
#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
*
* Implements IsCanApproachTarget for TechnoTypes.
*
* @author: CCHyper
*/
DECLARE_PATCH(_FootClass_Approach_Target_Can_Approach_Patch)
{
GET_REGISTER_STATIC(FootClass *, this_ptr, ebp);
static TechnoTypeClassExtension *technotypeext;

technotypeext = TechnoTypeClassExtensions.find(this_ptr->Techno_Type_Class());

/**
* Stolen bytes/code.
*/
if (this_ptr->Mission == MISSION_STICKY) {
goto assign_null_target_return;
}

/**
*
*/
if (technotypeext && !technotypeext->IsCanApproachTarget) {

static bool force_approach;
force_approach = false;

if (this_ptr->Mission == MISSION_ATTACK) {
force_approach = true;
}
if (this_ptr->Mission == MISSION_GUARD_AREA && this_ptr->House->Is_Player_Control()) {
force_approach = true;
}
if ((this_ptr->Mission != MISSION_HUNT || this_ptr->House->Is_Player_Control()) && !force_approach) {
goto assign_null_target_return;
}

}

continue_checks:
JMP(0x004A1ED2);

assign_null_target_return:
JMP(0x004A1EAE);
}


/**
* #issue-593
*
Expand Down Expand Up @@ -284,4 +397,6 @@ void FootClassExtension_Hooks()
Patch_Jump(0x004A2BE7, &_FootClass_Mission_Guard_Area_Can_Passive_Acquire_Patch);
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);
}
5 changes: 4 additions & 1 deletion src/extensions/rules/rulesext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ RulesClassExtension::RulesClassExtension(RulesClass *this_ptr) :
IsMPAutoDeployMCV(false),
IsMPPrePlacedConYards(false),
IsBuildOffAlly(true),
IsShowSuperWeaponTimers(true)
IsShowSuperWeaponTimers(true),
ApproachTargetResetMultiplier(1.0)
{
ASSERT(ThisPtr != nullptr);
//EXT_DEBUG_TRACE("RulesClassExtension constructor - 0x%08X\n", (uintptr_t)(ThisPtr));
Expand Down Expand Up @@ -291,6 +292,8 @@ bool RulesClassExtension::General(CCINIClass &ini)
return false;
}

ApproachTargetResetMultiplier = ini.Get_Float(GENERAL, "ApproachTargetResetMultiplier", ApproachTargetResetMultiplier);

return true;
}

Expand Down
6 changes: 6 additions & 0 deletions src/extensions/rules/rulesext.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ class RulesClassExtension final : public Extension<RulesClass>
* on the tactical view?
*/
bool IsShowSuperWeaponTimers;

/**
* The "approach target" position should be recalculated if the target is
* now more than weapon range times this value.
*/
double ApproachTargetResetMultiplier;
};


Expand Down
4 changes: 4 additions & 0 deletions src/extensions/technotype/technotypeext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ TechnoTypeClassExtension::TechnoTypeClassExtension(TechnoTypeClass *this_ptr) :
IsImmuneToEMP(false),
IsCanPassiveAcquire(true),
IsCanRetaliate(true),
IsCanApproachTarget(true),
IsCanRecalcApproachTarget(true),
ShakePixelYHi(0),
ShakePixelYLo(0),
ShakePixelXHi(0),
Expand Down Expand Up @@ -259,6 +261,8 @@ bool TechnoTypeClassExtension::Read_INI(CCINIClass &ini)
IsImmuneToEMP = ini.Get_Bool(ini_name, "ImmuneToEMP", IsImmuneToEMP);
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);
Expand Down
12 changes: 12 additions & 0 deletions src/extensions/technotype/technotypeext.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@ class TechnoTypeClassExtension final : public Extension<TechnoTypeClass>
*/
bool IsCanRetaliate;

/**
* Can this unit can continually move towards its intended target with
* the intention of gaining more accuracy?
*/
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