Basic AP (Action Points) system tied to the AI actions, but there's no way to set 'has AP' for the AI?
This commit is contained in:
parent
c78b2ae75e
commit
a38bb5b691
8 changed files with 64 additions and 18 deletions
34
battle.cpp
34
battle.cpp
|
|
@ -16,7 +16,16 @@ namespace combat {
|
|||
|
||||
int active = 0;
|
||||
|
||||
fmt::println("---------- start combatants");
|
||||
for(auto& [entity, enemy] : $combatants) {
|
||||
if(enemy.combat->ap < enemy.combat->max_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 {} has {} ap", entity, enemy.combat->ap);
|
||||
// reset action points
|
||||
|
||||
enemy.ai->update();
|
||||
active += enemy.ai->active();
|
||||
|
||||
|
|
@ -24,15 +33,38 @@ namespace combat {
|
|||
for(auto& action : enemy.ai->plan.script) {
|
||||
BattleHostState host_state = not_host;
|
||||
|
||||
if(enemy.is_host) {
|
||||
if(action.cost > enemy.combat->ap) {
|
||||
host_state = out_of_ap;
|
||||
} else if(enemy.is_host) {
|
||||
host_state = $player_requests.contains(action.name) ? agree : disagree;
|
||||
}
|
||||
|
||||
if(host_state == out_of_ap) {
|
||||
fmt::println("--- enemy CANNOT go: {}-{}={}",
|
||||
enemy.combat->ap, action.cost,
|
||||
enemy.combat->ap - action.cost);
|
||||
break;
|
||||
} else {
|
||||
fmt::println("--- enemy can go, {}-{}={}",
|
||||
enemy.combat->ap, action.cost,
|
||||
enemy.combat->ap - action.cost);
|
||||
|
||||
enemy.combat->ap -= action.cost;
|
||||
}
|
||||
|
||||
fmt::println("--- active enemy {} ap={}, host_state={}",
|
||||
entity, enemy.combat->ap, int(host_state));
|
||||
|
||||
$pending_actions.emplace_back(enemy, action.name, action.cost, host_state);
|
||||
}
|
||||
|
||||
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");
|
||||
|
||||
if($pending_actions.size() > 0) {
|
||||
std::sort($pending_actions.begin(), $pending_actions.end(),
|
||||
[](const auto& a, const auto& b) -> bool
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue