The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Member Functions | Private Member Functions | Private Attributes | List of all members
ai::engine_lua Class Reference

#include <engine_lua.hpp>

Inheritance diagram for ai::engine_lua:
Inheritance graph

Public Member Functions

 engine_lua (readonly_context &context, const config &cfg)
 Note that initially we get access only to readonly context (engine is created rather early, when there's no way to move/attack. More...
 
virtual ~engine_lua ()
 
bool is_ok () const
 
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. More...
 
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. More...
 
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. More...
 
virtual void do_parse_goal_from_config (const config &cfg, std::back_insert_iterator< std::vector< goal_ptr > > b)
 
virtual std::string evaluate (const std::string &str)
 
virtual void push_ai_table ()
 Method that pushes the AI table of the lua_context on the stack for debugging purposes. More...
 
virtual config to_config () const
 Serialize to config. More...
 
- Public Member Functions inherited from ai::engine
 engine (readonly_context &context, const config &cfg)
 
virtual ~engine ()
 
virtual void do_parse_engine_from_config (const config &cfg, std::back_insert_iterator< std::vector< engine_ptr > > b)
 
readonly_contextget_readonly_context ()
 
virtual void set_ai_context (ai_context_ptr context)
 set ai context (which is not available during early initialization) More...
 
virtual ai_context_ptr get_ai_context ()
 
virtual std::string get_id () const
 
virtual std::string get_engine () const
 
virtual std::string get_name () const
 
- Public Member Functions inherited from ai::component
 component ()
 
virtual ~component ()
 
virtual componentget_child (const path_element &child)
 
virtual std::vector< component * > get_children (const std::string &type)
 
virtual std::vector< std::string > get_children_types ()
 
virtual bool change_child (const path_element &child, const config &cfg)
 
virtual bool add_child (const path_element &child, const config &cfg)
 
virtual bool delete_child (const path_element &child)
 
property_handler_mapproperty_handlers ()
 

Private Member Functions

std::string get_engine_code (const config &) const
 

Private Attributes

std::string code_
 Method to inject AI context into the engine. More...
 
std::shared_ptr< lua_ai_contextlua_ai_context_
 

Additional Inherited Members

- Static Public Member Functions inherited from ai::engine
static void parse_aspect_from_config (readonly_context &context, const config &cfg, const std::string &id, std::back_insert_iterator< std::vector< aspect_ptr > > b)
 
static void parse_goal_from_config (readonly_context &context, const config &cfg, std::back_insert_iterator< std::vector< goal_ptr > > b)
 
static void parse_candidate_action_from_config (rca_context &context, const config &cfg, std::back_insert_iterator< std::vector< candidate_action_ptr > > b)
 
static void parse_engine_from_config (readonly_context &context, const config &cfg, std::back_insert_iterator< std::vector< engine_ptr > > b)
 
static void parse_stage_from_config (ai_context &context, const config &cfg, std::back_insert_iterator< std::vector< stage_ptr > > b)
 
- Protected Attributes inherited from ai::engine
readonly_contextai_
 
ai_context_ptr ai_context_
 
std::string engine_
 name of the engine which has created this engine More...
 
std::string id_
 
std::string name_
 

Detailed Description

Definition at line 30 of file engine_lua.hpp.

Constructor & Destructor Documentation

ai::engine_lua::engine_lua ( readonly_context context,
const config cfg 
)

Note that initially we get access only to readonly context (engine is created rather early, when there's no way to move/attack.

We inject full ai_context later.

Definition at line 251 of file engine_lua.cpp.

References config::child_or_empty(), lua_ai_context_, and ai::engine::name_.

ai::engine_lua::~engine_lua ( )
virtual

Definition at line 278 of file engine_lua.cpp.

Member Function Documentation

void ai::engine_lua::do_parse_aspect_from_config ( const config cfg,
const std::string &  id,
std::back_insert_iterator< std::vector< aspect_ptr > >  b 
)
virtual

Taka a config (with engine=lua in it) and parse several (usually, 1) aspects out of it.

Reimplemented from ai::engine.

Definition at line 340 of file engine_lua.cpp.

References ai::engine::ai_, b, DBG_AI_LUA, ERR_AI_LUA, f, ai::lua_aspect_factory::get_list(), ai::side_context::get_side(), and lua_ai_context_.

void ai::engine_lua::do_parse_candidate_action_from_config ( rca_context context,
const config cfg,
std::back_insert_iterator< std::vector< candidate_action_ptr > >  b 
)
virtual

Taka a config (with engine=lua in it) and parse several (usually, 1) candidate actions out of it.

Reimplemented from ai::engine.

Definition at line 295 of file engine_lua.cpp.

References b, config::has_attribute(), and lua_ai_context_.

void ai::engine_lua::do_parse_goal_from_config ( const config cfg,
std::back_insert_iterator< std::vector< goal_ptr > >  b 
)
virtual
void ai::engine_lua::do_parse_stage_from_config ( ai_context context,
const config cfg,
std::back_insert_iterator< std::vector< stage_ptr > >  b 
)
virtual

Taka a config (with engine=lua in it) and parse several (usually, 1) stages out of it.

Reimplemented from ai::engine.

Definition at line 323 of file engine_lua.cpp.

References b, and lua_ai_context_.

std::string ai::engine_lua::evaluate ( const std::string &  str)
virtual
Todo:
this is not mandatory, but if we want to allow lua to evaluate

Reimplemented from ai::engine.

Definition at line 378 of file engine_lua.cpp.

std::string ai::engine_lua::get_engine_code ( const config cfg) const
private

Definition at line 268 of file engine_lua.cpp.

References config::has_attribute().

bool ai::engine_lua::is_ok ( ) const
virtual

Reimplemented from ai::engine.

Definition at line 282 of file engine_lua.cpp.

References lua_ai_context_.

void ai::engine_lua::push_ai_table ( )
virtual

Method that pushes the AI table of the lua_context on the stack for debugging purposes.

Definition at line 287 of file engine_lua.cpp.

References game_config::debug, and lua_ai_context_.

Referenced by intf_debug_ai().

config ai::engine_lua::to_config ( ) const
virtual

Serialize to config.

Reimplemented from ai::engine.

Definition at line 385 of file engine_lua.cpp.

References config::add_child(), code_, ai::engine::get_id(), lua_ai_context_, and ai::engine::to_config().

Referenced by intf_debug_ai().

Member Data Documentation

std::string ai::engine_lua::code_
private

Method to inject AI context into the engine.

The context includes all that in necessary for the AI - , like access to game state and movement/attack routines. The underlying lua code

Definition at line 84 of file engine_lua.hpp.

Referenced by to_config().

std::shared_ptr<lua_ai_context> ai::engine_lua::lua_ai_context_
private

The documentation for this class was generated from the following files: