Skip to content

Commit

Permalink
Merge branch 'body-part-components' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
Xymanek committed Oct 2, 2019
2 parents e480f4d + 19e970e commit c781513
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
//-----------------------------------------------------------
// Class: XComBodyPartContentAdvanced
// Author: xyman
//
//-----------------------------------------------------------

//---------------------------------------------------------------------------------------
// FILE: XComBodyPartContentAdvanced
// AUTHOR: Xymanek
//
// Allows cosmetic mods to attach arbitrary actors (eg. EmitterSpawnable) to a body part
//
//---------------------------------------------------------------------------------------
// File added to the CHL (this is a non-base game class). Issue #641
//---------------------------------------------------------------------------------------

class XComBodyPartContentAdvanced extends XComBodyPartContent;

Expand Down
35 changes: 30 additions & 5 deletions X2WOTCCommunityHighlander/Src/XComGame/Classes/XComUnitPawn.uc
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ var private XComNarrativeMoment DialogNarrativeMoment;

var transient bool bPhotoboothPawn;

// Issue #641
// This array is private as it is internal CHL logic and mods do not need to access it directly
// If you have a use case for accessing this array, open a new issue
var private array<Actor> AdvancedBodyPartActors;

delegate AdditionalHitEffect( XComUnitPawn Pawn );

event RigidBodyCollision( PrimitiveComponent HitComponent, PrimitiveComponent OtherComponent,
Expand Down Expand Up @@ -1633,6 +1638,8 @@ function CreateBodyPartAttachment(XComBodyPartContent BodyPartContent)
{
local SkeletalMeshComponent SkelMeshComp;
local XComPawnPhysicsProp PhysicsProp;

// Variables for issue #641
local XComBodyPartContentAdvanced AdvancedContent;
local Actor Archetype, Instance;
local Vector SocketLocation;
Expand All @@ -1641,6 +1648,7 @@ function CreateBodyPartAttachment(XComBodyPartContent BodyPartContent)
if (BodyPartContent == none)
return;

// Start issue #641
AdvancedContent = XComBodyPartContentAdvanced(BodyPartContent);
if (AdvancedContent != none)
{
Expand All @@ -1652,11 +1660,13 @@ function CreateBodyPartAttachment(XComBodyPartContent BodyPartContent)
if (Instance != None)
{
Instance.SetBase(self,, Mesh, BodyPartContent.SocketName);
AdvancedBodyPartActors.AddItem(Instance);
}
}

return;
}
// End issue #641

if( BodyPartContent.SocketName != '' && Mesh.GetSocketByName(BodyPartContent.SocketName) != none )
{
Expand Down Expand Up @@ -1709,25 +1719,30 @@ function RemoveBodyPartAttachment(XComBodyPartContent BodyPartContent)
{
local int AttachmentIndex;
local SkeletalMeshComponent AttachedMesh;

// Variables for issue #641
local XComBodyPartContentAdvanced AdvancedContent;
local Actor AttachedActor, Archetype;

// Start issue #641
AdvancedContent = XComBodyPartContentAdvanced(BodyPartContent);
if (AdvancedContent != none)
{
foreach Attached(AttachedActor)
foreach AdvancedBodyPartActors(AttachedActor)
{
foreach AdvancedContent.Archetypes(Archetype)
{
if (AttachedActor.ObjectArchetype == Archetype)
{
AdvancedBodyPartActors.RemoveItem(AttachedActor);
AttachedActor.Destroy();
}
}
}

return;
}
// End issue #641

if( BodyPartContent.SkeletalMesh != None )
{
Expand Down Expand Up @@ -1815,18 +1830,28 @@ simulated event Destroyed ()
{
super.Destroyed();

DestroyAttachedActors();
DestroyAdvancedBodyPartActors(); // Issue #641
}

simulated function DestroyAttachedActors()
// Start issue #641
simulated private function DestroyAdvancedBodyPartActors ()
{
local Actor Actor;

foreach Attached(Actor)
// We do not need to worry about iterator invalidation here as no callbacks/events in Actor.Destroy() chain
// affect the AdvancedBodyPartActors array. However, if one is to be added, then this code needs to be checked
// for potential iterator invalidation issues
foreach AdvancedBodyPartActors(Actor)
{
Actor.Destroy();
if (Actor != none)
{
Actor.Destroy();
}
}

AdvancedBodyPartActors.Length = 0;
}
// End issue #641

simulated function int GetCurrentFloor()
{
Expand Down

0 comments on commit c781513

Please sign in to comment.