The Battle for Wesnoth  1.19.5+dev
lua_terrainmap.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2018 - 2024
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 <string>
18 #include "map/location.hpp"
19 #include "map/map.hpp"
20 #include "terrain/type_data.hpp"
21 
22 struct lua_State;
23 
24 // Unlike the original gamemap, this offers 'raw' access to the data.
25 // The original gamemap uses terrain type data.
26 class mapgen_gamemap : public gamemap_base {
27 public:
28  explicit mapgen_gamemap(std::string_view data);
29  mapgen_gamemap(int w, int h, terrain_code);
30  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;
31 
32  template<typename F>
33  void for_each_loc(const F& f) const
34  {
35  for (int x = 0; x < total_width(); ++x) {
36  for (int y = 0; y < total_height(); ++y) {
37  f({ x, y , wml_loc()});
38  }
39  }
40  }
41 };
42 
43 int intf_terrain_mask(lua_State *L);
44 
45 bool luaW_isterrainmap(lua_State* L, int index);
46 
47 gamemap_base* luaW_toterrainmap(lua_State *L, int index);
48 
49 gamemap_base& luaW_checkterrainmap(lua_State *L, int index);
50 
51 void lua_terrainmap_setmetatable(lua_State *L);
52 
53 int intf_terrainmap_create(lua_State *L);
54 int intf_terrainmap_get(lua_State *L);
55 
56 int intf_replace_if_failed(lua_State* L);
57 int intf_terrainmap_iter(lua_State* L);
58 int intf_on_board(lua_State* L);
59 int intf_on_border(lua_State* L);
60 
61 namespace lua_terrainmap {
62  std::string register_metatables(lua_State *L);
63 }
int w() const
Effective map width.
Definition: map.hpp:50
int h() const
Effective map height.
Definition: map.hpp:53
int total_width() const
Real width of the map, including borders.
Definition: map.hpp:59
int total_height() const
Real height of the map, including borders.
Definition: map.hpp:62
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 'loc', with the given terrain.
void for_each_loc(const F &f) const
mapgen_gamemap(std::string_view data)
int intf_terrainmap_create(lua_State *L)
Create a map.
int intf_terrain_mask(lua_State *L)
Replaces part of the map.
int intf_on_border(lua_State *L)
void lua_terrainmap_setmetatable(lua_State *L)
int intf_on_board(lua_State *L)
int intf_terrainmap_iter(lua_State *L)
int intf_terrainmap_get(lua_State *L)
gamemap_base & luaW_checkterrainmap(lua_State *L, int index)
bool luaW_isterrainmap(lua_State *L, int index)
int intf_replace_if_failed(lua_State *L)
gamemap_base * luaW_toterrainmap(lua_State *L, int index)
std::string register_metatables(lua_State *L)
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:70
std::string_view data
Definition: picture.cpp:178
Encapsulates the map of the game.
Definition: location.hpp:45
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
#define f