naev 0.11.5
ai.h
1/*
2 * See Licensing and Copyright notice in naev.h
3 */
4#pragma once
5
6#include "nlua.h"
7#include "physics.h"
8
9/* Forward declaration to avoid cyclical import. */
10struct Pilot_;
11typedef struct Pilot_ Pilot;
12
13#define MIN_DIR_ERR 5.0*M_PI/180.
14#define MIN_VEL_ERR 5.0
16/* maximum number of AI timers */
17#define MAX_AI_TIMERS 2
24typedef struct Task_ {
25 struct Task_* next;
26 char *name;
27 int func;
28 int done;
30 struct Task_* subtask;
32 int dat;
33} Task;
34
40typedef struct AI_Profile_ {
41 char* name;
42 nlua_env env;
43 double control_rate;
44 int lua_mem;
50
58typedef struct AIMemory_ {
59 int mem;
61} AIMemory;
62
63/*
64 * misc
65 */
66AI_Profile* ai_getProfile( const char *name );
67
68/*
69 * init/exit
70 */
71int ai_load (void);
72void ai_exit (void);
73int nlua_loadAI( nlua_env env );
74
75/*
76 * Init, destruction.
77 */
78int ai_pinit( Pilot *p, const char *ai );
79void ai_destroy( Pilot* p );
80
81/*
82 * Task related.
83 */
84Task *ai_newtask( lua_State *L, Pilot *p, const char *func, int subtask, int pos );
85Task* ai_curTask( Pilot* pilot );
86void ai_freetask( Task* t );
87void ai_cleartasks( Pilot* p );
88
89/*
90 * Misc functions.
91 */
92void ai_attacked( Pilot* attacked, const unsigned int attacker, double dmg );
93void ai_discovered( Pilot* discovered );
94void ai_hail( Pilot* recipient );
95void ai_refuel( Pilot* refueler, unsigned int target );
96void ai_getDistress( const Pilot *p, const Pilot *distressed, const Pilot *attacker );
97void ai_think( Pilot* pilot, double dt, int dotask );
99void ai_unsetPilot( AIMemory oldmem );
100void ai_thinkSetup( double dt );
101void ai_thinkApply( Pilot *p );
102void ai_init( Pilot *p );
Task * ai_newtask(lua_State *L, Pilot *p, const char *func, int subtask, int pos)
Creates a new AI task.
Definition ai.c:1117
void ai_unsetPilot(AIMemory oldmem)
Finishes setting up a pilot.
Definition ai.c:426
void ai_thinkApply(Pilot *p)
Applies the result of thinking.
Definition ai.c:452
Task * ai_curTask(Pilot *pilot)
Gets the current running task.
Definition ai.c:383
void ai_refuel(Pilot *refueler, unsigned int target)
Has a pilot attempt to refuel the other.
Definition ai.c:1018
void ai_cleartasks(Pilot *p)
Clears the pilot's tasks.
Definition ai.c:550
void ai_freetask(Task *t)
Frees an AI task.
Definition ai.c:1175
void ai_think(Pilot *pilot, double dt, int dotask)
Heart of the AI, brains of the pilot.
Definition ai.c:797
void ai_thinkSetup(double dt)
Sets up the pilot for thinking.
Definition ai.c:438
void ai_getDistress(const Pilot *p, const Pilot *distressed, const Pilot *attacker)
Sends a distress signal to a pilot.
Definition ai.c:1049
AIMemory ai_setPilot(Pilot *p)
Sets the pilot for further AI calls.
Definition ai.c:414
void ai_attacked(Pilot *attacked, const unsigned int attacker, double dmg)
Triggers the attacked() function in the pilot's AI.
Definition ai.c:911
void ai_destroy(Pilot *p)
Destroys the ai part of the pilot.
Definition ai.c:563
void ai_hail(Pilot *recipient)
Triggers the hail() function in the pilot's AI.
Definition ai.c:983
void ai_discovered(Pilot *discovered)
Triggers the discovered() function in the pilot's AI.
Definition ai.c:948
void ai_exit(void)
Cleans up global AI.
Definition ai.c:773
void ai_init(Pilot *p)
Initializes the AI.
Definition ai.c:893
int ai_pinit(Pilot *p, const char *ai)
Initializes the pilot in the ai.
Definition ai.c:496
int ai_load(void)
Initializes the AI stuff which is basically Lua.
Definition ai.c:590
AI_Profile * ai_getProfile(const char *name)
Gets the AI_Profile by name.
Definition ai.c:761
Represents a temporary pilot memory. For use with ai_setPilot and ai_unsetPilot.
Definition ai.h:58
Pilot * p
Definition ai.h:60
int mem
Definition ai.h:59
Basic AI profile.
Definition ai.h:40
int lua_mem
Definition ai.h:44
int ref_refuel
Definition ai.h:47
nlua_env env
Definition ai.h:42
int ref_control
Definition ai.h:45
char * name
Definition ai.h:41
double control_rate
Definition ai.h:43
int ref_create
Definition ai.h:48
int ref_control_manual
Definition ai.h:46
The representation of an in-game pilot.
Definition pilot.h:217
Basic AI task.
Definition ai.h:24
int func
Definition ai.h:27
char * name
Definition ai.h:26
struct Task_ * subtask
Definition ai.h:30
struct Task_ * next
Definition ai.h:25
int done
Definition ai.h:28
int dat
Definition ai.h:32