Oolite
Loading...
Searching...
No Matches
PlayerEntity(OOPrivate) Category Reference

Instance Methods

(void) - setExtraEquipmentFromFlags
(void) - doTradeIn:forPriceFactor:
(void) - updateMovementFlags
(void) - updateAlertCondition
(void) - updateFuelScoops:
(void) - updateClocks:
(void) - checkScriptsIfAppropriate
(void) - updateTrumbles:
(void) - performAutopilotUpdates:
(void) - performInFlightUpdates:
(void) - performWitchspaceCountdownUpdates:
(void) - performWitchspaceExitUpdates:
(void) - performLaunchingUpdates:
(void) - performDockingUpdates:
(void) - performDeadUpdates:
(void) - gameOverFadeToBW
(void) - updateTargeting
(void) - showGameOver
(void) - updateWormholes
(void) - updateAlertConditionForNearbyEntities
(BOOL) - checkEntityForMassLock:withScanClass:
(void) - showMarketScreenHeaders
(void) - showMarketScreenDataLine:forGood:inMarket:holdQuantity:
(void) - showMarketCashAndLoadLine
(BOOL) - tryBuyingItem:
(NSArray *) - contractsListForScriptingFromArray:forCargo:
(void) - prepareMarkedDestination:marker:
(void) - witchStart
(void) - witchJumpTo:misjump:
(void) - witchEnd
(double) - hyperspaceJumpDistance
(OOFuelQuantity) - fuelRequiredForJump
(void) - noteCompassLostTarget

Detailed Description

Definition at line 109 of file PlayerEntity.m.

Method Documentation

◆ checkEntityForMassLock:withScanClass:

- (BOOL) checkEntityForMassLock: (Entity *) ent
withScanClass: (int) scanClass 

Extends class PlayerEntity.

Definition at line 3014 of file PlayerEntity.m.

3014 :(Entity*)ent withScanClass:(int)theirClass
3015{
3016 BOOL massLocked = NO;
3017 BOOL entIsCloakedShip = [ent isShip] && [(ShipEntity*)ent isCloaked];
3018
3019 if (EXPECT_NOT([ent isStellarObject])) {
3020 Entity<OOStellarBody>* stellar = (Entity<OOStellarBody>*)ent;
3021 if (EXPECT([stellar planetType] != STELLAR_TYPE_MINIATURE)) {
3022 double dist = stellar->zero_distance;
3023 double rad = stellar->collision_radius;
3024 double factor = ([stellar isSun]) ? 2.0 : 4.0;
3025 // plus ensure mass lock when 25 km or less from the surface of small stellar bodies
3026 // dist is a square distance so it needs to be compared to (rad+25000) * (rad+25000)!
3027 if (dist < rad * rad * factor || dist < rad * rad + 50000 * rad + 625000000) {
3028 massLocked = YES;
3029 }
3030 }
3031 } else if (theirClass != CLASS_NO_DRAW) {
3032 if (EXPECT_NOT(entIsCloakedShip)) {
3033 theirClass = CLASS_NO_DRAW;
3034 }
3035 }
3036
3037 if (!massLocked && ent->zero_distance <= SCANNER_MAX_RANGE2) {
3038 switch (theirClass) {
3039 case CLASS_NO_DRAW:
3040 // cloaked ships do mass lock! - Nikos 20200718
3041 if (entIsCloakedShip && ![ent isPlayer]) {
3042 massLocked = YES;
3043 }
3044 break;
3045 case CLASS_PLAYER:
3046 case CLASS_BUOY:
3047 case CLASS_ROCK:
3048 case CLASS_CARGO:
3049 case CLASS_MINE:
3050 case CLASS_VISUAL_EFFECT:
3051 break;
3052
3053 case CLASS_THARGOID:
3054 case CLASS_MISSILE:
3055 case CLASS_STATION:
3056 case CLASS_POLICE:
3057 case CLASS_MILITARY:
3058 case CLASS_WORMHOLE:
3059 default:
3060 massLocked = YES;
3061 break;
3062 }
3063 }
3064
3065 return massLocked;
3066}
#define SCANNER_MAX_RANGE2
Definition Entity.h:54
#define EXPECT_NOT(x)
#define EXPECT(x)
@ STELLAR_TYPE_MINIATURE
GLfloat collision_radius
Definition Entity.h:107
BOOL isSun()
Definition Entity.m:155
GLfloat zero_distance
Definition Entity.h:104
unsigned isShip
Definition Entity.m:125
BOOL isCloaked()
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque

References Entity::collision_radius, EXPECT, EXPECT_NOT, ShipEntity::isCloaked, Entity::isShip, Entity::isSun, SCANNER_MAX_RANGE2, STELLAR_TYPE_MINIATURE, and Entity::zero_distance.

Referenced by updateAlertConditionForNearbyEntities.

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

◆ checkScriptsIfAppropriate

- (void) checkScriptsIfAppropriate

Extends class PlayerEntity.

Definition at line 3160 of file PlayerEntity.m.

3161{
3162 if (script_time <= script_time_check)
3163 return;
3164
3165 if ([self status] != STATUS_IN_FLIGHT) {
3166 switch (gui_screen) {
3167 // Screens where no world script tickles are performed
3168 case GUI_SCREEN_MAIN:
3169 case GUI_SCREEN_INTRO1:
3170 case GUI_SCREEN_SHIPLIBRARY:
3171 case GUI_SCREEN_KEYBOARD:
3172 case GUI_SCREEN_NEWGAME:
3173 case GUI_SCREEN_OXZMANAGER:
3174 case GUI_SCREEN_MARKET:
3175 case GUI_SCREEN_MARKETINFO:
3176 case GUI_SCREEN_OPTIONS:
3177 case GUI_SCREEN_GAMEOPTIONS:
3178 case GUI_SCREEN_LOAD:
3179 case GUI_SCREEN_SAVE:
3180 case GUI_SCREEN_SAVE_OVERWRITE:
3181 case GUI_SCREEN_STICKMAPPER:
3182 case GUI_SCREEN_STICKPROFILE:
3183 case GUI_SCREEN_MISSION:
3184 case GUI_SCREEN_REPORT:
3185 case GUI_SCREEN_KEYBOARD_CONFIRMCLEAR:
3186 case GUI_SCREEN_KEYBOARD_CONFIG:
3187 case GUI_SCREEN_KEYBOARD_ENTRY:
3188 case GUI_SCREEN_KEYBOARD_LAYOUT:
3189 return;
3190
3191 // Screens from which it's safe to jump to the mission screen
3192 // case GUI_SCREEN_CONTRACTS:
3193 case GUI_SCREEN_EQUIP_SHIP:
3194 case GUI_SCREEN_INTERFACES:
3195 case GUI_SCREEN_MANIFEST:
3196 case GUI_SCREEN_SHIPYARD:
3197 case GUI_SCREEN_LONG_RANGE_CHART:
3198 case GUI_SCREEN_SHORT_RANGE_CHART:
3199 case GUI_SCREEN_STATUS:
3200 case GUI_SCREEN_SYSTEM_DATA:
3201 // Test passed, we can run scripts. Nothing to do here.
3202 break;
3203 }
3204 }
3205
3206 // Test either passed or never ran, run scripts.
3207 [self checkScript];
3208 script_time_check += script_time_interval;
3209}

References PlayerEntity::checkScript, and checkScriptsIfAppropriate.

Referenced by checkScriptsIfAppropriate, setExtraEquipmentFromFlags, and PlayerEntity::update:.

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

◆ contractsListForScriptingFromArray:forCargo:

- (NSArray *) contractsListForScriptingFromArray: (NSArray *) contractsArray
forCargo: (BOOL) forCargo 

Extends class PlayerEntity.

Definition at line 7443 of file PlayerEntity.m.

7443 :(NSArray*)contracts_array forCargo:(BOOL)forCargo
7444{
7445 NSMutableArray* result = [NSMutableArray array];
7446 NSUInteger i;
7447
7448 for (i = 0; i < [contracts_array count]; i++) {
7449 NSMutableDictionary* contract = [NSMutableDictionary dictionaryWithCapacity:10];
7450 NSDictionary* dict = [contracts_array oo_dictionaryAtIndex:i];
7451 if (forCargo) {
7452 // commodity, quantity - keep consistency between .manifest and .contracts
7453 [contract setObject:[dict oo_stringForKey:CARGO_KEY_TYPE] forKey:@"commodity"];
7454 [contract setObject:[NSNumber numberWithUnsignedInt:[dict oo_intForKey:CARGO_KEY_AMOUNT]] forKey:@"quantity"];
7455 [contract setObject:[dict oo_stringForKey:CARGO_KEY_DESCRIPTION] forKey:@"description"];
7456 } else {
7457 [contract setObject:[dict oo_stringForKey:PASSENGER_KEY_NAME] forKey:PASSENGER_KEY_NAME];
7458 [contract setObject:[NSNumber numberWithUnsignedInt:[dict oo_unsignedIntForKey:CONTRACT_KEY_RISK]] forKey:CONTRACT_KEY_RISK];
7459 }
7460
7461 OOSystemID planet = [dict oo_intForKey:CONTRACT_KEY_DESTINATION];
7462 NSString* planetName = [UNIVERSE getSystemName:planet];
7463 [contract setObject:[NSNumber numberWithUnsignedInt:planet] forKey:CONTRACT_KEY_DESTINATION];
7464 [contract setObject:planetName forKey:@"destinationName"];
7465 planet = [dict oo_intForKey:CONTRACT_KEY_START];
7466 planetName = [UNIVERSE getSystemName:planet];
7467 [contract setObject:[NSNumber numberWithUnsignedInt:planet] forKey:CONTRACT_KEY_START];
7468 [contract setObject:planetName forKey:@"startName"];
7469
7470 int dest_eta = [dict oo_doubleForKey:CONTRACT_KEY_ARRIVAL_TIME] - ship_clock;
7471 [contract setObject:[NSNumber numberWithInt:dest_eta] forKey:@"eta"];
7472 [contract setObject:[UNIVERSE shortTimeDescription:dest_eta] forKey:@"etaDescription"];
7473 [contract setObject:[NSNumber numberWithInt:[dict oo_intForKey:CONTRACT_KEY_PREMIUM]] forKey:CONTRACT_KEY_PREMIUM];
7474 [contract setObject:[NSNumber numberWithInt:[dict oo_intForKey:CONTRACT_KEY_FEE]] forKey:CONTRACT_KEY_FEE];
7475 [result addObject:contract];
7476 }
7477
7478 return [[result copy] autorelease]; // return an immutable copy
7479}
int16_t OOSystemID
Definition OOTypes.h:183

Referenced by PlayerEntity::contractListForScripting, PlayerEntity::parcelListForScripting, and PlayerEntity::passengerListForScripting.

Here is the caller graph for this function:

◆ doTradeIn:forPriceFactor:

- (void) doTradeIn: (OOCreditsQuantity) tradeInValue
forPriceFactor: (double) priceFactor 

Extends class PlayerEntity.

Definition at line 9431 of file PlayerEntity.m.

9431 :(OOCreditsQuantity)tradeInValue forPriceFactor:(double)priceFactor
9432{
9433 if (tradeInValue != 0) {
9434 if (priceFactor < 1.0)
9435 tradeInValue *= priceFactor;
9436 credits += tradeInValue;
9437 }
9438}
uint64_t OOCreditsQuantity
Definition OOTypes.h:160

Referenced by tryBuyingItem:.

Here is the caller graph for this function:

◆ fuelRequiredForJump

- (OOFuelQuantity) fuelRequiredForJump

Extends class PlayerEntity.

Definition at line 6630 of file PlayerEntity.m.

6631{
6632 return 10.0 * MAX(0.1, [self hyperspaceJumpDistance]);
6633}
#define MAX(A, B)
Definition OOMaths.h:94

References fuelRequiredForJump, hyperspaceJumpDistance, and MAX.

Referenced by PlayerEntity::dialHyperRange, PlayerEntity::enterWitchspace, fuelRequiredForJump, PlayerEntity::hasSufficientFuelForJump, and setExtraEquipmentFromFlags.

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

◆ gameOverFadeToBW

- (void) gameOverFadeToBW

Extends class PlayerEntity.

Definition at line 3566 of file PlayerEntity.m.

3567{
3568 float secondsToBWFadeOut = [[NSUserDefaults standardUserDefaults] oo_floatForKey:@"gameover-seconds-to-bw-fadeout" defaultValue:5.0f];
3569 if ([UNIVERSE detailLevel] >= DETAIL_LEVEL_SHADERS && secondsToBWFadeOut > 0.0f) {
3570 MyOpenGLView* gameView = [UNIVERSE gameView];
3571 static float originalColorSaturation = -1.0f;
3572 if (originalColorSaturation == -1.0f)
3573 originalColorSaturation = [gameView colorSaturation];
3574 if ([self shotTime] < secondsToBWFadeOut) {
3575 // fade to black & white within secondsToBWFadeOut, independently of
3576 // frame rate and original color saturation
3577 if (fps_counter != 0) {
3578 [gameView adjustColorSaturation:-(originalColorSaturation * (1.0f / secondsToBWFadeOut) * [UNIVERSE timeAccelerationFactor] / fps_counter)];
3579 }
3580 }
3581
3582 if ([self shotTime] > kDeadResetTime) {
3583 // make sure to subtract the current saturation because if the user presses space to skip
3584 // the game over screen before the transition to b/w has been completed, whatever is left
3585 // will be added to the original saturation, resulting in an oversaturated image
3586 [gameView adjustColorSaturation:originalColorSaturation - [gameView colorSaturation]];
3587 originalColorSaturation = -1.0f;
3588 }
3589 }
3590}
@ DETAIL_LEVEL_SHADERS
Definition OOTypes.h:211
static float const kDeadResetTime
#define UNIVERSE
Definition Universe.h:827
void adjustColorSaturation:(float colorSaturationAdjustment)
float colorSaturation()

References MyOpenGLView::adjustColorSaturation:, MyOpenGLView::colorSaturation, DETAIL_LEVEL_SHADERS, gameOverFadeToBW, kDeadResetTime, and UNIVERSE.

Referenced by gameOverFadeToBW, performDeadUpdates:, and setExtraEquipmentFromFlags.

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

◆ hyperspaceJumpDistance

- (double) hyperspaceJumpDistance

Extends class PlayerEntity.

Definition at line 6624 of file PlayerEntity.m.

6625{
6626 NSPoint targetCoordinates = PointFromString([[UNIVERSE systemManager] getProperty:@"coordinates" forSystem:[self nextHopTargetSystemID] inGalaxy:galaxy_number]);
6627 return distanceBetweenPlanetPositions(targetCoordinates.x, targetCoordinates.y, galaxy_coordinates.x, galaxy_coordinates.y);
6628}
NSPoint PointFromString(NSString *xyString)
OOINLINE double distanceBetweenPlanetPositions(int x1, int y1, int x2, int y2) INLINE_CONST_FUNC

References distanceBetweenPlanetPositions(), hyperspaceJumpDistance, PointFromString(), and UNIVERSE.

Referenced by fuelRequiredForJump, hyperspaceJumpDistance, setExtraEquipmentFromFlags, and PlayerEntity::witchJumpChecklist:.

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

◆ noteCompassLostTarget

- (void) noteCompassLostTarget

Extends class PlayerEntity.

Definition at line 6640 of file PlayerEntity.m.

6641{
6642 if ([[self hud] isCompassActive]) {
6643 // "the compass, it says we're lost!" :)
6644 JSContext* context = OOJSAcquireContext();
6645 OOJSVal jsmode = OOJSValueFromCompassMode(context, [self compassMode]);
6646 ShipScriptEvent(context, self, "compassTargetChanged", OOJSUndefinedValue(), jsmode);
6647 OOJSRelinquishContext(context);
6648
6649 [[self hud] setCompassActive:NO]; // ensure a target change when returning to normal space.
6650 }
6651}
OOINLINE jsval OOJSValueFromCompassMode(JSContext *context, OOCompassMode value)
jsval OOJSVal
#define OOJSUndefinedValue()
OOINLINE JSContext * OOJSAcquireContext(void)
OOINLINE void OOJSRelinquishContext(JSContext *context)
#define ShipScriptEvent(context, ship, event,...)

References PlayerEntity::hud, noteCompassLostTarget, OOJSAcquireContext(), OOJSRelinquishContext(), OOJSUndefinedValue, OOJSValueFromCompassMode(), HeadUpDisplay::setCompassActive:, and ShipScriptEvent.

Referenced by PlayerEntity::enterGalacticWitchspace, PlayerEntity::enterWitchspace, noteCompassLostTarget, and setExtraEquipmentFromFlags.

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

◆ performAutopilotUpdates:

- (void) performAutopilotUpdates: (OOTimeDelta) delta_t

Extends class PlayerEntity.

Definition at line 3222 of file PlayerEntity.m.

3222 :(OOTimeDelta)delta_t
3223{
3224 [self processBehaviour:delta_t];
3225 [self applyVelocity:delta_t];
3226 [self doBookkeeping:delta_t];
3227}
double OOTimeDelta
Definition OOTypes.h:193

References Entity::applyVelocity:, PlayerEntity::doBookkeeping:, and ShipEntity::processBehaviour:.

Referenced by PlayerEntity::update:.

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

◆ performDeadUpdates:

- (void) performDeadUpdates: (OOTimeDelta) delta_t

Extends class PlayerEntity.

Definition at line 3551 of file PlayerEntity.m.

3551 :(OOTimeDelta)delta_t
3552{
3553 [UNIVERSE terminatePostFX:OO_POSTFX_CLOAK];
3554 if ([UNIVERSE ECMVisualFXEnabled])
3555 [UNIVERSE terminatePostFX:OO_POSTFX_CRTBADSIGNAL];
3556
3557 [self gameOverFadeToBW];
3558
3559 if ([self shotTime] > kDeadResetTime) {
3560 BOOL was_mouse_control_on = mouse_control_on;
3561 [UNIVERSE handleGameOver]; // we restart the UNIVERSE
3562 mouse_control_on = was_mouse_control_on;
3563 }
3564}

References PlayerEntity::gameOverFadeToBW, kDeadResetTime, and UNIVERSE.

Referenced by PlayerEntity::update:.

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

◆ performDockingUpdates:

- (void) performDockingUpdates: (OOTimeDelta) delta_t

Extends class PlayerEntity.

Definition at line 3539 of file PlayerEntity.m.

3539 :(OOTimeDelta)delta_t
3540{
3541 if ([UNIVERSE breakPatternOver]) {
3542 [self docked]; // bookkeeping for docking
3543 }
3544
3545 // if cloak or ecm visual effects are playing while docking, terminate them
3546 [UNIVERSE terminatePostFX:OO_POSTFX_CLOAK];
3547 if ([UNIVERSE ECMVisualFXEnabled])
3548 [UNIVERSE terminatePostFX:OO_POSTFX_CRTBADSIGNAL];
3549}

References PlayerEntity::docked, and UNIVERSE.

Referenced by PlayerEntity::update:.

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

◆ performInFlightUpdates:

- (void) performInFlightUpdates: (OOTimeDelta) delta_t

Extends class PlayerEntity.

Definition at line 3367 of file PlayerEntity.m.

3367 :(OOTimeDelta)delta_t
3368{
3370
3371 // do flight routines
3373 UPDATE_STAGE(@"applying newtonian drift");
3375
3376 [self applyVelocity:delta_t];
3377
3378 GLfloat thrust_factor = 1.0;
3379 if (flightSpeed > maxFlightSpeed) {
3380 if (afterburner_engaged) {
3381 thrust_factor = [self afterburnerFactor];
3382 } else {
3383 thrust_factor = HYPERSPEED_FACTOR;
3384 }
3385 }
3386
3387 GLfloat velmag = magnitude(velocity);
3388 GLfloat velmag2 = velmag - (float)delta_t * thrust * thrust_factor;
3389 if (velmag > 0) {
3390 UPDATE_STAGE(@"applying power braking");
3391
3392 if (velmag > VELOCITY_CLEANUP_MIN) {
3393 GLfloat rate;
3394 // Fix up extremely ridiculous speeds that can happen in collisions or explosions
3395 if (velmag > VELOCITY_CLEANUP_FULL)
3396 rate = VELOCITY_CLEANUP_RATE;
3397 else
3399 velmag2 -= velmag * rate;
3400 }
3401 if (velmag2 < 0.0f)
3402 velocity = kZeroVector;
3403 else
3404 velocity = vector_multiply_scalar(velocity, velmag2 / velmag);
3405 }
3406
3407 UPDATE_STAGE(@"updating joystick");
3408 [self applyRoll:(float)delta_t * flightRoll andClimb:(float)delta_t * flightPitch];
3409 if (flightYaw != 0.0) {
3410 [self applyYaw:(float)delta_t * flightYaw];
3411 }
3412
3413 UPDATE_STAGE(@"applying para-newtonian thrust");
3414 [self moveForward:delta_t * flightSpeed];
3415
3416 UPDATE_STAGE(@"updating targeting");
3417 [self updateTargeting];
3418
3420}
OOINLINE OOScalar magnitude(Vector vec) INLINE_CONST_FUNC
Definition OOVector.h:242
const Vector kZeroVector
Definition OOVector.m:27
OOINLINE Vector vector_multiply_scalar(Vector v, OOScalar s) INLINE_CONST_FUNC
Definition OOVector.h:180
#define HYPERSPEED_FACTOR
#define VELOCITY_CLEANUP_MIN
#define STAGE_TRACKING_END
#define UPDATE_STAGE(x)
#define VELOCITY_CLEANUP_RATE
#define STAGE_TRACKING_BEGIN
#define VELOCITY_CLEANUP_FULL

References ShipEntity::afterburnerFactor, PlayerEntity::applyRoll:andClimb:, Entity::applyVelocity:, PlayerEntity::applyYaw:, HYPERSPEED_FACTOR, kZeroVector, magnitude(), PlayerEntity::moveForward:, STAGE_TRACKING_BEGIN, STAGE_TRACKING_END, UPDATE_STAGE, PlayerEntity::updateTargeting, vector_multiply_scalar(), VELOCITY_CLEANUP_FULL, VELOCITY_CLEANUP_MIN, and VELOCITY_CLEANUP_RATE.

Referenced by PlayerEntity::update:.

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

◆ performLaunchingUpdates:

- (void) performLaunchingUpdates: (OOTimeDelta) delta_t

Extends class PlayerEntity.

Definition at line 3519 of file PlayerEntity.m.

3519 :(OOTimeDelta)delta_t
3520{
3521 if (![UNIVERSE breakPatternHide]) {
3522 flightRoll = launchRoll; // synchronise player's & launching station's spins.
3523 [self doBookkeeping:delta_t]; // don't show ghost exhaust plumes from previous docking!
3524 }
3525
3526 if ([UNIVERSE breakPatternOver]) {
3527 // time to check the legacy scripts!
3528 [self checkScript];
3529 // next check in 10s
3530
3531 [self setStatus:STATUS_IN_FLIGHT];
3532
3533 [self setDockingClearanceStatus:DOCKING_CLEARANCE_STATUS_NONE];
3534 StationEntity* stationLaunchedFrom = [UNIVERSE nearestEntityMatchingPredicate:IsStationPredicate parameter:NULL relativeToEntity:self];
3535 [self doScriptEvent:OOJSID("shipLaunchedFromStation") withArgument:stationLaunchedFrom];
3536 }
3537}

References PlayerEntity::checkScript, PlayerEntity::doBookkeeping:, ShipEntity::doScriptEvent:withArgument:, PlayerEntity::setDockingClearanceStatus:, ShipEntity::setStatus:, and UNIVERSE.

Referenced by PlayerEntity::update:.

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

◆ performWitchspaceCountdownUpdates:

- (void) performWitchspaceCountdownUpdates: (OOTimeDelta) delta_t

Extends class PlayerEntity.

Definition at line 3422 of file PlayerEntity.m.

3422 :(OOTimeDelta)delta_t
3423{
3425
3426 UPDATE_STAGE(@"doing bookkeeping");
3427 [self doBookkeeping:delta_t];
3428
3429 UPDATE_STAGE(@"updating countdown timer");
3430 witchspaceCountdown = fdim(witchspaceCountdown, delta_t);
3431
3432 // damaged gal drive? abort!
3433 /* TODO: this check should possibly be hasEquipmentItemProviding:,
3434 * but if it was we'd need to know which item was actually doing
3435 * the providing so it could be removed. */
3436 if (EXPECT_NOT(galactic_witchjump && ![self hasEquipmentItem:@"EQ_GAL_DRIVE"])) {
3437 galactic_witchjump = NO;
3438 [self setStatus:STATUS_IN_FLIGHT];
3439 [self playHyperspaceAborted];
3440 [self doScriptEvent:OOJSID("playerJumpFailed") withArgument:@"malfunction"];
3441 return;
3442 }
3443
3444 int seconds = round(witchspaceCountdown);
3445 if (galactic_witchjump) {
3446 [UNIVERSE displayCountdownMessage:OOExpandKey(@"witch-galactic-in-x-seconds", seconds) forCount:1.0];
3447 } else {
3448 NSString* destination = [UNIVERSE getSystemName:[self nextHopTargetSystemID]];
3449 [UNIVERSE displayCountdownMessage:OOExpandKey(@"witch-to-x-in-y-seconds", seconds, destination) forCount:1.0];
3450 }
3451
3452 if (witchspaceCountdown == 0.0) {
3453 UPDATE_STAGE(@"preloading planet textures");
3454 if (!galactic_witchjump) {
3455 /* Note: planet texture preloading is done twice for hyperspace jumps:
3456 once when starting the countdown and once at the beginning of the
3457 jump. The reason is that the preloading may have been skipped the
3458 first time because of rate limiting (see notes at
3459 -preloadPlanetTexturesForSystem:). There is no significant overhead
3460 from doing it twice thanks to the texture cache.
3461 -- Ahruman 2009-12-19
3462 */
3463 [UNIVERSE preloadPlanetTexturesForSystem:target_system_id];
3464 } else {
3465 // FIXME: preload target system for galactic jump?
3466 }
3467
3468 UPDATE_STAGE(@"JUMP!");
3469 if (galactic_witchjump)
3470 [self enterGalacticWitchspace];
3471 else
3472 [self enterWitchspace];
3473 galactic_witchjump = NO;
3474 }
3475
3477}

References PlayerEntity::doBookkeeping:, ShipEntity::doScriptEvent:withArgument:, PlayerEntity::enterGalacticWitchspace, PlayerEntity::enterWitchspace, EXPECT_NOT, PlayerEntity::nextHopTargetSystemID, PlayerEntity::playHyperspaceAborted, ShipEntity::setStatus:, STAGE_TRACKING_BEGIN, STAGE_TRACKING_END, and UPDATE_STAGE.

Referenced by PlayerEntity::update:.

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

◆ performWitchspaceExitUpdates:

- (void) performWitchspaceExitUpdates: (OOTimeDelta) delta_t

Extends class PlayerEntity.

Definition at line 3479 of file PlayerEntity.m.

3479 :(OOTimeDelta)delta_t
3480{
3481 if ([UNIVERSE breakPatternOver]) {
3482 [self resetExhaustPlumes];
3483 // time to check the script!
3484 [self checkScript];
3485 // next check in 10s
3486 [self resetScriptTimer]; // reset the in-system timer
3487
3488 // announce arrival
3489 if ([UNIVERSE planet]) {
3490 [UNIVERSE addMessage:[NSString stringWithFormat:@" %@. ", [UNIVERSE getSystemName:system_id]] forCount:3.0];
3491 // and reset the compass
3492 if ([self hasEquipmentItemProviding:@"EQ_ADVANCED_COMPASS"])
3493 compassMode = COMPASS_MODE_PLANET;
3494 else
3495 compassMode = COMPASS_MODE_BASIC;
3496 } else {
3497 if ([UNIVERSE inInterstellarSpace])
3498 [UNIVERSE addMessage:DESC(@"witch-engine-malfunction") forCount:3.0]; // if sun gone nova, print nothing
3499 }
3500
3501 [self setStatus:STATUS_IN_FLIGHT];
3502
3503 // If we are exiting witchspace after a scripted misjump. then make sure it gets reset now.
3504 // Scripted misjump situations should have a lifespan of one jump only, to keep things
3505 // simple - Nikos 20090728
3506 if ([self scriptedMisjump])
3507 [self setScriptedMisjump:NO];
3508 // similarly reset the misjump range to the traditional 0.5
3509 [self setScriptedMisjumpRange:0.5];
3510
3511 [self doScriptEvent:OOJSID("shipExitedWitchspace") withArgument:[self jumpCause]];
3512
3513 [self doBookkeeping:delta_t]; // arrival frame updates
3514
3515 suppressAegisMessages = NO;
3516 }
3517}

References PlayerEntity::checkScript, PlayerEntity::doBookkeeping:, ShipEntity::doScriptEvent:withArgument:, PlayerEntity::jumpCause, ShipEntity::resetExhaustPlumes, PlayerEntity::resetScriptTimer, ShipEntity::setScriptedMisjump:, ShipEntity::setScriptedMisjumpRange:, ShipEntity::setStatus:, and UNIVERSE.

Referenced by PlayerEntity::update:.

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

◆ prepareMarkedDestination:marker:

- (void) prepareMarkedDestination: (NSMutableDictionary *) markers
marker: (NSDictionary *) marker 

Extends class PlayerEntity.

Definition at line 7697 of file PlayerEntity.m.

7697 :(NSMutableDictionary*)markers marker:(NSDictionary*)marker
7698{
7699 NSNumber* key = [NSNumber numberWithInt:[marker oo_intForKey:@"system"]];
7700 NSMutableArray* list = [markers objectForKey:key];
7701 if (list == nil) {
7702 list = [NSMutableArray arrayWithObject:marker];
7703 } else {
7704 [list addObject:marker];
7705 }
7706 [markers setObject:list forKey:key];
7707}
return nil

References nil.

Referenced by PlayerEntity::markedDestinations.

Here is the caller graph for this function:

◆ setExtraEquipmentFromFlags

- (void) setExtraEquipmentFromFlags

Extends class PlayerEntity.

References checkScriptsIfAppropriate, fuelRequiredForJump, gameOverFadeToBW, hyperspaceJumpDistance, noteCompassLostTarget, setExtraEquipmentFromFlags, showGameOver, showMarketCashAndLoadLine, showMarketScreenHeaders, updateAlertCondition, updateAlertConditionForNearbyEntities, updateMovementFlags, updateTargeting, updateWormholes, witchEnd, and witchStart.

Referenced by setExtraEquipmentFromFlags.

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

◆ showGameOver

- (void) showGameOver

Extends class PlayerEntity.

Definition at line 3630 of file PlayerEntity.m.

3631{
3632 [hud resetGuis:[NSDictionary dictionaryWithObject:[NSDictionary dictionary] forKey:@"message_gui"]];
3633 NSString* scoreMS = [NSString stringWithFormat:OOExpandKey(@"gameoverscreen-score-@"),
3634 KillCountToRatingAndKillString(ship_kills)];
3635
3636 [UNIVERSE displayMessage:OOExpandKey(@"gameoverscreen-game-over") forCount:kDeadResetTime];
3637 [UNIVERSE displayMessage:@"" forCount:kDeadResetTime];
3638 [UNIVERSE displayMessage:scoreMS forCount:kDeadResetTime];
3639 [UNIVERSE displayMessage:@"" forCount:kDeadResetTime];
3640 [UNIVERSE displayMessage:OOExpandKey(@"gameoverscreen-press-space") forCount:kDeadResetTime];
3641 [UNIVERSE displayMessage:@" " forCount:kDeadResetTime];
3642 [UNIVERSE displayMessage:@"" forCount:kDeadResetTime];
3643 [self resetShotTime];
3644}

References ShipEntity::resetShotTime, and showGameOver.

Referenced by PlayerEntity::doBookkeeping:, PlayerEntity::getDestroyedBy:damageType:, setExtraEquipmentFromFlags, and showGameOver.

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

◆ showMarketCashAndLoadLine

- (void) showMarketCashAndLoadLine

Extends class PlayerEntity.

Definition at line 9979 of file PlayerEntity.m.

9980{
9981 GuiDisplayGen* gui = [UNIVERSE gui];
9982 OOCargoQuantity currentCargo = current_cargo;
9983 OOCargoQuantity cargoCapacity = [self maxAvailableCargoSpace];
9984 [gui setText:OOExpandKey(@"market-cash-and-load", credits, currentCargo, cargoCapacity) forRow:GUI_ROW_MARKET_CASH];
9985 [gui setColor:[gui colorFromSetting:kGuiMarketCashColor defaultValue:[OOColor yellowColor]] forRow:GUI_ROW_MARKET_CASH];
9986}
uint32_t OOCargoQuantity
Definition OOTypes.h:155
OOColor * colorFromSetting:defaultValue:(NSString *setting,[defaultValue] OOColor *def)
void setText:forRow:(NSString *str,[forRow] OOGUIRow row)
void setColor:forRow:(OOColor *color,[forRow] OOGUIRow row)
OOColor * yellowColor()
Definition OOColor.m:279

References GuiDisplayGen::colorFromSetting:defaultValue:, ShipEntity::maxAvailableCargoSpace, GuiDisplayGen::setColor:forRow:, GuiDisplayGen::setText:forRow:, showMarketCashAndLoadLine, and OOColor::yellowColor.

Referenced by setExtraEquipmentFromFlags, PlayerEntity::setGuiToMarketInfoScreen, PlayerEntity::setGuiToMarketScreen, and showMarketCashAndLoadLine.

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

◆ showMarketScreenDataLine:forGood:inMarket:holdQuantity:

- (void) showMarketScreenDataLine: (OOGUIRow) row
forGood: (OOCommodityType) good
inMarket: (OOCommodityMarket *) localMarket
holdQuantity: (OOCargoQuantity) quantity 

Extends class PlayerEntity.

Definition at line 9654 of file PlayerEntity.m.

9654 :(OOGUIRow)row forGood:(OOCommodityType)good inMarket:(OOCommodityMarket*)localMarket holdQuantity:(OOCargoQuantity)quantity
9655{
9656 GuiDisplayGen* gui = [UNIVERSE gui];
9657 NSString* desc = [NSString stringWithFormat:@" %@ ", [shipCommodityData nameForGood:good]];
9658 OOCargoQuantity available_units = [localMarket quantityForGood:good];
9659 OOCargoQuantity units_in_hold = quantity;
9660 OOCreditsQuantity pricePerUnit = [localMarket priceForGood:good];
9661 OOMassUnit unit = [shipCommodityData massUnitForGood:good];
9662
9663 NSString* available = OOPadStringToEms(((available_units > 0) ? (NSString*)[NSString stringWithFormat:@"%d", available_units] : DESC(@"commodity-quantity-none")), 2.5);
9664
9665 NSUInteger priceDecimal = pricePerUnit % 10;
9666 NSString* price = [NSString stringWithFormat:@" %@.%zu ", OOPadStringToEms([NSString stringWithFormat:@"%zu", (pricePerUnit / 10)], 2.5), priceDecimal];
9667
9668 // this works with up to 9999 tons of gemstones. Any more than that, they deserve the formatting they get! :)
9669
9670 NSString* owned = OOPadStringToEms((units_in_hold > 0) ? (NSString*)[NSString stringWithFormat:@"%d", units_in_hold] : DESC(@"commodity-quantity-none"), 4.5);
9671 NSString* units = DisplayStringForMassUnit(unit);
9672 NSString* units_available = [NSString stringWithFormat:@" %@ %@ ", available, units];
9673 NSString* units_owned = [NSString stringWithFormat:@" %@ %@ ", owned, units];
9674
9675 NSUInteger import_legality = [localMarket importLegalityForGood:good];
9676 NSUInteger export_legality = [localMarket exportLegalityForGood:good];
9677 NSString* legaldesc = nil;
9678 if (import_legality == 0) {
9679 if (export_legality == 0) {
9680 legaldesc = DESC(@"oolite-legality-clear");
9681 } else {
9682 legaldesc = DESC(@"oolite-legality-import");
9683 }
9684 } else {
9685 if (export_legality == 0) {
9686 legaldesc = DESC(@"oolite-legality-export");
9687 } else {
9688 legaldesc = DESC(@"oolite-legality-neither");
9689 }
9690 }
9691 legaldesc = [NSString stringWithFormat:@" %@ ", legaldesc];
9692
9693 NSString* extradesc = [shipCommodityData shortCommentForGood:good];
9694
9695 [gui setKey:good forRow:row];
9696 [gui setColor:[gui colorFromSetting:kGuiMarketCommodityColor defaultValue:nil] forRow:row];
9697 [gui setArray:[NSArray arrayWithObjects:desc, extradesc, price, units_available, units_owned, legaldesc, nil] forRow:row++];
9698}
NSInteger OOGUIRow
NSString * DisplayStringForMassUnit(OOMassUnit unit)
NSString * OOPadStringToEms(NSString *string, float numEms)
NSString * OOCommodityType
Definition OOTypes.h:97
OOMassUnit
Definition OOTypes.h:111
#define DESC(key)
Definition Universe.h:832
void setArray:forRow:(NSArray *arr,[forRow] OOGUIRow row)
void setKey:forRow:(NSString *str,[forRow] OOGUIRow row)
NSUInteger exportLegalityForGood:(OOCommodityType good)
NSUInteger importLegalityForGood:(OOCommodityType good)
OOCargoQuantity quantityForGood:(OOCommodityType good)
OOCreditsQuantity priceForGood:(OOCommodityType good)

References GuiDisplayGen::colorFromSetting:defaultValue:, DESC, DisplayStringForMassUnit(), OOCommodityMarket::exportLegalityForGood:, OOCommodityMarket::importLegalityForGood:, nil, OOPadStringToEms(), OOCommodityMarket::priceForGood:, OOCommodityMarket::quantityForGood:, GuiDisplayGen::setArray:forRow:, GuiDisplayGen::setColor:forRow:, and GuiDisplayGen::setKey:forRow:.

Referenced by PlayerEntity::setGuiToMarketInfoScreen, and PlayerEntity::setGuiToMarketScreen.

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

◆ showMarketScreenHeaders

- (void) showMarketScreenHeaders

Extends class PlayerEntity.

Definition at line 9632 of file PlayerEntity.m.

9633{
9634 GuiDisplayGen* gui = [UNIVERSE gui];
9635 OOGUITabSettings tab_stops;
9636 tab_stops[0] = 0;
9637 tab_stops[1] = 137;
9638 tab_stops[2] = 187;
9639 tab_stops[3] = 267;
9640 tab_stops[4] = 321;
9641 tab_stops[5] = 431;
9642 [gui overrideTabs:tab_stops from:kGuiMarketTabs length:6];
9643 [gui setTabStops:tab_stops];
9644
9645 [gui setColor:[gui colorFromSetting:kGuiMarketHeadingColor defaultValue:[OOColor greenColor]] forRow:GUI_ROW_MARKET_KEY];
9646 [gui setArray:[NSArray arrayWithObjects:DESC(@"commodity-column-title"), OOPadStringToEms(DESC(@"price-column-title"), 3.5),
9647 OOPadStringToEms(DESC(@"for-sale-column-title"), 3.75), OOPadStringToEms(DESC(@"in-hold-column-title"), 5.75), DESC(@"oolite-legality-column-title"), DESC(@"oolite-extras-column-title"), nil]
9648 forRow:GUI_ROW_MARKET_KEY];
9649 [gui setArray:[NSArray arrayWithObjects:DESC(@"commodity-column-title"), DESC(@"oolite-extras-column-title"), OOPadStringToEms(DESC(@"price-column-title"), 3.5),
9650 OOPadStringToEms(DESC(@"for-sale-column-title"), 3.75), OOPadStringToEms(DESC(@"in-hold-column-title"), 5.75), DESC(@"oolite-legality-column-title"), nil]
9651 forRow:GUI_ROW_MARKET_KEY];
9652}
OOGUITabStop OOGUITabSettings[GUI_MAX_COLUMNS]
void overrideTabs:from:length:(OOGUITabSettings stops,[from] NSString *setting,[length] NSUInteger len)
void setTabStops:(OOGUITabSettings stops)
OOColor * greenColor()
Definition OOColor.m:264

References GuiDisplayGen::colorFromSetting:defaultValue:, OOColor::greenColor, GuiDisplayGen::overrideTabs:from:length:, GuiDisplayGen::setArray:forRow:, GuiDisplayGen::setColor:forRow:, GuiDisplayGen::setTabStops:, and showMarketScreenHeaders.

Referenced by setExtraEquipmentFromFlags, PlayerEntity::setGuiToMarketInfoScreen, PlayerEntity::setGuiToMarketScreen, and showMarketScreenHeaders.

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

◆ tryBuyingItem:

- (BOOL) tryBuyingItem: (NSString *) eqKey

Extends class PlayerEntity.

Definition at line 9104 of file PlayerEntity.m.

9104 :(NSString*)eqKey
9105{
9106 // note this doesn't check the availability by tech-level
9107 OOEquipmentType* eqType = [OOEquipmentType equipmentTypeWithIdentifier:eqKey];
9108 OOCreditsQuantity pricePerUnit = [eqType price];
9109 NSString* eqKeyDamaged = [eqType damagedIdentifier];
9110 double price = pricePerUnit;
9111 double priceFactor = 1.0;
9112 OOCreditsQuantity tradeIn = 0;
9113 BOOL isRepair = NO;
9114
9115 // repairs cost 50%
9116 if ([self hasEquipmentItem:eqKeyDamaged]) {
9117 price /= 2.0;
9118 isRepair = YES;
9119 }
9120
9121 if ([eqKey isEqualToString:@"EQ_RENOVATION"]) {
9122 price = [self renovationCosts];
9123 }
9124
9125 price = [self adjustPriceByScriptForEqKey:eqKey withCurrent:price];
9126
9127 StationEntity* dockedStation = [self dockedStation];
9128 if (dockedStation) {
9129 priceFactor = [dockedStation equipmentPriceFactor];
9130 }
9131
9132 price *= priceFactor; // increased prices at some stations
9133
9134 if (price > credits) {
9135 return NO;
9136 }
9137
9138 if ([eqType isPrimaryWeapon]) {
9139 if (chosen_weapon_facing == WEAPON_FACING_NONE) {
9140 [self setGuiToEquipShipScreen:0 selectingFacingFor:eqKey]; // reset
9141 return YES;
9142 }
9143
9145 OOWeaponType current_weapon = nil;
9146
9147 NSUInteger multiplier = 1;
9148
9149 switch (chosen_weapon_facing) {
9151 current_weapon = forward_weapon_type;
9152 forward_weapon_type = chosen_weapon;
9153 if (_multiplyWeapons) {
9154 multiplier = [forwardWeaponOffset count];
9155 }
9156 break;
9157
9158 case WEAPON_FACING_AFT:
9159 current_weapon = aft_weapon_type;
9160 aft_weapon_type = chosen_weapon;
9161 if (_multiplyWeapons) {
9162 multiplier = [aftWeaponOffset count];
9163 }
9164 break;
9165
9166 case WEAPON_FACING_PORT:
9167 current_weapon = port_weapon_type;
9168 port_weapon_type = chosen_weapon;
9169 if (_multiplyWeapons) {
9170 multiplier = [portWeaponOffset count];
9171 }
9172 break;
9173
9175 current_weapon = starboard_weapon_type;
9176 starboard_weapon_type = chosen_weapon;
9177 if (_multiplyWeapons) {
9178 multiplier = [starboardWeaponOffset count];
9179 }
9180 break;
9181
9182 case WEAPON_FACING_NONE:
9183 break;
9184 }
9185
9186 price *= multiplier;
9187
9188 if (price > credits) {
9189 // not enough money - ensure that weapon
9190 // type is reset to what it was before
9191 // the attempt to buy took place
9192 switch (chosen_weapon_facing) {
9194 forward_weapon_type = current_weapon;
9195 break;
9196 case WEAPON_FACING_AFT:
9197 aft_weapon_type = current_weapon;
9198 break;
9199 case WEAPON_FACING_PORT:
9200 port_weapon_type = current_weapon;
9201 break;
9203 starboard_weapon_type = current_weapon;
9204 break;
9205 case WEAPON_FACING_NONE:
9206 break;
9207 }
9208 return NO;
9209 }
9210 credits -= price;
9211
9212 // Refund current_weapon
9213 if (current_weapon != nil) {
9214 tradeIn = [UNIVERSE getEquipmentPriceForKey:OOEquipmentIdentifierFromWeaponType(current_weapon)] * multiplier;
9215 }
9216
9217 [self doTradeIn:tradeIn forPriceFactor:priceFactor];
9218 // If equipped, remove damaged weapon after repairs. -- But there's no way we should get a damaged weapon. Ever.
9219 [self removeEquipmentItem:eqKeyDamaged];
9220 return YES;
9221 }
9222
9223 if ([eqType isMissileOrMine] && missiles >= max_missiles) {
9224 OOLog(@"equip.buy.mounted.failed.full", @"%@", @"rejecting missile because already full");
9225 return NO;
9226 }
9227
9228 // NSFO!
9229 // unsigned passenger_space = [[OOEquipmentType equipmentTypeWithIdentifier:@"EQ_PASSENGER_BERTH"] requiredCargoSpace];
9230 // if (passenger_space == 0) passenger_space = PASSENGER_BERTH_SPACE;
9231
9232 if ([eqKey isEqualToString:@"EQ_PASSENGER_BERTH"] && [self availableCargoSpace] < PASSENGER_BERTH_SPACE) {
9233 return NO;
9234 }
9235
9236 if ([eqKey isEqualToString:@"EQ_FUEL"]) {
9237#if MASS_DEPENDENT_FUEL_PRICES
9238 OOCreditsQuantity creditsForRefuel = ([self fuelCapacity] - [self fuel]) * pricePerUnit * [self fuelChargeRate];
9239#else
9240 OOCreditsQuantity creditsForRefuel = ([self fuelCapacity] - [self fuel]) * pricePerUnit;
9241#endif
9242 if (credits >= creditsForRefuel) // Ensure we don't overflow
9243 {
9244 credits -= creditsForRefuel;
9245 fuel = [self fuelCapacity];
9246 return YES;
9247 } else {
9248 return NO;
9249 }
9250 }
9251
9252 // check energy unit replacement
9253 if ([eqKey hasSuffix:@"ENERGY_UNIT"] && [self energyUnitType] != ENERGY_UNIT_NONE) {
9254 switch ([self energyUnitType]) {
9255 case ENERGY_UNIT_NAVAL:
9256 [self removeEquipmentItem:@"EQ_NAVAL_ENERGY_UNIT"];
9257 tradeIn = [UNIVERSE getEquipmentPriceForKey:@"EQ_NAVAL_ENERGY_UNIT"] / 2; // 50 % refund
9258 break;
9260 [self removeEquipmentItem:@"EQ_NAVAL_ENERGY_UNIT_DAMAGED"];
9261 tradeIn = [UNIVERSE getEquipmentPriceForKey:@"EQ_NAVAL_ENERGY_UNIT"] / 4; // half of the working one
9262 break;
9263 case ENERGY_UNIT_NORMAL:
9264 [self removeEquipmentItem:@"EQ_ENERGY_UNIT"];
9265 tradeIn = [UNIVERSE getEquipmentPriceForKey:@"EQ_ENERGY_UNIT"] * 3 / 4; // 75 % refund
9266 break;
9268 [self removeEquipmentItem:@"EQ_ENERGY_UNIT_DAMAGED"];
9269 tradeIn = [UNIVERSE getEquipmentPriceForKey:@"EQ_ENERGY_UNIT"] * 3 / 8; // half of the working one
9270 break;
9271
9272 default:
9273 break;
9274 }
9275 [self doTradeIn:tradeIn forPriceFactor:priceFactor];
9276 }
9277
9278 // maintain ship
9279 if ([eqKey isEqualToString:@"EQ_RENOVATION"]) {
9280 OOTechLevelID techLevel = NSNotFound;
9281 if (dockedStation != nil)
9282 techLevel = [dockedStation equivalentTechLevel];
9283 if (techLevel == NSNotFound)
9284 techLevel = [[UNIVERSE currentSystemData] oo_unsignedIntForKey:KEY_TECHLEVEL];
9285
9286 credits -= price;
9287 ship_trade_in_factor += 5 + techLevel; // you get better value at high-tech repair bases
9288 if (ship_trade_in_factor > 100)
9289 ship_trade_in_factor = 100;
9290
9291 [self clearSubEntities];
9292 [self setUpSubEntities];
9293
9294 return YES;
9295 }
9296
9297 if ([eqKey hasSuffix:@"MISSILE"] || [eqKey hasSuffix:@"MINE"]) {
9298 ShipEntity* weapon = [[UNIVERSE newShipWithRole:eqKey] autorelease];
9299 if (weapon)
9300 OOLog(kOOLogBuyMountedOK, @"Got ship for mounted weapon role %@", eqKey);
9301 else
9302 OOLog(kOOLogBuyMountedFailed, @"Could not find ship for mounted weapon role %@", eqKey);
9303
9304 BOOL mounted_okay = [self mountMissile:weapon];
9305 if (mounted_okay) {
9306 credits -= price;
9307 [self safeAllMissiles];
9308 [self tidyMissilePylons];
9309 [self setActiveMissile:0];
9310 }
9311 return mounted_okay;
9312 }
9313
9314 if ([eqKey isEqualToString:@"EQ_PASSENGER_BERTH"]) {
9315 [self changePassengerBerths:+1];
9316 credits -= price;
9317 return YES;
9318 }
9319
9320 if ([eqKey isEqualToString:@"EQ_PASSENGER_BERTH_REMOVAL"]) {
9321 [self changePassengerBerths:-1];
9322 credits -= price;
9323 return YES;
9324 }
9325
9326 if ([eqKey isEqualToString:@"EQ_MISSILE_REMOVAL"]) {
9327 credits -= price;
9328 tradeIn += [self removeMissiles];
9329 [self doTradeIn:tradeIn forPriceFactor:priceFactor];
9330 return YES;
9331 }
9332
9333 if ([self canAddEquipment:eqKey inContext:@"purchase"]) {
9334 credits -= price;
9335 [self addEquipmentItem:eqKey withValidation:NO inContext:@"purchase"]; // no need to validate twice.
9336 if (isRepair) {
9337 [self doScriptEvent:OOJSID("equipmentRepaired") withArgument:eqKey];
9338 }
9339 return YES;
9340 }
9341
9342 return NO;
9343}
#define OOLog(class, format,...)
Definition OOLogging.h:84
return self
NSUInteger OOTechLevelID
Definition OOTypes.h:177
@ WEAPON_FACING_FORWARD
Definition OOTypes.h:196
@ WEAPON_FACING_NONE
Definition OOTypes.h:201
@ WEAPON_FACING_AFT
Definition OOTypes.h:197
@ WEAPON_FACING_PORT
Definition OOTypes.h:198
@ WEAPON_FACING_STARBOARD
Definition OOTypes.h:199
@ ENERGY_UNIT_NORMAL
Definition OOTypes.h:123
@ ENERGY_UNIT_NAVAL_DAMAGED
Definition OOTypes.h:120
@ ENERGY_UNIT_NAVAL
Definition OOTypes.h:124
@ ENERGY_UNIT_NONE
Definition OOTypes.h:118
@ ENERGY_UNIT_NORMAL_DAMAGED
Definition OOTypes.h:119
static NSString *const kOOLogBuyMountedOK
static NSString *const kOOLogBuyMountedFailed
OOEquipmentType * OOWeaponType
Definition ShipEntity.h:164
OOWeaponType OOWeaponTypeFromEquipmentIdentifierStrict(NSString *string) PURE_FUNC
#define PASSENGER_BERTH_SPACE
Definition Universe.h:143
NSString * damagedIdentifier()
OOEquipmentType * equipmentTypeWithIdentifier:(NSString *identifier)
OOCreditsQuantity price()
OOTechLevelID equivalentTechLevel
float equipmentPriceFactor

References PlayerEntity::addEquipmentItem:withValidation:inContext:, PlayerEntity::adjustPriceByScriptForEqKey:withCurrent:, PlayerEntity::changePassengerBerths:, ShipEntity::clearSubEntities, OOEquipmentType::damagedIdentifier, PlayerEntity::dockedStation, ShipEntity::doScriptEvent:withArgument:, PlayerEntity::doTradeIn:forPriceFactor:, ENERGY_UNIT_NAVAL, ENERGY_UNIT_NAVAL_DAMAGED, ENERGY_UNIT_NONE, ENERGY_UNIT_NORMAL, ENERGY_UNIT_NORMAL_DAMAGED, StationEntity::equipmentPriceFactor, OOEquipmentType::equipmentTypeWithIdentifier:, StationEntity::equivalentTechLevel, ShipEntity::fuel, ShipEntity::fuelCapacity, kOOLogBuyMountedFailed, kOOLogBuyMountedOK, PlayerEntity::mountMissile:, nil, OOLog, OOWeaponTypeFromEquipmentIdentifierStrict(), PASSENGER_BERTH_SPACE, OOEquipmentType::price, PlayerEntity::removeEquipmentItem:, PlayerEntity::removeMissiles, PlayerEntity::renovationCosts, PlayerEntity::safeAllMissiles, PlayerEntity::setActiveMissile:, PlayerEntity::setGuiToEquipShipScreen:selectingFacingFor:, ShipEntity::setUpSubEntities, PlayerEntity::tidyMissilePylons, WEAPON_FACING_AFT, WEAPON_FACING_FORWARD, WEAPON_FACING_NONE, WEAPON_FACING_PORT, and WEAPON_FACING_STARBOARD.

Here is the call graph for this function:

◆ updateAlertCondition

- (void) updateAlertCondition

Extends class PlayerEntity.

Definition at line 3068 of file PlayerEntity.m.

3069{
3070 [self updateAlertConditionForNearbyEntities];
3071 /* TODO: update alert condition once per frame. Tried this before, but
3072 there turned out to be complications. See mailing list archive.
3073 -- Ahruman 20070802
3074 */
3075 OOAlertCondition cond = [self alertCondition];
3076 OOTimeAbsolute t = [UNIVERSE getTime];
3077 if (cond != lastScriptAlertCondition) {
3078 [self doScriptEvent:OOJSID("alertConditionChanged") withArgument:[NSNumber numberWithInt:cond] andArgument:[NSNumber numberWithInt:lastScriptAlertCondition]];
3079 lastScriptAlertCondition = cond;
3080 }
3081 /* Update heuristic assessment of whether player is fleeing */
3082 if (cond == ALERT_CONDITION_DOCKED || cond == ALERT_CONDITION_GREEN || (cond == ALERT_CONDITION_YELLOW && energy == maxEnergy)) {
3083 fleeing_status = PLAYER_FLEEING_NONE;
3084 } else if (fleeing_status == PLAYER_FLEEING_UNLIKELY && (energy > maxEnergy * 0.6 || cond != ALERT_CONDITION_RED)) {
3085 fleeing_status = PLAYER_FLEEING_NONE;
3086 } else if ((fleeing_status == PLAYER_FLEEING_MAYBE || fleeing_status == PLAYER_FLEEING_UNLIKELY) && cargo_dump_time > last_shot_time) {
3087 fleeing_status = PLAYER_FLEEING_CARGO;
3088 } else if (fleeing_status == PLAYER_FLEEING_MAYBE && last_shot_time + 10 > t) {
3089 fleeing_status = PLAYER_FLEEING_NONE;
3090 } else if (fleeing_status == PLAYER_FLEEING_LIKELY && last_shot_time + 10 > t) {
3091 fleeing_status = PLAYER_FLEEING_UNLIKELY;
3092 } else if (fleeing_status == PLAYER_FLEEING_NONE && cond == ALERT_CONDITION_RED && last_shot_time + 10 < t && flightSpeed > 0.75 * maxFlightSpeed) {
3093 fleeing_status = PLAYER_FLEEING_MAYBE;
3094 } else if ((fleeing_status == PLAYER_FLEEING_MAYBE || fleeing_status == PLAYER_FLEEING_CARGO) && cond == ALERT_CONDITION_RED && last_shot_time + 10 < t && flightSpeed > 0.75 * maxFlightSpeed && energy < maxEnergy * 0.5 && (forward_shield < [self maxForwardShieldLevel] * 0.25 || aft_shield < [self maxAftShieldLevel] * 0.25)) {
3095 fleeing_status = PLAYER_FLEEING_LIKELY;
3096 }
3097}
double OOTimeAbsolute
Definition OOTypes.h:192
@ PLAYER_FLEEING_MAYBE
@ PLAYER_FLEEING_LIKELY
@ PLAYER_FLEEING_NONE
@ PLAYER_FLEEING_CARGO
@ PLAYER_FLEEING_UNLIKELY
OOAlertCondition
Definition ShipEntity.h:166
@ ALERT_CONDITION_GREEN
Definition ShipEntity.h:170
@ ALERT_CONDITION_RED
Definition ShipEntity.h:172
@ ALERT_CONDITION_YELLOW
Definition ShipEntity.h:171
@ ALERT_CONDITION_DOCKED
Definition ShipEntity.h:169

References ALERT_CONDITION_DOCKED, ALERT_CONDITION_GREEN, ALERT_CONDITION_RED, ALERT_CONDITION_YELLOW, PlayerEntity::alertCondition, ShipEntity::doScriptEvent:withArgument:andArgument:, PLAYER_FLEEING_CARGO, PLAYER_FLEEING_LIKELY, PLAYER_FLEEING_MAYBE, PLAYER_FLEEING_NONE, PLAYER_FLEEING_UNLIKELY, updateAlertCondition, and PlayerEntity::updateAlertConditionForNearbyEntities.

Referenced by setExtraEquipmentFromFlags, PlayerEntity::setMassLockable:, PlayerEntity::update:, and updateAlertCondition.

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

◆ updateAlertConditionForNearbyEntities

- (void) updateAlertConditionForNearbyEntities

Extends class PlayerEntity.

Definition at line 2893 of file PlayerEntity.m.

2894{
2895 if (![self isInSpace] || [self status] == STATUS_DOCKING) {
2896 [self clearAlertFlags];
2897 // not needed while docked
2898 return;
2899 }
2900
2901 int i, ent_count = UNIVERSE->n_entities;
2902 Entity** uni_entities = UNIVERSE->sortedEntities; // grab the public sorted list
2903 Entity* my_entities[ent_count];
2904 Entity* scannedEntity = nil;
2905 for (i = 0; i < ent_count; i++) {
2906 my_entities[i] = [uni_entities[i] retain]; // retained
2907 }
2908 BOOL massLocked = NO;
2909 BOOL foundHostiles = NO;
2910#if OO_VARIABLE_TORUS_SPEED
2911 BOOL needHyperspeedNearest = YES;
2912 double hsnDistance = 0;
2913#endif
2914 for (i = 0; i < ent_count; i++) // scanner lollypops
2915 {
2916 scannedEntity = my_entities[i];
2917
2918#if OO_VARIABLE_TORUS_SPEED
2919 if (EXPECT_NOT(needHyperspeedNearest)) {
2920 // not visual effects, waypoints, ships, etc.
2921 if (scannedEntity != self && [scannedEntity canCollide] && (![scannedEntity isShip] || ![self collisionExceptedFor:(ShipEntity*)scannedEntity])) {
2922 hsnDistance = sqrt(scannedEntity->zero_distance) - [scannedEntity collisionRadius];
2923 needHyperspeedNearest = NO;
2924 }
2925 } else if ([scannedEntity isStellarObject]) {
2926 // planets, stars might be closest surface even if not
2927 // closest centre. That could be true of others, but the
2928 // error is negligible there.
2929 double thisHSN = sqrt(scannedEntity->zero_distance) - [scannedEntity collisionRadius];
2930 if (thisHSN < hsnDistance) {
2931 hsnDistance = thisHSN;
2932 }
2933 }
2934#endif
2935
2936 if (scannedEntity->zero_distance < SCANNER_MAX_RANGE2 || !scannedEntity->isShip) {
2937 int theirClass = [scannedEntity scanClass];
2938 // here we could also force masslock for higher than yellow alert, but
2939 // if we are going to hand over masslock control to scripting, might as well
2940 // hand it over fully
2941 if ([self massLockable] /*|| alertFlags > ALERT_FLAG_YELLOW_LIMIT*/) {
2942 massLocked |= [self checkEntityForMassLock:scannedEntity withScanClass:theirClass]; // we just need one masslocker..
2943 }
2944 if (theirClass != CLASS_NO_DRAW) {
2945 if (theirClass == CLASS_THARGOID || [scannedEntity isCascadeWeapon]) {
2946 foundHostiles = YES;
2947 } else if ([scannedEntity isShip]) {
2948 ShipEntity* ship = (ShipEntity*)scannedEntity;
2949 foundHostiles |= (([ship hasHostileTarget]) && ([ship primaryTarget] == self));
2950 }
2951 }
2952 }
2953 }
2954#if OO_VARIABLE_TORUS_SPEED
2955 if (EXPECT_NOT(needHyperspeedNearest)) {
2956 // this case should only occur in an otherwise empty
2957 // interstellar space - unlikely but possible
2958 hyperspeedFactor = MIN_HYPERSPEED_FACTOR;
2959 } else {
2960 // once nearest object is >4x scanner range
2961 // start increasing torus speed
2962 double factor = hsnDistance / (4 * SCANNER_MAX_RANGE);
2963 if (factor < 1.0) {
2964 hyperspeedFactor = MIN_HYPERSPEED_FACTOR;
2965 } else {
2966 hyperspeedFactor = MIN_HYPERSPEED_FACTOR * sqrt(factor);
2967 if (hyperspeedFactor > MAX_HYPERSPEED_FACTOR) {
2968 // caps out at ~10^8m from nearest object
2969 // which takes ~10 minutes of flying
2970 hyperspeedFactor = MAX_HYPERSPEED_FACTOR;
2971 }
2972 }
2973 }
2974#endif
2975
2976 [self setAlertFlag:ALERT_FLAG_MASS_LOCK
2977 to:massLocked];
2978
2979 [self setAlertFlag:ALERT_FLAG_HOSTILES to:foundHostiles];
2980
2981 for (i = 0; i < ent_count; i++) {
2982 [my_entities[i] release]; // released
2983 }
2984
2985 BOOL energyCritical = NO;
2986 if (energy < 64 && energy < maxEnergy * 0.8) {
2987 energyCritical = YES;
2988 }
2989 [self setAlertFlag:ALERT_FLAG_ENERGY to:energyCritical];
2990
2991 [self setAlertFlag:ALERT_FLAG_TEMP to:([self hullHeatLevel] > .90)];
2992
2993 [self setAlertFlag:ALERT_FLAG_ALT to:([self dialAltitude] < .10)];
2994}
#define SCANNER_MAX_RANGE
Definition Entity.h:53
#define MAX_HYPERSPEED_FACTOR
#define MIN_HYPERSPEED_FACTOR
BOOL hasHostileTarget()

References PlayerEntity::checkEntityForMassLock:withScanClass:, PlayerEntity::clearAlertFlags, Entity::collisionRadius, PlayerEntity::dialAltitude, EXPECT_NOT, ShipEntity::hasHostileTarget, ShipEntity::hullHeatLevel, Entity::isShip, MAX_HYPERSPEED_FACTOR, MIN_HYPERSPEED_FACTOR, nil, ShipEntity::primaryTarget, Entity::scanClass, SCANNER_MAX_RANGE, SCANNER_MAX_RANGE2, PlayerEntity::setAlertFlag:to:, UNIVERSE, updateAlertConditionForNearbyEntities, and Entity::zero_distance.

Referenced by setExtraEquipmentFromFlags, updateAlertCondition, and updateAlertConditionForNearbyEntities.

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

◆ updateClocks:

- (void) updateClocks: (OOTimeDelta) delta_t

Extends class PlayerEntity.

Definition at line 3110 of file PlayerEntity.m.

3110 :(OOTimeDelta)delta_t
3111{
3112 // shot time updates are still needed here for STATUS_DEAD!
3113 shot_time += delta_t;
3114 script_time += delta_t;
3115 unsigned prev_day = floor(ship_clock / 86400);
3116 ship_clock += delta_t;
3117 if (ship_clock_adjust > 0.0) // adjust for coming out of warp (add LY * LY hrs)
3118 {
3119 double fine_adjust = delta_t * 7200.0;
3120 if (ship_clock_adjust > 86400) // more than a day
3121 fine_adjust = delta_t * 115200.0; // 16 times faster
3122 if (ship_clock_adjust > 0) {
3123 if (fine_adjust > ship_clock_adjust)
3124 fine_adjust = ship_clock_adjust;
3125 ship_clock += fine_adjust;
3126 ship_clock_adjust -= fine_adjust;
3127 } else {
3128 if (fine_adjust < ship_clock_adjust)
3129 fine_adjust = ship_clock_adjust;
3130 ship_clock -= fine_adjust;
3131 ship_clock_adjust += fine_adjust;
3132 }
3133 } else
3134 ship_clock_adjust = 0.0;
3135
3136 unsigned now_day = floor(ship_clock / 86400.0);
3137 while (prev_day < now_day) {
3138 prev_day++;
3139 [self doScriptEvent:OOJSID("dayChanged") withArgument:[NSNumber numberWithUnsignedInt:prev_day]];
3140 // not impossible that at ultra-low frame rates two of these will
3141 // happen in a single update.
3142 }
3143
3144 // fps
3145 if (ship_clock > fps_check_time) {
3146 if (![self clockAdjusting]) {
3147 fps_counter = (int)([UNIVERSE timeAccelerationFactor] * floor([UNIVERSE framesDoneThisUpdate] / (fps_check_time - last_fps_check_time)));
3148 last_fps_check_time = fps_check_time;
3149 fps_check_time = ship_clock + MINIMUM_GAME_TICK;
3150 } else {
3151 // Good approximation for when the clock is adjusting and proper fps calculation
3152 // cannot be performed.
3153 fps_counter = (int)([UNIVERSE timeAccelerationFactor] * floor(1.0 / delta_t));
3154 fps_check_time = ship_clock + MINIMUM_GAME_TICK;
3155 }
3156 [UNIVERSE resetFramesDoneThisUpdate]; // Reset frame counter
3157 }
3158}
#define MINIMUM_GAME_TICK

References ShipEntity::doScriptEvent:withArgument:, int(), MINIMUM_GAME_TICK, and UNIVERSE.

Referenced by PlayerEntity::update:.

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

◆ updateFuelScoops:

- (void) updateFuelScoops: (OOTimeDelta) delta_t

Extends class PlayerEntity.

Definition at line 3099 of file PlayerEntity.m.

3099 :(OOTimeDelta)delta_t
3100{
3101 if (scoopsActive) {
3102 [self updateFuelScoopSoundWithInterval:delta_t];
3103 if (![self scoopOverride]) {
3104 scoopsActive = NO;
3105 [self updateFuelScoopSoundWithInterval:delta_t];
3106 }
3107 }
3108}

References PlayerEntity::updateFuelScoopSoundWithInterval:.

Referenced by PlayerEntity::update:.

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

◆ updateMovementFlags

- (void) updateMovementFlags

Extends class PlayerEntity.

Definition at line 2885 of file PlayerEntity.m.

2886{
2887 hasMoved = !HPvector_equal(position, lastPosition);
2888 hasRotated = !quaternion_equal(orientation, lastOrientation);
2889 lastPosition = position;
2890 lastOrientation = orientation;
2891}
OOINLINE bool HPvector_equal(HPVector a, HPVector b) INLINE_CONST_FUNC
Definition OOHPVector.h:250
OOINLINE bool quaternion_equal(Quaternion a, Quaternion b) INLINE_CONST_FUNC

References HPvector_equal(), quaternion_equal(), and updateMovementFlags.

Referenced by setExtraEquipmentFromFlags, PlayerEntity::update:, and updateMovementFlags.

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

◆ updateTargeting

- (void) updateTargeting

Extends class PlayerEntity.

Definition at line 3699 of file PlayerEntity.m.

3700{
3702
3703 // check for lost ident target and ensure the ident system is actually scanning
3704 UPDATE_STAGE(@"checking ident target");
3705 if (ident_engaged && [self primaryTarget] != nil) {
3706 if (![self isValidTarget:[self primaryTarget]]) {
3707 if (!suppressTargetLost) {
3708 [UNIVERSE addMessage:DESC(@"target-lost") forCount:3.0];
3709 [self playTargetLost];
3710 [self noteLostTarget];
3711 } else {
3712 suppressTargetLost = NO;
3713 }
3714
3715 DESTROY(_primaryTarget);
3716 }
3717 }
3718
3719 // check each unlaunched missile's target still exists and is in-range
3720 UPDATE_STAGE(@"checking missile targets");
3721 if (missile_status != MISSILE_STATUS_SAFE) {
3722 unsigned i;
3723 for (i = 0; i < max_missiles; i++) {
3724 if ([missile_entity[i] primaryTarget] != nil && ![self isValidTarget:[missile_entity[i] primaryTarget]]) {
3725 [UNIVERSE addMessage:DESC(@"target-lost") forCount:3.0];
3726 [self playTargetLost];
3727 [missile_entity[i] removeTarget:nil];
3728 if (i == activeMissile) {
3729 [self noteLostTarget];
3730 DESTROY(_primaryTarget);
3731 missile_status = MISSILE_STATUS_ARMED;
3732 }
3733 } else if (i == activeMissile && [missile_entity[i] primaryTarget] == nil) {
3734 missile_status = MISSILE_STATUS_ARMED;
3735 }
3736 }
3737 }
3738
3739 // if we don't have a primary target, and we're scanning, then check for a new
3740 // target to lock on to
3741 UPDATE_STAGE(@"looking for new target");
3742 if ([self primaryTarget] == nil && (ident_engaged || missile_status != MISSILE_STATUS_SAFE) && ([self status] == STATUS_IN_FLIGHT || [self status] == STATUS_WITCHSPACE_COUNTDOWN)) {
3743 Entity* target = [UNIVERSE firstEntityTargetedByPlayer];
3744 if ([self isValidTarget:target]) {
3745 [self addTarget:target];
3746 }
3747 }
3748
3749 // If our primary target is a wormhole, check to see if we have additional
3750 // information
3751 UPDATE_STAGE(@"checking for additional wormhole information");
3752 if ([[self primaryTarget] isWormhole]) {
3753 WormholeEntity* wh = [self primaryTarget];
3754 switch ([wh scanInfo]) {
3755 case WH_SCANINFO_NONE:
3756 OOLog(kOOLogInconsistentState, @"%@", @"Internal Error - WH_SCANINFO_NONE reached in [PlayerEntity updateTargeting:]");
3757 [self dumpState];
3758 [wh dumpState];
3759 // Workaround a reported hit of the assert here. We really
3760 // should work out how/why this could happen though and fix
3761 // the underlying cause.
3762 // - MKW 2011.03.11
3763 // assert([wh scanInfo] != WH_SCANINFO_NONE);
3764 [wh setScannedAt:[self clockTimeAdjusted]];
3765 break;
3767 if ([self clockTimeAdjusted] > [wh scanTime] + 2) {
3768 [wh setScanInfo:WH_SCANINFO_COLLAPSE_TIME];
3769 //[UNIVERSE addCommsMessage:[NSString stringWithFormat:DESC(@"wormhole-collapse-time-computed"),
3770 // [UNIVERSE getSystemName:[wh destination]]] forCount:5.0];
3771 }
3772 break;
3774 if ([self clockTimeAdjusted] > [wh scanTime] + 4) {
3775 [wh setScanInfo:WH_SCANINFO_ARRIVAL_TIME];
3776 [UNIVERSE addCommsMessage:[NSString stringWithFormat:DESC(@"wormhole-arrival-time-computed-@"),
3777 ClockToString([wh estimatedArrivalTime], NO)]
3778 forCount:5.0];
3779 }
3780 break;
3782 if ([self clockTimeAdjusted] > [wh scanTime] + 7) {
3783 [wh setScanInfo:WH_SCANINFO_DESTINATION];
3784 [UNIVERSE addCommsMessage:[NSString stringWithFormat:DESC(@"wormhole-destination-computed-@"),
3785 [UNIVERSE getSystemName:[wh destination]]]
3786 forCount:5.0];
3787 }
3788 break;
3790 if ([self clockTimeAdjusted] > [wh scanTime] + 10) {
3791 [wh setScanInfo:WH_SCANINFO_SHIP];
3792 // TODO: Extract last ship from wormhole and display its name
3793 }
3794 break;
3795 case WH_SCANINFO_SHIP:
3796 break;
3797 }
3798 }
3799
3801}
#define DESTROY(x)
NSString *const kOOLogInconsistentState
Definition OOLogging.m:599
@ MISSILE_STATUS_ARMED
@ MISSILE_STATUS_SAFE
@ WH_SCANINFO_NONE
@ WH_SCANINFO_SCANNED
@ WH_SCANINFO_SHIP
@ WH_SCANINFO_ARRIVAL_TIME
@ WH_SCANINFO_DESTINATION
@ WH_SCANINFO_COLLAPSE_TIME
void dumpState()
Definition Entity.m:903
double estimatedArrivalTime()
OOSystemID destination
void setScannedAt:(double time)
void setScanInfo:(WORMHOLE_SCANINFO scanInfo)

References PlayerEntity::addTarget:, PlayerEntity::clockTimeAdjusted, WormholeEntity::destination, DESTROY, Entity::dumpState, WormholeEntity::estimatedArrivalTime, kOOLogInconsistentState, MISSILE_STATUS_ARMED, MISSILE_STATUS_SAFE, nil, ShipEntity::noteLostTarget, OOLog, PlayerEntity::playTargetLost, ShipEntity::primaryTarget, WormholeEntity::setScanInfo:, WormholeEntity::setScannedAt:, STAGE_TRACKING_BEGIN, STAGE_TRACKING_END, UPDATE_STAGE, updateTargeting, WH_SCANINFO_ARRIVAL_TIME, WH_SCANINFO_COLLAPSE_TIME, WH_SCANINFO_DESTINATION, WH_SCANINFO_NONE, WH_SCANINFO_SCANNED, and WH_SCANINFO_SHIP.

Referenced by performInFlightUpdates:, setExtraEquipmentFromFlags, and updateTargeting.

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

◆ updateTrumbles:

- (void) updateTrumbles: (OOTimeDelta) delta_t

Extends class PlayerEntity.

Definition at line 3211 of file PlayerEntity.m.

3211 :(OOTimeDelta)delta_t
3212{
3213 OOTrumble** trumbles = [self trumbleArray];
3214 NSUInteger i;
3215
3216 for (i = [self trumbleCount]; i > 0; i--) {
3217 OOTrumble* trum = trumbles[i - 1];
3218 [trum updateTrumble:delta_t];
3219 }
3220}
void updateTrumble:(double delta_t)
Definition OOTrumble.m:490

References PlayerEntity::trumbleArray, and OOTrumble::updateTrumble:.

Referenced by PlayerEntity::update:.

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

◆ updateWormholes

- (void) updateWormholes

Extends class PlayerEntity.

Definition at line 11594 of file PlayerEntity.m.

11595{
11596 assert(scannedWormholes != nil);
11597
11598 if ([scannedWormholes count] == 0)
11599 return;
11600
11601 double now = [self clockTimeAdjusted];
11602
11603 NSMutableArray* savedWormholes = [[NSMutableArray alloc] initWithCapacity:[scannedWormholes count]];
11604 WormholeEntity* wh;
11605
11606 foreach (wh, scannedWormholes) {
11607 // TODO: Start drawing wormhole exit a few seconds before the first
11608 // ship is disgorged.
11609 if ([wh arrivalTime] > now) {
11610 [savedWormholes addObject:wh];
11611 } else if (NSEqualPoints(galaxy_coordinates, [wh destinationCoordinates])) {
11612 [wh disgorgeShips];
11613 if ([[wh shipsInTransit] count] > 0) {
11614 [savedWormholes addObject:wh];
11615 }
11616 }
11617 // Else wormhole has expired in another system, let it expire
11618 }
11619
11620 [scannedWormholes release];
11621 scannedWormholes = savedWormholes;
11622}
unsigned count

References PlayerEntity::clockTimeAdjusted, count, WormholeEntity::disgorgeShips, nil, and updateWormholes.

Referenced by setExtraEquipmentFromFlags, PlayerEntity::update:, and updateWormholes.

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

◆ witchEnd

- (void) witchEnd

Extends class PlayerEntity.

Definition at line 6531 of file PlayerEntity.m.

6532{
6533 [UNIVERSE setSystemTo:system_id];
6534 galaxy_coordinates = [[UNIVERSE systemManager] getCoordinatesForSystem:system_id inGalaxy:galaxy_number];
6535
6536 [UNIVERSE setUpUniverseFromWitchspace];
6537 [[UNIVERSE planet] update:2.34375 * market_rnd]; // from 0..10 minutes
6538 [[UNIVERSE station] update:2.34375 * market_rnd]; // from 0..10 minutes
6539
6540 chart_centre_coordinates = galaxy_coordinates;
6541 target_chart_centre = chart_centre_coordinates;
6542}

References witchEnd.

Referenced by PlayerEntity::enterGalacticWitchspace, setExtraEquipmentFromFlags, witchEnd, and witchJumpTo:misjump:.

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

◆ witchJumpTo:misjump:

- (void) witchJumpTo: (OOSystemID) sTo
misjump: (BOOL) misjump 

Extends class PlayerEntity.

Definition at line 6861 of file PlayerEntity.m.

6861 :(OOSystemID)sTo misjump:(BOOL)misjump
6862{
6863 [self witchStart];
6864 if (info_system_id == system_id) {
6865 [self setInfoSystemID:sTo moveChart:YES];
6866 }
6867 // wear and tear on all jumps (inc misjumps, failures, and wormholes)
6868 if (2 * market_rnd < ship_trade_in_factor) {
6869 // every eight jumps or so drop the price down towards 75%
6870 [self adjustTradeInFactorBy:-(1 + (market_rnd & 3))];
6871 }
6872
6873 // set clock after "playerWillEnterWitchspace" and before removeAllEntitiesExceptPlayer, to allow escorts time to follow their mother.
6874 NSPoint destCoords = PointFromString([[UNIVERSE systemManager] getProperty:@"coordinates" forSystem:sTo inGalaxy:galaxy_number]);
6875 double distance = distanceBetweenPlanetPositions(destCoords.x, destCoords.y, galaxy_coordinates.x, galaxy_coordinates.y);
6876
6877 // if we just escaped a system gone nova, make sure all nova parameters are reset
6878 OOSunEntity* theSun = [UNIVERSE sun];
6879 if (theSun && [theSun goneNova]) {
6880 [theSun resetNova];
6881 }
6882
6883 [UNIVERSE removeAllEntitiesExceptPlayer];
6884 if (!misjump) {
6885 ship_clock_adjust += distance * distance * 3600.0;
6886 [self setSystemID:sTo];
6887 [self setBounty:(legalStatus / 2) withReason:kOOLegalStatusReasonNewSystem]; // 'another day, another system'
6888 [self witchEnd];
6889 if (market_rnd < 8)
6890 [self erodeReputation]; // every 32 systems or so, drop back towards 'unknown'
6891 } else {
6892 // Misjump: move halfway there!
6893 // misjumps do not change legal status.
6894 if (randf() < 0.1)
6895 [self erodeReputation]; // once every 10 misjumps - should be much rarer than successful jumps!
6896
6897 [wormhole setMisjump];
6898 // just in case, but this has usually been set already
6899
6900 // and now the wormhole has travel time and coordinates calculated
6901 // so rather than duplicate the calculation we'll just ask it...
6902 NSPoint dest = [wormhole destinationCoordinates];
6903 galaxy_coordinates.x = dest.x;
6904 galaxy_coordinates.y = dest.y;
6905
6906 ship_clock_adjust += [wormhole travelTime];
6907
6908 [self playWitchjumpMisjump];
6909 [UNIVERSE setUpUniverseFromMisjump];
6910 }
6911}
OOINLINE OOScalar distance(Vector v1, Vector v2) INLINE_CONST_FUNC
Definition OOVector.h:280
float randf(void)

References PlayerEntity::adjustTradeInFactorBy:, distance(), distanceBetweenPlanetPositions(), PlayerEntity::erodeReputation, PlayerEntity::playWitchjumpMisjump, PointFromString(), randf(), OOSunEntity::resetNova, PlayerEntity::setBounty:withReason:, PlayerEntity::setInfoSystemID:moveChart:, PlayerEntity::setSystemID:, UNIVERSE, PlayerEntity::witchEnd, and PlayerEntity::witchStart.

Referenced by PlayerEntity::enterWitchspace, and PlayerEntity::enterWormhole:.

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

◆ witchStart

- (void) witchStart

Extends class PlayerEntity.

Definition at line 6488 of file PlayerEntity.m.

6489{
6490 // chances of entering witchspace with autopilot on are very low, but as Berlios bug #18307 has shown us, entirely possible
6491 // so in such cases we need to ensure that at least the docking music stops playing
6492 if (autopilot_engaged)
6493 [self disengageAutopilot];
6494
6495 if (![hud nonlinearScanner]) {
6496 [hud setScannerZoom:1.0];
6497 }
6498 [self safeAllMissiles];
6499
6500 OOViewID previousViewDirection = [UNIVERSE viewDirection];
6501 [UNIVERSE setViewDirection:VIEW_FORWARD];
6502 [self noteSwitchToView:VIEW_FORWARD fromView:previousViewDirection]; // notifies scripts of the switch
6503
6504 currentWeaponFacing = WEAPON_FACING_FORWARD;
6505 [self currentWeaponStats];
6506
6507 [self transitionToAegisNone];
6508 suppressAegisMessages = YES;
6509 hyperspeed_engaged = NO;
6510
6511 if ([self primaryTarget] != nil) {
6512 [self noteLostTarget]; // losing target? Fire lost target event!
6513 DESTROY(_primaryTarget);
6514 }
6515
6516 scanner_zoom_rate = 0.0f;
6517 [UNIVERSE setDisplayText:NO];
6518
6519 if (![self wormhole] && !galactic_witchjump) // galactic hyperspace does not generate a wormhole
6520 {
6521 OOLog(kOOLogInconsistentState, @"%@", @"Internal Error : Player entering witchspace with no wormhole.");
6522 }
6523 [UNIVERSE allShipsDoScriptEvent:OOJSID("playerWillEnterWitchspace") andReactToAIMessage:@"PLAYER WITCHSPACE"];
6524
6525 // set the new market seed now!
6526 // reseeding the RNG should be completely unnecessary here
6527 // ranrot_srand((uint32_t)[[NSDate date] timeIntervalSince1970]); // seed randomiser by time
6528 market_rnd = ranrot_rand() & 255; // random factor for market values is reset
6529}
OOViewID
Definition OOTypes.h:39
#define ranrot_rand()

References PlayerEntity::currentWeaponStats, DESTROY, PlayerEntity::disengageAutopilot, kOOLogInconsistentState, nil, ShipEntity::noteLostTarget, PlayerEntity::noteSwitchToView:fromView:, OOLog, ranrot_rand, PlayerEntity::safeAllMissiles, ShipEntity::transitionToAegisNone, WEAPON_FACING_FORWARD, and witchStart.

Referenced by PlayerEntity::enterGalacticWitchspace, setExtraEquipmentFromFlags, witchJumpTo:misjump:, and witchStart.

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

The documentation for this category was generated from the following file: