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;
98 NSUInteger i, j, k, jIndex, kIndex;
112 [neighbourCache[
jIndex] addObject:[
NSNumber numberWithUnsignedInteger:k]];
113 [neighbourCache[
kIndex] addObject:[
NSNumber numberWithUnsignedInteger:j]];
120- (void)setUniversalProperties:(NSDictionary*)properties
122 [universalProperties addEntriesFromDictionary:properties];
123 [propertiesInUse addObjectsFromArray:[
properties allKeys]];
129- (void)setInterstellarProperties:(NSDictionary*)properties
134- (void)setProperties:(NSDictionary*)properties forSystemKey:(NSString*)key
140 [systemDescriptions setObject:desc forKey:key];
143 [propertiesInUse addObjectsFromArray:[
properties allKeys]];
151 OOLog(
@"system.description.error",
@"'%@' is an invalid system key. This is an internal error. Please report it.", key);
158- (void)setProperty:(NSString*)property forSystemKey:(NSString*)key andLayer:(
OOSystemLayer)layer toValue:(
id)value fromManifest:(NSString*)manifest
164 [systemDescriptions setObject:desc forKey:key];
167 [propertiesInUse addObject:property];
177 OOLog(
@"system.description.error",
@"'%@' is an invalid system key. This is an internal error. Please report it.", key);
188- (void)saveScriptedChangeToProperty:(NSString*)property forSystemKey:(NSString*)key andLayer:(
OOSystemLayer)layer toValue:(
id)value fromManifest:(NSString*)manifest
191 if (manifest ==
nil) {
195 NSArray* overrideKey = [
NSArray arrayWithObjects:manifest, key, property, [[
NSNumber numberWithInt:layer] stringValue], nil];
198 NSString* overrideKeyStr = [
overrideKey componentsJoinedByString:kOOScriptedChangeJoiner];
206- (void)importScriptedChanges:(NSDictionary*)scripted
209 NSString* keyStr =
nil;
210 NSString* manifest =
nil;
213 key = [
keyStr componentsSeparatedByString:kOOScriptedChangeJoiner];
214 if ([key
count] == 4) {
215 manifest = [
key oo_stringAtIndex:0];
229 OOLog(
@"systemManager.import",
@"Key '%@' has unexpected format - skipping", keyStr);
235- (void)importLegacyScriptedChanges:(NSDictionary*)scripted
237 NSString* systemKey =
nil;
238 NSString* propertyKey =
nil;
239 NSString* defaultManifest =
@"org.oolite.oolite";
243 NSDictionary* legacyChanges = [
scripted oo_dictionaryForKey:systemKey];
244 if ([legacyChanges objectForKey:
@"sun_gone_nova"] !=
nil) {
258 float sr_num = [
sr floatValue];
259 if (sr_num < 600000) {
273 return [[scriptedChanges copy] autorelease];
282 OOLog(
@"system.description.error",
@"'%zu' is an invalid system index for the current system. This is an internal error. Please report it.", index);
287 OOLog(
@"system.description.error",
@"%@",
@"getPropertiesForCurrentSystem called while player in interstellar space. This is an internal error. Please report it.");
293- (NSDictionary*)getPropertiesForSystemKey:(NSString*)key
301 OOLog(
@"system.description.error",
@"'%@' is an invalid system key. This is an internal error. Please report it.", key);
314 OOLog(
@"system.description.error",
@"'%u, %u' is an invalid system. This is an internal error. Please report it.", g, s);
320- (id)getProperty:(NSString*)property forSystemKey:(NSString*)key
328 OOLog(
@"system.description.error",
@"'%d %d' is an invalid system key. This is an internal error. Please report it.", g, s);
333 OOLog(
@"system.description.error",
@"'%d %d' is an invalid system key. This is an internal error. Please report it.", g, s);
336 return [propertyCache[
index] objectForKey:property];
339- (id)getProperty:(NSString*)property forSystemKey:(NSString*)key withUniversal:(BOOL)universal
342 if (
EXPECT_NOT([key isEqualToString:
@"interstellar"])) {
343 desc = interstellarSpace;
358 if (result ==
nil && universal) {
367- (id)getProperty:(NSString*)property1 orProperty:(NSString*)property2 forSystemKey:(NSString*)key withUniversal:(BOOL)universal
409 OOSystemLayer layer = [
properties oo_unsignedIntForKey:kOOSystemLayerProperty defaultValue:OO_LAYER_OXP_STATIC];
411 OOLog(
@"system.description.error",
@"Layer %u is not a valid layer number in system information.", layer);
424- (NSDictionary*)calculatePropertiesForSystemKey:(NSString*)key
426 NSMutableDictionary* dict = [
NSMutableDictionary dictionaryWithCapacity:OO_LIKELY_PROPERTIES_PER_SYSTEM];
427 NSString*
property =
nil;
429 BOOL interstellar = [
key hasPrefix:@"interstellar:"];
430 foreach (property, propertiesInUse) {
435 [
dict setObject:val forKey:property];
436 }
else if (interstellar) {
441 [
dict setObject:val forKey:property];
448- (void)updateCacheEntry:(NSUInteger)i
451 NSString* key = [
NSString stringWithFormat:@"%zu %zu", i / OO_SYSTEMS_PER_GALAXY, i % OO_SYSTEMS_PER_GALAXY];
458- (void)updateCacheEntry:(NSUInteger)i forProperty:(NSString*)property
461 NSString* key = [
NSString stringWithFormat:@"%zu %zu", i / OO_SYSTEMS_PER_GALAXY, i % OO_SYSTEMS_PER_GALAXY];
463 if (current ==
nil) {
473 OOLog(
@"system.description.error",
@"'%d %d' is an invalid system key. This is an internal error. Please report it.", g, s);
474 return (NSPoint) { 0, 0 };
478 OOLog(
@"system.description.error",
@"'%d %d' is an invalid system key. This is an internal error. Please report it.", g, s);
479 return (NSPoint) { 0, 0 };
487 OOLog(
@"system.description.error",
@"'%d %d' is an invalid system key. This is an internal error. Please report it.", g, s);
492 OOLog(
@"system.description.error",
@"'%d %d' is an invalid system key. This is an internal error. Please report it.", g, s);
501 if ([
UNIVERSE currentSystemID] < 0) {
507 OOLog(
@"system.description.error",
@"'%zu' is an invalid system index for the current system. This is an internal error. Please report it.", index);
517 OOLog(
@"system.description.error",
@"'%d %d' is an invalid system key. This is an internal error. Please report it.", g, s);
522 OOLog(
@"system.description.error",
@"'%d %d' is an invalid system key. This is an internal error. Please report it.", g, s);
530@interface OOSystemDescriptionEntry (OOPrivate)
531- (id)validateProperty:(NSString*)property withValue:(
id)value;
555- (void)setProperty:(NSString*)property forLayer:(
OOSystemLayer)layer toValue:(
id)value
558 [layers[
layer] removeObjectForKey:property];
565 [layers[
layer] setObject:value forKey:property];
572 return [layers[
layer] objectForKey:property];
580- (id)validateProperty:(NSString*)property withValue:(
id)value
582 if ([property isEqualToString:
@"coordinates"]) {
585 if (![value isKindOfClass:[NSString
class]]) {
586 OOLog(
@"system.description.error",
@"'%@' is not a valid format for coordinates", value);
590 if ([tokens
count] != 2) {
591 OOLog(
@"system.description.error",
@"'%@' is not a valid format for coordinates (must have exactly two numbers)", value);
594 }
else if ([property isEqualToString:
@"radius"] || [property isEqualToString:
@"government"]) {
596 if (![value isKindOfClass:[NSString
class]]) {
597 if ([value isKindOfClass:[NSNumber
class]]) {
598 return [
value stringValue];
600 OOLog(
@"system.description.error",
@"'%@' is not a valid value for '%@' (string required)", value, property);
604 }
else if ([property isEqualToString:
@"inhabitant"] || [property isEqualToString:
@"inhabitants"] || [property isEqualToString:
@"name"]) {
606 if (![value isKindOfClass:[NSString
class]]) {
607 OOLog(
@"system.description.error",
@"'%@' is not a valid value for '%@' (string required)", value, property);
#define foreachkey(VAR, DICT)
#define OOLog(class, format,...)
NSMutableArray * ScanTokensFromString(NSString *values)
NSPoint PointFromString(NSString *xyString)
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