514{
516
518 JSValueConst function = JS_NULL;
519 JSValue value = JS_UNDEFINED;
520 JSValue params = JS_UNDEFINED;
521
522
523 if ([player status] == STATUS_START_GAME) {
524
525
527 }
528
529
530
532 params = JS_ToObject(context,
OOJS_ARGV[0]);
533 if (JS_IsException(params)) {
534 JS_FreeValue(context, JS_GetException(context));
535 params = JS_UNDEFINED;
536 }
537 }
538 if (!JS_IsObject(params)) {
540 return JS_EXCEPTION;
541 }
542
543 if (argc > 1)
546 JS_FreeValue(context, params);
548 return JS_EXCEPTION;
549 }
550
551
553
554 if (!JS_IsNull(function)) {
555
556
557
558
559
560
561
562
565 if (argc > 2) {
567 } else {
570 JS_FreeValue(context, scriptValue);
571 }
572 }
573
574
576 if (!JS_IsUndefined(value)) {
578 } else {
580 if (titleKey !=
nil) {
581 NSString* message = [[UNIVERSE missiontext] oo_stringForKey:titleKey];
582 if (message !=
nil) {
584 } else {
585 OOJSReportWarning(context,
@"Mission.runScreen: titleKey '%@' has no entry in missiontext.plist.", titleKey);
586 }
587 }
588 }
589 JS_FreeValue(context, value);
590
595
596 value =
GetParameter(context, params,
"customChartZoom");
597 if (!JS_IsUndefined(value)) {
598 double zoom;
599 if (JS_ToFloat64(context, &zoom, value) == 0) {
602 } else {
603 OOJSReportWarning(context,
@"Mission.runScreen: invalid customChartZoom value specified.");
605 }
606 } else {
607 JS_FreeValue(context, JS_GetException(context));
608 }
609 }
610 JS_FreeValue(context, value);
611
612 value =
GetParameter(context, params,
"customChartCentre");
613 if (!JS_IsUndefined(value)) {
616 NSPoint coords = { vValue.
x, vValue.
y };
618 } else {
620 OOJSReportWarning(context,
@"Mission.runScreen: invalid value for customChartCentre. Must be valid vector. Defaulting to current location.");
621 }
622 }
623 JS_FreeValue(context, value);
624
625 value =
GetParameter(context, params,
"customChartCentreInLY");
626 if (!JS_IsUndefined(value)) {
631 } else {
633 OOJSReportWarning(context,
@"Mission.runScreen: invalid value for customChartCentreInLY. Must be valid vector. Defaulting to current location.");
634 }
635 }
636 JS_FreeValue(context, value);
637
638 [UNIVERSE removeDemoShips];
639
642 if (!JS_IsUndefined(value)) {
643 if ([player status] == STATUS_IN_FLIGHT && JS_IsString(value)) {
644 OOJSReportWarning(context,
@"Mission.runScreen: model cannot be displayed while in flight.");
645 } else {
647
648 BOOL spinning = YES;
650
651
652 demoShip = [UNIVERSE makeDemoShipWithRole:role spinning:spinning];
653 }
654 }
655 JS_FreeValue(context, value);
656
657 if (demoShip !=
nil) {
658 value =
GetParameter(context, params,
"modelPersonality");
659 if (!JS_IsUndefined(value)) {
660 int32_t personality = 0;
661 if (!
OOJSValueToInt32(context, value, &personality) && JS_HasException(context)) {
662 JS_FreeValue(context, JS_GetException(context));
663 }
665 }
666 JS_FreeValue(context, value);
667
669 if (JS_SetPropertyStr(context,
sMissionObject,
"displayModel", demoShipVal) < 0) {
671 }
672 } else {
675 }
676 }
677
678 BOOL allowInterrupt = NO;
679
680 if ([player status] == STATUS_IN_FLIGHT) {
681 allowInterrupt = YES;
682 } else {
684 }
685
687 if (!JS_IsUndefined(value)) {
689 } else {
691 }
692 JS_FreeValue(context, value);
693
695 if (!JS_IsUndefined(value)) {
697 } else {
699 }
700 JS_FreeValue(context, value);
701
704 if (!JS_IsUndefined(value)) {
706 }
707 JS_FreeValue(context, value);
708
709 BOOL textEntry = NO;
711 if (textEntry) {
713 } else {
715 }
716
717
720
721
722 if (allowInterrupt) {
724 }
726 if (message !=
nil) {
728 } else {
730 if (messageKey !=
nil)
732 }
733
734 if (!textEntry) {
736 if (choices ==
nil) {
738 } else {
740 }
741 }
742
744 if (firstKey !=
nil) {
745 OOGUIRow row = [[UNIVERSE gui] rowForKey:firstKey];
746 if (row != -1) {
747 [[UNIVERSE gui] setSelectedRow:row];
748 }
749 }
750
751
756
757 JS_FreeValue(context, params);
758
760
762
764}
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
void OOJSPauseTimeLimiter(void)
void OOJSReportWarning(JSContext *context, NSString *format,...)
#define OOJS_RETURN_BOOL(v)
OOINLINE BOOL OOJSValueToInt32(JSContext *context, jsval value, int32_t *outValue)
OOINLINE BOOL OOJSValueIsFunction(JSContext *context, jsval value)
void OOJSResumeTimeLimiter(void)
NSPoint OOInternalCoordinatesFromGalactic(Vector galacticCoordinates)
static void GetParameterBool(JSContext *context, JSValueConst object, const char *key, BOOL *outValue)
jsval oo_jsValueInContext:(JSContext *context)
OOJSScript * currentlyRunningScript()
OOMusicController * sharedController()
void setMissionMusic:(NSString *missionMusicName)
void setMissionBackgroundDescriptor:(NSDictionary *descriptor)
void allowMissionInterrupt()
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 clearMissionScreenID()
void setCustomChartCentre:(NSPoint coords)
void setEntityPersonalityInt:(uint16_t value)