43@interface OOEquipmentType (Private)
45- (id) initWithInfo:(NSArray *)info;
54 NSArray *equipmentData =
nil;
55 NSMutableArray *equipmentTypes =
nil;
56 NSMutableDictionary *equipmentTypesByIdentifier =
nil;
57 NSArray *itemInfo =
nil;
59 NSEnumerator *itemEnum =
nil;
60 NSMutableArray *conditionScripts =
nil;
62 equipmentData = [UNIVERSE equipmentData];
64 [sEquipmentTypes release];
66 equipmentTypes = [NSMutableArray arrayWithCapacity:[equipmentData count]];
67 conditionScripts = [NSMutableArray arrayWithCapacity:[equipmentData count]];
69 equipmentTypesByIdentifier = [NSMutableDictionary dictionaryWithCapacity:[equipmentData count]];
71 for (itemEnum = [equipmentData objectEnumerator]; (itemInfo = [itemEnum nextObject]); )
76 [equipmentTypes addObject:item];
77 [equipmentTypesByIdentifier setObject:item forKey:[item
identifier]];
80 if (condition_script !=
nil)
82 if (![conditionScripts containsObject:condition_script])
84 [conditionScripts addObject:condition_script];
95 equipmentData = [UNIVERSE equipmentDataOutfitting];
97 [sEquipmentTypesOutfitting release];
100 equipmentTypes = [NSMutableArray arrayWithCapacity:[equipmentData count]];
101 for (itemEnum = [equipmentData objectEnumerator]; (itemInfo = [itemEnum nextObject]); )
106 [equipmentTypes addObject:item];
107 [equipmentTypesByIdentifier setObject:item forKey:[item
identifier]];
115+ (void) addEquipmentWithInfo:(NSArray *)itemInfo
117 NSMutableArray *equipmentTypes = [NSMutableArray arrayWithArray:sEquipmentTypes];
118 NSMutableArray *equipmentTypesOutfitting = [NSMutableArray arrayWithArray:sEquipmentTypesOutfitting];
119 NSMutableDictionary *equipmentTypesByIdentifier = [[NSMutableDictionary alloc] initWithDictionary:sEquipmentTypesByIdentifier];
123 [equipmentTypes addObject:item];
124 [equipmentTypesOutfitting addObject:item];
125 [equipmentTypesByIdentifier setObject:item forKey:[item
identifier]];
127 [sEquipmentTypes release];
129 [sEquipmentTypesOutfitting release];
136 DESTROY(equipmentTypesByIdentifier);
140+ (NSString *) getMissileRegistryRoleForShip:(NSString *)shipKey
142 return [sMissilesRegistry oo_stringForKey:shipKey];
146+ (void) setMissileRegistryRole:(NSString *)role forShip:(NSString *)shipKey
148 NSMutableDictionary *missilesRegistry = [[NSMutableDictionary alloc] initWithDictionary:sMissilesRegistry];
149 if (role !=
nil && shipKey !=
nil && ![shipKey isEqualToString:
@""])
151 [missilesRegistry setValue:role forKey:shipKey];
159+ (NSArray *) allEquipmentTypes
165+ (NSEnumerator *) equipmentEnumerator
167 return [sEquipmentTypes objectEnumerator];
171+ (NSEnumerator *) reverseEquipmentEnumerator
173 return [sEquipmentTypes reverseObjectEnumerator];
177+ (NSEnumerator *) equipmentEnumeratorOutfitting
179 return [sEquipmentTypesOutfitting objectEnumerator];
183+ (
OOEquipmentType *) equipmentTypeWithIdentifier:(NSString *)identifier
185 return [sEquipmentTypesByIdentifier objectForKey:identifier];
189- (id) initWithInfo:(NSArray *)info
192 NSDictionary *extra =
nil;
193 NSArray *conditions =
nil;
194 NSString *condition_script =
nil;
195 NSArray *keydef =
nil;
198 if (
self ==
nil) OK = NO;
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];
211 if (_name ==
nil || _identifier ==
nil || _description ==
nil)
213 OOLog(
@"equipment.load",
@"***** ERROR: Invalid equipment.plist entry - missing name, identifier or description (\"%@\
", %@, \"%@\")", _name, _identifier, _description);
221 if ([_identifier hasSuffix:
@"_MISSILE"] || [_identifier hasSuffix:
@"_MINE"])
223 _isMissileOrMine = YES;
224 _requiresEmptyPylon = YES;
226 else if ([_identifier isEqualToString:
@"EQ_PASSENGER_BERTH_REMOVAL"])
228 _requiresFreePassengerBerth = YES;
230 else if ([_identifier isEqualToString:
@"EQ_FUEL"])
232 _requiresNonFullFuel = YES;
235 _isAvailableToPlayer = YES;
236 _isAvailableToNPCs = YES;
237 _damageProbability = 1.0;
244 extra = [info oo_dictionaryAtIndex:EQUIPMENT_EXTRA_INFO_INDEX];
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];
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];
258 _requiresFreePassengerBerth = [extra oo_boolForKey:@"requires_free_passenger_berth" defaultValue:_requiresFreePassengerBerth];
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];
262 _canCarryMultiple = [extra oo_boolForKey:@"can_carry_multiple" defaultValue:NO];
263 _hideValues = [extra oo_boolForKey:@"hide_values" defaultValue:NO];
265 _requiredCargoSpace = [extra oo_unsignedIntForKey:@"requires_cargo_space" defaultValue:_requiredCargoSpace];
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];
271 id dispColor = [extra oo_objectForKey:@"display_color" defaultValue:nil];
274 _weaponInfo = [[extra oo_dictionaryForKey:@"weapon_info" defaultValue:[NSDictionary dictionary]] retain];
276 _damageProbability = [extra oo_floatForKey:@"damage_probability" defaultValue:(_isMissileOrMine?0.0:1.0)];
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)
283 OOLog(
@"equipment.load",
@"***** ERROR: %@ for equipment item %@ is not a string or an array.",
@"requires_equipment", _identifier);
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)
291 OOLog(
@"equipment.load",
@"***** ERROR: %@ for equipment item %@ is not a string or an array.",
@"requires_any_equipment", _identifier);
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)
299 OOLog(
@"equipment.load",
@"***** ERROR: %@ for equipment item %@ is not a string or an array.",
@"incompatible_with_equipment", _identifier);
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)
307 OOLog(
@"equipment.load",
@"***** ERROR: %@ for equipment item %@ is not a string or an array.",
@"conditions", _identifier);
309 if (conditions !=
nil)
311 OOStandardsDeprecated([NSString stringWithFormat:
@"The conditions key is deprecated for equipment %@",_name]);
315 [_conditions retain];
319 object = [extra objectForKey:@"condition_script"];
320 if ([
object isKindOfClass:[NSString
class]])
322 condition_script = object;
324 else if (
object !=
nil)
326 OOLog(
@"equipment.load",
@"***** ERROR: %@ for equipment item %@ is not a string.",
@"condition_script", _identifier);
328 if (condition_script !=
nil)
330 _condition_script = [condition_script retain];
337 _scriptInfo = [extra oo_dictionaryForKey:@"script_info"];
338 [_scriptInfo retain];
340 _script = [extra oo_stringForKey:@"script"];
341 if (_script !=
nil && ![
OOScript jsScriptFromFileNamed:_script properties:
nil]) _script =
nil;
345 _fastAffinityA = !![extra oo_boolForKey:@"fast_affinity_defensive"];
346 _fastAffinityB = !![extra oo_boolForKey:@"fast_affinity_offensive"];
353 object = [extra objectForKey:@"default_activate_key"];
354 if ([
object isKindOfClass:[NSArray
class]]) keydef = object;
355 else if (
object !=
nil)
357 OOLog(
@"equipment.load",
@"***** ERROR: %@ for equipment item %@ is not an array.",
@"default_activate_key", _identifier);
364 _defaultActivateKey = [PLAYER processKeyCode:keydef];
365 checking = [PLAYER validateKey:[NSString stringWithFormat:@"activate_%@", _identifier] checkKeys:_defaultActivateKey];
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);
369 _defaultActivateKey =
nil;
373 object = [extra objectForKey:@"default_mode_key"];
374 if ([
object isKindOfClass:[NSArray
class]]) keydef = object;
375 else if (
object !=
nil)
377 OOLog(
@"equipment.load",
@"***** ERROR: %@ for equipment item %@ is not an array.",
@"default_mode_key", _identifier);
384 _defaultModeKey = [PLAYER processKeyCode:keydef];
385 checking = [PLAYER validateKey:[NSString stringWithFormat:@"mode_%@", _identifier] checkKeys:_defaultModeKey];
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);
389 _defaultModeKey =
nil;
412 DESTROY(_requiresAnyEquipment);
413 DESTROY(_incompatibleEquipment);
427- (id) copyWithZone:(NSZone *)zone
430 return [
self retain];
434- (NSString *) descriptionComponents
436 return [NSString stringWithFormat:@"%@ \"%@\"", _identifier, _name];
440- (NSString *) identifier
446- (NSString *) damagedIdentifier
448 return [_identifier stringByAppendingString:@"_DAMAGED"];
458- (NSString *) descriptiveText
476- (BOOL) isAvailableToAll
478 return _isAvailableToAll;
482- (BOOL) requiresEmptyPylon
484 return _requiresEmptyPylon;
488- (BOOL) requiresMountedPylon
490 return _requiresMountedPylon;
494- (BOOL) requiresCleanLegalRecord
496 return _requiresClean;
500- (BOOL) requiresNonCleanLegalRecord
502 return _requiresNotClean;
506- (BOOL) requiresFreePassengerBerth
508 return _requiresFreePassengerBerth;
512- (BOOL) requiresFullFuel
514 return _requiresFullFuel;
518- (BOOL) requiresNonFullFuel
520 return _requiresNonFullFuel;
524- (BOOL) isPrimaryWeapon
526 return [[
self identifier] hasPrefix:@"EQ_WEAPON"];
530- (BOOL) isMissileOrMine
532 return _isMissileOrMine;
536- (BOOL) isPortableBetweenShips
538 return _portableBetweenShips;
542- (BOOL) canCarryMultiple
544 if ([
self isMissileOrMine])
return YES;
546 if ([
self isPrimaryWeapon])
return NO;
549 if ([_identifier isEqualToString:
@"EQ_PASSENGER_BERTH"] ||
550 [_identifier isEqualToString:
@"EQ_TRUMBLE"])
555 return _canCarryMultiple;
559- (GLfloat) damageProbability
561 if ([
self isMissileOrMine])
return 0.0;
563 return _damageProbability;
569 if ([
self isMissileOrMine])
return NO;
571 if ([
self damageProbability] > 0.0)
592- (BOOL) isAvailableToPlayer
594 return _isAvailableToPlayer;
598- (BOOL) isAvailableToNPCs
600 return _isAvailableToNPCs;
606 return _requiredCargoSpace;
610- (NSSet *) requiresEquipment
612 return _requiresEquipment;
616- (NSSet *) requiresAnyEquipment
618 return _requiresAnyEquipment;
622- (NSSet *) incompatibleEquipment
624 return _incompatibleEquipment;
630 return _displayColor;
634- (void) setDisplayColor:(
OOColor *)color
636 [_displayColor release];
637 _displayColor = [color retain];
641- (NSArray *) conditions
647- (NSString *) conditionScript
649 return _condition_script;
653- (NSDictionary *) scriptInfo
659- (NSString *) scriptName
665- (BOOL) fastAffinityDefensive
667 return _fastAffinityA;
671- (BOOL) fastAffinityOffensive
673 return _fastAffinityB;
677- (NSArray *) defaultActivateKey
679 return _defaultActivateKey;
683- (NSArray *) defaultModeKey
685 return _defaultModeKey;
689- (NSUInteger) installTime
695- (NSUInteger) repairTime
703 return _installTime / 2;
708- (NSArray *) providesForScripting
710 return [[_provides copy] autorelease];
714- (BOOL) provides:(NSString *)key
716 return [_provides containsObject:key];
721- (BOOL) isTurretLaser
723 return [_weaponInfo oo_boolForKey:@"is_turret_laser" defaultValue:NO];
727- (BOOL) isMiningLaser
729 return [_weaponInfo oo_boolForKey:@"is_mining_laser" defaultValue:NO];
733- (NSDictionary *) weaponInfo
739- (GLfloat) weaponRange
741 return [_weaponInfo oo_floatForKey:@"range" defaultValue:12500.0];
745- (GLfloat) weaponEnergyUse
747 return [_weaponInfo oo_floatForKey:@"energy" defaultValue:0.8];
751- (GLfloat) weaponDamage
753 return [_weaponInfo oo_floatForKey:@"damage" defaultValue:15.0];
757- (GLfloat) weaponRechargeRate
759 return [_weaponInfo oo_floatForKey:@"recharge_rate" defaultValue:0.5];
763- (GLfloat) weaponShotTemperature
765 return [_weaponInfo oo_floatForKey:@"shot_temperature" defaultValue:7.0];
769- (GLfloat) weaponThreatAssessment
771 return [_weaponInfo oo_floatForKey:@"threat_assessment" defaultValue:1.0];
781- (NSString *) fxShotMissName
783 return [_weaponInfo oo_stringForKey:@"fx_shot_miss_name" defaultValue:@"[player-laser-miss]"];
787- (NSString *) fxShotHitName
789 return [_weaponInfo oo_stringForKey:@"fx_shot_hit_name" defaultValue:@"[player-laser-hit]"];
793- (NSString *) fxShieldHitName
795 return [_weaponInfo oo_stringForKey:@"fx_hitplayer_shielded_name" defaultValue:@"[player-hit-by-weapon]"];
799- (NSString *) fxUnshieldedHitName
801 return [_weaponInfo oo_stringForKey:@"fx_hitplayer_unshielded_name" defaultValue:@"[player-direct-hit]"];
805- (NSString *) fxWeaponLaunchedName
807 return [_weaponInfo oo_stringForKey:@"fx_weapon_launch_name" defaultValue:([[
self identifier] hasSuffix:@"_MINE"] ? @"[mine-launched]" : @"[missile-launched]")];
816- (BOOL) suppressClangStuff
826@implementation OOEquipmentType (Conveniences)
833 tl = [
self techLevel];
839 missionVar = [PLAYER missionVariableForKey:[@"mission_TL_FOR_" stringByAppendingString:[
self identifier]]];
void OOStandardsDeprecated(NSString *message)
BOOL OOEnforceStandards(void)
static NSDictionary * sEquipmentTypesByIdentifier
static NSArray * sEquipmentTypes
static NSArray * sEquipmentTypesOutfitting
static NSDictionary * sMissilesRegistry
NSArray * OOSanitizeLegacyScriptConditions(NSArray *conditions, NSString *context)
#define OOLog(class, format,...)
uint64_t OOCreditsQuantity
@ EQUIPMENT_LONG_DESC_INDEX
@ EQUIPMENT_EXTRA_INFO_INDEX
void setObject:forKey:inCache:(id inElement,[forKey] NSString *inKey,[inCache] NSString *inCacheKey)
OOCacheManager * sharedCache()
OOColor * brightColorWithDescription:(id description)
OOColor * colorWithDescription:(id description)
NSString * conditionScript()