39static NSString *
const kStageName =
@"Checking shipdata.plist";
42@interface OOCheckShipDataPListVerifierStage (OOPrivate)
44- (void)verifyShipInfo:(NSDictionary *)info withName:(NSString *)name;
46- (void)message:(NSString *)format, ...;
47- (void)verboseMessage:(NSString *)format, ...;
54- (NSSet *)rolesFromString:(NSString *)string;
69 NSMutableSet *result = [[
super dependents] mutableCopy];
72 return [result autorelease];
80 fileScanner = [[
self verifier] fileScannerStage];
81 return [fileScanner
fileExists:@"shipdata.plist"
91 NSAutoreleasePool *pool =
nil;
92 NSEnumerator *shipEnum =
nil;
93 NSString *shipKey =
nil;
94 NSDictionary *shipInfo =
nil;
95 NSDictionary *ooliteShipData =
nil;
96 NSDictionary *settings =
nil;
97 NSMutableSet *mergeSet =
nil;
98 NSArray *shipList =
nil;
100 fileScanner = [[
self verifier] fileScannerStage];
101 _shipdataPList = [fileScanner
plistNamed:@"shipdata.plist"
106 if (_shipdataPList ==
nil)
return;
116 if (![_shipdataPList isKindOfClass:[NSDictionary
class]])
118 OOLog(
@"verifyOXP.shipdataPList.notDict",
@"%@",
@"***** ERROR: shipdata.plist is not a dictionary.");
123 _ooliteShipNames = [NSSet setWithArray:[ooliteShipData allKeys]];
124 settings = [[
self verifier] configurationDictionaryForKey:@"shipdataPListSettings"];
125 _basicKeys = [settings oo_setForKey:@"knownShipKeys"];
128 mergeSet = [_basicKeys mutableCopy];
129 [mergeSet addObjectsFromArray:[settings oo_arrayForKey:@"knownStationKeys"]];
130 _stationKeys = mergeSet;
133 mergeSet = [_basicKeys mutableCopy];
134 [mergeSet addObjectsFromArray:[settings oo_arrayForKey:@"knownPlayerKeys"]];
135 _playerKeys = [[mergeSet copy] autorelease];
138 [mergeSet unionSet:_stationKeys];
142 [_schemaVerifier setDelegate:self];
144 shipList = [[_shipdataPList allKeys] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
145 for (shipEnum = [shipList objectEnumerator]; (shipKey = [shipEnum nextObject]); )
147 pool = [[NSAutoreleasePool alloc] init];
149 shipInfo = [_shipdataPList oo_dictionaryForKey:shipKey];
152 OOLog(
@"verifyOXP.shipdata.badType",
@"***** ERROR: shipdata.plist entry for \"%@\
" is not a dictionary.", shipKey);
156 [
self verifyShipInfo:shipInfo withName:shipKey];
162 _shipdataPList =
nil;
163 _ooliteShipNames =
nil;
172@implementation OOCheckShipDataPListVerifierStage (OOPrivate)
174- (void)verifyShipInfo:(NSDictionary *)info withName:(NSString *)name
178 _havePrintedMessage = NO;
186 NSString *aiName = [info oo_stringForKey:@"ai_type"];
189 if (![aiName hasSuffix:
@".js"])
191 [_aiVerifierStage stateMachineNamed:aiName usedByShip:name];
198 if (!_havePrintedMessage)
200 OOLog(
@"verifyOXP.verbose.shipData.OK",
@"- ship \"%@\
" OK.", _name);
209- (void)message:(NSString *)format, ...
213 if (!_havePrintedMessage)
215 OOLog(
@"verifyOXP.shipData.firstMessage",
@"Ship \"%@\
":", _name);
217 _havePrintedMessage = YES;
220 va_start(args, format);
226- (void)verboseMessage:(NSString *)format, ...
232 if (!_havePrintedMessage)
234 OOLog(
@"verifyOXP.shipData.firstMessage",
@"Ship \"%@\
":", _name);
236 _havePrintedMessage = YES;
239 va_start(args, format);
247 NSString *rolesString =
nil;
249 rolesString = [_info objectForKey:@"roles"];
250 _roles = [
self rolesFromString:rolesString];
251 _isPlayer = [_roles containsObject:@"player"];
252 _isStation = [_info oo_boolForKey:@"is_carrier" defaultValue:NO] ||
253 [_info oo_boolForKey:@"isCarrier" defaultValue:NO] ||
254 [rolesString rangeOfString:@"station"].location != NSNotFound ||
255 [rolesString rangeOfString:@"carrier"].location != NSNotFound;
257 _isTemplate = [_info oo_boolForKey:@"is_template" defaultValue:NO];
259 if (_isPlayer && _isStation)
261 [
self message:@"***** ERROR: ship is both a player ship and a station. Treating as non-station."];
269 NSSet *referenceSet =
nil;
270 NSEnumerator *keyEnum =
nil;
273 if (_isPlayer) referenceSet = _playerKeys;
274 else if (_isStation) referenceSet = _stationKeys;
275 else referenceSet = _basicKeys;
277 for (keyEnum = [_info keyEnumerator]; (key = [keyEnum nextObject]); )
279 if (![referenceSet containsObject:key])
281 if ([_allKeys containsObject:key])
287 [
self message:@"----- WARNING: key \"%@\" does not apply to this category of ship.", key];
292 [
self message:@"----- WARNING: unknown key \"%@\".", key];