naev 0.10.4
Macros | Functions | Variables
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 "gatherable.h"
#include "gui.h"
#include "hook.h"
#include "land.h"
#include "land_outfits.h"
#include "land_shipyard.h"
#include "log.h"
#include "map.h"
#include "music.h"
#include "nlua_pilotoutfit.h"
#include "nlua_vec2.h"
#include "ndata.h"
#include "nstring.h"
#include "ntime.h"
#include "nxml.h"
#include "pause.h"
#include "player.h"
#include "player_autonav.h"
#include "rng.h"
#include "weapon.h"

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, const double dir, const vec2 *pos, const vec2 *vel, const PilotFlags flags, unsigned int dockpilot, int dockslot)
 Initialize pilot. More...
 
static void pilot_hyperspace (Pilot *p, double dt)
 Handles pilot's hyperspace states. More...
 
static void pilot_refuel (Pilot *p, double dt)
 Has the pilot refuel its target. More...
 
static void pilot_erase (Pilot *p)
 Destroys pilot from stack. More...
 
static int pilot_getStackPos (unsigned int id)
 Gets the pilot's position in the stack. More...
 
static void pilot_init_trails (Pilot *p)
 Initialize pilot's trails according to the ship type and current system characteristics. More...
 
static int pilot_trail_generated (Pilot *p, int generator)
 Return true if the given trail_emitters index has a corresponding generated trail. More...
 
Pilot *const * pilot_getAll (void)
 Gets the pilot stack. More...
 
static int pilot_cmp (const void *ptr1, const void *ptr2)
 Compare id (for use with bsearch) More...
 
unsigned int pilot_getNextID (unsigned int id, int mode)
 Gets the next pilot based on id. More...
 
unsigned int pilot_getPrevID (unsigned int id, int mode)
 Gets the previous pilot based on ID. More...
 
int pilot_validTarget (const Pilot *p, const Pilot *target)
 Checks to see if a pilot is a valid target for another pilot. More...
 
int pilot_canTarget (const Pilot *p)
 Same as pilot_validTarget but without the range check. More...
 
int pilot_validEnemy (const Pilot *p, const Pilot *target)
 Checks to see if a pilot is a valid enemy for another pilot. More...
 
int pilot_validEnemyDist (const Pilot *p, const Pilot *target, double *dist)
 Same as pilot_validEnemy, but able to store the distance too. More...
 
unsigned int pilot_getNearestEnemy (const Pilot *p)
 Gets the nearest enemy to the pilot. More...
 
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. More...
 
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. More...
 
unsigned int pilot_getNearestPilot (const Pilot *p)
 Get the nearest pilot to a pilot. More...
 
unsigned int pilot_getBoss (const Pilot *p)
 Get the strongest ally in a given range. More...
 
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. More...
 
double pilot_getNearestAng (const Pilot *p, unsigned int *tp, double ang, int disabled)
 Get the pilot closest to an angle extending from another pilot. More...
 
Pilotpilot_get (unsigned int id)
 Pulls a pilot out of the pilot_stack based on ID. More...
 
Pilotpilot_getTarget (Pilot *p)
 Gets the target of a pilot using a fancy caching system. More...
 
void pilot_setThrust (Pilot *p, double thrust)
 Sets the pilot's thrust. More...
 
void pilot_setTurn (Pilot *p, double turn)
 Sets the pilot's turn. More...
 
int pilot_isHostile (const Pilot *p)
 Checks to see if pilot is hostile to the player. More...
 
int pilot_isNeutral (const Pilot *p)
 Checks to see if pilot is neutral to the player. More...
 
int pilot_isFriendly (const Pilot *p)
 Checks to see if pilot is friendly to the player. More...
 
int pilot_areAllies (const Pilot *p, const Pilot *target)
 Like areAllies but for pilots. More...
 
int pilot_areEnemies (const Pilot *p, const Pilot *target)
 Like areEnemies but for pilots. More...
 
PilotOutfitSlotpilot_getDockSlot (Pilot *p)
 Gets the dock slot of the pilot. More...
 
double pilot_face (Pilot *p, const double dir)
 Tries to turn the pilot to face dir. More...
 
int pilot_brake (Pilot *p)
 Causes the pilot to turn around and brake. More...
 
double pilot_brakeDist (Pilot *p, vec2 *pos)
 Gets the braking distance for a pilot. More...
 
int pilot_interceptPos (Pilot *p, double x, double y)
 Attempts to make the pilot pass through a given point. More...
 
void pilot_cooldown (Pilot *p, int dochecks)
 Begins active cooldown, reducing hull and outfit temperatures. More...
 
void pilot_cooldownEnd (Pilot *p, const char *reason)
 Terminates active cooldown. More...
 
double pilot_aimAngle (Pilot *p, const vec2 *pos, const vec2 *vel)
 Returns the angle for a pilot to aim at another pilot. More...
 
void pilot_setHostile (Pilot *p)
 Marks pilot as hostile to player. More...
 
char pilot_getFactionColourChar (const Pilot *p)
 Gets the faction colour char, works like faction_getColourChar but for a pilot. More...
 
void pilot_setCommMsg (Pilot *p, const char *s)
 Sets the overhead communication message of the pilot. More...
 
void pilot_broadcast (Pilot *p, const char *msg, int ignore_int)
 Has the pilot broadcast a message. More...
 
void pilot_distress (Pilot *p, Pilot *attacker, const char *msg)
 Has the pilot broadcast a distress signal. More...
 
void pilot_rmHostile (Pilot *p)
 Unmarks a pilot as hostile to player. More...
 
void pilot_setFriendly (Pilot *p)
 Marks pilot as friendly to player. More...
 
void pilot_rmFriendly (Pilot *p)
 Unmarks a pilot as friendly to player. More...
 
int pilot_getJumps (const Pilot *p)
 Gets the amount of jumps the pilot has left. More...
 
const glColour * pilot_getColour (const Pilot *p)
 Gets a pilot's colour. More...
 
void pilot_setTarget (Pilot *p, unsigned int id)
 Sets the target of the pilot. More...
 
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. More...
 
void pilot_updateDisable (Pilot *p, unsigned int shooter)
 Handles pilot disabling. Set or unset the disable status depending on health and stress values. More...
 
void pilot_dead (Pilot *p, unsigned int killer)
 Pilot is dead, now will slowly explode. More...
 
void pilot_explode (double x, double y, double radius, const Damage *dmg, const Pilot *parent)
 Makes the pilot explosion. More...
 
void pilot_renderFramebuffer (Pilot *p, GLuint fbo, double fw, double fh)
 Renders a pilot to a framebuffer. More...
 
void pilot_render (Pilot *p)
 Renders the pilot. More...
 
void pilot_renderOverlay (Pilot *p)
 Renders the pilot overlay. More...
 
void pilot_update (Pilot *pilot, double dt)
 Updates the pilot. More...
 
void pilot_sample_trails (Pilot *p, int none)
 Updates the given pilot's trail emissions. More...
 
void pilot_delete (Pilot *p)
 Deletes a pilot. More...
 
void pilot_hyperspaceAbort (Pilot *p)
 Stops the pilot from hyperspacing. More...
 
int pilot_refuelStart (Pilot *p)
 Attempts to start refueling the pilot's target. More...
 
ntime_t pilot_hyperspaceDelay (Pilot *p)
 Calculates the hyperspace delay for a pilot. More...
 
void pilot_untargetAsteroid (int anchor, int asteroid)
 Loops over pilot stack to remove an asteroid as target. More...
 
int pilot_numOutfit (const Pilot *p, const Outfit *o)
 Checks to see how many of an outfit a pilot has. More...
 
int pilot_hasCredits (Pilot *p, credits_t amount)
 Checks to see if the pilot has at least a certain amount of credits. More...
 
credits_t pilot_modCredits (Pilot *p, credits_t amount)
 Modifies the amount of credits the pilot has. More...
 
void pilot_reset (Pilot *pilot)
 Resets a pilot. More...
 
unsigned int 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. More...
 
Pilotpilot_createEmpty (const Ship *ship, const char *name, int faction, PilotFlags flags)
 Creates a pilot without adding it to the stack. More...
 
unsigned int pilot_clone (const Pilot *ref)
 Clones an existing pilot. More...
 
unsigned int pilot_addStack (Pilot *p)
 Adds a pilot to the stack. More...
 
void pilot_clearTrails (Pilot *p)
 Resets the trails for a pilot. More...
 
Pilotpilot_setPlayer (Pilot *after)
 Replaces the player's pilot with an alternate ship with the same ID. More...
 
void pilot_choosePoint (vec2 *vp, Spob **spob, JumpPoint **jump, int lf, int ignore_rules, int guerilla)
 Finds a spawn point for a pilot. More...
 
void pilot_free (Pilot *p)
 Frees and cleans up a pilot. More...
 
void pilot_stackRemove (Pilot *p)
 Tries to remove a pilot from the stack. More...
 
void pilots_init (void)
 Initializes pilot stuff. More...
 
void pilots_free (void)
 Frees the pilot stack. More...
 
void pilots_clean (int persist)
 Cleans up the pilot stack - leaves the player. More...
 
void pilots_newSystem (void)
 Updates pilot state which depends on the system (sensor range, nebula trails...) More...
 
void pilots_clear (void)
 Clears all the pilots except the player and clear-exempt pilots. More...
 
void pilots_cleanAll (void)
 Even cleans up the player. More...
 
void pilots_update (double dt)
 Updates all the pilots. More...
 
void pilots_render (void)
 Renders all the pilots. More...
 
void pilots_renderOverlay (void)
 Renders all the pilots overlays. More...
 
void pilot_clearTimers (Pilot *pilot)
 Clears the pilot's timers. More...
 
double pilot_relsize (const Pilot *cur_pilot, const Pilot *p)
 Gets the relative size(shipmass) between the current pilot and the specified target. More...
 
void pilot_dpseps (const Pilot *p, double *pdps, double *peps)
 Calculates the dps and eps of a pilot. More...
 
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. More...
 
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. More...
 
credits_t pilot_worth (const Pilot *p)
 Gets the price or worth of a pilot in credits. More...
 
void pilot_msg (Pilot *p, Pilot *receiver, const char *type, unsigned int idx)
 Sends a message. More...
 
int pilot_hasIllegal (const Pilot *p, int faction)
 Checks to see if the pilot has illegal stuf to a faction. More...
 

Variables

static unsigned int pilot_id = PLAYER_ID
 
static Pilot ** pilot_stack = NULL
 
static const double pilot_commTimeout = 15.
 
static const double pilot_commFade = 5.
 

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 51 of file pilot.c.

Function Documentation

◆ pilot_addStack()

unsigned int pilot_addStack ( Pilot p)

Adds a pilot to the stack.

Definition at line 3262 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 1044 of file pilot.c.

◆ pilot_areAllies()

int pilot_areAllies ( const Pilot p,
const Pilot target 
)

Like areAllies but for pilots.

Definition at line 694 of file pilot.c.

◆ pilot_areEnemies()

int pilot_areEnemies ( const Pilot p,
const Pilot target 
)

Like areEnemies but for pilots.

Definition at line 718 of file pilot.c.

◆ pilot_brake()

int pilot_brake ( Pilot p)

Causes the pilot to turn around and brake.

Parameters
pPilot to brake.
Returns
1 when braking has finished.

Definition at line 788 of file pilot.c.

◆ pilot_brakeDist()

double pilot_brakeDist ( Pilot p,
vec2 pos 
)

Gets the braking distance for a pilot.

Parameters
pPilot to get the braking distance of.
[out]posEstimated final position once braked.
Returns
Estimated Braking distance based on current speed.

Definition at line 837 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 1154 of file pilot.c.

◆ pilot_canTarget()

int pilot_canTarget ( const Pilot p)

Same as pilot_validTarget but without the range check.

Definition at line 243 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 3345 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 3767 of file pilot.c.

◆ pilot_clearTrails()

void pilot_clearTrails ( Pilot p)

Resets the trails for a pilot.

Definition at line 3287 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 3223 of file pilot.c.

◆ pilot_cmp()

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

Compare id (for use with bsearch)

Definition at line 91 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 941 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 1004 of file pilot.c.

◆ pilot_create()

unsigned int 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 3151 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 3205 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 1676 of file pilot.c.

◆ pilot_delete()

void pilot_delete ( Pilot p)

Deletes a pilot.

Parameters
pPilot to delete.

Definition at line 2603 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 1182 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 3816 of file pilot.c.

◆ pilot_erase()

static void pilot_erase ( Pilot p)
static

Destroys pilot from stack.

Parameters
pPilot to destroy.

Definition at line 3496 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 1728 of file pilot.c.

◆ pilot_face()

double pilot_face ( Pilot p,
const double  dir 
)

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.
Returns
The distance left to turn to match dir.

Definition at line 773 of file pilot.c.

◆ pilot_free()

void pilot_free ( Pilot p)

Frees and cleans up a pilot.

Parameters
pPilot to free.

Definition at line 3428 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 589 of file pilot.c.

◆ pilot_getAll()

Pilot *const * pilot_getAll ( void  )

Gets the pilot stack.

Definition at line 83 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 425 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 1327 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 749 of file pilot.c.

◆ pilot_getFactionColourChar()

char pilot_getFactionColourChar ( const Pilot p)

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

See also
faction_getColourChar

Definition at line 1125 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 1316 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 536 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 312 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 376 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 341 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 412 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 492 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 124 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 172 of file pilot.c.

◆ pilot_getStackPos()

static 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 105 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 607 of file pilot.c.

◆ pilot_hasCredits()

int pilot_hasCredits ( 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 2897 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 3974 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 1381 of file pilot.c.

◆ pilot_hyperspace()

static void pilot_hyperspace ( Pilot p,
double  dt 
)
static

Handles pilot's hyperspace states.

Parameters
pPilot to handle hyperspace navigation.
dtCurrent deltatick.

Definition at line 2648 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 2772 of file pilot.c.

◆ pilot_hyperspaceDelay()

ntime_t pilot_hyperspaceDelay ( Pilot p)

Calculates the hyperspace delay for a pilot.

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

Definition at line 2855 of file pilot.c.

◆ pilot_init()

static void pilot_init ( Pilot pilot,
const Ship ship,
const char *  name,
int  faction,
const 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 2952 of file pilot.c.

◆ pilot_init_trails()

static void pilot_init_trails ( Pilot p)
static

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

Definition at line 3130 of file pilot.c.

◆ pilot_interceptPos()

int pilot_interceptPos ( Pilot p,
double  x,
double  y 
)

Attempts to make the pilot pass through a given point.

Todo:
Rewrite this using a superior method.
Parameters
pPilot to control.
xDestination X position.
yDestination Y position.
Returns
1 if pilot will pass through the point, 0 otherwise.

Definition at line 888 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 681 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 651 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 668 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 2911 of file pilot.c.

◆ pilot_msg()

void pilot_msg ( Pilot p,
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 3941 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 2880 of file pilot.c.

◆ pilot_refuel()

static 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 2822 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 2794 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 3883 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 3904 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 3804 of file pilot.c.

◆ pilot_render()

void pilot_render ( Pilot p)

Renders the pilot.

Parameters
pPilot to render.

Definition at line 1826 of file pilot.c.

◆ pilot_renderFramebuffer()

void pilot_renderFramebuffer ( Pilot p,
GLuint  fbo,
double  fw,
double  fh 
)

Renders a pilot to a framebuffer.

Parameters
pPilot to render.
fboFramebuffer to render to.
fwFramebuffer width.
fhFramebuffer height.

Definition at line 1778 of file pilot.c.

◆ pilot_renderOverlay()

void pilot_renderOverlay ( Pilot p)

Renders the pilot overlay.

Parameters
pPilot to render.

Definition at line 1968 of file pilot.c.

◆ pilot_reset()

void pilot_reset ( Pilot pilot)

Resets a pilot.

Parameters
pilotPilot to reset.

Definition at line 3088 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 1305 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 1276 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 2529 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 1139 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 1294 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 1111 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 3300 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 1351 of file pilot.c.

◆ pilot_setThrust()

void pilot_setThrust ( Pilot p,
double  thrust 
)

Sets the pilot's thrust.

Definition at line 632 of file pilot.c.

◆ pilot_setTurn()

void pilot_setTurn ( Pilot p,
double  turn 
)

Sets the pilot's turn.

Definition at line 640 of file pilot.c.

◆ pilot_stackRemove()

void pilot_stackRemove ( Pilot p)

Tries to remove a pilot from the stack.

Definition at line 3506 of file pilot.c.

◆ pilot_trail_generated()

static 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 2593 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 2867 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 2050 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 1598 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 266 of file pilot.c.

◆ pilot_validEnemyDist()

int pilot_validEnemyDist ( const Pilot p,
const Pilot target,
double *  dist 
)

Same as pilot_validEnemy, but able to store the distance too.

Definition at line 274 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.

Todo:
this calls inRangePilot which can be called again right after. This should probably be optimized.
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 226 of file pilot.c.

◆ pilot_worth()

credits_t pilot_worth ( const Pilot p)

Gets the price or worth of a pilot in credits.

Parameters
pPilot to get worth of.
Returns
Worth of the pilot.

Definition at line 3917 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 3555 of file pilot.c.

◆ pilots_cleanAll()

void pilots_cleanAll ( void  )

Even cleans up the player.

Definition at line 3635 of file pilot.c.

◆ pilots_clear()

void pilots_clear ( void  )

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

Definition at line 3624 of file pilot.c.

◆ pilots_free()

void pilots_free ( void  )

Frees the pilot stack.

Definition at line 3528 of file pilot.c.

◆ pilots_init()

void pilots_init ( void  )

Initializes pilot stuff.

Definition at line 3520 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 3614 of file pilot.c.

◆ pilots_render()

void pilots_render ( void  )

Renders all the pilots.

Definition at line 3731 of file pilot.c.

◆ pilots_renderOverlay()

void pilots_renderOverlay ( void  )

Renders all the pilots overlays.

Definition at line 3748 of file pilot.c.

◆ pilots_update()

void pilots_update ( double  dt)

Updates all the pilots.

Parameters
dtDelta tick for the update.

Definition at line 3653 of file pilot.c.

Variable Documentation

◆ pilot_commFade

const double pilot_commFade = 5.
static

Time for text above pilot to fade out.

Definition at line 61 of file pilot.c.

◆ pilot_commTimeout

const double pilot_commTimeout = 15.
static

Time for text above pilot to time out.

Definition at line 60 of file pilot.c.

◆ pilot_id

unsigned int pilot_id = PLAYER_ID
static

Stack of pilot ids to assure uniqueness

Definition at line 54 of file pilot.c.

◆ pilot_stack

Pilot** pilot_stack = NULL
static

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

Definition at line 57 of file pilot.c.