Oolite
Loading...
Searching...
No Matches
ShipEntity(OOAIPrivate) Category Reference

Instance Methods

(void) - checkFoundTarget
(BOOL) - performHyperSpaceExitReplace:
(BOOL) - performHyperSpaceExitReplace:toSystem:
(void) - scanForNearestShipWithPredicate:parameter:
(void) - scanForNearestShipWithNegatedPredicate:parameter:
(void) - acceptDistressMessageFrom:

Detailed Description

Definition at line 48 of file ShipEntityAI.m.

Method Documentation

◆ acceptDistressMessageFrom:

- (void) acceptDistressMessageFrom: (ShipEntity*) other

Extends class ShipEntity.

Definition at line 2513 of file ShipEntityAI.m.

2513 :(ShipEntity*)other
2514{
2515 [self setFoundTarget:[other primaryTarget]];
2516 if ([self isPolice]) {
2517 [(ShipEntity*)[self foundTarget] markAsOffender:8 withReason:kOOLegalStatusReasonDistressCall]; // you have been warned!!
2518 }
2519
2520 NSString* context = nil;
2521#ifndef NDEBUG
2522 context = [NSString stringWithFormat:@"%@ broadcastDistressMessage", [other shortDescription]];
2523#endif
2524 [shipAI reactToMessage:@"ACCEPT_DISTRESS_CALL"
2525 context:context];
2526}
return nil
void markAsOffender:withReason:(int offence_value,[withReason] OOLegalStatusReason reason)

References ShipEntity::foundTarget, nil, ShipEntity::primaryTarget, and ShipEntity::setFoundTarget:.

Here is the call graph for this function:

◆ checkFoundTarget

- (void) checkFoundTarget

Extends class ShipEntity.

Definition at line 2393 of file ShipEntityAI.m.

2394{
2395 if ([self foundTarget] != nil) {
2396 [shipAI message:@"TARGET_FOUND"];
2397 } else {
2398 [shipAI message:@"NOTHING_FOUND"];
2399 }
2400}

References checkFoundTarget, and nil.

Referenced by checkFoundTarget.

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

◆ performHyperSpaceExitReplace:

- (BOOL) performHyperSpaceExitReplace: (BOOL) replace

Extends class ShipEntity.

Definition at line 2402 of file ShipEntityAI.m.

2402 :(BOOL)replace
2403{
2404 return [self performHyperSpaceExitReplace:replace toSystem:-1];
2405}

References ShipEntity::performHyperSpaceExitReplace:toSystem:.

Here is the call graph for this function:

◆ performHyperSpaceExitReplace:toSystem:

- (BOOL) performHyperSpaceExitReplace: (BOOL) replace
toSystem: (OOSystemID) systemID 

Extends class ShipEntity.

Definition at line 2407 of file ShipEntityAI.m.

2407 :(BOOL)replace toSystem:(OOSystemID)systemID
2408{
2409 if (![self hasHyperspaceMotor]) {
2410 [shipAI reactToMessage:@"WITCHSPACE UNAVAILABLE" context:@"performHyperSpaceExit"];
2411 return NO;
2412 }
2413 if ([self status] == STATUS_ENTERING_WITCHSPACE) {
2414 // already in a wormhole
2415 return NO;
2416 }
2417
2418 NSArray* sDests = nil;
2419 OOSystemID targetSystem;
2420 NSUInteger i = 0;
2421
2422 // get a list of destinations within range
2423 sDests = [UNIVERSE nearbyDestinationsWithinRange:0.1f * fuel];
2424 NSUInteger n_dests = [sDests count];
2425
2426 // if none available report to the AI and exit
2427 if (n_dests == 0) {
2428 [shipAI reactToMessage:@"WITCHSPACE UNAVAILABLE" context:@"performHyperSpaceExit"];
2429
2430 // If no systems exist near us, the AI is switched to a different state, so we do not need
2431 // the nearby destinations array anymore.
2432 return NO;
2433 }
2434
2435 // check if we're clear of nearby masses
2436 ShipEntity* blocker = [UNIVERSE entityForUniversalID:[self checkShipsInVicinityForWitchJumpExit]];
2437 if (blocker) {
2438 [self setFoundTarget:blocker];
2439 [shipAI reactToMessage:@"WITCHSPACE BLOCKED" context:@"performHyperSpaceExit"];
2440 [self doScriptEvent:OOJSID("shipWitchspaceBlocked") withArgument:blocker];
2441
2442 return NO;
2443 }
2444
2445 if (systemID == -1) {
2446 // select one at random
2447 if (n_dests > 1) {
2448 i = ranrot_rand() % n_dests;
2449 }
2450
2451 targetSystem = [[sDests oo_dictionaryAtIndex:i] oo_intForKey:@"sysID"];
2452 } else {
2453 targetSystem = systemID;
2454
2455 for (i = 0; i < n_dests; i++) {
2456 if (systemID == [[sDests oo_dictionaryAtIndex:i] oo_intForKey:@"sysID"])
2457 break;
2458 }
2459
2460 if (i == n_dests) // no match found
2461 {
2462 return NO;
2463 }
2464 }
2465 float dist = [[sDests oo_dictionaryAtIndex:i] oo_floatForKey:@"distance"];
2466 if (dist > [self maxHyperspaceDistance] || dist > fuel / 10.0f) {
2467 OOLogWARN(@"script.debug", @"DEBUG: %@ Jumping %f which is further than allowed. I have %d fuel", self, dist, fuel);
2468 }
2469 fuel -= 10 * dist;
2470
2471 // create wormhole
2472 WormholeEntity* whole = [[[WormholeEntity alloc] initWormholeTo:targetSystem fromShip:self] autorelease];
2473 [UNIVERSE addEntity:whole];
2474
2475 [self enterWormhole:whole replacing:replace];
2476
2477 // we've no need for the destinations array anymore.
2478 return YES;
2479}
#define OOLogWARN(class, format,...)
Definition OOLogging.h:126
int16_t OOSystemID
Definition OOTypes.h:183
#define ranrot_rand()

References ShipEntity::checkShipsInVicinityForWitchJumpExit, ShipEntity::doScriptEvent:withArgument:, ShipEntity::enterWormhole:replacing:, nil, OOLogWARN, ranrot_rand, and ShipEntity::setFoundTarget:.

Here is the call graph for this function:

◆ scanForNearestShipWithNegatedPredicate:parameter:

- (void) scanForNearestShipWithNegatedPredicate: (EntityFilterPredicate) predicate
parameter: (void*) parameter 

Extends class ShipEntity.

Definition at line 2507 of file ShipEntityAI.m.

2507 :(EntityFilterPredicate)predicate parameter:(void*)parameter
2508{
2509 ChainedEntityPredicateParameter param = { predicate, parameter };
2510 [self scanForNearestShipWithPredicate:NOTPredicate parameter:&param];
2511}
BOOL(* EntityFilterPredicate)(Entity *entity, void *parameter)
Definition Universe.h:51

References ShipEntity::scanForNearestShipWithPredicate:parameter:.

Here is the call graph for this function:

◆ scanForNearestShipWithPredicate:parameter:

- (void) scanForNearestShipWithPredicate: (EntityFilterPredicate) predicate
parameter: (void*) parameter 

Extends class ShipEntity.

Definition at line 2481 of file ShipEntityAI.m.

2481 :(EntityFilterPredicate)predicate parameter:(void*)parameter
2482{
2483 // Locates all the ships in range for which predicate returns YES, and chooses the nearest.
2484 unsigned i;
2485 ShipEntity* candidate;
2486 float d2, found_d2 = scannerRange * scannerRange;
2487
2488 DESTROY(_foundTarget);
2489 [self checkScanner];
2490
2491 if (predicate == NULL)
2492 return;
2493
2494 for (i = 0; i < n_scanned_ships; i++) {
2495 candidate = scanned_ships[i];
2496 d2 = distance2_scanned_ships[i];
2497 if ((d2 < found_d2) && (candidate->scanClass != CLASS_CARGO) && ([candidate status] != STATUS_DOCKED)
2498 && predicate(candidate, parameter) && ![candidate isCloaked]) {
2499 [self setFoundTarget:candidate];
2500 found_d2 = d2;
2501 }
2502 }
2503
2504 [self checkFoundTarget];
2505}
#define DESTROY(x)
OOScanClass scanClass()

References ShipEntity::checkFoundTarget, ShipEntity::checkScanner, DESTROY, ShipEntity::scanClass, and ShipEntity::setFoundTarget:.

Here is the call graph for this function:

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