Oolite
Loading...
Searching...
No Matches
WormholeEntity Class Reference

#include <WormholeEntity.h>

Inheritance diagram for WormholeEntity:
Collaboration diagram for WormholeEntity:

Instance Methods

(WormholeEntity *) - initWithDict:
(WormholeEntity *) - initWormholeTo:fromShip:
(BOOL) - suckInShip:
(void) - disgorgeShips
(void) - setExitPosition:
(OOSystemID) - origin
(OOSystemID) - destination
(NSPoint) - originCoordinates
(NSPoint) - destinationCoordinates
(void) - setMisjump
(void) - setMisjumpWithRange:
(BOOL) - withMisjump
(GLfloat) - misjumpRange
(double) - exitSpeed
(void) - setExitSpeed:
(double) - expiryTime
(double) - arrivalTime
(double) - estimatedArrivalTime
(double) - travelTime
(double) - scanTime
(void) - setScannedAt:
(void) - setContainsPlayer:
(BOOL) - isScanned
(WORMHOLE_SCANINFO) - scanInfo
(void) - setScanInfo:
(NSArray *) - shipsInTransit
(NSString *) - identFromShip:
(NSDictionary *) - getDict
(void) - dealloc [implementation]
(NSString *) - descriptionComponents [implementation]
(BOOL) - canCollide [implementation]
(BOOL) - checkCloseCollisionWith: [implementation]
(void) - update: [implementation]
(void) - drawImmediate:translucent: [implementation]
(NSString *) - scanInfoString [implementation]
(void) - dumpSelfState [implementation]
(void) - getJSClass:andPrototype:
(NSString *) - oo_jsClassName
(NSString *) - oo_jsClassName
(BOOL) - isVisibleToScripts
(BOOL) - isVisibleToScripts
(JSClassID) - oo_jsClassID
(id) - init [implementation]
Instance Methods inherited from Entity
(NSUInteger) - sessionID
(BOOL) - isShip
(BOOL) - isDock
(BOOL) - isStation
(BOOL) - isSubEntity
(BOOL) - isPlayer
(BOOL) - isPlanet
(BOOL) - isSun
(BOOL) - isSunlit
(BOOL) - isStellarObject
(BOOL) - isSky
(BOOL) - isWormhole
(BOOL) - isEffect
(BOOL) - isVisualEffect
(BOOL) - isWaypoint
(BOOL) - validForAddToUniverse
(void) - addToLinkedLists
(void) - removeFromLinkedLists
(void) - updateLinkedLists
(void) - wasAddedToUniverse
(void) - wasRemovedFromUniverse
(void) - warnAboutHostiles
(CollisionRegion *) - collisionRegion
(void) - setCollisionRegion:
(void) - setUniversalID:
(OOUniversalID) - universalID
(BOOL) - throwingSparks
(void) - setThrowSparks:
(void) - throwSparks
(void) - setOwner:
(id) - owner
(ShipEntity *) - parentEntity
(ShipEntity *) - rootShipEntity
(void) - setPosition:
(void) - setPositionX:y:z:
(HPVector) - position
(Vector) - cameraRelativePosition
(GLfloat) - cameraRangeFront
(GLfloat) - cameraRangeBack
(void) - updateCameraRelativePosition
(Vector) - vectorTo:
(HPVector) - absolutePositionForSubentity
(HPVector) - absolutePositionForSubentityOffset:
(double) - zeroDistance
(double) - camZeroDistance
(NSComparisonResult) - compareZeroDistance:
(BoundingBox) - boundingBox
(GLfloat) - mass
(Quaternion) - orientation
(void) - setOrientation:
(Quaternion) - normalOrientation
(void) - setNormalOrientation:
(void) - orientationChanged
(void) - setVelocity:
(Vector) - velocity
(double) - speed
(GLfloat) - distanceTravelled
(void) - setDistanceTravelled:
(void) - setStatus:
(OOEntityStatus) - status
(void) - setScanClass:
(OOScanClass) - scanClass
(void) - setEnergy:
(GLfloat) - energy
(void) - setMaxEnergy:
(GLfloat) - maxEnergy
(void) - applyRoll:andClimb:
(void) - applyRoll:climb:andYaw:
(void) - moveForward:
(OOMatrix) - rotationMatrix
(OOMatrix) - drawRotationMatrix
(OOMatrix) - transformationMatrix
(OOMatrix) - drawTransformationMatrix
(GLfloat) - collisionRadius
(GLfloat) - frustumRadius
(void) - setCollisionRadius:
(NSMutableArray *) - collisionArray
(void) - applyVelocity:
(void) - takeEnergyDamage:from:becauseOf:weaponIdentifier:
(void) - dumpState
(NSUInteger) - lastDrawCounter
(void) - setLastDrawCounter:
(double) - findCollisionRadius
(BOOL) - isVisible
(BOOL) - isInSpace
(BOOL) - isImmuneToBreakPatternHide
(GLfloat) - universalTime
(GLfloat) - spawnTime
(GLfloat) - timeElapsedSinceSpawn
(void) - setAtmosphereFogging:
(OOColor *) - fogUniform
(BOOL) - checkLinkedLists [implementation]
(id< OOWeakReferenceSupport >) - superShaderBindingTarget [implementation]
(Vector) - relativePosition [implementation]
(void) - subEntityReallyDied: [implementation]
(BOOL) - isBreakPattern
(BOOL) - isECMBlast
(BOOL) - isExhaust
(BOOL) - isFlasher
(void) - deleteJSSelf
(void) - deleteJSSelf
(jsval) - oo_jsValueInContext: [implementation]
(BOOL) - isCascadeWeapon
(BOOL) - isPlayerLikeShip
(GLfloat) - clock [implementation]
(unsigned) - pseudoFixedD100 [implementation]
(unsigned) - pseudoFixedD256 [implementation]
(unsigned) - systemGovernment [implementation]
(unsigned) - systemEconomy [implementation]
(unsigned) - systemTechLevel [implementation]
(unsigned) - systemPopulation [implementation]
(unsigned) - systemProductivity [implementation]
(BOOL) - isShipWithSubEntityShip:
(void) - drawSubEntityImmediate:translucent: [implementation]
Instance Methods inherited from OOWeakRefObject
(id) - weakSelf
(id) - weakRetain [implementation]
(void) - weakRefDied: [implementation]
Instance Methods inherited from <OOWeakReferenceSupport>
(id) - OO_RETURNS_RETAINED

Class Methods

(static void) + DrawWormholeCorona [implementation]

Private Attributes

double expiry_time
double travel_time
double arrival_time
double estimated_arrival_time
double scan_time
OOSystemID origin
OOSystemID destination
NSPoint originCoords
NSPoint destinationCoords
NSMutableArray * shipsInTransit
double witch_mass
double shrink_factor
double exit_speed
WORMHOLE_SCANINFO scan_info
BOOL hasExitPosition
BOOL _misjump
GLfloat _misjumpRange
BOOL containsPlayer

Additional Inherited Members

Public Attributes inherited from Entity
OOUniversalID universalID
unsigned isShip: 1
unsigned isStation: 1
unsigned isPlayer: 1
unsigned isWormhole: 1
unsigned isSubEntity: 1
unsigned hasMoved: 1
unsigned hasRotated: 1
unsigned hasCollided: 1
unsigned isSunlit: 1
unsigned collisionTestFilter: 2
unsigned throw_sparks: 1
unsigned isImmuneToBreakPatternHide: 1
unsigned isExplicitlyNotMainStation: 1
unsigned isVisualEffect: 1
OOScanClass scanClass
GLfloat zero_distance
GLfloat cam_zero_distance
GLfloat no_draw_distance
GLfloat collision_radius
HPVector position
Vector cameraRelativePosition
Quaternion orientation
OOColor * atmosphereFogging
int zero_index
Entity * x_previous
Entity * x_next
Entity * y_previous
Entity * y_next
Entity * z_previous
Entity * z_next
Entity * collision_chain
OOUniversalID shadingEntityID
Entity * collider
CollisionRegion * collisionRegion
Protected Attributes inherited from Entity
HPVector lastPosition
Quaternion lastOrientation
GLfloat distanceTravelled
OOMatrix rotMatrix
Vector velocity
GLfloat energy
GLfloat maxEnergy
BoundingBox boundingBox
GLfloat mass
NSMutableArray * collidingEntities
OOTimeAbsolute spawnTime
struct JSObject * _jsSelf
NSUInteger lastDrawCounter
Protected Attributes inherited from OOWeakRefObject
OOWeakReference * weakSelf

Detailed Description

Definition at line 48 of file WormholeEntity.h.

Method Documentation

◆ arrivalTime

- (double) arrivalTime

Definition at line 494 of file WormholeEntity.m.

495{
496 return arrival_time;
497}

References arrival_time, and arrivalTime.

Referenced by arrivalTime, destination, and PlayerEntity::leaveWitchspace.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ canCollide

- (BOOL) canCollide
implementation

Reimplemented from Entity.

Definition at line 578 of file WormholeEntity.m.

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}
float x
#define PLAYER
#define UNIVERSE
Definition Universe.h:827
OOSystemID origin

References canCollide, origin, originCoords, PLAYER, UNIVERSE, witch_mass, and x.

Referenced by canCollide.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ checkCloseCollisionWith:

- (BOOL) checkCloseCollisionWith: (Entity*) other
implementation

Reimplemented from Entity.

Definition at line 593 of file WormholeEntity.m.

593 :(Entity*)other
594{
595 return ![other isEffect];
596}
BOOL isEffect()
Definition Entity.m:180

References Entity::isEffect.

Here is the call graph for this function:

◆ dealloc

- (void) dealloc
implementation

Reimplemented from Entity.

Definition at line 543 of file WormholeEntity.m.

544{
545 [shipsInTransit release];
546
547 [super dealloc];
548}

References Entity::dealloc, and dealloc.

Referenced by dealloc.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ descriptionComponents

- (NSString *) descriptionComponents
implementation

Reimplemented from Entity.

Definition at line 550 of file WormholeEntity.m.

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}

References descriptionComponents.

Referenced by descriptionComponents.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ destination

References arrivalTime, destination, destinationCoordinates, estimatedArrivalTime, exitSpeed, expiryTime, isScanned, misjumpRange, originCoordinates, scanInfo, scanTime, setMisjump, travelTime, and withMisjump.

Here is the call graph for this function:

◆ destinationCoordinates

- (NSPoint) destinationCoordinates

Definition at line 474 of file WormholeEntity.m.

475{
476 return destinationCoords;
477}
NSPoint destinationCoords

References destinationCoordinates, and destinationCoords.

Referenced by Universe::carryPlayerOn:inWormhole:, destination, and destinationCoordinates.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ disgorgeShips

- (void) disgorgeShips

Definition at line 317 of file WormholeEntity.m.

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}
#define SCANNER_MAX_RANGE
Definition Entity.h:53
OOINLINE HPVector vectorToHPVector(Vector v) INLINE_CONST_FUNC
Definition OOHPVector.h:166
struct HPVector HPVector
OOINLINE HPVector HPvector_add(HPVector a, HPVector b) INLINE_CONST_FUNC
Definition OOHPVector.h:213
return nil
Vector vector_forward_from_quaternion(Quaternion quat) CONST_FUNC
struct Quaternion Quaternion
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 y
struct Vector Vector
OOINLINE OOScalar dot_product(Vector first, Vector second) INLINE_CONST_FUNC
Definition OOVector.h:299
const Vector kBasisZVector
Definition OOVector.h:47
OOINLINE Vector vector_multiply_scalar(Vector v, OOScalar s) INLINE_CONST_FUNC
Definition OOVector.h:180
void setVelocity:(Vector vel)
Definition Entity.m:703
void setOrientation:(Quaternion quat)
Definition Entity.m:676
OOEntityStatus status()
Definition Entity.m:733
HPVector position
Definition Entity.m:576
void setPosition:(HPVector posn)
Definition Entity.m:608
void doScriptEvent:(OOJSPropID message)
BOOL witchspaceLeavingEffects()
void setRoll:(double amount)
void setSpeed:(double amount)
void setPitch:(double amount)
void setBeaconCode:(NSString *bcode)
void doScriptEvent:andReactToAIMessage:(OOJSPropID scriptEvent,[andReactToAIMessage] NSString *aiMessage)
void update:(OOTimeDelta delta_t)
GLfloat maxFlightSpeed
NSMutableArray * shipsInTransit
float randf(void)
#define ranrot_rand()
OOHPScalar x
Definition OOHPVector.h:36
OOHPScalar y
Definition OOHPVector.h:37
OOHPScalar z
Definition OOHPVector.h:38

References _misjump, arrival_time, ShipEntity::bounty, containsPlayer, disgorgeShips, ShipEntity::doScriptEvent:, ShipEntity::doScriptEvent:andReactToAIMessage:, dot_product(), exitSpeed, hasExitPosition, HPvector_add(), kBasisZVector, ShipEntity::maxFlightSpeed, nil, PLAYER, Entity::position, quaternion_set_random(), randf(), ranrot_rand, SCANNER_MAX_RANGE, ShipEntity::setBeaconCode:, ShipEntity::setBounty:withReason:, setExitSpeed:, Entity::setOrientation:, ShipEntity::setPitch:, Entity::setPosition:, ShipEntity::setRoll:, ShipEntity::setSpeed:, Entity::setVelocity:, shipsInTransit, Entity::status, UNIVERSE, ShipEntity::update:, vector_forward_from_quaternion(), vector_multiply_scalar(), vector_right_from_quaternion(), vector_up_from_quaternion(), vectorToHPVector(), ShipEntity::witchspaceLeavingEffects, HPVector::x, Vector::x, HPVector::y, Vector::y, HPVector::z, and Vector::z.

Referenced by Universe::carryPlayerOn:inWormhole:, disgorgeShips, Universe(OOPrivate)::populateSpaceFromActiveWormholes, and PlayerEntity(OOPrivate)::updateWormholes.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ drawImmediate:translucent:

- (void) drawImmediate: (bool) immediate
translucent: (bool) translucent 
implementation

Reimplemented from Entity.

Definition at line 626 of file WormholeEntity.m.

626 :(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}
#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
#define OO_WORMHOLE_COLOR_FVEC4
GLfloat collision_radius
Definition Entity.h:107
OOScanClass scanClass
Definition Entity.m:743
GLfloat cam_zero_distance
Definition Entity.h:105
GLfloat no_draw_distance
Definition Entity.h:106
static void DrawWormholeCorona(GLfloat inner_radius, GLfloat outer_radius, int step, GLfloat z_distance, GLfloat *col4v1)

References Entity::cam_zero_distance, Entity::collision_radius, DrawWormholeCorona(), GLDrawBallBillboard(), Entity::no_draw_distance, OO_WORMHOLE_COLOR_FVEC4, OOCheckOpenGLErrors(), OOGL, OOGLBEGIN, OOGLEND, OOSetOpenGLState, OOVerifyOpenGLState, OPENGL_STATE_TRANSLUCENT_PASS, Entity::scanClass, UNIVERSE, and witch_mass.

Here is the call graph for this function:

◆ DrawWormholeCorona

+ (void) DrawWormholeCorona (GLfloat) inner_radius
(GLfloat) outer_radius
(int) step
(GLfloat) z_distance
(GLfloat *) col4v1 
implementation

Definition at line 669 of file WormholeEntity.m.

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}
#define M_PI
Definition OOMaths.h:54
#define OO_WORMHOLE_COLOR_BOOST

References M_PI, OO_WORMHOLE_COLOR_BOOST, OOGLBEGIN, OOGLEND, and randf().

Here is the call graph for this function:

◆ dumpSelfState

- (void) dumpSelfState
implementation

Reimplemented from Entity.

Definition at line 780 of file WormholeEntity.m.

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}
#define OOLog(class, format,...)
Definition OOLogging.h:84
unsigned count
NSString * ClockToString(double clock, BOOL adjusting)
GLfloat mass
Definition Entity.m:671
OOSystemID destination
double estimated_arrival_time
NSString * scanInfoString()

References arrival_time, ClockToString(), count, destination, Entity::dumpSelfState, dumpSelfState, estimated_arrival_time, expiry_time, Entity::mass, OOLog, origin, scan_time, scanInfoString, shipsInTransit, UNIVERSE, and witch_mass.

Referenced by dumpSelfState.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ estimatedArrivalTime

- (double) estimatedArrivalTime

Definition at line 499 of file WormholeEntity.m.

500{
502}

References estimated_arrival_time, and estimatedArrivalTime.

Referenced by destination, estimatedArrivalTime, HeadUpDisplay::hudDrawReticleOnTarget, and PlayerEntity(OOPrivate)::updateTargeting.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ exitSpeed

- (double) exitSpeed

Definition at line 479 of file WormholeEntity.m.

480{
481 return exit_speed;
482}

References exit_speed, and exitSpeed.

Referenced by destination, disgorgeShips, exitSpeed, and PlayerEntity::leaveWitchspace.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ expiryTime

- (double) expiryTime

Definition at line 489 of file WormholeEntity.m.

490{
491 return expiry_time;
492}

References expiry_time, and expiryTime.

Referenced by destination, expiryTime, and HeadUpDisplay::hudDrawReticleOnTarget.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getDict

- (NSDictionary *) getDict

Definition at line 729 of file WormholeEntity.m.

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}

References getDict, and nil.

Referenced by PlayerEntity::commanderDataDictionary, getDict, and shipsInTransit.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getJSClass:andPrototype:

- (void) getJSClass: (JSClass**) outClass
andPrototype: (JSObject**) outPrototype 

Reimplemented from Entity.

Provided by category WormholeEntity(OOJavaScriptExtensions).

Definition at line 110 of file OOJSWormhole.m.

110 :(JSClass**)outClass andPrototype:(JSObject**)outPrototype
111{
112 *outClass = &sWormholeClass;
113 *outPrototype = sWormholePrototype;
114}
static JSObject * sWormholePrototype
static JSClass sWormholeClass

◆ identFromShip:

- (NSString *) identFromShip: (ShipEntity*) ship

Definition at line 559 of file WormholeEntity.m.

559 :(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}
#define OOLogERR(class, format,...)
Definition OOLogging.h:125
NSString *const kOOLogInconsistentState
Definition OOLogging.m:599
#define DESC(key)
Definition Universe.h:832
@ WH_SCANINFO_DESTINATION
WORMHOLE_SCANINFO scanInfo()

References DESC, kOOLogInconsistentState, nil, OOLogERR, scanInfo, and WH_SCANINFO_DESTINATION.

Here is the call graph for this function:

◆ init

- (id) init
implementation

Reimplemented from Entity.

Provided by category WormholeEntity(Private).

Definition at line 58 of file WormholeEntity.m.

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;
68 scan_time = 0;
69 hasExitPosition = NO;
70 containsPlayer = NO;
71 exit_speed = 50.0;
72 }
73 return self;
74}
@ WH_SCANINFO_NONE
unsigned isWormhole
Definition Entity.m:175
WORMHOLE_SCANINFO scan_info

Referenced by initWithDict:, and initWormholeTo:fromShip:.

Here is the caller graph for this function:

◆ initWithDict:

- (WormholeEntity *) initWithDict: (NSDictionary*) dict

Definition at line 84 of file WormholeEntity.m.

84 :(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) {
126 ShipEntity* ship = [ShipEntity shipRestoredFromDictionary:shipInfo
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}
@ WH_SCANINFO_SCANNED
id shipRestoredFromDictionary:useFallback:context:(NSDictionary *dictionary,[useFallback] BOOL fallback,[context] NSMutableDictionary *context)

References _misjump, arrival_time, destination, destinationCoords, estimated_arrival_time, expiry_time, init, nil, OOLog, origin, originCoords, Entity::position, scan_info, ShipEntity::shipRestoredFromDictionary:useFallback:context:, and WH_SCANINFO_SCANNED.

Here is the call graph for this function:

◆ initWormholeTo:fromShip:

- (WormholeEntity *) initWormholeTo: (OOSystemID) s
fromShip: (ShipEntity*) ship 

Definition at line 144 of file WormholeEntity.m.

144 :(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 }
183 position = [ship position];
185 }
186 return self;
187}
OOINLINE OOHPScalar HPdistance2(HPVector v1, HPVector v2) INLINE_CONST_FUNC
Definition OOHPVector.h:293
int16_t OOSystemID
Definition OOTypes.h:183
OOINLINE OOScalar distance(Vector v1, Vector v2) INLINE_CONST_FUNC
Definition OOVector.h:280
#define WORMHOLE_SHRINK_RATE
GLfloat zero_distance
Definition Entity.h:104
unsigned isPlayer
Definition Entity.m:145
OOINLINE double distanceBetweenPlanetPositions(int x1, int y1, int x2, int y2) INLINE_CONST_FUNC

References _misjump, arrival_time, Entity::collision_radius, destination, destinationCoords, distance(), distanceBetweenPlanetPositions(), estimated_arrival_time, expiry_time, HPdistance2(), init, Entity::isPlayer, M_PI, Entity::mass, nil, origin, originCoords, PLAYER, Entity::position, shrink_factor, travel_time, witch_mass, WORMHOLE_SHRINK_RATE, and Entity::zero_distance.

Here is the call graph for this function:

◆ isScanned

- (BOOL) isScanned

Definition at line 514 of file WormholeEntity.m.

515{
517}

References isScanned, scan_info, and WH_SCANINFO_NONE.

Referenced by destination, and isScanned.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isVisibleToScripts [1/2]

- (BOOL) isVisibleToScripts

Reimplemented from Entity.

Provided by category WormholeEntity(OOJavaScriptExtensions).

Definition at line 121 of file OOJSWormhole.m.

122{
123 return YES;
124}

◆ isVisibleToScripts [2/2]

- (BOOL) isVisibleToScripts

Reimplemented from Entity.

Provided by category WormholeEntity(OOJavaScriptExtensions).

◆ misjumpRange

- (GLfloat) misjumpRange

Definition at line 231 of file WormholeEntity.m.

232{
233 return _misjumpRange;
234}
GLfloat _misjumpRange

References _misjumpRange, and misjumpRange.

Referenced by destination, and misjumpRange.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ oo_jsClassID

- (JSClassID) oo_jsClassID

Reimplemented from Entity.

Provided by category WormholeEntity(OOJavaScriptExtensions).

Definition at line 111 of file OOJSWormhole.m.

112{
113 return sWormholeClassID;
114}
static JSClassID sWormholeClassID

◆ oo_jsClassName [1/2]

- (NSString *) oo_jsClassName

Reimplemented from Entity.

Provided by category WormholeEntity(OOJavaScriptExtensions).

Definition at line 116 of file OOJSWormhole.m.

117{
118 return @"Wormhole";
119}

◆ oo_jsClassName [2/2]

- (NSString *) oo_jsClassName

Reimplemented from Entity.

Provided by category WormholeEntity(OOJavaScriptExtensions).

◆ origin

References origin.

◆ originCoordinates

- (NSPoint) originCoordinates

Definition at line 469 of file WormholeEntity.m.

470{
471 return originCoords;
472}

References originCoordinates, and originCoords.

Referenced by destination, and originCoordinates.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scanInfo

- (WORMHOLE_SCANINFO) scanInfo

Definition at line 528 of file WormholeEntity.m.

529{
530 return scan_info;
531}

References scan_info, and scanInfo.

Referenced by destination, identFromShip:, and scanInfo.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scanInfoString

- (NSString *) scanInfoString
implementation

Definition at line 761 of file WormholeEntity.m.

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}
@ WH_SCANINFO_SHIP
@ WH_SCANINFO_ARRIVAL_TIME
@ WH_SCANINFO_COLLAPSE_TIME

References scan_info, scanInfoString, WH_SCANINFO_ARRIVAL_TIME, WH_SCANINFO_COLLAPSE_TIME, WH_SCANINFO_DESTINATION, WH_SCANINFO_NONE, WH_SCANINFO_SCANNED, and WH_SCANINFO_SHIP.

Referenced by dumpSelfState, and scanInfoString.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scanTime

- (double) scanTime

Definition at line 509 of file WormholeEntity.m.

510{
511 return scan_time;
512}

References scan_time, and scanTime.

Referenced by destination, and scanTime.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setContainsPlayer:

- (void) setContainsPlayer: (BOOL) val

Definition at line 448 of file WormholeEntity.m.

448 :(BOOL)val
449{
450 containsPlayer = val;
451}

References containsPlayer.

Referenced by PlayerEntity::leaveWitchspace.

Here is the caller graph for this function:

◆ setExitPosition:

- (void) setExitPosition: (HPVector) pos

Definition at line 453 of file WormholeEntity.m.

453 :(HPVector)pos
454{
455 [self setPosition:pos];
456 hasExitPosition = YES;
457}

References hasExitPosition, and Entity::setPosition:.

Referenced by PlayerEntity::leaveWitchspace.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setExitSpeed:

- (void) setExitSpeed: (double) speed

Definition at line 484 of file WormholeEntity.m.

484 :(double)speed
485{
487}
double speed()
Definition Entity.m:713

References exit_speed, and Entity::speed.

Referenced by disgorgeShips, and PlayerEntity::leaveWitchspace.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setMisjump

- (void) setMisjump

Definition at line 189 of file WormholeEntity.m.

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}

References _misjump, arrival_time, destinationCoords, distance(), distanceBetweenPlanetPositions(), originCoords, setMisjump, and travel_time.

Referenced by destination, and setMisjump.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setMisjumpWithRange:

- (void) setMisjumpWithRange: (GLfloat) range

Definition at line 204 of file WormholeEntity.m.

204 :(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}

References _misjump, _misjumpRange, arrival_time, destinationCoords, distance(), distanceBetweenPlanetPositions(), originCoords, and travel_time.

Referenced by PlayerEntity::enterWitchspace, PlayerEntity::enterWormhole:, and ShipEntity::enterWormhole:replacing:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setScanInfo:

- (void) setScanInfo: (WORMHOLE_SCANINFO) scanInfo

Definition at line 533 of file WormholeEntity.m.

533 :(WORMHOLE_SCANINFO)p_scanInfo
534{
535 scan_info = p_scanInfo;
536}
WORMHOLE_SCANINFO

References scan_info.

Referenced by PlayerEntity(OOPrivate)::updateTargeting.

Here is the caller graph for this function:

◆ setScannedAt:

- (void) setScannedAt: (double) time

Definition at line 519 of file WormholeEntity.m.

519 :(double)p_scanTime
520{
522 scan_time = p_scanTime;
524 }
525 // else we previously scanned this wormhole
526}

References scan_info, scan_time, WH_SCANINFO_NONE, and WH_SCANINFO_SCANNED.

Referenced by PlayerEntity::addScannedWormhole:, and PlayerEntity(OOPrivate)::updateTargeting.

Here is the caller graph for this function:

◆ shipsInTransit

- (NSArray *) shipsInTransit

References getDict, and shipsInTransit.

Here is the call graph for this function:

◆ suckInShip:

- (BOOL) suckInShip: (ShipEntity*) ship

Definition at line 236 of file WormholeEntity.m.

236 :(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}
OOINLINE OOHPScalar HPdistance(HPVector v1, HPVector v2) INLINE_CONST_FUNC
Definition OOHPVector.h:298
return self
#define MIN_FUEL
Definition ShipEntity.h:104
void clearStack()
Definition AI.m:604
void message:(NSString *ms)
Definition AI.m:536
GLfloat collisionRadius()
Definition Entity.m:830
unsigned isStation
Definition Entity.m:135
ShipEntity * leader()
void setStatus:(OOEntityStatus stat)
BOOL hasFuelInjection()
NSString * beaconCode()
OOShipGroup * group()
OOFuelQuantity fuel
float afterburnerFactor()

References ShipEntity::afterburnerFactor, arrival_time, ShipEntity::beaconCode, AI::clearStack, Entity::collision_radius, Entity::collisionRadius, ShipEntity::doScriptEvent:, expiry_time, ShipEntity::fuel, ShipEntity::getAI, ShipEntity::group, ShipEntity::hasFuelInjection, HPdistance(), Entity::isStation, OOShipGroup::leader, M_PI, Entity::mass, ShipEntity::maxFlightSpeed, AI::message:, MIN_FUEL, origin, originCoords, PLAYER, Entity::position, ShipEntity::setStatus:, shrink_factor, Entity::status, UNIVERSE, witch_mass, WORMHOLE_SHRINK_RATE, and x.

Referenced by ShipEntity::enterWormhole:replacing:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ travelTime

- (double) travelTime

Definition at line 504 of file WormholeEntity.m.

505{
506 return travel_time;
507}

References travel_time, and travelTime.

Referenced by Universe::carryPlayerOn:inWormhole:, destination, and travelTime.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ update:

- (void) update: (OOTimeDelta) delta_t
implementation

Reimplemented from Entity.

Definition at line 598 of file WormholeEntity.m.

598 :(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}
#define NO_DRAW_DISTANCE_FACTOR
Definition Entity.h:49
OOMatrix OOMatrixForBillboard(HPVector bbPos, HPVector eyePos) CONST_FUNC
Definition OOMatrix.m:186
double OOTimeDelta
Definition OOTypes.h:193
OOMatrix rotMatrix
Definition Entity.h:134
double clockTimeAdjusted()

References PlayerEntity::clockTimeAdjusted, Entity::collision_radius, expiry_time, M_PI, nil, Entity::no_draw_distance, NO_DRAW_DISTANCE_FACTOR, OOMatrixForBillboard(), PLAYER, Entity::position, Entity::rotMatrix, Entity::scanClass, shrink_factor, Entity::update:, witch_mass, and WORMHOLE_SHRINK_RATE.

Here is the call graph for this function:

◆ withMisjump

- (BOOL) withMisjump

Definition at line 226 of file WormholeEntity.m.

227{
228 return _misjump;
229}

References _misjump, and withMisjump.

Referenced by destination, PlayerEntity::enterWormhole:, and withMisjump.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ _misjump

- (BOOL) _misjump
private

◆ _misjumpRange

- (GLfloat) _misjumpRange
private

Definition at line 72 of file WormholeEntity.h.

Referenced by misjumpRange, and setMisjumpWithRange:.

◆ arrival_time

- (double) arrival_time
private

◆ containsPlayer

- (BOOL) containsPlayer
private

Definition at line 73 of file WormholeEntity.h.

Referenced by disgorgeShips, and setContainsPlayer:.

◆ destination

◆ destinationCoords

- (NSPoint) destinationCoords
private

◆ estimated_arrival_time

- (double) estimated_arrival_time
private

◆ exit_speed

- (double) exit_speed
private

Definition at line 67 of file WormholeEntity.h.

Referenced by exitSpeed, and setExitSpeed:.

◆ expiry_time

- (double) expiry_time
private

◆ hasExitPosition

- (BOOL) hasExitPosition
private

Definition at line 70 of file WormholeEntity.h.

Referenced by disgorgeShips, and setExitPosition:.

◆ origin

◆ originCoords

- (NSPoint) originCoords
private

◆ scan_info

- (WORMHOLE_SCANINFO) scan_info
private

Definition at line 69 of file WormholeEntity.h.

Referenced by initWithDict:, isScanned, scanInfo, scanInfoString, setScanInfo:, and setScannedAt:.

◆ scan_time

- (double) scan_time
private

Definition at line 54 of file WormholeEntity.h.

Referenced by dumpSelfState, scanTime, and setScannedAt:.

◆ shipsInTransit

- (NSArray *) shipsInTransit
private

Definition at line 538 of file WormholeEntity.m.

539{
540 return shipsInTransit;
541}

Referenced by disgorgeShips, dumpSelfState, and shipsInTransit.

◆ shrink_factor

- (double) shrink_factor
private

Definition at line 65 of file WormholeEntity.h.

Referenced by initWormholeTo:fromShip:, suckInShip:, and update:.

◆ travel_time

- (double) travel_time
private

Definition at line 51 of file WormholeEntity.h.

Referenced by initWormholeTo:fromShip:, setMisjump, setMisjumpWithRange:, and travelTime.

◆ witch_mass

- (double) witch_mass
private

The documentation for this class was generated from the following files: