From c5a91aa8f2fe7f5ff1936515430c8f6374e35f06 Mon Sep 17 00:00:00 2001 From: cim Date: Fri, 17 Jan 2014 21:50:35 +0000 Subject: [PATCH] Docking ships don't release their escorts until later --- Resources/Scripts/oolite-priorityai.js | 18 ++++++++++++------ src/Core/Entities/DockEntity.m | 20 ++++++++++---------- src/Core/Entities/StationEntity.h | 2 +- src/Core/Entities/StationEntity.m | 9 +++++---- 4 files changed, 28 insertions(+), 21 deletions(-) diff --git a/Resources/Scripts/oolite-priorityai.js b/Resources/Scripts/oolite-priorityai.js index 7053c2fc..4d884bbf 100644 --- a/Resources/Scripts/oolite-priorityai.js +++ b/Resources/Scripts/oolite-priorityai.js @@ -2750,11 +2750,6 @@ PriorityAIController.prototype.behaviourDestroyCurrentTarget = function() // NOTE: this does not, and should not, check whether the station is friendly PriorityAIController.prototype.behaviourDockWithStation = function() { - // may need to release escorts - if (this.ship.escortGroup && this.ship.escortGroup.count > 1) - { - this.ship.dockEscorts(); - } var station = this.getParameter("oolite_dockingStation"); this.ship.target = station; var handlers = {}; @@ -2791,8 +2786,18 @@ PriorityAIController.prototype.behaviourDockWithStation = function() this.ship.performFaceDestination(); // and will reconsider in a little bit break; - case "APPROACH": case "APPROACH_COORDINATES": + if (this.ship.escortGroup && this.ship.escortGroup.count > 1) + { + // docking clearance has been granted - can now release escorts + if (this.ship.dockingInstructions.docking_stage >= 2) + { + this.communicate("oolite_dockEscorts",{},3); + this.ship.dockEscorts(); + } + } + // and fall through + case "APPROACH": case "BACK_OFF": this.ship.performFlyToRangeFromDestination(); break; @@ -6239,6 +6244,7 @@ this.startUp = function() this.$commsSettings.generic.generic.oolite_groupIsOutnumbered = "Please, let us go!"; this.$commsSettings.pirate.generic.oolite_groupIsOutnumbered = "Argh! They're tougher than they looked. Break off the attack!" this.$commsSettings.generic.generic.oolite_dockingWait = "Bored now."; + this.$commsSettings.generic.generic.oolite_dockEscorts = "I've got clearance now. Begin your own docking sequences when ready."; this.$commsSettings.generic.generic.oolite_mining = "Maybe this one has gems."; this.$commsSettings.generic.generic.oolite_quiriumCascade = "Cascade! %N! Get out of here!"; this.$commsSettings.pirate.generic.oolite_scoopedCargo = "Ah, [oolite_goodsDescription]. We should have shaken them down for more."; diff --git a/src/Core/Entities/DockEntity.m b/src/Core/Entities/DockEntity.m index 98e5789c..3b1cbae5 100644 --- a/src/Core/Entities/DockEntity.m +++ b/src/Core/Entities/DockEntity.m @@ -292,26 +292,26 @@ MA 02110-1301, USA. if (ship_distance > SCANNER_MAX_RANGE) { // too far away - don't claim a docking slot by not putting on approachlist for now. - return OOMakeDockingInstructions(station, [self absolutePositionForSubentity], [ship maxFlightSpeed], 10000, @"APPROACH", nil, NO); + return OOMakeDockingInstructions(station, [self absolutePositionForSubentity], [ship maxFlightSpeed], 10000, @"APPROACH", nil, NO, -1); } [self addShipToShipsOnApproach: ship]; if (ship_distance < 1000.0 + [station collisionRadius] + ship->collision_radius) // too close - back off - return OOMakeDockingInstructions(station, [self absolutePositionForSubentity], [ship maxFlightSpeed], 5000, @"BACK_OFF", nil, NO); + return OOMakeDockingInstructions(station, [self absolutePositionForSubentity], [ship maxFlightSpeed], 5000, @"BACK_OFF", nil, NO, -1); float dot = HPdot_product(launchVector, delta); if (dot < 0) // approaching from the wrong side of the station - construct a vector to the side of the station. { HPVector approachVector = HPcross_product(HPvector_normal(delta), launchVector); approachVector = HPcross_product(launchVector, approachVector); // vector, 90 degr rotated from launchVector towards target. - return OOMakeDockingInstructions(station, OOHPVectorTowards([self absolutePositionForSubentity], approachVector, [station collisionRadius] + 5000) , [ship maxFlightSpeed], 1000, @"APPROACH", nil, NO); + return OOMakeDockingInstructions(station, OOHPVectorTowards([self absolutePositionForSubentity], approachVector, [station collisionRadius] + 5000) , [ship maxFlightSpeed], 1000, @"APPROACH", nil, NO, -1); } if (ship_distance > 12500.0) { // long way off - approach more closely - return OOMakeDockingInstructions(station, [self absolutePositionForSubentity], [ship maxFlightSpeed], 10000, @"APPROACH", nil, NO); + return OOMakeDockingInstructions(station, [self absolutePositionForSubentity], [ship maxFlightSpeed], 10000, @"APPROACH", nil, NO, -1); } } @@ -320,7 +320,7 @@ MA 02110-1301, USA. // some error has occurred - log it, and send the try-again message OOLogERR(@"station.issueDockingInstructions.failed", @"couldn't addShipToShipsOnApproach:%@ in %@, retrying later -- shipsOnApproach:\n%@", ship, self, shipsOnApproach); - return OOMakeDockingInstructions(station, [ship position], 0, 100, @"TRY_AGAIN_LATER", nil, NO); + return OOMakeDockingInstructions(station, [ship position], 0, 100, @"TRY_AGAIN_LATER", nil, NO, -1); } @@ -332,7 +332,7 @@ MA 02110-1301, USA. { OOLogERR(@"station.issueDockingInstructions.failed", @" -- coordinatesStack = %@", coordinatesStack); - return OOMakeDockingInstructions(station, [ship position], 0, 100, @"HOLD_POSITION", nil, NO); + return OOMakeDockingInstructions(station, [ship position], 0, 100, @"HOLD_POSITION", nil, NO, -1); } // get the docking information from the instructions @@ -360,7 +360,7 @@ MA 02110-1301, USA. if ((docking_stage == 1) &&(HPmagnitude2(delta) < 1000000.0)) // 1km*1km speedAdvised *= 0.5; // half speed - return OOMakeDockingInstructions(station, coords, speedAdvised, rangeAdvised, @"APPROACH_COORDINATES", nil, NO); + return OOMakeDockingInstructions(station, coords, speedAdvised, rangeAdvised, @"APPROACH_COORDINATES", nil, NO, docking_stage); } else { @@ -412,7 +412,7 @@ MA 02110-1301, USA. //remove the previous stage from the stack [coordinatesStack removeObjectAtIndex:0]; - return OOMakeDockingInstructions(station, coords, speedAdvised, rangeAdvised, @"APPROACH_COORDINATES", nil, match_rotation); + return OOMakeDockingInstructions(station, coords, speedAdvised, rangeAdvised, @"APPROACH_COORDINATES", nil, match_rotation, docking_stage); } else { @@ -428,12 +428,12 @@ MA 02110-1301, USA. [nextCoords setObject:@"YES" forKey:@"hold_message_given"]; } - return OOMakeDockingInstructions(station, ship->position, 0, 100, @"HOLD_POSITION", nil, NO); + return OOMakeDockingInstructions(station, ship->position, 0, 100, @"HOLD_POSITION", nil, NO, -1); } } // we should never reach here. - return OOMakeDockingInstructions(station, coords, 50, 10, @"APPROACH_COORDINATES", nil, NO); + return OOMakeDockingInstructions(station, coords, 50, 10, @"APPROACH_COORDINATES", nil, NO, -1); } diff --git a/src/Core/Entities/StationEntity.h b/src/Core/Entities/StationEntity.h index 739d1312..b0ad81f5 100644 --- a/src/Core/Entities/StationEntity.h +++ b/src/Core/Entities/StationEntity.h @@ -235,4 +235,4 @@ typedef enum -NSDictionary *OOMakeDockingInstructions(StationEntity *station, HPVector coords, float speed, float range, NSString *ai_message, NSString *comms_message, BOOL match_rotation); +NSDictionary *OOMakeDockingInstructions(StationEntity *station, HPVector coords, float speed, float range, NSString *ai_message, NSString *comms_message, BOOL match_rotation, int docking_stage); diff --git a/src/Core/Entities/StationEntity.m b/src/Core/Entities/StationEntity.m index 4042a0cd..f1bc0f8d 100644 --- a/src/Core/Entities/StationEntity.m +++ b/src/Core/Entities/StationEntity.m @@ -462,7 +462,7 @@ } -NSDictionary *OOMakeDockingInstructions(StationEntity *station, HPVector coords, float speed, float range, NSString *ai_message, NSString *comms_message, BOOL match_rotation) +NSDictionary *OOMakeDockingInstructions(StationEntity *station, HPVector coords, float speed, float range, NSString *ai_message, NSString *comms_message, BOOL match_rotation, int docking_stage) { NSMutableDictionary *acc = [NSMutableDictionary dictionaryWithCapacity:8]; [acc oo_setHPVector:coords forKey:@"destination"]; @@ -470,6 +470,7 @@ NSDictionary *OOMakeDockingInstructions(StationEntity *station, HPVector coords, [acc oo_setFloat:range forKey:@"range"]; [acc setObject:[[station weakRetain] autorelease] forKey:@"station"]; [acc oo_setBool:match_rotation forKey:@"match_rotation"]; + [acc oo_setInteger:docking_stage forKey:@"docking_stage"]; if (ai_message) { [acc setObject:ai_message forKey:@"ai_message"]; @@ -496,7 +497,7 @@ NSDictionary *OOMakeDockingInstructions(StationEntity *station, HPVector coords, if ([ship isPlayer] && [ship legalStatus] > 50) // note: non-player fugitives dock as normal { // refuse docking to the fugitive player - return OOMakeDockingInstructions(self, [ship position], 0, 100, @"DOCKING_REFUSED", @"[station-docking-refused-to-fugitive]", NO); + return OOMakeDockingInstructions(self, [ship position], 0, 100, @"DOCKING_REFUSED", @"[station-docking-refused-to-fugitive]", NO, -1); } if (magnitude2(velocity) > 1.0 || @@ -581,7 +582,7 @@ NSDictionary *OOMakeDockingInstructions(StationEntity *station, HPVector coords, docking = @"TRY_AGAIN_LATER"; } // no docks accept this ship (or the player is blocking them) - return OOMakeDockingInstructions(self, [ship position], 0, 100, docking, nil, NO); + return OOMakeDockingInstructions(self, [ship position], 0, 100, docking, nil, NO, -1); } @@ -609,7 +610,7 @@ NSDictionary *OOMakeDockingInstructions(StationEntity *station, HPVector coords, [_shipsOnHold addObject:ship]; } - return OOMakeDockingInstructions(self, [ship position], 0, 100, @"HOLD_POSITION", nil, NO); + return OOMakeDockingInstructions(self, [ship position], 0, 100, @"HOLD_POSITION", nil, NO, -1); }