The Battle for Wesnoth  1.17.0-dev
lua_terrainmap.hpp
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 
15 #pragma once
16 
17 #include <cstddef>
18 #include <string>
19 #include "scripting/lua_common.hpp"
20 #include "map/location.hpp"
21 #include "map/map.hpp"
22 #include "terrain/translation.hpp"
23 #include "terrain/type_data.hpp"
24 
25 struct lua_State;
26 class lua_unit;
27 struct map_location;
28 
29 // Unlike the original gamemap, this offers 'raw' access to the data.
30 // The original gamemap uses terrain type data.
31 class mapgen_gamemap : public gamemap_base {
32 public:
33  explicit mapgen_gamemap(std::string_view data);
34  mapgen_gamemap(int w, int h, terrain_code);
35  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;
36 
37  template<typename F>
38  void for_each_loc(const F& f) const
39  {
40  for (int x = 0; x < total_width(); ++x) {
41  for (int y = 0; y < total_height(); ++y) {
42  f({ x, y , wml_loc()});
43  }
44  }
45  }
46 };
47 
49 
50 bool luaW_isterrainmap(lua_State* L, int index);
51 
53 
55 
57 
60 
63 int intf_on_board(lua_State* L);
65 
66 namespace lua_terrainmap {
67  std::string register_metatables(lua_State *L);
68 }
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:50
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:50
std::string register_metatables(lua_State *L)
Definition: lua_color.cpp:136
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:38
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:80
int total_width() const
Real width of the map, including borders.
Definition: map.hpp:59
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:72
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:62
#define f
gamemap_base & luaW_checkterrainmap(lua_State *L, int index)
int h() const
Effective map height.
Definition: map.hpp:53