- Trunk only: new key added to savegame: 'target_system_name'. Needed to identify which overlapping system is being targeted when saving the game. This should fix the last of the overlapping systems oddities.

git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@3660 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
Marc 2010-07-06 00:55:54 +00:00
parent 0f26babb2d
commit 46dbbb0396
3 changed files with 42 additions and 10 deletions

View File

@ -484,8 +484,10 @@ static GLfloat sBaseMass = 0.0;
[result setObject:found_seed forKey:@"found_system_seed"];
}
// Write the name of the current system. Useful for looking up saved game information.
// Write the name of the current system. Useful for overlapping systems and for looking up saved game information.
[result setObject:[UNIVERSE getSystemName:[self system_seed]] forKey:@"current_system_name"];
// Write the name of the targeted system. Useful for overlapping systems.
[result setObject:[UNIVERSE getSystemName:[self target_system_seed]] forKey:@"target_system_name"];
[result setObject:player_name forKey:@"player_name"];
@ -914,20 +916,30 @@ static GLfloat sBaseMass = 0.0;
aft_shield = [self maxAftShieldLevel];
// Where are we? What system are we targeting?
BOOL sameCoords = (cursor_coordinates.x == galaxy_coordinates.x && cursor_coordinates.y == galaxy_coordinates.y);
// current_system_name and target_system_name, if present on the savegame,
// are the only way - at present - to distinguish between overlapping systems. Kaks 20100706
system_seed = [UNIVERSE findSystemAtCoords:galaxy_coordinates withGalaxySeed:galaxy_seed];
NSString *sysName = [UNIVERSE getSystemName:[self system_seed]];
// Should we be in the other overlapping system? TODO: find the right system_seed in a better way.
if (![sysName isEqualToString:[dict oo_stringForKey:@"current_system_name"]])
// If we have the current system name, let's see if it matches the current system.
NSString *sysName = [dict oo_stringForKey:@"current_system_name"];
system_seed = [UNIVERSE findSystemFromName:sysName];
if (is_nil_seed(system_seed) || (galaxy_coordinates.x != system_seed.d && galaxy_coordinates.y != system_seed.b))
{
galaxy_coordinates.y+=0.1;
// no match found, find the system from the coordinates.
system_seed = [UNIVERSE findSystemAtCoords:galaxy_coordinates withGalaxySeed:galaxy_seed];
}
if (sameCoords) target_system_seed = system_seed;
else target_system_seed = [UNIVERSE findSystemAtCoords:cursor_coordinates withGalaxySeed:galaxy_seed];
// If we have a target system name, let's see if it matches the system at the cursor coordinates.
sysName = [dict oo_stringForKey:@"target_system_name"];
target_system_seed = [UNIVERSE findSystemFromName:sysName];
if (is_nil_seed(target_system_seed) || (cursor_coordinates.x != target_system_seed.d && cursor_coordinates.y != target_system_seed.b))
{
// no match found, find the system from the coordinates.
BOOL sameCoords = (cursor_coordinates.x == galaxy_coordinates.x && cursor_coordinates.y == galaxy_coordinates.y);
if (sameCoords) target_system_seed = system_seed;
else target_system_seed = [UNIVERSE findSystemAtCoords:cursor_coordinates withGalaxySeed:galaxy_seed];
}
#if WORMHOLE_SCANNER
// wormholes

View File

@ -532,6 +532,7 @@ enum
- (NSString *) generateSystemInhabitants:(Random_Seed) s_seed plural:(BOOL)plural;
- (NSPoint) coordinatesForSystem:(Random_Seed)s_seed;
- (Random_Seed) findSystemAtCoords:(NSPoint) coords withGalaxySeed:(Random_Seed) gal_seed;
- (Random_Seed) findSystemFromName:(NSString *) sysName;
/**
* Finds systems within range. If range is greater than 7.0LY then only look within 7.0LY.

View File

@ -6568,6 +6568,25 @@ static NSDictionary *sCachedSystemData = nil;
}
- (Random_Seed) findSystemFromName:(NSString *) sysName
{
if (sysName == nil) return kNilRandomSeed; // no match found!
NSString *system_name = nil;
NSString *match = [sysName lowercaseString];
int i;
for (i = 0; i < 256; i++)
{
system_name = [system_names[i] lowercaseString];
if ([system_name isEqualToString:match])
{
return systems[i];
}
}
return kNilRandomSeed; // no match found!
}
- (Random_Seed) findSystemAtCoords:(NSPoint) coords withGalaxySeed:(Random_Seed) gal_seed
{
return systems[[self findSystemNumberAtCoords:coords withGalaxySeed:gal_seed]];