Space Plunder
Loading...
Searching...
No Matches
UBTT_FindRandomPatrolPoint Class Reference

#include <BTT_FindRandomPatrolPoint.h>

Inheritance diagram for UBTT_FindRandomPatrolPoint:

Public Member Functions

 UBTT_FindRandomPatrolPoint ()
 

Public Attributes

bool bDebuggingMode = false
 
bool bShowText = true
 
float PointSize = 20.0f
 
FColor TraceColor = FColor::Green
 
FColor TargetPatrolPointColor = FColor::Red
 
TEnumAsByte< EObjectTypeQuery > ObjectChannelToUse = ObjectTypeQuery1
 
FBlackboardKeySelector MoveTargetLocation
 
FBlackboardKeySelector bBridgeAvailable
 
FBlackboardKeySelector NextPatrolPoint
 
FBlackboardKeySelector NextBridgePatrolPoint
 
FBlackboardKeySelector WaitTime
 
float Radius = 2000.0f
 

Protected Member Functions

virtual EBTNodeResult::Type ExecuteTask (UBehaviorTreeComponent &OwnerComp, uint8 *NodeMemory) override
 
virtual FString GetStaticDescription () const override
 

Constructor & Destructor Documentation

◆ UBTT_FindRandomPatrolPoint()

UBTT_FindRandomPatrolPoint::UBTT_FindRandomPatrolPoint ( )
17{
18 NodeName = TEXT("Find Random Patrol Point");
19
20}

Member Function Documentation

◆ ExecuteTask()

EBTNodeResult::Type UBTT_FindRandomPatrolPoint::ExecuteTask ( UBehaviorTreeComponent & OwnerComp,
uint8 * NodeMemory )
overrideprotectedvirtual
23{
24 TRACE_CPUPROFILER_EVENT_SCOPE(UBTT_FindRandomPatrolPoint::ExecuteTask);
25 SCOPE_CYCLE_COUNTER(STATGROUP_AIToolKit_Behaviors);
26 SCOPE_CYCLE_COUNTER(STATGROUP_AIToolKit_Tasks);
27 TArray<AActor*> ActorsToIgnore;
28 TArray<FHitResult> HitArray;
29
30 if(OwnerComp.GetAIOwner() != nullptr && OwnerComp.GetAIOwner()->GetPawn() != nullptr)
31 {
32 const FVector Start = OwnerComp.GetAIOwner()->GetPawn()->GetActorLocation();
33
34 const FVector End = OwnerComp.GetAIOwner()->GetPawn()->GetActorForwardVector() + Start;
35 TArray<TEnumAsByte<EObjectTypeQuery>> NameOfObjects;
36 NameOfObjects.Add(ObjectChannelToUse);
37
38 EDrawDebugTrace::Type DebugDraw = EDrawDebugTrace::None;
40 {
41 DebugDraw = EDrawDebugTrace::ForDuration;
42 }
43
44 const bool bHit = UKismetSystemLibrary::SphereTraceMultiForObjects(GetWorld(), Start, End, Radius, NameOfObjects, false, ActorsToIgnore, DebugDraw, HitArray, true, TraceColor, TargetPatrolPointColor, 1.0f);
45 if(bHit)
46 {
47 AActor* BestActor = nullptr;
48 float BestDistance = 10000000000000.0f;
49 for(const FHitResult Hit : HitArray)
50 {
51 IPatrolInterface* PatrolPoint = Cast<IPatrolInterface>(Hit.GetActor());
52 if(Hit.Distance < BestDistance && PatrolPoint != nullptr)
53 {
54 BestDistance = Hit.Distance;
55 BestActor = Hit.GetActor();
56 }
57 }
58 if(OwnerComp.GetBlackboardComponent() != nullptr && BestActor != nullptr)
59 {
60
61 OwnerComp.GetBlackboardComponent()->SetValueAsVector(MoveTargetLocation.SelectedKeyName, BestActor->GetActorLocation());
62
63 //- Get All Values?
64 IPatrolInterface* PatrolPoint = Cast<IPatrolInterface>(BestActor);
65 if(PatrolPoint != nullptr)
66 {
67 bool bIsBridgeAvailable = false;
68 AActor* NextPatrolPointActor = PatrolPoint->GetNextPatrolPointActor(bIsBridgeAvailable);
69
70 OwnerComp.GetBlackboardComponent()->SetValueAsObject(NextPatrolPoint.SelectedKeyName, NextPatrolPointActor);
71 OwnerComp.GetBlackboardComponent()->SetValueAsBool(bBridgeAvailable.SelectedKeyName, bIsBridgeAvailable);
72
73 if(bIsBridgeAvailable)
74 {
75 AActor* NextBridgePatrolPointActor = PatrolPoint->GetNextBridgePatrolPointActor();
76 OwnerComp.GetBlackboardComponent()->SetValueAsObject(NextBridgePatrolPoint.SelectedKeyName, NextBridgePatrolPointActor);
77 }
78
79 float WaitTimeMin = 0.0f;
80 float WaitTimeMax = 0.0f;
81 bool bWaitTime = PatrolPoint->GetTimeToWait(WaitTimeMin, WaitTimeMax);
82 if(bWaitTime)
83 {
84 float WaitTimeTotal = UKismetMathLibrary::RandomFloatInRange(WaitTimeMin, WaitTimeMax);
85 OwnerComp.GetBlackboardComponent()->SetValueAsFloat(WaitTime.SelectedKeyName, WaitTimeTotal);
86 }
87 OwnerComp.GetBlackboardComponent()->SetValueAsVector(MoveTargetLocation.SelectedKeyName, BestActor->GetActorLocation());
88 }
89 }
90 return EBTNodeResult::Succeeded;
91 }
92 }
93 return EBTNodeResult::Failed;
94}
An interface class for patrol functionality.
Definition PatrolInterface.h:24
FBlackboardKeySelector NextBridgePatrolPoint
Definition BTT_FindRandomPatrolPoint.h:43
FBlackboardKeySelector MoveTargetLocation
Definition BTT_FindRandomPatrolPoint.h:37
bool bDebuggingMode
Definition BTT_FindRandomPatrolPoint.h:23
virtual EBTNodeResult::Type ExecuteTask(UBehaviorTreeComponent &OwnerComp, uint8 *NodeMemory) override
Definition BTT_FindRandomPatrolPoint.cpp:22
FBlackboardKeySelector NextPatrolPoint
Definition BTT_FindRandomPatrolPoint.h:41
FColor TargetPatrolPointColor
Definition BTT_FindRandomPatrolPoint.h:31
FBlackboardKeySelector bBridgeAvailable
Definition BTT_FindRandomPatrolPoint.h:39
float Radius
Definition BTT_FindRandomPatrolPoint.h:49
FBlackboardKeySelector WaitTime
Definition BTT_FindRandomPatrolPoint.h:46
TEnumAsByte< EObjectTypeQuery > ObjectChannelToUse
Definition BTT_FindRandomPatrolPoint.h:34
FColor TraceColor
Definition BTT_FindRandomPatrolPoint.h:29

◆ GetStaticDescription()

FString UBTT_FindRandomPatrolPoint::GetStaticDescription ( ) const
overrideprotectedvirtual
97{
98 FString Description;
100 {
101 Description += FString::Printf(TEXT("\n DEBUG ACTIVE"));
102 }
103 if(!MoveTargetLocation.SelectedKeyName.IsValid())
104 {
105 Description += FString::Printf(TEXT("\nMove Target Location: NOT SET"));
106 }
107 if(!bBridgeAvailable.SelectedKeyName.IsValid())
108 {
109 Description += FString::Printf(TEXT("\n Bridge Available: NOT SET"));
110 }
111 if(!NextPatrolPoint.SelectedKeyName.IsValid())
112 {
113 Description += FString::Printf(TEXT("\n Next Patrol Point: NOT SET"));
114 }
115 if(!NextBridgePatrolPoint.SelectedKeyName.IsValid())
116 {
117 Description += FString::Printf(TEXT("\n Next Bridge Patrol Point: NOT SET"));
118 }
119 if(!WaitTime.SelectedKeyName.IsValid())
120 {
121 Description += FString::Printf(TEXT("\n Wait Time: NOT SET"));
122 }
123 // Description += FString::Printf(TEXT("\nDegrees: %i"), ObjectChannelToUse.GetValue());
124 Description += FString::Printf(TEXT("\nRadius: %i"), FMath::RoundToInt(Radius));
125 return Description;
126}

Member Data Documentation

◆ bBridgeAvailable

FBlackboardKeySelector UBTT_FindRandomPatrolPoint::bBridgeAvailable

◆ bDebuggingMode

bool UBTT_FindRandomPatrolPoint::bDebuggingMode = false

◆ bShowText

bool UBTT_FindRandomPatrolPoint::bShowText = true

◆ MoveTargetLocation

FBlackboardKeySelector UBTT_FindRandomPatrolPoint::MoveTargetLocation

◆ NextBridgePatrolPoint

FBlackboardKeySelector UBTT_FindRandomPatrolPoint::NextBridgePatrolPoint

◆ NextPatrolPoint

FBlackboardKeySelector UBTT_FindRandomPatrolPoint::NextPatrolPoint

◆ ObjectChannelToUse

TEnumAsByte<EObjectTypeQuery> UBTT_FindRandomPatrolPoint::ObjectChannelToUse = ObjectTypeQuery1

◆ PointSize

float UBTT_FindRandomPatrolPoint::PointSize = 20.0f

◆ Radius

float UBTT_FindRandomPatrolPoint::Radius = 2000.0f

◆ TargetPatrolPointColor

FColor UBTT_FindRandomPatrolPoint::TargetPatrolPointColor = FColor::Red

◆ TraceColor

FColor UBTT_FindRandomPatrolPoint::TraceColor = FColor::Green

◆ WaitTime

FBlackboardKeySelector UBTT_FindRandomPatrolPoint::WaitTime

The documentation for this class was generated from the following files: