-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAggressiveAI.cpp
More file actions
28 lines (21 loc) · 857 Bytes
/
AggressiveAI.cpp
File metadata and controls
28 lines (21 loc) · 857 Bytes
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
#include "AggressiveAI.hpp"
#include "Battle.hpp"
#include "Character.hpp"
#include "BasicAttackAction.hpp"
std::shared_ptr<Action> AggressiveAI::chooseAction(Battle& battle,
const std::shared_ptr<Character>& actor) {
auto enemies = battle.enemiesOf(actor);
if (enemies.empty()) return nullptr;
// Target the enemy with the lowest current HP (focus-fire the weakest)
std::shared_ptr<Character> target = enemies[0];
for (const auto& enemy : enemies) {
if (enemy->getHP() < target->getHP()) {
target = enemy;
}
}
return std::make_shared<BasicAttackAction>(actor, target); // Creating an object using attacker, defender
// BasicAttackAction derived from the Action
}
std::string AggressiveAI::getAIType() const {
return "Aggressive";
}