The Battle for Wesnoth  1.15.12+dev
lua_terrainmap.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2018 the Battle for Wesnoth Project https://www.wesnoth.org/
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY.
10 
11  See the COPYING file for more details.
12 */
13 
14 #pragma once
15 
16 #include <cstddef>
17 #include <string>
18 #include "scripting/lua_common.hpp"
19 #include "map/location.hpp"
20 #include "map/map.hpp"
21 #include "terrain/translation.hpp"
22 #include "terrain/type_data.hpp"
23 
24 struct lua_State;
25 class lua_unit;
26 struct map_location;
27 
28 // Unlike the original gamemap, this offers 'raw' access to the data.
29 // The original gamemap uses terrain type data.
30 class mapgen_gamemap : public gamemap_base {
31 public:
32  explicit mapgen_gamemap(std::string_view data);
33  mapgen_gamemap(int w, int h, terrain_code);
34  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;
35 
36  template<typename F>
37  void for_each_loc(const F& f) const
38  {
39  for (int x = 0; x < total_width(); ++x) {
40  for (int y = 0; y < total_height(); ++y) {
41  f({ x, y , wml_loc()});
42  }
43  }
44  }
45 };
46 
48 
49 bool luaW_isterrainmap(lua_State* L, int index);
50 
52 
54 
56 
59 
62 int intf_on_board(lua_State* L);
64 
65 namespace lua_terrainmap {
66  std::string register_metatables(lua_State *L);
67 }
int intf_terrainmap_create(lua_State *L)
Create a map.
void lua_terrainmap_setmetatable(lua_State *L)
int intf_on_board(lua_State *L)
int intf_replace_if_failed(lua_State *L)
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
Definition: translation.hpp:49
gamemap_base * luaW_toterrainmap(lua_State *L, int index)
bool luaW_isterrainmap(lua_State *L, int index)
int w() const
Effective map width.
Definition: map.hpp:49
std::string register_metatables(lua_State *L)
Definition: lua_color.cpp:135
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.
void for_each_loc(const F &f) const
int intf_terrainmap_iter(lua_State *L)
int intf_on_border(lua_State *L)
Encapsulates the map of the game.
Definition: location.hpp:37
int intf_terrainmap_get(lua_State *L)
Storage for a unit, either owned by the Lua code (ptr != 0), a local variable unit (c_ptr != 0)...
Definition: lua_unit.hpp:79
int total_width() const
Real width of the map, including borders.
Definition: map.hpp:58
mapgen_gamemap(std::string_view data)
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:71
int intf_terrain_mask(lua_State *L)
Replaces part of the map.
int total_height() const
Real height of the map, including borders.
Definition: map.hpp:61
#define f
gamemap_base & luaW_checkterrainmap(lua_State *L, int index)
int h() const
Effective map height.
Definition: map.hpp:52