Line data Source code
1 0 : /* 2 : 3 : DockEntity.h 4 : 5 : ShipEntity subclass representing a dock. 6 : 7 : Oolite 8 : Copyright (C) 2004-2013 Giles C Williams and contributors 9 : 10 : This program is free software; you can redistribute it and/or 11 : modify it under the terms of the GNU General Public License 12 : as published by the Free Software Foundation; either version 2 13 : of the License, or (at your option) any later version. 14 : 15 : This program is distributed in the hope that it will be useful, 16 : but WITHOUT ANY WARRANTY; without even the implied warranty of 17 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 : GNU General Public License for more details. 19 : 20 : You should have received a copy of the GNU General Public License 21 : along with this program; if not, write to the Free Software 22 : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 23 : MA 02110-1301, USA. 24 : 25 : */ 26 : 27 : #import "ShipEntity.h" 28 : #import "StationEntity.h" // For MAX_DOCKING_STAGES 29 : 30 : 31 0 : @interface DockEntity: ShipEntity 32 : { 33 : @private 34 0 : NSMutableDictionary *shipsOnApproach; 35 0 : NSMutableArray *launchQueue; 36 0 : double last_launch_time; 37 : // double approach_spacing; // not needed now holding pattern changed 38 : 39 0 : ShipEntity *id_lock[MAX_DOCKING_STAGES]; // OOWeakReferences to a ShipEntity 40 : 41 0 : Vector port_dimensions; 42 0 : double port_corridor; // corridor length inside station. 43 : 44 0 : BOOL no_docking_while_launching; 45 0 : BOOL allow_launching; 46 0 : BOOL allow_docking; 47 0 : BOOL disallowed_docking_collides; 48 0 : BOOL virtual_dock; 49 : } 50 : 51 0 : - (void) clear; 52 : 53 : // Docking 54 0 : - (BOOL) allowsDocking; 55 0 : - (void) setAllowsDocking:(BOOL)allow; 56 0 : - (BOOL) disallowedDockingCollides; 57 0 : - (void) setDisallowedDockingCollides:(BOOL)ddc; 58 0 : - (NSUInteger) countOfShipsInDockingQueue; 59 : /** 60 : * Guides a ship into the dock. 61 : * <h3>Possible results:</h3> 62 : * <ul> 63 : * <li>null<br/> 64 : * if no result can be computed or the last control point is reached 65 : * <li>Move to station (APPROACH)<br/> 66 : * if ship is too far away 67 : * <li>Move away from station (BACKOFF)<br/> 68 : * if ship is too close 69 : * <li>Move perpendicular to station/dock direction (APPROACH)<br/> 70 : * if ship is approaching from wrong side of station 71 : * <li>Abort (TRY AGAIN LATER)<br/> 72 : * if something went wrong until here 73 : * <li>Hold position (HOLD_POSITION)<br/> 74 : * if coordinatesStack is empty or approach is not clear 75 : * <li>Move to next control point (APPROACH_COORDINATES)<br/> 76 : * if control point not within collision radius 77 : * </ul> 78 : * 79 : * <h3>Algorithm:</h3> 80 : * <ol> 81 : * <li>If ship is not on approach list and beyond scanner range (25 km?), approach the station 82 : * <li>Add ship to approach list 83 : * <li>If ship is within distance of 1000 km between station's and ship's collision radius, move away from station 84 : * <li>If ship is approaching from behind, move to the side of the station (perpendicular on direction to station and launch vector) 85 : * <li>If ship is further away than 12000 km, approach the station 86 : * </ol> 87 : * <p>Now the ship is in the vicinity of the station in the correct hemispere. Let's guide them in.</p> 88 : * <ol> 89 : * <li>Get the coordinatesStack for this ship (the approach path?). If there is a problem, Ship shall hold position 90 : * <li>If next coordinates (control point) not yet within collision radius, move towards that position 91 : * <li>Remove control point from stack; get next control point 92 : * <li>If next 3 stages of approach are clear, move to next position 93 : * <li>otherwise hold position 94 : * </ol> 95 : * 96 : * <p>TODO: Where is the detection that the ship has docked?</p> 97 : * <p>TODO: What are the magic number's units? Is it km (kilometers)?</p> 98 : */ 99 1 : - (NSDictionary *) dockingInstructionsForShip:(ShipEntity *)ship; 100 0 : - (NSString *) canAcceptShipForDocking:(ShipEntity *)ship; 101 0 : - (BOOL) shipIsInDockingCorridor:(ShipEntity *)ship; 102 0 : - (BOOL) shipIsInDockingQueue:(ShipEntity *)ship; 103 0 : - (void) abortDockingForShip:(ShipEntity *)ship; 104 0 : - (void) abortAllDockings; 105 0 : - (BOOL) dockingCorridorIsEmpty; 106 0 : - (void) clearDockingCorridor; 107 0 : - (void) autoDockShipsOnApproach; 108 0 : - (NSUInteger) pruneAndCountShipsOnApproach; 109 0 : - (void) noteDockingForShip:(ShipEntity *)ship; 110 : 111 : // Launching 112 0 : - (BOOL) allowsLaunching; 113 0 : - (void) setAllowsLaunching:(BOOL)allow; 114 0 : - (NSUInteger) countOfShipsInLaunchQueue; 115 0 : - (NSUInteger) countOfShipsInLaunchQueueWithPrimaryRole:(NSString *)role; 116 0 : - (BOOL) allowsLaunchingOf:(ShipEntity *)ship; 117 0 : - (void) launchShip:(ShipEntity *)ship; 118 0 : - (void) addShipToLaunchQueue:(ShipEntity *)ship withPriority:(BOOL)priority; 119 : 120 : // Geometry 121 0 : - (void) setDimensionsAndCorridor:(BOOL)docking :(BOOL)ddc :(BOOL)launching; 122 0 : - (Vector) portUpVectorForShipsBoundingBox:(BoundingBox)bb; 123 0 : - (BOOL) isOffCentre; 124 0 : - (void) setVirtual; 125 : 126 : @end