30 #define LOG_LUA LOG_STREAM(info, log_scripting_lua) 31 #define ERR_LUA LOG_STREAM(err, log_scripting_lua) 36 using std::string_view;
64 throw "luaW_type_error didn't thow.";
100 if(res.wml_x() >= 0) {
124 , starting_positions_()
167 bool valid = loc.
valid();
214 throw "luaW_type_error didn't throw";
222 template<
typename... T>
260 u->mapgen_gamemap::~mapgen_gamemap();
280 if(strcmp(m,
"special_locations") == 0) {
301 std::string err_msg =
"unknown modifiable property of map: ";
324 if(mode_str ==
"base") {
327 else if(mode_str ==
"overlay") {
353 std::vector<gamemap::overlay_rule> rules;
354 for (
int i = 1, i_end =
lua_rawlen(L, index);
i <= i_end; ++
i)
361 auto& rule = rules.back();
379 if(!terrain.empty()) {
380 rule.terrain_ = terrain[0];
415 bool ignore_special_locations =
false;
416 std::vector<gamemap::overlay_rule> rules;
419 is_odd = luaW_table_get_def<bool>(L, 4,
"is_odd",
false);
420 ignore_special_locations = luaW_table_get_def<bool>(L, 4,
"ignore_special_locations",
false);
440 ignore_special_locations
449 std::ostringstream cmd_out;
451 cmd_out <<
"Adding terrainmamap metatable...\n";
474 cmd_out <<
"Adding terrainmamap2 metatable...\n";
484 return cmd_out.str();
static int intf_mg_terrain_mask(lua_State *L)
Reaplces part of the map.
bool luaW_tableget(lua_State *L, int index, const char *key)
#define lua_isnoneornil(L, n)
LUA_API void lua_createtable(lua_State *L, int narray, int nrec)
#define lua_pushcfunction(L, f)
mapgen_gamemap * luaW_toslocs(lua_State *L, int index)
mapgen_gamemap & luaW_check_slocs(lua_State *L, int index)
static const char maplocationKey[]
int luaW_type_error(lua_State *L, int narg, const char *tname)
LUA_API int lua_rawgeti(lua_State *L, int idx, lua_Integer n)
void lua_slocs_setmetatable(lua_State *L)
std::string to_string() const
static void simplemerge(terrain_code old, terrain_code &t, const terrain_type_data::merge_mode mode)
LUA_API void lua_rawseti(lua_State *L, int idx, lua_Integer n)
#define lua_remove(L, idx)
bool luaW_isterrainmap(lua_State *L, int index)
#define return_string_attrib(name, accessor)
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
int impl_slocs_get(lua_State *L)
t_translation::ter_map tiles_
#define lua_tonumber(L, i)
int h() const
Effective map height.
ter_map read_game_map(std::string_view str, starting_positions &starting_positions, coordinate border_offset)
Reads a gamemap string into a 2D vector.
LUALIB_API void luaL_setmetatable(lua_State *L, const char *tname)
void set_terrain(const map_location &loc, const terrain_code &terrain, const terrain_type_data::merge_mode mode)
map_location luaW_checklocation(lua_State *L, int index)
Converts an optional table or pair of integers to a map location object.
void set_special_location(const std::string &id, const map_location &loc)
terrain_code read_terrain_code(std::string_view str, const ter_layer filler)
Reads a single terrain from a string.
int intf_terainmap_create(lua_State *L)
Create a map.
static std::vector< gamemap::overlay_rule > read_rules_vector(lua_State *L, int index)
LUALIB_API int luaL_argerror(lua_State *L, int arg, const char *extramsg)
#define return_int_attrib(name, accessor)
bool luaW_toboolean(lua_State *L, int n)
int intf_mg_get_tiles_radius(lua_State *L)
map_location special_location(const std::string &id) const
starting_positions starting_positions_
void luaW_pushslocs(lua_State *L, int index)
index the index of the map object.
static int impl_terainmap_collect(lua_State *L)
Destroys a map object before it is collected (__gc metamethod).
static void overlay_impl(const t_translation::ter_map &m1, t_translation::starting_positions &m1_st, const t_translation::ter_map &m2, const t_translation::starting_positions &m2_st, std::function< void(const map_location &, const t_translation::terrain_code &, terrain_type_data::merge_mode, bool)> set_terrain, map_location loc, const std::vector< overlay_rule > &rules, bool is_odd, bool ignore_special_locations)
std::string register_metatables(lua_State *L)
LUALIB_API void * luaL_testudata(lua_State *L, int ud, const char *tname)
static lg::log_domain log_scripting_lua("scripting/lua")
LUA_API void lua_pushnil(lua_State *L)
std::string write_terrain_code(const terrain_code &tcode)
Writes a single terrain code to a string.
Encapsulates the map of the game.
LUALIB_API int luaL_newmetatable(lua_State *L, const char *tname)
LUA_API void * lua_touserdata(lua_State *L, int idx)
static map_location::DIRECTION s
mapgen_gamemap(std::string_view data)
int w() const
Effective map width.
LUA_API void lua_pushvalue(lua_State *L, int idx)
std::size_t index(const std::string &str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
LUA_API int lua_isnumber(lua_State *L, int idx)
static int intf_set_terrain(lua_State *L)
Sets a terrain code.
std::string write_game_map(const ter_map &map, const starting_positions &starting_positions, coordinate border_offset)
Write a gamemap in to a vector string.
mapgen_gamemap * luaW_pushmap(lua_State *L, T &&... params)
LUA_API lua_Unsigned lua_rawlen(lua_State *L, int idx)
bool luaW_getmetafield(lua_State *L, int idx, const char *key)
Like luaL_getmetafield, but returns false if key is an empty string or begins with two underscores...
mapgen_gamemap & luaW_checkterrainmap(lua_State *L, int index)
int total_height() const
Real height of the map, including borders.
mapgen_gamemap * luaW_toterrainmap(lua_State *L, int index)
#define lua_istable(L, n)
std::string_view luaW_tostring(lua_State *L, int index)
void luaW_pushlocation(lua_State *L, const map_location &ml)
Converts a map location object to a Lua table pushed at the top of the stack.
static int impl_terainmap_set(lua_State *L)
Sets some data on a map (__newindex metamethod).
void lua_terrainmap_setmetatable(lua_State *L)
Standard logging facilities (interface).
std::vector< terrain_code > ter_list
int impl_slocs_set(lua_State *L)
bool luaW_isslocs(lua_State *L, int index)
map_location coordinate
Contains an x and y coordinate used for starting positions in maps.
int total_width() const
Real width of the map, including borders.
static int intf_get_terrain(lua_State *L)
Gets a terrain code.
int intf_mg_get_locations(lua_State *L)
LUA_API const char * lua_pushstring(lua_State *L, const char *s)
LUA_API void lua_setfield(lua_State *L, int idx, const char *k)
static const char terrinmapKey[]
ter_list read_list(std::string_view str, const ter_layer filler)
Reads a list of terrains from a string, when reading the.
static int impl_terainmap_get(lua_State *L)
Gets some data on a map (__index metamethod).
#define luaL_checkstring(L, n)