Oolite
Loading...
Searching...
No Matches
ShipEntityLoadRestore.m File Reference
import "ShipEntityLoadRestore.h"
import "Universe.h"
import "OOShipRegistry.h"
import "OORoleSet.h"
import "OOCollectionExtractors.h"
import "OOConstToString.h"
import "OOShipGroup.h"
import "OOEquipmentType.h"
import "AI.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 OOShipGroupGroupForGroupID (NSUInteger groupID, NSMutableDictionary *context)
 

Macro Definition Documentation

◆ KEY_AFT_WEAPON

#define KEY_AFT_WEAPON   @"aft_weapon_type"

Definition at line 52 of file ShipEntityLoadRestore.m.

◆ KEY_AI

#define KEY_AI   @"AI"

Definition at line 56 of file ShipEntityLoadRestore.m.

◆ KEY_BOUNTY

#define KEY_BOUNTY   @"bounty"

Definition at line 47 of file ShipEntityLoadRestore.m.

◆ KEY_ENERGY_LEVEL

#define KEY_ENERGY_LEVEL   @"energy_level"

Definition at line 48 of file ShipEntityLoadRestore.m.

◆ KEY_EQUIPMENT

#define KEY_EQUIPMENT   @"equipment"

Definition at line 49 of file ShipEntityLoadRestore.m.

◆ KEY_ESCORT_GROUP_ID

#define KEY_ESCORT_GROUP_ID   @"escort_group"

Definition at line 62 of file ShipEntityLoadRestore.m.

◆ KEY_FORWARD_WEAPON

#define KEY_FORWARD_WEAPON   @"forward_weapon_type"

Definition at line 51 of file ShipEntityLoadRestore.m.

◆ KEY_FUEL

#define KEY_FUEL   @"fuel"

Definition at line 46 of file ShipEntityLoadRestore.m.

◆ KEY_GROUP_ID

#define KEY_GROUP_ID   @"group"

Definition at line 59 of file ShipEntityLoadRestore.m.

◆ KEY_GROUP_NAME

#define KEY_GROUP_NAME   @"group_name"

Definition at line 60 of file ShipEntityLoadRestore.m.

◆ KEY_IS_GROUP_LEADER

#define KEY_IS_GROUP_LEADER   @"is_group_leader"

Definition at line 61 of file ShipEntityLoadRestore.m.

◆ KEY_MISSILES

#define KEY_MISSILES   @"missiles"

Definition at line 50 of file ShipEntityLoadRestore.m.

◆ KEY_ORIENTATION

#define KEY_ORIENTATION   @"orientation"

Definition at line 44 of file ShipEntityLoadRestore.m.

◆ KEY_POSITION

#define KEY_POSITION   @"position"

Definition at line 43 of file ShipEntityLoadRestore.m.

◆ KEY_PRIMARY_ROLE

#define KEY_PRIMARY_ROLE   @"primary_role"

Definition at line 42 of file ShipEntityLoadRestore.m.

◆ KEY_ROLES

#define KEY_ROLES   @"roles"

Definition at line 45 of file ShipEntityLoadRestore.m.

◆ KEY_SCAN_CLASS

#define KEY_SCAN_CLASS   @"scan_class"

Definition at line 53 of file ShipEntityLoadRestore.m.

◆ KEY_SHIP_KEY

#define KEY_SHIP_KEY   @"ship_key"

Definition at line 39 of file ShipEntityLoadRestore.m.

◆ KEY_SHIPDATA_DELETES

#define KEY_SHIPDATA_DELETES   @"shipdata_deletes"

Definition at line 41 of file ShipEntityLoadRestore.m.

◆ KEY_SHIPDATA_OVERRIDES

#define KEY_SHIPDATA_OVERRIDES   @"shipdata_overrides"

Definition at line 40 of file ShipEntityLoadRestore.m.

Function Documentation

◆ GroupForGroupID()

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

Definition at line 362 of file ShipEntityLoadRestore.m.

363{
364 NSNumber *key = [NSNumber numberWithUnsignedInteger:groupID];
365
366 NSMutableDictionary *groups = [context objectForKey:@"groupsByID"];
367 if (groups == nil)
368 {
369 groups = [NSMutableDictionary dictionary];
370 [context setObject:groups forKey:@"groupsByID"];
371 }
372
373 OOShipGroup *group = [groups objectForKey:key];
374 if (group == nil)
375 {
376 group = [[[OOShipGroup alloc] init] autorelease];
377 [groups setObject:group forKey:key];
378 }
379
380 return group;
381}
return nil

◆ GroupIDForGroup()

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

Definition at line 318 of file ShipEntityLoadRestore.m.

319{
320 NSMutableDictionary *groupIDs = [context objectForKey:@"groupIDs"];
321 if (groupIDs == nil)
322 {
323 groupIDs = [NSMutableDictionary dictionary];
324 [context setObject:groupIDs forKey:@"groupIDs"];
325 }
326
327 NSValue *key = [NSValue valueWithNonretainedObject:group];
328 NSNumber *groupIDObj = [groupIDs objectForKey:key];
329 unsigned groupID;
330 if (groupIDObj == nil)
331 {
332 // Assign a new group ID.
333 groupID = [context oo_unsignedIntForKey:@"nextGroupID"];
334 groupIDObj = [NSNumber numberWithUnsignedInt:groupID];
335 [context oo_setUnsignedInteger:groupID + 1 forKey:@"nextGroupID"];
336 [groupIDs setObject:groupIDObj forKey:key];
337
338 /* Also keep references to the groups. This isn't necessary at the
339 time of writing, but would be if we e.g. switched to pickling
340 ships in wormholes all the time (each wormhole would then need a
341 persistent context). We can't simply use the groups instead of
342 NSValues as keys, becuase dictionary keys must be copyable.
343 */
344 NSMutableSet *groups = [context objectForKey:@"groups"];
345 if (groups == nil)
346 {
347 groups = [NSMutableSet set];
348 [context setObject:groups forKey:@"groups"];
349 }
350 [groups addObject:group];
351 }
352 else
353 {
354 groupID = [groupIDObj unsignedIntValue];
355 }
356
357
358 return groupID;
359}

References nil.

◆ StripIgnoredKeys()

static void StripIgnoredKeys ( NSMutableDictionary *  dict)
static

Definition at line 305 of file ShipEntityLoadRestore.m.

306{
307 static NSArray *ignoredKeys = nil;
308 if (ignoredKeys == nil) 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];
309
310 NSString *key = nil;
311 foreach (key, ignoredKeys)
312 {
313 [dict removeObjectForKey:key];
314 }
315}

References nil.