26{
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
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
47 PatrolMemory->TargetPatrolPoint = Cast<IPatrolInterface>(PatrolMemory->TargetPatrolPointActor);
48 if(PatrolMemory->TargetPatrolPoint != nullptr)
49 {
50 if(OwnerComp.GetAIOwner() != nullptr)
51 {
52
53 const UNavigationSystemV1* NavSystem = UNavigationSystemV1::GetNavigationSystem(OwnerComp.GetAIOwner());
54 if(NavSystem != nullptr)
55 {
56 PatrolMemory->RandomPoint = FNavLocation(PatrolMemory->TargetPatrolPointActor->GetActorLocation());
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 {
68 break;
69 }
70 }
71 BlackboardComp->SetValueAsVector(
MoveTargetLocation.SelectedKeyName, PatrolMemory->RandomPoint);
73 {
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
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
95 PatrolMemory->bPatrolBackwards = BlackboardComp->GetValueAsBool(
bPatrolBackwards.SelectedKeyName);
96
97
98 if(PatrolMemory->TargetPatrolPoint->GetIsDeadEnd())
99 {
101 BlackboardComp->SetValueAsBool(
bPatrolBackwards.SelectedKeyName, !PatrolMemory->bPatrolBackwards);
102 PatrolMemory->bPatrolBackwards = !PatrolMemory->bPatrolBackwards;
103 }
104
105
106
107 AActor* NextPoint;
108
109 if(PatrolMemory->bPatrolBackwards)
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
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
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
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