Oolite 1.91.0.7646-241128-10e222e
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 49 of file DockEntity.m.

Method Documentation

◆ addShipToShipsOnApproach:

- (void) addShipToShipsOnApproach: (ShipEntity *) ship

Extends class DockEntity.

Definition at line 1 of file DockEntity.m.

445 :(ShipEntity *) ship
446{
447 int corridor_distance[] = { -1, 1, 3, 5, 7, 9, 11, 12, 12};
448 int corridor_offset[] = { 0, 0, 0, 0, 0, 0, 1, 3, 12};
449 /* Eric's improvements to the docking flight code seem to have
450 * made it safer to go quite a bit faster here. With the increased
451 * numbers of ships which might need to dock at the main station,
452 * faster docking will help avoid massive queues. Previous speed
453 * was mostly 48 - CIM: 27/8/2013*/
454 int corridor_speed[] = { 96, 96, 128, 128, 96, 128, 128, 256, 512}; // how fast to approach the next point
455 int corridor_range[] = { 24, 12, 6, 4, 4, 6, 15, 38, 96}; // how close you have to get to the target point
456 int corridor_rotate[] = { 1, 1, 1, 1, 0, 0, 0, 0, 0}; // whether to match the station rotation
457 int corridor_count = 9;
458 int corridor_final_approach = 3;
459
460 NSNumber *shipID = [NSNumber numberWithUnsignedShort:[ship universalID]];
461 StationEntity *station = (StationEntity *)[self parentEntity];
462
463 HPVector launchVector = HPvector_forward_from_quaternion(quaternion_multiply(orientation, [station orientation]));
464 HPVector temp = (fabs(launchVector.x) < 0.8)? make_HPvector(1,0,0) : make_HPvector(0,1,0);
465 temp = HPcross_product(launchVector, temp); // 90 deg to launchVector & temp
466 HPVector rightVector = HPcross_product(launchVector, temp);
467 HPVector upVector = HPcross_product(launchVector, rightVector);
468
469 // will select a direction for offset based on the entity personality (was ship ID)
470 int offset_id = [ship entityPersonalityInt] & 0xf; // 16 point compass
471 double c = cos(offset_id * M_PI * ONE_EIGHTH);
472 double s = sin(offset_id * M_PI * ONE_EIGHTH);
473
474 // test if this points at the ship
475 HPVector point1 = [self absolutePositionForSubentity];
476 point1.x += launchVector.x * corridor_offset[corridor_count - 1];
477 point1.y += launchVector.x * corridor_offset[corridor_count - 1];
478 point1.z += launchVector.x * corridor_offset[corridor_count - 1];
479 HPVector alt1 = point1;
480 point1.x += c * upVector.x * corridor_offset[corridor_count - 1] + s * rightVector.x * corridor_offset[corridor_count - 1];
481 point1.y += c * upVector.y * corridor_offset[corridor_count - 1] + s * rightVector.y * corridor_offset[corridor_count - 1];
482 point1.z += c * upVector.z * corridor_offset[corridor_count - 1] + s * rightVector.z * corridor_offset[corridor_count - 1];
483 alt1.x -= c * upVector.x * corridor_offset[corridor_count - 1] + s * rightVector.x * corridor_offset[corridor_count - 1];
484 alt1.y -= c * upVector.y * corridor_offset[corridor_count - 1] + s * rightVector.y * corridor_offset[corridor_count - 1];
485 alt1.z -= c * upVector.z * corridor_offset[corridor_count - 1] + s * rightVector.z * corridor_offset[corridor_count - 1];
486 if (HPdistance2(alt1, ship->position) < HPdistance2(point1, ship->position))
487 {
488 s = -s;
489 c = -c; // turn 180 degrees
490 }
491
492 //
493 NSMutableArray *coordinatesStack = [NSMutableArray arrayWithCapacity: MAX_DOCKING_STAGES];
494 float port_depth = port_dimensions.z; // 250m deep standard port.
495
496 int i;
497 for (i = corridor_count - 1; i >= 0; i--)
498 {
499 NSMutableDictionary *nextCoords = [NSMutableDictionary dictionaryWithCapacity:3];
500 int offset = corridor_offset[i];
501 float corridor_length = port_depth * corridor_distance[i];
502
503 float rx = s * port_depth * offset;
504 float ry = c * port_depth * offset;
505 float rz = corridor_length;
506 // if there are many ships on approach, randomise coordinates a bit
507 if ((i == corridor_count - 1) && [self countOfShipsInDockingQueue])
508 {
509 /* This used to try to just space the ships further out
510 * along the 16 approach lanes - this had various problems
511 * with putting ship coordinates on top of each other
512 * and/or spacing them out all the way back to the
513 * witchpoint. Instead, use a few more bits of
514 * entityPersonalityInt to shuffle the holding coordinates
515 * a bit more. It still doesn't guarantee two ships won't
516 * want the same space, but it makes it considerably more
517 * unlikely - I dropped 100 docking ships into the aegis
518 * at once, and they all got allocated positions far
519 * enough from the others to avoid collisions or near
520 * misses - CIM: 27 May 2014 */
521
522 int offset_id2 = ([ship entityPersonalityInt] & 0xf0)>>4; // 16 point compass
523 int offset_id3 = ([ship entityPersonalityInt] & 0xf00)>>8; // 16 point step position
524 float c2 = cos(offset_id2 * M_PI * ONE_EIGHTH);
525 float s2 = sin(offset_id2 * M_PI * ONE_EIGHTH);
526 float ssize = MAX(port_depth,1500.0);
527 rx += c2 * ssize;
528 ry += s2 * ssize;
529 rz += ssize * ((float)offset_id3 / 4.0);
530
531// OOLog(@"docking.debug",@"Adjusted coordinates by %f x %f x %f",c2 * ssize,s2 * ssize,ssize * ((float)offset_id3 / 4.0));
532 }
533
534 // add the lenght inside the station to the corridor, except for the final position, inside the dock.
535 if (corridor_distance[i] > 0) corridor_length += port_corridor;
536
537 [nextCoords oo_setInteger:corridor_count - i forKey:@"docking_stage"];
538 [nextCoords oo_setFloat:rx forKey:@"rx"];
539 [nextCoords oo_setFloat:ry forKey:@"ry"];
540 [nextCoords oo_setFloat:rz forKey:@"rz"];
541 [nextCoords oo_setFloat:corridor_speed[i] forKey:@"speed"];
542 [nextCoords oo_setFloat:corridor_range[i] forKey:@"range"];
543
544 if (corridor_rotate[i])
545 {
546 [nextCoords setObject:@"YES" forKey:@"match_rotation"];
547 }
548
549 if (i == corridor_final_approach)
550 {
551 if (station == [UNIVERSE station])
552 {
553 [nextCoords setObject:@"[station-begin-final-aproach]" forKey:@"comms_message"];
554 }
555 else
556 {
557 [nextCoords setObject:@"[docking-begin-final-aproach]" forKey:@"comms_message"];
558 }
559 }
560
561 [coordinatesStack addObject:nextCoords];
562 }
563
564 [shipsOnApproach setObject:coordinatesStack forKey:shipID];
565
566
567 // COMM-CHATTER
568 if (station == [UNIVERSE station])
569 {
570 [station sendExpandedMessage:@"[station-welcome]" toShip:ship];
571 }
572 else
573 {
574 [station sendExpandedMessage:@"[docking-welcome]" toShip:ship];
575 }
576}
#define ONE_EIGHTH
#define MAX(A, B)
Definition OOMaths.h:114
#define M_PI
Definition OOMaths.h:73
HPVector HPvector_forward_from_quaternion(Quaternion quat)
Quaternion quaternion_multiply(Quaternion q1, Quaternion q2)
float y
float x
#define UNIVERSE
Definition Universe.h:840
OOUniversalID universalID
Definition Entity.h:89
HPVector position
Definition Entity.h:112
GLint entityPersonalityInt()
voidpf uLong offset
Definition ioapi.h:140

◆ autoDockShipsInQueue:

- (void) autoDockShipsInQueue: (NSMutableDictionary *) queue

Extends class DockEntity.

Definition at line 1 of file DockEntity.m.

150 :(NSMutableDictionary *)queue
151{
152 NSNumber *idObj = nil;
153 foreach (idObj, [queue allKeys])
154 {
155 ShipEntity *ship = [UNIVERSE entityForUniversalID:[idObj unsignedIntValue]];
156 if ([ship isShip])
157 {
158 [self pullInShipIfPermitted:ship];
159 }
160 }
161
162 [queue removeAllObjects];
163}
return nil

◆ clearAllIdLocks

- (void) clearAllIdLocks

Extends class DockEntity.

Definition at line 1 of file DockEntity.m.

1222{
1223 int i;
1224 for (i = 1; i < MAX_DOCKING_STAGES; i++)
1225 {
1226 DESTROY(id_lock[i]);
1227 }
1228}
#define DESTROY(x)
Definition OOCocoa.h:77
#define MAX_DOCKING_STAGES

◆ clearIdLocks:

- (void) clearIdLocks: (ShipEntity *) ship

Extends class DockEntity.

Definition at line 1 of file DockEntity.m.

1208 :(ShipEntity *)ship
1209{
1210 int i;
1211 for (i = 1; i < MAX_DOCKING_STAGES; i++)
1212 {
1213 if (ship == nil || ship == [id_lock[i] weakRefUnderlyingObject])
1214 {
1215 DESTROY(id_lock[i]);
1216 }
1217 }
1218}

◆ pullInShipIfPermitted:

- (void) pullInShipIfPermitted: (ShipEntity *) ship

Extends class DockEntity.

Definition at line 1 of file DockEntity.m.

854 :(ShipEntity *)ship
855{
856 // allow_docking: docking permitted and expected
857 // disallowed_docking_collides: unauthorised docking does not result in explosion
858 if (allow_docking || !disallowed_docking_collides)
859 {
860 [ship enterDock:(StationEntity*)[self parentEntity]];
861 }
862}
void enterDock:(StationEntity *station)

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