#include <OORoleSet.h>
Definition at line 35 of file OORoleSet.h.
◆ anyRole
Definition at line 312 of file OORoleSet.m.
193{
194 NSString *role =
nil;
195 float prob, selected;
196
198 prob = 0.0f;
199
201
203 {
205 if (selected <= prob) break;
206 }
208 {
209 role = [[self roles] anyObject];
210 OOLog(
@"roleSet.anyRole.failed",
@"Could not get a weighted-random role from role set %@, returning unweighted selection %@. TotalProb: %g, selected: %g, prob at end: %f",
self, role,
_totalProb, selected, prob);
211 }
212 return role;
213}
#define foreachkey(VAR, DICT)
#define OOLog(class, format,...)
NSDictionary * _rolesAndProbabilities
References count, nil, and ScanTokensFromString().
◆ copyWithZone:
| - (id) copyWithZone: |
|
(NSZone *) |
zone |
|
|
implementation |
Definition at line 312 of file OORoleSet.m.
108 :(NSZone *)zone
109{
110
111 return [self retain];
112}
◆ dealloc
Definition at line 312 of file OORoleSet.m.
77{
78 [_roleString autorelease];
79 [_rolesAndProbabilities autorelease];
80 [_roles autorelease];
81
82 [super dealloc];
83}
◆ description
| - (NSString *) description |
|
|
|
|
implementation |
Definition at line 312 of file OORoleSet.m.
87{
88 return [NSString stringWithFormat:@"<%@ %p>{%@}", [self class], self, [self roleString]];
89}
◆ hash
Definition at line 312 of file OORoleSet.m.
103{
104 return [_rolesAndProbabilities hash];
105}
◆ hasRole:
| - (BOOL) hasRole: |
|
(NSString *) |
role |
|
Definition at line 312 of file OORoleSet.m.
149 :(NSString *)role
150{
151 return role !=
nil && [_rolesAndProbabilities objectForKey:role] !=
nil;
152}
◆ initWithRole:probability:
| - (id) initWithRole: |
|
(NSString *) |
role |
| probability: |
|
(float) |
probability |
|
|
| |
Definition at line 312 of file OORoleSet.m.
64 :(NSString *)role probability:(float)probability
65{
66 NSDictionary *dict =
nil;
67
68 if (role !=
nil && 0 <= probability)
69 {
70 dict = [NSDictionary dictionaryWithObject:[NSNumber numberWithFloat:probability] forKey:role];
71 }
72 return [self initWithRolesAndProbabilities:dict];
73}
◆ initWithRolesAndProbabilities:
| - (id) initWithRolesAndProbabilities: |
|
(NSDictionary *) |
dict |
|
|
implementation |
Provided by category OORoleSet(OOPrivate).
Definition at line 312 of file OORoleSet.m.
262 :(NSDictionary *)dict
263{
264 NSString *role =
nil;
265 float prob;
266
268 {
269 [self release];
271 }
272
273 self = [super init];
274 if (
self ==
nil)
return nil;
275
276
277
278
279
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
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];
301 }
302
303 _totalProb += prob;
304 }
305
306 return self;
307}
◆ initWithRoleString:
| - (id) initWithRoleString: |
|
(NSString *) |
roleString |
|
Definition at line 312 of file OORoleSet.m.
56{
57 NSDictionary *dict =
nil;
58
60 return [self initWithRolesAndProbabilities:dict];
61}
NSDictionary * OOParseRolesFromString(NSString *string)
◆ intersectsSet:
| - (BOOL) intersectsSet: |
|
(id) |
set |
|
Definition at line 312 of file OORoleSet.m.
161 :(id)set
162{
164 else if (![set isKindOfClass:[NSSet class]]) return NO;
165
166 return [[self roles] intersectsSet:set];
167}
◆ isEqual:
| - (BOOL) isEqual: |
|
(id) |
other |
|
|
implementation |
Definition at line 312 of file OORoleSet.m.
92 :(id)other
93{
94 if ([other isKindOfClass:[
OORoleSet class]])
95 {
96 return [_rolesAndProbabilities isEqual:[other rolesAndProbabilities]];
97 }
98 else return NO;
99}
◆ probabilityForRole:
| - (float) probabilityForRole: |
|
(NSString *) |
role |
|
Definition at line 312 of file OORoleSet.m.
155 :(NSString *)role
156{
157 return [_rolesAndProbabilities oo_floatForKey:role defaultValue:0.0f];
158}
◆ roles
Definition at line 312 of file OORoleSet.m.
171{
173 {
174 _roles = [[NSSet alloc] initWithArray:[_rolesAndProbabilities allKeys]];
175 }
177}
◆ rolesAndProbabilities
| - (NSDictionary *) rolesAndProbabilities |
|
|
|
◆ roleSetWithAddedRole:probability:
| - (id) roleSetWithAddedRole: |
|
(NSString *) |
role |
| probability: |
|
(float) |
probability |
|
|
| |
Definition at line 312 of file OORoleSet.m.
231 :(NSString *)role probability:(float)probability
232{
233 NSMutableDictionary *dict =
nil;
234
235 if (role ==
nil || probability < 0 || [
self hasRole:role])
236 {
237 return [[self copy] autorelease];
238 }
239
240 dict = [[_rolesAndProbabilities mutableCopy] autorelease];
241 [dict setObject:[NSNumber numberWithFloat:probability] forKey:role];
242 return [[[[self class] alloc] initWithRolesAndProbabilities:dict] autorelease];
243}
◆ roleSetWithAddedRoleIfNotSet:probability:
| - (id) roleSetWithAddedRoleIfNotSet: |
|
(NSString *) |
role |
| probability: |
|
(float) |
probability |
|
|
| |
Definition at line 312 of file OORoleSet.m.
216 :(NSString *)role probability:(float)probability
217{
218 NSMutableDictionary *dict =
nil;
219
220 if (role ==
nil || probability < 0 || ([
self hasRole:role] && [
self probabilityForRole:role] == probability))
221 {
222 return [[self copy] autorelease];
223 }
224
225 dict = [[_rolesAndProbabilities mutableCopy] autorelease];
226 [dict setObject:[NSNumber numberWithFloat:probability] forKey:role];
227 return [[[[self class] alloc] initWithRolesAndProbabilities:dict] autorelease];
228}
◆ roleSetWithRemovedRole:
| - (id) roleSetWithRemovedRole: |
|
(NSString *) |
role |
|
Definition at line 312 of file OORoleSet.m.
246 :(NSString *)role
247{
248 NSMutableDictionary *dict =
nil;
249
250 if (![
self hasRole:role]) return [[
self copy] autorelease];
251
252 dict = [[_rolesAndProbabilities mutableCopy] autorelease];
253 [dict removeObjectForKey:role];
254 return [[[[self class] alloc] initWithRolesAndProbabilities:dict] autorelease];
255}
◆ roleSetWithRole:probability:
| + (instancetype) roleSetWithRole: |
|
(NSString *) |
role |
| probability: |
|
(float) |
probability |
|
|
| |
Definition at line 312 of file OORoleSet.m.
50 :(NSString *)role probability:(float)probability
51{
52 return [[[self alloc] initWithRole:role probability:probability] autorelease];
53}
◆ roleSetWithString:
| + (instancetype) roleSetWithString: |
|
(NSString *) |
roleString |
|
Definition at line 312 of file OORoleSet.m.
45{
46 return [[[self alloc] initWithRoleString:roleString] autorelease];
47}
◆ roleString
| - (NSString *) roleString |
|
|
|
Definition at line 312 of file OORoleSet.m.
116{
118 NSString *role =
nil;
119 float probability;
120 NSMutableString *result =
nil;
121 BOOL first = YES;
122
124 {
125
126 result = [NSMutableString string];
127 roles = [
self sortedRoles];
128 foreach (role,
roles)
129 {
130 if (!first) [result appendString:@" "];
131 else first = NO;
132
133 [result appendString:role];
134
135 probability = [self probabilityForRole:role];
136 if (probability != 1.0f)
137 {
138 [result appendFormat:@"(%g)", probability];
139 }
140 }
141
143 }
144
146}
◆ sortedRoles
| - (NSArray *) sortedRoles |
|
|
|
Definition at line 312 of file OORoleSet.m.
181{
182 return [[_rolesAndProbabilities allKeys] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
183}
Referenced by ShipGetProperty().
◆ _roles
◆ _rolesAndProbabilities
| - (NSDictionary*) _rolesAndProbabilities |
|
private |
◆ _roleString
| - (NSString*) _roleString |
|
private |
◆ _totalProb
The documentation for this class was generated from the following files: