The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
core.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2010 - 2025
3 by Yurii Chernyi <terraninfo@terraninfo.net>
4 Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY.
12
13 See the COPYING file for more details.
14*/
15
16#pragma once
17
18#include <memory>
19
20struct lua_State;
21class game_lua_kernel;
22class config;
23
24namespace ai {
25
26class engine_lua;
27class lua_object_base;
28typedef std::shared_ptr<lua_object_base> lua_object_ptr;
29
30/**
31 * Proxy table for the AI context
32 */
34{
35private:
36 lua_State *L;
37 int num_;
38 int side_;
39 lua_ai_context(lua_State *l, int num, int side) : L(l), num_(num), side_(side)
40 {
41 }
42 static lua_ai_context* create(lua_State *L, char const *code, engine_lua *engine);
43public:
45 void update_state();
46 void get_persistent_data(config &) const;
47 void set_persistent_data(const config &);
48 void get_arguments(config &) const;
49 void set_arguments(const config &);
50 void push_ai_table();
51 void apply_micro_ai(const config& cfg);
52 static void init(lua_State *L);
53 friend class ::game_lua_kernel;
54 friend class lua_ai_load;
55};
56
58{
59 lua_State* L;
60 static int refcount;
61public:
63 lua_ai_load(lua_ai_context& ctx, bool read_only);
65};
66
67/**
68 * Proxy class for calling AI action handlers defined in Lua.
69 */
71{
72private:
73 lua_State *L;
75 int num_;
76 lua_ai_action_handler(lua_State *l, lua_ai_context &context, int num) : L(l), context_(context),num_(num)
77 {
78 }
79 static lua_ai_action_handler* create(lua_State *L, char const *code, lua_ai_context &context);
80public:
82 //void handle(const config &cfg, bool read_only, lua_object_ptr l_obj);
83 void handle(const config &cfg, const config &filter_own, bool read_only, const lua_object_ptr& l_obj);
84 friend class ::game_lua_kernel;
85};
86
87}//of namespace ai
Proxy class for calling AI action handlers defined in Lua.
Definition core.hpp:71
lua_ai_context & context_
Definition core.hpp:74
lua_ai_action_handler(lua_State *l, lua_ai_context &context, int num)
Definition core.hpp:76
static lua_ai_action_handler * create(lua_State *L, char const *code, lua_ai_context &context)
Definition core.cpp:1080
void handle(const config &cfg, const config &filter_own, bool read_only, const lua_object_ptr &l_obj)
Definition core.cpp:1161
Proxy table for the AI context.
Definition core.hpp:34
void set_persistent_data(const config &)
Definition core.cpp:110
void update_state()
Definition core.cpp:1059
void get_persistent_data(config &) const
Definition core.cpp:97
void push_ai_table()
Definition core.cpp:143
lua_ai_context(lua_State *l, int num, int side)
Definition core.hpp:39
static void init(lua_State *L)
Definition core.cpp:64
static lua_ai_context * create(lua_State *L, char const *code, engine_lua *engine)
Definition core.cpp:1038
void set_arguments(const config &)
Definition core.cpp:84
void get_arguments(config &) const
Definition core.cpp:71
lua_State * L
Definition core.hpp:36
void apply_micro_ai(const config &cfg)
Definition core.cpp:1031
bool was_readonly
Definition core.hpp:62
static int refcount
Definition core.hpp:60
lua_State * L
Definition core.hpp:59
A config object defines a single node in a WML file, with access to child nodes.
Definition config.hpp:157
const config * cfg
A small explanation about what's going on here: Each action has access to two game_info objects First...
Definition actions.cpp:59
std::shared_ptr< lua_object_base > lua_object_ptr
Definition core.hpp:28