Change allowPlayerDocking to disallowedDockingCollides (with approximately reversed meaning)

Fix some bugs with player docking clearance in new docking code
Disable logging of "ship could not launch because there aren't any launch docks"


git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@5130 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
Chris Morris 2012-07-24 16:51:28 +00:00
parent 002cbddf0a
commit 37703e68c3
7 changed files with 90 additions and 48 deletions

View File

@ -704,6 +704,20 @@
"Negative. Your ship cannot dock here.",
"Docking clearance denied."
);
"station-docking-clearance-denied-no-docks" =
(
"Docking clearance refused to all vessels.",
"Docking is not allowed at this station.",
"Negative. Your ship cannot dock here.",
"Docking clearance denied."
);
"station-docking-clearance-denied-no-docks-yet" =
(
"Docking clearance is refused at this time.",
"Docking bays are closed. Please come back later.",
"We do not have any docks open at this time.",
"Docking clearance denied."
);
"station-docking-clearance-granted-until-@" =
(
"You are cleared to dock. Please proceed. Clearance expires at %@",

View File

@ -408,7 +408,8 @@
startup.progress = no; // Startup progress stages. These are shown on-screen on Macs and of little interest otherwise.
station.launchShip.impossible = no; // generally cancelled launches due to station having no launch docks are uninteresting
strings.conversion = $scriptError; // Conversion of text to values (vectors, quaternions etc)
strings.conversion.vector = inherit;

View File

@ -221,14 +221,10 @@ MA 02110-1301, USA.
- (NSString*) canAcceptShipForDocking:(ShipEntity *) ship
{
// First test permanent rejection reasons
if (!allow_docking && (![ship isPlayer] || !allow_player_docking))
if (!allow_docking)
{
return @"DOCK_CLOSED"; // could be temp or perm reject
}
if (!allow_player_docking && [ship isPlayer])
{
return @"TOO_BIG_TO_DOCK"; // player always gets perm-reject in this case
}
BoundingBox bb = [ship totalBoundingBox];
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)))
@ -643,15 +639,10 @@ MA 02110-1301, USA.
BOOL allow_docking_thisship = allow_docking;
if (!allow_docking && allow_player_docking)
{
// player can dock here
allow_docking_thisship = YES;
// other ships also allowed to dock here, but will never be directed
// here by traffic control
}
else if (allow_docking && !allow_player_docking && [ship isPlayer])
{
// player cannot dock here
allow_docking_thisship = NO;
// ships can physically dock here, and this routine is mainly for
// collision detection, but will never be directed here by traffic
// control
}
StationEntity *station = (StationEntity *)[self parentEntity];
@ -784,20 +775,9 @@ MA 02110-1301, USA.
- (void) pullInShipIfPermitted:(ShipEntity *)ship
{
BOOL allow_docking_thisship = allow_docking;
if (!allow_docking && allow_player_docking)
{
// player can dock here
allow_docking_thisship = YES;
// other ships also allowed to dock here, but will never be directed
// here by traffic control
}
else if (allow_docking && !allow_player_docking && [ship isPlayer])
{
// player cannot dock here
allow_docking_thisship = NO;
}
if (allow_docking_thisship)
// allow_docking: docking permitted and expected
// allow_player_docking: unauthorised docking does not result in explosion
if (allow_docking || allow_player_docking)
{
[ship enterDock:(StationEntity*)[self parentEntity]];
}

View File

@ -845,7 +845,8 @@ static ShipEntity *doOctreesCollide(ShipEntity *prime, ShipEntity *other);
if (!asTurret && [self isStation] && [subentDict oo_boolForKey:@"is_dock"])
{
BOOL allow_docking = [subentDict oo_boolForKey:@"allow_docking" defaultValue:YES];
BOOL allow_player = [subentDict oo_boolForKey:@"allow_player_docking" defaultValue:YES];
// note the inversion at this point
BOOL allow_player = ![subentDict oo_boolForKey:@"disallowed_docking_collides" defaultValue:NO];
BOOL allow_launching = [subentDict oo_boolForKey:@"allow_launching" defaultValue:YES];
// do not include this key in OOShipRegistry; should never be set by shipdata
BOOL virtual_dock = [subentDict oo_boolForKey:@"_is_virtual_dock" defaultValue:NO];

View File

@ -646,7 +646,7 @@ NSDictionary *OOMakeDockingInstructions(StationEntity *station, Vector coords, f
[virtualDockDict oo_setBool:YES forKey:@"is_dock"];
[virtualDockDict setObject:@"the docking bay" forKey:@"dock_label"];
[virtualDockDict oo_setBool:YES forKey:@"allow_docking"];
[virtualDockDict oo_setBool:YES forKey:@"allow_player_docking"];
[virtualDockDict oo_setBool:NO forKey:@"disallowed_docking_collides"];
[virtualDockDict oo_setBool:YES forKey:@"allow_launching"];
[virtualDockDict oo_setBool:YES forKey:@"_is_virtual_dock"];
@ -913,7 +913,7 @@ NSDictionary *OOMakeDockingInstructions(StationEntity *station, Vector coords, f
DockEntity* sub = nil;
for (subEnum = [self dockSubEntityEnumerator]; (sub = [subEnum nextObject]); )
{
if ([sub allowsPlayerDocking] && [sub countOfShipsInLaunchQueue] == 0 && [sub countOfShipsInDockingQueue] == 0)
if ([sub allowsDocking] && [sub countOfShipsInLaunchQueue] == 0 && [sub countOfShipsInDockingQueue] == 0)
{
return YES;
}
@ -944,7 +944,7 @@ NSDictionary *OOMakeDockingInstructions(StationEntity *station, Vector coords, f
DockEntity* sub = nil;
for (subEnum = [self dockSubEntityEnumerator]; (sub = [subEnum nextObject]); )
{
if ([sub allowsPlayerDocking] && [sub countOfShipsInLaunchQueue] == 0 && [sub countOfShipsInDockingQueue] == 0)
if ([sub allowsDocking] && [sub countOfShipsInLaunchQueue] == 0 && [sub countOfShipsInDockingQueue] == 0)
{
return sub;
}
@ -1253,7 +1253,7 @@ NSDictionary *OOMakeDockingInstructions(StationEntity *station, Vector coords, f
{
if (![self hasLaunchDock])
{
OOLog(@"station.launchShip.failed", @"Cancelled launch for a ship with role %@, as the %@ has no launch docks.",
OOLog(@"station.launchShip.impossible", @"Cancelled launch for a ship with role %@, as the %@ has no launch docks.",
role, [self displayName]);
return nil;
}
@ -1412,7 +1412,7 @@ NSDictionary *OOMakeDockingInstructions(StationEntity *station, Vector coords, f
{
if (![self hasLaunchDock])
{
OOLog(@"station.launchShip.failed", @"Cancelled launch for a police ship, as the %@ has no launch docks.",
OOLog(@"station.launchShip.impossible", @"Cancelled launch for a police ship, as the %@ has no launch docks.",
[self displayName]);
return [NSArray array];
}
@ -1477,7 +1477,7 @@ NSDictionary *OOMakeDockingInstructions(StationEntity *station, Vector coords, f
{
if (![self hasLaunchDock])
{
OOLog(@"station.launchShip.failed", @"Cancelled launch for a defense ship, as the %@ has no launch docks.",
OOLog(@"station.launchShip.impossible", @"Cancelled launch for a defense ship, as the %@ has no launch docks.",
[self displayName]);
return nil;
}
@ -1582,7 +1582,7 @@ NSDictionary *OOMakeDockingInstructions(StationEntity *station, Vector coords, f
{
if (![self hasLaunchDock])
{
OOLog(@"station.launchShip.failed", @"Cancelled launch for a scavenger ship, as the %@ has no launch docks.",
OOLog(@"station.launchShip.impossible", @"Cancelled launch for a scavenger ship, as the %@ has no launch docks.",
[self displayName]);
return nil;
}
@ -1627,7 +1627,7 @@ NSDictionary *OOMakeDockingInstructions(StationEntity *station, Vector coords, f
{
if (![self hasLaunchDock])
{
OOLog(@"station.launchShip.failed", @"Cancelled launch for a miner ship, as the %@ has no launch docks.",
OOLog(@"station.launchShip.impossible", @"Cancelled launch for a miner ship, as the %@ has no launch docks.",
[self displayName]);
return nil;
}
@ -1676,7 +1676,7 @@ NSDictionary *OOMakeDockingInstructions(StationEntity *station, Vector coords, f
{
if ([self hasLaunchDock])
{
OOLog(@"station.launchShip.failed", @"Cancelled launch for a pirate ship, as the %@ has no launch docks.",
OOLog(@"station.launchShip.impossible", @"Cancelled launch for a pirate ship, as the %@ has no launch docks.",
[self displayName]);
return nil;
}
@ -1737,7 +1737,7 @@ NSDictionary *OOMakeDockingInstructions(StationEntity *station, Vector coords, f
{
if (![self hasLaunchDock])
{
OOLog(@"station.launchShip.failed", @"Cancelled launch for a shuttle ship, as the %@ has no launch docks.",
OOLog(@"station.launchShip.impossible", @"Cancelled launch for a shuttle ship, as the %@ has no launch docks.",
[self displayName]);
return nil;
}
@ -1775,7 +1775,7 @@ NSDictionary *OOMakeDockingInstructions(StationEntity *station, Vector coords, f
{
if (![self hasLaunchDock])
{
OOLog(@"station.launchShip.failed", @"Cancelled launch for an escort ship, as the %@ has no launch docks.",
OOLog(@"station.launchShip.impossible", @"Cancelled launch for an escort ship, as the %@ has no launch docks.",
[self displayName]);
return;
}
@ -1805,7 +1805,7 @@ NSDictionary *OOMakeDockingInstructions(StationEntity *station, Vector coords, f
{
if (![self hasLaunchDock])
{
OOLog(@"station.launchShip.failed", @"Cancelled launch for a patrol ship, as the %@ has no launch docks.",
OOLog(@"station.launchShip.impossible", @"Cancelled launch for a patrol ship, as the %@ has no launch docks.",
[self displayName]);
return nil;
}
@ -1861,7 +1861,7 @@ NSDictionary *OOMakeDockingInstructions(StationEntity *station, Vector coords, f
{
if (![self hasLaunchDock])
{
OOLog(@"station.launchShip.failed", @"Cancelled launch for a ship with role %@, as the %@ has no launch docks.",
OOLog(@"station.launchShip.impossible", @"Cancelled launch for a ship with role %@, as the %@ has no launch docks.",
role, [self displayName]);
return;
}
@ -2039,6 +2039,52 @@ NSDictionary *OOMakeDockingInstructions(StationEntity *station, Vector coords, f
// No need to set status to REQUESTED as we've already done that earlier.
result = @"DOCKING_CLEARANCE_DENIED_TRAFFIC_OUTBOUND";
}
if (result == nil)
{
// if this happens, the station has no docks which allow
// docking, so deny clearance
if ([other isPlayer])
{
[player setDockingClearanceStatus:DOCKING_CLEARANCE_STATUS_NONE];
}
result = @"DOCKING_CLEARANCE_DENIED_NO_DOCKS";
// but can check to see if we'll open some for later.
NSEnumerator *subEnum = nil;
DockEntity* sub = nil;
BOOL openLater = NO;
for (subEnum = [self dockSubEntityEnumerator]; (sub = [subEnum nextObject]); )
{
NSString *docking = [sub canAcceptShipForDocking:other];
if ([docking isEqualToString:@"DOCK_CLOSED"])
{
JSContext *context = OOJSAcquireContext();
jsval rval = JSVAL_VOID;
jsval args[] = { OOJSValueFromNativeObject(context, sub),
OOJSValueFromNativeObject(context, other) };
JSBool tempreject = NO;
BOOL OK = [[self script] callMethod:OOJSID("willOpenDockingPortFor") inContext:context withArguments:args count:2 result:&rval];
if (OK) OK = JS_ValueToBoolean(context, rval, &tempreject);
if (!OK) tempreject = NO; // default to permreject
if (tempreject)
{
openLater = YES;
}
OOJSRelinquishContext(context);
}
if (openLater) break;
}
if (openLater)
{
[self sendExpandedMessage:DESC(@"station-docking-clearance-denied-no-docks-yet") toShip:other];
}
else
{
[self sendExpandedMessage:DESC(@"station-docking-clearance-denied-no-docks") toShip:other];
}
}
}
// Ship has passed all checks - grant docking!

View File

@ -1431,11 +1431,11 @@ static NSString * const kDefaultDemoShip = @"coriolis-station";
[result setObject:docklabel forKey:@"dock_label"];
BOOL dockable = [declaration oo_boolForKey:@"allow_docking" defaultValue:YES];
BOOL playerdockable = [declaration oo_boolForKey:@"allow_player_docking" defaultValue:dockable];
BOOL playerdockable = [declaration oo_boolForKey:@"disallowed_docking_collides" defaultValue:NO];
BOOL undockable = [declaration oo_boolForKey:@"allow_launching" defaultValue:YES];
[result oo_setBool:dockable forKey:@"allow_docking"];
[result oo_setBool:playerdockable forKey:@"allow_player_docking"];
[result oo_setBool:playerdockable forKey:@"disallowed_docking_collides"];
[result oo_setBool:undockable forKey:@"allow_launching"];
}

View File

@ -61,7 +61,7 @@ enum
{
// Property IDs
kDock_allowsDocking,
kDock_allowsPlayerDocking,
kDock_disallowedDockingCollides,
kDock_allowsLaunching,
kDock_dockingQueueLength,
kDock_launchingQueueLength
@ -72,7 +72,7 @@ static JSPropertySpec sDockProperties[] =
{
// JS name ID flags
{ "allowsDocking", kDock_allowsDocking, OOJS_PROP_READWRITE_CB },
{ "allowsPlayerDocking", kDock_allowsPlayerDocking, OOJS_PROP_READONLY_CB },
{ "disallowedDockingCollides", kDock_disallowedDockingCollides, OOJS_PROP_READONLY_CB },
{ "allowsLaunching", kDock_allowsLaunching, OOJS_PROP_READWRITE_CB },
{ "dockingQueueLength", kDock_dockingQueueLength, OOJS_PROP_READONLY_CB },
{ "launchingQueueLength", kDock_launchingQueueLength, OOJS_PROP_READONLY_CB },
@ -151,8 +151,8 @@ static JSBool DockGetProperty(JSContext *context, JSObject *this, jsid propID, j
*value = OOJSValueFromBOOL([entity allowsDocking]);
return YES;
case kDock_allowsPlayerDocking:
*value = OOJSValueFromBOOL([entity allowsPlayerDocking]);
case kDock_disallowedDockingCollides:
*value = OOJSValueFromBOOL(![entity allowsPlayerDocking]);
return YES;
case kDock_allowsLaunching: