bool have_unit(const vconfig& cfg) { if(resources::units == nullptr) { return false; } std::vector<std::pair<int,int> > counts = cfg.has_attribute("count") ? utils::parse_ranges(cfg["count"]) : default_counts; int match_count = 0; const unit_filter ufilt(cfg, resources::filter_con); for(const unit &i : *resources::units) { if(i.hitpoints() > 0 && ufilt(i)) { ++match_count; if(counts == default_counts) { // by default a single match is enough, so avoid extra work break; } } } if(cfg["search_recall_list"].to_bool()) { for(const team& team : resources::gameboard->teams()) { if(counts == default_counts && match_count) { break; } for(size_t t = 0; t < team.recall_list().size(); ++t) { if(counts == default_counts && match_count) { break; } scoped_recall_unit auto_store("this_unit", team.save_id(), t); if(ufilt(*team.recall_list()[t])) { ++match_count; } } } } return in_ranges(match_count, counts); }
void target_unit_goal::add_targets(std::back_insert_iterator< std::vector< target > > target_list) { if (!(this)->active()) { return; } const config &criteria = cfg_.child("criteria"); if (!criteria) return; //find the enemy leaders and explicit targets const unit_filter ufilt(vconfig(criteria), resources::filter_con); BOOST_FOREACH(const unit &u, *resources::units) { if (ufilt( u )) { LOG_AI_GOAL << "found explicit target unit at ... " << u.get_location() << " with value: " << value() << "\n"; *target_list = target(u.get_location(), value(), target::EXPLICIT); } } }