parent
e6a8a8b338
commit
ca328e10dc
@ -0,0 +1,39 @@ |
|||||||
|
#include "rituals.hpp" |
||||||
|
#include "battle.hpp" |
||||||
|
|
||||||
|
namespace combat { |
||||||
|
void BattleEngine::add_enemy(BattleAction enemy) { |
||||||
|
combatants.try_emplace(enemy.entity, enemy); |
||||||
|
} |
||||||
|
|
||||||
|
bool BattleEngine::plan() { |
||||||
|
int active = 0; |
||||||
|
|
||||||
|
for(auto& [entity, enemy] : combatants) { |
||||||
|
enemy.ai.set_state("enemy_found", true); |
||||||
|
enemy.ai.set_state("in_combat", true); |
||||||
|
enemy.ai.update(); |
||||||
|
|
||||||
|
active += enemy.ai.active(); |
||||||
|
// yes, copy it out of the combatants list
|
||||||
|
pending_actions.push_back(enemy); |
||||||
|
} |
||||||
|
|
||||||
|
return active > 0; |
||||||
|
} |
||||||
|
|
||||||
|
std::optional<BattleAction> BattleEngine::next() { |
||||||
|
if(pending_actions.size() == 0) return std::nullopt; |
||||||
|
|
||||||
|
auto ba = pending_actions.back(); |
||||||
|
pending_actions.pop_back(); |
||||||
|
return std::make_optional(ba); |
||||||
|
} |
||||||
|
|
||||||
|
void BattleEngine::dump() { |
||||||
|
for(auto& [entity, enemy] : combatants) { |
||||||
|
fmt::println("\n\n###### ENTITY #{}", entity); |
||||||
|
enemy.ai.dump(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,25 @@ |
|||||||
|
#pragma once |
||||||
|
#include "rituals.hpp" |
||||||
|
#include "config.hpp" |
||||||
|
#include "dinkyecs.hpp" |
||||||
|
#include <optional> |
||||||
|
#include "components.hpp" |
||||||
|
|
||||||
|
namespace combat { |
||||||
|
|
||||||
|
struct BattleAction { |
||||||
|
DinkyECS::Entity entity; |
||||||
|
ai::EntityAI &ai; |
||||||
|
components::Combat &combat; |
||||||
|
}; |
||||||
|
|
||||||
|
struct BattleEngine { |
||||||
|
std::unordered_map<DinkyECS::Entity, BattleAction> combatants; |
||||||
|
std::vector<BattleAction> pending_actions; |
||||||
|
|
||||||
|
void add_enemy(BattleAction ba); |
||||||
|
bool plan(); |
||||||
|
std::optional<BattleAction> next(); |
||||||
|
void dump(); |
||||||
|
}; |
||||||
|
} |
@ -1,6 +1,7 @@ |
|||||||
#include <catch2/catch_test_macros.hpp> |
#include <catch2/catch_test_macros.hpp> |
||||||
#include <iostream> |
#include <iostream> |
||||||
#include "rituals.hpp" |
#include "rituals.hpp" |
||||||
|
#include "battle.hpp" |
||||||
#include "fsm.hpp" |
#include "fsm.hpp" |
||||||
#include "dinkyecs.hpp" |
#include "dinkyecs.hpp" |
||||||
|
|
Loading…
Reference in new issue