The Battle for Wesnoth  1.19.7+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_gold", int)
 
 SIDE_SETTER ("carryover_gold", 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 399 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 433 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 389 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 428 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 407 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 451 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 472 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 548 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 536 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/46]

SIDE_GETTER ( "__cfg"  ,
config   
)

Definition at line 377 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [2/46]

SIDE_GETTER ( "base_income"  ,
int   
)

Definition at line 111 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [3/46]

SIDE_GETTER ( "carryover_add"  ,
bool   
)

Definition at line 277 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [4/46]

SIDE_GETTER ( "carryover_bonus"  ,
double   
)

Definition at line 253 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [5/46]

SIDE_GETTER ( "carryover_gold"  ,
int   
)

Definition at line 269 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [6/46]

SIDE_GETTER ( "carryover_percentage"  ,
int   
)

Definition at line 261 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [7/46]

SIDE_GETTER ( "chose_random"  ,
bool   
)

Definition at line 317 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [8/46]

SIDE_GETTER ( "color"  ,
std::string   
)

Definition at line 170 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [9/46]

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() [10/46]

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() [11/46]

SIDE_GETTER ( "expenses"  ,
int   
)

Definition at line 369 of file lua_team.cpp.

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

◆ SIDE_GETTER() [12/46]

SIDE_GETTER ( "faction"  ,
std::string   
)

Definition at line 212 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [13/46]

SIDE_GETTER ( "faction_name"  ,
t_string   
)

Definition at line 216 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [14/46]

SIDE_GETTER ( "flag"  ,
std::string   
)

Definition at line 179 of file lua_team.cpp.

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

◆ SIDE_GETTER() [15/46]

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() [16/46]

SIDE_GETTER ( "fog"  ,
bool   
)

Definition at line 131 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [17/46]

SIDE_GETTER ( "gold"  ,
int   
)

Definition at line 67 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [18/46]

SIDE_GETTER ( "hidden"  ,
bool   
)

Definition at line 147 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [19/46]

SIDE_GETTER ( "is_local"  ,
bool   
)

Definition at line 228 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [20/46]

SIDE_GETTER ( "lost"  ,
bool   
)

Definition at line 285 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [21/46]

SIDE_GETTER ( "net_income"  ,
int   
)

Definition at line 373 of file lua_team.cpp.

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

◆ SIDE_GETTER() [22/46]

SIDE_GETTER ( "num_units"  ,
int   
)

Definition at line 361 of file lua_team.cpp.

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

◆ SIDE_GETTER() [23/46]

SIDE_GETTER ( "num_villages"  ,
int   
)

Definition at line 99 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [24/46]

SIDE_GETTER ( "objectives"  ,
t_string   
)

Definition at line 75 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [25/46]

SIDE_GETTER ( "objectives_changed"  ,
bool   
)

Definition at line 123 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [26/46]

SIDE_GETTER ( "persistent"  ,
bool   
)

Definition at line 293 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [27/46]

SIDE_GETTER ( "recall_cost"  ,
int   
)

Definition at line 103 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [28/46]

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

Definition at line 338 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [29/46]

SIDE_GETTER ( "save_id"  ,
std::string   
)

Definition at line 62 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [30/46]

SIDE_GETTER ( "scroll_to_leader"  ,
bool   
)

Definition at line 155 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [31/46]

SIDE_GETTER ( "share_maps"  ,
bool   
)

Definition at line 309 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [32/46]

SIDE_GETTER ( "share_view"  ,
bool   
)

Definition at line 313 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [33/46]

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() [34/46]

SIDE_GETTER ( "shroud"  ,
bool   
)

Definition at line 139 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [35/46]

SIDE_GETTER ( "shroud_data"  ,
std::string   
)

Definition at line 329 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [36/46]

SIDE_GETTER ( "side"  ,
int   
)

Definition at line 58 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [37/46]

SIDE_GETTER ( "side_name"  ,
t_string   
)

Definition at line 321 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [38/46]

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

◆ SIDE_GETTER() [39/46]

SIDE_GETTER ( "suppress_end_turn_confirmation"  ,
bool   
)

Definition at line 301 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [40/46]

SIDE_GETTER ( "team_name"  ,
std::string   
)

Definition at line 204 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [41/46]

SIDE_GETTER ( "total_income"  ,
int   
)

Definition at line 119 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [42/46]

SIDE_GETTER ( "total_upkeep"  ,
int   
)

Definition at line 365 of file lua_team.cpp.

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

◆ SIDE_GETTER() [43/46]

SIDE_GETTER ( "user_team_name"  ,
t_string   
)

Definition at line 196 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [44/46]

SIDE_GETTER ( "variables"  ,
lua_index_raw   
)

Definition at line 346 of file lua_team.cpp.

References t, and teamVar.

◆ SIDE_GETTER() [45/46]

SIDE_GETTER ( "village_gold"  ,
int   
)

Definition at line 83 of file lua_team.cpp.

References t.

◆ SIDE_GETTER() [46/46]

SIDE_GETTER ( "village_support"  ,
int   
)

Definition at line 91 of file lua_team.cpp.

References t.

◆ SIDE_SETTER() [1/29]

SIDE_SETTER ( "base_income"  ,
int   
)

Definition at line 115 of file lua_team.cpp.

References t.

◆ SIDE_SETTER() [2/29]

SIDE_SETTER ( "carryover_add"  ,
bool   
)

Definition at line 281 of file lua_team.cpp.

References t.

◆ SIDE_SETTER() [3/29]

SIDE_SETTER ( "carryover_bonus"  ,
double   
)

Definition at line 257 of file lua_team.cpp.

References t.

◆ SIDE_SETTER() [4/29]

SIDE_SETTER ( "carryover_gold"  ,
int   
)

Definition at line 273 of file lua_team.cpp.

References t.

◆ SIDE_SETTER() [5/29]

SIDE_SETTER ( "carryover_percentage"  ,
int   
)

Definition at line 265 of file lua_team.cpp.

References t.

◆ SIDE_SETTER() [6/29]

SIDE_SETTER ( "color"  ,
std::string   
)

Definition at line 174 of file lua_team.cpp.

References reinit_flag_for_team(), and t.

◆ SIDE_SETTER() [7/29]

SIDE_SETTER ( "controller"  ,
std::string   
)

Definition at line 224 of file lua_team.cpp.

References t.

◆ SIDE_SETTER() [8/29]

SIDE_SETTER ( "defeat_condition"  ,
std::string   
)

Definition at line 236 of file lua_team.cpp.

References t.

◆ SIDE_SETTER() [9/29]

SIDE_SETTER ( "flag"  ,
std::string   
)

Definition at line 183 of file lua_team.cpp.

References reinit_flag_for_team(), and t.

◆ SIDE_SETTER() [10/29]

SIDE_SETTER ( "flag_icon"  ,
std::string   
)

Definition at line 192 of file lua_team.cpp.

References t.

◆ SIDE_SETTER() [11/29]

SIDE_SETTER ( "fog"  ,
bool   
)

Definition at line 135 of file lua_team.cpp.

References t.

◆ SIDE_SETTER() [12/29]

SIDE_SETTER ( "gold"  ,
int   
)

Definition at line 71 of file lua_team.cpp.

References t.

◆ SIDE_SETTER() [13/29]

SIDE_SETTER ( "hidden"  ,
bool   
)

Definition at line 151 of file lua_team.cpp.

References t.

◆ SIDE_SETTER() [14/29]

SIDE_SETTER ( "lost"  ,
bool   
)

Definition at line 289 of file lua_team.cpp.

References t.

◆ SIDE_SETTER() [15/29]

SIDE_SETTER ( "objectives"  ,
t_string   
)

Definition at line 79 of file lua_team.cpp.

References t.

◆ SIDE_SETTER() [16/29]

SIDE_SETTER ( "objectives_changed"  ,
bool   
)

Definition at line 127 of file lua_team.cpp.

References t.

◆ SIDE_SETTER() [17/29]

SIDE_SETTER ( "persistent"  ,
bool   
)

Definition at line 297 of file lua_team.cpp.

References t.

◆ SIDE_SETTER() [18/29]

SIDE_SETTER ( "recall_cost"  ,
int   
)

Definition at line 107 of file lua_team.cpp.

References t.

◆ SIDE_SETTER() [19/29]

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

Definition at line 342 of file lua_team.cpp.

References t.

◆ SIDE_SETTER() [20/29]

SIDE_SETTER ( "scroll_to_leader"  ,
bool   
)

Definition at line 159 of file lua_team.cpp.

References t.

◆ SIDE_SETTER() [21/29]

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() [22/29]

SIDE_SETTER ( "shroud"  ,
bool   
)

Definition at line 143 of file lua_team.cpp.

References t.

◆ SIDE_SETTER() [23/29]

SIDE_SETTER ( "shroud_data"  ,
std::string   
)

Definition at line 333 of file lua_team.cpp.

References t.

◆ SIDE_SETTER() [24/29]

SIDE_SETTER ( "side_name"  ,
t_string   
)

Definition at line 325 of file lua_team.cpp.

References t.

◆ SIDE_SETTER() [25/29]

SIDE_SETTER ( "suppress_end_turn_confirmation"  ,
bool   
)

Definition at line 305 of file lua_team.cpp.

References t.

◆ SIDE_SETTER() [26/29]

SIDE_SETTER ( "team_name"  ,
std::string   
)

Definition at line 208 of file lua_team.cpp.

References t.

◆ SIDE_SETTER() [27/29]

SIDE_SETTER ( "user_team_name"  ,
t_string   
)

Definition at line 200 of file lua_team.cpp.

References t.

◆ SIDE_SETTER() [28/29]

SIDE_SETTER ( "village_gold"  ,
int   
)

Definition at line 87 of file lua_team.cpp.

References t.

◆ SIDE_SETTER() [29/29]

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().