1 /*
2  * See Licensing and Copyright notice in naev.h
3  */
4 
5 
6 #ifndef PILOT_H
7 #  define PILOT_H
8 
9 
10 #include "physics.h"
11 #include "ship.h"
12 #include "ai.h"
13 #include "outfit.h"
14 #include "faction.h"
15 #include "sound.h"
16 #include "economy.h"
17 #include "ntime.h"
18 
19 
20 #define PLAYER_ID       1 /**< Player pilot ID. */
21 
22 
23 /* Hyperspace parameters. */
24 #define HYPERSPACE_ENGINE_DELAY  3. /**< Time to warm up engine (seconds). */
25 #define HYPERSPACE_FLY_DELAY     5. /**< Time it takes to hyperspace (seconds). */
26 #define HYPERSPACE_STARS_BLUR    3. /**< How long it takes for stars to start blurring (seconds). */
27 #define HYPERSPACE_STARS_LENGTH  250 /**< Length the stars blur to at max (pixels). */
28 #define HYPERSPACE_FADEOUT       1. /**< How long the fade is (seconds). */
29 #define HYPERSPACE_THRUST        2000./**< How much thrust you use in hyperspace. */
30 #define HYPERSPACE_VEL           2 * HYPERSPACE_THRUST*HYPERSPACE_FLY_DELAY /**< Velocity at hyperspace. */
31 #define HYPERSPACE_ENTER_MIN     HYPERSPACE_VEL*0.3 /**< Minimum entering distance. */
32 #define HYPERSPACE_ENTER_MAX     HYPERSPACE_VEL*0.4 /**< Maximum entering distance. */
33 #define HYPERSPACE_EXIT_MIN      1500. /**< Minimum distance to begin jumping. */
34 /* Land/takeoff. */
35 #define PILOT_LANDING_DELAY      2. /**< Delay for land animation. */
36 #define PILOT_TAKEOFF_DELAY      2. /**< Delay for takeoff animation. */
37 /* Refueling. */
38 #define PILOT_REFUEL_TIME        3. /**< Time to complete refueling. */
39 #define PILOT_REFUEL_QUANTITY    100. /**< Amount transferred per refuel. */
40 #define PILOT_REFUEL_RATE        PILOT_REFUEL_QUANTITY/PILOT_REFUEL_TIME /**< Fuel per second. */
41 /* Misc. */
42 #define PILOT_SIZE_APROX         0.8   /**< approximation for pilot size */
43 #define PILOT_WEAPON_SETS        10    /**< Number of weapon sets the pilot has. */
44 #define PILOT_WEAPSET_MAX_LEVELS 2     /**< Maximum amount of weapon levels. */
45 #define PILOT_REVERSE_THRUST     0.4   /**< Ratio of normal thrust to apply when reversing. */
46 
47 
48 /* hooks */
49 enum {
50    PILOT_HOOK_NONE,      /**< No hook. */
51    PILOT_HOOK_DEATH,     /**< Pilot died. */
52    PILOT_HOOK_BOARDING,  /**< Pilot is boarding. */
53    PILOT_HOOK_BOARD,     /**< Pilot got boarded. */
54    PILOT_HOOK_DISABLE,   /**< Pilot got disabled. */
55    PILOT_HOOK_UNDISABLE, /**< Pilot recovered from being disabled. */
56    PILOT_HOOK_JUMP,      /**< Pilot jumped. */
57    PILOT_HOOK_HAIL,      /**< Pilot is hailed. */
58    PILOT_HOOK_LAND,      /**< Pilot is landing. */
59    PILOT_HOOK_ATTACKED,  /**< Pilot is in manual override and is being attacked. */
60    PILOT_HOOK_IDLE,      /**< Pilot is in manual override and has just become idle. */
61    PILOT_HOOK_EXPLODED,  /**< Pilot died and exploded (about to be removed). */
62    PILOT_HOOK_LOCKON     /**< Pilot had a launcher lockon. */
63 };
64 
65 
66 /* damage */
67 #define PILOT_HOSTILE_THRESHOLD  0.09 /**< Point at which pilot becomes hostile. */
68 #define PILOT_HOSTILE_DECAY      0.005 /**< Rate at which hostility decays. */
69 
70 
71 /* flags */
72 #define pilot_clearFlagsRaw(a) memset((a), 0, PILOT_FLAGS_MAX) /**< Clears the pilot flags. */
73 #define pilot_copyFlagsRaw(d,s) memcpy((d), (s), PILOT_FLAGS_MAX) /**< Copies the pilot flags from s to d. */
74 #define pilot_isFlagRaw(a,f)  ((a)[f]) /**< Checks to see if a pilot flag is set. */
75 #define pilot_setFlagRaw(a,f) ((a)[f] = 1) /**< Sets flags rawly. */
76 #define pilot_isFlag(p,f)     ((p)->flags[f]) /**< Checks if flag f is set on pilot p. */
77 #define pilot_setFlag(p,f)    ((p)->flags[f] = 1) /**< Sets flag f on pilot p. */
78 #define pilot_rmFlag(p,f)     ((p)->flags[f] = 0) /**< Removes flag f on pilot p. */
79 enum {
80    /* creation */
81    PILOT_PLAYER,       /**< Pilot is a player. */
82    PILOT_CARRIED,      /**< Pilot usually resides in a fighter bay. */
83    PILOT_CREATED_AI,   /** Pilot has already created AI. */
84    PILOT_EMPTY,        /**< Do not add pilot to stack. */
85    PILOT_NO_OUTFITS,   /**< Do not create the pilot with outfits. */
86    /* dynamic */
87    PILOT_HAILING,      /**< Pilot is hailing the player. */
88    PILOT_NODISABLE,    /**< Pilot can't be disabled. */
89    PILOT_INVINCIBLE,   /**< Pilot can't be hit ever. */
90    PILOT_HOSTILE,      /**< Pilot is hostile to the player. */
91    PILOT_FRIENDLY,     /**< Pilot is friendly to the player. */
92    PILOT_COMBAT,       /**< Pilot is engaged in combat. */
93    PILOT_AFTERBURNER,  /**< Pilot has their afterburner activated. */
94    PILOT_HYP_PREP,     /**< Pilot is getting ready for hyperspace. */
95    PILOT_HYP_BRAKE,    /**< PIlot has already braked before jumping. */
96    PILOT_HYP_BEGIN,    /**< Pilot is starting engines. */
97    PILOT_HYPERSPACE,   /**< Pilot is in hyperspace. */
98    PILOT_HYP_END,      /**< Pilot is exiting hyperspace. */
99    PILOT_BOARDED,      /**< Pilot has been boarded already. */
100    PILOT_NOBOARD,      /**< Pilot can't be boarded. */
101    PILOT_BOARDING,     /**< Pilot is currently boarding it's target. */
102    PILOT_BRIBED,       /**< Pilot has been bribed already. */
103    PILOT_DISTRESSED,   /**< Pilot has distressed once already. */
104    PILOT_REFUELING,    /**< Pilot is trying to refueling. */
105    PILOT_REFUELBOARDING, /**< Pilot is actively refueling. */
106    PILOT_MANUAL_CONTROL, /**< Pilot is under manual control of a mission or event. */
107    PILOT_LANDING,      /**< Pilot is landing. */
108    PILOT_TAKEOFF,      /**< Pilot is taking off. */
109    PILOT_DISABLED,     /**< Pilot is disabled. */
110    PILOT_DISABLED_PERM, /**< Pilot is permanently disabled. */
111    PILOT_DEAD,         /**< Pilot is in it's dying throes */
112    PILOT_DEATH_SOUND,  /**< Pilot just did death explosion. */
113    PILOT_EXPLODED,     /**< Pilot did final death explosion. */
114    PILOT_DELETE,       /**< Pilot will get deleted asap. */
115    PILOT_VISPLAYER,    /**< Pilot is always visible to the player (only player). */
116    PILOT_VISIBLE,      /**< Pilot is always visible to other pilots. */
117    PILOT_HILIGHT,      /**< Pilot is hilighted when visible (this does not increase visibility). */
118    PILOT_INVISIBLE,    /**< Pilot is invisible to other pilots. */
119    PILOT_BOARDABLE,    /**< Pilot can be boarded even while active. */
120    PILOT_NOJUMP,       /**< Pilot cannot engage hyperspace engines. */
121    PILOT_NOLAND,       /**< Pilot cannot land on stations or planets. */
122    PILOT_NODEATH,      /**< Pilot can not die, will stay at 1 armour. */
123    PILOT_INVINC_PLAYER, /**< Pilot can not be hurt by the player. */
124    PILOT_COOLDOWN,     /**< Pilot is in active cooldown mode. */
125    PILOT_COOLDOWN_BRAKE, /**< Pilot is braking to enter active cooldown mode. */
126    PILOT_BRAKING,      /**< Pilot is braking. */
127    PILOT_HASSPEEDLIMIT, /**< Speed limiting is activated for Pilot.*/
128    PILOT_FLAGS_MAX     /**< Maximum number of flags. */
129 };
130 typedef char PilotFlags[ PILOT_FLAGS_MAX ];
131 
132 /* makes life easier */
133 #define pilot_isPlayer(p)   pilot_isFlag(p,PILOT_PLAYER) /**< Checks if pilot is a player. */
134 #define pilot_isDisabled(p) pilot_isFlag(p,PILOT_DISABLED) /**< Checks if pilot is disabled. */
135 #define pilot_isStopped(p)  (VMOD(p->solid->vel) <= MIN_VEL_ERR)
136 
137 
138 /**
139  * @brief Contains the state of the outfit.
140  *
141  * Currently only applicable to beam weapons.
142  */
143 typedef enum PilotOutfitState_ {
144    PILOT_OUTFIT_OFF,    /**< Normal state. */
145    PILOT_OUTFIT_WARMUP, /**< Outfit is starting to warm up. */
146    PILOT_OUTFIT_ON,     /**< Outfit is activated and running. */
147    PILOT_OUTFIT_COOLDOWN /**< Outfit is cooling down. */
148 } PilotOutfitState;
149 
150 
151 /**
152  * @brief Stores outfit ammo.
153  */
154 typedef struct PilotOutfitAmmo_ {
155    Outfit *outfit;      /**< Type of ammo. */
156    int quantity;        /**< Amount of ammo. */
157    int deployed;        /**< For fighter bays. */
158    double lockon_timer; /**< Locking on timer. */
159    int in_arc;          /**< In arc. */
160 } PilotOutfitAmmo;
161 
162 
163 /**
164  * @brief Stores an outfit the pilot has.
165  */
166 typedef struct PilotOutfitSlot_ {
167    int id;           /**< Position in the global slot list. */
168 
169    /* Outfit slot properties. */
170    Outfit* outfit;   /**< Associated outfit. */
171    int active;       /**< Slot is an active slot. */
172    ShipOutfitSlot *sslot; /**< Ship outfit slot. */
173 
174    /* Heat. */
175    double heat_T;    /**< Slot temperature. [K] */
176    double heat_C;    /**< Slot heat capacity. [W/K] */
177    double heat_area; /**< Slot area of contact with ship hull. [m^2] */
178    double heat_start; /**< Slot heat at the beginning of a cooldown period. */
179 
180    /* Current state. */
181    PilotOutfitState state; /**< State of the outfit. */
182    double stimer;    /**< State timer, tracking current state. */
183    double timer;     /**< Used to store when it was last used. */
184    int level;        /**< Level in current weapon set (-1 is none). */
185    int weapset;      /**< First weapon set that uses the outfit (-1 is none). */
186 
187    /* Type-specific data. */
188    union {
189       unsigned int beamid;    /**< ID of the beam used in this outfit, only used for beams. */
190       PilotOutfitAmmo ammo;   /**< Ammo for launchers. */
191    } u; /**< Stores type specific data. */
192 } PilotOutfitSlot;
193 
194 
195 /**
196  * @brief A pilot Weapon Set Outfit.
197  */
198 typedef struct PilotWeaponSetOutfit_ {
199    int level;              /**< Level of trigger. */
200    double range2;          /**< Range squared of this specific outfit. */
201    PilotOutfitSlot *slot;  /**< Slot associated with it. */
202 } PilotWeaponSetOutfit;
203 
204 
205 /**
206  * @brief A weapon set represents a set of weapons that have an action.
207  *
208  * By default a weapon set indicates what weapons are enabled at a given time.
209  *  However they can also be used to launch weapons.
210  */
211 typedef struct PilotWeaponSet_ {
212    int type;      /**< Type of the weaponset. */
213    int active;    /**< Whether or not it's currently firing. */
214    PilotWeaponSetOutfit *slots; /**< Slots involved with the weapon set. */
215    /* Only applicable to weapon type. */
216    int inrange;   /**< Whether or not to fire only if the target is inrange. */
217    double range[PILOT_WEAPSET_MAX_LEVELS]; /**< Range of the levels in the outfit slot. */
218    double speed[PILOT_WEAPSET_MAX_LEVELS]; /**< Speed of the levels in the outfit slot. */
219 } PilotWeaponSet;
220 
221 
222 /**
223  * @brief Stores a pilot commodity.
224  */
225 typedef struct PilotCommodity_ {
226    Commodity* commodity;   /**< Associated commodity. */
227    int quantity;           /**< Amount player has. */
228    unsigned int id;        /**< Special mission id for cargo, 0 means none. */
229 } PilotCommodity;
230 
231 
232 /**
233  * @brief A wrapper for pilot hooks.
234  */
235 typedef struct PilotHook_ {
236    int type;         /**< Type of hook. */
237    unsigned int id;  /**< Hook ID associated with pilot hook. */
238 } PilotHook;
239 
240 
241 /**
242  * @brief Different types of escorts.
243  */
244 typedef enum EscortType_e {
245    ESCORT_TYPE_NULL,       /**< Invalid escort type. */
246    ESCORT_TYPE_BAY,        /**< Escort is from a fighter bay, controllable by it's parent and can dock. */
247    ESCORT_TYPE_MERCENARY,  /**< Escort is a mercenary, controllable by it's parent. */
248    ESCORT_TYPE_ALLY        /**< Escort is an ally, uncontrollable. */
249 } EscortType_t;
250 
251 
252 /**
253  * @brief Stores an escort.
254  */
255 typedef struct Escort_s {
256    char *ship;          /**< Type of the ship escort is flying. */
257    EscortType_t type;   /**< Type of escort. */
258    unsigned int id;     /**< ID of in-game pilot. */
259    /* TODO: something better than this */
260    int persist;         /**< True if escort should respawn on takeoff/landing */
261 } Escort_t;
262 
263 
264 /**
265  * @brief The representation of an in-game pilot.
266  */
267 typedef struct Pilot_ {
268 
269    unsigned int id;  /**< pilot's id, used for many functions */
270    char* name;       /**< pilot's name (if unique) */
271    char* title;      /**< title - usually indicating special properties - @todo use */
272 
273    /* Fleet/faction management. */
274    int faction;      /**< Pilot's faction. */
275    int presence;     /**< Presence being used by the pilot. */
276 
277    /* Object characteristics */
278    Ship* ship;       /**< ship pilot is flying */
279    Solid* solid;     /**< associated solid (physics) */
280    double base_mass; /**< Ship mass plus core outfit mass. */
281    double mass_cargo; /**< Amount of cargo mass added. */
282    double mass_outfit; /**< Amount of outfit mass added. */
283    int tsx;          /**< current sprite x position, calculated on update. */
284    int tsy;          /**< current sprite y position, calculated on update. */
285 
286    /* Properties. */
287    int cpu;       /**< Amount of CPU the pilot has left. */
288    int cpu_max;   /**< Maximum amount of CPU the pilot has. */
289    double crew;      /**< Crew amount the player has (display it as (int)floor(), but it's analogue. */
290    double cap_cargo; /**< Pilot's cargo capacity. */
291 
292    /* Movement */
293    double thrust;    /**< Pilot's thrust in px/s^2. */
294    double thrust_base; /**< Pilot's base thrust in px/s^2 (not modulated by mass). */
295    double speed;     /**< Pilot's speed in px/s. */
296    double speed_base; /**< Pilot's base speed in px/s (not modulated by mass). */
297    double speed_limit; /**< Pilot's maximum speed in px/s if limited by lua call. */
298    double turn;      /**< Pilot's turn in rad/s. */
299    double turn_base; /**< Pilot's base turn in rad/s (not modulated by mass). */
300 
301    /* Current health */
302    double armour;    /**< Current armour. */
303    double stress;    /**< Current disable damage level. */
304    double shield;    /**< Current shield. */
305    double fuel;      /**< Current fuel. */
306    double fuel_consumption; /**< Fuel consumed per jump. */
307    double armour_max; /**< Maximum armour. */
308    double shield_max; /**< Maximum shield. */
309    double fuel_max;  /**< Maximum fuel. */
310    double armour_regen; /**< Armour regeneration rate (per second). */
311    double shield_regen; /**< Shield regeneration rate (per second). */
312    double dmg_absorb; /**< Ship damage absorption [0:1] with 1 being 100%. */
313 
314    /* Energy is handled a bit differently. */
315    double energy;    /**< Current energy. */
316    double energy_max; /**< Maximum energy. */
317    double energy_regen; /**< Energy regeneration rate (per second). */
318    double energy_tau; /**< Tau regeneration rate for energy. */
319    double energy_loss; /**< Linear loss that bypasses the actual RC circuit stuff. */
320 
321    /* Electronic warfare. */
322    double ew_base_hide; /**< Base static hide factor. */
323    double ew_mass;   /**< Mass factor. */
324    double ew_heat;   /**< Heat factor, affects hide. */
325    double ew_asteroid;   /**< Asteroid field factor, affects hide. */
326    double ew_hide;   /**< Static hide factor. */
327    double ew_movement; /**< Movement factor. */
328    double ew_evasion; /**< Dynamic evasion factor. */
329    double ew_detect; /**< Static detection factor. */
330    double ew_jump_detect; /** Static jump detection factor */
331 
332    /* Heat. */
333    double heat_T;    /**< Ship temperature. [K] */
334    double heat_C;    /**< Heat capacity of the ship. [W/K] */
335    double heat_emis; /**< Ship epsilon parameter (emissivity). [adimensional 0:1] */
336    double heat_cond; /**< Ship conductivity parameter. [W/(m*K)] */
337    double heat_area; /**< Effective heatsink area of the ship. [m^2] */
338    double cdelay;    /**< Duration a full active cooldown takes. */
339    double ctimer;    /**< Remaining cooldown time. */
340    double heat_start; /**< Temperature at the start of a cooldown. */
341 
342    /* Ship statistics. */
343    ShipStats stats;  /**< Pilot's copy of ship statistics. */
344 
345    /* Associated functions */
346    void (*think)(struct Pilot_*, const double); /**< AI thinking for the pilot */
347    void (*update)(struct Pilot_*, const double); /**< Updates the pilot. */
348    void (*render)(struct Pilot_*, const double); /**< For rendering the pilot. */
349    void (*render_overlay)(struct Pilot_*, const double); /**< For rendering the pilot overlay. */
350 
351    /* Outfit management */
352    /* Global outfits. */
353    int noutfits;     /**< Total amount of slots. */
354    PilotOutfitSlot **outfits; /**< Total outfits. */
355    /* Per slot types. */
356    int outfit_nstructure; /**< Number of structure slots. */
357    PilotOutfitSlot *outfit_structure; /**< The structure slots. */
358    int outfit_nutility; /**< Number of utility slots. */
359    PilotOutfitSlot *outfit_utility; /**< The utility slots. */
360    int outfit_nweapon; /**< Number of weapon slots. */
361    PilotOutfitSlot *outfit_weapon; /**< The weapon slots. */
362 
363    /* Primarily for AI usage. */
364    int ncannons;      /**< Number of cannons equipped. */
365    int nturrets;      /**< Number of turrets equipped. */
366    int nbeams;        /**< Number of beams equipped. */
367    int njammers;      /**< Number of jammers equipped. */
368    int nafterburners; /**< Number of afterburners equipped. */
369 
370    /* For easier usage. */
371    PilotOutfitSlot *afterburner; /**< the afterburner */
372 
373    /* Jamming */
374    int jamming;      /**< Pilot is current jamming with at least a single jammer (used to
375                           speed up later checks in the code). */
376 
377    /* Weapon sets. */
378    PilotWeaponSet weapon_sets[PILOT_WEAPON_SETS]; /**< All the weapon sets the pilot has. */
379    int active_set;   /**< Index of the currently active weapon set. */
380    int autoweap;     /**< Automatically update weapon sets. */
381 
382    /* Cargo */
383    credits_t credits; /**< monies the pilot has */
384    PilotCommodity* commodities; /**< commodity and quantity */
385    int ncommodities; /**< number of commodities. */
386    int cargo_free;   /**< Free commodity space. */
387 
388    /* Hook attached to the pilot */
389    PilotHook *hooks; /**< Pilot hooks. */
390    int nhooks;       /**< Number of pilot hooks. */
391 
392    /* Escort stuff. */
393    unsigned int parent; /**< Pilot's parent. */
394    Escort_t *escorts; /**< Pilot's escorts. */
395    int nescorts;     /**< Number of pilot escorts. */
396 
397    /* Targeting. */
398    unsigned int target; /**< AI pilot target. */
399    int nav_planet;   /**< Planet land target. */
400    int nav_hyperspace; /**< Hyperspace target. */
401 
402    /* AI */
403    AI_Profile* ai;   /**< AI personality profile */
404    double tcontrol;  /**< timer for control tick */
405    double timer[MAX_AI_TIMERS]; /**< timers for AI */
406    Task* task;       /**< current action */
407 
408    /* Misc */
409    double comm_msgTimer; /**< Message timer for the comm. */
410    double comm_msgWidth; /**< Width of the message. */
411    char *comm_msg;   /**< Comm message to display overhead. */
412    PilotFlags flags; /**< used for AI and others */
413    double pdata;     /**< generic data for internal pilot use */
414    double ptimer;    /**< generic timer for internal pilot use */
415    double htimer;    /**< Hail animation timer. */
416    double stimer;    /**< Shield regeneration timer. */
417    double sbonus;    /**< Shield regeneration bonus. */
418    double dtimer;    /**< Disable timer. */
419    double dtimer_accum; /**< Accumulated disable timer. */
420    int hail_pos;     /**< Hail animation position. */
421    int lockons;      /**< Stores how many seeking weapons are targeting pilot */
422    int *mounted;     /**< Number of mounted outfits on the mount. */
423    double player_damage; /**< Accumulates damage done by player for hostileness.
424                               In per one of max shield + armour. */
425    double engine_glow; /**< Amount of engine glow to display. */
426    int messages;       /**< Queued messages (Lua ref). */
427 } Pilot;
428 
429 
430 #include "pilot_cargo.h"
431 #include "pilot_heat.h"
432 #include "pilot_hook.h"
433 #include "pilot_outfit.h"
434 #include "pilot_weapon.h"
435 #include "pilot_ew.h"
436 
437 
438 /*
439  * getting pilot stuff
440  */
441 Pilot** pilot_getAll( int *n );
442 Pilot* pilot_get( const unsigned int id );
443 unsigned int pilot_getNextID( const unsigned int id, int mode );
444 unsigned int pilot_getPrevID( const unsigned int id, int mode );
445 unsigned int pilot_getNearestEnemy( const Pilot* p );
446 unsigned int pilot_getNearestEnemy_size( const Pilot* p, double target_mass_LB, double target_mass_UB );
447 unsigned int pilot_getNearestEnemy_heuristic(const Pilot* p, double mass_factor, double health_factor, double damage_factor, double range_factor);
448 unsigned int pilot_getNearestHostile (void); /* only for the player */
449 unsigned int pilot_getNearestPilot( const Pilot* p );
450 unsigned int pilot_getBoss( const Pilot* p );
451 double pilot_getNearestPos( const Pilot *p, unsigned int *tp, double x, double y, int disabled );
452 double pilot_getNearestAng( const Pilot *p, unsigned int *tp, double ang, int disabled );
453 int pilot_getJumps( const Pilot* p );
454 const glColour* pilot_getColour( const Pilot* p );
455 int pilot_validTarget( const Pilot* p, const Pilot* target );
456 
457 /* non-lua wrappers */
458 double pilot_relsize( const Pilot* cur_pilot, const Pilot* p );
459 double pilot_reldps( const Pilot* cur_pilot, const Pilot* p );
460 double pilot_relhp( const Pilot* cur_pilot, const Pilot* p );
461 
462 /*
463  * Combat.
464  */
465 void pilot_setTarget( Pilot* p, unsigned int id );
466 double pilot_hit( Pilot* p, const Solid* w, const unsigned int shooter,
467       const Damage *dmg, int reset );
468 void pilot_updateDisable( Pilot* p, const unsigned int shooter );
469 void pilot_explode( double x, double y, double radius, const Damage *dmg, const Pilot *parent );
470 double pilot_face( Pilot* p, const double dir );
471 int pilot_brake( Pilot* p );
472 double pilot_brakeDist( Pilot *p, Vector2d *pos );
473 int pilot_interceptPos( Pilot *p, double x, double y );
474 void pilot_cooldown( Pilot *p );
475 void pilot_cooldownEnd( Pilot *p, const char *reason );
476 
477 
478 /* Misc. */
479 int pilot_hasCredits( Pilot *p, credits_t amount );
480 credits_t pilot_modCredits( Pilot *p, credits_t amount );
481 int pilot_refuelStart( Pilot *p );
482 void pilot_hyperspaceAbort( Pilot* p );
483 void pilot_clearTimers( Pilot *pilot );
484 int pilot_hasDeployed( Pilot *p );
485 int pilot_dock( Pilot *p, Pilot *target, int deployed );
486 ntime_t pilot_hyperspaceDelay( Pilot *p );
487 
488 
489 /*
490  * creation
491  */
492 void pilot_init( Pilot* dest, Ship* ship, const char* name, int faction, const char *ai,
493       const double dir, const Vector2d* pos, const Vector2d* vel,
494       const PilotFlags flags );
495 unsigned int pilot_create( Ship* ship, const char* name, int faction, const char *ai,
496       const double dir, const Vector2d* pos, const Vector2d* vel,
497       const PilotFlags flags );
498 Pilot* pilot_createEmpty( Ship* ship, const char* name,
499       int faction, const char *ai, PilotFlags flags );
500 Pilot* pilot_copy( Pilot* src );
501 void pilot_delete( Pilot *p );
502 
503 
504 /*
505  * init/cleanup
506  */
507 void pilot_destroy(Pilot* p);
508 void pilots_free (void);
509 void pilots_clean (void);
510 void pilots_clear (void);
511 void pilots_cleanAll (void);
512 void pilot_free( Pilot* p );
513 
514 
515 /*
516  * Movement.
517  */
518 void pilot_setThrust( Pilot *p, double thrust );
519 void pilot_setTurn( Pilot *p, double turn );
520 
521 /*
522  * update
523  */
524 void pilot_update( Pilot* pilot, const double dt );
525 void pilots_update( double dt );
526 void pilots_render( double dt );
527 void pilots_renderOverlay( double dt );
528 void pilot_render( Pilot* pilot, const double dt );
529 void pilot_renderOverlay( Pilot* p, const double dt );
530 
531 
532 /*
533  * communication
534  */
535 void pilot_message( Pilot *p, unsigned int target, const char *msg, int ignore_int );
536 void pilot_broadcast( Pilot *p, const char *msg, int ignore_int );
537 void pilot_distress( Pilot *p, Pilot *attacker, const char *msg, int ignore_int );
538 
539 
540 /*
541  * faction
542  */
543 void pilot_setHostile( Pilot *p );
544 void pilot_rmHostile( Pilot *p );
545 void pilot_setFriendly( Pilot *p );
546 void pilot_rmFriendly( Pilot *p );
547 int pilot_isHostile( const Pilot *p );
548 int pilot_isNeutral( const Pilot *p );
549 int pilot_isFriendly( const Pilot *p );
550 char pilot_getFactionColourChar( const Pilot *p );
551 
552 
553 /*
554  * Misc details.
555  */
556 credits_t pilot_worth( const Pilot *p );
557 void pilot_msg(Pilot *p, Pilot *reciever, const char *type, unsigned int index);
558 
559 #endif /* PILOT_H */
560