diff --git a/src/units/filter.cpp b/src/units/filter.cpp index e96ad007d61..de40708ee04 100644 --- a/src/units/filter.cpp +++ b/src/units/filter.cpp @@ -35,6 +35,8 @@ #include "units/types.hpp" #include "variable.hpp" // needed for vconfig, scoped unit #include "wml_exception.hpp" // needed for FAIL +#include "formula/callable_objects.hpp" +#include "formula/formula.hpp" #include #include @@ -551,7 +553,16 @@ bool basic_unit_filter_impl::internal_matches_filter(const unit & u, const map_l } } if (!vcfg["formula"].blank()) { - if (!u.formula_manager().matches_filter(vcfg["formula"], loc, u)) { + try { + const unit_callable callable(loc,u); + const game_logic::formula form(vcfg["formula"]); + if(!form.evaluate(callable).as_bool()) { + return false; + } + return true; + } catch(game_logic::formula_error& e) { + lg::wml_error() << "Formula error in unit filter: " << e.type << " at " << e.filename << ':' << e.line << ")\n"; + // Formulae with syntax errors match nothing return false; } } diff --git a/src/units/formula_manager.cpp b/src/units/formula_manager.cpp index 8a107cae011..5f62bfa306f 100644 --- a/src/units/formula_manager.cpp +++ b/src/units/formula_manager.cpp @@ -23,22 +23,6 @@ #include -bool unit_formula_manager::matches_filter(const std::string & cfg_formula, const map_location & loc, const unit & me) -{ - try { - const unit_callable callable(loc,me); - const game_logic::formula form(cfg_formula); - if(!form.evaluate(callable).as_bool()) {///@todo use formula_ai - return false; - } - return true; - } catch(game_logic::formula_error& e) { - lg::wml_error() << "Formula error in unit filter: " << e.type << " at " << e.filename << ':' << e.line << ")\n"; - // Formulae with syntax errors match nothing - return false; - } -} - void unit_formula_manager::add_formula_var(std::string str, variant var) { if(!formula_vars_) formula_vars_ = new game_logic::map_formula_callable; diff --git a/src/units/formula_manager.hpp b/src/units/formula_manager.hpp index 70b80edef0a..370f3330fc3 100644 --- a/src/units/formula_manager.hpp +++ b/src/units/formula_manager.hpp @@ -43,8 +43,6 @@ public: const std::string& get_loop_formula() const { return unit_loop_formula_; } const std::string& get_priority_formula() const { return unit_priority_formula_; } - bool matches_filter( const std::string & cfg_formula, const map_location & loc, const unit & me); - void read(const config & ai); void write(config & cfg);