Oolite
Loading...
Searching...
No Matches
WormholeEntity.m
Go to the documentation of this file.
1/*
2
3WormholeEntity.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 "WormholeEntity.h"
26
27#import "OOPlanetEntity.h"
28#import "OOSunEntity.h"
29#import "PlayerEntity.h"
30#import "ShipEntity.h"
32
33#import "AI.h"
35#import "OOLoggingExtended.h"
36#import "OORoleSet.h"
37#import "OOShipGroup.h"
38#import "OOShipRegistry.h"
39#import "OOStringParsing.h"
41#import "Universe.h"
42
43#define OO_WORMHOLE_COLOR_BOOST 25.0
44#define OO_WORMHOLE_COLOR_FVEC4 { 0.067, 0.067, 1.0, 0.25 }
45
46// Hidden interface
47@interface WormholeEntity (Private)
48
49- (id)init;
50
51@end
52
53// Static local functions
54static void DrawWormholeCorona(GLfloat inner_radius, GLfloat outer_radius, int step, GLfloat z_distance, GLfloat* col4v1);
55
56@implementation WormholeEntity (Private)
57
58- (id)init
59{
60 if ((self = [super init])) {
61 witch_mass = 0.0;
62 shipsInTransit = [[NSMutableArray arrayWithCapacity:4] retain];
63 collision_radius = 0.0;
64 [self setStatus:STATUS_EFFECT];
65 scanClass = CLASS_WORMHOLE;
66 isWormhole = YES;
67 scan_info = WH_SCANINFO_NONE;
68 scan_time = 0;
69 hasExitPosition = NO;
70 containsPlayer = NO;
71 exit_speed = 50.0;
72 }
73 return self;
74}
75
76@end // Private interface implementation
77
78//
79// Public Wormhole Implementation
80//
81
82@implementation WormholeEntity
83
84- (WormholeEntity*)initWithDict:(NSDictionary*)dict
85{
86 assert(dict != nil);
87
88 if ((self = [self init])) {
89 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
90
91 // wormholes from pre-1.80 savegames using "origin_seed" and "dest_seed"
92 // currently get defaults set; will probably disappear unnoticed
93 origin = [dict oo_intForKey:@"origin_id" defaultValue:0];
94 destination = [dict oo_intForKey:@"dest_id" defaultValue:255];
95
96 originCoords = [[UNIVERSE systemManager] getCoordinatesForSystem:origin inGalaxy:[PLAYER galaxyNumber]];
97 destinationCoords = [[UNIVERSE systemManager] getCoordinatesForSystem:destination inGalaxy:[PLAYER galaxyNumber]];
98
99 // We only ever init from dictionary if we're loaded by the player, so
100 // by definition we have been scanned
102
103 // Remember, times are stored as Ship Clock - but anything
104 // saving/restoring wormholes from dictionaries should know this!
105 expiry_time = [dict oo_doubleForKey:@"expiry_time"];
106 arrival_time = [dict oo_doubleForKey:@"arrival_time"];
107 // just in case an old save game has one with crossed times
110 }
111
112 // Since this is new for 1.75.1, we must give it a default values as we could be loading an old savegame
113 estimated_arrival_time = [dict oo_doubleForKey:@"estimated_arrival_time" defaultValue:arrival_time];
114 position = [dict oo_hpvectorForKey:@"position"];
115 _misjump = [dict oo_boolForKey:@"misjump" defaultValue:NO];
116
117 // Setup shipsInTransit
118 NSArray* shipDictsArray = [dict oo_arrayForKey:@"ships"];
119 NSDictionary* currShipDict = nil;
120 [shipsInTransit removeAllObjects];
121 NSMutableDictionary* restoreContext = [NSMutableDictionary dictionary];
122
123 foreach (currShipDict, shipDictsArray) {
124 NSDictionary* shipInfo = [currShipDict oo_dictionaryForKey:@"ship_info"];
125 if (shipInfo != nil) {
127 useFallback:YES
128 context:restoreContext];
129 if (ship != nil) {
130 [shipsInTransit addObject:[NSDictionary dictionaryWithObjectsAndKeys:
131 ship, @"ship",
132 [currShipDict objectForKey:@"time_delta"], @"time",
133 nil]];
134 } else {
135 OOLog(@"wormhole.load.warning", @"Wormhole ship \"%@\" failed to initialize - missing OXP or old-style saved wormhole data.", [shipInfo oo_stringForKey:@"ship_key"]);
136 }
137 }
138 }
139 [pool release];
140 }
141 return self;
142}
143
144- (WormholeEntity*)initWormholeTo:(OOSystemID)s fromShip:(ShipEntity*)ship
145{
146 assert(ship != nil);
147
148 if ((self = [self init])) {
149 double now = [PLAYER clockTimeAdjusted];
150 double distance;
151 OOSunEntity* sun = [UNIVERSE sun];
152
153 _misjump = NO;
154 origin = [UNIVERSE currentSystemID];
155 destination = s;
156 originCoords = [PLAYER galaxy_coordinates];
157 destinationCoords = [[UNIVERSE systemManager] getCoordinatesForSystem:destination inGalaxy:[PLAYER galaxyNumber]];
159 distance = fmax(distance, 0.1);
160 witch_mass = 200000.0; // MKW 2010.11.21 - originally the ship's mass was added twice - once here and once in suckInShip. Instead, we give each wormhole a minimum mass.
161 if ([ship isPlayer])
162 witch_mass += [ship mass]; // The player ship never gets sucked in, so add its mass here.
163
164 if (sun && ([sun willGoNova] || [sun goneNova]) && [ship mass] > 240000)
165 shrink_factor = [ship mass] / 240000; // don't allow longstanding wormholes in nova systems. (60 sec * WORMHOLE_SHRINK_RATE = 240 000)
166 else
167 shrink_factor = 1;
168
169 collision_radius = 0.5 * M_PI * pow(witch_mass, 1.0 / 3.0);
171 travel_time = (distance * distance * 3600); // Taken from PlayerEntity.h
174
175 /* There are a number of bugs where the arrival time is < than the
176 * expiry time (i.e. both ends open at once).
177 * Rather than try to flatten all of them, having been unsuccessful twice
178 * it seems easier to declare as a matter of wormhole physics that it
179 * _can't_ be open at both ends at once. - CIM: 13/12/12 */
182 }
185 }
186 return self;
187}
188
190{
191 // Test for misjump first - it's entirely possibly that the wormhole
192 // has already been marked for misjumping when another ship enters it.
193 if (!_misjump) {
195 double time_adjust = distance * distance * (3600 - 2700); // NB: Time adjustment is calculated using original distance. Formula matches the one in [PlayerEntity witchJumpTo]
196 arrival_time -= time_adjust;
197 travel_time -= time_adjust;
200 _misjump = YES;
201 }
202}
203
204- (void)setMisjumpWithRange:(GLfloat)range
205{
206 if (range <= 0.0 || range >= 1.0) {
207 range = 0.5; // for safety, though nothing should be setting this
208 }
209 _misjumpRange = range;
210 // Test for misjump first - it's entirely possibly that the wormhole
211 // has already been marked for misjumping when another ship enters it.
212 if (!_misjump) {
214 double time_adjust = (distance * (1 - _misjumpRange)) * (distance * (1 - _misjumpRange)) * 3600.0;
215 // time adjustment ensures that misjumps not faster than normal jumps
216 // formulae for time and distance by mwerle at http://developer.berlios.de/pm/task.php?func=detailtask&project_task_id=4703&group_id=3577&group_project_id=1753
217 arrival_time -= time_adjust;
218 travel_time -= time_adjust;
219
222 _misjump = YES;
223 }
224}
225
227{
228 return _misjump;
229}
230
231- (GLfloat)misjumpRange
232{
233 return _misjumpRange;
234}
235
236- (BOOL)suckInShip:(ShipEntity*)ship
237{
238 if (!ship || [ship status] == STATUS_ENTERING_WITCHSPACE) {
239 return NO;
240 }
241 if (origin != [UNIVERSE currentSystemID]) {
242 // if we're no longer in the origin system, can't suck in
243 return NO;
244 }
245 if ([PLAYER galaxy_coordinates].x != originCoords.x || [PLAYER galaxy_coordinates].y != originCoords.y) {
246 // if we're no longer at the origin coordinates, can't suck in (handles interstellar space case)
247 return NO;
248 }
249 double now = [PLAYER clockTimeAdjusted];
250
251 /* CIM: removed test. Not valid for wormholes which last longer than their travel time. Most likely for short distances e.g. zero-distance doubles. equal_seeds test above should cover it, with expiry_time test for safety. */
252 /* if (now > arrival_time)
253 return NO; // far end of the wormhole! */
254 if (now > expiry_time)
255 return NO;
256 // MKW 2010.11.18 - calculate time it takes for ship to reach wormhole
257 // This is for AI ships which get told to enter the wormhole even though they
258 // may still be some distance from it when the player exits the system
259 float d = HPdistance(position, [ship position]);
260 d -= [ship collisionRadius] + [self collisionRadius];
261 if (d > 0.0f) {
262 float afterburnerFactor = [ship hasFuelInjection] && [ship fuel] > MIN_FUEL ? [ship afterburnerFactor] : 1.0;
263 float shipSpeed = [ship maxFlightSpeed] * afterburnerFactor;
264 // MKW 2011.02.27 - calculate speed based on group leader, if any, to
265 // try and prevent escorts from entering the wormhole before their mother.
266 ShipEntity* leader = [[ship group] leader];
267 if (leader && (leader != ship)) {
268 afterburnerFactor = [leader hasFuelInjection] && [leader fuel] > MIN_FUEL ? [leader afterburnerFactor] : 1.0;
269 float leaderShipSpeed = [leader maxFlightSpeed] * afterburnerFactor;
270 if (leaderShipSpeed < shipSpeed)
271 shipSpeed = leaderShipSpeed;
272 }
273 if (shipSpeed <= 0.0f)
274 shipSpeed = 0.1f;
275 now += d / shipSpeed;
276 if (now > expiry_time) {
277 return NO;
278 }
279 }
280
281 [shipsInTransit addObject:[NSDictionary dictionaryWithObjectsAndKeys:
282 ship, @"ship",
283 [NSNumber numberWithDouble:now + travel_time - arrival_time], @"time",
284 [ship beaconCode], @"shipBeacon", // in case a beacon code has been set, nil otherwise
285 nil]];
286 witch_mass += [ship mass];
288 // and, again, cap to be earlier than arrival time
291 }
292
293 collision_radius = 0.5 * M_PI * pow(witch_mass, 1.0 / 3.0);
294
295 [UNIVERSE addWitchspaceJumpEffectForShip:ship];
296
297 // Should probably pass the wormhole, but they have no JS representation
298 [ship setStatus:STATUS_ENTERING_WITCHSPACE];
299 [ship doScriptEvent:OOJSID("shipWillEnterWormhole")];
300 [[ship getAI] message:@"ENTERED_WITCHSPACE"];
301
302 [UNIVERSE removeEntity:ship];
303 [[ship getAI] clearStack]; // get rid of any preserved states
304
305 if ([ship isStation]) {
306 if ([PLAYER dockedStation] == (StationEntity*)ship) {
307 // the carrier has jumped while the player is docked
308 [ship retain];
309 [UNIVERSE carryPlayerOn:(StationEntity*)ship inWormhole:self];
310 [ship release];
311 }
312 }
313
314 return YES;
315}
316
318{
319 double now = [PLAYER clockTimeAdjusted];
320 NSMutableArray* shipsStillInTransit = [[NSMutableArray alloc] initWithCapacity:[shipsInTransit count]];
321 BOOL hasShiftedExitPosition = NO;
322 BOOL useExitXYScatter = NO;
323
324 NSDictionary* shipInfo = nil;
325 foreach (shipInfo, shipsInTransit) {
326 ShipEntity* ship = [shipInfo objectForKey:@"ship"];
327 NSString* shipBeacon = [shipInfo objectForKey:@"shipBeacon"];
328 double ship_arrival_time = arrival_time + [shipInfo oo_doubleForKey:@"time"];
329 double time_passed = now - ship_arrival_time;
330
331 if ([ship status] == STATUS_DEAD)
332 continue; // skip dead ships.
333
334 if (ship_arrival_time > now) {
335 [shipsStillInTransit addObject:shipInfo];
336 } else {
337 // Only calculate exit position once so that all ships arrive from the same point
338 if (!hasExitPosition) {
339 position = [UNIVERSE getWitchspaceExitPosition]; // no need to reset PRNG.
340 GLfloat min_d1 = [UNIVERSE safeWitchspaceExitDistance];
341 Quaternion q1;
343 double d1 = SCANNER_MAX_RANGE * ((ranrot_rand() % 256) / 256.0 - 0.5);
345 if (dot_product(v1, kBasisZVector) < -0.99) {
346 // a bit more safe distance if right behind the buoy
347 min_d1 *= 3.0;
348 }
349
350 if (fabs(d1) < min_d1) // no closer than 750m to edge of buoy
351 {
352 d1 += ((d1 > 0.0) ? min_d1 : -min_d1);
353 }
354 position.x += v1.x * d1; // randomise exit position
355 position.y += v1.y * d1;
356 position.z += v1.z * d1;
357 }
358
359 if (hasExitPosition && (!containsPlayer || useExitXYScatter)) {
360 HPVector shippos;
361 Vector exit_vector_x = vector_right_from_quaternion([UNIVERSE getWitchspaceExitRotation]);
362 Vector exit_vector_y = vector_up_from_quaternion([UNIVERSE getWitchspaceExitRotation]);
363 // entry wormhole has a radius of around 100m (or perhaps more)
364 // so randomise exit positions slightly too for second and subsequent ships
365 // helps avoid collisions when two ships enter wormhole at same time
366 double offset_x = randf() * 150.0 - 75.0;
367 double offset_y = randf() * 150.0 - 75.0;
368 shippos.x = position.x + (offset_x * exit_vector_x.x) + (offset_y * exit_vector_y.x);
369 shippos.y = position.y + (offset_x * exit_vector_x.y) + (offset_y * exit_vector_y.y);
370 shippos.z = position.z + (offset_x * exit_vector_x.z) + (offset_y * exit_vector_y.z);
371 [ship setPosition:shippos];
372 } else {
373 // this is the first ship out of the wormhole
374 [self setExitSpeed:[ship maxFlightSpeed] * WORMHOLE_LEADER_SPEED_FACTOR];
375 if (containsPlayer) { // reset the player's speed to the new speed
376 [PLAYER setSpeed:exit_speed];
377 }
378 useExitXYScatter = YES;
379 [ship setPosition:position];
380 }
381
382 if (shipBeacon != nil) {
383 [ship setBeaconCode:shipBeacon];
384 }
385
386 // Don't reduce bounty on misjump. Fixes #17992
387 // - MKW 2011.03.10
388 if (!_misjump)
389 [ship setBounty:[ship bounty] / 2 withReason:kOOLegalStatusReasonNewSystem]; // adjust legal status for new system
390
391 // now the cargo is defined in advance, this is unnecessary
392 /* if ([ship cargoFlag] == CARGO_FLAG_FULL_PLENTIFUL)
393 {
394 [ship setCargoFlag: CARGO_FLAG_FULL_SCARCE];
395 }*/
396
397 if (time_passed < 2.0) {
398 [ship witchspaceLeavingEffects]; // adds the ship to the universe with effects.
399 } else {
400 // arrived 2 seconds or more before the player. Rings have faded out.
401 [ship setOrientation:[UNIVERSE getWitchspaceExitRotation]];
402 [ship setPitch:0.0];
403 [ship setRoll:0.0];
404 [ship setVelocity:kZeroVector];
405 [UNIVERSE addEntity:ship]; // AI and status get initialised here
406 }
407 [ship setSpeed:[self exitSpeed]]; // all ships from this wormhole have same velocity
408
409 // awaken JS-based AIs
410 [ship doScriptEvent:OOJSID("aiStarted")];
411
412 // Wormholes now have a JS representation, so we could provide it
413 // but is it worth it for the exit wormhole?
414 [ship doScriptEvent:OOJSID("shipExitedWormhole") andReactToAIMessage:@"EXITED WITCHSPACE"];
415
416 // update the ships's position
417 if (!hasExitPosition) {
418 hasExitPosition = YES;
419 hasShiftedExitPosition = YES; // exitPosition is shifted towards the lead ship update position.
420 [ship update:time_passed]; // do this only for one ship or the next ships might appear at very different locations.
421 position = [ship position]; // e.g. when the player docks first before following, time_passed is already > 10 minutes.
422 } else if (time_passed > 1) // Only update the ship position if it was some time ago, otherwise we're in 'real time'.
423 {
424 if (hasShiftedExitPosition) {
425 // only update the time delay to the lead ship. Sign is not correct but updating gives a small spacial distribution.
426 [ship update:(ship_arrival_time - arrival_time)];
427 } else {
428 // Exit position was externally set, e.g. by player ship following through this wormhole.
429 // Use the real time difference.
430 [ship update:time_passed];
431 }
432 }
433 }
434 }
435 [shipsInTransit release];
436 shipsInTransit = shipsStillInTransit;
437
438 if (containsPlayer) {
439 // ships exiting the wormhole after now are following the player
440 // so appear behind them
442 containsPlayer = NO;
443 }
444 // else, the wormhole doesn't now (or never) contained the player, so
445 // no need to move it
446}
447
448- (void)setContainsPlayer:(BOOL)val
449{
450 containsPlayer = val;
451}
452
453- (void)setExitPosition:(HPVector)pos
454{
455 [self setPosition:pos];
456 hasExitPosition = YES;
457}
458
460{
461 return origin;
462}
463
465{
466 return destination;
467}
468
470{
471 return originCoords;
472}
473
475{
476 return destinationCoords;
477}
478
479- (double)exitSpeed
480{
481 return exit_speed;
482}
483
484- (void)setExitSpeed:(double)speed
485{
487}
488
489- (double)expiryTime
490{
491 return expiry_time;
492}
493
494- (double)arrivalTime
495{
496 return arrival_time;
497}
498
500{
502}
503
504- (double)travelTime
505{
506 return travel_time;
507}
508
509- (double)scanTime
510{
511 return scan_time;
512}
513
515{
517}
518
519- (void)setScannedAt:(double)p_scanTime
520{
522 scan_time = p_scanTime;
524 }
525 // else we previously scanned this wormhole
526}
527
529{
530 return scan_info;
531}
532
533- (void)setScanInfo:(WORMHOLE_SCANINFO)p_scanInfo
534{
535 scan_info = p_scanInfo;
536}
537
538- (NSArray*)shipsInTransit
539{
540 return shipsInTransit;
541}
542
543- (void)dealloc
544{
545 [shipsInTransit release];
546
547 [super dealloc];
548}
549
551{
552 double now = [PLAYER clockTime];
553 return [NSString stringWithFormat:@"destination: %@ ttl: %.2fs arrival: %@",
554 _misjump ? (NSString*)@"Interstellar Space" : [UNIVERSE getSystemName:destination],
555 expiry_time - now,
556 ClockToString(arrival_time, false)];
557}
558
559- (NSString*)identFromShip:(ShipEntity*)ship
560{
561 if ([ship hasEquipmentItem:@"EQ_WORMHOLE_SCANNER"]) {
562 if ([self scanInfo] >= WH_SCANINFO_DESTINATION) {
563 return [NSString stringWithFormat:DESC(@"wormhole-to-@"), [UNIVERSE getSystemName:destination]];
564 } else {
565 return DESC(@"wormhole-desc");
566 }
567 } else {
568 OOLogERR(kOOLogInconsistentState, @"%@", @"Wormhole identified when ship has no EQ_WORMHOLE_SCANNER.");
569 /*
570 This was previously an assertion, but a player reported hitting it.
571 http://aegidian.org/bb/viewtopic.php?p=128110#p128110
572 -- Ahruman 2011-01-27
573 */
574 return nil;
575 }
576}
577
579{
580 /* Correct test for far end of wormhole */
581 if (origin != [UNIVERSE currentSystemID]) {
582 // if we're no longer in the origin system, can't suck in
583 return NO;
584 }
585 if ([PLAYER galaxy_coordinates].x != originCoords.x || [PLAYER galaxy_coordinates].y != originCoords.y) {
586 // if we're no longer at the origin coordinates, can't suck in (handles interstellar space case)
587 return NO;
588 }
589
590 return (witch_mass > 0.0);
591}
592
593- (BOOL)checkCloseCollisionWith:(Entity*)other
594{
595 return ![other isEffect];
596}
597
598- (void)update:(OOTimeDelta)delta_t
599{
600 [super update:delta_t];
601
602 PlayerEntity* player = PLAYER;
603 assert(player != nil);
604 rotMatrix = OOMatrixForBillboard(position, [player viewpointPosition]);
605 double now = [player clockTimeAdjusted];
606
607 if (witch_mass > 0.0) {
608
610 witch_mass = fmax(witch_mass, 0.0);
611 collision_radius = 0.5 * M_PI * pow(witch_mass, 1.0 / 3.0);
613 }
614
615 scanClass = (witch_mass > 0.0) ? CLASS_WORMHOLE : CLASS_NO_DRAW;
616
617 if (now > expiry_time) {
618 scanClass = CLASS_NO_DRAW; // witch_mass not certain to be limiting factor on extremely short jumps, so make sure now
619
620 // If we're a saved wormhole waiting to disgorge more ships, it's safe
621 // to remove self from UNIVERSE, but we need the current position!
622 [UNIVERSE removeEntity:self];
623 }
624}
625
626- (void)drawImmediate:(bool)immediate translucent:(bool)translucent
627{
628 if ([UNIVERSE breakPatternHide])
629 return; // DON'T DRAW DURING BREAK PATTERN
630
632 return; // TOO FAR AWAY TO SEE
633
634 if (witch_mass <= 0.0)
635 return;
636
637 if (collision_radius <= 0.0)
638 return;
639
640 if ([self scanClass] == CLASS_NO_DRAW)
641 return;
642
643 if (translucent) {
644 // for now, a simple copy of the energy bomb draw routine
645 float srzd = sqrt(cam_zero_distance);
646
647 GLfloat color_fv[4] = OO_WORMHOLE_COLOR_FVEC4;
648
650 OOGL(glDisable(GL_CULL_FACE));
651 OOGL(glEnable(GL_BLEND));
652
653 OOGL(glColor4fv(color_fv));
654 OOGLBEGIN(GL_TRIANGLE_FAN);
655 GLDrawBallBillboard(0.45 * collision_radius, 4, srzd);
656 OOGLEND();
657
658 color_fv[3] = fmin(color_fv[3] * 2.0, 1.0);
659 DrawWormholeCorona(0.45 * collision_radius, collision_radius, 4, srzd, color_fv);
660
661 OOGL(glEnable(GL_CULL_FACE));
662 OOGL(glDisable(GL_BLEND));
663 }
664
666 OOCheckOpenGLErrors(@"WormholeEntity after drawing %@", self);
667}
668
669static void DrawWormholeCorona(GLfloat inner_radius, GLfloat outer_radius, int step, GLfloat z_distance, GLfloat* col4v1)
670{
671 if (outer_radius >= z_distance) // inside the sphere
672 return;
673 int i;
674
675 const GLfloat activityMin = 0.34f;
676 const GLfloat activityLength = 1.0f;
677
678 GLfloat s0, c0, s1, c1;
679
680 GLfloat r0, r1;
681 GLfloat rv0, rv1, q;
682
683 GLfloat theta, delta, halfStep;
684
685 r0 = outer_radius * z_distance / sqrt(z_distance * z_distance - outer_radius * outer_radius);
686 r1 = inner_radius * z_distance / sqrt(z_distance * z_distance - inner_radius * inner_radius);
687
688 delta = step * M_PI / 180.0f;
689 halfStep = 0.5f * delta;
690 theta = 0.0f;
691
692 OOGLBEGIN(GL_TRIANGLE_STRIP);
693 for (i = 0; i < 360; i += step) {
694 rv0 = randf();
695 rv1 = randf();
696
697 q = activityMin + rv0 * activityLength;
698
699 s0 = r0 * sin(theta);
700 c0 = r0 * cos(theta);
701 glColor4f(col4v1[0] * q, col4v1[1] * q, col4v1[2] * q, col4v1[3] * rv0);
702 glVertex3f(s0, c0, 0.0);
703
704 s1 = r1 * sin(theta - halfStep) * 0.5 * (1.0 + rv1);
705 c1 = r1 * cos(theta - halfStep) * 0.5 * (1.0 + rv1);
706 glColor4f(col4v1[0] * OO_WORMHOLE_COLOR_BOOST, col4v1[1] * OO_WORMHOLE_COLOR_BOOST, col4v1[2] * OO_WORMHOLE_COLOR_BOOST, col4v1[3] * rv0);
707 glVertex3f(s1, c1, 0.0);
708
709 theta += delta;
710 }
711 // repeat last values to close
712 rv0 = randf();
713 rv1 = randf();
714
715 q = activityMin + rv0 * activityLength;
716
717 s0 = 0.0f; // r0 * sin(0);
718 c0 = r0; // r0 * cos(0);
719 glColor4f(col4v1[0] * q, col4v1[1] * q, col4v1[2] * q, col4v1[3] * rv0);
720 glVertex3f(s0, c0, 0.0);
721
722 s1 = r1 * sin(halfStep) * 0.5 * (1.0 + rv1);
723 c1 = r1 * cos(halfStep) * 0.5 * (1.0 + rv1);
724 glColor4f(col4v1[0] * OO_WORMHOLE_COLOR_BOOST, col4v1[1] * OO_WORMHOLE_COLOR_BOOST, col4v1[2] * OO_WORMHOLE_COLOR_BOOST, col4v1[3] * rv0);
725 glVertex3f(s1, c1, 0.0);
726 OOGLEND();
727}
728
729- (NSDictionary*)getDict
730{
731 NSMutableDictionary* myDict = [NSMutableDictionary dictionary];
732
733 [myDict oo_setInteger:origin forKey:@"origin_id"];
734 [myDict oo_setInteger:destination forKey:@"dest_id"];
735 [myDict setObject:StringFromPoint(originCoords) forKey:@"origin_coords"];
736 [myDict setObject:StringFromPoint(destinationCoords) forKey:@"dest_coords"];
737 // Anything converting a wormhole to a dictionary should already have
738 // modified its time to shipClock time
739 [myDict oo_setFloat:(expiry_time) forKey:@"expiry_time"];
740 [myDict oo_setFloat:(arrival_time) forKey:@"arrival_time"];
741 [myDict oo_setFloat:(estimated_arrival_time) forKey:@"estimated_arrival_time"];
742 [myDict oo_setHPVector:position forKey:@"position"];
743 [myDict oo_setBool:_misjump forKey:@"misjump"];
744
745 NSMutableArray* shipArray = [NSMutableArray arrayWithCapacity:[shipsInTransit count]];
746 NSEnumerator* ships = [shipsInTransit objectEnumerator];
747 NSDictionary* currShipDict = nil;
748 NSMutableDictionary* context = [NSMutableDictionary dictionary];
749 while ((currShipDict = [ships nextObject]) != nil) {
750 id ship = [currShipDict objectForKey:@"ship"];
751 [shipArray addObject:[NSDictionary dictionaryWithObjectsAndKeys:
752 [NSNumber numberWithDouble:[currShipDict oo_doubleForKey:@"time"]], @"time_delta",
753 [ship savedShipDictionaryWithContext:context], @"ship_info",
754 nil]];
755 }
756 [myDict setObject:shipArray forKey:@"ships"];
757
758 return myDict;
759}
760
761- (NSString*)scanInfoString
762{
763 switch (scan_info) {
764 case WH_SCANINFO_NONE:
765 return @"WH_SCANINFO_NONE";
767 return @"WH_SCANINFO_SCANNED";
769 return @"WH_SCANINFO_COLLAPSE_TIME";
771 return @"WH_SCANINFO_ARRIVAL_TIME";
773 return @"WH_SCANINFO_DESTINATION";
774 case WH_SCANINFO_SHIP:
775 return @"WH_SCANINFO_SHIP";
776 }
777 return @"WH_SCANINFO_UNDEFINED"; // should never get here
778}
779
781{
782 [super dumpSelfState];
783 OOLog(@"dumpState.wormholeEntity", @"Origin : %@", [UNIVERSE getSystemName:origin]);
784 OOLog(@"dumpState.wormholeEntity", @"Destination : %@", [UNIVERSE getSystemName:destination]);
785 OOLog(@"dumpState.wormholeEntity", @"Expiry Time : %@", ClockToString(expiry_time, false));
786 OOLog(@"dumpState.wormholeEntity", @"Arrival Time : %@", ClockToString(arrival_time, false));
787 OOLog(@"dumpState.wormholeEntity", @"Projected Arrival Time : %@", ClockToString(estimated_arrival_time, false));
788 OOLog(@"dumpState.wormholeEntity", @"Scanned Time : %@", ClockToString(scan_time, false));
789 OOLog(@"dumpState.wormholeEntity", @"Scanned State : %@", [self scanInfoString]);
790
791 OOLog(@"dumpState.wormholeEntity", @"Mass : %.2lf", witch_mass);
792 OOLog(@"dumpState.wormholeEntity", @"Ships : %zu", [shipsInTransit count]);
793 unsigned i;
794 for (i = 0; i < [shipsInTransit count]; ++i) {
795 NSDictionary* shipDict = [shipsInTransit oo_dictionaryAtIndex:i];
796 ShipEntity* ship = (ShipEntity*)[shipDict objectForKey:@"ship"];
797 double ship_arrival_time = arrival_time + [shipDict oo_doubleForKey:@"time"];
798 OOLog(@"dumpState.wormholeEntity.ships", @"Ship %d: %@ mass %.2f arrival time %@", i + 1, ship, [ship mass], ClockToString(ship_arrival_time, false));
799 }
800}
801
802@end
#define NO_DRAW_DISTANCE_FACTOR
Definition Entity.h:49
#define SCANNER_MAX_RANGE
Definition Entity.h:53
OOINLINE HPVector vectorToHPVector(Vector v) INLINE_CONST_FUNC
Definition OOHPVector.h:166
OOINLINE OOHPScalar HPdistance2(HPVector v1, HPVector v2) INLINE_CONST_FUNC
Definition OOHPVector.h:293
OOINLINE HPVector HPvector_add(HPVector a, HPVector b) INLINE_CONST_FUNC
Definition OOHPVector.h:213
OOINLINE OOHPScalar HPdistance(HPVector v1, HPVector v2) INLINE_CONST_FUNC
Definition OOHPVector.h:298
#define OOLogERR(class, format,...)
Definition OOLogging.h:125
NSString *const kOOLogInconsistentState
Definition OOLogging.m:599
#define OOLog(class, format,...)
Definition OOLogging.h:84
#define M_PI
Definition OOMaths.h:54
OOMatrix OOMatrixForBillboard(HPVector bbPos, HPVector eyePos) CONST_FUNC
Definition OOMatrix.m:186
#define OOGLBEGIN
Definition OOOpenGL.h:269
@ OPENGL_STATE_TRANSLUCENT_PASS
Definition OOOpenGL.h:122
#define OOVerifyOpenGLState()
Definition OOOpenGL.h:133
BOOL OOCheckOpenGLErrors(NSString *format,...)
Definition OOOpenGL.m:38
void GLDrawBallBillboard(GLfloat radius, GLfloat step, GLfloat z_distance)
Definition OOOpenGL.m:107
#define OOSetOpenGLState(STATE)
Definition OOOpenGL.h:132
#define OOGL(statement)
Definition OOOpenGL.h:262
#define OOGLEND
Definition OOOpenGL.h:270
unsigned count
return nil
Vector vector_forward_from_quaternion(Quaternion quat) CONST_FUNC
Vector vector_up_from_quaternion(Quaternion quat) CONST_FUNC
void quaternion_set_random(Quaternion *quat) NONNULL_FUNC
Vector vector_right_from_quaternion(Quaternion quat) CONST_FUNC
float x
NSString * ClockToString(double clock, BOOL adjusting)
int16_t OOSystemID
Definition OOTypes.h:183
double OOTimeDelta
Definition OOTypes.h:193
OOINLINE OOScalar dot_product(Vector first, Vector second) INLINE_CONST_FUNC
Definition OOVector.h:299
const Vector kBasisZVector
Definition OOVector.h:47
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
#define PLAYER
#define MIN_FUEL
Definition ShipEntity.h:104
#define UNIVERSE
Definition Universe.h:827
#define DESC(key)
Definition Universe.h:832
#define WORMHOLE_SHRINK_RATE
WORMHOLE_SCANINFO
@ WH_SCANINFO_NONE
@ WH_SCANINFO_SCANNED
@ WH_SCANINFO_SHIP
@ WH_SCANINFO_ARRIVAL_TIME
@ WH_SCANINFO_DESTINATION
@ WH_SCANINFO_COLLAPSE_TIME
#define OO_WORMHOLE_COLOR_FVEC4
#define OO_WORMHOLE_COLOR_BOOST
static void DrawWormholeCorona(GLfloat inner_radius, GLfloat outer_radius, int step, GLfloat z_distance, GLfloat *col4v1)
void clearStack()
Definition AI.m:604
void message:(NSString *ms)
Definition AI.m:536
GLfloat collision_radius
Definition Entity.h:107
void setVelocity:(Vector vel)
Definition Entity.m:703
void setOrientation:(Quaternion quat)
Definition Entity.m:676
void update:(OOTimeDelta delta_t)
Definition Entity.m:850
GLfloat zero_distance
Definition Entity.h:104
GLfloat collisionRadius()
Definition Entity.m:830
OOScanClass scanClass
Definition Entity.m:743
OOEntityStatus status()
Definition Entity.m:733
GLfloat cam_zero_distance
Definition Entity.h:105
BOOL isEffect()
Definition Entity.m:180
unsigned isStation
Definition Entity.m:135
unsigned isPlayer
Definition Entity.m:145
void dumpSelfState()
Definition Entity.m:918
HPVector position
Definition Entity.m:576
GLfloat no_draw_distance
Definition Entity.h:106
double speed()
Definition Entity.m:713
OOMatrix rotMatrix
Definition Entity.h:134
void setStatus:(OOEntityStatus stat)
Definition Entity.m:728
void dealloc()
Definition Entity.m:98
GLfloat mass
Definition Entity.m:671
void setPosition:(HPVector posn)
Definition Entity.m:608
ShipEntity * leader()
double clockTimeAdjusted()
void doScriptEvent:(OOJSPropID message)
void setBounty:withReason:(OOCreditsQuantity amount,[withReason] OOLegalStatusReason reason)
void setStatus:(OOEntityStatus stat)
BOOL witchspaceLeavingEffects()
void setRoll:(double amount)
BOOL hasFuelInjection()
void setSpeed:(double amount)
NSString * beaconCode()
OOShipGroup * group()
OOFuelQuantity fuel
OOCreditsQuantity bounty
void setPitch:(double amount)
void setBeaconCode:(NSString *bcode)
void doScriptEvent:andReactToAIMessage:(OOJSPropID scriptEvent,[andReactToAIMessage] NSString *aiMessage)
void update:(OOTimeDelta delta_t)
float afterburnerFactor()
id shipRestoredFromDictionary:useFallback:context:(NSDictionary *dictionary,[useFallback] BOOL fallback,[context] NSMutableDictionary *context)
GLfloat maxFlightSpeed
WORMHOLE_SCANINFO scanInfo()
double estimatedArrivalTime()
NSPoint originCoordinates()
OOSystemID destination
NSPoint destinationCoords
WORMHOLE_SCANINFO scan_info
double estimated_arrival_time
NSMutableArray * shipsInTransit
NSPoint destinationCoordinates()
NSDictionary * getDict()
NSString * scanInfoString()
GLfloat _misjumpRange
NSString * descriptionComponents()
void setExitSpeed:(double speed)
OOSystemID origin
static void DrawWormholeCorona(GLfloat inner_radius, GLfloat outer_radius, int step, GLfloat z_distance, GLfloat *col4v1)
float randf(void)
#define ranrot_rand()
OOINLINE double distanceBetweenPlanetPositions(int x1, int y1, int x2, int y2) INLINE_CONST_FUNC
OOHPScalar x
Definition OOHPVector.h:36
OOHPScalar y
Definition OOHPVector.h:37
OOHPScalar z
Definition OOHPVector.h:38
OOScalar x
Definition OOVector.h:32
OOScalar y
Definition OOVector.h:33
OOScalar z
Definition OOVector.h:34