Fixed some things but now the world and boss fight worlds are out of sync and need to be fixed. tools/arena is broken.

This commit is contained in:
Zed A. Shaw 2025-12-13 13:13:59 -05:00
parent 37b007d79c
commit bf8ce7e16b
6 changed files with 48 additions and 21 deletions

View file

@ -1,6 +1,7 @@
#include "boss/fight.hpp" #include "boss/fight.hpp"
#include "boss/system.hpp" #include "boss/system.hpp"
#include "animation.hpp" #include "animation.hpp"
#include "game_level.hpp"
namespace boss { namespace boss {
Fight::Fight(shared_ptr<World> world, Entity boss_id, Entity player_id) : Fight::Fight(shared_ptr<World> world, Entity boss_id, Entity player_id) :
@ -87,10 +88,6 @@ namespace boss {
break; break;
case START_COMBAT: case START_COMBAT:
$ui.status(L"EXEC PLAN"); $ui.status(L"EXEC PLAN");
while(auto action = $battle.next()) {
System::combat(*action, $world, $boss_id, 0);
run_systems();
}
state(State::EXEC_PLAN); state(State::EXEC_PLAN);
break; break;
case TICK: case TICK:
@ -109,6 +106,15 @@ namespace boss {
state(State::END); state(State::END);
break; break;
case TICK: 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()) { if(player_dead()) {
$ui.status(L"YOU DIED"); $ui.status(L"YOU DIED");
state(State::END); state(State::END);
@ -132,7 +138,7 @@ namespace boss {
$ui.update_stats(); $ui.update_stats();
$battle.set($host, "tough_personality", false); $battle.set($host, "tough_personality", false);
$battle.set($host, "have_healing", 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) { void Fight::render(sf::RenderWindow& window) {
@ -176,4 +182,33 @@ namespace boss {
System::initialize_actor_ai(*$world, $boss_id); System::initialize_actor_ai(*$world, $boss_id);
run_systems(); run_systems();
} }
void Fight::handle_world_events() {
fmt::println(">>>>>>>>>>>>>>>>> BOSS FIGHT EVENTS");
dbc::check($world->has_event<Events::GUI>(), "World doesn't have GUI events.");
while($world->has_event<Events::GUI>()) {
auto [evt, entity, data] = $world->recv<Events::GUI>();
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<Events::GUI>(), "World still has events!");
fmt::println("<<<<<<<<<<<<<<<< BOSS FIGHT EVENTS");
}
} }

View file

@ -42,6 +42,7 @@ namespace boss {
void END(gui::Event ev, std::any data); void END(gui::Event ev, std::any data);
void render(sf::RenderWindow& window); void render(sf::RenderWindow& window);
void handle_world_events();
void run_systems(); void run_systems();
bool player_dead(); bool player_dead();
void init_fight(); void init_fight();

View file

@ -20,7 +20,6 @@ namespace GameDB {
using std::shared_ptr, std::string, std::make_shared; using std::shared_ptr, std::string, std::make_shared;
struct LevelDB { struct LevelDB {
public:
std::vector<GameDB::Level> levels; std::vector<GameDB::Level> levels;
size_t current_level = 0; size_t current_level = 0;
}; };

View file

@ -29,6 +29,7 @@ namespace gui {
MOUSE_DRAG_START=24, MOUSE_DRAG_START=24,
MOUSE_DROP=25, MOUSE_DROP=25,
KEY_PRESS=26, KEY_PRESS=26,
AIM_CLICK=27 AIM_CLICK=27,
COMBAT=28
}; };
} }

View file

@ -107,7 +107,7 @@ TEST_CASE("boss/systems.cpp works", "[combat-battle]") {
animation::init(); animation::init();
GameDB::init(); GameDB::init();
cinematic::init(); cinematic::init();
auto host = GameDB::current_level().player; auto host = GameDB::the_player();
auto fight = System::create_bossfight(); auto fight = System::create_bossfight();
auto battle = System::create_battle(fight->$world, fight->$boss_id); auto battle = System::create_battle(fight->$world, fight->$boss_id);

View file

@ -47,6 +47,7 @@ int main(int, char*[]) {
auto main = boss::System::create_bossfight(); auto main = boss::System::create_bossfight();
auto world = GameDB::current_world(); 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)) { while(!main->in_state(boss::State::END)) {
main->mouse_pos = window.mapPixelToCoords(router.position); main->mouse_pos = window.mapPixelToCoords(router.position);
@ -61,19 +62,9 @@ int main(int, char*[]) {
} }
} }
while(world->has_event<Events::GUI>()) { if(main->$world->has_event<Events::GUI>()) {
auto [evt, entity, data] = world->recv<Events::GUI>(); main->handle_world_events();
dbc::check(!main->$world->has_event<Events::GUI>(), "You didn't eat all the events.");
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);
}
} }
main->render(window); main->render(window);