Skip to content

Commit

Permalink
Now able to select attack tile X2CommunityCore#1084, but can't attack…
Browse files Browse the repository at this point in the history
… from the tile the attacker is standing on.
  • Loading branch information
Iridar committed Dec 8, 2021
1 parent 2e8fa92 commit a32d512
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 2 deletions.
44 changes: 44 additions & 0 deletions X2WOTCCommunityHighlander/Src/XComGame/Classes/CHHelpers.uc
Original file line number Diff line number Diff line change
Expand Up @@ -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<TTile> 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
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<TTile> AdjacentTiles;
local TTile AdjacentTile;
local XComGameState_Unit TargetUnit;
local XComGameState_Destructible TargetObject;

Expand All @@ -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

Expand Down

0 comments on commit a32d512

Please sign in to comment.