From db4d6beb4cfc27e83c1a35ed27ba1b793d400204 Mon Sep 17 00:00:00 2001 From: baz Date: Mon, 12 Feb 2024 21:18:07 +0000 Subject: [PATCH] Create AI State Enum --- Source/Nakatomi/EAIState.cpp | 5 +++++ Source/Nakatomi/EAIState.h | 18 ++++++++++++++++++ Source/Nakatomi/EnemyAIController.cpp | 20 ++++++++++++++++++++ Source/Nakatomi/EnemyAIController.h | 10 ++++++++++ 4 files changed, 53 insertions(+) create mode 100644 Source/Nakatomi/EAIState.cpp create mode 100644 Source/Nakatomi/EAIState.h diff --git a/Source/Nakatomi/EAIState.cpp b/Source/Nakatomi/EAIState.cpp new file mode 100644 index 0000000..b94b964 --- /dev/null +++ b/Source/Nakatomi/EAIState.cpp @@ -0,0 +1,5 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "EAIState.h" + diff --git a/Source/Nakatomi/EAIState.h b/Source/Nakatomi/EAIState.h new file mode 100644 index 0000000..abadf5b --- /dev/null +++ b/Source/Nakatomi/EAIState.h @@ -0,0 +1,18 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" + +/** + * + */ +UENUM(BlueprintType) +enum class EAIState : uint8 +{ + PASSIVE UMETA(DisplayName = "Passive"), + ATTACKING UMETA(DisplayName = "Attacking"), + FROZEN UMETA(DisplayName = "Frozen"), + INVESTIGATING UMETA(DisplayName = "Investigating"), + DEAD UMETA(DisplayName = "Dead"), +}; diff --git a/Source/Nakatomi/EnemyAIController.cpp b/Source/Nakatomi/EnemyAIController.cpp index bbc8b5a..e67cc77 100644 --- a/Source/Nakatomi/EnemyAIController.cpp +++ b/Source/Nakatomi/EnemyAIController.cpp @@ -2,6 +2,8 @@ #include "EnemyAIController.h" #include + +#include "EAIState.h" #include "NakatomiGameInstance.h" #include "BehaviorTree/BehaviorTree.h" #include "BehaviorTree/BlackboardComponent.h" @@ -48,6 +50,8 @@ void AEnemyAIController::OnPossess(APawn* InPawn) BehaviorTree->StartTree(*behaviourTree); Blackboard->SetValueAsObject("SelfActor", enemy); } + + Blackboard->SetValueAsEnum("State", static_cast(EAIState::PASSIVE)); //ensure(enemy->GetMovementComponent()->UseAccelerationForPathFollowing()); } @@ -179,3 +183,19 @@ bool AEnemyAIController::GetHasAttackToken() { return HasAttackToken; } + +void AEnemyAIController::SetState(EAIState state) +{ + Blackboard->SetValueAsEnum("State", static_cast(state)); +} + +void AEnemyAIController::SetStateAsPassive() +{ + SetState(EAIState::PASSIVE); +} + +void AEnemyAIController::SetStateAsAttacking(AActor* target) +{ + Blackboard->SetValueAsObject("TargetActor", target); + SetState(EAIState::ATTACKING); +} diff --git a/Source/Nakatomi/EnemyAIController.h b/Source/Nakatomi/EnemyAIController.h index 3122437..28f02e5 100644 --- a/Source/Nakatomi/EnemyAIController.h +++ b/Source/Nakatomi/EnemyAIController.h @@ -4,6 +4,7 @@ #include "CoreMinimal.h" #include "AIController.h" +#include "EAIState.h" #include "EnemyCharacter.h" #include "PlayerCharacter.h" #include "Perception/AISenseConfig_Sight.h" @@ -59,4 +60,13 @@ public: UFUNCTION() bool GetHasAttackToken(); + + UFUNCTION() + void SetState(EAIState state); + + UFUNCTION() + void SetStateAsPassive(); + + UFUNCTION() + void SetStateAsAttacking(AActor* target); };