The Battle for Wesnoth  1.17.0-dev
lua_terrainmap.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2018 - 2021
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
17 
18 #include "formatter.hpp"
19 #include "global.hpp"
20 #include "log.hpp"
21 #include "map/location.hpp"
22 #include "map/map.hpp"
23 #include "scripting/lua_common.hpp"
24 #include "scripting/push_check.hpp"
26 #include "resources.hpp"
27 #include "game_board.hpp"
28 #include "play_controller.hpp"
29 
30 #include "lua/lauxlib.h"
31 #include "lua/lua.h"
32 
33 static lg::log_domain log_scripting_lua("scripting/lua");
34 #define LOG_LUA LOG_STREAM(info, log_scripting_lua)
35 #define ERR_LUA LOG_STREAM(err, log_scripting_lua)
36 
37 static const char terrainmapKey[] = "terrain map";
38 static const char maplocationKey[] = "special locations";
39 static const char mapReplaceIfFailedKey[] = "replace_if_failed terrain code";
40 
42  enum {CODE = 1, MODE = 2};
43 }
44 
45 using std::string_view;
46 
47 //////// SPECIAL LOCATION ////////
48 
49 static int impl_slocs_get(lua_State* L)
50 {
52  string_view id = luaL_checkstring(L, 2);
53  auto res = m.special_location(std::string(id));
54  if(res.valid()) {
55  luaW_pushlocation(L, res);
56  } else {
57  //functions with variable return numbers have been causing problem in the past
58  lua_pushnil(L);
59  }
60  return 1;
61 }
62 
63 static int impl_slocs_set(lua_State* L)
64 {
66  string_view id = luaL_checkstring(L, 2);
67  map_location loc = luaW_checklocation(L, 3);
68 
69  m.set_special_location(std::string(id), loc);
70  return 0;
71 }
72 
73 static int impl_slocs_next(lua_State *L)
74 {
76  const t_translation::starting_positions::left_map& left = m.special_locations().left;
77 
78  t_translation::starting_positions::left_const_iterator it;
79  if (lua_isnoneornil(L, 2)) {
80  it = left.begin();
81  }
82  else {
83  it = left.find(luaL_checkstring(L, 2));
84  if (it == left.end()) {
85  return 0;
86  }
87  ++it;
88  }
89  if (it == left.end()) {
90  return 0;
91  }
92  lua_pushstring(L, it->first.c_str());
93  luaW_pushlocation(L, it->second);
94  return 2;
95 }
96 
97 static int impl_slocs_iter(lua_State *L)
98 {
99  lua_settop(L, 1);
100  lua_pushvalue(L, 1);
102  lua_pushvalue(L, 1);
103  lua_pushnil(L);
104  return 3;
105 }
106 
107 //////// MAP ////////
108 
110 {
111  if(s.empty()) {
112  return;
113  }
114  //throws t_translation::error
115  //todo: make read_game_map take a string_view
116  tiles() = t_translation::read_game_map(s, special_locations(), t_translation::coordinate{ 1, 1 });
117 }
118 
120  : gamemap_base(w, h, t)
121 {
122 
123 }
124 
125 // This can produce invalid combinations in rare case
126 // where an overlay doesn't have an independent terrain definition,
127 // or if you set an overlay with no base and merge mode other than OVERLAY.
129 {
130  switch(mode) {
132  new_t = t_translation::terrain_code(old_t.base, new_t.overlay);
133  break;
135  new_t = t_translation::terrain_code(new_t.base, old_t.overlay);
136  break;
138  new_t = t_translation::terrain_code(new_t.base, new_t.overlay);
139  break;
140  }
141 }
142 
143 void mapgen_gamemap::set_terrain(const map_location& loc, const terrain_code & terrain, const terrain_type_data::merge_mode mode, bool)
144 {
145  terrain_code old = get_terrain(loc);
146  terrain_code t = terrain;
147  simplemerge(old, t, mode);
148  tiles().get(loc.x + border_size(), loc.y + border_size()) = t;
149 }
150 
151 struct lua_map_ref {
153  : owned_map(new mapgen_gamemap(w, h, ter))
154  , map_ptr(owned_map.get())
155  {}
156  lua_map_ref(string_view data)
157  : owned_map(new mapgen_gamemap(data))
158  , map_ptr(owned_map.get())
159  {}
161  : map_ptr(&ref)
162  {}
164  return *map_ptr;
165  }
166 private:
167  std::unique_ptr<gamemap_base> owned_map;
168  gamemap_base* map_ptr; // either owned or unowned
169 };
170 
172 {
173  return luaL_testudata(L, index, terrainmapKey) != nullptr || luaL_testudata(L, index, maplocationKey) != nullptr;
174 }
175 
176 
178 {
179  if(luaW_isterrainmap(L, index)) {
180  return &static_cast<lua_map_ref*>(lua_touserdata(L, index))->get_map();
181  }
182  return nullptr;
183 }
184 
186 {
187  if(luaW_isterrainmap(L, index)) {
188  return static_cast<lua_map_ref*>(lua_touserdata(L, index))->get_map();
189  }
190  luaW_type_error(L, index, "terrainmap");
191  throw "luaW_type_error didn't throw";
192 }
193 
194 /**
195  * Create a map.
196  * - Arg 1: string describing the map data.
197  * - or:
198  * - Arg 1: int, width
199  * - Arg 2: int, height
200  * - Arg 3: string, terrain
201 */
203 {
204  if(lua_isnumber(L, 1) && lua_isnumber(L, 2)) {
205  int w = lua_tointeger(L, 1);
206  int h = lua_tointeger(L, 2);
208  new(L) lua_map_ref(w, h, terrain);
209  } else {
210  string_view data_str = luaL_checkstring(L, 1);
211  new(L) lua_map_ref(data_str);
212  }
214  return 1;
215 }
216 
218 {
219  new(L) lua_map_ref(const_cast<gamemap&>(resources::gameboard->map()));
221  return 1;
222 }
223 
224 /**
225  * Destroys a map object before it is collected (__gc metamethod).
226  */
228 {
229  lua_map_ref* m = static_cast<lua_map_ref*>(lua_touserdata(L, 1));
230  m->lua_map_ref::~lua_map_ref();
231  return 0;
232 }
233 
235 {
236  auto t = map.get_terrain(loc);
238 }
239 
241 {
242  auto mode = terrain_type_data::BOTH;
243  bool replace_if_failed = false;
244  string_view t_str;
246  replace_if_failed = true;
248  t_str = luaL_checkstring(L, -1);
251  } else {
252  t_str = luaL_checkstring(L, 3);
253  if(t_str.front() == '^') {
255  } else if(t_str.back() == '^') {
257  }
258  }
259 
260  auto ter = t_translation::read_terrain_code(t_str);
261 
262  if(auto gm = dynamic_cast<gamemap*>(&map)) {
264  bool result = resources::gameboard->change_terrain(loc, ter, mode, replace_if_failed);
265 
266  for(team& t : resources::gameboard->teams()) {
267  t.fix_villages(*gm);
268  }
269 
272  }
273  }
274  } else map.set_terrain(loc, ter, mode, replace_if_failed);
275 }
276 
277 /**
278  * Gets some data on a map (__index metamethod).
279  * - Arg 1: full userdata containing the map.
280  * - Arg 2: string containing the name of the property.
281  * - Ret 1: something containing the attribute.
282  */
284 {
286  map_location loc;
287  if(luaW_tolocation(L, 2, loc)) {
288  luaW_push_terrain(L, tm, loc);
289  return 1;
290  }
291 
292  char const *m = luaL_checkstring(L, 2);
293 
294  // Find the corresponding attribute.
295  return_int_attrib("width", tm.total_width());
296  return_int_attrib("height", tm.total_height());
297  return_int_attrib("playable_width", tm.w());
298  return_int_attrib("playable_height", tm.h());
299  return_int_attrib("border_size", tm.border_size());
300  return_string_attrib("data", tm.to_string());
301 
302  if(strcmp(m, "special_locations") == 0) {
303  new(L) lua_map_ref(tm);
305  return 1;
306  }
307  if(luaW_getglobal(L, "wesnoth", "map", m)) {
308  return 1;
309  }
310  return 0;
311 }
312 
313 /**
314  * Sets some data on a map (__newindex metamethod).
315  * - Arg 1: full userdata containing the map.
316  * - Arg 2: string containing the name of the property.
317  * - Arg 3: something containing the attribute.
318  */
320 {
322  map_location loc;
323  // The extra check that value (arg 3) isn't a number is because without it,
324  // map[4] = 5 would be interpreted as map[{4, 5}] = nil, due to the way
325  // luaW_tolocation modifies the stack if it finds a pair of numbers on it.
326  if(lua_type(L, 3) != LUA_TNUMBER && luaW_tolocation(L, 2, loc)) {
327  impl_merge_terrain(L, tm, loc);
328  return 0;
329  }
330  char const *m = luaL_checkstring(L, 2);
331  std::string err_msg = "unknown modifiable property of map: ";
332  err_msg += m;
333  return luaL_argerror(L, 2, err_msg.c_str());
334 }
335 
336 /*
337 The map iterator, when called with false as its parameter
338 is roughly equivalent to the following Lua function:
339 
340 function map_iter()
341  local map, x, y = wesnoth.current.map, 0, 1
342  return function()
343  if x == map.playable_width then
344  if y == map.playable_height then
345  return nil
346  else
347  x, y = 1, y + 1
348  end
349  else
350  x = x + 1
351  end
352  return x, y, map[{x, y}]
353  end
354 end
355 
356 */
357 
358 template<bool with_border>
360 {
361  // Retrieve the upvalues stored with the function
364  int w = with_border ? tm.total_width() - 1 : tm.w();
365  int h = with_border ? tm.total_height() - 1 : tm.h();
366  int x, y;
367 
368  // Given the previous location, determine the next one to be returned
369  if(prev_loc.wml_x() == w) {
370  if(prev_loc.wml_y() == h) {
371  lua_pushnil(L);
372  return 1;
373  } else {
374  x = with_border ? 0 : 1;
375  y = prev_loc.wml_y() + 1;
376  }
377  } else {
378  x = prev_loc.wml_x() + 1;
379  y = prev_loc.wml_y();
380  }
381 
382  // Assign the upvalue representing the previous location
383  map_location next_loc(x, y, wml_loc{});
384  luaW_pushlocation(L, next_loc);
386 
387  // Return the new location and its terrain code
388  lua_pushinteger(L, x);
389  lua_pushinteger(L, y);
390  luaW_push_terrain(L, tm, next_loc);
391 
392  return 3;
393 }
394 
396 {
397  luaW_checkterrainmap(L, 1);
398  bool with_border = lua_isboolean(L, 2) ? luaW_toboolean(L, 2) : false;
399  lua_settop(L, 1);
400  luaW_pushlocation(L, map_location(with_border ? -1 : 0, 1, wml_loc{}));
401 
402  if(with_border) {
403  lua_pushcclosure(L, impl_terrainmap_iter<true>, 2);
404  } else {
405  lua_pushcclosure(L, impl_terrainmap_iter<false>, 2);
406  }
407  return 1;
408 }
409 
411 {
413  map_location loc = luaW_checklocation(L, 2);
414  bool with_border = luaL_opt(L, luaW_toboolean, 3, false);
415 
416  lua_pushboolean(L, with_border ? tm.on_board_with_border(loc) : tm.on_board(loc));
417  return 1;
418 }
419 
421 {
423  map_location loc = luaW_checklocation(L, 2);
424 
425  lua_pushboolean(L, tm.on_board_with_border(loc) && !tm.on_board(loc));
426  return 1;
427 }
428 
429 static std::vector<gamemap::overlay_rule> read_rules_vector(lua_State *L, int index)
430 {
431  std::vector<gamemap::overlay_rule> rules;
432  for (int i = 1, i_end = lua_rawlen(L, index); i <= i_end; ++i)
433  {
434  lua_rawgeti(L, index, i);
435  if(!lua_istable(L, -1)) {
436  luaL_argerror(L, index, "rules must be a table of tables");
437  }
438  rules.push_back(gamemap::overlay_rule());
439  auto& rule = rules.back();
440  if(luaW_tableget(L, -1, "old")) {
441  rule.old_ = t_translation::read_list(luaW_tostring(L, -1));
442  lua_pop(L, 1);
443  }
444 
445  if(luaW_tableget(L, -1, "new")) {
446  rule.new_ = t_translation::read_list(luaW_tostring(L, -1));
447  lua_pop(L, 1);
448  }
449 
450  if(luaW_tableget(L, -1, "layer")) {
451  auto str = luaW_tostring(L, -1);
452  rule.mode_ = str == "base" ? terrain_type_data::BASE : (str == "overlay" ? terrain_type_data::OVERLAY : terrain_type_data::BOTH);
453  lua_pop(L, 1);
454  }
455 
456  if(luaW_tableget(L, -1, "terrain")) {
458  if(!terrain.empty()) {
459  rule.terrain_ = terrain[0];
460  }
461  lua_pop(L, 1);
462  }
463 
464  if(luaW_tableget(L, -1, "use_old")) {
465  rule.use_old_ = luaW_toboolean(L, -1);
466  lua_pop(L, 1);
467  }
468 
469  if(luaW_tableget(L, -1, "replace_if_failed")) {
470  rule.replace_if_failed_ = luaW_toboolean(L, -1);
471  lua_pop(L, 1);
472  }
473 
474  lua_pop(L, 1);
475  }
476  return rules;
477 }
478 /**
479  * Replaces part of the map.
480  * - Arg 1: map location.
481  * - Arg 2: map data string.
482  * - Arg 3: table for optional named arguments
483  * - is_odd: boolean, if Arg2 has the odd map format (as if it was cut from a odd map location)
484  * - ignore_special_locations: boolean
485  * - rules: table of tables
486 */
488 {
489  gamemap_base& map = luaW_checkterrainmap(L, 1);
490  map_location loc = luaW_checklocation(L, 2);
491 
492  bool is_odd = false;
493  bool ignore_special_locations = false;
494  std::vector<gamemap::overlay_rule> rules;
495 
496  if(lua_istable(L, 4)) {
497  is_odd = luaW_table_get_def(L, 4, "is_odd", false);
498  ignore_special_locations = luaW_table_get_def(L, 4, "ignore_special_locations", false);
499 
500  if(luaW_tableget(L, 4, "rules")) {
501  if(!lua_istable(L, -1)) {
502  return luaL_argerror(L, 4, "rules must be a table");
503  }
504  rules = read_rules_vector(L, -1);
505  lua_pop(L, 1);
506  }
507  }
508 
509  if(lua_isstring(L, 3)) {
510  const std::string t_str = luaL_checkstring(L, 3);
511  std::unique_ptr<gamemap_base> mask;
512  if(dynamic_cast<gamemap*>(&map)) {
513  auto mask_ptr = new gamemap("");
514  mask_ptr->read(t_str, false);
515  mask.reset(mask_ptr);
516  } else {
517  mask.reset(new mapgen_gamemap(t_str));
518  }
519  map.overlay(*mask, loc, rules, is_odd, ignore_special_locations);
520  } else {
521  gamemap_base& mask = luaW_checkterrainmap(L, 3);
522  map.overlay(mask, loc, rules, is_odd, ignore_special_locations);
523  }
524 
526  if(auto gmap = dynamic_cast<gamemap*>(&map)) {
527  for(team& t : resources::gameboard->teams()) {
528  t.fix_villages(*gmap);
529  }
530  }
531  }
532 
535  }
536 
537  return 0;
538 }
539 
541 {
542  auto mode = terrain_type_data::BOTH;
543  if(!lua_isnoneornil(L, 2)) {
544  string_view mode_str = luaL_checkstring(L, 2);
545  if(mode_str == "base") {
547  } else if(mode_str == "overlay") {
549  } else if(mode_str != "both") {
550  return luaL_argerror(L, 2, "must be one of 'base', 'overlay', or 'both'");
551  }
552  }
553 
554  lua_newuserdatauv(L, 0, 2);
555  lua_pushinteger(L, int(mode));
557  lua_pushvalue(L, 1);
560  return 1;
561 }
562 
564 {
565  static const char* mode_strs[] = {"base", "overlay", "both"};
567  string_view t_str = luaL_checkstring(L, -1);
569  int mode = luaL_checkinteger(L, -1);
570  lua_pushfstring(L, "replace_if_failed('%s', '%s')", t_str.data(), mode_strs[mode]);
571  return 1;
572 }
573 
574 namespace lua_terrainmap {
576  {
577  std::ostringstream cmd_out;
578 
579  cmd_out << "Adding terrain map metatable...\n";
580 
583  lua_setfield(L, -2, "__gc");
585  lua_setfield(L, -2, "__index");
587  lua_setfield(L, -2, "__newindex");
589  lua_setfield(L, -2, "__metatable");
590 
593  lua_setfield(L, -2, "__tostring");
595  lua_setfield(L, -2, "__metatable");
596 
597  cmd_out << "Adding special locations metatable...\n";
598 
601  lua_setfield(L, -2, "__index");
603  lua_setfield(L, -2, "__newindex");
605  lua_setfield(L, -2, "__pairs");
607  lua_setfield(L, -2, "__metatable");
608 
609  return cmd_out.str();
610  }
611 }
bool luaW_tableget(lua_State *L, int index, const char *key)
play_controller * controller
Definition: resources.cpp:22
#define lua_isnoneornil(L, n)
Definition: lua.h:379
#define lua_pushcfunction(L, f)
Definition: lua.h:370
static void impl_merge_terrain(lua_State *L, gamemap_base &map, map_location loc)
std::decay_t< T > luaW_table_get_def(lua_State *L, int index, std::string_view k, const T &def)
returns t[k] where k is the table at index index and k is k or def if it is not convertible to the co...
Definition: push_check.hpp:395
gamemap_base & get_map()
bool is_odd(T num)
Definition: math.hpp:36
static void simplemerge(t_translation::terrain_code old_t, t_translation::terrain_code &new_t, const terrain_type_data::merge_mode mode)
location_map & special_locations()
Definition: map.hpp:90
static void luaW_push_terrain(lua_State *L, gamemap_base &map, map_location loc)
LUA_API void lua_settop(lua_State *L, int idx)
Definition: lapi.cpp:173
LUA_API int lua_type(lua_State *L, int idx)
Definition: lapi.cpp:260
static const char maplocationKey[]
int luaW_type_error(lua_State *L, int narg, const char *tname)
static int impl_terrainmap_iter(lua_State *L)
LUA_API void lua_pushboolean(lua_State *L, int b)
Definition: lapi.cpp:581
LUA_API int lua_rawgeti(lua_State *L, int idx, lua_Integer n)
Definition: lapi.cpp:710
static int impl_replace_if_failed_tostring(lua_State *L)
game_display & get_display() override
Get a reference to a display member a derived class uses.
bool luaW_isterrainmap(lua_State *L, int index)
int intf_terrainmap_iter(lua_State *L)
gamemap_base & luaW_checkterrainmap(lua_State *L, int index)
#define return_string_attrib(name, accessor)
Definition: lua_common.hpp:256
static int impl_slocs_next(lua_State *L)
#define lua_tointeger(L, i)
Definition: lua.h:362
int wml_x() const
Definition: location.hpp:153
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
Definition: translation.hpp:50
static int impl_slocs_set(lua_State *L)
#define h
static const char terrainmapKey[]
LUA_API void lua_pushcclosure(lua_State *L, lua_CFunction fn, int n)
Definition: lapi.cpp:555
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)
Definition: lauxlib.cpp:324
lua_map_ref(int w, int h, const t_translation::terrain_code &ter)
map_location luaW_checklocation(lua_State *L, int index)
Converts an optional table or pair of integers to a map location object.
Definition: lua_common.cpp:775
virtual void set_terrain(const map_location &loc, const terrain_code &terrain, const terrain_type_data::merge_mode mode=terrain_type_data::BOTH, bool replace_if_failed=false)=0
Clobbers over the terrain at location &#39;loc&#39;, with the given terrain.
map_location special_location(const std::string &id) const
Definition: map.cpp:312
void set_special_location(const std::string &id, const map_location &loc)
Definition: map.cpp:363
#define lua_pop(L, n)
Definition: lua.h:364
terrain_code read_terrain_code(std::string_view str, const ter_layer filler)
Reads a single terrain from a string.
static std::vector< gamemap::overlay_rule > read_rules_vector(lua_State *L, int index)
gamemap_base * map_ptr
terrain_map & tiles()
Definition: map.hpp:157
#define lua_upvalueindex(i)
Definition: lua.h:45
This class stores all the data for a single &#39;side&#39; (in game nomenclature).
Definition: team.hpp:72
LUALIB_API int luaL_argerror(lua_State *L, int arg, const char *extramsg)
Definition: lauxlib.cpp:175
#define return_int_attrib(name, accessor)
Definition: lua_common.hpp:267
int intf_on_board(lua_State *L)
bool luaW_getglobal(lua_State *L, const std::vector< std::string > &path)
Pushes the value found by following the variadic names (char *), if the value is not nil...
Definition: lua_common.cpp:953
LUA_API int lua_isstring(lua_State *L, int idx)
Definition: lapi.cpp:292
int w() const
Effective map width.
Definition: map.hpp:50
bool luaW_toboolean(lua_State *L, int n)
Definition: lua_common.cpp:972
terrain_code get_terrain(const map_location &loc) const
Looks up terrain at a particular location.
Definition: map.cpp:302
#define luaL_opt(L, f, n, d)
Definition: lauxlib.h:151
LUA_API void * lua_newuserdatauv(lua_State *L, size_t size, int nuvalue)
Definition: lapi.cpp:1311
int wml_y() const
Definition: location.hpp:154
bool on_board_with_border(const map_location &loc) const
Definition: map.cpp:390
game_board * gameboard
Definition: resources.cpp:21
Encapsulates the map of the game.
Definition: map.hpp:171
#define LUA_TNUMBER
Definition: lua.h:68
static int impl_terrainmap_get(lua_State *L)
Gets some data on a map (__index metamethod).
void set_terrain(const map_location &loc, const terrain_code &terrain, const terrain_type_data::merge_mode mode=terrain_type_data::BOTH, bool replace_if_failed=false) override
Clobbers over the terrain at location &#39;loc&#39;, with the given terrain.
int intf_terrain_mask(lua_State *L)
Replaces part of the map.
LUA_API int lua_setiuservalue(lua_State *L, int idx, int n)
Definition: lapi.cpp:941
std::string register_metatables(lua_State *L)
LUALIB_API void * luaL_testudata(lua_State *L, int ud, const char *tname)
Definition: lauxlib.cpp:330
void needs_rebuild(bool b)
Sets whether the screen (map visuals) needs to be rebuilt.
static lg::log_domain log_scripting_lua("scripting/lua")
LUA_API void lua_pushnil(lua_State *L)
Definition: lapi.cpp:473
std::string write_terrain_code(const terrain_code &tcode)
Writes a single terrain code to a string.
Encapsulates the map of the game.
Definition: location.hpp:38
#define lua_isboolean(L, n)
Definition: lua.h:376
int total_width() const
Real width of the map, including borders.
Definition: map.hpp:59
LUALIB_API int luaL_newmetatable(lua_State *L, const char *tname)
Definition: lauxlib.cpp:311
LUA_API void * lua_touserdata(lua_State *L, int idx)
Definition: lapi.cpp:432
std::size_t i
Definition: function.cpp:967
LUALIB_API lua_Integer luaL_checkinteger(lua_State *L, int arg)
Definition: lauxlib.cpp:442
static map_location::DIRECTION s
mapgen_gamemap(std::string_view data)
#define lua_replace(L, idx)
Definition: lua.h:393
CURSOR_TYPE get()
Definition: cursor.cpp:216
gamemap_base * luaW_toterrainmap(lua_State *L, int index)
bool on_board(const map_location &loc) const
Tell if a location is on the map.
Definition: map.cpp:385
bool change_terrain(const map_location &loc, const std::string &t, const std::string &mode, bool replace_if_failed)
Definition: game_board.cpp:325
int w
LUA_API void lua_pushvalue(lua_State *L, int idx)
Definition: lapi.cpp:246
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.
Definition: unicode.cpp:72
LUA_API int lua_isnumber(lua_State *L, int idx)
Definition: lapi.cpp:285
terrain_code & get(int x, int y)
Definition: translation.hpp:90
int total_height() const
Real height of the map, including borders.
Definition: map.hpp:62
LUA_API lua_Unsigned lua_rawlen(lua_State *L, int idx)
Definition: lapi.cpp:402
LUA_API int lua_getiuservalue(lua_State *L, int idx, int n)
Definition: lapi.cpp:768
int intf_on_border(lua_State *L)
double t
Definition: astarsearch.cpp:65
#define lua_istable(L, n)
Definition: lua.h:373
std::string_view luaW_tostring(lua_State *L, int index)
lu_byte left
Definition: lparser.cpp:1226
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.
Definition: lua_common.cpp:715
int intf_terrainmap_create(lua_State *L)
Create a map.
int border_size() const
Size of the map border.
Definition: map.hpp:56
Standard logging facilities (interface).
std::vector< terrain_code > ter_list
Definition: translation.hpp:78
lua_map_ref(string_view data)
LUA_API const char * lua_pushfstring(lua_State *L, const char *fmt,...)
Definition: lapi.cpp:542
static int impl_terrainmap_set(lua_State *L)
Sets some data on a map (__newindex metamethod).
static int impl_slocs_get(lua_State *L)
static const char mapReplaceIfFailedKey[]
void overlay(const gamemap_base &m, map_location loc, const std::vector< overlay_rule > &rules=std::vector< overlay_rule >(), bool is_odd=false, bool ignore_special_locations=false)
Overlays another map onto this one at the given position.
Definition: map.cpp:215
lua_map_ref(gamemap_base &ref)
int intf_replace_if_failed(lua_State *L)
int h() const
Effective map height.
Definition: map.hpp:53
LUA_API void lua_pushinteger(lua_State *L, lua_Integer n)
Definition: lapi.cpp:489
int intf_terrainmap_get(lua_State *L)
LUA_API const char * lua_pushstring(lua_State *L, const char *s)
Definition: lapi.cpp:514
LUA_API void lua_setfield(lua_State *L, int idx, const char *k)
Definition: lapi.cpp:837
static int impl_terrainmap_collect(lua_State *L)
Destroys a map object before it is collected (__gc metamethod).
static int impl_slocs_iter(lua_State *L)
bool luaW_tolocation(lua_State *L, int index, map_location &loc)
Converts an optional table or pair of integers to a map location object.
Definition: lua_common.cpp:726
std::unique_ptr< gamemap_base > owned_map
ter_list read_list(std::string_view str, const ter_layer filler)
Reads a list of terrains from a string, when reading the.
#define luaL_checkstring(L, n)
Definition: lauxlib.h:138
std::string to_string() const
Definition: map.cpp:470