Oolite
Loading...
Searching...
No Matches
OOShipRegistry Class Reference

#include <OOShipRegistry.h>

Inheritance diagram for OOShipRegistry:
Collaboration diagram for OOShipRegistry:

Instance Methods

(NSDictionary *) - shipInfoForKey:
(void) - setShipInfoForKey:with:
(NSDictionary *) - effectInfoForKey:
(NSDictionary *) - shipyardInfoForKey:
(OOProbabilitySet *) - probabilitySetForRole:
(NSArray *) - demoShipKeys
(NSArray *) - playerShipKeys
(id) - init [implementation]
(void) - dealloc [implementation]
(NSArray *) - shipKeys
(NSArray *) - shipRoles
(NSArray *) - shipKeysWithRole:
(NSString *) - randomShipKeyForRole:
(void) - loadShipData [implementation]
(void) - loadDemoShipConditions [implementation]
(void) - loadDemoShips [implementation]
(void) - loadCachedRoleProbabilitySets [implementation]
(void) - buildRoleProbabilitySets [implementation]
(BOOL) - applyLikeShips:withKey: [implementation]
(BOOL) - loadAndMergeShipyard: [implementation]
(BOOL) - stripPrivateKeys: [implementation]
(BOOL) - makeShipEntriesMutable: [implementation]
(BOOL) - loadAndApplyShipDataOverrides: [implementation]
(BOOL) - canonicalizeAndTagSubentities: [implementation]
(BOOL) - removeUnusableEntries:shipMode: [implementation]
(BOOL) - sanitizeConditions: [implementation]
(NSMutableDictionary *) - mergeShip:withParent: [implementation]
(void) - mergeShipRoles:forShipKey:intoProbabilityMap: [implementation]
(NSDictionary *) - canonicalizeSubentityDeclaration:forShip:shipData:fatalError: [implementation]
(NSDictionary *) - translateOldStyleSubentityDeclaration:forShip:shipData:fatalError: [implementation]
(NSDictionary *) - translateOldStyleFlasherDeclaration:forShip:fatalError: [implementation]
(NSDictionary *) - translateOldStandardBasicSubentityDeclaration:forShip:shipData:fatalError: [implementation]
(NSDictionary *) - validateNewStyleSubentityDeclaration:forShip:fatalError: [implementation]
(NSDictionary *) - validateNewStyleFlasherDeclaration:forShip:fatalError: [implementation]
(NSDictionary *) - validateNewStyleStandardSubentityDeclaration:forShip:fatalError: [implementation]
(BOOL) - shipIsBallTurretForKey:inShipData: [implementation]
(id) - copyWithZone: [implementation]
(id) - retain [implementation]
(NSUInteger) - retainCount [implementation]
(void) - release [implementation]
(id) - autorelease [implementation]

Class Methods

(OOShipRegistry *) + sharedRegistry
(void) + reload
(id) + allocWithZone: [implementation]

Private Attributes

NSDictionary * _shipData
NSDictionary * _effectData
NSArray * _demoShips
NSArray * _playerShips
NSDictionary * _probabilitySets

Detailed Description

Definition at line 34 of file OOShipRegistry.h.

Method Documentation

◆ allocWithZone:

+ (id) allocWithZone: (NSZone*) inZone
implementation

Provided by category OOShipRegistry(Singleton).

Definition at line 1519 of file OOShipRegistry.m.

1519 :(NSZone*)inZone
1520{
1521 if (sSingleton == nil) {
1522 OOLog(@"shipData.load.begin", @"%@", @"Loading ship data.");
1523 sSingleton = [super allocWithZone:inZone];
1524 return sSingleton;
1525 }
1526 return nil;
1527}
#define OOLog(class, format,...)
Definition OOLogging.h:84
static OONullTexture * sSingleton
return nil

◆ applyLikeShips:withKey:

- (BOOL) applyLikeShips: (NSMutableDictionary*) ioData
withKey: (NSString*) likeKey 
implementation

Provided by category OOShipRegistry(OODataLoader).

Definition at line 580 of file OOShipRegistry.m.

580 :(NSMutableDictionary*)ioData withKey:(NSString*)likeKey
581{
582 NSMutableSet* remainingLikeShips = nil;
583 NSString* key = nil;
584 NSString* parentKey = nil;
585 NSDictionary* shipEntry = nil;
586 NSDictionary* parentEntry = nil;
587 NSUInteger count, lastCount;
588 NSMutableArray* reportedBadShips = nil;
589
590 // Build set of ships with like_ship references
591 remainingLikeShips = [NSMutableSet set];
592 foreachkey(key, ioData)
593 {
594 shipEntry = [ioData objectForKey:key];
595 if ([shipEntry oo_stringForKey:likeKey] != nil) {
596 [remainingLikeShips addObject:key];
597 }
598 }
599
600 count = lastCount = [remainingLikeShips count];
601 while (count != 0) {
602 foreach (key, [[remainingLikeShips copy] autorelease]) {
603 // Look up like_ship entry
604 shipEntry = [ioData objectForKey:key];
605 parentKey = [shipEntry objectForKey:likeKey];
606 if (![remainingLikeShips containsObject:parentKey]) {
607 // If parent is fully resolved, we can resolve this child.
608 parentEntry = [ioData objectForKey:parentKey];
609 shipEntry = [self mergeShip:shipEntry withParent:parentEntry];
610 if (shipEntry != nil) {
611 [remainingLikeShips removeObject:key];
612 [ioData setObject:shipEntry forKey:key];
613 }
614 }
615 }
616
617 count = [remainingLikeShips count];
618 if (count == lastCount) {
619 /* Fail: we couldn't resolve all like_ship entries.
620 Remove unresolved entries, building a list of the ones that
621 don't have is_external_dependency set.
622 */
623 reportedBadShips = [NSMutableArray array];
624 foreach (key, remainingLikeShips) {
625 if (![[ioData oo_dictionaryForKey:key] oo_boolForKey:@"is_external_dependency"]) {
626 [reportedBadShips addObject:key];
627 }
628 [ioData removeObjectForKey:key];
629 }
630
631 if ([reportedBadShips count] != 0) {
632 [reportedBadShips sortUsingSelector:@selector(caseInsensitiveCompare:)];
633 OOLogERR(@"shipData.merge.failed", @"one or more shipdata.plist entries have %@ references that cannot be resolved: %@", likeKey, [reportedBadShips componentsJoinedByString:@", "]); // FIXME: distinguish shipdata and effectdata
634 OOStandardsError(@"Likely missing a dependency in a manifest.plist");
635 }
636 break;
637 }
638 lastCount = count;
639 }
640
641 return YES;
642}
void OOStandardsError(NSString *message)
#define foreachkey(VAR, DICT)
#define OOLogERR(class, format,...)
Definition OOLogging.h:125
unsigned count

◆ autorelease

- (id) autorelease
implementation

Provided by category OOShipRegistry(Singleton).

Definition at line 1548 of file OOShipRegistry.m.

1549{
1550 return self;
1551}

◆ buildRoleProbabilitySets

- (void) buildRoleProbabilitySets
implementation

Provided by category OOShipRegistry(OODataLoader).

Definition at line 532 of file OOShipRegistry.m.

533{
534 NSMutableDictionary* probabilitySets = nil;
535 NSString* shipKey = nil;
536 NSDictionary* shipEntry = nil;
537 NSString* roles = nil;
538 NSString* role = nil;
539 OOProbabilitySet* pset = nil;
540 NSMutableDictionary* cacheEntry = nil;
541
542 probabilitySets = [NSMutableDictionary dictionary];
543
544 // Build role sets
545 foreachkey(shipKey, _shipData)
546 {
547 shipEntry = [_shipData objectForKey:shipKey];
548 roles = [shipEntry oo_stringForKey:@"roles"];
549 [self mergeShipRoles:roles forShipKey:shipKey intoProbabilityMap:probabilitySets];
550 }
551
552 // Convert role sets to immutable form, and build cache entry.
553 // Note: we iterate over a copy of the keys to avoid mutating while iterating.
554 cacheEntry = [NSMutableDictionary dictionaryWithCapacity:[probabilitySets count]];
555 foreach (role, [probabilitySets allKeys]) {
556 pset = [probabilitySets objectForKey:role];
557 pset = [[pset copy] autorelease];
558 [probabilitySets setObject:pset forKey:role];
559 [cacheEntry setObject:[pset propertyListRepresentation] forKey:role];
560 }
561
562 _probabilitySets = [probabilitySets copy];
563 [[OOCacheManager sharedCache] setObject:cacheEntry forKey:kRoleWeightsCacheKey inCache:kShipRegistryCacheName];
564}
void setObject:forKey:inCache:(id inElement,[forKey] NSString *inKey,[inCache] NSString *inCacheKey)
OOCacheManager * sharedCache()
NSDictionary * propertyListRepresentation()
NSDictionary * _probabilitySets
NSDictionary * _shipData

Referenced by init.

Here is the caller graph for this function:

◆ canonicalizeAndTagSubentities:

- (BOOL) canonicalizeAndTagSubentities: (NSMutableDictionary*) ioData
implementation

Provided by category OOShipRegistry(OODataLoader).

Definition at line 828 of file OOShipRegistry.m.

828 :(NSMutableDictionary*)ioData
829{
830 NSString* shipKey = nil;
831 NSMutableDictionary* shipEntry = nil;
832 NSArray* subentityDeclarations = nil;
833 id subentityDecl = nil;
834 NSDictionary* subentityDict = nil;
835 NSString* subentityKey = nil;
836 NSMutableDictionary* subentityShipEntry = nil;
837 NSMutableSet* badSubentities = nil;
838 NSString* badSubentitiesList = nil;
839 NSMutableArray* okSubentities = nil;
840 BOOL remove, fatal;
841
842 // Convert all subentity declarations to dictionaries and add
843 // _oo_is_subentity=YES to all entries used as subentities.
844
845 // Iterate over all ships. (Iterates over a copy of keys since it mutates the dictionary.)
846 foreach (shipKey, [ioData allKeys]) {
847 shipEntry = [ioData objectForKey:shipKey];
848 remove = NO;
849 badSubentities = nil;
850
851 // Iterate over each subentity declaration of each ship
852 subentityDeclarations = [shipEntry oo_arrayForKey:@"subentities"];
853 if (subentityDeclarations != nil) {
854 okSubentities = [NSMutableArray arrayWithCapacity:[subentityDeclarations count]];
855 foreach (subentityDecl, subentityDeclarations) {
856 subentityDict = [self canonicalizeSubentityDeclaration:subentityDecl forShip:shipKey shipData:ioData fatalError:&fatal];
857
858 // If entry is broken, we need to kill this ship.
859 if (fatal) {
860 OOStandardsError(@"Bad subentity definition found");
861 remove = YES;
862 } else if (subentityDict != nil) {
863 [okSubentities addObject:subentityDict];
864
865 // Tag subentities.
866 if (![[subentityDict oo_stringForKey:@"type"] isEqualToString:@"flasher"]) {
867 subentityKey = [subentityDict oo_stringForKey:@"subentity_key"];
868 subentityShipEntry = [ioData objectForKey:subentityKey];
869 if (subentityKey == nil || subentityShipEntry == nil) {
870 // Oops, reference to non-existent subent.
871 if (badSubentities == nil)
872 badSubentities = [NSMutableSet set];
873 [badSubentities addObject:subentityKey];
874 } else {
875 // Subent exists, add _oo_is_subentity so roles aren't required.
876 [subentityShipEntry oo_setBool:YES forKey:@"_oo_is_subentity"];
877 }
878 }
879 }
880 }
881
882 // Set updated subentity list.
883 if ([okSubentities count] != 0) {
884 [shipEntry setObject:okSubentities forKey:@"subentities"];
885 } else {
886 [shipEntry removeObjectForKey:@"subentities"];
887 }
888
889 if (badSubentities != nil) {
890 if (![shipEntry oo_boolForKey:@"is_external_dependency"]) {
891 badSubentitiesList = [[[badSubentities allObjects] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)] componentsJoinedByString:@", "];
892 OOLogERR(@"shipData.load.error", @"the shipdata.plist entry \"%@\" has unresolved subentit%@ %@.", shipKey, ([badSubentities count] == 1) ? @"y" : @"ies", badSubentitiesList);
893 OOStandardsError(@"Bad subentity definition found");
894 }
895 remove = YES;
896 }
897
898 if (remove) {
899 // Removal is deferred to avoid bogus "entry doesn't exist" errors.
900 [shipEntry oo_setBool:YES forKey:@"_oo_deferred_remove"];
901 }
902 }
903 }
904
905 return YES;
906}

◆ canonicalizeSubentityDeclaration:forShip:shipData:fatalError:

- (NSDictionary *) canonicalizeSubentityDeclaration: (id) declaration
forShip: (NSString*) shipKey
shipData: (NSDictionary*) shipData
fatalError: (BOOL*) outFatalError 
implementation

Provided by category OOShipRegistry(OODataLoader).

Definition at line 1138 of file OOShipRegistry.m.

1138 :(id)declaration
1139 forShip:(NSString*)shipKey
1140 shipData:(NSDictionary*)shipData
1141 fatalError:(BOOL*)outFatalError
1142{
1143 NSDictionary* result = nil;
1144
1145 assert(outFatalError != NULL);
1146 *outFatalError = NO;
1147
1148 if ([declaration isKindOfClass:[NSString class]]) {
1149 // Update old-style string-based declaration.
1150 OOStandardsDeprecated([NSString stringWithFormat:@"Old style sub-entity declarations are deprecated in %@", shipKey]);
1151 if (!OOEnforceStandards()) {
1152 result = [self translateOldStyleSubentityDeclaration:declaration
1153 forShip:shipKey
1154 shipData:shipData
1155 fatalError:outFatalError];
1156 }
1157 if (result != nil) {
1158 // Ensure internal translation made sense, and clean up a bit.
1159 result = [self validateNewStyleSubentityDeclaration:result
1160 forShip:shipKey
1161 fatalError:outFatalError];
1162 }
1163 } else if ([declaration isKindOfClass:[NSDictionary class]]) {
1164 // Validate dictionary-based declaration.
1165 result = [self validateNewStyleSubentityDeclaration:declaration
1166 forShip:shipKey
1167 fatalError:outFatalError];
1168 } else {
1169 OOLogERR(@"shipData.load.error.badSubentity", @"subentity declaration for ship %@ should be string or dictionary, found %@.", shipKey, [declaration class]);
1170 *outFatalError = YES;
1171 }
1172
1173 // For frangible ships, bad subentities are non-fatal.
1174 if (*outFatalError && [[shipData oo_dictionaryForKey:shipKey] oo_boolForKey:@"frangible"])
1175 *outFatalError = NO;
1176
1177 return result;
1178}
void OOStandardsDeprecated(NSString *message)
BOOL OOEnforceStandards(void)

Referenced by OOShipRegistry(OODataLoader)::canonicalizeAndTagSubentities:.

Here is the caller graph for this function:

◆ copyWithZone:

- (id) copyWithZone: (NSZone*) inZone
implementation

Provided by category OOShipRegistry(Singleton).

Definition at line 1529 of file OOShipRegistry.m.

1529 :(NSZone*)inZone
1530{
1531 return self;
1532}

◆ dealloc

- (void) dealloc
implementation

Definition at line 180 of file OOShipRegistry.m.

181{
182 [_shipData release];
183 [_demoShips release];
184 [_playerShips release];
185 [_probabilitySets release];
186
187 [super dealloc];
188}

References dealloc.

Referenced by dealloc.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ demoShipKeys

- (NSArray *) demoShipKeys

Definition at line 220 of file OOShipRegistry.m.

221{
222 // with condition scripts in use, can't cache this value
223 [self loadDemoShips];
224
225 return [[_demoShips copy] autorelease];
226}

References demoShipKeys, and loadDemoShips.

Referenced by demoShipKeys, Universe::reinitAndShowDemo:, and Universe::setupIntroFirstGo:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ effectInfoForKey:

- (NSDictionary *) effectInfoForKey: (NSString*) key

Definition at line 203 of file OOShipRegistry.m.

203 :(NSString*)key
204{
205 return [_effectData objectForKey:key];
206}

Referenced by Universe::newVisualEffectWithName:.

Here is the caller graph for this function:

◆ init

- (id) init
implementation

Definition at line 141 of file OOShipRegistry.m.

142{
143 if ((self = [super init])) {
144 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
145 OOCacheManager* cache = [OOCacheManager sharedCache];
146
147 _shipData = [[cache objectForKey:kShipDataCacheKey inCache:kShipRegistryCacheName] retain];
148 _playerShips = [[cache objectForKey:kPlayerShipsCacheKey inCache:kShipRegistryCacheName] retain];
149 _effectData = [[cache objectForKey:kVisualEffectDataCacheKey inCache:kVisualEffectRegistryCacheName] retain];
150 if ([_shipData count] == 0) // Don't accept nil or empty
151 {
152 [self loadShipData];
153 if ([_shipData count] == 0) {
154 [NSException raise:@"OOShipRegistryLoadFailure" format:@"Could not load any ship data."];
155 }
156 if ([_playerShips count] == 0) {
157 [NSException raise:@"OOShipRegistryLoadFailure" format:@"Could not load any player ships."];
158 }
159 }
160
161 [self loadDemoShipConditions];
162 [self loadDemoShips]; // testing only
163 if ([_demoShips count] == 0) {
164 [NSException raise:@"OOShipRegistryLoadFailure" format:@"Could not load or synthesize any demo ships."];
165 }
166
167 [self loadCachedRoleProbabilitySets];
168 if (_probabilitySets == nil) {
169 [self buildRoleProbabilitySets];
170 if ([_probabilitySets count] == 0) {
171 [NSException raise:@"OOShipRegistryLoadFailure" format:@"Could not load or synthesize role probability sets."];
172 }
173 }
174
175 [pool release];
176 }
177 return self;
178}
id objectForKey:inCache:(NSString *inKey,[inCache] NSString *inCacheKey)
NSArray * _demoShips
NSArray * _playerShips
NSDictionary * _effectData

References _demoShips, _effectData, _playerShips, _probabilitySets, _shipData, buildRoleProbabilitySets, count, init, loadCachedRoleProbabilitySets, loadDemoShipConditions, loadDemoShips, loadShipData, nil, OOCacheManager::objectForKey:inCache:, and OOCacheManager::sharedCache.

Referenced by init.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ loadAndApplyShipDataOverrides:

- (BOOL) loadAndApplyShipDataOverrides: (NSMutableDictionary*) ioData
implementation

Provided by category OOShipRegistry(OODataLoader).

Definition at line 719 of file OOShipRegistry.m.

719 :(NSMutableDictionary*)ioData
720{
721 NSString* shipKey = nil;
722 NSMutableDictionary* shipEntry = nil;
723 NSDictionary* overrides = nil;
724 NSDictionary* overridesEntry = nil;
725
726 overrides = [ResourceManager dictionaryFromFilesNamed:@"shipdata-overrides.plist"
727 inFolder:@"Config"
728 mergeMode:MERGE_SMART
729 cache:NO];
730
731 foreachkey(shipKey, overrides)
732 {
733 shipEntry = [ioData objectForKey:shipKey];
734 if (shipEntry != nil) {
735 overridesEntry = [overrides objectForKey:shipKey];
736 if (![overridesEntry isKindOfClass:[NSDictionary class]]) {
737 OOLogERR(@"shipData.load.error", @"the shipdata-overrides.plist entry \"%@\" is not a dictionary.", shipKey);
738 } else {
739 [shipEntry addEntriesFromDictionary:overridesEntry];
740 }
741 }
742 }
743
744 return YES;
745}
NSDictionary * dictionaryFromFilesNamed:inFolder:mergeMode:cache:(NSString *fileName,[inFolder] NSString *folderName,[mergeMode] OOResourceMergeMode mergeMode,[cache] BOOL useCache)

◆ loadAndMergeShipyard:

- (BOOL) loadAndMergeShipyard: (NSMutableDictionary*) ioData
implementation

Provided by category OOShipRegistry(OODataLoader).

Definition at line 775 of file OOShipRegistry.m.

775 :(NSMutableDictionary*)ioData
776{
777 NSString* shipKey = nil;
778 NSMutableDictionary* shipEntry = nil;
779 NSDictionary* shipyard = nil;
780 NSDictionary* shipyardOverrides = nil;
781 NSDictionary* shipyardEntry = nil;
782 NSDictionary* shipyardOverridesEntry = nil;
783 NSMutableArray* playerShips = nil;
784
785 // Strip out any shipyard stuff in shipdata (there shouldn't be any).
786 foreachkey(shipKey, ioData)
787 {
788 shipEntry = [ioData objectForKey:shipKey];
789 if ([shipEntry objectForKey:@"_oo_shipyard"] != nil) {
790 [shipEntry removeObjectForKey:@"_oo_shipyard"];
791 }
792 }
793
794 shipyard = [ResourceManager dictionaryFromFilesNamed:@"shipyard.plist"
795 inFolder:@"Config"
796 mergeMode:MERGE_BASIC
797 cache:NO];
798 shipyardOverrides = [ResourceManager dictionaryFromFilesNamed:@"shipyard-overrides.plist"
799 inFolder:@"Config"
800 mergeMode:MERGE_SMART
801 cache:NO];
802
803 playerShips = [NSMutableArray arrayWithCapacity:[shipyard count]];
804
805 // Insert merged shipyard and shipyardOverrides entries.
806 foreachkey(shipKey, shipyard)
807 {
808 shipEntry = [ioData objectForKey:shipKey];
809 if (shipEntry != nil) {
810 shipyardEntry = [shipyard objectForKey:shipKey];
811 shipyardOverridesEntry = [shipyardOverrides objectForKey:shipKey];
812 shipyardEntry = [shipyardEntry dictionaryByAddingEntriesFromDictionary:shipyardOverridesEntry];
813
814 [shipEntry setObject:shipyardEntry forKey:@"_oo_shipyard"];
815
816 [playerShips addObject:shipKey];
817 } else {
818 OOLogWARN(@"shipData.load.shipyard.unknown", @"the shipyard.plist entry \"%@\" does not have a corresponding shipdata.plist entry, ignoring.", shipKey);
819 }
820 }
821
822 _playerShips = [playerShips copy];
823 [[OOCacheManager sharedCache] setObject:_playerShips forKey:kPlayerShipsCacheKey inCache:kShipRegistryCacheName];
824
825 return YES;
826}
#define OOLogWARN(class, format,...)
Definition OOLogging.h:126

◆ loadCachedRoleProbabilitySets

- (void) loadCachedRoleProbabilitySets
implementation

Provided by category OOShipRegistry(OODataLoader).

Definition at line 513 of file OOShipRegistry.m.

514{
515 NSDictionary* cachedSets = nil;
516 NSMutableDictionary* restoredSets = nil;
517 NSString* role = nil;
518
519 cachedSets = [[OOCacheManager sharedCache] objectForKey:kRoleWeightsCacheKey inCache:kShipRegistryCacheName];
520 if (cachedSets == nil)
521 return;
522
523 restoredSets = [NSMutableDictionary dictionaryWithCapacity:[cachedSets count]];
524 foreachkey(role, cachedSets)
525 {
526 [restoredSets setObject:[OOProbabilitySet probabilitySetWithPropertyListRepresentation:[cachedSets objectForKey:role]] forKey:role];
527 }
528
529 _probabilitySets = [restoredSets copy];
530}
void setObject:forKey:(id value,[forKey] id key)
Definition OOCache.m:256
id probabilitySetWithPropertyListRepresentation:(NSDictionary *plist)

Referenced by init.

Here is the caller graph for this function:

◆ loadDemoShipConditions

- (void) loadDemoShipConditions
implementation

Provided by category OOShipRegistry(OODataLoader).

Definition at line 383 of file OOShipRegistry.m.

384{
385 NSMutableArray* conditionScripts = [[NSMutableArray alloc] init];
386 NSDictionary* key = nil;
387 NSArray* initialDemoShips = nil;
388
389 initialDemoShips = [ResourceManager arrayFromFilesNamed:@"shiplibrary.plist"
390 inFolder:@"Config"
391 andMerge:YES
392 cache:NO];
393
394 foreach (key, initialDemoShips) {
395 NSString* conditions = [key oo_stringForKey:kOODemoShipConditions defaultValue:nil];
396 if (conditions != nil) {
397 [conditionScripts addObject:conditions];
398 }
399 }
400
401 [[OOCacheManager sharedCache] setObject:conditionScripts forKey:@"demoship conditions" inCache:@"condition scripts"];
402 [conditionScripts release];
403}
NSArray * arrayFromFilesNamed:inFolder:andMerge:cache:(NSString *fileName,[inFolder] NSString *folderName,[andMerge] BOOL mergeFiles,[cache] BOOL useCache)

Referenced by init.

Here is the caller graph for this function:

◆ loadDemoShips

- (void) loadDemoShips
implementation

Provided by category OOShipRegistry(OODataLoader).

Definition at line 411 of file OOShipRegistry.m.

412{
413 NSDictionary* key = nil;
414 NSArray* initialDemoShips = nil;
415 NSMutableArray* demoShips = nil;
416
418
419 initialDemoShips = [ResourceManager arrayFromFilesNamed:@"shiplibrary.plist"
420 inFolder:@"Config"
421 andMerge:YES
422 cache:NO];
423 demoShips = [NSMutableArray arrayWithArray:initialDemoShips];
424
425 // Note: iterate over initialDemoShips to avoid mutating the collection being enu,erated.
426 foreach (key, initialDemoShips) {
427 NSString* shipKey = [key oo_stringForKey:kOODemoShipKey];
428 if (![key isKindOfClass:[NSDictionary class]] || [self shipInfoForKey:shipKey] == nil) {
429 [demoShips removeObject:key];
430 } else {
431 NSString* conditions = [key oo_stringForKey:kOODemoShipConditions defaultValue:nil];
432 if (conditions != nil) {
433 if ([PLAYER status] == STATUS_START_GAME) {
434 // conditions always false here
435 [demoShips removeObject:key];
436 } else {
437 OOJSScript* condScript = [UNIVERSE getConditionScript:conditions];
438 if (condScript != nil) // should always be non-nil, but just in case
439 {
440 JSContext* context = OOJSAcquireContext();
441 BOOL OK;
442 BOOL allow_use = NO;
443 OOJSVal result = OOJSUndefinedValue();
444 OOJSVal args[] = { OOJSValueFromNativeObject(context, shipKey) };
445
446 OK = [condScript callMethod:OOJSID("allowShowLibraryShip")
447 inContext:context
448 withArguments:args
449 count:sizeof args / sizeof *args
450 result:&result];
451
452 if (OK)
453 allow_use = OOJSValueToBOOL(context, result);
454
455 OOJSFreeValue(context, result);
456 OOJSFreeValue(context, args[0]);
457 OOJSRelinquishContext(context);
458 if (OK && !allow_use) {
459 /* if the script exists, the function exists, the function
460 * returns a bool, and that bool is false, hide the
461 * ship. Otherwise allow it as default */
462 [demoShips removeObject:key];
463 }
464 }
465 }
466 }
467 }
468 }
469
470 if ([demoShips count] == 0) {
471 NSString* shipKey = nil;
472 if ([self shipInfoForKey:kDefaultDemoShip] != nil) {
473 shipKey = kDefaultDemoShip;
474 } else {
475 shipKey = [[_shipData allKeys] objectAtIndex:0];
476 }
477 [demoShips addObject:[NSDictionary dictionaryWithObject:shipKey forKey:kOODemoShipKey]];
478 }
479
480 // now separate out the demoships by class, and add some extra keys
481 NSMutableDictionary* demoList = [NSMutableDictionary dictionaryWithCapacity:8];
482 NSMutableArray* demoClass = nil;
483 foreach (key, demoShips) {
484 NSString* class = [key oo_stringForKey:kOODemoShipClass defaultValue:@"ship"];
485 if ([OOShipLibraryCategoryPlural(class) length] == 0) {
486 OOLog(@"shipdata.load.warning", @"Unexpected class '%@' in shiplibrary.plist for '%@'", class, [key oo_stringForKey:kOODemoShipKey]);
487 class = @"ship";
488 }
489 demoClass = [demoList objectForKey:class];
490 if (demoClass == nil) {
491 [demoList setObject:[NSMutableArray array] forKey:class];
492 demoClass = [demoList objectForKey:class];
493 }
494 NSMutableDictionary* demoEntry = [NSMutableDictionary dictionaryWithDictionary:key];
495 // add "name" object to dictionary from ship definition
496 [demoEntry setObject:[[self shipInfoForKey:[demoEntry oo_stringForKey:@"ship"]] oo_stringForKey:kOODemoShipName] forKey:kOODemoShipName];
497 // set "class" object to standard ship if not otherwise set
498 if (![[demoEntry oo_stringForKey:kOODemoShipClass defaultValue:nil] isEqualToString:class]) {
499 [demoEntry setObject:class forKey:kOODemoShipClass];
500 }
501 [demoClass addObject:demoEntry];
502 }
503 // sort each ship list by name
504 NSString* demoClassName = nil;
505 foreach (demoClassName, demoList) {
506 [[demoList objectForKey:demoClassName] sortUsingFunction:SortDemoShipsByName context:NULL];
507 }
508
509 // and then sort the ship list list by class name
510 _demoShips = [[[demoList allValues] sortedArrayUsingFunction:SortDemoCategoriesByName context:NULL] retain];
511}
#define DESTROY(x)
jsval OOJSVal
#define OOJSFreeValue(context, value)
#define OOJSUndefinedValue()
OOINLINE jsval OOJSValueFromNativeObject(JSContext *context, id object)
OOINLINE BOOL OOJSValueToBOOL(JSContext *context, jsval value)
OOINLINE JSContext * OOJSAcquireContext(void)
OOINLINE void OOJSRelinquishContext(JSContext *context)
static NSString *const kOODemoShipClass
static NSString *const kOODemoShipKey
static NSString *const kDefaultDemoShip
#define PLAYER
BOOL callMethod:inContext:withArguments:count:result:(jsid methodID,[inContext] JSContext *context,[withArguments] jsval *argv,[count] intN argc,[result] jsval *outResult)
Definition OOJSScript.m:328

Referenced by demoShipKeys, and init.

Here is the caller graph for this function:

◆ loadShipData

- (void) loadShipData
implementation

Provided by category OOShipRegistry(OODataLoader).

Definition at line 271 of file OOShipRegistry.m.

272{
273 NSMutableDictionary* result = nil;
274
275 [_shipData release];
276 _shipData = nil;
277 [_playerShips release];
279
280 // Load shipdata.plist.
281 result = [[[ResourceManager dictionaryFromFilesNamed:@"shipdata.plist"
282 inFolder:@"Config"
283 mergeMode:MERGE_BASIC
284 cache:NO] mutableCopy] autorelease];
285 if (result == nil)
286 return;
287
288 DumpStringAddrs(result, @"shipdata.plist");
289
290 // Make each entry mutable to simplify later stages. Also removes any entries that aren't dictionaries.
291 if (![self makeShipEntriesMutable:result])
292 return;
293 OOLog(@"shipData.load.progress", @"%@", @"Finished initial cleanup...");
294
295 // Apply patches.
296 if (![self loadAndApplyShipDataOverrides:result])
297 return;
298 OOLog(@"shipData.load.progress", @"%@", @"Finished applying patches...");
299
300 // Strip private keys (anything starting with _oo_).
301 if (![self stripPrivateKeys:result])
302 return;
303 OOLog(@"shipData.load.progress", @"%@", @"Finished stripping private keys...");
304
305 // Resolve like_ship entries.
306 if (![self applyLikeShips:result withKey:@"like_ship"])
307 return;
308 OOLog(@"shipData.load.progress", @"%@", @"Finished resolving like_ships...");
309
310 // Clean up subentity declarations and tag subentities so they won't be pruned.
311 if (![self canonicalizeAndTagSubentities:result])
312 return;
313 OOLog(@"shipData.load.progress", @"%@", @"Finished cleaning up subentities...");
314
315 // Clean out templates and invalid entries.
316 if (![self removeUnusableEntries:result shipMode:YES])
317 return;
318 OOLog(@"shipData.load.progress", @"%@", @"Finished removing invalid entries...");
319
320 // Add shipyard entries into shipdata entries.
321 if (![self loadAndMergeShipyard:result])
322 return;
323 OOLog(@"shipData.load.progress", @"%@", @"Finished adding shipyard entries...");
324
325 // Sanitize conditions.
326 if (![self sanitizeConditions:result])
327 return;
328 OOLog(@"shipData.load.progress", @"%@", @"Finished validating data...");
329
330#if PRELOAD
331 // Preload and cache meshes.
332 if (![self preloadShipMeshes:result])
333 return;
334 OOLog(@"shipData.load.progress", @"%@", @"Finished loading meshes...");
335#endif
336
337 _shipData = OODeepCopy(result);
338 [[OOCacheManager sharedCache] setObject:_shipData forKey:kShipDataCacheKey inCache:kShipRegistryCacheName];
339
340 OOLog(@"shipData.load.done", @"%@", @"Ship data loaded.");
341
342 [_effectData release];
344
345 result = [[[ResourceManager dictionaryFromFilesNamed:@"effectdata.plist"
346 inFolder:@"Config"
347 mergeMode:MERGE_BASIC
348 cache:NO] mutableCopy] autorelease];
349 if (result == nil)
350 return;
351
352 // Make each entry mutable to simplify later stages. Also removes any entries that aren't dictionaries.
353 if (![self makeShipEntriesMutable:result])
354 return;
355 OOLog(@"effectData.load.progress", @"%@", @"Finished initial cleanup...");
356
357 // Strip private keys (anything starting with _oo_).
358 if (![self stripPrivateKeys:result])
359 return;
360 OOLog(@"effectData.load.progress", @"%@", @"Finished stripping private keys...");
361
362 // Resolve like_effect entries.
363 if (![self applyLikeShips:result withKey:@"like_effect"])
364 return;
365 OOLog(@"effectData.load.progress", @"%@", @"Finished resolving like_effects...");
366
367 // Clean up subentity declarations and tag subentities so they won't be pruned.
368 if (![self canonicalizeAndTagSubentities:result])
369 return;
370 OOLog(@"effectData.load.progress", @"%@", @"Finished cleaning up subentities...");
371
372 // Clean out templates and invalid entries.
373 if (![self removeUnusableEntries:result shipMode:NO])
374 return;
375 OOLog(@"effectData.load.progress", @"%@", @"Finished removing invalid entries...");
376
377 _effectData = OODeepCopy(result);
378 [[OOCacheManager sharedCache] setObject:_effectData forKey:kVisualEffectDataCacheKey inCache:kVisualEffectRegistryCacheName];
379
380 OOLog(@"effectData.load.done", @"%@", @"Effect data loaded.");
381}
id OODeepCopy(id object) OO_RETURNS_RETAINED
Definition OODeepCopy.m:30
static void DumpStringAddrs(NSDictionary *dict, NSString *context)

Referenced by init.

Here is the caller graph for this function:

◆ makeShipEntriesMutable:

- (BOOL) makeShipEntriesMutable: (NSMutableDictionary*) ioData
implementation

Provided by category OOShipRegistry(OODataLoader).

Definition at line 698 of file OOShipRegistry.m.

698 :(NSMutableDictionary*)ioData
699{
700 NSString* shipKey = nil;
701 NSDictionary* shipEntry = nil;
702
703 foreach (shipKey, [ioData allKeys]) {
704 shipEntry = [ioData objectForKey:shipKey];
705 if (![shipEntry isKindOfClass:[NSDictionary class]]) {
706 OOLogERR(@"shipData.load.badEntry", @"the shipdata.plist entry \"%@\" is not a dictionary.", shipKey);
707 [ioData removeObjectForKey:shipKey];
708 } else {
709 shipEntry = [shipEntry mutableCopy];
710
711 [ioData setObject:shipEntry forKey:shipKey];
712 [shipEntry release];
713 }
714 }
715
716 return YES;
717}

◆ mergeShip:withParent:

- (NSMutableDictionary *) mergeShip: (NSDictionary*) child
withParent: (NSDictionary*) parent 
implementation

Provided by category OOShipRegistry(OODataLoader).

Definition at line 644 of file OOShipRegistry.m.

644 :(NSDictionary*)child withParent:(NSDictionary*)parent
645{
646 NSMutableDictionary* result = [[parent mutableCopy] autorelease];
647 if (result == nil)
648 return nil;
649
650 [result addEntriesFromDictionary:child];
651 [result removeObjectForKey:@"like_ship"];
652
653 // Certain properties cannot be inherited.
654 if ([child oo_stringForKey:@"display_name"] == nil)
655 [result removeObjectForKey:@"display_name"];
656 if ([child oo_stringForKey:@"is_template"] == nil)
657 [result removeObjectForKey:@"is_template"];
658
659 // Since both 'scanClass' and 'scan_class' are accepted as valid keys for the scanClass property,
660 // we may end up with conflicting scanClass and scan_class keys from like_ship relationships getting
661 // merged in the result dictionary. We want to always have the child overriding the parent setting
662 // and we do that by determining which of the two keys belongs to the child dictionary and removing
663 // the other one from the result - Nikos 20100512
664 if ([result oo_stringForKey:@"scan_class"] != nil && [result oo_stringForKey:@"scanClass"] != nil) {
665 if ([child oo_stringForKey:@"scanClass"] != nil)
666 [result removeObjectForKey:@"scan_class"];
667 else
668 [result removeObjectForKey:@"scanClass"];
669 }
670 // TODO: all normalised/non-normalised value name pairs need to be catered for. - Kaks 2010-05-13
671 if ([result oo_stringForKey:@"escort_role"] != nil && [result oo_stringForKey:@"escort-role"] != nil) {
672 if ([child oo_stringForKey:@"escort-role"] != nil)
673 [result removeObjectForKey:@"escort_role"];
674 else
675 [result removeObjectForKey:@"escort-role"];
676 }
677 if ([result oo_stringForKey:@"escort_ship"] != nil && [result oo_stringForKey:@"escort-ship"] != nil) {
678 if ([child oo_stringForKey:@"escort-ship"] != nil)
679 [result removeObjectForKey:@"escort_ship"];
680 else
681 [result removeObjectForKey:@"escort-ship"];
682 }
683 if ([result oo_stringForKey:@"is_carrier"] != nil && [result oo_stringForKey:@"isCarrier"] != nil) {
684 if ([child oo_stringForKey:@"isCarrier"] != nil)
685 [result removeObjectForKey:@"is_carrier"];
686 else
687 [result removeObjectForKey:@"isCarrier"];
688 }
689 if ([result oo_stringForKey:@"has_shipyard"] != nil && [result oo_stringForKey:@"hasShipyard"] != nil) {
690 if ([child oo_stringForKey:@"hasShipyard"] != nil)
691 [result removeObjectForKey:@"has_shipyard"];
692 else
693 [result removeObjectForKey:@"hasShipyard"];
694 }
695 return result;
696}

Referenced by OOShipRegistry(OODataLoader)::applyLikeShips:withKey:.

Here is the caller graph for this function:

◆ mergeShipRoles:forShipKey:intoProbabilityMap:

- (void) mergeShipRoles: (NSString*) roles
forShipKey: (NSString*) shipKey
intoProbabilityMap: (NSMutableDictionary*) probabilitySets 
implementation

Provided by category OOShipRegistry(OODataLoader).

Definition at line 1097 of file OOShipRegistry.m.

1097 :(NSString*)roles
1098 forShipKey:(NSString*)shipKey
1099 intoProbabilityMap:(NSMutableDictionary*)probabilitySets
1100{
1101 NSDictionary* rolesAndWeights = nil;
1102 NSString* role = nil;
1103 OOMutableProbabilitySet* probSet = nil;
1104
1105 /* probabilitySets is a dictionary whose keys are roles and whose values
1106 are mutable probability sets, whose values are ship keys.
1107
1108 When creating new ships Oolite looks up this probability map.
1109 To upgrade all soliton 'thargon' roles to 'EQ_THARGON' we need
1110 to swap these roles here.
1111 */
1112
1113 rolesAndWeights = OOParseRolesFromString(roles);
1114 // add default [shipKey] role
1115 NSMutableDictionary* mutable = [NSMutableDictionary dictionaryWithDictionary:rolesAndWeights];
1116 [mutable setObject:[NSNumber numberWithFloat:1.0] forKey:[[[NSString alloc] initWithFormat:@"[%@]", shipKey] autorelease]];
1117 rolesAndWeights = mutable;
1118
1119 id thargonValue = [rolesAndWeights objectForKey:@"thargon"];
1120 if (thargonValue != nil && [rolesAndWeights objectForKey:@"EQ_THARGON"] == nil) {
1121 NSMutableDictionary* mutable = [NSMutableDictionary dictionaryWithDictionary:rolesAndWeights];
1122 [mutable setObject:thargonValue forKey:@"EQ_THARGON"];
1123 rolesAndWeights = mutable;
1124 }
1125
1126 foreachkey(role, rolesAndWeights)
1127 {
1128 probSet = [probabilitySets objectForKey:role];
1129 if (probSet == nil) {
1131 [probabilitySets setObject:probSet forKey:role];
1132 }
1133
1134 [probSet setWeight:[rolesAndWeights oo_floatForKey:role] forObject:shipKey];
1135 }
1136}
NSDictionary * OOParseRolesFromString(NSString *string)
Definition OORoleSet.m:286
void setWeight:forObject:(float weight,[forObject] id object)

Referenced by OOShipRegistry(OODataLoader)::buildRoleProbabilitySets.

Here is the caller graph for this function:

◆ playerShipKeys

- (NSArray *) playerShipKeys

Definition at line 228 of file OOShipRegistry.m.

229{
230 return _playerShips;
231}

References _playerShips, and playerShipKeys.

Referenced by playerShipKeys, and Universe::shipsForSaleForSystem:withTL:atTime:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ probabilitySetForRole:

- (OOProbabilitySet *) probabilitySetForRole: (NSString*) role

Definition at line 213 of file OOShipRegistry.m.

213 :(NSString*)role
214{
215 if (role == nil)
216 return nil;
217 return [_probabilitySets objectForKey:role];
218}

References nil.

Referenced by OOShipRegistry(OOConveniences)::randomShipKeyForRole:, Universe::randomShipKeyForRoleRespectingConditions:, and OOShipRegistry(OOConveniences)::shipKeysWithRole:.

Here is the caller graph for this function:

◆ randomShipKeyForRole:

- (NSString *) randomShipKeyForRole: (NSString*) role

Provided by category OOShipRegistry(OOConveniences).

Definition at line 252 of file OOShipRegistry.m.

252 :(NSString*)role
253{
254 return [[self probabilitySetForRole:role] randomObject];
255}

Referenced by Universe::randomShipKeyForRoleRespectingConditions:, and Universe::setDockingClearanceProtocolActive:.

Here is the caller graph for this function:

◆ release

- (void) release
implementation

Provided by category OOShipRegistry(Singleton).

Definition at line 1544 of file OOShipRegistry.m.

1545{
1546}

◆ reload

+ (void) reload

Definition at line 128 of file OOShipRegistry.m.

129{
130 if (sSingleton != nil) {
131 /* CIM: 'release' doesn't work - the class definition
132 * overrides it, so this leaks memory. Needs a proper reset
133 * method for reloading the ship registry data instead */
135 sSingleton = nil;
136
137 (void)[self sharedRegistry];
138 }
139}
OOShipRegistry * sharedRegistry()

References nil, OONullTexture::release, reload, sharedRegistry, and sSingleton.

Referenced by Universe::reinitAndShowDemo:, and reload.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeUnusableEntries:shipMode:

- (BOOL) removeUnusableEntries: (NSMutableDictionary*) ioData
shipMode: (BOOL) shipMode 
implementation

Provided by category OOShipRegistry(OODataLoader).

Definition at line 908 of file OOShipRegistry.m.

908 :(NSMutableDictionary*)ioData shipMode:(BOOL)shipMode
909{
910 NSString* shipKey = nil;
911 NSMutableDictionary* shipEntry = nil;
912 BOOL remove;
913 NSString* modelName = nil;
914
915 // Clean out invalid entries and templates. (Iterates over a copy of keys since it mutates the dictionary.)
916 foreach (shipKey, [ioData allKeys]) {
917 shipEntry = [ioData objectForKey:shipKey];
918 remove = NO;
919
920 if ([shipEntry oo_boolForKey:@"is_template"] || [shipEntry oo_boolForKey:@"_oo_deferred_remove"])
921 remove = YES;
922 else if (shipMode && [[shipEntry oo_stringForKey:@"roles"] length] == 0 && ![shipEntry oo_boolForKey:@"_oo_is_subentity"] && ![shipEntry oo_boolForKey:@"_oo_is_effect"]) {
923 OOLogERR(@"shipData.load.error", @"the shipdata.plist entry \"%@\" specifies no %@.", shipKey, @"roles");
924 remove = YES;
925 OOStandardsError(@"Error in shipdata.plist");
926 } else {
927 modelName = [shipEntry oo_stringForKey:@"model"];
928 if (shipMode && [modelName length] == 0) {
929 OOLogERR(@"shipData.load.error", @"the shipdata.plist entry \"%@\" specifies no %@.", shipKey, @"model");
930 OOStandardsError(@"Error in shipdata.plist");
931 remove = YES;
932 } else if ([modelName length] != 0 && [ResourceManager pathForFileNamed:modelName inFolder:@"Models"] == nil) {
933 OOLogERR(@"shipData.load.error", @"the shipdata.plist entry \"%@\" specifies non-existent model \"%@\".", shipKey, modelName);
934 OOStandardsError(@"Error in shipdata.plist");
935 remove = YES;
936 }
937 }
938 if (remove)
939 [ioData removeObjectForKey:shipKey];
940 }
941
942 return YES;
943}

◆ retain

- (id) retain
implementation

Provided by category OOShipRegistry(Singleton).

Definition at line 1534 of file OOShipRegistry.m.

1535{
1536 return self;
1537}

◆ retainCount

- (NSUInteger) retainCount
implementation

Provided by category OOShipRegistry(Singleton).

Definition at line 1539 of file OOShipRegistry.m.

1540{
1541 return UINT_MAX;
1542}

◆ sanitizeConditions:

- (BOOL) sanitizeConditions: (NSMutableDictionary*) ioData
implementation

Provided by category OOShipRegistry(OODataLoader).

Definition at line 949 of file OOShipRegistry.m.

949 :(NSMutableDictionary*)ioData
950{
951 NSString* shipKey = nil;
952 NSMutableDictionary* shipEntry = nil;
953 NSMutableDictionary* mutableShipyard = nil;
954 NSArray* conditions = nil;
955 NSArray* hasShipyard = nil;
956 NSArray* shipyardConditions = nil;
957 NSString* condition_script = nil;
958 NSString* shipyard_condition_script = nil;
959
960 NSMutableArray* conditionScripts = [[NSMutableArray alloc] init];
961
962 foreach (shipKey, [ioData allKeys]) {
963 shipEntry = [ioData objectForKey:shipKey];
964 conditions = [shipEntry objectForKey:@"conditions"];
965 condition_script = [shipEntry oo_stringForKey:@"condition_script"];
966 if (condition_script != nil) {
967 if (![conditionScripts containsObject:condition_script]) {
968 [conditionScripts addObject:condition_script];
969 }
970 }
971
972 hasShipyard = [shipEntry objectForKey:@"has_shipyard"];
973 if (![hasShipyard isKindOfClass:[NSArray class]])
974 hasShipyard = nil; // May also be fuzzy boolean
975 if (hasShipyard == nil) {
976 hasShipyard = [shipEntry objectForKey:@"hasShipyard"];
977 if (![hasShipyard isKindOfClass:[NSArray class]])
978 hasShipyard = nil; // May also be fuzzy boolean
979 }
980 shipyardConditions = [[shipEntry oo_dictionaryForKey:@"_oo_shipyard"] objectForKey:@"conditions"];
981 shipyard_condition_script = [[shipEntry oo_dictionaryForKey:@"_oo_shipyard"] oo_stringForKey:@"condition_script"];
982 if (shipyard_condition_script != nil) {
983 if (![conditionScripts containsObject:shipyard_condition_script]) {
984 [conditionScripts addObject:shipyard_condition_script];
985 }
986 }
987
988 if (conditions == nil && hasShipyard && shipyardConditions == nil)
989 continue;
990
991 if (conditions != nil) {
992 OOStandardsDeprecated([NSString stringWithFormat:@"The 'conditions' key is deprecated in shipdata entry %@", shipKey]);
993 if (!OOEnforceStandards()) {
994 if ([conditions isKindOfClass:[NSArray class]]) {
995 conditions = OOSanitizeLegacyScriptConditions(conditions, [NSString stringWithFormat:@"<shipdata.plist entry \"%@\">", shipKey]);
996 } else {
997 OOLogWARN(@"shipdata.load.warning", @"conditions for shipdata.plist entry \"%@\" are not an array, ignoring.", shipKey);
998 conditions = nil;
999 }
1000
1001 if (conditions != nil) {
1002 [shipEntry setObject:conditions forKey:@"conditions"];
1003 } else {
1004 [shipEntry removeObjectForKey:@"conditions"];
1005 }
1006 }
1007 }
1008
1009 if (hasShipyard != nil) {
1010 hasShipyard = OOSanitizeLegacyScriptConditions(hasShipyard, [NSString stringWithFormat:@"<shipdata.plist entry \"%@\" hasShipyard conditions>", shipKey]);
1011 OOStandardsDeprecated([NSString stringWithFormat:@"Use of legacy script conditions in the 'has_shipyard' key is deprecated in shipyard entry %@", shipKey]);
1012 if (!OOEnforceStandards()) {
1013 if (hasShipyard != nil) {
1014 [shipEntry setObject:hasShipyard forKey:@"has_shipyard"];
1015 } else {
1016 [shipEntry removeObjectForKey:@"hasShipyard"];
1017 [shipEntry removeObjectForKey:@"has_shipyard"];
1018 }
1019 }
1020 }
1021
1022 if (shipyardConditions != nil) {
1023 OOStandardsDeprecated([NSString stringWithFormat:@"The 'conditions' key is deprecated in shipyard entry %@", shipKey]);
1024 if (!OOEnforceStandards()) {
1025 mutableShipyard = [[[shipEntry oo_dictionaryForKey:@"_oo_shipyard"] mutableCopy] autorelease];
1026
1027 if ([shipyardConditions isKindOfClass:[NSArray class]]) {
1028 shipyardConditions = OOSanitizeLegacyScriptConditions(shipyardConditions, [NSString stringWithFormat:@"<shipyard.plist entry \"%@\">", shipKey]);
1029 } else {
1030 OOLogWARN(@"shipdata.load.warning", @"conditions for shipyard.plist entry \"%@\" are not an array, ignoring.", shipKey);
1031 shipyardConditions = nil;
1032 }
1033
1034 if (shipyardConditions != nil) {
1035 [mutableShipyard setObject:shipyardConditions forKey:@"conditions"];
1036 } else {
1037 [mutableShipyard removeObjectForKey:@"conditions"];
1038 }
1039
1040 [shipEntry setObject:mutableShipyard forKey:@"_oo_shipyard"];
1041 }
1042 }
1043 }
1044
1045 [[OOCacheManager sharedCache] setObject:conditionScripts forKey:@"ship conditions" inCache:@"condition scripts"];
1046 [conditionScripts release];
1047
1048 return YES;
1049}
NSArray * OOSanitizeLegacyScriptConditions(NSArray *conditions, NSString *context)

◆ setShipInfoForKey:with:

- (void) setShipInfoForKey: (NSString*) key
with: (NSDictionary*) newShipData 

Definition at line 195 of file OOShipRegistry.m.

195 :(NSString*)key with:(NSDictionary*)newShipData
196{
197 NSMutableDictionary* mutableDict = [NSMutableDictionary dictionaryWithDictionary:_shipData];
198 [mutableDict setObject:OODeepCopy(newShipData) forKey:key];
200 _shipData = [[NSDictionary dictionaryWithDictionary:mutableDict] retain];
201}

References _shipData, and DESTROY.

Referenced by ShipStaticSetShipDataForKey(), and ShipStaticSetShipDataForKey().

Here is the caller graph for this function:

◆ sharedRegistry

+ (OOShipRegistry *) sharedRegistry

Definition at line 119 of file OOShipRegistry.m.

120{
121 if (sSingleton == nil) {
122 sSingleton = [[self alloc] init];
123 }
124
125 return sSingleton;
126}

References nil, sharedRegistry, and sSingleton.

Referenced by PlayerEntity::availableFacings, Universe::canInstantiateShip:, ShipEntity::equipmentValidToAdd:whileLoading:inContext:, Universe::initWithGameView:, PlayerEntity(LoadSave)::loadPlayerFromFile:asNew:, Universe::maxCargoForShip:, Universe::newDockWithName:andScaleFactor:, Universe::newShipWithName:usePlayerProxy:isSubentity:andScaleFactor:, Universe::newShipWithRole:, Universe::newVisualEffectWithName:, Universe::randomShipKeyForRoleRespectingConditions:, Universe::reinitAndShowDemo:, reload, PlayerEntity::renovationFactor, PlayerEntity(Contracts)::replaceShipWithNamedShip:, PlayerEntity::resetHud, PlayerEntity::setCommanderDataFromDictionary:, PlayerEntity::setDefaultCustomViews, Universe::setDockingClearanceProtocolActive:, PlayerEntity::setGuiToEquipShipScreen:selectingFacingFor:, Universe(OOPrivate)::setUpInitialUniverse, Universe::setupIntroFirstGo:, PlayerEntity::setWeaponMount:toWeapon:inContext:, sharedRegistry, ShipEntity(LoadRestore)::shipRestoredFromDictionary:useFallback:context:, Universe::shipsForSaleForSystem:withTL:atTime:, ShipStaticKeys(), ShipStaticKeys(), ShipStaticKeysForRole(), ShipStaticKeysForRole(), ShipStaticRoles(), ShipStaticRoles(), ShipStaticSetShipDataForKey(), ShipStaticSetShipDataForKey(), ShipStaticShipDataForKey(), ShipStaticShipDataForKey(), PlayerEntity(OOLoadSavePrivate)::showCommanderShip:, PlayerEntity::showShipModelWithKey:shipData:personality:factorX:factorY:factorZ:inContext:, ShipEntity(LoadRestoreInternal)::simplifyShipdata:andGetDeletes:, Universe::spawnShip:, StationAddShipToShipyard(), StationAddShipToShipyard(), and Universe::tradeInValueForCommanderDictionary:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ shipInfoForKey:

◆ shipIsBallTurretForKey:inShipData:

- (BOOL) shipIsBallTurretForKey: (NSString*) shipKey
inShipData: (NSDictionary*) shipData 
implementation

Provided by category OOShipRegistry(OODataLoader).

Definition at line 1486 of file OOShipRegistry.m.

1486 :(NSString*)shipKey inShipData:(NSDictionary*)shipData
1487{
1488 // Test for presence of setup_actions containing initialiseTurret.
1489 NSArray* setupActions = nil;
1490 NSString* action = nil;
1491
1492 setupActions = [[shipData oo_dictionaryForKey:shipKey] oo_arrayForKey:@"setup_actions"];
1493
1494 foreach (action, setupActions) {
1495 if ([[ScanTokensFromString(action) objectAtIndex:0] isEqualToString:@"initialiseTurret"])
1496 return YES;
1497 }
1498
1499 if ([shipKey isEqualToString:@"ballturret"]) {
1500 // compatibility for OXPs using old subentity declarations and the
1501 // core turret entity
1502 return YES;
1503 }
1504
1505 return NO;
1506}
NSMutableArray * ScanTokensFromString(NSString *values)

Referenced by OOShipRegistry(OODataLoader)::translateOldStandardBasicSubentityDeclaration:forShip:shipData:fatalError:.

Here is the caller graph for this function:

◆ shipKeys

- (NSArray *) shipKeys

Provided by category OOShipRegistry(OOConveniences).

Definition at line 237 of file OOShipRegistry.m.

238{
239 return [_shipData allKeys];
240}

Referenced by ShipStaticKeys(), and ShipStaticKeys().

Here is the caller graph for this function:

◆ shipKeysWithRole:

- (NSArray *) shipKeysWithRole: (NSString*) role

Provided by category OOShipRegistry(OOConveniences).

Definition at line 247 of file OOShipRegistry.m.

247 :(NSString*)role
248{
249 return [[self probabilitySetForRole:role] allObjects];
250}

Referenced by ShipStaticKeysForRole(), and ShipStaticKeysForRole().

Here is the caller graph for this function:

◆ shipRoles

- (NSArray *) shipRoles

Provided by category OOShipRegistry(OOConveniences).

Definition at line 242 of file OOShipRegistry.m.

243{
244 return [_probabilitySets allKeys];
245}

Referenced by ShipStaticRoles(), and ShipStaticRoles().

Here is the caller graph for this function:

◆ shipyardInfoForKey:

- (NSDictionary *) shipyardInfoForKey: (NSString*) key

Definition at line 208 of file OOShipRegistry.m.

208 :(NSString*)key
209{
210 return [[self shipInfoForKey:key] objectForKey:@"_oo_shipyard"];
211}

References shipInfoForKey:.

Referenced by PlayerEntity::availableFacings, ShipEntity::equipmentValidToAdd:whileLoading:inContext:, PlayerEntity::renovationFactor, PlayerEntity(Contracts)::replaceShipWithNamedShip:, PlayerEntity::setCommanderDataFromDictionary:, PlayerEntity::setGuiToEquipShipScreen:selectingFacingFor:, PlayerEntity::setWeaponMount:toWeapon:inContext:, Universe::shipsForSaleForSystem:withTL:atTime:, StationAddShipToShipyard(), StationAddShipToShipyard(), and Universe::tradeInValueForCommanderDictionary:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stripPrivateKeys:

- (BOOL) stripPrivateKeys: (NSMutableDictionary*) ioData
implementation

Provided by category OOShipRegistry(OODataLoader).

Definition at line 747 of file OOShipRegistry.m.

747 :(NSMutableDictionary*)ioData
748{
749 NSString* shipKey = nil;
750 NSMutableDictionary* shipEntry = nil;
751 NSEnumerator* attrKeyEnum = nil;
752 NSString* attrKey = nil;
753
754 foreachkey(shipKey, ioData)
755 {
756 shipEntry = [ioData objectForKey:shipKey];
757
758 for (attrKeyEnum = [shipEntry keyEnumerator]; (attrKey = [attrKeyEnum nextObject]);) {
759 if ([attrKey hasPrefix:@"_oo_"]) {
760 [shipEntry removeObjectForKey:attrKey];
761 }
762 }
763 }
764
765 return YES;
766}

◆ translateOldStandardBasicSubentityDeclaration:forShip:shipData:fatalError:

- (NSDictionary *) translateOldStandardBasicSubentityDeclaration: (NSArray*) tokens
forShip: (NSString*) shipKey
shipData: (NSDictionary*) shipData
fatalError: (BOOL*) outFatalError 
implementation

Provided by category OOShipRegistry(OODataLoader).

Definition at line 1251 of file OOShipRegistry.m.

1251 :(NSArray*)tokens
1252 forShip:(NSString*)shipKey
1253 shipData:(NSDictionary*)shipData
1254 fatalError:(BOOL*)outFatalError
1255{
1256 NSString* subentityKey = nil;
1257 Vector position;
1258 Quaternion orientation;
1259 NSMutableDictionary* result = nil;
1260 BOOL isTurret, isDock = NO;
1261
1262 subentityKey = [tokens oo_stringAtIndex:0];
1263
1264 isTurret = [self shipIsBallTurretForKey:subentityKey inShipData:shipData];
1265
1266 position.x = [tokens oo_floatAtIndex:1];
1267 position.y = [tokens oo_floatAtIndex:2];
1268 position.z = [tokens oo_floatAtIndex:3];
1269
1270 orientation.w = [tokens oo_floatAtIndex:4];
1271 orientation.x = [tokens oo_floatAtIndex:5];
1272 orientation.y = [tokens oo_floatAtIndex:6];
1273 orientation.z = [tokens oo_floatAtIndex:7];
1274
1275 if (orientation.w == 0 && orientation.x == 0 && orientation.y == 0 && orientation.z == 0) {
1276 orientation.w = 1; // avoid dividing by zero.
1277 OOLogWARN(@"shipData.load.error", @"The ship %@ has an undefined orientation for its %@ subentity. Setting it now at (1,0,0,0)", shipKey, subentityKey);
1278 }
1279
1280 quaternion_normalize(&orientation);
1281
1282 if (!isTurret) {
1283 isDock = [subentityKey rangeOfString:@"dock"].location != NSNotFound;
1284 }
1285
1286 result = [NSMutableDictionary dictionaryWithCapacity:5];
1287 [result setObject:isTurret ? @"ball_turret" : @"standard" forKey:@"type"];
1288 [result setObject:subentityKey forKey:@"subentity_key"];
1289 [result oo_setVector:position forKey:@"position"];
1290 [result oo_setQuaternion:orientation forKey:@"orientation"];
1291 if (isDock)
1292 [result oo_setBool:YES forKey:@"is_dock"];
1293
1294 OOLog(@"shipData.translateSubentity.standard", @"Translated subentity declaration \"%@\" to %@", [tokens componentsJoinedByString:@" "], result);
1295
1296 return [[result copy] autorelease];
1297}
struct Quaternion Quaternion
OOINLINE void quaternion_normalize(Quaternion *quat) NONNULL_FUNC ALWAYS_INLINE_FUNC
struct Vector Vector
OOScalar w
OOScalar x
OOScalar y
OOScalar z
OOScalar x
Definition OOVector.h:32
OOScalar y
Definition OOVector.h:33
OOScalar z
Definition OOVector.h:34

Referenced by OOShipRegistry(OODataLoader)::translateOldStyleSubentityDeclaration:forShip:shipData:fatalError:.

Here is the caller graph for this function:

◆ translateOldStyleFlasherDeclaration:forShip:fatalError:

- (NSDictionary *) translateOldStyleFlasherDeclaration: (NSArray*) tokens
forShip: (NSString*) shipKey
fatalError: (BOOL*) outFatalError 
implementation

Provided by category OOShipRegistry(OODataLoader).

Definition at line 1217 of file OOShipRegistry.m.

1217 :(NSArray*)tokens
1218 forShip:(NSString*)shipKey
1219 fatalError:(BOOL*)outFatalError
1220{
1221 Vector position;
1222 float size, frequency, phase, hue;
1223 NSDictionary* colorDict = nil;
1224 NSDictionary* result = nil;
1225
1226 position.x = [tokens oo_floatAtIndex:1];
1227 position.y = [tokens oo_floatAtIndex:2];
1228 position.z = [tokens oo_floatAtIndex:3];
1229
1230 hue = [tokens oo_floatAtIndex:4];
1231 frequency = [tokens oo_floatAtIndex:5];
1232 phase = [tokens oo_floatAtIndex:6];
1233 size = [tokens oo_floatAtIndex:7];
1234
1235 colorDict = [NSDictionary dictionaryWithObject:[NSNumber numberWithFloat:hue] forKey:@"hue"];
1236
1237 result = [NSDictionary dictionaryWithObjectsAndKeys:
1238 @"flasher", @"type",
1239 OOPropertyListFromVector(position), @"position",
1240 [NSArray arrayWithObject:colorDict], @"colors",
1241 [NSNumber numberWithFloat:frequency], @"frequency",
1242 [NSNumber numberWithFloat:phase], @"phase",
1243 [NSNumber numberWithFloat:size], @"size",
1244 nil];
1245
1246 OOLog(@"shipData.translateSubentity.flasher", @"Translated flasher declaration \"%@\" to %@", [tokens componentsJoinedByString:@" "], result);
1247
1248 return result;
1249}
voidpf void uLong size
Definition ioapi.h:126

Referenced by OOShipRegistry(OODataLoader)::translateOldStyleSubentityDeclaration:forShip:shipData:fatalError:.

Here is the caller graph for this function:

◆ translateOldStyleSubentityDeclaration:forShip:shipData:fatalError:

- (NSDictionary *) translateOldStyleSubentityDeclaration: (NSString*) declaration
forShip: (NSString*) shipKey
shipData: (NSDictionary*) shipData
fatalError: (BOOL*) outFatalError 
implementation

Provided by category OOShipRegistry(OODataLoader).

Definition at line 1180 of file OOShipRegistry.m.

1180 :(NSString*)declaration
1181 forShip:(NSString*)shipKey
1182 shipData:(NSDictionary*)shipData
1183 fatalError:(BOOL*)outFatalError
1184{
1185 NSArray* tokens = nil;
1186 NSString* subentityKey = nil;
1187 BOOL isFlasher;
1188
1189 tokens = ScanTokensFromString(declaration);
1190
1191 subentityKey = [tokens objectAtIndex:0];
1192 isFlasher = [subentityKey isEqualToString:@"*FLASHER*"];
1193
1194 // Sanity check: require eight tokens.
1195 if ([tokens count] != 8) {
1196 if (!isFlasher) {
1197 OOLogERR(@"shipData.load.error.badSubentity", @"the shipdata.plist entry \"%@\" has a broken subentity definition \"%@\" (should have 8 tokens, has %zu).", shipKey, subentityKey, [tokens count]);
1198 *outFatalError = YES;
1199 } else {
1200 OOLogWARN(@"shipData.load.warning.badFlasher", @"the shipdata.plist entry \"%@\" has a broken flasher definition (should have 8 tokens, has %zu). This flasher will be ignored.", shipKey, [tokens count]);
1201 }
1202 return nil;
1203 }
1204
1205 if (isFlasher) {
1206 return [self translateOldStyleFlasherDeclaration:tokens
1207 forShip:shipKey
1208 fatalError:outFatalError];
1209 } else {
1210 return [self translateOldStandardBasicSubentityDeclaration:tokens
1211 forShip:shipKey
1212 shipData:shipData
1213 fatalError:outFatalError];
1214 }
1215}

Referenced by OOShipRegistry(OODataLoader)::canonicalizeSubentityDeclaration:forShip:shipData:fatalError:.

Here is the caller graph for this function:

◆ validateNewStyleFlasherDeclaration:forShip:fatalError:

- (NSDictionary *) validateNewStyleFlasherDeclaration: (NSDictionary*) declaration
forShip: (NSString*) shipKey
fatalError: (BOOL*) outFatalError 
implementation

Provided by category OOShipRegistry(OODataLoader).

Definition at line 1320 of file OOShipRegistry.m.

1320 :(NSDictionary*)declaration
1321 forShip:(NSString*)shipKey
1322 fatalError:(BOOL*)outFatalError
1323{
1324 NSMutableDictionary* result = nil;
1325 Vector position = kZeroVector;
1326 NSArray* colors = nil;
1327 id colorDesc = nil;
1328 float size, frequency, phase, brightfraction;
1329 BOOL initiallyOn;
1330
1331#define kDefaultFlasherColor @"redColor"
1332
1333 // "Validate" is really "clean up", since all values have defaults.
1334 colors = [declaration oo_arrayForKey:@"colors"];
1335 if ([colors count] == 0) {
1336 colorDesc = [declaration objectForKey:@"color"];
1337 if (colorDesc == nil)
1338 colorDesc = kDefaultFlasherColor;
1339 if ([colorDesc isKindOfClass:[NSArray class]]) {
1340 // an easy made error is adding an array to "color" instead of "colors"
1341 OOLogWARN(@"shipData.load.warning.flasher.badColor", @"changing flasher for ship %@ from a color to a colors definition.", shipKey);
1342 colors = colorDesc;
1343 } else {
1344 colors = [NSArray arrayWithObject:colorDesc];
1345 }
1346 }
1347
1348 // Validate colours.
1349 NSMutableArray* validColors = [NSMutableArray arrayWithCapacity:[colors count]];
1350 foreach (colorDesc, colors) {
1351 OOColor* color = [OOColor colorWithDescription:colorDesc];
1352 if (color != nil) {
1353 [validColors addObject:[color normalizedArray]];
1354 } else {
1355 OOLogWARN(@"shipdata.load.warning.flasher.badColor", @"skipping invalid colour specifier for flasher for ship %@.", shipKey);
1356 }
1357 }
1358 // Ensure there's at least one.
1359 if ([validColors count] == 0) {
1360 [validColors addObject:kDefaultFlasherColor];
1361 }
1362 colors = validColors;
1363
1364 position = [declaration oo_vectorForKey:@"position"];
1365
1366 size = [declaration oo_floatForKey:@"size" defaultValue:8.0];
1367
1368 if (size <= 0) {
1369 OOLogWARN(@"shipData.load.warning.flasher.badSize", @"skipping flasher of invalid size %g for ship %@.", size, shipKey);
1370 return nil;
1371 }
1372
1373 brightfraction = [declaration oo_floatForKey:@"bright_fraction" defaultValue:0.5];
1374 if (brightfraction < 0.0 || brightfraction > 1.0) {
1375 OOLogWARN(@"shipData.load.warning.flasher.badFraction", @"skipping flasher of invalid bright fraction %g for ship %@.", brightfraction, shipKey);
1376 return nil;
1377 }
1378
1379 frequency = [declaration oo_floatForKey:@"frequency" defaultValue:2.0];
1380 phase = [declaration oo_floatForKey:@"phase" defaultValue:0.0];
1381 initiallyOn = [declaration oo_boolForKey:@"initially_on" defaultValue:YES];
1382
1383 result = [NSMutableDictionary dictionaryWithCapacity:8];
1384 [result setObject:@"flasher" forKey:@"type"];
1385 [result setObject:colors forKey:@"colors"];
1386 [result oo_setVector:position forKey:@"position"];
1387 [result setObject:[NSNumber numberWithFloat:size] forKey:@"size"];
1388 [result setObject:[NSNumber numberWithFloat:frequency] forKey:@"frequency"];
1389 if (phase != 0)
1390 [result setObject:[NSNumber numberWithFloat:phase] forKey:@"phase"];
1391 [result setObject:[NSNumber numberWithFloat:brightfraction] forKey:@"bright_fraction"];
1392 [result setObject:[NSNumber numberWithBool:initiallyOn] forKey:@"initially_on"];
1393
1394 return [[result copy] autorelease];
1395}
#define kDefaultFlasherColor
const Vector kZeroVector
Definition OOVector.m:27
OOColor * colorWithDescription:(id description)
Definition OOColor.m:135
NSArray * normalizedArray()
Definition OOColor.m:465

Referenced by OOShipRegistry(OODataLoader)::validateNewStyleSubentityDeclaration:forShip:fatalError:.

Here is the caller graph for this function:

◆ validateNewStyleStandardSubentityDeclaration:forShip:fatalError:

- (NSDictionary *) validateNewStyleStandardSubentityDeclaration: (NSDictionary*) declaration
forShip: (NSString*) shipKey
fatalError: (BOOL*) outFatalError 
implementation

Provided by category OOShipRegistry(OODataLoader).

Definition at line 1397 of file OOShipRegistry.m.

1397 :(NSDictionary*)declaration
1398 forShip:(NSString*)shipKey
1399 fatalError:(BOOL*)outFatalError
1400{
1401 NSMutableDictionary* result = nil;
1402 NSString* subentityKey = nil;
1403 Vector position = kZeroVector;
1404 Quaternion orientation = kIdentityQuaternion;
1405 BOOL isTurret;
1406 BOOL isDock = NO;
1407 float fireRate = -1.0f; // out of range constants
1408 float weaponRange = -1.0f;
1409 float weaponEnergy = -1.0f;
1410 NSDictionary* scriptInfo = nil;
1411
1412 subentityKey = [declaration objectForKey:@"subentity_key"];
1413 if (subentityKey == nil) {
1414 OOLogERR(@"shipData.load.error.badSubentity", @"subentity declaration for ship %@ specifies no subentity_key.", shipKey);
1415 *outFatalError = YES;
1416 return nil;
1417 }
1418
1419 isTurret = [[declaration oo_stringForKey:@"type"] isEqualToString:@"ball_turret"];
1420 if (isTurret) {
1421 fireRate = [declaration oo_floatForKey:@"fire_rate" defaultValue:-1.0f];
1422 if (fireRate < 0.25f && fireRate >= 0.0f) {
1423 OOLogWARN(@"shipData.load.warning.turret.badFireRate", @"ball turret fire rate of %g for subentity of ship %@ is invalid, using 0.25.", fireRate, shipKey);
1424 fireRate = 0.25f;
1425 }
1426 weaponRange = [declaration oo_floatForKey:@"weapon_range" defaultValue:-1.0f];
1427 if (weaponRange > TURRET_SHOT_RANGE * COMBAT_WEAPON_RANGE_FACTOR) {
1428 OOLogWARN(@"shipData.load.warning.turret.badWeaponRange", @"ball turret weapon range of %g for subentity of ship %@ is too high, using %.1f.", weaponRange, shipKey, TURRET_SHOT_RANGE * COMBAT_WEAPON_RANGE_FACTOR);
1429 weaponRange = TURRET_SHOT_RANGE * COMBAT_WEAPON_RANGE_FACTOR; // approx. range of primary plasma canon.
1430 }
1431
1432 weaponEnergy = [declaration oo_floatForKey:@"weapon_energy" defaultValue:-1.0f];
1433 if (weaponEnergy > 100.0f)
1434
1435 {
1436 OOLogWARN(@"shipData.load.warning.turret.badWeaponEnergy", @"ball turret weapon energy of %g for subentity of ship %@ is too high, using 100.", weaponEnergy, shipKey);
1437 weaponEnergy = 100.0f;
1438 }
1439 } else {
1440 isDock = [declaration oo_boolForKey:@"is_dock"];
1441 }
1442
1443 position = [declaration oo_vectorForKey:@"position"];
1444 orientation = [declaration oo_quaternionForKey:@"orientation"];
1445 quaternion_normalize(&orientation);
1446
1447 scriptInfo = [declaration oo_dictionaryForKey:@"script_info"];
1448
1449 result = [NSMutableDictionary dictionaryWithCapacity:10];
1450 [result setObject:isTurret ? @"ball_turret" : @"standard" forKey:@"type"];
1451 [result setObject:subentityKey forKey:@"subentity_key"];
1452 [result oo_setVector:position forKey:@"position"];
1453 [result oo_setQuaternion:orientation forKey:@"orientation"];
1454 if (isDock) {
1455 [result oo_setBool:YES forKey:@"is_dock"];
1456
1457 NSString* docklabel = [declaration oo_stringForKey:@"dock_label" defaultValue:@"the docking bay"];
1458 [result setObject:docklabel forKey:@"dock_label"];
1459
1460 BOOL dockable = [declaration oo_boolForKey:@"allow_docking" defaultValue:YES];
1461 BOOL playerdockable = [declaration oo_boolForKey:@"disallowed_docking_collides" defaultValue:NO];
1462 BOOL undockable = [declaration oo_boolForKey:@"allow_launching" defaultValue:YES];
1463
1464 [result oo_setBool:dockable forKey:@"allow_docking"];
1465 [result oo_setBool:playerdockable forKey:@"disallowed_docking_collides"];
1466 [result oo_setBool:undockable forKey:@"allow_launching"];
1467 }
1468
1469 if (isTurret) {
1470 // default constants are defined and set in shipEntity
1471 if (fireRate > 0)
1472 [result oo_setFloat:fireRate forKey:@"fire_rate"];
1473 if (weaponRange >= 0)
1474 [result oo_setFloat:weaponRange forKey:@"weapon_range"];
1475 if (weaponEnergy >= 0)
1476 [result oo_setFloat:weaponEnergy forKey:@"weapon_energy"];
1477 }
1478
1479 if (scriptInfo != nil) {
1480 [result setObject:scriptInfo forKey:@"script_info"];
1481 }
1482
1483 return [[result copy] autorelease];
1484}
const Quaternion kIdentityQuaternion
#define TURRET_SHOT_RANGE
Definition ShipEntity.h:84
#define COMBAT_WEAPON_RANGE_FACTOR
Definition ShipEntity.h:60

Referenced by OOShipRegistry(OODataLoader)::validateNewStyleSubentityDeclaration:forShip:fatalError:.

Here is the caller graph for this function:

◆ validateNewStyleSubentityDeclaration:forShip:fatalError:

- (NSDictionary *) validateNewStyleSubentityDeclaration: (NSDictionary*) declaration
forShip: (NSString*) shipKey
fatalError: (BOOL*) outFatalError 
implementation

Provided by category OOShipRegistry(OODataLoader).

Definition at line 1299 of file OOShipRegistry.m.

1299 :(NSDictionary*)declaration
1300 forShip:(NSString*)shipKey
1301 fatalError:(BOOL*)outFatalError
1302{
1303 NSString* type = nil;
1304
1305 type = [declaration oo_stringForKey:@"type"];
1306 if (type == nil)
1307 type = @"standard";
1308
1309 if ([type isEqualToString:@"flasher"]) {
1310 return [self validateNewStyleFlasherDeclaration:declaration forShip:shipKey fatalError:outFatalError];
1311 } else if ([type isEqualToString:@"standard"] || [type isEqualToString:@"ball_turret"]) {
1312 return [self validateNewStyleStandardSubentityDeclaration:declaration forShip:shipKey fatalError:outFatalError];
1313 } else {
1314 OOLogERR(@"shipData.load.error.badSubentity", @"subentity declaration for ship %@ does not declare a valid type (must be standard, flasher or ball_turret).", shipKey);
1315 *outFatalError = YES;
1316 return nil;
1317 }
1318}

Referenced by OOShipRegistry(OODataLoader)::canonicalizeSubentityDeclaration:forShip:shipData:fatalError:.

Here is the caller graph for this function:

Member Data Documentation

◆ _demoShips

- (NSArray*) _demoShips
private

Definition at line 38 of file OOShipRegistry.h.

Referenced by init.

◆ _effectData

- (NSDictionary*) _effectData
private

Definition at line 37 of file OOShipRegistry.h.

Referenced by init.

◆ _playerShips

- (NSArray*) _playerShips
private

Definition at line 39 of file OOShipRegistry.h.

Referenced by init, and playerShipKeys.

◆ _probabilitySets

- (NSDictionary*) _probabilitySets
private

Definition at line 40 of file OOShipRegistry.h.

Referenced by init.

◆ _shipData

- (NSDictionary*) _shipData
private

Definition at line 36 of file OOShipRegistry.h.

Referenced by init, and setShipInfoForKey:with:.


The documentation for this class was generated from the following files: