Remove hardcoded AA/Gattling weapon selection restrictions
- If both
PrimaryandSecondaryweapons can fire at air targets (projectile hasAA=true),Primarycan now be picked instead of always forcingSecondary. Also applies toIsGattling=true, with odd-numbered and even-numberedWeaponXslots instead ofPrimaryandSecondary, respectively. -
IsGattling=truecan now fall back to ´secondary´ weapon slot (even-numberedWeaponXslots) if 'primary' one (odd-numbered) cannot fire at current target (armor type,CanTarget(Houses), shield etc).
This allows for things like AA-only units with two different weapons and units using gattling logic with two sets of weapons that can both fire at ground targets.
As a bonus threw these fixes in:
- Fixed
LandTargeting=1not preventing from targeting TerrainTypes (trees etc.) on land. - Fixed
NavalTargeting=6not preventing from targeting empty water cells or TerrainTypes (trees etc.) on water. - Fixed
NavalTargeting=7and/orLandTargeting=2resulting in still targeting TerrainTypes (trees etc.) on land withPrimaryweapon.
Nightly build for this pull request:
- compiled-dll-1d7819ad1325c3a33f8df2621a743b96f3b154b2.zip This comment is automatic and is meant to allow guests to get latest nightly builds without registering. It is updated on every successful build.
Fixed the outstanding issues from feedback and simplified some of the code.
I think if gattling can select weapon by versus.... Just a suggestion.
DEFINE_HOOK(0x6F3436, TechnoClass_SelectGattlingWeapon, 0x6)
{
GET(TechnoClass*, pThis, ESI);
GET(AbstractClass*, pTarget, EBP);
enum { Odd = 0x6F346A, Even = 0x6F345C, Origin = 0 };
int gattlingStage = pThis->CurrentGattlingStage;
auto pTypeExt = TechnoTypeExt::ExtMap.Find(pThis->GetTechnoType());
if (pTypeExt->Gattling_SelectWeaponByVersus)
{
WeaponTypeClass* pWeaponOdd = pThis->GetWeapon(gattlingStage << 1)->WeaponType;
WeaponTypeClass* pWeaponEven = pThis->GetWeapon(gattlingStage << 1 | 1)->WeaponType;
if (auto pTargetTechno = abstract_cast<TechnoClass*>(pTarget))
{
R->ESI(gattlingStage);
auto pTargetExt = TechnoExt::ExtMap.Find(pTargetTechno);
if (pTargetTechno->IsInAir())
{
if (!pWeaponEven->Projectile->AA)
return Odd;
if (GeneralUtils::GetWarheadVersusArmor(pWeaponEven->Warhead, pTargetExt->GetArmorIdx(pWeaponEven)) != 0.0)
return Even;
if (GeneralUtils::GetWarheadVersusArmor(pWeaponOdd->Warhead, pTargetExt->GetArmorIdx(pWeaponOdd)) == 0.0)
return Even;
return Odd;
}
else
{
if (!pWeaponOdd->Projectile->AG)
return Even;
if (GeneralUtils::GetWarheadVersusArmor(pWeaponOdd->Warhead, pTargetExt->GetArmorIdx(pWeaponOdd)) != 0.0)
return Odd;
if (GeneralUtils::GetWarheadVersusArmor(pWeaponEven->Warhead, pTargetExt->GetArmorIdx(pWeaponEven)) == 0.0)
return Odd;
return Even;
}
}
else
{
if (auto pTargetObject = abstract_cast<ObjectClass*>(pTarget))
{
ObjectTypeClass* pTargetType = pTargetObject->GetType();
if (GeneralUtils::GetWarheadVersusArmor(pWeaponOdd->Warhead, pTargetType->Armor) != 0.0)
return Odd;
if (GeneralUtils::GetWarheadVersusArmor(pWeaponEven->Warhead, pTargetType->Armor) == 0.0)
return Odd;
return Even;
}
else
{
return Odd;
}
}
}
return Origin;
}
Did some minor code tweaks and added Land/NavalTargeting support for IsGattling weapons in same manner as regular weapons.
I think if gattling can select weapon by versus.... Just a suggestion.
Current code already behaves largely the same as that, and not counting for Phobos-required checks and the Naval/LandTargeting things I just added, is also less verbose. Given that the gattling weapon fallbacks were implemented with consistency with regular weapons in mind, the main differences are that the AG=false fallback from odd to even and armor type checks for non-techno targets do not exist. And the point was to make it work without separate toggle anyways, which I believe it currently does just fine.
I found that if you ordered a boomber submarine (who has LandTargeting = 2) to attack a tree on land, it will try to use torpedo (primary weapon). I think it's incorrect, it should use missile(secondary weapon).
Fixed the vanilla bug of LandTargeting=2 and/or NavalTargeting=7 not changing weapon used against TerrainTypes on land to Secondary.