189 :(NSArray *)info
190{
191 BOOL OK = YES;
192 NSDictionary *extra =
nil;
194 NSString *condition_script =
nil;
195 NSArray *keydef =
nil;
196
197 self = [super init];
198 if (
self ==
nil) OK = NO;
199
201
202 if (OK)
203 {
204
205 _techLevel = [info oo_unsignedIntAtIndex:EQUIPMENT_TECH_LEVEL_INDEX];
206 _price = [info oo_unsignedIntAtIndex:EQUIPMENT_PRICE_INDEX];
207 _name = [[info oo_stringAtIndex:EQUIPMENT_SHORT_DESC_INDEX] retain];
208 _identifier = [[info oo_stringAtIndex:EQUIPMENT_KEY_INDEX] retain];
209 _description = [[info oo_stringAtIndex:EQUIPMENT_LONG_DESC_INDEX] retain];
210
212 {
213 OOLog(
@"equipment.load",
@"***** ERROR: Invalid equipment.plist entry - missing name, identifier or description (\"%@\
", %@, \"%@\")",
_name,
_identifier,
_description);
214 OK = NO;
215 }
216 }
217
218 if (OK)
219 {
220
222 {
225 }
226 else if ([
_identifier isEqualToString:
@"EQ_PASSENGER_BERTH_REMOVAL"])
227 {
229 }
231 {
233 }
239 }
240
242 {
243
244 extra = [info oo_dictionaryAtIndex:EQUIPMENT_EXTRA_INFO_INDEX];
246 {
247
248 _isAvailableToAll = [extra oo_boolForKey:@"available_to_all" defaultValue:_isAvailableToAll];
249 _isAvailableToPlayer = [extra oo_boolForKey:@"available_to_player" defaultValue:_isAvailableToPlayer];
250 _isAvailableToNPCs = [extra oo_boolForKey:@"available_to_NPCs" defaultValue:_isAvailableToNPCs];
251
252 _isMissileOrMine = [extra oo_boolForKey:@"is_external_store" defaultValue:_isMissileOrMine];
253 _requiresEmptyPylon = [extra oo_boolForKey:@"requires_empty_pylon" defaultValue:_requiresEmptyPylon];
254 _requiresMountedPylon = [extra oo_boolForKey:@"requires_mounted_pylon" defaultValue:_requiresMountedPylon];
255 _requiresClean = [extra oo_boolForKey:@"requires_clean" defaultValue:_requiresClean];
256 _requiresNotClean = [extra oo_boolForKey:@"requires_not_clean" defaultValue:_requiresNotClean];
257 _portableBetweenShips = [extra oo_boolForKey:@"portable_between_ships" defaultValue:_portableBetweenShips];
259 _requiresFullFuel = [extra oo_boolForKey:@"requires_full_fuel" defaultValue:_requiresFullFuel];
260 _requiresNonFullFuel = [extra oo_boolForKey:@"requires_non_full_fuel" defaultValue:_requiresNonFullFuel];
261 _isVisible = [extra oo_boolForKey:@"visible" defaultValue:_isVisible];
263 _hideValues = [extra oo_boolForKey:@"hide_values" defaultValue:NO];
264
265 _requiredCargoSpace = [extra oo_unsignedIntForKey:@"requires_cargo_space" defaultValue:_requiredCargoSpace];
266
267 _installTime = [extra oo_unsignedIntForKey:@"installation_time" defaultValue:0];
268 _repairTime = [extra oo_unsignedIntForKey:@"repair_time" defaultValue:0];
269 _provides = [[extra oo_arrayForKey:@"provides" defaultValue:[NSArray array]] retain];
270
271 id dispColor = [extra oo_objectForKey:@"display_color" defaultValue:nil];
273
274 _weaponInfo = [[extra oo_dictionaryForKey:@"weapon_info" defaultValue:[NSDictionary dictionary]] retain];
275
276 _damageProbability = [extra oo_floatForKey:@"damage_probability" defaultValue:(_isMissileOrMine?0.0:1.0)];
277
278 id object = [extra objectForKey:@"requires_equipment"];
279 if ([
object isKindOfClass:[NSString
class]])
_requiresEquipment = [[NSSet setWithObject:object] retain];
280 else if ([
object isKindOfClass:[NSArray
class]])
_requiresEquipment = [[NSSet setWithArray:object] retain];
281 else if (
object !=
nil)
282 {
283 OOLog(
@"equipment.load",
@"***** ERROR: %@ for equipment item %@ is not a string or an array.",
@"requires_equipment",
_identifier);
284 }
285
286 object = [extra objectForKey:@"requires_any_equipment"];
287 if ([
object isKindOfClass:[NSString
class]])
_requiresAnyEquipment = [[NSSet setWithObject:object] retain];
288 else if ([
object isKindOfClass:[NSArray
class]])
_requiresAnyEquipment = [[NSSet setWithArray:object] retain];
289 else if (
object !=
nil)
290 {
291 OOLog(
@"equipment.load",
@"***** ERROR: %@ for equipment item %@ is not a string or an array.",
@"requires_any_equipment",
_identifier);
292 }
293
294 object = [extra objectForKey:@"incompatible_with_equipment"];
295 if ([
object isKindOfClass:[NSString
class]])
_incompatibleEquipment = [[NSSet setWithObject:object] retain];
296 else if ([
object isKindOfClass:[NSArray
class]])
_incompatibleEquipment = [[NSSet setWithArray:object] retain];
297 else if (
object !=
nil)
298 {
299 OOLog(
@"equipment.load",
@"***** ERROR: %@ for equipment item %@ is not a string or an array.",
@"incompatible_with_equipment",
_identifier);
300 }
301
302 object = [extra objectForKey:@"conditions"];
303 if ([
object isKindOfClass:[NSString
class]])
conditions = [NSArray arrayWithObject:object];
304 else if ([
object isKindOfClass:[NSArray
class]])
conditions = object;
305 else if (
object !=
nil)
306 {
307 OOLog(
@"equipment.load",
@"***** ERROR: %@ for equipment item %@ is not a string or an array.",
@"conditions",
_identifier);
308 }
310 {
313 {
315 [_conditions retain];
316 }
317 }
318
319 object = [extra objectForKey:@"condition_script"];
320 if ([object isKindOfClass:[NSString class]])
321 {
322 condition_script = object;
323 }
324 else if (
object !=
nil)
325 {
326 OOLog(
@"equipment.load",
@"***** ERROR: %@ for equipment item %@ is not a string.",
@"condition_script",
_identifier);
327 }
328 if (condition_script !=
nil)
329 {
331 }
332
333
334
335
336
337 _scriptInfo = [extra oo_dictionaryForKey:@"script_info"];
338 [_scriptInfo retain];
339
340 _script = [extra oo_stringForKey:@"script"];
342 [_script retain];
344 {
345 _fastAffinityA = !![extra oo_boolForKey:@"fast_affinity_defensive"];
346 _fastAffinityB = !![extra oo_boolForKey:@"fast_affinity_offensive"];
347
348
349
350
351 NSString *checking;
352
353 object = [extra objectForKey:@"default_activate_key"];
354 if ([object isKindOfClass:[NSArray class]]) keydef = object;
355 else if (
object !=
nil)
356 {
357 OOLog(
@"equipment.load",
@"***** ERROR: %@ for equipment item %@ is not an array.",
@"default_activate_key",
_identifier);
359 }
360
362 {
363
365 checking = [PLAYER validateKey:[NSString stringWithFormat:@"activate_%@", _identifier] checkKeys:_defaultActivateKey];
366
367 if (checking !=
nil) {
368 OOLog(
@"equipment.load",
@"***** Error: %@ for equipment item %@ is already in use for %@. Default not applied",
@"default_activate_key",
_identifier, checking);
370 }
371 }
372
373 object = [extra objectForKey:@"default_mode_key"];
374 if ([object isKindOfClass:[NSArray class]]) keydef = object;
375 else if (
object !=
nil)
376 {
377 OOLog(
@"equipment.load",
@"***** ERROR: %@ for equipment item %@ is not an array.",
@"default_mode_key",
_identifier);
379 }
380
382 {
383
385 checking = [PLAYER validateKey:[NSString stringWithFormat:@"mode_%@", _identifier] checkKeys:_defaultModeKey];
386
387 if (checking !=
nil) {
388 OOLog(
@"equipment.load",
@"***** Error: %@ for equipment item %@ is already in use for %@. Default not applied.",
@"default_mode_key",
_identifier, checking);
390 }
391 }
392 }
393 }
394 }
395
396 if (!OK)
397 {
398 [self release];
400 }
401 return self;
402}
NSArray * OOSanitizeLegacyScriptConditions(NSArray *conditions, NSString *context)
#define OOLog(class, format,...)
@ EQUIPMENT_LONG_DESC_INDEX
@ EQUIPMENT_EXTRA_INFO_INDEX
OOColor * colorWithDescription:(id description)
OOCargoQuantity _requiredCargoSpace
unsigned _isMissileOrMine
unsigned _requiresFullFuel
unsigned _portableBetweenShips
unsigned _requiresMountedPylon
unsigned _isAvailableToAll
unsigned _isAvailableToNPCs
unsigned _requiresNotClean
unsigned _requiresFreePassengerBerth
unsigned _requiresNonFullFuel
unsigned _isAvailableToPlayer
unsigned _requiresEmptyPylon