Oolite 1.91.0.7646-241128-10e222e
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

Extends class OORoleSet.

Definition at line 315 of file OORoleSet.m.

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

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