Skip to content

Commit

Permalink
Output formula errors in unit filters to WML error stream
Browse files Browse the repository at this point in the history
(And consider them to match no units)
  • Loading branch information
CelticMinstrel committed Mar 18, 2016
1 parent 26a2638 commit 240b5f6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
14 changes: 13 additions & 1 deletion data/test/scenarios/filter_this_unit.cfg
Expand Up @@ -59,7 +59,7 @@
[/event]
)}

{GENERIC_UNIT_TEST filter_this_unit_fai_short (
{GENERIC_UNIT_TEST filter_fai_unit (
[event]
name=prestart
[modify_unit]
Expand All @@ -76,3 +76,15 @@
)}
[/event]
)}

{GENERIC_UNIT_TEST filter_fai_unit_error (
[event]
name=prestart
{RETURN (
[have_unit]
id=bob
formula="+ max_moves"
[/have_unit]
)}
[/event]
)}
15 changes: 11 additions & 4 deletions src/unit_formula_manager.cpp
Expand Up @@ -19,17 +19,24 @@
#include "formula.hpp"
#include "formula_string_utils.hpp"
#include "map_location.hpp"
#include "log.hpp"

#include <boost/foreach.hpp>

bool unit_formula_manager::matches_filter(const std::string & cfg_formula, const map_location & loc, const unit & me)
{
const unit_callable callable(loc,me);
const game_logic::formula form(cfg_formula);
if(!form.evaluate(callable).as_bool()) {///@todo use formula_ai
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;
}
return true;
}

void unit_formula_manager::add_formula_var(std::string str, variant var)
Expand Down
3 changes: 2 additions & 1 deletion wml_test_schedule
Expand Up @@ -147,7 +147,8 @@
0 filter_this_unit_wml
0 filter_this_unit_tl
0 filter_this_unit_fai
0 filter_this_unit_fai_short
0 filter_fai_unit
1 filter_fai_unit_error
# Interrupt tag tests
0 check_interrupts_break
0 check_interrupts_return
Expand Down

0 comments on commit 240b5f6

Please sign in to comment.