Action nodes handling

This commit is contained in:
2026-02-01 23:25:38 +03:00
parent e6efd89bb0
commit 69035351a6
7 changed files with 81 additions and 40 deletions

View File

@@ -375,9 +375,10 @@ CharacterAIModule::CharacterAIModule(flecs::world &ecs)
});
});
});
#if 1
ecs.system<TownAI, TownNPCs>("PlanAI")
.kind(flecs::OnUpdate)
.interval(1.0f)
.interval(0.5f)
.each([&](flecs::entity town, TownAI &ai,
const TownNPCs &npcs) {
Ogre::Root::getSingleton().getWorkQueue()->addTask(
@@ -393,6 +394,7 @@ CharacterAIModule::CharacterAIModule(flecs::world &ecs)
});
});
});
#endif
}
void CharacterAIModule::createAI(flecs::entity town)
@@ -413,10 +415,14 @@ void CharacterAIModule::buildPlans(flecs::entity town, const TownNPCs &npcs,
if (ai.plans.find(it->first) != ai.plans.end() &&
ai.plans.at(it->first).size() > 0)
continue;
ai.plans[it->first] = {};
const auto &npc = npcs.npcs.at(it->first);
int index = it->first;
ai.plans[index] = {};
for (const auto &goal : ai.goals) {
if (goal.is_reached(bb))
continue;
struct TownAI::Plan plan;
plan.goal = &goal;
#if 0
std::cout << "blackboard: "
<< bb.stats.dump(4)
@@ -477,12 +483,14 @@ void CharacterAIModule::buildPlans(flecs::entity town, const TownNPCs &npcs,
// "planning");
#endif
if (path_length > 0) {
struct TownAI::Plan plan;
plan.goal = &goal;
plan.plan.insert(plan.plan.end(), path.begin(),
path.begin() + path_length);
ai.plans[it->first].push_back(plan);
break;
}
if (path_length > 0)
OgreAssert(false, "plan");
}
}
}