Oolite 1.91.0.7645-241119-222d325
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 365 of file ShipEntityLoadRestore.m.

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

◆ GroupIDForGroup()

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

Definition at line 321 of file ShipEntityLoadRestore.m.

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

References nil.

◆ StripIgnoredKeys()

static void StripIgnoredKeys ( NSMutableDictionary * dict)
static

Definition at line 307 of file ShipEntityLoadRestore.m.

308{
309 static NSArray *ignoredKeys = nil;
310 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];
311
312 NSEnumerator *keyEnum = nil;
313 NSString *key = nil;
314 for (keyEnum = [ignoredKeys objectEnumerator]; (key = [keyEnum nextObject]); )
315 {
316 [dict removeObjectForKey:key];
317 }
318}

References nil.