Oolite
Loading...
Searching...
No Matches
OOEquipmentType.m
Go to the documentation of this file.
1/*
2
3OOEquipmentType.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 "OOEquipmentType.h"
29#import "Universe.h"
32#import "OOCacheManager.h"
33#import "OODebugStandards.h"
36
37static NSArray *sEquipmentTypes = nil;
39static NSDictionary *sEquipmentTypesByIdentifier = nil;
40static NSDictionary *sMissilesRegistry = nil;
41
42
43@interface OOEquipmentType (Private)
44
45- (id) initWithInfo:(NSArray *)info;
46
47@end
48
49
50@implementation OOEquipmentType
51
52+ (void) loadEquipment
53{
54 NSArray *equipmentData = nil;
55 NSMutableArray *equipmentTypes = nil;
56 NSMutableDictionary *equipmentTypesByIdentifier = nil;
57 NSArray *itemInfo = nil;
58 OOEquipmentType *item = nil;
59 NSMutableArray *conditionScripts = nil;
60
61 equipmentData = [UNIVERSE equipmentData];
62
63 [sEquipmentTypes release];
65 equipmentTypes = [NSMutableArray arrayWithCapacity:[equipmentData count]];
66 conditionScripts = [NSMutableArray arrayWithCapacity:[equipmentData count]];
68 equipmentTypesByIdentifier = [NSMutableDictionary dictionaryWithCapacity:[equipmentData count]];
69
70 foreach (itemInfo, equipmentData)
71 {
72 item = [[[OOEquipmentType alloc] initWithInfo:itemInfo] autorelease];
73 if (item != nil)
74 {
75 [equipmentTypes addObject:item];
76 [equipmentTypesByIdentifier setObject:item forKey:[item identifier]];
77 }
78 NSString* condition_script = [item conditionScript];
79 if (condition_script != nil)
80 {
81 if (![conditionScripts containsObject:condition_script])
82 {
83 [conditionScripts addObject:condition_script];
84 }
85 }
86 }
87
88 [[OOCacheManager sharedCache] setObject:conditionScripts forKey:@"equipment conditions" inCache:@"condition scripts"];
89
90 sEquipmentTypes = [equipmentTypes copy];
91 sEquipmentTypesByIdentifier = [[NSDictionary alloc] initWithDictionary:equipmentTypesByIdentifier];
92
93 // same for the outfitting dataset
94 equipmentData = [UNIVERSE equipmentDataOutfitting];
95
96 [sEquipmentTypesOutfitting release];
98
99 equipmentTypes = [NSMutableArray arrayWithCapacity:[equipmentData count]];
100 foreach (itemInfo, equipmentData)
101 {
102 item = [[[OOEquipmentType alloc] initWithInfo:itemInfo] autorelease];
103 if (item != nil)
104 {
105 [equipmentTypes addObject:item];
106 [equipmentTypesByIdentifier setObject:item forKey:[item identifier]];
107 }
108 }
109 sEquipmentTypesOutfitting = [equipmentTypes copy];
110
111}
112
113
114+ (void) addEquipmentWithInfo:(NSArray *)itemInfo
115{
116 NSMutableArray *equipmentTypes = [NSMutableArray arrayWithArray:sEquipmentTypes];
117 NSMutableArray *equipmentTypesOutfitting = [NSMutableArray arrayWithArray:sEquipmentTypesOutfitting];
118 NSMutableDictionary *equipmentTypesByIdentifier = [[NSMutableDictionary alloc] initWithDictionary:sEquipmentTypesByIdentifier];
119 OOEquipmentType *item = [[[OOEquipmentType alloc] initWithInfo:itemInfo] autorelease];
120 if (item != nil)
121 {
122 [equipmentTypes addObject:item];
123 [equipmentTypesOutfitting addObject:item];
124 [equipmentTypesByIdentifier setObject:item forKey:[item identifier]];
125
126 [sEquipmentTypes release];
128 [sEquipmentTypesOutfitting release];
131 sEquipmentTypes = [equipmentTypes copy];
132 sEquipmentTypesOutfitting = [equipmentTypesOutfitting copy];
133 sEquipmentTypesByIdentifier = [[NSDictionary alloc] initWithDictionary:equipmentTypesByIdentifier];
134 }
135 DESTROY(equipmentTypesByIdentifier);
136}
137
138
139+ (NSString *) getMissileRegistryRoleForShip:(NSString *)shipKey
140{
141 return [sMissilesRegistry oo_stringForKey:shipKey];
142}
143
144
145+ (void) setMissileRegistryRole:(NSString *)role forShip:(NSString *)shipKey
146{
147 NSMutableDictionary *missilesRegistry = [[NSMutableDictionary alloc] initWithDictionary:sMissilesRegistry];
148 if (role != nil && shipKey != nil && ![shipKey isEqualToString:@""])
149 {
150 [missilesRegistry setValue:role forKey:shipKey];
152 sMissilesRegistry = [[NSDictionary alloc] initWithDictionary:missilesRegistry];
153 }
154 DESTROY(missilesRegistry);
155}
156
157
158+ (NSArray *) allEquipmentTypes
159{
160 return sEquipmentTypes;
161}
162
163
164+ (NSEnumerator *) equipmentEnumerator
165{
166 return [sEquipmentTypes objectEnumerator];
167}
168
169
170+ (NSEnumerator *) reverseEquipmentEnumerator
171{
172 return [sEquipmentTypes reverseObjectEnumerator];
173}
174
175
176+ (NSEnumerator *) equipmentEnumeratorOutfitting
177{
178 return [sEquipmentTypesOutfitting objectEnumerator];
179}
180
181
182+ (OOEquipmentType *) equipmentTypeWithIdentifier:(NSString *)identifier
183{
184 return [sEquipmentTypesByIdentifier objectForKey:identifier];
185}
186
187
188- (id) initWithInfo:(NSArray *)info
189{
190 BOOL OK = YES;
191 NSDictionary *extra = nil;
192 NSArray *conditions = nil;
193 NSString *condition_script = nil;
194 NSArray *keydef = nil;
195
196 self = [super init];
197 if (self == nil) OK = NO;
198
199 if (OK && [info count] <= EQUIPMENT_LONG_DESC_INDEX) OK = NO;
200
201 if (OK)
202 {
203 // Read required attributes
204 _techLevel = [info oo_unsignedIntAtIndex:EQUIPMENT_TECH_LEVEL_INDEX];
205 _price = [info oo_unsignedIntAtIndex:EQUIPMENT_PRICE_INDEX];
206 _name = [[info oo_stringAtIndex:EQUIPMENT_SHORT_DESC_INDEX] retain];
207 _identifier = [[info oo_stringAtIndex:EQUIPMENT_KEY_INDEX] retain];
208 _description = [[info oo_stringAtIndex:EQUIPMENT_LONG_DESC_INDEX] retain];
209
210 if (_name == nil || _identifier == nil || _description == nil)
211 {
212 OOLog(@"equipment.load", @"***** ERROR: Invalid equipment.plist entry - missing name, identifier or description (\"%@\", %@, \"%@\")", _name, _identifier, _description);
213 OK = NO;
214 }
215 }
216
217 if (OK)
218 {
219 // Implied attributes for backwards-compatibility
220 if ([_identifier hasSuffix:@"_MISSILE"] || [_identifier hasSuffix:@"_MINE"])
221 {
222 _isMissileOrMine = YES;
223 _requiresEmptyPylon = YES;
224 }
225 else if ([_identifier isEqualToString:@"EQ_PASSENGER_BERTH_REMOVAL"])
226 {
227 _requiresFreePassengerBerth = YES;
228 }
229 else if ([_identifier isEqualToString:@"EQ_FUEL"])
230 {
231 _requiresNonFullFuel = YES;
232 }
233 _isVisible = YES;
234 _isAvailableToPlayer = YES;
235 _isAvailableToNPCs = YES;
236 _damageProbability = 1.0;
237 _hideValues = NO;
238 }
239
240 if (OK && [info count] > EQUIPMENT_EXTRA_INFO_INDEX)
241 {
242 // Read extra info dictionary
243 extra = [info oo_dictionaryAtIndex:EQUIPMENT_EXTRA_INFO_INDEX];
244 if (extra != nil)
245 {
246
247 _isAvailableToAll = [extra oo_boolForKey:@"available_to_all" defaultValue:_isAvailableToAll];
248 _isAvailableToPlayer = [extra oo_boolForKey:@"available_to_player" defaultValue:_isAvailableToPlayer];
249 _isAvailableToNPCs = [extra oo_boolForKey:@"available_to_NPCs" defaultValue:_isAvailableToNPCs];
250
251 _isMissileOrMine = [extra oo_boolForKey:@"is_external_store" defaultValue:_isMissileOrMine];
252 _requiresEmptyPylon = [extra oo_boolForKey:@"requires_empty_pylon" defaultValue:_requiresEmptyPylon];
253 _requiresMountedPylon = [extra oo_boolForKey:@"requires_mounted_pylon" defaultValue:_requiresMountedPylon];
254 _requiresClean = [extra oo_boolForKey:@"requires_clean" defaultValue:_requiresClean];
255 _requiresNotClean = [extra oo_boolForKey:@"requires_not_clean" defaultValue:_requiresNotClean];
256 _portableBetweenShips = [extra oo_boolForKey:@"portable_between_ships" defaultValue:_portableBetweenShips];
257 _requiresFreePassengerBerth = [extra oo_boolForKey:@"requires_free_passenger_berth" defaultValue:_requiresFreePassengerBerth];
258 _requiresFullFuel = [extra oo_boolForKey:@"requires_full_fuel" defaultValue:_requiresFullFuel];
259 _requiresNonFullFuel = [extra oo_boolForKey:@"requires_non_full_fuel" defaultValue:_requiresNonFullFuel];
260 _isVisible = [extra oo_boolForKey:@"visible" defaultValue:_isVisible];
261 _canCarryMultiple = [extra oo_boolForKey:@"can_carry_multiple" defaultValue:NO];
262 _hideValues = [extra oo_boolForKey:@"hide_values" defaultValue:NO];
263
264 _requiredCargoSpace = [extra oo_unsignedIntForKey:@"requires_cargo_space" defaultValue:_requiredCargoSpace];
265
266 _installTime = [extra oo_unsignedIntForKey:@"installation_time" defaultValue:0];
267 _repairTime = [extra oo_unsignedIntForKey:@"repair_time" defaultValue:0];
268 _provides = [[extra oo_arrayForKey:@"provides" defaultValue:[NSArray array]] retain];
269
270 id dispColor = [extra oo_objectForKey:@"display_color" defaultValue:nil];
271 _displayColor = [[OOColor colorWithDescription:dispColor] retain];
272
273 _weaponInfo = [[extra oo_dictionaryForKey:@"weapon_info" defaultValue:[NSDictionary dictionary]] retain];
274
275 _damageProbability = [extra oo_floatForKey:@"damage_probability" defaultValue:(_isMissileOrMine?0.0:1.0)];
276
277 id object = [extra objectForKey:@"requires_equipment"];
278 if ([object isKindOfClass:[NSString class]]) _requiresEquipment = [[NSSet setWithObject:object] retain];
279 else if ([object isKindOfClass:[NSArray class]]) _requiresEquipment = [[NSSet setWithArray:object] retain];
280 else if (object != nil)
281 {
282 OOLog(@"equipment.load", @"***** ERROR: %@ for equipment item %@ is not a string or an array.", @"requires_equipment", _identifier);
283 }
284
285 object = [extra objectForKey:@"requires_any_equipment"];
286 if ([object isKindOfClass:[NSString class]]) _requiresAnyEquipment = [[NSSet setWithObject:object] retain];
287 else if ([object isKindOfClass:[NSArray class]]) _requiresAnyEquipment = [[NSSet setWithArray:object] retain];
288 else if (object != nil)
289 {
290 OOLog(@"equipment.load", @"***** ERROR: %@ for equipment item %@ is not a string or an array.", @"requires_any_equipment", _identifier);
291 }
292
293 object = [extra objectForKey:@"incompatible_with_equipment"];
294 if ([object isKindOfClass:[NSString class]]) _incompatibleEquipment = [[NSSet setWithObject:object] retain];
295 else if ([object isKindOfClass:[NSArray class]]) _incompatibleEquipment = [[NSSet setWithArray:object] retain];
296 else if (object != nil)
297 {
298 OOLog(@"equipment.load", @"***** ERROR: %@ for equipment item %@ is not a string or an array.", @"incompatible_with_equipment", _identifier);
299 }
300
301 object = [extra objectForKey:@"conditions"];
302 if ([object isKindOfClass:[NSString class]]) conditions = [NSArray arrayWithObject:object];
303 else if ([object isKindOfClass:[NSArray class]]) conditions = object;
304 else if (object != nil)
305 {
306 OOLog(@"equipment.load", @"***** ERROR: %@ for equipment item %@ is not a string or an array.", @"conditions", _identifier);
307 }
308 if (conditions != nil)
309 {
310 OOStandardsDeprecated([NSString stringWithFormat:@"The conditions key is deprecated for equipment %@",_name]);
311 if (!OOEnforceStandards())
312 {
313 _conditions = OOSanitizeLegacyScriptConditions(conditions, [NSString stringWithFormat:@"<equipment type \"%@\">", _name]);
314 [_conditions retain];
315 }
316 }
317
318 object = [extra objectForKey:@"condition_script"];
319 if ([object isKindOfClass:[NSString class]])
320 {
321 condition_script = object;
322 }
323 else if (object != nil)
324 {
325 OOLog(@"equipment.load", @"***** ERROR: %@ for equipment item %@ is not a string.", @"condition_script", _identifier);
326 }
327 if (condition_script != nil)
328 {
329 _condition_script = [condition_script retain];
330 }
331 /* Condition scripts are shared: all equipment/ships using the
332 * same condition script use one shared instance. Equipment
333 * scripts and ship scripts are not shared and get one instance
334 * per item. */
335
336 _scriptInfo = [extra oo_dictionaryForKey:@"script_info"];
337 [_scriptInfo retain];
338
339 _script = [extra oo_stringForKey:@"script"];
340 if (_script != nil && ![OOScript jsScriptFromFileNamed:_script properties:nil]) _script = nil;
341 [_script retain];
342 if (_script != nil)
343 {
344 _fastAffinityA = !![extra oo_boolForKey:@"fast_affinity_defensive"];
345 _fastAffinityB = !![extra oo_boolForKey:@"fast_affinity_offensive"];
346
347 // look for default activate and mode key settings
348 // note: the customEquipmentActivation array is only populated when starting a game
349 // so the application of any default key settings on equipment will only happen then
350 NSString *checking;
351
352 object = [extra objectForKey:@"default_activate_key"];
353 if ([object isKindOfClass:[NSArray class]]) keydef = object;
354 else if (object != nil)
355 {
356 OOLog(@"equipment.load", @"***** ERROR: %@ for equipment item %@ is not an array.", @"default_activate_key", _identifier);
357 object = nil;
358 }
359
360 if (object != nil)
361 {
362 // do processing for key
363 _defaultActivateKey = [PLAYER processKeyCode:keydef];
364 checking = [PLAYER validateKey:[NSString stringWithFormat:@"activate_%@", _identifier] checkKeys:_defaultActivateKey];
365
366 if (checking != nil) {
367 OOLog(@"equipment.load", @"***** Error: %@ for equipment item %@ is already in use for %@. Default not applied", @"default_activate_key", _identifier, checking);
368 _defaultActivateKey = nil;
369 }
370 }
371
372 object = [extra objectForKey:@"default_mode_key"];
373 if ([object isKindOfClass:[NSArray class]]) keydef = object;
374 else if (object != nil)
375 {
376 OOLog(@"equipment.load", @"***** ERROR: %@ for equipment item %@ is not an array.", @"default_mode_key", _identifier);
377 object = nil;
378 }
379
380 if (object != nil)
381 {
382 // do processing for key
383 _defaultModeKey = [PLAYER processKeyCode:keydef];
384 checking = [PLAYER validateKey:[NSString stringWithFormat:@"mode_%@", _identifier] checkKeys:_defaultModeKey];
385
386 if (checking != nil) {
387 OOLog(@"equipment.load", @"***** Error: %@ for equipment item %@ is already in use for %@. Default not applied.", @"default_mode_key", _identifier, checking);
388 _defaultModeKey = nil;
389 }
390 }
391 }
392 }
393 }
394
395 if (!OK)
396 {
397 [self release];
398 self = nil;
399 }
400 return self;
401}
402
403
404- (void) dealloc
405{
406 DESTROY(_name);
407 DESTROY(_identifier);
408 DESTROY(_description);
409 DESTROY(_displayColor);
410 DESTROY(_requiresEquipment);
411 DESTROY(_requiresAnyEquipment);
412 DESTROY(_incompatibleEquipment);
413 DESTROY(_conditions);
414 DESTROY(_condition_script);
415 DESTROY(_provides);
416 DESTROY(_weaponInfo);
417 DESTROY(_scriptInfo);
418 DESTROY(_script);
419 DESTROY(_defaultActivateKey);
420 DESTROY(_defaultModeKey);
421
422 [super dealloc];
423}
424
425
426- (id) copyWithZone:(NSZone *)zone
427{
428 // OOEquipmentTypes are immutable.
429 return [self retain];
430}
431
432
433- (NSString *) descriptionComponents
434{
435 return [NSString stringWithFormat:@"%@ \"%@\"", _identifier, _name];
436}
437
438
439- (NSString *) identifier
440{
441 return _identifier;
442}
443
444
445- (NSString *) damagedIdentifier
446{
447 return [_identifier stringByAppendingString:@"_DAMAGED"];
448}
449
450
451- (NSString *) name
452{
453 return _name;
454}
455
456
457- (NSString *) descriptiveText
458{
459 return _description;
460}
461
462
463- (OOTechLevelID) techLevel
464{
465 return _techLevel;
466}
467
468
469- (OOCreditsQuantity) price
470{
471 return _price;
472}
473
474
475- (BOOL) isAvailableToAll
476{
477 return _isAvailableToAll;
478}
479
480
481- (BOOL) requiresEmptyPylon
482{
483 return _requiresEmptyPylon;
484}
485
486
487- (BOOL) requiresMountedPylon
488{
489 return _requiresMountedPylon;
490}
491
492
493- (BOOL) requiresCleanLegalRecord
494{
495 return _requiresClean;
496}
497
498
499- (BOOL) requiresNonCleanLegalRecord
500{
501 return _requiresNotClean;
502}
503
504
505- (BOOL) requiresFreePassengerBerth
506{
507 return _requiresFreePassengerBerth;
508}
509
510
511- (BOOL) requiresFullFuel
512{
513 return _requiresFullFuel;
514}
515
516
517- (BOOL) requiresNonFullFuel
518{
519 return _requiresNonFullFuel;
520}
521
522
523- (BOOL) isPrimaryWeapon
524{
525 return [[self identifier] hasPrefix:@"EQ_WEAPON"];
526}
527
528
529- (BOOL) isMissileOrMine
530{
531 return _isMissileOrMine;
532}
533
534
535- (BOOL) isPortableBetweenShips
536{
537 return _portableBetweenShips;
538}
539
540
541- (BOOL) canCarryMultiple
542{
543 if ([self isMissileOrMine]) return YES;
544 // technically multiple can be fitted, but not to the same mount.
545 if ([self isPrimaryWeapon]) return NO;
546
547 // hard-coded as special items
548 if ([_identifier isEqualToString:@"EQ_PASSENGER_BERTH"] ||
549 [_identifier isEqualToString:@"EQ_TRUMBLE"])
550 {
551 return YES;
552 }
553
554 return _canCarryMultiple;
555}
556
557
558- (GLfloat) damageProbability
559{
560 if ([self isMissileOrMine]) return 0.0;
561
562 return _damageProbability;
563}
564
565
566- (BOOL) canBeDamaged
567{
568 if ([self isMissileOrMine]) return NO;
569
570 if ([self damageProbability] > 0.0)
571 {
572 return YES;
573 }
574
575 return NO;
576}
577
578
579- (BOOL) isVisible
580{
581 return _isVisible;
582}
583
584
585- (BOOL) hideValues
586{
587 return _hideValues;
588}
589
590
591- (BOOL) isAvailableToPlayer
592{
593 return _isAvailableToPlayer;
594}
595
596
597- (BOOL) isAvailableToNPCs
598{
599 return _isAvailableToNPCs;
600}
601
602
603- (OOCargoQuantity) requiredCargoSpace
604{
605 return _requiredCargoSpace;
606}
607
608
609- (NSSet *) requiresEquipment
610{
611 return _requiresEquipment;
612}
613
614
615- (NSSet *) requiresAnyEquipment
616{
617 return _requiresAnyEquipment;
618}
619
620
621- (NSSet *) incompatibleEquipment
622{
623 return _incompatibleEquipment;
624}
625
626
627- (OOColor *) displayColor
628{
629 return _displayColor;
630}
631
632
633- (void) setDisplayColor:(OOColor *)color
634{
635 [_displayColor release];
636 _displayColor = [color retain];
637}
638
639
640- (NSArray *) conditions
641{
642 return _conditions;
643}
644
645
646- (NSString *) conditionScript
647{
648 return _condition_script;
649}
650
651
652- (NSDictionary *) scriptInfo
653{
654 return _scriptInfo;
655}
656
657
658- (NSString *) scriptName
659{
660 return _script;
661}
662
663
664- (BOOL) fastAffinityDefensive
665{
666 return _fastAffinityA;
667}
668
669
670- (BOOL) fastAffinityOffensive
671{
672 return _fastAffinityB;
673}
674
675
676- (NSArray *) defaultActivateKey
677{
678 return _defaultActivateKey;
679}
680
681
682- (NSArray *) defaultModeKey
683{
684 return _defaultModeKey;
685}
686
687
688- (NSUInteger) installTime
689{
690 return _installTime;
691}
692
693
694- (NSUInteger) repairTime
695{
696 if (_repairTime > 0)
697 {
698 return _repairTime;
699 }
700 else
701 {
702 return _installTime / 2;
703 }
704}
705
706
707- (NSArray *) providesForScripting
708{
709 return [[_provides copy] autorelease];
710}
711
712
713- (BOOL) provides:(NSString *)key
714{
715 return [_provides containsObject:key];
716}
717
718
719// weapon properties follow
720- (BOOL) isTurretLaser
721{
722 return [_weaponInfo oo_boolForKey:@"is_turret_laser" defaultValue:NO];
723}
724
725
726- (BOOL) isMiningLaser
727{
728 return [_weaponInfo oo_boolForKey:@"is_mining_laser" defaultValue:NO];
729}
730
731
732- (NSDictionary *) weaponInfo
733{
734 return _weaponInfo;
735}
736
737
738- (GLfloat) weaponRange
739{
740 return [_weaponInfo oo_floatForKey:@"range" defaultValue:12500.0];
741}
742
743
744- (GLfloat) weaponEnergyUse
745{
746 return [_weaponInfo oo_floatForKey:@"energy" defaultValue:0.8];
747}
748
749
750- (GLfloat) weaponDamage
751{
752 return [_weaponInfo oo_floatForKey:@"damage" defaultValue:15.0];
753}
754
755
756- (GLfloat) weaponRechargeRate
757{
758 return [_weaponInfo oo_floatForKey:@"recharge_rate" defaultValue:0.5];
759}
760
761
762- (GLfloat) weaponShotTemperature
763{
764 return [_weaponInfo oo_floatForKey:@"shot_temperature" defaultValue:7.0];
765}
766
767
768- (GLfloat) weaponThreatAssessment
769{
770 return [_weaponInfo oo_floatForKey:@"threat_assessment" defaultValue:1.0];
771}
772
773
774- (OOColor *) weaponColor
775{
776 return [OOColor brightColorWithDescription:[_weaponInfo objectForKey:@"color"]];
777}
778
779
780- (NSString *) fxShotMissName
781{
782 return [_weaponInfo oo_stringForKey:@"fx_shot_miss_name" defaultValue:@"[player-laser-miss]"];
783}
784
785
786- (NSString *) fxShotHitName
787{
788 return [_weaponInfo oo_stringForKey:@"fx_shot_hit_name" defaultValue:@"[player-laser-hit]"];
789}
790
791
792- (NSString *) fxShieldHitName
793{
794 return [_weaponInfo oo_stringForKey:@"fx_hitplayer_shielded_name" defaultValue:@"[player-hit-by-weapon]"];
795}
796
797
798- (NSString *) fxUnshieldedHitName
799{
800 return [_weaponInfo oo_stringForKey:@"fx_hitplayer_unshielded_name" defaultValue:@"[player-direct-hit]"];
801}
802
803
804- (NSString *) fxWeaponLaunchedName
805{
806 return [_weaponInfo oo_stringForKey:@"fx_weapon_launch_name" defaultValue:([[self identifier] hasSuffix:@"_MINE"] ? @"[mine-launched]" : @"[missile-launched]")];
807}
808
809
810/* This method exists purely to suppress Clang static analyzer warnings that
811 this ivar is unused (but may be used by categories, which it is).
812 FIXME: there must be a feature macro we can use to avoid actually building
813 this into the app, but I can't find it in docs.
814*/
815- (BOOL) suppressClangStuff
816{
817 return !_jsSelf;
818}
819
820@end
821
822
824
825@implementation OOEquipmentType (Conveniences)
826
827- (OOTechLevelID) effectiveTechLevel
828{
829 OOTechLevelID tl;
830 id missionVar = nil;
831
832 tl = [self techLevel];
833 if (tl == kOOVariableTechLevel)
834 {
835 OOStandardsDeprecated([NSString stringWithFormat:@"TL99 is deprecated for %@",[self identifier]]);
836 if (!OOEnforceStandards())
837 {
838 missionVar = [PLAYER missionVariableForKey:[@"mission_TL_FOR_" stringByAppendingString:[self identifier]]];
839 tl = OOUIntegerFromObject(missionVar, tl);
840 }
841 }
842
843 return tl;
844}
845
846@end
#define DESTROY(x)
Definition OOCocoa.h:75
OOINLINE NSInteger OOUIntegerFromObject(id object, NSUInteger defaultValue)
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,...)
Definition OOLogging.h:88
return self
unsigned count
return nil
uint64_t OOCreditsQuantity
Definition OOTypes.h:182
@ kOOVariableTechLevel
Definition OOTypes.h:202
NSUInteger OOTechLevelID
Definition OOTypes.h:204
uint32_t OOCargoQuantity
Definition OOTypes.h:176
@ EQUIPMENT_LONG_DESC_INDEX
Definition Universe.h:83
@ EQUIPMENT_EXTRA_INFO_INDEX
Definition Universe.h:84
void setObject:forKey:inCache:(id inElement,[forKey] NSString *inKey,[inCache] NSString *inCacheKey)
OOCacheManager * sharedCache()
OOColor * brightColorWithDescription:(id description)
Definition OOColor.m:205
OOColor * colorWithDescription:(id description)
Definition OOColor.m:127
NSString * conditionScript()
NSString * identifier()