Oolite
Loading...
Searching...
No Matches
ShipEntityLoadRestore.m File Reference
import "ShipEntityLoadRestore.h"
import "Universe.h"
import "AI.h"
import "OOCollectionExtractors.h"
import "OOConstToString.h"
import "OOEquipmentType.h"
import "OORoleSet.h"
import "OOShipGroup.h"
import "OOShipRegistry.h"
import "ShipEntityAI.h"
Include dependency graph for ShipEntityLoadRestore.m:

Go to the source code of this file.

Classes

category  ShipEntity(LoadRestoreInternal)

Macros

#define KEY_SHIP_KEY   @"ship_key"
#define KEY_SHIPDATA_OVERRIDES   @"shipdata_overrides"
#define KEY_SHIPDATA_DELETES   @"shipdata_deletes"
#define KEY_PRIMARY_ROLE   @"primary_role"
#define KEY_POSITION   @"position"
#define KEY_ORIENTATION   @"orientation"
#define KEY_ROLES   @"roles"
#define KEY_FUEL   @"fuel"
#define KEY_BOUNTY   @"bounty"
#define KEY_ENERGY_LEVEL   @"energy_level"
#define KEY_EQUIPMENT   @"equipment"
#define KEY_MISSILES   @"missiles"
#define KEY_FORWARD_WEAPON   @"forward_weapon_type"
#define KEY_AFT_WEAPON   @"aft_weapon_type"
#define KEY_SCAN_CLASS   @"scan_class"
#define KEY_AI   @"AI"
#define KEY_GROUP_ID   @"group"
#define KEY_GROUP_NAME   @"group_name"
#define KEY_IS_GROUP_LEADER   @"is_group_leader"
#define KEY_ESCORT_GROUP_ID   @"escort_group"

Functions

static void StripIgnoredKeys (NSMutableDictionary *dict)
static NSUInteger GroupIDForGroup (OOShipGroup *group, NSMutableDictionary *context)
static OOShipGroup * GroupForGroupID (NSUInteger groupID, NSMutableDictionary *context)

Macro Definition Documentation

◆ KEY_AFT_WEAPON

#define KEY_AFT_WEAPON   @"aft_weapon_type"

Definition at line 51 of file ShipEntityLoadRestore.m.

◆ KEY_AI

#define KEY_AI   @"AI"

Definition at line 55 of file ShipEntityLoadRestore.m.

◆ KEY_BOUNTY

#define KEY_BOUNTY   @"bounty"

Definition at line 46 of file ShipEntityLoadRestore.m.

◆ KEY_ENERGY_LEVEL

#define KEY_ENERGY_LEVEL   @"energy_level"

Definition at line 47 of file ShipEntityLoadRestore.m.

◆ KEY_EQUIPMENT

#define KEY_EQUIPMENT   @"equipment"

◆ KEY_ESCORT_GROUP_ID

#define KEY_ESCORT_GROUP_ID   @"escort_group"

Definition at line 61 of file ShipEntityLoadRestore.m.

◆ KEY_FORWARD_WEAPON

#define KEY_FORWARD_WEAPON   @"forward_weapon_type"

Definition at line 50 of file ShipEntityLoadRestore.m.

◆ KEY_FUEL

#define KEY_FUEL   @"fuel"

Definition at line 45 of file ShipEntityLoadRestore.m.

◆ KEY_GROUP_ID

#define KEY_GROUP_ID   @"group"

Definition at line 58 of file ShipEntityLoadRestore.m.

◆ KEY_GROUP_NAME

#define KEY_GROUP_NAME   @"group_name"

Definition at line 59 of file ShipEntityLoadRestore.m.

◆ KEY_IS_GROUP_LEADER

#define KEY_IS_GROUP_LEADER   @"is_group_leader"

◆ KEY_MISSILES

#define KEY_MISSILES   @"missiles"

◆ KEY_ORIENTATION

#define KEY_ORIENTATION   @"orientation"

Definition at line 43 of file ShipEntityLoadRestore.m.

◆ KEY_POSITION

#define KEY_POSITION   @"position"

Definition at line 42 of file ShipEntityLoadRestore.m.

◆ KEY_PRIMARY_ROLE

#define KEY_PRIMARY_ROLE   @"primary_role"

Definition at line 41 of file ShipEntityLoadRestore.m.

◆ KEY_ROLES

#define KEY_ROLES   @"roles"

Definition at line 44 of file ShipEntityLoadRestore.m.

◆ KEY_SCAN_CLASS

#define KEY_SCAN_CLASS   @"scan_class"

Definition at line 52 of file ShipEntityLoadRestore.m.

◆ KEY_SHIP_KEY

#define KEY_SHIP_KEY   @"ship_key"

Definition at line 38 of file ShipEntityLoadRestore.m.

◆ KEY_SHIPDATA_DELETES

#define KEY_SHIPDATA_DELETES   @"shipdata_deletes"

Definition at line 40 of file ShipEntityLoadRestore.m.

◆ KEY_SHIPDATA_OVERRIDES

#define KEY_SHIPDATA_OVERRIDES   @"shipdata_overrides"

Definition at line 39 of file ShipEntityLoadRestore.m.

Function Documentation

◆ GroupForGroupID()

OOShipGroup * GroupForGroupID ( NSUInteger groupID,
NSMutableDictionary * context )
static

Definition at line 341 of file ShipEntityLoadRestore.m.

342{
343 NSNumber* key = [NSNumber numberWithUnsignedInteger:groupID];
344
345 NSMutableDictionary* groups = [context objectForKey:@"groupsByID"];
346 if (groups == nil) {
347 groups = [NSMutableDictionary dictionary];
348 [context setObject:groups forKey:@"groupsByID"];
349 }
350
351 OOShipGroup* group = [groups objectForKey:key];
352 if (group == nil) {
353 group = [[[OOShipGroup alloc] init] autorelease];
354 [groups setObject:group forKey:key];
355 }
356
357 return group;
358}
return nil

References nil.

Referenced by ShipEntity(LoadRestore)::shipRestoredFromDictionary:useFallback:context:.

Here is the caller graph for this function:

◆ GroupIDForGroup()

NSUInteger GroupIDForGroup ( OOShipGroup * group,
NSMutableDictionary * context )
static

Definition at line 304 of file ShipEntityLoadRestore.m.

305{
306 NSMutableDictionary* groupIDs = [context objectForKey:@"groupIDs"];
307 if (groupIDs == nil) {
308 groupIDs = [NSMutableDictionary dictionary];
309 [context setObject:groupIDs forKey:@"groupIDs"];
310 }
311
312 NSValue* key = [NSValue valueWithNonretainedObject:group];
313 NSNumber* groupIDObj = [groupIDs objectForKey:key];
314 unsigned groupID;
315 if (groupIDObj == nil) {
316 // Assign a new group ID.
317 groupID = [context oo_unsignedIntForKey:@"nextGroupID"];
318 groupIDObj = [NSNumber numberWithUnsignedInt:groupID];
319 [context oo_setUnsignedInteger:groupID + 1 forKey:@"nextGroupID"];
320 [groupIDs setObject:groupIDObj forKey:key];
321
322 /* Also keep references to the groups. This isn't necessary at the
323 time of writing, but would be if we e.g. switched to pickling
324 ships in wormholes all the time (each wormhole would then need a
325 persistent context). We can't simply use the groups instead of
326 NSValues as keys, becuase dictionary keys must be copyable.
327 */
328 NSMutableSet* groups = [context objectForKey:@"groups"];
329 if (groups == nil) {
330 groups = [NSMutableSet set];
331 [context setObject:groups forKey:@"groups"];
332 }
333 [groups addObject:group];
334 } else {
335 groupID = [groupIDObj unsignedIntValue];
336 }
337
338 return groupID;
339}

References nil.

◆ StripIgnoredKeys()

void StripIgnoredKeys ( NSMutableDictionary * dict)
static

Definition at line 292 of file ShipEntityLoadRestore.m.

293{
294 static NSArray* ignoredKeys = nil;
295 if (ignoredKeys == nil)
296 ignoredKeys = [[NSArray alloc] initWithObjects:@"ai_type", @"has_ecm", @"has_scoop", @"has_escape_pod", @"has_energy_bomb", @"has_fuel_injection", @"has_cloaking_device", @"has_military_jammer", @"has_military_scanner_filter", @"has_shield_booster", @"has_shield_enhancer", @"escorts", @"escort_role", @"escort-ship", @"conditions", @"missiles", @"auto_ai", nil];
297
298 NSString* key = nil;
299 foreach (key, ignoredKeys) {
300 [dict removeObjectForKey:key];
301 }
302}

References nil.

Referenced by ShipEntity(LoadRestore)::shipRestoredFromDictionary:useFallback:context:, and ShipEntity(LoadRestoreInternal)::simplifyShipdata:andGetDeletes:.

Here is the caller graph for this function: