Oolite
Loading...
Searching...
No Matches
OORoleSet(OOPrivate) Category Reference

Instance Methods

(id) - initWithRolesAndProbabilities:
 

Detailed Description

Definition at line 35 of file OORoleSet.m.

Method Documentation

◆ initWithRolesAndProbabilities:

- (id) initWithRolesAndProbabilities: (NSDictionary *)  dict

Definition at line 312 of file OORoleSet.m.

262 :(NSDictionary *)dict
263{
264 NSString *role = nil;
265 float prob;
266
267 if (dict == nil)
268 {
269 [self release];
270 return nil;
271 }
272
273 self = [super init];
274 if (self == nil) return nil;
275
276 // Note: _roles and _roleString are derived on the fly as needed.
277 // MKW 20090815 - if we are re-initialising this OORoleSet object, we need
278 // to ensure that _roles and _roleString are cleared.
279 // Why would we be re-initing? That's never valid. -- Ahruman 2010-02-06
280 assert(_roles == nil && _roleString == nil);
281
282 NSMutableDictionary *tDict = [[dict mutableCopy] autorelease];
283 float thargProb = [dict oo_floatForKey:@"thargon" defaultValue:0.0f];
284
285 if ( thargProb > 0.0f && [dict objectForKey:@"EQ_THARGON"] == nil)
286 {
287 [tDict setObject:[NSNumber numberWithFloat:thargProb] forKey:@"EQ_THARGON"];
288 [tDict removeObjectForKey:@"thargon"];
289 }
290
291 _rolesAndProbabilities = [tDict copy];
292
293 foreachkey (role, dict)
294 {
295 prob = [dict oo_floatForKey:role defaultValue:-1];
296 if (prob < 0)
297 {
298 OOLog(@"roleSet.badValue", @"Attempt to create a role set with negative or non-numerical probability for role %@.", role);
299 [self release];
300 return nil;
301 }
302
303 _totalProb += prob;
304 }
305
306 return self;
307}
#define foreachkey(VAR, DICT)
Definition OOCocoa.h:353
#define OOLog(class, format,...)
Definition OOLogging.h:88
return nil

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