dungeon/src/HealFriendNode.cpp

44 lines
1.1 KiB
C++
Raw Normal View History

2017-09-17 13:43:13 +02:00
#include "HealFriendNode.h"
#include "BehaviourTree.h"
#include "Actor.h"
#include "Tilemap.h"
#include "FieldOfView.h"
2017-09-17 13:43:13 +02:00
HealFriendNode::HealFriendNode(BehaviourTreeNode * parent) : BehaviourTreeNode(parent){}
HealFriendNode::~HealFriendNode() {}
BehaviourTreeStatus HealFriendNode::tick(BTTick * tick) {
bool ishero = tick->target->isTypeOf(ACT_HERO);
auto actors = tick->target->map->GetActorList();
std::vector<Actor*> friends;
2017-09-17 20:07:38 +02:00
for (auto actor : *actors) {
2017-09-17 13:43:13 +02:00
if (actor == tick->target) continue;
if (actor->isTypeOf(ACT_HERO) == ishero && actor->health < actor->maxhealth-1) {
vec2i pos = actor->getPosition();
if (line_of_sight(tick->target->map, tick->target->getPosition(), pos)) {
2017-09-17 13:43:13 +02:00
friends.push_back(actor);
}
}
}
if (friends.size() == 0) {
return BT_FAILED;
}
Actor* lowestHpActor = nullptr;
int lowestHp;
2017-09-17 20:07:38 +02:00
for (Actor* actor : friends) {
2017-09-17 13:43:13 +02:00
if (lowestHpActor == nullptr || actor->health < lowestHp) {
lowestHpActor = actor;
lowestHp = actor->health;
}
}
lowestHpActor->health += 1;
return BT_SUCCEEDED;
}