The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
engine_lua.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2016 by Yurii Chernyi <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 /**
16  * LUA AI Support engine - creating specific ai components from config
17  * @file
18  */
19 
20 #ifndef AI_COMPOSITE_ENGINE_LUA_HPP_INCLUDED
21 #define AI_COMPOSITE_ENGINE_LUA_HPP_INCLUDED
22 
23 #include "ai/composite/engine.hpp"
24 
25 //============================================================================
26 namespace ai {
27 
28 class lua_ai_context;
29 
30 class engine_lua : public engine {
31 public:
32  engine_lua( readonly_context &context, const config &cfg );
33 
34  virtual ~engine_lua();
35 
36  bool is_ok() const;
37 
38  /**
39  * Taka a config (with engine=lua in it)
40  * and parse several (usually, 1) candidate actions out of it
41  */
42  virtual void do_parse_candidate_action_from_config( rca_context &context, const config &cfg, std::back_insert_iterator<std::vector< candidate_action_ptr > > b );
43 
44  /**
45  * Taka a config (with engine=lua in it)
46  * and parse several (usually, 1) stages out of it
47  */
48  virtual void do_parse_stage_from_config( ai_context &context, const config &cfg, std::back_insert_iterator<std::vector< stage_ptr > > b );
49 
50  /**
51  * Taka a config (with engine=lua in it)
52  * and parse several (usually, 1) aspects out of it
53  */
54  virtual void do_parse_aspect_from_config( const config &cfg, const std::string &id, std::back_insert_iterator<std::vector< aspect_ptr > > b );
55 
56  virtual void do_parse_goal_from_config(const config &cfg, std::back_insert_iterator<std::vector< goal_ptr > > b );
57 
58  virtual std::string evaluate(const std::string &str);
59 
60  /**
61  * Method that pushes the AI table of the lua_context on the stack
62  * for debugging purposes
63  */
64 
65  virtual void push_ai_table();
66 
67  /**
68  * Serialize to config
69  */
70  virtual config to_config() const;
71 
72 // /**
73 // * Method to inject AI context into the engine.
74 // * The context includes all that in necessary for the AI -
75 // * , like access to game state and movement/attack routines.
76 // */
77 // virtual void set_ai_context(ai_context *context);
78 
79 private:
80 
81  /**
82  * The underlying lua code
83  */
85 
86  //There is one lua engine per AI. So, it can hold state
88 
89  std::string get_engine_code(const config&) const;
90 
91 };
92 
93 } //end of namespace ai
94 
95 #endif
std::string code_
Method to inject AI context into the engine.
Definition: engine_lua.hpp:84
virtual ~engine_lua()
Definition: engine_lua.cpp:278
AI Support engine - creating specific ai components from config.
std::string get_engine_code(const config &) const
Definition: engine_lua.cpp:268
engine_lua(readonly_context &context, const config &cfg)
Note that initially we get access only to readonly context (engine is created rather early...
Definition: engine_lua.cpp:251
virtual config to_config() const
Serialize to config.
Definition: engine_lua.cpp:385
GLdouble GLdouble GLdouble b
Definition: glew.h:6966
A small explanation about what's going on here: Each action has access to two game_info objects First...
Definition: actions.cpp:57
virtual void do_parse_goal_from_config(const config &cfg, std::back_insert_iterator< std::vector< goal_ptr > > b)
Definition: engine_lua.cpp:359
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...
Definition: engine_lua.cpp:340
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...
Definition: engine_lua.cpp:323
virtual void push_ai_table()
Method that pushes the AI table of the lua_context on the stack for debugging purposes.
Definition: engine_lua.cpp:287
boost::shared_ptr< lua_ai_context > lua_ai_context_
Definition: engine_lua.hpp:87
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...
Definition: engine_lua.cpp:295
virtual std::string evaluate(const std::string &str)
Definition: engine_lua.cpp:378
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
bool is_ok() const
Definition: engine_lua.cpp:282
GLsizei const GLcharARB ** string
Definition: glew.h:4503