Improved fallback behaviour when failing to generate a station. Fixed a "Ship foo was not set up from dictionary" error when failing to create stations.

git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@1673 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
Jens Ayton 2008-06-04 18:16:50 +00:00
parent ea6fe98212
commit a95a581ac9
2 changed files with 26 additions and 5 deletions

View File

@ -744,7 +744,7 @@ static NSDictionary* instructions(int station_id, Vector coords, float speed, fl
}
}
[super setUpShipFromDictionary:dict];
if (![super setUpShipFromDictionary:dict]) return NO;
equivalentTechLevel = [dict intForKey:@"equivalent_tech_level" defaultValue:NSNotFound];
max_scavengers = [dict unsignedIntForKey:@"max_scavengers" defaultValue:3];

View File

@ -984,17 +984,38 @@ static NSComparisonResult comparePrice(NSDictionary *dict1, NSDictionary *dict2,
*/
if (![a_station isStation] || ![a_station validForAddToUniverse])
{
OOLog(@"universe.setup.badStation", @"***** ERROR: Attempt to use non-station ship of type \"%@\" for role \"%@\" as system station, trying again with \"%@\".", [a_station name], stationDesc, defaultStationDesc);
if (a_station == nil)
{
// Should have had a more specific error already, just specify context
OOLog(@"universe.setup.badStation", @"Failed to set up a ship for role \"%@\" as system station, trying again with \"%@\".", stationDesc, defaultStationDesc);
}
else
{
OOLog(@"universe.setup.badStation", @"***** ERROR: Attempt to use non-station ship of type \"%@\" for role \"%@\" as system station, trying again with \"%@\".", [a_station name], stationDesc, defaultStationDesc);
}
[a_station release];
stationDesc = defaultStationDesc;
a_station = (StationEntity *)[self newShipWithRole:stationDesc]; // retain count = 1
if (![a_station isStation] || ![a_station validForAddToUniverse])
{
OOLog(@"universe.setup.badStation", @"***** ERROR: On retry, rolled non-station ship of type \"%@\" for role \"%@\". Non-station ships should not have this role! Generating a stationless system.", [a_station name], stationDesc);
if (a_station == nil)
{
OOLog(@"universe.setup.badStation", @"On retry, failed to set up a ship for role \"%@\" as system station. Trying to fall back to built-in Coriolis station.", stationDesc);
}
else
{
OOLog(@"universe.setup.badStation", @"***** ERROR: On retry, rolled non-station ship of type \"%@\" for role \"%@\". Non-station ships should not have this role! Trying to fall back to built-in Coriolis station.", [a_station name], stationDesc);
}
[a_station release];
a_station = nil;
a_station = (StationEntity *)[self newShipWithName:@"coriolis-station"];
if (![a_station isStation] || ![a_station validForAddToUniverse])
{
OOLog(@"universe.setup.badStation", @"Could not create built-in Coriolis station! Generating a stationless system.");
[a_station release];
a_station = nil;
}
}
}