Oolite 1.91.0.7644-241112-7f5034b
Loading...
Searching...
No Matches
OOJSMission.m File Reference
+ Include dependency graph for OOJSMission.m:

Go to the source code of this file.

Enumerations

enum  { kMission_markedSystems , kMission_screenID , kMission_exitScreen }
 

Functions

static JSBool MissionGetProperty (JSContext *context, JSObject *this, jsid propID, jsval *value)
 
static JSBool MissionSetProperty (JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value)
 
static JSBool MissionMarkSystem (JSContext *context, uintN argc, jsval *vp)
 
static JSBool MissionUnmarkSystem (JSContext *context, uintN argc, jsval *vp)
 
static JSBool MissionAddMessageText (JSContext *context, uintN argc, jsval *vp)
 
static JSBool MissionSetInstructions (JSContext *context, uintN argc, jsval *vp)
 
static JSBool MissionSetInstructionsKey (JSContext *context, uintN argc, jsval *vp)
 
static JSBool MissionRunScreen (JSContext *context, uintN argc, jsval *vp)
 
static JSBool MissionRunShipLibrary (JSContext *context, uintN argc, jsval *vp)
 
static JSBool MissionSetInstructionsInternal (JSContext *context, uintN argc, jsval *vp, BOOL isKey)
 
void InitOOJSMission (JSContext *context, JSObject *global)
 
void MissionRunCallback ()
 
static NSDictionary * GetParameterDictionary (JSContext *context, JSObject *object, const char *key)
 
static NSString * GetParameterString (JSContext *context, JSObject *object, const char *key)
 
static NSDictionary * GetParameterImageDescriptor (JSContext *context, JSObject *object, const char *key)
 

Variables

static jsval sCallbackFunction
 
static jsval sCallbackThis
 
static OOJSScriptsCallbackScript = nil
 
static JSObject * sMissionObject
 
static JSClass sMissionClass
 
static JSPropertySpec sMissionProperties []
 
static JSFunctionSpec sMissionMethods []
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
kMission_markedSystems 
kMission_screenID 
kMission_exitScreen 

Definition at line 76 of file OOJSMission.m.

77{
81};
@ kMission_exitScreen
Definition OOJSMission.m:80
@ kMission_markedSystems
Definition OOJSMission.m:78
@ kMission_screenID
Definition OOJSMission.m:79

Function Documentation

◆ GetParameterDictionary()

static NSDictionary * GetParameterDictionary ( JSContext * context,
JSObject * object,
const char * key )
static

Definition at line 460 of file OOJSMission.m.

461{
462 jsval value = JSVAL_NULL;
463 if (JS_GetProperty(context, object, key, &value))
464 {
465 if (JSVAL_IS_OBJECT(value))
466 {
467 return OOJSNativeObjectFromJSObject(context, JSVAL_TO_OBJECT(value));
468 }
469 }
470 return nil;
471}
id OOJSNativeObjectFromJSObject(JSContext *context, JSObject *object)
return nil

References nil, and OOJSNativeObjectFromJSObject().

Referenced by MissionRunScreen().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetParameterImageDescriptor()

static NSDictionary * GetParameterImageDescriptor ( JSContext * context,
JSObject * object,
const char * key )
static

Definition at line 485 of file OOJSMission.m.

486{
487 jsval value = JSVAL_NULL;
488 if (JS_GetProperty(context, object, key, &value))
489 {
490 return [[UNIVERSE gui] textureDescriptorFromJSValue:value inContext:context callerDescription:@"mission.runScreen()"];
491 }
492 else
493 {
494 return nil;
495 }
496}

References nil.

◆ GetParameterString()

static NSString * GetParameterString ( JSContext * context,
JSObject * object,
const char * key )
static

Definition at line 474 of file OOJSMission.m.

475{
476 jsval value = JSVAL_NULL;
477 if (JS_GetProperty(context, object, key, &value))
478 {
479 return OOStringFromJSValue(context, value);
480 }
481 return nil;
482}
NSString * OOStringFromJSValue(JSContext *context, jsval value)

References nil, and OOStringFromJSValue().

Referenced by MissionRunScreen().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ InitOOJSMission()

void InitOOJSMission ( JSContext * context,
JSObject * global )

Definition at line 108 of file OOJSMission.m.

109{
110 sCallbackFunction = JSVAL_NULL;
111 sCallbackThis = JSVAL_NULL;
112
113 JSObject *missionPrototype = JS_InitClass(context, global, NULL, &sMissionClass, OOJSUnconstructableConstruct, 0, sMissionProperties, sMissionMethods, NULL, NULL);
114 sMissionObject = JS_DefineObject(context, global, "mission", &sMissionClass, missionPrototype, OOJS_PROP_READONLY);
115
116 // Ensure JS objects are rooted.
117 OOJSAddGCValueRoot(context, &sCallbackFunction, "Pending mission callback function");
118 OOJSAddGCValueRoot(context, &sCallbackThis, "Pending mission callback this");
119}
static jsval sCallbackThis
Definition OOJSMission.m:55
static JSFunctionSpec sMissionMethods[]
Definition OOJSMission.m:94
static JSClass sMissionClass
Definition OOJSMission.m:60
static jsval sCallbackFunction
Definition OOJSMission.m:54
static JSPropertySpec sMissionProperties[]
Definition OOJSMission.m:84
static JSObject * sMissionObject
Definition OOJSMission.m:58
JSBool OOJSUnconstructableConstruct(JSContext *context, uintN argc, jsval *vp)
#define OOJS_PROP_READONLY
#define OOJSAddGCValueRoot(context, root, name)

References OOJS_PROP_READONLY, OOJSAddGCValueRoot, OOJSUnconstructableConstruct(), sCallbackFunction, sCallbackThis, sMissionClass, sMissionMethods, sMissionObject, and sMissionProperties.

+ Here is the call graph for this function:

◆ MissionAddMessageText()

static JSBool MissionAddMessageText ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 361 of file OOJSMission.m.

362{
363 OOJS_NATIVE_ENTER(context)
364
366 NSString *text = nil;
367
368 if (EXPECT_NOT(argc == 0))
369 {
371 }
372
373 // Found "FIXME: warning if no mission screen running.",,,
374 // However: used routinely by the Constrictor mission in F7, without mission screens.
375 text = OOStringFromJSValue(context, OOJS_ARGV[0]);
376 [player addLiteralMissionText:text];
377
379
381}
#define EXPECT_NOT(x)
#define OOJS_NATIVE_ENTER(cx)
#define OOJS_NATIVE_EXIT
PlayerEntity * OOPlayerForScripting(void)
Definition OOJSPlayer.m:191
#define OOJS_ARGV
#define OOJS_RETURN_VOID
void addLiteralMissionText:(NSString *text)

References PlayerEntity::addLiteralMissionText:, EXPECT_NOT, nil, OOJS_ARGV, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_VOID, OOPlayerForScripting(), and OOStringFromJSValue().

+ Here is the call graph for this function:

◆ MissionGetProperty()

static JSBool MissionGetProperty ( JSContext * context,
JSObject * this,
jsid propID,
jsval * value )
static

Definition at line 187 of file OOJSMission.m.

188{
189 if (!JSID_IS_INT(propID)) return YES;
190
191 OOJS_NATIVE_ENTER(context)
192
193 id result = nil;
195
196 switch (JSID_TO_INT(propID))
197 {
199 result = [player getMissionDestinations];
200 if (result == nil) result = [NSDictionary dictionary];
201 result = [result allValues];
202 break;
203
205 result = [player missionScreenID];
206 break;
207
209 *value = OOJSValueFromGUIScreenID(context, [player missionExitScreen]);
210 return YES;
211
212 default:
214 return NO;
215 }
216
217 *value = OOJSValueFromNativeObject(context, result);
218 return YES;
219
221}
OOINLINE jsval OOJSValueFromGUIScreenID(JSContext *context, OOGUIScreenID value)
OOINLINE jsval OOJSValueFromNativeObject(JSContext *context, id object)
void OOJSReportBadPropertySelector(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec)
NSMutableDictionary * getMissionDestinations()

References PlayerEntity::getMissionDestinations, kMission_exitScreen, kMission_markedSystems, kMission_screenID, PlayerEntity::missionScreenID, nil, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJSReportBadPropertySelector(), OOJSValueFromGUIScreenID(), OOJSValueFromNativeObject(), OOPlayerForScripting(), and sMissionProperties.

+ Here is the call graph for this function:

◆ MissionMarkSystem()

static JSBool MissionMarkSystem ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 255 of file OOJSMission.m.

256{
257 OOJS_NATIVE_ENTER(context)
258
260 unsigned i;
261 int dest;
262
263 // two pass. Once to validate, once to apply if they validate
264 for (i=0;i<argc;i++)
265 {
266 if (!JS_ValueToInt32(context, OOJS_ARGV[i], &dest))
267 {
268 JS_ClearPendingException(context); // or JS_ValueToInt32 exception crashes JS engine
269 if (!JSVAL_IS_OBJECT(OOJS_ARGV[i]))
270 {
271 OOJSReportBadArguments(context, @"Mission", @"markSystem", MIN(argc, 1U), OOJS_ARGV, nil, @"numbers or objects");
272 return NO;
273 }
274 }
275 }
276
277 for (i=0;i<argc;i++)
278 {
279 if (JS_ValueToInt32(context, OOJS_ARGV[i], &dest))
280 {
281 OOStandardsDeprecated(@"Use of numbers for mission.markSystem is deprecated");
282 if (!OOEnforceStandards())
283 {
284 [player addMissionDestinationMarker:[player defaultMarker:dest]];
285 }
286 }
287 else // must be object, from above
288 {
289 JS_ClearPendingException(context); // or JS_ValueToInt32 exception crashes JS engine
290 NSDictionary *marker = OOJSNativeObjectFromJSObject(context, JSVAL_TO_OBJECT(OOJS_ARGV[i]));
291 OOSystemID system = [marker oo_intForKey:@"system" defaultValue:-1];
292 if (system >= 0)
293 {
294 [player addMissionDestinationMarker:marker];
295 }
296 }
297 }
299
301}
void OOStandardsDeprecated(NSString *message)
BOOL OOEnforceStandards(void)
void OOJSReportBadArguments(JSContext *context, NSString *scriptClass, NSString *function, uintN argc, jsval *argv, NSString *message, NSString *expectedArgsDescription)
#define MIN(A, B)
Definition OOMaths.h:111
int16_t OOSystemID
Definition OOTypes.h:211
void addMissionDestinationMarker:(NSDictionary *marker)
NSDictionary * defaultMarker:(OOSystemID system)

References PlayerEntity::addMissionDestinationMarker:, PlayerEntity::defaultMarker:, MIN, nil, OOEnforceStandards(), OOJS_ARGV, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_VOID, OOJSNativeObjectFromJSObject(), OOJSReportBadArguments(), OOPlayerForScripting(), and OOStandardsDeprecated().

+ Here is the call graph for this function:

◆ MissionRunCallback()

void MissionRunCallback ( void )

Definition at line 122 of file OOJSMission.m.

123{
124 // don't do anything if we don't have a function.
125 if (JSVAL_IS_NULL(sCallbackFunction) || JSVAL_IS_VOID(sCallbackFunction)) return;
126
127 jsval argval = JSVAL_VOID;
128 jsval argval2 = JSVAL_VOID;
129 jsval rval = JSVAL_VOID;
132 JSContext *context = OOJSAcquireContext();
133
134 /* Create temporarily-rooted local copies of sCallbackFunction and
135 sCallbackThis, then clear the statics. This must be done in advance
136 since the callback might call runScreen() and clobber the statics.
137 */
138 jsval cbFunction = JSVAL_VOID;
139 JSObject *cbThis = NULL;
140 OOJSScript *cbScript = sCallbackScript;
141
142 OOJSAddGCValueRoot(context, &cbFunction, "Mission callback function");
143 OOJSAddGCObjectRoot(context, &cbThis, "Mission callback this");
144 cbFunction = sCallbackFunction;
145 cbScript = sCallbackScript;
146 JS_ValueToObject(context, sCallbackThis, &cbThis);
147
149 sCallbackFunction = JSVAL_NULL;
150 sCallbackThis = JSVAL_NULL;
151
152 jsval args[2];
153 argval = OOJSValueFromNativeObject(context, [player missionChoice_string]);
154 argval2 = OOJSValueFromNativeObject(context, [player missionKeyPress_string]);
155 args[0] = argval;
156 args[1] = argval2;
157
158 // now reset the mission choice silently, before calling the callback script.
159 [player setMissionChoice:nil keyPress:@"" withEvent:NO];
160
161 // Call the callback.
162 @try
163 {
164 [OOJSScript pushScript:cbScript];
165 [engine callJSFunction:cbFunction
166 forObject:cbThis
167 argc:2
168 argv:args
169 result:&rval];
170 }
171 @catch (NSException *exception)
172 {
173 // Squash any exception, allow cleanup to happen and so forth.
174 OOLog(kOOLogException, @"Ignoring exception %@:%@ during handling of mission screen completion callback.", [exception name], [exception reason]);
175 }
176 [OOJSScript popScript:cbScript];
177
178 // Manage that memory.
179 [cbScript release];
180 JS_RemoveValueRoot(context, &cbFunction);
181 JS_RemoveObjectRoot(context, &cbThis);
182
183 OOJSRelinquishContext(context);
184}
static OOJSScript * sCallbackScript
Definition OOJSMission.m:56
OOINLINE JSContext * OOJSAcquireContext(void)
#define OOJSAddGCObjectRoot(context, root, name)
OOINLINE void OOJSRelinquishContext(JSContext *context)
NSString *const kOOLogException
Definition OOLogging.m:651
#define OOLog(class, format,...)
Definition OOLogging.h:88
void pushScript:(OOJSScript *script)
Definition OOJSScript.m:537
void popScript:(OOJSScript *script)
Definition OOJSScript.m:550
BOOL callJSFunction:forObject:argc:argv:result:(jsval function,[forObject] JSObject *jsThis,[argc] uintN argc,[argv] jsval *argv,[result] jsval *outResult)
OOJavaScriptEngine * sharedEngine()
void setMissionChoice:keyPress:withEvent:(NSString *newChoice,[keyPress] NSString *keyPress,[withEvent] BOOL withEvent)

References OOJavaScriptEngine::callJSFunction:forObject:argc:argv:result:, kOOLogException, nil, OOJSAcquireContext(), OOJSAddGCObjectRoot, OOJSAddGCValueRoot, OOJSRelinquishContext(), OOJSValueFromNativeObject(), OOLog, OOPlayerForScripting(), OOJSScript::popScript:, OOJSScript::pushScript:, sCallbackFunction, sCallbackScript, sCallbackThis, PlayerEntity::setMissionChoice:keyPress:withEvent:, and OOJavaScriptEngine::sharedEngine.

+ Here is the call graph for this function:

◆ MissionRunScreen()

static JSBool MissionRunScreen ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 500 of file OOJSMission.m.

501{
502 OOJS_NATIVE_ENTER(context)
503
505 jsval function = JSVAL_NULL;
506 jsval value = JSVAL_NULL;
507 JSObject *params = NULL;
508
509 // No mission screens during intro.
510 if ([player status] == STATUS_START_GAME)
511 {
512 // (though no JS should be loaded at this stage, so this
513 // check may be obsolete - CIM)
515 }
516
517 // Validate arguments.
518 if (argc < 1 || !JS_ValueToObject(context, OOJS_ARGV[0], &params))
519 {
520 OOJSReportBadArguments(context, @"mission", @"runScreen", MIN(argc, 1U), &OOJS_ARGV[0], nil, @"parameter object");
521 return NO;
522 }
523
524 if (argc > 1) function = OOJS_ARGV[1];
525 if (!JSVAL_IS_NULL(function) && !OOJSValueIsFunction(context, function))
526 {
527 OOJSReportBadArguments(context, @"mission", @"runScreen", 1, &OOJS_ARGV[1], nil, @"function");
528 return NO;
529 }
530
531 // Not OOJS_BEGIN_FULL_NATIVE() - we use JSAPI while paused.
533
534 if (!JSVAL_IS_NULL(function))
535 {
536
537 /* CIM 30/12/12: This following line causes problems in certain
538 * cases, but has to be kept for backward
539 * compatibility. Documenting the third argument of
540 * mission.runScreen will at least help people get around it in
541 * multi-world-script mission screens. (Though, since no-one has
542 * complained yet, perhaps I'm the only one who uses them?) */
543
544 sCallbackScript = [[[OOJSScript currentlyRunningScript] weakRefUnderlyingObject] retain];
545 if (argc > 2)
546 {
548 }
549 else
550 {
552 }
553 }
554
555 // Apply settings.
556 if (JS_GetProperty(context, params, "title", &value) && !JSVAL_IS_VOID(value))
557 {
558 [player setMissionTitle:OOStringFromJSValue(context, value)];
559 }
560 else
561 {
562 NSString *titleKey = GetParameterString(context, params, "titleKey");
563 if (titleKey != nil)
564 {
565 NSString *message = [[UNIVERSE missiontext] oo_stringForKey:titleKey];
566 if (message != nil)
567 {
568 [player setMissionTitle:OOExpand(message)];
569 }
570 else
571 {
572 OOJSReportWarning(context, @"Mission.runScreen: titleKey '%@' has no entry in missiontext.plist.", titleKey);
573 }
574 }
575 }
576
577 [[OOMusicController sharedController] setMissionMusic:GetParameterString(context, params, "music")];
578 [player setMissionOverlayDescriptor:GetParameterImageDescriptor(context, params, "overlay")];
579 [player setMissionBackgroundDescriptor:GetParameterImageDescriptor(context, params, "background")];
580 [player setMissionBackgroundSpecial:GetParameterString(context, params, "backgroundSpecial")];
581
582 if (JS_GetProperty(context, params, "customChartZoom", &value) && !JSVAL_IS_VOID(value))
583 {
584 jsdouble zoom;
585 if (JS_ValueToNumber(context, value, &zoom))
586 {
587 if (zoom >= 1 && zoom <= CHART_MAX_ZOOM)
588 {
589 [player setCustomChartZoom:zoom];
590 }
591 else
592 {
593 OOJSReportWarning(context, @"Mission.runScreen: invalid customChartZoom value specified.");
594 [player setCustomChartZoom:1];
595 }
596 }
597 }
598 if (JS_GetProperty(context, params, "customChartCentre", &value) && !JSVAL_IS_VOID(value))
599 {
600 Vector vValue;
601 if (JSValueToVector(context, value, &vValue))
602 {
603 NSPoint coords = { vValue.x, vValue.y };
604 [player setCustomChartCentre:coords];
605 }
606 else
607 {
609 OOJSReportWarning(context, @"Mission.runScreen: invalid value for customChartCentre. Must be valid vector. Defaulting to current location.");
610 }
611 }
612 if (JS_GetProperty(context, params, "customChartCentreInLY", &value) && !JSVAL_IS_VOID(value))
613 {
614 Vector vValue;
615 if (JSValueToVector(context, value, &vValue))
616 {
617 NSPoint coords = OOInternalCoordinatesFromGalactic(vValue);
618 [player setCustomChartCentre:coords];
619 }
620 else
621 {
623 OOJSReportWarning(context, @"Mission.runScreen: invalid value for customChartCentreInLY. Must be valid vector. Defaulting to current location.");
624 }
625 }
626
627 [UNIVERSE removeDemoShips]; // remove any demoship or miniature planet that may be remaining from previous screens
628
629 ShipEntity *demoShip = nil;
630 if (JS_GetProperty(context, params, "model", &value) && !JSVAL_IS_VOID(value))
631 {
632 if ([player status] == STATUS_IN_FLIGHT && JSVAL_IS_STRING(value))
633 {
634 OOJSReportWarning(context, @"Mission.runScreen: model cannot be displayed while in flight.");
635 }
636 else
637 {
638 NSString *role = OOStringFromJSValue(context, value);
639
640 JSBool spinning = YES;
641 if (JS_GetProperty(context, params, "spinModel", &value) && !JSVAL_IS_VOID(value))
642 {
643 JS_ValueToBoolean(context, value, &spinning);
644 }
645
646 // [player showShipModel:OOStringFromJSValue(context, value)];
647 demoShip = [UNIVERSE makeDemoShipWithRole:role spinning:spinning];
648 }
649 }
650 if (demoShip != nil)
651 {
652 if (JS_GetProperty(context, params, "modelPersonality", &value) && !JSVAL_IS_VOID(value))
653 {
654 int personality = 0;
655 JS_ValueToInt32(context,value,&personality);
656 [demoShip setEntityPersonalityInt:personality];
657 }
658 jsval demoShipVal = [demoShip oo_jsValueInContext:context];
659 JS_SetProperty(context, sMissionObject, "displayModel", &demoShipVal);
660 }
661 else
662 {
663 JS_DeleteProperty(context, sMissionObject, "displayModel");
664 }
665
666 JSBool allowInterrupt = NO;
667 // force the allowInterrupt to be YES while in flight
668 if ([player status] == STATUS_IN_FLIGHT)
669 {
670 allowInterrupt = YES;
671 }
672 else
673 {
674 if (JS_GetProperty(context, params, "allowInterrupt", &value) && !JSVAL_IS_VOID(value))
675 {
676 JS_ValueToBoolean(context, value, &allowInterrupt);
677 }
678 }
679
680 if (JS_GetProperty(context, params, "exitScreen", &value) && !JSVAL_IS_VOID(value))
681 {
682 [player setMissionExitScreen:OOGUIScreenIDFromJSValue(context, value)];
683 }
684 else
685 {
686 [player setMissionExitScreen:GUI_SCREEN_STATUS];
687 }
688
689 if (JS_GetProperty(context, params, "screenID", &value) && !JSVAL_IS_VOID(value))
690 {
691 [player setMissionScreenID:OOStringFromJSValue(context, value)];
692 }
693 else
694 {
695 [player clearMissionScreenID];
696 }
697
698 [player clearExtraMissionKeys];
699 if (JS_GetProperty(context, params, "registerKeys", &value) && !JSVAL_IS_VOID(value))
700 {
701 [player setExtraMissionKeys:GetParameterDictionary(context, params, "registerKeys")];
702 }
703
704 JSBool textEntry = NO;
705 if (JS_GetProperty(context, params, "textEntry", &value) && !JSVAL_IS_VOID(value))
706 {
707 JS_ValueToBoolean(context, value, &textEntry);
708 }
709 if (textEntry)
710 {
711 [player setMissionChoiceByTextEntry:YES];
712 }
713 else
714 {
715 [player setMissionChoiceByTextEntry:NO];
716 }
717
718 // Start the mission screen.
719 sCallbackFunction = function;
720 [player setGuiToMissionScreenWithCallback:!JSVAL_IS_NULL(sCallbackFunction)];
721
722 // Apply more settings. (These must be done after starting the screen for legacy reasons.)
723 if (allowInterrupt)
724 {
725 [player allowMissionInterrupt];
726 }
727 NSString *message = GetParameterString(context, params, "message");
728 if (message != nil)
729 {
730 [player addLiteralMissionText:message];
731 }
732 else
733 {
734 NSString *messageKey = GetParameterString(context, params, "messageKey");
735 if (messageKey != nil) [player addMissionText:messageKey];
736 }
737
738 if (!textEntry)
739 {
740 NSDictionary *choices = GetParameterDictionary(context, params, "choices");
741 if (choices == nil)
742 {
743 [player setMissionChoices:GetParameterString(context, params, "choicesKey")];
744 }
745 else
746 {
747 [player setMissionChoicesDictionary:choices];
748 }
749 }
750
751 NSString *firstKey = GetParameterString(context, params, "initialChoicesKey");
752 if (firstKey != nil)
753 {
754 OOGUIRow row = [[UNIVERSE gui] rowForKey:firstKey];
755 if (row != -1)
756 {
757 [[UNIVERSE gui] setSelectedRow:row];
758 }
759 }
760
761 // now clean up!
762 [player setMissionOverlayDescriptor:nil];
764 [player setMissionTitle:nil];
765 [player setMissionMusic:nil];
766
768
769 OOJS_RETURN_BOOL(YES);
770
772}
NSInteger OOGUIRow
static NSDictionary * GetParameterDictionary(JSContext *context, JSObject *object, const char *key)
static NSString * GetParameterString(JSContext *context, JSObject *object, const char *key)
BOOL JSValueToVector(JSContext *context, jsval value, Vector *outVector) NONNULL_FUNC
Definition OOJSVector.m:259
void OOJSPauseTimeLimiter(void)
void OOJSReportWarning(JSContext *context, NSString *format,...)
#define OOJS_RETURN_BOOL(v)
OOINLINE BOOL OOJSValueIsFunction(JSContext *context, jsval value)
void OOJSResumeTimeLimiter(void)
NSPoint OOInternalCoordinatesFromGalactic(Vector galacticCoordinates)
#define CHART_MAX_ZOOM
jsval oo_jsValueInContext:(JSContext *context)
OOJSScript * currentlyRunningScript()
Definition OOJSScript.m:339
OOMusicController * sharedController()
void setMissionMusic:(NSString *missionMusicName)
void setMissionBackgroundDescriptor:(NSDictionary *descriptor)
void setMissionExitScreen:(OOGUIScreenID screen)
void setCustomChartZoom:(OOScalar zoom)
void setMissionBackgroundSpecial:(NSString *special)
void setMissionMusic:(NSString *value)
void addMissionText:(NSString *textKey)
void setExtraMissionKeys:(NSDictionary *keys)
void clearExtraMissionKeys()
NSPoint galaxy_coordinates
void setMissionChoiceByTextEntry:(BOOL enable)
void setGuiToMissionScreenWithCallback:(BOOL callback)
void setMissionScreenID:(NSString *msid)
void setMissionChoices:(NSString *choicesKey)
void setMissionChoicesDictionary:(NSDictionary *choicesDict)
void setMissionTitle:(NSString *value)
void setMissionOverlayDescriptor:(NSDictionary *descriptor)
void setCustomChartCentre:(NSPoint coords)
void setEntityPersonalityInt:(uint16_t value)

References PlayerEntity::addLiteralMissionText:, PlayerEntity::addMissionText:, PlayerEntity::allowMissionInterrupt, CHART_MAX_ZOOM, PlayerEntity::clearExtraMissionKeys, PlayerEntity::clearMissionScreenID, OOJSScript::currentlyRunningScript, PlayerEntity::galaxy_coordinates, GetParameterDictionary(), GetParameterString(), JSValueToVector(), MIN, nil, Entity::oo_jsValueInContext:, OOInternalCoordinatesFromGalactic(), OOJS_ARGV, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_BOOL, OOJSPauseTimeLimiter(), OOJSReportBadArguments(), OOJSReportWarning(), OOJSResumeTimeLimiter(), OOJSValueFromNativeObject(), OOJSValueIsFunction(), OOPlayerForScripting(), OOStringFromJSValue(), sCallbackFunction, sCallbackScript, sCallbackThis, PlayerEntity::setCustomChartCentre:, PlayerEntity::setCustomChartZoom:, ShipEntity::setEntityPersonalityInt:, PlayerEntity::setExtraMissionKeys:, PlayerEntity::setGuiToMissionScreenWithCallback:, PlayerEntity::setMissionBackgroundDescriptor:, PlayerEntity::setMissionBackgroundSpecial:, PlayerEntity::setMissionChoiceByTextEntry:, PlayerEntity::setMissionChoices:, PlayerEntity::setMissionChoicesDictionary:, PlayerEntity::setMissionExitScreen:, OOMusicController::setMissionMusic:, PlayerEntity::setMissionMusic:, PlayerEntity::setMissionOverlayDescriptor:, PlayerEntity::setMissionScreenID:, PlayerEntity::setMissionTitle:, OOMusicController::sharedController, and sMissionObject.

+ Here is the call graph for this function:

◆ MissionRunShipLibrary()

static JSBool MissionRunShipLibrary ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 775 of file OOJSMission.m.

776{
777 OOJS_NATIVE_ENTER(context)
778
780 BOOL OK = YES;
781 if ([player status] != STATUS_DOCKED)
782 {
783 OOJSReportWarning(context, @"Mission.runShipLibrary: must be docked.");
784 OK = NO;
785 }
786 else
787 {
788 [PLAYER setGuiToIntroFirstGo:NO];
789 }
790
792
794}

References OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_BOOL, OOJSReportWarning(), and OOPlayerForScripting().

+ Here is the call graph for this function:

◆ MissionSetInstructions()

static JSBool MissionSetInstructions ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 392 of file OOJSMission.m.

393{
394 return MissionSetInstructionsInternal(context, argc, vp, NO);
395}
static JSBool MissionSetInstructionsInternal(JSContext *context, uintN argc, jsval *vp, BOOL isKey)

References MissionSetInstructionsInternal().

+ Here is the call graph for this function:

◆ MissionSetInstructionsInternal()

static JSBool MissionSetInstructionsInternal ( JSContext * context,
uintN argc,
jsval * vp,
BOOL isKey )
static

Definition at line 398 of file OOJSMission.m.

399{
400 OOJS_NATIVE_ENTER(context)
401
403 NSString *text = nil;
404 NSArray *texts = nil;
405 NSString *missionKey = nil;
406
407 if (EXPECT_NOT(argc == 0))
408 {
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");
410 }
411 else if (EXPECT_NOT(JSVAL_IS_VOID(OOJS_ARGV[0])))
412 {
413 OOJSReportBadArguments(context, @"Mission", isKey ? @"setInstructionsKey" : @"setInstructions", 1, OOJS_ARGV, NULL, @"string or null");
414 return NO;
415 }
416 else if (!JSVAL_IS_NULL(OOJS_ARGV[0]) && JSVAL_IS_OBJECT(OOJS_ARGV[0]))
417 {
418 texts = OOJSNativeObjectFromJSValue(context, OOJS_ARGV[0]);
419 }
420 else
421 {
422 text = OOStringFromJSValue(context, OOJS_ARGV[0]);
423 }
424
425 if (argc > 1)
426 {
427 missionKey = OOStringFromJSValueEvenIfNull(context, OOJS_ARGV[1]);
428 }
429 else
430 {
431 missionKey = [[OOJSScript currentlyRunningScript] name];
432 }
433
434 if (text != nil)
435 {
436 if (isKey)
437 {
438 [player setMissionDescription:text forMission:missionKey];
439 }
440 else
441 {
442 [player setMissionInstructions:text forMission:missionKey];
443 }
444 }
445 else if (texts != nil && !isKey)
446 {
447 [player setMissionInstructionsList:texts forMission:missionKey];
448 }
449 else
450 {
451 [player clearMissionDescriptionForMission:missionKey];
452 }
453
455
457}
id OOJSNativeObjectFromJSValue(JSContext *context, jsval value)
NSString * OOStringFromJSValueEvenIfNull(JSContext *context, jsval value)
NSString * name
Definition OOJSScript.h:37
void setMissionInstructions:forMission:(NSString *text,[forMission] NSString *key)
void clearMissionDescriptionForMission:(NSString *key)
void setMissionInstructionsList:forMission:(NSArray *list,[forMission] NSString *key)
void setMissionDescription:forMission:(NSString *textKey,[forMission] NSString *key)

References PlayerEntity::clearMissionDescriptionForMission:, OOJSScript::currentlyRunningScript, EXPECT_NOT, OOJSScript::name, nil, OOJS_ARGV, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_VOID, OOJSNativeObjectFromJSValue(), OOJSReportBadArguments(), OOJSReportWarning(), OOPlayerForScripting(), OOStringFromJSValue(), OOStringFromJSValueEvenIfNull(), PlayerEntity::setMissionDescription:forMission:, PlayerEntity::setMissionInstructions:forMission:, and PlayerEntity::setMissionInstructionsList:forMission:.

Referenced by MissionSetInstructions(), and MissionSetInstructionsKey().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MissionSetInstructionsKey()

static JSBool MissionSetInstructionsKey ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 385 of file OOJSMission.m.

386{
387 return MissionSetInstructionsInternal(context, argc, vp, YES);
388}

References MissionSetInstructionsInternal().

+ Here is the call graph for this function:

◆ MissionSetProperty()

static JSBool MissionSetProperty ( JSContext * context,
JSObject * this,
jsid propID,
JSBool strict,
jsval * value )
static

Definition at line 224 of file OOJSMission.m.

225{
226 if (!JSID_IS_INT(propID)) return YES;
227
228 OOJS_NATIVE_ENTER(context)
229
230 OOGUIScreenID exitScreen;
232
233 switch (JSID_TO_INT(propID))
234 {
236 exitScreen = OOGUIScreenIDFromJSValue(context, *value);
237 [player setMissionExitScreen:exitScreen];
238 return YES;
239
240 default:
242 }
243
244 OOJSReportBadPropertyValue(context, this, propID, sMissionProperties, *value);
245 return NO;
246
248}
OOINLINE OOGUIScreenID OOGUIScreenIDFromJSValue(JSContext *context, jsval value)
void OOJSReportBadPropertyValue(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec, jsval value)
OOGUIScreenID

References kMission_exitScreen, OOGUIScreenIDFromJSValue(), OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJSReportBadPropertySelector(), OOJSReportBadPropertyValue(), OOPlayerForScripting(), PlayerEntity::setMissionExitScreen:, and sMissionProperties.

+ Here is the call graph for this function:

◆ MissionUnmarkSystem()

static JSBool MissionUnmarkSystem ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 305 of file OOJSMission.m.

306{
307 OOJS_NATIVE_ENTER(context)
308
310 unsigned i;
311 int dest;
312
313 // two pass. Once to validate, once to apply if they validate
314 for (i=0;i<argc;i++)
315 {
316 if (!JS_ValueToInt32(context, OOJS_ARGV[i], &dest))
317 {
318 JS_ClearPendingException(context); // or JS_ValueToInt32 exception crashes JS engine
319 if (!JSVAL_IS_OBJECT(OOJS_ARGV[i]))
320 {
321 OOJSReportBadArguments(context, @"Mission", @"unmarkSystem", MIN(argc, 1U), OOJS_ARGV, nil, @"numbers or objects");
322 return NO;
323 }
324 }
325 }
326
327 BOOL result = YES;
328 for (i=0;i<argc;i++)
329 {
330 if (JS_ValueToInt32(context, OOJS_ARGV[i], &dest))
331 {
332 OOStandardsDeprecated(@"Use of numbers for mission.unmarkSystem is deprecated");
333 if (!OOEnforceStandards())
334 {
335 if (![player removeMissionDestinationMarker:[player defaultMarker:dest]]) {
336 result = NO;
337 }
338 }
339 }
340 else // must be object, from above
341 {
342 JS_ClearPendingException(context); // or JS_ValueToInt32 exception crashes JS engine
343 NSDictionary *marker = OOJSNativeObjectFromJSObject(context, JSVAL_TO_OBJECT(OOJS_ARGV[i]));
344 OOSystemID system = [marker oo_intForKey:@"system" defaultValue:-1];
345 if (system >= 0)
346 {
347 if (![player removeMissionDestinationMarker:marker]) {
348 result = NO;
349 }
350 }
351 }
352 }
353
354 OOJS_RETURN_BOOL(result);
355
357}

References MIN, nil, OOEnforceStandards(), OOJS_ARGV, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_BOOL, OOJSNativeObjectFromJSObject(), OOJSReportBadArguments(), OOPlayerForScripting(), and OOStandardsDeprecated().

+ Here is the call graph for this function:

Variable Documentation

◆ sCallbackFunction

jsval sCallbackFunction
static

Definition at line 54 of file OOJSMission.m.

Referenced by InitOOJSMission(), MissionRunCallback(), and MissionRunScreen().

◆ sCallbackScript

OOJSScript* sCallbackScript = nil
static

Definition at line 56 of file OOJSMission.m.

Referenced by MissionRunCallback(), and MissionRunScreen().

◆ sCallbackThis

jsval sCallbackThis
static

Definition at line 55 of file OOJSMission.m.

Referenced by InitOOJSMission(), MissionRunCallback(), and MissionRunScreen().

◆ sMissionClass

JSClass sMissionClass
static
Initial value:
=
{
"Mission",
0,
JS_PropertyStub,
JS_PropertyStub,
JS_EnumerateStub,
JS_ResolveStub,
JS_ConvertStub,
JS_FinalizeStub
}
static JSBool MissionSetProperty(JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value)
static JSBool MissionGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)

Definition at line 60 of file OOJSMission.m.

61{
62 "Mission",
63 0,
64
65 JS_PropertyStub,
66 JS_PropertyStub,
69 JS_EnumerateStub,
70 JS_ResolveStub,
71 JS_ConvertStub,
72 JS_FinalizeStub
73};

Referenced by InitOOJSMission().

◆ sMissionMethods

JSFunctionSpec sMissionMethods[]
static
Initial value:
=
{
{ "addMessageText", MissionAddMessageText, 1 },
{ "markSystem", MissionMarkSystem, 1 },
{ "runScreen", MissionRunScreen, 1 },
{ "setInstructions", MissionSetInstructions, 1 },
{ "setInstructionsKey", MissionSetInstructionsKey, 1 },
{ "unmarkSystem", MissionUnmarkSystem, 1 },
{ "runShipLibrary", MissionRunShipLibrary, 0 },
{ 0 }
}
static JSBool MissionRunShipLibrary(JSContext *context, uintN argc, jsval *vp)
static JSBool MissionMarkSystem(JSContext *context, uintN argc, jsval *vp)
static JSBool MissionUnmarkSystem(JSContext *context, uintN argc, jsval *vp)
static JSBool MissionSetInstructions(JSContext *context, uintN argc, jsval *vp)
static JSBool MissionAddMessageText(JSContext *context, uintN argc, jsval *vp)
static JSBool MissionSetInstructionsKey(JSContext *context, uintN argc, jsval *vp)
static JSBool MissionRunScreen(JSContext *context, uintN argc, jsval *vp)

Definition at line 94 of file OOJSMission.m.

95{
96 // JS name Function min args
97 { "addMessageText", MissionAddMessageText, 1 },
98 { "markSystem", MissionMarkSystem, 1 },
99 { "runScreen", MissionRunScreen, 1 }, // the callback function is optional!
100 { "setInstructions", MissionSetInstructions, 1 },
101 { "setInstructionsKey", MissionSetInstructionsKey, 1 },
102 { "unmarkSystem", MissionUnmarkSystem, 1 },
103 { "runShipLibrary", MissionRunShipLibrary, 0 },
104 { 0 }
105};

Referenced by InitOOJSMission().

◆ sMissionObject

JSObject* sMissionObject
static

Definition at line 58 of file OOJSMission.m.

Referenced by InitOOJSMission(), and MissionRunScreen().

◆ sMissionProperties

JSPropertySpec sMissionProperties[]
static
Initial value:
=
{
{ 0 }
}
#define OOJS_PROP_READWRITE_CB
#define OOJS_PROP_READONLY_CB

Definition at line 84 of file OOJSMission.m.

85{
86 // JS name ID flags
90 { 0 }
91};

Referenced by InitOOJSMission(), MissionGetProperty(), and MissionSetProperty().