|
| static void | ai_run (nlua_env env, int nargs) |
| | Attempts to run a function.
|
| static int | ai_loadProfile (AI_Profile *prof, const char *filename) |
| | Initializes an AI_Profile and adds it to the stack.
|
| static int | ai_setMemory (void) |
| | Sets the cur_pilot's ai.
|
| static void | ai_create (Pilot *pilot) |
| | Runs the create() function in the pilot.
|
| static int | ai_loadEquip (void) |
| | Loads the equipment selector script.
|
| static int | ai_sort (const void *p1, const void *p2) |
| static void | ai_taskGC (Pilot *pilot) |
| | Runs the garbage collector on the pilot's tasks.
|
| static Task * | ai_createTask (lua_State *L, int subtask) |
| | Creates a new task based on stack information.
|
| static int | ai_tasktarget (lua_State *L, const Task *t) |
| | Pushes a task target.
|
| static int | aiL_pushtask (lua_State *L) |
| | Pushes a task onto the pilot's task list. Lua function parameter: string func Name of function to call for task. Lua function parameter:[opt] data Data to pass to the function. Supports any lua type.
|
| static int | aiL_poptask (lua_State *L) |
| | Pops the current running task.
|
| static int | aiL_taskname (lua_State *L) |
| | Gets the current task's name. Lua return parameter: string The current task name or nil if there are no tasks.
|
| static int | aiL_taskdata (lua_State *L) |
| | Gets the pilot's task data. Lua return parameter: The pilot's task data or nil if there is no task data. See also: pushtask.
|
| static int | aiL_pushsubtask (lua_State *L) |
| | Pushes a subtask onto the pilot's task's subtask list. Lua function parameter: string func Name of function to call for task. Lua function parameter:[opt] data Data to pass to the function. Supports any lua type.
|
| static int | aiL_popsubtask (lua_State *L) |
| | Pops the current running task.
|
| static int | aiL_subtaskname (lua_State *L) |
| | Gets the current subtask's name. Lua return parameter: string The current subtask name or nil if there are no subtasks.
|
| static int | aiL_subtaskdata (lua_State *L) |
| | Gets the pilot's subtask target. Lua return parameter: The pilot's target ship identifier or nil if no target. See also: pushsubtask.
|
| static int | aiL_pilot (lua_State *L) |
| | Gets the AI's pilot. Lua return parameter: Pilot The AI's pilot.
|
| static int | aiL_getrndpilot (lua_State *L) |
| | Gets a random pilot in the system. Lua return parameter: Pilot|nil.
|
| static int | aiL_getnearestpilot (lua_State *L) |
| | gets the nearest pilot to the current pilot
|
| static int | aiL_getdistance (lua_State *L) |
| | Gets the distance from the pointer.
|
| static int | aiL_getdistance2 (lua_State *L) |
| | Gets the squared distance from the pointer.
|
| static int | aiL_getflybydistance (lua_State *L) |
| | Gets the distance from the pointer perpendicular to the current pilot's flight vector.
|
| static int | aiL_minbrakedist (lua_State *L) |
| | Gets the minimum braking distance.
|
| static int | aiL_isbribed (lua_State *L) |
| | Checks to see if target has bribed pilot.
|
| static int | aiL_getGatherable (lua_State *L) |
| | Gets the closest gatherable within a radius.
|
| static int | aiL_instantJump (lua_State *L) |
| | Checks to see if pilot can instant jump.
|
| static int | aiL_ismaxvel (lua_State *L) |
| | Checks to see if pilot is at maximum velocity.
|
| static int | aiL_isstopped (lua_State *L) |
| | Checks to see if pilot is stopped.
|
| static int | aiL_isenemy (lua_State *L) |
| | Checks to see if target is an enemy.
|
| static int | aiL_isally (lua_State *L) |
| | Checks to see if target is an ally.
|
| static int | aiL_haslockon (lua_State *L) |
| | Checks to see if pilot has a missile lockon.
|
| static int | aiL_hasprojectile (lua_State *L) |
| | Checks to see if pilot has a projectile after him.
|
| static int | aiL_scandone (lua_State *L) |
| | Checks to see if pilot has finished scanning their target.
|
| static int | aiL_accel (lua_State *L) |
| | Starts accelerating the pilot.
|
| static int | aiL_turn (lua_State *L) |
| | Starts turning the pilot.
|
| static int | aiL_careful_face (lua_State *L) |
| | Gives the direction to follow in order to reach the target while minimizating risk.
|
| static int | aiL_aim (lua_State *L) |
| | Aims at a pilot, trying to hit it rather than move to it.
|
| static int | aiL_dir (lua_State *L) |
| | calculates the direction that the target is relative to the current pilot facing.
|
| static int | aiL_face (lua_State *L) |
| | Faces the target.
|
| static int | aiL_iface (lua_State *L) |
| | Maintains an intercept pursuit course.
|
| static int | aiL_idir (lua_State *L) |
| | Calculates angle between pilot facing and intercept-course to target.
|
| static int | aiL_follow_accurate (lua_State *L) |
| | Computes the point to face in order to follow another pilot using a PD controller.
|
| static int | aiL_face_accurate (lua_State *L) |
| | Computes the point to face in order to follow a moving object.
|
| static int | aiL_drift_facing (lua_State *L) |
| | Calculate the offset between the pilot's current direction of travel and the pilot's current facing.
|
| static int | aiL_brake (lua_State *L) |
| | Brakes the pilot.
|
| static int | aiL_getnearestspob (lua_State *L) |
| | Get the nearest friendly spob to the pilot.
|
| static int | aiL_getspobfrompos (lua_State *L) |
| | Get the nearest friendly spob to a given position.
|
| static int | aiL_getrndspob (lua_State *L) |
| | Get a random spob.
|
| static int | aiL_getlandspob (lua_State *L) |
| | Get a random friendly spob.
|
| static int | aiL_land (lua_State *L) |
| | Lands on a spob.
|
| static int | aiL_stop (lua_State *L) |
| | Completely stops the pilot if it is below minimum vel error (no insta-stops).
|
| static int | aiL_relvel (lua_State *L) |
| | Gets the relative velocity of a pilot.
|
| static int | aiL_sethyptarget (lua_State *L) |
| | Sets hyperspace target.
|
| static int | aiL_nearhyptarget (lua_State *L) |
| | Gets the nearest hyperspace target.
|
| static int | aiL_rndhyptarget (lua_State *L) |
| | Gets a random hyperspace target.
|
| static int | aiL_hyperspace (lua_State *L) |
| | Tries to enter hyperspace.
|
| static int | aiL_canHyperspace (lua_State *L) |
| | Gets whether or not the pilot can hyperspace.
|
| static int | aiL_hyperspaceAbort (lua_State *L) |
| | Has the AI abandon hyperspace if applicable.
|
| static int | aiL_dock (lua_State *L) |
| | Docks the ship.
|
| static int | aiL_combat (lua_State *L) |
| | Sets the combat flag.
|
| static int | aiL_settarget (lua_State *L) |
| | Sets the pilot's target.
|
| static int | aiL_weapSet (lua_State *L) |
| | Sets the active weapon set, fires another weapon set or activate an outfit.
|
| static int | aiL_hascannons (lua_State *L) |
| | Does the pilot have cannons?
|
| static int | aiL_hasturrets (lua_State *L) |
| | Does the pilot have turrets?
|
| static int | aiL_hasfighterbays (lua_State *L) |
| | Does the pilot have fighter bays?
|
| static int | aiL_hasafterburner (lua_State *L) |
| | Does the pilot have afterburners?
|
| static int | aiL_getenemy (lua_State *L) |
| | Gets the nearest enemy.
|
| static int | aiL_hostile (lua_State *L) |
| | Sets the enemy hostile (basically notifies of an impending attack).
|
| static int | aiL_getweaprangemin (lua_State *L) |
| | Gets the minimum range of a weapon set.
|
| static int | aiL_getweaprange (lua_State *L) |
| | Gets the range of a weapon set.
|
| static int | aiL_getweapspeed (lua_State *L) |
| | Gets the speed of a weapon.
|
| static int | aiL_getweapammo (lua_State *L) |
| | Gets the ammo of a weapon.
|
| static int | aiL_canboard (lua_State *L) |
| | Checks to see if pilot can board the target.
|
| static int | aiL_relsize (lua_State *L) |
| | Gets the relative size (ship mass) between the current pilot and the specified target.
|
| static int | aiL_reldps (lua_State *L) |
| | Gets the relative damage output (total DPS) between the current pilot and the specified target.
|
| static int | aiL_relhp (lua_State *L) |
| | Gets the relative health (total shields and armour) between the current pilot and the specified target.
|
| static int | aiL_settimer (lua_State *L) |
| | Sets a timer.
|
| static int | aiL_timeup (lua_State *L) |
| | Checks a timer.
|
| static int | aiL_distress (lua_State *L) |
| | Sends a distress signal.
|
| static int | aiL_getBoss (lua_State *L) |
| | Picks a pilot that will command the current pilot.
|
| static int | aiL_credits (lua_State *L) |
| | Sets the pilots credits. Only call in create().
|
| static int | aiL_board (lua_State *L) |
| | Attempts to board the pilot's target.
|
| static int | aiL_refuel (lua_State *L) |
| | Attempts to refuel the pilot's target.
|
| static int | aiL_messages (lua_State *L) |
| | Returns and clears the pilots message queue.
|
| static int | aiL_setasterotarget (lua_State *L) |
| | Sets the pilot's asteroid target.
|
| static int | aiL_gatherablePos (lua_State *L) |
| | Gets the pos and vel of a given gatherable.
|
| static int | aiL_shoot_indicator (lua_State *L) |
| | Access the seeker shoot indicator (that is put to true each time a seeker is shot).
|
| static int | aiL_set_shoot_indicator (lua_State *L) |
| | Set the seeker shoot indicator.
|
| static int | aiL_stealth (lua_State *L) |
| | Tries to stealth or destealth the pilot.
|
| static int | aiL_outfitOffAll (lua_State *L) |
| | Tries to turn off all outfits.
|
| Task * | ai_curTask (Pilot *pilot) |
| | Gets the current running task.
|
| AIMemory | ai_setPilot (Pilot *p) |
| | Sets the pilot for further AI calls.
|
| void | ai_unsetPilot (AIMemory oldmem) |
| | Finishes setting up a pilot.
|
| void | ai_thinkSetup (double dt) |
| | Sets up the pilot for thinking.
|
| void | ai_thinkApply (Pilot *p) |
| | Applies the result of thinking.
|
| int | ai_pinit (Pilot *p, const char *ai) |
| | Initializes the pilot in the ai.
|
| void | ai_cleartasks (Pilot *p) |
| | Clears the pilot's tasks.
|
| void | ai_destroy (Pilot *p) |
| | Destroys the ai part of the pilot.
|
| int | ai_load (void) |
| | Initializes the AI stuff which is basically Lua.
|
| int | nlua_loadAI (nlua_env env) |
| AI_Profile * | ai_getProfile (const char *name) |
| | Gets the AI_Profile by name.
|
| void | ai_exit (void) |
| | Cleans up global AI.
|
| void | ai_think (Pilot *pilot, double dt, int dotask) |
| | Heart of the AI, brains of the pilot.
|
| void | ai_init (Pilot *p) |
| | Initializes the AI.
|
| void | ai_attacked (Pilot *attacked, const unsigned int attacker, double dmg) |
| | Triggers the attacked() function in the pilot's AI.
|
| void | ai_discovered (Pilot *discovered) |
| | Triggers the discovered() function in the pilot's AI.
|
| void | ai_hail (Pilot *recipient) |
| | Triggers the hail() function in the pilot's AI.
|
| void | ai_refuel (Pilot *refueler, unsigned int target) |
| | Has a pilot attempt to refuel the other.
|
| void | ai_getDistress (const Pilot *p, const Pilot *distressed, const Pilot *attacker) |
| | Sends a distress signal to a pilot.
|
| Task * | ai_newtask (lua_State *L, Pilot *p, const char *func, int subtask, int pos) |
| | Creates a new AI task.
|
| void | ai_freetask (Task *t) |
| | Frees an AI task.
|
Controls the Pilot AI.
Lua module: ai
AI Overview
Concept: Goal (Task) Based AI with additional Optimization
AI uses the goal (task) based AI approach with tasks scripted in Lua, additionally there is a task that is hard-coded and obligatory in any AI script, the 'control' task, whose sole purpose is to assign tasks if there is no current tasks and optimizes or changes tasks if there are.
For example: Pilot A is attacking Pilot B. Say that Pilot C then comes in the same system and is of the same faction as Pilot B, and therefore attacks Pilot A. Pilot A would keep on fighting Pilot B until the control task kicks in. Then he/she could run if it deems that Pilot C and Pilot B together are too strong for him/her, or attack Pilot C because it's an easier target to finish off then Pilot B. Therefore there are endless possibilities and it's up to the AI coder to set up.
Specification
- AI will follow basic tasks defined from Lua AI script.
- if Task is NULL, AI will run "control" task
- Task is continued every frame
- Tasks can have subtasks which will be closed when parent task is dead.
- "control" task is a special task that MUST exist in any given Pilot AI (missiles and such will use "seek")
- "control" task is not permanent, but transitory
- "control" task sets another task
- "control" task is also run at a set rate (depending on Lua global "control_rate") to choose optimal behaviour (task)
Memory
The AI currently has per-pilot memory which is accessible as "mem". This memory is actually stored in the table pilotmem[cur_pilot->id]. This allows the pilot to keep some memory always accessible between runs without having to rely on the storage space a task has.
Garbage Collector
The tasks are not deleted directly but are marked for deletion and are then cleaned up in a garbage collector. This is to avoid accessing invalid task memory.
- Note
- Nothing in this file can be considered reentrant. Plan accordingly.
- Todo
- Clean up most of the code, it was written as one of the first subsystems and is pretty lacking in quite a few aspects.
Definition in file ai.c.