26 #define ERR_AI LOG_STREAM(err, log_formula_ai)
52 ERR_AI <<
"formula type error while evaluating candidate action: " << e.
message << std::endl;
81 callable.
add(
"input", input);
98 candidate_action_filters::const_iterator me_filter =
filter_map_.find(
"me");
100 std::vector<variant>
res;
104 if (
i->side() == ai->
get_side() &&
i->movement_left() > 0) {
114 filtered_units =
do_filtering(ai, my_units, me_filter->second);
116 filtered_units=my_units;
127 callable.
add(
"me", *
i);
155 candidate_action_filters::const_iterator me_filter =
filter_map_.find(
"me");
156 candidate_action_filters::const_iterator target_filter =
filter_map_.find(
"target");
158 std::vector<variant> my_res, enemy_res;
164 if (
i->attacks_left()) {
175 variant enemy_units(&enemy_res);
177 variant filtered_my_units, filtered_enemy_units;
180 filtered_my_units =
do_filtering(ai, my_units, me_filter->second);
182 filtered_my_units = my_units;
185 filtered_enemy_units =
do_filtering(ai, enemy_units, target_filter->second);
187 filtered_enemy_units = enemy_units;
199 ERR_AI <<
"Error while executing filter formulas for '" +
get_name() +
"' Candidate Action: " << e.
message << std::endl;
203 std::vector< const unit_callable* > my_units_flt;
204 std::vector< const unit_callable* > enemy_units_flt;
208 if(u_callable ==
nullptr) {
209 ERR_AI <<
"ERROR in "<<
get_name() <<
"Candidate Action: Filter formula returned table that does not contain units" << std::endl;
212 my_units_flt.push_back(u_callable);
217 if(u_callable ==
nullptr) {
218 ERR_AI <<
"ERROR in "<<
get_name() <<
"Candidate Action: Filter formula returned table that does not contain units" << std::endl;
221 enemy_units_flt.push_back(u_callable);
224 for(
size_t my_unit = 0 ; my_unit < my_units_flt.size() ; ++my_unit){
225 const unit_callable* my_unit_callalbe = my_units_flt[my_unit];
226 for(
size_t enemy_unit = 0 ; enemy_unit < enemy_units_flt.size() ; ++enemy_unit){
231 callable.
add(
"me", filtered_my_units[my_unit]);
232 callable.
add(
"target", filtered_enemy_units[enemy_unit]);
238 my_unit_ = filtered_my_units[my_unit];
virtual side_number get_side() const
Get the side number.
size_t num_elements() const
Defines formula ai candidate actions - headers.
GLuint GLuint GLsizei GLenum type
GLenum GLenum GLenum input
bool is_enemy(int n) const
attribute_map::value_type attribute
variant_iterator end() const
variant do_filtering(ai::formula_ai *ai, variant &input, game_logic::const_formula_ptr formula)
move_candidate_action(const std::string &name, const std::string &type, const config &cfg, function_symbol_table *function_table)
virtual void update_callable_map(game_logic::map_formula_callable &callable)
static lg::log_domain log_formula_ai("ai/engine/fai")
game_logic::candidate_action_filters filter_map_
A small explanation about what's going on here: Each action has access to two game_info objects First...
int execute_formula(const const_formula_ptr &formula, const game_logic::formula_callable &callable, const ai::formula_ai *ai)
base_candidate_action(const std::string &name, const std::string &type, const config &cfg, function_symbol_table *function_table)
Iterator class for the variant.
virtual void evaluate(ai::formula_ai *ai, unit_map &units)
candidate_action_with_filters(const std::string &name, const std::string &type, const config &cfg, function_symbol_table *function_table)
variant_iterator begin() const
const location & get_location() const
const_attr_itors attribute_range() const
const std::string & get_name() const
GLuint const GLchar * name
virtual const team & current_team() const
config & child(const std::string &key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
Standard logging facilities (interface).
Container associating units to locations.
attack_candidate_action(const std::string &name, const std::string &type, const config &cfg, function_symbol_table *function_table)
virtual void evaluate(ai::formula_ai *ai, unit_map &units)
A config object defines a single node in a WML file, with access to child nodes.
virtual void update_callable_map(game_logic::map_formula_callable &callable)
GLsizei const GLcharARB ** string