From f50e7131799b6d3aa8cce88d34bc8aeff6181656 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Tue, 23 Dec 2025 00:11:31 -0500 Subject: [PATCH] Now have enough state to show what's going on in the fight, next is to use graphics and stuff to make it better. --- battle.cpp | 5 ++--- boss/fight.cpp | 26 ++++++++++++++++++-------- boss/system.cpp | 10 +++++++++- boss/ui.cpp | 9 +++++++-- components.hpp | 6 ++++++ meson.build | 1 + scene.cpp | 6 +++++- scene.hpp | 1 + systems.cpp | 7 ++++++- 9 files changed, 55 insertions(+), 16 deletions(-) diff --git a/battle.cpp b/battle.cpp index 91ca347..a4fc824 100644 --- a/battle.cpp +++ b/battle.cpp @@ -74,11 +74,10 @@ namespace combat { host_state = $player_requests.contains(action.name) ? agree : disagree; } - if(host_state == out_of_ap) { - break; - } else { + if(host_state != out_of_ap) { enemy.combat->ap -= action.cost; } + $pending_actions.emplace_back(enemy, action.name, action.cost, host_state); } diff --git a/boss/fight.cpp b/boss/fight.cpp index a11f28e..1944f07 100644 --- a/boss/fight.cpp +++ b/boss/fight.cpp @@ -116,19 +116,29 @@ namespace boss { } void Fight::do_combat(std::any data) { + using combat::BattleHostState; + dbc::check(data.type() == typeid(components::CombatResult), - fmt::format("Boss Fight received any data={}", data.type().name())); + fmt::format("Boss Fight wrong any data={}", data.type().name())); auto result = std::any_cast(data); - $ui.zoom("", 1.0); - std::string boss_move = Random::uniform(0, 1) == 0 ? "boss5" : "boss6"; - std::string player_move = Random::uniform(0, 1) == 0 ? "player1" : "player3"; - $ui.move_actor("player", player_move); - $ui.move_actor("boss", boss_move); + switch(result.host_state) { + case BattleHostState::agree: + case BattleHostState::disagree: { + std::string player_move = Random::uniform(0, 1) == 0 ? "player1" : "player3"; + $ui.move_actor("player", player_move); + $ui.damage("boss", result.player_did); + } break; + case BattleHostState::not_host: { + std::string boss_move = Random::uniform(0, 1) == 0 ? "boss5" : "boss6"; + $ui.move_actor("boss", boss_move); + $ui.damage("player", result.enemy_did); + } break; + case BattleHostState::out_of_ap: + break; + } - $ui.damage("player", result.enemy_did); - $ui.damage("boss", result.player_did); } void Fight::END(game::Event ev, std::any) { diff --git a/boss/system.cpp b/boss/system.cpp index c80b45e..2e2efea 100644 --- a/boss/system.cpp +++ b/boss/system.cpp @@ -94,13 +94,21 @@ namespace boss { void System::combat(BattleResult& action, std::shared_ptr world, DinkyECS::Entity boss_id, int attack_id) { + fmt::println("COMBAT >>> enemy={}, wants_to={}, cost={}, host_state={}", + int(action.enemy.entity), action.wants_to, action.cost, int(action.host_state)); + auto& level = GameDB::current_level(); auto& player_combat = world->get(level.player); auto& boss_combat = world->get(boss_id); auto& [enemy, wants_to, cost, host_state] = action; - components::CombatResult result{}; + components::CombatResult result { + .attacker=enemy.entity, + .host_state=host_state, + .player_did=0, + .enemy_did=0 + }; switch(host_state) { case BattleHostState::agree: diff --git a/boss/ui.cpp b/boss/ui.cpp index 8ecffef..9e423ad 100644 --- a/boss/ui.cpp +++ b/boss/ui.cpp @@ -105,11 +105,16 @@ namespace boss { } void UI::damage(const std::string& actor, int amount) { + auto& config = $arena.actor_config(actor); + if(amount == 0) { - $arena.$ui.show_text("boss7", fmt::format(L"{} MISSED!", guecs::to_wstring(actor))); + $arena.$ui.show_text(config.cell, + fmt::format(L"{} MISSED!", guecs::to_wstring(actor))); } else { - $arena.$ui.show_text("boss7", fmt::format(L"{} HIT {}!", guecs::to_wstring(actor), amount)); + $arena.$ui.show_text(config.cell, + fmt::format(L"{} HIT {}!", guecs::to_wstring(actor), amount)); } + } void UI::zoom(const std::string &cell_name, double ratio) { diff --git a/components.hpp b/components.hpp index e40fb0a..f008cdf 100644 --- a/components.hpp +++ b/components.hpp @@ -14,11 +14,17 @@ #include "json_mods.hpp" #include "goap.hpp" +namespace combat { + enum class BattleHostState; +} + namespace components { using std::string; using namespace nlohmann; struct CombatResult { + DinkyECS::Entity attacker; + combat::BattleHostState host_state; int player_did = 0; int enemy_did = 0; }; diff --git a/meson.build b/meson.build index 966e509..5f04b44 100644 --- a/meson.build +++ b/meson.build @@ -25,6 +25,7 @@ if build_machine.system() == 'windows' '-static-libgcc', '-static-libstdc++', '-static', + '-flto', language: 'cpp', ) diff --git a/scene.cpp b/scene.cpp index 2028773..c602393 100644 --- a/scene.cpp +++ b/scene.cpp @@ -86,8 +86,12 @@ namespace scene { if(DEBUG) $ui.debug_layout(window); } + Element& Engine::actor_config(const std::string& actor) { + return $actors.at($actor_name_ids.at(actor)); + } + void Engine::move_actor(const std::string& actor, const std::string& cell_name) { - auto& config = $actors.at($actor_name_ids.at(actor)); + auto& config = actor_config(actor); config.cell = cell_name; config.pos = position_sprite(config.st, config.cell, config.scale_x, config.scale_y, config.at_mid); } diff --git a/scene.hpp b/scene.hpp index e27fdaf..e1a010a 100644 --- a/scene.hpp +++ b/scene.hpp @@ -43,5 +43,6 @@ namespace scene { void move_actor(const std::string& actor, const std::string& cell_name); void animate_actor(const std::string& actor); void play_animations(); + Element& actor_config(const std::string& actor); }; } diff --git a/systems.cpp b/systems.cpp index f6820e2..68be91d 100644 --- a/systems.cpp +++ b/systems.cpp @@ -262,10 +262,15 @@ void System::combat(int attack_id) { while(auto act = battle.next()) { auto [enemy, enemy_action, cost, host_state] = *act; + + // player shouldn't hit theirself if(host_state != BattleHostState::not_host) continue; components::CombatResult result { - player_combat.attack(*enemy.combat), 0 + .attacker=enemy.entity, + .host_state=host_state, + .player_did=player_combat.attack(*enemy.combat), + .enemy_did=0 }; if(result.player_did > 0) {