48@interface DockEntity (OOPrivate)
52- (void)autoDockShipsInQueue:(NSMutableDictionary*)queue;
53- (void)addShipToShipsOnApproach:(
ShipEntity*)ship;
54- (void)pullInShipIfPermitted:(
ShipEntity*)ship;
64 NSNumber* idObj =
nil;
66 ShipEntity* ship = [UNIVERSE entityForUniversalID:[
idObj unsignedIntValue]];
71 [shipsOnApproach removeObjectForKey:idObj];
86 return [shipsOnApproach count];
91 double playerExtraTime = 0;
95 NSNumber* idObj =
nil;
97 ShipEntity* ship = [UNIVERSE entityForUniversalID:[
idObj unsignedIntValue]];
103 [shipsOnApproach removeAllObjects];
108 if (isDockingStation && [player
status] == STATUS_IN_FLIGHT &&
116 playerExtraTime = 10;
117 int seconds = round(playerExtraTime);
132 [launchQueue removeAllObjects];
135- (void)autoDockShipsInQueue:(NSMutableDictionary*)queue
137 NSNumber* idObj =
nil;
138 foreach (idObj, [queue allKeys]) {
139 ShipEntity* ship = [UNIVERSE entityForUniversalID:[
idObj unsignedIntValue]];
145 [
queue removeAllObjects];
158- (void)setAllowsDocking:(BOOL)allowed
176- (void)setAllowsLaunching:(BOOL)allowed
184- (void)setDisallowedDockingCollides:(BOOL)ddc
198 return @"DOCK_CLOSED";
202 return @"TOO_BIG_TO_DOCK";
222 return @"TOO_BIG_TO_DOCK";
227 return @"TRY_AGAIN_LATER";
231 return @"TRY_AGAIN_LATER";
234 return @"DOCKING_POSSIBLE";
243 if (fabs(dir.
x) + fabs(dir.
y) > 0.1) {
255 NSNumber* shipID = [
NSNumber numberWithUnsignedShort:ship_id];
289 if (ship_distance > 12500.0) {
297 OOLogERR(
@"station.issueDockingInstructions.failed",
@"couldn't addShipToShipsOnApproach:%@ in %@, retrying later -- shipsOnApproach:\n%@", ship,
self,
shipsOnApproach);
304 NSMutableArray* coordinatesStack = [shipsOnApproach objectForKey:shipID];
306 if ([coordinatesStack
count] == 0) {
307 OOLogERR(
@"station.issueDockingInstructions.failed",
@" -- coordinatesStack = %@", coordinatesStack);
313 NSMutableDictionary* nextCoords = (NSMutableDictionary*)[coordinatesStack objectAtIndex:0];
314 int docking_stage = [
nextCoords oo_intForKey:@"docking_stage"];
315 float speedAdvised = [
nextCoords oo_floatForKey:@"speed"];
316 float rangeAdvised = [
nextCoords oo_floatForKey:@"range"];
324 coords.
x += rel_coords.
x * vi.
x + rel_coords.
y * vj.
x + rel_coords.
z * vk.
x;
325 coords.
y += rel_coords.
x * vi.
y + rel_coords.
y * vj.
y + rel_coords.
z * vk.
y;
326 coords.
z += rel_coords.
x * vi.
z + rel_coords.
y * vj.
z + rel_coords.
z * vk.
z;
332 if (
HPmagnitude2(delta) > max_allowed_range * max_allowed_range)
334 if ((docking_stage == 1) && (
HPmagnitude2(delta) < 1000000.0))
343 nextCoords = (NSMutableDictionary*)[coordinatesStack oo_dictionaryAtIndex:1];
344 if (nextCoords ==
nil) {
348 docking_stage = [
nextCoords oo_intForKey:@"docking_stage"];
349 speedAdvised = [
nextCoords oo_floatForKey:@"speed"];
350 rangeAdvised = [
nextCoords oo_floatForKey:@"range"];
351 BOOL match_rotation = [
nextCoords oo_boolForKey:@"match_rotation"];
352 NSString* comms_message = [
nextCoords oo_stringForKey:@"comms_message"];
363 coords.
x += rel_coords.
x * vi.
x + rel_coords.
y * vj.
x + rel_coords.
z * vk.
x;
364 coords.
y += rel_coords.
x * vi.
y + rel_coords.
y * vj.
y + rel_coords.
z * vk.
y;
365 coords.
z += rel_coords.
x * vi.
z + rel_coords.
y * vj.
z + rel_coords.
z * vk.
z;
367 if ([
id_lock[docking_stage] weakRefUnderlyingObject] ==
nil &&
368 [
id_lock[docking_stage + 1] weakRefUnderlyingObject] ==
nil &&
369 [
id_lock[docking_stage + 2] weakRefUnderlyingObject] ==
nil)
377 if (docking_stage > 1)
386 return OOMakeDockingInstructions(station, coords, speedAdvised, rangeAdvised,
@"APPROACH_COORDINATES",
nil, match_rotation, docking_stage);
393 if (![nextCoords objectForKey:
@"hold_message_given"]) {
395 [UNIVERSE clearPreviousMessage];
397 [
nextCoords setObject:@"YES" forKey:@"hold_message_given"];
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 };
412 int corridor_speed[] = { 96, 96, 128, 128, 96, 128, 128, 256, 512 };
413 int corridor_range[] = { 24, 12, 6, 4, 4, 6, 15, 38, 96 };
414 int corridor_rotate[] = { 1, 1, 1, 1, 0, 0, 0, 0, 0 };
415 int corridor_count = 9;
416 int corridor_final_approach = 3;
450 NSMutableArray* coordinatesStack = [
NSMutableArray arrayWithCapacity:MAX_DOCKING_STAGES];
451 float port_depth = port_dimensions.z;
454 for (i = corridor_count - 1; i >= 0; i--) {
456 int offset = corridor_offset[
i];
457 float corridor_length = port_depth * corridor_distance[
i];
459 float rx = s * port_depth *
offset;
460 float ry = c * port_depth *
offset;
461 float rz = corridor_length;
463 if ((i == corridor_count - 1) && [
self countOfShipsInDockingQueue]) {
481 float ssize =
MAX(port_depth, 1500.0);
484 rz += ssize * ((float)offset_id3 / 4.0);
490 if (corridor_distance[i] > 0)
491 corridor_length += port_corridor;
493 [
nextCoords oo_setInteger:corridor_count - i forKey:@"docking_stage"];
497 [
nextCoords oo_setFloat:corridor_speed[
i] forKey:@"speed"];
498 [
nextCoords oo_setFloat:corridor_range[
i] forKey:@"range"];
500 if (corridor_rotate[i]) {
501 [
nextCoords setObject:@"YES" forKey:@"match_rotation"];
504 if (i == corridor_final_approach) {
505 if (station == [
UNIVERSE station]) {
506 [
nextCoords setObject:@"[station-begin-final-aproach]" forKey:@"comms_message"];
508 [
nextCoords setObject:@"[docking-begin-final-aproach]" forKey:@"comms_message"];
518 if (station == [
UNIVERSE station]) {
537 NSNumber* shipID = [
NSNumber numberWithUnsignedShort:ship_id];
540 [shipsOnApproach removeObjectForKey:shipID];
545 if ([player
status] == STATUS_IN_FLIGHT &&
582 NSNumber* shipID = [
NSNumber numberWithUnsignedShort:ship_id];
588 if ([ship
isPlayer] && [[
self owner] playerReservedDock] ==
self) {
596 return [shipsOnApproach count];
601 return [launchQueue count];
617 if ([station
status] == STATUS_DEAD) {
636 BOOL rotatedPort = (ww >= hh) ? NO : YES;
637 BOOL rotatedShip = ((shipbb.
max.
x - shipbb.
min.
x) >= (shipbb.
max.
y - shipbb.
min.
y)) ? NO : YES;
638 BOOL rotationsMatch = (rotatedShip == rotatedPort);
639 if (rotationsMatch) {
641 while (shipbb.
max.
x - shipbb.
min.
x > ww * 0.90)
643 while (shipbb.
max.
y - shipbb.
min.
y > hh * 0.90)
647 while (shipbb.
max.
y - shipbb.
min.
y > ww * 0.90)
649 while (shipbb.
max.
x - shipbb.
min.
x > hh * 0.90)
656#ifdef OO_DEBUG_MONITOR_ENABLED
660 unsigned laneFlags = 0;
664 if (arbb.
min.
x > -ww)
668 if (arbb.
min.
y > -hh)
670 inLane = laneFlags == 0xF;
671 range = 0.90 * arbb.
max.
z + 0.10 * arbb.
min.
z;
673 OOLog(
@"docking.debug",
@"Normalised port dimensions are %g x %g x %g. Player bounding box is at %@-%@ -- %s (%X), range: %g",
674 ww * 2.0, hh * 2.0, dd,
675 VectorDescription(arbb.
min), VectorDescription(arbb.
max),
676 inLane ?
"in lane" :
"out of lane", laneFlags,
681 if ((arbb.
max.
x < ww * 3.0) && (arbb.
min.
x > -ww * 3.0) && (arbb.
max.
y < hh * 3.0) && (arbb.
min.
y > -hh * 3.0)) {
686 [UNIVERSE addMessage:DESC(@"oolite-station-docking-requires-clearance") forCount:3];
691 if (arbb.
max.
z < -dd) {
695 if ((arbb.
max.
x < ww) && (arbb.
min.
x > -ww) && (arbb.
max.
y < hh) && (arbb.
min.
y > -hh)) {
696 if ([ship
status] != STATUS_LAUNCHING && !allow_docking_thisship) {
697 if (arbb.
min.
z < dd) {
705 if (arbb.
max.
z < 0.0) {
711 if (0.90 * arbb.
max.
z + 0.10 * arbb.
min.
z < 0.0)
718 if ([ship
status] == STATUS_LAUNCHING) {
724 GLfloat safety = 1.0 + (50.0 / 100.0);
726 if ((arbb.
min.
x > -safety * ww) && (arbb.
max.
x < safety * ww) && (arbb.
min.
y > -safety * hh) && (arbb.
max.
y < safety * hh)) {
727 if (arbb.
min.
z < 0.0)
730 if ((arbb.
min.
x < -ww && arbb.
max.
x > ww) || (arbb.
min.
y < -hh && arbb.
max.
y > hh)) {
737 GLfloat correction_factor = -arbb.
min.
z / (arbb.
max.
z - arbb.
min.
z);
745 delta.
x = 0.5f * (arbb.
max.
x + arbb.
min.
x) * correction_factor;
746 delta.
y = 0.5f * (arbb.
max.
y + arbb.
min.
y) * correction_factor;
748 if (arbb.
max.
x < ww && arbb.
min.
x > -ww) {
752 if (arbb.
max.
y > hh && arbb.
min.
y > -hh) {
759 pos.
x -= delta.
y * vj.
x + delta.
x * vi.
x;
760 pos.
y -= delta.
y * vj.
y + delta.
x * vi.
y;
761 pos.
z -= delta.
y * vj.
z + delta.
x * vi.
z;
766 if (0.90f * arbb.
max.
z + 0.10f * arbb.
min.
z < 0.0f) {
780 if (allow_docking || !disallowed_docking_collides) {
785- (void)addShipToLaunchQueue:(
ShipEntity*)ship withPriority:(BOOL)priority
798 [launchQueue insertObject:ship atIndex:0];
800 [launchQueue addObject:ship];
843 [UNIVERSE addEntity:ship];
857- (NSUInteger)countOfShipsInLaunchQueueWithPrimaryRole:(NSString*)role
859 NSUInteger
count = 0;
862 if ([ship hasPrimaryRole:role])
902 [launchQueue removeAllObjects];
903 [shipsOnApproach removeAllObjects];
908 double unitime = [UNIVERSE getTime];
916 if ([station playerReservedDock] ==
self) {
923 int ent_count =
UNIVERSE->n_entities;
929 for (i = 0; i < ent_count; i++) {
936 for (i = 0; (i < ship_count) && (isEmpty); i++) {
939 if ((ship != station) && (d2 < 25000000) && ([ship
status] != STATUS_DOCKED))
950 if (r_pos.
x || r_pos.
y || r_pos.
z)
965 for (i = 0; i < ship_count; i++) {
977 int ent_count =
UNIVERSE->n_entities;
983 for (i = 0; i < ent_count; i++) {
984 if (uni_entities[i]->
isShip) {
989 for (i = 0; i < ship_count; i++) {
992 if ((ship != station) && (d2 < 25000000) && ([ship
status] != STATUS_DOCKED))
995 float time_out = -15.00;
1006 if (r_pos.
x || r_pos.
y || r_pos.
z)
1023 spos.
x += 3000.0 * v1.
x;
1024 spos.
y += 3000.0 * v1.
y;
1025 spos.
z += 3000.0 * v1.
z;
1033 for (i = 0; i < ship_count; i++) {
1038- (void)setDimensionsAndCorridor:(BOOL)docking ddc:(BOOL)ddc launching:(BOOL)launching
1052 while ((start.
x > stbb.
min.
x) && (start.
x < stbb.
max.
x) && (start.
y > stbb.
min.
y) && (start.
y < stbb.
max.
y) && (start.
z > stbb.
min.
z) && (start.
z < stbb.
max.
z)) {
1069- (id)initWithKey:(NSString*)key definition:(NSDictionary*)dict
1101 if (ship ==
nil || ship == [id_lock[i] weakRefUnderlyingObject]) {
1115- (BOOL)setUpShipFromDictionary:(NSDictionary*)dict
1122 if (![super setUpShipFromDictionary:dict])
1137 if ([se
status] == STATUS_DOCKED) {
1140 [launchQueue removeObjectAtIndex:0];
1157- (void)takeEnergyDamage:(
double)amount from:(
Entity*)ent becauseOf:(
Entity*)other weaponIdentifier:(NSString*)weaponIdentifier
1167- (void)drawImmediate:(
bool)immediate translucent:(
bool)translucent
#define SCANNER_MAX_RANGE
#define SCANNER_MAX_RANGE2
OOINLINE OOHPScalar HPdot_product(HPVector first, HPVector second) INLINE_CONST_FUNC
OOINLINE HPVector HPvector_subtract(HPVector a, HPVector b) INLINE_CONST_FUNC
OOINLINE HPVector HPvector_multiply_scalar(HPVector v, OOHPScalar s) INLINE_CONST_FUNC
OOINLINE HPVector HPcross_product(HPVector first, HPVector second) INLINE_CONST_FUNC
OOINLINE OOHPScalar HPmagnitude(HPVector vec) INLINE_CONST_FUNC
OOINLINE HPVector make_HPvector(OOHPScalar vx, OOHPScalar vy, OOHPScalar vz) INLINE_CONST_FUNC
OOINLINE OOHPScalar HPdistance2(HPVector v1, HPVector v2) INLINE_CONST_FUNC
OOINLINE HPVector HPvector_normal(HPVector vec) INLINE_CONST_FUNC
OOINLINE HPVector OOHPVectorTowards(HPVector a, HPVector b, OOHPScalar where) INLINE_CONST_FUNC
OOINLINE HPVector HPvector_add(HPVector a, HPVector b) INLINE_CONST_FUNC
OOINLINE OOHPScalar HPmagnitude2(HPVector vec) INLINE_CONST_FUNC
#define OOJS_PROFILE_EXIT
#define OOJS_PROFILE_ENTER
#define OOJSFreeValue(context, value)
#define OOJSUndefinedValue()
OOINLINE jsval OOJSValueFromNativeObject(JSContext *context, id object)
OOINLINE BOOL OOJSValueToBOOL(JSContext *context, jsval value)
OOINLINE JSContext * OOJSAcquireContext(void)
OOINLINE void OOJSRelinquishContext(JSContext *context)
#define OOLogERR(class, format,...)
#define OOLog(class, format,...)
Vector vector_forward_from_quaternion(Quaternion quat) CONST_FUNC
void quaternion_rotate_about_axis(Quaternion *quat, Vector axis, OOScalar angle) NONNULL_FUNC
Quaternion quaternion_multiply(Quaternion q1, Quaternion q2) CONST_FUNC
Vector vector_up_from_quaternion(Quaternion quat) CONST_FUNC
HPVector HPvector_forward_from_quaternion(Quaternion quat) CONST_FUNC
Vector vector_right_from_quaternion(Quaternion quat) CONST_FUNC
@ DOCKING_CLEARANCE_STATUS_GRANTED
@ DOCKING_CLEARANCE_STATUS_REQUESTED
OOINLINE Vector vector_add(Vector a, Vector b) INLINE_CONST_FUNC
OOINLINE OOScalar magnitude(Vector vec) INLINE_CONST_FUNC
OOINLINE Vector make_vector(OOScalar vx, OOScalar vy, OOScalar vz) INLINE_CONST_FUNC
OOINLINE OOScalar dot_product(Vector first, Vector second) INLINE_CONST_FUNC
OOINLINE Vector vector_multiply_scalar(Vector v, OOScalar s) INLINE_CONST_FUNC
OOINLINE Vector vector_normal(Vector vec) INLINE_CONST_FUNC
#define STATION_LAUNCH_RETRY_INTERVAL
NSDictionary * OOMakeDockingInstructions(StationEntity *station, HPVector coords, float speed, float range, NSString *ai_message, NSString *comms_message, BOOL match_rotation, int docking_stage)
@ STATION_ALERT_LEVEL_RED
#define MAX_DOCKING_STAGES
#define STATION_DELAY_BETWEEN_LAUNCHES
void setNextThinkTime:(OOTimeAbsolute ntt)
void message:(NSString *ms)
void launchShip:(ShipEntity *ship)
NSMutableDictionary * shipsOnApproach
BOOL dockingCorridorIsEmpty()
void autoDockShipsInQueue:(NSMutableDictionary *queue)
NSUInteger countOfShipsInLaunchQueue()
void pullInShipIfPermitted:(ShipEntity *ship)
NSUInteger countOfShipsInDockingQueue()
NSUInteger pruneAndCountShipsOnApproach()
void autoDockShipsOnApproach()
void abortDockingForShip:(ShipEntity *ship)
ShipEntity * id_lock[MAX_DOCKING_STAGES]
void addShipToShipsOnApproach:(ShipEntity *ship)
void clearIdLocks:(ShipEntity *ship)
BOOL no_docking_while_launching
BOOL disallowed_docking_collides
NSMutableArray * launchQueue
BOOL disallowedDockingCollides()
void clearDockingCorridor()
OOUniversalID universalID
HPVector absolutePositionForSubentity()
void setVelocity:(Vector vel)
GLfloat collisionRadius()
void setNormalOrientation:(Quaternion quat)
ShipEntity * parentEntity()
void setPosition:(HPVector posn)
BOOL callMethod:inContext:withArguments:count:result:(jsid methodID,[inContext] JSContext *context,[withArguments] jsval *argv,[count] intN argc,[result] jsval *outResult)
StationEntity * getTargetDockStation()
void setDockingClearanceStatus:(OODockingClearanceStatus newValue)
void doScriptEvent:(OOJSPropID message)
void setDesiredSpeed:(double amount)
void takeEnergyDamage:from:becauseOf:weaponIdentifier:(double amount, [from] Entity *ent, [becauseOf] Entity *other, [weaponIdentifier] NSString *weaponIdentifier)
void setStatus:(OOEntityStatus stat)
id initWithKey:definition:(NSString *key,[definition] NSDictionary *dict)
void setRoll:(double amount)
void setSpeed:(double amount)
void takeScrapeDamage:from:(double amount,[from] Entity *ent)
GLint entityPersonalityInt()
BoundingBox totalBoundingBox
void drawImmediate:translucent:(bool immediate, [translucent] bool translucent)
void resetExhaustPlumes()
BoundingBox findBoundingBoxRelativeToPosition:i:j:k:(HPVector opv,[i] Vector i,[j] Vector j,[k] Vector k)
void setPitch:(double amount)
void setYaw:(double amount)
void setLaunchDelay:(double delay)
void adjustVelocity:(Vector xVel)
void setPendingEscortCount:(uint8_t count)
void sendExpandedMessage:toShip:(NSString *message_text,[toShip] ShipEntity *other_ship)
void update:(OOTimeDelta delta_t)
uint8_t pendingEscortCount()
void noteTakingDamage:from:type:(double amount,[from] Entity *entity,[type] OOShipDamageType type)
void doScriptEvent:withArgument:(OOJSPropID message,[withArgument] id argument)
void sendAIMessage:(NSString *message)
void doScriptEvent:withArgument:andReactToAIMessage:(OOJSPropID scriptEvent,[withArgument] id argument,[andReactToAIMessage] NSString *aiMessage)
void enterDock:(StationEntity *station)
Vector virtualPortDimensions()