AI: Support [unit][ai][candidate_action]
This is essentially a syntax sugar for adding a candidate action filtered to only run for that single unit.
This commit is contained in:
parent
880ef29075
commit
9ad9833789
2 changed files with 24 additions and 0 deletions
|
@ -62,6 +62,12 @@
|
|||
super="$ai/micro_ai"
|
||||
{INSERT_TAG}
|
||||
[/tag]
|
||||
[tag]
|
||||
name="candidate_action"
|
||||
max=infinite
|
||||
super="$ai/$candidate_action"
|
||||
{DEFAULT_KEY stage string main_loop}
|
||||
[/tag]
|
||||
[/tag]
|
||||
{LINK_TAG "event"}
|
||||
{LINK_TAG "units/movetype/movement_costs"}
|
||||
|
|
|
@ -537,6 +537,24 @@ void unit::init(const config& cfg, bool use_traits, const vconfig* vcfg)
|
|||
mai["action"] = "add";
|
||||
ai_events.add_child("micro_ai", mai);
|
||||
}
|
||||
for(config ca : ai.child_range("candidate_action")) {
|
||||
ca.clear_children("filter_own");
|
||||
ca.add_child("filter_own")["id"] = id();
|
||||
// Sticky candidate actions not supported here (they cause a crash because the unit isn't on the map yet)
|
||||
ca.remove_attribute("sticky");
|
||||
std::string stage = "main_loop";
|
||||
if(ca.has_attribute("stage")) {
|
||||
stage = ca["stage"].str();
|
||||
ca.remove_attribute("stage");
|
||||
}
|
||||
config mod{
|
||||
"action", "add",
|
||||
"side", side(),
|
||||
"path", "stage[" + stage + "].candidate_action[]",
|
||||
"candidate_action", ca,
|
||||
};
|
||||
ai_events.add_child("modify_ai", mod);
|
||||
}
|
||||
if(ai_events.all_children_count() > 0) {
|
||||
ai::manager::get_singleton().append_active_ai_for_side(side(), ai_events);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue