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_gold();
274 t.set_carryover_gold(value);
278 return t.carryover_add();
282 t.set_carryover_add(value);
294 return t.persistent();
298 t.set_persistent(value);
302 return t.no_turn_confirmation();
306 t.set_no_turn_confirmation(value);
310 return t.share_maps();
314 return t.share_view();
318 return t.chose_random();
322 return t.side_name_tstr();
326 t.set_side_name(value);
330 return t.shroud_data();
335 t.merge_shroud_map_data(value);
343 t.set_recruits(value);
348 lua_createtable(L, 1, 0);
350 lua_rawseti(L, -2, 1);
410 std::ostringstream str;
418 lua_push(L, str.str());
428 static int impl_side_set(lua_State *L)
430 return sideReg.set(L);
433 static int impl_side_equal(lua_State *L)
435 // Hidden metamethod, so arg1 has to be a pointer to a team.
436 team &t1 = luaW_checkteam(L, 1);
437 if(team* t2 = luaW_toteam(L, 2)) {
438 lua_pushboolean(L, t1.side() == t2->side());
440 lua_pushboolean(L, false);
451 static int impl_side_variables_get(lua_State *L)
453 if(!lua_istable(L, 1)) {
454 return luaW_type_error(L, 1, "side variables");
456 lua_rawgeti(L, 1, 1);
457 const team& side = luaW_checkteam(L, -1);
459 char const *m = luaL_checkstring(L, 2);
460 return_cfgref_attrib("__cfg", side.variables());
462 variable_access_const v(m, side.variables());
463 return luaW_pushvariable(L, v) ? 1 : 0;
472 static int impl_side_variables_set(lua_State *L)
474 if(!lua_istable(L, 1)) {
475 return luaW_type_error(L, 1, "side variables");
477 lua_rawgeti(L, 1, 1);
478 team& side = luaW_checkteam(L, -1);
480 char const *m = luaL_checkstring(L, 2);
481 if(strcmp(m, "__cfg") == 0) {
482 side.variables() = luaW_checkconfig(L, 3);
485 config& vars = side.variables();
486 if(lua_isnoneornil(L, 3)) {
488 variable_access_throw(m, vars).clear(false);
489 } catch(const invalid_variablename_exception&) {
493 variable_access_create v(m, vars);
494 luaW_checkvariable(L, v, 3);
500 std::string register_metatable(lua_State * L)
502 std::ostringstream cmd_out;
504 cmd_out << "Adding getside metatable...\n";
506 luaL_newmetatable(L, Team);
508 static luaL_Reg const callbacks[] {
509 { "__index", &impl_side_get},
510 { "__newindex", &impl_side_set},
511 { "__dir", &impl_side_dir},
512 { "__eq", &impl_side_equal},
513 { "__tostring", &impl_side_tostring},
516 luaL_setfuncs(L, callbacks, 0);
518 lua_pushstring(L, Team);
519 lua_setfield(L, -2, "__metatable");
521 // Create the side variables metatable.
522 cmd_out << "Adding side variables metatable...\n";
524 luaL_newmetatable(L, teamVar);
525 lua_pushcfunction(L, impl_side_variables_get);
526 lua_setfield(L, -2, "__index");
527 lua_pushcfunction(L, impl_side_variables_set);
528 lua_setfield(L, -2, "__newindex");
529 lua_pushstring(L, "side variables");
530 lua_setfield(L, -2, "__metatable");
532 return cmd_out.str();
536 void luaW_pushteam(lua_State *L, team & tm)
538 team** t = static_cast<team**>(lua_newuserdatauv(L, sizeof(team*), 0));
540 luaL_setmetatable(L, Team);
543 team& luaW_checkteam(lua_State* L, int idx)
545 return **static_cast<team **>(luaL_checkudata(L, idx, Team));
548 team& luaW_checkteam(lua_State* L, int idx, game_board& board)
550 if(lua_isinteger(L, idx)) {
551 int side = lua_tointeger(L, idx);
552 if(!board.has_team(side)) {
553 std::string error = "side " + std::to_string(side) + " does not exist";
554 luaL_argerror(L, 1, error.c_str());
557 return board.get_team(side);
559 return **static_cast<team **>(luaL_checkudata(L, idx, Team));
562 team* luaW_toteam(lua_State* L, int idx)
564 if(void* p = luaL_testudata(L, idx, Team)) {
565 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