naev 0.10.4
player_autonav.c
Go to the documentation of this file.
1/*
2 * See Licensing and Copyright notice in naev.h
3 */
10#include <time.h>
11
12#include "naev.h"
15#include "player.h"
16
17#include "array.h"
18#include "board.h"
19#include "conf.h"
20#include "map.h"
21#include "pause.h"
22#include "pilot.h"
23#include "pilot_ew.h"
24#include "player.h"
25#include "sound.h"
26#include "space.h"
27#include "toolkit.h"
28
29extern double player_acc;
31static double tc_mod = 1.;
32static double tc_base = 1.;
33static double tc_down = 0.;
34static int tc_rampdown = 0;
35static double last_shield;
36static double last_armour;
37static int target_known = 0;
39/*
40 * Prototypes.
41 */
42static int player_autonavSetup (void);
43static void player_autonav (void);
44static int player_autonavApproach( const vec2 *pos, double *dist2, int count_target );
45static void player_autonavFollow( const vec2 *pos, const vec2 *vel, const int follow, double *dist2 );
46static int player_autonavApproachBoard( const vec2 *pos, const vec2 *vel, double *dist2, double sw );
47static int player_autonavBrake (void);
48
53{
54 tc_mod = 1.;
55 tc_rampdown = 0;
57}
58
63{
64 StarSystem *dest;
65
66 /* Not under manual control or disabled. */
67 if (pilot_isFlag( player.p, PILOT_MANUAL_CONTROL ) ||
68 pilot_isDisabled(player.p))
69 return;
70
71 if ((player.p->nav_hyperspace == -1) && (player.p->nav_spob== -1))
72 return;
73 else if ((player.p->nav_spob != -1) && !player_getHypPreempt()) {
74 player_autonavSpob( cur_system->spobs[ player.p->nav_spob ]->name, 0 );
75 return;
76 }
77
79 player_message(_("#rNot enough fuel to jump for autonav."));
80 return;
81 }
82
83 if (pilot_isFlag( player.p, PILOT_NOJUMP)) {
84 player_message(_("#rHyperspace drive is offline."));
85 return;
86 }
87
89 return;
90
91 dest = map_getDestination(NULL);
92 player_message(_("#oAutonav: travelling to %s."), (sys_isKnown(dest) ? _(dest->name) : _("Unknown")) );
94 player.autonav = AUTONAV_JUMP_BRAKE;
95 else
96 player.autonav = AUTONAV_JUMP_APPROACH;
97}
98
104static int player_autonavSetup (void)
105{
106 /* Not under manual control or disabled. */
107 if (pilot_isFlag( player.p, PILOT_MANUAL_CONTROL ) ||
108 pilot_isDisabled(player.p))
109 return -1;
110
111 /* Autonav is mutually-exclusive with other autopilot methods. */
112 player_restoreControl( PINPUT_AUTONAV, NULL );
113
114 if (!player_isFlag(PLAYER_AUTONAV)) {
116 tc_mod = tc_base;
117 if (conf.compression_mult >= 1.)
119 else
121 solid_maxspeed(player.p->solid, player.p->speed, player.p->thrust);
122
123 /* Safe cap. */
124 player.tc_max = MAX( 1., player.tc_max );
125 }
126
127 /* Safe values. */
128 free( player.autonavmsg );
129 player.autonavmsg = NULL;
130 tc_rampdown = 0;
131 tc_down = 0.;
134
135 /* Set flag and tc_mod just in case. */
136 player_setFlag(PLAYER_AUTONAV);
139
140 /* Make sure time acceleration starts immediately. */
142
143 return 0;
144}
145
150{
151 player_rmFlag(PLAYER_AUTONAV);
153 free( player.autonavmsg );
154 player.autonavmsg = NULL;
155 /* Get rid of acceleration. */
157}
158
162void player_autonavStartWindow( unsigned int wid, const char *str)
163{
164 (void) str;
167 window_destroy( wid );
168}
169
173void player_autonavPos( double x, double y )
174{
176 return;
177
178 player_message(_("#oAutonav: heading to target position."));
179 player.autonav = AUTONAV_POS_APPROACH;
180 player.autonavmsg = strdup( _("position" ));
181 player.autonavcol = '0';
182 vec2_cset( &player.autonav_pos, x, y );
183}
184
188void player_autonavSpob( const char *name, int tryland )
189{
190 Spob *p;
191 vec2 pos;
192 double a;
193
195 return;
196 p = spob_get( name );
197 player.autonavmsg = strdup( spob_name(p) );
199 pos = p->pos;
200
201 /* Don't target center, but position offset in the direction of the player. */
202 a = ANGLE( player.p->solid->pos.x - pos.x,
203 player.p->solid->pos.y - pos.y );
204 vec2_padd( &pos, 0.6 * p->radius, a );
205 player.autonav_pos = pos;
206
207 if (tryland) {
208 player.autonav = AUTONAV_SPOB_LAND_APPROACH;
209 player_message(_("#oAutonav: landing on #%c%s#0."), player.autonavcol, player.autonavmsg );
210 }
211 else {
212 player.autonav = AUTONAV_SPOB_APPROACH;
213 player_message(_("#oAutonav: approaching #%c%s#0."), player.autonavcol, player.autonavmsg );
214 }
215}
216
220void player_autonavPil( unsigned int p )
221{
222 Pilot *pilot = pilot_get( p );
223 int inrange = pilot_inRangePilot( player.p, pilot, NULL );
224 if (player_autonavSetup() || !inrange)
225 return;
226
227 target_known = (inrange > 0);
228 player_message(_("#oAutonav: following %s."), (target_known) ? pilot->name : _("Unknown") );
229 player.autonav = AUTONAV_PLT_FOLLOW;
230 player.autonavmsg = strdup( pilot->name );
231 player.autonavcol = '0';
232}
233
237void player_autonavBoard( unsigned int p )
238{
239 Pilot *pilot = pilot_get( p );
240 int inrange = pilot_inRangePilot( player.p, pilot, NULL );
241 if (player_autonavSetup() || !inrange)
242 return;
243
244 /* Detected fuzzy, can't board. */
245 if (inrange!=1) {
247 return;
248 }
249
250 player_message(_("#oAutonav: boarding %s."), pilot->name );
251 player.autonav = AUTONAV_PLT_BOARD_APPROACH;
252 player.autonavmsg = strdup( pilot->name );
253 player.autonavcol = '0';
254}
255
259static void player_autonavRampdown( double d )
260{
261 double t, tint;
262 double vel;
263
264 vel = MIN( 1.5*player.p->speed, VMOD(player.p->solid->vel) );
265 t = d / vel * (1. - 0.075 * tc_base);
266 tint = 3. + 0.5*(3.*(tc_mod-tc_base));
267 if (t < tint) {
268 tc_rampdown = 1;
269 tc_down = (tc_mod-tc_base) / 3.;
270 }
271}
272
278void player_autonavAbortJump( const char *reason )
279{
280 /* No point if player is beyond aborting. */
281 if ((player.p==NULL) || pilot_isFlag(player.p, PILOT_HYPERSPACE))
282 return;
283
284 if (!player_isFlag(PLAYER_AUTONAV) || ((player.autonav != AUTONAV_JUMP_APPROACH) &&
285 (player.autonav != AUTONAV_JUMP_BRAKE)))
286 return;
287
288 /* It's definitely not in-system autonav. */
289 player_autonavAbort(reason);
290}
291
297void player_autonavAbort( const char *reason )
298{
299 /* No point if player is beyond aborting. */
300 if ((player.p==NULL) || pilot_isFlag(player.p, PILOT_HYPERSPACE))
301 return;
302
303 /* Not under autonav. */
304 if (!player_isFlag(PLAYER_AUTONAV))
305 return;
306
307 /* Cooldown (handled later) may be script-initiated and we don't
308 * want to make it player-abortable while under manual control. */
309 if (pilot_isFlag( player.p, PILOT_MANUAL_CONTROL ))
310 return;
311
312 if (player_isFlag(PLAYER_AUTONAV)) {
313 if (reason != NULL)
314 player_message(_("#rAutonav: aborted due to '%s'!"), reason);
315 else
316 player_message(_("#rAutonav: aborted!"));
317 player_rmFlag(PLAYER_AUTONAV);
318
319 /* Get rid of acceleration. */
321
322 /* Break possible hyperspacing. */
323 if (pilot_isFlag(player.p, PILOT_HYP_PREP)) {
325 player_message(_("#oAutonav: aborting hyperspace sequence."));
326 }
327
328 /* Reset time compression. */
330 }
331}
332
336static void player_autonav (void)
337{
338 JumpPoint *jp;
339 Pilot *p;
340 int ret, map_npath, inrange;
341 double d, t, tint;
342 double vel;
343 vec2 pos;
344
345 (void) map_getDestination( &map_npath );
346
347 switch (player.autonav) {
348 case AUTONAV_JUMP_APPROACH:
349 /* Target jump. */
350 jp = &cur_system->jumps[ player.p->nav_hyperspace ];
351 /* Don't target center, but position offset in the direction of the player. */
352 pos = jp->pos;
353 t = ANGLE( player.p->solid->pos.x - jp->pos.x,
354 player.p->solid->pos.y - jp->pos.y );
355 d = space_jumpDistance( player.p, jp );
356 vec2_padd( &pos, MAX( 0.8*d, d-30. ), t );
357 ret = player_autonavApproach( &pos, &d, 0 );
358 if (ret)
359 player.autonav = AUTONAV_JUMP_BRAKE;
360 else if (!tc_rampdown && (map_npath<=1)) {
361 vel = MIN( 1.5*player.p->speed, VMOD(player.p->solid->vel) );
362 t = d / vel * (1.2 - .1 * tc_base);
363 /* tint is the integral of the time in per time units.
364 *
365 * tc_mod
366 * ^
367 * |
368 * |\
369 * | \
370 * | \___
371 * |
372 * +------> time
373 * 0 3
374 *
375 * We decompose integral in a rectangle (3*1) and a triangle (3*(tc_mod-1.))/2.
376 * This is the "elapsed time" when linearly decreasing the tc_mod. Which we can
377 * use to calculate the actual "game time" that'll pass when decreasing the
378 * tc_mod to 1 during 3 seconds. This can be used then to compare when we want to
379 * start decrementing.
380 */
381 tint = 3. + 0.5*(3.*(tc_mod-tc_base));
382 if (t < tint) {
383 tc_rampdown = 1;
384 tc_down = (tc_mod-tc_base) / 3.;
385 }
386 }
387 break;
388
389 case AUTONAV_JUMP_BRAKE:
390 /* Target jump. */
391 jp = &cur_system->jumps[ player.p->nav_hyperspace ];
393 ret = pilot_interceptPos( player.p, jp->pos.x, jp->pos.y );
394 if (!ret && space_canHyperspace(player.p))
395 ret = 1;
397 }
398 else
399 ret = player_autonavBrake();
400
401 /* Try to jump or see if braked. */
402 if (ret) {
404 player_jump();
405 player.autonav = AUTONAV_JUMP_APPROACH;
406 }
407
408 /* See if should ramp down. */
409 if (!tc_rampdown && (map_npath<=1)) {
410 tc_rampdown = 1;
411 tc_down = (tc_mod-tc_base) / 3.;
412 }
413 break;
414
415 case AUTONAV_POS_APPROACH:
417 if (ret) {
418 player_message( _("#oAutonav: arrived at position.") );
420 }
421 else if (!tc_rampdown)
423 break;
424
425 case AUTONAV_SPOB_APPROACH:
427 if (ret) {
428 player_message( _("#oAutonav: arrived at #%c%s#0."),
432 }
433 else if (!tc_rampdown)
435 break;
436
437 case AUTONAV_SPOB_LAND_APPROACH:
439 if (ret)
440 player.autonav = AUTONAV_SPOB_LAND_BRAKE;
441 else if (!tc_rampdown)
443 break;
444
445 case AUTONAV_SPOB_LAND_BRAKE:
446 ret = player_autonavBrake();
447
448 /* Try to land. */
449 if (ret) {
450 if (player_land(0) == PLAYER_LAND_DENIED)
452 else
453 player.autonav = AUTONAV_SPOB_LAND_APPROACH;
454 }
455
456 /* See if should ramp down. */
457 if (!tc_rampdown) {
458 tc_rampdown = 1;
459 tc_down = (tc_mod-tc_base) / 3.;
460 }
461 break;
462
463 case AUTONAV_PLT_FOLLOW:
464 p = pilot_getTarget( player.p );
465
466 if (p != NULL) {
467 inrange = pilot_inRangePilot( player.p, p, NULL );
468 target_known = (inrange > 0);
469 }
470 else {
471 inrange = 0;
472 target_known = 1; /* Suddenly disappeared but in range. */
473 }
474
475 if (!inrange) {
476 /* TODO : handle the different reasons: pilot is too far, jumped, landed or died. */
477 player_message( _("#oAutonav: following target %s has been lost."),
478 (target_known) ? player.autonavmsg : _("Unknown") );
479 player_accel( 0. );
481 break;
482 }
483
484 ret = (pilot_isDisabled(p) || pilot_isFlag(p,PILOT_BOARDABLE));
485 player_autonavFollow( &p->solid->pos, &p->solid->vel, !ret, &d );
486 if (ret && (!tc_rampdown))
488 break;
489
490 case AUTONAV_PLT_BOARD_APPROACH:
491 p = pilot_getTarget( player.p );
492
493 if (p != NULL) {
494 inrange = pilot_inRangePilot( player.p, p, NULL );
495 target_known = (inrange > 0);
496 }
497 else {
498 inrange = 0;
499 target_known = 1; /* Suddenly disappeared but in range. */
500 }
501
502 if (!inrange) {
503 /* TODO : handle the different reasons: pilot is too far, jumped, landed or died. */
504 player_message( _("#oAutonav: boarding target %s has been lost."),
505 (target_known) ? player.autonavmsg : _("Unknown") );
506 player_accel( 0. );
508 break;
509 }
510
511 ret = player_autonavApproachBoard( &p->solid->pos, &p->solid->vel, &d, p->ship->gfx_space->sw );
512 if (!tc_rampdown)
514
515 /* Try to board. */
516 if (ret) {
517 ret = player_tryBoard(0);
518 if (ret == PLAYER_BOARD_OK)
520 else if (!(ret == PLAYER_BOARD_RETRY))
521 player_autonavAbort(NULL); /* Not allowed to board, and it's not because of your position: abort. */
522 }
523 break;
524 }
525}
526
535static int player_autonavApproach( const vec2 *pos, double *dist2, int count_target )
536{
537 double d, t, vel, dist;
538
539 /* Only accelerate if facing move dir. */
540 d = pilot_face( player.p, vec2_angle( &player.p->solid->pos, pos ) );
541 if (FABS(d) < MIN_DIR_ERR) {
542 if (player_acc < 1.)
543 player_accel( 1. );
544 }
545 else if (player_acc > 0.)
547
548 /* Get current time to reach target. */
549 t = MIN( 1.5*player.p->speed, VMOD(player.p->solid->vel) ) /
551
552 /* Get velocity. */
553 vel = MIN( player.p->speed, VMOD(player.p->solid->vel) );
554
555 /* Get distance. */
556 dist = vel*(t+1.1*M_PI/player.p->turn) -
557 0.5*(player.p->thrust/player.p->solid->mass)*t*t;
558
559 /* Output distance^2 */
560 d = vec2_dist( pos, &player.p->solid->pos );
561 dist = d - dist;
562 if (count_target)
563 *dist2 = dist;
564 else
565 *dist2 = d;
566
567 /* See if should start braking. */
568 if (dist < 0.) {
570 return 1;
571 }
572 return 0;
573}
574
583static void player_autonavFollow( const vec2 *pos, const vec2 *vel, const int follow, double *dist2 )
584{
585 double angle, radius, d, timeFactor;
586 vec2 dir, point;
587
588 /* timeFactor is a time constant of the ship, used to heuristically determine the ratio Kd/Kp. */
589 timeFactor = M_PI/player.p->turn + player.p->speed/player.p->thrust*player.p->solid->mass;
590
591 /* Define the control coefficients.
592 Maybe radius could be adjustable by the player. */
593 const double Kp = 10.;
594 const double Kd = MAX( 5., 10.84*timeFactor-10.82 );
595 radius = 100.;
596
597 /* Find a point behind the target at a distance of radius unless stationary, or not following. */
598 if (!follow || (vel->x == 0 && vel->y == 0))
599 radius = 0.;
600 angle = M_PI + vel->angle;
601 vec2_cset( &point, pos->x + radius * cos(angle),
602 pos->y + radius * sin(angle) );
603
604 vec2_cset( &dir, (point.x - player.p->solid->pos.x) * Kp +
605 (vel->x - player.p->solid->vel.x) *Kd,
606 (point.y - player.p->solid->pos.y) * Kp +
607 (vel->y - player.p->solid->vel.y) *Kd );
608
609 d = pilot_face( player.p, VANGLE(dir) );
610
611 if ((FABS(d) < MIN_DIR_ERR) && (VMOD(dir) > 300.))
612 player_accel( 1. );
613 else
614 player_accel( 0. );
615
616 /* If aiming exactly at the point, should say when approaching. */
617 if (!follow)
618 *dist2 = vec2_dist( pos, &player.p->solid->pos );
619}
620
621static int player_autonavApproachBoard( const vec2 *pos, const vec2 *vel, double *dist2, double sw )
622{
623 double d, timeFactor;
624 vec2 dir;
625
626 /* timeFactor is a time constant of the ship, used to heuristically determine the ratio Kd/Kp. */
627 timeFactor = M_PI/player.p->turn + player.p->speed/player.p->thrust*player.p->solid->mass;
628
629 /* Define the control coefficients. */
630 const double Kp = 10.;
631 const double Kd = MAX( 5., 10.84*timeFactor-10.82 );
632
633 vec2_cset( &dir, (pos->x - player.p->solid->pos.x) * Kp +
634 (vel->x - player.p->solid->vel.x) *Kd,
635 (pos->y - player.p->solid->pos.y) * Kp +
636 (vel->y - player.p->solid->vel.y) *Kd );
637
638 d = pilot_face( player.p, VANGLE(dir) );
639
640 if ((FABS(d) < MIN_DIR_ERR) && (VMOD(dir) > 300.))
641 player_accel( 1. );
642 else
643 player_accel( 0. );
644
645 /* Distance for TC-rampdown. */
646 *dist2 = vec2_dist( pos, &player.p->solid->pos );
647
648 /* Check if velocity and position allow to board. */
649 if (*dist2 > sw * PILOT_SIZE_APPROX)
650 return 0;
651 if (vec2_dist2( &player.p->solid->vel, vel ) > pow2(MAX_HYPERSPACE_VEL))
652 return 0;
653 return 1;
654}
655
661static int player_autonavBrake (void)
662{
663 int ret;
664 if ((player.autonav == AUTONAV_JUMP_BRAKE) && (player.p->nav_hyperspace != -1)) {
665 vec2 pos;
666 JumpPoint *jp = &cur_system->jumps[ player.p->nav_hyperspace ];
667
668 pilot_brakeDist( player.p, &pos );
669 if (vec2_dist2( &pos, &jp->pos ) > pow2(jp->radius))
670 ret = pilot_interceptPos( player.p, jp->pos.x, jp->pos.y );
671 else
672 ret = pilot_brake( player.p );
673 }
674 else
675 ret = pilot_brake(player.p);
676
678
679 return ret;
680}
681
688{
689 double shield, armour;
690 int will_reset, lowhealth;
691 double reset_dist, reset_shield;
692
693 if (!player_isFlag(PLAYER_AUTONAV))
694 return 0;
695
696 /* Stop on lockons. */
697 if (player.p->lockons > 0) {
700 return 1;
701 }
702
703 /* Helper variables. */
704 reset_dist = conf.autonav_reset_dist;
705 reset_shield = conf.autonav_reset_shield;
706 will_reset = 0;
707 /* Current ship health. */
708 shield = player.p->shield / player.p->shield_max;
709 armour = player.p->armour / player.p->armour_max;
710 lowhealth = ((shield < last_shield && shield < reset_shield) || armour < last_armour);
711
712 /* Only care when low health or stopping on distance. */
713 if ((reset_dist > 0.) || lowhealth) {
714 double rdist2 = pow2(reset_dist);
715 Pilot *const*pstk = pilot_getAll();
716 for (int i=0; i<array_size(pstk); i++) {
717 double d2;
718 Pilot *p = pstk[i];
719
720 if (p->id == PLAYER_ID)
721 continue;
722
723 if (pilot_isDisabled(p))
724 continue;
725
726 if (!pilot_isHostile( p ))
727 continue;
728
729 if (pilot_isFlag(p,PILOT_STEALTH))
730 continue;
731
732 if (!pilot_canTarget( p ))
733 continue;
734
735 if (pilot_inRangePilot( player.p, pstk[i], &d2 )!=1)
736 continue;
737
738 if (lowhealth) {
739 will_reset = 1;
741 break;
742 }
743 if (reset_dist > 0.) {
744 if (d2 < rdist2) {
745 will_reset = 1;
747 break;
748 }
749 }
750 else
751 break;
752 }
753 }
754
755 /* Remember last helath status. */
756 last_shield = shield;
757 last_armour = armour;
758
759 if (will_reset || (player.autonav_timer > 0.)) {
761 return 1;
762 }
763 return 0;
764}
765
772void player_thinkAutonav( Pilot *pplayer, double dt )
773{
774 if (player.autonav_timer > 0.)
775 player.autonav_timer -= dt;
776
778 if ((player.autonav == AUTONAV_JUMP_APPROACH) ||
779 (player.autonav == AUTONAV_JUMP_BRAKE)) {
780 /* If we're already at the target. */
781 if (player.p->nav_hyperspace == -1)
782 player_autonavAbort(_("Target changed to current system"));
783
784 /* Need fuel. */
785 else if (pplayer->fuel < pplayer->fuel_consumption)
786 player_autonavAbort(_("Not enough fuel for autonav to continue"));
787
788 else
790 }
791
792 /* Keep on moving. */
793 else
795}
796
802void player_updateAutonav( double dt )
803{
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;
808
809 if (paused || (player.p==NULL) ||
810 pilot_isFlag(player.p, PILOT_DEAD) ||
811 player_isFlag( PLAYER_CINEMATICS ))
812 return;
813
814 /* We handle disabling here. */
815 if (pilot_isFlag(player.p, PILOT_DISABLED)) {
816 /* It is somewhat like:
817 * /------------\ 4x
818 * / \
819 * -----/ \----- 1x
820 *
821 * <---><-><----------><-><--->
822 * 5 6 X 6 5 Real time
823 * 5 15 X 15 5 Game time
824 *
825 * For triangles we have to add the rectangle and triangle areas.
826 */
827 /* 5 second deadtime. */
828 if (player.p->dtimer_accum < dis_dead)
829 tc_mod = tc_base;
830 else {
831 /* Ramp down. */
832 if (player.p->dtimer - player.p->dtimer_accum < dis_dead + (dis_max-tc_base)*dis_ramp/2 + tc_base*dis_ramp)
833 tc_mod = MAX( tc_base, tc_mod - dis_mod*dt );
834 /* Normal. */
835 else
836 tc_mod = MIN( dis_max, tc_mod + dis_mod*dt );
837 }
840 return;
841 }
842
843 /* Must be autonaving. */
844 if (!player_isFlag(PLAYER_AUTONAV))
845 return;
846
847 /* Ramping down. */
848 if (tc_rampdown) {
849 if (tc_mod != tc_base) {
853 }
854 return;
855 }
856
857 /* We'll update the time compression here. */
858 if (tc_mod == player.tc_max)
859 return;
860 else
861 tc_mod += 0.2 * dt * (player.tc_max-tc_base);
862 /* Avoid going over. */
863 if (tc_mod > player.tc_max)
867}
Provides macros to work with dynamic arrays.
static ALWAYS_INLINE int array_size(const void *array)
Returns number of elements in the array.
Definition: array.h:168
int player_tryBoard(int noisy)
Attempt to board the player's target.
Definition: board.c:113
void player_message(const char *fmt,...)
Adds a mesg to the queue to be displayed on screen.
Definition: gui.c:330
Header file with generic functions and naev-specifics.
#define MIN(x, y)
Definition: naev.h:40
#define pow2(x)
Definition: naev.h:46
#define FABS(x)
Definition: naev.h:37
#define MAX(x, y)
Definition: naev.h:39
void pause_setSpeed(double mod)
Adjusts the game's dt modifier.
Definition: pause.c:64
int paused
Definition: pause.c:21
int pilot_isHostile(const Pilot *p)
Checks to see if pilot is hostile to the player.
Definition: pilot.c:651
Pilot * pilot_getTarget(Pilot *p)
Gets the target of a pilot using a fancy caching system.
Definition: pilot.c:607
double pilot_face(Pilot *p, const double dir)
Tries to turn the pilot to face dir.
Definition: pilot.c:773
void pilot_hyperspaceAbort(Pilot *p)
Stops the pilot from hyperspacing.
Definition: pilot.c:2772
Pilot * pilot_get(unsigned int id)
Pulls a pilot out of the pilot_stack based on ID.
Definition: pilot.c:589
double pilot_brakeDist(Pilot *p, vec2 *pos)
Gets the braking distance for a pilot.
Definition: pilot.c:837
Pilot *const * pilot_getAll(void)
Gets the pilot stack.
Definition: pilot.c:83
int pilot_canTarget(const Pilot *p)
Same as pilot_validTarget but without the range check.
Definition: pilot.c:243
int pilot_interceptPos(Pilot *p, double x, double y)
Attempts to make the pilot pass through a given point.
Definition: pilot.c:888
int pilot_brake(Pilot *p)
Causes the pilot to turn around and brake.
Definition: pilot.c:788
int pilot_inRangePilot(const Pilot *p, const Pilot *target, double *dist2)
Check to see if a pilot is in sensor range of another.
Definition: pilot_ew.c:242
void player_accel(double acc)
Start accelerating.
Definition: player.c:2088
void player_resetSpeed(void)
Resets the player speed stuff.
Definition: player.c:1416
void player_hyperspacePreempt(int preempt)
Enables or disables jump points preempting spobs in autoface and target clearing.
Definition: player.c:1851
double player_dt_default(void)
Returns the player's total default time delta based on time dilation stuff.
Definition: player.c:1871
int player_getHypPreempt(void)
Returns whether the jump point target should preempt the spob target.
Definition: player.c:1861
void player_restoreControl(int reason, const char *str)
Aborts autonav and other states that take control of the ship.
Definition: player.c:1429
int player_jump(void)
Actually attempts to jump in hyperspace.
Definition: player.c:1900
void player_accelOver(void)
Done accelerating.
Definition: player.c:2102
int player_land(int loud)
Try to land or target closest spob if no land target.
Definition: player.c:1549
Player_t player
Definition: player.c:73
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 int tc_rampdown
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).
double player_acc
Definition: player.c:122
static double tc_mod
static int target_known
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.
static double tc_base
void player_thinkAutonav(Pilot *pplayer, double dt)
Handles autonav thinking.
static double tc_down
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.
static const double a[]
Definition: rng.c:247
static const double d[]
Definition: rng.c:273
void sound_setSpeed(double s)
Sets the speed to play the sound at.
Definition: sound.c:1160
int space_canHyperspace(const Pilot *p)
Checks to make sure if pilot is far enough away to hyperspace.
Definition: space.c:437
int space_jumpDistance(const Pilot *p, const JumpPoint *jp)
Distance at which a pilot can jump.
Definition: space.c:423
Spob * spob_get(const char *spobname)
Gets a spob based on its name.
Definition: space.c:1006
char spob_getColourChar(const Spob *p)
Gets the spob colour char.
Definition: space.c:1834
StarSystem * cur_system
Definition: space.c:105
const char * spob_name(const Spob *p)
Gets the translated name of a spob.
Definition: space.c:1705
The representation of an in-game pilot.
Definition: pilot.h:210
Solid * solid
Definition: pilot.h:220
double dtimer
Definition: pilot.h:361
double dtimer_accum
Definition: pilot.h:362
ShipStats stats
Definition: pilot.h:286
double shield
Definition: pilot.h:246
double thrust
Definition: pilot.h:235
int nav_hyperspace
Definition: pilot.h:337
double armour_max
Definition: pilot.h:247
double speed
Definition: pilot.h:237
int lockons
Definition: pilot.h:366
double fuel
Definition: pilot.h:253
char * name
Definition: pilot.h:212
double fuel_consumption
Definition: pilot.h:254
int nav_spob
Definition: pilot.h:336
double turn
Definition: pilot.h:240
double armour
Definition: pilot.h:244
double shield_max
Definition: pilot.h:248
double autonav_reset_shield
Definition: conf.h:157
double compression_velocity
Definition: conf.h:148
double autonav_reset_dist
Definition: conf.h:156
double compression_mult
Definition: conf.h:149
Pilot * p
Definition: player.h:101
int autonav
Definition: player.h:107
double autonav_timer
Definition: player.h:112
double tc_max
Definition: player.h:111
char autonavcol
Definition: player.h:110
char * autonavmsg
Definition: player.h:109
vec2 autonav_pos
Definition: player.h:108
double speed
Definition: player.h:115
int misc_instant_jump
Definition: shipstats.h:298
vec2 vel
Definition: physics.h:21
double thrust
Definition: physics.h:23
double mass
Definition: physics.h:18
vec2 pos
Definition: physics.h:22
Represents a Space Object (SPOB), including and not limited to planets, stations, wormholes,...
Definition: space.h:88
Represents a 2d vector.
Definition: vec2.h:32
double y
Definition: vec2.h:34
double angle
Definition: vec2.h:36
double x
Definition: vec2.h:33
void window_destroy(unsigned int wid)
Kills the window.
Definition: toolkit.c:1042