Formula engine: Expose WML unit/side variables

This commit is contained in:
Celtic Minstrel 2016-04-02 09:30:17 -04:00
parent 5c9923daba
commit 0688e6df8f
3 changed files with 11 additions and 0 deletions

View file

@ -179,6 +179,11 @@ Version 1.13.4+dev:
* Nearly all unit type, side, weapon, and terrain attributes available
to Lua code are now also exposed to WFL. The exceptions are mainly
translatable strings.
* Unit and side WML variables are now accessible under "wml_vars".
Since WML variables don't easily translate to formula variables, the
special attributes __all_children, __children, and __attributes provide
specialized views of the variables config as a list, string-list map,
and string-value map, respectively.
* The 'special' attribute of weapons was renamed to 'specials', and it now
contains the special IDs rather than their translateable names.
* New syntax features:

View file

@ -309,6 +309,8 @@ variant unit_callable::get_value(const std::string& key) const
} else {
return variant();
}
} else if(key == "wml_vars") {
return variant(new config_callable(u_.variables()));
} else if(key == "n" || key == "s" || key == "ne" || key == "se" || key == "nw" || key == "sw" || key == "lawful" || key == "neutral" || key == "chaotic" || key == "liminal" || key == "male" || key == "female") {
return variant(key);
} else {
@ -357,6 +359,7 @@ void unit_callable::get_inputs(std::vector<game_logic::formula_input>* inputs) c
inputs->push_back(game_logic::formula_input("alignment", FORMULA_READ_ONLY));
inputs->push_back(game_logic::formula_input("facing", FORMULA_READ_ONLY));
inputs->push_back(game_logic::formula_input("vars", FORMULA_READ_ONLY));
inputs->push_back(game_logic::formula_input("wml_vars", FORMULA_READ_ONLY));
}
int unit_callable::do_compare(const formula_callable* callable) const

View file

@ -224,6 +224,7 @@ CALLABLE_WRAPPER_INPUT(carryover_bonus)
CALLABLE_WRAPPER_INPUT(carryover_percentage)
CALLABLE_WRAPPER_INPUT(carryover_add)
CALLABLE_WRAPPER_INPUT(recruit)
CALLABLE_WRAPPER_INPUT(wml_vars)
CALLABLE_WRAPPER_INPUT_END
CALLABLE_WRAPPER_FN(side)
CALLABLE_WRAPPER_FN2(id, save_id)
@ -258,6 +259,8 @@ CALLABLE_WRAPPER_FN(carryover_add)
result.push_back(variant(*it));
}
return variant(&result);
} else if(key == "wml_vars") {
return variant(new config_callable(object_.variables()));
} else
CALLABLE_WRAPPER_END