Skip to content

Commit 5a72af3

Browse files
committed
adjust gatling targeting
1 parent 24a962d commit 5a72af3

File tree

3 files changed

+49
-38
lines changed

3 files changed

+49
-38
lines changed

src/Ext/Techno/Hooks.Firing.cpp

Lines changed: 45 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "Body.h"
1+
#include "Body.h"
22

33
#include <Ext/Anim/Body.h>
44
#include <Ext/Building/Body.h>
@@ -199,59 +199,68 @@ DEFINE_HOOK(0x6F3432, TechnoClass_WhatWeaponShouldIUse_Gattling, 0xA)
199199
auto const pTargetTechno = abstract_cast<TechnoClass*>(pTarget);
200200
const int oddWeaponIndex = 2 * pThis->CurrentGattlingStage;
201201
const int evenWeaponIndex = oddWeaponIndex + 1;
202-
int chosenWeaponIndex = oddWeaponIndex;
203202
const int eligibleWeaponIndex = TechnoExt::PickWeaponIndex(pThis, pTargetTechno, pTarget, oddWeaponIndex, evenWeaponIndex, true);
204203

205204
if (eligibleWeaponIndex != -1)
206205
{
207-
chosenWeaponIndex = eligibleWeaponIndex;
206+
R->EAX(eligibleWeaponIndex);
207+
return UseWeaponIndex;
208208
}
209-
else if (pTargetTechno)
209+
210+
int chosenWeaponIndex = oddWeaponIndex;
211+
212+
if (pTargetTechno)
210213
{
211214
auto const pTargetExt = TechnoExt::ExtMap.Find(pTargetTechno);
212-
auto const pWeaponOdd = pThis->GetWeapon(oddWeaponIndex)->WeaponType;
213215
auto const pWeaponEven = pThis->GetWeapon(evenWeaponIndex)->WeaponType;
214-
bool skipRemainingChecks = false;
216+
auto const pShield = pTargetExt->Shield.get();
217+
auto const armor = pTargetTechno->GetTechnoType()->Armor;
218+
const bool inAir = pTargetTechno->IsInAir();
219+
const bool isUnderground = pTargetTechno->InWhichLayer() == Layer::Underground;
215220

216-
if (const auto pShield = pTargetExt->Shield.get())
217-
{
218-
if (pShield->IsActive() && !pShield->CanBeTargeted(pWeaponOdd))
221+
auto isWeaponValid = [&](WeaponTypeClass* pWeapon)
219222
{
220-
chosenWeaponIndex = evenWeaponIndex;
221-
skipRemainingChecks = true;
222-
}
223+
if (pShield && pShield->IsActive() && !pShield->CanBeTargeted(pWeapon))
224+
return false;
225+
if (GeneralUtils::GetWarheadVersusArmor(pWeapon->Warhead, armor) == 0.0)
226+
return false;
227+
if (isUnderground && !BulletTypeExt::ExtMap.Find(pWeapon->Projectile)->AU)
228+
return false;
229+
if (inAir && !pWeapon->Projectile->AA)
230+
return false;
231+
return true;
232+
};
233+
234+
// check even weapon first
235+
236+
if (!isWeaponValid(pWeaponEven))
237+
{
238+
R->EAX(chosenWeaponIndex);
239+
return UseWeaponIndex;
223240
}
224241

225-
if (!skipRemainingChecks)
242+
// handle naval targeting
243+
244+
if (!pTargetTechno->OnBridge && !inAir)
226245
{
227-
if (GeneralUtils::GetWarheadVersusArmor(pWeaponOdd->Warhead, pTargetTechno->GetTechnoType()->Armor) == 0.0)
228-
{
229-
chosenWeaponIndex = evenWeaponIndex;
230-
}
231-
else if (pTargetTechno->InWhichLayer() == Layer::Underground)
246+
auto const landType = pTargetTechno->GetCell()->LandType;
247+
248+
if (landType == LandType::Water || landType == LandType::Beach)
232249
{
233-
if (BulletTypeExt::ExtMap.Find(pWeaponEven->Projectile)->AU && !BulletTypeExt::ExtMap.Find(pWeaponOdd->Projectile)->AU)
250+
if (pThis->SelectNavalTargeting(pTargetTechno) != 1)
234251
chosenWeaponIndex = evenWeaponIndex;
235-
}
236-
else
237-
{
238-
auto const landType = pTargetTechno->GetCell()->LandType;
239-
const bool isOnWater = (landType == LandType::Water || landType == LandType::Beach) && !pTargetTechno->IsInAir();
240252

241-
if (!pTargetTechno->OnBridge && isOnWater && pThis->SelectNavalTargeting(pTargetTechno) == 2)
242-
{
243-
chosenWeaponIndex = evenWeaponIndex;
244-
}
245-
else if (pTargetTechno->IsInAir() && !pWeaponOdd->Projectile->AA && pWeaponEven->Projectile->AA)
246-
{
247-
chosenWeaponIndex = evenWeaponIndex;
248-
}
249-
else if (pThis->GetTechnoType()->LandTargeting == LandTargetingType::Land_Secondary)
250-
{
251-
chosenWeaponIndex = evenWeaponIndex;
252-
}
253+
R->EAX(chosenWeaponIndex);
254+
return UseWeaponIndex;
253255
}
254256
}
257+
258+
// check odd weapon
259+
260+
auto const pWeaponOdd = pThis->GetWeapon(oddWeaponIndex)->WeaponType;
261+
262+
if (!isWeaponValid(pWeaponOdd) || pThis->GetTechnoType()->LandTargeting == LandTargetingType::Land_Secondary)
263+
chosenWeaponIndex = evenWeaponIndex;
255264
}
256265

257266
R->EAX(chosenWeaponIndex);

src/Ext/Techno/WeaponHelpers.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ int TechnoExt::PickWeaponIndex(TechnoClass* pThis, TechnoClass* pTargetTechno, A
1616
else if (!pWeaponStructOne)
1717
return weaponIndexTwo;
1818

19+
if (pTargetTechno && (pTargetTechno->Health <= 0 || !pTargetTechno->IsAlive))
20+
return weaponIndexOne;
21+
1922
auto const pWeaponTwo = pWeaponStructTwo->WeaponType;
2023
auto const pSecondExt = WeaponTypeExt::ExtMap.Find(pWeaponTwo);
2124

src/Ext/TechnoType/Body.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,8 @@ int TechnoTypeExt::ExtData::SelectMultiWeapon(TechnoClass* const pThis, Abstract
217217
};
218218

219219
const LandType landType = pTargetTechno->GetCell()->LandType;
220-
const bool targetOnWater = landType == LandType::Water || landType == LandType::Beach;
221220

222-
if (!pTargetTechno->OnBridge && targetOnWater)
221+
if (!pTargetTechno->OnBridge && (landType == LandType::Water || landType == LandType::Beach) && !pTargetTechno->IsInAir())
223222
{
224223
const int result = pThis->SelectNavalTargeting(pTargetTechno);
225224

0 commit comments

Comments
 (0)