197- (id)roleSetWithAddedRoleIfNotSet:(NSString*)role probability:(
float)probability
199 NSMutableDictionary* dict =
nil;
201 if (role ==
nil || probability < 0 || ([
self hasRole:role] && [
self probabilityForRole:role] == probability)) {
202 return [[
self copy] autorelease];
205 dict = [[_rolesAndProbabilities mutableCopy] autorelease];
206 [
dict setObject:[
NSNumber numberWithFloat:probability] forKey:role];
207 return [[[[
self class] alloc] initWithRolesAndProbabilities:dict] autorelease];
210- (id)roleSetWithAddedRole:(NSString*)role probability:(
float)probability
212 NSMutableDictionary* dict =
nil;
214 if (role ==
nil || probability < 0 || [
self hasRole:role]) {
215 return [[
self copy] autorelease];
218 dict = [[_rolesAndProbabilities mutableCopy] autorelease];
219 [
dict setObject:[
NSNumber numberWithFloat:probability] forKey:role];
220 return [[[[
self class] alloc] initWithRolesAndProbabilities:dict] autorelease];
223- (id)roleSetWithRemovedRole:(NSString*)role
225 NSMutableDictionary* dict =
nil;
227 if (![
self hasRole:role])
228 return [[
self copy] autorelease];
230 dict = [[_rolesAndProbabilities mutableCopy] autorelease];
231 [
dict removeObjectForKey:role];
232 return [[[[
self class] alloc] initWithRolesAndProbabilities:dict] autorelease];
239- (id)initWithRolesAndProbabilities:(NSDictionary*)dict
241 NSString* role =
nil;
257 assert(_roles ==
nil && _roleString ==
nil);
259 NSMutableDictionary* tDict = [[
dict mutableCopy] autorelease];
260 float thargProb = [
dict oo_floatForKey:@"thargon" defaultValue:0.0f];
262 if (thargProb > 0.0f && [dict objectForKey:
@"EQ_THARGON"] ==
nil) {
263 [
tDict setObject:[
NSNumber numberWithFloat:thargProb] forKey:@"EQ_THARGON"];
264 [
tDict removeObjectForKey:@"thargon"];
267 _rolesAndProbabilities = [
tDict copy];
271 prob = [
dict oo_floatForKey:role defaultValue:-1];
273 OOLog(
@"roleSet.badValue",
@"Attempt to create a role set with negative or non-numerical probability for role %@.", role);
288 NSMutableDictionary* result =
nil;
289 NSArray* tokens =
nil;
291 NSString* role =
nil;
293 NSScanner* scanner =
nil;
300 count = [tokens count];
304 result = [NSMutableDictionary dictionaryWithCapacity:count];
307 for (i = 0; i !=
count; ++i) {
308 role = [tokens objectAtIndex:i];
311 if ([role rangeOfString:
@"("].location != NSNotFound) {
312 scanner = [[NSScanner alloc] initWithString:role];
313 [scanner scanUpToString:@"(" intoString:&role];
314 [scanner scanString:@"(" intoString:NULL];
315 if (![scanner scanFloat:&probability])
323 if (0 <= probability && ![role hasPrefix:
@"["]) {
324 [result setObject:[NSNumber numberWithFloat:probability] forKey:role];
328 if ([result
count] == 0)