Oolite
Loading...
Searching...
No Matches
DockEntity.m
Go to the documentation of this file.
1/*
2
3DockEntity.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 "DockEntity.h"
27#import "OOStringExpander.h"
28#import "OOStringParsing.h"
29#import "ShipEntityAI.h"
30#import "StationEntity.h"
31
32#import "HeadUpDisplay.h"
33#import "Universe.h"
34
36#import "OOPlanetEntity.h"
38#import "OOShipGroup.h"
40
41#import "AI.h"
42#import "OOCharacter.h"
43
44#import "OODebugFlags.h"
45#import "OODebugGLDrawing.h"
46#import "OOJSScript.h"
47
48@interface DockEntity (OOPrivate)
49
50- (void)clearIdLocks:(ShipEntity*)ship;
51- (void)clearAllIdLocks;
52- (void)autoDockShipsInQueue:(NSMutableDictionary*)queue;
53- (void)addShipToShipsOnApproach:(ShipEntity*)ship;
54- (void)pullInShipIfPermitted:(ShipEntity*)ship;
55
56@end
57
58@implementation DockEntity
59
61{
62 // Remove dead entities.
63 // Enumerate over allKeys explicitly because we mutate the dictionary.
64 NSNumber* idObj = nil;
65 foreach (idObj, [shipsOnApproach allKeys]) {
66 ShipEntity* ship = [UNIVERSE entityForUniversalID:[idObj unsignedIntValue]];
67 /* Remove ships from the approach queue if they are dead, or
68 * are more than 25.6km from the dock.
69 */
71 [shipsOnApproach removeObjectForKey:idObj];
72 if (ship != nil) {
73 // notify ship if it's alive
74 [ship sendAIMessage:@"DOCKING_ABORTED"];
75 [ship doScriptEvent:OOJSID("stationWithdrewDockingClearance")];
76 }
77 }
78 }
79
80 if ([shipsOnApproach count] == 0) {
81 if (last_launch_time < [UNIVERSE getTime]) {
82 last_launch_time = [UNIVERSE getTime];
83 }
84 }
85
86 return [shipsOnApproach count];
87}
88
90{
91 double playerExtraTime = 0;
92
94
95 NSNumber* idObj = nil;
96 foreach (idObj, [shipsOnApproach allKeys]) {
97 ShipEntity* ship = [UNIVERSE entityForUniversalID:[idObj unsignedIntValue]];
98 if ([ship isShip]) {
99 [ship sendAIMessage:@"DOCKING_ABORTED"];
100 [ship doScriptEvent:OOJSID("stationWithdrewDockingClearance")];
101 }
102 }
103 [shipsOnApproach removeAllObjects];
104
105 PlayerEntity* player = PLAYER;
106 StationEntity* station = (StationEntity*)[self parentEntity];
107 BOOL isDockingStation = (station == [player getTargetDockStation]) && ([station playerReservedDock] == self);
108 if (isDockingStation && [player status] == STATUS_IN_FLIGHT &&
109 [player getDockingClearanceStatus] >= DOCKING_CLEARANCE_STATUS_REQUESTED) {
110 if (HPmagnitude2(HPvector_subtract([player position], [self absolutePositionForSubentity])) > 2250000) // within 1500m of the dock
111 {
112 [station sendExpandedMessage:@"[station-docking-clearance-abort-cancelled]" toShip:player];
113 [player setDockingClearanceStatus:DOCKING_CLEARANCE_STATUS_NONE];
114 [player doScriptEvent:OOJSID("stationWithdrewDockingClearance")];
115 } else {
116 playerExtraTime = 10; // when very close to the port, give the player a few seconds to react on the abort message.
117 int seconds = round(playerExtraTime);
118 [station sendExpandedMessage:OOExpandKey(@"station-docking-clearance-abort-cancelled-in-time", seconds) toShip:player];
119 [player setDockingClearanceStatus:DOCKING_CLEARANCE_STATUS_TIMING_OUT];
120 }
121 }
122
123 // mark docking queue flight pattern as clear
124 [self clearAllIdLocks];
125
126 last_launch_time = [UNIVERSE getTime] + playerExtraTime;
127}
128
130{
132 [launchQueue removeAllObjects];
133}
134
135- (void)autoDockShipsInQueue:(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}
147
149{
150 [self autoDockShipsInQueue:shipsOnApproach];
151}
152
154{
155 return allow_docking;
156}
157
158- (void)setAllowsDocking:(BOOL)allowed
159{
160 if (!allowed && allow_docking) {
161 [self abortAllDockings];
162 }
163 allow_docking = allowed;
164}
165
170
172{
173 return allow_launching;
174}
175
176- (void)setAllowsLaunching:(BOOL)allowed
177{
178 if (!allowed && allow_launching) {
179 [self abortAllLaunches];
180 }
181 allow_launching = allowed;
182}
183
184- (void)setDisallowedDockingCollides:(BOOL)ddc
185{
187}
188
190{
191 virtual_dock = YES;
192}
193
194- (NSString*)canAcceptShipForDocking:(ShipEntity*)ship
195{
196 // First test permanent rejection reasons
197 if (!allow_docking) {
198 return @"DOCK_CLOSED"; // could be temp or perm reject
199 }
201 if ((port_dimensions.x < (bb.max.x - bb.min.x) || port_dimensions.y < (bb.max.y - bb.min.y)) && (port_dimensions.y < (bb.max.x - bb.min.x) || port_dimensions.x < (bb.max.y - bb.min.y))) {
202 return @"TOO_BIG_TO_DOCK";
203 }
204
205 // callback to allow more complex filtering on accept/reject
206 JSContext* context = OOJSAcquireContext();
208 OOJSVal args[] = { OOJSValueFromNativeObject(context, ship) };
209 BOOL accept = YES;
210
211 BOOL OK = [[self script] callMethod:OOJSID("acceptDockingRequestFrom") inContext:context withArguments:args count:1 result:&rval];
212 if (OK)
213 accept = OOJSValueToBOOL(context, rval);
214 if (!OK)
215 accept = YES; // default to permreject
216
217 OOJSFreeValue(context, rval);
218 OOJSFreeValue(context, args[0]);
219 OOJSRelinquishContext(context);
220
221 if (!accept) {
222 return @"TOO_BIG_TO_DOCK";
223 }
224
225 // Second test temporary rejection reasons
227 return @"TRY_AGAIN_LATER";
228 }
229 // if there are pending launches, temporarily don't accept docking requests
231 return @"TRY_AGAIN_LATER";
232 }
233
234 return @"DOCKING_POSSIBLE";
235}
236
238{
239 if (fabs(position.x) + fabs(position.y) > 5.0) {
240 return YES;
241 }
243 if (fabs(dir.x) + fabs(dir.y) > 0.1) {
244 return YES;
245 }
246 return NO;
247}
248
249- (NSDictionary*)dockingInstructionsForShip:(ShipEntity*)ship
250{
251 if (ship == nil)
252 return nil;
253
254 OOUniversalID ship_id = [ship universalID];
255 NSNumber* shipID = [NSNumber numberWithUnsignedShort:ship_id];
256 StationEntity* station = (StationEntity*)[self parentEntity];
257
259 HPVector temp = (fabs(launchVector.x) < 0.8) ? make_HPvector(1, 0, 0) : make_HPvector(0, 1, 0);
260 temp = HPcross_product(launchVector, temp); // 90 deg to launchVector & temp
261 HPVector vi = HPcross_product(launchVector, temp);
262 HPVector vj = HPcross_product(launchVector, vi);
263 HPVector vk = launchVector;
264
265 // check if this is a new ship on approach
266 //
267 if (![shipsOnApproach objectForKey:shipID]) {
269 float ship_distance = HPmagnitude(delta);
270
271 if (ship_distance > SCANNER_MAX_RANGE) {
272 // too far away - don't claim a docking slot by not putting on approachlist for now.
273 return OOMakeDockingInstructions(station, [self absolutePositionForSubentity], [ship maxFlightSpeed], 10000, @"APPROACH", nil, NO, -1);
274 }
275
276 [self addShipToShipsOnApproach:ship];
277
278 if (ship_distance < 1000.0 + [station collisionRadius] + ship->collision_radius) // too close - back off
279 return OOMakeDockingInstructions(station, [self absolutePositionForSubentity], [ship maxFlightSpeed], 5000, @"BACK_OFF", nil, NO, -1);
280
281 float dot = HPdot_product(launchVector, delta);
282 if (dot < 0) // approaching from the wrong side of the station - construct a vector to the side of the station.
283 {
284 HPVector approachVector = HPcross_product(HPvector_normal(delta), launchVector);
285 approachVector = HPcross_product(launchVector, approachVector); // vector, 90 degr rotated from launchVector towards target.
286 return OOMakeDockingInstructions(station, OOHPVectorTowards([self absolutePositionForSubentity], approachVector, [station collisionRadius] + 5000), [ship maxFlightSpeed], 1000, @"APPROACH", nil, NO, -1);
287 }
288
289 if (ship_distance > 12500.0) {
290 // long way off - approach more closely
291 return OOMakeDockingInstructions(station, [self absolutePositionForSubentity], [ship maxFlightSpeed], 10000, @"APPROACH", nil, NO, -1);
292 }
293 }
294
295 if (![shipsOnApproach objectForKey:shipID]) {
296 // some error has occurred - log it, and send the try-again message
297 OOLogERR(@"station.issueDockingInstructions.failed", @"couldn't addShipToShipsOnApproach:%@ in %@, retrying later -- shipsOnApproach:\n%@", ship, self, shipsOnApproach);
298
299 return OOMakeDockingInstructions(station, [ship position], 200, 100, @"TRY_AGAIN_LATER", nil, NO, -1);
300 }
301
302 // shipsOnApproach now has an entry for the ship.
303 //
304 NSMutableArray* coordinatesStack = [shipsOnApproach objectForKey:shipID];
305
306 if ([coordinatesStack count] == 0) {
307 OOLogERR(@"station.issueDockingInstructions.failed", @" -- coordinatesStack = %@", coordinatesStack);
308
309 return OOMakeDockingInstructions(station, [ship position], 0, 100, @"HOLD_POSITION", nil, NO, -1);
310 }
311
312 // get the docking information from the instructions
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"];
317
318 // calculate world coordinates from relative coordinates
319 HPVector rel_coords;
320 rel_coords.x = [nextCoords oo_doubleForKey:@"rx"];
321 rel_coords.y = [nextCoords oo_doubleForKey:@"ry"];
322 rel_coords.z = [nextCoords oo_doubleForKey:@"rz"];
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;
327
328 // check if the ship is at the control point
329 double max_allowed_range = 2.0f * rangeAdvised + ship->collision_radius; // maximum distance permitted from control point - twice advised range
330 HPVector delta = HPvector_subtract(ship->position, coords);
331
332 if (HPmagnitude2(delta) > max_allowed_range * max_allowed_range) // too far from the coordinates - do not remove them from the stack!
333 {
334 if ((docking_stage == 1) && (HPmagnitude2(delta) < 1000000.0)) // 1km*1km
335 speedAdvised *= 0.5; // half speed
336
337 return OOMakeDockingInstructions(station, coords, speedAdvised, rangeAdvised, @"APPROACH_COORDINATES", nil, NO, docking_stage);
338 }
339
340 // else, reached the current coordinates okay..
341
342 // get the NEXT coordinates
343 nextCoords = (NSMutableDictionary*)[coordinatesStack oo_dictionaryAtIndex:1];
344 if (nextCoords == nil) {
345 return nil;
346 }
347
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"];
353
354 if (comms_message) {
355 [station sendExpandedMessage:comms_message toShip:ship];
356 }
357
358 // calculate world coordinates from relative coordinates
359 rel_coords.x = [nextCoords oo_doubleForKey:@"rx"];
360 rel_coords.y = [nextCoords oo_doubleForKey:@"ry"];
361 rel_coords.z = [nextCoords oo_doubleForKey:@"rz"];
362 coords = [self absolutePositionForSubentity];
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;
366
367 if ([id_lock[docking_stage] weakRefUnderlyingObject] == nil &&
368 [id_lock[docking_stage + 1] weakRefUnderlyingObject] == nil &&
369 [id_lock[docking_stage + 2] weakRefUnderlyingObject] == nil) // check three stages ahead
370 {
371 // approach is clear - move to next position
372 //
373
374 // clear any previously owned docking stages
375 [self clearIdLocks:ship];
376
377 if (docking_stage > 1) // don't claim first docking stage
378 {
379 [id_lock[docking_stage] release];
380 id_lock[docking_stage] = [ship weakRetain]; // otherwise - claim this docking stage
381 }
382
383 // remove the previous stage from the stack
384 [coordinatesStack removeObjectAtIndex:0];
385
386 return OOMakeDockingInstructions(station, coords, speedAdvised, rangeAdvised, @"APPROACH_COORDINATES", nil, match_rotation, docking_stage);
387 }
388
389 // else, approach isn't clear - hold position..
390 //
391 [[ship getAI] message:@"HOLD_POSITION"];
392
393 if (![nextCoords objectForKey:@"hold_message_given"]) {
394 // COMM-CHATTER
395 [UNIVERSE clearPreviousMessage];
396 [self sendExpandedMessage:@"[station-hold-position]" toShip:ship];
397 [nextCoords setObject:@"YES" forKey:@"hold_message_given"];
398 }
399
400 return OOMakeDockingInstructions(station, ship->position, 0, 100, @"HOLD_POSITION", nil, NO, -1);
401}
402
403- (void)addShipToShipsOnApproach:(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
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}
524
525- (void)noteDockingForShip:(ShipEntity*)ship
526{
527 // safe to do this for now, as it just clears the ship from the docking queue
528 [self abortDockingForShip:ship];
529
530 // avoid clashes with outgoing ships
531 last_launch_time = [UNIVERSE getTime];
532}
533
534- (void)abortDockingForShip:(ShipEntity*)ship
535{
536 OOUniversalID ship_id = [ship universalID];
537 NSNumber* shipID = [NSNumber numberWithUnsignedShort:ship_id];
538
539 if ([shipsOnApproach objectForKey:shipID]) {
540 [shipsOnApproach removeObjectForKey:shipID];
541 }
542
543 if ([ship isPlayer]) {
544 PlayerEntity* player = PLAYER;
545 if ([player status] == STATUS_IN_FLIGHT &&
546 [player getDockingClearanceStatus] >= DOCKING_CLEARANCE_STATUS_REQUESTED) {
547 if (HPmagnitude2(HPvector_subtract([player position], [self absolutePositionForSubentity])) > 2250000) // within 1500m of the dock
548 {
549 [[self parentEntity] sendExpandedMessage:@"[station-docking-clearance-abort-cancelled]" toShip:player];
550 [player setDockingClearanceStatus:DOCKING_CLEARANCE_STATUS_NONE];
551 } else {
552 int seconds = 10; // when very close to the port, give the player a few seconds to react on the abort message.
553 [[self parentEntity] sendExpandedMessage:OOExpandKey(@"station-docking-clearance-abort-cancelled-in-time", seconds) toShip:player];
554 [player setDockingClearanceStatus:DOCKING_CLEARANCE_STATUS_TIMING_OUT];
555 }
556 }
557 }
558
559 // clear any previously owned docking stages
560 [self clearIdLocks:ship];
561}
562
563- (Vector)portUpVectorForShipsBoundingBox:(BoundingBox)bb
564{
565 BOOL twist = ((port_dimensions.x < port_dimensions.y) ^ (bb.max.x - bb.min.x < bb.max.y - bb.min.y));
566
567 if (!twist) {
569 } else {
571 }
572}
573
574- (BOOL)shipIsInDockingQueue:(ShipEntity*)ship
575{
576 if (![ship isShip])
577 return NO;
578 if ([ship isPlayer] && [ship status] == STATUS_DEAD)
579 return NO;
580
581 OOUniversalID ship_id = [ship universalID];
582 NSNumber* shipID = [NSNumber numberWithUnsignedShort:ship_id];
583
584 if ([shipsOnApproach objectForKey:shipID]) {
585 return YES;
586 }
587 // player docking manually
588 if ([ship isPlayer] && [[self owner] playerReservedDock] == self) {
589 return YES;
590 }
591 return NO;
592}
593
595{
596 return [shipsOnApproach count];
597}
598
600{
601 return [launchQueue count];
602}
603
604- (BOOL)shipIsInDockingCorridor:(ShipEntity*)ship
605{
606 if (![ship isShip])
607 return NO;
608 if ([ship isPlayer] && [ship status] == STATUS_DEAD)
609 return NO;
610
611 BOOL allow_docking_thisship = allow_docking || !disallowed_docking_collides;
612 // ships can physically dock here, and this routine is mainly for
613 // collision detection, but will never be directed here by traffic
614 // control, if allow_docking is false but d_d_c is also false
615
616 StationEntity* station = (StationEntity*)[self parentEntity];
617 if ([station status] == STATUS_DEAD) {
618 return NO;
619 }
620
625
626 HPVector port_pos = [self absolutePositionForSubentity];
627
628 BoundingBox shipbb = [ship boundingBox];
629 BoundingBox arbb = [ship findBoundingBoxRelativeToPosition:port_pos i:vi j:vj k:vk];
630
631 // port dimensions..
632 GLfloat ww = port_dimensions.x;
633 GLfloat hh = port_dimensions.y;
634 GLfloat dd = port_dimensions.z;
635
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) {
640 // the ship and port are both bigger in x than y
641 while (shipbb.max.x - shipbb.min.x > ww * 0.90)
642 ww *= 1.25;
643 while (shipbb.max.y - shipbb.min.y > hh * 0.90)
644 hh *= 1.25;
645 } else {
646 // the ship and port have different x/y biggerness
647 while (shipbb.max.y - shipbb.min.y > ww * 0.90)
648 ww *= 1.25;
649 while (shipbb.max.x - shipbb.min.x > hh * 0.90)
650 hh *= 1.25;
651 }
652
653 ww *= 0.5;
654 hh *= 0.5;
655
656#ifdef OO_DEBUG_MONITOR_ENABLED
657 if ([ship isPlayer] && (gDebugFlags & DEBUG_DOCKING)) {
658 BOOL inLane;
659 float range;
660 unsigned laneFlags = 0;
661
662 if (arbb.max.x < ww)
663 laneFlags |= 1;
664 if (arbb.min.x > -ww)
665 laneFlags |= 2;
666 if (arbb.max.y < hh)
667 laneFlags |= 4;
668 if (arbb.min.y > -hh)
669 laneFlags |= 8;
670 inLane = laneFlags == 0xF;
671 range = 0.90 * arbb.max.z + 0.10 * arbb.min.z;
672
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,
677 range);
678 }
679#endif
680
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)) {
682 if ([station requiresDockingClearance] && [ship isPlayer] && [ship status] != STATUS_LAUNCHING && [ship status] != STATUS_AUTOPILOT_ENGAGED && [PLAYER getDockingClearanceStatus] < DOCKING_CLEARANCE_STATUS_GRANTED) {
683 if ((0.90 * arbb.max.z + 0.10 * arbb.min.z < 3000) && (dot_product(vk, [ship forwardVector]) < -0.9)) {
684 // player is in docking corridor and facing dock
685 // and within 3km
686 [UNIVERSE addMessage:DESC(@"oolite-station-docking-requires-clearance") forCount:3];
687 }
688 }
689 }
690
691 if (arbb.max.z < -dd) {
692 return NO;
693 }
694
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) { // launch-only dock: will collide!
697 if (arbb.min.z < dd) {
698 [ship takeScrapeDamage:5 * [UNIVERSE getTimeDelta] * [ship flightSpeed] from:station];
699 // and bounce
700 HPVector rel = HPvector_subtract([ship position], port_pos);
701 rel = HPvector_multiply_scalar(HPvector_normal(rel), [ship flightSpeed] * 0.4);
702 [ship adjustVelocity:HPVectorToVector(rel)];
703 }
704
705 if (arbb.max.z < 0.0) { // give some warning before exploding...
706 return NO;
707 }
708 }
709
710 // in lane
711 if (0.90 * arbb.max.z + 0.10 * arbb.min.z < 0.0) // we're 90% in docking position!
712 {
713 [self pullInShipIfPermitted:ship];
714 }
715 return YES;
716 }
717
718 if ([ship status] == STATUS_LAUNCHING) {
719 return YES;
720 }
721
722 // if close enough (within 50%) correct and add damage
723 //
724 GLfloat safety = 1.0 + (50.0 / 100.0);
725
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) // got our nose inside
728 {
729
730 if ((arbb.min.x < -ww && arbb.max.x > ww) || (arbb.min.y < -hh && arbb.max.y > hh)) {
731 /* No matter how much safety margin there is, if the
732 * ship is going off opposite edges of the dock at
733 * once, that's a fatal collision */
734 return NO;
735 }
736
737 GLfloat correction_factor = -arbb.min.z / (arbb.max.z - arbb.min.z); // proportion of ship inside
738
739 // damage the ship according to velocity - don't send collision messages to AIs to avoid problems.
740 [ship takeScrapeDamage:5 * [UNIVERSE getTimeDelta] * [ship flightSpeed] from:station];
741 [station doScriptEvent:OOJSID("shipCollided") withArgument:ship]; // no COLLISION message to station AI, carriers would move away!
742 [ship doScriptEvent:OOJSID("shipCollided") withArgument:station]; // no COLLISION message to ship AI, dockingAI.plist would abort.
743
744 Vector delta;
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;
747
748 if (arbb.max.x < ww && arbb.min.x > -ww) {
749 // x is okay - no need to correct
750 delta.x = 0.0f;
751 }
752 if (arbb.max.y > hh && arbb.min.y > -hh) {
753 // y is okay - no need to correct
754 delta.y = 0.0f;
755 }
756
757 // adjust the ship back to the center of the port
758 HPVector pos = [ship position];
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;
762 [ship setPosition:pos];
763 }
764
765 // if far enough in - dock
766 if (0.90f * arbb.max.z + 0.10f * arbb.min.z < 0.0f) {
767 [self pullInShipIfPermitted:ship];
768 }
769
770 return YES; // okay NOW we're in the docking corridor!
771 }
772
773 return NO;
774}
775
776- (void)pullInShipIfPermitted:(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}
784
785- (void)addShipToLaunchQueue:(ShipEntity*)ship withPriority:(BOOL)priority
786{
788
789 if (ship == nil)
790 return;
791
792 if (launchQueue == nil) {
793 launchQueue = [[NSMutableArray alloc] init]; // retained
794 }
795
796 [ship setStatus:STATUS_DOCKED];
797 if (priority) {
798 [launchQueue insertObject:ship atIndex:0];
799 } else {
800 [launchQueue addObject:ship];
801 }
802}
803
804- (void)launchShip:(ShipEntity*)ship
805{
806 if (![ship isShip])
807 return;
808
810 StationEntity* station = (StationEntity*)[self parentEntity];
811
812 HPVector launchPos = [self absolutePositionForSubentity];
813 Vector launchVel = [station velocity];
814 double launchSpeed = 0.5 * [ship maxFlightSpeed];
815 if ([station maxFlightSpeed] > 0 && [station flightSpeed] > 0) // is self a carrier in flight.
816 {
817 launchSpeed = 0.5 * [ship maxFlightSpeed] * (1.0 + [station flightSpeed] / [station maxFlightSpeed]);
818 }
821 Vector launchVector = vector_forward_from_quaternion(q1);
822
823 // launch orientation
824 if ((port_dimensions.x < port_dimensions.y) ^ (bb.max.x - bb.min.x < bb.max.y - bb.min.y)) {
825 quaternion_rotate_about_axis(&q1, launchVector, M_PI * 0.5); // to account for the slot being at 90 degrees to vertical
826 }
828 // launch position
829 [ship setPosition:launchPos];
830 if ([ship pendingEscortCount] > 0)
831 [ship setPendingEscortCount:0]; // Make sure no extra escorts are added after launch. (e.g. for miners etc.)
832 if ([ship hasEscorts])
834 // launch speed
835 launchVel = vector_add(launchVel, vector_multiply_scalar(launchVector, launchSpeed));
836 launchSpeed = magnitude(launchVel);
837 [ship setSpeed:launchSpeed];
838 [ship setVelocity:launchVel];
839 // launch roll/pitch
841 [ship setPitch:0.0];
842 [ship setYaw:0.0];
843 [UNIVERSE addEntity:ship];
844 [ship setStatus:STATUS_LAUNCHING];
845 [ship setDesiredSpeed:launchSpeed]; // must be set after initialising the AI to correct any speed set by AI
846 last_launch_time = [UNIVERSE getTime];
847 double delay = (port_corridor + 2 * port_dimensions.z) / launchSpeed; // pause until 2 portlengths outside of the station.
848 [ship setLaunchDelay:delay];
849 [[ship getAI] setNextThinkTime:last_launch_time + delay]; // pause while launching
850
851 [ship resetExhaustPlumes]; // resets stuff for tracking/exhausts
852
853 [ship doScriptEvent:OOJSID("shipWillLaunchFromStation") withArgument:station];
854 [station doScriptEvent:OOJSID("stationLaunchedShip") withArgument:ship andReactToAIMessage:@"STATION_LAUNCHED_SHIP"];
855}
856
857- (NSUInteger)countOfShipsInLaunchQueueWithPrimaryRole:(NSString*)role
858{
859 NSUInteger count = 0;
860 ShipEntity* ship = nil;
861 foreach (ship, launchQueue) {
862 if ([ship hasPrimaryRole:role])
863 count++;
864 }
865 return count;
866}
867
868- (BOOL)allowsLaunchingOf:(ShipEntity*)ship
869{
870 if (![ship isShip])
871 return NO;
872
874 if ((port_dimensions.x < (bb.max.x - bb.min.x) || port_dimensions.y < (bb.max.y - bb.min.y)) && (port_dimensions.y < (bb.max.x - bb.min.x) || port_dimensions.x < (bb.max.y - bb.min.y)) && ![ship isPlayer]) {
875 return NO;
876 }
877
878 // callback to allow more complex filtering on accept/reject
879 JSContext* context = OOJSAcquireContext();
881 OOJSVal args[] = { OOJSValueFromNativeObject(context, ship) };
882 BOOL accept = YES;
883
884 BOOL OK = [[self script] callMethod:OOJSID("acceptLaunchingRequestFrom") inContext:context withArguments:args count:1 result:&rval];
885 if (OK)
886 accept = OOJSValueToBOOL(context, rval);
887 if (!OK)
888 accept = YES; // default to permreject
889
890 OOJSFreeValue(context, rval);
891 OOJSFreeValue(context, args[0]);
892 OOJSRelinquishContext(context);
893 if (!accept) {
894 return NO;
895 }
896
897 return YES;
898}
899
900- (void)clear
901{
902 [launchQueue removeAllObjects];
903 [shipsOnApproach removeAllObjects];
904}
905
907{
908 double unitime = [UNIVERSE getTime];
909
911 // leave sufficient pause between launches
912 return NO;
913 }
914
915 StationEntity* station = (StationEntity*)[self parentEntity];
916 if ([station playerReservedDock] == self) {
917 // player probably will not appreciate a ship launch right now
918 return NO;
919 }
920
921 // check against all ships
922 BOOL isEmpty = YES;
923 int ent_count = UNIVERSE->n_entities;
924 Entity** uni_entities = UNIVERSE->sortedEntities; // grab the public sorted list
925 Entity* my_entities[ent_count];
926 int i;
927 int ship_count = 0;
928
929 for (i = 0; i < ent_count; i++) {
930 // on red alert, launch even if the player is trying block the corridor. Ignore cargopods or other small debris.
931 if ([uni_entities[i] isShip] && ([station alertLevel] < STATION_ALERT_LEVEL_RED || ![uni_entities[i] isPlayer]) && [uni_entities[i] mass] > 1000) {
932 my_entities[ship_count++] = [uni_entities[i] retain]; // retained
933 }
934 }
935
936 for (i = 0; (i < ship_count) && (isEmpty); i++) {
937 ShipEntity* ship = (ShipEntity*)my_entities[i];
938 double d2 = HPdistance2([station position], [ship position]);
939 if ((ship != station) && (d2 < 25000000) && ([ship status] != STATUS_DOCKED)) // within 5km
940 {
942 d2 = HPdistance2(ppos, ship->position);
943 if (d2 < 4000000) // within 2km of the port entrance
944 {
946 q1 = quaternion_multiply([self orientation], q1);
947 //
949 HPVector r_pos = make_HPvector(ship->position.x - ppos.x, ship->position.y - ppos.y, ship->position.z - ppos.z);
950 if (r_pos.x || r_pos.y || r_pos.z)
951 r_pos = HPvector_normal(r_pos);
952 else
953 r_pos.z = 1.0;
954 //
955 double vdp = HPdot_product(v_out, r_pos); //== cos of the angle between r_pos and v_out
956 //
957 if (vdp > 0.86) {
958 isEmpty = NO;
960 }
961 }
962 }
963 }
964
965 for (i = 0; i < ship_count; i++) {
966 [my_entities[i] release]; // released
967 }
968
969 return isEmpty;
970}
971
973{
974 // check against all ships
975 StationEntity* station = (StationEntity*)[self parentEntity];
976 BOOL isClear = YES;
977 int ent_count = UNIVERSE->n_entities;
978 Entity** uni_entities = UNIVERSE->sortedEntities; // grab the public sorted list
979 Entity* my_entities[ent_count];
980 int i;
981 int ship_count = 0;
982
983 for (i = 0; i < ent_count; i++) {
984 if (uni_entities[i]->isShip) {
985 my_entities[ship_count++] = [uni_entities[i] retain]; // retained
986 }
987 }
988
989 for (i = 0; i < ship_count; i++) {
990 ShipEntity* ship = (ShipEntity*)my_entities[i];
991 double d2 = HPdistance2([station position], [ship position]);
992 if ((ship != station) && (d2 < 25000000) && ([ship status] != STATUS_DOCKED)) // within 5km
993 {
995 float time_out = -15.00; // 15 secs
996 do {
997 isClear = YES;
998 d2 = HPdistance2(ppos, ship->position);
999 if (d2 < 4000000) // within 2km of the port entrance
1000 {
1002 q1 = quaternion_multiply([self orientation], q1);
1003 //
1005 Vector r_pos = make_vector(ship->position.x - ppos.x, ship->position.y - ppos.y, ship->position.z - ppos.z);
1006 if (r_pos.x || r_pos.y || r_pos.z)
1007 r_pos = vector_normal(r_pos);
1008 else
1009 r_pos.z = 1.0;
1010 //
1011 float vdp = dot_product(v_out, r_pos); //== cos of the angle between r_pos and v_out
1012 //
1013 if (vdp > 0.86f) {
1014 isClear = NO;
1015
1016 // okay it's in the way .. give it a wee nudge (0.25s)
1017 [ship update:0.25];
1018 time_out += 0.25;
1019 }
1020 if (time_out > 0) {
1022 HPVector spos = ship->position;
1023 spos.x += 3000.0 * v1.x;
1024 spos.y += 3000.0 * v1.y;
1025 spos.z += 3000.0 * v1.z;
1026 [ship setPosition:spos]; // move 3km out of the way
1027 }
1028 }
1029 } while (!isClear);
1030 }
1031 }
1032
1033 for (i = 0; i < ship_count; i++) {
1034 [my_entities[i] release]; // released
1035 }
1036}
1037
1038- (void)setDimensionsAndCorridor:(BOOL)docking ddc:(BOOL)ddc launching:(BOOL)launching
1039{
1040 StationEntity* station = (StationEntity*)[self parentEntity];
1041 if (virtual_dock) {
1043 } else {
1044 BoundingBox bb = [self boundingBox];
1045 port_dimensions = make_vector(bb.max.x - bb.min.x, bb.max.y - bb.min.y, bb.max.z - bb.min.z);
1046 }
1047
1049
1051 HPVector start = position;
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)) {
1054 }
1055 port_corridor = start.z - position.z;
1056
1057 allow_docking = docking;
1059 allow_launching = launching;
1060}
1061
1063
1064- (BOOL)isDock
1065{
1066 return YES;
1067}
1068
1069- (id)initWithKey:(NSString*)key definition:(NSDictionary*)dict
1070{
1072
1073 self = [super initWithKey:key definition:dict];
1074 if (self != nil) {
1075 shipsOnApproach = [[NSMutableDictionary alloc] init];
1076 launchQueue = [[NSMutableArray alloc] init];
1077 allow_docking = YES;
1079 allow_launching = YES;
1080 virtual_dock = NO;
1081 }
1082
1083 return self;
1084
1086}
1087
1088- (void)dealloc
1089{
1092 [self clearIdLocks:nil];
1093
1094 [super dealloc];
1095}
1096
1097- (void)clearIdLocks:(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}
1106
1108{
1109 int i;
1110 for (i = 1; i < MAX_DOCKING_STAGES; i++) {
1111 DESTROY(id_lock[i]);
1112 }
1113}
1114
1115- (BOOL)setUpShipFromDictionary:(NSDictionary*)dict
1116{
1118
1119 isShip = YES;
1120 isStation = NO;
1121
1122 if (![super setUpShipFromDictionary:dict])
1123 return NO;
1124
1125 return YES;
1126
1128}
1129
1130- (void)update:(OOTimeDelta)delta_t
1131{
1132 [super update:delta_t];
1133
1134 if (([launchQueue count] > 0) && ([shipsOnApproach count] == 0) && [self dockingCorridorIsEmpty]) {
1135 ShipEntity* se = (ShipEntity*)[launchQueue objectAtIndex:0];
1136 // check to make sure ship has not been destroyed in queue by script
1137 if ([se status] == STATUS_DOCKED) {
1138 [self launchShip:se];
1139 }
1140 [launchQueue removeObjectAtIndex:0];
1141 }
1143 no_docking_while_launching = NO; // launching complete
1144 }
1145}
1146
1147// avoid possibility of shooting the virtual dock damaging the station
1148- (void)noteTakingDamage:(double)amount from:(Entity*)entity type:(OOShipDamageType)type
1149{
1150 if (virtual_dock) // can't be damaged
1151 {
1152 return;
1153 }
1154 [super noteTakingDamage:amount from:entity type:type];
1155}
1156
1157- (void)takeEnergyDamage:(double)amount from:(Entity*)ent becauseOf:(Entity*)other weaponIdentifier:(NSString*)weaponIdentifier
1158{
1159 if (virtual_dock) // can't be damaged
1160 {
1161 return;
1162 }
1163 [super takeEnergyDamage:amount from:ent becauseOf:other weaponIdentifier:weaponIdentifier];
1164}
1165
1166// virtual docks are invisible
1167- (void)drawImmediate:(bool)immediate translucent:(bool)translucent
1168{
1169 if (virtual_dock) // not drawn
1170 {
1171 return;
1172 }
1173 [super drawImmediate:immediate translucent:translucent];
1174}
1175
1176@end
#define SCANNER_MAX_RANGE
Definition Entity.h:53
#define SCANNER_MAX_RANGE2
Definition Entity.h:54
#define ONE_EIGHTH
#define gDebugFlags
@ DEBUG_DOCKING
Definition OODebugFlags.h:7
#define DESTROY(x)
OOINLINE OOHPScalar HPdot_product(HPVector first, HPVector second) INLINE_CONST_FUNC
Definition OOHPVector.h:317
OOINLINE HPVector HPvector_subtract(HPVector a, HPVector b) INLINE_CONST_FUNC
Definition OOHPVector.h:236
OOINLINE HPVector HPvector_multiply_scalar(HPVector v, OOHPScalar s) INLINE_CONST_FUNC
Definition OOHPVector.h:198
OOINLINE HPVector HPcross_product(HPVector first, HPVector second) INLINE_CONST_FUNC
Definition OOHPVector.h:312
OOINLINE OOHPScalar HPmagnitude(HPVector vec) INLINE_CONST_FUNC
Definition OOHPVector.h:260
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
OOINLINE HPVector HPvector_normal(HPVector vec) INLINE_CONST_FUNC
Definition OOHPVector.h:288
OOINLINE HPVector OOHPVectorTowards(HPVector a, HPVector b, OOHPScalar where) INLINE_CONST_FUNC
Definition OOHPVector.h:229
OOINLINE HPVector HPvector_add(HPVector a, HPVector b) INLINE_CONST_FUNC
Definition OOHPVector.h:213
OOINLINE OOHPScalar HPmagnitude2(HPVector vec) INLINE_CONST_FUNC
Definition OOHPVector.h:255
#define OOJS_PROFILE_EXIT
#define OOJS_PROFILE_ENTER
jsval OOJSVal
#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,...)
Definition OOLogging.h:125
#define OOLog(class, format,...)
Definition OOLogging.h:84
#define MAX(A, B)
Definition OOMaths.h:94
#define M_PI
Definition OOMaths.h:54
unsigned count
return nil
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
uint16_t OOUniversalID
Definition OOTypes.h:165
double OOTimeDelta
Definition OOTypes.h:193
@ DOCKING_CLEARANCE_STATUS_GRANTED
Definition OOTypes.h:151
@ DOCKING_CLEARANCE_STATUS_REQUESTED
Definition OOTypes.h:150
OOINLINE Vector vector_add(Vector a, Vector b) INLINE_CONST_FUNC
Definition OOVector.h:195
OOINLINE OOScalar magnitude(Vector vec) INLINE_CONST_FUNC
Definition OOVector.h:242
OOINLINE Vector make_vector(OOScalar vx, OOScalar vy, OOScalar vz) INLINE_CONST_FUNC
Definition OOVector.h:149
OOINLINE OOScalar dot_product(Vector first, Vector second) INLINE_CONST_FUNC
Definition OOVector.h:299
OOINLINE Vector vector_multiply_scalar(Vector v, OOScalar s) INLINE_CONST_FUNC
Definition OOVector.h:180
OOINLINE Vector vector_normal(Vector vec) INLINE_CONST_FUNC
Definition OOVector.h:270
#define PLAYER
OOShipDamageType
Definition ShipEntity.h:175
#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
#define UNIVERSE
Definition Universe.h:827
void setNextThinkTime:(OOTimeAbsolute ntt)
Definition AI.m:581
void message:(NSString *ms)
Definition AI.m:536
void abortAllDockings()
Definition DockEntity.m:89
void launchShip:(ShipEntity *ship)
Definition DockEntity.m:804
double port_corridor
Definition DockEntity.h:42
void abortAllLaunches()
Definition DockEntity.m:129
NSMutableDictionary * shipsOnApproach
Definition DockEntity.h:34
BOOL dockingCorridorIsEmpty()
Definition DockEntity.m:906
BOOL allowsDocking()
Definition DockEntity.m:153
BOOL allowsLaunching()
Definition DockEntity.m:171
void autoDockShipsInQueue:(NSMutableDictionary *queue)
Definition DockEntity.m:135
NSUInteger countOfShipsInLaunchQueue()
Definition DockEntity.m:599
void pullInShipIfPermitted:(ShipEntity *ship)
Definition DockEntity.m:776
BOOL virtual_dock
Definition DockEntity.h:48
NSUInteger countOfShipsInDockingQueue()
Definition DockEntity.m:594
void clearAllIdLocks()
NSUInteger pruneAndCountShipsOnApproach()
Definition DockEntity.m:60
Vector port_dimensions
Definition DockEntity.h:41
void autoDockShipsOnApproach()
Definition DockEntity.m:148
BOOL allow_docking
Definition DockEntity.h:46
void abortDockingForShip:(ShipEntity *ship)
Definition DockEntity.m:534
BOOL allow_launching
Definition DockEntity.h:45
ShipEntity * id_lock[MAX_DOCKING_STAGES]
Definition DockEntity.h:39
void setVirtual()
Definition DockEntity.m:189
void addShipToShipsOnApproach:(ShipEntity *ship)
Definition DockEntity.m:403
void clearIdLocks:(ShipEntity *ship)
double last_launch_time
Definition DockEntity.h:36
BOOL no_docking_while_launching
Definition DockEntity.h:44
BOOL isOffCentre()
Definition DockEntity.m:237
BOOL disallowed_docking_collides
Definition DockEntity.h:47
NSMutableArray * launchQueue
Definition DockEntity.h:35
BOOL disallowedDockingCollides()
Definition DockEntity.m:166
void clearDockingCorridor()
Definition DockEntity.m:972
GLfloat collision_radius
Definition Entity.h:107
OOUniversalID universalID
Definition Entity.m:522
HPVector absolutePositionForSubentity()
Definition Entity.m:627
void setVelocity:(Vector vel)
Definition Entity.m:703
Quaternion orientation
Definition Entity.m:682
unsigned isShip
Definition Entity.m:125
GLfloat collisionRadius()
Definition Entity.m:830
void setNormalOrientation:(Quaternion quat)
Definition Entity.m:692
OOEntityStatus status()
Definition Entity.m:733
BoundingBox boundingBox
Definition Entity.m:666
unsigned isStation
Definition Entity.m:135
unsigned isPlayer
Definition Entity.m:145
HPVector position
Definition Entity.m:576
ShipEntity * parentEntity()
Definition Entity.m:553
id owner()
Definition Entity.m:548
GLfloat mass
Definition Entity.m:671
void setPosition:(HPVector posn)
Definition Entity.m:608
BOOL callMethod:inContext:withArguments:count:result:(jsid methodID,[inContext] JSContext *context,[withArguments] jsval *argv,[count] intN argc,[result] jsval *outResult)
Definition OOJSScript.m:328
StationEntity * getTargetDockStation()
void setDockingClearanceStatus:(OODockingClearanceStatus newValue)
Vector forwardVector()
void doScriptEvent:(OOJSPropID message)
void setDesiredSpeed:(double amount)
void takeEnergyDamage:from:becauseOf:weaponIdentifier:(double amount, [from] Entity *ent, [becauseOf] Entity *other, [weaponIdentifier] NSString *weaponIdentifier)
BOOL hasEscorts()
void setStatus:(OOEntityStatus stat)
id initWithKey:definition:(NSString *key,[definition] NSDictionary *dict)
Definition ShipEntity.m:190
void setRoll:(double amount)
void setSpeed:(double amount)
void takeScrapeDamage:from:(double amount,[from] Entity *ent)
GLint entityPersonalityInt()
GLfloat flightSpeed
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)
OOJSScript * script
Vector velocity()
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 dealloc()
Definition ShipEntity.m:986
void sendAIMessage:(NSString *message)
GLfloat flightRoll
GLfloat maxFlightSpeed
void doScriptEvent:withArgument:andReactToAIMessage:(OOJSPropID scriptEvent,[withArgument] id argument,[andReactToAIMessage] NSString *aiMessage)
void enterDock:(StationEntity *station)
Vector virtualPortDimensions()
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
OOScalar x
Definition OOVector.h:32
OOScalar y
Definition OOVector.h:33
OOScalar z
Definition OOVector.h:34