From 8e2edf4e4cf0dd5960adf5da92e1d5d455e1cf81 Mon Sep 17 00:00:00 2001 From: phkb Date: Mon, 20 Jul 2020 17:04:35 +1000 Subject: [PATCH] Provides an override mechanism for the amount of time a rescue in an escape pod takes. (#353) --- src/Core/Entities/PlayerEntity.h | 5 +++++ src/Core/Entities/PlayerEntity.m | 31 +++++++++++++++++++++++++++++-- src/Core/Scripting/OOJSPlayer.m | 15 ++++++++++++++- 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/src/Core/Entities/PlayerEntity.h b/src/Core/Entities/PlayerEntity.h index 4a68c657f..37e157a43 100644 --- a/src/Core/Entities/PlayerEntity.h +++ b/src/Core/Entities/PlayerEntity.h @@ -416,6 +416,8 @@ typedef enum double ship_clock; double ship_clock_adjust; + double escape_pod_rescue_time; + double fps_check_time; int fps_counter; double last_fps_check_time; @@ -902,6 +904,9 @@ typedef enum - (BOOL) clockAdjusting; - (void) addToAdjustTime:(double) seconds ; +- (double) escapePodRescueTime; +- (void) setEscapePodRescueTime:(double) seconds; + - (NSString *) dial_clock; - (NSString *) dial_clock_adjusted; - (NSString *) dial_fpsinfo; diff --git a/src/Core/Entities/PlayerEntity.m b/src/Core/Entities/PlayerEntity.m index 5bd2d6141..4f9343e7f 100644 --- a/src/Core/Entities/PlayerEntity.m +++ b/src/Core/Entities/PlayerEntity.m @@ -1099,6 +1099,9 @@ - (NSDictionary *) commanderDataDictionary //custom view no. [result oo_setUnsignedInteger:_customViewIndex forKey:@"custom_view_index"]; + // escape pod rescue time + [result oo_setFloat:[self escapePodRescueTime] forKey:@"escape_pod_rescue_time"]; + //local market for main station if ([[UNIVERSE station] localMarket]) [result setObject:[[[UNIVERSE station] localMarket] saveStationAmounts] forKey:@"localMarket"]; @@ -1591,6 +1594,8 @@ - (BOOL)setCommanderDataFromDictionary:(NSDictionary *) dict ship_clock = [dict oo_doubleForKey:@"ship_clock" defaultValue:PLAYER_SHIP_CLOCK_START]; fps_check_time = ship_clock; + escape_pod_rescue_time = [dict oo_doubleForKey:@"escape_pod_rescue_time" defaultValue:0.0]; + // role weights [roleWeights release]; roleWeights = [[dict oo_arrayForKey:@"role_weights"] mutableCopy]; @@ -2058,7 +2063,8 @@ - (BOOL) setUpAndConfirmOK:(BOOL)stopOnError saveGame:(BOOL)saveGame ship_clock += [nowDate secondOfMinute]; fps_check_time = ship_clock; ship_clock_adjust = 0.0; - + escape_pod_rescue_time = 0.0; + isSpeechOn = OOSPEECHSETTINGS_OFF; #if OOLITE_ESPEAK voice_gender_m = YES; @@ -4788,6 +4794,17 @@ - (void) addToAdjustTime:(double)seconds } +- (double) escapePodRescueTime +{ + return escape_pod_rescue_time; +} + + +- (void) setEscapePodRescueTime:(double)seconds +{ + escape_pod_rescue_time = seconds; +} + - (NSString *) dial_clock { return ClockToString(ship_clock, ship_clock_adjust > 0); @@ -6473,7 +6490,17 @@ - (ShipEntity *) launchEscapeCapsule */ [UNIVERSE setBlockJSPlayerShipProps:YES]; // no player.ship properties while inside the pod! - ship_clock_adjust += 43200 + 5400 * (ranrot_rand() & 127); // add up to 8 days until rescue! + // if a specific amount of time has been provided for the rescue, use it now + if (escape_pod_rescue_time > 0) + { + ship_clock_adjust += escape_pod_rescue_time; + escape_pod_rescue_time = 0; // reset value + } + else + { + // otherwise, use the default time calc + ship_clock_adjust += 43200 + 5400 * (ranrot_rand() & 127); // add up to 8 days until rescue! + } dockingClearanceStatus = DOCKING_CLEARANCE_STATUS_NOT_REQUIRED; flightSpeed = fmin(flightSpeed, maxFlightSpeed); diff --git a/src/Core/Scripting/OOJSPlayer.m b/src/Core/Scripting/OOJSPlayer.m index fb4bb7f19..7b73badcc 100644 --- a/src/Core/Scripting/OOJSPlayer.m +++ b/src/Core/Scripting/OOJSPlayer.m @@ -95,6 +95,7 @@ kPlayer_contractReputationPrecise, // reputation for cargo contracts, float, read only kPlayer_credits, // credit balance, float, read/write kPlayer_dockingClearanceStatus, // docking clearance status, string, read only + kPlayer_escapePodRescueTime, // override for the amount of time an escape pod rescue takes, read/write kPlayer_legalStatus, // legalStatus, string, read-only kPlayer_name, // Player name, string, read/write kPlayer_parcelReputation, // reputation for parcel contracts, integer, read-only @@ -122,6 +123,7 @@ { "contractReputationPrecise", kPlayer_contractReputationPrecise, OOJS_PROP_READONLY_CB }, { "credits", kPlayer_credits, OOJS_PROP_READWRITE_CB }, { "dockingClearanceStatus", kPlayer_dockingClearanceStatus, OOJS_PROP_READONLY_CB }, + { "escapePodRescueTime", kPlayer_escapePodRescueTime, OOJS_PROP_READWRITE_CB }, { "legalStatus", kPlayer_legalStatus, OOJS_PROP_READONLY_CB }, { "name", kPlayer_name, OOJS_PROP_READWRITE_CB }, { "parcelReputation", kPlayer_parcelReputation, OOJS_PROP_READONLY_CB }, @@ -249,6 +251,9 @@ static JSBool PlayerGetProperty(JSContext *context, JSObject *this, jsid propID, *value = OOJSValueFromBOOL([player alertFlags] & ALERT_FLAG_HOSTILES); return YES; + case kPlayer_escapePodRescueTime: + return JS_NewNumberValue(context, [player escapePodRescueTime], value); + case kPlayer_trumbleCount: return JS_NewNumberValue(context, [player trumbleCount], value); @@ -345,7 +350,15 @@ static JSBool PlayerSetProperty(JSContext *context, JSObject *this, jsid propID, return YES; } break; - + + case kPlayer_escapePodRescueTime: + if (JS_ValueToNumber(context, *value, &fValue)) + { + [player setEscapePodRescueTime:fValue]; + return YES; + } + break; + default: OOJSReportBadPropertySelector(context, this, propID, sPlayerProperties); return NO;