From bf8ce7e16bed9e107fef6e3628cc46c4155fdcdf Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Sat, 13 Dec 2025 13:13:59 -0500 Subject: [PATCH] Fixed some things but now the world and boss fight worlds are out of sync and need to be fixed. tools/arena is broken. --- boss/fight.cpp | 45 ++++++++++++++++++++++++++++++++++++++++----- boss/fight.hpp | 1 + game_level.cpp | 1 - gui/fsm_events.hpp | 3 ++- tests/battle.cpp | 2 +- tools/arena.cpp | 17 ++++------------- 6 files changed, 48 insertions(+), 21 deletions(-) diff --git a/boss/fight.cpp b/boss/fight.cpp index 9f10cfc..a137e28 100644 --- a/boss/fight.cpp +++ b/boss/fight.cpp @@ -1,6 +1,7 @@ #include "boss/fight.hpp" #include "boss/system.hpp" #include "animation.hpp" +#include "game_level.hpp" namespace boss { Fight::Fight(shared_ptr world, Entity boss_id, Entity player_id) : @@ -87,10 +88,6 @@ 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: @@ -109,6 +106,15 @@ namespace boss { state(State::END); break; case TICK: + case COMBAT: + if(auto action = $battle.next()) { + fmt::println("COMBAT!"); + System::combat(*action, $world, $boss_id, 0); + run_systems(); + } else { + fmt::println("NO MORE BATTLE ACTIONS!"); + } + if(player_dead()) { $ui.status(L"YOU DIED"); state(State::END); @@ -132,7 +138,7 @@ namespace boss { $ui.update_stats(); $battle.set($host, "tough_personality", false); $battle.set($host, "have_healing", false); - $battle.set($host, "health_good", $host_combat.hp > 20); + $battle.set($host, "health_good", $host_combat.hp > 100); } void Fight::render(sf::RenderWindow& window) { @@ -176,4 +182,33 @@ namespace boss { System::initialize_actor_ai(*$world, $boss_id); run_systems(); } + + void Fight::handle_world_events() { + fmt::println(">>>>>>>>>>>>>>>>> BOSS FIGHT EVENTS"); + dbc::check($world->has_event(), "World doesn't have GUI events."); + + while($world->has_event()) { + auto [evt, entity, data] = $world->recv(); + fmt::println("boss fight received event", int(evt)); + + switch(evt) { + case Events::GUI::ATTACK: + fmt::println("sending attack"); + event(gui::Event::ATTACK, data); + break; + case Events::GUI::COMBAT_START: + fmt::println("sending combat start"); + event(gui::Event::START_COMBAT, data); + break; + case Events::GUI::COMBAT: + fmt::println("sending combat"); + event(gui::Event::COMBAT, data); + break; + default: + fmt::println("GUI EVENT: {} entity={}", int(evt), entity); + } + } + dbc::check(!$world->has_event(), "World still has events!"); + fmt::println("<<<<<<<<<<<<<<<< BOSS FIGHT EVENTS"); + } } diff --git a/boss/fight.hpp b/boss/fight.hpp index b9867a0..244f760 100644 --- a/boss/fight.hpp +++ b/boss/fight.hpp @@ -42,6 +42,7 @@ namespace boss { void END(gui::Event ev, std::any data); void render(sf::RenderWindow& window); + void handle_world_events(); void run_systems(); bool player_dead(); void init_fight(); diff --git a/game_level.cpp b/game_level.cpp index 05a81b6..fd1ddb1 100644 --- a/game_level.cpp +++ b/game_level.cpp @@ -20,7 +20,6 @@ namespace GameDB { using std::shared_ptr, std::string, std::make_shared; struct LevelDB { - public: std::vector levels; size_t current_level = 0; }; diff --git a/gui/fsm_events.hpp b/gui/fsm_events.hpp index d451fd0..898624f 100644 --- a/gui/fsm_events.hpp +++ b/gui/fsm_events.hpp @@ -29,6 +29,7 @@ namespace gui { MOUSE_DRAG_START=24, MOUSE_DROP=25, KEY_PRESS=26, - AIM_CLICK=27 + AIM_CLICK=27, + COMBAT=28 }; } diff --git a/tests/battle.cpp b/tests/battle.cpp index 49cd873..5708cfe 100644 --- a/tests/battle.cpp +++ b/tests/battle.cpp @@ -107,7 +107,7 @@ TEST_CASE("boss/systems.cpp works", "[combat-battle]") { animation::init(); GameDB::init(); cinematic::init(); - auto host = GameDB::current_level().player; + auto host = GameDB::the_player(); auto fight = System::create_bossfight(); auto battle = System::create_battle(fight->$world, fight->$boss_id); diff --git a/tools/arena.cpp b/tools/arena.cpp index ff7ab15..af0c955 100644 --- a/tools/arena.cpp +++ b/tools/arena.cpp @@ -47,6 +47,7 @@ int main(int, char*[]) { auto main = boss::System::create_bossfight(); auto world = GameDB::current_world(); + dbc::check(main->$world == world, "GameDB::current_world doesn't match boss fight world."); while(!main->in_state(boss::State::END)) { main->mouse_pos = window.mapPixelToCoords(router.position); @@ -61,19 +62,9 @@ int main(int, char*[]) { } } - while(world->has_event()) { - auto [evt, entity, data] = world->recv(); - - switch(evt) { - case Events::GUI::ATTACK: - main->event(gui::Event::ATTACK, data); - break; - case Events::GUI::COMBAT_START: - main->event(gui::Event::START_COMBAT, data); - break; - default: - fmt::println("GUI EVENT: {} entity={}", int(evt), entity); - } + if(main->$world->has_event()) { + main->handle_world_events(); + dbc::check(!main->$world->has_event(), "You didn't eat all the events."); } main->render(window);