Oolite
Loading...
Searching...
No Matches
PlayerEntity(ScriptingPrivate) Category Reference

Instance Methods

(BOOL) - scriptTestCondition:
(NSString *) - expandScriptRightHandSide:
(void) - scriptActions:forTarget:missionKey:
(NSString *) - expandMessage:

Detailed Description

Definition at line 100 of file PlayerEntityLegacyScriptEngine.m.

Method Documentation

◆ expandMessage:

- (NSString *) expandMessage: (NSString *) valueString

Extends class PlayerEntity.

Definition at line 1034 of file PlayerEntityLegacyScriptEngine.m.

1034 :(NSString*)valueString
1035{
1036 Random_Seed very_random_seed;
1037 very_random_seed.a = rand() & 255;
1038 very_random_seed.b = rand() & 255;
1039 very_random_seed.c = rand() & 255;
1040 very_random_seed.d = rand() & 255;
1041 very_random_seed.e = rand() & 255;
1042 very_random_seed.f = rand() & 255;
1043 seed_RNG_only_for_planet_description(very_random_seed);
1044 NSString* expandedMessage = OOExpand(valueString);
1045 return [self replaceVariablesInString:expandedMessage];
1046}
#define OOExpand(string,...)
void seed_RNG_only_for_planet_description(Random_Seed s_seed)
struct Random_Seed Random_Seed

References Random_Seed::a, Random_Seed::b, Random_Seed::c, Random_Seed::d, Random_Seed::e, Random_Seed::f, OOExpand, PlayerEntity::replaceVariablesInString:, and seed_RNG_only_for_planet_description().

Referenced by PlayerEntity(Scripting)::commsMessage:, PlayerEntity(Scripting)::consoleMessage3s:, and PlayerEntity(Scripting)::consoleMessage6s:.

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

◆ expandScriptRightHandSide:

- (NSString *) expandScriptRightHandSide: (NSArray *) rhsComponents

Extends class PlayerEntity.

Definition at line 542 of file PlayerEntityLegacyScriptEngine.m.

542 :(NSArray*)rhsComponents
543{
544 NSMutableArray* result = nil;
545 NSArray* component = nil;
546 NSString* value = nil;
547
548 result = [NSMutableArray arrayWithCapacity:[rhsComponents count]];
549
550 foreach (component, rhsComponents) {
551 /* Each component is a two-element array. The second element is a
552 string. The first element is a boolean indicating whether the
553 string is a selector (true) or a literal (false).
554
555 All valid selectors return a string or an NSNumber; in either
556 case, -description gives us a useful value to substitute into
557 the expanded string.
558 */
559
560 value = [component oo_stringAtIndex:1];
561
562 if ([[component objectAtIndex:0] boolValue]) {
563 value = [[self performSelector:NSSelectorFromString(value)] description];
564 if (value == nil)
565 value = @"(null)"; // for backwards compatibility
566 }
567
568 [result addObject:value];
569 }
570
571 return [result componentsJoinedByString:@" "];
572}
return nil

References nil.

Referenced by scriptTestCondition:.

Here is the caller graph for this function:

◆ scriptActions:forTarget:missionKey:

- (void) scriptActions: (NSArray *) actions
forTarget: (ShipEntity *) target
missionKey: (NSString *) missionKey 

Extends class PlayerEntity.

◆ scriptTestCondition:

- (BOOL) scriptTestCondition: (NSArray *) scriptCondition

Extends class PlayerEntity.

Definition at line 374 of file PlayerEntityLegacyScriptEngine.m.

374 :(NSArray*)scriptCondition
375{
376 /* Test a script condition sanitized by OOLegacyScriptWhitelist.
377
378 A sanitized condition is an array of the form:
379 (opType, rawString, selector, comparisonType, operandArray).
380
381 opType and comparisonType are NSNumbers containing OOOperationType and
382 OOComparisonType enumerators, respectively.
383
384 rawString is the original textual representation of the condition for
385 display purposes.
386
387 selector is a string, either a method selector or a mission/local
388 variable name.
389
390 operandArray is an array of operands. Each operand is itself an array
391 of two items: a boolean indicating whether it's a method selector
392 (true) or a literal string (false), and a string.
393
394 The special opType OP_FALSE doesn't require any other elements in the
395 array. All other valid opTypes require the array to have five elements.
396
397 For performance reasons, this method assumes the script condition will
398 have been generated by OOSanitizeLegacyScriptConditions() and doesn't
399 perform extensive validity checks.
400 */
401
402 OOOperationType opType;
403 NSString* selectorString = nil;
404 SEL selector = NULL;
405 OOComparisonType comparator;
406 NSArray* operandArray = nil;
407 NSString* lhsString = nil;
408 NSString* expandedRHS = nil;
409 NSArray* rhsComponents = nil;
410 NSString* rhsItem = nil;
411 NSUInteger i, count;
412 NSCharacterSet* whitespace = nil;
413 double lhsValue, rhsValue;
414 BOOL lhsFlag, rhsFlag;
415
416 opType = [scriptCondition oo_unsignedIntAtIndex:0];
417 if (opType == OP_FALSE)
418 return NO;
419
420 selectorString = [scriptCondition oo_stringAtIndex:2];
421 comparator = [scriptCondition oo_unsignedIntAtIndex:3];
422 operandArray = [scriptCondition oo_arrayAtIndex:4];
423
424 // Transform mission/local var ops into string ops.
425 if (opType == OP_MISSION_VAR) {
426 sMissionStringValue = [mission_variables objectForKey:selectorString];
427 selector = @selector(mission_string);
428 opType = OP_STRING;
429 } else if (opType == OP_LOCAL_VAR) {
430 sMissionStringValue = [[self localVariablesForMission:sCurrentMissionKey] objectForKey:selectorString];
431 selector = @selector(mission_string);
432 opType = OP_STRING;
433 } else {
434 selector = NSSelectorFromString(selectorString);
435 }
436
437 expandedRHS = [self expandScriptRightHandSide:operandArray];
438
439 if (opType == OP_STRING) {
440 lhsString = [self performSelector:selector];
441
442#define DOUBLEVAL(x) ((x != nil) ? [x doubleValue] : 0.0)
443
444 switch (comparator) {
446 return lhsString == nil;
447
448 case COMPARISON_EQUAL:
449 return [lhsString isEqualToString:expandedRHS];
450
452 return ![lhsString isEqualToString:expandedRHS];
453
455 return DOUBLEVAL(lhsString) < DOUBLEVAL(expandedRHS);
456
458 return DOUBLEVAL(lhsString) > DOUBLEVAL(expandedRHS);
459
460 case COMPARISON_ONEOF: {
461 rhsComponents = [expandedRHS componentsSeparatedByString:@","];
462 count = [rhsComponents count];
463
464 whitespace = [NSCharacterSet whitespaceCharacterSet];
465 lhsString = [lhsString stringByTrimmingCharactersInSet:whitespace];
466
467 for (i = 0; i < count; i++) {
468 rhsItem = [[rhsComponents objectAtIndex:i] stringByTrimmingCharactersInSet:whitespace];
469 if ([lhsString isEqualToString:rhsItem]) {
470 return YES;
471 }
472 }
473 }
474 return NO;
475 }
476 } else if (opType == OP_NUMBER) {
477 lhsValue = [[self performSelector:selector] doubleValue];
478
479 if (comparator == COMPARISON_ONEOF) {
480 rhsComponents = [expandedRHS componentsSeparatedByString:@","];
481 count = [rhsComponents count];
482
483 for (i = 0; i < count; i++) {
484 rhsItem = [rhsComponents objectAtIndex:i];
485 rhsValue = [rhsItem doubleValue];
486
487 if (lhsValue == rhsValue) {
488 return YES;
489 }
490 }
491
492 return NO;
493 } else {
494 rhsValue = [expandedRHS doubleValue];
495
496 switch (comparator) {
497 case COMPARISON_EQUAL:
498 return lhsValue == rhsValue;
499
501 return lhsValue != rhsValue;
502
504 return lhsValue < rhsValue;
505
507 return lhsValue > rhsValue;
508
510 case COMPARISON_ONEOF:
511 // "Can't happen" - undefined should have been caught by the sanitizer, oneof is handled above.
512 OOLog(@"script.error.unexpectedOperator", @"***** SCRIPT ERROR: in %@, operator %@ is not valid for numbers, evaluating to false.", CurrentScriptDesc(), OOComparisonTypeToString(comparator));
513 return NO;
514 }
515 }
516 } else if (opType == OP_BOOL) {
517 lhsFlag = [[self performSelector:selector] isEqualToString:@"YES"];
518 rhsFlag = [expandedRHS isEqualToString:@"YES"];
519
520 switch (comparator) {
521 case COMPARISON_EQUAL:
522 return lhsFlag == rhsFlag;
523
525 return lhsFlag != rhsFlag;
526
530 case COMPARISON_ONEOF:
531 // "Can't happen" - should have been caught by the sanitizer.
532 OOLog(@"script.error.unexpectedOperator", @"***** SCRIPT ERROR: in %@, operator %@ is not valid for booleans, evaluating to false.", CurrentScriptDesc(), OOComparisonTypeToString(comparator));
533 return NO;
534 }
535 }
536
537 // What are we doing here?
538 OOLog(@"script.error.fallthrough", @"***** SCRIPT ERROR: in %@, unhandled condition '%@' (%@). %@", CurrentScriptDesc(), [scriptCondition objectAtIndex:1], scriptCondition, @"This is an internal error, please report it.");
539 return NO;
540}
#define OOLog(class, format,...)
Definition OOLogging.h:84
unsigned count
#define DOUBLEVAL(x)
NSString * OOComparisonTypeToString(OOComparisonType type)
static NSString * sMissionStringValue

References COMPARISON_EQUAL, COMPARISON_GREATERTHAN, COMPARISON_LESSTHAN, COMPARISON_NOTEQUAL, COMPARISON_ONEOF, COMPARISON_UNDEFINED, count, DOUBLEVAL, PlayerEntity::expandScriptRightHandSide:, PlayerEntity::localVariablesForMission:, nil, OOComparisonTypeToString(), OOLog, OP_BOOL, OP_FALSE, OP_LOCAL_VAR, OP_MISSION_VAR, OP_NUMBER, OP_STRING, and sMissionStringValue.

Here is the call graph for this function:

The documentation for this category was generated from the following file: