Oolite
Loading...
Searching...
No Matches
OOShipRegistry.m
Go to the documentation of this file.
1/*
2
3OOShipRegistry.m
4
5
6Copyright (C) 2008-2013 Jens Ayton and contributors
7
8Permission is hereby granted, free of charge, to any person obtaining a copy
9of this software and associated documentation files (the "Software"), to deal
10in the Software without restriction, including without limitation the rights
11to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12copies of the Software, and to permit persons to whom the Software is
13furnished to do so, subject to the following conditions:
14
15The above copyright notice and this permission notice shall be included in all
16copies or substantial portions of the Software.
17
18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24SOFTWARE.
25
26*/
27
28#import "OOShipRegistry.h"
29#import "GameController.h"
31#import "OOCacheManager.h"
33#import "OOColor.h"
34#import "OODeepCopy.h"
35#import "OOJSScript.h"
37#import "OOMesh.h"
38#import "OOProbabilitySet.h"
39#import "OORoleSet.h"
41#import "OOStringExpander.h"
42#import "OOStringParsing.h"
43#import "ResourceManager.h"
44#import "Universe.h"
45
46#import "OODebugStandards.h"
47
48#define PRELOAD 0
49
50static void DumpStringAddrs(NSDictionary* dict, NSString* context);
51static NSComparisonResult SortDemoShipsByName(id a, id b, void* context);
52static NSComparisonResult SortDemoCategoriesByName(id a, id b, void* context);
53
55
56static NSString* const kShipRegistryCacheName = @"ship registry";
57static NSString* const kShipDataCacheKey = @"ship data";
58static NSString* const kPlayerShipsCacheKey = @"player ships";
59static NSString* const kRoleWeightsCacheKey = @"role weights";
60static NSString* const kDefaultDemoShip = @"coriolis-station";
61static NSString* const kVisualEffectRegistryCacheName = @"visual effect registry";
62static NSString* const kVisualEffectDataCacheKey = @"visual effect data";
63
64@interface OOShipRegistry (OODataLoader)
65
66- (void)loadShipData;
68- (void)loadDemoShips;
71
72- (BOOL)applyLikeShips:(NSMutableDictionary*)ioData withKey:(NSString*)likeKey;
73- (BOOL)loadAndMergeShipyard:(NSMutableDictionary*)ioData;
74- (BOOL)stripPrivateKeys:(NSMutableDictionary*)ioData;
75- (BOOL)makeShipEntriesMutable:(NSMutableDictionary*)ioData;
76- (BOOL)loadAndApplyShipDataOverrides:(NSMutableDictionary*)ioData;
77- (BOOL)canonicalizeAndTagSubentities:(NSMutableDictionary*)ioData;
78- (BOOL)removeUnusableEntries:(NSMutableDictionary*)ioData shipMode:(BOOL)shipMode;
79- (BOOL)sanitizeConditions:(NSMutableDictionary*)ioData;
80
81#if PRELOAD
82- (BOOL)preloadShipMeshes:(NSMutableDictionary*)ioData;
83#endif
84
85- (NSMutableDictionary*)mergeShip:(NSDictionary*)child withParent:(NSDictionary*)parent;
86- (void)mergeShipRoles:(NSString*)roles forShipKey:(NSString*)shipKey intoProbabilityMap:(NSMutableDictionary*)probabilitySets;
87
88- (NSDictionary*)canonicalizeSubentityDeclaration:(id)declaration
89 forShip:(NSString*)shipKey
90 shipData:(NSDictionary*)shipData
91 fatalError:(BOOL*)outFatalError;
92- (NSDictionary*)translateOldStyleSubentityDeclaration:(NSString*)declaration
93 forShip:(NSString*)shipKey
94 shipData:(NSDictionary*)shipData
95 fatalError:(BOOL*)outFatalError;
96- (NSDictionary*)translateOldStyleFlasherDeclaration:(NSArray*)tokens
97 forShip:(NSString*)shipKey
98 fatalError:(BOOL*)outFatalError;
99- (NSDictionary*)translateOldStandardBasicSubentityDeclaration:(NSArray*)tokens
100 forShip:(NSString*)shipKey
101 shipData:(NSDictionary*)shipData
102 fatalError:(BOOL*)outFatalError;
103- (NSDictionary*)validateNewStyleSubentityDeclaration:(NSDictionary*)declaration
104 forShip:(NSString*)shipKey
105 fatalError:(BOOL*)outFatalError;
106- (NSDictionary*)validateNewStyleFlasherDeclaration:(NSDictionary*)declaration
107 forShip:(NSString*)shipKey
108 fatalError:(BOOL*)outFatalError;
109- (NSDictionary*)validateNewStyleStandardSubentityDeclaration:(NSDictionary*)declaration
110 forShip:(NSString*)shipKey
111 fatalError:(BOOL*)outFatalError;
112
113- (BOOL)shipIsBallTurretForKey:(NSString*)shipKey inShipData:(NSDictionary*)shipData;
114
115@end
116
117@implementation OOShipRegistry
118
120{
121 if (sSingleton == nil) {
122 sSingleton = [[self alloc] init];
123 }
124
125 return sSingleton;
126}
127
128+ (void)reload
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}
140
141- (id)init
142{
143 if ((self = [super init])) {
144 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
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
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
168 if (_probabilitySets == nil) {
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}
179
180- (void)dealloc
181{
182 [_shipData release];
183 [_demoShips release];
184 [_playerShips release];
185 [_probabilitySets release];
186
187 [super dealloc];
188}
189
190- (NSDictionary*)shipInfoForKey:(NSString*)key
191{
192 return [_shipData objectForKey:key];
193}
194
195- (void)setShipInfoForKey:(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}
202
203- (NSDictionary*)effectInfoForKey:(NSString*)key
204{
205 return [_effectData objectForKey:key];
206}
207
208- (NSDictionary*)shipyardInfoForKey:(NSString*)key
209{
210 return [[self shipInfoForKey:key] objectForKey:@"_oo_shipyard"];
211}
212
213- (OOProbabilitySet*)probabilitySetForRole:(NSString*)role
214{
215 if (role == nil)
216 return nil;
217 return [_probabilitySets objectForKey:role];
218}
219
220- (NSArray*)demoShipKeys
221{
222 // with condition scripts in use, can't cache this value
223 [self loadDemoShips];
224
225 return [[_demoShips copy] autorelease];
226}
227
228- (NSArray*)playerShipKeys
229{
230 return _playerShips;
231}
232
233@end
234
235@implementation OOShipRegistry (OOConveniences)
236
237- (NSArray*)shipKeys
238{
239 return [_shipData allKeys];
240}
241
242- (NSArray*)shipRoles
243{
244 return [_probabilitySets allKeys];
245}
246
247- (NSArray*)shipKeysWithRole:(NSString*)role
248{
249 return [[self probabilitySetForRole:role] allObjects];
250}
251
252- (NSString*)randomShipKeyForRole:(NSString*)role
253{
254 return [[self probabilitySetForRole:role] randomObject];
255}
256
257@end
258
259@implementation OOShipRegistry (OODataLoader)
260
261/* -loadShipData
262
263 Load the data for all ships. This consists of five stages:
264 * Load merges shipdata.plist dictionary.
265 * Apply all like_ship entries.
266 * Load shipdata-overrides.plist and apply patches.
267 * Load shipyard.plist, add shipyard data into ship dictionaries, and
268 create _playerShips array.
269 * Build role->ship type probability sets.
270*/
272{
273 NSMutableDictionary* result = nil;
274
275 [_shipData release];
276 _shipData = nil;
277 [_playerShips release];
278 _playerShips = nil;
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];
343 _effectData = nil;
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}
382
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}
404
405/* -loadDemoShips
406
407 Load demoships.plist, and filter out non-existent ships. If no existing
408 ships remain, try adding coriolis; if this fails, add any ship in
409 shipdata.
410*/
412{
413 NSDictionary* key = nil;
414 NSArray* initialDemoShips = nil;
415 NSMutableArray* demoShips = nil;
416
417 DESTROY(_demoShips);
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}
512
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 {
527 }
528
529 _probabilitySets = [restoredSets copy];
530}
531
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}
565
566/* -applyLikeShips:
567
568 Implement like_ship by copying inherited ship and overwriting with child
569 ship values. Done iteratively to report recursive references of arbitrary
570 depth. Also removes and reports ships whose like_ship entry does not
571 resolve, and handles reference loops by removing all ships involved.
572
573 We start with a set of keys all ships that have a like_ships entry. In
574 each iteration, every ship whose like_ship entry does not refer to a ship
575 which itself has a like_ship entry is finalized. If the set of pending
576 ships does not shrink in an iteration, the remaining ships cannot be
577 resolved (either their like_ships do not exist, or they form reference
578 cycles) so we stop looping and report it.
579*/
580- (BOOL)applyLikeShips:(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}
643
644- (NSMutableDictionary*)mergeShip:(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}
697
698- (BOOL)makeShipEntriesMutable:(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}
718
719- (BOOL)loadAndApplyShipDataOverrides:(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}
746
747- (BOOL)stripPrivateKeys:(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}
767
768/* -loadAndMergeShipyard:
769
770 Load shipyard.plist, add its entries to appropriate shipyard entries as
771 a dictionary under the key "shipyard", and build list of player ships.
772 Before that, we strip out any "shipyard" entries already in shipdata, and
773 apply any shipyard-overrides.plist stuff to shipyard.
774*/
775- (BOOL)loadAndMergeShipyard:(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}
827
828- (BOOL)canonicalizeAndTagSubentities:(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}
907
908- (BOOL)removeUnusableEntries:(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}
944
945/* Transform conditions, determinant (if conditions array) and
946 shipyard.conditions from hasShipyard to sanitized form.
947 Also get list of condition_scripts
948*/
949- (BOOL)sanitizeConditions:(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}
1050
1051#if PRELOAD
1052- (BOOL)preloadShipMeshes:(NSMutableDictionary*)ioData
1053{
1054 NSEnumerator* shipKeyEnum = nil;
1055 NSString* shipKey = nil;
1056 NSMutableDictionary* shipEntry = nil;
1057 BOOL remove;
1058 NSString* modelName = nil;
1059 OOMesh* mesh = nil;
1060 NSAutoreleasePool* pool = nil;
1061 NSUInteger i = 0, count;
1062
1063 count = [ioData count];
1064
1065 // Preload ship meshes. (Iterates over a copy of keys since it mutates the dictionary.)
1066 for (shipKeyEnum = [[ioData allKeys] objectEnumerator]; (shipKey = [shipKeyEnum nextObject]);) {
1067 pool = [[NSAutoreleasePool alloc] init];
1068
1069 [[GameController sharedController] setProgressBarValue:(float)i++ / (float)count];
1070
1071 shipEntry = [ioData objectForKey:shipKey];
1072 remove = NO;
1073
1074 modelName = [shipEntry oo_stringForKey:@"model"];
1075 mesh = [OOMesh meshWithName:modelName
1076 materialDictionary:[shipEntry oo_dictionaryForKey:@"materials"]
1077 shadersDictionary:[shipEntry oo_dictionaryForKey:@"shaders"]
1078 smooth:[shipEntry oo_boolForKey:@"smooth"]
1079 shaderMacros:nil
1080 shaderBindingTarget:nil];
1081
1082 [pool release]; // NOTE: mesh is now invalid, but pointer nil check is OK.
1083
1084 if (mesh == nil) {
1085 // FIXME: what if it's a subentity? Need to rearrange things.
1086 OOLogERR(@"shipData.load.error", @"model \"%@\" could not be loaded for ship \"%@\", removing.", modelName, shipKey);
1087 [ioData removeObjectForKey:shipKey];
1088 }
1089 }
1090
1091 [[GameController sharedController] setProgressBarValue:-1.0f];
1092
1093 return YES;
1094}
1095#endif
1096
1097- (void)mergeShipRoles:(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}
1137
1138- (NSDictionary*)canonicalizeSubentityDeclaration:(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}
1179
1180- (NSDictionary*)translateOldStyleSubentityDeclaration:(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 {
1211 forShip:shipKey
1212 shipData:shipData
1213 fatalError:outFatalError];
1214 }
1215}
1216
1217- (NSDictionary*)translateOldStyleFlasherDeclaration:(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}
1250
1251- (NSDictionary*)translateOldStandardBasicSubentityDeclaration:(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}
1298
1299- (NSDictionary*)validateNewStyleSubentityDeclaration:(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}
1319
1320- (NSDictionary*)validateNewStyleFlasherDeclaration:(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}
1396
1397- (NSDictionary*)validateNewStyleStandardSubentityDeclaration:(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}
1485
1486- (BOOL)shipIsBallTurretForKey:(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}
1507
1508@end
1509
1510@implementation OOShipRegistry (Singleton)
1511
1512/* Canonical singleton boilerplate.
1513 See Cocoa Fundamentals Guide: Creating a Singleton Instance.
1514 See also +sharedRegistry above.
1515
1516 NOTE: assumes single-threaded access.
1517*/
1518
1519+ (id)allocWithZone:(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}
1528
1529- (id)copyWithZone:(NSZone*)inZone
1530{
1531 return self;
1532}
1533
1535{
1536 return self;
1537}
1538
1539- (NSUInteger)retainCount
1540{
1541 return UINT_MAX;
1542}
1543
1544- (void)release
1545{
1546}
1547
1549{
1550 return self;
1551}
1552
1553@end
1554
1555static void GatherStringAddrsDict(NSDictionary* dict, NSMutableSet* strings, NSString* context);
1556static void GatherStringAddrsArray(NSArray* array, NSMutableSet* strings, NSString* context);
1557static void GatherStringAddrs(id object, NSMutableSet* strings, NSString* context);
1558
1559static void DumpStringAddrs(NSDictionary* dict, NSString* context)
1560{
1561 return;
1562 static FILE* dump = NULL;
1563 if (dump == NULL)
1564 dump = fopen("strings.txt", "w");
1565 if (dump == NULL)
1566 return;
1567
1568 NSAutoreleasePool* pool = [NSAutoreleasePool new];
1569 NSMutableSet* strings = [NSMutableSet set];
1570 GatherStringAddrs(dict, strings, context);
1571
1572 NSDictionary* entry = nil;
1573 foreach (entry, strings) {
1574 NSString* string = [entry objectForKey:@"string"];
1575 NSString* context = [entry objectForKey:@"context"];
1576 void* pointer = [[entry objectForKey:@"address"] pointerValue];
1577
1578 string = [NSString stringWithFormat:@"%p\t%@: \"%@\"", pointer, context, string];
1579
1580 fprintf(dump, "%s\n", [string UTF8String]);
1581 }
1582
1583 fprintf(dump, "\n");
1584 fflush(dump);
1585 [pool release];
1586}
1587
1588static void GatherStringAddrsDict(NSDictionary* dict, NSMutableSet* strings, NSString* context)
1589{
1590 id key = nil;
1591 NSString* keyContext = [context stringByAppendingString:@" key"];
1592 foreachkey(key, dict)
1593 {
1594 GatherStringAddrs(key, strings, keyContext);
1595 GatherStringAddrs([dict objectForKey:key], strings, [context stringByAppendingFormat:@".%@", key]);
1596 }
1597}
1598
1599static void GatherStringAddrsArray(NSArray* array, NSMutableSet* strings, NSString* context)
1600{
1601 NSString* v = nil;
1602 unsigned i = 0;
1603 foreach (v, array) {
1604 GatherStringAddrs(v, strings, [context stringByAppendingFormat:@"[%u]", i++]);
1605 }
1606}
1607
1608static void GatherStringAddrs(id object, NSMutableSet* strings, NSString* context)
1609{
1610 if ([object isKindOfClass:[NSString class]]) {
1611 NSDictionary* entry = [NSDictionary dictionaryWithObjectsAndKeys:object, @"string", [NSValue valueWithPointer:object], @"address", context, @"context", nil];
1612 [strings addObject:entry];
1613 } else if ([object isKindOfClass:[NSArray class]]) {
1614 GatherStringAddrsArray(object, strings, context);
1615 } else if ([object isKindOfClass:[NSDictionary class]]) {
1616 GatherStringAddrsDict(object, strings, context);
1617 }
1618}
1619
1620static NSComparisonResult SortDemoShipsByName(id a, id b, void* context)
1621{
1622 return [[a oo_stringForKey:@"name"] compare:[b oo_stringForKey:@"name"]];
1623}
1624
1625static NSComparisonResult SortDemoCategoriesByName(id a, id b, void* context)
1626{
1627 return [OOShipLibraryCategoryPlural([[a oo_dictionaryAtIndex:0] oo_stringForKey:@"class"]) compare:OOShipLibraryCategoryPlural([[b oo_dictionaryAtIndex:0] oo_stringForKey:@"class"])];
1628}
void OOStandardsDeprecated(NSString *message)
BOOL OOEnforceStandards(void)
void OOStandardsError(NSString *message)
id OODeepCopy(id object) OO_RETURNS_RETAINED
Definition OODeepCopy.m:30
#define DESTROY(x)
#define foreachkey(VAR, DICT)
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)
NSArray * OOSanitizeLegacyScriptConditions(NSArray *conditions, NSString *context)
#define OOLogWARN(class, format,...)
Definition OOLogging.h:126
#define OOLogERR(class, format,...)
Definition OOLogging.h:125
#define OOLog(class, format,...)
Definition OOLogging.h:84
static OONullTexture * sSingleton
unsigned count
return nil
const Quaternion kIdentityQuaternion
OOINLINE void quaternion_normalize(Quaternion *quat) NONNULL_FUNC ALWAYS_INLINE_FUNC
NSDictionary * OOParseRolesFromString(NSString *string)
Definition OORoleSet.m:286
static NSString *const kOODemoShipClass
static NSString *const kOODemoShipKey
#define kDefaultFlasherColor
static NSComparisonResult SortDemoCategoriesByName(id a, id b, void *context)
static NSString *const kDefaultDemoShip
static void GatherStringAddrsArray(NSArray *array, NSMutableSet *strings, NSString *context)
static void GatherStringAddrsDict(NSDictionary *dict, NSMutableSet *strings, NSString *context)
static NSString *const kPlayerShipsCacheKey
static NSString *const kShipDataCacheKey
static NSString *const kVisualEffectDataCacheKey
static NSComparisonResult SortDemoShipsByName(id a, id b, void *context)
static void DumpStringAddrs(NSDictionary *dict, NSString *context)
static NSString *const kShipRegistryCacheName
static void GatherStringAddrs(id object, NSMutableSet *strings, NSString *context)
static NSString *const kRoleWeightsCacheKey
static NSString *const kVisualEffectRegistryCacheName
NSMutableArray * ScanTokensFromString(NSString *values)
const Vector kZeroVector
Definition OOVector.m:27
#define PLAYER
#define TURRET_SHOT_RANGE
Definition ShipEntity.h:84
#define COMBAT_WEAPON_RANGE_FACTOR
Definition ShipEntity.h:60
GameController * sharedController()
void setObject:forKey:inCache:(id inElement,[forKey] NSString *inKey,[inCache] NSString *inCacheKey)
id objectForKey:inCache:(NSString *inKey,[inCache] NSString *inCacheKey)
OOCacheManager * sharedCache()
void setObject:forKey:(id value,[forKey] id key)
Definition OOCache.m:256
OOColor * colorWithDescription:(id description)
Definition OOColor.m:135
NSArray * normalizedArray()
Definition OOColor.m:465
BOOL callMethod:inContext:withArguments:count:result:(jsid methodID,[inContext] JSContext *context,[withArguments] jsval *argv,[count] intN argc,[result] jsval *outResult)
Definition OOJSScript.m:328
void setWeight:forObject:(float weight,[forObject] id object)
NSDictionary * propertyListRepresentation()
id probabilitySetWithPropertyListRepresentation:(NSDictionary *plist)
void loadDemoShipConditions()
NSArray * playerShipKeys()
NSArray * _demoShips
NSDictionary * validateNewStyleStandardSubentityDeclaration:forShip:fatalError:(NSDictionary *declaration,[forShip] NSString *shipKey,[fatalError] BOOL *outFatalError)
void loadCachedRoleProbabilitySets()
NSDictionary * translateOldStyleFlasherDeclaration:forShip:fatalError:(NSArray *tokens,[forShip] NSString *shipKey,[fatalError] BOOL *outFatalError)
NSDictionary * _probabilitySets
void mergeShipRoles:forShipKey:intoProbabilityMap:(NSString *roles,[forShipKey] NSString *shipKey,[intoProbabilityMap] NSMutableDictionary *probabilitySets)
BOOL shipIsBallTurretForKey:inShipData:(NSString *shipKey,[inShipData] NSDictionary *shipData)
NSDictionary * translateOldStyleSubentityDeclaration:forShip:shipData:fatalError:(NSString *declaration,[forShip] NSString *shipKey,[shipData] NSDictionary *shipData,[fatalError] BOOL *outFatalError)
OOProbabilitySet * probabilitySetForRole:(NSString *role)
NSArray * _playerShips
void buildRoleProbabilitySets()
NSDictionary * _effectData
OOShipRegistry * sharedRegistry()
NSDictionary * validateNewStyleFlasherDeclaration:forShip:fatalError:(NSDictionary *declaration,[forShip] NSString *shipKey,[fatalError] BOOL *outFatalError)
NSDictionary * shipInfoForKey:(NSString *key)
NSDictionary * canonicalizeSubentityDeclaration:forShip:shipData:fatalError:(id declaration,[forShip] NSString *shipKey,[shipData] NSDictionary *shipData,[fatalError] BOOL *outFatalError)
NSArray * demoShipKeys()
NSDictionary * _shipData
NSDictionary * translateOldStandardBasicSubentityDeclaration:forShip:shipData:fatalError:(NSArray *tokens,[forShip] NSString *shipKey,[shipData] NSDictionary *shipData,[fatalError] BOOL *outFatalError)
NSMutableDictionary * mergeShip:withParent:(NSDictionary *child,[withParent] NSDictionary *parent)
NSDictionary * validateNewStyleSubentityDeclaration:forShip:fatalError:(NSDictionary *declaration,[forShip] NSString *shipKey,[fatalError] BOOL *outFatalError)
NSArray * arrayFromFilesNamed:inFolder:andMerge:cache:(NSString *fileName,[inFolder] NSString *folderName,[andMerge] BOOL mergeFiles,[cache] BOOL useCache)
NSDictionary * dictionaryFromFilesNamed:inFolder:mergeMode:cache:(NSString *fileName,[inFolder] NSString *folderName,[mergeMode] OOResourceMergeMode mergeMode,[cache] BOOL useCache)
voidpf void uLong size
Definition ioapi.h:126
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