The Battle for Wesnoth  1.17.0-dev
lua_terrainfilter.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 <memory>
20 #include <map>
21 #include <set>
22 #include "map/map.hpp"
23 
24 #include "scripting/lua_common.hpp"
25 struct lua_State;
26 struct map_location;
27 class mapgen_gamemap;
28 class filter_impl;
29 namespace lua_mapgen
30 {
31  class filter
32  {
33  public:
34  /**
35  * @a a lua table with the following attributes
36  * [1]: the filter table,
37  * [2]: attributeslocation_sets
38  */
39  explicit filter(lua_State* L, int data_index, int res_index = 0);
40 
41  //impl_ may contain pointers to known_sets_, copycontructing this will result in segfaults.
42  filter(const filter&) = delete;
43  filter& operator=(const filter&) = delete;
44  //moving is ok though.
45  filter(filter&&) = default;
46  filter& operator=(filter&&) = default;
47 
48  ~filter();
49 
50  bool matches(const gamemap_base& m, map_location l);
51  //todo: add a clear cache function.
52  private:
53  std::map<std::string, std::set<map_location>> known_sets_;
54  std::unique_ptr<filter_impl> impl_;
55  };
56 
57  std::string register_filter_metatables(lua_State *L);
58 }
59 
60 bool luaW_is_mgfilter(lua_State* L, int index);
61 
63 
65 
67 
69 
72 
73 namespace lua_terrainfilter {
74  std::string register_metatables(lua_State *L);
75 }
void lua_mgfilter_setmetatable(lua_State *L)
bool matches(const gamemap_base &m, map_location l)
filter(lua_State *L, int data_index, int res_index=0)
a lua table with the following attributes [1]: the filter table,
std::unique_ptr< filter_impl > impl_
int intf_terrainfilter_create(lua_State *L)
Create a filter.
lua_mapgen::filter * luaW_to_mgfilter(lua_State *L, int index)
std::string register_filter_metatables(lua_State *L)
lua_mapgen::filter & luaW_check_mgfilter(lua_State *L, int index)
filter & operator=(const filter &)=delete
std::string register_metatables(lua_State *L)
Definition: lua_color.cpp:136
Encapsulates the map of the game.
Definition: location.hpp:38
std::map< std::string, std::set< map_location > > known_sets_
bool luaW_is_mgfilter(lua_State *L, int index)
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_mg_get_locations(lua_State *L)
int intf_mg_get_tiles_radius(lua_State *L)