44 static const char *
Team =
"side";
45 static const char teamVar[] =
"side variables";
47 #define SIDE_GETTER(name, type) LATTR_GETTER(name, type, team, t)
48 #define SIDE_SETTER(name, type) LATTR_SETTER(name, type, team, t)
52 inline static auto metatable =
Team;
76 return t.objectives();
80 t.set_objectives(value,
true);
84 return t.village_gold();
88 t.set_village_support(value);
92 return t.village_support();
96 t.set_village_support(value);
100 return t.villages().size();
104 return t.recall_cost();
108 t.set_recall_cost(value);
112 return t.base_income();
116 t.set_base_income(value);
120 return t.total_income();
124 return t.objectives_changed();
128 t.set_objectives_changed(value);
140 return t.uses_shroud();
156 return t.get_scroll_to_leader();
160 t.set_scroll_to_leader(value);
164 auto* disp = lua_kernel_base::get_lua_kernel<game_lua_kernel>(L).get_display();
166 disp->reinit_flags_for_team(
t);
193 t.set_flag_icon(value);
197 return t.user_team_name();
201 t.change_team(
t.team_name(), value);
205 return t.team_name();
209 t.change_team(value,
t.user_team_name());
217 return t.faction_name();
225 t.change_controller_by_wml(value);
237 t.set_defeat_condition_string(value);
247 t.set_share_vision(*v);
249 throw luaL_argerror(L, 3,
"Invalid share_vision value (should be 'all', 'none', or 'shroud')");
254 return t.carryover_bonus();
258 t.set_carryover_bonus(value);
262 return t.carryover_percentage();
266 t.set_carryover_percentage(value);
270 return t.carryover_add();
274 t.set_carryover_add(value);
286 return t.persistent();
290 t.set_persistent(value);
294 return t.no_turn_confirmation();
298 t.set_no_turn_confirmation(value);
302 return t.share_maps();
306 return t.share_view();
310 return t.chose_random();
314 return t.side_name_tstr();
318 t.set_side_name(value);
322 return t.shroud_data();
327 t.merge_shroud_map_data(value);
335 t.set_recruits(value);
340 lua_createtable(L, 1, 0);
342 lua_rawseti(L, -2, 1);
402 std::ostringstream str;
410 lua_push(L, str.str());
420 static int impl_side_set(lua_State *L)
422 return sideReg.set(L);
425 static int impl_side_equal(lua_State *L)
427 // Hidden metamethod, so arg1 has to be a pointer to a team.
428 team &t1 = luaW_checkteam(L, 1);
429 if(team* t2 = luaW_toteam(L, 2)) {
430 lua_pushboolean(L, t1.side() == t2->side());
432 lua_pushboolean(L, false);
443 static int impl_side_variables_get(lua_State *L)
445 if(!lua_istable(L, 1)) {
446 return luaW_type_error(L, 1, "side variables");
448 lua_rawgeti(L, 1, 1);
449 const team& side = luaW_checkteam(L, -1);
451 char const *m = luaL_checkstring(L, 2);
452 return_cfgref_attrib("__cfg", side.variables());
454 variable_access_const v(m, side.variables());
455 return luaW_pushvariable(L, v) ? 1 : 0;
464 static int impl_side_variables_set(lua_State *L)
466 if(!lua_istable(L, 1)) {
467 return luaW_type_error(L, 1, "side variables");
469 lua_rawgeti(L, 1, 1);
470 team& side = luaW_checkteam(L, -1);
472 char const *m = luaL_checkstring(L, 2);
473 if(strcmp(m, "__cfg") == 0) {
474 side.variables() = luaW_checkconfig(L, 3);
477 config& vars = side.variables();
478 if(lua_isnoneornil(L, 3)) {
480 variable_access_throw(m, vars).clear(false);
481 } catch(const invalid_variablename_exception&) {
485 variable_access_create v(m, vars);
486 luaW_checkvariable(L, v, 3);
492 std::string register_metatable(lua_State * L)
494 std::ostringstream cmd_out;
496 cmd_out << "Adding getside metatable...\n";
498 luaL_newmetatable(L, Team);
500 static luaL_Reg const callbacks[] {
501 { "__index", &impl_side_get},
502 { "__newindex", &impl_side_set},
503 { "__dir", &impl_side_dir},
504 { "__eq", &impl_side_equal},
505 { "__tostring", &impl_side_tostring},
508 luaL_setfuncs(L, callbacks, 0);
510 lua_pushstring(L, Team);
511 lua_setfield(L, -2, "__metatable");
513 // Create the side variables metatable.
514 cmd_out << "Adding side variables metatable...\n";
516 luaL_newmetatable(L, teamVar);
517 lua_pushcfunction(L, impl_side_variables_get);
518 lua_setfield(L, -2, "__index");
519 lua_pushcfunction(L, impl_side_variables_set);
520 lua_setfield(L, -2, "__newindex");
521 lua_pushstring(L, "side variables");
522 lua_setfield(L, -2, "__metatable");
524 return cmd_out.str();
528 void luaW_pushteam(lua_State *L, team & tm)
530 team** t = static_cast<team**>(lua_newuserdatauv(L, sizeof(team*), 0));
532 luaL_setmetatable(L, Team);
535 team& luaW_checkteam(lua_State* L, int idx)
537 return **static_cast<team **>(luaL_checkudata(L, idx, Team));
540 team& luaW_checkteam(lua_State* L, int idx, game_board& board)
542 if(lua_isinteger(L, idx)) {
543 int side = lua_tointeger(L, idx);
544 if(!board.has_team(side)) {
545 std::string error = "side " + std::to_string(side) + " does not exist";
546 luaL_argerror(L, 1, error.c_str());
549 return board.get_team(side);
551 return **static_cast<team **>(luaL_checkudata(L, idx, Team));
554 team* luaW_toteam(lua_State* L, int idx)
556 if(void* p = luaL_testudata(L, idx, Team)) {
557 return *static_cast<team **>(p);
A config object defines a single node in a WML file, with access to child nodes.
virtual const gamemap & map() const override
map_location starting_position(int side) const
This class stores all the data for a single 'side' (in game nomenclature).
const std::string & side_name() const
static int impl_side_get(lua_State *L)
Gets some data on a side (__index metamethod).
#define SIDE_SETTER(name, type)
static const char teamVar[]
static const char * Team
Implementation for a lua reference to a team, used by the wesnoth in-game sides table.
#define SIDE_GETTER(name, type)
static void reinit_flag_for_team(lua_State *L, const team &t)
static int impl_side_tostring(lua_State *L)
Turns a lua proxy side to string.
team & luaW_checkteam(lua_State *L, int idx)
Test if the top stack element is a team, and if not, error.
static int impl_side_dir(lua_State *L)
Gets a list of data on a side (__dir metamethod).
Holds a lookup table for members of one type of object.
int dir(lua_State *L)
Implement __dir metamethod.
int get(lua_State *L)
Implement __index metamethod.
static team & get(lua_State *L, int n)
Encapsulates the map of the game.
static std::string get_string(enum_type key)
Converts a enum to its string equivalent.
static constexpr utils::optional< enum_type > get_enum(const std::string_view value)
Converts a string into its enum equivalent.
static map_location::direction n