Fix bug where subents of stations might themselves be stations

This commit is contained in:
cim 2013-09-10 19:17:12 +01:00
parent 52b6c2b8ab
commit 6469d8ae7b
4 changed files with 41 additions and 6 deletions

View File

@ -803,7 +803,7 @@ static ShipEntity *doOctreesCollide(ShipEntity *prime, ShipEntity *other);
} }
else else
{ {
subentity = [UNIVERSE newShipWithName:subentKey]; subentity = [UNIVERSE newSubentityWithName:subentKey];
} }
if (subentity == nil) { if (subentity == nil) {
OOLog(@"setup.ship.badEntry.subentities",@"Failed to set up entity %@",subentKey); OOLog(@"setup.ship.badEntry.subentities",@"Failed to set up entity %@",subentKey);

View File

@ -722,8 +722,21 @@ NSDictionary *OOMakeDockingInstructions(StationEntity *station, Vector coords, f
{ {
return NO; return NO;
} }
// and now check for docks
NSEnumerator *subEnum = nil; NSEnumerator *subEnum = nil;
#ifndef NDEBUG
ShipEntity *subEntity = nil;
for (subEnum = [self shipSubEntityEnumerator]; (subEntity = [subEnum nextObject]); )
{
if ([subEntity isStation])
{
OOLog(@"setup.ship.badType.subentities",@"Subentity %@ (%@) of station %@ is itself a StationEntity. This is an internal error - please report it. ",subEntity,[subEntity shipDataKey],[self displayName]);
}
}
#endif
// and now check for docks
DockEntity *sub = nil; DockEntity *sub = nil;
for (subEnum = [self dockSubEntityEnumerator]; (sub = [subEnum nextObject]); ) for (subEnum = [self dockSubEntityEnumerator]; (sub = [subEnum nextObject]); )
{ {
@ -1089,7 +1102,7 @@ NSDictionary *OOMakeDockingInstructions(StationEntity *station, Vector coords, f
} }
OOLog(@"station.launchShip.failed", @"Cancelled launch for a %@ with role %@, as it is too large for the docking port of the %@.", OOLog(@"station.launchShip.failed", @"Cancelled launch for a %@ with role %@, as it is too large for the docking port of the %@.",
[ship displayName], [ship primaryRole], [self displayName]); [ship displayName], [ship primaryRole], self);
return NO; return NO;
} }

View File

@ -409,9 +409,11 @@ enum
- (NSString *) randomShipKeyForRoleRespectingConditions:(NSString *)role; - (NSString *) randomShipKeyForRoleRespectingConditions:(NSString *)role;
- (ShipEntity *) newShipWithRole:(NSString *)role OO_RETURNS_RETAINED; // Selects ship using role weights, applies auto_ai, respects conditions - (ShipEntity *) newShipWithRole:(NSString *)role OO_RETURNS_RETAINED; // Selects ship using role weights, applies auto_ai, respects conditions
- (ShipEntity *) newShipWithName:(NSString *)shipKey OO_RETURNS_RETAINED; // Does not apply auto_ai or respect conditions - (ShipEntity *) newShipWithName:(NSString *)shipKey OO_RETURNS_RETAINED; // Does not apply auto_ai or respect conditions
- (ShipEntity *) newSubentityWithName:(NSString *)shipKey OO_RETURNS_RETAINED; // Does not apply auto_ai or respect conditions
- (OOVisualEffectEntity *) newVisualEffectWithName:(NSString *)effectKey OO_RETURNS_RETAINED; - (OOVisualEffectEntity *) newVisualEffectWithName:(NSString *)effectKey OO_RETURNS_RETAINED;
- (DockEntity *) newDockWithName:(NSString *)shipKey OO_RETURNS_RETAINED; // Does not apply auto_ai or respect conditions - (DockEntity *) newDockWithName:(NSString *)shipKey OO_RETURNS_RETAINED; // Does not apply auto_ai or respect conditions
- (ShipEntity *) newShipWithName:(NSString *)shipKey usePlayerProxy:(BOOL)usePlayerProxy OO_RETURNS_RETAINED; // If usePlayerProxy, non-carriers are instantiated as ProxyPlayerEntity. - (ShipEntity *) newShipWithName:(NSString *)shipKey usePlayerProxy:(BOOL)usePlayerProxy OO_RETURNS_RETAINED; // If usePlayerProxy, non-carriers are instantiated as ProxyPlayerEntity.
- (ShipEntity *) newShipWithName:(NSString *)shipKey usePlayerProxy:(BOOL)usePlayerProxy isSubentity:(BOOL)isSubentity OO_RETURNS_RETAINED;
- (Class) shipClassForShipDictionary:(NSDictionary *)dict; - (Class) shipClassForShipDictionary:(NSDictionary *)dict;

View File

@ -2862,7 +2862,19 @@ static BOOL IsFriendlyStationPredicate(Entity *entity, void *parameter)
} }
- (ShipEntity *) newSubentityWithName:(NSString *)shipKey
{
return [self newShipWithName:shipKey usePlayerProxy:NO isSubentity:YES];
}
- (ShipEntity *) newShipWithName:(NSString *)shipKey usePlayerProxy:(BOOL)usePlayerProxy - (ShipEntity *) newShipWithName:(NSString *)shipKey usePlayerProxy:(BOOL)usePlayerProxy
{
return [self newShipWithName:shipKey usePlayerProxy:usePlayerProxy isSubentity:NO];
}
- (ShipEntity *) newShipWithName:(NSString *)shipKey usePlayerProxy:(BOOL)usePlayerProxy isSubentity:(BOOL)isSubentity
{ {
OOJS_PROFILE_ENTER OOJS_PROFILE_ENTER
@ -2872,10 +2884,18 @@ static BOOL IsFriendlyStationPredicate(Entity *entity, void *parameter)
shipDict = [[OOShipRegistry sharedRegistry] shipInfoForKey:shipKey]; shipDict = [[OOShipRegistry sharedRegistry] shipInfoForKey:shipKey];
if (shipDict == nil) return nil; if (shipDict == nil) return nil;
volatile Class shipClass = [self shipClassForShipDictionary:shipDict]; volatile Class shipClass = nil;
if (usePlayerProxy && shipClass == [ShipEntity class]) if (isSubentity)
{ {
shipClass = [ProxyPlayerEntity class]; shipClass = [ShipEntity class];
}
else
{
shipClass = [self shipClassForShipDictionary:shipDict];
if (usePlayerProxy && shipClass == [ShipEntity class])
{
shipClass = [ProxyPlayerEntity class];
}
} }
@try @try