Oolite
Loading...
Searching...
No Matches
OOCommodityMarket Class Reference

#include <OOCommodityMarket.h>

Inheritance diagram for OOCommodityMarket:
Collaboration diagram for OOCommodityMarket:

Instance Methods

(NSUInteger) - count
(void) - setGood:withInfo:
(NSArray *) - goods
(NSDictionary *) - dictionaryForScripting
(BOOL) - setPrice:forGood:
(BOOL) - setQuantity:forGood:
(BOOL) - addQuantity:forGood:
(BOOL) - removeQuantity:forGood:
(void) - removeAllGoods
(BOOL) - setComment:forGood:
(BOOL) - setShortComment:forGood:
(NSString *) - nameForGood:
(NSString *) - commentForGood:
(NSString *) - shortCommentForGood:
(OOCreditsQuantity) - priceForGood:
(OOCargoQuantity) - quantityForGood:
(OOMassUnit) - massUnitForGood:
(NSUInteger) - exportLegalityForGood:
(NSUInteger) - importLegalityForGood:
(OOCargoQuantity) - capacityForGood:
(float) - trumbleOpinionForGood:
(NSDictionary *) - definitionForGood:
(NSArray *) - savePlayerAmounts
(void) - loadPlayerAmounts:
(NSArray *) - saveStationAmounts
(void) - loadStationAmounts:
(id) - init [implementation]
(void) - dealloc [implementation]

Private Attributes

NSMutableDictionary * _commodityList
NSArray * _sortedKeys

Detailed Description

Definition at line 31 of file OOCommodityMarket.h.

Method Documentation

◆ addQuantity:forGood:

- (BOOL) addQuantity: (OOCargoQuantity) quantity
forGood: (OOCommodityType) good 

Definition at line 100 of file OOCommodityMarket.m.

100 :(OOCargoQuantity)quantity forGood:(OOCommodityType)good
101{
102 OOCargoQuantity current = [self quantityForGood:good];
103 if (current + quantity > [self capacityForGood:good]) {
104 return NO;
105 }
106 [self setQuantity:(current + quantity) forGood:good];
107 return YES;
108}
NSString * OOCommodityType
Definition OOTypes.h:97
uint32_t OOCargoQuantity
Definition OOTypes.h:155

References quantityForGood:, and setQuantity:forGood:.

Referenced by PlayerEntity::tryBuyingCommodity:all:, PlayerEntity::trySellingCommodity:all:, and PlayerEntity::unloadAllCargoPodsForType:toManifest:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ capacityForGood:

- (OOCargoQuantity) capacityForGood: (OOCommodityType) good

Definition at line 220 of file OOCommodityMarket.m.

220 :(OOCommodityType)good
221{
222 NSDictionary* definition = [_commodityList oo_dictionaryForKey:good];
223 if (definition == nil) {
224 return 0;
225 }
226 // should only be undefined for main system markets, not secondary stations
227 // meaningless for player ship, though
228 return [definition oo_unsignedIntForKey:kOOCommodityCapacity defaultValue:MAIN_SYSTEM_MARKET_LIMIT];
229}
return nil

References nil.

Referenced by PlayerEntity::tryBuyingCommodity:all:, and PlayerEntity::trySellingCommodity:all:.

Here is the caller graph for this function:

◆ commentForGood:

- (NSString *) commentForGood: (OOCommodityType) good

Definition at line 157 of file OOCommodityMarket.m.

157 :(OOCommodityType)good
158{
159 NSDictionary* definition = [_commodityList oo_dictionaryForKey:good];
160 if (definition == nil) {
161 return OOExpand(@"[oolite-unknown-commodity-name]");
162 }
163 return OOExpand([definition oo_stringForKey:kOOCommodityComment defaultValue:@"[oolite-commodity-no-comment]"]);
164}
static NSString *const kOOCommodityComment
#define OOExpand(string,...)

References kOOCommodityComment, nil, and OOExpand.

Referenced by PlayerEntity::setGuiToMarketInfoScreen.

Here is the caller graph for this function:

◆ count

- (NSUInteger) count

Definition at line 54 of file OOCommodityMarket.m.

55{
56 return [_commodityList count];
57}

References count.

Referenced by PlayerEntity::cargoListForScripting, count, Universe::getContainersOfGoods:scarce:legal:, savePlayerAmounts, saveStationAmounts, PlayerEntity::setGuiToMarketInfoScreen, and PlayerEntity::setGuiToMarketScreen.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dealloc

- (void) dealloc
implementation

Definition at line 47 of file OOCommodityMarket.m.

48{
51 [super dealloc];
52}
#define DESTROY(x)
NSMutableDictionary * _commodityList

References _commodityList, _sortedKeys, dealloc, and DESTROY.

Referenced by dealloc.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ definitionForGood:

- (NSDictionary *) definitionForGood: (OOCommodityType) good

Definition at line 240 of file OOCommodityMarket.m.

240 :(OOCommodityType)good
241{
242 return [[[_commodityList oo_dictionaryForKey:good] copy] autorelease];
243}

Referenced by Universe::commodityDataForType:.

Here is the caller graph for this function:

◆ dictionaryForScripting

- (NSDictionary *) dictionaryForScripting

Definition at line 75 of file OOCommodityMarket.m.

76{
77 return [[_commodityList copy] autorelease];
78}

References dictionaryForScripting.

Referenced by dictionaryForScripting, and StationEntity::localMarketForScripting.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ exportLegalityForGood:

- (NSUInteger) exportLegalityForGood: (OOCommodityType) good

Definition at line 202 of file OOCommodityMarket.m.

202 :(OOCommodityType)good
203{
204 NSDictionary* definition = [_commodityList oo_dictionaryForKey:good];
205 if (definition == nil) {
206 return 0;
207 }
208 return [definition oo_unsignedIntegerForKey:kOOCommodityLegalityExport];
209}

References nil.

Referenced by PlayerEntity::legalStatusOfCargoList, StationEntity::legalStatusOfManifest:export:, and PlayerEntity(OOPrivate)::showMarketScreenDataLine:forGood:inMarket:holdQuantity:.

Here is the caller graph for this function:

◆ goods

- (NSArray *) goods

Definition at line 66 of file OOCommodityMarket.m.

67{
68 if (_sortedKeys == nil) {
69 NSArray* keys = [_commodityList allKeys];
70 _sortedKeys = [[keys sortedArrayUsingFunction:goodsSorter context:_commodityList] retain];
71 }
72 return _sortedKeys;
73}

References _sortedKeys, goods, and nil.

Referenced by PlayerEntity::cargoListForScripting, Universe::getContainersOfGoods:scarce:legal:, goods, loadPlayerAmounts:, loadStationAmounts:, PlayerEntity(OOControlsPrivate)::pollMarketScreenControls, savePlayerAmounts, saveStationAmounts, PlayerEntity::setGuiToMarketInfoScreen, and PlayerEntity::setGuiToMarketScreen.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ importLegalityForGood:

- (NSUInteger) importLegalityForGood: (OOCommodityType) good

Definition at line 211 of file OOCommodityMarket.m.

211 :(OOCommodityType)good
212{
213 NSDictionary* definition = [_commodityList oo_dictionaryForKey:good];
214 if (definition == nil) {
215 return 0;
216 }
217 return [definition oo_unsignedIntegerForKey:kOOCommodityLegalityImport];
218}

References nil.

Referenced by StationEntity::legalStatusOfManifest:export:, and PlayerEntity(OOPrivate)::showMarketScreenDataLine:forGood:inMarket:holdQuantity:.

Here is the caller graph for this function:

◆ init

- (id) init
implementation

Definition at line 34 of file OOCommodityMarket.m.

35{
36 self = [super init];
37 if (self == nil)
38 return nil;
39
40 _commodityList = [[NSMutableDictionary dictionaryWithCapacity:24] retain];
41
43
44 return self;
45}

References _commodityList, _sortedKeys, init, and nil.

Referenced by init.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ loadPlayerAmounts:

- (void) loadPlayerAmounts: (NSArray*) amounts

Definition at line 255 of file OOCommodityMarket.m.

255 :(NSArray*)amounts
256{
258 BOOL loadedOK;
259 NSString* good = nil;
260 foreach (good, [self goods]) {
261 // make sure that any goods not defined in the save game are zeroed
262 [self setQuantity:0 forGood:good];
263 }
264
265 NSArray* loaded = nil;
266 foreach (loaded, amounts) {
267 loadedOK = NO;
268 good = [loaded oo_stringAtIndex:0];
269 q = [loaded oo_unsignedIntAtIndex:1];
270 // old save games might have more in the array, but we don't care
271 if (![self setQuantity:q forGood:good]) {
272 // then it's an array from a 1.80-or-earlier save game and
273 // the good name is the description string (maybe a
274 // translated one)
275 OOCommodityType key = nil;
276 foreach (key, [self goods]) {
277 if ([good isEqualToString:[self nameForGood:key]]) {
278 [self setQuantity:q forGood:key];
279 loadedOK = YES;
280 break;
281 }
282 }
283 } else {
284 loadedOK = YES;
285 }
286 if (!loadedOK) {
287 OOLog(@"setCommanderDataFromDictionary.warning.cargo", @"Cargo %@ (%u units) could not be loaded from the saved game, as it is no longer defined", good, q);
288 }
289 }
290}
#define OOLog(class, format,...)
Definition OOLogging.h:84

References goods, nil, OOLog, and setQuantity:forGood:.

Referenced by PlayerEntity::setCommanderDataFromDictionary:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ loadStationAmounts:

- (void) loadStationAmounts: (NSArray*) amounts

Definition at line 302 of file OOCommodityMarket.m.

302 :(NSArray*)amounts
303{
306 BOOL loadedOK;
307 NSString* good = nil;
308
309 NSArray* loaded = nil;
310 foreach (loaded, amounts) {
311 loadedOK = NO;
312 good = [loaded oo_stringAtIndex:0];
313 q = [loaded oo_unsignedIntAtIndex:1];
314 p = [loaded oo_unsignedIntegerAtIndex:2];
315 // old save games might have more in the array, but we don't care
316 if (![self setQuantity:q forGood:good]) {
317 // then it's an array from a 1.80-or-earlier save game and
318 // the good name is the description string (maybe a
319 // translated one)
320 OOCommodityType key = nil;
321 foreach (key, [self goods]) {
322 if ([good isEqualToString:[self nameForGood:key]]) {
323 [self setQuantity:q forGood:key];
324 [self setPrice:p forGood:key];
325 loadedOK = YES;
326 break;
327 }
328 }
329 } else {
330 [self setPrice:p forGood:good];
331 loadedOK = YES;
332 }
333 if (!loadedOK) {
334 OOLog(@"load.warning.cargo", @"Station market good %@ (%u units) could not be loaded from the saved game, as it is no longer defined", good, q);
335 }
336 }
337}
uint64_t OOCreditsQuantity
Definition OOTypes.h:160

References goods, nil, OOLog, setPrice:forGood:, and setQuantity:forGood:.

Referenced by StationEntity::setLocalMarket:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ massUnitForGood:

- (OOMassUnit) massUnitForGood: (OOCommodityType) good

Definition at line 193 of file OOCommodityMarket.m.

193 :(OOCommodityType)good
194{
195 NSDictionary* definition = [_commodityList oo_dictionaryForKey:good];
196 if (definition == nil) {
197 return UNITS_TONS;
198 }
199 return [definition oo_unsignedIntForKey:kOOCommodityContainer];
200}
@ UNITS_TONS
Definition OOTypes.h:112

References nil, and UNITS_TONS.

Referenced by PlayerEntity::cargoQuantityOnBoard, Universe::describeCommodity:amount:, PlayerEntity::loadCargoPodsForType:amount:, PlayerEntity::loadCargoPodsForType:fromManifest:, marketSorterByMassUnit(), PlayerEntity::setCargoQuantityForType:amount:, PlayerEntity::setCommanderDataFromDictionary:, PlayerEntity::setGuiToMarketInfoScreen, and PlayerEntity::tryBuyingCommodity:all:.

Here is the caller graph for this function:

◆ nameForGood:

- (NSString *) nameForGood: (OOCommodityType) good

Definition at line 148 of file OOCommodityMarket.m.

148 :(OOCommodityType)good
149{
150 NSDictionary* definition = [_commodityList oo_dictionaryForKey:good];
151 if (definition == nil) {
152 return OOExpand(@"[oolite-unknown-commodity-name]");
153 }
154 return OOExpand([definition oo_stringForKey:kOOCommodityName defaultValue:@"[oolite-unknown-commodity-name]"]);
155}
static NSString *const kOOCommodityName

References kOOCommodityName, nil, and OOExpand.

Referenced by PlayerEntity::cargoListForScripting, Universe::describeCommodity:amount:, Universe::displayNameForCommodity:, marketSorterByName(), and PlayerEntity::setGuiToMarketInfoScreen.

Here is the caller graph for this function:

◆ priceForGood:

- (OOCreditsQuantity) priceForGood: (OOCommodityType) good

Definition at line 175 of file OOCommodityMarket.m.

175 :(OOCommodityType)good
176{
177 NSDictionary* definition = [_commodityList oo_dictionaryForKey:good];
178 if (definition == nil) {
179 return 0;
180 }
181 return [definition oo_unsignedIntegerForKey:kOOCommodityPriceCurrent];
182}

References nil.

Referenced by OOCommodities::generateMarketForStation:, marketSorterByPrice(), saveStationAmounts, PlayerEntity(OOPrivate)::showMarketScreenDataLine:forGood:inMarket:holdQuantity:, PlayerEntity::tryBuyingCommodity:all:, and PlayerEntity::trySellingCommodity:all:.

Here is the caller graph for this function:

◆ quantityForGood:

◆ removeAllGoods

- (void) removeAllGoods

Definition at line 120 of file OOCommodityMarket.m.

121{
122 OOCommodityType good = nil;
123 foreach (good, [_commodityList allKeys]) {
124 [self setQuantity:0 forGood:good];
125 }
126}

References _commodityList, nil, removeAllGoods, and setQuantity:forGood:.

Referenced by removeAllGoods.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeQuantity:forGood:

- (BOOL) removeQuantity: (OOCargoQuantity) quantity
forGood: (OOCommodityType) good 

Definition at line 110 of file OOCommodityMarket.m.

110 :(OOCargoQuantity)quantity forGood:(OOCommodityType)good
111{
112 OOCargoQuantity current = [self quantityForGood:good];
113 if (current < quantity) {
114 return NO;
115 }
116 [self setQuantity:(current - quantity) forGood:good];
117 return YES;
118}

References quantityForGood:, and setQuantity:forGood:.

Referenced by PlayerEntity::setCommanderDataFromDictionary:, PlayerEntity::tryBuyingCommodity:all:, PlayerEntity::trySellingCommodity:all:, and PlayerEntity::unloadCargoPodsForType:amount:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ savePlayerAmounts

- (NSArray *) savePlayerAmounts

Definition at line 245 of file OOCommodityMarket.m.

246{
247 NSMutableArray* amounts = [NSMutableArray arrayWithCapacity:[self count]];
248 OOCommodityType good = nil;
249 foreach (good, [self goods]) {
250 [amounts addObject:[NSArray arrayWithObjects:good, [NSNumber numberWithUnsignedInt:[self quantityForGood:good]], nil]];
251 }
252 return [NSArray arrayWithArray:amounts];
253}

References count, goods, nil, quantityForGood:, and savePlayerAmounts.

Referenced by PlayerEntity::commanderDataDictionary, and savePlayerAmounts.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ saveStationAmounts

- (NSArray *) saveStationAmounts

Definition at line 292 of file OOCommodityMarket.m.

293{
294 NSMutableArray* amounts = [NSMutableArray arrayWithCapacity:[self count]];
295 OOCommodityType good = nil;
296 foreach (good, [self goods]) {
297 [amounts addObject:[NSArray arrayWithObjects:good, [NSNumber numberWithUnsignedInt:[self quantityForGood:good]], [NSNumber numberWithUnsignedInteger:[self priceForGood:good]], nil]];
298 }
299 return [NSArray arrayWithArray:amounts];
300}

References count, goods, nil, priceForGood:, quantityForGood:, and saveStationAmounts.

Referenced by Universe::getStationMarkets, and saveStationAmounts.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setComment:forGood:

- (BOOL) setComment: (NSString*) comment
forGood: (OOCommodityType) good 

Definition at line 128 of file OOCommodityMarket.m.

128 :(NSString*)comment forGood:(OOCommodityType)good
129{
130 NSMutableDictionary* definition = [_commodityList oo_mutableDictionaryForKey:good];
131 if (definition == nil) {
132 return NO;
133 }
134 [definition setObject:comment forKey:kOOCommodityComment];
135 return YES;
136}

References nil.

◆ setGood:withInfo:

- (void) setGood: (OOCommodityType) key
withInfo: (NSDictionary*) info 

Definition at line 59 of file OOCommodityMarket.m.

59 :(OOCommodityType)key withInfo:(NSDictionary*)info
60{
61 NSMutableDictionary* definition = [NSMutableDictionary dictionaryWithDictionary:info];
62 [_commodityList setObject:definition forKey:key];
63 DESTROY(_sortedKeys); // reset
64}

References _sortedKeys, and DESTROY.

Referenced by OOCommodities::generateBlankMarket, OOCommodities::generateManifestForPlayer, OOCommodities::generateMarketForStation:, and OOCommodities::generateMarketForSystemWithEconomy:andScript:.

Here is the caller graph for this function:

◆ setPrice:forGood:

- (BOOL) setPrice: (OOCreditsQuantity) price
forGood: (OOCommodityType) good 

Definition at line 80 of file OOCommodityMarket.m.

80 :(OOCreditsQuantity)price forGood:(OOCommodityType)good
81{
82 NSMutableDictionary* definition = [_commodityList oo_mutableDictionaryForKey:good];
83 if (definition == nil) {
84 return NO;
85 }
86 [definition oo_setUnsignedInteger:price forKey:kOOCommodityPriceCurrent];
87 return YES;
88}

References nil.

Referenced by loadStationAmounts:, and StationEntity::setPrice:forCommodity:.

Here is the caller graph for this function:

◆ setQuantity:forGood:

- (BOOL) setQuantity: (OOCargoQuantity) quantity
forGood: (OOCommodityType) good 

Definition at line 90 of file OOCommodityMarket.m.

90 :(OOCargoQuantity)quantity forGood:(OOCommodityType)good
91{
92 NSMutableDictionary* definition = [_commodityList oo_mutableDictionaryForKey:good];
93 if (definition == nil || quantity > [self capacityForGood:good]) {
94 return NO;
95 }
96 [definition oo_setUnsignedInteger:quantity forKey:kOOCommodityQuantityCurrent];
97 return YES;
98}

References nil.

Referenced by addQuantity:forGood:, PlayerEntity::loadCargoPodsForType:amount:, PlayerEntity::loadCargoPodsForType:fromManifest:, loadPlayerAmounts:, loadStationAmounts:, removeAllGoods, removeQuantity:forGood:, PlayerEntity::setCargoQuantityForType:amount:, and StationEntity::setQuantity:forCommodity:.

Here is the caller graph for this function:

◆ setShortComment:forGood:

- (BOOL) setShortComment: (NSString*) comment
forGood: (OOCommodityType) good 

Definition at line 138 of file OOCommodityMarket.m.

138 :(NSString*)comment forGood:(OOCommodityType)good
139{
140 NSMutableDictionary* definition = [_commodityList oo_mutableDictionaryForKey:good];
141 if (definition == nil) {
142 return NO;
143 }
144 [definition setObject:comment forKey:kOOCommodityShortComment];
145 return YES;
146}

References nil.

◆ shortCommentForGood:

- (NSString *) shortCommentForGood: (OOCommodityType) good

Definition at line 166 of file OOCommodityMarket.m.

166 :(OOCommodityType)good
167{
168 NSDictionary* definition = [_commodityList oo_dictionaryForKey:good];
169 if (definition == nil) {
170 return OOExpand(@"[oolite-unknown-commodity-name]");
171 }
172 return OOExpand([definition oo_stringForKey:kOOCommodityShortComment defaultValue:@"[oolite-commodity-no-short-comment]"]);
173}
static NSString *const kOOCommodityShortComment

References kOOCommodityShortComment, nil, and OOExpand.

◆ trumbleOpinionForGood:

- (float) trumbleOpinionForGood: (OOCommodityType) good

Definition at line 231 of file OOCommodityMarket.m.

231 :(OOCommodityType)good
232{
233 NSDictionary* definition = [_commodityList oo_dictionaryForKey:good];
234 if (definition == nil) {
235 return 0;
236 }
237 return [definition oo_floatForKey:kOOCommodityTrumbleOpinion];
238}

References nil.

Member Data Documentation

◆ _commodityList

- (NSMutableDictionary*) _commodityList
private

Definition at line 33 of file OOCommodityMarket.h.

Referenced by dealloc, init, and removeAllGoods.

◆ _sortedKeys

- (NSArray*) _sortedKeys
private

Definition at line 34 of file OOCommodityMarket.h.

Referenced by dealloc, goods, init, and setGood:withInfo:.


The documentation for this class was generated from the following files: