Oolite 1.91.0.7644-241112-7f5034b
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 1378 of file PlayerEntityLoadSave.m.

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

1413{
1414 if ([object isKindOfClass:[NSNumber class]] && [object oo_isFloatingPointNumber])
1415 {
1416 return OODeciCreditsFromDouble([object doubleValue]);
1417 }
1418 else
1419 {
1420 return OOUnsignedLongLongFromObject(object, 0);
1421 }
1422}
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 1364 of file PlayerEntityLoadSave.m.

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

References ENTITY_PERSONALITY_INVALID, and ENTITY_PERSONALITY_MAX.