Skip to content

Commit

Permalink
Updated Pillar code to properly grant cover to units spawed in range …
Browse files Browse the repository at this point in the history
…of the destructible actor.
  • Loading branch information
BlackDog86 committed Feb 27, 2024
1 parent 73b17a0 commit 912ea6b
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,96 @@ function int GetStartingNumTurns(const out EffectAppliedData ApplyEffectParamete
return SourceUnit.GetTemplarFocusLevel();
}

// Start Issue #1288
/// HL-Docs: ref:Bugfixes; issue:1288
/// Utilised updated OnEffectAdded and OnEffectRemoved functions to update unit data on all units in range of the spawend destructible
simulated protected function OnEffectAdded(const out EffectAppliedData ApplyEffectParameters, XComGameState_BaseObject kNewTargetState, XComGameState NewGameState, XComGameState_Effect NewEffectState)
{
local Vector Position;
local TTile TileLocation;

super.OnEffectAdded(ApplyEffectParameters, kNewTargetState, NewGameState, NewEffectState);

Position = ApplyEffectParameters.AbilityInputContext.TargetLocations[0];
TileLocation = `XWORLD.GetTileCoordinatesFromPosition(Position);

// After the destructible is spawned, perform an update to all of the units within range of the destructible
UpdateWorldDataForTile(TileLocation, NewGameState);
}

simulated function OnEffectRemoved(const out EffectAppliedData ApplyEffectParameters, XComGameState NewGameState, bool bCleansed, XComGameState_Effect RemovedEffectState)
{
local Vector Position;
local TTile TileLocation;

super.OnEffectRemoved(ApplyEffectParameters, NewGameState, bCleansed, RemovedEffectState);

Position = ApplyEffectParameters.AbilityInputContext.TargetLocations[0];
TileLocation = `XWORLD.GetTileCoordinatesFromPosition(Position);

// After the destructible is removed, perform an update to all of the units within range of the destructible
UpdateWorldDataForTile(TileLocation, NewGameState);
}

// helper to get the 3x3 cross of tiles around the specified tile
protected static function GetUpdateTiles(TTile Tile, out array<TTile> Tiles)
{
// center tile
Tiles.AddItem(Tile);

// adjacent x tiles
Tile.X -= 1;
Tiles.AddItem(Tile);
Tile.X += 2;
Tiles.AddItem(Tile);
Tile.X -= 1;

// adjacent y tiles
Tile.Y -= 1;
Tiles.AddItem(Tile);
Tile.Y += 2;
Tiles.AddItem(Tile);
}

protected static function UpdateWorldDataForTile(const out TTile OriginalTile, XComGameState NewGameState)
{
local XComGameStateHistory History;
local XComWorldData WorldData;
local TTile RebuildTile;
local array<TTile> ChangeTiles;
local array<StateObjectReference> UnitRefs;
local StateObjectReference UnitRef;
local XComGameState_BaseObject UnitOnTile;

History = `XCOMHISTORY;
WorldData = `XWORLD;

GetUpdateTiles(OriginalTile, ChangeTiles);

// update the world data for each tile touched
foreach ChangeTiles(RebuildTile)
{
WorldData.DebugRebuildTileData( RebuildTile );
}

// add any units on the tiles to the new game state since they need to do a visibility update
foreach ChangeTiles(RebuildTile)
{
UnitRefs = WorldData.GetUnitsOnTile( RebuildTile );
foreach UnitRefs( UnitRef )
{
UnitOnTile = History.GetGameStateForObjectID(UnitRef.ObjectID);
UnitOnTile = NewGameState.ModifyStateObject(UnitOnTile.Class, UnitOnTile.ObjectID);
UnitOnTile.bRequiresVisibilityUpdate = true;
}
}
}

// End Issue #1288

DefaultProperties
{
EffectName = "Pillar"
DuplicateResponse = eDupe_Allow
bDestroyOnRemoval = true
}
}
3 changes: 3 additions & 0 deletions X2WOTCCommunityHighlander/X2WOTCCommunityHighlander.x2proj
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,9 @@
<Content Include="Src\XComGame\Classes\X2Effect_LaserSight.uc">
<SubType>Content</SubType>
</Content>
<Content Include="Src\XComGame\Classes\X2Effect_Pillar.uc">
<SubType>Content</SubType>
</Content>
<Content Include="Src\XComGame\Classes\X2EncyclopediaTemplate.uc">
<SubType>Content</SubType>
</Content>
Expand Down

0 comments on commit 912ea6b

Please sign in to comment.