114 #include <functional>
126 #include <SDL2/SDL_timer.h>
133 #define LOG_LUA LOG_STREAM(info, log_scripting_lua)
134 #define WRN_LUA LOG_STREAM(warn, log_scripting_lua)
135 #define ERR_LUA LOG_STREAM(err, log_scripting_lua)
138 #define ERR_WML LOG_STREAM(err, log_wml)
146 template <member_callback method>
148 return ((lua_kernel_base::get_lua_kernel<game_lua_kernel>(L)).*method)(L);
154 template <member_callback2 method,
bool b>
156 return ((lua_kernel_base::get_lua_kernel<game_lua_kernel>(L)).*method)(L,
b);
206 if(!sides.
empty()) {
WRN_LUA <<
"ignoring duplicate side filter information (inline side=)"; }
219 struct queued_event_context
222 std::stack<qe const *> & stack_;
224 queued_event_context(qe
const *new_qe, std::stack<qe const*> & stack)
230 ~queued_event_context()
245 lua_pushinteger(L, disp->viewing_side());
246 lua_pushboolean(L, disp->show_everything());
264 anim.~unit_animator();
273 std::string which = luaL_checkstring(L, 3);
275 std::string hits_str = luaL_checkstring(L, 4);
285 if(lua_istable(L, 5)) {
286 lua_getfield(L, 5,
"target");
289 return luaL_argerror(L, 5,
"target location must be different from animated unit's location");
291 return luaL_argerror(L, 5,
"target location must be adjacent to the animated unit");
296 if(!lua_isnoneornil(L, -1)) {
302 lua_getfield(L, 5,
"value");
303 if(lua_isnumber(L, -1)) {
304 v1 = lua_tointeger(L, -1);
305 }
else if(lua_istable(L, -1)) {
306 lua_rawgeti(L, -1, 1);
307 v1 = lua_tointeger(L, -1);
309 lua_rawgeti(L, -1, 2);
310 v2 = lua_tointeger(L, -1);
312 }
else if(!lua_isnoneornil(L, -1)) {
313 return luaW_type_error(L, 5,
"value",
"number or array of two numbers");
317 lua_getfield(L, 5,
"with_bars");
318 if(lua_isboolean(L, -1)) {
320 }
else if(!lua_isnoneornil(L, -1)) {
321 return luaW_type_error(L, 5,
"with_bars", lua_typename(L, LUA_TBOOLEAN));
325 lua_getfield(L, 5,
"text");
326 if(lua_isstring(L, -1)) {
327 text = lua_tostring(L, -1);
330 }
else if(!lua_isnoneornil(L, -1)) {
335 lua_getfield(L, 5,
"color");
336 if(lua_istable(L, -1) && lua_rawlen(L, -1) == 3) {
337 int idx = lua_absindex(L, -1);
338 lua_rawgeti(L, idx, 1);
339 lua_rawgeti(L, idx, 2);
340 lua_rawgeti(L, idx, 3);
341 color =
color_t(lua_tointeger(L, -3), lua_tointeger(L, -2), lua_tointeger(L, -1));
343 }
else if(!lua_isnoneornil(L, -1)) {
348 lua_getfield(L, 5,
"primary");
350 if(!primary && !lua_isnoneornil(L, -1)) {
355 lua_getfield(L, 5,
"secondary");
357 if(!secondary && !lua_isnoneornil(L, -1)) {
361 }
else if(!lua_isnoneornil(L, 5)) {
365 anim.
add_animation(up, which, u.
get_location(), dest, v1, bars, text, color, hits, primary, secondary, v2);
393 const char* m = lua_tostring(L, 2);
401 luaL_Reg metafuncs[] {
405 {
"run", &dispatch<&game_lua_kernel::impl_run_animation>},
409 luaL_setfuncs(L, metafuncs, 0);
410 lua_pushstring(L,
"__metatable");
413 lua_setmetatable(L, -2);
436 if(lua_isstring(L, 1) && !lua_isnumber(L, 1)) {
437 std::string
id = luaL_checkstring(L, 1);
447 return luaL_argerror(L, 1,
"expected string or location");
451 if (!ui.
valid())
return 0;
472 if (!ui.
valid())
return 0;
490 std::vector<const unit*>
units;
494 return luaL_argerror(L, 2,
"unit not found");
497 }
else if(!lua_isnoneornil(L, 2)) {
501 return luaL_argerror(L, 2,
"invalid location");
516 lua_rawseti(L, 1,
i);
536 lua_pushboolean(L,
true);
542 WRN_LUA <<
"wesnoth.units.matches called with a secondary unit (3rd argument), ";
543 WRN_LUA <<
"but unit to match was on recall list. ";
544 WRN_LUA <<
"Thus the 3rd argument is ignored.";
551 return luaL_argerror(L, 3,
"unit not found");
553 lua_pushboolean(L,
unit_filter(filter).matches(*u, *u_adj));
559 lua_pushboolean(L,
unit_filter(filter).matches(*u, loc));
564 lua_pushboolean(L,
unit_filter(filter).matches(*u, loc));
589 if (!filter.
null()) {
591 t.save_id_or_number(),
t.recall_list().find_index(u->id()));
596 lua_rawseti(L, 1,
i);
615 char const *m = luaL_checkstring(L, 1);
632 if(
data.has_child(
"primary_attack")) {
633 data.add_child(
"first",
data.mandatory_child(
"primary_attack"));
634 data.remove_children(
"primary_attack");
636 if(
data.has_child(
"secondary_attack")) {
637 data.add_child(
"second",
data.mandatory_child(
"secondary_attack"));
638 data.remove_children(
"secondary_attack");
649 lua_pushboolean(L,
b);
667 char const *m = luaL_checkstring(L, 1);
672 lua_pushboolean(L,
b);
684 char const *m = luaL_checkstring(L, 1);
696 const std::string m = luaL_checkstring(L, 1);
697 if(m.empty())
return luaL_argerror(L, 1,
"empty variable name");
698 if (lua_isnoneornil(L, 2)) {
711 cfg[
"side"] =
teams().size() + 1;
726 std::string ids(luaL_checkstring(L, 1));
729 WRN_LUA <<
"[clear_menu_item] has been given an empty id=, ignoring";
746 if(lua_istable(L, 2)) {
758 return luaL_argerror(L, 2,
"expected list of locations");
777 if(lua_istable(L, 2)) {
805 if(!
map().on_board(loc))
return luaL_argerror(L, 1,
"not on board");
819 unsigned side_1, side_2;
823 side_1 = luaL_checkinteger(L, 1);
828 side_2 = luaL_checkinteger(L, 2);
831 lua_pushboolean(L,
board().get_team(side_1).is_enemy(side_2));
865 lua_pushstring(L, tod.
id.c_str());
866 lua_setfield(L, -2,
"id");
868 lua_setfield(L, -2,
"lawful_bonus");
870 lua_setfield(L, -2,
"bonus_modified");
871 lua_pushstring(L, tod.
image.c_str());
872 lua_setfield(L, -2,
"image");
874 lua_setfield(L, -2,
"name");
875 lua_pushstring(L, tod.
sounds.c_str());
876 lua_setfield(L, -2,
"sound");
878 lua_setfield(L, -2,
"mask");
880 lua_pushinteger(L, tod.
color.
r);
881 lua_setfield(L, -2,
"red");
882 lua_pushinteger(L, tod.
color.
g);
883 lua_setfield(L, -2,
"green");
884 lua_pushinteger(L, tod.
color.
b);
885 lua_setfield(L, -2,
"blue");
892 lua_newuserdatauv(L, 0, 1);
893 lua_pushinteger(L, area_index);
894 lua_setiuservalue(L, -2, 1);
895 if(luaL_newmetatable(L,
"schedule")) {
896 static luaL_Reg
const schedule_meta[] {
897 {
"__index", &dispatch<&game_lua_kernel::impl_schedule_get>},
898 {
"__newindex", &dispatch<&game_lua_kernel::impl_schedule_set>},
899 {
"__len", &dispatch<&game_lua_kernel::impl_schedule_len>},
902 luaL_setfuncs(L, schedule_meta, 0);
904 lua_setmetatable(L, -2);
909 int save_top = lua_gettop(L);
910 luaL_checkudata(L, idx,
"schedule");
911 lua_getiuservalue(L, idx, 1);
912 int i = luaL_checkinteger(L, -1);
913 lua_settop(L, save_top);
920 if(lua_isnumber(L, 2)) {
922 int i = lua_tointeger(L, 2) - 1;
923 if(i < 0 || i >=
static_cast<int>(times.size())) {
924 return luaL_argerror(L, 2,
"invalid time of day index");
929 const char* m = luaL_checkstring(L, 2);
930 if(area_index >= 0) {
933 if(strcmp(m,
"hexes") == 0) {
954 lua_pushinteger(L, times.size());
961 if(lua_isnumber(L, 2)) {
963 int i = lua_tointeger(L, 2) - 1;
964 if(i < 0 || i >=
static_cast<int>(times.size())) {
965 return luaL_argerror(L, 2,
"invalid time of day index");
975 const char* m = luaL_checkstring(L, 2);
976 if(strcmp(m,
"time_of_day") == 0) {
977 std::string value = luaL_checkstring(L, 3);
979 auto iter = std::find_if(times.begin(), times.end(), [&value](
const time_of_day& tod) {
980 return tod.id == value;
982 if(iter == times.end()) {
983 std::ostringstream
err;
984 err <<
"invalid time of day ID for ";
986 err <<
"global schedule";
992 err <<
"anonymous empty time area";
994 err <<
"anonymous time area at (" << hexes.begin()->wml_x() <<
',' << hexes.begin()->wml_y() <<
")";
997 err <<
"time area with id=" <<
id;
1001 return lua_error(L);
1003 int n = std::distance(times.begin(), iter);
1004 if(area_index < 0) {
1010 if(area_index >= 0) {
1012 if(strcmp(m,
"hexes") == 0) {
1019 if(lua_isnil(L, 3) && strcmp(m,
"liminal_bonus") == 0) {
1036 char const *m = luaL_checkstring(L, 2);
1042 lua_pushstring(L,
info.id().c_str());
1043 lua_setfield(L, -2,
"id");
1045 lua_setfield(L, -2,
"name");
1047 lua_setfield(L, -2,
"editor_name");
1049 lua_setfield(L, -2,
"description");
1051 lua_setfield(L, -2,
"icon");
1053 lua_setfield(L, -2,
"editor_image");
1054 lua_pushinteger(L,
info.light_bonus(0));
1055 lua_setfield(L, -2,
"light");
1056 lua_pushboolean(L,
info.is_village());
1057 lua_setfield(L, -2,
"village");
1058 lua_pushboolean(L,
info.is_castle());
1059 lua_setfield(L, -2,
"castle");
1060 lua_pushboolean(L,
info.is_keep());
1061 lua_setfield(L, -2,
"keep");
1062 lua_pushinteger(L,
info.gives_healing());
1063 lua_setfield(L, -2,
"healing");
1074 template<
bool cons
ider_illuminates>
1081 if(!
board().
map().on_board_with_border(loc)) {
1082 return luaL_argerror(L, 1,
"coordinates are not on board");
1084 }
else if(lua_isstring(L, 1)) {
1087 return luaL_error(L,
"invalid or empty time_area ID");
1090 loc = *area.begin();
1091 }
else if(!lua_isnil(L, 1)) {
1094 return luaL_error(L,
"empty time_area");
1097 loc = *area.begin();
1100 if(lua_isnumber(L, 2)) {
1101 for_turn = luaL_checkinteger(L, 2);
1103 if(for_turn < 1 || (number_of_turns != -1 && for_turn > number_of_turns)) {
1104 return luaL_argerror(L, 2,
"turn number out of range");
1125 if (!
board().
map().is_village(loc))
1129 if (!side)
return 0;
1130 lua_pushinteger(L, side);
1142 if(!
board().
map().is_village(loc)) {
1147 const int new_side_num = lua_isnoneornil(L, 2) ? 0 : luaL_checkinteger(L, 2);
1149 team* old_side =
nullptr;
1150 team* new_side =
nullptr;
1152 if(old_side_num == new_side_num) {
1158 }
catch(
const std::out_of_range&) {
1165 }
catch(
const std::out_of_range&) {
1171 if(new_side &&
board().team_is_defeated(*new_side)) {
1204 if (!
board().
map().on_board(loc))
return 0;
1205 lua_pushinteger(L, loc.
wml_x());
1206 lua_pushinteger(L, loc.
wml_y());
1222 if (!
board().
map().on_board(loc))
return 0;
1223 lua_pushinteger(L, loc.
wml_x());
1224 lua_pushinteger(L, loc.
wml_y());
1237 std::string m = luaL_checkstring(L, 1);
1243 return luaL_argerror(L, 1, (
"Cannot find resource with id '" + m +
"'").c_str());
1255 std::string m = luaL_checkstring(L, 1);
1261 return luaL_argerror(L, 1, (
"Cannot find era with id '" + m +
"'").c_str());
1274 LOG_LUA <<
"impl_game_config_get";
1275 char const *m = luaL_checkstring(L, 2);
1290 if(strcmp(m,
"global_traits") == 0) {
1293 const std::string&
id = trait[
"id"];
1297 lua_pushstring(L,
id.c_str());
1326 LOG_LUA <<
"impl_game_config_set";
1327 char const *m = luaL_checkstring(L, 2);
1351 static config find_addon(
const std::string&
type,
const std::string&
id)
1360 const char* m = luaL_checkstring(L, 2);
1378 struct end_level_committer {
1380 ~end_level_committer() {
1381 pc_.set_end_level_data(data_);
1392 const char* m = luaL_checkstring(L, 2);
1408 data->~end_level_data();
1414 void*
p = lua_touserdata(L, lua_upvalueindex(1));
1416 if(lua_type(L, 2) == LUA_TNUMBER) {
1419 size_t i = luaL_checkinteger(L, 2);
1421 lua_createtable(L, 2, 0);
1422 lua_pushstring(L,
"options");
1430 auto iter =
settings.addons.begin();
1431 std::advance(iter,
i);
1433 iter->second.write(cfg);
1434 cfg[
"id"] = iter->first;
1436 lua_createtable(L, 2, 0);
1437 lua_pushstring(L,
"addon");
1445 char const *m = luaL_checkstring(L, 2);
1473 if(strcmp(m,
"savegame") == 0) {
1475 if(
savegame == saved_game_mode::type::no) {
1476 lua_pushboolean(L,
false);
1482 if(strcmp(m,
"side_players") == 0) {
1486 if(strcmp(m,
"addons") == 0) {
1487 for(
const auto& [
id, addon] :
settings.addons) {
1488 lua_createtable(L, 0, 4);
1490 lua_setfield(L, -2,
"id");
1492 lua_setfield(L, -2,
"name");
1493 lua_pushboolean(L, addon.required);
1494 lua_setfield(L, -2,
"required");
1495 if(addon.min_version) {
1497 lua_push(L, addon.min_version->str());
1499 lua_setfield(L, -2,
"min_version");
1505 lua_setfield(L, -2,
"version");
1507 lua_createtable(L, addon.content.size(), 0);
1508 for(
const auto& content : addon.content) {
1509 lua_createtable(L, 0, 3);
1511 lua_setfield(L, -2,
"id");
1513 lua_setfield(L, -2,
"name");
1515 lua_setfield(L, -2,
"type");
1516 lua_seti(L, -2, lua_rawlen(L, -2) + 1);
1518 lua_setfield(L, -2,
"content");
1534 void*
p = lua_touserdata(L, lua_upvalueindex(1));
1536 lua_pushinteger(L,
settings.addons.size() + 1);
1548 LOG_LUA <<
"impl_scenario_get";
1549 char const *m = luaL_checkstring(L, 2);
1558 if(strcmp(m,
"resources") == 0) {
1561 resources.push_back(find_addon(
"resource", rsrc));
1576 if(strcmp(m,
"modifications") == 0) {
1577 std::vector<config> mods;
1579 mods.push_back(find_addon(
"modification", mod));
1584 if(strcmp(m,
"end_level_data") == 0) {
1590 if(luaL_newmetatable(L,
"end level data")) {
1591 static luaL_Reg
const callbacks[] {
1593 {
"__newindex", &dispatch<&game_lua_kernel::impl_end_level_data_set>},
1595 {
nullptr,
nullptr }
1597 luaL_setfuncs(L, callbacks, 0);
1599 lua_setmetatable(L, -2);
1605 if(strcmp(m,
"mp_settings") == 0) {
1606 lua_newuserdatauv(L, 0, 0);
1607 if(luaL_newmetatable(L,
"mp settings")) {
1610 lua_setfield(L, -2,
"__index");
1613 lua_setfield(L, -2,
"__len");
1614 lua_pushstring(L,
"mp settings");
1615 lua_setfield(L, -2,
"__metatable");
1617 lua_setmetatable(L, -2);
1633 LOG_LUA <<
"impl_scenario_set";
1634 char const *m = luaL_checkstring(L, 2);
1646 if(strcmp(m,
"end_level_data") == 0) {
1650 data.proceed_to_next_level = cfg[
"proceed_to_next_level"].to_bool(
true);
1651 data.transient.carryover_report = cfg[
"carryover_report"].to_bool(
true);
1652 data.prescenario_save = cfg[
"save"].to_bool(
true);
1653 data.replay_save = cfg[
"replay_save"].to_bool(
true);
1654 data.transient.linger_mode = cfg[
"linger_mode"].to_bool(
true) && !
teams().empty();
1655 data.transient.reveal_map = cfg[
"reveal_map"].to_bool(
true);
1656 data.is_victory = cfg[
"result"] == level_result::victory;
1657 data.test_result = cfg[
"test_result"].str();
1678 return "local_choice";
1697 char const *m = luaL_checkstring(L, 2);
1705 if(strcmp(m,
"map") == 0) {
1708 if(strcmp(m,
"schedule") == 0) {
1713 if (strcmp(m,
"event_context") == 0)
1717 cfg[
"name"] = ev.
name;
1724 cfg.
add_child(
"second_weapon", *weapon);
1729 cfg[
"damage_inflicted"] = di;
1759 if (lua_isnone(L, 2)) {
1765 LOG_LUA <<
"Script says: \"" << m <<
"\"";
1774 double factor = luaL_checknumber(L, 1);
1801 if (!lua_isnoneornil(L, 1)) {
1802 int max = 2 *
teams().size();
1803 int npn = luaL_checkinteger(L, 1);
1804 if (npn <= 0 || npn > max) {
1805 return luaL_argerror(L, 1,
"side number out of range");
1822 lua_pushboolean(L,
b);
1840 const unit* u =
nullptr;
1841 int viewing_side = 0;
1843 if (lua_isuserdata(L, arg))
1847 viewing_side = u->
side();
1856 viewing_side = u->
side();
1864 return luaL_argerror(L, 1,
"invalid location");
1866 return luaL_argerror(L, arg,
"invalid location");
1870 bool ignore_units =
false, see_all =
false, ignore_teleport =
false;
1871 double stop_at = 10000;
1872 std::unique_ptr<pathfind::cost_calculator> calc;
1874 if (lua_istable(L, arg))
1876 ignore_units = luaW_table_get_def<bool>(L, arg,
"ignore_units",
false);
1877 see_all = luaW_table_get_def<bool>(L, arg,
"ignore_visibility",
false);
1878 ignore_teleport = luaW_table_get_def<bool>(L, arg,
"ignore_teleport",
false);
1880 stop_at = luaW_table_get_def<double>(L, arg,
"max_cost", stop_at);
1883 lua_pushstring(L,
"viewing_side");
1885 if (!lua_isnil(L, -1)) {
1886 int i = luaL_checkinteger(L, -1);
1887 if (
i >= 1 &&
i <=
static_cast<int>(
teams().
size())) viewing_side =
i;
1891 if(u) see_all =
true;
1892 deprecated_message(
"wesnoth.paths.find_path with viewing_side=0 (or an invalid side)",
DEP_LEVEL::FOR_REMOVAL, {1, 17, 0},
"To consider fogged and hidden units, use ignore_visibility=true instead.");
1897 lua_pushstring(L,
"calculate");
1899 if(lua_isfunction(L, -1)) {
1904 else if (lua_isfunction(L, arg))
1912 if(!ignore_teleport) {
1913 if(viewing_side == 0) {
1914 lua_warning(L,
"wesnoth.paths.find_path: ignore_teleport=false requires a valid viewing_side; continuing with ignore_teleport=true",
false);
1915 ignore_teleport =
true;
1923 return luaL_argerror(L, 1,
"unit not found OR custom cost function not provided");
1927 teams(),
map, ignore_units,
false, see_all));
1931 &teleport_locations);
1933 int nb = res.
steps.size();
1934 lua_createtable(L, nb, 0);
1935 for (
int i = 0;
i < nb; ++
i)
1938 lua_rawseti(L, -2,
i + 1);
1954 const unit* u =
nullptr;
1956 if (lua_isuserdata(L, arg))
1966 return luaL_argerror(L, 1,
"unit not found");
1971 int viewing_side = u->
side();
1972 bool ignore_units =
false, see_all =
false, ignore_teleport =
false;
1973 int additional_turns = 0;
1975 if (lua_istable(L, arg))
1977 ignore_units = luaW_table_get_def<bool>(L, arg,
"ignore_units",
false);
1978 see_all = luaW_table_get_def<bool>(L, arg,
"ignore_visibility",
false);
1979 ignore_teleport = luaW_table_get_def<bool>(L, arg,
"ignore_teleport",
false);
1980 additional_turns = luaW_table_get_def<int>(L, arg,
"max_cost", additional_turns);
1982 lua_pushstring(L,
"viewing_side");
1984 if (!lua_isnil(L, -1)) {
1985 int i = luaL_checkinteger(L, -1);
1986 if (
i >= 1 &&
i <=
static_cast<int>(
teams().
size())) viewing_side =
i;
1990 if(u) see_all =
true;
2000 viewing_team, additional_turns, see_all, ignore_units);
2003 lua_createtable(L, nb, 0);
2004 for (
int i = 0;
i < nb; ++
i)
2008 lua_pushinteger(L,
s.curr.wml_x());
2009 lua_rawseti(L, -2, 1);
2010 lua_pushinteger(L,
s.curr.wml_y());
2011 lua_rawseti(L, -2, 2);
2012 lua_pushinteger(L,
s.move_left);
2013 lua_rawseti(L, -2, 3);
2014 lua_rawseti(L, -2,
i + 1);
2029 const unit* u =
nullptr;
2031 if (lua_isuserdata(L, arg))
2041 return luaL_argerror(L, 1,
"unit not found");
2048 return luaL_error(L,
"wesnoth.find_vision_range: requires a valid unit");
2051 std::map<map_location, int> jamming_map;
2058 lua_pushinteger(L,
d.curr.wml_x());
2059 lua_rawseti(L, -2, 1);
2060 lua_pushinteger(L,
d.curr.wml_y());
2061 lua_rawseti(L, -2, 2);
2062 lua_pushinteger(L,
d.move_left);
2063 lua_rawseti(L, -2, 3);
2064 lua_rawseti(L, -2, lua_rawlen(L, -2) + 1);
2066 for(
const auto&
e : res.
edges) {
2068 lua_pushinteger(L,
e.wml_x());
2069 lua_rawseti(L, -2, 1);
2070 lua_pushinteger(L,
e.wml_y());
2071 lua_rawseti(L, -2, 2);
2072 lua_pushinteger(L, -1);
2073 lua_rawseti(L, -2, 3);
2074 lua_rawseti(L, -2, lua_rawlen(L, -2) + 1);
2079 template<
typename T>
2082 for (
int i = 1, i_end = lua_rawlen(L, arg);
i <= i_end; ++
i)
2085 lua_rawgeti(L, arg,
i);
2086 int entry = lua_gettop(L);
2087 if (!lua_istable(L, entry)) {
2095 lua_rawgeti(L, entry, 3);
2096 if (!lua_isnumber(L, -1)) {
2097 lua_getfield(L, entry,
"side");
2098 if (!lua_isnumber(L, -1)) {
2102 int side = lua_tointeger(L, -1);
2104 lua_rawgeti(L, entry, 4);
2105 if (!lua_isstring(L, -1)) {
2106 lua_getfield(L, entry,
"type");
2107 if (!lua_isstring(L, -1)) {
2111 std::string
unit_type = lua_tostring(L, -1);
2115 lua_settop(L, entry - 1);
2119 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");
2137 std::vector<const ::unit*> real_units;
2138 typedef std::vector<std::tuple<map_location, int, std::string>> unit_type_vector;
2144 real_units.push_back(
unit);
2146 else if (!filter.
null())
2148 for(const ::unit* match :
unit_filter(filter).all_matches_on_map()) {
2149 if(match->get_location().valid()) {
2150 real_units.push_back(match);
2160 real_units.push_back(&(*ui));
2165 if (lua_istable(L, arg))
2173 return luaL_argerror(L, 1,
"unit(s) not found");
2176 int viewing_side = 0;
2177 bool ignore_units =
true, see_all =
true, ignore_teleport =
false,
debug =
false, use_max_moves =
false;
2179 if (lua_istable(L, arg))
2181 lua_pushstring(L,
"ignore_units");
2183 if (!lua_isnil(L, -1))
2189 lua_pushstring(L,
"ignore_teleport");
2191 if (!lua_isnil(L, -1))
2197 lua_pushstring(L,
"viewing_side");
2199 if (!lua_isnil(L, -1))
2201 int i = luaL_checkinteger(L, -1);
2202 if (
i >= 1 &&
i <=
static_cast<int>(
teams().
size()))
2209 lua_pushstring(L,
"debug");
2211 if (!lua_isnil(L, -1))
2217 lua_pushstring(L,
"use_max_moves");
2219 if (!lua_isnil(L, -1))
2236 const terrain_filter t_filter(filter, &fc,
false);
2241 const team& viewing_team = viewing_side
2246 ignore_units, !ignore_teleport, viewing_team, see_all, ignore_units);
2248 for (const ::unit*
const u : real_units)
2250 cost_map.
add_unit(*u, use_max_moves);
2252 for (
const unit_type_vector::value_type& fu :
fake_units)
2255 cost_map.
add_unit(std::get<0>(fu), ut, std::get<1>(fu));
2264 std::stringstream
s;
2280 lua_pushinteger(L, loc.wml_x());
2281 lua_rawseti(L, -2, 1);
2283 lua_pushinteger(L, loc.wml_y());
2284 lua_rawseti(L, -2, 2);
2286 lua_pushinteger(L, cost_map.
get_pair_at(loc).first);
2287 lua_rawseti(L, -2, 3);
2289 lua_pushinteger(L, cost_map.
get_pair_at(loc).second);
2290 lua_rawseti(L, -2, 4);
2292 lua_rawseti(L, -2, counter);
2302 return reinterpret_cast<int*
>(luaL_checkudata(L, idx,
labelKey));
2307 const char* m = luaL_checkstring(L, 2);
2315 int fade = luaL_optinteger(L, 2, -1);
2353 double width_ratio = 0;
2355 int lifetime = 2'000, fadeout = 100;
2361 if(lua_istable(L, 2)) {
2363 size = luaL_checkinteger(L, -1);
2367 width = lua_tointegerx(L, -1, &found_number);
2371 if(!value.empty() && value.back() ==
'%') {
2372 value.remove_suffix(1);
2373 width_ratio = std::stoi(std::string(value)) / 100.0;
2374 }
else throw std::invalid_argument(value.data());
2375 }
catch(std::invalid_argument&) {
2376 return luaL_argerror(L, -1,
"max_width should be integer or percentage");
2382 if(lua_isstring(L, -1)) {
2385 auto vec = lua_check<std::vector<int>>(L, -1);
2386 if(vec.size() != 3) {
2387 return luaL_error(L,
"floating label text color should be a hex string or an array of 3 integers");
2395 if(lua_isstring(L, -1)) {
2398 auto vec = lua_check<std::vector<int>>(L, -1);
2399 if(vec.size() != 3) {
2400 return luaL_error(L,
"floating label background color should be a hex string or an array of 3 integers");
2408 bgcolor.a = luaL_checkinteger(L, -1);
2413 lifetime = lua_tointegerx(L, -1, &found_number);
2416 if(value ==
"unlimited") {
2419 return luaL_argerror(L, -1,
"duration should be integer or 'unlimited'");
2424 fadeout = lua_tointeger(L, -1);
2430 static const char*
options[] = {
"left",
"center",
"right"};
2434 static const char*
options[] = {
"top",
"center",
"bottom"};
2447 int handle_idx = lua_gettop(L);
2454 if(width_ratio > 0) {
2455 width =
static_cast<int>(std::round(
rect.w * width_ratio));
2460 x =
rect.x + loc.wml_x();
2466 x =
rect.x +
rect.w / 2 + loc.wml_x();
2480 switch(vertical_alignment) {
2482 y =
rect.y + loc.wml_y();
2485 y =
rect.y +
rect.h / 2 + loc.wml_y();
2492 y =
rect.y +
rect.h - loc.wml_y() -
static_cast<int>(
size * 1.5);
2506 lua_settop(L, handle_idx);
2507 if(luaL_newmetatable(L,
labelKey)) {
2509 static const luaL_Reg methods[] = {
2510 {
"remove", &dispatch<&game_lua_kernel::intf_remove_floating_label>},
2511 {
"move", &dispatch<&game_lua_kernel::intf_move_floating_label>},
2512 {
"replace", &dispatch2<&game_lua_kernel::intf_set_floating_label, false>},
2514 {
nullptr,
nullptr }
2516 luaL_setfuncs(L, methods, 0);
2519 lua_setmetatable(L, handle_idx);
2520 lua_settop(L, handle_idx);
2545 return luaL_error(L,
"Attempted to move a unit while the map is locked");
2550 if (!
map().on_board(loc)) {
2551 return luaL_argerror(L, 2,
"invalid location");
2562 if (!
map().on_board(loc))
2563 return luaL_argerror(L, 1,
"invalid location");
2569 }
else if(!lua_isnoneornil(L, 1)) {
2570 const vconfig* vcfg =
nullptr;
2572 if (!
map().on_board(loc)) {
2575 if (!
map().on_board(loc))
2576 return luaL_argerror(L, 2,
"invalid location");
2582 u->set_location(loc);
2601 return luaL_error(L,
"Attempted to remove a unit while the map is locked");
2609 if (!
map().on_board(loc)) {
2610 return luaL_argerror(L, 1,
"invalid location");
2615 t.recall_list().erase_if_matches_id(u->
id());
2617 return luaL_argerror(L, 1,
"can't erase private units");
2620 if (!
map().on_board(loc)) {
2621 return luaL_argerror(L, 1,
"invalid location");
2624 return luaL_argerror(L, 1,
"expected unit or location");
2640 return luaL_error(L,
"Attempted to move a unit while the map is locked");
2644 int side = lua_tointeger(L, 2);
2645 if (
static_cast<unsigned>(side) >
teams().
size()) side = 0;
2649 u = lu->get_shared();
2650 if(lu->on_recall_list() && lu->on_recall_list() == side) {
2651 return luaL_argerror(L, 1,
"unit already on recall list");
2654 const vconfig* vcfg =
nullptr;
2666 std::size_t uid = u->underlying_id();
2667 t.recall_list().erase_by_underlying_id(uid);
2668 t.recall_list().add(u);
2673 u->anim_comp().clear_haloes();
2675 lu->lua_unit::~lua_unit();
2689 return luaL_error(L,
"Attempted to remove a unit while the map is locked");
2697 u->anim_comp().clear_haloes();
2698 }
else if (
int side = lu->on_recall_list()) {
2701 t.recall_list().erase_if_matches_id(u->id());
2707 lu->lua_unit::~lua_unit();
2723 if (!lua_isnoneornil(L, 2)) {
2727 const vconfig* vcfg =
nullptr;
2735 if (!res.
valid())
return 0;
2736 lua_pushinteger(L, res.
wml_x());
2737 lua_pushinteger(L, res.
wml_y());
2753 if (!lua_isnoneornil(L, 3)) {
2770 const vconfig* vcfg =
nullptr;
2800 char const *m = luaL_checkstring(L, 2);
2804 if(lua_isboolean(L, 3)) {
2806 if(!lua_isnoneornil(L, 4)) {
2809 }
else if(!lua_isnoneornil(L, 3)) {
2830 }
else if(lua_isstring(L, 2)) {
2831 char const *m = luaL_checkstring(L, 2);
2851 }
else if(lua_isstring(L, 2)) {
2852 char const *m = luaL_checkstring(L, 2);
2872 }
else if(lua_isstring(L, 2)) {
2873 char const *m = luaL_checkstring(L, 2);
2893 }
else if(lua_isstring(L, 2)) {
2894 char const *m = luaL_checkstring(L, 2);
2910 char const *m = luaL_checkstring(L, 2);
2924 char const *m = luaL_checkstring(L, 2);
2926 if (!utp)
return luaL_argerror(L, 2,
"unknown unit type");
2927 if(lua_isstring(L, 3)) {
2928 const std::string& m2 = lua_tostring(L, 3);
2929 if(!utp->
has_variation(m2))
return luaL_argerror(L, 2,
"unknown unit variation");
2943 lua_createtable(L, 0, 4);
2945 lua_setfield(L, -2,
"poisoned");
2946 lua_pushnumber(L, cmb.
slowed);
2947 lua_setfield(L, -2,
"slowed");
2949 lua_setfield(L, -2,
"untouched");
2951 lua_setfield(L, -2,
"average_hp");
2952 lua_createtable(L,
n, 0);
2953 for (
int i = 0;
i <
n; ++
i) {
2955 lua_rawseti(L, -2,
i);
2957 lua_setfield(L, -2,
"hp_chance");
2966 lua_createtable(L, 0, 16);
2969 lua_setfield(L, -2,
"num_blows");
2970 lua_pushnumber(L, bcustats.
damage);
2971 lua_setfield(L, -2,
"damage");
2973 lua_setfield(L, -2,
"chance_to_hit");
2974 lua_pushboolean(L, bcustats.
poisons);
2975 lua_setfield(L, -2,
"poisons");
2976 lua_pushboolean(L, bcustats.
slows);
2977 lua_setfield(L, -2,
"slows");
2979 lua_setfield(L, -2,
"petrifies");
2980 lua_pushboolean(L, bcustats.
plagues);
2981 lua_setfield(L, -2,
"plagues");
2983 lua_setfield(L, -2,
"plague_type");
2984 lua_pushnumber(L, bcustats.
rounds);
2985 lua_setfield(L, -2,
"rounds");
2987 lua_setfield(L, -2,
"firststrike");
2988 lua_pushboolean(L, bcustats.
drains);
2989 lua_setfield(L, -2,
"drains");
2991 lua_setfield(L, -2,
"drain_constant");
2993 lua_setfield(L, -2,
"drain_percent");
2998 lua_setfield(L, -2,
"attack_num");
3000 lua_setfield(L, -2,
"number");
3002 if(bcustats.
weapon !=
nullptr)
3004 lua_pushstring(L, bcustats.
weapon->id().c_str());
3005 lua_setfield(L, -2,
"name");
3007 lua_setfield(L, -2,
"weapon");
3026 int arg_num = 1, att_w = -1, def_w = -1;
3030 if (lua_isnumber(L, arg_num)) {
3031 att_w = lua_tointeger(L, arg_num) - 1;
3032 if (att_w < 0 || att_w >=
static_cast<int>(att->attacks().size()))
3033 return luaL_argerror(L, arg_num,
"weapon index out of bounds");
3039 if (lua_isnumber(L, arg_num)) {
3040 def_w = lua_tointeger(L, arg_num) - 1;
3041 if (def_w < 0 || def_w >=
static_cast<int>(def->attacks().size()))
3042 return luaL_argerror(L, arg_num,
"weapon index out of bounds");
3047 def->get_location(), att_w, def_w, 0.0,
nullptr, att, def);
3064 char const *m = luaL_checkstring(L, 1);
3065 int repeats = luaL_optinteger(L, 2, 0);
3077 const char* content_for = luaL_checkstring(L, 1);
3078 const char*
id = luaL_checkstring(L, 2);
3081 if(group.content_for_ == content_for) {
3083 if(achieve.
id_ ==
id) {
3108 ERR_LUA <<
"Achievement " <<
id <<
" not found for achievement group " << content_for;
3114 ERR_LUA <<
"Achievement group " << content_for <<
" not found";
3126 const char* content_for = luaL_checkstring(L, 1);
3127 const char*
id = luaL_checkstring(L, 2);
3130 ERR_LUA <<
"Returning false for whether a player has completed an achievement due to being networked multiplayer.";
3131 lua_pushboolean(L,
false);
3147 const char* content_for = luaL_checkstring(L, 1);
3148 const char*
id = luaL_checkstring(L, 2);
3152 if(group.content_for_ == content_for) {
3153 for(
const auto& achieve : group.achievements_) {
3154 if(achieve.id_ ==
id) {
3156 cfg[
"id"] = achieve.id_;
3157 cfg[
"name"] = achieve.name_;
3158 cfg[
"name_completed"] = achieve.name_completed_;
3159 cfg[
"description"] = achieve.description_;
3160 cfg[
"description_completed"] = achieve.description_completed_;
3161 cfg[
"icon"] = achieve.icon_;
3162 cfg[
"icon_completed"] = achieve.icon_completed_;
3163 cfg[
"hidden"] = achieve.hidden_;
3164 cfg[
"achieved"] = achieve.achieved_;
3165 cfg[
"max_progress"] = achieve.max_progress_;
3166 cfg[
"current_progress"] = achieve.current_progress_;
3168 for(
const auto& sub_ach : achieve.sub_achievements_) {
3170 sub[
"id"] = sub_ach.id_;
3171 sub[
"description"] = sub_ach.description_;
3172 sub[
"icon"] = sub_ach.icon_;
3173 sub[
"achieved"] = sub_ach.achieved_;
3181 ERR_LUA <<
"Achievement " <<
id <<
" not found for achievement group " << content_for;
3187 ERR_LUA <<
"Achievement group " << content_for <<
" not found";
3203 const char* content_for = luaL_checkstring(L, 1);
3204 const char*
id = luaL_checkstring(L, 2);
3205 int amount = luaL_checkinteger(L, 3);
3206 int limit = luaL_optinteger(L, 4, 999999999);
3209 if(group.content_for_ == content_for) {
3211 if(achieve.
id_ ==
id) {
3214 ERR_LUA <<
"Attempted to progress achievement " <<
id <<
" for achievement group " << content_for <<
", is not a progressible achievement.";
3215 lua_pushinteger(L, -1);
3216 lua_pushinteger(L, -1);
3228 lua_pushinteger(L, progress);
3230 lua_pushinteger(L, -1);
3238 lua_push(L,
"Achievement " + std::string(
id) +
" not found for achievement group " + content_for);
3239 return lua_error(L);
3244 lua_push(L,
"Achievement group " + std::string(content_for) +
" not found");
3245 return lua_error(L);
3257 const char* content_for = luaL_checkstring(L, 1);
3258 const char*
id = luaL_checkstring(L, 2);
3259 const char* sub_id = luaL_checkstring(L, 3);
3262 ERR_LUA <<
"Returning false for whether a player has completed an achievement due to being networked multiplayer.";
3263 lua_pushboolean(L,
false);
3279 const char* content_for = luaL_checkstring(L, 1);
3280 const char*
id = luaL_checkstring(L, 2);
3281 const char* sub_id = luaL_checkstring(L, 3);
3284 if(group.content_for_ == content_for) {
3286 if(achieve.
id_ ==
id) {
3293 if(sub_ach.
id_ == sub_id) {
3309 lua_push(L,
"Sub-achievement " + std::string(
id) +
" not found for achievement" +
id +
" in achievement group " + content_for);
3310 return lua_error(L);
3314 lua_push(L,
"Achievement " + std::string(
id) +
" not found for achievement group " + content_for);
3315 return lua_error(L);
3320 lua_push(L,
"Achievement group " + std::string(content_for) +
" not found");
3321 return lua_error(L);
3357 if(lua_isnoneornil(L, 1)) {
3362 if(!
map().on_board(loc))
return luaL_argerror(L, 1,
"not on board");
3363 bool highlight =
true;
3364 if(!lua_isnoneornil(L, 2))
3394 lua_pushboolean(L, skipping);
3405 if (!lua_isnone(L, 1)) {
3417 int user_choice_index;
3418 int random_choice_index;
3419 int ai_choice_index;
3421 lua_synchronize(lua_State *l,
const std::string& descr,
int user_index,
int random_index = 0,
int ai_index = 0)
3423 , user_choice_index(user_index)
3424 , random_choice_index(random_index)
3425 , ai_choice_index(ai_index != 0 ? ai_index : user_index)
3431 bool is_local_ai = lua_kernel_base::get_lua_kernel<game_lua_kernel>(L).board().get_team(side).is_local_ai();
3433 query_lua(side, is_local_ai ? ai_choice_index : user_choice_index, cfg);
3440 if(random_choice_index != 0 && lua_isfunction(L, random_choice_index)) {
3441 query_lua(side, random_choice_index, cfg);
3451 void query_lua(
int side,
int function_index,
config& cfg)
const
3453 lua_pushvalue(L, function_index);
3454 lua_pushnumber(L, side);
3457 static const char*
msg =
"function returned to wesnoth.sync.[multi_]evaluate a table which was partially invalid";
3458 lua_kernel_base::get_lua_kernel<game_lua_kernel>(L).log_error(
msg);
3459 lua_warning(L,
msg,
false);
3466 virtual bool is_visible()
const override {
return false; }
3480 std::string tagname =
"input";
3487 if(!lua_isfunction(L, nextarg) &&
luaW_totstring(L, nextarg, desc) ) {
3490 if(lua_isfunction(L, nextarg)) {
3491 human_func = nextarg++;
3494 return luaL_argerror(L, nextarg,
"expected a function");
3496 if(lua_isfunction(L, nextarg)) {
3497 ai_func = nextarg++;
3499 side_for = lua_tointeger(L, nextarg);
3515 std::string tagname =
"input";
3519 std::vector<int> sides_for;
3522 if(!lua_isfunction(L, nextarg) &&
luaW_totstring(L, nextarg, desc) ) {
3525 if(lua_isfunction(L, nextarg)) {
3526 human_func = nextarg++;
3529 return luaL_argerror(L, nextarg,
"expected a function");
3531 if(lua_isfunction(L, nextarg)) {
3532 null_func = nextarg++;
3534 sides_for = lua_check<std::vector<int>>(L, nextarg++);
3549 lua_pushvalue(L, 1);
3564 std::set<map_location> res;
3566 const terrain_filter t_filter(filter, &fc,
false);
3568 t_filter.get_locations(res, *
luaW_tounit(L, 2),
true);
3570 t_filter.get_locations(res,
true);
3589 if (filter.
null()) {
3590 lua_pushboolean(L,
true);
3595 const terrain_filter t_filter(filter, &fc,
false);
3597 lua_pushboolean(L, t_filter.match(loc, *
luaW_tounit(L, 3)));
3599 lua_pushboolean(L, t_filter.match(loc));
3616 if (filter.
null()) {
3617 lua_pushboolean(L,
true);
3625 lua_pushboolean(L, s_filter.
match(*
t));
3627 unsigned side = luaL_checkinteger(L, 1) - 1;
3629 lua_pushboolean(L, s_filter.
match(side + 1));
3640 team_i = luaL_checkinteger(L, 1);
3642 std::string
flag = luaL_optlstring(L, 2,
"",
nullptr);
3643 std::string color = luaL_optlstring(L, 3,
"",
nullptr);
3645 if(
flag.empty() && color.empty()) {
3648 if(team_i < 1 ||
static_cast<std::size_t
>(team_i) >
teams().
size()) {
3649 return luaL_error(L,
"set_side_id: side number %d out of range", team_i);
3653 if(!color.empty()) {
3668 side_num =
t->side();
3670 side_num = luaL_checkinteger(L, 1);
3672 std::string
path = luaL_checkstring(L, 2);
3677 if(strcmp(action,
"delete") == 0) {
3682 std::size_t len = std::string::npos, open_brak =
path.find_last_of(
'[');
3683 std::size_t dot =
path.find_last_of(
'.');
3684 if(open_brak != len) {
3685 len = open_brak - dot - 1;
3696 side_num =
t->side();
3698 side_num = luaL_checkinteger(L, 1);
3700 if(lua_isstring(L, 2)) {
3701 std::string file = luaL_checkstring(L, 2);
3703 std::string
err =
formatter() <<
"Could not load AI for side " << side_num <<
" from file " << file;
3704 lua_pushlstring(L,
err.c_str(),
err.length());
3705 return lua_error(L);
3717 side_num =
t->side();
3719 side_num = luaL_checkinteger(L, 1);
3723 cfg =
config {
"ai", cfg};
3725 bool added_dummy_stage =
false;
3727 added_dummy_stage =
true;
3731 if(added_dummy_stage) {
3733 if(iter->key ==
"stage" && iter->cfg[
"name"] ==
"empty") {
3734 iter = cfg.
erase(iter);
3744 unsigned i = luaL_checkinteger(L, 1);
3745 if(i < 1 || i >
teams().
size())
return 0;
3757 LOG_LUA <<
"intf_get_sides called: this = " << std::hex <<
this << std::dec <<
" myname = " <<
my_name();
3758 std::vector<int> sides;
3772 lua_createtable(L, sides.size(), 0);
3774 for(
int side : sides) {
3776 lua_rawseti(L, -2,
index);
3793 char const *m = luaL_checkstring(L, 2);
3795 if (sm ==
"advance") {
3799 if (sm !=
"advancement" && sm !=
"object" && sm !=
"trait") {
3800 return luaL_argerror(L, 2,
"unknown modification type");
3802 bool write_to_mods =
true;
3803 if (!lua_isnone(L, 4)) {
3807 write_to_mods =
false;
3825 std::vector<std::string> tags;
3826 if(lua_isstring(L, 3)) {
3827 tags.push_back(lua_check<std::string>(L, 3));
3828 }
else if (lua_istable(L, 3)){
3829 tags = lua_check<std::vector<std::string>>(L, 3);
3831 tags.push_back(
"object");
3837 for(
const std::string& tag : tags) {
3839 if(obj.matches(filter)) {
3840 obj[
"duration"] =
"now";
3860 if(lua_isboolean(L, 2)) {
3863 if(lua_isboolean(L, 3)) {
3877 char const *ty = luaL_checkstring(L, 1);
3880 std::stringstream ss;
3881 ss <<
"unknown unit type: '" << ty <<
"'";
3882 return luaL_argerror(L, 1, ss.str().c_str());
3899 std::string team_name;
3902 std::vector<std::string> team_names;
3903 std::transform(
teams.begin(),
teams.end(), std::back_inserter(team_names),
3904 [&](
int team) { return game_state_.get_disp_context().get_team(team).team_name(); });
3907 team_name = cfg[
"team_name"].str();
3912 team_name, cfg[
"name"], cfg[
"visible_in_fog"].to_bool(
true),
3913 cfg[
"submerge"].to_double(0), cfg[
"z_order"].to_double(0));
3926 char const *m = lua_tostring(L, 2);
3943 const int nargs = lua_gettop(L);
3944 if(nargs < 2 || nargs > 3) {
3945 return luaL_error(L,
"Wrong number of arguments to ai.log_replay() - should be 2 or 3 arguments.");
3947 const std::string key = nargs == 2 ? luaL_checkstring(L, 1) : luaL_checkstring(L, 2);
3953 }
else if(!lua_isstring(L, 3)) {
3954 return luaL_argerror(L, 3,
"accepts only string or config");
3977 cfg.
add_child(
"filter_lua")[
"code"] =
"<function>";
3987 if(lua_isstring(L, idx)) {
3988 return lua_tostring(L, idx);
4028 using namespace std::literals;
4034 }
else if(is_menu_item) {
4036 return luaL_argerror(L, 1,
"non-empty id is required for a menu item");
4038 name =
"menu item " +
id;
4040 if(
id.empty() && name.empty()) {
4041 return luaL_argerror(L, 1,
"either a name or id is required");
4044 if(new_handler.valid()) {
4045 bool has_lua_filter =
false;
4049 int filterIdx = lua_gettop(L);
4052 if(lua_isfunction(L, filterIdx)) {
4053 int fcnIdx = lua_absindex(L, -1);
4054 new_handler->add_filter(std::make_unique<lua_event_filter>(*
this, fcnIdx,
luaW_table_get_def(L, 1,
"filter_args",
config())));
4055 has_lua_filter =
true;
4057 #define READ_ONE_FILTER(key, tag) \
4059 if(luaW_tableget(L, filterIdx, key)) { \
4060 if(lua_isstring(L, -1)) { \
4061 filters.add_child("insert_tag", config{ \
4063 "variable", luaL_checkstring(L, -1) \
4066 filters.add_child(tag, luaW_checkconfig(L, -1)); \
4076 #undef READ_ONE_FILTER
4078 filters[
"filter_formula"] = luaL_checkstring(L, -1);
4082 new_handler->read_filters(filters);
4088 if(has_lua_filter) {
4093 new_handler->register_wml_event(*
this);
4106 lua_pushvalue(L, lua_upvalueindex(1));
4123 template<
bool is_menu_item>
4129 double priority = luaL_optnumber(L, 3, 0.);
4131 return luaL_argerror(L, 1,
"must not be empty");
4135 name =
"menu item " + name;
4136 }
else if(lua_absindex(L, -1) > 2 && lua_isfunction(L, -1)) {
4139 lua_pushcclosure(L, &dispatch<&game_lua_kernel::cfun_undoable_event>, 2);
4142 if(new_handler.valid()) {
4159 bool delayed_variable_substitution = cfg[
"delayed_variable_substitution"].to_bool(
true);
4160 if(delayed_variable_substitution) {
4187 lua_pushinteger(L, color.r);
4188 lua_pushinteger(L, color.g);
4189 lua_pushinteger(L, color.b);
4198 auto vec = lua_check<std::vector<uint8_t>>(L, 1);
4199 if(vec.size() != 4) {
4202 color_t fade{vec[0], vec[1], vec[2], vec[3]};
4220 lua_Integer delay = luaL_checkinteger(L, 1);
4228 const unsigned final = SDL_GetTicks() + delay;
4232 }
while (
static_cast<int>(
final - SDL_GetTicks()) > 0);
4256 std::string team_name;
4259 if(lua_gettop(L) == 1 && lua_istable(L, 1)) {
4260 using namespace std::literals;
4263 team_name = luaL_optstring(L, 2,
"");
4277 switch(lua_type(L, 2)) {
4279 case LUA_TNONE:
case LUA_TNIL:
4284 if(
size_t n = luaL_checkinteger(L, 2);
n > 0 &&
n <=
teams().size()) {
4324 for (
const int side : filter.
get_teams()){
4346 int side = cfg[
"side"];
4356 lua_getfield(L, -1,
"ca_ptr");
4370 lua_getfield(L, -1,
"stg_ptr");
4379 lua_createtable(L, 0, 0);
4381 lua_pushstring(L,
"name");
4382 lua_pushstring(L,
c->get_name().c_str());
4385 lua_pushstring(L,
"engine");
4386 lua_pushstring(L,
c->get_engine().c_str());
4389 lua_pushstring(L,
"id");
4390 lua_pushstring(L,
c->get_id().c_str());
4393 if (ct ==
"candidate_action") {
4394 lua_pushstring(L,
"ca_ptr");
4395 lua_pushlightuserdata(L,
c);
4398 lua_pushstring(L,
"exec");
4403 if (ct ==
"stage") {
4404 lua_pushstring(L,
"stg_ptr");
4405 lua_pushlightuserdata(L,
c);
4408 lua_pushstring(L,
"exec");
4414 std::vector<std::string> c_types =
c->get_children_types();
4416 for (std::vector<std::string>::const_iterator
t = c_types.begin();
t != c_types.end(); ++
t)
4418 std::vector<ai::component*> children =
c->get_children(*
t);
4419 std::string
type = *
t;
4420 if (
type ==
"aspect" ||
type ==
"goal" ||
type ==
"engine")
4425 lua_pushstring(L,
type.c_str());
4426 lua_createtable(L, 0, 0);
4428 for (std::vector<ai::component*>::const_iterator
i = children.begin();
i != children.end(); ++
i)
4430 lua_pushstring(L, (*i)->get_name().c_str());
4461 side = luaL_checkinteger(L, 1);
4468 std::vector<ai::component*> engines =
c->get_children(
"engine");
4470 for (std::vector<ai::component*>::const_iterator
i = engines.begin();
i != engines.end(); ++
i)
4472 if ((*i)->get_name() ==
"lua")
4482 if (lua_engine ==
nullptr)
4495 LOG_LUA <<
"Created new dummy lua-engine for debug_ai().";
4505 lua_pushstring(L,
"components");
4531 if(lua_isboolean(L, 1)) {
4556 std::set<map_location> locs;
4559 if(lua_gettop(L) == 1) {
4562 id = cfg[
"id"].str();
4563 const terrain_filter filter(cfg, &
game_state_,
false);
4564 filter.get_locations(locs,
true);
4567 id = luaL_checkstring(L, 1);
4568 if(!lua_isnoneornil(L, 3))
4573 const terrain_filter filter(cfg, &
game_state_,
false);
4574 filter.get_locations(locs,
true);
4582 LOG_LUA <<
"Lua inserted time_area '" <<
id <<
"'";
4591 const char *
id = luaL_checkstring(L, 1);
4593 LOG_LUA <<
"Lua removed time_area '" <<
id <<
"'";
4603 if(area_index < 0) {
4610 std::string area_id = luaL_checkstring(L, 1);
4612 if(
auto iter = std::find(area_ids.begin(), area_ids.end(), area_id); iter == area_ids.end()) {
4626 if(luaL_testudata(L, 1,
"schedule")) {
4636 ERR_LUA <<
"attempted to to replace ToD schedule with empty schedule";
4642 LOG_LUA <<
"replaced ToD schedule";
4650 int x = luaL_checkinteger(L, 1);
4651 int y = luaL_checkinteger(L, 2);
4670 lua_report_generator(lua_State *L,
const std::string &
n)
4679 if (!
luaW_getglobal(L,
"wesnoth",
"interface",
"game_display", name))
4703 char const *m = luaL_checkstring(L, 2);
4705 lua_pushvalue(L, 2);
4706 lua_pushvalue(L, -2);
4717 char const *m = luaL_checkstring(L, 2);
4718 lua_pushvalue(L, 2);
4719 lua_pushvalue(L, 3);
4751 if (dst == u->get_location() || !
map().on_board(dst)) {
4755 if (!
map().on_board(vacant_dst)) {
4766 std::vector<map_location> teleport_path;
4767 teleport_path.push_back(src_loc);
4768 teleport_path.push_back(vacant_dst);
4775 u->anim_comp().set_standing();
4782 if (
map().is_village(vacant_dst)) {
4801 const std::string& logger = lua_isstring(L, 2) ? luaL_checkstring(L, 1) :
"";
4802 const std::string&
msg = lua_isstring(L, 2) ? luaL_checkstring(L, 2) : luaL_checkstring(L, 1);
4804 if(logger ==
"wml" || logger ==
"WML") {
4818 lua_pushboolean(L,
fog ?
t.fogged(loc) :
t.shrouded(loc));
4836 bool affect_normal_fog =
false;
4837 if(lua_isboolean(L, -1)) {
4840 std::set<int> sides;
4842 sides.insert(
t->side());
4843 }
else if(lua_isnumber(L, 1)) {
4844 sides.insert(lua_tointeger(L, 1));
4845 }
else if(lua_istable(L, 1) && lua_istable(L, 2)) {
4846 const auto& v = lua_check<std::vector<int>>(L, 1);
4847 sides.insert(v.begin(), v.end());
4850 sides.insert(
t.side()+1);
4855 for(
const int &side_num : sides) {
4856 if(side_num < 1 ||
static_cast<std::size_t
>(side_num) >
teams().
size()) {
4862 t.remove_fog_override(locs);
4863 if(affect_normal_fog) {
4866 }
else if(!affect_normal_fog) {
4868 t.add_fog_override(locs);
4886 const std::string name = luaL_checkstring(L, 1);
4891 if(!
luaW_getglobal(L,
"wesnoth",
"custom_synced_commands", name)) {
4892 return luaL_argerror(L, 1,
"Unknown synced command");
4895 cmd_tag[
"name"] = name;
4896 if(!lua_isnoneornil(L, 2)) {
4957 cmd_log_ <<
"Registering game-specific wesnoth lib functions...\n";
4960 static luaL_Reg
const callbacks[] {
4965 {
"cancel_action", &dispatch<&game_lua_kernel::intf_cancel_action > },
4966 {
"log_replay", &dispatch<&game_lua_kernel::intf_log_replay > },
4967 {
"log", &dispatch<&game_lua_kernel::intf_log > },
4968 {
"redraw", &dispatch<&game_lua_kernel::intf_redraw > },
4969 {
"simulate_combat", &dispatch<&game_lua_kernel::intf_simulate_combat > },
4970 {
nullptr,
nullptr }
4971 };lua_getglobal(L,
"wesnoth");
4972 if (!lua_istable(L,-1)) {
4975 luaL_setfuncs(L, callbacks, 0);
4977 lua_setglobal(L,
"wesnoth");
4979 lua_getglobal(L,
"gui");
4980 lua_pushcfunction(L, &dispatch<&game_lua_kernel::intf_gamestate_inspector>);
4981 lua_setfield(L, -2,
"show_inspector");
4987 static luaL_Reg
const test_callbacks[] {
4988 {
"fire_wml_menu_item", &dispatch<&game_lua_kernel::intf_fire_wml_menu_item> },
4989 {
nullptr,
nullptr }
4991 luaL_setfuncs(L, test_callbacks, 0);
4992 lua_setglobal(L,
"unit_test");
5018 cmd_log_ <<
"Adding terrain_types table...\n";
5019 lua_getglobal(L,
"wesnoth");
5020 lua_newuserdatauv(L, 0, 0);
5021 lua_createtable(L, 0, 2);
5022 lua_pushcfunction(L, &dispatch<&game_lua_kernel::impl_get_terrain_info>);
5023 lua_setfield(L, -2,
"__index");
5024 lua_pushstring(L,
"terrain types");
5025 lua_setfield(L, -2,
"__metatable");
5026 lua_setmetatable(L, -2);
5027 lua_setfield(L, -2,
"terrain_types");
5031 cmd_log_ <<
"Adding ai elements table...\n";
5036 cmd_log_ <<
"Adding wesnoth current table...\n";
5038 lua_getglobal(L,
"wesnoth");
5039 lua_newuserdatauv(L, 0, 0);
5040 lua_createtable(L, 0, 2);
5041 lua_pushcfunction(L, &dispatch<&game_lua_kernel::impl_current_get>);
5042 lua_setfield(L, -2,
"__index");
5043 lua_pushstring(L,
"current config");
5044 lua_setfield(L, -2,
"__metatable");
5045 lua_setmetatable(L, -2);
5046 lua_setfield(L, -2,
"current");
5050 lua_getglobal(L,
"wml");
5051 static luaL_Reg
const wml_callbacks[] {
5055 {
"get_variable", &dispatch<&game_lua_kernel::intf_get_variable>},
5056 {
"set_variable", &dispatch<&game_lua_kernel::intf_set_variable>},
5057 {
"get_all_vars", &dispatch<&game_lua_kernel::intf_get_all_vars>},
5058 {
nullptr,
nullptr }
5060 luaL_setfuncs(L, wml_callbacks, 0);
5065 static luaL_Reg
const map_callbacks[] {
5072 {
"get_owner", &dispatch<&game_lua_kernel::intf_get_village_owner>},
5073 {
"set_owner", &dispatch<&game_lua_kernel::intf_set_village_owner>},
5075 {
"add_label", &dispatch<&game_lua_kernel::intf_add_label>},
5076 {
"remove_label", &dispatch<&game_lua_kernel::intf_remove_label>},
5077 {
"get_label", &dispatch<&game_lua_kernel::intf_get_label>},
5079 {
"place_area", &dispatch<&game_lua_kernel::intf_add_time_area>},
5080 {
"remove_area", &dispatch<&game_lua_kernel::intf_remove_time_area>},
5081 {
"get_area", &dispatch<&game_lua_kernel::intf_get_time_area>},
5083 {
"find", &dispatch<&game_lua_kernel::intf_get_locations>},
5084 {
"matches", &dispatch<&game_lua_kernel::intf_match_location>},
5086 {
nullptr,
nullptr }
5088 luaL_setfuncs(L, map_callbacks, 0);
5092 cmd_log_ <<
"Adding units module...\n";
5093 static luaL_Reg
const unit_callbacks[] {
5096 {
"erase", &dispatch<&game_lua_kernel::intf_erase_unit>},
5097 {
"extract", &dispatch<&game_lua_kernel::intf_extract_unit>},
5098 {
"matches", &dispatch<&game_lua_kernel::intf_match_unit>},
5099 {
"select", &dispatch<&game_lua_kernel::intf_select_unit>},
5100 {
"to_map", &dispatch<&game_lua_kernel::intf_put_unit>},
5101 {
"to_recall", &dispatch<&game_lua_kernel::intf_put_recall_unit>},
5103 {
"teleport", &dispatch<&game_lua_kernel::intf_teleport>},
5105 {
"ability", &dispatch<&game_lua_kernel::intf_unit_ability>},
5116 {
"find_on_map", &dispatch<&game_lua_kernel::intf_get_units>},
5117 {
"find_on_recall", &dispatch<&game_lua_kernel::intf_get_recall_units>},
5118 {
"get", &dispatch<&game_lua_kernel::intf_get_unit>},
5119 {
"get_hovered", &dispatch<&game_lua_kernel::intf_get_displayed_unit>},
5120 {
"create_animator", &dispatch<&game_lua_kernel::intf_create_animator>},
5123 {
nullptr,
nullptr }
5125 lua_getglobal(L,
"wesnoth");
5127 luaL_setfuncs(L, unit_callbacks, 0);
5128 lua_setfield(L, -2,
"units");
5132 cmd_log_ <<
"Adding sides module...\n";
5133 static luaL_Reg
const side_callbacks[] {
5134 {
"is_enemy", &dispatch<&game_lua_kernel::intf_is_enemy> },
5135 {
"matches", &dispatch<&game_lua_kernel::intf_match_side> },
5136 {
"set_id", &dispatch<&game_lua_kernel::intf_set_side_id> },
5141 {
"find", &dispatch<&game_lua_kernel::intf_get_sides> },
5142 {
"get", &dispatch<&game_lua_kernel::intf_get_side> },
5143 {
"create", &dispatch<&game_lua_kernel::intf_create_side> },
5145 {
"place_shroud", &dispatch2<&game_lua_kernel::intf_toggle_shroud, true>},
5146 {
"remove_shroud", &dispatch2<&game_lua_kernel::intf_toggle_shroud, false>},
5147 {
"override_shroud", &dispatch<&game_lua_kernel::intf_override_shroud>},
5148 {
"is_shrouded", &dispatch2<&game_lua_kernel::intf_get_fog_or_shroud, false>},
5150 {
"place_fog", &dispatch2<&game_lua_kernel::intf_toggle_fog, false>},
5151 {
"remove_fog", &dispatch2<&game_lua_kernel::intf_toggle_fog, true>},
5152 {
"is_fogged", &dispatch2<&game_lua_kernel::intf_get_fog_or_shroud, true>},
5153 {
nullptr,
nullptr }
5155 std::vector<lua_cpp::Reg>
const cpp_side_callbacks {
5156 {
"add_ai_component", std::bind(
intf_modify_ai, std::placeholders::_1,
"add")},
5157 {
"delete_ai_component", std::bind(
intf_modify_ai, std::placeholders::_1,
"delete")},
5158 {
"change_ai_component", std::bind(
intf_modify_ai, std::placeholders::_1,
"change")},
5162 lua_getglobal(L,
"wesnoth");
5164 luaL_setfuncs(L, side_callbacks, 0);
5166 lua_setfield(L, -2,
"sides");
5170 cmd_log_ <<
"Adding interface module...\n";
5171 static luaL_Reg
const intf_callbacks[] {
5172 {
"add_hex_overlay", &dispatch<&game_lua_kernel::intf_add_tile_overlay>},
5173 {
"remove_hex_overlay", &dispatch<&game_lua_kernel::intf_remove_tile_overlay>},
5174 {
"get_color_adjust", &dispatch<&game_lua_kernel::intf_get_color_adjust>},
5175 {
"color_adjust", &dispatch<&game_lua_kernel::intf_color_adjust>},
5176 {
"screen_fade", &dispatch<&game_lua_kernel::intf_screen_fade>},
5177 {
"delay", &dispatch<&game_lua_kernel::intf_delay>},
5178 {
"deselect_hex", &dispatch<&game_lua_kernel::intf_deselect_hex>},
5179 {
"highlight_hex", &dispatch<&game_lua_kernel::intf_highlight_hex>},
5180 {
"float_label", &dispatch<&game_lua_kernel::intf_float_label>},
5181 {
"get_displayed_unit", &dispatch<&game_lua_kernel::intf_get_displayed_unit>},
5182 {
"get_hovered_hex", &dispatch<&game_lua_kernel::intf_get_mouseover_tile>},
5183 {
"get_selected_hex", &dispatch<&game_lua_kernel::intf_get_selected_tile>},
5184 {
"lock", &dispatch<&game_lua_kernel::intf_lock_view>},
5185 {
"is_locked", &dispatch<&game_lua_kernel::intf_view_locked>},
5186 {
"scroll", &dispatch<&game_lua_kernel::intf_scroll>},
5187 {
"scroll_to_hex", &dispatch<&game_lua_kernel::intf_scroll_to_tile>},
5188 {
"skip_messages", &dispatch<&game_lua_kernel::intf_skip_messages>},
5189 {
"is_skipping_messages", &dispatch<&game_lua_kernel::intf_is_skipping_messages>},
5190 {
"zoom", &dispatch<&game_lua_kernel::intf_zoom>},
5191 {
"clear_menu_item", &dispatch<&game_lua_kernel::intf_clear_menu_item>},
5192 {
"set_menu_item", &dispatch<&game_lua_kernel::intf_set_menu_item>},
5193 {
"allow_end_turn", &dispatch<&game_lua_kernel::intf_allow_end_turn>},
5194 {
"clear_chat_messages", &dispatch<&game_lua_kernel::intf_clear_messages>},
5195 {
"end_turn", &dispatch<&game_lua_kernel::intf_end_turn>},
5197 {
"add_chat_message", &dispatch<&game_lua_kernel::intf_message>},
5198 {
"add_overlay_text", &dispatch2<&game_lua_kernel::intf_set_floating_label, true>},
5200 {
nullptr,
nullptr }
5202 lua_getglobal(L,
"wesnoth");
5204 luaL_setfuncs(L, intf_callbacks, 0);
5205 lua_setfield(L, -2,
"interface");
5209 cmd_log_ <<
"Adding achievements module...\n";
5210 static luaL_Reg
const achievement_callbacks[] {
5211 {
"set", &dispatch<&game_lua_kernel::intf_set_achievement> },
5212 {
"has", &dispatch<&game_lua_kernel::intf_has_achievement> },
5213 {
"get", &dispatch<&game_lua_kernel::intf_get_achievement> },
5214 {
"progress", &dispatch<&game_lua_kernel::intf_progress_achievement> },
5215 {
"has_sub_achievement", &dispatch<&game_lua_kernel::intf_has_sub_achievement> },
5216 {
"set_sub_achievement", &dispatch<&game_lua_kernel::intf_set_sub_achievement> },
5217 {
nullptr,
nullptr }
5219 lua_getglobal(L,
"wesnoth");
5221 luaL_setfuncs(L, achievement_callbacks, 0);
5222 lua_setfield(L, -2,
"achievements");
5226 cmd_log_ <<
"Adding audio module...\n";
5227 static luaL_Reg
const audio_callbacks[] {
5228 {
"play", &dispatch<&game_lua_kernel::intf_play_sound > },
5229 {
nullptr,
nullptr }
5231 lua_getglobal(L,
"wesnoth");
5233 luaL_setfuncs(L, audio_callbacks, 0);
5234 lua_setfield(L, -2,
"audio");
5238 cmd_log_ <<
"Adding paths module...\n";
5239 static luaL_Reg
const path_callbacks[] {
5240 {
"find_cost_map", &dispatch<&game_lua_kernel::intf_find_cost_map > },
5241 {
"find_path", &dispatch<&game_lua_kernel::intf_find_path > },
5242 {
"find_reach", &dispatch<&game_lua_kernel::intf_find_reach > },
5243 {
"find_vacant_hex", &dispatch<&game_lua_kernel::intf_find_vacant_tile > },
5244 {
"find_vision_range", &dispatch<&game_lua_kernel::intf_find_vision_range > },
5245 {
nullptr,
nullptr }
5247 lua_getglobal(L,
"wesnoth");
5249 luaL_setfuncs(L, path_callbacks, 0);
5250 lua_setfield(L, -2,
"paths");
5254 cmd_log_ <<
"Adding sync module...\n";
5255 static luaL_Reg
const sync_callbacks[] {
5260 {
nullptr,
nullptr }
5262 lua_getglobal(L,
"wesnoth");
5264 luaL_setfuncs(L, sync_callbacks, 0);
5265 lua_setfield(L, -2,
"sync");
5269 cmd_log_ <<
"Adding schedule module...\n";
5270 static luaL_Reg
const schedule_callbacks[] {
5271 {
"get_time_of_day", &dispatch<&game_lua_kernel::intf_get_time_of_day<false>>},
5272 {
"get_illumination", &dispatch<&game_lua_kernel::intf_get_time_of_day<true>>},
5273 {
"replace", &dispatch<&game_lua_kernel::intf_replace_schedule>},
5274 {
nullptr,
nullptr }
5276 lua_getglobal(L,
"wesnoth");
5278 luaL_setfuncs(L, schedule_callbacks, 0);
5279 lua_createtable(L, 0, 2);
5280 lua_setmetatable(L, -2);
5281 lua_setfield(L, -2,
"schedule");
5288 cmd_log_ <<
"Adding wml_actions table...\n";
5290 lua_getglobal(L,
"wesnoth");
5292 lua_setfield(L, -2,
"wml_actions");
5296 cmd_log_ <<
"Adding wml_conditionals table...\n";
5298 lua_getglobal(L,
"wesnoth");
5300 lua_setfield(L, -2,
"wml_conditionals");
5307 cmd_log_ <<
"Adding effects table...\n";
5309 lua_getglobal(L,
"wesnoth");
5311 lua_setfield(L, -2,
"effects");
5315 cmd_log_ <<
"Adding custom_synced_commands table...\n";
5317 lua_getglobal(L,
"wesnoth");
5319 lua_setfield(L, -2,
"custom_synced_commands");
5323 cmd_log_ <<
"Adding game_events module...\n";
5324 static luaL_Reg
const event_callbacks[] {
5325 {
"add", &dispatch<&game_lua_kernel::intf_add_event> },
5326 {
"add_repeating", &dispatch<&game_lua_kernel::intf_add_event_simple<false>> },
5327 {
"add_menu", &dispatch<&game_lua_kernel::intf_add_event_simple<true>> },
5328 {
"add_wml", &dispatch<&game_lua_kernel::intf_add_event_wml> },
5329 {
"remove", &dispatch<&game_lua_kernel::intf_remove_event> },
5330 {
"fire", &dispatch2<&game_lua_kernel::intf_fire_event, false> },
5331 {
"fire_by_id", &dispatch2<&game_lua_kernel::intf_fire_event, true> },
5332 {
"add_undo_actions", &dispatch<&game_lua_kernel::intf_add_undo_actions> },
5333 {
"set_undoable", &dispatch<&game_lua_kernel::intf_allow_undo > },
5334 {
nullptr,
nullptr }
5336 lua_getglobal(L,
"wesnoth");
5338 luaL_setfuncs(L, event_callbacks, 0);
5339 lua_setfield(L, -2,
"game_events");
5343 cmd_log_ <<
"Adding game_display table...\n";
5347 lua_createtable(L, 0, 2);
5348 lua_pushcfunction(L, &dispatch<&game_lua_kernel::impl_theme_items_get>);
5349 lua_setfield(L, -2,
"__index");
5350 lua_pushcfunction(L, &dispatch<&game_lua_kernel::impl_theme_items_set>);
5351 lua_setfield(L, -2,
"__newindex");
5352 lua_setmetatable(L, -2);
5353 lua_setfield(L, -2,
"game_display");
5357 cmd_log_ <<
"Adding scenario table...\n";
5361 lua_createtable(L, 0, 2);
5362 lua_pushcfunction(L, &dispatch<&game_lua_kernel::impl_scenario_get>);
5363 lua_setfield(L, -2,
"__index");
5364 lua_pushcfunction(L, &dispatch<&game_lua_kernel::impl_scenario_set>);
5365 lua_setfield(L, -2,
"__newindex");
5366 lua_setmetatable(L, -2);
5367 lua_setfield(L, -2,
"scenario");
5378 lua_pushstring(L, effect.c_str());
5396 cmd_log_ <<
"Adding races table...\n";
5399 lua_getglobal(L,
"wesnoth");
5401 lua_setfield(L, -2,
"races");
5405 cmd_log_ <<
"Running preload scripts...\n";
5428 using namespace std::literals::string_view_literals;
5429 static const std::array handled_file_tags {
5442 "modify_unit_type"sv,
5448 "terrain_graphics"sv,
5456 return std::binary_search(handled_file_tags.begin(), handled_file_tags.end(),
s);
5475 lua_createtable(L, 2, 0);
5476 lua_pushstring(L, v.key.c_str());
5477 lua_rawseti(L, -2, 1);
5479 lua_rawseti(L, -2, 2);
5480 lua_rawseti(L, -2, k++);
5515 const std::string m =
"Tag is already used: [" +
i->key +
"]";
5536 lua_pushstring(L, ev.
name.c_str());
5545 if (!
luaW_getglobal(L,
"wesnoth",
"custom_synced_commands", name)) {
5561 std::string which_effect = lua_tostring(L, lua_upvalueindex(1));
5576 lua_pushstring(L, description.c_str());
5589 int str_i = lua_gettop(L);
5592 lua_pushstring(L,
"__call");
5593 lua_pushvalue(L, str_i);
5594 lua_pushboolean(L,
true);
5595 lua_pushcclosure(L, &dispatch<&game_lua_kernel::cfun_builtin_effect>, 2);
5597 lua_pushstring(L,
"__descr");
5598 lua_pushvalue(L, str_i);
5599 lua_pushboolean(L,
false);
5600 lua_pushcclosure(L, &dispatch<&game_lua_kernel::cfun_builtin_effect>, 2);
5602 lua_setmetatable(L, -2);
5612 (lua_touserdata(L, lua_upvalueindex(1)));
5626 lua_getglobal(L,
"wesnoth");
5627 lua_pushstring(L,
"wml_actions");
5629 lua_pushstring(L, cmd.c_str());
5630 lua_pushlightuserdata(L,
reinterpret_cast<void *
>(
h));
5631 lua_pushcclosure(L, &dispatch<&game_lua_kernel::cfun_wml_action>, 1);
5644 (lua_touserdata(L, lua_upvalueindex(1)));
5647 lua_pushboolean(L,
h(vcfg));
5658 lua_getglobal(L,
"wesnoth");
5659 lua_pushstring(L,
"wml_conditionals");
5661 lua_pushstring(L, cmd.c_str());
5662 lua_pushlightuserdata(L,
reinterpret_cast<void *
>(
h));
5704 ERR_WML <<
"unknown conditional wml: [" << cmd <<
"]";
5723 int argIdx = lua_gettop(L);
5725 return luaL_error(L,
"wesnoth.wml_actions.command is missing");
5727 lua_pushvalue(L, argIdx);
5736 int evtIdx = lua_gettop(L);
5741 return luaL_ref(L, evtIdx);
5748 int evtIdx = lua_gettop(L);
5752 std::ostringstream lua_name;
5753 lua_name <<
"event ";
5755 lua_name <<
"<anon>";
5760 lua_name <<
"[id=" <<
id <<
"]";
5763 ERR_LUA <<
"Failed to register WML event: " << lua_name.str();
5766 return luaL_ref(L, evtIdx);
5772 idx = lua_absindex(L, idx);
5774 int evtIdx = lua_gettop(L);
5778 lua_pushvalue(L, idx);
5779 return luaL_ref(L, evtIdx);
5786 luaL_unref(L, -1, ref);
5797 lua_geti(L, -1, ref);
5798 if(lua_isnil(L, -1))
return false;
5844 lua_pushvalue(L, -1);
5864 std::string message = std::string() +
"function " + name +
" not found";
5865 log_error(message.c_str(),
"Lua SUF Error");
5869 lua_insert(L, -nArgs - 1);
5881 int top = lua_gettop(L);
5892 if(lua_istable(L, -1)) {
5895 lua_pushvalue(L, -1);
5897 lua_pushvalue(L, top + 1);
5899 lua_pushvalue(L, top + 2);
5904 if(luaL_getmetafield(L, -1,
"__descr")) {
5906 if(lua_isstring(L, -1)) {
5908 descr = lua_tostring(L, -1);
5910 lua_pushvalue(L, -2);
5912 lua_pushvalue(L, top + 1);
5914 lua_pushvalue(L, top + 2);
5917 if(lua_isstring(L, -1) && !lua_isnumber(L, -1)) {
5918 descr = lua_tostring(L, -1);
5920 ERR_LUA <<
"Effect __descr metafunction should have returned a string, but instead returned ";
5921 if(lua_isnone(L, -1)) {
5924 ERR_LUA << lua_typename(L, lua_type(L, -1));
5929 }
else if(need_apply) {
5931 lua_pushvalue(L, top + 1);
5933 lua_pushvalue(L, top + 2);
5958 if (!
luaW_getglobal(L,
"wesnoth",
"game_events",
"on_mouse_move")) {
5971 if (!
luaW_getglobal(L,
"wesnoth",
"game_events",
"on_mouse_button")) {
5990 if (!
luaW_getglobal(L,
"wesnoth",
"game_events",
"on_mouse_action")) {
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.
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.
all_children_iterator erase(const all_children_iterator &i)
const_all_children_iterator ordered_begin() const
std::size_t attribute_count() const
Count the number of non-blank attributes.
config & mandatory_child(config_key_type key, int n=0)
Returns the nth child with the given key, or throws an error if there is none.
const_attr_itors attribute_range() const
const_all_children_iterator ordered_end() const
bool has_child(config_key_type key) const
Determine whether a config has a child or not.
child_itors child_range(config_key_type key)
config & child_or_add(config_key_type key)
Returns a reference to the first child with the given key.
std::size_t all_children_count() const
void append_children(const config &cfg)
Adds children from cfg.
void splice_children(config &src, const std::string &key)
Moves all the children with tag key from src to this.
optional_config_impl< config > optional_child(config_key_type key, int n=0)
Euivalent to mandatory_child, but returns an empty optional if the nth child was not found.
config & add_child(config_key_type key)
virtual void play_slice(bool is_delay_enabled=true)
void clear_chat_messages()
void add_chat_message(const std::time_t &time, const std::string &speaker, int side, const std::string &msg, events::chat_handler::MESSAGE_TYPE type, bool bell)
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,...
Sort-of-Singleton that many classes, both GUI and non-GUI, use to access the game data.
void remove_overlay(const map_location &loc)
remove_overlay will remove all overlays on a tile.
std::size_t viewing_team() const
The viewing team is the team currently viewing the game.
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.
bool scroll(int xmov, int ymov, bool force=false)
Scrolls the display by xmov,ymov pixels.
void set_theme(const std::string &new_theme)
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.
const map_location & selected_hex() const
void fade_to(const color_t &color, int duration)
Screen fade.
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.
void add_overlay(const map_location &loc, const std::string &image, const std::string &halo="", const std::string &team_name="", const std::string &item_id="", bool visible_under_fog=true, float submerge=0.0f, float z_order=0)
Functions to add and remove overlays from locations.
void select_hex(const map_location &hex, const bool browse, const bool highlight=true, const bool fire_event=true)
void set_lifetime(int lifetime, int fadeout=100)
void set_position(double xpos, double ypos)
void set_alignment(ALIGN align)
void set_color(const color_t &color)
void set_clip_rect(const SDL_Rect &r)
void set_bg_color(const color_t &bg_color)
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
std::string difficulty
The difficulty level the game is being played on.
std::vector< std::string > active_mods
bool end_credits
whether to show the standard credits at the end
unsigned int end_text_duration
for how long the end-of-campaign text is shown
std::string campaign
The id of the campaign being played.
bool is_multiplayer() const
std::string end_text
end-of-campaign text
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(config_key_type 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.
@ 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.
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_allow_end_turn(bool value, const t_string &reason="")
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)
Arg 1: text - string Arg 2: options table.
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: ...
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 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.
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.
void clear_wml_event(int ref)
Clear a WML event store in the Lua registry.
int intf_create_animator(lua_State *)
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_
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...
int impl_game_config_set(lua_State *L) override
Sets some game_config data (__newindex metamethod).
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.
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)
int impl_theme_item(lua_State *L, std::string name)
Executes its upvalue as a theme item generator.
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.
int impl_game_config_get(lua_State *L) override
Gets some game_config data (__index metamethod).
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.
bool do_healing_
True if healing should be done at the beginning of the next side turn.
const std::unique_ptr< game_events::manager > events_manager_
game_events::wmi_manager & get_wml_menu_items()
int w() const
Effective map width.
int h() const
Effective map height.
Encapsulates the map of the game.
const std::shared_ptr< terrain_type_data > & tdata() 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.
virtual int impl_game_config_get(lua_State *L)
virtual int impl_game_config_set(lua_State *L)
bool load_string(char const *prog, const std::string &name, error_handler)
void run_lua_tag(const config &cfg)
Runs a [lua] tag.
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()
void set_end_level_data(const end_level_data &data)
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_regular_game_end() const
const mp_game_settings & get_mp_settings()
const end_level_data & get_end_level_data() const
int current_side() const
Returns the number of the side whose turn it is.
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::string get_loaded_resources() const
t_string get_scenario_name() const
void add_log_data(const std::string &key, const std::string &var)
config generate_report(const std::string &name, const context &ct, bool only_static=false)
void register_generator(const std::string &name, generator *)
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 void add_undo_commands(const config &commands, const game_events::queued_event &ctx)
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 &)
To store label data Class implements logic for rendering.
void replace_schedule(const config &time_cfg)
Replace the time of day schedule.
int number_of_turns() const
const 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::vector< time_of_day > & times(const map_location &loc=map_location::null_location()) const
const std::string & get_area_id(int area_index) 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.
void set_current_time(int time)
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.
void replace_area_locations(int index, const std::set< map_location > &locs)
void reset_max_liminal_bonus()
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 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(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...
vconfig child(const std::string &key) const
Returns a child of *this whose key is key.
const config & get_config() const
config get_parsed_config() const
child_list get_children(const std::string &key) const
constexpr uint8_t ALPHA_OPAQUE
A component of the AI framework.
Composite AI with turn sequence which is a vector of stages.
Define conditionals for the game's events mechanism, a.k.a.
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)
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)
static int impl_animator_collect(lua_State *L)
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)
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 READ_ONE_FILTER(key, tag)
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.
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.
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.
static void luaW_pushsimdata(lua_State *L, const combatant &cmb)
Puts a table at the top of the stack with some combat result.
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 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 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...
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 is_handled_file_tag(const std::string &s)
These are the child tags of [scenario] (and the like) that are handled elsewhere (in the C++ code).
static int cfun_wml_condition(lua_State *L)
Executes its upvalue as a wml condition and returns the result.
static int * luaW_check_floating_label(lua_State *L, int idx)
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 defense_modifier(const t_translation::terrain_code &terrain) const
The unit's defense on a given terrain.
int resistance_against(const std::string &damage_name, bool attacker, const map_location &loc, const_attack_ptr weapon=nullptr, const_attack_ptr opp_weapon=nullptr) const
The unit's resistance against a given damage type.
void apply_builtin_effect(std::string type, const config &effect)
Apply a builtin effect to the unit.
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(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.
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)
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)
void luaW_push_namedtuple(lua_State *L, const std::vector< std::string > &names)
Push an empty "named tuple" onto the stack.
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_cfgref_attrib_deprecated(name, prefix, level, version, msg, accessor)
#define return_vector_string_attrib(name, accessor)
#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_int_attrib_deprecated(name, prefix, level, version, msg, accessor)
#define modify_bool_attrib(name, accessor)
#define modify_string_attrib_deprecated(name, prefix, level, version, msg, accessor)
#define return_vector_string_attrib_deprecated(name, prefix, level, version, msg, accessor)
#define modify_vector_string_attrib_deprecated(name, prefix, level, version, msg, accessor)
#define return_bool_attrib(name, accessor)
#define return_tstring_attrib(name, accessor)
#define modify_int_attrib(name, accessor)
#define return_cfg_attrib(name, accessor)
#define modify_tstring_attrib(name, accessor)
#define modify_string_attrib(name, accessor)
#define modify_vector_string_attrib(name, accessor)
#define return_int_attrib_deprecated(name, prefix, level, version, msg, accessor)
#define return_string_attrib_deprecated(name, prefix, level, version, msg, accessor)
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, attack_ptr weapon)
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.
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, int 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 show_gamestate_inspector(const vconfig &cfg, 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)
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,...
void set_achievement(const std::string &content_for, const std::string &id)
Marks the specified achievement as completed.
std::set< std::string > & encountered_units()
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.
int progress_achievement(const std::string &content_for, const std::string &id, int limit, int max_progress, int amount)
Increments the achievement's current progress by amount if it hasn't already been completed.
void set_theme(const std::string &theme)
bool achievement(const std::string &content_for, const std::string &id)
bool sub_achievement(const std::string &content_for, const std::string &id, const std::string &sub_id)
Unit and team statistics.
fake_unit_manager * fake_units
game_classification * classification
play_controller * controller
std::shared_ptr< wb::manager > whiteboard
Contains the general settings which have a default.
void play_sound(const std::string &files, channel_group group, unsigned int repeats)
terrain_code read_terrain_code(std::string_view str, const ter_layer filler)
Reads a single terrain from a string.
const terrain_code NONE_TERRAIN
void move_unit(const std::vector< map_location > &path, unit_ptr u, bool animate, map_location::DIRECTION dir, bool force_scroll)
Display a unit moving along a given path.
std::size_t index(const std::string &str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
@ STRIP_SPACES
REMOVE_EMPTY: remove empty elements.
std::string join_map(const T &v, const std::string &major=",", const std::string &minor=":")
std::string join(const T &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)
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.
std::decay_t< T > lua_check(lua_State *L, int n)
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
#define ON_SCOPE_EXIT(...)
Run some arbitrary code (a lambda) when the current scope exits The lambda body follows this header,...
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.
The basic class for representing 8-bit RGB or RGBA colour values.
static color_t from_rgb_string(const std::string &c)
Creates a new opaque color_t object from a string variable in "R,G,B" format.
static color_t from_hex_string(const std::string &c)
Creates a new color_t object from a string variable in hex 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)
Additional information on the game outcome which can be provided by WML.
Error used for any general game error, e.g.
const map_location & filter_loc() const
Represents a single filter condition on an event.
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.
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.
static std::string get_string(enum_type key)
Converts a enum to its string equivalent.
static constexpr std::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 implementing vision (through fog of war and shroud).