Initial battle engine is now integrated in the systems so now I can finally get the turn based combat to work the way I envision.

This commit is contained in:
Zed A. Shaw 2025-04-06 00:45:51 -04:00
parent e18aeaf05c
commit 1f90367f51
10 changed files with 80 additions and 81 deletions

View file

@ -12,6 +12,7 @@
#include "ai.hpp"
#include "ai_debug.hpp"
#include "shiterator.hpp"
#include "rituals.hpp"
#include <iostream>
using std::string;
@ -210,29 +211,31 @@ void System::combat(GameLevel &level) {
// this is guaranteed to not return the given position
auto [found, nearby] = collider.neighbors(player_position.location);
combat::BattleEngine battle;
if(found) {
for(auto entity : nearby) {
if(world.has<ai::EntityAI>(entity)) {
auto& enemy_ai = world.get<ai::EntityAI>(entity);
auto& enemy_combat = world.get<Combat>(entity);
Events::Combat result {
player_combat.attack(enemy_combat), 0
};
enemy_ai.set_state("enemy_found", true);
enemy_ai.set_state("in_combat", true);
enemy_ai.update();
if(enemy_ai.wants_to("kill_enemy")) {
result.enemy_did = enemy_combat.attack(player_combat);
animate_entity(world, entity);
}
world.send<Events::GUI>(Events::GUI::COMBAT, entity, result);
battle.add_enemy({entity, enemy_ai, enemy_combat});
}
}
battle.plan();
}
while(auto enemy = battle.next()) {
Events::Combat result {
player_combat.attack(enemy->combat), 0
};
if(enemy->ai.wants_to("kill_enemy")) {
result.enemy_did = enemy->combat.attack(player_combat);
animate_entity(world, enemy->entity);
}
world.send<Events::GUI>(Events::GUI::COMBAT, enemy->entity, result);
}
}