diff --git a/COMP250_1_2101327_AI/COMP250_1_2101327_AI.uproject.DotSettings b/COMP250_1_2101327_AI/COMP250_1_2101327_AI.uproject.DotSettings index 2323d1b..453a20d 100644 --- a/COMP250_1_2101327_AI/COMP250_1_2101327_AI.uproject.DotSettings +++ b/COMP250_1_2101327_AI/COMP250_1_2101327_AI.uproject.DotSettings @@ -1,4 +1,5 @@  True + True True True \ No newline at end of file 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 new file mode 100644 index 0000000..84087c7 --- /dev/null +++ b/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/GOAPAction.cpp @@ -0,0 +1,32 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "GOAPAction.h" + +bool UGOAPAction::CheckPreConditions(TMap WorldState) +{ + for (TPair PreCondition : PreConditions) + { + if (WorldState.Contains(PreCondition.Key)) + { + if (WorldState[PreCondition.Key] != PreCondition.Value) return false; + } + } + return true; +} + +TMap UGOAPAction::ApplyEffects(TMap WorldState) +{ + for (TPair Effect : Effects) + { + if (WorldState.Contains(Effect.Key)) + { + WorldState[Effect.Key] = Effect.Value; + } + else + { + WorldState.Add(Effect.Key, Effect.Value); + } + } + return WorldState; +} 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 new file mode 100644 index 0000000..c3311ea --- /dev/null +++ b/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/GOAPAction.h @@ -0,0 +1,24 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "UObject/Object.h" +#include "GOAPAction.generated.h" + +/** + * + */ +UCLASS() +class COMP250_1_2101327_AI_API UGOAPAction : public UObject +{ + GENERATED_BODY() + +public: + virtual bool CheckPreConditions(TMap WorldState); + TMap ApplyEffects(TMap WorldState); + +protected: + TMap PreConditions; + TMap Effects; +};