Oolite 1.91.0.7644-241112-7f5034b
Loading...
Searching...
No Matches
OORoleSet.h
Go to the documentation of this file.
1/*
2
3OORoleSet.h
4
5Manage a set of roles for a ship (or ship type), including probabilities.
6
7A role set is an immutable object.
8
9
10Copyright (C) 2007-2013 Jens Ayton
11
12Permission is hereby granted, free of charge, to any person obtaining a copy
13of this software and associated documentation files (the "Software"), to deal
14in the Software without restriction, including without limitation the rights
15to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16copies of the Software, and to permit persons to whom the Software is
17furnished to do so, subject to the following conditions:
18
19The above copyright notice and this permission notice shall be included in all
20copies or substantial portions of the Software.
21
22THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28SOFTWARE.
29
30*/
31
32#import "OOCocoa.h"
33
34
35@interface OORoleSet: NSObject <NSCopying>
36{
37@private
38 NSString *_roleString;
40 NSSet *_roles;
43
44+ (instancetype) roleSetWithString:(NSString *)roleString;
45+ (instancetype) roleSetWithRole:(NSString *)role probability:(float)probability;
46
47- (id)initWithRoleString:(NSString *)roleString;
48- (id)initWithRole:(NSString *)role probability:(float)probability;
49
50- (NSString *)roleString;
51
52- (BOOL)hasRole:(NSString *)role;
53- (float)probabilityForRole:(NSString *)role;
54- (BOOL)intersectsSet:(id)set; // set may be an OORoleSet or an NSSet.
55
56- (NSSet *)roles;
57- (NSArray *)sortedRoles;
58- (NSDictionary *)rolesAndProbabilities;
59
60// Returns a random role, taking probabilities into account.
61- (NSString *)anyRole;
62
63 // Creating modified copies of role sets:
64- (id)roleSetWithAddedRole:(NSString *)role probability:(float)probability;
65- (id)roleSetWithAddedRoleIfNotSet:(NSString *)role probability:(float)probability; // Unlike the above, does not change probability if role exists.
66- (id)roleSetWithRemovedRole:(NSString *)role;
67
68@end
69
70
71// Returns a dictionary whose keys are roles and whose values are weights.
72NSDictionary *OOParseRolesFromString(NSString *string);
NSDictionary * OOParseRolesFromString(NSString *string)
float _totalProb
Definition OORoleSet.h:42
NSDictionary * _rolesAndProbabilities
Definition OORoleSet.h:40
NSString * _roleString
Definition OORoleSet.h:39
NSSet * _roles
Definition OORoleSet.h:41