Skip to content

Commit

Permalink
Provides an override mechanism for the amount of time a rescue in an …
Browse files Browse the repository at this point in the history
…escape pod takes. (#353)
  • Loading branch information
phkb authored Jul 20, 2020
1 parent ba63810 commit 8e2edf4
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/Core/Entities/PlayerEntity.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
31 changes: 29 additions & 2 deletions src/Core/Entities/PlayerEntity.m
Original file line number Diff line number Diff line change
Expand Up @@ -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"];

Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
15 changes: 14 additions & 1 deletion src/Core/Scripting/OOJSPlayer.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 },
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 8e2edf4

Please sign in to comment.