Skip to content

Commit 10db911

Browse files
committed
FIX
Refactored split/periodic target validation into WeaponTypeExt::IsAllowedTarget and BulletTypeExt::IsAllowedTarget with no intended behavioral change; call sites updated for splits and periodic weapon.
1 parent ecebb82 commit 10db911

9 files changed

Lines changed: 90 additions & 110 deletions

File tree

Phobos.log

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/Ext/Bullet/Hooks.DetonateLogics.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
#include <Ext/Anim/Body.h>
44
#include <Ext/CaptureManager/Body.h>
5+
#include <Ext/BulletType/Body.h>
56
#include <Ext/WeaponType/Body.h>
6-
#include <Ext/Techno/Body.h>
77
#include <Ext/Scenario/Body.h>
88
#include <Utilities/Helpers.Alex.h>
99

@@ -663,8 +663,8 @@ DEFINE_HOOK(0x469EC0, BulletClass_Logics_AirburstWeapon, 0x6)
663663
if (pTechno->IsInPlayfield && pTechno->IsOnMap && pTechno->IsAlive && pTechno->Health > 0 && !pTechno->InLimbo
664664
&& (retargetSelf || pTechno != pSource))
665665
{
666-
if (TechnoExt::SplitsProjectileCheck(pType, pWeapon, pTechno, useWeaponTargeting, pSource) &&
667-
TechnoExt::IsAllowedSplitsTarget(pSource, pOwner, pWeapon, pTechno, useWeaponTargeting))
666+
if (BulletTypeExt::IsAllowedTarget(pType, pTechno, useWeaponTargeting, pSource) &&
667+
WeaponTypeExt::IsAllowedTarget(pWeapon, pTechno, useWeaponTargeting, pSource, pOwner))
668668
{
669669
targets.AddItem(pTechno);
670670
}

src/Ext/BulletType/Body.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,41 @@ BulletTypeClass* BulletTypeExt::GetDefaultBulletType()
1919
return GameCreate<BulletTypeClass>(NONE_STR);
2020
}
2121

22+
bool BulletTypeExt::IsAllowedTarget(BulletTypeClass* pProjectile, TechnoClass* pTarget, bool useWeaponTargeting, TechnoClass* pFirer)
23+
{
24+
if (!pProjectile || !pTarget)
25+
return false;
26+
27+
if (!useWeaponTargeting)
28+
return pProjectile->AA || !pTarget->IsInAir();
29+
30+
const bool inAir = pTarget->IsInAir();
31+
32+
if (inAir)
33+
{
34+
if (!pProjectile->AA)
35+
return false;
36+
}
37+
else
38+
{
39+
auto const pProjectileExt = BulletTypeExt::ExtMap.Find(pProjectile);
40+
41+
if (pFirer && pFirer->GetTechnoType()->LandTargeting != LandTargetingType::Land_Not_OK
42+
&& pProjectile->AA && pProjectileExt->AAOnly)
43+
{
44+
return false;
45+
}
46+
47+
if (!pProjectile->AG)
48+
return false;
49+
}
50+
51+
if (pTarget->InWhichLayer() == Layer::Underground && !BulletTypeExt::ExtMap.Find(pProjectile)->AU)
52+
return false;
53+
54+
return true;
55+
}
56+
2257
// =============================
2358
// load / save
2459

src/Ext/BulletType/Body.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,5 @@ class BulletTypeExt
162162

163163
static double GetAdjustedGravity(BulletTypeClass* pType);
164164
static BulletTypeClass* GetDefaultBulletType();
165+
static bool IsAllowedTarget(BulletTypeClass* pProjectile, TechnoClass* pTarget, bool useWeaponTargeting, TechnoClass* pFirer = nullptr);
165166
};

src/Ext/Techno/Body.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,6 @@ class TechnoExt
328328
static int GetWeaponIndexAgainstWall(TechnoClass* pThis, OverlayTypeClass* pWallOverlayType);
329329
static void ApplyKillWeapon(TechnoClass* pThis, TechnoClass* pSource, WarheadTypeClass* pWH);
330330
static void ApplyRevengeWeapon(TechnoClass* pThis, TechnoClass* pSource, WarheadTypeClass* pWH);
331-
static bool IsAllowedSplitsTarget(TechnoClass* pSource, HouseClass* pOwner, WeaponTypeClass* pWeapon, TechnoClass* pTarget, bool useWeaponTargeting);
332-
static bool SplitsProjectileCheck(BulletTypeClass* pProjectile, WeaponTypeClass* pWeapon, TechnoClass* pTarget, bool useWeaponTargeting, TechnoClass* pFirer = nullptr);
333331
static bool MultiWeaponCanFire(TechnoClass* const pThis, AbstractClass* const pTarget, WeaponTypeClass* const pWeaponType);
334332
static bool HasWeaponsDisabled(TechnoClass* pThis);
335333
static FireError GetFireErrorIgnoreDisableWeapons(TechnoClass* pThis, AbstractClass* pTarget, int weaponIndex, bool ignoreRange);

src/Ext/Techno/WeaponHelpers.cpp

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -3,80 +3,6 @@
33
#include <Ext/BulletType/Body.h>
44
#include <Ext/WeaponType/Body.h>
55
#include <Ext/WarheadType/Body.h>
6-
#include <Utilities/EnumFunctions.h>
7-
#include <Utilities/GeneralUtils.h>
8-
9-
bool TechnoExt::IsAllowedSplitsTarget(TechnoClass* pSource, HouseClass* pOwner, WeaponTypeClass* pWeapon, TechnoClass* pTarget, bool useWeaponTargeting)
10-
{
11-
auto const pWH = pWeapon->Warhead;
12-
13-
if (useWeaponTargeting)
14-
{
15-
auto const pType = pTarget->GetTechnoType();
16-
17-
if (!pType->LegalTarget || GeneralUtils::GetWarheadVersusArmor(pWH, pTarget, pType) == 0.0)
18-
return false;
19-
20-
auto const pWeaponExt = WeaponTypeExt::ExtMap.Find(pWeapon);
21-
22-
if (pWeaponExt->SkipWeaponPicking)
23-
return true;
24-
25-
if (!EnumFunctions::CanTargetHouse(pWeaponExt->CanTargetHouses, pOwner, pTarget->Owner)
26-
|| !EnumFunctions::IsCellEligible(pTarget->GetCell(), pWeaponExt->CanTarget, true, true)
27-
|| !EnumFunctions::IsTechnoEligible(pTarget, pWeaponExt->CanTarget)
28-
|| !pWeaponExt->IsHealthInThreshold(pTarget)
29-
|| !pWeaponExt->IsVeterancyInThreshold(pTarget))
30-
{
31-
return false;
32-
}
33-
34-
if (!pWeaponExt->HasRequiredAttachedEffects(pTarget, pSource))
35-
return false;
36-
}
37-
else
38-
{
39-
if (!WarheadTypeExt::ExtMap.Find(pWH)->CanTargetHouse(pOwner, pTarget))
40-
return false;
41-
}
42-
43-
return true;
44-
}
45-
46-
bool TechnoExt::SplitsProjectileCheck(BulletTypeClass* pProjectile, WeaponTypeClass* pWeapon, TechnoClass* pTarget, bool useWeaponTargeting, TechnoClass* pFirer)
47-
{
48-
if (!pProjectile || !pTarget)
49-
return false;
50-
51-
if (!useWeaponTargeting)
52-
return pProjectile->AA || !pTarget->IsInAir();
53-
54-
const bool inAir = pTarget->IsInAir();
55-
56-
if (inAir)
57-
{
58-
if (!pProjectile->AA)
59-
return false;
60-
}
61-
else
62-
{
63-
auto const pProjectileExt = BulletTypeExt::ExtMap.Find(pProjectile);
64-
65-
if (pFirer && pFirer->GetTechnoType()->LandTargeting != LandTargetingType::Land_Not_OK
66-
&& pProjectile->AA && pProjectileExt->AAOnly)
67-
{
68-
return false;
69-
}
70-
71-
if (!pProjectile->AG)
72-
return false;
73-
}
74-
75-
if (pTarget->InWhichLayer() == Layer::Underground && !BulletTypeExt::ExtMap.Find(pProjectile)->AU)
76-
return false;
77-
78-
return true;
79-
}
806

817
// Compares two weapons and returns index of which one is eligible to fire against current target (0 = first, 1 = second), or -1 if neither works.
828
int TechnoExt::PickWeaponIndex(TechnoClass* pThis, TechnoClass* pTargetTechno, AbstractClass* pTarget, int weaponIndexOne, int weaponIndexTwo, bool allowFallback, bool allowAAFallback)

src/Ext/WeaponType/Body.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,56 @@
11
#include "Body.h"
22
#include <Ext/Bullet/Body.h>
33
#include <Ext/Techno/Body.h>
4+
#include <Ext/WarheadType/Body.h>
5+
#include <Utilities/EnumFunctions.h>
6+
#include <Utilities/GeneralUtils.h>
47

58
WeaponTypeExt::ExtContainer WeaponTypeExt::ExtMap;
69

10+
bool WeaponTypeExt::IsAllowedTarget(WeaponTypeClass* pWeapon, TechnoClass* pTarget, bool useWeaponTargeting, TechnoClass* pSource, HouseClass* pOwner)
11+
{
12+
if (!pWeapon || !pTarget)
13+
return false;
14+
15+
if (!pOwner && pSource)
16+
pOwner = pSource->Owner;
17+
18+
auto const pWH = pWeapon->Warhead;
19+
20+
if (useWeaponTargeting)
21+
{
22+
auto const pType = pTarget->GetTechnoType();
23+
24+
if (!pType->LegalTarget || GeneralUtils::GetWarheadVersusArmor(pWH, pTarget, pType) == 0.0)
25+
return false;
26+
27+
auto const pWeaponExt = WeaponTypeExt::ExtMap.Find(pWeapon);
28+
29+
if (pWeaponExt->SkipWeaponPicking)
30+
return true;
31+
32+
if (!pOwner
33+
|| !EnumFunctions::CanTargetHouse(pWeaponExt->CanTargetHouses, pOwner, pTarget->Owner)
34+
|| !EnumFunctions::IsCellEligible(pTarget->GetCell(), pWeaponExt->CanTarget, true, true)
35+
|| !EnumFunctions::IsTechnoEligible(pTarget, pWeaponExt->CanTarget)
36+
|| !pWeaponExt->IsHealthInThreshold(pTarget)
37+
|| !pWeaponExt->IsVeterancyInThreshold(pTarget))
38+
{
39+
return false;
40+
}
41+
42+
if (!pWeaponExt->HasRequiredAttachedEffects(pTarget, pSource))
43+
return false;
44+
}
45+
else
46+
{
47+
if (!pOwner || !WarheadTypeExt::ExtMap.Find(pWH)->CanTargetHouse(pOwner, pTarget))
48+
return false;
49+
}
50+
51+
return true;
52+
}
53+
754
bool WeaponTypeExt::ExtData::HasRequiredAttachedEffects(TechnoClass* pTarget, TechnoClass* pFirer) const
855
{
956
const bool hasRequiredTypes = this->AttachEffect_RequiredTypes.size() > 0;

src/Ext/WeaponType/Body.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,4 +231,5 @@ class WeaponTypeExt
231231
static int GetRangeWithModifiers(WeaponTypeClass* pThis, TechnoClass* pFirer);
232232
static int GetRangeWithModifiers(WeaponTypeClass* pThis, TechnoClass* pFirer, int range);
233233
static int GetTechnoKeepRange(WeaponTypeClass* pThis, TechnoClass* pFirer, bool isMinimum);
234+
static bool IsAllowedTarget(WeaponTypeClass* pWeapon, TechnoClass* pTarget, bool useWeaponTargeting, TechnoClass* pSource = nullptr, HouseClass* pOwner = nullptr);
234235
};

src/New/Entity/AttachEffectClass.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <Ext/Anim/Body.h>
1010
#include <Ext/Bullet/Body.h>
11+
#include <Ext/BulletType/Body.h>
1112
#include <Ext/Techno/Body.h>
1213
#include <Ext/WeaponType/Body.h>
1314

@@ -662,10 +663,10 @@ void AttachEffectClass::FirePeriodicWeapon()
662663
if (dist > searchRange)
663664
continue;
664665

665-
if (!TechnoExt::SplitsProjectileCheck(pBulletType, pWeapon, pTarget, useWeaponTargeting, pFirer))
666+
if (!BulletTypeExt::IsAllowedTarget(pBulletType, pTarget, useWeaponTargeting, pFirer))
666667
continue;
667668

668-
if (!TechnoExt::IsAllowedSplitsTarget(pFirer, pFirerHouse, pWeapon, pTarget, useWeaponTargeting))
669+
if (!WeaponTypeExt::IsAllowedTarget(pWeapon, pTarget, useWeaponTargeting, pFirer, pFirerHouse))
669670
continue;
670671

671672
validTargets.emplace_back(pTarget, dist);

0 commit comments

Comments
 (0)