36 #define UNIT_TYPE_GETTER(name, type) LATTR_GETTER(name, type, unit_type, ut)
37 #define UNIT_TYPE_VALID(name) LATTR_VALID(name, unit_type, ut)
48 return ut.type_name();
72 return ut.big_profile();
76 return ut.small_profile();
80 return ut.hitpoints();
88 return ut.experience_needed();
100 return ut.recall_cost();
104 return ut.advances_to();
108 return ut.advances_from();
118 for (
const config& trait : ut.possible_traits()) {
119 traits.emplace(trait[
"id"], trait);
125 return ut.get_ability_list();
135 return ut.variation_id().empty();
169 lua_pushboolean(L, &ut1 == ut2);
171 lua_pushboolean(L,
false);
177 std::vector<std::string> keys;
179 keys = base->variations();
181 keys.push_back(
"male");
184 keys.push_back(
"female");
189 keys.push_back(
p.first);
198 std::string
id = luaL_checkstring(L, 2);
201 if(
id ==
"male" ||
id ==
"female") {
220 lua_pushstring(L,
"unit_types table is read-only");
235 if(lua_isnoneornil(L, 2)) {
238 lua_pushstring(L,
"male");
242 lua_pushstring(L,
"female");
249 const std::string
id = luaL_checkstring(L, 2);
252 lua_pushstring(L,
"female");
255 }
else if(
id ==
"male" ||
id ==
"female") {
270 lua_pushlstring(L, it->first.c_str(), it->first.size());
281 lua_pushvalue(L, -2);
292 std::ostringstream str;
294 str <<
"unit type: <" << ut.
id() <<
'>';
306 lua_setfield(L, -2,
"__index");
308 lua_setfield(L, -2,
"__dir");
310 lua_setfield(L, -2,
"__tostring");
312 lua_setfield(L, -2,
"__eq");
314 lua_setfield(L, -2,
"__metatable");
316 return "Adding unit type metatable...\n";
321 lua_getglobal(L,
"wesnoth");
325 lua_setfield(L, -2,
"__index");
327 lua_setfield(L, -2,
"__dir");
329 lua_setfield(L, -2,
"__newindex");
331 lua_setfield(L, -2,
"__len");
333 lua_setfield(L, -2,
"__pairs");
335 lua_setfield(L, -2,
"__metatable");
336 lua_setmetatable(L, -2);
337 lua_setfield(L, -2,
"unit_types");
340 return "Adding unit_types table...\n";
352 if(
void*
p = luaL_testudata(L, idx,
UnitType)) {
A config object defines a single node in a WML file, with access to child nodes.
Container associating units to locations.
unit_iterator find(std::size_t id)
const unit_type * find(const std::string &key, unit_type::BUILD_STATUS status=unit_type::FULL) const
Finds a unit_type by its id() and makes sure it is built to the specified level.
void build_unit_type(const unit_type &ut, unit_type::BUILD_STATUS status) const
Makes sure the provided unit_type is built to the specified level.
const unit_type_map & types() const
A single unit type that the player may recruit.
const unit_type & get_gender_unit_type(const std::string &gender) const
Returns a gendered variant of this unit_type.
const std::string & id() const
The id for this unit_type.
const unit_type & get_variation(const std::string &id) const
const variations_map & variation_types() const
bool has_gender_variation(const unit_race::GENDER gender) const
void push_unit_attacks_table(lua_State *L, int idx)
static int impl_unit_type_lookup(lua_State *L)
static int impl_unit_type_tostring(lua_State *L)
Turns a lua proxy unit type to string.
std::map< std::string, config > traits_map
static int impl_unit_type_next(lua_State *L)
#define UNIT_TYPE_VALID(name)
static int impl_unit_type_dir(lua_State *L)
Gets a list of data on a unit type (__dir metamethod).
const unit_type * luaW_tounittype(lua_State *L, int idx)
Test if a stack element is a unit type, and return it if so.
static int impl_unit_type_new(lua_State *L)
static int impl_unit_type_get(lua_State *L)
Gets some data on a unit type (__index metamethod).
static int impl_unit_type_equal(lua_State *L)
const unit_type & luaW_checkunittype(lua_State *L, int idx)
Test if a stack element is a unit type, and return it if so.
static const char UnitType[]
Implementation for a lua reference to a unit_type.
#define UNIT_TYPE_GETTER(name, type)
static int impl_unit_type_count(lua_State *L)
static int impl_unit_type_list(lua_State *L)
void luaW_pushunittype(lua_State *L, const unit_type &ut)
Create a lua object containing a reference to a unittype, and a metatable to access the properties.
static const char UnitTypeTable[]
luaW_Registry unitTypeReg
static int impl_unit_type_pairs(lua_State *L)
This namespace contains bindings for lua to hold a reference to a unit type and access its stats.
std::string register_metatable(lua_State *L)
std::string register_table(lua_State *L)
void lua_push(lua_State *L, const T &val)
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 const unit_type & get(lua_State *L, int n)
static std::string get_string(enum_type key)
Converts a enum to its string equivalent.
static map_location::direction n
unit_type_data unit_types