Oolite
Loading...
Searching...
No Matches
DockEntity(OOPrivate) Category Reference

Instance Methods

(void) - clearIdLocks:
(void) - clearAllIdLocks
(void) - autoDockShipsInQueue:
(void) - addShipToShipsOnApproach:
(void) - pullInShipIfPermitted:

Detailed Description

Definition at line 48 of file DockEntity.m.

Method Documentation

◆ addShipToShipsOnApproach:

- (void) addShipToShipsOnApproach: (ShipEntity *) ship

Extends class DockEntity.

Definition at line 403 of file DockEntity.m.

403 :(ShipEntity*)ship
404{
405 int corridor_distance[] = { -1, 1, 3, 5, 7, 9, 11, 12, 12 };
406 int corridor_offset[] = { 0, 0, 0, 0, 0, 0, 1, 3, 12 };
407 /* Eric's improvements to the docking flight code seem to have
408 * made it safer to go quite a bit faster here. With the increased
409 * numbers of ships which might need to dock at the main station,
410 * faster docking will help avoid massive queues. Previous speed
411 * was mostly 48 - CIM: 27/8/2013*/
412 int corridor_speed[] = { 96, 96, 128, 128, 96, 128, 128, 256, 512 }; // how fast to approach the next point
413 int corridor_range[] = { 24, 12, 6, 4, 4, 6, 15, 38, 96 }; // how close you have to get to the target point
414 int corridor_rotate[] = { 1, 1, 1, 1, 0, 0, 0, 0, 0 }; // whether to match the station rotation
415 int corridor_count = 9;
416 int corridor_final_approach = 3;
417
418 NSNumber* shipID = [NSNumber numberWithUnsignedShort:[ship universalID]];
419 StationEntity* station = (StationEntity*)[self parentEntity];
420
421 HPVector launchVector = HPvector_forward_from_quaternion(quaternion_multiply(orientation, [station orientation]));
422 HPVector temp = (fabs(launchVector.x) < 0.8) ? make_HPvector(1, 0, 0) : make_HPvector(0, 1, 0);
423 temp = HPcross_product(launchVector, temp); // 90 deg to launchVector & temp
424 HPVector rightVector = HPcross_product(launchVector, temp);
425 HPVector upVector = HPcross_product(launchVector, rightVector);
426
427 // will select a direction for offset based on the entity personality (was ship ID)
428 int offset_id = [ship entityPersonalityInt] & 0xf; // 16 point compass
429 double c = cos(offset_id * M_PI * ONE_EIGHTH);
430 double s = sin(offset_id * M_PI * ONE_EIGHTH);
431
432 // test if this points at the ship
433 HPVector point1 = [self absolutePositionForSubentity];
434 point1.x += launchVector.x * corridor_offset[corridor_count - 1];
435 point1.y += launchVector.x * corridor_offset[corridor_count - 1];
436 point1.z += launchVector.x * corridor_offset[corridor_count - 1];
437 HPVector alt1 = point1;
438 point1.x += c * upVector.x * corridor_offset[corridor_count - 1] + s * rightVector.x * corridor_offset[corridor_count - 1];
439 point1.y += c * upVector.y * corridor_offset[corridor_count - 1] + s * rightVector.y * corridor_offset[corridor_count - 1];
440 point1.z += c * upVector.z * corridor_offset[corridor_count - 1] + s * rightVector.z * corridor_offset[corridor_count - 1];
441 alt1.x -= c * upVector.x * corridor_offset[corridor_count - 1] + s * rightVector.x * corridor_offset[corridor_count - 1];
442 alt1.y -= c * upVector.y * corridor_offset[corridor_count - 1] + s * rightVector.y * corridor_offset[corridor_count - 1];
443 alt1.z -= c * upVector.z * corridor_offset[corridor_count - 1] + s * rightVector.z * corridor_offset[corridor_count - 1];
444 if (HPdistance2(alt1, ship->position) < HPdistance2(point1, ship->position)) {
445 s = -s;
446 c = -c; // turn 180 degrees
447 }
448
449 //
450 NSMutableArray* coordinatesStack = [NSMutableArray arrayWithCapacity:MAX_DOCKING_STAGES];
451 float port_depth = port_dimensions.z; // 250m deep standard port.
452
453 int i;
454 for (i = corridor_count - 1; i >= 0; i--) {
455 NSMutableDictionary* nextCoords = [NSMutableDictionary dictionaryWithCapacity:3];
456 int offset = corridor_offset[i];
457 float corridor_length = port_depth * corridor_distance[i];
458
459 float rx = s * port_depth * offset;
460 float ry = c * port_depth * offset;
461 float rz = corridor_length;
462 // if there are many ships on approach, randomise coordinates a bit
463 if ((i == corridor_count - 1) && [self countOfShipsInDockingQueue]) {
464 /* This used to try to just space the ships further out
465 * along the 16 approach lanes - this had various problems
466 * with putting ship coordinates on top of each other
467 * and/or spacing them out all the way back to the
468 * witchpoint. Instead, use a few more bits of
469 * entityPersonalityInt to shuffle the holding coordinates
470 * a bit more. It still doesn't guarantee two ships won't
471 * want the same space, but it makes it considerably more
472 * unlikely - I dropped 100 docking ships into the aegis
473 * at once, and they all got allocated positions far
474 * enough from the others to avoid collisions or near
475 * misses - CIM: 27 May 2014 */
476
477 int offset_id2 = ([ship entityPersonalityInt] & 0xf0) >> 4; // 16 point compass
478 int offset_id3 = ([ship entityPersonalityInt] & 0xf00) >> 8; // 16 point step position
479 float c2 = cos(offset_id2 * M_PI * ONE_EIGHTH);
480 float s2 = sin(offset_id2 * M_PI * ONE_EIGHTH);
481 float ssize = MAX(port_depth, 1500.0);
482 rx += c2 * ssize;
483 ry += s2 * ssize;
484 rz += ssize * ((float)offset_id3 / 4.0);
485
486 // OOLog(@"docking.debug",@"Adjusted coordinates by %f x %f x %f",c2 * ssize,s2 * ssize,ssize * ((float)offset_id3 / 4.0));
487 }
488
489 // add the lenght inside the station to the corridor, except for the final position, inside the dock.
490 if (corridor_distance[i] > 0)
491 corridor_length += port_corridor;
492
493 [nextCoords oo_setInteger:corridor_count - i forKey:@"docking_stage"];
494 [nextCoords oo_setFloat:rx forKey:@"rx"];
495 [nextCoords oo_setFloat:ry forKey:@"ry"];
496 [nextCoords oo_setFloat:rz forKey:@"rz"];
497 [nextCoords oo_setFloat:corridor_speed[i] forKey:@"speed"];
498 [nextCoords oo_setFloat:corridor_range[i] forKey:@"range"];
499
500 if (corridor_rotate[i]) {
501 [nextCoords setObject:@"YES" forKey:@"match_rotation"];
502 }
503
504 if (i == corridor_final_approach) {
505 if (station == [UNIVERSE station]) {
506 [nextCoords setObject:@"[station-begin-final-aproach]" forKey:@"comms_message"];
507 } else {
508 [nextCoords setObject:@"[docking-begin-final-aproach]" forKey:@"comms_message"];
509 }
510 }
511
512 [coordinatesStack addObject:nextCoords];
513 }
514
515 [shipsOnApproach setObject:coordinatesStack forKey:shipID];
516
517 // COMM-CHATTER
518 if (station == [UNIVERSE station]) {
519 [station sendExpandedMessage:@"[station-welcome]" toShip:ship];
520 } else {
521 [station sendExpandedMessage:@"[docking-welcome]" toShip:ship];
522 }
523}
#define ONE_EIGHTH
OOINLINE HPVector HPcross_product(HPVector first, HPVector second) INLINE_CONST_FUNC
Definition OOHPVector.h:312
struct HPVector HPVector
OOINLINE HPVector make_HPvector(OOHPScalar vx, OOHPScalar vy, OOHPScalar vz) INLINE_CONST_FUNC
Definition OOHPVector.h:149
OOINLINE OOHPScalar HPdistance2(HPVector v1, HPVector v2) INLINE_CONST_FUNC
Definition OOHPVector.h:293
#define MAX(A, B)
Definition OOMaths.h:94
#define M_PI
Definition OOMaths.h:54
Quaternion quaternion_multiply(Quaternion q1, Quaternion q2) CONST_FUNC
HPVector HPvector_forward_from_quaternion(Quaternion quat) CONST_FUNC
float y
float x
#define UNIVERSE
Definition Universe.h:827
OOUniversalID universalID
Definition Entity.m:522
HPVector position
Definition Entity.m:576
GLint entityPersonalityInt()
voidpf uLong offset
Definition ioapi.h:132
OOHPScalar x
Definition OOHPVector.h:36
OOHPScalar y
Definition OOHPVector.h:37
OOHPScalar z
Definition OOHPVector.h:38

References Entity::absolutePositionForSubentity, ShipEntity::entityPersonalityInt, HPcross_product(), HPdistance2(), HPvector_forward_from_quaternion(), M_PI, make_HPvector(), MAX, ONE_EIGHTH, Entity::position, quaternion_multiply(), ShipEntity::sendExpandedMessage:toShip:, Entity::universalID, UNIVERSE, HPVector::x, HPVector::y, and HPVector::z.

Referenced by DockEntity::dockingInstructionsForShip:.

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

◆ autoDockShipsInQueue:

- (void) autoDockShipsInQueue: (NSMutableDictionary *) queue

Extends class DockEntity.

Definition at line 135 of file DockEntity.m.

135 :(NSMutableDictionary*)queue
136{
137 NSNumber* idObj = nil;
138 foreach (idObj, [queue allKeys]) {
139 ShipEntity* ship = [UNIVERSE entityForUniversalID:[idObj unsignedIntValue]];
140 if ([ship isShip]) {
141 [self pullInShipIfPermitted:ship];
142 }
143 }
144
145 [queue removeAllObjects];
146}
return nil

References nil, and DockEntity::pullInShipIfPermitted:.

Referenced by DockEntity::autoDockShipsOnApproach.

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

◆ clearAllIdLocks

- (void) clearAllIdLocks

Extends class DockEntity.

Definition at line 1107 of file DockEntity.m.

1108{
1109 int i;
1110 for (i = 1; i < MAX_DOCKING_STAGES; i++) {
1111 DESTROY(id_lock[i]);
1112 }
1113}
#define DESTROY(x)
#define MAX_DOCKING_STAGES

References clearAllIdLocks, DESTROY, and MAX_DOCKING_STAGES.

Referenced by DockEntity::abortAllDockings, and clearAllIdLocks.

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

◆ clearIdLocks:

- (void) clearIdLocks: (ShipEntity *) ship

Extends class DockEntity.

Definition at line 1097 of file DockEntity.m.

1097 :(ShipEntity*)ship
1098{
1099 int i;
1100 for (i = 1; i < MAX_DOCKING_STAGES; i++) {
1101 if (ship == nil || ship == [id_lock[i] weakRefUnderlyingObject]) {
1102 DESTROY(id_lock[i]);
1103 }
1104 }
1105}

References DESTROY, MAX_DOCKING_STAGES, and nil.

Referenced by DockEntity::abortDockingForShip:, DockEntity::dealloc, and DockEntity::dockingInstructionsForShip:.

Here is the caller graph for this function:

◆ pullInShipIfPermitted:

- (void) pullInShipIfPermitted: (ShipEntity *) ship

Extends class DockEntity.

Definition at line 776 of file DockEntity.m.

776 :(ShipEntity*)ship
777{
778 // allow_docking: docking permitted and expected
779 // disallowed_docking_collides: unauthorised docking does not result in explosion
780 if (allow_docking || !disallowed_docking_collides) {
781 [ship enterDock:(StationEntity*)[self parentEntity]];
782 }
783}
void enterDock:(StationEntity *station)

References ShipEntity::enterDock:, and Entity::parentEntity.

Referenced by autoDockShipsInQueue:, and DockEntity::shipIsInDockingCorridor:.

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

The documentation for this category was generated from the following file: