[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

@ -1,4 +1,3 @@
#define FSM_DEBUG 1
#include "boss/fight.hpp"
#include "boss/system.hpp"
#include "animation.hpp"
@ -9,7 +8,8 @@ namespace boss {
$boss_id(boss_id),
$battle(System::create_battle($world, $boss_id)),
$ui(world, boss_id, player_id),
$player_id(player_id)
$host(player_id),
$host_combat($world->get<components::Combat>(player_id))
{
$ui.init();
}
@ -31,8 +31,7 @@ namespace boss {
return in_state(State::END);
}
void Fight::START(gui::Event ev, std::any data) {
(void)data;
void Fight::START(gui::Event ev, std::any) {
using enum gui::Event;
switch(ev) {
@ -42,6 +41,7 @@ namespace boss {
break;
case TICK:
$ui.status(L"PLAYER REQUESTS");
$battle.ap_refresh();
state(State::PLAYER_REQUESTS);
break;
default:
@ -58,8 +58,18 @@ namespace boss {
state(State::END);
break;
case START_COMBAT:
System::plan_battle($battle, $world, $boss_id);
$ui.status(L"PLANNING BATTLE");
state(State::PLAN_BATTLE);
break;
case ATTACK:
if($battle.player_request("kill_enemy")) {
fmt::println("player requests kill_enemy {} vs. {}",
$host_combat.ap, $battle.player_pending_ap());
} else {
fmt::println("NO MORE ACTION!");
}
break;
case TICK:
break; // ignore tick
default:
@ -77,6 +87,10 @@ namespace boss {
break;
case START_COMBAT:
$ui.status(L"EXEC PLAN");
while(auto action = $battle.next()) {
System::combat(*action, $world, $boss_id, 0);
run_systems();
}
state(State::EXEC_PLAN);
break;
case TICK:
@ -100,6 +114,8 @@ namespace boss {
state(State::END);
} else {
$ui.status(L"PLAYER REQUESTS");
$battle.ap_refresh();
$battle.clear_requests();
state(State::PLAYER_REQUESTS);
}
break; // ignore tick
@ -113,7 +129,10 @@ namespace boss {
}
void Fight::run_systems() {
run++;
$ui.update_stats();
$battle.set($host, "tough_personality", false);
$battle.set($host, "have_healing", false);
$battle.set($host, "health_good", $host_combat.hp > 20);
}
void Fight::render(sf::RenderWindow& window) {
@ -150,7 +169,11 @@ namespace boss {
}
bool Fight::player_dead() {
auto& combat = $world->get<components::Combat>($player_id);
return combat.hp <= 0;
return $host_combat.hp <= 0;
}
void Fight::init_fight() {
System::initialize_actor_ai(*$world, $boss_id);
run_systems();
}
}