The Battle for Wesnoth  1.17.0-dev
core.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 - 2021
3  Part of the Battle for Wesnoth Project https://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 #pragma once
16 
17 #include <memory>
18 
19 struct lua_State;
20 class game_lua_kernel;
21 class config;
22 
23 namespace ai {
24 
25 class engine_lua;
27 typedef std::shared_ptr<lua_object_base> lua_object_ptr;
28 
29 /**
30  * Proxy table for the AI context
31  */
33 {
34 private:
36  int num_;
37  int side_;
38  lua_ai_context(lua_State *l, int num, int side) : L(l), num_(num), side_(side)
39  {
40  }
41  static lua_ai_context* create(lua_State *L, char const *code, engine_lua *engine);
42 public:
44  void update_state();
45  void get_persistent_data(config &) const;
46  void set_persistent_data(const config &);
47  void get_arguments(config &) const;
48  void set_arguments(const config &);
49  void push_ai_table();
50  static void init(lua_State *L);
51  friend class ::game_lua_kernel;
52  friend class lua_ai_load;
53 };
54 
56 {
58  static int refcount;
59 public:
61  lua_ai_load(lua_ai_context& ctx, bool read_only);
62  ~lua_ai_load();
63 };
64 
65 /**
66  * Proxy class for calling AI action handlers defined in Lua.
67  */
69 {
70 private:
73  int num_;
74  lua_ai_action_handler(lua_State *l, lua_ai_context &context, int num) : L(l), context_(context),num_(num)
75  {
76  }
77  static lua_ai_action_handler* create(lua_State *L, char const *code, lua_ai_context &context);
78 public:
80  //void handle(const config &cfg, bool read_only, lua_object_ptr l_obj);
81  void handle(const config &cfg, const config &filter_own, bool read_only, lua_object_ptr l_obj);
82  friend class ::game_lua_kernel;
83 };
84 
85 }//of namespace ai
void get_arguments(config &) const
Definition: core.cpp:68
lua_ai_context & context_
Definition: core.hpp:72
static lua_ai_context * create(lua_State *L, char const *code, engine_lua *engine)
Definition: core.cpp:954
void get_persistent_data(config &) const
Definition: core.cpp:94
A small explanation about what&#39;s going on here: Each action has access to two game_info objects First...
Definition: actions.cpp:60
void set_arguments(const config &)
Definition: core.cpp:81
void set_persistent_data(const config &)
Definition: core.cpp:107
bool was_readonly
Definition: core.hpp:60
Proxy table for the AI context.
Definition: core.hpp:32
static int refcount
Definition: core.hpp:58
void push_ai_table()
Definition: core.cpp:131
static void init(lua_State *L)
Definition: core.cpp:61
lua_ai_context(lua_State *l, int num, int side)
Definition: core.hpp:38
friend class lua_ai_load
Definition: core.hpp:52
Proxy class for calling AI action handlers defined in Lua.
Definition: core.hpp:68
lua_ai_action_handler(lua_State *l, lua_ai_context &context, int num)
Definition: core.hpp:74
lua_State * L
Definition: core.hpp:35
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:59
lua_State * L
Definition: core.hpp:57
std::shared_ptr< halo_record > handle
Definition: halo.hpp:29
void update_state()
Definition: core.cpp:975
std::shared_ptr< lua_object_base > lua_object_ptr
Definition: core.hpp:26