The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
lua_terrainmap.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2018 - 2025
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
22struct lua_State;
23
24// Unlike the original gamemap, this offers 'raw' access to the data.
25// The original gamemap uses terrain type data.
27public:
28 explicit mapgen_gamemap(std::string_view data);
29 mapgen_gamemap(int w, int h, terrain_code);
31 const terrain_code& terrain,
33 bool replace_if_failed = false) override;
34
35 template<typename F>
36 void for_each_loc(const F& f) const
37 {
38 for (int x = 0; x < total_width(); ++x) {
39 for (int y = 0; y < total_height(); ++y) {
40 f({ x, y , wml_loc()});
41 }
42 }
43 }
44};
45
46int intf_terrain_mask(lua_State *L);
47
48bool luaW_isterrainmap(lua_State* L, int index);
49
50gamemap_base* luaW_toterrainmap(lua_State *L, int index);
51
52gamemap_base& luaW_checkterrainmap(lua_State *L, int index);
53
54void lua_terrainmap_setmetatable(lua_State *L);
55
56int intf_terrainmap_create(lua_State *L);
57int intf_terrainmap_get(lua_State *L);
58
59int intf_replace_if_failed(lua_State* L);
60int intf_terrainmap_iter(lua_State* L);
61int intf_on_board(lua_State* L);
62int intf_on_border(lua_State* L);
63
64namespace lua_terrainmap {
65 std::string register_metatables(lua_State *L);
66}
map_location loc
Definition move.cpp:172
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
gamemap_base::set_terrain_result 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
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)
gamemap_base & luaW_checkterrainmap(lua_State *L, int index)
void lua_terrainmap_setmetatable(lua_State *L)
int intf_on_board(lua_State *L)
int intf_terrainmap_iter(lua_State *L)
gamemap_base * luaW_toterrainmap(lua_State *L, int index)
int intf_terrainmap_get(lua_State *L)
bool luaW_isterrainmap(lua_State *L, int index)
int intf_replace_if_failed(lua_State *L)
std::string register_metatables(lua_State *L)
std::string_view data
Definition picture.cpp:188
Encapsulates the map of the game.
Definition location.hpp:46
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
#define f