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

Instance Methods

(id) - initWithRolesAndProbabilities:

Detailed Description

Definition at line 34 of file OORoleSet.m.

Method Documentation

◆ initWithRolesAndProbabilities:

- (id) initWithRolesAndProbabilities: (NSDictionary*) dict

Extends class OORoleSet.

Definition at line 239 of file OORoleSet.m.

239 :(NSDictionary*)dict
240{
241 NSString* role = nil;
242 float prob;
243
244 if (dict == nil) {
245 [self release];
246 return nil;
247 }
248
249 self = [super init];
250 if (self == nil)
251 return nil;
252
253 // Note: _roles and _roleString are derived on the fly as needed.
254 // MKW 20090815 - if we are re-initialising this OORoleSet object, we need
255 // to ensure that _roles and _roleString are cleared.
256 // Why would we be re-initing? That's never valid. -- Ahruman 2010-02-06
257 assert(_roles == nil && _roleString == nil);
258
259 NSMutableDictionary* tDict = [[dict mutableCopy] autorelease];
260 float thargProb = [dict oo_floatForKey:@"thargon" defaultValue:0.0f];
261
262 if (thargProb > 0.0f && [dict objectForKey:@"EQ_THARGON"] == nil) {
263 [tDict setObject:[NSNumber numberWithFloat:thargProb] forKey:@"EQ_THARGON"];
264 [tDict removeObjectForKey:@"thargon"];
265 }
266
267 _rolesAndProbabilities = [tDict copy];
268
269 foreachkey(role, dict)
270 {
271 prob = [dict oo_floatForKey:role defaultValue:-1];
272 if (prob < 0) {
273 OOLog(@"roleSet.badValue", @"Attempt to create a role set with negative or non-numerical probability for role %@.", role);
274 [self release];
275 return nil;
276 }
277
278 _totalProb += prob;
279 }
280
281 return self;
282}
#define foreachkey(VAR, DICT)
#define OOLog(class, format,...)
Definition OOLogging.h:84
return nil

References foreachkey, nil, and OOLog.


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