forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
map_selector.h
92 lines (79 loc) · 2.88 KB
/
map_selector.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#pragma once
#ifndef CATA_SRC_MAP_SELECTOR_H
#define CATA_SRC_MAP_SELECTOR_H
#include <climits>
#include <functional>
#include <list>
#include <vector>
#include "point.h"
#include "visitable.h"
class item;
class map_cursor : public visitable
{
private:
tripoint pos_;
public:
explicit map_cursor( const tripoint &pos );
tripoint pos() const;
// inherited from visitable
VisitResponse visit_items( const std::function<VisitResponse( item *, item * )> &func ) const
override;
std::list<item> remove_items_with( const std::function<bool( const item & )> &filter,
int count = INT_MAX ) override;
};
class map_selector : public visitable
{
public:
using value_type = map_cursor;
using size_type = std::vector<value_type>::size_type;
using iterator = std::vector<value_type>::iterator;
using const_iterator = std::vector<value_type>::const_iterator;
using reference = std::vector<value_type>::reference;
using const_reference = std::vector<value_type>::const_reference;
/**
* Constructs map_selector used for querying items located on map tiles
* @param pos position on map at which to start each query
* @param radius number of adjacent tiles to include (searching from pos outwards)
* @param accessible whether found items must be accessible from pos to be considered
*/
explicit map_selector( const tripoint &pos, int radius = 0, bool accessible = true );
// similar to item_location you are not supposed to store this class between turns
map_selector( const map_selector &that ) = delete;
map_selector &operator=( const map_selector & ) = delete;
map_selector( map_selector && ) = default;
size_type size() const {
return data.size();
}
iterator begin() {
return data.begin();
}
iterator end() {
return data.end();
}
const_iterator cbegin() const {
return data.cbegin();
}
const_iterator cend() const {
return data.cend();
}
reference front() {
return data.front();
}
const_reference front() const {
return data.front();
}
reference back() {
return data.back();
}
const_reference back() const {
return data.back();
}
// inherited from visitable
VisitResponse visit_items( const std::function<VisitResponse( item *, item * )> &func ) const
override;
std::list<item> remove_items_with( const std::function<bool( const item & )> &filter,
int count = INT_MAX ) override;
private:
std::vector<value_type> data;
};
#endif // CATA_SRC_MAP_SELECTOR_H