44static JSBool
SystemInfoSetProperty(JSContext *context, JSObject *
this, jsid propID, JSBool strict, jsval *value);
46static JSBool
SystemInfoEnumerate(JSContext *context, JSObject *
this, JSIterateOp enumOp, jsval *state, jsid *idp);
60 JSCLASS_HAS_PRIVATE | JSCLASS_NEW_ENUMERATE,
70 JSCLASS_NO_OPTIONAL_MEMBERS
127- (id) valueForKey:(NSString *)key;
128- (void) setValue:(
id)value forKey:(NSString *)key;
130- (NSArray *) allKeys;
159 if ((
self = [super
init]))
163 _planetKey = [[NSString stringWithFormat:@"%u %i", galaxy, system] retain];
171 [_planetKey release];
179 return [NSString stringWithFormat:@"galaxy %u, system %i", _galaxy, _system];
191 return @"SystemInfo";
195- (BOOL) isEqual:(
id)other
197 return other ==
self ||
214- (id) valueForKey:(NSString *)key
218 return [[UNIVERSE currentSystemData] objectForKey:key];
220 return [UNIVERSE systemDataForGalaxy:_galaxy planet:_system key:key];
224- (void) setValue:(
id)value forKey:(NSString *)key
228 [UNIVERSE setSystemDataForGalaxy:_galaxy planet:_system key:key value:value fromManifest:manifest forLayer:OO_LAYER_OXP_DYNAMIC];
236 return [[UNIVERSE currentSystemData] allKeys];
238 return [UNIVERSE systemDataKeysForGalaxy:_galaxy planet:_system];
265 return [PLAYER galaxy_coordinates];
267 return [UNIVERSE coordinatesForSystem:_system];
271- (jsval) oo_jsValueInContext:(JSContext *)context
273 JSObject *jsSelf = NULL;
274 jsval result = JSVAL_NULL;
279 if (!JS_SetPrivate(context, jsSelf, [
self retain])) jsSelf = NULL;
281 if (jsSelf != NULL) result = OBJECT_TO_JSVAL(jsSelf);
313 info = [[[
OOSystemInfo alloc] initWithGalaxy:galaxy system:system] autorelease];
338 [(id)JS_GetPrivate(context, this) release];
339 JS_SetPrivate(context,
this,
nil);
348static JSBool
SystemInfoEnumerate(JSContext *context, JSObject *
this, JSIterateOp enumOp, jsval *state, jsid *idp)
352 NSEnumerator *enumerator =
nil;
356 case JSENUMERATE_INIT:
357 case JSENUMERATE_INIT_ALL:
360 NSArray *keys = [info
allKeys];
361 enumerator = [[keys objectEnumerator] retain];
362 *state = PRIVATE_TO_JSVAL(enumerator);
364 NSUInteger
count = [keys count];
365 assert(
count <= INT32_MAX);
366 if (idp != NULL) *idp = INT_TO_JSID((int32_t)
count);
370 case JSENUMERATE_NEXT:
372 enumerator = JSVAL_TO_PRIVATE(*state);
373 NSString *next = [enumerator nextObject];
376 jsval val = [next oo_jsValueInContext:context];
377 return JS_ValueToId(context, val, idp);
384 case JSENUMERATE_DESTROY:
386 if (enumerator ==
nil && JSVAL_IS_DOUBLE(*state))
388 enumerator = JSVAL_TO_PRIVATE(*state);
390 [enumerator release];
392 if (idp != NULL) *idp = JSID_VOID;
407 jsval v = JSVAL_VOID;
426 BOOL savedInterstellarInfo = ![UNIVERSE inInterstellarSpace] && [info
system] == -1;
427 BOOL sameGalaxy = [PLAYER currentGalaxyID] == [info
galaxy];
430 if (JSID_IS_INT(propID))
432 switch (JSID_TO_INT(propID))
435 if (sameGalaxy && !savedInterstellarInfo)
441 OOJSReportError(context,
@"Cannot read systemInfo values for %@.", savedInterstellarInfo ?
@"invalid interstellar space reference" :
@"other galaxies");
447 if (sameGalaxy && !savedInterstellarInfo)
453 OOJSReportError(context,
@"Cannot read systemInfo values for %@.", savedInterstellarInfo ?
@"invalid interstellar space reference" :
@"other galaxies");
459 *value = INT_TO_JSVAL([info
galaxy]);
463 *value = INT_TO_JSVAL([info
system]);
471 else if (JSID_IS_STRING(propID))
485 if (propValue !=
nil)
487 if ([propValue isKindOfClass:[NSNumber
class]] ||
OOIsNumberLiteral([propValue description], YES))
489 BOOL OK = JS_NewNumberValue(context, [propValue doubleValue], value);
498 *value = [propValue oo_jsValueInContext:context];
518 if (JSID_IS_STRING(propID))
537 JSObject *otherObj = NULL;
540 if (!JSSystemInfoGetSystemInfo(context,
OOJS_THIS, &thisInfo))
return NO;
541 if (argc < 1 || !JS_ValueToObject(context,
OOJS_ARGV[0], &otherObj) || !JSSystemInfoGetSystemInfo(context, otherObj, &otherInfo))
547 BOOL sameGalaxy = ([thisInfo
galaxy] == [otherInfo
galaxy]);
550 OOJSReportErrorForCaller(context,
@"SystemInfo",
@"distanceToSystem",
@"Cannot calculate distance for systems in other galaxies.");
569 JSObject *otherObj = NULL;
571 NSDictionary *result =
nil;
574 if (!JSSystemInfoGetSystemInfo(context,
OOJS_THIS, &thisInfo))
return NO;
575 if (argc < 1 || !JS_ValueToObject(context,
OOJS_ARGV[0], &otherObj) || !JSSystemInfoGetSystemInfo(context, otherObj, &otherInfo))
581 BOOL sameGalaxy = ([thisInfo
galaxy] == [otherInfo
galaxy]);
584 OOJSReportErrorForCaller(context,
@"SystemInfo",
@"routeToSystem",
@"Cannot calculate route for destinations in other galaxies.");
594 result = [UNIVERSE routeFromSystem:[thisInfo
system] toSystem:[otherInfo
system] optimizedBy:routeType];
610 if (!JSSystemInfoGetSystemInfo(context,
OOJS_THIS, &thisInfo))
return NO;
618 BOOL sameGalaxy = ([thisInfo
galaxy] == [PLAYER galaxyNumber]);
621 OOJSReportErrorForCaller(context,
@"SystemInfo",
@"samplePrice",
@"Cannot calculate sample price for destinations in other galaxies.");
627 return JS_NewNumberValue(context, price, &
OOJS_RVAL);
639 if (!JSSystemInfoGetSystemInfo(context,
OOJS_THIS, &thisInfo))
return NO;
641 NSString *
property =
nil;
643 NSString *manifest =
nil;
649 OOJSReportBadArguments(context,
@"SystemInfo",
@"setProperty",
MIN(argc, 3U),
OOJS_ARGV, NULL,
@"setProperty(layer, property, value [,manifest])");
652 if (!JS_ValueToInt32(context,
OOJS_ARGV[0], &iValue))
654 OOJSReportBadArguments(context,
@"SystemInfo",
@"setProperty",
MIN(argc, 3U),
OOJS_ARGV, NULL,
@"setProperty(layer, property, value [,manifest])");
678 [UNIVERSE setSystemDataForGalaxy:[thisInfo
galaxy] planet:[thisInfo
system] key:property value:value fromManifest:manifest forLayer:layer];
691 JSObject *jsThis = NULL;
701 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
702 NSMutableArray *result = [NSMutableArray arrayWithCapacity:256];
708 BOOL OK = result !=
nil;
717 jsval rval = JSVAL_VOID;
719 OK = JS_CallFunctionValue(context, jsThis, predicate, 1, args, &rval);
724 if (JS_IsExceptionPending(context))
726 JS_ReportPendingException(context);
734 if (JS_ValueToBoolean(context, rval, &boolVal) && boolVal)
736 [result addObject:info];
765 NSString *
property =
nil;
767 NSString *manifest =
nil;
775 OOJSReportBadArguments(context,
@"SystemInfo",
@"setInterstellarProperty",
MIN(argc, 3U),
OOJS_ARGV, NULL,
@"setProperty(galaxy, fromsystem, tosystem, layer, property, value [,manifest])");
778 if (!JS_ValueToInt32(context,
OOJS_ARGV[0], &iValue))
780 OOJSReportBadArguments(context,
@"SystemInfo",
@"setInterstellarProperty",
MIN(argc, 3U),
OOJS_ARGV, NULL,
@"setProperty(galaxy, fromsystem, tosystem, layer, property, value [,manifest])");
793 if (!JS_ValueToInt32(context,
OOJS_ARGV[1], &iValue))
795 OOJSReportBadArguments(context,
@"SystemInfo",
@"setInterstellarProperty",
MIN(argc, 3U),
OOJS_ARGV, NULL,
@"setProperty(galaxy, fromsystem, tosystem, layer, property, value [,manifest])");
808 if (!JS_ValueToInt32(context,
OOJS_ARGV[2], &iValue))
810 OOJSReportBadArguments(context,
@"SystemInfo",
@"setInterstellarProperty",
MIN(argc, 3U),
OOJS_ARGV, NULL,
@"setProperty(galaxy, fromsystem, tosystem, layer, property, value [,manifest])");
823 if (!JS_ValueToInt32(context,
OOJS_ARGV[3], &iValue))
825 OOJSReportBadArguments(context,
@"SystemInfo",
@"setInterstellarProperty",
MIN(argc, 3U),
OOJS_ARGV, NULL,
@"setProperty(galaxy, fromsystem, tosystem, layer, property, value [,manifest])");
849 NSString *key = [NSString stringWithFormat:@"interstellar: %u %u %u",g,s1,s2];
851 [[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
#define OOJS_PROFILE_EXIT_JSVAL
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 JSBool SystemInfoDeleteProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
static JSPropertySpec sSystemInfoProperties[]
static JSBool SystemInfoSetProperty(JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value)
static JSObject * sCachedSystemInfo
static JSFunctionSpec sSystemInfoStaticMethods[]
static JSObject * sSystemInfoPrototype
static JSBool SystemInfoStaticSetInterstellarProperty(JSContext *context, uintN argc, jsval *vp)
static JSBool SystemInfoSetPropertyMethod(JSContext *context, uintN argc, jsval *vp)
static JSBool SystemInfoGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
static JSClass sSystemInfoClass
@ kSystemInfo_coordinates
@ kSystemInfo_internalCoordinates
static void SystemInfoFinalize(JSContext *context, JSObject *this)
static OOGalaxyID sCachedGalaxy
static JSFunctionSpec sSystemInfoMethods[]
static JSBool SystemInfoEnumerate(JSContext *context, JSObject *this, JSIterateOp enumOp, jsval *state, jsid *idp)
static JSBool SystemInfoSamplePrice(JSContext *context, uintN argc, jsval *vp)
BOOL NSPointToVectorJSValue(JSContext *context, NSPoint point, jsval *outValue) NONNULL_FUNC
BOOL VectorToJSValue(JSContext *context, Vector vector, jsval *outValue) NONNULL_FUNC
void OOJSPauseTimeLimiter(void)
id OOJSNativeObjectFromJSValue(JSContext *context, jsval value)
void OOJSReportWarning(JSContext *context, NSString *format,...)
JSBool OOJSObjectWrapperToString(JSContext *context, uintN argc, jsval *vp)
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)
#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,...)
NSString * OOStringFromJSValue(JSContext *context, jsval value)
JSBool OOJSUnconstructableConstruct(JSContext *context, uintN argc, jsval *vp)
OOINLINE BOOL OOJSValueIsFunction(JSContext *context, jsval value)
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)
#define OOJS_PROP_READONLY_CB
void OOJSResumeTimeLimiter(void)
NSString * OOStringFromJSString(JSContext *context, JSString *string)
id OOJSNativeObjectOfClassFromJSObject(JSContext *context, JSObject *object, Class requiredClass)
NSString * OOCommodityType
uint64_t OOCreditsQuantity
Vector OOGalacticCoordinatesFromInternal(NSPoint internalCoordinates)
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)
NSString * oo_jsClassName()
NSString * descriptionComponents()
void setValue:forKey:(id value,[forKey] NSString *key)
NSString * shortDescriptionComponents()
OOINLINE double distanceBetweenPlanetPositions(int x1, int y1, int x2, int y2) INLINE_CONST_FUNC