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 50 of file ShipEntityAI.m.

Method Documentation

◆ acceptDistressMessageFrom:

- (void) acceptDistressMessageFrom: (ShipEntity *)  other

Definition at line 1 of file ShipEntityAI.m.

2877 :(ShipEntity *)other
2878{
2879 [self setFoundTarget:[other primaryTarget]];
2880 if ([self isPolice])
2881 {
2882 [(ShipEntity*)[self foundTarget] markAsOffender:8 withReason:kOOLegalStatusReasonDistressCall]; // you have been warned!!
2883 }
2884
2885 NSString *context = nil;
2886#ifndef NDEBUG
2887 context = [NSString stringWithFormat:@"%@ broadcastDistressMessage", [other shortDescription]];
2888#endif
2889 [shipAI reactToMessage:@"ACCEPT_DISTRESS_CALL" context:context];
2890
2891}
return nil

◆ checkFoundTarget

- (void) checkFoundTarget

Definition at line 1 of file ShipEntityAI.m.

2739{
2740 if ([self foundTarget] != nil)
2741 {
2742 [shipAI message:@"TARGET_FOUND"];
2743 }
2744 else
2745 {
2746 [shipAI message:@"NOTHING_FOUND"];
2747 }
2748}

◆ performHyperSpaceExitReplace:

- (BOOL) performHyperSpaceExitReplace: (BOOL)  replace

Definition at line 1 of file ShipEntityAI.m.

2751 :(BOOL)replace
2752{
2753 return [self performHyperSpaceExitReplace:replace toSystem:-1];
2754}

◆ performHyperSpaceExitReplace:toSystem:

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

Definition at line 1 of file ShipEntityAI.m.

2757 :(BOOL)replace toSystem:(OOSystemID)systemID
2758{
2759 if(![self hasHyperspaceMotor])
2760 {
2761 [shipAI reactToMessage:@"WITCHSPACE UNAVAILABLE" context:@"performHyperSpaceExit"];
2762 return NO;
2763 }
2764 if([self status] == STATUS_ENTERING_WITCHSPACE)
2765 {
2766// already in a wormhole
2767 return NO;
2768 }
2769
2770 NSArray *sDests = nil;
2771 OOSystemID targetSystem;
2772 NSUInteger i = 0;
2773
2774 // get a list of destinations within range
2775 sDests = [UNIVERSE nearbyDestinationsWithinRange: 0.1f * fuel];
2776 NSUInteger n_dests = [sDests count];
2777
2778 // if none available report to the AI and exit
2779 if (n_dests == 0)
2780 {
2781 [shipAI reactToMessage:@"WITCHSPACE UNAVAILABLE" context:@"performHyperSpaceExit"];
2782
2783 // If no systems exist near us, the AI is switched to a different state, so we do not need
2784 // the nearby destinations array anymore.
2785 return NO;
2786 }
2787
2788 // check if we're clear of nearby masses
2789 ShipEntity *blocker = [UNIVERSE entityForUniversalID:[self checkShipsInVicinityForWitchJumpExit]];
2790 if (blocker)
2791 {
2792 [self setFoundTarget:blocker];
2793 [shipAI reactToMessage:@"WITCHSPACE BLOCKED" context:@"performHyperSpaceExit"];
2794 [self doScriptEvent:OOJSID("shipWitchspaceBlocked") withArgument:blocker];
2795
2796 return NO;
2797 }
2798
2799 if (systemID == -1)
2800 {
2801 // select one at random
2802 if (n_dests > 1)
2803 {
2804 i = ranrot_rand() % n_dests;
2805 }
2806
2807
2808 targetSystem = [[sDests oo_dictionaryAtIndex:i] oo_intForKey:@"sysID"];
2809 }
2810 else
2811 {
2812 targetSystem = systemID;
2813
2814 for (i = 0; i < n_dests; i++)
2815 {
2816 if (systemID == [[sDests oo_dictionaryAtIndex:i] oo_intForKey:@"sysID"]) break;
2817 }
2818
2819 if (i == n_dests) // no match found
2820 {
2821 return NO;
2822 }
2823 }
2824 float dist = [[sDests oo_dictionaryAtIndex:i] oo_floatForKey:@"distance"];
2825 if (dist > [self maxHyperspaceDistance] || dist > fuel/10.0f)
2826 {
2827 OOLogWARN(@"script.debug", @"DEBUG: %@ Jumping %f which is further than allowed. I have %d fuel", self, dist, fuel);
2828 }
2829 fuel -= 10 * dist;
2830
2831 // create wormhole
2832 WormholeEntity *whole = [[[WormholeEntity alloc] initWormholeTo: targetSystem fromShip:self] autorelease];
2833 [UNIVERSE addEntity: whole];
2834
2835 [self enterWormhole:whole replacing:replace];
2836
2837 // we've no need for the destinations array anymore.
2838 return YES;
2839}
#define OOLogWARN(class, format,...)
Definition OOLogging.h:113
int16_t OOSystemID
Definition OOTypes.h:211
#define ranrot_rand()

◆ scanForNearestShipWithNegatedPredicate:parameter:

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

Definition at line 1 of file ShipEntityAI.m.

2870 :(EntityFilterPredicate)predicate parameter:(void *)parameter
2871{
2872 ChainedEntityPredicateParameter param = { predicate, parameter };
2873 [self scanForNearestShipWithPredicate:NOTPredicate parameter:&param];
2874}
BOOL(* EntityFilterPredicate)(Entity *entity, void *parameter)
Definition Universe.h:52

◆ scanForNearestShipWithPredicate:parameter:

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

Definition at line 1 of file ShipEntityAI.m.

2842 :(EntityFilterPredicate)predicate parameter:(void *)parameter
2843{
2844 // Locates all the ships in range for which predicate returns YES, and chooses the nearest.
2845 unsigned i;
2846 ShipEntity *candidate;
2847 float d2, found_d2 = scannerRange * scannerRange;
2848
2849 DESTROY(_foundTarget);
2850 [self checkScanner];
2851
2852 if (predicate == NULL) return;
2853
2854 for (i = 0; i < n_scanned_ships ; i++)
2855 {
2856 candidate = scanned_ships[i];
2857 d2 = distance2_scanned_ships[i];
2858 if ((d2 < found_d2) && (candidate->scanClass != CLASS_CARGO) && ([candidate status] != STATUS_DOCKED)
2859 && predicate(candidate, parameter) && ![candidate isCloaked])
2860 {
2861 [self setFoundTarget:candidate];
2862 found_d2 = d2;
2863 }
2864 }
2865
2866 [self checkFoundTarget];
2867}
#define DESTROY(x)
Definition OOCocoa.h:75
OOScanClass scanClass()

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