Oolite 1.91.0.7645-241119-222d325
Loading...
Searching...
No Matches
OOEntityFilterPredicate.m
Go to the documentation of this file.
1/*
2
3OOEntityFilterPredicate.h
4
5Filters used to select entities in various contexts.
6
7
8Oolite
9Copyright (C) 2004-2013 Giles C Williams and contributors
10
11This program is free software; you can redistribute it and/or
12modify it under the terms of the GNU General Public License
13as published by the Free Software Foundation; either version 2
14of the License, or (at your option) any later version.
15
16This program is distributed in the hope that it will be useful,
17but WITHOUT ANY WARRANTY; without even the implied warranty of
18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19GNU General Public License for more details.
20
21You should have received a copy of the GNU General Public License
22along with this program; if not, write to the Free Software
23Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
24MA 02110-1301, USA.
25
26*/
27
29#import "Entity.h"
30#import "ShipEntity.h"
31#import "OOPlanetEntity.h"
32#import "OORoleSet.h"
33
34
35BOOL YESPredicate(Entity *entity, void *parameter)
36{
37 return YES;
38}
39
40
41BOOL NOPredicate(Entity *entity, void *parameter)
42{
43 return NO;
44}
45
46
47BOOL NOTPredicate(Entity *entity, void *parameter)
48{
49 ChainedEntityPredicateParameter *param = parameter;
50 if (param == NULL || param->predicate == NULL) return NO;
51
52 return !param->predicate(entity, param->parameter);
53}
54
55
56BOOL ANDPredicate(Entity *entity, void *parameter)
57{
58 BinaryOperationPredicateParameter *param = parameter;
59
60 if (!param->predicate1(entity, param->parameter1)) return NO;
61 if (!param->predicate2(entity, param->parameter2)) return NO;
62 return YES;
63}
64
65
66BOOL ORPredicate(Entity *entity, void *parameter)
67{
68 BinaryOperationPredicateParameter *param = parameter;
69
70 if (param->predicate1(entity, param->parameter1)) return YES;
71 if (param->predicate2(entity, param->parameter2)) return YES;
72 return NO;
73}
74
75
76BOOL NORPredicate(Entity *entity, void *parameter)
77{
78 BinaryOperationPredicateParameter *param = parameter;
79
80 if (param->predicate1(entity, param->parameter1)) return NO;
81 if (param->predicate2(entity, param->parameter2)) return NO;
82 return YES;
83}
84
85
86BOOL XORPredicate(Entity *entity, void *parameter)
87{
88 BinaryOperationPredicateParameter *param = parameter;
89 BOOL A, B;
90
91 A = param->predicate1(entity, param->parameter1);
92 B = param->predicate2(entity, param->parameter2);
93
94 return (A || B) && !(A && B);
95}
96
97
98BOOL NANDPredicate(Entity *entity, void *parameter)
99{
100 BinaryOperationPredicateParameter *param = parameter;
101 BOOL A, B;
102
103 A = param->predicate1(entity, param->parameter1);
104 B = param->predicate2(entity, param->parameter2);
105
106 return !(A && B);
107}
108
109
110BOOL HasScanClassPredicate(Entity *entity, void *parameter)
111{
112 return [(id)parameter intValue] == [entity scanClass];
113}
114
115
116BOOL HasClassPredicate(Entity *entity, void *parameter)
117{
118 return [entity isKindOfClass:(Class)parameter];
119}
120
121
122BOOL IsShipPredicate(Entity *entity, void *parameter)
123{
124 return [entity isShip] && ![entity isSubEntity];
125}
126
127
128BOOL IsStationPredicate(Entity *entity, void *parameter)
129{
130 return [entity isStation];
131}
132
133
134BOOL IsPlanetPredicate(Entity *entity, void *parameter)
135{
136 if (![entity isPlanet]) return NO;
137 OOStellarBodyType type = [(OOPlanetEntity *)entity planetType];
138 return (type == STELLAR_TYPE_NORMAL_PLANET || type == STELLAR_TYPE_MOON);
139}
140
141
142BOOL IsSunPredicate(Entity *entity, void *parameter)
143{
144 return [entity isSun];
145}
146
147
148BOOL IsVisualEffectPredicate(Entity *entity, void *parameter)
149{
150 return [entity isVisualEffect] && ![entity isSubEntity];
151}
152
153
154BOOL HasRolePredicate(Entity *ship, void *parameter)
155{
156 return [(ShipEntity *)ship hasRole:(NSString *)parameter];
157}
158
159
160BOOL HasPrimaryRolePredicate(Entity *ship, void *parameter)
161{
162 return [(ShipEntity *)ship hasPrimaryRole:(NSString *)parameter];
163}
164
165
166BOOL HasRoleInSetPredicate(Entity *ship, void *parameter)
167{
168 return [[(ShipEntity *)ship roleSet] intersectsSet:(NSSet *)parameter];
169}
170
171
172BOOL HasPrimaryRoleInSetPredicate(Entity *ship, void *parameter)
173{
174 return [(NSSet *)parameter containsObject:[(ShipEntity *)ship primaryRole]];
175}
176
177
178BOOL IsHostileAgainstTargetPredicate(Entity *ship, void *parameter)
179{
180 return [(ShipEntity *)ship hasHostileTarget] && [(ShipEntity *)ship primaryTarget] == (ShipEntity *)parameter;
181}
BOOL IsStationPredicate(Entity *entity, void *parameter)
BOOL NOPredicate(Entity *entity, void *parameter)
BOOL NANDPredicate(Entity *entity, void *parameter)
BOOL XORPredicate(Entity *entity, void *parameter)
BOOL ANDPredicate(Entity *entity, void *parameter)
BOOL NOTPredicate(Entity *entity, void *parameter)
BOOL IsSunPredicate(Entity *entity, void *parameter)
BOOL HasScanClassPredicate(Entity *entity, void *parameter)
BOOL IsHostileAgainstTargetPredicate(Entity *ship, void *parameter)
BOOL HasPrimaryRolePredicate(Entity *ship, void *parameter)
BOOL IsShipPredicate(Entity *entity, void *parameter)
BOOL IsPlanetPredicate(Entity *entity, void *parameter)
BOOL HasRolePredicate(Entity *ship, void *parameter)
BOOL IsVisualEffectPredicate(Entity *entity, void *parameter)
BOOL ORPredicate(Entity *entity, void *parameter)
BOOL NORPredicate(Entity *entity, void *parameter)
BOOL HasClassPredicate(Entity *entity, void *parameter)
BOOL HasRoleInSetPredicate(Entity *ship, void *parameter)
BOOL YESPredicate(Entity *entity, void *parameter)
BOOL HasPrimaryRoleInSetPredicate(Entity *ship, void *parameter)
OOStellarBodyType
@ STELLAR_TYPE_MOON
@ STELLAR_TYPE_NORMAL_PLANET
unsigned isVisualEffect
Definition Entity.h:104
unsigned isSubEntity
Definition Entity.h:95
BOOL isSun()
Definition Entity.m:167
unsigned isShip
Definition Entity.h:91
OOScanClass scanClass
Definition Entity.h:106
unsigned isStation
Definition Entity.h:92