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

#include <ShipEntityAI.h>

Instance Methods

(void) - setAITo:
(void) - setAIScript:
(void) - switchAITo:
(void) - scanForHostiles
(BOOL) - performHyperSpaceToSpecificSystem:
(void) - scanForNearestIncomingMissile
(void) - enterTargetWormhole
(void) - enterPlayerWormhole
(void) - wormholeEscorts
(void) - wormholeEntireGroup
(BOOL) - suggestEscortTo:
(void) - groupAttackTarget
(void) - performAttack
(void) - performCollect
(void) - performEscort
(void) - performFaceDestination
(void) - performFlee
(void) - performFlyToRangeFromDestination
(void) - performHold
(void) - performIdle
(void) - performIntercept
(void) - performLandOnPlanet
(void) - performMining
(void) - performScriptedAI
(void) - performScriptedAttackAI
(void) - performStop
(void) - performTumble
(void) - broadcastDistressMessage
(void) - broadcastDistressMessageWithDumping:
(void) - requestDockingCoordinates
(void) - recallDockingInstructions
(void) - performBuoyTumble [implementation]

Detailed Description

Definition at line 32 of file ShipEntityAI.h.

Method Documentation

◆ broadcastDistressMessage

- (void) broadcastDistressMessage

Extends class ShipEntity.

Definition at line 677 of file ShipEntityAI.m.

678{
679 /*-- Locates all the stations, bounty hunters and police ships in range and tells them that you are under attack --*/
680 [self broadcastDistressMessageWithDumping:YES];
681}

References broadcastDistressMessage, and ShipEntity::broadcastDistressMessageWithDumping:.

Referenced by broadcastDistressMessage.

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

◆ broadcastDistressMessageWithDumping:

- (void) broadcastDistressMessageWithDumping: (BOOL) dumpCargo

Extends class ShipEntity.

Definition at line 683 of file ShipEntityAI.m.

683 :(BOOL)dumpCargo
684{
685 [self checkScannerIgnoringUnpowered];
686 DESTROY(_foundTarget);
687
688 ShipEntity* aggressor_ship = (ShipEntity*)[self primaryAggressor];
689 if (aggressor_ship == nil)
690 return;
691
692 // don't send too many distress messages at once, space them out semi-randomly
693 if (messageTime > 2.0 * randf())
694 return;
695
696 NSString* distress_message = nil;
697 BOOL is_buoy = (scanClass == CLASS_BUOY);
698 if (is_buoy)
699 distress_message = @"[buoy-distress-call]";
700 else
701 distress_message = @"[distress-call]";
702
703 unsigned i;
704 for (i = 0; i < n_scanned_ships; i++) {
705 ShipEntity* ship = scanned_ships[i];
706
707 // dump cargo if energy is low
708 if (dumpCargo && !is_buoy && [self primaryAggressor] == ship && energy < 0.375 * maxEnergy) {
709 [self ejectCargo];
710 [self performFlee];
711 }
712
713 // tell it! (only plist AIs send comms here; JS AIs are
714 // expected to handle their own)
715 if (ship->isPlayer && ![self hasNewAI]) {
716 [ship doScriptEvent:OOJSID("distressMessageReceived") withArgument:aggressor_ship andArgument:self];
717
718 if (!is_buoy && [self primaryAggressor] == ship && energy < 0.375 * maxEnergy) {
719 [self sendExpandedMessage:@"[beg-for-mercy]" toShip:ship];
720 } else if ([self bounty] == 0) {
721 // only send distress message to player if plausibly sending
722 // one more generally
723 [self sendExpandedMessage:distress_message toShip:ship];
724 }
725
726 // reset the thanked_ship_id
727 DESTROY(_thankedShip);
728 } else if ([self bounty] == 0 && [ship crew]) // Only clean ships can have their distress calls accepted
729 {
730 [ship doScriptEvent:OOJSID("distressMessageReceived") withArgument:aggressor_ship andArgument:self];
731
732 // we only can send distressMessages to ships that are known to have a "ACCEPT_DISTRESS_CALL" reaction
733 // in their AI, or they might react wrong on the added found_target.
734
735 // ship must have a plist AI for this next bit. JS AIs
736 // should already have done something sensible on
737 // distressMessageReceived
738 if (![self hasNewAI]) {
739 // FIXME: this test only works with core AIs
740 if (ship->isStation || [ship hasPrimaryRole:@"police"] || [ship hasPrimaryRole:@"hunter"]) {
741 [ship acceptDistressMessageFrom:self];
742 }
743 }
744 }
745 }
746}
#define DESTROY(x)
return nil
unsigned isStation
Definition Entity.m:135
unsigned isPlayer
Definition Entity.m:145
void doScriptEvent:withArgument:andArgument:(OOJSPropID message,[withArgument] id argument1,[andArgument] id argument2)
void acceptDistressMessageFrom:(ShipEntity *other)
float randf(void)

References ShipEntity::acceptDistressMessageFrom:, ShipEntity::checkScannerIgnoringUnpowered, DESTROY, ShipEntity::doScriptEvent:withArgument:andArgument:, ShipEntity::ejectCargo, Entity::isPlayer, Entity::isStation, nil, ShipEntity::performFlee, randf(), and ShipEntity::sendExpandedMessage:toShip:.

Here is the call graph for this function:

◆ enterPlayerWormhole

- (void) enterPlayerWormhole

Extends class ShipEntity.

Definition at line 564 of file ShipEntityAI.m.

565{
566 [self enterWormhole:[PLAYER wormhole] replacing:NO];
567}

References enterPlayerWormhole, and ShipEntity::enterWormhole:replacing:.

Referenced by enterPlayerWormhole.

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

◆ enterTargetWormhole

- (void) enterTargetWormhole

Extends class ShipEntity.

Definition at line 569 of file ShipEntityAI.m.

570{
571 WormholeEntity* whole = nil;
572 ShipEntity* targEnt = [self primaryTarget];
573 double found_d2 = scannerRange * scannerRange;
574
575 if (targEnt && (HPdistance2(position, [targEnt position]) < found_d2)) {
576 if ([targEnt isWormhole])
577 whole = (WormholeEntity*)targEnt;
578 else if ([targEnt isPlayer])
579 whole = [PLAYER wormhole];
580 }
581
582 if (!whole) {
583 // locate nearest wormhole
584 int ent_count = UNIVERSE->n_entities;
585 Entity** uni_entities = UNIVERSE->sortedEntities; // grab the public sorted list
586 WormholeEntity* wormholes[ent_count];
587 int i;
588 int wh_count = 0;
589 for (i = 0; i < ent_count; i++)
590 if (uni_entities[i]->isWormhole)
591 wormholes[wh_count++] = [(WormholeEntity*)uni_entities[i] retain];
592 //
593 // double found_d2 = scannerRange * scannerRange;
594 for (i = 0; i < wh_count; i++) {
595 WormholeEntity* wh = wormholes[i];
596 double d2 = HPdistance2(position, wh->position);
597 if (d2 < found_d2) {
598 whole = wh;
599 found_d2 = d2;
600 }
601 [wh release];
602 }
603 }
604
605 [self enterWormhole:whole replacing:NO];
606}
OOINLINE OOHPScalar HPdistance2(HPVector v1, HPVector v2) INLINE_CONST_FUNC
Definition OOHPVector.h:293
#define UNIVERSE
Definition Universe.h:827
HPVector position
Definition Entity.m:576

References enterTargetWormhole, ShipEntity::enterWormhole:replacing:, HPdistance2(), nil, Entity::position, ShipEntity::primaryTarget, and UNIVERSE.

Referenced by enterTargetWormhole.

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

◆ groupAttackTarget

- (void) groupAttackTarget

Extends class ShipEntity.

Definition at line 315 of file ShipEntityAI.m.

316{
317 ShipEntity *target = nil, *ship = nil;
318
319 target = [self primaryTarget];
320
321 if (target == nil)
322 return;
323
324 if ([self group] == nil) // ship is alone!
325 {
326 [self setFoundTarget:target];
327 [shipAI reactToMessage:@"GROUP_ATTACK_TARGET" context:@"groupAttackTarget"];
328 [self doScriptEvent:OOJSID("helpRequestReceived") withArgument:self andArgument:target];
329 return;
330 }
331
332 foreach (ship, [[self group] mutationSafeEnumerator]) {
333 [ship setFoundTarget:target];
334 [ship reactToAIMessage:@"GROUP_ATTACK_TARGET" context:@"groupAttackTarget"];
335 [ship doScriptEvent:OOJSID("helpRequestReceived") withArgument:self andArgument:target];
336
337 if ([ship escortGroup] != [ship group] && [[ship escortGroup] count] > 1) // Ship has a seperate escort group.
338 {
339 ShipEntity* escort = nil;
340 NSArray* escortMembers = [[ship escortGroup] memberArrayExcludingLeader];
341 foreach (escort, escortMembers) {
342 [escort setFoundTarget:target];
343 [escort reactToAIMessage:@"GROUP_ATTACK_TARGET" context:@"groupAttackTarget"];
344 [escort doScriptEvent:OOJSID("helpRequestReceived") withArgument:self andArgument:target];
345 }
346 }
347 }
348}
unsigned count
void reactToAIMessage:context:(NSString *message,[context] NSString *debugContext)
void setFoundTarget:(Entity *targetEntity)

References count, ShipEntity::doScriptEvent:withArgument:andArgument:, groupAttackTarget, nil, ShipEntity::primaryTarget, ShipEntity::reactToAIMessage:context:, and ShipEntity::setFoundTarget:.

Referenced by groupAttackTarget.

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

◆ performAttack

- (void) performAttack

Extends class ShipEntity.

Definition at line 350 of file ShipEntityAI.m.

351{
352 if (behaviour != BEHAVIOUR_EVASIVE_ACTION) {
353 behaviour = BEHAVIOUR_ATTACK_TARGET;
354 desired_range = 1250 * randf() + 750; // 750 til 2000
355 frustration = 0.0;
356 }
357}

References performAttack, and randf().

Referenced by performAttack.

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

◆ performBuoyTumble

- (void) performBuoyTumble
implementation

Extends class ShipEntity.

Definition at line 458 of file ShipEntityAI.m.

459{
460 stick_roll = 0.10;
461 stick_pitch = 0.15;
462 behaviour = BEHAVIOUR_TUMBLE;
463 frustration = 0.0;
464}

References performBuoyTumble.

Referenced by performBuoyTumble.

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

◆ performCollect

- (void) performCollect

Extends class ShipEntity.

Definition at line 359 of file ShipEntityAI.m.

360{
361 behaviour = BEHAVIOUR_COLLECT_TARGET;
362 frustration = 0.0;
363}

References performCollect.

Referenced by performCollect.

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

◆ performEscort

- (void) performEscort

Extends class ShipEntity.

Definition at line 365 of file ShipEntityAI.m.

366{
367 if (behaviour != BEHAVIOUR_FORMATION_FORM_UP) {
368 behaviour = BEHAVIOUR_FORMATION_FORM_UP;
369 frustration = 0.0; // behavior changed, reset frustration.
370 }
371}

References performEscort.

Referenced by performEscort.

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

◆ performFaceDestination

- (void) performFaceDestination

Extends class ShipEntity.

Definition at line 373 of file ShipEntityAI.m.

374{
375 behaviour = BEHAVIOUR_FACE_DESTINATION;
376 frustration = 0.0;
377}

References performFaceDestination.

Referenced by performFaceDestination.

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

◆ performFlee

- (void) performFlee

Extends class ShipEntity.

Definition at line 379 of file ShipEntityAI.m.

380{
381 if (behaviour != BEHAVIOUR_FLEE_EVASIVE_ACTION) {
382 behaviour = BEHAVIOUR_FLEE_TARGET;
383 [self setEvasiveJink:400.0];
384 frustration = 0.0;
385 if (accuracy > COMBAT_AI_ISNT_AWFUL) {
386 // alert! they've got us in their sights! react!!
387 if ([self approachAspectToPrimaryTarget] > 0.9995) {
388 behaviour = randf() < 0.15 ? BEHAVIOUR_EVASIVE_ACTION : BEHAVIOUR_FLEE_EVASIVE_ACTION;
389 }
390 }
391 }
392}
#define COMBAT_AI_ISNT_AWFUL
Definition ShipEntity.h:124

References COMBAT_AI_ISNT_AWFUL, performFlee, randf(), and ShipEntity::setEvasiveJink:.

Referenced by performFlee.

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

◆ performFlyToRangeFromDestination

- (void) performFlyToRangeFromDestination

Extends class ShipEntity.

Definition at line 394 of file ShipEntityAI.m.

395{
396 behaviour = BEHAVIOUR_FLY_RANGE_FROM_DESTINATION;
397 frustration = 0.0;
398}

References performFlyToRangeFromDestination.

Referenced by performFlyToRangeFromDestination.

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

◆ performHold

- (void) performHold

Extends class ShipEntity.

Definition at line 400 of file ShipEntityAI.m.

401{
402 desired_speed = 0.0;
403 behaviour = BEHAVIOUR_TRACK_TARGET;
404 frustration = 0.0;
405}

References performHold.

Referenced by performHold.

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

◆ performHyperSpaceToSpecificSystem:

- (BOOL) performHyperSpaceToSpecificSystem: (OOSystemID) systemID

Extends class ShipEntity.

Definition at line 481 of file ShipEntityAI.m.

481 :(OOSystemID)systemID
482{
483 return [self performHyperSpaceExitReplace:NO toSystem:systemID];
484}
int16_t OOSystemID
Definition OOTypes.h:183

References ShipEntity::performHyperSpaceExitReplace:toSystem:.

Here is the call graph for this function:

◆ performIdle

- (void) performIdle

Extends class ShipEntity.

Definition at line 407 of file ShipEntityAI.m.

408{
409 behaviour = BEHAVIOUR_IDLE;
410 frustration = 0.0;
411}

References performIdle.

Referenced by performIdle.

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

◆ performIntercept

- (void) performIntercept

Extends class ShipEntity.

Definition at line 413 of file ShipEntityAI.m.

414{
415 behaviour = BEHAVIOUR_INTERCEPT_TARGET;
416 frustration = 0.0;
417}

References performIntercept.

Referenced by performIntercept.

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

◆ performLandOnPlanet

- (void) performLandOnPlanet

Extends class ShipEntity.

Definition at line 419 of file ShipEntityAI.m.

420{
421 OOPlanetEntity* nearest = [self findNearestPlanet];
422 if (isNearPlanetSurface) {
423 _destination = [nearest position];
424 behaviour = BEHAVIOUR_LAND_ON_PLANET;
425 planetForLanding = [nearest universalID];
426 } else {
427 behaviour = BEHAVIOUR_IDLE;
428 [shipAI message:@"NO_PLANET_NEARBY"];
429 }
430
431 frustration = 0.0;
432}

References ShipEntity::findNearestPlanet, and performLandOnPlanet.

Referenced by performLandOnPlanet.

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

◆ performMining

- (void) performMining

Extends class ShipEntity.

Definition at line 434 of file ShipEntityAI.m.

435{
436 Entity* target = [self primaryTarget];
437 // mining is not seen as hostile behaviour, so ensure it is only used against rocks.
438 if (target && [target scanClass] == CLASS_ROCK) {
439 behaviour = BEHAVIOUR_ATTACK_MINING_TARGET;
440 frustration = 0.0;
441 } else {
442 [self noteLostTargetAndGoIdle];
443 }
444}

References ShipEntity::noteLostTargetAndGoIdle, performMining, and ShipEntity::primaryTarget.

Referenced by performMining.

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

◆ performScriptedAI

- (void) performScriptedAI

Extends class ShipEntity.

Definition at line 446 of file ShipEntityAI.m.

447{
448 behaviour = BEHAVIOUR_SCRIPTED_AI;
449 frustration = 0.0;
450}

References performScriptedAI.

Referenced by performScriptedAI.

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

◆ performScriptedAttackAI

- (void) performScriptedAttackAI

Extends class ShipEntity.

Definition at line 452 of file ShipEntityAI.m.

453{
454 behaviour = BEHAVIOUR_SCRIPTED_ATTACK_AI;
455 frustration = 0.0;
456}

References performScriptedAttackAI.

Referenced by performScriptedAttackAI.

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

◆ performStop

- (void) performStop

Extends class ShipEntity.

Definition at line 466 of file ShipEntityAI.m.

467{
468 behaviour = BEHAVIOUR_STOP_STILL;
469 desired_speed = 0.0;
470 frustration = 0.0;
471}

References performStop.

Referenced by performStop.

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

◆ performTumble

- (void) performTumble

Extends class ShipEntity.

Definition at line 473 of file ShipEntityAI.m.

474{
475 stick_roll = max_flight_roll * 2.0 * (randf() - 0.5);
476 stick_pitch = max_flight_pitch * 2.0 * (randf() - 0.5);
477 behaviour = BEHAVIOUR_TUMBLE;
478 frustration = 0.0;
479}

References performTumble, and randf().

Referenced by performTumble.

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

◆ recallDockingInstructions

- (void) recallDockingInstructions

Extends class ShipEntity.

Definition at line 536 of file ShipEntityAI.m.

537{
538 if (dockingInstructions != nil) {
539 _destination = [dockingInstructions oo_hpvectorForKey:@"destination"];
540 desired_speed = fmin([dockingInstructions oo_floatForKey:@"speed"], maxFlightSpeed);
541 desired_range = [dockingInstructions oo_floatForKey:@"range"];
542 if ([dockingInstructions objectForKey:@"station"]) {
543 StationEntity* targetStation = [[dockingInstructions objectForKey:@"station"] weakRefUnderlyingObject];
544 if (targetStation != nil) {
545 [self addTarget:targetStation];
546 [self setTargetStation:targetStation];
547 } else {
548 [self removeTarget:[self primaryTarget]];
549 }
550 }
551 docking_match_rotation = [dockingInstructions oo_boolForKey:@"match_rotation"];
552 }
553}

References ShipEntity::addTarget:, nil, ShipEntity::primaryTarget, recallDockingInstructions, ShipEntity::removeTarget:, and ShipEntity::setTargetStation:.

Referenced by recallDockingInstructions.

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

◆ requestDockingCoordinates

- (void) requestDockingCoordinates

Extends class ShipEntity.

Definition at line 486 of file ShipEntityAI.m.

487{
488 /*- requests coordinates from the target station
489 if the target station can't be found
490 then use the nearest it can find (which may be a rock hermit) -*/
491
492 StationEntity* station = nil;
493 Entity* targStation = nil;
494 NSString* message = nil;
495 double distanceToStation2 = 0.0;
496
497 targStation = [self targetStation];
498 if ([targStation isStation]) {
499 station = (StationEntity*)targStation;
500 } else {
501 station = [UNIVERSE nearestShipMatchingPredicate:IsStationPredicate
502 parameter:nil
503 relativeToEntity:self];
504 }
505
506 distanceToStation2 = HPdistance2([station position], [self position]);
507
508 // Player check for being inside the aegis already exists in PlayerEntityControls. We just
509 // check here that distance to station is less than 2.5 times scanner range to avoid problems with
510 // NPC ships getting stuck with a dockingAI while just outside the aegis - Nikos 20090630, as proposed by Eric
511 // On very busy systems (> 50 docking ships) docking ships can be sent to a hold position outside the range,
512 // so also test for presence of dockingInstructions. - Eric 20091130
513 if (station != nil && (distanceToStation2 < SCANNER_MAX_RANGE2 * 6.25 || dockingInstructions != nil)) {
514 // remember the instructions
515 [dockingInstructions release];
516 dockingInstructions = [[station dockingInstructionsForShip:self] retain];
517 if (dockingInstructions != nil) {
518 [self recallDockingInstructions];
519
520 message = [dockingInstructions objectForKey:@"ai_message"];
521 if (message != nil)
522 [shipAI message:message];
523 message = [dockingInstructions objectForKey:@"comms_message"];
524 if (message != nil)
525 [station sendExpandedMessage:message toShip:self];
526 }
527 } else {
528 DESTROY(dockingInstructions);
529 }
530
531 if (dockingInstructions == nil) {
532 [shipAI message:@"NO_STATION_FOUND"];
533 }
534}
#define SCANNER_MAX_RANGE2
Definition Entity.h:54

References DESTROY, StationEntity::dockingInstructionsForShip:, HPdistance2(), nil, ShipEntity::recallDockingInstructions, requestDockingCoordinates, SCANNER_MAX_RANGE2, ShipEntity::sendExpandedMessage:toShip:, and ShipEntity::targetStation.

Referenced by requestDockingCoordinates.

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

◆ scanForHostiles

- (void) scanForHostiles

Extends class ShipEntity.

Definition at line 293 of file ShipEntityAI.m.

294{
295 /*-- Locates all the ships in range targeting the receiver and chooses the nearest --*/
296 DESTROY(_foundTarget);
297
298 [self checkScanner];
299 unsigned i;
300 GLfloat found_d2 = scannerRange * scannerRange;
301 for (i = 0; i < n_scanned_ships; i++) {
302 ShipEntity* thing = scanned_ships[i];
303 GLfloat d2 = distance2_scanned_ships[i];
304 if ((d2 < found_d2)
305 && ([thing isThargoid] || (([thing primaryTarget] == self) && [thing hasHostileTarget]) || [thing isDefenseTarget:self])
306 && ![thing isCloaked]) {
307 [self setFoundTarget:thing];
308 found_d2 = d2;
309 }
310 }
311
312 [self checkFoundTarget];
313}

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

Referenced by scanForHostiles.

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

◆ scanForNearestIncomingMissile

- (void) scanForNearestIncomingMissile

Extends class ShipEntity.

Definition at line 555 of file ShipEntityAI.m.

556{
557 BinaryOperationPredicateParameter param = {
558 HasScanClassPredicate, [NSNumber numberWithInt:CLASS_MISSILE],
560 };
561 [self scanForNearestShipWithPredicate:ANDPredicate parameter:&param];
562}
BOOL HasScanClassPredicate(Entity *entity, void *parameter)
BOOL IsHostileAgainstTargetPredicate(Entity *ship, void *parameter)

References HasScanClassPredicate(), IsHostileAgainstTargetPredicate(), scanForNearestIncomingMissile, and ShipEntity::scanForNearestShipWithPredicate:parameter:.

Referenced by scanForNearestIncomingMissile.

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

◆ setAIScript:

- (void) setAIScript: (NSString*) aiString

Extends class ShipEntity.

Definition at line 268 of file ShipEntityAI.m.

268 :(NSString*)aiString
269{
270 NSMutableDictionary* properties = nil;
271
272 properties = [NSMutableDictionary dictionary];
273 [properties setObject:self forKey:@"ship"];
274
275 [aiScript autorelease];
276 aiScript = [OOScript jsAIScriptFromFileNamed:aiString properties:properties];
277 if (aiScript == nil) {
278 OOLog(@"ai.load.failed.unknownAI", @"Unable to load JS AI %@ for ship %@ (%@ for role %@)", aiString, self, [self shipDataKey], [self primaryRole]);
279 aiScript = [OOScript jsAIScriptFromFileNamed:@"oolite-nullAI.js" properties:properties];
280 } else {
281 aiScriptWakeTime = 0;
282 haveStartedJSAI = NO;
283 }
284 [aiScript retain];
285}
#define OOLog(class, format,...)
Definition OOLogging.h:84
id jsAIScriptFromFileNamed:properties:(NSString *fileName,[properties] NSDictionary *properties)
Definition OOScript.m:202

References OOScript::jsAIScriptFromFileNamed:properties:, nil, and OOLog.

Here is the call graph for this function:

◆ setAITo:

- (void) setAITo: (NSString*) aiString

Extends class ShipEntity.

Definition at line 245 of file ShipEntityAI.m.

245 :(NSString*)aiString
246{
247 // don't try to load real AIs if the game hasn't started yet
248 if (![PLAYER scriptsLoaded]) {
249 aiString = @"oolite-nullAI.js";
250 }
251 if ([aiString hasSuffix:@".plist"]) {
252 [[self getAI] setStateMachine:aiString withJSScript:@"oolite-nullAI.js"];
253 [self setAIScript:@"oolite-nullAI.js"];
254 } else if ([aiString hasSuffix:@".js"]) {
255 [[self getAI] setStateMachine:@"nullAI.plist" withJSScript:aiString];
256 [self setAIScript:aiString];
257 } else {
258 NSString* path = [ResourceManager pathForFileNamed:[aiString stringByAppendingString:@".js"] inFolder:@"AIs"];
259 if (path == nil) // no js, use plist
260 {
261 [self setAITo:[aiString stringByAppendingString:@".plist"]];
262 } else {
263 [self setAITo:[aiString stringByAppendingString:@".js"]];
264 }
265 }
266}
#define PLAYER
NSString * pathForFileNamed:inFolder:(NSString *fileName,[inFolder] NSString *folderName)

References ShipEntity::getAI, nil, ResourceManager::pathForFileNamed:inFolder:, PLAYER, ShipEntity::setAIScript:, ShipEntity::setAITo:, and AI::setStateMachine:withJSScript:.

Here is the call graph for this function:

◆ suggestEscortTo:

- (BOOL) suggestEscortTo: (ShipEntity*) mother

Extends class ShipEntity.

Definition at line 641 of file ShipEntityAI.m.

641 :(ShipEntity*)mother
642{
643 if (mother) {
644#ifdef OO_DEBUG_MONITOR_ENABLED
645 if (reportAIMessages) {
646 OOLog(@"ai.suggestEscort", @"DEBUG: %@ suggests escorting %@", self, mother);
647 }
648#endif
649
650 if ([mother acceptAsEscort:self]) {
651 // copy legal status across
652 if (([mother legalStatus] > 0) && (bounty <= 0)) {
653 int extra = 1 | (ranrot_rand() & 15);
654 // [mother setBounty: [mother legalStatus] + extra withReason:kOOLegalStatusReasonAssistingOffender];
655 [self markAsOffender:extra withReason:kOOLegalStatusReasonAssistingOffender];
656 // bounty += extra; // obviously we're dodgier than we thought!
657 }
658
659 [self setOwner:mother];
660 [self setGroup:[mother escortGroup]];
661 [shipAI message:@"ESCORTING"];
662 return YES;
663 }
664
665#ifdef OO_DEBUG_MONITOR_ENABLED
666 if (reportAIMessages) {
667 OOLog(@"ai.suggestEscort.refused", @"DEBUG: %@ refused by %@", self, mother);
668 }
669#endif
670 }
671 [self setOwner:self];
672 [shipAI message:@"NOT_ESCORTING"];
673 [self doScriptEvent:OOJSID("escortRejected") withArgument:mother];
674 return NO;
675}
OOShipGroup * escortGroup()
#define ranrot_rand()

References ShipEntity::doScriptEvent:withArgument:, ShipEntity::escortGroup, ShipEntity::markAsOffender:withReason:, OOLog, ranrot_rand, ShipEntity::setGroup:, and ShipEntity::setOwner:.

Here is the call graph for this function:

◆ switchAITo:

- (void) switchAITo: (NSString*) aiString

Extends class ShipEntity.

Definition at line 287 of file ShipEntityAI.m.

287 :(NSString*)aiString
288{
289 [self setAITo:aiString];
290 [[self getAI] clearStack];
291}

References AI::clearStack, ShipEntity::getAI, and ShipEntity::setAITo:.

Here is the call graph for this function:

◆ wormholeEntireGroup

- (void) wormholeEntireGroup

Extends class ShipEntity.

Definition at line 635 of file ShipEntityAI.m.

636{
637 [self wormholeGroup];
638 [self wormholeEscorts];
639}

References wormholeEntireGroup, ShipEntity::wormholeEscorts, and ShipEntity::wormholeGroup.

Referenced by wormholeEntireGroup.

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

◆ wormholeEscorts

- (void) wormholeEscorts

Extends class ShipEntity.

Definition at line 609 of file ShipEntityAI.m.

610{
611 ShipEntity* ship = nil;
612 NSString* context = nil;
613 WormholeEntity* whole = nil;
614
615 whole = [self primaryTarget];
616 if (![whole isWormhole])
617 return;
618
619#ifndef NDEBUG
620 context = [NSString stringWithFormat:@"%@ wormholeEscorts", [self shortDescription]];
621#endif
622
623 foreach (ship, [self escortEnumerator]) {
624 [ship addTarget:whole];
625 [ship reactToAIMessage:@"ENTER WORMHOLE" context:context];
626 [ship doScriptEvent:OOJSID("wormholeSuggested") withArgument:whole];
627 }
628
629 // We now have no escorts..
630
631 [_escortGroup release];
632 _escortGroup = nil;
633}
void addTarget:(Entity *targetEntity)
void doScriptEvent:withArgument:(OOJSPropID message,[withArgument] id argument)

References ShipEntity::addTarget:, ShipEntity::doScriptEvent:withArgument:, nil, ShipEntity::primaryTarget, ShipEntity::reactToAIMessage:context:, and wormholeEscorts.

Referenced by wormholeEscorts.

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

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