naev 0.12.6
ai.h
1/*
2 * See Licensing and Copyright notice in naev.h
3 */
4#pragma once
5
6#include "nlua.h"
7
8/* Forward declaration to avoid cyclical import. */
9struct Pilot_;
10typedef struct Pilot_ Pilot;
11
12#define MIN_DIR_ERR 5.0 * M_PI / 180.
13#define MIN_VEL_ERR 5.0
14
15/* maximum number of AI timers */
16#define MAX_AI_TIMERS 2
17
23typedef struct Task_ {
24 struct Task_ *next;
25 char *name;
26 int func;
27 int done;
28
29 struct Task_ *subtask;
30
31 int dat;
32} Task;
33
39typedef struct AI_Profile_ {
40 char *name;
41 nlua_env env;
42 double control_rate;
43 int lua_mem;
50
59typedef struct AIMemory_ {
60 int mem;
61 Pilot *p;
62} AIMemory;
63
64/*
65 * misc
66 */
67AI_Profile *ai_getProfile( const char *name );
68
69/*
70 * init/exit
71 */
72int ai_load( void );
73void ai_exit( void );
74int nlua_loadAI( nlua_env env );
75
76/*
77 * Init, destruction.
78 */
79int ai_pinit( Pilot *p, const char *ai );
80void ai_destroy( Pilot *p );
81
82/*
83 * Task related.
84 */
85Task *ai_newtask( lua_State *L, Pilot *p, const char *func, int subtask,
86 int pos );
87Task *ai_curTask( Pilot *pilot );
88void ai_freetask( Task *t );
89void ai_cleartasks( Pilot *p );
90
91/*
92 * Misc functions.
93 */
94void ai_attacked( Pilot *attacked, const unsigned int attacker, double dmg );
95void ai_discovered( Pilot *discovered );
96void ai_hail( Pilot *recipient );
97void ai_refuel( Pilot *refueler, unsigned int target );
98void ai_getDistress( const Pilot *p, const Pilot *distressed,
99 const Pilot *attacker );
100void ai_think( Pilot *pilot, double dt, int dotask );
102void ai_unsetPilot( AIMemory oldmem );
103void ai_thinkSetup( double dt );
104void ai_thinkApply( Pilot *p );
105void 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:1169
void ai_unsetPilot(AIMemory oldmem)
Finishes setting up a pilot.
Definition ai.c:428
void ai_thinkApply(Pilot *p)
Applies the result of thinking.
Definition ai.c:454
Task * ai_curTask(Pilot *pilot)
Gets the current running task.
Definition ai.c:385
void ai_refuel(Pilot *refueler, unsigned int target)
Has a pilot attempt to refuel the other.
Definition ai.c:1061
void ai_cleartasks(Pilot *p)
Clears the pilot's tasks.
Definition ai.c:548
void ai_freetask(Task *t)
Frees an AI task.
Definition ai.c:1231
void ai_think(Pilot *pilot, double dt, int dotask)
Heart of the AI, brains of the pilot.
Definition ai.c:812
void ai_thinkSetup(double dt)
Sets up the pilot for thinking.
Definition ai.c:440
void ai_getDistress(const Pilot *p, const Pilot *distressed, const Pilot *attacker)
Sends a distress signal to a pilot.
Definition ai.c:1094
AIMemory ai_setPilot(Pilot *p)
Sets the pilot for further AI calls.
Definition ai.c:416
void ai_attacked(Pilot *attacked, const unsigned int attacker, double dmg)
Triggers the attacked() function in the pilot's AI.
Definition ai.c:951
void ai_destroy(Pilot *p)
Destroys the ai part of the pilot.
Definition ai.c:561
void ai_hail(Pilot *recipient)
Triggers the hail() function in the pilot's AI.
Definition ai.c:1025
void ai_discovered(Pilot *discovered)
Triggers the discovered() function in the pilot's AI.
Definition ai.c:989
void ai_exit(void)
Cleans up global AI.
Definition ai.c:788
void ai_init(Pilot *p)
Initializes the AI.
Definition ai.c:929
int ai_pinit(Pilot *p, const char *ai)
Initializes the pilot in the ai.
Definition ai.c:494
int ai_load(void)
Initializes the AI stuff which is basically Lua.
Definition ai.c:589
AI_Profile * ai_getProfile(const char *name)
Gets the AI_Profile by name.
Definition ai.c:775
Represents a temporary pilot memory. For use with ai_setPilot and ai_unsetPilot.
Definition ai.h:59
Pilot * p
Definition ai.h:61
int mem
Definition ai.h:60
Basic AI profile.
Definition ai.h:39
int lua_mem
Definition ai.h:43
int ref_refuel
Definition ai.h:46
nlua_env env
Definition ai.h:41
int ref_control
Definition ai.h:44
char * name
Definition ai.h:40
double control_rate
Definition ai.h:42
int ref_create
Definition ai.h:47
int ref_control_manual
Definition ai.h:45
The representation of an in-game pilot.
Definition pilot.h:263
Basic AI task.
Definition ai.h:23
int func
Definition ai.h:26
char * name
Definition ai.h:25
struct Task_ * subtask
Definition ai.h:29
struct Task_ * next
Definition ai.h:24
int done
Definition ai.h:27
int dat
Definition ai.h:31