Rework the source so that battle is in its own thing to work on.
This commit is contained in:
parent
e6a8a8b338
commit
ca328e10dc
7 changed files with 69 additions and 57 deletions
39
battle.cpp
Normal file
39
battle.cpp
Normal file
|
@ -0,0 +1,39 @@
|
|||
#include "rituals.hpp"
|
||||
#include "battle.hpp"
|
||||
|
||||
namespace combat {
|
||||
void BattleEngine::add_enemy(BattleAction enemy) {
|
||||
combatants.try_emplace(enemy.entity, enemy);
|
||||
}
|
||||
|
||||
bool BattleEngine::plan() {
|
||||
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);
|
||||
}
|
||||
|
||||
return active > 0;
|
||||
}
|
||||
|
||||
std::optional<BattleAction> BattleEngine::next() {
|
||||
if(pending_actions.size() == 0) return std::nullopt;
|
||||
|
||||
auto ba = pending_actions.back();
|
||||
pending_actions.pop_back();
|
||||
return std::make_optional(ba);
|
||||
}
|
||||
|
||||
void BattleEngine::dump() {
|
||||
for(auto& [entity, enemy] : combatants) {
|
||||
fmt::println("\n\n###### ENTITY #{}", entity);
|
||||
enemy.ai.dump();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue