44 #define DBG_AI_LUA LOG_STREAM(debug, log_ai_engine_lua) 
   45 #define LOG_AI_LUA LOG_STREAM(info, log_ai_engine_lua) 
   46 #define WRN_AI_LUA LOG_STREAM(warn, log_ai_engine_lua) 
   47 #define ERR_AI_LUA LOG_STREAM(err, log_ai_engine_lua) 
   52 #pragma warning(disable:4250) 
   68         auto l_obj = std::make_shared<lua_object<double>>();
 
   76         std::shared_ptr<double> result = l_obj->get();
 
   78         return result ? *result : 0.0;
 
  138         std::string eval_code;
 
  139         std::string exec_code;
 
  166         std::string preamble = 
"local self, params, data, filter_own = ...\n";
 
  169             eval = preamble + 
"return " + 
load + 
":evaluation(ai, {" + 
eval_parms_ + 
"}, {data = data})";
 
  170             exec = preamble + 
load + 
":execution(ai, {" + 
exec_parms_ + 
"}, {data = data})";
 
  172             eval = preamble + 
"return " + 
load + 
".evaluation(self, params, data, filter_own)";
 
  173             exec = preamble + 
load + 
".execution(self, params, data, filter_own)";
 
  210         cfg[
"sticky"] = 
true;
 
  264     , code_(get_engine_code(
cfg))
 
  266         get_engine_code(
cfg).c_str(), this))
 
  282         return cfg[
"code"].str();
 
  285     std::string code = 
"wesnoth.require(\"ai/lua/dummy_engine_lua.lua\")";
 
  313     if (!
cfg[
"sticky"].to_bool())
 
  337     if(
auto st_ptr = std::make_shared<lua_stage_wrapper>(context, 
cfg, *
lua_ai_context_)) {
 
  345     const std::string aspect_factory_key = 
id+
"*lua_aspect"; 
 
  350         DBG_AI_LUA << 
"config snippet contains: " << std::endl << 
cfg;
 
  355         ERR_AI_LUA << 
"side "<<
ai_.
get_side()<< 
" : UNABLE TO CREATE aspect, key=["<<aspect_factory_key<<
"]";
 
  356         DBG_AI_LUA << 
"config snippet contains: " << std::endl << 
cfg;
 
  367         DBG_AI_LUA << 
"config snippet contains: " << std::endl << 
cfg;
 
  372     if (!new_goal || !new_goal->ok()) {
 
  374         DBG_AI_LUA << 
"config snippet contains: " << std::endl << 
cfg;
 
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_
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.
config & add_child(std::string_view key)
bool has_attribute(std::string_view key) const
const config & child_or_empty(std::string_view key) const
Returns the first child with the given key, or an empty config if there is none.
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...
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
auto * find(Container &container, const Value &value)
Convenience wrapper for using find on a container without needing to comare to end()
std::string::const_iterator iterator
std::shared_ptr< unit > unit_ptr
candidate action framework
Encapsulates the map of the game.