50static BOOL
GetRelativeToAndRange(JSContext* context, NSString* methodName, uintN* ioArgc, jsval** ioArgv,
Entity** outRelativeTo,
double* outRange);
58static JSBool
SystemGetProperty(JSContext* context, JSObject*
this, jsid propID, jsval* value);
59static JSBool
SystemSetProperty(JSContext* context, JSObject*
this, jsid propID, JSBool strict, jsval* value);
61static JSBool
SystemToString(JSContext* context, uintN argc, jsval* vp);
62static JSBool
SystemAddPlanet(JSContext* context, uintN argc, jsval* vp);
63static JSBool
SystemAddMoon(JSContext* context, uintN argc, jsval* vp);
74static JSBool
SystemAddShips(JSContext* context, uintN argc, jsval* vp);
75static JSBool
SystemAddGroup(JSContext* context, uintN argc, jsval* vp);
224 if (!JSID_IS_INT(propID))
231 NSDictionary* systemData =
nil;
237 switch (JSID_TO_INT(propID)) {
239 *value = INT_TO_JSVAL([player currentSystemID]);
247 result = [UNIVERSE station];
252 result = [UNIVERSE planet];
257 result = [UNIVERSE sun];
262 result = [[[UNIVERSE planets] objectEnumeratorFilteredWithSelector:@selector(isVisibleToScripts)] allObjects];
267 result = [UNIVERSE stations];
272 result = [UNIVERSE currentWaypoints];
277 result = [UNIVERSE wormholes];
283 result = [UNIVERSE findShipsMatchingPredicate:JSEntityIsJavaScriptSearchablePredicate parameter:NULL inRange:-1 ofEntity:nil];
290 result = [UNIVERSE findShipsMatchingPredicate:JSEntityIsDemoShipPredicate parameter:NULL inRange:-1 ofEntity:nil];
297 result = [UNIVERSE findVisualEffectsMatchingPredicate:JSEntityIsJavaScriptSearchablePredicate parameter:NULL inRange:-1 ofEntity:nil];
303 return JS_NewNumberValue(context, [
UNIVERSE ambientLightLevel], value);
310 return JS_NewNumberValue(context, [player systemPseudoRandomFloat], value);
313 *value = INT_TO_JSVAL([player systemPseudoRandom100]);
317 *value = INT_TO_JSVAL([player systemPseudoRandom256]);
332 systemData = [UNIVERSE currentSystemData];
334 switch (JSID_TO_INT(propID)) {
336 result = [systemData objectForKey:KEY_NAME];
340 result = [systemData objectForKey:KEY_DESCRIPTION];
344 result = [systemData objectForKey:KEY_INHABITANTS];
354 result =
DESC(
@"not-applicable");
358 *value = INT_TO_JSVAL([systemData oo_intForKey:
KEY_ECONOMY]);
364 result =
DESC(
@"not-applicable");
368 *value = INT_TO_JSVAL([systemData oo_intForKey:
KEY_TECHLEVEL]);
385 switch (JSID_TO_INT(propID)) {
387 result =
DESC(
@"interstellar-space");
395 result =
DESC(
@"not-applicable");
399 *value = INT_TO_JSVAL(-1);
403 result =
DESC(
@"not-applicable");
407 *value = INT_TO_JSVAL(-1);
411 result =
DESC(
@"not-applicable");
415 *value = INT_TO_JSVAL(-1);
419 *value = INT_TO_JSVAL(0);
423 *value = INT_TO_JSVAL(0);
439static JSBool
SystemSetProperty(JSContext* context, JSObject*
this, jsid propID, JSBool strict, jsval* value)
441 if (!JSID_IS_INT(propID))
449 NSString* stringValue =
nil;
450 NSString* manifest =
nil;
460 switch (JSID_TO_INT(propID)) {
462 if (JS_ValueToNumber(context, *value, &fValue)) {
463 [UNIVERSE setAmbientLightLevel:fValue];
464 [UNIVERSE setLighting];
470 if (JS_ValueToBoolean(context, *value, &bValue)) {
471 [UNIVERSE setWitchspaceBreakPattern:bValue];
485 switch (JSID_TO_INT(propID)) {
488 if (stringValue !=
nil) {
489 [UNIVERSE setSystemDataForGalaxy:galaxy planet:system key:KEY_NAME value:stringValue fromManifest:manifest forLayer:OO_LAYER_OXP_DYNAMIC];
496 if (stringValue !=
nil) {
497 [UNIVERSE setSystemDataForGalaxy:galaxy planet:system key:KEY_DESCRIPTION value:stringValue fromManifest:manifest forLayer:OO_LAYER_OXP_DYNAMIC];
504 if (stringValue !=
nil) {
505 [UNIVERSE setSystemDataForGalaxy:galaxy planet:system key:KEY_INHABITANTS value:stringValue fromManifest:manifest forLayer:OO_LAYER_OXP_DYNAMIC];
511 if (JS_ValueToInt32(context, *value, &iValue)) {
516 [UNIVERSE setSystemDataForGalaxy:galaxy planet:system key:KEY_GOVERNMENT value:[NSNumber numberWithInt:iValue] fromManifest:manifest forLayer:OO_LAYER_OXP_DYNAMIC];
522 if (JS_ValueToInt32(context, *value, &iValue)) {
527 [UNIVERSE setSystemDataForGalaxy:galaxy planet:system key:KEY_ECONOMY value:[NSNumber numberWithInt:iValue] fromManifest:manifest forLayer:OO_LAYER_OXP_DYNAMIC];
533 if (JS_ValueToInt32(context, *value, &iValue)) {
538 [UNIVERSE setSystemDataForGalaxy:galaxy planet:system key:KEY_TECHLEVEL value:[NSNumber numberWithInt:iValue] fromManifest:manifest forLayer:OO_LAYER_OXP_DYNAMIC];
544 if (JS_ValueToInt32(context, *value, &iValue)) {
545 [UNIVERSE setSystemDataForGalaxy:galaxy planet:system key:KEY_POPULATION value:[NSNumber numberWithInt:iValue] fromManifest:manifest forLayer:OO_LAYER_OXP_DYNAMIC];
551 if (JS_ValueToInt32(context, *value, &iValue)) {
552 [UNIVERSE setSystemDataForGalaxy:galaxy planet:system key:KEY_PRODUCTIVITY value:[NSNumber numberWithInt:iValue] fromManifest:manifest forLayer:OO_LAYER_OXP_DYNAMIC];
576 NSString* systemDesc =
nil;
578 systemDesc = [NSString stringWithFormat:@"[System %u:%u \"%@\"]", [player
currentGalaxyID], [player
currentSystemID], [[UNIVERSE currentSystemData] objectForKey:KEY_NAME]];
591 OOPlanetEntity* planet =
nil;
616 OOPlanetEntity* planet =
nil;
652 NSString* role =
nil;
671 result = [UNIVERSE countShipsWithPrimaryRole:role inRange:range ofEntity:relativeTo];
684 NSString* role =
nil;
703 result = [UNIVERSE countShipsWithRole:role inRange:range ofEntity:relativeTo];
716 NSString* role =
nil;
719 NSArray* result =
nil;
749 NSString* role =
nil;
752 NSArray* result =
nil;
789 if (scanClass == CLASS_NOT_SET) {
801 result = [UNIVERSE countShipsWithScanClass:scanClass inRange:range ofEntity:relativeTo];
817 NSArray* result =
nil;
821 if (scanClass == CLASS_NOT_SET) {
847 JSObject* jsThis = NULL;
851 NSArray* result =
nil;
885 NSString* code =
nil;
894 OOPlanetEntity* planet = [UNIVERSE planet];
896 if (sun ==
nil || planet ==
nil) {
897 position = [UNIVERSE locationByCode:@"WITCHPOINT" withSun:nil andPlanet:nil];
899 position = [UNIVERSE locationByCode:code withSun:sun andPlanet:planet];
937 NSString* role =
nil;
949 [UNIVERSE witchspaceShipWithPrimaryRole:role];
964 NSString* role =
nil;
976 [UNIVERSE addShipWithRole:role nearRouteOneAt:position];
992 NSString* role =
nil;
994 NSString* coordScheme =
nil;
1001 OOJSReportBadArguments(context,
@"System",
@"legacy_addShipsAt", argc,
OOJS_ARGV,
nil,
@"role, positive count no greater than 64, coordinate scheme and coordinates");
1006 arg = [NSString stringWithFormat:@"%@ %d %@ %f %f %f", role, count, coordScheme, where.x, where.y, where.z];
1023 NSString* role =
nil;
1025 NSString* coordScheme =
nil;
1026 NSString* arg =
nil;
1032 OOJSReportBadArguments(context,
@"System",
@"legacy_addShipsAtPrecisely", argc,
OOJS_ARGV,
nil,
@"role, positive count no greater than 64, coordinate scheme and coordinates");
1037 arg = [NSString stringWithFormat:@"%@ %d %@ %f %f %f", role, count, coordScheme, where.x, where.y, where.z];
1055 NSString* role =
nil;
1057 NSString* coordScheme =
nil;
1058 NSString* arg =
nil;
1066 OOJSReportBadArguments(context,
@"System",
@"legacy_addShipWithinRadius", argc,
OOJS_ARGV,
nil,
@"role, positive count no greater than 64, coordinate scheme, coordinates and radius");
1071 arg = [NSString stringWithFormat:@"%@ %d %@ %f %f %f %f", role, count, coordScheme, where.x, where.y, where.z, radius];
1086 NSString* key =
nil;
1097 [UNIVERSE spawnShip:key];
1133 NSString* name =
nil;
1145 result = [UNIVERSE findSystemFromName:name];
1162 if (argc < 2 || !JS_ValueToInt32(context,
OOJS_ARGV[0], &galaxyID) || !JS_ValueToInt32(context,
OOJS_ARGV[1], &systemID)) {
1186 NSString* key =
nil;
1207 result = [UNIVERSE addVisualEffectAt:where withKey:key];
1221 NSMutableDictionary* settings;
1222 JSObject* params = NULL;
1233 if (argc < 2 || JSVAL_IS_NULL(
OOJS_ARGV[1])) {
1235 [UNIVERSE setPopulatorSetting:key to:nil];
1238 if (!JS_ValueToObject(context,
OOJS_ARGV[1], ¶ms)) {
1242 jsval callback = JSVAL_NULL;
1243 if (JS_GetProperty(context, params,
"callback", &callback) == JS_FALSE || JSVAL_IS_VOID(callback)) {
1252 [settings setObject:populator forKey:@"callbackObj"];
1254 jsval coords = JSVAL_NULL;
1255 if (JS_GetProperty(context, params,
"coordinates", &coords) != JS_FALSE && !JSVAL_IS_VOID(coords)) {
1259 [settings setObject:[NSArray arrayWithObjects:[NSNumber numberWithFloat:coordinates.x], [NSNumber numberWithFloat:coordinates.y], [NSNumber numberWithFloat:coordinates.z], nil] forKey:@"coordinates"];
1263 [populator release];
1265 [UNIVERSE setPopulatorSetting:key to:settings];
1278 NSMutableDictionary* settings;
1283 OOJSReportBadArguments(context,
@"System",
@"setWaypoint",
MIN(argc, 0U), &
OOJS_ARGV[0],
nil,
@"key, position, orientation, definition");
1288 OOJSReportBadArguments(context,
@"System",
@"setWaypoint",
MIN(argc, 0U), &
OOJS_ARGV[0],
nil,
@"key, position, orientation, definition");
1291 if (argc < 4 || JSVAL_IS_NULL(
OOJS_ARGV[3])) {
1293 [UNIVERSE defineWaypoint:nil forKey:key];
1297 OOJSReportBadArguments(context,
@"System",
@"setWaypoint",
MIN(argc, 2U),
OOJS_ARGV, NULL,
@"key, position, orientation, definition");
1301 OOJSReportBadArguments(context,
@"System",
@"setWaypoint",
MIN(argc, 3U),
OOJS_ARGV, NULL,
@"key, position, orientation, definition");
1305 OOJSReportBadArguments(context,
@"System",
@"setWaypoint",
MIN(argc, 4U),
OOJS_ARGV, NULL,
@"key, position, orientation, definition");
1309 settings = [[OOJSNativeObjectFromJSObject(context, JSVAL_TO_OBJECT(OOJS_ARGV[3])) mutableCopy] autorelease];
1310 [settings setObject:[NSArray arrayWithObjects:[NSNumber numberWithDouble:position.x], [NSNumber numberWithDouble:position.y], [NSNumber numberWithDouble:position.z], nil] forKey:@"position"];
1311 [settings setObject:[NSArray arrayWithObjects:[NSNumber numberWithDouble:orientation.w], [NSNumber numberWithDouble:orientation.x], [NSNumber numberWithDouble:orientation.y], [NSNumber numberWithDouble:orientation.z], nil] forKey:@"orientation"];
1313 [UNIVERSE defineWaypoint:settings forKey:key];
1328 NSString* role =
nil;
1332 double radius = NSNotFound;
1335 NSString* func = isGroup ?
@"addGroup" :
@"addShips";
1349 where = [UNIVERSE getWitchspaceExitPosition];
1357 if (argc > 2 + consumed) {
1358 if (!JS_ValueToNumber(context,
OOJS_ARGV[2 + consumed], &radius)) {
1367 result = [UNIVERSE addShipsAt:where withRole:role quantity:count withinRadius:radius asGroup:isGroup];
1370 NSArray* array = result;
1371 if ([array
count] > 0)
1387 NSString* role =
nil;
1388 NSString* route =
@"st";
1389 static NSSet* validRoutes =
nil;
1391 double where = NSNotFound;
1394 NSString* func = isGroup ?
@"addGroup" :
@"addShips";
1408 if (!JS_ValueToNumber(context,
OOJS_ARGV[2], &where) || !isfinite(where) || where < 0.0f || where > 1.0f) {
1414 route = [OOStringFromJSValue(context, OOJS_ARGV[3]) lowercaseString];
1416 if (validRoutes ==
nil) {
1417 validRoutes = [[NSSet alloc] initWithObjects:@"wp", @"pw", @"ws", @"sw", @"sp", @"ps", nil];
1420 if (route ==
nil || ![validRoutes containsObject:route]) {
1429 result = [UNIVERSE addShipsToRoute:route withRole:role quantity:count routeFraction:where asGroup:isGroup];
1432 NSArray* array = result;
1433 if ([array
count] > 0)
1450 assert(ioArgc && ioArgv && outRelativeTo && outRange);
1464 if (!
EXPECT_NOT(JS_ValueToNumber(context, **ioArgv, outRange))) {
1481 NSMutableArray* result =
nil;
1484 predicate, parameter
1487 result = [UNIVERSE findEntitiesMatchingPredicate:ANDPredicate
1490 ofEntity:relativeTo];
1492 if (result !=
nil && relativeTo !=
nil && ![relativeTo isPlayer]) {
1493 [result sortUsingFunction:CompareEntitiesByDistance context:relativeTo];
1496 return [NSArray array];
1508 predicate, parameter
1521 *r = (id)relativeTo;
1528 return NSOrderedAscending;
1530 return NSOrderedDescending;
1532 return NSOrderedSame;
#define SCANNER_MAX_RANGE
OOINLINE OOScanClass OOScanClassFromJSValue(JSContext *context, jsval value)
NSString * OODisplayStringFromEconomyID(OOEconomyID economy)
NSString * OODisplayStringFromGovernmentID(OOGovernmentID government)
void OOStandardsDeprecated(NSString *message)
BOOL ANDPredicate(Entity *entity, void *parameter)
BOOL HasScanClassPredicate(Entity *entity, void *parameter)
BOOL HasPrimaryRolePredicate(Entity *ship, void *parameter)
BOOL IsShipPredicate(Entity *entity, void *parameter)
BOOL HasRolePredicate(Entity *ship, void *parameter)
const HPVector kZeroHPVector
OOINLINE OOHPScalar HPdistance2(HPVector v1, HPVector v2) INLINE_CONST_FUNC
#define OOJS_PROFILE_EXIT
#define OOJS_END_FULL_NATIVE
#define OOJS_BEGIN_FULL_NATIVE(context)
#define OOJS_NATIVE_ENTER(cx)
#define OOJS_PROFILE_ENTER
BOOL JSValueToEntity(JSContext *context, jsval value, Entity **outEntity)
PlayerEntity * OOPlayerForScripting(void)
BOOL JSValueToQuaternion(JSContext *context, jsval value, Quaternion *outQuaternion) NONNULL_FUNC
jsval GetJSSystemInfoForSystem(JSContext *context, OOGalaxyID galaxy, OOSystemID system)
static JSPropertySpec sSystemProperties[]
static NSArray * FindShips(EntityFilterPredicate predicate, void *parameter, Entity *relativeTo, double range)
static JSBool SystemFilteredEntities(JSContext *context, uintN argc, jsval *vp)
static JSBool SystemAddShipsOrGroup(JSContext *context, uintN argc, jsval *vp, BOOL isGroup)
static JSBool SystemLocationFromCode(JSContext *context, uintN argc, jsval *vp)
static JSBool SystemLegacySpawnShip(JSContext *context, uintN argc, jsval *vp)
static JSBool SystemStaticInfoForSystem(JSContext *context, uintN argc, jsval *vp)
static JSBool SystemAddShipsOrGroupToRoute(JSContext *context, uintN argc, jsval *vp, BOOL isGroup)
static JSBool SystemStaticSystemIDForName(JSContext *context, uintN argc, jsval *vp)
static JSBool SystemCountShipsWithRole(JSContext *context, uintN argc, jsval *vp)
static BOOL GetRelativeToAndRange(JSContext *context, NSString *methodName, uintN *ioArgc, jsval **ioArgv, Entity **outRelativeTo, double *outRange)
static JSFunctionSpec sSystemStaticMethods[]
static NSComparisonResult CompareEntitiesByDistance(id a, id b, void *relativeTo)
static JSBool SystemLegacyAddShips(JSContext *context, uintN argc, jsval *vp)
static JSBool SystemCountShipsWithPrimaryRole(JSContext *context, uintN argc, jsval *vp)
static JSBool SystemAddGroup(JSContext *context, uintN argc, jsval *vp)
static JSBool SystemAddVisualEffect(JSContext *context, uintN argc, jsval *vp)
void InitOOJSSystem(JSContext *context, JSObject *global)
static JSBool SystemAddShips(JSContext *context, uintN argc, jsval *vp)
static NSArray * FindJSVisibleEntities(EntityFilterPredicate predicate, void *parameter, Entity *relativeTo, double range)
static JSBool SystemSetWaypoint(JSContext *context, uintN argc, jsval *vp)
static JSBool SystemLegacyAddShipsAt(JSContext *context, uintN argc, jsval *vp)
static JSBool SystemShipsWithPrimaryRole(JSContext *context, uintN argc, jsval *vp)
static JSBool SystemLegacyAddSystemShips(JSContext *context, uintN argc, jsval *vp)
static JSClass sSystemClass
static JSBool SystemSetProperty(JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value)
static JSFunctionSpec sSystemMethods[]
static JSBool SystemLegacyAddShipsAtPrecisely(JSContext *context, uintN argc, jsval *vp)
static JSBool SystemSendAllShipsAway(JSContext *context, uintN argc, jsval *vp)
static JSBool SystemAddShipsToRoute(JSContext *context, uintN argc, jsval *vp)
static JSBool SystemToString(JSContext *context, uintN argc, jsval *vp)
static JSBool SystemEntitiesWithScanClass(JSContext *context, uintN argc, jsval *vp)
@ kSystem_inhabitantsDescription
@ kSystem_populatorSettings
@ kSystem_pseudoRandom100
@ kSystem_allVisualEffects
@ kSystem_governmentDescription
@ kSystem_pseudoRandom256
@ kSystem_pseudoRandomNumber
@ kSystem_economyDescription
@ kSystem_isInterstellarSpace
static JSBool SystemGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
static JSBool SystemAddGroupToRoute(JSContext *context, uintN argc, jsval *vp)
static JSBool SystemSetPopulator(JSContext *context, uintN argc, jsval *vp)
static JSBool SystemCountEntitiesWithScanClass(JSContext *context, uintN argc, jsval *vp)
static JSBool SystemAddPlanet(JSContext *context, uintN argc, jsval *vp)
static JSBool SystemShipsWithRole(JSContext *context, uintN argc, jsval *vp)
static JSBool SystemLegacyAddShipsWithinRadius(JSContext *context, uintN argc, jsval *vp)
static JSBool SystemStaticSystemNameForID(JSContext *context, uintN argc, jsval *vp)
static JSBool SystemAddMoon(JSContext *context, uintN argc, jsval *vp)
static JSObject * sSystemPrototype
BOOL JSValueToVector(JSContext *context, jsval value, Vector *outVector) NONNULL_FUNC
BOOL JSValueToHPVector(JSContext *context, jsval value, HPVector *outVector) NONNULL_FUNC
BOOL BOOL VectorFromArgumentListNoError(JSContext *context, uintN argc, jsval *argv, HPVector *outVector, uintN *outConsumed) GCC_ATTR((nonnull(1
void OOJSPauseTimeLimiter(void)
BOOL JSEntityIsJavaScriptSearchablePredicate(Entity *entity, void *parameter)
#define OOJS_PROP_READWRITE_CB
BOOL JSFunctionPredicate(Entity *entity, void *parameter)
OOINLINE jsval OOJSValueFromNativeObject(JSContext *context, id object)
id OOJSNativeObjectFromJSObject(JSContext *context, JSObject *object)
#define OOJS_RETURN_OBJECT(o)
void OOJSReportBadPropertySelector(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec)
NSString * OOStringFromJSValue(JSContext *context, jsval value)
JSBool OOJSUnconstructableConstruct(JSContext *context, uintN argc, jsval *vp)
#define OOJS_PROP_READONLY
OOINLINE BOOL OOJSValueIsFunction(JSContext *context, jsval value)
OOINLINE jsval OOJSValueFromBOOL(int b) INLINE_CONST_FUNC
void OOJSReportBadPropertyValue(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec, jsval value)
void OOJSReportBadArguments(JSContext *context, NSString *scriptClass, NSString *function, uintN argc, jsval *argv, NSString *message, NSString *expectedArgsDescription)
#define OOJS_RETURN_HPVECTOR(value)
#define OOJS_PROP_READONLY_CB
void OOJSResumeTimeLimiter(void)
#define OOJS_RETURN_INT(v)
BOOL(* EntityFilterPredicate)(Entity *entity, void *parameter)
void setCallback:(jsval callback)
id propertyNamed:(NSString *name)
OOJSScript * currentlyRunningScript()
void addShipsWithinRadius:(NSString *roles_number_system_x_y_z_r)
OOSystemID currentSystemID()
void addShipsAt:(NSString *roles_number_system_x_y_z)
OOGalaxyID currentGalaxyID()
void addShipsAtPrecisely:(NSString *roles_number_system_x_y_z)
OOPlanetEntity * addPlanet:(NSString *planetKey)
OOPlanetEntity * addMoon:(NSString *moonKey)