42static JSBool
SystemInfoSetProperty(JSContext* context, JSObject*
this, jsid propID, JSBool strict, jsval* value);
44static JSBool
SystemInfoEnumerate(JSContext* context, JSObject*
this, JSIterateOp enumOp, jsval* state, jsid* idp);
56 JSCLASS_HAS_PRIVATE | JSCLASS_NEW_ENUMERATE,
66 JSCLASS_NO_OPTIONAL_MEMBERS
113- (id)valueForKey:(NSString*)key;
114- (void)setValue:(
id)value forKey:(NSString*)key;
141 if ((
self = [super
init])) {
144 _planetKey = [[NSString stringWithFormat:@"%u %i", galaxy, system] retain];
151 [_planetKey release];
158 return [
NSString stringWithFormat:@"galaxy %u, system %i", _galaxy, _system];
168 return @"SystemInfo";
171- (BOOL)isEqual:(
id)other
184- (id)valueForKey:(NSString*)key
187 return [[UNIVERSE currentSystemData] objectForKey:key];
189 return [UNIVERSE systemDataForGalaxy:_galaxy planet:_system key:key];
192- (void)setValue:(
id)value forKey:(NSString*)key
196 [UNIVERSE setSystemDataForGalaxy:_galaxy planet:_system key:key value:value fromManifest:manifest forLayer:OO_LAYER_OXP_DYNAMIC];
202 return [[UNIVERSE currentSystemData] allKeys];
204 return [UNIVERSE systemDataKeysForGalaxy:_galaxy planet:_system];
226 return [PLAYER galaxy_coordinates];
228 return [UNIVERSE coordinatesForSystem:_system];
231- (jsval)oo_jsValueInContext:(JSContext*)context
233 JSObject* jsSelf = NULL;
234 jsval result = JSVAL_NULL;
237 if (jsSelf != NULL) {
238 if (!JS_SetPrivate(context, jsSelf, [
self retain]))
242 result = OBJECT_TO_JSVAL(jsSelf);
268 info = [[[
OOSystemInfo alloc] initWithGalaxy:galaxy system:system] autorelease];
291 [(id)JS_GetPrivate(context, this) release];
292 JS_SetPrivate(context,
this,
nil);
301static JSBool
SystemInfoEnumerate(JSContext* context, JSObject*
this, JSIterateOp enumOp, jsval* state, jsid* idp)
305 NSEnumerator* enumerator =
nil;
308 case JSENUMERATE_INIT:
309 case JSENUMERATE_INIT_ALL:
312 NSArray* keys = [info
allKeys];
313 enumerator = [[keys objectEnumerator] retain];
314 *state = PRIVATE_TO_JSVAL(enumerator);
316 NSUInteger
count = [keys count];
317 assert(
count <= INT32_MAX);
319 *idp = INT_TO_JSID((int32_t)
count);
323 case JSENUMERATE_NEXT: {
324 enumerator = JSVAL_TO_PRIVATE(*state);
325 NSString* next = [enumerator nextObject];
327 jsval val = [next oo_jsValueInContext:context];
328 return JS_ValueToId(context, val, idp);
335 case JSENUMERATE_DESTROY: {
336 if (enumerator ==
nil && JSVAL_IS_DOUBLE(*state)) {
337 enumerator = JSVAL_TO_PRIVATE(*state);
339 [enumerator release];
354 jsval v = JSVAL_VOID;
371 BOOL savedInterstellarInfo = ![UNIVERSE inInterstellarSpace] && [info
system] == -1;
372 BOOL sameGalaxy = [PLAYER currentGalaxyID] == [info
galaxy];
374 if (JSID_IS_INT(propID)) {
375 switch (JSID_TO_INT(propID)) {
377 if (sameGalaxy && !savedInterstellarInfo) {
380 OOJSReportError(context,
@"Cannot read systemInfo values for %@.", savedInterstellarInfo ?
@"invalid interstellar space reference" :
@"other galaxies");
386 if (sameGalaxy && !savedInterstellarInfo) {
389 OOJSReportError(context,
@"Cannot read systemInfo values for %@.", savedInterstellarInfo ?
@"invalid interstellar space reference" :
@"other galaxies");
395 *value = INT_TO_JSVAL([info
galaxy]);
399 *value = INT_TO_JSVAL([info
system]);
406 }
else if (JSID_IS_STRING(propID)) {
412 if ([info
system] != -1) {
418 if (propValue !=
nil) {
419 if ([propValue isKindOfClass:[NSNumber
class]] ||
OOIsNumberLiteral([propValue description], YES)) {
420 BOOL OK = JS_NewNumberValue(context, [propValue doubleValue], value);
426 *value = [propValue oo_jsValueInContext:context];
444 if (JSID_IS_STRING(propID)) {
461 JSObject* otherObj = NULL;
464 if (!JSSystemInfoGetSystemInfo(context,
OOJS_THIS, &thisInfo))
466 if (argc < 1 || !JS_ValueToObject(context,
OOJS_ARGV[0], &otherObj) || !JSSystemInfoGetSystemInfo(context, otherObj, &otherInfo)) {
471 BOOL sameGalaxy = ([thisInfo
galaxy] == [otherInfo
galaxy]);
473 OOJSReportErrorForCaller(context,
@"SystemInfo",
@"distanceToSystem",
@"Cannot calculate distance for systems in other galaxies.");
491 JSObject* otherObj = NULL;
493 NSDictionary* result =
nil;
496 if (!JSSystemInfoGetSystemInfo(context,
OOJS_THIS, &thisInfo))
498 if (argc < 1 || !JS_ValueToObject(context,
OOJS_ARGV[0], &otherObj) || !JSSystemInfoGetSystemInfo(context, otherObj, &otherInfo)) {
503 BOOL sameGalaxy = ([thisInfo
galaxy] == [otherInfo
galaxy]);
505 OOJSReportErrorForCaller(context,
@"SystemInfo",
@"routeToSystem",
@"Cannot calculate route for destinations in other galaxies.");
514 result = [UNIVERSE routeFromSystem:[thisInfo
system] toSystem:[otherInfo
system] optimizedBy:routeType];
529 if (!JSSystemInfoGetSystemInfo(context,
OOJS_THIS, &thisInfo))
537 BOOL sameGalaxy = ([thisInfo
galaxy] == [PLAYER galaxyNumber]);
539 OOJSReportErrorForCaller(context,
@"SystemInfo",
@"samplePrice",
@"Cannot calculate sample price for destinations in other galaxies.");
545 return JS_NewNumberValue(context, price, &
OOJS_RVAL);
556 if (!JSSystemInfoGetSystemInfo(context,
OOJS_THIS, &thisInfo))
559 NSString*
property =
nil;
561 NSString* manifest =
nil;
566 OOJSReportBadArguments(context,
@"SystemInfo",
@"setProperty",
MIN(argc, 3U),
OOJS_ARGV, NULL,
@"setProperty(layer, property, value [,manifest])");
569 if (!JS_ValueToInt32(context,
OOJS_ARGV[0], &iValue)) {
570 OOJSReportBadArguments(context,
@"SystemInfo",
@"setProperty",
MIN(argc, 3U),
OOJS_ARGV, NULL,
@"setProperty(layer, property, value [,manifest])");
589 [UNIVERSE setSystemDataForGalaxy:[thisInfo
galaxy] planet:[thisInfo
system] key:property value:value fromManifest:manifest forLayer:layer];
601 JSObject* jsThis = NULL;
610 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
611 NSMutableArray* result = [NSMutableArray arrayWithCapacity:256];
617 BOOL OK = result !=
nil;
625 jsval rval = JSVAL_VOID;
627 OK = JS_CallFunctionValue(context, jsThis, predicate, 1, args, &rval);
631 if (JS_IsExceptionPending(context)) {
632 JS_ReportPendingException(context);
639 if (JS_ValueToBoolean(context, rval, &boolVal) && boolVal) {
640 [result addObject:info];
666 NSString*
property =
nil;
668 NSString* manifest =
nil;
675 OOJSReportBadArguments(context,
@"SystemInfo",
@"setInterstellarProperty",
MIN(argc, 3U),
OOJS_ARGV, NULL,
@"setProperty(galaxy, fromsystem, tosystem, layer, property, value [,manifest])");
678 if (!JS_ValueToInt32(context,
OOJS_ARGV[0], &iValue)) {
679 OOJSReportBadArguments(context,
@"SystemInfo",
@"setInterstellarProperty",
MIN(argc, 3U),
OOJS_ARGV, NULL,
@"setProperty(galaxy, fromsystem, tosystem, layer, property, value [,manifest])");
689 if (!JS_ValueToInt32(context,
OOJS_ARGV[1], &iValue)) {
690 OOJSReportBadArguments(context,
@"SystemInfo",
@"setInterstellarProperty",
MIN(argc, 3U),
OOJS_ARGV, NULL,
@"setProperty(galaxy, fromsystem, tosystem, layer, property, value [,manifest])");
700 if (!JS_ValueToInt32(context,
OOJS_ARGV[2], &iValue)) {
701 OOJSReportBadArguments(context,
@"SystemInfo",
@"setInterstellarProperty",
MIN(argc, 3U),
OOJS_ARGV, NULL,
@"setProperty(galaxy, fromsystem, tosystem, layer, property, value [,manifest])");
711 if (!JS_ValueToInt32(context,
OOJS_ARGV[3], &iValue)) {
712 OOJSReportBadArguments(context,
@"SystemInfo",
@"setInterstellarProperty",
MIN(argc, 3U),
OOJS_ARGV, NULL,
@"setProperty(galaxy, fromsystem, tosystem, layer, property, value [,manifest])");
731 NSString* key = [NSString stringWithFormat:@"interstellar: %u %u %u", g, s1, s2];
733 [[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)
@ 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 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)
static JSClassDef sSystemInfoClass
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