From 08fbc2180d5b909573cd0ed957e978f16e069fe9 Mon Sep 17 00:00:00 2001 From: PHILIP White Date: Wed, 22 Mar 2023 05:36:20 +0000 Subject: [PATCH] Added More GOAP Actions --- .../GOAP/Actions/COMBO_P.cpp | 12 +++++++++++ .../GOAP/Actions/{Combo_P.h => COMBO_P.h} | 3 +-- .../GOAP/Actions/COMBO_PP.cpp | 12 +++++++++++ .../GOAP/Actions/COMBO_PP.h | 19 ++++++++++++++++++ .../GOAP/Actions/COMBO_PPP.cpp | 12 +++++++++++ .../GOAP/Actions/COMBO_PPP.h | 19 ++++++++++++++++++ .../GOAP/Actions/Combo_P.cpp | 20 ------------------- .../GOAP/Actions/DefaultAttack.cpp | 8 -------- .../GOAP/Actions/DefaultAttack.h | 1 - .../COMP250_1_2101327_AI/GOAP/GOAPAction.cpp | 20 ++++++++++--------- .../COMP250_1_2101327_AI/GOAP/GOAPAction.h | 8 ++++---- .../COMP250_1_2101327_AI/GOAP/WorldState.cpp | 4 ++++ .../COMP250_1_2101327_AI/GOAP/WorldState.h | 19 ++++++++++++++++++ 13 files changed, 113 insertions(+), 44 deletions(-) create mode 100644 COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/Actions/COMBO_P.cpp rename COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/Actions/{Combo_P.h => COMBO_P.h} (73%) create mode 100644 COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/Actions/COMBO_PP.cpp create mode 100644 COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/Actions/COMBO_PP.h create mode 100644 COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/Actions/COMBO_PPP.cpp create mode 100644 COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/Actions/COMBO_PPP.h delete mode 100644 COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/Actions/Combo_P.cpp create mode 100644 COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/WorldState.cpp create mode 100644 COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/WorldState.h diff --git a/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/Actions/COMBO_P.cpp b/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/Actions/COMBO_P.cpp new file mode 100644 index 0000000..9de9b17 --- /dev/null +++ b/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/Actions/COMBO_P.cpp @@ -0,0 +1,12 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "Combo_P.h" + +void UCOMBO_P::Init() +{ + ActionCost = 3.0f; + PreConditions.Add("ProbertiumResource", 1); + Effects.Add("PlayerHealth", 5); + Effects.Add("ProbertiumResource", 1); +} diff --git a/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/Actions/Combo_P.h b/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/Actions/COMBO_P.h similarity index 73% rename from COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/Actions/Combo_P.h rename to COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/Actions/COMBO_P.h index f692f57..09d82bf 100644 --- a/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/Actions/Combo_P.h +++ b/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/Actions/COMBO_P.h @@ -10,11 +10,10 @@ * */ UCLASS() -class COMP250_1_2101327_AI_API UCombo_P : public UGOAPAction +class COMP250_1_2101327_AI_API UCOMBO_P : public UGOAPAction { GENERATED_BODY() public: virtual void Init() override; - virtual bool Perform() override; }; diff --git a/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/Actions/COMBO_PP.cpp b/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/Actions/COMBO_PP.cpp new file mode 100644 index 0000000..c970777 --- /dev/null +++ b/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/Actions/COMBO_PP.cpp @@ -0,0 +1,12 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "COMBO_PP.h" + +void UCOMBO_PP::Init() +{ + ActionCost = 2.0f; + PreConditions.Add("ProbertiumResource", 2); + Effects.Add("PlayerHealth", 10); + Effects.Add("ProbertiumResource", 2); +} diff --git a/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/Actions/COMBO_PP.h b/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/Actions/COMBO_PP.h new file mode 100644 index 0000000..703e9b2 --- /dev/null +++ b/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/Actions/COMBO_PP.h @@ -0,0 +1,19 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "../GOAPAction.h" +#include "COMBO_PP.generated.h" + +/** + * + */ +UCLASS() +class COMP250_1_2101327_AI_API UCOMBO_PP : public UGOAPAction +{ + GENERATED_BODY() + +public: + virtual void Init() override; +}; diff --git a/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/Actions/COMBO_PPP.cpp b/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/Actions/COMBO_PPP.cpp new file mode 100644 index 0000000..421689c --- /dev/null +++ b/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/Actions/COMBO_PPP.cpp @@ -0,0 +1,12 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "COMBO_PPP.h" + +void UCOMBO_PPP::Init() +{ + ActionCost = 1.0f; + PreConditions.Add("ProbertiumResource", 3); + Effects.Add("PlayerHealth", 15); + Effects.Add("ProbertiumResource", 3); +} diff --git a/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/Actions/COMBO_PPP.h b/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/Actions/COMBO_PPP.h new file mode 100644 index 0000000..dfe2022 --- /dev/null +++ b/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/Actions/COMBO_PPP.h @@ -0,0 +1,19 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "../GOAPAction.h" +#include "COMBO_PPP.generated.h" + +/** + * + */ +UCLASS() +class COMP250_1_2101327_AI_API UCOMBO_PPP : public UGOAPAction +{ + GENERATED_BODY() + +public: + virtual void Init() override; +}; diff --git a/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/Actions/Combo_P.cpp b/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/Actions/Combo_P.cpp deleted file mode 100644 index 9408bce..0000000 --- a/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/Actions/Combo_P.cpp +++ /dev/null @@ -1,20 +0,0 @@ -// Fill out your copyright notice in the Description page of Project Settings. - - -#include "Combo_P.h" - -void UCombo_P::Init() -{ - PreConditions.Add("PlayerHealth", 15); - PreConditions.Add("ProbertiumResource", 5); - Effects.Add("PlayerHealth", 15); - Effects.Add("ProbertiumResource", 5); -} - -bool UCombo_P::Perform() -{ - ATurnBaseCombatV2* CombatSystem = Cast(GetWorld()->GetGameState()); - CombatSystem->DamagePlayer(15, "P"); - - return true; -} diff --git a/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/Actions/DefaultAttack.cpp b/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/Actions/DefaultAttack.cpp index 599809e..d4614cf 100644 --- a/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/Actions/DefaultAttack.cpp +++ b/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/Actions/DefaultAttack.cpp @@ -9,11 +9,3 @@ void UDefaultAttack::Init() PreConditions.Add("PlayerHealth", 1); Effects.Add("PlayerHealth", 1); } - -bool UDefaultAttack::Perform() -{ - ATurnBaseCombatV2* CombatSystem = Cast(GetWorld()->GetGameState()); - CombatSystem->DamagePlayer(1, "Punch"); - - return true; -} diff --git a/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/Actions/DefaultAttack.h b/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/Actions/DefaultAttack.h index 2756d84..258e8b4 100644 --- a/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/Actions/DefaultAttack.h +++ b/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/Actions/DefaultAttack.h @@ -16,5 +16,4 @@ class COMP250_1_2101327_AI_API UDefaultAttack : public UGOAPAction public: virtual void Init() override; - virtual bool Perform() override; }; diff --git a/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/GOAPAction.cpp b/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/GOAPAction.cpp index e282e8a..f135419 100644 --- a/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/GOAPAction.cpp +++ b/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/GOAPAction.cpp @@ -3,31 +3,33 @@ #include "GOAPAction.h" -bool UGOAPAction::CheckPreConditions(TMap WorldState) +bool UGOAPAction::CheckPreConditions(UWorldState* WorldState) { for (TPair PreCondition : PreConditions) { - if (WorldState.Contains(PreCondition.Key)) + if (WorldState->State.Contains(PreCondition.Key)) { - if (WorldState[PreCondition.Key] < PreCondition.Value) return false; + if (WorldState->State[PreCondition.Key] < PreCondition.Value) return false; } } return true; } -TMap UGOAPAction::ApplyEffects(TMap WorldState) +UWorldState* UGOAPAction::ApplyEffects(UWorldState* WorldState) { + UWorldState* NewWorldState = NewObject(); + NewWorldState->State.Append(WorldState->State); for (TPair Effect : Effects) { - if (WorldState.Contains(Effect.Key)) + if (NewWorldState->State.Contains(Effect.Key)) { - WorldState[Effect.Key] -= Effect.Value; + NewWorldState->State[Effect.Key] -= Effect.Value; } } - return WorldState; + return NewWorldState; } -bool UGOAPAction::Perform() +int UGOAPAction::Perform() { - return false; + return Effects["PlayerHealth"]; } diff --git a/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/GOAPAction.h b/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/GOAPAction.h index 58ac314..71cb6a5 100644 --- a/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/GOAPAction.h +++ b/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/GOAPAction.h @@ -4,7 +4,7 @@ #include "CoreMinimal.h" #include "UObject/Object.h" -#include "COMP250_1_2101327_AI/TurnBasedCombatV2/TurnBaseCombatV2.h" +#include "WorldState.h" #include "GOAPAction.generated.h" /** @@ -19,11 +19,11 @@ public: float ActionCost = 1.0f; UFUNCTION() - bool CheckPreConditions(TMap WorldState); + bool CheckPreConditions(UWorldState* WorldState); UFUNCTION() - TMap ApplyEffects(TMap WorldState); + UWorldState* ApplyEffects(UWorldState* WorldState); UFUNCTION() - virtual bool Perform(); + virtual int Perform(); UPROPERTY() TMap PreConditions; diff --git a/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/WorldState.cpp b/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/WorldState.cpp new file mode 100644 index 0000000..e17610f --- /dev/null +++ b/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/WorldState.cpp @@ -0,0 +1,4 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "WorldState.h" diff --git a/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/WorldState.h b/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/WorldState.h new file mode 100644 index 0000000..bde825b --- /dev/null +++ b/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/WorldState.h @@ -0,0 +1,19 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "UObject/Object.h" +#include "WorldState.generated.h" + +/** + * + */ +UCLASS() +class COMP250_1_2101327_AI_API UWorldState : public UObject +{ + GENERATED_BODY() + +public: + TMap State; +};