Now have the basics of the turn based battle engine with AI rebellion working.
This commit is contained in:
parent
f3b20f30c5
commit
c78b2ae75e
8 changed files with 114 additions and 73 deletions
|
|
@ -18,11 +18,10 @@ TEST_CASE("battle operations fantasy", "[combat-battle]") {
|
|||
auto host_goal = ai::load_state("Host::final_state");
|
||||
BattleEngine battle;
|
||||
|
||||
|
||||
DinkyECS::Entity host = 0;
|
||||
ai::EntityAI host_ai("Host::actions", host_start, host_goal);
|
||||
components::Combat host_combat{100, 100, 20};
|
||||
battle.add_enemy({host, &host_ai, &host_combat});
|
||||
battle.add_enemy({host, &host_ai, &host_combat, true});
|
||||
|
||||
DinkyECS::Entity axe_ranger = 1;
|
||||
ai::EntityAI axe_ai("Enemy::actions", ai_start, ai_goal);
|
||||
|
|
@ -40,39 +39,44 @@ TEST_CASE("battle operations fantasy", "[combat-battle]") {
|
|||
battle.set_all("health_good", true);
|
||||
|
||||
battle.set(rat, "tough_personality", false);
|
||||
|
||||
battle.set(host, "have_healing", false);
|
||||
battle.set(host, "health_good", false);
|
||||
battle.set(host, "tough_personality", false);
|
||||
|
||||
battle.plan();
|
||||
|
||||
std::set<std::string> requests{
|
||||
"use_healing",
|
||||
"kill_enemy"
|
||||
};
|
||||
while(host_combat.hp > 0) {
|
||||
battle.set(host, "health_good", host_combat.hp > 20);
|
||||
|
||||
while(auto act = battle.next()) {
|
||||
auto& [enemy, wants_to, action] = *act;
|
||||
battle.player_request("use_healing");
|
||||
battle.player_request("kill_enemy");
|
||||
|
||||
fmt::println(">>>>> entity: {} wants to {} cost={} and has {} HP and {} damage",
|
||||
enemy.entity, wants_to.name,
|
||||
wants_to.cost, enemy.combat->hp,
|
||||
enemy.combat->damage);
|
||||
battle.plan();
|
||||
|
||||
if(enemy.entity == host) {
|
||||
// negotiate between the player requested actions and the AI action
|
||||
if(requests.contains(wants_to.name)) {
|
||||
fmt::println("HOST and PLAYER requests match {}, doing it.",
|
||||
wants_to.name);
|
||||
requests.erase(wants_to.name);
|
||||
} else {
|
||||
fmt::println("REBELIOUS ACT: {}", wants_to.name);
|
||||
while(auto act = battle.next()) {
|
||||
auto& [enemy, wants_to, cost, host_behavior] = *act;
|
||||
|
||||
fmt::println(">>>>> entity: {} wants to {} cost={} and has {} HP and {} damage",
|
||||
enemy.entity, wants_to,
|
||||
cost, enemy.combat->hp,
|
||||
enemy.combat->damage);
|
||||
|
||||
switch(host_behavior) {
|
||||
case BattleHostState::agree:
|
||||
fmt::println("HOST and PLAYER requests match {}, doing it.",
|
||||
wants_to);
|
||||
break;
|
||||
case BattleHostState::disagree:
|
||||
fmt::println("REBELIOUS ACT: {}", wants_to);
|
||||
battle.$player_requests.clear();
|
||||
break;
|
||||
case BattleHostState::not_host:
|
||||
if(wants_to == "kill_enemy") {
|
||||
enemy.combat->attack(host_combat);
|
||||
}
|
||||
}
|
||||
|
||||
fmt::println("<<<<<<<<<<<<<<<<");
|
||||
}
|
||||
|
||||
fmt::println("<<<<<<<<<<<<<<<<");
|
||||
REQUIRE(!battle.next());
|
||||
}
|
||||
|
||||
REQUIRE(!battle.next());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue