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

Represents a defense system pawn that can interact with other actors and participate in the generic team system. More...

#include <DefenseSystemPawn.h>

Inheritance diagram for ADefenseSystemPawn:
AInteractablePawn IDefencePawnAnim ICharacterInterface IBaseInterface ISaveLoad AAutoTurret ASecurityCameraPawn

Public Member Functions

 ADefenseSystemPawn ()
 
virtual ETeamAttitude::Type GetTeamAttitudeTowards (const AActor &Other) const override
 
virtual void SetGenericTeamId (const FGenericTeamId &NewTeamID) override
 
virtual FGenericTeamId GetGenericTeamId () const override
 
virtual FRotator GetTargetRotation () const override
 
virtual bool GetIsUpsideDown () const override
 
bool GetActive () const
 
void SetActive (const bool bValue)
 
void OnActivated (const bool bValue)
 
virtual void OnActivated_Implementation (const bool bValue)
 
- Public Member Functions inherited from AInteractablePawn
 AInteractablePawn ()
 
virtual void ReceiveStartFocus (AActor *Caller)
 
virtual void ReceiveEndFocus (AActor *Caller)
 
virtual void ReceiveOnInteract (AActor *Caller, const EInteractionType InteractionType)
 
virtual void ReceiveOnEndInteract (AActor *Caller)
 
virtual void ReceiveOnOverlap (AActor *Caller)
 
virtual void ReceiveOnEndOverlap (AActor *Caller)
 
virtual void ReceiveToggleSwitch (AActor *Caller, const bool bOn)
 
virtual void InteractionDataUpdated ()
 
virtual void SetupPlayerInputComponent (class UInputComponent *PlayerInputComponent) override
 
- Public Member Functions inherited from ICharacterInterface
virtual USkeletalMeshComponent * GetCharacterSecondaryMesh () const
 
virtual void StartThreatIndication (AActor *PawnThreat)
 
virtual void UpdateThreatIndication (const FVector &Location, const float DetectionAmount)
 
virtual void StopThreatIndication ()
 

Protected Member Functions

virtual void BeginPlay () override
 
virtual void GetActorEyesViewPoint (FVector &OutLocation, FRotator &OutRotation) const override
 
int32 GetTeamID () const
 
virtual ECharacterType GetCharacterType () const override
 
virtual EFactionType GetCharacterFaction () const override
 
virtual bool GetIsDead () const override
 
virtual void SetCharacterVehicleMode (const EVehicleMode Mode) override
 
void OnNewTargetSeen (APawn *Pawn)
 
void OnTargetSeen (APawn *Pawn)
 
void OnHostileSeen ()
 
void OnHostileSeenUpdate ()
 
void OnTargetLost ()
 
void OnLostAllTargets ()
 
void OnAlertChange (const float CurrentAlertLevel, const float MaxAlertLevel)
 
virtual bool GetIsCharacter () const override
 
virtual void PointDamageTaken (AActor *DamagedActor, float Damage, class AController *InstigatedBy, FVector HitLocation, class UPrimitiveComponent *HitComponent, FName BoneName, FVector ShotFromDirection, const class UDamageType *DamageType, AActor *DamageCauser)
 
virtual void OnDeath (AActor *OwningActor, EDeathType DeathType, AActor *DeathCauser, AController *DeathInstigator)
 
bool CanStillSeePawn (APawn *Pawn) const
 
bool IsPawnAlive (APawn *Pawn) const
 
bool GetCurrentTarget (APawn *&Pawn) const
 
TArray< APawn * > & GetTargets ()
 
float GetDistanceToPawn (const APawn *Pawn) const
 
float GetTotalDistanceScoreToAllTargets () const
 
virtual FRotator GetRotationToTarget (const FVector &StartLocation)
 
virtual void TargetSeen (APawn *Pawn)
 
virtual void NewTargetSeen (APawn *Pawn)
 
virtual void EnemySeen ()
 
virtual void LostAllTargets ()
 
virtual void RotateToTarget ()
 
- Protected Member Functions inherited from AInteractablePawn
virtual bool SaveGame () override
 
virtual bool LoadGame () override
 
FVector GetCustomInteractionLocation () const
 
void LogDebugError (const FString &Message) const
 
void LogDebugError (const FString &Message, const int32 Value) const
 
void LogDebugError (const FString &Message, const float Value) const
 
void LogDebugWarning (const FString &Message) const
 
void LogDebugWarning (const FString &Message, const int32 Value) const
 
void LogDebugWarning (const FString &Message, const float Value) const
 
void LogDebugMessage (const FString &Message, const bool bWarning=false, const bool bError=false) const
 
void LogDebugMessage (const FString &Message, const int32 Value, const bool bWarning=false, const bool bError=false) const
 
void LogDebugMessage (const FString &Message, const float Value, const bool bWarning=false, const bool bError=false) const
 
void LogDebugMessage (const FString &Message, const bool bValue, const bool bWarning, const bool bError) const
 
void LogOnScreenMessage (const int32 Key, const FString &Message, FColor Color=FColor::Green) const
 
void SetCategoryName (const FLogCategoryBase &Category)
 

Protected Attributes

FGenericTeamId TeamID
 
ECharacterType CharacterType = ECharacterType::Defence
 
EFactionType OwnerFaction = EFactionType::Alliance
 
FRotator StartRotation = FRotator::ZeroRotator
 
FRotator TargetRotation = FRotator::ZeroRotator
 
float AlertUpdateFrequency = 0.2f
 
float AlertLevelIncrease = 0.1f
 
float AlertLevelDecrease = 0.1f
 
float AlertLevelThreshold = 100.0f
 
float AlertLevel = 0.0f
 
bool bAlert = false
 
float VisibilityCheckFrequency = 2.0f
 
bool bInstantResetOnLostTarget = false
 
float LostTargetResetTime = 2.0f
 
bool bDead = false
 
bool bAutoActivate = true
 
UHealthComponentBase * HealthComponent
 
UAdvancedPawnSensingComponentPawnSensingComponent
 
- Protected Attributes inherited from AInteractablePawn
class UAudioReactionComponent * AudioReactionComponent
 
class UInteractableActorComponent * InteractableActorComponent
 
class UAIPerceptionStimuliSourceComponent * PerceptionStimuliComponent
 
bool bDebuggingMode = false
 

Private Member Functions

virtual void OnSeePawn (APawn *Pawn)
 
virtual void OnHearPawn (APawn *Pawn, const FVector &Location, float Volume)
 
void CheckVisibilityOfTargets ()
 
void IncreaseAlert ()
 
void DecreaseAlert ()
 
void CheckEnemySeen ()
 

Private Attributes

bool bActive = false
 
int32 CurrentTarget = -1
 
TArray< APawn * > Targets
 
FTimerHandle IncreaseAlertTimerHandle
 
FTimerHandle DecreaseAlertTimerHandle
 
FTimerHandle EnemySeenTimerHandle
 
FTimerHandle CheckVisibilityTimerHandle
 
FTimerHandle LostTargetTimerHandle
 

Detailed Description

Represents a defense system pawn that can interact with other actors and participate in the generic team system.

This class inherits from AInteractablePawn, IGenericTeamAgentInterface, and IDefencePawnAnim. It provides functionality for determining the team attitude towards other actors, managing the generic team ID, and getting the target rotation and upside-down status.

Constructor & Destructor Documentation

◆ ADefenseSystemPawn()

ADefenseSystemPawn::ADefenseSystemPawn ( )
14{
15 PrimaryActorTick.bCanEverTick = false;
16
17 HealthComponent = CreateDefaultSubobject<UHealthComponentBase>(TEXT("Health"));
18 HealthComponent->SetMaxHealth(100.0f);
19
20 PawnSensingComponent = CreateDefaultSubobject<UAdvancedPawnSensingComponent>(TEXT("Pawn Sensing"));
21 PawnSensingComponent->bHearNoises = false;
22 PawnSensingComponent->bSeePawns = true;
23 PawnSensingComponent->bOnlySensePlayers = false;
24}
UHealthComponentBase * HealthComponent
Definition DefenseSystemPawn.h:155
UAdvancedPawnSensingComponent * PawnSensingComponent
Definition DefenseSystemPawn.h:157

Member Function Documentation

◆ BeginPlay()

void ADefenseSystemPawn::BeginPlay ( )
overrideprotectedvirtual

Reimplemented from AInteractablePawn.

Reimplemented in AAutoTurret, and ASecurityCameraPawn.

104{
105 if(bAutoActivate)
106 {
107 SetActive(true);
108 }
109 Super::BeginPlay();
111 AlertLevel = 0.0f;
112 if(HealthComponent != nullptr)
113 {
114 HealthComponent->OnDeath.AddUniqueDynamic(this, &ADefenseSystemPawn::OnDeath);
115 }
116 if(PawnSensingComponent != nullptr)
117 {
118 PawnSensingComponent->OnSeePawn.AddUniqueDynamic(this, &ADefenseSystemPawn::OnSeePawn);
119 PawnSensingComponent->OnHearNoise.AddUniqueDynamic(this, &ADefenseSystemPawn::OnHearPawn);
120 }
121 // OnTakeAnyDamage.AddUniqueDynamic(this, &ADefenseSystemPawn::AnyDamageTaken);
122 OnTakePointDamage.AddUniqueDynamic(this, &ADefenseSystemPawn::PointDamageTaken);
123
124}
float AlertLevel
Definition DefenseSystemPawn.h:106
virtual void PointDamageTaken(AActor *DamagedActor, float Damage, class AController *InstigatedBy, FVector HitLocation, class UPrimitiveComponent *HitComponent, FName BoneName, FVector ShotFromDirection, const class UDamageType *DamageType, AActor *DamageCauser)
Definition DefenseSystemPawn.cpp:418
virtual void OnDeath(AActor *OwningActor, EDeathType DeathType, AActor *DeathCauser, AController *DeathInstigator)
Definition DefenseSystemPawn.cpp:437
virtual void SetGenericTeamId(const FGenericTeamId &NewTeamID) override
Definition DefenseSystemPawn.cpp:59
void SetActive(const bool bValue)
Definition DefenseSystemPawn.cpp:92
virtual void OnSeePawn(APawn *Pawn)
Definition DefenseSystemPawn.cpp:127
virtual void OnHearPawn(APawn *Pawn, const FVector &Location, float Volume)
Definition DefenseSystemPawn.cpp:159
EFactionType OwnerFaction
Definition DefenseSystemPawn.h:67
bool bAutoActivate
Definition DefenseSystemPawn.h:124
static uint8 GetTeamIDFromFaction(const EFactionType Faction)
Definition AIBPLib.cpp:91

◆ CanStillSeePawn()

bool ADefenseSystemPawn::CanStillSeePawn ( APawn * Pawn) const
protected
347{
348 if(GetActive() == false || GetIsDead()){return false;}
349 if(PawnSensingComponent == nullptr || Pawn == nullptr){return false;}
350 return PawnSensingComponent->HasLineOfSightTo(Pawn) && PawnSensingComponent->CouldSeePawn(Pawn) && IsPawnAlive(Pawn);
351}
virtual bool GetIsDead() const override
Definition DefenseSystemPawn.h:75
bool GetActive() const
Definition DefenseSystemPawn.h:44
bool IsPawnAlive(APawn *Pawn) const
Definition DefenseSystemPawn.cpp:353

◆ CheckEnemySeen()

void ADefenseSystemPawn::CheckEnemySeen ( )
private
238{
239 if(GetActive() == false || GetIsDead()){LostAllTargets();return;}
240 if(Targets.IsEmpty())
241 {
242 GetWorld()->GetTimerManager().ClearTimer(EnemySeenTimerHandle);
243 if(bDebuggingMode){UE_LOG(LogAIToolKit, Warning, TEXT("Check Enemy Lost Target"));}
245 {
246 if(bDebuggingMode){UE_LOG(LogAIToolKit, Warning, TEXT("Set Timer LostAllTargets"));}
247 GetWorld()->GetTimerManager().SetTimer(LostTargetTimerHandle, this, &ADefenseSystemPawn::LostAllTargets, LostTargetResetTime, false);
248 }
249 else
250 {
251 if(bDebuggingMode){UE_LOG(LogAIToolKit, Warning, TEXT("Set Timer Decrease"));}
252 GetWorld()->GetTimerManager().SetTimer(DecreaseAlertTimerHandle, this, &ADefenseSystemPawn::DecreaseAlert, AlertUpdateFrequency, true, LostTargetResetTime);
253 }
254 return;
255 }
256 if(bDebuggingMode){UE_LOG(LogAIToolKit, Warning, TEXT("EnemySeen"));}
259}
bool bInstantResetOnLostTarget
Definition DefenseSystemPawn.h:116
float AlertUpdateFrequency
Definition DefenseSystemPawn.h:93
void CheckVisibilityOfTargets()
Definition DefenseSystemPawn.cpp:277
float LostTargetResetTime
Definition DefenseSystemPawn.h:119
virtual void LostAllTargets()
Definition DefenseSystemPawn.cpp:261
TArray< APawn * > Targets
Definition DefenseSystemPawn.h:224
FTimerHandle LostTargetTimerHandle
Definition DefenseSystemPawn.h:231
void DecreaseAlert()
Definition DefenseSystemPawn.cpp:217
FTimerHandle EnemySeenTimerHandle
Definition DefenseSystemPawn.h:229
FTimerHandle DecreaseAlertTimerHandle
Definition DefenseSystemPawn.h:227
void OnHostileSeenUpdate()
bool bDebuggingMode
Definition InteractablePawn.h:69

◆ CheckVisibilityOfTargets()

void ADefenseSystemPawn::CheckVisibilityOfTargets ( )
private
278{
279 for(int32 i = Targets.Num() - 1; i >= 0; i--)
280 {
281 APawn* TargetPawn = Targets[i];
282 if(TargetPawn == nullptr || !CanStillSeePawn(TargetPawn))
283 {
284 Targets.RemoveAt(i);
285 if(CurrentTarget == i)
286 {
287 if(Targets.IsValidIndex(0))
288 {
289 CurrentTarget = 0;
290 }
291 else
292 {
293 CurrentTarget = -1;
294 }
295 }
296 OnTargetLost();
297 // Optionally handle target lost logic here
298 }
299 }
300}
bool CanStillSeePawn(APawn *Pawn) const
Definition DefenseSystemPawn.cpp:346
int32 CurrentTarget
Definition DefenseSystemPawn.h:221

◆ DecreaseAlert()

void ADefenseSystemPawn::DecreaseAlert ( )
private
218{
220 if(bDebuggingMode){UE_LOG(LogAIToolKit, Warning, TEXT("Decrease Alert! %.2f"), AlertLevel);}
222 if(AlertLevel <= 0.0f)
223 {
224 GetWorld()->GetTimerManager().ClearTimer(DecreaseAlertTimerHandle);
226 }
227}
float AlertLevelThreshold
Definition DefenseSystemPawn.h:103
float AlertLevelDecrease
Definition DefenseSystemPawn.h:99
void OnAlertChange(const float CurrentAlertLevel, const float MaxAlertLevel)

◆ EnemySeen()

void ADefenseSystemPawn::EnemySeen ( )
protectedvirtual

Reimplemented in AAutoTurret, and ASecurityCameraPawn.

230{
231 bAlert = true;
232 GetWorld()->GetTimerManager().ClearTimer(IncreaseAlertTimerHandle);
233 GetWorld()->GetTimerManager().SetTimer(EnemySeenTimerHandle, this, &ADefenseSystemPawn::CheckEnemySeen, VisibilityCheckFrequency, true);
235}
void CheckEnemySeen()
Definition DefenseSystemPawn.cpp:237
bool bAlert
Definition DefenseSystemPawn.h:109
FTimerHandle IncreaseAlertTimerHandle
Definition DefenseSystemPawn.h:226
float VisibilityCheckFrequency
Definition DefenseSystemPawn.h:113

◆ GetActive()

bool ADefenseSystemPawn::GetActive ( ) const
inline
44{return bActive;};
bool bActive
Definition DefenseSystemPawn.h:206

◆ GetActorEyesViewPoint()

void ADefenseSystemPawn::GetActorEyesViewPoint ( FVector & OutLocation,
FRotator & OutRotation ) const
overrideprotectedvirtual

Reimplemented in AAutoTurret, and ASecurityCameraPawn.

81{
82 if(RootComponent != nullptr && RootComponent->DoesSocketExist(FName("Eyes")))
83 {
84 OutLocation = RootComponent->GetSocketLocation(FName("Eyes"));
85 OutRotation = RootComponent->GetSocketRotation(FName("Eyes"));
86 return;
87 }
88 Super::GetActorEyesViewPoint(OutLocation, OutRotation);
89}

◆ GetCharacterFaction()

virtual EFactionType ADefenseSystemPawn::GetCharacterFaction ( ) const
inlineoverrideprotectedvirtual

Implements ICharacterInterface.

72{return OwnerFaction;};

◆ GetCharacterType()

virtual ECharacterType ADefenseSystemPawn::GetCharacterType ( ) const
inlineoverrideprotectedvirtual

Implements ICharacterInterface.

70{return CharacterType;};
ECharacterType CharacterType
Definition DefenseSystemPawn.h:65

◆ GetCurrentTarget()

bool ADefenseSystemPawn::GetCurrentTarget ( APawn *& Pawn) const
protected
362{
363 if(GetActive() == false || GetIsDead()){return false;}
364 if(Targets.IsValidIndex(CurrentTarget) && Targets[CurrentTarget] != nullptr && IsPawnAlive(Targets[CurrentTarget]))
365 {
366 Pawn = Targets[CurrentTarget];
367 return true;
368 }
369 return false;
370}

◆ GetDistanceToPawn()

float ADefenseSystemPawn::GetDistanceToPawn ( const APawn * Pawn) const
protected

@Returns Distance to Pawn

373{
374 if(Pawn == nullptr){return 0.0f;}
375 return FVector::Distance(Pawn->GetActorLocation(), GetActorLocation());
376}

◆ GetGenericTeamId()

virtual FGenericTeamId ADefenseSystemPawn::GetGenericTeamId ( ) const
inlineoverridevirtual
37{return TeamID;};
FGenericTeamId TeamID
Definition DefenseSystemPawn.h:58

◆ GetIsCharacter()

virtual bool ADefenseSystemPawn::GetIsCharacter ( ) const
inlineoverrideprotectedvirtual
163{return true;};

◆ GetIsDead()

virtual bool ADefenseSystemPawn::GetIsDead ( ) const
inlineoverrideprotectedvirtual

Implements ICharacterInterface.

75{return bDead;};
bool bDead
Definition DefenseSystemPawn.h:122

◆ GetIsUpsideDown()

virtual bool ADefenseSystemPawn::GetIsUpsideDown ( ) const
inlineoverridevirtual

Implements IDefencePawnAnim.

Reimplemented in AAutoTurret, and ASecurityCameraPawn.

41{return false;};

◆ GetRotationToTarget()

FRotator ADefenseSystemPawn::GetRotationToTarget ( const FVector & StartLocation)
protectedvirtual
393{
394 APawn* Target;
395 if(GetCurrentTarget(Target) && Target != nullptr)
396 {
397 const FVector TargetLocation = Target->GetActorLocation();
398 return UKismetMathLibrary::FindLookAtRotation(StartLocation, TargetLocation);
399 }
400 return TargetRotation;
401}
bool GetCurrentTarget(APawn *&Pawn) const
Definition DefenseSystemPawn.cpp:361
FRotator TargetRotation
Definition DefenseSystemPawn.h:89

◆ GetTargetRotation()

virtual FRotator ADefenseSystemPawn::GetTargetRotation ( ) const
inlineoverridevirtual

Implements IDefencePawnAnim.

40{return TargetRotation;};

◆ GetTargets()

TArray< APawn * > & ADefenseSystemPawn::GetTargets ( )
inlineprotected

All Currently Perceived Pawns

183{return Targets;};

◆ GetTeamAttitudeTowards()

ETeamAttitude::Type ADefenseSystemPawn::GetTeamAttitudeTowards ( const AActor & Other) const
overridevirtual
27{
28 if(const APawn* OtherPawn = Cast<APawn>(&Other))
29 {
30 const IGenericTeamAgentInterface* TeamAgent = Cast<IGenericTeamAgentInterface>(OtherPawn);
31 if(TeamAgent == nullptr){TeamAgent = Cast<IGenericTeamAgentInterface>(OtherPawn->GetController());}
32 if(TeamAgent != nullptr)
33 {
34 const FGenericTeamId OtherTeamID = TeamAgent->GetGenericTeamId();
35 const EFactionType OtherPawnFaction = UAIBPLib::GetFactionFromTeamID(OtherTeamID);
36 bool bSuccess = false;
37 const FFactionRelationship Relationship = UAIBPLib::GetFactionRelationship(this, OwnerFaction, OtherPawnFaction, bSuccess);
38 if(bSuccess)
39 {
40 switch (Relationship.RelationshipStatus)
41 {
44 return ETeamAttitude::Friendly;
48 return ETeamAttitude::Neutral;
51 return ETeamAttitude::Hostile;
52 }
53 }
54 }
55 }
56 return ETeamAttitude::Neutral;
57}
EFactionType
Definition AIDataTypes.h:103
static EFactionType GetFactionFromTeamID(const uint8 TeamID)
Definition AIBPLib.cpp:120
static FFactionRelationship GetFactionRelationship(const UObject *WorldContextObject, const EFactionType Faction, const EFactionType TargetFaction, bool &bSuccess, UDataTable *DataTable=nullptr)
Definition AIBPLib.cpp:339
Definition AIDataTypes.h:279
ERelationshipStatus RelationshipStatus
Definition AIDataTypes.h:284

◆ GetTeamID()

int32 ADefenseSystemPawn::GetTeamID ( ) const
inlineprotected
60{return (TeamID == FGenericTeamId::NoTeam) ? INDEX_NONE : (int32)TeamID;};

◆ GetTotalDistanceScoreToAllTargets()

float ADefenseSystemPawn::GetTotalDistanceScoreToAllTargets ( ) const
protected

@Returns a % 0.0f - 1.0f based on Distance, Giving each pawn 100% of the SightRadius - Distance

379{
380 float TotalScore = 0.0f;
381 if(Targets.IsEmpty() || PawnSensingComponent == nullptr){return TotalScore;}
382 for(const auto& Pawn :Targets)
383 {
384 const float DistanceScore = PawnSensingComponent->SightRadius - GetDistanceToPawn(Pawn);
385 TotalScore += (DistanceScore / PawnSensingComponent->SightRadius); // Multiplied by 100 for percentage.
386 // TotalScore += PawnSensingComponent->SightRadius - GetDistanceToPawn(Pawn);
387 }
388 // const float Percent = (TotalScore / PawnSensingComponent->SightRadius) * 100.0f;
389 return TotalScore;
390}
float GetDistanceToPawn(const APawn *Pawn) const
Definition DefenseSystemPawn.cpp:372

◆ IncreaseAlert()

void ADefenseSystemPawn::IncreaseAlert ( )
private
190{
191 if(GetActive() == false || GetIsDead()){LostAllTargets();return;}
193 if(Targets.IsEmpty())
194 {
195 if(bDebuggingMode){UE_LOG(LogAIToolKit, Warning, TEXT("Lost Targets During Increase Alert"));}
197 {
199 }
200 else
201 {
202 GetWorld()->GetTimerManager().ClearTimer(IncreaseAlertTimerHandle);
203 GetWorld()->GetTimerManager().SetTimer(DecreaseAlertTimerHandle, this, &ADefenseSystemPawn::DecreaseAlert, AlertUpdateFrequency, true);
204 }
205 return;
206 }
210 {
212 EnemySeen();
213 }
214 if(bDebuggingMode){UE_LOG(LogAIToolKit, Warning, TEXT("Increase Alert! %.2f"), AlertLevel);}
215}
float AlertLevelIncrease
Definition DefenseSystemPawn.h:96
float GetTotalDistanceScoreToAllTargets() const
Definition DefenseSystemPawn.cpp:378
virtual void EnemySeen()
Definition DefenseSystemPawn.cpp:229

◆ IsPawnAlive()

bool ADefenseSystemPawn::IsPawnAlive ( APawn * Pawn) const
protected
354{
355 if(Pawn == nullptr){return false;}
356 const ICharacterInterface* Character = Cast<ICharacterInterface>(Pawn);
357 if(Character == nullptr || Character->GetIsDead()){return false;}
358 return true;
359}
Definition CharacterInterface.h:20

◆ LostAllTargets()

void ADefenseSystemPawn::LostAllTargets ( )
protectedvirtual

Reimplemented in AAutoTurret, and ASecurityCameraPawn.

262{
263 bAlert = false;
264 if(bDebuggingMode){UE_LOG(LogAIToolKit, Warning, TEXT("Lost All Targets"));}
265 GetWorld()->GetTimerManager().ClearTimer(IncreaseAlertTimerHandle);
266 GetWorld()->GetTimerManager().ClearTimer(LostTargetTimerHandle);
267 GetWorld()->GetTimerManager().ClearTimer(EnemySeenTimerHandle);
268 AlertLevel = 0.0f;
270}

◆ NewTargetSeen()

void ADefenseSystemPawn::NewTargetSeen ( APawn * Pawn)
protectedvirtual
185{
186 OnNewTargetSeen(Pawn);
187}
void OnNewTargetSeen(APawn *Pawn)

◆ OnActivated()

void ADefenseSystemPawn::OnActivated ( const bool bValue)

◆ OnActivated_Implementation()

void ADefenseSystemPawn::OnActivated_Implementation ( const bool bValue)
virtual
99{
100
101}

◆ OnAlertChange()

void ADefenseSystemPawn::OnAlertChange ( const float CurrentAlertLevel,
const float MaxAlertLevel )
protected

◆ OnDeath()

void ADefenseSystemPawn::OnDeath ( AActor * OwningActor,
EDeathType DeathType,
AActor * DeathCauser,
AController * DeathInstigator )
protectedvirtual

Reimplemented in AAutoTurret, and ASecurityCameraPawn.

439{
440 SetActive(false);
441 bDead = true;
442 AlertLevel = 0.0f;
443 bAlert = false;
444 if(PawnSensingComponent != nullptr)
445 {
446 PawnSensingComponent->DestroyComponent();
447 }
448 if(GetWorld() != nullptr)
449 {
450 GetWorld()->GetTimerManager().ClearTimer(EnemySeenTimerHandle);
451 GetWorld()->GetTimerManager().ClearTimer(CheckVisibilityTimerHandle);
452 GetWorld()->GetTimerManager().ClearTimer(LostTargetTimerHandle);
453 GetWorld()->GetTimerManager().ClearTimer(DecreaseAlertTimerHandle);
454 }
455}
FTimerHandle CheckVisibilityTimerHandle
Definition DefenseSystemPawn.h:230

◆ OnHearPawn()

void ADefenseSystemPawn::OnHearPawn ( APawn * Pawn,
const FVector & Location,
float Volume )
privatevirtual
160{
161
162}

◆ OnHostileSeen()

void ADefenseSystemPawn::OnHostileSeen ( )
protected

◆ OnHostileSeenUpdate()

void ADefenseSystemPawn::OnHostileSeenUpdate ( )
protected

◆ OnLostAllTargets()

void ADefenseSystemPawn::OnLostAllTargets ( )
protected

◆ OnNewTargetSeen()

void ADefenseSystemPawn::OnNewTargetSeen ( APawn * Pawn)
protected

Should we check if we can still see the target before we've hit the Alert level Target who isn't known seen, alert will begin

◆ OnSeePawn()

void ADefenseSystemPawn::OnSeePawn ( APawn * Pawn)
privatevirtual
128{
129 if(GetActive() == false){return;}
130 if(GetWorld() == nullptr){return;}
131 if(Pawn == nullptr){return;}
132 //- Only get Hostile Targets //
133 // GetController()->G/
134 const ETeamAttitude::Type Attitude = GetTeamAttitudeTowards(*Pawn);
135 if(Attitude != ETeamAttitude::Hostile){return;}
136 //- Only Alive Targets && Character Pawns //
137 const ICharacterInterface* Character = Cast<ICharacterInterface>(Pawn);
138 if(Character == nullptr || Character->GetIsDead()){return;}
139
140 TargetSeen(Pawn);
141
142 // if(!Targets.Contains(Pawn))
143 // {
144 // OnNewTargetSeen();
145 // }
146 // if(Targets.IsEmpty())
147 // {
148 // GetWorld()->GetTimerManager().SetTimer(IncreaseAlertTimerHandle, this, &ADefenseSystemPawn::IncreaseAlert, AlertUpdateFrequency, true);
149 // }
150 // //- No Current Target, set Current //
151 // if(CurrentTarget == -1)
152 // {
153 // CurrentTarget = Targets.AddUnique(Pawn);
154 // }
155 // Targets.AddUnique(Pawn);
156 // OnTargetSeen();
157}
virtual ETeamAttitude::Type GetTeamAttitudeTowards(const AActor &Other) const override
Definition DefenseSystemPawn.cpp:26
virtual void TargetSeen(APawn *Pawn)
Definition DefenseSystemPawn.cpp:164

◆ OnTargetLost()

void ADefenseSystemPawn::OnTargetLost ( )
protected

◆ OnTargetSeen()

void ADefenseSystemPawn::OnTargetSeen ( APawn * Pawn)
protected

Target seen, called for each target that enters view

◆ PointDamageTaken()

void ADefenseSystemPawn::PointDamageTaken ( AActor * DamagedActor,
float Damage,
class AController * InstigatedBy,
FVector HitLocation,
class UPrimitiveComponent * HitComponent,
FName BoneName,
FVector ShotFromDirection,
const class UDamageType * DamageType,
AActor * DamageCauser )
protectedvirtual
421{
422 if(InstigatedBy != nullptr && InstigatedBy->GetPawn() != nullptr)
423 {
424 bool bKillingHit = false;
425 if(HealthComponent != nullptr)
426 {
427 bKillingHit = HealthComponent->GetHealth() <= 0.0f;
428 }
429 IHitMarkerInterface* HitMarkerActor = Cast<IHitMarkerInterface>(InstigatedBy->GetPawn());
430 if(HitMarkerActor != nullptr)
431 {
432 HitMarkerActor->HitMarker(this, Damage, DamageType, BoneName, HitLocation, bKillingHit);
433 }
434 }
435}
Definition HitMarkerInterface.h:16
virtual void HitMarker(const AActor *ActorHit, const float Damage, const UDamageType *DamageType, const FName HitBone, const FVector HitLocation, const bool bKillingHit=false, const bool bInjuredPart=false)=0

◆ RotateToTarget()

void ADefenseSystemPawn::RotateToTarget ( )
protectedvirtual

Reimplemented in AAutoTurret, and ASecurityCameraPawn.

273{
274
275}

◆ SetActive()

void ADefenseSystemPawn::SetActive ( const bool bValue)
93{
94 bActive = bValue;
96}
void OnActivated(const bool bValue)

◆ SetCharacterVehicleMode()

void ADefenseSystemPawn::SetCharacterVehicleMode ( const EVehicleMode Mode)
overrideprotectedvirtual

Implements ICharacterInterface.

76{
77
78}

◆ SetGenericTeamId()

void ADefenseSystemPawn::SetGenericTeamId ( const FGenericTeamId & NewTeamID)
overridevirtual
60{
61 if(HasAuthority())
62 {
63 const FGenericTeamId OldTeamID = TeamID;
64
65 // MARK_PROPERTY_DIRTY_FROM_NAME(ThisClass, MyTeamID, this);
66 TeamID = NewTeamID;
67 if(bDebuggingMode){ UE_LOG(LogTemp, Error, TEXT("team %i"), NewTeamID.GetId());}
68 }
69 else
70 {
71 if(bDebuggingMode){UE_LOG(LogTemp, Error, TEXT("Cannot set team for %s on non-authority"), *GetPathName(this));}
72 }
73}

◆ TargetSeen()

void ADefenseSystemPawn::TargetSeen ( APawn * Pawn)
protectedvirtual

Only Fires when Someone is Hostile, Alive, and a Character

Reimplemented in ASecurityCameraPawn.

165{
166 if(GetActive() == false || GetIsDead()){LostAllTargets();return;}
167 GetWorld()->GetTimerManager().ClearTimer(DecreaseAlertTimerHandle);
168 //- Is The Target New? //
169 if(!Targets.Contains(Pawn)){NewTargetSeen(Pawn);}
170 //- If First Target, Start Increase Alert //
171 if(Targets.IsEmpty())
172 {
173 GetWorld()->GetTimerManager().SetTimer(IncreaseAlertTimerHandle, this, &ADefenseSystemPawn::IncreaseAlert, AlertUpdateFrequency, true);
174 }
175 //- No Current Target, set Current Target to Pawn //
176 if(CurrentTarget == -1)
177 {
178 CurrentTarget = Targets.AddUnique(Pawn);
179 }
180 Targets.AddUnique(Pawn);
181 OnTargetSeen(Pawn);
182}
virtual void NewTargetSeen(APawn *Pawn)
Definition DefenseSystemPawn.cpp:184
void IncreaseAlert()
Definition DefenseSystemPawn.cpp:189
void OnTargetSeen(APawn *Pawn)

Member Data Documentation

◆ AlertLevel

float ADefenseSystemPawn::AlertLevel = 0.0f
protected

Current Alert Level

◆ AlertLevelDecrease

float ADefenseSystemPawn::AlertLevelDecrease = 0.1f
protected

How much the alert goes down each update

◆ AlertLevelIncrease

float ADefenseSystemPawn::AlertLevelIncrease = 0.1f
protected

How much the alert goes up each update

◆ AlertLevelThreshold

float ADefenseSystemPawn::AlertLevelThreshold = 100.0f
protected

Level that triggers the Alert

◆ AlertUpdateFrequency

float ADefenseSystemPawn::AlertUpdateFrequency = 0.2f
protected

How Frequently the Alert goes up, and checks the target is still in view

◆ bActive

bool ADefenseSystemPawn::bActive = false
private

◆ bAlert

bool ADefenseSystemPawn::bAlert = false
protected

Is Pawn Alert

◆ bAutoActivate

bool ADefenseSystemPawn::bAutoActivate = true
protected

◆ bDead

bool ADefenseSystemPawn::bDead = false
protected

◆ bInstantResetOnLostTarget

bool ADefenseSystemPawn::bInstantResetOnLostTarget = false
protected

Once lost all targets, Should just instantly go back

◆ CharacterType

ECharacterType ADefenseSystemPawn::CharacterType = ECharacterType::Defence
protected

◆ CheckVisibilityTimerHandle

FTimerHandle ADefenseSystemPawn::CheckVisibilityTimerHandle
private

◆ CurrentTarget

int32 ADefenseSystemPawn::CurrentTarget = -1
private

◆ DecreaseAlertTimerHandle

FTimerHandle ADefenseSystemPawn::DecreaseAlertTimerHandle
private

◆ EnemySeenTimerHandle

FTimerHandle ADefenseSystemPawn::EnemySeenTimerHandle
private

◆ HealthComponent

UHealthComponentBase* ADefenseSystemPawn::HealthComponent
protected

◆ IncreaseAlertTimerHandle

FTimerHandle ADefenseSystemPawn::IncreaseAlertTimerHandle
private

◆ LostTargetResetTime

float ADefenseSystemPawn::LostTargetResetTime = 2.0f
protected

Once lost all targets, Should just instantly go back

◆ LostTargetTimerHandle

FTimerHandle ADefenseSystemPawn::LostTargetTimerHandle
private

◆ OwnerFaction

EFactionType ADefenseSystemPawn::OwnerFaction = EFactionType::Alliance
protected

◆ PawnSensingComponent

UAdvancedPawnSensingComponent* ADefenseSystemPawn::PawnSensingComponent
protected

◆ StartRotation

FRotator ADefenseSystemPawn::StartRotation = FRotator::ZeroRotator
protected

◆ TargetRotation

FRotator ADefenseSystemPawn::TargetRotation = FRotator::ZeroRotator
protected

◆ Targets

TArray<APawn*> ADefenseSystemPawn::Targets
private

All Currently Perceived Pawns

◆ TeamID

FGenericTeamId ADefenseSystemPawn::TeamID
protected

◆ VisibilityCheckFrequency

float ADefenseSystemPawn::VisibilityCheckFrequency = 2.0f
protected

Once Alert, How often does pawn check the Target is still in View


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