The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
lua_terrainfilter.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 <memory>
19#include <map>
20#include <set>
21#include "map/map.hpp"
22
23struct lua_State;
24class filter_impl;
25namespace lua_mapgen
26{
27 class filter
28 {
29 public:
30 /**
31 * @a a lua table with the following attributes
32 * [1]: the filter table,
33 * [2]: attributeslocation_sets
34 */
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&&) noexcept = default;
42 filter& operator=(filter&&) noexcept = default;
43
44 ~filter();
45
46 bool matches(const gamemap_base& m, map_location l) const;
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 using filter_ptr = std::unique_ptr<filter, std::function<void(filter*)>>;
54
55 std::string register_filter_metatables(lua_State *L);
56}
57
58bool luaW_is_mgfilter(lua_State* L, int index);
59
60lua_mapgen::filter* luaW_to_mgfilter(lua_State *L, int index);
61
62lua_mapgen::filter_ptr luaW_check_mgfilter(lua_State *L, int index, bool allow_compile = false);
63
64void lua_mgfilter_setmetatable(lua_State *L);
65
66int intf_terrainfilter_create(lua_State *L);
67
68int intf_mg_get_locations(lua_State* L);
69int intf_mg_get_tiles_radius(lua_State* L);
70
71namespace lua_terrainfilter {
72 std::string register_metatables(lua_State *L);
73}
filter(const filter &)=delete
std::unique_ptr< filter_impl > impl_
filter & operator=(const filter &)=delete
bool matches(const gamemap_base &m, map_location l) const
filter(filter &&) noexcept=default
std::map< std::string, std::set< map_location > > known_sets_
int intf_mg_get_tiles_radius(lua_State *L)
lua_mapgen::filter * luaW_to_mgfilter(lua_State *L, int index)
int intf_terrainfilter_create(lua_State *L)
Create a filter.
int intf_mg_get_locations(lua_State *L)
void lua_mgfilter_setmetatable(lua_State *L)
lua_mapgen::filter_ptr luaW_check_mgfilter(lua_State *L, int index, bool allow_compile)
bool luaW_is_mgfilter(lua_State *L, int index)
std::string register_filter_metatables(lua_State *L)
std::unique_ptr< filter, std::function< void(filter *)> > filter_ptr
STL namespace.
Encapsulates the map of the game.
Definition location.hpp:46