diff --git a/X2WOTCCommunityHighlander/Src/XComGame/Classes/CHHelpers.uc b/X2WOTCCommunityHighlander/Src/XComGame/Classes/CHHelpers.uc index 52553e7d5..eb425a4b8 100644 --- a/X2WOTCCommunityHighlander/Src/XComGame/Classes/CHHelpers.uc +++ b/X2WOTCCommunityHighlander/Src/XComGame/Classes/CHHelpers.uc @@ -943,3 +943,47 @@ static function name GetPlaceEvacZoneAbilityName() return default.PlaceEvacZoneAbilityName != '' ? default.PlaceEvacZoneAbilityName : 'PlaceEvacZone'; } // End Issue #855 + +// Start Issue #1084 +// This helper function is covered by Backwards Compatibility policy and is safe for use in mods. +static final function int GetTileDistanceBetweenTiles(const TTile TileA, const TTile TileB) +{ + local XComWorldData WorldData; + local vector LocA, LocB; + local float Dist; + local int TileDistance; + + WorldData = `XWORLD; + LocA = WorldData.GetPositionFromTileCoordinates(TileA); + LocB = WorldData.GetPositionFromTileCoordinates(TileB); + + Dist = VSize(LocA - LocB); + TileDistance = Dist / WorldData.WORLD_StepSize; + return TileDistance; +} + +// This helper function is covered by Backwards Compatibility policy and is safe for use in mods. +static final function GetTilesAdjacentToTile(const TTile SourceTile, out array AdjacentTiles) +{ + local TTile AdjacentTile; + + AdjacentTile = SourceTile; + AdjacentTile.X--; + AdjacentTile.Y--; + AdjacentTiles.AddItem(AdjacentTile); + AdjacentTile.X++; + AdjacentTiles.AddItem(AdjacentTile); + AdjacentTile.X++; + AdjacentTiles.AddItem(AdjacentTile); + AdjacentTile.Y++; + AdjacentTiles.AddItem(AdjacentTile); + AdjacentTile.Y++; + AdjacentTiles.AddItem(AdjacentTile); + AdjacentTile.X--; + AdjacentTiles.AddItem(AdjacentTile); + AdjacentTile.X--; + AdjacentTiles.AddItem(AdjacentTile); + AdjacentTile.Y--; + AdjacentTiles.AddItem(AdjacentTile); +} +// End Issue #1084 \ No newline at end of file diff --git a/X2WOTCCommunityHighlander/Src/XComGame/Classes/X2MeleePathingPawn.uc b/X2WOTCCommunityHighlander/Src/XComGame/Classes/X2MeleePathingPawn.uc index e0891b543..52176b523 100644 --- a/X2WOTCCommunityHighlander/Src/XComGame/Classes/X2MeleePathingPawn.uc +++ b/X2WOTCCommunityHighlander/Src/XComGame/Classes/X2MeleePathingPawn.uc @@ -156,6 +156,9 @@ simulated function UpdateMeleeTarget(XComGameState_BaseObject Target) if(class'X2AbilityTarget_MovingMelee'.static.SelectAttackTile(UnitState, Target, AbilityTemplate, PossibleTiles)) { // Start Issue #1084 + // The native `class'X2AbilityTarget_MovingMelee'.static.SelectAttackTile` function + // gives only one possible attack tile for adjacent targets, so we use our own + // script logic to add more possible attack tiles for adjacent targets. if (PossibleTiles.Length == 1) { UpdatePossibleTilesForAdjacentTarget(Target); @@ -192,9 +195,12 @@ simulated function UpdateMeleeTarget(XComGameState_BaseObject Target) } // Start Issue #1084 +// This is an internal CHL API. It is not intended for use by mods and is not covered by Backwards Compatibility policy. private function UpdatePossibleTilesForAdjacentTarget(XComGameState_BaseObject Target) { local TTile TargetTileLocation; + local array AdjacentTiles; + local TTile AdjacentTile; local XComGameState_Unit TargetUnit; local XComGameState_Destructible TargetObject; @@ -216,9 +222,23 @@ private function UpdatePossibleTilesForAdjacentTarget(XComGameState_BaseObject T } } - // TODO: Check distance between UnitState and TargetTileLocation and exit if they're not adjacent + // Make sure the target is actually adjacent before we do anything. + // The "PossibleTiles.Length == 1" check earlier does not guarantee that, as target may simply be blocked on other sides. + if (class'CHHelpers'.static.GetTileDistanceBetweenTiles(UnitState.TileLocation, TargetTileLocation) > 1) + { + return; + } + + class'CHHelpers'.static.GetTilesAdjacentToTile(TargetTileLocation, AdjacentTiles); + AdjacentTiles.RemoveItem(PossibleTiles[0]); - // TODO: Append new tiles to PossibleTiles + foreach AdjacentTiles(AdjacentTile) + { + if (class'X2AbilityTarget_MovingMelee'.static.IsValidAttackTile(UnitState, AdjacentTile, TargetTileLocation, ActiveCache)) + { + PossibleTiles.AddItem(AdjacentTile); + } + } } // End Issue #1084