* Fix crash bug with Wormholes when loading a saved-game containing ships from removed OXPs
* Fixed bug in [OORoleSet anyRole] not returning a role if _roles had not been initialised yet. * Fixed potential problem in OORoleSet when reinitialising an existing OORoleSet object git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@2289 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
parent
b1ecf44f55
commit
0a97d1b193
@ -31,6 +31,8 @@ MA 02110-1301, USA.
|
||||
|
||||
#import "Universe.h"
|
||||
#import "AI.h"
|
||||
#import "OORoleSet.h"
|
||||
#import "OOShipRegistry.h"
|
||||
#import "OOStringParsing.h"
|
||||
#import "OOCollectionExtractors.h"
|
||||
|
||||
@ -79,6 +81,8 @@ static void DrawWormholeCorona(GLfloat inner_radius, GLfloat outer_radius, int s
|
||||
|
||||
if ([self init])
|
||||
{
|
||||
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
origin = RandomSeedFromString([dict stringForKey:@"origin_seed"]);
|
||||
destination = RandomSeedFromString([dict stringForKey:@"dest_seed"]);
|
||||
|
||||
@ -103,16 +107,43 @@ static void DrawWormholeCorona(GLfloat inner_radius, GLfloat outer_radius, int s
|
||||
while ((currShipDict = [shipDicts nextObject]) != nil)
|
||||
{
|
||||
double time = [currShipDict doubleForKey:@"time_delta"];
|
||||
NSMutableDictionary * myShipDict = [currShipDict objectForKey:@"ship"];
|
||||
NSDictionary * myShipDict = [currShipDict objectForKey:@"ship"];
|
||||
ShipEntity * ship = [ShipEntity alloc];
|
||||
[ship initWithDictionary:myShipDict];
|
||||
ship = [ship initWithDictionary:myShipDict];
|
||||
// MKW 20090815 - Check to make sure the ship loaded ok - if not, let's try to load
|
||||
// a compatible alternative.
|
||||
if( !ship )
|
||||
{
|
||||
OOLog(@"wormhole.load.warning", @"Ship '%@' failed to initialize - missing OXP? Attempting to replace with random ship using roles '%@'.",
|
||||
[myShipDict stringForKey:@"name"], [myShipDict stringForKey:@"roles"]);
|
||||
OORoleSet * roleSet = [OORoleSet roleSetWithString:[myShipDict stringForKey:@"roles"]];
|
||||
NSString * shipRole = [roleSet anyRole];
|
||||
NSString * shipKey = [[OOShipRegistry sharedRegistry] randomShipKeyForRole:shipRole];
|
||||
if( shipKey )
|
||||
{
|
||||
ship = [ShipEntity alloc];
|
||||
myShipDict = [[OOShipRegistry sharedRegistry] shipInfoForKey:shipKey];
|
||||
ship = [ship initWithDictionary:myShipDict];
|
||||
}
|
||||
if( ship )
|
||||
{
|
||||
OOLog(@"wormhole.load.warning", @"Loaded alternative ship '%@' with role '%@'.",
|
||||
[ship name], shipRole);
|
||||
}
|
||||
else
|
||||
{
|
||||
OOLog(@"wormhole.load.warning", @"Failed to load alternative ship - skipping Wormhole ship.");
|
||||
}
|
||||
}
|
||||
|
||||
[shipsInTransit addObject:[NSDictionary dictionaryWithObjectsAndKeys:
|
||||
ship, @"ship",
|
||||
[NSNumber numberWithDouble:time], @"time",
|
||||
nil]];
|
||||
|
||||
[ship release];
|
||||
if( ship )
|
||||
{
|
||||
[shipsInTransit addObject:[NSDictionary dictionaryWithObjectsAndKeys:
|
||||
ship, @"ship",
|
||||
[NSNumber numberWithDouble:time], @"time",
|
||||
nil]];
|
||||
[ship release];
|
||||
}
|
||||
/*
|
||||
[shipsInTransit addObject:[NSDictionary dictionaryWithObjectsAndKeys:
|
||||
[NSNumber numberWithDouble:[currShipDict doubleForKey:@"time_delta"]], @"time",
|
||||
@ -120,6 +151,7 @@ static void DrawWormholeCorona(GLfloat inner_radius, GLfloat outer_radius, int s
|
||||
nil]];
|
||||
*/
|
||||
}
|
||||
[pool release];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
@ -220,7 +220,7 @@ SOFTWARE.
|
||||
selected = randf() * _totalProb;
|
||||
prob = 0.0f;
|
||||
|
||||
if ([_roles count] == 0) return nil;
|
||||
if ([_rolesAndProbabilities count] == 0) return nil;
|
||||
|
||||
for (roleEnum = [_rolesAndProbabilities keyEnumerator]; (role = [roleEnum nextObject]); )
|
||||
{
|
||||
@ -297,6 +297,18 @@ SOFTWARE.
|
||||
if ([super init] == nil) return nil;
|
||||
|
||||
// Note: _roles and _roleString are derived on the fly as needed.
|
||||
// MKW 20090815 - if we are re-initialising this OORoleSet object, we need
|
||||
// to ensure that _roles and _roleString are cleared.
|
||||
if( _roles )
|
||||
{
|
||||
[_roles release];
|
||||
_roles = nil;
|
||||
}
|
||||
if( _roleString )
|
||||
{
|
||||
[_roleString release];
|
||||
_roleString = nil;
|
||||
}
|
||||
_rolesAndProbabilities = [dict copy];
|
||||
|
||||
for (roleEnum = [dict keyEnumerator]; (role = [roleEnum nextObject]); )
|
||||
|
Loading…
x
Reference in New Issue
Block a user