41#define OO_LIKELY_PROPERTIES_PER_SYSTEM 50
43@interface OOSystemDescriptionManager (OOPrivate)
45- (NSDictionary *) calculatePropertiesForSystemKey:(NSString *)key;
46- (void) updateCacheEntry:(NSUInteger)i;
47- (void) updateCacheEntry:(NSUInteger)i forProperty:(NSString *)property;
48- (id) getProperty:(NSString *)property forSystemKey:(NSString *)key withUniversal:(BOOL)universal;
52- (id) getProperty:(NSString *)property1 orProperty:(NSString *)property2 forSystemKey:(NSString *)key withUniversal:(BOOL)universal;
54- (void) saveScriptedChangeToProperty:(NSString *)property forSystemKey:(NSString *)key andLayer:(
OOSystemLayer)layer toValue:(
id)value fromManifest:(NSString *)manifest;
102 NSUInteger i,j,k,jIndex,kIndex;
121 [neighbourCache[
jIndex] addObject:[
NSNumber numberWithUnsignedInteger:k]];
122 [neighbourCache[
kIndex] addObject:[
NSNumber numberWithUnsignedInteger:j]];
131- (void) setUniversalProperties:(NSDictionary *)properties
133 [universalProperties addEntriesFromDictionary:properties];
134 [propertiesInUse addObjectsFromArray:[
properties allKeys]];
131- (void) setUniversalProperties:(NSDictionary *)properties {
…}
142- (void) setInterstellarProperties:(NSDictionary *)properties
142- (void) setInterstellarProperties:(NSDictionary *)properties {
…}
148- (void) setProperties:(NSDictionary *)properties forSystemKey:(NSString *)key
155 [systemDescriptions setObject:desc forKey:key];
158 [propertiesInUse addObjectsFromArray:[
properties allKeys]];
168 OOLog(
@"system.description.error",
@"'%@' is an invalid system key. This is an internal error. Please report it.",key);
148- (void) setProperties:(NSDictionary *)properties forSystemKey:(NSString *)key {
…}
178- (void) setProperty:(NSString *)property forSystemKey:(NSString *)key andLayer:(
OOSystemLayer)layer toValue:(
id)value fromManifest:(NSString *)manifest
185 [systemDescriptions setObject:desc forKey:key];
188 [propertiesInUse addObject:property];
200 OOLog(
@"system.description.error",
@"'%@' is an invalid system key. This is an internal error. Please report it.",key);
178- (void) setProperty:(NSString *)property forSystemKey:(NSString *)key andLayer:(
OOSystemLayer)layer toValue:(
id)value fromManifest:(NSString *)manifest {
…}
215- (void) saveScriptedChangeToProperty:(NSString *)property forSystemKey:(NSString *)key andLayer:(
OOSystemLayer)layer toValue:(
id)value fromManifest:(NSString *)manifest
223 NSArray *overrideKey = [
NSArray arrayWithObjects:manifest,key,property,[[
NSNumber numberWithInt:layer] stringValue],nil];
226 NSString *overrideKeyStr = [
overrideKey componentsJoinedByString:kOOScriptedChangeJoiner];
215- (void) saveScriptedChangeToProperty:(NSString *)property forSystemKey:(NSString *)key andLayer:(
OOSystemLayer)layer toValue:(
id)value fromManifest:(NSString *)manifest {
…}
238- (void) importScriptedChanges:(NSDictionary *)scripted
241 NSString *keyStr =
nil;
242 NSString *manifest =
nil;
245 key = [
keyStr componentsSeparatedByString:kOOScriptedChangeJoiner];
246 if ([key
count] == 4)
248 manifest = [
key oo_stringAtIndex:0];
265 OOLog(
@"systemManager.import",
@"Key '%@' has unexpected format - skipping",keyStr);
238- (void) importScriptedChanges:(NSDictionary *)scripted {
…}
273- (void) importLegacyScriptedChanges:(NSDictionary *)scripted
275 NSString *systemKey =
nil;
276 NSString *propertyKey =
nil;
277 NSString *defaultManifest =
@"org.oolite.oolite";
281 NSDictionary *legacyChanges = [
scripted oo_dictionaryForKey:systemKey];
282 if ([legacyChanges objectForKey:
@"sun_gone_nova"] !=
nil)
297 float sr_num = [
sr floatValue];
298 if (sr_num < 600000) {
273- (void) importLegacyScriptedChanges:(NSDictionary *)scripted {
…}
314 return [[scriptedChanges copy] autorelease];
326 OOLog(
@"system.description.error",
@"'%lu' is an invalid system index for the current system. This is an internal error. Please report it.",index);
333 OOLog(
@"system.description.error",
@"%@",
@"getPropertiesForCurrentSystem called while player in interstellar space. This is an internal error. Please report it.");
340- (NSDictionary *) getPropertiesForSystemKey:(NSString *)key
350 OOLog(
@"system.description.error",
@"'%@' is an invalid system key. This is an internal error. Please report it.",key);
340- (NSDictionary *) getPropertiesForSystemKey:(NSString *)key {
…}
365 OOLog(
@"system.description.error",
@"'%u, %u' is an invalid system. This is an internal error. Please report it.",g,s);
372- (id) getProperty:(NSString *)property forSystemKey:(NSString *)key
372- (id) getProperty:(NSString *)property forSystemKey:(NSString *)key {
…}
381 OOLog(
@"system.description.error",
@"'%d %d' is an invalid system key. This is an internal error. Please report it.",g,s);
387 OOLog(
@"system.description.error",
@"'%d %d' is an invalid system key. This is an internal error. Please report it.",g,s);
390 return [propertyCache[
index] objectForKey:property];
394- (id) getProperty:(NSString *)property forSystemKey:(NSString *)key withUniversal:(BOOL)universal
397 if (
EXPECT_NOT([key isEqualToString:
@"interstellar"]))
399 desc = interstellarSpace;
419 if (result ==
nil && universal)
394- (id) getProperty:(NSString *)property forSystemKey:(NSString *)key withUniversal:(BOOL)universal {
…}
431- (id) getProperty:(NSString *)property1 orProperty:(NSString *)property2 forSystemKey:(NSString *)key withUniversal:(BOOL)universal
431- (id) getProperty:(NSString *)property1 orProperty:(NSString *)property2 forSystemKey:(NSString *)key withUniversal:(BOOL)universal {
…}
485 OOSystemLayer layer = [
properties oo_unsignedIntForKey:kOOSystemLayerProperty defaultValue:OO_LAYER_OXP_STATIC];
488 OOLog(
@"system.description.error",
@"Layer %u is not a valid layer number in system information.",layer);
503- (NSDictionary *) calculatePropertiesForSystemKey:(NSString *)key
505 NSMutableDictionary *dict = [
NSMutableDictionary dictionaryWithCapacity:OO_LIKELY_PROPERTIES_PER_SYSTEM];
506 NSString *
property =
nil;
508 BOOL interstellar = [
key hasPrefix:@"interstellar:"];
509 foreach (property, propertiesInUse)
516 [
dict setObject:val forKey:property];
518 else if (interstellar)
525 [
dict setObject:val forKey:property];
503- (NSDictionary *) calculatePropertiesForSystemKey:(NSString *)key {
…}
533- (void) updateCacheEntry:(NSUInteger)i
536 NSString *key = [
NSString stringWithFormat:@"%lu %lu",i/OO_SYSTEMS_PER_GALAXY,i%OO_SYSTEMS_PER_GALAXY];
533- (void) updateCacheEntry:(NSUInteger)i {
…}
544- (void) updateCacheEntry:(NSUInteger)i forProperty:(NSString *)property
547 NSString *key = [
NSString stringWithFormat:@"%lu %lu",i/OO_SYSTEMS_PER_GALAXY,i%OO_SYSTEMS_PER_GALAXY];
544- (void) updateCacheEntry:(NSUInteger)i forProperty:(NSString *)property {
…}
564 OOLog(
@"system.description.error",
@"'%d %d' is an invalid system key. This is an internal error. Please report it.",g,s);
565 return (NSPoint){0,0};
570 OOLog(
@"system.description.error",
@"'%d %d' is an invalid system key. This is an internal error. Please report it.",g,s);
571 return (NSPoint){0,0};
581 OOLog(
@"system.description.error",
@"'%d %d' is an invalid system key. This is an internal error. Please report it.",g,s);
587 OOLog(
@"system.description.error",
@"'%d %d' is an invalid system key. This is an internal error. Please report it.",g,s);
607 OOLog(
@"system.description.error",
@"'%lu' is an invalid system index for the current system. This is an internal error. Please report it.",(
unsigned long)index);
619 OOLog(
@"system.description.error",
@"'%d %d' is an invalid system key. This is an internal error. Please report it.",g,s);
625 OOLog(
@"system.description.error",
@"'%d %d' is an invalid system key. This is an internal error. Please report it.",g,s);
635@interface OOSystemDescriptionEntry (OOPrivate)
636- (id) validateProperty:(NSString *)property withValue:(
id)value;
665- (void) setProperty:(NSString *)property forLayer:(
OOSystemLayer)layer toValue:(
id)value
669 [layers[
layer] removeObjectForKey:property];
679 [layers[
layer] setObject:value forKey:property];
665- (void) setProperty:(NSString *)property forLayer:(
OOSystemLayer)layer toValue:(
id)value {
…}
687 return [layers[
layer] objectForKey:property];
696- (id) validateProperty:(NSString *)property withValue:(
id)value
698 if ([property isEqualToString:
@"coordinates"])
702 if (![value isKindOfClass:[NSString
class]])
704 OOLog(
@"system.description.error",
@"'%@' is not a valid format for coordinates",value);
708 if ([tokens
count] != 2)
710 OOLog(
@"system.description.error",
@"'%@' is not a valid format for coordinates (must have exactly two numbers)",value);
714 else if ([property isEqualToString:
@"radius"] || [property isEqualToString:
@"government"])
717 if (![value isKindOfClass:[NSString
class]])
719 if ([value isKindOfClass:[NSNumber
class]])
721 return [
value stringValue];
725 OOLog(
@"system.description.error",
@"'%@' is not a valid value for '%@' (string required)",value,property);
730 else if ([property isEqualToString:
@"inhabitant"] || [property isEqualToString:
@"inhabitants"] || [property isEqualToString:
@"name"] )
733 if (![value isKindOfClass:[NSString
class]])
735 OOLog(
@"system.description.error",
@"'%@' is not a valid value for '%@' (string required)",value,property);
696- (id) validateProperty:(NSString *)property withValue:(
id)value {
…}
#define foreachkey(VAR, DICT)
#define OOLog(class, format,...)
NSPoint PointFromString(NSString *xyString)
NSMutableArray * ScanTokensFromString(NSString *values)
Random_Seed RandomSeedFromString(NSString *abcdefString)
#define OO_GALAXIES_AVAILABLE
#define OO_SYSTEM_CACHE_LENGTH
#define OO_SYSTEMS_PER_GALAXY
static NSString * kOOSystemLayerProperty
static NSString *const kOOScriptedChangeJoiner
id getProperty:forLayer:(NSString *property,[forLayer] OOSystemLayer layer)
id validateProperty:withValue:(NSString *property, [withValue] id value)
void setProperty:forLayer:toValue:(NSString *property,[forLayer] OOSystemLayer layer,[toValue] id value)
NSMutableDictionary * layers[OO_SYSTEM_LAYERS]
NSMutableDictionary * systemDescriptions
Random_Seed getRandomSeedForCurrentSystem()
void updateCacheEntry:forProperty:(NSUInteger i, [forProperty] NSString *property)
void updateCacheEntry:(NSUInteger i)
NSMutableSet * propertiesInUse
NSDictionary * getPropertiesForCurrentSystem()
NSMutableDictionary * propertyCache[OO_SYSTEM_CACHE_LENGTH]
NSDictionary * exportScriptedChanges()
NSMutableArray * neighbourCache[OO_SYSTEM_CACHE_LENGTH]
void setProperty:forSystemKey:andLayer:toValue:fromManifest:(NSString *property,[forSystemKey] NSString *key,[andLayer] OOSystemLayer layer,[toValue] id value,[fromManifest] NSString *manifest)
NSDictionary * calculatePropertiesForSystemKey:(NSString *key)
NSMutableDictionary * universalProperties
OOSystemDescriptionEntry * interstellarSpace
void saveScriptedChangeToProperty:forSystemKey:andLayer:toValue:fromManifest:(NSString *property, [forSystemKey] NSString *key, [andLayer] OOSystemLayer layer, [toValue] id value, [fromManifest] NSString *manifest)
NSPoint coordinatesCache[OO_SYSTEM_CACHE_LENGTH]
id getProperty:forSystemKey:withUniversal:(NSString *property, [forSystemKey] NSString *key, [withUniversal] BOOL universal)
NSMutableDictionary * scriptedChanges
id getProperty:forSystemKey:(NSString *property,[forSystemKey] NSString *key)
void setProperties:inDescription:(NSDictionary *properties, [inDescription] OOSystemDescriptionEntry *desc)
const Random_Seed kNilRandomSeed
OOINLINE double distanceBetweenPlanetPositions(int x1, int y1, int x2, int y2) INLINE_CONST_FUNC