30#import "OOJSFunction.h"
31#import "OOJavaScriptEngine.h"
41#import "OOConstToJSString.h"
48@interface ShipEntity (OOAIPrivate)
52- (BOOL)performHyperSpaceExitReplace:(BOOL)replace;
53- (BOOL)performHyperSpaceExitReplace:(BOOL)replace toSystem:(
OOSystemID)systemID;
56- (void)scanForNearestShipWithNegatedPredicate:(
EntityFilterPredicate)predicate parameter:(
void*)parameter;
58- (void)acceptDistressMessageFrom:(
ShipEntity*)other;
62@interface StationEntity (OOAIPrivate)
64- (void)acceptDistressMessageFrom:(
ShipEntity*)other;
68@interface ShipEntity (PureAI)
72- (void)setStateTo:(NSString*)state;
74- (void)pauseAI:(NSString*)intervalString;
76- (void)randomPauseAI:(NSString*)intervalString;
78- (void)dropMessages:(NSString*)messageString;
84- (void)setDesiredRangeTo:(NSString*)rangeString;
88- (void)setSpeedTo:(NSString*)speedString;
90- (void)setSpeedFactorTo:(NSString*)speedString;
94- (void)setThrustFactorTo:(NSString*)thrustFactorString;
123- (void)exitAIWithMessage:(NSString*)message;
146- (void)commsMessage:(NSString*)valueString;
147- (void)commsMessageByUnpiloted:(NSString*)valueString;
168- (void)messageMother:(NSString*)msgString;
182- (void)sendTargetCommsMessage:(NSString*)message;
186- (void)markTargetForOffence:(NSString*)valueString;
197- (void)rollD:(NSString*)die_number;
199- (void)scanForNearestShipWithPrimaryRole:(NSString*)scanRole;
200- (void)scanForNearestShipHavingRole:(NSString*)scanRole;
201- (void)scanForNearestShipWithAnyPrimaryRole:(NSString*)scanRoles;
202- (void)scanForNearestShipHavingAnyRole:(NSString*)scanRoles;
203- (void)scanForNearestShipWithScanClass:(NSString*)scanScanClass;
205- (void)scanForNearestShipWithoutPrimaryRole:(NSString*)scanRole;
206- (void)scanForNearestShipNotHavingRole:(NSString*)scanRole;
207- (void)scanForNearestShipWithoutAnyPrimaryRole:(NSString*)scanRoles;
208- (void)scanForNearestShipNotHavingAnyRole:(NSString*)scanRoles;
209- (void)scanForNearestShipWithoutScanClass:(NSString*)scanScanClass;
211- (void)setCoordinates:(NSString*)system_x_y_z;
218- (void)addFuel:(NSString*)fuel_number;
220- (void)scriptActionOnTarget:(NSString*)action;
222- (void)sendScriptMessage:(NSString*)message;
228- (void)ai_debugMessage:(NSString*)message;
231- (void)targetFirstBeaconWithCode:(NSString*)code;
232- (void)targetNextBeaconWithCode:(NSString*)code;
243@implementation ShipEntity (AI)
245- (void)setAITo:(NSString*)aiString
248 if (![
PLAYER scriptsLoaded]) {
249 aiString =
@"oolite-nullAI.js";
251 if ([aiString hasSuffix:
@".plist"]) {
254 }
else if ([aiString hasSuffix:
@".js"]) {
268- (void)setAIScript:(NSString*)aiString
270 NSMutableDictionary* properties =
nil;
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]);
281 aiScriptWakeTime = 0;
282 haveStartedJSAI = NO;
287- (void)switchAITo:(NSString*)aiString
300 GLfloat found_d2 = scannerRange * scannerRange;
301 for (i = 0; i < n_scanned_ships; i++) {
303 GLfloat d2 = distance2_scanned_ships[
i];
305 && ([thing isThargoid] || (([thing primaryTarget] ==
self) && [thing hasHostileTarget]) || [thing isDefenseTarget:
self])
306 && ![thing isCloaked]) {
324 if ([
self group] ==
nil)
327 [
shipAI reactToMessage:@"GROUP_ATTACK_TARGET" context:@"groupAttackTarget"];
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];
337 if ([ship escortGroup] != [ship group] && [[ship escortGroup]
count] > 1)
340 NSArray* escortMembers = [[
ship escortGroup] memberArrayExcludingLeader];
341 foreach (escort, escortMembers) {
352 if (behaviour != BEHAVIOUR_EVASIVE_ACTION) {
353 behaviour = BEHAVIOUR_ATTACK_TARGET;
354 desired_range = 1250 *
randf() + 750;
361 behaviour = BEHAVIOUR_COLLECT_TARGET;
367 if (behaviour != BEHAVIOUR_FORMATION_FORM_UP) {
368 behaviour = BEHAVIOUR_FORMATION_FORM_UP;
375 behaviour = BEHAVIOUR_FACE_DESTINATION;
381 if (behaviour != BEHAVIOUR_FLEE_EVASIVE_ACTION) {
382 behaviour = BEHAVIOUR_FLEE_TARGET;
387 if ([
self approachAspectToPrimaryTarget] > 0.9995) {
388 behaviour =
randf() < 0.15 ? BEHAVIOUR_EVASIVE_ACTION : BEHAVIOUR_FLEE_EVASIVE_ACTION;
396 behaviour = BEHAVIOUR_FLY_RANGE_FROM_DESTINATION;
403 behaviour = BEHAVIOUR_TRACK_TARGET;
409 behaviour = BEHAVIOUR_IDLE;
415 behaviour = BEHAVIOUR_INTERCEPT_TARGET;
422 if (isNearPlanetSurface) {
423 _destination = [
nearest position];
424 behaviour = BEHAVIOUR_LAND_ON_PLANET;
425 planetForLanding = [
nearest universalID];
427 behaviour = BEHAVIOUR_IDLE;
428 [
shipAI message:@"NO_PLANET_NEARBY"];
438 if (target && [target scanClass] == CLASS_ROCK) {
439 behaviour = BEHAVIOUR_ATTACK_MINING_TARGET;
448 behaviour = BEHAVIOUR_SCRIPTED_AI;
454 behaviour = BEHAVIOUR_SCRIPTED_ATTACK_AI;
462 behaviour = BEHAVIOUR_TUMBLE;
468 behaviour = BEHAVIOUR_STOP_STILL;
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;
481- (BOOL)performHyperSpaceToSpecificSystem:(
OOSystemID)systemID
494 NSString* message =
nil;
495 double distanceToStation2 = 0.0;
498 if ([targStation isStation]) {
501 station = [UNIVERSE nearestShipMatchingPredicate:IsStationPredicate
503 relativeToEntity:
self];
506 distanceToStation2 =
HPdistance2([station position], [
self position]);
517 if (dockingInstructions !=
nil) {
531 if (dockingInstructions ==
nil) {
532 [
shipAI message:@"NO_STATION_FOUND"];
538 if (dockingInstructions !=
nil) {
540 desired_speed = fmin([dockingInstructions oo_floatForKey:
@"speed"], maxFlightSpeed);
542 if ([dockingInstructions objectForKey:
@"station"]) {
544 if (targetStation !=
nil) {
573 double found_d2 = scannerRange * scannerRange;
575 if (targEnt && (
HPdistance2(position, [targEnt position]) < found_d2)) {
576 if ([targEnt isWormhole])
578 else if ([targEnt isPlayer])
579 whole = [PLAYER wormhole];
584 int ent_count =
UNIVERSE->n_entities;
589 for (i = 0; i < ent_count; i++)
590 if (uni_entities[i]->isWormhole)
594 for (i = 0; i < wh_count; i++) {
612 NSString* context =
nil;
616 if (![whole isWormhole])
620 context = [
NSString stringWithFormat:@"%@ wormholeEscorts", [
self shortDescription]];
623 foreach (ship, [
self escortEnumerator]) {
644#ifdef OO_DEBUG_MONITOR_ENABLED
645 if (reportAIMessages) {
646 OOLog(
@"ai.suggestEscort",
@"DEBUG: %@ suggests escorting %@",
self, mother);
650 if ([mother acceptAsEscort:
self]) {
652 if (([mother legalStatus] > 0) && (bounty <= 0)) {
661 [
shipAI message:@"ESCORTING"];
665#ifdef OO_DEBUG_MONITOR_ENABLED
666 if (reportAIMessages) {
667 OOLog(
@"ai.suggestEscort.refused",
@"DEBUG: %@ refused by %@",
self, mother);
672 [
shipAI message:@"NOT_ESCORTING"];
683- (void)broadcastDistressMessageWithDumping:(BOOL)dumpCargo
689 if (aggressor_ship ==
nil)
693 if (messageTime > 2.0 *
randf())
696 NSString* distress_message =
nil;
697 BOOL is_buoy = (scanClass == CLASS_BUOY);
699 distress_message =
@"[buoy-distress-call]";
701 distress_message =
@"[distress-call]";
704 for (i = 0; i < n_scanned_ships; i++) {
708 if (dumpCargo && !is_buoy && [
self primaryAggressor] == ship && energy < 0.375 * maxEnergy) {
715 if (ship->
isPlayer && ![
self hasNewAI]) {
718 if (!is_buoy && [
self primaryAggressor] == ship && energy < 0.375 * maxEnergy) {
720 }
else if ([
self bounty] == 0) {
728 }
else if ([
self bounty] == 0 && [ship crew])
738 if (![
self hasNewAI]) {
740 if (ship->
isStation || [ship hasPrimaryRole:
@"police"] || [ship hasPrimaryRole:
@"hunter"]) {
750@implementation ShipEntity (PureAI)
752- (void)setStateTo:(NSString*)state
757- (void)pauseAI:(NSString*)intervalString
762- (void)randomPauseAI:(NSString*)intervalString
767 if ([tokens
count] != 2) {
768 OOLog(
@"ai.syntax.randomPauseAI",
@"***** ERROR: cannot read min and max value for randomPauseAI:, needs 2 values: '%@'.", intervalString);
772 start = [
tokens oo_doubleAtIndex:0];
773 end = [
tokens oo_doubleAtIndex:1];
775 [
shipAI setNextThinkTime:[UNIVERSE getTime] + (start + (end - start) * randf())];
778- (void)dropMessages:(NSString*)messageString
780 NSArray* messages =
nil;
781 NSString* message =
nil;
782 NSCharacterSet* whiteSpace = [
NSCharacterSet whitespaceCharacterSet];
785 foreach (message, messages) {
786 [
shipAI dropMessage:[
message stringByTrimmingCharactersInSet:whiteSpace]];
792 [
shipAI debugDumpPendingMessages];
808- (void)setDesiredRangeTo:(NSString*)rangeString
815 desired_range = fmax(maxFlightSpeed / max_flight_pitch / 6, 50.0);
818- (void)setSpeedTo:(NSString*)speedString
823- (void)setSpeedFactorTo:(NSString*)speedString
825 desired_speed = maxFlightSpeed * [
speedString doubleValue];
830 desired_speed = cruiseSpeed;
833- (void)setThrustFactorTo:(NSString*)thrustFactorString
835 thrust =
OOClamp_0_1_f([thrustFactorString doubleValue]) * max_thrust;
843 if ([
self primaryTarget] == primeAggressor)
849 if ([
self hasHostileTarget] &&
randf() < 0.75)
856 if ([primeAggressor isShip] && ![(
ShipEntity*)primeAggressor isFriendlyTo:
self]) {
860 if ((primeTarget) && (primeTarget->
isShip)) {
876 if ([
self isDefenseTarget:primeAggressor])
879 if ([primeAggressor isShip] && ![(
ShipEntity*)primeAggressor isFriendlyTo:
self]) {
893 found_d2 = scannerRange * scannerRange;
896 for (i = 0; i < n_scanned_ships; i++) {
897 ship = scanned_ships[
i];
898 if ([ship isPirateVictim] && ([ship status] != STATUS_DEAD) && ([ship status] != STATUS_DOCKED) && ![ship isCloaked]) {
899 d2 = distance2_scanned_ships[
i];
903 d2 = distance2_scanned_ships[
i];
923 for (i = 0; i < n_scanned_ships; i++) {
925 if (([ship status] != STATUS_DEAD) && ([ship status] != STATUS_DOCKED) && [ship isPirateVictim] && ![ship isCloaked])
929 [
shipAI message:@"NOTHING_FOUND"];
933 [
shipAI message:@"TARGET_FOUND"];
941 if (![
self hasCargoScoop]) {
942 [
shipAI message:@"NOTHING_FOUND"];
945 if ([cargo
count] >= [
self maxAvailableCargoSpace]) {
947 [
shipAI message:@"HOLD_FULL"];
948 [
shipAI message:@"NOTHING_FOUND"];
953 [
shipAI message:@"NOTHING_FOUND"];
960 double found_d2 = scannerRange * scannerRange;
963 for (i = 0; i < n_scanned_ships; i++) {
965 if ([other scanClass] == CLASS_CARGO && [other cargoType] !=
CARGO_NOT_CARGO && [other status] != STATUS_BEING_SCOOPED) {
966 if ((![
self isPolice]) || ([[other commodityType] isEqualToString:
@"slaves"]))
968 GLfloat d2 = distance2_scanned_ships[
i];
982 if (![
self isStation] && ![
self hasCargoScoop]) {
983 [
shipAI message:@"NOTHING_FOUND"];
990 unsigned things_found = 0;
993 for (i = 0; (i < n_scanned_ships) && (things_found < 16); i++) {
995 if ([other scanClass] == CLASS_CARGO && [other cargoType] !=
CARGO_NOT_CARGO && [other status] != STATUS_BEING_SCOOPED) {
1000 if (things_found != 0) {
1001 [
self setFoundTarget:thing_uids_found[ranrot_rand() % things_found]];
1002 [
shipAI message:@"TARGET_FOUND"];
1004 [
shipAI message:@"NOTHING_FOUND"];
1009 if ([
self foundTarget] !=
nil) {
1012 [
shipAI message:@"TARGET_LOST"];
1019 if (fTarget !=
nil) {
1020 if ([fTarget isShip] && ![(
ShipEntity*)fTarget isFriendlyTo:
self]) {
1029 [
shipAI message:@"NO_CARGO_BAY"];
1030 }
else if ([cargo
count] >= [
self maxAvailableCargoSpace]) {
1031 [
shipAI message:@"HOLD_FULL"];
1033 [
shipAI message:@"HOLD_NOT_FULL"];
1051 station = [UNIVERSE nearestShipMatchingPredicate:IsStationPredicate
1053 relativeToEntity:
self];
1067 _destination = coordinates;
1072 coordinates = position;
1085 for (i = 0; (i < n_scanned_ships) && (missile ==
nil); i++) {
1087 if (thing->
scanClass == CLASS_MISSILE) {
1090 if (target ==
self) {
1093 foreach (escort, [
self escortEnumerator]) {
1094 if (target == escort) {
1113 if ([
self isPolice]) {
1118 foreach (police, [[
self group] mutationSafeEnumerator]) {
1125 if ([
self isPolice] && ![hunter isPolice])
1128 if ([
self hasECM]) {
1139 desired_range = 10000;
1141 [
shipAI message:@"FLEEING"];
1149 double variation = (aegis_status ==
AEGIS_NONE ? 0.5 : 0.2);
1150 HPVector p_pos = the_planet->position;
1151 double p_cr = the_planet->collision_radius;
1154 p1.
x += variation * (
randf() - variation);
1155 p1.
y += variation * (
randf() - variation);
1156 p1.
z += variation * (
randf() - variation);
1159 desired_range = collision_radius + 100.0;
1161 [
shipAI message:@"NO_PLANET_FOUND"];
1171 desired_range = 50.0;
1173 OOLog(
@"ai.setTakeOffFromPlanet.noPlanet",
@"%@",
@"***** Error. Planet not found during take off!");
1187 [
shipAI message:@"NO_TARGET"];
1192 [
shipAI message:@"TARGET_FUGITIVE"];
1196 [
shipAI message:@"TARGET_OFFENDER"];
1200 [
shipAI message:@"TARGET_MINOR_OFFENDER"];
1203 [
shipAI message:@"TARGET_CLEAN"];
1209 if (scanClass == CLASS_THARGOID) {
1210 [
shipAI message:@"SELF_THARGOID"];
1215 [
shipAI message:@"SELF_FUGITIVE"];
1219 [
shipAI message:@"SELF_OFFENDER"];
1223 [
shipAI message:@"SELF_MINOR_OFFENDER"];
1226 [
shipAI message:@"SELF_CLEAN"];
1229- (void)exitAIWithMessage:(NSString*)message
1231 if ([message length] == 0)
1232 message =
@"RESTARTED";
1233 [
shipAI exitStateMachineWithMessage:message];
1240 _destination = the_target->
position;
1258 Entity* hazard = [UNIVERSE hazardOnRouteFromEntity:
self toDistance:desired_range fromPoint:_destination];
1260 if (hazard ==
nil || ([hazard isShip] &&
HPdistance(position, [hazard position]) > scannerRange) || ([hazard isPlanet] && aegis_status ==
AEGIS_NONE))
1261 [
shipAI message:@"COURSE_OK"];
1263 if ([hazard isShip] && (weapon_damage * 24.0 > [hazard energy])) {
1264 [
shipAI reactToMessage:@"HAZARD_CAN_BE_DESTROYED" context:@"checkCourseToDestination"];
1267 _destination = [UNIVERSE getSafeVectorFromEntity:
self toDistance:desired_range fromPoint:_destination];
1268 [
shipAI message:@"WAYPOINT_SET"];
1274 switch (aegis_status) {
1276 [
shipAI message:@"AEGIS_CLOSE_TO_MAIN_PLANET"];
1283 if ([nearest isSun]) {
1284 [
shipAI message:@"CLOSE_TO_SUN"];
1286 [
shipAI message:@"CLOSE_TO_PLANET"];
1288 [
shipAI message:@"CLOSE_TO_MOON"];
1290 [
shipAI message:@"CLOSE_TO_SECONDARY_PLANET"];
1296 [
shipAI message:@"AEGIS_IN_DOCKING_RANGE"];
1299 [
shipAI message:@"AEGIS_NONE"];
1303 NSLog(
@"Aegis status for %@ has taken on invalid value %i. This is an internal error, please report it.",
self, aegis_status);
1305 [
shipAI message:@"AEGIS_NONE"];
1310 if (energy == maxEnergy) {
1311 [
shipAI message:@"ENERGY_FULL"];
1314 if (energy >= maxEnergy * 0.75) {
1315 [
shipAI message:@"ENERGY_HIGH"];
1318 if (energy <= maxEnergy * 0.25) {
1319 [
shipAI message:@"ENERGY_LOW"];
1322 [
shipAI message:@"ENERGY_MEDIUM"];
1329 if ([
self heatInsulation] < minInsulation) {
1330 [
shipAI message:@"INSULATION_POOR"];
1333 [
shipAI message:@"INSULATION_OK"];
1340 for (i = 0; i < n_scanned_ships; i++) {
1342 if (![ship isCloaked] && (([ship primaryTarget] ==
self && [ship hasHostileTarget]) || [ship isMine] || ([ship isThargoid] != [
self isThargoid]))) {
1343 if (![
self isDefenseTarget:ship]) {
1354 NSDictionary* systeminfo = [UNIVERSE currentSystemData];
1355 float gov_factor = 0.4 * [(
NSNumber*)[
systeminfo objectForKey:KEY_GOVERNMENT] intValue];
1366 float worst_legal_factor = 0;
1367 GLfloat found_d2 = scannerRange * scannerRange;
1369 for (i = 0; i < n_scanned_ships; i++) {
1371 if ((ship->
scanClass != CLASS_CARGO) && ([ship status] != STATUS_DEAD) && ([ship status] != STATUS_DOCKED) && ![ship isCloaked]) {
1372 GLfloat d2 = distance2_scanned_ships[
i];
1375 if ((d2 < found_d2) && (random_factor < legal_factor) && (legal_factor > worst_legal_factor)) {
1376 if (group ==
nil || group != [ship group])
1379 worst_legal_factor = legal_factor;
1391 _destination = [UNIVERSE getWitchspaceExitPosition];
1392 desired_range = 10000.0;
1398 _destination = [UNIVERSE getWitchspaceExitPosition];
1404 _destination = [[UNIVERSE station] beaconPosition];
1420 OOLogERR(
@"ai.invalid.notPlayer",
@"Error in %@:%@, AI method endAutoPilot is only applicable to the player.", [shipAI name], [shipAI state]);
1429 if (![whole isWormhole])
1432 foreach (ship, [[
self group] mutationSafeEnumerator]) {
1439- (void)commsMessage:(NSString*)valueString
1444- (void)commsMessageByUnpiloted:(NSString*)valueString
1452 while (cargo_to_go > 15) {
1456 for (i = 1; i < cargo_to_go; i++) {
1457 [
self performSelector:@selector(dumpCargo) withObject:nil afterDelay:0.75 * i];
1473 GLfloat found_d2 = scannerRange * scannerRange;
1474 for (i = 0; i < n_scanned_ships; i++) {
1476 GLfloat d2 = distance2_scanned_ships[
i];
1477 if (([thing scanClass] != CLASS_CARGO) && ([thing status] != STATUS_DOCKED) && ![thing isThargoid] && ![thing isCloaked] && (d2 < found_d2)) {
1479 if ([thing isPlayer])
1491 if (mother ==
nil && [
self group])
1494 double maxRange2 = scannerRange * scannerRange;
1497 [
shipAI message:@"TARGET_FOUND"];
1501 if ([
self foundTarget] !=
nil) {
1504 if ([mother group] != [mother escortGroup])
1514 int ent_count =
UNIVERSE->n_entities;
1517 for (i = 0; i < ent_count; i++)
1518 if (uni_entities[i]->isShip) {
1520 if ([other primaryTarget] ==
self) {
1523 if ([other isDefenseTarget:
self]) {
1528 scanClass = CLASS_CARGO;
1529 reportAIMessages = NO;
1530 [
self setAITo:@"dumbAI.plist"];
1538 if (distanceTravelled > desired_range)
1539 [
shipAI message:@"GONE_BEYOND_RANGE"];
1546 if ([
self hasEscorts]) {
1548 if (leTarget !=
nil) {
1550 [
shipAI message:@"FLEEING"];
1557 [
shipAI message:@"DEPLOYING_ESCORTS"];
1558 [
shipAI message:@"FLEEING"];
1565 if (
randf() < 0.50) {
1569 [
shipAI message:@"FLEEING"];
1575 if (energy > maxEnergy * 0.80) {
1578 [
shipAI message:@"FIGHTING"];
1582 [
shipAI message:@"FLEEING"];
1595 if ([mother acceptAsEscort:
self]) {
1598 [
shipAI message:@"ESCORTING"];
1601 if ([
self group] == [mother escortGroup])
1603 [
shipAI message:@"NOT_ESCORTING"];
1612 if (ownGroupCount == targetGroupCount) {
1613 [
shipAI message:@"ODDS_LEVEL"];
1614 }
else if (ownGroupCount > targetGroupCount) {
1615 [
shipAI message:@"ODDS_GOOD"];
1617 [
shipAI message:@"ODDS_BAD"];
1627 GLfloat found_d2 = scannerRange * scannerRange;
1628 for (i = 0; i < n_scanned_ships; i++) {
1630 if ((ship !=
self) && (!ship->
isPlayer) && (ship->
scanClass == scanClass) && [ship primaryTarget] !=
self && ![ship isCloaked])
1632 GLfloat d2 = distance2_scanned_ships[
i];
1633 if ((d2 < found_d2) && [ship canAcceptEscort:
self]) {
1640 if ([
self foundTarget] !=
nil)
1641 [
shipAI message:@"TARGET_FOUND"];
1643 [
shipAI message:@"NOTHING_FOUND"];
1644 if ([
self hasPrimaryRole:
@"wingman"]) {
1646 [
self setAITo:@"route1patrolAI.plist"];
1652- (void)messageMother:(NSString*)msgString
1655 if (mother !=
nil && mother !=
self) {
1656 NSString* context =
nil;
1658 context = [
NSString stringWithFormat:@"%@ messageMother", [
self shortDescription]];
1665- (void)messageSelf:(NSString*)msgString
1674 if (
HPmagnitude2(r_pos) < 1000000 || patrol_counter == 0) {
1675 Entity* the_sun = [UNIVERSE sun];
1677 if (!the_station || ![the_station isStation])
1678 the_station = [UNIVERSE station];
1679 if ((!the_sun) || (!the_station))
1685 if (sun_dir.
x || sun_dir.
y || sun_dir.
z)
1690 switch (patrol_counter) {
1692 coordinates =
make_HPvector(stn_pos.
x + 5000 * v0.
x, stn_pos.
y + 5000 * v0.
y, stn_pos.
z + 5000 * v0.
z);
1693 desired_range = 250.0;
1696 coordinates =
make_HPvector(stn_pos.
x + 25000 * v1.
x, stn_pos.
y + 25000 * v1.
y, stn_pos.
z + 25000 * v1.
z);
1697 desired_range = 250.0;
1700 coordinates =
make_HPvector(stn_pos.
x + 25000 * v2.
x, stn_pos.
y + 25000 * v2.
y, stn_pos.
z + 25000 * v2.
z);
1701 desired_range = 250.0;
1704 coordinates =
make_HPvector(stn_pos.
x - 25000 * v1.
x, stn_pos.
y - 25000 * v1.
y, stn_pos.
z - 25000 * v1.
z);
1705 desired_range = 250.0;
1708 coordinates =
make_HPvector(stn_pos.
x - 25000 * v2.
x, stn_pos.
y - 25000 * v2.
y, stn_pos.
z - 25000 * v2.
z);
1709 desired_range = 250.0;
1712 coordinates =
make_HPvector(stn_pos.
x + 5000 * v0.
x, stn_pos.
y + 5000 * v0.
y, stn_pos.
z + 5000 * v0.
z);
1713 desired_range = 250.0;
1717 if (patrol_counter > 4) {
1718 if (
randf() < .25) {
1721 [
self setAITo:@"dockingAI.plist"];
1729 [
shipAI message:@"APPROACH_COORDINATES"];
1735 [
shipAI message:@"NO_SUN_FOUND"];
1739 HPVector v0 = [UNIVERSE getSunSkimStartPositionForShip:
self];
1743 [
shipAI message:@"APPROACH_COORDINATES"];
1745 [
shipAI message:@"WAIT_FOR_SUN"];
1752 [
shipAI message:@"NO_SUN_FOUND"];
1756 coordinates = [UNIVERSE getSunSkimEndPositionForShip:
self];
1757 [
shipAI message:@"APPROACH_COORDINATES"];
1762 Entity* the_sun = [UNIVERSE sun];
1765 HPVector v1 = [UNIVERSE getSunSkimEndPositionForShip:
self];
1768 if (vout.
x || vout.
y || vout.
z)
1772 v1.
x += 10000 * vout.
x;
1773 v1.
y += 10000 * vout.
y;
1774 v1.
z += 10000 * vout.
z;
1776 [
shipAI message:@"APPROACH_COORDINATES"];
1783 if (!the_station || ![the_station isStation])
1784 the_station = [UNIVERSE station];
1791 if ((!motherStation) || (!(motherStation->
isStation))) {
1792 [
shipAI message:@"NOTHING_FOUND"];
1795 double found_d2 = scannerRange * scannerRange;
1798 [
shipAI message:@"NOTHING_FOUND"];
1801 [
shipAI message:@"STATION_FOUND"];
1804- (void)sendTargetCommsMessage:(NSString*)message
1807 if ((ship ==
nil) || ([ship status] == STATUS_DEAD) || ([ship status] == STATUS_DOCKED)) {
1817 if ((ship ==
nil) || ([ship status] == STATUS_DEAD) || ([ship status] == STATUS_DOCKED)) {
1821 if ([ship markForFines])
1822 [
shipAI message:@"TARGET_MARKED"];
1825- (void)markTargetForOffence:(NSString*)valueString
1827 if ((isStation) || (scanClass == CLASS_POLICE)) {
1829 if ((ship ==
nil) || ([ship status] == STATUS_DEAD) || ([ship status] == STATUS_DOCKED)) {
1833 NSString* finalValue =
OOExpand(valueString);
1854 if (oldTarget && ![oldTarget isCloaked]) {
1855 GLfloat range2 =
HPdistance2([oldTarget position], position);
1863 [
shipAI message:@"TARGET_FOUND"];
1865 if (oldTarget ==
nil)
1867 [
shipAI message:@"NOTHING_FOUND"];
1880 GLfloat found_d2 = scannerRange * scannerRange;
1881 for (i = 0; i < n_scanned_ships; i++) {
1883 if ([thing isBoulder]) {
1884 GLfloat d2 = distance2_scanned_ships[
i];
1885 if (d2 < found_d2) {
1891 if ([
self foundTarget] ==
nil) {
1892 for (i = 0; i < n_scanned_ships; i++) {
1894 if ([thing hasRole:
@"asteroid"]) {
1895 GLfloat d2 = distance2_scanned_ships[
i];
1896 if (d2 < found_d2) {
1913 the_target = [UNIVERSE station];
1915 double bo_distance = 8000;
1918 v0.
x += (
randf() - 0.5) * collision_radius;
1919 v0.
y += (
randf() - 0.5) * collision_radius;
1920 v0.
z += (
randf() - 0.5) * collision_radius;
1926 v0.
x *= bo_distance;
1927 v0.
y *= bo_distance;
1928 v0.
z *= bo_distance;
1939 if (mother ==
nil) {
1940 [
shipAI message:@"MOTHER_LOST"];
1948 GLfloat found_d2 = scannerRange * scannerRange;
1950 for (i = 0; i < n_scanned_ships; i++) {
1952 GLfloat d2 = distance2_scanned_ships[
i];
1954 if ((d2 < found_d2) && ![thing isCloaked] && (([thing isThargoid] && ![mother isThargoid]) || (([thing primaryTarget] == mother) && [thing hasHostileTarget]))) {
1965- (void)rollD:(NSString*)die_number
1968 if (die_sides > 0) {
1970 NSString* result = [
NSString stringWithFormat:@"ROLL_%d", die_roll];
1971 [
shipAI reactToMessage:result context:@"rollD:"];
1973 OOLog(
@"ai.rollD.invalidValue",
@"***** ERROR: invalid value supplied to rollD: '%@'.", die_number);
1977- (void)scanForNearestShipWithPrimaryRole:(NSString*)scanRole
1982- (void)scanForNearestShipHavingRole:(NSString*)scanRole
1987- (void)scanForNearestShipWithAnyPrimaryRole:(NSString*)scanRoles
1989 NSSet*
set = [
NSSet setWithArray:ScanTokensFromString(scanRoles)];
1993- (void)scanForNearestShipHavingAnyRole:(NSString*)scanRoles
1995 NSSet*
set = [
NSSet setWithArray:ScanTokensFromString(scanRoles)];
1999- (void)scanForNearestShipWithScanClass:(NSString*)scanScanClass
2001 NSNumber* parameter = [
NSNumber numberWithInt:OOScanClassFromString(scanScanClass)];
2005- (void)scanForNearestShipWithoutPrimaryRole:(NSString*)scanRole
2010- (void)scanForNearestShipNotHavingRole:(NSString*)scanRole
2015- (void)scanForNearestShipWithoutAnyPrimaryRole:(NSString*)scanRoles
2017 NSSet*
set = [
NSSet setWithArray:ScanTokensFromString(scanRoles)];
2021- (void)scanForNearestShipNotHavingAnyRole:(NSString*)scanRoles
2023 NSSet*
set = [
NSSet setWithArray:ScanTokensFromString(scanRoles)];
2027- (void)scanForNearestShipWithoutScanClass:(NSString*)scanScanClass
2029 NSNumber* parameter = [
NSNumber numberWithInt:OOScanClassFromString(scanScanClass)];
2033- (void)scanForNearestShipMatchingPredicate:(NSString*)predicateExpression
2050 static NSMutableDictionary* scriptCache =
nil;
2051 NSString* aiName =
nil;
2052 NSString* key =
nil;
2054 JSContext* context = NULL;
2058 if (predicateExpression ==
nil)
2059 predicateExpression =
@"false";
2068 key = [
NSString stringWithFormat:@"%@\n%@", aiName, predicateExpression];
2070 key = predicateExpression;
2075 if (
function ==
nil) {
2076 NSString* predicateCode =
nil;
2077 const char* argNames[] = {
"ship" };
2080 predicateCode = [
NSString stringWithFormat:@"return %@;", predicateExpression];
2081 function = [[
OOJSFunction alloc] initWithName:@"_oo_AIScanPredicate"
2089 argumentNames:argNames
2096 if (
function !=
nil) {
2097 if (scriptCache ==
nil)
2103 if (
function !=
nil) {
2112 JS_FreeValue(context, jsThis);
2116 .function = [
function functionValue],
2123 static NSMutableSet* errorCache =
nil;
2125 if (![errorCache containsObject:key]) {
2126 OOLog(
@"ai.scanForNearestShipMatchingPredicate.compile.failed",
@"Could not compile JavaScript predicate \"%@\
" for AI %@.", predicateExpression, [[
self getAI] name]);
2127 if (errorCache ==
nil)
2141- (void)setCoordinates:(NSString*)system_x_y_z
2144 NSString* systemString =
nil;
2145 NSString* xString =
nil;
2146 NSString* yString =
nil;
2147 NSString* zString =
nil;
2149 if ([tokens
count] != 4) {
2150 OOLog(
@"ai.syntax.setCoordinates",
@"***** ERROR: cannot setCoordinates: '%@'.", system_x_y_z);
2154 systemString = (NSString*)[tokens objectAtIndex:0];
2155 xString = (NSString*)[tokens objectAtIndex:1];
2156 if ([xString hasPrefix:
@"rand:"])
2157 xString = [
NSString stringWithFormat:@"%.3f", bellf([(
NSString*)[[
xString componentsSeparatedByString:@":"] objectAtIndex:1] intValue])];
2158 yString = (NSString*)[tokens objectAtIndex:2];
2159 if ([yString hasPrefix:
@"rand:"])
2160 yString = [
NSString stringWithFormat:@"%.3f", bellf([(
NSString*)[[
yString componentsSeparatedByString:@":"] objectAtIndex:1] intValue])];
2161 zString = (NSString*)[tokens objectAtIndex:3];
2162 if ([zString hasPrefix:
@"rand:"])
2163 zString = [
NSString stringWithFormat:@"%.3f", bellf([(
NSString*)[[
zString componentsSeparatedByString:@":"] objectAtIndex:1] intValue])];
2166 GLfloat scalar = 1.0;
2168 coordinates = [UNIVERSE coordinatesForPosition:posn withCoordinateSystem:systemString returningScalar:&scalar];
2170 [
shipAI message:@"APPROACH_COORDINATES"];
2176 [
shipAI message:@"NORMAL_SPACE"];
2178 [
shipAI message:@"INTERSTELLAR_SPACE"];
2184 int ent_count =
UNIVERSE->n_entities;
2188 double maxRange2 = desired_range * desired_range;
2190 int station_count = 0;
2192 for (i = 0; i < ent_count; i++) {
2194 if (uni_entities[i]->isStation) {
2196 if ([my_station maxFlightSpeed] == 0 && [my_station hasNPCTraffic] &&
HPdistance2(position, [my_station position]) < maxRange2) {
2202 if (station_count != 0) {
2206 if (station == [
UNIVERSE station] && station_count > 1) {
2207 while (station == [
UNIVERSE station]) {
2213 for (i = 0; i < station_count; i++)
2214 [my_entities[i] release];
2219 [
shipAI message:@"STATION_FOUND"];
2221 [
shipAI message:@"NO_STATION_IN_RANGE"];
2229 if (station !=
nil && [station isStation]) {
2232 [
shipAI message:@"NO_STATION_FOUND"];
2237- (void)addFuel:(NSString*)fuel_number
2242- (void)scriptActionOnTarget:(NSString*)action
2249 static BOOL deprecationWarning = NO;
2251 if (!deprecationWarning) {
2252 deprecationWarning = YES;
2253 OOLog(
@"script.deprecated.scriptActionOnTarget",
@"----- WARNING in AI %@: the AI method scriptActionOnTarget: is deprecated and should not be used. It is slow and has unpredictable side effects. The recommended alternative is to use sendScriptMessage: to call a function in a ship's JavaScript ship script instead. scriptActionOnTarget: should not be used at all from scripts. An alternative is safeScriptActionOnTarget:, which is similar to scriptActionOnTarget: but has less side effects.", [
AI currentlyRunningAIDescription]);
2255 OOLog(
@"script.deprecated.scriptActionOnTarget.repeat",
@"----- WARNING in AI %@: the AI method scriptActionOnTarget: is deprecated and should not be used.", [
AI currentlyRunningAIDescription]);
2259 if ([targEnt isShip]) {
2271- (void)safeScriptActionOnTarget:(NSString*)action
2277 if ([targEnt isShip]) {
2289- (void)sendScriptMessage:(NSString*)message
2293 if ([components
count] == 1) {
2296 NSString*
function = [
components objectAtIndex:0];
2312- (void)ai_debugMessage:(NSString*)message
2315 if ([
self isPlayer])
2316 desc =
@"player autopilot";
2317 OOLog(
@"ai.takeAction.debugMessage",
@"DEBUG: AI MESSAGE from %@: %@", desc, message);
2321- (void)targetFirstBeaconWithCode:(NSString*)code
2323 NSArray* all_beacons = [UNIVERSE listBeaconsWithCode:code];
2324 if ([all_beacons
count]) {
2326 [
shipAI message:@"TARGET_FOUND"];
2328 [
shipAI message:@"NOTHING_FOUND"];
2331- (void)targetNextBeaconWithCode:(NSString*)code
2333 NSArray* all_beacons = [UNIVERSE listBeaconsWithCode:code];
2336 if ((!current_beacon) || (![current_beacon isBeacon])) {
2337 [
shipAI message:@"NO_CURRENT_BEACON"];
2338 [
shipAI message:@"NOTHING_FOUND"];
2343 NSUInteger i = [
all_beacons indexOfObject:current_beacon];
2345 if (i == NSNotFound) {
2346 [
shipAI message:@"NOTHING_FOUND"];
2352 if (i < [all_beacons
count]) {
2355 [
shipAI message:@"TARGET_FOUND"];
2357 [
shipAI message:@"LAST_BEACON"];
2358 [
shipAI message:@"NOTHING_FOUND"];
2367 [
shipAI message:@"NOTHING_FOUND"];
2375 navpoints[2] =
make_HPvector(o.
x + 2.0 * c * k.
x, o.
y + 2.0 * c * k.
y, o.
z + 2.0 * c * k.
z);
2376 number_of_navpoints = 2;
2377 next_navpoint_index = 0;
2378 _destination = navpoints[0];
2379 [
shipAI message:@"RACEPOINTS_SET"];
2384 next_navpoint_index = 0;
2385 desired_range = collision_radius;
2386 behaviour = BEHAVIOUR_FLY_THRU_NAVPOINTS;
2391@implementation ShipEntity (OOAIPrivate)
2395 if ([
self foundTarget] !=
nil) {
2396 [
shipAI message:@"TARGET_FOUND"];
2398 [
shipAI message:@"NOTHING_FOUND"];
2402- (BOOL)performHyperSpaceExitReplace:(BOOL)replace
2407- (BOOL)performHyperSpaceExitReplace:(BOOL)replace toSystem:(
OOSystemID)systemID
2409 if (![
self hasHyperspaceMotor]) {
2410 [
shipAI reactToMessage:@"WITCHSPACE UNAVAILABLE" context:@"performHyperSpaceExit"];
2413 if ([
self status] == STATUS_ENTERING_WITCHSPACE) {
2418 NSArray* sDests =
nil;
2423 sDests = [UNIVERSE nearbyDestinationsWithinRange:0.1f * fuel];
2424 NSUInteger n_dests = [
sDests count];
2428 [
shipAI reactToMessage:@"WITCHSPACE UNAVAILABLE" context:@"performHyperSpaceExit"];
2439 [
shipAI reactToMessage:@"WITCHSPACE BLOCKED" context:@"performHyperSpaceExit"];
2445 if (systemID == -1) {
2451 targetSystem = [[
sDests oo_dictionaryAtIndex:i] oo_intForKey:@"sysID"];
2453 targetSystem = systemID;
2455 for (i = 0; i < n_dests; i++) {
2456 if (systemID == [[sDests oo_dictionaryAtIndex:i] oo_intForKey:
@"sysID"])
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);
2473 [UNIVERSE addEntity:whole];
2486 float d2, found_d2 = scannerRange * scannerRange;
2491 if (predicate == NULL)
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]) {
2516 if ([
self isPolice]) {
2520 NSString* context =
nil;
2522 context = [
NSString stringWithFormat:@"%@ broadcastDistressMessage", [
other shortDescription]];
2524 [
shipAI reactToMessage:@"ACCEPT_DISTRESS_CALL"
2530@implementation StationEntity (OOAIPrivate)
2541 _primaryTarget = old_target;
2546@implementation ShipEntity (OOAIStationStubs)
2550#define STATION_STUB_BASE(PROTO, NAME) \
2551 PROTO { OOLog(@"ai.invalid.notAStation", @"Attempt to use station AI method \"%s\" on non-station %@.", NAME, self); }
2552#define STATION_STUB_NOARG(NAME) STATION_STUB_BASE(-(void)NAME, #NAME)
2553#define STATION_STUB_ARG(NAME) STATION_STUB_BASE(-(void)NAME(NSString*) param, #NAME)
2567 OOLog(
@"ai.invalid.notAStation",
@"Attempt to use station AI method \"%s\
" on non-station %@.",
"launchPatrol",
self);
#define SCANNER_MAX_RANGE2
BOOL HasScanClassPredicate(Entity *entity, void *parameter)
BOOL IsHostileAgainstTargetPredicate(Entity *ship, void *parameter)
OOINLINE float OOClamp_0_1_f(float value) INLINE_CONST_FUNC
OOINLINE HPVector vectorToHPVector(Vector v) INLINE_CONST_FUNC
OOINLINE HPVector HPvector_subtract(HPVector a, HPVector b) INLINE_CONST_FUNC
OOINLINE HPVector HPvector_multiply_scalar(HPVector v, OOHPScalar s) INLINE_CONST_FUNC
const HPVector kZeroHPVector
OOINLINE bool HPvector_equal(HPVector a, HPVector b) INLINE_CONST_FUNC
OOINLINE HPVector HPvector_normal_or_fallback(HPVector vec, HPVector fallback) INLINE_CONST_FUNC
OOINLINE Vector HPVectorToVector(HPVector v) INLINE_CONST_FUNC
OOINLINE HPVector make_HPvector(OOHPScalar vx, OOHPScalar vy, OOHPScalar vz) INLINE_CONST_FUNC
OOINLINE OOHPScalar HPdistance2(HPVector v1, HPVector v2) INLINE_CONST_FUNC
OOINLINE HPVector HPvector_normal(HPVector vec) INLINE_CONST_FUNC
OOINLINE HPVector HPvector_add(HPVector a, HPVector b) INLINE_CONST_FUNC
HPVector OOHPVectorRandomSpatial(OOHPScalar maxLength)
#define HPvector_between(a, b)
OOINLINE OOHPScalar HPmagnitude2(HPVector vec) INLINE_CONST_FUNC
OOINLINE OOHPScalar HPdistance(HPVector v1, HPVector v2) INLINE_CONST_FUNC
JSObject * OOJSObjectFromNativeObject(JSContext *context, id object)
OOINLINE JSContext * OOJSAcquireContext(void)
OOINLINE void OOJSReportPendingException(JSContext *context)
OOINLINE void OOJSRelinquishContext(JSContext *context)
#define OOLogWARN(class, format,...)
#define OOLogERR(class, format,...)
#define NSLog(format,...)
#define OOLog(class, format,...)
Vector vector_forward_from_quaternion(Quaternion quat) CONST_FUNC
void quaternion_set_random(Quaternion *quat) NONNULL_FUNC
#define OOExpand(string,...)
NSMutableArray * ScanTokensFromString(NSString *values)
@ AEGIS_CLOSE_TO_MAIN_PLANET
@ AEGIS_CLOSE_TO_ANY_PLANET
OOINLINE Vector vector_add(Vector a, Vector b) INLINE_CONST_FUNC
OOINLINE Vector make_vector(OOScalar vx, OOScalar vy, OOScalar vz) INLINE_CONST_FUNC
OOINLINE Vector cross_product(Vector first, Vector second) INLINE_CONST_FUNC
OOINLINE OOScalar magnitude2(Vector vec) INLINE_CONST_FUNC
Vector OOVectorRandomSpatial(OOScalar maxLength)
OOINLINE Vector vector_multiply_scalar(Vector v, OOScalar s) INLINE_CONST_FUNC
#define STATION_STUB_NOARG(NAME)
#define STATION_STUB_ARG(NAME)
#define COMBAT_AI_ISNT_AWFUL
#define PIRATES_PREFER_PLAYER
BOOL(* EntityFilterPredicate)(Entity *entity, void *parameter)
void broadcastDistressMessage()
void performFlyToRangeFromDestination()
void scanForNearestIncomingMissile()
void enterPlayerWormhole()
void performFaceDestination()
void enterTargetWormhole()
void performScriptedAttackAI()
void performLandOnPlanet()
void recallDockingInstructions()
void requestDockingCoordinates()
void wormholeEntireGroup()
void setSpeedToCruiseSpeed()
void setCourseToWitchpoint()
void checkHeatInsulation()
void setDesiredRangeForWaypoint()
void fightOrFleeMissile()
void performHyperSpaceExitWithoutReplacing()
void addFoundTargetAsDefenseTarget()
void checkForMotherStation()
void setDestinationToStationBeacon()
void setTargetToFoundTarget()
void scanForFormationLeader()
void markTargetForFines()
void setTargetToRandomStation()
void scanForRandomMerchantman()
void becomeUncontrolledThargon()
void checkOwnLegalStatus()
void setDestinationToTarget()
void setPlanetPatrolCoordinates()
void setSunSkimExitCoordinates()
void performFlyRacepoints()
void checkTargetLegalStatus()
void scanForNearestMerchantman()
void debugDumpPendingMessages()
void setCoordinatesFromPosition()
void setTargetToPrimaryAggressor()
void checkCourseToDestination()
void thargonCheckMother()
void setDestinationToJinkPosition()
void performHyperSpaceExit()
void recallStoredTarget()
void scanForNonThargoid()
void checkGroupOddsVersusTarget()
void setDestinationToCurrentLocation()
void setDestinationToDockingAbort()
void addPrimaryAggressorAsDefenseTarget()
void setSunSkimEndCoordinates()
void setDestinationToWitchpoint()
void checkForNormalSpace()
void checkDistanceTravelled()
void setDestinationWithinTarget()
void findNewDefenseTarget()
void fightOrFleeHostiles()
void setRacepointsFromTarget()
void setDestinationFromCoordinates()
void setTakeOffFromPlanet()
void setSunSkimStartCoordinates()
void getWitchspaceEntryCoordinates()
void setTargetToLastStation()
void disengageAutopilot()
void setStateMachine:withJSScript:(NSString *smName,[withJSScript] NSString *script)
void message:(NSString *ms)
void setState:(NSString *stateName)
OOUniversalID universalID
void setThrowSparks:(BOOL value)
id jsAIScriptFromFileNamed:properties:(NSString *fileName,[properties] NSDictionary *properties)
void runUnsanitizedScriptActions:allowingAIMethods:withContextName:forTarget:(NSArray *unsanitizedActions,[allowingAIMethods] BOOL allowAIMethods,[withContextName] NSString *contextName,[forTarget] ShipEntity *target)
void setScriptTarget:(ShipEntity *ship)
ShipEntity * scriptTarget()
NSString * pathForFileNamed:inFolder:(NSString *fileName,[inFolder] NSString *folderName)
void getDestroyedBy:damageType:(Entity *whom,[damageType] OOShipDamageType type)
void doScriptEvent:(OOJSPropID message)
void landOnPlanet:(OOPlanetEntity *planet)
void setTargetStation:(Entity *targetEntity)
void addTarget:(Entity *targetEntity)
void setPrimaryAggressor:(Entity *targetEntity)
void scanForNearestShipWithPredicate:parameter:(EntityFilterPredicate predicate,[parameter] void *parameter)
void setFuel:(OOFuelQuantity amount)
void removeTarget:(Entity *targetEntity)
BOOL addDefenseTarget:(Entity *target)
void setAIScript:(NSString *aiString)
void setEvasiveJink:(GLfloat z)
OOShipGroup * escortGroup()
void setSpeed:(double amount)
void scanForNearestShipWithPrimaryRole:(NSString *scanRole)
BOOL suggestEscortTo:(ShipEntity *mother)
int checkShipsInVicinityForWitchJumpExit()
void setGroup:(OOShipGroup *group)
Entity * primaryAggressor()
void setPrimaryRole:(NSString *role)
void broadcastDistressMessageWithDumping:(BOOL dumpCargo)
BOOL performHyperSpaceExitReplace:(BOOL replace)
void checkScannerIgnoringUnpowered()
StationEntity * targetStation()
void doScriptEvent:withArgument:andArgument:(OOJSPropID message,[withArgument] id argument1,[andArgument] id argument2)
ShipEntity * fireMissile()
void removeDefenseTarget:(Entity *target)
OOPlanetEntity * findNearestPlanet()
OOCommodityType dumpCargo()
void setAITo:(NSString *aiString)
void commsMessage:withUnpilotedOverride:(NSString *valueString,[withUnpilotedOverride] BOOL unpilotedOverride)
void scanForNearestShipHavingRole:(NSString *scanRole)
BOOL performHyperSpaceExitReplace:toSystem:(BOOL replace,[toSystem] OOSystemID systemID)
Entity< OOStellarBody > * findNearestStellarBody()
void sendExpandedMessage:toShip:(NSString *message_text,[toShip] ShipEntity *other_ship)
void scanForNearestShipWithNegatedPredicate:parameter:(EntityFilterPredicate predicate,[parameter] void *parameter)
void noteLostTargetAndGoIdle()
OOCargoQuantity maxAvailableCargoSpace()
void doScriptEvent:withArgument:(OOJSPropID message,[withArgument] id argument)
void markAsOffender:withReason:(int offence_value,[withReason] OOLegalStatusReason reason)
void setRememberedShip:(Entity *targetEntity)
void reactToAIMessage:context:(NSString *message,[context] NSString *debugContext)
void setFoundTarget:(Entity *targetEntity)
OOPlanetEntity * findNearestPlanetExcludingMoons()
void sendAIMessage:(NSString *message)
void acceptDistressMessageFrom:(ShipEntity *other)
void enterWormhole:replacing:(WormholeEntity *w_hole,[replacing] BOOL replacing)
void setOwner:(Entity *who_owns_entity)
Entity * lastEscortTarget()
void recallDockingInstructions()
void acceptPatrolReportFrom:(ShipEntity *patrol_ship)
ShipEntity * launchDefenseShip()
NSDictionary * dockingInstructionsForShip:(ShipEntity *ship)