42 #define DBG_AI_LUA LOG_STREAM(debug, log_ai_engine_lua)
43 #define LOG_AI_LUA LOG_STREAM(info, log_ai_engine_lua)
44 #define WRN_AI_LUA LOG_STREAM(warn, log_ai_engine_lua)
45 #define ERR_AI_LUA LOG_STREAM(err, log_ai_engine_lua)
50 #pragma warning(disable:4250)
78 return result ? *result : 0.0;
164 std::string preamble =
"local self, params, data = ...\n";
167 eval = preamble +
"return " + load +
":evaluation(ai, {" + eval_parms_ +
"}, {data = data})";
168 exec = preamble + load +
":execution(ai, {" + exec_parms_ +
"}, {data = data})";
170 eval = preamble +
"return " + load +
".evaluation(self, params, data)";
171 exec = preamble + load +
".execution(self, params, data)";
253 , code_(get_engine_code(cfg))
255 get_engine_code(cfg).c_str(), this))
271 return cfg[
"code"].str();
274 std::string code =
"wesnoth.require(\"ai/lua/dummy_engine_lua.lua\")";
305 if (!cfg[
"sticky"].to_bool())
342 const std::string aspect_factory_key =
id+
"*lua_aspect";
347 DBG_AI_LUA <<
"config snippet contains: " << std::endl << cfg << std::endl;
352 ERR_AI_LUA <<
"side "<<
ai_.
get_side()<<
" : UNABLE TO CREATE aspect, key=["<<aspect_factory_key<<
"]"<< std::endl;
353 DBG_AI_LUA <<
"config snippet contains: " << std::endl << cfg << std::endl;
364 DBG_AI_LUA <<
"config snippet contains: " << std::endl << cfg << std::endl;
367 goal_ptr new_goal = f->second->get_new_instance(
ai_,cfg);
369 if (!new_goal || !new_goal->ok()) {
371 DBG_AI_LUA <<
"config snippet contains: " << std::endl << cfg << std::endl;
390 cfg[
"code"] = this->
code_;
virtual double evaluate()
Evaluate the candidate action, resetting the internal state of the action.
virtual void execute()
Execute the candidate action.
boost::shared_ptr< stage > stage_ptr
lua_stage_wrapper(ai_context &context, const config &cfg, lua_ai_context &lua_ai_ctx)
virtual ~lua_candidate_action_wrapper_external()
std::string code_
Method to inject AI context into the engine.
static factory_map & get_list()
bool is_gamestate_changed()
Check if the gamestate has changed since last reset reset is done once on construction, and can be done by hand via reset() method.
virtual ~lua_candidate_action_wrapper_base()
game_logic::candidate_action_ptr ca_ptr
static factory_map & get_list()
void generate_code(std::string &eval, std::string &exec)
virtual ~lua_stage_wrapper()
const config & child_or_empty(const std::string &key) const
Returns the first child with the given key, or an empty config if there is none.
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
std::string get_engine_code(const config &) const
A helper class to observe the game state.
Lua object(value) wrapper implementation.
engine_lua(readonly_context &context, const config &cfg)
Note that initially we get access only to readonly context (engine is created rather early...
virtual config to_config() const
Serialize to config.
config serialized_evaluation_state_
GLdouble GLdouble GLdouble b
A small explanation about what's going on here: Each action has access to two game_info objects First...
virtual config to_config() const
serialize
virtual config to_config() const
serialize
Proxy table for the AI context.
virtual void do_parse_goal_from_config(const config &cfg, std::back_insert_iterator< std::vector< goal_ptr > > b)
Composite AI with turn sequence which is a vector of stages.
virtual void execute()
Execute the candidate action.
virtual config to_config() const
serialize
config serialized_evaluation_state_
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...
config & add_child(const std::string &key)
virtual void set_to_be_removed()
virtual config to_config() const
serialize
static lg::log_domain log_ai_engine_lua("ai/engine/lua")
virtual std::string get_id() const
Templates and utility-routines for strings and numbers.
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 config to_config() const
serialize
Encapsulates the map of the game.
boost::shared_ptr< lua_ai_action_handler > evaluation_action_handler_
virtual bool do_play_stage()
Play the turn - implementation.
virtual double evaluate()
Evaluate the candidate action, resetting the internal state of the action.
boost::shared_ptr< lua_object< int > > lua_int_obj
virtual void push_ai_table()
Method that pushes the AI table of the lua_context on the stack for debugging purposes.
virtual config to_config() const
serialize
boost::shared_ptr< candidate_action > candidate_action_ptr
ai::lua_ai_action_handler * create_lua_ai_action_handler(char const *code, ai::lua_ai_context &context)
boost::shared_ptr< lua_ai_context > lua_ai_context_
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
void disable()
Disable the candidate action.
boost::intrusive_ptr< unit > unit_ptr
lua_sticky_candidate_action_wrapper(rca_context &context, const config &cfg, lua_ai_context &lua_ai_ctx)
bool has_attribute(const std::string &key) const
bool find(E event, F functor)
Tests whether an event handler is available.
Standard logging facilities (interface).
virtual side_number get_side() const =0
Get the side number.
boost::shared_ptr< lua_ai_action_handler > action_handler_
static const double BAD_SCORE
game_lua_kernel * lua_kernel
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...
lua_candidate_action_wrapper_base(rca_context &context, const config &cfg)
virtual std::string evaluate(const std::string &str)
A config object defines a single node in a WML file, with access to child nodes.
LUA AI Support engine - creating specific ai components from config.
GLsizei const GLcharARB ** string
lua_candidate_action_wrapper_external(rca_context &context, const config &cfg, lua_ai_context &lua_ai_ctx)
boost::shared_ptr< lua_ai_action_handler > execution_action_handler_
candidate action framework
const std::string valid
Little parts of regex templates used to parse Wml annoations.