LEAP Documentation 40220
Documentation for the LEAP project
ProjectXAIPerception.h
Go to the documentation of this file.
1// Copyright 2017 Blue Isle Studios, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "Components/ActorComponent.h"
6#include "ProjectXAIPerception.generated.h"
7
8class APlayerState;
10
11#define ECC_AISight ECC_GameTraceChannel4
12
13UENUM(BlueprintType)
14enum class EStimulusType : uint8
15{
16 None = 0,
17 Sight = 1,
18 Hearing = 2,
19 Damage = 3
20};
21
22USTRUCT(BlueprintType, meta = (DisplayName = "Stimulus Data"))
24{
25 GENERATED_USTRUCT_BODY()
26
27 UPROPERTY(BlueprintReadWrite, Category = "AI|Perception")
28 float Strength;
29
30 UPROPERTY(BlueprintReadWrite, Category = "AI|Perception")
31 EStimulusType StimulusType;
32};
33
34USTRUCT(BlueprintType, meta = (DisplayName = "Sensed Actor's Data"))
36{
37 GENERATED_USTRUCT_BODY()
38
39 UPROPERTY(BlueprintReadWrite, Category = "AI|Perception")
40 AActor* Target;
41
42 UPROPERTY(BlueprintReadWrite, Category = "AI|Perception")
43 TArray<FPerceptionStimulus> LastSensedStimuli;
44
45 FProjectXPerceptionInfo() : Target(nullptr)
46 {}
47
48 bool operator==(const FProjectXPerceptionInfo& rhs) const
49 {
50 return Target && Target == rhs.Target;
51 }
52};
53
54DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FPerceptionUpdateSignature, TArray<FProjectXPerceptionInfo>, UpdatedActors);
55
56UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
57class PROJECTX_API UProjectXAIPerception : public UActorComponent
58{
59 GENERATED_BODY()
60
61public:
62 UProjectXAIPerception();
63
64 bool PassesConeCheck(const FVector ActorLocation, const FVector StartLocation, const FVector LookDirection) const;
65 UFUNCTION()
66 void ReportDamageEvent(class AActor* Victim, const float Damage, struct FDamageEvent const& DamageEvent, const class AController* EventInstigator, const class AActor* DamageCauser, const class APlayerState* InstigatorPlayerState);
67 UFUNCTION()
68 void OnPawnPosessed(APawn* InPawn);
69protected:
70 virtual void BeginPlay() override;
71
72 TArray<FProjectXPerceptionInfo> PercievedActors;
73 AProjectXAIController* AIController;
74 float PeripheralVisionAngleCos;
75 float SquareVisionRange;
76
77public:
78 virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
79
80 /* How far can the creature see? Setting this and hearing range to zero will effectively turn off perception (aside from damage) */
81 UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "Perception")
82 float VisionRange = 2000.0f;
83 /* Added weight to the perception if the target is armored */
84 UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "Perception")
85 float ArmorMaxStrength = 0.0f;
86 /* Added weight to the perception if the target is damaged */
87 UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "Perception")
88 float TargetDamagedMaxStrength = 0.0f;
89 /* Weight of the perception, this is accounted into threat for creature combat */
90 UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "Perception")
91 float SightMaxStrength = 2.0f;
92 /* Weight of the perception, this is accounted into threat for creature combat */
93 UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "Perception")
94 float SightMaxStrengthAlly = 2.0f;
95 /* Half the degrees of the desired cone check*/
96 UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "Perception")
97 float PeripheralVisionAngleDegrees = 90.0f;
98 /* How many vision traces are allowed per check. Increasing this will affect performance */
99 UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "Perception")
100 int32 MaxVisionTargets = 3;
101
102 /* How far can the creature hear? */
103 UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "Perception")
104 float HearingRange = 700.0f;
105 /* Weight of the perception, this is accounted into threat for creature combat */
106 UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "Perception")
107 float HearingMaxStrength = 3.0f;
108 /* Weight of the perception, this is accounted into threat for creature combat */
109 UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "Perception")
110 float HearingMaxStrengthAlly = 3.0f;
111 /* Weight of the perception, this is accounted into threat for creature combat */
112 UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "Perception")
113 float DamageMaxStrength = 10.0f;
114
115 UPROPERTY(BlueprintAssignable, Category = "Perception Events")
116 FPerceptionUpdateSignature OnPerceptionUpdated;
117
118private:
119 void UpdateTargetVisibilityInfo();
120};
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FPerceptionUpdateSignature, TArray< FProjectXPerceptionInfo >, UpdatedActors)
EStimulusType
Definition: ProjectXAIPerception.h:15
Definition: ProjectXAIController.h:52
FText DisplayName
Definition: ProjectXAIController.h:58
Definition: ProjectXAIPerception.h:24
Definition: ProjectXAIPerception.h:36
bool operator==(const FProjectXPerceptionInfo &rhs) const
Definition: ProjectXAIPerception.h:48
AActor * Target
Definition: ProjectXAIPerception.h:40