[BREAKING] Battle system now runs the turn based combat better, and lots of interesting things like if you don't choose an action the host AI rebels and does it for you.

This commit is contained in:
Zed A. Shaw 2025-12-11 13:49:53 -05:00
parent 9739441a9c
commit 986b2612d4
9 changed files with 100 additions and 32 deletions

View file

@ -4,27 +4,30 @@
namespace combat {
void BattleEngine::add_enemy(Combatant enemy) {
$combatants.try_emplace(enemy.entity, enemy);
if(enemy.is_host) {
dbc::check($host_combat == nullptr, "added the host twice!");
$host_combat = enemy.combat;
}
}
void BattleEngine::player_request(const std::string& request) {
$player_requests.emplace(request);
bool BattleEngine::player_request(const std::string& request) {
auto action = ai::load_action(request);
bool can_go = player_pending_ap() >= action.cost;
if(can_go) {
$player_requests.try_emplace(request, action);
}
return can_go;
}
void BattleEngine::clear_requests() {
$player_requests.clear();
}
bool BattleEngine::plan() {
dbc::check($player_requests.size() > 0, "Calling plan without any player reqeusts queued.");
using enum BattleHostState;
int active = 0;
bool had_host = false;
void BattleEngine::ap_refresh() {
for(auto& [entity, enemy] : $combatants) {
//NOTE: this is just for asserting I'm using things right
if(enemy.is_host) had_host = true;
if(enemy.combat->ap < enemy.combat->max_ap) {
int new_ap = std::min(enemy.combat->max_ap, enemy.combat->ap_delta + enemy.combat->ap);
@ -34,6 +37,29 @@ namespace combat {
enemy.combat->ap = new_ap;
}
}
}
int BattleEngine::player_pending_ap() {
dbc::check($host_combat != nullptr, "didn't set host before checking AP");
int pending_ap = $host_combat->ap;
for(auto& [name, action] : $player_requests) {
pending_ap -= action.cost;
}
return pending_ap;
}
bool BattleEngine::plan() {
using enum BattleHostState;
int active = 0;
bool had_host = false;
for(auto& [entity, enemy] : $combatants) {
//NOTE: this is just for asserting I'm using things right
if(enemy.is_host) had_host = true;
enemy.ai->update();
active += enemy.ai->active();