naev 0.12.5
pilot.c File Reference

Handles the pilot stuff. More...

#include "pilot.h"
#include "ai.h"
#include "array.h"
#include "board.h"
#include "camera.h"
#include "damagetype.h"
#include "debris.h"
#include "debug.h"
#include "escort.h"
#include "explosion.h"
#include "faction.h"
#include "font.h"
#include "gui.h"
#include "hook.h"
#include "log.h"
#include "nlua_outfit.h"
#include "nlua_pilotoutfit.h"
#include "nlua_vec2.h"
#include "ntime.h"
#include "ntracing.h"
#include "pilot_ship.h"
#include "player.h"
#include "player_autonav.h"
#include "quadtree.h"
#include "rng.h"
#include "sound.h"
Include dependency graph for pilot.c:

Go to the source code of this file.

Macros

#define PILOT_SIZE_MIN   128

Functions

static void pilot_init (Pilot *pilot, const Ship *ship, const char *name, int faction, double dir, const vec2 *pos, const vec2 *vel, const PilotFlags flags, unsigned int dockpilot, int dockslot)
 Initialize pilot.
static void pilot_hyperspace (Pilot *p, double dt)
 Handles pilot's hyperspace states.
static void pilot_refuel (Pilot *p, double dt)
 Has the pilot refuel its target.
static void pilot_updateSolid (Pilot *p, double dt)
 Updates the pilot solid.
static void pilot_erase (Pilot *p)
 Destroys pilot from stack.
static void pilot_renderFramebufferBase (Pilot *p, GLuint fbo, double fw, double fh, const Lighting *L)
 Renders a pilot to a framebuffer without effects.
static int pilot_getStackPos (unsigned int id)
 Gets the pilot's position in the stack.
static void pilot_init_trails (Pilot *p)
 Initialize pilot's trails according to the ship type and current system characteristics.
static int pilot_trail_generated (Pilot *p, int generator)
 Return true if the given trail_emitters index has a corresponding generated trail.
static void pilot_addQuadtree (const Pilot *p, int i)
Pilot *const * pilot_getAll (void)
 Gets the pilot stack.
static int pilot_cmp (const void *ptr1, const void *ptr2)
 Compare id (for use with bsearch)
unsigned int pilot_getNextID (unsigned int id, int mode)
 Gets the next pilot based on id.
unsigned int pilot_getPrevID (unsigned int id, int mode)
 Gets the previous pilot based on ID.
int pilot_validTarget (const Pilot *p, const Pilot *target)
 Checks to see if a pilot is a valid target for another pilot.
int pilot_validTargetRange (const Pilot *p, const Pilot *target, int *inrange)
 Checks to see if a pilot is a valid target for another pilot while storing the result of pilot_inRangePilot in inrange.
int pilot_canTarget (const Pilot *p)
 Same as pilot_validTarget but without the range check.
int pilot_validEnemy (const Pilot *p, const Pilot *target)
 Checks to see if a pilot is a valid enemy for another pilot.
unsigned int pilot_getNearestEnemy (const Pilot *p)
 Gets the nearest enemy to the pilot.
unsigned int pilot_getNearestEnemy_size (const Pilot *p, double target_mass_LB, double target_mass_UB)
 Gets the nearest enemy to the pilot closest to the pilot whose mass is between LB and UB.
unsigned int pilot_getNearestEnemy_heuristic (const Pilot *p, double mass_factor, double health_factor, double damage_factor, double range_factor)
 Gets the nearest enemy to the pilot closest to the pilot whose mass is between LB and UB.
unsigned int pilot_getNearestPilot (const Pilot *p)
 Get the nearest pilot to a pilot.
unsigned int pilot_getBoss (const Pilot *p)
 Get the strongest ally in a given range.
double pilot_getNearestPosPilot (const Pilot *p, Pilot **tp, double x, double y, int disabled)
 Get the nearest pilot to a pilot from a certain position.
double pilot_getNearestPos (const Pilot *p, unsigned int *tp, double x, double y, int disabled)
 Get the nearest pilot to a pilot from a certain position.
double pilot_getNearestAng (const Pilot *p, unsigned int *tp, double ang, int disabled)
 Get the pilot closest to an angle extending from another pilot.
Pilotpilot_get (unsigned int id)
 Pulls a pilot out of the pilot_stack based on ID.
Pilotpilot_getTarget (Pilot *p)
 Gets the target of a pilot using a fancy caching system.
void pilot_setAccel (Pilot *p, double accel)
 Sets the pilot's accel.
void pilot_setTurn (Pilot *p, double turn)
 Sets the pilot's turn.
int pilot_isHostile (const Pilot *p)
 Checks to see if pilot is hostile to the player.
int pilot_isNeutral (const Pilot *p)
 Checks to see if pilot is neutral to the player.
int pilot_isFriendly (const Pilot *p)
 Checks to see if pilot is friendly to the player.
int pilot_areAllies (const Pilot *p, const Pilot *target)
 Like areAllies but for pilots.
int pilot_areEnemies (const Pilot *p, const Pilot *target)
 Like areEnemies but for pilots.
PilotOutfitSlotpilot_getDockSlot (Pilot *p)
 Gets the dock slot of the pilot.
const IntListpilot_collideQuery (int x1, int y1, int x2, int y2)
void pilot_collideQueryIL (IntList *il, int x1, int y1, int x2, int y2)
double pilot_face (Pilot *p, double dir, double dt)
 Tries to turn the pilot to face dir.
int pilot_brakeCheckReverseThrusters (const Pilot *p)
 See if the pilot wants to use their reverse thrusters to brake.
double pilot_minbrakedist (const Pilot *p, double dt, double *flytime)
 Gets the minimum braking distance for the pilot.
int pilot_brake (Pilot *p, double dt)
 Causes the pilot to turn around and brake.
void pilot_cooldown (Pilot *p, int dochecks)
 Begins active cooldown, reducing hull and outfit temperatures.
void pilot_cooldownEnd (Pilot *p, const char *reason)
 Terminates active cooldown.
double pilot_aimAngle (Pilot *p, const vec2 *pos, const vec2 *vel)
 Returns the angle for a pilot to aim at another pilot.
void pilot_setHostile (Pilot *p)
 Marks pilot as hostile to player.
char pilot_getFactionColourChar (const Pilot *p)
 Gets the faction colour char, works like faction_reputationColourChar but for a pilot.
void pilot_setCommMsg (Pilot *p, const char *s)
 Sets the overhead communication message of the pilot.
void pilot_broadcast (Pilot *p, const char *msg, int ignore_int)
 Has the pilot broadcast a message.
void pilot_distress (Pilot *p, Pilot *attacker, const char *msg)
 Has the pilot broadcast a distress signal.
void pilot_rmHostile (Pilot *p)
 Unmarks a pilot as hostile to player.
void pilot_setFriendly (Pilot *p)
 Marks pilot as friendly to player.
void pilot_rmFriendly (Pilot *p)
 Unmarks a pilot as friendly to player.
int pilot_getJumps (const Pilot *p)
 Gets the amount of jumps the pilot has left.
const glColour * pilot_getColour (const Pilot *p)
 Gets a pilot's colour.
void pilot_setTarget (Pilot *p, unsigned int id)
 Sets the target of the pilot.
double pilot_hit (Pilot *p, const Solid *w, const Pilot *pshooter, const Damage *dmg, const Outfit *outfit, int lua_mem, int reset)
 Damages the pilot.
void pilot_updateDisable (Pilot *p, unsigned int shooter)
 Handles pilot disabling. Set or unset the disable status depending on health and stress values.
void pilot_dead (Pilot *p, unsigned int killer)
 Pilot is dead, now will slowly explode.
void pilot_explode (double x, double y, double radius, const Damage *dmg, const Pilot *parent)
 Makes the pilot explosion.
void pilot_renderFramebuffer (Pilot *p, GLuint fbo, double fw, double fh, const Lighting *L)
 Renders a pilot to a framebuffer.
void pilot_render (Pilot *p)
 Renders the pilot.
void pilot_renderOverlay (Pilot *p)
 Renders the pilot overlay.
void pilot_update (Pilot *pilot, double dt)
 Updates the pilot.
void pilot_sample_trails (Pilot *p, int none)
 Updates the given pilot's trail emissions.
void pilot_delete (Pilot *p)
 Deletes a pilot.
void pilot_hyperspaceAbort (Pilot *p)
 Stops the pilot from hyperspacing.
int pilot_refuelStart (Pilot *p)
 Attempts to start refueling the pilot's target.
ntime_t pilot_hyperspaceDelay (const Pilot *p)
 Calculates the hyperspace delay for a pilot.
void pilot_untargetAsteroid (int anchor, int asteroid)
 Loops over pilot stack to remove an asteroid as target.
int pilot_numOutfit (const Pilot *p, const Outfit *o)
 Checks to see how many of an outfit a pilot has.
int pilot_hasCredits (const Pilot *p, credits_t amount)
 Checks to see if the pilot has at least a certain amount of credits.
credits_t pilot_modCredits (Pilot *p, credits_t amount)
 Modifies the amount of credits the pilot has.
void pilot_reset (Pilot *pilot)
 Resets a pilot.
Pilotpilot_create (const Ship *ship, const char *name, int faction, const char *ai, const double dir, const vec2 *pos, const vec2 *vel, const PilotFlags flags, unsigned int dockpilot, int dockslot)
 Creates a new pilot.
Pilotpilot_createEmpty (const Ship *ship, const char *name, int faction, PilotFlags flags)
 Creates a pilot without adding it to the stack.
unsigned int pilot_clone (const Pilot *ref)
 Clones an existing pilot.
unsigned int pilot_addStack (Pilot *p)
 Adds a pilot to the stack.
void pilot_clearTrails (Pilot *p)
 Resets the trails for a pilot.
Pilotpilot_setPlayer (Pilot *after)
 Replaces the player's pilot with an alternate ship with the same ID.
void pilot_choosePoint (vec2 *vp, Spob **spob, JumpPoint **jump, int lf, int ignore_rules, int guerilla)
 Finds a spawn point for a pilot.
void pilot_free (Pilot *p)
 Frees and cleans up a pilot.
void pilot_stackRemove (Pilot *p)
 Tries to remove a pilot from the stack.
void pilots_init (void)
 Initializes pilot stuff.
void pilots_free (void)
 Frees the pilot stack.
void pilots_clean (int persist)
 Cleans up the pilot stack - leaves the player.
void pilots_newSystem (void)
 Updates pilot state which depends on the system (sensor range, nebula trails...)
void pilots_clear (void)
 Clears all the pilots except the player and clear-exempt pilots.
void pilots_cleanAll (void)
 Even cleans up the player.
void pilots_updatePurge (void)
 Purges pilots set for deletion.
void pilots_update (double dt)
 Updates all the pilots.
void pilots_render (void)
 Renders all the pilots.
void pilots_renderOverlay (void)
 Renders all the pilots overlays.
void pilot_clearTimers (Pilot *pilot)
 Clears the pilot's timers.
double pilot_relsize (const Pilot *cur_pilot, const Pilot *p)
 Gets the relative size(shipmass) between the current pilot and the specified target.
void pilot_dpseps (const Pilot *p, double *pdps, double *peps)
 Calculates the dps and eps of a pilot.
double pilot_reldps (const Pilot *cur_pilot, const Pilot *p)
 Gets the relative damage output(total DPS) between the current pilot and the specified target.
double pilot_relhp (const Pilot *cur_pilot, const Pilot *p)
 Gets the relative hp(combined shields and armour) between the current pilot and the specified target.
credits_t pilot_worth (const Pilot *p, int count_unique)
 Gets the price or worth of a pilot in credits.
mat4 pilot_local_transform (const Pilot *p)
 Gets the local transformation matrix of a pilot.
void pilot_msg (const Pilot *p, const Pilot *receiver, const char *type, unsigned int idx)
 Sends a message.
int pilot_hasIllegal (const Pilot *p, int faction)
 Checks to see if the pilot has illegal stuf to a faction.
void pilot_quadtreeParams (int max_elem, int depth)
 Sets the quad tree parameters. Can have significant impact on performance.

Variables

static unsigned int pilot_id
static Pilot ** pilot_stack
static Quadtree pilot_quadtree
static IntList pilot_qtquery
static int qt_init = 0
static int qt_max_elem = 2
static int qt_depth = 5
static const double pilot_commTimeout
static const double pilot_commFade

Detailed Description

Handles the pilot stuff.

Definition in file pilot.c.

Macro Definition Documentation

◆ PILOT_SIZE_MIN

#define PILOT_SIZE_MIN   128

Minimum chunks to increment pilot_stack by

Definition at line 44 of file pilot.c.

Function Documentation

◆ pilot_addQuadtree()

void pilot_addQuadtree ( const Pilot * p,
int i )
static

Definition at line 4160 of file pilot.c.

◆ pilot_addStack()

unsigned int pilot_addStack ( Pilot * p)

Adds a pilot to the stack.

Definition at line 3690 of file pilot.c.

◆ pilot_aimAngle()

double pilot_aimAngle ( Pilot * p,
const vec2 * pos,
const vec2 * vel )

Returns the angle for a pilot to aim at another pilot.

Parameters
pPilot that aims.
posPosiion of the target being aimed at.
velVelocity of the target being aimed at.

Definition at line 1025 of file pilot.c.

◆ pilot_areAllies()

int pilot_areAllies ( const Pilot * p,
const Pilot * target )

Like areAllies but for pilots.

Definition at line 741 of file pilot.c.

◆ pilot_areEnemies()

int pilot_areEnemies ( const Pilot * p,
const Pilot * target )

Like areEnemies but for pilots.

Definition at line 763 of file pilot.c.

◆ pilot_brake()

int pilot_brake ( Pilot * p,
double dt )

Causes the pilot to turn around and brake.

Parameters
pPilot to brake.
dtCurrent delta-tick.
Returns
1 when braking has finished.

Definition at line 886 of file pilot.c.

◆ pilot_brakeCheckReverseThrusters()

int pilot_brakeCheckReverseThrusters ( const Pilot * p)

See if the pilot wants to use their reverse thrusters to brake.

Definition at line 838 of file pilot.c.

◆ pilot_broadcast()

void pilot_broadcast ( Pilot * p,
const char * msg,
int ignore_int )

Has the pilot broadcast a message.

Parameters
pPilot to broadcast the message.
msgMessage to broadcast.
ignore_intWhether or not should ignore interference.

Definition at line 1152 of file pilot.c.

◆ pilot_canTarget()

int pilot_canTarget ( const Pilot * p)

Same as pilot_validTarget but without the range check.

Definition at line 270 of file pilot.c.

◆ pilot_choosePoint()

void pilot_choosePoint ( vec2 * vp,
Spob ** spob,
JumpPoint ** jump,
int lf,
int ignore_rules,
int guerilla )

Finds a spawn point for a pilot.

Parameters
[out]vpPosition.
[out]spobSpob chosen or NULL if not.
[out]jumpJump chosen or NULL if not.
lfFaction to choose point for.
ignore_rulesWhether or not to ignore all rules.
guerillaWhether or not to spawn in deep space.

Definition at line 3784 of file pilot.c.

◆ pilot_clearTimers()

void pilot_clearTimers ( Pilot * pilot)

Clears the pilot's timers.

Parameters
pilotPilot to clear timers of.

Definition at line 4337 of file pilot.c.

◆ pilot_clearTrails()

void pilot_clearTrails ( Pilot * p)

Resets the trails for a pilot.

Definition at line 3722 of file pilot.c.

◆ pilot_clone()

unsigned int pilot_clone ( const Pilot * ref)

Clones an existing pilot.

Parameters
refReference pilot to be cloned.
Returns
ID of the newly created clone.

Definition at line 3646 of file pilot.c.

◆ pilot_cmp()

int pilot_cmp ( const void * ptr1,
const void * ptr2 )
static

Compare id (for use with bsearch)

Definition at line 101 of file pilot.c.

◆ pilot_collideQuery()

const IntList * pilot_collideQuery ( int x1,
int y1,
int x2,
int y2 )

Definition at line 805 of file pilot.c.

◆ pilot_collideQueryIL()

void pilot_collideQueryIL ( IntList * il,
int x1,
int y1,
int x2,
int y2 )

Definition at line 811 of file pilot.c.

◆ pilot_cooldown()

void pilot_cooldown ( Pilot * p,
int dochecks )

Begins active cooldown, reducing hull and outfit temperatures.

Parameters
pPilot that should cool down.
dochecksWhether or not to do the standard checks or cooling down automatically.

Definition at line 918 of file pilot.c.

◆ pilot_cooldownEnd()

void pilot_cooldownEnd ( Pilot * p,
const char * reason )

Terminates active cooldown.

Parameters
pPilot to stop cooling.
reasonReason for the termination.

Definition at line 986 of file pilot.c.

◆ pilot_create()

Pilot * pilot_create ( const Ship * ship,
const char * name,
int faction,
const char * ai,
const double dir,
const vec2 * pos,
const vec2 * vel,
const PilotFlags flags,
unsigned int dockpilot,
int dockslot )

Creates a new pilot.

See pilot_init for parameters.

Returns
Pilot's id.
See also
pilot_init

Definition at line 3557 of file pilot.c.

◆ pilot_createEmpty()

Pilot * pilot_createEmpty ( const Ship * ship,
const char * name,
int faction,
PilotFlags flags )

Creates a pilot without adding it to the stack.

Parameters
shipShip for the pilot to use.
nameName of the pilot ship (NULL uses ship name).
factionFaction of the ship.
flagsFlags for tweaking.
Returns
Pointer to the new pilot (not added to stack).

Definition at line 3627 of file pilot.c.

◆ pilot_dead()

void pilot_dead ( Pilot * p,
unsigned int killer )

Pilot is dead, now will slowly explode.

Parameters
pPilot that just died.
killerPilot killer or 0 if invalid.

Definition at line 1687 of file pilot.c.

◆ pilot_delete()

void pilot_delete ( Pilot * p)

Deletes a pilot.

Parameters
pPilot to delete.

Definition at line 2965 of file pilot.c.

◆ pilot_distress()

void pilot_distress ( Pilot * p,
Pilot * attacker,
const char * msg )

Has the pilot broadcast a distress signal.

Can do a faction hit on the player.

Parameters
pPilot sending the distress signal.
attackerAttacking pilot.
msgMessage in distress signal.

Definition at line 1180 of file pilot.c.

◆ pilot_dpseps()

void pilot_dpseps ( const Pilot * p,
double * pdps,
double * peps )

Calculates the dps and eps of a pilot.

Parameters
pPilot to compute stats of.
[out]pdpsDPS of pilot.
[out]pepsEPS of pilot.

Definition at line 4377 of file pilot.c.

◆ pilot_erase()

void pilot_erase ( Pilot * p)
static

Destroys pilot from stack.

Parameters
pPilot to destroy.

Definition at line 3982 of file pilot.c.

◆ pilot_explode()

void pilot_explode ( double x,
double y,
double radius,
const Damage * dmg,
const Pilot * parent )

Makes the pilot explosion.

Parameters
xX position of the pilot.
yY position of the pilot.
radiusRadius of the explosion.
dmgDamage of the explosion.
parentThe exploding pilot.

Definition at line 1767 of file pilot.c.

◆ pilot_face()

double pilot_face ( Pilot * p,
double dir,
double dt )

Tries to turn the pilot to face dir.

Sets the direction velocity property of the pilot's solid, does not directly manipulate the direction.

Parameters
pPilot to turn.
dirDirection to attempt to face.
dtCurrent deltatick.
Returns
The distance left to turn to match dir.

Definition at line 827 of file pilot.c.

◆ pilot_free()

void pilot_free ( Pilot * p)

Frees and cleans up a pilot.

Parameters
pPilot to free.

Definition at line 3902 of file pilot.c.

◆ pilot_get()

Pilot * pilot_get ( unsigned int id)

Pulls a pilot out of the pilot_stack based on ID.

It's a binary search ( O(logn) ) therefore it's pretty fast and can be abused all the time. Maximum iterations is 32 on a platform with 32 bit unsigned ints.

Parameters
idID of the pilot to get.
Returns
The actual pilot who has matching ID or NULL if not found.

Definition at line 640 of file pilot.c.

◆ pilot_getAll()

Pilot *const * pilot_getAll ( void )

Gets the pilot stack.

Definition at line 93 of file pilot.c.

◆ pilot_getBoss()

unsigned int pilot_getBoss ( const Pilot * p)

Get the strongest ally in a given range.

Parameters
pPilot to get the boss of.
Returns
The boss.

Definition at line 450 of file pilot.c.

◆ pilot_getColour()

const glColour * pilot_getColour ( const Pilot * p)

Gets a pilot's colour.

Parameters
pPilot to get colour of.
Returns
The colour of the pilot.

Definition at line 1328 of file pilot.c.

◆ pilot_getDockSlot()

PilotOutfitSlot * pilot_getDockSlot ( Pilot * p)

Gets the dock slot of the pilot.

Parameters
pPilot to get dock slot of.
Returns
The dock slot as an outfit slot, or NULL if N/A.

Definition at line 793 of file pilot.c.

◆ pilot_getFactionColourChar()

char pilot_getFactionColourChar ( const Pilot * p)

Gets the faction colour char, works like faction_reputationColourChar but for a pilot.

See also
faction_reputationColourChar

Definition at line 1121 of file pilot.c.

◆ pilot_getJumps()

int pilot_getJumps ( const Pilot * p)

Gets the amount of jumps the pilot has left.

Parameters
pPilot to get the jumps left.
Returns
Number of jumps the pilot has left.

Definition at line 1317 of file pilot.c.

◆ pilot_getNearestAng()

double pilot_getNearestAng ( const Pilot * p,
unsigned int * tp,
double ang,
int disabled )

Get the pilot closest to an angle extending from another pilot.

Parameters
pPilot to get the nearest pilot of.
[out]tpThe nearest pilot.
angAngle to compare against.
disabledWhether to return disabled pilots.
Returns
Angle between the pilot and the nearest pilot.

Definition at line 585 of file pilot.c.

◆ pilot_getNearestEnemy()

unsigned int pilot_getNearestEnemy ( const Pilot * p)

Gets the nearest enemy to the pilot.

Parameters
pPilot to get the nearest enemy of.
Returns
ID of their nearest enemy.

Definition at line 331 of file pilot.c.

◆ pilot_getNearestEnemy_heuristic()

unsigned int pilot_getNearestEnemy_heuristic ( const Pilot * p,
double mass_factor,
double health_factor,
double damage_factor,
double range_factor )

Gets the nearest enemy to the pilot closest to the pilot whose mass is between LB and UB.

Parameters
pPilot to get the nearest enemy of.
mass_factorparameter for target mass (0-1, 0.5 = current mass)
health_factorparameter for target shields/armour (0-1, 0.5 = current health)
damage_factorparameter for target dps (0-1, 0.5 = current dps)
range_factorweighting for range (typically >> 1)
Returns
ID of their nearest enemy.

Definition at line 400 of file pilot.c.

◆ pilot_getNearestEnemy_size()

unsigned int pilot_getNearestEnemy_size ( const Pilot * p,
double target_mass_LB,
double target_mass_UB )

Gets the nearest enemy to the pilot closest to the pilot whose mass is between LB and UB.

Parameters
pPilot to get the nearest enemy of.
target_mass_LBthe lower bound for target mass
target_mass_UBthe upper bound for target mass
Returns
ID of their nearest enemy.

Definition at line 361 of file pilot.c.

◆ pilot_getNearestPilot()

unsigned int pilot_getNearestPilot ( const Pilot * p)

Get the nearest pilot to a pilot.

Parameters
pPilot to get the nearest pilot of.
Returns
The nearest pilot.

Definition at line 437 of file pilot.c.

◆ pilot_getNearestPos()

double pilot_getNearestPos ( const Pilot * p,
unsigned int * tp,
double x,
double y,
int disabled )

Get the nearest pilot to a pilot from a certain position.

Parameters
pPilot to get the nearest pilot of.
[out]tpThe nearest pilot.
xX position to calculate from.
yY position to calculate from.
disabledWhether to return disabled pilots.
Returns
The distance to the nearest pilot.

Definition at line 564 of file pilot.c.

◆ pilot_getNearestPosPilot()

double pilot_getNearestPosPilot ( const Pilot * p,
Pilot ** tp,
double x,
double y,
int disabled )

Get the nearest pilot to a pilot from a certain position.

Parameters
pPilot to get the nearest pilot of.
[out]tpThe nearest pilot.
xX position to calculate from.
yY position to calculate from.
disabledWhether to return disabled pilots.
Returns
The distance to the nearest pilot.

Definition at line 518 of file pilot.c.

◆ pilot_getNextID()

unsigned int pilot_getNextID ( unsigned int id,
int mode )

Gets the next pilot based on id.

Parameters
idID of current pilot.
modeMethod to use when cycling. 0 is normal, 1 is hostiles.
Returns
ID of next pilot or PLAYER_ID if no next pilot.

Definition at line 135 of file pilot.c.

◆ pilot_getPrevID()

unsigned int pilot_getPrevID ( unsigned int id,
int mode )

Gets the previous pilot based on ID.

Parameters
idID of the current pilot.
modeMethod to use when cycling. 0 is normal, 1 is hostiles.
Returns
ID of previous pilot or PLAYER_ID if no previous pilot.

Definition at line 183 of file pilot.c.

◆ pilot_getStackPos()

int pilot_getStackPos ( unsigned int id)
static

Gets the pilot's position in the stack.

Parameters
idID of the pilot to get.
Returns
Position of pilot in stack or -1 if not found.

Definition at line 115 of file pilot.c.

◆ pilot_getTarget()

Pilot * pilot_getTarget ( Pilot * p)

Gets the target of a pilot using a fancy caching system.

Definition at line 655 of file pilot.c.

◆ pilot_hasCredits()

int pilot_hasCredits ( const Pilot * p,
credits_t amount )

Checks to see if the pilot has at least a certain amount of credits.

Parameters
pPilot to check to see if they have enough credits.
amountAmount to check for.
Returns
1 if they have enough, 0 otherwise.

Definition at line 3286 of file pilot.c.

◆ pilot_hasIllegal()

int pilot_hasIllegal ( const Pilot * p,
int faction )

Checks to see if the pilot has illegal stuf to a faction.

Parameters
pPilot to check.
factionFaction to check.
Returns
1 if has illegal stuff 0 otherwise.

Definition at line 4567 of file pilot.c.

◆ pilot_hit()

double pilot_hit ( Pilot * p,
const Solid * w,
const Pilot * pshooter,
const Damage * dmg,
const Outfit * outfit,
int lua_mem,
int reset )

Damages the pilot.

Parameters
pPilot that is taking damage.
wSolid that is hitting pilot.
pshooterAttacker that shot the pilot.
dmgDamage being done.
outfitOutfit doing the damage if applicable.
lua_memLua reference to the Pilot Outfit's mem table, if applicable.
resetWhether the shield timer should be reset.
Returns
The real damage done.

Definition at line 1383 of file pilot.c.

◆ pilot_hyperspace()

void pilot_hyperspace ( Pilot * p,
double dt )
static

Handles pilot's hyperspace states.

Parameters
pPilot to handle hyperspace navigation.
dtCurrent deltatick.

Definition at line 3011 of file pilot.c.

◆ pilot_hyperspaceAbort()

void pilot_hyperspaceAbort ( Pilot * p)

Stops the pilot from hyperspacing.

Can only stop in preparation mode.

Parameters
pPilot to handle stop hyperspace.

Definition at line 3140 of file pilot.c.

◆ pilot_hyperspaceDelay()

ntime_t pilot_hyperspaceDelay ( const Pilot * p)

Calculates the hyperspace delay for a pilot.

Parameters
pPilot to calculate hyperspace delay for.
Returns
The hyperspace delay.

Definition at line 3243 of file pilot.c.

◆ pilot_init()

void pilot_init ( Pilot * pilot,
const Ship * ship,
const char * name,
int faction,
double dir,
const vec2 * pos,
const vec2 * vel,
const PilotFlags flags,
unsigned int dockpilot,
int dockslot )
static

Initialize pilot.

Parameters
pilotPilot to initialize.
shipShip pilot will be flying.
namePilot's name, if NULL ship's name will be used.
factionFaction of the pilot.
dirInitial direction to face (radians).
posInitial position.
velInitial velocity.
flagsUsed for tweaking the pilot.
dockpilotThe pilot which launched this pilot (0 if N/A).
dockslotThe outfit slot which launched this pilot (-1 if N/A).

Definition at line 3340 of file pilot.c.

◆ pilot_init_trails()

void pilot_init_trails ( Pilot * p)
static

Initialize pilot's trails according to the ship type and current system characteristics.

Definition at line 3535 of file pilot.c.

◆ pilot_isFriendly()

int pilot_isFriendly ( const Pilot * p)

Checks to see if pilot is friendly to the player.

Parameters
pPlayer to see if is friendly.
Returns
1 if pilot is friendly to the player.

Definition at line 728 of file pilot.c.

◆ pilot_isHostile()

int pilot_isHostile ( const Pilot * p)

Checks to see if pilot is hostile to the player.

Parameters
pPlayer to see if is hostile.
Returns
1 if pilot is hostile to the player.

Definition at line 699 of file pilot.c.

◆ pilot_isNeutral()

int pilot_isNeutral ( const Pilot * p)

Checks to see if pilot is neutral to the player.

Parameters
pPlayer to see if is neutral.
Returns
1 if pilot is neutral to the player.

Definition at line 715 of file pilot.c.

◆ pilot_local_transform()

mat4 pilot_local_transform ( const Pilot * p)

Gets the local transformation matrix of a pilot.

Useful for transforming mount points or other objects on the pilot.

Parameters
pPilot to get local 3D transformation.
Returns
The local 3D transformation.

Definition at line 4507 of file pilot.c.

◆ pilot_minbrakedist()

double pilot_minbrakedist ( const Pilot * p,
double dt,
double * flytime )

Gets the minimum braking distance for the pilot.

Definition at line 862 of file pilot.c.

◆ pilot_modCredits()

credits_t pilot_modCredits ( Pilot * p,
credits_t amount )

Modifies the amount of credits the pilot has.

Parameters
pPilot to modify amount of credits of.
amountQuantity of credits to give/take.
Returns
Amount of credits the pilot has.

Definition at line 3300 of file pilot.c.

◆ pilot_msg()

void pilot_msg ( const Pilot * p,
const Pilot * receiver,
const char * type,
unsigned int idx )

Sends a message.

Parameters
pPilot to send message
receiverPilot to receive it
typeType of message.
idxIndex of data on lua stack or 0

Definition at line 4531 of file pilot.c.

◆ pilot_numOutfit()

int pilot_numOutfit ( const Pilot * p,
const Outfit * o )

Checks to see how many of an outfit a pilot has.

Definition at line 3269 of file pilot.c.

◆ pilot_quadtreeParams()

void pilot_quadtreeParams ( int max_elem,
int depth )

Sets the quad tree parameters. Can have significant impact on performance.

Parameters
max_elemMaximum elements to add to a leaf before splitting.
depthMaximum depth to use.

Definition at line 4592 of file pilot.c.

◆ pilot_refuel()

void pilot_refuel ( Pilot * p,
double dt )
static

Has the pilot refuel its target.

Parameters
pPilot that is actively refueling.
dtCurrent delta tick.

Definition at line 3210 of file pilot.c.

◆ pilot_refuelStart()

int pilot_refuelStart ( Pilot * p)

Attempts to start refueling the pilot's target.

Parameters
pPilot to try to start refueling.

Definition at line 3170 of file pilot.c.

◆ pilot_reldps()

double pilot_reldps ( const Pilot * cur_pilot,
const Pilot * p )

Gets the relative damage output(total DPS) between the current pilot and the specified target.

Parameters
cur_pilotReference pilot to compare against.
pThe pilot whose dps we will compare
Returns
The relative dps of p with respect to cur_pilot (0.5 is equal, 1 is p is infinitely stronger, 0 is t is infinitely stronger).

Definition at line 4445 of file pilot.c.

◆ pilot_relhp()

double pilot_relhp ( const Pilot * cur_pilot,
const Pilot * p )

Gets the relative hp(combined shields and armour) between the current pilot and the specified target.

Parameters
cur_pilotReference pilot.
pthe pilot whose shields/armour we will compare
Returns
A number from 0 to 1 mapping the relative HPs (0.5 is equal, 1 is reference pilot is infinity, 0 is current pilot is infinity)

Definition at line 4468 of file pilot.c.

◆ pilot_relsize()

double pilot_relsize ( const Pilot * cur_pilot,
const Pilot * p )

Gets the relative size(shipmass) between the current pilot and the specified target.

Parameters
cur_pilotthe current pilot
pthe pilot whose mass we will compare
Returns
A number from 0 to 1 mapping the relative masses

Definition at line 4364 of file pilot.c.

◆ pilot_render()

void pilot_render ( Pilot * p)

Renders the pilot.

Parameters
pPilot to render.

Definition at line 1958 of file pilot.c.

◆ pilot_renderFramebuffer()

void pilot_renderFramebuffer ( Pilot * p,
GLuint fbo,
double fw,
double fh,
const Lighting * L )

Renders a pilot to a framebuffer.

Todo
Reduce duplicate code with pilot_render.
Parameters
pPilot to render.
fboFramebuffer to render to.
fwFramebuffer width.
fhFramebuffer height.
LLighting to use or NULL for default.

Definition at line 1849 of file pilot.c.

◆ pilot_renderFramebufferBase()

void pilot_renderFramebufferBase ( Pilot * p,
GLuint fbo,
double fw,
double fh,
const Lighting * L )
static

Renders a pilot to a framebuffer without effects.

Parameters
pPilot to render.
fboFramebuffer to render to.
fwFramebuffer width.
fhFramebuffer height.
LLighting to use or NULL for default.

Definition at line 1825 of file pilot.c.

◆ pilot_renderOverlay()

void pilot_renderOverlay ( Pilot * p)

Renders the pilot overlay.

Parameters
pPilot to render.

Definition at line 2235 of file pilot.c.

◆ pilot_reset()

void pilot_reset ( Pilot * pilot)

Resets a pilot.

Parameters
pilotPilot to reset.

Definition at line 3491 of file pilot.c.

◆ pilot_rmFriendly()

void pilot_rmFriendly ( Pilot * p)

Unmarks a pilot as friendly to player.

Parameters
pPilot to mark as friendly to player.

Definition at line 1306 of file pilot.c.

◆ pilot_rmHostile()

void pilot_rmHostile ( Pilot * p)

Unmarks a pilot as hostile to player.

Parameters
pPilot to mark as hostile to player.

Definition at line 1277 of file pilot.c.

◆ pilot_sample_trails()

void pilot_sample_trails ( Pilot * p,
int none )

Updates the given pilot's trail emissions.

Parameters
pPilot to update trails of.
noneIndicates that the pilot should update trails but skip their position.

Definition at line 2846 of file pilot.c.

◆ pilot_setAccel()

void pilot_setAccel ( Pilot * p,
double accel )

Sets the pilot's accel.

Definition at line 680 of file pilot.c.

◆ pilot_setCommMsg()

void pilot_setCommMsg ( Pilot * p,
const char * s )

Sets the overhead communication message of the pilot.

Definition at line 1137 of file pilot.c.

◆ pilot_setFriendly()

void pilot_setFriendly ( Pilot * p)

Marks pilot as friendly to player.

Parameters
pPilot to mark as friendly to player.

Definition at line 1295 of file pilot.c.

◆ pilot_setHostile()

void pilot_setHostile ( Pilot * p)

Marks pilot as hostile to player.

Parameters
pPilot to mark as hostile to player.

Definition at line 1105 of file pilot.c.

◆ pilot_setPlayer()

Pilot * pilot_setPlayer ( Pilot * after)

Replaces the player's pilot with an alternate ship with the same ID.

Returns
The new pilot.

Definition at line 3735 of file pilot.c.

◆ pilot_setTarget()

void pilot_setTarget ( Pilot * p,
unsigned int id )

Sets the target of the pilot.

Parameters
pPilot to set target of.
idID of the target (set to p->id for none).

Definition at line 1352 of file pilot.c.

◆ pilot_setTurn()

void pilot_setTurn ( Pilot * p,
double turn )

Sets the pilot's turn.

Definition at line 688 of file pilot.c.

◆ pilot_stackRemove()

void pilot_stackRemove ( Pilot * p)

Tries to remove a pilot from the stack.

Definition at line 3992 of file pilot.c.

◆ pilot_trail_generated()

int pilot_trail_generated ( Pilot * p,
int generator )
static

Return true if the given trail_emitters index has a corresponding generated trail.

Definition at line 2953 of file pilot.c.

◆ pilot_untargetAsteroid()

void pilot_untargetAsteroid ( int anchor,
int asteroid )

Loops over pilot stack to remove an asteroid as target.

Parameters
anchorAsteroid anchor the asteroid belongs to.
asteroidAsteroid.

Definition at line 3255 of file pilot.c.

◆ pilot_update()

void pilot_update ( Pilot * pilot,
double dt )

Updates the pilot.

Parameters
pilotPilot to update.
dtCurrent delta tick.

Definition at line 2328 of file pilot.c.

◆ pilot_updateDisable()

void pilot_updateDisable ( Pilot * p,
unsigned int shooter )

Handles pilot disabling. Set or unset the disable status depending on health and stress values.

Parameters
pThe pilot in question.
shooterAttacker that shot the pilot.

Definition at line 1605 of file pilot.c.

◆ pilot_updateSolid()

void pilot_updateSolid ( Pilot * p,
double dt )
static

Updates the pilot solid.

Definition at line 3196 of file pilot.c.

◆ pilot_validEnemy()

int pilot_validEnemy ( const Pilot * p,
const Pilot * target )

Checks to see if a pilot is a valid enemy for another pilot.

Parameters
pReference pilot.
targetPilot to see if is a valid enemy of the reference.
Returns
1 if it is valid, 0 otherwise.

Definition at line 291 of file pilot.c.

◆ pilot_validTarget()

int pilot_validTarget ( const Pilot * p,
const Pilot * target )

Checks to see if a pilot is a valid target for another pilot.

Parameters
pReference pilot.
targetPilot to see if is a valid target of the reference.
Returns
1 if it is valid, 0 otherwise.

Definition at line 235 of file pilot.c.

◆ pilot_validTargetRange()

int pilot_validTargetRange ( const Pilot * p,
const Pilot * target,
int * inrange )

Checks to see if a pilot is a valid target for another pilot while storing the result of pilot_inRangePilot in inrange.

Parameters
pReference pilot.
targetPilot to see if is a valid target of the reference.
[out]inrangeStores the value of pilot_inRangePilot.
Returns
1 if it is valid, 0 otherwise.

Definition at line 250 of file pilot.c.

◆ pilot_worth()

credits_t pilot_worth ( const Pilot * p,
int count_unique )

Gets the price or worth of a pilot in credits.

Parameters
pPilot to get worth of.
count_uniqueWhether or not to count the cost of unique outfits.
Returns
Worth of the pilot.

Definition at line 4482 of file pilot.c.

◆ pilots_clean()

void pilots_clean ( int persist)

Cleans up the pilot stack - leaves the player.

Parameters
persistDo not remove persistent pilots.

Definition at line 4052 of file pilot.c.

◆ pilots_cleanAll()

void pilots_cleanAll ( void )

Even cleans up the player.

Definition at line 4148 of file pilot.c.

◆ pilots_clear()

void pilots_clear ( void )

Clears all the pilots except the player and clear-exempt pilots.

Definition at line 4137 of file pilot.c.

◆ pilots_free()

void pilots_free ( void )

Frees the pilot stack.

Definition at line 4019 of file pilot.c.

◆ pilots_init()

void pilots_init ( void )

Initializes pilot stuff.

Definition at line 4010 of file pilot.c.

◆ pilots_newSystem()

void pilots_newSystem ( void )

Updates pilot state which depends on the system (sensor range, nebula trails...)

Definition at line 4116 of file pilot.c.

◆ pilots_render()

void pilots_render ( void )

Renders all the pilots.

Definition at line 4293 of file pilot.c.

◆ pilots_renderOverlay()

void pilots_renderOverlay ( void )

Renders all the pilots overlays.

Definition at line 4314 of file pilot.c.

◆ pilots_update()

void pilots_update ( double dt)

Updates all the pilots.

Parameters
dtDelta tick for the update.

Definition at line 4216 of file pilot.c.

◆ pilots_updatePurge()

void pilots_updatePurge ( void )

Purges pilots set for deletion.

Definition at line 4176 of file pilot.c.

Variable Documentation

◆ pilot_commFade

const double pilot_commFade
static
Initial value:
=
5.

Time for text above pilot to fade out.

Definition at line 65 of file pilot.c.

◆ pilot_commTimeout

const double pilot_commTimeout
static
Initial value:
=
15.

Time for text above pilot to time out.

Definition at line 63 of file pilot.c.

◆ pilot_id

unsigned int pilot_id
static
Initial value:
=
PLAYER_ID

Stack of pilot ids to assure uniqueness

Definition at line 47 of file pilot.c.

◆ pilot_qtquery

IntList pilot_qtquery
static

Quadtree query.

Definition at line 55 of file pilot.c.

◆ pilot_quadtree

Quadtree pilot_quadtree
static

Quadtree for the pilots.

Definition at line 54 of file pilot.c.

◆ pilot_stack

Pilot** pilot_stack
static
Initial value:
=
NULL

All the pilots in space. (Player may have other Pilot objects, e.g. backup ships.)

Definition at line 51 of file pilot.c.

◆ qt_depth

int qt_depth = 5
static

Definition at line 60 of file pilot.c.

◆ qt_init

int qt_init = 0
static

Definition at line 56 of file pilot.c.

◆ qt_max_elem

int qt_max_elem = 2
static

Definition at line 59 of file pilot.c.