Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the AI Condition bTestTargetEffectsApply work properly and allow it to be used with grenades #1451

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 72 additions & 5 deletions X2WOTCCommunityHighlander/Src/XComGame/Classes/XGAIBehavior.uc
Original file line number Diff line number Diff line change
Expand Up @@ -6751,6 +6751,10 @@ function bool GetAllAoETargets(out array<TTile> TargetList, AoETargetingInfo Pro
local bool bValid;
local X2Effect MultiTargetEffect;
local X2AbilityTemplate AbilityTemplate;
local array<X2Effect> TargetEffects;
local X2Effect TestEffect;
local X2GrenadeTemplate TestGrenadeTemplate;
local XComGameState_Item TestSourceWeapon;

if (!GetUnfilteredAoETargetList(UnitList, Profile, RequiredTarget, DeprioritizedEffects))
{
Expand All @@ -6774,13 +6778,75 @@ function bool GetAllAoETargets(out array<TTile> TargetList, AoETargetingInfo Pro
if ( Profile.bTestTargetEffectsApply )
{
AbilityTemplate = AbilityState.GetMyTemplate();
// Ignore units that are immune to this ability. (passes as long as any effect applies to this unit)
foreach AbilityTemplate.AbilityMultiTargetEffects(MultiTargetEffect)
// Start Issue #1369
/// HL-Docs: feature:ImproveAIAreaOfEffectProfiles; issue:1380; tags:tactical
/// Setting bTestTargetEffectsApply on AOE Profiles in XComAI is supposed to filter the list of acceptable targets
/// for a given Area of Effect ability by looking through the targeting conditions on each effect and and whether
/// the prospective targets are immune to the damage (this is done in X2Effect::TargetIsValidForAbility). However,
/// the GetAllAOETargets was not sophisticated enough to handle grenade templates and was also being short-circuited
/// due to bValid not being reset between each unit (i.e. so if a single unit passed the check, all subsequent units
/// were added to the supposedly-filtered target list).
If (AbilityTemplate.bUseLaunchedGrenadeEffects)
{
TestSourceWeapon = AbilityState.GetSourceWeapon();
bValid = false;
If (TestSourceWeapon != none)
{
TestGrenadeTemplate = X2GrenadeTemplate(TestSourceWeapon.GetLoadedAmmoTemplate(AbilityState));
If (TestGrenadeTemplate != none)
{
TargetEffects = TestGrenadeTemplate.LaunchedGrenadeEffects;
If (TargetEffects.Length > 0)
{
foreach TargetEffects(TestEffect)
{
if(TestEffect.DamageTypes.Length > 0 && TestEffect.TargetIsValidForAbility(TargetState, UnitState, AbilityState))
{
bValid = true;
break;
}
}
}
}
}
}
else if (AbilityTemplate.bUseThrownGrenadeEffects)
{
if (MultiTargetEffect.TargetIsValidForAbility(TargetState, UnitState, AbilityState))
TestSourceWeapon = AbilityState.GetSourceWeapon();
bValid = false;
If (TestSourceWeapon != none)
{
bValid = true;
break;
TestGrenadeTemplate = X2GrenadeTemplate(TestSourceWeapon.GetMyTemplate());
If (TestGrenadeTemplate != none)
{
TargetEffects = TestGrenadeTemplate.ThrownGrenadeEffects;
If (TargetEffects.Length > 0)
{
foreach TargetEffects(TestEffect)
{
if(TestEffect.DamageTypes.Length > 0 && TestEffect.TargetIsValidForAbility(TargetState, UnitState, AbilityState))
{
bValid = true;
break;
}
}
}
}
}
}
else
{
// Ignore units that are immune to this ability. (passes as long as any effect applies to this unit)
foreach AbilityTemplate.AbilityMultiTargetEffects(MultiTargetEffect)
{
// Issue #1369 - Reset bValid for Each Unit and check the DamageTypes Array on the MultiTargetEffects to
// exclude dummy abilities with no damage type from passing the validity check
bValid = false;
if (MultiTargetEffect.DamageTypes.Length > 0 && MultiTargetEffect.TargetIsValidForAbility(TargetState, UnitState, AbilityState))
{
bValid = true;
break;
}
}
}
if (!bValid)
Expand All @@ -6789,6 +6855,7 @@ function bool GetAllAoETargets(out array<TTile> TargetList, AoETargetingInfo Pro
}
}

// End Issue #1369
// Ignore inactive AI units that are not visible.
if (TargetState.ControllingPlayerIsAI() && TargetState.IsUnrevealedAI()
&& !class'X2TacticalVisibilityHelpers'.static.CanUnitSeeLocation(UnitState.ObjectID, TargetState.TileLocation))
Expand Down
Loading