27#import "MyOpenGLView.h"
98#if OO_LOCALIZATION_TOOLS
103#include <espeak/speak_lib.h>
113#define DEMO2_VANISHING_DISTANCE 650.0
114#define DEMO2_FLY_IN_STAGE_TIME 0.4
117#define MAX_NUMBER_OF_ENTITIES 200
118#define STANDARD_STATION_ROLL 0.4
120#define LANE_WIDTH 51200.0
131 1.0f, 1.0f, 1.0f, 1.0f,
132 1.0f, -1.0f, 1.0f, 0.0f,
133 -1.0f, -1.0f, 0.0f, 0.0f,
134 -1.0f, 1.0f, 0.0f, 1.0f
155#undef CACHE_ROUTE_FROM_SYSTEM_RESULTS
165+ (instancetype) elementWithLocation:(
OOSystemID) location parent:(
OOSystemID)parent cost:(
double) cost distance:(
double) distance time:(
double) time jumps:(
int) jumps;
177+ (instancetype) elementWithLocation:(
OOSystemID) location parent:(
OOSystemID) parent cost:(
double) cost distance:(
double) distance time:(
double) time jumps:(
int) jumps
188 return [
r autorelease];
201@interface Universe (OOPrivate)
203- (void) initTargetFramebufferWithViewSize:(NSSize)viewSize;
205- (void) resizeTargetFramebufferWithViewSize:(NSSize)viewSize;
209- (BOOL) doRemoveEntity:(
Entity *)entity;
212- (HPVector) fractionalPositionFrom:(HPVector)point0 to:(HPVector)point1 withFraction:(
double)routeFraction;
216- (NSString *)chooseStringForKey:(NSString *)key inDictionary:(NSDictionary *)dictionary;
218#if OO_LOCALIZATION_TOOLS
220- (void) dumpDebugGraphViz;
221- (void) dumpSystemDescriptionGraphViz;
223- (void) addNumericRefsInString:(NSString *)string toGraphViz:(NSMutableString *)graphViz fromNode:(NSString *)fromNode nodeCount:(NSUInteger)nodeCount;
233- (void) prunePreloadingPlanetMaterials;
239- (void) setFirstBeacon:(
Entity <OOBeaconEntity> *)beacon;
240- (void) setLastBeacon:(
Entity <OOBeaconEntity> *)beacon;
248- (Vector) randomPlaceWithinScannerFrom:(Vector)pos alongRoute:(Vector)route withOffset:(
double)offset;
267static GLfloat
sun_off[4] = {0.0, 0.0, 0.0, 1.0};
270#define DOCKED_AMBIENT_LEVEL 0.2f
271#define DOCKED_ILLUM_LEVEL 0.7f
278#define SUN_AMBIENT_INFLUENCE 0.75
280#define SKY_AMBIENT_ADJUSTMENT 0.0625
287- (void) setBloom: (BOOL)newBloom
297- (void) setCurrentPostFX: (
int) newCurrentPostFX
313- (void) terminatePostFX:(
int)postFX
321- (
int) nextColorblindMode:(
int) index
329- (
int) prevColorblindMode:(
int) index
342- (void) initTargetFramebufferWithViewSize:(NSSize)viewSize
345 OOGL(glClampColor(GL_CLAMP_VERTEX_COLOR, GL_FALSE));
346 OOGL(glClampColor(GL_CLAMP_READ_COLOR, GL_FALSE));
347 OOGL(glClampColor(GL_CLAMP_FRAGMENT_COLOR, GL_FALSE));
350 OOGL(glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &defaultDrawFBO));
352 GLint previousProgramID;
353 OOGL(glGetIntegerv(GL_CURRENT_PROGRAM, &previousProgramID));
354 GLint previousTextureID;
355 OOGL(glGetIntegerv(GL_TEXTURE_BINDING_2D, &previousTextureID));
357 OOGL(glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &previousVAO));
358 GLint previousArrayBuffer;
359 OOGL(glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &previousArrayBuffer));
360 GLint previousElementBuffer;
361 OOGL(glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &previousElementBuffer));
364 OOGL(glGenFramebuffers(1, &msaaFramebufferID));
365 OOGL(glBindFramebuffer(GL_FRAMEBUFFER, msaaFramebufferID));
368 OOGL(glGenTextures(1, &msaaTextureID));
369 OOGL(glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, msaaTextureID));
370 OOGL(glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 4, GL_RGBA16F, (GLsizei)viewSize.width, (GLsizei)viewSize.height, GL_TRUE));
371 OOGL(glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, 0));
372 OOGL(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, msaaTextureID, 0));
375 OOGL(glGenRenderbuffers(1, &msaaDepthBufferID));
376 OOGL(glBindRenderbuffer(GL_RENDERBUFFER, msaaDepthBufferID));
377 OOGL(glRenderbufferStorageMultisample(GL_RENDERBUFFER, 4, GL_DEPTH_COMPONENT32F, (GLsizei)viewSize.width, (GLsizei)viewSize.height));
378 OOGL(glBindRenderbuffer(GL_RENDERBUFFER, 0));
379 OOGL(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, msaaDepthBufferID));
381 if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
383 OOLogERR(
@"initTargetFramebufferWithViewSize.result",
@"%@",
@"***** Error: Multisample framebuffer not complete");
387 OOGL(glGenFramebuffers(1, &targetFramebufferID));
388 OOGL(glBindFramebuffer(GL_FRAMEBUFFER, targetFramebufferID));
391 OOGL(glGenTextures(1, &targetTextureID));
392 OOGL(glBindTexture(GL_TEXTURE_2D, targetTextureID));
393 OOGL(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, (GLsizei)viewSize.width, (GLsizei)viewSize.height, 0, GL_RGBA, GL_FLOAT, NULL));
394 OOGL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
395 OOGL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
398 OOGL(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, targetTextureID, 0));
401 OOGL(glGenRenderbuffers(1, &targetDepthBufferID));
402 OOGL(glBindRenderbuffer(GL_RENDERBUFFER, targetDepthBufferID));
403 OOGL(glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT32F, (GLsizei)viewSize.width, (GLsizei)viewSize.height));
404 OOGL(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, targetDepthBufferID));
406 GLenum attachment[1] = { GL_COLOR_ATTACHMENT0 };
407 OOGL(glDrawBuffers(1, attachment));
409 if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
411 OOLogERR(
@"initTargetFramebufferWithViewSize.result",
@"%@",
@"***** Error: Framebuffer not complete");
414 OOGL(glBindFramebuffer(GL_FRAMEBUFFER, defaultDrawFBO));
416 targetFramebufferSize = viewSize;
424 OOGL(glGenFramebuffers(1, &passthroughFramebufferID));
425 OOGL(glBindFramebuffer(GL_FRAMEBUFFER, passthroughFramebufferID));
428 OOGL(glGenTextures(2, passthroughTextureID));
429 for (
unsigned int i = 0; i < 2; i++)
431 OOGL(glBindTexture(GL_TEXTURE_2D, passthroughTextureID[i]));
432 OOGL(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, (GLsizei)viewSize.width, (GLsizei)viewSize.height, 0, GL_RGBA, GL_FLOAT, NULL));
433 OOGL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
434 OOGL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
437 OOGL(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, passthroughTextureID[i], 0));
440 GLenum attachments[2] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 };
441 OOGL(glDrawBuffers(2, attachments));
443 if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
445 OOLogERR(
@"initTargetFramebufferWithViewSize.result",
@"%@",
@"***** Error: Passthrough framebuffer not complete");
447 OOGL(glBindFramebuffer(GL_FRAMEBUFFER, defaultDrawFBO));
450 OOGL(glGenFramebuffers(2, pingpongFBO));
451 OOGL(glGenTextures(2, pingpongColorbuffers));
452 for (
unsigned int i = 0; i < 2; i++)
454 OOGL(glBindFramebuffer(GL_FRAMEBUFFER, pingpongFBO[i]));
455 OOGL(glBindTexture(GL_TEXTURE_2D, pingpongColorbuffers[i]));
456 OOGL(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, (GLsizei)viewSize.width, (GLsizei)viewSize.height, 0, GL_RGBA, GL_FLOAT, NULL));
457 OOGL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
458 OOGL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
461 OOGL(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, pingpongColorbuffers[i], 0));
463 if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
465 OOLogERR(
@"initTargetFramebufferWithViewSize.result",
@"%@",
@"***** Error: Pingpong framebuffers not complete");
468 OOGL(glBindFramebuffer(GL_FRAMEBUFFER, defaultDrawFBO));
482 textureProgram = [[
OOShaderProgram shaderProgramWithVertexShaderName:@"oolite-texture.vertex"
483 fragmentShaderName:@"oolite-texture.fragment"
484 prefix:@"#version 330\n"
487 blurProgram = [[
OOShaderProgram shaderProgramWithVertexShaderName:@"oolite-blur.vertex"
488 fragmentShaderName:@"oolite-blur.fragment"
489 prefix:@"#version 330\n"
492 finalProgram = [[
OOShaderProgram shaderProgramWithVertexShaderName:@"oolite-final.vertex"
494 fragmentShaderName:[[UNIVERSE gameView] hdrOutput] ? @"oolite-final-hdr.fragment" : @"oolite-final.fragment"
496 fragmentShaderName:@"oolite-final.fragment"
498 prefix:@"#version 330\n"
502 OOGL(glGenVertexArrays(1, &quadTextureVAO));
503 OOGL(glGenBuffers(1, &quadTextureVBO));
504 OOGL(glGenBuffers(1, &quadTextureEBO));
506 OOGL(glBindVertexArray(quadTextureVAO));
508 OOGL(glBindBuffer(GL_ARRAY_BUFFER, quadTextureVBO));
511 OOGL(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, quadTextureEBO));
514 OOGL(glEnableVertexAttribArray(0));
516 OOGL(glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 *
sizeof(
float), (
void*)0));
517 OOGL(glEnableVertexAttribArray(1));
519 OOGL(glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 *
sizeof(
float), (
void*)(2 *
sizeof(
float))));
523 OOGL(glUseProgram(previousProgramID));
524 OOGL(glBindTexture(GL_TEXTURE_2D, previousTextureID));
525 OOGL(glBindVertexArray(previousVAO));
526 OOGL(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, previousElementBuffer));
527 OOGL(glBindBuffer(GL_ARRAY_BUFFER, previousArrayBuffer));
534 OOGL(glDeleteTextures(1, &msaaTextureID));
535 OOGL(glDeleteTextures(1, &targetTextureID));
536 OOGL(glDeleteTextures(2, passthroughTextureID));
537 OOGL(glDeleteTextures(2, pingpongColorbuffers));
538 OOGL(glDeleteRenderbuffers(1, &msaaDepthBufferID));
539 OOGL(glDeleteRenderbuffers(1, &targetDepthBufferID));
540 OOGL(glDeleteFramebuffers(1, &msaaFramebufferID));
541 OOGL(glDeleteFramebuffers(1, &targetFramebufferID));
542 OOGL(glDeleteFramebuffers(2, pingpongFBO));
543 OOGL(glDeleteFramebuffers(1, &passthroughFramebufferID));
544 OOGL(glDeleteVertexArrays(1, &quadTextureVAO));
545 OOGL(glDeleteBuffers(1, &quadTextureVBO));
546 OOGL(glDeleteBuffers(1, &quadTextureEBO));
553- (void) resizeTargetFramebufferWithViewSize:(NSSize)viewSize
557 OOGL(glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, msaaTextureID));
558 OOGL(glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 4, GL_RGBA16F, (GLsizei)viewSize.width, (GLsizei)viewSize.height, GL_TRUE));
559 OOGL(glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, 0));
562 OOGL(glBindRenderbuffer(GL_RENDERBUFFER, msaaDepthBufferID));
563 OOGL(glRenderbufferStorageMultisample(GL_RENDERBUFFER, 4, GL_DEPTH_COMPONENT32F, (GLsizei)viewSize.width, (GLsizei)viewSize.height));
564 OOGL(glBindRenderbuffer(GL_RENDERBUFFER, 0));
567 OOGL(glBindTexture(GL_TEXTURE_2D, targetTextureID));
568 OOGL(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, (GLsizei)viewSize.width, (GLsizei)viewSize.height, 0, GL_RGBA, GL_FLOAT, NULL));
569 OOGL(glBindTexture(GL_TEXTURE_2D, 0));
571 for (i = 0; i < 2; i++)
573 OOGL(glBindTexture(GL_TEXTURE_2D, pingpongColorbuffers[i]));
574 OOGL(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, (GLsizei)viewSize.width, (GLsizei)viewSize.height, 0, GL_RGBA, GL_FLOAT, NULL));
575 OOGL(glBindTexture(GL_TEXTURE_2D, 0));
578 for (i = 0; i < 2; i++)
580 OOGL(glBindTexture(GL_TEXTURE_2D, passthroughTextureID[i]));
581 OOGL(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, (GLsizei)viewSize.width, (GLsizei)viewSize.height, 0, GL_RGBA, GL_FLOAT, NULL));
582 OOGL(glBindTexture(GL_TEXTURE_2D, 0));
586 OOGL(glBindRenderbuffer(GL_RENDERBUFFER, targetDepthBufferID));
587 OOGL(glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT32F, (GLsizei)viewSize.width, (GLsizei)viewSize.height));
588 OOGL(glBindRenderbuffer(GL_RENDERBUFFER, 0));
590 targetFramebufferSize.width = viewSize.width;
591 targetFramebufferSize.height = viewSize.height;
599 OOGL(glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &previousFBO));
600 GLint previousProgramID;
601 OOGL(glGetIntegerv(GL_CURRENT_PROGRAM, &previousProgramID));
602 GLint previousTextureID;
603 OOGL(glGetIntegerv(GL_TEXTURE_BINDING_2D, &previousTextureID));
605 OOGL(glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &previousVAO));
606 GLint previousActiveTexture;
607 OOGL(glGetIntegerv(GL_ACTIVE_TEXTURE, &previousActiveTexture));
609 OOGL(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
611 OOGL(glDisable(GL_BLEND));
616 NSSize viewSize = [
gameView viewSize];
617 float fboResolution[2] = {viewSize.width, viewSize.height};
619 OOGL(glBindFramebuffer(GL_FRAMEBUFFER, passthroughFramebufferID));
620 OOGL(glClear(GL_COLOR_BUFFER_BIT));
622 OOGL(glUseProgram(program));
623 OOGL(glBindTexture(GL_TEXTURE_2D, targetTextureID));
624 OOGL(glUniform1i(glGetUniformLocation(program,
"image"), 0));
627 OOGL(glBindVertexArray(quadTextureVAO));
628 OOGL(glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0));
629 OOGL(glBindVertexArray(0));
631 OOGL(glBindFramebuffer(GL_FRAMEBUFFER, defaultDrawFBO));
634 BOOL horizontal = YES, firstIteration = YES;
635 unsigned int amount = [
self bloom] ? 10 : 0;
636 OOGL(glUseProgram(blur));
637 for (
unsigned int i = 0; i < amount; i++)
639 OOGL(glBindFramebuffer(GL_FRAMEBUFFER, pingpongFBO[horizontal]));
640 OOGL(glUniform1i(glGetUniformLocation(blur,
"horizontal"), horizontal));
641 OOGL(glActiveTexture(GL_TEXTURE0));
643 OOGL(glBindTexture(GL_TEXTURE_2D, firstIteration ? passthroughTextureID[1] : pingpongColorbuffers[!horizontal]));
644 OOGL(glUniform1i(glGetUniformLocation([blurProgram program],
"imageIn"), 0));
645 OOGL(glBindVertexArray(quadTextureVAO));
646 OOGL(glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0));
647 OOGL(glBindVertexArray(0));
648 horizontal = !horizontal;
651 OOGL(glBindFramebuffer(GL_FRAMEBUFFER, defaultDrawFBO));
654 OOGL(glUseProgram(
final));
656 OOGL(glActiveTexture(GL_TEXTURE0));
657 OOGL(glBindTexture(GL_TEXTURE_2D, passthroughTextureID[0]));
658 OOGL(glUniform1i(glGetUniformLocation(
final,
"scene"), 0));
659 OOGL(glUniform1i(glGetUniformLocation(
final,
"bloom"), [
self bloom]));
660 OOGL(glUniform1f(glGetUniformLocation(
final,
"uTime"), [
self getTime]));
661 OOGL(glUniform2fv(glGetUniformLocation(
final,
"uResolution"), 1, fboResolution));
662 OOGL(glUniform1i(glGetUniformLocation(
final,
"uPostFX"), [
self currentPostFX]));
664 if([gameView hdrOutput])
666 OOGL(glUniform1f(glGetUniformLocation(
final,
"uMaxBrightness"), [gameView hdrMaxBrightness]));
667 OOGL(glUniform1f(glGetUniformLocation(
final,
"uPaperWhiteBrightness"), [gameView hdrPaperWhiteBrightness]));
668 OOGL(glUniform1i(glGetUniformLocation(
final,
"uHDRToneMapper"), [gameView hdrToneMapper]));
671 OOGL(glUniform1i(glGetUniformLocation(
final,
"uSDRToneMapper"), [gameView sdrToneMapper]));
673 OOGL(glActiveTexture(GL_TEXTURE1));
674 OOGL(glBindTexture(GL_TEXTURE_2D, pingpongColorbuffers[!horizontal]));
675 OOGL(glUniform1i(glGetUniformLocation(
final,
"bloomBlur"), 1));
676 OOGL(glUniform1f(glGetUniformLocation(
final,
"uSaturation"), [gameView colorSaturation]));
678 OOGL(glBindVertexArray(quadTextureVAO));
679 OOGL(glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0));
683 OOGL(glBindTexture(GL_TEXTURE_2D, 0));
686 OOGL(glBindFramebuffer(GL_FRAMEBUFFER, previousFBO));
687 OOGL(glActiveTexture(previousActiveTexture));
688 OOGL(glBindTexture(GL_TEXTURE_2D, previousTextureID));
689 OOGL(glUseProgram(previousProgramID));
690 OOGL(glBindVertexArray(previousVAO));
691 OOGL(glEnable(GL_BLEND));
699 [
NSException raise:NSInternalInconsistencyException format:@"%s: expected only one Universe to exist at a time.", __PRETTY_FUNCTION__];
705 if (
self ==
nil)
return nil;
738#if OOLITE_SPEECH_SYNTH
739 OOLog(
@"speech.synthesis",
@"Spoken messages are %@.", ([prefs oo_boolForKey:
@"speech_on" defaultValue:NO] ?
@"on" :
@"off"));
752 autoSave = [
prefs oo_boolForKey:@"autosave" defaultValue:NO];
757 OOLog(
@"MSAA.setup",
@"Multisample anti-aliasing %@requested.", [inGameView msaa] ?
@"" :
@"not ");
764#if OOLITE_SPEECH_SYNTH
766 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0),
776 OOLog(
@"speech.setup.begin",
@"Starting to set up speech synthesizer.");
778 OOLog(
@"speech.setup.end",
@"Finished setting up speech synthesizer.");
783 espeak_Initialize(AUDIO_OUTPUT_PLAYBACK, 100, NULL, 0);
784 espeak_SetParameter(espeakPUNCTUATION, espeakPUNCT_NONE, 0);
785 espeak_SetParameter(espeakVOLUME, volume, 0);
786 espeak_voices = espeak_ListVoices(NULL);
787 for (espeak_voice_count = 0;
789 ++espeak_voice_count)
848#if OO_LOCALIZATION_TOOLS
851 [
self dumpDebugGraphViz];
866 [currentMessage release];
876 [_descriptions release];
877 [characters release];
878 [customSounds release];
879 [globalSettings release];
881 [missiontext release];
882 [equipmentData release];
883 [equipmentDataOutfitting release];
884 [demo_ships release];
886 [screenBackgrounds release];
888 [populatorSettings release];
889 [system_repopulator release];
890 [allPlanets release];
891 [allStations release];
892 [explosionSettings release];
894 [activeWormholes release];
895 [characterPool release];
906 [entitiesDeadThisUpdate release];
910#if OOLITE_SPEECH_SYNTH
911 [speechArray release];
913 [speechSynthesizer release];
918 [conditionScripts release];
944- (void) setDoProcedurallyTexturedPlanets:(BOOL) value
947 [[
NSUserDefaults standardUserDefaults] setBool:doProcedurallyTexturedPlanets forKey:@"procedurally-textured-planets"];
957- (BOOL) setUseAddOns:(NSString *) newUse fromSaveGame:(BOOL) saveGame
963- (BOOL) setUseAddOns:(NSString *) newUse fromSaveGame:(BOOL) saveGame forceReinit:(BOOL)force
965 if (!force && [newUse isEqualToString:
useAddOns])
979 return [entities count];
994 for (i = 0; i < show_count; i++)
996 OOLog(
@"universe.objectDump",
@"Ent:%4u %@", i, [
sortedEntities[i] descriptionForObjDump]);
1002 OOLog(
@"universe.objectDump",
@"entities = %@", [
entities description]);
1009 return [
NSArray arrayWithArray:entities];
1020 NSString *pauseKey = [PLAYER keyBindingDescription2:@"key_pausebutton"];
1022 if ([player status] == STATUS_DOCKED)
1024 if ([
gui setForegroundTextureKey:
@"paused_docked_overlay"])
1036 if ([player guiScreen] != GUI_SCREEN_MAIN && [
gui setForegroundTextureKey:
@"paused_overlay"])
1061 ShipScriptEvent(context, player,
"shipWillEnterWitchspace", STRING_TO_JSVAL(JS_InternString(context, [[player jumpCause] UTF8String])), INT_TO_JSVAL(dest));
1076 if (![wormhole withMisjump])
1099 [UNIVERSE setSkyColorRed:0.0f
1127 if (dockedStation && !interstel)
1135 Entity *ent = [entities objectAtIndex:index];
1136 if ((ent != player)&&(ent != dockedStation))
1153 if (!dockedStation || !interstel)
1159 if ([dockedStation maxFlightSpeed] > 0)
1162 HPVector pos = [UNIVERSE getWitchspaceExitPosition];
1166 if (abs((
int)d1) < 2750)
1168 d1 += ((d1 > 0.0)? 2750.0f: -2750.0f);
1189 [UNIVERSE setSkyColorRed:0.0f
1214 player = [PLAYER retain];
1250 player = [PLAYER retain];
1292 thing = [[
SkyEntity alloc] initWithColors:col1:col2 andSystemInfo: systeminfo];
1312 NSString *populator = [
systeminfo oo_stringForKey:@"populator" defaultValue:@"interstellarSpaceWillPopulate"];
1313 [system_repopulator release];
1316 [PLAYER doWorldScriptEvent:OOJSIDFromString(populator) inContext:context withArguments:NULL count:0 timeLimit:kOOJSLongTimeLimit];
1321 NSArray *script_actions = [
systeminfo oo_arrayForKey:@"script_actions"];
1322 if (script_actions !=
nil)
1324 OOStandardsDeprecated([NSString stringWithFormat:
@"The script_actions system info key is deprecated for %@.",override_key]);
1347 [
planetDict oo_setBool:YES forKey:@"mainForLocalSystem"];
1348 OOPlanetEntity *a_planet = [[
OOPlanetEntity alloc] initFromDictionary:planetDict withAtmosphere:[
planetDict oo_boolForKey:@"has_atmosphere" defaultValue:YES] andSeed:systemSeed forSystem:systemID];
1350 double planet_zpos = [
planetDict oo_floatForKey:@"planet_distance" defaultValue:500000];
1351 planet_zpos *= [
planetDict oo_floatForKey:@"planet_distance_multiplier" defaultValue:1.0];
1353#ifdef OO_DUMP_PLANETINFO
1354 OOLog(
@"planetinfo.record",
@"planet zpos = %f",planet_zpos);
1361 OOPlanetEntity *tmp=[allPlanets objectAtIndex:0];
1363 [allPlanets removeObject:a_planet];
1365 [allPlanets replaceObjectAtIndex:0 withObject:a_planet];
1384 OOPlanetEntity *a_planet;
1386 HPVector stationPos;
1392 unsigned techlevel = [
systeminfo oo_unsignedIntForKey:KEY_TECHLEVEL];
1393 NSString *stationDesc =
nil, *defaultStationDesc =
nil;
1402 sunGoneNova = [
systeminfo oo_boolForKey:@"sun_gone_nova" defaultValue:NO];
1414#ifdef OO_DUMP_PLANETINFO
1415 OOLog(
@"planetinfo.record",
@"seed = %d %d %d %d",system_seed.c,system_seed.d,system_seed.e,system_seed.f);
1416 OOLog(
@"planetinfo.record",
@"coordinates = %d %d",system_seed.d,system_seed.b);
1418#define SPROP(PROP) OOLog(@"planetinfo.record",@#PROP " = \"%@\";",[systeminfo oo_stringForKey:@"" #PROP]);
1419#define IPROP(PROP) OOLog(@"planetinfo.record",@#PROP " = %d;",[systeminfo oo_intForKey:@#PROP]);
1420#define FPROP(PROP) OOLog(@"planetinfo.record",@#PROP " = %f;",[systeminfo oo_floatForKey:@"" #PROP]);
1425 IPROP(productivity);
1438 float h2 = h1 + 1.0 / (1.0 + (
Ranrot() % 5));
1444 thing = [[
SkyEntity alloc] initWithColors:col1:col2 andSystemInfo: systeminfo];
1459 dict_object=[
systeminfo objectForKey:@"sun_color"];
1460 if (dict_object!=
nil)
1481 float defaultSunFlare =
randf()*0.1;
1482 float defaultSunHues = 0.5+
randf()*0.5;
1489 double planet_radius = [
a_planet radius];
1498 double sun_distance;
1499 double sunDistanceModifier;
1500 double safeDistance;
1503 sunDistanceModifier = [
systeminfo oo_nonNegativeDoubleForKey:@"sun_distance_modifier" defaultValue:0.0];
1504 if (sunDistanceModifier < 6.0)
1506 sun_distance = [
systeminfo oo_nonNegativeDoubleForKey:@"sun_distance" defaultValue:(planet_radius*20)];
1508 sun_distance *= [
systeminfo oo_nonNegativeDoubleForKey:@"sun_distance_multiplier" defaultValue:1];
1512 sun_distance = planet_radius * sunDistanceModifier;
1515 sun_radius = [
systeminfo oo_nonNegativeDoubleForKey:@"sun_radius" defaultValue:2.5 * planet_radius];
1517 if ((sun_radius < 1000.0) || (sun_radius > sun_distance / 2 && !sunGoneNova))
1519 OOLogWARN(
@"universe.setup.badSun",
@"Sun radius of %f is not valid for this system",sun_radius);
1520 sun_radius = sun_radius < 1000.0 ? 1000.0 : (sun_distance / 2);
1522#ifdef OO_DUMP_PLANETINFO
1523 OOLog(
@"planetinfo.record",
@"sun_radius = %f",sun_radius);
1525 safeDistance=36 * sun_radius * sun_radius;
1529 HPVector sun_dir = [
systeminfo oo_hpvectorForKey:@"sun_vector"];
1530 sun_distance /= 2.0;
1533 sun_distance *= 2.0;
1534 sunPos = HPvector_subtract([a_planet position],
1535 HPvector_multiply_scalar(sun_dir,sun_distance));
1539 while (HPmagnitude2(sunPos) < safeDistance);
1543 [
a_planet setOrientation:quaternion_rotation_betweenHP(sun_dir,make_HPvector(1.0,0.0,0.0))];
1545#ifdef OO_DUMP_PLANETINFO
1546 OOLog(
@"planetinfo.record",
@"sun_vector = %.3f %.3f %.3f",vf.x,vf.y,vf.z);
1547 OOLog(
@"planetinfo.record",
@"sun_distance = %.0f",sun_distance);
1553 [
sun_dict setObject:[
NSNumber numberWithDouble:sun_radius] forKey:@"sun_radius"];
1554 dict_object=[
systeminfo objectForKey: @"corona_shimmer"];
1555 if (dict_object!=
nil) [
sun_dict setObject:dict_object forKey:@"corona_shimmer"];
1556 dict_object=[
systeminfo objectForKey: @"corona_hues"];
1557 if (dict_object!=
nil)
1559 [
sun_dict setObject:dict_object forKey:@"corona_hues"];
1563 [
sun_dict setObject:[
NSNumber numberWithFloat:defaultSunHues] forKey:@"corona_hues"];
1565 dict_object=[
systeminfo objectForKey: @"corona_flare"];
1566 if (dict_object!=
nil)
1568 [
sun_dict setObject:dict_object forKey:@"corona_flare"];
1572 [
sun_dict setObject:[
NSNumber numberWithFloat:defaultSunFlare] forKey:@"corona_flare"];
1574 dict_object=[
systeminfo objectForKey:KEY_SUNNAME];
1575 if (dict_object!=
nil)
1577 [
sun_dict setObject:dict_object forKey:KEY_SUNNAME];
1579#ifdef OO_DUMP_PLANETINFO
1580 OOLog(
@"planetinfo.record",
@"corona_flare = %f",[sun_dict oo_floatForKey:
@"corona_flare"]);
1581 OOLog(
@"planetinfo.record",
@"corona_hues = %f",[sun_dict oo_floatForKey:
@"corona_hues"]);
1582 OOLog(
@"planetinfo.record",
@"sun_color = %@",[bgcolor descriptionComponents]);
1584 a_sun = [[
OOSunEntity alloc] initSunWithColor:bgcolor andDictionary:sun_dict];
1606 vf = [
systeminfo oo_vectorForKey:@"station_vector"];
1607#ifdef OO_DUMP_PLANETINFO
1608 OOLog(
@"planetinfo.record",
@"station_vector = %.3f %.3f %.3f",vf.x,vf.y,vf.z);
1610 stationPos = HPvector_subtract(stationPos, vectorToHPVector(vector_multiply_scalar(vf, 2.0 * planet_radius)));
1614 stationDesc = [
systeminfo oo_stringForKey:@"station" defaultValue:@"coriolis"];
1615#ifdef OO_DUMP_PLANETINFO
1616 OOLog(
@"planetinfo.record",
@"station = %@",stationDesc);
1619 a_station = (
StationEntity *)[
self newShipWithRole:stationDesc];
1631 if (![a_station isStation] || ![a_station validForAddToUniverse])
1633 if (a_station ==
nil)
1636 OOLog(
@"universe.setup.badStation",
@"Failed to set up a ship for role \"%@\
" as system station, trying again with \"%@\".", stationDesc, defaultStationDesc);
1640 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);
1643 stationDesc = defaultStationDesc;
1644 a_station = (
StationEntity *)[
self newShipWithRole:stationDesc];
1646 if (![a_station isStation] || ![a_station validForAddToUniverse])
1648 if (a_station ==
nil)
1650 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);
1654 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);
1658 a_station = (
StationEntity *)[
self newShipWithName:
@"coriolis-station"];
1659 if (![a_station isStation] || ![a_station validForAddToUniverse])
1661 OOLog(
@"universe.setup.badStation",
@"%@",
@"Could not create built-in Coriolis station! Generating a stationless system.");
1667 if (a_station !=
nil)
1702 BOOL sunGoneNova = [
systeminfo oo_boolForKey:@"sun_gone_nova"];
1708 HPVector v0 = make_HPvector(0,0,34567.89);
1709 double min_safe_dist2 = 6000000.0 * 6000000.0;
1711 while (HPmagnitude2(
cachedSun->position) < min_safe_dist2)
1715 sunPos = HPvector_add(sunPos, v0);
1730 if ([
PLAYER status] != STATUS_START_GAME)
1732 NSString *populator = [
systeminfo oo_stringForKey:@"populator" defaultValue:(sunGoneNova)?@"novaSystemWillPopulate":@"systemWillPopulate"];
1733 [system_repopulator release];
1734 system_repopulator = [[
systeminfo oo_stringForKey:@"repopulator" defaultValue:(sunGoneNova)?@"novaSystemWillRepopulate":@"systemWillRepopulate"] retain];
1737 [PLAYER doWorldScriptEvent:OOJSIDFromString(populator) inContext:context withArguments:NULL count:0 timeLimit:kOOJSLongTimeLimit];
1745 NSArray *script_actions = [
systeminfo oo_arrayForKey:@"script_actions"];
1746 if (script_actions !=
nil)
1748 OOStandardsDeprecated([NSString stringWithFormat:
@"The script_actions system info key is deprecated for %@.",[
self getSystemName:
systemID]]);
1752 [PLAYER runUnsanitizedScriptActions:script_actions
1753 allowingAIMethods:NO
1754 withContextName:@"<system script_actions>"
1766 [populatorSettings release];
1777- (void) setPopulatorSetting:(NSString *)key to:(NSDictionary *)setting
1781 [populatorSettings removeObjectForKey:key];
1785 [populatorSettings setObject:setting forKey:key];
1796- (void) populateSystemFromDictionariesWithSun:(
OOSunEntity *)sun andPlanet:(OOPlanetEntity *)planet
1799 NSArray *blocks = [populatorSettings allValues];
1800 NSEnumerator *enumerator = [[
blocks sortedArrayUsingFunction:populatorPrioritySort context:nil] objectEnumerator];
1801 NSDictionary *populator =
nil;
1803 uint32_t i, locationSeed, groupCount, rndvalue;
1806 NSString *locationCode =
nil;
1808 while ((populator = [enumerator nextObject]))
1817 locationSeed = [
populator oo_unsignedIntForKey:@"locationSeed" defaultValue:0];
1818 groupCount = [
populator oo_unsignedIntForKey:@"groupCount" defaultValue:1];
1820 for (i = 0; i < groupCount; i++)
1822 locationCode = [
populator oo_stringForKey:@"location" defaultValue:@"COORDINATES"];
1823 if ([locationCode isEqualToString:
@"COORDINATES"])
1825 location = [
populator oo_hpvectorForKey:@"coordinates" defaultValue:kZeroHPVector];
1829 if (locationSeed != 0)
1856 if(locationSeed != 0)
1863 pdef = [
populator objectForKey:@"callbackObj"];
1886- (HPVector) locationByCode:(NSString *)code withSun:(
OOSunEntity *)sun andPlanet:(OOPlanetEntity *)planet
1889 if ([code isEqualToString:
@"WITCHPOINT"] ||
sun ==
nil ||
planet ==
nil || [
sun goneNova])
1896 if ([code isEqualToString:
@"LANE_WPS"])
1899 double l1 = HPmagnitude([
planet position]);
1900 double l2 = HPmagnitude(HPvector_subtract([
sun position],[
planet position]));
1901 double l3 = HPmagnitude([
sun position]);
1902 double total = l1+l2+l3;
1903 float choice =
randf();
1904 if (choice < l1/total)
1908 else if (choice < (l1+l2)/total)
1917 else if ([code isEqualToString:
@"LANE_WP"])
1921 else if ([code isEqualToString:
@"LANE_WS"])
1925 else if ([code isEqualToString:
@"LANE_PS"])
1929 else if ([code isEqualToString:
@"STATION_AEGIS"])
1937 else if ([code isEqualToString:
@"PLANET_ORBIT_LOW"])
1941 else if ([code isEqualToString:
@"PLANET_ORBIT"])
1945 else if ([code isEqualToString:
@"PLANET_ORBIT_HIGH"])
1949 else if ([code isEqualToString:
@"STAR_ORBIT_LOW"])
1953 else if ([code isEqualToString:
@"STAR_ORBIT"])
1957 else if ([code isEqualToString:
@"STAR_ORBIT_HIGH"])
1961 else if ([code isEqualToString:
@"TRIANGLE"])
1974 result = HPvector_add(HPvector_multiply_scalar([
planet position],r),HPvector_multiply_scalar([
sun position],s));
1979 else if ([code isEqualToString:
@"INNER_SYSTEM"])
1986 }
while (HPdistance2(result,[
sun position]) < [
sun radius]*[
sun radius]*9.0);
1988 else if ([code isEqualToString:
@"INNER_SYSTEM_OFFPLANE"])
1992 else if ([code isEqualToString:
@"OUTER_SYSTEM"])
1998 else if ([code isEqualToString:
@"OUTER_SYSTEM_OFFPLANE"])
2012- (void) setAmbientLightLevel:(
float)newValue
2014 NSAssert(
UNIVERSE !=
nil,
@"Attempt to set ambient light level with a non yet existent universe.");
2047 GLfloat sun_pos[] = {0.0, 0.0, 0.0, 1.0};
2048 GLfloat sun_ambient[] = {0.0, 0.0, 0.0, 1.0};
2059 OOGL(glLightfv(GL_LIGHT1, GL_AMBIENT, sun_ambient));
2072 OOGL(glLightfv(GL_LIGHT1, GL_AMBIENT, sun_ambient));
2077 OOGL(glLightfv(GL_LIGHT1, GL_POSITION, sun_pos));
2110- (void) setMainLightPosition: (Vector) sunPos
2119- (
ShipEntity *) addShipWithRole:(NSString *)desc launchPos:(HPVector)launchPos rfactor:(GLfloat)rfactor
2124 launchPos.x += 2 * rfactor * (
randf() - 0.5);
2125 launchPos.y += 2 * rfactor * (
randf() - 0.5);
2126 launchPos.z += 2 * rfactor * (
randf() - 0.5);
2139 if (![ship crew] && ![ship isUnpiloted])
2144 if ([ship scanClass] == CLASS_NOT_SET)
2156- (void) addShipWithRole:(NSString *) desc nearRouteOneAt:(
double) route_fraction
2172- (HPVector) coordinatesForPosition:(HPVector) pos withCoordinateSystem:(NSString *) system returningScalar:(GLfloat*) my_scalar
2209 NSString* l_sys = [
system lowercaseString];
2210 if ([l_sys length] != 3)
2212 OOPlanetEntity* the_planet = [
self planet];
2214 if (the_planet ==
nil || the_sun ==
nil || [l_sys isEqualToString:
@"abs"])
2216 if (my_scalar) *my_scalar = 1.0;
2220 HPVector p_pos = the_planet->
position;
2221 HPVector s_pos = the_sun->
position;
2223 const char* c_sys = [
l_sys UTF8String];
2224 HPVector p0, p1, p2;
2233 p1 = p_pos; p2 = s_pos;
break;
2235 p1 = s_pos; p2 = p_pos;
break;
2245 p1 = w_pos; p2 = s_pos;
break;
2247 p1 = s_pos; p2 = w_pos;
break;
2257 p1 = w_pos; p2 = p_pos;
break;
2259 p1 = p_pos; p2 = w_pos;
break;
2267 HPVector k = HPvector_normal_or_zbasis(HPvector_subtract(p1, p0));
2268 HPVector v = HPvector_normal_or_xbasis(HPvector_subtract(p2, p0));
2270 HPVector j = HPcross_product(k, v);
2271 HPVector i = HPcross_product(j, k);
2273 GLfloat scale = 1.0;
2285 scale = HPmagnitude(HPvector_subtract(p1, p0));
2299 HPVector result = p0;
2300 result.x += scale * (pos.x * i.x + pos.y * j.x + pos.z * k.x);
2301 result.y += scale * (pos.x * i.y + pos.y * j.y + pos.z * k.y);
2302 result.z += scale * (pos.x * i.z + pos.y * j.z + pos.z * k.z);
2308- (NSString *) expressPosition:(HPVector) pos inCoordinateSystem:(NSString *) system
2311 return [
NSString stringWithFormat:@"%@ %.2f %.2f %.2f", system, result.x, result.y, result.z];
2315- (HPVector) legacyPositionFrom:(HPVector) pos asCoordinateSystem:(NSString *) system
2317 NSString* l_sys = [
system lowercaseString];
2318 if ([l_sys length] != 3)
2320 OOPlanetEntity* the_planet = [
self planet];
2322 if (the_planet ==
nil || the_sun ==
nil || [l_sys isEqualToString:
@"abs"])
2327 HPVector p_pos = the_planet->
position;
2328 HPVector s_pos = the_sun->
position;
2330 const char* c_sys = [
l_sys UTF8String];
2331 HPVector p0, p1, p2;
2340 p1 = p_pos; p2 = s_pos;
break;
2342 p1 = s_pos; p2 = p_pos;
break;
2352 p1 = w_pos; p2 = s_pos;
break;
2354 p1 = s_pos; p2 = w_pos;
break;
2364 p1 = w_pos; p2 = p_pos;
break;
2366 p1 = p_pos; p2 = w_pos;
break;
2374 HPVector k = HPvector_normal_or_zbasis(HPvector_subtract(p1, p0));
2375 HPVector v = HPvector_normal_or_xbasis(HPvector_subtract(p2, p0));
2377 HPVector j = HPcross_product(k, v);
2378 HPVector i = HPcross_product(j, k);
2380 GLfloat scale = 1.0;
2395 scale = 1.0f / HPdistance(p1, p0);
2407 HPVector r_pos = HPvector_subtract(pos, p0);
2408 HPVector result = make_HPvector(scale * (r_pos.x * i.x + r_pos.y * i.y + r_pos.z * i.z),
2409 scale * (r_pos.x * j.x + r_pos.y * j.y + r_pos.z * j.z),
2410 scale * (r_pos.x * k.x + r_pos.y * k.y + r_pos.z * k.z) );
2416- (HPVector) coordinatesFromCoordinateSystemString:(NSString *) system_x_y_z
2419 if ([tokens
count] != 4)
2422 return make_HPvector(0,0,0);
2429- (BOOL) addShipWithRole:(NSString *) desc nearPosition:(HPVector) pos withCoordinateSystem:(NSString *) system
2432 GLfloat scalar = 1.0;
2435 GLfloat rfactor = scalar;
2441 return ([
self addShipWithRole:desc launchPos:launchPos rfactor:rfactor] !=
nil);
2445- (BOOL) addShips:(
int) howMany withRole:(NSString *) desc atPosition:(HPVector) pos withCoordinateSystem:(NSString *) system
2448 GLfloat scalar = 1.0;
2450 GLfloat distance_from_center = 0.0;
2451 HPVector v_from_center, ship_pos;
2452 HPVector ship_positions[
howMany];
2454 int scale_up_after = 0;
2455 int current_shell = 0;
2456 GLfloat walk_factor = 2.0;
2460 if (ship ==
nil)
return NO;
2466 int limit_count = 8;
2473 v_from_center.x += walk_factor * (
randf() - 0.5);
2474 v_from_center.y += walk_factor * (
randf() - 0.5);
2475 v_from_center.z += walk_factor * (
randf() - 0.5);
2476 }
while ((v_from_center.x == 0.0)&&(v_from_center.y == 0.0)&&(v_from_center.z == 0.0));
2477 v_from_center = HPvector_normal(v_from_center);
2479 ship_pos = make_HPvector( launchPos.x + distance_from_center * v_from_center.x,
2480 launchPos.y + distance_from_center * v_from_center.y,
2481 launchPos.z + distance_from_center * v_from_center.z);
2486 while (safe && (j >= current_shell))
2488 safe = (safe && (HPdistance2(ship_pos, ship_positions[j]) > safe_distance2));
2497 distance_from_center += sqrt(safe_distance2);
2504 [
ship setScanClass:scanClass == CLASS_NOT_SET ? CLASS_NEUTRAL : scanClass];
2512 ship_positions[
i] = ship_pos;
2514 if (i > scale_up_after)
2517 scale_up_after += 1 + 2 * i;
2518 distance_from_center += sqrt(safe_distance2);
2525- (BOOL) addShips:(
int) howMany withRole:(NSString *) desc nearPosition:(HPVector) pos withCoordinateSystem:(NSString *) system
2528 GLfloat scalar = 1.0;
2530 GLfloat rfactor = scalar;
2535 BoundingBox launch_bbox;
2536 bounding_box_reset_to_vector(&launch_bbox, make_vector(launchPos.x - rfactor, launchPos.y - rfactor, launchPos.z - rfactor));
2537 bounding_box_add_xyz(&launch_bbox, launchPos.x + rfactor, launchPos.y + rfactor, launchPos.z + rfactor);
2543- (BOOL) addShips:(
int) howMany withRole:(NSString *) desc nearPosition:(HPVector) pos withCoordinateSystem:(NSString *) system withinRadius:(GLfloat) radius
2546 GLfloat scalar = 1.0;
2548 GLfloat rfactor = radius;
2551 BoundingBox launch_bbox;
2552 bounding_box_reset_to_vector(&launch_bbox, make_vector(launchPos.x - rfactor, launchPos.y - rfactor, launchPos.z - rfactor));
2553 bounding_box_add_xyz(&launch_bbox, launchPos.x + rfactor, launchPos.y + rfactor, launchPos.z + rfactor);
2559- (BOOL) addShips:(
int) howMany withRole:(NSString *) desc intoBoundingBox:(BoundingBox) bbox
2566 int h0 = howMany / 2;
2567 int h1 = howMany - h0;
2569 GLfloat lx = bbox.max.x - bbox.min.x;
2570 GLfloat ly = bbox.max.y - bbox.min.y;
2571 GLfloat lz = bbox.max.z - bbox.min.z;
2572 BoundingBox bbox0 = bbox;
2573 BoundingBox bbox1 = bbox;
2574 if ((lx > lz)&&(lx > ly))
2576 bbox0.min.x += 0.5 * lx;
2577 bbox1.max.x -= 0.5 * lx;
2583 bbox0.min.y += 0.5 * ly;
2584 bbox1.max.y -= 0.5 * ly;
2588 bbox0.min.z += 0.5 * lz;
2589 bbox1.max.z -= 0.5 * lz;
2593 return ([
self addShips: h0 withRole: desc intoBoundingBox: bbox0] && [
self addShips: h1 withRole: desc intoBoundingBox: bbox1]);
2597 HPVector pos = make_HPvector(bbox.min.x, bbox.min.y, bbox.min.z);
2598 pos.x += 0.5 * (
randf() +
randf()) * (bbox.max.x - bbox.min.x);
2599 pos.y += 0.5 * (
randf() +
randf()) * (bbox.max.y - bbox.min.y);
2600 pos.z += 0.5 * (
randf() +
randf()) * (bbox.max.z - bbox.min.z);
2602 return ([
self addShipWithRole:desc launchPos:pos rfactor:0.0] !=
nil);
2606- (BOOL) spawnShip:(NSString *) shipdesc
2610 OOStandardsDeprecated([NSString stringWithFormat:
@"'spawn' via legacy script is deprecated as a way of adding ships for %@",shipdesc]);
2613 NSDictionary *shipdict =
nil;
2616 if (shipdict ==
nil)
return NO;
2620 if (ship ==
nil)
return NO;
2623 NSDictionary *spawndict = [
shipdict oo_dictionaryForKey:@"spawn"];
2624 HPVector pos, rpos, spos;
2625 NSString *positionString =
nil;
2628 positionString = [
spawndict oo_stringForKey:@"position"];
2629 if (positionString !=
nil)
2631 if([positionString hasPrefix:
@"abs "] && ([
self planet] !=
nil || [
self sun] !=
nil))
2633 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);
2642 OOLogERR(
@"universe.spawnShip.error",
@"***** ERROR: failed to find a spawn position for ship %@.", shipdesc);
2647 positionString = [
spawndict oo_stringForKey:@"facing_position"];
2648 if (positionString !=
nil)
2650 if([positionString hasPrefix:
@"abs "] && ([
self planet] !=
nil || [
self sun] !=
nil))
2652 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);
2658 rpos = HPvector_subtract(rpos, spos);
2662 rpos = HPvector_normal(rpos);
2671 q1 = make_quaternion(0,1,0,0);
2686- (void) witchspaceShipWithPrimaryRole:(NSString *)role
2690 NSDictionary *systeminfo =
nil;
2694 government = [
systeminfo oo_unsignedCharForKey:KEY_GOVERNMENT];
2699 if (ship && [ship hasRole:
@"cargopod"])
2706 if (([ship scanClass] == CLASS_NO_DRAW)||([ship scanClass] == CLASS_NOT_SET))
2708 if ([role isEqual:
@"trader"])
2711 if ([ship hasRole:
@"sunskim-trader"] &&
randf() < 0.25)
2721 if (([ship pendingEscortCount] > 0)&&((
Ranrot() % 7) < government))
2724 [
ship setPendingEscortCount:(nx > 0) ? nx : 0];
2727 if ([role isEqual:
@"pirate"])
2730 [
ship setBounty: (Ranrot() & 7) + (Ranrot() & 7) + ((randf() < 0.05)? 63 : 23)
withReason:kOOLegalStatusReasonSetup];
2732 if ([ship crew] ==
nil && ![ship isUnpiloted])
2746 if (entity ==
nil)
return nil;
2773 [
vis setPosition:pos];
2774 [
vis setOrientation:OORandomQuaternion()];
2786- (
ShipEntity *) addShipAt:(HPVector)pos withRole:(NSString *)role withinRadius:(GLfloat)radius
2791 if (radius == NSNotFound)
2793 GLfloat scalar = 1.0;
2796 GLfloat rfactor = scalar;
2818 if (scanClass == CLASS_NOT_SET)
2820 scanClass = CLASS_NEUTRAL;
2824 if ([ship crew] ==
nil && ![ship isUnpiloted])
2833 BOOL trader = [
role isEqualToString:@"trader"];
2843 if (pendingEscortCount > 0)
2846 if ((
Ranrot() % 7) < government)
2848 int nx = pendingEscortCount - 2 * (1 + (
Ranrot() & 3));
2849 [
ship setPendingEscortCount:(nx > 0) ? nx : 0];
2864 if ([ship hasRole:
@"sunskim-trader"] &&
randf() < 0.25)
2874 else if ([role isEqual:
@"pirate"])
2876 [
ship setBounty:(Ranrot() & 7) + (Ranrot() & 7) + ((randf() < 0.05)? 63 : 23)
withReason:kOOLegalStatusReasonSetup];
2893- (NSArray *) addShipsAt:(HPVector)pos withRole:(NSString *)role quantity:(
unsigned)count withinRadius:(GLfloat)radius asGroup:(BOOL)isGroup
2897 NSMutableArray *ships = [
NSMutableArray arrayWithCapacity:count];
2913 [
ships addObject:ship];
2917 if ([ships
count] == 0)
return nil;
2919 return [[
ships copy] autorelease];
2925- (NSArray *) addShipsToRoute:(NSString *)route withRole:(NSString *)role quantity:(
unsigned)count routeFraction:(
double)routeFraction asGroup:(BOOL)isGroup
2927 NSMutableArray *ships = [
NSMutableArray arrayWithCapacity:count];
2933 if ([route isEqualToString:
@"pw"] || [route isEqualToString:
@"sw"] || [route isEqualToString:
@"ps"])
2935 routeFraction = 1.0f - routeFraction;
2939 if ([route isEqualTo:
@"wp"] || [route isEqualTo:
@"pw"])
2943 if (entity ==
nil)
return nil;
2945 radius = [
entity radius];
2947 else if ([route isEqualTo:
@"ws"] || [route isEqualTo:
@"sw"])
2950 entity = [
self sun];
2951 if (entity ==
nil)
return nil;
2953 radius = [
entity radius];
2955 else if ([route isEqualTo:
@"sp"] || [route isEqualTo:
@"ps"])
2957 entity = [
self sun];
2958 if (entity ==
nil)
return nil;
2960 double radius0 = [
entity radius];
2963 if (entity ==
nil)
return nil;
2965 radius = [
entity radius];
2968 direction = HPvector_normal(HPvector_subtract(point0, point1));
2969 point0 = HPvector_subtract(point0, HPvector_multiply_scalar(direction, radius0 +
SCANNER_MAX_RANGE * 1.1f));
2971 else if ([route isEqualTo:
@"st"])
2981 direction = HPvector_normal(HPvector_subtract(point1, point0));
2982 point1 = HPvector_subtract(point1, HPvector_multiply_scalar(direction, radius +
SCANNER_MAX_RANGE * 1.1f));
2994 if (ship !=
nil) [
ships addObject:ship];
2998 if ([ships
count] == 0)
return nil;
3001 return [[
ships copy] autorelease];
3005- (BOOL) roleIsPirateVictim:(NSString *)role
3011- (BOOL) role:(NSString *)role isInCategory:(NSString *)category
3013 NSSet *categoryInfo = [roleCategories objectForKey:category];
3014 if (categoryInfo ==
nil)
3032 if ([my_target isWormhole])
3036 else if ([[[my_ship getAI] state] isEqualToString:
@"ENTER_WORMHOLE"])
3048 if ([
PLAYER status] != STATUS_ENTERING_WITCHSPACE && [
PLAYER status] != STATUS_EXITING_WITCHSPACE)
3061 if ([e2 isShip] && [(
ShipEntity*)e2 hasPrimaryRole:
@"buoy-witchpoint"])
3070- (void) setUpBreakPattern:(HPVector) pos orientation:(Quaternion) q forDocking:(BOOL) forDocking
3089 colorDesc = [[
self globalSettings] objectForKey:@"hyperspace_tunnel_color_1"];
3090 if (colorDesc !=
nil)
3093 if (color !=
nil) col1 = color;
3094 else OOLogWARN(
@"hyperspaceTunnel.fromDict",
@"could not interpret \"%@\
" as a colour.", colorDesc);
3097 colorDesc = [[
self globalSettings] objectForKey:@"hyperspace_tunnel_color_2"];
3098 if (colorDesc !=
nil)
3101 if (color !=
nil) col2 = color;
3102 else OOLogWARN(
@"hyperspaceTunnel.fromDict",
@"could not interpret \"%@\
" as a colour.", colorDesc);
3106 GLfloat startAngle = 0;
3107 GLfloat aspectRatio = 1;
3111 NSDictionary *info = [[PLAYER dockedStation] shipInfoDictionary];
3112 sides = [
info oo_unsignedIntForKey:@"tunnel_corners" defaultValue:4];
3113 startAngle = [
info oo_floatForKey:@"tunnel_start_angle" defaultValue:45.0f];
3114 aspectRatio = [
info oo_floatForKey:@"tunnel_aspect_ratio" defaultValue:2.67f];
3117 for (i = 1; i < 11; i++)
3133 if (forDocking && ![[
PLAYER dockedStation] hasBreakPattern])
3153- (void) setWitchspaceBreakPattern:(BOOL)newValue
3165- (void) setDockingClearanceProtocolActive:(BOOL)newValue
3168 NSEnumerator *statEnum = [allStations objectEnumerator];
3176 while ((
station = [statEnum nextObject]))
3179 if (![[[registry shipInfoForKey:stationKey] allKeys] containsObject:
@"requires_docking_clearance"])
3202- (void) setupIntroFirstGo:(BOOL)justCobra
3206 Quaternion q2 = { 0.0f, 0.0f, 1.0f, 0.0f };
3237 NSArray *subList =
nil;
3240 if ([[[subList oo_dictionaryAtIndex:0] oo_stringForKey:
kOODemoShipClass] isEqualToString:
@"ship"])
3243 NSDictionary *shipEntry =
nil;
3244 foreach (shipEntry, subList)
3246 if ([[shipEntry oo_stringForKey:
kOODemoShipKey] isEqualToString:
@"cobra3-trader"])
3268 [
ship setPositionX:0.0f
y:0.0f
z:DEMO2_VANISHING_DISTANCE * ship->collision_radius * 0.01];
3306 return [[
demo_ships oo_arrayAtIndex:demo_ship_index] oo_dictionaryAtIndex:demo_ship_subindex];
3316 [
gui setTabStops:tab_stops];
3325 NSString *field1 =
nil;
3326 NSString *field2 =
nil;
3327 NSString *field3 =
nil;
3328 NSString *
override =
nil;
3331 for (NSUInteger i=1;i<=26;i++)
3333 [
gui setText:@"" forRow:i];
3337 override = [
librarySettings oo_stringForKey:kOODemoShipClass defaultValue:@"ship"];
3344 override = [
librarySettings oo_stringForKey:kOODemoShipSummary defaultValue:nil];
3345 if (
override !=
nil)
3353 [
gui setArray:[
NSArray arrayWithObjects:field1,field2,field3,nil] forRow:1];
3365 override = [
librarySettings oo_stringForKey:kOODemoShipSpeed defaultValue:nil];
3366 if (
override !=
nil)
3368 if ([
override length] == 0)
3374 field1 = [
NSString stringWithFormat:DESC(@"oolite-ship-library-speed-custom"),OOExpand(override)];
3383 override = [
librarySettings oo_stringForKey:kOODemoShipTurnRate defaultValue:nil];
3384 if (
override !=
nil)
3386 if ([
override length] == 0)
3392 field2 = [
NSString stringWithFormat:DESC(@"oolite-ship-library-turn-custom"),OOExpand(override)];
3401 override = [
librarySettings oo_stringForKey:kOODemoShipCargo defaultValue:nil];
3402 if (
override !=
nil)
3404 if ([
override length] == 0)
3410 field3 = [
NSString stringWithFormat:DESC(@"oolite-ship-library-cargo-custom"),OOExpand(override)];
3419 [
gui setArray:[
NSArray arrayWithObjects:field1,field2,field3,nil] forRow:3];
3422 override = [
librarySettings oo_stringForKey:kOODemoShipGenerator defaultValue:nil];
3423 if (
override !=
nil)
3425 if ([
override length] == 0)
3431 field1 = [
NSString stringWithFormat:DESC(@"oolite-ship-library-generator-custom"),OOExpand(override)];
3440 override = [
librarySettings oo_stringForKey:kOODemoShipShields defaultValue:nil];
3441 if (
override !=
nil)
3443 if ([
override length] == 0)
3449 field2 = [
NSString stringWithFormat:DESC(@"oolite-ship-library-shields-custom"),OOExpand(override)];
3458 override = [
librarySettings oo_stringForKey:kOODemoShipWitchspace defaultValue:nil];
3459 if (
override !=
nil)
3461 if ([
override length] == 0)
3467 field3 = [
NSString stringWithFormat:DESC(@"oolite-ship-library-witchspace-custom"),OOExpand(override)];
3476 [
gui setArray:[
NSArray arrayWithObjects:field1,field2,field3,nil] forRow:4];
3480 override = [
librarySettings oo_stringForKey:kOODemoShipWeapons defaultValue:nil];
3481 if (
override !=
nil)
3483 if ([
override length] == 0)
3489 field1 = [
NSString stringWithFormat:DESC(@"oolite-ship-library-weapons-custom"),OOExpand(override)];
3497 override = [
librarySettings oo_stringForKey:kOODemoShipTurrets defaultValue:nil];
3498 if (
override !=
nil)
3500 if ([
override length] == 0)
3506 field2 = [
NSString stringWithFormat:DESC(@"oolite-ship-library-turrets-custom"),OOExpand(override)];
3514 override = [
librarySettings oo_stringForKey:kOODemoShipSize defaultValue:nil];
3515 if (
override !=
nil)
3517 if ([
override length] == 0)
3523 field3 = [
NSString stringWithFormat:DESC(@"oolite-ship-library-size-custom"),OOExpand(override)];
3531 [
gui setArray:[
NSArray arrayWithObjects:field1,field2,field3,nil] forRow:5];
3534 override = [
librarySettings oo_stringForKey:kOODemoShipDescription defaultValue:nil];
3535 if (
override !=
nil)
3537 [
gui addLongText:OOExpand(override) startingAtRow:descRow align:GUI_ALIGN_LEFT];
3542 field1 = [
NSString stringWithFormat:@"<-- %@",OOShipLibraryCategoryPlural([[[
demo_ships objectAtIndex:((demo_ship_index+[
demo_ships count]-1)%[
demo_ships count])] objectAtIndex:0] oo_stringForKey:kOODemoShipClass])];
3544 field3 = [
NSString stringWithFormat:@"%@ -->",OOShipLibraryCategoryPlural([[[
demo_ships objectAtIndex:((demo_ship_index+1)%[
demo_ships count])] objectAtIndex:0] oo_stringForKey:kOODemoShipClass])];
3546 [
gui setArray:[
NSArray arrayWithObjects:field1,field2,field3,nil] forRow:19];
3550 NSArray *subList = [
demo_ships objectAtIndex:demo_ship_index];
3551 NSUInteger i,start = demo_ship_subindex - (demo_ship_subindex%5);
3552 NSUInteger end = start + 4;
3553 if (end >= [subList
count])
3560 for (i = start ; i <= end ; i++)
3562 field2 = [[
subList objectAtIndex:i] oo_stringForKey:kOODemoShipName];
3563 [
gui setArray:[
NSArray arrayWithObjects:field1,field2,field3,nil] forRow:row];
3564 if (i == demo_ship_subindex)
3578 [
gui setArray:[
NSArray arrayWithObjects:field1,field2,field3,nil] forRow:20];
3581 if (end < [subList
count]-1)
3583 [
gui setArray:[
NSArray arrayWithObjects:field1,field2,field3,nil] forRow:26];
3593 NSUInteger subcount = [[demo_ships objectAtIndex:demo_ship_index] count];
3647- (
StationEntity *) stationWithRole:(NSString *)role andPosition:(HPVector)position
3649 if ([role isEqualToString:
@""])
3654 float range = 1000000;
3660 if (HPdistance2(position,[
station position]) < range)
3662 if ([[
station primaryRole] isEqualToString:role])
3708 return [allStations allObjects];
3730 if (playerStatus == STATUS_START_GAME)
return;
3740 Entity <OOBeaconEntity> *beaconShip = [
self firstBeacon], *next =
nil;
3760- (void) setFirstBeacon:(
Entity <OOBeaconEntity> *)beacon
3762 if (beacon != [
self firstBeacon])
3764 [
beacon setPrevBeacon:nil];
3768 _firstBeacon = [
beacon weakRetain];
3779- (void) setLastBeacon:(
Entity <OOBeaconEntity> *)beacon
3781 if (beacon != [
self lastBeacon])
3783 [
beacon setNextBeacon:nil];
3787 _lastBeacon = [
beacon weakRetain];
3792- (void) setNextBeacon:(
Entity <OOBeaconEntity> *) beaconShip
3794 if ([beaconShip isBeacon])
3801 OOLog(
@"universe.beacon.error",
@"***** ERROR: Universe setNextBeacon '%@'. The ship has no beacon code set.", beaconShip);
3806- (void) clearBeacon:(
Entity <OOBeaconEntity> *) beaconShip
3808 Entity <OOBeaconEntity> *tmp =
nil;
3810 if ([beaconShip isBeacon])
3840- (void) defineWaypoint:(NSDictionary *)definition forKey:(NSString *)key
3843 BOOL preserveCompass = NO;
3844 waypoint = [waypoints objectForKey:key];
3845 if (waypoint !=
nil)
3847 if ([
PLAYER compassTarget] == waypoint)
3849 preserveCompass = YES;
3852 [waypoints removeObjectForKey:key];
3854 if (definition !=
nil)
3857 if (waypoint !=
nil)
3860 [waypoints setObject:waypoint forKey:key];
3861 if (preserveCompass)
3863 [PLAYER setCompassTarget:waypoint];
3864 [PLAYER setNextBeacon:waypoint];
3877- (void) setSkyColorRed:(GLfloat)red green:(GLfloat)green blue:(GLfloat)blue alpha:(GLfloat)alpha
3900#define PROFILE_SHIP_SELECTION 0
3903- (BOOL) canInstantiateShip:(NSString *)shipKey
3905 NSDictionary *shipInfo =
nil;
3906 NSArray *conditions =
nil;
3907 NSString *condition_script =
nil;
3910 condition_script = [
shipInfo oo_stringForKey:@"condition_script"];
3911 if (condition_script !=
nil)
3914 if (condScript !=
nil)
3918 JSBool allow_instantiation;
3927 if (OK) OK = JS_ValueToBoolean(context, result, &allow_instantiation);
3931 if (OK && !allow_instantiation)
3941 conditions = [
shipInfo oo_arrayForKey:@"conditions"];
3942 if (conditions ==
nil)
return YES;
3945 return [PLAYER scriptTestConditions:conditions];
3949- (NSString *) randomShipKeyForRoleRespectingConditions:(NSString *)role
3954 NSString *shipKey =
nil;
3957#if PROFILE_SHIP_SELECTION
3958 static unsigned long profTotal = 0, profSlowPath = 0;
3964 if ([
self canInstantiateShip:shipKey])
return shipKey;
3973#if PROFILE_SHIP_SELECTION
3975 if ((profSlowPath % 10) == 0)
3977 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);
3983 while ([pset
count] > 0)
3987 if ([
self canInstantiateShip:shipKey])
return shipKey;
4005 NSString *shipKey =
nil;
4006 NSDictionary *shipInfo =
nil;
4007 NSString *autoAI =
nil;
4018 if ([shipInfo oo_fuzzyBooleanForKey:
@"auto_ai" defaultValue:YES])
4027 if ([role isEqualToString:
@"pirate"]) [
ship setBounty:20 + randf() * 50
withReason:kOOLegalStatusReasonSetup];
4030 if ([role isEqualToString:
@"interceptor"])
4036 if ([role isEqualToString:
@"thargoid"]) [
ship setScanClass: CLASS_THARGOID];
4051 NSDictionary *effectDict =
nil;
4055 if (effectDict ==
nil)
return nil;
4061 @catch (NSException *exception)
4065 OOLog(
kOOLogException,
@"***** Oolite Exception : '%@' in [Universe newVisualEffectWithName: %@ ] *****", [exception reason], effectKey);
4067 else @throw exception;
4076- (
ShipEntity *) newSubentityWithName:(NSString *)shipKey andScaleFactor:(
float)scale
4082- (
ShipEntity *) newShipWithName:(NSString *)shipKey usePlayerProxy:(BOOL)usePlayerProxy
4087- (
ShipEntity *) newShipWithName:(NSString *)shipKey usePlayerProxy:(BOOL)usePlayerProxy isSubentity:(BOOL)isSubentity
4092- (
ShipEntity *) newShipWithName:(NSString *)shipKey usePlayerProxy:(BOOL)usePlayerProxy isSubentity:(BOOL)isSubentity andScaleFactor:(
float)scale
4096 NSDictionary *shipDict =
nil;
4100 if (shipDict ==
nil)
return nil;
4102 volatile Class shipClass =
nil;
4110 if (usePlayerProxy && shipClass == [
ShipEntity class])
4120 NSMutableDictionary *mShipDict = [
shipDict mutableCopy];
4121 [
mShipDict setObject:[
NSNumber numberWithFloat:scale] forKey:@"model_scale_factor"];
4122 shipDict = [
NSDictionary dictionaryWithDictionary:mShipDict];
4125 ship = [[
shipClass alloc] initWithKey:shipKey definition:shipDict];
4127 @catch (NSException *exception)
4131 OOLog(
kOOLogException,
@"***** Oolite Exception : '%@' in [Universe newShipWithName: %@ ] *****", [exception reason], shipKey);
4133 else @throw exception;
4146- (
DockEntity *) newDockWithName:(NSString *)shipDataKey andScaleFactor:(
float)scale
4150 NSDictionary *shipDict =
nil;
4154 if (shipDict ==
nil)
return nil;
4160 NSMutableDictionary *mShipDict = [
shipDict mutableCopy];
4161 [
mShipDict setObject:[
NSNumber numberWithFloat:scale] forKey:@"model_scale_factor"];
4162 shipDict = [
NSDictionary dictionaryWithDictionary:mShipDict];
4165 dock = [[
DockEntity alloc] initWithKey:shipDataKey definition:shipDict];
4167 @catch (NSException *exception)
4171 OOLog(
kOOLogException,
@"***** Oolite Exception : '%@' in [Universe newDockWithName: %@ ] *****", [exception reason], shipDataKey);
4173 else @throw exception;
4192- (Class) shipClassForShipDictionary:(NSDictionary *)dict
4196 if (dict ==
nil)
return Nil;
4198 BOOL isStation = NO;
4199 NSString *shipRoles = [
dict oo_stringForKey:@"roles"];
4201 if (shipRoles !=
nil)
4203 isStation = [
shipRoles rangeOfString:@"station"].location != NSNotFound ||
4204 [
shipRoles rangeOfString:@"carrier"].location != NSNotFound;
4208 isStation = [
dict oo_boolForKey:@"isCarrier" defaultValue:isStation];
4209 isStation = [
dict oo_boolForKey:@"is_carrier" defaultValue:isStation];
4218- (NSString *)defaultAIForRole:(NSString *)role
4220 return [autoAIMap oo_stringForKey:role];
4237 NSString *itemType = [
itemData oo_stringAtIndex:EQUIPMENT_KEY_INDEX];
4239 if ([itemType isEqual:eq_key])
4241 return [
itemData oo_unsignedLongLongAtIndex:EQUIPMENT_PRICE_INDEX];
4257 if ([cargoObj isTemplateCargoPod])
4259 return [UNIVERSE cargoPodFromTemplate:cargoObj];
4273 OOCargoQuantity co_amount = [UNIVERSE getRandomAmountOfCommodity:co_type];
4276 container = [UNIVERSE newShipWithRole:co_type];
4278 if (container ==
nil)
4280 container = [UNIVERSE newShipWithRole:@"cargopod"];
4287- (NSArray *) getContainersOfGoods:(
OOCargoQuantity)how_many scarce:(BOOL)scarce legal:(BOOL)legal
4293 NSMutableArray *accumulator = [
NSMutableArray arrayWithCapacity:how_many];
4299 NSString *goodsKey =
nil;
4301 foreach (goodsKey, goodsKeys)
4306 if (q < 64) q = 64 - q;
4317 quantities[
i++] = q;
4318 total_quantity += q;
4321 for (i = 0; i < how_many; i++)
4323 NSUInteger co_type = 0;
4328 qr = 1+(
Ranrot() % total_quantity);
4332 NSAssert((NSUInteger)co_type < commodityCount,
@"Commodity type index out of range.");
4340 if (container !=
nil)
4346 OOLog(
@"universe.createContainer.failed",
@"***** ERROR: failed to find a container to fill with %@ (%ld).", [goodsKeys oo_stringAtIndex:co_type], co_type);
4350 return [
NSArray arrayWithArray:accumulator];
4356 NSMutableArray *accumulator = [
NSMutableArray arrayWithCapacity:how_much];
4362 ShipEntity *container = [cargoPods objectForKey:commodity_name];
4363 while (how_much > 0)
4371 OOLog(
@"universe.createContainer.failed",
@"***** ERROR: failed to find a container to fill with %@", commodity_name);
4376 return [
NSArray arrayWithArray:accumulator];
4382 if (cargopod ==
nil || ![cargopod hasRole:
@"cargopod"] || [cargopod cargoType] ==
CARGO_SCRIPTED_ITEM)
return;
4384 if ([cargopod commodityType] ==
nil || ![cargopod commodityAmount])
4403 if (co_type ==
nil) {
4417 OOLog(
@"universe.commodityAmount.warning",
@"Commodity %@ has an unrecognised mass unit, assuming tonnes",co_type);
4437 NSString *unitDesc =
nil, *typeDesc =
nil;
4440 if (commodity ==
nil)
return @"";
4448 unitDesc =
DESC(
@"cargo-kilogram");
4451 unitDesc =
DESC(
@"cargo-gram");
4455 unitDesc =
DESC(
@"cargo-ton");
4464 unitDesc =
DESC(
@"cargo-kilograms");
4467 unitDesc =
DESC(
@"cargo-grams");
4471 unitDesc =
DESC(
@"cargo-tons");
4478 return [
NSString stringWithFormat:@"%d %@ %@",co_amount, unitDesc, typeDesc];
4510 [
result oo_setInteger:[PLAYER isSpeechOn] forKey:@"speechOn"];
4511 [
result oo_setBool:autoSave forKey:@"autosave"];
4512 [
result oo_setBool:wireframeGraphics forKey:@"wireframeGraphics"];
4513 [
result oo_setBool:doProcedurallyTexturedPlanets forKey:@"procedurallyTexturedPlanets"];
4523 [
result oo_setFloat:[
gameView hdrMaxBrightness] forKey:@"hdr-max-brightness"];
4524 [
result oo_setFloat:[
gameView hdrPaperWhiteBrightness] forKey:@"hdr-paperwhite-brightness"];
4525 [
result setObject:OOStringFromHDRToneMapper([
gameView hdrToneMapper]) forKey:@"hdr-tone-mapper"];
4531 [
result setObject:OOStringFromGraphicsDetail([
self detailLevel]) forKey:@"detailLevel"];
4533 NSString *desc =
@"UNDEFINED";
4540 [
result setObject:desc forKey:@"musicMode"];
4542 NSDictionary *gameWindow = [
NSDictionary dictionaryWithObjectsAndKeys:
4547 [
result setObject:gameWindow forKey:@"gameWindow"];
4549 [
result setObject:[PLAYER keyConfig] forKey:@"keyConfig"];
4551 return [[
result copy] autorelease];
4555- (void) useGUILightSource:(BOOL)GUILight
4563 OOGL(glEnable(GL_LIGHT0));
4564 OOGL(glDisable(GL_LIGHT1));
4568 OOGL(glEnable(GL_LIGHT1));
4569 OOGL(glDisable(GL_LIGHT0));
4578 else OOGL(glEnable(GL_LIGHT1));
4585- (void) lightForEntity:(BOOL)isLit
4606 if (isLit)
OOGL(glEnable(GL_LIGHT1));
4607 else OOGL(glDisable(GL_LIGHT1));
4612 OOGL(glEnable(GL_LIGHT0));
4628 { 1.0f, 0.0f, 0.0f, 0.0f },
4629 { 0.0f, 1.0f, 0.0f, 0.0f },
4630 { 0.0f, 0.0f, 1.0f, 0.0f },
4631 { 0.0f, 0.0f, 0.0f, 1.0f }
4635 {-1.0f, 0.0f, 0.0f, 0.0f },
4636 { 0.0f, 1.0f, 0.0f, 0.0f },
4637 { 0.0f, 0.0f, -1.0f, 0.0f },
4638 { 0.0f, 0.0f, 0.0f, 1.0f }
4642 { 0.0f, 0.0f, -1.0f, 0.0f },
4643 { 0.0f, 1.0f, 0.0f, 0.0f },
4644 { 1.0f, 0.0f, 0.0f, 0.0f },
4645 { 0.0f, 0.0f, 0.0f, 1.0f }
4649 { 0.0f, 0.0f, 1.0f, 0.0f },
4650 { 0.0f, 1.0f, 0.0f, 0.0f },
4651 {-1.0f, 0.0f, 0.0f, 0.0f },
4652 { 0.0f, 0.0f, 0.0f, 1.0f }
4656- (void) getActiveViewMatrix:(OOMatrix *)outMatrix forwardVector:(Vector *)outForward upVector:(Vector *)outUp
4658 assert(outMatrix != NULL && outForward != NULL && outUp != NULL);
4676 case VIEW_STARBOARD:
4691 case VIEW_GUI_DISPLAY:
4692 case VIEW_BREAK_PATTERN:
4725 frustum[0][0] = clip.m[0][3] - clip.m[0][0];
4726 frustum[0][1] = clip.m[1][3] - clip.m[1][0];
4727 frustum[0][2] = clip.m[2][3] - clip.m[2][0];
4728 frustum[0][3] = clip.m[3][3] - clip.m[3][0];
4738 frustum[1][0] = clip.m[0][3] + clip.m[0][0];
4739 frustum[1][1] = clip.m[1][3] + clip.m[1][0];
4740 frustum[1][2] = clip.m[2][3] + clip.m[2][0];
4741 frustum[1][3] = clip.m[3][3] + clip.m[3][0];
4751 frustum[2][0] = clip.m[0][3] + clip.m[0][1];
4752 frustum[2][1] = clip.m[1][3] + clip.m[1][1];
4753 frustum[2][2] = clip.m[2][3] + clip.m[2][1];
4754 frustum[2][3] = clip.m[3][3] + clip.m[3][1];
4764 frustum[3][0] = clip.m[0][3] - clip.m[0][1];
4765 frustum[3][1] = clip.m[1][3] - clip.m[1][1];
4766 frustum[3][2] = clip.m[2][3] - clip.m[2][1];
4767 frustum[3][3] = clip.m[3][3] - clip.m[3][1];
4777 frustum[4][0] = clip.m[0][3] - clip.m[0][2];
4778 frustum[4][1] = clip.m[1][3] - clip.m[1][2];
4779 frustum[4][2] = clip.m[2][3] - clip.m[2][2];
4780 frustum[4][3] = clip.m[3][3] - clip.m[3][2];
4790 frustum[5][0] = clip.m[0][3] + clip.m[0][2];
4791 frustum[5][1] = clip.m[1][3] + clip.m[1][2];
4792 frustum[5][2] = clip.m[2][3] + clip.m[2][2];
4793 frustum[5][3] = clip.m[3][3] + clip.m[3][2];
4804- (BOOL) viewFrustumIntersectsSphereAt:(Vector)position withRadius:(GLfloat)radius
4808 for (p = 0; p < 6; p++)
4824 OOLog(
@"universe.profile.draw",
@"%@",
@"Begin draw");
4848 int i, v_status, vdist;
4849 Vector view_dir, view_up;
4850 OOMatrix view_matrix;
4858 float aspect = viewSize.height/viewSize.width;
4864 else [UNIVERSE setMainLightPosition:kZeroVector];
4868 for (i = 0; i < ent_count; i++)
4878 my_entities[
draw_count++] = [[
e retain] autorelease];
4888 OOGL(glClear(GL_COLOR_BUFFER_BIT));
4896 OOGL(glClearColor(0.0, 0.0, 0.0, 0.0));
4906 for (vdist=0;vdist<=1;vdist++)
4915 OOGLFrustum(-ratio, ratio, -aspect*ratio, aspect*ratio, nearPlane, farPlane);
4919 OOGLFrustum(-3*ratio/aspect/4, 3*ratio/aspect/4, -3*ratio/4, 3*ratio/4, nearPlane, farPlane);
4954 OOGL(glClear(GL_DEPTH_BUFFER_BIT));
4959 flipMatrix.m[2][2] = -1;
4967 if (
EXPECT(!demoShipMode))
4996 OOGL([
self useGUILightSource:demoShipMode]);
5001 int furthest = draw_count - 1;
5005 double fog_scale, half_scale;
5006 GLfloat flat_ambdiff[4] = {1.0, 1.0, 1.0, 1.0};
5007 GLfloat mat_no[4] = {0.0, 0.0, 0.0, 1.0};
5016 OOLog(
@"universe.profile.draw",
@"%@",
@"Begin opaque pass");
5020 for (i = furthest; i >= nearest; i--)
5022 drawthing = my_entities[
i];
5026 if (vdist == 1 && [drawthing cameraRangeFront] > farPlane*1.5)
continue;
5027 if (vdist == 0 && [drawthing cameraRangeBack] < nearPlane)
continue;
5030 if (!((d_status == STATUS_COCKPIT_DISPLAY) ^ demoShipMode))
5034 OOGL(glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, flat_ambdiff));
5035 OOGL(glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, mat_no));
5038 if (
EXPECT(drawthing != player))
5061 half_scale = fog_scale * 0.50;
5062 OOGL(glEnable(GL_FOG));
5063 OOGL(glFogi(GL_FOG_MODE, GL_LINEAR));
5065 OOGL(glFogf(GL_FOG_START, half_scale));
5066 OOGL(glFogf(GL_FOG_END, fog_scale));
5067 fog_blend = OOClamp_0_1_f((magnitude([drawthing cameraRelativePosition]) - half_scale)/half_scale);
5082 OOGL(glDisable(GL_FOG));
5087 if (!((d_status == STATUS_COCKPIT_DISPLAY) ^ demoShipMode))
5090 if (
EXPECT(drawthing != player))
5113 half_scale = fog_scale * 0.50;
5114 OOGL(glEnable(GL_FOG));
5115 OOGL(glFogi(GL_FOG_MODE, GL_LINEAR));
5117 OOGL(glFogf(GL_FOG_START, half_scale));
5118 OOGL(glFogf(GL_FOG_END, fog_scale));
5119 fog_blend = OOClamp_0_1_f((magnitude([drawthing cameraRelativePosition]) - half_scale)/half_scale);
5130 OOGL(glDisable(GL_FOG));
5155 if (hudSeparateRenderPass)
5163 OOLog(
@"universe.profile.secondPassDraw",
@"%@",
@"Begin second pass draw");
5165 OOCheckOpenGLErrors(
@"Universe after drawing from custom framebuffer to screen framebuffer");
5166 OOLog(
@"universe.profile.secondPassDraw",
@"%@",
@"End second pass drawing");
5168 OOLog(
@"universe.profile.drawHUD",
@"%@",
@"Begin HUD drawing");
5173 OOLog(
@"universe.profile.draw",
@"%@",
@"Begin HUD");
5176 if (lineWidth < 1.0) lineWidth = 1.0;
5177 if (lineWidth > 1.5) lineWidth = 1.5;
5184 if ([theHUD deferredHudName] !=
nil)
5193 static float sPrevHudAlpha = -1.0f;
5194 if ([theHUD isHidden])
5196 if (sPrevHudAlpha < 0.0f)
5202 else if (sPrevHudAlpha >= 0.0f)
5205 sPrevHudAlpha = -1.0f;
5210 case STATUS_ESCAPE_SEQUENCE:
5211 case STATUS_START_GAME:
5215 switch ([player guiScreen])
5229#if (defined (SNAPSHOT_BUILD) && defined (OOLITE_SNAPSHOT_VERSION))
5233 OOLog(
@"universe.profile.drawHUD",
@"%@",
@"End HUD drawing");
5247 @catch (NSException *exception)
5251 if ([[exception name] hasPrefix:
@"Oolite"])
5257 OOLog(
kOOLogException,
@"***** Exception: %@ : %@ *****",[exception name], [exception reason]);
5263 OOLog(
@"universe.profile.draw",
@"%@",
@"End drawing");
5266 if(!hudSeparateRenderPass)
5273 OOLog(
@"universe.profile.secondPassDraw",
@"%@",
@"Begin second pass draw");
5275 OOLog(
@"universe.profile.secondPassDraw",
@"%@",
@"End second pass drawing");
5283 NSSize viewSize = [
gameView viewSize];
5284 if([
self useShaders])
5286 if ([gameView msaa])
5289 OOGL(glBindFramebuffer(GL_READ_FRAMEBUFFER, msaaFramebufferID));
5290 OOGL(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, targetFramebufferID));
5291 OOGL(glBlitFramebuffer(0, 0, (GLint)viewSize.width, (GLint)viewSize.height, 0, 0, (GLint)viewSize.width, (GLint)viewSize.height, GL_COLOR_BUFFER_BIT, GL_NEAREST));
5319 OOGL(glDisable(GL_TEXTURE_2D));
5321 float overallAlpha = [[PLAYER hud] overallAlpha];
5341- (void) drawWatermarkString:(NSString *) watermarkString
5343 NSSize watermarkStringSize =
OORectFromString(watermarkString, 0.0f, 0.0f, NSMakeSize(10, 10)).size;
5345 OOGL(glColor4f(0.0, 1.0, 0.0, 1.0));
5359 OOLog(
@"universe.badUID",
@"Attempt to retrieve entity for out-of-range UID %u. (This is an internal programming error, please report it.)", u_id);
5372 if ([ent status] == STATUS_DEAD || [ent status] == STATUS_DOCKED)
5383 NSCParameterAssert(uni != NULL);
5396 while ((n--)&&(checkEnt))
5399 checkEnt = checkEnt->
x_next;
5401 if ((checkEnt)||(n > 0))
5409 while ((n--)&&(checkEnt)) checkEnt = checkEnt->
x_previous;
5410 if ((checkEnt)||(n > 0))
5421 checkEnt = checkEnt->
x_next;
5429 while ((n--)&&(checkEnt))
5432 checkEnt = checkEnt->
y_next;
5434 if ((checkEnt)||(n > 0))
5442 while ((n--)&&(checkEnt)) checkEnt = checkEnt->
y_previous;
5443 if ((checkEnt)||(n > 0))
5454 checkEnt = checkEnt->
y_next;
5462 while ((n--)&&(checkEnt))
5465 checkEnt = checkEnt->
z_next;
5467 if ((checkEnt)||(n > 0))
5475 while ((n--)&&(checkEnt)) checkEnt = checkEnt->
z_previous;
5476 if ((checkEnt)||(n > 0))
5483 NSCAssert(checkEnt !=
nil,
@"Expected z-list to be non-empty.");
5488 checkEnt = checkEnt->
z_next;
5498 NSArray *allEntities = uni->
entities;
5504 foreach (ent, allEntities)
5528 if (![entity validForAddToUniverse])
return NO;
5531 if ([
entities containsObject:entity])
5544 if (![entity isEffect])
5557 OOLog(
@"universe.addEntity.failed",
@"***** Universe cannot addEntity:%@ -- Could not find free slot for entity.", entity);
5561 [
entity setUniversalID:next_universal_id];
5563 if ([entity isShip])
5575 double stationRoll = 0.0;
5579 if (definedRoll !=
nil)
5585 stationRoll = [[
self currentSystemData] oo_doubleForKey:@"station_roll" defaultValue:STANDARD_STATION_ROLL];
5598 if ([se status] != STATUS_COCKPIT_DISPLAY)
5606 [
entity setUniversalID:NO_TARGET];
5607 if ([entity isVisualEffect])
5615 else if ([entity isWaypoint])
5626 entity->isSunlit = YES;
5630 [entities addObject:entity];
5631 [
entity wasAddedToUniverse];
5634 HPVector entity_pos = entity->position;
5635 HPVector delta = HPvector_between(entity_pos,
PLAYER->position);
5636 double z_distance = HPmagnitude2(delta);
5637 entity->zero_distance = z_distance;
5640 entity->zero_index = index;
5641 while ((index > 0)&&(z_distance <
sortedEntities[index - 1]->zero_distance))
5647 entity->zero_index = index;
5654 [
entity addToLinkedLists];
5655 if ([entity canCollide])
5660 if ([entity isWormhole])
5662 [activeWormholes addObject:entity];
5664 else if ([entity isPlanet])
5666 [allPlanets addObject:entity];
5668 else if ([entity isShip])
5672 if ([entity isStation])
5674 [allStations addObject:entity];
5686 if (entity !=
nil && ![entity isPlayer])
5692 [entitiesDeadThisUpdate addObject:entity];
5693 if ([entity isStation])
5695 [allStations removeObject:entity];
5696 if ([
PLAYER getTargetDockStation] == entity)
5698 [PLAYER setDockingClearanceStatus:DOCKING_CLEARANCE_STATUS_NONE];
5707- (void) ensureEntityReallyRemoved:(
Entity *)entity
5711 OOLog(
@"universe.unremovedEntity",
@"Entity %@ dealloced without being removed from universe! (This is an internal programming error, please report it.)", entity);
5723 Entity* p0 = [entities objectAtIndex:0];
5732 NSMutableArray *savedWormholes = [activeWormholes mutableCopy];
5736 Entity* ent = [entities objectAtIndex:1];
5739 if (
EXPECT(![ent isVisualEffect]))
5750 [activeWormholes release];
5759 [closeSystems release];
5763 [waypoints removeAllObjects];
5776 for (i = 0; i < ent_count; i++)
5779 if ([ent status] == STATUS_COCKPIT_DISPLAY && ![ent isPlayer])
5789- (
ShipEntity *) makeDemoShipWithRole:(NSString *)role spinning:(BOOL)spinning
5795 [PLAYER setShowDemoShips: YES];
5796 Quaternion q2 = { (GLfloat)
M_SQRT1_2, (GLfloat)
M_SQRT1_2, (GLfloat)0.0, (GLfloat)0.0 };
5808 [UNIVERSE addEntity:ship];
5825 return [
ship autorelease];
5829- (BOOL) isVectorClearFromEntity:(
Entity *) e1 toDistance:(
double)dist fromPoint:(HPVector) p2
5837 v1.x -= p1.x; v1.y -= p1.y; v1.z -= p1.z;
5839 double nearest = sqrt(v1.x*v1.x + v1.y*v1.y + v1.z*v1.z) - dist;
5847 for (i = 0; i < ent_count; i++)
5850 if (v1.x || v1.y || v1.z)
5851 f1 = HPvector_normal(v1);
5853 f1 = make_HPvector(0, 0, 1);
5855 for (i = 0; i < ent_count ; i++)
5858 if ((e2 != e1)&&([e2 canCollide]))
5861 epos.x -= p1.x; epos.y -= p1.y; epos.z -= p1.z;
5863 double d_forward = HPdot_product(epos,f1);
5865 if ((d_forward > 0)&&(d_forward < nearest))
5869 p0.x += d_forward * f1.x; p0.y += d_forward * f1.y; p0.z += d_forward * f1.z;
5872 p0.x -= epos.x; p0.y -= epos.y; p0.z -= epos.z;
5874 double dist2 = p0.x * p0.x + p0.y * p0.y + p0.z * p0.z;
5877 for (i = 0; i < ent_count; i++)
5878 [my_entities[i] release];
5884 for (i = 0; i < ent_count; i++)
5885 [my_entities[i] release];
5890- (
Entity*) hazardOnRouteFromEntity:(
Entity *) e1 toDistance:(
double)dist fromPoint:(HPVector) p2
5898 v1.x -= p1.x; v1.y -= p1.y; v1.z -= p1.z;
5900 double nearest = HPmagnitude(v1) - dist;
5909 for (i = 0; i < ent_count; i++)
5912 if (v1.x || v1.y || v1.z)
5913 f1 = HPvector_normal(v1);
5915 f1 = make_HPvector(0, 0, 1);
5917 for (i = 0; (i < ent_count) && (!result) ; i++)
5920 if ((e2 != e1)&&([e2 canCollide]))
5923 epos.x -= p1.x; epos.y -= p1.y; epos.z -= p1.z;
5925 double d_forward = HPdot_product(epos,f1);
5927 if ((d_forward > 0)&&(d_forward < nearest))
5931 p0.x += d_forward * f1.x; p0.y += d_forward * f1.y; p0.z += d_forward * f1.z;
5934 p0.x -= epos.x; p0.y -= epos.y; p0.z -= epos.z;
5936 double dist2 = HPmagnitude2(p0);
5942 for (i = 0; i < ent_count; i++)
5943 [my_entities[i] release];
5948- (HPVector) getSafeVectorFromEntity:(
Entity *) e1 toDistance:(
double)dist fromPoint:(HPVector) p2
5959 HPVector result = p2;
5963 for (i = 0; i < ent_count; i++)
5967 v1.x -= p1.x; v1.y -= p1.y; v1.z -= p1.z;
5969 double nearest = sqrt(v1.x*v1.x + v1.y*v1.y + v1.z*v1.z) - dist;
5971 if (v1.x || v1.y || v1.z)
5972 f1 = HPvector_normal(v1);
5974 f1 = make_HPvector(0, 0, 1);
5976 for (i = 0; i < ent_count; i++)
5979 if ((e2 != e1)&&([e2 canCollide]))
5982 epos.x -= p1.x; epos.y -= p1.y; epos.z -= p1.z;
5983 double d_forward = HPdot_product(epos,f1);
5984 if ((d_forward > 0)&&(d_forward < nearest))
5989 p0.x += d_forward * f1.x; p0.y += d_forward * f1.y; p0.z += d_forward * f1.z;
5993 p0.x -= epos.x; p0.y -= epos.y; p0.z -= epos.z;
5996 double dist2 = p0.x * p0.x + p0.y * p0.y + p0.z * p0.z;
6001 nearest = d_forward;
6007 result.x += ((
int)(
Ranrot() % 1024) - 512)/512.0;
6008 result.y += ((
int)(
Ranrot() % 1024) - 512)/512.0;
6009 result.z += ((
int)(
Ranrot() % 1024) - 512)/512.0;
6012 HPVector nearest_point = p1;
6013 nearest_point.x += d_forward * f1.x; nearest_point.y += d_forward * f1.y; nearest_point.z += d_forward * f1.z;
6016 HPVector outward = nearest_point;
6017 outward.x -= result.x; outward.y -= result.y; outward.z -= result.z;
6018 if (outward.x||outward.y||outward.z)
6019 outward = HPvector_normal(outward);
6024 HPVector backward = p1;
6025 backward.x -= result.x; backward.y -= result.y; backward.z -= result.z;
6026 if (backward.x||backward.y||backward.z)
6027 backward = HPvector_normal(backward);
6032 HPVector dd = result;
6033 dd.x -= p1.x; dd.y -= p1.y; dd.z -= p1.z;
6034 double current_distance = HPmagnitude(dd);
6037 if (current_distance < cr * 1.25)
6038 current_distance = cr * 1.25;
6039 if (current_distance > cr * 5.0)
6040 current_distance = cr * 5.0;
6044 result.x += 0.25 * (outward.x * current_distance) + 0.75 * (backward.x * current_distance);
6045 result.y += 0.25 * (outward.y * current_distance) + 0.75 * (backward.y * current_distance);
6046 result.z += 0.25 * (outward.z * current_distance) + 0.75 * (backward.z * current_distance);
6052 for (i = 0; i < ent_count; i++)
6053 [my_entities[i] release];
6058- (
ShipEntity*) addWreckageFrom:(
ShipEntity *)ship withRole:(NSString *)wreckRole at:(HPVector)rpos scale:(GLfloat)scale lifetime:(GLfloat)lifetime
6060 ShipEntity* wreck = [UNIVERSE newShipWithRole:wreckRole];
6064 GLfloat expected_mass = 0.1f * [
ship mass] * (0.75 + 0.5 *
randf());
6066 GLfloat scale_factor = powf(expected_mass / wreck_mass, 0.33333333f) * scale;
6082 [UNIVERSE addEntity:wreck];
6092- (void) addLaserHitEffectsAt:(HPVector)pos against:(
ShipEntity *)target damage:(
float)damage color:(
OOColor *)color
6095 if ([target showDamage] && [target energy] < [target maxEnergy]/2)
6097 NSString *key = (
randf() < 0.5) ?
@"oolite-hull-spark" :
@"oolite-hull-spark-b";
6098 NSDictionary *settings = [UNIVERSE explosionSetting:key];
6102 if ([target energy] *
randf() < damage)
6107 Vector direction = HPVectorToVector(HPvector_normal(HPvector_subtract(pos,[target position])));
6121 if (srcEntity ==
nil)
return nil;
6133 HPVector midfrontplane = make_HPvector(0.5 * (bbox.max.x + bbox.min.x), 0.5 * (bbox.max.y + bbox.min.y), bbox.max.z);
6136 if ([parent isPlayer]) q1.w = -q1.w;
6145 for (i = 0; i < ent_count; i++)
6148 if (ent != srcEntity && ent != parent && [ent isShip] && [ent canCollide])
6179 HPVector p1 = HPvector_add(p0, vectorToHPVector(vector_multiply_scalar(f1, nearest)));
6181 for (i = 0; i < ship_count; i++)
6187 Vector rpos = HPVectorToVector(HPvector_subtract(e2->
position, p0));
6188 Vector v_off = make_vector(dot_product(rpos, r1), dot_product(rpos, u1), dot_product(rpos, f1));
6189 if (v_off.z > 0.0 && v_off.z < nearest + cr &&
6190 v_off.x < cr && v_off.x > -cr && v_off.y < cr && v_off.y > -cr &&
6191 v_off.x * v_off.x + v_off.y * v_off.y < cr * cr)
6194 GLfloat hit = [(
ShipEntity *)
e2 doesHitLine:p0 :p1 :&entHit];
6196 if (hit > 0.0 && hit < nearest)
6198 if ([entHit isSubEntity])
6200 hit_subentity = entHit;
6204 p1 = HPvector_add(p0, vectorToHPVector(vector_multiply_scalar(f1, nearest)));
6214 if (range_ptr != NULL)
6216 *range_ptr = nearest;
6220 for (i = 0; i < ship_count; i++) [my_entities[i] release];
6231 nearest2 *= nearest2;
6237 for (i = 0; i < ent_count; i++)
6261 case VIEW_STARBOARD :
6269 for (i = 0; i < ship_count; i++)
6272 if ([e2 canCollide] && [e2 scanClass] != CLASS_NO_DRAW)
6274 Vector rp = HPVectorToVector(HPvector_subtract([e2 position], p1));
6276 if (dist2 < nearest2)
6279 if (df > 0.0 && df * df < nearest2)
6284 if (du * du + dr * dr < cr * cr)
6294 if (hit_entity !=
nil && [hit_entity isShip])
6297 if ([ship isJammingScanning] && ![player hasMilitaryScannerFilter])
6303 for (i = 0; i < ship_count; i++)
6335 case VIEW_STARBOARD:
6350- (NSArray *) entitiesWithinRange:(
double)range ofEntity:(
Entity *)entity
6352 if (entity ==
nil)
return nil;
6361- (unsigned) countShipsWithRole:(NSString *)role inRange:(
double)range ofEntity:(
Entity *)entity
6370- (unsigned) countShipsWithRole:(NSString *)role
6376- (unsigned) countShipsWithPrimaryRole:(NSString *)role inRange:(
double)range ofEntity:(
Entity *)entity
6385- (unsigned) countShipsWithScanClass:(
OOScanClass)scanClass inRange:(
double)range ofEntity:(
Entity *)entity
6394- (unsigned) countShipsWithPrimaryRole:(NSString *)role
6401 parameter:(
void *)parameter
6402 inRange:(
double)range
6405 unsigned i, found = 0;
6407 double distance, cr;
6417 if (e2 != e1 && predicate(e2, parameter))
6419 if (range < 0) distance = -1;
6423 distance = HPdistance2(e2->
position, p1) - cr * cr;
6437 parameter:(
void *)parameter
6438 inRange:(
double)range
6439 ofEntity:(
Entity *)entity
6441 if (predicate != NULL)
6446 predicate, parameter
6466 if (range < 0)
return YES;
6468 return HPdistance2(e2->
position,p1) < cr * cr;
6475 parameter:(
void *)parameter
6476 inRange:(
double)range
6483 NSMutableArray *result =
nil;
6500 predicate(e2, parameter))
6515 parameter:(
void *)parameter
6527 if (predicate(candidate, parameter))
return candidate;
6537 parameter:(
void *)parameter
6538 inRange:(
double)range
6539 ofEntity:(
Entity *)entity
6541 if (predicate != NULL)
6546 predicate, parameter
6565 parameter:(
void *)parameter
6566 inRange:(
double)range
6567 ofEntity:(
Entity *)entity
6569 if (predicate != NULL)
6574 predicate, parameter
6593 parameter:(
void *)parameter
6594 relativeToEntity:(
Entity *)entity
6598 float rangeSq = INFINITY;
6609 float distanceToReferenceEntitySquared = (float)HPdistance2(p1, [e2 position]);
6612 distanceToReferenceEntitySquared < rangeSq &&
6613 predicate(e2, parameter))
6616 rangeSq = distanceToReferenceEntitySquared;
6620 return [[
result retain] autorelease];
6625 parameter:(
void *)parameter
6626 relativeToEntity:(
Entity *)entity
6628 if (predicate != NULL)
6633 predicate, parameter
6704 BOOL guiSelected = NO;
6712 ms =
DESC(
@"forward-view-string");
6716 ms =
DESC(
@"aft-view-string");
6720 ms =
DESC(
@"port-view-string");
6723 case VIEW_STARBOARD:
6724 ms =
DESC(
@"starboard-view-string");
6728 ms = [PLAYER customViewDescription];
6731 case VIEW_GUI_DISPLAY:
6754 #if (ALLOW_CUSTOM_VIEWS_WHILE_PAUSED)
6757 BOOL gamePaused = NO;
6762 if (ms && !gamePaused)
6766 else if (gamePaused)
6774- (void) enterGUIViewModeWithMouseInteraction:(BOOL)mouseInteraction
6788- (NSString *) soundNameForCustomSoundKey:(NSString *)key
6790 NSString *result =
nil;
6791 NSMutableSet *seen =
nil;
6792 id object = [customSounds objectForKey:key];
6794 if ([
object isKindOfClass:[NSArray
class]] && [
object count] > 0)
6796 key = [
object oo_stringAtIndex:Ranrot() % [
object count]];
6809 if (
object ==
nil || ([result hasPrefix:
@"["] && [result hasSuffix:
@"]"]))
6813 [
seen addObject:result];
6814 object = [customSounds objectForKey:result];
6815 if( [
object isKindOfClass:[NSArray
class]] && [
object count] > 0)
6817 result = [
object oo_stringAtIndex:Ranrot() % [
object count]];
6818 if ([key hasPrefix:
@"["] && [key hasSuffix:
@"]"]) key=result;
6822 if ([
object isKindOfClass:[NSString
class]])
6827 if (result ==
nil || ![result hasPrefix:
@"["] || ![result hasSuffix:
@"]"])
break;
6828 if ([seen containsObject:result])
6830 OOLogERR(
@"sound.customSounds.recursion",
@"recursion in customsounds.plist for '%@' (at '%@'), no sound will be played.", key, result);
6837 if (result ==
nil) result =
@"__oolite-no-sound";
6841 if ([result isEqualToString:
@"__oolite-no-sound"])
6843 OOLog(
@"sound.customSounds",
@"Could not resolve sound name in customsounds.plist for '%@', no sound will be played.", key);
6850- (NSDictionary *) screenTextureDescriptorForKey:(NSString *)key
6852 id value = [screenBackgrounds objectForKey:key];
6853 while ([value isKindOfClass:[NSArray
class]]) value = [
value objectAtIndex:Ranrot() % [
value count]];
6855 if ([value isKindOfClass:[NSString
class]]) value = [
NSDictionary dictionaryWithObject:value forKey:@"name"];
6856 else if (![value isKindOfClass:[NSDictionary
class]]) value =
nil;
6859 if (![[
self gui] preloadGUITexture:value]) value =
nil;
6865- (void) setScreenTextureDescriptorForKey:(NSString *)key descriptor:(NSDictionary *)desc
6867 NSMutableDictionary *sbCopy = [screenBackgrounds mutableCopy];
6870 [
sbCopy removeObjectForKey:key];
6874 [
sbCopy setObject:desc forKey:key];
6876 [screenBackgrounds release];
6889- (void) setMessageGuiBackgroundColor:(
OOColor *)some_color
6907- (void) displayCountdownMessage:(NSString *) text forCount:(
OOTimeDelta)count
6919- (void) addDelayedMessage:(NSString *)text forCount:(
OOTimeDelta)count afterDelay:(
double)delay
6922 [
msgDict setObject:text forKey:@"message"];
6923 [
msgDict setObject:[
NSNumber numberWithDouble:count] forKey:@"duration"];
6924 [
self performSelector:@selector(addDelayedMessage:) withObject:msgDict afterDelay:delay];
6928- (void) addDelayedMessage:(NSDictionary *) textdict
6930 NSString *msg =
nil;
6933 msg = [
textdict oo_stringForKey:@"message"];
6934 if (msg ==
nil)
return;
6935 msg_duration = [
textdict oo_nonNegativeDoubleForKey:@"duration" defaultValue:3.0];
6947- (void) speakWithSubstitutions:(NSString *)text
6949#if OOLITE_SPEECH_SYNTH
6955 NSString *systemSaid =
nil;
6956 NSString *h_systemSaid =
nil;
6960 systemSaid = systemName;
6963 h_systemSaid = h_systemName;
6965 NSString *spokenText = text;
6968 NSEnumerator *speechEnumerator =
nil;
6969 NSArray *thePair =
nil;
6973 NSString *original_phrase = [
thePair oo_stringAtIndex:0];
6975 NSUInteger replacementIndex;
6977 replacementIndex = 1;
6979 replacementIndex = [
thePair count] > 2 ? 2 : 1;
6982 NSString *replacement_phrase = [
thePair oo_stringAtIndex:replacementIndex];
6983 if (![replacement_phrase isEqualToString:
@"_"])
6985 spokenText = [
spokenText stringByReplacingOccurrencesOfString:original_phrase withString:replacement_phrase];
6988 spokenText = [
spokenText stringByReplacingOccurrencesOfString:systemName withString:systemSaid];
6989 spokenText = [
spokenText stringByReplacingOccurrencesOfString:h_systemName withString:h_systemSaid];
6998- (void) addMessage:(NSString *) text forCount:(
OOTimeDelta) count forceDisplay:(BOOL) forceDisplay
7009 [PLAYER doScriptEvent:OOJSID("consoleMessageReceived") withArgument:text];
7011 [currentMessage release];
7024- (void) addCommsMessage:(NSString *)text forCount:(
OOTimeDelta)count andShowComms:(BOOL)showComms logOnly:(BOOL)logOnly
7026 if ([
PLAYER showDemoShips])
return;
7028 NSString *expandedMessage =
OOExpand(text);
7039 NSString *format =
OOExpandKey(
@"speech-synthesis-incoming-message-@");
7045 [currentMessage release];
7064- (void) showGUIMessage:(NSString *)text withScroll:(BOOL)scroll andColor:(
OOColor *)selectedColor overDuration:(
OOTimeDelta)how_long
7085 [PLAYER doWorldScriptEvent:OOJSIDFromString(system_repopulator) inContext:context withArguments:NULL count:0 timeLimit:kOOJSLongTimeLimit];
7095 OOLog(
@"universe.profile.update",
@"%@",
@"Begin update");
7110 for (i = 0; i < ent_count; i++)
7115 NSString *
volatile update_stage =
@"initialisation";
7117 id volatile update_stage_param =
nil;
7132 if (
EXPECT_NOT([player showDemoShips] && [player guiScreen] == GUI_SCREEN_SHIPLIBRARY))
7134 update_stage =
@"demo management";
7214 update_stage =
@"update:entity";
7215 NSMutableSet *zombies =
nil;
7216 OOLog(
@"universe.profile.update",
@"%@", update_stage);
7217 for (i = 0; i < ent_count; i++)
7219 Entity *thing = my_entities[
i];
7221 update_stage_param = thing;
7222 update_stage =
@"update:entity [%@]";
7240 update_stage =
@"update:list maintenance [%@]";
7247 while (index > 0 && z_distance <
sortedEntities[index - 1]->zero_distance)
7260 update_stage =
@"update:think [%@]";
7275 update_stage_param =
nil;
7280 update_stage =
@"shootin' zombies";
7281 NSEnumerator *zombieEnum =
nil;
7283 for (zombieEnum = [zombies objectEnumerator]; (zombie = [
zombieEnum nextObject]); )
7285 OOLogERR(
@"universe.zombie",
@"Found dead entity %@ in active entity list, removing. This is an internal error, please report it.", zombie);
7291 update_stage =
@"updating linked lists";
7292 OOLog(
@"universe.profile.update",
@"%@", update_stage);
7293 for (i = 0; i < ent_count; i++)
7300 update_stage =
@"collision and shadow detection";
7301 OOLog(
@"universe.profile.update",
@"%@", update_stage);
7313 @catch (NSException *exception)
7315 if ([[exception name] hasPrefix:
@"Oolite"])
7322 if (update_stage_param !=
nil) update_stage = [
NSString stringWithFormat:update_stage, update_stage_param];
7324 OOLog(
kOOLogException,
@"***** Exception during [%@] in [Universe update:] : %@ : %@ *****", update_stage, [exception name], [exception reason]);
7330 update_stage =
@"clean up";
7331 OOLog(
@"universe.profile.update",
@"%@", update_stage);
7332 for (i = 0; i < ent_count; i++)
7344 update_stage =
@"JS Garbage Collection";
7345 OOLog(
@"universe.profile.update",
@"%@", update_stage);
7348 uint32 gcbytes1 = JS_GetGCParameter(JS_GetRuntime(context),JSGC_BYTES);
7354 uint32 gcbytes2 = JS_GetGCParameter(JS_GetRuntime(context),JSGC_BYTES);
7356 if (gcbytes2 < gcbytes1)
7358 OOLog(
@"universe.profile.jsgc",
@"Unplanned JS Garbage Collection from %d to %d",gcbytes1,gcbytes2);
7367 if ([
PLAYER status] == STATUS_DEAD) [PLAYER update:delta_t];
7370 [entitiesDeadThisUpdate autorelease];
7375 [
self prunePreloadingPlanetMaterials];
7378 OOLog(
@"universe.profile.update",
@"%@",
@"Update complete");
7389- (void) setTimeAccelerationFactor:(
double)newTimeAccelerationFactor
7398- (double) timeAccelerationFactor
7404- (void) setTimeAccelerationFactor:(
double)newTimeAccelerationFactor
7416- (void) setECMVisualFXEnabled:(BOOL)isEnabled
7432 Entity *e0, *next, *prev;
7433 OOHPScalar start, finish, next_start, next_finish, prev_start, prev_finish;
7464 if (next_start < finish)
7467 while ((next)&&(next_start < finish))
7471 if (next_finish > finish)
7472 finish = next_finish;
7508 if (prev_start > finish)
7511 while ((prev)&&(prev_start > finish))
7515 if (prev_finish < finish)
7516 finish = prev_finish;
7555 if (next_start < finish)
7558 while ((next)&&(next_start < finish))
7562 if (next_finish > finish)
7563 finish = next_finish;
7599 if (prev_start > finish)
7602 while ((prev)&&(prev_start > finish))
7606 if (prev_finish < finish)
7607 finish = prev_finish;
7645 if (next_start < finish)
7648 while ((next)&&(next_start < finish))
7652 if (next_finish > finish)
7653 finish = next_finish;
7689 if (prev_start > finish)
7692 while ((prev)&&(prev_start > finish))
7696 if (prev_finish < finish)
7697 finish = prev_finish;
7735 if (next_start < finish)
7738 while ((next)&&(next_start < finish))
7742 if (next_finish > finish)
7743 finish = next_finish;
7778 if (prev_start > finish)
7781 while ((prev)&&(prev_start > finish))
7785 if (prev_finish < finish)
7786 finish = prev_finish;
7824 if (next_start < finish)
7827 while ((next)&&(next_start < finish))
7833 if (next_finish > finish)
7834 finish = next_finish;
7870 if (prev_start > finish)
7873 while ((prev)&&(prev_start > finish))
7898 OOLog(
@"general.error.inconsistentState",
@"Unexpected state in collision chain builder prev=%@, prev->c=%@, e0=%@, e0->c=%@",prev,prev->
collision_chain,e0,e0->
collision_chain);
7904 if (prev_finish < finish)
7905 finish = prev_finish;
7944 NSAutoreleasePool *pool =
nil;
7952 for (i = 0; i < 256; i++)
7956 [system_names[
i] release];
7968 NSDictionary *systemData;
7971 NSString *scriptName;
7979 economy = [
systemData oo_unsignedCharForKey:KEY_ECONOMY];
7980 scriptName = [
systemData oo_stringForKey:@"market_script" defaultValue:nil];
8000 stringByAppendingPathComponent:@"Config"]
8001 stringByAppendingPathComponent:@"descriptions.plist"]];
8009static void VerifyDesc(NSString *key,
id desc);
8014 if ([desc rangeOfString:
@"%n"].location != NSNotFound)
8016 OOLog(
@"descriptions.verify.percentN",
@"***** FATAL: descriptions.plist entry \"%@\
" contains the dangerous control sequence %%n.", key);
8025 foreach (subDesc, desc)
8034 if ([desc isKindOfClass:[NSString
class]])
8038 else if ([desc isKindOfClass:[NSArray
class]])
8042 else if ([desc isKindOfClass:[NSNumber
class]])
8048 OOLogERR(
@"descriptions.verify.badType",
@"***** FATAL: descriptions.plist entry for \"%@\
" is neither a string nor an array.", key);
8066 NSString *key =
nil;
8067 if (_descriptions ==
nil)
8069 OOLog(
@"descriptions.verify",
@"%@",
@"***** FATAL: Tried to verify descriptions, but descriptions was nil - unable to load any descriptions.plist file.");
8074 VerifyDesc(key, [_descriptions objectForKey:key]);
8087- (NSDictionary *) explosionSetting:(NSString *)explosion
8089 return [explosionSettings oo_dictionaryForKey:explosion defaultValue:nil];
8118- (NSString *)descriptionForKey:(NSString *)key
8124- (NSString *)descriptionForArrayKey:(NSString *)key index:(
unsigned)index
8126 NSArray *array = [[
self descriptions] oo_arrayForKey:key];
8127 if ([array
count] <= index)
return nil;
8128 return [
array objectAtIndex:index];
8132- (BOOL) descriptionBooleanForKey:(NSString *)key
8146 return [
NSString stringWithFormat:@"%d %d", g, s];
8152 return [
NSString stringWithFormat:@"interstellar: %d %d %d", g, s1, s2];
8163- (NSDictionary *) generateSystemData:(
OOSystemID) s useCache:(BOOL) useCache
8170 NSString *systemKey = [
NSString stringWithFormat:@"%u %u",[PLAYER galaxyNumber],s];
8188 static NSDictionary *interstellarDict =
nil;
8189 if (interstellarDict ==
nil)
8191 NSString *interstellarName =
DESC(
@"interstellar-space");
8192 NSString *notApplicable =
DESC(
@"not-applicable");
8193 NSNumber *minusOne = [
NSNumber numberWithInt:-1];
8194 NSNumber *zero = [
NSNumber numberWithInt:0];
8195 interstellarDict = [[
NSDictionary alloc] initWithObjectsAndKeys:
8196 interstellarName, KEY_NAME,
8197 minusOne, KEY_GOVERNMENT,
8198 minusOne, KEY_ECONOMY,
8199 minusOne, KEY_TECHLEVEL,
8200 zero, KEY_POPULATION,
8201 zero, KEY_PRODUCTIVITY,
8203 notApplicable, KEY_INHABITANTS,
8204 notApplicable, KEY_DESCRIPTION,
8208 return interstellarDict;
8217 return [
self sun] ==
nil;
8225- (void) setSystemDataKey:(NSString *)key value:(NSObject *)object fromManifest:(NSString *)manifest
8233 static BOOL sysdataLocked = NO;
8236 OOLogERR(
@"script.error",
@"%@",
@"System properties cannot be set during 'systemInformationChanged' events to avoid infinite loops.");
8240 BOOL sameGalaxy = (gnum == [PLAYER currentGalaxyID]);
8244 if ([key isEqualToString:
KEY_RADIUS] && sameGalaxy && sameSystem)
8246 OOLogERR(
@"script.error",
@"System property '%@' cannot be set while in the system.",key);
8250 if ([key isEqualToString:
@"coordinates"])
8252 OOLogERR(
@"script.error",
@"System property '%@' cannot be set.",key);
8257 NSString *overrideKey = [
NSString stringWithFormat:@"%u %u", gnum, pnum];
8258 NSDictionary *sysInfo =
nil;
8263 if (
object !=
nil) {
8265 if ([key isEqualToString:
KEY_NAME])
8267 object=(id)[[(NSString *)
object lowercaseString] capitalizedString];
8274 else if ([key isEqualToString:
@"sun_radius"])
8276 if ([
object doubleValue] < 1000.0 || [
object doubleValue] > 10000000.0 )
8278 object = ([
object doubleValue] < 1000.0 ? (id)
@"1000.0" : (id)
@"10000000.0");
8281 else if ([key hasPrefix:
@"corona_"])
8283 object = (id)[NSString stringWithFormat:
@"%f",OOClamp_0_1_f([
object floatValue])];
8308 else if ([key isEqualToString:
@"sun_color"] || [key isEqualToString:
@"star_count_multiplier"] ||
8309 [key isEqualToString:
@"nebula_count_multiplier"] || [key hasPrefix:
@"sky_"])
8322 if ([key isEqualToString:
@"sun_color"])
8337 else if (the_sun !=
nil && ([key hasPrefix:
@"sun_"] || [key hasPrefix:
@"corona_"]))
8341 else if ([key isEqualToString:
@"texture"])
8343 [[
self planet] setUpPlanetFromTexture:(NSString *)object];
8345 else if ([key isEqualToString:
@"texture_hsb_color"])
8347 [[
self planet] setUpPlanetFromTexture: [[
self planet] textureFileName]];
8349 else if ([key isEqualToString:
@"air_color"])
8353 else if ([key isEqualToString:
@"illumination_color"])
8357 else if ([key isEqualToString:
@"air_color_mix_ratio"])
8359 [[
self planet] setAirColorMixRatio:[
sysInfo oo_floatForKey:key]];
8363 sysdataLocked = YES;
8364 [PLAYER doScriptEvent:OOJSID("systemInformationChanged") withArguments:[
NSArray arrayWithObjects:[
NSNumber numberWithInt:gnum],[
NSNumber numberWithInt:pnum],key,object,nil]];
8414- (NSString *) getSystemInhabitants:(
OOSystemID) sys plural:(BOOL)plural
8416 NSString *ret =
nil;
8440 if (sysName ==
nil)
return -1;
8442 NSString *system_name =
nil;
8443 NSString *match = [
sysName lowercaseString];
8445 for (i = 0; i < 256; i++)
8447 system_name = [system_names[
i] lowercaseString];
8448 if ([system_name isEqualToString:match])
8459 OOLog(
@"deprecated.function",
@"%@",
@"findSystemAtCoords");
8464- (NSMutableArray *) nearbyDestinationsWithinRange:(
double)range
8469 NSPoint here = [PLAYER galaxy_coordinates];
8471 for (
unsigned short i = 0; i < 256; i++)
8478 [
NSNumber numberWithDouble:dist], @"distance",
8479 [
NSNumber numberWithInt:i], @"sysID",
8480 [[
self generateSystemData:i] oo_stringForKey:@"sun_gone_nova" defaultValue:@"0"], @"nova",
8494 double min_dist = 10000.0;
8497 BOOL connected[256];
8498 for (i = 0; i < 256; i++)
8501 for (n = 0; n < 3; n++)
8503 for (i = 0; i < 256; i++)
8506 for (j = 0; j < 256; j++)
8512 connected[
j] |= connected[
i];
8513 connected[
i] |= connected[
j];
8519 for (i = 0; i < 256; i++)
8523 if ((connected[i])&&(distance < min_dist)&&(distance != 0.0))
8525 min_dist = distance;
8541 double min_dist = 10000.0;
8544 BOOL connected[256];
8545 for (i = 0; i < 256; i++)
8548 for (n = 0; n < 3; n++)
8550 for (i = 0; i < 256; i++)
8553 for (j = 0; j < 256; j++)
8559 connected[
j] |= connected[
i];
8560 connected[
i] |= connected[
j];
8566 for (i = 0; i < 256; i++)
8570 if ((connected[i])&&(distance < min_dist))
8572 min_dist = distance;
8590 unsigned distance, dx, dy;
8592 unsigned min_dist = 10000;
8594 for (i = 0; i < 256; i++)
8598 NSInteger concealment = [
systemInfo oo_intForKey:@"concealment" defaultValue:OO_SYSTEMCONCEALMENT_NONE];
8605 dx =
ABS(coords.x - ipos.x);
8606 dy =
ABS(coords.y - ipos.y);
8608 if (dx > dy) distance = (dx + dx + dy) / 2;
8609 else distance = (dx + dy + dy) / 2;
8611 if (distance < min_dist)
8613 min_dist = distance;
8617 if ((distance == min_dist)&&(coords.y > ipos.y))
8631- (NSPoint) findSystemCoordinatesWithPrefix:(NSString *) p_fix
8637- (NSPoint) findSystemCoordinatesWithPrefix:(NSString *) p_fix exactMatch:(BOOL) exactMatch
8639 NSString *system_name =
nil;
8640 NSPoint system_coords = NSMakePoint(-1.0,-1.0);
8643 for (i = 0; i < 256; i++)
8646 system_name = [system_names[
i] lowercaseString];
8647 if ((exactMatch && [system_name isEqualToString:p_fix]) || (!exactMatch && [system_name hasPrefix:p_fix]))
8651 NSInteger concealment = [
systemInfo oo_intForKey:@"concealment" defaultValue:OO_SYSTEMCONCEALMENT_NONE];
8665 return system_coords;
8694 if (start == -1 || goal == -1)
return nil;
8696#ifdef CACHE_ROUTE_FROM_SYSTEM_RESULTS
8698 static NSDictionary *c_route =
nil;
8702 if (c_route !=
nil && c_start == start && c_goal == goal && c_optimizeBy == optimizeBy)
8711 if (start > 255 || goal > 255)
return nil;
8713 NSArray *neighbours[256];
8714 BOOL concealed[256];
8715 for (i = 0; i < 256; i++)
8718 NSInteger concealment = [
systemInfo oo_intForKey:@"concealment" defaultValue:OO_SYSTEMCONCEALMENT_NONE];
8733 double maxCost = optimizeBy ==
OPTIMIZED_BY_TIME ? 256 * (7 * 7) : 256 * (7 * 256 + 7);
8739 while ([curr
count] != 0)
8741 for (i = 0; i < [
curr count]; i++) {
8744 for (j = 0; j < [
ns count]; j++)
8758 double lastTime = lastDistance * lastDistance;
8760 double distance = [
ce distance] + lastDistance;
8761 double time = [
ce time] + lastTime;
8765 if (cost < maxCost && (cheapest[n] ==
nil || [cheapest[n] cost] > cost)) {
8770 if (n == goal && cost < maxCost)
8775 [
curr setArray:next];
8776 [
next removeAllObjects];
8780 if (!cheapest[goal])
return nil;
8787 if ([e parent] == -1)
break;
8791#ifdef CACHE_ROUTE_FROM_SYSTEM_RESULTS
8794 c_optimizeBy = optimizeBy;
8820 [closeSystems release];
8860 [
self prunePreloadingPlanetMaterials];
8862 if ([_preloadingPlanetMaterials
count] < 3)
8864 if (_preloadingPlanetMaterials ==
nil) _preloadingPlanetMaterials = [[
NSMutableArray alloc] initWithCapacity:4];
8872 if (![surface isFinishedLoading])
8878 OOMaterial *atmo = [planet atmosphereMaterial];
8913- (NSString *) timeDescription:(
double) interval
8915 double r_time = interval;
8916 NSString* result =
@"";
8920 int days = floor(r_time / 86400);
8921 r_time -= 86400 * days;
8922 result = [
NSString stringWithFormat:@"%@ %d day%@", result, days, (days > 1) ? @"s" : @""];
8926 int hours = floor(r_time / 3600);
8927 r_time -= 3600 * hours;
8928 result = [
NSString stringWithFormat:@"%@ %d hour%@", result, hours, (hours > 1) ? @"s" : @""];
8932 int mins = floor(r_time / 60);
8933 r_time -= 60 * mins;
8934 result = [
NSString stringWithFormat:@"%@ %d minute%@", result, mins, (mins > 1) ? @"s" : @""];
8938 int secs = floor(r_time);
8939 result = [
NSString stringWithFormat:@"%@ %d second%@", result, secs, (secs > 1) ? @"s" : @""];
8945- (NSString *) shortTimeDescription:(
double) interval
8947 double r_time = interval;
8948 NSString* result =
@"";
8951 if (interval <= 0.0)
8952 return DESC(
@"contracts-no-time");
8956 int days = floor(r_time / 86400);
8957 r_time -= 86400 * days;
8958 result = [
NSString stringWithFormat:@"%@ %d %@", result, days, DESC_PLURAL(@"contracts-day-word", days)];
8963 int hours = floor(r_time / 3600);
8964 r_time -= 3600 * hours;
8965 result = [
NSString stringWithFormat:@"%@ %d %@", result, hours, DESC_PLURAL(@"contracts-hour-word", hours)];
8968 if (parts < 2 && r_time > 60)
8970 int mins = floor(r_time / 60);
8971 r_time -= 60 * mins;
8972 result = [
NSString stringWithFormat:@"%@ %d %@", result, mins, DESC_PLURAL(@"contracts-minute-word", mins)];
8975 if (parts < 2 && r_time > 0)
8977 int secs = floor(r_time);
8978 result = [
NSString stringWithFormat:@"%@ %d %@", result, secs, DESC_PLURAL(@"contracts-second-word", secs)];
9012- (void) loadStationMarkets:(NSArray *)marketData
9014 if (marketData ==
nil)
9021 NSDictionary *savedMarket =
nil;
9023 foreach (savedMarket, marketData)
9025 HPVector pos = [
savedMarket oo_hpvectorForKey:@"position"];
9032 if (HPdistance2(pos,[
station position]) < 1000000)
9050 NSMutableDictionary *savedMarket =
nil;
9060 if (stationMarket !=
nil)
9065 [
markets addObject:savedMarket];
9081 float tech_price_boost = (ship_seed.
a + ship_seed.
b) / 256.0;
9087 for (i = 0; i < 256; i++)
9089 long long reference_time = 0x1000000 * floor(current_time / 0x1000000);
9091 long long c_time = ship_seed.
a * 0x10000 + ship_seed.
b * 0x100 + ship_seed.
c;
9092 double ship_sold_time = reference_time + c_time;
9094 if (ship_sold_time < 0)
9095 ship_sold_time += 0x1000000;
9097 double days_until_sale = (ship_sold_time - current_time) / 86400.0;
9106 NSArray *conditions = [
dict oo_arrayForKey:@"conditions"];
9108 if (![player scriptTestConditions:conditions])
9112 NSString *condition_script = [
dict oo_stringForKey:@"condition_script"];
9113 if (condition_script !=
nil)
9116 if (condScript !=
nil)
9120 JSBool allow_purchase;
9129 if (OK) OK = JS_ValueToBoolean(context, result, &allow_purchase);
9133 if (OK && !allow_purchase)
9147 if (specialTL != NSNotFound)
9150 techlevel = specialTL;
9155 techlevel = [
systemInfo oo_unsignedIntForKey:KEY_TECHLEVEL];
9157 unsigned ship_index = (ship_seed.
d * 0x100 + ship_seed.
e) % [keysForShips
count];
9158 NSString *ship_key = [
keysForShips oo_stringAtIndex:ship_index];
9165 int superRand1 = ship_seed.
a * 0x10000 + ship_seed.
c * 0x100 + ship_seed.
e;
9166 uint32_t superRand2 = ship_seed.
b * 0x10000 + ship_seed.
d * 0x100 + ship_seed.
f;
9171 if ((days_until_sale > 0.0) && (days_until_sale < 30.0) && (ship_techlevel <= techlevel) && (
randf() < chance) && (shipBaseDict !=
nil))
9173 NSMutableDictionary* shipDict = [
NSMutableDictionary dictionaryWithDictionary:shipBaseDict];
9174 NSMutableString* shortShipDescription = [
NSMutableString stringWithCapacity:256];
9175 NSString *shipName = [
shipDict oo_stringForKey:@"display_name" defaultValue:[
shipDict oo_stringForKey:KEY_NAME]];
9178 NSMutableArray* extras = [
NSMutableArray arrayWithArray:[[
ship_info oo_dictionaryForKey:KEY_STANDARD_EQUIPMENT] oo_arrayForKey:KEY_EQUIPMENT_EXTRAS]];
9179 NSString* fwdWeaponString = [[
ship_info oo_dictionaryForKey:KEY_STANDARD_EQUIPMENT] oo_stringForKey:KEY_EQUIPMENT_FORWARD_WEAPON];
9180 NSString* aftWeaponString = [[
ship_info oo_dictionaryForKey:KEY_STANDARD_EQUIPMENT] oo_stringForKey:KEY_EQUIPMENT_AFT_WEAPON];
9197 if (fwdWeapon && fwdWeaponString) [
shipDict setObject:fwdWeaponString forKey:KEY_EQUIPMENT_FORWARD_WEAPON];
9198 if (aftWeapon && aftWeaponString) [
shipDict setObject:aftWeaponString forKey:KEY_EQUIPMENT_AFT_WEAPON];
9200 int passengerBerthCount = 0;
9201 BOOL customised = NO;
9202 BOOL weaponCustomized = NO;
9204 NSString *fwdWeaponDesc =
nil;
9206 NSString *shortExtrasKey =
@"shipyard-first-extra";
9211 while ((
randf() < chance) && ([options
count]))
9215 NSString *equipmentKey = [
options oo_stringAtIndex:optionIndex];
9222 NSString *eqShortDesc = [
item name];
9224 if ([item techLevel] > techlevel)
9227 eqTechLevel =
MIN(eqTechLevel, 15U);
9230 if (
randf() * (eqTechLevel - techlevel) < 1.0)
9233 eqPrice *= (tech_price_boost + eqTechLevel - techlevel) * 90 / 100;
9239 if ([item incompatibleEquipment] !=
nil && extras !=
nil)
9241 NSEnumerator *keyEnum =
nil;
9243 BOOL incompatible = NO;
9245 for (keyEnum = [[item incompatibleEquipment] objectEnumerator]; (key = [
keyEnum nextObject]); )
9247 if ([extras containsObject:key])
9249 [
options removeObject:equipmentKey];
9254 if (incompatible)
break;
9257 for (keyEnum = [[item incompatibleEquipment] objectEnumerator]; (key = [
keyEnum nextObject]); )
9259 if ([options containsObject:key])
9268 if (condition_script !=
nil)
9271 if (condScript !=
nil)
9275 JSBool allow_addition;
9284 if (OK) OK = JS_ValueToBoolean(JScontext, result, &allow_addition);
9288 if (OK && !allow_addition)
9299 if ([item requiresEquipment] !=
nil && extras !=
nil)
9301 NSEnumerator *keyEnum =
nil;
9305 for (keyEnum = [[item requiresEquipment] objectEnumerator]; (key = [
keyEnum nextObject]); )
9307 if (![extras containsObject:key])
9315 if ([item requiresAnyEquipment] !=
nil && extras !=
nil)
9317 NSEnumerator *keyEnum =
nil;
9321 for (keyEnum = [[item requiresAnyEquipment] objectEnumerator]; (key = [
keyEnum nextObject]); )
9323 if ([extras containsObject:key])
9333 if ([equipmentKey isEqualTo:
@"EQ_NAVAL_ENERGY_UNIT"])
9335 if ([extras containsObject:
@"EQ_ENERGY_UNIT"])
9337 [
options removeObject:equipmentKey];
9342 if ([equipmentKey hasPrefix:
@"EQ_WEAPON"])
9346 if (availableFacings &
WEAPON_FACING_FORWARD && [new_weapon weaponThreatAssessment] > [fwdWeapon weaponThreatAssessment])
9351 fwdWeaponString = equipmentKey;
9352 fwdWeapon = new_weapon;
9353 [
shipDict setObject:fwdWeaponString forKey:KEY_EQUIPMENT_FORWARD_WEAPON];
9354 weaponCustomized = YES;
9355 fwdWeaponDesc = eqShortDesc;
9360 if (availableFacings &
WEAPON_FACING_AFT && (
isWeaponNone(aftWeapon) || [new_weapon weaponThreatAssessment] > [aftWeapon weaponThreatAssessment]))
9364 aftWeaponString = equipmentKey;
9365 aftWeapon = new_weapon;
9366 [
shipDict setObject:aftWeaponString forKey:KEY_EQUIPMENT_AFT_WEAPON];
9370 [
options removeObject:equipmentKey];
9377 if ([equipmentKey isEqualToString:
@"EQ_PASSENGER_BERTH"])
9383 [
extras addObject:equipmentKey];
9384 passengerBerthCount++;
9390 [
options removeObject:equipmentKey];
9396 [
extras addObject:equipmentKey];
9397 if ([item isVisible])
9399 NSString *item = eqShortDesc;
9401 shortExtrasKey =
@"shipyard-additional-extra";
9404 [
options removeObject:equipmentKey];
9410 [
options removeObject:equipmentKey];
9415 BOOL lowercaseIgnore = [[
self descriptions] oo_boolForKey:@"lowercase_ignore"];
9417 if (passengerBerthCount)
9419 NSString* npb = (passengerBerthCount > 1)? [NSString stringWithFormat:
@"%d ", passengerBerthCount] : (id)
@"";
9420 NSString* ppb =
DESC_PLURAL(
@"passenger-berth", passengerBerthCount);
9421 NSString* extraPassengerBerthsDescription = [
NSString stringWithFormat:DESC(@"extra-@-@-(passenger-berths)"), npb, ppb];
9422 NSString *item = extraPassengerBerthsDescription;
9424 shortExtrasKey =
@"shipyard-additional-extra";
9432 if (weaponCustomized)
9434 NSString *weapon = (lowercaseIgnore ? fwdWeaponDesc : [
fwdWeaponDesc lowercaseString]);
9437 if (price > base_price)
9439 price = base_price +
cunningFee(price - base_price, 0.05);
9444 NSString *shipID = [
NSString stringWithFormat:@"%06x-%06x", superRand1, superRand2];
9448 NSDictionary *ship_info_dictionary = [
NSDictionary dictionaryWithObjectsAndKeys:
9449 shipID, SHIPYARD_KEY_ID,
9450 ship_key, SHIPYARD_KEY_SHIPDATA_KEY,
9451 shipDict, SHIPYARD_KEY_SHIP,
9452 shortShipDescription, KEY_SHORT_DESCRIPTION,
9453 [
NSNumber numberWithUnsignedLongLong:price], SHIPYARD_KEY_PRICE,
9454 extras, KEY_EQUIPMENT_EXTRAS,
9455 [
NSNumber numberWithUnsignedShort:personality], SHIPYARD_KEY_PERSONALITY,
9468 NSMutableArray *resultArray = [[[
resultDictionary allValues] mutableCopy] autorelease];
9469 [
resultArray sortUsingFunction:compareName context:NULL];
9474 while (i < [resultArray
count])
9476 if (
compareName([resultArray objectAtIndex:i - 1], [resultArray objectAtIndex:i],
nil) == NSOrderedSame )
9488 return [
NSArray arrayWithArray:resultArray];
9494 NSDictionary *ship1 = [(
NSDictionary *)
dict1 oo_dictionaryForKey:SHIPYARD_KEY_SHIP];
9495 NSDictionary *ship2 = [(
NSDictionary *)
dict2 oo_dictionaryForKey:SHIPYARD_KEY_SHIP];
9496 NSString *name1 = [
ship1 oo_stringForKey:KEY_NAME];
9497 NSString *name2 = [
ship2 oo_stringForKey:KEY_NAME];
9499 NSComparisonResult result = [[
name1 lowercaseString] compare:[
name2 lowercaseString]];
9500 if (result != NSOrderedSame)
9512 return [
price1 compare:price2];
9520 NSString *ship_desc = [
dict oo_stringForKey:@"ship_desc"];
9524 if (shipyard_info ==
nil)
9526 OOLogERR(
@"universe.tradeInValueForCommanderDictionary.valueCalculationError",
9527 @"Shipyard dictionary entry for ship %@ required for trade in value calculation, but does not exist. Setting ship value to 0.", ship_desc);
9531 base_price = [
shipyard_info oo_unsignedLongLongForKey:SHIPYARD_KEY_PRICE defaultValue:0ULL];
9534 if(base_price == 0ULL)
return base_price;
9542 unsigned ship_missiles = [
dict oo_unsignedIntForKey:@"missiles"];
9543 unsigned ship_max_passengers = [
dict oo_unsignedIntForKey:@"max_passengers"];
9544 NSMutableArray *ship_extra_equipment = [
NSMutableArray arrayWithArray:[[
dict oo_dictionaryForKey:@"extra_equipment"] allKeys]];
9546 NSDictionary *basic_info = [
shipyard_info oo_dictionaryForKey:KEY_STANDARD_EQUIPMENT];
9547 unsigned base_missiles = [
basic_info oo_unsignedIntForKey:KEY_EQUIPMENT_MISSILES];
9548 OOCreditsQuantity base_missiles_value = base_missiles * [UNIVERSE getEquipmentPriceForKey:@"EQ_MISSILE"] / 10;
9549 NSString *base_weapon_key = [
basic_info oo_stringForKey:KEY_EQUIPMENT_FORWARD_WEAPON];
9550 OOCreditsQuantity base_weapons_value = [UNIVERSE getEquipmentPriceForKey:base_weapon_key] / 10;
9551 NSMutableArray *base_extra_equipment = [
NSMutableArray arrayWithArray:[
basic_info oo_arrayForKey:KEY_EQUIPMENT_EXTRAS]];
9552 NSString *weapon_key =
nil;
9555 base_weapon_key = [
basic_info oo_stringForKey:KEY_EQUIPMENT_AFT_WEAPON defaultValue:nil];
9556 if (base_weapon_key !=
nil)
9557 base_weapons_value += [UNIVERSE getEquipmentPriceForKey:base_weapon_key] / 10;
9564 NSArray *missileRoles = [
dict oo_arrayForKey:@"missile_roles"];
9565 if (missileRoles !=
nil)
9568 for (i = 0; i < ship_missiles; i++)
9570 NSString *missile_desc = [
missileRoles oo_stringAtIndex:i];
9571 if (missile_desc !=
nil && ![missile_desc isEqualToString:
@"NONE"])
9573 ship_missiles_value += [UNIVERSE getEquipmentPriceForKey:missile_desc] / 10;
9578 ship_missiles_value = ship_missiles * [UNIVERSE getEquipmentPriceForKey:@"EQ_MISSILE"] / 10;
9581 long long extra_equipment_value = ship_max_passengers * [UNIVERSE getEquipmentPriceForKey:@"EQ_PASSENGER_BERTH"]/10;
9584 extra_equipment_value += ship_missiles_value - base_missiles_value;
9587 if (ship_fwd_weapon)
9590 ship_main_weapons_value = [UNIVERSE getEquipmentPriceForKey:weapon_key] / 10;
9592 if (ship_aft_weapon)
9595 if (base_weapon_key !=
nil)
9597 ship_main_weapons_value += [UNIVERSE getEquipmentPriceForKey:weapon_key] / 10;
9601 ship_other_weapons_value += [UNIVERSE getEquipmentPriceForKey:weapon_key] / 10;
9604 if (ship_port_weapon)
9607 ship_other_weapons_value += [UNIVERSE getEquipmentPriceForKey:weapon_key] / 10;
9609 if (ship_starboard_weapon)
9612 ship_other_weapons_value += [UNIVERSE getEquipmentPriceForKey:weapon_key] / 10;
9616 extra_equipment_value += ship_other_weapons_value;
9617 extra_equipment_value += ship_main_weapons_value - base_weapons_value;
9620 NSString *eq_key =
nil;
9624 for (i = [base_extra_equipment
count]-1; i > 0;i--)
9627 if ([base_extra_equipment indexOfObject:eq_key inRange:NSMakeRange(0, i-1)] != NSNotFound)
9632 for (i = [base_extra_equipment
count]-1; i >= 0; i--)
9635 if ([ship_extra_equipment containsObject:eq_key])
9638 extra_equipment_value -= ([UNIVERSE getEquipmentPriceForKey:eq_key] / 10);
9644 for (i = [ship_extra_equipment
count]-1; i >= 0; i--)
9652 for (i = [ship_extra_equipment
count]-1; i >= 0; i--)
9653 extra_equipment_value += ([
UNIVERSE getEquipmentPriceForKey:[ship_extra_equipment oo_stringAtIndex:i]] / 10);
9656 extra_equipment_value *= extra_equipment_value < 0 ? 1.4 : 0.9;
9660 if ((
long long)scrap_value > (
long long)base_price + extra_equipment_value)
return scrap_value;
9662 return base_price + extra_equipment_value;
9666- (NSString *) brochureDescriptionWithDictionary:(NSDictionary *)dict standardEquipment:(NSArray *)extras optionalEquipment:(NSArray *)options
9668 NSMutableArray *mut_extras = [
NSMutableArray arrayWithArray:extras];
9669 NSString *allOptions = [
options componentsJoinedByString:@" "];
9671 NSMutableString *desc = [
NSMutableString stringWithFormat:@"The %@.", [
dict oo_stringForKey: KEY_NAME]];
9678 [
desc appendFormat:@" Cargo capacity %dt", max_cargo];
9679 BOOL canExpand = ([
allOptions rangeOfString:@"EQ_CARGO_BAY"].location != NSNotFound);
9681 [
desc appendFormat:@" (expandable to %dt at most starports)", max_cargo + extra_cargo];
9682 [
desc appendString:@"."];
9686 float top_speed = [
dict oo_intForKey:@"max_flight_speed"];
9687 [
desc appendFormat:@" Top speed %.3fLS.", 0.001 * top_speed];
9690 if ([mut_extras
count])
9692 unsigned n_berths = 0;
9696 NSString* item_key = [
mut_extras oo_stringAtIndex:i];
9697 if ([item_key isEqual:
@"EQ_PASSENGER_BERTH"])
9706 [
desc appendString:@" Includes luxury accomodation for a single passenger."];
9708 [
desc appendFormat:@" Includes luxury accomodation for %d passengers.", n_berths];
9713 if ([mut_extras
count])
9715 [
desc appendString:@"\nComes with"];
9719 NSString* item_key = [
mut_extras oo_stringAtIndex:i];
9720 NSString* item_desc =
nil;
9721 for (j = 0; ((j < [equipmentData count])&&(!item_desc)) ; j++)
9723 NSString *eq_type = [[equipmentData oo_arrayAtIndex:j] oo_stringAtIndex:EQUIPMENT_KEY_INDEX];
9724 if ([eq_type isEqual:item_key])
9725 item_desc = [[equipmentData oo_arrayAtIndex:j] oo_stringAtIndex:EQUIPMENT_SHORT_DESC_INDEX];
9729 switch ([mut_extras
count] - i)
9732 [
desc appendFormat:@" %@ fitted as standard.", item_desc];
9735 [
desc appendFormat:@" %@ and", item_desc];
9738 [
desc appendFormat:@" %@,", item_desc];
9746 if ([options
count])
9748 [
desc appendString:@"\nCan additionally be outfitted with"];
9750 for (i = 0; i < [
options count]; i++)
9752 NSString* item_key = [
options oo_stringAtIndex:i];
9753 NSString* item_desc =
nil;
9754 for (j = 0; ((j < [equipmentData count])&&(!item_desc)) ; j++)
9756 NSString *eq_type = [[equipmentData oo_arrayAtIndex:j] oo_stringAtIndex:EQUIPMENT_KEY_INDEX];
9757 if ([eq_type isEqual:item_key])
9758 item_desc = [[equipmentData oo_arrayAtIndex:j] oo_stringAtIndex:EQUIPMENT_SHORT_DESC_INDEX];
9762 switch ([options
count] - i)
9765 [
desc appendFormat:@" %@ at suitably equipped starports.", item_desc];
9768 [
desc appendFormat:@" %@ and/or", item_desc];
9771 [
desc appendFormat:@" %@,", item_desc];
9791 Quaternion q_result;
9801 quaternion_normalize(&q_result);
9823 v1.x -= v0.x; v1.y -= v0.y; v1.z -= v0.z;
9824 if (v1.x||v1.y||v1.z)
9825 v1 = HPvector_normal(v1);
9829 v1.x *= radius; v1.y *= radius; v1.z *= radius;
9830 v1.x += v0.x; v1.y += v0.y; v1.z += v0.z;
9852 v1.x -= v0.x; v1.y -= v0.y; v1.z -= v0.z;
9853 if (v1.x||v1.y||v1.z)
9854 v1 = HPvector_normal(v1);
9858 if (v2.x||v2.y||v2.z)
9859 v2 = HPvector_normal(v2);
9862 HPVector v3 = HPcross_product(v1, v2);
9863 if (v3.x||v3.y||v3.z)
9864 v3 = HPvector_normal(v3);
9868 v1.x *= radius; v1.y *= radius; v1.z *= radius;
9869 v1.x += v0.x; v1.y += v0.y; v1.z += v0.z;
9870 v1.x += 15000 * v3.x; v1.y += 15000 * v3.y; v1.z += 15000 * v3.z;
9871 v1.x -= v0.x; v1.y -= v0.y; v1.z -= v0.z;
9872 if (v1.x||v1.y||v1.z)
9873 v1 = HPvector_normal(v1);
9876 v1.x *= radius; v1.y *= radius; v1.z *= radius;
9877 v1.x += v0.x; v1.y += v0.y; v1.z += v0.z;
9883- (NSArray *) listBeaconsWithCode:(NSString *)code
9886 Entity <OOBeaconEntity> *beacon = [
self firstBeacon];
9888 while (beacon !=
nil)
9890 NSString *beaconCode = [
beacon beaconCode];
9891 if ([beaconCode rangeOfString:code options: NSCaseInsensitiveSearch].location != NSNotFound)
9893 [
result addObject:beacon];
9895 beacon = [
beacon nextBeacon];
9898 return [
result sortedArrayUsingSelector:@selector(compareBeaconCodeWith:)];
9902- (void) allShipsDoScriptEvent:(jsid)event andReactToAIMessage:(NSString *)message
9908 for (i = 0; i < ent_count; i++)
9916 for (i = 0; i < ship_count; i++)
9961- (void) setDisplayText:(BOOL) value
9973- (void) setDisplayFPS:(BOOL) value
9985- (void) setAutoSave:(BOOL) value
9988 [[
NSUserDefaults standardUserDefaults] setBool:autoSave forKey:@"autosave"];
9998- (void) setAutoSaveNow:(BOOL) value
10010- (void) setWireframeGraphics:(BOOL) value
10013 [[
NSUserDefaults standardUserDefaults] setBool:wireframeGraphics forKey:@"wireframe-graphics"];
10044 detailLevel = value;
10052 [[
NSUserDefaults standardUserDefaults] setInteger:detailLevel forKey:@"detailLevel"];
10075- (void) handleOoliteException:(NSException *)exception
10077 if (exception !=
nil)
10084 OOLog(
kOOLogException,
@"***** Handling Fatal : %@ : %@ *****",[exception name], [exception reason]);
10085 NSString* exception_msg = [
NSString stringWithFormat:@"Exception : %@ : %@ Please take a screenshot and/or press esc or Q to quit.", [
exception name], [
exception reason]];
10091 OOLog(
kOOLogException,
@"***** Handling Non-fatal : %@ : %@ *****",[exception name], [exception reason]);
10103- (void) setAirResistanceFactor:(GLfloat)newFactor
10112- (void) startSpeakingString:(NSString *) text
10114 [speechSynthesizer startSpeakingString:[
NSString stringWithFormat:@"[[volm %.3f]]%@", 0.3333333f * [
OOSound masterVolume], text]];
10122 [speechSynthesizer stopSpeakingAtBoundary:NSSpeechWordBoundary];
10126 [speechSynthesizer stopSpeaking];
10133 return [speechSynthesizer isSpeaking];
10138- (void) startSpeakingString:(NSString *) text
10140 NSData *utf8 = [text dataUsingEncoding:NSUTF8StringEncoding];
10144 const char *stringToSay = [text UTF8String];
10145 espeak_Synth(stringToSay, strlen(stringToSay) + 1 , 0, POS_CHARACTER, 0, espeakCHARS_UTF8 | espeakPHONEMES | espeakENDPAUSE, NULL, NULL);
10150- (void) stopSpeaking
10158 return espeak_IsPlaying();
10162- (NSString *) voiceName:(
unsigned int) index
10164 if (index >= espeak_voice_count)
10166 return [NSString stringWithCString: espeak_voices[index]->name];
10170- (
unsigned int) voiceNumber:(NSString *) name
10175 const char *
const label = [name UTF8String];
10179 unsigned int index = -1;
10180 while (espeak_voices[++index] && strcmp (espeak_voices[index]->name, label))
10182 return (index < espeak_voice_count) ? index : UINT_MAX;
10186- (
unsigned int) nextVoice:(
unsigned int) index
10188 if (++index >= espeak_voice_count)
10194- (
unsigned int) prevVoice:(
unsigned int) index
10196 if (--index >= espeak_voice_count)
10197 index = espeak_voice_count - 1;
10202- (
unsigned int) setVoice:(
unsigned int) index withGenderM:(BOOL) isMale
10204 if (index == UINT_MAX)
10205 index = [
self voiceNumber:DESC(@"espeak-default-voice")];
10207 if (index < espeak_voice_count)
10209 espeak_VOICE voice = { espeak_voices[index]->name, NULL, NULL, isMale ? 1 : 2 };
10210 espeak_SetVoiceByProperties (&voice);
10218- (void) startSpeakingString:(NSString *) text {}
10220- (void) stopSpeaking {}
10235- (void) setPauseMessageVisible:(BOOL)value
10247- (void) setPermanentMessageLog:(BOOL)value
10259- (void) setAutoMessageLogBg:(BOOL)value
10271- (void) setPermanentCommLog:(BOOL)value
10277- (void) setAutoCommLog:(BOOL)value
10289- (void) setBlockJSPlayerShipProps:(BOOL)value
10318 initWithPixelSize:NSMakeSize(480, 160)
10327 initWithPixelSize:NSMakeSize(360, 120)
10344#if OOLITE_SPEECH_SYNTH
10345 [speechArray autorelease];
10355 [characters autorelease];
10358 [customSounds autorelease];
10361 [globalSettings autorelease];
10368 [screenBackgrounds autorelease];
10372 [roleCategories autorelease];
10375 [autoAIMap autorelease];
10378 [equipmentData autorelease];
10379 [equipmentDataOutfitting autorelease];
10386 [explosionSettings autorelease];
10396 foreach (type, [commodities goods])
10401 [
tmp setObject:container forKey:type];
10405 cargoPods = [[
NSDictionary alloc] initWithDictionary:tmp];
10412 NSMutableArray *badEntities =
nil;
10416 for (i = 0; i < n_entities; i++)
10418 entity = sortedEntities[
i];
10419 if ([entity sessionID] != _sessionID)
10421 OOLogERR(
@"universe.sessionIDs.verify.failed",
@"Invalid entity %@ (came from session %lu, current session is %lu).", [entity shortDescription], [entity sessionID], _sessionID);
10427 foreach (entity, badEntities)
10436- (BOOL) reinitAndShowDemo:(BOOL) showDemo
10440 assert(player !=
nil);
10466 [PLAYER setSpeed:0.0];
10471 [missiontext autorelease];
10477 [demo_ships release];
10496 if (![player setUpAndConfirmOK:YES])
10559 activeWormholes = [[
NSMutableArray arrayWithCapacity:16] retain];
10561 characterPool = [[
NSMutableArray arrayWithCapacity:256] retain];
10578 [[
self currentSystemData] oo_boolForKey:@"stations_require_docking_clearance" defaultValue:YES]];
10592- (Vector) randomPlaceWithinScannerFrom:(Vector)pos alongRoute:(Vector)route withOffset:(
double)offset
10602- (HPVector) fractionalPositionFrom:(HPVector)point0 to:(HPVector)point1 withFraction:(
double)routeFraction
10604 if (routeFraction == NSNotFound) routeFraction =
randf();
10606 point1 = OOHPVectorInterpolate(point0, point1, routeFraction);
10619 if ([entity canCollide])
10621 doLinkedListMaintenanceThisUpdate = YES;
10639 if (sortedEntities[index] != entity)
10641 OOLog(
kOOLogInconsistentState,
@"DEBUG: Universe removeEntity:%@ ENTITY IS NOT IN THE RIGHT PLACE IN THE ZERO_DISTANCE SORTED LIST -- FIXING...", entity);
10644 for (i = 0; (i < n_entities)&&(index == -1); i++)
10645 if (sortedEntities[i] == entity)
10648 OOLog(
kOOLogInconsistentState,
@"DEBUG: Universe removeEntity:%@ ENTITY IS NOT IN THE ZERO_DISTANCE SORTED LIST -- CONTINUING...", entity);
10652 while ((
unsigned)index < n_entities)
10654 while (((
unsigned)index + n < n_entities)&&(sortedEntities[index + n] == entity))
10673 sortedEntities[
index] = sortedEntities[
index + n];
10674 if (sortedEntities[index])
10676 sortedEntities[
index]->zero_index = index;
10681 OOLog(
kOOLogInconsistentState,
@"DEBUG: Universe removeEntity: REMOVED %d EXTRA COPIES OF %@ FROM THE ZERO_DISTANCE SORTED LIST", n - 1, entity);
10692 if ([entities containsObject:entity])
10695 if ([entity isBreakPattern] && ![entity isVisualEffect])
10697 breakPatternCounter--;
10700 if ([entity isShip])
10705 if ([entity isWaypoint])
10710 if ([entity isVisualEffect])
10716 if ([entity isWormhole])
10720 else if ([entity isPlanet])
10735 if (![soundName hasPrefix:
@"["] && ![soundName hasSuffix:
@"]"])
10745 NSString *key =
nil;
10748 id object = [customSounds objectForKey:key];
10749 if([
object isKindOfClass:[NSString
class]])
10753 else if([
object isKindOfClass:[NSArray
class]] && [
object count] > 0)
10755 NSString *soundName =
nil;
10756 foreach (soundName,
object)
10758 if ([soundName isKindOfClass:[NSString
class]])
10773 NSAutoreleasePool *pool =
nil;
10775 while ([activeWormholes
count])
10783 if (![whole isScanned] &&
10784 NSEqualPoints([
PLAYER galaxy_coordinates], [whole destinationCoordinates]) )
10791 @catch (NSException *exception)
10793 OOLog(
kOOLogException,
@"Squashing exception during wormhole unpickling (%@: %@).", [exception name], [exception reason]);
10800- (NSString *)chooseStringForKey:(NSString *)key inDictionary:(NSDictionary *)dictionary
10803 if ([
object isKindOfClass:[NSString
class]])
return object;
10804 else if ([
object isKindOfClass:[NSArray
class]] && [
object count] > 0)
return [
object oo_stringAtIndex:Ranrot() % [
object count]];
10809#if OO_LOCALIZATION_TOOLS
10812- (void) dumpDebugGraphViz
10814 if ([[NSUserDefaults standardUserDefaults] boolForKey:
@"universe-dump-debug-graphviz"])
10816 [
self dumpSystemDescriptionGraphViz];
10821- (void) dumpSystemDescriptionGraphViz
10823 NSMutableString *graphViz =
nil;
10824 NSArray *systemDescriptions =
nil;
10825 NSArray *thisDesc =
nil;
10826 NSUInteger i,
count, j, subCount;
10827 NSString *descLine =
nil;
10828 NSArray *curses =
nil;
10829 NSString *label =
nil;
10830 NSDictionary *keyMap =
nil;
10836 graphViz = [NSMutableString stringWithString:
10837 @"// System description grammar:\n\n"
10838 "digraph system_descriptions\n"
10840 "\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"
10841 "\tedge [arrowhead=dot]\n"
10842 "\tnode [shape=none height=0.2 width=3 fontname=Helvetica]\n\t\n"];
10844 systemDescriptions = [[
self descriptions] oo_arrayForKey:@"system_description"];
10845 count = [systemDescriptions count];
10848 descLine =
DESC(
@"system-description-string");
10850 [graphViz appendFormat:@"\tsystem_description_string [label=\"%@\" shape=ellipse]\n", EscapedGraphVizString(label)];
10851 [
self addNumericRefsInString:descLine
10852 toGraphViz:graphViz
10853 fromNode:@"system_description_string"
10855 [graphViz appendString:@"\t\n"];
10858 [graphViz appendString:
10859 @"\tpercent_I [label=\"%I\\nInhabitants\" shape=diamond]\n"
10860 "\tpercent_H [label=\"%H\\nSystem name\" shape=diamond]\n"
10861 "\tpercent_RN [label=\"%R/%N\\nRandom name\" shape=diamond]\n"
10862 "\tpercent_J [label=\"%J\\nNumbered system name\" shape=diamond]\n"
10863 "\tpercent_G [label=\"%G\\nNumbered system name in chart number\" shape=diamond]\n\t\n"];
10866 [graphViz appendString:@"\tsubgraph cluster_thargoid_curses\n\t{\n\t\tlabel = \"Thargoid curses\"\n"];
10867 curses = [[
self descriptions] oo_arrayForKey:@"thargoid_curses"];
10868 subCount = [curses count];
10869 for (j = 0; j < subCount; ++j)
10872 [graphViz appendFormat:@"\t\tthargoid_curse_%lu [label=\"%@\"]\n", j, EscapedGraphVizString(label)];
10874 [graphViz appendString:@"\t}\n"];
10875 for (j = 0; j < subCount; ++j)
10877 [
self addNumericRefsInString:[curses oo_stringAtIndex:j]
10878 toGraphViz:graphViz
10879 fromNode:[NSString stringWithFormat:@"thargoid_curse_%lu", j]
10882 [graphViz appendString:@"\t\n"];
10886 for (i = 0; i <
count; ++i)
10889 label = [keyMap objectForKey:[NSString stringWithFormat:@"%lu", i]];
10890 if (label ==
nil) label = [NSString stringWithFormat:
@"[%lu]", i];
10891 else label = [NSString stringWithFormat:@"[%lu] (%@)", i, label];
10893 [graphViz appendFormat:@"\tsubgraph cluster_%lu\n\t{\n\t\tlabel=\"%@\"\n", i, EscapedGraphVizString(label)];
10895 thisDesc = [systemDescriptions oo_arrayAtIndex:i];
10896 subCount = [thisDesc count];
10897 for (j = 0; j < subCount; ++j)
10900 [graphViz appendFormat:@"\t\tn%lu_%lu [label=\"\\\"%@\\\"\"]\n", i, j, EscapedGraphVizString(label)];
10903 [graphViz appendString:@"\t}\n"];
10905 [graphViz appendString:@"\t\n"];
10908 for (i = 0; i !=
count; ++i)
10910 thisDesc = [systemDescriptions oo_arrayAtIndex:i];
10911 subCount = [thisDesc count];
10912 for (j = 0; j != subCount; ++j)
10914 descLine = [thisDesc oo_stringAtIndex:j];
10915 [
self addNumericRefsInString:descLine
10916 toGraphViz:graphViz
10917 fromNode:[NSString stringWithFormat:@"n%lu_%lu", i, j]
10923 [graphViz appendString:@"\t}\n"];
10929- (void) addNumericRefsInString:(NSString *)string toGraphViz:(NSMutableString *)graphViz fromNode:(NSString *)fromNode nodeCount:(NSUInteger)nodeCount
10931 NSString *index =
nil;
10932 NSInteger start, end;
10933 NSRange remaining, subRange;
10936 remaining = NSMakeRange(0, [
string length]);
10940 subRange = [
string rangeOfString:@"[" options:NSLiteralSearch range:remaining];
10941 if (subRange.location == NSNotFound)
break;
10942 start = subRange.location + subRange.length;
10943 remaining.length -= start - remaining.location;
10944 remaining.location = start;
10946 subRange = [
string rangeOfString:@"]" options:NSLiteralSearch range:remaining];
10947 if (subRange.location == NSNotFound)
break;
10948 end = subRange.location;
10949 remaining.length -= end - remaining.location;
10950 remaining.location = end;
10952 index = [
string substringWithRange:NSMakeRange(start, end - start)];
10953 i = [
index intValue];
10956 [
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];
10959 if ([
string rangeOfString:
@"%I"].location != NSNotFound)
10961 [
graphViz appendFormat:@"\t%@ -> percent_I [color=\"0,0,0.25\"]\n", fromNode];
10963 if ([
string rangeOfString:
@"%H"].location != NSNotFound)
10965 [
graphViz appendFormat:@"\t%@ -> percent_H [color=\"0,0,0.45\"]\n", fromNode];
10967 if ([
string rangeOfString:
@"%R"].location != NSNotFound || [
string rangeOfString:
@"%N"].location != NSNotFound)
10969 [
graphViz appendFormat:@"\t%@ -> percent_RN [color=\"0,0,0.65\"]\n", fromNode];
10973 if ([
string rangeOfString:
@"%J"].location != NSNotFound)
10975 [
graphViz appendFormat:@"\t%@ -> percent_J [color=\"0,0,0.75\"]\n", fromNode];
10978 if ([
string rangeOfString:
@"%G"].location != NSNotFound)
10980 [
graphViz appendFormat:@"\t%@ -> percent_G [color=\"0,0,0.85\"]\n", fromNode];
10988 NSArray *arguments =
nil;
10989 NSEnumerator *argEnum =
nil;
10990 NSString *arg =
nil;
10991 BOOL compileSysDesc = NO, exportSysDesc = NO, xml = NO;
10995 for (argEnum = [arguments objectEnumerator]; (arg = [
argEnum nextObject]); )
10997 if ([arg isEqual:
@"--compile-sysdesc"]) compileSysDesc = YES;
10998 else if ([arg isEqual:
@"--export-sysdesc"]) exportSysDesc = YES;
10999 else if ([arg isEqual:
@"--xml"]) xml = YES;
11000 else if ([arg isEqual:
@"--openstep"]) xml = NO;
11011- (void) prunePreloadingPlanetMaterials
11015 NSUInteger i = [_preloadingPlanetMaterials count];
11018 if ([[_preloadingPlanetMaterials objectAtIndex:i] isFinishedLoading])
11020 [_preloadingPlanetMaterials removeObjectAtIndex:i];
11030 [conditionScripts autorelease];
11041- (void) addConditionScripts:(NSEnumerator *)scripts
11043 NSString *scriptname =
nil;
11044 while ((scriptname = [scripts nextObject]))
11051 [conditionScripts setObject:script forKey:scriptname];
11060 return [conditionScripts objectForKey:scriptname];
11066@implementation OOSound (OOCustomSounds)
11068+ (id) soundWithCustomSoundKey:(NSString *)key
11070 NSString *fileName = [UNIVERSE soundNameForCustomSoundKey:key];
11071 if (fileName ==
nil)
return nil;
11076- (id) initWithCustomSoundKey:(NSString *)key
11085@implementation OOSoundSource (OOCustomSounds)
11087+ (id) sourceWithCustomSoundKey:(NSString *)key
11089 return [[[
self alloc] initWithCustomSoundKey:key] autorelease];
11093- (id) initWithCustomSoundKey:(NSString *)key
11096 if (theSound !=
nil)
11109- (void) playCustomSoundWithKey:(NSString *)key
11119 NSDictionary *one = (NSDictionary *)a;
11120 NSDictionary *two = (NSDictionary *)b;
11121 int pri_one = [one oo_intForKey:@"priority" defaultValue:100];
11122 int pri_two = [two oo_intForKey:@"priority" defaultValue:100];
11123 if (pri_one < pri_two)
return NSOrderedAscending;
11124 if (pri_one > pri_two)
return NSOrderedDescending;
11125 return NSOrderedSame;
11131 NSArray *one = (NSArray *)a;
11132 NSArray *two = (NSArray *)b;
11136 OOCreditsQuantity comp1 = [[one oo_dictionaryAtIndex:EQUIPMENT_EXTRA_INFO_INDEX] oo_unsignedLongLongForKey:@"sort_order" defaultValue:1000];
11137 OOCreditsQuantity comp2 = [[two oo_dictionaryAtIndex:EQUIPMENT_EXTRA_INFO_INDEX] oo_unsignedLongLongForKey:@"sort_order" defaultValue:1000];
11138 if (comp1 < comp2)
return NSOrderedAscending;
11139 if (comp1 > comp2)
return NSOrderedDescending;
11141 comp1 = [one oo_unsignedLongLongAtIndex:EQUIPMENT_TECH_LEVEL_INDEX];
11142 comp2 = [two oo_unsignedLongLongAtIndex:EQUIPMENT_TECH_LEVEL_INDEX];
11143 if (comp1 < comp2)
return NSOrderedAscending;
11144 if (comp1 > comp2)
return NSOrderedDescending;
11146 comp1 = [one oo_unsignedLongLongAtIndex:EQUIPMENT_PRICE_INDEX];
11147 comp2 = [two oo_unsignedLongLongAtIndex:EQUIPMENT_PRICE_INDEX];
11148 if (comp1 < comp2)
return NSOrderedAscending;
11149 if (comp1 > comp2)
return NSOrderedDescending;
11151 return NSOrderedSame;
11157 NSArray *one = (NSArray *)a;
11158 NSArray *two = (NSArray *)b;
11162 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]];
11163 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]];
11164 if (comp1 < comp2)
return NSOrderedAscending;
11165 if (comp1 > comp2)
return NSOrderedDescending;
11167 comp1 = [one oo_unsignedLongLongAtIndex:EQUIPMENT_TECH_LEVEL_INDEX];
11168 comp2 = [two oo_unsignedLongLongAtIndex:EQUIPMENT_TECH_LEVEL_INDEX];
11169 if (comp1 < comp2)
return NSOrderedAscending;
11170 if (comp1 > comp2)
return NSOrderedDescending;
11172 comp1 = [one oo_unsignedLongLongAtIndex:EQUIPMENT_PRICE_INDEX];
11173 comp2 = [two oo_unsignedLongLongAtIndex:EQUIPMENT_PRICE_INDEX];
11174 if (comp1 < comp2)
return NSOrderedAscending;
11175 if (comp1 > comp2)
return NSOrderedDescending;
11177 return NSOrderedSame;
11183 NSString *result = [UNIVERSE descriptionForKey:key];
11184 if (result ==
nil) result = key;
11192 NSArray *conditions = [[UNIVERSE descriptions] oo_arrayForKey:@"plural-rules"];
11195 NSString *tmp = [UNIVERSE descriptionForKey:key];
11198 static NSMutableSet *warned =
nil;
11200 if (![warned containsObject:tmp])
11202 OOLogWARN(
@"localization.plurals",
@"'%@' found in descriptions.plist, should be '%@%%0'. Localization data needs updating.",key,key);
11203 if (warned ==
nil) warned = [[NSMutableSet alloc] init];
11204 [warned addObject:tmp];
11208 if (conditions ==
nil)
11218 for (index = i = 0; i < [conditions count]; ++index, ++i)
11220 const char *cond = [[conditions oo_stringAtIndex:i] UTF8String];
11224 long int input =
count;
11227 while (isspace (*cond))
11232 while (isspace (*cond))
11235 char command = *cond++;
11247 long int param = strtol(cond, (
char **)&cond, 10);
11262 if (flag ^ (input == param))
11266 if (flag ^ (input != param))
11271 if (flag ^ (input < param))
11275 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