diff --git a/GNUmakefile b/GNUmakefile index 6b028808..3b873def 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -9,13 +9,13 @@ ifeq ($(GNUSTEP_HOST_OS),mingw32) ADDITIONAL_OBJC_LIBS = -lglu32 -lopengl32 -lmingw32 -lSDLmain -lSDL -lSDL_mixer -lSDL_image -lgnustep-base -ljs32 ADDITIONAL_CFLAGS = -DLINUX -DWIN32 -DNEED_STRLCPY `sdl-config --cflags` # note the vpath stuff above isn't working for me, so adding src/SDL and src/Core explicitly - ADDITIONAL_OBJCFLAGS = -DLOADSAVEGUI -DLINUX -DWIN32 -DXP_WIN -DHAVE_SOUND -Wno-import `sdl-config --cflags` -Isrc/SDL -Isrc/Core -Isrc/Core/JavaScript + ADDITIONAL_OBJCFLAGS = -DLOADSAVEGUI -DLINUX -DWIN32 -DXP_WIN -Wno-import `sdl-config --cflags` -Isrc/SDL -Isrc/Core -Isrc/Core/JavaScript oolite_LIB_DIRS += -L$(GNUSTEP_LOCAL_ROOT)/lib -Ldeps/Windows-x86-deps/lib else ADDITIONAL_INCLUDE_DIRS = -Isrc/SDL -Isrc/Core -Isrc/BSDCompat ADDITIONAL_OBJC_LIBS = -lGLU -lGL -lSDL -lpthread -lSDL_mixer -lSDL_image -lgnustep-base ADDITIONAL_CFLAGS = -DLINUX -DNEED_STRLCPY `sdl-config --cflags` - ADDITIONAL_OBJCFLAGS = -DLOADSAVEGUI -DLINUX -DHAVE_SOUND -Wno-import `sdl-config --cflags` + ADDITIONAL_OBJCFLAGS = -DLOADSAVEGUI -DLINUX -Wno-import `sdl-config --cflags` oolite_LIB_DIRS += -L/usr/X11R6/lib/ endif OBJC_PROGRAM_NAME = oolite diff --git a/Oolite.xcodeproj/project.pbxproj b/Oolite.xcodeproj/project.pbxproj index 9f7fb4a3..7b469390 100644 --- a/Oolite.xcodeproj/project.pbxproj +++ b/Oolite.xcodeproj/project.pbxproj @@ -730,7 +730,7 @@ 083325DC09DDBCDE00F5B8E4 /* OOColor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OOColor.m; sourceTree = ""; }; 083DB4D30A70E51E00B419B2 /* OOBrain.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OOBrain.h; sourceTree = ""; }; 083DB4D40A70E51E00B419B2 /* OOBrain.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OOBrain.m; sourceTree = ""; }; - 0865432206B8447D000CA0AB /* Oolite.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Oolite.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 0865432206B8447D000CA0AB /* OoliteDev.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = OoliteDev.app; sourceTree = BUILT_PRODUCTS_DIR; }; 0878FD2F086EF845004CB752 /* Carbon.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Carbon.framework; path = /System/Library/Frameworks/Carbon.framework; sourceTree = ""; }; 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = ""; }; 1A23154E0B9C778400EF0852 /* solar.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = solar.png; sourceTree = ""; }; @@ -1194,7 +1194,7 @@ 19C28FACFE9D520D11CA2CBB /* Products */ = { isa = PBXGroup; children = ( - 0865432206B8447D000CA0AB /* Oolite.app */, + 0865432206B8447D000CA0AB /* OoliteDev.app */, ); name = Products; sourceTree = ""; @@ -1987,7 +1987,7 @@ name = Oolite; productInstallPath = "$(HOME)/Applications"; productName = Oolite; - productReference = 0865432206B8447D000CA0AB /* Oolite.app */; + productReference = 0865432206B8447D000CA0AB /* OoliteDev.app */; productType = "com.apple.product-type.application"; }; /* End PBXNativeTarget section */ diff --git a/Resources/Config/logcontrol.plist b/Resources/Config/logcontrol.plist index e4289a03..216efe7f 100644 --- a/Resources/Config/logcontrol.plist +++ b/Resources/Config/logcontrol.plist @@ -124,6 +124,9 @@ mesh.load.error.tooManyVertices = inherit; mesh.load.error.tooManyFaces = inherit; +oxp.versionMismatch = $error; + + $plistError = $error; plist.parse.foundation.failed = $plistError; plist.wrongType = $plistError; @@ -199,6 +202,9 @@ script.debug.syntax.addShips = inherit; script.debug.syntax.set = inherit; script.debug.syntax.reset = inherit; +script.javascript.compile.success = inherit; +script.javascript.compile.failed = $scriptError; + searchPaths.dumpAll = $troubleShootingDump; @@ -249,3 +255,4 @@ sound.streaming.loop = $soundDebug; sound.streaming.underflow = $soundError; sound.virtualringbuffer = $soundError; sound.streaming.releaseContext = $soundDebug; +sound.invalidBeep = inherit; diff --git a/src/Cocoa/Groolite.m b/src/Cocoa/Groolite.m index da7356de..a4b2c628 100644 --- a/src/Cocoa/Groolite.m +++ b/src/Cocoa/Groolite.m @@ -68,7 +68,7 @@ static NSString * const kOOLogGrooliteDebug = @"growl.debug"; NSString *displayString; universe = [gameController universe]; - player = (PlayerEntity *)[universe entityZero]; + player = [PlayerEntity sharedPlayer]; if (!inTitle) return; // catch blank messages diff --git a/src/Cocoa/MyOpenGLView.m b/src/Cocoa/MyOpenGLView.m index 69e2100e..71ed1f34 100644 --- a/src/Cocoa/MyOpenGLView.m +++ b/src/Cocoa/MyOpenGLView.m @@ -49,8 +49,6 @@ static NSString * kOOLogKeyDown = @"input.keyMapping.keyPress.keyDown"; - (id) initWithFrame:(NSRect)frameRect { - //NSLog(@"-- initWithFrame MyOpenGLView"); - // Pixel Format Attributes for the View-based (non-FullScreen) NSOpenGLContext NSOpenGLPixelFormatAttribute attrs[] = { @@ -85,7 +83,6 @@ static NSString * kOOLogKeyDown = @"input.keyMapping.keyPress.keyDown"; // Just as a diagnostic, report the renderer ID that this pixel format binds to. CGLRenderers.h contains a list of known renderers // and their corresponding RendererID codes. [pixelFormat getValues:&rendererID forAttribute:NSOpenGLPFARendererID forVirtualScreen:0]; - //NSLog(@" init! NSOpenGLView pixelFormat RendererID = %08x", (unsigned)rendererID); self = [super initWithFrame:frameRect pixelFormat:pixelFormat]; @@ -137,7 +134,6 @@ static NSString * kOOLogKeyDown = @"input.keyMapping.keyPress.keyDown"; - (void) setTypedString:(NSString*) value { -// NSLog(@"DEBUG setTypedString:%@",value); [typedString setString:value]; } @@ -171,8 +167,6 @@ static NSString * kOOLogKeyDown = @"input.keyMapping.keyPress.keyDown"; { m_glContextInitialized = NO; viewSize = [self frame].size; - - //NSLog(@"DEBUG resized to %.0f x %.0f", viewSize.width, viewSize.height); } if (!m_glContextInitialized) @@ -300,7 +294,7 @@ static NSString * kOOLogKeyDown = @"input.keyMapping.keyPress.keyDown"; NSString *pathToPng = [[pathToPic stringByDeletingPathExtension] stringByAppendingPathExtension:@"png"]; - NSLog(@">>>>> Snapshot %d x %d file path chosen = %@", w, h, pathToPic); + NSLog(@"snapshot", @">>>>> Snapshot %d x %d file path chosen = %@", w, h, pathToPic); NSBitmapImageRep* bitmapRep = [[NSBitmapImageRep alloc] @@ -403,7 +397,6 @@ static NSString * kOOLogKeyDown = @"input.keyMapping.keyPress.keyDown"; isAlphabetKeyDown = YES; // convert to lowercase [typedString appendFormat:@"%c", (key | 64)]; - //NSLog(@"accumulated string '%@'",typedString); } else isAlphabetKeyDown = NO; @@ -423,7 +416,6 @@ static NSString * kOOLogKeyDown = @"input.keyMapping.keyPress.keyDown"; isAlphabetKeyDown = YES; // convert to lowercase [typedString appendFormat:@"%c", key]; - //NSLog(@"accumulated string '%@'",typedString); } else isAlphabetKeyDown = NO; @@ -473,8 +465,6 @@ static NSString * kOOLogKeyDown = @"input.keyMapping.keyPress.keyDown"; { doubleClick = (timeBetweenClicks < MOUSE_DOUBLE_CLICK_INTERVAL); // One fifth of a second keys[gvMouseDoubleClick] = doubleClick; -// if (doubleClick) -// NSLog(@"DEBUG registering a double-click!"); } keys[gvMouseLeftButton] = NO; // 'a' up diff --git a/src/Cocoa/OOCASound.h b/src/Cocoa/OOCASound.h index c9722a77..9a774b44 100644 --- a/src/Cocoa/OOCASound.h +++ b/src/Cocoa/OOCASound.h @@ -26,10 +26,6 @@ MA 02110-1301, USA. #import -#ifndef HAVE_SOUND -#define HAVE_SOUND -#endif - @interface OOSound: NSObject { diff --git a/src/Cocoa/OOCASoundInternal.h b/src/Cocoa/OOCASoundInternal.h index deb85c60..36d4a2fe 100644 --- a/src/Cocoa/OOCASoundInternal.h +++ b/src/Cocoa/OOCASoundInternal.h @@ -67,7 +67,7 @@ extern NSLock *gOOCASoundSyncLock; extern NSString * const kOOLogDeprecatedMethodOOCASound; extern NSString * const kOOLogSoundInitError; -#define kOOLogUnconvertedNSLog @"unclassified.sound" +#define kOOLogUnconvertedNSLog @"unclassified.OOCASound" #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4 diff --git a/src/Cocoa/VirtualRingBuffer.m b/src/Cocoa/VirtualRingBuffer.m index 07f6e915..95f946e6 100644 --- a/src/Cocoa/VirtualRingBuffer.m +++ b/src/Cocoa/VirtualRingBuffer.m @@ -22,7 +22,7 @@ #include -#define kOOLogUnconvertedNSLog @"sound.virtualringbuffer" +#define kOOLogUnconvertedNSLog @"unclassified.VirtualRingBuffer" @implementation VirtualRingBuffer diff --git a/src/Core/AI.m b/src/Core/AI.m index 8b16e290..d9525c03 100644 --- a/src/Core/AI.m +++ b/src/Core/AI.m @@ -29,6 +29,8 @@ MA 02110-1301, USA. #import "ShipEntity.h" +#define kOOLogUnconvertedNSLog @"unclassified.AI" + static NSString * const kOOLogAIReceiveMessage = @"ai.message.receive"; static NSString * const kOOLogAITakeAction = @"ai.takeAction.takeAction"; diff --git a/src/Core/CollisionRegion.m b/src/Core/CollisionRegion.m index 29a72851..4b9b65c1 100644 --- a/src/Core/CollisionRegion.m +++ b/src/Core/CollisionRegion.m @@ -31,6 +31,8 @@ MA 02110-1301, USA. #import "StationEntity.h" #import "PlayerEntity.h" +#define kOOLogUnconvertedNSLog @"unclassified.CollisionRegion" + @implementation CollisionRegion diff --git a/src/Core/DustEntity.m b/src/Core/DustEntity.m index 32bfc57b..17cc2b2f 100644 --- a/src/Core/DustEntity.m +++ b/src/Core/DustEntity.m @@ -50,8 +50,7 @@ MA 02110-1301, USA. vertices[vi].y = (ranrot_rand() % DUST_SCALE) - DUST_SCALE / 2; vertices[vi].z = (ranrot_rand() % DUST_SCALE) - DUST_SCALE / 2; } - //NSLog(@"DustEntity vertices set"); - // + dust_color = [[OOColor colorWithCalibratedRed:0.5 green:1.0 blue:1.0 alpha:1.0] retain]; // displayListName = 0; @@ -86,7 +85,7 @@ MA 02110-1301, USA. - (void) update:(double) delta_t { - PlayerEntity* player = (PlayerEntity*)[universe entityZero]; + PlayerEntity* player = [PlayerEntity sharedPlayer]; if (!player) return; // DON'T UPDATE // do nowt! zero_distance = 0.0; @@ -116,7 +115,7 @@ MA 02110-1301, USA. - (void) drawEntity:(BOOL) immediate :(BOOL) translucent { - PlayerEntity* player = (PlayerEntity*)[universe entityZero]; + PlayerEntity* player = [PlayerEntity sharedPlayer]; if (!player) return; // DON'T DRAW // diff --git a/src/Core/Entity.m b/src/Core/Entity.m index 16dffb6a..450a18c4 100644 --- a/src/Core/Entity.m +++ b/src/Core/Entity.m @@ -23,6 +23,7 @@ MA 02110-1301, USA. */ #import "Entity.h" +#import "PlayerEntity.h" #import "OOMaths.h" #import "Geometry.h" @@ -35,6 +36,8 @@ MA 02110-1301, USA. #import "NSScannerOOExtensions.h" +#define kOOLogUnconvertedNSLog @"unclassified.Entity" + static NSString * const kOOLogEntityAddToList = @"entity.linkedList.add"; static NSString * const kOOLogEntityAddToListError = @"entity.linkedList.add.error"; @@ -515,8 +518,7 @@ BOOL global_testForVAR; // collision_radius = [self findCollisionRadius]; actual_radius = collision_radius; - //NSLog(@"Entity with model '%@' collision radius set to %f",modelName, collision_radius); - // + [mypool release]; } - (NSString *) getModel @@ -540,7 +542,6 @@ BOOL global_testForVAR; - (double) getZeroDistance { -// NSLog(@"DEBUG %@ %.1f", self, zero_distance); return zero_distance; } @@ -821,7 +822,6 @@ BOOL global_testForVAR; else { OOLog(kOOLogFileNotLoaded, @"ERROR no basefile for entity %@"); - // NSBeep(); // appkit dependency } } glShadeModel(GL_SMOOTH); @@ -850,7 +850,6 @@ BOOL global_testForVAR; zero_distance = my_owner->zero_distance; if (zero_distance > no_draw_distance) { - //NSLog(@"DEBUG - sub entity '%@' too far away to draw", self); return; // TOO FAR AWAY } } @@ -896,8 +895,6 @@ BOOL global_testForVAR; #ifdef WIN32 int fi; - //NSLog(@"Entity::reloadTextures called on [%@]", [self description]); - // Force the entity to reload the textures for each face by clearing the face's texture name. for (fi = 0; fi < n_faces; fi++) faces[fi].texName = 0; @@ -931,7 +928,6 @@ BOOL global_testForVAR; if (!texture_name[ti]) { texture_name[ti] = [TextureStore getTextureNameFor: [NSString stringWithUTF8String: (char*)texture_file[ti]]]; -// NSLog(@"DEBUG (initialiseTextures) Processed textureFile : %@ to texName : %d", entityData[ti].textureFile, entityData[ti].texName); } } } @@ -958,7 +954,7 @@ BOOL global_testForVAR; - (void) update:(double) delta_t { - Entity* player = [universe entityZero]; + PlayerEntity *player = [PlayerEntity sharedPlayer]; if (player) { if (status != STATUS_COCKPIT_DISPLAY) @@ -1011,8 +1007,6 @@ BOOL global_testForVAR; // - (void) resetFramesFromFrame:(Frame) resetFrame withVelocity:(Vector) vel1 { - // if (isPlayer) NSLog(@"DEBUG ** resetting track for %@ **", self); - Vector v1 = make_vector( 0.1 * vel1.x, 0.1 * vel1.y, 0.1 * vel1.z); double t_now = [universe getTime]; Vector pos = resetFrame.position; @@ -1118,8 +1112,7 @@ BOOL global_testForVAR; double period = (moment_in_time - t_frame) - track_time; double f1 = -t_frame/period; double f0 = 1.0 - f1; -// NSLog(@"DEBUG m-i-t:%.3f track_time:%.3f t_frame:%.3f period:%.3f f0:f1 %.3f:%.3f", -// moment_in_time, track_time, t_frame, period, f0, f1); + Vector posn; posn.x = f0 * result.position.x + f1 * fr1.position.x; posn.y = f0 * result.position.y + f1 * fr1.position.y; @@ -1149,8 +1142,7 @@ BOOL global_testForVAR; double period = track[t0].timeframe - track[t1].timeframe; double f0 = (moment_in_time - track[t1].timeframe)/period; double f1 = 1.0 - f0; -// NSLog(@"DEBUG m-i-t:%.3f t0.timeframe:%.3f t1.timeframe:%.3f period:%.3f f0:f1 %.3f:%.3f", -// moment_in_time, track[t0].timeframe, track[t1].timeframe, period, f0, f1); + Vector posn; posn.x = f0 * track[t0].position.x + f1 * track[t1].position.x; posn.y = f0 * track[t0].position.y + f1 * track[t1].position.y; @@ -1264,8 +1256,6 @@ BOOL global_testForVAR; } data = [lines componentsJoinedByString:@"\n"]; - //NSLog(@"More data:\n%@",data); - scanner = [NSScanner scannerWithString:data]; // get number of vertices @@ -1470,7 +1460,6 @@ BOOL global_testForVAR; { // faces[j].textureFile = [texfile retain]; strlcpy( (char*)faces[j].textureFileStr255, [texfile UTF8String], 256); -// NSLog(@"DEBUG TEST strlcpy of '%@' result = '%s'", texfile, faces[j].textureFileStr255); } faces[j].texName = 0; @@ -1521,19 +1510,13 @@ BOOL global_testForVAR; if ((failFlag)&&([failString rangeOfString:@"TEXTURES"].location != NSNotFound)) { - //NSLog(@"Off to make new textures!"); [self fakeTexturesWithImageFile:@"metal.png" andMaxSize:NSMakeSize(256.0,256.0)]; - - // dump out data for ships with faked textures - //if (isShip) - // //NSLog(@"Faked Texture coordinates for this model :\n\n%@\n\n", [self toString]); } if (failFlag) NSLog([NSString stringWithFormat:@"%@ ..... from %@ %@", failString, filename, (using_preloaded)? @"(from preloaded data)" : @"(from file)"]); - // check for smooth chading and recalculate normals - // + // check for smooth shading and recalculate normals if (is_smooth_shaded) [self calculateVertexNormals]; // @@ -1560,6 +1543,8 @@ BOOL global_testForVAR; // } + +// FIXME: this isn't working, we're getting smoothed models with inside-out winding. --ahruman - (void) checkNormalsAndAdjustWinding { Vector calculatedNormal; @@ -1574,7 +1559,6 @@ BOOL global_testForVAR; calculatedNormal = normal_to_surface (v2, v1, v0); if ((norm.x == 0.0)&&(norm.y == 0.0)&&(norm.z == 0.0)) { - //NSLog(@"Using calculated normal for face %d", i); faces[i].normal = normal_to_surface (v0, v1, v2); norm = normal_to_surface (v0, v1, v2); } @@ -1586,10 +1570,6 @@ BOOL global_testForVAR; GLfloat s[faces[i].n_verts]; GLfloat t[faces[i].n_verts]; - // - //NSLog(@"Normal pointing the wrong way for winding on face %d", i); - // - for (j = 0; j < faces[i].n_verts; j++) { v[j] = faces[i].vertex[faces[i].n_verts - 1 - j]; @@ -1745,9 +1725,6 @@ BOOL global_testForVAR; } triangle_range[texi].length = tri_index - triangle_range[texi].location; -// NSLog(@"DEBUG processing %@ texture %@ texName %d triangles %d to %d", -// basefile, texture_file[texi], texture_name[texi], triangle_range[texi].location, triangle_range[texi].location + triangle_range[texi].length); - //finally... [texturesProcessed setObject:tex_string forKey:tex_string]; // note this texture done texi++; @@ -1832,7 +1809,6 @@ BOOL global_testForVAR; - (BoundingBox) findBoundingBoxRelativeToPosition:(Vector)opv InVectors:(Vector) _i :(Vector) _j :(Vector) _k { -// NSLog(@"DEBUG ** DEPRECATED [Entity findBoundingBoxRelativeToPosition:(Vector)opv InVectors:(Vector) _i :(Vector) _j :(Vector) _k] CALLED **"); Vector pv, rv; Vector rpos = position; @@ -1882,9 +1858,7 @@ BOOL global_testForVAR; result = [NSString stringWithFormat:@"%@\n", result]; } result = [NSString stringWithFormat:@"%@\nFACES\n", result]; - // - //NSLog(result); - // + for (j = 0; j < n_faces; j++) { r = (int)(faces[j].red * 255.0); g = (int)(faces[j].green * 255.0); b = (int)(faces[j].blue * 255.0); @@ -1970,15 +1944,11 @@ BOOL global_testForVAR; // st_width = max_s - min_s; st_height = max_t - min_t; - // - //NSLog(@"TOP st_width %f st_height %f maxSize.height %f maxSize.width %f", st_width, st_height, maxSize.width, maxSize.height); - // + for (j = 0; j < nf; j++) { i = fi[j]; - //fa[i] = faces[i]; -// fa[i].textureFile = [NSString stringWithFormat:@"top_%@", textureFile]; -// strlcpy( (char*)fa[i].textureFileStr255, [fa[i].textureFile UTF8String], 256); + strlcpy( (char*)fa[i].textureFileStr255, [[NSString stringWithFormat:@"top_%@", textureFile] UTF8String], 256); for (k = 0; k < faces[i].n_verts; k++) { @@ -1991,9 +1961,6 @@ BOOL global_testForVAR; // TESTING // fa[i].t[k] = maxSize.height - fa[i].t[k]; // REVERSE t locations - // - //NSLog(@"%f, %f", fa[i].s[k], fa[i].t[k]); - // } } @@ -2211,26 +2178,21 @@ BOOL global_testForVAR; fa[i].t[k] = (t - min_t) * maxSize.height / st_height; } } - //NSLog(@"%d / %d faces matched at tolerance: %f", n_faces - faces_to_match, n_faces, tolerance); } for (i = 0; i < n_faces; i++) { NSString *result; -// faces[i].textureFile = [fa[i].textureFile retain]; + strlcpy( (char*)faces[i].textureFileStr255, (char*)fa[i].textureFileStr255, 256); faces[i].texName = 0; for (j = 0; j < faces[i].n_verts; j++) { - // - //NSLog(@"face[%d] %f, %f", i, fa[i].s[j], fa[i].t[j]); - // faces[i].s[j] = fa[i].s[j] / maxSize.width; faces[i].t[j] = fa[i].t[j] / maxSize.height; } -// result = [NSString stringWithFormat:@"%@\t%d %d", faces[i].textureFile, (int)maxSize.width, (int)maxSize.height]; + result = [NSString stringWithFormat:@"%s\t%d %d", faces[i].textureFileStr255, (int)maxSize.width, (int)maxSize.height]; - //NSLog(@"face[%d] : %@", i, result); } } diff --git a/src/Core/GameController.m b/src/Core/GameController.m index 898b1cb0..14b33611 100644 --- a/src/Core/GameController.m +++ b/src/Core/GameController.m @@ -31,16 +31,17 @@ MA 02110-1301, USA. #import "OOOpenGL.h" #import "PlayerEntity.h" +#define kOOLogUnconvertedNSLog @"unclassified.GameController" + + @implementation GameController - (id) init { self = [super init]; - // - //NSLog(@"--- init GameController"); - // - last_timeInterval = [NSDate timeIntervalSinceReferenceDate]; - delta_t = 0.01; // one hundredth of a second + + last_timeInterval = [NSDate timeIntervalSinceReferenceDate]; + delta_t = 0.01; // one hundredth of a second // my_mouse_x = my_mouse_y = 0; // @@ -49,13 +50,10 @@ MA 02110-1301, USA. expansionPathsToInclude = nil; pauseSelector = (SEL)nil; pauseTarget = nil; - // game_is_paused = NO; - // debug = 0; -// debug = DEBUG_COLLISIONS; - // + return self; } @@ -65,14 +63,14 @@ MA 02110-1301, USA. [[[NSWorkspace sharedWorkspace] notificationCenter] removeObserver:universe]; #endif // - if (timer) [timer release]; - if (gameView) [gameView release]; - if (universe) [universe release]; - // - if (playerFileToLoad) [playerFileToLoad release]; - if (playerFileDirectory) [playerFileDirectory release]; - if (expansionPathsToInclude) [expansionPathsToInclude release]; - // + [timer release]; + [gameView release]; + [universe release]; + + [playerFileToLoad release]; + [playerFileDirectory release]; + [expansionPathsToInclude release]; + [super dealloc]; } @@ -96,7 +94,6 @@ MA 02110-1301, USA. NSDictionary *d_mode = [self findDisplayModeForWidth: d_width Height: d_height Refresh: d_refresh]; if (d_mode) { - // do stuff width = d_width; height = d_height; refresh = d_refresh; @@ -121,8 +118,6 @@ MA 02110-1301, USA. { NSDictionary *mode; - //NSLog(@"looking for a display mode that's %d x %d %dHz",width, height, refresh); - mode = [self findDisplayModeForWidth: width Height: height Refresh: refresh]; if (mode == nil) return NSNotFound; @@ -149,7 +144,6 @@ MA 02110-1301, USA. modeRefresh = [[mode objectForKey: (NSString *)kCGDisplayRefreshRate] intValue]; if ((modeWidth == d_width)&&(modeHeight == d_height)&&(modeRefresh == d_refresh)) { -// NSLog(@"Found mode %@", mode); return mode; } } @@ -256,8 +250,7 @@ static int _compareModes(id arg1, id arg2, void *context) // Fill the popup with the resulting modes modeCount = [displayModes count]; - - //NSLog(@"displayModes = %@", displayModes); + int i; for (i = 0; i < modeCount; i++) { @@ -265,7 +258,6 @@ static int _compareModes(id arg1, id arg2, void *context) modeWidth = [[mode objectForKey: (NSString *)kCGDisplayWidth] intValue]; modeHeight = [[mode objectForKey: (NSString *)kCGDisplayHeight] intValue]; modeRefresh = [[mode objectForKey: (NSString *)kCGDisplayRefreshRate] intValue]; - //NSLog(@"()=> %d x %d at %dHz", modeWidth, modeHeight, modeRefresh); } #else // ifndef GNUSTEP // SDL code all lives in the gameview. @@ -378,9 +370,7 @@ static int _compareModes(id arg1, id arg2, void *context) width = 640; // standard screen is 640x480 pixels, 32 bit color, 32 bit z-buffer, refresh rate 75Hz height = 480; refresh = 75; - // - //NSLog(@"--- loading userdefaults"); - // + NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; // if ([userDefaults objectForKey:@"display_width"]) @@ -447,7 +437,7 @@ static int _compareModes(id arg1, id arg2, void *context) { if (playerFileToLoad) { - PlayerEntity *player = [universe entityZero]; + PlayerEntity *player = [PlayerEntity sharedPlayer]; [player loadPlayerFromFile:playerFileToLoad]; [player setStatus:STATUS_DOCKED]; [player setGuiToStatusScreen]; @@ -465,10 +455,9 @@ static int _compareModes(id arg1, id arg2, void *context) - (void) logProgress:(NSString*) message { -// NSLog(@"progress: %@", message); #ifndef GNUSTEP [splashProgressTextField setStringValue:message]; - [splashProgressTextField display]; // **thanks Jens Ayton ** + [splashProgressTextField display]; #endif } @@ -585,7 +574,6 @@ static int _compareModes(id arg1, id arg2, void *context) } originalDisplayMode = (NSDictionary *)CGDisplayCurrentMode(kCGDirectMainDisplay); - //NSLog(@"originalDisplayMode = %@", originalDisplayMode); // Pixel Format Attributes for the FullScreen NSOpenGLContext NSOpenGLPixelFormatAttribute attrs[] = { @@ -620,7 +608,6 @@ static int _compareModes(id arg1, id arg2, void *context) // Just as a diagnostic, report the renderer ID that this pixel format binds to. CGLRenderers.h contains a list of known renderers and their corresponding RendererID codes. [pixelFormat getValues:&rendererID forAttribute:NSOpenGLPFARendererID forVirtualScreen:0]; - //NSLog(@"FullScreen pixelFormat RendererID = %08x", (unsigned)rendererID); // Create an NSOpenGLContext with the FullScreen pixel format. By specifying the non-FullScreen context as our "shareContext", we automatically inherit all of the textures, display lists, and other OpenGL objects it has defined. fullScreenContext = [[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:[gameView openGLContext]]; @@ -716,9 +703,8 @@ static int _compareModes(id arg1, id arg2, void *context) my_mouse_x += mouse_dx; my_mouse_y += mouse_dy; } - else - past_first_mouse_delta =YES; - //NSLog(@".. %d, %d ..",my_mouse_x, my_mouse_y); + else past_first_mouse_delta =YES; + [gameView setVirtualJoystick:(double)my_mouse_x/width :(double)my_mouse_y/height]; CGDisplayMoveCursorToPoint(kCGDirectMainDisplay,centerOfScreen); break; @@ -800,7 +786,6 @@ static int _compareModes(id arg1, id arg2, void *context) - (void) exitFullScreenMode { - //NSLog(@"in gameController exitFullScreenMode"); stayInFullScreenMode = NO; } @@ -840,7 +825,6 @@ static int _compareModes(id arg1, id arg2, void *context) - (void)windowDidResize:(NSNotification *)aNotification { -// NSLog(@"Mwahhahaha"); [gameView drawRect:[gameView bounds]]; } @@ -860,7 +844,6 @@ static int _compareModes(id arg1, id arg2, void *context) [[NSFileManager defaultManager] fileExistsAtPath:filename isDirectory:&dir_test]; if (dir_test) { -// NSLog(@"Including expansion pack : %@", filename); if (!expansionPathsToInclude) expansionPathsToInclude = [[NSMutableArray alloc] initWithCapacity: 4]; // retained [expansionPathsToInclude addObject: filename]; diff --git a/src/Core/Geometry.m b/src/Core/Geometry.m index 92b9a26a..79d6c98b 100644 --- a/src/Core/Geometry.m +++ b/src/Core/Geometry.m @@ -95,7 +95,7 @@ MA 02110-1301, USA. if (!new_triangles) // couldn't allocate space { - NSLog(@" --- ran out of memory to allocate more geometry!"); + OOLog(kOOLogAllocationFailure, @" --- ran out of memory to allocate more geometry!"); exit(-1); } @@ -206,8 +206,6 @@ static float volumecount; // NSObject* foundOctree = [self octreeWithinRadius:foundRadius toDepth:depth]; // -// NSLog(@"octree found has %d leafs - object has volume %.2f mass %.2f", leafcount, volumecount, volumecount * 8.0); - // Octree* octreeRepresentation = [[Octree alloc] initWithRepresentationOfOctree:foundRadius :foundOctree :leafcount]; // return [octreeRepresentation autorelease]; diff --git a/src/Core/GuiDisplayGen.m b/src/Core/GuiDisplayGen.m index 5caf0078..918e895e 100644 --- a/src/Core/GuiDisplayGen.m +++ b/src/Core/GuiDisplayGen.m @@ -194,7 +194,7 @@ MA 02110-1301, USA. pixel_text_size = NSMakeSize( csize, csize); pixel_title_size = NSMakeSize( csize * 1.75, csize * 1.5); - NSLog(@"gui %@ reset to rows:%d columns:%d start:%d", self, n_rows, n_columns, pixel_row_start); + OOLog(@"gui.reset", @"gui %@ reset to rows:%d columns:%d start:%d", self, n_rows, n_columns, pixel_row_start); rowRange = NSMakeRange(0,n_rows); [self clear]; @@ -298,11 +298,8 @@ MA 02110-1301, USA. - (void) click { -#ifdef HAVE_SOUND - if ([guiclick isPlaying]) - [guiclick stop]; + if ([guiclick isPlaying]) [guiclick stop]; [guiclick play]; -#endif } - (void)setShowAdvancedNavArray:(BOOL)inFlag @@ -532,8 +529,6 @@ MA 02110-1301, USA. - (void) printLongText: (NSString *) str Align:(int) alignment Color:(OOColor*) text_color FadeTime:(float) text_fade Key:(NSString*) text_key AddToArray:(NSMutableArray*) text_array { -// NSLog(@"GUI printing text '%@'", str); - // print a multi-line message // if ([str rangeOfString:@"\n"].location != NSNotFound) @@ -716,7 +711,7 @@ MA 02110-1301, USA. GLfloat z1 = [[universe gameView] display_z]; if (alpha > 0.05) { - PlayerEntity* player = (PlayerEntity*)[universe entityZero]; + PlayerEntity* player = [PlayerEntity sharedPlayer]; [self drawGLDisplay: drawPosition.x - 0.5 * size_in_pixels.width :drawPosition.y - 0.5 * size_in_pixels.height :z1 :alpha forUniverse:universe]; @@ -787,7 +782,7 @@ MA 02110-1301, USA. if (alpha > 0.05) { - PlayerEntity* player = (PlayerEntity*)[universe entityZero]; + PlayerEntity* player = [PlayerEntity sharedPlayer]; [self drawGLDisplay:x - 0.5 * size_in_pixels.width :y - 0.5 * size_in_pixels.height :z :alpha forUniverse:universe]; @@ -856,7 +851,7 @@ MA 02110-1301, USA. if (alpha < 0.05) return; // too dim to see! - PlayerEntity* player = (PlayerEntity*)[universe entityZero]; + PlayerEntity* player = [PlayerEntity sharedPlayer]; [self drawGLDisplay:x - 0.5 * size_in_pixels.width :y - 0.5 * size_in_pixels.height :z :alpha forUniverse:universe]; @@ -1047,7 +1042,7 @@ MA 02110-1301, USA. - (void) drawStarChart:(GLfloat)x :(GLfloat)y :(GLfloat)z :(GLfloat) alpha forUniverse:(Universe*)universe { - PlayerEntity* player = (PlayerEntity*)[universe entityZero]; + PlayerEntity* player = [PlayerEntity sharedPlayer]; if (!player) return; @@ -1182,7 +1177,7 @@ MA 02110-1301, USA. - (void) drawGalaxyChart:(GLfloat)x :(GLfloat)y :(GLfloat)z :(GLfloat) alpha forUniverse:(Universe*)universe { - PlayerEntity* player = (PlayerEntity*)[universe entityZero]; + PlayerEntity* player = [PlayerEntity sharedPlayer]; NSPoint galaxy_coordinates = [player galaxy_coordinates]; NSPoint cursor_coordinates = [player cursor_coordinates]; @@ -1322,7 +1317,7 @@ MA 02110-1301, USA. // Advanced Navigation Array -- galactic chart route mapping - contributed by Nikos Barkas (another_commander). - (void) drawAdvancedNavArrayAtX:(float)x y:(float)y z:(float)z alpha:(float)alpha forUniverse:(Universe*)universe; { - PlayerEntity *player = (PlayerEntity*)[universe entityZero]; + PlayerEntity *player = [PlayerEntity sharedPlayer]; NSPoint galaxy_coordinates = [player galaxy_coordinates]; NSPoint cursor_coordinates = [player cursor_coordinates]; Random_Seed galaxy_seed = [player galaxy_seed]; diff --git a/src/Core/HeadUpDisplay.m b/src/Core/HeadUpDisplay.m index a316c882..52bb14a6 100644 --- a/src/Core/HeadUpDisplay.m +++ b/src/Core/HeadUpDisplay.m @@ -33,6 +33,8 @@ MA 02110-1301, USA. #import "OOColor.h" #import "GuiDisplayGen.h" +#define kOOLogUnconvertedNSLog @"unclassified.HeadUpDisplay" + static const char *toAscii(unsigned inCodePoint); @implementation HeadUpDisplay @@ -83,8 +85,6 @@ float char_widths[128] = { } if (!areTrumblesToBeDrawn) // naughty - a hud with no built-in drawTrumbles: - one must be added! { -// NSLog(@"DEBUG // naughty - a hud with no built-in drawTrumbles: - one must be added!"); - // NSDictionary* trumble_dial_info = [NSDictionary dictionaryWithObjectsAndKeys: @"drawTrumbles:", SELECTOR_KEY, nil]; [self addDial: trumble_dial_info]; } @@ -240,12 +240,8 @@ GLuint ascii_texture_name; { if ([info objectForKey:SELECTOR_KEY]) { - //NSLog(@"DEBUG adding Dial for %@",[info objectForKey:SELECTOR_KEY]); SEL _selector = NSSelectorFromString((NSString *)[info objectForKey:SELECTOR_KEY]); - if ([self respondsToSelector:_selector]) - [dialArray addObject:info]; - //else - // NSLog(@"DEBUG HeadUpDisplay does not respond to '%@'",[info objectForKey:SELECTOR_KEY]); + if ([self respondsToSelector:_selector]) [dialArray addObject:info]; } } @@ -262,6 +258,8 @@ checkGLErrors(@"HeadUpDisplay after drawLegends"); // } + +// SLOW_CODE - HUD drawing is taking up a ridiculous 30%-40% of frame time. Much of this seems to be spent in string processing. String caching is needed. -- ahruman - (void) drawDials { int i; @@ -306,7 +304,6 @@ checkGLErrors(@"HeadUpDisplay after drawDials"); if ([info objectForKey:SELECTOR_KEY]) { - //NSLog(@"DEBUG about to '%@'",[info objectForKey:SELECTOR_KEY]); SEL _selector = NSSelectorFromString((NSString *)[info objectForKey:SELECTOR_KEY]); if ([self respondsToSelector:_selector]) [self performSelector:_selector withObject:info]; @@ -622,7 +619,6 @@ static BOOL hostiles; if ((lt == nil)||(!(lt->isShip))) return; ShipEntity* st = (ShipEntity*)lt; -// NSLog(@"DEBUG Last Transmitter (%d) == %@ %d", last_transmitter, [st name], [st universal_id]); if ([st message_time] <= 0.0) [st setMessage_time:2.5]; } @@ -2070,8 +2066,6 @@ void hudDrawReticleOnTarget(Entity* target, PlayerEntity* player1, GLfloat z1) glVertex2f(-rs0,-rs2); glVertex2f(-rs0,-rs0); glVertex2f(-rs0,-rs0); glVertex2f(-rs2,-rs0); -// NSLog(@"DEBUG rs0 %.3f %.3f",rs0, rs2); - glEnd(); // add text for reticle here @@ -2114,7 +2108,6 @@ void drawString(NSString *text, double x, double y, double z, NSSize siz) char simple[2] = {0, 0}; unsigned ch, next, length; -// NSLog(@"DEBUG drawing string (%@) at %.1f, %.1f, %.1f (%.1f x %.1f)", text, x, y, z, siz.width, siz.height); glEnable(GL_TEXTURE_2D); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glBindTexture(GL_TEXTURE_2D, ascii_texture_name); diff --git a/src/Core/JavaScript/JSUniverse.h b/src/Core/JavaScript/JSUniverse.h index 427917a8..fd9a3b16 100644 --- a/src/Core/JavaScript/JSUniverse.h +++ b/src/Core/JavaScript/JSUniverse.h @@ -44,9 +44,9 @@ JSFunctionSpec Universe_funcs[] = { JSBool UniverseCheckForShips(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { if (argc == 1) { - // PlayerEntity *playerEntity = (PlayerEntity *)[scriptedUniverse entityZero]; + // PlayerEntity *playerEntity = [PlayerEntity sharedPlayer]; NSString *role = JSValToNSString(cx, argv[0]); - int num = [scriptedUniverse countShipsWithRole:role]; + int num = [[Universe sharedUniverse] countShipsWithRole:role]; *rval = INT_TO_JSVAL(num); } return JS_TRUE; @@ -54,12 +54,12 @@ JSBool UniverseCheckForShips(JSContext *cx, JSObject *obj, uintN argc, jsval *ar JSBool UniverseAddShips(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { if (argc == 2) { - // PlayerEntity *playerEntity = (PlayerEntity *)[scriptedUniverse entityZero]; + // PlayerEntity *playerEntity = [PlayerEntity sharedPlayer]; NSString *role = JSValToNSString(cx, argv[0]); int num = JSVAL_TO_INT(argv[1]); while (num--) - [scriptedUniverse witchspaceShipWithRole:role]; + [[Universe sharedUniverse] witchspaceShipWithRole:role]; } return JS_TRUE; } @@ -67,12 +67,12 @@ JSBool UniverseAddShips(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, j JSBool UniverseAddSystemShips(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { if (argc == 3) { jsdouble posn; - // PlayerEntity *playerEntity = (PlayerEntity *)[scriptedUniverse entityZero]; + // PlayerEntity *playerEntity = [PlayerEntity sharedPlayer]; NSString *role = JSValToNSString(cx, argv[0]); int num = JSVAL_TO_INT(argv[1]); JS_ValueToNumber(cx, argv[2], &posn); while (num--) - [scriptedUniverse addShipWithRole:role nearRouteOneAt:posn]; + [[Universe sharedUniverse] addShipWithRole:role nearRouteOneAt:posn]; } return JS_TRUE; } @@ -80,7 +80,7 @@ JSBool UniverseAddSystemShips(JSContext *cx, JSObject *obj, uintN argc, jsval *a JSBool UniverseAddShipsAt(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { if (argc == 6) { jsdouble x, y, z; - PlayerEntity *playerEntity = (PlayerEntity *)[scriptedUniverse entityZero]; + PlayerEntity *playerEntity = [PlayerEntity sharedPlayer]; NSString *role = JSValToNSString(cx, argv[0]); int num = JSVAL_TO_INT(argv[1]); NSString *coordScheme = JSValToNSString(cx, argv[2]); @@ -96,7 +96,7 @@ JSBool UniverseAddShipsAt(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, JSBool UniverseAddShipsAtPrecisely(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { if (argc == 6) { jsdouble x, y, z; - PlayerEntity *playerEntity = (PlayerEntity *)[scriptedUniverse entityZero]; + PlayerEntity *playerEntity = [PlayerEntity sharedPlayer]; NSString *role = JSValToNSString(cx, argv[0]); int num = JSVAL_TO_INT(argv[1]); NSString *coordScheme = JSValToNSString(cx, argv[2]); @@ -112,7 +112,7 @@ JSBool UniverseAddShipsAtPrecisely(JSContext *cx, JSObject *obj, uintN argc, jsv JSBool UniverseAddShipsWithinRadius(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { if (argc == 7) { jsdouble x, y, z; - PlayerEntity *playerEntity = (PlayerEntity *)[scriptedUniverse entityZero]; + PlayerEntity *playerEntity = [PlayerEntity sharedPlayer]; NSString *role = JSValToNSString(cx, argv[0]); int num = JSVAL_TO_INT(argv[1]); NSString *coordScheme = JSValToNSString(cx, argv[2]); @@ -128,7 +128,7 @@ JSBool UniverseAddShipsWithinRadius(JSContext *cx, JSObject *obj, uintN argc, js JSBool UniverseSpawn(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { if (argc == 2) { - PlayerEntity *playerEntity = (PlayerEntity *)[scriptedUniverse entityZero]; + PlayerEntity *playerEntity = [PlayerEntity sharedPlayer]; NSString *role = JSValToNSString(cx, argv[0]); int num = JSVAL_TO_INT(argv[1]); NSString *arg = [NSString stringWithFormat:@"%@ %d", role, num]; @@ -139,7 +139,7 @@ JSBool UniverseSpawn(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsva JSBool UniverseSpawnShip(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { if (argc == 1) { - PlayerEntity *playerEntity = (PlayerEntity *)[scriptedUniverse entityZero]; + PlayerEntity *playerEntity = [PlayerEntity sharedPlayer]; [playerEntity spawnShip:JSValToNSString(cx, argv[0])]; } return JS_TRUE; @@ -154,7 +154,7 @@ JSBool UniverseAddMessage(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, ok = JS_ValueToInt32(cx, argv[1], &count); NSString *str = JSValToNSString(cx, argv[0]); - [scriptedUniverse addMessage: str forCount:(int)count]; + [[Universe sharedUniverse] addMessage: str forCount:(int)count]; //[str dealloc]; return JS_TRUE; } @@ -167,7 +167,7 @@ JSBool UniverseAddCommsMessage(JSContext *cx, JSObject *obj, uintN argc, jsval * ok = JS_ValueToInt32(cx, argv[1], &count); NSString *str = JSValToNSString(cx, argv[0]); - [scriptedUniverse addCommsMessage: str forCount:(int)count]; + [[Universe sharedUniverse] addCommsMessage: str forCount:(int)count]; //[str dealloc]; return JS_TRUE; } @@ -175,7 +175,7 @@ JSBool UniverseAddCommsMessage(JSContext *cx, JSObject *obj, uintN argc, jsval * /* JSBool UniverseGetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) { if (JSVAL_IS_INT(id)) { - PlayerEntity *playerEntity = (PlayerEntity *)[scriptedUniverse entityZero]; + PlayerEntity *playerEntity = [PlayerEntity sharedPlayer]; switch (JSVAL_TO_INT(id)) { case UNI_PLAYER_ENTITY: { diff --git a/src/Core/JavaScript/OXPScript.m b/src/Core/JavaScript/OXPScript.m index 661dca7e..61d8da6f 100644 --- a/src/Core/JavaScript/OXPScript.m +++ b/src/Core/JavaScript/OXPScript.m @@ -23,6 +23,8 @@ MA 02110-1301, USA. */ #import "OXPScript.h" +#import "OOLogging.h" + OXPScript *currentOXPScript; @@ -42,8 +44,7 @@ extern NSString *JSValToNSString(JSContext *cx, jsval val); // ... self = [super init]; - - //NSLog(@"Attempting to load script: %@", filename); + obj = JS_NewObject(context, &OXP_class, 0x00, JS_GetGlobalObject(context)); JS_AddRoot(context, &obj); // note 2nd arg is a pointer-to-pointer @@ -52,35 +53,29 @@ extern NSString *JSValToNSString(JSContext *cx, jsval val); jsval rval; JSBool ok; JSScript *script = JS_CompileFile(context, obj, [filename cString]); - if (script != 0x00) { + if (script != NULL) { ok = JS_ExecuteScript(context, obj, script, &rval); if (ok) { ok = JS_GetProperty(context, obj, "Name", &rval); if (ok) { name = JSValToNSString(context, rval); - //NSLog(@"Found name property: %@", name); } else { // No name given in the script so use the filename name = [NSString stringWithString:filename]; - //NSLog(@"No name property, defaulting to : %@", name); } ok = JS_GetProperty(context, obj, "Description", &rval); if (ok) { description = JSValToNSString(context, rval); - //NSLog(@"Found description : %@", description); } else { description = @""; - //NSLog(@"No description"); } ok = JS_GetProperty(context, obj, "Version", &rval); if (ok) { version = JSValToNSString(context, rval); - //NSLog(@"Found version: %@", version); } else { version= @""; - //NSLog(@"No version"); } - NSLog(@"Loaded JavaScript OXP: %@ %@ %@", name, description, version); + OOLog(@"script.javascript.compile.success", @"Loaded JavaScript OXP: %@ %@ %@", name, description, version); /* * Example code to read the mission variables. @@ -111,8 +106,8 @@ extern NSString *JSValToNSString(JSContext *cx, jsval val); } JS_DestroyScript(context, script); } else { - NSLog(@"Script compilation failed"); - [super dealloc]; + OOLog(@"script.javascript.compile.failed", @"Script compilation failed"); + [self release]; return nil; } diff --git a/src/Core/JavaScript/ScriptEngine.m b/src/Core/JavaScript/ScriptEngine.m index 1b717988..5571cddc 100644 --- a/src/Core/JavaScript/ScriptEngine.m +++ b/src/Core/JavaScript/ScriptEngine.m @@ -28,7 +28,9 @@ MA 02110-1301, USA. #include #include -Universe *scriptedUniverse; +#define kOOLogUnconvertedNSLog @"unclassified.JSScriptEngine" + + JSObject *xglob, *universeObj, *systemObj, *playerObj, *missionObj; extern OXPScript *currentOXPScript; @@ -66,7 +68,7 @@ JSClass MissionVars_class = { }; JSBool MissionVarsGetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) { - PlayerEntity *playerEntity = (PlayerEntity *)[scriptedUniverse entityZero]; + PlayerEntity *playerEntity = [PlayerEntity sharedPlayer]; NSDictionary *mission_variables = [playerEntity mission_variables]; if (JSVAL_IS_STRING(id)) { @@ -104,7 +106,7 @@ JSBool MissionVarsGetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) } JSBool MissionVarsSetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) { - PlayerEntity *playerEntity = (PlayerEntity *)[scriptedUniverse entityZero]; + PlayerEntity *playerEntity = [PlayerEntity sharedPlayer]; NSDictionary *mission_variables = [playerEntity mission_variables]; if (JSVAL_IS_STRING(id)) { @@ -156,7 +158,7 @@ JSFunctionSpec Global_funcs[] = { JSBool GlobalListenForKey(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { NSString *key = JSValToNSString(cx, argv[0]); - PlayerEntity *playerEntity = (PlayerEntity *)[scriptedUniverse entityZero]; + PlayerEntity *playerEntity = [PlayerEntity sharedPlayer]; [playerEntity mapKey:key toOXP:currentOXPScript]; return JS_TRUE; } @@ -177,7 +179,7 @@ JSBool GlobalGetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) { if (!JSVAL_IS_INT(id)) return JS_TRUE; - PlayerEntity *playerEntity = (PlayerEntity *)[scriptedUniverse entityZero]; + PlayerEntity *playerEntity = [PlayerEntity sharedPlayer]; switch (JSVAL_TO_INT(id)) { case GLOBAL_GALAXY_NUMBER: @@ -269,7 +271,7 @@ JSFunctionSpec Player_funcs[] = { JSBool PlayerAwardCargo(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { if (argc == 2) { - PlayerEntity *playerEntity = (PlayerEntity *)[scriptedUniverse entityZero]; + PlayerEntity *playerEntity = [PlayerEntity sharedPlayer]; NSString *amount_type = [NSString stringWithFormat:@"%@ %@", JSValToNSString(cx, argv[0]), JSValToNSString(cx, argv[1])]; [playerEntity awardCargo:amount_type]; } @@ -277,21 +279,21 @@ JSBool PlayerAwardCargo(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, j } JSBool PlayerRemoveAllCargo(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - PlayerEntity *playerEntity = (PlayerEntity *)[scriptedUniverse entityZero]; + PlayerEntity *playerEntity = [PlayerEntity sharedPlayer]; [playerEntity removeAllCargo]; return JS_TRUE; } JSBool PlayerUseSpecialCargo(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { if (argc == 1) { - PlayerEntity *playerEntity = (PlayerEntity *)[scriptedUniverse entityZero]; + PlayerEntity *playerEntity = [PlayerEntity sharedPlayer]; [playerEntity useSpecialCargo:JSValToNSString(cx, argv[0])]; } return JS_TRUE; } JSBool PlayerAwardEquipment(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - PlayerEntity *playerEntity = (PlayerEntity *)[scriptedUniverse entityZero]; + PlayerEntity *playerEntity = [PlayerEntity sharedPlayer]; if (argc > 0 && JSVAL_IS_STRING(argv[0])) { JSString *jskey = JS_ValueToString(cx, argv[0]); [playerEntity awardEquipment: [NSString stringWithCString:JS_GetStringBytes(jskey)]]; @@ -300,7 +302,7 @@ JSBool PlayerAwardEquipment(JSContext *cx, JSObject *obj, uintN argc, jsval *arg } JSBool PlayerRemoveEquipment(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - PlayerEntity *playerEntity = (PlayerEntity *)[scriptedUniverse entityZero]; + PlayerEntity *playerEntity = [PlayerEntity sharedPlayer]; if (argc > 0 && JSVAL_IS_STRING(argv[0])) { JSString *jskey = JS_ValueToString(cx, argv[0]); [playerEntity removeEquipment: [NSString stringWithCString:JS_GetStringBytes(jskey)]]; @@ -309,7 +311,7 @@ JSBool PlayerRemoveEquipment(JSContext *cx, JSObject *obj, uintN argc, jsval *ar } JSBool PlayerHasEquipment(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - PlayerEntity *playerEntity = (PlayerEntity *)[scriptedUniverse entityZero]; + PlayerEntity *playerEntity = [PlayerEntity sharedPlayer]; if (argc > 0 && JSVAL_IS_STRING(argv[0])) { JSString *jskey = JS_ValueToString(cx, argv[0]); BOOLToJSVal(cx, [playerEntity has_extra_equipment: [NSString stringWithCString:JS_GetStringBytes(jskey)]], rval); @@ -318,13 +320,13 @@ JSBool PlayerHasEquipment(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, } JSBool PlayerLaunch(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - PlayerEntity *playerEntity = (PlayerEntity *)[scriptedUniverse entityZero]; + PlayerEntity *playerEntity = [PlayerEntity sharedPlayer]; [playerEntity launchFromStation]; return JS_TRUE; } JSBool PlayerCall(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - PlayerEntity *playerEntity = (PlayerEntity *)[scriptedUniverse entityZero]; + PlayerEntity *playerEntity = [PlayerEntity sharedPlayer]; if (argc > 0) { NSString *selectorString = JSValToNSString(cx, argv[0]); // Check if the selector needs a trailing colon to flag an argument will be sent @@ -349,7 +351,7 @@ JSBool PlayerGetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) { if (!JSVAL_IS_INT(id)) return JS_TRUE; - PlayerEntity *playerEntity = (PlayerEntity *)[scriptedUniverse entityZero]; + PlayerEntity *playerEntity = [PlayerEntity sharedPlayer]; switch (JSVAL_TO_INT(id)) { case PE_SHIP_DESCRIPTION: @@ -395,7 +397,7 @@ JSBool PlayerSetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) { if (!JSVAL_IS_INT(id)) return JS_TRUE; - PlayerEntity *playerEntity = (PlayerEntity *)[scriptedUniverse entityZero]; + PlayerEntity *playerEntity = [PlayerEntity sharedPlayer]; switch (JSVAL_TO_INT(id)) { case PE_SCORE: @@ -469,7 +471,7 @@ JSFunctionSpec System_funcs[] = { }; JSBool SystemAddPlanet(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - PlayerEntity *playerEntity = (PlayerEntity *)[scriptedUniverse entityZero]; + PlayerEntity *playerEntity = [PlayerEntity sharedPlayer]; if (argc > 0 && JSVAL_IS_STRING(argv[0])) { NSString *key = JSValToNSString(cx, argv[0]); [playerEntity addPlanet:key]; @@ -478,7 +480,7 @@ JSBool SystemAddPlanet(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, js } JSBool SystemAddMoon(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - PlayerEntity *playerEntity = (PlayerEntity *)[scriptedUniverse entityZero]; + PlayerEntity *playerEntity = [PlayerEntity sharedPlayer]; if (argc > 0 && JSVAL_IS_STRING(argv[0])) { NSString *key = JSValToNSString(cx, argv[0]); [playerEntity addMoon:key]; @@ -487,13 +489,13 @@ JSBool SystemAddMoon(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsva } JSBool SystemSendAllShipsAway(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - PlayerEntity *playerEntity = (PlayerEntity *)[scriptedUniverse entityZero]; + PlayerEntity *playerEntity = [PlayerEntity sharedPlayer]; [playerEntity sendAllShipsAway]; return JS_TRUE; } JSBool SystemSetSunNova(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - PlayerEntity *playerEntity = (PlayerEntity *)[scriptedUniverse entityZero]; + PlayerEntity *playerEntity = [PlayerEntity sharedPlayer]; if (argc > 0) { NSString *key = JSValToNSString(cx, argv[0]); [playerEntity setSunNovaIn:key]; @@ -509,14 +511,14 @@ JSBool SystemGetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) { if (!JSVAL_IS_INT(id)) return JS_TRUE; NSString *str; - PlayerEntity *playerEntity = (PlayerEntity *)[scriptedUniverse entityZero]; + PlayerEntity *playerEntity = [PlayerEntity sharedPlayer]; if (!equal_seeds(currentSystem, playerEntity->system_seed)) { //fprintf(stdout, "Current system has changed, regenerating local copy of planetinfo\r\n"); currentSystem = playerEntity->system_seed; if (planetinfo) [planetinfo release]; - planetinfo = [[scriptedUniverse generateSystemData:currentSystem] retain]; + planetinfo = [[[Universe sharedUniverse] generateSystemData:currentSystem] retain]; } switch (JSVAL_TO_INT(id)) { @@ -584,29 +586,29 @@ JSBool SystemSetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) { if (!JSVAL_IS_INT(id)) return JS_TRUE; - PlayerEntity *playerEntity = (PlayerEntity *)[scriptedUniverse entityZero]; + PlayerEntity *playerEntity = [PlayerEntity sharedPlayer]; if (!equal_seeds(currentSystem, playerEntity->system_seed)) { //fprintf(stdout, "Current system has changed, regenerating local copy of planetinfo\r\n"); currentSystem = playerEntity->system_seed; if (planetinfo) [planetinfo release]; - planetinfo = [[scriptedUniverse generateSystemData:currentSystem] retain]; + planetinfo = [[[Universe sharedUniverse] generateSystemData:currentSystem] retain]; } int gn = [[playerEntity galaxy_number] intValue]; int pn = [[playerEntity planet_number] intValue]; switch (JSVAL_TO_INT(id)) { case SYS_NAME: - [scriptedUniverse setSystemDataForGalaxy:gn planet:pn key:KEY_NAME value:JSValToNSString(cx, *vp)]; + [[Universe sharedUniverse] setSystemDataForGalaxy:gn planet:pn key:KEY_NAME value:JSValToNSString(cx, *vp)]; break; case SYS_DESCRIPTION: - [scriptedUniverse setSystemDataForGalaxy:gn planet:pn key:KEY_DESCRIPTION value:JSValToNSString(cx, *vp)]; + [[Universe sharedUniverse] setSystemDataForGalaxy:gn planet:pn key:KEY_DESCRIPTION value:JSValToNSString(cx, *vp)]; break; case SYS_INHABITANTS: - [scriptedUniverse setSystemDataForGalaxy:gn planet:pn key:KEY_INHABITANTS value:JSValToNSString(cx, *vp)]; + [[Universe sharedUniverse] setSystemDataForGalaxy:gn planet:pn key:KEY_INHABITANTS value:JSValToNSString(cx, *vp)]; break; /* case SYS_GOING_NOVA: @@ -618,23 +620,23 @@ JSBool SystemSetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) { break; */ case SYS_GOVT_ID: - [scriptedUniverse setSystemDataForGalaxy:gn planet:pn key:KEY_GOVERNMENT value:[NSNumber numberWithInt:[JSValToNSString(cx, *vp) intValue]]]; + [[Universe sharedUniverse] setSystemDataForGalaxy:gn planet:pn key:KEY_GOVERNMENT value:[NSNumber numberWithInt:[JSValToNSString(cx, *vp) intValue]]]; break; case SYS_ECONOMY_ID: - [scriptedUniverse setSystemDataForGalaxy:gn planet:pn key:KEY_ECONOMY value:[NSNumber numberWithInt:[JSValToNSString(cx, *vp) intValue]]]; + [[Universe sharedUniverse] setSystemDataForGalaxy:gn planet:pn key:KEY_ECONOMY value:[NSNumber numberWithInt:[JSValToNSString(cx, *vp) intValue]]]; break; case SYS_TECH_LVL: - [scriptedUniverse setSystemDataForGalaxy:gn planet:pn key:KEY_TECHLEVEL value:[NSNumber numberWithInt:[JSValToNSString(cx, *vp) intValue]]]; + [[Universe sharedUniverse] setSystemDataForGalaxy:gn planet:pn key:KEY_TECHLEVEL value:[NSNumber numberWithInt:[JSValToNSString(cx, *vp) intValue]]]; break; case SYS_POPULATION: - [scriptedUniverse setSystemDataForGalaxy:gn planet:pn key:KEY_POPULATION value:[NSNumber numberWithInt:[JSValToNSString(cx, *vp) intValue]]]; + [[Universe sharedUniverse] setSystemDataForGalaxy:gn planet:pn key:KEY_POPULATION value:[NSNumber numberWithInt:[JSValToNSString(cx, *vp) intValue]]]; break; case SYS_PRODUCTIVITY: - [scriptedUniverse setSystemDataForGalaxy:gn planet:pn key:KEY_PRODUCTIVITY value:[NSNumber numberWithInt:[JSValToNSString(cx, *vp) intValue]]]; + [[Universe sharedUniverse] setSystemDataForGalaxy:gn planet:pn key:KEY_PRODUCTIVITY value:[NSNumber numberWithInt:[JSValToNSString(cx, *vp) intValue]]]; break; } return JS_TRUE; @@ -687,7 +689,7 @@ JSBool MissionGetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) { if (!JSVAL_IS_INT(id)) return JS_TRUE; NSString *str; - PlayerEntity *playerEntity = (PlayerEntity *)[scriptedUniverse entityZero]; + PlayerEntity *playerEntity = [PlayerEntity sharedPlayer]; switch (JSVAL_TO_INT(id)) { case MISSION_CHOICE: @@ -704,7 +706,7 @@ JSBool MissionSetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) { if (!JSVAL_IS_INT(id)) return JS_TRUE; - PlayerEntity *playerEntity = (PlayerEntity *)[scriptedUniverse entityZero]; + PlayerEntity *playerEntity = [PlayerEntity sharedPlayer]; switch (JSVAL_TO_INT(id)) { case MISSION_TEXT: { @@ -753,13 +755,13 @@ JSBool MissionSetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) { } JSBool MissionShowMissionScreen(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - PlayerEntity *playerEntity = (PlayerEntity *)[scriptedUniverse entityZero]; + PlayerEntity *playerEntity = [PlayerEntity sharedPlayer]; [playerEntity setGuiToMissionScreen]; return JS_TRUE; } JSBool MissionShowShipModel(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - PlayerEntity *playerEntity = (PlayerEntity *)[scriptedUniverse entityZero]; + PlayerEntity *playerEntity = [PlayerEntity sharedPlayer]; if (argc > 0 && JSVAL_IS_STRING(argv[0])) { JSString *jskey = JS_ValueToString(cx, argv[0]); [playerEntity showShipModel: [NSString stringWithCString:JS_GetStringBytes(jskey)]]; @@ -768,7 +770,7 @@ JSBool MissionShowShipModel(JSContext *cx, JSObject *obj, uintN argc, jsval *arg } JSBool MissionResetMissionChoice(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { - PlayerEntity *playerEntity = (PlayerEntity *)[scriptedUniverse entityZero]; + PlayerEntity *playerEntity = [PlayerEntity sharedPlayer]; [playerEntity resetMissionChoice]; return JS_TRUE; } @@ -795,7 +797,6 @@ void reportJSError(JSContext *cx, const char *message, JSErrorReport *report) { - (id) initWithUniverse: (Universe *)universe { self = [super init]; - scriptedUniverse = universe; /*set up global JS variables, including global and custom objects */ diff --git a/src/Core/NSFileManagerOOExtensions.m b/src/Core/NSFileManagerOOExtensions.m index 3f0373f3..fa29a87e 100644 --- a/src/Core/NSFileManagerOOExtensions.m +++ b/src/Core/NSFileManagerOOExtensions.m @@ -31,6 +31,9 @@ MA 02110-1301, USA. #import "ResourceManager.h" #import "OOPListParsing.h" +#define kOOLogUnconvertedNSLog @"unclassified.NSFileManagerOOExtensions" + + @implementation NSFileManager (OOExtensions) - (NSArray *)commanderContents @@ -92,7 +95,6 @@ MA 02110-1301, USA. // check file extension if (![[path pathExtension] isEqual:@"oolite-save"]) { -// NSLog(@">>>> %@ is not a saved game", path); [contents removeObjectAtIndex: i--]; continue; } diff --git a/src/Core/OOCharacter.m b/src/Core/OOCharacter.m index 3711a0ca..28fc760f 100644 --- a/src/Core/OOCharacter.m +++ b/src/Core/OOCharacter.m @@ -106,7 +106,6 @@ MA 02110-1301, USA. return castmember; else { -// NSLog(@"DEBUG ***** couldn't cast character in role '%@'", c_role); return castmember; } } @@ -140,7 +139,7 @@ MA 02110-1301, USA. // save random seeds for restoration later RNG_Seed saved_seed = currentRandomSeed(); // set RNG to character seed - seed_for_planet_description( genSeed); + seed_for_planet_description(genSeed); // determine the planet of origin NSDictionary* originInfo = [universe generateSystemData: originSystemSeed]; @@ -152,16 +151,16 @@ MA 02110-1301, USA. NSString* speciesString = [self species]; // determine the character's name - seed_RNG_only_for_planet_description( genSeed); + seed_RNG_only_for_planet_description(genSeed); NSString* genName; if ([speciesString hasPrefix:@"human"]) - genName = [NSString stringWithFormat:@"%@ %@", [universe expandDescription:@"%R" forSystem: genSeed], [universe expandDescription:@"[nom]" forSystem: genSeed]]; + genName = [NSString stringWithFormat:@"%@ %@", ExpandDescriptionForSeed(@"%R", genSeed), ExpandDescriptionForSeed(@"[nom]", genSeed)]; else - genName = [NSString stringWithFormat:@"%@ %@", [universe expandDescription:@"%R" forSystem: genSeed], [universe expandDescription:@"%R" forSystem: genSeed]]; + genName = [NSString stringWithFormat:@"%@ %@", ExpandDescriptionForSeed(@"%R", genSeed), ExpandDescriptionForSeed(@"%R", genSeed)]; [self setName: genName]; - [self setShortDescription: [NSString stringWithFormat:[universe expandDescription:@"[character-a-@-from-@]" forSystem: genSeed], speciesString, planetName]]; + [self setShortDescription: [NSString stringWithFormat:ExpandDescriptionForSeed(@"[character-a-@-from-@]", genSeed), speciesString, planetName]]; [self setLongDescription: [self shortDescription]]; // determine legal_status for a completely random character @@ -233,11 +232,7 @@ MA 02110-1301, USA. break; } [self setLongDescription: - [universe expandDescription: - [NSString stringWithFormat:@"%@ is a [21] %@ from %@", [self name], legalDesc, [self planetOfOrigin]] - forSystem: genSeed]]; - -// NSLog(@">>>>> %@", self); + ExpandDescriptionForSeed([NSString stringWithFormat:@"%@ is a [21] %@ from %@", [self name], legalDesc, [self planetOfOrigin]], genSeed)]; specialSetUpDone = YES; } diff --git a/src/Core/OOInstinct.m b/src/Core/OOInstinct.m index 085c8938..158175dc 100644 --- a/src/Core/OOInstinct.m +++ b/src/Core/OOInstinct.m @@ -27,6 +27,8 @@ MA 02110-1301, USA. #import "Universe.h" #import "AI.h" +#define kOOLogUnconvertedNSLog @"unclassified.OOInstinct" + @implementation OOInstinct diff --git a/src/Core/OOLogging.m b/src/Core/OOLogging.m index 0c6630a6..175622a2 100644 --- a/src/Core/OOLogging.m +++ b/src/Core/OOLogging.m @@ -141,13 +141,14 @@ BOOL OOLogWillDisplayMessagesInClass(NSString *inMessageClass) // Look for cached value value = [sDerivedSettingsCache objectForKey:inMessageClass]; - if (__builtin_expect(value == nil, 0)) + if (EXPECT_NOT(value == nil)) { // No cached value. value = ResolveDisplaySetting(inMessageClass); if (value != nil) { + if (EXPECT_NOT(sDerivedSettingsCache == nil)) sDerivedSettingsCache = [[NSMutableDictionary alloc] init]; [sDerivedSettingsCache setObject:value forKey:inMessageClass]; } } diff --git a/src/Core/OOStringParsing.h b/src/Core/OOStringParsing.h index 73bbd069..90aaa671 100644 --- a/src/Core/OOStringParsing.h +++ b/src/Core/OOStringParsing.h @@ -45,6 +45,7 @@ NSString *StringFromPoint(NSPoint point); NSPoint PointFromString(NSString *xyString); Random_Seed RandomSeedFromString(NSString *abcdefString); +NSString *StringFromRandomSeed(Random_Seed seed); NSString *ExpandDescriptionForSeed(NSString *text, Random_Seed seed); @@ -53,9 +54,14 @@ NSString *ExpandDescriptionForCurrentSystem(NSString *text); NSString *ExpandDescriptionsWithLocalsForSystemSeed(NSString *text, Random_Seed seed, NSDictionary *locals); NSString *ExpandDescriptionsWithLocalsForCurrentSystem(NSString *text, NSDictionary *locals); +NSString *DescriptionForSystem(Random_Seed seed); +NSString *DescriptionForCurrentSystem(void); + // target and localVariables are optional; target will default to the player. NSString *ReplaceVariables(NSString *string, Entity *target, NSDictionary *localVariables); +NSString *RandomDigrams(void); + @interface NSString (OOUtilities) @@ -64,3 +70,15 @@ NSString *ReplaceVariables(NSString *string, Entity *target, NSDictionary *local - (BOOL)pathHasExtensionInArray:(NSArray *)extensions; @end + + +// Given a string of the form 1.2.3.4 (with arbitrarily many components), return an array of unsigned ints. +NSArray *ComponentsFromVersionString(NSString *string); + +/* Compare two arrays of unsigned int NSNumbers, as returned by + ComponentsFromVersionString(). + + Components are ordered from most to least significant, and a missing + component is treated as 0. Thus "1.7" < "1.60", and "1.2.3.0" == "1.2.3". +*/ +NSComparisonResult CompareVersions(NSArray *version1, NSArray *version2); diff --git a/src/Core/OOStringParsing.m b/src/Core/OOStringParsing.m index f03c54eb..5b94c718 100644 --- a/src/Core/OOStringParsing.m +++ b/src/Core/OOStringParsing.m @@ -239,6 +239,12 @@ Random_Seed RandomSeedFromString(NSString *abcdefString) } +NSString *StringFromRandomSeed(Random_Seed seed) +{ + return [NSString stringWithFormat: @"%d %d %d %d %d %d", seed.a, seed.b, seed.c, seed.d, seed.e, seed.f]; +} + + NSString *ExpandDescriptionForSeed(NSString *text, Random_Seed seed) { // to enable variables to return strings that can be expanded (eg. @"[commanderName_string]") @@ -253,7 +259,7 @@ NSString *ExpandDescriptionForSeed(NSString *text, Random_Seed seed) do { old_desc = result; - result = ExpandDescriptionsWithLocalsForSystemSeed(text, seed, nil); + result = ExpandDescriptionsWithLocalsForSystemSeed(result, seed, nil); } while (--stack_check && ![result isEqual:old_desc]); if (!stack_check) @@ -262,7 +268,7 @@ NSString *ExpandDescriptionForSeed(NSString *text, Random_Seed seed) #if 0 // What's the point of breaking? A bad description is better than falling to pieces. [NSException raise:OOLITE_EXCEPTION_LOOPING - format:@"script stack overflow for expandDescription: \"%@\"", text]; + format:@"script stack overflow for ExpandDescriptionForSeed(\"%@\")", text]; #endif } @@ -355,7 +361,7 @@ NSString *ExpandDescriptionsWithLocalsForSystemSeed(NSString *text, Random_Seed options:NSLiteralSearch range:NSMakeRange(0, [partial length])]; [partial replaceOccurrencesOfString:@"%R" - withString:[universe getRandomDigrams] + withString:RandomDigrams() options:NSLiteralSearch range:NSMakeRange(0, [partial length])]; return partial; @@ -368,6 +374,19 @@ NSString *ExpandDescriptionsWithLocalsForCurrentSystem(NSString *text, NSDiction } +NSString *DescriptionForSystem(Random_Seed seed) +{ + seed_RNG_only_for_planet_description(seed); + return ExpandDescriptionForSeed(@"[14] is [22].", seed); +} + + +NSString *DescriptionForCurrentSystem(void) +{ + return DescriptionForSystem([[PlayerEntity sharedPlayer] system_seed]); +} + + NSString *ReplaceVariables(NSString *string, Entity *target, NSDictionary *localVariables) { NSMutableString *resultString = nil; @@ -413,6 +432,21 @@ NSString *ReplaceVariables(NSString *string, Entity *target, NSDictionary *local } +NSString *RandomDigrams(void) +{ + int i; + int len = gen_rnd_number() & 3; + NSString* digrams = [[[Universe sharedUniverse] descriptions] objectForKey:@"digrams"]; + NSMutableString* name = [NSMutableString stringWithCapacity:256]; + for (i = 0; i <=len; i++) + { + int x = gen_rnd_number() & 0x3e; + [name appendString:[digrams substringWithRange:NSMakeRange(x,2)]]; + } + return [name capitalizedString]; +} + + @implementation NSString (OOUtilities) - (BOOL)pathHasExtension:(NSString *)extension @@ -435,3 +469,60 @@ NSString *ReplaceVariables(NSString *string, Entity *target, NSDictionary *local } @end + + +NSArray *ComponentsFromVersionString(NSString *string) +{ + NSArray *stringComponents = nil; + NSMutableArray *result = nil; + unsigned i, count; + int value; + id component; + + stringComponents = [string componentsSeparatedByString:@"."]; + count = [stringComponents count]; + result = [NSMutableArray arrayWithCapacity:count]; + + for (i = 0; i != count; ++i) + { + component = [stringComponents objectAtIndex:i]; + if ([component respondsToSelector:@selector(intValue)]) value = MAX([component intValue], 0); + else value = 0; + + [result addObject:[NSNumber numberWithUnsignedInt:value]]; + } + + return result; +} + + +NSComparisonResult CompareVersions(NSArray *version1, NSArray *version2) +{ + NSEnumerator *leftEnum = nil, + *rightEnum = nil; + NSNumber *leftComponent = nil, + *rightComponent = nil; + unsigned leftValue, + rightValue; + + leftEnum = [version1 objectEnumerator]; + rightEnum = [version2 objectEnumerator]; + + for (;;) + { + leftComponent = [leftEnum nextObject]; + rightComponent = [rightEnum nextObject]; + + if (leftComponent == nil && rightComponent == nil) break; // End of both versions + + // We'll get 0 if the component is nil, which is what we want. + leftValue = [leftComponent unsignedIntValue]; + rightValue = [rightComponent unsignedIntValue]; + + if (leftValue < rightValue) return NSOrderedAscending; + if (leftValue > rightValue) return NSOrderedDescending; + } + + // If there was a difference, we'd have returned already. + return NSOrderedSame; +} diff --git a/src/Core/OOTrumble.m b/src/Core/OOTrumble.m index 706b8614..9d2b4fb6 100644 --- a/src/Core/OOTrumble.m +++ b/src/Core/OOTrumble.m @@ -375,7 +375,6 @@ MA 02110-1301, USA. */ GLfloat wd = 96 * size; GLfloat ht = 96 * size; -// NSLog(@"DEBUG drawing Trumble %@ of size %.2f at position %.2fx %.2fy %.2fz", self, size, position.x, position.y, z); glShadeModel(GL_SMOOTH); glEnable(GL_TEXTURE_2D); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); @@ -614,10 +613,9 @@ MA 02110-1301, USA. { // eaten all of this cargo! Universe* uni = [player universe]; - Random_Seed seed = [uni systemSeed]; - NSString* ms = [NSString stringWithFormat:[uni expandDescription:@"[trumbles-eat-@]" forSystem:seed], + NSString* ms = [NSString stringWithFormat:ExpandDescriptionForCurrentSystem(@"[trumbles-eat-@]"), [uni nameForCommodity:[selectedCargopod getCommodityType]]]; -// NSLog(ms); + [uni addMessage: ms forCount: 4.5]; [cargopods removeObject:selectedCargopod]; trumbleAppetiteAccumulator -= 10.0; @@ -625,7 +623,6 @@ MA 02110-1301, USA. // consider breeding - must be full grown and happy if ((size > 0.95)&&(discomfort < 0.25)) { -// NSLog(@"Trumbles breeding!"); readyToSpawn = YES; } } @@ -875,7 +872,6 @@ MA 02110-1301, USA. if (animationTime > animationDuration) { // kaputnik! -// NSLog(@"TRUMBLE DIES!"); [player removeTrumble:self]; } } diff --git a/src/Core/OOVector.h b/src/Core/OOVector.h index a0515dda..2f79a00d 100644 --- a/src/Core/OOVector.h +++ b/src/Core/OOVector.h @@ -63,9 +63,9 @@ OOINLINE GLfloat magnitude(Vector vec) INLINE_CONST_FUNC; OOINLINE GLfloat fast_magnitude(Vector vec) INLINE_CONST_FUNC; /* Normalize vector */ -OOINLINE Vector vector_normal(Vector vec) CONST_FUNC; -OOINLINE Vector fast_vector_normal(Vector vec) CONST_FUNC; -OOINLINE Vector unit_vector(const Vector *vec) NONNULL_FUNC CONST_FUNC; +OOINLINE Vector vector_normal(Vector vec) INLINE_CONST_FUNC; +OOINLINE Vector fast_vector_normal(Vector vec) INLINE_CONST_FUNC; +OOINLINE Vector unit_vector(const Vector *vec) NONNULL_FUNC INLINE_CONST_FUNC; /* Square of distance between vectors */ OOINLINE GLfloat distance2(Vector v1, Vector v2) INLINE_CONST_FUNC; diff --git a/src/Core/Octree.m b/src/Core/Octree.m index b0a262ec..839c9f60 100644 --- a/src/Core/Octree.m +++ b/src/Core/Octree.m @@ -28,6 +28,9 @@ MA 02110-1301, USA. #import "OOOpenGL.h" #import "legacy_random.h" +#define kOOLogUnconvertedNSLog @"unclassified.Octree" + + @implementation Octree - (id) init diff --git a/src/Core/OpenGLSprite.m b/src/Core/OpenGLSprite.m index 37fece95..50a59797 100644 --- a/src/Core/OpenGLSprite.m +++ b/src/Core/OpenGLSprite.m @@ -171,10 +171,6 @@ MA 02110-1301, USA. [self makeTextureFromImage:image cropRectangle:NSMakeRect(0, 0, [image size].width, [image size].height) size:[image size]]; [image release]; - - // - //NSLog(@"%@ message sprite [ %f, %f ]", str, [image size].width, [image size].height); - // #endif } @@ -261,8 +257,7 @@ MA 02110-1301, USA. if ((textureRect.size.width != textureSize.width)||(textureRect.size.height != textureSize.height)) { - NSLog(@"***** ERROR! replacement texture isn't the same size as original texture"); - NSLog(@"***** cropRect %f x %f textureSize %f x %f",textureRect.size.width, textureRect.size.height, textureSize.width, textureSize.height); + OOLog(@"sprite.badReplacementSize", @"***** ERROR! replacement texture isn't the same size as original texture -- cropRect %f x %f textureSize %f x %f",textureRect.size.width, textureRect.size.height, textureSize.width, textureSize.height); return; } @@ -383,7 +378,6 @@ enum SDL_Surface *texSurface = [texImage surface]; SDL_SetAlpha(texSurface, 0, SDL_ALPHA_OPAQUE); - //NSLog(@"makeTextureFromSurface: texImage dimensions: %d x %d", texSurface->w, texSurface->h); size = spriteSize; textureCropRect = cropRect; @@ -397,42 +391,24 @@ enum textureCropRect.origin= NSMakePoint(0,0); textureSize = textureRect.size; - - //image = [[NSImage alloc] initWithSize:textureRect.size]; // retained - //NSLog(@"makeTextureFromSurface: texture surface dimensions: %d x %d", (int)textureRect.size.width, (int)textureRect.size.height); + surface = SDL_CreateRGBSurface(SDL_SWSURFACE, (int)textureRect.size.width, (int)textureRect.size.height, 32, rmask, gmask, bmask, amask); - - //[image lockFocus]; - //[[OOColor clearColor] set]; - //NSRectFill(textureRect); + SDL_FillRect(surface, (SDL_Rect *)0x00, SDL_MapRGBA(surface->format, 0, 0, 0, SDL_ALPHA_TRANSPARENT)); - //[texImage drawInRect:textureCropRect fromRect:cropRect operation:NSCompositeSourceOver fraction:1.0]; - //bitmapImageRep = [[NSBitmapImageRep alloc] initWithFocusedViewRect:textureRect]; // retained - //[image unlockFocus]; - SDL_Rect srcRect, destRect; srcRect.x = (int)cropRect.origin.x; srcRect.y = (int)cropRect.origin.y; srcRect.w = (int)cropRect.size.width; srcRect.h = (int)cropRect.size.height; destRect.x = 0; destRect.y = 0; SDL_BlitSurface(texSurface, &srcRect, surface, &destRect); - //NSLog(@"destRect x: %d, y: %d, w: %d, h: %d", destRect.x, destRect.y, destRect.w, destRect.h); - - //[image release]; // released // normalise textureCropRect size to 0.0 -> 1.0 textureCropRect.size.width /= textureRect.size.width; textureCropRect.size.height /= textureRect.size.height; -// int n_bytes = surface->format->BytesPerPixel * surface->w * surface->h; - //unsigned char *buffer = malloc(n_bytes); SDL_LockSurface(surface); - //memcpy(buffer, surface->pixels, n_bytes); if (textureData) [textureData release]; - //textureData = [[NSData dataWithBytes:[bitmapImageRep bitmapData] length:n_bytes] retain]; - //[bitmapImageRep release]; // released - //textureData = [[NSData dataWithBytesNoCopy: buffer length: n_bytes] retain]; textureData = [[NSData dataWithBytes:surface->pixels length:surface->w * surface->h * surface->format->BytesPerPixel] retain]; SDL_UnlockSurface(surface); diff --git a/src/Core/ParticleEntity.m b/src/Core/ParticleEntity.m index 7dfa55c9..e61ad161 100644 --- a/src/Core/ParticleEntity.m +++ b/src/Core/ParticleEntity.m @@ -34,6 +34,8 @@ MA 02110-1301, USA. #import "PlayerEntity.h" #import "PlanetEntity.h" +#define kOOLogUnconvertedNSLog @"unclassified.ParticleEntity" + static Vector circleVertex[65]; // holds vector coordinates for a unit circle @@ -914,7 +916,7 @@ static Vector circleVertex[65]; // holds vector coordinates for a unit circle case PARTICLE_BURST2 : case PARTICLE_FLASH : { - Entity* player = [universe entityZero]; + PlayerEntity *player = [PlayerEntity sharedPlayer]; if (!texName) [self initialiseTexture: textureNameString]; if (player) @@ -1037,7 +1039,7 @@ static Vector circleVertex[65]; // holds vector coordinates for a unit circle - (void) updateEnergyMine:(double) delta_t { // new billboard routine (working at last!) - Entity* player = [universe entityZero]; + PlayerEntity *player = [PlayerEntity sharedPlayer]; Vector v0 = position; Vector p0 = (player)? player->position : make_vector( 0.0f, 0.0f, 0.0f); v0.x -= p0.x; v0.y -= p0.y; v0.z -= p0.z; // vector from player to position @@ -1606,7 +1608,7 @@ static Vector circleVertex[65]; // holds vector coordinates for a unit circle glPushMatrix(); // position and orientation is absolute glTranslatef( abspos.x, abspos.y, abspos.z); - glMultMatrixf([[universe entityZero] drawRotationMatrix]); + glMultMatrixf([[PlayerEntity sharedPlayer] drawRotationMatrix]); [self drawEntity:immediate :translucent]; @@ -1707,7 +1709,7 @@ static Vector circleVertex[65]; // holds vector coordinates for a unit circle case VIEW_CUSTOM : { - PlayerEntity* player = (PlayerEntity*)[universe entityZero]; + PlayerEntity *player = [PlayerEntity sharedPlayer]; Vector vi = [player customViewRightVector]; vi.x *= xx; vi.y *= xx; vi.z *= xx; Vector vj = [player customViewUpVector]; vj.x *= yy; vj.y *= yy; vj.z *= yy; Vector vk = [player customViewForwardVector]; vk.x *= xx; vk.y *= xx; vk.z *= xx; @@ -1960,7 +1962,7 @@ void drawQuadForView(Universe* universe, GLfloat x, GLfloat y, GLfloat z, GLfloa break; case VIEW_CUSTOM : { - PlayerEntity* player = (PlayerEntity*)[universe entityZero]; + PlayerEntity *player = [PlayerEntity sharedPlayer]; Vector vi = [player customViewRightVector]; vi.x *= xx; vi.y *= xx; vi.z *= xx; Vector vj = [player customViewUpVector]; vj.x *= yy; vj.y *= yy; vj.z *= yy; glTexCoord2f(0.0, 1.0); glVertex3f(x - vi.x - vj.x, y - vi.y - vj.y, z - vi.z - vj.z); diff --git a/src/Core/PlanetEntity.m b/src/Core/PlanetEntity.m index 3039dd0b..80a71086 100644 --- a/src/Core/PlanetEntity.m +++ b/src/Core/PlanetEntity.m @@ -35,6 +35,8 @@ MA 02110-1301, USA. #import "OOStringParsing.h" #import "PlayerEntity.h" +#define kOOLogUnconvertedNSLog @"unclassified.PlanetEntity" + #define LIM500 500.0*500.0 * NO_DRAW_DISTANCE_FACTOR*NO_DRAW_DISTANCE_FACTOR #define LIM4K 4000.0*4000.0 * NO_DRAW_DISTANCE_FACTOR*NO_DRAW_DISTANCE_FACTOR @@ -257,8 +259,7 @@ void setUpSinTable() self = [super init]; // percent_land = 3 + (gen_rnd_number() & 31)+(gen_rnd_number() & 31); - //NSLog(@"Atmosphere is %d percent clear.",percent_land); - // + polar_color_factor = 1.0; // amb_land[0] = gen_rnd_number() / 256.0; @@ -336,18 +337,14 @@ void setUpSinTable() [self setModel:(isTextured)? @"icostextured.dat" : @"icosahedron.dat"]; // [self rescaleTo:1.0]; - -// NSLog(@"DEBUG atmosphere testing [PlanetEntity initialiseBaseVertexArray]"); + [self initialiseBaseVertexArray]; - -// NSLog(@"DEBUG atmosphere testing [PlanetEntity initialiseBaseTerrainArray:%d]", percent_land); + [self initialiseBaseTerrainArray:percent_land]; - -// NSLog(@"DEBUG atmosphere painting %d vertices", next_free_vertex); + for (i = 0; i < next_free_vertex; i++) [self paintVertex:i :planet_seed]; - -// NSLog(@"DEBUG atmosphere scaling %d vertices", next_free_vertex); + [self scaleVertices]; // set speed of rotation @@ -428,7 +425,7 @@ void setUpSinTable() NSMutableDictionary* planetinfo = [NSMutableDictionary dictionaryWithDictionary:[uni generateSystemData:p_seed]]; int radius_km = [(NSNumber *)[planetinfo objectForKey:KEY_RADIUS] intValue]; int techlevel = [(NSNumber *)[planetinfo objectForKey:KEY_TECHLEVEL] intValue]; - //NSLog(@"Generating planet %@ with radius %dkm",[planetinfo objectForKey:KEY_NAME],radius_km); + if ([planetinfo objectForKey:@"texture"]) { textureName = [TextureStore getTextureNameFor:(NSString*)[planetinfo objectForKey:@"texture"]]; @@ -441,8 +438,6 @@ void setUpSinTable() last_launch_time = -(ranrot_rand() % 60) * shuttle_launch_interval/60.0; last_launch_time = 30.0 - shuttle_launch_interval; // debug - launch 30s after player enters universe - //NSLog(@"shuttles on ground:%d launch_interval:%.1f minutes", shuttles_on_ground, shuttle_launch_interval/60); - //collision_radius = 25000.0; // 25km across collision_radius = radius_km * 10.0; // scale down by a factor of 100 ! // @@ -474,8 +469,7 @@ void setUpSinTable() // save the current random number generator seed RNG_Seed saved_seed = currentRandomSeed(); - - //NSLog(@"Planet surface is %d percent land.",percent_land); + for (i = 0; i < n_vertices; i++) { if (gen_rnd_number() < 256 * percent_land / 100) @@ -560,19 +554,15 @@ void setUpSinTable() shader_program = nil; #endif } - -// NSLog(@"DEBUG testing [PlanetEntity initialiseBaseVertexArray]"); + [self initialiseBaseVertexArray]; - -// NSLog(@"DEBUG testing [PlanetEntity initialiseBaseTerrainArray:%d]", percent_land); + setRandomSeed(saved_seed); [self initialiseBaseTerrainArray:percent_land]; - -// NSLog(@"DEBUG painting %d vertices", next_free_vertex); + for (i = 0; i < next_free_vertex; i++) [self paintVertex:i :planet_seed]; - -// NSLog(@"DEBUG scaling %d vertices", next_free_vertex); + [self scaleVertices]; // set speed of rotation @@ -617,8 +607,6 @@ void setUpSinTable() last_launch_time = 8400.0; shuttle_launch_interval = 8400.0; - //NSLog(@"shuttles on ground:%d launch_interval:%.1f minutes", shuttles_on_ground, shuttle_launch_interval/60); - collision_radius = [planet collisionRadius] * PLANET_MINIATURE_FACTOR; // teeny tiny // scan_class = CLASS_NO_DRAW; @@ -743,8 +731,6 @@ void setUpSinTable() shuttle_launch_interval = 3600.0 / shuttles_on_ground; // all are launched in an hour last_launch_time = 3600.0; - //NSLog(@"shuttles on ground:%d launch_interval:%.1f minutes", shuttles_on_ground, shuttle_launch_interval/60); - collision_radius = radius_km * 10.0; // scale down by a factor of 100 ! // scan_class = CLASS_NO_DRAW; @@ -774,8 +760,7 @@ void setUpSinTable() // save the current random number generator seed RNG_Seed saved_seed = currentRandomSeed(); - - //NSLog(@"Planet surface is %d percent land.",percent_land); + for (i = 0; i < n_vertices; i++) { if (gen_rnd_number() < 256 * percent_land / 100) @@ -829,19 +814,15 @@ void setUpSinTable() amb_polar_sea[1] = [[OOColor colorWithCalibratedHue:sea_polar_hsb.x saturation:sea_polar_hsb.y brightness:sea_polar_hsb.z alpha:1.0] blueComponent]; amb_polar_sea[2] = [[OOColor colorWithCalibratedHue:sea_polar_hsb.x saturation:sea_polar_hsb.y brightness:sea_polar_hsb.z alpha:1.0] greenComponent]; amb_polar_sea[3] = 1.0; - -// NSLog(@"DEBUG testing [PlanetEntity initialiseBaseVertexArray]"); + [self initialiseBaseVertexArray]; - -// NSLog(@"DEBUG testing [PlanetEntity initialiseBaseTerrainArray:%d]", percent_land); + setRandomSeed(saved_seed); [self initialiseBaseTerrainArray:percent_land]; - -// NSLog(@"DEBUG painting %d vertices", next_free_vertex); + for (i = 0; i < next_free_vertex; i++) [self paintVertex:i :planet_seed]; - -// NSLog(@"DEBUG scaling %d vertices", next_free_vertex); + [self scaleVertices]; // set speed of rotation @@ -923,8 +904,6 @@ void setUpSinTable() shuttle_launch_interval = 3600.0 / shuttles_on_ground; // all are launched in an hour last_launch_time = 3600.0; - //NSLog(@"shuttles on ground:%d launch_interval:%.1f minutes", shuttles_on_ground, shuttle_launch_interval/60); - collision_radius = radius_km * 10.0; // scale down by a factor of 100 ! // scan_class = CLASS_NO_DRAW; @@ -954,8 +933,7 @@ void setUpSinTable() // save the current random number generator seed RNG_Seed saved_seed = currentRandomSeed(); - - //NSLog(@"Planet surface is %d percent land.",percent_land); + for (i = 0; i < n_vertices; i++) { if (gen_rnd_number() < 256 * percent_land / 100) @@ -1009,19 +987,15 @@ void setUpSinTable() amb_polar_sea[1] = [[OOColor colorWithCalibratedHue:sea_polar_hsb.x saturation:sea_polar_hsb.y brightness:sea_polar_hsb.z alpha:1.0] blueComponent]; amb_polar_sea[2] = [[OOColor colorWithCalibratedHue:sea_polar_hsb.x saturation:sea_polar_hsb.y brightness:sea_polar_hsb.z alpha:1.0] greenComponent]; amb_polar_sea[3] = 1.0; - -// NSLog(@"DEBUG testing [PlanetEntity initialiseBaseVertexArray]"); + [self initialiseBaseVertexArray]; - -// NSLog(@"DEBUG testing [PlanetEntity initialiseBaseTerrainArray:%d]", percent_land); + setRandomSeed(saved_seed); [self initialiseBaseTerrainArray:percent_land]; - -// NSLog(@"DEBUG painting %d vertices", next_free_vertex); + for (i = 0; i < next_free_vertex; i++) [self paintVertex:i :planet_seed]; - -// NSLog(@"DEBUG scaling %d vertices", next_free_vertex); + [self scaleVertices]; // set speed of rotation @@ -1190,7 +1164,7 @@ void setUpSinTable() case PLANET_TYPE_SUN : { // new billboard routine (working at last!) - PlayerEntity* player = (PlayerEntity*)[universe entityZero]; + PlayerEntity* player = [PlayerEntity sharedPlayer]; Vector v0 = position; Vector p0 = (player)? player->position: make_vector( 0.0f, 0.0f, 0.0f); v0.x -= p0.x; v0.y -= p0.y; v0.z -= p0.z; // vector from player to position @@ -1307,7 +1281,6 @@ void setUpSinTable() double old_collision_radius = collision_radius; [super setModel:modelName]; collision_radius = old_collision_radius; // preserve the radius - //NSLog(@"Planet collision radius preserved!"); } @@ -1496,7 +1469,6 @@ void setUpSinTable() displayListNames[subdivideLevel] = glGenLists(1); if (displayListNames[subdivideLevel] != 0) // sanity check { - //NSLog(@"Generating planet data for subdivide %d",subdivideLevel); glNewList(displayListNames[subdivideLevel], GL_COMPILE); // glColor4fv(mat1); @@ -1672,8 +1644,6 @@ void drawCorona (double inner_radius, double outer_radius, int step, double z_di GLfloat r0 = c * x / z; GLfloat z0 = c * r / z; -// NSLog(@"DEBUG r1 = %.4f z1 = %.4f r0 = %.4f z0 = %.4f", r1, z1, r0, z0); - glBegin(GL_TRIANGLE_STRIP); for ( i = 0; i < 360; i += step ) { @@ -1714,8 +1684,6 @@ void drawActiveCorona (double inner_radius, double outer_radius, int step, doubl GLfloat r0 = c * x / z; GLfloat z0 = c * r / z; -// NSLog(@"DEBUG r1 = %.4f z1 = %.4f r0 = %.4f z0 = %.4f", r1, z1, r0, z0); - GLfloat rv0, rv1, rv2; glBegin(GL_TRIANGLE_STRIP); @@ -1858,7 +1826,7 @@ void drawActiveCorona (double inner_radius, double outer_radius, int step, doubl launch_pos.y += start_distance * vf.y; launch_pos.z += start_distance * vf.z; - shuttle_ship = [universe getShipWithRole:@"shuttle"]; // retain count = 1 + shuttle_ship = [universe newShipWithRole:@"shuttle"]; // retain count = 1 if (shuttle_ship) { if (![shuttle_ship crew]) @@ -1881,8 +1849,6 @@ void drawActiveCorona (double inner_radius, double outer_radius, int step, doubl [universe addEntity:shuttle_ship]; [[shuttle_ship getAI] setStateMachine:@"risingShuttleAI.plist"]; // must happen after adding to the universe! - //NSLog(@"Planet %@ in universe %@ Launching shuttle: %@ %d", self, universe, [shuttle_ship name], [shuttle_ship universal_id]); - [shuttle_ship release]; } } @@ -1912,11 +1878,6 @@ static BOOL last_one_was_textured; last_one_was_textured = isTextured; } -// if (isTextured) -// NSLog(@"DEBUG %@ creating textured vertex data texture_uv_array = <%x>", self, texture_uv_array); -// else -// NSLog(@"DEBUG %@ creating plain vertex data", self); - if (edge_to_vertex == nil) { edge_to_vertex = [[NSMutableDictionary dictionaryWithCapacity:7680] retain]; // make a new one @@ -1957,9 +1918,6 @@ static BOOL last_one_was_textured; int newlevel = sublevel + 1; triangle_start[newlevel] = triangle_start[sublevel] + n_triangles[sublevel] * 3; n_triangles[newlevel] = n_triangles[sublevel] * 4; - // - -// NSLog(@"Building new level of subdivision - level %d.", newlevel); int tri; for (tri = 0; tri < n_triangles[sublevel]; tri++) @@ -1989,13 +1947,9 @@ static BOOL last_one_was_textured; vertex_index_array[triangle_start[newlevel] + tri * 12 +11] = v20; } - -// NSLog(@"Current total number of vertices %d.", next_free_vertex); } } -// NSLog(@"edge_to_vertex %@", edge_to_vertex); - // all done - copy the indices to the instance // for (i = 0; i < MAX_TRI_INDICES; i++) @@ -2024,8 +1978,6 @@ int baseVertexIndexForEdge(int va, int vb, BOOL textured) base_vertex_array[vindex].z += base_vertex_array[vb].z; base_vertex_array[vindex] = unit_vector(&base_vertex_array[vindex]); // guaranteed non-zero -// NSLog(@"%d [%@]= (%.3f,%.3f,%.3f)", vindex, key, base_vertex_array[vindex].x, base_vertex_array[vindex].y, base_vertex_array[vindex].z); - if (textured) { //calculate new texture coordinates @@ -2221,8 +2173,6 @@ double longitudeFromVector(Vector v) // No over-ride of Entity's version of the method is required for non-Win32 platforms. - (void) reloadTextures { - //NSLog(@"PlanetEntity::reloadTextures called, clearing planet draw lists and calling super"); - int i; // Clear out the planet's various detail level display lists. for (i = 0; i < MAX_SUBDIVIDE; i++) diff --git a/src/Core/PlayerEntity.m b/src/Core/PlayerEntity.m index 49000f70..a7dc3916 100644 --- a/src/Core/PlayerEntity.m +++ b/src/Core/PlayerEntity.m @@ -57,6 +57,9 @@ MA 02110-1301, USA. #import "PlayerEntityStickMapper.h" #endif +#define kOOLogUnconvertedNSLog @"unclassified.PlayerEntity" + + // 10m/s forward drift #define OG_ELITE_FORWARD_DRIFT 10.0f @@ -270,8 +273,6 @@ static PlayerEntity *sSharedPlayer = nil; co_type = [(ShipEntity *)[cargoArray objectAtIndex:i] getCommodityType]; co_amount = [(ShipEntity *)[cargoArray objectAtIndex:i] getCommodityAmount]; -// NSLog(@"unloading a %@ with %@", [(ShipEntity *)[cargoArray objectAtIndex:i] name], [universe describeCommodity:co_type amount:co_amount]); - commodityInfo = (NSMutableArray *)[manifest objectAtIndex:co_type]; quantity = [(NSNumber *)[commodityInfo objectAtIndex:MARKET_QUANTITY] intValue] + co_amount; @@ -302,17 +303,14 @@ static PlayerEntity *sSharedPlayer = nil; NSMutableArray* commodityInfo = [[NSMutableArray arrayWithArray:(NSArray *)[manifest objectAtIndex:i]] retain]; // retain int quantity = [(NSNumber *)[commodityInfo objectAtIndex:MARKET_QUANTITY] intValue]; int units = [universe unitsForCommodity:i]; -// NSLog(@"DEBUG Commodity index:%d %@ units:%d", i, [commodityInfo objectAtIndex:MARKET_NAME], units); if (quantity > 0) { - //NSLog(@"loading containers with %@",[universe describeCommodity:i amount:quantity]); - if (units == UNITS_TONS) { // put each ton in a separate container for (j = 0; j < quantity; j++) { - ShipEntity* container = [universe getShipWithRole:@"1t-cargopod"]; + ShipEntity* container = [universe newShipWithRole:@"1t-cargopod"]; if (container) { [container setUniverse:universe]; @@ -326,11 +324,8 @@ static PlayerEntity *sSharedPlayer = nil; { NSLog(@"***** ERROR couldn't find a container while trying to [PlayerEntity loadCargoPods] *****"); // throw an exception here... - NSException* myException = [NSException - exceptionWithName: OOLITE_EXCEPTION_FATAL - reason:@"[PlayerEntity loadCargoPods] failed to create a container for cargo with role 'cargopod'" - userInfo:nil]; - [myException raise]; + [NSException raise:OOLITE_EXCEPTION_FATAL + format:@"[PlayerEntity loadCargoPods] failed to create a container for cargo with role 'cargopod'"]; } } // zero this commodity @@ -537,11 +532,6 @@ static PlayerEntity *sSharedPlayer = nil; //set checksum [result setObject:[NSNumber numberWithInt:final_checksum] forKey:@"checksum"]; - //NSLog(@"Player Dictionary :\n%@",[result description]); - - //DEBUG TEST -// NSLog(@"DEBUG TESTING OOXML Export Dictionary:-\n%@", [result OOXMLdescription]); - return [NSDictionary dictionaryWithDictionary:[result autorelease]]; } @@ -879,7 +869,7 @@ static PlayerEntity *sSharedPlayer = nil; NSString* missile_desc = (NSString*)[missile_roles objectAtIndex:i]; if (![missile_desc isEqual:@"NONE"]) { - ShipEntity* amiss = [universe getShipWithRole:missile_desc]; + ShipEntity* amiss = [universe newShipWithRole:missile_desc]; if (amiss) missile_entity[i] = amiss; // retain count = 1 else @@ -898,7 +888,7 @@ static PlayerEntity *sSharedPlayer = nil; else { for (i = 0; i < missiles; i++) - missile_entity[i] = [universe getShipWithRole:@"EQ_MISSILE"]; // retain count = 1 - should be okay as long as we keep a missile with this role + missile_entity[i] = [universe newShipWithRole:@"EQ_MISSILE"]; // retain count = 1 - should be okay as long as we keep a missile with this role // in the base package. } while ((missiles > 0)&&(missile_entity[active_missile] == nil)) @@ -1168,7 +1158,7 @@ static PlayerEntity *sSharedPlayer = nil; { if (missile_entity[i]) [missile_entity[i] release]; - missile_entity[i] = [universe getShipWithRole:@"EQ_MISSILE"]; // retain count = 1 + missile_entity[i] = [universe newShipWithRole:@"EQ_MISSILE"]; // retain count = 1 } [self safe_all_missiles]; @@ -1225,8 +1215,6 @@ static PlayerEntity *sSharedPlayer = nil; if (shipinfoDictionary) [shipinfoDictionary release]; shipinfoDictionary = [[NSDictionary alloc] initWithDictionary:dict]; // retained - - //NSLog(@"DEBUG Playerentity - setUpShipFromDictionary:(NSDictionary *) dict"); // set things from dictionary from here out @@ -1337,13 +1325,11 @@ static PlayerEntity *sSharedPlayer = nil; if ([dict objectForKey:@"max_missiles"]) { -// NSLog(@"DEBUG setting max_missiles %@",[dict objectForKey:@"max_missiles"]); max_missiles = [(NSNumber *)[dict objectForKey:@"max_missiles"] intValue]; } if ([dict objectForKey:@"hud"]) { - //NSLog(@"DEBUG setting hud %@",[dict objectForKey:@"hud"]); NSString *hud_desc = (NSString *)[dict objectForKey:@"hud"]; NSDictionary *huddict = [ResourceManager dictionaryFromFilesNamed:hud_desc inFolder:@"Config" andMerge:YES]; if (huddict) @@ -1366,7 +1352,7 @@ static PlayerEntity *sSharedPlayer = nil; missile_entity[i] = nil; } for (i = 0; i < missiles; i++) - missile_entity[i] = [universe getShipWithRole:@"EQ_MISSILE"]; // retain count = 1 + missile_entity[i] = [universe newShipWithRole:@"EQ_MISSILE"]; // retain count = 1 [self setActive_missile: 0]; @@ -1458,7 +1444,7 @@ static PlayerEntity *sSharedPlayer = nil; { quaternion_normalise(&sub_q); - subent = [universe getShip:subdesc]; // retained + subent = [universe newShipWithName:subdesc]; // retained if (subent) { @@ -1545,14 +1531,10 @@ static PlayerEntity *sSharedPlayer = nil; - (void) warnAboutHostiles { - // make a warningSound -// NSLog(@"player warned about hostiles!"); -#ifdef HAVE_SOUND - if (![warningSound isPlaying]) - [warningSound play]; -#endif + [self playHostileWarning]; } + - (BOOL) canCollide { switch (status) @@ -1742,9 +1724,9 @@ double scoopSoundPlayTime = 0.0; witchspaceCountdown -= delta_t; if (witchspaceCountdown < 0.0) witchspaceCountdown = 0.0; if (galactic_witchjump) - [universe displayCountdownMessage:[NSString stringWithFormat:[universe expandDescription:@"[witch-galactic-in-f-seconds]" forSystem:system_seed], witchspaceCountdown] forCount:1.0]; + [universe displayCountdownMessage:[NSString stringWithFormat:ExpandDescriptionForCurrentSystem(@"[witch-galactic-in-f-seconds]"), witchspaceCountdown] forCount:1.0]; else - [universe displayCountdownMessage:[NSString stringWithFormat:[universe expandDescription:@"[witch-to-@-in-f-seconds]" forSystem:system_seed], [universe getSystemName:target_system_seed], witchspaceCountdown] forCount:1.0]; + [universe displayCountdownMessage:[NSString stringWithFormat:ExpandDescriptionForCurrentSystem(@"[witch-to-@-in-f-seconds]"), [universe getSystemName:target_system_seed], witchspaceCountdown] forCount:1.0]; if (witchspaceCountdown == 0.0) { BOOL go = YES; @@ -1754,7 +1736,7 @@ double scoopSoundPlayTime = 0.0; if (blocker) { [universe clearPreviousMessage]; - [universe addMessage:[NSString stringWithFormat:[universe expandDescription:@"[witch-blocked-by-@]" forSystem:system_seed], [blocker name]] forCount: 4.5]; + [universe addMessage:[NSString stringWithFormat:ExpandDescriptionForCurrentSystem(@"[witch-blocked-by-@]"), [blocker name]] forCount: 4.5]; if (![universe playCustomSound:@"[witch-blocked-by-@]"]) [witchAbortSound play]; status = STATUS_IN_FLIGHT; @@ -1769,7 +1751,7 @@ double scoopSoundPlayTime = 0.0; if (jump_distance > 7.0) { [universe clearPreviousMessage]; - [universe addMessage:[universe expandDescription:@"[witch-too-far]" forSystem:system_seed] forCount: 4.5]; + [universe addMessage:ExpandDescriptionForCurrentSystem(@"[witch-too-far]") forCount: 4.5]; if (![universe playCustomSound:@"[witch-too-far]"]) [witchAbortSound play]; status = STATUS_IN_FLIGHT; @@ -1784,7 +1766,7 @@ double scoopSoundPlayTime = 0.0; if (fuel < fuel_required) { [universe clearPreviousMessage]; - [universe addMessage:[universe expandDescription:@"[witch-no-fuel]" forSystem:system_seed] forCount: 4.5]; + [universe addMessage:ExpandDescriptionForCurrentSystem(@"[witch-no-fuel]") forCount: 4.5]; if (![universe playCustomSound:@"[witch-no-fuel]"]) [witchAbortSound play]; status = STATUS_IN_FLIGHT; @@ -1817,7 +1799,7 @@ double scoopSoundPlayTime = 0.0; if ([universe planet]) [universe addMessage:[NSString stringWithFormat:@" %@. ",[universe getSystemName:system_seed]] forCount:3.0]; else - [universe addMessage:[universe expandDescription:@"[witch-engine-malfunction]" forSystem:system_seed] forCount:3.0]; + [universe addMessage:ExpandDescriptionForCurrentSystem(@"[witch-engine-malfunction]") forCount:3.0]; status = STATUS_IN_FLIGHT; } @@ -1852,7 +1834,7 @@ double scoopSoundPlayTime = 0.0; { if (!suppressTargetLost) { - [universe addMessage:[universe expandDescription:@"[target-lost]" forSystem:system_seed] forCount:3.0]; + [universe addMessage:ExpandDescriptionForCurrentSystem(@"[target-lost]") forCount:3.0]; if (![universe playCustomSound:@"[target-lost]"]) [self boop]; } @@ -1880,7 +1862,7 @@ double scoopSoundPlayTime = 0.0; ShipEntity* target_ship = (ShipEntity *)[missile_entity[i] getPrimaryTarget]; if ((!target_ship)||(target_ship->zero_distance > SCANNER_MAX_RANGE2)) { - [universe addMessage:[universe expandDescription:@"[target-lost]" forSystem:system_seed] forCount:3.0]; + [universe addMessage:ExpandDescriptionForCurrentSystem(@"[target-lost]") forCount:3.0]; if (![universe playCustomSound:@"[target-lost]"]) [self boop]; [missile_entity[i] removeTarget:nil]; @@ -1905,7 +1887,7 @@ double scoopSoundPlayTime = 0.0; missile_status = MISSILE_STATUS_TARGET_LOCKED; if ((missile_entity[active_missile])&&(!ident_engaged)) [missile_entity[active_missile] addTarget:first_target]; - [universe addMessage:[NSString stringWithFormat:[universe expandDescription:@"[@-locked-onto-@]" forSystem:system_seed], (ident_engaged)? @"Ident system": @"Missile", [(ShipEntity *)first_target name]] forCount:4.5]; + [universe addMessage:[NSString stringWithFormat:ExpandDescriptionForCurrentSystem(@"[@-locked-onto-@]"), (ident_engaged)? @"Ident system": @"Missile", [(ShipEntity *)first_target name]] forCount:4.5]; if (ident_engaged) { if (![universe playCustomSound:@"[ident-locked-on]"]) @@ -2056,8 +2038,7 @@ double scoopSoundPlayTime = 0.0; { ecm_in_operation = NO; [self stopECMSound]; - //[universe displayMessage:@"ECM system deactivated (no energy left)." forCount:3.0]; - [universe addMessage:[universe expandDescription:@"[ecm-out-of-juice]" forSystem:system_seed] forCount:3.0]; + [universe addMessage:ExpandDescriptionForCurrentSystem(@"[ecm-out-of-juice]") forCount:3.0]; } if ([universe getTime] > ecm_start_time + ECM_DURATION) { @@ -2086,7 +2067,7 @@ double scoopSoundPlayTime = 0.0; fuel_accumulator -= 1.0; } if (fuel > PLAYER_MAX_FUEL) fuel = PLAYER_MAX_FUEL; - [universe displayCountdownMessage:[universe expandDescription:@"[fuel-scoop-active]" forSystem:system_seed] forCount:1.0]; + [universe displayCountdownMessage:ExpandDescriptionForCurrentSystem(@"[fuel-scoop-active]") forCount:1.0]; } } @@ -2115,7 +2096,7 @@ double scoopSoundPlayTime = 0.0; if ([self getPrimaryTarget]) { // restore player ship - ShipEntity *player_ship = [universe getShip: ship_desc]; // retained + ShipEntity *player_ship = [universe newShipWithName: ship_desc]; // retained if (player_ship) { [self setModel:[player_ship getModel]]; @@ -2144,7 +2125,7 @@ double scoopSoundPlayTime = 0.0; { if (![universe playCustomSound:@"[jump-mass-locked]"]) [self boop]; - [universe addMessage:[universe expandDescription:@"[jump-mass-locked]" forSystem:system_seed] forCount:4.5]; + [universe addMessage:ExpandDescriptionForCurrentSystem(@"[jump-mass-locked]") forCount:4.5]; hyperspeed_engaged = NO; } } @@ -2853,13 +2834,7 @@ double scoopSoundPlayTime = 0.0; } if ((alert_condition == ALERT_CONDITION_RED)&&(old_alert_condition < ALERT_CONDITION_RED)) { - // give an audible warning -// NSLog(@"WARNING! %d %x", alert_condition, alert_flags); -#ifdef HAVE_SOUND - if ([warningSound isPlaying]) - [warningSound stop]; - [warningSound play]; -#endif + [self playAlertConditionRed]; } if (alert_condition != old_alert_condition) @@ -2877,34 +2852,27 @@ double scoopSoundPlayTime = 0.0; { if (![universe playCustomSound:@"[hold-full]"]) [self beep]; - [universe addMessage:[universe expandDescription:@"[hold-full]" forSystem:system_seed] forCount:4.5]; + [universe addMessage:ExpandDescriptionForCurrentSystem(@"[hold-full]") forCount:4.5]; } if ([ms isEqual:@"INCOMING_MISSILE"]) { -#ifdef HAVE_SOUND - if (![universe playCustomSound:@"[incoming-missile]"]) - [warningSound play]; -#endif - [universe addMessage:[universe expandDescription:@"[incoming-missile]" forSystem:system_seed] forCount:4.5]; + if (![universe playCustomSound:@"[incoming-missile]"]) [warningSound play]; + [universe addMessage:ExpandDescriptionForCurrentSystem(@"[incoming-missile]") forCount:4.5]; } if ([ms isEqual:@"ENERGY_LOW"]) { [universe playCustomSound:@"[energy-low]"]; - [universe addMessage:[universe expandDescription:@"[energy-low]" forSystem:system_seed] forCount:6.0]; + [universe addMessage:ExpandDescriptionForCurrentSystem(@"[energy-low]") forCount:6.0]; } - if ([ms isEqual:@"ECM"]) - [self playECMSound]; + if ([ms isEqual:@"ECM"]) [self playECMSound]; if ([ms isEqual:@"DOCKING_REFUSED"]&&(status == STATUS_AUTOPILOT_ENGAGED)) { -#ifdef HAVE_SOUND - if (![universe playCustomSound:@"[autopilot-denied]"]) - [warningSound play]; -#endif - [universe addMessage:[universe expandDescription:@"[autopilot-denied]" forSystem:system_seed] forCount:4.5]; + if (![universe playCustomSound:@"[autopilot-denied]"]) [warningSound play]; + [universe addMessage:ExpandDescriptionForCurrentSystem(@"[autopilot-denied]") forCount:4.5]; autopilot_engaged = NO; primaryTarget = NO_TARGET; status = STATUS_IN_FLIGHT; @@ -3033,8 +3001,7 @@ double scoopSoundPlayTime = 0.0; [missile setReportAImessages:YES]; [universe addEntity:missile]; - //NSLog(@"Missile collision radius is %.1f",missile->collision_radius); - [missile release]; //release + [missile release]; [(ShipEntity *)target setPrimaryAggressor:self]; [[(ShipEntity *)target getAI] reactToMessage:@"INCOMING_MISSILE"]; @@ -3088,10 +3055,9 @@ double scoopSoundPlayTime = 0.0; [(ShipEntity *)e2 takeEnergyDamage:1000 from:self becauseOf:self]; } } - [universe addMessage:[universe expandDescription:@"[energy-bomb-activated]" forSystem:system_seed] forCount:4.5]; -#ifdef HAVE_SOUND + [universe addMessage:ExpandDescriptionForCurrentSystem(@"[energy-bomb-activated]") forCount:4.5]; [destructionSound play]; -#endif + return YES; } @@ -3104,7 +3070,7 @@ double scoopSoundPlayTime = 0.0; if (weapon_temp / PLAYER_MAX_WEAPON_TEMP >= 0.85) { [universe playCustomSound:@"[weapon-overheat]"]; - [universe addMessage:[universe expandDescription:@"[weapon-overheat]" forSystem:system_seed] forCount:3.0]; + [universe addMessage:ExpandDescriptionForCurrentSystem(@"[weapon-overheat]") forCount:3.0]; return NO; } @@ -3153,7 +3119,7 @@ double scoopSoundPlayTime = 0.0; if (energy <= weapon_energy_per_shot) { - [universe addMessage:[universe expandDescription:@"[weapon-out-of-juice]" forSystem:system_seed] forCount:3.0]; + [universe addMessage:ExpandDescriptionForCurrentSystem(@"[weapon-out-of-juice]") forCount:3.0]; return NO; } @@ -3167,7 +3133,6 @@ double scoopSoundPlayTime = 0.0; case VIEW_NONE: case VIEW_BREAK_PATTERN: case VIEW_FORWARD: -// NSLog(@"forward weapon offset = ( %.2f, %.2f, %.2f)", forwardWeaponOffset.x, forwardWeaponOffset.y, forwardWeaponOffset.z); forward_weapon_temp += weapon_heat_increment_per_shot; break; case VIEW_AFT: @@ -3180,8 +3145,7 @@ double scoopSoundPlayTime = 0.0; starboard_weapon_temp += weapon_heat_increment_per_shot; break; } - - //NSLog(@"%@ firing weapon",name); + switch (weapon_to_be_fired) { case WEAPON_PLASMA_CANNON : @@ -3248,11 +3212,8 @@ double scoopSoundPlayTime = 0.0; if (damageSound) { -#ifdef HAVE_SOUND - if ([damageSound isPlaying]) - [damageSound stop]; + if ([damageSound isPlaying]) [damageSound stop]; [damageSound play]; -#endif } // firing on an innocent ship is an offence @@ -3263,7 +3224,6 @@ double scoopSoundPlayTime = 0.0; if (d_forward >= 0) { - //NSLog(@"hit on FORWARD shields"); forward_shield -= amount; if (forward_shield < 0.0) { @@ -3277,7 +3237,6 @@ double scoopSoundPlayTime = 0.0; } else { - //NSLog(@"hit on AFT shields"); aft_shield -= amount; if (aft_shield < 0.0) { @@ -3296,11 +3255,8 @@ double scoopSoundPlayTime = 0.0; energy -= amount; if (scrapeDamageSound) { -#ifdef HAVE_SOUND - if ([scrapeDamageSound isPlaying]) - [scrapeDamageSound stop]; + if ([scrapeDamageSound isPlaying]) [scrapeDamageSound stop]; [scrapeDamageSound play]; -#endif } ship_temperature += amount; } @@ -3320,11 +3276,7 @@ double scoopSoundPlayTime = 0.0; [self getDestroyed]; } - if (internal_damage) - { -// NSLog(@"DEBUG ***** triggered chance of internal damage! *****"); - [self takeInternalDamage]; - } + if (internal_damage) [self takeInternalDamage]; [ent release]; [other release]; @@ -3351,11 +3303,8 @@ double scoopSoundPlayTime = 0.0; if (scrapeDamageSound) { -#ifdef HAVE_SOUND - if ([scrapeDamageSound isPlaying]) - [scrapeDamageSound stop]; + if ([scrapeDamageSound isPlaying]) [scrapeDamageSound stop]; [scrapeDamageSound play]; -#endif } if (d_forward >= 0) { @@ -3403,11 +3352,7 @@ double scoopSoundPlayTime = 0.0; [self getDestroyed]; } - if (internal_damage) - { -// NSLog(@"DEBUG ***** triggered chance of internal damage! *****"); - [self takeInternalDamage]; - } + if (internal_damage) [self takeInternalDamage]; [ent release]; @@ -3483,7 +3428,7 @@ double scoopSoundPlayTime = 0.0; vel.y = flight_speed * v_forward.y; vel.z = flight_speed * v_forward.z; - doppelganger = [universe getShip: ship_desc]; // retain count = 1 + doppelganger = [universe newShipWithName: ship_desc]; // retain count = 1 if (doppelganger) { [doppelganger setPosition: origin]; // directly below @@ -3534,7 +3479,7 @@ double scoopSoundPlayTime = 0.0; [cargo removeAllObjects]; energy = 25; - [universe addMessage:[universe expandDescription:@"[escape-sequence]" forSystem:system_seed] forCount:4.5]; + [universe addMessage:ExpandDescriptionForCurrentSystem(@"[escape-sequence]") forCount:4.5]; shot_time = 0.0; return result; @@ -3544,14 +3489,14 @@ double scoopSoundPlayTime = 0.0; { if (flight_speed > 4.0 * max_flight_speed) { - [universe addMessage:[universe expandDescription:@"[hold-locked]" forSystem:system_seed] forCount:3.0]; + [universe addMessage:ExpandDescriptionForCurrentSystem(@"[hold-locked]") forCount:3.0]; return CARGO_NOT_CARGO; } int result = [super dumpCargo]; if (result != CARGO_NOT_CARGO) { - [universe addMessage:[NSString stringWithFormat:[universe expandDescription:@"[@-ejected]" forSystem:system_seed],[universe nameForCommodity:result]] forCount:3.0]; + [universe addMessage:[NSString stringWithFormat:ExpandDescriptionForCurrentSystem(@"[@-ejected]") ,[universe nameForCommodity:result]] forCount:3.0]; } return result; } @@ -3576,11 +3521,11 @@ double scoopSoundPlayTime = 0.0; [pod release]; if (contents != CARGO_NOT_CARGO) { - [universe addMessage:[NSString stringWithFormat:[universe expandDescription:@"[@-ready-to-eject]" forSystem:system_seed],[universe nameForCommodity:contents]] forCount:3.0]; + [universe addMessage:[NSString stringWithFormat:ExpandDescriptionForCurrentSystem(@"[@-ready-to-eject]"), [universe nameForCommodity:contents]] forCount:3.0]; } else { - [universe addMessage:[NSString stringWithFormat:[universe expandDescription:@"[ready-to-eject-@]" forSystem:system_seed],[pod name]] forCount:3.0]; + [universe addMessage:[NSString stringWithFormat:ExpandDescriptionForCurrentSystem(@"[ready-to-eject-@]") ,[pod name]] forCount:3.0]; } // now scan through the remaining 1..(n_cargo - rotates) places moving similar cargo to the last place // this means the cargo gets to be sorted as it is rotated through @@ -3628,13 +3573,10 @@ double scoopSoundPlayTime = 0.0; if (![universe strict]) // only mess with the scores if we're not in 'strict' mode { BOOL killIsCargo = ((killClass == CLASS_CARGO)&&([other getCommodityAmount] > 0)); -// NSLog(@"DEBUG universe not strict killClass is %d", killClass); if ((killIsCargo)||(killClass == CLASS_BUOY)||(killClass == CLASS_ROCK)) { -// NSLog(@"DEBUG killClass not suitable for high reward"); if (![[other roles] isEqual:@"tharglet"]) // okay, we'll count tharglets as proper kills { -// NSLog(@"DEBUG reducing award"); score /= 10; // reduce bounty awarded kill_award = 0; // don't award a kill } @@ -3645,8 +3587,8 @@ double scoopSoundPlayTime = 0.0; if (score) { - NSString* bonusMS1 = [NSString stringWithFormat:[universe expandDescription:@"[bounty-d]" forSystem:system_seed], score / 10]; - NSString* bonusMS2 = [NSString stringWithFormat:[universe expandDescription:@"[total-f-credits]" forSystem:system_seed], 0.1 * credits]; + NSString* bonusMS1 = [NSString stringWithFormat:ExpandDescriptionForCurrentSystem(@"[bounty-d]"), score / 10]; + NSString* bonusMS2 = [NSString stringWithFormat:ExpandDescriptionForCurrentSystem(@"[total-f-credits]"), 0.1 * credits]; if (score > 9) [universe addDelayedMessage:bonusMS1 forCount:6 afterDelay:0.15]; @@ -3660,7 +3602,7 @@ double scoopSoundPlayTime = 0.0; if ((ship_kills % 256) == 0) { // congratulations method needs to be delayed a fraction of a second - NSString* roc = [universe expandDescription:@"[right-on-commander]" forSystem:system_seed]; + NSString* roc = ExpandDescriptionForCurrentSystem(@"[right-on-commander]"); [universe addDelayedMessage:roc forCount:4 afterDelay:0.2]; } } @@ -3680,7 +3622,7 @@ double scoopSoundPlayTime = 0.0; if (!cargo_desc) return; [universe clearPreviousMessage]; - [universe addMessage:[NSString stringWithFormat:[universe expandDescription:@"[@-destroyed]" forSystem:system_seed],cargo_desc] forCount:4.5]; + [universe addMessage:[NSString stringWithFormat:ExpandDescriptionForCurrentSystem(@"[@-destroyed]"), cargo_desc] forCount:4.5]; [cargo removeObject:pod]; return; } @@ -3712,11 +3654,11 @@ double scoopSoundPlayTime = 0.0; [self removeEquipment:system_key]; if (![universe strict]) { - [universe addMessage:[NSString stringWithFormat:[universe expandDescription:@"[@-damaged]" forSystem:system_seed],system_name] forCount:4.5]; + [universe addMessage:[NSString stringWithFormat:ExpandDescriptionForCurrentSystem(@"[@-damaged]"), system_name] forCount:4.5]; [self add_extra_equipment:[NSString stringWithFormat:@"%@_DAMAGED", system_key]]; // for possible future repair } else - [universe addMessage:[NSString stringWithFormat:[universe expandDescription:@"[@-destroyed]" forSystem:system_seed],system_name] forCount:4.5]; + [universe addMessage:[NSString stringWithFormat:ExpandDescriptionForCurrentSystem(@"[@-destroyed]"), system_name] forCount:4.5]; return; } //cosmetic damage @@ -3745,10 +3687,9 @@ double scoopSoundPlayTime = 0.0; [self becomeLargeExplosion:4.0]; [self moveForward:100.0]; -#ifdef HAVE_SOUND [universe playCustomSound:@"[game-over]"]; [destructionSound play]; -#endif + flight_speed = 160.0; status = STATUS_DEAD; [universe displayMessage:@"Game Over" forCount:30.0]; @@ -4125,7 +4066,6 @@ double scoopSoundPlayTime = 0.0; } else { - //NSLog(@"---> Witchspace misjump"); // move sort of halfway there... galaxy_coordinates.x += target_system_seed.d; galaxy_coordinates.y += target_system_seed.b; @@ -4185,7 +4125,6 @@ double scoopSoundPlayTime = 0.0; filename = [[(MyOpenGLView *)[universe gameView] gameController] playerFileToLoad]; if (!filename) { - // NSBeep(); // AppKit NSLog(@"ERROR no filename returned by [[(MyOpenGLView *)[universe gameView] gameController] playerFileToLoad]"); NSException* myException = [NSException exceptionWithName:@"GameNotSavedException" @@ -4196,7 +4135,6 @@ double scoopSoundPlayTime = 0.0; } if (![[self commanderDataDictionary] writeOOXMLToFile:filename atomically:YES]) { - // NSBeep(); //AppKit NSLog(@"***** ERROR: Save to %@ failed!", filename); NSException* myException = [NSException exceptionWithName:@"OoliteException" @@ -4209,7 +4147,7 @@ double scoopSoundPlayTime = 0.0; { [universe clearPreviousMessage]; // allow this to be given time and again - [universe addMessage:[universe expandDescription:@"[game-saved]" forSystem:system_seed] forCount:2]; + [universe addMessage:ExpandDescriptionForCurrentSystem(@"[game-saved]") forCount:2]; if (save_path) [save_path autorelease]; save_path = [filename retain]; @@ -4241,15 +4179,11 @@ double scoopSoundPlayTime = 0.0; NSArray* path_components = [[sp filename] pathComponents]; NSString* new_name = [[path_components objectAtIndex:[path_components count]-1] stringByDeletingPathExtension]; - //NSLog(@"Attempting to save to %@",[sp filename]); - //NSLog(@"Will set Commander's name to %@", new_name); - if (player_name) [player_name release]; player_name = [new_name retain]; if (![[self commanderDataDictionary] writeOOXMLToFile:[sp filename] atomically:YES]) { - // NSBeep(); // AppKit NSLog(@"***** ERROR: Save to %@ failed!", [sp filename]); NSException* myException = [NSException exceptionWithName:@"OoliteException" @@ -4304,7 +4238,7 @@ double scoopSoundPlayTime = 0.0; loadedOK = NO; if ([[localException name] isEqual: OOLITE_EXCEPTION_SHIP_NOT_FOUND]) { - NSLog(@"***** Oolite Exception : '%@' in [PlayerEntity loadPlayerFromFile: %@ ] *****", [localException reason], fileToOpen); + OOLog(kOOLogException, @"***** Oolite Exception : '%@' in [PlayerEntity loadPlayerFromFile: %@ ] *****", [localException reason], fileToOpen); fail_reason = @"Couldn't load Commander details for some reason (AddOns folder missing an OXP perhaps?)"; } else @@ -4325,7 +4259,6 @@ double scoopSoundPlayTime = 0.0; else { NSLog(@"***** FILE LOADING ERROR!! *****"); - // NSBeep(); AppKit [[universe gameController] setPlayerFileToLoad:nil]; [universe game_over]; [universe clearPreviousMessage]; @@ -4392,8 +4325,6 @@ double scoopSoundPlayTime = 0.0; NSString* targetSystemName; NSString* text; - //NSLog(@"DEBUG original hold size = %d",original_hold_size); - system_seed = [universe findSystemAtCoords:galaxy_coordinates withGalaxySeed:galaxy_seed]; target_system_seed = [universe findSystemAtCoords:cursor_coordinates withGalaxySeed:galaxy_seed]; @@ -4475,7 +4406,6 @@ double scoopSoundPlayTime = 0.0; } /* ends */ - //NSLog(@"gui_screen = GUI_SCREEN_STATUS"); if (lastTextKey) { [lastTextKey release]; @@ -4561,8 +4491,6 @@ double scoopSoundPlayTime = 0.0; NSString *grams = (NSString *)[descriptions objectForKey:@"cargo-grams-symbol"]; NSString *kilograms = (NSString *)[descriptions objectForKey:@"cargo-kilograms-symbol"]; -// NSLog(@"DEBUG ::::: %@", [shipCommodityData description]); - if (specialCargo) [manifest addObject:specialCargo]; @@ -4591,11 +4519,6 @@ double scoopSoundPlayTime = 0.0; [manifest addObject:[NSString stringWithFormat:@"%d%@ x %@", in_hold[i], units, desc]]; } } - -// // debug -// NSLog(@"DEBUG shipCommodityData:-\n%@", [shipCommodityData description]); -// NSLog(@"DEBUG manifest:-\n%@", [manifest description]); - return [NSArray arrayWithArray:manifest]; } @@ -4606,8 +4529,6 @@ double scoopSoundPlayTime = 0.0; NSString* targetSystemName; NSDictionary* descriptions = [universe descriptions]; -// target_system_seed = [universe findSystemAtCoords:cursor_coordinates withGalaxySeed:galaxy_seed]; - targetSystemData = [[universe generateSystemData:target_system_seed] retain]; // retained targetSystemName = [[universe getSystemName:target_system_seed] retain]; // retained @@ -4643,7 +4564,7 @@ double scoopSoundPlayTime = 0.0; population = 0; productivity = 0; radius = 0; - system_desc = [universe expandDescription:@"[nova-system-description]" forSystem:target_system_seed]; + system_desc = ExpandDescriptionForCurrentSystem(@"[nova-system-description]"); } [gui clear]; @@ -4673,16 +4594,14 @@ double scoopSoundPlayTime = 0.0; } /* ends */ - //NSLog(@"gui_screen = GUI_SCREEN_SYSTEM_DATA for system %@ at (%d,%d)",targetSystemName,target_system_seed.d,target_system_seed.b); - if (lastTextKey) { [lastTextKey release]; lastTextKey = nil; } - [targetSystemData release]; // released - [targetSystemName release]; // released + [targetSystemData release]; + [targetSystemName release]; gui_screen = GUI_SCREEN_SYSTEM_DATA; @@ -4760,11 +4679,9 @@ double scoopSoundPlayTime = 0.0; } /* ends */ - //NSLog(@"gui_screen = GUI_SCREEN_LONG_RANGE_CHART"); - gui_screen = GUI_SCREEN_LONG_RANGE_CHART; - [targetSystemName release]; // released + [targetSystemName release]; [self setShowDemoShips: NO]; [universe setDisplayText: YES]; @@ -4968,8 +4885,6 @@ double scoopSoundPlayTime = 0.0; target_system_seed = [universe findSystemAtCoords:cursor_coordinates withGalaxySeed:galaxy_seed]; targetSystemName = [[universe getSystemName:target_system_seed] retain]; // retained - //NSLog(@"found %@ at (%d, %d)",targetSystemName,(int)cursor_coordinates.x,(int)cursor_coordinates.y); - // GUI stuff { GuiDisplayGen* gui = [universe gui]; @@ -4988,8 +4903,6 @@ double scoopSoundPlayTime = 0.0; } /* ends */ - //NSLog(@"gui_screen = GUI_SCREEN_LONG_RANGE_CHART"); - gui_screen = GUI_SCREEN_SHORT_RANGE_CHART; [targetSystemName release]; // released @@ -5193,8 +5106,6 @@ double scoopSoundPlayTime = 0.0; } /* ends */ - //NSLog(@"gui_screen = GUI_SCREEN_OPTIONS"); - [self setShowDemoShips:NO]; gui_screen = GUI_SCREEN_OPTIONS; @@ -5210,8 +5121,6 @@ static int last_outfitting_index; { missiles = [self calc_missiles]; -// NSLog(@"DEBUG EquipShipScreen missiles = %d", missiles); - // if skip < 0 then use the last recorded index if (skip < 0) { @@ -5544,15 +5453,15 @@ static int last_outfitting_index; [gui clear]; [gui setTitle:@"Oolite"]; - text = [universe expandDescription:@"[game-copyright]" forSystem:system_seed]; + text = ExpandDescriptionForCurrentSystem(@"[game-copyright]"); [gui setText:text forRow:17 align:GUI_ALIGN_CENTER]; [gui setColor:[OOColor whiteColor] forRow:17]; - text = [universe expandDescription:@"[theme-music-credit]" forSystem:system_seed]; + text = ExpandDescriptionForCurrentSystem(@"[theme-music-credit]"); [gui setText:text forRow:19 align:GUI_ALIGN_CENTER]; [gui setColor:[OOColor grayColor] forRow:19]; - text = [universe expandDescription:@"[load-previous-commander]" forSystem:system_seed]; + text = ExpandDescriptionForCurrentSystem(@"[load-previous-commander]"); [gui setText:text forRow:21 align:GUI_ALIGN_CENTER]; [gui setColor:[OOColor yellowColor] forRow:21]; @@ -5569,7 +5478,6 @@ static int last_outfitting_index; // check for messages from the command line NSArray* arguments = [[NSProcessInfo processInfo] arguments]; - //NSLog(@"DEBUG arguments:\n%@",[arguments description]); int i; for (i = 0; i < [arguments count]; i++) { @@ -5616,7 +5524,7 @@ static int last_outfitting_index; [gui clear]; [gui setTitle:@"Oolite"]; - text = [universe expandDescription:@"[press-space-commander]" forSystem:system_seed]; + text = ExpandDescriptionForCurrentSystem(@"[press-space-commander]"); [gui setText:text forRow:21 align:GUI_ALIGN_CENTER]; [gui setColor:[OOColor yellowColor] forRow:21]; @@ -5660,7 +5568,7 @@ static int last_outfitting_index; chosen_weapon_facing = WEAPON_FACING_PORT; if ([item_text isEqual:STARBOARD_FACING_STRING]) chosen_weapon_facing = WEAPON_FACING_STARBOARD; - //NSLog(@"Try Buying Item %d",item); + int old_credits = credits; if ([self tryBuyingItem:item]) { @@ -5841,14 +5749,14 @@ static int last_outfitting_index; ship_trade_in_factor += 5 + techlevel; // you get better value at high-tech repair bases if (ship_trade_in_factor > 100) ship_trade_in_factor = 100; -// NSLog(@"DEBUG : Ship trade in value now %d\%", ship_trade_in_factor); + [self setGuiToEquipShipScreen:-1:-1]; return YES; } if ([eq_key hasSuffix:@"MISSILE"]||[eq_key hasSuffix:@"MINE"]) { - ShipEntity* weapon = [[universe getShipWithRole:eq_key] autorelease]; + ShipEntity* weapon = [[universe newShipWithRole:eq_key] autorelease]; if (weapon) OOLog(kOOLogBuyMountedOK, @"Got ship for mounted weapon role %@", eq_key); else OOLog(kOOLogBuyMountedFailed, @"Could not find ship for mounted weapon role %@", eq_key); @@ -5896,7 +5804,6 @@ static int last_outfitting_index; { NSString* weapon_key = [weapon roles]; int weapon_value = [universe getPriceForWeaponSystemWithKey:weapon_key]; -// NSLog(@"..... selling a %@ worth %f", weapon_key, 0.1 * weapon_value); credits += weapon_value; [universe recycleOrDiscard: weapon]; [weapon release]; @@ -5913,7 +5820,6 @@ static int last_outfitting_index; NSString *w_key = (NSString *)[(NSArray *)[equipdata objectAtIndex:i] objectAtIndex:EQUIPMENT_KEY_INDEX]; if (([eq_key isEqual:w_key])&&(![self has_extra_equipment:eq_key])) { - //NSLog(@"adding %@",eq_key); credits -= price; [self add_extra_equipment:eq_key]; [self setGuiToEquipShipScreen:-1:-1]; @@ -5970,8 +5876,7 @@ static int last_outfitting_index; else localMarket = [[universe station] initialiseLocalMarketWithSeed:system_seed andRandomFactor:market_rnd]; } - -// NSLog(@"DEBUG local market = %@ [universe station] = %@", [localMarket description], [universe station]); + // fix problems with economies in witch-space if (![universe station]) { @@ -6326,11 +6231,9 @@ OOSound* burnersound; burnersound = afterburner2Sound; else burnersound = afterburner1Sound; - -// NSLog(@"DEBUG loopAfterburnerSound playing sound %@", burnersound); -#ifdef HAVE_SOUND + [burnersound play]; -#endif + [self performSelector:_loopAfterburnerSoundSelector withObject:NULL afterDelay:1.25]; // and swap sounds in 1.25s time @@ -6380,7 +6283,7 @@ OOSound* burnersound; credits -= fine; } fine /= 10; // divide by ten for display - NSString* fined_message = [NSString stringWithFormat:[universe expandDescription:@"[fined]" forSystem:system_seed], fine]; + NSString* fined_message = [NSString stringWithFormat:ExpandDescriptionForCurrentSystem(@"[fined]"), fine]; [universe addMessage:fined_message forCount:6]; ship_clock_adjust = 24 * 3600; // take up a day if (gui_screen != GUI_SCREEN_STATUS) @@ -6430,8 +6333,6 @@ OOSound* burnersound; - (void) setUpTrumbles { -// NSLog(@"DEBUG setting up trumbles for %@%@", player_name, basefile); - NSMutableString* trumbleDigrams = [NSMutableString stringWithCapacity:256]; unichar xchar = (unichar)0; unichar digramchars[2]; @@ -6542,7 +6443,6 @@ OOSound* burnersound; NSString* namekey = [NSString stringWithFormat:@"%@-humbletrash", player_name]; [self setUpTrumbles]; -// NSLog(@"DEBUG setting trumble values from %@", trumbleValue); if (trumbleValue) { @@ -6618,8 +6518,6 @@ OOSound* burnersound; // at this stage we've done the best we can to stop cheaters n_trumbles = putativeNTrumbles; -// NSLog(@"DEBUG putativeTrumbleArray = \n%@", putativeTrumbleArray); - if ((putativeTrumbleArray != nil) && ([putativeTrumbleArray count] == PLAYER_MAX_TRUMBLES)) { for (i = 0; i < PLAYER_MAX_TRUMBLES; i++) @@ -6724,7 +6622,7 @@ OOSound* burnersound; { [super addTarget:potential_target]; missile_status = MISSILE_STATUS_TARGET_LOCKED; - [universe addMessage:[NSString stringWithFormat:[universe expandDescription:@"[@-locked-onto-@]" forSystem:system_seed], (ident_engaged)? @"Ident system": @"Missile", [(ShipEntity *)potential_target name]] forCount:4.5]; + [universe addMessage:[NSString stringWithFormat:ExpandDescriptionForCurrentSystem(@"[@-locked-onto-@]"), (ident_engaged)? @"Ident system": @"Missile", [(ShipEntity *)potential_target name]] forCount:4.5]; return YES; } } @@ -6750,7 +6648,7 @@ OOSound* burnersound; { [super addTarget:potential_target]; missile_status = MISSILE_STATUS_TARGET_LOCKED; - [universe addMessage:[NSString stringWithFormat:[universe expandDescription:@"[@-locked-onto-@]" forSystem:system_seed], (ident_engaged)? @"Ident system": @"Missile", [(ShipEntity *)potential_target name]] forCount:4.5]; + [universe addMessage:[NSString stringWithFormat:ExpandDescriptionForCurrentSystem(@"[@-locked-onto-@]"), (ident_engaged)? @"Ident system": @"Missile", [(ShipEntity *)potential_target name]] forCount:4.5]; return YES; } } diff --git a/src/Core/PlayerEntityContracts.m b/src/Core/PlayerEntityContracts.m index 207bf7b7..9d4edbef 100644 --- a/src/Core/PlayerEntityContracts.m +++ b/src/Core/PlayerEntityContracts.m @@ -80,7 +80,7 @@ static NSString * const kOOLogNoteShowShipyardModel = @"script.debug.note.showSh else if ([rescuee insuranceCredits]) { // claim insurance reward - [result appendFormat:[universe expandDescription:@"[rescue-reward-for-@@-f-credits]\n" forSystem:system_seed], + [result appendFormat:ExpandDescriptionForCurrentSystem(@"[rescue-reward-for-@@-f-credits]\n"), [rescuee name], [rescuee shortDescription], (float)[rescuee insuranceCredits]]; credits += 10 * [rescuee insuranceCredits]; } @@ -88,7 +88,7 @@ static NSString * const kOOLogNoteShowShipyardModel = @"script.debug.note.showSh { // claim bounty for capture float reward = (5.0 + government) * [rescuee legalStatus]; - [result appendFormat:[universe expandDescription:@"[capture-reward-for-@@-f-credits]\n" forSystem:system_seed], + [result appendFormat:ExpandDescriptionForCurrentSystem(@"[capture-reward-for-@@-f-credits]\n"), [rescuee name], [rescuee shortDescription], 0.1f * reward]; credits += reward; } @@ -141,9 +141,9 @@ static NSString * const kOOLogNoteShowShipyardModel = @"script.debug.note.showSh } credits += 10 * fee; if (!result) - result = [NSString stringWithFormat:[universe expandDescription:@"[passenger-delivered-okay-@-d-@]" forSystem:system_seed], passenger_name, fee, passenger_dest_name]; + result = [NSString stringWithFormat:ExpandDescriptionForCurrentSystem(@"[passenger-delivered-okay-@-d-@]"), passenger_name, fee, passenger_dest_name]; else - result = [NSString stringWithFormat:[universe expandDescription:@"%@\n[passenger-delivered-okay-@-d-@]" forSystem:system_seed], result, passenger_name, fee, passenger_dest_name]; + result = [NSString stringWithFormat:ExpandDescriptionForCurrentSystem(@"%@\n[passenger-delivered-okay-@-d-@]"), result, passenger_name, fee, passenger_dest_name]; [passengers removeObjectAtIndex:i--]; [self increasePassengerReputation]; } @@ -155,9 +155,9 @@ static NSString * const kOOLogNoteShowShipyardModel = @"script.debug.note.showSh fee /= 2; credits += 10 * fee; if (!result) - result = [NSString stringWithFormat:[universe expandDescription:@"[passenger-delivered-late-@-d-@]" forSystem:system_seed], passenger_name, fee, passenger_dest_name]; + result = [NSString stringWithFormat:ExpandDescriptionForCurrentSystem(@"[passenger-delivered-late-@-d-@]"), passenger_name, fee, passenger_dest_name]; else - result = [NSString stringWithFormat:[universe expandDescription:@"%@\n[passenger-delivered-late-@-d-@]" forSystem:system_seed], result, passenger_name, fee, passenger_dest_name]; + result = [NSString stringWithFormat:ExpandDescriptionForCurrentSystem(@"%@\n[passenger-delivered-late-@-d-@]"), result, passenger_name, fee, passenger_dest_name]; [passengers removeObjectAtIndex:i--]; } } @@ -167,9 +167,9 @@ static NSString * const kOOLogNoteShowShipyardModel = @"script.debug.note.showSh { // we've run out of time! if (!result) - result = [NSString stringWithFormat:[universe expandDescription:@"[passenger-failed-@]" forSystem:system_seed], passenger_name]; + result = [NSString stringWithFormat:ExpandDescriptionForCurrentSystem(@"[passenger-failed-@]"), passenger_name]; else - result = [NSString stringWithFormat:[universe expandDescription:@"%@\n[passenger-failed-@]" forSystem:system_seed], result, passenger_name]; + result = [NSString stringWithFormat:ExpandDescriptionForCurrentSystem(@"%@\n[passenger-failed-@]"), result, passenger_name]; [passengers removeObjectAtIndex:i--]; [self decreasePassengerReputation]; } @@ -215,9 +215,9 @@ static NSString * const kOOLogNoteShowShipyardModel = @"script.debug.note.showSh // pay the premium and fee credits += fee + premium; if (!result) - result = [NSString stringWithFormat:[universe expandDescription:@"[cargo-delivered-okay-@-f]" forSystem:system_seed], contract_cargo_desc, (float)(fee + premium) / 10.0]; + result = [NSString stringWithFormat:ExpandDescriptionForCurrentSystem(@"[cargo-delivered-okay-@-f]"), contract_cargo_desc, (float)(fee + premium) / 10.0]; else - result = [NSString stringWithFormat:[universe expandDescription:@"%@\n[cargo-delivered-okay-@-f]" forSystem:system_seed], result, contract_cargo_desc, (float)(fee + premium) / 10.0]; + result = [NSString stringWithFormat:ExpandDescriptionForCurrentSystem(@"%@\n[cargo-delivered-okay-@-f]"), result, contract_cargo_desc, (float)(fee + premium) / 10.0]; [contracts removeObjectAtIndex:i--]; // repute++ [self increaseContractReputation]; @@ -244,18 +244,18 @@ static NSString * const kOOLogNoteShowShipyardModel = @"script.debug.note.showSh int payment = percent_delivered * (fee + premium) / 100.0; credits += payment; if (!result) - result = [NSString stringWithFormat:[universe expandDescription:@"[cargo-delivered-short-@-f-d]" forSystem:system_seed], contract_cargo_desc, (float)payment / 10.0, shortfall]; + result = [NSString stringWithFormat:ExpandDescriptionForCurrentSystem(@"[cargo-delivered-short-@-f-d]"), contract_cargo_desc, (float)payment / 10.0, shortfall]; else - result = [NSString stringWithFormat:[universe expandDescription:@"%@\n[cargo-delivered-short-@-f-d]" forSystem:system_seed], contract_cargo_desc, (float)payment / 10.0, shortfall]; + result = [NSString stringWithFormat:ExpandDescriptionForCurrentSystem(@"%@\n[cargo-delivered-short-@-f-d]"), contract_cargo_desc, (float)payment / 10.0, shortfall]; [contracts removeObjectAtIndex:i--]; // repute unchanged } else { if (!result) - result = [NSString stringWithFormat:[universe expandDescription:@"[cargo-refused-short-%@]" forSystem:system_seed], contract_cargo_desc]; + result = [NSString stringWithFormat:ExpandDescriptionForCurrentSystem(@"[cargo-refused-short-%@]"), contract_cargo_desc]; else - result = [NSString stringWithFormat:[universe expandDescription:@"%@\n[cargo-refused-short-%@]" forSystem:system_seed], contract_cargo_desc]; + result = [NSString stringWithFormat:ExpandDescriptionForCurrentSystem(@"%@\n[cargo-refused-short-%@]"), contract_cargo_desc]; } } } @@ -263,9 +263,9 @@ static NSString * const kOOLogNoteShowShipyardModel = @"script.debug.note.showSh { // but we're late! if (!result) - result = [NSString stringWithFormat:[universe expandDescription:@"[cargo-delivered-late-@]" forSystem:system_seed], contract_cargo_desc]; + result = [NSString stringWithFormat:ExpandDescriptionForCurrentSystem(@"[cargo-delivered-late-@]"), contract_cargo_desc]; else - result = [NSString stringWithFormat:[universe expandDescription:@"%@\n[cargo-delivered-late-@]" forSystem:system_seed], result, contract_cargo_desc]; + result = [NSString stringWithFormat:ExpandDescriptionForCurrentSystem(@"%@\n[cargo-delivered-late-@]"), result, contract_cargo_desc]; [contracts removeObjectAtIndex:i--]; // repute-- [self decreaseContractReputation]; @@ -277,9 +277,9 @@ static NSString * const kOOLogNoteShowShipyardModel = @"script.debug.note.showSh { // we've run out of time! if (!result) - result = [NSString stringWithFormat:[universe expandDescription:@"[cargo-failed-@]" forSystem:system_seed], contract_cargo_desc]; + result = [NSString stringWithFormat:ExpandDescriptionForCurrentSystem(@"[cargo-failed-@]"), contract_cargo_desc]; else - result = [NSString stringWithFormat:[universe expandDescription:@"%@\n[cargo-failed-@]" forSystem:system_seed], result, contract_cargo_desc]; + result = [NSString stringWithFormat:ExpandDescriptionForCurrentSystem(@"%@\n[cargo-failed-@]"), result, contract_cargo_desc]; [contracts removeObjectAtIndex:i--]; // repute-- [self decreaseContractReputation]; @@ -696,8 +696,6 @@ static NSString * const kOOLogNoteShowShipyardModel = @"script.debug.note.showSh [passenger_market removeObject:passenger_info]; credits += 10 * passenger_premium; -// NSLog(@"DEBUG passengers:\n%@", [passengers description]); - return YES; } @@ -743,8 +741,6 @@ static NSString * const kOOLogNoteShowShipyardModel = @"script.debug.note.showSh [contract_record setObject:contract_arrival_time forKey:contract_id]; [contract_market removeObject:contract_info]; -// NSLog(@"DEBUG contracts:\n%@", [contracts description]); - return YES; } return NO; @@ -967,7 +963,7 @@ static NSString * const kOOLogNoteShowShipyardModel = @"script.debug.note.showSh // GUI stuff { [gui clear]; - [gui setTitle:[universe expandDescription:@"[arrival-report-title]" forSystem:system_seed]]; + [gui setTitle:ExpandDescriptionForCurrentSystem(@"[arrival-report-title]")]; // // report might be a multi-line message @@ -1017,7 +1013,7 @@ static NSString * const kOOLogNoteShowShipyardModel = @"script.debug.note.showSh // GUI stuff { [gui clear]; - [gui setTitle:[universe expandDescription:@"[arrival-report-title]" forSystem:system_seed]]; + [gui setTitle:ExpandDescriptionForCurrentSystem(@"[arrival-report-title]")]; // // dockingReport might be a multi-line message @@ -1159,9 +1155,6 @@ static NSMutableDictionary* currentShipyard = nil; } } -// NSLog(@"DEBUG Ships for sale n_ships:%d MAX_ROWS_SHIPS_FOR_SALE:%d n_rows:%d skip:%d", n_ships, MAX_ROWS_SHIPS_FOR_SALE, n_rows, skip); - - // if (n_ships > 0) { [gui setColor:[OOColor greenColor] forRow:GUI_ROW_SHIPYARD_LABELS]; @@ -1227,8 +1220,6 @@ static NSMutableDictionary* currentShipyard = nil; GuiDisplayGen* gui = [universe gui]; int sel_row = [gui selectedRow]; -// NSLog(@"-- %d %d %d", sel_row, [gui selectableRange].location, [gui selectableRange].length); - if (sel_row <= 0) return; @@ -1238,7 +1229,6 @@ static NSMutableDictionary* currentShipyard = nil; NSString* key = [gui keyForRow:sel_row]; -// NSDictionary* info = (NSDictionary *)[[docked_station localShipyard] objectAtIndex:sel_row - GUI_ROW_SHIPYARD_START]; NSDictionary* info = (NSDictionary *)[currentShipyard objectForKey:key]; if (info) @@ -1330,12 +1320,8 @@ static NSMutableDictionary* currentShipyard = nil; if ([key hasPrefix:@"More:"]) { -// NSLog(@"DEBUG Key is '%@'", key); - int from_ship = [(NSString*)[[key componentsSeparatedByString:@":"] objectAtIndex:1] intValue]; - -// NSLog(@"DEBUG skipping %d", from_ship); - + [self setGuiToShipyardScreen:from_ship]; if ([[universe gui] selectedRow] < 0) [[universe gui] setSelectedRow:GUI_ROW_SHIPYARD_START]; @@ -1389,8 +1375,6 @@ static NSMutableDictionary* currentShipyard = nil; starboard_weapon = WEAPON_NONE; forward_weapon = [universe weaponForEquipmentKey:(NSString*)[(NSDictionary*)[ship_info objectForKey:SHIPYARD_KEY_SHIP] objectForKey:@"forward_weapon_type"]]; -// NSLog(@"%@ (%d) from %@",[(NSDictionary*)[ship_info objectForKey:SHIPYARD_KEY_SHIP] objectForKey:@"forward_weapon_type"],forward_weapon,[[ship_info objectForKey:SHIPYARD_KEY_SHIP] description]); - // get basic max_cargo max_cargo = [universe maxCargoForShip:ship_desc]; diff --git a/src/Core/PlayerEntityControls.m b/src/Core/PlayerEntityControls.m index 95882804..fa461ecb 100644 --- a/src/Core/PlayerEntityControls.m +++ b/src/Core/PlayerEntityControls.m @@ -173,7 +173,7 @@ static NSTimeInterval time_last_frame; { if ((fuel > 0)&&(!afterburner_engaged)) { - [universe addMessage:[universe expandDescription:@"[fuel-inject-on]" forSystem:system_seed] forCount:1.5]; + [universe addMessage:ExpandDescriptionForCurrentSystem(@"[fuel-inject-on]") forCount:1.5]; afterburner_engaged = YES; if (!afterburnerSoundLooping) [self loopAfterburnerSound]; @@ -181,7 +181,7 @@ static NSTimeInterval time_last_frame; else { if (fuel <= 0.0) - [universe addMessage:[universe expandDescription:@"[fuel-out]" forSystem:system_seed] forCount:1.5]; + [universe addMessage:ExpandDescriptionForCurrentSystem(@"[fuel-out]") forCount:1.5]; } afterburner_engaged = (fuel > 0); } @@ -268,7 +268,7 @@ static NSTimeInterval time_last_frame; { if (![universe playCustomSound:@"[jump-mass-locked]"]) [self boop]; - [universe addMessage:[universe expandDescription:@"[jump-mass-locked]" forSystem:system_seed] forCount:1.5]; + [universe addMessage:ExpandDescriptionForCurrentSystem(@"[jump-mass-locked]") forCount:1.5]; } } else @@ -296,7 +296,6 @@ static NSTimeInterval time_last_frame; { if (target_laser_hit != NO_TARGET) { -#ifdef HAVE_SOUND if (weaponHitSound) { if ([weaponHitSound isPlaying]) @@ -308,11 +307,9 @@ static NSTimeInterval time_last_frame; { if (weaponSound) { - if ([weaponSound isPlaying]) - [weaponSound stop]; + if ([weaponSound isPlaying]) [weaponSound stop]; [weaponSound play]; } -#endif } } } @@ -331,10 +328,7 @@ static NSTimeInterval time_last_frame; BOOL missile_noise = [[missile_entity[active_missile] roles] hasSuffix:@"MISSILE"]; if ([self fireMissile]) { -#ifdef HAVE_SOUND - if (missile_noise) - [missileSound play]; -#endif + if (missile_noise) [missileSound play]; } } fire_missile_pressed = YES; @@ -414,7 +408,7 @@ static NSTimeInterval time_last_frame; ident_engaged = YES; if (![universe playCustomSound:@"[ident-on]"]) [self beep]; - [universe addMessage:[universe expandDescription:@"[ident-on]" forSystem:system_seed] forCount:2.0]; + [universe addMessage:ExpandDescriptionForCurrentSystem(@"[ident-on]") forCount:2.0]; } ident_pressed = YES; } @@ -439,7 +433,7 @@ static NSTimeInterval time_last_frame; { missile_status = MISSILE_STATUS_TARGET_LOCKED; [missile_entity[active_missile] addTarget:[self getPrimaryTarget]]; - [universe addMessage:[NSString stringWithFormat:[universe expandDescription:@"[missile-locked-onto-@]" forSystem:system_seed], [(ShipEntity *)[self getPrimaryTarget] identFromShip: self]] forCount:4.5]; + [universe addMessage:[NSString stringWithFormat:ExpandDescriptionForCurrentSystem(@"[missile-locked-onto-@]"), [(ShipEntity *)[self getPrimaryTarget] identFromShip: self]] forCount:4.5]; if (![universe playCustomSound:@"[missile-locked-on]"]) [self beep]; } @@ -451,14 +445,14 @@ static NSTimeInterval time_last_frame; { if (missile_entity[active_missile]) [missile_entity[active_missile] removeTarget:nil]; - [universe addMessage:[universe expandDescription:@"[missile-armed]" forSystem:system_seed] forCount:2.0]; + [universe addMessage:ExpandDescriptionForCurrentSystem(@"[missile-armed]") forCount:2.0]; if (![universe playCustomSound:@"[missile-armed]"]) [self beep]; } } if ([[missile_entity[active_missile] roles] hasSuffix:@"MINE"]) { - [universe addMessage:[universe expandDescription:@"[mine-armed]" forSystem:system_seed] forCount:4.5]; + [universe addMessage:ExpandDescriptionForCurrentSystem(@"[mine-armed]") forCount:4.5]; if (![universe playCustomSound:@"[mine-armed]"]) [self beep]; } @@ -487,7 +481,7 @@ static NSTimeInterval time_last_frame; [self safe_all_missiles]; if (![universe playCustomSound:@"[missile-safe]"]) [self boop]; - [universe addMessage:[universe expandDescription:@"[missile-safe]" forSystem:system_seed] forCount:2.0]; + [universe addMessage:ExpandDescriptionForCurrentSystem(@"[missile-safe]") forCount:2.0]; } else { @@ -496,7 +490,7 @@ static NSTimeInterval time_last_frame; missile_status = (primaryTarget != NO_TARGET)? MISSILE_STATUS_TARGET_LOCKED : MISSILE_STATUS_SAFE; if (![universe playCustomSound:@"[ident-off]"]) [self boop]; - [universe addMessage:[universe expandDescription:@"[ident-off]" forSystem:system_seed] forCount:2.0]; + [universe addMessage:ExpandDescriptionForCurrentSystem(@"[ident-off]") forCount:2.0]; } ident_engaged = NO; } @@ -518,7 +512,7 @@ static NSTimeInterval time_last_frame; if ([self fireECM]) { [self playECMSound]; - [universe addMessage:[universe expandDescription:@"[ecm-on]" forSystem:system_seed] forCount:3.0]; + [universe addMessage:ExpandDescriptionForCurrentSystem(@"[ecm-on]") forCount:3.0]; } } } @@ -594,7 +588,7 @@ static NSTimeInterval time_last_frame; isOkayToUseAutopilot = NO; if (![universe playCustomSound:@"[autopilot-out-of-range]"]) [self boop]; - [universe addMessage:[universe expandDescription:@"[autopilot-out-of-range]" forSystem:system_seed] forCount:4.5]; + [universe addMessage:ExpandDescriptionForCurrentSystem(@"[autopilot-out-of-range]") forCount:4.5]; } } // @@ -610,7 +604,7 @@ static NSTimeInterval time_last_frame; [shipAI setState:@"GLOBAL"]; // reboot the AI if (![universe playCustomSound:@"[autopilot-on]"]) [self beep]; - [universe addMessage:[universe expandDescription:@"[autopilot-on]" forSystem:system_seed] forCount:4.5]; + [universe addMessage:ExpandDescriptionForCurrentSystem(@"[autopilot-on]") forCount:4.5]; // if (ootunes_on) { @@ -652,7 +646,7 @@ static NSTimeInterval time_last_frame; [shipAI setState:@"GLOBAL"]; // restart the AI if (![universe playCustomSound:@"[autopilot-on]"]) [self beep]; - [universe addMessage:[universe expandDescription:@"[autopilot-on]" forSystem:system_seed] forCount:4.5]; + [universe addMessage:ExpandDescriptionForCurrentSystem(@"[autopilot-on]") forCount:4.5]; // if (ootunes_on) { @@ -672,7 +666,7 @@ static NSTimeInterval time_last_frame; { if (![universe playCustomSound:@"[autopilot-cannot-dock-with-target]"]) [self boop]; - [universe addMessage:[universe expandDescription:@"Target is not capable of autopilot-docking" forSystem:system_seed] forCount:4.5]; + [universe addMessage:ExpandDescriptionForCurrentSystem(@"Target is not capable of autopilot-docking") forCount:4.5]; } } target_autopilot_key_pressed = YES; @@ -724,7 +718,7 @@ static NSTimeInterval time_last_frame; { if (![universe playCustomSound:@"[autopilot-out-of-range]"]) [self boop]; - [universe addMessage:[universe expandDescription:@"[autopilot-out-of-range]" forSystem:system_seed] forCount:4.5]; + [universe addMessage:ExpandDescriptionForCurrentSystem(@"[autopilot-out-of-range]") forCount:4.5]; } } fast_autopilot_key_pressed = YES; @@ -752,7 +746,7 @@ static NSTimeInterval time_last_frame; if (![universe playCustomSound:@"[witch-no-target]"]) [self boop]; [universe clearPreviousMessage]; - [universe addMessage:[universe expandDescription:@"[witch-no-target]" forSystem:system_seed] forCount:3.0]; + [universe addMessage:ExpandDescriptionForCurrentSystem(@"[witch-no-target]") forCount:3.0]; jumpOK = NO; } @@ -761,7 +755,7 @@ static NSTimeInterval time_last_frame; if (![universe playCustomSound:@"[witch-no-fuel]"]) [self boop]; [universe clearPreviousMessage]; - [universe addMessage:[universe expandDescription:@"[witch-no-fuel]" forSystem:system_seed] forCount:3.0]; + [universe addMessage:ExpandDescriptionForCurrentSystem(@"[witch-no-fuel]") forCount:3.0]; jumpOK = NO; } @@ -779,7 +773,7 @@ static NSTimeInterval time_last_frame; [self boop]; // say it! [universe clearPreviousMessage]; - [universe addMessage:[universe expandDescription:@"[witch-user-abort]" forSystem:system_seed] forCount:3.0]; + [universe addMessage:ExpandDescriptionForCurrentSystem(@"[witch-user-abort]") forCount:3.0]; } if (jumpOK) @@ -791,7 +785,7 @@ static NSTimeInterval time_last_frame; [self beep]; // say it! [universe clearPreviousMessage]; - [universe addMessage:[NSString stringWithFormat:[universe expandDescription:@"[witch-to-@-in-f-seconds]" forSystem:system_seed], [universe getSystemName:target_system_seed], witchspaceCountdown] forCount:1.0]; + [universe addMessage:[NSString stringWithFormat:ExpandDescriptionForCurrentSystem(@"[witch-to-@-in-f-seconds]"), [universe getSystemName:target_system_seed], witchspaceCountdown] forCount:1.0]; } } hyperspace_pressed = YES; @@ -825,7 +819,7 @@ static NSTimeInterval time_last_frame; [self boop]; // say it! [universe clearPreviousMessage]; - [universe addMessage:[universe expandDescription:@"[witch-user-abort]" forSystem:system_seed] forCount:3.0]; + [universe addMessage:ExpandDescriptionForCurrentSystem(@"[witch-user-abort]") forCount:3.0]; } if (jumpOK) @@ -837,7 +831,7 @@ static NSTimeInterval time_last_frame; if (![universe playCustomSound:@"[hyperspace-countdown-begun]"]) [self beep]; // say it! - [universe addMessage:[NSString stringWithFormat:[universe expandDescription:@"[witch-galactic-in-f-seconds]" forSystem:system_seed], witchspaceCountdown] forCount:1.0]; + [universe addMessage:[NSString stringWithFormat:ExpandDescriptionForCurrentSystem(@"[witch-galactic-in-f-seconds]"), witchspaceCountdown] forCount:1.0]; } } galhyperspace_pressed = YES; @@ -858,14 +852,14 @@ static NSTimeInterval time_last_frame; if (!cloaking_device_active) { if ([self activateCloakingDevice]) - [universe addMessage:[universe expandDescription:@"[cloak-on]" forSystem:system_seed] forCount:2]; + [universe addMessage:ExpandDescriptionForCurrentSystem(@"[cloak-on]") forCount:2]; else - [universe addMessage:[universe expandDescription:@"[cloak-low-juice]" forSystem:system_seed] forCount:3]; + [universe addMessage:ExpandDescriptionForCurrentSystem(@"[cloak-low-juice]") forCount:3]; } else { [self deactivateCloakingDevice]; - [universe addMessage:[universe expandDescription:@"[cloak-off]" forSystem:system_seed] forCount:2]; + [universe addMessage:ExpandDescriptionForCurrentSystem(@"[cloak-off]") forCount:2]; } // if (cloaking_device_active) @@ -994,8 +988,8 @@ static NSTimeInterval time_last_frame; { saved_view_direction = [universe viewDir]; saved_script_time = script_time; - [universe addMessage:[universe expandDescription:@"[game-paused]" forSystem:system_seed] forCount:1.0]; - [universe addMessage:[universe expandDescription:@"[game-paused-options]" forSystem:system_seed] forCount:1.0]; + [universe addMessage:ExpandDescriptionForCurrentSystem(@"[game-paused]") forCount:1.0]; + [universe addMessage:ExpandDescriptionForCurrentSystem(@"[game-paused-options]") forCount:1.0]; [[gameView gameController] pause_game]; } } @@ -1030,7 +1024,7 @@ static BOOL taking_snapshot; { [[gameView gameController] exitFullScreenMode]; if (mouse_control_on) - [universe addMessage:[universe expandDescription:@"[mouse-off]" forSystem:system_seed] forCount:3.0]; + [universe addMessage:ExpandDescriptionForCurrentSystem(@"[mouse-off]") forCount:3.0]; mouse_control_on = NO; } // @@ -1065,7 +1059,7 @@ static BOOL taking_snapshot; // if ([gameView isDown: 64]) // '@' { - NSLog(@"%@ status==%@ guiscreen==%@", self, [self status_string], [self gui_screen_string]); + OOLog(@"debug.atKey", @"%@ status==%@ guiscreen==%@", self, [self status_string], [self gui_screen_string]); } // @@ -1108,13 +1102,13 @@ static BOOL taking_snapshot; mouse_control_on = !mouse_control_on; if (mouse_control_on) { - [universe addMessage:[universe expandDescription:@"[mouse-on]" forSystem:system_seed] forCount:3.0]; + [universe addMessage:ExpandDescriptionForCurrentSystem(@"[mouse-on]") forCount:3.0]; // ensure the keyboard pitch override (intended to lock out the joystick if the // player runs to the keyboard) is reset keyboardRollPitchOverride = NO; } else - [universe addMessage:[universe expandDescription:@"[mouse-off]" forSystem:system_seed] forCount:3.0]; + [universe addMessage:ExpandDescriptionForCurrentSystem(@"[mouse-off]") forCount:3.0]; } m_key_pressed = YES; } @@ -1447,7 +1441,6 @@ static BOOL spacePressed; double vscale = 4.0 * MAIN_GUI_PIXEL_HEIGHT / 512.0; cursor_coordinates.x = galaxy_coordinates.x + (maus.x * MAIN_GUI_PIXEL_WIDTH) / hscale; cursor_coordinates.y = galaxy_coordinates.y + (maus.y * MAIN_GUI_PIXEL_HEIGHT + vadjust) / vscale; - //NSLog(@"DEBUG mouse (%.3f,%.3f), coordinates (%.3f,%.3f) vadjust %.1f", maus.x, maus.y, cursor_coordinates.x, cursor_coordinates.y, vadjust); } if (gui_screen == GUI_SCREEN_LONG_RANGE_CHART) { @@ -1457,7 +1450,6 @@ static BOOL spacePressed; double vscale = MAIN_GUI_PIXEL_HEIGHT / 512.0; cursor_coordinates.x = (maus.x * MAIN_GUI_PIXEL_WIDTH + hadjust)/ hscale; cursor_coordinates.y = (maus.y * MAIN_GUI_PIXEL_HEIGHT + vadjust) / vscale; - //NSLog(@"DEBUG mouse (%.3f,%.3f), coordinates (%.3f,%.3f) vadjust %.1f", maus.x, maus.y, cursor_coordinates.x, cursor_coordinates.y, vadjust); } [gameView resetTypedString]; moving = YES; @@ -1594,10 +1586,10 @@ static BOOL spacePressed; disc_operation_in_progress = YES; [self quicksavePlayer]; NS_HANDLER - NSLog(@"\n\n***** Handling localException: %@ : %@ *****\n\n",[localException name], [localException reason]); + OOLog(kOOLogException, @"\n\n***** Handling localException: %@ : %@ *****\n\n",[localException name], [localException reason]); if ([[localException name] isEqual:@"GameNotSavedException"]) // try saving game instead { - NSLog(@"\n\n***** Trying a normal save instead *****\n\n"); + OOLog(kOOLogException, @"\n\n***** Trying a normal save instead *****\n\n"); if ([[universe gameController] inFullScreenMode]) [[universe gameController] pauseFullScreenModeToPerform:@selector(savePlayer) onTarget:self]; else @@ -1663,7 +1655,7 @@ static BOOL spacePressed; int displayModeIndex = [controller indexOfCurrentDisplayMode]; if (displayModeIndex == NSNotFound) { - NSLog(@"***** couldn't find current display mode switching to basic 640x480"); + OOLog(@"graphics.mode.notFound", @"***** couldn't find current display mode switching to basic 640x480"); displayModeIndex = 0; } else @@ -1902,7 +1894,6 @@ static BOOL spacePressed; if (!wait_for_key_up) { int item = [(NSString *)[gui selectedRowKey] intValue]; - //NSLog(@"Try Buying Commodity %d",item); if ([self tryBuyingCommodity:item]) [self setGuiToMarketScreen]; else @@ -1915,7 +1906,6 @@ static BOOL spacePressed; if (!wait_for_key_up) { int item = [(NSString *)[gui selectedRowKey] intValue]; - //NSLog(@"Try Selling Commodity %d",item); if ([self trySellingCommodity:item]) [self setGuiToMarketScreen]; else @@ -1934,13 +1924,11 @@ static BOOL spacePressed; { int item = [(NSString *)[gui selectedRowKey] intValue]; int yours = [(NSNumber *)[(NSArray *)[shipCommodityData objectAtIndex:item] objectAtIndex:1] intValue]; - //NSLog(@"buy/sell all of item %d (you have %d)",item,yours); if ((yours > 0)&&(![self marketFlooded:item])) // sell all you can { int i; for (i = 0; i < yours; i++) [self trySellingCommodity:item]; - //NSLog(@"... you sold %d.", yours); [self playInterfaceBeep:kInterfaceBeep_Sell]; [self setGuiToMarketScreen]; } @@ -1949,7 +1937,6 @@ static BOOL spacePressed; int amount_bought = 0; while ([self tryBuyingCommodity:item]) amount_bought++; - //NSLog(@"... you bought %d.", amount_bought); [self setGuiToMarketScreen]; if (amount_bought == 0) { @@ -2442,7 +2429,7 @@ static BOOL toggling_music; status = STATUS_IN_FLIGHT; if (![universe playCustomSound:@"[autopilot-off]"]) [self beep]; - [universe addMessage:[universe expandDescription:@"[autopilot-off]" forSystem:system_seed] forCount:4.5]; + [universe addMessage:ExpandDescriptionForCurrentSystem(@"[autopilot-off]") forCount:4.5]; // if (ootunes_on) { @@ -2487,7 +2474,6 @@ static BOOL toggling_music; [universe set_up_universe_from_station]; // launch! if (!docked_station) docked_station = [universe station]; - //NSLog(@"Leaving dock (%@)...%@",docked_station,[docked_station name]); [self leaveDock:docked_station]; [universe setDisplayCursor:NO]; } @@ -2583,7 +2569,6 @@ static BOOL toggling_music; case GUI_SCREEN_MISSION : if ([[gui keyForRow:21] isEqual:@"spacebar"]) { -// NSLog(@"GUI_SCREEN_MISSION looking for spacebar"); if ([gameView isDown:32]) // '' { if (!spacePressed) @@ -2602,7 +2587,6 @@ static BOOL toggling_music; } else { -// NSLog(@"GUI_SCREEN_MISSION looking for up/down/select"); if ([gameView isDown:gvArrowKeyDown]) { if ((!upDownKeyPressed)||(script_time > timeLastKeyPress + KEY_REPEAT_INTERVAL)) diff --git a/src/Core/PlayerEntityLoadSave.m b/src/Core/PlayerEntityLoadSave.m index e9920b3a..a8dd81ff 100644 --- a/src/Core/PlayerEntityLoadSave.m +++ b/src/Core/PlayerEntityLoadSave.m @@ -39,6 +39,8 @@ MA 02110-1301, USA. #import "ResourceManager.h" #endif +#define kOOLogUnconvertedNSLog @"unclassified.PlayerEntityLoadSave" + @implementation PlayerEntity (LoadSave) - (void) setGuiToLoadCommanderScreen @@ -510,7 +512,6 @@ MA 02110-1301, USA. if(![[self commanderDataDictionary] writeOOXMLToFile:savePath atomically:YES]) { - //NSBeep(); // appkit dependency NSLog(@"***** ERROR: Save to %@ failed!", savePath); NSException *myException = [NSException exceptionWithName:@"OoliteException" @@ -529,7 +530,7 @@ MA 02110-1301, USA. [[universe gameController] setPlayerFileDirectory:save_path]; [universe clearPreviousMessage]; // allow this to be given time and again - [universe addMessage:[universe expandDescription:@"[game-saved]" forSystem:system_seed] forCount:2]; + [universe addMessage:ExpandDescriptionForCurrentSystem(@"[game-saved]") forCount:2]; } // check for an existing saved game... @@ -607,7 +608,7 @@ MA 02110-1301, USA. } else { - NSLog(@"\n\n***** Encountered localException in [PlayerEntity (LoadSave) showCommanderShip:] : %@ : %@ *****\n\n", [localException name], [localException reason]); + OOLog(kOOLogException, @"***** Exception in [PlayerEntity (LoadSave) showCommanderShip:] : %@ : %@ *****", [localException name], [localException reason]); [localException raise]; } diff --git a/src/Core/PlayerEntityScripting.m b/src/Core/PlayerEntityScripting.m index cbc6a3f8..09b15aed 100644 --- a/src/Core/PlayerEntityScripting.m +++ b/src/Core/PlayerEntityScripting.m @@ -42,6 +42,8 @@ MA 02110-1301, USA. #import "Comparison.h" #endif +#define kOOLogUnconvertedNSLog @"unclassified.PlayerEntityScripting" + static NSString * const kOOLogScriptAddShipsFailed = @"script.addShips.failed"; static NSString * const kOOLogScriptMissionDescNoText = @"script.missionDescription.noMissionText"; static NSString * const kOOLogScriptMissionDescNoKey = @"script.missionDescription.noMissionKey"; @@ -123,7 +125,7 @@ static NSString * mission_key; - (void) scriptActions:(NSArray*) some_actions forTarget:(ShipEntity*) a_target { - PlayerEntity* player = (PlayerEntity *)[universe entityZero]; + PlayerEntity* player = [PlayerEntity sharedPlayer]; int i; for (i = 0; i < [some_actions count]; i++) { @@ -227,7 +229,7 @@ static NSString * mission_key; { [tokens removeObjectAtIndex:0]; valueString = [[tokens componentsJoinedByString:@" "] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; - valueString = [universe expandDescriptionWithLocals:valueString forSystem:[self system_seed] withLocalVariables:locals]; + valueString = ExpandDescriptionsWithLocalsForCurrentSystem(valueString, locals); OOLog(kOOLogNoteScriptAction, @"scriptAction after expansion: \"%@ %@\"", selectorString, valueString); } @@ -506,7 +508,7 @@ static NSString * mission_key; OOLog(kOOLogScriptMissionDescNoKey, @"SCRIPT ERROR ***** mission_key not set"); return; } - text = [universe expandDescription:text forSystem:system_seed]; + text = ExpandDescriptionForCurrentSystem(text); text = [self replaceVariablesInString: text]; [mission_variables setObject:text forKey:mission_key]; @@ -850,7 +852,7 @@ static int scriptRandomSeed = -1; // ensure proper random function very_random_seed.e = rand() & 255; very_random_seed.f = rand() & 255; seed_RNG_only_for_planet_description(very_random_seed); - NSString* expandedMessage = [universe expandDescription:valueString forSystem:[universe systemSeed]]; + NSString* expandedMessage = ExpandDescriptionForCurrentSystem(valueString); expandedMessage = [self replaceVariablesInString: expandedMessage]; [universe addCommsMessage:expandedMessage forCount:4.5]; @@ -867,7 +869,7 @@ static int scriptRandomSeed = -1; // ensure proper random function very_random_seed.e = rand() & 255; very_random_seed.f = rand() & 255; seed_RNG_only_for_planet_description(very_random_seed); - NSString* expandedMessage = [universe expandDescription:valueString forSystem:[universe systemSeed]]; + NSString* expandedMessage = ExpandDescriptionForCurrentSystem(valueString); expandedMessage = [self replaceVariablesInString: expandedMessage]; [universe addMessage: expandedMessage forCount: 3]; @@ -883,7 +885,7 @@ static int scriptRandomSeed = -1; // ensure proper random function very_random_seed.e = rand() & 255; very_random_seed.f = rand() & 255; seed_RNG_only_for_planet_description(very_random_seed); - NSString* expandedMessage = [universe expandDescription:valueString forSystem:[universe systemSeed]]; + NSString* expandedMessage = ExpandDescriptionForCurrentSystem(valueString); expandedMessage = [self replaceVariablesInString: expandedMessage]; [universe addMessage: expandedMessage forCount: 6]; @@ -928,7 +930,7 @@ static int scriptRandomSeed = -1; // ensure proper random function if ([eq_type hasSuffix:@"MISSILE"]||[eq_type hasSuffix:@"MINE"]) { - if ([self mountMissile:[[universe getShipWithRole:eq_type] autorelease]]) + if ([self mountMissile:[[universe newShipWithRole:eq_type] autorelease]]) missiles++; return; } @@ -1049,7 +1051,7 @@ static int scriptRandomSeed = -1; // ensure proper random function int smaller_quantity = 1 + ((amount - 1) % amount_per_container); if ([cargo count] < max_cargo) { - ShipEntity* container = [universe getShipWithRole:@"cargopod"]; + ShipEntity* container = [universe newShipWithRole:@"cargopod"]; if (container) { [container setUniverse:universe]; @@ -1069,7 +1071,7 @@ static int scriptRandomSeed = -1; // ensure proper random function { if ([cargo count] < max_cargo) { - ShipEntity* container = [universe getShipWithRole:@"cargopod"]; + ShipEntity* container = [universe newShipWithRole:@"cargopod"]; if (container) { [container setUniverse:universe]; @@ -1139,7 +1141,7 @@ static int scriptRandomSeed = -1; // ensure proper random function return; [self removeAllCargo]; - specialCargo = [[universe expandDescription:descriptionString forSystem:system_seed] retain]; + specialCargo = [ExpandDescriptionForCurrentSystem(descriptionString) retain]; // OOLog(kOOLogNoteUseSpecialCargo, @"Going to useSpecialCargo:'%@'", specialCargo); } @@ -1179,7 +1181,7 @@ static int scriptRandomSeed = -1; // ensure proper random function - (void) ejectItem:(NSString *)item_key { - ShipEntity* item = [universe getShip:item_key]; + ShipEntity* item = [universe newShipWithName:item_key]; if (script_target == nil) script_target = self; if (item) @@ -1559,9 +1561,9 @@ static int scriptRandomSeed = -1; // ensure proper random function // GuiDisplayGen *gui = [universe gui]; NSString *text = (NSString *)[[universe missiontext] objectForKey:textKey]; - text = [universe expandDescription:text forSystem:system_seed]; + text = ExpandDescriptionForCurrentSystem(text); text = [self replaceVariablesInString: text]; - //NSLog(@"::::: Adding text '%@':\n'%@'", textKey, text); + NSArray *paras = [text componentsSeparatedByString:@"\\n"]; if (text) { @@ -1602,7 +1604,7 @@ static int scriptRandomSeed = -1; // ensure proper random function { NSString* choice_key = (NSString *)[choice_keys objectAtIndex:i]; NSString* choice_text = [NSString stringWithFormat:@" %@ ",[choices_dict objectForKey:choice_key]]; - choice_text = [universe expandDescription:choice_text forSystem:system_seed]; + choice_text = ExpandDescriptionForCurrentSystem(choice_text); choice_text = [self replaceVariablesInString: choice_text]; [gui setText:choice_text forRow:choices_row align: GUI_ALIGN_CENTER]; [gui setKey:choice_key forRow:choices_row]; @@ -1697,7 +1699,7 @@ static int scriptRandomSeed = -1; // ensure proper random function Quaternion q2 = { (GLfloat)0.707, (GLfloat)0.707, (GLfloat)0.0, (GLfloat)0.0}; - ship = [universe getShipWithRole: shipKey]; // retain count = 1 + ship = [universe newShipWithRole: shipKey]; // retain count = 1 if (ship) { double cr = ship->collision_radius; @@ -1954,7 +1956,7 @@ static int scriptRandomSeed = -1; // ensure proper random function } else if ([valueString hasPrefix:@"["]&&[valueString hasSuffix:@"]"]) { - NSString* replaceString = [universe expandDescription:valueString forSystem:system_seed]; + NSString* replaceString = ExpandDescriptionForCurrentSystem(valueString); [resultString replaceOccurrencesOfString:valueString withString:replaceString options:NSLiteralSearch range:NSMakeRange(0, [resultString length])]; } } @@ -2069,7 +2071,6 @@ static int scriptRandomSeed = -1; // ensure proper random function if (![conditions isKindOfClass:[NSArray class]]) { NSLog(@"SCENE ERROR \"conditions = %@\" is not an array - returning NO.", [conditions description]); - // NSBeep(); AppKit return NO; } } @@ -2135,9 +2136,9 @@ static int scriptRandomSeed = -1; // ensure proper random function return NO; // 0... 1... 2 3 4 5 6 7 8 9.... ShipEntity* ship = nil; if ([i_key isEqual:@"ship"]||[i_key isEqual:@"model"]) - ship = [universe getShip:(NSString*)[i_info objectAtIndex: 1]]; + ship = [universe newShipWithName:(NSString*)[i_info objectAtIndex: 1]]; if ([i_key isEqual:@"role"]) - ship = [universe getShipWithRole:(NSString*)[i_info objectAtIndex: 1]]; + ship = [universe newShipWithRole:(NSString*)[i_info objectAtIndex: 1]]; if (!ship) return NO; @@ -2171,7 +2172,7 @@ static int scriptRandomSeed = -1; // ensure proper random function if ([i_info count] != 9) // must be player_x_y_z_W_X_Y_Z_align return NO; // 0..... 1 2 3 4 5 6 7 8.... - ShipEntity* doppelganger = [universe getShip: ship_desc]; // retain count = 1 + ShipEntity* doppelganger = [universe newShipWithName: ship_desc]; // retain count = 1 if (!doppelganger) return NO; diff --git a/src/Core/PlayerEntitySound.h b/src/Core/PlayerEntitySound.h index df0000e8..07daa3be 100644 --- a/src/Core/PlayerEntitySound.h +++ b/src/Core/PlayerEntitySound.h @@ -49,4 +49,7 @@ enum - (void)playBreakPattern; +- (void)playHostileWarning; +- (void)playAlertConditionRed; + @end diff --git a/src/Core/PlayerEntitySound.m b/src/Core/PlayerEntitySound.m index efcf1139..2f04be80 100644 --- a/src/Core/PlayerEntitySound.m +++ b/src/Core/PlayerEntitySound.m @@ -40,98 +40,94 @@ MA 02110-1301, USA. - (void)setUpSound { - #ifdef HAVE_SOUND - [self destroySound]; - - beepSound = [[ResourceManager ooSoundNamed:@"beep.ogg" inFolder:@"Sounds"] retain]; - boopSound = [[ResourceManager ooSoundNamed:@"boop.ogg" inFolder:@"Sounds"] retain]; - weaponSound = [[ResourceManager ooSoundNamed:@"laser.ogg" inFolder:@"Sounds"] retain]; - weaponHitSound = [[ResourceManager ooSoundNamed:@"laserhits.ogg" inFolder:@"Sounds"] retain]; - missileSound = [[ResourceManager ooSoundNamed:@"missile.ogg" inFolder:@"Sounds"] retain]; - damageSound = [[ResourceManager ooSoundNamed:@"hit.ogg" inFolder:@"Sounds"] retain]; - scrapeDamageSound = [[ResourceManager ooSoundNamed:@"hullbang.ogg" inFolder:@"Sounds"] retain]; - destructionSound = [[ResourceManager ooSoundNamed:@"bigbang.ogg" inFolder:@"Sounds"] retain]; - breakPatternSound = [[ResourceManager ooSoundNamed:@"breakpattern.ogg" inFolder:@"Sounds"] retain]; - // - ecmSound = [[ResourceManager ooSoundNamed:@"ecm.ogg" inFolder:@"Sounds"] retain]; - buySound = [[ResourceManager ooSoundNamed:@"buy.ogg" inFolder:@"Sounds"] retain]; - sellSound = [[ResourceManager ooSoundNamed:@"sell.ogg" inFolder:@"Sounds"] retain]; - warningSound = [[ResourceManager ooSoundNamed:@"warning.ogg" inFolder:@"Sounds"] retain]; - afterburner1Sound = [[ResourceManager ooSoundNamed:@"afterburner1.ogg" inFolder:@"Sounds"] retain]; - afterburner2Sound = [[ResourceManager ooSoundNamed:@"afterburner2.ogg" inFolder:@"Sounds"] retain]; - // - witchAbortSound = [[ResourceManager ooSoundNamed:@"witchabort.ogg" inFolder:@"Sounds"] retain]; - // - fuelScoopSound = [[ResourceManager ooSoundNamed:@"scoop.ogg" inFolder:@"Sounds"] retain]; - - themeMusic = [[ResourceManager ooMusicNamed:@"OoliteTheme.ogg" inFolder:@"Music"] retain]; - missionMusic = [[ResourceManager ooMusicNamed:@"OoliteTheme.ogg" inFolder:@"Music"] retain]; - dockingMusic = [[ResourceManager ooMusicNamed:@"BlueDanube.ogg" inFolder:@"Music"] retain]; - - refPoint = [[OOSoundReferencePoint alloc] init]; - interfaceBeepSource = [[OOSoundSource alloc] init]; - breakPatternSource = [[OOSoundSource alloc] init]; - ecmSource = [[OOSoundSource alloc] init]; - #endif + [self destroySound]; + + beepSound = [[ResourceManager ooSoundNamed:@"beep.ogg" inFolder:@"Sounds"] retain]; + boopSound = [[ResourceManager ooSoundNamed:@"boop.ogg" inFolder:@"Sounds"] retain]; + weaponSound = [[ResourceManager ooSoundNamed:@"laser.ogg" inFolder:@"Sounds"] retain]; + weaponHitSound = [[ResourceManager ooSoundNamed:@"laserhits.ogg" inFolder:@"Sounds"] retain]; + missileSound = [[ResourceManager ooSoundNamed:@"missile.ogg" inFolder:@"Sounds"] retain]; + damageSound = [[ResourceManager ooSoundNamed:@"hit.ogg" inFolder:@"Sounds"] retain]; + scrapeDamageSound = [[ResourceManager ooSoundNamed:@"hullbang.ogg" inFolder:@"Sounds"] retain]; + destructionSound = [[ResourceManager ooSoundNamed:@"bigbang.ogg" inFolder:@"Sounds"] retain]; + breakPatternSound = [[ResourceManager ooSoundNamed:@"breakpattern.ogg" inFolder:@"Sounds"] retain]; + // + ecmSound = [[ResourceManager ooSoundNamed:@"ecm.ogg" inFolder:@"Sounds"] retain]; + buySound = [[ResourceManager ooSoundNamed:@"buy.ogg" inFolder:@"Sounds"] retain]; + sellSound = [[ResourceManager ooSoundNamed:@"sell.ogg" inFolder:@"Sounds"] retain]; + warningSound = [[ResourceManager ooSoundNamed:@"warning.ogg" inFolder:@"Sounds"] retain]; + afterburner1Sound = [[ResourceManager ooSoundNamed:@"afterburner1.ogg" inFolder:@"Sounds"] retain]; + afterburner2Sound = [[ResourceManager ooSoundNamed:@"afterburner2.ogg" inFolder:@"Sounds"] retain]; + // + witchAbortSound = [[ResourceManager ooSoundNamed:@"witchabort.ogg" inFolder:@"Sounds"] retain]; + // + fuelScoopSound = [[ResourceManager ooSoundNamed:@"scoop.ogg" inFolder:@"Sounds"] retain]; + + themeMusic = [[ResourceManager ooMusicNamed:@"OoliteTheme.ogg" inFolder:@"Music"] retain]; + missionMusic = [[ResourceManager ooMusicNamed:@"OoliteTheme.ogg" inFolder:@"Music"] retain]; + dockingMusic = [[ResourceManager ooMusicNamed:@"BlueDanube.ogg" inFolder:@"Music"] retain]; + + refPoint = [[OOSoundReferencePoint alloc] init]; + interfaceBeepSource = [[OOSoundSource alloc] init]; + breakPatternSource = [[OOSoundSource alloc] init]; + ecmSource = [[OOSoundSource alloc] init]; } - (void)destroySound { - #ifdef HAVE_SOUND - [beepSound release]; - beepSound = nil; - [boopSound release]; - boopSound = nil; - [weaponSound release]; - weaponSound = nil; - [weaponHitSound release]; - weaponHitSound = nil; - [damageSound release]; - damageSound = nil; - [scrapeDamageSound release]; - scrapeDamageSound = nil; - [destructionSound release]; - destructionSound = nil; - [breakPatternSound release]; - breakPatternSound = nil; - - [ecmSound release]; - ecmSound = nil; - [buySound release]; - buySound = nil; - [sellSound release]; - sellSound = nil; - [warningSound release]; - warningSound = nil; - [afterburner1Sound release]; - afterburner1Sound = nil; - [afterburner2Sound release]; - afterburner2Sound = nil; - - [witchAbortSound release]; - witchAbortSound = nil; - - [fuelScoopSound release]; - fuelScoopSound = nil; - - - [themeMusic release]; - themeMusic = nil; - [missionMusic release]; - missionMusic = nil; - [dockingMusic release]; - dockingMusic = nil; - - [refPoint release]; - refPoint = nil; - [interfaceBeepSource release]; - interfaceBeepSource = nil; - [ecmSource release]; - ecmSource = nil; - [breakPatternSource release]; - breakPatternSource = nil; - #endif + [beepSound release]; + beepSound = nil; + [boopSound release]; + boopSound = nil; + [weaponSound release]; + weaponSound = nil; + [weaponHitSound release]; + weaponHitSound = nil; + [damageSound release]; + damageSound = nil; + [scrapeDamageSound release]; + scrapeDamageSound = nil; + [destructionSound release]; + destructionSound = nil; + [breakPatternSound release]; + breakPatternSound = nil; + + [ecmSound release]; + ecmSound = nil; + [buySound release]; + buySound = nil; + [sellSound release]; + sellSound = nil; + [warningSound release]; + warningSound = nil; + [afterburner1Sound release]; + afterburner1Sound = nil; + [afterburner2Sound release]; + afterburner2Sound = nil; + + [witchAbortSound release]; + witchAbortSound = nil; + + [fuelScoopSound release]; + fuelScoopSound = nil; + + + [themeMusic release]; + themeMusic = nil; + [missionMusic release]; + missionMusic = nil; + [dockingMusic release]; + dockingMusic = nil; + + [refPoint release]; + refPoint = nil; + [interfaceBeepSource release]; + interfaceBeepSource = nil; + [ecmSource release]; + ecmSource = nil; + [breakPatternSource release]; + breakPatternSource = nil; } @@ -149,75 +145,76 @@ MA 02110-1301, USA. - (void)playInterfaceBeep:(unsigned)inInterfaceBeep { - #ifdef HAVE_SOUND - OOSound *sound = nil; + OOSound *sound = nil; + + switch (inInterfaceBeep) + { + case kInterfaceBeep_Beep: + sound = beepSound; + break; - switch (inInterfaceBeep) - { - case kInterfaceBeep_Beep: - sound = beepSound; - break; - - case kInterfaceBeep_Boop: - sound = boopSound; - break; - - case kInterfaceBeep_Buy: - sound = buySound; - break; - - case kInterfaceBeep_Sell: - sound = sellSound; - break; - - default: - NSLog(@"Invalid beep selector: %u", inInterfaceBeep); - } + case kInterfaceBeep_Boop: + sound = boopSound; + break; - #if BEEP_MODE == 0 - [interfaceBeepSource playOrRepeatSound:sound]; - #elif BEEP_MODE == 1 - [interfaceBeepSource playSound:sound]; - #elif BEEP_MODE == 2 - [sound play]; - #else - #error Unknown BEEP_MODE - #endif + case kInterfaceBeep_Buy: + sound = buySound; + break; + + case kInterfaceBeep_Sell: + sound = sellSound; + break; + + default: + OOLog(@"sound.invalidBeep", @"Invalid beep selector: %u", inInterfaceBeep); + } + + #if BEEP_MODE == 0 + [interfaceBeepSource playOrRepeatSound:sound]; + #elif BEEP_MODE == 1 + [interfaceBeepSource playSound:sound]; + #elif BEEP_MODE == 2 + [sound play]; + #else + #error Unknown BEEP_MODE #endif } - (BOOL)isBeeping { - #ifdef HAVE_SOUND - return [interfaceBeepSource isPlaying]; - #else - return NO; - #endif + return [interfaceBeepSource isPlaying]; } - (void)playECMSound { - #ifdef HAVE_SOUND - if (![ecmSource isPlaying]) [ecmSource playSound:ecmSound]; - #endif + if (![ecmSource isPlaying]) [ecmSource playSound:ecmSound]; } - (void)stopECMSound { - #ifdef HAVE_SOUND - [ecmSource stop]; - #endif + [ecmSource stop]; } - (void)playBreakPattern { - #ifdef HAVE_SOUND [breakPatternSource playSound:breakPatternSound]; - #endif +} + + +- (void)playHostileWarning +{ + if (![warningSound isPlaying]) [warningSound play]; +} + + +- (void)playAlertConditionRed +{ + if ([warningSound isPlaying]) [warningSound stop]; + [warningSound play]; } @end diff --git a/src/Core/ResourceManager.h b/src/Core/ResourceManager.h index 9cf03af5..258c376a 100644 --- a/src/Core/ResourceManager.h +++ b/src/Core/ResourceManager.h @@ -50,7 +50,6 @@ BOOL always_include_addons; + (NSString *) errors; + (NSMutableArray *) paths; + (NSMutableArray *) pathsUsingAddOns:(BOOL) include_addons; -+ (BOOL) areRequirementsFulfilled:(NSDictionary*) requirements; + (void) addExternalPath:(NSString *)filename; + (NSDictionary *) dictionaryFromFilesNamed:(NSString *)filename inFolder:(NSString *)foldername andMerge:(BOOL) mergeFiles; diff --git a/src/Core/ResourceManager.m b/src/Core/ResourceManager.m index 0dcd12e0..85d3dc74 100644 --- a/src/Core/ResourceManager.m +++ b/src/Core/ResourceManager.m @@ -31,6 +31,8 @@ MA 02110-1301, USA. #import "OOStringParsing.h" #import "OOPListParsing.h" +#define kOOLogUnconvertedNSLog @"unclassified.ResourceManager" + static NSString * const kOOLogDumpSearchPaths = @"searchPaths.dumpAll"; static NSString * const kOOLogCacheUpToDate = @"dataCache.upToDate"; @@ -43,6 +45,14 @@ static NSString * const kOOCacheKeyModificationDates = @"modification dates"; extern NSDictionary* parseScripts(NSString* script); + +@interface ResourceManager (OOPrivate) + ++ (BOOL) areRequirementsFulfilled:(NSDictionary*)requirements forOXP:(NSString *)path; + +@end + + @implementation ResourceManager static NSMutableArray* saved_paths; @@ -185,11 +195,9 @@ NSMutableDictionary* surface_cache; int i; if (saved_paths) return saved_paths; - if (errors) - { - [errors release]; - errors = nil; - } + + [errors release]; + errors = nil; NSFileManager *fmgr = [NSFileManager defaultManager]; @@ -261,7 +269,7 @@ NSMutableDictionary* surface_cache; NSDictionary* requires_dic = OODictionaryFromFile(requiresPath); if (requires_dic != nil) { - require_test = [ResourceManager areRequirementsFulfilled:requires_dic]; + require_test = [ResourceManager areRequirementsFulfilled:requires_dic forOXP:possibleExpansionPath]; } if (require_test) { @@ -269,24 +277,30 @@ NSMutableDictionary* surface_cache; } else { - NSString* version = (NSString *)[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]; - // NSBeep(); // AppKit - if (!failed_parsing) + NSString *errorString = nil; + + if (failed_parsing) { - NSString* old_errors = errors; - errors = [[NSString alloc] initWithFormat:@"%@\n\t'%@' requirements property list could not be parsed",old_errors, [possibleExpansionPath lastPathComponent]]; - [old_errors release]; + errorString = [NSString stringWithFormat:@"\t'%@' requirements property list could not be parsed.", [possibleExpansionPath lastPathComponent]]; } else { - NSLog(@"ERROR %@ is incompatible with this version %@ of Oolite",possibleExpansionPath,version); - if (!errors) - errors = [[NSString alloc] initWithFormat:@"\t'%@' is incompatible with version %@ of Oolite",[possibleExpansionPath lastPathComponent],version]; + NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]; + OOLog(@"oxp.versionMismatch", @"ERROR: OXP %@ is incompatible with version %@ of Oolite",possibleExpansionPath,version); + errorString = [NSString stringWithFormat:@"\t'%@' is incompatible with version %@ of Oolite", [possibleExpansionPath lastPathComponent], version]; + } + + if (errorString != nil) + { + if (errors) + { + errorString = [[NSString alloc] initWithFormat:@"%@\n%@", errors, errorString]; + [errors release]; + errors = errorString; + } else { - NSString* old_errors = errors; - errors = [[NSString alloc] initWithFormat:@"%@\n\t'%@' is incompatible with version %@ of Oolite",old_errors,[possibleExpansionPath lastPathComponent],version]; - [old_errors release]; + errors = [errorString retain]; } } } @@ -303,17 +317,38 @@ NSMutableDictionary* surface_cache; return file_paths; } -+ (BOOL) areRequirementsFulfilled:(NSDictionary*) requirements ++ (BOOL) areRequirementsFulfilled:(NSDictionary*)requirements forOXP:(NSString *)path { - if (!requirements) - return YES; - if ([requirements objectForKey:@"version"]) + BOOL result = YES; + NSString *requiredVersion; + + if (result) { - NSString* version = (NSString *)[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]; - if ([version isLessThan:[requirements objectForKey:@"version"]]) - return NO; + requiredVersion = [requirements objectForKey:@"version"]; + if (requiredVersion != nil) + { + if ([requiredVersion isKindOfClass:[NSString class]]) + { + static NSArray *ooVersionComponents = nil; + NSArray *oxpVersionComponents = nil; + + if (ooVersionComponents == nil) + { + ooVersionComponents = ComponentsFromVersionString([[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]); + } + + oxpVersionComponents = ComponentsFromVersionString([requirements objectForKey:@"version"]); + if (NSOrderedAscending == CompareVersions(ooVersionComponents, oxpVersionComponents)) result = NO; + } + else + { + OOLog(@"plist.wrongType", @"Expected requires.plist entry \"version\" to be string, but got %@ in OXP %@.", [requirements class], [path lastPathComponent]); + result = NO; + } + } } - return YES; + + return result; } + (void) addExternalPath:(NSString *)filename @@ -332,7 +367,6 @@ NSMutableDictionary* surface_cache; } if (!paths_to_load) paths_to_load = [saved_paths retain]; -// NSLog(@"DEBUG HERE:::: paths_to_load = %@", paths_to_load); } + (NSDictionary *) dictionaryFromFilesNamed:(NSString *)filename inFolder:(NSString *)foldername andMerge:(BOOL) mergeFiles @@ -390,10 +424,7 @@ NSMutableDictionary* surface_cache; } } // - if (result) - [dictionary_cache setObject:result forKey:dict_key]; - -// NSLog(@"DEBUG ResourceManager dictionary_cache keys:\n%@", [dictionary_cache allKeys]); + if (result) [dictionary_cache setObject:result forKey:dict_key]; return [NSDictionary dictionaryWithDictionary:result]; } @@ -432,7 +463,6 @@ NSMutableDictionary* surface_cache; // got results we may want to cache // - //NSLog(@"---> ResourceManager found %d file(s) with name '%@' (in folder '%@')", [results count], filename, foldername); NSMutableArray *result = [NSMutableArray arrayWithCapacity:128]; if (!mergeFiles) { @@ -621,22 +651,17 @@ NSMutableDictionary* surface_cache; filepath = [[filepath stringByDeletingPathExtension] stringByAppendingPathExtension:@"oos"]; - //NSLog(@"looking for oos file: %@", filepath); if ([[NSFileManager defaultManager] fileExistsAtPath:filepath]) { // load and compile oos script NSLog(@"trying to load and parse %@", filepath); NSString *script = [NSString stringWithContentsOfFile:filepath]; NSDictionary *scriptDict = parseScripts(script); - if (scriptDict) { - //NSLog(@"parsed ok, adding to results"); - [results addObject:scriptDict]; - } + if (scriptDict) [results addObject:scriptDict]; } else { filepath = [[filepath stringByDeletingPathExtension] stringByAppendingPathExtension:@"plist"]; - //NSLog(@"oos not found, looking for plist file: %@", filepath); // All this code replicated from dictionaryFromFileNamed because that method // will traverse all possible locations and any oos files that co-exist with // plist files will probably get their entries overwritten. @@ -651,7 +676,6 @@ NSMutableDictionary* surface_cache; { xfilepath = [[(NSString *)[fpaths objectAtIndex:i] stringByAppendingPathComponent:foldername] stringByAppendingPathComponent:filename]; filepath = [[xfilepath stringByDeletingPathExtension] stringByAppendingPathExtension:@"oos"]; - //NSLog(@"looking for oos file: %@", filepath); if ([[NSFileManager defaultManager] fileExistsAtPath:filepath]) { // load and compile oos script @@ -659,7 +683,6 @@ NSMutableDictionary* surface_cache; NSString *script = [NSString stringWithContentsOfFile:filepath]; NSDictionary *scriptDict = parseScripts(script); if (scriptDict) { - //NSLog(@"parsed ok, adding to results"); [results addObject:scriptDict]; } } @@ -686,8 +709,6 @@ NSMutableDictionary* surface_cache; [dictionary_cache setObject:result forKey:dict_key]; } -// NSLog(@"DEBUG ResourceManager dictionary_cache keys:\n%@", [dictionary_cache allKeys]); - return [NSDictionary dictionaryWithDictionary:result]; } diff --git a/src/Core/RingEntity.m b/src/Core/RingEntity.m index f955c295..95c6f146 100644 --- a/src/Core/RingEntity.m +++ b/src/Core/RingEntity.m @@ -111,7 +111,6 @@ Ringdata ringentity; lifetime -= movement; if (lifetime < 0.0) { - //NSLog(@"removing ring %@ movement %.3f delta_t %.3f",self,movement,delta_t); [universe removeEntity:self]; } } @@ -127,7 +126,6 @@ Ringdata ringentity; { if (basefile) { - //NSLog(@"Drawing ring : %@ n_faces %d, n_vertices %d", basefile, n_faces, n_vertices); if (immediate) { #ifdef GNUSTEP diff --git a/src/Core/ScriptCompiler.m b/src/Core/ScriptCompiler.m index 86aaec29..bda90608 100644 --- a/src/Core/ScriptCompiler.m +++ b/src/Core/ScriptCompiler.m @@ -25,6 +25,9 @@ MA 02110-1301, USA. #import #import "StringTokeniser.h" +#define kOOLogUnconvertedNSLog @"unclassified.OOSCompiler" + + @interface NSMutableString (OOScript) - (void) replaceString:(NSString*)aString withString:(NSString*)otherString; diff --git a/src/Core/ShipEntity.m b/src/Core/ShipEntity.m index 94016a3f..d7901efa 100644 --- a/src/Core/ShipEntity.m +++ b/src/Core/ShipEntity.m @@ -48,6 +48,8 @@ MA 02110-1301, USA. #import "WormholeEntity.h" #import "GuiDisplayGen.h" +#define kOOLogUnconvertedNSLog @"unclassified.ShipEntity" + extern NSString * const kOOLogNoteAddShips; extern NSString * const kOOLogSyntaxAddShips; @@ -414,7 +416,7 @@ NSString* describeStatus(int some_status) NS_HANDLER if ([[localException name] isEqual: OOLITE_EXCEPTION_DATA_NOT_FOUND]) { - NSLog(@"***** Oolite Data Not Found Exception : '%@' in [ShipEntity setModel:] *****", [localException reason]); + OOLog(kOOLogException, @"***** Oolite Data Not Found Exception : '%@' in [ShipEntity setModel:] *****", [localException reason]); } [localException raise]; NS_ENDHANDLER @@ -596,14 +598,14 @@ NSString* describeStatus(int some_status) if ([shipinfoDictionary objectForKey:@"escort-role"]) { escortRole = (NSString*)[shipinfoDictionary objectForKey:@"escort-role"]; - if (![[universe getShipWithRole:escortRole] autorelease]) + if (![[universe newShipWithRole:escortRole] autorelease]) escortRole = @"escort"; } if ([shipinfoDictionary objectForKey:@"escort-ship"]) { escortShipKey = (NSString*)[shipinfoDictionary objectForKey:@"escort-ship"]; - if (![[universe getShip:escortShipKey] autorelease]) + if (![[universe newShipWithName:escortShipKey] autorelease]) escortShipKey = nil; } @@ -616,9 +618,9 @@ NSString* describeStatus(int some_status) ShipEntity *escorter; if (escortShipKey) - escorter = [universe getShip:escortShipKey]; // retained + escorter = [universe newShipWithName:escortShipKey]; // retained else - escorter = [universe getShipWithRole:escortRole]; // retained + escorter = [universe newShipWithRole:escortRole]; // retained if (!escorter) break; @@ -984,7 +986,7 @@ NSString* describeStatus(int some_status) NS_HANDLER if ([[localException name] isEqual: OOLITE_EXCEPTION_SHIP_NOT_FOUND]) { - NSLog(@"***** Oolite Exception : '%@' in [ShipEntity setUpShipFromDictionary:] while basing a ship upon '%@' *****", [localException reason], other_shipdesc); + OOLog(kOOLogException, @"***** Oolite Exception : '%@' in [ShipEntity setUpShipFromDictionary:] while basing a ship upon '%@' *****", [localException reason], other_shipdesc); other_shipdict = nil; } else @@ -1270,7 +1272,7 @@ NSString* describeStatus(int some_status) { quaternion_normalise(&sub_q); - subent = [universe getShip:subdesc]; // retained + subent = [universe newShipWithName:subdesc]; // retained if ((self->isStation)&&([subdesc rangeOfString:@"dock"].location != NSNotFound)) [(StationEntity*)self setDockingPortModel:(ShipEntity*)subent :sub_pos :sub_q]; @@ -1372,7 +1374,7 @@ NSString* describeStatus(int some_status) { if (universe) { - PlayerEntity* player = (PlayerEntity*)[universe entityZero]; + PlayerEntity* player = [PlayerEntity sharedPlayer]; [player setScript_target:self]; NSArray * setup_actions = (NSArray *)[shipdict objectForKey:KEY_SETUP_ACTIONS]; @@ -2104,8 +2106,8 @@ ShipEntity* doOctreesCollide(ShipEntity* prime, ShipEntity* other) //scripting if ((status == STATUS_IN_FLIGHT)&&([launch_actions count])) { - [(PlayerEntity *)[universe entityZero] setScript_target:self]; - [(PlayerEntity *)[universe entityZero] scriptActions: launch_actions forTarget: self]; + [[PlayerEntity sharedPlayer] setScript_target:self]; + [[PlayerEntity sharedPlayer] scriptActions: launch_actions forTarget: self]; [launch_actions removeAllObjects]; } @@ -3556,7 +3558,7 @@ void testForShaders() } else { - NSLog(@"ERROR no basefile for entity %@"); + OOLog(kOOLogFileNotFound, @"ERROR no basefile for entity %@"); } } glShadeModel(GL_SMOOTH); @@ -3564,8 +3566,8 @@ void testForShaders() NS_HANDLER - NSLog(@"***** [Entity drawEntity::] encountered exception: %@ : %@ *****",[localException name], [localException reason]); - NSLog(@"***** Removing entity %@ from universe *****", self); + OOLog(kOOLogException, @"***** [Entity drawEntity::] encountered exception: %@ : %@ *****",[localException name], [localException reason]); + OOLog(kOOLogException, @"***** Removing entity %@ from universe *****", self); [universe removeEntity:self]; if ([[localException name] hasPrefix:@"Oolite"]) [universe handleOoliteException:localException]; // handle these ourself @@ -3624,7 +3626,6 @@ void testForShaders() zero_distance = my_owner->zero_distance; if (zero_distance > no_draw_distance) { - //NSLog(@"DEBUG - sub entity '%@' too far away to draw", self); return; // TOO FAR AWAY } } @@ -3651,8 +3652,6 @@ void testForShaders() glMultMatrixf(rotMatrix); [self drawEntity:immediate :translucent]; - -// NSLog(@"drawn active entity : %@", basefile); } else @@ -3847,22 +3846,13 @@ static GLfloat mascem_color2[4] = { 0.4, 0.1, 0.4, 1.0}; // purple { if (scan_class == CLASS_MISSILE) return; // missiles are SUPPOSED to collide! - -// NSLog(@"DEBUG ***** %@ in AVOID COLLISION!", self); - - + ShipEntity* prox_ship = [self proximity_alert]; if (prox_ship) { -// if (self == [universe entityZero]) -// NSLog(@"DEBUG ***** proximity alert for %@ %d against target %d", name, universal_id, proximity_alert); - if (previousCondition) { - // -// NSLog(@"DEBUG ***** avoidCollision dropping previousCondition"); - // [previousCondition release]; previousCondition = nil; } @@ -3891,9 +3881,7 @@ static GLfloat mascem_color2[4] = { 0.4, 0.1, 0.4, 1.0}; // purple { if (!previousCondition) return; - -// NSLog(@"DEBUG ***** proximity alert for %@ %d over", name, universal_id, proximity_alert); - + behaviour = [(NSNumber*)[previousCondition objectForKey:@"behaviour"] intValue]; primaryTarget = [(NSNumber*)[previousCondition objectForKey:@"primaryTarget"] intValue]; desired_range = [(NSNumber*)[previousCondition objectForKey:@"desired_range"] floatValue]; @@ -3982,16 +3970,11 @@ static GLfloat mascem_color2[4] = { 0.4, 0.1, 0.4, 1.0}; // purple // check which subtends the greatest angle GLfloat sa_prox = prox->collision_radius * prox->collision_radius / distance2(position, prox->position); GLfloat sa_other = other->collision_radius * other->collision_radius / distance2(position, other->position); - if (sa_prox < sa_other) - { -// NSLog(@"DEBUG %@ is already avoiding %@", self, prox); - return; - } + if (sa_prox < sa_other) return; } } proximity_alert = [other universal_id]; other->proximity_alert = universal_id; -// NSLog(@"DEBUG PROXIMITY ALERT FOR %@ VS %@ == %d", self, other, proximity_alert); } - (NSString *) name @@ -4145,10 +4128,8 @@ static GLfloat mascem_color2[4] = { 0.4, 0.1, 0.4, 1.0}; // purple int result = AEGIS_NONE; p1.x -= position.x; p1.y -= position.y; p1.z -= position.z; double d2 = p1.x*p1.x + p1.y*p1.y + p1.z*p1.z; + // check if nearing surface - // -// if (reportAImessages) -// NSLog(@"DEBUG reporting altitude d2(%.2f) - cr2(%.2f) = %.2f", d2, cr2, d2 - cr2); BOOL wasNearPlanetSurface = isNearPlanetSurface; isNearPlanetSurface = (d2 - cr2 < 3600000.0); if ((!wasNearPlanetSurface)&&(isNearPlanetSurface)) @@ -4477,9 +4458,6 @@ static GLfloat mascem_color2[4] = { 0.4, 0.1, 0.4, 1.0}; // purple double d2 = p2.x*p2.x + p2.y*p2.y + p2.z*p2.z - ecr*ecr; double damage = weapon_energy*desired_range/d2; [e2 takeEnergyDamage:damage from:self becauseOf:[self owner]]; - -// if ((e2)&&(e2->isShip)) -// NSLog(@"DEBUG Doing %.1f damage to %@ %d",damage,[(ShipEntity *)e2 name],[(ShipEntity *)e2 universal_id]); } } } @@ -4585,9 +4563,6 @@ static GLfloat mascem_color2[4] = { 0.4, 0.1, 0.4, 1.0}; // purple ShipEntity *group_leader = (ShipEntity *)[universe entityForUniversalID:group_id]; if ((group_leader)&&(group_leader->isShip)) { - //NSLog(@"DEBUG %@ %d informs group leader %@ %d of attack by %@ %d", name, universal_id, [group_leader name], [group_leader universal_id], [hunter name], [hunter universal_id]); - - //[group_leader setReportAImessages:YES]; [group_leader setFound_target:hunter]; [group_leader setPrimaryAggressor:hunter]; [[group_leader getAI] reactToMessage:@"ATTACKED"]; @@ -4665,7 +4640,7 @@ static GLfloat mascem_color2[4] = { 0.4, 0.1, 0.4, 1.0}; // purple if ((energy < max_energy *0.125)&&(has_escape_pod)&&((ranrot_rand() & 3) == 0)) // 25% chance he gets to an escape pod { has_escape_pod = NO; - //NSLog(@"Escape Pod launched"); + [shipAI setStateMachine:@"nullAI.plist"]; [shipAI setState:@"GLOBAL"]; behaviour = BEHAVIOUR_IDLE; @@ -4721,7 +4696,7 @@ static GLfloat mascem_color2[4] = { 0.4, 0.1, 0.4, 1.0}; // purple //scripting if ([death_actions count]) { - PlayerEntity* player = (PlayerEntity *)[universe entityZero]; + PlayerEntity* player = [PlayerEntity sharedPlayer]; [player setScript_target:self]; [player scriptActions: death_actions forTarget: self]; @@ -4858,7 +4833,7 @@ static GLfloat mascem_color2[4] = { 0.4, 0.1, 0.4, 1.0}; // purple // for (i = 0; i < n_rocks; i++) { - ShipEntity* rock = [universe getShipWithRole:@"boulder"]; // retain count = 1 + ShipEntity* rock = [universe newShipWithRole:@"boulder"]; // retain count = 1 if (rock) { Vector rpos = xposition; @@ -4894,7 +4869,7 @@ static GLfloat mascem_color2[4] = { 0.4, 0.1, 0.4, 1.0}; // purple // for (i = 0; i < n_rocks; i++) { - ShipEntity* rock = [universe getShipWithRole:@"splinter"]; // retain count = 1 + ShipEntity* rock = [universe newShipWithRole:@"splinter"]; // retain count = 1 if (rock) { Vector rpos = xposition; @@ -4940,7 +4915,7 @@ static GLfloat mascem_color2[4] = { 0.4, 0.1, 0.4, 1.0}; // purple for (i = 0; i < n_wreckage; i++) { - ShipEntity* wreck = [universe getShipWithRole:@"wreckage"]; // retain count = 1 + ShipEntity* wreck = [universe newShipWithRole:@"wreckage"]; // retain count = 1 if (wreck) { GLfloat expected_mass = 0.1f * mass * (0.75 + 0.5 * randf()); @@ -4979,7 +4954,7 @@ static GLfloat mascem_color2[4] = { 0.4, 0.1, 0.4, 1.0}; // purple // for (i = 0; i < n_alloys; i++) { - ShipEntity* plate = [universe getShipWithRole:@"alloy"]; // retain count = 1 + ShipEntity* plate = [universe newShipWithRole:@"alloy"]; // retain count = 1 if (plate) { Vector rpos = xposition; @@ -5029,7 +5004,7 @@ static GLfloat mascem_color2[4] = { 0.4, 0.1, 0.4, 1.0}; // purple [self dealMomentumWithinDesiredRange: 0.125 * mass]; // - if (self != [universe entityZero]) // was if !isPlayer - but I think this may cause ghosts + if (self != [PlayerEntity sharedPlayer]) // was if !isPlayer - but I think this may cause ghosts [universe removeEntity:self]; } @@ -5160,7 +5135,7 @@ Vector positionOffsetForShipInRotationToAlignment(ShipEntity* ship, Quaternion q //scripting if ([death_actions count]) { - PlayerEntity* player = (PlayerEntity *)[universe entityZero]; + PlayerEntity* player = [PlayerEntity sharedPlayer]; [player setScript_target:self]; [player scriptActions: death_actions forTarget: self]; @@ -5206,7 +5181,6 @@ Vector positionOffsetForShipInRotationToAlignment(ShipEntity* ship, Quaternion q int cargo_to_go = max_cargo / 10; while (cargo_to_go > 15) cargo_to_go = ranrot_rand() % cargo_to_go; - //NSLog(@"explosion in %@ %d will launch %d pieces of cargo (max_cargo = %d)", name, universal_id, cargo_to_go, max_cargo); [self setCargo:[universe getContainersOfPlentifulGoods:cargo_to_go]]; cargo_chance = 100; } @@ -5215,7 +5189,6 @@ Vector positionOffsetForShipInRotationToAlignment(ShipEntity* ship, Quaternion q int cargo_to_go = max_cargo / 10; while (cargo_to_go > 15) cargo_to_go = ranrot_rand() % cargo_to_go; - //NSLog(@"explosion in %@ %d will launch %d pieces of cargo (max_cargo = %d)", name, universal_id, cargo_to_go, max_cargo); [self setCargo:[universe getContainersOfScarceGoods:cargo_to_go]]; cargo_chance = 100; } @@ -5454,11 +5427,9 @@ BOOL class_masslocks(int some_class) Vector my_aim = vector_forward_from_quaternion(q_rotation); Vector my_ref = reference; double aim_cos, ref_cos; - // + Entity* targent = [self getPrimaryTarget]; - // - // - //NSLog(@"DEBUG ball_tracking (before rotation) my_aim (%.2f,%.2f,%.2f) my_ref (%.2f,%.2f,%.2f)", my_aim.x, my_aim.y, my_aim.z, my_ref.x, my_ref.y, my_ref.z); + Entity* last = nil; Entity* father = [self owner]; GLfloat* r_mat = [father drawRotationMatrix]; @@ -5492,9 +5463,6 @@ BOOL class_masslocks(int some_class) aim_cos = 0.0; ref_cos = -1.0; } - // - //NSLog(@"DEBUG ball_tracking vtt (%.2f,%.2f,%.2f)", vector_to_target.x, vector_to_target.y, vector_to_target.z); - //NSLog(@"DEBUG ball_tracking target %@ aim_cos = %.3f ref_cos = %.3f", [(ShipEntity *)targent name], aim_cos, ref_cos); if (ref_cos > TURRET_MINIMUM_COS) // target is forward of self { @@ -5563,10 +5531,7 @@ BOOL class_masslocks(int some_class) Entity* targent = [self getPrimaryTarget]; // Vector leading = [targent getVelocity]; -// leading.x *= lead_t; leading.y *= lead_t; leading.z *= lead_t; - // - // - //NSLog(@"DEBUG ball_tracking (before rotation) my_aim (%.2f,%.2f,%.2f) my_ref (%.2f,%.2f,%.2f)", my_aim.x, my_aim.y, my_aim.z, my_ref.x, my_ref.y, my_ref.z); + Entity* last = nil; Entity* father = [self owner]; GLfloat* r_mat = [father drawRotationMatrix]; @@ -5604,9 +5569,6 @@ BOOL class_masslocks(int some_class) aim_cos = 0.0; ref_cos = -1.0; } - // - //NSLog(@"DEBUG ball_tracking vtt (%.2f,%.2f,%.2f)", vector_to_target.x, vector_to_target.y, vector_to_target.z); - //NSLog(@"DEBUG ball_tracking target %@ aim_cos = %.3f ref_cos = %.3f", [(ShipEntity *)targent name], aim_cos, ref_cos); if (ref_cos > TURRET_MINIMUM_COS) // target is forward of self { @@ -5945,10 +5907,7 @@ BOOL class_masslocks(int some_class) // begin rule-of-thumb manoeuvres stick_pitch = 0.0; stick_roll = 0.0; - -// if (isPlayer) -// NSLog(@"DEBUG trackDestination:: max_cos %.4f, d_forward %.4f, we_are_docking %@", max_cos, d_forward, (we_are_docking)? @":YES:" : @":NO:"); - + // check if we are flying toward the destination.. if ((d_forward < max_cos)||(retreat)) // not on course so we must adjust controls.. { @@ -5994,42 +5953,11 @@ BOOL class_masslocks(int some_class) if (we_are_docking && docking_match_rotation && (d_forward > max_cos)) { /* we are docking and need to consider the rotation/orientation of the docking port */ - -// NSLog(@"DEBUG DOCKING MATCH ROTATION %@ targetStation = %d %@ primaryTarget = %d %@", -// self, targetStation, [universe entityForUniversalID:targetStation], primaryTarget, [universe entityForUniversalID:primaryTarget]); StationEntity* station_for_docking = (StationEntity*)[universe entityForUniversalID:targetStation]; if ((station_for_docking)&&(station_for_docking->isStation)) { stick_roll = [self rollToMatchUp:[station_for_docking portUpVectorForShipsBoundingBox: boundingBox] rotating:[station_for_docking flight_roll]]; -// Vector up_vec = [station_for_docking portUpVectorForShipsBoundingBox: boundingBox]; -// double cosTheta = dot_product(up_vec, v_up); // == cos of angle between up vectors -// double sinTheta = dot_product(up_vec, v_right); -// -// double station_roll = [station_for_docking flight_roll]; -// -// if (!isPlayer) -// { -// station_roll = -station_roll; // make necessary corrections for a different viewpoint -// sinTheta = -sinTheta; -// } -// -// if (cosTheta < 0) -// { -// cosTheta = -cosTheta; -// sinTheta = -sinTheta; -// } -// -// if (sinTheta > 0.0) -// { -// // increase roll rate -// stick_roll = cosTheta * cosTheta * station_roll + sinTheta * sinTheta * max_flight_roll; -// } -// else -// { -// // decrease roll rate -// stick_roll = cosTheta * cosTheta * station_roll - sinTheta * sinTheta * max_flight_roll; -// } } } @@ -6224,10 +6152,6 @@ BOOL class_masslocks(int some_class) // set new values from aft_weapon_type // [self set_weapon_data_from_type:aft_weapon_type]; - // - // - - //NSLog(@"DEBUG %@ should fire aft weapon",name); if (shot_time < weapon_recharge_rate) return NO; @@ -6236,8 +6160,6 @@ BOOL class_masslocks(int some_class) if (range > randf() * weapon_range) return NO; - //NSLog(@"DEBUG %@ firing aft weapon",name); - if (result) { switch (aft_weapon_type) @@ -6351,8 +6273,6 @@ BOOL class_masslocks(int some_class) hit_at_range = weapon_range; target_laser_hit = [universe getFirstEntityHitByLaserFromEntity:self inView:direction offset: make_vector(0,0,0) rangeFound: &hit_at_range]; -// NSLog(@"DEBUG target hit by SubEntityLaserShot: %d %@", target_laser_hit, [universe entityForUniversalID:target_laser_hit]); - shot = [[ParticleEntity alloc] initLaserFromSubentity:self view:direction]; // alloc retains! [shot setColor:laser_color]; [shot setScanClass: CLASS_NO_DRAW]; @@ -6394,8 +6314,6 @@ BOOL class_masslocks(int some_class) - (BOOL) fireDirectLaserShot { -// NSLog(@"DEBUG %@ %d laser fired direct shot on %@ %d", name, universal_id, [(ShipEntity*)[self getPrimaryTarget] name], primaryTarget); - GLfloat hit_at_range; Entity* my_target = [self getPrimaryTarget]; if (!my_target) @@ -6409,8 +6327,6 @@ BOOL class_masslocks(int some_class) else r_pos.z = 1.0; -// target_laser_hit = primaryTarget; - Quaternion q_laser = quaternion_rotation_between(r_pos, make_vector(0.0f,0.0f,1.0f)); q_laser.x += 0.01 * (randf() - 0.5); // randomise aim a little (+/- 0.005) q_laser.y += 0.01 * (randf() - 0.5); @@ -6501,10 +6417,7 @@ BOOL class_masslocks(int some_class) } target_laser_hit = [universe getFirstEntityHitByLaserFromEntity:self inView:direction offset:laserPortOffset rangeFound: &hit_at_range]; - -// if (isPlayer) -// NSLog(@"DEBUG target double-check range = %.2f victim = %d --> %@\n\n", hit_at_range, target_laser_hit, [universe entityForUniversalID:target_laser_hit]); - + shot = [[ParticleEntity alloc] initLaserFromShip:self view:direction offset:laserPortOffset]; // alloc retains! [shot setColor:laser_color]; @@ -6697,13 +6610,13 @@ BOOL class_masslocks(int some_class) // custom missiles if ([shipinfoDictionary objectForKey:@"missile_role"]) - missile = [universe getShipWithRole:(NSString*)[shipinfoDictionary objectForKey:@"missile_role"]]; + missile = [universe newShipWithRole:(NSString*)[shipinfoDictionary objectForKey:@"missile_role"]]; if (!missile) // no custom role { if (randf() < 0.90) // choose a standard missile 90% of the time - missile = [universe getShipWithRole:@"EQ_MISSILE"]; // retained + missile = [universe newShipWithRole:@"EQ_MISSILE"]; // retained else // otherwise choose any with the role 'missile' - which may include alternative weapons - missile = [universe getShipWithRole:@"missile"]; // retained + missile = [universe newShipWithRole:@"missile"]; // retained } if (!missile) @@ -6793,7 +6706,7 @@ BOOL class_masslocks(int some_class) return NO; has_energy_bomb = NO; [self setSpeed: max_flight_speed + 300]; - ShipEntity* bomb = [universe getShipWithRole:@"energy-bomb"]; + ShipEntity* bomb = [universe newShipWithRole:@"energy-bomb"]; if (!bomb) return NO; double start = collision_radius + bomb->collision_radius; @@ -6831,7 +6744,7 @@ BOOL class_masslocks(int some_class) [universe addEntity:bomb]; [[bomb getAI] setState:@"GLOBAL"]; [bomb release]; - if (self != [universe entityZero]) // get the heck out of here + if (self != [PlayerEntity sharedPlayer]) // get the heck out of here { [self addTarget:bomb]; behaviour = BEHAVIOUR_FLEE_TARGET; @@ -6854,12 +6767,12 @@ BOOL class_masslocks(int some_class) // check for custom escape pod // if ([shipinfoDictionary objectForKey:@"escape_pod_model"]) - pod = [universe getShipWithRole: (NSString*)[shipinfoDictionary objectForKey:@"escape_pod_model"]]; + pod = [universe newShipWithRole: (NSString*)[shipinfoDictionary objectForKey:@"escape_pod_model"]]; // // if not found - use standard escape pod // if (!pod) - pod = [universe getShipWithRole:@"escape-capsule"]; // retain count = 1 + pod = [universe newShipWithRole:@"escape-capsule"]; // retain count = 1 if (pod) { @@ -6888,7 +6801,7 @@ BOOL class_masslocks(int some_class) int i; for (i = 1; i < n_pods; i++) { - pod = [universe getShipWithRole:@"escape-capsule"]; + pod = [universe newShipWithRole:@"escape-capsule"]; if (pod) { Random_Seed orig = [universe systemSeedForSystemNumber:gen_rnd_number()]; @@ -7048,9 +6961,6 @@ BOOL class_masslocks(int some_class) if (!other) return NO; - -// if ((self->isPlayer)||(other->isPlayer)) -// NSLog(@"DEBUG %@ %d colliding with other %@ %d", name, universal_id, [other name], [other universal_id]); ShipEntity* otherParent = (ShipEntity*)[other owner]; BOOL otherIsSubentity = ((otherParent)&&(otherParent != other)&&([otherParent->sub_entities containsObject:other])); @@ -7123,23 +7033,13 @@ BOOL class_masslocks(int some_class) // are they moving apart at over 1m/s already? if (v2b < 0.0f) { - if (v2b < -1.0f) - { -// NSLog(@"MOVING APART! %@ >%.3f %.3f< %@", self, sqrt(distance2(position, opos)), v2b, other); - return NO; - } + if (v2b < -1.0f) return NO; else { -// NSLog(@"MOVING APART TOO SLOW! %@ >%.3f %.3f< %@", self, sqrt(distance2(position, opos)), v2b, other); position = make_vector( position.x - loc.x, position.y - loc.y, position.z - loc.z); // adjust self position v = make_vector( 0.0f, 0.0f, 0.0f); // go for the 1m/s solution } } -// else -// { -// NSLog(@"MOVING CLOSER %@ >%.3f %.3f< %@", self, sqrt(distance2(position, opos)), v2b, other); -// } - // // convert change in velocity into damage energy (KE) // @@ -7190,9 +7090,7 @@ BOOL class_masslocks(int some_class) [other adjustVelocity:vel1a]; } } - -// NSLog(@"DEBUG back-off distance is %.3fm\n\n", back_dist); - // + if ((!selfDestroyed)&&(!otherDestroyed)) { float t = 10.0 * [universe getTimeDelta]; // 10 ticks @@ -7242,18 +7140,12 @@ BOOL class_masslocks(int some_class) - (BOOL) canScoop:(ShipEntity*)other { -// NSLog(@"DEBUG Checking if %@ %d can scoop %@ %d", name, universal_id, [other name], [other universal_id]); if (!other) return NO; - // if (!has_scoop) return NO; -// NSLog(@"DEBUG scoop okay"); if ([cargo count] >= max_cargo) return NO; -// NSLog(@"DEBUG cargo space okay"); if (scan_class == CLASS_CARGO) return NO; // we have no power so we can't scoop if (other->scan_class != CLASS_CARGO) return NO; -// NSLog(@"DEBUG other scan class is CLASS_CARGO okay"); if ([other getCargoType] == CARGO_NOT_CARGO) return NO; -// NSLog(@"DEBUG other cargo type is not CARGO_NOT_CARGO okay"); if (other->isStation) return NO; @@ -7320,7 +7212,7 @@ BOOL class_masslocks(int some_class) //scripting if ([actions count]) { - PlayerEntity* player = (PlayerEntity *)[universe entityZero]; + PlayerEntity* player = [PlayerEntity sharedPlayer]; [player setScript_target:self]; [player scriptActions: actions forTarget: other]; @@ -7341,9 +7233,8 @@ BOOL class_masslocks(int some_class) if (co_amount > 0) { [other setCommodity:co_type andAmount:co_amount]; // belt and braces setting this! - if (cargo_flag !=CARGO_FLAG_CANISTERS) - cargo_flag = CARGO_FLAG_CANISTERS; - //NSLog(@"---> %@ %d scooped %@", name, universal_id, [universe describeCommodity:co_type amount:co_amount]); + cargo_flag = CARGO_FLAG_CANISTERS; + if (isPlayer) { [universe clearPreviousMessage]; @@ -7536,8 +7427,6 @@ int w_space_seed = 1234567; [shipAI message:@"EXITED_WITCHSPACE"]; [universe addEntity:self]; -// NSLog(@"DEBUG Ship: %@ exiting witchspace at %.2f %.2f %.2f", self, position.x, position.y, position.z); - // witchspace exit effects here ParticleEntity *ring1 = [[ParticleEntity alloc] initHyperringFromShip:self]; // retained [universe addEntity:ring1]; @@ -7550,9 +7439,7 @@ int w_space_seed = 1234567; - (void) markAsOffender:(int)offence_value { -// if (![roles isEqual:@"police"]) - if (scan_class != CLASS_POLICE) - bounty |= offence_value; + if (scan_class != CLASS_POLICE) bounty |= offence_value; } - (void) switchLightsOn @@ -7598,25 +7485,18 @@ inline BOOL pairOK(NSString* my_role, NSString* their_role) pairing_okay |= (![my_role isEqual:@"escort"] && ![my_role isEqual:@"wingman"] && [their_role isEqual:@"escort"]); pairing_okay |= (([my_role isEqual:@"police"]||[my_role isEqual:@"interceptor"]) && [their_role isEqual:@"wingman"]); -// NSLog(@"checking if pairOK for ( %@, %@) >> %@", my_role, their_role, (pairing_okay)? @"YES":@"NO"); - return pairing_okay; } - (BOOL) acceptAsEscort:(ShipEntity *) other_ship { // can't pair with self - if (self == other_ship) - return NO; - -// NSLog(@"DEBUG %@ %d asked to accept %@ %d as escort when ai_stack_depth is %d", name, universal_id, [other_ship name], [other_ship universal_id], [shipAI ai_stack_depth]); + if (self == other_ship) return NO; // if not in standard ai mode reject approach if ([shipAI ai_stack_depth] > 1) return NO; -// NSLog(@"DEBUG pairOK( %@, %@) = %@", roles, [other_ship roles], (pairOK( roles, [other_ship roles]))? @"YES":@"NO"); - if (pairOK( roles, [other_ship roles])) { // check total number acceptable @@ -7641,9 +7521,6 @@ inline BOOL pairOK(NSString* my_role, NSString* their_role) [self setGroup_id:universal_id]; // make self part of same group n_escorts++; - //debug -// NSLog(@"DEBUG ::YES:: %@ accepts escort %@", self, other_ship); - return YES; } } @@ -7680,7 +7557,6 @@ inline BOOL pairOK(NSString* my_role, NSString* their_role) if (primaryTarget == last_escort_target) { // already deployed escorts onto this target! -// NSLog(@"DEBUG attempting to deploy more escorts onto same target - denied"); return; } @@ -7690,8 +7566,6 @@ inline BOOL pairOK(NSString* my_role, NSString* their_role) if (n_deploy == 0) n_deploy = 1; - //NSLog(@"DEBUG %@ %d deploying %d escorts", name, universal_id, n_deploy); - int i_deploy = n_escorts - 1; while ((n_deploy > 0)&&(n_escorts > 0)) { @@ -7714,9 +7588,6 @@ inline BOOL pairOK(NSString* my_role, NSString* their_role) i_deploy--; n_deploy--; n_escorts--; - //debug - //NSLog(@"DEBUG trader %@ %d deploys escort %@ %d", name, universal_id, [escorter name], [escorter universal_id]); - //[escorter setReportAImessages:YES]; } else { @@ -7901,7 +7772,6 @@ inline BOOL pairOK(NSString* my_role, NSString* their_role) - (void) broadcastHitByLaserFrom:(ShipEntity*) aggressor_ship { /*-- If you're clean, locates all police and stations in range and tells them OFFENCE_COMMITTED --*/ -// NSLog(@"DEBUG IN [%@ broadcastHitByLaserFrom:%@]", self, aggressor_ship); if (!universe) return; if (bounty) @@ -7915,7 +7785,6 @@ inline BOOL pairOK(NSString* my_role, NSString* their_role) (scan_class == CLASS_MILITARY)|| (scan_class == CLASS_PLAYER)) // only for active ships... { -// NSLog(@"DEBUG IN [%@ broadcastHitByLaserFrom:%@]", self, aggressor_ship); int ent_count = universe->n_entities; Entity** uni_entities = universe->sortedEntities; // grab the public sorted list Entity* my_entities[ent_count]; @@ -7931,7 +7800,6 @@ inline BOOL pairOK(NSString* my_role, NSString* their_role) ShipEntity* ship = (ShipEntity *)my_entities[i]; if (((ship == mainStation) && (within_station_aegis)) || (distance2( position, ship->position) < SCANNER_MAX_RANGE2)) { -// NSLog(@"DEBUG SENDING %@'s AI \"OFFENCE_COMMITTED\"", ship); [ship setFound_target: aggressor_ship]; [[ship getAI] reactToMessage: @"OFFENCE_COMMITTED"]; } @@ -7993,7 +7861,7 @@ inline BOOL pairOK(NSString* my_role, NSString* their_role) very_random_seed.e = rand() & 255; very_random_seed.f = rand() & 255; seed_RNG_only_for_planet_description(very_random_seed); - NSString* expandedMessage = [universe expandDescription:localExpandedMessage forSystem:[universe systemSeed]]; + NSString* expandedMessage = ExpandDescriptionForCurrentSystem(localExpandedMessage); [self setCommsMessageColor]; [other_ship receiveCommsMessage:[NSString stringWithFormat:@"%@:\n %@", name, expandedMessage]]; if (other_ship->isPlayer) @@ -8306,12 +8174,10 @@ inline BOOL pairOK(NSString* my_role, NSString* their_role) // No over-ride of Entity's version of the method is required for non-Win32 platforms. - (void) reloadTextures { - //NSLog(@"ShipEntity::reloadTextures called, resetting subentities and calling super"); int i; for (i = 0; i < [sub_entities count]; i++) { Entity *e = (Entity *)[sub_entities objectAtIndex:i]; - //NSLog(@"ShipEntity::reloadTextures calling reloadTextures on: %@", [e description]); [e reloadTextures]; } diff --git a/src/Core/ShipEntityAI.m b/src/Core/ShipEntityAI.m index 2e90036c..f6b70e86 100644 --- a/src/Core/ShipEntityAI.m +++ b/src/Core/ShipEntityAI.m @@ -35,6 +35,8 @@ MA 02110-1301, USA. #import "OOStringParsing.h" +#define kOOLogUnconvertedNSLog @"unclassified.ShipEntityAI" + @implementation ShipEntity (AI) @@ -384,7 +386,6 @@ MA 02110-1301, USA. { flight_roll = max_flight_roll*2.0*(randf() - 0.5); flight_pitch = max_flight_pitch*2.0*(randf() - 0.5); -// velocity = make_vector( flight_speed*2.0*(randf() - 0.5), flight_speed*2.0*(randf() - 0.5), flight_speed*2.0*(randf() - 0.5)); behaviour = BEHAVIOUR_TUMBLE; frustration = 0.0; } @@ -655,8 +656,6 @@ MA 02110-1301, USA. } } -// NSLog(@"DEBUG %@'s scanForOffenders found %@ with legal_factor %.1f", self, [universe entityForUniversalID:found_target], worst_legal_factor); - if (found_target != NO_TARGET) [shipAI message:@"TARGET_FOUND"]; else @@ -882,8 +881,7 @@ WormholeEntity* whole; // scared - ignore the request; break; - default : - //NSLog(@"%@ %d responding to distress message from %@ %d", name, universal_id, [other name], [other universal_id]); + default: if ((scan_class == CLASS_POLICE)||[roles isEqual:@"police"]||[roles isEqual:@"interceptor"]||[roles isEqual:@"wingman"]) [(ShipEntity *)[universe entityForUniversalID:found_target] markAsOffender:8]; // you have been warned!! [shipAI reactToMessage:@"ACCEPT_DISTRESS_CALL"]; @@ -1025,31 +1023,15 @@ WormholeEntity* whole; } } - if (found_target != NO_TARGET) - { - //NSLog(@"DEBUG %@ %d scanForHostiles ----> found %@ %@ %d", name, universal_id, [(ShipEntity *)[universe entityForUniversalID:found_target] roles], [(ShipEntity *)[universe entityForUniversalID:found_target] name], found_target); - //[self setReportAImessages:YES]; - - [shipAI message:@"TARGET_FOUND"]; - } - else - [shipAI message:@"NOTHING_FOUND"]; + if (found_target != NO_TARGET) [shipAI message:@"TARGET_FOUND"]; + else [shipAI message:@"NOTHING_FOUND"]; } - (void) fightOrFleeHostiles { - //NSLog(@"DEBUG %@ %d considers fightOrFleeHostiles", name, universal_id); - // consider deploying escorts - //if ([escorts count] > 0) if (n_escorts > 0) { - if (found_target == last_escort_target) - { - //NSLog(@"DEBUG exit fightOrFleeHostiles because found_target == last_escort_target == %d", found_target); - return; - } - - //NSLog(@"DEBUG %@ %d decides to deploy escorts and flee", name, universal_id); + if (found_target == last_escort_target) return; primaryAggressor = found_target; primaryTarget = found_target; @@ -1064,8 +1046,6 @@ WormholeEntity* whole; { if (randf() < 0.50) { - //NSLog(@"DEBUG %@ %d decides to launch missile and flee", name, universal_id); - primaryAggressor = found_target; primaryTarget = found_target; [self fireMissile]; @@ -1077,15 +1057,12 @@ WormholeEntity* whole; // consider fighting if (energy > max_energy * 0.80) { - //NSLog(@"DEBUG %@ %d decides to fight hostiles", name, universal_id); - primaryAggressor = found_target; //[self performAttack]; [shipAI message:@"FIGHTING"]; return; } - - //NSLog(@"DEBUG %@ %d decides to flee hostiles", name, universal_id); + [shipAI message:@"FLEEING"]; } @@ -1105,7 +1082,6 @@ WormholeEntity* whole; int extra = 1 | (ranrot_rand() & 15); [mother setBounty: [mother legal_status] + extra]; bounty += extra; // obviously we're dodgier than we thought! -// NSLog(@"DEBUG setting new bounty for %@ escorting %@ to %d", self, mother, extra); } // [self setOwner:mother]; @@ -1158,9 +1134,6 @@ WormholeEntity* whole; int own_group_numbers = [self numberOfShipsInGroup:own_group_id] + (ranrot_rand() & 3); // add a random fudge factor int target_group_numbers = [self numberOfShipsInGroup:target_group_id] + (ranrot_rand() & 3); // add a random fudge factor - //debug - //NSLog(@"DEBUG pirates of group %d (%d ships) considering an attack on group %d (%d ships)", own_group_id, own_group_numbers, target_group_id, target_group_numbers); - if (own_group_numbers == target_group_numbers) { [shipAI message:@"ODDS_LEVEL"]; @@ -1177,17 +1150,12 @@ WormholeEntity* whole; { if (group_id == NO_TARGET) // ship is alone! { - //debug - //NSLog(@"DEBUG Lone ship %@ %d attacking target %d", name, universal_id, found_target); - found_target = primaryTarget; [shipAI reactToMessage:@"GROUP_ATTACK_TARGET"]; return; } NSArray* fellow_ships = [self shipsInGroup:group_id]; - //debug - //NSLog(@"DEBUG %d %@ ships of group %d attacking target %d", [fellow_ships count], roles, group_id, found_target); ShipEntity* target_ship = (ShipEntity*) [universe entityForUniversalID:primaryTarget]; if ((!target_ship)||(target_ship->isShip != YES)) @@ -1730,8 +1698,6 @@ WormholeEntity* whole; } [wh release]; // released } - -// NSLog(@"DEBUG %@ told to enter wormhole %@", self, whole); if (!whole) return; @@ -1743,7 +1709,7 @@ WormholeEntity* whole; - (void) scriptActionOnTarget:(NSString*) action { - PlayerEntity* player = (PlayerEntity*)[universe entityZero]; + PlayerEntity* player = [PlayerEntity sharedPlayer]; Entity* targEnt = [universe entityForUniversalID:primaryTarget]; if ((targEnt)&&(player)) { diff --git a/src/Core/SkyEntity.h b/src/Core/SkyEntity.h index 4fde1490..bf320309 100644 --- a/src/Core/SkyEntity.h +++ b/src/Core/SkyEntity.h @@ -28,7 +28,6 @@ MA 02110-1301, USA. #import "Entity.h" -#define SKY_POINTS 2 #define SKY_BILLBOARDS 3 #define BILLBOARD_DEPTH 50000.0 diff --git a/src/Core/SkyEntity.m b/src/Core/SkyEntity.m index 662c0a10..2df15a1c 100644 --- a/src/Core/SkyEntity.m +++ b/src/Core/SkyEntity.m @@ -26,6 +26,7 @@ MA 02110-1301, USA. #import "Entity.h" #import "SkyEntity.h" +#import "PlayerEntity.h" #import "OOMaths.h" #import "Universe.h" @@ -442,7 +443,7 @@ MA 02110-1301, USA. { if (usingVAR) [self OGL_UpdateVAR]; - Entity* player = [universe entityZero]; + PlayerEntity *player = [PlayerEntity sharedPlayer]; zero_distance = MAX_CLEAR_DEPTH * MAX_CLEAR_DEPTH; position = (player)? player->position : position; } @@ -471,10 +472,6 @@ MA 02110-1301, USA. { switch (sky_type) { - case SKY_POINTS : - NSLog(@"ERROR: SkyEntity SKY_POINTS deprecated"); - break; - case SKY_BILLBOARDS : if ((star_textureName == 0)&&(universe)) @@ -492,10 +489,6 @@ MA 02110-1301, USA. if (usingVAR) glBindVertexArrayAPPLE(gVertexArrayRangeObjects[0]); #endif - -// if (usingVAR) -// NSLog(@"DEBUG using accelerated memory technique to draw %@ (%@)", self, basefile); -// glBindTexture(GL_TEXTURE_2D, star_textureName); glEnableClientState(GL_VERTEX_ARRAY); @@ -594,8 +587,6 @@ MA 02110-1301, USA. // No over-ride of Entity's version of the method is required for non-Win32 platforms. - (void) reloadTextures { - //NSLog(@"SkyEntity::reloadTextures called, calling super and resetTextureNames"); - // Force the sky textures to be reloaded next time a frame is drawn. star_textureName = 0; blob_textureName = 0; diff --git a/src/Core/StationEntity.m b/src/Core/StationEntity.m index bcb9958b..822e0222 100644 --- a/src/Core/StationEntity.m +++ b/src/Core/StationEntity.m @@ -36,16 +36,14 @@ MA 02110-1301, USA. #import "AI.h" #import "OOCharacter.h" +#define kOOLogUnconvertedNSLog @"unclassified.StationEntity" + @implementation StationEntity - (void) acceptDistressMessageFrom:(ShipEntity *)other { - if (self != [universe station]) - { - //NSLog(@"DEBUG acceptDistressMessageFrom rejected from sub-station '%@'", name); - return; - } + if (self != [universe station]) return; int old_target = primaryTarget; primaryTarget = [[other getPrimaryTarget] universal_id]; @@ -147,7 +145,6 @@ MA 02110-1301, USA. - (NSMutableArray *) initialiseLocalMarketWithSeed: (Random_Seed) s_seed andRandomFactor: (int) random_factor { - //NSLog(@"///// Initialising local market for station %@ with roles %@",self,[self roles]); int rf = (random_factor ^ universal_id) & 0xff; int economy = [(NSNumber *)[[universe generateSystemData:s_seed] objectForKey:KEY_ECONOMY] intValue]; if (localMarket) @@ -158,19 +155,17 @@ MA 02110-1301, USA. - (NSMutableArray *) initialiseLocalPassengersWithSeed: (Random_Seed) s_seed andRandomFactor: (int) random_factor { - //NSLog(@"///// Initialising local market for station %@ with roles %@",self,[self roles]); if (localPassengers) [localPassengers release]; - localPassengers = [[NSMutableArray alloc] initWithArray:[universe passengersForSystem:s_seed atTime:[[(PlayerEntity*)[universe entityZero] clock_number] intValue]]]; + localPassengers = [[NSMutableArray alloc] initWithArray:[universe passengersForSystem:s_seed atTime:[[[PlayerEntity sharedPlayer] clock_number] intValue]]]; return localPassengers; } - (NSMutableArray *) initialiseLocalContractsWithSeed: (Random_Seed) s_seed andRandomFactor: (int) random_factor { - //NSLog(@"///// Initialising local market for station %@ with roles %@",self,[self roles]); if (localContracts) [localContracts release]; - localContracts = [[NSMutableArray alloc] initWithArray:[universe contractsForSystem:s_seed atTime:[[(PlayerEntity*)[universe entityZero] clock_number] intValue]]]; + localContracts = [[NSMutableArray alloc] initWithArray:[universe contractsForSystem:s_seed atTime:[[[PlayerEntity sharedPlayer] clock_number] intValue]]]; return localContracts; } @@ -423,10 +418,6 @@ NSDictionary* instructions(int station_id, Vector coords, float speed, float ran Vector delta = ship->position; delta.x -= coords.x; delta.y -= coords.y; delta.z -= coords.z; -// if (ship->isPlayer) -// NSLog(@"DEBUG docking_stage %d: ship is %.2fm from control point ( %.2f, %.2f, %.2f)", -// docking_stage, sqrt(magnitude2(delta)), coords.x, coords.y, coords.z); - if (magnitude2(delta) > max_allowed_range * max_allowed_range) // too far from the coordinates - do not remove them from the stack! { if ((docking_stage == 1) &&(magnitude2(delta) < 1000000.0)) // 1km*1km @@ -509,8 +500,6 @@ NSDictionary* instructions(int station_id, Vector coords, float speed, float ran int corridor_count = 9; int corridor_final_approach = 3; -// NSLog(@"DEBUG adding %@ to shipsOnApproach", ship); - int ship_id = [ship universal_id]; NSString* shipID = [NSString stringWithFormat:@"%d", ship_id]; @@ -621,16 +610,12 @@ NSDictionary* instructions(int station_id, Vector coords, float speed, float ran - (Vector) portUpVector { -// NSLog(@"DEBUG docking port for %@ is %@ dimensions ( %.2f, %.2f, %.2f)", self, port_model, -// port_dimensions.x, port_dimensions.y, port_dimensions.z); if (port_dimensions.x > port_dimensions.y) { -// NSLog(@"DEBUG returning UP !"); return vector_up_from_quaternion( quaternion_multiply( port_qrotation, q_rotation)); } else { -// NSLog(@"DEBUG returning RIGHT !"); return vector_right_from_quaternion( quaternion_multiply( port_qrotation, q_rotation)); } } @@ -639,8 +624,6 @@ NSDictionary* instructions(int station_id, Vector coords, float speed, float ran { BOOL twist = ((port_dimensions.x < port_dimensions.y) ^ (bb.max.x - bb.min.x < bb.max.y - bb.min.y)); -// NSLog(@"DEBUG docking: port_twist:%@ ship_twist:%@ twist:%@", (port_dimensions.x < port_dimensions.y)?@"YES":@"NO", (bb.max.x - bb.min.x < bb.max.y - bb.min.y)?@"YES":@"NO", twist?@"YES":@"NO"); - if (!twist) { return vector_up_from_quaternion( quaternion_multiply( port_qrotation, q_rotation)); @@ -750,8 +733,6 @@ NSDictionary* instructions(int station_id, Vector coords, float speed, float ran { self = [super initWithDictionary:dict]; - //NSLog(@"DEBUG setting up station '%@' from dict:%@",name,[dict description]); - if ([dict objectForKey:@"equivalent_tech_level"]) equivalent_tech_level = [(NSNumber *)[dict objectForKey:@"equivalent_tech_level"] intValue]; else @@ -1043,7 +1024,6 @@ NSDictionary* instructions(int station_id, Vector coords, float speed, float ran if (vdp > 0.86) { isEmpty = NO; -// NSLog(@"DEBUG %@ is blocking %@ launch corridor distance = %.0f (%.0f).", ship, self, sqrt(d2), d2); last_launch_time = unitime; } } @@ -1101,8 +1081,8 @@ NSDictionary* instructions(int station_id, Vector coords, float speed, float ran if (vdp > 0.86) { isClear = NO; + // okay it's in the way .. give it a wee nudge (0.25s) -// NSLog(@"DEBUG [StationEntity clearDockingCorridor] nudging %@", ship); [ship update: 0.25]; time_out += 0.25; } @@ -1131,9 +1111,6 @@ NSDictionary* instructions(int station_id, Vector coords, float speed, float ran double unitime = [universe getTime]; -// if (sub_entities) -// NSLog(@"DEBUG %@ sub_entities %@", [self name], [sub_entities description]); - [super update:delta_t]; if (([launchQueue count] > 0)&&([shipsOnApproach count] == 0)&&[self dockingCorridorIsEmpty]) @@ -1160,10 +1137,8 @@ NSDictionary* instructions(int station_id, Vector coords, float speed, float ran if ((docked_traders > 0)&&(!isRockHermit)) { -// NSLog(@"DEBUG1 %f %f", unitime, last_trader_launch_time + trader_launch_interval); if (unitime > last_trader_launch_time + trader_launch_interval) { -// NSLog(@"DEBUG O ---> %d docked traders at %.1f (%.1f and every %.1f)", docked_traders, [universe getTime], last_trader_launch_time + trader_launch_interval, trader_launch_interval); [self launchTrader]; docked_traders--; last_trader_launch_time = unitime; @@ -1173,7 +1148,6 @@ NSDictionary* instructions(int station_id, Vector coords, float speed, float ran // testing patrols if ((unitime > last_patrol_report_time + patrol_launch_interval)&&(isMainStation)) { -// NSLog(@"%@ %d (%@) launching a patrol...", name, universal_id, roles); if (![self launchPatrol]) last_patrol_report_time = unitime; } @@ -1277,7 +1251,7 @@ NSDictionary* instructions(int station_id, Vector coords, float speed, float ran if ((id_lock[i] == ship_id)||([universe entityForUniversalID:id_lock[i]] == nil)) id_lock[i] = NO_TARGET; - if (ship == [universe entityZero]) // ie. the player + if (ship == [PlayerEntity sharedPlayer]) // ie. the player { //scripting if ([script_actions count]) @@ -1286,10 +1260,6 @@ NSDictionary* instructions(int station_id, Vector coords, float speed, float ran [(PlayerEntity *)ship scriptActions: script_actions forTarget: ship]; } } - -// NSLog(@"DEBUG ::::: %d :: %d :: %d :: %d :: %d :: %d :: %d :: %d :: %d :: %d <<", -// id_lock[10],id_lock[9],id_lock[8],id_lock[7],id_lock[6],id_lock[5],id_lock[4],id_lock[3],id_lock[2],id_lock[1]); - } @@ -1359,13 +1329,11 @@ NSDictionary* instructions(int station_id, Vector coords, float speed, float ran [shipAI reactToMessage:@"TARGET_LOST"]; return; } - - //NSLog(@"Launching Police Ship to intercept %@",[universe entityForUniversalID:police_target]); if ((ranrot_rand() & 7) + 6 <= techlevel) - police_ship = [universe getShipWithRole:@"interceptor"]; // retain count = 1 + police_ship = [universe newShipWithRole:@"interceptor"]; // retain count = 1 else - police_ship = [universe getShipWithRole:@"police"]; // retain count = 1 + police_ship = [universe newShipWithRole:@"police"]; // retain count = 1 if (police_ship) { if (![police_ship crew]) @@ -1415,29 +1383,23 @@ NSDictionary* instructions(int station_id, Vector coords, float speed, float ran if ([shipinfoDictionary objectForKey:@"defense_ship"]) { -// NSLog(@"DEBUG Defense ship key found: %@", [shipinfoDictionary objectForKey:@"defense_ship"]); defense_ship_key = (NSString*)[shipinfoDictionary objectForKey:@"defense_ship"]; defense_ship_ai = nil; } if ([shipinfoDictionary objectForKey:@"defense_ship_role"]) { -// NSLog(@"DEBUG Defense ship role key found: %@", [shipinfoDictionary objectForKey:@"defense_ship_role"]); defense_ship_role_key = (NSString*)[shipinfoDictionary objectForKey:@"defense_ship_role"]; defense_ship_ai = nil; } - -// NSLog(@"DEBUG Launching defense ship to intercept %@",[(ShipEntity *)[universe entityForUniversalID:defense_target] name]); if (defense_ship_key) { - defense_ship = [universe getShip:defense_ship_key]; -// NSLog(@"DEBUG launchDefenseShip Got ship with defense_ship '%@' : %@", defense_ship_key, defense_ship); + defense_ship = [universe newShipWithName:defense_ship_key]; [defense_ship setRoles:@"defense_ship"]; } else { - defense_ship = [universe getShipWithRole:defense_ship_role_key]; -// NSLog(@"DEBUG launchDefenseShip Got ship with defense_ship_role '%@' : %@", defense_ship_role_key, defense_ship); + defense_ship = [universe newShipWithRole:defense_ship_role_key]; [defense_ship setRoles:@"defense_ship"]; } @@ -1461,18 +1423,12 @@ NSDictionary* instructions(int station_id, Vector coords, float speed, float ran if ((scan_class != CLASS_ROCK)&&(scan_class != CLASS_STATION)) [defense_ship setScanClass: scan_class]; // same as self - - //[defense_ship setReportAImessages:YES]; // debug - -// NSLog(@"DEBUG Launching defense ship %@ %@", defense_ship, [defense_ship name]); [self addShipToLaunchQueue:defense_ship]; [defense_ship release]; no_docking_while_launching = YES; [self abortAllDockings]; -// NSLog(@"DEBUG Launchqueue : %@",[launchQueue description]); - } - (void) launchScavenger @@ -1481,17 +1437,12 @@ NSDictionary* instructions(int station_id, Vector coords, float speed, float ran int scavs = [universe countShipsWithRole:@"scavenger" inRange:SCANNER_MAX_RANGE ofEntity:self] + [self countShipsInLaunchQueueWithRole:@"scavenger"]; - if (scavs >= max_scavengers) - return; - - if (scavengers_launched >= max_scavengers) - return; - - //NSLog(@"Launching Scavenger"); + if (scavs >= max_scavengers) return; + if (scavengers_launched >= max_scavengers) return; scavengers_launched++; - scavenger_ship = [universe getShipWithRole:@"scavenger"]; // retain count = 1 + scavenger_ship = [universe newShipWithRole:@"scavenger"]; // retain count = 1 if (scavenger_ship) { if (![scavenger_ship crew]) @@ -1518,13 +1469,9 @@ NSDictionary* instructions(int station_id, Vector coords, float speed, float ran return; // count miners as scavengers... - // - if (scavengers_launched >= max_scavengers) - return; - // -// NSLog(@"Launching Miner"); - // - miner_ship = [universe getShipWithRole:@"miner"]; // retain count = 1 + if (scavengers_launched >= max_scavengers) return; + + miner_ship = [universe newShipWithRole:@"miner"]; // retain count = 1 if (miner_ship) { if (![miner_ship crew]) @@ -1557,12 +1504,10 @@ NSDictionary* instructions(int station_id, Vector coords, float speed, float ran return; } - //NSLog(@"Launching pirate Ship to intercept %@",[(ShipEntity *)[universe entityForUniversalID:defense_target] name]); //debug - police_launched++; // Yep! The standard hermit defence ships, even if they're the aggressor. - pirate_ship = [universe getShipWithRole:@"pirate"]; // retain count = 1 + pirate_ship = [universe newShipWithRole:@"pirate"]; // retain count = 1 // Nope, use standard pirates in a generic method. if (pirate_ship) @@ -1594,7 +1539,7 @@ NSDictionary* instructions(int station_id, Vector coords, float speed, float ran { ShipEntity *shuttle_ship; - shuttle_ship = [universe getShipWithRole:@"shuttle"]; // retain count = 1 + shuttle_ship = [universe newShipWithRole:@"shuttle"]; // retain count = 1 if (shuttle_ship) { @@ -1608,9 +1553,6 @@ NSDictionary* instructions(int station_id, Vector coords, float speed, float ran [shuttle_ship setCargoFlag:CARGO_FLAG_FULL_SCARCE]; [[shuttle_ship getAI] setStateMachine:@"fallingShuttleAI.plist"]; [self addShipToLaunchQueue:shuttle_ship]; - -// NSLog(@"%@ Prepping shuttle: %@ %d for launch.", [self name], [shuttle_ship name], [shuttle_ship universal_id]); -// [shuttle_ship setReportAImessages:YES]; //DEBUG [shuttle_ship release]; } @@ -1621,19 +1563,8 @@ NSDictionary* instructions(int station_id, Vector coords, float speed, float ran BOOL sunskimmer = (randf() < 0.1); // 10% ShipEntity *trader_ship = nil; -// NSLog(@"DEBUG %@ [StationEntity launchTrader]", self); - -// do { -// [trader_ship release]; - // - if (!sunskimmer) - trader_ship = [universe getShipWithRole:@"trader"]; // retain count = 1 - else - trader_ship = [universe getShipWithRole:@"sunskim-trader"]; // retain count = 1 - // -// } while (![trader_ship n_escorts]); // DEBUG we NEED escorts - -// NSLog(@"DEBUG [StationEntity launchTrader] ---> %@ ", trader_ship); + if (!sunskimmer) trader_ship = [universe newShipWithRole:@"trader"]; // retain count = 1 + else trader_ship = [universe newShipWithRole:@"sunskim-trader"]; // retain count = 1 if (trader_ship) { @@ -1663,8 +1594,6 @@ NSDictionary* instructions(int station_id, Vector coords, float speed, float ran [trader_ship setN_escorts:0]; while (escorts--) [self launchEscort]; - -// NSLog(@"%@ Prepping trader: %@ %d for launch.", [self name], [trader_ship name], [trader_ship universal_id]); [trader_ship release]; } @@ -1674,7 +1603,7 @@ NSDictionary* instructions(int station_id, Vector coords, float speed, float ran { ShipEntity *escort_ship; - escort_ship = [universe getShipWithRole:@"escort"]; // retain count = 1 + escort_ship = [universe newShipWithRole:@"escort"]; // retain count = 1 if (escort_ship) { @@ -1689,8 +1618,6 @@ NSDictionary* instructions(int station_id, Vector coords, float speed, float ran [[escort_ship getAI] setStateMachine:@"escortAI.plist"]; [self addShipToLaunchQueue:escort_ship]; -// [escort_ship setReportAImessages: YES]; - [escort_ship release]; } } @@ -1708,9 +1635,9 @@ NSDictionary* instructions(int station_id, Vector coords, float speed, float ran police_launched++; if ((ranrot_rand() & 7) + 6 <= techlevel) - patrol_ship = [universe getShipWithRole:@"interceptor"]; // retain count = 1 + patrol_ship = [universe newShipWithRole:@"interceptor"]; // retain count = 1 else - patrol_ship = [universe getShipWithRole:@"police"]; // retain count = 1 + patrol_ship = [universe newShipWithRole:@"police"]; // retain count = 1 if (patrol_ship) { if (![patrol_ship crew]) @@ -1736,7 +1663,7 @@ NSDictionary* instructions(int station_id, Vector coords, float speed, float ran - (void) launchShipWithRole:(NSString*) role { - ShipEntity *ship = [universe getShipWithRole: role]; // retain count = 1 + ShipEntity *ship = [universe newShipWithRole: role]; // retain count = 1 if (ship) { if (![ship crew]) @@ -1754,7 +1681,7 @@ NSDictionary* instructions(int station_id, Vector coords, float speed, float ran - (void) becomeExplosion { // launch docked ships if possible - PlayerEntity* player = (PlayerEntity*)[universe entityZero]; + PlayerEntity* player = [PlayerEntity sharedPlayer]; if ((player)&&(player->status == STATUS_DOCKED)&&([player docked_station] == self)) { // undock the player! @@ -1778,19 +1705,13 @@ NSDictionary* instructions(int station_id, Vector coords, float speed, float ran - (void) acceptPatrolReportFrom:(ShipEntity*) patrol_ship { last_patrol_report_time = [universe getTime]; -// NSLog(@"..... patrol report received from %@ %d at %3.2f", [patrol_ship name], [patrol_ship universal_id], [universe getTime]); } - (void) acceptDockingClearanceRequestFrom:(ShipEntity *)other { - if (self != [universe station]) - { - //NSLog(@"DEBUG acceptDistressMessageFrom rejected from sub-station '%@'", name); - return; - } + if (self != [universe station]) return; // check - // if ([shipsOnApproach count]) { [self sendExpandedMessage:@"Please wait until all ships have completed their approach." toShip:other]; @@ -1836,7 +1757,7 @@ NSDictionary* instructions(int station_id, Vector coords, float speed, float ran return YES; if ([shipinfoDictionary objectForKey:@"hasShipyard"]) { - PlayerEntity *player = (PlayerEntity*)[universe entityZero]; + PlayerEntity *player = [PlayerEntity sharedPlayer]; NSObject *determinant = [shipinfoDictionary objectForKey:@"hasShipyard"]; if ([determinant isKindOfClass:[NSArray class]]) { diff --git a/src/Core/TextureStore.m b/src/Core/TextureStore.m index 5674a1fe..68b8fec0 100644 --- a/src/Core/TextureStore.m +++ b/src/Core/TextureStore.m @@ -34,6 +34,8 @@ MA 02110-1301, USA. #import "OOTextureScaling.h" #import "OOStringParsing.h" +#define kOOLogUnconvertedNSLog @"unclassified.TextureStore" + static NSString * const kOOLogPlanetTextureGen = @"texture.planet.generate"; static NSString * const kOOLogShaderInitSuccess = @"rendering.opengl.shader.init.success"; @@ -58,7 +60,6 @@ GLuint max_texture_dimension = 512; // conservative start glGetIntegerv( GL_MAX_TEXTURE_SIZE, &result); max_texture_dimension = result; done_maxsize_test = YES; - // NSLog(@"TESTING: GL_MAX_TEXTURE_SIZE = %d", max_texture_dimension); return max_texture_dimension; } @@ -122,8 +123,6 @@ GLuint max_texture_dimension = 512; // conservative start #ifndef GNUSTEP NSArray* reps = [texImage representations]; -// NSLog(@"DEBUG texture %@ representations:\n%@", filename, reps); - int i; for (i = 0; ((i < [reps count]) && !bitmapImageRep); i++) { @@ -177,7 +176,6 @@ GLuint max_texture_dimension = 512; // conservative start if (([filename hasPrefix:@"blur"])&&(texture_w == image_w)&&(texture_h == image_h)) { -// NSLog(@"DEBUG filling image data for %@ (%d x %d) with special sauce!", filename, texture_w, texture_h); fillSquareImageDataWithBlur(imageBuffer, texture_w, n_planes); } @@ -364,7 +362,7 @@ GLuint max_texture_dimension = 512; // conservative start GLhandleARB shader_object = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB); // a fragment shader if (!shader_object) { - NSLog(kOOLogShaderInitFailed, @"GLSL ERROR: could not create a fragment shader with glCreateShaderObjectARB()"); + OOLog(kOOLogShaderInitFailed, @"GLSL ERROR: could not create a fragment shader with glCreateShaderObjectARB()"); OK = NO; } @@ -385,7 +383,7 @@ GLuint max_texture_dimension = 512; // conservative start char log[1024]; GLsizei log_length; glGetInfoLogARB( shader_object, 1024, &log_length, log); - NSLog(kOOLogShaderInitFailed, @"GLSL ERROR: shader code would not compile:\n%s\n\n%@\n\n", log, fragmentSource); + OOLog(kOOLogShaderInitFailed, @"GLSL ERROR: shader code would not compile:\n%s\n\n%@\n\n", log, fragmentSource); OK = NO; } fragment_shader_object = shader_object; @@ -398,7 +396,7 @@ GLuint max_texture_dimension = 512; // conservative start GLhandleARB shader_object = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB); // a vertex shader if (!shader_object) { - NSLog(kOOLogShaderInitFailed, @"GLSL ERROR: could not create a fragment shader with glCreateShaderObjectARB()"); + OOLog(kOOLogShaderInitFailed, @"GLSL ERROR: could not create a fragment shader with glCreateShaderObjectARB()"); OK = NO; } @@ -644,7 +642,6 @@ void fillSquareImageDataWithBlur(unsigned char * imageBuffer, int width, int npl if ((i_error > 1.0)&&(i < 255)) { -// NSLog(@"DEBUG err correct"); i_error -= 1.0; i++; } diff --git a/src/Core/Universe.h b/src/Core/Universe.h index 699f874c..3ad9ee7f 100644 --- a/src/Core/Universe.h +++ b/src/Core/Universe.h @@ -234,7 +234,6 @@ extern int debug; StationEntity* cachedStation; PlanetEntity* cachedPlanet; PlanetEntity* cachedSun; - Entity* cachedEntityZero; BOOL strict; @@ -324,10 +323,10 @@ extern int debug; - (BOOL) breakPatternHide; - (id) recycleOrDiscard:(Entity *) entity; -- (Entity *) recycledOrNew:(NSString *) classname; +- (Entity *) allocRecycledOrNewEntity:(NSString *) classname; -- (ShipEntity *) getShipWithRole:(NSString *) desc; -- (ShipEntity *) getShip:(NSString *) desc; +- (ShipEntity *) newShipWithRole:(NSString *) desc; +- (ShipEntity *) newShipWithName:(NSString *) desc; - (NSDictionary *) getDictionaryForShip:(NSString *) desc; - (int) maxCargoForShip:(NSString *) desc; @@ -357,7 +356,6 @@ extern int debug; - (void) drawCrosshairs; - (void) drawMessage; -- (id)entityZero; - (id)entityForUniversalID:(int)u_id; BOOL maintainLinkedLists(Universe* uni); @@ -435,7 +433,6 @@ BOOL maintainLinkedLists(Universe* uni); - (NSString *) generateSystemInhabitants:(Random_Seed) s_seed plural:(BOOL)plural; - (Random_Seed) findSystemAtCoords:(NSPoint) coords withGalaxySeed:(Random_Seed) gal_seed; -+ (NSString*) systemSeedString:(Random_Seed) s; - (NSArray*) nearbyDestinationsWithinRange:(double) range; - (Random_Seed) findNeighbouringSystemToCoords:(NSPoint) coords withGalaxySeed:(Random_Seed) gal_seed; - (Random_Seed) findConnectedSystemAtCoords:(NSPoint) coords withGalaxySeed:(Random_Seed) gal_seed; @@ -471,11 +468,6 @@ double estimatedTimeForJourney(double distance, int hops); - (NSString*) equipmentKeyForWeapon:(int) weapon; - (NSString*) brochureDescriptionWithDictionary:(NSDictionary*) dict standardEquipment:(NSArray*) extras optionalEquipment:(NSArray*) options; -- (NSString *) generateSystemDescription:(Random_Seed) s_seed; -- (NSString *) expandDescription:(NSString *) desc forSystem:(Random_Seed)s_seed; -- (NSString *) expandDescriptionWithLocals:(NSString *) desc forSystem:(Random_Seed)s_seed withLocalVariables:(NSDictionary *)locals; -- (NSString *) getRandomDigrams; - - (Vector) getWitchspaceExitPosition; - (Quaternion) getWitchspaceExitRotation; diff --git a/src/Core/Universe.m b/src/Core/Universe.m index 5d61bef9..23c5f40a 100644 --- a/src/Core/Universe.m +++ b/src/Core/Universe.m @@ -52,6 +52,8 @@ MA 02110-1301, USA. #import "ParticleEntity.h" #import "OOStringParsing.h" +#define kOOLogUnconvertedNSLog @"unclassified.Universe" + #define MAX_NUMBER_OF_ENTITIES 200 #define MAX_NUMBER_OF_SOLAR_SYSTEM_ENTITIES 20 @@ -103,7 +105,6 @@ static Universe *sSharedUniverse = nil; // universe_lock = [[NSLock alloc] init]; // alloc retains // init the Resource Manager -// NSLog(@"DEBUG Universe initialising ResourceManager..."); [ResourceManager pathsUsingAddOns:YES]; reducedDetail = NO; @@ -194,7 +195,6 @@ static Universe *sSharedUniverse = nil; cachedSun = nil; cachedPlanet = nil; cachedStation = nil; - cachedEntityZero = nil; station = NO_TARGET; planet = NO_TARGET; @@ -238,9 +238,6 @@ static Universe *sSharedUniverse = nil; [self setViewDirection:VIEW_GUI_DISPLAY]; - - //NSLog(@"UNIVERSE INIT station %d, planet %d, sun %d",station,planet,sun); - demo_ship = nil; universeRegion = [[CollisionRegion alloc] initAsUniverse]; // retained @@ -326,7 +323,7 @@ static Universe *sSharedUniverse = nil; - (void) reinit { - PlayerEntity* player = [[self entityZero] retain]; + PlayerEntity* player = [[PlayerEntity sharedPlayer] retain]; Quaternion q0 = kIdentityQuaternion; int i; @@ -442,7 +439,6 @@ static Universe *sSharedUniverse = nil; cachedSun = nil; cachedPlanet = nil; cachedStation = nil; - cachedEntityZero = nil; station = NO_TARGET; planet = NO_TARGET; @@ -458,10 +454,6 @@ static Universe *sSharedUniverse = nil; system_seed = [self findSystemAtCoords:[player galaxy_coordinates] withGalaxySeed:galaxy_seed]; -// NSLog(@"Galaxy coords are (%f, %f)", [player galaxy_coordinates].x, [player galaxy_coordinates].y); - -// NSLog(@"Well whaddayaknow - we're at %@", [self getSystemName:system_seed]); - if (activeWormholes) [activeWormholes autorelease]; activeWormholes = [[NSMutableArray arrayWithCapacity:16] retain]; @@ -516,7 +508,7 @@ static Universe *sSharedUniverse = nil; - (void) sleepytime: (id) thing { // deal with the machine going to sleep - PlayerEntity *player = [self entityZero]; + PlayerEntity *player = [PlayerEntity sharedPlayer]; if ((player)&&(player->status == STATUS_IN_FLIGHT)) { [self displayMessage:@" Paused (press 'p') " forCount:1.0]; @@ -530,7 +522,7 @@ static Universe *sSharedUniverse = nil; { // we're in witchspace or this is the first launch... // save the player - PlayerEntity* player = [self entityZero]; + PlayerEntity* player = [PlayerEntity sharedPlayer]; // save the docked craft Entity* docked_station = [player docked_station]; // jump to the nearest system @@ -592,7 +584,7 @@ static Universe *sSharedUniverse = nil; } else { - player = [[self entityZero] retain]; // retained here + player = [[PlayerEntity sharedPlayer] retain]; // retained here } @@ -630,7 +622,7 @@ static Universe *sSharedUniverse = nil; } else { - player = [[self entityZero] retain]; // retained here + player = [[PlayerEntity sharedPlayer] retain]; // retained here } @@ -652,7 +644,7 @@ static Universe *sSharedUniverse = nil; // new system is hyper-centric : witchspace exit point is origin Entity *thing; - PlayerEntity* player = [self entityZero]; + PlayerEntity* player = [PlayerEntity sharedPlayer]; Quaternion randomQ; NSMutableDictionary* systeminfo = [NSMutableDictionary dictionaryWithCapacity:4]; @@ -663,8 +655,6 @@ static Universe *sSharedUniverse = nil; Random_Seed s2 = player->target_system_seed; NSString* override_key = [self keyForInterstellarOverridesForSystemSeeds:s1 :s2 inGalaxySeed:galaxy_seed]; -// NSLog(@"DEBUG checking interstellar overrides for key '%@'", override_key); - // check at this point // for scripted overrides for this insterstellar area if ([planetinfo objectForKey:PLANETINFO_UNIVERSAL_KEY]) @@ -673,9 +663,6 @@ static Universe *sSharedUniverse = nil; [systeminfo addEntriesFromDictionary:(NSDictionary *)[planetinfo objectForKey:override_key]]; if ([local_planetinfo_overrides objectForKey:override_key]) [systeminfo addEntriesFromDictionary:(NSDictionary *)[local_planetinfo_overrides objectForKey:override_key]]; - -// NSLog(@"DEBUGsysteminfo now:\n%@", systeminfo); - } [universeRegion clearSubregions]; @@ -735,7 +722,7 @@ static Universe *sSharedUniverse = nil; for (i = 0; i < n_thargs; i++) { Quaternion tharg_quaternion; - ShipEntity *thargoid = [self getShipWithRole:@"thargoid"]; // is retained + ShipEntity *thargoid = [self newShipWithRole:@"thargoid"]; // is retained if (thargoid) { Vector tharg_pos = tharg_start_pos; @@ -800,11 +787,7 @@ static Universe *sSharedUniverse = nil; [universeRegion clearSubregions]; -// NSLog(@"DEBUG systeminfo =\n%@", [systeminfo description]); - - // fixed entities (part of the graphics system really) come first... - [self setSky_clear_color:0.0 :0.0 :0.0 :0.0]; // set the system seed for random number generation @@ -933,7 +916,7 @@ static Universe *sSharedUniverse = nil; stationPos.x -= station_orbit * vf.x; // back away from the planet stationPos.y -= station_orbit * vf.y; stationPos.z -= station_orbit * vf.z; - //NSLog(@"Station added at vector (%.1f,%.1f,%.1f) from planet",-vf.x,-vf.y,-vf.z); + stationDesc = @"coriolis"; if (techlevel > 10) { @@ -948,8 +931,7 @@ static Universe *sSharedUniverse = nil; if ([systeminfo objectForKey:@"station"]) stationDesc = (NSString *)[systeminfo objectForKey:@"station"]; - //NSLog(@"* INFO *\t>>\tAdding %@ station for TL %d", stationDesc, techlevel); - a_station = (StationEntity *)[self getShipWithRole:stationDesc]; // retain count = 1 + a_station = (StationEntity *)[self newShipWithRole:stationDesc]; // retain count = 1 if (a_station) { [a_station setStatus:STATUS_ACTIVE]; @@ -974,7 +956,7 @@ static Universe *sSharedUniverse = nil; [self populateSpaceFromHyperPoint:[self getWitchspaceExitPosition] toPlanetPosition: a_planet->position andSunPosition: a_sun->position]; /*- nav beacon -*/ - nav_buoy = [self getShipWithRole:@"buoy"]; // retain count = 1 + nav_buoy = [self newShipWithRole:@"buoy"]; // retain count = 1 if (nav_buoy) { [nav_buoy setRoll: 0.10]; // zero for debugging @@ -989,7 +971,7 @@ static Universe *sSharedUniverse = nil; /*- nav beacon witchpoint -*/ Vector witchpoint = [self getWitchspaceExitPosition]; // witchpoint - nav_buoy = [self getShipWithRole:@"buoy-witchpoint"]; // retain count = 1 + nav_buoy = [self newShipWithRole:@"buoy-witchpoint"]; // retain count = 1 if (nav_buoy) { [nav_buoy setRoll: 0.10]; @@ -1043,7 +1025,7 @@ static Universe *sSharedUniverse = nil; if ([systeminfo objectForKey:KEY_SCRIPT_ACTIONS]) { - PlayerEntity* player = [self entityZero]; + PlayerEntity* player = [PlayerEntity sharedPlayer]; NSArray* script_actions = [systeminfo objectForKey:KEY_SCRIPT_ACTIONS]; [player scriptActions: script_actions forTarget: nil]; @@ -1143,17 +1125,12 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, - (void) populateSpaceFromActiveWormholes { -// NSLog(@"DEBUG populating from activeWormholes:\n%@", activeWormholes); - while ([activeWormholes count]) { WormholeEntity* whole = (WormholeEntity*)[activeWormholes objectAtIndex:0]; [whole setUniverse: self]; -// NSLog(@"DEBUG considering wormhole %@ destination %@ (system %@)", -// whole, [Universe systemSeedString:[whole destination]], [Universe systemSeedString:system_seed]); - if (equal_seeds( [whole destination], system_seed)) { // this is a wormhole to this system @@ -1271,7 +1248,7 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, launch_pos.x += ship_location * v_route1.x + SCANNER_MAX_RANGE*((ranrot_rand() & 255)/256.0 - 0.5); launch_pos.y += ship_location * v_route1.y + SCANNER_MAX_RANGE*((ranrot_rand() & 255)/256.0 - 0.5); launch_pos.z += ship_location * v_route1.z + SCANNER_MAX_RANGE*((ranrot_rand() & 255)/256.0 - 0.5); - trader_ship = [self getShipWithRole:@"trader"]; // retain count = 1 + trader_ship = [self newShipWithRole:@"trader"]; // retain count = 1 if (trader_ship) { if (![trader_ship crew]) @@ -1327,16 +1304,17 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, lastPiratePosition = launch_pos; wolfPackCounter = 0; } - pirate_ship = [self getShipWithRole:@"pirate"]; // retain count = 1 + pirate_ship = [self newShipWithRole:@"pirate"]; // retain count = 1 if (pirate_ship) { if (![pirate_ship crew]) + { [pirate_ship setCrew:[NSArray arrayWithObject: [OOCharacter randomCharacterWithRole:@"pirate" andOriginalSystem: (randf() > 0.25)? systems[ranrot_rand() & 255]:system_seed inUniverse: self]]]; -// NSLog(@">>>>> %@", [pirate_ship crew]); - + } + if (pirate_ship->scan_class == CLASS_NOT_SET) [pirate_ship setScanClass: CLASS_NEUTRAL]; [pirate_ship setPosition:launch_pos]; @@ -1344,8 +1322,6 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, [pirate_ship setBounty: 20 + government + wolfPackCounter + (ranrot_rand() & 7)]; [pirate_ship setCargoFlag: CARGO_FLAG_PIRATE]; - //[pirate_ship setReportAImessages: (i == 0) ? YES:NO ]; // debug - [self addEntity:pirate_ship]; if (wolfPackCounter == 0) // first ship @@ -1377,9 +1353,9 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, if ((ranrot_rand() & 7) < government) { if ((ranrot_rand() & 7) + 6 <= techlevel) - hunter_ship = [self getShipWithRole:@"interceptor"]; // retain count = 1 + hunter_ship = [self newShipWithRole:@"interceptor"]; // retain count = 1 else - hunter_ship = [self getShipWithRole:@"police"]; // retain count = 1 + hunter_ship = [self newShipWithRole:@"police"]; // retain count = 1 if (hunter_ship) { if (![hunter_ship crew]) @@ -1400,7 +1376,7 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, } else { - hunter_ship = [self getShipWithRole:@"hunter"]; // retain count = 1 + hunter_ship = [self newShipWithRole:@"hunter"]; // retain count = 1 if ((hunter_ship)&&(hunter_ship->scan_class == CLASS_NOT_SET)) [hunter_ship setScanClass: CLASS_NEUTRAL]; if (![hunter_ship crew]) @@ -1418,13 +1394,9 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, [hunter_ship setStatus:STATUS_IN_FLIGHT]; [hunter_ship setBounty:0]; - //[hunter_ship setReportAImessages: (i == 0) ? YES:NO ]; // debug - [self addEntity:hunter_ship]; [[hunter_ship getAI] setStateMachine:@"route1patrolAI.plist"]; // must happen after adding to the universe! - //NSLog(@"DEBUG hunter ship %@ %@ %d has %d escorts", [hunter_ship roles], [hunter_ship name], [hunter_ship universal_id], escorts_added); - [hunter_ship release]; } } @@ -1440,7 +1412,7 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, launch_pos.x = h1_pos.x + thargoid_location * v_route1.x + SCANNER_MAX_RANGE*((ranrot_rand() & 255)/256.0 - 0.5); launch_pos.y = h1_pos.y + thargoid_location * v_route1.y + SCANNER_MAX_RANGE*((ranrot_rand() & 255)/256.0 - 0.5); launch_pos.z = h1_pos.z + thargoid_location * v_route1.z + SCANNER_MAX_RANGE*((ranrot_rand() & 255)/256.0 - 0.5); - thargoid_ship = [self getShipWithRole:@"thargoid"]; // retain count = 1 + thargoid_ship = [self newShipWithRole:@"thargoid"]; // retain count = 1 if (thargoid_ship) { if (thargoid_ship->scan_class == CLASS_NOT_SET) @@ -1494,16 +1466,11 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, double end = 3.0 * [[self sun] getRadius]; double max_length = d_route2 - (start + end); double ship_location = randf() * max_length + start; - -// NSLog(@"Planet: %@ \tSun: %@", [self planet], [self sun]); -// NSLog(@"Planet collision radius: %.0fm \tSun collision radius: %.0fm \tRoute2 length: %.0fm", [[self planet] getRadius], [[self sun] getRadius], d_route2); -// NSLog(@"start: %.0fm \tend: %.0fm", start, end); -// NSLog(@"max length: %.0fm \tLocation is: %.0fm", max_length, ship_location); // launch_pos.x += ship_location * v_route2.x + SCANNER_MAX_RANGE*((ranrot_rand() & 255)/256.0 - 0.5); launch_pos.y += ship_location * v_route2.y + SCANNER_MAX_RANGE*((ranrot_rand() & 255)/256.0 - 0.5); launch_pos.z += ship_location * v_route2.z + SCANNER_MAX_RANGE*((ranrot_rand() & 255)/256.0 - 0.5); - trader_ship = [self getShipWithRole:@"sunskim-trader"]; // retain count = 1 + trader_ship = [self newShipWithRole:@"sunskim-trader"]; // retain count = 1 if (trader_ship) { if (![trader_ship crew]) @@ -1562,7 +1529,7 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, lastPiratePosition = launch_pos; wolfPackCounter = 0; } - pirate_ship = [self getShipWithRole:@"pirate"]; // retain count = 1 + pirate_ship = [self newShipWithRole:@"pirate"]; // retain count = 1 if (pirate_ship) { if (![pirate_ship crew]) @@ -1570,7 +1537,6 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, [OOCharacter randomCharacterWithRole:@"pirate" andOriginalSystem: (randf() > 0.25)? systems[ranrot_rand() & 255]:system_seed inUniverse: self]]]; -// NSLog(@">>>>> %@", [pirate_ship crew]); if (pirate_ship->scan_class == CLASS_NOT_SET) [pirate_ship setScanClass: CLASS_NEUTRAL]; @@ -1578,8 +1544,6 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, [pirate_ship setStatus: STATUS_IN_FLIGHT]; [pirate_ship setBounty: 20 + government + wolfPackCounter + (ranrot_rand() % 7)]; [pirate_ship setCargoFlag: CARGO_FLAG_PIRATE]; - - // [pirate_ship setReportAImessages: (i == 0) ? YES:NO ]; // debug [self addEntity:pirate_ship]; @@ -1612,9 +1576,9 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, if ((ranrot_rand() & 7) < government) { if ((ranrot_rand() & 7) + 6 <= techlevel) - hunter_ship = [self getShipWithRole:@"interceptor"]; // retain count = 1 + hunter_ship = [self newShipWithRole:@"interceptor"]; // retain count = 1 else - hunter_ship = [self getShipWithRole:@"police"]; // retain count = 1 + hunter_ship = [self newShipWithRole:@"police"]; // retain count = 1 if (hunter_ship) { if (![hunter_ship crew]) @@ -1635,7 +1599,7 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, } else { - hunter_ship = [self getShipWithRole:@"hunter"]; // retain count = 1 + hunter_ship = [self newShipWithRole:@"hunter"]; // retain count = 1 if ((hunter_ship)&&(hunter_ship->scan_class == CLASS_NOT_SET)) [hunter_ship setScanClass: CLASS_NEUTRAL]; if (![hunter_ship crew]) @@ -1699,7 +1663,7 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, launch_pos.x = spawnPos.x + SCANNER_MAX_RANGE * (randf() - randf()); launch_pos.y = spawnPos.y + SCANNER_MAX_RANGE * (randf() - randf()); launch_pos.z = spawnPos.z + SCANNER_MAX_RANGE * (randf() - randf()); - asteroid = [self getShipWithRole:@"asteroid"]; // retain count = 1 + asteroid = [self newShipWithRole:@"asteroid"]; // retain count = 1 if (asteroid) { if (asteroid->scan_class == CLASS_NOT_SET) @@ -1722,13 +1686,11 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, if (spawnHermit) { - //debug - //NSLog(@"DEBUG ... adding rock-hermit"); StationEntity* hermit; launch_pos.x = spawnPos.x + 0.5 * SCANNER_MAX_RANGE * (randf() - randf()); launch_pos.y = spawnPos.y + 0.5 * SCANNER_MAX_RANGE * (randf() - randf()); launch_pos.z = spawnPos.z + 0.5 * SCANNER_MAX_RANGE * (randf() - randf()); - hermit = (StationEntity *)[self getShipWithRole:@"rockhermit"]; // retain count = 1 + hermit = (StationEntity *)[self newShipWithRole:@"rockhermit"]; // retain count = 1 if (hermit) { if (hermit->scan_class == CLASS_NOT_SET) @@ -1743,12 +1705,6 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, } } -// // hint to the collision detection system -// if (cluster_size > 3) -// { -// [universeRegion addSubregionAtPosition: spawnPos withRadius: SCANNER_MAX_RANGE * 1.5f ]; // 50% fudge on size -// } - return rocks; } @@ -1770,7 +1726,7 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, launch_pos.z += SCANNER_MAX_RANGE*(randf() - randf()); ShipEntity *ship; - ship = [self getShipWithRole:desc]; // retain count = 1 + ship = [self newShipWithRole:desc]; // retain count = 1 if (ship) { if (![ship crew]) @@ -1787,9 +1743,6 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, [ship setStatus:STATUS_IN_FLIGHT]; // or ships that were 'demo' ships become invisible! - // NSLog(@"DEBUG added %@ %@ %d to universe at (%.0f,%.0f,%.0f)", ship, [ship name], [ship universal_id], - // ship->position.x, ship->position.y, ship->position.z); - [ship release]; } @@ -1837,7 +1790,6 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, PlanetEntity* the_sun = [self sun]; if ((!the_planet)||(!the_sun)) { -// NSLog(@"NO ERROR - Universe coordinatesForPosition:withCoordinateSystem: in system with no sun or planet returned as an absolute position"); if (my_scalar) *my_scalar = 1.0; return pos; @@ -1851,8 +1803,6 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, Vector p1 = make_vector(0,1,0); Vector p2 = make_vector(0,0,1); -// NSLog(@"DEBUG addShipAt (system %s)", c_sys); - switch (c_sys[0]) { case 'w': @@ -1942,7 +1892,6 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, PlanetEntity* the_sun = [self sun]; if ((!the_planet)||(!the_sun)) { -// NSLog(@"NO ERROR - Universe coordinatesForPosition:withCoordinateSystem: in system with no sun or planet returned as an absolute position"); return [NSString stringWithFormat:@"%@ %.2f %.2f %.2f", system, pos.x, pos.y, pos.z]; } Vector w_pos = [self getWitchspaceExitPosition]; @@ -2059,11 +2008,8 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, launch_pos.y += rfactor*(randf() - randf()); launch_pos.z += rfactor*(randf() - randf()); -// NSLog(@"DEBUG POSITION SET (%.1f, %.1f, %.1f)", launch_pos.x, launch_pos.y, launch_pos.z); - - ShipEntity *ship; - ship = [self getShipWithRole:desc]; // retain count = 1 + ship = [self newShipWithRole:desc]; // retain count = 1 if (ship) { if (![ship crew]) @@ -2100,7 +2046,7 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, while (i < howMany) { ShipEntity *ship; - ship = [self getShipWithRole:desc]; // retain count = 1 + ship = [self newShipWithRole:desc]; // retain count = 1 if (!ship) return NO; if (![ship crew]) @@ -2140,11 +2086,9 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, } if (!safe) { -// NSLog(@"DEBUG - AddShips %d/%d : proposed position clashed with ship %d", i, howMany, j + 1); limit_count--; if (!limit_count) // give up and expand the shell { -// NSLog(@"DEBUG - limit_count depleted, expanding area..."); limit_count = 8; distance_from_center += sqrt(safe_distance2); // expand to the next distance } @@ -2166,9 +2110,6 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, [ship setStatus:STATUS_IN_FLIGHT]; // or ships that were 'demo' ships become invisible! [ship release]; -// NSLog(@"DEBUG - AddShips %d/%d : ship added successfully %.1fm from the requested position", -// i, howMany, distance_from_center); - ship_positions[i] = ship_pos; i++; if (i > scale_up_after) @@ -2176,9 +2117,6 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, current_shell = i; scale_up_after += 1 + 2 * i; distance_from_center += sqrt(safe_distance2); // fill the next shell - -// NSLog(@"DEBUG - AddShips %d/%d : Filling a shell of radius %.2fm from the requested position with the next %d ships", -// i, howMany, distance_from_center, 1 + scale_up_after - i); } } return YES; @@ -2261,7 +2199,7 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, ShipEntity *ship; - ship = [self getShipWithRole:desc]; // retain count = 1 + ship = [self newShipWithRole:desc]; // retain count = 1 if (ship) { if (![ship crew]) @@ -2293,7 +2231,7 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, NS_HANDLER if ([[localException name] isEqual: OOLITE_EXCEPTION_SHIP_NOT_FOUND]) { - NSLog(@"***** Oolite Exception : '%@' in [Universe spawnShip: %@ ] *****", [localException reason], shipdesc); + OOLog(kOOLogException, @"***** Oolite Exception : '%@' in [Universe spawnShip: %@ ] *****", [localException reason], shipdesc); shipdict = nil; } else @@ -2303,7 +2241,7 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, if (!shipdict) return NO; - ship = [self getShip:shipdesc]; // retain count is 1 + ship = [self newShipWithName:shipdesc]; // retain count is 1 if (!ship) return NO; @@ -2369,7 +2307,7 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, { // adds a ship exiting witchspace (corollary of when ships leave the system) ShipEntity *ship; - ship = [self getShipWithRole:desc]; // retain count = 1 + ship = [self newShipWithRole:desc]; // retain count = 1 if (ship) { if ((ship->scan_class == CLASS_NO_DRAW)||(ship->scan_class == CLASS_NOT_SET)) @@ -2413,7 +2351,7 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, Vector vf = vector_forward_from_quaternion(spawn_q); GLfloat offset = (randf() + randf()) * entity->collision_radius; spawn_pos.x += offset * vf.x; spawn_pos.y += offset * vf.y; spawn_pos.z += offset * vf.z; - ship = [self getShipWithRole:desc]; // retain count = 1 + ship = [self newShipWithRole:desc]; // retain count = 1 if (ship) { if (![ship crew]) @@ -2446,7 +2384,7 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, for (i = 1; i < 11; i++) { - ring = (RingEntity *)[self recycledOrNew:@"RingEntity"]; + ring = (RingEntity *)[self allocRecycledOrNewEntity:@"RingEntity"]; [ring setPosition:pos.x+v.x*i*50.0:pos.y+v.y*i*50.0:pos.z+v.z*i*50.0]; // ahead of the player [ring setQRotation:q]; [ring setVelocity:v]; @@ -2460,7 +2398,7 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, - (void) game_over { - PlayerEntity* player = [[self entityZero] retain]; + PlayerEntity* player = [[PlayerEntity sharedPlayer] retain]; [self removeAllEntitiesExceptPlayer:NO]; // don't want to restore afterwards @@ -2490,7 +2428,7 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, - (void) set_up_intro1 { - PlayerEntity* player = [self entityZero]; + PlayerEntity* player = [PlayerEntity sharedPlayer]; ShipEntity *ship; Quaternion q2; q2.x = 0.0; q2.y = 0.0; q2.z = 0.0; q2.w = 1.0; @@ -2503,16 +2441,13 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, displayGUI = YES; /*- cobra -*/ - ship = [self getShip:PLAYER_SHIP_DESC]; // retain count = 1 // shows the cobra-player ship + ship = [self newShipWithName:PLAYER_SHIP_DESC]; // retain count = 1 // shows the cobra-player ship if (ship) { [ship setStatus: STATUS_COCKPIT_DISPLAY]; [ship setQRotation:q2]; -// [ship setPosition: p0.x : p0.y : p0.z + 3.6 * ship->actual_radius]; // 250m ahead [ship setPosition: 0.0f : 0.0f :3.6f * ship->actual_radius]; // some way ahead - //NSLog(@"demo ship %@ has collision radius %.1f 250.0/cr = %.1f", [ship name], ship->collision_radius, 250.0/ship->collision_radius); - [ship setScanClass: CLASS_NO_DRAW]; [ship setRoll:PI/5.0]; [ship setPitch:PI/10.0]; @@ -2540,21 +2475,19 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, // in status demo draw ships and display text [self removeDemoShips]; - [[self entityZero] setStatus: STATUS_START_GAME]; - [[self entityZero] setShowDemoShips: YES]; + [[PlayerEntity sharedPlayer] setStatus: STATUS_START_GAME]; + [[PlayerEntity sharedPlayer] setShowDemoShips: YES]; displayGUI = YES; /*- demo ships -*/ demo_ship_index = 0; - ship = [self getShip:[demo_ships objectAtIndex:0]]; // retain count = 1 + ship = [self newShipWithName:[demo_ships objectAtIndex:0]]; // retain count = 1 if (ship) { [ship setQRotation:q2]; [ship setPosition: 0.0f : 0.0f : 3.6f * ship->actual_radius]; [ship setDestination: ship->position]; // ideal position - //NSLog(@"demo ship %@ has collision radius %.1f 250.0/cr = %.1f", [ship name], ship->collision_radius, 250.0/ship->collision_radius); - [ship setScanClass: CLASS_NO_DRAW]; [ship setRoll:PI/5.0]; [ship setPitch:PI/10.0]; @@ -2749,7 +2682,7 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, - (BOOL) breakPatternHide { - Entity* player = [self entityZero]; + Entity* player = [PlayerEntity sharedPlayer]; return ((breakPatternCounter > 5)||(!player)||(player->status == STATUS_DOCKING)); } @@ -2770,8 +2703,6 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, if (entity->isStation) classname = @"StationEntity"; -// NSLog(@"Considering a used %@ with retainCount:%d for recycling",classname,[entity retainCount]); - if (classname) { if (entity->status == STATUS_IN_HOLD) @@ -2804,7 +2735,7 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, return entity; // pass through } -- (Entity *) recycledOrNew:(NSString *) classname +- (Entity *) allocRecycledOrNewEntity:(NSString *) classname { Entity *entity = nil; NSMutableArray *entlist; @@ -2816,10 +2747,8 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, entlist = (NSMutableArray *)[entityRecyclePool objectForKey:classname]; if ([entlist count] > 0) { -// NSLog(@"Recycling a used %@ from %@",classname,[entlist description]); entity = [[entlist objectAtIndex:0] retain]; [entlist removeObjectAtIndex:0]; -// NSLog(@"Recycling a used %@",classname); } [recycleLock unlock]; } @@ -2829,12 +2758,11 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, Class required_class = [[NSBundle mainBundle] classNamed:classname]; entity = [[required_class alloc] init]; [entity setUniverse:self]; // ensures access to preloaded data -// NSLog(@"Generating a new %@",classname); } return entity; } -- (ShipEntity *) getShipWithRole:(NSString *) desc +- (ShipEntity *) newShipWithRole:(NSString *) desc { int i, j, found; ShipEntity *ship = nil; @@ -2857,7 +2785,7 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, if ([shipDict objectForKey:@"conditions"]) { - PlayerEntity* player = [self entityZero]; + PlayerEntity* player = [PlayerEntity sharedPlayer]; if ((player) && (player->isPlayer) && (![player checkCouplet: shipDict onEntity: player])) shipRoles = [NSArray array]; // empty array - ship does not meet conditions listed } @@ -2895,11 +2823,6 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, if (found > 1) { - -// NSLog(@"... candidates are: %d (%.3f) %@", found, foundf, [foundShips searchription]); - -// NSLog(@"... selection is: %.3f", selectedf * foundf); - selectedf *= foundf; while (selectedf > [[foundChance objectAtIndex:i] floatValue]) { @@ -2909,18 +2832,17 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, if (i >= found) // sanity check i = 0; -// NSLog(@"... we chose %@",(NSString *)[foundShips objectAtIndex:i]); } if (found) { - ship = [self getShip:(NSString *)[foundShips objectAtIndex:i]]; // may return nil if not found! + ship = [self newShipWithName:(NSString *)[foundShips objectAtIndex:i]]; // may return nil if not found! [ship setRoles:search]; // set its roles to this one particular chosen role } else if (debug) { - NSLog(@"DEBUG [Universe getShipWithRole: %@] couldn't find a ship!", search); + NSLog(@"DEBUG [Universe newShipWithRole: %@] couldn't find a ship!", search); } [mypool release]; // tidy everything up @@ -2935,7 +2857,7 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, } -- (ShipEntity *) getShip:(NSString *) desc +- (ShipEntity *) newShipWithName:(NSString *) desc { NSDictionary *shipDict = nil; ShipEntity *ship = nil; @@ -2945,7 +2867,7 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, NS_HANDLER if ([[localException name] isEqual: OOLITE_EXCEPTION_SHIP_NOT_FOUND]) { - NSLog(@"***** Oolite Exception : '%@' in [Universe getShip: %@ ] *****", [localException reason], desc); + OOLog(kOOLogException, @"***** Oolite Exception : '%@' in [Universe newShipWithName: %@ ] *****", [localException reason], desc); shipDict = nil; } else @@ -2963,9 +2885,9 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, isStation = [[shipDict objectForKey:@"isCarrier"] boolValue]; if (isStation) - ship = (StationEntity *)[self recycledOrNew:@"StationEntity"]; // is returned retained + ship = (StationEntity *)[self allocRecycledOrNewEntity:@"StationEntity"]; // is returned retained else - ship = (ShipEntity *)[self recycledOrNew:@"ShipEntity"]; // is returned retained + ship = (ShipEntity *)[self allocRecycledOrNewEntity:@"ShipEntity"]; // is returned retained [ship setUniverse:self]; NS_DURING @@ -2973,7 +2895,7 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, NS_HANDLER if ([[localException name] isEqual: OOLITE_EXCEPTION_DATA_NOT_FOUND]||[[localException name] isEqual: OOLITE_EXCEPTION_SHIP_NOT_FOUND]) { - NSLog(@"***** Oolite Exception : '%@' in [Universe getShip: %@ ] *****", [localException reason], desc); + OOLog(kOOLogException, @"***** Oolite Exception : '%@' in [Universe newShipWithName: %@ ] *****", [localException reason], desc); [self recycleOrDiscard: ship]; ship = nil; } @@ -3010,7 +2932,7 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, NS_HANDLER if ([[localException name] isEqual: OOLITE_EXCEPTION_SHIP_NOT_FOUND]) { - NSLog(@"***** Oolite Exception : '%@' in [Universe getDictionaryForShip:] while basing a ship upon '%@' *****", [localException reason], other_shipdesc); + OOLog(kOOLogException, @"***** Oolite Exception : '%@' in [Universe getDictionaryForShip:] while basing a ship upon '%@' *****", [localException reason], other_shipdesc); other_shipdict = nil; } else @@ -3100,7 +3022,7 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, // quantities is now used to determine which good get into the containers for (i = 0; i < how_many; i++) { - ShipEntity* container = [self getShipWithRole:@"cargopod"]; // retained + ShipEntity* container = [self newShipWithRole:@"cargopod"]; // retained // look for a pre-set filling int co_type = [container getCommodityType]; @@ -3129,7 +3051,7 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, co_amount = [self getRandomAmountOfCommodity:co_type]; - ShipEntity* special_container = [self getShipWithRole: [self nameForCommodity:co_type]]; + ShipEntity* special_container = [self newShipWithRole: [self nameForCommodity:co_type]]; if (special_container) { [container release]; @@ -3137,8 +3059,6 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, } } - //NSLog(@"... loading with plentiful %@",[self describeCommodity:co_type amount:co_amount]); - // into the barrel it goes... if (container) { @@ -3172,7 +3092,7 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, // quantities is now used to determine which good get into the containers for (i = 0; i < how_many; i++) { - ShipEntity* container = [self getShipWithRole:@"cargopod"]; + ShipEntity* container = [self newShipWithRole:@"cargopod"]; // look for a pre-set filling int co_type = [container getCommodityType]; @@ -3192,7 +3112,7 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, co_amount = [self getRandomAmountOfCommodity:co_type]; - ShipEntity* special_container = [self getShipWithRole: [self nameForCommodity:co_type]]; + ShipEntity* special_container = [self newShipWithRole: [self nameForCommodity:co_type]]; if (special_container) { [container release]; @@ -3200,7 +3120,6 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, } } - //NSLog(@"... loading with scarce %@",[self describeCommodity:co_type amount:co_amount]); if (container) { [container setUniverse:self]; @@ -3228,9 +3147,9 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5, int how_much = how_many; while (how_much > 0) { - ShipEntity* container = [self getShipWithRole: commodity_name]; // try the commodity name first + ShipEntity* container = [self newShipWithRole: commodity_name]; // try the commodity name first if (!container) - container = [self getShipWithRole:@"cargopod"]; + container = [self newShipWithRole:@"cargopod"]; int amount = 1; if (commodity_units != 0) amount += ranrot_rand() & (15 * commodity_units); @@ -3365,7 +3284,6 @@ void setSunLight(BOOL yesno) else glDisable(GL_LIGHT1); sun_light_on = yesno; -// NSLog(@"DEBUG ::::: Sunlight switched %@", (yesno)? @"ON":@"off"); } } void setDemoLight(BOOL yesno, Vector position) @@ -3378,14 +3296,12 @@ void setDemoLight(BOOL yesno, Vector position) demo_light_position[1] = position.y; demo_light_position[2] = position.z; glLightfv(GL_LIGHT0, GL_POSITION, demo_light_position); -// NSLog(@"DEBUG ::::: Demo light repositioned at ( %.2f, %.2f, %.2f)", position.x, position.y, position.z); } if (yesno) glEnable(GL_LIGHT0); else glDisable(GL_LIGHT0); demo_light_on = yesno; -// NSLog(@"DEBUG ::::: Demo light switched %@", (yesno)? @"ON":@"off"); } } @@ -3431,8 +3347,6 @@ GLfloat* custom_matrix; my_entities[draw_count++] = [e retain]; // retained } -// NSLog(@"DEBUG drawing %d entities", draw_count); - Entity *viewthing = nil; Entity *drawthing = nil; @@ -3481,8 +3395,6 @@ GLfloat* custom_matrix; /* -- */ } - //NSLog(@"Drawing from [%f,%f,%f]", position.x, position.y, position.z); - checkGLErrors(@"Universe before doing anything"); glEnable(GL_LIGHTING); @@ -3766,7 +3678,7 @@ GLfloat* custom_matrix; [self handleOoliteException:localException]; else { - NSLog(@"\n\n***** Encountered localException: %@ : %@ *****\n\n",[localException name], [localException reason]); + OOLog(kOOLogException, @"***** Exception: %@ : %@ *****",[localException name], [localException reason]); [localException raise]; } @@ -3778,7 +3690,7 @@ GLfloat* custom_matrix; - (void) drawCrosshairs { - PlayerEntity* playerShip = (PlayerEntity *)[self entityZero]; + PlayerEntity* playerShip = [PlayerEntity sharedPlayer]; if (viewDirection == VIEW_CUSTOM) return; // don't try to draw cross hairs in a custom view @@ -3880,17 +3792,11 @@ GLfloat* custom_matrix; } } -- (id)entityZero -{ - if (cachedEntityZero == nil ) cachedEntityZero = [entities objectAtIndex:0]; - return cachedEntityZero; -} - - (id)entityForUniversalID:(int)u_id { if (u_id == 100) - return [self entityZero]; // the player + return [PlayerEntity sharedPlayer]; // the player if ((u_id == NO_TARGET)||(!entity_for_uid[u_id])) return nil; @@ -4130,7 +4036,7 @@ BOOL maintainLinkedLists(Universe* uni) // maintain sorted list (and for the scanner relative position) Vector entity_pos = entity->position; - Vector delta = vector_between(entity_pos, ((PlayerEntity *)[self entityZero])->position); + Vector delta = vector_between(entity_pos, ((PlayerEntity *)[PlayerEntity sharedPlayer])->position); double z_distance = magnitude2(delta); entity->zero_distance = z_distance; entity->relative_position = delta; @@ -4258,8 +4164,6 @@ BOOL maintainLinkedLists(Universe* uni) [entities removeObject:[self recycleOrDiscard:entity]]; - //NSLog(@"--(%@)\n%@", entity, [entities description]); - return YES; } } @@ -4386,7 +4290,6 @@ BOOL maintainLinkedLists(Universe* uni) cachedSun = nil; cachedPlanet = nil; cachedStation = nil; - cachedEntityZero = nil; firstBeacon = NO_TARGET; lastBeacon = NO_TARGET; @@ -4540,7 +4443,6 @@ BOOL maintainLinkedLists(Universe* uni) if (!e1) { NSLog(@"ERROR ***** No entity set in Universe getSafeVectorFromEntity:toDistance:fromPoint:"); - // NSBeep(); // AppKit return make_vector( 0.0f, 0.0f, 0.0f); } Vector f1; @@ -4622,7 +4524,6 @@ BOOL maintainLinkedLists(Universe* uni) double current_distance = sqrt (dd.x*dd.x + dd.y*dd.y + dd.z*dd.z); // sanity check current_distance - //NSLog(@"Current distance is %.1f CR", current_distance/cr); if (current_distance < cr * 1.25) // 25% safety margin current_distance = cr * 1.25; if (current_distance > cr * 5.0) // up to 2 diameters away @@ -4633,8 +4534,6 @@ BOOL maintainLinkedLists(Universe* uni) result.x += 0.25 * (outward.x * current_distance) + 0.75 * (backward.x * current_distance); // push 'out' by this amount result.y += 0.25 * (outward.y * current_distance) + 0.75 * (backward.y * current_distance); result.z += 0.25 * (outward.z * current_distance) + 0.75 * (backward.z * current_distance); - - //NSLog(@"Bypassing %@ by going from (%.1f,%.1f,%.1f) to (%.1f,%.1f,%.1f)",e2,p1.x,p1.y,p1.z,result.x,result.y,result.z); } } @@ -4679,7 +4578,6 @@ BOOL maintainLinkedLists(Universe* uni) nearest = [(ShipEntity *)e1 weapon_range]; else nearest = PARTICLE_LASER_LENGTH; -// NSLog(@"DEBUG LASER nearest = %.1f",nearest); int i; int ent_count = n_entities; @@ -4753,9 +4651,6 @@ BOOL maintainLinkedLists(Universe* uni) if (hit_entity) { -// if (e1->isPlayer) -// NSLog(@"DEBUG HIT %@ %d at %.2fm", hit_entity, [hit_entity universal_id], nearest); - result = [hit_entity universal_id]; if ((hit_subentity)&&[hit_entity->sub_entities containsObject:hit_subentity]) hit_entity->subentity_taking_damage = hit_subentity; @@ -5040,7 +4935,7 @@ BOOL maintainLinkedLists(Universe* uni) #ifdef GNUSTEP [gameView setMouseInDeltaMode: YES]; #endif - ms = [[self entityZero] customViewDescription]; + ms = [[PlayerEntity sharedPlayer] customViewDescription]; displayGUI = NO; // switch off any text displays break; @@ -5057,12 +4952,10 @@ BOOL maintainLinkedLists(Universe* uni) if (ms) [self addMessage:ms forCount:3]; } - //NSLog(@"Universe viewDir : %d %@",viewDirection,ms); } - (int) viewDir { - //NSLog(@"Universe viewDir : %d",viewDirection); return viewDirection; } @@ -5164,7 +5057,7 @@ BOOL maintainLinkedLists(Universe* uni) if (![currentMessage isEqual:text]) { #ifndef GNUSTEP - PlayerEntity* player = (PlayerEntity *)[self entityZero]; + PlayerEntity* player = [PlayerEntity sharedPlayer]; //speech synthesis if ([player speech_on]) { @@ -5182,11 +5075,8 @@ BOOL maintainLinkedLists(Universe* uni) { NSString *original_phrase = (NSString*)[thePair objectAtIndex: 0]; NSString *replacement_phrase = (NSString*)[thePair objectAtIndex: 1]; -// NSLog(@"Will replace %@ with %@", original_phrase, replacement_phrase); spoken_text = [[spoken_text componentsSeparatedByString: original_phrase] componentsJoinedByString: replacement_phrase]; - -// NSLog(@"%@", spoken_text); } spoken_text = [[spoken_text componentsSeparatedByString: systemName] componentsJoinedByString: systemSaid]; spoken_text = [[spoken_text componentsSeparatedByString: h_systemName] componentsJoinedByString: h_systemSaid]; @@ -5212,7 +5102,7 @@ BOOL maintainLinkedLists(Universe* uni) { if (![currentMessage isEqual:text]) { - PlayerEntity* player = (PlayerEntity *)[self entityZero]; + PlayerEntity* player = [PlayerEntity sharedPlayer]; if ([player speech_on]) { @@ -5245,7 +5135,7 @@ BOOL maintainLinkedLists(Universe* uni) NSString* update_stage = @"initialisation"; NS_DURING int i; - PlayerEntity* player = (PlayerEntity *)[self entityZero]; + PlayerEntity* player = [PlayerEntity sharedPlayer]; int ent_count = n_entities; Entity* my_entities[ent_count]; BOOL inGUIMode = [player showDemoShips]; @@ -5311,7 +5201,7 @@ BOOL maintainLinkedLists(Universe* uni) // we want to skip on to another ship demo_ship_index++; demo_ship_index %= [demo_ships count]; - NSLog(@"***** Oolite Data Not Found Exception : '%@' in DEMO_FLY_OUT stage of [Universe update:] *****", [localException reason]); + OOLog(kOOLogException, @"***** Oolite Data Not Found Exception : '%@' in DEMO_FLY_OUT stage of [Universe update:] *****", [localException reason]); okay = NO; } else @@ -5416,7 +5306,7 @@ BOOL maintainLinkedLists(Universe* uni) [self handleOoliteException:localException]; else { - NSLog(@"\n\n***** Encountered localException during %@ in [Universe update:] : %@ : %@ *****\n\n", update_stage, [localException name], [localException reason]); + OOLog(kOOLogException, @"***** Exception during during %@ in [Universe update:] : %@ : %@ *****", update_stage, [localException name], [localException reason]); [localException raise]; } @@ -5701,7 +5591,7 @@ BOOL maintainLinkedLists(Universe* uni) - (void) setSystemTo:(Random_Seed) s_seed { NSDictionary* systemData; - PlayerEntity* player = (PlayerEntity *)[self entityZero]; + PlayerEntity* player = [PlayerEntity sharedPlayer]; [self setGalaxy_seed: [player galaxy_seed]]; @@ -5820,7 +5710,7 @@ BOOL maintainLinkedLists(Universe* uni) NSString *name = [self generateSystemName:s_seed]; NSString *inhabitants = [self generateSystemInhabitants:s_seed plural:YES]; - NSString *description = [self generateSystemDescription:s_seed]; + NSString *description = DescriptionForSystem(s_seed); NSString *override_key = [self keyForPlanetOverridesForSystemSeed:s_seed inGalaxySeed:galaxy_seed]; @@ -5842,8 +5732,6 @@ BOOL maintainLinkedLists(Universe* uni) [systemdata addEntriesFromDictionary:(NSDictionary *)[planetinfo objectForKey:override_key]]; if ([local_planetinfo_overrides objectForKey:override_key]) [systemdata addEntriesFromDictionary:(NSDictionary *)[local_planetinfo_overrides objectForKey:override_key]]; - - //NSLog(@"Generated system data is :\n%@",[systemdata description]); return [NSDictionary dictionaryWithDictionary:[systemdata autorelease]]; } @@ -6024,10 +5912,6 @@ BOOL maintainLinkedLists(Universe* uni) return system; } -+ (NSString*) systemSeedString:(Random_Seed) s -{ - return [NSString stringWithFormat: @"%d %d %d %d %d %d", s.a, s.b, s.c, s.d, s.e, s.f]; -} - (NSArray*) nearbyDestinationsWithinRange:(double) range { @@ -6042,15 +5926,13 @@ BOOL maintainLinkedLists(Universe* uni) if ((dist > 0) && (dist <= range) && (dist <= 7.0)) // limit to systems within 7LY { [result addObject: [NSDictionary dictionaryWithObjectsAndKeys: - [Universe systemSeedString:systems[i]], @"system_seed", - [NSNumber numberWithDouble: dist], @"distance", + StringFromRandomSeed(systems[i]), @"system_seed", + [NSNumber numberWithDouble:dist], @"distance", [self getSystemName:systems[i]], @"name", nil]]; } } -// NSLog(@"DEBUG found possible destinations: %@", result); - return result; } @@ -6219,9 +6101,6 @@ BOOL maintainLinkedLists(Universe* uni) if ((start < 0)||(start > 255)||(goal < 0)||(goal > 255)) return nil; -// NSLog(@"DEBUG determining route from %d (%d,%d) to %d (%d, %d)", start, systems[start].d, systems[start].b, goal, systems[goal].d, systems[goal].b); - - // use A* algorithm to determine shortest route // for this we need the neighbouring (<= 7LY distant) systems @@ -6292,8 +6171,6 @@ BOOL maintainLinkedLists(Universe* uni) cost_to_goal = [(NSNumber*)[node objectForKey:@"cost_to_goal"] doubleValue]; total_cost_estimate = [(NSNumber*)[node objectForKey:@"total_cost_estimate"] doubleValue]; parent_node = (NSDictionary *)[node objectForKey:@"parent_node"]; - -// NSLog(@"DEBUG examining location %d from list of %d ...", location, [open_nodes count]); // if at goal we're done! if (location == goal) @@ -6320,8 +6197,6 @@ BOOL maintainLinkedLists(Universe* uni) { NSArray* neighbours = (NSArray *)[neighbour_systems objectAtIndex:location]; -// NSLog(@"DEBUG neighbours for %d = %@", location, [neighbours description]); - for (i = 0; i < [neighbours count]; i++) { int newLocation = [(NSNumber *)[neighbours objectAtIndex:i] intValue]; @@ -6446,17 +6321,10 @@ BOOL maintainLinkedLists(Universe* uni) station_roles = (NSString*)[[self currentSystemData] objectForKey:@"market"]; } -// NSLog(@"///// station roles detected as '%@'", station_roles); - if (![commoditylists objectForKey:station_roles]) { -// NSLog(@"///// using default economy"); station_roles = @"default"; } - else - { -// NSLog(@"///// found a special economy"); - } NSMutableArray *ourEconomy = [NSMutableArray arrayWithArray:(NSArray *)[commoditylists objectForKey:station_roles]]; int i; @@ -6496,7 +6364,7 @@ double estimatedTimeForJourney(double distance, int hops) - (NSArray *) passengersForSystem:(Random_Seed) s_seed atTime:(double) current_time { - PlayerEntity* player = [self entityZero]; + PlayerEntity* player = [PlayerEntity sharedPlayer]; int player_repute = [player passengerReputation]; @@ -6522,8 +6390,6 @@ double estimatedTimeForJourney(double distance, int hops) NSMutableArray* resultArray = [NSMutableArray arrayWithCapacity:255]; int i = 0; -// NSLog(@"DEBUG Passenger generator for reputation %d...\n", [player passengerReputation]); - for (i = 0; i < 256; i++) { long long reference_time = 0x1000000 * floor( current_time / 0x1000000); @@ -6543,8 +6409,6 @@ double estimatedTimeForJourney(double distance, int hops) int destination_government = [(NSNumber*)[destinationInfo objectForKey:KEY_GOVERNMENT] intValue]; int pick_up_factor = destination_government + floor(days_until_departure) - 7; // lower for anarchies (gov 0) - -// NSLog(@"DEBUG Passenger to %d pick-up %d repute %d", passenger_destination, pick_up_factor, player_repute); if ((days_until_departure > 0.0)&&(pick_up_factor <= player_repute)&&(passenger_seed.d != start)) { @@ -6560,11 +6424,10 @@ double estimatedTimeForJourney(double distance, int hops) passenger_species_string = [[passenger_species_string lowercaseString] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; // determine the passenger's name -// seed_for_planet_description(passenger_seed); // set the random number generator seed_RNG_only_for_planet_description(passenger_seed); - NSString* passenger_name = [NSString stringWithFormat:@"%@ %@", [self expandDescription:@"%R" forSystem:passenger_seed], [self expandDescription:@"%R" forSystem:passenger_seed]]; + NSString* passenger_name = [NSString stringWithFormat:@"%@ %@", ExpandDescriptionForSeed(@"%R", passenger_seed), ExpandDescriptionForSeed(@"%R", passenger_seed)]; if ([passenger_species_string hasPrefix:@"human"]) - passenger_name = [NSString stringWithFormat:@"%@ %@", [self expandDescription:@"%R" forSystem:passenger_seed], [self expandDescription:@"[nom]" forSystem:passenger_seed]]; + passenger_name = [NSString stringWithFormat:@"%@ %@", ExpandDescriptionForSeed(@"%R", passenger_seed), ExpandDescriptionForSeed(@"[nom]", passenger_seed)]; // determine information about the route... NSDictionary* routeInfo = [self routeFromSystem:start ToSystem:passenger_destination]; @@ -6575,7 +6438,6 @@ double estimatedTimeForJourney(double distance, int hops) NSString* destination_name = [self generateSystemName:destination_seed]; double route_length = [(NSNumber *)[routeInfo objectForKey:@"distance"] doubleValue]; -// double distance_as_crow_flies = accurateDistanceBetweenPlanetPositions(s_seed.d,s_seed.b,destination_seed.d,destination_seed.b); int route_hops = [(NSArray *)[routeInfo objectForKey:@"route"] count] - 1; // 50 cr per hop + 8..15 cr per LY + bonus for low government level of destination @@ -6588,7 +6450,6 @@ double estimatedTimeForJourney(double distance, int hops) fee -= premium; // 1hr per LY*LY, + 30 mins per hop -// double passenger_arrival_time = passenger_departure_time + 4000 * distance_as_crow_flies * distance_as_crow_flies + 2000 * route_hops; double passenger_arrival_time = passenger_departure_time + estimatedTimeForJourney( route_length, route_hops); @@ -6607,8 +6468,6 @@ double estimatedTimeForJourney(double distance, int hops) long_description = [NSString stringWithFormat: @"%@ Will pay %d Cr: %d Cr in advance, and %d Cr on arrival.", long_description, premium + fee, premium, fee]; - -// NSLog(@"DEBUG Passenger %@:\n%@\n...", passenger_name, long_description); NSDictionary* passenger_info_dictionary = [NSDictionary dictionaryWithObjectsAndKeys: passenger_name, PASSENGER_KEY_NAME, @@ -6709,7 +6568,7 @@ double estimatedTimeForJourney(double distance, int hops) - (NSArray *) contractsForSystem:(Random_Seed) s_seed atTime:(double) current_time { - PlayerEntity* player = [self entityZero]; + PlayerEntity* player = [PlayerEntity sharedPlayer]; int player_repute = [player contractReputation]; @@ -6734,8 +6593,6 @@ double estimatedTimeForJourney(double distance, int hops) NSMutableArray* resultArray = [NSMutableArray arrayWithCapacity:255]; int i = 0; -// NSLog(@"DEBUG contract generator for reputation %d...\n", [player contractReputation]); - NSArray* localMarket; if ([[self station] localMarket]) localMarket = [[self station] localMarket]; @@ -6746,8 +6603,6 @@ double estimatedTimeForJourney(double distance, int hops) { long long reference_time = 0x1000000 * floor( current_time / 0x1000000); -// NSLog(@"DEBUG time = %lld (%.1f) reference time = %lld", now, current_time, reference_time); - long long contract_time = contract_seed.a * 0x10000 + contract_seed.b * 0x100 + contract_seed.c; double contract_departure_time = reference_time + contract_time; @@ -6770,8 +6625,6 @@ double estimatedTimeForJourney(double distance, int hops) int destination_economy = [(NSNumber*)[destinationInfo objectForKey:KEY_ECONOMY] intValue]; NSArray* destinationMarket = [self commodityDataForEconomy:destination_economy andStation:[self station] andRandomFactor:random_factor]; -// NSLog(@"DEBUG local economy:\n%@\ndestination_economy:\n%@", [localMarket description], [destinationMarket description]); - // now we need a commodity that's both plentiful here and scarce there... // build list of goods allocating 0..100 for each based on how // much of each quantity there is. Use a ratio of n x 100/64 @@ -6882,8 +6735,6 @@ double estimatedTimeForJourney(double distance, int hops) long_description = [NSString stringWithFormat: @"%@ The contract will cost you %.1f Cr, and pay a total of %.1f Cr.", long_description, premium, premium + fee]; - -// NSLog(@"DEBUG (%06x-%06x):\n%@\n...", super_rand1, super_rand2, long_description); NSDictionary* contract_info_dictionary = [NSDictionary dictionaryWithObjectsAndKeys: [NSString stringWithFormat:@"%06x-%06x", super_rand1, super_rand2 ],CONTRACT_KEY_ID, @@ -6941,14 +6792,10 @@ double estimatedTimeForJourney(double distance, int hops) float tech_price_boost = (ship_seed.a + ship_seed.b) / 256.0; int i = 0; -// NSLog(@"DEBUG ships for sale generator...\n"); - for (i = 0; i < 256; i++) { long long reference_time = 0x1000000 * floor( current_time / 0x1000000); -// NSLog(@"DEBUG time = %lld (%.1f) reference time = %lld", now, current_time, reference_time); - long long c_time = ship_seed.a * 0x10000 + ship_seed.b * 0x100 + ship_seed.c; double ship_sold_time = reference_time + c_time; @@ -6966,7 +6813,7 @@ double estimatedTimeForJourney(double distance, int hops) NSDictionary* dict = (NSDictionary*)[shipyard objectForKey: key]; if ([dict objectForKey:@"conditions"]) { - PlayerEntity* player = [self entityZero]; + PlayerEntity* player = [PlayerEntity sharedPlayer]; if ((player) && (player->isPlayer) && (![player checkCouplet: dict onEntity: player])) [keysForShips removeObjectAtIndex: si--]; } @@ -6999,7 +6846,7 @@ double estimatedTimeForJourney(double distance, int hops) NS_HANDLER if ([[localException name] isEqual: OOLITE_EXCEPTION_SHIP_NOT_FOUND]) { - NSLog(@"***** Oolite Ship Not Found Exception : '%@' in [Universe shipsForSaleInSystem:atTime:] *****", [localException reason]); + OOLog(kOOLogException, @"***** Oolite Ship Not Found Exception : '%@' in [Universe shipsForSaleInSystem:atTime:] *****", [localException reason]); ship_base_dict = nil; } else @@ -7226,8 +7073,6 @@ double estimatedTimeForJourney(double distance, int hops) i++; } -// NSLog(@"Ships for sale:\n%@", [resultArray description]); - return [NSArray arrayWithArray:resultArray]; } @@ -7282,8 +7127,6 @@ NSComparisonResult comparePrice(NSDictionary *dict1, NSDictionary *dict2, void * int base_weapon_value = [self getPriceForWeaponSystemWithKey:base_fwd_weapon_key] / 10; NSArray* base_extra_equipment = (NSArray*)[basic_info objectForKey:KEY_EQUIPMENT_EXTRAS]; -// NSLog(@"DEBUG shipyard_info:\n%@\nbasic_info\n%@\n", [shipyard_info description], [basic_info description]); - // work out weapon values if (cmdr_fwd_weapon) { @@ -7325,11 +7168,6 @@ NSComparisonResult comparePrice(NSDictionary *dict1, NSDictionary *dict2, void * extra_equipment_value += [self getPriceForWeaponSystemWithKey:(NSString*)[cmdr_extra_equipment objectAtIndex:j]] / 10; // final reckoning - -// NSLog(@"DEBUG base_price for %@ %d weapons_bonus %d equipment_bonus %d", cmdr_ship_desc, base_price, -// cmdr_missiles_value + cmdr_other_weapons_value + cmdr_fwd_weapon_value - base_weapon_value - base_missiles_value, -// extra_equipment_value); - result = base_price; // add on extra weapons - base weapons @@ -7504,179 +7342,6 @@ NSComparisonResult comparePrice(NSDictionary *dict1, NSDictionary *dict2, void * } - -- (NSString *) generateSystemDescription:(Random_Seed) s_seed -{ -// seed_for_planet_description (s_seed); - seed_RNG_only_for_planet_description(s_seed); - return [self expandDescription:@"[14] is [22]." forSystem:s_seed]; -} - -- (NSString *) expandDescription:(NSString *) desc forSystem:(Random_Seed)s_seed -{ -// return [self expandDescriptionWithLocals:desc forSystem:s_seed withLocalVariables:nil]; - - // to enable variables to return strings that can be expanded (eg. @"[commanderName_string]") - // we're going to loop until every expansion has been done! - // but to check this does not infinitely recurse - // we'll stop after 32 loops. - - int stack_check = 32; - NSString *old_desc = [NSString stringWithString: desc]; - NSString *result = desc; - do { - old_desc = result; - result = [self expandDescriptionWithLocals:result forSystem:s_seed withLocalVariables:nil]; - } while ((--stack_check)&&(![result isEqual:old_desc])); - - if (!stack_check) - { - NSLog(@"***** ERROR: script stack overflow for expandDescription: \"%@\"", desc); - NSException *myException = [NSException - exceptionWithName: OOLITE_EXCEPTION_LOOPING - reason:[NSString stringWithFormat:@"script stack overflow for expandDescription: \"%@\"", desc] - userInfo:nil]; - [myException raise]; - } - - return result; -} - -- (NSString *) expandDescriptionWithLocals:(NSString *) desc forSystem:(Random_Seed)s_seed withLocalVariables:(NSDictionary *)locals -{ - PlayerEntity *player = [self entityZero]; - NSMutableString *partial = [NSMutableString stringWithString:desc]; - NSMutableDictionary *all_descriptions = [NSMutableDictionary dictionaryWithDictionary:descriptions]; -// -// -- GILES move mission variable expansion to new routine -- -// -// // add in mission_variables if required -// if ([desc rangeOfString:@"[mission_"].location != NSNotFound) -// { -// NSDictionary* mission_vars = [player mission_variables]; -// NSEnumerator* missVarsEnum = [mission_vars keyEnumerator]; -// id key; -// while (key = [missVarsEnum nextObject]) -// [all_descriptions setObject:[mission_vars objectForKey:key] forKey:key]; -// } -// -// // also add the mission-local vars, if they have been passed in -// if (locals != nil && [desc rangeOfString:@"[local_"].location != NSNotFound) -// { -// NSEnumerator* localVarsEnum = [locals keyEnumerator]; -// id key; -// while (key = [localVarsEnum nextObject]) -// [all_descriptions setObject:[locals objectForKey:key] forKey:key]; -// } - - // add in player info if required - - // -- this is now duplicated with new commanderXXX_string and commanderYYY_number methods in PlayerEntity Additions -- GILES - - if ([desc rangeOfString:@"[commander_"].location != NSNotFound) - { - // commander's name - [all_descriptions setObject:[player commanderName_string] forKey:@"commander_name"]; - // one or two word description of ship - [all_descriptions setObject:[player commanderShip_string] forKey:@"commander_shipname"]; - // ranking from Hamless to ELITE - [all_descriptions setObject:[player commanderRank_string] forKey:@"commander_rank"]; - // legal status - [all_descriptions setObject:[player commanderLegalStatus_string] forKey:@"commander_legal_status"]; - } - - while ([partial rangeOfString:@"["].location != NSNotFound) - { - NSString *part, *before, *after, *middle; - int sub, rnd, opt; - int p1 = [partial rangeOfString:@"["].location; - int p2 = [partial rangeOfString:@"]"].location + 1; - - part = nil; // stop compiler warning... - - before = [partial substringWithRange:NSMakeRange(0,p1)]; - after = [partial substringWithRange:NSMakeRange(p2,[partial length] - p2)]; - middle = [partial substringWithRange:NSMakeRange(p1 + 1 , p2 - p1 - 2)]; - - // check all_descriptions for an array that's keyed to middle - if ([all_descriptions objectForKey:middle]) - { - if ([[all_descriptions objectForKey:middle] isKindOfClass:[NSArray class]]) - { - NSArray* choices = (NSArray*)[all_descriptions objectForKey:middle]; - rnd = gen_rnd_number() % [choices count]; - part = [NSString stringWithString:(NSString *)[choices objectAtIndex:rnd]]; - } - else - { - part = [all_descriptions objectForKey:middle]; - } - } -// else if (([middle hasSuffix:@"_number"])||([middle hasSuffix:@"_bool"])||([middle hasSuffix:@"_string"])) -// { -// SEL value_selector = NSSelectorFromString(middle); -// if ([player respondsToSelector:value_selector]) -// { -// part = [NSString stringWithFormat:@"%@", [player performSelector:value_selector]]; -// } -// } - else if ([[middle stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"0123456789"]] isEqual:@""]) - { - // if all characters are all from the set "0123456789" interpret it as a number in system_description array - if (![middle isEqual:@""]) - { - sub = [middle intValue]; - - //NSLog(@"Expanding:\t%@",partial); - rnd = gen_rnd_number(); - opt = 0; - if (rnd >= 0x33) opt++; - if (rnd >= 0x66) opt++; - if (rnd >= 0x99) opt++; - if (rnd >= 0xCC) opt++; - - part = (NSString *)[(NSArray *)[(NSArray *)[all_descriptions objectForKey:@"system_description"] objectAtIndex:sub] objectAtIndex:opt]; - } - else - part = @""; - } - else - { - // do replacement of mission and local variables here instead - part = [player replaceVariablesInString:middle]; - } - partial = [NSMutableString stringWithFormat:@"%@%@%@",before,part,after]; - } - - [partial replaceOccurrencesOfString:@"%H" - withString:[self generateSystemName:s_seed] - options:NSLiteralSearch range:NSMakeRange(0, [partial length])]; - - [partial replaceOccurrencesOfString:@"%I" - withString:[NSString stringWithFormat:@"%@ian",[self generateSystemName:s_seed]] - options:NSLiteralSearch range:NSMakeRange(0, [partial length])]; - - [partial replaceOccurrencesOfString:@"%R" - withString:[self getRandomDigrams] - options:NSLiteralSearch range:NSMakeRange(0, [partial length])]; - - return partial; -} - -- (NSString *) getRandomDigrams -{ - int i; - int len = gen_rnd_number() & 3; - NSString* digrams = [descriptions objectForKey:@"digrams"]; - NSMutableString* name = [NSMutableString stringWithCapacity:256]; - for (i = 0; i <=len; i++) - { - int x = gen_rnd_number() & 0x3e; - [name appendString:[digrams substringWithRange:NSMakeRange(x,2)]]; - } - return [name capitalizedString]; -} - - (Vector) getWitchspaceExitPosition { Vector result; @@ -7715,7 +7380,6 @@ NSComparisonResult comparePrice(NSDictionary *dict1, NSDictionary *dict2, void * if (!ship) { NSLog(@"ERROR ***** No ship set in Universe getSunSkimStartPositionForShip:"); - // NSBeep(); // AppKit return make_vector( 0.0f, 0.0f, 0.0f); } PlanetEntity* the_sun = [self sun]; @@ -7723,7 +7387,6 @@ NSComparisonResult comparePrice(NSDictionary *dict1, NSDictionary *dict2, void * if (!the_sun) { NSLog(@"ERROR ***** No sun set in Universe getSunSkimStartPositionForShip:"); - // NSBeep(); // AppKit return make_vector( 0.0f, 0.0f, 0.0f); } Vector v0 = the_sun->position; @@ -7746,14 +7409,12 @@ NSComparisonResult comparePrice(NSDictionary *dict1, NSDictionary *dict2, void * if (!ship) { NSLog(@"ERROR ***** No ship set in Universe getSunSkimEndPositionForShip:"); - // NSBeep(); // AppKit return make_vector( 0.0f, 0.0f, 0.0f); } // get vector from sun position to ship if (!the_sun) { NSLog(@"ERROR ***** No sun set in Universe getSunSkimEndPositionForShip:"); - // NSBeep(); // AppKit return make_vector( 0.0f, 0.0f, 0.0f); } Vector v0 = the_sun->position; @@ -7805,9 +7466,6 @@ NSComparisonResult comparePrice(NSDictionary *dict1, NSDictionary *dict2, void * - (void) allShipAIsReactToMessage:(NSString*) message { - -// NSLog(@"DEBUG sending all ships '%@'", message); - int i; int ent_count = n_entities; int ship_count = 0; @@ -7920,17 +7578,17 @@ NSComparisonResult comparePrice(NSDictionary *dict1, NSDictionary *dict2, void * { exception = [ooliteException retain]; - PlayerEntity* player = [self entityZero]; + PlayerEntity* player = [PlayerEntity sharedPlayer]; [player setStatus:STATUS_HANDLING_ERROR]; - NSLog(@"***** Handling Fatal : %@ : %@ *****",[exception name], [exception reason]); + OOLog(kOOLogException, @"***** Handling Fatal : %@ : %@ *****",[exception name], [exception reason]); NSString* exception_msg = [NSString stringWithFormat:@"Exception : %@ : %@ Please take a screenshot and/or press esc or Q to quit.", [exception name], [exception reason]]; [self addMessage:exception_msg forCount:30.0]; [[self gameController] pause_game]; } else { - NSLog(@"***** Handling Non-fatal : %@ : %@ *****",[ooliteException name], [ooliteException reason]); + OOLog(kOOLogException, @"***** Handling Non-fatal : %@ : %@ *****",[ooliteException name], [ooliteException reason]); } } } diff --git a/src/Core/WormholeEntity.m b/src/Core/WormholeEntity.m index 3445bb15..64ec6219 100644 --- a/src/Core/WormholeEntity.m +++ b/src/Core/WormholeEntity.m @@ -27,10 +27,12 @@ MA 02110-1301, USA. #import "ParticleEntity.h" #import "ShipEntity.h" #import "PlanetEntity.h" +#import "PlayerEntity.h" #import "Universe.h" #import "AI.h" #import "TextureStore.h" +#import "OOStringParsing.h" @implementation WormholeEntity @@ -61,14 +63,12 @@ MA 02110-1301, USA. // position = [ship getPosition]; // - Entity* player = [universe entityZero]; + PlayerEntity *player = [PlayerEntity sharedPlayer]; if (player) zero_distance = distance2( player->position, position); // isWormhole = YES; - // -// NSLog(@"DEBUG %@ created!", self); - // + return self; } @@ -87,8 +87,6 @@ MA 02110-1301, USA. expiry_time = time_counter + WORMHOLE_EXPIRES_TIMEINTERVAL; collision_radius = 0.5 * PI * pow( witch_mass, 1.0/3.0); -// NSLog(@"DEBUG %@ sucks in %@", self, ship); - // witchspace entry effects here ParticleEntity *ring = [[ParticleEntity alloc] initHyperringFromShip:ship]; // retained [universe addEntity:ring]; @@ -112,8 +110,6 @@ MA 02110-1301, USA. - (void) disgorgeShips { -// NSLog(@"disgorging %@", shipsInTransit); - int n_ships = [shipsInTransit count]; int i; @@ -147,10 +143,6 @@ MA 02110-1301, USA. [[ship getAI] reactToMessage:@"EXITED WITCHSPACE"]; -// [ship setReportAImessages:YES]; // DEBUG - -// NSLog(@"DEBUG %@ disgorged %@", self, ship); - // update the ships's position [ship update: time_passed]; } @@ -170,7 +162,7 @@ MA 02110-1301, USA. - (NSString*) description { - NSString* whereto = (universe)? [universe getSystemName: destination] : [Universe systemSeedString: destination]; + NSString* whereto = (universe) ? [universe getSystemName:destination] : StringFromRandomSeed(destination); return [NSString stringWithFormat:@"", whereto, WORMHOLE_EXPIRES_TIMEINTERVAL - time_counter]; } @@ -190,7 +182,7 @@ MA 02110-1301, USA. { [super update:delta_t]; - Entity* player = [universe entityZero]; + Entity* player = [PlayerEntity sharedPlayer]; if (player) { // new billboard routine (from Planetentity.m) diff --git a/src/SDL/JoystickHandler.m b/src/SDL/JoystickHandler.m index a390d79a..a78c9f2b 100644 --- a/src/SDL/JoystickHandler.m +++ b/src/SDL/JoystickHandler.m @@ -24,6 +24,10 @@ MA 02110-1301, USA. */ #import "JoystickHandler.h" +#import "OOLogging.h" + +#define kOOLogUnconvertedNSLog @"unclassified.JoystickHandler" + @implementation JoystickHandler diff --git a/src/SDL/MyOpenGLView.m b/src/SDL/MyOpenGLView.m index e5163409..b8f0cff5 100644 --- a/src/SDL/MyOpenGLView.m +++ b/src/SDL/MyOpenGLView.m @@ -38,6 +38,8 @@ MA 02110-1301, USA. #import "TextureStore.h" #endif +#define kOOLogUnconvertedNSLog @"unclassified.MyOpenGLView" + #include @implementation MyOpenGLView diff --git a/src/SDL/SDLMusic.m b/src/SDL/SDLMusic.m index 2d451666..ce787405 100644 --- a/src/SDL/SDLMusic.m +++ b/src/SDL/SDLMusic.m @@ -23,6 +23,9 @@ MA 02110-1301, USA. */ #include "SDLMusic.h" +#import "OOLogging.h" + +#define kOOLogUnconvertedNSLog @"unclassified.SDLMusic" /* * This is used by instances of OOMusic to check if they are currently playing diff --git a/src/SDL/SDLSound.m b/src/SDL/SDLSound.m index 4614bf79..8b8993b5 100644 --- a/src/SDL/SDLSound.m +++ b/src/SDL/SDLSound.m @@ -25,6 +25,8 @@ MA 02110-1301, USA. #import "SDLSound.h" #import "OOBasicSoundSource.h" +#define kOOLogUnconvertedNSLog @"unclassified.SDLSound" + static int mixChan=0; static float masterVol=1.0; @@ -148,7 +150,6 @@ static BOOL isSetUp=NO; [super init]; if(!isSetUp) [OOSound setUp]; - //NSLog(@"loading sample: %s", [filepath cString]); sample = Mix_LoadWAV([filepath cString]); if (!sample) { NSLog(@"Mix_LoadWAV: %s\n", Mix_GetError());