118 #include <functional>
136 #define DBG_LUA LOG_STREAM(debug, log_scripting_lua)
137 #define LOG_LUA LOG_STREAM(info, log_scripting_lua)
138 #define WRN_LUA LOG_STREAM(warn, log_scripting_lua)
139 #define ERR_LUA LOG_STREAM(err, log_scripting_lua)
142 #define ERR_WML LOG_STREAM(err, log_wml)
150 template <member_callback method>
152 return ((lua_kernel_base::get_lua_kernel<game_lua_kernel>(L)).*method)(L);
158 template <member_callback2 method,
bool b>
160 return ((lua_kernel_base::get_lua_kernel<game_lua_kernel>(L)).*method)(L,
b);
207 const vconfig &ssf =
cfg.child(
"filter_side");
210 if(!sides.
empty()) {
WRN_LUA <<
"ignoring duplicate side filter information (inline side=)"; }
212 return filter.get_teams();
216 return filter.get_teams();
228 struct queued_event_context
231 std::stack<qe const *> & stack_;
233 queued_event_context(qe
const *new_qe, std::stack<qe const*> & stack)
239 ~queued_event_context()
254 lua_pushinteger(L, disp->viewing_team().side());
255 lua_pushboolean(L, disp->show_everything());
273 anim.~unit_animator();
282 std::string which = luaL_checkstring(L, 3);
284 std::string hits_str = luaL_checkstring(L, 4);
294 if(lua_istable(L, 5)) {
295 lua_getfield(L, 5,
"target");
298 return luaL_argerror(L, 5,
"target location must be different from animated unit's location");
300 return luaL_argerror(L, 5,
"target location must be adjacent to the animated unit");
305 if(!lua_isnoneornil(L, -1)) {
311 lua_getfield(L, 5,
"value");
312 if(lua_isnumber(L, -1)) {
313 v1 = lua_tointeger(L, -1);
314 }
else if(lua_istable(L, -1)) {
315 lua_rawgeti(L, -1, 1);
316 v1 = lua_tointeger(L, -1);
318 lua_rawgeti(L, -1, 2);
319 v2 = lua_tointeger(L, -1);
321 }
else if(!lua_isnoneornil(L, -1)) {
322 return luaW_type_error(L, 5,
"value",
"number or array of two numbers");
326 lua_getfield(L, 5,
"with_bars");
327 if(lua_isboolean(L, -1)) {
329 }
else if(!lua_isnoneornil(L, -1)) {
330 return luaW_type_error(L, 5,
"with_bars", lua_typename(L, LUA_TBOOLEAN));
334 lua_getfield(L, 5,
"text");
335 if(lua_isstring(L, -1)) {
336 text = lua_tostring(L, -1);
339 }
else if(!lua_isnoneornil(L, -1)) {
344 lua_getfield(L, 5,
"color");
345 if(lua_istable(L, -1) && lua_rawlen(L, -1) == 3) {
346 int idx = lua_absindex(L, -1);
347 lua_rawgeti(L, idx, 1);
348 lua_rawgeti(L, idx, 2);
349 lua_rawgeti(L, idx, 3);
350 color =
color_t(lua_tointeger(L, -3), lua_tointeger(L, -2), lua_tointeger(L, -1));
352 }
else if(!lua_isnoneornil(L, -1)) {
357 lua_getfield(L, 5,
"primary");
359 if(!primary && !lua_isnoneornil(L, -1)) {
364 lua_getfield(L, 5,
"secondary");
366 if(!secondary && !lua_isnoneornil(L, -1)) {
370 }
else if(!lua_isnoneornil(L, 5)) {
374 anim.
add_animation(up, which, u.
get_location(), dest, v1, bars, text, color, hits, primary, secondary, v2);
402 const char* m = lua_tostring(L, 2);
410 luaL_Reg metafuncs[] {
414 {
"run", &dispatch<&game_lua_kernel::impl_run_animation>},
418 luaL_setfuncs(L, metafuncs, 0);
419 lua_pushstring(L,
"__metatable");
422 lua_setmetatable(L, -2);
432 name =
cfg[
"name"].str();
435 name = luaL_optstring(L, 1,
"");
453 if(lua_isstring(L, 1) && !lua_isnumber(L, 1)) {
454 std::string
id = luaL_checkstring(L, 1);
464 return luaL_argerror(L, 1,
"expected string or location");
468 if (!ui.
valid())
return 0;
489 if (!ui.
valid())
return 0;
507 std::vector<const unit*>
units;
511 return luaL_argerror(L, 2,
"unit not found");
514 }
else if(!lua_isnoneornil(L, 2)) {
518 return luaL_argerror(L, 2,
"invalid location");
533 lua_rawseti(L, 1,
i);
553 lua_pushboolean(L,
true);
559 WRN_LUA <<
"wesnoth.units.matches called with a secondary unit (3rd argument), ";
560 WRN_LUA <<
"but unit to match was on recall list. ";
561 WRN_LUA <<
"Thus the 3rd argument is ignored.";
568 return luaL_argerror(L, 3,
"unit not found");
608 t.save_id_or_number(),
t.recall_list().find_index(u->id()));
613 lua_rawseti(L, 1,
i);
632 char const *m = luaL_checkstring(L, 1);
649 if(
data.has_child(
"primary_attack")) {
650 data.add_child(
"first",
data.mandatory_child(
"primary_attack"));
651 data.remove_children(
"primary_attack");
653 if(
data.has_child(
"secondary_attack")) {
654 data.add_child(
"second",
data.mandatory_child(
"secondary_attack"));
655 data.remove_children(
"secondary_attack");
666 lua_pushboolean(L,
b);
684 char const *m = luaL_checkstring(L, 1);
689 lua_pushboolean(L,
b);
701 char const *m = luaL_checkstring(L, 1);
713 const std::string m = luaL_checkstring(L, 1);
714 if(m.empty())
return luaL_argerror(L, 1,
"empty variable name");
715 if (lua_isnoneornil(L, 2)) {
743 std::string ids(luaL_checkstring(L, 1));
746 WRN_LUA <<
"[clear_menu_item] has been given an empty id=, ignoring";
763 if(lua_istable(L, 2)) {
775 return luaL_argerror(L, 2,
"expected list of locations");
794 if(lua_istable(L, 2)) {
822 if(!
map().on_board(
loc))
return luaL_argerror(L, 1,
"not on board");
836 unsigned side_1, side_2;
840 side_1 = luaL_checkinteger(L, 1);
845 side_2 = luaL_checkinteger(L, 2);
848 lua_pushboolean(L,
board().get_team(side_1).
is_enemy(side_2));
882 lua_pushstring(L, tod.
id.c_str());
883 lua_setfield(L, -2,
"id");
885 lua_setfield(L, -2,
"lawful_bonus");
887 lua_setfield(L, -2,
"bonus_modified");
888 lua_pushstring(L, tod.
image.c_str());
889 lua_setfield(L, -2,
"image");
891 lua_setfield(L, -2,
"name");
892 lua_pushstring(L, tod.
sounds.c_str());
893 lua_setfield(L, -2,
"sound");
895 lua_setfield(L, -2,
"mask");
897 lua_pushinteger(L, tod.
color.
r);
898 lua_setfield(L, -2,
"red");
899 lua_pushinteger(L, tod.
color.
g);
900 lua_setfield(L, -2,
"green");
901 lua_pushinteger(L, tod.
color.
b);
902 lua_setfield(L, -2,
"blue");
909 lua_newuserdatauv(L, 0, 1);
910 lua_pushinteger(L, area_index);
911 lua_setiuservalue(L, -2, 1);
912 if(luaL_newmetatable(L,
"schedule")) {
913 static luaL_Reg
const schedule_meta[] {
914 {
"__index", &dispatch<&game_lua_kernel::impl_schedule_get>},
915 {
"__newindex", &dispatch<&game_lua_kernel::impl_schedule_set>},
916 {
"__dir", &dispatch<&game_lua_kernel::impl_schedule_dir>},
917 {
"__len", &dispatch<&game_lua_kernel::impl_schedule_len>},
920 luaL_setfuncs(L, schedule_meta, 0);
922 lua_setmetatable(L, -2);
927 int save_top = lua_gettop(L);
928 luaL_checkudata(L, idx,
"schedule");
929 lua_getiuservalue(L, idx, 1);
930 int i = luaL_checkinteger(L, -1);
931 lua_settop(L, save_top);
941 #define SCHEDULE_GETTER(name, type) LATTR_GETTER(name, type, schedule_tag, sched)
942 #define SCHEDULE_SETTER(name, type) LATTR_SETTER(name, type, schedule_tag, sched)
943 #define SCHEDULE_VALID(name) LATTR_VALID(name, schedule_tag, sched)
947 inline static auto metatable =
"schedule";
949 schedule_tag sched{lua_kernel_base::get_lua_kernel<game_lua_kernel>(L)};
958 if(lua_isnumber(L, 2)) {
960 int i = lua_tointeger(L, 2) - 1;
961 if(i < 0 || i >=
static_cast<int>(times.size())) {
962 return luaL_argerror(L, 2,
"invalid time of day index");
974 lua_pushinteger(L, times.size());
981 if(lua_isnumber(L, 2)) {
983 int i = lua_tointeger(L, 2) - 1;
984 if(i < 0 || i >=
static_cast<int>(times.size())) {
985 return luaL_argerror(L, 2,
"invalid time of day index");
1004 if(sched.area_index >= 0) {
1005 return sched.tod_man().get_area_time_of_day(sched.area_index).id;
1007 return sched.tod_man().get_time_of_day().id;
1011 const auto& times = sched.area_index < 0 ? sched.tod_man().times() : sched.tod_man().times(sched.area_index);
1013 if(iter == times.end()) {
1014 std::ostringstream
err;
1015 err <<
"invalid time of day ID for ";
1016 if(sched.area_index < 0) {
1017 err <<
"global schedule";
1019 const std::string&
id = sched.tod_man().get_area_id(sched.area_index);
1021 const auto& hexes = sched.tod_man().get_area_by_index(sched.area_index);
1023 err <<
"anonymous empty time area";
1025 err <<
"anonymous time area at (" << hexes.begin()->wml_x() <<
',' << hexes.begin()->wml_y() <<
")";
1028 err <<
"time area with id=" <<
id;
1034 int n = std::distance(times.begin(), iter);
1035 if(sched.area_index < 0) {
1036 sched.tod_man().set_current_time(
n);
1038 sched.tod_man().set_current_time(
n, sched.area_index);
1043 return sched.area_index < 0;
1047 if(sched.area_index >= 0)
return utils::nullopt;
1048 return sched.tod_man().get_max_liminal_bonus();
1052 if(sched.area_index >= 0) {
1053 throw luaL_error(L,
"liminal_bonus can only be set on the global schedule");
1056 sched.tod_man().set_max_liminal_bonus(*value);
1058 sched.tod_man().reset_max_liminal_bonus();
1063 return sched.area_index >= 0;
1067 if(sched.area_index < 0)
return utils::nullopt;
1068 return sched.tod_man().get_area_id(sched.area_index);
1072 if(sched.area_index < 0) {
1073 throw luaL_error(L,
"can't set id of global schedule");
1075 sched.tod_man().set_area_id(sched.area_index, value);
1079 return sched.area_index >= 0;
1083 if(sched.area_index < 0)
return utils::nullopt;
1084 return sched.tod_man().get_area_by_index(sched.area_index);
1088 if(sched.area_index < 0) {
1089 throw luaL_error(L,
"can't set hexes of global schedule");
1091 sched.tod_man().replace_area_locations(sched.area_index, value);
1102 char const *m = luaL_checkstring(L, 2);
1106 if (!
info.is_nonnull())
return 0;
1109 lua_pushstring(L,
info.id().c_str());
1110 lua_setfield(L, -2,
"id");
1112 lua_setfield(L, -2,
"name");
1114 lua_setfield(L, -2,
"editor_name");
1116 lua_setfield(L, -2,
"description");
1118 lua_setfield(L, -2,
"icon");
1120 lua_setfield(L, -2,
"editor_image");
1121 lua_pushinteger(L,
info.light_bonus(0));
1122 lua_setfield(L, -2,
"light");
1123 lua_pushboolean(L,
info.is_village());
1124 lua_setfield(L, -2,
"village");
1125 lua_pushboolean(L,
info.is_castle());
1126 lua_setfield(L, -2,
"castle");
1127 lua_pushboolean(L,
info.is_keep());
1128 lua_setfield(L, -2,
"keep");
1129 lua_pushinteger(L,
info.gives_healing());
1130 lua_setfield(L, -2,
"healing");
1135 for (
const auto& terrain :
info.mvt_type()) {
1137 if (!base.
id().empty()) {
1139 lua_rawseti(L, -2, idx++);
1142 lua_setfield(L, -2,
"mvt_alias");
1147 for (
const auto& terrain :
info.def_type()) {
1149 if (!base.
id().empty()) {
1151 lua_rawseti(L, -2, idx++);
1154 lua_setfield(L, -2,
"def_alias");
1166 std::vector<std::string> terrains;
1167 terrains.reserve(codes.size());
1168 for(
auto code : codes) {
1181 template<
bool cons
ider_illuminates>
1188 if(!
map().on_board_with_border(
loc)) {
1189 return luaL_argerror(L, 1,
"coordinates are not on board");
1191 }
else if(lua_isstring(L, 1)) {
1194 return luaL_error(L,
"invalid or empty time_area ID");
1197 loc = *area.begin();
1198 }
else if(!lua_isnil(L, 1)) {
1201 return luaL_error(L,
"empty time_area");
1204 loc = *area.begin();
1207 if(lua_isnumber(L, 2)) {
1208 for_turn = luaL_checkinteger(L, 2);
1210 if(for_turn < 1 || (number_of_turns != -1 && for_turn > number_of_turns)) {
1211 return luaL_argerror(L, 2,
"turn number out of range");
1232 if (!
map().is_village(
loc))
1236 if (!side)
return 0;
1237 lua_pushinteger(L, side);
1249 if(!
map().is_village(
loc)) {
1254 const int new_side_num = lua_isnoneornil(L, 2) ? 0 : luaL_checkinteger(L, 2);
1256 team* old_side =
nullptr;
1257 team* new_side =
nullptr;
1259 if(old_side_num == new_side_num) {
1265 }
catch(
const std::out_of_range&) {
1272 }
catch(
const std::out_of_range&) {
1278 if(new_side &&
board().team_is_defeated(*new_side)) {
1311 if (!
map().on_board(
loc))
return 0;
1329 if (!
map().on_board(
loc))
return 0;
1344 std::string m = luaL_checkstring(L, 1);
1350 return luaL_argerror(L, 1, (
"Cannot find resource with id '" + m +
"'").c_str());
1362 std::string m = luaL_checkstring(L, 1);
1368 return luaL_argerror(L, 1, (
"Cannot find era with id '" + m +
"'").c_str());
1383 #define GAME_CONFIG_SIMPLE_SETTER(name) \
1384 GAME_CONFIG_SETTER(#name, decltype(game_config::name), game_lua_kernel) { \
1386 game_config::name = value; \
1392 return k2.pc().gamestate().do_healing_;
1397 k2.pc().gamestate().do_healing_ = value;}
1401 return k2.pc().get_classification().random_mode;
1412 k2.disp()->set_theme(value);
1415 using traits_map = std::map<std::string, config>;
1418 std::map<std::string, config> result;
1423 result.emplace(trait[
"id"], trait);
1439 static config find_addon(
const std::string&
type,
const std::string&
id)
1448 const char* m = luaL_checkstring(L, 2);
1466 struct end_level_committer {
1468 ~end_level_committer() {
1469 pc_.set_end_level_data(data_);
1480 const char* m = luaL_checkstring(L, 2);
1496 data->~end_level_data();
1502 void*
p = lua_touserdata(L, lua_upvalueindex(1));
1504 if(lua_type(L, 2) == LUA_TNUMBER) {
1507 std::size_t
i = luaL_checkinteger(L, 2);
1509 lua_createtable(L, 2, 0);
1510 lua_pushstring(L,
"options");
1518 auto iter =
settings.addons.begin();
1519 std::advance(iter,
i);
1521 iter->second.write(
cfg);
1522 cfg[
"id"] = iter->first;
1524 lua_createtable(L, 2, 0);
1525 lua_pushstring(L,
"addon");
1533 char const *m = luaL_checkstring(L, 2);
1561 if(strcmp(m,
"savegame") == 0) {
1563 if(
savegame == saved_game_mode::type::no) {
1564 lua_pushboolean(L,
false);
1570 if(strcmp(m,
"side_players") == 0) {
1574 if(strcmp(m,
"addons") == 0) {
1575 for(
const auto& [
id, addon] :
settings.addons) {
1576 lua_createtable(L, 0, 4);
1578 lua_setfield(L, -2,
"id");
1580 lua_setfield(L, -2,
"name");
1581 lua_pushboolean(L, addon.required);
1582 lua_setfield(L, -2,
"required");
1583 if(addon.min_version) {
1585 lua_push(L, addon.min_version->str());
1587 lua_setfield(L, -2,
"min_version");
1593 lua_setfield(L, -2,
"version");
1595 lua_createtable(L, addon.content.size(), 0);
1596 for(
const auto& content : addon.content) {
1597 lua_createtable(L, 0, 3);
1599 lua_setfield(L, -2,
"id");
1601 lua_setfield(L, -2,
"name");
1603 lua_setfield(L, -2,
"type");
1604 lua_seti(L, -2, lua_rawlen(L, -2) + 1);
1606 lua_setfield(L, -2,
"content");
1622 void*
p = lua_touserdata(L, lua_upvalueindex(1));
1624 lua_pushinteger(L,
settings.addons.size() + 1);
1635 auto end_level_set()
const {
return &dispatch<&game_lua_kernel::impl_end_level_data_set>; }
1637 #define SCENARIO_GETTER(name, type) LATTR_GETTER(name, type, scenario_tag, k)
1638 #define SCENARIO_SETTER(name, type) LATTR_SETTER(name, type, scenario_tag, k)
1639 #define SCENARIO_VALID(name) LATTR_VALID(name, scenario_tag, k)
1643 inline static auto metatable =
"scenario";
1645 return lua_kernel_base::get_lua_kernel<game_lua_kernel>(L);
1651 return k.tod_man().number_of_turns();
1655 k.tod_man().set_number_of_turns_by_wml(value);
1659 return k.gamedata().next_scenario();
1663 k.gamedata().set_next_scenario(value);
1667 return k.gamedata().get_id();
1671 return k.pc().get_scenario_name();
1675 return k.gamedata().get_defeat_music();
1679 k.gamedata().set_defeat_music(value);
1683 return k.gamedata().get_victory_music();
1687 k.gamedata().set_victory_music(value);
1692 for(
const std::string& rsrc :
utils::split(k.pc().get_loaded_resources())) {
1693 resources.push_back(find_addon(
"resource", rsrc));
1703 return k.cls().difficulty;
1707 return k.cls().end_credits;
1711 k.cls().end_credits = value;
1715 return k.cls().end_text;
1719 k.cls().end_text = value;
1723 return k.cls().end_text_duration.count();
1727 k.cls().end_text_duration = std::chrono::milliseconds{value};
1731 return !k.cls().campaign.empty();
1735 if(k.cls().campaign.empty())
return utils::nullopt;
1736 return find_addon(
"campaign", k.cls().campaign);
1740 std::vector<config> mods;
1741 for(
const std::string& mod : k.cls().active_mods) {
1742 mods.push_back(find_addon(
"modification", mod));
1748 if (!k.pc().is_regular_game_end()) {
1752 auto data = k.pc().get_end_level_data();
1754 if(luaL_newmetatable(L,
"end level data")) {
1755 static luaL_Reg
const callbacks[] {
1757 {
"__newindex", k.end_level_set()},
1759 {
nullptr,
nullptr }
1761 luaL_setfuncs(L, callbacks, 0);
1763 lua_setmetatable(L, -2);
1770 data.proceed_to_next_level = value[
"proceed_to_next_level"].to_bool(
true);
1771 data.transient.carryover_report = value[
"carryover_report"].to_bool(
true);
1772 data.prescenario_save = value[
"save"].to_bool(
true);
1773 data.replay_save = value[
"replay_save"].to_bool(
true);
1774 data.transient.linger_mode = value[
"linger_mode"].to_bool(
true) && !k.ref.teams().empty();
1775 data.transient.reveal_map = value[
"reveal_map"].to_bool(k.pc().reveal_map_default());
1776 data.is_victory = value[
"result"] == level_result::victory;
1777 data.test_result = value[
"test_result"].str();
1778 k.pc().set_end_level_data(
data);
1782 return k.cls().is_multiplayer();
1786 if(!k.cls().is_multiplayer()) {
1790 lua_newuserdatauv(L, 0, 0);
1791 if(luaL_newmetatable(L,
"mp settings")) {
1792 lua_pushlightuserdata(L, &k.pc());
1794 lua_setfield(L, -2,
"__index");
1795 lua_pushlightuserdata(L, &k.pc());
1797 lua_setfield(L, -2,
"__len");
1798 lua_pushstring(L,
"mp settings");
1799 lua_setfield(L, -2,
"__metatable");
1801 lua_setmetatable(L, -2);
1806 return k.cls().is_multiplayer();
1810 if(!k.cls().is_multiplayer())
return utils::nullopt;
1811 return find_addon(
"era", k.cls().era_id);
1823 DBG_LUA <<
"impl_scenario_get";
1835 DBG_LUA <<
"impl_scenario_set";
1844 DBG_LUA <<
"impl_scenario_dir";
1861 return "local_choice";
1880 #define CURRENT_GETTER(name, type) LATTR_GETTER(name, type, current_tag, k)
1884 inline static auto metatable =
"current";
1886 return lua_kernel_base::get_lua_kernel<game_lua_kernel>(L);
1892 return k.pc().current_side();
1896 return k.pc().turn();
1919 return k.pc().is_replay();
1937 cfg[
"damage_inflicted"] = di;
1983 if (lua_isnone(L, 2)) {
1989 LOG_LUA <<
"Script says: \"" << m <<
"\"";
1998 double factor = luaL_checknumber(L, 1);
2025 if (!lua_isnoneornil(L, 1)) {
2026 int max = 2 *
teams().size();
2027 int npn = luaL_checkinteger(L, 1);
2028 if (npn <= 0 || npn > max) {
2029 return luaL_argerror(L, 1,
"side number out of range");
2046 lua_pushboolean(L,
b);
2063 const unit* u =
nullptr;
2064 int viewing_side = 0;
2066 if (lua_isuserdata(L, arg))
2070 viewing_side = u->
side();
2079 viewing_side = u->
side();
2086 if (!
map().on_board(
src))
2087 return luaL_argerror(L, 1,
"invalid location");
2088 if (!
map().on_board(
dst))
2089 return luaL_argerror(L, arg,
"invalid location");
2092 bool ignore_units =
false, see_all =
false, ignore_teleport =
false;
2093 double stop_at = 10000;
2094 std::unique_ptr<pathfind::cost_calculator> calc;
2096 if (lua_istable(L, arg))
2098 ignore_units = luaW_table_get_def<bool>(L, arg,
"ignore_units",
false);
2099 see_all = luaW_table_get_def<bool>(L, arg,
"ignore_visibility",
false);
2100 ignore_teleport = luaW_table_get_def<bool>(L, arg,
"ignore_teleport",
false);
2102 stop_at = luaW_table_get_def<double>(L, arg,
"max_cost", stop_at);
2104 lua_pushstring(L,
"viewing_side");
2106 if (!lua_isnil(L, -1)) {
2107 int i = luaL_checkinteger(L, -1);
2108 if(
board().has_team(
i)) {
2111 return luaL_argerror(L, -1,
"invalid viewing side");
2116 lua_pushstring(L,
"calculate");
2118 if(lua_isfunction(L, -1)) {
2122 }
else if(!lua_isnoneornil(L, arg)) {
2123 return luaL_argerror(L, arg,
"table expected");
2128 if(!ignore_teleport) {
2129 if(viewing_side == 0) {
2130 lua_warning(L,
"wesnoth.paths.find_path: ignore_teleport=false requires a valid viewing_side; continuing with ignore_teleport=true",
false);
2131 ignore_teleport =
true;
2139 return luaL_argerror(L, 1,
"unit not found OR custom cost function not provided");
2143 teams(),
map(), ignore_units,
false, see_all));
2147 &teleport_locations);
2149 int nb = res.
steps.size();
2150 lua_createtable(L, nb, 0);
2151 for (
int i = 0;
i < nb; ++
i)
2154 lua_rawseti(L, -2,
i + 1);
2170 const unit* u =
nullptr;
2172 if (lua_isuserdata(L, arg))
2182 return luaL_argerror(L, 1,
"unit not found");
2187 int viewing_side = u->
side();
2188 bool ignore_units =
false, see_all =
false, ignore_teleport =
false;
2189 int additional_turns = 0;
2191 if (lua_istable(L, arg))
2193 ignore_units = luaW_table_get_def<bool>(L, arg,
"ignore_units",
false);
2194 see_all = luaW_table_get_def<bool>(L, arg,
"ignore_visibility",
false);
2195 ignore_teleport = luaW_table_get_def<bool>(L, arg,
"ignore_teleport",
false);
2196 additional_turns = luaW_table_get_def<int>(L, arg,
"max_cost", additional_turns);
2198 lua_pushstring(L,
"viewing_side");
2200 if (!lua_isnil(L, -1)) {
2201 int i = luaL_checkinteger(L, -1);
2202 if(
board().has_team(
i)) {
2205 return luaL_argerror(L, -1,
"invalid viewing side");
2209 }
else if(!lua_isnoneornil(L, arg)) {
2210 return luaL_argerror(L, arg,
"table expected");
2216 viewing_team, additional_turns, see_all, ignore_units);
2221 lua_createtable(L, nb, 0);
2222 for (
int i = 0;
i < nb; ++
i)
2225 tuple_builder.push(L);
2226 lua_pushinteger(L,
s.curr.wml_x());
2227 lua_rawseti(L, -2, 1);
2228 lua_pushinteger(L,
s.curr.wml_y());
2229 lua_rawseti(L, -2, 2);
2230 lua_pushinteger(L,
s.move_left);
2231 lua_rawseti(L, -2, 3);
2232 lua_rawseti(L, -2,
i + 1);
2247 const unit* u =
nullptr;
2249 if (lua_isuserdata(L, arg))
2259 return luaL_argerror(L, 1,
"unit not found");
2266 return luaL_error(L,
"wesnoth.find_vision_range: requires a valid unit");
2269 std::map<map_location, int> jamming_map;
2277 tuple_builder.push(L);
2278 lua_pushinteger(L,
d.curr.wml_x());
2279 lua_rawseti(L, -2, 1);
2280 lua_pushinteger(L,
d.curr.wml_y());
2281 lua_rawseti(L, -2, 2);
2282 lua_pushinteger(L,
d.move_left);
2283 lua_rawseti(L, -2, 3);
2284 lua_rawseti(L, -2, lua_rawlen(L, -2) + 1);
2286 for(
const auto&
e : res.
edges) {
2287 tuple_builder.push(L);
2288 lua_pushinteger(L,
e.wml_x());
2289 lua_rawseti(L, -2, 1);
2290 lua_pushinteger(L,
e.wml_y());
2291 lua_rawseti(L, -2, 2);
2292 lua_pushinteger(L, -1);
2293 lua_rawseti(L, -2, 3);
2294 lua_rawseti(L, -2, lua_rawlen(L, -2) + 1);
2299 template<
typename T>
2302 for (
int i = 1, i_end = lua_rawlen(L, arg);
i <= i_end; ++
i)
2305 lua_rawgeti(L, arg,
i);
2306 int entry = lua_gettop(L);
2307 if (!lua_istable(L, entry)) {
2315 lua_rawgeti(L, entry, 3);
2316 if (!lua_isnumber(L, -1)) {
2317 lua_getfield(L, entry,
"side");
2318 if (!lua_isnumber(L, -1)) {
2322 int side = lua_tointeger(L, -1);
2324 lua_rawgeti(L, entry, 4);
2325 if (!lua_isstring(L, -1)) {
2326 lua_getfield(L, entry,
"type");
2327 if (!lua_isstring(L, -1)) {
2331 std::string
unit_type = lua_tostring(L, -1);
2335 lua_settop(L, entry - 1);
2339 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");
2357 std::vector<const ::unit*> real_units;
2358 typedef std::vector<std::tuple<map_location, int, std::string>> unit_type_vector;
2364 real_units.push_back(
unit);
2369 if(match->get_location().valid()) {
2370 real_units.push_back(match);
2380 real_units.push_back(&(*ui));
2385 if (lua_istable(L, arg))
2393 return luaL_argerror(L, 1,
"unit(s) not found");
2396 int viewing_side = 0;
2397 bool ignore_units =
true, see_all =
true, ignore_teleport =
false,
debug =
false, use_max_moves =
false;
2399 if (lua_istable(L, arg))
2401 lua_pushstring(L,
"ignore_units");
2403 if (!lua_isnil(L, -1))
2409 lua_pushstring(L,
"ignore_teleport");
2411 if (!lua_isnil(L, -1))
2417 lua_pushstring(L,
"viewing_side");
2419 if (!lua_isnil(L, -1))
2421 int i = luaL_checkinteger(L, -1);
2422 if (
i >= 1 &&
i <=
static_cast<int>(
teams().
size()))
2429 lua_pushstring(L,
"debug");
2431 if (!lua_isnil(L, -1))
2437 lua_pushstring(L,
"use_max_moves");
2439 if (!lua_isnil(L, -1))
2461 const team& viewing_team = viewing_side
2466 ignore_units, !ignore_teleport, viewing_team, see_all, ignore_units);
2468 for (const ::unit*
const u : real_units)
2470 cost_map.
add_unit(*u, use_max_moves);
2472 for (
const unit_type_vector::value_type& fu :
fake_units)
2475 cost_map.
add_unit(std::get<0>(fu), ut, std::get<1>(fu));
2484 std::stringstream
s;
2500 tuple_builder.push(L);
2503 lua_rawseti(L, -2, 1);
2506 lua_rawseti(L, -2, 2);
2509 lua_rawseti(L, -2, 3);
2512 lua_rawseti(L, -2, 4);
2514 lua_rawseti(L, -2, counter);
2524 return reinterpret_cast<int*
>(luaL_checkudata(L, idx,
labelKey));
2529 const char* m = luaL_checkstring(L, 2);
2537 std::chrono::milliseconds fade{luaL_optinteger(L, 2, -1)};
2585 int handle_idx = lua_gettop(L);
2590 double width_ratio = 0;
2592 int lifetime = 2'000, fadeout = 100;
2599 if(lua_istable(L, idx+1)) {
2601 size = luaL_checkinteger(L, -1);
2605 width = lua_tointegerx(L, -1, &found_number);
2609 if(!value.empty() && value.back() ==
'%') {
2610 value.remove_suffix(1);
2611 width_ratio =
std::stoi(std::string(value)) / 100.0;
2612 }
else throw std::invalid_argument(value.data());
2613 }
catch(std::invalid_argument&) {
2614 return luaL_argerror(L, -1,
"max_width should be integer or percentage");
2620 if(lua_isstring(L, -1)) {
2623 auto vec = lua_check<std::vector<int>>(L, -1);
2624 if(vec.size() != 3) {
2625 int idx = lua_absindex(L, -1);
2627 color.r = luaL_checkinteger(L, -3);
2628 color.g = luaL_checkinteger(L, -2);
2629 color.b = luaL_checkinteger(L, -1);
2631 return luaL_error(L,
"floating label text color should be a hex string, an array of 3 integers, or a table with r,g,b keys");
2641 if(lua_isstring(L, -1)) {
2644 auto vec = lua_check<std::vector<int>>(L, -1);
2645 if(vec.size() != 3) {
2646 int idx = lua_absindex(L, -1);
2648 bgcolor.r = luaL_checkinteger(L, -3);
2649 bgcolor.g = luaL_checkinteger(L, -2);
2650 bgcolor.b = luaL_checkinteger(L, -1);
2652 return luaL_error(L,
"floating label background color should be a hex string, an array of 3 integers, or a table with r,g,b keys");
2662 bgcolor.a = luaL_checkinteger(L, -1);
2667 lifetime = lua_tointegerx(L, -1, &found_number);
2670 if(value ==
"unlimited") {
2673 return luaL_argerror(L, -1,
"duration should be integer or 'unlimited'");
2678 fadeout = lua_tointeger(L, -1);
2684 border = std::max<int>(0, lua_tointeger(L, -1));
2687 static const char* options[] = {
"left",
"center",
"right"};
2688 alignment =
font::ALIGN(luaL_checkoption(L, -1,
nullptr, options));
2691 static const char* options[] = {
"top",
"center",
"bottom"};
2692 vertical_alignment =
font::ALIGN(luaL_checkoption(L, -1,
nullptr, options));
2701 if(width_ratio > 0) {
2702 width =
static_cast<int>(std::round(
rect.w * width_ratio));
2716 switch(vertical_alignment) {
2732 using std::chrono::milliseconds;
2740 flabel.
set_lifetime(milliseconds{lifetime}, milliseconds{fadeout});
2751 lua_settop(L, handle_idx);
2752 if(luaL_newmetatable(L,
labelKey)) {
2754 static const luaL_Reg methods[] = {
2755 {
"remove", &dispatch<&game_lua_kernel::intf_remove_floating_label>},
2756 {
"move", &dispatch<&game_lua_kernel::intf_move_floating_label>},
2757 {
"replace", &dispatch2<&game_lua_kernel::intf_set_floating_label, false>},
2759 {
nullptr,
nullptr }
2761 luaL_setfuncs(L, methods, 0);
2764 lua_setmetatable(L, handle_idx);
2765 lua_settop(L, handle_idx);
2790 return luaL_error(L,
"Attempted to move a unit while the map is locked");
2795 if (!
map().on_board(
loc)) {
2796 return luaL_argerror(L, 2,
"invalid location");
2807 if (!
map().on_board(
loc))
2808 return luaL_argerror(L, 1,
"invalid location");
2815 }
else if(!lua_isnoneornil(L, 1)) {
2816 const vconfig* vcfg =
nullptr;
2818 if (!
map().on_board(
loc)) {
2821 if (!
map().on_board(
loc))
2822 return luaL_argerror(L, 2,
"invalid location");
2828 u->set_location(
loc);
2830 u->anim_comp().reset_affect_adjacent(
units());
2848 return luaL_error(L,
"Attempted to remove a unit while the map is locked");
2856 if (!
map().on_board(
loc)) {
2857 return luaL_argerror(L, 1,
"invalid location");
2863 t.recall_list().erase_if_matches_id(u->
id());
2865 return luaL_argerror(L, 1,
"can't erase private units");
2868 if (!
map().on_board(
loc)) {
2869 return luaL_argerror(L, 1,
"invalid location");
2872 return luaL_argerror(L, 1,
"expected unit or location");
2888 return luaL_error(L,
"Attempted to move a unit while the map is locked");
2892 int side = lua_tointeger(L, 2);
2893 if (
static_cast<unsigned>(side) >
teams().
size()) side = 0;
2897 u = lu->get_shared();
2898 if(lu->on_recall_list() && lu->on_recall_list() == side) {
2899 return luaL_argerror(L, 1,
"unit already on recall list");
2902 const vconfig* vcfg =
nullptr;
2914 std::size_t uid = u->underlying_id();
2915 t.recall_list().erase_by_underlying_id(uid);
2916 t.recall_list().add(u);
2921 u->anim_comp().clear_haloes();
2922 u->anim_comp().reset_affect_adjacent(
units());
2924 lu->lua_unit::~lua_unit();
2938 return luaL_error(L,
"Attempted to remove a unit while the map is locked");
2946 u->anim_comp().clear_haloes();
2947 u->anim_comp().reset_affect_adjacent(
units());
2948 }
else if (
int side = lu->on_recall_list()) {
2951 t.recall_list().erase_if_matches_id(u->id());
2957 lu->lua_unit::~lua_unit();
2973 if (!lua_isnoneornil(L, 2)) {
2977 const vconfig* vcfg =
nullptr;
2980 if (u->get_location().valid()) {
2981 u->anim_comp().reset_affect_adjacent(
units());
2988 if (!res.
valid())
return 0;
2989 lua_pushinteger(L, res.
wml_x());
2990 lua_pushinteger(L, res.
wml_y());
3006 if (!lua_isnoneornil(L, 3)) {
3029 void reset_affect_adjacent(
const unit&
unit)
3042 const vconfig* vcfg =
nullptr;
3046 if (u->get_location().valid()) {
3047 reset_affect_adjacent(*u);
3075 char const *m = luaL_checkstring(L, 2);
3079 if(lua_isboolean(L, 3)) {
3081 if(!lua_isnoneornil(L, 4)) {
3084 }
else if(!lua_isnoneornil(L, 3)) {
3105 }
else if(lua_isstring(L, 2)) {
3106 char const *m = luaL_checkstring(L, 2);
3126 }
else if(lua_isstring(L, 2)) {
3127 char const *m = luaL_checkstring(L, 2);
3147 }
else if(lua_isstring(L, 2)) {
3148 char const *m = luaL_checkstring(L, 2);
3168 }
else if(lua_isstring(L, 2)) {
3169 char const *m = luaL_checkstring(L, 2);
3185 char const *m = luaL_checkstring(L, 2);
3199 char const *m = luaL_checkstring(L, 2);
3201 if (!utp)
return luaL_argerror(L, 2,
"unknown unit type");
3202 if(lua_isstring(L, 3)) {
3203 const std::string& m2 = lua_tostring(L, 3);
3204 if(!utp->
has_variation(m2))
return luaL_argerror(L, 2,
"unknown unit variation");
3209 reset_affect_adjacent(u);
3221 lua_createtable(L, 0, 4);
3223 lua_setfield(L, -2,
"poisoned");
3224 lua_pushnumber(L, cmb.
slowed);
3225 lua_setfield(L, -2,
"slowed");
3227 lua_setfield(L, -2,
"untouched");
3229 lua_setfield(L, -2,
"average_hp");
3230 lua_createtable(L,
n, 0);
3231 for (
int i = 0;
i <
n; ++
i) {
3233 lua_rawseti(L, -2,
i);
3235 lua_setfield(L, -2,
"hp_chance");
3244 lua_createtable(L, 0, 16);
3247 lua_setfield(L, -2,
"num_blows");
3248 lua_pushnumber(L, bcustats.
damage);
3249 lua_setfield(L, -2,
"damage");
3251 lua_setfield(L, -2,
"chance_to_hit");
3252 lua_pushboolean(L, bcustats.
poisons);
3253 lua_setfield(L, -2,
"poisons");
3254 lua_pushboolean(L, bcustats.
slows);
3255 lua_setfield(L, -2,
"slows");
3257 lua_setfield(L, -2,
"petrifies");
3258 lua_pushboolean(L, bcustats.
plagues);
3259 lua_setfield(L, -2,
"plagues");
3261 lua_setfield(L, -2,
"plague_type");
3262 lua_pushnumber(L, bcustats.
rounds);
3263 lua_setfield(L, -2,
"rounds");
3265 lua_setfield(L, -2,
"firststrike");
3266 lua_pushboolean(L, bcustats.
drains);
3267 lua_setfield(L, -2,
"drains");
3269 lua_setfield(L, -2,
"drain_constant");
3271 lua_setfield(L, -2,
"drain_percent");
3276 lua_setfield(L, -2,
"attack_num");
3278 lua_setfield(L, -2,
"number");
3280 if(bcustats.
weapon !=
nullptr)
3282 lua_pushstring(L, bcustats.
weapon->id().c_str());
3283 lua_setfield(L, -2,
"name");
3285 lua_setfield(L, -2,
"weapon");
3304 int arg_num = 1, att_w = -1, def_w = -1;
3308 if (lua_isnumber(L, arg_num)) {
3309 att_w = lua_tointeger(L, arg_num) - 1;
3310 if (att_w < 0 || att_w >=
static_cast<int>(att->attacks().size()))
3311 return luaL_argerror(L, arg_num,
"weapon index out of bounds");
3317 if (lua_isnumber(L, arg_num)) {
3318 def_w = lua_tointeger(L, arg_num) - 1;
3319 if (def_w < 0 || def_w >=
static_cast<int>(def->attacks().size()))
3320 return luaL_argerror(L, arg_num,
"weapon index out of bounds");
3325 def->get_location(), att_w, def_w, 0.0,
nullptr, att, def);
3342 char const *m = luaL_checkstring(L, 1);
3343 int repeats = luaL_optinteger(L, 2, 0);
3355 const char* content_for = luaL_checkstring(L, 1);
3356 const char*
id = luaL_checkstring(L, 2);
3359 if(group.content_for_ == content_for) {
3361 if(achieve.
id_ ==
id) {
3388 ERR_LUA <<
"Achievement " <<
id <<
" not found for achievement group " << content_for;
3394 ERR_LUA <<
"Achievement group " << content_for <<
" not found";
3406 const char* content_for = luaL_checkstring(L, 1);
3407 const char*
id = luaL_checkstring(L, 2);
3410 ERR_LUA <<
"Returning false for whether a player has completed an achievement due to being networked multiplayer.";
3411 lua_pushboolean(L,
false);
3427 const char* content_for = luaL_checkstring(L, 1);
3428 const char*
id = luaL_checkstring(L, 2);
3432 if(group.content_for_ == content_for) {
3433 for(
const auto& achieve : group.achievements_) {
3434 if(achieve.id_ ==
id) {
3436 cfg[
"id"] = achieve.id_;
3437 cfg[
"name"] = achieve.name_;
3438 cfg[
"name_completed"] = achieve.name_completed_;
3439 cfg[
"description"] = achieve.description_;
3440 cfg[
"description_completed"] = achieve.description_completed_;
3441 cfg[
"icon"] = achieve.icon_;
3442 cfg[
"icon_completed"] = achieve.icon_completed_;
3443 cfg[
"hidden"] = achieve.hidden_;
3444 cfg[
"achieved"] = achieve.achieved_;
3445 cfg[
"max_progress"] = achieve.max_progress_;
3446 cfg[
"current_progress"] = achieve.current_progress_;
3448 for(
const auto& sub_ach : achieve.sub_achievements_) {
3450 sub[
"id"] = sub_ach.id_;
3451 sub[
"description"] = sub_ach.description_;
3452 sub[
"icon"] = sub_ach.icon_;
3453 sub[
"achieved"] = sub_ach.achieved_;
3461 ERR_LUA <<
"Achievement " <<
id <<
" not found for achievement group " << content_for;
3467 ERR_LUA <<
"Achievement group " << content_for <<
" not found";
3483 const char* content_for = luaL_checkstring(L, 1);
3484 const char*
id = luaL_checkstring(L, 2);
3485 int amount = luaL_checkinteger(L, 3);
3486 int limit = luaL_optinteger(L, 4, 999999999);
3489 if(group.content_for_ == content_for) {
3491 if(achieve.
id_ ==
id) {
3494 ERR_LUA <<
"Attempted to progress achievement " <<
id <<
" for achievement group " << content_for <<
", is not a progressible achievement.";
3495 lua_pushinteger(L, -1);
3496 lua_pushinteger(L, -1);
3511 lua_pushinteger(L, progress);
3513 lua_pushinteger(L, -1);
3521 lua_push(L,
"Achievement " + std::string(
id) +
" not found for achievement group " + content_for);
3522 return lua_error(L);
3527 lua_push(L,
"Achievement group " + std::string(content_for) +
" not found");
3528 return lua_error(L);
3540 const char* content_for = luaL_checkstring(L, 1);
3541 const char*
id = luaL_checkstring(L, 2);
3542 const char* sub_id = luaL_checkstring(L, 3);
3545 ERR_LUA <<
"Returning false for whether a player has completed an achievement due to being networked multiplayer.";
3546 lua_pushboolean(L,
false);
3562 const char* content_for = luaL_checkstring(L, 1);
3563 const char*
id = luaL_checkstring(L, 2);
3564 const char* sub_id = luaL_checkstring(L, 3);
3567 if(group.content_for_ == content_for) {
3569 if(achieve.
id_ ==
id) {
3576 if(sub_ach.
id_ == sub_id) {
3594 lua_push(L,
"Sub-achievement " + std::string(
id) +
" not found for achievement" +
id +
" in achievement group " + content_for);
3595 return lua_error(L);
3599 lua_push(L,
"Achievement " + std::string(
id) +
" not found for achievement group " + content_for);
3600 return lua_error(L);
3605 lua_push(L,
"Achievement group " + std::string(content_for) +
" not found");
3606 return lua_error(L);
3642 if(lua_isnoneornil(L, 1)) {
3647 if(!
map().on_board(
loc))
return luaL_argerror(L, 1,
"not on board");
3648 bool highlight =
true;
3649 if(!lua_isnoneornil(L, 2))
3679 lua_pushboolean(L, skipping);
3690 if (!lua_isnone(L, 1)) {
3702 int user_choice_index;
3703 int random_choice_index;
3704 int ai_choice_index;
3706 lua_synchronize(lua_State *l,
const std::string& descr,
int user_index,
int random_index = 0,
int ai_index = 0)
3708 , user_choice_index(user_index)
3709 , random_choice_index(random_index)
3710 , ai_choice_index(ai_index != 0 ? ai_index : user_index)
3716 bool is_local_ai = lua_kernel_base::get_lua_kernel<game_lua_kernel>(L).board().get_team(side).is_local_ai();
3718 query_lua(side, is_local_ai ? ai_choice_index : user_choice_index,
cfg);
3725 if(random_choice_index != 0 && lua_isfunction(L, random_choice_index)) {
3726 query_lua(side, random_choice_index,
cfg);
3736 void query_lua(
int side,
int function_index,
config&
cfg)
const
3738 lua_pushvalue(L, function_index);
3739 lua_pushnumber(L, side);
3742 static const char*
msg =
"function returned to wesnoth.sync.[multi_]evaluate a table which was partially invalid";
3743 lua_kernel_base::get_lua_kernel<game_lua_kernel>(L).log_error(
msg);
3744 lua_warning(L,
msg,
false);
3751 virtual bool is_visible()
const override {
return false; }
3765 std::string tagname =
"input";
3772 if(!lua_isfunction(L, nextarg) &&
luaW_totstring(L, nextarg, desc) ) {
3775 if(lua_isfunction(L, nextarg)) {
3776 human_func = nextarg++;
3779 return luaL_argerror(L, nextarg,
"expected a function");
3781 if(lua_isfunction(L, nextarg)) {
3782 ai_func = nextarg++;
3784 side_for = lua_tointeger(L, nextarg);
3800 std::string tagname =
"input";
3804 std::vector<int> sides_for;
3807 if(!lua_isfunction(L, nextarg) &&
luaW_totstring(L, nextarg, desc) ) {
3810 if(lua_isfunction(L, nextarg)) {
3811 human_func = nextarg++;
3814 return luaL_argerror(L, nextarg,
"expected a function");
3816 if(lua_isfunction(L, nextarg)) {
3817 null_func = nextarg++;
3819 sides_for = lua_check<std::vector<int>>(L, nextarg++);
3834 lua_pushvalue(L, 1);
3849 std::set<map_location> res;
3875 lua_pushboolean(L,
true);
3884 lua_pushboolean(L, t_filter.
match(
loc));
3902 lua_pushboolean(L,
true);
3910 lua_pushboolean(L, s_filter.
match(*
t));
3912 unsigned side = luaL_checkinteger(L, 1) - 1;
3914 lua_pushboolean(L, s_filter.
match(side + 1));
3925 team_i = luaL_checkinteger(L, 1);
3927 std::string
flag = luaL_optlstring(L, 2,
"",
nullptr);
3928 std::string color = luaL_optlstring(L, 3,
"",
nullptr);
3930 if(
flag.empty() && color.empty()) {
3933 if(team_i < 1 ||
static_cast<std::size_t
>(team_i) >
teams().
size()) {
3934 return luaL_error(L,
"set_side_id: side number %d out of range", team_i);
3938 if(!color.empty()) {
3953 side_num =
t->side();
3955 side_num = luaL_checkinteger(L, 1);
3957 std::string
path = luaL_checkstring(L, 2);
3962 if(strcmp(action,
"delete") == 0) {
3967 std::size_t len = std::string::npos, open_brak =
path.find_last_of(
'[');
3968 std::size_t dot =
path.find_last_of(
'.');
3969 if(open_brak != len) {
3970 len = open_brak - dot - 1;
3981 side_num =
t->side();
3983 side_num = luaL_checkinteger(L, 1);
3985 if(lua_isstring(L, 2)) {
3986 std::string file = luaL_checkstring(L, 2);
3988 std::string
err =
formatter() <<
"Could not load AI for side " << side_num <<
" from file " << file;
3989 lua_pushlstring(L,
err.c_str(),
err.length());
3990 return lua_error(L);
4002 side_num =
t->side();
4004 side_num = luaL_checkinteger(L, 1);
4010 bool added_dummy_stage =
false;
4012 added_dummy_stage =
true;
4016 if(added_dummy_stage) {
4025 unsigned i = luaL_checkinteger(L, 1);
4026 if(i < 1 || i >
teams().
size())
return 0;
4038 LOG_LUA <<
"intf_get_sides called: this = " << std::hex <<
this << std::dec <<
" myname = " <<
my_name();
4039 std::vector<int> sides;
4043 sides.push_back(
t.side());
4049 sides =
filter.get_teams();
4053 lua_createtable(L, sides.size(), 0);
4055 for(
int side : sides) {
4057 lua_rawseti(L, -2,
index);
4074 char const *m = luaL_checkstring(L, 2);
4076 if (sm ==
"advance") {
4080 if (sm !=
"advancement" && sm !=
"object" && sm !=
"trait") {
4081 return luaL_argerror(L, 2,
"unknown modification type");
4083 bool write_to_mods =
true;
4084 if (!lua_isnone(L, 4)) {
4088 write_to_mods =
false;
4106 std::vector<std::string> tags;
4107 if(lua_isstring(L, 3)) {
4108 tags.push_back(lua_check<std::string>(L, 3));
4109 }
else if (lua_istable(L, 3)){
4110 tags = lua_check<std::vector<std::string>>(L, 3);
4112 tags.push_back(
"object");
4115 if(
filter.attribute_count() == 1 &&
filter.all_children_count() == 0 &&
filter.attribute_range().front().first ==
"duration") {
4118 for(
const std::string&
tag : tags) {
4120 if(obj.matches(
filter)) {
4121 obj[
"duration"] =
"now";
4141 if(lua_isboolean(L, 2)) {
4144 if(lua_isboolean(L, 3)) {
4158 char const *ty = luaL_checkstring(L, 1);
4161 std::stringstream ss;
4162 ss <<
"unknown unit type: '" << ty <<
"'";
4163 return luaL_argerror(L, 1, ss.str().c_str());
4178 const vconfig &ssf =
cfg.child(
"filter_team");
4180 std::string team_name;
4183 std::vector<std::string> team_names;
4185 [&](
int team) { return game_state_.get_disp_context().get_team(team).team_name(); });
4188 team_name =
cfg[
"team_name"].str();
4197 cfg[
"visible_in_fog"].to_bool(
true),
4198 cfg[
"submerge"].to_double(0),
4199 cfg[
"z_order"].to_double(0)
4213 char const *m = lua_tostring(L, 2);
4230 const int nargs = lua_gettop(L);
4231 if(nargs < 2 || nargs > 3) {
4232 return luaL_error(L,
"Wrong number of arguments to ai.log_replay() - should be 2 or 3 arguments.");
4234 const std::string key = nargs == 2 ? luaL_checkstring(L, 1) : luaL_checkstring(L, 2);
4240 }
else if(!lua_isstring(L, 3)) {
4241 return luaL_argerror(L, 3,
"accepts only string or config");
4274 if(lua_isstring(L, idx)) {
4275 return lua_tostring(L, idx);
4315 using namespace std::literals;
4321 }
else if(is_menu_item) {
4323 return luaL_argerror(L, 1,
"non-empty id is required for a menu item");
4325 name =
"menu item " +
id;
4327 if(
id.empty() && name.empty()) {
4328 return luaL_argerror(L, 1,
"either a name or id is required");
4331 if(new_handler.valid()) {
4332 bool has_lua_filter =
false;
4336 int filterIdx = lua_gettop(L);
4339 if(lua_isfunction(L, filterIdx)) {
4340 int fcnIdx = lua_absindex(L, -1);
4341 new_handler->add_filter(std::make_unique<lua_event_filter>(*
this, fcnIdx,
luaW_table_get_def(L, 1,
"filter_args",
config())));
4342 has_lua_filter =
true;
4344 #define READ_ONE_FILTER(key, tag) \
4346 if(luaW_tableget(L, filterIdx, key)) { \
4347 if(lua_isstring(L, -1)) { \
4348 filters.add_child("insert_tag", config{ \
4350 "variable", luaL_checkstring(L, -1) \
4353 filters.add_child(tag, luaW_checkconfig(L, -1)); \
4363 #undef READ_ONE_FILTER
4365 filters[
"filter_formula"] = luaL_checkstring(L, -1);
4369 new_handler->read_filters(filters);
4375 if(has_lua_filter) {
4380 new_handler->register_wml_event(*
this);
4393 lua_pushvalue(L, lua_upvalueindex(1));
4410 template<
bool is_menu_item>
4416 double priority = luaL_optnumber(L, 3, 0.);
4418 return luaL_argerror(L, 1,
"must not be empty");
4422 name =
"menu item " + name;
4423 }
else if(lua_absindex(L, -1) > 2 && lua_isfunction(L, -1)) {
4426 lua_pushcclosure(L, &dispatch<&game_lua_kernel::cfun_undoable_event>, 2);
4429 if(new_handler.valid()) {
4446 bool delayed_variable_substitution =
cfg[
"delayed_variable_substitution"].to_bool(
true);
4447 if(delayed_variable_substitution) {
4474 lua_pushinteger(L, color.r);
4475 lua_pushinteger(L, color.g);
4476 lua_pushinteger(L, color.b);
4485 auto vec = lua_check<std::vector<uint8_t>>(L, 1);
4486 if(vec.size() != 4) {
4489 color_t fade{vec[0], vec[1], vec[2], vec[3]};
4507 using namespace std::chrono_literals;
4508 std::chrono::milliseconds delay{luaL_checkinteger(L, 1)};
4516 const auto end_time = std::chrono::steady_clock::now() + delay;
4519 std::this_thread::sleep_for(10ms);
4520 }
while (std::chrono::steady_clock::now() < end_time);
4544 std::string team_name;
4547 if(lua_gettop(L) == 1 && lua_istable(L, 1)) {
4548 using namespace std::literals;
4551 team_name = luaL_optstring(L, 2,
"");
4565 switch(lua_type(L, 2)) {
4567 case LUA_TNONE:
case LUA_TNIL:
4572 if(std::size_t
n = luaL_checkinteger(L, 2);
n > 0 &&
n <=
teams().size()) {
4612 for (
const int side :
filter.get_teams()){
4634 int side =
cfg[
"side"].to_int();
4644 lua_getfield(L, -1,
"ca_ptr");
4658 lua_getfield(L, -1,
"stg_ptr");
4667 lua_createtable(L, 0, 0);
4669 lua_pushstring(L,
"name");
4670 lua_pushstring(L,
c->get_name().c_str());
4673 lua_pushstring(L,
"engine");
4674 lua_pushstring(L,
c->get_engine().c_str());
4677 lua_pushstring(L,
"id");
4678 lua_pushstring(L,
c->get_id().c_str());
4681 if (ct ==
"candidate_action") {
4682 lua_pushstring(L,
"ca_ptr");
4683 lua_pushlightuserdata(L,
c);
4686 lua_pushstring(L,
"exec");
4691 if (ct ==
"stage") {
4692 lua_pushstring(L,
"stg_ptr");
4693 lua_pushlightuserdata(L,
c);
4696 lua_pushstring(L,
"exec");
4701 for(
const std::string&
type :
c->get_children_types()) {
4702 if (
type ==
"aspect" ||
type ==
"goal" ||
type ==
"engine")
4707 lua_pushstring(L,
type.c_str());
4708 lua_createtable(L, 0, 0);
4711 lua_pushstring(L, child->get_name().c_str());
4740 side = luaL_checkinteger(L, 1);
4749 if(engine->get_name() ==
"lua") {
4758 if (lua_engine ==
nullptr)
4771 LOG_LUA <<
"Created new dummy lua-engine for debug_ai().";
4781 lua_pushstring(L,
"components");
4807 if(lua_isboolean(L, 1)) {
4832 std::set<map_location> locs;
4835 if(lua_gettop(L) == 1) {
4838 id =
cfg[
"id"].str();
4840 filter.get_locations(locs,
true);
4841 times =
cfg.get_parsed_config();
4843 id = luaL_checkstring(L, 1);
4844 if(!lua_isnoneornil(L, 3))
4850 filter.get_locations(locs,
true);
4858 LOG_LUA <<
"Lua inserted time_area '" <<
id <<
"'";
4867 const char *
id = luaL_checkstring(L, 1);
4869 LOG_LUA <<
"Lua removed time_area '" <<
id <<
"'";
4879 if(area_index < 0) {
4886 std::string area_id = luaL_checkstring(L, 1);
4888 if(
auto iter =
std::find(area_ids.begin(), area_ids.end(), area_id); iter == area_ids.end()) {
4902 if(luaL_testudata(L, 1,
"schedule")) {
4911 if(
cfg.get_children(
"time").
empty()) {
4912 ERR_LUA <<
"attempted to to replace ToD schedule with empty schedule";
4918 LOG_LUA <<
"replaced ToD schedule";
4927 point scroll_to(luaL_checkinteger(L, 1), luaL_checkinteger(L, 2));
4944 lua_report_generator(lua_State *L,
const std::string &
n)
4953 if (!
luaW_getglobal(L,
"wesnoth",
"interface",
"game_display", name))
4977 char const *m = luaL_checkstring(L, 2);
4979 lua_pushvalue(L, 2);
4980 lua_pushvalue(L, -2);
4991 char const *m = luaL_checkstring(L, 2);
4992 lua_pushvalue(L, 2);
4993 lua_pushvalue(L, 3);
5034 if (
dst == u->get_location() || !
map().on_board(
dst)) {
5038 if (!
map().on_board(vacant_dst)) {
5049 std::vector<map_location> teleport_path;
5050 teleport_path.push_back(src_loc);
5051 teleport_path.push_back(vacant_dst);
5058 u->anim_comp().set_standing();
5065 if (
map().is_village(vacant_dst)) {
5084 const std::string& logger = lua_isstring(L, 2) ? luaL_checkstring(L, 1) :
"";
5085 const std::string&
msg = lua_isstring(L, 2) ? luaL_checkstring(L, 2) : luaL_checkstring(L, 1);
5087 if(logger ==
"wml" || logger ==
"WML") {
5101 lua_pushboolean(L, fog ?
t.fogged(
loc) :
t.shrouded(
loc));
5119 bool affect_normal_fog =
false;
5120 if(lua_isboolean(L, -1)) {
5123 std::set<int> sides;
5125 sides.insert(
t->side());
5126 }
else if(lua_isnumber(L, 1)) {
5127 sides.insert(lua_tointeger(L, 1));
5128 }
else if(lua_istable(L, 1) && lua_istable(L, 2)) {
5129 const auto& v = lua_check<std::vector<int>>(L, 1);
5130 sides.insert(v.begin(), v.end());
5133 sides.insert(
t.side()+1);
5138 for(
const int &side_num : sides) {
5139 if(side_num < 1 ||
static_cast<std::size_t
>(side_num) >
teams().
size()) {
5145 t.remove_fog_override(locs);
5146 if(affect_normal_fog) {
5149 }
else if(!affect_normal_fog) {
5151 t.add_fog_override(locs);
5169 const std::string name = luaL_checkstring(L, 1);
5174 if(!
luaW_getglobal(L,
"wesnoth",
"custom_synced_commands", name)) {
5175 return luaL_argerror(L, 1,
"Unknown synced command");
5178 cmd_tag[
"name"] = name;
5179 if(!lua_isnoneornil(L, 2)) {
5197 #define CALLBACK_GETTER(name, type) LATTR_GETTER(name, lua_index_raw, callbacks_tag, ) { lua_pushcfunction(L, &impl_null_callback<type>); return lua_index_raw(L); }
5200 template<
typename Ret>
5202 if constexpr(std::is_same_v<Ret, void>)
return 0;
5208 inline static auto metatable =
"game_events";
5210 return lua_kernel_base::get_lua_kernel<game_lua_kernel>(L);
5231 template<
typename Ret =
void>
5233 int top = lua_gettop(L);
5237 lua_getfield(L, -1, name.c_str());
5238 lua_pushcfunction(L, &impl_null_callback<Ret>);
5239 if(lua_rawequal(L, -1, -2)) {
5294 cmd_log_ <<
"Registering game-specific wesnoth lib functions...\n";
5297 static luaL_Reg
const callbacks[] {
5302 {
"cancel_action", &dispatch<&game_lua_kernel::intf_cancel_action > },
5303 {
"log_replay", &dispatch<&game_lua_kernel::intf_log_replay > },
5304 {
"log", &dispatch<&game_lua_kernel::intf_log > },
5305 {
"redraw", &dispatch<&game_lua_kernel::intf_redraw > },
5306 {
"simulate_combat", &dispatch<&game_lua_kernel::intf_simulate_combat > },
5307 {
nullptr,
nullptr }
5308 };lua_getglobal(L,
"wesnoth");
5309 if (!lua_istable(L,-1)) {
5312 luaL_setfuncs(L, callbacks, 0);
5314 lua_setglobal(L,
"wesnoth");
5316 lua_getglobal(L,
"gui");
5317 lua_pushcfunction(L, &dispatch<&game_lua_kernel::intf_gamestate_inspector>);
5318 lua_setfield(L, -2,
"show_inspector");
5320 lua_setfield(L, -2,
"show_recruit_dialog");
5322 lua_setfield(L, -2,
"show_recall_dialog");
5328 static luaL_Reg
const test_callbacks[] {
5329 {
"fire_wml_menu_item", &dispatch<&game_lua_kernel::intf_fire_wml_menu_item> },
5330 {
nullptr,
nullptr }
5332 luaL_setfuncs(L, test_callbacks, 0);
5333 lua_setglobal(L,
"unit_test");
5359 cmd_log_ <<
"Adding terrain_types table...\n";
5360 lua_getglobal(L,
"wesnoth");
5361 lua_newuserdatauv(L, 0, 0);
5362 lua_createtable(L, 0, 2);
5363 lua_pushcfunction(L, &dispatch<&game_lua_kernel::impl_get_terrain_info>);
5364 lua_setfield(L, -2,
"__index");
5365 lua_pushcfunction(L, &dispatch<&game_lua_kernel::impl_get_terrain_list>);
5366 lua_setfield(L, -2,
"__dir");
5367 lua_pushstring(L,
"terrain types");
5368 lua_setfield(L, -2,
"__metatable");
5369 lua_setmetatable(L, -2);
5370 lua_setfield(L, -2,
"terrain_types");
5374 cmd_log_ <<
"Adding ai elements table...\n";
5379 cmd_log_ <<
"Adding wesnoth current table...\n";
5381 lua_getglobal(L,
"wesnoth");
5382 lua_newuserdatauv(L, 0, 0);
5383 lua_createtable(L, 0, 2);
5384 lua_pushcfunction(L, &dispatch<&game_lua_kernel::impl_current_get>);
5385 lua_setfield(L, -2,
"__index");
5386 lua_pushcfunction(L, &dispatch<&game_lua_kernel::impl_current_dir>);
5387 lua_setfield(L, -2,
"__dir");
5388 lua_pushboolean(L,
true);
5389 lua_setfield(L, -2,
"__dir_tablelike");
5390 lua_pushstring(L,
"current config");
5391 lua_setfield(L, -2,
"__metatable");
5392 lua_setmetatable(L, -2);
5393 lua_setfield(L, -2,
"current");
5397 lua_getglobal(L,
"wml");
5398 static luaL_Reg
const wml_callbacks[] {
5402 {
"get_variable", &dispatch<&game_lua_kernel::intf_get_variable>},
5403 {
"set_variable", &dispatch<&game_lua_kernel::intf_set_variable>},
5404 {
"get_all_vars", &dispatch<&game_lua_kernel::intf_get_all_vars>},
5405 {
nullptr,
nullptr }
5407 luaL_setfuncs(L, wml_callbacks, 0);
5412 static luaL_Reg
const map_callbacks[] {
5419 {
"get_owner", &dispatch<&game_lua_kernel::intf_get_village_owner>},
5420 {
"set_owner", &dispatch<&game_lua_kernel::intf_set_village_owner>},
5422 {
"add_label", &dispatch<&game_lua_kernel::intf_add_label>},
5423 {
"remove_label", &dispatch<&game_lua_kernel::intf_remove_label>},
5424 {
"get_label", &dispatch<&game_lua_kernel::intf_get_label>},
5426 {
"place_area", &dispatch<&game_lua_kernel::intf_add_time_area>},
5427 {
"remove_area", &dispatch<&game_lua_kernel::intf_remove_time_area>},
5428 {
"get_area", &dispatch<&game_lua_kernel::intf_get_time_area>},
5430 {
"find", &dispatch<&game_lua_kernel::intf_get_locations>},
5431 {
"matches", &dispatch<&game_lua_kernel::intf_match_location>},
5433 {
nullptr,
nullptr }
5435 luaL_setfuncs(L, map_callbacks, 0);
5439 cmd_log_ <<
"Adding units module...\n";
5440 static luaL_Reg
const unit_callbacks[] {
5443 {
"erase", &dispatch<&game_lua_kernel::intf_erase_unit>},
5444 {
"extract", &dispatch<&game_lua_kernel::intf_extract_unit>},
5445 {
"matches", &dispatch<&game_lua_kernel::intf_match_unit>},
5446 {
"select", &dispatch<&game_lua_kernel::intf_select_unit>},
5447 {
"to_map", &dispatch<&game_lua_kernel::intf_put_unit>},
5448 {
"to_recall", &dispatch<&game_lua_kernel::intf_put_recall_unit>},
5450 {
"teleport", &dispatch<&game_lua_kernel::intf_teleport>},
5452 {
"ability", &dispatch<&game_lua_kernel::intf_unit_ability>},
5463 {
"find_on_map", &dispatch<&game_lua_kernel::intf_get_units>},
5464 {
"find_on_recall", &dispatch<&game_lua_kernel::intf_get_recall_units>},
5465 {
"get", &dispatch<&game_lua_kernel::intf_get_unit>},
5466 {
"get_hovered", &dispatch<&game_lua_kernel::intf_get_displayed_unit>},
5467 {
"create_animator", &dispatch<&game_lua_kernel::intf_create_animator>},
5470 {
nullptr,
nullptr }
5472 lua_getglobal(L,
"wesnoth");
5474 luaL_setfuncs(L, unit_callbacks, 0);
5475 lua_setfield(L, -2,
"units");
5479 cmd_log_ <<
"Adding sides module...\n";
5480 static luaL_Reg
const side_callbacks[] {
5481 {
"is_enemy", &dispatch<&game_lua_kernel::intf_is_enemy> },
5482 {
"matches", &dispatch<&game_lua_kernel::intf_match_side> },
5483 {
"set_id", &dispatch<&game_lua_kernel::intf_set_side_id> },
5488 {
"find", &dispatch<&game_lua_kernel::intf_get_sides> },
5489 {
"get", &dispatch<&game_lua_kernel::intf_get_side> },
5490 {
"create", &dispatch<&game_lua_kernel::intf_create_side> },
5492 {
"place_shroud", &dispatch2<&game_lua_kernel::intf_toggle_shroud, true>},
5493 {
"remove_shroud", &dispatch2<&game_lua_kernel::intf_toggle_shroud, false>},
5494 {
"override_shroud", &dispatch<&game_lua_kernel::intf_override_shroud>},
5495 {
"is_shrouded", &dispatch2<&game_lua_kernel::intf_get_fog_or_shroud, false>},
5497 {
"place_fog", &dispatch2<&game_lua_kernel::intf_toggle_fog, false>},
5498 {
"remove_fog", &dispatch2<&game_lua_kernel::intf_toggle_fog, true>},
5499 {
"is_fogged", &dispatch2<&game_lua_kernel::intf_get_fog_or_shroud, true>},
5500 {
nullptr,
nullptr }
5502 std::vector<lua_cpp::Reg>
const cpp_side_callbacks {
5503 {
"add_ai_component", std::bind(
intf_modify_ai, std::placeholders::_1,
"add")},
5504 {
"delete_ai_component", std::bind(
intf_modify_ai, std::placeholders::_1,
"delete")},
5505 {
"change_ai_component", std::bind(
intf_modify_ai, std::placeholders::_1,
"change")},
5509 lua_getglobal(L,
"wesnoth");
5511 luaL_setfuncs(L, side_callbacks, 0);
5513 lua_setfield(L, -2,
"sides");
5517 cmd_log_ <<
"Adding interface module...\n";
5518 static luaL_Reg
const intf_callbacks[] {
5519 {
"add_hex_overlay", &dispatch<&game_lua_kernel::intf_add_tile_overlay>},
5520 {
"remove_hex_overlay", &dispatch<&game_lua_kernel::intf_remove_tile_overlay>},
5521 {
"get_color_adjust", &dispatch<&game_lua_kernel::intf_get_color_adjust>},
5522 {
"color_adjust", &dispatch<&game_lua_kernel::intf_color_adjust>},
5523 {
"screen_fade", &dispatch<&game_lua_kernel::intf_screen_fade>},
5524 {
"delay", &dispatch<&game_lua_kernel::intf_delay>},
5525 {
"deselect_hex", &dispatch<&game_lua_kernel::intf_deselect_hex>},
5526 {
"highlight_hex", &dispatch<&game_lua_kernel::intf_highlight_hex>},
5527 {
"float_label", &dispatch<&game_lua_kernel::intf_float_label>},
5528 {
"get_displayed_unit", &dispatch<&game_lua_kernel::intf_get_displayed_unit>},
5529 {
"get_hovered_hex", &dispatch<&game_lua_kernel::intf_get_mouseover_tile>},
5530 {
"get_selected_hex", &dispatch<&game_lua_kernel::intf_get_selected_tile>},
5531 {
"lock", &dispatch<&game_lua_kernel::intf_lock_view>},
5532 {
"is_locked", &dispatch<&game_lua_kernel::intf_view_locked>},
5533 {
"scroll", &dispatch<&game_lua_kernel::intf_scroll>},
5534 {
"scroll_to_hex", &dispatch<&game_lua_kernel::intf_scroll_to_tile>},
5535 {
"skip_messages", &dispatch<&game_lua_kernel::intf_skip_messages>},
5536 {
"is_skipping_messages", &dispatch<&game_lua_kernel::intf_is_skipping_messages>},
5537 {
"zoom", &dispatch<&game_lua_kernel::intf_zoom>},
5538 {
"clear_menu_item", &dispatch<&game_lua_kernel::intf_clear_menu_item>},
5539 {
"set_menu_item", &dispatch<&game_lua_kernel::intf_set_menu_item>},
5540 {
"allow_end_turn", &dispatch<&game_lua_kernel::intf_allow_end_turn>},
5541 {
"clear_chat_messages", &dispatch<&game_lua_kernel::intf_clear_messages>},
5542 {
"end_turn", &dispatch<&game_lua_kernel::intf_end_turn>},
5544 {
"add_chat_message", &dispatch<&game_lua_kernel::intf_message>},
5545 {
"add_overlay_text", &dispatch2<&game_lua_kernel::intf_set_floating_label, true>},
5547 {
nullptr,
nullptr }
5549 lua_getglobal(L,
"wesnoth");
5551 luaL_setfuncs(L, intf_callbacks, 0);
5552 lua_setfield(L, -2,
"interface");
5556 cmd_log_ <<
"Adding achievements module...\n";
5557 static luaL_Reg
const achievement_callbacks[] {
5558 {
"set", &dispatch<&game_lua_kernel::intf_set_achievement> },
5559 {
"has", &dispatch<&game_lua_kernel::intf_has_achievement> },
5560 {
"get", &dispatch<&game_lua_kernel::intf_get_achievement> },
5561 {
"progress", &dispatch<&game_lua_kernel::intf_progress_achievement> },
5562 {
"has_sub_achievement", &dispatch<&game_lua_kernel::intf_has_sub_achievement> },
5563 {
"set_sub_achievement", &dispatch<&game_lua_kernel::intf_set_sub_achievement> },
5564 {
nullptr,
nullptr }
5566 lua_getglobal(L,
"wesnoth");
5568 luaL_setfuncs(L, achievement_callbacks, 0);
5569 lua_setfield(L, -2,
"achievements");
5573 cmd_log_ <<
"Adding audio module...\n";
5574 static luaL_Reg
const audio_callbacks[] {
5575 {
"play", &dispatch<&game_lua_kernel::intf_play_sound > },
5576 {
nullptr,
nullptr }
5578 lua_getglobal(L,
"wesnoth");
5580 luaL_setfuncs(L, audio_callbacks, 0);
5581 lua_setfield(L, -2,
"audio");
5585 cmd_log_ <<
"Adding paths module...\n";
5586 static luaL_Reg
const path_callbacks[] {
5587 {
"find_cost_map", &dispatch<&game_lua_kernel::intf_find_cost_map > },
5588 {
"find_path", &dispatch<&game_lua_kernel::intf_find_path > },
5589 {
"find_reach", &dispatch<&game_lua_kernel::intf_find_reach > },
5590 {
"find_vacant_hex", &dispatch<&game_lua_kernel::intf_find_vacant_tile > },
5591 {
"find_vision_range", &dispatch<&game_lua_kernel::intf_find_vision_range > },
5592 {
nullptr,
nullptr }
5594 lua_getglobal(L,
"wesnoth");
5596 luaL_setfuncs(L, path_callbacks, 0);
5597 lua_setfield(L, -2,
"paths");
5601 cmd_log_ <<
"Adding sync module...\n";
5602 static luaL_Reg
const sync_callbacks[] {
5607 {
nullptr,
nullptr }
5609 lua_getglobal(L,
"wesnoth");
5611 luaL_setfuncs(L, sync_callbacks, 0);
5612 lua_setfield(L, -2,
"sync");
5616 cmd_log_ <<
"Adding schedule module...\n";
5617 static luaL_Reg
const schedule_callbacks[] {
5618 {
"get_time_of_day", &dispatch<&game_lua_kernel::intf_get_time_of_day<false>>},
5619 {
"get_illumination", &dispatch<&game_lua_kernel::intf_get_time_of_day<true>>},
5620 {
"replace", &dispatch<&game_lua_kernel::intf_replace_schedule>},
5621 {
nullptr,
nullptr }
5623 lua_getglobal(L,
"wesnoth");
5625 luaL_setfuncs(L, schedule_callbacks, 0);
5626 lua_createtable(L, 0, 2);
5627 lua_setmetatable(L, -2);
5628 lua_setfield(L, -2,
"schedule");
5635 cmd_log_ <<
"Adding wml_actions table...\n";
5637 lua_getglobal(L,
"wesnoth");
5639 lua_setfield(L, -2,
"wml_actions");
5643 cmd_log_ <<
"Adding wml_conditionals table...\n";
5645 lua_getglobal(L,
"wesnoth");
5647 lua_setfield(L, -2,
"wml_conditionals");
5654 cmd_log_ <<
"Adding effects table...\n";
5656 lua_getglobal(L,
"wesnoth");
5658 lua_setfield(L, -2,
"effects");
5662 cmd_log_ <<
"Adding custom_synced_commands table...\n";
5664 lua_getglobal(L,
"wesnoth");
5666 lua_setfield(L, -2,
"custom_synced_commands");
5670 cmd_log_ <<
"Adding game_events module...\n";
5671 static luaL_Reg
const event_callbacks[] {
5672 {
"add", &dispatch<&game_lua_kernel::intf_add_event> },
5673 {
"add_repeating", &dispatch<&game_lua_kernel::intf_add_event_simple<false>> },
5674 {
"add_menu", &dispatch<&game_lua_kernel::intf_add_event_simple<true>> },
5675 {
"add_wml", &dispatch<&game_lua_kernel::intf_add_event_wml> },
5676 {
"remove", &dispatch<&game_lua_kernel::intf_remove_event> },
5677 {
"fire", &dispatch2<&game_lua_kernel::intf_fire_event, false> },
5678 {
"fire_by_id", &dispatch2<&game_lua_kernel::intf_fire_event, true> },
5679 {
"add_undo_actions", &dispatch<&game_lua_kernel::intf_add_undo_actions> },
5680 {
"set_undoable", &dispatch<&game_lua_kernel::intf_allow_undo > },
5681 {
nullptr,
nullptr }
5683 lua_getglobal(L,
"wesnoth");
5685 luaL_setfuncs(L, event_callbacks, 0);
5686 lua_createtable(L, 0, 2);
5688 lua_setfield(L, -2,
"__dir");
5690 lua_setfield(L, -2,
"__index");
5691 lua_pushstring(L,
"game_events");
5692 lua_setfield(L, -2,
"__metatable");
5693 lua_setmetatable(L, -2);
5694 lua_setfield(L, -2,
"game_events");
5698 cmd_log_ <<
"Adding game_display table...\n";
5702 lua_createtable(L, 0, 2);
5703 lua_pushcfunction(L, &dispatch<&game_lua_kernel::impl_theme_items_get>);
5704 lua_setfield(L, -2,
"__index");
5705 lua_pushcfunction(L, &dispatch<&game_lua_kernel::impl_theme_items_set>);
5706 lua_setfield(L, -2,
"__newindex");
5707 lua_pushcfunction(L, &dispatch<&game_lua_kernel::impl_theme_items_dir>);
5708 lua_setfield(L, -2,
"__dir");
5709 lua_setmetatable(L, -2);
5710 lua_setfield(L, -2,
"game_display");
5714 cmd_log_ <<
"Adding scenario table...\n";
5718 lua_createtable(L, 0, 2);
5719 lua_pushcfunction(L, &dispatch<&game_lua_kernel::impl_scenario_get>);
5720 lua_setfield(L, -2,
"__index");
5721 lua_pushcfunction(L, &dispatch<&game_lua_kernel::impl_scenario_set>);
5722 lua_setfield(L, -2,
"__newindex");
5723 lua_pushcfunction(L, &dispatch<&game_lua_kernel::impl_scenario_dir>);
5724 lua_setfield(L, -2,
"__dir");
5725 lua_setmetatable(L, -2);
5726 lua_setfield(L, -2,
"scenario");
5737 lua_pushstring(L, effect.c_str());
5753 cmd_log_ <<
"Adding races table...\n";
5756 lua_getglobal(L,
"wesnoth");
5758 lua_setfield(L, -2,
"races");
5762 cmd_log_ <<
"Running preload scripts...\n";
5785 using namespace std::literals::string_view_literals;
5786 static constexpr std::array handled_file_tags {
5799 "modify_unit_type"sv,
5805 "terrain_graphics"sv,
5813 return std::binary_search(handled_file_tags.begin(), handled_file_tags.end(),
s);
5829 for(
const auto [child_key, child_cfg] :
level.all_children_view())
5832 lua_createtable(L, 2, 0);
5833 lua_pushstring(L, child_key.c_str());
5834 lua_rawseti(L, -2, 1);
5836 lua_rawseti(L, -2, 2);
5837 lua_rawseti(L, -2, k++);
5851 if(!impl_get_callback<config>(L,
"on_save"))
5864 const std::vector<std::string> src_tags(temp.begin(), temp.end());
5866 for(
const auto& key : src_tags) {
5873 const std::string m =
"Tag is already used: [" + key +
"]";
5894 lua_pushstring(L, ev.
name.c_str());
5903 if (!
luaW_getglobal(L,
"wesnoth",
"custom_synced_commands", name)) {
5919 std::string which_effect = lua_tostring(L, lua_upvalueindex(1));
5934 lua_pushstring(L, description.c_str());
5947 int str_i = lua_gettop(L);
5950 lua_pushstring(L,
"__call");
5951 lua_pushvalue(L, str_i);
5952 lua_pushboolean(L,
true);
5953 lua_pushcclosure(L, &dispatch<&game_lua_kernel::cfun_builtin_effect>, 2);
5955 lua_pushstring(L,
"__descr");
5956 lua_pushvalue(L, str_i);
5957 lua_pushboolean(L,
false);
5958 lua_pushcclosure(L, &dispatch<&game_lua_kernel::cfun_builtin_effect>, 2);
5960 lua_setmetatable(L, -2);
5970 (lua_touserdata(L, lua_upvalueindex(1)));
5984 lua_getglobal(L,
"wesnoth");
5985 lua_pushstring(L,
"wml_actions");
5987 lua_pushstring(L, cmd.c_str());
5988 lua_pushlightuserdata(L,
reinterpret_cast<void *
>(
h));
5989 lua_pushcclosure(L, &dispatch<&game_lua_kernel::cfun_wml_action>, 1);
6002 (lua_touserdata(L, lua_upvalueindex(1)));
6005 lua_pushboolean(L,
h(vcfg));
6016 lua_getglobal(L,
"wesnoth");
6017 lua_pushstring(L,
"wml_conditionals");
6019 lua_pushstring(L, cmd.c_str());
6020 lua_pushlightuserdata(L,
reinterpret_cast<void *
>(
h));
6062 ERR_WML <<
"unknown conditional wml: [" << cmd <<
"]";
6081 int argIdx = lua_gettop(L);
6083 return luaL_error(L,
"wesnoth.wml_actions.command is missing");
6085 lua_pushvalue(L, argIdx);
6094 int evtIdx = lua_gettop(L);
6096 return luaL_ref(L, evtIdx);
6103 int evtIdx = lua_gettop(L);
6104 std::ostringstream lua_name;
6105 lua_name <<
"event ";
6107 lua_name <<
"<anon>";
6112 lua_name <<
"[id=" <<
id <<
"]";
6115 ERR_LUA <<
"Failed to register WML event: " << lua_name.str();
6118 return luaL_ref(L, evtIdx);
6124 idx = lua_absindex(L, idx);
6126 int evtIdx = lua_gettop(L);
6127 lua_pushvalue(L, idx);
6128 return luaL_ref(L, evtIdx);
6135 luaL_unref(L, -1, ref);
6142 lua_geti(L, -1, ref);
6143 if(lua_isnil(L, -1))
return false;
6189 lua_pushvalue(L, -1);
6209 std::string message = std::string() +
"function " + name +
" not found";
6210 log_error(message.c_str(),
"Lua SUF Error");
6214 lua_insert(L, -nArgs - 1);
6226 int top = lua_gettop(L);
6237 if(lua_istable(L, -1)) {
6240 lua_pushvalue(L, -1);
6242 lua_pushvalue(L, top + 1);
6244 lua_pushvalue(L, top + 2);
6249 if(luaL_getmetafield(L, -1,
"__descr")) {
6251 if(lua_isstring(L, -1)) {
6253 descr = lua_tostring(L, -1);
6255 lua_pushvalue(L, -2);
6257 lua_pushvalue(L, top + 1);
6259 lua_pushvalue(L, top + 2);
6262 if(lua_isstring(L, -1) && !lua_isnumber(L, -1)) {
6263 descr = lua_tostring(L, -1);
6265 ERR_LUA <<
"Effect __descr metafunction should have returned a string, but instead returned ";
6266 if(lua_isnone(L, -1)) {
6269 ERR_LUA << lua_typename(L, lua_type(L, -1));
6274 }
else if(need_apply) {
6276 lua_pushvalue(L, top + 1);
6278 lua_pushvalue(L, top + 2);
6316 if(!impl_get_callback<bool>(L,
"on_mouse_button")) {
static bool is_enemy(std::size_t side, std::size_t other_side)
Various functions that implement attacks and attack calculations.
Various functions related to moving units.
void advance_unit_at(const advance_unit_params ¶ms)
Various functions that implement advancements of units.
Managing the AIs lifecycle - headers TODO: Refactor history handling and internal commands.
Composite AI with turn sequence which is a vector of stages.
GAME_CONFIG_SETTER("debug", bool, application_lua_kernel)
Class to encapsulate fog/shroud clearing and the resultant sighted events.
bool clear_dest(const map_location &dest, const unit &viewer)
Clears shroud (and fog) at the provided location and its immediate neighbors.
game_events::pump_result_t fire_events()
Fires the sighted events that were earlier recorded by fog/shroud clearing.
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,...
virtual ai_context & get_ai_context()
unwrap
virtual double evaluate()=0
Evaluate the candidate action, resetting the internal state of the action.
virtual void execute()=0
Execute the candidate action.
static bool add_component(component *root, const std::string &path, const config &cfg)
static void expand_simplified_aspects(side_number side, config &cfg)
Expand simplified aspects, similar to the change from 1.7.2 to 1.7.3 but with some additional syntax ...
static const config & get_default_ai_parameters()
get default AI parameters
virtual config to_config() const
Serialize to config.
virtual void push_ai_table()
Method that pushes the AI table of the lua_context on the stack for debugging purposes.
component * get_component(component *root, const std::string &path)
Proxy class for calling AI action handlers defined in Lua.
static lua_ai_action_handler * create(lua_State *L, char const *code, lua_ai_context &context)
Proxy table for the AI context.
static void init(lua_State *L)
static lua_ai_context * create(lua_State *L, char const *code, engine_lua *engine)
bool add_ai_for_side_from_config(side_number side, const config &cfg, bool replace=true)
Adds active AI for specified side from cfg.
void append_active_ai_for_side(ai::side_number side, const config &cfg)
Appends AI parameters to active AI of the given side.
void raise_user_interact()
Notifies all observers of 'ai_user_interact' event.
static manager & get_singleton()
void modify_active_ai_for_side(ai::side_number side, const config &cfg)
Modifies AI parameters for active AI of the given side.
ai::holder & get_active_ai_holder_for_side_dbg(side_number side)
Gets the active AI holder for debug purposes.
bool play_stage()
Play the turn - strategy.
Computes the statistics of a battle between an attacker and a defender unit.
const battle_context_unit_stats & get_defender_stats() const
This method returns the statistics of the defender.
const combatant & get_attacker_combatant(const combatant *prev_def=nullptr)
Get the simulation results.
const battle_context_unit_stats & get_attacker_stats() const
This method returns the statistics of the attacker.
const combatant & get_defender_combatant(const combatant *prev_def=nullptr)
Variant for storing WML attributes.
std::string str(const std::string &fallback="") const
bool empty() const
Tests for an attribute that either was never set or was set to "".
A config object defines a single node in a WML file, with access to child nodes.
config & add_child(std::string_view key)
optional_config_impl< config > optional_child(std::string_view key, int n=0)
Equivalent to mandatory_child, but returns an empty optional if the nth child was not found.
config & child_or_add(std::string_view key)
Returns a reference to the first child with the given key.
child_itors child_range(std::string_view key)
void splice_children(config &src, std::string_view key)
Moves all the children with tag key from src to this.
auto child_name_view() const
A non-owning view over all child tag names.
bool has_child(std::string_view key) const
Determine whether a config has a child or not.
config & mandatory_child(std::string_view key, int n=0)
Returns the nth child with the given key, or throws an error if there is none.
void remove_children(std::string_view key, const std::function< bool(const config &)> &p={})
Removes all children with tag key for which p returns true.
virtual void play_slice()
void add_chat_message(const std::chrono::system_clock::time_point &time, const std::string &speaker, int side, const std::string &msg, events::chat_handler::MESSAGE_TYPE type, bool bell)
void clear_chat_messages()
int village_owner(const map_location &loc) const
Given the location of a village, will return the 1-based number of the team that currently owns it,...
virtual const unit_map & units() const =0
Sort-of-Singleton that many classes, both GUI and non-GUI, use to access the game data.
const team & viewing_team() const
void remove_overlay(const map_location &loc)
remove_overlay will remove all overlays on a tile.
void recalculate_minimap()
Schedule the minimap for recalculation.
void remove_single_overlay(const map_location &loc, const std::string &toDelete)
remove_single_overlay will remove a single overlay from a tile
bool invalidate(const map_location &loc)
Function to invalidate a specific tile for redrawing.
double turbo_speed() const
void adjust_color_overlay(int r, int g, int b)
Add r,g,b to the colors for all images displayed on the map.
static double get_zoom_factor()
Returns the current zoom factor.
void scroll_to_tile(const map_location &loc, SCROLL_TYPE scroll_type=ONSCREEN, bool check_fogged=true, bool force=true)
Scroll such that location loc is on-screen.
bool set_zoom(bool increase)
Zooms the display in (true) or out (false).
tod_color get_color_overlay() const
void invalidate_all()
Function to invalidate all tiles.
rect map_outside_area() const
Returns the available area for a map, this may differ from the above.
void fade_to(const color_t &color, const std::chrono::milliseconds &duration)
Screen fade.
const display_context & context() const
void add_overlay(const map_location &loc, overlay &&ov)
Functions to add and remove overlays from locations.
const map_location & selected_hex() const
bool show_everything() const
static display * get_singleton()
Returns the display object if a display object exists.
void reinit_flags_for_team(const team &)
Rebuild the flag list (not team colors) for a single side.
const map_location & mouseover_hex() const
void set_view_locked(bool value)
Sets whether the map view is locked (e.g.
bool scroll(const point &amount, bool force=false)
Scrolls the display by amount pixels.
void select_hex(const map_location &hex, const bool browse, const bool highlight=true, const bool fire_event=true, const bool force_unhighlight=false)
void set_position(double xpos, double ypos)
void set_alignment(ALIGN align)
void set_lifetime(const std::chrono::milliseconds &lifetime, const std::chrono::milliseconds &fadeout=std::chrono::milliseconds{100})
void set_color(const color_t &color)
void set_border_size(int border)
void set_bg_color(const color_t &bg_color)
void set_clip_rect(const rect &r)
void set_font_size(int font_size)
virtual const std::vector< team > & teams() const override
unit_map::iterator find_visible_unit(const map_location &loc, const team ¤t_team, bool see_all=false)
virtual const unit_map & units() const override
virtual const gamemap & map() const override
static game_config_manager * get()
const game_config_view & game_config() const
A class grating read only view to a vector of config objects, viewed as one config with all children ...
const config & find_mandatory_child(std::string_view key, const std::string &name, const std::string &value) const
void clear_variable(const std::string &varname)
Clears attributes config children does nothing if varname is no valid variable name.
void set_allow_end_turn(bool value, const t_string &reason={})
@ PRELOAD
the preload [event] is fired next phase: PRESTART (normal game), TURN_STARTING_WAITING (reloaded game...
@ INITIAL
creating intitial [unit]s, executing toplevel [lua] etc.
@ PRESTART
the prestart [event] is fired next phase: START (default), GAME_ENDING
@ TURN_PLAYING
The User is controlling the game and invoking actions The game can be saved here.
const std::string & get_theme() const
variable_access_create get_variable_access_write(const std::string &varname)
returns a variable_access that can be used to change the game variables
void set_theme(const std::string &value)
variable_access_const get_variable_access_read(const std::string &varname) const
returns a variable_access that cannot be used to change the game variables
void display_unit_hex(map_location hex)
Change the unit to be displayed in the sidebar.
void invalidate_unit_after_move(const map_location &src, const map_location &dst)
Same as invalidate_unit() if moving the displayed unit.
virtual void highlight_hex(map_location hex) override
Function to highlight a location.
virtual const map_location & displayed_unit_hex() const override
Virtual functions shadowed in game_display.
void new_turn()
Update lighting settings.
bool maybe_rebuild()
Rebuilds the screen if needs_rebuild(true) was previously called, and resets the flag.
display_chat_manager & get_chat_manager()
void float_label(const map_location &loc, const std::string &text, const color_t &color)
Function to float a label above a tile.
void set_arguments(const config &cfg)
The game event manager loads the scenario configuration object, and ensures that events are handled a...
void add_event_handler_from_wml(const config &handler, game_lua_kernel &lk, bool is_menu_item=false)
Create an event handler from an [event] tag.
pending_event_handler add_event_handler_from_lua(const std::string &name, const std::string &id, bool repeat=false, double priority=0., bool is_menu_item=false)
Create an empty event handler.
bool fire_item(const std::string &id, const map_location &hex, game_data &gamedata, filter_context &fc, unit_map &units, bool is_key_hold_repeat=false) const
Fires the menu item with the given id.
bool erase(const std::string &id)
Erases the item with the provided id.
void set_item(const std::string &id, const vconfig &menu_item)
Updates or creates (as appropriate) the menu item with the given id.
void(* handler)(const queued_event &, const vconfig &)
static const map & registry()
void set_action_canceled()
Sets whether or not wml wants to abort the currently executed user action.
pump_result_t fire(const std::string &event, const entity_location &loc1=entity_location::null_entity, const entity_location &loc2=entity_location::null_entity, const config &data=config())
Function to fire an event.
void set_undo_disabled(bool mutated)
[allow_undo] implementation
int intf_get_mouseover_tile(lua_State *L)
Returns the currently overed tile.
void custom_command(const std::string &, const config &)
int intf_put_unit(lua_State *L)
Places a unit on the map.
int intf_get_label(lua_State *L)
int intf_cancel_action(lua_State *)
int intf_set_floating_label(lua_State *L, bool spawn)
Create a new floating label or replace an existing one.
int intf_replace_schedule(lua_State *l)
Replacing the current time of day schedule.
int intf_select_unit(lua_State *L)
Selects and highlights the given location on the map.
int intf_deselect_hex(lua_State *L)
Deselects any highlighted hex on the map.
std::stack< game_events::queued_event const * > queued_events_
int intf_get_all_vars(lua_State *L)
Gets all the WML variables currently set.
int intf_remove_tile_overlay(lua_State *L)
Removes an overlay from a tile.
int intf_screen_fade(lua_State *L)
int intf_erase_unit(lua_State *L)
Erases a unit from the map.
int intf_get_fog_or_shroud(lua_State *L, bool fog)
int intf_override_shroud(lua_State *L)
Overrides the shroud entirely.
int intf_get_variable(lua_State *L)
Gets a WML variable.
int intf_scroll(lua_State *L)
game_lua_kernel(game_state &, play_controller &, reports &)
int intf_set_sub_achievement(lua_State *L)
Marks a single sub-achievement as completed.
int intf_lock_view(lua_State *L)
Sets whether gamemap scrolling is disabled for the user.
void put_unit_helper(const map_location &loc)
int intf_toggle_shroud(lua_State *L, bool place_shroud)
Toggle shroud on some locations Arg 1: Side number Arg 2: List of locations on which to place/remove ...
int intf_match_side(lua_State *L)
Matches a side against the given filter.
int intf_get_selected_tile(lua_State *L)
Returns the currently selected tile.
int cfun_wml_action(lua_State *L)
Executes its upvalue as a wml action.
virtual void log_error(char const *msg, char const *context="Lua error") override
Error reporting mechanisms, used by virtual methods protected_call and load_string.
int cfun_builtin_effect(lua_State *L)
Applies its upvalue as an effect Arg 1: The unit to apply to Arg 3: The [effect] tag contents Arg 3: ...
int impl_theme_item(lua_State *L, const std::string &name)
Executes its upvalue as a theme item generator.
ai::lua_ai_context * create_lua_ai_context(char const *code, ai::engine_lua *engine)
int intf_has_achievement(lua_State *L)
Returns whether an achievement has been completed.
int intf_gamestate_inspector(lua_State *)
int intf_float_label(lua_State *L)
Floats some text on the map.
int intf_find_reach(lua_State *L)
Finds all the locations reachable by a unit.
bool run_event(const game_events::queued_event &)
Executes the game_events.on_event function.
int intf_end_turn(lua_State *)
int save_wml_event()
Store a WML event in the Lua registry, as a function.
int impl_scenario_dir(lua_State *L)
Get a list of scenario data (__dir metamethod).
int intf_set_achievement(lua_State *L)
Sets an achievement as being completed.
int intf_get_units(lua_State *)
Gets all the units matching a given filter.
int intf_color_adjust(lua_State *L)
int intf_redraw(lua_State *L)
int intf_set_village_owner(lua_State *L)
Sets the owner of a village.
int impl_current_dir(lua_State *L)
Gets a list of date about current point of game (__dir metamethod).
static config preload_config
int intf_find_cost_map(lua_State *L)
Is called with one or more units and builds a cost map.
int intf_get_time_area(lua_State *)
int intf_highlight_hex(lua_State *L)
Highlights the given location on the map.
bool run_wml_event(int ref, const vconfig &args, const game_events::queued_event &ev, bool *out=nullptr)
Run a WML stored in the Lua registry.
int intf_scroll_to_tile(lua_State *L)
Scrolls to given tile.
int intf_get_side(lua_State *L)
int intf_remove_event(lua_State *L)
int intf_is_enemy(lua_State *L)
Returns whether the first side is an enemy of the second one.
static void extract_preload_scripts(const game_config_view &game_config)
int impl_get_terrain_info(lua_State *L)
Gets details about a terrain.
virtual std::string my_name() override
User-visible name of the lua kernel that they are talking to.
int intf_remove_label(lua_State *L)
bool run_wml_action(const std::string &, const vconfig &, const game_events::queued_event &)
Runs a command from an event handler.
int intf_move_floating_label(lua_State *L)
int intf_match_unit(lua_State *L)
Matches a unit against the given filter.
int intf_add_time_area(lua_State *)
Adding new time_areas dynamically with Standard Location Filters.
scoped_lua_argument push_wml_events_table(lua_State *L) const
Pushes the WML events table to the Lua stack.
void clear_wml_event(int ref)
Clear a WML event store in the Lua registry.
int intf_create_animator(lua_State *)
int impl_theme_items_dir(lua_State *L)
Get all available theme_items (__dir metamethod).
int intf_add_event_wml(lua_State *L)
Add a new event handler Arg: A full event specification as a WML config.
int impl_scenario_set(lua_State *L)
Sets some scenario data (__newindex metamethod).
int intf_message(lua_State *L)
Displays a message in the chat window and in the logs.
int intf_set_side_id(lua_State *L)
int intf_view_locked(lua_State *L)
Gets whether gamemap scrolling is disabled for the user.
int intf_get_displayed_unit(lua_State *)
Gets the unit displayed in the sidebar.
bool run_wml_conditional(const std::string &, const vconfig &)
Evaluates a WML conidition.
int intf_get_recall_units(lua_State *L)
Gets the numeric ids of all the units matching a given filter on the recall lists.
int intf_add_label(lua_State *L)
int intf_zoom(lua_State *L)
int intf_log_replay(lua_State *L)
const game_events::queued_event & get_event_info()
int intf_unit_ability(lua_State *L)
Returns true if the unit has the given ability enabled.
void push_builtin_effect()
Registers a function for use as an effect handler.
int impl_run_animation(lua_State *)
std::string apply_effect(const std::string &name, unit &u, const config &cfg, bool need_apply)
int intf_fire_wml_menu_item(lua_State *L)
Fires a wml menu item.
int intf_clear_menu_item(lua_State *L)
void mouse_over_hex_callback(const map_location &loc)
int impl_theme_items_get(lua_State *L)
Creates a field of the theme_items table and returns it (__index metamethod).
int intf_find_vacant_tile(lua_State *L)
Finds a vacant tile.
play_controller & play_controller_
int impl_schedule_dir(lua_State *L)
const gamemap & map() const
int map_locked_
A value != 0 means that the shouldn't remove any units from the map, usually because we are currently...
static std::vector< config > preload_scripts
int intf_get_unit(lua_State *)
Gets the unit at the given location or with the given id.
int impl_current_get(lua_State *L)
Gets some data about current point of game (__index metamethod).
int impl_schedule_set(lua_State *L)
void select_hex_callback(const map_location &loc)
void set_wml_condition(const std::string &, bool(*)(const vconfig &))
Registers a function for use as a conditional handler.
int impl_end_level_data_set(lua_State *)
std::string synced_state()
converts synced_context::get_synced_state() to a string.
int intf_find_path(lua_State *L)
Finds a path between two locations.
int intf_remove_floating_label(lua_State *L)
void set_wml_action(const std::string &, game_events::wml_action::handler)
Registers a function for use as an action handler.
int intf_put_recall_unit(lua_State *L)
Puts a unit on a recall list.
int intf_teleport(lua_State *L)
Teeleports a unit to a location.
void luaW_push_schedule(lua_State *L, int area_index)
int intf_add_tile_overlay(lua_State *L)
Adds an overlay on a tile.
int intf_play_sound(lua_State *L)
Plays a sound, possibly repeated.
void lua_chat(const std::string &caption, const std::string &msg)
int intf_allow_end_turn(lua_State *)
Allow undo sets the flag saying whether the event has mutated the game to false.
int intf_get_village_owner(lua_State *L)
Gets the side of a village owner.
int intf_get_sides(lua_State *L)
Returns a proxy table array for all sides matching the given SSF.
int intf_has_sub_achievement(lua_State *L)
Returns whether an achievement has been completed.
int intf_create_side(lua_State *L)
void initialize(const config &level)
int intf_add_undo_actions(lua_State *L)
Add undo actions for the current active event Arg 1: Either a table of ActionWML or a function to cal...
void save_game(config &level)
Executes the game_events.on_save function and adds to cfg the returned tags.
int impl_scenario_get(lua_State *L)
Gets some scenario data (__index metamethod).
int intf_remove_time_area(lua_State *)
Removing new time_areas dynamically with Standard Location Filters.
int impl_schedule_len(lua_State *L)
int intf_get_locations(lua_State *L)
Gets all the locations matching a given filter.
int intf_add_event(lua_State *L)
Add a new event handler Arg 1: Table of options.
int intf_simulate_combat(lua_State *L)
Simulates a combat between two units.
int impl_get_terrain_list(lua_State *L)
Gets a list of known terrain codes.
std::vector< team > & teams()
int intf_progress_achievement(lua_State *L)
Progresses the provided achievement.
int intf_match_location(lua_State *L)
Matches a location against the given filter.
int intf_toggle_fog(lua_State *L, const bool clear)
Implements the lifting and resetting of fog via WML.
int intf_extract_unit(lua_State *L)
Extracts a unit from the map or a recall list and gives it to Lua.
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...
int intf_clear_messages(lua_State *)
Removes all messages from the chat window.
int intf_allow_undo(lua_State *)
Allow undo sets the flag saying whether the event has mutated the game to false.
int impl_schedule_get(lua_State *L)
int intf_set_variable(lua_State *L)
Sets a WML variable.
int impl_theme_items_set(lua_State *L)
Sets a field of the theme_items table (__newindex metamethod).
void set_game_display(game_display *gd)
int intf_set_menu_item(lua_State *L)
ai::lua_ai_action_handler * create_lua_ai_action_handler(char const *code, ai::lua_ai_context &context)
bool mouse_button_callback(const map_location &loc, const std::string &button, const std::string &event)
int intf_get_achievement(lua_State *L)
Returns information on a single achievement, or no data if the achievement is not found.
std::vector< int > get_sides_vector(const vconfig &cfg)
Gets a vector of sides from side= attribute in a given config node.
int intf_fire_event(lua_State *L, const bool by_id)
Fires an event.
int intf_delay(lua_State *L)
Delays engine for a while.
int intf_add_event_simple(lua_State *L)
Add a new event handler Arg 1: Event to handle, as a string or list of strings; or menu item ID if th...
bool run_filter(char const *name, const unit &u)
Runs a script from a unit filter.
int intf_find_vision_range(lua_State *L)
Finds all the locations for which a given unit would remove the fog (if there was fog on the map).
int intf_skip_messages(lua_State *L)
Set whether to skip messages Arg 1 (optional) - boolean.
game_display * game_display_
int cfun_undoable_event(lua_State *L)
Upvalue 1: The event function Upvalue 2: The undo function Arg 1: The event content.
void load_game(const config &level)
Executes the game_events.on_load function and passes to it all the scenario tags not yet handled.
int intf_get_time_of_day(lua_State *L)
Gets time of day information.
int intf_get_color_adjust(lua_State *L)
int intf_is_skipping_messages(lua_State *L)
Return true if a replay is in progress but the player has chosen to skip it.
void add_side_wml(config cfg)
creates a new side during a game.
const std::unique_ptr< actions::undo_list > undo_stack_
undo_stack_ is never nullptr.
const std::unique_ptr< game_events::manager > events_manager_
game_events::wmi_manager & get_wml_menu_items()
Encapsulates the map of the game.
const t_translation::ter_list & get_terrain_list() const
Gets the list of terrains.
const terrain_type & get_terrain_info(const t_translation::terrain_code &terrain) const
virtual void log_error(char const *msg, char const *context="Lua error")
Error reporting mechanisms, used by virtual methods protected_call and load_string.
bool load_string(const std::string &prog, const std::string &name, const error_handler &, bool allow_unsafe=false)
void run_lua_tag(const config &cfg)
Runs a [lua] tag.
Efficiently creates new LUA "named tuples" with the specified field names.
Storage for a unit, either owned by the Lua code (ptr != 0), a local variable unit (c_ptr !...
bool put_map(const map_location &loc)
int on_recall_list() const
unit_ptr get_shared() const
const terrain_label * set_label(const map_location &loc, const t_string &text, const int creator=-1, const std::string &team="", const color_t color=font::NORMAL_COLOR, const bool visible_in_fog=true, const bool visible_in_shroud=false, const bool immutable=false, const std::string &category="", const t_string &tooltip="")
const terrain_label * get_label(const map_location &loc, const std::string &team_name) const
void recalculate_shroud()
game_classification & get_classification()
events::mouse_handler & get_mouse_handler_base() override
Get a reference to a mouse handler member a derived class uses.
bool is_skipping_story() const
bool is_skipping_replay() const
std::shared_ptr< wb::manager > get_whiteboard() const
virtual void force_end_turn()=0
game_events::wml_event_pump & pump()
std::set< std::string > & encountered_units()
int progress_achievement(const std::string &content_for, const std::string &id, int limit=999999, int max_progress=999999, int amount=0)
Increments the achievement's current progress by amount if it hasn't already been completed.
void set_achievement(const std::string &content_for, const std::string &id)
Marks the specified achievement as completed.
void set_sub_achievement(const std::string &content_for, const std::string &id, const std::string &sub_id)
Marks the specified sub-achievement as completed.
void add_log_data(const std::string &key, const std::string &var)
void register_generator(const std::string &name, generator *)
config generate_builtin_report(const std::string &name, const context &rc)
Generate the specified report using the given context, excluding dynamic generators.
const std::set< std::string > & report_list()
Shallow wrapper around lua_geti which pops the top variable from the Lua stack when destroyed.
An object to leave the synced context during draw or unsynced wml items when we don’t know whether we...
std::vector< int > get_teams() const
bool match(const team &t) const
static map & registry()
using static function variable instead of static member variable to prevent static initialization fia...
static synced_state get_synced_state()
This class stores all the data for a single 'side' (in game nomenclature).
game_events::pump_result_t get_village(const map_location &, const int owner_side, game_data *fire_event)
Acquires a village from owner_side.
const std::string & team_name() const
void set_color(const std::string &color)
void set_flag(const std::string &flag)
void lose_village(const map_location &)
bool match(const map_location &loc) const
void get_locations(std::set< map_location > &locs, bool with_border=false) const
gets all locations on the map that match this filter
To store label data Class implements logic for rendering.
const std::string & id() const
t_translation::terrain_code number() const
void replace_schedule(const config &time_cfg)
Replace the time of day schedule.
int number_of_turns() const
std::vector< std::string > get_area_ids() const
const std::set< map_location > & get_area_by_index(int index) const
void remove_time_area(const std::string &id)
Removes a time area from config, making it follow the scenario's normal time-of-day sequence.
const std::vector< time_of_day > & times() const
void add_time_area(const gamemap &map, const config &cfg)
Adds a new local time area from config, making it follow its own time-of-day sequence.
void replace_local_schedule(const std::vector< time_of_day > &schedule, int area_index, int initial_time=0)
const time_of_day & get_time_of_day(int for_turn=0) const
Returns global time of day for the passed turn.
time_of_day get_illuminated_time_of_day(const unit_map &units, const gamemap &map, const map_location &loc, int for_turn=0) const
Returns time of day object for the passed turn at a location.
const std::set< map_location > & get_area_by_id(const std::string &id) const
std::pair< int, std::string > get_area_on_hex(const map_location &loc) const
void reset_affect_adjacent(const unit_map &units)
Refresh map around unit if has ability with [affect_adjacent/distant] tag.
void wait_for_end() const
void add_animation(unit_const_ptr animated_unit, const unit_animation *animation, const map_location &src=map_location::null_location(), bool with_bars=false, const std::string &text="", const color_t text_color={0, 0, 0})
std::vector< const unit * > all_matches_with_unit(const unit &u) const
std::vector< const unit * > all_matches_at(const map_location &loc) const
std::vector< const unit * > all_matches_on_map(const map_location *loc=nullptr, const unit *other_unit=nullptr) const
Container associating units to locations.
unit_ptr extract(const map_location &loc)
Extracts a unit from the map.
unit_iterator find(std::size_t id)
std::size_t erase(const map_location &l)
Erases the unit at location l, if any.
umap_retval_pair_t insert(const unit_ptr &p)
Inserts the unit pointed to by p into the map.
umap_retval_pair_t move(const map_location &src, const map_location &dst)
Moves a unit from location src to location dst.
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.
config_array_view traits() const
A single unit type that the player may recruit.
const unit_type & get_variation(const std::string &id) const
bool has_variation(const std::string &variation_id) const
This class represents a single unit of a specific type.
static void clear_status_caches()
Clear this unit status cache for all units.
static unit_ptr create(const config &cfg, bool use_traits=false, const vconfig *vcfg=nullptr)
Initializes a unit from a config.
Additional functionality for a non-const variable_info.
Information on a WML variable.
A variable-expanding proxy for the config class.
static vconfig unconstructed_vconfig()
This is just a wrapper for the default constructor; it exists for historical reasons and to make it c...
constexpr uint8_t ALPHA_OPAQUE
A component of the AI framework.
Define conditionals for the game's events mechanism, a.k.a.
Definitions for the interface to Wesnoth Markup Language (WML).
Managing the AIs configuration - headers.
std::string deprecated_message(const std::string &elem_name, DEP_LEVEL level, const version_info &version, const std::string &detail)
@ border
The border of the map.
LUA AI Support engine - creating specific ai components from config.
Define locations as used by the game's events mechanism.
static int intf_modify_ai(lua_State *L, const char *action)
int dispatch(lua_State *L)
static int load_fake_units(lua_State *L, int arg, T &fake_units)
static int impl_animator_get(lua_State *L)
#define SCENARIO_SETTER(name, type)
static int impl_null_callback(lua_State *L)
static int impl_animator_collect(lua_State *L)
#define SCENARIO_GETTER(name, type)
static int intf_unit_resistance(lua_State *L)
Returns unit resistance against a given attack type.
static int intf_synchronize_choice(lua_State *L)
Ensures a value is synchronized among all the clients.
static int luaW_check_schedule(lua_State *L, int idx)
#define SCENARIO_VALID(name)
static lg::log_domain log_scripting_lua("scripting/lua")
static int intf_add_known_unit(lua_State *L)
Adds a new known unit type to the help system.
static int intf_append_ai(lua_State *L)
static int impl_end_level_data_collect(lua_State *L)
static int impl_mp_settings_len(lua_State *L)
#define CURRENT_GETTER(name, type)
#define READ_ONE_FILTER(key, tag)
#define SCHEDULE_SETTER(name, type)
luaW_Registry scenarioReg
bool(*)(const vconfig &) wml_conditional_handler
static int cfun_exec_candidate_action(lua_State *L)
static int intf_run_event_wml(lua_State *L)
static int intf_eval_conditional(lua_State *L)
Evaluates a boolean WML conditional.
luaW_Registry & gameConfigReg()
static int impl_clear_animation(lua_State *L)
static int intf_advance_unit(lua_State *L)
Advances a unit if the unit has enough xp.
static int impl_add_animation(lua_State *L)
static int intf_debug_ai(lua_State *L)
Debug access to the ai tables.
#define GAME_CONFIG_SIMPLE_SETTER(name)
static int intf_unit_movement_cost(lua_State *L)
Returns unit movement cost on a given terrain.
static int intf_add_modification(lua_State *L)
Adds a modification to a unit.
#define SCHEDULE_GETTER(name, type)
static void luaW_pushsimdata(lua_State *L, const combatant &cmb)
Puts a table at the top of the stack with some combat result.
#define CALLBACK_GETTER(name, type)
static std::string read_event_name(lua_State *L, int idx)
static int intf_remove_modifications(lua_State *L)
Removes modifications from a unit.
int dispatch2(lua_State *L)
static int intf_copy_unit(lua_State *L)
Copies a unit.
static void push_component(lua_State *L, ai::component *c, const std::string &ct="")
static int impl_mp_settings_get(lua_State *L)
static int cfun_exec_stage(lua_State *L)
static int impl_game_events_get(lua_State *L)
static int intf_modify_ai_old(lua_State *L)
Lua frontend to the modify_ai functionality.
static int intf_get_resource(lua_State *L)
Gets a table for an resource tag.
static const char animatorKey[]
static bool is_handled_file_tag(std::string_view s)
These are the child tags of [scenario] (and the like) that are handled elsewhere (in the C++ code).
static int intf_synchronize_choices(lua_State *L)
Ensures a value is synchronized among all the clients.
static int intf_switch_ai(lua_State *L)
static int intf_create_unit(lua_State *L)
Creates a unit from its WML description.
static int intf_transform_unit(lua_State *L)
Changes a unit to the given unit type.
static int impl_floating_label_getmethod(lua_State *L)
static int intf_get_viewing_side(lua_State *L)
Gets currently viewing side.
int(game_lua_kernel::* member_callback)(lua_State *)
int(game_lua_kernel::* member_callback2)(lua_State *, bool)
static int intf_invoke_synced_command(lua_State *L)
static void luaW_push_tod(lua_State *L, const time_of_day &tod)
static int intf_do_unsynced(lua_State *L)
Calls a function in an unsynced context (this specially means that all random calls used by that func...
luaW_Registry scheduleReg
static void luaW_pushsimweapon(lua_State *L, const battle_context_unit_stats &bcustats)
Puts a table at the top of the stack with information about the combatants' weapons.
static int intf_handle_user_interact(lua_State *)
static int intf_unit_jamming_cost(lua_State *L)
Returns unit jamming cost on a given terrain.
static int impl_end_level_data_get(lua_State *L)
static lg::log_domain log_wml("wml")
static int intf_unit_defense(lua_State *L)
Returns unit defense on a given terrain.
static int intf_get_era(lua_State *L)
Gets a table for an era tag.
static bool impl_get_callback(lua_State *L, const std::string &name)
#define SCHEDULE_VALID(name)
static int cfun_wml_condition(lua_State *L)
Executes its upvalue as a wml condition and returns the result.
luaW_Registry callbacksReg
static int * luaW_check_floating_label(lua_State *L, int idx)
static int impl_game_events_dir(lua_State *L)
static int intf_unit_vision_cost(lua_State *L)
Returns unit vision cost on a given terrain.
static std::string _(const char *str)
bool get_ability_bool(const std::string &tag_name, const map_location &loc) const
Checks whether this unit currently possesses or is affected by a given ability.
const std::string & id() const
Gets this unit's id.
int side() const
The side this unit belongs to.
void advance_to(const unit_type &t, bool use_traits=false)
Advances this unit to another type.
int resistance_against(const std::string &damage_name, bool attacker, const map_location &loc) const
The unit's resistance against a given damage type.
int defense_modifier(const t_translation::terrain_code &terrain, const map_location &loc) const
The unit's defense on a given terrain.
unit_animation_component & anim_comp() const
void add_modification(const std::string &type, const config &modification, bool no_add=false)
Add a new modification to the unit.
static const std::set< std::string > builtin_effects
std::string describe_builtin_effect(const std::string &type, const config &effect)
Construct a string describing a built-in effect.
config & get_modifications()
Get the raw modifications.
void expire_modifications(const std::string &duration)
Clears those modifications whose duration has expired.
void apply_builtin_effect(const std::string &type, const config &effect)
Apply a builtin effect to the unit.
const map_location & get_location() const
The current map location this unit is at.
int movement_cost(const t_translation::terrain_code &terrain) const
Get the unit's movement cost on a particular terrain.
int vision_cost(const t_translation::terrain_code &terrain) const
Get the unit's vision cost on a particular terrain.
int jamming_cost(const t_translation::terrain_code &terrain) const
Get the unit's jamming cost on a particular terrain.
std::string label
What to show in the filter's drop-down list.
std::string id
Text to match against addon_info.tags()
Define the handlers for the game's events mechanism.
bool tiles_adjacent(const map_location &a, const map_location &b)
Function which tells if two locations are adjacent.
Standard logging facilities (interface).
#define log_scope(description)
std::decay_t< T > lua_check(lua_State *L, int n)
void luaW_pushconfig(lua_State *L, const config &cfg)
Converts a config object to a Lua table pushed at the top of the stack.
bool luaW_iststring(lua_State *L, int index)
config luaW_checkconfig(lua_State *L, int index)
Converts an optional table or vconfig to a config object.
void luaW_pushlocation(lua_State *L, const map_location &ml)
Converts a map location object to a Lua table pushed at the top of the stack.
std::set< map_location > luaW_check_locationset(lua_State *L, int idx)
Converts a table of integer pairs to a set of map location objects.
void luaW_pushtstring(lua_State *L, const t_string &v)
Pushes a t_string on the top of the stack.
bool luaW_pushvariable(lua_State *L, variable_access_const &v)
bool luaW_tovconfig(lua_State *L, int index, vconfig &vcfg)
Gets an optional vconfig from either a table or a userdata.
void luaW_pushvconfig(lua_State *L, const vconfig &cfg)
Pushes a vconfig on the top of the stack.
bool luaW_toboolean(lua_State *L, int n)
int luaW_type_error(lua_State *L, int narg, const char *tname)
std::string_view luaW_tostring(lua_State *L, int index)
bool luaW_getmetafield(lua_State *L, int idx, const char *key)
Like luaL_getmetafield, but returns false if key is an empty string or begins with two underscores.
bool luaW_totstring(lua_State *L, int index, t_string &str)
Converts a scalar to a translatable string.
bool luaW_tableget(lua_State *L, int index, const char *key)
bool luaW_checkvariable(lua_State *L, variable_access_create &v, int n)
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.
bool luaW_toconfig(lua_State *L, int index, config &cfg)
Converts an optional table or vconfig to a config object.
int luaW_push_locationset(lua_State *L, const std::set< map_location > &locs)
Converts a set of map locations to a Lua table pushed at the top of the stack.
vconfig luaW_checkvconfig(lua_State *L, int index, bool allow_missing)
Gets an optional vconfig from either a table or a userdata.
bool luaW_tolocation(lua_State *L, int index, map_location &loc)
Converts an optional table or pair of integers to a map location object.
map_location luaW_checklocation(lua_State *L, int index)
Converts an optional table or pair of integers to a map location object.
bool luaW_getglobal(lua_State *L, const std::vector< std::string > &path)
Pushes the value found by following the variadic names (char *), if the value is not nil.
t_string luaW_checktstring(lua_State *L, int index)
Converts a scalar to a translatable string.
#define return_cstring_attrib(name, accessor)
#define return_string_attrib(name, accessor)
#define return_cfgref_attrib(name, accessor)
#define return_int_attrib(name, accessor)
#define modify_bool_attrib(name, accessor)
#define return_bool_attrib(name, accessor)
#define return_cfg_attrib(name, accessor)
#define modify_string_attrib(name, accessor)
#define return_string_attrib_deprecated(name, prefix, level, version, msg, accessor)
#define GAME_CONFIG_GETTER(name, type, kernel_type)
void luaW_pushracetable(lua_State *L)
void luaW_pushteam(lua_State *L, team &tm)
Create a full userdata containing a pointer to the team.
team * luaW_toteam(lua_State *L, int idx)
Test if the top stack element is a team, and if so, return it.
team & luaW_checkteam(lua_State *L, int idx)
Test if the top stack element is a team, and if not, error.
std::set< map_location > location_set
int intf_terrain_mask(lua_State *L)
Replaces part of the map.
int intf_on_border(lua_State *L)
int intf_on_board(lua_State *L)
int intf_terrainmap_iter(lua_State *L)
int intf_terrainmap_get(lua_State *L)
int intf_replace_if_failed(lua_State *L)
lua_unit * luaW_checkunit_ref(lua_State *L, int index)
Similar to luaW_checkunit but returns a lua_unit; use this if you need to handle map and recall units...
unit & luaW_checkunit(lua_State *L, int index, bool only_on_map)
Converts a Lua value to a unit pointer.
bool luaW_isunit(lua_State *L, int index)
Test if a Lua value is a unit.
unit_ptr luaW_checkunit_ptr(lua_State *L, int index, bool only_on_map)
Similar to luaW_checkunit but returns a unit_ptr; use this instead of luaW_checkunit when using an ap...
lua_unit * luaW_pushlocalunit(lua_State *L, unit &u)
Pushes a private unit on the stack.
unit * luaW_tounit(lua_State *L, int index, bool only_on_map)
Converts a Lua value to a unit pointer.
lua_unit * luaW_pushunit(lua_State *L, Args... args)
int intf_create_attack(lua_State *L)
const_attack_ptr luaW_toweapon(lua_State *L, int idx)
void luaW_pushweapon(lua_State *L, const attack_ptr &weapon)
std::map< std::string, config > traits_map
bool clear_shroud(int side, bool reset_fog, bool fire_events)
Function that will clear shroud (and fog) based on current unit positions.
game_events::pump_result_t get_village(const map_location &loc, int side, bool *action_timebonus, bool fire_event)
Makes it so the village at the given location is owned by the given side.
void create_jamming_map(std::map< map_location, int > &jamming, const team &view_team)
Helper function that creates the map of enemy anti-vision that's needed when creating a pathfinding::...
void clear()
Clear the current render target.
Handling of system events.
const color_t LABEL_COLOR
int add_floating_label(const floating_label &flabel)
add a label floating on the screen above everything else.
void remove_floating_label(int handle, const std::chrono::milliseconds &fadeout)
removes the floating label given by 'handle' from the screen
void move_floating_label(int handle, double xmove, double ymove)
moves the floating label given by 'handle' by (xmove,ymove)
Game configuration data as global variables.
void load_config(const config &v)
bool variable_matches(const vconfig &values)
bool have_location(const vconfig &cfg)
bool have_unit(const vconfig &cfg)
bool conditional_passed(const vconfig &cond)
bool fire_event(const ui_event event, const std::vector< std::pair< widget *, ui_event >> &event_chain, widget *dispatcher, widget *w, F &&... params)
Helper function for fire_event.
std::shared_ptr< halo_record > handle
std::stringstream & log_to_chat()
Use this to show WML errors in the ingame chat.
std::string register_table(lua_State *L)
std::string register_vconfig_metatable(lua_State *L)
Adds the vconfig metatable.
int intf_tovconfig(lua_State *L)
Creates a vconfig containing the WML table.
void set_functions(lua_State *L, const std::vector< lua_cpp::Reg > &functions)
Analogous to lua_setfuncs, it registers a collection of function wrapper objects into a table,...
void push_closure(lua_State *L, const lua_function &f, int nup)
Pushes a closure which retains a std::function object as its first up-value.
int intf_show_recall_dialog(lua_State *L)
int intf_show_recruit_dialog(lua_State *L)
int show_gamestate_inspector(const std::string &name, const game_data &data, const game_state &state)
std::string register_metatable(lua_State *L)
std::string register_metatable(lua_State *L)
std::string register_metatables(lua_State *L)
std::string register_metatable(lua_State *L)
std::string register_table(lua_State *L)
std::string register_metatables(lua_State *L)
std::string register_attacks_metatables(lua_State *L)
std::string tag(std::string_view tag, Args &&... data)
Wraps the given data in the specified tag.
config get_user_choice(const std::string &name, const user_choice &uch, int side=0)
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.
plain_route a_star_search(const map_location &src, const map_location &dst, double stop_at, const cost_calculator &calc, const std::size_t width, const std::size_t height, const teleport_map *teleports, bool border)
const teleport_map get_teleport_locations(const unit &u, const team &viewing_team, bool see_all, bool ignore_units, bool check_vision)
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,...
Unit and team statistics.
fake_unit_manager * fake_units
play_controller * controller
std::shared_ptr< wb::manager > whiteboard
Contains the general settings which have a default.
void play_sound(const std::string &files, sound_tracks::type group, unsigned int repeats)
terrain_code read_terrain_code(std::string_view str, const ter_layer filler)
Reads a single terrain from a string.
constexpr terrain_code NONE_TERRAIN
std::string write_terrain_code(const terrain_code &tcode)
Writes a single terrain code to a string.
void move_unit(const std::vector< map_location > &path, const unit_ptr &u, bool animate, map_location::direction dir, bool force_scroll)
Display a unit moving along a given path.
std::size_t size(std::string_view str)
Length in characters of a UTF-8 string.
std::size_t index(std::string_view str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
auto find(Container &container, const Value &value, const Projection &projection={})
@ STRIP_SPACES
REMOVE_EMPTY: remove empty elements.
int stoi(std::string_view str)
Same interface as std::stoi and meant as a drop in replacement, except:
std::string join_map(const T &v, const std::string &major=",", const std::string &minor=":")
std::string join(const Range &v, const std::string &s=",")
Generates a new string joining container items in a list.
std::vector< std::string > split(const config_attribute_value &val)
auto * find(Container &container, const Value &value)
Convenience wrapper for using find on a container without needing to comare to end()
bool headless()
The game is running headless.
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
This module contains various pathfinding functions and utilities.
std::shared_ptr< const unit > unit_const_ptr
std::shared_ptr< const attack_type > const_attack_ptr
std::shared_ptr< unit > unit_ptr
Define the game's event mechanism.
void lua_push(lua_State *L, const T &val)
std::decay_t< T > luaW_table_get_def(lua_State *L, int index, std::string_view k, const T &def)
returns t[k] where k is the table at index index and k is k or def if it is not convertible to the co...
void luaW_table_set(lua_State *L, int index, std::string_view k, const T &value)
candidate action framework
rect dst
Location on the final composed sheet.
rect src
Non-transparent portion of the surface to compose.
A set of achievements tied to a particular content.
Represents a single achievement and its data.
std::string icon_completed_
The icon of the achievement to show on the UI if the achievement is completed.
t_string name_completed_
The name of the achievement to show on the UI if the achievement is completed.
t_string description_completed_
The name of the achievement to show on the UI if the achievement is completed.
bool achieved_
Whether the achievement has been completed.
std::string id_
The ID of the achievement.
int max_progress_
When the achievement's current progress matches or equals this value, then it should be marked as com...
std::string sound_path_
The path to a sound to play when an achievement is completed.
int current_progress_
The current progress value of the achievement.
std::vector< sub_achievement > sub_achievements_
The list of distinct sub-achievements for this achievement.
advances the unit at loc if it has enough experience, maximum 20 times.
advance_unit_params & animate(bool value)
advance_unit_params & fire_events(bool value)
Structure describing the statistics of a unit involved in the battle.
bool slows
Attack slows opponent when it hits.
unsigned int num_blows
Effective number of blows, takes swarm into account.
std::string plague_type
The plague type used by the attack, if any.
bool petrifies
Attack petrifies opponent when it hits.
int drain_percent
Percentage of damage recovered as health.
bool drains
Attack drains opponent when it hits.
const_attack_ptr weapon
The weapon used by the unit to attack the opponent, or nullptr if there is none.
unsigned int rounds
Berserk special can force us to fight more than one round.
int damage
Effective damage of the weapon (all factors accounted for).
bool poisons
Attack poisons opponent when it hits.
unsigned int chance_to_hit
Effective chance to hit as a percentage (all factors accounted for).
int drain_constant
Base HP drained regardless of damage dealt.
bool firststrike
Attack has firststrike special.
int attack_num
Index into unit->attacks() or -1 for none.
bool plagues
Attack turns opponent into a zombie when fatal.
callbacks_tag(game_lua_kernel &k)
The basic class for representing 8-bit RGB or RGBA colour values.
static color_t from_hex_string(std::string_view c)
Creates a new color_t object from a string variable in hex format.
static color_t from_rgb_string(std::string_view c)
Creates a new opaque color_t object from a string variable in "R,G,B" format.
double slowed
Resulting chance we are slowed.
std::vector< double > hp_dist
Resulting probability distribution (might be not as large as max_hp)
double poisoned
Resulting chance we are poisoned.
double average_hp(unsigned int healing=0) const
What's the average hp (weighted average of hp_dist).
double untouched
Resulting chance we were not hit by this opponent (important if it poisons)
void push_schedule(lua_State *L) const
current_tag(game_lua_kernel &k)
Additional information on the game outcome which can be provided by WML.
Error used for any general game error, e.g.
game_config_glk_tag(lua_kernel_base &k)
const map_location & filter_loc() const
Represents a single filter condition on an event.
Holds a lookup table for members of one type of object.
int dir(lua_State *L)
Implement __dir metamethod.
int set(lua_State *L)
Implement __newindex metamethod.
int get(lua_State *L)
Implement __index metamethod.
void serialize(config &cfg) const override
Serializes the filter into a config, if possible.
lua_event_filter(game_lua_kernel &lk, int idx, const config &args)
bool operator()(const game_events::queued_event &event_info) const override
Runs the filter and returns whether it passes on the given event.
static game_lua_kernel & get(lua_State *L, int)
static game_lua_kernel & get(lua_State *L, int)
static scenario_tag get(lua_State *L, int)
static schedule_tag get(lua_State *L, int n)
Cost function object relying on a Lua function.
Encapsulates the map of the game.
static const map_location & null_location()
game_lua_kernel * kernel_
map_locker(game_lua_kernel *kernel)
Interface for querying local choices.
virtual config query_user(int side) const =0
virtual std::string description() const
virtual bool is_visible() const
whether the choice is visible for the user like an advancement choice a non-visible choice is for exa...
virtual config random_choice(int side) const =0
Structure which uses find_routes() to build a cost map This maps each hex to a the movements a unit w...
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)
std::pair< int, int > get_pair_at(map_location loc) const
Accessor for the cost/reach-amount pairs.
Object which contains all the possible locations a unit can move to, with associated best routes to t...
Structure which holds a single route between one location and another.
std::vector< map_location > steps
int move_cost
Movement cost for reaching the end of the route.
A refinement of paths for use when calculating vision.
std::set< map_location > edges
The edges are the non-destination hexes bordering the destinations.
An abstract description of a rectangle with integer coordinates.
scenario_tag(game_lua_kernel &k)
auto end_level_set() const
schedule_tag(game_lua_kernel &k)
static std::string get_string(enum_type key)
Converts a enum to its string equivalent.
static constexpr utils::optional< enum_type > get_enum(const std::string_view value)
Converts a string into its enum equivalent.
Represents a distinct sub-achievement within another achievement.
std::string id_
The ID of the sub-achievement.
bool achieved_
Whether the sub-achievement has been completed.
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
Object which defines a time of day with associated bonuses, image, sounds etc.
tod_color color
The color modifications that should be made to the game board to reflect the time of day.
int lawful_bonus
The % bonus lawful units receive.
std::string image
The image to be displayed in the game status.
std::string sounds
List of "ambient" sounds associated with this time_of_day, Played at the beginning of turn.
std::string image_mask
The image that is to be laid over all images while this time of day lasts.
pointer get_shared_ptr() const
This is exactly the same as operator-> but it's slightly more readable, and can replace &*iter syntax...
static map_location::direction n
static map_location::direction s
unit_type_data unit_types
Display units performing various actions: moving, attacking, and dying.
Various functions that implement the undoing (and redoing) of in-game commands.
Various functions implementing vision (through fog of war and shroud).