summaryrefslogtreecommitdiff
path: root/engine-ocean/Game/Systems/AI/aibehaviorcomponent.cpp
blob: b43ed07ca36b2f88781dc0d068f9ac4bf2b0cbb6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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<std::string, BlackboardData>& global_blackboard):
    m_global_blackboard(global_blackboard)
{
    m_entity_id = entity_id;
    makeBehaviorTree();

}

void AIBehaviorComponent::makeBehaviorTree(){
    // leaves
    //std::unique_ptr<BTNode> walk = std::make_unique<WalkAction>(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;
}