Oolite
Loading...
Searching...
No Matches
PlayerEntityLoadSave.m File Reference
+ Include dependency graph for PlayerEntityLoadSave.m:

Go to the source code of this file.

Classes

category  MyOpenGLView(OOLoadSaveExtensions)
 
category  PlayerEntity(OOLoadSavePrivate)
 

Macros

#define COMMAND_MODIFIER_KEY   "Ctrl"
 

Functions

static uint16_t PersonalityForCommanderDict (NSDictionary *dict)
 
OOCreditsQuantity OODeciCreditsFromDouble (double doubleDeciCredits)
 
OOCreditsQuantity OODeciCreditsFromObject (id object)
 

Macro Definition Documentation

◆ COMMAND_MODIFIER_KEY

#define COMMAND_MODIFIER_KEY   "Ctrl"

Definition at line 54 of file PlayerEntityLoadSave.m.

Function Documentation

◆ OODeciCreditsFromDouble()

OOCreditsQuantity OODeciCreditsFromDouble ( double  doubleDeciCredits)

Definition at line 1386 of file PlayerEntityLoadSave.m.

1387{
1388 /* Clamp value to 0..kOOMaxCredits.
1389 The important bit here is that kOOMaxCredits can't be represented
1390 exactly as a double, and casting it rounds it up; casting this value
1391 back to an OOCreditsQuantity truncates it. Comparing value directly to
1392 kOOMaxCredits promotes kOOMaxCredits to a double, giving us this
1393 problem.
1394 nextafter(kOOMaxCredits, -1) gives us the highest non-truncated
1395 credits value that's representable as a double (namely,
1396 18 446 744 073 709 549 568 decicredits, or 2047 less than kOOMaxCredits).
1397 -- Ahruman 2011-02-27
1398 */
1399 if (doubleDeciCredits > 0)
1400 {
1401 doubleDeciCredits = round(doubleDeciCredits);
1402 double threshold = nextafter(kOOMaxCredits, -1);
1403
1404 if (doubleDeciCredits <= threshold)
1405 {
1406 return doubleDeciCredits;
1407 }
1408 else
1409 {
1410 return kOOMaxCredits;
1411 }
1412 }
1413 else
1414 {
1415 return 0;
1416 }
1417}
#define kOOMaxCredits
Definition OOTypes.h:183

References kOOMaxCredits.

Referenced by PlayerEntity(LoadSave)::addScenarioModel:.

+ Here is the caller graph for this function:

◆ OODeciCreditsFromObject()

OOCreditsQuantity OODeciCreditsFromObject ( id  object)

Definition at line 1420 of file PlayerEntityLoadSave.m.

1421{
1422 if ([object isKindOfClass:[NSNumber class]] && [object oo_isFloatingPointNumber])
1423 {
1424 return OODeciCreditsFromDouble([object doubleValue]);
1425 }
1426 else
1427 {
1428 return OOUnsignedLongLongFromObject(object, 0);
1429 }
1430}
unsigned long long OOUnsignedLongLongFromObject(id object, unsigned long long defaultValue)
OOCreditsQuantity OODeciCreditsFromDouble(double doubleDeciCredits)

◆ PersonalityForCommanderDict()

static uint16_t PersonalityForCommanderDict ( NSDictionary *  dict)
static

Definition at line 1372 of file PlayerEntityLoadSave.m.

1373{
1374 uint16_t personality = [dict oo_unsignedShortForKey:@"entity_personality" defaultValue:ENTITY_PERSONALITY_INVALID];
1375
1376 if (personality == ENTITY_PERSONALITY_INVALID)
1377 {
1378 // For pre-1.74 saved games, generate a default personality based on some hashes.
1379 personality = [[dict oo_stringForKey:@"ship_desc"] oo_hash] * [[dict oo_stringForKey:@"player_name"] oo_hash];
1380 }
1381
1382 return personality & ENTITY_PERSONALITY_MAX;
1383}
#define ENTITY_PERSONALITY_INVALID
Definition ShipEntity.h:111
#define ENTITY_PERSONALITY_MAX
Definition ShipEntity.h:110

References ENTITY_PERSONALITY_INVALID, and ENTITY_PERSONALITY_MAX.