Oolite 1.93.0.7767-260207-f2a8cb5
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 1379 of file PlayerEntityLoadSave.m.

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

References kOOMaxCredits.

Referenced by OODeciCreditsFromObject(), and PlayerEntity(ScriptMethods)::setCreditBalance:.

Here is the caller graph for this function:

◆ OODeciCreditsFromObject()

OOCreditsQuantity OODeciCreditsFromObject ( id object)

Definition at line 1413 of file PlayerEntityLoadSave.m.

1414{
1415 if ([object isKindOfClass:[NSNumber class]] && [object oo_isFloatingPointNumber])
1416 {
1417 return OODeciCreditsFromDouble([object doubleValue]);
1418 }
1419 else
1420 {
1421 return OOUnsignedLongLongFromObject(object, 0);
1422 }
1423}
unsigned long long OOUnsignedLongLongFromObject(id object, unsigned long long defaultValue)
OOCreditsQuantity OODeciCreditsFromDouble(double doubleDeciCredits)

References OODeciCreditsFromDouble(), and OOUnsignedLongLongFromObject().

Referenced by PlayerEntity::setCommanderDataFromDictionary:, and PlayerEntity(OOLoadSavePrivate)::showCommanderShip:.

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

◆ PersonalityForCommanderDict()

uint16_t PersonalityForCommanderDict ( NSDictionary * dict)
static

Definition at line 1365 of file PlayerEntityLoadSave.m.

1366{
1367 uint16_t personality = [dict oo_unsignedShortForKey:@"entity_personality" defaultValue:ENTITY_PERSONALITY_INVALID];
1368
1369 if (personality == ENTITY_PERSONALITY_INVALID)
1370 {
1371 // For pre-1.74 saved games, generate a default personality based on some hashes.
1372 personality = [[dict oo_stringForKey:@"ship_desc"] oo_hash] * [[dict oo_stringForKey:@"player_name"] oo_hash];
1373 }
1374
1375 return personality & ENTITY_PERSONALITY_MAX;
1376}
#define ENTITY_PERSONALITY_INVALID
Definition ShipEntity.h:111
#define ENTITY_PERSONALITY_MAX
Definition ShipEntity.h:110

References ENTITY_PERSONALITY_INVALID, and ENTITY_PERSONALITY_MAX.

Referenced by PlayerEntity(OOLoadSavePrivate)::showCommanderShip:.

Here is the caller graph for this function: