diff --git a/src/Core/Entities/PlanetEntity.h b/src/Core/Entities/PlanetEntity.h index 3a2ca567..188380f8 100644 --- a/src/Core/Entities/PlanetEntity.h +++ b/src/Core/Entities/PlanetEntity.h @@ -136,6 +136,8 @@ GLfloat rvalue[729]; // stores random values for adjusting colors in the coro - (id) initPlanetFromDictionary:(NSDictionary*) dict; - (id) initPlanetFromDictionary:(NSDictionary*) dict withAtmosphere: (BOOL) atmo andSeed:(Random_Seed) p_seed; - (BOOL) setUpPlanetFromTexture:(NSString *)fileName; +- (BOOL) setSunColor:(OOColor*)sun_color; +- (BOOL) changeSunProperty:(NSString *)key withDictionary:(NSDictionary*) dict; void drawActiveCorona(GLfloat inner_radius, GLfloat outer_radius, GLfloat step, GLfloat z_distance, GLfloat* col4v1, int rv); diff --git a/src/Core/Entities/PlanetEntity.m b/src/Core/Entities/PlanetEntity.m index c99faea4..f2af3531 100644 --- a/src/Core/Entities/PlanetEntity.m +++ b/src/Core/Entities/PlanetEntity.m @@ -142,30 +142,13 @@ static float corona_blending; } -- (id) initSunWithColor:(OOColor *)sun_color andDictionary:(NSDictionary *) dict +- (BOOL) setSunColor:(OOColor*)sun_color { - int i; + if (sun_color == nil) return NO; + OOCGFloat hue, sat, bri, alf; OOColor *color; - double sun_radius; - - self = [super init]; - - isTextured = NO; -#ifndef NO_SHADERS - isShadered = NO; -#endif - - collision_radius = 100000.0; // 100km across - - scanClass = CLASS_NO_DRAW; - planet_type = PLANET_TYPE_SUN; - shuttles_on_ground = 0; - last_launch_time = 0.0; - shuttle_launch_interval = 3600.0; - - for (i = 0; i < 5; i++) displayListNames[i] = 0; // empty for now! - + [sun_color getHue:&hue saturation:&sat brightness:&bri alpha:&alf]; hue /=360; @@ -174,7 +157,6 @@ static float corona_blending; // set the lighting color for the sun GLfloat r,g,b,a; [sun_color getGLRed:&r green:&g blue:&b alpha:&a]; - corona_blending=OOClamp_0_1_f([dict floatForKey:@"corona_hues" defaultValue:1.0f]); GLfloat sun_ambient[] = { 0.0, 0.0, 0.0, 1.0}; // ambient light about 5% sun_diffuse[0] = 0.5 * (1.0 + r); // paler @@ -224,7 +206,36 @@ static float corona_blending; amb_polar_sea[1] = [color greenComponent]; amb_polar_sea[2] = [color blueComponent]; amb_polar_sea[3] = 1.0; + + return YES; +} + + +- (id) initSunWithColor:(OOColor *)sun_color andDictionary:(NSDictionary *) dict +{ + int i; + double sun_radius; + self = [super init]; + + isTextured = NO; +#ifndef NO_SHADERS + isShadered = NO; +#endif + + collision_radius = 100000.0; // 100km across + + scanClass = CLASS_NO_DRAW; + planet_type = PLANET_TYPE_SUN; + shuttles_on_ground = 0; + last_launch_time = 0.0; + shuttle_launch_interval = 3600.0; + + for (i = 0; i < 5; i++) displayListNames[i] = 0; // empty for now! + + [self setSunColor:sun_color]; + + corona_blending=OOClamp_0_1_f([dict floatForKey:@"corona_hues" defaultValue:1.0f]); corona_speed_factor=[dict floatForKey:@"corona_shimmer" defaultValue:-1.0]; if(corona_speed_factor<0) { @@ -1416,6 +1427,40 @@ void drawActiveCorona(GLfloat inner_radius, GLfloat outer_radius, GLfloat step, return textureName; } + +- (BOOL) changeSunProperty:(NSString *)key withDictionary:(NSDictionary*) dict +{ + id object = [dict objectForKey:key]; + + if ([key isEqualToString:@"sun_radius"]) + { + // clamp corona_flare in case planetinfo.plist / savegame contains the wrong value + [self setRadius: [object doubleValue] + (0.66*MAX_CORONAFLARE * OOClamp_0_1_f([dict floatForKey:@"corona_flare" defaultValue:0.0f]))]; + collision_radius = [object doubleValue]; + } + else if ([key isEqualToString:@"corona_flare"]) + { + double rad=collision_radius; + [self setRadius: rad + (0.66*MAX_CORONAFLARE * OOClamp_0_1_f([object floatValue]))]; + collision_radius = rad; + } + else if ([key isEqualToString:@"corona_shimmer"]) + { + corona_speed_factor=OOClamp_0_1_f([object floatValue]) * 2.0 + randf() * randf(); + } + else if ([key isEqualToString:@"corona_hues"]) + { + corona_blending=OOClamp_0_1_f([object floatValue]); + } + else + { + OOLogWARN(@"script.warning", @"Change to property '%@' not applied, will apply only on leaving and re-entering this system.",key); + return NO; + } + return YES; +} + + - (BOOL) setUpPlanetFromTexture:(NSString *)fileName { GLuint tName=[TextureStore getTextureNameFor:fileName]; diff --git a/src/Core/Entities/SkyEntity.h b/src/Core/Entities/SkyEntity.h index 7229482a..7ba5881c 100644 --- a/src/Core/Entities/SkyEntity.h +++ b/src/Core/Entities/SkyEntity.h @@ -35,6 +35,7 @@ MA 02110-1301, USA. } - (id) initWithColors:(OOColor *)col1 :(OOColor *)col2 andSystemInfo:(NSDictionary *)systemInfo; +- (BOOL) changeProperty:(NSString *)key withDictionary:(NSDictionary*) dict; - (OOColor *)skyColor; diff --git a/src/Core/Entities/SkyEntity.m b/src/Core/Entities/SkyEntity.m index e9e6bb82..01a8e278 100644 --- a/src/Core/Entities/SkyEntity.m +++ b/src/Core/Entities/SkyEntity.m @@ -136,6 +136,31 @@ MA 02110-1301, USA. } +- (BOOL) changeProperty:(NSString *)key withDictionary:(NSDictionary*) dict +{ + id object = [dict objectForKey:key]; + + // TODO: properties requiring reInit? + if ([key isEqualToString:@"sun_color"]) + { + OOColor *col=[[OOColor colorWithDescription:object] retain]; + if (col != nil) + { + [skyColor release]; + skyColor = [col copy]; + [col release]; + [UNIVERSE setLighting]; + } + } + else + { + OOLogWARN(@"script.warning", @"Change to property '%@' not applied, will apply only on leaving and re-entering this system.",key); + return NO; + } + return YES; +} + + - (void) update:(OOTimeDelta) delta_t { PlayerEntity *player = [PlayerEntity sharedPlayer]; diff --git a/src/Core/Entities/WormholeEntity.m b/src/Core/Entities/WormholeEntity.m index fe7e066e..84e514b3 100644 --- a/src/Core/Entities/WormholeEntity.m +++ b/src/Core/Entities/WormholeEntity.m @@ -39,7 +39,7 @@ MA 02110-1301, USA. // Hidden interface @interface WormholeEntity (Private) --(WormholeEntity *) init; +-(id) init; @end @@ -49,7 +49,7 @@ static void DrawWormholeCorona(GLfloat inner_radius, GLfloat outer_radius, int s @implementation WormholeEntity (Private) -- (WormholeEntity*)init +-(id) init { if ((self = [super init])) { diff --git a/src/Core/GuiDisplayGen.h b/src/Core/GuiDisplayGen.h index 09e6efd6..d8cc46c9 100644 --- a/src/Core/GuiDisplayGen.h +++ b/src/Core/GuiDisplayGen.h @@ -31,7 +31,7 @@ MA 02110-1301, USA. #define GUI_DEFAULT_COLUMNS 6 -#define GUI_DEFAULT_ROWS 24 +#define GUI_DEFAULT_ROWS 30 #define GUI_MAX_ROWS 64 #define GUI_MAX_COLUMNS 40 diff --git a/src/Core/Universe.m b/src/Core/Universe.m index d1968a48..4442f9b8 100644 --- a/src/Core/Universe.m +++ b/src/Core/Universe.m @@ -975,9 +975,10 @@ static OOComparisonResult comparePrice(id dict1, id dict2, void * context); sun_radius = [systeminfo nonNegativeDoubleForKey:@"sun_radius" defaultValue:(2.5 + randf() - randf() ) * planet_radius]; // clamp the sun radius - if (sun_radius < 1000.0) sun_radius = 1000.0; - if (sun_radius > 1000000.0) sun_radius = 1000000.0; - + if (sun_radius < 1000.0 || sun_radius > 1000000.0 ) + { + sun_radius = sun_radius < 1000.0 ? 1000.0 : 1000000.0; + } 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 ) @@ -6101,10 +6102,19 @@ OOINLINE BOOL EntityInRange(Vector p1, Entity *e2, float range) - (void) setSystemDataForGalaxy:(OOGalaxyID)gnum planet:(OOSystemID)pnum key:(NSString *)key value:(id)object { + // trying to set unsettable properties? + if ([key isEqualToString:KEY_RADIUS]) // buggy if we allow this key to be set + { + OOLogERR(@"script.error", @"System property '%@' cannot be set.",key); + return; + } + NSString *overrideKey = [NSString stringWithFormat:@"%u %u", gnum, pnum]; Random_Seed s_seed = [self systemSeedForSystemNumber:pnum]; - BOOL sameGalaxy=([overrideKey isEqualToString:[self keyForPlanetOverridesForSystemSeed:s_seed inGalaxySeed: galaxy_seed]]); - + BOOL sameGalaxy = ([overrideKey isEqualToString:[self keyForPlanetOverridesForSystemSeed:s_seed inGalaxySeed: galaxy_seed]]); + BOOL sameSystem = (sameGalaxy && equal_seeds([self systemSeed], s_seed)); + NSDictionary *sysInfo = nil; + // long range map fixes if ([key isEqualToString:KEY_NAME]) { @@ -6115,9 +6125,71 @@ OOINLINE BOOL EntityInRange(Vector p1, Entity *e2, float range) system_names[pnum] = [(NSString *)object retain]; } } + else if ([key isEqualToString:@"sun_radius"]) + { + if ([object doubleValue] < 1000.0 || [object doubleValue] > 1000000.0 ) + { + object = ([object doubleValue] < 1000.0 ? (id)@"1000.0" : (id)@"1000000.0"); // works! + } + } + else if ([key hasPrefix:@"corona_"]) + { + object = (id)[NSString stringWithFormat:@"%f",OOClamp_0_1_f([object floatValue])]; + } + [self setObject:object forKey:key forPlanetKey:overrideKey]; + if (sameGalaxy) // refresh the current systemData cache! - [self generateSystemData:system_seed useCache:NO]; + sysInfo=[self generateSystemData:system_seed useCache:NO]; // needed if sameSystem + + // Apply changes that can be effective immediately, issue warning if they can't be changed just now + if (sameSystem) + { + if ([key isEqualToString:KEY_ECONOMY]) + { + if([self station]) [[self station] initialiseLocalMarketWithSeed:s_seed andRandomFactor:[[PlayerEntity sharedPlayer] random_factor]]; + } + else if ([key isEqualToString:KEY_TECHLEVEL]) + { + if([self station]){ + [[self station] setEquivalentTechLevel:[object intValue]]; + [[self station] setLocalShipyard:[self shipsForSaleForSystem:system_seed + withTL:[object intValue] atTime:[[PlayerEntity sharedPlayer] clockTime]]]; + } + } + else if ([key isEqualToString:@"sun_color"] || [key isEqualToString:@"star_count_multiplier"] || + [key isEqualToString:@"nebula_count_multiplier"] || [key hasPrefix:@"sky_"]) + { + SkyEntity *the_sky = nil; + int i; + + for (i = n_entities - 1; i > 0; i--) + if ((sortedEntities[i]) && ([sortedEntities[i] isKindOfClass:[SkyEntity class]])) + the_sky = (SkyEntity*)sortedEntities[i]; + + if (the_sky != nil) + { + [the_sky changeProperty:key withDictionary:sysInfo]; + + if ([key isEqualToString:@"sun_color"]) + { + OOColor *color=[[the_sky skyColor] blendedColorWithFraction:0.5 ofColor:[OOColor whiteColor]]; + if ([self sun]) [[self sun] setSunColor:color]; + for (i = n_entities - 1; i > 0; i--) + if ((sortedEntities[i]) && ([sortedEntities[i] isKindOfClass:[DustEntity class]])) + [(DustEntity*)sortedEntities[i] setDustColor:color]; + } + } + } + else if ([self sun] && ([key hasPrefix:@"sun_"] || [key hasPrefix:@"corona_"])) + { + [[self sun] changeSunProperty:key withDictionary:sysInfo]; + } + else if ([key isEqualToString:@"texture"]) + { + [[self planet] setUpPlanetFromTexture:(NSString *)object]; + } + } }