-
-
Notifications
You must be signed in to change notification settings - Fork 991
/
game_lua_kernel.hpp
226 lines (201 loc) · 8.13 KB
/
game_lua_kernel.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
/*
Copyright (C) 2009 - 2018 by Guillaume Melquiond <guillaume.melquiond@gmail.com>
Part of the Battle for Wesnoth Project https://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#pragma once
#include "scripting/lua_kernel_base.hpp" // for lua_kernel_base
#include "game_events/action_wml.hpp" // for wml_action, etc
#include <stack>
#include <string> // for string
class config;
class game_config_view;
class unit;
class vconfig;
namespace ai { class engine_lua; }
namespace ai { class lua_ai_action_handler; }
namespace ai { class lua_ai_context; }
namespace game_events { struct queued_event; }
class game_display;
class game_state;
class game_board;
class unit_map;
class gamemap;
class team;
class game_data;
class tod_manager;
class play_controller;
class reports;
struct map_location;
typedef int (*lua_CFunction) (lua_State *L);
class game_lua_kernel : public lua_kernel_base
{
game_display * game_display_;
game_state & game_state_;
play_controller & play_controller_;
reports & reports_;
// Private functions to ease access to parts of game_state
unit_map & units();
game_data & gamedata();
tod_manager & tod_man();
config level_lua_;
std::stack<game_events::queued_event const * > queued_events_;
const game_events::queued_event & get_event_info();
static void extract_preload_scripts(const game_config_view& game_config);
static std::vector<config> preload_scripts;
static config preload_config;
friend class game_config_manager; // to allow it to call extract_preload_scripts
// Private lua callbacks
int intf_allow_end_turn(lua_State *);
int intf_allow_undo(lua_State *);
int intf_cancel_action(lua_State *);
int intf_add_time_area(lua_State *);
int intf_remove_time_area(lua_State *);
int intf_animate_unit(lua_State *);
int intf_gamestate_inspector(lua_State *);
int impl_run_animation(lua_State *);
int intf_create_animator(lua_State *);
int intf_get_unit(lua_State *);
int intf_get_units(lua_State *);
int intf_get_displayed_unit(lua_State*);
int intf_match_unit(lua_State *L);
int intf_get_recall_units(lua_State *L);
int intf_get_variable(lua_State *L);
int intf_get_side_variable(lua_State *L);
int intf_set_variable(lua_State *L);
int intf_set_side_variable(lua_State *L);
int intf_highlight_hex(lua_State *L);
int intf_is_enemy(lua_State *L);
int intf_unit_ability(lua_State *L);
int intf_view_locked(lua_State *L);
int intf_lock_view(lua_State *L);
int intf_get_terrain(lua_State *L);
int intf_set_terrain(lua_State *L);
int intf_terrain_mask(lua_State *L);
int intf_get_terrain_info(lua_State *L);
int intf_get_time_of_day(lua_State *L);
int intf_get_max_liminal_bonus(lua_State *L);
int intf_get_village_owner(lua_State *L);
int intf_set_village_owner(lua_State *L);
int intf_get_map_size(lua_State *L);
int intf_get_mouseover_tile(lua_State *L);
int intf_get_selected_tile(lua_State *L);
int impl_game_config_get(lua_State *L) override;
int impl_game_config_set(lua_State *L) override;
int impl_current_get(lua_State *L);
int intf_clear_messages(lua_State*);
int intf_end_level(lua_State*);
int impl_end_level_data_set(lua_State*);
int intf_get_end_level_data(lua_State*);
int intf_end_turn(lua_State*);
int intf_find_path(lua_State *L);
int intf_find_reach(lua_State *L);
int intf_find_cost_map(lua_State *L);
int intf_heal_unit(lua_State *L);
int intf_message(lua_State *L);
int intf_open_help(lua_State *L);
int intf_play_sound(lua_State *L);
int intf_print(lua_State *L);
void put_unit_helper(const map_location& loc);
int intf_put_unit(lua_State *L);
int intf_erase_unit(lua_State *L);
int intf_put_recall_unit(lua_State *L);
int intf_extract_unit(lua_State *L);
int intf_find_vacant_tile(lua_State *L);
int intf_float_label(lua_State *L);
int intf_set_end_campaign_credits(lua_State *L);
int intf_set_end_campaign_text(lua_State *L);
int intf_clear_menu_item(lua_State *L);
int intf_create_side(lua_State *L);
int intf_set_menu_item(lua_State *L);
int intf_set_next_scenario(lua_State *L);
int intf_shroud_op(lua_State *L, bool place_shroud);
int intf_simulate_combat(lua_State *L);
int intf_scroll_to_tile(lua_State *L);
int intf_select_hex(lua_State *L);
int intf_select_unit(lua_State *L);
int intf_deselect_hex(lua_State *L);
int intf_is_skipping_messages(lua_State *L);
int intf_skip_messages(lua_State *L);
int intf_get_locations(lua_State *L);
int intf_get_villages(lua_State *L);
int intf_match_location(lua_State *L);
int intf_match_side(lua_State *L);
int intf_set_side_id(lua_State *L);
int intf_modify_ai_wml(lua_State *L);
int intf_get_sides(lua_State* L);
int intf_get_side(lua_State* L);
int intf_add_tile_overlay(lua_State *L);
int intf_remove_tile_overlay(lua_State *L);
int intf_add_event(lua_State *L);
int intf_remove_event(lua_State *L);
int intf_color_adjust(lua_State *L);
int intf_delay(lua_State *L);
int intf_label(lua_State *L);
int intf_redraw(lua_State *L);
int intf_replace_schedule(lua_State *l);
int intf_set_time_of_day(lua_State *L);
int intf_scroll(lua_State *L);
int intf_get_all_vars(lua_State *L);
int impl_theme_item(lua_State *L, std::string name);
int impl_theme_items_get(lua_State *L);
int impl_theme_items_set(lua_State *L);
int cfun_builtin_effect(lua_State *L);
int cfun_wml_action(lua_State *L);
int intf_fire_event(lua_State *L, const bool by_id);
int intf_fire_wml_menu_item(lua_State *L);
int intf_teleport(lua_State *L);
int intf_log(lua_State *L);
int intf_toggle_fog(lua_State *L, const bool clear);
int intf_get_fog_or_shroud(lua_State *L, bool fog);
int intf_log_replay(lua_State* L);
int intf_zoom(lua_State* L);
//private helpers
std::string synced_state();
void lua_chat(const std::string& caption, const std::string& msg);
std::vector<int> get_sides_vector(const vconfig& cfg);
public:
game_board & board();
std::vector<team> & teams();
const gamemap & map() const;
game_display * get_display() const { return game_display_; }
/**
A value != 0 means that the shouldn't remove any units from the map, usually because
we are currently operating on a unit& and removing it might cause memory corruptions
note that we don't check for the dtor of lua owned units because we assume that
we operate on such a unit that the lua function that invoked the operation on that unit
(like wesnoth.units.add_modification, wesnoth.units.matches ..) have a local copy of that
lua_unit* userdata in its stack that prevents it from being collected.
*/
int map_locked_;
game_lua_kernel(game_state &, play_controller &, reports &);
void set_game_display(game_display * gd);
virtual std::string my_name() override { return "Game Lua Kernel"; }
std::string apply_effect(const std::string& name, unit& u, const config& cfg, bool need_apply);
void initialize(const config& level);
void save_game(config & level);
void load_game(const config& level);
bool run_event(const game_events::queued_event&);
void custom_command(const std::string&, const config&);
void push_builtin_effect();
void set_wml_action(const std::string&, game_events::wml_action::handler);
void set_wml_condition(const std::string&, bool(*)(const vconfig&));
bool run_wml_action(const std::string&, const vconfig&,
const game_events::queued_event&);
bool run_filter(char const *name, const unit& u);
bool run_filter(char const *name, const map_location& l);
bool run_filter(char const *name, const team& t);
bool run_filter(char const *name, int nArgs);
bool run_wml_conditional(const std::string&, const vconfig&);
virtual void log_error(char const* msg, char const* context = "Lua error") override;
ai::lua_ai_context* create_lua_ai_context(char const *code, ai::engine_lua *engine);
ai::lua_ai_action_handler* create_lua_ai_action_handler(char const *code, ai::lua_ai_context &context);
void mouse_over_hex_callback(const map_location& loc);
void select_hex_callback(const map_location& loc);
};