AI engine is working and I have a little BattleEngine going but the AI is working better than it should in systems.cpp. Need to find out why then make the BattleEngine avoid running entities that have END in action lists.

This commit is contained in:
Zed A. Shaw 2025-03-26 13:34:52 -04:00
parent da273cbee6
commit 47c6bfd531
13 changed files with 131 additions and 27 deletions

View file

@ -4,6 +4,51 @@
namespace combat {
void BattleEngine::add_enemy(DinkyECS::Entity enemy_id, ai::EntityAI& enemy) {
combatants.insert_or_assign(enemy_id, enemy);
}
bool BattleEngine::plan() {
int active = 0;
for(auto& [entity, enemy_ai] : combatants) {
fmt::println("\n\n==== ENTITY {} has AI:", entity);
enemy_ai.dump();
enemy_ai.set_state("enemy_found", true);
enemy_ai.set_state("in_combat", true);
enemy_ai.update();
fmt::println("\n\n---- AFTER UPDATE:");
enemy_ai.dump();
active += enemy_ai.active();
}
return active > 0;
}
void BattleEngine::fight(std::function<void(DinkyECS::Entity, ai::EntityAI &)> cb) {
for(auto& [entity, enemy_ai] : combatants) {
if(enemy_ai.wants_to("kill_enemy")) {
cb(entity, enemy_ai);
} else if(!enemy_ai.active()) {
enemy_ai.dump();
dbc::sentinel("enemy AI ended early, fix your ai.json");
} else {
dbc::log("enemy doesn't want to fight");
enemy_ai.dump();
}
}
}
void BattleEngine::dump() {
for(auto& [entity, enemy_ai] : combatants) {
fmt::println("\n\n###### ENTITY #{}", entity);
enemy_ai.dump();
}
}
RitualEngine::RitualEngine(std::string config_path) :
$config(config_path)
{
@ -23,12 +68,12 @@ namespace combat {
auto& scripts = $config["scripts"];
for(auto& [script_name, action_names] : scripts.items()) {
std::vector<ai::Action> the_script;
for(auto name : action_names) {
the_script.push_back($actions.at(name));
}
std::vector<ai::Action> the_script;
for(auto name : action_names) {
the_script.push_back($actions.at(name));
}
$scripts.insert_or_assign(script_name, the_script);
$scripts.insert_or_assign(script_name, the_script);
}
}