Exploring raycasters and possibly make a little "doom like" game based on it.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
raycaster/battle.cpp

39 lines
931 B

#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();
}
}
}