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

#include <BTTask_GetNextPatrolPoint.h>

Inheritance diagram for UBTTask_GetNextPatrolPoint:

Classes

struct  FBTTaskPatrolMemory
 

Public Member Functions

 UBTTask_GetNextPatrolPoint ()
 

Public Attributes

bool bMoveToBridge = false
 
int32 GetPointAttempts = 4
 
bool bOverrideRadius = false
 
float Radius = 10.0f
 
FBlackboardKeySelector NextPatrolPoint
 
FBlackboardKeySelector NextBridgePatrolPoint
 
FBlackboardKeySelector MoveTargetLocation
 
FBlackboardKeySelector WaitTime
 
FBlackboardKeySelector bBridgeAvailable
 
FBlackboardKeySelector bPatrolBackwards
 
bool bDebuggingMode = false
 
bool bShowText = true
 
float DebugPointSize = 20.0f
 
float DebugPointDuration = 10.0f
 
FColor TargetLocationColor = FColor::Yellow
 
FColor PatrolPointColor = FColor::Red
 

Protected Member Functions

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

Detailed Description

Class for a behavior tree task node that retrieves the next patrol point for an AI character.

Constructor & Destructor Documentation

◆ UBTTask_GetNextPatrolPoint()

UBTTask_GetNextPatrolPoint::UBTTask_GetNextPatrolPoint ( )
17{
18 NodeName = TEXT("Get Next Patrol Point");
19#if WITH_EDITOR
20 bDebuggingMode = true;
21#endif // WITH_EDITOR
22
23}
bool bDebuggingMode
Definition BTTask_GetNextPatrolPoint.h:52

Member Function Documentation

◆ ExecuteTask()

EBTNodeResult::Type UBTTask_GetNextPatrolPoint::ExecuteTask ( UBehaviorTreeComponent & OwnerComp,
uint8 * NodeMemory )
overrideprotectedvirtual
26{
27 TRACE_CPUPROFILER_EVENT_SCOPE(UBTTask_GetNextPatrolPoint::ExecuteTask);
28 SCOPE_CYCLE_COUNTER(STATGROUP_AIToolKit_Behaviors);
29 SCOPE_CYCLE_COUNTER(STATGROUP_AIToolKit_Tasks);
30 FBTTaskPatrolMemory* PatrolMemory = reinterpret_cast<FBTTaskPatrolMemory*>(NodeMemory);
31 if(PatrolMemory == nullptr){return EBTNodeResult::Failed;}
32 UBlackboardComponent* BlackboardComp = OwnerComp.GetBlackboardComponent();
33 if(BlackboardComp != nullptr)
34 {
35 //- Get next Patrol point (Bridge or next in sequence //
37 {
38 PatrolMemory->TargetPatrolPointActor = Cast<AActor>(BlackboardComp->GetValueAsObject(NextBridgePatrolPoint.SelectedKeyName));
39 }
40 else
41 {
42 PatrolMemory->TargetPatrolPointActor = Cast<AActor>(BlackboardComp->GetValueAsObject(NextPatrolPoint.SelectedKeyName));
43 }
44 if(PatrolMemory->TargetPatrolPointActor != nullptr)
45 {
46 //- Get Patrol point Interface //
47 PatrolMemory->TargetPatrolPoint = Cast<IPatrolInterface>(PatrolMemory->TargetPatrolPointActor);
48 if(PatrolMemory->TargetPatrolPoint != nullptr)
49 {
50 if(OwnerComp.GetAIOwner() != nullptr)
51 {
52 //- Set Move Location Around Patrol Point //
53 const UNavigationSystemV1* NavSystem = UNavigationSystemV1::GetNavigationSystem(OwnerComp.GetAIOwner());
54 if(NavSystem != nullptr)
55 {
56 PatrolMemory->RandomPoint = FNavLocation(PatrolMemory->TargetPatrolPointActor->GetActorLocation());
57 for(int32 i = 0; i < GetPointAttempts; i++)
58 {
59 PatrolMemory->Radius = PatrolMemory->TargetPatrolPoint->GetRadius() + Radius;
61 {
62 PatrolMemory->Radius = Radius;
63 }
64 const bool bFoundPoint = NavSystem->GetRandomReachablePointInRadius(PatrolMemory->TargetPatrolPointActor->GetActorLocation(), PatrolMemory->Radius, PatrolMemory->RandomPoint);
65 if(bFoundPoint)
66 {
67 if(bDebuggingMode){UE_LOG(LogAIToolKit, Warning, TEXT("Point found"));}
68 break;
69 }
70 }
71 BlackboardComp->SetValueAsVector(MoveTargetLocation.SelectedKeyName, PatrolMemory->RandomPoint);
72 if(bDebuggingMode && GetWorld() != nullptr)
73 {
74 DrawDebugPoint(GetWorld(), PatrolMemory->TargetPatrolPointActor->GetActorLocation(), DebugPointSize, PatrolPointColor, false, DebugPointDuration);
75 DrawDebugPoint(GetWorld(), PatrolMemory->RandomPoint, DebugPointSize, TargetLocationColor, false, DebugPointDuration);
76 if(bShowText)
77 {
78 const FString ActorName = OwnerComp.GetAIOwner()->GetPawn()->GetName();
79 const FString PrintMessage = (ActorName + " Target Patrol Point");
80 DrawDebugString(GetWorld(), PatrolMemory->RandomPoint, PrintMessage, nullptr, FColor::White, DebugPointDuration);
81 }
82 }
83 }
84 }
85 //- Set Wait time //
86 const bool bWaitRandom = PatrolMemory->TargetPatrolPoint->GetTimeToWait(PatrolMemory->TimeToWaitMin, PatrolMemory->TimeToWaitMax);
87 PatrolMemory->WaitTime = PatrolMemory->TimeToWaitMin;
88 if(bWaitRandom)
89 {
90 PatrolMemory->WaitTime = FMath::RandRange(PatrolMemory->TimeToWaitMin, PatrolMemory->TimeToWaitMax);
91 }
92 BlackboardComp->SetValueAsFloat(WaitTime.SelectedKeyName, PatrolMemory->WaitTime);
93
94 //- Set Patrol Direction At next point //
95 PatrolMemory->bPatrolBackwards = BlackboardComp->GetValueAsBool(bPatrolBackwards.SelectedKeyName);
96
97 //- If dead end change direction //
98 if(PatrolMemory->TargetPatrolPoint->GetIsDeadEnd())
99 {
100 if(bDebuggingMode){UE_LOG(LogAIToolKit, Warning, TEXT("Dead End"));}
101 BlackboardComp->SetValueAsBool(bPatrolBackwards.SelectedKeyName, !PatrolMemory->bPatrolBackwards);
102 PatrolMemory->bPatrolBackwards = !PatrolMemory->bPatrolBackwards;
103 }
104
105
106 //- Patrol Direction, if moving forward, get next point and bridge if available //
107 AActor* NextPoint;
108
109 if(PatrolMemory->bPatrolBackwards)// || PatrolMemory->NextPatrolPointActor == nullptr)
110 {
111 PatrolMemory->NextPatrolPointActor = PatrolMemory->TargetPatrolPoint->GetNextPatrolPointActor(PatrolMemory->bIsBridgeAvailable);
112 PatrolMemory->PreviousPatrolPointActor = PatrolMemory->TargetPatrolPoint->GetPreviousPatrolPointActor(PatrolMemory->bIsBridgeAvailable);
113 PatrolMemory->NextBridgePatrolPointActor = PatrolMemory->TargetPatrolPoint->GetNextBridgePatrolPointActor();
114 NextPoint = PatrolMemory->PreviousPatrolPointActor;
115 // BlackboardComp->SetValueAsObject(NextPatrolPoint.SelectedKeyName, PatrolMemory->PreviousPatrolPointActor);
116 }
117 else
118 {
119 PatrolMemory->PreviousPatrolPointActor = PatrolMemory->TargetPatrolPoint->GetPreviousPatrolPointActor(PatrolMemory->bIsBridgeAvailable);
120 PatrolMemory->NextPatrolPointActor = PatrolMemory->TargetPatrolPoint->GetNextPatrolPointActor(PatrolMemory->bIsBridgeAvailable);
121 PatrolMemory->NextBridgePatrolPointActor = PatrolMemory->TargetPatrolPoint->GetNextBridgePatrolPointActor();
122 NextPoint = PatrolMemory->NextPatrolPointActor;
123 // BlackboardComp->SetValueAsObject(NextPatrolPoint.SelectedKeyName, PatrolMemory->NextPatrolPointActor);
124 }
125 if(PatrolMemory->PreviousPatrolPointActor == nullptr)
126 {
127 NextPoint = PatrolMemory->NextPatrolPointActor;
128 }
129 if(PatrolMemory->NextPatrolPointActor == nullptr)
130 {
131 NextPoint = PatrolMemory->PreviousPatrolPointActor;
132 }
133 BlackboardComp->SetValueAsObject(NextPatrolPoint.SelectedKeyName, NextPoint);
134
135
136 //- Set Is Bridge Available, and next bridge point //
137 BlackboardComp->SetValueAsBool(bBridgeAvailable.SelectedKeyName, PatrolMemory->bIsBridgeAvailable);
138 BlackboardComp->SetValueAsObject(NextBridgePatrolPoint.SelectedKeyName, PatrolMemory->NextBridgePatrolPointActor);
139
140 }
141 }
142 }
143 return EBTNodeResult::Succeeded;
144}
FBlackboardKeySelector bBridgeAvailable
Definition BTTask_GetNextPatrolPoint.h:46
FColor PatrolPointColor
Definition BTTask_GetNextPatrolPoint.h:62
bool bOverrideRadius
Definition BTTask_GetNextPatrolPoint.h:27
float DebugPointDuration
Definition BTTask_GetNextPatrolPoint.h:58
FBlackboardKeySelector MoveTargetLocation
Definition BTTask_GetNextPatrolPoint.h:42
FBlackboardKeySelector bPatrolBackwards
Definition BTTask_GetNextPatrolPoint.h:48
bool bMoveToBridge
Definition BTTask_GetNextPatrolPoint.h:22
int32 GetPointAttempts
Definition BTTask_GetNextPatrolPoint.h:24
FColor TargetLocationColor
Definition BTTask_GetNextPatrolPoint.h:60
FBlackboardKeySelector NextBridgePatrolPoint
Definition BTTask_GetNextPatrolPoint.h:37
bool bShowText
Definition BTTask_GetNextPatrolPoint.h:54
FBlackboardKeySelector NextPatrolPoint
Definition BTTask_GetNextPatrolPoint.h:35
virtual EBTNodeResult::Type ExecuteTask(UBehaviorTreeComponent &OwnerComp, uint8 *NodeMemory) override
Definition BTTask_GetNextPatrolPoint.cpp:25
float Radius
Definition BTTask_GetNextPatrolPoint.h:30
float DebugPointSize
Definition BTTask_GetNextPatrolPoint.h:56
FBlackboardKeySelector WaitTime
Definition BTTask_GetNextPatrolPoint.h:44

◆ GetInstanceMemorySize()

uint16 UBTTask_GetNextPatrolPoint::GetInstanceMemorySize ( ) const
overrideprotectedvirtual
186{
187 return sizeof(FBTTaskPatrolMemory);
188}

◆ GetStaticDescription()

FString UBTTask_GetNextPatrolPoint::GetStaticDescription ( ) const
overrideprotectedvirtual
147{
148 FString Description;
150 {
151 Description += FString::Printf(TEXT("\n DEBUG ACTIVE"));
152 }
153 Description += FString::Printf(TEXT("\n Move To Bridge: %s"), bMoveToBridge ? TEXT("True") : TEXT("False"));
154 Description += FString::Printf(TEXT("\n Radius: %s"), bOverrideRadius ? *FString::Printf(TEXT("\n OVERRIDEN %f"), Radius) : *FString::Printf(TEXT("\n %i"), FMath::RoundToInt(Radius)));
155 Description += FString::Printf(TEXT("\n Attempts: %i"), GetPointAttempts);
156
157 if(!MoveTargetLocation.SelectedKeyName.IsValid())
158 {
159 Description += FString::Printf(TEXT("\nMoveTargetLocation: NULL"));
160 }
161 if(!WaitTime.SelectedKeyName.IsValid())
162 {
163 Description += FString::Printf(TEXT("\n Wait Time: NULL"));
164 }
165 if(!bBridgeAvailable.SelectedKeyName.IsValid())
166 {
167 Description += FString::Printf(TEXT("\n Bridge Available: NULL"));
168 }
169 if(!bPatrolBackwards.SelectedKeyName.IsValid())
170 {
171 Description += FString::Printf(TEXT("\n Patrol Backward: NULL"));
172 }
173
174 return Description;
175}

Member Data Documentation

◆ bBridgeAvailable

FBlackboardKeySelector UBTTask_GetNextPatrolPoint::bBridgeAvailable

◆ bDebuggingMode

bool UBTTask_GetNextPatrolPoint::bDebuggingMode = false

◆ bMoveToBridge

bool UBTTask_GetNextPatrolPoint::bMoveToBridge = false

◆ bOverrideRadius

bool UBTTask_GetNextPatrolPoint::bOverrideRadius = false

◆ bPatrolBackwards

FBlackboardKeySelector UBTTask_GetNextPatrolPoint::bPatrolBackwards

◆ bShowText

bool UBTTask_GetNextPatrolPoint::bShowText = true

◆ DebugPointDuration

float UBTTask_GetNextPatrolPoint::DebugPointDuration = 10.0f

◆ DebugPointSize

float UBTTask_GetNextPatrolPoint::DebugPointSize = 20.0f

◆ GetPointAttempts

int32 UBTTask_GetNextPatrolPoint::GetPointAttempts = 4

◆ MoveTargetLocation

FBlackboardKeySelector UBTTask_GetNextPatrolPoint::MoveTargetLocation

◆ NextBridgePatrolPoint

FBlackboardKeySelector UBTTask_GetNextPatrolPoint::NextBridgePatrolPoint

◆ NextPatrolPoint

FBlackboardKeySelector UBTTask_GetNextPatrolPoint::NextPatrolPoint

◆ PatrolPointColor

FColor UBTTask_GetNextPatrolPoint::PatrolPointColor = FColor::Red

◆ Radius

float UBTTask_GetNextPatrolPoint::Radius = 10.0f

◆ TargetLocationColor

FColor UBTTask_GetNextPatrolPoint::TargetLocationColor = FColor::Yellow

◆ WaitTime

FBlackboardKeySelector UBTTask_GetNextPatrolPoint::WaitTime

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