dungeon/src/IfSeeEnemyNode.cpp

32 lines
886 B
C++
Raw Normal View History

2017-09-17 13:43:13 +02:00
#include "IfSeeEnemyNode.h"
#include "BehaviourTree.h"
#include "Actor.h"
#include "Tilemap.h"
#include "FieldOfView.h"
2017-09-17 13:43:13 +02:00
IfSeeEnemyNode::IfSeeEnemyNode(BehaviourTreeNode * parent) : BehaviourTreeNode(parent) {}
IfSeeEnemyNode::~IfSeeEnemyNode() {}
BehaviourTreeStatus IfSeeEnemyNode::tick(BTTick * tick) {
if (children.size() <= 0) {
return BT_ERROR;
}
2017-09-26 15:49:11 +02:00
bool ishero = tick->target->is_type_of(ACT_HERO);
vec2i targetpos = tick->target->get_position();
2017-09-17 13:43:13 +02:00
2018-01-09 21:59:05 +01:00
auto actors = tick->map->get_actors(targetpos.x, targetpos.y, 6);
for (Actor* actor : actors) {
2017-09-17 13:43:13 +02:00
if (actor == tick->target) continue;
2017-09-26 15:49:11 +02:00
if (actor->is_type_of(ACT_HERO) != ishero) {
2017-09-21 22:44:05 +02:00
vec2i pos = actor->get_position();
2018-01-09 21:59:05 +01:00
if (line_of_sight(tick->map, tick->target->get_position(), pos)) {
2017-09-17 13:43:13 +02:00
return children[0]->execute(tick);
}
}
}
return BT_FAILED;
}