111 #include <boost/intrusive_ptr.hpp>
112 #include <boost/optional.hpp>
113 #include <boost/range/algorithm/copy.hpp>
114 #include <boost/range/adaptors.hpp>
115 #include <boost/tuple/tuple.hpp>
126 #include <SDL_timer.h>
127 #include <SDL_video.h>
138 #if defined(__GNUC__) && !defined(__clang__) // we shouldn't need this for clang, but for gcc and tdm-gcc we probably do
139 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6 ) // "GCC diagnostic ignored" is apparently not available at version 4.5.2
140 #pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
145 #define LOG_LUA LOG_STREAM(info, log_scripting_lua)
146 #define WRN_LUA LOG_STREAM(warn, log_scripting_lua)
147 #define ERR_LUA LOG_STREAM(err, log_scripting_lua)
168 game_lua_kernel::preload_scripts.clear();
170 game_lua_kernel::preload_scripts.push_back(cfg);
172 game_lua_kernel::preload_config = game_config.
child(
"game_config");
199 if(!sides.
empty()) {
WRN_LUA <<
"ignoring duplicate side filter information (inline side=)" << std::endl; }
205 return filter.get_teams();
212 lua_pushnumber(L, lua_kernel_base::get_lua_kernel<game_lua_kernel>(L).map().special_locations().
size());
218 const t_translation::tstarting_positions::left_map&
left = lua_kernel_base::get_lua_kernel<game_lua_kernel>(L).map().special_locations().left;
220 t_translation::tstarting_positions::left_const_iterator it;
226 if (it == left.end()) {
231 if (it == left.end()) {
253 const t_translation::tstarting_positions::left_map&
left = lua_kernel_base::get_lua_kernel<game_lua_kernel>(L).map().special_locations().left;
255 if (it == left.end()) {
270 lua_pushstring(L,
"special locations cannot be modified uwing wesnoth.special_locations");
297 struct queued_event_context
300 std::stack<qe const *> & stack_;
302 queued_event_context(qe
const *new_qe, std::stack<qe const*> & stack)
308 ~queued_event_context()
321 u->lua_unit::~lua_unit();
349 if (strcmp(m,
"valid") == 0)
367 if (strcmp(m,
"loc") == 0) {
394 if (strcmp(m,
"alignment") == 0) {
399 if (strcmp(m,
"upkeep") == 0) {
401 if(boost::get<unit::upkeep_full>(&upkeep) !=
nullptr){
404 else if(boost::get<unit::upkeep_loyal>(&upkeep) !=
nullptr){
408 lua_push(L, boost::get<int>(upkeep));
412 if (strcmp(m,
"advancements") == 0) {
416 if (strcmp(m,
"overlays") == 0) {
420 if (strcmp(m,
"traits") == 0) {
424 if (strcmp(m,
"abilities") == 0) {
428 if (strcmp(m,
"status") == 0) {
438 if (strcmp(m,
"variables") == 0) {
448 if (strcmp(m,
"attacks") == 0) {
470 return lua_kernel_base::get_lua_kernel<game_lua_kernel>(L).return_unit_method(L, m);
506 if (strcmp(m,
"alignment") == 0) {
512 if (strcmp(m,
"advancements") == 0) {
517 if (strcmp(m,
"upkeep") == 0) {
523 if(strcmp(m,
"loyal") == 0) {
526 else if(strcmp(m,
"full") == 0) {
531 std::string err_msg =
"unknown upkeep value of unit: ";
543 std::string err_msg =
"unknown modifiable property of unit: ";
621 const std::vector<attack_type>& attacks = u ? u->
attacks() : ut->
attacks();
625 if(
at.id() == attack_id) {
630 if (attack ==
nullptr) {
639 if (index >= attacks.size()) {
643 attack = &attacks[
index];
703 if(attack.id() == attack_id)
721 std::string err_msg =
"unknown property of attack: ";
750 if(attack.id() == attack_id)
768 if (strcmp(m,
"specials") == 0) { \
773 std::string err_msg =
"unknown modifyable property of attack: ";
795 if (strcmp(m,
"__cfg") == 0) {
868 if (!ui.
valid())
return 0;
893 if (!ui.
valid())
return 0;
924 for (
const unit * ui :
unit_filter(filter, &fc).all_matches_on_map()) {
961 WRN_LUA <<
"wesnoth.match_unit called with a secondary unit (3rd argument), ";
962 WRN_LUA <<
"but unit to match was on recall list. ";
963 WRN_LUA <<
"Thus the 3rd argument is ignored.\n";
1014 if (!filter.
null()) {
1016 t.save_id(),
t.recall_list().find_index(u->id()));
1149 if(m.empty())
return luaL_argerror(L, 1,
"empty variable name");
1166 double r_max = double (std::numeric_limits<uint32_t>::max());
1174 min = lua_check<int32_t>(L, 1);
1175 max = lua_check<int32_t>(L, 2);
1179 max = lua_check<int32_t>(L, 1);
1200 WRN_LUA <<
"[clear_menu_item] has been given an empty id=, ignoring" << std::endl;
1241 std::set<map_location> locs;
1245 for (
const int &side_num : sides)
1247 index = side_num - 1;
1355 bool replace_if_failed =
false;
1427 bool consider_illuminates =
false;
1433 if(for_turn < 1 || (number_of_turns != -1 && for_turn > number_of_turns)) {
1485 if (!
board().
map().is_village(loc))
1489 if (!side)
return 0;
1504 if (!
board().
map().is_village(loc))
1509 if (new_side == old_side || new_side < 0 || new_side > static_cast<int>(
teams().
size()) ||
board().team_is_defeated(
teams()[new_side - 1])) {
1514 teams()[old_side - 1].lose_village(loc);
1550 if (!
board().
map().on_board(loc))
return 0;
1568 if (!
board().
map().on_board(loc))
return 0;
1582 if(side < 1 || static_cast<int>(
teams().
size()) < side)
1585 if(!
board().
map().on_board(starting_pos))
return 0;
1617 LOG_LUA <<
"impl_game_config_get\n";
1638 if(classification.campaign_type==game_classification::CAMPAIGN_TYPE::MULTIPLAYER) {
1647 for(; its.first != its.second; ++its.first) {
1648 eras_list = eras_list +
"," + (*(its.first))[
"id"];
1663 LOG_LUA <<
"impl_game_config_set\n";
1676 std::string err_msg =
"unknown modifiable property of game_config: ";
1694 return "local_choice";
1720 if (strcmp(m,
"event_context") == 0)
1724 cfg[
"name"] = ev.
name;
1735 cfg[
"unit_x"] = ev.
loc1.
x + 1;
1736 cfg[
"unit_y"] = ev.
loc1.
y + 1;
1764 LOG_LUA <<
"Script says: \"" << m <<
"\"\n";
1820 data.
replay_save = cfg[
"replay_save"].to_bool(
true);
1823 data.
is_victory = cfg[
"result"] ==
"victory";
1861 const unit* u =
nullptr;
1888 int viewing_side = 0;
1889 bool ignore_units =
false, see_all =
false, ignore_teleport =
false;
1890 double stop_at = 10000;
1915 if (i >= 1 && i <=
int(
teams().
size())) viewing_side =
i;
1916 else see_all =
true;
1930 const team &viewing_team =
board().
teams()[(viewing_side ? viewing_side : u->
side()) - 1];
1931 if (!ignore_teleport) {
1933 *u, viewing_team, see_all, ignore_units);
1936 teams(), map, ignore_units,
false, see_all);
1940 &teleport_locations);
1943 int nb = res.
steps.size();
1945 for (
int i = 0;
i < nb; ++
i)
1968 const unit* u =
nullptr;
1985 int viewing_side = 0;
1986 bool ignore_units =
false, see_all =
false, ignore_teleport =
false;
1987 int additional_turns = 0;
2010 if (i >= 1 && i <=
int(
teams().
size())) viewing_side =
i;
2011 else see_all =
true;
2016 const team &viewing_team =
board().
teams()[(viewing_side ? viewing_side : u->
side()) - 1];
2018 viewing_team, additional_turns, see_all, ignore_units);
2022 for (
int i = 0;
i < nb; ++
i)
2042 template<
typename T>
2045 for (
int i = 1, i_end =
lua_rawlen(L, arg);
i <= i_end; ++
i)
2076 boost::tuple<map_location, int, std::string> tuple(src, side, unit_type);
2077 fake_units.push_back(tuple);
2083 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");
2101 std::vector<const unit*> real_units;
2102 typedef std::vector<boost::tuple<map_location, int, std::string> > unit_type_vector;
2108 real_units.push_back(u);
2110 else if (!filter.
null())
2121 real_units.push_back(&(*ui));
2132 if(real_units.empty() && fake_units.empty())
2137 int viewing_side = 0;
2138 bool ignore_units =
true, see_all =
true, ignore_teleport =
false,
debug =
false, use_max_moves =
false;
2190 std::set<map_location> location_set;
2202 const team &viewing_team =
board().
teams()[(viewing_side ? viewing_side : 1) - 1];
2204 ignore_units, !ignore_teleport, viewing_team, see_all, ignore_units);
2206 for (
const unit*
const u : real_units)
2208 cost_map.
add_unit(*u, use_max_moves);
2210 for (
const unit_type_vector::value_type& fu : fake_units)
2213 cost_map.
add_unit(fu.get<0>(), ut, fu.get<1>());
2222 std::stringstream
s;
2265 const vconfig & healers_filter = cfg.
child(
"filter_second");
2266 std::vector<unit*> healers;
2267 if (!healers_filter.
null()) {
2269 for (
unit& u : *units) {
2270 if ( ufilt(u) && u.has_ability_type(
"heals") ) {
2271 healers.push_back(&u);
2278 const bool restore_attacks = cfg[
"restore_attacks"].to_bool(
false);
2279 const bool restore_statuses = cfg[
"restore_statuses"].to_bool(
true);
2280 const bool animate = cfg[
"animate"].to_bool(
false);
2283 bool only_unit_at_loc1 = healed_filter.
null();
2284 bool heal_amount_to_set =
true;
2288 if (only_unit_at_loc1)
2291 if(!u.valid())
return 0;
2293 else if ( !ufilt(*u) )
continue;
2295 int heal_amount = u->max_hitpoints() - u->hitpoints();
2296 if(amount.
blank() || amount ==
"full") u->set_hitpoints(u->max_hitpoints());
2298 heal_amount = lexical_cast_default<int, config::attribute_value> (
amount, heal_amount);
2299 const int new_hitpoints = std::max(1, std::min(u->max_hitpoints(), u->hitpoints() + heal_amount));
2300 heal_amount = new_hitpoints - u->hitpoints();
2301 u->set_hitpoints(new_hitpoints);
2304 if(!moves.
blank()) {
2305 if(moves ==
"full") u->set_movement(u->total_movement());
2308 u->set_movement(std::min<int>(
2309 u->total_movement(),
2310 u->movement_left() + lexical_cast_default<int, config::attribute_value> (moves, 0)
2315 if(restore_attacks) u->set_attacks(u->max_attacks());
2317 if(restore_statuses)
2323 u->anim_comp().set_standing();
2326 if (heal_amount_to_set)
2328 heal_amount_to_set =
false;
2333 if(only_unit_at_loc1)
return 0;
2342 static int floating_label = 0;
2352 int lifetime = cfg[
"duration"].to_int(50);
2356 if(!cfg[
"color"].empty()) {
2359 color =
create_color(cfg[
"red"], cfg[
"green"], cfg[
"blue"]);
2388 return luaL_error(L,
"Attempted to move a unit while the map is locked");
2400 if (!
map().on_board(loc)) {
2404 if (!
map().on_board(loc)) {
2413 if (!u)
return luaL_argerror(L, unit_arg,
"unit not found");
2414 if (lu->
on_map() && (unit_arg == 1 || u->get_location() == loc)) {
2418 loc = u->get_location();
2419 if (!
map().on_board(loc))
2421 }
else if (unit_arg != 1) {
2422 WRN_LUA <<
"wesnoth.put_unit(x, y, unit) is deprecated. Use wesnoth.put_unit(unit, x, y) instead\n";
2428 if (unit_arg == 1 && !
map().on_board(loc)) {
2429 loc.
x = cfg[
"x"] - 1;
2430 loc.
y = cfg[
"y"] - 1;
2431 if (!
map().on_board(loc))
2433 }
else if (unit_arg != 1) {
2434 WRN_LUA <<
"wesnoth.put_unit(x, y, unit) is deprecated. Use wesnoth.put_unit(unit, x, y) instead\n";
2444 if (unit_arg == 3) {
2445 WRN_LUA <<
"wesnoth.put_unit(x, y) is deprecated. Use wesnoth.erase_unit(x, y) instead\n";
2454 lu->
get_shared()->anim_comp().set_standing();
2456 u->set_location(loc);
2472 return luaL_error(L,
"Attempted to remove a unit while the map is locked");
2483 loc = u->get_location();
2484 if (!
map().on_board(loc)) {
2495 if (!
map().on_board(loc)) {
2500 loc.
x = cfg[
"x"] - 1;
2501 loc.
y = cfg[
"y"] - 1;
2502 if (!
map().on_board(loc)) {
2521 return luaL_error(L,
"Attempted to move a unit while the map is locked");
2526 if (
unsigned(side) >
teams().
size()) side = 0;
2541 if (!side) side = u->side();
2544 size_t uid = u->underlying_id();
2550 lu->lua_unit::~lua_unit();
2564 return luaL_error(L,
"Attempted to remove a unit while the map is locked");
2575 u->anim_comp().clear_haloes();
2585 lu->lua_unit::~lua_unit();
2606 u.reset(
new unit(cfg,
false));
2612 if (!res.
valid())
return 0;
2800 for (
int i = 0;
i <
n; ++
i) {
2849 if(bcustats.
weapon !=
nullptr)
2870 int arg_num = 1, att_w = -1, def_w = -1;
2876 if (att_w < 0 || att_w >=
int(att.
attacks().size()))
2877 return luaL_argerror(L, arg_num,
"weapon index out of bounds");
2885 if (def_w < 0 || def_w >=
int(def.
attacks().size()))
2886 return luaL_argerror(L, arg_num,
"weapon index out of bounds");
2950 ERR_LUA <<
"wesnoth.select_hex is deprecated, use wesnoth.select_unit and/or wesnoth.highlight_hex" << std::endl;
2975 bool highlight =
true;
2980 loc,
false, highlight, fire_event);
2992 loc,
false,
false,
false);
3031 int user_choice_index;
3032 int random_choice_index;
3033 int ai_choice_index;
3035 lua_synchronize(
lua_State *
l,
const std::string& descr,
int user_index,
int random_index = 0,
int ai_index = 0)
3037 , user_choice_index(user_index)
3038 , random_choice_index(random_index)
3039 , ai_choice_index(ai_index != 0 ? ai_index : user_index)
3045 bool is_local_ai = lua_kernel_base::get_lua_kernel<game_lua_kernel>(L).
teams()[side - 1].is_local_ai();
3047 query_lua(side, is_local_ai ? ai_choice_index : user_choice_index, cfg);
3054 if(random_choice_index != 0 &&
lua_isfunction(L, random_choice_index)) {
3055 query_lua(side, random_choice_index, cfg);
3065 void query_lua(
int side,
int function_index,
config& cfg)
const
3067 assert(cfg.
empty());
3072 lua_kernel_base::get_lua_kernel<game_lua_kernel>(L).log_error(
"function returned to wesnoth.synchronize_choice a table which was partially invalid");
3079 virtual bool is_visible()
const {
return false; }
3104 human_func = nextarg++;
3110 ai_func = nextarg++;
3132 std::vector<int> sides_for;
3139 human_func = nextarg++;
3145 null_func = nextarg++;
3147 sides_for = lua_check<std::vector<int> >(L, nextarg++);
3176 std::set<map_location>
res;
3203 std::vector<map_location> locs =
map().
villages();
3210 for(std::vector<map_location>::const_iterator it = locs.begin(); it != locs.end(); ++it) {
3236 if (filter.
null()) {
3261 if (filter.
null()) {
3277 std::vector<int> sides = ssf.
get_teams();
3278 for (
const int &side_num : sides)
3289 bool invalidate_screen =
false;
3292 std::string user_team_name = cfg[
"user_team_name"];
3294 std::string defeat_condition = cfg[
"defeat_condition"];
3305 for(
const int &side_num : sides)
3307 team_index = side_num - 1;
3311 LOG_LUA <<
"modifying side: " << side_num <<
"\n";
3312 if(!team_name.empty()) {
3313 LOG_LUA <<
"change side's team to team_name '" << team_name <<
"'\n";
3316 }
else if(!user_team_name.empty()) {
3317 LOG_LUA <<
"change side's user_team_name to '" << user_team_name <<
"'\n";
3322 if (!recruit_str.empty()) {
3327 if (!income.
empty()) {
3332 if (!gold.
empty()) {
3336 if (!controller.empty()) {
3340 if (!defeat_condition.empty()) {
3345 if (!shroud.
empty()) {
3347 invalidate_screen =
true;
3350 if ( cfg[
"reset_maps"].to_bool(
false) ) {
3352 invalidate_screen =
true;
3355 if (!shroud_data.empty()) {
3357 invalidate_screen =
true;
3361 if (!hidden.
empty()) {
3368 invalidate_screen =
true;
3371 if ( cfg[
"reset_view"].to_bool(
false) ) {
3373 invalidate_screen =
true;
3377 if (!village_gold.
empty()) {
3381 if (!village_support.empty()) {
3385 if (!switch_ai.empty()) {
3389 if (ai.first != ai.second) {
3394 if(!color.
empty()) {
3396 invalidate_screen =
true;
3403 invalidate_screen =
true;
3413 if(!flag_icon.
empty()) {
3421 if ( !setc.
empty() ) {
3427 if ( !stl.
empty()) {
3449 LOG_LUA <<
"intf_get_sides called: this = " << (
formatter() << std::hex <<
this).str() <<
" myname = " <<
my_name() << std::endl;
3450 std::vector<int> sides;
3465 for(
int side : sides) {
3506 if (sm ==
"advance") {
3508 lg::wml_error() <<
"(Lua) Modifications of type \"advance\" are deprecated, use \"advancement\" instead\n";
3510 if (sm !=
"advancement" && sm !=
"object" && sm !=
"trait") {
3513 bool write_to_mods =
true;
3554 std::stringstream ss;
3555 ss <<
"unknown unit type: '" << ty <<
"'";
3574 cfg[
"team_name"], cfg[
"name"], cfg[
"visible_in_fog"].to_bool(
true));
3607 if (!cfg[
"delayed_variable_substitution"].to_bool(
true)) {
3648 const unsigned final = SDL_GetTicks() + delay;
3652 }
while (
int(
final - SDL_GetTicks()) > 0);
3658 class recursion_preventer {
3659 typedef std::map<map_location, int> t_counter;
3660 static t_counter counter_;
3661 static const int max_recursion = 10;
3664 bool too_many_recursions_;
3669 too_many_recursions_(false)
3673 too_many_recursions_ = inserted->second >= max_recursion;
3675 ~recursion_preventer()
3678 if (--itor->second == 0)
3680 counter_.erase(itor);
3683 bool too_many_recursions()
const
3685 return too_many_recursions_;
3688 recursion_preventer::t_counter recursion_preventer::counter_;
3689 typedef boost::scoped_ptr<recursion_preventer> recursion_preventer_ptr;
3698 size_t number_killed = 0;
3700 bool secondary_unit = cfg.
has_child(
"secondary_unit");
3702 if(cfg[
"fire_event"].to_bool() && secondary_unit)
3704 secondary_unit =
false;
3707 if ( ufilt( *
unit) )
3710 secondary_unit =
true;
3714 if(!secondary_unit) {
3715 WRN_LUA <<
"failed to match [secondary_unit] in [kill] with a single on-board unit" << std::endl;
3720 std::vector<unit *> dead_men_walking;
3724 dead_men_walking.push_back(&u);
3728 for(
unit * un : dead_men_walking) {
3732 if(!secondary_unit) {
3736 if (cfg[
"fire_event"].to_bool())
3740 recursion_preventer_ptr recursion_prevent;
3742 if (event_info.
loc1 == death_loc && (event_info.
name ==
"die" || event_info.
name ==
"last breath"))
3744 recursion_prevent.reset(
new recursion_preventer(death_loc));
3746 if(recursion_prevent->too_many_recursions())
3750 ERR_LUA <<
"tried to fire 'die' or 'last breath' event on primary_unit inside its own 'die' or 'last breath' event with 'first_time_only' set to false!" << std::endl;
3760 if (cfg[
"animate"].to_bool()) {
3791 if((cfg_x.
empty() || cfg_x ==
"recall")
3792 && (cfg_y.
empty() || cfg_y ==
"recall"))
3797 pi!=
teams().end(); ++pi)
3800 scoped_recall_unit auto_store(
"this_unit", pi->save_id(), j - pi->recall_list().begin());
3802 j = pi->recall_list().erase(j);
3825 screen.
labels().
set_label(label.location(), label.text(), label.creator(), label.team_name(), label.color(),
3826 label.visible_in_fog(), label.visible_in_shroud(), label.immutable(), label.category(), label.tooltip());
3848 for (
const int side : filter.
get_teams()){
3859 screen.
draw(
true,
true);
3899 int side = cfg[
"side"];
3946 if (ct ==
"candidate_action") {
3956 if (ct ==
"stage") {
3969 for (std::vector<std::string>::const_iterator
t = c_types.begin();
t != c_types.end(); ++
t)
3973 if (type ==
"aspect" || type ==
"goal" || type ==
"engine")
3981 for (std::vector<ai::component*>::const_iterator
i = children.begin();
i != children.end(); ++
i)
4016 std::vector<ai::component*> engines = c->
get_children(
"engine");
4018 for (std::vector<ai::component*>::const_iterator
i = engines.begin();
i != engines.end(); ++
i)
4020 if ((*i)->get_name() ==
"lua")
4030 if (lua_engine ==
nullptr)
4043 LOG_LUA <<
"Created new dummy lua-engine for debug_ai(). \n";
4087 std::set<map_location> locs;
4092 LOG_LUA <<
"Lua inserted time_area '" <<
id <<
"'\n";
4103 LOG_LUA <<
"Lua removed time_area '" <<
id <<
"'\n";
4114 ERR_LUA <<
"attempted to to replace ToD schedule with empty schedule" << std::endl;
4120 LOG_LUA <<
"replaced ToD schedule\n";
4135 area_i =
std::find(area_ids.begin(), area_ids.end(), area_id) - area_ids.begin();
4136 if(area_i >= area_ids.size()) {
4142 const std::vector<time_of_day>& times = area_id.empty()
4145 int num_times = times.size();
4150 if(time_id == time.id) {
4155 if(new_time >= num_times) {
4159 if(new_time < 0 || new_time >= num_times) {
4163 if(area_id.empty()) {
4177 bool side_match =
false;
4178 for (
int side : side_list) {
4179 if(
teams()[side-1].is_local_human()) {
4184 if ((cfg[
"side"].empty() && !cfg.
has_child(
"filter_side")) || side_match) {
4199 : mState(L), name(n) {}
4278 if (dst == u->get_location() || !
map().
on_board(dst)) {
4287 if ( clear_shroud ) {
4293 std::vector<map_location> teleport_path;
4294 teleport_path.push_back(src_loc);
4295 teleport_path.push_back(vacant_dst);
4302 u->anim_comp().set_standing();
4304 if ( clear_shroud ) {
4309 if (
map().is_village(vacant_dst)) {
4345 ERR_LUA <<
"Error when parsing sound_source config: invalid parameter." << std::endl;
4346 ERR_LUA <<
"sound_source config was: " << cfg.
debug() << std::endl;
4347 ERR_LUA <<
"Skipping this sound source..." << std::endl;
4385 if(logger ==
"wml" || logger ==
"WML") {
4408 bool affect_normal_fog =
false;
4412 std::set<int> sides;
4416 const auto&
v = lua_check<std::vector<int>>(L, 1);
4417 sides.insert(
v.begin(),
v.end());
4420 sides.insert(
t.side()+1);
4423 const auto& v_locs = lua_check<std::vector<map_location>>(L,
lua_istable(L, 2) ? 2 : 1);
4424 std::set<map_location> locs(v_locs.begin(), v_locs.end());
4426 for(
const int &side_num : sides) {
4427 if(side_num < 1 || static_cast<size_t>(side_num) >
teams().size()) {
4434 if(affect_normal_fog) {
4437 }
else if(!affect_normal_fog) {
4487 template <member_callback method>
4489 return ((lua_kernel_base::get_lua_kernel<game_lua_kernel>(L)).*method)(L);
4495 template <member_callback2 method,
bool b>
4497 return ((lua_kernel_base::get_lua_kernel<game_lua_kernel>(L)).*method)(L,
b);
4503 , game_display_(nullptr)
4505 , play_controller_(pc)
4506 , reports_(reports_object)
4516 cmd_log_ <<
"Registering game-specific wesnoth lib functions...\n";
4519 static luaL_Reg const callbacks[] = {
4543 {
"add_event_handler", &dispatch<&game_lua_kernel::intf_add_event > },
4544 {
"add_fog", &dispatch2<&game_lua_kernel::intf_toggle_fog, true > },
4545 {
"add_tile_overlay", &dispatch<&game_lua_kernel::intf_add_tile_overlay > },
4546 {
"add_time_area", &dispatch<&game_lua_kernel::intf_add_time_area > },
4547 {
"add_sound_source", &dispatch<&game_lua_kernel::intf_add_sound_source > },
4548 {
"allow_end_turn", &dispatch<&game_lua_kernel::intf_allow_end_turn > },
4549 {
"allow_undo", &dispatch<&game_lua_kernel::intf_allow_undo > },
4550 {
"animate_unit", &dispatch<&game_lua_kernel::intf_animate_unit > },
4551 {
"check_end_level_disabled", &dispatch<&game_lua_kernel::intf_check_end_level_disabled > },
4552 {
"clear_menu_item", &dispatch<&game_lua_kernel::intf_clear_menu_item > },
4553 {
"clear_messages", &dispatch<&game_lua_kernel::intf_clear_messages > },
4554 {
"color_adjust", &dispatch<&game_lua_kernel::intf_color_adjust > },
4555 {
"delay", &dispatch<&game_lua_kernel::intf_delay > },
4556 {
"end_turn", &dispatch<&game_lua_kernel::intf_end_turn > },
4557 {
"end_level", &dispatch<&game_lua_kernel::intf_end_level > },
4558 {
"erase_unit", &dispatch<&game_lua_kernel::intf_erase_unit > },
4559 {
"extract_unit", &dispatch<&game_lua_kernel::intf_extract_unit > },
4560 {
"find_cost_map", &dispatch<&game_lua_kernel::intf_find_cost_map > },
4561 {
"find_path", &dispatch<&game_lua_kernel::intf_find_path > },
4562 {
"find_reach", &dispatch<&game_lua_kernel::intf_find_reach > },
4563 {
"find_vacant_tile", &dispatch<&game_lua_kernel::intf_find_vacant_tile > },
4564 {
"fire_event", &dispatch<&game_lua_kernel::intf_fire_event > },
4565 {
"fire_wml_menu_item", &dispatch<&game_lua_kernel::intf_fire_wml_menu_item > },
4566 {
"float_label", &dispatch<&game_lua_kernel::intf_float_label > },
4567 {
"gamestate_inspector", &dispatch<&game_lua_kernel::intf_gamestate_inspector > },
4568 {
"get_all_vars", &dispatch<&game_lua_kernel::intf_get_all_vars > },
4569 {
"get_locations", &dispatch<&game_lua_kernel::intf_get_locations > },
4570 {
"get_map_size", &dispatch<&game_lua_kernel::intf_get_map_size > },
4571 {
"get_mouseover_tile", &dispatch<&game_lua_kernel::intf_get_mouseover_tile > },
4572 {
"get_recall_units", &dispatch<&game_lua_kernel::intf_get_recall_units > },
4573 {
"get_selected_tile", &dispatch<&game_lua_kernel::intf_get_selected_tile > },
4574 {
"get_sides", &dispatch<&game_lua_kernel::intf_get_sides > },
4575 {
"get_sound_source", &dispatch<&game_lua_kernel::intf_get_sound_source > },
4576 {
"get_starting_location", &dispatch<&game_lua_kernel::intf_get_starting_location > },
4577 {
"get_terrain", &dispatch<&game_lua_kernel::intf_get_terrain > },
4578 {
"get_terrain_info", &dispatch<&game_lua_kernel::intf_get_terrain_info > },
4579 {
"get_time_of_day", &dispatch<&game_lua_kernel::intf_get_time_of_day > },
4580 {
"get_unit", &dispatch<&game_lua_kernel::intf_get_unit > },
4581 {
"get_units", &dispatch<&game_lua_kernel::intf_get_units > },
4582 {
"get_variable", &dispatch<&game_lua_kernel::intf_get_variable > },
4583 {
"get_side_variable", &dispatch<&game_lua_kernel::intf_get_side_variable > },
4584 {
"get_villages", &dispatch<&game_lua_kernel::intf_get_villages > },
4585 {
"get_village_owner", &dispatch<&game_lua_kernel::intf_get_village_owner > },
4586 {
"get_displayed_unit", &dispatch<&game_lua_kernel::intf_get_displayed_unit > },
4587 {
"heal_unit", &dispatch<&game_lua_kernel::intf_heal_unit > },
4588 {
"highlight_hex", &dispatch<&game_lua_kernel::intf_highlight_hex > },
4589 {
"is_enemy", &dispatch<&game_lua_kernel::intf_is_enemy > },
4590 {
"kill", &dispatch<&game_lua_kernel::intf_kill > },
4591 {
"label", &dispatch<&game_lua_kernel::intf_label > },
4592 {
"lock_view", &dispatch<&game_lua_kernel::intf_lock_view > },
4593 {
"log", &dispatch<&game_lua_kernel::intf_log > },
4594 {
"match_location", &dispatch<&game_lua_kernel::intf_match_location > },
4595 {
"match_side", &dispatch<&game_lua_kernel::intf_match_side > },
4596 {
"match_unit", &dispatch<&game_lua_kernel::intf_match_unit > },
4597 {
"message", &dispatch<&game_lua_kernel::intf_message > },
4598 {
"modify_ai_wml", &dispatch<&game_lua_kernel::intf_modify_ai_wml > },
4599 {
"modify_side", &dispatch<&game_lua_kernel::intf_modify_side > },
4600 {
"open_help", &dispatch<&game_lua_kernel::intf_open_help > },
4601 {
"play_sound", &dispatch<&game_lua_kernel::intf_play_sound > },
4602 {
"print", &dispatch<&game_lua_kernel::intf_print > },
4603 {
"put_recall_unit", &dispatch<&game_lua_kernel::intf_put_recall_unit > },
4604 {
"put_unit", &dispatch<&game_lua_kernel::intf_put_unit > },
4605 {
"random", &dispatch<&game_lua_kernel::intf_random > },
4606 {
"redraw", &dispatch<&game_lua_kernel::intf_redraw > },
4607 {
"remove_event_handler", &dispatch<&game_lua_kernel::intf_remove_event > },
4608 {
"remove_fog", &dispatch2<&game_lua_kernel::intf_toggle_fog, false > },
4609 {
"remove_tile_overlay", &dispatch<&game_lua_kernel::intf_remove_tile_overlay > },
4610 {
"remove_time_area", &dispatch<&game_lua_kernel::intf_remove_time_area > },
4611 {
"remove_sound_source", &dispatch<&game_lua_kernel::intf_remove_sound_source > },
4612 {
"replace_schedule", &dispatch<&game_lua_kernel::intf_replace_schedule > },
4613 {
"scroll", &dispatch<&game_lua_kernel::intf_scroll > },
4614 {
"scroll_to_tile", &dispatch<&game_lua_kernel::intf_scroll_to_tile > },
4615 {
"select_hex", &dispatch<&game_lua_kernel::intf_select_hex > },
4616 {
"set_time_of_day", &dispatch<&game_lua_kernel::intf_set_time_of_day > },
4617 {
"deselect_hex", &dispatch<&game_lua_kernel::intf_deselect_hex > },
4618 {
"select_unit", &dispatch<&game_lua_kernel::intf_select_unit > },
4619 {
"skip_messages", &dispatch<&game_lua_kernel::intf_skip_messages > },
4620 {
"is_skipping_messages", &dispatch<&game_lua_kernel::intf_is_skipping_messages > },
4621 {
"set_end_campaign_credits", &dispatch<&game_lua_kernel::intf_set_end_campaign_credits > },
4622 {
"set_end_campaign_text", &dispatch<&game_lua_kernel::intf_set_end_campaign_text > },
4623 {
"set_menu_item", &dispatch<&game_lua_kernel::intf_set_menu_item > },
4624 {
"set_next_scenario", &dispatch<&game_lua_kernel::intf_set_next_scenario > },
4625 {
"set_terrain", &dispatch<&game_lua_kernel::intf_set_terrain > },
4626 {
"set_variable", &dispatch<&game_lua_kernel::intf_set_variable > },
4627 {
"set_side_variable", &dispatch<&game_lua_kernel::intf_set_side_variable > },
4628 {
"set_village_owner", &dispatch<&game_lua_kernel::intf_set_village_owner > },
4629 {
"simulate_combat", &dispatch<&game_lua_kernel::intf_simulate_combat > },
4632 {
"teleport", &dispatch<&game_lua_kernel::intf_teleport > },
4633 {
"view_locked", &dispatch<&game_lua_kernel::intf_view_locked > },
4634 {
"place_shroud", &dispatch2<&game_lua_kernel::intf_shroud_op, true > },
4635 {
"remove_shroud", &dispatch2<&game_lua_kernel::intf_shroud_op, false > },
4636 {
nullptr,
nullptr }
4660 cmd_log_ <<
"Adding getunit metatable...\n";
4678 cmd_log_ <<
"Adding unit status metatable...\n";
4692 cmd_log_ <<
"Adding unit attacks metatable...\n";
4716 cmd_log_ <<
"Adding unit variables metatable...\n";
4733 cmd_log_ <<
"Adding ai elements table...\n";
4738 cmd_log_ <<
"Adding game_config table...\n";
4754 cmd_log_ <<
"Adding wesnoth current table...\n";
4768 cmd_log_ <<
"Adding wml_actions table...\n";
4776 cmd_log_ <<
"Adding wml_conditionals table...\n";
4784 cmd_log_ <<
"Adding effects table...\n";
4792 cmd_log_ <<
"Adding game_events table...\n";
4802 cmd_log_ <<
"Adding theme_items table...\n";
4847 cmd_log_ <<
"Failed to compute wesnoth.sides\n";
4850 cmd_log_ <<
"Added wesnoth.sides\n";
4854 cmd_log_ <<
"Adding unit_types table...\n";
4859 for (
const unit_type_data::unit_type_map::value_type &ut :
unit_types.
types())
4867 cmd_log_ <<
"Adding races table...\n";
4876 cmd_log_ <<
"Running preload scripts...\n";
4879 for (
const config &cfg : game_lua_kernel::preload_scripts) {
4890 static luaL_Reg const methods[] = {
4891 {
"matches", &dispatch<&game_lua_kernel::intf_match_unit>},
4892 {
"to_recall", &dispatch<&game_lua_kernel::intf_put_recall_unit>},
4893 {
"to_map", &dispatch<&game_lua_kernel::intf_put_unit>},
4894 {
"erase", &dispatch<&game_lua_kernel::intf_erase_unit>},
4896 {
"extract", &dispatch<&game_lua_kernel::intf_extract_unit>},
4906 {
"select", &dispatch<&game_lua_kernel::intf_select_unit>},
4910 if (strcmp(m,
r.name) == 0) {
4930 "color_palette",
"color_range",
"display",
"end_level_data",
"era",
4931 "event",
"generator",
"label",
"lua",
"map",
"menu_item",
4932 "modification",
"music",
"options",
"side",
"sound_source",
4933 "story",
"terrain_graphics",
"time",
"time_area",
"tunnel",
4934 "undo_stack",
"variables"
4939 for (
char const *
t : handled_file_tags) {
4940 if (s ==
t)
return true;
5001 const std::string m =
"Tag is already used: [" + i->key +
"]";
5145 std::string err_msg =
"unknown conditional wml: [";
5178 if (!ui.
valid())
return false;
5200 log_error(message.c_str(),
"Lua SUF Error");
5255 ERR_LUA <<
"Effect __descr metafunction should have returned a string, but instead returned ";
5264 }
else if(need_apply) {
5293 if (!
luaW_getglobal(L,
"wesnoth",
"game_events",
"on_mouse_move")) {
5306 if (!
luaW_getglobal(L,
"wesnoth",
"game_events",
"on_mouse_action")) {
std::string image_mods() const
bool luaW_checkvariable(lua_State *L, variable_access_create &v, int n)
void set_resting(bool rest)
std::vector< int > get_teams() const
int dispatch(lua_State *L)
#define modify_bool_attrib(name, accessor)
LUA_API void lua_rawgeti(lua_State *L, int idx, int n)
void luaW_pushvconfig(lua_State *L, vconfig const &cfg)
Pushes a vconfig on the top of the stack.
int intf_get_terrain_info(lua_State *L)
Gets details about a terrain.
static int intf_transform_unit(lua_State *L)
Changes a unit to the given unit type.
int intf_kill(lua_State *L)
#define lua_isnoneornil(L, n)
virtual std::string description() const
surface get_image(const image::locator &i_locator, TYPE type)
function to get the surface corresponding to an image.
child_itors child_range(const std::string &key)
const gamemap & map() const
virtual void highlight_hex(map_location hex)
Function to highlight a location.
unsigned int end_text_duration
for how long the end-of-campaign text is shown
static const std::set< std::string > builtin_effects
int total_movement() const
void invalidate_unit_after_move(const map_location &src, const map_location &dst)
Same as invalidate_unit() if moving the displayed unit.
LUA_API void lua_pushlightuserdata(lua_State *L, void *p)
void recalculate_shroud()
config get_user_choice(const std::string &name, const user_choice &uch, int side=0)
events::mouse_handler & get_mouse_handler_base()
Get a reference to a mouse handler member a derived class uses.
std::stack< game_events::queued_event const * > queued_events_
const std::string & id() const
LUA_API void lua_createtable(lua_State *L, int narray, int nrec)
plain_route a_star_search(const map_location &src, const map_location &dst, double stop_at, const cost_calculator *calc, const size_t width, const size_t height, const teleport_map *teleports, bool border)
#define lua_pushcfunction(L, f)
static int intf_advance_unit(lua_State *L)
Advances a unit if the unit has enough xp.
static int intf_get_era(lua_State *L)
Gets a table for an era tag.
static int special_locations_pairs(lua_State *L)
virtual std::string get_id() const =0
int map_locked_
A value != 0 means that the shouldn't remove any units from the map, usually because we are currently...
std::string apply_effect(const std::string &name, unit &u, const config &cfg, bool need_apply)
static DIRECTION parse_direction(const std::string &str)
LUA_API void lua_getfield(lua_State *L, int idx, const char *k)
void show_help(CVideo &video, const std::string &show_topic, int xloc, int yloc)
Open the help browser, show topic with id show_topic.
static thandler * handler
LUA_API void lua_replace(lua_State *L, int idx)
bool end_credits
whether to show the standard credits at the end
void set_shroud(bool shroud)
void apply_builtin_effect(std::string type, const config &effect)
std::vector< double > hp_dist
Resulting probability distribution (might be not as large as max_hp)
LUALIB_API lua_Integer luaL_checkinteger(lua_State *L, int narg)
const map_location & get_location() const
static char const * handled_file_tags[]
These are the child tags of [scenario] (and the like) that are handled elsewhere (in the C++ code)...
void(* handler)(const queued_event &, const vconfig &)
static display * get_singleton()
Returns the display object if a display object exists.
int intf_remove_sound_source(lua_State *L)
Removes a sound source by its ID Arg 1: sound source ID.
int intf_allow_end_turn(lua_State *)
Allow undo sets the flag saying whether the event has mutated the game to false.
std::string const & gender_string(unit_race::GENDER gender)
void set_hidden(bool state) const
std::string absolute_image() const
The name of the file to game_display (used in menus).
int intf_find_path(lua_State *L)
Finds a path between two locations.
bool luaW_tovconfig(lua_State *L, int index, vconfig &vcfg)
Gets an optional vconfig from either a table or a userdata.
std::pair< int, int > get_pair_at(int x, int y) const
Accessor for the cost/reach-amount pairs.
void set_hitpoints(int hp)
void adjust_color_overlay(int r, int g, int b)
Add r,g,b to the colors for all images displayed on the map.
int intf_set_end_campaign_credits(lua_State *L)
#define return_tstring_attrib(name, accessor)
game_display * game_display_
all_children_iterator ordered_end() const
LUA_API void lua_settop(lua_State *L, int idx)
static int impl_unit_set(lua_State *L)
Sets some data on a unit (__newindex metamethod).
bool invalidate(const map_location &loc)
Function to invalidate a specific tile for redrawing.
int max_hitpoints() const
bool get_state(const std::string &state) const
int intf_get_time_of_day(lua_State *L)
Gets time of day information.
int intf_get_unit(lua_State *)
Gets the unit at the given location or with the given id.
LUA_API int lua_type(lua_State *L, int idx)
void luaW_pushteam(lua_State *L, team &tm)
std::string plague_type
The plague type used by the attack, if any.
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.
SDL_Color create_color(const unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha)
void luaW_pushunittype(lua_State *L, const std::string &id)
Create a lua object containing a reference to a unittype, and a metatable to access the properties...
size_t underlying_id() const
The unique internal ID of the unit.
bool clear_unit(const map_location &view_loc, team &view_team, 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, size_t *enemy_count=nullptr, size_t *friend_count=nullptr, move_unit_spectator *spectator=nullptr, bool instant=true)
Clears shroud (and fog) around the provided location for view_team based on sight_range, costs, and slowed.
game_classification * classification
int intf_get_variable(lua_State *L)
Gets a WML variable.
tod_color color
The color modifications that should be made to the game board to reflect the time of day...
const t_string & name() const
The unit name for display.
int intf_modify_ai_wml(lua_State *L)
void replace_schedule(const config &time_cfg)
Replace the time of day schedule.
int intf_match_location(lua_State *L)
Matches a location against the given filter.
std::vector< int > get_sides_vector(const vconfig &cfg)
Gets a vector of sides from side= attribute in a given config node.
Various functions implementing vision (through fog of war and shroud).
const mp_game_settings & get_mp_settings()
int impl_theme_items_get(lua_State *L)
Creates a field of the theme_items table and returns it (__index metamethod).
bool match(const team &t) const
static int impl_unit_attack_set(lua_State *L)
Gets a propoerty of a units attack (__index metamethod).
bool 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.
int intf_replace_schedule(lua_State *l)
Replacing the current time of day schedule.
static int special_locations_len(lua_State *L)
bool play_stage()
Play the turn - strategy.
void set_clip_rect(const SDL_Rect &r)
static int impl_unit_collect(lua_State *L)
Destroys a unit object before it is collected (__gc metamethod).
int movement_cost(const t_translation::t_terrain &terrain) const
LUA_API void lua_pushboolean(lua_State *L, int b)
const mp_game_settings * mp_settings
Various functions that implement attacks and attack calculations.
bool run_wml_action(std::string const &, vconfig const &, game_events::queued_event const &)
Runs a command from an event handler.
int intf_view_locked(lua_State *L)
Gets whether gamemap scrolling is disabled for the user.
Add a special kind of assert to validate whether the input from WML doesn't contain any problems that...
void set_next_scenario(const std::string &next_scenario)
vconfig child(const std::string &key) const
Returns a child of *this whose key is key.
bool clear_fog(const map_location &loc)
void set_wml_action(std::string const &, game_events::wml_action::handler)
Registers a function for use as an action handler.
virtual std::vector< component * > get_children(const std::string &type)
bool to_bool(bool def=false) const
rng * generator
This generator is automatically synced during synced context.
config get_parsed_config() const
GLuint GLuint GLsizei GLenum type
std::vector< team > & teams()
const t_terrain NONE_TERRAIN
static l_noret error(LoadState *S, const char *why)
int intf_set_terrain(lua_State *L)
Sets a terrain code.
bool fire_item(const std::string &id, const map_location &hex, game_data &gamedata, filter_context &fc, unit_map &units) const
Fires the menu item with the given id.
void clear_chat_messages()
static int impl_unit_status_get(lua_State *L)
Gets the status of a unit (__index metamethod).
void advance_unit_at(const advance_unit_params ¶ms)
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...
void handle_legacy_share_vision(const config &cfg)
int intf_clear_messages(lua_State *)
Removes all messages from the chat window.
lua_check_impl::remove_constref< T >::type lua_check(lua_State *L, int n)
const time_of_day & get_time_of_day(int for_turn=0) const
Returns global time of day for the passed turn.
void set_recall_cost(int recall_cost)
int intf_play_sound(lua_State *L)
Plays a sound, possibly repeated.
LUA_API void lua_getglobal(lua_State *L, const char *var)
boost::shared_ptr< ai_composite > ai_ptr
int intf_label(lua_State *L)
Extends variable_info with methods that can only be applied if vit != vit_const.
static int special_locations_newindex(lua_State *L)
bool file_exists() const
Tests whether the file the locater points at exists.
map_location find_vacant_tile(const map_location &loc, VACANT_TILE_TYPE vacancy, const unit *pass_check, const team *shroud_check, const game_board *board)
Function that will find a location on the board that is as near to loc as possible, but which is unoccupied by any units.
LUALIB_API int luaL_getmetafield(lua_State *L, int obj, const char *event)
LUA_API int lua_gettop(lua_State *L)
int intf_extract_unit(lua_State *L)
Extracts a unit from the map or a recall list and gives it to Lua.
std::string usage() const
bool luaW_pushvariable(lua_State *L, variable_access_const &v)
static int intf_copy_unit(lua_State *L)
Copies a unit.
void remove_floating_label(int handle)
removes the floating label given by 'handle' from the screen
std::string register_metatable(lua_State *L)
static int special_locations_next(lua_State *L)
int intf_get_all_vars(lua_State *L)
Gets all the WML variables currently set.
int intf_find_cost_map(lua_State *L)
Is called with one or more units and builds a cost map.
static int impl_unit_get(lua_State *L)
Gets some data on a unit (__index metamethod).
void clear(const std::string &key)
const std::string & id() const
int lawful_bonus
The % bonus lawful units receive.
#define return_string_attrib(name, accessor)
void float_label(const map_location &loc, const std::string &text, const SDL_Color &color)
Function to float a label above a tile.
#define lua_tointeger(L, i)
int intf_set_time_of_day(lua_State *L)
const t_string & name() const
static int special_locations_index(lua_State *L)
void advance_to(const unit_type &t, bool use_traits=false)
Advances this unit to another type.
static lua_ai_context * create(lua_State *L, char const *code, engine_lua *engine)
std::string image
The image to be displayed in the game status.
unit_type_data unit_types
const std::string & id() const
bool prescenario_save
Should a prescenario be created the next game?
bool 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.
int intf_set_village_owner(lua_State *L)
Sets the owner of a village.
int intf_match_unit(lua_State *L)
Matches a unit against the given filter.
int intf_set_next_scenario(lua_State *L)
void play_slice(bool is_delay_enabled=true)
void push_builtin_effect()
Registers a function for use as an effect handler.
int village_owner(const map_location &loc) const
Given the location of a village, will return the 0-based index of the team that currently owns it...
virtual const std::vector< team > & teams() const
const attack_type * weapon
The weapon used by the unit to attack the opponent, or nullptr if there is none.
#define lua_tonumber(L, i)
void set_alignment(unit_type::ALIGNMENT alignment)
advance_unit_params & fire_events(bool value)
bool replay_save
Should a replay save be made?
void remove(const std::string &id)
void write(config &cfg) const
bool slows
Attack slows opponent when it hits.
int intf_skip_messages(lua_State *L)
Set whether to skip messages Arg 1 (optional) - boolean.
void set_font_size(int font_size)
LUA_API int lua_isuserdata(lua_State *L, int idx)
LUA_API void lua_pushcclosure(lua_State *L, lua_CFunction fn, int n)
bool is_skipping_replay() const
unit_ptr luaW_checkunit_ptr(lua_State *L, int index, bool only_on_map)
int intf_scroll(lua_State *L)
virtual void draw()
Draws invalidated items.
int impl_theme_items_set(lua_State *L)
Sets a field of the theme_items table (__newindex metamethod).
void set_state(const std::string &state, bool value)
void append_children(const config &cfg)
Adds children from cfg.
#define return_vector_string_attrib(name, accessor)
luatypekey const getunitKey
int light_bonus(int base) const
Returns the light (lawful) bonus for this terrain when the time of day gives a base bonus...
void set_defeat_condition_string(const std::string &value)
sets the defeat condition if
static bool is_handled_file_tag(const std::string &s)
int intf_get_sides(lua_State *L)
Returns a proxy table array for all sides matching the given SSF.
void lua_push(lua_State *L, const T &val)
void add_unit(const unit &u, bool use_max_moves=true)
Adds a units cost map to cost_map (increments the elements in cost_map)
int drain_constant
Base HP drained regardless of damage dealt.
an object to leave the synced context during draw or unsynced wml items when we don’t know whether w...
std::string debug() const
void lua_chat(std::string const &caption, std::string const &msg)
int intf_gamestate_inspector(lua_State *)
bool get_ability_bool(const std::string &tag_name, const map_location &loc) const
Returns true if the unit is currently under effect by an ability with this given TAG NAME...
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
bool run_wml_conditional(std::string const &, vconfig const &)
Runs a command from an event handler.
bool empty() const
Tests for an attribute that either was never set or was set to "".
map_location luaW_checklocation(lua_State *L, int index)
Converts an optional table or pair of integers to a map location object.
void set_hidden(bool value)
void select_hex(const map_location &hex, const bool browse, const bool highlight=true, const bool fire_event=true)
Definitions for the interface to Wesnoth Markup Language (WML).
const t_string & editor_name() const
t_terrain read_terrain_code(const std::string &str, const t_layer filler)
Reads a single terrain from a string.
void redraw_minimap()
Schedule the minimap to be redrawn.
const game_events::queued_event & get_event_info()
void load_config(const config &v)
static synced_state get_synced_state()
unsigned int chance_to_hit
Effective chance to hit as a percentage (all factors accounted for).
void new_turn()
Update lighting settings.
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 mutiple sides for WML events.
std::pair< const_child_iterator, const_child_iterator > const_child_itors
virtual config random_choice(int side) const =0
LUA_API void * lua_newuserdata(lua_State *L, size_t size)
Variant for storing WML attributes.
int defense_modifier(const t_translation::t_terrain &terrain) const
int intf_get_locations(lua_State *L)
Gets all the locations matching a given filter.
config::attribute_value & get_variable(const std::string &varname)
throws invalid_variablename_exception if varname is no valid variable name.
advance_unit_params & animate(bool value)
void set_scroll_to_leader(bool value)
Unit and team statistics.
bool match(const map_location &loc) const
const tdata_cache & tdata() const
virtual config to_config() const
Serialize to config.
unit * luaW_tounit(lua_State *L, int index, bool only_on_map)
Converts a Lua value to a unit pointer.
std::string describe_builtin_effect(std::string type, const config &effect)
void wml_animation(const vconfig &cfg, const map_location &default_location)
Parse a standard WML for animations and play the corresponding animation.
void play_sound(const std::string &files, channel_group group, unsigned int repeats)
#define return_cfgref_attrib(name, accessor)
const terrain_label * set_label(const map_location &loc, const t_string &text, const int creator=-1, const std::string &team="", const SDL_Color 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="")
bool clear_dest(const map_location &dest, const unit &viewer)
Clears shroud (and fog) at the provided location and its immediate neighbors.
bool reveal_map
Should we reveal map when game is ended? (Multiplayer only)
const std::vector< std::string > & recruits() const
bool blank() const
Tests for an attribute that was never set.
static void extract_preload_scripts(config const &game_config)
static int impl_unit_status_set(lua_State *L)
Sets the status of a unit (__newindex metamethod).
GLdouble GLdouble GLdouble b
int intf_find_reach(lua_State *L)
Finds all the locations reachable by a unit.
void set_game_display(game_display *gd)
bool poisons
Attack poisons opponent when it hits.
static int intf_unit_ability(lua_State *L)
Returns true if the unit has the given ability enabled.
int intf_set_variable(lua_State *L)
Sets a WML variable.
int(game_lua_kernel::* member_callback2)(lua_State *, bool)
void set_no_turn_confirmation(bool value)
std::string register_metatable(lua_State *L)
void set_flag(const std::string &flag)
STRIP_SPACES : strips leading and trailing blank spaces.
void set_role(const std::string &role)
int intf_delay(lua_State *L)
Delays engine for a while.
static bool add_ai_for_side_from_file(side_number side, const std::string &file, bool replace=true)
Adds active AI for specified side from file.
Object which defines a time of day with associated bonuses, image, sounds etc.
void set_current_time(int time)
static std::vector< team > *& teams
lua_unit * luaW_pushlocalunit(lua_State *L, unit &u)
#define lua_upvalueindex(i)
bool backstab_pos
True if the attacker is in position to backstab the defender (this is used to determine whether to ap...
const std::string & type_id() const
The id of the type of the unit.
static void clear_status_caches()
Clear the unit status cache for all units.
game_events::t_pump & pump()
This class stores all the data for a single 'side' (in game nomenclature).
static int intf_eval_conditional(lua_State *L)
Evaluates a boolean WML conditional.
static game_config_manager * get()
A small explanation about what's going on here: Each action has access to two game_info objects First...
static std::string at(const std::string &file, int line)
static UNUSEDNOWARN std::string _(const char *str)
#define modify_tstring_attrib(name, accessor)
void select_hex_callback(const map_location &loc)
int intf_get_map_size(lua_State *L)
Returns the map size.
bool incapacitated() const
LUA_API void lua_setglobal(lua_State *L, const char *var)
void set_facing(map_location::DIRECTION dir) const
int damage
Effective damage of the weapon (all factors accounted for).
static int intf_get_viewing_side(lua_State *L)
Gets currently viewing side.
GLsizei const char ** path
boost::variant< upkeep_full, upkeep_loyal, int > t_upkeep
std::string register_vconfig_metatable(lua_State *L)
Adds the vconfig metatable.
const map_location & mouseover_hex() const
#define modify_string_attrib(name, accessor)
bool linger_mode
Should linger mode be invoked?
std::vector< map_location > steps
int intf_simulate_combat(lua_State *L)
Simulates a combat between two units.
int intf_select_unit(lua_State *L)
Selects and highlights the given location on the map.
int intf_remove_tile_overlay(lua_State *L)
Removes an overlay from a tile.
int current_side() const
Returns the number of the side whose turn it is.
int gives_healing() const
void splice_children(config &src, const std::string &key)
Moves all the children with tag key from src to this.
const std::vector< std::string > & overlays() const
#define return_int_attrib(name, accessor)
int intf_remove_time_area(lua_State *)
Removing new time_areas dynamically with Standard Location Filters.
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...
LUA_API int lua_isstring(lua_State *L, int idx)
map_location starting_position(int side) const
std::vector< team > teams_
bool luaW_toboolean(lua_State *L, int n)
component * get_component(component *root, const std::string &path)
pointer get_shared_ptr() const
const unit_type_map & types() const
unit_type::ALIGNMENT alignment() const
Structure which holds a single route between one location and another.
bool is_regular_game_end() const
void register_generator(const std::string &name, generator *)
void set_emit_zoc(bool val)
unsigned int rounds
Berserk special can force us to fight more than one round.
child_list get_children(const std::string &key) const
void set_lifetime(int lifetime)
std::pair< unit_iterator, bool > insert(unit_ptr p)
Adds the unit to the map.
Proxy table for the AI context.
void recalculate_minimap()
Schedule the minimap for recalculation.
virtual std::string get_engine() const =0
static lua_ai_action_handler * create(lua_State *L, char const *code, lua_ai_context &context)
boost::scoped_ptr< game_events::manager > events_manager_
const std::string & editor_image() const
variable_access_create get_variable_access_write(const std::string &varname)
returns a variable_access that can be used to change the game variables
GLsizei const GLfloat * value
all_children_itors all_children_range() const
In-order iteration over all children.
int intf_get_villages(lua_State *L)
Gets all the villages matching a given filter, or all the villages on the map if no filter is given...
void set_can_recruit(bool canrecruit)
int intf_fire_wml_menu_item(lua_State *L)
Fires a wml menu item.
void luaW_pushtstring(lua_State *L, t_string const &v)
Pushes a t_string on the top of the stack.
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.
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...
virtual bool is_visible() const
whether the choice is visible for the user like an advacement choice a non-visible choice is for exam...
A component of the AI framework.
t_string luaW_checktstring(lua_State *L, int index)
Converts a scalar to a translatable string.
int vision_cost(const t_translation::t_terrain &terrain) const
int w() const
Effective map width.
int intf_set_end_campaign_text(lua_State *L)
int intf_get_displayed_unit(lua_State *)
Gets the unit displayed in the sidebar.
void set_recruits(const std::vector< std::string > &recruits)
Composite AI with turn sequence which is a vector of stages.
static int intf_unit_resistance(lua_State *L)
Returns unit resistance against a given attack type.
Interface for querying local choices.
std::string synced_state()
converts synced_context::get_synced_state() to a string.
virtual void log_error(char const *msg, char const *context="Lua error")
config generate_report(const std::string &name, context &ct, bool only_static=false)
int intf_get_recall_units(lua_State *L)
Gets the numeric ids of all the units matching a given filter on the recall lists.
bool has_child(const std::string &key) const
Returns whether or not *this has a child whose key is key.
GLboolean GLboolean GLboolean GLboolean a
bool plagues
Attack turns opponent into a zombie when fatal.
static int intf_synchronize_choices(lua_State *L)
Ensures a value is synchronized among all the clients.
void play_music_config(const config &music_node)
Encapsulates the map of the game.
virtual ai_context & get_ai_context()
unwrap
bool protected_call(int nArgs, int nRets, error_handler)
int(game_lua_kernel::* member_callback)(lua_State *)
void set_color(const SDL_Color &color)
Computes the statistics of a battle between an attacker and a defender unit.
unit & luaW_checkunit(lua_State *L, int index, bool only_on_map)
Converts a Lua value to a unit pointer.
void initialize(const config &level)
luatypekey const ustatusKey
const std::string & team_name() const
config & add_child(const std::string &key)
std::string end_text
end-of-campaign text
const map_location & displayed_unit_hex() const
Virtual functions shadowed in game_display.
const t_advancements & modification_advancements() const
void set_village_support(int support)
fake_unit_manager * fake_units
LUALIB_API lua_Number luaL_checknumber(lua_State *L, int narg)
unit_race::GENDER gender() const
LUA_API int lua_setmetatable(lua_State *L, int objindex)
int intf_teleport(lua_State *L)
Teeleports a unit to a location.
int intf_get_village_owner(lua_State *L)
Gets the side of a village owner.
int border_size() const
Size of the map border.
void set_position(double xpos, double ypos)
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: ...
void unit_healing(unit &healed, const std::vector< unit * > &healers, int healing, const std::string &extra_text)
This will use a poisoning anim if healing<0.
Managing the AIs lifecycle - headers.
int attack_num
Index into unit->attacks() or -1 for none.
int intf_is_enemy(lua_State *L)
Returns whether the first side is an enemy of the second one.
Structure describing the statistics of a unit involved in the battle.
bool carryover_report
Should a summary of the scenario outcome be displayed?
static void modify_active_ai_for_side(ai::side_number side, const config &cfg)
Modifies AI parameters for active AI of the given side.
int intf_is_skipping_messages(lua_State *L)
Return true if a replay is in progress but the player has chosen to skip it.
int intf_get_sound_source(lua_State *L)
Get an existing sound source Arg 1: The sound source ID Return: Config of sound source info...
LUALIB_API void * luaL_testudata(lua_State *L, int ud, const char *tname)
int intf_put_unit(lua_State *L)
Places a unit on the map.
static void push_component(lua_State *L, ai::component *c, const std::string &ct="")
static int intf_unit_vision_cost(lua_State *L)
Returns unit vision cost on a given terrain.
void needs_rebuild(bool b)
Sets whether the screen (map visuals) needs to be rebuilt. This is typically after the map has been c...
static void push_locations_talbe(lua_State *L)
Error used for any general game error, e.g.
int movement_left() const
Returns how far a unit can move this turn (zero if incapacitated).
void invalidate_all()
Function to invalidate all tiles.
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
int intf_redraw(lua_State *L)
Templates and utility-routines for strings and numbers.
LUA_API lua_Number lua_tonumberx(lua_State *L, int idx, int *isnum)
const std::string & id() const
void remove_fog_override(const std::set< map_location > &hexes)
Removes the record of hexes that were cleared of fog via WML.
int intf_add_tile_overlay(lua_State *L)
Adds an overlay on a tile.
void place_shroud(const map_location &loc)
virtual config query_user(int side) const =0
int impl_current_get(lua_State *L)
Gets some data about current point of game (__index metamethod).
static int intf_set_music(lua_State *L)
Modifies the music playlist.
LUA_API void lua_pushnil(lua_State *L)
all_children_iterator erase(const all_children_iterator &i)
#define modify_vector_string_attrib(name, accessor)
void erase_if_matches_id(const std::string &unit_id)
Erase any unit with this id.
const std::vector< attack_type > & attacks() const
void load_game(const config &level)
Executes the game_events.on_load function and passes to it all the scenario tags not yet handled...
LUA_API void lua_pushnumber(lua_State *L, lua_Number n)
advances the unit at loc if it has enough experience, maximum 20 times.
int move_cost
Movement cost for reaching the end of the route.
void write(config &cfg) const
const std::string & save_id() const
const std::string ¶meters float amount
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
static int impl_unit_equality(lua_State *L)
Checks two lua proxy units for equality.
static int intf_get_time_stamp(lua_State *L)
Returns the time stamp, exactly as [set_variable] time=stamp does.
virtual void force_end_turn()=0
play_controller & play_controller_
int intf_modify_side(lua_State *L)
void set_allow_end_turn(bool value)
double slowed
Resulting chance we are slowed.
int impl_theme_item(lua_State *L, std::string name)
Executes its upvalue as a theme item generator.
void save_game(config &level)
Executes the game_events.on_save function and adds to cfg the returned tags.
Encapsulates the map of the game.
ai::lua_ai_context * create_lua_ai_context(char const *code, ai::engine_lua *engine)
void set_village_gold(int income)
int intf_add_event(lua_State *L)
Adding new events.
Various functions related to moving units.
#define lua_isboolean(L, n)
double turbo_speed() const
void unit_die(const map_location &loc, unit &loser, const attack_type *attack, const attack_type *secondary_attack, const map_location &winner_loc, unit *winner)
Show a unit fading out.
int jamming_cost(const t_translation::t_terrain &terrain) const
Storage for a unit, either owned by the Lua code (ptr != 0), a local variable unit (c_ptr != 0)...
virtual std::string get_name() const =0
int intf_message(lua_State *L)
Displays a message in the chat window and in the logs.
bool luaW_toconfig(lua_State *L, int index, config &cfg)
Converts an optional table or vconfig to a config object.
Define conditionals for the game's events mechanism, a.k.a.
bool luaW_totstring(lua_State *L, int index, t_string &str)
Converts a scalar to a translatable string.
#define return_cfg_attrib(name, accessor)
int intf_heal_unit(lua_State *L)
void set_end_level_data(const end_level_data &data)
int on_recall_list() const
LUA_API void * lua_touserdata(lua_State *L, int idx)
void erase_by_underlying_id(size_t uid)
Erase any unit with this underlying id.
void add_modification(const std::string &type, const config &modification, bool no_add=false)
static void init(lua_State *L)
int impl_game_config_set(lua_State *L)
Sets some game_config data (__newindex metamethod).
bool luaW_hasmetatable(lua_State *L, int index, luatypekey key)
Returns true if the metatable of the object is the one found in the registry.
transient_end_level transient
void luaW_pushracetable(lua_State *L)
static bool add_component(component *root, const std::string &path, const config &cfg)
const std::vector< std::string > & advances_to() const
void get_locations(std::set< map_location > &locs, bool with_border=false) const
std::vector< std::string > get_area_ids() const
void set_video(CVideo *ptr)
Cost function object relying on a Lua function.
void set_gold(int amount)
std::map< std::string, tfilter >::iterator itor
virtual void push_ai_table()
Method that pushes the AI table of the lua_context on the stack for debugging purposes.
bool clear_shroud(const map_location &loc)
std::stringstream & wml_error()
Use this logger to send errors due to deprecated WML.
int intf_end_turn(lua_State *)
int h() const
Effective map height.
int intf_remove_event(lua_State *L)
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.
map_location::DIRECTION facing() const
LUA_API void lua_rawset(lua_State *L, int idx)
static int impl_unit_variables_get(lua_State *L)
Gets the variable of a unit (__index metamethod).
void add(const sourcespec &source)
void add_event_handler(const config &handler, bool is_menu_item=false)
Create an event handler.
void set_name(const t_string &name)
static int intf_synchronize_choice(lua_State *L)
Ensures a value is synchronized among all the clients.
int intf_get_units(lua_State *)
Gets all the units matching a given filter.
config luaW_checkconfig(lua_State *L, int index)
Converts an optional table or vconfig to a config object.
static int intf_unit_movement_cost(lua_State *L)
Returns unit movement cost on a given terrain.
void set_location(const map_location &loc)
To be called by unit_map or for temporary units only.
Game configuration data as global variables.
#define lua_isfunction(L, n)
const config & get_config() const
const config & game_config() const
const SDL_Color LABEL_COLOR
int intf_set_side_variable(lua_State *L)
Gets a side specific WML variable.
static int intf_debug_ai(lua_State *L)
Debug access to the ai tables.
Structure which uses find_routes() to build a cost map This maps each hex to a the movements a unit w...
static int impl_unit_attacks_len(lua_State *L)
Counts the attacks of a unit (__len metamethod).
static int cfun_exec_stage(lua_State *L)
int intf_animate_unit(lua_State *)
Define the game's event mechanism.
#define log_scope(description)
GLfloat GLfloat GLfloat GLfloat h
int intf_scroll_to_tile(lua_State *L)
Scrolls to given tile.
LUALIB_API int luaL_argerror(lua_State *L, int narg, const char *extramsg)
void set_movement(int moves, bool unit_action=false)
Set the unit's remaining movement to moves.
bool firststrike
Attack has firststrike special.
const std::string & variation() const
static int impl_unit_attack_get(lua_State *L)
Gets a propoerty of a units attack (__index metamethod).
#define lua_tostring(L, i)
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
int add_floating_label(const floating_label &flabel)
add a label floating on the screen above everything else.
LUA_API void lua_rawseti(lua_State *L, int idx, int n)
ai::lua_ai_action_handler * create_lua_ai_action_handler(char const *code, ai::lua_ai_context &context)
bool run_filter(char const *name, unit const &u)
Runs a script from a unit filter.
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 set_side(unsigned int new_side)
int intf_lock_view(lua_State *L)
Sets whether gamemap scrolling is disabled for the user.
bool proceed_to_next_level
whether to proceed to the next scenario, equals is_victory in sp.
int intf_add_time_area(lua_State *)
Adding new time_areas dynamically with Standard Location Filters.
static int intf_debug(lua_State *L)
Dumps a wml table or userdata wml object into a pretty string.
void set_upkeep(t_upkeep v)
bool change_terrain(const map_location &loc, const std::string &t, const std::string &mode, bool replace_if_failed)
void set_flag_icon(const std::string &flag_icon)
int intf_get_starting_location(lua_State *L)
Returns the starting position of a side.
static int intf_get_image_size(lua_State *L)
Gets the dimension of an image.
LUA_API void lua_insert(lua_State *L, int idx)
Additional information on the game outcome which can be provided by WML.
std::set< std::string > & encountered_units()
GLdouble GLdouble GLdouble r
LUA_API void lua_pushvalue(lua_State *L, int idx)
static int intf_get_traits(lua_State *L)
.Returns information about the global traits known to the engine.
int impl_game_config_get(lua_State *L)
Gets some game_config data (__index metamethod).
int intf_get_selected_tile(lua_State *L)
Returns the currently selected tile.
The game event manager loads the scenario configuration object, and ensures that events are handled a...
std::string register_metatable(lua_State *L)
bool context_mutated()
Context: The general environment within which events are processed.
LUA_API int lua_isnumber(lua_State *L, int idx)
void set_view_locked(bool value)
Sets whether the map view is locked (e.g.
int intf_set_menu_item(lua_State *L)
static vconfig unconstructed_vconfig()
This is just a wrapper for the default constructor; it exists for historical reasons and to make it c...
bool fire_event(const tevent event, std::vector< std::pair< twidget *, tevent > > &event_chain, twidget *dispatcher, twidget *widget, F functor)
Helper function for fire_event.
static int intf_add_known_unit(lua_State *L)
Adds a new known unit type to the help system.
virtual void log_error(char const *msg, char const *context="Lua error")
int intf_add_sound_source(lua_State *L)
Add a new sound source Arg 1: Table containing keyword arguments.
static int intf_unit_jamming_cost(lua_State *L)
Returns unit jamming cost on a given terrain.
std::pair< unit_iterator, bool > move(const map_location &src, const map_location &dst)
Moves a unit from location src to location dst.
int intf_shroud_op(lua_State *L, bool place_shroud)
void change_controller_by_wml(const std::string &new_controller)
LUALIB_API int luaL_error(lua_State *L, const char *fmt,...)
std::string write_terrain_code(const t_terrain &tcode)
Writes a single terrain code to a string.
int resistance_against(const std::string &damage_name, bool attacker, const map_location &loc) const
Proxy class for calling AI action handlers defined in Lua.
const config::const_child_itors traits() const
std::string big_profile() const
int intf_allow_undo(lua_State *)
Allow undo sets the flag saying whether the event has mutated the game to false.
static int load_fake_units(lua_State *L, int arg, T &fake_units)
int drain_percent
Percentage of damage recovered as health.
virtual std::vector< std::string > get_children_types()
int intf_match_side(lua_State *L)
Matches a side against the given filter.
GLuint const GLchar * name
virtual const gamemap & map() const
std::set< std::string > set_split(std::string const &val, const char c= ',', const int flags=REMOVE_EMPTY|STRIP_SPACES)
Splits a (comma-)separated string into a set of pieces.
size_t erase(const map_location &l)
Erases the unit at location l, if any.
int intf_toggle_fog(lua_State *L, const bool clear)
Implements the lifting and resetting of fog via WML.
const game_classification & get_classification()
LUA_API size_t lua_rawlen(lua_State *L, int idx)
bool clear_shroud(int side, bool reset_fog, bool fire_events)
Function that will clear shroud (and fog) based on current unit positions.
bool on_board(const map_location &loc) const
Tell if a location is on the map.
virtual double evaluate()=0
Evaluate the candidate action, resetting the internal state of the action.
bool run_event(game_events::queued_event const &)
Executes the game_events.on_event function.
bool fire_events()
Fires the sighted events that were earlier recorded by fog/shroud clearing.
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.
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)
Functions to add and remove overlays from locations.
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
display_chat_manager & get_chat_manager()
virtual std::string my_name()
const std::string & effect_image_mods() const
size_t find_index(const std::string &unit_id) const
Find the index of a unit by its id.
bool conditional_passed(const vconfig &cond)
#define LUA_REGISTRYINDEX
#define return_bool_attrib(name, accessor)
bool matches_unit(const unit_map::const_iterator &un_it) const
Determines if un_it matches (using underlying ID) the unit that was supplied when this was constructe...
To store label data Class implements logic for rendering.
boost::intrusive_ptr< unit > unit_ptr
#define luaL_checkint(L, n)
LUA_API int lua_error(lua_State *L)
void set_advancements(std::vector< config > advancements)
int intf_erase_unit(lua_State *L)
Erases a unit from the map.
boost::shared_ptr< wb::manager > get_whiteboard()
static const config & get_default_ai_parameters()
get default AI parameters
bool put_map(const map_location &loc)
int max_experience() const
map_locker(game_lua_kernel *kernel)
int intf_color_adjust(lua_State *L)
int intf_open_help(lua_State *L)
#define lua_istable(L, n)
static int intf_modify_ai(lua_State *L)
Lua frontend to the modify_ai functionality.
int intf_clear_menu_item(lua_State *L)
bool find(E event, F functor)
Tests whether an event handler is available.
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 luaW_pushconfig(lua_State *L, config const &cfg)
Converts a config object to a Lua table pushed at the top of the stack.
int intf_get_mouseover_tile(lua_State *L)
Returns the currently overed tile.
void merge_shroud_map_data(const std::string &shroud_data)
Merge a WML shroud map with the shroud data of this player.
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.
Managing the AIs configuration - headers.
config & child(const std::string &key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
static int cond(LexState *ls)
const std::vector< time_of_day > & times(const map_location &loc=map_location::null_location()) const
std::vector< attack_type > attacks() const
A variable-expanding proxy for the config class.
bool show_everything() const
unit_ptr extract(const map_location &loc)
Extracts a unit from the map.
Standard logging facilities (interface).
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 config preload_config
const SDL_Rect & map_outside_area() const
Returns the available area for a map, this may differ from the above.
CVideo & video()
Gets the underlying screen object.
Object which contains all the possible locations a unit can move to, with associated best routes to t...
static int intf_unit_defense(lua_State *L)
Returns unit defense on a given terrain.
recall_list_manager & recall_list()
void add(const unit_ptr &ptr)
Add a unit to the list.
void add_fog_override(const std::set< map_location > &hexes)
Records hexes that were cleared of fog via WML.
Container associating units to locations.
static void delay(unsigned int milliseconds)
GLsizei GLenum GLuint GLuint GLsizei char * message
void reinit_flags_for_side(size_t side)
Rebuild the flag list (not team colors) for a single side.
game_lua_kernel * kernel_
void set_attacks(int left)
int intf_print(lua_State *L)
int to_int(int def=0) const
void set_item(const std::string &id, const vconfig &menu_item)
Updates or creates (as appropriate) the menu item with the given id.
void mouse_over_hex_callback(const map_location &loc)
static int cfun_exec_candidate_action(lua_State *L)
void change_team(const std::string &name, const t_string &user_name)
Class to encapsulate fog/shroud clearing and the resultant sighted events.
void set_level(int level)
unsigned int num_blows
Effective number of blows, takes swarm into account.
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.
vconfig luaW_checkvconfig(lua_State *L, int index, bool allow_missing)
Gets an optional vconfig from either a table or a userdata.
luatypekey const uattackKey
double average_hp(unsigned int healing=0) const
What's the average hp (weighted average of hp_dist).
std::vector< std::string > split(std::string const &val, const char c, const int flags)
Splits a (comma-)separated string into a vector of pieces.
static const map & registry()
luatypekey const uattacksKey
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...
int intf_put_recall_unit(lua_State *L)
Puts a unit on a recall list.
int cfun_wml_action(lua_State *L)
Executes its upvalue as a wml action.
SDL_Color string_to_color(const std::string &cmp_str)
Return the color the string represents.
static int intf_add_modification(lua_State *L)
Adds a modification to a unit.
void set_base_income(int amount)
void clear_variable(const std::string &varname)
Clears attributes config children does nothing if varname is no valid variable name.
size_t viewing_team() const
The viewing team is the team currently viewing the game.
unit_iterator find(size_t id)
void commit_music_changes()
int intf_get_side_variable(lua_State *L)
Gets a side specific WML variable.
void set_recruits(const std::set< std::string > &recruits)
int intf_get_terrain(lua_State *L)
Gets a terrain code.
const teleport_map get_teleport_locations(const unit &u, const team &viewing_team, bool see_all, bool ignore_units)
LUALIB_API void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup)
virtual soundsource::manager * get_soundsource_man()
Get (optionally) a soundsources manager a derived class uses.
static void luaW_pushsimdata(lua_State *L, const combatant &cmb)
Puts a table at the top of the stack with some combat result.
std::string custom_endlevel_music
Custom short music played at the end.
const std::string & get_role() const
static bool intf_find_cost_map_helper(const unit *ptr)
int show_gamestate_inspector(CVideo &video, const vconfig &cfg)
int intf_deselect_hex(lua_State *L)
Deselects any highlighted hex on the map.
bool petrifies
Attack petrifies opponent when it hits.
bool get_emit_zoc() const
A config object defines a single node in a WML file, with access to child nodes.
int intf_check_end_level_disabled(lua_State *L)
void add_chat_message(const time_t &time, const std::string &speaker, int side, const std::string &msg, events::chat_handler::MESSAGE_TYPE type, bool bell)
static ai::holder & get_active_ai_holder_for_side_dbg(side_number side)
Gets the active AI holder for debug purposes.
void remove_single_overlay(const map_location &loc, const std::string &toDelete)
remove_single_overlay will remove a single overlay from a tile
int intf_find_vacant_tile(lua_State *L)
Finds a vacant tile.
LUA AI Support engine - creating specific ai components from config.
config get(const std::string &id)
const t_string & description() const
static int impl_unit_attacks_get(lua_State *L)
Gets the attacks of a unit or unit type (__index metamethod).
const std::vector< map_location > & villages() const
Return a list of the locations of villages on the map.
void set_experience(int xp)
luatypekey const unitvarKey
static int impl_unit_variables_set(lua_State *L)
Sets the variable of a unit (__newindex metamethod).
int dispatch2(lua_State *L)
const unit_race * race() const
Never returns nullptr, but may point to the null race.
LUA_API void lua_pushinteger(lua_State *L, lua_Integer n)
bool scroll(int xmov, int ymov, bool force=false)
Scrolls the display by xmov,ymov pixels.
Thrown when a lexical_cast fails.
void remove_overlay(const map_location &loc)
remove_overlay will remove all overlays on a tile.
This module contains various pathfinding functions and utilities.
LUALIB_API int luaL_typerror(lua_State *L, int narg, const char *tname)
static std::string write_direction(DIRECTION dir)
std::vector< std::string > get_ability_list() const
const std::string version
LUA_API void lua_rawget(lua_State *L, int idx)
Defines the MAKE_ENUM macro.
bool drains
Attack drains opponent when it hits.
GLsizei const GLcharARB ** string
void display_unit_hex(map_location hex)
Change the unit to be displayed in the sidebar.
int intf_fire_event(lua_State *L)
Fires an event.
Define locations as used by the game's events mechanism.
void run_lua_tag(const config &cfg)
Runs a [lua] tag.
bool has_attribute(const std::string &key) const
< Synonym for operator[]
LUA_API const char * lua_pushstring(lua_State *L, const char *s)
LUA_API void lua_setfield(lua_State *L, int idx, const char *k)
const std::string & icon_image() const
unit_map::iterator find_visible_unit(const map_location &loc, const team ¤t_team, bool see_all=false)
Display units performing various actions: moving, attacking, and dying.
size_type erase(const std::string &id)
Erases the item with the provided id.
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.
const map_location & selected_hex() const
bool luaW_tolocation(lua_State *L, int index, map_location &loc)
Converts an optional table or pair of integers to a map location object.
void set_advances_to(const std::vector< std::string > &advances_to)
LUA_API const char * lua_typename(lua_State *L, int t)
double poisoned
Resulting chance we are poisoned.
static lg::log_domain log_scripting_lua("scripting/lua")
int intf_random(lua_State *L)
Returns a random numer, same interface as math.random.
static void modify_active_ai_config_old_for_side(side_number side, const config::const_child_itors &ai_parameters)
Modifies AI parameters for active AI of the given side.
virtual void execute()=0
Execute the candidate action.
all_children_iterator ordered_begin() const
int number_of_turns() const
candidate action framework
t_upkeep upkeep_raw() const
bool maybe_rebuild()
Rebuilds the screen if needs_rebuild(true) was previously called, and resets the flag.
int intf_select_hex(lua_State *L)
static std::vector< config > preload_scripts
int return_unit_method(lua_State *L, char const *m)
#define modify_int_attrib(name, accessor)
int intf_float_label(lua_State *L)
Floats some text on the map.
int intf_end_level(lua_State *)
void set_color(const std::string &color)
game_events::wmi_container & get_wml_menu_items()
std::vector< std::string > get_traits_list() const
virtual config generate(context &ct)=0
static int intf_create_unit(lua_State *L)
Creates a unit from its WML description.
#define luaL_checkstring(L, n)
int intf_highlight_hex(lua_State *L)
Highlights the given location on the map.
game_lua_kernel(CVideo *, game_state &, play_controller &, reports &)