Lots of changes, mostly JavaScript-related. Bumped version number to 1.68.

git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@877 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
Jens Ayton 2007-04-01 11:26:35 +00:00
parent 05e5a0282f
commit 3fe9c74267
34 changed files with 2033 additions and 685 deletions

View File

@ -21,7 +21,7 @@ endif
OBJC_PROGRAM_NAME = oolite
oolite_C_FILES = legacy_random.c strlcpy.c
oolite_OBJC_FILES = Comparison.m AI.m DustEntity.m Entity.m GameController.m GuiDisplayGen.m HeadUpDisplay.m main.m MyOpenGLView.m OpenGLSprite.m ParticleEntity.m PlanetEntity.m PlayerEntityScripting.m PlayerEntityContracts.m PlayerEntityControls.m PlayerEntityLoadSave.m PlayerEntitySound.m PlayerEntity.m ResourceManager.m RingEntity.m ShipEntityAI.m ShipEntity.m SkyEntity.m StationEntity.m TextureStore.m Universe.m OOSound.m SDLMusic.m SDLImage.m NSFileManagerOOExtensions.m JoystickHandler.m PlayerEntityStickMapper.m OOBasicSoundReferencePoint.m OOBasicSoundSource.m OOCharacter.m OOTrumble.m WormholeEntity.m NSScannerOOExtensions.m OOXMLExtensions.m NSMutableDictionaryOOExtensions.m Geometry.m Octree.m CollisionRegion.m OOColor.m ScriptCompiler.m StringTokeniser.m OOLogging.m OOCacheManager.m OOCache.m OXPScript.m ScriptEngine.m OOStringParsing.m OOCollectionExtractors.m OOVector.m OOMatrix.m OOQuaternion.m OOVoxel.m OOTriangle.m OOPListParsing.m OOFastArithmetic.m OOTextureScaling.m
oolite_OBJC_FILES = Comparison.m AI.m DustEntity.m Entity.m GameController.m GuiDisplayGen.m HeadUpDisplay.m main.m MyOpenGLView.m OpenGLSprite.m ParticleEntity.m PlanetEntity.m PlayerEntityScripting.m PlayerEntityContracts.m PlayerEntityControls.m PlayerEntityLoadSave.m PlayerEntitySound.m PlayerEntity.m ResourceManager.m RingEntity.m ShipEntityAI.m ShipEntity.m SkyEntity.m StationEntity.m TextureStore.m Universe.m OOSound.m SDLMusic.m SDLImage.m NSFileManagerOOExtensions.m JoystickHandler.m PlayerEntityStickMapper.m OOBasicSoundReferencePoint.m OOBasicSoundSource.m OOCharacter.m OOTrumble.m WormholeEntity.m NSScannerOOExtensions.m OOXMLExtensions.m NSMutableDictionaryOOExtensions.m Geometry.m Octree.m CollisionRegion.m OOColor.m ScriptCompiler.m StringTokeniser.m OOLogging.m OOCacheManager.m OOCache.m OXPScript.m ScriptEngine.m OOStringParsing.m OOCollectionExtractors.m OOVector.m OOMatrix.m OOQuaternion.m OOVoxel.m OOTriangle.m OOPListParsing.m OOFastArithmetic.m OOTextureScaling.m OOScript.m OOPListScript.m OOConstToString.m
include $(GNUSTEP_MAKEFILES)/objc.make
include GNUmakefile.postamble

View File

@ -230,6 +230,14 @@
1A472917096B5454000E78D8 /* CoreAudio.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1A472916096B5454000E78D8 /* CoreAudio.framework */; };
1A472921096B5468000E78D8 /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1A47291F096B5468000E78D8 /* AudioToolbox.framework */; };
1A472922096B5468000E78D8 /* AudioUnit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1A472920096B5468000E78D8 /* AudioUnit.framework */; };
1A5DAFFE0BBD6E3300D57389 /* OOJavaScriptEngine.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A5DAFF80BBD6E3300D57389 /* OOJavaScriptEngine.h */; };
1A5DAFFF0BBD6E3300D57389 /* OOJSScript.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A5DAFF90BBD6E3300D57389 /* OOJSScript.h */; };
1A5DB0010BBD6E3300D57389 /* OOScript.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A5DAFFB0BBD6E3300D57389 /* OOScript.h */; };
1A5DB0020BBD6E3300D57389 /* OOScript.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A5DAFFC0BBD6E3300D57389 /* OOScript.m */; };
1A5DB1EA0BBD8F0000D57389 /* OOConstToString.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A5DB1E80BBD8F0000D57389 /* OOConstToString.h */; };
1A5DB1EB0BBD8F0000D57389 /* OOConstToString.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A5DB1E90BBD8F0000D57389 /* OOConstToString.m */; };
1A5DB2980BBE9EC400D57389 /* OOPListScript.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A5DB2970BBE9EC400D57389 /* OOPListScript.h */; };
1A5DB2A20BBE9F4700D57389 /* OOPListScript.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A5DB2A10BBE9F4700D57389 /* OOPListScript.m */; };
1A81F7090A7BAC4D006580AD /* OOCAMusic.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A81F7070A7BAC4D006580AD /* OOCAMusic.m */; };
1A81F70A0A7BAC4D006580AD /* OOCAMusic.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A81F7080A7BAC4D006580AD /* OOCAMusic.h */; };
1A8A37040B95CADD007D20B8 /* PlayerEntityLoadSave.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A8A37020B95CADD007D20B8 /* PlayerEntityLoadSave.m */; };
@ -943,6 +951,14 @@
1A47291F096B5468000E78D8 /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = /System/Library/Frameworks/AudioToolbox.framework; sourceTree = "<absolute>"; };
1A472920096B5468000E78D8 /* AudioUnit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioUnit.framework; path = /System/Library/Frameworks/AudioUnit.framework; sourceTree = "<absolute>"; };
1A5BF2720916D47300BF238F /* Oolite-importer.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = "Oolite-importer.xcodeproj"; path = "Oolite-importer/Oolite-importer.xcodeproj"; sourceTree = "<group>"; };
1A5DAFF80BBD6E3300D57389 /* OOJavaScriptEngine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OOJavaScriptEngine.h; path = Scripting/OOJavaScriptEngine.h; sourceTree = "<group>"; };
1A5DAFF90BBD6E3300D57389 /* OOJSScript.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OOJSScript.h; path = Scripting/OOJSScript.h; sourceTree = "<group>"; };
1A5DAFFB0BBD6E3300D57389 /* OOScript.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OOScript.h; path = Scripting/OOScript.h; sourceTree = "<group>"; };
1A5DAFFC0BBD6E3300D57389 /* OOScript.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OOScript.m; path = Scripting/OOScript.m; sourceTree = "<group>"; };
1A5DB1E80BBD8F0000D57389 /* OOConstToString.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OOConstToString.h; sourceTree = "<group>"; };
1A5DB1E90BBD8F0000D57389 /* OOConstToString.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OOConstToString.m; sourceTree = "<group>"; };
1A5DB2970BBE9EC400D57389 /* OOPListScript.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OOPListScript.h; path = Scripting/OOPListScript.h; sourceTree = "<group>"; };
1A5DB2A10BBE9F4700D57389 /* OOPListScript.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OOPListScript.m; path = Scripting/OOPListScript.m; sourceTree = "<group>"; };
1A81F7070A7BAC4D006580AD /* OOCAMusic.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OOCAMusic.m; sourceTree = "<group>"; };
1A81F7080A7BAC4D006580AD /* OOCAMusic.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OOCAMusic.h; sourceTree = "<group>"; };
1A8A37020B95CADD007D20B8 /* PlayerEntityLoadSave.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PlayerEntityLoadSave.m; sourceTree = "<group>"; };
@ -1489,6 +1505,17 @@
name = Products;
sourceTree = "<group>";
};
1A5DAFF60BBD6DE400D57389 /* Scripting */ = {
isa = PBXGroup;
children = (
1A5DAFFB0BBD6E3300D57389 /* OOScript.h */,
1A5DAFFC0BBD6E3300D57389 /* OOScript.m */,
1AEAAB870BA4515E000705D0 /* JavaScript */,
1A8A3DAB0B9B061800AB7625 /* PList scripts */,
);
name = Scripting;
sourceTree = "<group>";
};
1A8A3BE90B963F02007D20B8 /* Source */ = {
isa = PBXGroup;
children = (
@ -1497,7 +1524,6 @@
1A8A3C1E0B9640B4007D20B8 /* Mathematics */,
1A8A3C180B964030007D20B8 /* Resource Management */,
1A8A3C1B0B96407A007D20B8 /* User Interface */,
1A8A3DAB0B9B061800AB7625 /* OOScript */,
1A8A3BFB0B963F91007D20B8 /* Utilities */,
1A8A3BF20B963F3C007D20B8 /* Mac-specific */,
25161144099544390037C2E1 /* Universe.h */,
@ -1507,7 +1533,7 @@
25161116099544390037C2E1 /* OOSound.h */,
25161100099544380037C2E1 /* OpenGLSprite.h */,
251610FF099544380037C2E1 /* OpenGLSprite.m */,
1AEAAB870BA4515E000705D0 /* JavaScript */,
1A5DAFF60BBD6DE400D57389 /* Scripting */,
);
name = Source;
path = src/Core;
@ -1553,6 +1579,8 @@
1A9403CF0BAF36C3005F6CF3 /* OOFunctionAttributes.h */,
1A9404240BAF3DED005F6CF3 /* OOCollectionExtractors.m */,
1A9404250BAF3DED005F6CF3 /* OOCollectionExtractors.h */,
1A5DB1E80BBD8F0000D57389 /* OOConstToString.h */,
1A5DB1E90BBD8F0000D57389 /* OOConstToString.m */,
);
name = Utilities;
sourceTree = "<group>";
@ -1711,14 +1739,16 @@
name = Groolite;
sourceTree = "<group>";
};
1A8A3DAB0B9B061800AB7625 /* OOScript */ = {
1A8A3DAB0B9B061800AB7625 /* PList scripts */ = {
isa = PBXGroup;
children = (
0831C5C609E3396D0058029A /* StringTokeniser.m */,
1A5DB2970BBE9EC400D57389 /* OOPListScript.h */,
1A5DB2A10BBE9F4700D57389 /* OOPListScript.m */,
0831C5C709E3396D0058029A /* StringTokeniser.h */,
0831C5C609E3396D0058029A /* StringTokeniser.m */,
0831C5C809E3396D0058029A /* ScriptCompiler.m */,
);
name = OOScript;
name = "PList scripts";
sourceTree = "<group>";
};
1AC0E9380B974D8700C46994 /* Documentation */ = {
@ -1738,7 +1768,8 @@
1AEAAB870BA4515E000705D0 /* JavaScript */ = {
isa = PBXGroup;
children = (
1AEAAC6C0BA457C3000705D0 /* SpiderMonkey headers */,
1A5DAFF80BBD6E3300D57389 /* OOJavaScriptEngine.h */,
1A5DAFF90BBD6E3300D57389 /* OOJSScript.h */,
1AEAACDA0BA45895000705D0 /* JSUniverse.h */,
1AEAACD80BA45895000705D0 /* OXPScript.h */,
1AEAACDB0BA45895000705D0 /* OXPScript.m */,
@ -1800,7 +1831,7 @@
1AEAAC9D0BA457E7000705D0 /* jsapi.h */,
);
name = "SpiderMonkey headers";
path = "../../deps/Cocoa-deps/js/headers";
path = "deps/Cocoa-deps/js/headers";
sourceTree = "<group>";
};
29B97314FDCFA39411CA2CEA /* Oolite_GUSTO */ = {
@ -1820,6 +1851,7 @@
29B97323FDCFA39411CA2CEA /* Frameworks */ = {
isa = PBXGroup;
children = (
1AEAAC6C0BA457C3000705D0 /* SpiderMonkey headers */,
1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */,
1058C7A2FEA54F0111CA2CBB /* Other Frameworks */,
);
@ -1958,6 +1990,11 @@
1AB01ABE0BB15AED00F1B949 /* OOTextureScaling.h in Headers */,
1AB01BBB0BB16A8A00F1B949 /* OOFastArithmetic.h in Headers */,
1A451D8D0BB1BD2A004CD72F /* OOMaths.h in Headers */,
1A5DAFFE0BBD6E3300D57389 /* OOJavaScriptEngine.h in Headers */,
1A5DAFFF0BBD6E3300D57389 /* OOJSScript.h in Headers */,
1A5DB0010BBD6E3300D57389 /* OOScript.h in Headers */,
1A5DB1EA0BBD8F0000D57389 /* OOConstToString.h in Headers */,
1A5DB2980BBE9EC400D57389 /* OOPListScript.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -1980,6 +2017,7 @@
1A2319640B9D02B900EF0852 /* Copy Models */,
1A2319780B9D030400EF0852 /* Copy Music */,
1A2319BA0B9D032700EF0852 /* Copy Sounds */,
1A5DB2D10BBEA46F00D57389 /* Sync logcontrol.plist.xml */,
);
buildRules = (
);
@ -2041,6 +2079,25 @@
};
/* End PBXResourcesBuildPhase section */
/* Begin PBXShellScriptBuildPhase section */
1A5DB2D10BBEA46F00D57389 /* Sync logcontrol.plist.xml */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
"$(SRCROOT)/Resources/Config/logcontrol.plist",
);
name = "Sync logcontrol.plist.xml";
outputPaths = (
"$(SRCROOT)/Resources/Config/logcontrol.plist.xml",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "plutil -convert xml1 -o $SRCROOT/Resources/Config/logcontrol.plist.xml $SRCROOT/Resources/Config/logcontrol.plist\necho Updated logcontrol.plist.xml.\n";
};
/* End PBXShellScriptBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
0865430306B8447D000CA0AB /* Sources */ = {
isa = PBXSourcesBuildPhase;
@ -2115,6 +2172,9 @@
1A9406B50BAF67BF005F6CF3 /* OOTriangle.m in Sources */,
1AB01B5F0BB1639600F1B949 /* OOTextureScaling.m in Sources */,
1AB01BBC0BB16A8A00F1B949 /* OOFastArithmetic.m in Sources */,
1A5DB0020BBD6E3300D57389 /* OOScript.m in Sources */,
1A5DB1EB0BBD8F0000D57389 /* OOConstToString.m in Sources */,
1A5DB2A20BBE9F4700D57389 /* OOPListScript.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@ -17,7 +17,12 @@
“logging-show-app-name” defaults to 1 under Mac OS X (where log output
goes to a shared console) and 0 under GNUstep (where log output goes to an
application-specific log file). “logging-show-class” defaults to 1. The
others default to 0.
others default to 0.
NOTE: the GNUstep plist parser cannot parse this file, presumably because
of the $s. Until this is properly analyzed, an XML version is used
instead. The XML version is automatically generated from this version when
building with Xcode under OS X.
*/
@ -155,7 +160,6 @@ rendering.opengl.shader.texNameMissing = $shaderError;
rendering.opengl.stateDump = $troubleShootingDump; // Dump of OpenGL state (debug tool, currently unused)
script = $entityState;
script.addShips.failed = $scriptError;
script.missionDescription.noMissionText = inherit;
script.missionDescription.noMissionKey = inherit;
@ -174,8 +178,8 @@ script.debug.processSceneString.addTargetPlanet = inherit;
script.debug.processSceneString.addBillboard = inherit;
script.debug.setSunNovaIn = inherit;
script.debug.note.checkScript = inherit; // Messages saying a scripting method was called, with no further info
script.debug.note.scriptAction = inherit;
script.debug.note = $entityState;
script.debug.note.scriptAction = inherit; // Messages saying a scripting method was called, with no further info
script.debug.note.awardCargo = inherit;
script.debug.note.removeAllCargo = inherit;
script.debug.note.useSpecialCargo = inherit;
@ -202,8 +206,25 @@ script.debug.syntax.addShips = inherit;
script.debug.syntax.set = inherit;
script.debug.syntax.reset = inherit;
script.javascript.compile.success = inherit;
script.javascript.compile.success = no;
script.javascript.compile.failed = $scriptError;
script.javaScript.init.success = no;
script.javaScript.init.error = $error; // Fatal start-up error
script.javaScript.call.badSelector = $scriptError;
script.load.badName = $scriptError;
script.load.notFound = $scriptError;
script.load.parseOK = no;
script.load.unnamed = $scriptError;
script.load.exception = $error;
script.load.world.listAll = no; // List names and versions of all loaded world scripts at startup.
script.plist.run.badTarget = $error;
script.trace = no;
script.trace.runWorld = inherit;
script.trace.plist.run = inherit;
script.trace.javaScript.call = inherit; // Prints selector and parameter string on Player.call()
searchPaths.dumpAll = $troubleShootingDump;

View File

@ -190,22 +190,20 @@
<string>$troubleShootingDump</string>
<key>rendering.opengl.version</key>
<string>$troubleShootingDump</string>
<key>script</key>
<string>$entityState</string>
<key>script.addShips.failed</key>
<string>$scriptError</string>
<key>script.debug</key>
<string>$scriptDebugOn</string>
<key>script.debug.message</key>
<string>inherit</string>
<key>script.debug.note</key>
<string>$entityState</string>
<key>script.debug.note.addPlanet</key>
<string>inherit</string>
<key>script.debug.note.addShips</key>
<string>inherit</string>
<key>script.debug.note.awardCargo</key>
<string>inherit</string>
<key>script.debug.note.checkScript</key>
<string>inherit</string>
<key>script.debug.note.processSceneString</key>
<string>inherit</string>
<key>script.debug.note.removeAllCargo</key>
@ -272,14 +270,42 @@
<string>inherit</string>
<key>script.debug.testCondition.testValues</key>
<string>inherit</string>
<key>script.javaScript.call.badSelector</key>
<string>$scriptError</string>
<key>script.javaScript.init.error</key>
<string>$error</string>
<key>script.javaScript.init.success</key>
<string>no</string>
<key>script.javascript.compile.failed</key>
<string>$scriptError</string>
<key>script.javascript.compile.success</key>
<string>inherit</string>
<string>no</string>
<key>script.load.badName</key>
<string>$scriptError</string>
<key>script.load.exception</key>
<string>$error</string>
<key>script.load.notFound</key>
<string>$scriptError</string>
<key>script.load.parseOK</key>
<string>no</string>
<key>script.load.unnamed</key>
<string>$scriptError</string>
<key>script.load.world.listAll</key>
<string>no</string>
<key>script.missionDescription.noMissionKey</key>
<string>inherit</string>
<key>script.missionDescription.noMissionText</key>
<string>inherit</string>
<key>script.plist.run.badTarget</key>
<string>$error</string>
<key>script.trace</key>
<string>no</string>
<key>script.trace.javaScript.call</key>
<string>inherit</string>
<key>script.trace.plist.run</key>
<string>inherit</string>
<key>script.trace.runWorld</key>
<string>inherit</string>
<key>searchPaths.dumpAll</key>
<string>$troubleShootingDump</string>
<key>sound.channel.cleanup.failed</key>

View File

@ -1,4 +1,10 @@
{
"!metadata!" = {
// NOTE: metadata tagging syntax is not backwards compatible with versions of Oolite prior to 1.68.
version = "Oolite 1.68";
description = "Oolite built-in world scripts.";
};
"thargoid_plans" = (
{
conditions = (

View File

@ -1,6 +1,6 @@
/* Localized versions of Info.plist keys */
CFBundleName = "Oolite";
CFBundleShortVersionString = "Oolite version 1.67.1";
CFBundleGetInfoString = "Oolite version 1.67.1, © 2003-2007 Giles Williams and contributors.";
CFBundleShortVersionString = "Oolite version 1.68";
CFBundleGetInfoString = "Oolite version 1.68, © 2003-2007 Giles Williams and contributors.";
NSHumanReadableCopyright = "Copyright 2003-2007 Giles Williams and contributors.";

View File

@ -48,7 +48,7 @@
<key>CFBundleSignature</key>
<string>Ool8</string>
<key>CFBundleVersion</key>
<string>1.67.1</string>
<string>1.68</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>

View File

@ -48,7 +48,7 @@
<key>CFBundleSignature</key>
<string>Ool8</string>
<key>CFBundleVersion</key>
<string>1.67.1</string>
<string>1.68</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>

View File

@ -48,7 +48,7 @@
<key>CFBundleSignature</key>
<string>Ool8</string>
<key>CFBundleVersion</key>
<string>1.67.1</string>
<string>1.68</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>

View File

@ -2,14 +2,23 @@
// Universe proxy
//===========================================================================
JSClass Universe_class = {
"Universe", JSCLASS_HAS_PRIVATE,
JS_PropertyStub,JS_PropertyStub,JS_PropertyStub,JS_PropertyStub,
JS_EnumerateStub,JS_ResolveStub,JS_ConvertStub,JS_FinalizeStub
static JSClass Universe_class =
{
"Universe",
JSCLASS_HAS_PRIVATE,
JS_PropertyStub,
JS_PropertyStub,
JS_PropertyStub,
JS_PropertyStub,
JS_EnumerateStub,
JS_ResolveStub,
JS_ConvertStub,
JS_FinalizeStub
};
/*
JSBool UniverseGetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
JSBool UniverseGetProperty(JSContext *cx, JSObject *obj, jsval name, jsval *vp);
enum Universe_propertyIds {
UNI_PLAYER_ENTITY
@ -21,30 +30,35 @@ JSPropertySpec Universe_props[] = {
};
*/
JSBool UniverseCheckForShips(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
JSBool UniverseAddShips(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
JSBool UniverseAddSystemShips(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
JSBool UniverseAddShipsAt(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
JSBool UniverseAddShipsAtPrecisely(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
JSBool UniverseAddShipsWithinRadius(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
JSBool UniverseSpawn(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
JSBool UniverseSpawnShip(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
JSFunctionSpec Universe_funcs[] = {
{ "CheckForShips", UniverseCheckForShips, 1, 0 },
{ "AddShips", UniverseAddShips, 2, 0 },
{ "AddSystemShips", UniverseAddSystemShips, 3, 0 },
{ "AddShipsAt", UniverseAddShipsAt, 6, 0 },
{ "AddShipsAtPrecisely", UniverseAddShipsAtPrecisely, 6, 0 },
{ "AddShipsWithinRadius", UniverseAddShipsWithinRadius, 7, 0 },
{ "Spawn", UniverseSpawn, 2, 0 },
{ "SpawnShip", UniverseSpawnShip, 1, 0 },
static JSBool UniverseCountShipsWithRole(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool UniverseAddShips(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool UniverseAddSystemShips(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool UniverseAddShipsAt(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool UniverseAddShipsAtPrecisely(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool UniverseAddShipsWithinRadius(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool UniverseSpawn(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSBool UniverseSpawnShip(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
static JSFunctionSpec Universe_funcs[] =
{
{ "countShipsWithRole", UniverseCountShipsWithRole, 1, 0 },
{ "addShips", UniverseAddShips, 2, 0 },
{ "addSystemShips", UniverseAddSystemShips, 3, 0 },
{ "addShipsAt", UniverseAddShipsAt, 6, 0 },
{ "addShipsAtPrecisely", UniverseAddShipsAtPrecisely, 6, 0 },
{ "addShipsWithinRadius", UniverseAddShipsWithinRadius, 7, 0 },
{ "spawn", UniverseSpawn, 2, 0 },
{ "spawnShip", UniverseSpawnShip, 1, 0 },
{ 0 }
};
JSBool UniverseCheckForShips(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) {
if (argc == 1) {
// PlayerEntity *playerEntity = [PlayerEntity sharedPlayer];
static JSBool UniverseCountShipsWithRole(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
if (argc == 1)
{
NSString *role = JSValToNSString(cx, argv[0]);
int num = [[Universe sharedUniverse] countShipsWithRole:role];
*rval = INT_TO_JSVAL(num);
@ -52,9 +66,11 @@ JSBool UniverseCheckForShips(JSContext *cx, JSObject *obj, uintN argc, jsval *ar
return JS_TRUE;
}
JSBool UniverseAddShips(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) {
if (argc == 2) {
// PlayerEntity *playerEntity = [PlayerEntity sharedPlayer];
static JSBool UniverseAddShips(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
if (argc == 2)
{
NSString *role = JSValToNSString(cx, argv[0]);
int num = JSVAL_TO_INT(argv[1]);
@ -64,10 +80,12 @@ JSBool UniverseAddShips(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, j
return JS_TRUE;
}
JSBool UniverseAddSystemShips(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) {
if (argc == 3) {
static JSBool UniverseAddSystemShips(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
if (argc == 3)
{
jsdouble posn;
// PlayerEntity *playerEntity = [PlayerEntity sharedPlayer];
NSString *role = JSValToNSString(cx, argv[0]);
int num = JSVAL_TO_INT(argv[1]);
JS_ValueToNumber(cx, argv[2], &posn);
@ -77,8 +95,11 @@ JSBool UniverseAddSystemShips(JSContext *cx, JSObject *obj, uintN argc, jsval *a
return JS_TRUE;
}
JSBool UniverseAddShipsAt(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) {
if (argc == 6) {
static JSBool UniverseAddShipsAt(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
if (argc == 6)
{
jsdouble x, y, z;
PlayerEntity *playerEntity = [PlayerEntity sharedPlayer];
NSString *role = JSValToNSString(cx, argv[0]);
@ -93,8 +114,11 @@ JSBool UniverseAddShipsAt(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
return JS_TRUE;
}
JSBool UniverseAddShipsAtPrecisely(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) {
if (argc == 6) {
static JSBool UniverseAddShipsAtPrecisely(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
if (argc == 6)
{
jsdouble x, y, z;
PlayerEntity *playerEntity = [PlayerEntity sharedPlayer];
NSString *role = JSValToNSString(cx, argv[0]);
@ -109,8 +133,11 @@ JSBool UniverseAddShipsAtPrecisely(JSContext *cx, JSObject *obj, uintN argc, jsv
return JS_TRUE;
}
JSBool UniverseAddShipsWithinRadius(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) {
if (argc == 7) {
static JSBool UniverseAddShipsWithinRadius(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
if (argc == 7)
{
jsdouble x, y, z;
PlayerEntity *playerEntity = [PlayerEntity sharedPlayer];
NSString *role = JSValToNSString(cx, argv[0]);
@ -126,8 +153,11 @@ JSBool UniverseAddShipsWithinRadius(JSContext *cx, JSObject *obj, uintN argc, js
return JS_TRUE;
}
JSBool UniverseSpawn(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) {
if (argc == 2) {
static JSBool UniverseSpawn(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
if (argc == 2)
{
PlayerEntity *playerEntity = [PlayerEntity sharedPlayer];
NSString *role = JSValToNSString(cx, argv[0]);
int num = JSVAL_TO_INT(argv[1]);
@ -137,8 +167,11 @@ JSBool UniverseSpawn(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsva
return JS_TRUE;
}
JSBool UniverseSpawnShip(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) {
if (argc == 1) {
static JSBool UniverseSpawnShip(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
if (argc == 1)
{
PlayerEntity *playerEntity = [PlayerEntity sharedPlayer];
[playerEntity spawnShip:JSValToNSString(cx, argv[0])];
}
@ -146,38 +179,37 @@ JSBool UniverseSpawnShip(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
}
JSBool UniverseAddMessage(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) {
/*static JSBool UniverseAddMessage(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
JSBool ok;
int32 count;
if (argc != 2)
return JS_FALSE;
if (argc != 2) return JS_FALSE;
ok = JS_ValueToInt32(cx, argv[1], &count);
NSString *str = JSValToNSString(cx, argv[0]);
[[Universe sharedUniverse] addMessage: str forCount:(int)count];
//[str dealloc];
return JS_TRUE;
}
JSBool UniverseAddCommsMessage(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) {
static JSBool UniverseAddCommsMessage(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
JSBool ok;
int32 count;
if (argc != 2)
return JS_FALSE;
if (argc != 2) return JS_FALSE;
ok = JS_ValueToInt32(cx, argv[1], &count);
NSString *str = JSValToNSString(cx, argv[0]);
[[Universe sharedUniverse] addCommsMessage: str forCount:(int)count];
//[str dealloc];
return JS_TRUE;
}
}*/
/*
JSBool UniverseGetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) {
if (JSVAL_IS_INT(id)) {
JSBool UniverseGetProperty(JSContext *cx, JSObject *obj, jsval name, jsval *vp) {
if (JSVAL_IS_INT(name)) {
PlayerEntity *playerEntity = [PlayerEntity sharedPlayer];
switch (JSVAL_TO_INT(id)) {
switch (JSVAL_TO_INT(name)) {
case UNI_PLAYER_ENTITY: {
JSObject *pe = JS_DefineObject(cx, universeObj, "PlayerEntity", &PlayerEntity_class, 0x00, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT);
if (pe == 0x00) {

View File

@ -1,6 +1,6 @@
/*
OXPScript.h
OOJSScript.h
JavaScript support for Oolite
Copyright (C) 2007 David Taylor
@ -22,13 +22,16 @@ MA 02110-1301, USA.
*/
#ifndef OXPSCRIPT_H_SEEN
#define OXPSCRIPT_H_SEEN
#ifndef OOJSSCRIPT_H_USED
#error OXPScript.h is deprecated, use OOJSScript.h.
#endif
#include <Foundation/Foundation.h>
#include "OOScript.h"
#include <jsapi.h>
@interface OXPScript : NSObject
@interface OOJSScript : OOScript
{
JSContext *cx;
JSObject *obj;
@ -38,16 +41,10 @@ MA 02110-1301, USA.
NSString *version;
}
- (id) initWithContext: (JSContext *) context andFilename: (NSString *) filename;
+ (id)scriptWithPath:(NSString *)path;
- (NSString *) name;
- (NSString *) description;
- (NSString *) version;
- (BOOL) doEvent: (NSString *) eventName;
- (BOOL) doEvent: (NSString *) eventName withIntegerArgument:(int)argument;
- (BOOL) doEvent: (NSString *) eventName withStringArgument:(NSString *)argument;
- (id)initWithPath:(NSString *)path;
- (id)initWithPath:(NSString *)path andContext:(JSContext *)context;
@end
#endif

View File

@ -1,6 +1,6 @@
/*
OXPScript.m
OOJSScript.m
JavaScript support for Oolite
Copyright (C) 2007 David Taylor
@ -22,60 +22,96 @@ MA 02110-1301, USA.
*/
#import "OXPScript.h"
#import "OOJSScript.h"
#import "OOLogging.h"
#import "OOConstToString.h"
#import "Entity.h"
#import "OOJavaScriptEngine.h"
OXPScript *currentOXPScript;
OOJSScript *currentOOJSScript;
JSClass OXP_class = {
"OXPScript", JSCLASS_HAS_PRIVATE,
JS_PropertyStub,JS_PropertyStub,JS_PropertyStub,JS_PropertyStub,
JS_EnumerateStub,JS_ResolveStub,JS_ConvertStub,JS_FinalizeStub
JSClass script_class =
{
"JSScript",
JSCLASS_HAS_PRIVATE,
JS_PropertyStub,
JS_PropertyStub,
JS_PropertyStub,
JS_PropertyStub,
JS_EnumerateStub,
JS_ResolveStub,
JS_ConvertStub,
JS_FinalizeStub
};
extern NSString *JSValToNSString(JSContext *cx, jsval val);
@implementation OXPScript
#define JSValToNSString(cx, val) [NSString stringWithJavaScriptValue:val inContext:cx]
- (id) initWithContext: (JSContext *) context andFilename: (NSString *) filename
@interface OOJSScript (OOPrivate)
- (NSString *)scriptNameFromPath:(NSString *)path;
@end
@implementation OOJSScript
+ (id)scriptWithPath:(NSString *)path
{
// Check if file exists before doing anything else
// ...
return [[[self alloc] initWithPath:path] autorelease];
}
- (id)initWithPath:(NSString *)path
{
return [self initWithPath:path andContext:[[OOJavaScriptEngine sharedEngine] context]];
}
- (id)initWithPath:(NSString *)path andContext:(JSContext *)context
{
self = [super init];
obj = JS_NewObject(context, &OXP_class, 0x00, JS_GetGlobalObject(context));
obj = JS_NewObject(context, &script_class, 0x00, JS_GetGlobalObject(context));
JS_AddRoot(context, &obj); // note 2nd arg is a pointer-to-pointer
cx = context;
jsval rval;
JSBool ok;
JSScript *script = JS_CompileFile(context, obj, [filename cString]);
if (script != NULL) {
JSScript *script = JS_CompileFile(context, obj, [path fileSystemRepresentation]);
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);
} else {
// No name given in the script so use the filename
name = [NSString stringWithString:filename];
if (ok)
{
ok = JS_GetProperty(context, obj, "name", &rval);
if (ok && !JSVAL_IS_VOID(rval))
{
name = [[NSString stringWithJavaScriptValue:rval inContext:context] retain];
}
ok = JS_GetProperty(context, obj, "Description", &rval);
if (ok) {
description = JSValToNSString(context, rval);
} else {
description = @"";
else
{
// No name given in the script so use the file name
name = [[self scriptNameFromPath:path] retain];
}
ok = JS_GetProperty(context, obj, "Version", &rval);
if (ok) {
version = JSValToNSString(context, rval);
} else {
version= @"";
ok = JS_GetProperty(context, obj, "description", &rval);
if (ok && !JSVAL_IS_VOID(rval))
{
description = [[NSString stringWithJavaScriptValue:rval inContext:context] retain];
}
OOLog(@"script.javascript.compile.success", @"Loaded JavaScript OXP: %@ %@ %@", name, description, version);
ok = JS_GetProperty(context, obj, "version", &rval);
if (ok && !JSVAL_IS_VOID(rval))
{
version = [[NSString stringWithJavaScriptValue:rval inContext:context] retain];
}
OOLog(@"script.javaScript.compile.success", @"Loaded JavaScript OXP: %@ -- %@", [self displayName], description ? description : @"(no description)");
/*
* Example code to read the mission variables.
@ -105,8 +141,10 @@ extern NSString *JSValToNSString(JSContext *cx, jsval val);
*/
}
JS_DestroyScript(context, script);
} else {
OOLog(@"script.javascript.compile.failed", @"Script compilation failed");
}
else
{
OOLog(@"script.javaScript.compile.failed", @"Failed to compile JavaScript script %@", path);
[self release];
return nil;
}
@ -119,7 +157,7 @@ extern NSString *JSValToNSString(JSContext *cx, jsval val);
return name;
}
- (NSString *) description
- (NSString *) scriptDescription
{
return description;
}
@ -129,6 +167,11 @@ extern NSString *JSValToNSString(JSContext *cx, jsval val);
return version;
}
- (void)runWithTarget:(Entity *)target
{
[self doEvent:@"tickle" withStringArgument:[[PlayerEntity sharedPlayer] status_string]];
}
- (BOOL) doEvent: (NSString *) eventName
{
jsval rval;
@ -138,7 +181,7 @@ extern NSString *JSValToNSString(JSContext *cx, jsval val);
if (ok && !JSVAL_IS_VOID(rval)) {
JSFunction *func = JS_ValueToFunction(cx, rval);
if (func != 0x00) {
currentOXPScript = self;
currentOOJSScript = self;
ok = JS_CallFunction(cx, obj, func, 0, 0x00, &rval);
if (ok)
return YES;
@ -157,7 +200,7 @@ extern NSString *JSValToNSString(JSContext *cx, jsval val);
if (ok && !JSVAL_IS_VOID(rval)) {
JSFunction *func = JS_ValueToFunction(cx, rval);
if (func != 0x00) {
currentOXPScript = self;
currentOOJSScript = self;
jsval args[1];
args[0] = INT_TO_JSVAL(argument);
ok = JS_CallFunction(cx, obj, func, 1, args, &rval);
@ -178,8 +221,10 @@ extern NSString *JSValToNSString(JSContext *cx, jsval val);
if (ok && !JSVAL_IS_VOID(rval)) {
JSFunction *func = JS_ValueToFunction(cx, rval);
if (func != 0x00) {
currentOXPScript = self;
ok = JS_CallFunction(cx, obj, func, 0, 0x00, &rval);
currentOOJSScript = self;
jsval args[1];
args[0] = [argument javaScriptValueInContext:cx];
ok = JS_CallFunction(cx, obj, func, 1, args, &rval);
if (ok)
return YES;
}
@ -188,4 +233,52 @@ extern NSString *JSValToNSString(JSContext *cx, jsval val);
return NO;
}
/* Generate default name for script which doesn't set its name property when
first run.
The generated name is <name>.anon-script, where <name> is selected as
follows:
* If path is nil (futureproofing), use the address of the script object.
* If the file's name is something other than script.*, use the file name.
* If the containing directory is something other than Config, use the
containing directory's name.
* Otherwise, use the containing directory's parent (which will generally
be an OXP root directory).
* If either of the two previous steps results in an empty string, fall
back on the full path.
*/
- (NSString *)scriptNameFromPath:(NSString *)path
{
NSString *lastComponent = nil;
NSString *truncatedPath = nil;
NSString *theName = nil;
if (path == nil) theName = [NSString stringWithFormat:@"%p", self];
else
{
lastComponent = [path lastPathComponent];
if (![lastComponent hasPrefix:@"script."]) theName = lastComponent;
else
{
truncatedPath = [path stringByDeletingLastPathComponent];
if (NSOrderedSame == [[truncatedPath lastPathComponent] caseInsensitiveCompare:@"Config"])
{
truncatedPath = [truncatedPath stringByDeletingLastPathComponent];
}
if (NSOrderedSame == [[truncatedPath pathExtension] caseInsensitiveCompare:@"oxp"])
{
truncatedPath = [truncatedPath stringByDeletingPathExtension];
}
lastComponent = [truncatedPath lastPathComponent];
theName = lastComponent;
}
}
if (0 == [theName length]) theName = path;
return [theName stringByAppendingString:@".anon-script"];
}
@end

View File

@ -1,6 +1,6 @@
/*
ScriptEngine.h
OOJavaScriptEngine.h
JavaScript support for Oolite
Copyright (C) 2007 David Taylor
@ -22,8 +22,10 @@ MA 02110-1301, USA.
*/
#ifndef SCRIPTENGINE_H_SEEN
#define SCRIPTENGINE_H_SEEN
#ifndef OOJAVASCRIPTENGINE_H_USED
#error ScriptEngine.h is deprecated, use OOJavaScriptEngine.h.
#endif
#import <Foundation/Foundation.h>
#import "Universe.h"
@ -31,7 +33,7 @@ MA 02110-1301, USA.
#import "PlayerEntityScripting.h"
#import <jsapi.h>
@interface ScriptEngine : NSObject
@interface OOJavaScriptEngine : NSObject
{
JSRuntime *rt;
JSContext *cx;
@ -39,11 +41,34 @@ MA 02110-1301, USA.
JSBool builtins;
}
- (id) initWithUniverse: (Universe *) universe;
- (void) dealloc;
+ (OOJavaScriptEngine *)sharedEngine;
- (JSContext *) context;
@end
#endif
@protocol OOJavaScriptConversion <NSObject>
- (jsval)javaScriptValueInContext:(JSContext *)context;
@end
@interface NSString (OOJavaScriptExtensions) <OOJavaScriptConversion>
// Convert a JSString to an NSString.
+ (id)stringWithJavaScriptString:(JSString *)string;
// Convert an arbitrary JS object to an NSString, using JS_ValueToString.
+ (id)stringWithJavaScriptValue:(jsval)value inContext:(JSContext *)context;
// Concatenate sequence of arbitrary JS objects into string.
+ (id)concatenationOfStringsFromJavaScriptValues:(jsval *)values count:(size_t)count separator:(NSString *)separator inContext:(JSContext *)context;
@end
@interface NSNumber (OOJavaScriptExtensions) <OOJavaScriptConversion>
@end

File diff suppressed because it is too large Load Diff

View File

@ -30,6 +30,9 @@ MA 02110-1301, USA.
#import <Foundation/Foundation.h>
BOOL EvaluateAsBoolean(id object, BOOL defaultValue);
@interface NSArray (OOExtractor)
- (char)charAtIndex:(unsigned)index defaultValue:(char)value;

View File

@ -23,7 +23,39 @@ MA 02110-1301, USA.
*/
#import "OOCollectionExtractors.h"
#import <limits.h>
BOOL EvaluateAsBoolean(id object, BOOL defaultValue)
{
BOOL result = defaultValue;
if ([object isKindOfClass:[NSString class]])
{
// This is here because A. [NSString boolValue] exists, but is not documented; and B. we want to return the default value (rather than NO) if the string doesn't make sense as a boolean.
if (NSOrderedSame == [object caseInsensitiveCompare:@"yes"] ||
NSOrderedSame == [object caseInsensitiveCompare:@"true"] ||
NSOrderedSame == [object caseInsensitiveCompare:@"on"] ||
[object intValue] != 0)
{
result = YES;
}
else if (NSOrderedSame == [object caseInsensitiveCompare:@"no"] ||
NSOrderedSame == [object caseInsensitiveCompare:@"false"] ||
NSOrderedSame == [object caseInsensitiveCompare:@"off"] ||
NSOrderedSame == [object caseInsensitiveCompare:@"0"] ||
NSOrderedSame == [object caseInsensitiveCompare:@"-0"])
{
result = NO;
}
}
else if ([object respondsToSelector:@selector(boolValue)]) result = [object boolValue];
else if ([object respondsToSelector:@selector(intValue)])
{
result = [object intValue] != 0;
}
return result;
}
@implementation NSArray (OOExtractor)
@ -208,32 +240,7 @@ MA 02110-1301, USA.
id objVal = [self objectAtIndex:index];
BOOL result;
if ([objVal isKindOfClass:[NSString class]])
{
// This is here because A. [NSString boolValue] exists, but is not documented; and B. we want to return the default value (rather than NO) if the string doesn't make sense as a boolean.
if (NSOrderedSame == [objVal caseInsensitiveCompare:@"yes"] ||
NSOrderedSame == [objVal caseInsensitiveCompare:@"true"] ||
NSOrderedSame == [objVal caseInsensitiveCompare:@"on"] ||
[objVal intValue] != 0)
{
result = YES;
}
else if (NSOrderedSame == [objVal caseInsensitiveCompare:@"no"] ||
NSOrderedSame == [objVal caseInsensitiveCompare:@"false"] ||
NSOrderedSame == [objVal caseInsensitiveCompare:@"off"] ||
NSOrderedSame == [objVal caseInsensitiveCompare:@"0"] ||
NSOrderedSame == [objVal caseInsensitiveCompare:@"-0"])
{
result = NO;
}
else result = value;
}
else if ([objVal respondsToSelector:@selector(boolValue)]) result = [objVal boolValue];
else if ([objVal respondsToSelector:@selector(intValue)])
{
result = [objVal intValue] != 0;
}
else result = value;
result = EvaluateAsBoolean(objVal, value);
return result;
}
@ -475,32 +482,7 @@ MA 02110-1301, USA.
id objVal = [self objectForKey:key];
BOOL result;
if ([objVal isKindOfClass:[NSString class]])
{
// This is here because A. [NSString boolValue] exists, but is not documented; and B. we want to return the default value (rather than NO) if the string doesn't make sense as a boolean.
if (NSOrderedSame == [objVal caseInsensitiveCompare:@"yes"] ||
NSOrderedSame == [objVal caseInsensitiveCompare:@"true"] ||
NSOrderedSame == [objVal caseInsensitiveCompare:@"on"] ||
[objVal intValue] != 0)
{
result = YES;
}
else if (NSOrderedSame == [objVal caseInsensitiveCompare:@"no"] ||
NSOrderedSame == [objVal caseInsensitiveCompare:@"false"] ||
NSOrderedSame == [objVal caseInsensitiveCompare:@"off"] ||
NSOrderedSame == [objVal caseInsensitiveCompare:@"0"] ||
NSOrderedSame == [objVal caseInsensitiveCompare:@"-0"])
{
result = NO;
}
else result = value;
}
else if ([objVal respondsToSelector:@selector(boolValue)]) result = [objVal boolValue];
else if ([objVal respondsToSelector:@selector(intValue)])
{
result = [objVal intValue] != 0;
}
else result = value;
result = EvaluateAsBoolean(objVal, value);
return result;
}
@ -557,4 +539,4 @@ MA 02110-1301, USA.
return result;
}
@end
@end

View File

@ -0,0 +1,35 @@
/*
OOConstToString.h
Oolite
Copyright (C) 2004-2007 Giles C Williams and contributors
Convert various sets of integer constants to strings.
To consider: replacing the integer constants with string constants.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
*/
#import <Foundation/Foundation.h>
// STATUS_ACTIVE, STATUS_DOCKING and so forth
NSString *EntityStatusToString(int status);
// CLASS_STATION, CLASS_MISSILE and so forth
NSString *ScanClassToString(int scanClass);

View File

@ -0,0 +1,84 @@
/*
OOConstToString.m
Oolite
Copyright (C) 2004-2007 Giles C Williams and contributors
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version );
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., ); Franklin Street, Fifth Floor, Boston,
MA );-);, USA.
*/
#import "OOConstToString.h"
#import "Entity.h"
#define CASE(foo) case foo: return @#foo;
NSString *EntityStatusToString(int status)
{
switch (status)
{
CASE(STATUS_EXPERIMENTAL);
CASE(STATUS_EFFECT);
CASE(STATUS_ACTIVE);
CASE(STATUS_COCKPIT_DISPLAY);
CASE(STATUS_TEST);
CASE(STATUS_INACTIVE);
CASE(STATUS_DEAD);
CASE(STATUS_START_GAME);
CASE(STATUS_IN_FLIGHT);
CASE(STATUS_DOCKED);
CASE(STATUS_AUTOPILOT_ENGAGED);
CASE(STATUS_DOCKING);
CASE(STATUS_LAUNCHING);
CASE(STATUS_WITCHSPACE_COUNTDOWN);
CASE(STATUS_ENTERING_WITCHSPACE);
CASE(STATUS_EXITING_WITCHSPACE);
CASE(STATUS_ESCAPE_SEQUENCE);
CASE(STATUS_IN_HOLD);
CASE(STATUS_BEING_SCOOPED);
CASE(STATUS_HANDLING_ERROR);
default: return @"UNDEFINED";
}
}
NSString *ScanClassToString(int scanClass)
{
switch (scanClass)
{
CASE(CLASS_NOT_SET);
CASE(CLASS_NO_DRAW);
CASE(CLASS_NEUTRAL);
CASE(CLASS_STATION);
CASE(CLASS_TARGET);
CASE(CLASS_CARGO);
CASE(CLASS_MISSILE);
CASE(CLASS_ROCK);
CASE(CLASS_MINE);
CASE(CLASS_THARGOID);
CASE(CLASS_BUOY);
CASE(CLASS_WORMHOLE);
CASE(CLASS_PLAYER);
CASE(CLASS_POLICE);
CASE(CLASS_MILITARY);
default: return @"UNDEFINED";
}
}

View File

@ -704,6 +704,8 @@ enum
/* -- */
- (void) sendMessageToScripts:(NSString *)message;
- (void) sendMessageToScripts:(NSString *)message withString:(NSString *)argument;
- (void) sendMessageToScripts:(NSString *)message withInteger:(int)argument;
- (BOOL)showInfoFlag;

View File

@ -46,10 +46,11 @@ MA 02110-1301, USA.
#import "OOSound.h"
#import "OOColor.h"
#import "OOCacheManager.h"
#import "OXPScript.h"
#import "OOStringParsing.h"
#import "OOPListParsing.h"
#import "OOScript.h"
#ifndef GNUSTEP
#import "Groolite.h"
#else
@ -951,6 +952,8 @@ static PlayerEntity *sSharedPlayer = nil;
dockingReport = [[NSMutableString string] retain];
script = [[ResourceManager loadScripts] retain];
return self;
}
@ -977,13 +980,12 @@ static PlayerEntity *sSharedPlayer = nil;
[hud resizeGuis:huddict];
scanner_zoom_rate = 0.0;
script = [[ResourceManager loadScripts] retain];
mission_variables =[[NSMutableDictionary dictionaryWithCapacity:16] retain];
local_variables =[[NSMutableDictionary dictionaryWithCapacity:[script count]] retain];
NSArray *scriptKeys = [script allKeys];
for (i = 0; i < [scriptKeys count]; i++)
[local_variables setObject:[NSMutableDictionary dictionaryWithCapacity:16] forKey:[scriptKeys objectAtIndex:i]];
[self setScript_target:nil];
[self resetMissionChoice];
@ -1208,6 +1210,8 @@ static PlayerEntity *sSharedPlayer = nil;
scoopsActive = NO;
[dockingReport setString:@""];
[self sendMessageToScripts:@"reset"];
}
- (void) setUpShipFromDictionary:(NSDictionary *) dict
@ -1715,6 +1719,7 @@ double scoopSoundPlayTime = 0.0;
// next check in 10s
status = STATUS_IN_FLIGHT;
[self sendMessageToScripts:@"didLaunch"];
}
}
@ -1740,6 +1745,7 @@ double scoopSoundPlayTime = 0.0;
if (![universe playCustomSound:@"[witch-blocked-by-@]"])
[witchAbortSound play];
status = STATUS_IN_FLIGHT;
[self sendMessageToScripts:@"didFailToJump" withString:@"blocked"];
go = NO;
}
@ -1755,6 +1761,7 @@ double scoopSoundPlayTime = 0.0;
if (![universe playCustomSound:@"[witch-too-far]"])
[witchAbortSound play];
status = STATUS_IN_FLIGHT;
[self sendMessageToScripts:@"didFailToJump" withString:@"too far"];
go = NO;
}
}
@ -1770,6 +1777,7 @@ double scoopSoundPlayTime = 0.0;
if (![universe playCustomSound:@"[witch-no-fuel]"])
[witchAbortSound play];
status = STATUS_IN_FLIGHT;
[self sendMessageToScripts:@"didFailToJump" withString:@"insufficient fuel"];
go = NO;
}
@ -1802,6 +1810,7 @@ double scoopSoundPlayTime = 0.0;
[universe addMessage:ExpandDescriptionForCurrentSystem(@"[witch-engine-malfunction]") forCount:3.0];
status = STATUS_IN_FLIGHT;
[self sendMessageToScripts:@"didExitWitchSpace"];
}
}
@ -2838,7 +2847,7 @@ double scoopSoundPlayTime = 0.0;
}
if (alert_condition != old_alert_condition)
[self sendMessageToScripts:@"AlertConditionChanged"];
[self sendMessageToScripts:@"alertConditionChanged"];
return alert_condition;
}
@ -2882,6 +2891,7 @@ double scoopSoundPlayTime = 0.0;
[[universe gameController] playiTunesPlaylist:@"Oolite-Inflight"];
docking_music_on = NO;
}
[self sendMessageToScripts:@"didRecieveDockingRefusal"];
}
// aegis messages to advanced compass so in planet mode it behaves like the old compass
@ -3481,6 +3491,8 @@ double scoopSoundPlayTime = 0.0;
energy = 25;
[universe addMessage:ExpandDescriptionForCurrentSystem(@"[escape-sequence]") forCount:4.5];
shot_time = 0.0;
[self sendMessageToScripts:@"didLaunchEscapePod"];
return result;
}
@ -3699,6 +3711,7 @@ double scoopSoundPlayTime = 0.0;
[universe displayMessage:@"Press Space" forCount:30.0];
shot_time = 0.0;
[self sendMessageToScripts:@"didBecomeDead"];
[self loseTargetStatus];
}
@ -3734,6 +3747,7 @@ double scoopSoundPlayTime = 0.0;
return;
status = STATUS_DOCKING;
[self sendMessageToScripts:@"willDock"];
afterburner_engaged = NO;
@ -3839,6 +3853,8 @@ double scoopSoundPlayTime = 0.0;
}
[[OOCacheManager sharedCache] flush];
[self sendMessageToScripts:@"didDock"];
}
- (void) leaveDock:(StationEntity *)station
@ -3885,6 +3901,7 @@ double scoopSoundPlayTime = 0.0;
- (void) enterGalacticWitchspace
{
status = STATUS_ENTERING_WITCHSPACE;
[self sendMessageToScripts:@"willEnterWitchSpace" withString:@"galactic jump"];
if (primaryTarget != NO_TARGET)
primaryTarget = NO_TARGET;
@ -3954,6 +3971,7 @@ double scoopSoundPlayTime = 0.0;
{
target_system_seed = [w_hole destination];
status = STATUS_ENTERING_WITCHSPACE;
[self sendMessageToScripts:@"willEnterWitchSpace" withString:@"wormhole"];
hyperspeed_engaged = NO;
@ -3998,6 +4016,7 @@ double scoopSoundPlayTime = 0.0;
double distance = distanceBetweenPlanetPositions(target_system_seed.d,target_system_seed.b,galaxy_coordinates.x,galaxy_coordinates.y);
status = STATUS_ENTERING_WITCHSPACE;
[self sendMessageToScripts:@"willEnterWitchSpace" withString:@"standard jump"];
hyperspeed_engaged = NO;
@ -4107,10 +4126,12 @@ double scoopSoundPlayTime = 0.0;
[universe setDisplayText:NO];
[universe set_up_break_pattern:position quaternion:q_rotation];
[self playBreakPattern];
[self sendMessageToScripts:@"willExitWitchSpace"];
}
- (void) performDocking
{
// Huh? What is this? Doesn't seem to get called. -- ahruman
[self abortDocking]; // let the station know that you are no longer on approach
autopilot_engaged = NO;
status = STATUS_IN_FLIGHT;
@ -6752,19 +6773,36 @@ OOSound* burnersound;
- (void) sendMessageToScripts:(NSString *)message
{
int i;
if (oxpKeys == nil)
oxpKeys = [[NSMutableDictionary alloc] init];
for (i = 0; i < [[script allKeys] count]; i++)
NSEnumerator *scriptEnum;
OOScript *theScript;
for (scriptEnum = [script objectEnumerator]; (theScript = [scriptEnum nextObject]); )
{
NSString *missionTitle = (NSString *)[[script allKeys] objectAtIndex:i];
id obj = [script objectForKey:missionTitle];
if ([obj isKindOfClass:[OXPScript class]])
{
OXPScript *jscript = (OXPScript *)obj;
[jscript doEvent:message];
}
[theScript doEvent:message];
}
}
- (void) sendMessageToScripts:(NSString *)message withString:(NSString *)argument
{
NSEnumerator *scriptEnum;
OOScript *theScript;
for (scriptEnum = [script objectEnumerator]; (theScript = [scriptEnum nextObject]); )
{
[theScript doEvent:message withStringArgument:argument];
}
}
- (void) sendMessageToScripts:(NSString *)message withInteger:(int)argument
{
NSEnumerator *scriptEnum;
OOScript *theScript;
for (scriptEnum = [script objectEnumerator]; (theScript = [scriptEnum nextObject]); )
{
[theScript doEvent:message withIntegerArgument:argument];
}
}

View File

@ -605,6 +605,7 @@ static NSTimeInterval time_last_frame;
if (![universe playCustomSound:@"[autopilot-on]"])
[self beep];
[universe addMessage:ExpandDescriptionForCurrentSystem(@"[autopilot-on]") forCount:4.5];
[self sendMessageToScripts:@"didStartAutoPilot"];
//
if (ootunes_on)
{
@ -647,6 +648,7 @@ static NSTimeInterval time_last_frame;
if (![universe playCustomSound:@"[autopilot-on]"])
[self beep];
[universe addMessage:ExpandDescriptionForCurrentSystem(@"[autopilot-on]") forCount:4.5];
[self sendMessageToScripts:@"didStartAutoPilot"];
//
if (ootunes_on)
{
@ -774,6 +776,8 @@ static NSTimeInterval time_last_frame;
// say it!
[universe clearPreviousMessage];
[universe addMessage:ExpandDescriptionForCurrentSystem(@"[witch-user-abort]") forCount:3.0];
[self sendMessageToScripts:@"didCancelJumpCountDown"];
}
if (jumpOK)
@ -786,6 +790,8 @@ static NSTimeInterval time_last_frame;
// say it!
[universe clearPreviousMessage];
[universe addMessage:[NSString stringWithFormat:ExpandDescriptionForCurrentSystem(@"[witch-to-@-in-f-seconds]"), [universe getSystemName:target_system_seed], witchspaceCountdown] forCount:1.0];
[self sendMessageToScripts:@"didBeginJumpCountDown"withString:@"standard"];
}
}
hyperspace_pressed = YES;
@ -820,6 +826,8 @@ static NSTimeInterval time_last_frame;
// say it!
[universe clearPreviousMessage];
[universe addMessage:ExpandDescriptionForCurrentSystem(@"[witch-user-abort]") forCount:3.0];
[self sendMessageToScripts:@"didCancelJumpCountDown"];
}
if (jumpOK)
@ -832,6 +840,8 @@ static NSTimeInterval time_last_frame;
[self beep];
// say it!
[universe addMessage:[NSString stringWithFormat:ExpandDescriptionForCurrentSystem(@"[witch-galactic-in-f-seconds]"), witchspaceCountdown] forCount:1.0];
[self sendMessageToScripts:@"didBeginJumpCountDown" withString:@"galactic"];
}
}
galhyperspace_pressed = YES;
@ -2430,6 +2440,7 @@ static BOOL toggling_music;
if (![universe playCustomSound:@"[autopilot-off]"])
[self beep];
[universe addMessage:ExpandDescriptionForCurrentSystem(@"[autopilot-off]") forCount:4.5];
[self sendMessageToScripts:@"didAbortAutoPilot"];
//
if (ootunes_on)
{

View File

@ -36,13 +36,15 @@ MA 02110-1301, USA.
#define COMPARISON_UNDEFINED 010
@class OXPScript;
@class OOScript;
@interface PlayerEntity (Scripting)
- (void) checkScript;
- (void) scriptActions:(NSArray*) some_actions forTarget:(ShipEntity*) a_target;
- (void)runScript:(NSArray*)scriptActions withName:(NSString *)scriptName forTarget:(ShipEntity *)target; // Hook for OOPListScript
- (BOOL) checkCouplet:(NSDictionary *) couplet onEntity:(Entity *) entity;
- (void) scriptAction:(NSString *) scriptAction onEntity:(Entity *) entity;
- (BOOL) scriptTestCondition:(NSString *) scriptCondition;
@ -197,7 +199,7 @@ MA 02110-1301, USA.
- (void) playSound:(NSString *) soundName;
- (BOOL) mapKey:(NSString *) keycode toOXP:(OXPScript *)oxp;
- (BOOL) mapKey:(NSString *) keycode toOXP:(OOScript *)oxp;
- (void) targetNearestHostile;
/*-----------------------------------------------------*/

View File

@ -29,10 +29,11 @@ MA 02110-1301, USA.
#import "TextureStore.h"
#import "AI.h"
#import "ShipEntityAI.h"
#import "OXPScript.h"
#import "OOScript.h"
#import "OOSound.h"
#import "OOColor.h"
#import "OOStringParsing.h"
#import "OOConstToString.h"
#import "PlanetEntity.h"
#import "ParticleEntity.h"
@ -50,7 +51,7 @@ static NSString * const kOOLogScriptMissionDescNoKey = @"script.missionDescript
static NSString * const kOOLogDebug = @"script.debug";
static NSString * const kOOLogDebugOnMetaClass = @"$scriptDebugOn";
static NSString * const kOOLogDebugMessage = @"script.debug.message";
NSString * const kOOLogDebugMessage = @"script.debug.message";
static NSString * const kOOLogDebugOnOff = @"script.debug.onOff";
static NSString * const kOOLogDebugTestConditionCheckingVariable = @"script.debug.testCondition.checkingVariable";
static NSString * const kOOLogDebugTestConditionValues = @"script.debug.testCondition.testValues";
@ -64,7 +65,6 @@ static NSString * const kOOLogDebugProcessSceneStringAddTargetPlanet = @"script.
static NSString * const kOOLogDebugProcessSceneStringAddBillboard = @"script.debug.processSceneString.addBillboard";
static NSString * const kOOLogDebugSetSunNovaIn = @"script.debug.setSunNovaIn";
static NSString * const kOOLogNoteCheckScript = @"script.debug.note.checkScript";
static NSString * const kOOLogNoteScriptAction = @"script.debug.note.scriptAction";
static NSString * const kOOLogNoteTestCondition = @"script.debug.note.testCondition";
static NSString * const kOOLogNoteAwardCargo = @"script.debug.note.awardCargo";
@ -94,6 +94,7 @@ static NSString * const kOOLogSyntaxReset = @"script.debug.syntax.reset";
static NSString * mission_string_value;
static NSString * mission_key;
#if OLD_SCRIPT_CODE
- (void) checkScript
{
int i;
@ -113,27 +114,56 @@ static NSString * mission_key;
mission_key = missionTitle;
[self scriptActions: mission forTarget: self];
}
else if ([obj isKindOfClass:[OXPScript class]])
else if ([obj isKindOfClass:[OOScript class]])
{
OXPScript *jscript = (OXPScript *)obj;
OOScript *jscript = (OOScript *)obj;
[jscript doEvent:[self status_string]];
}
}
OOLogOutdentIf(kOOLogNoteCheckScript);
}
#endif
- (void) checkScript
{
NSEnumerator *scriptEnum = nil;
OOScript *theScript = nil;
[self setScript_target:self];
OOLog(@"script.trace.runWorld", @"----- Running world script with state %@", [self status_string]);
OOLogIndentIf(@"script.trace.runWorld");
for (scriptEnum = [script objectEnumerator]; (theScript = [scriptEnum nextObject]); )
{
[theScript runWithTarget:self];
}
OOLogOutdentIf(@"script.trace.runWorld");
}
- (void)runScript:(NSArray*)scriptActions withName:(NSString *)scriptName forTarget:(ShipEntity *)target
{
[self setScript_target:target];
mission_key = scriptName;
[self scriptActions:scriptActions forTarget:target];
}
- (void) scriptActions:(NSArray*) some_actions forTarget:(ShipEntity*) a_target
{
PlayerEntity* player = [PlayerEntity sharedPlayer];
int i;
for (i = 0; i < [some_actions count]; i++)
{
NSObject* action = [some_actions objectAtIndex:i];
if ([action isKindOfClass:[NSDictionary class]])
[player checkCouplet:(NSDictionary *)action onEntity: a_target];
[self checkCouplet:(NSDictionary *)action onEntity: a_target];
if ([action isKindOfClass:[NSString class]])
[player scriptAction:(NSString *)action onEntity: a_target];
[self scriptAction:(NSString *)action onEntity: a_target];
}
}
@ -546,48 +576,14 @@ static NSString * mission_key;
{
return mission_string_value;
}
- (NSString *) status_string
{
switch(status)
{
case STATUS_AUTOPILOT_ENGAGED :
return @"STATUS_AUTOPILOT_ENGAGED";
case STATUS_DEAD :
return @"STATUS_DEAD";
case STATUS_START_GAME :
return @"STATUS_START_GAME";
case STATUS_COCKPIT_DISPLAY :
return @"STATUS_COCKPIT_DISPLAY";
case STATUS_DOCKING :
return @"STATUS_DOCKING";
case STATUS_DOCKED :
return @"STATUS_DOCKED";
case STATUS_EFFECT :
return @"STATUS_EFFECT";
case STATUS_ENTERING_WITCHSPACE :
return @"STATUS_ENTERING_WITCHSPACE";
case STATUS_ESCAPE_SEQUENCE :
return @"STATUS_ESCAPE_SEQUENCE";
case STATUS_EXITING_WITCHSPACE :
return @"STATUS_EXITING_WITCHSPACE";
case STATUS_EXPERIMENTAL :
return @"STATUS_EXPERIMENTAL";
case STATUS_IN_FLIGHT :
return @"STATUS_IN_FLIGHT";
case STATUS_IN_HOLD :
return @"STATUS_IN_HOLD";
case STATUS_INACTIVE :
return @"STATUS_INACTIVE";
case STATUS_LAUNCHING :
return @"STATUS_LAUNCHING";
case STATUS_TEST :
return @"STATUS_TEST";
case STATUS_WITCHSPACE_COUNTDOWN :
return @"STATUS_WITCHSPACE_COUNTDOWN";
default :
return @"UNDEFINED";
}
return EntityStatusToString(status);
}
- (NSString *) gui_screen_string
{
switch(gui_screen)
@ -786,31 +782,31 @@ static int scriptRandomSeed = -1; // ensure proper random function
- (NSNumber *) systemGovernment_number
{
NSDictionary *systeminfo = [universe generateSystemData:system_seed];
return (NSNumber *)[systeminfo objectForKey:KEY_GOVERNMENT];
return [systeminfo objectForKey:KEY_GOVERNMENT];
}
- (NSNumber *) systemEconomy_number
{
NSDictionary *systeminfo = [universe generateSystemData:system_seed];
return (NSNumber *)[systeminfo objectForKey:KEY_ECONOMY];
return [systeminfo objectForKey:KEY_ECONOMY];
}
- (NSNumber *) systemTechLevel_number
{
NSDictionary *systeminfo = [universe generateSystemData:system_seed];
return (NSNumber *)[systeminfo objectForKey:KEY_TECHLEVEL];
return [systeminfo objectForKey:KEY_TECHLEVEL];
}
- (NSNumber *) systemPopulation_number
{
NSDictionary *systeminfo = [universe generateSystemData:system_seed];
return (NSNumber *)[systeminfo objectForKey:KEY_POPULATION];
return [systeminfo objectForKey:KEY_POPULATION];
}
- (NSNumber *) systemProductivity_number
{
NSDictionary *systeminfo = [universe generateSystemData:system_seed];
return (NSNumber *)[systeminfo objectForKey:KEY_PRODUCTIVITY];
return [systeminfo objectForKey:KEY_PRODUCTIVITY];
}
- (NSString *) commanderName_string
@ -2292,31 +2288,33 @@ static int scriptRandomSeed = -1; // ensure proper random function
}
- (BOOL) mapKey:(NSString *) keycode toOXP:(OXPScript *)oxp
- (BOOL) mapKey:(NSString *)keycode toOXP:(OOScript *)oxp
{
OXPScript *s = [oxpKeys objectForKey:keycode];
if (s == nil)
{
[oxpKeys setObject:oxp forKey:keycode];
return YES;
}
return NO;
OOScript *s = [oxpKeys objectForKey:keycode];
if (s == nil)
{
if (oxpKeys == nil) oxpKeys = [[NSMutableDictionary alloc] init];
[oxpKeys setObject:oxp forKey:keycode];
return YES;
}
return NO;
}
- (void) targetNearestHostile
{
[self scanForHostiles];
if (found_target != NO_TARGET)
{
Entity *ent = [universe entityForUniversalID:found_target];
if (ent != 0x00)
{
ident_engaged = YES;
missile_status = MISSILE_STATUS_TARGET_LOCKED;
[self addTarget:ent];
}
}
[self scanForHostiles];
if (found_target != NO_TARGET)
{
Entity *ent = [universe entityForUniversalID:found_target];
if (ent != 0x00)
{
ident_engaged = YES;
missile_status = MISSILE_STATUS_TARGET_LOCKED;
[self addTarget:ent];
}
}
}
@end

View File

@ -41,11 +41,6 @@ extern int debug;
BOOL always_include_addons;
@interface ResourceManager : NSObject
{
NSMutableArray *paths;
}
- (id) initIncludingAddOns: (BOOL) include_addons;
+ (NSString *) errors;
+ (NSMutableArray *) paths;
@ -68,4 +63,5 @@ BOOL always_include_addons;
+ (NSString *) stringFromFilesNamed:(NSString *)filename inFolder:(NSString *)foldername;
+ (NSDictionary *) loadScripts;
@end

View File

@ -31,6 +31,9 @@ MA 02110-1301, USA.
#import "OOStringParsing.h"
#import "OOPListParsing.h"
#import "OOJSScript.h"
#import "OOPListScript.h"
#define kOOLogUnconvertedNSLog @"unclassified.ResourceManager"
@ -43,7 +46,7 @@ static NSString * const kOOCacheKeySearchPaths = @"search paths";
static NSString * const kOOCacheKeyModificationDates = @"modification dates";
extern NSDictionary* parseScripts(NSString* script);
extern NSDictionary* ParseOOSScripts(NSString* script);
@interface ResourceManager (OOPrivate)
@ -53,30 +56,10 @@ extern NSDictionary* parseScripts(NSString* script);
@end
@implementation ResourceManager
static NSMutableArray* saved_paths;
static NSMutableArray* paths_to_load;
static NSString* errors;
- (id) init
{
self = [super init];
always_include_addons = YES;
paths = [[ResourceManager paths] retain];
errors = nil;
return self;
}
- (id) initIncludingAddOns: (BOOL) include_addons;
{
self = [super init];
always_include_addons = include_addons;
paths = [[ResourceManager paths] retain];
errors = nil;
return self;
}
// caches allow us to load any given file once only
//
NSMutableDictionary* dictionary_cache;
@ -89,17 +72,8 @@ NSMutableDictionary* movie_cache;
NSMutableDictionary* surface_cache;
#endif
- (void) dealloc
{
if (paths) [paths release];
// if (dictionary_cache) [dictionary_cache release];
// if (array_cache) [array_cache release];
// if (image_cache) [image_cache release];
// if (sound_cache) [sound_cache release];
[super dealloc];
}
@implementation ResourceManager
+ (NSString *) errors
{
@ -173,18 +147,24 @@ NSMutableDictionary* surface_cache;
if (always_include_addons != include_addons)
{
// clear the caches
if (dictionary_cache) [dictionary_cache release];
if (array_cache) [array_cache release];
if (image_cache) [image_cache release];
if (sound_cache) [sound_cache release];
if (string_cache) [string_cache release];
if (movie_cache) [movie_cache release];
[dictionary_cache release];
dictionary_cache = nil;
[array_cache release];
array_cache = nil;
[image_cache release];
image_cache = nil;
[sound_cache release];
sound_cache = nil;
[string_cache release];
string_cache = nil;
[movie_cache release];
movie_cache = nil;
// set flag for further accesses
always_include_addons = include_addons;
//
@ -627,6 +607,8 @@ NSMutableDictionary* surface_cache;
#endif
#if OLD_SCRIPT_CODE
+ (NSDictionary *) loadScripts
{
NSMutableArray *results = [NSMutableArray arrayWithCapacity:16];
@ -656,7 +638,7 @@ NSMutableDictionary* surface_cache;
// load and compile oos script
NSLog(@"trying to load and parse %@", filepath);
NSString *script = [NSString stringWithContentsOfFile:filepath];
NSDictionary *scriptDict = parseScripts(script);
NSDictionary *scriptDict = ParseOOSScripts(script);
if (scriptDict) [results addObject:scriptDict];
}
else
@ -681,7 +663,7 @@ NSMutableDictionary* surface_cache;
// load and compile oos script
NSLog(@"trying to load and compile %@", filepath);
NSString *script = [NSString stringWithContentsOfFile:filepath];
NSDictionary *scriptDict = parseScripts(script);
NSDictionary *scriptDict = ParseOOSScripts(script);
if (scriptDict) {
[results addObject:scriptDict];
}
@ -712,5 +694,77 @@ NSMutableDictionary* surface_cache;
return [NSDictionary dictionaryWithDictionary:result];
}
#else
// New OOScript-based code. Result is dictionary of names -> OOScripts.
+ (NSDictionary *)loadScripts
{
NSMutableDictionary *loadedScripts = nil;
NSArray *results = nil;
NSArray *paths = nil;
NSEnumerator *pathEnum = nil;
NSString *path = nil;
NSEnumerator *scriptEnum = nil;
OOScript *script = nil;
NSString *name = nil;
NSAutoreleasePool *pool = nil;
loadedScripts = [NSMutableDictionary dictionary];
paths = [ResourceManager paths];
for (pathEnum = [paths objectEnumerator]; (path = [pathEnum nextObject]); )
{
pool = [[NSAutoreleasePool alloc] init];
NS_DURING
results = [OOScript worldScriptsAtPath:[path stringByAppendingPathComponent:@"Config"]];
if (results == nil) results = [OOScript worldScriptsAtPath:path];
if (results != nil)
{
for (scriptEnum = [results objectEnumerator]; (script = [scriptEnum nextObject]); )
{
name = [script name];
if (name != nil) [loadedScripts setObject:script forKey:name];
else OOLog(@"script.load.unnamed", @"Discarding anonymous script %@", script);
}
}
NS_HANDLER
OOLog(@"script.load.exception", @"***** %s encountered exception %@ (%@) while trying to load script from %@ -- ignoring this location.", __FUNCTION__, [localException name], [localException reason], path);
// Ignore exception and keep loading other scripts.
NS_ENDHANDLER
[pool release];
}
if (OOLogWillDisplayMessagesInClass(@"script.load.world.listAll"))
{
unsigned count = [loadedScripts count];
if (count != 0)
{
NSMutableArray *displayNames = nil;
NSEnumerator *scriptEnum = nil;
OOScript *script = nil;
NSString *displayString = nil;
displayNames = [NSMutableArray arrayWithCapacity:count];
for (scriptEnum = [loadedScripts objectEnumerator]; (script = [scriptEnum nextObject]); )
{
[displayNames addObject:[script displayName]];
}
displayString = [[displayNames sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)] componentsJoinedByString:@", "];
OOLog(@"script.load.world.listAll", @"Loaded %u world scripts: %@", count, displayString);
}
else
{
OOLog(@"script.load.world.listAll", @"*** No world scripts loaded.");
}
}
return loadedScripts;
}
#endif
@end

View File

@ -207,7 +207,7 @@ NSDictionary* parseIf(StringTokeniser* st) {
}
NSDictionary* parseScripts(NSString* script) {
NSDictionary* ParseOOSScripts(NSString* script) {
NSString *processedScript = preprocess(script);
StringTokeniser *st = [[StringTokeniser alloc] initWithString:processedScript];
NSMutableDictionary *scriptDict = [[NSMutableDictionary alloc] initWithCapacity:10];

View File

@ -0,0 +1,3 @@
#define OOJSSCRIPT_H_USED
#import "OXPScript.h"
#undef OOJSSCRIPT_H_USED

View File

@ -0,0 +1,3 @@
#define OOJAVASCRIPTENGINE_H_USED
#import "ScriptEngine.h"
#undef OOJAVASCRIPTENGINE_H_USED

View File

@ -0,0 +1,45 @@
/*
OOPListScript.h
Property list-based script.
I started off reimplementing plist scripting here, in order to remove one of
PlayerEntity's many overloaded functions. The scale of the task was such that
I've stepped back, and this simply wraps the old plist scripting in
PlayerEntity. I intend to split it off as initially intended, hopefully as
early as 1.69.
Oolite
Copyright (C) 2004-2007 Giles C Williams and contributors
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
*/
#import "OOScript.h"
@interface OOPListScript: OOScript
{
NSArray *_script;
NSDictionary *_metadata;
}
+ (NSArray *)scriptsInOOSFile:(NSString *)filePath;
+ (NSArray *)scriptsInPListFile:(NSString *)filePath;
@end

View File

@ -0,0 +1,187 @@
/*
OOPListScript.h
Oolite
Copyright (C) 2004-2007 Giles C Williams and contributors
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
*/
#import "OOPListScript.h"
#import "OOPListParsing.h"
#import "PlayerEntityScripting.h"
extern NSDictionary *ParseOOSScripts(NSString* script);
static NSString * const kMDKeyName = @"name";
static NSString * const kMDKeyDescription = @"description";
static NSString * const kMDKeyVersion = @"version";
static NSString * const kKeyMetadata = @"!metadata!";
@interface OOPListScript (SetUp)
+ (NSArray *)scriptsFromDictionaryOfScripts:(NSDictionary *)dictionary;
- (id)initWithName:(NSString *)name scriptArray:(NSArray *)script metadata:(NSDictionary *)metadata;
@end
@implementation OOPListScript
+ (NSArray *)scriptsInOOSFile:(NSString *)filePath
{
NSString *script = [NSString stringWithContentsOfFile:filePath];
return [self scriptsFromDictionaryOfScripts:ParseOOSScripts(script)];
}
+ (NSArray *)scriptsInPListFile:(NSString *)filePath
{
NSDictionary *dict = nil;
dict = OODictionaryFromFile(filePath);
return [self scriptsFromDictionaryOfScripts:dict];
}
- (void)dealloc
{
[_script release];
[_metadata release];
[super dealloc];
}
- (NSString *)name
{
return [_metadata objectForKey:kMDKeyName];
}
- (NSString *)scriptDescription
{
return [_metadata objectForKey:kMDKeyDescription];
}
- (NSString *)version
{
return [_metadata objectForKey:kMDKeyVersion];
}
- (void)runWithTarget:(Entity *)target
{
if (target != nil && ![target isKindOfClass:[ShipEntity class]])
{
OOLog(@"script.plist.run.badTarget", @"Expected ShipEntity or nil for target, got %@.", [target class]);
return;
}
OOLog(@"script.trace.plist.run", @"Running script %@", [self displayName]);
OOLogIndentIf(@"script.trace.plist.run");
[[PlayerEntity sharedPlayer] runScript:_script withName:[self name] forTarget:(ShipEntity *)target];
OOLogOutdentIf(@"script.trace.plist.run");
}
- (BOOL)doEvent:(NSString *)eventName
{
// PList scripts don't have event handlers.
return NO;
}
- (BOOL)doEvent:(NSString *)eventName withIntegerArgument:(int)argument
{
// PList scripts don't have event handlers.
return NO;
}
- (BOOL)doEvent:(NSString *)eventName withStringArgument:(NSString *)argument
{
// PList scripts don't have event handlers.
return NO;
}
@end
@implementation OOPListScript (SetUp)
+ (NSArray *)scriptsFromDictionaryOfScripts:(NSDictionary *)dictionary
{
NSMutableArray *result = nil;
NSEnumerator *keyEnum = nil;
NSString *key = nil;
NSArray *scriptArray = nil;
NSDictionary *metadata = nil;
OOPListScript *script = nil;
result = [NSMutableArray arrayWithCapacity:[dictionary count]];
metadata = [dictionary objectForKey:kKeyMetadata];
if (![metadata isKindOfClass:[NSDictionary class]]) metadata = nil;
for (keyEnum = [dictionary keyEnumerator]; (key = [keyEnum nextObject]); )
{
scriptArray = [dictionary objectForKey:key];
if ([key isKindOfClass:[NSString class]] &&
[scriptArray isKindOfClass:[NSArray class]] &&
![key isEqual:kKeyMetadata])
{
script = [[self alloc] initWithName:key scriptArray:scriptArray metadata:metadata];
if (script != nil)
{
[result addObject:script];
}
}
}
return result;
}
- (id)initWithName:(NSString *)name scriptArray:(NSArray *)script metadata:(NSDictionary *)metadata
{
self = [super init];
if (self != nil)
{
_script = [script retain];
if (name != nil)
{
if (metadata == nil) metadata = [NSDictionary dictionaryWithObject:name forKey:kMDKeyName];
else
{
NSMutableDictionary *mutableMetadata = [metadata mutableCopy];
[mutableMetadata setObject:name forKey:kMDKeyName];
metadata = mutableMetadata;
}
}
_metadata = [metadata copy];
}
return self;
}
@end

View File

@ -0,0 +1,67 @@
/*
OOScript.h
Abstract base class for scripts.
Currently, Oolite supports three types of script: the original property list
scripts, OOS scripts which translate into plist scripts, and JavaScript
scripts. OOScript unifies the interfaces to the script types and abstracts
loading. Additionally, it falls back to a more "primitive" script if loading
of one type fails; specifically, the order of precedence is:
script.js (JavaScript)
script.oos (OOS)
script.plist (property list)
Oolite
Copyright (C) 2004-2007 Giles C Williams and contributors
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
*/
#import <Foundation/Foundation.h>
@class Entity;
@interface OOScript: NSObject
/* Looks for path/world-scripts.plist, path/script.js, then path/script.oos,
then path/script.plist.
May return zero or more scripts.
*/
+ (NSArray *)worldScriptsAtPath:(NSString *)path;
// Load named scripts from Scripts folders.
+ (NSArray *)scriptsFromFileNamed:(NSString *)fileName;
+ (NSArray *)scriptsFromList:(NSArray *)fileNames;
+ (NSArray *)scriptsFromFileAtPath:(NSString *)filePath;
- (void)resetState; // Clear local variables, for instance.
- (NSString *)name;
- (NSString *)scriptDescription;
- (NSString *)version;
- (NSString *)displayName; // '"name" version' if version is defined, otherwise just '"name"'.
- (void)runWithTarget:(Entity *)target;
- (BOOL)doEvent:(NSString *)eventName;
- (BOOL)doEvent:(NSString *)eventName withIntegerArgument:(int)argument;
- (BOOL)doEvent:(NSString *)eventName withStringArgument:(NSString *)argument;
@end

View File

@ -0,0 +1,275 @@
/*
OOScript.m
Oolite
Copyright (C) 2004-2007 Giles C Williams and contributors
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
*/
#import "OOScript.h"
#import "OOJSScript.h"
#import "OOPListScript.h"
#import "OOLogging.h"
#import "Universe.h"
#import "OOJavaScriptEngine.h"
#import "OOPListParsing.h"
#import "ResourceManager.h"
static NSString * const kOOLogScriptSubclassResponsibility = @"general.error.subclassResponsibility.OOScript";
static NSString * const kOOLogLoadScriptJavaScript = @"script.load.javaScript";
static NSString * const kOOLogLoadScriptOOS = @"script.load.oos";
static NSString * const kOOLogLoadScriptPList = @"script.load.pList";
static NSString * const kOOLogLoadScriptOK = @"script.load.parseOK";
static NSString * const kOOLogLoadScriptParseError = @"script.load.parseError";
static NSString * const kOOLogLoadScriptNone = @"script.load.none";
@implementation OOScript
+ (NSArray *)worldScriptsAtPath:(NSString *)path
{
NSFileManager *fmgr = nil;
NSString *filePath = nil;
NSArray *names = nil;
NSArray *result = nil;
id script = nil;
BOOL foundScript = NO;
fmgr = [NSFileManager defaultManager];
// First, look for world-scripts.plist.
filePath = [path stringByAppendingPathComponent:@"world-scripts.plist"];
if (filePath != nil)
{
names = OOArrayFromFile(filePath);
if (names != nil)
{
foundScript = YES;
result = [self scriptsFromList:names];
}
}
// Second, try to load a JavaScript.
if (result == nil)
{
filePath = [path stringByAppendingPathComponent:@"script.js"];
if ([fmgr fileExistsAtPath:filePath]) foundScript = YES;
else
{
filePath = [path stringByAppendingPathComponent:@"script.es"];
if ([fmgr fileExistsAtPath:filePath]) foundScript = YES;
}
if (foundScript)
{
OOLog(kOOLogLoadScriptJavaScript, @"Trying to load JavaScript script %@", filePath);
OOLogIndentIf(kOOLogLoadScriptJavaScript);
script = [OOJSScript scriptWithPath:filePath];
if (script != nil)
{
result = [NSArray arrayWithObject:script];
OOLog(kOOLogLoadScriptOK, @"Successfully loaded JavaScript script %@", filePath);
}
else OOLog(kOOLogLoadScriptParseError, @"*** Failed to load JavaScript script %@", filePath);
OOLogOutdentIf(kOOLogLoadScriptJavaScript);
}
}
// Third, try to load an OOS script.
if (result == nil)
{
filePath = [path stringByAppendingPathComponent:@"script.oos"];
if ([fmgr fileExistsAtPath:filePath])
{
foundScript = YES;
OOLog(kOOLogLoadScriptOOS, @"Trying to load OOS script %@", filePath);
OOLogIndentIf(kOOLogLoadScriptOOS);
result = [OOPListScript scriptsInOOSFile:filePath];
if (result != nil) OOLog(kOOLogLoadScriptOK, @"Successfully loaded OOS script %@", filePath);
else OOLog(kOOLogLoadScriptParseError, @"*** Failed to load OOS script %@", filePath);
OOLogOutdentIf(kOOLogLoadScriptOOS);
}
}
// Fourth, try to load an plist script.
if (result == nil)
{
filePath = [path stringByAppendingPathComponent:@"script.plist"];
if ([fmgr fileExistsAtPath:filePath])
{
foundScript = YES;
OOLog(kOOLogLoadScriptPList, @"Trying to load property list script %@", filePath);
OOLogIndentIf(kOOLogLoadScriptPList);
result = [OOPListScript scriptsInPListFile:filePath];
if (result != nil) OOLog(kOOLogLoadScriptOK, @"Successfully loaded property list script %@", filePath);
else OOLog(kOOLogLoadScriptParseError, @"*** Failed to load property list script %@", filePath);
OOLogOutdentIf(kOOLogLoadScriptPList);
}
}
if (result == nil && foundScript)
{
OOLog(kOOLogLoadScriptNone, @"No script could be loaded from %@", path);
}
return result;
}
+ (NSArray *)scriptsFromFileNamed:(NSString *)fileName
{
NSEnumerator *pathEnum = nil;
NSString *path = nil;
NSString *filePath = nil;
NSArray *result = nil;
if (fileName == nil) return nil;
for (pathEnum = [[ResourceManager paths] objectEnumerator]; (path = [pathEnum nextObject]); )
{
filePath = [[path stringByAppendingPathComponent:@"Scripts"] stringByAppendingPathComponent:fileName];
result = [self scriptsFromFileAtPath:filePath];
if (result != nil) return result;
}
OOLog(@"script.load.notFound", @"***** Could not find a script file named %@.", fileName);
return nil;
}
+ (NSArray *)scriptsFromList:(NSArray *)fileNames
{
NSEnumerator *nameEnum = nil;
NSString *name = nil;
NSMutableArray *result = nil;
NSArray *scripts = nil;
result = [NSMutableArray arrayWithCapacity:[fileNames count]];
for (nameEnum = [fileNames objectEnumerator]; (name = [nameEnum nextObject]); )
{
scripts = [self scriptsFromFileNamed:name];
if (scripts != nil) [result addObjectsFromArray:scripts];
}
return result;
}
+ (NSArray *)scriptsFromFileAtPath:(NSString *)filePath
{
BOOL directory;
if (![[NSFileManager defaultManager] fileExistsAtPath:filePath isDirectory:&directory] || directory) return nil;
NSString *extension = [[filePath pathExtension] lowercaseString];
if ([extension isEqualToString:@"js"] || [extension isEqualToString:@"es"])
{
return [NSArray arrayWithObject:[OOJSScript scriptWithPath:filePath]];
}
else if ([extension isEqualToString:@"oos"])
{
return [OOPListScript scriptsInOOSFile:filePath];
}
else if ([extension isEqualToString:@"plist"])
{
return [OOPListScript scriptsInPListFile:filePath];
}
OOLog(@"script.load.badName", @"***** Don't know how to load a script from %@.", filePath);
return nil;
}
- (NSString *)description
{
return [NSString stringWithFormat:@"<%@ %p>{\"%@\" version %@}", [self class], self, [self name], [self version]];
}
- (void)resetState
{
}
- (NSString *)name
{
OOLog(kOOLogScriptSubclassResponsibility, @"OOScript should not be used directly!");
return nil;
}
- (NSString *)scriptDescription
{
OOLog(kOOLogScriptSubclassResponsibility, @"OOScript should not be used directly!");
return nil;
}
- (NSString *)version
{
OOLog(kOOLogScriptSubclassResponsibility, @"OOScript should not be used directly!");
return nil;
}
- (NSString *)displayName
{
NSString *name = [self name];
NSString *version = [self version];
if (version != NULL) return [NSString stringWithFormat:@"\"%@\" %@", name, version];
else return [NSString stringWithFormat:@"\"%@\"", name];
}
- (void)runWithTarget:(Entity *)target
{
OOLog(kOOLogScriptSubclassResponsibility, @"OOScript should not be used directly!");
}
- (BOOL)doEvent:(NSString *)eventName
{
OOLog(kOOLogScriptSubclassResponsibility, @"OOScript should not be used directly!");
return NO;
}
- (BOOL)doEvent:(NSString *)eventName withIntegerArgument:(int)argument
{
OOLog(kOOLogScriptSubclassResponsibility, @"OOScript should not be used directly!");
return NO;
}
- (BOOL)doEvent:(NSString *)eventName withStringArgument:(NSString *)argument
{
OOLog(kOOLogScriptSubclassResponsibility, @"OOScript should not be used directly!");
return NO;
}
@end

View File

@ -124,7 +124,6 @@ MA 02110-1301, USA.
@class TextureStore, GameController, CollisionRegion, MyOpenGLView, GuiDisplayGen;
@class Entity, ShipEntity, StationEntity, PlanetEntity, PlayerEntity;
@class ScriptEngine;
extern int debug;
@ -254,8 +253,6 @@ extern int debug;
// experimental proc-genned textures
BOOL doProcedurallyTexturedPlanets;
ScriptEngine *scriptEngine;
}
+ (id)sharedUniverse;
@ -502,8 +499,6 @@ double estimatedTimeForJourney(double distance, int hops);
- (void) handleOoliteException:(NSException*) ooliteException;
- (ScriptEngine *) scriptEngine;
// speech routines
//
- (void) startSpeakingString:(NSString *) text;

View File

@ -34,7 +34,8 @@ MA 02110-1301, USA.
#import "OOSound.h"
#import "OOColor.h"
#import "OOCacheManager.h"
#import "ScriptEngine.h"
#import "OOStringParsing.h"
#import "OOCollectionExtractors.h"
#import "Octree.h"
#import "CollisionRegion.h"
@ -50,7 +51,6 @@ MA 02110-1301, USA.
#import "WormholeEntity.h"
#import "RingEntity.h"
#import "ParticleEntity.h"
#import "OOStringParsing.h"
#define kOOLogUnconvertedNSLog @"unclassified.Universe"
@ -200,19 +200,14 @@ static Universe *sSharedUniverse = nil;
planet = NO_TARGET;
sun = NO_TARGET;
// NOTE! scriptEngine MUST be initialised before the PlayerEntity
scriptEngine = [[[ScriptEngine alloc] initWithUniverse: self] retain];
player = [[PlayerEntity alloc] init]; // alloc retains!
[self addEntity:player];
[player release];
player->x_next = nil; player->x_previous = nil; x_list_start = player;
player->y_next = nil; player->y_previous = nil; y_list_start = player;
player->z_next = nil; player->z_previous = nil; z_list_start = player;
[player set_up];
[player sendMessageToScripts:@"Initialise"];
[player setUpShipFromDictionary:[self getDictionaryForShip:[player ship_desc]]]; // ship desc is the standard cobra at this point
[player setStatus:STATUS_START_GAME];
@ -233,8 +228,6 @@ static Universe *sSharedUniverse = nil;
if (cachedStation)
[player setPosition: cachedStation->position];
[player release];
[self setViewDirection:VIEW_GUI_DISPLAY];
@ -243,6 +236,8 @@ static Universe *sSharedUniverse = nil;
universeRegion = [[CollisionRegion alloc] initAsUniverse]; // retained
doProcedurallyTexturedPlanets = NO;
[player sendMessageToScripts:@"startUp"];
return self;
}
@ -286,7 +281,6 @@ static Universe *sSharedUniverse = nil;
[activeWormholes release];
[characterPool release];
[universeRegion release];
[scriptEngine release];
int i;
for (i = 0; i < 256; i++) [system_names[i] release];
@ -928,8 +922,7 @@ static Universe *sSharedUniverse = nil;
//// possibly systeminfo has an override for the station
if ([systeminfo objectForKey:@"station"])
stationDesc = (NSString *)[systeminfo objectForKey:@"station"];
stationDesc = [systeminfo stringForKey:@"station" defaultValue:nil];
a_station = (StationEntity *)[self newShipWithRole:stationDesc]; // retain count = 1
if (a_station)
@ -2881,8 +2874,7 @@ GLfloat docked_light_specular[] = { (GLfloat) 1.0, (GLfloat) 1.0, (GLfloat) 0.5,
NSString *shipRoles = (NSString *)[shipDict objectForKey:@"roles"];
if (shipRoles)
isStation = ([shipRoles rangeOfString:@"station"].location != NSNotFound)||([shipRoles rangeOfString:@"carrier"].location != NSNotFound);
if ([shipDict objectForKey:@"isCarrier"])
isStation = [[shipDict objectForKey:@"isCarrier"] boolValue];
isStation = isStation || [shipDict boolForKey:@"isCarrier" defaultValue:isStation];
if (isStation)
ship = (StationEntity *)[self allocRecycledOrNewEntity:@"StationEntity"]; // is returned retained
@ -4001,15 +3993,14 @@ BOOL maintainLinkedLists(Universe* uni)
if ([se isBeacon])
[self setNextBeacon:se];
if (se->isStation)
{
double stationRoll = 0.4;
// check for ststion_roll override
NSDictionary* systeminfo = [self generateSystemData:system_seed];
if ([systeminfo objectForKey:@"station_roll"])
stationRoll = [(NSNumber *)[systeminfo objectForKey:@"station_roll"] doubleValue];
{
// check if it is a proper rotating station (ie. roles contains the word "station")
if ([(StationEntity*)se isRotatingStation])
{
// check for station_roll override
NSDictionary* systeminfo = [self generateSystemData:system_seed];
double stationRoll = [systeminfo doubleForKey:@"station_roll" defaultValue:0.4];
[se setRoll: stationRoll];
[(StationEntity*)se setPlanet:[self planet]];
[se setStatus:STATUS_ACTIVE];
@ -7594,12 +7585,6 @@ NSComparisonResult comparePrice(NSDictionary *dict1, NSDictionary *dict2, void *
}
- (ScriptEngine *) scriptEngine
{
return scriptEngine;
}
// speech routines
//
- (void) startSpeakingString:(NSString *) text