Section 2.6.5. rdInstBase- Proxy Routines, Data and Structures

// [rdInst v1.35] Swaps the Mesh Instance over to its ProxyActor
AActor* rdSwapInstanceToProxyActor(UStaticMesh* mesh,int32 index,const FTransform& transform,bool forImpact=false,bool forLongDistance=false);

// [rdInst v1.35] Swaps the Mesh Instances List over to their ProxyActors
void rdSwapInstancesToProxyActors(TArray<FrdInstanceItems>& instances,const TArray<FTransform>& transforms,TArray<AActor*>& outActors,bool forImpact=false,bool forLongDistance=false);

// [rdInst v1.35] Swaps the Prefab over to its ProxyActor
AActor* rdSwapPrefabToProxyActor(ArdActor* prefab,bool forImpact=false,bool forLongDistance=false);

// [rdInst v1.35] Swaps the ProxyActor back to its Instanced Mesh
void rdSwapProxyActorToInstance(AActor* actor);

// [rdInst v1.35] Swaps the ProxyActors back to their Mesh Instances
void rdSwapProxyActorsToInstances(TArray<FrdInstanceItems>& instances);

// [rdInst v1.35] Swaps the ProxyActor back to its Prefab
void rdSwapProxyActorToPrefab(AActor* actor);

// [rdInst v1.35] Swaps any Actors/Instances to ProxyActors around the impact point
void rdProcessImpactProxies(FVector loc);

// [rdInst v1.40] Marks the Proxy to be set to the Destroyed Instance/Prefab when swapped out
void rdMarkProxyAsDestroyed(AActor* proxy,const FTransform& offset=FTransform());

// [rdInst v1.40] Sets the Proxies state to Destroyed
void rdSetProxyToDestroyed(AActor* proxy,const FTransform& offset=FTransform());

// [rdInst v1.40] Removes the Proxy Instance
void rdRemoveProxyByInstance(UStaticMesh* mesh,int32 index);

// [rdInst v1.40] Removes the Proxy from the passed in proxy actor
void rdRemoveProxyByProxy(AActor* proxy,bool bKeepPinned=false);

// [rdInst v1.43] Removes the Proxy DataLayer from the passed in proxy actor
void rdRemoveProxyByDataLayer(const FString& name);

// [rdInst v1.43] Removes the Proxy ISM from the passed in proxy ISM
void rdRemoveProxyByProxyISM(UStaticMesh* mesh,int32 index);

// [rdInst v1.40] Removes the Proxy Prefab
void rdRemoveProxyByPrefab(ArdActor* prefab);

// [rdInst v1.40] Removes the LongDistance Proxy Instance
void rdRemoveLongDistanceProxyByProxy(AActor* proxy);

// [rdInst v1.40] Removes all Instance and Prefab Proxies
void rdRemoveAllProxies();


// [rdInst v1.35] Spawn the assets from the rdSpawner struct
int32 rdSpawnStuff(const ArdSpawnStuffActor* spawner);

// [rdInst v1.35] C++ only wrapper
int32 rdSpawnStuffData(const FrdSpawnStuffData* spawnData,bool bake=false);

// [rdInst v1.35] Moves the specified Instances (whole mesh proxies only) in the specified way
void rdMassMove(const UStaticMesh* mesh,TEnumAsByte<rdMassMovementType> moveType,float maxDistance=0.0f);

// [rdInst v1.35] Returns a reference to the InstancedMeshToProxy Map
TMap<UStaticMesh*,FrdProxyItem>& rdGetInstancedMeshToProxyMap();

// [rdInst v1.35] Returns a reference to the InstancesToProxy Map
TMap<UStaticMesh*,FrdProxyInstanceItems>& rdGetInstancesToProxyMap();

// [rdInst v1.35] Returns a reference to the PrefabsToProxy Map
TMap<ArdActor*,FrdProxyItem>& rdGetPrefabsToProxyMap();

// [rdInst v1.35] Returns a reference to the LongDistanceInstancesToProxy Map
TMap<UStaticMesh*,FrdProxyInstanceItems>& rdGetLongDistanceInstancesToProxyMap();

// [rdInst v1.35] Returns a reference to the LongDistancePrefabsToProxy Map
TMap<ArdActor*,FrdProxyItem>& rdGetLongDistancePrefabsToProxyMap();

// [rdInst v1.35] Returns a reference to the ProxyActor Map
TMap<AActor*,FrdProxyActorItem>&  rdGetProxyActorMap();

// [rdInst v1.35] Does a SphereTrace, returning found actors and instances
void rdSphereTrace(const FVector location,float radius,TArray<AActor*>& actors,TArray<FrdInstanceItems>& instances,TArray<AActor*>& ignoreActors);

// [rdInst v1.35] Does a BoxTrace, returning found actors and instances
void rdBoxTrace(const FVector location,FVector halfSize,FRotator rot,TArray<AActor*>& actors,TArray<FrdInstanceItems>& instances,TArray<AActor*>& ignoreActors);


// [rdInst v1.35-1.43] FrdProxySetup
USTRUCT(BlueprintType,meta=(HasNativeBreak="/Script/rdInst.rdActor.BreakProxySetup",HasNativeMake="/Script/rdInst.rdActor.MakeProxySetup"))
struct FrdProxySetup {
	GENERATED_BODY()
public:
	FrdProxySetup() : proxyActor(nullptr),proxyStaticMesh(nullptr),destroyedMesh(nullptr),destroyedPrefab(nullptr),bUseWithSphereTrace(true),bUseWithLongDistance(false),
						longDistance(50000.0f),proxyPhysicsTimeout(30.0f),bUseWithDestruction(false),bPooled(false),bSimplePool(false),pooledAmount(0),bDontRemove(false),bDontHide(false),
						bEntireMeshProxy(true),savedState(nullptr),bCallSwapEvent(false) {}

	FrdProxySetup(const FrdProxySetup& o) : proxyActor(o.proxyActor),proxyDataLayerName(o.proxyDataLayerName),proxyStaticMesh(o.proxyStaticMesh),
						destroyedMesh(o.destroyedMesh),destroyedPrefab(o.destroyedPrefab),destroyedOffset(o.destroyedOffset),
						bUseWithSphereTrace(o.bUseWithSphereTrace),bUseWithLongDistance(o.bUseWithLongDistance),longDistance(o.longDistance),proxyPhysicsTimeout(o.proxyPhysicsTimeout),
						bUseWithDestruction(o.bUseWithDestruction),bPooled(o.bPooled),bSimplePool(o.bSimplePool),pooledAmount(o.pooledAmount),bDontRemove(o.bDontRemove),
						bDontHide(o.bDontHide),bEntireMeshProxy(o.bEntireMeshProxy),savedState(o.savedState),bCallSwapEvent(o.bCallSwapEvent) {}

	FrdProxySetup(UClass* pa,const FString& pdl,UStaticMesh* psm,UStaticMesh* dm,UClass* dp,const FTransform& dof,bool ust,bool uld,float ld,float pto,bool ud,bool p,bool sp,int32 pam,bool dr,bool dh,bool em,UrdStateDataAsset* ss,bool cse) : 
						proxyActor(pa),proxyDataLayerName(pdl),proxyStaticMesh(psm),destroyedMesh(dm),destroyedPrefab(dp),destroyedOffset(dof),bUseWithSphereTrace(ust),bUseWithLongDistance(uld),longDistance(ld),proxyPhysicsTimeout(pto),
						bUseWithDestruction(ud),bPooled(p),bSimplePool(sp),pooledAmount(pam),bDontRemove(dr),bDontHide(dh),bEntireMeshProxy(em),savedState(ss),bCallSwapEvent(cse) {}

	UPROPERTY(Category=rdProxies,EditAnywhere)
	UClass* proxyActor=nullptr;

	UPROPERTY(Category=rdProxies,EditAnywhere)
	FString proxyDataLayerName;

	UPROPERTY(Category=rdProxies,EditAnywhere)
	UStaticMesh* proxyStaticMesh=nullptr;

	UPROPERTY(Category=rdProxies,EditAnywhere)
	UStaticMesh* destroyedMesh=nullptr;

	UPROPERTY(Category=rdProxies,EditAnywhere)
	UClass* destroyedPrefab=nullptr;

	UPROPERTY(Category=rdProxies,EditAnywhere)
	FTransform	destroyedOffset=FTransform::Identity;

	UPROPERTY(Category=rdProxies,EditAnywhere)
	uint8 bUseWithSphereTrace:1;

	UPROPERTY(Category=rdProxies,EditAnywhere)
	uint8 bUseWithLongDistance:1;

	UPROPERTY(Category=rdProxies,EditAnywhere)
	float longDistance=50000.0f;

	UPROPERTY(Category=rdProxies,EditAnywhere)
	float proxyPhysicsTimeout=30.0f;

	UPROPERTY(Category=rdProxies,EditAnywhere)
	uint8 bUseWithDestruction:1;

	UPROPERTY(Category=rdProxies,EditAnywhere)
	uint8 bPooled:1;

	UPROPERTY(Category=rdProxies,EditAnywhere)
	uint8 bSimplePool:1;

	UPROPERTY(Category=rdProxies,EditAnywhere)
	int32 pooledAmount=0;

	UPROPERTY(Category=rdProxies,EditAnywhere)
	uint8 bDontRemove:1;

	UPROPERTY(Category=rdProxies,EditAnywhere)
	uint8 bDontHide:1;

	UPROPERTY(Category=rdProxies,EditAnywhere)
	uint8 bEntireMeshProxy:1;

	UPROPERTY(Category=rdProxies,EditAnywhere)
	UrdStateDataAsset* savedState=nullptr;

	UPROPERTY(Category=rdProxies,EditAnywhere)
	bool bCallSwapEvent=false;
};

// [rdInst v1.35-1.43] FrdProxyItem
struct FrdProxyItem {
	GENERATED_BODY()
	FrdProxyItem() : bHasProxy(false),mesh(nullptr),destroyedMesh(nullptr),destroyedPrefab(nullptr),proxyActor(nullptr),proxyPhysicsTimeout(30.0),bUseWithSphereTrace(true),bUseWithDestruction(false),bPooled(true),bSimplePool(false),bDontRemove(false),bDontHide(false),savedState(nullptr),bDestroyed(false),bCallSwapEvent(false) {}
	FrdProxyItem(const FrdProxyItem& o) : bHasProxy(o.bHasProxy),mesh(o.mesh),destroyedMesh(o.destroyedMesh),destroyedPrefab(o.destroyedPrefab),destroyedOffset(o.destroyedOffset),
					instanceIndex(o.instanceIndex),prefab(o.prefab),actorClass(o.actorClass),
					proxyDataLayerName(o.proxyDataLayerName),proxyStaticMesh(o.proxyStaticMesh),distance(o.distance),transform(o.transform),
					proxyActor(o.proxyActor),proxyPhysicsTimeout(o.proxyPhysicsTimeout),proxyInstanceIndex(o.proxyInstanceIndex),proxyInstanceComponent(o.proxyInstanceComponent),
					bUseWithSphereTrace(o.bUseWithSphereTrace),bUseWithDestruction(o.bUseWithDestruction),bPooled(o.bPooled),bSimplePool(o.bSimplePool),bDontRemove(o.bDontRemove),
					bDontHide(o.bDontHide),savedState(o.savedState),instanceVolume(o.instanceVolume),bDestroyed(o.bDestroyed),bCallSwapEvent(o.bCallSwapEvent),swappedInstances(o.swappedInstances) {}
	FrdProxyItem(UStaticMesh* m,UStaticMesh* dm,UClass* dp,const FTransform& dof,int32 ii,ArdActor* pf,UClass* ac,float d,const FTransform& t,AActor* ia,float pto,int32 pii,UInstancedStaticMeshComponent* pic,const FString& pdl,UStaticMesh* psm,bool ust,bool ud,bool p,bool sp,bool dr,bool dh,AActor* iv,bool dy,UrdStateDataAsset*& ss,bool cse) : 
					bHasProxy(false),mesh(m),destroyedMesh(dm),destroyedPrefab(dp),destroyedOffset(dof),instanceIndex(ii),prefab(pf),actorClass(ac),
					proxyDataLayerName(pdl),proxyStaticMesh(psm),distance(d),transform(t),proxyActor(ia),proxyPhysicsTimeout(pto),proxyInstanceIndex(pii),proxyInstanceComponent(pic),
					bUseWithSphereTrace(ust),bUseWithDestruction(ud),bPooled(p),bSimplePool(sp),bDontRemove(dr),bDontHide(dh),savedState(ss),instanceVolume(iv),bDestroyed(dy),bCallSwapEvent(cse) {}
	FrdProxyItem(const FrdProxySetup& o) : bHasProxy(false),mesh(nullptr),destroyedMesh(o.destroyedMesh),destroyedPrefab(o.destroyedPrefab),destroyedOffset(o.destroyedOffset),
					instanceIndex(-1),prefab(nullptr),actorClass(o.proxyActor),
					proxyDataLayerName(o.proxyDataLayerName),proxyStaticMesh(o.proxyStaticMesh),distance(o.longDistance),transform(),
		proxyActor(nullptr),proxyPhysicsTimeout(o.proxyPhysicsTimeout),proxyInstanceIndex(-1),proxyInstanceComponent(nullptr),
					bUseWithSphereTrace(o.bUseWithSphereTrace),bUseWithDestruction(o.bUseWithDestruction),bPooled(o.bPooled),bSimplePool(o.bSimplePool),bDontRemove(o.bDontRemove),
					bDontHide(o.bDontHide),savedState(o.savedState),instanceVolume(nullptr),bDestroyed(false),bCallSwapEvent(o.bCallSwapEvent) {}
public:
	UPROPERTY(Category=rdProxies,EditAnywhere)
	uint8			bHasProxy:1;

	UPROPERTY(Category=rdProxies,EditAnywhere)
	UStaticMesh* mesh=nullptr;

	UPROPERTY(Category=rdProxies,EditAnywhere)
	UStaticMesh* destroyedMesh=nullptr;

	UPROPERTY(Category=rdProxies,EditAnywhere)
	UClass* destroyedPrefab=nullptr;

	UPROPERTY(Category=rdProxies,EditAnywhere)
	FTransform	destroyedOffset;

	UPROPERTY(Category=rdProxies,EditAnywhere)
	int32 instanceIndex=-1;

	UPROPERTY(Category=rdProxies,EditAnywhere)
	ArdActor* prefab=nullptr;

	UPROPERTY(Category=rdProxies,EditAnywhere)
	UClass*	actorClass=nullptr;

	UPROPERTY(Category=rdProxies,EditAnywhere)
	FString proxyDataLayerName;

	UPROPERTY(Category=rdProxies,EditAnywhere)
	UStaticMesh* proxyStaticMesh=nullptr;

	UPROPERTY(Category=rdProxies,EditAnywhere)
	double distance=20000.0f;

	UPROPERTY(Category=rdProxies,EditAnywhere)
	FTransform	transform;

	UPROPERTY(Category=rdProxies,EditAnywhere)
	AActor* proxyActor=nullptr;

	UPROPERTY(Category=rdProxies,EditAnywhere)
	float proxyPhysicsTimeout=30.0f;

	UPROPERTY(Category=rdProxies,EditAnywhere)
	int32 proxyInstanceIndex=-1;

	UPROPERTY(Category=rdProxies,EditAnywhere)
	UInstancedStaticMeshComponent*	proxyInstanceComponent=nullptr;

	UPROPERTY(Category=rdProxies,EditAnywhere)
	uint8 bUseWithSphereTrace:1;

	UPROPERTY(Category=rdProxies,EditAnywhere)
	uint8 bUseWithDestruction:1;

	UPROPERTY(Category=rdProxies,EditAnywhere)
	uint8 bPooled:1;

	UPROPERTY(Category=rdProxies,EditAnywhere)
	uint8 bSimplePool:1;

	UPROPERTY(Category=rdProxies,EditAnywhere)
	uint8 bDontRemove:1;

	UPROPERTY(Category=rdProxies,EditAnywhere)
	uint8 bDontHide:1;

	UPROPERTY(Category=rdProxies,EditAnywhere)
	UrdStateDataAsset* savedState=nullptr;

	UPROPERTY(Category=rdProxies,EditAnywhere)
	AActor* instanceVolume=nullptr;

	UPROPERTY(Category=rdProxies,EditAnywhere)
	uint8 bDestroyed:1;

	UPROPERTY(Category=rdProxies,EditAnywhere)
	uint8 bCallSwapEvent:1;

	TArray<int32> swappedInstances;
};

// [rdInst v1.35] FrdProxyInstanceItems
USTRUCT(BlueprintType)
struct FrdProxyInstanceItems {
	GENERATED_BODY()
public:
	UPROPERTY(Category=rdProxies,EditAnywhere)
	TMap<int32,FrdProxyItem> proxyInstanceIndexList;
};

// [rdInst v1.35-1.43] FrdProxyActorItem
USTRUCT(BlueprintType,meta=(HasNativeBreak="/Script/rdInst.rdActor.BreakProxyActorItem",HasNativeMake="/Script/rdInst.rdActor.MakeProxyActorItem"))
struct FrdProxyActorItem {
	GENERATED_BODY()
public:
	FrdProxyActorItem() : proxyActor(nullptr),proxyInstanceIndex(-1),proxySource(0),instanceIndex(-1),idleCountdown(10),forDestruction(false),forLongDistance(false),bDontRemove(false),bDontHide(false),spawnMillis(0) {}
	FrdProxyActorItem(const FrdProxyActorItem& o) : proxyActor(o.proxyActor),proxyInstanceIndex(o.proxyInstanceIndex),proxyInstanceComponent(o.proxyInstanceComponent),proxyItem(o.proxyItem),proxySource(o.proxySource),instanceIndex(o.instanceIndex),idleCountdown(o.idleCountdown),forDestruction(o.forDestruction),forLongDistance(o.forLongDistance),bDontRemove(o.bDontRemove),bDontHide(o.bDontHide),spawnMillis(o.spawnMillis) {}
	FrdProxyActorItem(AActor* pa,int32 pii,UInstancedStaticMeshComponent* pic,const FrdProxyItem& pi,int32 ps,int32 ii,const FTransform& t,int32 ic,bool fd,bool fld,bool dr,bool dh) : proxyActor(pa),proxyInstanceIndex(pii),proxyInstanceComponent(pic),proxyItem(pi),proxySource(0),instanceIndex(-1),idleCountdown(10),forDestruction(fd),forLongDistance(fld),bDontRemove(dr),bDontHide(dh),spawnMillis(0) {}

	UPROPERTY(Category=rdProxies,EditAnywhere)
	AActor*			proxyActor=nullptr;

	UPROPERTY(Category=rdProxies,EditAnywhere)
	int32			proxyInstanceIndex=-1;

	UPROPERTY(Category=rdProxies,EditAnywhere)
	UInstancedStaticMeshComponent*	proxyInstanceComponent=nullptr;

	FrdProxyItem	proxyItem;
	int32			proxySource=0;

	UPROPERTY(Category=rdProxies,EditAnywhere)
	int32			instanceIndex=-1;
	UPROPERTY(Category=rdProxies,EditAnywhere)
	FTransform		instanceTransform;

	UPROPERTY(Category=rdProxies,EditAnywhere)
	int32			idleCountdown=10;
	UPROPERTY(Category=rdProxies,EditAnywhere)
	uint8			forDestruction:1;
	UPROPERTY(Category=rdProxies,EditAnywhere)
	uint8			forLongDistance:1;
	UPROPERTY(Category=rdProxies,EditAnywhere)
	uint8			bDontRemove:1;
	UPROPERTY(Category=rdProxies,EditAnywhere)
	uint8			bDontHide:1;

	uint64			spawnMillis=0;
};

// [rdInst v1.35-1.43] FrdInstanceItems
USTRUCT(BlueprintType,meta=(HasNativeBreak="/Script/rdInst.rdActor.BreakInstanceItems",HasNativeMake="/Script/rdInst.rdActor.MakeInstanceItems"))
struct FrdInstanceItems {
	GENERATED_BODY()
public:

	FrdInstanceItems() : mesh(nullptr) {}
	FrdInstanceItems(const FrdInstanceItems& o) : mesh(o.mesh),volume(o.volume),instances(o.instances),transforms(o.transforms) {}
	FrdInstanceItems(UStaticMesh* m,const TArray<int32>& i,const TArray<FTransform>& t) : mesh(m),instances(i),transforms(t) {}

	UPROPERTY(Category=rdInstances,EditAnywhere)
	UStaticMesh* mesh=nullptr;

	UPROPERTY(Category=rdInstances,EditAnywhere)
	AActor* volume=nullptr;

	UPROPERTY(Category=rdInstances,EditAnywhere)
	TArray<int32> instances;

	UPROPERTY(Category=rdInstances,EditAnywhere)
	TArray<FTransform> transforms;
};