diff --git a/assets/bosses.json b/assets/bosses.json index 5a8fa5a..7e31746 100644 --- a/assets/bosses.json +++ b/assets/bosses.json @@ -62,7 +62,7 @@ } ] }, - {"_type": "Combat", "hp": 200, "max_hp": 200, "damage": 20, "dead": false}, + {"_type": "Combat", "hp": 200, "max_hp": 200, "ap": 0, "ap_delta": 9, "max_ap": 20, "damage": 20, "dead": false}, {"_type": "Sound", "attack": "Marmot_Scream_1", "death": "Creature_Death_1"}, {"_type": "EnemyConfig", "ai_script": "Enemy::actions", "ai_start_name": "Enemy::initial_state", "ai_goal_name": "Enemy::final_state"} ] diff --git a/assets/enemies.json b/assets/enemies.json index b9f7c83..f09909d 100644 --- a/assets/enemies.json +++ b/assets/enemies.json @@ -6,7 +6,7 @@ "foreground": "enemies/fg:player", "background": "color:transparent" }, - {"_type": "Combat", "hp": 200, "max_hp": 200, "damage": 10, "dead": false}, + {"_type": "Combat", "hp": 200, "max_hp": 200, "ap": 0, "max_ap": 12, "ap_delta": 6, "damage": 10, "dead": false}, {"_type": "Motion", "dx": 0, "dy": 0, "random": false}, {"_type": "Collision", "has": true}, {"_type": "LightSource", "strength": 35, "radius": 2.0} @@ -18,7 +18,7 @@ "foreground": "enemies/fg:gold_savior", "background": "color:transparent" }, - {"_type": "Combat", "hp": 20, "max_hp": 20, "damage": 1, "dead": false}, + {"_type": "Combat", "hp": 20, "max_hp": 20, "ap": 0, "max_ap": 12, "ap_delta": 6, "damage": 1, "dead": false}, {"_type": "Collision", "has": true}, {"_type": "Motion", "dx": 0, "dy": 0, "random": false}, {"_type": "EnemyConfig", "ai_script": "Enemy::actions", "ai_start_name": "Enemy::initial_state", "ai_goal_name": "Enemy::final_state"}, @@ -33,7 +33,7 @@ "foreground": "enemies/fg:knight", "background": "color:transparent" }, - {"_type": "Combat", "hp": 20, "max_hp": 20, "damage": 1, "dead": false}, + {"_type": "Combat", "hp": 20, "max_hp": 20, "ap": 0, "max_ap": 12, "ap_delta": 6,"damage": 1, "dead": false}, {"_type": "Collision", "has": true}, {"_type": "Motion", "dx": 0, "dy": 0, "random": false}, {"_type": "EnemyConfig", "ai_script": "Enemy::actions", "ai_start_name": "Enemy::initial_state", "ai_goal_name": "Enemy::final_state"}, @@ -48,7 +48,7 @@ "foreground": "enemies/fg:axe_ranger", "background": "color:transparent" }, - {"_type": "Combat", "hp": 40, "max_hp": 40, "damage": 10, "dead": false}, + {"_type": "Combat", "hp": 40, "max_hp": 40, "ap": 0, "max_ap": 12, "ap_delta": 6,"damage": 10, "dead": false}, {"_type": "Collision", "has": true}, {"_type": "Motion", "dx": 0, "dy": 0, "random": true}, {"_type": "EnemyConfig", "ai_script": "Enemy::actions", "ai_start_name": "Enemy::initial_state", "ai_goal_name": "Enemy::final_state"}, @@ -63,7 +63,7 @@ "foreground": "enemies/fg:rat_giant", "background": "color:transparent" }, - {"_type": "Combat", "hp": 50, "max_hp": 50, "damage": 2, "dead": false}, + {"_type": "Combat", "hp": 50, "max_hp": 50, "ap": 0, "max_ap": 12, "ap_delta": 6,"damage": 2, "dead": false}, {"_type": "Collision", "has": true}, {"_type": "Motion", "dx": 0, "dy": 0, "random": false}, {"_type": "EnemyConfig", "ai_script": "Enemy::actions", "ai_start_name": "Enemy::initial_state", "ai_goal_name": "Enemy::final_state"}, @@ -78,7 +78,7 @@ "foreground": "enemies/fg:spider_giant", "background": "color:transparent" }, - {"_type": "Combat", "hp": 20, "max_hp": 20, "damage": 20, "dead": false}, + {"_type": "Combat", "hp": 20, "max_hp": 20, "ap": 0, "max_ap": 12, "ap_delta": 6,"damage": 20, "dead": false}, {"_type": "Collision", "has": true}, {"_type": "Motion", "dx": 0, "dy": 0, "random": false}, {"_type": "EnemyConfig", "ai_script": "Enemy::actions", "ai_start_name": "Enemy::initial_state", "ai_goal_name": "Enemy::final_state"}, diff --git a/battle.cpp b/battle.cpp index 8b36d90..b851b8b 100644 --- a/battle.cpp +++ b/battle.cpp @@ -16,7 +16,16 @@ namespace combat { int active = 0; + fmt::println("---------- start combatants"); for(auto& [entity, enemy] : $combatants) { + if(enemy.combat->ap < enemy.combat->max_ap) { + // only add up to the max + enemy.combat->ap = std::min(enemy.combat->max_ap, enemy.combat->ap_delta + enemy.combat->ap); + } + + fmt::println("--- enemy {} has {} ap", entity, enemy.combat->ap); + // reset action points + enemy.ai->update(); active += enemy.ai->active(); @@ -24,15 +33,38 @@ namespace combat { for(auto& action : enemy.ai->plan.script) { BattleHostState host_state = not_host; - if(enemy.is_host) { + if(action.cost > enemy.combat->ap) { + host_state = out_of_ap; + } else if(enemy.is_host) { host_state = $player_requests.contains(action.name) ? agree : disagree; } + if(host_state == out_of_ap) { + fmt::println("--- enemy CANNOT go: {}-{}={}", + enemy.combat->ap, action.cost, + enemy.combat->ap - action.cost); + break; + } else { + fmt::println("--- enemy can go, {}-{}={}", + enemy.combat->ap, action.cost, + enemy.combat->ap - action.cost); + + enemy.combat->ap -= action.cost; + } + + fmt::println("--- active enemy {} ap={}, host_state={}", + entity, enemy.combat->ap, int(host_state)); + $pending_actions.emplace_back(enemy, action.name, action.cost, host_state); } + + dbc::check(enemy.combat->ap >= 0, "enemy's AP went below 0"); + dbc::check(enemy.combat->ap <= enemy.combat->max_ap, "enemy's AP went above max"); } } + fmt::print("<---- end of enemy setup, sorting"); + if($pending_actions.size() > 0) { std::sort($pending_actions.begin(), $pending_actions.end(), [](const auto& a, const auto& b) -> bool diff --git a/battle.hpp b/battle.hpp index eaa6937..779aebc 100644 --- a/battle.hpp +++ b/battle.hpp @@ -11,7 +11,8 @@ namespace combat { enum class BattleHostState { not_host = 0, agree = 1, - disagree = 2 + disagree = 2, + out_of_ap = 3 }; struct Combatant { diff --git a/boss/system.cpp b/boss/system.cpp index 0f82a9f..6e4be5d 100644 --- a/boss/system.cpp +++ b/boss/system.cpp @@ -89,6 +89,10 @@ namespace boss { if(wants_to == "kill_enemy") { result.enemy_did = enemy.combat->attack(player_combat); } + break; + case combat::BattleHostState::out_of_ap: + fmt::println("OUT OF AP {}", wants_to); + break; } if(result.player_did > 0) { diff --git a/components.hpp b/components.hpp index 3a2c0f9..039ecac 100644 --- a/components.hpp +++ b/components.hpp @@ -102,6 +102,11 @@ namespace components { int hp; int max_hp; int damage; + int ap_delta; + int max_ap; + + // everyone starts at 0 but ap_delta is added each round + int ap = 0; /* NOTE: This is used to _mark_ entities as dead, to detect ones that have just died. Don't make attack automatically set it.*/ bool dead = false; @@ -176,7 +181,7 @@ namespace components { ENROLL_COMPONENT(EnemyConfig, ai_script, ai_start_name, ai_goal_name); ENROLL_COMPONENT(Personality, hearing_distance, tough); ENROLL_COMPONENT(Motion, dx, dy, random); - ENROLL_COMPONENT(Combat, hp, max_hp, damage, dead); + ENROLL_COMPONENT(Combat, hp, max_hp, damage, ap_delta, max_ap, dead); ENROLL_COMPONENT(Device, config, events); ENROLL_COMPONENT(Storyboard, image, audio, layout, beats); ENROLL_COMPONENT(Animation, min_x, min_y, diff --git a/systems.cpp b/systems.cpp index 170b7a3..a35cb25 100644 --- a/systems.cpp +++ b/systems.cpp @@ -250,6 +250,7 @@ void System::combat(int attack_id) { battle.set_all("enemy_found", true); battle.set_all("in_combat", true); + battle.player_request("kill_enemy"); battle.plan(); } diff --git a/tests/battle.cpp b/tests/battle.cpp index d8f51b7..899c95b 100644 --- a/tests/battle.cpp +++ b/tests/battle.cpp @@ -20,17 +20,17 @@ TEST_CASE("battle operations fantasy", "[combat-battle]") { DinkyECS::Entity host = 0; ai::EntityAI host_ai("Host::actions", host_start, host_goal); - components::Combat host_combat{100, 100, 20}; + components::Combat host_combat{100, 100, 20, 6, 12}; battle.add_enemy({host, &host_ai, &host_combat, true}); DinkyECS::Entity axe_ranger = 1; ai::EntityAI axe_ai("Enemy::actions", ai_start, ai_goal); - components::Combat axe_combat{100, 100, 20}; + components::Combat axe_combat{100, 100, 20, 8, 12}; battle.add_enemy({axe_ranger, &axe_ai, &axe_combat}); DinkyECS::Entity rat = 2; ai::EntityAI rat_ai("Enemy::actions", ai_start, ai_goal); - components::Combat rat_combat{10, 10, 2}; + components::Combat rat_combat{10, 10, 2, 12, 18}; battle.add_enemy({rat, &rat_ai, &rat_combat}); battle.set_all("enemy_found", true); @@ -42,7 +42,6 @@ TEST_CASE("battle operations fantasy", "[combat-battle]") { battle.set(host, "have_healing", false); battle.set(host, "tough_personality", false); - while(host_combat.hp > 0) { battle.set(host, "health_good", host_combat.hp > 20); @@ -52,14 +51,14 @@ TEST_CASE("battle operations fantasy", "[combat-battle]") { battle.plan(); while(auto act = battle.next()) { - auto& [enemy, wants_to, cost, host_behavior] = *act; + auto& [enemy, wants_to, cost, enemy_state] = *act; - fmt::println(">>>>> entity: {} wants to {} cost={} and has {} HP and {} damage", + fmt::println(">>>>> entity: {} wants to {} cost={}; has {} HP; {} ap", enemy.entity, wants_to, cost, enemy.combat->hp, - enemy.combat->damage); + enemy.combat->ap); - switch(host_behavior) { + switch(enemy_state) { case BattleHostState::agree: fmt::println("HOST and PLAYER requests match {}, doing it.", wants_to); @@ -72,6 +71,10 @@ TEST_CASE("battle operations fantasy", "[combat-battle]") { if(wants_to == "kill_enemy") { enemy.combat->attack(host_combat); } + break; + case BattleHostState::out_of_ap: + fmt::println("ENEMY OUT OF AP"); + break; } fmt::println("<<<<<<<<<<<<<<<<");