27#import "MyOpenGLView.h"
98#if OO_LOCALIZATION_TOOLS
109#define DEMO2_VANISHING_DISTANCE 650.0
110#define DEMO2_FLY_IN_STAGE_TIME 0.4
113#define MAX_NUMBER_OF_ENTITIES 200
114#define STANDARD_STATION_ROLL 0.4
116#define LANE_WIDTH 51200.0
127 1.0f, 1.0f, 1.0f, 1.0f,
128 1.0f, -1.0f, 1.0f, 0.0f,
129 -1.0f, -1.0f, 0.0f, 0.0f,
130 -1.0f, 1.0f, 0.0f, 1.0f
151#undef CACHE_ROUTE_FROM_SYSTEM_RESULTS
161+ (instancetype) elementWithLocation:(
OOSystemID) location parent:(
OOSystemID)parent cost:(
double) cost distance:(
double) distance time:(
double) time jumps:(
int) jumps;
173+ (instancetype) elementWithLocation:(
OOSystemID) location parent:(
OOSystemID) parent cost:(
double) cost distance:(
double) distance time:(
double) time jumps:(
int) jumps
184 return [
r autorelease];
197@interface Universe (OOPrivate)
199- (void) initTargetFramebufferWithViewSize:(NSSize)viewSize;
201- (void) resizeTargetFramebufferWithViewSize:(NSSize)viewSize;
205- (BOOL) doRemoveEntity:(
Entity *)entity;
208- (HPVector) fractionalPositionFrom:(HPVector)point0 to:(HPVector)point1 withFraction:(
double)routeFraction;
212- (NSString *)chooseStringForKey:(NSString *)key inDictionary:(NSDictionary *)dictionary;
214#if OO_LOCALIZATION_TOOLS
216- (void) dumpDebugGraphViz;
217- (void) dumpSystemDescriptionGraphViz;
219- (void) addNumericRefsInString:(NSString *)string toGraphViz:(NSMutableString *)graphViz fromNode:(NSString *)fromNode nodeCount:(NSUInteger)nodeCount;
229- (void) prunePreloadingPlanetMaterials;
235- (void) setFirstBeacon:(
Entity <OOBeaconEntity> *)beacon;
236- (void) setLastBeacon:(
Entity <OOBeaconEntity> *)beacon;
244- (Vector) randomPlaceWithinScannerFrom:(Vector)pos alongRoute:(Vector)route withOffset:(
double)offset;
263static GLfloat
sun_off[4] = {0.0, 0.0, 0.0, 1.0};
266#define DOCKED_AMBIENT_LEVEL 0.2f
267#define DOCKED_ILLUM_LEVEL 0.7f
274#define SUN_AMBIENT_INFLUENCE 0.75
276#define SKY_AMBIENT_ADJUSTMENT 0.0625
283- (void) setBloom: (BOOL)newBloom
293- (void) setCurrentPostFX: (
int) newCurrentPostFX
309- (void) terminatePostFX:(
int)postFX
317- (
int) nextColorblindMode:(
int) index
325- (
int) prevColorblindMode:(
int) index
338- (void) initTargetFramebufferWithViewSize:(NSSize)viewSize
341 OOGL(glClampColor(GL_CLAMP_VERTEX_COLOR, GL_FALSE));
342 OOGL(glClampColor(GL_CLAMP_READ_COLOR, GL_FALSE));
343 OOGL(glClampColor(GL_CLAMP_FRAGMENT_COLOR, GL_FALSE));
346 OOGL(glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &defaultDrawFBO));
348 GLint previousProgramID;
349 OOGL(glGetIntegerv(GL_CURRENT_PROGRAM, &previousProgramID));
350 GLint previousTextureID;
351 OOGL(glGetIntegerv(GL_TEXTURE_BINDING_2D, &previousTextureID));
353 OOGL(glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &previousVAO));
354 GLint previousArrayBuffer;
355 OOGL(glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &previousArrayBuffer));
356 GLint previousElementBuffer;
357 OOGL(glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &previousElementBuffer));
360 OOGL(glGenFramebuffers(1, &msaaFramebufferID));
361 OOGL(glBindFramebuffer(GL_FRAMEBUFFER, msaaFramebufferID));
364 OOGL(glGenTextures(1, &msaaTextureID));
365 OOGL(glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, msaaTextureID));
366 OOGL(glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 4, GL_RGBA16F, (GLsizei)viewSize.width, (GLsizei)viewSize.height, GL_TRUE));
367 OOGL(glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, 0));
368 OOGL(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, msaaTextureID, 0));
371 OOGL(glGenRenderbuffers(1, &msaaDepthBufferID));
372 OOGL(glBindRenderbuffer(GL_RENDERBUFFER, msaaDepthBufferID));
373 OOGL(glRenderbufferStorageMultisample(GL_RENDERBUFFER, 4, GL_DEPTH_COMPONENT32F, (GLsizei)viewSize.width, (GLsizei)viewSize.height));
374 OOGL(glBindRenderbuffer(GL_RENDERBUFFER, 0));
375 OOGL(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, msaaDepthBufferID));
377 if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
379 OOLogERR(
@"initTargetFramebufferWithViewSize.result",
@"%@",
@"***** Error: Multisample framebuffer not complete");
383 OOGL(glGenFramebuffers(1, &targetFramebufferID));
384 OOGL(glBindFramebuffer(GL_FRAMEBUFFER, targetFramebufferID));
387 OOGL(glGenTextures(1, &targetTextureID));
388 OOGL(glBindTexture(GL_TEXTURE_2D, targetTextureID));
389 OOGL(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, (GLsizei)viewSize.width, (GLsizei)viewSize.height, 0, GL_RGBA, GL_FLOAT, NULL));
390 OOGL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
391 OOGL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
394 OOGL(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, targetTextureID, 0));
397 OOGL(glGenRenderbuffers(1, &targetDepthBufferID));
398 OOGL(glBindRenderbuffer(GL_RENDERBUFFER, targetDepthBufferID));
399 OOGL(glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT32F, (GLsizei)viewSize.width, (GLsizei)viewSize.height));
400 OOGL(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, targetDepthBufferID));
402 GLenum attachment[1] = { GL_COLOR_ATTACHMENT0 };
403 OOGL(glDrawBuffers(1, attachment));
405 if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
407 OOLogERR(
@"initTargetFramebufferWithViewSize.result",
@"%@",
@"***** Error: Framebuffer not complete");
410 OOGL(glBindFramebuffer(GL_FRAMEBUFFER, defaultDrawFBO));
412 targetFramebufferSize = viewSize;
420 OOGL(glGenFramebuffers(1, &passthroughFramebufferID));
421 OOGL(glBindFramebuffer(GL_FRAMEBUFFER, passthroughFramebufferID));
424 OOGL(glGenTextures(2, passthroughTextureID));
425 for (
unsigned int i = 0; i < 2; i++)
427 OOGL(glBindTexture(GL_TEXTURE_2D, passthroughTextureID[i]));
428 OOGL(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, (GLsizei)viewSize.width, (GLsizei)viewSize.height, 0, GL_RGBA, GL_FLOAT, NULL));
429 OOGL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
430 OOGL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
433 OOGL(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, passthroughTextureID[i], 0));
436 GLenum attachments[2] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 };
437 OOGL(glDrawBuffers(2, attachments));
439 if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
441 OOLogERR(
@"initTargetFramebufferWithViewSize.result",
@"%@",
@"***** Error: Passthrough framebuffer not complete");
443 OOGL(glBindFramebuffer(GL_FRAMEBUFFER, defaultDrawFBO));
446 OOGL(glGenFramebuffers(2, pingpongFBO));
447 OOGL(glGenTextures(2, pingpongColorbuffers));
448 for (
unsigned int i = 0; i < 2; i++)
450 OOGL(glBindFramebuffer(GL_FRAMEBUFFER, pingpongFBO[i]));
451 OOGL(glBindTexture(GL_TEXTURE_2D, pingpongColorbuffers[i]));
452 OOGL(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, (GLsizei)viewSize.width, (GLsizei)viewSize.height, 0, GL_RGBA, GL_FLOAT, NULL));
453 OOGL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
454 OOGL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
457 OOGL(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, pingpongColorbuffers[i], 0));
459 if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
461 OOLogERR(
@"initTargetFramebufferWithViewSize.result",
@"%@",
@"***** Error: Pingpong framebuffers not complete");
464 OOGL(glBindFramebuffer(GL_FRAMEBUFFER, defaultDrawFBO));
478 textureProgram = [[
OOShaderProgram shaderProgramWithVertexShaderName:@"oolite-texture.vertex"
479 fragmentShaderName:@"oolite-texture.fragment"
480 prefix:@"#version 330\n"
483 blurProgram = [[
OOShaderProgram shaderProgramWithVertexShaderName:@"oolite-blur.vertex"
484 fragmentShaderName:@"oolite-blur.fragment"
485 prefix:@"#version 330\n"
488 finalProgram = [[
OOShaderProgram shaderProgramWithVertexShaderName:@"oolite-final.vertex"
490 fragmentShaderName:[[UNIVERSE gameView] hdrOutput] ? @"oolite-final-hdr.fragment" : @"oolite-final.fragment"
492 fragmentShaderName:@"oolite-final.fragment"
494 prefix:@"#version 330\n"
498 OOGL(glGenVertexArrays(1, &quadTextureVAO));
499 OOGL(glGenBuffers(1, &quadTextureVBO));
500 OOGL(glGenBuffers(1, &quadTextureEBO));
502 OOGL(glBindVertexArray(quadTextureVAO));
504 OOGL(glBindBuffer(GL_ARRAY_BUFFER, quadTextureVBO));
507 OOGL(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, quadTextureEBO));
510 OOGL(glEnableVertexAttribArray(0));
512 OOGL(glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 *
sizeof(
float), (
void*)0));
513 OOGL(glEnableVertexAttribArray(1));
515 OOGL(glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 *
sizeof(
float), (
void*)(2 *
sizeof(
float))));
519 OOGL(glUseProgram(previousProgramID));
520 OOGL(glBindTexture(GL_TEXTURE_2D, previousTextureID));
521 OOGL(glBindVertexArray(previousVAO));
522 OOGL(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, previousElementBuffer));
523 OOGL(glBindBuffer(GL_ARRAY_BUFFER, previousArrayBuffer));
530 OOGL(glDeleteTextures(1, &msaaTextureID));
531 OOGL(glDeleteTextures(1, &targetTextureID));
532 OOGL(glDeleteTextures(2, passthroughTextureID));
533 OOGL(glDeleteTextures(2, pingpongColorbuffers));
534 OOGL(glDeleteRenderbuffers(1, &msaaDepthBufferID));
535 OOGL(glDeleteRenderbuffers(1, &targetDepthBufferID));
536 OOGL(glDeleteFramebuffers(1, &msaaFramebufferID));
537 OOGL(glDeleteFramebuffers(1, &targetFramebufferID));
538 OOGL(glDeleteFramebuffers(2, pingpongFBO));
539 OOGL(glDeleteFramebuffers(1, &passthroughFramebufferID));
540 OOGL(glDeleteVertexArrays(1, &quadTextureVAO));
541 OOGL(glDeleteBuffers(1, &quadTextureVBO));
542 OOGL(glDeleteBuffers(1, &quadTextureEBO));
549- (void) resizeTargetFramebufferWithViewSize:(NSSize)viewSize
553 OOGL(glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, msaaTextureID));
554 OOGL(glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 4, GL_RGBA16F, (GLsizei)viewSize.width, (GLsizei)viewSize.height, GL_TRUE));
555 OOGL(glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, 0));
558 OOGL(glBindRenderbuffer(GL_RENDERBUFFER, msaaDepthBufferID));
559 OOGL(glRenderbufferStorageMultisample(GL_RENDERBUFFER, 4, GL_DEPTH_COMPONENT32F, (GLsizei)viewSize.width, (GLsizei)viewSize.height));
560 OOGL(glBindRenderbuffer(GL_RENDERBUFFER, 0));
563 OOGL(glBindTexture(GL_TEXTURE_2D, targetTextureID));
564 OOGL(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, (GLsizei)viewSize.width, (GLsizei)viewSize.height, 0, GL_RGBA, GL_FLOAT, NULL));
565 OOGL(glBindTexture(GL_TEXTURE_2D, 0));
567 for (i = 0; i < 2; i++)
569 OOGL(glBindTexture(GL_TEXTURE_2D, pingpongColorbuffers[i]));
570 OOGL(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, (GLsizei)viewSize.width, (GLsizei)viewSize.height, 0, GL_RGBA, GL_FLOAT, NULL));
571 OOGL(glBindTexture(GL_TEXTURE_2D, 0));
574 for (i = 0; i < 2; i++)
576 OOGL(glBindTexture(GL_TEXTURE_2D, passthroughTextureID[i]));
577 OOGL(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, (GLsizei)viewSize.width, (GLsizei)viewSize.height, 0, GL_RGBA, GL_FLOAT, NULL));
578 OOGL(glBindTexture(GL_TEXTURE_2D, 0));
582 OOGL(glBindRenderbuffer(GL_RENDERBUFFER, targetDepthBufferID));
583 OOGL(glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT32F, (GLsizei)viewSize.width, (GLsizei)viewSize.height));
584 OOGL(glBindRenderbuffer(GL_RENDERBUFFER, 0));
586 targetFramebufferSize.width = viewSize.width;
587 targetFramebufferSize.height = viewSize.height;
595 OOGL(glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &previousFBO));
596 GLint previousProgramID;
597 OOGL(glGetIntegerv(GL_CURRENT_PROGRAM, &previousProgramID));
598 GLint previousTextureID;
599 OOGL(glGetIntegerv(GL_TEXTURE_BINDING_2D, &previousTextureID));
601 OOGL(glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &previousVAO));
602 GLint previousActiveTexture;
603 OOGL(glGetIntegerv(GL_ACTIVE_TEXTURE, &previousActiveTexture));
605 OOGL(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
607 OOGL(glDisable(GL_BLEND));
612 NSSize viewSize = [
gameView viewSize];
613 float fboResolution[2] = {viewSize.width, viewSize.height};
615 OOGL(glBindFramebuffer(GL_FRAMEBUFFER, passthroughFramebufferID));
616 OOGL(glClear(GL_COLOR_BUFFER_BIT));
618 OOGL(glUseProgram(program));
619 OOGL(glBindTexture(GL_TEXTURE_2D, targetTextureID));
620 OOGL(glUniform1i(glGetUniformLocation(program,
"image"), 0));
623 OOGL(glBindVertexArray(quadTextureVAO));
624 OOGL(glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0));
625 OOGL(glBindVertexArray(0));
627 OOGL(glBindFramebuffer(GL_FRAMEBUFFER, defaultDrawFBO));
630 BOOL horizontal = YES, firstIteration = YES;
631 unsigned int amount = [
self bloom] ? 10 : 0;
632 OOGL(glUseProgram(blur));
633 for (
unsigned int i = 0; i < amount; i++)
635 OOGL(glBindFramebuffer(GL_FRAMEBUFFER, pingpongFBO[horizontal]));
636 OOGL(glUniform1i(glGetUniformLocation(blur,
"horizontal"), horizontal));
637 OOGL(glActiveTexture(GL_TEXTURE0));
639 OOGL(glBindTexture(GL_TEXTURE_2D, firstIteration ? passthroughTextureID[1] : pingpongColorbuffers[!horizontal]));
640 OOGL(glUniform1i(glGetUniformLocation([blurProgram program],
"imageIn"), 0));
641 OOGL(glBindVertexArray(quadTextureVAO));
642 OOGL(glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0));
643 OOGL(glBindVertexArray(0));
644 horizontal = !horizontal;
647 OOGL(glBindFramebuffer(GL_FRAMEBUFFER, defaultDrawFBO));
650 OOGL(glUseProgram(
final));
652 OOGL(glActiveTexture(GL_TEXTURE0));
653 OOGL(glBindTexture(GL_TEXTURE_2D, passthroughTextureID[0]));
654 OOGL(glUniform1i(glGetUniformLocation(
final,
"scene"), 0));
655 OOGL(glUniform1i(glGetUniformLocation(
final,
"bloom"), [
self bloom]));
656 OOGL(glUniform1f(glGetUniformLocation(
final,
"uTime"), [
self getTime]));
657 OOGL(glUniform2fv(glGetUniformLocation(
final,
"uResolution"), 1, fboResolution));
658 OOGL(glUniform1i(glGetUniformLocation(
final,
"uPostFX"), [
self currentPostFX]));
660 if([gameView hdrOutput])
662 OOGL(glUniform1f(glGetUniformLocation(
final,
"uMaxBrightness"), [gameView hdrMaxBrightness]));
663 OOGL(glUniform1f(glGetUniformLocation(
final,
"uPaperWhiteBrightness"), [gameView hdrPaperWhiteBrightness]));
664 OOGL(glUniform1i(glGetUniformLocation(
final,
"uHDRToneMapper"), [gameView hdrToneMapper]));
667 OOGL(glUniform1i(glGetUniformLocation(
final,
"uSDRToneMapper"), [gameView sdrToneMapper]));
669 OOGL(glActiveTexture(GL_TEXTURE1));
670 OOGL(glBindTexture(GL_TEXTURE_2D, pingpongColorbuffers[!horizontal]));
671 OOGL(glUniform1i(glGetUniformLocation(
final,
"bloomBlur"), 1));
672 OOGL(glUniform1f(glGetUniformLocation(
final,
"uSaturation"), [gameView colorSaturation]));
674 OOGL(glBindVertexArray(quadTextureVAO));
675 OOGL(glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0));
679 OOGL(glBindTexture(GL_TEXTURE_2D, 0));
682 OOGL(glBindFramebuffer(GL_FRAMEBUFFER, previousFBO));
683 OOGL(glActiveTexture(previousActiveTexture));
684 OOGL(glBindTexture(GL_TEXTURE_2D, previousTextureID));
685 OOGL(glUseProgram(previousProgramID));
686 OOGL(glBindVertexArray(previousVAO));
687 OOGL(glEnable(GL_BLEND));
695 [
NSException raise:NSInternalInconsistencyException format:@"%s: expected only one Universe to exist at a time.", __PRETTY_FUNCTION__];
701 if (
self ==
nil)
return nil;
734#if OOLITE_SPEECH_SYNTH
735 OOLog(
@"speech.synthesis",
@"Spoken messages are %@.", ([prefs oo_boolForKey:
@"speech_on" defaultValue:NO] ?
@"on" :
@"off"));
748 autoSave = [
prefs oo_boolForKey:@"autosave" defaultValue:NO];
753 OOLog(
@"MSAA.setup",
@"Multisample anti-aliasing %@requested.", [inGameView msaa] ?
@"" :
@"not ");
760#if OOLITE_SPEECH_SYNTH
762 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0),
772 OOLog(
@"speech.setup.begin",
@"Starting to set up speech synthesizer.");
774 OOLog(
@"speech.setup.end",
@"Finished setting up speech synthesizer.");
779 if (!SDL_getenv(
"ESPEAK_DATA_PATH"))
781 espeak_Initialize(AUDIO_OUTPUT_PLAYBACK, 100, [[
ResourceManager builtInPath] UTF8String], 0);
785 espeak_Initialize(AUDIO_OUTPUT_PLAYBACK, 100, NULL, 0);
787 espeak_SetParameter(espeakPUNCTUATION, espeakPUNCT_NONE, 0);
788 espeak_SetParameter(espeakVOLUME, volume, 0);
789 espeak_voices = espeak_ListVoices(NULL);
790 for (espeak_voice_count = 0;
792 ++espeak_voice_count)
851#if OO_LOCALIZATION_TOOLS
854 [
self dumpDebugGraphViz];
869 [currentMessage release];
879 [_descriptions release];
880 [characters release];
881 [customSounds release];
882 [globalSettings release];
884 [missiontext release];
885 [equipmentData release];
886 [equipmentDataOutfitting release];
887 [demo_ships release];
889 [screenBackgrounds release];
891 [populatorSettings release];
892 [system_repopulator release];
893 [allPlanets release];
894 [allStations release];
895 [explosionSettings release];
897 [activeWormholes release];
898 [characterPool release];
909 [entitiesDeadThisUpdate release];
913#if OOLITE_SPEECH_SYNTH
914 [speechArray release];
916 [speechSynthesizer release];
921 [conditionScripts release];
947- (void) setDoProcedurallyTexturedPlanets:(BOOL) value
950 [[
NSUserDefaults standardUserDefaults] setBool:doProcedurallyTexturedPlanets forKey:@"procedurally-textured-planets"];
960- (BOOL) setUseAddOns:(NSString *) newUse fromSaveGame:(BOOL) saveGame
966- (BOOL) setUseAddOns:(NSString *) newUse fromSaveGame:(BOOL) saveGame forceReinit:(BOOL)force
968 if (!force && [newUse isEqualToString:
useAddOns])
982 return [entities count];
997 for (i = 0; i < show_count; i++)
999 OOLog(
@"universe.objectDump",
@"Ent:%4u %@", i, [
sortedEntities[i] descriptionForObjDump]);
1005 OOLog(
@"universe.objectDump",
@"entities = %@", [
entities description]);
1012 return [
NSArray arrayWithArray:entities];
1023 NSString *pauseKey = [PLAYER keyBindingDescription2:@"key_pausebutton"];
1025 if ([player status] == STATUS_DOCKED)
1027 if ([
gui setForegroundTextureKey:
@"paused_docked_overlay"])
1039 if ([player guiScreen] != GUI_SCREEN_MAIN && [
gui setForegroundTextureKey:
@"paused_overlay"])
1064 ShipScriptEvent(context, player,
"shipWillEnterWitchspace", STRING_TO_JSVAL(JS_InternString(context, [[player jumpCause] UTF8String])), INT_TO_JSVAL(dest));
1079 if (![wormhole withMisjump])
1102 [UNIVERSE setSkyColorRed:0.0f
1130 if (dockedStation && !interstel)
1138 Entity *ent = [entities objectAtIndex:index];
1139 if ((ent != player)&&(ent != dockedStation))
1156 if (!dockedStation || !interstel)
1162 if ([dockedStation maxFlightSpeed] > 0)
1165 HPVector pos = [UNIVERSE getWitchspaceExitPosition];
1169 if (abs((
int)d1) < 2750)
1171 d1 += ((d1 > 0.0)? 2750.0f: -2750.0f);
1192 [UNIVERSE setSkyColorRed:0.0f
1217 player = [PLAYER retain];
1253 player = [PLAYER retain];
1295 thing = [[
SkyEntity alloc] initWithColors:col1:col2 andSystemInfo: systeminfo];
1315 NSString *populator = [
systeminfo oo_stringForKey:@"populator" defaultValue:@"interstellarSpaceWillPopulate"];
1316 [system_repopulator release];
1319 [PLAYER doWorldScriptEvent:OOJSIDFromString(populator) inContext:context withArguments:NULL count:0 timeLimit:kOOJSLongTimeLimit];
1324 NSArray *script_actions = [
systeminfo oo_arrayForKey:@"script_actions"];
1325 if (script_actions !=
nil)
1327 OOStandardsDeprecated([NSString stringWithFormat:
@"The script_actions system info key is deprecated for %@.",override_key]);
1350 [
planetDict oo_setBool:YES forKey:@"mainForLocalSystem"];
1351 OOPlanetEntity *a_planet = [[
OOPlanetEntity alloc] initFromDictionary:planetDict withAtmosphere:[
planetDict oo_boolForKey:@"has_atmosphere" defaultValue:YES] andSeed:systemSeed forSystem:systemID];
1353 double planet_zpos = [
planetDict oo_floatForKey:@"planet_distance" defaultValue:500000];
1354 planet_zpos *= [
planetDict oo_floatForKey:@"planet_distance_multiplier" defaultValue:1.0];
1356#ifdef OO_DUMP_PLANETINFO
1357 OOLog(
@"planetinfo.record",
@"planet zpos = %f",planet_zpos);
1364 OOPlanetEntity *tmp=[allPlanets objectAtIndex:0];
1366 [allPlanets removeObject:a_planet];
1368 [allPlanets replaceObjectAtIndex:0 withObject:a_planet];
1387 OOPlanetEntity *a_planet;
1389 HPVector stationPos;
1395 unsigned techlevel = [
systeminfo oo_unsignedIntForKey:KEY_TECHLEVEL];
1396 NSString *stationDesc =
nil, *defaultStationDesc =
nil;
1405 sunGoneNova = [
systeminfo oo_boolForKey:@"sun_gone_nova" defaultValue:NO];
1417#ifdef OO_DUMP_PLANETINFO
1418 OOLog(
@"planetinfo.record",
@"seed = %d %d %d %d",system_seed.c,system_seed.d,system_seed.e,system_seed.f);
1419 OOLog(
@"planetinfo.record",
@"coordinates = %d %d",system_seed.d,system_seed.b);
1421#define SPROP(PROP) OOLog(@"planetinfo.record",@#PROP " = \"%@\";",[systeminfo oo_stringForKey:@"" #PROP]);
1422#define IPROP(PROP) OOLog(@"planetinfo.record",@#PROP " = %d;",[systeminfo oo_intForKey:@#PROP]);
1423#define FPROP(PROP) OOLog(@"planetinfo.record",@#PROP " = %f;",[systeminfo oo_floatForKey:@"" #PROP]);
1428 IPROP(productivity);
1441 float h2 = h1 + 1.0 / (1.0 + (
Ranrot() % 5));
1447 thing = [[
SkyEntity alloc] initWithColors:col1:col2 andSystemInfo: systeminfo];
1462 dict_object=[
systeminfo objectForKey:@"sun_color"];
1463 if (dict_object!=
nil)
1484 float defaultSunFlare =
randf()*0.1;
1485 float defaultSunHues = 0.5+
randf()*0.5;
1492 double planet_radius = [
a_planet radius];
1501 double sun_distance;
1502 double sunDistanceModifier;
1503 double safeDistance;
1506 sunDistanceModifier = [
systeminfo oo_nonNegativeDoubleForKey:@"sun_distance_modifier" defaultValue:0.0];
1507 if (sunDistanceModifier < 6.0)
1509 sun_distance = [
systeminfo oo_nonNegativeDoubleForKey:@"sun_distance" defaultValue:(planet_radius*20)];
1511 sun_distance *= [
systeminfo oo_nonNegativeDoubleForKey:@"sun_distance_multiplier" defaultValue:1];
1515 sun_distance = planet_radius * sunDistanceModifier;
1518 sun_radius = [
systeminfo oo_nonNegativeDoubleForKey:@"sun_radius" defaultValue:2.5 * planet_radius];
1520 if ((sun_radius < 1000.0) || (sun_radius > sun_distance / 2 && !sunGoneNova))
1522 OOLogWARN(
@"universe.setup.badSun",
@"Sun radius of %f is not valid for this system",sun_radius);
1523 sun_radius = sun_radius < 1000.0 ? 1000.0 : (sun_distance / 2);
1525#ifdef OO_DUMP_PLANETINFO
1526 OOLog(
@"planetinfo.record",
@"sun_radius = %f",sun_radius);
1528 safeDistance=36 * sun_radius * sun_radius;
1532 HPVector sun_dir = [
systeminfo oo_hpvectorForKey:@"sun_vector"];
1533 sun_distance /= 2.0;
1536 sun_distance *= 2.0;
1537 sunPos = HPvector_subtract([a_planet position],
1538 HPvector_multiply_scalar(sun_dir,sun_distance));
1542 while (HPmagnitude2(sunPos) < safeDistance);
1546 [
a_planet setOrientation:quaternion_rotation_betweenHP(sun_dir,make_HPvector(1.0,0.0,0.0))];
1548#ifdef OO_DUMP_PLANETINFO
1549 OOLog(
@"planetinfo.record",
@"sun_vector = %.3f %.3f %.3f",vf.x,vf.y,vf.z);
1550 OOLog(
@"planetinfo.record",
@"sun_distance = %.0f",sun_distance);
1556 [
sun_dict setObject:[
NSNumber numberWithDouble:sun_radius] forKey:@"sun_radius"];
1557 dict_object=[
systeminfo objectForKey: @"corona_shimmer"];
1558 if (dict_object!=
nil) [
sun_dict setObject:dict_object forKey:@"corona_shimmer"];
1559 dict_object=[
systeminfo objectForKey: @"corona_hues"];
1560 if (dict_object!=
nil)
1562 [
sun_dict setObject:dict_object forKey:@"corona_hues"];
1566 [
sun_dict setObject:[
NSNumber numberWithFloat:defaultSunHues] forKey:@"corona_hues"];
1568 dict_object=[
systeminfo objectForKey: @"corona_flare"];
1569 if (dict_object!=
nil)
1571 [
sun_dict setObject:dict_object forKey:@"corona_flare"];
1575 [
sun_dict setObject:[
NSNumber numberWithFloat:defaultSunFlare] forKey:@"corona_flare"];
1577 dict_object=[
systeminfo objectForKey:KEY_SUNNAME];
1578 if (dict_object!=
nil)
1580 [
sun_dict setObject:dict_object forKey:KEY_SUNNAME];
1582#ifdef OO_DUMP_PLANETINFO
1583 OOLog(
@"planetinfo.record",
@"corona_flare = %f",[sun_dict oo_floatForKey:
@"corona_flare"]);
1584 OOLog(
@"planetinfo.record",
@"corona_hues = %f",[sun_dict oo_floatForKey:
@"corona_hues"]);
1585 OOLog(
@"planetinfo.record",
@"sun_color = %@",[bgcolor descriptionComponents]);
1587 a_sun = [[
OOSunEntity alloc] initSunWithColor:bgcolor andDictionary:sun_dict];
1609 vf = [
systeminfo oo_vectorForKey:@"station_vector"];
1610#ifdef OO_DUMP_PLANETINFO
1611 OOLog(
@"planetinfo.record",
@"station_vector = %.3f %.3f %.3f",vf.x,vf.y,vf.z);
1613 stationPos = HPvector_subtract(stationPos, vectorToHPVector(vector_multiply_scalar(vf, 2.0 * planet_radius)));
1617 stationDesc = [
systeminfo oo_stringForKey:@"station" defaultValue:@"coriolis"];
1618#ifdef OO_DUMP_PLANETINFO
1619 OOLog(
@"planetinfo.record",
@"station = %@",stationDesc);
1622 a_station = (
StationEntity *)[
self newShipWithRole:stationDesc];
1634 if (![a_station isStation] || ![a_station validForAddToUniverse])
1636 if (a_station ==
nil)
1639 OOLog(
@"universe.setup.badStation",
@"Failed to set up a ship for role \"%@\
" as system station, trying again with \"%@\".", stationDesc, defaultStationDesc);
1643 OOLog(
@"universe.setup.badStation",
@"***** ERROR: Attempt to use non-station ship of type \"%@\
" for role \"%@\" as system station, trying again with \"%@\".", [a_station name], stationDesc, defaultStationDesc);
1646 stationDesc = defaultStationDesc;
1647 a_station = (
StationEntity *)[
self newShipWithRole:stationDesc];
1649 if (![a_station isStation] || ![a_station validForAddToUniverse])
1651 if (a_station ==
nil)
1653 OOLog(
@"universe.setup.badStation",
@"On retry, failed to set up a ship for role \"%@\
" as system station. Trying to fall back to built-in Coriolis station.", stationDesc);
1657 OOLog(
@"universe.setup.badStation",
@"***** ERROR: On retry, rolled non-station ship of type \"%@\
" for role \"%@\". Non-station ships should not have this role! Trying to fall back to built-in Coriolis station.", [a_station name], stationDesc);
1661 a_station = (
StationEntity *)[
self newShipWithName:
@"coriolis-station"];
1662 if (![a_station isStation] || ![a_station validForAddToUniverse])
1664 OOLog(
@"universe.setup.badStation",
@"%@",
@"Could not create built-in Coriolis station! Generating a stationless system.");
1670 if (a_station !=
nil)
1705 BOOL sunGoneNova = [
systeminfo oo_boolForKey:@"sun_gone_nova"];
1711 HPVector v0 = make_HPvector(0,0,34567.89);
1712 double min_safe_dist2 = 6000000.0 * 6000000.0;
1714 while (HPmagnitude2(
cachedSun->position) < min_safe_dist2)
1718 sunPos = HPvector_add(sunPos, v0);
1733 if ([
PLAYER status] != STATUS_START_GAME)
1735 NSString *populator = [
systeminfo oo_stringForKey:@"populator" defaultValue:(sunGoneNova)?@"novaSystemWillPopulate":@"systemWillPopulate"];
1736 [system_repopulator release];
1737 system_repopulator = [[
systeminfo oo_stringForKey:@"repopulator" defaultValue:(sunGoneNova)?@"novaSystemWillRepopulate":@"systemWillRepopulate"] retain];
1740 [PLAYER doWorldScriptEvent:OOJSIDFromString(populator) inContext:context withArguments:NULL count:0 timeLimit:kOOJSLongTimeLimit];
1748 NSArray *script_actions = [
systeminfo oo_arrayForKey:@"script_actions"];
1749 if (script_actions !=
nil)
1751 OOStandardsDeprecated([NSString stringWithFormat:
@"The script_actions system info key is deprecated for %@.",[
self getSystemName:
systemID]]);
1755 [PLAYER runUnsanitizedScriptActions:script_actions
1756 allowingAIMethods:NO
1757 withContextName:@"<system script_actions>"
1769 [populatorSettings release];
1780- (void) setPopulatorSetting:(NSString *)key to:(NSDictionary *)setting
1784 [populatorSettings removeObjectForKey:key];
1788 [populatorSettings setObject:setting forKey:key];
1799- (void) populateSystemFromDictionariesWithSun:(
OOSunEntity *)sun andPlanet:(OOPlanetEntity *)planet
1802 NSArray *blocks = [populatorSettings allValues];
1803 NSEnumerator *enumerator = [[
blocks sortedArrayUsingFunction:populatorPrioritySort context:nil] objectEnumerator];
1804 NSDictionary *populator =
nil;
1806 uint32_t i, locationSeed, groupCount, rndvalue;
1809 NSString *locationCode =
nil;
1811 while ((populator = [enumerator nextObject]))
1820 locationSeed = [
populator oo_unsignedIntForKey:@"locationSeed" defaultValue:0];
1821 groupCount = [
populator oo_unsignedIntForKey:@"groupCount" defaultValue:1];
1823 for (i = 0; i < groupCount; i++)
1825 locationCode = [
populator oo_stringForKey:@"location" defaultValue:@"COORDINATES"];
1826 if ([locationCode isEqualToString:
@"COORDINATES"])
1828 location = [
populator oo_hpvectorForKey:@"coordinates" defaultValue:kZeroHPVector];
1832 if (locationSeed != 0)
1859 if(locationSeed != 0)
1866 pdef = [
populator objectForKey:@"callbackObj"];
1889- (HPVector) locationByCode:(NSString *)code withSun:(
OOSunEntity *)sun andPlanet:(OOPlanetEntity *)planet
1892 if ([code isEqualToString:
@"WITCHPOINT"] ||
sun ==
nil ||
planet ==
nil || [
sun goneNova])
1899 if ([code isEqualToString:
@"LANE_WPS"])
1902 double l1 = HPmagnitude([
planet position]);
1903 double l2 = HPmagnitude(HPvector_subtract([
sun position],[
planet position]));
1904 double l3 = HPmagnitude([
sun position]);
1905 double total = l1+l2+l3;
1906 float choice =
randf();
1907 if (choice < l1/total)
1911 else if (choice < (l1+l2)/total)
1920 else if ([code isEqualToString:
@"LANE_WP"])
1924 else if ([code isEqualToString:
@"LANE_WS"])
1928 else if ([code isEqualToString:
@"LANE_PS"])
1932 else if ([code isEqualToString:
@"STATION_AEGIS"])
1940 else if ([code isEqualToString:
@"PLANET_ORBIT_LOW"])
1944 else if ([code isEqualToString:
@"PLANET_ORBIT"])
1948 else if ([code isEqualToString:
@"PLANET_ORBIT_HIGH"])
1952 else if ([code isEqualToString:
@"STAR_ORBIT_LOW"])
1956 else if ([code isEqualToString:
@"STAR_ORBIT"])
1960 else if ([code isEqualToString:
@"STAR_ORBIT_HIGH"])
1964 else if ([code isEqualToString:
@"TRIANGLE"])
1977 result = HPvector_add(HPvector_multiply_scalar([
planet position],r),HPvector_multiply_scalar([
sun position],s));
1982 else if ([code isEqualToString:
@"INNER_SYSTEM"])
1989 }
while (HPdistance2(result,[
sun position]) < [
sun radius]*[
sun radius]*9.0);
1991 else if ([code isEqualToString:
@"INNER_SYSTEM_OFFPLANE"])
1995 else if ([code isEqualToString:
@"OUTER_SYSTEM"])
2001 else if ([code isEqualToString:
@"OUTER_SYSTEM_OFFPLANE"])
2015- (void) setAmbientLightLevel:(
float)newValue
2017 NSAssert(
UNIVERSE !=
nil,
@"Attempt to set ambient light level with a non yet existent universe.");
2050 GLfloat sun_pos[] = {0.0, 0.0, 0.0, 1.0};
2051 GLfloat sun_ambient[] = {0.0, 0.0, 0.0, 1.0};
2062 OOGL(glLightfv(GL_LIGHT1, GL_AMBIENT, sun_ambient));
2075 OOGL(glLightfv(GL_LIGHT1, GL_AMBIENT, sun_ambient));
2080 OOGL(glLightfv(GL_LIGHT1, GL_POSITION, sun_pos));
2113- (void) setMainLightPosition: (Vector) sunPos
2122- (
ShipEntity *) addShipWithRole:(NSString *)desc launchPos:(HPVector)launchPos rfactor:(GLfloat)rfactor
2127 launchPos.x += 2 * rfactor * (
randf() - 0.5);
2128 launchPos.y += 2 * rfactor * (
randf() - 0.5);
2129 launchPos.z += 2 * rfactor * (
randf() - 0.5);
2142 if (![ship crew] && ![ship isUnpiloted])
2147 if ([ship scanClass] == CLASS_NOT_SET)
2159- (void) addShipWithRole:(NSString *) desc nearRouteOneAt:(
double) route_fraction
2175- (HPVector) coordinatesForPosition:(HPVector) pos withCoordinateSystem:(NSString *) system returningScalar:(GLfloat*) my_scalar
2212 NSString* l_sys = [
system lowercaseString];
2213 if ([l_sys length] != 3)
2215 OOPlanetEntity* the_planet = [
self planet];
2217 if (the_planet ==
nil || the_sun ==
nil || [l_sys isEqualToString:
@"abs"])
2219 if (my_scalar) *my_scalar = 1.0;
2223 HPVector p_pos = the_planet->
position;
2224 HPVector s_pos = the_sun->
position;
2226 const char* c_sys = [
l_sys UTF8String];
2227 HPVector p0, p1, p2;
2236 p1 = p_pos; p2 = s_pos;
break;
2238 p1 = s_pos; p2 = p_pos;
break;
2248 p1 = w_pos; p2 = s_pos;
break;
2250 p1 = s_pos; p2 = w_pos;
break;
2260 p1 = w_pos; p2 = p_pos;
break;
2262 p1 = p_pos; p2 = w_pos;
break;
2270 HPVector k = HPvector_normal_or_zbasis(HPvector_subtract(p1, p0));
2271 HPVector v = HPvector_normal_or_xbasis(HPvector_subtract(p2, p0));
2273 HPVector j = HPcross_product(k, v);
2274 HPVector i = HPcross_product(j, k);
2276 GLfloat scale = 1.0;
2288 scale = HPmagnitude(HPvector_subtract(p1, p0));
2302 HPVector result = p0;
2303 result.x += scale * (pos.x * i.x + pos.y * j.x + pos.z * k.x);
2304 result.y += scale * (pos.x * i.y + pos.y * j.y + pos.z * k.y);
2305 result.z += scale * (pos.x * i.z + pos.y * j.z + pos.z * k.z);
2311- (NSString *) expressPosition:(HPVector) pos inCoordinateSystem:(NSString *) system
2314 return [
NSString stringWithFormat:@"%@ %.2f %.2f %.2f", system, result.x, result.y, result.z];
2318- (HPVector) legacyPositionFrom:(HPVector) pos asCoordinateSystem:(NSString *) system
2320 NSString* l_sys = [
system lowercaseString];
2321 if ([l_sys length] != 3)
2323 OOPlanetEntity* the_planet = [
self planet];
2325 if (the_planet ==
nil || the_sun ==
nil || [l_sys isEqualToString:
@"abs"])
2330 HPVector p_pos = the_planet->
position;
2331 HPVector s_pos = the_sun->
position;
2333 const char* c_sys = [
l_sys UTF8String];
2334 HPVector p0, p1, p2;
2343 p1 = p_pos; p2 = s_pos;
break;
2345 p1 = s_pos; p2 = p_pos;
break;
2355 p1 = w_pos; p2 = s_pos;
break;
2357 p1 = s_pos; p2 = w_pos;
break;
2367 p1 = w_pos; p2 = p_pos;
break;
2369 p1 = p_pos; p2 = w_pos;
break;
2377 HPVector k = HPvector_normal_or_zbasis(HPvector_subtract(p1, p0));
2378 HPVector v = HPvector_normal_or_xbasis(HPvector_subtract(p2, p0));
2380 HPVector j = HPcross_product(k, v);
2381 HPVector i = HPcross_product(j, k);
2383 GLfloat scale = 1.0;
2398 scale = 1.0f / HPdistance(p1, p0);
2410 HPVector r_pos = HPvector_subtract(pos, p0);
2411 HPVector result = make_HPvector(scale * (r_pos.x * i.x + r_pos.y * i.y + r_pos.z * i.z),
2412 scale * (r_pos.x * j.x + r_pos.y * j.y + r_pos.z * j.z),
2413 scale * (r_pos.x * k.x + r_pos.y * k.y + r_pos.z * k.z) );
2419- (HPVector) coordinatesFromCoordinateSystemString:(NSString *) system_x_y_z
2422 if ([tokens
count] != 4)
2425 return make_HPvector(0,0,0);
2432- (BOOL) addShipWithRole:(NSString *) desc nearPosition:(HPVector) pos withCoordinateSystem:(NSString *) system
2435 GLfloat scalar = 1.0;
2438 GLfloat rfactor = scalar;
2444 return ([
self addShipWithRole:desc launchPos:launchPos rfactor:rfactor] !=
nil);
2448- (BOOL) addShips:(
int) howMany withRole:(NSString *) desc atPosition:(HPVector) pos withCoordinateSystem:(NSString *) system
2451 GLfloat scalar = 1.0;
2453 GLfloat distance_from_center = 0.0;
2454 HPVector v_from_center, ship_pos;
2455 HPVector ship_positions[
howMany];
2457 int scale_up_after = 0;
2458 int current_shell = 0;
2459 GLfloat walk_factor = 2.0;
2463 if (ship ==
nil)
return NO;
2469 int limit_count = 8;
2476 v_from_center.x += walk_factor * (
randf() - 0.5);
2477 v_from_center.y += walk_factor * (
randf() - 0.5);
2478 v_from_center.z += walk_factor * (
randf() - 0.5);
2479 }
while ((v_from_center.x == 0.0)&&(v_from_center.y == 0.0)&&(v_from_center.z == 0.0));
2480 v_from_center = HPvector_normal(v_from_center);
2482 ship_pos = make_HPvector( launchPos.x + distance_from_center * v_from_center.x,
2483 launchPos.y + distance_from_center * v_from_center.y,
2484 launchPos.z + distance_from_center * v_from_center.z);
2489 while (safe && (j >= current_shell))
2491 safe = (safe && (HPdistance2(ship_pos, ship_positions[j]) > safe_distance2));
2500 distance_from_center += sqrt(safe_distance2);
2507 [
ship setScanClass:scanClass == CLASS_NOT_SET ? CLASS_NEUTRAL : scanClass];
2515 ship_positions[
i] = ship_pos;
2517 if (i > scale_up_after)
2520 scale_up_after += 1 + 2 * i;
2521 distance_from_center += sqrt(safe_distance2);
2528- (BOOL) addShips:(
int) howMany withRole:(NSString *) desc nearPosition:(HPVector) pos withCoordinateSystem:(NSString *) system
2531 GLfloat scalar = 1.0;
2533 GLfloat rfactor = scalar;
2538 BoundingBox launch_bbox;
2539 bounding_box_reset_to_vector(&launch_bbox, make_vector(launchPos.x - rfactor, launchPos.y - rfactor, launchPos.z - rfactor));
2540 bounding_box_add_xyz(&launch_bbox, launchPos.x + rfactor, launchPos.y + rfactor, launchPos.z + rfactor);
2546- (BOOL) addShips:(
int) howMany withRole:(NSString *) desc nearPosition:(HPVector) pos withCoordinateSystem:(NSString *) system withinRadius:(GLfloat) radius
2549 GLfloat scalar = 1.0;
2551 GLfloat rfactor = radius;
2554 BoundingBox launch_bbox;
2555 bounding_box_reset_to_vector(&launch_bbox, make_vector(launchPos.x - rfactor, launchPos.y - rfactor, launchPos.z - rfactor));
2556 bounding_box_add_xyz(&launch_bbox, launchPos.x + rfactor, launchPos.y + rfactor, launchPos.z + rfactor);
2562- (BOOL) addShips:(
int) howMany withRole:(NSString *) desc intoBoundingBox:(BoundingBox) bbox
2569 int h0 = howMany / 2;
2570 int h1 = howMany - h0;
2572 GLfloat lx = bbox.max.x - bbox.min.x;
2573 GLfloat ly = bbox.max.y - bbox.min.y;
2574 GLfloat lz = bbox.max.z - bbox.min.z;
2575 BoundingBox bbox0 = bbox;
2576 BoundingBox bbox1 = bbox;
2577 if ((lx > lz)&&(lx > ly))
2579 bbox0.min.x += 0.5 * lx;
2580 bbox1.max.x -= 0.5 * lx;
2586 bbox0.min.y += 0.5 * ly;
2587 bbox1.max.y -= 0.5 * ly;
2591 bbox0.min.z += 0.5 * lz;
2592 bbox1.max.z -= 0.5 * lz;
2596 return ([
self addShips: h0 withRole: desc intoBoundingBox: bbox0] && [
self addShips: h1 withRole: desc intoBoundingBox: bbox1]);
2600 HPVector pos = make_HPvector(bbox.min.x, bbox.min.y, bbox.min.z);
2601 pos.x += 0.5 * (
randf() +
randf()) * (bbox.max.x - bbox.min.x);
2602 pos.y += 0.5 * (
randf() +
randf()) * (bbox.max.y - bbox.min.y);
2603 pos.z += 0.5 * (
randf() +
randf()) * (bbox.max.z - bbox.min.z);
2605 return ([
self addShipWithRole:desc launchPos:pos rfactor:0.0] !=
nil);
2609- (BOOL) spawnShip:(NSString *) shipdesc
2613 OOStandardsDeprecated([NSString stringWithFormat:
@"'spawn' via legacy script is deprecated as a way of adding ships for %@",shipdesc]);
2616 NSDictionary *shipdict =
nil;
2619 if (shipdict ==
nil)
return NO;
2623 if (ship ==
nil)
return NO;
2626 NSDictionary *spawndict = [
shipdict oo_dictionaryForKey:@"spawn"];
2627 HPVector pos, rpos, spos;
2628 NSString *positionString =
nil;
2631 positionString = [
spawndict oo_stringForKey:@"position"];
2632 if (positionString !=
nil)
2634 if([positionString hasPrefix:
@"abs "] && ([
self planet] !=
nil || [
self sun] !=
nil))
2636 OOLogWARN(
@"script.deprecated",
@"setting %@ for %@ '%@' in 'abs' inside .plists can cause compatibility issues across Oolite versions. Use coordinates relative to main system objects instead.",
@"position",
@"entity",shipdesc);
2645 OOLogERR(
@"universe.spawnShip.error",
@"***** ERROR: failed to find a spawn position for ship %@.", shipdesc);
2650 positionString = [
spawndict oo_stringForKey:@"facing_position"];
2651 if (positionString !=
nil)
2653 if([positionString hasPrefix:
@"abs "] && ([
self planet] !=
nil || [
self sun] !=
nil))
2655 OOLogWARN(
@"script.deprecated",
@"setting %@ for %@ '%@' in 'abs' inside .plists can cause compatibility issues across Oolite versions. Use coordinates relative to main system objects instead.",
@"facing_position",
@"entity",shipdesc);
2661 rpos = HPvector_subtract(rpos, spos);
2665 rpos = HPvector_normal(rpos);
2674 q1 = make_quaternion(0,1,0,0);
2689- (void) witchspaceShipWithPrimaryRole:(NSString *)role
2693 NSDictionary *systeminfo =
nil;
2697 government = [
systeminfo oo_unsignedCharForKey:KEY_GOVERNMENT];
2702 if (ship && [ship hasRole:
@"cargopod"])
2709 if (([ship scanClass] == CLASS_NO_DRAW)||([ship scanClass] == CLASS_NOT_SET))
2711 if ([role isEqual:
@"trader"])
2714 if ([ship hasRole:
@"sunskim-trader"] &&
randf() < 0.25)
2724 if (([ship pendingEscortCount] > 0)&&((
Ranrot() % 7) < government))
2727 [
ship setPendingEscortCount:(nx > 0) ? nx : 0];
2730 if ([role isEqual:
@"pirate"])
2733 [
ship setBounty: (Ranrot() & 7) + (Ranrot() & 7) + ((randf() < 0.05)? 63 : 23)
withReason:kOOLegalStatusReasonSetup];
2735 if ([ship crew] ==
nil && ![ship isUnpiloted])
2749 if (entity ==
nil)
return nil;
2776 [
vis setPosition:pos];
2777 [
vis setOrientation:OORandomQuaternion()];
2789- (
ShipEntity *) addShipAt:(HPVector)pos withRole:(NSString *)role withinRadius:(GLfloat)radius
2794 if (radius == NSNotFound)
2796 GLfloat scalar = 1.0;
2799 GLfloat rfactor = scalar;
2821 if (scanClass == CLASS_NOT_SET)
2823 scanClass = CLASS_NEUTRAL;
2827 if ([ship crew] ==
nil && ![ship isUnpiloted])
2836 BOOL trader = [
role isEqualToString:@"trader"];
2846 if (pendingEscortCount > 0)
2849 if ((
Ranrot() % 7) < government)
2851 int nx = pendingEscortCount - 2 * (1 + (
Ranrot() & 3));
2852 [
ship setPendingEscortCount:(nx > 0) ? nx : 0];
2867 if ([ship hasRole:
@"sunskim-trader"] &&
randf() < 0.25)
2877 else if ([role isEqual:
@"pirate"])
2879 [
ship setBounty:(Ranrot() & 7) + (Ranrot() & 7) + ((randf() < 0.05)? 63 : 23)
withReason:kOOLegalStatusReasonSetup];
2896- (NSArray *) addShipsAt:(HPVector)pos withRole:(NSString *)role quantity:(
unsigned)count withinRadius:(GLfloat)radius asGroup:(BOOL)isGroup
2900 NSMutableArray *ships = [
NSMutableArray arrayWithCapacity:count];
2916 [
ships addObject:ship];
2920 if ([ships
count] == 0)
return nil;
2922 return [[
ships copy] autorelease];
2928- (NSArray *) addShipsToRoute:(NSString *)route withRole:(NSString *)role quantity:(
unsigned)count routeFraction:(
double)routeFraction asGroup:(BOOL)isGroup
2930 NSMutableArray *ships = [
NSMutableArray arrayWithCapacity:count];
2936 if ([route isEqualToString:
@"pw"] || [route isEqualToString:
@"sw"] || [route isEqualToString:
@"ps"])
2938 routeFraction = 1.0f - routeFraction;
2942 if ([route isEqualTo:
@"wp"] || [route isEqualTo:
@"pw"])
2946 if (entity ==
nil)
return nil;
2948 radius = [
entity radius];
2950 else if ([route isEqualTo:
@"ws"] || [route isEqualTo:
@"sw"])
2953 entity = [
self sun];
2954 if (entity ==
nil)
return nil;
2956 radius = [
entity radius];
2958 else if ([route isEqualTo:
@"sp"] || [route isEqualTo:
@"ps"])
2960 entity = [
self sun];
2961 if (entity ==
nil)
return nil;
2963 double radius0 = [
entity radius];
2966 if (entity ==
nil)
return nil;
2968 radius = [
entity radius];
2971 direction = HPvector_normal(HPvector_subtract(point0, point1));
2972 point0 = HPvector_subtract(point0, HPvector_multiply_scalar(direction, radius0 +
SCANNER_MAX_RANGE * 1.1f));
2974 else if ([route isEqualTo:
@"st"])
2984 direction = HPvector_normal(HPvector_subtract(point1, point0));
2985 point1 = HPvector_subtract(point1, HPvector_multiply_scalar(direction, radius +
SCANNER_MAX_RANGE * 1.1f));
2997 if (ship !=
nil) [
ships addObject:ship];
3001 if ([ships
count] == 0)
return nil;
3004 return [[
ships copy] autorelease];
3008- (BOOL) roleIsPirateVictim:(NSString *)role
3014- (BOOL) role:(NSString *)role isInCategory:(NSString *)category
3016 NSSet *categoryInfo = [roleCategories objectForKey:category];
3017 if (categoryInfo ==
nil)
3035 if ([my_target isWormhole])
3039 else if ([[[my_ship getAI] state] isEqualToString:
@"ENTER_WORMHOLE"])
3051 if ([
PLAYER status] != STATUS_ENTERING_WITCHSPACE && [
PLAYER status] != STATUS_EXITING_WITCHSPACE)
3064 if ([e2 isShip] && [(
ShipEntity*)e2 hasPrimaryRole:
@"buoy-witchpoint"])
3073- (void) setUpBreakPattern:(HPVector) pos orientation:(Quaternion) q forDocking:(BOOL) forDocking
3092 colorDesc = [[
self globalSettings] objectForKey:@"hyperspace_tunnel_color_1"];
3093 if (colorDesc !=
nil)
3096 if (color !=
nil) col1 = color;
3097 else OOLogWARN(
@"hyperspaceTunnel.fromDict",
@"could not interpret \"%@\
" as a colour.", colorDesc);
3100 colorDesc = [[
self globalSettings] objectForKey:@"hyperspace_tunnel_color_2"];
3101 if (colorDesc !=
nil)
3104 if (color !=
nil) col2 = color;
3105 else OOLogWARN(
@"hyperspaceTunnel.fromDict",
@"could not interpret \"%@\
" as a colour.", colorDesc);
3109 GLfloat startAngle = 0;
3110 GLfloat aspectRatio = 1;
3114 NSDictionary *info = [[PLAYER dockedStation] shipInfoDictionary];
3115 sides = [
info oo_unsignedIntForKey:@"tunnel_corners" defaultValue:4];
3116 startAngle = [
info oo_floatForKey:@"tunnel_start_angle" defaultValue:45.0f];
3117 aspectRatio = [
info oo_floatForKey:@"tunnel_aspect_ratio" defaultValue:2.67f];
3120 for (i = 1; i < 11; i++)
3136 if (forDocking && ![[
PLAYER dockedStation] hasBreakPattern])
3156- (void) setWitchspaceBreakPattern:(BOOL)newValue
3168- (void) setDockingClearanceProtocolActive:(BOOL)newValue
3171 NSEnumerator *statEnum = [allStations objectEnumerator];
3179 while ((
station = [statEnum nextObject]))
3182 if (![[[registry shipInfoForKey:stationKey] allKeys] containsObject:
@"requires_docking_clearance"])
3205- (void) setupIntroFirstGo:(BOOL)justCobra
3209 Quaternion q2 = { 0.0f, 0.0f, 1.0f, 0.0f };
3240 NSArray *subList =
nil;
3243 if ([[[subList oo_dictionaryAtIndex:0] oo_stringForKey:
kOODemoShipClass] isEqualToString:
@"ship"])
3246 NSDictionary *shipEntry =
nil;
3247 foreach (shipEntry, subList)
3249 if ([[shipEntry oo_stringForKey:
kOODemoShipKey] isEqualToString:
@"cobra3-trader"])
3271 [
ship setPositionX:0.0f
y:0.0f
z:DEMO2_VANISHING_DISTANCE * ship->collision_radius * 0.01];
3309 return [[
demo_ships oo_arrayAtIndex:demo_ship_index] oo_dictionaryAtIndex:demo_ship_subindex];
3319 [
gui setTabStops:tab_stops];
3328 NSString *field1 =
nil;
3329 NSString *field2 =
nil;
3330 NSString *field3 =
nil;
3331 NSString *
override =
nil;
3334 for (NSUInteger i=1;i<=26;i++)
3336 [
gui setText:@"" forRow:i];
3340 override = [
librarySettings oo_stringForKey:kOODemoShipClass defaultValue:@"ship"];
3347 override = [
librarySettings oo_stringForKey:kOODemoShipSummary defaultValue:nil];
3348 if (
override !=
nil)
3356 [
gui setArray:[
NSArray arrayWithObjects:field1,field2,field3,nil] forRow:1];
3368 override = [
librarySettings oo_stringForKey:kOODemoShipSpeed defaultValue:nil];
3369 if (
override !=
nil)
3371 if ([
override length] == 0)
3377 field1 = [
NSString stringWithFormat:DESC(@"oolite-ship-library-speed-custom"),OOExpand(override)];
3386 override = [
librarySettings oo_stringForKey:kOODemoShipTurnRate defaultValue:nil];
3387 if (
override !=
nil)
3389 if ([
override length] == 0)
3395 field2 = [
NSString stringWithFormat:DESC(@"oolite-ship-library-turn-custom"),OOExpand(override)];
3404 override = [
librarySettings oo_stringForKey:kOODemoShipCargo defaultValue:nil];
3405 if (
override !=
nil)
3407 if ([
override length] == 0)
3413 field3 = [
NSString stringWithFormat:DESC(@"oolite-ship-library-cargo-custom"),OOExpand(override)];
3422 [
gui setArray:[
NSArray arrayWithObjects:field1,field2,field3,nil] forRow:3];
3425 override = [
librarySettings oo_stringForKey:kOODemoShipGenerator defaultValue:nil];
3426 if (
override !=
nil)
3428 if ([
override length] == 0)
3434 field1 = [
NSString stringWithFormat:DESC(@"oolite-ship-library-generator-custom"),OOExpand(override)];
3443 override = [
librarySettings oo_stringForKey:kOODemoShipShields defaultValue:nil];
3444 if (
override !=
nil)
3446 if ([
override length] == 0)
3452 field2 = [
NSString stringWithFormat:DESC(@"oolite-ship-library-shields-custom"),OOExpand(override)];
3461 override = [
librarySettings oo_stringForKey:kOODemoShipWitchspace defaultValue:nil];
3462 if (
override !=
nil)
3464 if ([
override length] == 0)
3470 field3 = [
NSString stringWithFormat:DESC(@"oolite-ship-library-witchspace-custom"),OOExpand(override)];
3479 [
gui setArray:[
NSArray arrayWithObjects:field1,field2,field3,nil] forRow:4];
3483 override = [
librarySettings oo_stringForKey:kOODemoShipWeapons defaultValue:nil];
3484 if (
override !=
nil)
3486 if ([
override length] == 0)
3492 field1 = [
NSString stringWithFormat:DESC(@"oolite-ship-library-weapons-custom"),OOExpand(override)];
3500 override = [
librarySettings oo_stringForKey:kOODemoShipTurrets defaultValue:nil];
3501 if (
override !=
nil)
3503 if ([
override length] == 0)
3509 field2 = [
NSString stringWithFormat:DESC(@"oolite-ship-library-turrets-custom"),OOExpand(override)];
3517 override = [
librarySettings oo_stringForKey:kOODemoShipSize defaultValue:nil];
3518 if (
override !=
nil)
3520 if ([
override length] == 0)
3526 field3 = [
NSString stringWithFormat:DESC(@"oolite-ship-library-size-custom"),OOExpand(override)];
3534 [
gui setArray:[
NSArray arrayWithObjects:field1,field2,field3,nil] forRow:5];
3537 override = [
librarySettings oo_stringForKey:kOODemoShipDescription defaultValue:nil];
3538 if (
override !=
nil)
3540 [
gui addLongText:OOExpand(override) startingAtRow:descRow align:GUI_ALIGN_LEFT];
3545 field1 = [
NSString stringWithFormat:@"<-- %@",OOShipLibraryCategoryPlural([[[
demo_ships objectAtIndex:((demo_ship_index+[
demo_ships count]-1)%[
demo_ships count])] objectAtIndex:0] oo_stringForKey:kOODemoShipClass])];
3547 field3 = [
NSString stringWithFormat:@"%@ -->",OOShipLibraryCategoryPlural([[[
demo_ships objectAtIndex:((demo_ship_index+1)%[
demo_ships count])] objectAtIndex:0] oo_stringForKey:kOODemoShipClass])];
3549 [
gui setArray:[
NSArray arrayWithObjects:field1,field2,field3,nil] forRow:19];
3553 NSArray *subList = [
demo_ships objectAtIndex:demo_ship_index];
3554 NSUInteger i,start = demo_ship_subindex - (demo_ship_subindex%5);
3555 NSUInteger end = start + 4;
3556 if (end >= [subList
count])
3563 for (i = start ; i <= end ; i++)
3565 field2 = [[
subList objectAtIndex:i] oo_stringForKey:kOODemoShipName];
3566 [
gui setArray:[
NSArray arrayWithObjects:field1,field2,field3,nil] forRow:row];
3567 if (i == demo_ship_subindex)
3581 [
gui setArray:[
NSArray arrayWithObjects:field1,field2,field3,nil] forRow:20];
3584 if (end < [subList
count]-1)
3586 [
gui setArray:[
NSArray arrayWithObjects:field1,field2,field3,nil] forRow:26];
3596 NSUInteger subcount = [[demo_ships objectAtIndex:demo_ship_index] count];
3650- (
StationEntity *) stationWithRole:(NSString *)role andPosition:(HPVector)position
3652 if ([role isEqualToString:
@""])
3657 float range = 1000000;
3663 if (HPdistance2(position,[
station position]) < range)
3665 if ([[
station primaryRole] isEqualToString:role])
3711 return [allStations allObjects];
3733 if (playerStatus == STATUS_START_GAME)
return;
3743 Entity <OOBeaconEntity> *beaconShip = [
self firstBeacon], *next =
nil;
3763- (void) setFirstBeacon:(
Entity <OOBeaconEntity> *)beacon
3765 if (beacon != [
self firstBeacon])
3767 [
beacon setPrevBeacon:nil];
3771 _firstBeacon = [
beacon weakRetain];
3782- (void) setLastBeacon:(
Entity <OOBeaconEntity> *)beacon
3784 if (beacon != [
self lastBeacon])
3786 [
beacon setNextBeacon:nil];
3790 _lastBeacon = [
beacon weakRetain];
3795- (void) setNextBeacon:(
Entity <OOBeaconEntity> *) beaconShip
3797 if ([beaconShip isBeacon])
3804 OOLog(
@"universe.beacon.error",
@"***** ERROR: Universe setNextBeacon '%@'. The ship has no beacon code set.", beaconShip);
3809- (void) clearBeacon:(
Entity <OOBeaconEntity> *) beaconShip
3811 Entity <OOBeaconEntity> *tmp =
nil;
3813 if ([beaconShip isBeacon])
3843- (void) defineWaypoint:(NSDictionary *)definition forKey:(NSString *)key
3846 BOOL preserveCompass = NO;
3847 waypoint = [waypoints objectForKey:key];
3848 if (waypoint !=
nil)
3850 if ([
PLAYER compassTarget] == waypoint)
3852 preserveCompass = YES;
3855 [waypoints removeObjectForKey:key];
3857 if (definition !=
nil)
3860 if (waypoint !=
nil)
3863 [waypoints setObject:waypoint forKey:key];
3864 if (preserveCompass)
3866 [PLAYER setCompassTarget:waypoint];
3867 [PLAYER setNextBeacon:waypoint];
3880- (void) setSkyColorRed:(GLfloat)red green:(GLfloat)green blue:(GLfloat)blue alpha:(GLfloat)alpha
3903#define PROFILE_SHIP_SELECTION 0
3906- (BOOL) canInstantiateShip:(NSString *)shipKey
3908 NSDictionary *shipInfo =
nil;
3909 NSArray *conditions =
nil;
3910 NSString *condition_script =
nil;
3913 condition_script = [
shipInfo oo_stringForKey:@"condition_script"];
3914 if (condition_script !=
nil)
3917 if (condScript !=
nil)
3921 JSBool allow_instantiation;
3930 if (OK) OK = JS_ValueToBoolean(context, result, &allow_instantiation);
3934 if (OK && !allow_instantiation)
3944 conditions = [
shipInfo oo_arrayForKey:@"conditions"];
3945 if (conditions ==
nil)
return YES;
3948 return [PLAYER scriptTestConditions:conditions];
3952- (NSString *) randomShipKeyForRoleRespectingConditions:(NSString *)role
3957 NSString *shipKey =
nil;
3960#if PROFILE_SHIP_SELECTION
3961 static unsigned long profTotal = 0, profSlowPath = 0;
3967 if ([
self canInstantiateShip:shipKey])
return shipKey;
3976#if PROFILE_SHIP_SELECTION
3978 if ((profSlowPath % 10) == 0)
3980 OOLog(
@"shipRegistry.selection.profile",
@"Hit slow path in ship selection for role \"%@\
", having selected ship \"%@\". Now %lu of %lu on slow path (%f%%).", role, shipKey, profSlowPath, profTotal, ((
double)profSlowPath)/((
double)profTotal) * 100.0f);
3986 while ([pset
count] > 0)
3990 if ([
self canInstantiateShip:shipKey])
return shipKey;
4008 NSString *shipKey =
nil;
4009 NSDictionary *shipInfo =
nil;
4010 NSString *autoAI =
nil;
4021 if ([shipInfo oo_fuzzyBooleanForKey:
@"auto_ai" defaultValue:YES])
4030 if ([role isEqualToString:
@"pirate"]) [
ship setBounty:20 + randf() * 50
withReason:kOOLegalStatusReasonSetup];
4033 if ([role isEqualToString:
@"interceptor"])
4039 if ([role isEqualToString:
@"thargoid"]) [
ship setScanClass: CLASS_THARGOID];
4054 NSDictionary *effectDict =
nil;
4058 if (effectDict ==
nil)
return nil;
4064 @catch (NSException *exception)
4068 OOLog(
kOOLogException,
@"***** Oolite Exception : '%@' in [Universe newVisualEffectWithName: %@ ] *****", [exception reason], effectKey);
4070 else @throw exception;
4079- (
ShipEntity *) newSubentityWithName:(NSString *)shipKey andScaleFactor:(
float)scale
4085- (
ShipEntity *) newShipWithName:(NSString *)shipKey usePlayerProxy:(BOOL)usePlayerProxy
4090- (
ShipEntity *) newShipWithName:(NSString *)shipKey usePlayerProxy:(BOOL)usePlayerProxy isSubentity:(BOOL)isSubentity
4095- (
ShipEntity *) newShipWithName:(NSString *)shipKey usePlayerProxy:(BOOL)usePlayerProxy isSubentity:(BOOL)isSubentity andScaleFactor:(
float)scale
4099 NSDictionary *shipDict =
nil;
4103 if (shipDict ==
nil)
return nil;
4105 volatile Class shipClass =
nil;
4113 if (usePlayerProxy && shipClass == [
ShipEntity class])
4123 NSMutableDictionary *mShipDict = [
shipDict mutableCopy];
4124 [
mShipDict setObject:[
NSNumber numberWithFloat:scale] forKey:@"model_scale_factor"];
4125 shipDict = [
NSDictionary dictionaryWithDictionary:mShipDict];
4128 ship = [[
shipClass alloc] initWithKey:shipKey definition:shipDict];
4130 @catch (NSException *exception)
4134 OOLog(
kOOLogException,
@"***** Oolite Exception : '%@' in [Universe newShipWithName: %@ ] *****", [exception reason], shipKey);
4136 else @throw exception;
4149- (
DockEntity *) newDockWithName:(NSString *)shipDataKey andScaleFactor:(
float)scale
4153 NSDictionary *shipDict =
nil;
4157 if (shipDict ==
nil)
return nil;
4163 NSMutableDictionary *mShipDict = [
shipDict mutableCopy];
4164 [
mShipDict setObject:[
NSNumber numberWithFloat:scale] forKey:@"model_scale_factor"];
4165 shipDict = [
NSDictionary dictionaryWithDictionary:mShipDict];
4168 dock = [[
DockEntity alloc] initWithKey:shipDataKey definition:shipDict];
4170 @catch (NSException *exception)
4174 OOLog(
kOOLogException,
@"***** Oolite Exception : '%@' in [Universe newDockWithName: %@ ] *****", [exception reason], shipDataKey);
4176 else @throw exception;
4195- (Class) shipClassForShipDictionary:(NSDictionary *)dict
4199 if (dict ==
nil)
return Nil;
4201 BOOL isStation = NO;
4202 NSString *shipRoles = [
dict oo_stringForKey:@"roles"];
4204 if (shipRoles !=
nil)
4206 isStation = [
shipRoles rangeOfString:@"station"].location != NSNotFound ||
4207 [
shipRoles rangeOfString:@"carrier"].location != NSNotFound;
4211 isStation = [
dict oo_boolForKey:@"isCarrier" defaultValue:isStation];
4212 isStation = [
dict oo_boolForKey:@"is_carrier" defaultValue:isStation];
4221- (NSString *)defaultAIForRole:(NSString *)role
4223 return [autoAIMap oo_stringForKey:role];
4240 NSString *itemType = [
itemData oo_stringAtIndex:EQUIPMENT_KEY_INDEX];
4242 if ([itemType isEqual:eq_key])
4244 return [
itemData oo_unsignedLongLongAtIndex:EQUIPMENT_PRICE_INDEX];
4260 if ([cargoObj isTemplateCargoPod])
4262 return [UNIVERSE cargoPodFromTemplate:cargoObj];
4276 OOCargoQuantity co_amount = [UNIVERSE getRandomAmountOfCommodity:co_type];
4279 container = [UNIVERSE newShipWithRole:co_type];
4281 if (container ==
nil)
4283 container = [UNIVERSE newShipWithRole:@"cargopod"];
4290- (NSArray *) getContainersOfGoods:(
OOCargoQuantity)how_many scarce:(BOOL)scarce legal:(BOOL)legal
4296 NSMutableArray *accumulator = [
NSMutableArray arrayWithCapacity:how_many];
4302 NSString *goodsKey =
nil;
4304 foreach (goodsKey, goodsKeys)
4309 if (q < 64) q = 64 - q;
4320 quantities[
i++] = q;
4321 total_quantity += q;
4324 for (i = 0; i < how_many; i++)
4326 NSUInteger co_type = 0;
4331 qr = 1+(
Ranrot() % total_quantity);
4335 NSAssert((NSUInteger)co_type < commodityCount,
@"Commodity type index out of range.");
4343 if (container !=
nil)
4349 OOLog(
@"universe.createContainer.failed",
@"***** ERROR: failed to find a container to fill with %@ (%llu).", [goodsKeys oo_stringAtIndex:co_type], co_type);
4353 return [
NSArray arrayWithArray:accumulator];
4359 NSMutableArray *accumulator = [
NSMutableArray arrayWithCapacity:how_much];
4365 ShipEntity *container = [cargoPods objectForKey:commodity_name];
4366 while (how_much > 0)
4374 OOLog(
@"universe.createContainer.failed",
@"***** ERROR: failed to find a container to fill with %@", commodity_name);
4379 return [
NSArray arrayWithArray:accumulator];
4385 if (cargopod ==
nil || ![cargopod hasRole:
@"cargopod"] || [cargopod cargoType] ==
CARGO_SCRIPTED_ITEM)
return;
4387 if ([cargopod commodityType] ==
nil || ![cargopod commodityAmount])
4406 if (co_type ==
nil) {
4420 OOLog(
@"universe.commodityAmount.warning",
@"Commodity %@ has an unrecognised mass unit, assuming tonnes",co_type);
4440 NSString *unitDesc =
nil, *typeDesc =
nil;
4443 if (commodity ==
nil)
return @"";
4451 unitDesc =
DESC(
@"cargo-kilogram");
4454 unitDesc =
DESC(
@"cargo-gram");
4458 unitDesc =
DESC(
@"cargo-ton");
4467 unitDesc =
DESC(
@"cargo-kilograms");
4470 unitDesc =
DESC(
@"cargo-grams");
4474 unitDesc =
DESC(
@"cargo-tons");
4481 return [
NSString stringWithFormat:@"%d %@ %@",co_amount, unitDesc, typeDesc];
4513 [
result oo_setInteger:[PLAYER isSpeechOn] forKey:@"speechOn"];
4514 [
result oo_setBool:autoSave forKey:@"autosave"];
4515 [
result oo_setBool:wireframeGraphics forKey:@"wireframeGraphics"];
4516 [
result oo_setBool:doProcedurallyTexturedPlanets forKey:@"procedurallyTexturedPlanets"];
4526 [
result oo_setFloat:[
gameView hdrMaxBrightness] forKey:@"hdr-max-brightness"];
4527 [
result oo_setFloat:[
gameView hdrPaperWhiteBrightness] forKey:@"hdr-paperwhite-brightness"];
4528 [
result setObject:OOStringFromHDRToneMapper([
gameView hdrToneMapper]) forKey:@"hdr-tone-mapper"];
4534 [
result setObject:OOStringFromGraphicsDetail([
self detailLevel]) forKey:@"detailLevel"];
4536 NSString *desc =
@"UNDEFINED";
4543 [
result setObject:desc forKey:@"musicMode"];
4545 NSDictionary *gameWindow = [
NSDictionary dictionaryWithObjectsAndKeys:
4550 [
result setObject:gameWindow forKey:@"gameWindow"];
4552 [
result setObject:[PLAYER keyConfig] forKey:@"keyConfig"];
4554 return [[
result copy] autorelease];
4558- (void) useGUILightSource:(BOOL)GUILight
4566 OOGL(glEnable(GL_LIGHT0));
4567 OOGL(glDisable(GL_LIGHT1));
4571 OOGL(glEnable(GL_LIGHT1));
4572 OOGL(glDisable(GL_LIGHT0));
4581 else OOGL(glEnable(GL_LIGHT1));
4588- (void) lightForEntity:(BOOL)isLit
4609 if (isLit)
OOGL(glEnable(GL_LIGHT1));
4610 else OOGL(glDisable(GL_LIGHT1));
4615 OOGL(glEnable(GL_LIGHT0));
4631 { 1.0f, 0.0f, 0.0f, 0.0f },
4632 { 0.0f, 1.0f, 0.0f, 0.0f },
4633 { 0.0f, 0.0f, 1.0f, 0.0f },
4634 { 0.0f, 0.0f, 0.0f, 1.0f }
4638 {-1.0f, 0.0f, 0.0f, 0.0f },
4639 { 0.0f, 1.0f, 0.0f, 0.0f },
4640 { 0.0f, 0.0f, -1.0f, 0.0f },
4641 { 0.0f, 0.0f, 0.0f, 1.0f }
4645 { 0.0f, 0.0f, -1.0f, 0.0f },
4646 { 0.0f, 1.0f, 0.0f, 0.0f },
4647 { 1.0f, 0.0f, 0.0f, 0.0f },
4648 { 0.0f, 0.0f, 0.0f, 1.0f }
4652 { 0.0f, 0.0f, 1.0f, 0.0f },
4653 { 0.0f, 1.0f, 0.0f, 0.0f },
4654 {-1.0f, 0.0f, 0.0f, 0.0f },
4655 { 0.0f, 0.0f, 0.0f, 1.0f }
4659- (void) getActiveViewMatrix:(OOMatrix *)outMatrix forwardVector:(Vector *)outForward upVector:(Vector *)outUp
4661 assert(outMatrix != NULL && outForward != NULL && outUp != NULL);
4679 case VIEW_STARBOARD:
4694 case VIEW_GUI_DISPLAY:
4695 case VIEW_BREAK_PATTERN:
4728 frustum[0][0] = clip.m[0][3] - clip.m[0][0];
4729 frustum[0][1] = clip.m[1][3] - clip.m[1][0];
4730 frustum[0][2] = clip.m[2][3] - clip.m[2][0];
4731 frustum[0][3] = clip.m[3][3] - clip.m[3][0];
4741 frustum[1][0] = clip.m[0][3] + clip.m[0][0];
4742 frustum[1][1] = clip.m[1][3] + clip.m[1][0];
4743 frustum[1][2] = clip.m[2][3] + clip.m[2][0];
4744 frustum[1][3] = clip.m[3][3] + clip.m[3][0];
4754 frustum[2][0] = clip.m[0][3] + clip.m[0][1];
4755 frustum[2][1] = clip.m[1][3] + clip.m[1][1];
4756 frustum[2][2] = clip.m[2][3] + clip.m[2][1];
4757 frustum[2][3] = clip.m[3][3] + clip.m[3][1];
4767 frustum[3][0] = clip.m[0][3] - clip.m[0][1];
4768 frustum[3][1] = clip.m[1][3] - clip.m[1][1];
4769 frustum[3][2] = clip.m[2][3] - clip.m[2][1];
4770 frustum[3][3] = clip.m[3][3] - clip.m[3][1];
4780 frustum[4][0] = clip.m[0][3] - clip.m[0][2];
4781 frustum[4][1] = clip.m[1][3] - clip.m[1][2];
4782 frustum[4][2] = clip.m[2][3] - clip.m[2][2];
4783 frustum[4][3] = clip.m[3][3] - clip.m[3][2];
4793 frustum[5][0] = clip.m[0][3] + clip.m[0][2];
4794 frustum[5][1] = clip.m[1][3] + clip.m[1][2];
4795 frustum[5][2] = clip.m[2][3] + clip.m[2][2];
4796 frustum[5][3] = clip.m[3][3] + clip.m[3][2];
4807- (BOOL) viewFrustumIntersectsSphereAt:(Vector)position withRadius:(GLfloat)radius
4811 for (p = 0; p < 6; p++)
4827 OOLog(
@"universe.profile.draw",
@"%@",
@"Begin draw");
4851 int i, v_status, vdist;
4852 Vector view_dir, view_up;
4853 OOMatrix view_matrix;
4861 float aspect = viewSize.height/viewSize.width;
4867 else [UNIVERSE setMainLightPosition:kZeroVector];
4871 for (i = 0; i < ent_count; i++)
4881 my_entities[
draw_count++] = [[
e retain] autorelease];
4891 OOGL(glClear(GL_COLOR_BUFFER_BIT));
4899 OOGL(glClearColor(0.0, 0.0, 0.0, 0.0));
4909 for (vdist=0;vdist<=1;vdist++)
4918 OOGLFrustum(-ratio, ratio, -aspect*ratio, aspect*ratio, nearPlane, farPlane);
4922 OOGLFrustum(-3*ratio/aspect/4, 3*ratio/aspect/4, -3*ratio/4, 3*ratio/4, nearPlane, farPlane);
4957 OOGL(glClear(GL_DEPTH_BUFFER_BIT));
4962 flipMatrix.m[2][2] = -1;
4970 if (
EXPECT(!demoShipMode))
4999 OOGL([
self useGUILightSource:demoShipMode]);
5004 int furthest = draw_count - 1;
5008 double fog_scale, half_scale;
5009 GLfloat flat_ambdiff[4] = {1.0, 1.0, 1.0, 1.0};
5010 GLfloat mat_no[4] = {0.0, 0.0, 0.0, 1.0};
5019 OOLog(
@"universe.profile.draw",
@"%@",
@"Begin opaque pass");
5023 for (i = furthest; i >= nearest; i--)
5025 drawthing = my_entities[
i];
5029 if (vdist == 1 && [drawthing cameraRangeFront] > farPlane*1.5)
continue;
5030 if (vdist == 0 && [drawthing cameraRangeBack] < nearPlane)
continue;
5033 if (!((d_status == STATUS_COCKPIT_DISPLAY) ^ demoShipMode))
5037 OOGL(glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, flat_ambdiff));
5038 OOGL(glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, mat_no));
5041 if (
EXPECT(drawthing != player))
5064 half_scale = fog_scale * 0.50;
5065 OOGL(glEnable(GL_FOG));
5066 OOGL(glFogi(GL_FOG_MODE, GL_LINEAR));
5068 OOGL(glFogf(GL_FOG_START, half_scale));
5069 OOGL(glFogf(GL_FOG_END, fog_scale));
5070 fog_blend = OOClamp_0_1_f((magnitude([drawthing cameraRelativePosition]) - half_scale)/half_scale);
5085 OOGL(glDisable(GL_FOG));
5090 if (!((d_status == STATUS_COCKPIT_DISPLAY) ^ demoShipMode))
5093 if (
EXPECT(drawthing != player))
5116 half_scale = fog_scale * 0.50;
5117 OOGL(glEnable(GL_FOG));
5118 OOGL(glFogi(GL_FOG_MODE, GL_LINEAR));
5120 OOGL(glFogf(GL_FOG_START, half_scale));
5121 OOGL(glFogf(GL_FOG_END, fog_scale));
5122 fog_blend = OOClamp_0_1_f((magnitude([drawthing cameraRelativePosition]) - half_scale)/half_scale);
5133 OOGL(glDisable(GL_FOG));
5158 if (hudSeparateRenderPass)
5166 OOLog(
@"universe.profile.secondPassDraw",
@"%@",
@"Begin second pass draw");
5168 OOCheckOpenGLErrors(
@"Universe after drawing from custom framebuffer to screen framebuffer");
5169 OOLog(
@"universe.profile.secondPassDraw",
@"%@",
@"End second pass drawing");
5171 OOLog(
@"universe.profile.drawHUD",
@"%@",
@"Begin HUD drawing");
5176 OOLog(
@"universe.profile.draw",
@"%@",
@"Begin HUD");
5179 if (lineWidth < 1.0) lineWidth = 1.0;
5180 if (lineWidth > 1.5) lineWidth = 1.5;
5187 if ([theHUD deferredHudName] !=
nil)
5196 static float sPrevHudAlpha = -1.0f;
5197 if ([theHUD isHidden])
5199 if (sPrevHudAlpha < 0.0f)
5205 else if (sPrevHudAlpha >= 0.0f)
5208 sPrevHudAlpha = -1.0f;
5213 case STATUS_ESCAPE_SEQUENCE:
5214 case STATUS_START_GAME:
5218 switch ([player guiScreen])
5232#if (defined (SNAPSHOT_BUILD) && defined (OOLITE_SNAPSHOT_VERSION))
5236 OOLog(
@"universe.profile.drawHUD",
@"%@",
@"End HUD drawing");
5250 @catch (NSException *exception)
5254 if ([[exception name] hasPrefix:
@"Oolite"])
5260 OOLog(
kOOLogException,
@"***** Exception: %@ : %@ *****",[exception name], [exception reason]);
5266 OOLog(
@"universe.profile.draw",
@"%@",
@"End drawing");
5269 if(!hudSeparateRenderPass)
5276 OOLog(
@"universe.profile.secondPassDraw",
@"%@",
@"Begin second pass draw");
5278 OOLog(
@"universe.profile.secondPassDraw",
@"%@",
@"End second pass drawing");
5286 NSSize viewSize = [
gameView viewSize];
5287 if([
self useShaders])
5289 if ([gameView msaa])
5292 OOGL(glBindFramebuffer(GL_READ_FRAMEBUFFER, msaaFramebufferID));
5293 OOGL(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, targetFramebufferID));
5294 OOGL(glBlitFramebuffer(0, 0, (GLint)viewSize.width, (GLint)viewSize.height, 0, 0, (GLint)viewSize.width, (GLint)viewSize.height, GL_COLOR_BUFFER_BIT, GL_NEAREST));
5322 OOGL(glDisable(GL_TEXTURE_2D));
5324 float overallAlpha = [[PLAYER hud] overallAlpha];
5344- (void) drawWatermarkString:(NSString *) watermarkString
5346 NSSize watermarkStringSize =
OORectFromString(watermarkString, 0.0f, 0.0f, NSMakeSize(10, 10)).size;
5348 OOGL(glColor4f(0.0, 1.0, 0.0, 1.0));
5362 OOLog(
@"universe.badUID",
@"Attempt to retrieve entity for out-of-range UID %u. (This is an internal programming error, please report it.)", u_id);
5375 if ([ent status] == STATUS_DEAD || [ent status] == STATUS_DOCKED)
5386 NSCParameterAssert(uni != NULL);
5399 while ((n--)&&(checkEnt))
5402 checkEnt = checkEnt->
x_next;
5404 if ((checkEnt)||(n > 0))
5412 while ((n--)&&(checkEnt)) checkEnt = checkEnt->
x_previous;
5413 if ((checkEnt)||(n > 0))
5424 checkEnt = checkEnt->
x_next;
5432 while ((n--)&&(checkEnt))
5435 checkEnt = checkEnt->
y_next;
5437 if ((checkEnt)||(n > 0))
5445 while ((n--)&&(checkEnt)) checkEnt = checkEnt->
y_previous;
5446 if ((checkEnt)||(n > 0))
5457 checkEnt = checkEnt->
y_next;
5465 while ((n--)&&(checkEnt))
5468 checkEnt = checkEnt->
z_next;
5470 if ((checkEnt)||(n > 0))
5478 while ((n--)&&(checkEnt)) checkEnt = checkEnt->
z_previous;
5479 if ((checkEnt)||(n > 0))
5486 NSCAssert(checkEnt !=
nil,
@"Expected z-list to be non-empty.");
5491 checkEnt = checkEnt->
z_next;
5501 NSArray *allEntities = uni->
entities;
5507 foreach (ent, allEntities)
5531 if (![entity validForAddToUniverse])
return NO;
5534 if ([
entities containsObject:entity])
5547 if (![entity isEffect])
5560 OOLog(
@"universe.addEntity.failed",
@"***** Universe cannot addEntity:%@ -- Could not find free slot for entity.", entity);
5564 [
entity setUniversalID:next_universal_id];
5566 if ([entity isShip])
5578 double stationRoll = 0.0;
5582 if (definedRoll !=
nil)
5588 stationRoll = [[
self currentSystemData] oo_doubleForKey:@"station_roll" defaultValue:STANDARD_STATION_ROLL];
5601 if ([se status] != STATUS_COCKPIT_DISPLAY)
5609 [
entity setUniversalID:NO_TARGET];
5610 if ([entity isVisualEffect])
5618 else if ([entity isWaypoint])
5629 entity->isSunlit = YES;
5633 [entities addObject:entity];
5634 [
entity wasAddedToUniverse];
5637 HPVector entity_pos = entity->position;
5638 HPVector delta = HPvector_between(entity_pos,
PLAYER->position);
5639 double z_distance = HPmagnitude2(delta);
5640 entity->zero_distance = z_distance;
5643 entity->zero_index = index;
5644 while ((index > 0)&&(z_distance <
sortedEntities[index - 1]->zero_distance))
5650 entity->zero_index = index;
5657 [
entity addToLinkedLists];
5658 if ([entity canCollide])
5663 if ([entity isWormhole])
5665 [activeWormholes addObject:entity];
5667 else if ([entity isPlanet])
5669 [allPlanets addObject:entity];
5671 else if ([entity isShip])
5675 if ([entity isStation])
5677 [allStations addObject:entity];
5689 if (entity !=
nil && ![entity isPlayer])
5695 [entitiesDeadThisUpdate addObject:entity];
5696 if ([entity isStation])
5698 [allStations removeObject:entity];
5699 if ([
PLAYER getTargetDockStation] == entity)
5701 [PLAYER setDockingClearanceStatus:DOCKING_CLEARANCE_STATUS_NONE];
5710- (void) ensureEntityReallyRemoved:(
Entity *)entity
5714 OOLog(
@"universe.unremovedEntity",
@"Entity %@ dealloced without being removed from universe! (This is an internal programming error, please report it.)", entity);
5726 Entity* p0 = [entities objectAtIndex:0];
5735 NSMutableArray *savedWormholes = [activeWormholes mutableCopy];
5739 Entity* ent = [entities objectAtIndex:1];
5742 if (
EXPECT(![ent isVisualEffect]))
5753 [activeWormholes release];
5762 [closeSystems release];
5766 [waypoints removeAllObjects];
5779 for (i = 0; i < ent_count; i++)
5782 if ([ent status] == STATUS_COCKPIT_DISPLAY && ![ent isPlayer])
5792- (
ShipEntity *) makeDemoShipWithRole:(NSString *)role spinning:(BOOL)spinning
5798 [PLAYER setShowDemoShips: YES];
5799 Quaternion q2 = { (GLfloat)
M_SQRT1_2, (GLfloat)
M_SQRT1_2, (GLfloat)0.0, (GLfloat)0.0 };
5811 [UNIVERSE addEntity:ship];
5828 return [
ship autorelease];
5832- (BOOL) isVectorClearFromEntity:(
Entity *) e1 toDistance:(
double)dist fromPoint:(HPVector) p2
5840 v1.x -= p1.x; v1.y -= p1.y; v1.z -= p1.z;
5842 double nearest = sqrt(v1.x*v1.x + v1.y*v1.y + v1.z*v1.z) - dist;
5850 for (i = 0; i < ent_count; i++)
5853 if (v1.x || v1.y || v1.z)
5854 f1 = HPvector_normal(v1);
5856 f1 = make_HPvector(0, 0, 1);
5858 for (i = 0; i < ent_count ; i++)
5861 if ((e2 != e1)&&([e2 canCollide]))
5864 epos.x -= p1.x; epos.y -= p1.y; epos.z -= p1.z;
5866 double d_forward = HPdot_product(epos,f1);
5868 if ((d_forward > 0)&&(d_forward < nearest))
5872 p0.x += d_forward * f1.x; p0.y += d_forward * f1.y; p0.z += d_forward * f1.z;
5875 p0.x -= epos.x; p0.y -= epos.y; p0.z -= epos.z;
5877 double dist2 = p0.x * p0.x + p0.y * p0.y + p0.z * p0.z;
5880 for (i = 0; i < ent_count; i++)
5881 [my_entities[i] release];
5887 for (i = 0; i < ent_count; i++)
5888 [my_entities[i] release];
5893- (
Entity*) hazardOnRouteFromEntity:(
Entity *) e1 toDistance:(
double)dist fromPoint:(HPVector) p2
5901 v1.x -= p1.x; v1.y -= p1.y; v1.z -= p1.z;
5903 double nearest = HPmagnitude(v1) - dist;
5912 for (i = 0; i < ent_count; i++)
5915 if (v1.x || v1.y || v1.z)
5916 f1 = HPvector_normal(v1);
5918 f1 = make_HPvector(0, 0, 1);
5920 for (i = 0; (i < ent_count) && (!result) ; i++)
5923 if ((e2 != e1)&&([e2 canCollide]))
5926 epos.x -= p1.x; epos.y -= p1.y; epos.z -= p1.z;
5928 double d_forward = HPdot_product(epos,f1);
5930 if ((d_forward > 0)&&(d_forward < nearest))
5934 p0.x += d_forward * f1.x; p0.y += d_forward * f1.y; p0.z += d_forward * f1.z;
5937 p0.x -= epos.x; p0.y -= epos.y; p0.z -= epos.z;
5939 double dist2 = HPmagnitude2(p0);
5945 for (i = 0; i < ent_count; i++)
5946 [my_entities[i] release];
5951- (HPVector) getSafeVectorFromEntity:(
Entity *) e1 toDistance:(
double)dist fromPoint:(HPVector) p2
5962 HPVector result = p2;
5966 for (i = 0; i < ent_count; i++)
5970 v1.x -= p1.x; v1.y -= p1.y; v1.z -= p1.z;
5972 double nearest = sqrt(v1.x*v1.x + v1.y*v1.y + v1.z*v1.z) - dist;
5974 if (v1.x || v1.y || v1.z)
5975 f1 = HPvector_normal(v1);
5977 f1 = make_HPvector(0, 0, 1);
5979 for (i = 0; i < ent_count; i++)
5982 if ((e2 != e1)&&([e2 canCollide]))
5985 epos.x -= p1.x; epos.y -= p1.y; epos.z -= p1.z;
5986 double d_forward = HPdot_product(epos,f1);
5987 if ((d_forward > 0)&&(d_forward < nearest))
5992 p0.x += d_forward * f1.x; p0.y += d_forward * f1.y; p0.z += d_forward * f1.z;
5996 p0.x -= epos.x; p0.y -= epos.y; p0.z -= epos.z;
5999 double dist2 = p0.x * p0.x + p0.y * p0.y + p0.z * p0.z;
6004 nearest = d_forward;
6010 result.x += ((
int)(
Ranrot() % 1024) - 512)/512.0;
6011 result.y += ((
int)(
Ranrot() % 1024) - 512)/512.0;
6012 result.z += ((
int)(
Ranrot() % 1024) - 512)/512.0;
6015 HPVector nearest_point = p1;
6016 nearest_point.x += d_forward * f1.x; nearest_point.y += d_forward * f1.y; nearest_point.z += d_forward * f1.z;
6019 HPVector outward = nearest_point;
6020 outward.x -= result.x; outward.y -= result.y; outward.z -= result.z;
6021 if (outward.x||outward.y||outward.z)
6022 outward = HPvector_normal(outward);
6027 HPVector backward = p1;
6028 backward.x -= result.x; backward.y -= result.y; backward.z -= result.z;
6029 if (backward.x||backward.y||backward.z)
6030 backward = HPvector_normal(backward);
6035 HPVector dd = result;
6036 dd.x -= p1.x; dd.y -= p1.y; dd.z -= p1.z;
6037 double current_distance = HPmagnitude(dd);
6040 if (current_distance < cr * 1.25)
6041 current_distance = cr * 1.25;
6042 if (current_distance > cr * 5.0)
6043 current_distance = cr * 5.0;
6047 result.x += 0.25 * (outward.x * current_distance) + 0.75 * (backward.x * current_distance);
6048 result.y += 0.25 * (outward.y * current_distance) + 0.75 * (backward.y * current_distance);
6049 result.z += 0.25 * (outward.z * current_distance) + 0.75 * (backward.z * current_distance);
6055 for (i = 0; i < ent_count; i++)
6056 [my_entities[i] release];
6061- (
ShipEntity*) addWreckageFrom:(
ShipEntity *)ship withRole:(NSString *)wreckRole at:(HPVector)rpos scale:(GLfloat)scale lifetime:(GLfloat)lifetime
6063 ShipEntity* wreck = [UNIVERSE newShipWithRole:wreckRole];
6067 GLfloat expected_mass = 0.1f * [
ship mass] * (0.75 + 0.5 *
randf());
6069 GLfloat scale_factor = powf(expected_mass / wreck_mass, 0.33333333f) * scale;
6085 [UNIVERSE addEntity:wreck];
6095- (void) addLaserHitEffectsAt:(HPVector)pos against:(
ShipEntity *)target damage:(
float)damage color:(
OOColor *)color
6098 if ([target showDamage] && [target energy] < [target maxEnergy]/2)
6100 NSString *key = (
randf() < 0.5) ?
@"oolite-hull-spark" :
@"oolite-hull-spark-b";
6101 NSDictionary *settings = [UNIVERSE explosionSetting:key];
6105 if ([target energy] *
randf() < damage)
6110 Vector direction = HPVectorToVector(HPvector_normal(HPvector_subtract(pos,[target position])));
6124 if (srcEntity ==
nil)
return nil;
6136 HPVector midfrontplane = make_HPvector(0.5 * (bbox.max.x + bbox.min.x), 0.5 * (bbox.max.y + bbox.min.y), bbox.max.z);
6139 if ([parent isPlayer]) q1.w = -q1.w;
6148 for (i = 0; i < ent_count; i++)
6151 if (ent != srcEntity && ent != parent && [ent isShip] && [ent canCollide])
6182 HPVector p1 = HPvector_add(p0, vectorToHPVector(vector_multiply_scalar(f1, nearest)));
6184 for (i = 0; i < ship_count; i++)
6190 Vector rpos = HPVectorToVector(HPvector_subtract(e2->
position, p0));
6191 Vector v_off = make_vector(dot_product(rpos, r1), dot_product(rpos, u1), dot_product(rpos, f1));
6192 if (v_off.z > 0.0 && v_off.z < nearest + cr &&
6193 v_off.x < cr && v_off.x > -cr && v_off.y < cr && v_off.y > -cr &&
6194 v_off.x * v_off.x + v_off.y * v_off.y < cr * cr)
6197 GLfloat hit = [(
ShipEntity *)
e2 doesHitLine:p0 :p1 :&entHit];
6199 if (hit > 0.0 && hit < nearest)
6201 if ([entHit isSubEntity])
6203 hit_subentity = entHit;
6207 p1 = HPvector_add(p0, vectorToHPVector(vector_multiply_scalar(f1, nearest)));
6217 if (range_ptr != NULL)
6219 *range_ptr = nearest;
6223 for (i = 0; i < ship_count; i++) [my_entities[i] release];
6234 nearest2 *= nearest2;
6240 for (i = 0; i < ent_count; i++)
6264 case VIEW_STARBOARD :
6272 for (i = 0; i < ship_count; i++)
6275 if ([e2 canCollide] && [e2 scanClass] != CLASS_NO_DRAW)
6277 Vector rp = HPVectorToVector(HPvector_subtract([e2 position], p1));
6279 if (dist2 < nearest2)
6282 if (df > 0.0 && df * df < nearest2)
6287 if (du * du + dr * dr < cr * cr)
6297 if (hit_entity !=
nil && [hit_entity isShip])
6300 if ([ship isJammingScanning] && ![player hasMilitaryScannerFilter])
6306 for (i = 0; i < ship_count; i++)
6338 case VIEW_STARBOARD:
6353- (NSArray *) entitiesWithinRange:(
double)range ofEntity:(
Entity *)entity
6355 if (entity ==
nil)
return nil;
6364- (unsigned) countShipsWithRole:(NSString *)role inRange:(
double)range ofEntity:(
Entity *)entity
6373- (unsigned) countShipsWithRole:(NSString *)role
6379- (unsigned) countShipsWithPrimaryRole:(NSString *)role inRange:(
double)range ofEntity:(
Entity *)entity
6388- (unsigned) countShipsWithScanClass:(
OOScanClass)scanClass inRange:(
double)range ofEntity:(
Entity *)entity
6397- (unsigned) countShipsWithPrimaryRole:(NSString *)role
6404 parameter:(
void *)parameter
6405 inRange:(
double)range
6408 unsigned i, found = 0;
6410 double distance, cr;
6420 if (e2 != e1 && predicate(e2, parameter))
6422 if (range < 0) distance = -1;
6426 distance = HPdistance2(e2->
position, p1) - cr * cr;
6440 parameter:(
void *)parameter
6441 inRange:(
double)range
6442 ofEntity:(
Entity *)entity
6444 if (predicate != NULL)
6449 predicate, parameter
6469 if (range < 0)
return YES;
6471 return HPdistance2(e2->
position,p1) < cr * cr;
6478 parameter:(
void *)parameter
6479 inRange:(
double)range
6486 NSMutableArray *result =
nil;
6503 predicate(e2, parameter))
6518 parameter:(
void *)parameter
6530 if (predicate(candidate, parameter))
return candidate;
6540 parameter:(
void *)parameter
6541 inRange:(
double)range
6542 ofEntity:(
Entity *)entity
6544 if (predicate != NULL)
6549 predicate, parameter
6568 parameter:(
void *)parameter
6569 inRange:(
double)range
6570 ofEntity:(
Entity *)entity
6572 if (predicate != NULL)
6577 predicate, parameter
6596 parameter:(
void *)parameter
6597 relativeToEntity:(
Entity *)entity
6601 float rangeSq = INFINITY;
6612 float distanceToReferenceEntitySquared = (float)HPdistance2(p1, [e2 position]);
6615 distanceToReferenceEntitySquared < rangeSq &&
6616 predicate(e2, parameter))
6619 rangeSq = distanceToReferenceEntitySquared;
6623 return [[
result retain] autorelease];
6628 parameter:(
void *)parameter
6629 relativeToEntity:(
Entity *)entity
6631 if (predicate != NULL)
6636 predicate, parameter
6707 BOOL guiSelected = NO;
6715 ms =
DESC(
@"forward-view-string");
6719 ms =
DESC(
@"aft-view-string");
6723 ms =
DESC(
@"port-view-string");
6726 case VIEW_STARBOARD:
6727 ms =
DESC(
@"starboard-view-string");
6731 ms = [PLAYER customViewDescription];
6734 case VIEW_GUI_DISPLAY:
6757 #if (ALLOW_CUSTOM_VIEWS_WHILE_PAUSED)
6760 BOOL gamePaused = NO;
6765 if (ms && !gamePaused)
6769 else if (gamePaused)
6777- (void) enterGUIViewModeWithMouseInteraction:(BOOL)mouseInteraction
6791- (NSString *) soundNameForCustomSoundKey:(NSString *)key
6793 NSString *result =
nil;
6794 NSMutableSet *seen =
nil;
6795 id object = [customSounds objectForKey:key];
6797 if ([
object isKindOfClass:[NSArray
class]] && [
object count] > 0)
6799 key = [
object oo_stringAtIndex:Ranrot() % [
object count]];
6812 if (
object ==
nil || ([result hasPrefix:
@"["] && [result hasSuffix:
@"]"]))
6816 [
seen addObject:result];
6817 object = [customSounds objectForKey:result];
6818 if( [
object isKindOfClass:[NSArray
class]] && [
object count] > 0)
6820 result = [
object oo_stringAtIndex:Ranrot() % [
object count]];
6821 if ([key hasPrefix:
@"["] && [key hasSuffix:
@"]"]) key=result;
6825 if ([
object isKindOfClass:[NSString
class]])
6830 if (result ==
nil || ![result hasPrefix:
@"["] || ![result hasSuffix:
@"]"])
break;
6831 if ([seen containsObject:result])
6833 OOLogERR(
@"sound.customSounds.recursion",
@"recursion in customsounds.plist for '%@' (at '%@'), no sound will be played.", key, result);
6840 if (result ==
nil) result =
@"__oolite-no-sound";
6844 if ([result isEqualToString:
@"__oolite-no-sound"])
6846 OOLog(
@"sound.customSounds",
@"Could not resolve sound name in customsounds.plist for '%@', no sound will be played.", key);
6853- (NSDictionary *) screenTextureDescriptorForKey:(NSString *)key
6855 id value = [screenBackgrounds objectForKey:key];
6856 while ([value isKindOfClass:[NSArray
class]]) value = [
value objectAtIndex:Ranrot() % [
value count]];
6858 if ([value isKindOfClass:[NSString
class]]) value = [
NSDictionary dictionaryWithObject:value forKey:@"name"];
6859 else if (![value isKindOfClass:[NSDictionary
class]]) value =
nil;
6862 if (![[
self gui] preloadGUITexture:value]) value =
nil;
6868- (void) setScreenTextureDescriptorForKey:(NSString *)key descriptor:(NSDictionary *)desc
6870 NSMutableDictionary *sbCopy = [screenBackgrounds mutableCopy];
6873 [
sbCopy removeObjectForKey:key];
6877 [
sbCopy setObject:desc forKey:key];
6879 [screenBackgrounds release];
6892- (void) setMessageGuiBackgroundColor:(
OOColor *)some_color
6910- (void) displayCountdownMessage:(NSString *) text forCount:(
OOTimeDelta)count
6922- (void) addDelayedMessage:(NSString *)text forCount:(
OOTimeDelta)count afterDelay:(
double)delay
6925 [
msgDict setObject:text forKey:@"message"];
6926 [
msgDict setObject:[
NSNumber numberWithDouble:count] forKey:@"duration"];
6927 [
self performSelector:@selector(addDelayedMessage:) withObject:msgDict afterDelay:delay];
6931- (void) addDelayedMessage:(NSDictionary *) textdict
6933 NSString *msg =
nil;
6936 msg = [
textdict oo_stringForKey:@"message"];
6937 if (msg ==
nil)
return;
6938 msg_duration = [
textdict oo_nonNegativeDoubleForKey:@"duration" defaultValue:3.0];
6950- (void) speakWithSubstitutions:(NSString *)text
6952#if OOLITE_SPEECH_SYNTH
6958 NSString *systemSaid =
nil;
6959 NSString *h_systemSaid =
nil;
6963 systemSaid = systemName;
6966 h_systemSaid = h_systemName;
6968 NSString *spokenText = text;
6971 NSEnumerator *speechEnumerator =
nil;
6972 NSArray *thePair =
nil;
6976 NSString *original_phrase = [
thePair oo_stringAtIndex:0];
6978 NSUInteger replacementIndex;
6980 replacementIndex = 1;
6982 replacementIndex = [
thePair count] > 2 ? 2 : 1;
6985 NSString *replacement_phrase = [
thePair oo_stringAtIndex:replacementIndex];
6986 if (![replacement_phrase isEqualToString:
@"_"])
6988 spokenText = [
spokenText stringByReplacingOccurrencesOfString:original_phrase withString:replacement_phrase];
6991 spokenText = [
spokenText stringByReplacingOccurrencesOfString:systemName withString:systemSaid];
6992 spokenText = [
spokenText stringByReplacingOccurrencesOfString:h_systemName withString:h_systemSaid];
7001- (void) addMessage:(NSString *) text forCount:(
OOTimeDelta) count forceDisplay:(BOOL) forceDisplay
7012 [PLAYER doScriptEvent:OOJSID("consoleMessageReceived") withArgument:text];
7014 [currentMessage release];
7027- (void) addCommsMessage:(NSString *)text forCount:(
OOTimeDelta)count andShowComms:(BOOL)showComms logOnly:(BOOL)logOnly
7029 if ([
PLAYER showDemoShips])
return;
7031 NSString *expandedMessage =
OOExpand(text);
7042 NSString *format =
OOExpandKey(
@"speech-synthesis-incoming-message-@");
7048 [currentMessage release];
7067- (void) showGUIMessage:(NSString *)text withScroll:(BOOL)scroll andColor:(
OOColor *)selectedColor overDuration:(
OOTimeDelta)how_long
7088 [PLAYER doWorldScriptEvent:OOJSIDFromString(system_repopulator) inContext:context withArguments:NULL count:0 timeLimit:kOOJSLongTimeLimit];
7098 OOLog(
@"universe.profile.update",
@"%@",
@"Begin update");
7113 for (i = 0; i < ent_count; i++)
7118 NSString *
volatile update_stage =
@"initialisation";
7120 id volatile update_stage_param =
nil;
7135 if (
EXPECT_NOT([player showDemoShips] && [player guiScreen] == GUI_SCREEN_SHIPLIBRARY))
7137 update_stage =
@"demo management";
7217 update_stage =
@"update:entity";
7218 NSMutableSet *zombies =
nil;
7219 OOLog(
@"universe.profile.update",
@"%@", update_stage);
7220 for (i = 0; i < ent_count; i++)
7222 Entity *thing = my_entities[
i];
7224 update_stage_param = thing;
7225 update_stage =
@"update:entity [%@]";
7243 update_stage =
@"update:list maintenance [%@]";
7250 while (index > 0 && z_distance <
sortedEntities[index - 1]->zero_distance)
7263 update_stage =
@"update:think [%@]";
7278 update_stage_param =
nil;
7283 update_stage =
@"shootin' zombies";
7284 NSEnumerator *zombieEnum =
nil;
7286 for (zombieEnum = [zombies objectEnumerator]; (zombie = [
zombieEnum nextObject]); )
7288 OOLogERR(
@"universe.zombie",
@"Found dead entity %@ in active entity list, removing. This is an internal error, please report it.", zombie);
7294 update_stage =
@"updating linked lists";
7295 OOLog(
@"universe.profile.update",
@"%@", update_stage);
7296 for (i = 0; i < ent_count; i++)
7303 update_stage =
@"collision and shadow detection";
7304 OOLog(
@"universe.profile.update",
@"%@", update_stage);
7316 @catch (NSException *exception)
7318 if ([[exception name] hasPrefix:
@"Oolite"])
7325 if (update_stage_param !=
nil) update_stage = [
NSString stringWithFormat:update_stage, update_stage_param];
7327 OOLog(
kOOLogException,
@"***** Exception during [%@] in [Universe update:] : %@ : %@ *****", update_stage, [exception name], [exception reason]);
7333 update_stage =
@"clean up";
7334 OOLog(
@"universe.profile.update",
@"%@", update_stage);
7335 for (i = 0; i < ent_count; i++)
7347 update_stage =
@"JS Garbage Collection";
7348 OOLog(
@"universe.profile.update",
@"%@", update_stage);
7351 uint32 gcbytes1 = JS_GetGCParameter(JS_GetRuntime(context),JSGC_BYTES);
7357 uint32 gcbytes2 = JS_GetGCParameter(JS_GetRuntime(context),JSGC_BYTES);
7359 if (gcbytes2 < gcbytes1)
7361 OOLog(
@"universe.profile.jsgc",
@"Unplanned JS Garbage Collection from %d to %d",gcbytes1,gcbytes2);
7370 if ([
PLAYER status] == STATUS_DEAD) [PLAYER update:delta_t];
7373 [entitiesDeadThisUpdate autorelease];
7378 [
self prunePreloadingPlanetMaterials];
7381 OOLog(
@"universe.profile.update",
@"%@",
@"Update complete");
7392- (void) setTimeAccelerationFactor:(
double)newTimeAccelerationFactor
7401- (double) timeAccelerationFactor
7407- (void) setTimeAccelerationFactor:(
double)newTimeAccelerationFactor
7419- (void) setECMVisualFXEnabled:(BOOL)isEnabled
7435 Entity *e0, *next, *prev;
7436 OOHPScalar start, finish, next_start, next_finish, prev_start, prev_finish;
7467 if (next_start < finish)
7470 while ((next)&&(next_start < finish))
7474 if (next_finish > finish)
7475 finish = next_finish;
7511 if (prev_start > finish)
7514 while ((prev)&&(prev_start > finish))
7518 if (prev_finish < finish)
7519 finish = prev_finish;
7558 if (next_start < finish)
7561 while ((next)&&(next_start < finish))
7565 if (next_finish > finish)
7566 finish = next_finish;
7602 if (prev_start > finish)
7605 while ((prev)&&(prev_start > finish))
7609 if (prev_finish < finish)
7610 finish = prev_finish;
7648 if (next_start < finish)
7651 while ((next)&&(next_start < finish))
7655 if (next_finish > finish)
7656 finish = next_finish;
7692 if (prev_start > finish)
7695 while ((prev)&&(prev_start > finish))
7699 if (prev_finish < finish)
7700 finish = prev_finish;
7738 if (next_start < finish)
7741 while ((next)&&(next_start < finish))
7745 if (next_finish > finish)
7746 finish = next_finish;
7781 if (prev_start > finish)
7784 while ((prev)&&(prev_start > finish))
7788 if (prev_finish < finish)
7789 finish = prev_finish;
7827 if (next_start < finish)
7830 while ((next)&&(next_start < finish))
7836 if (next_finish > finish)
7837 finish = next_finish;
7873 if (prev_start > finish)
7876 while ((prev)&&(prev_start > finish))
7901 OOLog(
@"general.error.inconsistentState",
@"Unexpected state in collision chain builder prev=%@, prev->c=%@, e0=%@, e0->c=%@",prev,prev->
collision_chain,e0,e0->
collision_chain);
7907 if (prev_finish < finish)
7908 finish = prev_finish;
7947 NSAutoreleasePool *pool =
nil;
7955 for (i = 0; i < 256; i++)
7959 [system_names[
i] release];
7971 NSDictionary *systemData;
7974 NSString *scriptName;
7982 economy = [
systemData oo_unsignedCharForKey:KEY_ECONOMY];
7983 scriptName = [
systemData oo_stringForKey:@"market_script" defaultValue:nil];
8003 stringByAppendingPathComponent:@"Config"]
8004 stringByAppendingPathComponent:@"descriptions.plist"]];
8012static void VerifyDesc(NSString *key,
id desc);
8017 if ([desc rangeOfString:
@"%n"].location != NSNotFound)
8019 OOLog(
@"descriptions.verify.percentN",
@"***** FATAL: descriptions.plist entry \"%@\
" contains the dangerous control sequence %%n.", key);
8028 foreach (subDesc, desc)
8037 if ([desc isKindOfClass:[NSString
class]])
8041 else if ([desc isKindOfClass:[NSArray
class]])
8045 else if ([desc isKindOfClass:[NSNumber
class]])
8051 OOLogERR(
@"descriptions.verify.badType",
@"***** FATAL: descriptions.plist entry for \"%@\
" is neither a string nor an array.", key);
8069 NSString *key =
nil;
8070 if (_descriptions ==
nil)
8072 OOLog(
@"descriptions.verify",
@"%@",
@"***** FATAL: Tried to verify descriptions, but descriptions was nil - unable to load any descriptions.plist file.");
8077 VerifyDesc(key, [_descriptions objectForKey:key]);
8090- (NSDictionary *) explosionSetting:(NSString *)explosion
8092 return [explosionSettings oo_dictionaryForKey:explosion defaultValue:nil];
8121- (NSString *)descriptionForKey:(NSString *)key
8127- (NSString *)descriptionForArrayKey:(NSString *)key index:(
unsigned)index
8129 NSArray *array = [[
self descriptions] oo_arrayForKey:key];
8130 if ([array
count] <= index)
return nil;
8131 return [
array objectAtIndex:index];
8135- (BOOL) descriptionBooleanForKey:(NSString *)key
8149 return [
NSString stringWithFormat:@"%d %d", g, s];
8155 return [
NSString stringWithFormat:@"interstellar: %d %d %d", g, s1, s2];
8166- (NSDictionary *) generateSystemData:(
OOSystemID) s useCache:(BOOL) useCache
8173 NSString *systemKey = [
NSString stringWithFormat:@"%u %u",[PLAYER galaxyNumber],s];
8191 static NSDictionary *interstellarDict =
nil;
8192 if (interstellarDict ==
nil)
8194 NSString *interstellarName =
DESC(
@"interstellar-space");
8195 NSString *notApplicable =
DESC(
@"not-applicable");
8196 NSNumber *minusOne = [
NSNumber numberWithInt:-1];
8197 NSNumber *zero = [
NSNumber numberWithInt:0];
8198 interstellarDict = [[
NSDictionary alloc] initWithObjectsAndKeys:
8199 interstellarName, KEY_NAME,
8200 minusOne, KEY_GOVERNMENT,
8201 minusOne, KEY_ECONOMY,
8202 minusOne, KEY_TECHLEVEL,
8203 zero, KEY_POPULATION,
8204 zero, KEY_PRODUCTIVITY,
8206 notApplicable, KEY_INHABITANTS,
8207 notApplicable, KEY_DESCRIPTION,
8211 return interstellarDict;
8220 return [
self sun] ==
nil;
8228- (void) setSystemDataKey:(NSString *)key value:(NSObject *)object fromManifest:(NSString *)manifest
8236 static BOOL sysdataLocked = NO;
8239 OOLogERR(
@"script.error",
@"%@",
@"System properties cannot be set during 'systemInformationChanged' events to avoid infinite loops.");
8243 BOOL sameGalaxy = (gnum == [PLAYER currentGalaxyID]);
8247 if ([key isEqualToString:
KEY_RADIUS] && sameGalaxy && sameSystem)
8249 OOLogERR(
@"script.error",
@"System property '%@' cannot be set while in the system.",key);
8253 if ([key isEqualToString:
@"coordinates"])
8255 OOLogERR(
@"script.error",
@"System property '%@' cannot be set.",key);
8260 NSString *overrideKey = [
NSString stringWithFormat:@"%u %u", gnum, pnum];
8261 NSDictionary *sysInfo =
nil;
8266 if (
object !=
nil) {
8268 if ([key isEqualToString:
KEY_NAME])
8270 object=(id)[[(NSString *)
object lowercaseString] capitalizedString];
8277 else if ([key isEqualToString:
@"sun_radius"])
8279 if ([
object doubleValue] < 1000.0 || [
object doubleValue] > 10000000.0 )
8281 object = ([
object doubleValue] < 1000.0 ? (id)
@"1000.0" : (id)
@"10000000.0");
8284 else if ([key hasPrefix:
@"corona_"])
8286 object = (id)[NSString stringWithFormat:
@"%f",OOClamp_0_1_f([
object floatValue])];
8311 else if ([key isEqualToString:
@"sun_color"] || [key isEqualToString:
@"star_count_multiplier"] ||
8312 [key isEqualToString:
@"nebula_count_multiplier"] || [key hasPrefix:
@"sky_"])
8325 if ([key isEqualToString:
@"sun_color"])
8340 else if (the_sun !=
nil && ([key hasPrefix:
@"sun_"] || [key hasPrefix:
@"corona_"]))
8344 else if ([key isEqualToString:
@"texture"])
8346 [[
self planet] setUpPlanetFromTexture:(NSString *)object];
8348 else if ([key isEqualToString:
@"texture_hsb_color"])
8350 [[
self planet] setUpPlanetFromTexture: [[
self planet] textureFileName]];
8352 else if ([key isEqualToString:
@"air_color"])
8356 else if ([key isEqualToString:
@"illumination_color"])
8360 else if ([key isEqualToString:
@"air_color_mix_ratio"])
8362 [[
self planet] setAirColorMixRatio:[
sysInfo oo_floatForKey:key]];
8366 sysdataLocked = YES;
8367 [PLAYER doScriptEvent:OOJSID("systemInformationChanged") withArguments:[
NSArray arrayWithObjects:[
NSNumber numberWithInt:gnum],[
NSNumber numberWithInt:pnum],key,object,nil]];
8417- (NSString *) getSystemInhabitants:(
OOSystemID) sys plural:(BOOL)plural
8419 NSString *ret =
nil;
8443 if (sysName ==
nil)
return -1;
8445 NSString *system_name =
nil;
8446 NSString *match = [
sysName lowercaseString];
8448 for (i = 0; i < 256; i++)
8450 system_name = [system_names[
i] lowercaseString];
8451 if ([system_name isEqualToString:match])
8462 OOLog(
@"deprecated.function",
@"%@",
@"findSystemAtCoords");
8467- (NSMutableArray *) nearbyDestinationsWithinRange:(
double)range
8472 NSPoint here = [PLAYER galaxy_coordinates];
8474 for (
unsigned short i = 0; i < 256; i++)
8481 [
NSNumber numberWithDouble:dist], @"distance",
8482 [
NSNumber numberWithInt:i], @"sysID",
8483 [[
self generateSystemData:i] oo_stringForKey:@"sun_gone_nova" defaultValue:@"0"], @"nova",
8497 double min_dist = 10000.0;
8500 BOOL connected[256];
8501 for (i = 0; i < 256; i++)
8504 for (n = 0; n < 3; n++)
8506 for (i = 0; i < 256; i++)
8509 for (j = 0; j < 256; j++)
8515 connected[
j] |= connected[
i];
8516 connected[
i] |= connected[
j];
8522 for (i = 0; i < 256; i++)
8526 if ((connected[i])&&(distance < min_dist)&&(distance != 0.0))
8528 min_dist = distance;
8544 double min_dist = 10000.0;
8547 BOOL connected[256];
8548 for (i = 0; i < 256; i++)
8551 for (n = 0; n < 3; n++)
8553 for (i = 0; i < 256; i++)
8556 for (j = 0; j < 256; j++)
8562 connected[
j] |= connected[
i];
8563 connected[
i] |= connected[
j];
8569 for (i = 0; i < 256; i++)
8573 if ((connected[i])&&(distance < min_dist))
8575 min_dist = distance;
8593 unsigned distance, dx, dy;
8595 unsigned min_dist = 10000;
8597 for (i = 0; i < 256; i++)
8601 NSInteger concealment = [
systemInfo oo_intForKey:@"concealment" defaultValue:OO_SYSTEMCONCEALMENT_NONE];
8608 dx =
ABS(coords.x - ipos.x);
8609 dy =
ABS(coords.y - ipos.y);
8611 if (dx > dy) distance = (dx + dx + dy) / 2;
8612 else distance = (dx + dy + dy) / 2;
8614 if (distance < min_dist)
8616 min_dist = distance;
8620 if ((distance == min_dist)&&(coords.y > ipos.y))
8634- (NSPoint) findSystemCoordinatesWithPrefix:(NSString *) p_fix
8640- (NSPoint) findSystemCoordinatesWithPrefix:(NSString *) p_fix exactMatch:(BOOL) exactMatch
8642 NSString *system_name =
nil;
8643 NSPoint system_coords = NSMakePoint(-1.0,-1.0);
8646 for (i = 0; i < 256; i++)
8649 system_name = [system_names[
i] lowercaseString];
8650 if ((exactMatch && [system_name isEqualToString:p_fix]) || (!exactMatch && [system_name hasPrefix:p_fix]))
8654 NSInteger concealment = [
systemInfo oo_intForKey:@"concealment" defaultValue:OO_SYSTEMCONCEALMENT_NONE];
8668 return system_coords;
8697 if (start == -1 || goal == -1)
return nil;
8699#ifdef CACHE_ROUTE_FROM_SYSTEM_RESULTS
8701 static NSDictionary *c_route =
nil;
8705 if (c_route !=
nil && c_start == start && c_goal == goal && c_optimizeBy == optimizeBy)
8714 if (start > 255 || goal > 255)
return nil;
8716 NSArray *neighbours[256];
8717 BOOL concealed[256];
8718 for (i = 0; i < 256; i++)
8721 NSInteger concealment = [
systemInfo oo_intForKey:@"concealment" defaultValue:OO_SYSTEMCONCEALMENT_NONE];
8736 double maxCost = optimizeBy ==
OPTIMIZED_BY_TIME ? 256 * (7 * 7) : 256 * (7 * 256 + 7);
8742 while ([curr
count] != 0)
8744 for (i = 0; i < [
curr count]; i++) {
8747 for (j = 0; j < [
ns count]; j++)
8761 double lastTime = lastDistance * lastDistance;
8763 double distance = [
ce distance] + lastDistance;
8764 double time = [
ce time] + lastTime;
8768 if (cost < maxCost && (cheapest[n] ==
nil || [cheapest[n] cost] > cost)) {
8773 if (n == goal && cost < maxCost)
8778 [
curr setArray:next];
8779 [
next removeAllObjects];
8783 if (!cheapest[goal])
return nil;
8790 if ([e parent] == -1)
break;
8794#ifdef CACHE_ROUTE_FROM_SYSTEM_RESULTS
8797 c_optimizeBy = optimizeBy;
8823 [closeSystems release];
8863 [
self prunePreloadingPlanetMaterials];
8865 if ([_preloadingPlanetMaterials
count] < 3)
8867 if (_preloadingPlanetMaterials ==
nil) _preloadingPlanetMaterials = [[
NSMutableArray alloc] initWithCapacity:4];
8875 if (![surface isFinishedLoading])
8881 OOMaterial *atmo = [planet atmosphereMaterial];
8916- (NSString *) timeDescription:(
double) interval
8918 double r_time = interval;
8919 NSString* result =
@"";
8923 int days = floor(r_time / 86400);
8924 r_time -= 86400 * days;
8925 result = [
NSString stringWithFormat:@"%@ %d day%@", result, days, (days > 1) ? @"s" : @""];
8929 int hours = floor(r_time / 3600);
8930 r_time -= 3600 * hours;
8931 result = [
NSString stringWithFormat:@"%@ %d hour%@", result, hours, (hours > 1) ? @"s" : @""];
8935 int mins = floor(r_time / 60);
8936 r_time -= 60 * mins;
8937 result = [
NSString stringWithFormat:@"%@ %d minute%@", result, mins, (mins > 1) ? @"s" : @""];
8941 int secs = floor(r_time);
8942 result = [
NSString stringWithFormat:@"%@ %d second%@", result, secs, (secs > 1) ? @"s" : @""];
8948- (NSString *) shortTimeDescription:(
double) interval
8950 double r_time = interval;
8951 NSString* result =
@"";
8954 if (interval <= 0.0)
8955 return DESC(
@"contracts-no-time");
8959 int days = floor(r_time / 86400);
8960 r_time -= 86400 * days;
8961 result = [
NSString stringWithFormat:@"%@ %d %@", result, days, DESC_PLURAL(@"contracts-day-word", days)];
8966 int hours = floor(r_time / 3600);
8967 r_time -= 3600 * hours;
8968 result = [
NSString stringWithFormat:@"%@ %d %@", result, hours, DESC_PLURAL(@"contracts-hour-word", hours)];
8971 if (parts < 2 && r_time > 60)
8973 int mins = floor(r_time / 60);
8974 r_time -= 60 * mins;
8975 result = [
NSString stringWithFormat:@"%@ %d %@", result, mins, DESC_PLURAL(@"contracts-minute-word", mins)];
8978 if (parts < 2 && r_time > 0)
8980 int secs = floor(r_time);
8981 result = [
NSString stringWithFormat:@"%@ %d %@", result, secs, DESC_PLURAL(@"contracts-second-word", secs)];
9015- (void) loadStationMarkets:(NSArray *)marketData
9017 if (marketData ==
nil)
9024 NSDictionary *savedMarket =
nil;
9026 foreach (savedMarket, marketData)
9028 HPVector pos = [
savedMarket oo_hpvectorForKey:@"position"];
9035 if (HPdistance2(pos,[
station position]) < 1000000)
9053 NSMutableDictionary *savedMarket =
nil;
9063 if (stationMarket !=
nil)
9068 [
markets addObject:savedMarket];
9084 float tech_price_boost = (ship_seed.
a + ship_seed.
b) / 256.0;
9090 for (i = 0; i < 256; i++)
9092 long long reference_time = 0x1000000 * floor(current_time / 0x1000000);
9094 long long c_time = ship_seed.
a * 0x10000 + ship_seed.
b * 0x100 + ship_seed.
c;
9095 double ship_sold_time = reference_time + c_time;
9097 if (ship_sold_time < 0)
9098 ship_sold_time += 0x1000000;
9100 double days_until_sale = (ship_sold_time - current_time) / 86400.0;
9109 NSArray *conditions = [
dict oo_arrayForKey:@"conditions"];
9111 if (![player scriptTestConditions:conditions])
9115 NSString *condition_script = [
dict oo_stringForKey:@"condition_script"];
9116 if (condition_script !=
nil)
9119 if (condScript !=
nil)
9123 JSBool allow_purchase;
9132 if (OK) OK = JS_ValueToBoolean(context, result, &allow_purchase);
9136 if (OK && !allow_purchase)
9150 if (specialTL != NSNotFound)
9153 techlevel = specialTL;
9158 techlevel = [
systemInfo oo_unsignedIntForKey:KEY_TECHLEVEL];
9160 unsigned ship_index = (ship_seed.
d * 0x100 + ship_seed.
e) % [keysForShips
count];
9161 NSString *ship_key = [
keysForShips oo_stringAtIndex:ship_index];
9168 int superRand1 = ship_seed.
a * 0x10000 + ship_seed.
c * 0x100 + ship_seed.
e;
9169 uint32_t superRand2 = ship_seed.
b * 0x10000 + ship_seed.
d * 0x100 + ship_seed.
f;
9174 if ((days_until_sale > 0.0) && (days_until_sale < 30.0) && (ship_techlevel <= techlevel) && (
randf() < chance) && (shipBaseDict !=
nil))
9176 NSMutableDictionary* shipDict = [
NSMutableDictionary dictionaryWithDictionary:shipBaseDict];
9177 NSMutableString* shortShipDescription = [
NSMutableString stringWithCapacity:256];
9178 NSString *shipName = [
shipDict oo_stringForKey:@"display_name" defaultValue:[
shipDict oo_stringForKey:KEY_NAME]];
9181 NSMutableArray* extras = [
NSMutableArray arrayWithArray:[[
ship_info oo_dictionaryForKey:KEY_STANDARD_EQUIPMENT] oo_arrayForKey:KEY_EQUIPMENT_EXTRAS]];
9182 NSString* fwdWeaponString = [[
ship_info oo_dictionaryForKey:KEY_STANDARD_EQUIPMENT] oo_stringForKey:KEY_EQUIPMENT_FORWARD_WEAPON];
9183 NSString* aftWeaponString = [[
ship_info oo_dictionaryForKey:KEY_STANDARD_EQUIPMENT] oo_stringForKey:KEY_EQUIPMENT_AFT_WEAPON];
9200 if (fwdWeapon && fwdWeaponString) [
shipDict setObject:fwdWeaponString forKey:KEY_EQUIPMENT_FORWARD_WEAPON];
9201 if (aftWeapon && aftWeaponString) [
shipDict setObject:aftWeaponString forKey:KEY_EQUIPMENT_AFT_WEAPON];
9203 int passengerBerthCount = 0;
9204 BOOL customised = NO;
9205 BOOL weaponCustomized = NO;
9207 NSString *fwdWeaponDesc =
nil;
9209 NSString *shortExtrasKey =
@"shipyard-first-extra";
9214 while ((
randf() < chance) && ([options
count]))
9218 NSString *equipmentKey = [
options oo_stringAtIndex:optionIndex];
9225 NSString *eqShortDesc = [
item name];
9227 if ([item techLevel] > techlevel)
9230 eqTechLevel =
MIN(eqTechLevel, 15U);
9233 if (
randf() * (eqTechLevel - techlevel) < 1.0)
9236 eqPrice *= (tech_price_boost + eqTechLevel - techlevel) * 90 / 100;
9242 if ([item incompatibleEquipment] !=
nil && extras !=
nil)
9244 NSEnumerator *keyEnum =
nil;
9246 BOOL incompatible = NO;
9248 for (keyEnum = [[item incompatibleEquipment] objectEnumerator]; (key = [
keyEnum nextObject]); )
9250 if ([extras containsObject:key])
9252 [
options removeObject:equipmentKey];
9257 if (incompatible)
break;
9260 for (keyEnum = [[item incompatibleEquipment] objectEnumerator]; (key = [
keyEnum nextObject]); )
9262 if ([options containsObject:key])
9271 if (condition_script !=
nil)
9274 if (condScript !=
nil)
9278 JSBool allow_addition;
9287 if (OK) OK = JS_ValueToBoolean(JScontext, result, &allow_addition);
9291 if (OK && !allow_addition)
9302 if ([item requiresEquipment] !=
nil && extras !=
nil)
9304 NSEnumerator *keyEnum =
nil;
9308 for (keyEnum = [[item requiresEquipment] objectEnumerator]; (key = [
keyEnum nextObject]); )
9310 if (![extras containsObject:key])
9318 if ([item requiresAnyEquipment] !=
nil && extras !=
nil)
9320 NSEnumerator *keyEnum =
nil;
9324 for (keyEnum = [[item requiresAnyEquipment] objectEnumerator]; (key = [
keyEnum nextObject]); )
9326 if ([extras containsObject:key])
9336 if ([equipmentKey isEqualTo:
@"EQ_NAVAL_ENERGY_UNIT"])
9338 if ([extras containsObject:
@"EQ_ENERGY_UNIT"])
9340 [
options removeObject:equipmentKey];
9345 if ([equipmentKey hasPrefix:
@"EQ_WEAPON"])
9349 if (availableFacings &
WEAPON_FACING_FORWARD && [new_weapon weaponThreatAssessment] > [fwdWeapon weaponThreatAssessment])
9354 fwdWeaponString = equipmentKey;
9355 fwdWeapon = new_weapon;
9356 [
shipDict setObject:fwdWeaponString forKey:KEY_EQUIPMENT_FORWARD_WEAPON];
9357 weaponCustomized = YES;
9358 fwdWeaponDesc = eqShortDesc;
9363 if (availableFacings &
WEAPON_FACING_AFT && (
isWeaponNone(aftWeapon) || [new_weapon weaponThreatAssessment] > [aftWeapon weaponThreatAssessment]))
9367 aftWeaponString = equipmentKey;
9368 aftWeapon = new_weapon;
9369 [
shipDict setObject:aftWeaponString forKey:KEY_EQUIPMENT_AFT_WEAPON];
9373 [
options removeObject:equipmentKey];
9380 if ([equipmentKey isEqualToString:
@"EQ_PASSENGER_BERTH"])
9386 [
extras addObject:equipmentKey];
9387 passengerBerthCount++;
9393 [
options removeObject:equipmentKey];
9399 [
extras addObject:equipmentKey];
9400 if ([item isVisible])
9402 NSString *item = eqShortDesc;
9404 shortExtrasKey =
@"shipyard-additional-extra";
9407 [
options removeObject:equipmentKey];
9413 [
options removeObject:equipmentKey];
9418 BOOL lowercaseIgnore = [[
self descriptions] oo_boolForKey:@"lowercase_ignore"];
9420 if (passengerBerthCount)
9422 NSString* npb = (passengerBerthCount > 1)? [NSString stringWithFormat:
@"%d ", passengerBerthCount] : (id)
@"";
9423 NSString* ppb =
DESC_PLURAL(
@"passenger-berth", passengerBerthCount);
9424 NSString* extraPassengerBerthsDescription = [
NSString stringWithFormat:DESC(@"extra-@-@-(passenger-berths)"), npb, ppb];
9425 NSString *item = extraPassengerBerthsDescription;
9427 shortExtrasKey =
@"shipyard-additional-extra";
9435 if (weaponCustomized)
9437 NSString *weapon = (lowercaseIgnore ? fwdWeaponDesc : [
fwdWeaponDesc lowercaseString]);
9440 if (price > base_price)
9442 price = base_price +
cunningFee(price - base_price, 0.05);
9447 NSString *shipID = [
NSString stringWithFormat:@"%06x-%06x", superRand1, superRand2];
9451 NSDictionary *ship_info_dictionary = [
NSDictionary dictionaryWithObjectsAndKeys:
9452 shipID, SHIPYARD_KEY_ID,
9453 ship_key, SHIPYARD_KEY_SHIPDATA_KEY,
9454 shipDict, SHIPYARD_KEY_SHIP,
9455 shortShipDescription, KEY_SHORT_DESCRIPTION,
9456 [
NSNumber numberWithUnsignedLongLong:price], SHIPYARD_KEY_PRICE,
9457 extras, KEY_EQUIPMENT_EXTRAS,
9458 [
NSNumber numberWithUnsignedShort:personality], SHIPYARD_KEY_PERSONALITY,
9471 NSMutableArray *resultArray = [[[
resultDictionary allValues] mutableCopy] autorelease];
9472 [
resultArray sortUsingFunction:compareName context:NULL];
9477 while (i < [resultArray
count])
9479 if (
compareName([resultArray objectAtIndex:i - 1], [resultArray objectAtIndex:i],
nil) == NSOrderedSame )
9491 return [
NSArray arrayWithArray:resultArray];
9497 NSDictionary *ship1 = [(
NSDictionary *)
dict1 oo_dictionaryForKey:SHIPYARD_KEY_SHIP];
9498 NSDictionary *ship2 = [(
NSDictionary *)
dict2 oo_dictionaryForKey:SHIPYARD_KEY_SHIP];
9499 NSString *name1 = [
ship1 oo_stringForKey:KEY_NAME];
9500 NSString *name2 = [
ship2 oo_stringForKey:KEY_NAME];
9502 NSComparisonResult result = [[
name1 lowercaseString] compare:[
name2 lowercaseString]];
9503 if (result != NSOrderedSame)
9515 return [
price1 compare:price2];
9523 NSString *ship_desc = [
dict oo_stringForKey:@"ship_desc"];
9527 if (shipyard_info ==
nil)
9529 OOLogERR(
@"universe.tradeInValueForCommanderDictionary.valueCalculationError",
9530 @"Shipyard dictionary entry for ship %@ required for trade in value calculation, but does not exist. Setting ship value to 0.", ship_desc);
9534 base_price = [
shipyard_info oo_unsignedLongLongForKey:SHIPYARD_KEY_PRICE defaultValue:0ULL];
9537 if(base_price == 0ULL)
return base_price;
9545 unsigned ship_missiles = [
dict oo_unsignedIntForKey:@"missiles"];
9546 unsigned ship_max_passengers = [
dict oo_unsignedIntForKey:@"max_passengers"];
9547 NSMutableArray *ship_extra_equipment = [
NSMutableArray arrayWithArray:[[
dict oo_dictionaryForKey:@"extra_equipment"] allKeys]];
9549 NSDictionary *basic_info = [
shipyard_info oo_dictionaryForKey:KEY_STANDARD_EQUIPMENT];
9550 unsigned base_missiles = [
basic_info oo_unsignedIntForKey:KEY_EQUIPMENT_MISSILES];
9551 OOCreditsQuantity base_missiles_value = base_missiles * [UNIVERSE getEquipmentPriceForKey:@"EQ_MISSILE"] / 10;
9552 NSString *base_weapon_key = [
basic_info oo_stringForKey:KEY_EQUIPMENT_FORWARD_WEAPON];
9553 OOCreditsQuantity base_weapons_value = [UNIVERSE getEquipmentPriceForKey:base_weapon_key] / 10;
9554 NSMutableArray *base_extra_equipment = [
NSMutableArray arrayWithArray:[
basic_info oo_arrayForKey:KEY_EQUIPMENT_EXTRAS]];
9555 NSString *weapon_key =
nil;
9558 base_weapon_key = [
basic_info oo_stringForKey:KEY_EQUIPMENT_AFT_WEAPON defaultValue:nil];
9559 if (base_weapon_key !=
nil)
9560 base_weapons_value += [UNIVERSE getEquipmentPriceForKey:base_weapon_key] / 10;
9567 NSArray *missileRoles = [
dict oo_arrayForKey:@"missile_roles"];
9568 if (missileRoles !=
nil)
9571 for (i = 0; i < ship_missiles; i++)
9573 NSString *missile_desc = [
missileRoles oo_stringAtIndex:i];
9574 if (missile_desc !=
nil && ![missile_desc isEqualToString:
@"NONE"])
9576 ship_missiles_value += [UNIVERSE getEquipmentPriceForKey:missile_desc] / 10;
9581 ship_missiles_value = ship_missiles * [UNIVERSE getEquipmentPriceForKey:@"EQ_MISSILE"] / 10;
9584 long long extra_equipment_value = ship_max_passengers * [UNIVERSE getEquipmentPriceForKey:@"EQ_PASSENGER_BERTH"]/10;
9587 extra_equipment_value += ship_missiles_value - base_missiles_value;
9590 if (ship_fwd_weapon)
9593 ship_main_weapons_value = [UNIVERSE getEquipmentPriceForKey:weapon_key] / 10;
9595 if (ship_aft_weapon)
9598 if (base_weapon_key !=
nil)
9600 ship_main_weapons_value += [UNIVERSE getEquipmentPriceForKey:weapon_key] / 10;
9604 ship_other_weapons_value += [UNIVERSE getEquipmentPriceForKey:weapon_key] / 10;
9607 if (ship_port_weapon)
9610 ship_other_weapons_value += [UNIVERSE getEquipmentPriceForKey:weapon_key] / 10;
9612 if (ship_starboard_weapon)
9615 ship_other_weapons_value += [UNIVERSE getEquipmentPriceForKey:weapon_key] / 10;
9619 extra_equipment_value += ship_other_weapons_value;
9620 extra_equipment_value += ship_main_weapons_value - base_weapons_value;
9623 NSString *eq_key =
nil;
9627 for (i = [base_extra_equipment
count]-1; i > 0;i--)
9630 if ([base_extra_equipment indexOfObject:eq_key inRange:NSMakeRange(0, i-1)] != NSNotFound)
9635 for (i = [base_extra_equipment
count]-1; i >= 0; i--)
9638 if ([ship_extra_equipment containsObject:eq_key])
9641 extra_equipment_value -= ([UNIVERSE getEquipmentPriceForKey:eq_key] / 10);
9647 for (i = [ship_extra_equipment
count]-1; i >= 0; i--)
9655 for (i = [ship_extra_equipment
count]-1; i >= 0; i--)
9656 extra_equipment_value += ([
UNIVERSE getEquipmentPriceForKey:[ship_extra_equipment oo_stringAtIndex:i]] / 10);
9659 extra_equipment_value *= extra_equipment_value < 0 ? 1.4 : 0.9;
9663 if ((
long long)scrap_value > (
long long)base_price + extra_equipment_value)
return scrap_value;
9665 return base_price + extra_equipment_value;
9669- (NSString *) brochureDescriptionWithDictionary:(NSDictionary *)dict standardEquipment:(NSArray *)extras optionalEquipment:(NSArray *)options
9671 NSMutableArray *mut_extras = [
NSMutableArray arrayWithArray:extras];
9672 NSString *allOptions = [
options componentsJoinedByString:@" "];
9674 NSMutableString *desc = [
NSMutableString stringWithFormat:@"The %@.", [
dict oo_stringForKey: KEY_NAME]];
9681 [
desc appendFormat:@" Cargo capacity %dt", max_cargo];
9682 BOOL canExpand = ([
allOptions rangeOfString:@"EQ_CARGO_BAY"].location != NSNotFound);
9684 [
desc appendFormat:@" (expandable to %dt at most starports)", max_cargo + extra_cargo];
9685 [
desc appendString:@"."];
9689 float top_speed = [
dict oo_intForKey:@"max_flight_speed"];
9690 [
desc appendFormat:@" Top speed %.3fLS.", 0.001 * top_speed];
9693 if ([mut_extras
count])
9695 unsigned n_berths = 0;
9699 NSString* item_key = [
mut_extras oo_stringAtIndex:i];
9700 if ([item_key isEqual:
@"EQ_PASSENGER_BERTH"])
9709 [
desc appendString:@" Includes luxury accomodation for a single passenger."];
9711 [
desc appendFormat:@" Includes luxury accomodation for %d passengers.", n_berths];
9716 if ([mut_extras
count])
9718 [
desc appendString:@"\nComes with"];
9722 NSString* item_key = [
mut_extras oo_stringAtIndex:i];
9723 NSString* item_desc =
nil;
9724 for (j = 0; ((j < [equipmentData count])&&(!item_desc)) ; j++)
9726 NSString *eq_type = [[equipmentData oo_arrayAtIndex:j] oo_stringAtIndex:EQUIPMENT_KEY_INDEX];
9727 if ([eq_type isEqual:item_key])
9728 item_desc = [[equipmentData oo_arrayAtIndex:j] oo_stringAtIndex:EQUIPMENT_SHORT_DESC_INDEX];
9732 switch ([mut_extras
count] - i)
9735 [
desc appendFormat:@" %@ fitted as standard.", item_desc];
9738 [
desc appendFormat:@" %@ and", item_desc];
9741 [
desc appendFormat:@" %@,", item_desc];
9749 if ([options
count])
9751 [
desc appendString:@"\nCan additionally be outfitted with"];
9753 for (i = 0; i < [
options count]; i++)
9755 NSString* item_key = [
options oo_stringAtIndex:i];
9756 NSString* item_desc =
nil;
9757 for (j = 0; ((j < [equipmentData count])&&(!item_desc)) ; j++)
9759 NSString *eq_type = [[equipmentData oo_arrayAtIndex:j] oo_stringAtIndex:EQUIPMENT_KEY_INDEX];
9760 if ([eq_type isEqual:item_key])
9761 item_desc = [[equipmentData oo_arrayAtIndex:j] oo_stringAtIndex:EQUIPMENT_SHORT_DESC_INDEX];
9765 switch ([options
count] - i)
9768 [
desc appendFormat:@" %@ at suitably equipped starports.", item_desc];
9771 [
desc appendFormat:@" %@ and/or", item_desc];
9774 [
desc appendFormat:@" %@,", item_desc];
9794 Quaternion q_result;
9804 quaternion_normalize(&q_result);
9826 v1.x -= v0.x; v1.y -= v0.y; v1.z -= v0.z;
9827 if (v1.x||v1.y||v1.z)
9828 v1 = HPvector_normal(v1);
9832 v1.x *= radius; v1.y *= radius; v1.z *= radius;
9833 v1.x += v0.x; v1.y += v0.y; v1.z += v0.z;
9855 v1.x -= v0.x; v1.y -= v0.y; v1.z -= v0.z;
9856 if (v1.x||v1.y||v1.z)
9857 v1 = HPvector_normal(v1);
9861 if (v2.x||v2.y||v2.z)
9862 v2 = HPvector_normal(v2);
9865 HPVector v3 = HPcross_product(v1, v2);
9866 if (v3.x||v3.y||v3.z)
9867 v3 = HPvector_normal(v3);
9871 v1.x *= radius; v1.y *= radius; v1.z *= radius;
9872 v1.x += v0.x; v1.y += v0.y; v1.z += v0.z;
9873 v1.x += 15000 * v3.x; v1.y += 15000 * v3.y; v1.z += 15000 * v3.z;
9874 v1.x -= v0.x; v1.y -= v0.y; v1.z -= v0.z;
9875 if (v1.x||v1.y||v1.z)
9876 v1 = HPvector_normal(v1);
9879 v1.x *= radius; v1.y *= radius; v1.z *= radius;
9880 v1.x += v0.x; v1.y += v0.y; v1.z += v0.z;
9886- (NSArray *) listBeaconsWithCode:(NSString *)code
9889 Entity <OOBeaconEntity> *beacon = [
self firstBeacon];
9891 while (beacon !=
nil)
9893 NSString *beaconCode = [
beacon beaconCode];
9894 if ([beaconCode rangeOfString:code options: NSCaseInsensitiveSearch].location != NSNotFound)
9896 [
result addObject:beacon];
9898 beacon = [
beacon nextBeacon];
9901 return [
result sortedArrayUsingSelector:@selector(compareBeaconCodeWith:)];
9905- (void) allShipsDoScriptEvent:(jsid)event andReactToAIMessage:(NSString *)message
9911 for (i = 0; i < ent_count; i++)
9919 for (i = 0; i < ship_count; i++)
9964- (void) setDisplayText:(BOOL) value
9976- (void) setDisplayFPS:(BOOL) value
9988- (void) setAutoSave:(BOOL) value
9991 [[
NSUserDefaults standardUserDefaults] setBool:autoSave forKey:@"autosave"];
10001- (void) setAutoSaveNow:(BOOL) value
10013- (void) setWireframeGraphics:(BOOL) value
10016 [[
NSUserDefaults standardUserDefaults] setBool:wireframeGraphics forKey:@"wireframe-graphics"];
10047 detailLevel = value;
10055 [[
NSUserDefaults standardUserDefaults] setInteger:detailLevel forKey:@"detailLevel"];
10078- (void) handleOoliteException:(NSException *)exception
10080 if (exception !=
nil)
10087 OOLog(
kOOLogException,
@"***** Handling Fatal : %@ : %@ *****",[exception name], [exception reason]);
10088 NSString* exception_msg = [
NSString stringWithFormat:@"Exception : %@ : %@ Please take a screenshot and/or press esc or Q to quit.", [
exception name], [
exception reason]];
10094 OOLog(
kOOLogException,
@"***** Handling Non-fatal : %@ : %@ *****",[exception name], [exception reason]);
10106- (void) setAirResistanceFactor:(GLfloat)newFactor
10115- (void) startSpeakingString:(NSString *) text
10117 [speechSynthesizer startSpeakingString:[
NSString stringWithFormat:@"[[volm %.3f]]%@", 0.3333333f * [
OOSound masterVolume], text]];
10125 [speechSynthesizer stopSpeakingAtBoundary:NSSpeechWordBoundary];
10129 [speechSynthesizer stopSpeaking];
10136 return [speechSynthesizer isSpeaking];
10141- (void) startSpeakingString:(NSString *) text
10143 NSData *utf8 = [text dataUsingEncoding:NSUTF8StringEncoding];
10147 const char *stringToSay = [text UTF8String];
10148 espeak_Synth(stringToSay, strlen(stringToSay) + 1 , 0, POS_CHARACTER, 0, espeakCHARS_UTF8 | espeakPHONEMES | espeakENDPAUSE, NULL, NULL);
10153- (void) stopSpeaking
10161 return espeak_IsPlaying();
10165- (NSString *) voiceName:(
unsigned int) index
10167 if (index >= espeak_voice_count)
10169 return [NSString stringWithCString: espeak_voices[index]->name];
10173- (
unsigned int) voiceNumber:(NSString *) name
10178 const char *
const label = [name UTF8String];
10182 unsigned int index = -1;
10183 while (espeak_voices[++index] && strcmp (espeak_voices[index]->name, label))
10185 return (index < espeak_voice_count) ? index : UINT_MAX;
10189- (
unsigned int) nextVoice:(
unsigned int) index
10191 if (++index >= espeak_voice_count)
10197- (
unsigned int) prevVoice:(
unsigned int) index
10199 if (--index >= espeak_voice_count)
10200 index = espeak_voice_count - 1;
10205- (
unsigned int) setVoice:(
unsigned int) index withGenderM:(BOOL) isMale
10207 if (index == UINT_MAX)
10208 index = [
self voiceNumber:DESC(@"espeak-default-voice")];
10210 if (index < espeak_voice_count)
10212 espeak_VOICE voice = { espeak_voices[index]->name, NULL, NULL, isMale ? 1 : 2 };
10213 espeak_SetVoiceByProperties (&voice);
10221- (void) startSpeakingString:(NSString *) text {}
10223- (void) stopSpeaking {}
10238- (void) setPauseMessageVisible:(BOOL)value
10250- (void) setPermanentMessageLog:(BOOL)value
10262- (void) setAutoMessageLogBg:(BOOL)value
10274- (void) setPermanentCommLog:(BOOL)value
10280- (void) setAutoCommLog:(BOOL)value
10292- (void) setBlockJSPlayerShipProps:(BOOL)value
10321 initWithPixelSize:NSMakeSize(480, 160)
10330 initWithPixelSize:NSMakeSize(360, 120)
10347#if OOLITE_SPEECH_SYNTH
10348 [speechArray autorelease];
10358 [characters autorelease];
10361 [customSounds autorelease];
10364 [globalSettings autorelease];
10371 [screenBackgrounds autorelease];
10375 [roleCategories autorelease];
10378 [autoAIMap autorelease];
10381 [equipmentData autorelease];
10382 [equipmentDataOutfitting autorelease];
10389 [explosionSettings autorelease];
10399 foreach (type, [commodities goods])
10404 [
tmp setObject:container forKey:type];
10408 cargoPods = [[
NSDictionary alloc] initWithDictionary:tmp];
10415 NSMutableArray *badEntities =
nil;
10419 for (i = 0; i < n_entities; i++)
10421 entity = sortedEntities[
i];
10422 if ([entity sessionID] != _sessionID)
10424 OOLogERR(
@"universe.sessionIDs.verify.failed",
@"Invalid entity %@ (came from session %llu, current session is %llu).", [entity shortDescription], [entity sessionID], _sessionID);
10430 foreach (entity, badEntities)
10439- (BOOL) reinitAndShowDemo:(BOOL) showDemo
10443 assert(player !=
nil);
10469 [PLAYER setSpeed:0.0];
10474 [missiontext autorelease];
10480 [demo_ships release];
10499 if (![player setUpAndConfirmOK:YES])
10562 activeWormholes = [[
NSMutableArray arrayWithCapacity:16] retain];
10564 characterPool = [[
NSMutableArray arrayWithCapacity:256] retain];
10581 [[
self currentSystemData] oo_boolForKey:@"stations_require_docking_clearance" defaultValue:YES]];
10595- (Vector) randomPlaceWithinScannerFrom:(Vector)pos alongRoute:(Vector)route withOffset:(
double)offset
10605- (HPVector) fractionalPositionFrom:(HPVector)point0 to:(HPVector)point1 withFraction:(
double)routeFraction
10607 if (routeFraction == NSNotFound) routeFraction =
randf();
10609 point1 = OOHPVectorInterpolate(point0, point1, routeFraction);
10622 if ([entity canCollide])
10624 doLinkedListMaintenanceThisUpdate = YES;
10642 if (sortedEntities[index] != entity)
10644 OOLog(
kOOLogInconsistentState,
@"DEBUG: Universe removeEntity:%@ ENTITY IS NOT IN THE RIGHT PLACE IN THE ZERO_DISTANCE SORTED LIST -- FIXING...", entity);
10647 for (i = 0; (i < n_entities)&&(index == -1); i++)
10648 if (sortedEntities[i] == entity)
10651 OOLog(
kOOLogInconsistentState,
@"DEBUG: Universe removeEntity:%@ ENTITY IS NOT IN THE ZERO_DISTANCE SORTED LIST -- CONTINUING...", entity);
10655 while ((
unsigned)index < n_entities)
10657 while (((
unsigned)index + n < n_entities)&&(sortedEntities[index + n] == entity))
10676 sortedEntities[
index] = sortedEntities[
index + n];
10677 if (sortedEntities[index])
10679 sortedEntities[
index]->zero_index = index;
10684 OOLog(
kOOLogInconsistentState,
@"DEBUG: Universe removeEntity: REMOVED %d EXTRA COPIES OF %@ FROM THE ZERO_DISTANCE SORTED LIST", n - 1, entity);
10695 if ([entities containsObject:entity])
10698 if ([entity isBreakPattern] && ![entity isVisualEffect])
10700 breakPatternCounter--;
10703 if ([entity isShip])
10708 if ([entity isWaypoint])
10713 if ([entity isVisualEffect])
10719 if ([entity isWormhole])
10723 else if ([entity isPlanet])
10738 if (![soundName hasPrefix:
@"["] && ![soundName hasSuffix:
@"]"])
10748 NSString *key =
nil;
10751 id object = [customSounds objectForKey:key];
10752 if([
object isKindOfClass:[NSString
class]])
10756 else if([
object isKindOfClass:[NSArray
class]] && [
object count] > 0)
10758 NSString *soundName =
nil;
10759 foreach (soundName,
object)
10761 if ([soundName isKindOfClass:[NSString
class]])
10776 NSAutoreleasePool *pool =
nil;
10778 while ([activeWormholes
count])
10786 if (![whole isScanned] &&
10787 NSEqualPoints([
PLAYER galaxy_coordinates], [whole destinationCoordinates]) )
10794 @catch (NSException *exception)
10796 OOLog(
kOOLogException,
@"Squashing exception during wormhole unpickling (%@: %@).", [exception name], [exception reason]);
10803- (NSString *)chooseStringForKey:(NSString *)key inDictionary:(NSDictionary *)dictionary
10806 if ([
object isKindOfClass:[NSString
class]])
return object;
10807 else if ([
object isKindOfClass:[NSArray
class]] && [
object count] > 0)
return [
object oo_stringAtIndex:Ranrot() % [
object count]];
10812#if OO_LOCALIZATION_TOOLS
10815- (void) dumpDebugGraphViz
10817 if ([[NSUserDefaults standardUserDefaults] boolForKey:
@"universe-dump-debug-graphviz"])
10819 [
self dumpSystemDescriptionGraphViz];
10824- (void) dumpSystemDescriptionGraphViz
10826 NSMutableString *graphViz =
nil;
10827 NSArray *systemDescriptions =
nil;
10828 NSArray *thisDesc =
nil;
10829 NSUInteger i,
count, j, subCount;
10830 NSString *descLine =
nil;
10831 NSArray *curses =
nil;
10832 NSString *label =
nil;
10833 NSDictionary *keyMap =
nil;
10839 graphViz = [NSMutableString stringWithString:
10840 @"// System description grammar:\n\n"
10841 "digraph system_descriptions\n"
10843 "\tgraph [charset=\"UTF-8\", label=\"System description grammar\", labelloc=t, labeljust=l rankdir=LR compound=true nodesep=0.02 ranksep=1.5 concentrate=true fontname=Helvetica]\n"
10844 "\tedge [arrowhead=dot]\n"
10845 "\tnode [shape=none height=0.2 width=3 fontname=Helvetica]\n\t\n"];
10847 systemDescriptions = [[
self descriptions] oo_arrayForKey:@"system_description"];
10848 count = [systemDescriptions count];
10851 descLine =
DESC(
@"system-description-string");
10853 [graphViz appendFormat:@"\tsystem_description_string [label=\"%@\" shape=ellipse]\n", EscapedGraphVizString(label)];
10854 [
self addNumericRefsInString:descLine
10855 toGraphViz:graphViz
10856 fromNode:@"system_description_string"
10858 [graphViz appendString:@"\t\n"];
10861 [graphViz appendString:
10862 @"\tpercent_I [label=\"%I\\nInhabitants\" shape=diamond]\n"
10863 "\tpercent_H [label=\"%H\\nSystem name\" shape=diamond]\n"
10864 "\tpercent_RN [label=\"%R/%N\\nRandom name\" shape=diamond]\n"
10865 "\tpercent_J [label=\"%J\\nNumbered system name\" shape=diamond]\n"
10866 "\tpercent_G [label=\"%G\\nNumbered system name in chart number\" shape=diamond]\n\t\n"];
10869 [graphViz appendString:@"\tsubgraph cluster_thargoid_curses\n\t{\n\t\tlabel = \"Thargoid curses\"\n"];
10870 curses = [[
self descriptions] oo_arrayForKey:@"thargoid_curses"];
10871 subCount = [curses count];
10872 for (j = 0; j < subCount; ++j)
10875 [graphViz appendFormat:@"\t\tthargoid_curse_%llu [label=\"%@\"]\n", j, EscapedGraphVizString(label)];
10877 [graphViz appendString:@"\t}\n"];
10878 for (j = 0; j < subCount; ++j)
10880 [
self addNumericRefsInString:[curses oo_stringAtIndex:j]
10881 toGraphViz:graphViz
10882 fromNode:[NSString stringWithFormat:@"thargoid_curse_%llu", j]
10885 [graphViz appendString:@"\t\n"];
10889 for (i = 0; i <
count; ++i)
10892 label = [keyMap objectForKey:[NSString stringWithFormat:@"%llu", i]];
10893 if (label ==
nil) label = [NSString stringWithFormat:
@"[%llu]", i];
10894 else label = [NSString stringWithFormat:@"[%llu] (%@)", i, label];
10896 [graphViz appendFormat:@"\tsubgraph cluster_%llu\n\t{\n\t\tlabel=\"%@\"\n", i, EscapedGraphVizString(label)];
10898 thisDesc = [systemDescriptions oo_arrayAtIndex:i];
10899 subCount = [thisDesc count];
10900 for (j = 0; j < subCount; ++j)
10903 [graphViz appendFormat:@"\t\tn%llu_%llu [label=\"\\\"%@\\\"\"]\n", i, j, EscapedGraphVizString(label)];
10906 [graphViz appendString:@"\t}\n"];
10908 [graphViz appendString:@"\t\n"];
10911 for (i = 0; i !=
count; ++i)
10913 thisDesc = [systemDescriptions oo_arrayAtIndex:i];
10914 subCount = [thisDesc count];
10915 for (j = 0; j != subCount; ++j)
10917 descLine = [thisDesc oo_stringAtIndex:j];
10918 [
self addNumericRefsInString:descLine
10919 toGraphViz:graphViz
10920 fromNode:[NSString stringWithFormat:@"n%llu_%llu", i, j]
10926 [graphViz appendString:@"\t}\n"];
10932- (void) addNumericRefsInString:(NSString *)string toGraphViz:(NSMutableString *)graphViz fromNode:(NSString *)fromNode nodeCount:(NSUInteger)nodeCount
10934 NSString *index =
nil;
10935 NSInteger start, end;
10936 NSRange remaining, subRange;
10939 remaining = NSMakeRange(0, [
string length]);
10943 subRange = [
string rangeOfString:@"[" options:NSLiteralSearch range:remaining];
10944 if (subRange.location == NSNotFound)
break;
10945 start = subRange.location + subRange.length;
10946 remaining.length -= start - remaining.location;
10947 remaining.location = start;
10949 subRange = [
string rangeOfString:@"]" options:NSLiteralSearch range:remaining];
10950 if (subRange.location == NSNotFound)
break;
10951 end = subRange.location;
10952 remaining.length -= end - remaining.location;
10953 remaining.location = end;
10955 index = [
string substringWithRange:NSMakeRange(start, end - start)];
10956 i = [
index intValue];
10959 [
graphViz appendFormat:@"\t%@ -> n%u_0 [color=\"%f,0.75,0.8\" lhead=cluster_%u]\n", fromNode, i, ((float)(i * 511 % nodeCount)) / ((float)nodeCount), i];
10962 if ([
string rangeOfString:
@"%I"].location != NSNotFound)
10964 [
graphViz appendFormat:@"\t%@ -> percent_I [color=\"0,0,0.25\"]\n", fromNode];
10966 if ([
string rangeOfString:
@"%H"].location != NSNotFound)
10968 [
graphViz appendFormat:@"\t%@ -> percent_H [color=\"0,0,0.45\"]\n", fromNode];
10970 if ([
string rangeOfString:
@"%R"].location != NSNotFound || [
string rangeOfString:
@"%N"].location != NSNotFound)
10972 [
graphViz appendFormat:@"\t%@ -> percent_RN [color=\"0,0,0.65\"]\n", fromNode];
10976 if ([
string rangeOfString:
@"%J"].location != NSNotFound)
10978 [
graphViz appendFormat:@"\t%@ -> percent_J [color=\"0,0,0.75\"]\n", fromNode];
10981 if ([
string rangeOfString:
@"%G"].location != NSNotFound)
10983 [
graphViz appendFormat:@"\t%@ -> percent_G [color=\"0,0,0.85\"]\n", fromNode];
10991 NSArray *arguments =
nil;
10992 NSEnumerator *argEnum =
nil;
10993 NSString *arg =
nil;
10994 BOOL compileSysDesc = NO, exportSysDesc = NO, xml = NO;
10998 for (argEnum = [arguments objectEnumerator]; (arg = [
argEnum nextObject]); )
11000 if ([arg isEqual:
@"--compile-sysdesc"]) compileSysDesc = YES;
11001 else if ([arg isEqual:
@"--export-sysdesc"]) exportSysDesc = YES;
11002 else if ([arg isEqual:
@"--xml"]) xml = YES;
11003 else if ([arg isEqual:
@"--openstep"]) xml = NO;
11014- (void) prunePreloadingPlanetMaterials
11018 NSUInteger i = [_preloadingPlanetMaterials count];
11021 if ([[_preloadingPlanetMaterials objectAtIndex:i] isFinishedLoading])
11023 [_preloadingPlanetMaterials removeObjectAtIndex:i];
11033 [conditionScripts autorelease];
11044- (void) addConditionScripts:(NSEnumerator *)scripts
11046 NSString *scriptname =
nil;
11047 while ((scriptname = [scripts nextObject]))
11054 [conditionScripts setObject:script forKey:scriptname];
11063 return [conditionScripts objectForKey:scriptname];
11069@implementation OOSound (OOCustomSounds)
11071+ (id) soundWithCustomSoundKey:(NSString *)key
11073 NSString *fileName = [UNIVERSE soundNameForCustomSoundKey:key];
11074 if (fileName ==
nil)
return nil;
11079- (id) initWithCustomSoundKey:(NSString *)key
11088@implementation OOSoundSource (OOCustomSounds)
11090+ (id) sourceWithCustomSoundKey:(NSString *)key
11092 return [[[
self alloc] initWithCustomSoundKey:key] autorelease];
11096- (id) initWithCustomSoundKey:(NSString *)key
11099 if (theSound !=
nil)
11112- (void) playCustomSoundWithKey:(NSString *)key
11122 NSDictionary *one = (NSDictionary *)a;
11123 NSDictionary *two = (NSDictionary *)b;
11124 int pri_one = [one oo_intForKey:@"priority" defaultValue:100];
11125 int pri_two = [two oo_intForKey:@"priority" defaultValue:100];
11126 if (pri_one < pri_two)
return NSOrderedAscending;
11127 if (pri_one > pri_two)
return NSOrderedDescending;
11128 return NSOrderedSame;
11134 NSArray *one = (NSArray *)a;
11135 NSArray *two = (NSArray *)b;
11139 OOCreditsQuantity comp1 = [[one oo_dictionaryAtIndex:EQUIPMENT_EXTRA_INFO_INDEX] oo_unsignedLongLongForKey:@"sort_order" defaultValue:1000];
11140 OOCreditsQuantity comp2 = [[two oo_dictionaryAtIndex:EQUIPMENT_EXTRA_INFO_INDEX] oo_unsignedLongLongForKey:@"sort_order" defaultValue:1000];
11141 if (comp1 < comp2)
return NSOrderedAscending;
11142 if (comp1 > comp2)
return NSOrderedDescending;
11144 comp1 = [one oo_unsignedLongLongAtIndex:EQUIPMENT_TECH_LEVEL_INDEX];
11145 comp2 = [two oo_unsignedLongLongAtIndex:EQUIPMENT_TECH_LEVEL_INDEX];
11146 if (comp1 < comp2)
return NSOrderedAscending;
11147 if (comp1 > comp2)
return NSOrderedDescending;
11149 comp1 = [one oo_unsignedLongLongAtIndex:EQUIPMENT_PRICE_INDEX];
11150 comp2 = [two oo_unsignedLongLongAtIndex:EQUIPMENT_PRICE_INDEX];
11151 if (comp1 < comp2)
return NSOrderedAscending;
11152 if (comp1 > comp2)
return NSOrderedDescending;
11154 return NSOrderedSame;
11160 NSArray *one = (NSArray *)a;
11161 NSArray *two = (NSArray *)b;
11165 OOCreditsQuantity comp1 = [[one oo_dictionaryAtIndex:EQUIPMENT_EXTRA_INFO_INDEX] oo_unsignedLongLongForKey:@"purchase_sort_order" defaultValue:[[one oo_dictionaryAtIndex:EQUIPMENT_EXTRA_INFO_INDEX] oo_unsignedLongLongForKey:@"sort_order" defaultValue:1000]];
11166 OOCreditsQuantity comp2 = [[two oo_dictionaryAtIndex:EQUIPMENT_EXTRA_INFO_INDEX] oo_unsignedLongLongForKey:@"purchase_sort_order" defaultValue:[[two oo_dictionaryAtIndex:EQUIPMENT_EXTRA_INFO_INDEX] oo_unsignedLongLongForKey:@"sort_order" defaultValue:1000]];
11167 if (comp1 < comp2)
return NSOrderedAscending;
11168 if (comp1 > comp2)
return NSOrderedDescending;
11170 comp1 = [one oo_unsignedLongLongAtIndex:EQUIPMENT_TECH_LEVEL_INDEX];
11171 comp2 = [two oo_unsignedLongLongAtIndex:EQUIPMENT_TECH_LEVEL_INDEX];
11172 if (comp1 < comp2)
return NSOrderedAscending;
11173 if (comp1 > comp2)
return NSOrderedDescending;
11175 comp1 = [one oo_unsignedLongLongAtIndex:EQUIPMENT_PRICE_INDEX];
11176 comp2 = [two oo_unsignedLongLongAtIndex:EQUIPMENT_PRICE_INDEX];
11177 if (comp1 < comp2)
return NSOrderedAscending;
11178 if (comp1 > comp2)
return NSOrderedDescending;
11180 return NSOrderedSame;
11186 NSString *result = [UNIVERSE descriptionForKey:key];
11187 if (result ==
nil) result = key;
11195 NSArray *conditions = [[UNIVERSE descriptions] oo_arrayForKey:@"plural-rules"];
11198 NSString *tmp = [UNIVERSE descriptionForKey:key];
11201 static NSMutableSet *warned =
nil;
11203 if (![warned containsObject:tmp])
11205 OOLogWARN(
@"localization.plurals",
@"'%@' found in descriptions.plist, should be '%@%%0'. Localization data needs updating.",key,key);
11206 if (warned ==
nil) warned = [[NSMutableSet alloc] init];
11207 [warned addObject:tmp];
11211 if (conditions ==
nil)
11221 for (index = i = 0; i < [conditions count]; ++index, ++i)
11223 const char *cond = [[conditions oo_stringAtIndex:i] UTF8String];
11227 long int input =
count;
11230 while (isspace (*cond))
11235 while (isspace (*cond))
11238 char command = *cond++;
11250 long int param = strtol(cond, (
char **)&cond, 10);
11265 if (flag ^ (input == param))
11269 if (flag ^ (input != param))
11274 if (flag ^ (input < param))
11278 if (flag ^ (input > param))
#define INTERMEDIATE_CLEAR_DEPTH
#define SCANNER_MAX_RANGE
#define SCANNER_MAX_RANGE2
static NSString *const kOOLogEntityVerificationError
#define OO_DEBUG_POP_PROGRESS()
#define OO_DEBUG_PROGRESS(...)
#define OO_DEBUG_PUSH_PROGRESS(...)
OOGUITabStop OOGUITabSettings[GUI_MAX_COLUMNS]
#define MAIN_GUI_PIXEL_WIDTH
#define MAIN_GUI_PIXEL_HEIGHT
NSRect OORectFromString(NSString *text, GLfloat x, GLfloat y, NSSize siz)
void OODrawString(NSString *text, GLfloat x, GLfloat y, GLfloat z, NSSize siz)
#define BREAK_PATTERN_RING_SPEED
#define BREAK_PATTERN_RING_SPACING
@ kOOBreakPatternMaxSides
NSInteger OOComparisonResult
#define foreachkey(VAR, DICT)
OOINLINE jsval OOJSValueFromViewID(JSContext *context, OOViewID value)
NSString * OOStringFromGraphicsDetail(OOGraphicsDetail detail)
void CompileSystemDescriptions(BOOL asXML)
void ExportSystemDescriptions(BOOL asXML)
NSString * OOStringifySystemDescriptionLine(NSString *line, NSDictionary *indicesToKeys, BOOL useFallback)
void OOStandardsDeprecated(NSString *message)
BOOL OOEnforceStandards(void)
void OOInitDebugSupport(void)
BOOL IsShipPredicate(Entity *entity, void *parameter)
BOOL IsVisualEffectPredicate(Entity *entity, void *parameter)
BOOL YESPredicate(Entity *entity, void *parameter)
HPVector OOHPVectorRandomRadial(OOHPScalar maxLength)
HPVector OOProjectHPVectorToPlane(HPVector point, HPVector plane, HPVector normal)
HPVector OORandomPositionInShell(HPVector centre, OOHPScalar inner, OOHPScalar outer)
const HPVector kZeroHPVector
HPVector OOHPVectorRandomSpatial(OOHPScalar maxLength)
const HPVector kBasisZHPVector
HPVector OORandomPositionInCylinder(HPVector centre1, OOHPScalar exclusion1, HPVector centre2, OOHPScalar exclusion2, OOHPScalar radius)
#define OOJS_PROFILE_EXIT
#define OOJS_PROFILE_ENTER
void OOJSPauseTimeLimiter(void)
OOINLINE jsval OOJSValueFromNativeObject(JSContext *context, id object)
OOINLINE JSContext * OOJSAcquireContext(void)
OOINLINE void OOJSRelinquishContext(JSContext *context)
void OOJSResumeTimeLimiter(void)
#define OOLogWARN(class, format,...)
#define OOLogERR(class, format,...)
NSString *const kOOLogException
NSString *const kOOLogInconsistentState
BOOL OOLogWillDisplayMessagesInClass(NSString *inMessageClass)
#define OOLogOutdentIf(class)
#define OOLog(class, format,...)
NSString *const kOOLogParameterError
#define OOLogIndentIf(class)
OOMatrix OOMatrixMultiply(OOMatrix a, OOMatrix b)
const OOMatrix kIdentityMatrix
Vector OOVectorMultiplyMatrix(Vector v, OOMatrix m)
@ MOUSE_MODE_UI_SCREEN_WITH_INTERACTION
void OOGLLoadModelView(OOMatrix matrix)
void OOGLLookAt(Vector eye, Vector center, Vector up)
OOMatrix OOGLGetModelView(void)
void OOGLPushModelView(void)
void OOGLResetModelView(void)
void OOGLTranslateModelView(Vector vector)
void OOGLFrustum(double left, double right, double bottom, double top, double near, double far)
void OOGLMultModelView(OOMatrix matrix)
OOMatrix OOGLGetModelViewProjection(void)
OOMatrix OOGLPopModelView(void)
void OOGLResetProjection(void)
#define OOVerifyOpenGLState()
BOOL OOCheckOpenGLErrors(NSString *format,...)
void GLScaledLineWidth(GLfloat width)
#define OOSetOpenGLState(STATE)
Vector vector_forward_from_quaternion(Quaternion quat)
void basis_vectors_from_quaternion(Quaternion quat, Vector *outRight, Vector *outUp, Vector *outForward)
void quaternion_set_random(Quaternion *quat)
const Quaternion kIdentityQuaternion
Quaternion quaternion_rotation_between(Vector v0, Vector v1)
void quaternion_rotate_about_y(Quaternion *quat, OOScalar angle)
void quaternion_rotate_about_axis(Quaternion *quat, Vector axis, OOScalar angle)
NSString * OOShipLibraryCategorySingular(NSString *category)
NSString * OOShipLibraryWitchspace(ShipEntity *demo_ship)
NSString * OOShipLibraryTurrets(ShipEntity *demo_ship)
NSString * OOShipLibraryShields(ShipEntity *demo_ship)
NSString * OOShipLibraryCargo(ShipEntity *demo_ship)
NSString * OOShipLibraryCategoryPlural(NSString *category)
static NSString *const kOODemoShipClass
NSString * OOShipLibraryGenerator(ShipEntity *demo_ship)
static NSString *const kOODemoShipShipData
NSString * OOShipLibrarySize(ShipEntity *demo_ship)
NSString * OOShipLibrarySpeed(ShipEntity *demo_ship)
static NSString *const kOODemoShipKey
NSString * OOShipLibraryWeapons(ShipEntity *demo_ship)
NSString * OOShipLibraryTurnRate(ShipEntity *demo_ship)
#define OOExpandKey(key,...)
#define OOExpand(string,...)
NSMutableArray * ScanTokensFromString(NSString *values)
@ OO_SYSTEMCONCEALMENT_NOTHING
@ OO_SYSTEMCONCEALMENT_NONAME
uint8_t OOWeaponFacingSet
NSString * OOCommodityType
uint64_t OOCreditsQuantity
#define VALID_WEAPON_FACINGS
@ WEAPON_FACING_STARBOARD
const Vector kBasisYVector
const Vector kBasisZVector
const Vector kBasisXVector
OOEquipmentType * OOWeaponType
BOOL isWeaponNone(OOWeaponType weapon)
#define ENTITY_PERSONALITY_MAX
NSString * OOEquipmentIdentifierFromWeaponType(OOWeaponType weapon) CONST_FUNC
OOWeaponType OOWeaponTypeFromEquipmentIdentifierSloppy(NSString *string) PURE_FUNC
#define ShipScriptEvent(context, ship, event,...)
#define SUN_SKIM_RADIUS_FACTOR
@ OO_POSTFX_COLORBLINDNESS_TRITAN
#define TIME_ACCELERATION_FACTOR_DEFAULT
#define PASSENGER_BERTH_SPACE
#define MIN_DISTANCE_TO_BUOY
#define DEMO_LIGHT_POSITION
#define DESC_PLURAL(key, count)
#define OOLITE_EXCEPTION_FATAL
#define TIME_ACCELERATION_FACTOR_MAX
NSString * OOLookUpDescriptionPRIV(NSString *key)
#define SAFE_ADDITION_FACTOR2
NSString * OOLookUpPluralDescriptionPRIV(NSString *key, NSInteger count)
NSComparisonResult populatorPrioritySort(id a, id b, void *context)
NSComparisonResult equipmentSortOutfitting(id a, id b, void *context)
NSComparisonResult equipmentSort(id a, id b, void *context)
#define SYSTEM_REPOPULATION_INTERVAL
#define OOLITE_EXCEPTION_DATA_NOT_FOUND
BOOL(* EntityFilterPredicate)(Entity *entity, void *parameter)
#define DOCKED_ILLUM_LEVEL
const GLfloat framebufferQuadVertices[]
static const OOMatrix fwd_matrix
#define SKY_AMBIENT_ADJUSTMENT
static GLfloat docked_light_specular[4]
static NSString *const kOOLogUniversePopulateWitchspace
static const OOMatrix port_matrix
Universe * gSharedUniverse
static const OOMatrix starboard_matrix
#define SUN_AMBIENT_INFLUENCE
static BOOL MaintainLinkedLists(Universe *uni)
static OOComparisonResult compareName(id dict1, id dict2, void *context)
static BOOL demo_light_on
static const OOMatrix aft_matrix
static NSString *const kOOLogEntityVerificationRebuild
static BOOL object_light_on
Entity * gOOJSPlayerIfStale
static GLfloat docked_light_ambient[4]
#define DEMO2_FLY_IN_STAGE_TIME
static GLfloat sun_off[4]
static NSString *const kOOLogUniversePopulateError
#define DEMO2_VANISHING_DISTANCE
const GLuint framebufferQuadIndices[]
static GLfloat docked_light_diffuse[4]
static GLfloat demo_light_position[4]
#define DOCKED_AMBIENT_LEVEL
OOINLINE BOOL EntityInRange(HPVector p1, Entity *e2, float range)
static OOComparisonResult comparePrice(id dict1, id dict2, void *context)
NSDictionary * demoShipData()
void deleteOpenGLObjects()
void drawTargetTextureIntoDefaultFramebuffer()
void verifyEntitySessionIDs()
void setLibraryTextForDemoShip()
void prepareToRenderIntoDefaultFramebuffer()
void verifyDescriptions()
void setUpInitialUniverse()
float randomDistanceWithinScanner()
void populateSpaceFromActiveWormholes()
void setGuiToIntroFirstGo:(BOOL justCobra)
void runLocalizationTools()
void setNextThinkTime:(OOTimeAbsolute ntt)
void setOwner:(ShipEntity *ship)
OOTimeDelta thinkTimeInterval
void setState:(NSString *stateName)
OOTimeAbsolute nextThinkTime
void reactToMessage:context:(NSString *message,[context] NSString *debugContext)
NSString * collisionDescription()
void findShadowedEntities()
BOOL checkEntity:(Entity *ent)
void setDustColor:(OOColor *color)
unsigned isImmuneToBreakPatternHide
void setAtmosphereFogging:(OOColor *fogging)
void removeFromLinkedLists()
void drawImmediate:translucent:(bool immediate,[translucent] bool translucent)
void setUniversalID:(OOUniversalID uid)
OOUniversalID universalID
void setThrowSparks:(BOOL value)
void setVelocity:(Vector vel)
void updateCameraRelativePosition()
void setOrientation:(Quaternion quat)
void update:(OOTimeDelta delta_t)
unsigned collisionTestFilter
GLfloat collisionRadius()
void wasRemovedFromUniverse()
void setScanClass:(OOScanClass sClass)
Vector cameraRelativePosition
void setPositionX:y:z:(OOHPScalar x,[y] OOHPScalar y,[z] OOHPScalar z)
HPVector absolutePositionForSubentityOffset:(HPVector offset)
void setEnergy:(GLfloat amount)
Quaternion normalOrientation()
ShipEntity * parentEntity()
unsigned isExplicitlyNotMainStation
void setStatus:(OOEntityStatus stat)
void setPosition:(HPVector posn)
void setMouseInteractionModeForUIWithMouseInteraction:(BOOL interaction)
GameController * sharedController()
void setGamePaused:(BOOL value)
void logProgress:(NSString *message)
void setMouseInteractionModeForFlight()
void loadPlayerIfRequired()
void setPlayerFileToLoad:(NSString *filename)
void setTextColor:(OOColor *color)
void printLineNoScroll:align:color:fadeTime:key:addToArray:(NSString *str,[align] OOGUIAlignment alignment,[color] OOColor *text_color,[fadeTime] float text_fade,[key] NSString *text_key,[addToArray] NSMutableArray *text_array)
NSDictionary * userSettings()
void setBackgroundColor:(OOColor *color)
void printLongText:align:color:fadeTime:key:addToArray:(NSString *str,[align] OOGUIAlignment alignment,[color] OOColor *text_color,[fadeTime] float text_fade,[key] NSString *text_key,[addToArray] NSMutableArray *text_array)
int drawGUI:drawCursor:(GLfloat alpha,[drawCursor] BOOL drawCursor)
void setAlpha:(GLfloat an_alpha)
void fadeOutFromTime:overDuration:(OOTimeAbsolute now_time,[overDuration] OOTimeDelta duration)
void setLineWidth:(GLfloat value)
NSString * deferredHudName
void setOverallAlpha:(GLfloat newAlphaValue)
void setFov:fromFraction:(float value,[fromFraction] BOOL fromFraction)
void setGammaValue:(float value)
float fov:(BOOL inFraction)
void setMsaa:(BOOL newMsaa)
OOSDRToneMapper sdrToneMapper()
GameController * gameController
void completePendingTasks()
OOAsyncWorkManager * sharedAsyncWorkManager()
void setInnerColor:outerColor:(OOColor *color1,[outerColor] OOColor *color2)
void setLifetime:(double lifetime)
instancetype breakPatternWithPolygonSides:startAngle:aspectRatio:(NSUInteger sides,[startAngle] float startAngleDegrees,[aspectRatio] float aspectRatio)
void setObject:forKey:inCache:(id inElement,[forKey] NSString *inKey,[inCache] NSString *inCacheKey)
id objectForKey:inCache:(NSString *inKey,[inCache] NSString *inCacheKey)
OOCacheManager * sharedCache()
OOCharacter * randomCharacterWithRole:andOriginalSystem:(NSString *c_role,[andOriginalSystem] OOSystemID s)
OOColor * colorWithRed:green:blue:alpha:(float red,[green] float green,[blue] float blue,[alpha] float alpha)
OOColor * brightColorWithDescription:(id description)
OOColor * colorWithDescription:(id description)
void getRed:green:blue:alpha:(float *red,[green] float *green,[blue] float *blue,[alpha] float *alpha)
OOColor * colorWithHue:saturation:brightness:alpha:(float hue,[saturation] float saturation,[brightness] float brightness,[alpha] float alpha)
OOColor * blendedColorWithFraction:ofColor:(float fraction,[ofColor] OOColor *color)
NSString * getRandomCommodity()
OOCommodityMarket * generateMarketForSystemWithEconomy:andScript:(OOEconomyID economy,[andScript] NSString *scriptName)
OOMassUnit massUnitForGood:(NSString *good)
OOMassUnit massUnitForGood:(OOCommodityType good)
NSArray * saveStationAmounts()
OOCargoQuantity quantityForGood:(OOCommodityType good)
NSDictionary * definitionForGood:(OOCommodityType good)
NSString * nameForGood:(OOCommodityType good)
NSString * conditionScript()
OOTechLevelID techLevel()
OOEquipmentType * equipmentTypeWithIdentifier:(NSString *identifier)
OOCreditsQuantity price()
instancetype explosionCloudFromEntity:withSettings:(Entity *entity,[withSettings] NSDictionary *settings)
instancetype laserFlashWithPosition:velocity:color:(HPVector position,[velocity] Vector vel,[color] OOColor *color)
void resetGraphicsState()
OOGraphicsResetManager * sharedManager()
void runCallback:(HPVector location)
BOOL callMethod:inContext:withArguments:count:result:(jsid methodID,[inContext] JSContext *context,[withArguments] jsval *argv,[count] intN argc,[result] jsval *outResult)
OOJavaScriptEngine * sharedEngine()
void garbageCollectionOpportunity:(BOOL force)
void removeObject:(id object)
OOOpenGLExtensionManager * sharedManager()
OOGraphicsDetail defaultDetailLevel()
instancetype shrinkingRingFromEntity:(Entity *sourceEntity)
instancetype ringFromEntity:(Entity *sourceEntity)
id jsScriptFromFileNamed:properties:(NSString *fileName,[properties] NSDictionary *properties)
instancetype groupWithName:(NSString *name)
NSDictionary * shipyardInfoForKey:(NSString *key)
NSArray * playerShipKeys()
OOProbabilitySet * probabilitySetForRole:(NSString *role)
NSString * randomShipKeyForRole:(NSString *role)
OOShipRegistry * sharedRegistry()
NSDictionary * shipInfoForKey:(NSString *key)
NSDictionary * effectInfoForKey:(NSString *key)
id initWithSound:(OOSound *inSound)
void playSound:(OOSound *inSound)
id soundWithCustomSoundKey:(NSString *key)
void setRadius:andCorona:(GLfloat rad,[andCorona] GLfloat corona)
void drawDirectVisionSunGlare()
BOOL changeSunProperty:withDictionary:(NSString *key,[withDictionary] NSDictionary *dict)
void setPosition:(HPVector posn)
void getSpecularComponents:(GLfloat[4] components)
void getDiffuseComponents:(GLfloat[4] components)
BOOL setSunColor:(OOColor *sun_color)
Random_Seed getRandomSeedForCurrentSystem()
NSDictionary * getPropertiesForSystemKey:(NSString *key)
NSPoint getCoordinatesForSystem:inGalaxy:(OOSystemID s,[inGalaxy] OOGalaxyID g)
id getProperty:forSystem:inGalaxy:(NSString *property,[forSystem] OOSystemID s,[inGalaxy] OOGalaxyID g)
NSDictionary * getPropertiesForCurrentSystem()
void setProperty:forSystemKey:andLayer:toValue:fromManifest:(NSString *property,[forSystemKey] NSString *key,[andLayer] OOSystemLayer layer,[toValue] id value,[fromManifest] NSString *manifest)
NSArray * getNeighbourIDsForSystem:inGalaxy:(OOSystemID s,[inGalaxy] OOGalaxyID g)
NSDictionary * getPropertiesForSystem:inGalaxy:(OOSystemID s,[inGalaxy] OOGalaxyID g)
instancetype waypointWithDictionary:(NSDictionary *info)
id weakRefUnderlyingObject()
void setBounty:withReason:(OOCreditsQuantity amount, [withReason] OOLegalStatusReason reason)
void setSystemID:(OOSystemID sid)
void setGuiToStatusScreen()
void setRandom_factor:(int rf)
Vector weaponViewOffset()
OOGalaxyID galaxyNumber()
void setWormhole:(WormholeEntity *newWormhole)
BOOL setUpShipFromDictionary:(NSDictionary *shipDict)
StationEntity * dockedStation()
void setShowDemoShips:(BOOL value)
Quaternion normalOrientation()
BOOL switchHudTo:(NSString *hudFileName)
void addScannedWormhole:(WormholeEntity *wormhole)
void addToAdjustTime:(double seconds)
NSPoint galaxy_coordinates
OOSystemID currentSystemID()
void setGalaxyCoordinates:(NSPoint newPosition)
void runUnsanitizedScriptActions:allowingAIMethods:withContextName:forTarget:(NSArray *unsanitizedActions,[allowingAIMethods] BOOL allowAIMethods,[withContextName] NSString *contextName,[forTarget] ShipEntity *target)
void setJumpCause:(NSString *value)
void setDockedAtMainStation()
void setPreviousSystemID:(OOSystemID sid)
OOMatrix customViewMatrix
Vector customViewUpVector
Vector customViewForwardVector
NSString * dial_clock_adjusted()
BOOL doWorldEventUntilMissionScreen:(jsid message)
PlayerEntity * sharedPlayer()
OOSystemID targetSystemID()
OOSound * ooSoundNamed:inFolder:(NSString *fileName,[inFolder] NSString *folderName)
NSDictionary * dictionaryFromFilesNamed:inFolder:andMerge:(NSString *fileName,[inFolder] NSString *folderName,[andMerge] BOOL mergeFiles)
NSArray * arrayFromFilesNamed:inFolder:andMerge:(NSString *fileName,[inFolder] NSString *folderName,[andMerge] BOOL mergeFiles)
BOOL writeDiagnosticData:toFileNamed:(NSData *data,[toFileNamed] NSString *name)
OOSystemDescriptionManager * systemDescriptionManager()
void setUseAddOns:(NSString *useAddOns)
NSDictionary * roleCategoriesDictionary()
NSDictionary * dictionaryFromFilesNamed:inFolder:mergeMode:cache:(NSString *fileName,[inFolder] NSString *folderName,[mergeMode] OOResourceMergeMode mergeMode,[cache] BOOL useCache)
instancetype elementWithLocation:parent:cost:distance:time:jumps:(OOSystemID location,[parent] OOSystemID parent,[cost] double cost,[distance] double distance,[time] double time,[jumps] int jumps)
void setDemoStartTime:(OOTimeAbsolute time)
void setIsWreckage:(BOOL isw)
void setBounty:withReason:(OOCreditsQuantity amount,[withReason] OOLegalStatusReason reason)
NSDictionary * shipInfoDictionary()
void removeEquipmentItem:(NSString *equipmentKey)
void setFuel:(OOFuelQuantity amount)
void rescaleBy:writeToCache:(GLfloat factor, [writeToCache] BOOL writeToCache)
void setStatus:(OOEntityStatus stat)
void setCargoFlag:(OOCargoFlag flag)
BOOL witchspaceLeavingEffects()
void setRoll:(double amount)
void setDestination:(HPVector dest)
void setGroup:(OOShipGroup *group)
void setSubEntityTakingDamage:(ShipEntity *sub)
void doScriptEvent:(jsid message)
NSArray * portWeaponOffset
void setPrimaryRole:(NSString *role)
NSArray * starboardWeaponOffset
void setHeatInsulation:(GLfloat value)
void setPitch:(double amount)
BOOL isHostileTo:(Entity *entity)
void setAITo:(NSString *aiString)
void enterTargetWormhole()
NSArray * aftWeaponOffset
NSArray * forwardWeaponOffset
void setPendingEscortCount:(uint8_t count)
uint8_t pendingEscortCount()
void setTemperature:(GLfloat value)
void setCrew:(NSArray *crewArray)
void setDemoShip:(OOScalar demoRate)
void doScriptEvent:withArgument:(jsid message,[withArgument] id argument)
void switchAITo:(NSString *aiString)
void setCommodity:andAmount:(OOCommodityType co_type,[andAmount] OOCargoQuantity co_amount)
OOCommodityType commodityType()
BOOL changeProperty:withDictionary:(NSString *key,[withDictionary] NSDictionary *dict)
OOCommodityMarket * localMarket
void setAllowsFastDocking:(BOOL newValue)
OOCommodityMarket * initialiseLocalMarket()
void setRequiresDockingClearance:(BOOL newValue)
void setEquivalentTechLevel:(OOTechLevelID value)
void setLocalMarket:(NSArray *market)
unsigned interstellarUndockingAllowed
void setPlanet:(OOPlanetEntity *planet)
void setLocalShipyard:(NSArray *market)
void setAllegiance:(NSString *newAllegiance)
BOOL role:isInCategory:(NSString *role,[isInCategory] NSString *category)
OOSystemID findSystemNumberAtCoords:withGalaxy:includingHidden:(NSPoint coords,[withGalaxy] OOGalaxyID gal,[includingHidden] BOOL hidden)
NSSpeechSynthesizer * speechSynthesizer
OOGraphicsDetail detailLevel
HPVector legacyPositionFrom:asCoordinateSystem:(HPVector pos,[asCoordinateSystem] NSString *system)
void setTimeAccelerationFactor:(double newTimeAccelerationFactor)
NSDictionary * commodityDataForType:(OOCommodityType type)
void populateNormalSpace()
OOWeakReference * _firstBeacon
Entity< OOBeaconEntity > * lastBeacon()
void setDetailLevelDirectly:(OOGraphicsDetail value)
NSMutableDictionary * conditionScripts
Entity * firstEntityTargetedByPlayerPrecisely()
static BOOL MaintainLinkedLists(Universe *uni)
OOTimeDelta getTimeDelta()
static OOComparisonResult compareName(id dict1, id dict2, void *context)
unsigned countShipsMatchingPredicate:parameter:inRange:ofEntity:(EntityFilterPredicate predicate,[parameter] void *parameter,[inRange] double range,[ofEntity] Entity *entity)
ShipEntity * newShipWithName:usePlayerProxy:isSubentity:(NSString *shipKey,[usePlayerProxy] BOOL usePlayerProxy,[isSubentity] BOOL OO_RETURNS_RETAINED)
void deleteOpenGLObjects()
void setUpUniverseFromWitchspace()
void resetCommsLogColor()
void allShipsDoScriptEvent:andReactToAIMessage:(jsid event,[andReactToAIMessage] NSString *message)
NSString * collisionDescription()
OOINLINE BOOL EntityInRange(HPVector p1, Entity *e2, float range)
void setDockingClearanceProtocolActive:(BOOL newValue)
NSString * system_repopulator
OOTimeAbsolute demo_start_time
OOSystemID targetSystemID
NSString * system_names[256]
unsigned countShipsWithRole:inRange:ofEntity:(NSString *role,[inRange] double range,[ofEntity] Entity *entity)
NSString * defaultAIForRole:(NSString *role)
id nearestEntityMatchingPredicate:parameter:relativeToEntity:(EntityFilterPredicate predicate,[parameter] void *parameter,[relativeToEntity] Entity *entity)
void selectIntro2Previous()
GuiDisplayGen * messageGUI()
void forceWitchspaceEntries()
NSUInteger demo_ship_index
BOOL dockingClearanceProtocolActive()
NSDictionary * customSounds
BOOL doProcedurallyTexturedPlanets
void setPauseMessageVisible:(BOOL value)
OOCreditsQuantity getEquipmentPriceForKey:(NSString *eq_key)
static void VerifyDescArray(NSString *key, NSArray *desc)
NSDictionary * currentSystemData()
NSDictionary * descriptions()
OOCommodities * commodities
void getActiveViewMatrix:forwardVector:upVector:(OOMatrix *outMatrix, [forwardVector] Vector *outForward, [upVector] Vector *outUp)
void showCommsLog:(OOTimeDelta how_long)
NSMutableSet * allStations
NSDictionary * roleCategories
GuiDisplayGen * comm_log_gui
void setAirResistanceFactor:(GLfloat newFactor)
void removeAllEntitiesExceptPlayer()
void setWitchspaceBreakPattern:(BOOL newValue)
NSUInteger demo_ship_subindex
NSDictionary * gameSettings()
BOOL doRemoveEntity:(Entity *entity)
void handleOoliteException:(NSException *ooliteException)
GLuint targetFramebufferID
NSDictionary * _descriptions
void drawWatermarkString:(NSString *watermarkString)
void speakWithSubstitutions:(NSString *text)
ShipEntity * addShipAt:withRole:withinRadius:(HPVector pos,[withRole] NSString *role,[withinRadius] GLfloat radius)
void enterGUIViewModeWithMouseInteraction:(BOOL mouseInteraction)
ShipEntity * addShipWithRole:launchPos:rfactor:(NSString *desc, [launchPos] HPVector launchPos, [rfactor] GLfloat rfactor)
ShipEntity * newShipWithName:(NSString *OO_RETURNS_RETAINED)
ShipEntity * newShipWithRole:(NSString *OO_RETURNS_RETAINED)
void drawTargetTextureIntoDefaultFramebuffer()
void resetFramesDoneThisUpdate()
void setGalaxyTo:andReinit:(OOGalaxyID g,[andReinit] BOOL forced)
HPVector coordinatesFromCoordinateSystemString:(NSString *system_x_y_z)
static void VerifyDescString(NSString *key, NSString *desc)
BOOL doLinkedListMaintenanceThisUpdate
NSArray * getStationMarkets()
NSDictionary * characters
void setMainLightPosition:(Vector sunPos)
void setDisplayText:(BOOL value)
NSMutableDictionary * waypoints
void setECMVisualFXEnabled:(BOOL isEnabled)
OOTimeAbsolute demo_stage_time
void addMessage:forCount:forceDisplay:(NSString *text,[forCount] OOTimeDelta count,[forceDisplay] BOOL forceDisplay)
void populateSystemFromDictionariesWithSun:andPlanet:(OOSunEntity *sun,[andPlanet] OOPlanetEntity *planet)
void addMessage:forCount:(NSString *text,[forCount] OOTimeDelta count)
BOOL deterministic_population
void setUpUniverseFromStation()
void verifyEntitySessionIDs()
NSMutableDictionary * populatorSettings
NSDictionary * screenBackgrounds
void unMagicMainStation()
unsigned countEntitiesMatchingPredicate:parameter:inRange:ofEntity:(EntityFilterPredicate predicate,[parameter] void *parameter,[inRange] double range,[ofEntity] Entity *entity)
void setUpWitchspaceBetweenSystem:andSystem:(OOSystemID s1,[andSystem] OOSystemID s2)
NSDictionary * globalSettings
GuiDisplayGen * message_gui
BOOL addShips:withRole:intoBoundingBox:(int howMany,[withRole] NSString *desc,[intoBoundingBox] BoundingBox bbox)
OOJSScript * getConditionScript:(NSString *scriptname)
static BOOL IsCandidateMainStationPredicate(Entity *entity, void *parameter)
void lightForEntity:(BOOL isLit)
HPVector getWitchspaceExitPosition()
NSMutableArray * findEntitiesMatchingPredicate:parameter:inRange:ofEntity:(EntityFilterPredicate predicate,[parameter] void *parameter,[inRange] double range,[ofEntity] Entity *entity)
NSString * currentMessage
CollisionRegion * universeRegion
NSDictionary * generateSystemData:useCache:(OOSystemID s,[useCache] BOOL useCache)
void setUpUniverseFromMisjump()
NSDictionary * explosionSettings
void clearSystemPopulator()
OOPlanetEntity * cachedPlanet
OOMatrix activeViewMatrix()
NSSize targetFramebufferSize
NSDictionary * getPopulatorSettings()
NSMutableArray * activeWormholes
void setGalaxyTo:(OOGalaxyID g)
void clearPreviousMessage()
NSMutableArray * entities
NSMutableArray * findShipsMatchingPredicate:parameter:inRange:ofEntity:(EntityFilterPredicate predicate,[parameter] void *parameter,[inRange] double range,[ofEntity] Entity *entity)
void setSystemTo:(OOSystemID s)
void setUpInitialUniverse()
void populateSpaceFromActiveWormholes()
BOOL deterministicPopulation()
void prepareToRenderIntoDefaultFramebuffer()
BOOL reinitAndShowDemo:(BOOL showDemo)
OOPlanetEntity * setUpPlanet()
Entity * firstEntityTargetedByPlayer()
NSString * getSystemName:(OOSystemID sys)
OOCommodityMarket * commodityMarket
OOPlanetEntity * planet()
OOSystemDescriptionManager * systemManager
NSPoint findSystemCoordinatesWithPrefix:exactMatch:(NSString *p_fix,[exactMatch] BOOL exactMatch)
BOOL _permanentMessageLog
BOOL inInterstellarSpace()
BOOL _witchspaceBreakPattern
void loadConditionScripts()
static void PreloadOneSound(NSString *soundName)
void setViewDirection:(OOViewID vd)
ShipEntity * newShipWithName:usePlayerProxy:(NSString *shipKey,[usePlayerProxy] BOOL OO_RETURNS_RETAINED)
OOTimeDelta next_repopulation
void setSystemDataForGalaxy:planet:key:value:fromManifest:forLayer:(OOGalaxyID gnum,[planet] OOSystemID pnum,[key] NSString *key,[value] id object,[fromManifest] NSString *manifest,[forLayer] OOSystemLayer layer)
ShipEntity * addWreckageFrom:withRole:at:scale:lifetime:(ShipEntity *ship,[withRole] NSString *wreckRole,[at] HPVector rpos,[scale] GLfloat scale,[lifetime] GLfloat lifetime)
BOOL removeEntity:(Entity *entity)
double timeAccelerationFactor
void setCurrentPostFX:(int newCurrentPostFX)
NSString * getSystemInhabitants:plural:(OOSystemID sys,[plural] BOOL plural)
Entity * sortedEntities[UNIVERSE_MAX_ENTITIES+1]
GLfloat main_light_position[4]
NSArray * addShipsAt:withRole:quantity:withinRadius:asGroup:(HPVector pos,[withRole] NSString *role,[quantity] unsigned count,[withinRadius] GLfloat radius,[asGroup] BOOL isGroup)
void setSkyColorRed:green:blue:alpha:(GLfloat red,[green] GLfloat green,[blue] GLfloat blue,[alpha] GLfloat alpha)
void showGUIMessage:withScroll:andColor:overDuration:(NSString *text,[withScroll] BOOL scroll,[andColor] OOColor *selectedColor,[overDuration] OOTimeDelta how_long)
BOOL _dockingClearanceProtocolActive
BOOL setUseAddOns:fromSaveGame:forceReinit:(NSString *newUse,[fromSaveGame] BOOL saveGame,[forceReinit] BOOL force)
static BOOL IsFriendlyStationPredicate(Entity *entity, void *parameter)
ShipEntity * firstShipHitByLaserFromShip:inDirection:offset:gettingRangeFound:(ShipEntity *srcEntity,[inDirection] OOWeaponFacing direction,[offset] Vector offset,[gettingRangeFound] GLfloat *range_ptr)
ShipEntity * newShipWithName:usePlayerProxy:isSubentity:andScaleFactor:(NSString *shipKey,[usePlayerProxy] BOOL usePlayerProxy,[isSubentity] BOOL isSubentity,[andScaleFactor] float OO_RETURNS_RETAINED)
NSPoint coordinatesForSystem:(OOSystemID s)
void initTargetFramebufferWithViewSize:(NSSize viewSize)
NSArray * neighboursToSystem:(OOSystemID system_number)
OOTimeAbsolute countdown_messageRepeatTime
void setGameView:(MyOpenGLView *view)
NSMutableSet * entitiesDeadThisUpdate
NSArray * shipsForSaleForSystem:withTL:atTime:(OOSystemID s,[withTL] OOTechLevelID specialTL,[atTime] OOTimeAbsolute current_time)
HPVector locationByCode:withSun:andPlanet:(NSString *code,[withSun] OOSunEntity *sun,[andPlanet] OOPlanetEntity *planet)
NSString * getRandomCommodity()
void fillCargopodWithRandomCargo:(ShipEntity *cargopod)
void verifyDescriptions()
void startSpeakingString:(NSString *text)
GLfloat airResistanceFactor
NSString * randomShipKeyForRoleRespectingConditions:(NSString *role)
void addConditionScripts:(NSEnumerator *scripts)
BOOL addEntity:(Entity *entity)
id findOneEntityMatchingPredicate:parameter:(EntityFilterPredicate predicate,[parameter] void *parameter)
NSDictionary * currentWaypoints()
NSString * keyForPlanetOverridesForSystem:inGalaxy:(OOSystemID s,[inGalaxy] OOGalaxyID g)
OOTimeAbsolute messageRepeatTime
NSMutableArray * allPlanets
Class shipClassForShipDictionary:(NSDictionary *dict)
NSString * chooseStringForKey:inDictionary:(NSString *key, [inDictionary] NSDictionary *dictionary)
NSString * keyForInterstellarOverridesForSystems:s1:inGalaxy:(OOSystemID,[s1] OOSystemID s2,[inGalaxy] OOGalaxyID g)
GameController * gameController()
NSDictionary * generateSystemData:(OOSystemID s)
void setLastBeacon:(Entity< OOBeaconEntity > *beacon)
StationEntity * station()
Entity< OOBeaconEntity > * firstBeacon()
GLfloat safeWitchspaceExitDistance()
void addCommsMessage:forCount:andShowComms:logOnly:(NSString *text,[forCount] OOTimeDelta count,[andShowComms] BOOL showComms,[logOnly] BOOL logOnly)
Quaternion getWitchspaceExitRotation()
void selectIntro2NextCategory()
BOOL blockJSPlayerShipProps()
BOOL permanentMessageLog()
void findCollisionsAndShadows()
Entity * entity_for_uid[MAX_ENTITY_UID]
BOOL pauseMessageVisible()
static void VerifyDesc(NSString *key, id desc)
float randomDistanceWithinScanner()
OOTimeAbsolute universal_time
GuiDisplayGen * commLogGUI()
void setLibraryTextForDemoShip()
void setFirstBeacon:(Entity< OOBeaconEntity > *beacon)
StationEntity * cachedStation
void clearBeacon:(Entity< OOBeaconEntity > *beaconShip)
NSString * getSystemName:forGalaxy:(OOSystemID sys,[forGalaxy] OOGalaxyID gnum)
OOWeakReference * _lastBeacon
NSDictionary * generateSystemDataForGalaxy:planet:(OOGalaxyID gnum, [planet] OOSystemID pnum)
OOSystemID currentSystemID()
OOVisualEffectEntity * newVisualEffectWithName:(NSString *OO_RETURNS_RETAINED)
HPVector fractionalPositionFrom:to:withFraction:(HPVector point0, [to] HPVector point1, [withFraction] double routeFraction)
HPVector coordinatesForPosition:withCoordinateSystem:returningScalar:(HPVector pos,[withCoordinateSystem] NSString *system,[returningScalar] GLfloat *my_scalar)
void resizeTargetFramebufferWithViewSize:(NSSize viewSize)
BOOL witchspaceBreakPattern()
void makeSunSkimmer:andSetAI:(ShipEntity *ship,[andSetAI] BOOL setAI)
void selectIntro2PreviousCategory()
NSDictionary * missiontext
static OOComparisonResult comparePrice(id dict1, id dict2, void *context)
NSDictionary * demoShipData()
unsigned countShipsWithPrimaryRole:inRange:ofEntity:(NSString *role,[inRange] double range,[ofEntity] Entity *entity)
void setNextBeacon:(Entity< OOBeaconEntity > *beaconShip)
NSArray * equipmentDataOutfitting
OOCargoQuantity getRandomAmountOfCommodity:(OOCommodityType co_type)
NSPoint destinationCoordinates()
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
RANROTSeed RanrotSeedFromRandomSeed(Random_Seed seed)
RANROTSeed RANROTGetFullSeed(void)
void ranrot_srand(uint32_t seed)
void OOInitReallyRandom(uint64_t seed)
void RANROTSetFullSeed(RANROTSeed seed)
unsigned RanrotWithSeed(RANROTSeed *ioSeed)
double cunningFee(double value, double precision)
void seed_for_planet_description(Random_Seed s_seed)
RANROTSeed MakeRanrotSeed(uint32_t seed)
void rotate_seed(Random_Seed *seed_ptr)
OOINLINE double distanceBetweenPlanetPositions(int x1, int y1, int x2, int y2) INLINE_CONST_FUNC