Naev

Module ai

Handles how the AI interacts with the universe.

Usage is:

 ai.function( params )
 

Functions

pushtask (func[, data]) Pushes a task onto the pilot's task list.
poptask () Pops the current running task.
taskname () Gets the current task's name.
target () Gets the pilot's task target.
pushsubtask (func[, data]) Pushes a subtask onto the pilot's task's subtask list.
popsubtask () Pops the current running task.
subtaskname () Gets the current subtask's name.
subtarget () Gets the pilot's subtask target.
pilot () Gets the AI's pilot.
rndpilot () Gets a random pilot in the system.
nearestpilot () gets the nearest pilot to the current pilot
dist (pointer) Gets the distance from the pointer.
flyby_dist (pointer) Gets the distance from the pointer perpendicular to the current pilot's flight vector.
minbrakedist () Gets the minimum braking distance.
isbribed (target) Checks to see if target has bribed pilot.
getstanding (target) Gets the standing of the target pilot with the current pilot.
ismaxvel () Checks to see if pilot is at maximum velocity.
isstopped () Checks to see if pilot is stopped.
isenemy (target) Checks to see if target is an enemy.
isally (target) Checks to see if target is an ally.
haslockon () Checks to see if pilot has a missile lockon.
hasprojectile () Checks to see if pilot has a projectile after him.
accel ([acceleration=1.]) Starts accelerating the pilot.
turn (vel) Starts turning the pilot.
face (target, invert, compensate) Faces the target.
careful_face (target) Gives the direction to follow in order to reach the target while minimizating risk.
aim (target) Aims at a pilot, trying to hit it rather than move to it.
iface (target) Maintains an intercept pursuit course.
dir (target) calculates the direction that the target is relative to the current pilot facing.
idir (target) calculates angle between pilot facing and intercept-course to target.
drift_facing () Calculate the offset between the pilot's current direction of travel and the pilot's current facing.
brake () Brakes the pilot.
nearestplanet () Get the nearest friendly planet to the pilot.
rndplanet () Get a random planet.
landplanet (only_friend) Get a random friendly planet.
land () Lands on a planet.
hyperspace () Tries to enter hyperspace.
sethyptarget (target) Sets hyperspace target.
nearhyptarget () Gets the nearest hyperspace target.
rndhyptarget () Gets a random hyperspace target.
relvel () Gets the relative velocity of a pilot.
follow_accurate (target, radius, angle, Kp, Kd[, method]) Computes the point to face in order to follow an other pilot using a PD controller.
face_accurate (pos, vel, radius, angle, Kp, Kd) Computes the point to face in order to follow a moving object.
stop () Completely stops the pilot if it is below minimum vel error (no insta-stops).
dock (target) Docks the ship.
combat ([val=true]) Sets the combat flag.
settarget (target) Sets the pilot's target.
setasterotarget (int, int) Sets the pilot's asteroid target.
getgatherable (float) Gets the closest gatherable within a radius.
gatherablepos (int) Gets the pos and vel of a given gatherable.
weapset (id[, type=true]) Sets the active weapon set, fires another weapon set or activate an outfit.
hascannons () Does the pilot have cannons?
hasturrets () Does the pilot have turrets?
hasafterburners () Does the pilot have afterburners?
shoot ([secondary=false]) Makes the pilot shoot
getenemy () Gets the nearest enemy.
getenemy_size (lb, ub) Gets the nearest enemy within specified size bounds.
getenemy_heuristic (mass, dps, hp, range) Gets the nearest enemy within specified heuristic.
hostile (target) Sets the enemy hostile (basically notifies of an impending attack).
getweaprange ([id[, level=-1]]) Gets the range of a weapon.
getweapspeed ([id[, level=-1]]) Gets the speed of a weapon.
canboard (target) Checks to see if pilot can board the target.
relsize (target) Gets the relative size (ship mass) between the current pilot and the specified target.
reldps (target) Gets the relative damage output (total DPS) between the current pilot and the specified target.
relhp (target) Gets the relative health (total shields and armour) between the current pilot and the specified target
board () Attempts to board the pilot's target.
refuel () Attempts to refuel the pilot's target.
settimer (timer[, time=0]) Sets a timer.
timeup (timer) Checks a timer.
set_shoot_indicator (value) Set the seeker shoot indicator.
set_shoot_indicator () Access the seeker shoot indicator (that is put to true each time a seeker is shot).
distress (msg) Sends a distress signal.
getBoss () Picks a pilot that will command the current pilot.
setcredits (num) Sets the pilot_nstack credits.
messages () Returns and clears the pilots message queue.


Functions

pushtask (func[, data])
Pushes a task onto the pilot's task list. ( func, data )

Parameters:

  • func string Name of function to call for task.
  • data Data to pass to the function. Supports any lua type. (optional)
poptask ()
Pops the current running task. ()
taskname ()
Gets the current task's name. ()

Returns:

    string The current task name or nil if there are no tasks.
target ()
Gets the pilot's task target. ()

Returns:

    The pilot's target ship identifier or nil if no target.

See also:

pushsubtask (func[, data])
Pushes a subtask onto the pilot's task's subtask list. ( func, data )

Parameters:

  • func string Name of function to call for task.
  • data Data to pass to the function. Supports any lua type. (optional)
popsubtask ()
Pops the current running task. ()
subtaskname ()
Gets the current subtask's name. ()

Returns:

    string The current subtask name or nil if there are no subtasks.
subtarget ()
Gets the pilot's subtask target. ()

Returns:

    The pilot's target ship identifier or nil if no target.

See also:

pilot ()
Gets the AI's pilot. ()

Returns:

    Pilot The AI's pilot.
rndpilot ()
Gets a random pilot in the system. ()

Returns:

    Pilot or nil
nearestpilot ()
gets the nearest pilot to the current pilot ()

Returns:

    Pilot or nil
dist (pointer)
Gets the distance from the pointer. ( pointer )

Parameters:

  • pointer Vec2 or Pilot

Returns:

    number The distance from the pointer.
flyby_dist (pointer)
Gets the distance from the pointer perpendicular to the current pilot's flight vector. ( pointer )

Parameters:

  • pointer Vec2 or Pilot

Returns:

    number offset_distance
minbrakedist ()
Gets the minimum braking distance.

braking vel ==> 0 = v - a*dt add turn around time (to initial vel) ==> 180.*360./cur_pilot->turn add it to general euler equation x = v * t + 0.5 * a * t^2 and voila!

I hate this function and it'll probably need to get changed in the future

()

Returns:

    number Minimum braking distance.
isbribed (target)
Checks to see if target has bribed pilot. ( target )

Parameters:

  • target Pilot

Returns:

    boolean Whether the target has bribed pilot.
getstanding (target)
Gets the standing of the target pilot with the current pilot. ( target )

Parameters:

  • target Pilot Pilot to get faction standing of.

Returns:

    number or nil The faction standing of the target [-100,100] or nil if invalid.
ismaxvel ()
Checks to see if pilot is at maximum velocity. ()

Returns:

    boolean Whether the pilot is at maximum velocity.
isstopped ()
Checks to see if pilot is stopped. ()

Returns:

    boolean Whether the pilot is stopped.
isenemy (target)
Checks to see if target is an enemy. ( target )

Parameters:

  • target Pilot

Returns:

    boolean Whether the target is an enemy.
isally (target)
Checks to see if target is an ally. ( target )

Parameters:

  • target Pilot

Returns:

    boolean Whether the target is an ally.
haslockon ()
Checks to see if pilot has a missile lockon. ()

Returns:

    boolean Whether the pilot has a missile lockon.
hasprojectile ()
Checks to see if pilot has a projectile after him. ()

Returns:

    boolean Whether the pilot has a projectile after him.
accel ([acceleration=1.])
Starts accelerating the pilot. ( acceleration )

Parameters:

  • acceleration number Fraction of pilot's maximum acceleration from 0 to 1. (default 1.)
turn (vel)
Starts turning the pilot. ( vel )

Parameters:

  • vel number Directional velocity from -1 to 1.
face (target, invert, compensate)
Faces the target. ( target, invert, compensate )

Parameters:

  • target Pilot, Vec2 or number Target to face.
  • invert boolean Invert away from target.
  • compensate boolean Compensate for velocity?

Returns:

    number Angle offset in degrees.

Usage:

  • ai.face( a_pilot ) -- Face a pilot
  • ai.face( a_pilot, true ) -- Face away from a pilot
  • ai.face( a_pilot, nil, true ) -- Compensate velocity facing a pilot
careful_face (target)
Gives the direction to follow in order to reach the target while minimizating risk.

This method is based on a simplified version of trajectory generation in mobile robotics using the potential method.

The principle is to consider the mobile object (ship) as a mechanical object. Obstacles (enemies) and the target exert attractive or repulsive force on this object.

Only visible ships are taken into account. ( target )

Parameters:

  • target Pilot, Vec2 or number Target to go to.
aim (target)
Aims at a pilot, trying to hit it rather than move to it.

This method uses a polar UV decomposition to get a more accurate time-of-flight ( target )

Parameters:

  • target Pilot The pilot to aim at

Returns:

    number The offset from the target aiming position (in degrees).
iface (target)
Maintains an intercept pursuit course. ( target )

Parameters:

  • target Pilot or Vec2 Position or pilot to intercept.

Returns:

    number The offset from the proper intercept course (in degrees).
dir (target)
calculates the direction that the target is relative to the current pilot facing. ( target )

Parameters:

  • target Pilot or Vec2 Position or pilot to compare facing to

Returns:

    number The facing offset to the target (in degrees).
idir (target)
calculates angle between pilot facing and intercept-course to target. ( target )

Parameters:

  • target Pilot or Vec2 Position or pilot to compare facing to

Returns:

    number The facing offset to intercept-course to the target (in degrees).
drift_facing ()
Calculate the offset between the pilot's current direction of travel and the pilot's current facing. ()

Returns:

    number Offset
brake ()
Brakes the pilot. ()

Returns:

    boolean Whether braking is finished.
nearestplanet ()
Get the nearest friendly planet to the pilot. ()

Returns:

    Planet or nil
rndplanet ()
Get a random planet. ()

Returns:

    Planet or nil
landplanet (only_friend)
Get a random friendly planet. ( only_friend )

Parameters:

  • only_friend boolean Only check for ally planets.

Returns:

    Planet or nil
land ()
Lands on a planet. ()

Returns:

    boolean Whether landing was successful.
hyperspace ()
Tries to enter hyperspace. ()

Returns:

    number or nil Distance if too far away.
sethyptarget (target)
Sets hyperspace target. (target)

Parameters:

  • target Jump Hyperspace target

Returns:

    Vec2 Where to go to jump
nearhyptarget ()
Gets the nearest hyperspace target. ()

Returns:

    JumpPoint or nil
rndhyptarget ()
Gets a random hyperspace target. ()

Returns:

    JumpPoint or nil
relvel ()
Gets the relative velocity of a pilot. ()

Returns:

    number Relative velocity.
follow_accurate (target, radius, angle, Kp, Kd[, method])
Computes the point to face in order to follow an other pilot using a PD controller. ( target, radius, angle, Kp, Kd, method )

Parameters:

  • target Pilot The pilot to follow
  • radius number The requested distance between p and target
  • angle number The requested angle between p and target
  • Kp number The first controller parameter
  • Kd number The second controller parameter
  • method string Method to compute goal angle (optional)

Returns:

    The point to go to as a vector2.
face_accurate (pos, vel, radius, angle, Kp, Kd)
Computes the point to face in order to follow a moving object. ( target, radius, angle, Kp, Kd, method )

Parameters:

  • pos vec2 The objective vector
  • vel vec2 The objective velocity
  • radius number The requested distance between p and target
  • angle number The requested angle between p and target
  • Kp number The first controller parameter
  • Kd number The second controller parameter

Returns:

    The point to go to as a vector2.
stop ()
Completely stops the pilot if it is below minimum vel error (no insta-stops). ()
dock (target)
Docks the ship. ( target )

Parameters:

  • target Pilot Pilot to dock with.
combat ([val=true])
Sets the combat flag. ( val )

Parameters:

  • val boolean Value to set flag to. (default true)
settarget (target)
Sets the pilot's target. ( target )

Parameters:

  • target Pilot to target.
setasterotarget (int, int)
Sets the pilot's asteroid target. ( field, ast )

Parameters:

  • int ast Id of the asteroid to target.
  • int ast Id of the asteroid to target.
getgatherable (float)
Gets the closest gatherable within a radius. ( field, ast )

Parameters:

  • float rad Radius to search in.

Returns:

    int i Id of the gatherable or nil if none found.
gatherablepos (int)
Gets the pos and vel of a given gatherable. ( field, ast )

Parameters:

  • int id Id of the gatherable.

Returns:

  1. vec2 pos position of the gatherable.
  2. vec2 vel velocity of the gatherable.
weapset (id[, type=true])
Sets the active weapon set, fires another weapon set or activate an outfit. ( id, type )

Parameters:

  • id number ID of the weapon set to switch to or fire.
  • type boolean true to activate, false to deactivate. (default true)
hascannons ()
Does the pilot have cannons? ()

Returns:

    boolean True if the pilot has cannons.
hasturrets ()
Does the pilot have turrets? ()

Returns:

    boolean True if the pilot has turrets.
hasafterburners ()
Does the pilot have afterburners? ()

Returns:

    boolean True if the pilot has afterburners.
shoot ([secondary=false])
Makes the pilot shoot ( secondary )

Parameters:

  • secondary boolean Fire secondary weapons instead of primary. (default false)
getenemy ()
Gets the nearest enemy. ()

Returns:

    Pilot or nil
getenemy_size (lb, ub)
Gets the nearest enemy within specified size bounds. ( lb, ub )

Parameters:

  • lb number Lower size bound
  • ub number upper size bound

Returns:

    Pilot
getenemy_heuristic (mass, dps, hp, range)
Gets the nearest enemy within specified heuristic. ( mass, dps, hp, range )

Parameters:

  • mass number goal mass map (0-1)
  • dps number goal DPS map (0-1)
  • hp number goal HP map (0-1)
  • range number weighting for range (typically > 1)

Returns:

    Pilot the best fitting target
hostile (target)
Sets the enemy hostile (basically notifies of an impending attack). ( target )

Parameters:

  • target Pilot Pilot to set hostile.
getweaprange ([id[, level=-1]])
Gets the range of a weapon. ( id, level )

Parameters:

  • id number Optional parameter indicating id of weapon set to get range of, defaults to selected one. (optional)
  • level number Level of weapon set to get range of. (default -1)

Returns:

    number The range of the weapon set.
getweapspeed ([id[, level=-1]])
Gets the speed of a weapon. ( id, level )

Parameters:

  • id number Optional parameter indicating id of weapon set to get speed of, defaults to selected one. (optional)
  • level number Level of weapon set to get range of. (default -1)

Returns:

    number The range of the weapon set.
canboard (target)
Checks to see if pilot can board the target. ( target )

Parameters:

  • target Pilot Target to see if pilot can board.

Returns:

    boolean true if pilot can board, false if it can't.
relsize (target)
Gets the relative size (ship mass) between the current pilot and the specified target. ( target )

Parameters:

  • target Pilot The pilot whose mass we will compare.

Returns:

    number A number from 0 to 1 mapping the relative masses.
reldps (target)
Gets the relative damage output (total DPS) between the current pilot and the specified target. ( target )

Parameters:

  • target Pilot The pilot whose DPS we will compare.

Returns:

    number A number from 0 to 1 mapping the relative DPSes.
relhp (target)
Gets the relative health (total shields and armour) between the current pilot and the specified target (target)

Parameters:

  • target Pilot The pilot whose health we will compare.

Returns:

    number A number from 0 to 1 mapping the relative healths.
board ()
Attempts to board the pilot's target. ()

Returns:

    boolean true if was able to board the target.
refuel ()
Attempts to refuel the pilot's target. ()

Returns:

    boolean true if pilot has begun refueling, false if it hasn't.
settimer (timer[, time=0])
Sets a timer. (timer, time)

Parameters:

  • timer number Timer number.
  • time number Number of seconds to set timer to. (default 0)
timeup (timer)
Checks a timer. (timer)

Parameters:

  • timer number Timer number.

Returns:

    boolean Whether time is up.
set_shoot_indicator (value)
Set the seeker shoot indicator. ()

Parameters:

  • value boolean to set the shoot indicator to.
set_shoot_indicator ()
Access the seeker shoot indicator (that is put to true each time a seeker is shot). ()

Returns:

    boolean true if the shoot_indicator is true.
distress (msg)
Sends a distress signal. ( msg )

Parameters:

  • msg string or nil Message to send or nil.
getBoss ()
Picks a pilot that will command the current pilot. ()

Returns:

    Pilot or nil
setcredits (num)
Sets the pilot_nstack credits. Only call in create(). ( num )

Parameters:

  • num number Number of credits.
messages ()
Returns and clears the pilots message queue. ()

Returns:

    {{},...} Messages.
generated by LDoc 1.4.6 Last updated 2020-11-29 22:13:27