108 { +0.000000, -0.850664, -0.525710 },
109 { +0.000000, -0.850664, +0.525710 },
110 { +0.000000, +0.850664, +0.525710 },
111 { +0.000000, +0.850664, -0.525710 },
112 { -0.525710, +0.000000, -0.850664 },
113 { +0.525710, +0.000000, -0.850664 },
114 { +0.525710, +0.000000, +0.850664 },
115 { -0.525710, +0.000000, +0.850664 },
116 { -0.850664, -0.525710, +0.000000 },
117 { -0.850664, +0.525710, +0.000000 },
118 { +0.850664, +0.525710, +0.000000 },
119 { +0.850664, -0.525710, +0.000000 }
124 { { 9, +0.600000, +0.666667 }, { 7, +0.800000, +0.666667 }, { 8, +0.800000, +0.333333 } },
125 { { 8, +0.800000, +0.333333 }, { 4, +0.600000, +0.333333 }, { 9, +0.600000, +0.666667 } },
126 { { 3, +0.400000, +0.666667 }, { 9, +0.600000, +0.666667 }, { 4, +0.600000, +0.333333 } },
127 { { 8, +0.800000, +0.333333 }, { 0, +0.500000, +0.000000 }, { 4, +0.600000, +0.333333 } },
128 { { 7, +0.800000, +0.666667 }, { 1, +1.000000, +0.333333 }, { 8, +0.800000, +0.333333 } },
129 { { 2, +0.500000, +1.000000 }, { 7, +0.800000, +0.666667 }, { 9, +0.600000, +0.666667 } },
130 { { 2, +0.500000, +1.000000 }, { 9, +0.600000, +0.666667 }, { 3, +0.400000, +0.666667 } },
131 { { 1, +1.000000, +0.333333 }, { 0, +0.500000, +0.000000 }, { 8, +0.800000, +0.333333 } },
132 { { 4, +0.600000, +0.333333 }, { 0, +0.500000, +0.000000 }, { 5, +0.400000, +0.333333 } },
133 { { 5, +0.400000, +0.333333 }, { 3, +0.400000, +0.666667 }, { 4, +0.600000, +0.333333 } },
134 { { 6, +1.000000, +0.666667 }, { 1, +1.000000, +0.333333 }, { 7, +0.800000, +0.666667 } },
135 { { 7, +0.800000, +0.666667 }, { 2, +0.500000, +1.000000 }, { 6, +1.000000, +0.666667 } },
136 { { 1, +0.000000, +0.333333 }, { 11, +0.200000, +0.333333 }, { 0, +0.500000, +0.000000 } },
137 { { 3, +0.400000, +0.666667 }, { 10, +0.200000, +0.666667 }, { 2, +0.500000, +1.000000 } },
138 { { 0, +0.500000, +0.000000 }, { 11, +0.200000, +0.333333 }, { 5, +0.400000, +0.333333 } },
139 { { 5, +0.400000, +0.333333 }, { 10, +0.200000, +0.666667 }, { 3, +0.400000, +0.666667 } },
140 { { 1, +0.000000, +0.333333 }, { 6, +0.000000, +0.666667 }, { 11, +0.200000, +0.333333 } },
141 { { 6, +0.000000, +0.666667 }, { 2, +0.500000, +1.000000 }, { 10, +0.200000, +0.666667 } },
142 { { 5, +0.400000, +0.333333 }, { 11, +0.200000, +0.333333 }, { 10, +0.200000, +0.666667 } },
143 { { 11, +0.200000, +0.333333 }, { 6, +0.000000, +0.666667 }, { 10, +0.200000, +0.666667 } }
149 { +0.525731, +0.000000, +0.850651 },
150 { -0.525731, +0.000000, +0.850651 },
151 { +0.525731, +0.000000, -0.850651 },
152 { -0.525731, +0.000000, -0.850651 },
153 { +0.000000, +0.850651, +0.525731 },
154 { +0.000000, +0.850651, -0.525731 },
155 { +0.000000, -0.850651, +0.525731 },
156 { +0.000000, -0.850651, -0.525731 },
157 { -0.850651, +0.525731, +0.000000 },
158 { +0.850651, +0.525731, +0.000000 },
159 { -0.850651, -0.525731, +0.000000 },
160 { +0.850651, -0.525731, +0.000000 },
161 { +0.000000, +0.850651, -0.525731 },
162 { +0.525731, +0.000000, -0.850651 }
167 { { 1, +0.400000, +0.666667 }, { 0, +0.600000, +0.666667 }, { 6, +0.500000, +0.333333 } },
168 { { 3, +0.100000, +0.333333 }, { 2, -0.100000, +0.333333 }, { 5, +0.000000, +0.666667 } },
169 { { 4, +0.500000, +1.000000 }, { 0, +0.600000, +0.666667 }, { 1, +0.400000, +0.666667 } },
170 { { 4, +0.500000, +1.000000 }, { 1, +0.400000, +0.666667 }, { 8, +0.200000, +0.666667 } },
171 { { 12, +1.000000, +0.666667 }, { 13, +0.900000, +0.333333 }, { 9, +0.800000, +0.666667 } },
172 { { 5, +0.000000, +0.666667 }, { 4, +0.500000, +1.000000 }, { 8, +0.200000, +0.666667 } },
173 { { 6, +0.500000, +0.333333 }, { 0, +0.600000, +0.666667 }, { 11, +0.700000, +0.333333 } },
174 { { 7, +0.500000, +0.000000 }, { 2, -0.100000, +0.333333 }, { 3, +0.100000, +0.333333 } },
175 { { 7, +0.500000, +0.000000 }, { 3, +0.100000, +0.333333 }, { 10, +0.300000, +0.333333 } },
176 { { 7, +0.500000, +0.000000 }, { 6, +0.500000, +0.333333 }, { 11, +0.700000, +0.333333 } },
177 { { 8, +0.200000, +0.666667 }, { 1, +0.400000, +0.666667 }, { 10, +0.300000, +0.333333 } },
178 { { 8, +0.200000, +0.666667 }, { 3, +0.100000, +0.333333 }, { 5, +0.000000, +0.666667 } },
179 { { 9, +0.800000, +0.666667 }, { 0, +0.600000, +0.666667 }, { 4, +0.500000, +1.000000 } },
180 { { 9, +0.800000, +0.666667 }, { 13, +0.900000, +0.333333 }, { 11, +0.700000, +0.333333 } },
181 { { 9, +0.800000, +0.666667 }, { 4, +0.500000, +1.000000 }, { 12, +1.000000, +0.666667 } },
182 { { 10, +0.300000, +0.333333 }, { 1, +0.400000, +0.666667 }, { 6, +0.500000, +0.333333 } },
183 { { 10, +0.300000, +0.333333 }, { 3, +0.100000, +0.333333 }, { 8, +0.200000, +0.666667 } },
184 { { 10, +0.300000, +0.333333 }, { 6, +0.500000, +0.333333 }, { 7, +0.500000, +0.000000 } },
185 { { 11, +0.700000, +0.333333 }, { 0, +0.600000, +0.666667 }, { 9, +0.800000, +0.666667 } },
186 { { 11, +0.700000, +0.333333 }, { 13, +0.900000, +0.333333 }, { 7, +0.500000, +0.000000 } }
195 [NSException raise:NSInternalInconsistencyException format:@"%s, believed dead, called.", __PRETTY_FUNCTION__];
200- (id) initAsAtmosphereForPlanet:(
PlanetEntity *)planet dictionary:(NSDictionary *)dict
202 BOOL procGen = [UNIVERSE doProcedurallyTexturedPlanets];
204 if (dict ==
nil) dict = [NSDictionary dictionary];
210 polar_color_factor = 1.0;
212#define CLEAR_SKY_ALPHA 0.05
213#define CLOUD_ALPHA 0.50
214#define POLAR_CLEAR_SKY_ALPHA 0.34
215#define POLAR_CLOUD_ALPHA 0.75
246 cloudAlpha = OOClamp_0_1_f([dict oo_floatForKey:
@"cloud_alpha" defaultValue:1.0]);
248 if (clearSkyColor !=
nil)
253 if (cloudColor !=
nil)
258 if (polarClearSkyColor !=
nil)
260 [polarClearSkyColor
getRed:&amb_polar_land[0]
green:&amb_polar_land[1]
blue:&amb_polar_land[2]
alpha:&amb_polar_land[3]];
262 else if (clearSkyColor !=
nil)
264 memmove(amb_polar_land, amb_land,
sizeof amb_polar_land);
268 if (polarCloudColor !=
nil)
270 [polarCloudColor
getRed:&amb_polar_sea[0]
green:&amb_polar_sea[1]
blue:&amb_polar_sea[2]
alpha:&amb_polar_sea[3]];
272 else if (cloudColor !=
nil)
274 memmove(amb_polar_sea, amb_sea,
sizeof amb_polar_sea);
279 amb_sea[3] *= cloudAlpha;
280 amb_polar_land[3] *= cloudAlpha;
281 amb_polar_sea[3] *= cloudAlpha;
283 amb_sea[3] = OOClamp_0_1_f(amb_sea[3]);
284 amb_polar_sea[3] = OOClamp_0_1_f(amb_polar_sea[3]);
293 float cloud_bias = -0.01 * (float)percent_land;
294 float cloud_impress = 1.0 - cloud_bias;
296 _texture = [
self cloudTextureWithCloudColor:cloudColor cloudImpress:cloud_impress cloudBias:cloud_bias];
306 OOLogERR(
@"planet.atmosphere.init.noPlanet",
@"planet entity initAsAtmosphereForPlanet: no planet found.");
310 [
self setOwner: planet];
320 shuttles_on_ground = 0;
321 last_launch_time = 0.0;
322 shuttle_launch_interval = 3600.0;
324 scanClass = CLASS_NO_DRAW;
335 [
self setUseTexturedModel:YES];
336 [
self initialiseBaseVertexArray];
337 [
self initialiseBaseTerrainArray:percent_land];
341 [
self paintVertex:i :planet_seed];
344 [
self scaleVertices];
347 rotational_velocity = [dict oo_floatForKey:@"atmosphere_rotational_velocity" defaultValue:[planet
rotationalVelocity]*(0.9+(randf()*0.2))];
349 root_planet = planet;
362 shuttles_on_ground = 0;
363 last_launch_time = 0.0;
364 shuttle_launch_interval = 3600.0;
365 [
self setStatus:STATUS_COCKPIT_DISPLAY];
367 [
self scaleVertices];
368 if (atmosphere !=
nil)
371 [atmosphere scaleVertices];
373 rotational_velocity = 0.04;
378- (id) initFromDictionary:(NSDictionary*)dict withAtmosphere:(BOOL)atmo andSeed:(
Random_Seed)p_seed
380 BOOL procGen = [UNIVERSE doProcedurallyTexturedPlanets];
382 if (dict ==
nil) dict = [NSDictionary dictionary];
390 planet_seed = p_seed.
a * 13 + p_seed.c * 11 + p_seed.e * 7;
392 planet_seed = p_seed.
a * 7 + p_seed.c * 11 + p_seed.e * 13;
394 OOTexture *texture = [dict oo_objectOfClass:[
OOTexture class] forKey:@"_oo_textureObject"];
397 _texture = [texture
retain];
398 isTextureImage = [dict oo_boolForKey:@"_oo_isExplicitlyTextured"];
402 NSDictionary *textureSpec = [dict oo_textureSpecifierForKey:@"texture" defaultName:nil];
403 if (textureSpec !=
nil)
405 [
self loadTexture:textureSpec];
415 NSString *seedStr = [dict oo_stringForKey:@"seed"];
425 OOLogERR(
@"planet.fromDict",
@"could not interpret \"%@\
" as planet seed, using default.", seedStr);
432 NSMutableDictionary *planetInfo = [NSMutableDictionary dictionaryWithDictionary:[UNIVERSE generateSystemData:p_seed]];
433 int radius_km = [dict oo_intForKey:KEY_RADIUS
434 defaultValue:[planetInfo oo_intForKey:KEY_RADIUS]];
435 int techlevel = [dict oo_intForKey:KEY_TECHLEVEL
436 defaultValue:[planetInfo oo_intForKey:KEY_TECHLEVEL]];
438 shuttles_on_ground = 1 + floor(techlevel * 0.5);
439 last_launch_time = 0.0;
440 shuttle_launch_interval = 3600.0 / shuttles_on_ground;
442 last_launch_time = [UNIVERSE getTime] + 30.0 - shuttle_launch_interval;
444 collision_radius = radius_km * 10.0;
446 scanClass = CLASS_NO_DRAW;
453 [
self setUseTexturedModel:(procGen || _texture != nil)];
455 int percent_land = [planetInfo oo_intForKey:@"percent_land" defaultValue:24 + (gen_rnd_number() % 48)];
465 [planetInfo setObject:[NSNumber numberWithFloat:0.01 * percent_land] forKey:@"land_fraction"];
467 polar_color_factor = [dict oo_doubleForKey:@"polar_color_factor" defaultValue:0.5f];
469 Vector land_hsb, sea_hsb, land_polar_hsb, sea_polar_hsb;
474 land_hsb.x = 0.0; land_hsb.y = 0.0; land_hsb.z = 1.0;
475 sea_hsb.x = 0.0; sea_hsb.y = 1.0; sea_hsb.z = 1.0;
477 [
self setTextureColorForPlanet:!![dict objectForKey:@"mainForLocalSystem"] inSystem:[dict oo_boolForKey:@"mainForLocalSystem" defaultValue:NO]];
484 while (dot_product(land_hsb,sea_hsb) > .80)
494 land_polar_hsb.x = land_hsb.x; land_polar_hsb.y = (land_hsb.y / 4.0); land_polar_hsb.z = 1.0 - (land_hsb.z / 10.0);
495 sea_polar_hsb.x = sea_hsb.x; sea_polar_hsb.y = (sea_hsb.y / 4.0); sea_polar_hsb.z = 1.0 - (sea_hsb.z / 10.0);
506 amb_sea[0] = [amb_sea_color redComponent];
507 amb_sea[1] = [amb_sea_color blueComponent];
508 amb_sea[2] = [amb_sea_color greenComponent];
510 amb_polar_land[0] = [amb_polar_land_color redComponent];
511 amb_polar_land[1] = [amb_polar_land_color blueComponent];
512 amb_polar_land[2] = [amb_polar_land_color greenComponent];
513 amb_polar_land[3] = 1.0;
514 amb_polar_sea[0] = [amb_polar_sea_color redComponent];
515 amb_polar_sea[1] = [amb_polar_sea_color blueComponent];
516 amb_polar_sea[2] = [amb_polar_sea_color greenComponent];
517 amb_polar_sea[3] = 1.0;
519 [planetInfo setObject:amb_land_color forKey:@"land_color"];
520 [planetInfo setObject:amb_sea_color forKey:@"sea_color"];
521 [planetInfo setObject:amb_polar_land_color forKey:@"polar_land_color"];
522 [planetInfo setObject:amb_polar_sea_color forKey:@"polar_sea_color"];
525 if (procGen && _texture ==
nil)
527 _texture = [
self planetTextureWithInfo:planetInfo];
532 [
self initialiseBaseVertexArray];
533 [
self initialiseBaseTerrainArray:percent_land];
537 [
self paintVertex:i :planet_seed];
540 [
self scaleVertices];
542 if ([dict objectForKey:
@"rotational_velocity"])
544 rotational_velocity = [dict oo_floatForKey:@"rotational_velocity" defaultValue:0.01f * randf()];
548 rotational_velocity = [planetInfo oo_floatForKey:@"rotation_speed" defaultValue:0.002 * (0.5+0.5*randf())];
549 rotational_velocity *= [planetInfo oo_floatForKey:@"rotation_speed_factor" defaultValue:1.0f];
553 NSDictionary *atmoDict = dict;
554 if (_texture !=
nil) atmoDict = [NSDictionary dictionaryWithObjectsAndKeys:
@"0",
@"percent_cloud", [NSNumber numberWithFloat:[planetInfo oo_floatForKey:
@"cloud_alpha" defaultValue:1.0]],
@"cloud_alpha",
nil];
555 if (atmo) atmosphere = [[
PlanetEntity alloc] initAsAtmosphereForPlanet:
self dictionary:atmoDict];
561 energy = collision_radius * 1000.0;
569 int deltaT = floor(fmod([
PLAYER clockTimeAdjusted], 86400));
572 [
self setStatus:STATUS_ACTIVE];
582 [
self deleteDisplayLists];
594- (NSString*) descriptionComponents
596 NSString *typeString;
600 typeString =
@"STELLAR_TYPE_MINIATURE";
break;
602 typeString =
@"STELLAR_TYPE_NORMAL_PLANET";
break;
604 typeString =
@"STELLAR_TYPE_ATMOSPHERE";
break;
606 typeString =
@"STELLAR_TYPE_MOON";
break;
609 typeString =
@"UNKNOWN";
611 return [NSString stringWithFormat:@"ID: %u position: %@ type: %@ radius: %.3fkm", [
self universalID], HPVectorDescription([
self position]), typeString, 0.001 * [
self radius]];
1325 void *key = (
void *)(((uintptr_t)va << 16) | vb);
1330 return (
unsigned)num - 1;
1339 pos = vector_normal(pos);
1349 if (uva.y == 0.0 || uva.y == 1.0) uva.x = uvb.x;
1350 if (uvb.y == 0.0 || uvb.y == 1.0) uvb.x = uva.x;
1364- (void) initialiseBaseTerrainArray:(
int) percent_land
1369 if (percent_land >= 0)
1372 for (vi = 0; vi < vertexCount; vi++)
1383 BOOL isTextured = [
self isTextured];
1386 for (sublevel = 0; sublevel <
MAX_SUBDIVIDE - 1; sublevel++)
1438- (void) paintVertex:(
unsigned) vi :(
int) seed
1441 BOOL isTextured = _texture !=
nil;
1443 GLfloat paint_land[4] = { 0.2, 0.9, 0.0, 1.0};
1444 GLfloat paint_sea[4] = { 0.0, 0.2, 0.9, 1.0};
1445 GLfloat paint_color[4];
1449 double pole_blend = v.z * v.z * polar_color_factor;
1450 if (pole_blend < 0.0) pole_blend = 0.0;
1451 if (pole_blend > 1.0) pole_blend = 1.0;
1453 paint_land[0] = (1.0 - pole_blend)*amb_land[0] + pole_blend*amb_polar_land[0];
1454 paint_land[1] = (1.0 - pole_blend)*amb_land[1] + pole_blend*amb_polar_land[1];
1455 paint_land[2] = (1.0 - pole_blend)*amb_land[2] + pole_blend*amb_polar_land[2];
1456 paint_sea[0] = (1.0 - pole_blend)*amb_sea[0] + pole_blend*amb_polar_sea[0];
1457 paint_sea[1] = (1.0 - pole_blend)*amb_sea[1] + pole_blend*amb_polar_sea[1];
1458 paint_sea[2] = (1.0 - pole_blend)*amb_sea[2] + pole_blend*amb_polar_sea[2];
1461 paint_land[3] = (1.0 - pole_blend)*amb_land[3] + pole_blend*amb_polar_land[3];
1462 paint_sea[3] = (1.0 - pole_blend)*amb_sea[3] + pole_blend*amb_polar_sea[3];
1465 ranrot_srand((uint32_t)(seed+v.x*1000+v.y*100+v.z*10));
1467 for (i = 0; i < 3; i++)
1470 paint_land[i] += (cv - 0.5)*0.1;
1471 paint_sea[i] += (cv - 0.5)*0.1;
1474 for (i = 0; i < 4; i++)
1477 paint_color[i] = 1.0;
1479 paint_color[i] = (r * paint_sea[i])*0.01 + ((100 - r) * paint_land[i])*0.01;
1481 vertexdata.color_array[vi*4 + i] = paint_color[i];
1494 vertexdata.normal_array[vi] = v;
1495 vertexdata.vertex_array[vi] = make_vector(v.x * collision_radius, v.y * collision_radius, v.z * collision_radius);
1508 if (displayListNames[i] != 0)
1510 glDeleteLists(displayListNames[i], 1);
1511 displayListNames[i] = 0;
1519 [
self deleteDisplayLists];
1523- (BOOL) isExplicitlyTextured
1525 return isTextureImage;
1535- (void) loadTexture:(NSDictionary *)configuration
1541 [_textureFileName release];
1542 if (_texture !=
nil)
1544 _textureFileName = [[configuration oo_stringForKey:@"name"] copy];
1545 isTextureImage = YES;
1549 _textureFileName =
nil;
1550 isTextureImage = NO;
1561- (
OOTexture *) planetTextureWithInfo:(NSDictionary *)info
1563 unsigned char *data;
1564 GLuint width, height;
1577 textureOptions:kOOTextureDefaultOptions | kOOTextureRepeatS
1579 [loader autorelease];
1585- (
OOTexture *) cloudTextureWithCloudColor:(
OOColor *)cloudColor cloudImpress:(GLfloat)cloud_impress cloudBias:(GLfloat)cloud_bias
1587 unsigned char *data;
1588 GLuint width, height;
1603 textureOptions:kOOTextureDefaultOptions | kOOTextureRepeatS
1605 [loader autorelease];
1612- (NSSet *) allTextures
1614 if (_texture !=
nil)
return [NSSet setWithObject:_texture];