diff --git a/Makefile b/Makefile index 907b977..47b9365 100644 --- a/Makefile +++ b/Makefile @@ -37,7 +37,7 @@ tracy_build: meson compile -j 10 -C builddir test: build - ./builddir/runtests -d yes "[combat-battle]" + ./builddir/runtests -d yes run: build test ifeq '$(OS)' 'Windows_NT' @@ -60,7 +60,7 @@ clean: meson compile --clean -C builddir debug_test: build - gdb --nx -x .gdbinit --ex run --ex bt --ex q --args builddir/runtests -e "[combat-battle]" + gdb --nx -x .gdbinit --ex run --ex bt --ex q --args builddir/runtests -e win_installer: powershell 'start "C:\Program Files (x86)\solicus\InstallForge\bin\ifbuilderenvx86.exe" scripts\win_installer.ifp' diff --git a/assets/enemies.json b/assets/enemies.json index 9efbb78..10f8c6b 100644 --- a/assets/enemies.json +++ b/assets/enemies.json @@ -10,6 +10,7 @@ {"_type": "Motion", "dx": 0, "dy": 0, "random": false}, {"_type": "Collision", "has": true}, {"_type": "EnemyConfig", "ai_script": "Host::actions", "ai_start_name": "Host::initial_state", "ai_goal_name": "Host::final_state"}, + {"_type": "Personality", "hearing_distance": 5, "tough": false}, {"_type": "LightSource", "strength": 35, "radius": 2.0} ] }, diff --git a/battle.cpp b/battle.cpp index 5dcd599..659c07f 100644 --- a/battle.cpp +++ b/battle.cpp @@ -19,6 +19,9 @@ namespace combat { fmt::println("---------- start combatants"); for(auto& [entity, enemy] : $combatants) { + //NOTE: this is just for asserting I'm using things right + if(enemy.is_host) had_host = true; + if(enemy.combat->ap < enemy.combat->max_ap) { int new_ap = std::min(enemy.combat->max_ap, enemy.combat->ap_delta + enemy.combat->ap); @@ -29,17 +32,12 @@ namespace combat { enemy.combat->ap = new_ap; } - fmt::println("--- enemy {} has {} ap", entity, enemy.combat->ap); - // reset action points - enemy.ai->update(); active += enemy.ai->active(); if(enemy.ai->active()) { for(auto& action : enemy.ai->plan.script) { BattleHostState host_state = not_host; - //NOTE: this is just for asserting I'm using things right - if(enemy.is_host) had_host = true; if(action.cost > enemy.combat->ap) { host_state = out_of_ap; @@ -66,12 +64,12 @@ namespace combat { $pending_actions.emplace_back(enemy, action.name, action.cost, host_state); } - dbc::check(had_host, "FAIL, you forgot to set enemy.is_host=true for one entity"); 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"); } } + dbc::check(had_host, "FAIL, you forgot to set enemy.is_host=true for one entity"); fmt::println("<---- end of enemy setup, sorting"); if($pending_actions.size() > 0) { diff --git a/systems.cpp b/systems.cpp index a35cb25..7b7ff34 100644 --- a/systems.cpp +++ b/systems.cpp @@ -234,6 +234,7 @@ void System::combat(int attack_id) { auto& world = *level.world; const auto& player_pos = GameDB::player_position(); auto& player_combat = world.get(level.player); + auto& player_ai = world.get(level.player); // this is guaranteed to not return the given position auto [found, nearby] = collider.neighbors(player_pos.location); @@ -248,6 +249,7 @@ void System::combat(int attack_id) { } } + battle.add_enemy({level.player, &player_ai, &player_combat, true}); battle.set_all("enemy_found", true); battle.set_all("in_combat", true); battle.player_request("kill_enemy"); diff --git a/tests/battle.cpp b/tests/battle.cpp index e979e10..2d51319 100644 --- a/tests/battle.cpp +++ b/tests/battle.cpp @@ -79,8 +79,6 @@ TEST_CASE("battle operations fantasy", "[combat-battle]") { fmt::println("ENEMY OUT OF AP"); break; } - - fmt::println("<<<<<<<<<<<<<<<<"); } REQUIRE(!battle.next());