Skip to content

Commit 6239360

Browse files
committed
Fix issues
- Move ApproachTarget hooks to FootClass and make use of existing weapon range check results - Unify locomotor behaviour - prevent locomotor processing on AssignDestination if immobilized - Moved checking speed multipliers for zero speed to per frame processing due to necessity apply behaviour on all locomotors now - Make TurretResponse code easier to read
1 parent 9c5a769 commit 6239360

4 files changed

Lines changed: 59 additions & 97 deletions

File tree

src/Ext/Techno/Body.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,9 @@ void TechnoExt::SyncInvulnerability(TechnoClass* pFrom, TechnoClass* pTo)
184184

185185
double TechnoExt::GetCurrentSpeedMultiplier(FootClass* pThis)
186186
{
187-
double houseMultiplier = 1.0;
187+
auto const pExt = TechnoExt::ExtMap.Find(pThis);
188188
auto const whatAmI = pThis->WhatAmI();
189+
double houseMultiplier = 1.0;
189190

190191
if (whatAmI == AbstractType::Aircraft)
191192
houseMultiplier = pThis->Owner->Type->SpeedAircraftMult;
@@ -194,8 +195,6 @@ double TechnoExt::GetCurrentSpeedMultiplier(FootClass* pThis)
194195
else
195196
houseMultiplier = pThis->Owner->Type->SpeedUnitsMult;
196197

197-
auto const pExt = TechnoExt::ExtMap.Find(pThis);
198-
199198
return pThis->SpeedMultiplier * houseMultiplier * pExt->AE.SpeedMultiplier *
200199
(pThis->HasAbility(Ability::Faster) ? RulesClass::Instance->VeteranSpeed : 1.0);
201200
}
@@ -755,7 +754,7 @@ bool TechnoExt::CannotMove(FootClass* pThis, bool checkSpeedMultiplier)
755754
if (pType->Speed == 0)
756755
return true;
757756

758-
if (checkSpeedMultiplier && TechnoExt::GetCurrentSpeedMultiplier(pThis) <= 0.0)
757+
if (checkSpeedMultiplier && TechnoExt::ExtMap.Find(pThis)->IsZeroSpeed)
759758
return true;
760759

761760
auto landType = pThis->GetCell()->LandType;
@@ -1271,6 +1270,7 @@ void TechnoExt::ExtData::Serialize(T& Stm)
12711270
.Process(this->HoverShutdown)
12721271
.Process(this->LastTargetCrd)
12731272
.Process(this->LastTargetCrdClearTimer)
1273+
.Process(this->IsZeroSpeed)
12741274
;
12751275
}
12761276

src/Ext/Techno/Body.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ class TechnoExt
106106
CoordStruct LastTargetCrd;
107107
CDTimerClass LastTargetCrdClearTimer;
108108

109+
bool IsZeroSpeed; // Temporary speed multipliers have made this techno stationary.
110+
109111
ExtData(TechnoClass* OwnerObject) : Extension<TechnoClass>(OwnerObject)
110112
, TypeExtData { nullptr }
111113
, Shield {}
@@ -177,6 +179,7 @@ class TechnoExt
177179
, HoverShutdown { false }
178180
, LastTargetCrd { CoordStruct::Empty }
179181
, LastTargetCrdClearTimer {}
182+
, IsZeroSpeed { false }
180183
{ }
181184

182185
void OnEarlyUpdate();

src/Ext/Techno/Hooks.DisallowMoving.cpp

Lines changed: 28 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@
77

88
#pragma region Helpers
99

10-
namespace ApproachTargetTemp
11-
{
12-
int WeaponIndex;
13-
}
14-
1510
static int inline HandleHunt(FootClass* pThis)
1611
{
1712
if (TechnoExt::CannotMove(pThis, true))
@@ -24,23 +19,6 @@ static int inline HandleHunt(FootClass* pThis)
2419
return 0;
2520
}
2621

27-
static bool inline HandleApproachTarget(FootClass* pThis, int& weaponIndex)
28-
{
29-
if (TechnoExt::CannotMove(pThis, true))
30-
{
31-
const auto pTarget = pThis->Target;
32-
weaponIndex = pThis->SelectWeapon(pTarget);
33-
34-
if (!pThis->IsCloseEnough(pTarget, weaponIndex))
35-
{
36-
pThis->SetTarget(nullptr);
37-
return true;
38-
}
39-
}
40-
41-
return false;
42-
}
43-
4422
#pragma endregion
4523

4624
#pragma region Infantry
@@ -52,30 +30,6 @@ static bool __fastcall InfantryClass_CantMove_Wrapper(InfantryClass* pThis)
5230

5331
DEFINE_FUNCTION_JUMP(CALL6, 0x75ACBD, InfantryClass_CantMove_Wrapper);
5432

55-
DEFINE_HOOK(0x75AED1, WalkLocomotionClass_MovementAI_DisallowMoving, 0x5)
56-
{
57-
GET(WalkLocomotionClass*, pThis, EBP);
58-
59-
auto const pLinkedTo = pThis->LinkedTo;
60-
61-
if (TechnoExt::CannotMove(pLinkedTo, true))
62-
{
63-
if (pThis->Is_Moving())
64-
{
65-
pThis->Force_Immediate_Destination(CoordStruct::Empty);
66-
pThis->Stop_Moving();
67-
}
68-
69-
return 0x75C1F1;
70-
}
71-
else if (pLinkedTo->Destination && pThis->Destination == CoordStruct::Empty)
72-
{
73-
pLinkedTo->SetDestination(pLinkedTo->Destination, false);
74-
}
75-
76-
return 0;
77-
}
78-
7933
DEFINE_HOOK(0x51AA84, InfantryClass_AssignDestination_DisallowMoving, 0x6)
8034
{
8135
GET(InfantryClass*, pThis, EBP);
@@ -150,18 +104,6 @@ DEFINE_HOOK(0x51CB8C, InfantryClass_GetFireError_DisallowMoving, 0x6)
150104
return 0;
151105
}
152106

153-
DEFINE_HOOK(0x522352, InfantryClass_ApproachTarget_DisallowMoving, 0x6)
154-
{
155-
GET(InfantryClass*, pThis, ECX);
156-
157-
int weaponIndex = -1;
158-
159-
if (HandleApproachTarget(pThis, weaponIndex))
160-
return 0x522373;
161-
162-
return 0;
163-
}
164-
165107
#pragma endregion
166108

167109
#pragma region Unit
@@ -222,12 +164,16 @@ DEFINE_HOOK(0x740744, UnitClass_WhatAction_DisallowMoving_2, 0x6)
222164
return 0;
223165
}
224166

225-
DEFINE_HOOK(0x736B60, UnitClass_Rotation_AI_DisallowMoving, 0x6)
167+
DEFINE_HOOK(0x736B60, UnitClass_RotationAI_DisallowMoving, 0x6)
226168
{
227169
GET(UnitClass*, pThis, ESI);
228170

229171
const auto pTypeExt = TechnoTypeExt::ExtMap.Find(pThis->Type);
230-
return (pTypeExt->TurretResponse.isset() ? !pTypeExt->TurretResponse.Get() : TechnoExt::CannotMove(pThis, false)) ? 0x736AFB : 0;
172+
173+
if (pTypeExt->TurretResponse.isset() ? !pTypeExt->TurretResponse.Get() : TechnoExt::CannotMove(pThis, false))
174+
return 0x736AFB;
175+
176+
return 0;
231177
}
232178

233179
DEFINE_HOOK(0x73EFC4, UnitClass_Mission_Hunt_DisallowMoving, 0x6)
@@ -254,35 +200,6 @@ DEFINE_HOOK(0x74132B, UnitClass_GetFireError_DisallowMoving, 0x7)
254200
return 0;
255201
}
256202

257-
DEFINE_HOOK(0x7414E0, UnitClass_ApproachTarget_DisallowMoving, 0xA)
258-
{
259-
GET(UnitClass*, pThis, ECX);
260-
261-
int weaponIndex = -1;
262-
263-
if (HandleApproachTarget(pThis, weaponIndex))
264-
return 0x741690;
265-
266-
ApproachTargetTemp::WeaponIndex = weaponIndex;
267-
return 0;
268-
}
269-
270-
DEFINE_HOOK(0x7415A9, UnitClass_ApproachTarget_SetWeaponIndex, 0x6)
271-
{
272-
if (ApproachTargetTemp::WeaponIndex != -1)
273-
{
274-
GET(UnitClass*, pThis, ESI);
275-
276-
R->EDI(VTable::Get(pThis));
277-
R->EAX(ApproachTargetTemp::WeaponIndex);
278-
ApproachTargetTemp::WeaponIndex = -1;
279-
280-
return 0x7415BA;
281-
}
282-
283-
return 0;
284-
}
285-
286203
#pragma endregion
287204

288205
#pragma region Foot
@@ -300,7 +217,18 @@ DEFINE_HOOK(0x4D4203, FootClass_Mission_Move_DisallowMoving, 0x6)
300217
return 0;
301218
}
302219

303-
DEFINE_HOOK(0x4D7DCC, FootClass_ActiveClickWith_DisallowMoving, 0x6)
220+
DEFINE_HOOK(0x4D9563, FootClass_AssignDestination_DisallowMoving, 0x6)
221+
{
222+
GET(FootClass*, pThis, EBP);
223+
224+
// Prevent locomotor processing when assigned target if temporarily immobilized.
225+
if (TechnoExt::ExtMap.Find(pThis)->IsZeroSpeed)
226+
return 0x4D96C2;
227+
228+
return 0;
229+
}
230+
231+
DEFINE_HOOK(0x4D7EB5, FootClass_ActiveClickWith_DisallowMoving, 0x5)
304232
{
305233
GET(FootClass*, pThis, ESI);
306234

@@ -334,6 +262,16 @@ DEFINE_HOOK(0x4D6AAB, FootClass_Mission_AreaGuard_DisallowMoving, 0x6)
334262
return 0;
335263
}
336264

265+
DEFINE_HOOK(0x4D5716, FootClass_ApproachTarget_DisallowMoving, 0x7)
266+
{
267+
GET(FootClass*, pThis, EBX);
268+
269+
if (TechnoExt::CannotMove(pThis, true))
270+
return 0x4D571D;
271+
272+
return 0;
273+
}
274+
337275
#pragma endregion
338276

339277
#pragma region Techno

src/Ext/Techno/Hooks.cpp

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ DEFINE_HOOK(0x7363C9, UnitClass_AI_AnimationPaused, 0x6)
3131
enum { SkipGameCode = 0x7363DE };
3232

3333
GET(UnitClass*, pThis, ESI);
34-
34+
3535
if (TechnoExt::ExtMap.Find(pThis)->DelayedFireSequencePaused)
3636
return SkipGameCode;
3737

@@ -62,6 +62,27 @@ DEFINE_HOOK(0x4DA54E, FootClass_AI, 0x6)
6262
pExt->UpdateTiberiumEater();
6363
pExt->AmmoAutoConvertActions();
6464

65+
// Check speed multipliers for zero, update things like allowing
66+
// locomotor to process destination again.
67+
if (TechnoExt::GetCurrentSpeedMultiplier(pThis) > 0.0)
68+
{
69+
bool wasZeroSpeed = pExt->IsZeroSpeed;
70+
pExt->IsZeroSpeed = false;
71+
72+
if (wasZeroSpeed)
73+
{
74+
if (auto const pDest = pThis->Destination)
75+
{
76+
pThis->Destination = nullptr; // Force it to update.
77+
pThis->SetDestination(pDest, false);
78+
}
79+
}
80+
}
81+
else
82+
{
83+
pExt->IsZeroSpeed = true;
84+
}
85+
6586
return 0;
6687
}
6788

@@ -850,7 +871,7 @@ DEFINE_HOOK(0x655DDD, RadarClass_ProcessPoint_RadarInvisible, 0x6)
850871
if (pTypeExt->OwnerObject()->RadarInvisible
851872
&& EnumFunctions::CanTargetHouse(pTypeExt->RadarInvisibleToHouse.Get(AffectedHouse::Enemies), pTechno->Owner, HouseClass::CurrentPlayer))
852873
{
853-
return Invisible;
874+
return Invisible;
854875
}
855876

856877
return GoOtherChecks;
@@ -1351,7 +1372,7 @@ DEFINE_HOOK(0x71A8BD, TemporalClass_Update_WarpAwayAnim, 0x5)
13511372
AnimExt::CreateRandomAnim(pExt->WarpAway, pTarget->Location, nullptr, pTarget->Owner);
13521373
return 0x71A90E;
13531374
}
1354-
1375+
13551376
return 0;
13561377
}
13571378

0 commit comments

Comments
 (0)