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