Oolite 1.91.0.7646-241128-10e222e
Loading...
Searching...
No Matches
OOEquipmentType(Private) Category Reference

Instance Methods

(id) - initWithInfo:
 

Detailed Description

Definition at line 43 of file OOEquipmentType.m.

Method Documentation

◆ initWithInfo:

- (id) initWithInfo: (NSArray *) info

Extends class OOEquipmentType.

Definition at line 40 of file OOEquipmentType.m.

189 :(NSArray *)info
190{
191 BOOL OK = YES;
192 NSDictionary *extra = nil;
193 NSArray *conditions = nil;
194 NSString *condition_script = nil;
195 NSArray *keydef = nil;
196
197 self = [super init];
198 if (self == nil) OK = NO;
199
200 if (OK && [info count] <= EQUIPMENT_LONG_DESC_INDEX) OK = NO;
201
202 if (OK)
203 {
204 // Read required attributes
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
211 if (_name == nil || _identifier == nil || _description == nil)
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 // Implied attributes for backwards-compatibility
221 if ([_identifier hasSuffix:@"_MISSILE"] || [_identifier hasSuffix:@"_MINE"])
222 {
223 _isMissileOrMine = YES;
224 _requiresEmptyPylon = YES;
225 }
226 else if ([_identifier isEqualToString:@"EQ_PASSENGER_BERTH_REMOVAL"])
227 {
228 _requiresFreePassengerBerth = YES;
229 }
230 else if ([_identifier isEqualToString:@"EQ_FUEL"])
231 {
232 _requiresNonFullFuel = YES;
233 }
234 _isVisible = YES;
235 _isAvailableToPlayer = YES;
236 _isAvailableToNPCs = YES;
237 _damageProbability = 1.0;
238 _hideValues = NO;
239 }
240
241 if (OK && [info count] > EQUIPMENT_EXTRA_INFO_INDEX)
242 {
243 // Read extra info dictionary
244 extra = [info oo_dictionaryAtIndex:EQUIPMENT_EXTRA_INFO_INDEX];
245 if (extra != nil)
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];
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];
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];
272 _displayColor = [[OOColor colorWithDescription:dispColor] retain];
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 }
309 if (conditions != nil)
310 {
311 OOStandardsDeprecated([NSString stringWithFormat:@"The conditions key is deprecated for equipment %@",_name]);
312 if (!OOEnforceStandards())
313 {
314 _conditions = OOSanitizeLegacyScriptConditions(conditions, [NSString stringWithFormat:@"<equipment type \"%@\">", _name]);
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 {
330 _condition_script = [condition_script retain];
331 }
332 /* Condition scripts are shared: all equipment/ships using the
333 * same condition script use one shared instance. Equipment
334 * scripts and ship scripts are not shared and get one instance
335 * per item. */
336
337 _scriptInfo = [extra oo_dictionaryForKey:@"script_info"];
338 [_scriptInfo retain];
339
340 _script = [extra oo_stringForKey:@"script"];
341 if (_script != nil && ![OOScript jsScriptFromFileNamed:_script properties:nil]) _script = nil;
342 [_script retain];
343 if (_script != nil)
344 {
345 _fastAffinityA = !![extra oo_boolForKey:@"fast_affinity_defensive"];
346 _fastAffinityB = !![extra oo_boolForKey:@"fast_affinity_offensive"];
347
348 // look for default activate and mode key settings
349 // note: the customEquipmentActivation array is only populated when starting a game
350 // so the application of any default key settings on equipment will only happen then
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);
358 object = nil;
359 }
360
361 if (object != nil)
362 {
363 // do processing for key
364 _defaultActivateKey = [PLAYER processKeyCode:keydef];
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);
369 _defaultActivateKey = nil;
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);
378 object = nil;
379 }
380
381 if (object != nil)
382 {
383 // do processing for key
384 _defaultModeKey = [PLAYER processKeyCode:keydef];
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);
389 _defaultModeKey = nil;
390 }
391 }
392 }
393 }
394 }
395
396 if (!OK)
397 {
398 [self release];
399 self = nil;
400 }
401 return self;
402}
void OOStandardsDeprecated(NSString *message)
BOOL OOEnforceStandards(void)
NSArray * OOSanitizeLegacyScriptConditions(NSArray *conditions, NSString *context)
#define OOLog(class, format,...)
Definition OOLogging.h:88
unsigned count
return nil
@ EQUIPMENT_LONG_DESC_INDEX
Definition Universe.h:83
@ EQUIPMENT_EXTRA_INFO_INDEX
Definition Universe.h:84
OOColor * colorWithDescription:(id description)
Definition OOColor.m:127

The documentation for this category was generated from the following file: