34@interface OOCharacter (Private)
37- (void) setCharacterFromDictionary:(NSDictionary *)dict;
47- (NSString *) descriptionComponents
53- (NSString *) oo_jsClassName
62 [_shortDescription release];
63 [_scriptActions release];
72 if ((
self = [super init]))
75 _genSeed = characterSeed;
76 _originSystem = system;
84- (id) initWithRole:(NSString *)role andOriginalSystem:(
OOSystemID)system
89 if ((
self = [
self initWithGenSeed:seed andOriginalSystem:system]))
91 [
self castInRole:role];
99 return [[[
self alloc] initWithRole:role andOriginalSystem:system] autorelease];
114 OOCharacter *character = [[[
OOCharacter alloc] initWithGenSeed:seed andOriginalSystem:system] autorelease];
121+ (
OOCharacter *) characterWithDictionary:(NSDictionary *)dict
130- (NSString *) planetOfOrigin
133 NSDictionary *originInfo = [UNIVERSE generateSystemData:[
self planetIDOfOrigin]];
134 return [originInfo objectForKey:KEY_NAME];
141 return _originSystem;
145- (NSString *) species
148 int species = [
self genSeed].f & 0x03;
149 NSString* speciesString =
nil;
150 if (species == 3) speciesString = [UNIVERSE getSystemInhabitants:[
self genSeed].e plural:NO];
151 else speciesString = [UNIVERSE getSystemInhabitants:[
self planetIDOfOrigin] plural:NO];
153 if (![[
UNIVERSE descriptions] oo_boolForKey:
@"lowercase_ignore"])
155 speciesString = [speciesString lowercaseString];
158 return [speciesString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
172 NSDictionary *originInfo = [UNIVERSE generateSystemData:[
self planetIDOfOrigin]];
173 NSString *planet = [originInfo oo_stringForKey:KEY_NAME];
174 OOGovernmentID government = [originInfo oo_intForKey:KEY_GOVERNMENT];
175 int criminalTendency = government ^ 0x07;
178 NSString *species = [
self species];
182 NSString *genName =
nil;
183 if ([species hasPrefix:
@"human"])
185 genName = [NSString stringWithFormat:@"%@ %@", OOExpandWithSeed(genSeed, @"%R"), OOExpandKeyWithSeed(genSeed, @"nom")];
192 genName = [NSString stringWithFormat:@"%@ %@", OOExpandWithSeed(genSeed, @"%R"), OOExpandWithSeed(genSeed, @"%R")];
194 [
self setName:genName];
196 [
self setShortDescription:OOExpandKeyWithSeed(genSeed, @"character-generic-description", species, planet)];
199 [
self setLegalStatus:0];
201 while (((
gen_rnd_number() & 0xf) < criminalTendency) && (legalIndex < 3))
208 [
self setLegalStatus:criminalTendency + criminalTendency * (gen_rnd_number() & 0x03) + (gen_rnd_number() & gen_rnd_number() & 0x7f)];
211 if (_legalStatus > 0) legalIndex = (_legalStatus <= 50) ? 1 : 2;
214 [
self setInsuranceCredits:0];
218 switch (insuranceIndex)
221 [
self setInsuranceCredits:125];
224 [
self setInsuranceCredits:250];
227 [
self setInsuranceCredits:500];
237- (BOOL) castInRole:(NSString *)role
239 BOOL specialSetUpDone = NO;
241 role = [role lowercaseString];
242 if ([role hasPrefix:
@"pirate"])
246 int sins = 0x08 | (genSeed.
a & genSeed.
b);
247 [
self setLegalStatus:sins & 0x7f];
249 specialSetUpDone = YES;
251 else if ([role hasPrefix:
@"trader"])
253 [
self setLegalStatus:0];
256 switch (insuranceIndex)
259 [
self setInsuranceCredits:0];
262 [
self setInsuranceCredits:125];
265 [
self setInsuranceCredits:250];
268 [
self setInsuranceCredits:500];
270 specialSetUpDone = YES;
272 else if ([role hasPrefix:
@"hunter"])
274 [
self setLegalStatus:0];
276 if (insuranceIndex == 3)
277 [
self setInsuranceCredits:500];
278 specialSetUpDone = YES;
280 else if ([role hasPrefix:
@"police"])
282 [
self setLegalStatus:0];
283 [
self setInsuranceCredits:125];
284 specialSetUpDone = YES;
286 else if ([role isEqual:
@"miner"])
288 [
self setLegalStatus:0];
289 [
self setInsuranceCredits:25];
290 specialSetUpDone = YES;
292 else if ([role isEqual:
@"passenger"])
294 [
self setLegalStatus:0];
296 switch (insuranceIndex)
299 [
self setInsuranceCredits:25];
302 [
self setInsuranceCredits:125];
305 [
self setInsuranceCredits:250];
308 [
self setInsuranceCredits:500];
310 specialSetUpDone = YES;
312 else if ([role isEqual:
@"slave"])
314 [
self setLegalStatus:0];
315 [
self setInsuranceCredits:0];
316 specialSetUpDone = YES;
318 else if ([role isEqual:
@"thargoid"])
320 [
self setLegalStatus:100];
321 [
self setInsuranceCredits:0];
322 [
self setName:DESC(@"character-thargoid-name")];
323 [
self setShortDescription:DESC(@"character-a-thargoid")];
324 specialSetUpDone = YES;
329 return specialSetUpDone;
339- (NSString *)shortDescription
341 return _shortDescription;
359 return _insuranceCredits;
363- (NSArray *)legacyScript
365 return _scriptActions;
369- (NSDictionary *) infoForScripting
371 return [NSDictionary dictionaryWithObjectsAndKeys:
372 [
self name], @"name",
373 [
self shortDescription], @"description",
374 [
self species], @"species",
375 [NSNumber numberWithInt:[
self legalStatus]], @"legalStatus",
376 [NSNumber numberWithUnsignedLongLong:[
self insuranceCredits]], @"insuranceCredits",
377 [NSNumber numberWithInt:[
self planetIDOfOrigin]], @"homeSystem",
382- (void)setName:(NSString *)value
385 _name = [value copy];
389- (void)setShortDescription:(NSString *)value
391 [_shortDescription autorelease];
392 _shortDescription = [value copy];
398 _originSystem = value;
408- (void)setLegalStatus:(
int)value
410 _legalStatus = value;
416 _insuranceCredits = value;
420- (void)setLegacyScript:(NSArray *)some_actions
422 [_scriptActions autorelease];
423 _scriptActions = [some_actions copy];
433- (void) setCharacterScript:(NSString *)scriptName
435 [_script autorelease];
437 properties:[NSDictionary dictionaryWithObject:self forKey:@"character"]];
442- (void) doScriptEvent:(jsid)message
445 [_script callMethod:message inContext:context withArguments:NULL count:0 result:NULL];
450- (void) setCharacterFromDictionary:(NSDictionary *)dict
455 origin = [dict objectForKey:@"origin"];
456 if ([
origin isKindOfClass:[NSNumber
class]] ||
457 ([
origin respondsToSelector:
@selector(intValue)] && ([
origin intValue] != 0 || [
origin isEqual:
@"0"])))
460 [
self setOriginSystem:[origin intValue]];
462 else if ([
origin isKindOfClass:[NSString
class]])
464 OOSystemID sys = [UNIVERSE findSystemFromName:origin];
467 OOLogERR(
@"character.load.unknownSystem",
@"could not find a system named '%@' in this galaxy.",
origin);
468 [
self setOriginSystem:(ranrot_rand() & 0xff)];
472 [
self setOriginSystem:sys];
478 [
self setOriginSystem:(ranrot_rand() & 0xff)];
481 if ([dict objectForKey:
@"random_seed"])
494 [
self setGenSeed:seed];
497 if ([dict oo_stringForKey:
@"role"]) [
self castInRole:[dict oo_stringForKey:@"role"]];
498 if ([dict oo_stringForKey:
@"name"]) [
self setName:[dict oo_stringForKey:@"name"]];
499 if ([dict oo_stringForKey:
@"short_description"]) [
self setShortDescription:[dict oo_stringForKey:@"short_description"]];
500 if ([dict objectForKey:
@"legal_status"]) [
self setLegalStatus:[dict oo_intForKey:@"legal_status"]];
501 if ([dict objectForKey:
@"bounty"]) [
self setLegalStatus:[dict oo_intForKey:@"bounty"]];
502 if ([dict objectForKey:
@"insurance"]) [
self setInsuranceCredits:[dict oo_unsignedLongLongForKey:@"insurance"]];
503 if ([dict oo_stringForKey:
@"script"]) [
self setCharacterScript:[dict oo_stringForKey:@"script"]];
504 if ([dict oo_arrayForKey:
@"script_actions"]) [
self setLegacyScript:[dict oo_arrayForKey:@"script_actions"]];
OOINLINE JSContext * OOJSAcquireContext(void)
OOINLINE void OOJSRelinquishContext(JSContext *context)
#define OOLogERR(class, format,...)
Random_Seed RandomSeedFromString(NSString *abcdefString)
uint64_t OOCreditsQuantity
BOOL castInRole:(NSString *role)
OOCreditsQuantity insuranceCredits()
void setCharacterFromDictionary:(NSDictionary *dict)
NSString * shortDescription()
id jsScriptFromFileNamed:properties:(NSString *fileName,[properties] NSDictionary *properties)
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
void make_pseudo_random_seed(Random_Seed *seed_ptr)
RANROTSeed RANROTGetFullSeed(void)
void seed_RNG_only_for_planet_description(Random_Seed s_seed)
void setRandomSeed(RNG_Seed a_seed)
RNG_Seed currentRandomSeed(void)
void RANROTSetFullSeed(RANROTSeed seed)
void seed_for_planet_description(Random_Seed s_seed)