Oolite
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 "OOMacroOpenGL.h"
29#import "OOOpenGL.h"
30#import "OOPolygonSprite.h"
31#import "OOStringExpander.h"
32#import "PlayerEntity.h"
33#import "Universe.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))
52 return nil;
53
54 oriented = YES;
55 position = [info oo_hpvectorForKey:OOWAYPOINT_KEY_POSITION];
56 Quaternion q = [info oo_quaternionForKey:OOWAYPOINT_KEY_ORIENTATION];
57 [self setOrientation:q];
58 [self setSize:[info oo_nonNegativeFloatForKey:OOWAYPOINT_KEY_SIZE defaultValue:1000.0]];
59 [self setBeaconCode:[info oo_stringForKey:OOWAYPOINT_KEY_CODE defaultValue:@"W"]];
60 [self setBeaconLabel:[info oo_stringForKey:OOWAYPOINT_KEY_LABEL defaultValue:@"Waypoint"]];
61
62 [self setStatus:STATUS_EFFECT];
63 [self setScanClass:CLASS_NO_DRAW];
64
65 return self;
66}
67
78
79// override
80- (void)setOrientation:(Quaternion)q
81{
84 oriented = NO;
85 } else {
86 oriented = YES;
87 }
88 [super setOrientation:q];
89}
90
91- (BOOL)oriented
92{
93 return oriented;
94}
95
97{
98 return _size;
99}
100
101- (void)setSize:(OOScalar)newSize
102{
103 if (newSize > 0) {
104 _size = newSize;
106 }
107}
108
109- (BOOL)isEffect
110{
111 return YES;
112}
113
115{
116 return YES;
117}
118
119- (void)drawImmediate:(bool)immediate translucent:(bool)translucent
120{
121 if (!translucent || no_draw_distance < cam_zero_distance) {
122 return;
123 }
124
125 if (![PLAYER hasEquipmentItemProviding:@"EQ_ADVANCED_COMPASS"]) {
126 return;
127 }
128
129 int8_t i, j, k;
130
131 GLfloat a = 0.75;
132 if ([PLAYER compassTarget] != self) {
133 a *= 0.25;
134 }
135 if (cam_zero_distance > _size * _size) {
136 // dim out as gets further away; 2-D HUD display more
137 // important at long range
138 a -= 0.004f * (sqrtf(cam_zero_distance) / _size);
139 }
140 if (a < 0.01f) {
141 return;
142 }
143
144 GLfloat s0 = _size;
145 GLfloat s1 = _size * 0.75f;
146
149 OOGL(glEnable(GL_BLEND));
151
152 OOGL(glColor4f(0.0, 0.0, 1.0, a));
153 OOGLBEGIN(GL_LINES);
154 for (i = -1; i <= 1; i += 2) {
155 for (j = -1; j <= 1; j += 2) {
156 for (k = -1; k <= 1; k += 2) {
157 glVertex3f(i * s0, j * s0, k * s1);
158 glVertex3f(i * s0, j * s1, k * s0);
159 glVertex3f(i * s0, j * s1, k * s0);
160 glVertex3f(i * s1, j * s0, k * s0);
161 glVertex3f(i * s1, j * s0, k * s0);
162 glVertex3f(i * s0, j * s0, k * s1);
163 }
164 }
165 }
166 if (oriented) {
167 while (s1 > 20.0f) {
168 glVertex3f(-20.0, 0, -s1 - 20.0f);
169 glVertex3f(0, 0, -s1);
170 glVertex3f(20.0, 0, -s1 - 20.0f);
171 glVertex3f(0, 0, -s1);
172 glVertex3f(-20.0, 0, s1 - 20.0f);
173 glVertex3f(0, 0, s1);
174 glVertex3f(20.0, 0, s1 - 20.0f);
175 glVertex3f(0, 0, s1);
176 s1 *= 0.5;
177 }
178 }
179 OOGLEND();
180
181 OOGL(glDisable(GL_BLEND));
183}
184
185/* beacons */
186
187- (NSComparisonResult)compareBeaconCodeWith:(Entity<OOBeaconEntity>*)other
188{
189 return [[self beaconCode] compare:[other beaconCode] options:NSCaseInsensitiveSearch];
190}
191
192- (NSString*)beaconCode
193{
194 return _beaconCode;
195}
196
197- (void)setBeaconCode:(NSString*)bcode
198{
199 if ([bcode length] == 0)
200 bcode = nil;
201
202 if (_beaconCode != bcode) {
203 [_beaconCode release];
204 _beaconCode = [bcode copy];
205
207 }
208 // if not blanking code and label is currently blank, default label to code
209 if (bcode != nil && (_beaconLabel == nil || [_beaconLabel length] == 0)) {
210 [self setBeaconLabel:bcode];
211 }
212}
213
214- (NSString*)beaconLabel
215{
216 return _beaconLabel;
217}
218
219- (void)setBeaconLabel:(NSString*)blabel
220{
221 if ([blabel length] == 0)
222 blabel = nil;
223
224 if (_beaconLabel != blabel) {
225 [_beaconLabel release];
226 _beaconLabel = [OOExpand(blabel) retain];
227 }
228}
229
230- (BOOL)isBeacon
231{
232 return [self beaconCode] != nil;
233}
234
235- (id<OOHUDBeaconIcon>)beaconDrawable
236{
237 if (_beaconDrawable == nil) {
238 NSString* beaconCode = [self beaconCode];
239 NSUInteger length = [beaconCode length];
240
241 if (length > 1) {
242 NSArray* iconData = [[UNIVERSE descriptions] oo_arrayForKey:beaconCode];
243 if (iconData != nil)
244 _beaconDrawable = [[OOPolygonSprite alloc] initWithDataArray:iconData outlineWidth:0.5 name:beaconCode];
245 }
246
247 if (_beaconDrawable == nil) {
248 if (length > 0)
249 _beaconDrawable = [[beaconCode substringToIndex:1] retain];
250 else
251 _beaconDrawable = @"";
252 }
253 }
254
255 return _beaconDrawable;
256}
257
258- (Entity<OOBeaconEntity>*)prevBeacon
259{
261}
262
263- (Entity<OOBeaconEntity>*)nextBeacon
264{
266}
267
268- (void)setPrevBeacon:(Entity<OOBeaconEntity>*)beaconShip
269{
270 if (beaconShip != [self prevBeacon]) {
271 [_prevBeacon release];
272 _prevBeacon = [beaconShip weakRetain];
273 }
274}
275
276- (void)setNextBeacon:(Entity<OOBeaconEntity>*)beaconShip
277{
278 if (beaconShip != [self nextBeacon]) {
279 [_nextBeacon release];
280 _nextBeacon = [beaconShip weakRetain];
281 }
282}
283
285{
286 return NO;
287}
288
289@end
#define NO_DRAW_DISTANCE_FACTOR
Definition Entity.h:49
#define DESTROY(x)
#define EXPECT_NOT(x)
#define OO_ENTER_OPENGL()
GLfloat OOScalar
Definition OOMaths.h:49
#define OOGLBEGIN
Definition OOOpenGL.h:269
@ OPENGL_STATE_TRANSLUCENT_PASS
Definition OOOpenGL.h:122
#define OOVerifyOpenGLState()
Definition OOOpenGL.h:133
void GLScaledLineWidth(GLfloat width)
Definition OOOpenGL.m:206
#define OOSetOpenGLState(STATE)
Definition OOOpenGL.h:132
#define OOGL(statement)
Definition OOOpenGL.h:262
#define OOGLEND
Definition OOOpenGL.h:270
return nil
OOINLINE bool quaternion_equal(Quaternion a, Quaternion b) INLINE_CONST_FUNC
const Quaternion kIdentityQuaternion
const Quaternion kZeroQuaternion
#define PLAYER
void setOrientation:(Quaternion quat)
Definition Entity.m:676
void setScanClass:(OOScanClass sClass)
Definition Entity.m:738
GLfloat cam_zero_distance
Definition Entity.h:105
HPVector position
Definition Entity.m:576
GLfloat no_draw_distance
Definition Entity.h:106
id init()
Definition Entity.m:64
void setStatus:(OOEntityStatus stat)
Definition Entity.m:728
void dealloc()
Definition Entity.m:98
id< OOHUDBeaconIcon > _beaconDrawable
void setBeaconLabel:(NSString *blabel)
OOWeakReference * _nextBeacon
id< OOHUDBeaconIcon > beaconDrawable()
void setBeaconCode:(NSString *bcode)
NSString * _beaconLabel
OOWeakReference * _prevBeacon
void setSize:(OOScalar newSize)
Entity< OOBeaconEntity > * prevBeacon()
void setOrientation:(Quaternion q)
Entity< OOBeaconEntity > * nextBeacon()