46static int player_autonavApproachBoard(
const vec2 *pos,
const vec2 *vel,
double *dist2,
double sw );
67 if (pilot_isFlag(
player.
p, PILOT_MANUAL_CONTROL ) ||
83 if (pilot_isFlag(
player.
p, PILOT_NOJUMP)) {
91 dest = map_getDestination(NULL);
92 player_message(_(
"#oAutonav: travelling to %s."), (sys_isKnown(dest) ? _(dest->name) : _(
"Unknown")) );
107 if (pilot_isFlag(
player.
p, PILOT_MANUAL_CONTROL ) ||
114 if (!player_isFlag(PLAYER_AUTONAV)) {
136 player_setFlag(PLAYER_AUTONAV);
151 player_rmFlag(PLAYER_AUTONAV);
204 vec2_padd( &pos, 0.6 * p->radius, a );
265 t =
d / vel * (1. - 0.075 *
tc_base);
284 if (!player_isFlag(PLAYER_AUTONAV) || ((
player.
autonav != AUTONAV_JUMP_APPROACH) &&
304 if (!player_isFlag(PLAYER_AUTONAV))
309 if (pilot_isFlag(
player.
p, PILOT_MANUAL_CONTROL ))
312 if (player_isFlag(PLAYER_AUTONAV)) {
317 player_rmFlag(PLAYER_AUTONAV);
323 if (pilot_isFlag(
player.
p, PILOT_HYP_PREP)) {
340 int ret, map_npath, inrange;
345 (void) map_getDestination( &map_npath );
348 case AUTONAV_JUMP_APPROACH:
356 vec2_padd( &pos,
MAX( 0.8*
d,
d-30. ), t );
389 case AUTONAV_JUMP_BRAKE:
415 case AUTONAV_POS_APPROACH:
425 case AUTONAV_SPOB_APPROACH:
437 case AUTONAV_SPOB_LAND_APPROACH:
445 case AUTONAV_SPOB_LAND_BRAKE:
463 case AUTONAV_PLT_FOLLOW:
477 player_message( _(
"#oAutonav: following target %s has been lost."),
484 ret = (pilot_isDisabled(p) || pilot_isFlag(p,PILOT_BOARDABLE));
490 case AUTONAV_PLT_BOARD_APPROACH:
504 player_message( _(
"#oAutonav: boarding target %s has been lost."),
511 ret = player_autonavApproachBoard( &p->solid->pos, &p->solid->vel, &
d, p->ship->gfx_space->sw );
518 if (ret == PLAYER_BOARD_OK)
520 else if (!(ret == PLAYER_BOARD_RETRY))
537 double d, t, vel, dist;
541 if (
FABS(
d) < MIN_DIR_ERR) {
585 double angle, radius,
d, timeFactor;
593 const double Kp = 10.;
594 const double Kd =
MAX( 5., 10.84*timeFactor-10.82 );
598 if (!follow || (vel->
x == 0 && vel->
y == 0))
600 angle = M_PI + vel->
angle;
601 vec2_cset( &point, pos->
x + radius * cos(angle),
602 pos->
y + radius * sin(angle) );
611 if ((
FABS(
d) < MIN_DIR_ERR) && (VMOD(dir) > 300.))
621static int player_autonavApproachBoard(
const vec2 *pos,
const vec2 *vel,
double *dist2,
double sw )
623 double d, timeFactor;
630 const double Kp = 10.;
631 const double Kd =
MAX( 5., 10.84*timeFactor-10.82 );
640 if ((
FABS(
d) < MIN_DIR_ERR) && (VMOD(dir) > 300.))
649 if (*dist2 > sw * PILOT_SIZE_APPROX)
669 if (vec2_dist2( &pos, &jp->pos ) >
pow2(jp->radius))
689 double shield, armour;
690 int will_reset, lowhealth;
691 double reset_dist, reset_shield;
693 if (!player_isFlag(PLAYER_AUTONAV))
713 if ((reset_dist > 0.) || lowhealth) {
714 double rdist2 =
pow2(reset_dist);
720 if (p->id == PLAYER_ID)
723 if (pilot_isDisabled(p))
729 if (pilot_isFlag(p,PILOT_STEALTH))
743 if (reset_dist > 0.) {
804 const double dis_dead = 5.0;
805 const double dis_mod = 0.5;
806 const double dis_max = 4.0;
807 const double dis_ramp = 6.0;
810 pilot_isFlag(
player.
p, PILOT_DEAD) ||
811 player_isFlag( PLAYER_CINEMATICS ))
815 if (pilot_isFlag(
player.
p, PILOT_DISABLED)) {
844 if (!player_isFlag(PLAYER_AUTONAV))
Provides macros to work with dynamic arrays.
static ALWAYS_INLINE int array_size(const void *array)
Returns number of elements in the array.
int player_tryBoard(int noisy)
Attempt to board the player's target.
void player_message(const char *fmt,...)
Adds a mesg to the queue to be displayed on screen.
Header file with generic functions and naev-specifics.
void pause_setSpeed(double mod)
Adjusts the game's dt modifier.
int pilot_isHostile(const Pilot *p)
Checks to see if pilot is hostile to the player.
Pilot * pilot_getTarget(Pilot *p)
Gets the target of a pilot using a fancy caching system.
double pilot_face(Pilot *p, const double dir)
Tries to turn the pilot to face dir.
void pilot_hyperspaceAbort(Pilot *p)
Stops the pilot from hyperspacing.
Pilot * pilot_get(unsigned int id)
Pulls a pilot out of the pilot_stack based on ID.
double pilot_brakeDist(Pilot *p, vec2 *pos)
Gets the braking distance for a pilot.
Pilot *const * pilot_getAll(void)
Gets the pilot stack.
int pilot_canTarget(const Pilot *p)
Same as pilot_validTarget but without the range check.
int pilot_interceptPos(Pilot *p, double x, double y)
Attempts to make the pilot pass through a given point.
int pilot_brake(Pilot *p)
Causes the pilot to turn around and brake.
int pilot_inRangePilot(const Pilot *p, const Pilot *target, double *dist2)
Check to see if a pilot is in sensor range of another.
void player_accel(double acc)
Start accelerating.
void player_resetSpeed(void)
Resets the player speed stuff.
void player_hyperspacePreempt(int preempt)
Enables or disables jump points preempting spobs in autoface and target clearing.
double player_dt_default(void)
Returns the player's total default time delta based on time dilation stuff.
int player_getHypPreempt(void)
Returns whether the jump point target should preempt the spob target.
void player_restoreControl(int reason, const char *str)
Aborts autonav and other states that take control of the ship.
int player_jump(void)
Actually attempts to jump in hyperspace.
void player_accelOver(void)
Done accelerating.
int player_land(int loud)
Try to land or target closest spob if no land target.
static int player_autonavSetup(void)
Prepares the player to enter autonav.
void player_autonavEnd(void)
Ends the autonav.
void player_autonavStartWindow(unsigned int wid, const char *str)
Starts autonav and closes the window.
void player_autonavPos(double x, double y)
Starts autonav with a local position destination.
static void player_autonav(void)
Handles the autonavigation process for the player.
void player_autonavResetSpeed(void)
Resets the game speed.
void player_autonavStart(void)
Starts autonav.
int player_autonavShouldResetSpeed(void)
Checks whether the speed should be reset due to damage or missile locks.
static double last_armour
static double last_shield
void player_autonavPil(unsigned int p)
Starts autonav with a pilot to follow.
void player_autonavBoard(unsigned int p)
Starts autonav with a pilot to board.
static void player_autonavFollow(const vec2 *pos, const vec2 *vel, const int follow, double *dist2)
Handles following a moving point with autonav (PD controller).
void player_autonavSpob(const char *name, int tryland)
Starts autonav with a spob destination.
static int player_autonavBrake(void)
Handles the autonav braking.
void player_autonavAbort(const char *reason)
Aborts autonav.
void player_autonavAbortJump(const char *reason)
Aborts regular interstellar autonav, but not in-system autonav.
void player_thinkAutonav(Pilot *pplayer, double dt)
Handles autonav thinking.
static void player_autonavRampdown(double d)
Handles common time accel ramp-down for autonav to positions and spobs.
static int player_autonavApproach(const vec2 *pos, double *dist2, int count_target)
Handles approaching a position with autonav.
void player_updateAutonav(double dt)
Updates the player's autonav.
void sound_setSpeed(double s)
Sets the speed to play the sound at.
int space_canHyperspace(const Pilot *p)
Checks to make sure if pilot is far enough away to hyperspace.
int space_jumpDistance(const Pilot *p, const JumpPoint *jp)
Distance at which a pilot can jump.
Spob * spob_get(const char *spobname)
Gets a spob based on its name.
char spob_getColourChar(const Spob *p)
Gets the spob colour char.
const char * spob_name(const Spob *p)
Gets the translated name of a spob.
The representation of an in-game pilot.
double autonav_reset_shield
double compression_velocity
double autonav_reset_dist
Represents a Space Object (SPOB), including and not limited to planets, stations, wormholes,...