The Battle for Wesnoth  1.19.4+dev
pathutils.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2024
3  by David White <dave@whitevine.net>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #pragma once
17 
18 #include "map/location.hpp"
19 
20 class gamemap;
21 
22 class xy_pred
23 {
24 public:
25  virtual bool operator()(const map_location&) const = 0;
26 protected:
27  virtual ~xy_pred() {}
28 };
29 
30 /**
31  * Function that will add to @a result all locations exactly @a radius tiles
32  * from @a center (or nothing if @a radius is not positive). @a result must be
33  * a std::vector of locations.
34  */
35 void get_tile_ring(const map_location& center, const int radius,
36  std::vector<map_location>& result);
37 
38 /**
39  * Function that will add to @a result all locations within @a radius tiles
40  * of @a center (excluding @a center itself). @a result must be a std::vector
41  * of locations.
42  */
43 void get_tiles_in_radius(const map_location& center, const int radius,
44  std::vector<map_location>& result);
45 
46 /**
47  * Function that will add to @a result all locations within @a radius tiles
48  * of @a center (including @a center itself). @a result must be a std::set
49  * of locations.
50  */
51 void get_tiles_radius(const map_location& center, std::size_t radius,
52  std::set<map_location>& result);
53 
54 /**
55  * Function that will add to @a result all elements of @a locs, plus all
56  * on-board locations that are within @a radius tiles of an element of locs.
57  * @a result must be a std::set of locations.
58  */
59 void get_tiles_radius(const gamemap& map, const std::vector<map_location>& locs,
60  std::size_t radius, std::set<map_location>& result,
61  bool with_border=false);
62 
63 /**
64  * Function that will add to @a result all elements of @a locs, plus all
65  * on-board locations matching @a pred that are connected to elements of
66  * locs by a chain of at most @a radius tiles, each of which matches @a pred.
67  * @a result must be a std::set of locations.
68  */
69 void get_tiles_radius(const gamemap& map, const std::vector<map_location>& locs,
70  std::size_t radius, std::set<map_location>& result,
71  bool with_border, const xy_pred &pred);
Encapsulates the map of the game.
Definition: map.hpp:172
virtual bool operator()(const map_location &) const =0
virtual ~xy_pred()
Definition: pathutils.hpp:27
void get_tiles_in_radius(const map_location &center, const int radius, std::vector< map_location > &result)
Function that will add to result all locations within radius tiles of center (excluding center itself...
Definition: pathutils.cpp:56
void get_tiles_radius(const map_location &center, std::size_t radius, std::set< map_location > &result)
Function that will add to result all locations within radius tiles of center (including center itself...
Definition: pathutils.cpp:70
void get_tile_ring(const map_location &center, const int radius, std::vector< map_location > &result)
Function that will add to result all locations exactly radius tiles from center (or nothing if radius...
Definition: pathutils.cpp:32
Encapsulates the map of the game.
Definition: location.hpp:44