Move filtering code out of the unit formula manager.
This commit is contained in:
parent
49fc414cc6
commit
7b6dea55c8
3 changed files with 12 additions and 19 deletions
|
@ -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 <boost/foreach.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,22 +23,6 @@
|
|||
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
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;
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue