summaryrefslogtreecommitdiff
path: root/src/object_filter.hpp
blob: 9a22090b53405b5c95f36814767ad64034f80d29 (plain)
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
93
94
95
96
97
98
99
#pragma once

#include "h-basic.h"
#include "object_type_fwd.hpp"

#include <functional>
#include <initializer_list>

typedef std::function<bool (object_type const *)> object_filter_t;

namespace object_filter {

/**
 * Is TVal equal to the given value?
 */
object_filter_t TVal(byte tval);

/**
 * Is SVal equal to the given value?
 */
object_filter_t SVal(byte sval);

/**
 * Has given bit mask in flag3 value.
 */
object_filter_t HasFlag3(u32b mask);

/**
 * Has given bit mask in flag4 value.
 */
object_filter_t HasFlag4(u32b mask);

/**
 * Has given bit mask in flag5 value.
 */
object_filter_t HasFlag5(u32b mask);

/**
 * Is the object an artifact?
 */
object_filter_t IsArtifact();

/**
 * Is the object an artifact as determined by artifact_p?
 */
object_filter_t IsArtifactP();

/**
 * Is the object an ego item?
 */
object_filter_t IsEgo();

/**
 * Is the object "known"?
 */
object_filter_t IsKnown();

/**
 * True always accepts all items.
 */
object_filter_t True();

/**
 * Invert an object filter.
 */
object_filter_t Not(object_filter_t p);

/**
 * Logical conjunction (AND)
 */
object_filter_t And();

/**
 * Logical conjunction (AND)
 */
template<typename Arg0, typename... Args> object_filter_t And(Arg0&& arg0, Args&&... args) {
	auto argsFilter = And(args...);
	return [=](object_type const *o_ptr) -> bool {
		return arg0(o_ptr) && argsFilter(o_ptr);
	};
}

/**
 * Logical disjunction (OR)
 */
object_filter_t Or();

/**
 * Logical disjunction (OR)
 */
template<typename Arg0, typename... Args> object_filter_t Or(Arg0&& arg0, Args&&... args) {
	auto argsFilter = Or(args...);
	return [=](object_type const *o_ptr) -> bool {
		auto x = arg0(o_ptr) || argsFilter(o_ptr);
		return x;
	};
}

}