112 #include <functional> 124 #include <SDL2/SDL_timer.h> 135 #define LOG_LUA LOG_STREAM(info, log_scripting_lua) 136 #define WRN_LUA LOG_STREAM(warn, log_scripting_lua) 137 #define ERR_LUA LOG_STREAM(err, log_scripting_lua) 145 template <member_callback method>
147 return ((lua_kernel_base::get_lua_kernel<game_lua_kernel>(L)).*method)(L);
153 template <member_callback2 method,
bool b>
155 return ((lua_kernel_base::get_lua_kernel<game_lua_kernel>(L)).*method)(L,
b);
174 game_lua_kernel::preload_scripts.clear();
176 game_lua_kernel::preload_scripts.push_back(cfg);
178 game_lua_kernel::preload_config = game_config.
child(
"game_config");
184 lua_chat(context, msg);
190 game_display_->get_chat_manager().add_chat_message(std::time(
nullptr), caption, 0, msg,
205 if(!sides.
empty()) {
WRN_LUA <<
"ignoring duplicate side filter information (inline side=)" << std::endl; }
218 lua_pushnumber(L, lua_kernel_base::get_lua_kernel<game_lua_kernel>(L).map().special_locations().
size());
224 const t_translation::starting_positions::left_map&
left = lua_kernel_base::get_lua_kernel<game_lua_kernel>(L).map().special_locations().left;
226 t_translation::starting_positions::left_const_iterator it;
232 if (it == left.end()) {
237 if (it == left.end()) {
255 const t_translation::starting_positions::left_map&
left = lua_kernel_base::get_lua_kernel<game_lua_kernel>(L).map().special_locations().left;
257 if (it == left.end()) {
268 lua_pushstring(L,
"special locations cannot be modified using wesnoth.special_locations");
295 struct queued_event_context
298 std::stack<qe const *> & stack_;
300 queued_event_context(qe
const *new_qe, std::stack<qe const*> & stack)
306 ~queued_event_context()
334 anim.~unit_animator();
345 using hit_type = unit_animation::hit_type;
347 hit_type hits = hit_type::string_to_enum(hits_str, hit_type::INVALID);
360 return luaL_argerror(L, 5,
"target location must be different from animated unit's location");
362 return luaL_argerror(L, 5,
"target location must be adjacent to the animated unit");
384 return luaW_type_error(L, 5,
"value",
"number or array of two numbers");
436 anim.
add_animation(up, which, u.
get_location(), dest, v1, bars, text, color, hits, primary, secondary, v2);
448 play_controller_.play_slice(
false);
477 {
"run", &dispatch<&game_lua_kernel::impl_run_animation>},
510 for(
const unit& u : units()) {
523 if (!ui.
valid())
return 0;
536 if (!game_display_) {
541 game_display_->displayed_unit_hex(),
542 teams()[game_display_->viewing_team()],
543 game_display_->show_everything());
544 if (!ui.
valid())
return 0;
562 std::vector<const unit*> units;
586 for (
const unit * ui : units) {
614 WRN_LUA <<
"wesnoth.units.matches called with a secondary unit (3rd argument), ";
615 WRN_LUA <<
"but unit to match was on recall list. ";
616 WRN_LUA <<
"Thus the 3rd argument is ignored.\n";
617 team &
t = board().get_team(side);
629 team &
t = board().get_team(side);
657 for (
team &
t : teams())
661 if (!filter.
null()) {
663 t.save_id_or_number(),
t.recall_list().find_index(u->id()));
712 b = std::get<0>(play_controller_.pump().fire(
"", m, l1, l2, data));
715 b = std::get<0>(play_controller_.pump().fire(m, l1, l2, data));
739 bool b = game_state_.get_wml_menu_items().fire_item(m, l1,
gamedata(), game_state_, units());
765 if(m.empty())
return luaL_argerror(L, 1,
"empty variable name");
779 game_state_.add_side_wml(cfg);
795 WRN_LUA <<
"[clear_menu_item] has been given an empty id=, ignoring" << std::endl;
798 game_state_.get_wml_menu_items().erase(
id);
836 team& side = board().get_team(side_num);
842 }
else if(!place_shroud) {
850 std::vector<map_location> locs_v = lua_check<std::vector<map_location>>(L, 2);
851 std::set<map_location> locs(locs_v.begin(), locs_v.end());
852 team &
t = board().get_team(side_num);
863 return luaL_argerror(L, 2,
"expected list of locations or shroud data string");
866 game_display_->labels().recalculate_shroud();
867 game_display_->recalculate_minimap();
868 game_display_->invalidate_all();
880 if (!game_display_) {
885 if(!map().on_board(loc))
return luaL_argerror(L, 1,
"not on board");
886 game_display_->highlight_hex(loc);
887 game_display_->display_unit_hex(loc);
899 unsigned side_1, side_2;
910 if (side_1 > teams().
size() || side_2 > teams().
size())
return 0;
921 if (!game_display_) {
937 game_display_->set_view_locked(lock);
969 std::string mode_str =
"both";
970 bool replace_if_failed =
false;
981 bool result = board().change_terrain(loc, t_str, mode_str, replace_if_failed);
984 game_display_->needs_rebuild(result);
1004 bool ignore_special_locations =
false;
1005 std::vector<gamemap::overlay_rule> rules;
1026 return luaL_argerror(L, 3,
"rules must be a table of tables");
1029 auto& rule = rules.back();
1048 if(!terrain.empty()) {
1049 rule.terrain_ = terrain[0];
1072 mask_map.
read(t_str,
false);
1073 board().map().overlay(mask_map, loc, rules, is_odd, ignore_special_locations);
1075 for(
team&
t : board().teams()) {
1076 t.fix_villages(board().map());
1079 if (game_display_) {
1080 game_display_->needs_rebuild(
true);
1136 int for_turn = tod_man().turn();
1138 bool consider_illuminates =
false;
1143 int number_of_turns = tod_man().number_of_turns();
1144 if(for_turn < 1 || (number_of_turns != -1 && for_turn > number_of_turns)) {
1151 if(!board().map().on_board(loc))
return luaL_argerror(L, arg,
"coordinates are not on board");
1163 tod_man().get_illuminated_time_of_day(board().units(), board().map(), loc, for_turn) :
1164 tod_man().get_time_of_day(loc, for_turn);
1194 int bonus = tod_man().get_max_liminal_bonus();
1208 if (!board().map().is_village(loc))
1211 int side = board().village_owner(loc);
1212 if (!side)
return 0;
1225 if(!board().map().is_village(loc)) {
1229 const int old_side_num = board().village_owner(loc);
1232 team* old_side =
nullptr;
1233 team* new_side =
nullptr;
1235 if(old_side_num == new_side_num) {
1240 old_side = &board().get_team(old_side_num);
1241 }
catch(
const std::out_of_range&) {
1247 new_side = &board().get_team(new_side_num);
1248 }
catch(
const std::out_of_range&) {
1254 if(new_side && board().team_is_defeated(*new_side)) {
1284 const gamemap &map = board().map();
1298 if (!game_display_) {
1302 const map_location &loc = game_display_->mouseover_hex();
1303 if (!board().map().on_board(loc))
return 0;
1316 if (!game_display_) {
1320 const map_location &loc = game_display_->selected_hex();
1321 if (!board().map().on_board(loc))
return 0;
1342 return luaL_argerror(L, 1, (
"Cannot find ressource with id '" + m +
"'").c_str());
1367 LOG_LUA <<
"impl_game_config_get\n";
1384 if(classification.campaign_type==game_classification::CAMPAIGN_TYPE::MULTIPLAYER) {
1390 std::vector<std::string> eras_list;
1392 eras_list.push_back(
era[
"id"].str());
1407 LOG_LUA <<
"impl_game_config_set\n";
1425 game_display_->set_theme(play_controller_.get_theme(game_config, value));
1445 return "local_choice";
1472 if (strcmp(m,
"event_context") == 0)
1476 cfg[
"name"] = ev.
name;
1487 cfg[
"damage_inflicted"] = di;
1523 LOG_LUA <<
"Script says: \"" << m <<
"\"\n";
1529 if (game_display_) {
1537 if(!game_display_) {
1543 factor *= game_display_->get_zoom_factor();
1557 if (game_display_) {
1558 game_display_->get_chat_manager().clear_chat_messages();
1584 struct end_level_committer {
1586 ~end_level_committer() {
1587 pc_.set_end_level_data(data_);
1599 end_level_committer commit(data, play_controller_);
1614 data->~end_level_data();
1620 if (!play_controller_.is_regular_game_end()) {
1623 auto data = play_controller_.get_end_level_data();
1626 static luaL_Reg const callbacks[] {
1628 {
"__newindex", &dispatch<&game_lua_kernel::impl_end_level_data_set>},
1630 {
nullptr,
nullptr }
1646 data.
replay_save = cfg[
"replay_save"].to_bool(
true);
1649 data.
is_victory = cfg[
"result"] ==
"victory";
1650 data.
test_result = cfg[
"test_result"].str(LEVEL_RESULT::enum_to_string(LEVEL_RESULT::TEST_NOT_SET));
1651 play_controller_.set_end_level_data(data);
1661 if (npn <= 0 /*TODO: || npn > 2*nteams*/) {
1666 play_controller_.force_end_turn();
1697 const unit* u =
nullptr;
1698 int viewing_side = 0;
1704 viewing_side = u->
side();
1713 viewing_side = u->
side();
1721 if (!board().map().on_board(src))
1723 if (!board().map().on_board(dst))
1726 const gamemap &map = board().map();
1727 bool ignore_units =
false, see_all =
false, ignore_teleport =
false;
1728 double stop_at = 10000;
1729 std::unique_ptr<pathfind::cost_calculator> calc;
1733 ignore_units = luaW_table_get_def<bool>(L, arg,
"ignore_units",
false);
1734 see_all = luaW_table_get_def<bool>(L, arg,
"ignore_visibility",
false);
1735 ignore_teleport = luaW_table_get_def<bool>(L, arg,
"ignore_teleport",
false);
1737 stop_at = luaW_table_get_def<double>(L, arg,
"max_cost", stop_at);
1744 if (i >= 1 && i <= static_cast<int>(teams().
size())) viewing_side =
i;
1748 if(u) see_all =
true;
1769 if(!ignore_teleport) {
1770 if(viewing_side == 0) {
1771 return luaL_error(L,
"wesnoth.find_path: ignore_teleport=false requires a valid viewing_side");
1779 return luaL_argerror(L, 1,
"unit not found OR custom cost function not provided");
1783 teams(), map, ignore_units,
false, see_all));
1787 &teleport_locations);
1789 int nb = res.
steps.size();
1791 for (
int i = 0;
i < nb; ++
i)
1814 const unit* u =
nullptr;
1831 int viewing_side = u->
side();
1832 bool ignore_units =
false, see_all =
false, ignore_teleport =
false;
1833 int additional_turns = 0;
1837 ignore_units = luaW_table_get_def<bool>(L, arg,
"ignore_units",
false);
1838 see_all = luaW_table_get_def<bool>(L, arg,
"ignore_visibility",
false);
1839 ignore_teleport = luaW_table_get_def<bool>(L, arg,
"ignore_teleport",
false);
1840 additional_turns = luaW_table_get_def<int>(L, arg,
"max_cost", additional_turns);
1846 if (i >= 1 && i <= static_cast<int>(teams().
size())) viewing_side =
i;
1850 if(u) see_all =
true;
1857 const team& viewing_team = board().get_team(viewing_side);
1860 viewing_team, additional_turns, see_all, ignore_units);
1864 for (
int i = 0;
i < nb; ++
i)
1880 template<
typename T>
1883 for (
int i = 1, i_end =
lua_rawlen(L, arg);
i <= i_end; ++
i)
1914 fake_units.emplace_back(src, side, unit_type);
1920 return luaL_argerror(L, arg,
"unit type table malformed - each entry should be either array of 4 elements or table with keys x, y, side, type");
1938 std::vector<const ::unit*> real_units;
1939 typedef std::vector<std::tuple<map_location, int, std::string>> unit_type_vector;
1945 real_units.push_back(unit);
1947 else if (!filter.
null())
1950 if(
match->get_location().valid()) {
1951 real_units.push_back(
match);
1961 real_units.push_back(&(*ui));
1972 if(real_units.empty() && fake_units.empty())
1977 int viewing_side = 0;
1978 bool ignore_units =
true, see_all =
true, ignore_teleport =
false,
debug =
false, use_max_moves =
false;
2003 if (i >= 1 && i <= static_cast<int>(teams().
size()))
2037 const terrain_filter t_filter(filter, &fc,
false);
2038 t_filter.get_locations(location_set,
true);
2042 const team& viewing_team = viewing_side
2043 ? board().get_team(viewing_side)
2044 : board().teams()[0];
2047 ignore_units, !ignore_teleport, viewing_team, see_all, ignore_units);
2049 for (const ::unit*
const u : real_units)
2051 cost_map.
add_unit(*u, use_max_moves);
2053 for (
const unit_type_vector::value_type& fu : fake_units)
2056 cost_map.
add_unit(std::get<0>(fu), ut, std::get<1>(fu));
2061 if (game_display_) {
2062 game_display_->labels().clear_all();
2065 std::stringstream
s;
2069 game_display_->labels().set_label(loc, s.str());
2103 static int floating_label = 0;
2108 std::string text = cfg[
"text"];
2109 if(text.empty() || !game_display_)
2113 int lifetime = cfg[
"duration"].to_int(50);
2117 if(!cfg[
"color"].empty()) {
2120 color =
color_t(cfg[
"red"], cfg[
"green"], cfg[
"blue"]);
2123 const SDL_Rect& rect = game_display_->map_outside_area();
2128 flabel.
set_position(rect.x + rect.w/2, rect.y + rect.h/2);
2140 game_display_->invalidate(loc);
2159 return luaL_error(L,
"Attempted to move a unit while the map is locked");
2164 if (!map().on_board(loc)) {
2176 if (!map().on_board(loc))
2180 put_unit_helper(loc);
2184 const vconfig* vcfg =
nullptr;
2186 if (!map().on_board(loc)) {
2189 if (!map().on_board(loc))
2194 put_unit_helper(loc);
2195 u->set_location(loc);
2202 play_controller_.pump().fire(
"unit_placed", loc);
2214 return luaL_error(L,
"Attempted to remove a unit while the map is locked");
2222 if (!map().on_board(loc)) {
2226 team &
t = board().get_team(side);
2233 if (!map().on_board(loc)) {
2253 return luaL_error(L,
"Attempted to move a unit while the map is locked");
2258 if (static_cast<unsigned>(side) > teams().
size()) side = 0;
2262 u = lu->get_shared();
2263 if(lu->on_recall_list() && lu->on_recall_list() == side) {
2267 const vconfig* vcfg =
nullptr;
2277 team &
t = board().get_team(side);
2279 std::size_t uid = u->underlying_id();
2284 units().erase(u->get_location());
2286 u->anim_comp().clear_haloes();
2288 lu->lua_unit::~lua_unit();
2302 return luaL_error(L,
"Attempted to remove a unit while the map is locked");
2308 u = units().extract(u->get_location());
2310 u->anim_comp().clear_haloes();
2311 }
else if (
int side = lu->on_recall_list()) {
2312 team &
t = board().get_team(side);
2320 lu->lua_unit::~lua_unit();
2340 const vconfig* vcfg =
nullptr;
2348 if (!res.
valid())
return 0;
2370 if (game_display_) {
2371 game_display_->float_label(loc, text, color);
2383 const vconfig* vcfg =
nullptr;
2566 for (
int i = 0;
i <
n; ++
i) {
2617 if(bcustats.
weapon !=
nullptr)
2641 int arg_num = 1, att_w = -1, def_w = -1;
2647 if (att_w < 0 || att_w >= static_cast<int>(att->attacks().size()))
2648 return luaL_argerror(L, arg_num,
"weapon index out of bounds");
2656 if (def_w < 0 || def_w >= static_cast<int>(def->attacks().size()))
2657 return luaL_argerror(L, arg_num,
"weapon index out of bounds");
2662 def->get_location(), att_w, def_w, 0.0,
nullptr, att, def);
2696 if (play_controller_.is_skipping_replay())
return 0;
2713 if(rel < 0.0f || rel > 100.0
f) {
2714 return luaL_argerror(L, 1,
"volume must be in range 0..100");
2716 vol =
static_cast<int>(rel*vol / 100.0f);
2741 if (game_display_) {
2742 game_display_->scroll_to_tile(loc, scroll, check_fogged);
2759 intf_select_unit(L);
2761 intf_highlight_hex(L);
2779 if(!map().on_board(loc))
return luaL_argerror(L, 1,
"not on board");
2780 bool highlight =
true;
2784 play_controller_.get_mouse_handler_base().select_hex(
2785 loc,
false, highlight, fire_event);
2807 bool skipping = play_controller_.is_skipping_replay() || play_controller_.is_skipping_story();
2809 skipping = game_state_.events_manager_->pump().context_skip_messages();
2825 game_state_.events_manager_->pump().context_skip_messages(skip);
2834 int user_choice_index;
2835 int random_choice_index;
2836 int ai_choice_index;
2838 lua_synchronize(
lua_State *l,
const std::string& descr,
int user_index,
int random_index = 0,
int ai_index = 0)
2840 , user_choice_index(user_index)
2841 , random_choice_index(random_index)
2842 , ai_choice_index(ai_index != 0 ? ai_index : user_index)
2846 virtual config query_user(
int side)
const override 2848 bool is_local_ai = lua_kernel_base::get_lua_kernel<game_lua_kernel>(L).board().get_team(side).is_local_ai();
2850 query_lua(side, is_local_ai ? ai_choice_index : user_choice_index, cfg);
2854 virtual config random_choice(
int side)
const override 2857 if(random_choice_index != 0 &&
lua_isfunction(L, random_choice_index)) {
2858 query_lua(side, random_choice_index, cfg);
2863 virtual std::string description()
const override 2868 void query_lua(
int side,
int function_index,
config& cfg)
const 2870 assert(cfg.
empty());
2875 lua_kernel_base::get_lua_kernel<game_lua_kernel>(L).log_error(
"function returned to wesnoth.synchronize_choice a table which was partially invalid");
2882 virtual bool is_visible()
const override {
return false; }
2896 std::string tagname =
"input";
2907 human_func = nextarg++;
2913 ai_func = nextarg++;
2931 std::string tagname =
"input";
2935 std::vector<int> sides_for;
2942 human_func = nextarg++;
2948 null_func = nextarg++;
2950 sides_for = lua_check<std::vector<int>>(L, nextarg++);
2980 std::set<map_location> res;
2982 const terrain_filter t_filter(filter, &fc,
false);
2984 t_filter.get_locations(res, *
luaW_tounit(L, 2),
true);
2986 t_filter.get_locations(res,
true);
3011 std::vector<map_location> locs = map().villages();
3018 for(std::vector<map_location>::const_iterator it = locs.begin(); it != locs.end(); ++it) {
3019 bool matches = terrain_filter(filter, &fc,
false).match(*it);
3045 if (filter.
null()) {
3051 const terrain_filter t_filter(filter, &fc,
false);
3072 if (filter.
null()) {
3084 if (side >= teams().
size())
return 0;
3101 if(flag.empty() && color.empty()) {
3104 if(team_i < 1 || static_cast<std::size_t>(team_i) > teams().size()) {
3105 return luaL_error(L,
"set_side_id: side number %d out of range", team_i);
3107 team& side = board().get_team(team_i);
3109 if(!color.empty()) {
3116 game_display_->reinit_flags_for_team(side);
3124 side_num =
t->side();
3133 if(strcmp(action,
"delete") == 0) {
3138 std::size_t len = std::string::npos, open_brak = path.find_last_of(
'[');
3139 std::size_t dot = path.find_last_of(
'.');
3140 if(open_brak != len) {
3141 len = open_brak - dot - 1;
3143 cfg.add_child(path.substr(dot + 1, len), component);
3152 side_num =
t->side();
3159 std::string
err =
formatter() <<
"Could not load AI for side " << side_num <<
" from file " << file;
3173 side_num =
t->side();
3179 cfg =
config {
"ai", cfg};
3181 bool added_dummy_stage =
false;
3183 added_dummy_stage =
true;
3187 if(added_dummy_stage) {
3189 if(iter->key ==
"stage" && iter->cfg[
"name"] ==
"empty") {
3190 iter = cfg.
erase(iter);
3201 if(i < 1 || i > teams().
size())
return 0;
3213 LOG_LUA <<
"intf_get_sides called: this = " << std::hex <<
this << std::dec <<
" myname = " << my_name() << std::endl;
3214 std::vector<int> sides;
3230 for(
int side : sides) {
3247 const std::string&
id = trait[
"id"];
3271 if (sm ==
"advance") {
3275 if (sm !=
"advancement" && sm !=
"object" && sm !=
"trait") {
3278 bool write_to_mods =
true;
3283 write_to_mods =
false;
3307 if(obj.matches(filter)) {
3308 obj[
"duration"] =
"now";
3347 std::stringstream ss;
3348 ss <<
"unknown unit type: '" << ty <<
"'";
3366 std::string team_name;
3369 std::vector<std::string> team_names;
3370 std::transform(teams.begin(), teams.end(), std::back_inserter(team_names),
3371 [&](
int team) {
return game_state_.get_disp_context().get_team(
team).team_name(); });
3374 team_name = cfg[
"team_name"].str();
3377 if (game_display_) {
3378 game_display_->add_overlay(loc, cfg[
"image"], cfg[
"halo"],
3379 team_name, cfg[
"name"], cfg[
"visible_in_fog"].to_bool(
true), cfg[
"z_order"].to_double(0));
3395 if (game_display_) {
3396 game_display_->remove_single_overlay(loc, m);
3399 if (game_display_) {
3400 game_display_->remove_overlay(loc);
3410 if(nargs < 2 || nargs > 3) {
3411 return luaL_error(L,
"Wrong number of arguments to ai.log_replay() - should be 2 or 3 arguments.");
3420 return luaL_argerror(L, 3,
"accepts only string or config");
3433 if (!cfg[
"delayed_variable_substitution"].to_bool(
true)) {
3449 if (game_display_) {
3452 game_display_->adjust_color_overlay(cfg[
"red"], cfg[
"green"], cfg[
"blue"]);
3453 game_display_->invalidate_all();
3454 game_display_->draw(
true,
true);
3473 play_controller_.play_slice(
false);
3476 if(
luaW_toboolean(L, 2) && game_display_ && game_display_->turbo_speed() > 0) {
3477 delay /= game_display_->turbo_speed();
3479 const unsigned final = SDL_GetTicks() + delay;
3481 play_controller_.play_slice(
false);
3483 }
while (static_cast<int>(
final - SDL_GetTicks()) > 0);
3489 if (game_display_) {
3496 screen.
labels().
set_label(label.location(), label.text(), label.creator(), label.team_name(), label.color(),
3497 label.visible_in_fog(), label.visible_in_shroud(), label.immutable(), label.category(), label.tooltip());
3504 if (game_display_) {
3519 for (
const int side : filter.
get_teams()){
3530 screen.
draw(
true,
true);
3543 int side = cfg[
"side"];
3591 if (ct ==
"candidate_action") {
3601 if (ct ==
"stage") {
3614 for (std::vector<std::string>::const_iterator
t = c_types.begin();
t != c_types.end(); ++
t)
3617 std::string
type = *
t;
3618 if (type ==
"aspect" || type ==
"goal" || type ==
"engine")
3626 for (std::vector<ai::component*>::const_iterator
i = children.begin();
i != children.end(); ++
i)
3666 std::vector<ai::component*> engines = c->
get_children(
"engine");
3668 for (std::vector<ai::component*>::const_iterator
i = engines.begin();
i != engines.end(); ++
i)
3670 if ((*i)->get_name() ==
"lua")
3680 if (lua_engine ==
nullptr)
3693 LOG_LUA <<
"Created new dummy lua-engine for debug_ai(). \n";
3722 gamedata().set_allow_end_turn(allow, reason);
3730 play_controller_.pump().set_undo_disabled(!
luaW_toboolean(L, 1));
3733 play_controller_.pump().set_undo_disabled(
false);
3740 play_controller_.pump().set_action_canceled();
3750 const std::string
id = cfg[
"id"];
3752 std::set<map_location> locs;
3753 const terrain_filter filter(cfg, &game_state_,
false);
3754 filter.get_locations(locs,
true);
3756 tod_man().add_time_area(
id, locs, parsed_cfg);
3757 LOG_LUA <<
"Lua inserted time_area '" <<
id <<
"'\n";
3767 tod_man().remove_time_area(
id);
3768 LOG_LUA <<
"Lua removed time_area '" <<
id <<
"'\n";
3779 ERR_LUA <<
"attempted to to replace ToD schedule with empty schedule" << std::endl;
3782 if (game_display_) {
3783 game_display_->new_turn();
3785 LOG_LUA <<
"replaced ToD schedule\n";
3792 if(!game_display_) {
3795 std::string area_id;
3796 std::size_t area_i = 0;
3799 std::vector<std::string> area_ids = tod_man().get_area_ids();
3800 area_i = std::distance(area_ids.begin(), std::find(area_ids.begin(), area_ids.end(), area_id));
3801 if(area_i >= area_ids.size()) {
3807 const std::vector<time_of_day>& times = area_id.empty()
3809 : tod_man().times(area_i);
3810 int num_times = times.size();
3815 if(time_id == time.id) {
3820 if(new_time >= num_times) {
3825 if(new_time == 0 && num_times == 0) {
3829 if(new_time < 0 || new_time >= num_times) {
3833 if(area_id.empty()) {
3834 tod_man().set_current_time(new_time);
3836 tod_man().set_current_time(new_time, area_i);
3845 if (game_display_) {
3846 game_display_->scroll(x, y,
true);
3847 game_display_->draw(
true,
true);
3858 lua_report_generator(
lua_State *L,
const std::string &
n)
3859 : mState(L),
name(n) {}
3881 reports::context temp_context =
reports::context(board(), *game_display_, tod_man(), play_controller_.get_whiteboard(), play_controller_.get_mouse_handler_base());
3882 luaW_pushconfig(L, reports_.generate_report(m.c_str(), temp_context ,
true));
3896 reports_.register_generator(m,
new lua_report_generator(L, m));
3909 reports_.register_generator(m,
new lua_report_generator(L, m));
3939 if (dst == u->get_location() || !map().on_board(dst)) {
3943 if (!map().on_board(vacant_dst)) {
3948 if ( clear_shroud ) {
3954 std::vector<map_location> teleport_path;
3955 teleport_path.push_back(src_loc);
3956 teleport_path.push_back(vacant_dst);
3959 units().move(src_loc, vacant_dst);
3962 u = units().find(vacant_dst).get_shared_ptr();
3963 u->anim_comp().set_standing();
3965 if ( clear_shroud ) {
3970 if (map().is_village(vacant_dst)) {
3974 game_display_->invalidate_unit_after_move(src_loc, vacant_dst);
3975 game_display_->draw();
4007 ERR_LUA <<
"Error when parsing sound_source config: invalid parameter." << std::endl;
4008 ERR_LUA <<
"sound_source config was: " << cfg.
debug() << std::endl;
4009 ERR_LUA <<
"Skipping this sound source..." << std::endl;
4047 if(logger ==
"wml" || logger ==
"WML") {
4051 game_state_.events_manager_->pump().put_wml_message(logger,msg,in_chat);
4060 if(side < 1 || static_cast<std::size_t>(side) > teams().
size()) {
4061 std::string
error =
"side " + std::to_string(side) +
" does not exist";
4065 team&
t = board().get_team(side);
4084 bool affect_normal_fog =
false;
4088 std::set<int> sides;
4092 const auto& v = lua_check<std::vector<int>>(L, 1);
4093 sides.insert(v.begin(), v.end());
4095 for(
const team&
t : teams()) {
4096 sides.insert(
t.side()+1);
4099 const auto& v_locs = lua_check<std::vector<map_location>>(L,
lua_istable(L, 2) ? 2 : 1);
4100 std::set<map_location> locs(v_locs.begin(), v_locs.end());
4102 for(
const int &side_num : sides) {
4103 if(side_num < 1 || static_cast<std::size_t>(side_num) > teams().size()) {
4106 team &
t = board().get_team(side_num);
4110 if(affect_normal_fog) {
4113 }
else if(!affect_normal_fog) {
4125 game_display_->recalculate_minimap();
4126 game_display_->invalidate_all();
4138 if(!
luaW_getglobal(L,
"wesnoth",
"custom_synced_commands", name)) {
4142 cmd_tag[
"name"] =
name;
4160 return game_state_.board_;
4164 return game_state_.board_.units();
4168 return game_state_.board_.teams();
4172 return game_state_.board_.map();
4176 return game_state_.gamedata_;
4180 return game_state_.tod_manager_;
4184 return *queued_events_.top();
4190 , game_display_(nullptr)
4192 , play_controller_(pc)
4193 , reports_(reports_object)
4203 cmd_log_ <<
"Registering game-specific wesnoth lib functions...\n";
4206 static luaL_Reg const callbacks[] {
4208 {
"create_animator", &dispatch<&game_lua_kernel::intf_create_animator> },
4219 {
"add_event_handler", &dispatch<&game_lua_kernel::intf_add_event > },
4220 {
"add_fog", &dispatch2<&game_lua_kernel::intf_toggle_fog, false > },
4221 {
"add_time_area", &dispatch<&game_lua_kernel::intf_add_time_area > },
4222 {
"add_sound_source", &dispatch<&game_lua_kernel::intf_add_sound_source > },
4223 {
"allow_end_turn", &dispatch<&game_lua_kernel::intf_allow_end_turn > },
4224 {
"allow_undo", &dispatch<&game_lua_kernel::intf_allow_undo > },
4225 {
"cancel_action", &dispatch<&game_lua_kernel::intf_cancel_action > },
4226 {
"clear_messages", &dispatch<&game_lua_kernel::intf_clear_messages > },
4227 {
"end_turn", &dispatch<&game_lua_kernel::intf_end_turn > },
4228 {
"end_level", &dispatch<&game_lua_kernel::intf_end_level > },
4229 {
"find_cost_map", &dispatch<&game_lua_kernel::intf_find_cost_map > },
4230 {
"find_path", &dispatch<&game_lua_kernel::intf_find_path > },
4231 {
"find_reach", &dispatch<&game_lua_kernel::intf_find_reach > },
4232 {
"find_vacant_tile", &dispatch<&game_lua_kernel::intf_find_vacant_tile > },
4233 {
"fire_event", &dispatch2<&game_lua_kernel::intf_fire_event, false > },
4234 {
"fire_event_by_id", &dispatch2<&game_lua_kernel::intf_fire_event, true > },
4235 {
"get_all_vars", &dispatch<&game_lua_kernel::intf_get_all_vars > },
4236 {
"get_end_level_data", &dispatch<&game_lua_kernel::intf_get_end_level_data > },
4237 {
"get_locations", &dispatch<&game_lua_kernel::intf_get_locations > },
4238 {
"get_map_size", &dispatch<&game_lua_kernel::intf_get_map_size > },
4239 {
"get_sound_source", &dispatch<&game_lua_kernel::intf_get_sound_source > },
4240 {
"get_terrain", &dispatch<&game_lua_kernel::intf_get_terrain > },
4241 {
"get_terrain_info", &dispatch<&game_lua_kernel::intf_get_terrain_info > },
4242 {
"get_time_of_day", &dispatch<&game_lua_kernel::intf_get_time_of_day > },
4243 {
"get_max_liminal_bonus", &dispatch<&game_lua_kernel::intf_get_max_liminal_bonus > },
4244 {
"get_variable", &dispatch<&game_lua_kernel::intf_get_variable > },
4245 {
"get_villages", &dispatch<&game_lua_kernel::intf_get_villages > },
4246 {
"get_village_owner", &dispatch<&game_lua_kernel::intf_get_village_owner > },
4247 {
"label", &dispatch<&game_lua_kernel::intf_label > },
4248 {
"log_replay", &dispatch<&game_lua_kernel::intf_log_replay > },
4249 {
"log", &dispatch<&game_lua_kernel::intf_log > },
4250 {
"match_location", &dispatch<&game_lua_kernel::intf_match_location > },
4251 {
"message", &dispatch<&game_lua_kernel::intf_message > },
4252 {
"open_help", &dispatch<&game_lua_kernel::intf_open_help > },
4253 {
"play_sound", &dispatch<&game_lua_kernel::intf_play_sound > },
4254 {
"print", &dispatch<&game_lua_kernel::intf_print > },
4255 {
"redraw", &dispatch<&game_lua_kernel::intf_redraw > },
4256 {
"remove_event_handler", &dispatch<&game_lua_kernel::intf_remove_event > },
4257 {
"remove_fog", &dispatch2<&game_lua_kernel::intf_toggle_fog, true > },
4258 {
"remove_time_area", &dispatch<&game_lua_kernel::intf_remove_time_area > },
4259 {
"remove_sound_source", &dispatch<&game_lua_kernel::intf_remove_sound_source > },
4260 {
"replace_schedule", &dispatch<&game_lua_kernel::intf_replace_schedule > },
4261 {
"select_hex", &dispatch<&game_lua_kernel::intf_select_hex > },
4262 {
"set_time_of_day", &dispatch<&game_lua_kernel::intf_set_time_of_day > },
4263 {
"is_fogged", &dispatch2<&game_lua_kernel::intf_get_fog_or_shroud, true > },
4264 {
"is_shrouded", &dispatch2<&game_lua_kernel::intf_get_fog_or_shroud, false > },
4265 {
"set_end_campaign_credits", &dispatch<&game_lua_kernel::intf_set_end_campaign_credits > },
4266 {
"set_end_campaign_text", &dispatch<&game_lua_kernel::intf_set_end_campaign_text > },
4267 {
"create_side", &dispatch<&game_lua_kernel::intf_create_side > },
4268 {
"set_next_scenario", &dispatch<&game_lua_kernel::intf_set_next_scenario > },
4269 {
"set_terrain", &dispatch<&game_lua_kernel::intf_set_terrain > },
4270 {
"set_variable", &dispatch<&game_lua_kernel::intf_set_variable > },
4271 {
"set_village_owner", &dispatch<&game_lua_kernel::intf_set_village_owner > },
4272 {
"simulate_combat", &dispatch<&game_lua_kernel::intf_simulate_combat > },
4275 {
"terrain_mask", &dispatch<&game_lua_kernel::intf_terrain_mask > },
4276 {
"teleport", &dispatch<&game_lua_kernel::intf_teleport > },
4277 {
"place_shroud", &dispatch2<&game_lua_kernel::intf_shroud_op, true > },
4278 {
"remove_shroud", &dispatch2<&game_lua_kernel::intf_shroud_op, false > },
4279 {
nullptr,
nullptr }
4287 static luaL_Reg const test_callbacks[] {
4288 {
"fire_wml_menu_item", &dispatch<&game_lua_kernel::intf_fire_wml_menu_item > },
4289 {
nullptr,
nullptr }
4321 cmd_log_ <<
"Adding ai elements table...\n";
4326 cmd_log_ <<
"Adding wesnoth current table...\n";
4346 cmd_log_ <<
"Adding units module...\n";
4347 static luaL_Reg const unit_callbacks[] {
4350 {
"erase", &dispatch<&game_lua_kernel::intf_erase_unit>},
4351 {
"extract", &dispatch<&game_lua_kernel::intf_extract_unit>},
4352 {
"matches", &dispatch<&game_lua_kernel::intf_match_unit>},
4353 {
"select", &dispatch<&game_lua_kernel::intf_select_unit>},
4354 {
"to_map", &dispatch<&game_lua_kernel::intf_put_unit>},
4355 {
"to_recall", &dispatch<&game_lua_kernel::intf_put_recall_unit>},
4358 {
"ability", &dispatch<&game_lua_kernel::intf_unit_ability>},
4369 {
"find_on_map", &dispatch<&game_lua_kernel::intf_get_units>},
4370 {
"find_on_recall", &dispatch<&game_lua_kernel::intf_get_recall_units>},
4371 {
"get", &dispatch<&game_lua_kernel::intf_get_unit>},
4372 {
"get_hovered", &dispatch<&game_lua_kernel::intf_get_displayed_unit>},
4373 {
nullptr,
nullptr }
4382 cmd_log_ <<
"Adding sides module...\n";
4383 static luaL_Reg const side_callbacks[] {
4384 {
"is_enemy", &dispatch<&game_lua_kernel::intf_is_enemy> },
4385 {
"matches", &dispatch<&game_lua_kernel::intf_match_side> },
4386 {
"set_id", &dispatch<&game_lua_kernel::intf_set_side_id> },
4391 {
"find", &dispatch<&game_lua_kernel::intf_get_sides> },
4392 {
"get", &dispatch<&game_lua_kernel::intf_get_side> },
4393 {
nullptr,
nullptr }
4395 std::vector<lua_cpp::Reg>
const cpp_side_callbacks {
4396 {
"add_ai_component", std::bind(
intf_modify_ai, std::placeholders::_1,
"add")},
4397 {
"delete_ai_component", std::bind(
intf_modify_ai, std::placeholders::_1,
"delete")},
4398 {
"change_ai_component", std::bind(
intf_modify_ai, std::placeholders::_1,
"change")},
4410 cmd_log_ <<
"Adding interface module...\n";
4411 static luaL_Reg const intf_callbacks[] {
4412 {
"add_hex_overlay", &dispatch<&game_lua_kernel::intf_add_tile_overlay>},
4413 {
"remove_hex_overlay", &dispatch<&game_lua_kernel::intf_remove_tile_overlay>},
4414 {
"color_adjust", &dispatch<&game_lua_kernel::intf_color_adjust>},
4415 {
"delay", &dispatch<&game_lua_kernel::intf_delay>},
4416 {
"deselect_hex", &dispatch<&game_lua_kernel::intf_deselect_hex>},
4417 {
"highlight_hex", &dispatch<&game_lua_kernel::intf_highlight_hex>},
4418 {
"float_label", &dispatch<&game_lua_kernel::intf_float_label>},
4419 {
"get_displayed_unit", &dispatch<&game_lua_kernel::intf_get_displayed_unit>},
4420 {
"get_hovered_hex", &dispatch<&game_lua_kernel::intf_get_mouseover_tile>},
4421 {
"get_selected_hex", &dispatch<&game_lua_kernel::intf_get_selected_tile>},
4422 {
"lock", &dispatch<&game_lua_kernel::intf_lock_view>},
4423 {
"is_locked", &dispatch<&game_lua_kernel::intf_view_locked>},
4424 {
"scroll", &dispatch<&game_lua_kernel::intf_scroll>},
4425 {
"scroll_to_hex", &dispatch<&game_lua_kernel::intf_scroll_to_tile>},
4426 {
"skip_messages", &dispatch<&game_lua_kernel::intf_skip_messages>},
4427 {
"is_skipping_messages", &dispatch<&game_lua_kernel::intf_is_skipping_messages>},
4428 {
"zoom", &dispatch<&game_lua_kernel::intf_zoom>},
4429 {
"clear_menu_item", &dispatch<&game_lua_kernel::intf_clear_menu_item>},
4430 {
"set_menu_item", &dispatch<&game_lua_kernel::intf_set_menu_item>},
4431 {
nullptr,
nullptr }
4443 cmd_log_ <<
"Adding wml_actions table...\n";
4451 cmd_log_ <<
"Adding wml_conditionals table...\n";
4462 cmd_log_ <<
"Adding effects table...\n";
4470 cmd_log_ <<
"Adding custom_synced_commands table...\n";
4478 cmd_log_ <<
"Adding game_events table...\n";
4488 cmd_log_ <<
"Adding game_display table...\n";
4523 cmd_log_ <<
"Adding races table...\n";
4532 cmd_log_ <<
"Running preload scripts...\n";
4535 for (
const config &cfg : game_lua_kernel::preload_scripts) {
4582 if (s ==
t)
return true;
4644 const std::string m =
"Tag is already used: [" + i->key +
"]";
4674 if (!
luaW_getglobal(L,
"wesnoth",
"custom_synced_commands", name)) {
4832 lg::wml_error() <<
"unknown conditional wml: [" << cmd <<
"]\n";
4902 std::string message = std::string() +
"function " + name +
" not found";
4903 log_error(message.c_str(),
"Lua SUF Error");
4958 ERR_LUA <<
"Effect __descr metafunction should have returned a string, but instead returned ";
4967 }
else if(need_apply) {
4996 if (!
luaW_getglobal(L,
"wesnoth",
"game_events",
"on_mouse_move")) {
5009 if (!
luaW_getglobal(L,
"wesnoth",
"game_events",
"on_mouse_action")) {
const_attack_ptr weapon
The weapon used by the unit to attack the opponent, or nullptr if there is none.
bool luaW_checkvariable(lua_State *L, variable_access_create &v, int n)
int dispatch(lua_State *L)
#define modify_bool_attrib(name, accessor)
bool luaW_tableget(lua_State *L, int index, const char *key)
play_controller * controller
int intf_get_terrain_info(lua_State *L)
Gets details about a terrain.
static int intf_transform_unit(lua_State *L)
Changes a unit to the given unit type.
#define lua_isnoneornil(L, n)
void wait_for_end() const
unsigned int end_text_duration
for how long the end-of-campaign text is shown
bool empty() const
Tests for an attribute that either was never set or was set to "".
LUA_API void lua_pushlightuserdata(lua_State *L, void *p)
static int impl_end_level_data_get(lua_State *L)
LUALIB_API void * luaL_checkudata(lua_State *L, int ud, const char *tname)
config get_user_choice(const std::string &name, const user_choice &uch, int side=0)
std::stack< game_events::queued_event const *> queued_events_
static synced_state get_synced_state()
LUA_API void lua_createtable(lua_State *L, int narray, int nrec)
#define lua_pushcfunction(L, f)
static int intf_advance_unit(lua_State *L)
Advances a unit if the unit has enough xp.
static int intf_get_era(lua_State *L)
Gets a table for an era tag.
static int special_locations_pairs(lua_State *L)
virtual std::string get_id() const =0
int map_locked_
A value != 0 means that the shouldn't remove any units from the map, usually because we are currently...
std::string apply_effect(const std::string &name, unit &u, const config &cfg, bool need_apply)
config & child(config_key_type key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
lua_unit * luaW_pushunit(lua_State *L, Args... args)
int h() const
Effective map height, in hexes.
bool end_credits
whether to show the standard credits at the end
void set_shroud(bool shroud)
double untouched
Resulting chance we were not hit by this opponent (important if it poisons)
std::vector< double > hp_dist
Resulting probability distribution (might be not as large as max_hp)
bool update_locked() const
Whether the screen has been 'locked' or not.
void show_help(const std::string &show_topic, int xloc, int yloc)
Open the help browser, show topic with id show_topic.
LUA_API lua_Number lua_tonumberx(lua_State *L, int idx, int *pisnum)
static display * get_singleton()
Returns the display object if a display object exists.
int intf_remove_sound_source(lua_State *L)
Removes a sound source by its ID Arg 1: sound source ID.
int intf_allow_end_turn(lua_State *)
Allow undo sets the flag saying whether the event has mutated the game to false.
const_all_children_itors all_children_range() const
In-order iteration over all children.
const unit_type * find(const std::string &key, unit_type::BUILD_STATUS status=unit_type::FULL) const
Finds a unit_type by its id() and makes sure it is built to the specified level.
int intf_find_path(lua_State *L)
Finds a path between two locations.
const terrain_code NONE_TERRAIN
bool luaW_tovconfig(lua_State *L, int index, vconfig &vcfg)
Gets an optional vconfig from either a table or a userdata.
std::string register_metatables(lua_State *L)
vconfig child(const std::string &key) const
Returns a child of *this whose key is key.
int intf_set_end_campaign_credits(lua_State *L)
const t_string & description() const
LUALIB_API lua_Number luaL_checknumber(lua_State *L, int arg)
game_display * game_display_
void luaW_pushconfig(lua_State *L, const config &cfg)
Converts a config object to a Lua table pushed at the top of the stack.
LUA_API void lua_settop(lua_State *L, int idx)
int intf_fire_event(lua_State *L, const bool by_id)
Fires an event.
int intf_get_time_of_day(lua_State *L)
Gets time of day information.
int intf_get_unit(lua_State *)
Gets the unit at the given location or with the given id.
LUA_API int lua_type(lua_State *L, int idx)
bool luaW_pcall(lua_State *L, int nArgs, int nRets, bool allow_wml_error)
Calls a Lua function stored below its nArgs arguments at the top of the stack.
void luaW_pushteam(lua_State *L, team &tm)
Create a full userdata containing a pointer to the team.
std::string plague_type
The plague type used by the attack, if any.
This class represents a single unit of a specific type.
game_classification * classification
int intf_get_variable(lua_State *L)
Gets a WML variable.
tod_color color
The color modifications that should be made to the game board to reflect the time of day...
int movement_cost(const t_translation::terrain_code &terrain) const
Get the unit's movement cost on a particular terrain.
int intf_match_location(lua_State *L)
Matches a location against the given filter.
std::string join(const T &v, const std::string &s=",")
Generates a new string joining container items in a list.
void advance_to(const unit_type &t, bool use_traits=false)
Advances this unit to another type.
std::vector< int > get_sides_vector(const vconfig &cfg)
Gets a vector of sides from side= attribute in a given config node.
Various functions implementing vision (through fog of war and shroud).
int luaW_type_error(lua_State *L, int narg, const char *tname)
bool run_filter(char const *name, const unit &u)
Runs a script from a unit filter.
int impl_theme_items_get(lua_State *L)
Creates a field of the theme_items table and returns it (__index metamethod).
int intf_replace_schedule(lua_State *l)
Replacing the current time of day schedule.
static int special_locations_len(lua_State *L)
bool play_stage()
Play the turn - strategy.
void set_clip_rect(const SDL_Rect &r)
unit & luaW_checkunit(lua_State *L, int index, bool only_on_map)
Converts a Lua value to a unit pointer.
static manager & get_singleton()
config_array_view traits() const
LUA_API void lua_pushboolean(lua_State *L, int b)
LUA_API int lua_rawgeti(lua_State *L, int idx, lua_Integer n)
Various functions that implement attacks and attack calculations.
int impl_end_level_data_set(lua_State *)
Variant for storing WML attributes.
int intf_view_locked(lua_State *L)
Gets whether gamemap scrolling is disabled for the user.
Add a special kind of assert to validate whether the input from WML doesn't contain any problems that...
bool luaW_isunit(lua_State *L, int index)
Test if a Lua value is a unit.
bool clear_fog(const map_location &loc)
void add_log_data(const std::string &key, const std::string &var)
virtual std::vector< component * > get_children(const std::string &type)
std::vector< team > & teams()
static const char animatorKey[]
static l_noret error(LoadState *S, const char *why)
int intf_set_terrain(lua_State *L)
Sets a terrain code.
int intf_log(lua_State *L)
Logs a message Arg 1: (optional) Logger; "wml" for WML errors or deprecations Arg 2: Message Arg 3: W...
config_array_view child_range(config_key_type key) const
static map & registry()
using static function variable instead of static member variable to prevent static initialization fia...
int intf_clear_messages(lua_State *)
Removes all messages from the chat window.
bool has_child(config_key_type key) const
Determine whether a config has a child or not.
int intf_play_sound(lua_State *L)
Plays a sound, possibly repeated.
int intf_terrain_mask(lua_State *L)
Reaplces part of the map.
static int impl_animator_get(lua_State *L)
bool have_location(const vconfig &cfg)
int intf_label(lua_State *L)
static int special_locations_newindex(lua_State *L)
bool has_attribute(const std::string &key) const
< Synonym for operator[]
map_location find_vacant_tile(const map_location &loc, VACANT_TILE_TYPE vacancy, const unit *pass_check, const team *shroud_check, const game_board *board)
Function that will find a location on the board that is as near to loc as possible, but which is unoccupied by any units.
LUA_API void lua_rawseti(lua_State *L, int idx, lua_Integer n)
LUALIB_API int luaL_getmetafield(lua_State *L, int obj, const char *event)
LUA_API int lua_gettop(lua_State *L)
child_itors child_range(config_key_type key)
std::string register_table(lua_State *L)
int border_size() const
Size of the map border.
int intf_extract_unit(lua_State *L)
Extracts a unit from the map or a recall list and gives it to Lua.
double average_hp(unsigned int healing=0) const
What's the average hp (weighted average of hp_dist).
const map_location & filter_loc() const
bool luaW_pushvariable(lua_State *L, variable_access_const &v)
static int intf_copy_unit(lua_State *L)
Copies a unit.
void remove_floating_label(int handle)
removes the floating label given by 'handle' from the screen
std::string register_metatable(lua_State *L)
static int special_locations_next(lua_State *L)
int intf_get_all_vars(lua_State *L)
Gets all the WML variables currently set.
LUA_API int lua_getglobal(lua_State *L, const char *name)
int intf_find_cost_map(lua_State *L)
Is called with one or more units and builds a cost map.
void clear(const std::string &key)
int lawful_bonus
The % bonus lawful units receive.
#define return_string_attrib(name, accessor)
#define lua_tointeger(L, i)
int intf_set_time_of_day(lua_State *L)
const std::string & gamedata
virtual config to_config() const
Serialize to config.
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
static int special_locations_index(lua_State *L)
static lua_ai_context * create(lua_State *L, char const *code, engine_lua *engine)
LUA_API int lua_rawget(lua_State *L, int idx)
std::string image
The image to be displayed in the game status.
unit_type_data unit_types
int intf_get_fog_or_shroud(lua_State *L, bool fog)
static int cfun_wml_condition(lua_State *L)
Executes its upvalue as a wml condition and returns the result.
bool prescenario_save
Should a prescenario be created the next game?
int intf_set_village_owner(lua_State *L)
Sets the owner of a village.
lua_unit * luaW_pushlocalunit(lua_State *L, unit &u)
Pushes a private unit on the stack.
const color_t LABEL_COLOR
int intf_unit_ability(lua_State *L)
Returns true if the unit has the given ability enabled.
int intf_match_unit(lua_State *L)
Matches a unit against the given filter.
int intf_set_next_scenario(lua_State *L)
void push_builtin_effect()
Registers a function for use as an effect handler.
static CVideo & get_singleton()
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
#define lua_tonumber(L, i)
config & child_or_add(config_key_type key)
advance_unit_params & fire_events(bool value)
bool replay_save
Should a replay save be made?
void remove(const std::string &id)
std::string save_id_or_number() const
void custom_command(const std::string &, const config &)
Additional functionality for a non-const variable_info.
bool slows
Attack slows opponent when it hits.
int intf_skip_messages(lua_State *L)
Set whether to skip messages Arg 1 (optional) - boolean.
void set_font_size(int font_size)
LUA_API int lua_isuserdata(lua_State *L, int idx)
const std::string & editor_image() const
LUA_API void lua_pushcclosure(lua_State *L, lua_CFunction fn, int n)
int intf_scroll(lua_State *L)
virtual void draw()
Draws invalidated items.
int impl_theme_items_set(lua_State *L)
Sets a field of the theme_items table (__newindex metamethod).
void append_children(const config &cfg)
Adds children from cfg.
#define return_vector_string_attrib(name, accessor)
int intf_get_max_liminal_bonus(lua_State *L)
Gets the max liminal bonus.
static bool is_handled_file_tag(const std::string &s)
int intf_get_sides(lua_State *L)
Returns a proxy table array for all sides matching the given SSF.
void lua_push(lua_State *L, const T &val)
void add_unit(const unit &u, bool use_max_moves=true)
Adds a units cost map to cost_map (increments the elements in cost_map)
int drain_constant
Base HP drained regardless of damage dealt.
An object to leave the synced context during draw or unsynced wml items when we don’t know whether w...
int(game_lua_kernel::* member_callback2)(lua_State *, bool)
int intf_gamestate_inspector(lua_State *)
static std::string _(const char *str)
int impl_game_config_set(lua_State *L) override
Sets some game_config data (__newindex metamethod).
void(* handler)(const queued_event &, const vconfig &)
map_location luaW_checklocation(lua_State *L, int index)
Converts an optional table or pair of integers to a map location object.
Definitions for the interface to Wesnoth Markup Language (WML).
const game_events::queued_event & get_event_info()
LUA_API int lua_absindex(lua_State *L, int idx)
std::shared_ptr< unit > unit_ptr
void load_config(const config &v)
unsigned int chance_to_hit
Effective chance to hit as a percentage (all factors accounted for).
std::map< int, config > get_user_choice_multiple_sides(const std::string &name, const user_choice &uch, std::set< int > sides)
Performs a choice for multiple sides for WML events.
static unit_ptr create(const config &cfg, bool use_traits=false, const vconfig *vcfg=nullptr)
Initializes a unit from a config.
const_attr_itors attribute_range() const
A single unit type that the player may recruit.
int intf_get_locations(lua_State *L)
Gets all the locations matching a given filter.
int intf_log_replay(lua_State *L)
advance_unit_params & animate(bool value)
Unit and team statistics.
terrain_code read_terrain_code(std::string_view str, const ter_layer filler)
Reads a single terrain from a string.
void play_sound(const std::string &files, channel_group group, unsigned int repeats)
void append_active_ai_for_side(ai::side_number side, const config &cfg)
Appends AI parameters to active AI of the given side.
#define return_cfgref_attrib(name, accessor)
bool clear_dest(const map_location &dest, const unit &viewer)
Clears shroud (and fog) at the provided location and its immediate neighbors.
bool reveal_map
Should we reveal map when game is ended? (Multiplayer only)
bool have_unit(const vconfig &cfg)
bool clear_unit(const map_location &view_loc, team &view_team, std::size_t viewer_id, int sight_range, bool slowed, const movetype::terrain_costs &costs, const map_location &real_loc, const std::set< map_location > *known_units=nullptr, std::size_t *enemy_count=nullptr, std::size_t *friend_count=nullptr, move_unit_spectator *spectator=nullptr, bool instant=true)
Clears shroud (and fog) around the provided location for view_team based on sight_range, costs, and slowed.
int intf_find_reach(lua_State *L)
Finds all the locations reachable by a unit.
void set_game_display(game_display *gd)
bool poisons
Attack poisons opponent when it hits.
int vision_cost(const t_translation::terrain_code &terrain) const
Get the unit's vision cost on a particular terrain.
int intf_set_variable(lua_State *L)
Sets a WML variable.
LUALIB_API const char * luaL_optlstring(lua_State *L, int arg, const char *def, size_t *len)
std::string register_metatable(lua_State *L)
void set_flag(const std::string &flag)
std::shared_ptr< const unit > unit_const_ptr
int intf_delay(lua_State *L)
Delays engine for a while.