Added in a new art for a 'gold savior' and refined the battle engine more but it's not quite what I want.
This commit is contained in:
parent
ca328e10dc
commit
0e2f213871
7 changed files with 88 additions and 32 deletions
35
battle.cpp
35
battle.cpp
|
@ -2,7 +2,7 @@
|
|||
#include "battle.hpp"
|
||||
|
||||
namespace combat {
|
||||
void BattleEngine::add_enemy(BattleAction enemy) {
|
||||
void BattleEngine::add_enemy(Combatant enemy) {
|
||||
combatants.try_emplace(enemy.entity, enemy);
|
||||
}
|
||||
|
||||
|
@ -10,19 +10,22 @@ namespace combat {
|
|||
int active = 0;
|
||||
|
||||
for(auto& [entity, enemy] : combatants) {
|
||||
enemy.ai.set_state("enemy_found", true);
|
||||
enemy.ai.set_state("in_combat", true);
|
||||
enemy.ai.update();
|
||||
|
||||
active += enemy.ai.active();
|
||||
// yes, copy it out of the combatants list
|
||||
pending_actions.push_back(enemy);
|
||||
|
||||
if(enemy.ai.active()) {
|
||||
if(enemy.ai.wants_to("kill_enemy")) {
|
||||
pending_actions.emplace_back(enemy, BattleAction::ATTACK);
|
||||
} else if(enemy.ai.wants_to("run_away")) {
|
||||
pending_actions.emplace_back(enemy, BattleAction::ESCAPE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return active > 0;
|
||||
}
|
||||
|
||||
std::optional<BattleAction> BattleEngine::next() {
|
||||
std::optional<BattleResult> BattleEngine::next() {
|
||||
if(pending_actions.size() == 0) return std::nullopt;
|
||||
|
||||
auto ba = pending_actions.back();
|
||||
|
@ -36,4 +39,22 @@ namespace combat {
|
|||
enemy.ai.dump();
|
||||
}
|
||||
}
|
||||
|
||||
void BattleEngine::set(DinkyECS::Entity entity, std::string state, bool setting) {
|
||||
dbc::check(combatants.contains(entity), "invalid combatant given to BattleEngine");
|
||||
auto& action = combatants.at(entity);
|
||||
action.ai.set_state(state, setting);
|
||||
}
|
||||
|
||||
void BattleEngine::set_all(std::string state, bool setting) {
|
||||
for(auto& [ent, action] : combatants) {
|
||||
action.ai.set_state(state, setting);
|
||||
}
|
||||
}
|
||||
|
||||
void BattleEngine::queue(DinkyECS::Entity entity, BattleAction action) {
|
||||
dbc::check(combatants.contains(entity), "invalid combatant given to BattleEngine");
|
||||
auto& enemy = combatants.at(entity);
|
||||
pending_actions.emplace_back(enemy, action);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue