From a556b45abf18f1bd509daaf63b66b7d55e9fd291 Mon Sep 17 00:00:00 2001 From: jjesswan Date: Mon, 22 Apr 2024 21:56:26 -0400 Subject: add engine version --- .../Game/Systems/AI/aibehaviorcomponent.cpp | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 engine-ocean/Game/Systems/AI/aibehaviorcomponent.cpp (limited to 'engine-ocean/Game/Systems/AI/aibehaviorcomponent.cpp') diff --git a/engine-ocean/Game/Systems/AI/aibehaviorcomponent.cpp b/engine-ocean/Game/Systems/AI/aibehaviorcomponent.cpp new file mode 100644 index 0000000..b43ed07 --- /dev/null +++ b/engine-ocean/Game/Systems/AI/aibehaviorcomponent.cpp @@ -0,0 +1,46 @@ +#include "aibehaviorcomponent.h" +#include "Game/Systems/AI/Actions/walkaction.h" +#include "Game/Systems/AI/Conditions/proximitycondition.h" +#include "Game/Systems/AI/btselector.h" +#include "Game/Systems/AI/btsequence.h" + +AIBehaviorComponent::AIBehaviorComponent(std::string entity_id, + std::map& global_blackboard): + m_global_blackboard(global_blackboard) +{ + m_entity_id = entity_id; + makeBehaviorTree(); + +} + +void AIBehaviorComponent::makeBehaviorTree(){ + // leaves + //std::unique_ptr walk = std::make_unique(m_entity_id, m_global_blackboard); + BTNode *proximCond = new ProximityCondition(m_entity_id, m_global_blackboard, 20.f); + BTNode *walk = new WalkAction(m_entity_id, m_global_blackboard); + + +// // pathfind sequence + BTNode *pathfindSeq = new BTSequence; + pathfindSeq->addChildren(proximCond); + pathfindSeq->addChildren(walk); + +// // idle sequence + +// // root + m_root = new BTSelector; + m_root->addChildren(pathfindSeq); +} + +// how might i be able to generalize the creation of the tree? +void AIBehaviorComponent::update(float seconds){ + // update root, which updates all its children + //std::cout << "---------in ai system" << std::endl; + + m_status = m_root->update(seconds); +} + +AIBehaviorComponent::~AIBehaviorComponent(){ + delete m_root; +} + -- cgit v1.2.3-70-g09d2