Space Plunder
Loading...
Searching...
No Matches
AISense_Actions.h
Go to the documentation of this file.
1// Fill out your copyright notice in the Description page of Project Settings.
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "Data/BaseData.h"
7#include "Perception/AISense.h"
8#include "AISense_Actions.generated.h"
9
10
16class UAISenseConfig_Actions; //forward declaration to avoid circular dependencies
17
18USTRUCT()
19struct AITOOLKIT_API FAIActionEvent
20{
21 GENERATED_USTRUCT_BODY()
22
24
25 FVector Location;
26 FGenericTeamId TeamIdentifier;
27 // float RangeSq;
28 float RangeMultiplier = 1.0f;
29
30 float InformationAge = 0.0f;
31 float Strength = 1.0f;
32
33 UPROPERTY()
34 TObjectPtr<AActor> Broadcaster;
35 UPROPERTY()
36 TObjectPtr<AActor> OtherActor;
37 FName ActionName;
38
40
41
42 FAIActionEvent() : Broadcaster(nullptr), OtherActor(nullptr), Action(EAIActionType::Default) {}
43 FAIActionEvent(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);
44
45
46 FORCEINLINE void CacheBroadcastLocation()
47 {
48 BroadcastLocation = Broadcaster ? Broadcaster->GetActorLocation() : FAISystem::InvalidLocation;
49 }
50 FORCEINLINE const FVector& GetBroadcastLocation() const
51 {
52 return BroadcastLocation;
53 }
54
55private:
57
58 // IAIPerceptionListenerInterface* GetTouchedActorAsPerceptionListener() const;
59};
60
61
62
63UCLASS(meta = (DisplayName = "AI Sense Actions"))
64class AITOOLKIT_API UAISense_Actions : public UAISense
65{
66 GENERATED_BODY()
67
68public:
69
70 /*
71 * After inspecting the engine's code it seems like there's a pattern to use a struct
72 * to consume the properties from the config class so it's better to follow the engine's
73 * standards and workflows.
74 */
76 {
78 // bool bDisplayDebugSphere;
80 FPerceptionListenerID ListenerID;
81
83 FDigestedActionProperties(const UAISenseConfig_Actions& SenseConfig, const FPerceptionListenerID& ID);
84
85 // bool operator==(const FDigestedActionProperties& Other) const
86 // {
87 // return Other.ListenerID == ListenerID;
88 // }
89 };
90
91 /* Consumed properties from config */
92 TArray<FDigestedActionProperties> DigestedProperties;
93 const FDigestedActionProperties* GetActionConfigByListenerID(const FPerceptionListenerID& TargetID);
94
95 UAISense_Actions(const FObjectInitializer& ObjectInitializer);
96
97 UFUNCTION(BlueprintCallable, Category = "AI|Perception", meta = (WorldContext = "WorldContextObject"))
98 static void ReportActionEvent(UObject* WorldContextObject, AActor* Broadcaster, AActor* OtherActor,
99 const FVector& TargetLocation, const EAIActionType ActionType,
100 const float EventRangeMultiplier = 1.0f, const float PassedInfoAge = 0.f, const float InStrength = 1.f);
101
102
103
104 UPROPERTY()
105 TArray<FAIActionEvent> RegisteredEvents;
106
107 void RegisterEvent(const FAIActionEvent& Event);
108
109
110protected:
111 /* Core logic for the sense */
112 virtual float Update() override;
113
114 /* A listener is someone who has a Perception component with various senses
115 * This function will be called when a new listener gained this sense
116 */
117 void OnNewListenerImpl(const FPerceptionListener& NewListener);
118
119 /*
120 * Called whenever the listener is removed (eg destroyed or game has stopped)
121 */
122 void OnListenerRemovedImpl(const FPerceptionListener& UpdatedListener);
123
124 FGenericTeamId TeamIdentifier;
125
126};
EAIActionType
Definition BaseData.h:219
UCLASS(Blueprintable, BlueprintType, ClassGroup=(BucciGames), meta=(BlueprintSpawnableComponent)) class CHATSYSTEM_API UChatSystemComponent
Definition ChatSystemComponent.h:13
Definition AISense_Actions.h:65
TArray< FDigestedActionProperties > DigestedProperties
Definition AISense_Actions.h:92
Definition AISenseConfig_Actions.h:17
Definition AISense_Actions.h:20
FORCEINLINE void CacheBroadcastLocation()
Definition AISense_Actions.h:46
FVector BroadcastLocation
Definition AISense_Actions.h:56
FORCEINLINE const FVector & GetBroadcastLocation() const
Definition AISense_Actions.h:50
Definition AISense_Actions.h:76
float ActionRadius
Definition AISense_Actions.h:77
FPerceptionListenerID ListenerID
Definition AISense_Actions.h:80
uint8 AffiliationFlags
Definition AISense_Actions.h:79