Now have the basics of the turn based battle engine with AI rebellion working.

This commit is contained in:
Zed A. Shaw 2025-12-01 00:14:08 -05:00
parent f3b20f30c5
commit c78b2ae75e
8 changed files with 114 additions and 73 deletions

View file

@ -51,34 +51,51 @@ namespace boss {
auto& level = GameDB::current_level();
dbc::check(world->has<ai::EntityAI>(boss_id), "boss doesn't have an AI");
auto host_start = ai::load_state("Host::initial_state");
auto host_goal = ai::load_state("Host::final_state");
ai::EntityAI host_ai("Host::actions", host_start, host_goal);
auto& player_combat = world->get<Combat>(level.player);
auto& boss_combat = world->get<Combat>(boss_id);
auto& boss_ai = world->get<ai::EntityAI>(boss_id);
combat::BattleEngine battle;
battle.add_enemy({boss_id, &boss_ai, &boss_combat});
battle.add_enemy({level.player, &host_ai, &player_combat});
battle.set_all("enemy_found", true);
battle.set_all("in_combat", true);
battle.set(boss_id, "tough_personality", true);
battle.set(level.player, "tough_personality", false);
battle.set(level.player, "have_healing", false);
battle.set(level.player, "health_good", player_combat.hp > 20);
battle.player_request("kill_enemy");
battle.plan();
while(auto act = battle.next()) {
auto [enemy, ai_action, enemy_action] = *act;
auto [enemy, wants_to, cost, host_state] = *act;
Events::Combat result{};
Events::Combat result {
player_combat.attack(*enemy.combat), 0
};
switch(host_state) {
case combat::BattleHostState::agree:
result.player_did = player_combat.attack(*enemy.combat);
break;
case combat::BattleHostState::disagree:
fmt::println("HOST DISAGREES! {}", wants_to);
break;
case combat::BattleHostState::not_host:
if(wants_to == "kill_enemy") {
result.enemy_did = enemy.combat->attack(player_combat);
}
}
if(result.player_did > 0) {
auto& the_belt = world->get_the<ritual::Belt>();
dbc::check(the_belt.has(attack_id), "STOP passing invalid attack IDs to the system.");
}
if(enemy_action == combat::BattleAction::ATTACK) {
result.enemy_did = enemy.combat->attack(player_combat);
}
// need to replicate this in the boss UI
world->send<Events::GUI>(Events::GUI::COMBAT, enemy.entity, result);
}