Commit 644e7e54 authored by Kyrium's avatar Kyrium
Browse files

more fixes

parent d3d56775
......@@ -2,7 +2,7 @@
#include "Subsystems/ResourceNodes/KBFLActorSpawnDescriptor.h"
#include "Subsystems/ResourceNodes/ResourceNodesLogging.h"
void UKBFLActorSpawnDescriptor::ForeachLocations(TArray<FTransform>& TransformArray)
void UKBFLActorSpawnDescriptor::ForeachLocations(TArray<AActor*>& ActorArray)
{
UE_LOG(ActorSpawnerLog, Warning, TEXT("ForeachLocations Actors"));
......@@ -14,12 +14,14 @@ void UKBFLActorSpawnDescriptor::ForeachLocations(TArray<FTransform>& TransformAr
}
UE_LOG(ActorSpawnerLog, Warning, TEXT("Try Actor spawn at: %s"), *Location.ToString());
TransformArray.Add(Location);
AActor* OutActor;
if(!CheckActorInRange(Location, OutActor) && IsRangeFree(Location))
{
UE_LOG(ActorSpawnerLog, Warning, TEXT("!CheckActorInRange(Location, OutActor) && IsRangeFree(Location)"));
SpawnActorAtLocation(Location, GetActorClass());
}
if(OutActor)
ActorArray.AddUnique(OutActor);
}
}
......@@ -21,19 +21,17 @@ void UKBFLActorSpawnDescriptorBase::BeginSpawning()
{
UE_LOG(ActorSpawnerLog, Log, TEXT("BeginSpawning > Classes Valid"));
TArray<FTransform> TransformArray;
ForeachLocations(TransformArray);
TArray<AActor*> ActorArray;
ForeachLocations(ActorArray);
AfterSpawning();
if(mRemoveOld)
RemoveWrongActors(TransformArray);
mSubsystem->Server_FinishedSpawningNodes();
RemoveWrongActors(ActorArray);
}
}
}
void UKBFLActorSpawnDescriptorBase::ForeachLocations(TArray<FTransform>& TransformArray)
void UKBFLActorSpawnDescriptorBase::ForeachLocations(TArray<AActor*>& ActorArray)
{
}
......@@ -87,41 +85,32 @@ bool UKBFLActorSpawnDescriptorBase::IsRangeFree(FTransform Transform)
return Free && OutActors.Num() == 0;
}
void UKBFLActorSpawnDescriptorBase::RemoveWrongActors(TArray<FTransform>& TransformArray)
void UKBFLActorSpawnDescriptorBase::RemoveWrongActors(TArray<AActor*>& ActorArray)
{
TArray<AActor*> OutActors;
UGameplayStatics::GetAllActorsOfClass(GetWorld(), GetActorClass(), OutActors);
UE_LOG(ActorSpawnerLog, Log, TEXT("Remove Actors > Found, %d"), OutActors.Num());
for (AActor* Actor : OutActors)
if (GetActorClass())
{
bool IsActorCorrect = false;
FTransform LastTransform;
for (int i = 0; i < TransformArray.Num(); ++i)
for(TActorIterator Actor(GetWorld(), GetActorClass()); Actor; ++Actor)
{
LastTransform = TransformArray[i];
if(FVector::Distance(Actor->GetActorLocation(), TransformArray[i].GetLocation()) <= mCheckRange)
bool IsActorCorrect = ActorArray.Contains(*Actor);
if(!IsActorCorrect && IsAllowedToRemoveActor(*Actor))
{
IsActorCorrect = true;
TransformArray.RemoveAt(i);
break;
UE_LOG(ActorSpawnerLog, Log, TEXT("Remove Actors > Destroy wrong at, %s"), *Actor->GetTransform().ToString());
Actor->Destroy();
}
}
if(!IsActorCorrect && IsAllowedToRemoveActor(Actor))
{
UE_LOG(ActorSpawnerLog, Log, TEXT("Remove Actors > Destroy wrong at, %s"), *LastTransform.ToString());
Actor->Destroy();
}
}
}
void UKBFLActorSpawnDescriptorBase::ApplyMaterialData(AActor* Actor, TMap<uint8, UMaterialInterface*> MaterialInfo)
{
UE_LOG(ActorSpawnerLog, Log, TEXT("ApplyMaterialData <%s> | %d"), *Actor->GetName(), MaterialInfo.Num());
if(Actor && MaterialInfo.Num() > 0)
{
if(UActorComponent* PrimitiveComponent = Actor->GetComponentByClass(UStaticMeshComponent::StaticClass()))
TArray<UActorComponent*> PrimitiveComponent = Actor->GetComponentsByClass(UStaticMeshComponent::StaticClass());
if(PrimitiveComponent.Num() > 0)
{
UStaticMeshComponent* StaticMesh = Cast<UStaticMeshComponent>(PrimitiveComponent);
UStaticMeshComponent* StaticMesh = Cast<UStaticMeshComponent>(PrimitiveComponent[0]);
if(StaticMesh)
{
for (auto Info : MaterialInfo)
......@@ -174,3 +163,6 @@ void UKBFLActorSpawnDescriptorBase::ModifySpawnedActorPostSpawn(AActor*& InActor
{
//
}
void UKBFLActorSpawnDescriptorBase::AfterSpawning()
{}
......@@ -2,14 +2,13 @@
#include "Subsystems/ResourceNodes/KBFLResourceNodeDescriptor_ResourceNode.h"
#include "Subsystems/ResourceNodes/ResourceNodesLogging.h"
void UKBFLResourceNodeDescriptor_ResourceNode::ForeachLocations(TArray<FTransform>& TransformArray)
void UKBFLResourceNodeDescriptor_ResourceNode::ForeachLocations(TArray<AActor*>& ActorArray)
{
for (TTuple<TEnumAsByte<EResourcePurity>, FKBFLTransformArray> PurityMap : mPurityLocations)
{
mLastPur = PurityMap.Key;
for (FTransform Location : PurityMap.Value.mTransforms)
{
TransformArray.Add(Location);
AActor* OutActor;
if(!CheckActorInRange(Location, OutActor) && IsRangeFree(Location))
{
......@@ -17,7 +16,10 @@ void UKBFLResourceNodeDescriptor_ResourceNode::ForeachLocations(TArray<FTransfor
}
if(OutActor)
{
ApplyMaterialData(OutActor, mResourceNodeMaterialInfo);
ActorArray.AddUnique(OutActor);
}
}
}
}
......
......@@ -18,7 +18,7 @@ uint32 UKBFLResourceNodeDescriptor_ResourceWell::GetCountOfSat(TMap<TEnumAsByte<
return count;
}
void UKBFLResourceNodeDescriptor_ResourceWell::ForeachLocations(TArray<FTransform>& TransformArray)
void UKBFLResourceNodeDescriptor_ResourceWell::ForeachLocations(TArray<AActor*>& ActorArray)
{
UE_LOG(ActorSpawnerLog, Warning, TEXT("ForeachLocations Wells"));
for (FKBFLCoreInformations WellData : mLocations)
......@@ -41,11 +41,14 @@ void UKBFLResourceNodeDescriptor_ResourceWell::ForeachLocations(TArray<FTransfor
OutActor = SpawnActorAtLocation(WellData.mCoreLocation, GetActorClass());
}
if(OutActor)
ApplyMaterialData(OutActor, WellData.mFrackingCoreMaterialInfo);
mLastCore = Cast<AFGResourceNodeFrackingCore>(OutActor);
if(mLastCore)
{
ApplyMaterialData(mLastCore, WellData.mFrackingCoreMaterialInfo);
ActorArray.AddUnique(mLastCore);
}
if(mLastCore)
{
TArray<AFGResourceNodeFrackingSatellite*> Satellites = {};
......@@ -57,16 +60,16 @@ void UKBFLResourceNodeDescriptor_ResourceWell::ForeachLocations(TArray<FTransfor
{
if(Location.GetLocation() != FVector(0))
{
UE_LOG(ActorSpawnerLog, Warning, TEXT("Try Sat check at: %s"), *Location.ToString());
TransformArray.Add(Location);
if(!CheckActorInRange(Location, OutActor) && IsRangeFree(Location))
{
UE_LOG(ActorSpawnerLog, Warning, TEXT("Try Sat spawn at: %s"), *Location.ToString());
OutActor = SpawnActorAtLocation(Location, mFrackingSatelliteClass);
}
if(OutActor)
{
ApplyMaterialData(OutActor, WellData.mFrackingSatelliteMaterialInfo);
ActorArray.AddUnique(OutActor);
}
if(AFGResourceNodeFrackingSatellite* Satellite = Cast<AFGResourceNodeFrackingSatellite>(OutActor))
{
......@@ -82,7 +85,10 @@ void UKBFLResourceNodeDescriptor_ResourceWell::ForeachLocations(TArray<FTransfor
{
OutActor = SpawnActorAtLocation(Location, mCrackClass);
if(OutActor)
{
ApplyMaterialData(OutActor, WellData.mCrackMaterialInfo);
ActorArray.AddUnique(OutActor);
}
}
}
else
......@@ -92,7 +98,6 @@ void UKBFLResourceNodeDescriptor_ResourceWell::ForeachLocations(TArray<FTransfor
}
bIsInSatelliteSpawning = false;
Super::ForeachLocations(TransformArray);
}
void UKBFLResourceNodeDescriptor_ResourceWell::Validate(TArray<AFGResourceNodeFrackingSatellite*> Satellites)
......@@ -120,17 +125,14 @@ void UKBFLResourceNodeDescriptor_ResourceWell::Validate(TArray<AFGResourceNodeFr
mLastCore->mActivator->mSatelliteNodeCount = mLastCore->mSatellites.Num();
mLastCore->mActivator->CalculateConnectedExtractorCount();
mLastCore->mActivator->CalculateDefaultPotentialExtractionPerMinute();
UE_LOG(ActorSpawnerLog, Warning, TEXT("CalculateDefaultPotentialExtractionPerMinute"));
}
UE_LOG(ActorSpawnerLog, Warning, TEXT("Ensure Count! %d"), mLastCore->mSatellites.Num());
TArray<AFGResourceNodeFrackingSatellite*> AllreadyFound = {};
for (int i = 0; i < mLastCore->mSatellites.Num(); ++i)
{
if(mLastCore->mSatellites[i].IsValid() && !AllreadyFound.Contains(mLastCore->mSatellites[i]))
{
UE_LOG(ActorSpawnerLog, Warning, TEXT("Remove Duplicated"));
UE_LOG(ActorSpawnerLog, Warning, TEXT("Remove Duplicated Satellite"));
mLastCore->mSatellites.RemoveAt(i);
}
else
......@@ -210,7 +212,6 @@ bool UKBFLResourceNodeDescriptor_ResourceWell::IsAllowedToRemoveActor(AActor* In
int32 CountOfSat = Fracking->GetSatellites().Num();
for (TWeakObjectPtr<AFGResourceNodeFrackingSatellite> Satellite : Fracking->GetSatellites())
{
UE_LOG(ActorSpawnerLog, Warning, TEXT("Satellite %s"), *Satellite->GetName());
if(Satellite.IsValid())
{
if(Satellite->IsOccupied())
......@@ -230,93 +231,60 @@ bool UKBFLResourceNodeDescriptor_ResourceWell::IsAllowedToRemoveActor(AActor* In
if(class AFGResourceNodeFrackingSatellite* Satellite = Cast<AFGResourceNodeFrackingSatellite>(InActor))
{
UE_LOG(ActorSpawnerLog, Warning, TEXT("IsAllowedToRemoveActor Satellite"), *Satellite->GetName());
if(Satellite->mCore)
{
UE_LOG(ActorSpawnerLog, Warning, TEXT("IsAllowedToRemoveActor Satellite FALSE!!!!"), *Satellite->GetName());
return false;
}
return true;
}
return Super::IsAllowedToRemoveActor(InActor);
}
void UKBFLResourceNodeDescriptor_ResourceWell::RemoveWrongActors(TArray<FTransform>& TransformArray)
void UKBFLResourceNodeDescriptor_ResourceWell::RemoveWrongActors(TArray<AActor*>& ActorArray)
{
TArray<AActor*> OutActors;
UGameplayStatics::GetAllActorsOfClass(GetWorld(), mFrackingCoreClass, OutActors);
for (const auto InActor : OutActors)
for(TActorIterator<AFGResourceNodeFrackingCore> CoreActor(GetWorld(), mFrackingCoreClass); CoreActor; ++CoreActor)
{
class AFGResourceNodeFrackingCore* Fracking = Cast<class AFGResourceNodeFrackingCore>(InActor);
if(Fracking)
const bool IsActorCorrect = ActorArray.Contains(*CoreActor);
if(!IsActorCorrect)
{
bool IsNodeCorrect = false;
for (int i = 0; i < mCoreTransforms.Num(); ++i)
{
UE_LOG(ActorSpawnerLog, Warning, TEXT("Core Distance: %f"), FVector::Distance(InActor->GetActorLocation(), mCoreTransforms[i].GetLocation()));
if(FVector::Distance(InActor->GetActorLocation(), mCoreTransforms[i].GetLocation()) <= mCheckRange)
{
UE_LOG(ActorSpawnerLog, Warning, TEXT("Core is Valid > %s "), *Fracking->GetName());
IsNodeCorrect = true;
mCoreTransforms.RemoveAt(i);
break;
}
}
UE_LOG(ActorSpawnerLog, Warning, TEXT("Core remove! > %s "), *CoreActor->GetName());
UE_LOG(ActorSpawnerLog, Warning, TEXT("Core remove! > %s "), *Fracking->GetName());
if(!IsNodeCorrect)
for (TWeakObjectPtr<AFGResourceNodeFrackingSatellite> Sat : CoreActor->GetSatellites())
{
for (TWeakObjectPtr<AFGResourceNodeFrackingSatellite> Sat : Fracking->GetSatellites())
if(Sat.IsValid() && IsAllowedToRemoveActor(Sat.Get()))
{
if(Sat.IsValid() && IsAllowedToRemoveActor(Sat.Get()))
{
Sat->K2_DestroyActor();
}
Sat->K2_DestroyActor();
}
}
if(IsAllowedToRemoveActor(InActor) && !IsNodeCorrect)
{
UE_LOG(ActorSpawnerLog, Log, TEXT("Remove Actors > Destroy > %s"), *InActor->GetName());
InActor->K2_DestroyActor();
}
if(IsAllowedToRemoveActor(*CoreActor))
{
UE_LOG(ActorSpawnerLog, Log, TEXT("Remove Core > %s"), *CoreActor->GetName());
CoreActor->K2_DestroyActor();
}
}
}
UGameplayStatics::GetAllActorsOfClass(GetWorld(), mFrackingSatelliteClass, OutActors);
for (const auto InActor : OutActors)
for(TActorIterator<AFGResourceNodeFrackingSatellite> SatelliteActor(GetWorld(), mFrackingSatelliteClass); SatelliteActor; ++SatelliteActor)
{
if(class AFGResourceNodeFrackingSatellite* Satellite = Cast<class AFGResourceNodeFrackingSatellite>(InActor))
const bool IsActorCorrect = ActorArray.Contains(*SatelliteActor);
if(!IsActorCorrect)
{
bool IsNodeCorrect = false;
for (int i = 0; i < mCoreTransforms.Num(); ++i)
{
UE_LOG(ActorSpawnerLog, Warning, TEXT("Core Distance: %f"), FVector::Distance(InActor->GetActorLocation(), mCoreTransforms[i].GetLocation()));
if(FVector::Distance(InActor->GetActorLocation(), mCoreTransforms[i].GetLocation()) <= mCheckRange)
{
IsNodeCorrect = true;
mCoreTransforms.RemoveAt(i);
break;
}
}
if(!IsNodeCorrect)
{
if(IsAllowedToRemoveActor(Satellite))
{
UE_LOG(ActorSpawnerLog, Log, TEXT("Remove Actors > Destroy > %s"), *InActor->GetName());
if(Satellite->mCore)
if(Satellite->mCore->mSatellites.Contains(Satellite))
Satellite->mCore->mSatellites.Remove(Satellite);
Satellite->Destroy();
}
}
else if(!Satellite->mCore)
if(IsAllowedToRemoveActor(*SatelliteActor))
{
UE_LOG(ActorSpawnerLog, Log, TEXT("Remove Actors > InValidCore!!! > %s"), *InActor->GetName());
Satellite->Destroy();
if(SatelliteActor->mCore)
if(SatelliteActor->mCore->mSatellites.Contains(*SatelliteActor))
SatelliteActor->mCore->mSatellites.Remove(*SatelliteActor);
SatelliteActor->Destroy();
}
}
else if(!SatelliteActor->mCore)
{
UE_LOG(ActorSpawnerLog, Log, TEXT("Remove Actors > InValidCore!!! > %s"), *SatelliteActor->GetName());
SatelliteActor->Destroy();
}
}
}
......@@ -16,7 +16,7 @@ class KBFL_API UKBFLActorSpawnDescriptor : public UKBFLActorSpawnDescriptorBase
public:
virtual void ForeachLocations(TArray<FTransform>& TransformArray) override;
virtual void ForeachLocations(TArray<AActor*>& ActorArray) override;
FORCEINLINE virtual TSubclassOf<AActor> GetActorClass() override { return mActorClass; };
......
......@@ -21,16 +21,16 @@ class KBFL_API UKBFLActorSpawnDescriptorBase : public UObject
#endif
void BeginSpawning();
virtual void ForeachLocations(TArray<FTransform>& TransformArray);
virtual void ForeachLocations(TArray<AActor*>& ActorArray);
virtual bool CheckActorInRange(FTransform Transform, AActor*& OutActor);
virtual void ModifyCheckActor(AActor*& InActor, FTransform FoundTransform);
virtual bool IsRangeFree(FTransform Transform);
virtual void RemoveWrongActors(TArray<FTransform>& TransformArray);
virtual void RemoveWrongActors(TArray<AActor*>& ActorArray);
virtual AActor* SpawnActorAtLocation(FTransform Transform, TSubclassOf<AActor> ClassToSpawn);
virtual void ModifySpawnedActorPreSpawn(AActor*& InActor);
virtual void ModifySpawnedActorPostSpawn(AActor*& InActor);
virtual void AfterSpawning() {};
virtual void AfterSpawning();;
void ApplyMaterialData(AActor* Actor, TMap<uint8, UMaterialInterface*> MaterialInfo);
......
......@@ -28,7 +28,7 @@ class KBFL_API UKBFLResourceNodeDescriptor_ResourceNode : public UKBFLResourceNo
GENERATED_BODY()
public:
virtual void ForeachLocations(TArray<FTransform>& TransformArray) override;
virtual void ForeachLocations(TArray<AActor*>& ActorArray) override;
virtual void ModifyCheckActor(AActor*& InActor, FTransform FoundTransform) override;
virtual void ModifySpawnedActorPreSpawn(AActor*& InActor) override;
/*virtual void ModifySpawnedActorPostSpawn(AActor*& InActor) override {
......
......@@ -52,7 +52,7 @@ class KBFL_API UKBFLResourceNodeDescriptor_ResourceWell : public UKBFLResourceNo
public:
virtual void ForeachLocations(TArray<FTransform>& TransformArray) override;
virtual void ForeachLocations(TArray<AActor*>& ActorArray) override;
virtual void ModifyCheckActor(AActor*& InActor, FTransform FoundTransform) override;
virtual void ModifySpawnedActorPreSpawn(AActor*& InActor) override;
virtual void ModifySpawnedActorPostSpawn(AActor*& InActor) override;
......@@ -63,7 +63,7 @@ class KBFL_API UKBFLResourceNodeDescriptor_ResourceWell : public UKBFLResourceNo
virtual bool IsAllowedToRemoveActor(AActor* InActor) override;
virtual void RemoveWrongActors(TArray<FTransform>& TransformArray) override;
virtual void RemoveWrongActors(TArray<AActor*>& ActorArray) override;
uint32 GetCountOfSat(TMap<TEnumAsByte< EResourcePurity >, FKBFLTransformArray> SatMap);
/*virtual void ModifySpawnedActorPostSpawn(AActor*& InActor) override {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment