@@ -696,6 +696,18 @@ - (void) setSystemID:(OOSystemID) sid
696696}
697697
698698
699+ - (OOSystemID) previousSystemID
700+ {
701+ return previous_system_id;
702+ }
703+
704+
705+ - (void ) setPreviousSystemID : (OOSystemID) sid
706+ {
707+ previous_system_id = sid;
708+ }
709+
710+
699711- (OOSystemID) targetSystemID
700712{
701713 return target_system_id;
@@ -909,13 +921,16 @@ - (NSDictionary *) commanderDataDictionary
909921 NSString *gal_id = [NSString stringWithFormat: @" %u " , galaxy_number];
910922 NSString *sys_id = [NSString stringWithFormat: @" %d " , system_id];
911923 NSString *tgt_id = [NSString stringWithFormat: @" %d " , target_system_id];
924+ NSString *prv_id = [NSString stringWithFormat: @" %d " , previous_system_id];
925+
912926 // Variable requiredCargoSpace not suitable for Oolite as it currently stands: it retroactively changes a savegame cargo space.
913927 // unsigned passenger_space = [[OOEquipmentType equipmentTypeWithIdentifier:@"EQ_PASSENGER_BERTH"] requiredCargoSpace];
914928 // if (passenger_space == 0) passenger_space = PASSENGER_BERTH_SPACE;
915929
916930 [result setObject: gal_id forKey: @" galaxy_id" ];
917931 [result setObject: sys_id forKey: @" system_id" ];
918932 [result setObject: tgt_id forKey: @" target_id" ];
933+ [result setObject: prv_id forKey: @" previous_system_id" ];
919934 [result setObject: [NSNumber numberWithFloat: saved_chart_zoom] forKey: @" chart_zoom" ];
920935 [result setObject: [NSNumber numberWithInt: ANA_mode] forKey: @" chart_ana_mode" ];
921936 [result setObject: [NSNumber numberWithInt: longRangeChartMode] forKey: @" chart_colour_mode" ];
@@ -1260,6 +1275,7 @@ - (BOOL)setCommanderDataFromDictionary:(NSDictionary *) dict
12601275 if (longRangeChartMode == OOLRC_MODE_UNKNOWN ) longRangeChartMode = OOLRC_MODE_SUNCOLOR ;
12611276
12621277 target_system_id = [dict oo_intForKey: @" target_id" defaultValue: system_id];
1278+ previous_system_id = [dict oo_intForKey: @" previous_system_id" defaultValue: system_id];
12631279 info_system_id = target_system_id;
12641280 coord_vals = ScanTokensFromString ([[UNIVERSE systemManager ] getProperty: @" coordinates" forSystem: target_system_id inGalaxy: galaxy_number]);
12651281 cursor_coordinates.x = [coord_vals oo_unsignedCharAtIndex: 0 ];
@@ -2414,6 +2430,8 @@ - (void) dealloc
24142430
24152431 DESTROY (dockingReport);
24162432
2433+ DESTROY (_jumpCause);
2434+
24172435 [self destroySound ];
24182436
24192437 DESTROY (scannedWormholes);
@@ -3874,7 +3892,7 @@ - (void) performWitchspaceExitUpdates:(OOTimeDelta)delta_t
38743892 // similarly reset the misjump range to the traditional 0.5
38753893 [self setScriptedMisjumpRange: 0.5 ];
38763894
3877- [self doScriptEvent: OOJSID (" shipExitedWitchspace" )];
3895+ [self doScriptEvent: OOJSID (" shipExitedWitchspace" ) withArgument: [ self jumpCause ] ];
38783896
38793897 [self doBookkeeping: delta_t ]; // arrival frame updates
38803898
@@ -7489,9 +7507,14 @@ - (void) enterGalacticWitchspace
74897507
74907508
74917509 [self setStatus: STATUS_ENTERING_WITCHSPACE ];
7492- ShipScriptEventNoCx (self, " shipWillEnterWitchspace" , OOJSSTR (" galactic jump" ), INT_TO_JSVAL (destGalaxy));
7510+ JSContext *context = OOJSAcquireContext ();
7511+ [self setJumpCause: @" galactic jump" ];
7512+ [self setPreviousSystemID: [self currentSystemID ]];
7513+ ShipScriptEvent (context, self, " shipWillEnterWitchspace" , STRING_TO_JSVAL (JS_InternString (context, [[self jumpCause ] UTF8String ])), INT_TO_JSVAL (destGalaxy));
7514+ OOJSRelinquishContext (context);
7515+
74937516 [self noteCompassLostTarget ];
7494-
7517+
74957518 [self witchStart ];
74967519
74977520 [UNIVERSE removeAllEntitiesExceptPlayer ];
@@ -7585,7 +7608,11 @@ - (void) enterWormhole:(WormholeEntity *) w_hole
75857608 wormhole = [w_hole retain ];
75867609 [self addScannedWormhole: wormhole];
75877610 [self setStatus: STATUS_ENTERING_WITCHSPACE ];
7588- ShipScriptEventNoCx (self, " shipWillEnterWitchspace" , OOJSSTR (" wormhole" ), INT_TO_JSVAL ([w_hole destination ]));
7611+ JSContext *context = OOJSAcquireContext ();
7612+ [self setJumpCause: @" wormhole" ];
7613+ [self setPreviousSystemID: [self currentSystemID ]];
7614+ ShipScriptEvent (context, self, " shipWillEnterWitchspace" , STRING_TO_JSVAL (JS_InternString (context, [[self jumpCause ] UTF8String ])), INT_TO_JSVAL ([w_hole destination ]));
7615+ OOJSRelinquishContext (context);
75897616 if ([self scriptedMisjump ])
75907617 {
75917618 misjump = YES ; // a script could just have changed this to true;
@@ -7653,7 +7680,11 @@ - (void) enterWitchspace
76537680 [self addScannedWormhole: wormhole];
76547681
76557682 [self setStatus: STATUS_ENTERING_WITCHSPACE ];
7656- ShipScriptEventNoCx (self, " shipWillEnterWitchspace" , OOJSSTR (" standard jump" ), INT_TO_JSVAL (jumpTarget));
7683+ JSContext *context = OOJSAcquireContext ();
7684+ [self setJumpCause: @" standard jump" ];
7685+ [self setPreviousSystemID: [self currentSystemID ]];
7686+ ShipScriptEvent (context, self, " shipWillEnterWitchspace" , STRING_TO_JSVAL (JS_InternString (context, [[self jumpCause ] UTF8String ])), INT_TO_JSVAL (jumpTarget));
7687+ OOJSRelinquishContext (context);
76577688
76587689 [self updateSystemMemory ];
76597690 NSUInteger legality = [self legalStatusOfCargoList ];
@@ -7854,7 +7885,7 @@ - (void) leaveWitchspace
78547885 [self doScriptEvent: OOJSID (" playerEnteredNewGalaxy" ) withArgument: [NSNumber numberWithUnsignedInt: galaxy_number]];
78557886 }
78567887
7857- [self doScriptEvent: OOJSID (" shipWillExitWitchspace" )];
7888+ [self doScriptEvent: OOJSID (" shipWillExitWitchspace" ) withArgument: [ self jumpCause ] ];
78587889 [UNIVERSE setUpBreakPattern: [self breakPatternPosition ] orientation: orientation forDocking: NO ];
78597890}
78607891
@@ -12955,6 +12986,20 @@ - (void) setDockTarget:(ShipEntity *)entity
1295512986}
1295612987
1295712988
12989+ - (NSString *) jumpCause
12990+ {
12991+ return _jumpCause;
12992+ }
12993+
12994+
12995+ - (void ) setJumpCause:(NSString *)value
12996+ {
12997+ NSParameterAssert (value != nil );
12998+ [_jumpCause autorelease ];
12999+ _jumpCause = [value copy ];
13000+ }
13001+
13002+
1295813003- (NSString *) commanderName
1295913004{
1296013005 return _commanderName;
0 commit comments