OXP howto AI

From Elite Wiki
Revision as of 07:32, 17 September 2010 by Eric Walch (talk | contribs) (Added: thargonCheckMother)

AI Script Format

The AI system consists of a stack of state machines (only the top one of which is active), which respond to game events sent to them as messages. They respond by calling a series of methods which affect the behaviour of the entity and possibly trigger changes to the AI by changing the state or (more drastically) the state machine.

Each state machine (or AI script) is described in a property list. The structure is of a dictionary containing each of the machine's possible states referenced by an identifying state name. Each state comprises a dictionary of responses to messages the AI might receive, referenced by the message itself. Each response is an array of methods that will be called when the AI receives that message.

The AI function calls within a message handler are separated from each other by a comma. If a function takes a parameter the value is separated from the function name by a colon and a space, and both the function name and value are enclosed in double quotes.

In OpenStep property list format a simple (two-state) machine looks like this:

{
     "STATE_1" = {
         "ENTER" = ();
         "MESSAGE_A" = ("method1: value", method2, method3);
         "MESSAGE_B" = (method4, "setStateTo: STATE_2");
         EXIT = ();
         UPDATE = ();
     };
     "STATE_2" = {
         "ENTER" = ();
         "MESSAGE_A" = ("method1: another_value", method5);
         "MESSAGE_B" = (method6, method7, "setStateTo: STATE_1");
         EXIT = ();
         UPDATE = ();
     };
}

The same script in XML.


AI

Messages to the statemachine with a priority are displayed in boldface.

Method Description
dropMessages: (NSString *)messageString Removes the pending massage(s) with this name. (Added in Oolite 1.73)

e.g. when attacking a trader there is often both a "FIGHTING" and a "FLEEING" message on update time. When reacting on one while staying in the same state, it might be wise to drop the other possible one.

exitAI Exits current AI and returns to the same state in the old AI that called this AI with a "setAITo:". It returns: "RESTARTED".
exitAIWithMessage: (NSString *)messageString Exits current AI and returns to the same state in the old AI that called this AI with a "setAITo:". It returns: "messageString" instead of RESTARTED. Useful for something like "exitAIWithMessage: ATTACKED", as the main AI will loose that message with just an "ExitAI". (Added in OOlite 1.73)
messageSelf: (NSString *)messageString Sends a message to itself to be read in the next UPDATE. Useful to add delays in a reaction on an other message without the need to go to another state. (Added in Oolite 1.73)

e.g.

INCOMING_MISSILE = ("messageSelf: MISSILE_DETECTED", "pauseAI: 1.5");
MISSILE_DETECTED = (fightOrFleeMissile);

will act delayed on an incoming missile.

pauseAI: (NSString *)intervalString Sets next AI update time in seconds. It does not stop the execution of the remainder of the line. It just sets the next UPDATE time to the current time plus the pause time. The pauseAI commands are non-cumulative.
randomPauseAI: (NSString *)intervalString Sets next AI update time in seconds to a random time between a minimum and a maximum value. This command takes two space separated parameters like in "randomPauseAI: 0.2 2.6". (Added in Oolite 1.73)
setAITo: (NSString *)aiString Pauses current AI and switches to anotherAI.plist, this becomes the top AI on the 'AI-stack'.
When anotherAI.plist exits (exitAI or exitAIWithMessage), the previousAI becomes topAI again and AI-state is messaged "RESTARTED" .
(In some older scripts the commands "setStateMachine:" is found. That does the same as "setAITo:" and should be replaced by setAITo:.)
setStateTo: SOMESTATE Changes the AI state to SOMESTATE.
switchAITo: (NSString *)aiString Switches entity AI to another *AI.plist, the previous AI will be exited.

AI choices

Method Description
fightOrFleeHostiles Deploys escorts if he has them. If he has enough missiles left he might fire one. Then decides between issue the FIGHTING or FLEEING message. Returns "FIGHTING", "DEPLOYING_ESCORTS" or "FLEEING".
fightOrFleeMissile Deals with missiles, uses ECM if available, flees if not, marks as offender if police. Returns: "FLEEING" or nothing.

Perform Action

Method Description
becomeEnergyBlast Used in the Q bomb.
becomeExplosion The entity model is replaced by an explosion. If player is docked at exploding station it first launches the player.
becomeLargeExplosion Used at player entity death, not for use in other instances.
dealEnergyDamageWithinDesiredRange Needs desiredRange to be set first, then deals weaponEnergy (Shipdata.plist) damage within this sphere.
decreaseAlertLevel Can only be used on stations. Decreases station alertlevel. Returns: "CONDITION_YELLOW", "CONDITION_GREEN".
deployEscorts Sends the mothers primary target to all escorts and sets the statemachine of all the escorts to: interceptAI.plist.
dockEscorts Gives all existing escorts a dockingAI.plist and sets the state to ABORT so the escorts go to a waiting position for docking.
dumpCargo Ejects one cargo canister when present. Since Oolite 1.74 this action will send "CARGO_DUMPED" to all ships in range.
ejectCargo Ejects the complete cargo bay content with 0.75 seconds spacing between cargo canisters. Since Oolite 1.74 this action will send "CARGO_DUMPED" to all ships in range.
enterTargetWormhole Will locate nearest wormhole, and enter it.
escortCheckMother Returns "ESCORTING" or "NOT_ESCORTING".
fireECM Used by stations and hermits to engage ECM.
fireMissile Fires missiles on selected target. It sends a "INCOMING_MISSILE" message to the target state machine.
groupAttackTarget All ships in group will have their targets set to this entity's current target. It will return "GROUP_ATTACK_TARGET" to the sending ship as well as to all group members.
increaseAlertLevel Can only be used on stations. Increases station alertlevel. Returns: "YELLOW_ALERT", "RED_ALERT".
landOnPlanet Selects the nearest planet it can find, increments the landed shuttles counter for that planet and 'removes' the entity. Returns: "LANDED_ON_PLANET"
Launch..SomeShip Launches a ship fron a dockable entity, various types of this method exist. See also Station Ships.
  • LaunchDefenseShip
  • LaunchEscort
  • LaunchIndependentShipWithRole: <Role> (Added with Oolite 1.73)
  • LaunchMiner
  • LaunchPatrol
  • LaunchPirateShip
  • LaunchPolice
  • LaunchScavenger
  • LaunchShipWithRole: <Role>
  • LaunchShuttle
  • LaunchTrader
markTargetForFines Deals out a fine to target. It returns: "TARGET_MARKED". When the target was no ship it returns: "TARGET_LOST".

Will fine the target on the next docking in the current system. The value of the fine is always 50 or 100, multiplied by the targets legal status on docking. Dealing out multiple fines has no extra effect. On paying the fine, the ships legal status is cleared and the system clock advances a day. The amount to be fined is cleared after the ship enters a new system.

markTargetForOffence:(NSString*) valueString Has police mark up the criminal record (Legal status) of target entity. The value is not added to the criminal record but a bit-wise OR is used between value and criminal record. It returns: "TARGET_LOST" when the target was no ship. This command can only be used by stations or police ships. With other ships this command is ignored.
messageMother:(NSString *)msgString Sends a AI priority message to the mothership/leader of a group.

Example:

INCOMING_MISSILE = ("messageMother: INCOMING_MISSILE");

The mothership will then behave as if it was targeted by the missile. But you don't have to use standard message names, you can also send self defined message names were the mother can react on.

performAttack Attacks target.
performCollect Performs 'collection' of target.
performDocking NOT YET IMPLEMENTED.
performEscort Performs escorting. Needs a desired range first. The escorts follow at the desired range. See also Escort Instructions.
performFaceDestination Has entity face destination. Sets also the desiredSpeed to zero. Returns "FACING_DESTINATION" when turn is completed.
performFlee Sets the caller (AI) to flee from it's primary target at maximum speed. If the caller has a cloaking device, it will be activated. It needs a range to be set first. When the ship outruns the attacker by this distance it returns: "REACHED_SAFETY".
performFlyToRangeFromDestination With this command the ship can react in two ways. It first looks at the distance to the target. When it is closer to the target than the previously defined desired range, it will fly away from the target, otherwise it will fly toward the target. It stops the ship at the desired range from the destination and than returns: "DESIRED_RANGE_ACHIEVED".

It will not send a ship on a head-on course to the target, but on a course that intersects with a sphere of desired_range around the target. When flying towards the target it will automatic reduce speed based on ship characteristics so it stops at almost the exactly the desired_range from target. (setting speed in UPDATE could interfere with this). It sends a "FRUSTRATED" message when not progressing for some time.

performHold Performs idleness while tracking a potential target, speed is set to zero. frustration level is reset.
performHyperSpaceExit Gets a list of destinations within fuel range, checks if clear of nearby masses, and select one at random. May return "WITCHSPACE UNAVAILABLE", "WITCHSPACE BLOCKED" or "WITCHSPACE_OKAY". It will add a new ship with the same role as the leaving ship at the witchspace entry point.

When the player performs a hyperspace exit or a galactic jump, all NPC ships get the priority message: "PLAYER WITCHSPACE".

performHyperSpaceExitWithoutReplacing Gets a list of destinations within fuel range, checks if clear of nearby masses, and select one at random. May return "WITCHSPACE UNAVAILABLE", "WITCHSPACE BLOCKED" or "WITCHSPACE_OKAY". This command will not add a new ship at the witchspace entry point. (available with version 1.70 and higher)
performIdle Performs idleness. Ship corrects its roll and pitch to 'horizontal' flight, speed is unaffected. frustration level is reset to zero.
performIntercept Performs target interception. It needs a range to be set first. When the distance to target becomes less than desired range it returns: "DESIRED_RANGE_ACHIEVED". When target lost: "TARGET_LOST". When it hasn't come closer to target for 10 seconds it returns: "FRUSTRATED"
performMining Performs mining. (Finds, intercepts and shoots asteroids with mining laser, if fitted.) It returns: "TARGET_LOST".
performTumble Performs random pitch and roll, 'evasive maneuvers'.
setSpeedTo:(NSString *)speedString Sets desired speed to an absolute value, entity cannot go faster than maxspeed value determined in the shipdata.plist. If speed is above maxspeed, entity will use fuel injectors if available.
setSpeedFactorTo:(NSString *)speedString Sets the desired speed to a percentage of maxspeed (0->1=0%->100%). If speedfactor is set above 100%, entity will use fuelinjectors if available.
setThrustFactorTo:(NSString *)thrustString Sets the thrust to a percentage of maxThrust (0->1=0%->100%). maxThrust is the thrust value defined in shipdata. (Added with Oolite 1.74)
setUpEscorts Useful to quickly establish (by name and number the shipdata.plist prescribed) escorts, when a ship is introduced to a system. See also Escort Instructions.
suggestEscort Has an escort seek employment and either gets accepted or rejected by the "mother". See also Escort Instructions.
switchLightsOff If an entity has lights (or flashers), this command will turn them off. Default state is on. (See shipdata.plist)
switchLightsOn Will turn flashers back on.
throwSparks Will throw a single burst of spark. (added in Oolite 1.73)
wormholeEntireGroup Wormholes ships in this group. Returns "ENTER WORMHOLE"
wormholeEscorts Wormholes official escorts. Returns "ENTER WORMHOLE"
wormholeGroup Wormholes ships in group of which this is a leader. Returns "ENTER WORMHOLE"

Navigation

Method Description
**** The aegis check is part of the system update and messages needs no command to generate them. The following messages are only generated when the status changes.

"AEGIS_CLOSE_TO_PLANET": Within 3x planetary radius of the main planet and not near station. "AEGIS_IN_DOCKING_RANGE": Within 2x scanner radius of system station. "AEGIS_LEAVING_DOCKING_RANGE": Has been in docking range but now only close to planet. "AEGIS_NONE": None of the above three messages is true.

Starting with Oolite 1.72 new messages are added:
"AEGIS_CLOSE_TO_MAIN_PLANET": Within 3x planetary radius of the main planet and not near station. "CLOSE_TO_PLANET": Within 3x planetary radius of any planet and not near station. "AWAY_FROM_PLANET": Leaving the area of 3x planetary radius of any planet.

Starting with Oolite 1.73 new messages are added:
"CLOSE_TO_SUN": Within 3x sun radius of the sun . "AWAY_FROM_SUN Leaving the area of 3x sun radius of the sun. "CLOSE_TO_SECONDARY_PLANET": Within 3x radius of a planet that is not the main-planet. "CLOSE_TO_MOON": Within 3x radius of a moon (=planet without atmosphere).

With intersecting aegis of planets the main-planet aegis has priority, even when closer to another planet.

**** The surface check needs no command. It automatically generates messages when a ship passes a border at approximately 1 meter from the main planet surface.

"APPROACHING_SURFACE": passed the border inward. "LEAVING_SURFACE": passed the border outward.

abortDocking Signal the mother station that the docking is aborted. see Docking Instructions
checkAegis Retransmits the aegis status. Sends: "AEGIS_NONE", "AEGIS_IN_DOCKING_RANGE", "AEGIS_CLOSE_TO_MAIN_PLANET", "AEGIS_CLOSE_TO_PLANET", "CLOSE_TO_PLANET", "CLOSE_TO_SECONDARY_PLANET", "CLOSE_TO_MOON" and/or "CLOSE_TO_SUN". (Added with Oolite 1.74)
getWitchspaceEntryCoordinates Calculates coordinates at 10 km from the rotation axis of the nearest station it can find, or just fly 10s forward.
recallDockingInstructions see Docking Instructions
requestDockingCoordinates Requests coordinates from the nearest station it can find (which may be a Rock hermit). Returns: "NO_STATION_FOUND", "TRY_AGAIN_LATER", "HOLD_POSITION", "BACK_OFF" , "APPROACH" or "APPROACH_COORDINATES". see also Docking Instructions
setCoordinates:(NSString *)system_x_y_z Sets destination coords, see addShipsAt. It needs 4 parameters separated with space. When coordinates are set it returns: "APPROACH_COORDINATES". You can even randomize positive coordinates.
setCoordinatesFromPosition Sets Coordinates to the current position. Nothing is done with these coordinates until setDestinationFromCoordinates is used. Useful for remembering a position for later returning. (getWitchspaceEntryCoordinates, setPlanetPatrolCoordinates, setSunSkimStartCoordinates, setSunSkimEndCoordinates, setSunSkimExitCoordinates, setCoordinates: and setDestinationToDockingAbort will also set new coordinates and overwrite an existing Coordinates value with a new one) Added with Oolite 1.74
setCourseToPlanet Selects the nearest planet it can find, sets the coordinates to a point on the ship's side of the surface with a large random spread to avoid all ships flying to the same point. Then it sets the desired range to 50 m (+ its own collision diameter). This short desired range will probably crash normal fast flying ships on the surface but a collision between the planet and a ship with role "shuttle" is interpreted as landing. (Change with Oolite 1.73: Will exclude moons. Closest planet will be of type: PLANET_TYPE_GREEN)
setCourseToWitchpoint Sets destination coords to Witchpoint area and sets "DesiredRange" to 10 km.
setDesiredRangeTo:(NSString *)rangeString Some methods (such as scanForNearestMerchantmen, checkCourseToDestination, checkDistanceTravelled, etc) require a "desired range" parameter to be set before they can be used.

This method is used to set the desired range. There is only one value for desired range within an instance of the AI. The value of desired range is modified internally by AI methods such as fightOrFleeMissile, setCourseToWitchpoint, and setPlanetPatrolCoordinates.

setDestinationFromCoordinates Enables the plotting of manual waypoints.
setDestinationToCurrentLocation This method sets the destination of the current entity to its current location plus a random offset of up to 0.5 metres in the X, Y, and Z coordinates. This can be used to make a ship idle in a small area of space without being completely still.
setDestinationToDockingAbort DockingAbort coordinates 8000 meter distance from the docking slit.
setDestinationToStationBeacon Sets destination at 10 km ahead of the docking slid (of the main station). The station beacon itself needs not to be present.
setDestinationToTarget Sets destination to target coords.
setDestinationToWitchpoint Sets destination coordinates to WitchspaceExitPosition.
setDestinationWithinTarget Handy for ramming and racing.
setPlanetPatrolCoordinates Request coordinates for planet control. Read more in setPlanetPatrolCoordinates.
setSunSkimEndCoordinates ...
setSunSkimExitCoordinates ...
setSunSkimStartCoordinates ...
setTargetToSystemStation Sets the system station as the current target.
setTargetToStation Sets the closest station as the current target. When the ship has a mother station, the mother will become the target, even when there is a closer station.
setTargetToNearestStation Sets the closest station as the current target. When the ship has a mother station, the mother will become the target, even when there is a closer station. (added with Oolite 1.72?) Exactly the same as setTargetToStation but preferred above the old name.
setTakeOffFromPlanet Selects the nearest planet it can find and calculates a vector perpendicular to the surface and sets a destination range of 10 km. Does nothing if there is no planet to be found.

Communication

Method Description
****** Hitting a clean ship with scanClass equal to CLASS_NEUTRAL, CLASS_STATION, CLASS_BUOY, CLASS_POLICE, CLASS_MILITARY or CLASS_PLAYER, automatically sends a "OFFENCE_COMMITTED" to all nearby police ships and the system station. Besides this all the ships flying in a group like pirates, police or escorts get an "ATTACKED" message as when they were attacked themself.
broadcastDistressMessage Locates all the stations, bounty hunters and police ships in range and tells them that you are under attack. This command resets a previous found target to none at the sending side. It returns: "ACCEPT_DISTRESS_MESSAGE" in the AI of Stations, Hunters and Police ships and gives them as" Found Target", the "Primary Target" of the sender of the broadcast.
commsMessage:(NSString *)valueString Broadcasts a general message to player. It will only send a message if the ship has a pilot. (not by rocks, cargo pods etc.)

Example:

"sendCommsMessage: [thargoid_curses]"
commsMessageByUnpiloted:(NSString *)valueString Broadcasts a general message to player without check for pilot. (Will be available from 1.72+)

Example:

"commsMessageByUnpiloted: This is an automated distress signal."
patrolReportIn This command sets the "last patrol report time" to the current time. Only useful for station patrol.
sendTargetCommsMessage:(NSString*) message Sends any message to the established (found) target. When the target is not a ship it returns: "TARGET_LOST"

Example:

"sendTargetCommsMessage: Listen to me!!"

Locating entities

For all these methods you can set a maximum scanning range by setting <scanner_range> in shipdata.plist. Only the first 16 ships in scanner range are evaluated. With more than 16 ships in range, the scanner might miss some ships. So when you want your ship to scan in dense populated areas you might want to set <scanner_range> in shipdata.plist at a lower value to have less chance to hit the maximum of 16 ships during scanning and do a more accurate scanning in the smaller area.
All scans will return the message TARGET_FOUND or NOTHING_FOUND. The calling entity remembers the found target, but it does not become the current (universal) target. It can be made the current target by responding to the TARGET_FOUND message with a call to setTargetToFoundTarget. All scan commands start with clearing any previous found target, so you can't use two scans in the same line for complex scanning.

When you are continuously scanning as in a update event, make sure you add also a pause command. Scanning takes time and in most cases one scan every few seconds is enough. Look also at Oolites internal AI's were this timing is well thought of.

Method Description
checkCourseToDestination Will return "COURSE_OK" when no obstacles on the direct route, else it calculates a little deviated save vector and returns "WAYPOINT_SET". When there is a small ship in his way it also returns: HAZARD_CAN_BE_DESTROYED

(Since 1.73 not the whole route is examined, but only the part within scanner range for ships and a bit longer range for planets&moons).

checkDistanceTravelled First you must define a range with setDesiredRangeTo:. When the total traveled distance since creation is greater than this value it returns: "GONE_BEYOND_RANGE". Used for missiles.
checkGroupOddsVersusTarget Will return "ODDS_GOOD", "ODDS_LEVEL" or "ODDS_BAD".
checkForFullHold If entity's cargo capacity is reached, will return "HOLD_FULL".

Since 1.73 it can also return "HOLD_NOT_FULL" or "NO_CARGO_BAY".

checkForMotherStation Will return "STATION_FOUND" or "NOTHING_FOUND".
checkForNormalSpace Will return "NORMAL_SPACE" or "INTERSTELLAR_SPACE".
checkTargetLegalStatus Returns "TARGET_CLEAN, "TARGET_MINOR_OFFENDER", "TARGET_OFFENDER", "TARGET_FUGITIVE" or "NO_TARGET".
findNearestPlanet Will scan for planetentity. Returns nothing. Nearest planet coordinates are placed in destination memory.
scanForFormationLeader Locates the nearest suitable formation leader in range. Returns: "TARGET_FOUND" or "NOTHING_FOUND". See also Escort Instructions.
scanForHostiles Locates all the ships in range targeting the receiver and ships with "CLASS_TARGOID" and chooses the nearest. Returns: "TARGET_FOUND" or "NOTHING_FOUND"
scanForLoot Scans for nearest debris in range.

Returns: "HOLD_FULL", "TARGET_FOUND" or "NOTHING_FOUND". If scanning ship is moving station or has no scoop it always return: "NOTHING_FOUND". If scanning ship has scanClass: "CLASS_POLICE", it only finds slaves and lifepods.
Loot is everything with scan_class = CLASS_CARGO, except debris that explicit defines: cargo_type = CARGO_NOT_CARGO

scanForNearestMerchantmen Scans for ships with role: Trader or Player and selects the nearest. If scanning ship has role Pirate it prefers the player.

Returns: "TARGET_FOUND" or "NOTHING_FOUND"

scanForNearestShipWithRole:(NSString*) scanRole Locates all the ships in range and chooses the nearest. Returns: "TARGET_FOUND" or "NOTHING_FOUND". Anything of CLASS_CARGO is skipped in the search, even if the role matches.
scanForNonThargoid Locates all the non thargoid ships in range and chooses the nearest. It finds everything except cargo and ships with scanClass "thargoid". If it finds the player it prefers the player. Returns: "TARGET_FOUND" or "NOTHING_FOUND" (Before 1.70 it did not look for scanClass but for a role starting with "tharg")
scanForOffenders Locates all the ships in range, multiplies the legal status with a government factor, subtracts a random value between 0 and 255 from this result and compares the remaining value. It chooses the worst remaining offender. Because of the random value not all ships are found in every scan and the lower the bounty and lower the government, the longer it takes to detect a ship as offender. Returns: "TARGET_FOUND" or "NOTHING_FOUND".

Government factor = 0 in an anarchy and increases with 0.4 for every government till it reaches 2.8 for a corporate state. Result is that it never finds a ship in an anarchy, that is needs 637 points to always find an offender in a feudal state and only needs 91 points to always find a offender in a corporate state.

scanForRandomLoot Scans for debris in range and selects one at random from the first 16 found.

Returns: "TARGET_FOUND" or "NOTHING_FOUND" If scanning ship is station or has no scoop it always return: "NOTHING_FOUND".

scanForRandomMerchantmen Scans for ships with role: Trader or Player and selects one at random. Returns: "TARGET_FOUND" or "NOTHING_FOUND".
scanForRocks Scans for nearest boulder in range. When nothing found then scans for nearest asteroid in range. Returns "TARGET_FOUND" or "NOTING_FOUND".
scanForThargoid Locates all the ships with primaryRole "thargoid" in range and chooses the nearest. Returns: "TARGET_FOUND" or "NOTHING_FOUND"
thargonCheckMother Checks if its owner is still alive and in range. When not it scans for a new ship containing the role "thargoid-mothership" in its role list and makes that the new owner. Returns: "TARGET_FOUND" or "NOTHING_FOUND". (Added with Oolite 1.75)

Targeting

Method Description
requestNewTarget Locates all the ships in range targeting the mother ship, and chooses the nearest/biggest. Returns: "MOTHER_LOST", "TARGET_FOUND" or "NOTHING_FOUND".
setTargetToFoundTarget Affirms a TARGET_FOUND by a scanFor- or find-Something-method as the universal target.
setTargetToPrimaryAggressor This function sets the primary agressor to the primary target. Then in the "performAttack" state, it only has a 25% change of setting the primary agressor to the primary target. The other 75% it will do nothing. This function is designed for used during attack to prevent it will constantly change targets when attacking a group.

primary agressor is set by the system when a ship fires a laser or missile on the other.

Flying racing points

Method Description
targetFirstBeaconWithCode:(NSString*) beacon code Looks for all beacons in the system that contain the given code, sorts them alphabetical and puts them in a list, and defines the first in the list as the found target. The code-string to search for can be in the middle of the beacon-code itself. (e.g. beacon codes: 1-TBR, 2-TBG, 3-TBR and looking for TB) Returns: "TARGET_FOUND" or "NOTHING_FOUND".
targetNextBeaconWithCode:(NSString*) beacon code Sets the target to the next target in the list that was generated by the command : targetFirstBeaconWithCode. Returns: "NO_CURRENT_BEACON" when the primary target is no beacon, "TARGET_FOUND" when there is a next beacon in the list or "LAST_BEACON" when there is no next beacon in the list. On top of the previous messages it sends a "NOTHING_FOUND" when there is no target found.
setRacepointsFromTarget Sets 3 racing points along the z-axis of the target and sets the destination to the first. Returns: "NOTHING_FOUND" or "RACEPOINTS_SET"
performFlyRacepoints Sets the ship in a mode to fly a path along the 3 points set by setRacepointsFromTarget. Returns: "NAVPOINT_REACHED" when arriving at one of the 3 navpoints and "ENDPOINT_REACHED" when arriving at the last one. It also triggers the eventhandlers: this.shipReachedNavPoint() and this.shipReachedEndPoint() for use in java-script)

Miscellaneous

Method Description
addFuel:(NSString*) fuel_number Changes player's fuel level by fuel_number LY's, max to 7.0 min to 0.0.
becomeUncontrolledThargon Changes ship into cargo with scannClass "CLASS_CARGO" and sets AI to "dumbAI". If also the the cargo type is defined in ShipData.plist it can be picked up like any other cargo.
checkEnergy Checks the energy level and returns: ENERGY_LOW (energy< 25%), ENERGY_MEDIUM (25%<energy<75%), ENERGY_HIGH (75%<energy<100%) or ENERGY_FULL (energy = 100%). Added with Oolite 1.74
initialiseTurret Prepares the turret. As turrets have no statemachine of their own, this function can only be used in the setup_actions of the turrets shipData.
rollD:(NSString*) dice_number Uses "dice" for random situation use. It returns "ROLL_1", "ROLL_2" and so on until dice_number. dice_number is an integer and has no size limit.

Example 1, 3 options in someAI.plist:

GLOBAL = {
  ENTER = ("rollD: 3"); 
  "ROLL_1" = (action1);
  "ROLL_2" = (action2);
  "ROLL_3" = (action3);}

Example 2, 50% chance in script.plist;

conditions = ("d100_number lessthan 50");
do = (action1);
else = (action2);

is similar in function.

safeScriptActionOnTarget:(NSString*) action This will do a script action on the target. For NPC ships as target you can use all the AI commands available that will act as if its own AI used the command. (command introduced with version 1.71)

It will also execute player script commands, like setting mission variables. For this to work it needs a target being set. It doesn't matter witch one.

Example:

"scriptActionOnTarget: set: mission_my_missionvariable TRUE",
"scriptActionOnTarget: awardCredits: 100"
scriptActionOnTarget:(NSString*) action This will do the same as safeScriptActionOnTarget, but in addition the legacy script engine is started so all installed player scripts are evaluated immediately. Use of this command is discouraged in favour of safeScriptActionOnTarget as it takes a lot of time to evaluate all scripts and in most situations this is also unnecessary.
sendScriptMessage: message Calls the javaScript function message() on the ship’s ship script. Added in Oolite 1.70. This function opens the whole js power to the AI scripting. e.g. by using:
"sendScriptMessage: myFunction".

This script message than activates the ship-script function:

this.myFunction = () { body };

Since Oolite 1.73 one can also transfer space separated parameters by using:

"sendScriptMessage: myFunction param1 param2"

These values are transferred as an array and can be read in JavaScript as

this.myFunction = ([param1, param2]) { body };

Note that spaces are read as separation of parameters so you cant transfer message text with spaces.

Role scanning methods

Starting with version 1.70 next commands will become available. This info is still preliminary until the actual release. These role based methods all skip ships with scanclass: CLASS_CARGO

Method Description
scanForNearestShipWithPrimaryRole:(NSString*) role new (preferred) name for scanForNearestShipWithRole:.
scanForNearestShipHavingRole:(NSString*) role scan based on entire role set rather than primary role.
scanForNearestShipWithAnyPrimaryRole:(NSString*) role-list takes a list of roles (space-separated) and returns the nearest ship with any of them as primary.
scanForNearestShipHavingAnyRole:(NSString*) role-list takes a list of roles (space-separated) and returns the nearest ship with any of them in its role set.
scanForNearestShipWithScanClass:(NSString*) scanclass searches for a ship by scan class.
scanForNearestShipWithoutPrimaryRole:(NSString*) role
scanForNearestShipNotHavingRole:(NSString*) role
scanForNearestShipWithoutAnyPrimaryRole:(NSString*) role-list
scanForNearestShipNotHavingAnyRole:(NSString*) role-list
scanForNearestShipWithoutScanClass:(NSString*) scanclass