|
29 | 29 | #include "foot.h"
|
30 | 30 | #include "technotype.h"
|
31 | 31 | #include "technotypeext.h"
|
| 32 | +#include "tibsun_inline.h" |
32 | 33 | #include "house.h"
|
| 34 | +#include "rules.h" |
| 35 | +#include "rulesext.h" |
| 36 | +#include "target.h" |
33 | 37 | #include "fatal.h"
|
34 | 38 | #include "asserthandler.h"
|
35 | 39 | #include "debughandler.h"
|
|
38 | 42 | #include "hooker_macros.h"
|
39 | 43 |
|
40 | 44 |
|
| 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 | + |
41 | 103 | /**
|
42 | 104 | * #issue-595
|
43 | 105 | *
|
@@ -189,4 +251,5 @@ void FootClassExtension_Hooks()
|
189 | 251 | Patch_Jump(0x004A4D60, &_FootClass_Death_Announcement_IsInsignifcant_Patch);
|
190 | 252 | Patch_Jump(0x004A6866, &_FootClass_Is_Allowed_To_Recloak_Cloak_Stop_BugFix_Patch);
|
191 | 253 | Patch_Jump(0x004A1EA8, &_FootClass_Approach_Target_Can_Approach_Patch);
|
| 254 | + Patch_Jump(0x004A1FEA, &_FootClass_Approach_Target_Can_Recalc_Approach_Target_Patch); |
192 | 255 | }
|
0 commit comments