30static NSComparisonResult
goodsSorter(
id a,
id b,
void* context);
56 return [_commodityList count];
62 [_commodityList setObject:definition forKey:key];
69 NSArray* keys = [_commodityList allKeys];
70 _sortedKeys = [[
keys sortedArrayUsingFunction:goodsSorter context:_commodityList] retain];
77 return [[_commodityList copy] autorelease];
82 NSMutableDictionary* definition = [_commodityList oo_mutableDictionaryForKey:good];
83 if (definition ==
nil) {
86 [
definition oo_setUnsignedInteger:price forKey:kOOCommodityPriceCurrent];
92 NSMutableDictionary* definition = [_commodityList oo_mutableDictionaryForKey:good];
93 if (definition ==
nil || quantity > [
self capacityForGood:good]) {
96 [
definition oo_setUnsignedInteger:quantity forKey:kOOCommodityQuantityCurrent];
103 if (current + quantity > [
self capacityForGood:good]) {
113 if (current < quantity) {
130 NSMutableDictionary* definition = [_commodityList oo_mutableDictionaryForKey:good];
131 if (definition ==
nil) {
134 [
definition setObject:comment forKey:kOOCommodityComment];
140 NSMutableDictionary* definition = [_commodityList oo_mutableDictionaryForKey:good];
141 if (definition ==
nil) {
144 [
definition setObject:comment forKey:kOOCommodityShortComment];
150 NSDictionary* definition = [_commodityList oo_dictionaryForKey:good];
151 if (definition ==
nil) {
152 return OOExpand(
@"[oolite-unknown-commodity-name]");
159 NSDictionary* definition = [_commodityList oo_dictionaryForKey:good];
160 if (definition ==
nil) {
161 return OOExpand(
@"[oolite-unknown-commodity-name]");
168 NSDictionary* definition = [_commodityList oo_dictionaryForKey:good];
169 if (definition ==
nil) {
170 return OOExpand(
@"[oolite-unknown-commodity-name]");
177 NSDictionary* definition = [_commodityList oo_dictionaryForKey:good];
178 if (definition ==
nil) {
181 return [
definition oo_unsignedIntegerForKey:kOOCommodityPriceCurrent];
186 NSDictionary* definition = [_commodityList oo_dictionaryForKey:good];
187 if (definition ==
nil) {
190 return [
definition oo_unsignedIntForKey:kOOCommodityQuantityCurrent];
195 NSDictionary* definition = [_commodityList oo_dictionaryForKey:good];
196 if (definition ==
nil) {
199 return [
definition oo_unsignedIntForKey:kOOCommodityContainer];
204 NSDictionary* definition = [_commodityList oo_dictionaryForKey:good];
205 if (definition ==
nil) {
208 return [
definition oo_unsignedIntegerForKey:kOOCommodityLegalityExport];
213 NSDictionary* definition = [_commodityList oo_dictionaryForKey:good];
214 if (definition ==
nil) {
217 return [
definition oo_unsignedIntegerForKey:kOOCommodityLegalityImport];
222 NSDictionary* definition = [_commodityList oo_dictionaryForKey:good];
223 if (definition ==
nil) {
228 return [
definition oo_unsignedIntForKey:kOOCommodityCapacity defaultValue:MAIN_SYSTEM_MARKET_LIMIT];
233 NSDictionary* definition = [_commodityList oo_dictionaryForKey:good];
234 if (definition ==
nil) {
237 return [
definition oo_floatForKey:kOOCommodityTrumbleOpinion];
242 return [[[_commodityList oo_dictionaryForKey:good] copy] autorelease];
249 foreach (good, [
self goods]) {
252 return [
NSArray arrayWithArray:amounts];
255- (void)loadPlayerAmounts:(NSArray*)amounts
259 NSString* good =
nil;
260 foreach (good, [
self goods]) {
265 NSArray* loaded =
nil;
266 foreach (loaded, amounts) {
268 good = [
loaded oo_stringAtIndex:0];
269 q = [
loaded oo_unsignedIntAtIndex:1];
271 if (![
self setQuantity:q forGood:good]) {
276 foreach (key, [
self goods]) {
277 if ([good isEqualToString:[
self nameForGood:key]]) {
287 OOLog(
@"setCommanderDataFromDictionary.warning.cargo",
@"Cargo %@ (%u units) could not be loaded from the saved game, as it is no longer defined", good, q);
296 foreach (good, [
self goods]) {
299 return [
NSArray arrayWithArray:amounts];
302- (void)loadStationAmounts:(NSArray*)amounts
307 NSString* good =
nil;
309 NSArray* loaded =
nil;
310 foreach (loaded, amounts) {
312 good = [
loaded oo_stringAtIndex:0];
313 q = [
loaded oo_unsignedIntAtIndex:1];
314 p = [
loaded oo_unsignedIntegerAtIndex:2];
316 if (![
self setQuantity:q forGood:good]) {
321 foreach (key, [
self goods]) {
322 if ([good isEqualToString:[
self nameForGood:key]]) {
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);
343 NSDictionary* commodityList = (NSDictionary*)context;
344 int v1 = [[commodityList oo_dictionaryForKey:(NSString*)a] oo_intForKey:kOOCommoditySortOrder];
345 int v2 = [[commodityList oo_dictionaryForKey:(NSString*)b] oo_intForKey:kOOCommoditySortOrder];
348 return NSOrderedAscending;
349 }
else if (v1 > v2) {
350 return NSOrderedDescending;
352 return NSOrderedSame;
static NSString *const kOOCommodityComment
static NSString *const kOOCommodityName
static NSString *const kOOCommodityShortComment
static NSComparisonResult goodsSorter(id a, id b, void *context)
#define OOLog(class, format,...)
#define OOExpand(string,...)
NSString * OOCommodityType
uint64_t OOCreditsQuantity
NSArray * saveStationAmounts()
NSArray * savePlayerAmounts()
NSDictionary * dictionaryForScripting()
NSMutableDictionary * _commodityList
BOOL setQuantity:forGood:(OOCargoQuantity quantity,[forGood] OOCommodityType good)
OOCargoQuantity quantityForGood:(OOCommodityType good)
OOCreditsQuantity priceForGood:(OOCommodityType good)
BOOL setPrice:forGood:(OOCreditsQuantity price,[forGood] OOCommodityType good)