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 53 of file PlayerEntityLoadSave.m.

Function Documentation

◆ OODeciCreditsFromDouble()

OOCreditsQuantity OODeciCreditsFromDouble ( double doubleDeciCredits)

Definition at line 1151 of file PlayerEntityLoadSave.m.

1152{
1153 /* Clamp value to 0..kOOMaxCredits.
1154 The important bit here is that kOOMaxCredits can't be represented
1155 exactly as a double, and casting it rounds it up; casting this value
1156 back to an OOCreditsQuantity truncates it. Comparing value directly to
1157 kOOMaxCredits promotes kOOMaxCredits to a double, giving us this
1158 problem.
1159 nextafter(kOOMaxCredits, -1) gives us the highest non-truncated
1160 credits value that's representable as a double (namely,
1161 18 446 744 073 709 549 568 decicredits, or 2047 less than kOOMaxCredits).
1162 -- Ahruman 2011-02-27
1163 */
1164 if (doubleDeciCredits > 0) {
1165 doubleDeciCredits = round(doubleDeciCredits);
1166 double threshold = nextafter(kOOMaxCredits, -1);
1167
1168 if (doubleDeciCredits <= threshold) {
1169 return doubleDeciCredits;
1170 } else {
1171 return kOOMaxCredits;
1172 }
1173 } else {
1174 return 0;
1175 }
1176}
#define kOOMaxCredits
Definition OOTypes.h:161

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 1178 of file PlayerEntityLoadSave.m.

1179{
1180 if ([object isKindOfClass:[NSNumber class]] && [object oo_isFloatingPointNumber]) {
1181 return OODeciCreditsFromDouble([object doubleValue]);
1182 } else {
1183 return OOUnsignedLongLongFromObject(object, 0);
1184 }
1185}
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 1139 of file PlayerEntityLoadSave.m.

1140{
1141 uint16_t personality = [dict oo_unsignedShortForKey:@"entity_personality" defaultValue:ENTITY_PERSONALITY_INVALID];
1142
1143 if (personality == ENTITY_PERSONALITY_INVALID) {
1144 // For pre-1.74 saved games, generate a default personality based on some hashes.
1145 personality = [[dict oo_stringForKey:@"ship_desc"] oo_hash] * [[dict oo_stringForKey:@"player_name"] oo_hash];
1146 }
1147
1148 return personality & ENTITY_PERSONALITY_MAX;
1149}
#define ENTITY_PERSONALITY_INVALID
Definition ShipEntity.h:113
#define ENTITY_PERSONALITY_MAX
Definition ShipEntity.h:112

References ENTITY_PERSONALITY_INVALID, and ENTITY_PERSONALITY_MAX.

Referenced by PlayerEntity(OOLoadSavePrivate)::showCommanderShip:.

Here is the caller graph for this function: