* sun_radius loop bug: should now cope with all sun_radius values. Plus clamped sun_radius to a min and max value and added 'bad sun settings' warning.

* updated paging code ('more ->') to be more consistent across screens.
* minor mac code cleanup

git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@2257 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
Marc 2009-07-24 18:42:53 +00:00
parent 84bd4b5d90
commit 6fab208475
4 changed files with 46 additions and 19 deletions

View File

@ -299,17 +299,15 @@ static NSString * kOOLogKeyDown = @"input.keyMapping.keyPress.keyDown";
unsigned char *blue = (unsigned char *) malloc( nPixels);
NSString *filepath = [[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent];
int imageNo = 1;
NSString *pathToPic = [filepath stringByAppendingPathComponent:[NSString stringWithFormat:@"oolite-%03d.png",imageNo]];
int imageNo = 0;
NSString *pathToPic;
while ([[NSFileManager defaultManager] fileExistsAtPath:pathToPic])
do
{
imageNo++;
pathToPic = [filepath stringByAppendingPathComponent:[NSString stringWithFormat:@"oolite-%03d.png",imageNo]];
}
NSString *pathToPng = [[pathToPic stringByDeletingPathExtension] stringByAppendingPathExtension:@"png"];
} while ([[NSFileManager defaultManager] fileExistsAtPath:pathToPic])
OOLog(@"snapshot", @">>>>> Snapshot %d x %d file path chosen = %@", w, h, pathToPic);
NSBitmapImageRep* bitmapRep =
@ -345,7 +343,7 @@ static NSString * kOOLogKeyDown = @"input.keyMapping.keyPress.keyDown";
}
[[bitmapRep representationUsingType:NSPNGFileType properties:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], NSImageInterlaced, NULL]]
writeToFile:pathToPng atomically:YES]; // save PNG representation of Image
writeToFile:pathToPic atomically:YES]; // save PNG representation of Image
// free allocated objects and memory
[bitmapRep release];

View File

@ -607,7 +607,7 @@ static NSString * const kOOLogNoteShowShipyardModel = @"script.debug.note.showSh
{
NSDictionary* passenger_info = [passenger_market dictionaryAtIndex:i];
NSString *Name = [passenger_info stringForKey:PASSENGER_KEY_NAME];
if([Name length] >26) Name =[[Name substringToIndex:25] stringByAppendingString:@"..."];
if([Name length] >27) Name =[[Name substringToIndex:25] stringByAppendingString:@"..."];
int dest_eta = [passenger_info doubleForKey:PASSENGER_KEY_ARRIVAL_TIME] - ship_clock;
[row_info removeAllObjects];
[row_info addObject:[NSString stringWithFormat:@" %@ ",Name]];

View File

@ -201,6 +201,7 @@
if ([gameView isDown:gvArrowKeyLeft] && [[gui keyForRow:BACKROW] isEqual: GUI_KEY_OK])
{
currentPage--;
[self playMenuPagePrevious];
[self lsCommanders: gui directory: dir pageNumber: currentPage highlightName: nil];
[gameView supressKeysUntilKeyUp];
}
@ -208,6 +209,7 @@
if ([gameView isDown:gvArrowKeyRight] && [[gui keyForRow:MOREROW] isEqual: GUI_KEY_OK])
{
currentPage++;
[self playMenuPageNext];
[self lsCommanders: gui directory: dir pageNumber: currentPage highlightName: nil];
[gameView supressKeysUntilKeyUp];
}
@ -783,6 +785,7 @@
if (page)
{
[gui setColor:[OOColor greenColor] forRow:STARTROW-1];
[gui setArray:[NSArray arrayWithObjects:DESC(@"gui-back"), @" <-- ", nil]
forRow:STARTROW-1];
[gui setKey:GUI_KEY_OK forRow:STARTROW-1];
@ -799,6 +802,7 @@
else
{
lastIndex=(page * NUMROWS) + NUMROWS;
[gui setColor:[OOColor greenColor] forRow:ENDROW];
[gui setArray:[NSArray arrayWithObjects:DESC(@"gui-more"), @" --> ", nil]
forRow:ENDROW];
[gui setKey:GUI_KEY_OK forRow:ENDROW];

View File

@ -553,11 +553,11 @@ static OOComparisonResult comparePrice(id dict1, id dict2, void * context);
activeWormholes = [[NSMutableArray arrayWithCapacity:16] retain];
[characterPool removeAllObjects];
[self setUpSpace];
// these lines are needed here to reset systeminfo and long range chart properly
[localPlanetInfoOverrides removeAllObjects];
[self setUpSpace];
[self setGalaxy_seed: [player galaxy_seed] andReinit:YES];
system_seed = [self findSystemAtCoords:[player galaxy_coordinates] withGalaxySeed:galaxy_seed];
@ -900,7 +900,7 @@ static OOComparisonResult comparePrice(id dict1, id dict2, void * context);
Vector vf;
NSDictionary *systeminfo = [self generateSystemData:system_seed];
NSDictionary *systeminfo = [self generateSystemData:system_seed useCache:NO];
unsigned techlevel = [systeminfo unsignedIntForKey:KEY_TECHLEVEL];
NSString *stationDesc = nil, *defaultStationDesc = nil;
OOColor *bgcolor;
@ -957,17 +957,36 @@ static OOComparisonResult comparePrice(id dict1, id dict2, void * context);
seed_for_planet_description(system_seed);
/*- space sun -*/
double sunDistanceModifier;
sunDistanceModifier = [systeminfo nonNegativeDoubleForKey:@"sun_distance_modifier" defaultValue:20.0];
double sun_distance = (sunDistanceModifier + (Ranrot() % 5) - (Ranrot() % 5) ) * planet_radius;
double sun_radius;
double sun_distance;
double sunDistanceModifier;
double safeDistance;
int posIterator=0;
id dict_object;
Quaternion q_sun;
Vector sunPos;
sun_radius = [systeminfo nonNegativeDoubleForKey:@"sun_radius" defaultValue:(2.5 + randf() - randf() ) * planet_radius];
if(sun_radius > 250000) sun_distance += sun_radius; // To avoid an unresolvable while loop. 241920 m is the highest possible in-game generated sun_radius.
// clamp the sun radius
if (sun_radius < 1000.0) sun_radius = 1000.0;
if (sun_radius > 1000000.0) sun_radius = 1000000.0;
sunDistanceModifier = [systeminfo nonNegativeDoubleForKey:@"sun_distance_modifier" defaultValue:20.0];
// Any smaller than 6, the main planet can end up inside the sun
if (sunDistanceModifier < 6.0) sunDistanceModifier = 6.0;
sun_distance = (sunDistanceModifier + (Ranrot() % 5) - (Ranrot() % 5) ) * planet_radius;
safeDistance=16 * sun_radius * sun_radius; // 4 times the sun radius
// generated sun_distance/sun_radius ratios vary from 4.29 ( 15/3.5 ) to 16.67 ( 25/1.5 )
// if ratio is less than 4 there's an OXP asking for an unusual system.
if (sun_distance <= 4.2 * sun_radius)
{
// recalculate base distance: lowest 2.60 sun radii, highest 4.28 sun radii
sun_distance= (2.6 + sun_distance /(2.5 * sun_radius)) * sun_radius;
// decrease the safe distance, so we have a better chance to exit the loop normally
safeDistance *= 0.6; // ~ 3 times the sun radius
}
// here we need to check if the sun collides with (or is too close to) the witchpoint
// otherwise at (for example) Maregais in Galaxy 1 we go BANG!
@ -980,9 +999,15 @@ static OOComparisonResult comparePrice(id dict1, id dict2, void * context);
[a_planet setOrientation:q_sun];
vf = vector_right_from_quaternion(q_sun);
sunPos = vector_subtract(sunPos, vector_multiply_scalar(vf, sun_distance)); // back off from the planet by 16..24 pr
sunPos = vector_subtract(sunPos, vector_multiply_scalar(vf, sun_distance)); // back off from the planet by 15..25 planet radii
posIterator++;
} while (magnitude2(sunPos) < safeDistance && posIterator <= 10); // try 10 times before giving up
} while (magnitude2(sunPos) < 16 * sun_radius * sun_radius); // stay at least 4 radii away!
if (posIterator>10)
{
OOLogWARN(@"universe.setup.badSun",@"Sun positioning: max iterations exceeded for '%@'. Adjust radius, sun_radius or sun_distance_modifier.",[systeminfo objectForKey: @"name"]);
}
NSMutableDictionary* sun_dict = [[NSMutableDictionary alloc] initWithCapacity:4];
[sun_dict setObject:[NSNumber numberWithDouble:sun_radius] forKey:@"sun_radius"];