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

#include <AISense_Actions.h>

Inheritance diagram for UAISense_Actions:

Classes

struct  FDigestedActionProperties
 

Public Member Functions

const FDigestedActionPropertiesGetActionConfigByListenerID (const FPerceptionListenerID &TargetID)
 
 UAISense_Actions (const FObjectInitializer &ObjectInitializer)
 
void RegisterEvent (const FAIActionEvent &Event)
 

Static Public Member Functions

static void ReportActionEvent (UObject *WorldContextObject, AActor *Broadcaster, AActor *OtherActor, const FVector &TargetLocation, const EAIActionType ActionType, const float EventRangeMultiplier=1.0f, const float PassedInfoAge=0.f, const float InStrength=1.f)
 

Public Attributes

TArray< FDigestedActionPropertiesDigestedProperties
 
TArray< FAIActionEventRegisteredEvents
 

Protected Member Functions

virtual float Update () override
 
void OnNewListenerImpl (const FPerceptionListener &NewListener)
 
void OnListenerRemovedImpl (const FPerceptionListener &UpdatedListener)
 

Protected Attributes

FGenericTeamId TeamIdentifier
 

Constructor & Destructor Documentation

◆ UAISense_Actions()

UAISense_Actions::UAISense_Actions ( const FObjectInitializer & ObjectInitializer)
23 : Super(ObjectInitializer)
24{
25 //Bind the required functions
26 OnNewListenerDelegate.BindUObject(this, &UAISense_Actions::OnNewListenerImpl);
27 OnListenerRemovedDelegate.BindUObject(this, &UAISense_Actions::OnListenerRemovedImpl);
28}
void OnNewListenerImpl(const FPerceptionListener &NewListener)
Definition AISense_Actions.cpp:152
void OnListenerRemovedImpl(const FPerceptionListener &UpdatedListener)
Definition AISense_Actions.cpp:166

Member Function Documentation

◆ GetActionConfigByListenerID()

const UAISense_Actions::FDigestedActionProperties * UAISense_Actions::GetActionConfigByListenerID ( const FPerceptionListenerID & TargetID)
45{
46 for (const FDigestedActionProperties& Action : DigestedProperties)
47 {
48 if (Action.ListenerID == TargetID)
49 {
50 return &Action;
51 }
52 }
53 return nullptr; // Return nullptr if not found
54}
TArray< FDigestedActionProperties > DigestedProperties
Definition AISense_Actions.h:92

◆ OnListenerRemovedImpl()

void UAISense_Actions::OnListenerRemovedImpl ( const FPerceptionListener & UpdatedListener)
protected
167{
168 //In our case, executes when we stop playing
169 // GLog->Log("on listener removed!");
170 check(UpdatedListener.Listener.IsValid());
171 DigestedProperties.RemoveAll([&](const FDigestedActionProperties& Action) {
172 return Action.ListenerID == UpdatedListener.GetListenerID();});
173 RequestImmediateUpdate();
174}

◆ OnNewListenerImpl()

void UAISense_Actions::OnNewListenerImpl ( const FPerceptionListener & NewListener)
protected
153{
154 //Since we have at least one AI actor with this sense this function will fire when the game starts
155 check(NewListener.Listener.IsValid());
156 //Get the config
157 UAISenseConfig* Config = NewListener.Listener->GetSenseConfig(GetSenseID());
158 const UAISenseConfig_Actions* SenseConfig = Cast<const UAISenseConfig_Actions>(Config);
159 check(SenseConfig);
160 //Consume properties from the sense config
161 const FDigestedActionProperties PropertyDigest(*SenseConfig, NewListener.GetListenerID());
162 DigestedProperties.Add(PropertyDigest);
163 RequestImmediateUpdate();
164}
Definition AISenseConfig_Actions.h:17

◆ RegisterEvent()

void UAISense_Actions::RegisterEvent ( const FAIActionEvent & Event)
194{
195 RegisteredEvents.Add(Event);
196 RequestImmediateUpdate();
197}
TArray< FAIActionEvent > RegisteredEvents
Definition AISense_Actions.h:105

◆ ReportActionEvent()

void UAISense_Actions::ReportActionEvent ( UObject * WorldContextObject,
AActor * Broadcaster,
AActor * OtherActor,
const FVector & TargetLocation,
const EAIActionType ActionType,
const float EventRangeMultiplier = 1.0f,
const float PassedInfoAge = 0.f,
const float InStrength = 1.f )
static
33{
34 if(WorldContextObject == nullptr){return;}
35 UAIPerceptionSystem* PerceptionSystem = UAIPerceptionSystem::GetCurrent(WorldContextObject);
36 if(PerceptionSystem != nullptr)
37 {
38 const FAIActionEvent Event(Broadcaster, OtherActor, TargetLocation, ActionType, EventRangeMultiplier, PassedInfoAge, InStrength);
39 PerceptionSystem->OnEvent(Event);
40 }
41}
Definition AISense_Actions.h:20

◆ Update()

float UAISense_Actions::Update ( )
overrideprotectedvirtual
58{
59 AIPerception::FListenerMap& ListenersMap = *GetListeners();
60
61 //For each listener who has this sense we're going to perform a sweep to determine nearby aqua actors
62 for (AIPerception::FListenerMap::TIterator ListenerIt(ListenersMap); ListenerIt; ++ListenerIt)
63 {
64 //Get the listener
65 FPerceptionListener& Listener = ListenerIt->Value;
66
67 //- Team
68 // skip listeners not interested in this sense
69 if(Listener.HasSense(GetSenseID()) == false){continue;}
70 if(GetActionConfigByListenerID(Listener.GetListenerID()) == nullptr){continue;}
71 // const FDigestedActionProperties& ListenersConfig = DigestedProperties[Listener.GetListenerID()];
72 const FDigestedActionProperties& ListenersConfig = *GetActionConfigByListenerID(Listener.GetListenerID());
73 for(const FAIActionEvent& Event : RegisteredEvents)
74 {
75 const FVector::FReal DistToActionSquared = FVector::DistSquared(Event.GetBroadcastLocation(), Listener.CachedLocation);
76 //- Don't want Negative Multiplier //
77 const float ClampedMultiplier = FMath::Max(0.1f, Event.RangeMultiplier);
78 const bool bOutOfListeningRange = (DistToActionSquared > (FMath::Square(ListenersConfig.ActionRadius) * ClampedMultiplier));
79
80 if(FAISenseAffiliationFilter::ShouldSenseTeam(Listener.TeamIdentifier, Event.TeamIdentifier, ListenersConfig.AffiliationFlags) == false)
81 {
82 continue;
83 }
84 if(bOutOfListeningRange)
85 {
86 continue;
87 }
88 // // @todo implement some kind of TeamIdentifierType that would supply comparison operator
89 // if(Listener.TeamIdentifier != Event.TeamIdentifier)
90 // {
91 // continue;
92 // }
93 if(Listener.GetBodyActor()->GetInstigatorController() == Event.Broadcaster)
94 {
95 continue;
96 }
97 Listener.RegisterStimulus(Event.OtherActor, FAIStimulus(*this, Event.Strength, Event.Location, Event.GetBroadcastLocation(), FAIStimulus::SensingSucceeded, UAIBPLib::GetActionTagFromType(Event.Action)).SetStimulusAge(Event.InformationAge));
98
99 // if(Listener.TeamIdentifier != Event.TeamIdentifier
100 // || FVector::DistSquared(Event.GetBroadcastLocation(), Listener.CachedLocation) > Event.RangeSq)
101 // {
102 // continue;
103 // }
104 // Listener.RegisterStimulus(Event.OtherActor, FAIStimulus(*this, Event.Strength, Event.Location, Event.GetBroadcastLocation(), FAIStimulus::SensingSucceeded, UAIBPLib::GetActionTagFromType(Event.Action)).SetStimulusAge(Event.InformationAge));
105 }
106
107
108
109 // const AActor* ListenerBodyActor = Listener.GetBodyActor();
110 //
111 // for (int32 DigestedPropertyIndex = 0; DigestedPropertyIndex < DigestedProperties.Num(); DigestedPropertyIndex++)
112 // {
113 // //Create the sphere for this sense and perform the sweep to determine nearby actors
114 // FCollisionShape CollisionSphere = FCollisionShape::MakeSphere(DigestedProperties[DigestedPropertyIndex].ActionRadius);
115 // TArray<FHitResult> HitResults;
116 // GetWorld()->SweepMultiByChannel(HitResults, ListenerBodyActor->GetActorLocation(), ListenerBodyActor->GetActorLocation() + FVector::UpVector*CollisionSphere.GetSphereRadius(), FQuat(), ECollisionChannel::ECC_WorldDynamic, CollisionSphere);
117 //
118 // //Draw debug sphere if we have activated it via the config
119 // if(DigestedProperties[DigestedPropertyIndex].bDisplayDebugSphere)
120 // {
121 // DrawDebugSphere(GetWorld(), ListenerBodyActor->GetActorLocation(), DigestedProperties[DigestedPropertyIndex].ActionRadius, 8, FColor::Blue, false, 3.0f, 1, 1.f);
122 // }
123 //
124 // if(HitResults.IsEmpty()){return 0.0f;}
125 // //Check hit results for aqua actors
126 // for (int32 i = 0; i < HitResults.Num(); i++)
127 // {
128 // FHitResult hit = HitResults[i];
129 // //To simplify things, we're going to assume that "water resources" for this post are actors that have the following game tag
130 // if (hit.GetActor()->ActorHasTag(FName("AquaActor")))
131 // {
132 // if ((hit.GetActor()->GetActorLocation() - ListenerBodyActor->GetActorLocation()).Size() <= DigestedProperties[DigestedPropertyIndex].ActionRadius)
133 // {
134 // Elem.Value.RegisterStimulus(hit.GetActor(), FAIStimulus(*this, 5.f, hit.GetActor()->GetActorLocation(), ListenerBodyActor->GetActorLocation()));
135 // // GLog->Log("registered stimulus!");
136 // }
137 //
138 // }
139 //
140 // }
141 // }
142
143
144 }
145 RegisteredEvents.Reset();
146 return SuspendNextUpdate;
147
148 // //Time until next update; in this case we're forcing the update to happen in each frame
149 // return 0.f;
150}
static FName GetActionTagFromType(const EAIActionType ActionType)
Definition AIBPLib.cpp:216
const FDigestedActionProperties * GetActionConfigByListenerID(const FPerceptionListenerID &TargetID)
Definition AISense_Actions.cpp:43

Member Data Documentation

◆ DigestedProperties

TArray<FDigestedActionProperties> UAISense_Actions::DigestedProperties

◆ RegisteredEvents

TArray<FAIActionEvent> UAISense_Actions::RegisteredEvents

◆ TeamIdentifier

FGenericTeamId UAISense_Actions::TeamIdentifier
protected

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