90 :(NSDictionary *)dict withAtmosphere:(BOOL)atmosphere andSeed:(
Random_Seed)seed forSystem:(
OOSystemID)systemID
91{
92 if (dict ==
nil) dict = [NSDictionary dictionary];
94
95 self = [self init];
96 if (
self ==
nil)
return nil;
97
99
100 NSMutableDictionary *planetInfo = [[UNIVERSE generateSystemData:systemID] mutableCopy];
101 [planetInfo autorelease];
102
103 [self setUpTypeParametersWithSourceInfo:dict targetInfo:planetInfo];
104
105 [self setUpTerrainParametersWithSourceInfo:dict targetInfo:planetInfo];
106
107
108
109 NSString *seedStr = [dict oo_stringForKey:@"seed"];
111 {
113 if (!
is_nil_seed(overrideSeed)) seed = overrideSeed;
114 else OOLogERR(
@"planet.fromDict",
@"could not interpret \"%@\
" as planet seed, using default.", seedStr);
115 }
116
117
119
121 [self setName:OOExpand([dict oo_stringForKey:KEY_PLANETNAME defaultValue:[planetInfo oo_stringForKey:KEY_PLANETNAME defaultValue:@"%H"]])];
122
123 int radius_km = [dict oo_intForKey:KEY_RADIUS defaultValue:[planetInfo oo_intForKey:KEY_RADIUS]];
125 OOTechLevelID techLevel = [dict oo_intForKey:KEY_TECHLEVEL defaultValue:[planetInfo oo_intForKey:KEY_TECHLEVEL]];
126
127 if (techLevel > 14) techLevel = 14;
131
132
133 int percent_land = [planetInfo oo_intForKey:@"percent_land" defaultValue:24 + (gen_rnd_number() % 48)];
134 [planetInfo setObject:[NSNumber numberWithFloat:0.01 * percent_land] forKey:@"land_fraction"];
135
136 int percent_ice = [planetInfo oo_intForKey:@"percent_ice" defaultValue:5];
137 [planetInfo setObject:[NSNumber numberWithFloat:0.01 * percent_ice] forKey:@"polar_fraction"];
138
139
141
143
144 _terminatorThresholdVector = [planetInfo oo_vectorForKey:@"terminator_threshold_vector" defaultValue:OO_TERMINATOR_THRESHOLD_VECTOR_DEFAULT];
145
146
148 [planetInfo setObject:[NSValue valueWithBytes:&planetNoiseSeed objCType:@encode(RANROTSeed)] forKey:@"noise_map_seed"];
149 [self setUpLandParametersWithSourceInfo:dict targetInfo:planetInfo];
150
154
156
157#if NEW_ATMOSPHERE
158 if (atmosphere)
159 {
160
161
162
167
168
170 [planetInfo setObject:[NSNumber numberWithFloat:0.01 * percent_land] forKey:@"cloud_fraction"];
171 [self setUpAtmosphereParametersWithSourceInfo:dict targetInfo:planetInfo];
172
173 _airColor = [[planetInfo objectForKey:@"air_color"] retain];
175
176 _airDensity = OOClamp_0_1_f([planetInfo oo_floatForKey:
@"air_density"]);
177
178
179 _materialParameters = [planetInfo dictionaryWithValuesForKeys:[NSArray arrayWithObjects:@"cloud_fraction", @"air_color", @"air_color_mix_ratio", @"air_density", @"cloud_color", @"polar_cloud_color", @"cloud_alpha", @"land_fraction", @"land_color", @"sea_color", @"polar_land_color", @"polar_sea_color", @"noise_map_seed", @"economy", @"polar_fraction", @"isMiniature", @"perlin_3d", @"terminator_threshold_vector", nil]];
180 }
181 else
182#else
183
184 if (atmosphere)
185 {
188 }
189 if (YES)
190#endif
191 {
192 _materialParameters = [planetInfo dictionaryWithValuesForKeys:[NSArray arrayWithObjects:@"land_fraction", @"land_color", @"sea_color", @"polar_land_color", @"polar_sea_color", @"noise_map_seed", @"economy", @"polar_fraction", @"isMiniature", @"perlin_3d", @"terminator_threshold_vector", @"illumination_color", nil]];
193 }
194 [_materialParameters retain];
195
197
199
200 _textureName = [[dict oo_stringForKey:@"texture"] retain];
201 [self setUpPlanetFromTexture:_textureName];
202 [_planetDrawable setRadius:collision_radius];
203
204
208
209
210 if ([dict objectForKey:@"rotational_velocity"])
211 {
212 _rotationalVelocity = [dict oo_floatForKey:@"rotational_velocity" defaultValue:0.01f * randf()];
213 }
214 else
215 {
216 _rotationalVelocity = [planetInfo oo_floatForKey:@"rotation_speed" defaultValue:0.005f * randf()];
217 _rotationalVelocity *= [planetInfo oo_floatForKey:@"rotation_speed_factor" defaultValue:1.0f];
218 }
219
221
222
224
227
228
229 int deltaT = floor(fmod([
PLAYER clockTimeAdjusted], 86400));
232
233
234#ifdef OO_DUMP_PLANETINFO
235#define CPROP(PROP) OOLog(@"planetinfo.record",@#PROP " = %@;",[(OOColor *)[planetInfo objectForKey:@#PROP] descriptionComponents]);
236#define FPROP(PROP) OOLog(@"planetinfo.record",@#PROP " = %f;",[planetInfo oo_floatForKey:@"" #PROP]);
237 CPROP(air_color);
238 CPROP(illumination_color);
239 FPROP(air_color_mix_ratio);
240 FPROP(cloud_alpha);
241 CPROP(cloud_color);
242 FPROP(cloud_fraction);
243 CPROP(land_color);
244 FPROP(land_fraction);
245 CPROP(polar_cloud_color);
246 CPROP(polar_land_color);
247 CPROP(polar_sea_color);
248 CPROP(sea_color);
250#endif
251
252 [self setStatus:STATUS_ACTIVE];
253
255
256 return self;
257}
#define OOLogERR(class, format,...)
#define OOLog(class, format,...)
static const double kMesosphere
Vector vector_up_from_quaternion(Quaternion quat)
const Quaternion kIdentityQuaternion
void quaternion_rotate_about_axis(Quaternion *quat, Vector axis, OOScalar angle)
Random_Seed RandomSeedFromString(NSString *abcdefString)
const Vector kBasisYVector
OOColor * colorWithRed:green:blue:alpha:(float red,[green] float green,[blue] float blue,[alpha] float alpha)
void registerClient:(id< OOGraphicsResetClient > client)
instancetype atmosphereWithRadius:(float radius)
OOTimeDelta _shuttleLaunchInterval
unsigned _shuttlesOnGround
float _atmosphereRotationalVelocity
OOTimeDelta _lastLaunchTime
RANROTSeed RANROTGetFullSeed(void)
void setRandomSeed(RNG_Seed a_seed)
RNG_Seed currentRandomSeed(void)
void RANROTSetFullSeed(RANROTSeed seed)
void seed_for_planet_description(Random_Seed s_seed)
OOINLINE int is_nil_seed(Random_Seed a_seed) INLINE_CONST_FUNC