Oolite
Loading...
Searching...
No Matches
HeadUpDisplay.m
Go to the documentation of this file.
1/*
2
3HeadUpDisplay.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 "HeadUpDisplay.h"
26#import "GameController.h"
27#import "GuiDisplayGen.h"
29#import "OOColor.h"
30#import "OOConstToString.h"
31#import "OOCrosshairs.h"
33#import "OOFoundation.h"
34#import "OOJavaScriptEngine.h"
35#import "OOJoystickManager.h"
36#import "OOPlanetEntity.h"
37#import "OOPolygonSprite.h"
39#import "OOStringExpander.h"
40#import "OOStringParsing.h"
41#import "OOSunEntity.h"
42#import "OOTexture.h"
43#import "OOTextureSprite.h"
44#import "OOTrumble.h"
46#import "OOWaypointEntity.h"
47#import "PlayerEntity.h"
48#import "ResourceManager.h"
49#import "StationEntity.h"
50#import "Universe.h"
51
52#define ONE_SIXTEENTH 0.0625
53#define ONE_SIXTYFOURTH 0.015625
54#define DEFAULT_OVERALL_ALPHA 0.75
55#define GLYPH_SCALE_FACTOR 0.13 // 0.13 is an inherited magic number
56#define IDENTIFY_SCANNER_LOLLIPOPS (0 && OOLITE_DEBUG)
57
58#define NOT_DEFINED INFINITY
59#define WIDGET_INFO 0
60#define WIDGET_CACHE 1
61#define WIDGET_SELECTOR 2
62#define WIDGET_SELECTOR_NAME 3
63
64/* Convenience macros to make set-colour-or-default quicker. 'info' must be the NSDictionary and 'alpha' must be the overall alpha or these won't work */
65#define DO_SET_COLOR(t, d) SetGLColourFromInfo(info, t, d, alpha)
66#define SET_COLOR(d) DO_SET_COLOR(COLOR_KEY, d)
67#define SET_COLOR_LOW(d) DO_SET_COLOR(COLOR_KEY_LOW, d)
68#define SET_COLOR_MEDIUM(d) DO_SET_COLOR(COLOR_KEY_MEDIUM, d)
69#define SET_COLOR_HIGH(d) DO_SET_COLOR(COLOR_KEY_HIGH, d)
70#define SET_COLOR_CRITICAL(d) DO_SET_COLOR(COLOR_KEY_CRITICAL, d)
71#define SET_COLOR_SURROUND(d) DO_SET_COLOR(COLOR_KEY_SURROUND, d)
72
73struct CachedInfo {
74 float x, y, x0, y0;
76};
77
78static NSArray* sCurrentDrawItem;
79
80OOINLINE float useDefined(float val, float validVal)
81{
82 return (val == NOT_DEFINED) ? validVal : val;
83}
84
85static void DrawSpecialOval(GLfloat x, GLfloat y, GLfloat z, NSSize siz, GLfloat step, GLfloat* color4v);
86
87static void SetGLColourFromInfo(NSDictionary* info, NSString* key, const GLfloat defaultColor[4], GLfloat alpha);
88static void GetRGBAArrayFromInfo(NSDictionary* info, GLfloat ioColor[4]);
89
90static void hudDrawIndicatorAt(GLfloat x, GLfloat y, GLfloat z, NSSize siz, GLfloat amount);
91static void hudDrawMarkerAt(GLfloat x, GLfloat y, GLfloat z, NSSize siz, GLfloat amount);
92static void hudDrawBarAt(GLfloat x, GLfloat y, GLfloat z, NSSize siz, GLfloat amount);
93static void hudDrawSurroundAt(GLfloat x, GLfloat y, GLfloat z, NSSize siz);
94static void hudDrawStatusIconAt(int x, int y, int z, NSSize siz);
95static void hudDrawReticleOnTarget(Entity* target, PlayerEntity* player1, GLfloat z1,
96 GLfloat alpha, BOOL reticleTargetSensitive, NSMutableDictionary* propertiesReticleTargetSensitive,
97 BOOL colourFromScannerColour, BOOL showText, NSDictionary* info, NSMutableArray* reticleColors);
98static void hudDrawWaypoint(OOWaypointEntity* waypoint, PlayerEntity* player1, GLfloat z1, GLfloat alpha, BOOL selected, GLfloat scale);
100static void drawScannerGrid(GLfloat x, GLfloat y, GLfloat z, NSSize siz, int v_dir, GLfloat thickness, GLfloat zoom, BOOL nonlinear, BOOL minimalistic);
101static GLfloat nonlinearScannerFunc(GLfloat distance, GLfloat zoom, GLfloat scale);
102static void GLDrawNonlinearCascadeWeapon(GLfloat x, GLfloat y, GLfloat z, NSSize siz, Vector centre, GLfloat radius, GLfloat zoom, GLfloat alpha);
103
106static NSString* distance_unit;
107
108enum {
110};
111
112@interface HeadUpDisplay (Private)
113
114- (void)drawCrosshairs;
115- (void)drawLegends;
116- (void)drawDials;
117- (void)drawMFDs;
118
119- (void)drawLegend:(NSDictionary*)info;
120- (void)drawHUDItem:(NSDictionary*)info;
121
122- (void)drawScanner:(NSDictionary*)info;
123- (void)drawScannerZoomIndicator:(NSDictionary*)info;
124
125- (void)drawCompass:(NSDictionary*)info;
126- (void)drawCompassPlanetBlipAt:(Vector)relativePosition Size:(NSSize)siz Alpha:(GLfloat)alpha;
127- (void)drawCompassStationBlipAt:(Vector)relativePosition Size:(NSSize)siz Alpha:(GLfloat)alpha;
128- (void)drawCompassSunBlipAt:(Vector)relativePosition Size:(NSSize)siz Alpha:(GLfloat)alpha;
129- (void)drawCompassTargetBlipAt:(Vector)relativePosition Size:(NSSize)siz Alpha:(GLfloat)alpha;
130- (void)drawCompassBeaconBlipAt:(Vector)relativePosition Size:(NSSize)siz Alpha:(GLfloat)alpha;
131
132- (void)drawAegis:(NSDictionary*)info;
133- (void)drawSpeedBar:(NSDictionary*)info;
134- (void)drawRollBar:(NSDictionary*)info;
135- (void)drawPitchBar:(NSDictionary*)info;
136- (void)drawYawBar:(NSDictionary*)info;
137- (void)drawEnergyGauge:(NSDictionary*)info;
138- (void)drawForwardShieldBar:(NSDictionary*)info;
139- (void)drawAftShieldBar:(NSDictionary*)info;
140- (void)drawFuelBar:(NSDictionary*)info;
141- (void)drawWitchspaceDestination:(NSDictionary*)info;
142- (void)drawCabinTempBar:(NSDictionary*)info;
143- (void)drawWeaponTempBar:(NSDictionary*)info;
144- (void)drawAltitudeBar:(NSDictionary*)info;
145- (void)drawMissileDisplay:(NSDictionary*)info;
146- (void)drawTargetReticle:(NSDictionary*)info;
147- (void)drawSecondaryTargetReticle:(NSDictionary*)info;
148- (void)drawWaypoints:(NSDictionary*)info;
149- (void)drawStatusLight:(NSDictionary*)info;
150- (void)drawDirectionCue:(NSDictionary*)info;
151- (void)drawClock:(NSDictionary*)info;
152- (void)drawPrimedEquipmentText:(NSDictionary*)info;
153- (void)drawASCTarget:(NSDictionary*)info;
154- (void)drawWeaponsOfflineText:(NSDictionary*)info;
155- (void)drawMultiFunctionDisplay:(NSDictionary*)info withText:(NSString*)text asIndex:(NSUInteger)index;
156- (void)drawFPSInfoCounter:(NSDictionary*)info;
157- (void)drawScoopStatus:(NSDictionary*)info;
158- (void)drawStickSensitivityIndicator:(NSDictionary*)info;
159- (void)drawCustomBar:(NSDictionary*)info;
160- (void)drawCustomText:(NSDictionary*)info;
161- (void)drawCustomIndicator:(NSDictionary*)info;
162- (void)drawCustomLight:(NSDictionary*)info;
163- (void)drawCustomImage:(NSDictionary*)info;
164
165- (void)drawSurroundInternal:(NSDictionary*)info color:(const GLfloat[4])color;
166- (void)drawSurround:(NSDictionary*)info;
167- (void)drawGreenSurround:(NSDictionary*)info;
168- (void)drawYellowSurround:(NSDictionary*)info;
169
170- (void)drawTrumbles:(NSDictionary*)info;
171
172- (NSArray*)crosshairDefinitionForWeaponType:(OOWeaponType)weapon;
173
174- (BOOL)checkPlayerInFlight;
176
177- (void)resetGui:(GuiDisplayGen*)gui withInfo:(NSDictionary*)gui_info;
178- (void)resetGuiPosition:(GuiDisplayGen*)gui withInfo:(NSDictionary*)gui_info;
179
180@end
181
182@implementation HeadUpDisplay
183
184static const GLfloat red_color[4] = { 1.0, 0.0, 0.0, 1.0 };
185static const GLfloat redplus_color[4] = { 1.0, 0.0, 0.5, 1.0 };
186static const GLfloat yellow_color[4] = { 1.0, 1.0, 0.0, 1.0 };
187static const GLfloat green_color[4] = { 0.0, 1.0, 0.0, 1.0 };
188static const GLfloat darkgreen_color[4] = { 0.0, 0.75, 0.0, 1.0 };
189static const GLfloat blue_color[4] = { 0.0, 0.0, 1.0, 1.0 };
190static const GLfloat black_color[4] = { 0.0, 0.0, 0.0, 1.0 };
191static const GLfloat lightgray_color[4] = { 0.25, 0.25, 0.25, 1.0 };
192
193static float sGlyphWidths[256];
194static float sF6KernGovt;
195static float sF6KernTL;
196static BOOL _compassUpdated;
197
198static GLfloat drawCharacterQuad(uint8_t chr, GLfloat x, GLfloat y, GLfloat z, NSSize siz);
199
200static void InitTextEngine(void);
201
202static void prefetchData(NSDictionary* info, struct CachedInfo* data);
203
204OOINLINE void GLColorWithOverallAlpha(const GLfloat* color, GLfloat alpha)
205{
206 // NO OOGL(), this is called within immediate mode blocks.
207 glColor4f(color[0], color[1], color[2], color[3] * alpha);
208}
209
210- (id)initWithDictionary:(NSDictionary*)hudinfo
211{
212 return [self initWithDictionary:hudinfo inFile:nil];
213}
214
215- (id)initWithDictionary:(NSDictionary*)hudinfo inFile:(NSString*)hudFileName
216{
217 unsigned i;
218 BOOL isCompassToBeDrawn = NO;
219 BOOL areTrumblesToBeDrawn = NO;
220
221 self = [super init];
222
223 lineWidth = 1.0;
224
225 if (sFontTexture == nil)
226 InitTextEngine();
227
228 deferredHudName = nil; // if not nil, it means that we have a deferred HUD which is to be drawn at first available opportunity
229 hudName = [hudFileName copy];
230
231 // init arrays
232 dialArray = [[NSMutableArray alloc] initWithCapacity:16]; // alloc retains
233 legendArray = [[NSMutableArray alloc] initWithCapacity:16]; // alloc retains
234 mfdArray = [[NSMutableArray alloc] initWithCapacity:8]; // alloc retains
235
237
238 // populate arrays
239 NSArray* dials = [hudinfo oo_arrayForKey:DIALS_KEY];
240 for (i = 0; i < [dials count]; i++) {
241 NSDictionary* dial_info = [dials oo_dictionaryAtIndex:i];
242 if (!areTrumblesToBeDrawn && [[dial_info oo_stringForKey:SELECTOR_KEY] isEqualToString:@"drawTrumbles:"])
243 areTrumblesToBeDrawn = YES;
244 if (!isCompassToBeDrawn && [[dial_info oo_stringForKey:SELECTOR_KEY] isEqualToString:@"drawCompass:"])
245 isCompassToBeDrawn = YES;
246 if ([[dial_info oo_stringForKey:SELECTOR_KEY] isEqualToString:@"drawTargetReticle:"]) {
247 _reticleColors = [[NSMutableArray arrayWithObjects:[OOColor colorWithDescription:[dial_info oo_objectForKey:@"target_rgba" defaultValue:@"greenColor"]],
248 [OOColor colorWithDescription:[dial_info oo_objectForKey:@"target_sensitive_rgba" defaultValue:@"redColor"]],
249 [OOColor colorWithDescription:[dial_info oo_objectForKey:@"wormhole_rgba" defaultValue:@"cyanColor"]],
250 nil] retain];
251 }
252 [self addDial:dial_info];
253 }
254
255 // reticle colors should be set at this point, but just be safe in case they are not
256 if (!_reticleColors) {
257 _reticleColors = [[NSMutableArray arrayWithObjects:[OOColor greenColor], [OOColor redColor], [OOColor cyanColor], nil] retain];
258 }
259
260 if (!areTrumblesToBeDrawn) // naughty - a hud with no built-in drawTrumbles: - one must be added!
261 {
262 NSDictionary* trumble_dial_info = [NSDictionary dictionaryWithObjectsAndKeys:@"drawTrumbles:", SELECTOR_KEY, nil];
263 [self addDial:trumble_dial_info];
264 }
265
266 _compassActive = isCompassToBeDrawn;
267
269
270 NSArray* legends = [hudinfo oo_arrayForKey:LEGENDS_KEY];
271 for (i = 0; i < [legends count]; i++) {
272 [self addLegend:[legends oo_dictionaryAtIndex:i]];
273 }
274
275 NSArray* mfds = [hudinfo oo_arrayForKey:MFDS_KEY];
276 for (i = 0; i < [mfds count]; i++) {
277 [self addMFD:[mfds oo_dictionaryAtIndex:i]];
278 }
279
280 hudHidden = NO;
281
282 _hiddenSelectors = [[NSMutableSet alloc] initWithCapacity:16];
283
284 hudUpdating = NO;
285
286 overallAlpha = [hudinfo oo_floatForKey:@"overall_alpha" defaultValue:DEFAULT_OVERALL_ALPHA];
287
288 reticleTargetSensitive = [hudinfo oo_boolForKey:@"reticle_target_sensitive" defaultValue:NO];
289 propertiesReticleTargetSensitive = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
290 [NSNumber numberWithBool:YES], @"isAccurate",
291 [NSNumber numberWithDouble:[UNIVERSE getTime]], @"timeLastAccuracyProbabilityCalculation",
292 nil];
293
294 cloakIndicatorOnStatusLight = [hudinfo oo_boolForKey:@"cloak_indicator_on_status_light" defaultValue:YES];
295
296 allowBigGui = [hudinfo oo_boolForKey:@"allow_big_gui" defaultValue:NO];
297
299
300 [crosshairDefinition release];
301
302 NSString* crossfile = [[hudinfo oo_stringForKey:@"crosshair_file"] retain];
303 if (crossfile == nil) {
304 _crosshairOverrides = [[hudinfo oo_dictionaryForKey:@"crosshairs"] retain];
306 } else {
307 [self setCrosshairDefinition:crossfile];
308 }
309 [crossfile release];
310
311 id crosshairColor = [hudinfo oo_objectForKey:@"crosshair_color" defaultValue:@"greenColor"];
312 _crosshairColor = [[OOColor colorWithDescription:crosshairColor] retain];
313 _crosshairScale = [hudinfo oo_floatForKey:@"crosshair_scale" defaultValue:32.0f];
314 _crosshairWidth = [hudinfo oo_floatForKey:@"crosshair_width" defaultValue:1.5f];
315
316 minimalistic_scanner = [hudinfo oo_boolForKey:@"scanner_minimalistic" defaultValue:NO];
317
318 nonlinear_scanner = [hudinfo oo_boolForKey:@"scanner_non_linear" defaultValue:NO];
319 scanner_ultra_zoom = [hudinfo oo_boolForKey:@"scanner_ultra_zoom" defaultValue:NO];
320
321 distance_unit = DESC(@"oolite-hud-distance-unit");
322
323 return self;
324}
325
342
343//------------------------------------------------------------------------------------//
344
345- (void)resetGui:(GuiDisplayGen*)gui withInfo:(NSDictionary*)gui_info
346{
347 [self resetGuiPosition:gui withInfo:gui_info];
348
349 NSSize siz = [gui size];
350 int rht = [gui rowHeight];
351 NSString* title = [gui title];
352 if ([gui_info objectForKey:WIDTH_KEY])
353 siz.width = [gui_info oo_floatForKey:WIDTH_KEY];
354 if ([gui_info objectForKey:HEIGHT_KEY])
355 siz.height = [gui_info oo_floatForKey:HEIGHT_KEY];
356 if ([gui_info objectForKey:ROW_HEIGHT_KEY])
357 rht = [gui_info oo_floatForKey:ROW_HEIGHT_KEY];
358 if ([gui_info objectForKey:TITLE_KEY])
359 title = [gui_info oo_stringForKey:TITLE_KEY];
360 [gui resizeTo:siz characterHeight:rht title:title];
361 if ([gui_info objectForKey:BACKGROUND_RGBA_KEY])
362 [gui setBackgroundColor:[OOColor colorFromString:[gui_info oo_stringForKey:BACKGROUND_RGBA_KEY]]];
363 if ([gui_info objectForKey:ALPHA_KEY])
364 [gui setMaxAlpha:OOClamp_0_max_f([gui_info oo_floatForKey:ALPHA_KEY], 1.0f)];
365 else
366 [gui setMaxAlpha:1.0f];
367}
368
369- (void)resetGuiPosition:(GuiDisplayGen*)gui withInfo:(NSDictionary*)gui_info
370{
371 Vector pos = [gui drawPosition];
372 if ([gui_info objectForKey:X_KEY])
373 pos.x = [gui_info oo_floatForKey:X_KEY] +
374 [[UNIVERSE gameView] x_offset] *
375 [gui_info oo_floatForKey:X_ORIGIN_KEY
376 defaultValue:0.0];
377 if ([gui_info objectForKey:Y_KEY])
378 pos.y = [gui_info oo_floatForKey:Y_KEY] +
379 [[UNIVERSE gameView] y_offset] *
380 [gui_info oo_floatForKey:Y_ORIGIN_KEY
381 defaultValue:0.0];
382
383 [gui setDrawPosition:pos];
384}
385
386- (void)resetGuis:(NSDictionary*)info
387{
388 // check for entries in hud.plist for message_gui and comm_log_gui
389 // then resize and reposition them accordingly.
390
391 GuiDisplayGen* gui = [UNIVERSE messageGUI];
392 NSDictionary* gui_info = [info oo_dictionaryForKey:@"message_gui"];
393 if (gui && [gui_info count] > 0) {
394 /*
395 If switching message guis, remember the last 2 message lines.
396 Present GUI limitations make it impractical to transfer anything
397 more...
398
399 TODO: a more usable GUI code! - Kaks 2011.11.05
400 */
401
402 NSArray* lastLines = [gui getLastLines]; // text, colour, fade time - text, colour, fade time
403 BOOL line1 = ![[lastLines oo_stringAtIndex:0] isEqualToString:@""];
404 [self resetGui:gui withInfo:gui_info];
405
406 BOOL permanent = [gui_info oo_boolForKey:@"permanent" defaultValue:NO];
407 [UNIVERSE setPermanentMessageLog:permanent];
408
409 BOOL automaticBg = [gui_info oo_boolForKey:@"background_automatic" defaultValue:YES];
410 [UNIVERSE setAutoMessageLogBg:automaticBg];
411
412 // set message gui text colors - one for standard messages, one for incoming comms
413 // incoming comms message color must default to green for compatibility with older huds that
414 // don't have this key
415 [gui setTextColor:[OOColor colorWithDescription:[gui_info objectForKey:@"text_color"]]];
416 OOColor* textCommsColor = [OOColor colorWithDescription:[gui_info objectForKey:@"text_comms_color"]];
417 if (!textCommsColor)
418 textCommsColor = [OOColor greenColor];
419 [gui setTextCommsColor:textCommsColor];
420
421 if (line1) {
422 [gui printLongText:[lastLines oo_stringAtIndex:0]
423 align:GUI_ALIGN_CENTER
424 color:[OOColor colorFromString:[lastLines oo_stringAtIndex:1]]
425 fadeTime:(permanent ? 0.0 : [lastLines oo_floatAtIndex:2])key:nil
426 addToArray:nil];
427 }
428 if ([lastLines count] > 3 && (line1 || ![[lastLines oo_stringAtIndex:3] isEqualToString:@""])) {
429 [gui printLongText:[lastLines oo_stringAtIndex:3]
430 align:GUI_ALIGN_CENTER
431 color:[OOColor colorFromString:[lastLines oo_stringAtIndex:4]]
432 fadeTime:(permanent ? 0.0 : [lastLines oo_floatAtIndex:5])key:nil
433 addToArray:nil];
434 }
435 }
436
437 if (gui_info != nil && [gui_info count] == 0) {
438 // exists and it's empty. complete reset.
439 [gui setCurrentRow:8];
440 [gui setDrawPosition:make_vector(0.0, -40.0, 640.0)];
441 [gui resizeTo:NSMakeSize(480, 160) characterHeight:19 title:nil];
442 [gui setCharacterSize:NSMakeSize(16, 20)]; // narrow characters
445 [UNIVERSE setPermanentMessageLog:NO];
446 [UNIVERSE setAutoMessageLogBg:YES];
447 }
448
449 [gui setAlpha:1.0f]; // message_gui is always visible.
450
451 // And now set up the comms log
452
453 gui = [UNIVERSE commLogGUI];
454 gui_info = [info oo_dictionaryForKey:@"comm_log_gui"];
455
456 if (gui && [gui_info count] > 0) {
457 [UNIVERSE setAutoCommLog:[gui_info oo_boolForKey:@"automatic" defaultValue:YES]];
458 [UNIVERSE setPermanentCommLog:[gui_info oo_boolForKey:@"permanent" defaultValue:NO]];
459
460 /*
461 We need to repopulate the comms log after resetting it.
462
463 At the moment the colour information is set on a per-line basis, rather than a per-text basis.
464 A comms message can span multiple lines, and two consecutive messages can share the same colour,
465 so trying to match the colour information from the GUI with each message won't work.
466
467 Bottom line: colour information is lost on comms log gui reset.
468 And yes, this is yet another reason for the following
469
470 TODO: a more usable GUI code! - Kaks 2011.11.05
471 */
472
473 NSArray* cLog = [PLAYER commLog];
474 NSUInteger i, commCount = [cLog count];
475
476 [self resetGui:gui withInfo:gui_info];
477
478 for (i = 0; i < commCount; i++) {
479 [gui printLongText:[cLog oo_stringAtIndex:i]
480 align:GUI_ALIGN_LEFT
481 color:nil
482 fadeTime:0.0
483 key:nil
484 addToArray:nil];
485 }
486 }
487
488 if (gui_info != nil && [gui_info count] == 0) {
489 // exists and it's empty. complete reset.
490 [UNIVERSE setAutoCommLog:YES];
491 [UNIVERSE setPermanentCommLog:NO];
492 [gui setCurrentRow:9];
493 [gui setDrawPosition:make_vector(0.0, 180.0, 640.0)];
494 [gui resizeTo:NSMakeSize(360, 120) characterHeight:12 title:nil];
497 [gui printLongText:DESC(@"communications-log-string") align:GUI_ALIGN_CENTER color:[OOColor yellowColor] fadeTime:0 key:nil addToArray:nil];
498 }
499
500 if ([UNIVERSE permanentCommLog]) {
502 [gui setAlpha:1.0];
503 } else {
504 [gui setAlpha:0.0];
505 }
506}
507
508- (NSString*)hudName
509{
510 return hudName;
511}
512
513- (void)setHudName:(NSString*)newHudName
514{
515 if (newHudName != nil) {
516 [hudName release];
517 hudName = [newHudName copy];
518 }
519}
520
521- (OOColor*)reticleColorForIndex:(NSUInteger)idx
522{
523 if (idx < [_reticleColors count]) {
524 return [_reticleColors objectAtIndex:idx];
525 }
526 return nil;
527}
528
529- (BOOL)setReticleColorForIndex:(NSUInteger)idx toColor:(OOColor*)newColor
530{
531 if (newColor && idx < [_reticleColors count]) {
532 [_reticleColors replaceObjectAtIndex:idx withObject:newColor];
533 return YES;
534 }
535 return NO;
536}
537
538- (GLfloat)scannerZoom
539{
540 return scanner_zoom;
541}
542
543- (void)setScannerZoom:(GLfloat)value
544{
545 scanner_zoom = value;
546}
547
548- (GLfloat)overallAlpha
549{
550 return overallAlpha;
551}
552
553- (void)setOverallAlpha:(GLfloat)newAlphaValue
554{
555 overallAlpha = OOClamp_0_1_f(newAlphaValue);
556}
557
559{
561}
562
563- (void)setReticleTargetSensitive:(BOOL)newReticleTargetSensitiveValue
564{
565 reticleTargetSensitive = !!newReticleTargetSensitiveValue; // ensure YES or NO.
566}
567
568- (NSMutableDictionary*)propertiesReticleTargetSensitive
569{
571}
572
573- (BOOL)isHidden
574{
575 return hudHidden;
576}
577
578- (void)setHidden:(BOOL)newValue
579{
580 hudHidden = !!newValue; // ensure YES or NO
581}
582
584{
585 return allowBigGui || hudHidden;
586}
587
588- (BOOL)hasHidden:(NSString*)selectorName
589{
590 if (selectorName == nil) {
591 return NO;
592 }
593 return [_hiddenSelectors containsObject:selectorName];
594}
595
596- (void)setHiddenSelector:(NSString*)selectorName hidden:(BOOL)hide
597{
598 if (hide) {
599 [_hiddenSelectors addObject:selectorName];
600 } else {
601 [_hiddenSelectors removeObject:selectorName];
602 }
603}
604
606{
607 [_hiddenSelectors removeAllObjects];
608}
609
611{
612 return _compassActive;
613}
614
615- (void)setCompassActive:(BOOL)newValue
616{
617 _compassActive = !!newValue;
618}
619
621{
622 return hudUpdating;
623}
624
625- (void)setDeferredHudName:(NSString*)newDeferredHudName
626{
627 [deferredHudName release];
629}
630
631- (NSString*)deferredHudName
632{
633 return deferredHudName;
634}
635
636- (void)addLegend:(NSDictionary*)info
637{
638 NSString* imageName = nil;
639 OOTexture* texture = nil;
640 NSSize imageSize;
641 OOTextureSprite* legendSprite = nil;
642 NSMutableDictionary* legendDict = nil;
643 struct CachedInfo cache;
644
645 // prefetch data associated with this legend
646 prefetchData(info, &cache);
647
648 imageName = [info oo_stringForKey:IMAGE_KEY];
649 if (imageName != nil) {
650 texture = [OOTexture textureWithName:imageName
651 inFolder:@"Images"
652 options:kOOTextureDefaultOptions | kOOTextureNoShrink
653 anisotropy:kOOTextureDefaultAnisotropy
654 lodBias:kOOTextureDefaultLODBias];
655 if (texture == nil) {
656 OOLogERR(kOOLogFileNotFound, @"HeadUpDisplay couldn't get an image texture name for %@", imageName);
657 return;
658 }
659
660 imageSize = [texture dimensions];
661 imageSize.width = [info oo_floatForKey:WIDTH_KEY defaultValue:imageSize.width];
662 imageSize.height = [info oo_floatForKey:HEIGHT_KEY defaultValue:imageSize.height];
663
664 legendSprite = [[OOTextureSprite alloc] initWithTexture:texture size:imageSize];
665
666 legendDict = [info mutableCopy];
667 [legendDict setObject:legendSprite forKey:SPRITE_KEY];
668 // add WIDGET_INFO, WIDGET_CACHE to array
669 [legendArray addObject:[NSArray arrayWithObjects:legendDict, [NSValue valueWithBytes:&cache objCType:@encode(struct CachedInfo)], nil]];
670 [legendDict release];
671 [legendSprite release];
672 } else if ([info oo_stringForKey:TEXT_KEY] != nil) {
673 // add WIDGET_INFO, WIDGET_CACHE to array
674 [legendArray addObject:[NSArray arrayWithObjects:info, [NSValue valueWithBytes:&cache objCType:@encode(struct CachedInfo)], nil]];
675 }
676}
677
678- (void)addDial:(NSDictionary*)info
679{
680 static NSSet* allowedSelectors = nil;
681 if (allowedSelectors == nil) {
682 NSDictionary* whitelist = [ResourceManager whitelistDictionary];
683 allowedSelectors = [[NSSet alloc] initWithArray:[whitelist oo_arrayForKey:@"hud_dial_methods"]];
684 }
685
686 NSString* selectorString = [info oo_stringForKey:SELECTOR_KEY];
687 if (selectorString == nil) {
688 OOLogERR(@"hud.dial.noSelector", @"HUD dial in %@ is missing selector.", hudName);
689 return;
690 }
691
692 if (![allowedSelectors containsObject:selectorString]) {
693 OOLogERR(@"hud.dial.invalidSelector", @"HUD dial in %@ uses selector \"%@\" which is not in whitelist, and will be ignored.", hudName, selectorString);
694 return;
695 }
696
697 SEL selector = NSSelectorFromString(selectorString);
698
699 NSAssert2([self respondsToSelector:selector], @"HUD dial in %@ uses selector \"%@\" which is in whitelist, but not implemented.", hudName, selectorString);
700
701 // handle the case above with NS_BLOCK_ASSERTIONS too.
702 if (![self respondsToSelector:selector]) {
703 OOLogERR(@"hud.dial.invalidSelector", @"HUD dial in %@ uses selector \"%@\" which is in whitelist, but not implemented, and will be ignored.", hudName, selectorString);
704 return;
705 }
706
707 // valid dial, now prefetch data
708 struct CachedInfo cache;
709 prefetchData(info, &cache);
710 // add WIDGET_INFO, WIDGET_CACHE, WIDGET_SELECTOR, WIDGET_SELECTOR_NAME to array
711 [dialArray addObject:[NSArray arrayWithObjects:info, [NSValue valueWithBytes:&cache objCType:@encode(struct CachedInfo)],
712 [NSValue valueWithPointer:selector], selectorString, nil]];
713}
714
715- (void)addMFD:(NSDictionary*)info
716{
717 struct CachedInfo cache;
718 prefetchData(info, &cache);
719 [mfdArray addObject:[NSArray arrayWithObjects:info, [NSValue valueWithBytes:&cache objCType:@encode(struct CachedInfo)], nil]];
720}
721
722- (NSUInteger)mfdCount
723{
724 return [mfdArray count];
725}
726
727/*
728 SLOW_CODE
729 As of 2012-09-13 (r5320), HUD rendering is taking 25%-30% of rendering time,
730 or 15%-20% of game tick time, as tested on a couple of Macs using the
731 default HUD and models. This could be worse - there used to be a note here
732 saying 30%-40% of tick time - but could still improve.
733
734 In a top-down perspective, of HUD rendering time, 67% is in -drawDials and
735 27% is in -drawLegends.
736
737 Bottom-up, one profile shows:
738 21.2% OODrawString()
739 (Caching the glyph conversion here was a win, but caching geometry
740 in vertex arrays/VBOs would be better.)
741 8.9% -[HeadUpDisplay drawHudItem:]
742 5.1% OOFloatFromObject
743 (Reifying HUD info instead of parsing plists each frame would be
744 a win.)
745 4.4% hudDrawBarAt()
746 (Using fixed geometery and a vertex shader could help here,
747 especially if bars are grouped together and drawn at once if
748 possible.)
749 4.3% -[OOCrosshairs render]
750 (Uses vertex arrays, but does more GL state manipulation than
751 strictly necessary.)
752
753*/
755{
756 hudUpdating = YES;
757
759
760 if ((_crosshairWidth * lineWidth) > 0) {
762 [self drawCrosshairs];
763 }
764
765 if (lineWidth > 0) {
767 [self drawLegends];
768 }
769
770 [self drawDials];
771 [self drawMFDs];
772 OOCheckOpenGLErrors(@"After drawing HUD");
773
775
776 hudUpdating = NO;
777}
778
780{
781 /* Since the order of legend drawing is significant, this loop must be kept
782 * as an incrementing one for compatibility with previous Oolite versions.
783 * CIM: 28/9/12 */
784 z1 = [[UNIVERSE gameView] display_z];
785 NSUInteger i, nLegends = [legendArray count];
786 for (i = 0; i < nLegends; i++) {
787 sCurrentDrawItem = [legendArray oo_arrayAtIndex:i];
788 [self drawLegend:[sCurrentDrawItem oo_dictionaryAtIndex:WIDGET_INFO]];
789 }
790}
791
793{
794 z1 = [[UNIVERSE gameView] display_z];
795 // reset drawScanner flag.
796 _compassUpdated = NO;
797
798 // tight loop, we assume dialArray doesn't change in mid-draw.
799 NSUInteger i, nDials = [dialArray count];
800 for (i = 0; i < nDials; i++) {
801 sCurrentDrawItem = [dialArray oo_arrayAtIndex:i];
802 [self drawHUDItem:[sCurrentDrawItem oo_dictionaryAtIndex:WIDGET_INFO]];
803 }
804
805 if (EXPECT_NOT(!_compassUpdated && _compassActive && [self checkPlayerInSystemFlight])) // compass gone / broken / disabled ?
806 {
807 // trigger the targetChanged event with whom == null
808 _compassActive = NO;
809 [PLAYER doScriptEvent:OOJSID("compassTargetChanged") withArguments:[NSArray arrayWithObjects:[NSNull null], OOStringFromCompassMode([PLAYER compassMode]), nil]];
810 }
811}
812
813- (void)drawMFDs
814{
815 NSUInteger i, nMFDs = [mfdArray count];
816 NSString* text = nil;
817 for (i = 0; i < nMFDs; i++) {
818 text = [PLAYER multiFunctionText:i];
819 if (text != nil) {
820 sCurrentDrawItem = [mfdArray oo_arrayAtIndex:i];
821 [self drawMultiFunctionDisplay:[sCurrentDrawItem oo_dictionaryAtIndex:WIDGET_INFO] withText:text asIndex:i];
822 }
823 }
824}
825
827{
828 OOViewID viewID = [UNIVERSE viewDirection];
829 OOWeaponType weapon = [PLAYER currentWeapon];
830 BOOL weaponsOnline = [PLAYER weaponsOnline];
831 NSArray* points = nil;
832
833 if (viewID == VIEW_CUSTOM || overallAlpha == 0.0f || !([PLAYER status] == STATUS_IN_FLIGHT || [PLAYER status] == STATUS_WITCHSPACE_COUNTDOWN) ||
834 [UNIVERSE displayGUI]) {
835 // Don't draw crosshairs
836 return;
837 }
838
839 if (weapon != _lastWeaponType || overallAlpha != _lastOverallAlpha || weaponsOnline != _lastWeaponsOnline) {
840 DESTROY(_crosshairs);
841 }
842
843 if (_crosshairs == nil) {
844 GLfloat useAlpha = weaponsOnline ? overallAlpha : overallAlpha * 0.5f;
845
846 // Make new crosshairs object
847 points = [self crosshairDefinitionForWeaponType:weapon];
848
849 _crosshairs = [[OOCrosshairs alloc] initWithPoints:points
850 scale:_crosshairScale
851 color:_crosshairColor
852 overallAlpha:useAlpha];
853 _lastWeaponType = weapon;
854 _lastOverallAlpha = useAlpha;
855 _lastWeaponsOnline = weaponsOnline;
856 }
857
858 [_crosshairs render];
859}
860
862{
863 return crosshairDefinition;
864}
865
866- (BOOL)setCrosshairDefinition:(NSString*)newDefinition
867{
868 // force crosshair redraw
869 [_crosshairs release];
871
872 [_crosshairOverrides release];
874 inFolder:@"Config"
875 andMerge:YES] retain];
876 if (_crosshairOverrides == nil || [_crosshairOverrides count] == 0) { // invalid file
877 [_crosshairOverrides release];
879 inFolder:@"Config"
880 andMerge:YES] retain];
881 crosshairDefinition = @"crosshairs.plist";
882 return NO;
883 }
885 return YES;
886}
887
888- (NSArray*)crosshairDefinitionForWeaponType:(OOWeaponType)weapon
889{
890 NSString* weaponName = nil;
891 NSString* weaponName2 = nil;
892 static NSDictionary* crosshairDefs = nil;
893 NSArray* result = nil;
894
895 /* Search order:
896 (hud.plist).crosshairs.WEAPON_NAME
897 (hud.plist).crosshairs.OTHER
898 (crosshairs.plist).WEAPON_NAME
899 (crosshairs.plist).OTHER
900 */
901
902 weaponName = OOStringFromWeaponType(weapon);
903 weaponName2 = [weaponName substringFromIndex:3]; // strip "EQ_"
904 result = [_crosshairOverrides oo_arrayForKey:weaponName];
905 if (result == nil) {
906 result = [_crosshairOverrides oo_arrayForKey:weaponName2];
907 }
908 if (result == nil)
909 result = [_crosshairOverrides oo_arrayForKey:@"OTHER"];
910 if (result == nil) {
911 if (crosshairDefs == nil) {
912 crosshairDefs = [ResourceManager dictionaryFromFilesNamed:@"crosshairs.plist"
913 inFolder:@"Config"
914 andMerge:YES];
915 [crosshairDefs retain];
916 }
917
918 result = [crosshairDefs oo_arrayForKey:weaponName];
919 if (result == nil) {
920 result = [crosshairDefs oo_arrayForKey:weaponName2];
921 }
922 if (result == nil)
923 result = [crosshairDefs oo_arrayForKey:@"OTHER"];
924 }
925
926 return result;
927}
928
929- (void)drawLegend:(NSDictionary*)info
930{
931 // check if equipment is required
932 NSString* equipmentRequired = [info oo_stringForKey:EQUIPMENT_REQUIRED_KEY];
933 if (equipmentRequired != nil && ![PLAYER hasEquipmentItemProviding:equipmentRequired]) {
934 return;
935 }
936
937 // check alert condition
938 NSUInteger alertMask = [info oo_unsignedIntForKey:ALERT_CONDITIONS_KEY defaultValue:15];
939 // 1=docked, 2=green, 4=yellow, 8=red
940 if (alertMask < 15) {
941 OOAlertCondition alertCondition = [PLAYER alertCondition];
942 if (~alertMask & (1 << alertCondition)) {
943 return;
944 }
945 }
946
947 BOOL viewOnly = [info oo_boolForKey:VIEWSCREEN_KEY defaultValue:NO];
948 // 1=docked, 2=green, 4=yellow, 8=red
949 if (viewOnly && [PLAYER guiScreen] != GUI_SCREEN_MAIN) {
950 return;
951 }
952
953 // check association with hidden dials
954 if ([self hasHidden:[info oo_stringForKey:DIAL_REQUIRED_KEY defaultValue:nil]]) {
955 return;
956 }
957
958 OOTextureSprite* legendSprite = nil;
959 NSString* legendText = nil;
960 float x, y;
961 NSSize size;
962 GLfloat alpha = overallAlpha;
963 struct CachedInfo cached;
964
965 [(NSValue*)[sCurrentDrawItem objectAtIndex:WIDGET_CACHE] getValue:&cached];
966
967 // if either x or y is missing, use 0 instead
968
969 x = useDefined(cached.x, 0.0f) + [[UNIVERSE gameView] x_offset] * cached.x0;
970 y = useDefined(cached.y, 0.0f) + [[UNIVERSE gameView] y_offset] * cached.y0;
971 alpha *= cached.alpha;
972
973 legendSprite = [info objectForKey:SPRITE_KEY];
974 if (legendSprite != nil) {
975 [legendSprite blitCentredToX:x Y:y Z:z1 alpha:alpha];
976 } else {
977 legendText = [info oo_stringForKey:TEXT_KEY];
978 if (legendText != nil) {
979 // randomly chosen default width & height
980 size.width = useDefined(cached.width, 14.0f);
981 size.height = useDefined(cached.height, 8.0f);
983 if ([info oo_intForKey:@"align"] == 1) {
984 OODrawStringAligned(legendText, x, y, z1, size, YES);
985 } else {
986 OODrawStringAligned(legendText, x, y, z1, size, NO);
987 }
988 }
989 }
990}
991
992- (void)drawHUDItem:(NSDictionary*)info
993{
994 NSString* equipment = [info oo_stringForKey:EQUIPMENT_REQUIRED_KEY];
995
996 if (equipment != nil && ![PLAYER hasEquipmentItemProviding:equipment]) {
997 return;
998 }
999
1000 // check alert condition
1001 NSUInteger alertMask = [info oo_unsignedIntForKey:ALERT_CONDITIONS_KEY defaultValue:15];
1002 // 1=docked, 2=green, 4=yellow, 8=red
1003 if (alertMask < 15) {
1004 OOAlertCondition alertCondition = [PLAYER alertCondition];
1005 if (~alertMask & (1 << alertCondition)) {
1006 return;
1007 }
1008 }
1009
1010 BOOL viewOnly = [info oo_boolForKey:VIEWSCREEN_KEY defaultValue:NO];
1011
1012 // 1=docked, 2=green, 4=yellow, 8=red
1013 if (viewOnly && [PLAYER guiScreen] != GUI_SCREEN_MAIN) {
1014 return;
1015 }
1016
1017 if (EXPECT_NOT([self hasHidden:[sCurrentDrawItem objectAtIndex:WIDGET_SELECTOR_NAME]])) {
1018 return;
1019 }
1020
1021 // use the selector value stored during init.
1022 [self performSelector:[(NSValue*)[sCurrentDrawItem objectAtIndex:WIDGET_SELECTOR] pointerValue] withObject:info];
1023 OOCheckOpenGLErrors(@"HeadUpDisplay after drawHUDItem %@", info);
1024
1026}
1027
1029{
1030 return [PLAYER isInSpace] && [PLAYER status] != STATUS_DOCKING;
1031}
1032
1034{
1035 OOSunEntity* the_sun = [UNIVERSE sun];
1036 OOPlanetEntity* the_planet = [UNIVERSE planet];
1037
1038 return [self checkPlayerInFlight] // be in the right mode
1039 && the_sun && the_planet // and be in a system
1040 && ![the_sun goneNova];
1041}
1042
1043static void prefetchData(NSDictionary* info, struct CachedInfo* data)
1044{
1045 data->x = [info oo_floatForKey:X_KEY defaultValue:NOT_DEFINED];
1046 data->x0 = [info oo_floatForKey:X_ORIGIN_KEY defaultValue:0.0];
1047 data->y = [info oo_floatForKey:Y_KEY defaultValue:NOT_DEFINED];
1048 data->y0 = [info oo_floatForKey:Y_ORIGIN_KEY defaultValue:0.0];
1049 data->width = [info oo_floatForKey:WIDTH_KEY defaultValue:NOT_DEFINED];
1050 data->height = [info oo_floatForKey:HEIGHT_KEY defaultValue:NOT_DEFINED];
1051 data->alpha = [info oo_nonNegativeFloatForKey:ALPHA_KEY defaultValue:1.0f];
1052}
1053
1054//---------------------------------------------------------------------//
1055
1056- (void)drawScanner:(NSDictionary*)info
1057{
1058 int i, x, y;
1059 NSSize siz;
1060 GLfloat scanner_color[4] = { 1.0, 0.0, 0.0, 1.0 };
1061
1062 BOOL emptyDial = ([info oo_floatForKey:ALPHA_KEY] == 0.0f);
1063
1064 BOOL isHostile = NO;
1065
1066 BOOL inColorBlindMode = [UNIVERSE colorblindMode] != OO_POSTFX_NONE;
1067
1068 if (emptyDial) {
1069 // we can skip a lot of code.
1070 x = y = 0;
1071 scanner_color[3] = 0.0; // nothing to see!
1072 siz = NSMakeSize(1.0, 1.0); // avoid divide by 0s
1073 } else {
1074 struct CachedInfo cached;
1075
1076 [(NSValue*)[sCurrentDrawItem objectAtIndex:WIDGET_CACHE] getValue:&cached];
1077
1078 x = useDefined(cached.x, SCANNER_CENTRE_X) + [[UNIVERSE gameView] x_offset] * cached.x0;
1079 y = useDefined(cached.y, SCANNER_CENTRE_Y) + [[UNIVERSE gameView] y_offset] * cached.y0;
1080 siz.width = useDefined(cached.width, SCANNER_WIDTH);
1081 siz.height = useDefined(cached.height, SCANNER_HEIGHT);
1082
1083 GetRGBAArrayFromInfo(info, scanner_color);
1084
1085 scanner_color[3] *= overallAlpha;
1086 }
1087
1088 GLfloat alpha = scanner_color[3];
1089 GLfloat col[4] = { 1.0, 1.0, 1.0, alpha }; // temporary colour variable
1090
1091 GLfloat z_factor = siz.height / siz.width; // approx 1/4
1092 GLfloat y_factor = 1.0 - sqrt(z_factor); // approx 1/2
1093
1094 int scanner_cx = x;
1095 int scanner_cy = y;
1096
1097 int scannerFootprint = SCANNER_MAX_RANGE * 2.5 / siz.width;
1098
1099 GLfloat zoom = scanner_zoom;
1100 if (scanner_ultra_zoom)
1101 zoom = pow(2, zoom - 1.0);
1102 GLfloat max_zoomed_range2 = SCANNER_SCALE * SCANNER_SCALE * 10000.0;
1103 if (!nonlinear_scanner) {
1104 max_zoomed_range2 /= zoom * zoom;
1105 }
1106 GLfloat max_zoomed_range = sqrt(max_zoomed_range2);
1107
1108 if (PLAYER == nil)
1109 return;
1110
1111 OOMatrix rotMatrix = [PLAYER rotationMatrix];
1112 Vector relativePosition;
1113 int flash = ((int)([UNIVERSE getTime] * 4)) & 1;
1114
1115 // use a non-mutable copy so this can't be changed under us.
1116 int ent_count = UNIVERSE->n_entities;
1117 Entity** uni_entities = UNIVERSE->sortedEntities; // grab the public sorted list
1118 Entity* my_entities[ent_count];
1119 Entity* scannedEntity = nil;
1120
1121 for (i = 0; i < ent_count; i++) {
1122 my_entities[i] = [uni_entities[i] retain]; // retained
1123 }
1124
1125 if (!emptyDial) {
1126 OOGL(glColor4fv(scanner_color));
1127 drawScannerGrid(x, y, z1, siz, [UNIVERSE viewDirection], lineWidth, zoom, nonlinear_scanner, minimalistic_scanner);
1128 }
1129
1130 if ([self checkPlayerInFlight]) {
1131 GLfloat upscale = zoom * 1.25 / scannerFootprint;
1132 GLfloat max_blip = 0.0;
1133 int drawClass;
1134
1136
1137 // Debugging code for nonlinear scanner - draws three fake cascade weapons, which looks pretty and enables me
1138 // to debug the code without the mass slaughter of innocent civillians.
1139 // if (nonlinear_scanner)
1140 //{
1141 // Vector p = OOVectorMultiplyMatrix(make_vector(10000.0, 0.0, 0.0), rotMatrix);
1142 // GLDrawNonlinearCascadeWeapon( scanner_cx, scanner_cy, z1, siz, p, 5000, zoom, alpha );
1143 // p = OOVectorMultiplyMatrix(make_vector(10000.0, 4500.0, 0.0), rotMatrix);
1144 // GLDrawNonlinearCascadeWeapon( scanner_cx, scanner_cy, z1, siz, p, 2000, zoom, alpha );
1145 // p = OOVectorMultiplyMatrix(make_vector(0.0, 0.0, 20000.0), rotMatrix);
1146 // GLDrawNonlinearCascadeWeapon( scanner_cx, scanner_cy, z1, siz, p, 6000, zoom, alpha );
1147 //}
1148 for (i = 0; i < ent_count; i++) // scanner lollypops
1149 {
1150 scannedEntity = my_entities[i];
1151
1152 drawClass = [scannedEntity scanClass];
1153
1154 // cloaked ships - and your own one - don't show up on the scanner.
1155 if (EXPECT_NOT(drawClass == CLASS_PLAYER || ([scannedEntity isShip] && [(ShipEntity*)scannedEntity isCloaked]))) {
1156 drawClass = CLASS_NO_DRAW;
1157 }
1158
1159 if (drawClass != CLASS_NO_DRAW) {
1160 GLfloat x1, y1, y2;
1161 float ms_blip = 0.0;
1162
1163 if (emptyDial)
1164 continue;
1165
1166 if (isnan(scannedEntity->zero_distance))
1167 continue;
1168
1169 // exit if it's too far away
1170 GLfloat act_dist = sqrt(scannedEntity->zero_distance);
1171 GLfloat lim_dist = act_dist - scannedEntity->collision_radius;
1172
1173 // for efficiency, assume no scannable entity > 10km radius
1174 if (act_dist > max_zoomed_range + 10000.0)
1175 break;
1176
1177 if (lim_dist > max_zoomed_range)
1178 continue;
1179
1180 // has it sent a recent message
1181 //
1182 if ([scannedEntity isShip])
1183 ms_blip = 2.0 * [(ShipEntity*)scannedEntity messageTime];
1184 if (ms_blip > max_blip) {
1185 max_blip = ms_blip;
1186 last_transmitter = [scannedEntity universalID];
1187 }
1188 ms_blip -= floor(ms_blip);
1189
1190 relativePosition = [PLAYER vectorTo:scannedEntity];
1191 double fuzz = [PLAYER scannerFuzziness];
1192 if (fuzz > 0 && ![[UNIVERSE gameController] isGamePaused]) {
1193 relativePosition = vector_add(relativePosition, OOVectorRandomRadial(fuzz));
1194 }
1195
1196 Vector rp = relativePosition;
1197
1198 if (act_dist > max_zoomed_range)
1199 scale_vector(&relativePosition, max_zoomed_range / act_dist);
1200
1201 // rotate the view
1202 relativePosition = OOVectorMultiplyMatrix(relativePosition, rotMatrix);
1203 Vector rrp = relativePosition;
1204 // scale the view
1205 if (nonlinear_scanner) {
1206 relativePosition = [HeadUpDisplay nonlinearScannerScale:relativePosition Zoom:zoom Scale:0.5 * siz.width];
1207 } else {
1208 scale_vector(&relativePosition, upscale);
1209 }
1210
1211 x1 = relativePosition.x;
1212 y1 = z_factor * relativePosition.z;
1213 y2 = y1 + y_factor * relativePosition.y;
1214
1215 isHostile = NO;
1216 if ([scannedEntity isShip]) {
1217 ShipEntity* ship = (ShipEntity*)scannedEntity;
1218 isHostile = (([ship hasHostileTarget]) && ([ship primaryTarget] == PLAYER));
1219 GLfloat* base_col = [ship scannerDisplayColorForShip:PLAYER
1220 isHostile:isHostile
1221 flash:flash
1223 scannerDisplayColor2:[ship scannerDisplayColor2]
1224 scannerDisplayColorH1:[ship scannerDisplayColorHostile1]
1225 scannerDisplayColorH2:[ship scannerDisplayColorHostile2]];
1226 col[0] = base_col[0];
1227 col[1] = base_col[1];
1228 col[2] = base_col[2];
1229 col[3] = alpha * base_col[3];
1230 } else if ([scannedEntity isVisualEffect]) {
1231 OOVisualEffectEntity* vis = (OOVisualEffectEntity*)scannedEntity;
1232 GLfloat* base_col = [vis scannerDisplayColorForShip:flash scannerDisplayColor1:[vis scannerDisplayColor1] scannerDisplayColor2:[vis scannerDisplayColor2]];
1233 col[0] = base_col[0];
1234 col[1] = base_col[1];
1235 col[2] = base_col[2];
1236 col[3] = alpha * base_col[3];
1237 }
1238
1239 if ([scannedEntity isWormhole]) {
1240 col[0] = blue_color[0];
1241 col[1] = (flash) ? 1.0 : blue_color[1];
1242 col[2] = blue_color[2];
1243 col[3] = alpha * blue_color[3];
1244 }
1245
1246 // position the scanner
1247 x1 += scanner_cx;
1248 y1 += scanner_cy;
1249 y2 += scanner_cy;
1250
1251 if ([scannedEntity isShip]) {
1252 ShipEntity* ship = (ShipEntity*)scannedEntity;
1253 if ((!nonlinear_scanner && ship->collision_radius * upscale > 4.5) || (nonlinear_scanner && nonlinearScannerFunc(act_dist, zoom, siz.width) - nonlinearScannerFunc(lim_dist, zoom, siz.width) > 4.5)) {
1254 Vector bounds[6];
1255 BoundingBox bb = ship->totalBoundingBox;
1256 bounds[0] = ship->v_forward;
1257 scale_vector(&bounds[0], bb.max.z);
1258 bounds[1] = ship->v_forward;
1259 scale_vector(&bounds[1], bb.min.z);
1260 bounds[2] = ship->v_right;
1261 scale_vector(&bounds[2], bb.max.x);
1262 bounds[3] = ship->v_right;
1263 scale_vector(&bounds[3], bb.min.x);
1264 bounds[4] = ship->v_up;
1265 scale_vector(&bounds[4], bb.max.y);
1266 bounds[5] = ship->v_up;
1267 scale_vector(&bounds[5], bb.min.y);
1268 // rotate the view
1269 int i;
1270 for (i = 0; i < 6; i++) {
1271 bounds[i] = OOVectorMultiplyMatrix(vector_add(bounds[i], rp), rotMatrix);
1272 if (nonlinear_scanner) {
1273 bounds[i] = [HeadUpDisplay nonlinearScannerScale:bounds[i] Zoom:zoom Scale:0.5 * siz.width];
1274 } else {
1275 scale_vector(&bounds[i], upscale);
1276 }
1277 bounds[i] = make_vector(bounds[i].x + scanner_cx, bounds[i].z * z_factor + bounds[i].y * y_factor + scanner_cy, z1);
1278 }
1279 // draw the diamond
1280 //
1281 OOGLBEGIN(GL_QUADS);
1282 glColor4f(col[0], col[1], col[2], 0.33333 * col[3]);
1283 glVertex3f(bounds[0].x, bounds[0].y, bounds[0].z);
1284 glVertex3f(bounds[4].x, bounds[4].y, bounds[4].z);
1285 glVertex3f(bounds[1].x, bounds[1].y, bounds[1].z);
1286 glVertex3f(bounds[5].x, bounds[5].y, bounds[5].z);
1287 glVertex3f(bounds[2].x, bounds[2].y, bounds[2].z);
1288 glVertex3f(bounds[4].x, bounds[4].y, bounds[4].z);
1289 glVertex3f(bounds[3].x, bounds[3].y, bounds[3].z);
1290 glVertex3f(bounds[5].x, bounds[5].y, bounds[5].z);
1291 glVertex3f(bounds[2].x, bounds[2].y, bounds[2].z);
1292 glVertex3f(bounds[0].x, bounds[0].y, bounds[0].z);
1293 glVertex3f(bounds[3].x, bounds[3].y, bounds[3].z);
1294 glVertex3f(bounds[1].x, bounds[1].y, bounds[1].z);
1295 OOGLEND();
1296 }
1297 }
1298
1299 if (ms_blip > 0.0) {
1300 DrawSpecialOval(x1 - 0.5, y2 + 1.5, z1, NSMakeSize(16.0 * (1.0 - ms_blip), 8.0 * (1.0 - ms_blip)), 30, col);
1301 }
1302 if ([scannedEntity isCascadeWeapon]) {
1303 if (nonlinear_scanner) {
1304 GLDrawNonlinearCascadeWeapon(scanner_cx, scanner_cy, z1, siz, rrp, scannedEntity->collision_radius, zoom, alpha);
1305 } else {
1306 GLfloat r1 = 2.5 + scannedEntity->collision_radius * upscale;
1307 GLfloat l2 = r1 * r1 - relativePosition.y * relativePosition.y;
1308 GLfloat r0 = (l2 > 0) ? sqrt(l2) : 0;
1309 if (r0 > 0) {
1310 OOGL(glColor4f(1.0, 0.5, 1.0, alpha));
1311 GLDrawOval(x1 - 0.5, y1 + 1.5, z1, NSMakeSize(r0, r0 * siz.height / siz.width), 20);
1312 }
1313 OOGL(glColor4f(0.5, 0.0, 1.0, 0.33333 * alpha));
1314 GLDrawFilledOval(x1 - 0.5, y2 + 1.5, z1, NSMakeSize(r1, r1), 15);
1315 }
1316 } else {
1317
1318#if IDENTIFY_SCANNER_LOLLIPOPS
1319 if ([scannedEntity isShip]) {
1320 glColor4f(1.0, 1.0, 0.5, alpha);
1321 OODrawString([(ShipEntity*)scannedEntity displayName], x1 + 2, y2 + 2, z1, NSMakeSize(8, 8));
1322 }
1323#endif
1324 glColor4fv(col);
1325 if (inColorBlindMode && isHostile) {
1326 // in colorblind mode turn hostile blips into X shapes for easier recognition
1327 OOGLBEGIN(GL_LINES);
1328 glVertex3f(x1 + 2, y2 + 3, z1);
1329 glVertex3f(x1 - 3, y2, z1);
1330 glVertex3f(x1 + 2, y2, z1);
1331 glVertex3f(x1 - 3, y2 + 3, z1);
1332 OOGLEND();
1333 } else {
1334 OOGLBEGIN(GL_QUADS);
1335 glVertex3f(x1 - 3, y2, z1);
1336 glVertex3f(x1 + 2, y2, z1);
1337 glVertex3f(x1 + 2, y2 + 3, z1);
1338 glVertex3f(x1 - 3, y2 + 3, z1);
1339 OOGLEND();
1340 }
1341 OOGLBEGIN(GL_QUADS); // lollipop tail
1342 col[3] *= 0.3333; // one third the alpha
1343 glColor4fv(col);
1344 glVertex3f(x1, y1, z1);
1345 glVertex3f(x1 + 2, y1, z1);
1346 glVertex3f(x1 + 2, y2, z1);
1347 glVertex3f(x1, y2, z1);
1348 OOGLEND();
1349 }
1350 }
1351 }
1352 }
1353
1354 for (i = 0; i < ent_count; i++) {
1355 [my_entities[i] release]; // released
1356 }
1357
1359}
1360
1362{
1363 return minimalistic_scanner;
1364}
1365
1366- (void)setMinimalisticScanner:(BOOL)newValue
1367{
1368 minimalistic_scanner = !!newValue;
1369}
1370
1371+ (Vector)nonlinearScannerScale:(Vector)V Zoom:(GLfloat)zoom Scale:(double)scale
1372{
1373 OOScalar mag = magnitude(V);
1374 Vector unit = vector_normal(V);
1375 return vector_multiply_scalar(unit, nonlinearScannerFunc(mag, zoom, scale));
1376}
1377
1379{
1380 return nonlinear_scanner;
1381}
1382
1383- (void)setNonlinearScanner:(BOOL)newValue
1384{
1385 nonlinear_scanner = !!newValue;
1386}
1387
1389{
1390 return scanner_ultra_zoom;
1391}
1392
1393- (void)setScannerUltraZoom:(BOOL)newValue
1394{
1395 scanner_ultra_zoom = !!newValue;
1396}
1397
1399{
1400 Entity* lt = [UNIVERSE entityForUniversalID:last_transmitter];
1401 if ((lt == nil) || (!(lt->isShip)))
1402 return;
1403 ShipEntity* st = (ShipEntity*)lt;
1404 if ([st messageTime] <= 0.0)
1405 [st setMessageTime:2.5];
1406}
1407
1408- (void)drawScannerZoomIndicator:(NSDictionary*)info
1409{
1410 int x, y;
1411 NSSize siz;
1412 GLfloat alpha;
1413 GLfloat zoom_color[4] = { 1.0f, 0.1f, 0.0f, 1.0f };
1414 struct CachedInfo cached;
1415
1416 [(NSValue*)[sCurrentDrawItem objectAtIndex:WIDGET_CACHE] getValue:&cached];
1417
1418 x = useDefined(cached.x, ZOOM_INDICATOR_CENTRE_X) + [[UNIVERSE gameView] x_offset] * cached.x0;
1419 y = useDefined(cached.y, ZOOM_INDICATOR_CENTRE_Y) + [[UNIVERSE gameView] y_offset] * cached.y0;
1420 siz.width = useDefined(cached.width, ZOOM_INDICATOR_WIDTH);
1421 siz.height = useDefined(cached.height, ZOOM_INDICATOR_HEIGHT);
1422
1423 GetRGBAArrayFromInfo(info, zoom_color);
1424 zoom_color[3] *= overallAlpha;
1425 alpha = zoom_color[3];
1426
1427 GLfloat cx = x - 0.3 * siz.width;
1428 GLfloat cy = y - 0.75 * siz.height;
1429
1430 int zl = scanner_zoom;
1431 if (zl < 1)
1432 zl = 1;
1433 if (zl > SCANNER_ZOOM_LEVELS)
1435 if (zl == 1)
1436 zoom_color[3] *= 0.75;
1437 if (scanner_ultra_zoom)
1438 zl = pow(2, zl - 1);
1439 GLColorWithOverallAlpha(zoom_color, alpha);
1440 OOGL(glEnable(GL_TEXTURE_2D));
1442
1443 OOGLBEGIN(GL_QUADS);
1444 if (zl / 10 > 0)
1445 drawCharacterQuad(48 + zl / 10, cx - 0.8 * siz.width, cy, z1, siz);
1446 drawCharacterQuad(48 + zl % 10, cx - 0.4 * siz.width, cy, z1, siz);
1447 drawCharacterQuad(58, cx, cy, z1, siz);
1448 drawCharacterQuad(49, cx + 0.3 * siz.width, cy, z1, siz);
1449 OOGLEND();
1450
1452 OOGL(glDisable(GL_TEXTURE_2D));
1453}
1454
1455- (void)drawCompass:(NSDictionary*)info
1456{
1457 int x, y;
1458 NSSize siz;
1459 GLfloat alpha;
1460 GLfloat compass_color[4] = { 0.0f, 0.0f, 1.0f, 1.0f };
1461 struct CachedInfo cached;
1462
1463 [(NSValue*)[sCurrentDrawItem objectAtIndex:WIDGET_CACHE] getValue:&cached];
1464
1465 x = useDefined(cached.x, COMPASS_CENTRE_X) + [[UNIVERSE gameView] x_offset] * cached.x0;
1466 y = useDefined(cached.y, COMPASS_CENTRE_Y) + [[UNIVERSE gameView] y_offset] * cached.y0;
1467 siz.width = useDefined(cached.width, COMPASS_HALF_SIZE);
1468 siz.height = useDefined(cached.height, COMPASS_HALF_SIZE);
1469
1470 GetRGBAArrayFromInfo(info, compass_color);
1471 compass_color[3] *= overallAlpha;
1472 alpha = compass_color[3];
1473
1474 // draw the compass
1475 OOMatrix rotMatrix = [PLAYER rotationMatrix];
1476
1477 GLfloat h1 = siz.height * 0.125;
1478 GLfloat h3 = siz.height * 0.375;
1479 GLfloat w1 = siz.width * 0.125;
1480 GLfloat w3 = siz.width * 0.375;
1481 OOGL(GLScaledLineWidth(2.0 * lineWidth)); // thicker
1482 OOGL(glColor4f(compass_color[0], compass_color[1], compass_color[2], alpha));
1483 GLDrawOval(x, y, z1, siz, 12);
1484 OOGL(glColor4f(compass_color[0], compass_color[1], compass_color[2], 0.5f * alpha));
1485 OOGLBEGIN(GL_LINES);
1486 glVertex3f(x - w1, y, z1);
1487 glVertex3f(x - w3, y, z1);
1488 glVertex3f(x + w1, y, z1);
1489 glVertex3f(x + w3, y, z1);
1490 glVertex3f(x, y - h1, z1);
1491 glVertex3f(x, y - h3, z1);
1492 glVertex3f(x, y + h1, z1);
1493 glVertex3f(x, y + h3, z1);
1494 OOGLEND();
1495 OOGL(GLScaledLineWidth(lineWidth)); // thinner
1496
1497 if ([self checkPlayerInSystemFlight] && [PLAYER status] != STATUS_LAUNCHING) // normal system
1498 {
1499 Entity* reference = [PLAYER compassTarget];
1500
1501 // translate and rotate the view
1502
1503 Vector relativePosition = [PLAYER vectorTo:reference];
1504 relativePosition = OOVectorMultiplyMatrix(relativePosition, rotMatrix);
1505 relativePosition = vector_normal_or_fallback(relativePosition, kBasisZVector);
1506
1507 relativePosition.x *= siz.width * 0.4;
1508 relativePosition.y *= siz.height * 0.4;
1509 relativePosition.x += x;
1510 relativePosition.y += y;
1511
1512 siz.width *= 0.2;
1513 siz.height *= 0.2;
1514 OOGL(GLScaledLineWidth(2.0 * lineWidth));
1515 switch ([PLAYER compassMode]) {
1516 case COMPASS_MODE_INACTIVE:
1517 break;
1518
1519 case COMPASS_MODE_BASIC:
1520 if ([reference isStation]) // validateCompassTarget in PlayerEntity.m changes COMPASS_BASIC_MODE target to the main station when inside the planetary aegis or in docking range of the main station
1521 [self drawCompassStationBlipAt:relativePosition Size:siz Alpha:alpha];
1522 else
1523 [self drawCompassPlanetBlipAt:relativePosition Size:siz Alpha:alpha];
1524 break;
1525
1526 case COMPASS_MODE_PLANET:
1527 [self drawCompassPlanetBlipAt:relativePosition Size:siz Alpha:alpha];
1528 break;
1529
1530 case COMPASS_MODE_STATION:
1531 [self drawCompassStationBlipAt:relativePosition Size:siz Alpha:alpha];
1532 break;
1533
1534 case COMPASS_MODE_SUN:
1535 [self drawCompassSunBlipAt:relativePosition Size:siz Alpha:alpha];
1536 break;
1537
1538 case COMPASS_MODE_TARGET:
1539 [self drawCompassTargetBlipAt:relativePosition Size:siz Alpha:alpha];
1540 break;
1541
1542 case COMPASS_MODE_BEACONS:
1543 [self drawCompassBeaconBlipAt:relativePosition Size:siz Alpha:alpha];
1544 Entity<OOBeaconEntity>* beacon = [PLAYER nextBeacon];
1545 [[beacon beaconDrawable] oo_drawHUDBeaconIconAt:NSMakePoint(x, y) size:siz alpha:alpha z:z1];
1546 break;
1547 }
1548 OOGL(GLScaledLineWidth(lineWidth)); // reset
1549
1550 _compassUpdated = YES;
1551 _compassActive = YES;
1552 }
1553}
1554
1555OOINLINE void SetCompassBlipColor(GLfloat relativeZ, GLfloat alpha)
1556{
1557 if (relativeZ >= 0.0f) {
1558 OOGL(glColor4f(0.0f, 1.0f, 0.0f, alpha));
1559 } else {
1560 OOGL(glColor4f(1.0f, 0.0f, 0.0f, alpha));
1561 }
1562}
1563
1564- (void)drawCompassPlanetBlipAt:(Vector)relativePosition Size:(NSSize)siz Alpha:(GLfloat)alpha
1565{
1566 if (relativePosition.z >= 0) {
1567 OOGL(glColor4f(0.0, 1.0, 0.0, 0.75 * alpha));
1568 GLDrawFilledOval(relativePosition.x, relativePosition.y, z1, siz, 30);
1569 OOGL(glColor4f(0.0, 1.0, 0.0, alpha));
1570 GLDrawOval(relativePosition.x, relativePosition.y, z1, siz, 30);
1571 } else {
1572 OOGL(glColor4f(1.0, 0.0, 0.0, alpha));
1573 GLDrawOval(relativePosition.x, relativePosition.y, z1, siz, 30);
1574 }
1575}
1576
1577- (void)drawCompassStationBlipAt:(Vector)relativePosition Size:(NSSize)siz Alpha:(GLfloat)alpha
1578{
1579 SetCompassBlipColor(relativePosition.z, alpha);
1580
1581 OOGLBEGIN(GL_LINE_LOOP);
1582 glVertex3f(relativePosition.x - 0.5 * siz.width, relativePosition.y - 0.5 * siz.height, z1);
1583 glVertex3f(relativePosition.x + 0.5 * siz.width, relativePosition.y - 0.5 * siz.height, z1);
1584 glVertex3f(relativePosition.x + 0.5 * siz.width, relativePosition.y + 0.5 * siz.height, z1);
1585 glVertex3f(relativePosition.x - 0.5 * siz.width, relativePosition.y + 0.5 * siz.height, z1);
1586 OOGLEND();
1587}
1588
1589- (void)drawCompassSunBlipAt:(Vector)relativePosition Size:(NSSize)siz Alpha:(GLfloat)alpha
1590{
1591 OOGL(glColor4f(1.0, 1.0, 0.0, 0.75 * alpha));
1592 GLDrawFilledOval(relativePosition.x, relativePosition.y, z1, siz, 30);
1593
1594 SetCompassBlipColor(relativePosition.z, alpha);
1595
1596 GLDrawOval(relativePosition.x, relativePosition.y, z1, siz, 30);
1597}
1598
1599- (void)drawCompassTargetBlipAt:(Vector)relativePosition Size:(NSSize)siz Alpha:(GLfloat)alpha
1600{
1601 SetCompassBlipColor(relativePosition.z, alpha);
1602
1603 OOGLBEGIN(GL_LINES);
1604 glVertex3f(relativePosition.x - siz.width, relativePosition.y, z1);
1605 glVertex3f(relativePosition.x + siz.width, relativePosition.y, z1);
1606 glVertex3f(relativePosition.x, relativePosition.y - siz.height, z1);
1607 glVertex3f(relativePosition.x, relativePosition.y + siz.height, z1);
1608 OOGLEND();
1609
1610 GLDrawOval(relativePosition.x, relativePosition.y, z1, siz, 30);
1611}
1612
1613- (void)drawCompassBeaconBlipAt:(Vector)relativePosition Size:(NSSize)siz Alpha:(GLfloat)alpha
1614{
1615 SetCompassBlipColor(relativePosition.z, alpha);
1616
1617 OOGLBEGIN(GL_LINES);
1618 /* glVertex3f(relativePosition.x - 0.5 * siz.width, relativePosition.y - 0.5 * siz.height, z1);
1619 glVertex3f(relativePosition.x, relativePosition.y + 0.5 * siz.height, z1);
1620
1621 glVertex3f(relativePosition.x + 0.5 * siz.width, relativePosition.y - 0.5 * siz.height, z1);
1622 glVertex3f(relativePosition.x, relativePosition.y + 0.5 * siz.height, z1);
1623
1624 glVertex3f(relativePosition.x - 0.5 * siz.width, relativePosition.y - 0.5 * siz.height, z1);
1625 glVertex3f(relativePosition.x + 0.5 * siz.width, relativePosition.y - 0.5 * siz.height, z1); */
1626 glVertex3f(relativePosition.x + 0.6 * siz.width, relativePosition.y, z1);
1627 glVertex3f(relativePosition.x, relativePosition.y + 0.6 * siz.height, z1);
1628
1629 glVertex3f(relativePosition.x - 0.6 * siz.width, relativePosition.y, z1);
1630 glVertex3f(relativePosition.x, relativePosition.y + 0.6 * siz.height, z1);
1631
1632 glVertex3f(relativePosition.x + 0.6 * siz.width, relativePosition.y, z1);
1633 glVertex3f(relativePosition.x, relativePosition.y - 0.6 * siz.height, z1);
1634
1635 glVertex3f(relativePosition.x - 0.6 * siz.width, relativePosition.y, z1);
1636 glVertex3f(relativePosition.x, relativePosition.y - 0.6 * siz.height, z1);
1637
1638 OOGLEND();
1639}
1640
1641- (void)drawAegis:(NSDictionary*)info
1642{
1643 if (([UNIVERSE viewDirection] == VIEW_GUI_DISPLAY) || ([UNIVERSE sun] == nil) || ([PLAYER checkForAegis] != AEGIS_IN_DOCKING_RANGE))
1644 return; // don't draw
1645
1646 int x, y;
1647 NSSize siz;
1648 GLfloat alpha = 0.5f * overallAlpha;
1649 struct CachedInfo cached;
1650
1651 [(NSValue*)[sCurrentDrawItem objectAtIndex:WIDGET_CACHE] getValue:&cached];
1652
1653 x = useDefined(cached.x, AEGIS_CENTRE_X) + [[UNIVERSE gameView] x_offset] * cached.x0;
1654 y = useDefined(cached.y, AEGIS_CENTRE_Y) + [[UNIVERSE gameView] y_offset] * cached.y0;
1655 siz.width = useDefined(cached.width, AEGIS_WIDTH);
1656 siz.height = useDefined(cached.height, AEGIS_HEIGHT);
1657 alpha *= cached.alpha;
1658
1659 // draw the aegis indicator
1660 //
1661 GLfloat w = siz.width / 16.0;
1662 GLfloat h = siz.height / 16.0;
1663
1664 GLfloat strip[] = { -7, 8, -6, 5, 5, 8, 3, 5, 7, 2, 4, 2, 6, -1, 4, 2, -4, -1, -6, 2, -4, -1, -7, -1, -3, -4, -5, -7, 6, -4, 7, -7 };
1665
1666#if 1
1667 OOGL(glColor4f(0.0f, 1.0f, 0.0f, alpha));
1668 OOGLBEGIN(GL_QUAD_STRIP);
1669 int i;
1670 for (i = 0; i < 32; i += 2) {
1671 glVertex3f(x + w * strip[i], y - h * strip[i + 1], z1);
1672 }
1673 OOGLEND();
1674#else
1677 OOGLScaleModelView(make_vector(w, -h, 1.0f));
1678
1679 OOGL(glColor4f(0.0f, 1.0f, 0.0f, alpha));
1680 OOGL(glVertexPointer(2, GL_FLOAT, 0, strip));
1681 OOGL(glEnableClientState(GL_VERTEX_ARRAY));
1682 OOGL(glDisableClientState(GL_COLOR_ARRAY));
1683
1684 OOGL(glDrawArrays(GL_QUAD_STRIP, 0, sizeof strip / sizeof *strip / 2));
1685 OOGL(glDisableClientState(GL_VERTEX_ARRAY));
1686
1688#endif
1689}
1690
1691- (void)drawCustomBar:(NSDictionary*)info
1692{
1693 int x, y;
1694 NSSize siz;
1695 BOOL draw_surround;
1696 GLfloat alpha = overallAlpha;
1697 GLfloat ds = OOClamp_0_1_f([PLAYER dialCustomFloat:[info oo_stringForKey:CUSTOM_DIAL_KEY]]);
1698 struct CachedInfo cached;
1699
1700 [(NSValue*)[sCurrentDrawItem objectAtIndex:WIDGET_CACHE] getValue:&cached];
1701
1702 x = useDefined(cached.x, 0) + [[UNIVERSE gameView] x_offset] * cached.x0;
1703 y = useDefined(cached.y, 0) + [[UNIVERSE gameView] y_offset] * cached.y0;
1704 siz.width = useDefined(cached.width, 50);
1705 siz.height = useDefined(cached.height, 8);
1706 alpha *= cached.alpha;
1707
1708 draw_surround = [info oo_boolForKey:DRAW_SURROUND_KEY defaultValue:NO];
1709
1711 if (draw_surround) {
1712 // draw custom surround
1713 hudDrawSurroundAt(x, y, z1, siz);
1714 }
1715 // draw custom bar
1716 if (ds > .75) {
1718 } else if (ds > .25) {
1720 } else {
1722 }
1723
1724 hudDrawBarAt(x, y, z1, siz, ds);
1725}
1726
1727- (void)drawCustomText:(NSDictionary*)info
1728{
1729 int x, y;
1730 NSSize size;
1731 GLfloat alpha = overallAlpha;
1732 NSString* text = [PLAYER dialCustomString:[info oo_stringForKey:CUSTOM_DIAL_KEY]];
1733 struct CachedInfo cached;
1734
1735 [(NSValue*)[sCurrentDrawItem objectAtIndex:WIDGET_CACHE] getValue:&cached];
1736
1737 x = useDefined(cached.x, 0) + [[UNIVERSE gameView] x_offset] * cached.x0;
1738 y = useDefined(cached.y, 0) + [[UNIVERSE gameView] y_offset] * cached.y0;
1739 alpha *= cached.alpha;
1740
1742
1743 size.width = useDefined(cached.width, 10.0f);
1744 size.height = useDefined(cached.height, 10.0f);
1745
1746 if ([info oo_intForKey:@"align"] == 1) {
1747 OODrawStringAligned(text, x, y, z1, size, YES);
1748 } else {
1749 OODrawStringAligned(text, x, y, z1, size, NO);
1750 }
1751}
1752
1753- (void)drawCustomIndicator:(NSDictionary*)info
1754{
1755 int x, y;
1756 NSSize siz;
1757 BOOL draw_surround;
1758 GLfloat alpha = overallAlpha;
1759 GLfloat iv = OOClamp_n1_1_f([PLAYER dialCustomFloat:[info oo_stringForKey:CUSTOM_DIAL_KEY]]);
1760
1761 struct CachedInfo cached;
1762
1763 [(NSValue*)[sCurrentDrawItem objectAtIndex:WIDGET_CACHE] getValue:&cached];
1764
1765 x = useDefined(cached.x, 0) + [[UNIVERSE gameView] x_offset] * cached.x0;
1766 y = useDefined(cached.y, 0) + [[UNIVERSE gameView] y_offset] * cached.y0;
1767 siz.width = useDefined(cached.width, 50);
1768 siz.height = useDefined(cached.height, 8);
1769 alpha *= cached.alpha;
1770 draw_surround = [info oo_boolForKey:DRAW_SURROUND_KEY defaultValue:NO];
1771
1772 if (draw_surround) {
1773 // draw custom surround
1775 hudDrawSurroundAt(x, y, z1, siz);
1776 }
1777 // draw custom indicator
1779 hudDrawIndicatorAt(x, y, z1, siz, iv);
1780}
1781
1782- (void)drawCustomLight:(NSDictionary*)info
1783{
1784 int x, y;
1785 NSSize siz;
1786 GLfloat alpha = overallAlpha;
1787
1788 struct CachedInfo cached;
1789
1790 [(NSValue*)[sCurrentDrawItem objectAtIndex:WIDGET_CACHE] getValue:&cached];
1791
1792 x = useDefined(cached.x, 0) + [[UNIVERSE gameView] x_offset] * cached.x0;
1793 y = useDefined(cached.y, 0) + [[UNIVERSE gameView] y_offset] * cached.y0;
1794 siz.width = useDefined(cached.width, 8);
1795 siz.height = useDefined(cached.height, 8);
1796 alpha *= cached.alpha;
1797
1798 GLfloat light_color[4] = { 0.25, 0.25, 0.25, 0.0 };
1799
1800 OOColor* color = [PLAYER dialCustomColor:[info oo_stringForKey:CUSTOM_DIAL_KEY]];
1801 [color getRed:&light_color[0]
1802 green:&light_color[1]
1803 blue:&light_color[2]
1804 alpha:&light_color[3]];
1805
1806 GLColorWithOverallAlpha(light_color, alpha);
1807 OOGLBEGIN(GL_POLYGON);
1808 hudDrawStatusIconAt(x, y, z1, siz);
1809 OOGLEND();
1810 OOGL(glColor4f(0.25, 0.25, 0.25, alpha));
1811 OOGLBEGIN(GL_LINE_LOOP);
1812 hudDrawStatusIconAt(x, y, z1, siz);
1813 OOGLEND();
1814}
1815
1816- (void)drawCustomImage:(NSDictionary*)info
1817{
1818 int x, y;
1819 GLfloat alpha = overallAlpha;
1820
1821 struct CachedInfo cached;
1822
1823 [(NSValue*)[sCurrentDrawItem objectAtIndex:WIDGET_CACHE] getValue:&cached];
1824
1825 x = useDefined(cached.x, 0) + [[UNIVERSE gameView] x_offset] * cached.x0;
1826 y = useDefined(cached.y, 0) + [[UNIVERSE gameView] y_offset] * cached.y0;
1827 alpha *= cached.alpha;
1828
1829 NSString* textureFile = [PLAYER dialCustomString:[info oo_stringForKey:CUSTOM_DIAL_KEY]];
1830 if (textureFile == nil || [textureFile length] == 0) {
1831 return;
1832 }
1833
1834 OOTexture* texture = [OOTexture textureWithName:textureFile
1835 inFolder:@"Images"
1836 options:kOOTextureDefaultOptions | kOOTextureNoShrink
1837 anisotropy:kOOTextureDefaultAnisotropy
1838 lodBias:kOOTextureDefaultLODBias];
1839 if (texture == nil) {
1840 OOLogERR(kOOLogFileNotFound, @"HeadUpDisplay couldn't get an image texture name for %@", textureFile);
1841 return;
1842 }
1843
1844 NSSize imageSize = [texture dimensions];
1845 imageSize.width = useDefined(cached.width, imageSize.width);
1846 imageSize.height = useDefined(cached.height, imageSize.height);
1847
1848 /* There's possibly some optimisation which could be done by
1849 * caching the sprite, but regenerating it each frame doesn't
1850 * appear to take any significant amount of time compared with the
1851 * time taken to actually render it and the texture will be
1852 * returned from the cache anyway. - CIM */
1853 OOTextureSprite* sprite = [[OOTextureSprite alloc] initWithTexture:texture size:imageSize];
1854
1855 [sprite blitCentredToX:x Y:y Z:z1 alpha:alpha];
1856 [sprite release];
1857}
1858
1859- (void)drawSpeedBar:(NSDictionary*)info
1860{
1861 int x, y;
1862 NSSize siz;
1863 BOOL draw_surround;
1864 GLfloat alpha = overallAlpha;
1865 GLfloat ds = [PLAYER dialSpeed];
1866 struct CachedInfo cached;
1867
1868 [(NSValue*)[sCurrentDrawItem objectAtIndex:WIDGET_CACHE] getValue:&cached];
1869
1870 x = useDefined(cached.x, SPEED_BAR_CENTRE_X) + [[UNIVERSE gameView] x_offset] * cached.x0;
1871 y = useDefined(cached.y, SPEED_BAR_CENTRE_Y) + [[UNIVERSE gameView] y_offset] * cached.y0;
1872 siz.width = useDefined(cached.width, SPEED_BAR_WIDTH);
1873 siz.height = useDefined(cached.height, SPEED_BAR_HEIGHT);
1874 alpha *= cached.alpha;
1875
1876 draw_surround = [info oo_boolForKey:DRAW_SURROUND_KEY defaultValue:SPEED_BAR_DRAW_SURROUND];
1877
1879 if (draw_surround) {
1880 // draw speed surround
1881 hudDrawSurroundAt(x, y, z1, siz);
1882 }
1883 // draw speed bar
1884 if (ds > .80) {
1886 } else if (ds > .25) {
1888 } else {
1890 }
1891
1892 hudDrawBarAt(x, y, z1, siz, ds);
1893}
1894
1895- (void)drawRollBar:(NSDictionary*)info
1896{
1897 int x, y;
1898 NSSize siz;
1899 BOOL draw_surround;
1900 GLfloat alpha = overallAlpha;
1901 struct CachedInfo cached;
1902
1903 [(NSValue*)[sCurrentDrawItem objectAtIndex:WIDGET_CACHE] getValue:&cached];
1904
1905 x = useDefined(cached.x, ROLL_BAR_CENTRE_X) + [[UNIVERSE gameView] x_offset] * cached.x0;
1906 y = useDefined(cached.y, ROLL_BAR_CENTRE_Y) + [[UNIVERSE gameView] y_offset] * cached.y0;
1907 siz.width = useDefined(cached.width, ROLL_BAR_WIDTH);
1908 siz.height = useDefined(cached.height, ROLL_BAR_HEIGHT);
1909 alpha *= cached.alpha;
1910 draw_surround = [info oo_boolForKey:DRAW_SURROUND_KEY defaultValue:ROLL_BAR_DRAW_SURROUND];
1911
1912 if (draw_surround) {
1913 // draw ROLL surround
1915 hudDrawSurroundAt(x, y, z1, siz);
1916 }
1917 // draw ROLL bar
1919 hudDrawIndicatorAt(x, y, z1, siz, [PLAYER dialRoll]);
1920}
1921
1922- (void)drawPitchBar:(NSDictionary*)info
1923{
1924 int x, y;
1925 NSSize siz;
1926 BOOL draw_surround;
1927 GLfloat alpha = overallAlpha;
1928 struct CachedInfo cached;
1929
1930 [(NSValue*)[sCurrentDrawItem objectAtIndex:WIDGET_CACHE] getValue:&cached];
1931
1932 x = useDefined(cached.x, PITCH_BAR_CENTRE_X) + [[UNIVERSE gameView] x_offset] * cached.x0;
1933 y = useDefined(cached.y, PITCH_BAR_CENTRE_Y) + [[UNIVERSE gameView] y_offset] * cached.y0;
1934 siz.width = useDefined(cached.width, PITCH_BAR_WIDTH);
1935 siz.height = useDefined(cached.height, PITCH_BAR_HEIGHT);
1936 alpha *= cached.alpha;
1937 draw_surround = [info oo_boolForKey:DRAW_SURROUND_KEY defaultValue:PITCH_BAR_DRAW_SURROUND];
1938
1939 if (draw_surround) {
1940 // draw PITCH surround
1942 hudDrawSurroundAt(x, y, z1, siz);
1943 }
1944 // draw PITCH bar
1946 hudDrawIndicatorAt(x, y, z1, siz, [PLAYER dialPitch]);
1947}
1948
1949- (void)drawYawBar:(NSDictionary*)info
1950{
1951 int x, y;
1952 NSSize siz;
1953 BOOL draw_surround;
1954 GLfloat alpha = overallAlpha;
1955 struct CachedInfo cached;
1956
1957 [(NSValue*)[sCurrentDrawItem objectAtIndex:WIDGET_CACHE] getValue:&cached];
1958
1959 // No standard YAW definitions - using PITCH ones instead.
1960 x = useDefined(cached.x, PITCH_BAR_CENTRE_X) + [[UNIVERSE gameView] x_offset] * cached.x0;
1961 y = useDefined(cached.y, PITCH_BAR_CENTRE_Y) + [[UNIVERSE gameView] y_offset] * cached.y0;
1962 siz.width = useDefined(cached.width, PITCH_BAR_WIDTH);
1963 siz.height = useDefined(cached.height, PITCH_BAR_HEIGHT);
1964 alpha *= cached.alpha;
1965 draw_surround = [info oo_boolForKey:DRAW_SURROUND_KEY defaultValue:PITCH_BAR_DRAW_SURROUND];
1966
1967 if (draw_surround) {
1968 // draw YAW surround
1970 hudDrawSurroundAt(x, y, z1, siz);
1971 }
1972 // draw YAW bar
1974 hudDrawIndicatorAt(x, y, z1, siz, [PLAYER dialYaw]);
1975}
1976
1977- (void)drawEnergyGauge:(NSDictionary*)info
1978{
1979 int x, y;
1980 unsigned i;
1981 NSSize siz;
1982 BOOL drawSurround, labelled, energyCritical = NO;
1983 GLfloat alpha = overallAlpha;
1984 GLfloat bankHeight, bankY;
1985 PlayerEntity* player = PLAYER;
1986
1987 unsigned n_bars = [player dialMaxEnergy] / 64.0;
1988 n_bars = [info oo_unsignedIntForKey:N_BARS_KEY defaultValue:n_bars];
1989 if (n_bars < 1) {
1990 n_bars = 1;
1991 }
1992 GLfloat energy = [player dialEnergy] * n_bars;
1993 struct CachedInfo cached;
1994
1995 [(NSValue*)[sCurrentDrawItem objectAtIndex:WIDGET_CACHE] getValue:&cached];
1996
1997 x = useDefined(cached.x, ENERGY_GAUGE_CENTRE_X) + [[UNIVERSE gameView] x_offset] * cached.x0;
1998 y = useDefined(cached.y, ENERGY_GAUGE_CENTRE_Y) + [[UNIVERSE gameView] y_offset] * cached.y0;
1999 siz.width = useDefined(cached.width, ENERGY_GAUGE_WIDTH);
2000 siz.height = useDefined(cached.height, ENERGY_GAUGE_HEIGHT);
2001 alpha *= cached.alpha;
2002 drawSurround = [info oo_boolForKey:DRAW_SURROUND_KEY defaultValue:ENERGY_GAUGE_DRAW_SURROUND];
2003 labelled = [info oo_boolForKey:LABELLED_KEY defaultValue:YES];
2004 if (n_bars > 8)
2005 labelled = NO;
2006
2007 if (drawSurround) {
2008 // draw energy surround
2010 hudDrawSurroundAt(x, y, z1, siz);
2011 }
2012
2013 bankHeight = siz.height / n_bars;
2014 // draw energy banks
2015 NSSize barSize = NSMakeSize(siz.width, bankHeight - 2.0); // leave a gap between bars
2016 GLfloat midBank = bankHeight / 2.0f;
2017 bankY = y - (n_bars - 1) * midBank - 1.0;
2018
2019 // avoid constant colour switching...
2020 if (labelled) {
2021 GLColorWithOverallAlpha(green_color, alpha);
2022 GLfloat labelStartX = x + 0.5f * barSize.width + 3.0f;
2023 NSSize labelSize = NSMakeSize(9.0, (bankHeight < 18.0) ? bankHeight : 18.0);
2024 for (i = 0; i < n_bars; i++) {
2025 OODrawString([NSString stringWithFormat:@"E%x", n_bars - i], labelStartX, bankY - midBank, z1, labelSize);
2026 bankY += bankHeight;
2027 }
2028 }
2029
2030 if (energyCritical) {
2032 } else {
2034 }
2035 bankY = y - (n_bars - 1) * midBank;
2036 for (i = 0; i < n_bars; i++) {
2037 if (energy > 1.0) {
2038 hudDrawBarAt(x, bankY, z1, barSize, 1.0);
2039 } else if (energy > 0.0) {
2040 hudDrawBarAt(x, bankY, z1, barSize, energy);
2041 }
2042
2043 energy -= 1.0;
2044 bankY += bankHeight;
2045 }
2046}
2047
2048- (void)drawForwardShieldBar:(NSDictionary*)info
2049{
2050 int x, y;
2051 NSSize siz;
2052 BOOL draw_surround;
2053 GLfloat alpha = overallAlpha;
2054 GLfloat shield = [PLAYER dialForwardShield];
2055 struct CachedInfo cached;
2056
2057 [(NSValue*)[sCurrentDrawItem objectAtIndex:WIDGET_CACHE] getValue:&cached];
2058
2059 x = useDefined(cached.x, FORWARD_SHIELD_BAR_CENTRE_X) + [[UNIVERSE gameView] x_offset] * cached.x0;
2060 y = useDefined(cached.y, FORWARD_SHIELD_BAR_CENTRE_Y) + [[UNIVERSE gameView] y_offset] * cached.y0;
2061 siz.width = useDefined(cached.width, FORWARD_SHIELD_BAR_WIDTH);
2062 siz.height = useDefined(cached.height, FORWARD_SHIELD_BAR_HEIGHT);
2063 alpha *= cached.alpha;
2064 draw_surround = [info oo_boolForKey:DRAW_SURROUND_KEY defaultValue:FORWARD_SHIELD_BAR_DRAW_SURROUND];
2065
2066 if (draw_surround) {
2067 // draw forward_shield surround
2069 hudDrawSurroundAt(x, y, z1, siz);
2070 }
2071 // draw forward_shield bar
2072 if (shield < .25) {
2074 } else if (shield < .80) {
2076 } else {
2078 }
2079 hudDrawBarAt(x, y, z1, siz, shield);
2080}
2081
2082- (void)drawAftShieldBar:(NSDictionary*)info
2083{
2084 int x, y;
2085 NSSize siz;
2086 BOOL draw_surround;
2087 GLfloat alpha = overallAlpha;
2088 GLfloat shield = [PLAYER dialAftShield];
2089 struct CachedInfo cached;
2090
2091 [(NSValue*)[sCurrentDrawItem objectAtIndex:WIDGET_CACHE] getValue:&cached];
2092
2093 x = useDefined(cached.x, AFT_SHIELD_BAR_CENTRE_X) + [[UNIVERSE gameView] x_offset] * cached.x0;
2094 y = useDefined(cached.y, AFT_SHIELD_BAR_CENTRE_Y) + [[UNIVERSE gameView] y_offset] * cached.y0;
2095 siz.width = useDefined(cached.width, AFT_SHIELD_BAR_WIDTH);
2096 siz.height = useDefined(cached.height, AFT_SHIELD_BAR_HEIGHT);
2097 alpha *= cached.alpha;
2098 draw_surround = [info oo_boolForKey:DRAW_SURROUND_KEY defaultValue:AFT_SHIELD_BAR_DRAW_SURROUND];
2099
2100 if (draw_surround) {
2101 // draw forward_shield surround
2103 hudDrawSurroundAt(x, y, z1, siz);
2104 }
2105 // draw forward_shield bar
2106 if (shield < .25) {
2108 } else if (shield < .80) {
2110 } else {
2112 }
2113 hudDrawBarAt(x, y, z1, siz, shield);
2114}
2115
2116- (void)drawFuelBar:(NSDictionary*)info
2117{
2118 int x, y;
2119 NSSize siz;
2120 BOOL draw_surround;
2121 float fu, hr;
2122 GLfloat alpha = overallAlpha;
2123 struct CachedInfo cached;
2124
2125 [(NSValue*)[sCurrentDrawItem objectAtIndex:WIDGET_CACHE] getValue:&cached];
2126
2127 x = useDefined(cached.x, FUEL_BAR_CENTRE_X) + [[UNIVERSE gameView] x_offset] * cached.x0;
2128 y = useDefined(cached.y, FUEL_BAR_CENTRE_Y) + [[UNIVERSE gameView] y_offset] * cached.y0;
2129 siz.width = useDefined(cached.width, FUEL_BAR_WIDTH);
2130 siz.height = useDefined(cached.height, FUEL_BAR_HEIGHT);
2131 alpha *= cached.alpha;
2132 draw_surround = [info oo_boolForKey:DRAW_SURROUND_KEY defaultValue:NO];
2133
2134 if (draw_surround) {
2136 hudDrawSurroundAt(x, y, z1, siz);
2137 }
2138
2139 fu = [PLAYER dialFuel];
2140 hr = [PLAYER dialHyperRange];
2141
2142 // draw fuel bar
2144 hudDrawBarAt(x, y, z1, siz, fu);
2145
2146 // draw range indicator
2147 if (hr > 0.0f && hr <= 1.0f) {
2148 if ([PLAYER hasSufficientFuelForJump]) {
2150 } else {
2152 }
2153 hudDrawMarkerAt(x, y, z1, siz, hr);
2154 }
2155}
2156
2157- (void)drawWitchspaceDestination:(NSDictionary*)info
2158{
2159 // A zero-distance jump counts as 0.1LY
2160 if ([PLAYER dialHyperRange] == 0.0f) {
2161 return;
2162 }
2163
2164 int x, y;
2165 NSSize siz;
2166 GLfloat alpha = overallAlpha;
2167
2168 struct CachedInfo cached;
2169
2170 [(NSValue*)[sCurrentDrawItem objectAtIndex:WIDGET_CACHE] getValue:&cached];
2171
2172 x = useDefined(cached.x, WITCHDEST_CENTRE_X) + [[UNIVERSE gameView] x_offset] * cached.x0;
2173 y = useDefined(cached.y, WITCHDEST_CENTRE_Y) + [[UNIVERSE gameView] y_offset] * cached.y0;
2174 siz.width = useDefined(cached.width, WITCHDEST_WIDTH);
2175 siz.height = useDefined(cached.height, WITCHDEST_HEIGHT);
2176 alpha *= cached.alpha;
2177 NSString* dest = [UNIVERSE getSystemName:[PLAYER targetSystemID]];
2178 NSInteger concealment = [[[UNIVERSE systemManager] getPropertiesForSystem:[PLAYER targetSystemID] inGalaxy:[PLAYER galaxyNumber]] oo_intForKey:@"concealment" defaultValue:OO_SYSTEMCONCEALMENT_NONE];
2179 if (concealment >= OO_SYSTEMCONCEALMENT_NONAME)
2180 dest = DESC(@"status-unknown-system");
2181
2183
2184 if ([info oo_intForKey:@"align"] == 1) {
2185 OODrawStringAligned(dest, x, y, z1, siz, YES);
2186 } else {
2187 OODrawStringAligned(dest, x, y, z1, siz, NO);
2188 }
2189}
2190
2191- (void)drawCabinTempBar:(NSDictionary*)info
2192{
2193 int x, y;
2194 NSSize siz;
2195 BOOL draw_surround;
2196 GLfloat temp = [PLAYER hullHeatLevel];
2197 GLfloat alpha = overallAlpha;
2198 struct CachedInfo cached;
2199
2200 [(NSValue*)[sCurrentDrawItem objectAtIndex:WIDGET_CACHE] getValue:&cached];
2201
2202 x = useDefined(cached.x, CABIN_TEMP_BAR_CENTRE_X) + [[UNIVERSE gameView] x_offset] * cached.x0;
2203 y = useDefined(cached.y, CABIN_TEMP_BAR_CENTRE_Y) + [[UNIVERSE gameView] y_offset] * cached.y0;
2204 siz.width = useDefined(cached.width, CABIN_TEMP_BAR_WIDTH);
2205 siz.height = useDefined(cached.height, CABIN_TEMP_BAR_HEIGHT);
2206 alpha *= cached.alpha;
2207 draw_surround = [info oo_boolForKey:DRAW_SURROUND_KEY defaultValue:NO];
2208
2209 if (draw_surround) {
2211 hudDrawSurroundAt(x, y, z1, siz);
2212 }
2213
2214 int flash = (int)([UNIVERSE getTime] * 4);
2215 flash &= 1;
2216 // what color are we?
2217 if (temp > .80) {
2218 if (temp > .90 && flash)
2220 else
2222 } else {
2223 if (temp > .25)
2225 else
2227 }
2228
2229 hudDrawBarAt(x, y, z1, siz, temp);
2230}
2231
2232- (void)drawWeaponTempBar:(NSDictionary*)info
2233{
2234 int x, y;
2235 NSSize siz;
2236 BOOL draw_surround;
2237 GLfloat temp = [PLAYER laserHeatLevel];
2238 GLfloat alpha = overallAlpha;
2239 struct CachedInfo cached;
2240
2241 [(NSValue*)[sCurrentDrawItem objectAtIndex:WIDGET_CACHE] getValue:&cached];
2242
2243 x = useDefined(cached.x, WEAPON_TEMP_BAR_CENTRE_X) + [[UNIVERSE gameView] x_offset] * cached.x0;
2244 y = useDefined(cached.y, WEAPON_TEMP_BAR_CENTRE_Y) + [[UNIVERSE gameView] y_offset] * cached.y0;
2245 siz.width = useDefined(cached.width, WEAPON_TEMP_BAR_WIDTH);
2246 siz.height = useDefined(cached.height, WEAPON_TEMP_BAR_HEIGHT);
2247 alpha *= cached.alpha;
2248 draw_surround = [info oo_boolForKey:DRAW_SURROUND_KEY defaultValue:NO];
2249
2250 if (draw_surround) {
2252 hudDrawSurroundAt(x, y, z1, siz);
2253 }
2254
2255 // draw weapon_temp bar (only need to call GLColor() once!)
2256 if (temp > .80)
2258 else if (temp > .25)
2260 else
2262 hudDrawBarAt(x, y, z1, siz, temp);
2263}
2264
2265- (void)drawAltitudeBar:(NSDictionary*)info
2266{
2267 int x, y;
2268 NSSize siz;
2269 BOOL draw_surround;
2270 GLfloat alt = [PLAYER dialAltitude];
2271 GLfloat alpha = overallAlpha;
2272 struct CachedInfo cached;
2273
2274 [(NSValue*)[sCurrentDrawItem objectAtIndex:WIDGET_CACHE] getValue:&cached];
2275
2276 x = useDefined(cached.x, ALTITUDE_BAR_CENTRE_X) + [[UNIVERSE gameView] x_offset] * cached.x0;
2277 y = useDefined(cached.y, ALTITUDE_BAR_CENTRE_Y) + [[UNIVERSE gameView] y_offset] * cached.y0;
2278 siz.width = useDefined(cached.width, ALTITUDE_BAR_WIDTH);
2279 siz.height = useDefined(cached.height, ALTITUDE_BAR_HEIGHT);
2280 alpha *= cached.alpha;
2281 draw_surround = [info oo_boolForKey:DRAW_SURROUND_KEY defaultValue:NO];
2282
2283 if (draw_surround) {
2285 hudDrawSurroundAt(x, y, z1, siz);
2286 }
2287
2288 int flash = (int)([UNIVERSE getTime] * 4);
2289 flash &= 1;
2290
2291 // draw altitude bar (evaluating the least amount of ifs per go)
2292 if (alt < .25) {
2293 if (alt < .10 && flash)
2295 else
2297 } else {
2298 if (alt < .75)
2300 else
2302 }
2303
2304 hudDrawBarAt(x, y, z1, siz, alt);
2305}
2306
2307static NSString* const kDefaultMissileIconKey = @"oolite-default-missile-icon";
2308static NSString* const kDefaultMineIconKey = @"oolite-default-mine-icon";
2309static const GLfloat kOutlineWidth = 0.5f;
2310
2312{
2313 static NSMutableDictionary* sIcons = nil;
2314 OOPolygonSprite* result = nil;
2315
2316 result = [sIcons objectForKey:role];
2317 if (result == nil) {
2318 NSString* key = role;
2319 NSArray* iconDef = [[UNIVERSE descriptions] oo_arrayForKey:key];
2320 if (iconDef != nil)
2321 result = [[OOPolygonSprite alloc] initWithDataArray:iconDef outlineWidth:kOutlineWidth name:key];
2322 if (result == nil) // No custom icon or bad data
2323 {
2324 /* Backwards compatibility note:
2325 The old implementation used suffixes "MISSILE" and "MINE" (without
2326 the underscore), and didn't draw anything if neither was found. I
2327 believe any difference in practical behavour due to the change here
2328 will be positive.
2329 -- Ahruman 2009-10-09
2330 */
2331 if ([role hasSuffix:@"_MISSILE"])
2333 else
2334 key = kDefaultMineIconKey;
2335
2336 iconDef = [[UNIVERSE descriptions] oo_arrayForKey:key];
2337 result = [[OOPolygonSprite alloc] initWithDataArray:iconDef outlineWidth:kOutlineWidth name:key];
2338 }
2339
2340 if (result != nil) {
2341 if (sIcons == nil)
2342 sIcons = [[NSMutableDictionary alloc] init];
2343 [sIcons setObject:result forKey:role];
2344 [result release]; // Balance alloc
2345 }
2346 }
2347
2348 return result;
2349}
2350
2351- (void)drawIconForMissile:(ShipEntity*)missile
2352 selected:(BOOL)selected
2353 status:(OOMissileStatus)status
2354 x:(int)x
2355 y:(int)y
2356 width:(GLfloat)width
2357 height:(GLfloat)height
2358 alpha:(GLfloat)alpha
2359{
2360 OOPolygonSprite* sprite = IconForMissileRole([missile primaryRole]);
2361
2362 if (selected) {
2363 // Draw yellow outline.
2365 OOGLTranslateModelView(make_vector(x - width * 2.0f, y - height * 2.0f, z1));
2366 OOGLScaleModelView(make_vector(width, height, 1.0f));
2368 [sprite drawOutline];
2370
2371 // Draw black backing, so outline colour isn’t blended into missile colour.
2373 OOGLTranslateModelView(make_vector(x - width * 2.0f, y - height * 2.0f, z1));
2374 OOGLScaleModelView(make_vector(width, height, 1.0f));
2376 [sprite drawFilled];
2378
2379 switch (status) {
2382 break;
2385 break;
2388 break;
2389 }
2390 } else {
2391 if ([missile primaryTarget] == nil)
2393 else
2395 }
2396
2398 OOGLTranslateModelView(make_vector(x - width * 2.0f, y - height * 2.0f, z1));
2399 OOGLScaleModelView(make_vector(width, height, 1.0f));
2400 [sprite drawFilled];
2402}
2403
2404- (void)drawIconForEmptyPylonAtX:(int)x y:(int)y
2405 width:(GLfloat)width
2406 height:(GLfloat)height
2407 alpha:(GLfloat)alpha
2408{
2410
2411 // Draw gray outline.
2413 OOGLTranslateModelView(make_vector(x - width * 2.0f, y - height * 2.0f, z1));
2414 OOGLScaleModelView(make_vector(width, height, 1.0f));
2416 [sprite drawOutline];
2418}
2419
2420- (void)drawMissileDisplay:(NSDictionary*)info
2421{
2422 int x, y, sp;
2423 NSSize siz;
2424 GLfloat alpha = overallAlpha;
2425 struct CachedInfo cached;
2426
2427 [(NSValue*)[sCurrentDrawItem objectAtIndex:WIDGET_CACHE] getValue:&cached];
2428
2429 x = useDefined(cached.x, MISSILES_DISPLAY_X) + [[UNIVERSE gameView] x_offset] * cached.x0;
2430 y = useDefined(cached.y, MISSILES_DISPLAY_Y) + [[UNIVERSE gameView] y_offset] * cached.y0;
2431 siz.width = useDefined(cached.width, MISSILE_ICON_WIDTH);
2432 siz.height = useDefined(cached.height, MISSILE_ICON_HEIGHT);
2433 alpha *= cached.alpha;
2434 sp = [info oo_unsignedIntForKey:SPACING_KEY defaultValue:MISSILES_DISPLAY_SPACING];
2435
2436 BOOL weaponsOnline = [PLAYER weaponsOnline];
2437 if (!weaponsOnline)
2438 alpha *= 0.2f; // darken missile display if weapons are offline
2439
2440 if (![PLAYER dialIdentEngaged]) {
2441 OOMissileStatus status = [PLAYER dialMissileStatus];
2442 NSUInteger i, n_mis = [PLAYER dialMaxMissiles];
2443 for (i = 0; i < n_mis; i++) {
2444 ShipEntity* missile = [PLAYER missileForPylon:i];
2445 if (missile) {
2446 [self drawIconForMissile:missile
2447 selected:weaponsOnline && i == [PLAYER activeMissile]
2448 status:status
2449 x:x + (int)i * sp + 2
2450 y:y
2451 width:siz.width * 0.25f
2452 height:siz.height * 0.25f
2453 alpha:alpha];
2454 } else {
2455 [self drawIconForEmptyPylonAtX:x + (int)i * sp + 2
2456 y:y
2457 width:siz.width * 0.25f
2458 height:siz.height * 0.25f
2459 alpha:alpha];
2460 }
2461 }
2462 } else {
2463 x -= siz.width;
2464 y -= siz.height * 0.75;
2465 siz.width *= 0.80;
2466 sp *= 0.75;
2467 switch ([PLAYER dialMissileStatus]) {
2469 GLColorWithOverallAlpha(green_color, alpha);
2470 break;
2472 GLColorWithOverallAlpha(yellow_color, alpha);
2473 break;
2475 GLColorWithOverallAlpha(red_color, alpha);
2476 break;
2477 }
2478 OOGLBEGIN(GL_QUADS);
2479 glVertex3i(x, y, z1);
2480 glVertex3i(x + siz.width, y, z1);
2481 glVertex3i(x + siz.width, y + siz.height, z1);
2482 glVertex3i(x, y + siz.height, z1);
2483 OOGLEND();
2484 GLColorWithOverallAlpha(green_color, alpha);
2485 OODrawString([PLAYER dialTargetName], x + sp, y - 1, z1, NSMakeSize(siz.width, siz.height));
2486 }
2487}
2488
2489- (void)drawTargetReticle:(NSDictionary*)info
2490{
2491 GLfloat alpha = [info oo_nonNegativeFloatForKey:ALPHA_KEY defaultValue:1.0f] * overallAlpha;
2492
2493 if ([PLAYER primaryTarget] != nil) {
2494 hudDrawReticleOnTarget([PLAYER primaryTarget], PLAYER, z1, alpha, reticleTargetSensitive, propertiesReticleTargetSensitive, NO, YES, info, _reticleColors);
2495 [self drawDirectionCue:info];
2496 }
2497 // extra feature if extra equipment installed
2498 if ([PLAYER hasEquipmentItemProviding:@"EQ_INTEGRATED_TARGETING_SYSTEM"]) {
2499 [self drawSecondaryTargetReticle:info];
2500 }
2501}
2502
2503- (void)drawSecondaryTargetReticle:(NSDictionary*)info
2504{
2505 GLfloat alpha = [info oo_nonNegativeFloatForKey:ALPHA_KEY defaultValue:1.0f] * overallAlpha * 0.4;
2506
2507 PlayerEntity* player = PLAYER;
2508 if ([player hasEquipmentItemProviding:@"EQ_TARGET_MEMORY"]) {
2509 // needs target memory to be working in addition to any other equipment
2510 // this item may be bound to
2511 NSMutableArray* targetMemory = [player targetMemory];
2512 ShipEntity* primary = [player primaryTarget];
2513 for (unsigned i = 0; i < PLAYER_TARGET_MEMORY_SIZE; i++) {
2514 id sec_id = [targetMemory objectAtIndex:i];
2515 // isProxy = weakref ; not = NSNull (in this case...)
2516 // can't use isKindOfClass because that throws
2517 // NSInvalidArgumentException when called on a weakref
2518 // with a dropped object.
2519 // TODO: fix OOWeakReference so isKindOfClass works
2520 if (sec_id != nil && [sec_id isProxy]) {
2522 if (secondary != nil && secondary != primary) {
2523 if ([secondary zeroDistance] <= SCANNER_MAX_RANGE2 && [secondary isInSpace]) {
2524 hudDrawReticleOnTarget(secondary, PLAYER, z1, alpha, NO, nil, YES, NO, info, _reticleColors);
2525 }
2526 }
2527 }
2528 }
2529 }
2530}
2531
2532- (void)drawWaypoints:(NSDictionary*)info
2533{
2534 GLfloat alpha = [info oo_nonNegativeFloatForKey:ALPHA_KEY defaultValue:1.0f] * overallAlpha;
2535 GLfloat scale = [info oo_floatForKey:@"reticle_scale" defaultValue:ONE_SIXTYFOURTH];
2536
2537 OOWaypointEntity* waypoint = nil;
2538 Entity* compass = [PLAYER compassTarget];
2539
2540 foreach (waypoint, [[UNIVERSE currentWaypoints] allValues]) {
2541 hudDrawWaypoint(waypoint, PLAYER, z1, alpha, waypoint == compass, scale);
2542 }
2543}
2544
2545- (void)drawStatusLight:(NSDictionary*)info
2546{
2547 int x, y;
2548 NSSize siz;
2549 GLfloat alpha = overallAlpha;
2550 BOOL blueAlert = cloakIndicatorOnStatusLight && [PLAYER isCloaked];
2551 struct CachedInfo cached;
2552
2553 [(NSValue*)[sCurrentDrawItem objectAtIndex:WIDGET_CACHE] getValue:&cached];
2554
2555 x = useDefined(cached.x, STATUS_LIGHT_CENTRE_X) + [[UNIVERSE gameView] x_offset] * cached.x0;
2556 y = useDefined(cached.y, STATUS_LIGHT_CENTRE_Y) + [[UNIVERSE gameView] y_offset] * cached.y0;
2557 siz.width = useDefined(cached.width, STATUS_LIGHT_HEIGHT);
2558 siz.height = useDefined(cached.height, STATUS_LIGHT_HEIGHT);
2559 alpha *= cached.alpha;
2560
2561 GLfloat status_color[4] = { 0.25, 0.25, 0.25, 1.0 };
2562 int alertCondition = [PLAYER alertCondition];
2563 GLfloat flash_alpha = 0.333 * (2.0f + sin((GLfloat)[UNIVERSE getTime] * 2.5f * alertCondition));
2564
2565 switch (alertCondition) {
2567 status_color[0] = red_color[0];
2568 status_color[1] = red_color[1];
2569 status_color[2] = blueAlert ? blue_color[2] : red_color[2];
2570 break;
2571
2573 status_color[0] = green_color[0];
2574 status_color[1] = green_color[1];
2575 status_color[2] = blueAlert ? blue_color[2] : green_color[2];
2576 break;
2577
2579 status_color[0] = yellow_color[0];
2580 status_color[1] = yellow_color[1];
2581 status_color[2] = blueAlert ? blue_color[2] : yellow_color[2];
2582 break;
2583
2584 default:
2586 break;
2587 }
2588 status_color[3] = flash_alpha;
2589 GLColorWithOverallAlpha(status_color, alpha);
2590 OOGLBEGIN(GL_POLYGON);
2591 hudDrawStatusIconAt(x, y, z1, siz);
2592 OOGLEND();
2593 OOGL(glColor4f(0.25, 0.25, 0.25, alpha));
2594 OOGLBEGIN(GL_LINE_LOOP);
2595 hudDrawStatusIconAt(x, y, z1, siz);
2596 OOGLEND();
2597}
2598
2599- (void)drawDirectionCue:(NSDictionary*)info
2600{
2601 GLfloat alpha = overallAlpha;
2602 struct CachedInfo cached;
2603
2604 [(NSValue*)[sCurrentDrawItem objectAtIndex:WIDGET_CACHE] getValue:&cached];
2605
2606 alpha *= cached.alpha;
2607
2608 if ([UNIVERSE displayGUI])
2609 return;
2610
2611 Entity* target = [PLAYER primaryTarget];
2612 if (target == nil)
2613 return;
2614
2615 // draw the direction cue
2616 OOMatrix rotMatrix;
2617
2618 rotMatrix = [PLAYER rotationMatrix];
2619
2620 if ([UNIVERSE viewDirection] != VIEW_GUI_DISPLAY) {
2621 const GLfloat innerSize = CROSSHAIR_SIZE;
2622 const GLfloat width = CROSSHAIR_SIZE * ONE_EIGHTH;
2623 const GLfloat outerSize = CROSSHAIR_SIZE * (1.0f + ONE_EIGHTH + ONE_EIGHTH);
2624 const float visMin = 0.994521895368273f; // cos(6 degrees)
2625 const float visMax = 0.984807753012208f; // cos(10 degrees)
2626
2627 // Transform the view
2628 Vector rpn = [PLAYER vectorTo:target];
2629 rpn = OOVectorMultiplyMatrix(rpn, rotMatrix);
2630 Vector drawPos = rpn;
2631 Vector forward = kZeroVector;
2632
2633 switch ([UNIVERSE viewDirection]) {
2634 case VIEW_FORWARD:
2635 forward = kBasisZVector;
2636 break;
2637 case VIEW_AFT:
2638 drawPos.x = -drawPos.x;
2639 forward = vector_flip(kBasisZVector);
2640 break;
2641 case VIEW_PORT:
2642 drawPos.x = drawPos.z;
2643 forward = vector_flip(kBasisXVector);
2644 break;
2645 case VIEW_STARBOARD:
2646 drawPos.x = -drawPos.z;
2647 forward = kBasisXVector;
2648 break;
2649 case VIEW_CUSTOM:
2650 return;
2651
2652 default:
2653 break;
2654 }
2655
2656 float cosAngle = dot_product(vector_normal(rpn), forward);
2657 float visibility = 1.0f - ((visMax - cosAngle) * (1.0f / (visMax - visMin)));
2658 alpha *= OOClamp_0_1_f(visibility);
2659
2660 if (alpha > 0.0f) {
2661 NSUInteger cueColorIndex = [target isWormhole] ? OO_RETICLE_COLOR_WORMHOLE : OO_RETICLE_COLOR_TARGET;
2662 OOColor* directionCueColor = [_reticleColors objectAtIndex:cueColorIndex];
2663 GLfloat clearColorArray[4] = { [directionCueColor redComponent],
2666 0.0f };
2667 GLfloat directionCueColorArray[4] = { [directionCueColor redComponent],
2671 drawPos.z = 0.0f; // flatten vector
2672 drawPos = vector_normal(drawPos);
2673 OOGLBEGIN(GL_LINE_STRIP);
2674 glColor4fv(clearColorArray);
2675 glVertex3f(drawPos.x * innerSize - drawPos.y * width, drawPos.y * innerSize + drawPos.x * width, z1);
2676 GLColorWithOverallAlpha(directionCueColorArray, alpha);
2677 glVertex3f(drawPos.x * outerSize, drawPos.y * outerSize, z1);
2678 glColor4fv(clearColorArray);
2679 glVertex3f(drawPos.x * innerSize + drawPos.y * width, drawPos.y * innerSize - drawPos.x * width, z1);
2680 OOGLEND();
2681 }
2682 }
2683}
2684
2685- (void)drawClock:(NSDictionary*)info
2686{
2687 int x, y;
2688 NSSize siz;
2689 GLfloat itemColor[4] = { 0.0f, 1.0f, 0.0f, 1.0f };
2690 struct CachedInfo cached;
2691
2692 [(NSValue*)[sCurrentDrawItem objectAtIndex:WIDGET_CACHE] getValue:&cached];
2693
2694 x = useDefined(cached.x, CLOCK_DISPLAY_X) + [[UNIVERSE gameView] x_offset] * cached.x0;
2695 y = useDefined(cached.y, CLOCK_DISPLAY_Y) + [[UNIVERSE gameView] y_offset] * cached.y0;
2696 siz.width = useDefined(cached.width, CLOCK_DISPLAY_WIDTH);
2697 siz.height = useDefined(cached.height, CLOCK_DISPLAY_HEIGHT);
2698
2699 GetRGBAArrayFromInfo(info, itemColor);
2700 itemColor[3] *= overallAlpha;
2701
2702 OOGL(glColor4f(itemColor[0], itemColor[1], itemColor[2], itemColor[3]));
2703 OODrawString([PLAYER dial_clock], x, y, z1, siz);
2704}
2705
2706- (void)drawPrimedEquipment:(NSDictionary*)info
2707{
2708 if ([PLAYER status] == STATUS_DOCKED) {
2709 // Can't activate equipment while docked
2710 return;
2711 }
2712
2713 GLfloat itemColor[4] = { 0.0f, 1.0f, 0.0f, 1.0f };
2714 struct CachedInfo cached;
2715
2716 NSUInteger lines = [info oo_intForKey:@"n_bars" defaultValue:1];
2717 NSInteger pec = (NSInteger)[PLAYER primedEquipmentCount];
2718
2719 [(NSValue*)[sCurrentDrawItem objectAtIndex:WIDGET_CACHE] getValue:&cached];
2720
2721 NSInteger x = useDefined(cached.x, PRIMED_DISPLAY_X) + [[UNIVERSE gameView] x_offset] * cached.x0;
2722 NSInteger y = useDefined(cached.y, PRIMED_DISPLAY_Y) + [[UNIVERSE gameView] y_offset] * cached.y0;
2723
2724 NSSize size = {
2725 .width = useDefined(cached.width, PRIMED_DISPLAY_WIDTH),
2726 .height = useDefined(cached.height, PRIMED_DISPLAY_HEIGHT)
2727 };
2728
2729 if (pec == 0) {
2730 // Don't display if no primed equipment fitted
2731 return;
2732 }
2733
2734 GetRGBAArrayFromInfo(info, itemColor);
2735 itemColor[3] *= overallAlpha;
2736
2737 if (lines == 1) {
2738 OOGL(glColor4f(itemColor[0], itemColor[1], itemColor[2], itemColor[3]));
2739 NSString* equipmentName = [PLAYER primedEquipmentName:0];
2740 OODrawString(OOExpandKey(@"equipment-primed-hud", equipmentName), x, y, z1, size);
2741 } else {
2742 NSInteger negative = (lines - 1) / 2;
2743 NSInteger positive = lines / 2;
2744 for (NSInteger i = -negative; i <= positive; i++) {
2745 if (i >= -(pec) / 2 && i <= (pec + 1) / 2) {
2746 // don't display loops if we have more equipment than lines
2747 // instead compact the display towards its centre
2748 GLfloat alphaScale = 1.0 / ((i < 0) ? (1.0 - i) : (1.0 + i));
2749 OOGL(glColor4f(itemColor[0], itemColor[1], itemColor[2], itemColor[3] * alphaScale));
2750 OODrawString([PLAYER primedEquipmentName:i], x, y, z1, size);
2751 }
2752 y -= size.height;
2753 }
2754 }
2755}
2756
2757- (void)drawASCTarget:(NSDictionary*)info
2758{
2759 if (!([self checkPlayerInSystemFlight] && [PLAYER status] != STATUS_LAUNCHING)) // normal system
2760 {
2761 // Can't have compass target when docked, etc. (matches blip condition)
2762 return;
2763 }
2764
2765 GLfloat itemColor[4] = { 0.0f, 0.0f, 1.0f, 1.0f };
2766 struct CachedInfo cached;
2767
2768 [(NSValue*)[sCurrentDrawItem objectAtIndex:WIDGET_CACHE] getValue:&cached];
2769
2770 NSInteger x = useDefined(cached.x, ASCTARGET_DISPLAY_X) + [[UNIVERSE gameView] x_offset] * cached.x0;
2771 NSInteger y = useDefined(cached.y, ASCTARGET_DISPLAY_Y) + [[UNIVERSE gameView] y_offset] * cached.y0;
2772
2773 NSSize size = {
2774 .width = useDefined(cached.width, ASCTARGET_DISPLAY_WIDTH),
2775 .height = useDefined(cached.height, ASCTARGET_DISPLAY_HEIGHT)
2776 };
2777
2778 GetRGBAArrayFromInfo(info, itemColor);
2779 itemColor[3] *= overallAlpha;
2780
2781 OOGL(glColor4f(itemColor[0], itemColor[1], itemColor[2], itemColor[3]));
2782 if ([info oo_intForKey:@"align"] == 1) {
2783 OODrawStringAligned([PLAYER compassTargetLabel], x, y, z1, size, YES);
2784 } else {
2785 OODrawStringAligned([PLAYER compassTargetLabel], x, y, z1, size, NO);
2786 }
2787}
2788
2789- (void)drawWeaponsOfflineText:(NSDictionary*)info
2790{
2791 OOViewID viewID = [UNIVERSE viewDirection];
2792 GLfloat textColor[4] = { 0.0f, 1.0f, 0.0f, 1.0f };
2793
2794 if (viewID == VIEW_CUSTOM || overallAlpha == 0.0f || !([PLAYER status] == STATUS_IN_FLIGHT || [PLAYER status] == STATUS_WITCHSPACE_COUNTDOWN) ||
2795 [UNIVERSE displayGUI]) {
2796 // Don't draw weapons offline text
2797 return;
2798 }
2799
2800 if (![PLAYER weaponsOnline]) {
2801 int x, y;
2802 NSSize siz;
2803 struct CachedInfo cached;
2804
2805 [(NSValue*)[sCurrentDrawItem objectAtIndex:WIDGET_CACHE] getValue:&cached];
2806
2807 x = useDefined(cached.x, WEAPONSOFFLINETEXT_DISPLAY_X) + [[UNIVERSE gameView] x_offset] * cached.x0;
2808 y = useDefined(cached.y, WEAPONSOFFLINETEXT_DISPLAY_Y) + [[UNIVERSE gameView] y_offset] * cached.y0;
2809 siz.width = useDefined(cached.width, WEAPONSOFFLINETEXT_WIDTH);
2810 siz.height = useDefined(cached.height, WEAPONSOFFLINETEXT_HEIGHT);
2811
2812 GetRGBAArrayFromInfo(info, textColor);
2813 textColor[3] *= overallAlpha;
2814
2815 OOGL(glColor4f(textColor[0], textColor[1], textColor[2], textColor[3]));
2816 // TODO: some caching required...
2817 OODrawString(DESC(@"weapons-systems-offline"), x, y, z1, siz);
2818 }
2819}
2820
2821- (void)drawFPSInfoCounter:(NSDictionary*)info
2822{
2823 if (![UNIVERSE displayFPS])
2824 return;
2825
2826 int x, y;
2827 NSSize siz;
2828 struct CachedInfo cached;
2829 GLfloat textColor[4] = { 0.0, 1.0, 0.0, 1.0 };
2830
2831 [(NSValue*)[sCurrentDrawItem objectAtIndex:WIDGET_CACHE] getValue:&cached];
2832
2833 x = useDefined(cached.x, FPSINFO_DISPLAY_X) + [[UNIVERSE gameView] x_offset] * cached.x0;
2834 y = useDefined(cached.y, FPSINFO_DISPLAY_Y) + [[UNIVERSE gameView] y_offset] * cached.y0;
2835 siz.width = useDefined(cached.width, FPSINFO_DISPLAY_WIDTH);
2836 siz.height = useDefined(cached.height, FPSINFO_DISPLAY_HEIGHT);
2837
2838 HPVector playerPos = [PLAYER position];
2839 NSString* positionInfo = [UNIVERSE expressPosition:playerPos inCoordinateSystem:@"pwm"];
2840 positionInfo = [NSString stringWithFormat:@"abs %.2f %.2f %.2f / %@", playerPos.x, playerPos.y, playerPos.z, positionInfo];
2841
2842 // We would normally set a variable alpha value here, but in this case we don't.
2843 // We prefer the FPS counter to be always visible - Nikos 20100405
2844 GetRGBAArrayFromInfo(info, textColor);
2845 OOGL(glColor4f(textColor[0], textColor[1], textColor[2], 1.0f));
2846 OODrawString([PLAYER dial_fpsinfo], x, y, z1, siz);
2847
2848#ifndef NDEBUG
2849 NSSize siz08 = NSMakeSize(0.8 * siz.width, 0.8 * siz.width);
2850 NSString* collDebugInfo = [NSString stringWithFormat:@"%@ - %@", [PLAYER dial_objinfo], [UNIVERSE collisionDescription]];
2851 OODrawString(collDebugInfo, x, y - siz.height, z1, siz);
2852
2853 OODrawString(positionInfo, x, y - 1.8 * siz.height, z1, siz08);
2854
2855 NSString* timeAccelerationFactorInfo = [NSString stringWithFormat:@"TAF: %@%.2f", DESC(@"multiplication-sign"), [UNIVERSE timeAccelerationFactor]];
2856 OODrawString(timeAccelerationFactorInfo, x, y - 3.2 * siz08.height, z1, siz08);
2857#endif
2858}
2859
2860- (void)drawScoopStatus:(NSDictionary*)info
2861{
2862 int i, x, y;
2863 NSSize siz;
2864 GLfloat alpha;
2865 struct CachedInfo cached;
2866
2867 [(NSValue*)[sCurrentDrawItem objectAtIndex:WIDGET_CACHE] getValue:&cached];
2868
2869 x = useDefined(cached.x, SCOOPSTATUS_CENTRE_X) + [[UNIVERSE gameView] x_offset] * cached.x0;
2870 y = useDefined(cached.y, SCOOPSTATUS_CENTRE_Y) + [[UNIVERSE gameView] y_offset] * cached.y0;
2871 siz.width = useDefined(cached.width, SCOOPSTATUS_WIDTH);
2872 siz.height = useDefined(cached.height, SCOOPSTATUS_HEIGHT);
2873 // default alpha value different from all others, won't use cached.alpha
2874 alpha = [info oo_nonNegativeFloatForKey:ALPHA_KEY defaultValue:0.75f];
2875
2876 const GLfloat* s0_color = red_color;
2877 GLfloat s1c[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
2878 GLfloat s2c[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
2879 GLfloat s3c[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
2880 int scoop_status = [PLAYER dialFuelScoopStatus];
2881 GLfloat t = [UNIVERSE getTime];
2882 GLfloat a1 = alpha * 0.5f * (1.0f + sin(t * 8.0f));
2883 GLfloat a2 = alpha * 0.5f * (1.0f + sin(t * 8.0f - 1.0f));
2884 GLfloat a3 = alpha * 0.5f * (1.0f + sin(t * 8.0f - 2.0f));
2885
2886 switch (scoop_status) {
2888 return; // don't draw
2889
2891 s0_color = darkgreen_color;
2892 alpha *= 0.75;
2893 break;
2894
2896 case SCOOP_STATUS_OKAY:
2897 s0_color = green_color;
2898 break;
2899 }
2900
2901 for (i = 0; i < 3; i++) {
2902 s1c[i] = s0_color[i];
2903 s2c[i] = s0_color[i];
2904 s3c[i] = s0_color[i];
2905 }
2906 if (scoop_status == SCOOP_STATUS_FULL_HOLD) {
2907 s3c[0] = red_color[0];
2908 s3c[1] = red_color[1];
2909 s3c[2] = red_color[2];
2910 }
2911 if (scoop_status == SCOOP_STATUS_ACTIVE) {
2912 s1c[3] = alpha * a1;
2913 s2c[3] = alpha * a2;
2914 s3c[3] = alpha * a3;
2915 } else {
2916 s1c[3] = alpha;
2917 s2c[3] = alpha;
2918 s3c[3] = alpha;
2919 }
2920
2921 GLfloat w1 = siz.width / 8.0;
2922 GLfloat w2 = 2.0 * w1;
2923 // GLfloat w3 = 3.0 * w1;
2924 GLfloat w4 = 4.0 * w1;
2925 GLfloat h1 = siz.height / 8.0;
2926 GLfloat h2 = 2.0 * h1;
2927 GLfloat h3 = 3.0 * h1;
2928 GLfloat h4 = 4.0 * h1;
2929
2930 OOGL(glDisable(GL_TEXTURE_2D));
2931 OOGLBEGIN(GL_QUADS);
2932 // section 1
2933 GLColorWithOverallAlpha(s1c, overallAlpha);
2934 glVertex3f(x, y + h1, z1);
2935 glVertex3f(x - w2, y + h2, z1);
2936 glVertex3f(x, y + h3, z1);
2937 glVertex3f(x + w2, y + h2, z1);
2938 // section 2
2939 GLColorWithOverallAlpha(s2c, overallAlpha);
2940 glVertex3f(x, y - h1, z1);
2941 glVertex3f(x - w4, y + h1, z1);
2942 glVertex3f(x - w4, y + h2, z1);
2943 glVertex3f(x, y, z1);
2944 glVertex3f(x, y - h1, z1);
2945 glVertex3f(x + w4, y + h1, z1);
2946 glVertex3f(x + w4, y + h2, z1);
2947 glVertex3f(x, y, z1);
2948 // section 3
2949 GLColorWithOverallAlpha(s3c, overallAlpha);
2950 glVertex3f(x, y - h4, z1);
2951 glVertex3f(x - w2, y - h2, z1);
2952 glVertex3f(x - w2, y - h1, z1);
2953 glVertex3f(x, y - h2, z1);
2954 glVertex3f(x, y - h4, z1);
2955 glVertex3f(x + w2, y - h2, z1);
2956 glVertex3f(x + w2, y - h1, z1);
2957 glVertex3f(x, y - h2, z1);
2958 OOGLEND();
2959}
2960
2961- (void)drawStickSensitivityIndicator:(NSDictionary*)info
2962{
2963 GLfloat x, y;
2964 NSSize siz;
2965 GLfloat alpha = overallAlpha;
2966 BOOL mouse = [PLAYER isMouseControlOn];
2968 struct CachedInfo cached;
2969
2970 if (![stickHandler joystickCount]) {
2971 return; // no need to draw if no joystick fitted
2972 }
2973
2974 [(NSValue*)[sCurrentDrawItem objectAtIndex:WIDGET_CACHE] getValue:&cached];
2975
2976 x = useDefined(cached.x, STATUS_LIGHT_CENTRE_X) + [[UNIVERSE gameView] x_offset] * cached.x0;
2977 y = useDefined(cached.y, STATUS_LIGHT_CENTRE_Y) + [[UNIVERSE gameView] y_offset] * cached.y0;
2978 siz.width = useDefined(cached.width, STATUS_LIGHT_HEIGHT);
2979 siz.height = useDefined(cached.height, STATUS_LIGHT_HEIGHT);
2980 alpha *= cached.alpha;
2981
2982 GLfloat div = [stickHandler getSensitivity];
2983
2984 GLColorWithOverallAlpha(black_color, alpha / 4);
2985 GLDrawFilledOval(x, y, z1, siz, 10);
2986
2987 GLColorWithOverallAlpha((div < 1.0 || mouse) ? lightgray_color : green_color, alpha);
2988 OOGL(GLScaledLineWidth(_crosshairWidth * lineWidth));
2989
2990 if (div >= 1.0) {
2991 if (!mouse) {
2992 NSSize siz8th = { siz.width / 8, siz.height / 8 };
2993 GLDrawFilledOval(x, y, z1, siz8th, 30);
2994
2995 if (div == 1.0) // normal mode
2996 GLColorWithOverallAlpha(lightgray_color, alpha);
2997 }
2998
2999 siz.width -= _crosshairWidth * lineWidth / 2;
3000 siz.height -= _crosshairWidth * lineWidth / 2;
3001 GLDrawOval(x, y, z1, siz, 10);
3002 } else if (div < 1.0) // insensitive mode (shouldn't happen)
3003 GLDrawFilledOval(x, y, z1, siz, 10);
3004
3005 OOGL(GLScaledLineWidth(lineWidth)); // reset
3006}
3007
3008- (void)drawSurroundInternal:(NSDictionary*)info color:(const GLfloat[4])color
3009{
3010 NSInteger x, y;
3011 NSSize siz;
3012 GLfloat alpha = overallAlpha;
3013 struct CachedInfo cached;
3014
3015 [(NSValue*)[sCurrentDrawItem objectAtIndex:WIDGET_CACHE] getValue:&cached];
3016
3017 if (cached.x == NOT_DEFINED || cached.y == NOT_DEFINED || cached.width == NOT_DEFINED || cached.height == NOT_DEFINED) {
3018 return;
3019 }
3020
3021 x = cached.x + [[UNIVERSE gameView] x_offset] * cached.x0;
3022 y = cached.y + [[UNIVERSE gameView] y_offset] * cached.y0;
3023 siz.width = useDefined(cached.width, WEAPONSOFFLINETEXT_WIDTH);
3024 siz.height = useDefined(cached.height, WEAPONSOFFLINETEXT_HEIGHT);
3025 alpha *= cached.alpha;
3026
3027 // draw the surround
3028 GLColorWithOverallAlpha(color, alpha);
3029 hudDrawSurroundAt(x, y, z1, siz);
3030}
3031
3032- (void)drawSurround:(NSDictionary*)info
3033{
3034 GLfloat itemColor[4] = { 0.0f, 1.0f, 0.0f, 1.0f };
3035 id colorDesc = [info objectForKey:COLOR_KEY];
3036 if (colorDesc != nil) {
3037 OOColor* color = [OOColor colorWithDescription:colorDesc];
3038 if (color != nil) {
3039 itemColor[0] = [color redComponent];
3040 itemColor[1] = [color greenComponent];
3041 itemColor[2] = [color blueComponent];
3042 }
3043 }
3044
3045 [self drawSurroundInternal:info color:itemColor];
3046}
3047
3048- (void)drawGreenSurround:(NSDictionary*)info
3049{
3050 [self drawSurroundInternal:info color:green_color];
3051}
3052
3053- (void)drawYellowSurround:(NSDictionary*)info
3054{
3055 [self drawSurroundInternal:info color:yellow_color];
3056}
3057
3058- (void)drawTrumbles:(NSDictionary*)info
3059{
3060 OOTrumble** trumbles = [PLAYER trumbleArray];
3061 NSUInteger i;
3062 for (i = [PLAYER trumbleCount]; i > 0; i--) {
3063 OOTrumble* trum = trumbles[i - 1];
3064 [trum drawTrumble:z1];
3065 }
3066}
3067
3068- (void)drawMultiFunctionDisplay:(NSDictionary*)info withText:(NSString*)text asIndex:(NSUInteger)index
3069{
3070 PlayerEntity* player1 = PLAYER;
3071 struct CachedInfo cached;
3072 NSInteger i, x, y;
3073 NSSize siz, tmpsiz;
3074 if ([player1 guiScreen] != GUI_SCREEN_MAIN) // don't draw on text screens
3075 {
3076 return;
3077 }
3078 GLfloat alpha = [info oo_nonNegativeFloatForKey:ALPHA_KEY defaultValue:1.0f] * overallAlpha;
3079
3080 GLfloat mfd_color[4] = { 0.0, 1.0, 0.0, 0.9 * alpha };
3081 OOColor* mfdcol = [OOColor colorWithDescription:[info objectForKey:COLOR_KEY]];
3082 if (mfdcol != nil) {
3083 [mfdcol getRed:&mfd_color[0] green:&mfd_color[1] blue:&mfd_color[2] alpha:&mfd_color[3]];
3084 }
3085 if (index != [player1 activeMFD]) {
3086 mfd_color[3] *= 0.75;
3087 }
3088 [self drawSurroundInternal:info color:mfd_color];
3089
3090 [(NSValue*)[sCurrentDrawItem objectAtIndex:WIDGET_CACHE] getValue:&cached];
3091 x = cached.x + [[UNIVERSE gameView] x_offset] * cached.x0;
3092 y = cached.y + [[UNIVERSE gameView] y_offset] * cached.y0;
3093
3094 siz.width = useDefined(cached.width / 15, MFD_TEXT_WIDTH);
3095 siz.height = useDefined(cached.height / 10, MFD_TEXT_HEIGHT);
3096
3097 GLfloat x0 = (GLfloat)(x - cached.width / 2);
3098 GLfloat y0 = (GLfloat)(y + cached.height / 2);
3099 GLfloat x1 = (GLfloat)(x + cached.width / 2);
3100 GLfloat y1 = (GLfloat)(y - cached.height / 2);
3101 GLColorWithOverallAlpha(mfd_color, alpha * 0.3);
3102 OOGLBEGIN(GL_QUADS);
3103 glVertex3f(x0 - 2, y0 + 2, z1);
3104 glVertex3f(x0 - 2, y1 - 2, z1);
3105 glVertex3f(x1 + 2, y1 - 2, z1);
3106 glVertex3f(x1 + 2, y0 + 2, z1);
3107 OOGLEND();
3108
3109 NSString* line = nil;
3110 NSArray* lines = [text componentsSeparatedByString:@"\n"];
3111 // text at full opacity
3112 GLColorWithOverallAlpha(mfd_color, alpha);
3113 for (i = 0; i < 10; i++) {
3114 line = [lines oo_stringAtIndex:i defaultValue:nil];
3115 if (line != nil) {
3116 y0 -= siz.height;
3117 // all lines should be shorter than the size of the MFD
3118 GLfloat textwidth = OORectFromString(line, 0.0f, 0.0f, siz).size.width;
3119 if (textwidth <= cached.width) {
3120 OODrawString(line, x0, y0, z1, siz);
3121 } else {
3122 // compress it so it fits
3123 tmpsiz.height = siz.height;
3124 tmpsiz.width = siz.width * cached.width / textwidth;
3125 OODrawString(line, x0, y0, z1, tmpsiz);
3126 }
3127 } else {
3128 break;
3129 }
3130 }
3131}
3132
3133//---------------------------------------------------------------------//
3134
3135static void hudDrawIndicatorAt(GLfloat x, GLfloat y, GLfloat z, NSSize siz, GLfloat amount)
3136{
3137 if (siz.width > siz.height) {
3138 GLfloat dial_oy = y - siz.height / 2;
3139 GLfloat position = x + amount * siz.width / 2;
3140 OOGLBEGIN(GL_QUADS);
3141 glVertex3f(position, dial_oy, z);
3142 glVertex3f(position + 2, y, z);
3143 glVertex3f(position, dial_oy + siz.height, z);
3144 glVertex3f(position - 2, y, z);
3145 OOGLEND();
3146 } else {
3147 GLfloat dial_ox = x - siz.width / 2;
3148 GLfloat position = y + amount * siz.height / 2;
3149 OOGLBEGIN(GL_QUADS);
3150 glVertex3f(dial_ox, position, z);
3151 glVertex3f(x, position + 2, z);
3152 glVertex3f(dial_ox + siz.width, position, z);
3153 glVertex3f(x, position - 2, z);
3154 OOGLEND();
3155 }
3156}
3157
3158static void hudDrawMarkerAt(GLfloat x, GLfloat y, GLfloat z, NSSize siz, GLfloat amount)
3159{
3160 if (siz.width > siz.height) {
3161 GLfloat dial_oy = y - siz.height / 2;
3162 GLfloat position = x + amount * siz.width - siz.width / 2;
3163 OOGLBEGIN(GL_QUADS);
3164 glVertex3f(position + 1, dial_oy + 1, z);
3165 glVertex3f(position + 1, dial_oy + siz.height - 1, z);
3166 glVertex3f(position - 1, dial_oy + siz.height - 1, z);
3167 glVertex3f(position - 1, dial_oy + 1, z);
3168 OOGLEND();
3169 } else {
3170 GLfloat dial_ox = x - siz.width / 2;
3171 GLfloat position = y + amount * siz.height - siz.height / 2;
3172 OOGLBEGIN(GL_QUADS);
3173 glVertex3f(dial_ox + 1, position + 1, z);
3174 glVertex3f(dial_ox + siz.width - 1, position + 1, z);
3175 glVertex3f(dial_ox + siz.width - 1, position - 1, z);
3176 glVertex3f(dial_ox + 1, position - 1, z);
3177 OOGLEND();
3178 }
3179}
3180
3181static void hudDrawBarAt(GLfloat x, GLfloat y, GLfloat z, NSSize siz, GLfloat amount)
3182{
3183 GLfloat dial_ox = x - siz.width / 2;
3184 GLfloat dial_oy = y - siz.height / 2;
3185 if (fabs(siz.width) > fabs(siz.height)) {
3186 GLfloat position = dial_ox + amount * siz.width;
3187
3188 OOGLBEGIN(GL_QUADS);
3189 glVertex3f(dial_ox, dial_oy, z);
3190 glVertex3f(position, dial_oy, z);
3191 glVertex3f(position, dial_oy + siz.height, z);
3192 glVertex3f(dial_ox, dial_oy + siz.height, z);
3193 OOGLEND();
3194 } else {
3195 GLfloat position = dial_oy + amount * siz.height;
3196
3197 OOGLBEGIN(GL_QUADS);
3198 glVertex3f(dial_ox, dial_oy, z);
3199 glVertex3f(dial_ox, position, z);
3200 glVertex3f(dial_ox + siz.width, position, z);
3201 glVertex3f(dial_ox + siz.width, dial_oy, z);
3202 OOGLEND();
3203 }
3204}
3205
3206static void hudDrawSurroundAt(GLfloat x, GLfloat y, GLfloat z, NSSize siz)
3207{
3208 GLfloat dial_ox = x - siz.width / 2;
3209 GLfloat dial_oy = y - siz.height / 2;
3210
3211 OOGLBEGIN(GL_LINE_LOOP);
3212 glVertex3f(dial_ox - 2, dial_oy - 2, z);
3213 glVertex3f(dial_ox + siz.width + 2, dial_oy - 2, z);
3214 glVertex3f(dial_ox + siz.width + 2, dial_oy + siz.height + 2, z);
3215 glVertex3f(dial_ox - 2, dial_oy + siz.height + 2, z);
3216 OOGLEND();
3217}
3218
3219static void hudDrawStatusIconAt(int x, int y, int z, NSSize siz)
3220{
3221 int ox = x - siz.width / 2.0;
3222 int oy = y - siz.height / 2.0;
3223 int w = siz.width / 4.0;
3224 int h = siz.height / 4.0;
3225
3226 glVertex3i(ox, oy + h, z);
3227 glVertex3i(ox, oy + 3 * h, z);
3228 glVertex3i(ox + w, oy + 4 * h, z);
3229 glVertex3i(ox + 3 * w, oy + 4 * h, z);
3230 glVertex3i(ox + 4 * w, oy + 3 * h, z);
3231 glVertex3i(ox + 4 * w, oy + h, z);
3232 glVertex3i(ox + 3 * w, oy, z);
3233 glVertex3i(ox + w, oy, z);
3234}
3235
3236static void hudDrawReticleOnTarget(Entity* target, PlayerEntity* player1, GLfloat z1,
3237 GLfloat alpha, BOOL reticleTargetSensitive, NSMutableDictionary* propertiesReticleTargetSensitive,
3238 BOOL colourFromScannerColour, BOOL showText, NSDictionary* info, NSMutableArray* reticleColors)
3239{
3240 if (target == nil || player1 == nil) {
3241 return;
3242 }
3243 if ([player1 guiScreen] != GUI_SCREEN_MAIN) // don't draw on text screens
3244 {
3245 return;
3246 }
3247
3248 ShipEntity* target_ship = nil;
3249 NSString* legal_desc = nil;
3250
3251 GLfloat scale = [info oo_floatForKey:@"reticle_scale" defaultValue:ONE_SIXTYFOURTH];
3252
3253 if ([target isShip]) {
3254 target_ship = (ShipEntity*)target;
3255 legal_desc = [target_ship scanDescription];
3256 }
3257
3258 if ([target_ship isCloaked])
3259 return;
3260
3261 Vector p1;
3262
3263 // by definition close enough that single precision is fine
3264 p1 = HPVectorToVector(HPvector_subtract([target position], [player1 viewpointPosition]));
3265
3266 GLfloat rdist = magnitude(p1);
3267 GLfloat rsize = [target collisionRadius] / (2 * [[UNIVERSE gameView] fov:YES]); // FIXME integrate 2 into fov to remove magic number
3268
3269 if (rsize < rdist * scale)
3270 rsize = rdist * scale;
3271
3272 GLfloat rs0 = rsize;
3273 GLfloat rs2 = rsize * 0.50;
3274
3277
3278 // draw the reticle
3279 float range = sqrt(target->zero_distance) - target->collision_radius;
3280
3281 int flash = (int)([UNIVERSE getTime] * 4);
3282 flash &= 1;
3283
3284 // Draw reticle cyan for Wormholes
3285 if ([target isWormhole]) {
3286 OOColor* wormholeReticleColor = [reticleColors objectAtIndex:OO_RETICLE_COLOR_WORMHOLE];
3287 GLfloat wormholeReticleColorArray[4] = { [wormholeReticleColor redComponent],
3291 GLColorWithOverallAlpha(wormholeReticleColorArray, alpha);
3292 } else {
3293 // Reticle sensitivity accuracy calculation
3294 BOOL isTargeted = NO;
3295 GLfloat probabilityAccuracy;
3296
3298 // Only if target is within player's weapon range, we mind for reticle accuracy
3299 if (range < [player1 weaponRange]) {
3300 // After MAX_ACCURACY_RANGE km start decreasing high accuracy probability by ACCURACY_PROBABILITY_DECREASE_FACTOR%
3301 if (range > MAX_ACCURACY_RANGE) {
3302 // Every one second re-evaluate accuracy
3303 if ([UNIVERSE getTime] > [propertiesReticleTargetSensitive oo_doubleForKey:@"timeLastAccuracyProbabilityCalculation"] + 1) {
3304 probabilityAccuracy = 1 - (range - MAX_ACCURACY_RANGE) * ACCURACY_PROBABILITY_DECREASE_FACTOR;
3305 // Make sure probability does not go below a minimum
3306 probabilityAccuracy = probabilityAccuracy < MIN_PROBABILITY_ACCURACY ? MIN_PROBABILITY_ACCURACY : probabilityAccuracy;
3307 [propertiesReticleTargetSensitive setObject:[NSNumber numberWithBool:((randf() < probabilityAccuracy) ? YES : NO)] forKey:@"isAccurate"];
3308
3309 // Store the time the last accuracy probability has been performed
3310 [propertiesReticleTargetSensitive setObject:[NSNumber numberWithDouble:[UNIVERSE getTime]] forKey:@"timeLastAccuracyProbabilityCalculation"];
3311 }
3312 if ([propertiesReticleTargetSensitive oo_boolForKey:@"isAccurate"]) {
3313 // high accuracy reticle
3314 isTargeted = ([UNIVERSE firstEntityTargetedByPlayerPrecisely] == target);
3315 } else {
3316 // low accuracy reticle
3317 isTargeted = ([UNIVERSE firstEntityTargetedByPlayer] == target);
3318 }
3319 } else {
3320 // high accuracy reticle
3321 isTargeted = ([UNIVERSE firstEntityTargetedByPlayerPrecisely] == target);
3322 }
3323 }
3324 }
3325
3326 // If reticle is target sensitive, draw target box in red
3327 // when target passes through laser hit-point(with decreasing accuracy)
3328 // and is within hit-range.
3329 //
3330 // NOTE: The following condition also considers (indirectly) the player's weapon range.
3331 // 'isTargeted' is initialised to FALSE. Only if target is within the player's weapon range,
3332 // it might change value. Therefore, it is not necessary to add '&& range < [player1 weaponRange]'
3333 // to the following condition.
3334 if (colourFromScannerColour) {
3335 if ([target isShip]) {
3336 ShipEntity* ship = (ShipEntity*)target;
3337 BOOL isHostile = (([ship hasHostileTarget]) && ([ship primaryTarget] == PLAYER));
3338 GLColorWithOverallAlpha([ship scannerDisplayColorForShip:PLAYER isHostile:isHostile flash:flash scannerDisplayColor1:[ship scannerDisplayColor1] scannerDisplayColor2:[ship scannerDisplayColor2] scannerDisplayColorH1:[ship scannerDisplayColorHostile1] scannerDisplayColorH2:[ship scannerDisplayColorHostile2]], alpha);
3339 } else if ([target isVisualEffect]) {
3341 GLColorWithOverallAlpha([vis scannerDisplayColorForShip:flash scannerDisplayColor1:[vis scannerDisplayColor1] scannerDisplayColor2:[vis scannerDisplayColor2]], alpha);
3342 } else {
3344 }
3345 } else {
3346 OOColor* reticleDisplayColor = nil;
3347 if (reticleTargetSensitive && isTargeted) {
3348 reticleDisplayColor = [reticleColors objectAtIndex:OO_RETICLE_COLOR_TARGET_SENSITIVE];
3349 if (!reticleDisplayColor)
3350 reticleDisplayColor = [OOColor redColor];
3351 } else {
3352 reticleDisplayColor = [reticleColors objectAtIndex:OO_RETICLE_COLOR_TARGET];
3353 if (!reticleDisplayColor)
3354 reticleDisplayColor = [OOColor greenColor];
3355 }
3356 GLfloat reticleDisplayColorArray[4] = { [reticleDisplayColor redComponent],
3360 GLColorWithOverallAlpha(reticleDisplayColorArray, alpha);
3361 }
3362 }
3363 OOGLBEGIN(GL_LINES);
3364 glVertex2f(rs0, rs2);
3365 glVertex2f(rs0, rs0);
3366 glVertex2f(rs0, rs0);
3367 glVertex2f(rs2, rs0);
3368
3369 glVertex2f(rs0, -rs2);
3370 glVertex2f(rs0, -rs0);
3371 glVertex2f(rs0, -rs0);
3372 glVertex2f(rs2, -rs0);
3373
3374 glVertex2f(-rs0, rs2);
3375 glVertex2f(-rs0, rs0);
3376 glVertex2f(-rs0, rs0);
3377 glVertex2f(-rs2, rs0);
3378
3379 glVertex2f(-rs0, -rs2);
3380 glVertex2f(-rs0, -rs0);
3381 glVertex2f(-rs0, -rs0);
3382 glVertex2f(-rs2, -rs0);
3383 OOGLEND();
3384
3385 if (showText) {
3386 // add text for reticle here
3387 range *= 0.001f;
3388 if (range < 0.001f)
3389 range = 0.0f; // avoids the occasional -0.001 km distance.
3390 NSSize textsize = NSMakeSize(rdist * scale, rdist * scale);
3391 float line_height = rdist * scale;
3392 NSString* infoline = [NSString stringWithFormat:@"%0.3f %@", range, distance_unit];
3393 if (legal_desc != nil)
3394 infoline = [NSString stringWithFormat:@"%@ (%@)", infoline, legal_desc];
3395 // no need to set colour here
3396 OODrawString([player1 dialTargetName], rs0, 0.5 * rs2, 0, textsize);
3397 OODrawString(infoline, rs0, 0.5 * rs2 - line_height, 0, textsize);
3398
3399 if ([target isWormhole]) {
3400 // Note: No break statements in the following switch() since every case
3401 // falls through to the next. Cases arranged in reverse order.
3402 switch ([(WormholeEntity*)target scanInfo]) {
3403 case WH_SCANINFO_SHIP:
3404 // TOOD: Render anything on the HUD for this?
3406 // Rendered above in dialTargetName, so no need to do anything here
3407 // unless we want a separate line Destination: XXX ?
3409 NSString* wormholeETA = [NSString stringWithFormat:DESC(@"wormhole-ETA-@"), ClockToString([(WormholeEntity*)target estimatedArrivalTime], NO)];
3410 OODrawString(wormholeETA, rs0, 0.5 * rs2 - 3 * line_height, 0, textsize);
3411 }
3414 int minutesToCollapse = floor(timeForCollapsing / 60.0);
3415 int secondsToCollapse = (int)timeForCollapsing % 60;
3416
3417 NSString* wormholeExpiringIn = [NSString stringWithFormat:DESC(@"wormhole-collapsing-in-mm:ss"), minutesToCollapse, secondsToCollapse];
3418 OODrawString(wormholeExpiringIn, rs0, 0.5 * rs2 - 2 * line_height, 0, textsize);
3419 }
3421 case WH_SCANINFO_NONE:
3422 break;
3423 }
3424 }
3425 }
3426
3428}
3429
3430static void hudDrawWaypoint(OOWaypointEntity* waypoint, PlayerEntity* player1, GLfloat z1, GLfloat alpha, BOOL selected, GLfloat scale)
3431{
3432 if ([player1 guiScreen] != GUI_SCREEN_MAIN) // don't draw on text screens
3433 {
3434 return;
3435 }
3436
3437 Vector p1 = HPVectorToVector(HPvector_subtract([waypoint position], [player1 viewpointPosition]));
3438
3441
3442 // either close enough that single precision is fine or far enough
3443 // away that precision is irrelevant
3444
3445 GLfloat rdist = magnitude(p1);
3446 GLfloat rsize = rdist * scale;
3447
3448 GLfloat rs0 = rsize;
3449 GLfloat rs2 = rsize * 0.50;
3450
3451 if (selected) {
3453 } else {
3454 GLColorWithOverallAlpha(blue_color, alpha * 0.25);
3455 }
3456
3457 OOGLBEGIN(GL_LINES);
3458 glVertex2f(rs0, rs2);
3459 glVertex2f(rs2, rs2);
3460 glVertex2f(rs2, rs0);
3461 glVertex2f(rs2, rs2);
3462
3463 glVertex2f(-rs0, rs2);
3464 glVertex2f(-rs2, rs2);
3465 glVertex2f(-rs2, rs0);
3466 glVertex2f(-rs2, rs2);
3467
3468 glVertex2f(-rs0, -rs2);
3469 glVertex2f(-rs2, -rs2);
3470 glVertex2f(-rs2, -rs0);
3471 glVertex2f(-rs2, -rs2);
3472
3473 glVertex2f(rs0, -rs2);
3474 glVertex2f(rs2, -rs2);
3475 glVertex2f(rs2, -rs0);
3476 glVertex2f(rs2, -rs2);
3477
3478 // glVertex2f(0,-rs2); glVertex2f(0,rs2);
3479 // glVertex2f(rs2,0); glVertex2f(-rs2,0);
3480 OOGLEND();
3481
3482 if (selected) {
3483 GLfloat range = HPdistance([player1 position], [waypoint position]) * 0.001f;
3484 if (range < 0.001f)
3485 range = 0.0f; // avoids the occasional -0.001 km distance.
3486 NSSize textsize = NSMakeSize(rdist * scale, rdist * scale);
3487 float line_height = rdist * scale;
3488 NSString* infoline = [NSString stringWithFormat:@"%0.3f %@", range, distance_unit];
3489 OODrawString(infoline, rs0 * 0.5, -rs2 - line_height, 0, textsize);
3490 }
3491
3493}
3494
3496{
3497 Quaternion back_q = [player1 orientation];
3498 back_q.w = -back_q.w; // invert
3499 Vector v1 = vector_up_from_quaternion(back_q);
3500 NSSize viewSize = [[UNIVERSE gameView] viewSize];
3501 float aspect = viewSize.width / viewSize.height;
3502
3503 // The field of view transformation is really a scale operation on the view window.
3504 // We must unapply it through these transformations for them to be right.
3505 // We must also take into account the window aspect ratio.
3506 float ratio = 2 * [[UNIVERSE gameView] fov:YES]; // FIXME 2 is magic number; fov should integrate it
3507 if (3.0f * aspect >= 4.0f) {
3508 OOGLScaleModelView(make_vector(1 / ratio, 1 / ratio, 1.0f));
3509 } else {
3510 OOGLScaleModelView(make_vector((4.0f / 3.0f) / (aspect * ratio), (4.0f / 3.0f) / (aspect * ratio), 1.0f));
3511 }
3512
3513 // deal with view directions
3514 Vector view_dir, view_up = kBasisYVector;
3515 switch ([UNIVERSE viewDirection]) {
3516 default:
3517 case VIEW_FORWARD:
3518 view_dir.x = 0.0;
3519 view_dir.y = 0.0;
3520 view_dir.z = 1.0;
3521 break;
3522
3523 case VIEW_AFT:
3524 view_dir.x = 0.0;
3525 view_dir.y = 0.0;
3526 view_dir.z = -1.0;
3527 quaternion_rotate_about_axis(&back_q, v1, M_PI);
3528 break;
3529
3530 case VIEW_PORT:
3531 view_dir.x = -1.0;
3532 view_dir.y = 0.0;
3533 view_dir.z = 0.0;
3534 quaternion_rotate_about_axis(&back_q, v1, 0.5 * M_PI);
3535 break;
3536
3537 case VIEW_STARBOARD:
3538 view_dir.x = 1.0;
3539 view_dir.y = 0.0;
3540 view_dir.z = 0.0;
3541 quaternion_rotate_about_axis(&back_q, v1, -0.5 * M_PI);
3542 break;
3543
3544 case VIEW_CUSTOM:
3545 view_dir = [player1 customViewForwardVector];
3546 view_up = [player1 customViewUpVector];
3547 back_q = quaternion_multiply([player1 customViewQuaternion], back_q);
3548 break;
3549 }
3550 OOGLLookAt(view_dir, kZeroVector, view_up);
3551
3552 // rotate the view
3553 OOGLMultModelView([player1 rotationMatrix]);
3554 // translate the view
3556 // rotate to face player1
3558
3559 // We come back now to the previous scale.
3560 OOGLScaleModelView(make_vector(ratio, ratio, 1.0f));
3561 // draw the waypoint
3562}
3563
3564static void InitTextEngine(void)
3565{
3566 NSDictionary* fontSpec = nil;
3567 NSArray* widths = nil;
3568 NSString* texName = nil;
3569 NSUInteger i, count;
3570
3571 fontSpec = [ResourceManager dictionaryFromFilesNamed:@"oolite-font.plist"
3572 inFolder:@"Config"
3573 andMerge:NO];
3574
3575 texName = [fontSpec oo_stringForKey:@"texture" defaultValue:@"oolite-font.png"];
3577 inFolder:@"Textures"
3578 options:kFontTextureOptions
3579 anisotropy:0.0f
3580 lodBias:-0.75f];
3581 [sFontTexture retain];
3582
3583 sF6KernGovt = [fontSpec oo_floatForKey:@"f6KernGovernment" defaultValue:1.0];
3584 sF6KernTL = [fontSpec oo_floatForKey:@"f6KernTechLevel" defaultValue:2.0];
3585
3586 sEncodingCoverter = [[OOEncodingConverter alloc] initWithFontPList:fontSpec];
3587 widths = [fontSpec oo_arrayForKey:@"widths"];
3588 count = [widths count];
3589 if (count > 256)
3590 count = 256;
3591 for (i = 0; i != count; ++i) {
3592 sGlyphWidths[i] = [widths oo_floatAtIndex:i] * GLYPH_SCALE_FACTOR;
3593 }
3594}
3595
3601
3602static GLfloat drawCharacterQuad(uint8_t chr, GLfloat x, GLfloat y, GLfloat z, NSSize siz)
3603{
3604 // 31 (narrow space) and 32 (space) are non-printing characters, so
3605 // don't print them, just return their width to move the pointer
3606 if (chr > 32 || chr < 31) {
3607 GLfloat texture_x = ONE_SIXTEENTH * (chr & 0x0f);
3608 GLfloat texture_y = ONE_SIXTEENTH * (chr >> 4);
3609 if (chr > 32)
3610 y += ONE_EIGHTH * siz.height; // Adjust for baseline offset change in 1.71 (needed to keep accented characters in box)
3611
3612 glTexCoord2f(texture_x, texture_y + ONE_SIXTEENTH);
3613 glVertex3f(x, y, z);
3614 glTexCoord2f(texture_x + ONE_SIXTEENTH, texture_y + ONE_SIXTEENTH);
3615 glVertex3f(x + siz.width, y, z);
3616 glTexCoord2f(texture_x + ONE_SIXTEENTH, texture_y);
3617 glVertex3f(x + siz.width, y + siz.height, z);
3618 glTexCoord2f(texture_x, texture_y);
3619 glVertex3f(x, y + siz.height, z);
3620 }
3621 return siz.width * sGlyphWidths[chr];
3622}
3623
3624NSRect OORectFromString(NSString* text, GLfloat x, GLfloat y, NSSize siz)
3625{
3626 GLfloat w = 0;
3627 NSData* data = nil;
3628 const uint8_t* bytes = NULL;
3629 NSUInteger i, length;
3630
3631 data = [sEncodingCoverter convertString:text];
3632 bytes = [data bytes];
3633 length = [data length];
3634
3635 for (i = 0; i < length; i++) {
3636 w += siz.width * sGlyphWidths[bytes[i]];
3637 }
3638
3639 return NSMakeRect(x, y, w, siz.height);
3640}
3641
3642CGFloat OOStringWidthInEm(NSString* text)
3643{
3644 return OORectFromString(text, 0, 0, NSMakeSize(1.0 / (GLYPH_SCALE_FACTOR * 8.0), 1.0)).size.width;
3645}
3646
3647void drawHighlight(GLfloat x, GLfloat y, GLfloat z, NSSize siz, GLfloat alpha)
3648{
3649 // Rounded corners, fading 'shadow' version
3650 OOGL(glColor4f(0.0f, 0.0f, 0.0f, alpha * 0.4f)); // dark translucent shadow
3651
3652 OOGLBEGIN(GL_POLYGON);
3653 // thin 'halo' around the 'solid' highlight
3654 glVertex3f(x + 1.0f, y + siz.height + 2.5f, z);
3655 glVertex3f(x + siz.width + 3.0f, y + siz.height + 2.5f, z);
3656 glVertex3f(x + siz.width + 4.5f, y + siz.height + 1.0f, z);
3657 glVertex3f(x + siz.width + 4.5f, y + 3.0f, z);
3658 glVertex3f(x + siz.width + 3.0f, y + 1.5f, z);
3659 glVertex3f(x + 1.0f, y + 1.5f, z);
3660 glVertex3f(x - 0.5f, y + 3.0f, z);
3661 glVertex3f(x - 0.5f, y + siz.height + 1.0f, z);
3662 OOGLEND();
3663
3664 OOGLBEGIN(GL_POLYGON);
3665 glVertex3f(x + 1.0f, y + siz.height + 2.0f, z);
3666 glVertex3f(x + siz.width + 3.0f, y + siz.height + 2.0f, z);
3667 glVertex3f(x + siz.width + 4.0f, y + siz.height + 1.0f, z);
3668 glVertex3f(x + siz.width + 4.0f, y + 3.0f, z);
3669 glVertex3f(x + siz.width + 3.0f, y + 2.0f, z);
3670 glVertex3f(x + 1.0f, y + 2.0f, z);
3671 glVertex3f(x, y + 3.0f, z);
3672 glVertex3f(x, y + siz.height + 1.0f, z);
3673 OOGLEND();
3674}
3675
3676void OODrawString(NSString* text, GLfloat x, GLfloat y, GLfloat z, NSSize siz)
3677{
3678 OODrawStringAligned(text, x, y, z, siz, NO);
3679}
3680
3681void OODrawStringAligned(NSString* text, GLfloat x, GLfloat y, GLfloat z, NSSize siz, BOOL rightAlign)
3682{
3684 OODrawStringQuadsAligned(text, x, y, z, siz, rightAlign);
3686}
3687
3689{
3691
3692 OOGL(glEnable(GL_TEXTURE_2D));
3694 OOGLBEGIN(GL_QUADS);
3695}
3696
3697void OODrawStringQuadsAligned(NSString* text, GLfloat x, GLfloat y, GLfloat z, NSSize siz, BOOL rightAlign)
3698{
3699 GLfloat cx = x;
3700 NSInteger i, length;
3701 NSData* data = nil;
3702 const uint8_t* bytes = NULL;
3703
3704 data = [sEncodingCoverter convertString:text];
3705 length = [data length];
3706 bytes = [data bytes];
3707
3708 if (EXPECT_NOT(rightAlign)) {
3709 cx -= OORectFromString(text, 0.0f, 0.0f, siz).size.width;
3710 }
3711
3712 for (i = 0; i < length; i++) {
3713 cx += drawCharacterQuad(bytes[i], cx, y, z, siz);
3714 }
3715}
3716
3718{
3719 OOGLEND();
3720
3722 OOGL(glDisable(GL_TEXTURE_2D));
3723
3725}
3726
3727void OODrawHilightedString(NSString* text, GLfloat x, GLfloat y, GLfloat z, NSSize siz)
3728{
3729 GLfloat color[4];
3730
3731 // get the physical dimensions of the string
3732 NSSize strsize = OORectFromString(text, 0.0f, 0.0f, siz).size;
3733 strsize.width += 0.5f;
3734
3736
3737 OOGL(glPushAttrib(GL_CURRENT_BIT)); // save the text colour
3738 OOGL(glGetFloatv(GL_CURRENT_COLOR, color)); // we need the original colour's alpha.
3739
3740 drawHighlight(x, y, z, strsize, color[3]);
3741
3742 OOGL(glPopAttrib()); // restore the colour
3743
3744 OODrawString(text, x, y, z, siz);
3745
3747}
3748
3749void OODrawPlanetInfo(int gov, int eco, int tec, GLfloat x, GLfloat y, GLfloat z, NSSize siz)
3750{
3751 GLfloat govcol[] = { 0.5, 0.0, 0.7,
3752 0.7, 0.5, 0.3,
3753 0.0, 1.0, 0.3,
3754 1.0, 0.8, 0.1,
3755 1.0, 0.0, 0.0,
3756 0.1, 0.5, 1.0,
3757 0.7, 0.7, 0.7,
3758 0.7, 1.0, 1.0 };
3759
3760 GLfloat cx = x;
3761 int tl = tec + 1;
3762 GLfloat ce1 = 1.0f - 0.125f * eco;
3763
3765
3766 OOGL(glEnable(GL_TEXTURE_2D));
3768
3769 OOGLBEGIN(GL_QUADS);
3770 {
3771 [[UNIVERSE gui] setGLColorFromSetting:[NSString stringWithFormat:kGuiChartEconomyUColor, (size_t)eco]
3772 defaultValue:[OOColor colorWithRed:ce1 green:1.0f blue:0.0f alpha:1.0f]
3773 alpha:1.0];
3774
3775 // see OODrawHilightedPlanetInfo
3776 cx += drawCharacterQuad(23 - eco, cx, y, z, siz); // characters 16..23 are economy symbols
3777 [[UNIVERSE gui] setGLColorFromSetting:[NSString stringWithFormat:kGuiChartGovernmentUColor, (size_t)gov]
3778 defaultValue:[OOColor colorWithRed:govcol[gov * 3] green:govcol[1 + (gov * 3)] blue:govcol[2 + (gov * 3)] alpha:1.0f]
3779 alpha:1.0];
3780
3781 cx += drawCharacterQuad(gov, cx, y, z, siz) - sF6KernGovt; // charcters 0..7 are government symbols
3782 [[UNIVERSE gui] setGLColorFromSetting:kGuiChartTechColor
3783 defaultValue:[OOColor colorWithRed:0.5 green:1.0f blue:1.0f alpha:1.0f]
3784 alpha:1.0];
3785
3786 if (tl > 9) {
3787 // display TL clamped between 1..16, this must be a '1'!
3788 cx += drawCharacterQuad(49, cx, y - 2, z, siz) - sF6KernTL;
3789 }
3790 cx += drawCharacterQuad(48 + (tl % 10), cx, y - 2.0f, z, siz);
3791 }
3792 OOGLEND();
3793
3794 (void)cx; // Suppress "value not used" analyzer issue.
3795
3797 OOGL(glDisable(GL_TEXTURE_2D));
3798
3800}
3801
3802void OODrawHilightedPlanetInfo(int gov, int eco, int tec, GLfloat x, GLfloat y, GLfloat z, NSSize siz)
3803{
3804 float color[4];
3805 int tl = tec + 1;
3806
3807 NSSize hisize;
3808
3809 // get the physical dimensions
3810 hisize.height = siz.height;
3811 hisize.width = 0.0f;
3812
3813 // see OODrawPlanetInfo
3814 hisize.width += siz.width * sGlyphWidths[23 - eco];
3815 hisize.width += siz.width * sGlyphWidths[gov] - 1.0;
3816 if (tl > 9)
3817 hisize.width += siz.width * sGlyphWidths[49] - 2.0;
3818 hisize.width += siz.width * sGlyphWidths[48 + (tl % 10)];
3819
3821
3822 OOGL(glPushAttrib(GL_CURRENT_BIT)); // save the text colour
3823 OOGL(glGetFloatv(GL_CURRENT_COLOR, color)); // we need the original colour's alpha.
3824
3825 drawHighlight(x, y - 2.0f, z, hisize, color[3]);
3826
3827 OOGL(glPopAttrib()); // restore the colour
3828
3829 OODrawPlanetInfo(gov, eco, tec, x, y, z, siz);
3830
3832}
3833
3834static void GLDrawNonlinearCascadeWeapon(GLfloat x, GLfloat y, GLfloat z, NSSize siz, Vector centre, GLfloat radius, GLfloat zoom, GLfloat alpha)
3835{
3836 Vector spacepos, scannerpos;
3837 GLfloat theta, phi;
3838 GLfloat z_factor = siz.height / siz.width; // approx 1/4
3839 GLfloat y_factor = 1.0 - sqrt(z_factor); // approx 1/2
3840 OOGLVector* points = malloc(sizeof(OOGLVector) * 25);
3841 int i, j;
3842
3843 if (radius * radius > centre.y * centre.y) {
3844 GLfloat r0 = sqrt(radius * radius - centre.y * centre.y);
3845 OOGL(glColor4f(1.0, 0.5, 1.0, alpha));
3846 spacepos.y = 0;
3847 for (i = 0; i < 24; i++) {
3848 theta = i * 2 * M_PI / 24;
3849 spacepos.x = centre.x + r0 * cos(theta);
3850 spacepos.z = centre.z + r0 * sin(theta);
3851 scannerpos = [HeadUpDisplay nonlinearScannerScale:spacepos Zoom:zoom Scale:0.5 * siz.width];
3852 points[i].x = x + scannerpos.x;
3853 points[i].y = y + scannerpos.z * z_factor + scannerpos.y * y_factor;
3854 points[i].z = z;
3855 }
3856 spacepos.x = centre.x + r0;
3857 spacepos.y = 0;
3858 spacepos.z = centre.z;
3859 scannerpos = [HeadUpDisplay nonlinearScannerScale:spacepos Zoom:zoom Scale:0.5 * siz.width];
3860 points[24].x = x + scannerpos.x;
3861 points[24].y = y + scannerpos.z * z_factor + scannerpos.y * y_factor;
3862 points[24].z = z;
3863 GLDrawPoints(points, 25);
3864 }
3865 OOGL(glColor4f(0.5, 0.0, 1.0, 0.33333 * alpha));
3866 free(points);
3867 // Here, we draw a sphere distorted by the nonlinear function. We draw the sphere as a set of horizontal strips
3868 // The even indices of points are the points on the upper edge of the strip, while odd indices are points
3869 // on the bottom edge.
3870 points = malloc(sizeof(OOGLVector) * 50);
3871 spacepos.x = centre.x;
3872 spacepos.y = centre.y + radius;
3873 spacepos.z = centre.z;
3874 scannerpos = [HeadUpDisplay nonlinearScannerScale:spacepos Zoom:zoom Scale:0.5 * siz.width];
3875 for (i = 0; i <= 24; i++) {
3876 points[2 * i + 1].x = x + scannerpos.x;
3877 points[2 * i + 1].y = y + scannerpos.y * y_factor + scannerpos.z * z_factor;
3878 points[2 * i + 1].z = z;
3879 }
3880 for (i = 1; i <= 24; i++) {
3881 theta = i * M_PI / 24;
3882 for (j = 0; j <= 24; j++) {
3883 phi = j * M_PI / 12;
3884 // copy point from bottom edge of previous strip into top edge position
3885 points[2 * j] = points[2 * j + 1];
3886
3887 spacepos.x = centre.x + radius * sin(theta) * cos(phi);
3888 spacepos.y = centre.y + radius * cos(theta);
3889 spacepos.z = centre.z + radius * sin(theta) * sin(phi);
3890 scannerpos = [HeadUpDisplay nonlinearScannerScale:spacepos Zoom:zoom Scale:0.5 * siz.width];
3891 points[2 * j + 1].x = x + scannerpos.x;
3892 points[2 * j + 1].y = y + scannerpos.y * y_factor + scannerpos.z * z_factor;
3893 points[2 * j + 1].z = z;
3894 }
3895 GLDrawQuadStrip(points, 50);
3896 }
3897 free(points);
3898 return;
3899}
3900
3901static GLfloat nonlinearScannerFunc(GLfloat distance, GLfloat zoom, GLfloat scale)
3902{
3903 GLfloat x = fabs(distance / SCANNER_MAX_RANGE);
3904 if (x >= 1.0)
3905 return scale;
3906 if (zoom <= 1.0)
3907 return scale * x;
3908 GLfloat c = 1 / (zoom - 1);
3909 GLfloat b = c * (c + 1);
3910 GLfloat a = c + 1;
3911 return scale * (a - b / (x + c));
3912}
3913
3914static void drawScannerGrid(GLfloat x, GLfloat y, GLfloat z, NSSize siz, int v_dir, GLfloat thickness, GLfloat zoom, BOOL nonlinear, BOOL minimalistic)
3915{
3917
3918 MyOpenGLView* gameView = [UNIVERSE gameView];
3919
3920 GLfloat w1, h1;
3921 GLfloat ww = 0.5 * siz.width;
3922 GLfloat hh = 0.5 * siz.height;
3923
3924 GLfloat km_scan;
3925 GLfloat hdiv;
3926 GLfloat wdiv;
3927 BOOL drawdiv = NO, drawdiv1 = NO, drawdiv5 = NO;
3928
3929 int i, ii;
3930
3931 OOGL(GLScaledLineWidth(2.0 * thickness));
3932 GLDrawOval(x, y, z, siz, 4);
3933 OOGL(GLScaledLineWidth(thickness)); // reset (thickness = lineWidth)
3934
3935 OOGLBEGIN(GL_LINES);
3936 if (!minimalistic) {
3937 glVertex3f(x, y - hh, z);
3938 glVertex3f(x, y + hh, z);
3939 glVertex3f(x - ww, y, z);
3940 glVertex3f(x + ww, y, z);
3941
3942 if (nonlinear) {
3943 if (nonlinearScannerFunc(4000.0, zoom, hh) - nonlinearScannerFunc(3000.0, zoom, hh) > 2)
3944 drawdiv1 = YES;
3945 if (nonlinearScannerFunc(10000.0, zoom, hh) - nonlinearScannerFunc(5000.0, zoom, hh) > 2)
3946 drawdiv5 = YES;
3947 wdiv = ww / (0.001 * SCANNER_MAX_RANGE);
3948 for (i = 1; 1000.0 * i < SCANNER_MAX_RANGE; i++) {
3949 drawdiv = drawdiv1;
3950 w1 = wdiv;
3951 if (i % 10 == 0) {
3952 w1 = wdiv * 4;
3953 drawdiv = YES;
3954 if (nonlinearScannerFunc((i + 5) * 1000, zoom, hh) - nonlinearScannerFunc(i * 1000.0, zoom, hh) > 2) {
3955 drawdiv5 = YES;
3956 } else {
3957 drawdiv5 = NO;
3958 }
3959 } else if (i % 5 == 0) {
3960 w1 = wdiv * 2;
3961 drawdiv = drawdiv5;
3962 if (nonlinearScannerFunc((i + 1) * 1000, zoom, hh) - nonlinearScannerFunc(i * 1000.0, zoom, hh) > 2) {
3963 drawdiv1 = YES;
3964 } else {
3965 drawdiv1 = NO;
3966 }
3967 }
3968 if (drawdiv) {
3969 h1 = nonlinearScannerFunc(i * 1000.0, zoom, hh);
3970 glVertex3f(x - w1, y + h1, z);
3971 glVertex3f(x + w1, y + h1, z);
3972 glVertex3f(x - w1, y - h1, z);
3973 glVertex3f(x + w1, y - h1, z);
3974 }
3975 }
3976 } else {
3977 km_scan = 0.001 * SCANNER_MAX_RANGE / zoom; // calculate kilometer divisions
3978 hdiv = 0.5 * siz.height / km_scan;
3979 wdiv = 0.25 * siz.width / km_scan;
3980 if (wdiv < 4.0) {
3981 wdiv *= 2.0;
3982 ii = 5;
3983 } else {
3984 ii = 1;
3985 }
3986
3987 for (i = ii; 2.0 * hdiv * i < siz.height; i += ii) {
3988 h1 = i * hdiv;
3989 w1 = wdiv;
3990 if (i % 5 == 0)
3991 w1 = w1 * 2.5;
3992 if (i % 10 == 0)
3993 w1 = w1 * 2.0;
3994 if (w1 > 3.5) // don't draw tiny marks
3995 {
3996 glVertex3f(x - w1, y + h1, z);
3997 glVertex3f(x + w1, y + h1, z);
3998 glVertex3f(x - w1, y - h1, z);
3999 glVertex3f(x + w1, y - h1, z);
4000 }
4001 }
4002 }
4003 }
4004
4005 double tanfov = [gameView fov:YES];
4006 GLfloat aspect = [gameView viewSize].width / [gameView viewSize].height;
4007 if (aspect < 4.0 / 3.0) {
4008 tanfov *= 0.75 * aspect;
4009 }
4010 double cosfov = 1.0 / sqrt(1 + tanfov * tanfov);
4011 double sinfov = tanfov * cosfov;
4012
4013 switch (v_dir) {
4014 case VIEW_BREAK_PATTERN:
4015 case VIEW_GUI_DISPLAY:
4016 case VIEW_FORWARD:
4017 case VIEW_NONE:
4018 glVertex3f(x, y, z);
4019 glVertex3f(x - ww * sinfov, y + hh * cosfov, z);
4020 glVertex3f(x, y, z);
4021 glVertex3f(x + ww * sinfov, y + hh * cosfov, z);
4022 break;
4023
4024 case VIEW_AFT:
4025 glVertex3f(x, y, z);
4026 glVertex3f(x - ww * sinfov, y - hh * cosfov, z);
4027 glVertex3f(x, y, z);
4028 glVertex3f(x + ww * sinfov, y - hh * cosfov, z);
4029 break;
4030
4031 case VIEW_PORT:
4032 glVertex3f(x, y, z);
4033 glVertex3f(x - ww * cosfov, y + hh * sinfov, z);
4034 glVertex3f(x, y, z);
4035 glVertex3f(x - ww * cosfov, y - hh * sinfov, z);
4036 break;
4037
4038 case VIEW_STARBOARD:
4039 glVertex3f(x, y, z);
4040 glVertex3f(x + ww * cosfov, y + hh * sinfov, z);
4041 glVertex3f(x, y, z);
4042 glVertex3f(x + ww * cosfov, y - hh * sinfov, z);
4043 break;
4044 }
4045 OOGLEND();
4046
4048}
4049
4050static void DrawSpecialOval(GLfloat x, GLfloat y, GLfloat z, NSSize siz, GLfloat step, GLfloat* color4v)
4051{
4052 GLfloat ww = 0.5 * siz.width;
4053 GLfloat hh = 0.5 * siz.height;
4054 GLfloat theta;
4055 GLfloat delta;
4056 GLfloat s;
4057
4058 delta = step * M_PI / 180.0f;
4059
4060 OOGLBEGIN(GL_LINE_LOOP);
4061 for (theta = 0.0f; theta < (2.0f * M_PI); theta += delta) {
4062 s = sin(theta);
4063 glColor4f(color4v[0], color4v[1], color4v[2], fabs(s * color4v[3]));
4064 glVertex3f(x + ww * s, y + hh * cos(theta), z);
4065 }
4066 OOGLEND();
4067}
4068
4069- (void)setLineWidth:(GLfloat)value
4070{
4071 lineWidth = value;
4072}
4073
4074- (GLfloat)lineWidth
4075{
4076 return lineWidth;
4077}
4078
4079@end
4080
4081@implementation NSString (OODisplayEncoding)
4082
4084{
4085 if (sEncodingCoverter == nil)
4086 InitTextEngine();
4087
4088 // Note: the data will be autoreleased, so the bytes behave as though they're autoreleased too.
4089 return [[self dataUsingEncoding:[sEncodingCoverter encoding] allowLossyConversion:YES] bytes];
4090}
4091
4093{
4094 if (sEncodingCoverter == nil)
4095 InitTextEngine();
4096
4097 // Note: the data will be autoreleased, so the bytes behave as though they're autoreleased too.
4098 return [[sEncodingCoverter convertString:self] bytes];
4099}
4100
4101@end
4102
4103@implementation OOPolygonSprite (OOHUDBeaconIcon)
4104
4105- (void)oo_drawHUDBeaconIconAt:(NSPoint)where size:(NSSize)size alpha:(GLfloat)alpha z:(GLfloat)z
4106{
4107 GLfloat x = where.x - size.width;
4108 GLfloat y = where.y - 1.5 * size.height;
4109
4110 GLfloat ox = x - size.width * 0.5;
4111 GLfloat oy = y - size.height * 0.5;
4112 GLfloat width = size.width * (1.0f / 6.0f);
4113 GLfloat height = size.height * (1.0f / 6.0f);
4114
4117 OOGLScaleModelView(make_vector(width, height, 1.0f));
4118 [self drawFilled];
4119 glColor4f(0.0, 0.0, 0.0, 0.5 * alpha);
4120 [self drawOutline];
4122}
4123
4124@end
4125
4126@implementation NSString (OOHUDBeaconIcon)
4127
4128- (void)oo_drawHUDBeaconIconAt:(NSPoint)where size:(NSSize)size alpha:(GLfloat)alpha z:(GLfloat)z
4129{
4130 OODrawString(self, where.x - 2.5 * size.width, where.y - 3.0 * size.height, z, NSMakeSize(size.width * 2, size.height * 2));
4131}
4132
4133@end
4134
4135static void SetGLColourFromInfo(NSDictionary* info, NSString* key, const GLfloat defaultColor[4], GLfloat alpha)
4136{
4137 id colorDesc = nil;
4138 OOColor* color = nil;
4139 colorDesc = [info objectForKey:key];
4140 if (colorDesc != nil) {
4141 color = [OOColor colorWithDescription:colorDesc];
4142 if (color != nil) {
4143 GLfloat ioColor[4];
4144 [color getRed:&ioColor[0] green:&ioColor[1] blue:&ioColor[2] alpha:&ioColor[3]];
4145 GLColorWithOverallAlpha(ioColor, alpha);
4146 return;
4147 }
4148 }
4149 GLColorWithOverallAlpha(defaultColor, alpha);
4150}
4151
4152static void GetRGBAArrayFromInfo(NSDictionary* info, GLfloat ioColor[4])
4153{
4154 id colorDesc = nil;
4155 OOColor* color = nil;
4156
4157 // First, look for general colour specifier.
4158 colorDesc = [info objectForKey:RGB_COLOR_KEY];
4159 if (colorDesc != nil && ![info objectForKey:ALPHA_KEY]) {
4160 color = [OOColor colorWithDescription:colorDesc];
4161 if (color != nil) {
4162 [color getRed:&ioColor[0] green:&ioColor[1] blue:&ioColor[2] alpha:&ioColor[3]];
4163 return;
4164 }
4165 }
4166
4167 // Failing that, look for rgb_color and alpha.
4168 colorDesc = [info oo_arrayForKey:RGB_COLOR_KEY];
4169 if (colorDesc != nil && [colorDesc count] == 3) {
4170 ioColor[0] = [colorDesc oo_nonNegativeFloatAtIndex:0];
4171 ioColor[1] = [colorDesc oo_nonNegativeFloatAtIndex:1];
4172 ioColor[2] = [colorDesc oo_nonNegativeFloatAtIndex:2];
4173 }
4174 ioColor[3] = [info oo_nonNegativeFloatForKey:ALPHA_KEY defaultValue:ioColor[3]];
4175}
#define SCANNER_MAX_RANGE
Definition Entity.h:53
#define SCANNER_MAX_RANGE2
Definition Entity.h:54
#define ZOOM_INDICATOR_HEIGHT
#define SELECTOR_KEY
#define ROW_HEIGHT_KEY
#define CABIN_TEMP_BAR_HEIGHT
#define AFT_SHIELD_BAR_HEIGHT
#define HEIGHT_KEY
#define FPSINFO_DISPLAY_Y
#define SCOOPSTATUS_HEIGHT
#define CABIN_TEMP_BAR_CENTRE_Y
#define FPSINFO_DISPLAY_WIDTH
#define SCANNER_WIDTH
#define MISSILE_ICON_WIDTH
#define ASCTARGET_DISPLAY_WIDTH
#define STATUS_LIGHT_CENTRE_X
#define ALTITUDE_BAR_CENTRE_X
#define MFD_TEXT_WIDTH
#define SPEED_BAR_CENTRE_Y
#define SCANNER_CENTRE_Y
void OODrawStringAligned(NSString *text, GLfloat x, GLfloat y, GLfloat z, NSSize siz, BOOL rightAlign)
#define WIDTH_KEY
#define ZOOM_INDICATOR_WIDTH
#define PITCH_BAR_CENTRE_Y
#define SCOOPSTATUS_CENTRE_X
#define ASCTARGET_DISPLAY_HEIGHT
#define ROLL_BAR_CENTRE_Y
#define WEAPON_TEMP_BAR_HEIGHT
#define AEGIS_CENTRE_Y
#define X_KEY
#define SCOOPSTATUS_WIDTH
#define ALTITUDE_BAR_WIDTH
#define SCANNER_ZOOM_LEVELS
#define CABIN_TEMP_BAR_WIDTH
#define CLOCK_DISPLAY_WIDTH
#define WEAPONSOFFLINETEXT_WIDTH
#define FORWARD_SHIELD_BAR_HEIGHT
#define WEAPON_TEMP_BAR_WIDTH
#define WITCHDEST_WIDTH
void OOHUDResetTextEngine(void)
#define WITCHDEST_HEIGHT
#define SPEED_BAR_WIDTH
#define FORWARD_SHIELD_BAR_WIDTH
void OODrawStringQuadsAligned(NSString *text, GLfloat x, GLfloat y, GLfloat z, NSSize siz, BOOL rightAlign)
#define AFT_SHIELD_BAR_CENTRE_Y
#define FORWARD_SHIELD_BAR_CENTRE_Y
#define ROLL_BAR_WIDTH
#define CLOCK_DISPLAY_Y
#define PRIMED_DISPLAY_WIDTH
#define WEAPONSOFFLINETEXT_DISPLAY_X
#define WEAPONSOFFLINETEXT_HEIGHT
void OOStartDrawingStrings(void)
#define FPSINFO_DISPLAY_HEIGHT
#define TITLE_KEY
#define CABIN_TEMP_BAR_CENTRE_X
#define CUSTOM_DIAL_KEY
#define ROLL_BAR_HEIGHT
#define TEXT_KEY
#define MISSILES_DISPLAY_Y
#define FUEL_BAR_CENTRE_Y
#define AEGIS_CENTRE_X
#define FUEL_BAR_CENTRE_X
#define WEAPON_TEMP_BAR_CENTRE_X
#define ONE_EIGHTH
#define PRIMED_DISPLAY_X
NSRect OORectFromString(NSString *text, GLfloat x, GLfloat y, NSSize siz)
#define AEGIS_WIDTH
#define ZOOM_INDICATOR_CENTRE_X
#define AFT_SHIELD_BAR_WIDTH
#define CLOCK_DISPLAY_X
#define PITCH_BAR_CENTRE_X
#define ALTITUDE_BAR_HEIGHT
#define ACCURACY_PROBABILITY_DECREASE_FACTOR
@ OO_RETICLE_COLOR_TARGET
@ OO_RETICLE_COLOR_WORMHOLE
#define COMPASS_CENTRE_Y
#define ASCTARGET_DISPLAY_X
#define ENERGY_GAUGE_CENTRE_X
#define FUEL_BAR_HEIGHT
#define SPEED_BAR_HEIGHT
#define MISSILES_DISPLAY_X
#define MIN_PROBABILITY_ACCURACY
#define WEAPONSOFFLINETEXT_DISPLAY_Y
#define FORWARD_SHIELD_BAR_CENTRE_X
#define ROLL_BAR_CENTRE_X
#define DIAL_REQUIRED_KEY
void OODrawString(NSString *text, GLfloat x, GLfloat y, GLfloat z, NSSize siz)
#define WEAPON_TEMP_BAR_CENTRE_Y
#define AFT_SHIELD_BAR_CENTRE_X
void OODrawPlanetInfo(int gov, int eco, int tec, GLfloat x, GLfloat y, GLfloat z, NSSize siz)
#define CLOCK_DISPLAY_HEIGHT
#define PRIMED_DISPLAY_HEIGHT
#define FPSINFO_DISPLAY_X
#define ENERGY_GAUGE_HEIGHT
#define BACKGROUND_RGBA_KEY
#define WITCHDEST_CENTRE_X
#define COMPASS_CENTRE_X
#define SCANNER_CENTRE_X
#define ENERGY_GAUGE_WIDTH
void OOStopDrawingStrings(void)
#define PRIMED_DISPLAY_Y
#define MAX_ACCURACY_RANGE
#define ALTITUDE_BAR_CENTRE_Y
#define SCANNER_SCALE
#define COMPASS_HALF_SIZE
#define WITCHDEST_CENTRE_Y
#define ASCTARGET_DISPLAY_Y
#define MISSILE_ICON_HEIGHT
#define AEGIS_HEIGHT
#define SCANNER_HEIGHT
#define PITCH_BAR_HEIGHT
#define STATUS_LIGHT_CENTRE_Y
#define ALPHA_KEY
#define STATUS_LIGHT_HEIGHT
#define SCOOPSTATUS_CENTRE_Y
#define Y_KEY
#define ENERGY_GAUGE_CENTRE_Y
#define FUEL_BAR_WIDTH
#define PITCH_BAR_WIDTH
#define ZOOM_INDICATOR_CENTRE_Y
#define MFD_TEXT_HEIGHT
#define SPEED_BAR_CENTRE_X
static void hudRotateViewpointForVirtualDepth(PlayerEntity *player1, Vector p1)
static void hudDrawStatusIconAt(int x, int y, int z, NSSize siz)
#define SET_COLOR_CRITICAL(d)
static float sF6KernGovt
static void hudDrawWaypoint(OOWaypointEntity *waypoint, PlayerEntity *player1, GLfloat z1, GLfloat alpha, BOOL selected, GLfloat scale)
static NSString * distance_unit
static const GLfloat redplus_color[4]
#define ONE_SIXTEENTH
#define SET_COLOR_LOW(d)
#define SET_COLOR_MEDIUM(d)
static NSString *const kDefaultMissileIconKey
static NSString *const kDefaultMineIconKey
static float sGlyphWidths[256]
static OOEncodingConverter * sEncodingCoverter
#define NOT_DEFINED
#define WIDGET_SELECTOR_NAME
static OOTexture * sFontTexture
static void SetGLColourFromInfo(NSDictionary *info, NSString *key, const GLfloat defaultColor[4], GLfloat alpha)
static void DrawSpecialOval(GLfloat x, GLfloat y, GLfloat z, NSSize siz, GLfloat step, GLfloat *color4v)
static const GLfloat green_color[4]
static GLfloat nonlinearScannerFunc(GLfloat distance, GLfloat zoom, GLfloat scale)
static const GLfloat darkgreen_color[4]
static void hudDrawSurroundAt(GLfloat x, GLfloat y, GLfloat z, NSSize siz)
static void GLDrawNonlinearCascadeWeapon(GLfloat x, GLfloat y, GLfloat z, NSSize siz, Vector centre, GLfloat radius, GLfloat zoom, GLfloat alpha)
static void hudDrawReticleOnTarget(Entity *target, PlayerEntity *player1, GLfloat z1, GLfloat alpha, BOOL reticleTargetSensitive, NSMutableDictionary *propertiesReticleTargetSensitive, BOOL colourFromScannerColour, BOOL showText, NSDictionary *info, NSMutableArray *reticleColors)
static NSArray * sCurrentDrawItem
static float sF6KernTL
@ kFontTextureOptions
static const GLfloat lightgray_color[4]
static BOOL _compassUpdated
static const GLfloat black_color[4]
#define SET_COLOR_HIGH(d)
static void hudDrawIndicatorAt(GLfloat x, GLfloat y, GLfloat z, NSSize siz, GLfloat amount)
static const GLfloat blue_color[4]
static const GLfloat yellow_color[4]
#define SET_COLOR_SURROUND(d)
static void hudDrawMarkerAt(GLfloat x, GLfloat y, GLfloat z, NSSize siz, GLfloat amount)
#define GLYPH_SCALE_FACTOR
#define SET_COLOR(d)
static const GLfloat red_color[4]
static void GetRGBAArrayFromInfo(NSDictionary *info, GLfloat ioColor[4])
static void drawScannerGrid(GLfloat x, GLfloat y, GLfloat z, NSSize siz, int v_dir, GLfloat thickness, GLfloat zoom, BOOL nonlinear, BOOL minimalistic)
OOINLINE float useDefined(float val, float validVal)
static void hudDrawBarAt(GLfloat x, GLfloat y, GLfloat z, NSSize siz, GLfloat amount)
static const GLfloat kOutlineWidth
OOINLINE float OOClamp_n1_1_f(float value) INLINE_CONST_FUNC
OOINLINE float OOClamp_0_1_f(float value) INLINE_CONST_FUNC
#define DESTROY(x)
#define EXPECT_NOT(x)
#define OOINLINE
OOINLINE HPVector HPvector_subtract(HPVector a, HPVector b) INLINE_CONST_FUNC
Definition OOHPVector.h:236
OOINLINE Vector HPVectorToVector(HPVector v) INLINE_CONST_FUNC
Definition OOHPVector.h:175
OOINLINE OOHPScalar HPdistance(HPVector v1, HPVector v2) INLINE_CONST_FUNC
Definition OOHPVector.h:298
#define OOLogERR(class, format,...)
Definition OOLogging.h:125
NSString *const kOOLogFileNotFound
Definition OOLogging.m:601
GLfloat OOScalar
Definition OOMaths.h:49
#define M_PI
Definition OOMaths.h:54
Vector OOVectorMultiplyMatrix(Vector v, OOMatrix m) CONST_FUNC
Definition OOMatrix.m:121
OOMatrix OOMatrixForQuaternionRotation(Quaternion orientation)
Definition OOMatrix.m:56
void OOGLLookAt(Vector eye, Vector center, Vector up)
void OOGLScaleModelView(Vector scale)
void OOGLPushModelView(void)
void OOGLTranslateModelView(Vector vector)
void OOGLMultModelView(OOMatrix matrix)
OOMatrix OOGLPopModelView(void)
#define OOGLBEGIN
Definition OOOpenGL.h:269
void GLDrawFilledOval(GLfloat x, GLfloat y, GLfloat z, NSSize siz, GLfloat step)
Definition OOOpenGL.m:158
@ OPENGL_STATE_OVERLAY
Definition OOOpenGL.h:124
void GLDrawPoints(OOGLVector *points, int n)
Definition OOOpenGL.m:167
void GLDrawQuadStrip(OOGLVector *points, int n)
Definition OOOpenGL.m:193
#define OOVerifyOpenGLState()
Definition OOOpenGL.h:133
BOOL OOCheckOpenGLErrors(NSString *format,...)
Definition OOOpenGL.m:38
void GLScaledLineWidth(GLfloat width)
Definition OOOpenGL.m:206
void GLDrawOval(GLfloat x, GLfloat y, GLfloat z, NSSize siz, GLfloat step)
Definition OOOpenGL.m:149
#define OOSetOpenGLState(STATE)
Definition OOOpenGL.h:132
#define OOGL(statement)
Definition OOOpenGL.h:262
#define OOGLEND
Definition OOOpenGL.h:270
unsigned count
return nil
void quaternion_rotate_about_axis(Quaternion *quat, Vector axis, OOScalar angle) NONNULL_FUNC
Quaternion quaternion_multiply(Quaternion q1, Quaternion q2) CONST_FUNC
Vector vector_up_from_quaternion(Quaternion quat) CONST_FUNC
float y
float x
#define OOExpandKey(key,...)
@ OO_SYSTEMCONCEALMENT_NONAME
@ kOOTextureNoShrink
Definition OOTexture.h:53
@ kOOTextureMinFilterMipMap
Definition OOTexture.h:48
@ kOOTextureAlphaMask
Definition OOTexture.h:60
@ kOOTextureMagFilterLinear
Definition OOTexture.h:51
@ NO_TARGET
Definition OOTypes.h:169
@ AEGIS_IN_DOCKING_RANGE
Definition OOTypes.h:57
OOViewID
Definition OOTypes.h:39
double OOTimeDelta
Definition OOTypes.h:193
OOINLINE Vector vector_flip(Vector v) INLINE_CONST_FUNC
Definition OOVector.h:227
OOINLINE Vector vector_add(Vector a, Vector b) INLINE_CONST_FUNC
Definition OOVector.h:195
OOINLINE OOScalar magnitude(Vector vec) INLINE_CONST_FUNC
Definition OOVector.h:242
OOINLINE Vector make_vector(OOScalar vx, OOScalar vy, OOScalar vz) INLINE_CONST_FUNC
Definition OOVector.h:149
OOINLINE OOScalar dot_product(Vector first, Vector second) INLINE_CONST_FUNC
Definition OOVector.h:299
OOINLINE Vector vector_normal_or_fallback(Vector vec, Vector fallback) INLINE_CONST_FUNC
Definition OOVector.h:247
const Vector kZeroVector
Definition OOVector.m:27
const Vector kBasisYVector
Definition OOVector.h:46
OOINLINE void scale_vector(Vector *outVector, OOScalar factor) ALWAYS_INLINE_FUNC NONNULL_FUNC
Definition OOVector.h:166
const Vector kBasisZVector
Definition OOVector.h:47
const Vector kBasisXVector
Definition OOVector.h:45
Vector OOVectorRandomRadial(OOScalar maxLength)
Definition OOVector.m:102
OOINLINE OOScalar distance(Vector v1, Vector v2) INLINE_CONST_FUNC
Definition OOVector.h:280
OOINLINE Vector vector_multiply_scalar(Vector v, OOScalar s) INLINE_CONST_FUNC
Definition OOVector.h:180
OOINLINE Vector vector_normal(Vector vec) INLINE_CONST_FUNC
Definition OOVector.h:270
@ SCOOP_STATUS_FULL_HOLD
@ SCOOP_STATUS_NOT_INSTALLED
@ SCOOP_STATUS_ACTIVE
@ SCOOP_STATUS_OKAY
#define PLAYER
OOMissileStatus
@ MISSILE_STATUS_TARGET_LOCKED
@ MISSILE_STATUS_ARMED
@ MISSILE_STATUS_SAFE
#define PLAYER_TARGET_MEMORY_SIZE
OOEquipmentType * OOWeaponType
Definition ShipEntity.h:164
OOAlertCondition
Definition ShipEntity.h:166
@ ALERT_CONDITION_GREEN
Definition ShipEntity.h:170
@ ALERT_CONDITION_RED
Definition ShipEntity.h:172
@ ALERT_CONDITION_YELLOW
Definition ShipEntity.h:171
@ ALERT_CONDITION_DOCKED
Definition ShipEntity.h:169
NSString * OOStringFromWeaponType(OOWeaponType weapon) CONST_FUNC
@ OO_POSTFX_NONE
Definition Universe.h:83
#define UNIVERSE
Definition Universe.h:827
#define DESC(key)
Definition Universe.h:832
#define CROSSHAIR_SIZE
Definition Universe.h:58
@ WH_SCANINFO_NONE
@ WH_SCANINFO_SCANNED
@ WH_SCANINFO_SHIP
@ WH_SCANINFO_ARRIVAL_TIME
@ WH_SCANINFO_DESTINATION
@ WH_SCANINFO_COLLAPSE_TIME
const char * cStringUsingOoliteEncoding()
const char * cStringUsingOoliteEncodingAndRemapping()
GLfloat collision_radius
Definition Entity.h:107
OOUniversalID universalID
Definition Entity.m:522
Quaternion orientation
Definition Entity.m:682
GLfloat zero_distance
Definition Entity.h:104
unsigned isShip
Definition Entity.m:125
GLfloat collisionRadius()
Definition Entity.m:830
OOScanClass scanClass
Definition Entity.m:743
unsigned isWormhole
Definition Entity.m:175
void setTextColor:(OOColor *color)
void resizeTo:characterHeight:title:(NSSize gui_size,[characterHeight] int csize,[title] NSString *gui_title)
void setMaxAlpha:(GLfloat an_alpha)
void setDrawPosition:(Vector vector)
void setCharacterSize:(NSSize character_size)
NSArray * getLastLines()
NSString * title
void setBackgroundColor:(OOColor *color)
void printLongText:align:color:fadeTime:key:addToArray:(NSString *str,[align] OOGUIAlignment alignment,[color] OOColor *text_color,[fadeTime] float text_fade,[key] NSString *text_key,[addToArray] NSMutableArray *text_array)
void setTextCommsColor:(OOColor *color)
void setAlpha:(GLfloat an_alpha)
void setCurrentRow:(OOGUIRow value)
unsigned rowHeight()
void drawSecondaryTargetReticle:(NSDictionary *info)
NSArray * crosshairDefinitionForWeaponType:(OOWeaponType weapon)
OOCrosshairs * _crosshairs
static void DrawSpecialOval(GLfloat x, GLfloat y, GLfloat z, NSSize siz, GLfloat step, GLfloat *color4v)
void drawCompassBeaconBlipAt:Size:Alpha:(Vector relativePosition, [Size] NSSize siz, [Alpha] GLfloat alpha)
NSMutableArray * _reticleColors
Vector nonlinearScannerScale:Zoom:Scale:(Vector V,[Zoom] GLfloat zoom,[Scale] double scale)
static void hudDrawIndicatorAt(GLfloat x, GLfloat y, GLfloat z, NSSize siz, GLfloat amount)
static void hudDrawStatusIconAt(int x, int y, int z, NSSize siz)
GLfloat scanner_zoom
void OOStopDrawingStrings()
void OODrawHilightedPlanetInfo(int gov, int eco, int tec, GLfloat x, GLfloat y, GLfloat z, NSSize siz)
static void hudRotateViewpointForVirtualDepth(PlayerEntity *player1, Vector p1)
BOOL setCrosshairDefinition:(NSString *newDefinition)
void resetGuiPosition:withInfo:(GuiDisplayGen *gui, [withInfo] NSDictionary *gui_info)
void addDial:(NSDictionary *info)
NSString * hudName
void OODrawStringQuadsAligned(NSString *text, GLfloat x, GLfloat y, GLfloat z, NSSize siz, BOOL rightAlign)
NSString * deferredHudName
void addMFD:(NSDictionary *info)
GLfloat _crosshairScale
NSString * crosshairDefinition
static GLfloat nonlinearScannerFunc(GLfloat distance, GLfloat zoom, GLfloat scale)
id initWithDictionary:inFile:(NSDictionary *hudinfo,[inFile] NSString *hudFileName)
void drawIconForMissile:selected:status:x:y:width:height:alpha:(ShipEntity *missile, [selected] BOOL selected, [status] OOMissileStatus status, [x] int x, [y] int y, [width] GLfloat width, [height] GLfloat height, [alpha] GLfloat alpha)
OOINLINE void GLColorWithOverallAlpha(const GLfloat *color, GLfloat alpha)
void drawCompassPlanetBlipAt:Size:Alpha:(Vector relativePosition, [Size] NSSize siz, [Alpha] GLfloat alpha)
static void hudDrawBarAt(GLfloat x, GLfloat y, GLfloat z, NSSize siz, GLfloat amount)
void addLegend:(NSDictionary *info)
OOColor * _crosshairColor
static OOPolygonSprite * IconForMissileRole(NSString *role)
OOWeaponType _lastWeaponType
void drawCompassTargetBlipAt:Size:Alpha:(Vector relativePosition, [Size] NSSize siz, [Alpha] GLfloat alpha)
static void hudDrawSurroundAt(GLfloat x, GLfloat y, GLfloat z, NSSize siz)
void drawMultiFunctionDisplay:withText:asIndex:(NSDictionary *info, [withText] NSString *text, [asIndex] NSUInteger index)
NSMutableSet * _hiddenSelectors
void drawCompassStationBlipAt:Size:Alpha:(Vector relativePosition, [Size] NSSize siz, [Alpha] GLfloat alpha)
NSRect OORectFromString(NSString *text, GLfloat x, GLfloat y, NSSize siz)
void resetGui:withInfo:(GuiDisplayGen *gui, [withInfo] NSDictionary *gui_info)
static void drawScannerGrid(GLfloat x, GLfloat y, GLfloat z, NSSize siz, int v_dir, GLfloat thickness, GLfloat zoom, BOOL nonlinear, BOOL minimalistic)
void OODrawStringAligned(NSString *text, GLfloat x, GLfloat y, GLfloat z, NSSize siz, BOOL rightAlign)
void refreshLastTransmitter()
void OOStartDrawingStrings()
NSUInteger mfdCount()
void drawIconForEmptyPylonAtX:y:width:height:alpha:(int x, [y] int y, [width] GLfloat width, [height] GLfloat height, [alpha] GLfloat alpha)
BOOL cloakIndicatorOnStatusLight
NSMutableArray * mfdArray
NSDictionary * _crosshairOverrides
static void GLDrawNonlinearCascadeWeapon(GLfloat x, GLfloat y, GLfloat z, NSSize siz, Vector centre, GLfloat radius, GLfloat zoom, GLfloat alpha)
static void prefetchData(NSDictionary *info, struct CachedInfo *data)
void drawCompassSunBlipAt:Size:Alpha:(Vector relativePosition, [Size] NSSize siz, [Alpha] GLfloat alpha)
static GLfloat drawCharacterQuad(uint8_t chr, GLfloat x, GLfloat y, GLfloat z, NSSize siz)
void OODrawHilightedString(NSString *text, GLfloat x, GLfloat y, GLfloat z, NSSize siz)
GLfloat scannerZoom()
GLfloat _crosshairWidth
NSMutableArray * dialArray
GLfloat overallAlpha
BOOL minimalistic_scanner
void drawHUDItem:(NSDictionary *info)
OOINLINE void SetCompassBlipColor(GLfloat relativeZ, GLfloat alpha)
void clearHiddenSelectors()
void drawHighlight(GLfloat x, GLfloat y, GLfloat z, NSSize siz, GLfloat alpha)
static void hudDrawMarkerAt(GLfloat x, GLfloat y, GLfloat z, NSSize siz, GLfloat amount)
NSMutableDictionary * propertiesReticleTargetSensitive
void drawLegend:(NSDictionary *info)
CGFloat OOStringWidthInEm(NSString *text)
BOOL reticleTargetSensitive
NSMutableArray * legendArray
static void hudDrawReticleOnTarget(Entity *target, PlayerEntity *player1, GLfloat z1, GLfloat alpha, BOOL reticleTargetSensitive, NSMutableDictionary *propertiesReticleTargetSensitive, BOOL colourFromScannerColour, BOOL showText, NSDictionary *info, NSMutableArray *reticleColors)
void drawSurroundInternal:color:(NSDictionary *info, [color] const GLfloat[4] color)
void OODrawString(NSString *text, GLfloat x, GLfloat y, GLfloat z, NSSize siz)
static void hudDrawWaypoint(OOWaypointEntity *waypoint, PlayerEntity *player1, GLfloat z1, GLfloat alpha, BOOL selected, GLfloat scale)
void OODrawPlanetInfo(int gov, int eco, int tec, GLfloat x, GLfloat y, GLfloat z, NSSize siz)
void drawDirectionCue:(NSDictionary *info)
float fov:(BOOL inFraction)
OOColor * cyanColor()
Definition OOColor.m:274
OOColor * colorWithRed:green:blue:alpha:(float red,[green] float green,[blue] float blue,[alpha] float alpha)
Definition OOColor.m:107
float alphaComponent()
Definition OOColor.m:442
OOColor * colorFromString:(NSString *colorFloatString)
Definition OOColor.m:211
float blueComponent()
Definition OOColor.m:339
OOColor * colorWithDescription:(id description)
Definition OOColor.m:135
OOColor * redColor()
Definition OOColor.m:259
OOColor * greenColor()
Definition OOColor.m:264
void getRed:green:blue:alpha:(float *red,[green] float *green,[blue] float *blue,[alpha] float *alpha)
Definition OOColor.m:344
OOColor * whiteColor()
Definition OOColor.m:249
float redComponent()
Definition OOColor.m:329
OOColor * yellowColor()
Definition OOColor.m:279
float greenComponent()
Definition OOColor.m:334
NSStringEncoding encoding()
NSData * convertString:(NSString *string)
void blitCentredToX:Y:Z:alpha:(float x,[Y] float y,[Z] float z,[alpha] float a)
void apply()
Definition OOTexture.m:258
NSSize dimensions()
Definition OOTexture.m:292
void applyNone()
Definition OOTexture.m:263
id textureWithName:inFolder:options:anisotropy:lodBias:(NSString *name,[inFolder] NSString *directory,[options] OOTextureFlags options,[anisotropy] GLfloat anisotropy,[lodBias] GLfloat lodBias)
Definition OOTexture.m:132
void drawTrumble:(double z)
Definition OOTrumble.m:362
GLfloat * scannerDisplayColorForShip:scannerDisplayColor1:scannerDisplayColor2:(BOOL flash,[scannerDisplayColor1] OOColor *scannerDisplayColor1,[scannerDisplayColor2] OOColor *scannerDisplayColor2)
GLfloat dialEnergy()
NSMutableArray * targetMemory()
GLfloat dialMaxEnergy()
Vector customViewUpVector
Vector customViewForwardVector
double clockTimeAdjusted()
NSDictionary * whitelistDictionary()
NSDictionary * dictionaryFromFilesNamed:inFolder:andMerge:(NSString *fileName,[inFolder] NSString *folderName,[andMerge] BOOL mergeFiles)
Vector v_forward
Definition ShipEntity.h:189
GLfloat * scannerDisplayColorForShip:isHostile:flash:scannerDisplayColor1:scannerDisplayColor2:scannerDisplayColorH1:scannerDisplayColorH2:(ShipEntity *otherShip,[isHostile] BOOL isHostile,[flash] BOOL flash,[scannerDisplayColor1] OOColor *scannerDisplayColor1,[scannerDisplayColor2] OOColor *scannerDisplayColor2,[scannerDisplayColorH1] OOColor *scannerDisplayColorH1,[scannerDisplayColorH2] OOColor *scannerDisplayColorH2)
OOColor * scannerDisplayColor2()
BoundingBox totalBoundingBox
Vector v_up
Definition ShipEntity.h:189
NSString * scanDescription()
OOColor * scannerDisplayColorHostile2()
OOColor * scannerDisplayColorHostile1()
BOOL hasHostileTarget()
double messageTime
void setMessageTime:(double value)
OOColor * scannerDisplayColor1()
Vector v_right
Definition ShipEntity.h:189
double estimatedArrivalTime()
voidpf void uLong size
Definition ioapi.h:126
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
GLfloat y
Definition OOOpenGL.h:199
GLfloat x
Definition OOOpenGL.h:198
GLfloat z
Definition OOOpenGL.h:200
OOScalar w
OOScalar x
Definition OOVector.h:32
OOScalar y
Definition OOVector.h:33
OOScalar z
Definition OOVector.h:34