Oolite 1.91.0.7645-241119-222d325
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

Extends class ShipEntity.

Definition at line 1 of file ShipEntityAI.m.

2884 :(ShipEntity *)other
2885{
2886 [self setFoundTarget:[other primaryTarget]];
2887 if ([self isPolice])
2888 {
2889 [(ShipEntity*)[self foundTarget] markAsOffender:8 withReason:kOOLegalStatusReasonDistressCall]; // you have been warned!!
2890 }
2891
2892 NSString *context = nil;
2893#ifndef NDEBUG
2894 context = [NSString stringWithFormat:@"%@ broadcastDistressMessage", [other shortDescription]];
2895#endif
2896 [shipAI reactToMessage:@"ACCEPT_DISTRESS_CALL" context:context];
2897
2898}
return nil

◆ checkFoundTarget

- (void) checkFoundTarget

Extends class ShipEntity.

Definition at line 1 of file ShipEntityAI.m.

2746{
2747 if ([self foundTarget] != nil)
2748 {
2749 [shipAI message:@"TARGET_FOUND"];
2750 }
2751 else
2752 {
2753 [shipAI message:@"NOTHING_FOUND"];
2754 }
2755}

◆ performHyperSpaceExitReplace:

- (BOOL) performHyperSpaceExitReplace: (BOOL) replace

Extends class ShipEntity.

Definition at line 1 of file ShipEntityAI.m.

2758 :(BOOL)replace
2759{
2760 return [self performHyperSpaceExitReplace:replace toSystem:-1];
2761}

◆ performHyperSpaceExitReplace:toSystem:

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

Extends class ShipEntity.

Definition at line 1 of file ShipEntityAI.m.

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

Extends class ShipEntity.

Definition at line 1 of file ShipEntityAI.m.

2877 :(EntityFilterPredicate)predicate parameter:(void *)parameter
2878{
2879 ChainedEntityPredicateParameter param = { predicate, parameter };
2880 [self scanForNearestShipWithPredicate:NOTPredicate parameter:&param];
2881}
BOOL(* EntityFilterPredicate)(Entity *entity, void *parameter)
Definition Universe.h:52

◆ scanForNearestShipWithPredicate:parameter:

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

Extends class ShipEntity.

Definition at line 1 of file ShipEntityAI.m.

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

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