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

@ -70,6 +70,8 @@ namespace boss {
$ui.status(L"PLAYER TURN");
state(State::PLAYER_TURN);
break;
case TICK:
break; // ignore tick
default:
fmt::println("BOSS_FIGHT:START unknown event {}", (int)ev);
break;
@ -98,9 +100,11 @@ namespace boss {
$ui.update_stats();
state(State::PLAYER_TURN);
} break;
case TICK:
break; // ignore tick
default:
fmt::println("BOSS_FIGHT:BOSS_TURN unknown event {}", (int)ev);
break;
// skip it
}
}
@ -124,8 +128,10 @@ namespace boss {
boss::System::combat($world, $boss_id, attack_id);
state(State::BOSS_TURN);
} break;
case TICK:
break; // ignore tick
default:
// skip it
fmt::println("BOSS_FIGHT:PLAYER_TURN unknown event {}", (int)ev);
break;
}
}

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);
}

View file

@ -72,11 +72,11 @@ namespace boss {
}
if(result.player_did > 0) {
zoom(boss_is.cell);
zoom("boss14", 1.8);
} else if(result.enemy_did > 0) {
zoom(player_is.cell);
zoom(player_is.cell, 2.0);
} else {
zoom("");
zoom("", 0.0);
}
}
@ -115,14 +115,14 @@ namespace boss {
$arena.play_animations();
}
void UI::zoom(const std::string &cell_name) {
void UI::zoom(const std::string &cell_name, double ratio) {
if(cell_name == "") {
dbc::log("!!!!!!!!! you should add this to guecs");
$camera.reset($view_texture, BOSS_VIEW_WIDTH, BOSS_VIEW_HEIGHT);
} else {
auto& cell = $arena.$ui.cell_for(cell_name);
$camera.resize(BOSS_VIEW_WIDTH/2, BOSS_VIEW_HEIGHT/2);
$camera.resize(double(BOSS_VIEW_WIDTH)/ratio, double(BOSS_VIEW_HEIGHT)/ratio);
$camera.move(float(cell.mid_x), float(cell.mid_y));
$camera.play();
}

View file

@ -38,6 +38,6 @@ namespace boss {
void animate_actor(const std::string& actor);
void update_stats();
void play_animations();
void zoom(const std::string &cell);
void zoom(const std::string &cell, double ratio);
};
}