43 #define DBG_AI_LUA LOG_STREAM(debug, log_ai_engine_lua)
44 #define LOG_AI_LUA LOG_STREAM(info, log_ai_engine_lua)
45 #define WRN_AI_LUA LOG_STREAM(warn, log_ai_engine_lua)
46 #define ERR_AI_LUA LOG_STREAM(err, log_ai_engine_lua)
51 #pragma warning(disable:4250)
67 auto l_obj = std::make_shared<lua_object<double>>();
75 std::shared_ptr<double> result = l_obj->get();
77 return result ? *result : 0.0;
137 std::string eval_code;
138 std::string exec_code;
165 std::string preamble =
"local self, params, data, filter_own = ...\n";
168 eval = preamble +
"return " +
load +
":evaluation(ai, {" +
eval_parms_ +
"}, {data = data})";
169 exec = preamble +
load +
":execution(ai, {" +
exec_parms_ +
"}, {data = data})";
171 eval = preamble +
"return " +
load +
".evaluation(self, params, data, filter_own)";
172 exec = preamble +
load +
".execution(self, params, data, filter_own)";
209 cfg[
"sticky"] =
true;
210 cfg[
"unit_x"] =
bound_unit_->get_location().wml_x();
211 cfg[
"unit_y"] =
bound_unit_->get_location().wml_y();
263 , code_(get_engine_code(cfg))
265 get_engine_code(cfg).c_str(), this))
281 return cfg[
"code"].str();
284 std::string code =
"wesnoth.require(\"ai/lua/dummy_engine_lua.lua\")";
312 if (!cfg[
"sticky"].to_bool())
336 if(
auto st_ptr = std::make_shared<lua_stage_wrapper>(context, cfg, *
lua_ai_context_)) {
344 const std::string aspect_factory_key =
id+
"*lua_aspect";
349 DBG_AI_LUA <<
"config snippet contains: " << std::endl << cfg;
354 ERR_AI_LUA <<
"side "<<
ai_.
get_side()<<
" : UNABLE TO CREATE aspect, key=["<<aspect_factory_key<<
"]";
355 DBG_AI_LUA <<
"config snippet contains: " << std::endl << cfg;
366 DBG_AI_LUA <<
"config snippet contains: " << std::endl << cfg;
369 goal_ptr new_goal =
f->second->get_new_instance(
ai_,cfg);
371 if (!new_goal || !new_goal->ok()) {
373 DBG_AI_LUA <<
"config snippet contains: " << std::endl << cfg;
396 cfg[
"code"] = this->
code_;
virtual void set_to_be_removed()
void disable()
Disable the candidate action.
static const double BAD_SCORE
virtual config to_config() const
serialize
void apply_micro_ai(const config &cfg)
std::string get_engine_code(const config &) const
virtual void do_parse_stage_from_config(ai_context &context, const config &cfg, std::back_insert_iterator< std::vector< stage_ptr > > b)
Taka a config (with engine=lua in it) and parse several (usually, 1) stages out of it.
virtual void do_parse_aspect_from_config(const config &cfg, const std::string &id, std::back_insert_iterator< std::vector< aspect_ptr > > b)
Taka a config (with engine=lua in it) and parse several (usually, 1) aspects out of it.
virtual void do_parse_candidate_action_from_config(rca_context &context, const config &cfg, std::back_insert_iterator< std::vector< candidate_action_ptr > > b)
Taka a config (with engine=lua in it) and parse several (usually, 1) candidate actions out of it.
virtual config to_config() const
Serialize to config.
std::shared_ptr< lua_ai_context > lua_ai_context_
virtual std::string evaluate(const std::string &str)
engine_lua(readonly_context &context, const config &cfg)
Note that initially we get access only to readonly context (engine is created rather early,...
virtual void do_parse_goal_from_config(const config &cfg, std::back_insert_iterator< std::vector< goal_ptr > > b)
std::string code_
The underlying lua code.
virtual void push_ai_table()
Method that pushes the AI table of the lua_context on the stack for debugging purposes.
virtual std::string get_id() const
virtual config to_config() const
serialize
bool is_gamestate_changed()
Check if the gamestate has changed since last reset reset is done once on construction,...
static factory_map & get_list()
Proxy table for the AI context.
static factory_map & get_list()
virtual void execute()
Execute the candidate action.
virtual ~lua_candidate_action_wrapper_base()
lua_candidate_action_wrapper_base(rca_context &context, const config &cfg)
virtual config to_config() const
serialize
std::shared_ptr< lua_ai_action_handler > evaluation_action_handler_
config serialized_filterown_
config serialized_evaluation_state_
std::shared_ptr< lua_ai_action_handler > execution_action_handler_
virtual double evaluate()
Evaluate the candidate action, resetting the internal state of the action.
lua_candidate_action_wrapper_external(rca_context &context, const config &cfg, lua_ai_context &lua_ai_ctx)
virtual ~lua_candidate_action_wrapper_external()
void generate_code(std::string &eval, std::string &exec)
virtual config to_config() const
serialize
virtual config to_config() const
serialize
lua_candidate_action_wrapper(rca_context &context, const config &cfg, lua_ai_context &lua_ai_ctx)
virtual ~lua_candidate_action_wrapper()
virtual config to_config() const
serialize
lua_stage_wrapper(ai_context &context, const config &cfg, lua_ai_context &lua_ai_ctx)
virtual bool do_play_stage()
Play the turn - implementation.
virtual ~lua_stage_wrapper()
config serialized_evaluation_state_
std::shared_ptr< lua_ai_action_handler > action_handler_
lua_sticky_candidate_action_wrapper(rca_context &context, const config &cfg, lua_ai_context &lua_ai_ctx)
virtual double evaluate()
Evaluate the candidate action, resetting the internal state of the action.
virtual void execute()
Execute the candidate action.
virtual config to_config() const
serialize
virtual side_number get_side() const =0
Get the side number.
virtual config to_config() const
serialize
A config object defines a single node in a WML file, with access to child nodes.
const config & child_or_empty(config_key_type key) const
Returns the first child with the given key, or an empty config if there is none.
bool has_attribute(config_key_type key) const
config & add_child(config_key_type key)
virtual const unit_map & units() const override
unit_iterator find(std::size_t id)
std::string deprecated_message(const std::string &elem_name, DEP_LEVEL level, const version_info &version, const std::string &detail)
LUA AI Support engine - creating specific ai components from config.
Interfaces for manipulating version numbers of engine, add-ons, etc.
A helper class to observe the game state.
Standard logging facilities (interface).
Lua object(value) wrapper implementation.
A small explanation about what's going on here: Each action has access to two game_info objects First...
wfl::candidate_action_ptr ca_ptr
std::shared_ptr< lua_object_base > lua_object_ptr
std::shared_ptr< aspect > aspect_ptr
std::shared_ptr< goal > goal_ptr
std::shared_ptr< candidate_action > candidate_action_ptr
static lg::log_domain log_ai_engine_lua("ai/engine/lua")
std::vector< game_tip > load(const config &cfg)
Loads the tips from a config.
game_lua_kernel * lua_kernel
std::string::const_iterator iterator
std::shared_ptr< unit > unit_ptr
candidate action framework
Encapsulates the map of the game.