2017-09-17 13:43:13 +02:00
|
|
|
#include "HealFriendNode.h"
|
|
|
|
#include "BehaviourTree.h"
|
|
|
|
#include "Actor.h"
|
|
|
|
#include "Tilemap.h"
|
2017-09-21 22:17:06 +02:00
|
|
|
#include "FieldOfView.h"
|
2017-09-17 13:43:13 +02:00
|
|
|
|
|
|
|
|
|
|
|
HealFriendNode::HealFriendNode(BehaviourTreeNode * parent) : BehaviourTreeNode(parent){}
|
|
|
|
|
2017-09-26 15:49:11 +02:00
|
|
|
HealFriendNode::~HealFriendNode() = default;
|
2017-09-17 13:43:13 +02:00
|
|
|
|
|
|
|
BehaviourTreeStatus HealFriendNode::tick(BTTick * tick) {
|
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);
|
2017-09-17 13:43:13 +02:00
|
|
|
std::vector<Actor*> friends;
|
2017-12-30 20:15:39 +01:00
|
|
|
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 && actor->get_health() < actor->get_health_max()) {
|
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
|
|
|
friends.push_back(actor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-26 15:49:11 +02:00
|
|
|
if (friends.empty()) {
|
2017-09-17 13:43:13 +02:00
|
|
|
return BT_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
Actor* lowestHpActor = nullptr;
|
|
|
|
int lowestHp;
|
2017-09-17 20:07:38 +02:00
|
|
|
for (Actor* actor : friends) {
|
2017-09-26 15:49:11 +02:00
|
|
|
if (lowestHpActor == nullptr || actor->get_health() < lowestHp) {
|
2017-09-17 13:43:13 +02:00
|
|
|
lowestHpActor = actor;
|
2017-09-26 15:49:11 +02:00
|
|
|
lowestHp = actor->get_health();
|
2017-09-17 13:43:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-26 15:49:11 +02:00
|
|
|
lowestHpActor->heal(1);
|
2017-09-17 13:43:13 +02:00
|
|
|
return BT_SUCCEEDED;
|
|
|
|
}
|