From a95a581ac9b385fc36b563c87a746abeca2429af Mon Sep 17 00:00:00 2001 From: Jens Ayton Date: Wed, 4 Jun 2008 18:16:50 +0000 Subject: [PATCH] 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 --- src/Core/Entities/StationEntity.m | 2 +- src/Core/Universe.m | 29 +++++++++++++++++++++++++---- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/Core/Entities/StationEntity.m b/src/Core/Entities/StationEntity.m index 970624b1..c3b6ec4b 100644 --- a/src/Core/Entities/StationEntity.m +++ b/src/Core/Entities/StationEntity.m @@ -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]; diff --git a/src/Core/Universe.m b/src/Core/Universe.m index 84ce7e9a..9bc44e47 100644 --- a/src/Core/Universe.m +++ b/src/Core/Universe.m @@ -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; + } } }