Oolite 1.91.0.7644-241112-7f5034b
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:markers:
 
(void) - witchStart
 
(void) - witchJumpTo:misjump:
 
(void) - witchEnd
 
(double) - hyperspaceJumpDistance
 
(OOFuelQuantity- fuelRequiredForJump
 
(void) - noteCompassLostTarget
 

Detailed Description

Definition at line 113 of file PlayerEntity.m.

Method Documentation

◆ checkEntityForMassLock:withScanClass:

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

Extends class PlayerEntity.

Definition at line 13699 of file PlayerEntity.m.

3334 :(Entity *)ent withScanClass:(int)theirClass
3335{
3336 BOOL massLocked = NO;
3337 BOOL entIsCloakedShip = [ent isShip] && [(ShipEntity *)ent isCloaked];
3338
3339 if (EXPECT_NOT([ent isStellarObject]))
3340 {
3342 if (EXPECT([stellar planetType] != STELLAR_TYPE_MINIATURE))
3343 {
3344 double dist = stellar->zero_distance;
3345 double rad = stellar->collision_radius;
3346 double factor = ([stellar isSun]) ? 2.0 : 4.0;
3347 // plus ensure mass lock when 25 km or less from the surface of small stellar bodies
3348 // dist is a square distance so it needs to be compared to (rad+25000) * (rad+25000)!
3349 if (dist < rad*rad*factor || dist < rad*rad + 50000*rad + 625000000 )
3350 {
3351 massLocked = YES;
3352 }
3353 }
3354 }
3355 else if (theirClass != CLASS_NO_DRAW)
3356 {
3357 if (EXPECT_NOT (entIsCloakedShip))
3358 {
3359 theirClass = CLASS_NO_DRAW;
3360 }
3361 }
3362
3363 if (!massLocked && ent->zero_distance <= SCANNER_MAX_RANGE2)
3364 {
3365 switch (theirClass)
3366 {
3367 case CLASS_NO_DRAW:
3368 // cloaked ships do mass lock! - Nikos 20200718
3369 if (entIsCloakedShip && ![ent isPlayer])
3370 {
3371 massLocked = YES;
3372 }
3373 break;
3374 case CLASS_PLAYER:
3375 case CLASS_BUOY:
3376 case CLASS_ROCK:
3377 case CLASS_CARGO:
3378 case CLASS_MINE:
3379 case CLASS_VISUAL_EFFECT:
3380 break;
3381
3382 case CLASS_THARGOID:
3383 case CLASS_MISSILE:
3384 case CLASS_STATION:
3385 case CLASS_POLICE:
3386 case CLASS_MILITARY:
3387 case CLASS_WORMHOLE:
3388 default:
3389 massLocked = YES;
3390 break;
3391 }
3392 }
3393
3394 return massLocked;
3395}
#define SCANNER_MAX_RANGE2
Definition Entity.h:52
#define EXPECT_NOT(x)
#define EXPECT(x)
@ STELLAR_TYPE_MINIATURE
GLfloat collision_radius
Definition Entity.h:111
BOOL isSun()
Definition Entity.m:167
GLfloat zero_distance
Definition Entity.h:108
unsigned isShip
Definition Entity.h:91
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque

◆ checkScriptsIfAppropriate

- (void) checkScriptsIfAppropriate

Extends class PlayerEntity.

Definition at line 13699 of file PlayerEntity.m.

3519{
3520 if (script_time <= script_time_check) return;
3521
3522 if ([self status] != STATUS_IN_FLIGHT)
3523 {
3524 switch (gui_screen)
3525 {
3526 // Screens where no world script tickles are performed
3527 case GUI_SCREEN_MAIN:
3528 case GUI_SCREEN_INTRO1:
3529 case GUI_SCREEN_SHIPLIBRARY:
3530 case GUI_SCREEN_KEYBOARD:
3531 case GUI_SCREEN_NEWGAME:
3532 case GUI_SCREEN_OXZMANAGER:
3533 case GUI_SCREEN_MARKET:
3534 case GUI_SCREEN_MARKETINFO:
3535 case GUI_SCREEN_OPTIONS:
3536 case GUI_SCREEN_GAMEOPTIONS:
3537 case GUI_SCREEN_LOAD:
3538 case GUI_SCREEN_SAVE:
3539 case GUI_SCREEN_SAVE_OVERWRITE:
3540 case GUI_SCREEN_STICKMAPPER:
3541 case GUI_SCREEN_STICKPROFILE:
3542 case GUI_SCREEN_MISSION:
3543 case GUI_SCREEN_REPORT:
3544 case GUI_SCREEN_KEYBOARD_CONFIRMCLEAR:
3545 case GUI_SCREEN_KEYBOARD_CONFIG:
3546 case GUI_SCREEN_KEYBOARD_ENTRY:
3547 case GUI_SCREEN_KEYBOARD_LAYOUT:
3548 return;
3549
3550 // Screens from which it's safe to jump to the mission screen
3551// case GUI_SCREEN_CONTRACTS:
3552 case GUI_SCREEN_EQUIP_SHIP:
3553 case GUI_SCREEN_INTERFACES:
3554 case GUI_SCREEN_MANIFEST:
3555 case GUI_SCREEN_SHIPYARD:
3556 case GUI_SCREEN_LONG_RANGE_CHART:
3557 case GUI_SCREEN_SHORT_RANGE_CHART:
3558 case GUI_SCREEN_STATUS:
3559 case GUI_SCREEN_SYSTEM_DATA:
3560 // Test passed, we can run scripts. Nothing to do here.
3561 break;
3562 }
3563 }
3564
3565 // Test either passed or never ran, run scripts.
3566 [self checkScript];
3567 script_time_check += script_time_interval;
3568}

◆ contractsListForScriptingFromArray:forCargo:

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

Extends class PlayerEntity.

Definition at line 13699 of file PlayerEntity.m.

8397 :(NSArray *) contracts_array forCargo:(BOOL)forCargo
8398{
8399 NSMutableArray *result = [NSMutableArray array];
8400 NSUInteger i;
8401
8402 for (i = 0; i < [contracts_array count]; i++)
8403 {
8404 NSMutableDictionary *contract = [NSMutableDictionary dictionaryWithCapacity:10];
8405 NSDictionary *dict = [contracts_array oo_dictionaryAtIndex:i];
8406 if (forCargo)
8407 {
8408 // commodity, quantity - keep consistency between .manifest and .contracts
8409 [contract setObject:[dict oo_stringForKey:CARGO_KEY_TYPE] forKey:@"commodity"];
8410 [contract setObject:[NSNumber numberWithUnsignedInt:[dict oo_intForKey:CARGO_KEY_AMOUNT]] forKey:@"quantity"];
8411 [contract setObject:[dict oo_stringForKey:CARGO_KEY_DESCRIPTION] forKey:@"description"];
8412 }
8413 else
8414 {
8415 [contract setObject:[dict oo_stringForKey:PASSENGER_KEY_NAME] forKey:PASSENGER_KEY_NAME];
8416 [contract setObject:[NSNumber numberWithUnsignedInt:[dict oo_unsignedIntForKey:CONTRACT_KEY_RISK]] forKey:CONTRACT_KEY_RISK];
8417 }
8418
8419 OOSystemID planet = [dict oo_intForKey:CONTRACT_KEY_DESTINATION];
8420 NSString *planetName = [UNIVERSE getSystemName:planet];
8421 [contract setObject:[NSNumber numberWithUnsignedInt:planet] forKey:CONTRACT_KEY_DESTINATION];
8422 [contract setObject:planetName forKey:@"destinationName"];
8423 planet = [dict oo_intForKey:CONTRACT_KEY_START];
8424 planetName = [UNIVERSE getSystemName: planet];
8425 [contract setObject:[NSNumber numberWithUnsignedInt:planet] forKey:CONTRACT_KEY_START];
8426 [contract setObject:planetName forKey:@"startName"];
8427
8428 int dest_eta = [dict oo_doubleForKey:CONTRACT_KEY_ARRIVAL_TIME] - ship_clock;
8429 [contract setObject:[NSNumber numberWithInt:dest_eta] forKey:@"eta"];
8430 [contract setObject:[UNIVERSE shortTimeDescription:dest_eta] forKey:@"etaDescription"];
8431 [contract setObject:[NSNumber numberWithInt:[dict oo_intForKey:CONTRACT_KEY_PREMIUM]] forKey:CONTRACT_KEY_PREMIUM];
8432 [contract setObject:[NSNumber numberWithInt:[dict oo_intForKey:CONTRACT_KEY_FEE]] forKey:CONTRACT_KEY_FEE];
8433 [result addObject:contract];
8434 }
8435
8436 return [[result copy] autorelease]; // return an immutable copy
8437}
int16_t OOSystemID
Definition OOTypes.h:211

◆ doTradeIn:forPriceFactor:

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

Extends class PlayerEntity.

Definition at line 9211 of file PlayerEntity.m.

10665 :(OOCreditsQuantity)tradeInValue forPriceFactor:(double)priceFactor
10666{
10667 if (tradeInValue != 0)
10668 {
10669 if (priceFactor < 1.0) tradeInValue *= priceFactor;
10670 credits += tradeInValue;
10671 }
10672}
uint64_t OOCreditsQuantity
Definition OOTypes.h:182

◆ fuelRequiredForJump

- (OOFuelQuantity) fuelRequiredForJump

Extends class PlayerEntity.

Definition at line 13699 of file PlayerEntity.m.

7470{
7471 return 10.0 * MAX(0.1, [self hyperspaceJumpDistance]);
7472}
#define MAX(A, B)
Definition OOMaths.h:114

◆ gameOverFadeToBW

- (void) gameOverFadeToBW

Extends class PlayerEntity.

Definition at line 13699 of file PlayerEntity.m.

3950{
3951 float secondsToBWFadeOut = [[NSUserDefaults standardUserDefaults] oo_floatForKey:@"gameover-seconds-to-bw-fadeout" defaultValue:5.0f];
3952 if ([UNIVERSE detailLevel] >= DETAIL_LEVEL_SHADERS && secondsToBWFadeOut > 0.0f)
3953 {
3954 MyOpenGLView *gameView = [UNIVERSE gameView];
3955 static float originalColorSaturation = -1.0f;
3956 if (originalColorSaturation == -1.0f) originalColorSaturation = [gameView colorSaturation];
3957 if ([self shotTime] < secondsToBWFadeOut)
3958 {
3959 // fade to black & white within secondsToBWFadeOut, independently of
3960 // frame rate and original color saturation
3961 if (fps_counter != 0)
3962 {
3963 [gameView adjustColorSaturation:-(originalColorSaturation * (1.0f / secondsToBWFadeOut) * [UNIVERSE timeAccelerationFactor] / fps_counter)];
3964 }
3965 }
3966
3967 if ([self shotTime] > kDeadResetTime)
3968 {
3969 // make sure to subtract the current saturation because if the user presses space to skip
3970 // the game over screen before the transition to b/w has been completed, whatever is left
3971 // will be added to the original saturation, resulting in an oversaturated image
3972 [gameView adjustColorSaturation:originalColorSaturation - [gameView colorSaturation]];
3973 originalColorSaturation = -1.0f;
3974 }
3975 }
3976}
@ DETAIL_LEVEL_SHADERS
Definition OOTypes.h:246
static float const kDeadResetTime
#define UNIVERSE
Definition Universe.h:833
void adjustColorSaturation:(float colorSaturationAdjustment)
float colorSaturation()

◆ hyperspaceJumpDistance

- (double) hyperspaceJumpDistance

Extends class PlayerEntity.

Definition at line 13699 of file PlayerEntity.m.

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

◆ noteCompassLostTarget

- (void) noteCompassLostTarget

Extends class PlayerEntity.

Definition at line 13699 of file PlayerEntity.m.

7482{
7483 if ([[self hud] isCompassActive])
7484 {
7485 // "the compass, it says we're lost!" :)
7486 JSContext *context = OOJSAcquireContext();
7487 jsval jsmode = OOJSValueFromCompassMode(context, [self compassMode]);
7488 ShipScriptEvent(context, self, "compassTargetChanged", JSVAL_VOID, jsmode);
7489 OOJSRelinquishContext(context);
7490
7491 [[self hud] setCompassActive:NO]; // ensure a target change when returning to normal space.
7492 }
7493}
OOINLINE jsval OOJSValueFromCompassMode(JSContext *context, OOCompassMode value)
OOINLINE JSContext * OOJSAcquireContext(void)
OOINLINE void OOJSRelinquishContext(JSContext *context)
#define ShipScriptEvent(context, ship, event,...)

◆ performAutopilotUpdates:

- (void) performAutopilotUpdates: (OOTimeDelta) delta_t

Extends class PlayerEntity.

Definition at line 13699 of file PlayerEntity.m.

3584 :(OOTimeDelta)delta_t
3585{
3586 [self processBehaviour:delta_t];
3587 [self applyVelocity:delta_t];
3588 [self doBookkeeping:delta_t];
3589}
double OOTimeDelta
Definition OOTypes.h:224

◆ performDeadUpdates:

- (void) performDeadUpdates: (OOTimeDelta) delta_t

Extends class PlayerEntity.

Definition at line 13699 of file PlayerEntity.m.

3936 :(OOTimeDelta)delta_t
3937{
3938 [self gameOverFadeToBW];
3939
3940 if ([self shotTime] > kDeadResetTime)
3941 {
3942 BOOL was_mouse_control_on = mouse_control_on;
3943 [UNIVERSE handleGameOver]; // we restart the UNIVERSE
3944 mouse_control_on = was_mouse_control_on;
3945 }
3946}

◆ performDockingUpdates:

- (void) performDockingUpdates: (OOTimeDelta) delta_t

Extends class PlayerEntity.

Definition at line 13699 of file PlayerEntity.m.

3927 :(OOTimeDelta)delta_t
3928{
3929 if ([UNIVERSE breakPatternOver])
3930 {
3931 [self docked]; // bookkeeping for docking
3932 }
3933}

◆ performInFlightUpdates:

- (void) performInFlightUpdates: (OOTimeDelta) delta_t

Extends class PlayerEntity.

Definition at line 13699 of file PlayerEntity.m.

3736 :(OOTimeDelta)delta_t
3737{
3739
3740 // do flight routines
3742 UPDATE_STAGE(@"applying newtonian drift");
3744
3745 [self applyVelocity:delta_t];
3746
3747 GLfloat thrust_factor = 1.0;
3748 if (flightSpeed > maxFlightSpeed)
3749 {
3750 if (afterburner_engaged)
3751 {
3752 thrust_factor = [self afterburnerFactor];
3753 }
3754 else
3755 {
3756 thrust_factor = HYPERSPEED_FACTOR;
3757 }
3758 }
3759
3760
3761 GLfloat velmag = magnitude(velocity);
3762 GLfloat velmag2 = velmag - (float)delta_t * thrust * thrust_factor;
3763 if (velmag > 0)
3764 {
3765 UPDATE_STAGE(@"applying power braking");
3766
3767 if (velmag > VELOCITY_CLEANUP_MIN)
3768 {
3769 GLfloat rate;
3770 // Fix up extremely ridiculous speeds that can happen in collisions or explosions
3771 if (velmag > VELOCITY_CLEANUP_FULL) rate = VELOCITY_CLEANUP_RATE;
3773 velmag2 -= velmag * rate;
3774 }
3775 if (velmag2 < 0.0f) velocity = kZeroVector;
3776 else velocity = vector_multiply_scalar(velocity, velmag2 / velmag);
3777
3778 }
3779
3780 UPDATE_STAGE(@"updating joystick");
3781 [self applyRoll:(float)delta_t*flightRoll andClimb:(float)delta_t*flightPitch];
3782 if (flightYaw != 0.0)
3783 {
3784 [self applyYaw:(float)delta_t*flightYaw];
3785 }
3786
3787 UPDATE_STAGE(@"applying para-newtonian thrust");
3788 [self moveForward:delta_t*flightSpeed];
3789
3790 UPDATE_STAGE(@"updating targeting");
3791 [self updateTargeting];
3792
3794}
const Vector kZeroVector
Definition OOVector.m:28
#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

◆ performLaunchingUpdates:

- (void) performLaunchingUpdates: (OOTimeDelta) delta_t

Extends class PlayerEntity.

Definition at line 13699 of file PlayerEntity.m.

3904 :(OOTimeDelta)delta_t
3905{
3906 if (![UNIVERSE breakPatternHide])
3907 {
3908 flightRoll = launchRoll; // synchronise player's & launching station's spins.
3909 [self doBookkeeping:delta_t]; // don't show ghost exhaust plumes from previous docking!
3910 }
3911
3912 if ([UNIVERSE breakPatternOver])
3913 {
3914 // time to check the legacy scripts!
3915 [self checkScript];
3916 // next check in 10s
3917
3918 [self setStatus:STATUS_IN_FLIGHT];
3919
3920 [self setDockingClearanceStatus:DOCKING_CLEARANCE_STATUS_NONE];
3921 StationEntity *stationLaunchedFrom = [UNIVERSE nearestEntityMatchingPredicate:IsStationPredicate parameter:NULL relativeToEntity:self];
3922 [self doScriptEvent:OOJSID("shipLaunchedFromStation") withArgument:stationLaunchedFrom];
3923 }
3924}

◆ performWitchspaceCountdownUpdates:

- (void) performWitchspaceCountdownUpdates: (OOTimeDelta) delta_t

Extends class PlayerEntity.

Definition at line 13699 of file PlayerEntity.m.

3797 :(OOTimeDelta)delta_t
3798{
3800
3801 UPDATE_STAGE(@"doing bookkeeping");
3802 [self doBookkeeping:delta_t];
3803
3804 UPDATE_STAGE(@"updating countdown timer");
3805 witchspaceCountdown = fdim(witchspaceCountdown, delta_t);
3806
3807 // damaged gal drive? abort!
3808 /* TODO: this check should possibly be hasEquipmentItemProviding:,
3809 * but if it was we'd need to know which item was actually doing
3810 * the providing so it could be removed. */
3811 if (EXPECT_NOT(galactic_witchjump && ![self hasEquipmentItem:@"EQ_GAL_DRIVE"]))
3812 {
3813 galactic_witchjump = NO;
3814 [self setStatus:STATUS_IN_FLIGHT];
3815 [self playHyperspaceAborted];
3816 ShipScriptEventNoCx(self, "playerJumpFailed", OOJSSTR("malfunction"));
3817 return;
3818 }
3819
3820 int seconds = round(witchspaceCountdown);
3821 if (galactic_witchjump)
3822 {
3823 [UNIVERSE displayCountdownMessage:OOExpandKey(@"witch-galactic-in-x-seconds", seconds) forCount:1.0];
3824 }
3825 else
3826 {
3827 NSString *destination = [UNIVERSE getSystemName:[self nextHopTargetSystemID]];
3828 [UNIVERSE displayCountdownMessage:OOExpandKey(@"witch-to-x-in-y-seconds", seconds, destination) forCount:1.0];
3829 }
3830
3831 if (witchspaceCountdown == 0.0)
3832 {
3833 UPDATE_STAGE(@"preloading planet textures");
3834 if (!galactic_witchjump)
3835 {
3836 /* Note: planet texture preloading is done twice for hyperspace jumps:
3837 once when starting the countdown and once at the beginning of the
3838 jump. The reason is that the preloading may have been skipped the
3839 first time because of rate limiting (see notes at
3840 -preloadPlanetTexturesForSystem:). There is no significant overhead
3841 from doing it twice thanks to the texture cache.
3842 -- Ahruman 2009-12-19
3843 */
3844 [UNIVERSE preloadPlanetTexturesForSystem:target_system_id];
3845 }
3846 else
3847 {
3848 // FIXME: preload target system for galactic jump?
3849 }
3850
3851 UPDATE_STAGE(@"JUMP!");
3852 if (galactic_witchjump) [self enterGalacticWitchspace];
3853 else [self enterWitchspace];
3854 galactic_witchjump = NO;
3855 }
3856
3858}
#define OOJSSTR(str)
#define ShipScriptEventNoCx(ship, event,...)

◆ performWitchspaceExitUpdates:

- (void) performWitchspaceExitUpdates: (OOTimeDelta) delta_t

Extends class PlayerEntity.

Definition at line 13699 of file PlayerEntity.m.

3861 :(OOTimeDelta)delta_t
3862{
3863 if ([UNIVERSE breakPatternOver])
3864 {
3865 [self resetExhaustPlumes];
3866 // time to check the script!
3867 [self checkScript];
3868 // next check in 10s
3869 [self resetScriptTimer]; // reset the in-system timer
3870
3871 // announce arrival
3872 if ([UNIVERSE planet])
3873 {
3874 [UNIVERSE addMessage:[NSString stringWithFormat:@" %@. ",[UNIVERSE getSystemName:system_id]] forCount:3.0];
3875 // and reset the compass
3876 if ([self hasEquipmentItemProviding:@"EQ_ADVANCED_COMPASS"])
3877 compassMode = COMPASS_MODE_PLANET;
3878 else
3879 compassMode = COMPASS_MODE_BASIC;
3880 }
3881 else
3882 {
3883 if ([UNIVERSE inInterstellarSpace]) [UNIVERSE addMessage:DESC(@"witch-engine-malfunction") forCount:3.0]; // if sun gone nova, print nothing
3884 }
3885
3886 [self setStatus:STATUS_IN_FLIGHT];
3887
3888 // If we are exiting witchspace after a scripted misjump. then make sure it gets reset now.
3889 // Scripted misjump situations should have a lifespan of one jump only, to keep things
3890 // simple - Nikos 20090728
3891 if ([self scriptedMisjump]) [self setScriptedMisjump:NO];
3892 // similarly reset the misjump range to the traditional 0.5
3893 [self setScriptedMisjumpRange:0.5];
3894
3895 [self doScriptEvent:OOJSID("shipExitedWitchspace") withArgument:[self jumpCause]];
3896
3897 [self doBookkeeping:delta_t]; // arrival frame updates
3898
3899 suppressAegisMessages=NO;
3900 }
3901}

◆ prepareMarkedDestination:markers:

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

Extends class PlayerEntity.

Definition at line 13699 of file PlayerEntity.m.

8688 :(NSMutableDictionary *)markers :(NSDictionary *)marker
8689{
8690 NSNumber *key = [NSNumber numberWithInt:[marker oo_intForKey:@"system"]];
8691 NSMutableArray *list = [markers objectForKey:key];
8692 if (list == nil)
8693 {
8694 list = [NSMutableArray arrayWithObject:marker];
8695 }
8696 else
8697 {
8698 [list addObject:marker];
8699 }
8700 [markers setObject:list forKey:key];
8701}
return nil

◆ setExtraEquipmentFromFlags

- (void) setExtraEquipmentFromFlags

Extends class PlayerEntity.

◆ showGameOver

- (void) showGameOver

Extends class PlayerEntity.

Definition at line 13699 of file PlayerEntity.m.

4022{
4023 [hud resetGuis:[NSDictionary dictionaryWithObject:[NSDictionary dictionary] forKey:@"message_gui"]];
4024 NSString *scoreMS = [NSString stringWithFormat:OOExpandKey(@"gameoverscreen-score-@"),
4025 KillCountToRatingAndKillString(ship_kills)];
4026
4027 [UNIVERSE displayMessage:OOExpandKey(@"gameoverscreen-game-over") forCount:kDeadResetTime];
4028 [UNIVERSE displayMessage:@"" forCount:kDeadResetTime];
4029 [UNIVERSE displayMessage:scoreMS forCount:kDeadResetTime];
4030 [UNIVERSE displayMessage:@"" forCount:kDeadResetTime];
4031 [UNIVERSE displayMessage:OOExpandKey(@"gameoverscreen-press-space") forCount:kDeadResetTime];
4032 [UNIVERSE displayMessage:@" " forCount:kDeadResetTime];
4033 [UNIVERSE displayMessage:@"" forCount:kDeadResetTime];
4034 [self resetShotTime];
4035}

◆ showMarketCashAndLoadLine

- (void) showMarketCashAndLoadLine

Extends class PlayerEntity.

Definition at line 9211 of file PlayerEntity.m.

11316{
11317 GuiDisplayGen *gui = [UNIVERSE gui];
11318 OOCargoQuantity currentCargo = current_cargo;
11319 OOCargoQuantity cargoCapacity = [self maxAvailableCargoSpace];
11320 [gui setText:OOExpandKey(@"market-cash-and-load", credits, currentCargo, cargoCapacity) forRow:GUI_ROW_MARKET_CASH];
11321 [gui setColor:[gui colorFromSetting:kGuiMarketCashColor defaultValue:[OOColor yellowColor]] forRow:GUI_ROW_MARKET_CASH];
11322}
uint32_t OOCargoQuantity
Definition OOTypes.h:176
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:292

◆ showMarketScreenDataLine:forGood:inMarket:holdQuantity:

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

Extends class PlayerEntity.

Definition at line 9211 of file PlayerEntity.m.

10921 :(OOGUIRow)row forGood:(OOCommodityType)good inMarket:(OOCommodityMarket *)localMarket holdQuantity:(OOCargoQuantity)quantity
10922{
10923 GuiDisplayGen *gui = [UNIVERSE gui];
10924 NSString* desc = [NSString stringWithFormat:@" %@ ", [shipCommodityData nameForGood:good]];
10925 OOCargoQuantity available_units = [localMarket quantityForGood:good];
10926 OOCargoQuantity units_in_hold = quantity;
10927 OOCreditsQuantity pricePerUnit = [localMarket priceForGood:good];
10928 OOMassUnit unit = [shipCommodityData massUnitForGood:good];
10929
10930 NSString *available = OOPadStringToEms(((available_units > 0) ? (NSString *)[NSString stringWithFormat:@"%d",available_units] : DESC(@"commodity-quantity-none")), 2.5);
10931
10932 NSUInteger priceDecimal = pricePerUnit % 10;
10933 NSString *price = [NSString stringWithFormat:@" %@.%lu ",OOPadStringToEms([NSString stringWithFormat:@"%lu",(unsigned long)(pricePerUnit/10)],2.5),priceDecimal];
10934
10935 // this works with up to 9999 tons of gemstones. Any more than that, they deserve the formatting they get! :)
10936
10937 NSString *owned = OOPadStringToEms((units_in_hold > 0) ? (NSString *)[NSString stringWithFormat:@"%d",units_in_hold] : DESC(@"commodity-quantity-none"), 4.5);
10938 NSString *units = DisplayStringForMassUnit(unit);
10939 NSString *units_available = [NSString stringWithFormat:@" %@ %@ ",available, units];
10940 NSString *units_owned = [NSString stringWithFormat:@" %@ %@ ",owned, units];
10941
10942 NSUInteger import_legality = [localMarket importLegalityForGood:good];
10943 NSUInteger export_legality = [localMarket exportLegalityForGood:good];
10944 NSString *legaldesc = nil;
10945 if (import_legality == 0)
10946 {
10947 if (export_legality == 0)
10948 {
10949 legaldesc = DESC(@"oolite-legality-clear");
10950 }
10951 else
10952 {
10953 legaldesc = DESC(@"oolite-legality-import");
10954 }
10955 }
10956 else
10957 {
10958 if (export_legality == 0)
10959 {
10960 legaldesc = DESC(@"oolite-legality-export");
10961 }
10962 else
10963 {
10964 legaldesc = DESC(@"oolite-legality-neither");
10965 }
10966 }
10967 legaldesc = [NSString stringWithFormat:@" %@ ",legaldesc];
10968
10969 NSString *extradesc = [shipCommodityData shortCommentForGood:good];
10970
10971 [gui setKey:good forRow:row];
10972 [gui setColor:[gui colorFromSetting:kGuiMarketCommodityColor defaultValue:nil] forRow:row];
10973 [gui setArray:[NSArray arrayWithObjects: desc, extradesc, price, units_available, units_owned, legaldesc, nil] forRow:row++];
10974
10975}
NSInteger OOGUIRow
NSString * DisplayStringForMassUnit(OOMassUnit unit)
NSString * OOPadStringToEms(NSString *string, float numEms)
NSString * OOCommodityType
Definition OOTypes.h:106
OOMassUnit
Definition OOTypes.h:123
#define DESC(key)
Definition Universe.h:839
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)

◆ showMarketScreenHeaders

- (void) showMarketScreenHeaders

Extends class PlayerEntity.

Definition at line 9211 of file PlayerEntity.m.

10900{
10901 GuiDisplayGen *gui = [UNIVERSE gui];
10902 OOGUITabSettings tab_stops;
10903 tab_stops[0] = 0;
10904 tab_stops[1] = 137;
10905 tab_stops[2] = 187;
10906 tab_stops[3] = 267;
10907 tab_stops[4] = 321;
10908 tab_stops[5] = 431;
10909 [gui overrideTabs:tab_stops from:kGuiMarketTabs length:6];
10910 [gui setTabStops:tab_stops];
10911
10912 [gui setColor:[gui colorFromSetting:kGuiMarketHeadingColor defaultValue:[OOColor greenColor]] forRow:GUI_ROW_MARKET_KEY];
10913 [gui setArray:[NSArray arrayWithObjects: DESC(@"commodity-column-title"), OOPadStringToEms(DESC(@"price-column-title"),3.5),
10914 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] forRow:GUI_ROW_MARKET_KEY];
10915 [gui setArray:[NSArray arrayWithObjects: DESC(@"commodity-column-title"), DESC(@"oolite-extras-column-title"), OOPadStringToEms(DESC(@"price-column-title"),3.5),
10916 OOPadStringToEms(DESC(@"for-sale-column-title"),3.75), OOPadStringToEms(DESC(@"in-hold-column-title"),5.75), DESC(@"oolite-legality-column-title"), nil] forRow:GUI_ROW_MARKET_KEY];
10917
10918}
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:274

◆ tryBuyingItem:

- (BOOL) tryBuyingItem: (NSString *) eqKey

Extends class PlayerEntity.

Definition at line 9211 of file PlayerEntity.m.

10305 :(NSString *)eqKey
10306{
10307 // note this doesn't check the availability by tech-level
10309 OOCreditsQuantity pricePerUnit = [eqType price];
10310 NSString *eqKeyDamaged = [eqType damagedIdentifier];
10311 double price = pricePerUnit;
10312 double priceFactor = 1.0;
10313 OOCreditsQuantity tradeIn = 0;
10314 BOOL isRepair = NO;
10315
10316 // repairs cost 50%
10317 if ([self hasEquipmentItem:eqKeyDamaged])
10318 {
10319 price /= 2.0;
10320 isRepair = YES;
10321 }
10322
10323 if ([eqKey isEqualToString:@"EQ_RENOVATION"])
10324 {
10325 price = [self renovationCosts];
10326 }
10327
10328 price = [self adjustPriceByScriptForEqKey:eqKey withCurrent:price];
10329
10330 StationEntity *dockedStation = [self dockedStation];
10331 if (dockedStation)
10332 {
10333 priceFactor = [dockedStation equipmentPriceFactor];
10334 }
10335
10336 price *= priceFactor; // increased prices at some stations
10337
10338 if (price > credits)
10339 {
10340 return NO;
10341 }
10342
10343 if ([eqType isPrimaryWeapon])
10344 {
10345 if (chosen_weapon_facing == WEAPON_FACING_NONE)
10346 {
10347 [self setGuiToEquipShipScreen:0 selectingFacingFor:eqKey]; // reset
10348 return YES;
10349 }
10350
10352 OOWeaponType current_weapon = nil;
10353
10354 NSUInteger multiplier = 1;
10355
10356 switch (chosen_weapon_facing)
10357 {
10359 current_weapon = forward_weapon_type;
10360 forward_weapon_type = chosen_weapon;
10361 if (_multiplyWeapons)
10362 {
10363 multiplier = [forwardWeaponOffset count];
10364 }
10365 break;
10366
10367 case WEAPON_FACING_AFT:
10368 current_weapon = aft_weapon_type;
10369 aft_weapon_type = chosen_weapon;
10370 if (_multiplyWeapons)
10371 {
10372 multiplier = [aftWeaponOffset count];
10373 }
10374 break;
10375
10376 case WEAPON_FACING_PORT:
10377 current_weapon = port_weapon_type;
10378 port_weapon_type = chosen_weapon;
10379 if (_multiplyWeapons)
10380 {
10381 multiplier = [portWeaponOffset count];
10382 }
10383 break;
10384
10386 current_weapon = starboard_weapon_type;
10387 starboard_weapon_type = chosen_weapon;
10388 if (_multiplyWeapons)
10389 {
10390 multiplier = [starboardWeaponOffset count];
10391 }
10392 break;
10393
10394 case WEAPON_FACING_NONE:
10395 break;
10396 }
10397
10398 price *= multiplier;
10399
10400 if (price > credits)
10401 {
10402 // not enough money - ensure that weapon
10403 // type is reset to what it was before
10404 // the attempt to buy took place
10405 switch (chosen_weapon_facing)
10406 {
10408 forward_weapon_type = current_weapon;
10409 break;
10410 case WEAPON_FACING_AFT:
10411 aft_weapon_type = current_weapon;
10412 break;
10413 case WEAPON_FACING_PORT:
10414 port_weapon_type = current_weapon;
10415 break;
10417 starboard_weapon_type = current_weapon;
10418 break;
10419 case WEAPON_FACING_NONE:
10420 break;
10421 }
10422 return NO;
10423 }
10424 credits -= price;
10425
10426 // Refund current_weapon
10427 if (current_weapon != nil)
10428 {
10429 tradeIn = [UNIVERSE getEquipmentPriceForKey:OOEquipmentIdentifierFromWeaponType(current_weapon)] * multiplier;
10430 }
10431
10432 [self doTradeIn:tradeIn forPriceFactor:priceFactor];
10433 // If equipped, remove damaged weapon after repairs. -- But there's no way we should get a damaged weapon. Ever.
10434 [self removeEquipmentItem:eqKeyDamaged];
10435 return YES;
10436 }
10437
10438 if ([eqType isMissileOrMine] && missiles >= max_missiles)
10439 {
10440 OOLog(@"equip.buy.mounted.failed.full", @"%@", @"rejecting missile because already full");
10441 return NO;
10442 }
10443
10444 // NSFO!
10445 //unsigned passenger_space = [[OOEquipmentType equipmentTypeWithIdentifier:@"EQ_PASSENGER_BERTH"] requiredCargoSpace];
10446 //if (passenger_space == 0) passenger_space = PASSENGER_BERTH_SPACE;
10447
10448 if ([eqKey isEqualToString:@"EQ_PASSENGER_BERTH"] && [self availableCargoSpace] < PASSENGER_BERTH_SPACE)
10449 {
10450 return NO;
10451 }
10452
10453 if ([eqKey isEqualToString:@"EQ_FUEL"])
10454 {
10455#if MASS_DEPENDENT_FUEL_PRICES
10456 OOCreditsQuantity creditsForRefuel = ([self fuelCapacity] - [self fuel]) * pricePerUnit * [self fuelChargeRate];
10457#else
10458 OOCreditsQuantity creditsForRefuel = ([self fuelCapacity] - [self fuel]) * pricePerUnit;
10459#endif
10460 if (credits >= creditsForRefuel) // Ensure we don't overflow
10461 {
10462 credits -= creditsForRefuel;
10463 fuel = [self fuelCapacity];
10464 return YES;
10465 }
10466 else
10467 {
10468 return NO;
10469 }
10470 }
10471
10472 // check energy unit replacement
10473 if ([eqKey hasSuffix:@"ENERGY_UNIT"] && [self energyUnitType] != ENERGY_UNIT_NONE)
10474 {
10475 switch ([self energyUnitType])
10476 {
10477 case ENERGY_UNIT_NAVAL :
10478 [self removeEquipmentItem:@"EQ_NAVAL_ENERGY_UNIT"];
10479 tradeIn = [UNIVERSE getEquipmentPriceForKey:@"EQ_NAVAL_ENERGY_UNIT"] / 2; // 50 % refund
10480 break;
10482 [self removeEquipmentItem:@"EQ_NAVAL_ENERGY_UNIT_DAMAGED"];
10483 tradeIn = [UNIVERSE getEquipmentPriceForKey:@"EQ_NAVAL_ENERGY_UNIT"] / 4; // half of the working one
10484 break;
10485 case ENERGY_UNIT_NORMAL :
10486 [self removeEquipmentItem:@"EQ_ENERGY_UNIT"];
10487 tradeIn = [UNIVERSE getEquipmentPriceForKey:@"EQ_ENERGY_UNIT"] * 3 / 4; // 75 % refund
10488 break;
10490 [self removeEquipmentItem:@"EQ_ENERGY_UNIT_DAMAGED"];
10491 tradeIn = [UNIVERSE getEquipmentPriceForKey:@"EQ_ENERGY_UNIT"] * 3 / 8; // half of the working one
10492 break;
10493
10494 default:
10495 break;
10496 }
10497 [self doTradeIn:tradeIn forPriceFactor:priceFactor];
10498 }
10499
10500 // maintain ship
10501 if ([eqKey isEqualToString:@"EQ_RENOVATION"])
10502 {
10503 OOTechLevelID techLevel = NSNotFound;
10504 if (dockedStation != nil) techLevel = [dockedStation equivalentTechLevel];
10505 if (techLevel == NSNotFound) techLevel = [[UNIVERSE currentSystemData] oo_unsignedIntForKey:KEY_TECHLEVEL];
10506
10507 credits -= price;
10508 ship_trade_in_factor += 5 + techLevel; // you get better value at high-tech repair bases
10509 if (ship_trade_in_factor > 100) ship_trade_in_factor = 100;
10510
10511 [self clearSubEntities];
10512 [self setUpSubEntities];
10513
10514 return YES;
10515 }
10516
10517 if ([eqKey hasSuffix:@"MISSILE"] || [eqKey hasSuffix:@"MINE"])
10518 {
10519 ShipEntity* weapon = [[UNIVERSE newShipWithRole:eqKey] autorelease];
10520 if (weapon) OOLog(kOOLogBuyMountedOK, @"Got ship for mounted weapon role %@", eqKey);
10521 else OOLog(kOOLogBuyMountedFailed, @"Could not find ship for mounted weapon role %@", eqKey);
10522
10523 BOOL mounted_okay = [self mountMissile:weapon];
10524 if (mounted_okay)
10525 {
10526 credits -= price;
10527 [self safeAllMissiles];
10528 [self tidyMissilePylons];
10529 [self setActiveMissile:0];
10530 }
10531 return mounted_okay;
10532 }
10533
10534 if ([eqKey isEqualToString:@"EQ_PASSENGER_BERTH"])
10535 {
10536 [self changePassengerBerths:+1];
10537 credits -= price;
10538 return YES;
10539 }
10540
10541 if ([eqKey isEqualToString:@"EQ_PASSENGER_BERTH_REMOVAL"])
10542 {
10543 [self changePassengerBerths:-1];
10544 credits -= price;
10545 return YES;
10546 }
10547
10548 if ([eqKey isEqualToString:@"EQ_MISSILE_REMOVAL"])
10549 {
10550 credits -= price;
10551 tradeIn += [self removeMissiles];
10552 [self doTradeIn:tradeIn forPriceFactor:priceFactor];
10553 return YES;
10554 }
10555
10556 if ([self canAddEquipment:eqKey inContext:@"purchase"])
10557 {
10558 credits -= price;
10559 [self addEquipmentItem:eqKey withValidation:NO inContext:@"purchase"]; // no need to validate twice.
10560 if (isRepair)
10561 {
10562 [self doScriptEvent:OOJSID("equipmentRepaired") withArgument:eqKey];
10563 }
10564 return YES;
10565 }
10566
10567 return NO;
10568}
#define OOLog(class, format,...)
Definition OOLogging.h:88
return self
NSUInteger OOTechLevelID
Definition OOTypes.h:204
@ WEAPON_FACING_FORWARD
Definition OOTypes.h:229
@ WEAPON_FACING_NONE
Definition OOTypes.h:234
@ WEAPON_FACING_AFT
Definition OOTypes.h:230
@ WEAPON_FACING_PORT
Definition OOTypes.h:231
@ WEAPON_FACING_STARBOARD
Definition OOTypes.h:232
@ ENERGY_UNIT_NORMAL
Definition OOTypes.h:137
@ ENERGY_UNIT_NAVAL_DAMAGED
Definition OOTypes.h:134
@ ENERGY_UNIT_NAVAL
Definition OOTypes.h:138
@ ENERGY_UNIT_NONE
Definition OOTypes.h:132
@ ENERGY_UNIT_NORMAL_DAMAGED
Definition OOTypes.h:133
static NSString *const kOOLogBuyMountedOK
static NSString *const kOOLogBuyMountedFailed
OOWeaponType OOWeaponTypeFromEquipmentIdentifierStrict(NSString *string) PURE_FUNC
#define PASSENGER_BERTH_SPACE
Definition Universe.h:151
NSString * damagedIdentifier()
OOEquipmentType * equipmentTypeWithIdentifier:(NSString *identifier)
OOCreditsQuantity price()
OOTechLevelID equivalentTechLevel
float equipmentPriceFactor

◆ updateAlertCondition

- (void) updateAlertCondition

Extends class PlayerEntity.

Definition at line 13699 of file PlayerEntity.m.

3399{
3400 [self updateAlertConditionForNearbyEntities];
3401 /* TODO: update alert condition once per frame. Tried this before, but
3402 there turned out to be complications. See mailing list archive.
3403 -- Ahruman 20070802
3404 */
3405 OOAlertCondition cond = [self alertCondition];
3406 OOTimeAbsolute t = [UNIVERSE getTime];
3407 if (cond != lastScriptAlertCondition)
3408 {
3409 ShipScriptEventNoCx(self, "alertConditionChanged", INT_TO_JSVAL(cond), INT_TO_JSVAL(lastScriptAlertCondition));
3410 lastScriptAlertCondition = cond;
3411 }
3412 /* Update heuristic assessment of whether player is fleeing */
3413 if (cond == ALERT_CONDITION_DOCKED || cond == ALERT_CONDITION_GREEN || (cond == ALERT_CONDITION_YELLOW && energy == maxEnergy))
3414 {
3415 fleeing_status = PLAYER_FLEEING_NONE;
3416 }
3417 else if (fleeing_status == PLAYER_FLEEING_UNLIKELY && (energy > maxEnergy*0.6 || cond != ALERT_CONDITION_RED))
3418 {
3419 fleeing_status = PLAYER_FLEEING_NONE;
3420 }
3421 else if ((fleeing_status == PLAYER_FLEEING_MAYBE || fleeing_status == PLAYER_FLEEING_UNLIKELY) && cargo_dump_time > last_shot_time)
3422 {
3423 fleeing_status = PLAYER_FLEEING_CARGO;
3424 }
3425 else if (fleeing_status == PLAYER_FLEEING_MAYBE && last_shot_time + 10 > t)
3426 {
3427 fleeing_status = PLAYER_FLEEING_NONE;
3428 }
3429 else if (fleeing_status == PLAYER_FLEEING_LIKELY && last_shot_time + 10 > t)
3430 {
3431 fleeing_status = PLAYER_FLEEING_UNLIKELY;
3432 }
3433 else if (fleeing_status == PLAYER_FLEEING_NONE && cond == ALERT_CONDITION_RED && last_shot_time + 10 < t && flightSpeed > 0.75*maxFlightSpeed)
3434 {
3435 fleeing_status = PLAYER_FLEEING_MAYBE;
3436 }
3437 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))
3438 {
3439 fleeing_status = PLAYER_FLEEING_LIKELY;
3440 }
3441}
double OOTimeAbsolute
Definition OOTypes.h:223
@ PLAYER_FLEEING_MAYBE
@ PLAYER_FLEEING_LIKELY
@ PLAYER_FLEEING_NONE
@ PLAYER_FLEEING_CARGO
@ PLAYER_FLEEING_UNLIKELY
OOAlertCondition
Definition ShipEntity.h:172
@ ALERT_CONDITION_GREEN
Definition ShipEntity.h:176
@ ALERT_CONDITION_RED
Definition ShipEntity.h:178
@ ALERT_CONDITION_YELLOW
Definition ShipEntity.h:177
@ ALERT_CONDITION_DOCKED
Definition ShipEntity.h:175

◆ updateAlertConditionForNearbyEntities

- (void) updateAlertConditionForNearbyEntities

Extends class PlayerEntity.

Definition at line 13699 of file PlayerEntity.m.

3188{
3189 if (![self isInSpace] || [self status] == STATUS_DOCKING)
3190 {
3191 [self clearAlertFlags];
3192 // not needed while docked
3193 return;
3194 }
3195
3196 int i, ent_count = UNIVERSE->n_entities;
3197 Entity **uni_entities = UNIVERSE->sortedEntities; // grab the public sorted list
3198 Entity *my_entities[ent_count];
3199 Entity *scannedEntity = nil;
3200 for (i = 0; i < ent_count; i++)
3201 {
3202 my_entities[i] = [uni_entities[i] retain]; // retained
3203 }
3204 BOOL massLocked = NO;
3205 BOOL foundHostiles = NO;
3206#if OO_VARIABLE_TORUS_SPEED
3207 BOOL needHyperspeedNearest = YES;
3208 double hsnDistance = 0;
3209#endif
3210 for (i = 0; i < ent_count; i++) // scanner lollypops
3211 {
3212 scannedEntity = my_entities[i];
3213
3214#if OO_VARIABLE_TORUS_SPEED
3215 if (EXPECT_NOT(needHyperspeedNearest))
3216 {
3217 // not visual effects, waypoints, ships, etc.
3218 if (scannedEntity != self && [scannedEntity canCollide] && (![scannedEntity isShip] || ![self collisionExceptedFor:(ShipEntity *) scannedEntity]))
3219 {
3220 hsnDistance = sqrt(scannedEntity->zero_distance)-[scannedEntity collisionRadius];
3221 needHyperspeedNearest = NO;
3222 }
3223 }
3224 else if ([scannedEntity isStellarObject])
3225 {
3226 // planets, stars might be closest surface even if not
3227 // closest centre. That could be true of others, but the
3228 // error is negligible there.
3229 double thisHSN = sqrt(scannedEntity->zero_distance)-[scannedEntity collisionRadius];
3230 if (thisHSN < hsnDistance)
3231 {
3232 hsnDistance = thisHSN;
3233 }
3234 }
3235#endif
3236
3237 if (scannedEntity->zero_distance < SCANNER_MAX_RANGE2 || !scannedEntity->isShip)
3238 {
3239 int theirClass = [scannedEntity scanClass];
3240 // here we could also force masslock for higher than yellow alert, but
3241 // if we are going to hand over masslock control to scripting, might as well
3242 // hand it over fully
3243 if ([self massLockable] /*|| alertFlags > ALERT_FLAG_YELLOW_LIMIT*/)
3244 {
3245 massLocked |= [self checkEntityForMassLock:scannedEntity withScanClass:theirClass]; // we just need one masslocker..
3246 }
3247 if (theirClass != CLASS_NO_DRAW)
3248 {
3249 if (theirClass == CLASS_THARGOID || [scannedEntity isCascadeWeapon])
3250 {
3251 foundHostiles = YES;
3252 }
3253 else if ([scannedEntity isShip])
3254 {
3255 ShipEntity *ship = (ShipEntity *)scannedEntity;
3256 foundHostiles |= (([ship hasHostileTarget])&&([ship primaryTarget] == self));
3257 }
3258 }
3259 }
3260 }
3261#if OO_VARIABLE_TORUS_SPEED
3262 if (EXPECT_NOT(needHyperspeedNearest))
3263 {
3264 // this case should only occur in an otherwise empty
3265 // interstellar space - unlikely but possible
3266 hyperspeedFactor = MIN_HYPERSPEED_FACTOR;
3267 }
3268 else
3269 {
3270 // once nearest object is >4x scanner range
3271 // start increasing torus speed
3272 double factor = hsnDistance/(4*SCANNER_MAX_RANGE);
3273 if (factor < 1.0)
3274 {
3275 hyperspeedFactor = MIN_HYPERSPEED_FACTOR;
3276 }
3277 else
3278 {
3279 hyperspeedFactor = MIN_HYPERSPEED_FACTOR * sqrt(factor);
3280 if (hyperspeedFactor > MAX_HYPERSPEED_FACTOR)
3281 {
3282 // caps out at ~10^8m from nearest object
3283 // which takes ~10 minutes of flying
3284 hyperspeedFactor = MAX_HYPERSPEED_FACTOR;
3285 }
3286 }
3287 }
3288#endif
3289
3290 [self setAlertFlag:ALERT_FLAG_MASS_LOCK to:massLocked];
3291
3292 [self setAlertFlag:ALERT_FLAG_HOSTILES to:foundHostiles];
3293
3294 for (i = 0; i < ent_count; i++)
3295 {
3296 [my_entities[i] release]; // released
3297 }
3298
3299 BOOL energyCritical = NO;
3300 if (energy < 64 && energy < maxEnergy * 0.8)
3301 {
3302 energyCritical = YES;
3303 }
3304 [self setAlertFlag:ALERT_FLAG_ENERGY to:energyCritical];
3305
3306 [self setAlertFlag:ALERT_FLAG_TEMP to:([self hullHeatLevel] > .90)];
3307
3308 [self setAlertFlag:ALERT_FLAG_ALT to:([self dialAltitude] < .10)];
3309
3310}
#define SCANNER_MAX_RANGE
Definition Entity.h:51
#define MAX_HYPERSPEED_FACTOR
#define MIN_HYPERSPEED_FACTOR
BOOL hasHostileTarget()

◆ updateClocks:

- (void) updateClocks: (OOTimeDelta) delta_t

Extends class PlayerEntity.

Definition at line 13699 of file PlayerEntity.m.

3458 :(OOTimeDelta)delta_t
3459{
3460 // shot time updates are still needed here for STATUS_DEAD!
3461 shot_time += delta_t;
3462 script_time += delta_t;
3463 unsigned prev_day = floor(ship_clock / 86400);
3464 ship_clock += delta_t;
3465 if (ship_clock_adjust > 0.0) // adjust for coming out of warp (add LY * LY hrs)
3466 {
3467 double fine_adjust = delta_t * 7200.0;
3468 if (ship_clock_adjust > 86400) // more than a day
3469 fine_adjust = delta_t * 115200.0; // 16 times faster
3470 if (ship_clock_adjust > 0)
3471 {
3472 if (fine_adjust > ship_clock_adjust)
3473 fine_adjust = ship_clock_adjust;
3474 ship_clock += fine_adjust;
3475 ship_clock_adjust -= fine_adjust;
3476 }
3477 else
3478 {
3479 if (fine_adjust < ship_clock_adjust)
3480 fine_adjust = ship_clock_adjust;
3481 ship_clock -= fine_adjust;
3482 ship_clock_adjust += fine_adjust;
3483 }
3484 }
3485 else
3486 ship_clock_adjust = 0.0;
3487
3488 unsigned now_day = floor(ship_clock / 86400.0);
3489 while (prev_day < now_day)
3490 {
3491 prev_day++;
3492 [self doScriptEvent:OOJSID("dayChanged") withArgument:[NSNumber numberWithUnsignedInt:prev_day]];
3493 // not impossible that at ultra-low frame rates two of these will
3494 // happen in a single update.
3495 }
3496
3497 //fps
3498 if (ship_clock > fps_check_time)
3499 {
3500 if (![self clockAdjusting])
3501 {
3502 fps_counter = (int)([UNIVERSE timeAccelerationFactor] * floor([UNIVERSE framesDoneThisUpdate] / (fps_check_time - last_fps_check_time)));
3503 last_fps_check_time = fps_check_time;
3504 fps_check_time = ship_clock + MINIMUM_GAME_TICK;
3505 }
3506 else
3507 {
3508 // Good approximation for when the clock is adjusting and proper fps calculation
3509 // cannot be performed.
3510 fps_counter = (int)([UNIVERSE timeAccelerationFactor] * floor(1.0 / delta_t));
3511 fps_check_time = ship_clock + MINIMUM_GAME_TICK;
3512 }
3513 [UNIVERSE resetFramesDoneThisUpdate]; // Reset frame counter
3514 }
3515}
#define MINIMUM_GAME_TICK

◆ updateFuelScoops:

- (void) updateFuelScoops: (OOTimeDelta) delta_t

Extends class PlayerEntity.

Definition at line 13699 of file PlayerEntity.m.

3444 :(OOTimeDelta)delta_t
3445{
3446 if (scoopsActive)
3447 {
3448 [self updateFuelScoopSoundWithInterval:delta_t];
3449 if (![self scoopOverride])
3450 {
3451 scoopsActive = NO;
3452 [self updateFuelScoopSoundWithInterval:delta_t];
3453 }
3454 }
3455}

◆ updateMovementFlags

- (void) updateMovementFlags

Extends class PlayerEntity.

Definition at line 13699 of file PlayerEntity.m.

3179{
3180 hasMoved = !HPvector_equal(position, lastPosition);
3181 hasRotated = !quaternion_equal(orientation, lastOrientation);
3182 lastPosition = position;
3183 lastOrientation = orientation;
3184}

◆ updateTargeting

- (void) updateTargeting

Extends class PlayerEntity.

Definition at line 13699 of file PlayerEntity.m.

4112{
4114
4115 // check for lost ident target and ensure the ident system is actually scanning
4116 UPDATE_STAGE(@"checking ident target");
4117 if (ident_engaged && [self primaryTarget] != nil)
4118 {
4119 if (![self isValidTarget:[self primaryTarget]])
4120 {
4121 if (!suppressTargetLost)
4122 {
4123 [UNIVERSE addMessage:DESC(@"target-lost") forCount:3.0];
4124 [self playTargetLost];
4125 [self noteLostTarget];
4126 }
4127 else
4128 {
4129 suppressTargetLost = NO;
4130 }
4131
4132 DESTROY(_primaryTarget);
4133 }
4134 }
4135
4136 // check each unlaunched missile's target still exists and is in-range
4137 UPDATE_STAGE(@"checking missile targets");
4138 if (missile_status != MISSILE_STATUS_SAFE)
4139 {
4140 unsigned i;
4141 for (i = 0; i < max_missiles; i++)
4142 {
4143 if ([missile_entity[i] primaryTarget] != nil &&
4144 ![self isValidTarget:[missile_entity[i] primaryTarget]])
4145 {
4146 [UNIVERSE addMessage:DESC(@"target-lost") forCount:3.0];
4147 [self playTargetLost];
4148 [missile_entity[i] removeTarget:nil];
4149 if (i == activeMissile)
4150 {
4151 [self noteLostTarget];
4152 DESTROY(_primaryTarget);
4153 missile_status = MISSILE_STATUS_ARMED;
4154 }
4155 } else if (i == activeMissile && [missile_entity[i] primaryTarget] == nil) {
4156 missile_status = MISSILE_STATUS_ARMED;
4157 }
4158 }
4159 }
4160
4161 // if we don't have a primary target, and we're scanning, then check for a new
4162 // target to lock on to
4163 UPDATE_STAGE(@"looking for new target");
4164 if ([self primaryTarget] == nil &&
4165 (ident_engaged || missile_status != MISSILE_STATUS_SAFE) &&
4166 ([self status] == STATUS_IN_FLIGHT || [self status] == STATUS_WITCHSPACE_COUNTDOWN))
4167 {
4168 Entity *target = [UNIVERSE firstEntityTargetedByPlayer];
4169 if ([self isValidTarget:target])
4170 {
4171 [self addTarget:target];
4172 }
4173 }
4174
4175 // If our primary target is a wormhole, check to see if we have additional
4176 // information
4177 UPDATE_STAGE(@"checking for additional wormhole information");
4178 if ([[self primaryTarget] isWormhole])
4179 {
4180 WormholeEntity *wh = [self primaryTarget];
4181 switch ([wh scanInfo])
4182 {
4183 case WH_SCANINFO_NONE:
4184 OOLog(kOOLogInconsistentState, @"%@", @"Internal Error - WH_SCANINFO_NONE reached in [PlayerEntity updateTargeting:]");
4185 [self dumpState];
4186 [wh dumpState];
4187 // Workaround a reported hit of the assert here. We really
4188 // should work out how/why this could happen though and fix
4189 // the underlying cause.
4190 // - MKW 2011.03.11
4191 //assert([wh scanInfo] != WH_SCANINFO_NONE);
4192 [wh setScannedAt:[self clockTimeAdjusted]];
4193 break;
4195 if ([self clockTimeAdjusted] > [wh scanTime] + 2)
4196 {
4197 [wh setScanInfo:WH_SCANINFO_COLLAPSE_TIME];
4198 //[UNIVERSE addCommsMessage:[NSString stringWithFormat:DESC(@"wormhole-collapse-time-computed"),
4199 // [UNIVERSE getSystemName:[wh destination]]] forCount:5.0];
4200 }
4201 break;
4203 if([self clockTimeAdjusted] > [wh scanTime] + 4)
4204 {
4205 [wh setScanInfo:WH_SCANINFO_ARRIVAL_TIME];
4206 [UNIVERSE addCommsMessage:[NSString stringWithFormat:DESC(@"wormhole-arrival-time-computed-@"),
4207 ClockToString([wh estimatedArrivalTime], NO)] forCount:5.0];
4208 }
4209 break;
4211 if ([self clockTimeAdjusted] > [wh scanTime] + 7)
4212 {
4213 [wh setScanInfo:WH_SCANINFO_DESTINATION];
4214 [UNIVERSE addCommsMessage:[NSString stringWithFormat:DESC(@"wormhole-destination-computed-@"),
4215 [UNIVERSE getSystemName:[wh destination]]] forCount:5.0];
4216 }
4217 break;
4219 if ([self clockTimeAdjusted] > [wh scanTime] + 10)
4220 {
4221 [wh setScanInfo:WH_SCANINFO_SHIP];
4222 // TODO: Extract last ship from wormhole and display its name
4223 }
4224 break;
4225 case WH_SCANINFO_SHIP:
4226 break;
4227 }
4228 }
4229
4231}
#define DESTROY(x)
Definition OOCocoa.h:77
NSString *const kOOLogInconsistentState
Definition OOLogging.m:650
@ 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:996
double estimatedArrivalTime()
OOSystemID destination
void setScannedAt:(double time)
void setScanInfo:(WORMHOLE_SCANINFO scanInfo)

◆ updateTrumbles:

- (void) updateTrumbles: (OOTimeDelta) delta_t

Extends class PlayerEntity.

Definition at line 13699 of file PlayerEntity.m.

3571 :(OOTimeDelta)delta_t
3572{
3573 OOTrumble **trumbles = [self trumbleArray];
3574 NSUInteger i;
3575
3576 for (i = [self trumbleCount] ; i > 0; i--)
3577 {
3578 OOTrumble* trum = trumbles[i - 1];
3579 [trum updateTrumble:delta_t];
3580 }
3581}
void updateTrumble:(double delta_t)
Definition OOTrumble.m:494

◆ updateWormholes

- (void) updateWormholes

Extends class PlayerEntity.

Definition at line 9211 of file PlayerEntity.m.

13205{
13206 assert(scannedWormholes != nil);
13207
13208 if ([scannedWormholes count] == 0)
13209 return;
13210
13211 double now = [self clockTimeAdjusted];
13212
13213 NSMutableArray * savedWormholes = [[NSMutableArray alloc] initWithCapacity:[scannedWormholes count]];
13214 NSEnumerator * wormholes = [scannedWormholes objectEnumerator];
13215 WormholeEntity *wh;
13216
13217 while ((wh = (WormholeEntity*)[wormholes nextObject]))
13218 {
13219 // TODO: Start drawing wormhole exit a few seconds before the first
13220 // ship is disgorged.
13221 if ([wh arrivalTime] > now)
13222 {
13223 [savedWormholes addObject:wh];
13224 }
13225 else if (NSEqualPoints(galaxy_coordinates, [wh destinationCoordinates]))
13226 {
13227 [wh disgorgeShips];
13228 if ([[wh shipsInTransit] count] > 0)
13229 {
13230 [savedWormholes addObject:wh];
13231 }
13232 }
13233 // Else wormhole has expired in another system, let it expire
13234 }
13235
13236 [scannedWormholes release];
13237 scannedWormholes = savedWormholes;
13238}
unsigned count

◆ witchEnd

- (void) witchEnd

Extends class PlayerEntity.

Definition at line 13699 of file PlayerEntity.m.

7355{
7356 [UNIVERSE setSystemTo:system_id];
7357 galaxy_coordinates = [[UNIVERSE systemManager] getCoordinatesForSystem:system_id inGalaxy:galaxy_number];
7358
7359 [UNIVERSE setUpUniverseFromWitchspace];
7360 [[UNIVERSE planet] update: 2.34375 * market_rnd]; // from 0..10 minutes
7361 [[UNIVERSE station] update: 2.34375 * market_rnd]; // from 0..10 minutes
7362
7363 chart_centre_coordinates = galaxy_coordinates;
7364 target_chart_centre = chart_centre_coordinates;
7365}

◆ witchJumpTo:misjump:

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

Extends class PlayerEntity.

Definition at line 13699 of file PlayerEntity.m.

7736 :(OOSystemID)sTo misjump:(BOOL)misjump
7737{
7738 [self witchStart];
7739 if (info_system_id == system_id)
7740 {
7741 [self setInfoSystemID: sTo moveChart: YES];
7742 }
7743 //wear and tear on all jumps (inc misjumps, failures, and wormholes)
7744 if (2 * market_rnd < ship_trade_in_factor)
7745 {
7746 // every eight jumps or so drop the price down towards 75%
7747 [self adjustTradeInFactorBy:-(1 + (market_rnd & 3))];
7748 }
7749
7750 // set clock after "playerWillEnterWitchspace" and before removeAllEntitiesExceptPlayer, to allow escorts time to follow their mother.
7751 NSPoint destCoords = PointFromString([[UNIVERSE systemManager] getProperty:@"coordinates" forSystem:sTo inGalaxy:galaxy_number]);
7752 double distance = distanceBetweenPlanetPositions(destCoords.x,destCoords.y,galaxy_coordinates.x,galaxy_coordinates.y);
7753
7754 // if we just escaped a system gone nova, make sure all nova parameters are reset
7755 OOSunEntity *theSun = [UNIVERSE sun];
7756 if (theSun && [theSun goneNova])
7757 {
7758 [theSun resetNova];
7759 }
7760
7761 [UNIVERSE removeAllEntitiesExceptPlayer];
7762 if (!misjump)
7763 {
7764 ship_clock_adjust += distance * distance * 3600.0;
7765 [self setSystemID:sTo];
7766 [self setBounty:(legalStatus/2) withReason:kOOLegalStatusReasonNewSystem]; // 'another day, another system'
7767 [self witchEnd];
7768 if (market_rnd < 8) [self erodeReputation]; // every 32 systems or so, drop back towards 'unknown'
7769 }
7770 else
7771 {
7772 // Misjump: move halfway there!
7773 // misjumps do not change legal status.
7774 if (randf() < 0.1) [self erodeReputation]; // once every 10 misjumps - should be much rarer than successful jumps!
7775
7776 [wormhole setMisjump];
7777 // just in case, but this has usually been set already
7778
7779 // and now the wormhole has travel time and coordinates calculated
7780 // so rather than duplicate the calculation we'll just ask it...
7781 NSPoint dest = [wormhole destinationCoordinates];
7782 galaxy_coordinates.x = dest.x;
7783 galaxy_coordinates.y = dest.y;
7784
7785 ship_clock_adjust += [wormhole travelTime];
7786
7787 [self playWitchjumpMisjump];
7788 [UNIVERSE setUpUniverseFromMisjump];
7789 }
7790}
float randf(void)

◆ witchStart

- (void) witchStart

Extends class PlayerEntity.

Definition at line 13699 of file PlayerEntity.m.

7310{
7311 // chances of entering witchspace with autopilot on are very low, but as Berlios bug #18307 has shown us, entirely possible
7312 // so in such cases we need to ensure that at least the docking music stops playing
7313 if (autopilot_engaged) [self disengageAutopilot];
7314
7315 if (![hud nonlinearScanner])
7316 {
7317 [hud setScannerZoom: 1.0];
7318 }
7319 [self safeAllMissiles];
7320
7321 OOViewID previousViewDirection = [UNIVERSE viewDirection];
7322 [UNIVERSE setViewDirection:VIEW_FORWARD];
7323 [self noteSwitchToView:VIEW_FORWARD fromView:previousViewDirection]; // notifies scripts of the switch
7324
7325 currentWeaponFacing = WEAPON_FACING_FORWARD;
7326 [self currentWeaponStats];
7327
7328 [self transitionToAegisNone];
7329 suppressAegisMessages=YES;
7330 hyperspeed_engaged = NO;
7331
7332 if ([self primaryTarget] != nil)
7333 {
7334 [self noteLostTarget]; // losing target? Fire lost target event!
7335 DESTROY(_primaryTarget);
7336 }
7337
7338 scanner_zoom_rate = 0.0f;
7339 [UNIVERSE setDisplayText:NO];
7340
7341 if ( ![self wormhole] && !galactic_witchjump) // galactic hyperspace does not generate a wormhole
7342 {
7343 OOLog(kOOLogInconsistentState, @"%@", @"Internal Error : Player entering witchspace with no wormhole.");
7344 }
7345 [UNIVERSE allShipsDoScriptEvent:OOJSID("playerWillEnterWitchspace") andReactToAIMessage:@"PLAYER WITCHSPACE"];
7346
7347 // set the new market seed now!
7348 // reseeding the RNG should be completely unnecessary here
7349// ranrot_srand((uint32_t)[[NSDate date] timeIntervalSince1970]); // seed randomiser by time
7350 market_rnd = ranrot_rand() & 255; // random factor for market values is reset
7351}
OOViewID
Definition OOTypes.h:43
#define ranrot_rand()

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