BattleEngine is now connected to the boss::UI so as you click it'll continually run the plan and figure out the AI actions.
This commit is contained in:
parent
a38bb5b691
commit
f839edcd56
10 changed files with 112 additions and 56 deletions
13
battle.cpp
13
battle.cpp
|
|
@ -15,12 +15,18 @@ namespace combat {
|
|||
using enum BattleHostState;
|
||||
|
||||
int active = 0;
|
||||
bool had_host = false;
|
||||
|
||||
fmt::println("---------- start combatants");
|
||||
for(auto& [entity, enemy] : $combatants) {
|
||||
if(enemy.combat->ap < enemy.combat->max_ap) {
|
||||
int new_ap = std::min(enemy.combat->max_ap, enemy.combat->ap_delta + enemy.combat->ap);
|
||||
|
||||
// only add up to the max
|
||||
enemy.combat->ap = std::min(enemy.combat->max_ap, enemy.combat->ap_delta + enemy.combat->ap);
|
||||
fmt::println("enemy {} get more ap {}->{}",
|
||||
entity, enemy.combat->ap, new_ap);
|
||||
|
||||
enemy.combat->ap = new_ap;
|
||||
}
|
||||
|
||||
fmt::println("--- enemy {} has {} ap", entity, enemy.combat->ap);
|
||||
|
|
@ -32,6 +38,8 @@ namespace combat {
|
|||
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;
|
||||
|
|
@ -58,12 +66,13 @@ 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");
|
||||
}
|
||||
}
|
||||
|
||||
fmt::print("<---- end of enemy setup, sorting");
|
||||
fmt::println("<---- end of enemy setup, sorting");
|
||||
|
||||
if($pending_actions.size() > 0) {
|
||||
std::sort($pending_actions.begin(), $pending_actions.end(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue