Docking ships don't release their escorts until later

This commit is contained in:
cim 2014-01-17 21:50:35 +00:00
parent 925a4035c2
commit c5a91aa8f2
4 changed files with 28 additions and 21 deletions

View File

@ -2750,11 +2750,6 @@ PriorityAIController.prototype.behaviourDestroyCurrentTarget = function()
// NOTE: this does not, and should not, check whether the station is friendly // NOTE: this does not, and should not, check whether the station is friendly
PriorityAIController.prototype.behaviourDockWithStation = function() 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"); var station = this.getParameter("oolite_dockingStation");
this.ship.target = station; this.ship.target = station;
var handlers = {}; var handlers = {};
@ -2791,8 +2786,18 @@ PriorityAIController.prototype.behaviourDockWithStation = function()
this.ship.performFaceDestination(); this.ship.performFaceDestination();
// and will reconsider in a little bit // and will reconsider in a little bit
break; break;
case "APPROACH":
case "APPROACH_COORDINATES": 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": case "BACK_OFF":
this.ship.performFlyToRangeFromDestination(); this.ship.performFlyToRangeFromDestination();
break; break;
@ -6239,6 +6244,7 @@ this.startUp = function()
this.$commsSettings.generic.generic.oolite_groupIsOutnumbered = "Please, let us go!"; 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.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_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_mining = "Maybe this one has gems.";
this.$commsSettings.generic.generic.oolite_quiriumCascade = "Cascade! %N! Get out of here!"; 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."; this.$commsSettings.pirate.generic.oolite_scoopedCargo = "Ah, [oolite_goodsDescription]. We should have shaken them down for more.";

View File

@ -292,26 +292,26 @@ MA 02110-1301, USA.
if (ship_distance > SCANNER_MAX_RANGE) if (ship_distance > SCANNER_MAX_RANGE)
{ {
// too far away - don't claim a docking slot by not putting on approachlist for now. // 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]; [self addShipToShipsOnApproach: ship];
if (ship_distance < 1000.0 + [station collisionRadius] + ship->collision_radius) // too close - back off 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); 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. 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); HPVector approachVector = HPcross_product(HPvector_normal(delta), launchVector);
approachVector = HPcross_product(launchVector, approachVector); // vector, 90 degr rotated from launchVector towards target. 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) if (ship_distance > 12500.0)
{ {
// long way off - approach more closely // 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 // 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); 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); 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 // 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 if ((docking_stage == 1) &&(HPmagnitude2(delta) < 1000000.0)) // 1km*1km
speedAdvised *= 0.5; // half speed 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 else
{ {
@ -412,7 +412,7 @@ MA 02110-1301, USA.
//remove the previous stage from the stack //remove the previous stage from the stack
[coordinatesStack removeObjectAtIndex:0]; [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 else
{ {
@ -428,12 +428,12 @@ MA 02110-1301, USA.
[nextCoords setObject:@"YES" forKey:@"hold_message_given"]; [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. // 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);
} }

View File

@ -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);

View File

@ -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]; NSMutableDictionary *acc = [NSMutableDictionary dictionaryWithCapacity:8];
[acc oo_setHPVector:coords forKey:@"destination"]; [acc oo_setHPVector:coords forKey:@"destination"];
@ -470,6 +470,7 @@ NSDictionary *OOMakeDockingInstructions(StationEntity *station, HPVector coords,
[acc oo_setFloat:range forKey:@"range"]; [acc oo_setFloat:range forKey:@"range"];
[acc setObject:[[station weakRetain] autorelease] forKey:@"station"]; [acc setObject:[[station weakRetain] autorelease] forKey:@"station"];
[acc oo_setBool:match_rotation forKey:@"match_rotation"]; [acc oo_setBool:match_rotation forKey:@"match_rotation"];
[acc oo_setInteger:docking_stage forKey:@"docking_stage"];
if (ai_message) if (ai_message)
{ {
[acc setObject:ai_message forKey:@"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 if ([ship isPlayer] && [ship legalStatus] > 50) // note: non-player fugitives dock as normal
{ {
// refuse docking to the fugitive player // 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 || if (magnitude2(velocity) > 1.0 ||
@ -581,7 +582,7 @@ NSDictionary *OOMakeDockingInstructions(StationEntity *station, HPVector coords,
docking = @"TRY_AGAIN_LATER"; docking = @"TRY_AGAIN_LATER";
} }
// no docks accept this ship (or the player is blocking them) // 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]; [_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);
} }