83static int SystemInfoExoticSetProperty(JSContext* context, JSValueConst obj, JSAtom prop, JSValueConst value, JSValueConst receiver,
int flags);
102 .class_name =
"SystemInfo",
149- (id)valueForKey:(NSString*)key;
150- (void)setValue:(
id)value forKey:(NSString*)key;
154- (void)setNullAssigned:(BOOL)flag forKey:(NSString*)key;
155- (BOOL)isNullAssignedForKey:(NSString*)key;
180 if ((
self = [super
init])) {
190 [_planetKey release];
191 [_nullAssignedKeys release];
196- (void)setNullAssigned:(BOOL)flag forKey:(NSString*)key
201 [_nullAssignedKeys addObject:key];
203 [_nullAssignedKeys removeObject:key];
207- (BOOL)isNullAssignedForKey:(NSString*)key
209 return [_nullAssignedKeys containsObject:key];
214 return [NSString stringWithFormat:@"galaxy %u, system %i", _galaxy, _system];
224 return @"SystemInfo";
227- (BOOL)isEqual:(
id)other
229 return other ==
self || ([other isKindOfClass:[
OOSystemInfo class]] && [other galaxy] ==
_galaxy && [other system] ==
_system);
240- (id)valueForKey:(NSString*)key
243 return [[UNIVERSE currentSystemData] objectForKey:key];
245 return [UNIVERSE systemDataForGalaxy:_galaxy planet:_system key:key];
248- (void)setValue:(
id)value forKey:(NSString*)key
252 [UNIVERSE setSystemDataForGalaxy:_galaxy planet:_system key:key value:value fromManifest:manifest forLayer:OO_LAYER_OXP_DYNAMIC];
258 return [[UNIVERSE currentSystemData] allKeys];
260 return [UNIVERSE systemDataKeysForGalaxy:_galaxy planet:_system];
282 return [PLAYER galaxy_coordinates];
284 return [UNIVERSE coordinatesForSystem:_system];
287- (JSValue)oo_jsValueInContext:(JSContext*)context
290 if (JS_IsException(result)) {
291 JS_FreeValue(context, JS_GetException(context));
294 JS_SetOpaque(result, [
self retain]);
299+ (void)oo_javaScriptEngineWillReset:(NSNotification*)notification
303 if (JS_IsObject(oldCache))
311 static BOOL observing = NO;
313 [[NSNotificationCenter defaultCenter] addObserver:[
OOSystemInfo class]
314 selector:@selector(oo_javaScriptEngineWillReset:)
315 name:kOOJavaScriptEngineWillResetNotification
341 info = [[[
OOSystemInfo alloc] initWithGalaxy:galaxy system:system] autorelease];
353 if (JS_IsObject(oldCache))
354 JS_FreeValue(context, oldCache);
355 sCachedSystemInfo = JS_IsObject(result) ? JS_DupValue(context, result) : JS_UNDEFINED;
385#define OOJS_EXOTIC_ENTER \
387#define OOJS_EXOTIC_EXIT(context, failure) \
389 @catch (id exception) \
391 OOJSReportWrappedException(context, exception); \
405 JSValue propValue = JS_AtomToValue(context, prop);
406 if (JS_IsString(propValue)) {
409 JS_FreeValue(context, propValue);
420 *outValue = JS_UNDEFINED;
425 if ([info
system] != -1) {
431 if (propValue ==
nil)
434 if ([propValue isKindOfClass:[NSNumber
class]] ||
OOIsNumberLiteral([propValue description], YES)) {
435 *outValue = JS_NewNumber(context, [propValue doubleValue]);
437 *outValue = [propValue oo_jsValueInContext:context];
448static int SystemInfoSetOnPrototypeChain(JSContext* context, JSValueConst obj, JSAtom prop, JSValueConst value, JSValueConst receiver,
int flags, BOOL* outHandled)
450 JSValue proto = JS_GetPrototype(context, obj);
453 while (JS_IsObject(proto)) {
454 JSPropertyDescriptor desc;
455 int found = JS_GetOwnProperty(context, &desc, proto, prop);
457 JS_FreeValue(context, proto);
461 JS_FreeValue(context, proto);
462 if (desc.flags & JS_PROP_GETSET) {
463 JS_FreeValue(context, desc.getter);
464 if (JS_IsUndefined(desc.setter))
466 JSValue result = JS_Call(context, desc.setter, receiver, 1, &value);
467 JS_FreeValue(context, desc.setter);
468 if (JS_IsException(result))
470 JS_FreeValue(context, result);
473 JS_FreeValue(context, desc.value);
474 if (!(desc.flags & JS_PROP_WRITABLE))
480 JSValue next = JS_GetPrototype(context, proto);
481 JS_FreeValue(context, proto);
485 if (JS_IsException(proto))
487 JS_FreeValue(context, proto);
496 if (flags & JS_PROP_THROW) {
497 JSValue propName = JS_AtomToString(context, prop);
498 const char* name = JS_ToCString(context, propName);
499 JS_ThrowTypeError(context,
"'%s' is read-only", name ? name :
"?");
500 JS_FreeCString(context, name);
501 JS_FreeValue(context, propName);
525 if (shared > 0 && desc != NULL && key !=
nil) {
527 if (JS_IsException(value)) {
528 JS_FreeValue(context, desc->getter);
529 JS_FreeValue(context, desc->setter);
530 JS_FreeValue(context, desc->value);
533 JS_FreeValue(context, value);
534 desc->flags |= JS_PROP_ENUMERABLE;
556 if (JS_IsException(value))
560 desc->flags = JS_PROP_C_W_E;
562 desc->getter = JS_UNDEFINED;
563 desc->setter = JS_UNDEFINED;
565 JS_FreeValue(context, value);
584 NSArray* keys = [info
allKeys];
585 NSUInteger
count = [keys count];
586 assert(
count <= INT32_MAX);
588 JSPropertyEnum* tab = js_mallocz(context,
sizeof *tab * (
count + 1));
594 for (NSString* key in keys) {
595 JSAtom atom = JS_NewAtom(context, [[key description] UTF8String]);
596 if (atom == JS_ATOM_NULL) {
597 JS_FreePropertyEnum(context, tab, i);
601 tab[i].is_enumerable =
true;
627 if (info !=
nil && key !=
nil) {
628 [info setValue:nil forKey:key];
644 JSValue proto = JS_GetPrototype(context, obj);
645 while (JS_IsObject(proto)) {
646 JSPropertyDescriptor desc;
647 int found = JS_GetOwnProperty(context, &desc, proto, prop);
649 JS_FreeValue(context, proto);
653 JS_FreeValue(context, proto);
654 if (desc.flags & JS_PROP_GETSET) {
655 JSValue result = JS_UNDEFINED;
656 JS_FreeValue(context, desc.setter);
657 if (JS_IsFunction(context, desc.getter)) {
658 result = JS_Call(context, desc.getter, receiver, 0, NULL);
660 JS_FreeValue(context, desc.getter);
666 JSValue next = JS_GetPrototype(context, proto);
667 JS_FreeValue(context, proto);
670 if (JS_IsException(proto))
672 JS_FreeValue(context, proto);
707 if (info ==
nil || key ==
nil || !JS_IsObject(receiver) || JS_VALUE_GET_PTR(receiver) != JS_VALUE_GET_PTR(obj)) {
709 return JS_DefinePropertyValue(context, receiver, prop, JS_DupValue(context, value), JS_PROP_C_W_E);
738 BOOL savedInterstellarInfo = ![UNIVERSE inInterstellarSpace] && [info
system] == -1;
739 BOOL sameGalaxy = [PLAYER currentGalaxyID] == [info
galaxy];
743 if (sameGalaxy && !savedInterstellarInfo) {
746 OOJSReportError(context,
@"Cannot read systemInfo values for %@.", savedInterstellarInfo ?
@"invalid interstellar space reference" :
@"other galaxies");
752 if (sameGalaxy && !savedInterstellarInfo) {
755 OOJSReportError(context,
@"Cannot read systemInfo values for %@.", savedInterstellarInfo ?
@"invalid interstellar space reference" :
@"other galaxies");
761 return JS_NewInt32(context, [info
galaxy]);
764 return JS_NewInt32(context, [info
system]);
784 if (!JSSystemInfoGetSystemInfo(context,
OOJS_THIS, &thisInfo))
787 if (argc < 1 || !JS_IsObject(
OOJS_ARGV[0]) || !JSSystemInfoGetSystemInfo(context,
OOJS_ARGV[0], &otherInfo)) {
792 BOOL sameGalaxy = ([thisInfo
galaxy] == [otherInfo
galaxy]);
794 OOJSReportErrorForCaller(context,
@"SystemInfo",
@"distanceToSystem",
@"Cannot calculate distance for systems in other galaxies.");
813 NSDictionary* result =
nil;
816 if (!JSSystemInfoGetSystemInfo(context,
OOJS_THIS, &thisInfo))
818 if (argc < 1 || !JS_IsObject(
OOJS_ARGV[0]) || !JSSystemInfoGetSystemInfo(context,
OOJS_ARGV[0], &otherInfo)) {
823 BOOL sameGalaxy = ([thisInfo
galaxy] == [otherInfo
galaxy]);
825 OOJSReportErrorForCaller(context,
@"SystemInfo",
@"routeToSystem",
@"Cannot calculate route for destinations in other galaxies.");
834 result = [UNIVERSE routeFromSystem:[thisInfo
system] toSystem:[otherInfo
system] optimizedBy:routeType];
849 if (!JSSystemInfoGetSystemInfo(context,
OOJS_THIS, &thisInfo))
857 BOOL sameGalaxy = ([thisInfo
galaxy] == [PLAYER galaxyNumber]);
859 OOJSReportErrorForCaller(context,
@"SystemInfo",
@"samplePrice",
@"Cannot calculate sample price for destinations in other galaxies.");
865 return JS_NewNumber(context, price);
876 if (!JSSystemInfoGetSystemInfo(context,
OOJS_THIS, &thisInfo))
879 NSString*
property =
nil;
881 NSString* manifest =
nil;
886 OOJSReportBadArguments(context,
@"SystemInfo",
@"setProperty",
MIN(argc, 3),
OOJS_ARGV, NULL,
@"setProperty(layer, property, value [,manifest])");
890 OOJSReportBadArguments(context,
@"SystemInfo",
@"setProperty",
MIN(argc, 3),
OOJS_ARGV, NULL,
@"setProperty(layer, property, value [,manifest])");
909 [UNIVERSE setSystemDataForGalaxy:[thisInfo
galaxy] planet:[thisInfo
system] key:property value:value fromManifest:manifest forLayer:layer];
934 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
935 NSMutableArray* result = [NSMutableArray arrayWithCapacity:256];
936 JSValue rval = JS_UNDEFINED;
942 BOOL OK = result !=
nil;
951 JSValue callResult = JS_Call(context, predicate, jsThis, 1, (JSValueConst*)args);
953 JS_FreeValue(context, args[0]);
956 OK = !JS_IsException(callResult);
959 int boolVal = JS_ToBool(context, callResult);
961 [result addObject:info];
962 }
else if (boolVal < 0) {
963 JS_FreeValue(context, JS_GetException(context));
966 JS_FreeValue(context, callResult);
973 rval = [result oo_jsValueInContext:context];
990 NSString*
property =
nil;
992 NSString* manifest =
nil;
999 OOJSReportBadArguments(context,
@"SystemInfo",
@"setInterstellarProperty",
MIN(argc, 3),
OOJS_ARGV, NULL,
@"setProperty(galaxy, fromsystem, tosystem, layer, property, value [,manifest])");
1003 OOJSReportBadArguments(context,
@"SystemInfo",
@"setInterstellarProperty",
MIN(argc, 3),
OOJS_ARGV, NULL,
@"setProperty(galaxy, fromsystem, tosystem, layer, property, value [,manifest])");
1014 OOJSReportBadArguments(context,
@"SystemInfo",
@"setInterstellarProperty",
MIN(argc, 3),
OOJS_ARGV, NULL,
@"setProperty(galaxy, fromsystem, tosystem, layer, property, value [,manifest])");
1025 OOJSReportBadArguments(context,
@"SystemInfo",
@"setInterstellarProperty",
MIN(argc, 3),
OOJS_ARGV, NULL,
@"setProperty(galaxy, fromsystem, tosystem, layer, property, value [,manifest])");
1036 OOJSReportBadArguments(context,
@"SystemInfo",
@"setInterstellarProperty",
MIN(argc, 3),
OOJS_ARGV, NULL,
@"setProperty(galaxy, fromsystem, tosystem, layer, property, value [,manifest])");
1055 NSString* key = [NSString stringWithFormat:@"interstellar: %u %u %u", g, s1, s2];
1057 [[UNIVERSE systemManager] setProperty:property forSystemKey:key andLayer:layer toValue:value fromManifest:manifest];
OORouteType StringToRouteType(NSString *string)
BOOL OOIsNumberLiteral(NSString *string, BOOL allowSpaces)
#define OOJS_PROFILE_EXIT
#define OOJS_PROFILE_EXIT_VOID
#define OOJS_END_FULL_NATIVE
#define OOJS_BEGIN_FULL_NATIVE(context)
#define OOJS_NATIVE_ENTER(cx)
#define OOJS_PROFILE_ENTER
void InitOOJSSystemInfo(JSContext *context, JSObject *global)
jsval GetJSSystemInfoForSystem(JSContext *context, OOGalaxyID galaxy, OOSystemID system)
static JSBool SystemInfoDistanceToSystem(JSContext *context, uintN argc, jsval *vp)
static OOSystemID sCachedSystem
static JSBool SystemInfoStaticFilteredSystems(JSContext *context, uintN argc, jsval *vp)
static JSBool SystemInfoRouteToSystem(JSContext *context, uintN argc, jsval *vp)
static JSPropertySpec sSystemInfoProperties[]
static JSObject * sCachedSystemInfo
static JSFunctionSpec sSystemInfoStaticMethods[]
static JSBool SystemInfoStaticSetInterstellarProperty(JSContext *context, uintN argc, jsval *vp)
static JSBool SystemInfoSetPropertyMethod(JSContext *context, uintN argc, jsval *vp)
@ kSystemInfo_coordinates
@ kSystemInfo_internalCoordinates
static JSBool SystemInfoGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
static JSClass sSystemInfoClass
static void SystemInfoFinalize(JSContext *context, JSObject *this)
static OOGalaxyID sCachedGalaxy
static JSFunctionSpec sSystemInfoMethods[]
static JSBool SystemInfoSamplePrice(JSContext *context, uintN argc, jsval *vp)
BOOL NSPointToVectorJSValue(JSContext *context, NSPoint point, jsval *outValue) NONNULL_FUNC
void OOJSPauseTimeLimiter(void)
id OOJSNativeObjectFromJSValue(JSContext *context, jsval value)
void OOJSReportWarning(JSContext *context, NSString *format,...)
#define OOJS_RETURN_WITH_HELPER(helper, value)
JSBool OOJSObjectWrapperToString(JSContext *context, uintN argc, jsval *vp)
#define OOJS_PROP_HIDDEN_READONLY_CB
void OOJSRegisterObjectConverter(JSClass *theClass, OOJSClassConverterCallback converter)
#define OOJS_RETURN_DOUBLE(value)
OOINLINE jsval OOJSValueFromNativeObject(JSContext *context, id object)
#define DEFINE_JS_OBJECT_GETTER(NAME, JSCLASS, JSPROTO, OBJCCLASSNAME)
void OOJSObjectWrapperFinalize(JSContext *context, JSObject *this)
#define OOJS_RETURN_OBJECT(o)
void OOJSReportBadPropertySelector(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec)
void OOJSReportErrorForCaller(JSContext *context, NSString *scriptClass, NSString *function, NSString *format,...)
OOINLINE BOOL OOJSValueToInt32(JSContext *context, jsval value, int32_t *outValue)
NSString * OOStringFromJSValue(JSContext *context, jsval value)
JSBool OOJSUnconstructableConstruct(JSContext *context, uintN argc, jsval *vp)
OOINLINE BOOL OOJSValueIsFunction(JSContext *context, jsval value)
OOINLINE JSContext * OOJSAcquireContext(void)
void OOJSReportError(JSContext *context, NSString *format,...)
id OOJSBasicPrivateObjectConverter(JSContext *context, JSObject *object)
void OOJSReportBadArguments(JSContext *context, NSString *scriptClass, NSString *function, uintN argc, jsval *argv, NSString *message, NSString *expectedArgsDescription)
void OOJSResumeTimeLimiter(void)
id OOJSNativeObjectOfClassFromJSObject(JSContext *context, JSObject *object, Class requiredClass)
#define OOJS_RETURN_VECTOR(value)
NSString * OOCommodityType
uint64_t OOCreditsQuantity
Vector OOGalacticCoordinatesFromInternal(NSPoint internalCoordinates)
#define OOJS_EXOTIC_EXIT(context, failure)
static int SystemInfoExoticGetOwnPropertyNames(JSContext *context, JSPropertyEnum **ptab, uint32_t *plen, JSValueConst obj)
static JSClassID sSystemInfoClassID
#define OOJS_EXOTIC_ENTER
static int SystemInfoExoticDeleteProperty(JSContext *context, JSValueConst obj, JSAtom prop)
static NSString * SystemInfoKeyForAtom(JSContext *context, JSAtom prop)
static int SystemInfoSetOnPrototypeChain(JSContext *context, JSValueConst obj, JSAtom prop, JSValueConst value, JSValueConst receiver, int flags, BOOL *outHandled)
static JSValue SystemInfoExoticGetProperty(JSContext *context, JSValueConst obj, JSAtom prop, JSValueConst receiver)
static JSValue sCachedSystemInfo
static int SystemInfoExoticSetProperty(JSContext *context, JSValueConst obj, JSAtom prop, JSValueConst value, JSValueConst receiver, int flags)
static int SystemInfoExoticGetOwnProperty(JSContext *context, JSPropertyDescriptor *desc, JSValueConst obj, JSAtom prop)
static JSClassExoticMethods sSystemInfoExoticMethods
static BOOL SystemInfoGetSystemDataValue(JSContext *context, OOSystemInfo *info, NSString *key, JSValue *outValue)
static OOSystemInfo * SystemInfoForObject(JSValueConst obj)
JSValue OOJSNativeFailure(JSContext *context)
JSClassID OOJSRegisterClass(JSClassID *ioClassID, const JSClassDef *classDef)
int OOJSGetSharedPermanentOwnProperty(JSContext *context, JSPropertyDescriptor *desc, JSValueConst object, JSAtom prop)
JSValueConst OOJSInitClass(JSContext *context, JSValueConst global, JSClassID classID, JSValueConst parentPrototype, JSCFunction *constructor, int constructorArgCount, const JSCFunctionListEntry *properties, size_t propertyCount, const JSCFunctionListEntry *methods, size_t methodCount, const JSCFunctionListEntry *staticMethods, size_t staticMethodCount)
#define OOJS_COUNT(array)
OOCreditsQuantity samplePriceForCommodity:inEconomy:withScript:inSystem:(OOCommodityType commodity,[inEconomy] OOEconomyID economy,[withScript] NSString *scriptName,[inSystem] OOSystemID system)
id propertyNamed:(NSString *name)
OOJSScript * currentlyRunningScript()
id getProperty:forSystem:inGalaxy:(NSString *property,[forSystem] OOSystemID s,[inGalaxy] OOGalaxyID g)
id valueForKey:(NSString *key)
NSMutableSet * _nullAssignedKeys
NSString * oo_jsClassName()
NSString * descriptionComponents()
void setNullAssigned:forKey:(BOOL flag,[forKey] NSString *key)
void setValue:forKey:(id value,[forKey] NSString *key)
NSString * shortDescriptionComponents()
OOINLINE double distanceBetweenPlanetPositions(int x1, int y1, int x2, int y2) INLINE_CONST_FUNC