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_gold(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);
165 disp->reinit_flags_for_team(
t);
192 t.set_flag_icon(value);
196 return t.user_team_name();
200 t.change_team(
t.team_name(), value);
204 return t.team_name();
208 t.change_team(value,
t.user_team_name());
216 return t.faction_name();
224 t.change_controller_by_wml(value);
236 t.set_defeat_condition_string(value);
246 t.set_share_vision(*v);
248 throw luaL_argerror(L, 3,
"Invalid share_vision value (should be 'all', 'none', or 'shroud')");
253 return t.carryover_bonus();
257 t.set_carryover_bonus(value);
261 return t.carryover_percentage();
265 t.set_carryover_percentage(value);
269 return t.carryover_gold();
273 t.set_carryover_gold(value);
277 return t.carryover_add();
281 t.set_carryover_add(value);
293 return t.persistent();
297 t.set_persistent(value);
301 return t.no_turn_confirmation();
305 t.set_no_turn_confirmation(value);
309 return t.share_maps();
313 return t.share_view();
317 return t.chose_random();
321 return t.side_name_tstr();
325 t.set_side_name(value);
329 return t.shroud_data();
334 t.merge_shroud_map_data(value);
342 t.set_recruits(value);
347 lua_createtable(L, 1, 0);
349 lua_rawseti(L, -2, 1);
409 std::ostringstream str;
417 lua_push(L, str.str());
427 static int impl_side_set(lua_State *L)
429 return sideReg.set(L);
432 static int impl_side_equal(lua_State *L)
434 // Hidden metamethod, so arg1 has to be a pointer to a team.
435 team &t1 = luaW_checkteam(L, 1);
436 if(team* t2 = luaW_toteam(L, 2)) {
437 lua_pushboolean(L, t1.side() == t2->side());
439 lua_pushboolean(L, false);
450 static int impl_side_variables_get(lua_State *L)
452 if(!lua_istable(L, 1)) {
453 return luaW_type_error(L, 1, "side variables");
455 lua_rawgeti(L, 1, 1);
456 const team& side = luaW_checkteam(L, -1);
458 char const *m = luaL_checkstring(L, 2);
459 return_cfgref_attrib("__cfg", side.variables());
461 variable_access_const v(m, side.variables());
462 return luaW_pushvariable(L, v) ? 1 : 0;
471 static int impl_side_variables_set(lua_State *L)
473 if(!lua_istable(L, 1)) {
474 return luaW_type_error(L, 1, "side variables");
476 lua_rawgeti(L, 1, 1);
477 team& side = luaW_checkteam(L, -1);
479 char const *m = luaL_checkstring(L, 2);
480 if(strcmp(m, "__cfg") == 0) {
481 side.variables() = luaW_checkconfig(L, 3);
484 config& vars = side.variables();
485 if(lua_isnoneornil(L, 3)) {
487 variable_access_throw(m, vars).clear(false);
488 } catch(const invalid_variablename_exception&) {
492 variable_access_create v(m, vars);
493 luaW_checkvariable(L, v, 3);
499 std::string register_metatable(lua_State * L)
501 std::ostringstream cmd_out;
503 cmd_out << "Adding getside metatable...\n";
505 luaL_newmetatable(L, Team);
507 static luaL_Reg const callbacks[] {
508 { "__index", &impl_side_get},
509 { "__newindex", &impl_side_set},
510 { "__dir", &impl_side_dir},
511 { "__eq", &impl_side_equal},
512 { "__tostring", &impl_side_tostring},
515 luaL_setfuncs(L, callbacks, 0);
517 lua_pushstring(L, Team);
518 lua_setfield(L, -2, "__metatable");
520 // Create the side variables metatable.
521 cmd_out << "Adding side variables metatable...\n";
523 luaL_newmetatable(L, teamVar);
524 lua_pushcfunction(L, impl_side_variables_get);
525 lua_setfield(L, -2, "__index");
526 lua_pushcfunction(L, impl_side_variables_set);
527 lua_setfield(L, -2, "__newindex");
528 lua_pushstring(L, "side variables");
529 lua_setfield(L, -2, "__metatable");
531 return cmd_out.str();
535 void luaW_pushteam(lua_State *L, team & tm)
537 team** t = static_cast<team**>(lua_newuserdatauv(L, sizeof(team*), 0));
539 luaL_setmetatable(L, Team);
542 team& luaW_checkteam(lua_State* L, int idx)
544 return **static_cast<team **>(luaL_checkudata(L, idx, Team));
547 team& luaW_checkteam(lua_State* L, int idx, game_board& board)
549 if(lua_isinteger(L, idx)) {
550 int side = lua_tointeger(L, idx);
551 if(!board.has_team(side)) {
552 std::string error = "side " + std::to_string(side) + " does not exist";
553 luaL_argerror(L, 1, error.c_str());
556 return board.get_team(side);
558 return **static_cast<team **>(luaL_checkudata(L, idx, Team));
561 team* luaW_toteam(lua_State* L, int idx)
563 if(void* p = luaL_testudata(L, idx, Team)) {
564 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
static game_display * get_singleton()
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 int impl_side_tostring(lua_State *L)
Turns a lua proxy side to string.
static void reinit_flag_for_team(const team &t)
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