The Battle for Wesnoth  1.19.5+dev
Classes | Namespaces | Macros | Functions | Variables
lua_team.cpp File Reference
#include "scripting/lua_team.hpp"
#include "scripting/lua_attributes.hpp"
#include "scripting/lua_common.hpp"
#include "scripting/push_check.hpp"
#include "scripting/game_lua_kernel.hpp"
#include "team.hpp"
#include "resources.hpp"
#include "game_board.hpp"
#include "game_display.hpp"
#include "map/map.hpp"
#include <string>
Include dependency graph for lua_team.cpp:

Go to the source code of this file.

Classes

struct  lua_object_traits< team >
 

Namespaces

 lua_team
 This namespace contains bindings for lua to hold a pointer to a team, and to access and modify it.
 

Macros

#define SIDE_GETTER(name, type)   LATTR_GETTER(name, type, team, t)
 
#define SIDE_SETTER(name, type)   LATTR_SETTER(name, type, team, t)
 

Functions

 SIDE_GETTER ("side", int)
 
 SIDE_GETTER ("save_id", std::string)
 
 SIDE_GETTER ("gold", int)
 
 SIDE_SETTER ("gold", int)
 
 SIDE_GETTER ("objectives", t_string)
 
 SIDE_SETTER ("objectives", t_string)
 
 SIDE_GETTER ("village_gold", int)
 
 SIDE_SETTER ("village_gold", int)
 
 SIDE_GETTER ("village_support", int)
 
 SIDE_SETTER ("village_support", int)
 
 SIDE_GETTER ("num_villages", int)
 
 SIDE_GETTER ("recall_cost", int)
 
 SIDE_SETTER ("recall_cost", int)
 
 SIDE_GETTER ("base_income", int)
 
 SIDE_SETTER ("base_income", int)
 
 SIDE_GETTER ("total_income", int)
 
 SIDE_GETTER ("objectives_changed", bool)
 
 SIDE_SETTER ("objectives_changed", bool)
 
 SIDE_GETTER ("fog", bool)
 
 SIDE_SETTER ("fog", bool)
 
 SIDE_GETTER ("shroud", bool)
 
 SIDE_SETTER ("shroud", bool)
 
 SIDE_GETTER ("hidden", bool)
 
 SIDE_SETTER ("hidden", bool)
 
 SIDE_GETTER ("scroll_to_leader", bool)
 
 SIDE_SETTER ("scroll_to_leader", bool)
 
static void reinit_flag_for_team (lua_State *L, const team &t)
 
 SIDE_GETTER ("color", std::string)
 
 SIDE_SETTER ("color", std::string)
 
 SIDE_GETTER ("flag", std::string)
 
 SIDE_SETTER ("flag", std::string)
 
 SIDE_GETTER ("flag_icon", std::string)
 
 SIDE_SETTER ("flag_icon", std::string)
 
 SIDE_GETTER ("user_team_name", t_string)
 
 SIDE_SETTER ("user_team_name", t_string)
 
 SIDE_GETTER ("team_name", std::string)
 
 SIDE_SETTER ("team_name", std::string)
 
 SIDE_GETTER ("faction", std::string)
 
 SIDE_GETTER ("faction_name", t_string)
 
 SIDE_GETTER ("controller", std::string)
 
 SIDE_SETTER ("controller", std::string)
 
 SIDE_GETTER ("is_local", bool)
 
 SIDE_GETTER ("defeat_condition", std::string)
 
 SIDE_SETTER ("defeat_condition", std::string)
 
 SIDE_GETTER ("share_vision", std::string)
 
 SIDE_SETTER ("share_vision", std::string)
 
 SIDE_GETTER ("carryover_bonus", double)
 
 SIDE_SETTER ("carryover_bonus", double)
 
 SIDE_GETTER ("carryover_percentage", int)
 
 SIDE_SETTER ("carryover_percentage", int)
 
 SIDE_GETTER ("carryover_add", bool)
 
 SIDE_SETTER ("carryover_add", bool)
 
 SIDE_GETTER ("lost", bool)
 
 SIDE_SETTER ("lost", bool)
 
 SIDE_GETTER ("persistent", bool)
 
 SIDE_SETTER ("persistent", bool)
 
 SIDE_GETTER ("suppress_end_turn_confirmation", bool)
 
 SIDE_SETTER ("suppress_end_turn_confirmation", bool)
 
 SIDE_GETTER ("share_maps", bool)
 
 SIDE_GETTER ("share_view", bool)
 
 SIDE_GETTER ("chose_random", bool)
 
 SIDE_GETTER ("side_name", t_string)
 
 SIDE_SETTER ("side_name", t_string)
 
 SIDE_GETTER ("shroud_data", std::string)
 
 SIDE_SETTER ("shroud_data", std::string)
 
 SIDE_GETTER ("recruit", std::set< std::string >)
 
 SIDE_SETTER ("recruit", std::set< std::string >)
 
 SIDE_GETTER ("variables", lua_index_raw)
 
 SIDE_GETTER ("starting_location", utils::optional< map_location >)
 
 SIDE_GETTER ("num_units", int)
 
 SIDE_GETTER ("total_upkeep", int)
 
 SIDE_GETTER ("expenses", int)
 
 SIDE_GETTER ("net_income", int)
 
 SIDE_GETTER ("__cfg", config)
 
static int impl_side_get (lua_State *L)
 Gets some data on a side (__index metamethod). More...
 
static int impl_side_dir (lua_State *L)
 Gets a list of data on a side (__dir metamethod). More...
 
static int impl_side_tostring (lua_State *L)
 Turns a lua proxy side to string. More...
 
static int impl_side_set (lua_State *L)
 Sets some data on a side (__newindex metamethod). More...
 
static int impl_side_equal (lua_State *L)
 
static int impl_side_variables_get (lua_State *L)
 Gets the variable of a side (__index metamethod). More...
 
static int impl_side_variables_set (lua_State *L)
 Sets the variable of a side (__newindex metamethod). More...
 
std::string lua_team::register_metatable (lua_State *L)
 
void luaW_pushteam (lua_State *L, team &tm)
 Create a full userdata containing a pointer to the team. More...
 
teamluaW_checkteam (lua_State *L, int idx)
 Test if the top stack element is a team, and if not, error. More...
 
teamluaW_checkteam (lua_State *L, int idx, game_board &board)
 Get a team either from a direct userdata or from a side number. More...
 
teamluaW_toteam (lua_State *L, int idx)
 Test if the top stack element is a team, and if so, return it. More...
 

Variables

static const char * Team = "side"
 Implementation for a lua reference to a team, used by the wesnoth in-game sides table. More...
 
static const char teamVar [] = "side variables"
 
luaW_Registry sideReg {"wesnoth", "sides", Team}
 

Macro Definition Documentation

◆ SIDE_GETTER

#define SIDE_GETTER (   name,
  type 
)    LATTR_GETTER(name, type, team, t)

Definition at line 47 of file lua_team.cpp.

◆ SIDE_SETTER

#define SIDE_SETTER (   name,
  type 
)    LATTR_SETTER(name, type, team, t)

Definition at line 48 of file lua_team.cpp.

Function Documentation

◆ impl_side_dir()

static int impl_side_dir ( lua_State *  L)
static

Gets a list of data on a side (__dir metamethod).

  • Arg 1: full userdata containing the team.
  • Ret 1: a list of attributes.

Definition at line 391 of file lua_team.cpp.

References luaW_Registry::dir(), and sideReg.

◆ impl_side_equal()

static int impl_side_equal ( lua_State *  L)
static

Definition at line 425 of file lua_team.cpp.

◆ impl_side_get()

static int impl_side_get ( lua_State *  L)
static

Gets some data on a side (__index metamethod).

  • Arg 1: full userdata containing the team.
  • Arg 2: string containing the name of the property.
  • Ret 1: something containing the attribute.

Definition at line 381 of file lua_team.cpp.

References luaW_Registry::get(), and sideReg.

◆ impl_side_set()

static int impl_side_set ( lua_State *  L)
static

Sets some data on a side (__newindex metamethod).

  • Arg 1: full userdata containing the team.
  • Arg 2: string containing the name of the property.
  • Arg 3: something containing the attribute.

Definition at line 420 of file lua_team.cpp.

◆ impl_side_tostring()

static int impl_side_tostring ( lua_State *  L)
static

Turns a lua proxy side to string.

(__tostring metamethod)

Definition at line 399 of file lua_team.cpp.

References luaW_checkteam(), team::side(), and team::side_name().

◆ impl_side_variables_get()

static int impl_side_variables_get ( lua_State *  L)
static

Gets the variable of a side (__index metamethod).

  • Arg 1: table containing the userdata containing the side id.
  • Arg 2: string containing the name of the status.
  • Ret 1: boolean.

Definition at line 443 of file lua_team.cpp.

◆ impl_side_variables_set()

static int impl_side_variables_set ( lua_State *  L)
static

Sets the variable of a side (__newindex metamethod).

  • Arg 1: table containing the userdata containing the side id.
  • Arg 2: string containing the name of the status.
  • Arg 3: scalar.

Definition at line 464 of file lua_team.cpp.

◆ luaW_checkteam() [1/2]

team& luaW_checkteam ( lua_State *  L,
int  idx 
)

◆ luaW_checkteam() [2/2]

team& luaW_checkteam ( lua_State *  L,
int  idx,
game_board board 
)

Get a team either from a direct userdata or from a side number.

Definition at line 540 of file lua_team.cpp.

◆ luaW_pushteam()

void luaW_pushteam ( lua_State *  L,
team tm 
)

Create a full userdata containing a pointer to the team.

Definition at line 528 of file lua_team.cpp.

Referenced by game_lua_kernel::intf_get_side(), game_lua_kernel::intf_get_sides(), luaW_pushfaivariant(), and game_lua_kernel::run_filter().

◆ luaW_toteam()

team* luaW_toteam ( lua_State *  L,
int  idx 
)

◆ reinit_flag_for_team()

static void reinit_flag_for_team ( lua_State *  L,
const team t 
)
static

Definition at line 163 of file lua_team.cpp.

References t.

Referenced by SIDE_SETTER().

◆ SIDE_GETTER() [1/45]

SIDE_GETTER ( "__cfg"  ,
config   
)

Definition at line 369 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [2/45]

SIDE_GETTER ( "base_income"  ,
int   
)

Definition at line 111 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [3/45]

SIDE_GETTER ( "carryover_add"  ,
bool   
)

Definition at line 269 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [4/45]

SIDE_GETTER ( "carryover_bonus"  ,
double   
)

Definition at line 253 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [5/45]

SIDE_GETTER ( "carryover_percentage"  ,
int   
)

Definition at line 261 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [6/45]

SIDE_GETTER ( "chose_random"  ,
bool   
)

Definition at line 309 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [7/45]

SIDE_GETTER ( "color"  ,
std::string   
)

Definition at line 170 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [8/45]

SIDE_GETTER ( "controller"  ,
std::string   
)

Definition at line 220 of file lua_team.cpp.

References string_enums::enum_base< Definition >::get_string(), and t.

◆ SIDE_GETTER() [9/45]

SIDE_GETTER ( "defeat_condition"  ,
std::string   
)

Definition at line 232 of file lua_team.cpp.

References string_enums::enum_base< Definition >::get_string(), and t.

◆ SIDE_GETTER() [10/45]

SIDE_GETTER ( "expenses"  ,
int   
)

Definition at line 361 of file lua_team.cpp.

References team_data::expenses, resources::gameboard, and t.

◆ SIDE_GETTER() [11/45]

SIDE_GETTER ( "faction"  ,
std::string   
)

Definition at line 212 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [12/45]

SIDE_GETTER ( "faction_name"  ,
t_string   
)

Definition at line 216 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [13/45]

SIDE_GETTER ( "flag"  ,
std::string   
)

Definition at line 179 of file lua_team.cpp.

References game_config::images::flag, and t.

◆ SIDE_GETTER() [14/45]

SIDE_GETTER ( "flag_icon"  ,
std::string   
)

Definition at line 188 of file lua_team.cpp.

References game_config::images::flag_icon, and t.

◆ SIDE_GETTER() [15/45]

SIDE_GETTER ( "fog"  ,
bool   
)

Definition at line 131 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [16/45]

SIDE_GETTER ( "gold"  ,
int   
)

Definition at line 67 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [17/45]

SIDE_GETTER ( "hidden"  ,
bool   
)

Definition at line 147 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [18/45]

SIDE_GETTER ( "is_local"  ,
bool   
)

Definition at line 228 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [19/45]

SIDE_GETTER ( "lost"  ,
bool   
)

Definition at line 277 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [20/45]

SIDE_GETTER ( "net_income"  ,
int   
)

Definition at line 365 of file lua_team.cpp.

References resources::gameboard, team_data::net_income, and t.

◆ SIDE_GETTER() [21/45]

SIDE_GETTER ( "num_units"  ,
int   
)

Definition at line 353 of file lua_team.cpp.

References resources::gameboard, t, and team_data::units.

◆ SIDE_GETTER() [22/45]

SIDE_GETTER ( "num_villages"  ,
int   
)

Definition at line 99 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [23/45]

SIDE_GETTER ( "objectives"  ,
t_string   
)

Definition at line 75 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [24/45]

SIDE_GETTER ( "objectives_changed"  ,
bool   
)

Definition at line 123 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [25/45]

SIDE_GETTER ( "persistent"  ,
bool   
)

Definition at line 285 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [26/45]

SIDE_GETTER ( "recall_cost"  ,
int   
)

Definition at line 103 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [27/45]

SIDE_GETTER ( "recruit"  ,
std::set< std::string >   
)

Definition at line 330 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [28/45]

SIDE_GETTER ( "save_id"  ,
std::string   
)

Definition at line 62 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [29/45]

SIDE_GETTER ( "scroll_to_leader"  ,
bool   
)

Definition at line 155 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [30/45]

SIDE_GETTER ( "share_maps"  ,
bool   
)

Definition at line 301 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [31/45]

SIDE_GETTER ( "share_view"  ,
bool   
)

Definition at line 305 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [32/45]

SIDE_GETTER ( "share_vision"  ,
std::string   
)

Definition at line 240 of file lua_team.cpp.

References string_enums::enum_base< Definition >::get_string(), and t.

◆ SIDE_GETTER() [33/45]

SIDE_GETTER ( "shroud"  ,
bool   
)

Definition at line 139 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [34/45]

SIDE_GETTER ( "shroud_data"  ,
std::string   
)

Definition at line 321 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [35/45]

SIDE_GETTER ( "side"  ,
int   
)

Definition at line 58 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [36/45]

SIDE_GETTER ( "side_name"  ,
t_string   
)

Definition at line 313 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [37/45]

SIDE_GETTER ( "starting_location"  ,
utils::optional< map_location  
)

◆ SIDE_GETTER() [38/45]

SIDE_GETTER ( "suppress_end_turn_confirmation"  ,
bool   
)

Definition at line 293 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [39/45]

SIDE_GETTER ( "team_name"  ,
std::string   
)

Definition at line 204 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [40/45]

SIDE_GETTER ( "total_income"  ,
int   
)

Definition at line 119 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [41/45]

SIDE_GETTER ( "total_upkeep"  ,
int   
)

Definition at line 357 of file lua_team.cpp.

References resources::gameboard, t, and team_data::upkeep.

◆ SIDE_GETTER() [42/45]

SIDE_GETTER ( "user_team_name"  ,
t_string   
)

Definition at line 196 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [43/45]

SIDE_GETTER ( "variables"  ,
lua_index_raw   
)

Definition at line 338 of file lua_team.cpp.

References t, and teamVar.

◆ SIDE_GETTER() [44/45]

SIDE_GETTER ( "village_gold"  ,
int   
)

Definition at line 83 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [45/45]

SIDE_GETTER ( "village_support"  ,
int   
)

Definition at line 91 of file lua_team.cpp.

References t.

◆ SIDE_SETTER() [1/28]

SIDE_SETTER ( "base_income"  ,
int   
)

Definition at line 115 of file lua_team.cpp.

References t.

◆ SIDE_SETTER() [2/28]

SIDE_SETTER ( "carryover_add"  ,
bool   
)

Definition at line 273 of file lua_team.cpp.

References t.

◆ SIDE_SETTER() [3/28]

SIDE_SETTER ( "carryover_bonus"  ,
double   
)

Definition at line 257 of file lua_team.cpp.

References t.

◆ SIDE_SETTER() [4/28]

SIDE_SETTER ( "carryover_percentage"  ,
int   
)

Definition at line 265 of file lua_team.cpp.

References t.

◆ SIDE_SETTER() [5/28]

SIDE_SETTER ( "color"  ,
std::string   
)

Definition at line 174 of file lua_team.cpp.

References reinit_flag_for_team(), and t.

◆ SIDE_SETTER() [6/28]

SIDE_SETTER ( "controller"  ,
std::string   
)

Definition at line 224 of file lua_team.cpp.

References t.

◆ SIDE_SETTER() [7/28]

SIDE_SETTER ( "defeat_condition"  ,
std::string   
)

Definition at line 236 of file lua_team.cpp.

References t.

◆ SIDE_SETTER() [8/28]

SIDE_SETTER ( "flag"  ,
std::string   
)

Definition at line 183 of file lua_team.cpp.

References reinit_flag_for_team(), and t.

◆ SIDE_SETTER() [9/28]

SIDE_SETTER ( "flag_icon"  ,
std::string   
)

Definition at line 192 of file lua_team.cpp.

References t.

◆ SIDE_SETTER() [10/28]

SIDE_SETTER ( "fog"  ,
bool   
)

Definition at line 135 of file lua_team.cpp.

References t.

◆ SIDE_SETTER() [11/28]

SIDE_SETTER ( "gold"  ,
int   
)

Definition at line 71 of file lua_team.cpp.

References t.

◆ SIDE_SETTER() [12/28]

SIDE_SETTER ( "hidden"  ,
bool   
)

Definition at line 151 of file lua_team.cpp.

References t.

◆ SIDE_SETTER() [13/28]

SIDE_SETTER ( "lost"  ,
bool   
)

Definition at line 281 of file lua_team.cpp.

References t.

◆ SIDE_SETTER() [14/28]

SIDE_SETTER ( "objectives"  ,
t_string   
)

Definition at line 79 of file lua_team.cpp.

References t.

◆ SIDE_SETTER() [15/28]

SIDE_SETTER ( "objectives_changed"  ,
bool   
)

Definition at line 127 of file lua_team.cpp.

References t.

◆ SIDE_SETTER() [16/28]

SIDE_SETTER ( "persistent"  ,
bool   
)

Definition at line 289 of file lua_team.cpp.

References t.

◆ SIDE_SETTER() [17/28]

SIDE_SETTER ( "recall_cost"  ,
int   
)

Definition at line 107 of file lua_team.cpp.

References t.

◆ SIDE_SETTER() [18/28]

SIDE_SETTER ( "recruit"  ,
std::set< std::string >   
)

Definition at line 334 of file lua_team.cpp.

References t.

◆ SIDE_SETTER() [19/28]

SIDE_SETTER ( "scroll_to_leader"  ,
bool   
)

Definition at line 159 of file lua_team.cpp.

References t.

◆ SIDE_SETTER() [20/28]

SIDE_SETTER ( "share_vision"  ,
std::string   
)

Definition at line 244 of file lua_team.cpp.

References string_enums::enum_base< Definition >::get_enum(), and t.

◆ SIDE_SETTER() [21/28]

SIDE_SETTER ( "shroud"  ,
bool   
)

Definition at line 143 of file lua_team.cpp.

References t.

◆ SIDE_SETTER() [22/28]

SIDE_SETTER ( "shroud_data"  ,
std::string   
)

Definition at line 325 of file lua_team.cpp.

References t.

◆ SIDE_SETTER() [23/28]

SIDE_SETTER ( "side_name"  ,
t_string   
)

Definition at line 317 of file lua_team.cpp.

References t.

◆ SIDE_SETTER() [24/28]

SIDE_SETTER ( "suppress_end_turn_confirmation"  ,
bool   
)

Definition at line 297 of file lua_team.cpp.

References t.

◆ SIDE_SETTER() [25/28]

SIDE_SETTER ( "team_name"  ,
std::string   
)

Definition at line 208 of file lua_team.cpp.

References t.

◆ SIDE_SETTER() [26/28]

SIDE_SETTER ( "user_team_name"  ,
t_string   
)

Definition at line 200 of file lua_team.cpp.

References t.

◆ SIDE_SETTER() [27/28]

SIDE_SETTER ( "village_gold"  ,
int   
)

Definition at line 87 of file lua_team.cpp.

References t.

◆ SIDE_SETTER() [28/28]

SIDE_SETTER ( "village_support"  ,
int   
)

Definition at line 95 of file lua_team.cpp.

References t.

Variable Documentation

◆ sideReg

luaW_Registry sideReg {"wesnoth", "sides", Team}

Definition at line 49 of file lua_team.cpp.

Referenced by impl_side_dir(), and impl_side_get().

◆ Team

const char* Team = "side"
static

Implementation for a lua reference to a team, used by the wesnoth in-game sides table.

(The userdata has type team** because lua holds only a pointer to a team, not a full-size team. If it were a full object then we would cast to type team *, since checkudata returns a pointer to the type corresponding to the sizeof expr used when we allocated the userdata.)

Definition at line 44 of file lua_team.cpp.

◆ teamVar

const char teamVar[] = "side variables"
static

Definition at line 45 of file lua_team.cpp.

Referenced by SIDE_GETTER().