add lua_function in side filters

This commit is contained in:
gfgtdf 2020-05-24 19:58:01 +02:00
parent 11f96b3a98
commit fd7da64a50
3 changed files with 25 additions and 0 deletions

View file

@ -4824,6 +4824,18 @@ bool game_lua_kernel::run_filter(char const *name, const map_location& l)
lua_pushinteger(mState, l.wml_y());
return run_filter(name, 2);
}
/**
* Runs a script from a location filter.
* The script is an already compiled function given by its name.
*/
bool game_lua_kernel::run_filter(char const *name, const team& t)
{
//TODO: instead of passing the lua team object we coudl also jsut pass its
// number. then we wouldn't need this const cast.
luaW_pushteam(mState, const_cast<team&>(t));
return run_filter(name, 1);
}
/**
* Runs a script from a unit filter.
* The script is an already compiled function given by its name.

View file

@ -213,6 +213,7 @@ public:
const game_events::queued_event&);
bool run_filter(char const *name, const unit& u);
bool run_filter(char const *name, const map_location& l);
bool run_filter(char const *name, const team& t);
bool run_filter(char const *name, int nArgs);
bool run_wml_conditional(const std::string&, const vconfig&);

View file

@ -23,6 +23,7 @@
#include "variable.hpp"
#include "team.hpp"
#include "serialization/string_utils.hpp"
#include "scripting/game_lua_kernel.hpp"
#include "play_controller.hpp"
#include "resources.hpp"
#include "synced_context.hpp"
@ -30,6 +31,7 @@
#include "units/filter.hpp"
#include "units/map.hpp"
#include "variable.hpp"
#include "filter_context.hpp"
#include "formula/callable_objects.hpp"
#include "formula/formula.hpp"
#include "formula/function_gamestate.hpp"
@ -243,6 +245,16 @@ bool side_filter::match_internal(const team &t) const
}
}
if (cfg_.has_attribute("lua_function")) {
std::string lua_function = cfg_["lua_function"].str();
if (!lua_function.empty() && fc_->get_lua_kernel()) {
if (!fc_->get_lua_kernel()->run_filter(lua_function.c_str(), t)) {
return false;
}
}
}
return true;
}