40static JSBool
MissionGetProperty(JSContext *context, JSObject *
this, jsid propID, jsval *value);
41static JSBool
MissionSetProperty(JSContext *context, JSObject *
this, jsid propID, JSBool strict, jsval *value);
127 jsval argval = JSVAL_VOID;
128 jsval argval2 = JSVAL_VOID;
129 jsval rval = JSVAL_VOID;
138 jsval cbFunction = JSVAL_VOID;
139 JSObject *cbThis = NULL;
171 @catch (NSException *exception)
174 OOLog(
kOOLogException,
@"Ignoring exception %@:%@ during handling of mission screen completion callback.", [exception name], [exception reason]);
180 JS_RemoveValueRoot(context, &cbFunction);
181 JS_RemoveObjectRoot(context, &cbThis);
189 if (!JSID_IS_INT(propID))
return YES;
196 switch (JSID_TO_INT(propID))
200 if (result ==
nil) result = [NSDictionary dictionary];
201 result = [result allValues];
224static JSBool
MissionSetProperty(JSContext *context, JSObject *
this, jsid propID, JSBool strict, jsval *value)
226 if (!JSID_IS_INT(propID))
return YES;
233 switch (JSID_TO_INT(propID))
266 if (!JS_ValueToInt32(context,
OOJS_ARGV[i], &dest))
268 JS_ClearPendingException(context);
279 if (JS_ValueToInt32(context,
OOJS_ARGV[i], &dest))
289 JS_ClearPendingException(context);
291 OOSystemID system = [marker oo_intForKey:@"system" defaultValue:-1];
316 if (!JS_ValueToInt32(context,
OOJS_ARGV[i], &dest))
318 JS_ClearPendingException(context);
330 if (JS_ValueToInt32(context,
OOJS_ARGV[i], &dest))
335 if (![player removeMissionDestinationMarker:[player defaultMarker:dest]]) {
342 JS_ClearPendingException(context);
344 OOSystemID system = [marker oo_intForKey:@"system" defaultValue:-1];
347 if (![player removeMissionDestinationMarker:marker]) {
366 NSString *text =
nil;
403 NSString *text =
nil;
404 NSArray *texts =
nil;
405 NSString *missionKey =
nil;
409 OOJSReportWarning(context,
@"Usage error: mission.%@() called with no arguments. Treating as Mission.%@(null). This call may fail in a future version of Oolite.", isKey ?
@"setInstructionsKey" :
@"setInstructions", isKey ?
@"setInstructionsKey" :
@"setInstructions");
445 else if (texts !=
nil && !isKey)
462 jsval value = JSVAL_NULL;
463 if (JS_GetProperty(context,
object, key, &value))
465 if (JSVAL_IS_OBJECT(value))
476 jsval value = JSVAL_NULL;
477 if (JS_GetProperty(context,
object, key, &value))
487 jsval value = JSVAL_NULL;
488 if (JS_GetProperty(context,
object, key, &value))
490 return [[UNIVERSE gui] textureDescriptorFromJSValue:value inContext:context callerDescription:@"mission.runScreen()"];
505 jsval
function = JSVAL_NULL;
506 jsval value = JSVAL_NULL;
507 JSObject *params = NULL;
510 if ([player status] == STATUS_START_GAME)
518 if (argc < 1 || !JS_ValueToObject(context,
OOJS_ARGV[0], ¶ms))
534 if (!JSVAL_IS_NULL(
function))
556 if (JS_GetProperty(context, params,
"title", &value) && !JSVAL_IS_VOID(value))
565 NSString *message = [[UNIVERSE missiontext] oo_stringForKey:titleKey];
572 OOJSReportWarning(context,
@"Mission.runScreen: titleKey '%@' has no entry in missiontext.plist.", titleKey);
582 if (JS_GetProperty(context, params,
"customChartZoom", &value) && !JSVAL_IS_VOID(value))
585 if (JS_ValueToNumber(context, value, &zoom))
593 OOJSReportWarning(context,
@"Mission.runScreen: invalid customChartZoom value specified.");
598 if (JS_GetProperty(context, params,
"customChartCentre", &value) && !JSVAL_IS_VOID(value))
603 NSPoint coords = { vValue.x, vValue.y };
609 OOJSReportWarning(context,
@"Mission.runScreen: invalid value for customChartCentre. Must be valid vector. Defaulting to current location.");
612 if (JS_GetProperty(context, params,
"customChartCentreInLY", &value) && !JSVAL_IS_VOID(value))
623 OOJSReportWarning(context,
@"Mission.runScreen: invalid value for customChartCentreInLY. Must be valid vector. Defaulting to current location.");
627 [UNIVERSE removeDemoShips];
630 if (JS_GetProperty(context, params,
"model", &value) && !JSVAL_IS_VOID(value))
632 if ([player status] == STATUS_IN_FLIGHT && JSVAL_IS_STRING(value))
634 OOJSReportWarning(context,
@"Mission.runScreen: model cannot be displayed while in flight.");
640 JSBool spinning = YES;
641 if (JS_GetProperty(context, params,
"spinModel", &value) && !JSVAL_IS_VOID(value))
643 JS_ValueToBoolean(context, value, &spinning);
647 demoShip = [UNIVERSE makeDemoShipWithRole:role spinning:spinning];
652 if (JS_GetProperty(context, params,
"modelPersonality", &value) && !JSVAL_IS_VOID(value))
655 JS_ValueToInt32(context,value,&personality);
659 JS_SetProperty(context,
sMissionObject,
"displayModel", &demoShipVal);
666 JSBool allowInterrupt = NO;
668 if ([player status] == STATUS_IN_FLIGHT)
670 allowInterrupt = YES;
674 if (JS_GetProperty(context, params,
"allowInterrupt", &value) && !JSVAL_IS_VOID(value))
676 JS_ValueToBoolean(context, value, &allowInterrupt);
680 if (JS_GetProperty(context, params,
"exitScreen", &value) && !JSVAL_IS_VOID(value))
689 if (JS_GetProperty(context, params,
"screenID", &value) && !JSVAL_IS_VOID(value))
699 if (JS_GetProperty(context, params,
"registerKeys", &value) && !JSVAL_IS_VOID(value))
704 JSBool textEntry = NO;
705 if (JS_GetProperty(context, params,
"textEntry", &value) && !JSVAL_IS_VOID(value))
707 JS_ValueToBoolean(context, value, &textEntry);
754 OOGUIRow row = [[UNIVERSE gui] rowForKey:firstKey];
757 [[UNIVERSE gui] setSelectedRow:row];
781 if ([player status] != STATUS_DOCKED)
788 [PLAYER setGuiToIntroFirstGo:NO];
OOINLINE OOGUIScreenID OOGUIScreenIDFromJSValue(JSContext *context, jsval value)
OOINLINE jsval OOJSValueFromGUIScreenID(JSContext *context, OOGUIScreenID value)
void OOStandardsDeprecated(NSString *message)
BOOL OOEnforceStandards(void)
#define OOJS_NATIVE_ENTER(cx)
void MissionRunCallback()
static OOJSScript * sCallbackScript
static jsval sCallbackThis
static JSBool MissionRunShipLibrary(JSContext *context, uintN argc, jsval *vp)
static JSBool MissionMarkSystem(JSContext *context, uintN argc, jsval *vp)
static JSFunctionSpec sMissionMethods[]
static JSClass sMissionClass
static jsval sCallbackFunction
static JSPropertySpec sMissionProperties[]
static NSDictionary * GetParameterImageDescriptor(JSContext *context, JSObject *object, const char *key)
static JSObject * sMissionObject
static JSBool MissionUnmarkSystem(JSContext *context, uintN argc, jsval *vp)
static JSBool MissionSetInstructions(JSContext *context, uintN argc, jsval *vp)
static NSDictionary * GetParameterDictionary(JSContext *context, JSObject *object, const char *key)
void InitOOJSMission(JSContext *context, JSObject *global)
static JSBool MissionSetProperty(JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value)
static JSBool MissionAddMessageText(JSContext *context, uintN argc, jsval *vp)
static JSBool MissionSetInstructionsInternal(JSContext *context, uintN argc, jsval *vp, BOOL isKey)
static JSBool MissionGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
static JSBool MissionSetInstructionsKey(JSContext *context, uintN argc, jsval *vp)
static NSString * GetParameterString(JSContext *context, JSObject *object, const char *key)
static JSBool MissionRunScreen(JSContext *context, uintN argc, jsval *vp)
PlayerEntity * OOPlayerForScripting(void)
BOOL JSValueToVector(JSContext *context, jsval value, Vector *outVector) NONNULL_FUNC
void OOJSPauseTimeLimiter(void)
id OOJSNativeObjectFromJSValue(JSContext *context, jsval value)
void OOJSReportWarning(JSContext *context, NSString *format,...)
#define OOJS_PROP_READWRITE_CB
OOINLINE jsval OOJSValueFromNativeObject(JSContext *context, id object)
id OOJSNativeObjectFromJSObject(JSContext *context, JSObject *object)
void OOJSReportBadPropertySelector(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec)
#define OOJS_RETURN_BOOL(v)
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 JSContext * OOJSAcquireContext(void)
#define OOJSAddGCObjectRoot(context, root, name)
NSString * OOStringFromJSValueEvenIfNull(JSContext *context, jsval value)
OOINLINE void OOJSRelinquishContext(JSContext *context)
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_PROP_READONLY_CB
void OOJSResumeTimeLimiter(void)
#define OOJSAddGCValueRoot(context, root, name)
NSString *const kOOLogException
#define OOLog(class, format,...)
NSPoint OOInternalCoordinatesFromGalactic(Vector galacticCoordinates)
jsval oo_jsValueInContext:(JSContext *context)
void pushScript:(OOJSScript *script)
OOJSScript * currentlyRunningScript()
void popScript:(OOJSScript *script)
BOOL callJSFunction:forObject:argc:argv:result:(jsval function,[forObject] JSObject *jsThis,[argc] uintN argc,[argv] jsval *argv,[result] jsval *outResult)
OOJavaScriptEngine * sharedEngine()
OOMusicController * sharedController()
void setMissionMusic:(NSString *missionMusicName)
void setMissionBackgroundDescriptor:(NSDictionary *descriptor)
void setMissionChoice:keyPress:withEvent:(NSString *newChoice,[keyPress] NSString *keyPress,[withEvent] BOOL withEvent)
void allowMissionInterrupt()
void setMissionExitScreen:(OOGUIScreenID screen)
void setCustomChartZoom:(OOScalar zoom)
void setMissionBackgroundSpecial:(NSString *special)
void setMissionMusic:(NSString *value)
NSString * missionScreenID()
void addMissionText:(NSString *textKey)
void setExtraMissionKeys:(NSDictionary *keys)
void setMissionInstructions:forMission:(NSString *text,[forMission] NSString *key)
void clearExtraMissionKeys()
void clearMissionDescriptionForMission:(NSString *key)
NSPoint galaxy_coordinates
void setMissionChoiceByTextEntry:(BOOL enable)
void setGuiToMissionScreenWithCallback:(BOOL callback)
void addMissionDestinationMarker:(NSDictionary *marker)
void setMissionScreenID:(NSString *msid)
NSDictionary * defaultMarker:(OOSystemID system)
void setMissionChoices:(NSString *choicesKey)
NSMutableDictionary * getMissionDestinations()
void addLiteralMissionText:(NSString *text)
void setMissionChoicesDictionary:(NSDictionary *choicesDict)
void setMissionInstructionsList:forMission:(NSArray *list,[forMission] NSString *key)
void setMissionTitle:(NSString *value)
void setMissionOverlayDescriptor:(NSDictionary *descriptor)
void setMissionDescription:forMission:(NSString *textKey,[forMission] NSString *key)
void clearMissionScreenID()
void setCustomChartCentre:(NSPoint coords)
void setEntityPersonalityInt:(uint16_t value)