Oolite 1.91.0.7645-241119-222d325
Loading...
Searching...
No Matches
OOWaypointEntity.m
Go to the documentation of this file.
1/*
2
3OOWaypointEntity.m
4
5Oolite
6Copyright (C) 2004-2013 Giles C Williams and contributors
7
8This program is free software; you can redistribute it and/or
9modify it under the terms of the GNU General Public License
10as published by the Free Software Foundation; either version 2
11of the License, or (at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with this program; if not, write to the Free Software
20Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21MA 02110-1301, USA.
22
23*/
24
25#import "OOWaypointEntity.h"
26#import "Entity.h"
28#import "OOStringExpander.h"
29#import "Universe.h"
30#import "PlayerEntity.h"
31#import "OOPolygonSprite.h"
32#import "OOOpenGL.h"
33#import "OOMacroOpenGL.h"
34
35#define OOWAYPOINT_KEY_POSITION @"position"
36#define OOWAYPOINT_KEY_ORIENTATION @"orientation"
37#define OOWAYPOINT_KEY_SIZE @"size"
38#define OOWAYPOINT_KEY_CODE @"beaconCode"
39#define OOWAYPOINT_KEY_LABEL @"beaconLabel"
40
41@implementation OOWaypointEntity
42
43+ (instancetype) waypointWithDictionary:(NSDictionary *)info
44{
45 return [[[OOWaypointEntity alloc] initWithDictionary:info] autorelease];
46}
47
48- (id) initWithDictionary:(NSDictionary *)info
49{
50 self = [super init];
51 if (EXPECT_NOT(self == nil)) return nil;
52
53 oriented = YES;
54 position = [info oo_hpvectorForKey:OOWAYPOINT_KEY_POSITION];
55 Quaternion q = [info oo_quaternionForKey:OOWAYPOINT_KEY_ORIENTATION];
56 [self setOrientation:q];
57 [self setSize:[info oo_nonNegativeFloatForKey:OOWAYPOINT_KEY_SIZE defaultValue:1000.0]];
58 [self setBeaconCode:[info oo_stringForKey:OOWAYPOINT_KEY_CODE defaultValue:@"W"]];
59 [self setBeaconLabel:[info oo_stringForKey:OOWAYPOINT_KEY_LABEL defaultValue:@"Waypoint"]];
60
61 [self setStatus:STATUS_EFFECT];
62 [self setScanClass:CLASS_NO_DRAW];
63
64 return self;
65}
66
67
68- (void) dealloc
69{
75
76 [super dealloc];
77}
78
79
80// override
81- (void) setOrientation:(Quaternion)q
82{
83 if (quaternion_equal(q,kZeroQuaternion)) {
85 oriented = NO;
86 } else {
87 oriented = YES;
88 }
89 [super setOrientation:q];
90}
91
92
93- (BOOL) oriented
94{
95 return oriented;
96}
97
98
99- (OOScalar) size
100{
101 return _size;
102}
103
104
105- (void) setSize:(OOScalar)newSize
106{
107 if (newSize > 0)
108 {
109 _size = newSize;
111 }
112}
113
114
115
116- (BOOL) isEffect
117{
118 return YES;
119}
120
121
122- (BOOL) isWaypoint
123{
124 return YES;
125}
126
127
128- (void) drawImmediate:(bool)immediate translucent:(bool)translucent
129{
130 if (!translucent || no_draw_distance < cam_zero_distance)
131 {
132 return;
133 }
134
135 if (![PLAYER hasEquipmentItemProviding:@"EQ_ADVANCED_COMPASS"])
136 {
137 return;
138 }
139
140 int8_t i,j,k;
141
142 GLfloat a = 0.75;
143 if ([PLAYER compassTarget] != self)
144 {
145 a *= 0.25;
146 }
148 {
149 // dim out as gets further away; 2-D HUD display more
150 // important at long range
151 a -= 0.004f*(sqrtf(cam_zero_distance) / _size);
152 }
153 if (a < 0.01f)
154 {
155 return;
156 }
157
158 GLfloat s0 = _size;
159 GLfloat s1 = _size * 0.75f;
160
163 OOGL(glEnable(GL_BLEND));
165
166 OOGL(glColor4f(0.0, 0.0, 1.0, a));
167 OOGLBEGIN(GL_LINES);
168 for (i = -1; i <= 1; i+=2)
169 {
170 for (j = -1; j <= 1; j+=2)
171 {
172 for (k = -1; k <= 1; k+=2)
173 {
174 glVertex3f(i*s0,j*s0,k*s1); glVertex3f(i*s0,j*s1,k*s0);
175 glVertex3f(i*s0,j*s1,k*s0); glVertex3f(i*s1,j*s0,k*s0);
176 glVertex3f(i*s1,j*s0,k*s0); glVertex3f(i*s0,j*s0,k*s1);
177 }
178 }
179 }
180 if (oriented)
181 {
182 while (s1 > 20.0f)
183 {
184 glVertex3f(-20.0,0,-s1-20.0f); glVertex3f(0,0,-s1);
185 glVertex3f(20.0,0,-s1-20.0f); glVertex3f(0,0,-s1);
186 glVertex3f(-20.0,0,s1-20.0f); glVertex3f(0,0,s1);
187 glVertex3f(20.0,0,s1-20.0f); glVertex3f(0,0,s1);
188 s1 *= 0.5;
189 }
190 }
191 OOGLEND();
192
193 OOGL(glDisable(GL_BLEND));
195}
196
197
198/* beacons */
199
200- (NSComparisonResult) compareBeaconCodeWith:(Entity<OOBeaconEntity> *) other
201{
202 return [[self beaconCode] compare:[other beaconCode] options: NSCaseInsensitiveSearch];
203}
204
205
206- (NSString *) beaconCode
207{
208 return _beaconCode;
209}
210
211
212- (void) setBeaconCode:(NSString *)bcode
213{
214 if ([bcode length] == 0) bcode = nil;
215
216 if (_beaconCode != bcode)
217 {
218 [_beaconCode release];
219 _beaconCode = [bcode copy];
220
222 }
223 // if not blanking code and label is currently blank, default label to code
224 if (bcode != nil && (_beaconLabel == nil || [_beaconLabel length] == 0))
225 {
226 [self setBeaconLabel:bcode];
227 }
228
229}
230
231
232- (NSString *) beaconLabel
233{
234 return _beaconLabel;
235}
236
237
238- (void) setBeaconLabel:(NSString *)blabel
239{
240 if ([blabel length] == 0) blabel = nil;
241
242 if (_beaconLabel != blabel)
243 {
244 [_beaconLabel release];
245 _beaconLabel = [OOExpand(blabel) retain];
246 }
247}
248
249
250- (BOOL) isBeacon
251{
252 return [self beaconCode] != nil;
253}
254
255
256- (id <OOHUDBeaconIcon>) beaconDrawable
257{
258 if (_beaconDrawable == nil)
259 {
260 NSString *beaconCode = [self beaconCode];
261 NSUInteger length = [beaconCode length];
262
263 if (length > 1)
264 {
265 NSArray *iconData = [[UNIVERSE descriptions] oo_arrayForKey:beaconCode];
266 if (iconData != nil) _beaconDrawable = [[OOPolygonSprite alloc] initWithDataArray:iconData outlineWidth:0.5 name:beaconCode];
267 }
268
269 if (_beaconDrawable == nil)
270 {
271 if (length > 0) _beaconDrawable = [[beaconCode substringToIndex:1] retain];
272 else _beaconDrawable = @"";
273 }
274 }
275
276 return _beaconDrawable;
277}
278
279
280- (Entity <OOBeaconEntity> *) prevBeacon
281{
282 return [_prevBeacon weakRefUnderlyingObject];
283}
284
285
286- (Entity <OOBeaconEntity> *) nextBeacon
287{
288 return [_nextBeacon weakRefUnderlyingObject];
289}
290
291
292- (void) setPrevBeacon:(Entity <OOBeaconEntity> *)beaconShip
293{
294 if (beaconShip != [self prevBeacon])
295 {
296 [_prevBeacon release];
297 _prevBeacon = [beaconShip weakRetain];
298 }
299}
300
301
302- (void) setNextBeacon:(Entity <OOBeaconEntity> *)beaconShip
303{
304 if (beaconShip != [self nextBeacon])
305 {
306 [_nextBeacon release];
307 _nextBeacon = [beaconShip weakRetain];
308 }
309}
310
311
312- (BOOL) isJammingScanning
313{
314 return NO;
315}
316
317
318@end
#define NO_DRAW_DISTANCE_FACTOR
Definition Entity.h:46
#define DESTROY(x)
Definition OOCocoa.h:77
#define EXPECT_NOT(x)
#define OO_ENTER_OPENGL()
GLfloat OOScalar
Definition OOMaths.h:64
#define OOGLBEGIN
Definition OOOpenGL.h:253
@ OPENGL_STATE_TRANSLUCENT_PASS
Definition OOOpenGL.h:124
#define OOVerifyOpenGLState()
Definition OOOpenGL.h:136
void GLScaledLineWidth(GLfloat width)
Definition OOOpenGL.m:218
#define OOSetOpenGLState(STATE)
Definition OOOpenGL.h:135
#define OOGL(statement)
Definition OOOpenGL.h:251
#define OOGLEND
Definition OOOpenGL.h:254
return nil
const Quaternion kIdentityQuaternion
const Quaternion kZeroQuaternion
#define PLAYER
GLfloat cam_zero_distance
Definition Entity.h:109
HPVector position
Definition Entity.h:112
GLfloat no_draw_distance
Definition Entity.h:110
id< OOHUDBeaconIcon > _beaconDrawable
OOWeakReference * _nextBeacon
id< OOHUDBeaconIcon > beaconDrawable()
NSString * _beaconLabel
OOWeakReference * _prevBeacon
Entity< OOBeaconEntity > * prevBeacon()
Entity< OOBeaconEntity > * nextBeacon()
voidpf void uLong size
Definition ioapi.h:134