20#include "player_autonav.h"
23#define EW_ASTEROID_DIST 7.5e3
24#define EW_JUMPDETECT_DIST 7.5e3
25#define EW_SPOBDETECT_DIST 20e3
47 return pow( p->solid->mass, 1./3. ) * 1.25 * p->stats.ew_hide * p->stats.ew_scanned_time;
77 if (p->target == p->id)
79 return (p->scantimer < 0.);
87 p->ew_detection = p->ew_mass * p->ew_asteroid / p->stats.ew_hide;
88 p->ew_evasion = p->ew_detection * 0.75 *
ew_interference / p->stats.ew_evade;
90 p->ew_stealth =
MAX( 1000., p->ew_mass / p->stats.ew_hide * 0.25 / p->stats.ew_stealth ) * p->ew_asteroid *
ew_interference * p->ew_jumppoint;
120 if (p->scantimer < 0.)
129 if (vec2_dist2( &p->solid->pos, &t->
solid->
pos ) <
pow2(
MAX( 0., p->stats.ew_detect * p->stats.ew_track * t->
ew_evasion ) )) {
132 if (p->scantimer < 0.) {
158 return pow(mass, 1./1.8) * 350.;
172 return 1. / (1. + 0.4*
cur_system->asteroids[infield].density);
184 if (!pilot_isFlag(p,PILOT_STEALTH))
190 if (jp_isFlag(jp,JP_EXITONLY) || jp_isFlag(jp,JP_HIDDEN))
192 double d2 = vec2_dist2( &jp->pos, &p->solid->pos );
193 if (d2 <=
pow2(EW_JUMP_BONUS_RANGE))
194 return MAX( 0.5, sqrt(d2) / EW_JUMP_BONUS_RANGE);
227 double d =
pow2(x-p->solid->pos.x) +
pow2(y-p->solid->pos.y);
248 *dist2 = vec2_dist2( &p->solid->pos, &target->
solid->
pos );
251 if ((pilot_isPlayer(p) && pilot_isFlag(target, PILOT_VISPLAYER)) ||
252 pilot_isFlag(target, PILOT_VISIBLE) ||
257 if (pilot_isFlag( target, PILOT_STEALTH ))
261 d = (dist2!=NULL ? *dist2 : vec2_dist2( &p->solid->pos, &target->
solid->
pos ) );
262 if (
d <
pow2(
MAX( 0., p->stats.ew_detect * p->stats.ew_track * target->
ew_evasion )))
289 sense = EW_SPOBDETECT_DIST;
292 d = vec2_dist2( &p->solid->pos, &pnt->
pos );
293 if (
d <
pow2(
MAX( 0., sense * p->stats.ew_detect * pnt->
hide) ) )
320 as = &f->asteroids[ast];
323 sense = EW_ASTEROID_DIST;
326 d = vec2_dist2( &p->solid->pos, &as->
pos );
329 if (
d <
pow2(
MAX( 0., sense * p->stats.ew_detect ) ) )
357 if (jp_isFlag(jp, JP_EXITONLY))
365 sense = EW_JUMPDETECT_DIST * p->stats.ew_jump_detect * p->stats.ew_detect;
367 if (jp_isFlag(jp, JP_HIDDEN))
368 sense *= p->stats.misc_hidden_jump_detect;
371 d = vec2_dist2( &p->solid->pos, &jp->pos );
372 if (
d <
pow2(
MAX( 0., sense * hide )))
389 double mod = p->stats.ew_track * p->stats.ew_detect;
390 return CLAMP( 0., 1., (t->
ew_evasion * mod - trackmin) / (trackmax - trackmin) );
412 if (isplayer != NULL)
421 if (pilot_isDisabled(t))
427 if (pilot_isFlag(t, PILOT_LANDING) ||
428 pilot_isFlag(t, PILOT_TAKEOFF))
442 dist = vec2_dist2( &p->solid->pos, &t->
solid->
pos );
444 if ((close != NULL) && !pilot_isFlag(t,PILOT_STEALTH) &&
455 if ((isplayer != NULL) && pilot_isPlayer(t))
470 int n, close, isplayer;
473 if (!pilot_isFlag( p, PILOT_STEALTH ))
477 if (pilot_isPlayer(p)) {
478 if (pilot_isFlag(p, PILOT_NONTARGETABLE))
492 p->ew_stealth_timer += dt * 5e3 / p->ew_stealth;
493 if (p->ew_stealth_timer > 1.)
494 p->ew_stealth_timer = 1.;
498 p->ew_stealth_timer -= dt * (p->ew_stealth / 10e3 + mod) * p->stats.ew_stealth_timer;
499 if (p->ew_stealth_timer < 0.) {
501 if (pilot_isPlayer(p))
517 if (pilot_isFlag( p, PILOT_STEALTH ))
525 pilot_setFlag( p, PILOT_STEALTH );
528 pilot_rmFlag( p, PILOT_STEALTH );
538 p->ew_stealth_timer = 0.;
541 const HookParam hparam = { .
type = HOOK_PARAM_BOOL, .u.b = 1 };
551 if (!pilot_isFlag( p, PILOT_STEALTH ))
553 pilot_rmFlag( p, PILOT_STEALTH );
554 p->ew_stealth_timer = 0.;
559 const HookParam hparam = { .
type = HOOK_PARAM_BOOL, .u.b = 0 };
void ai_discovered(Pilot *discovered)
Triggers the discovered() function in the pilot's AI.
Provides macros to work with dynamic arrays.
static ALWAYS_INLINE int array_size(const void *array)
Returns number of elements in the array.
int asteroids_inField(const vec2 *p)
See if the position is in an asteroid field.
int areAllies(int a, int b)
Checks whether two factions are allies or not.
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.
char pilot_getFactionColourChar(const Pilot *p)
Gets the faction colour char, works like faction_getColourChar but for a pilot.
Pilot * pilot_getTarget(Pilot *p)
Gets the target of a pilot using a fancy caching system.
int pilot_isFriendly(const Pilot *p)
Checks to see if pilot is friendly to the player.
int pilot_hasIllegal(const Pilot *p, int faction)
Checks to see if the pilot has illegal stuf to a faction.
Pilot *const * pilot_getAll(void)
Gets the pilot stack.
int pilot_canTarget(const Pilot *p)
Same as pilot_validTarget but without the range check.
void pilot_ewUpdateStealth(Pilot *p, double dt)
Updates the stealth mode and checks to see if it is getting broken.
int pilot_inRangePilot(const Pilot *p, const Pilot *target, double *dist2)
Check to see if a pilot is in sensor range of another.
void pilot_ewUpdateDynamic(Pilot *p, double dt)
Updates the pilot's dynamic electronic warfare properties.
int pilot_ewScanCheck(const Pilot *p)
Checks to see if a scan is done.
static double pilot_ewJumpPoint(const Pilot *p)
Gets the electronic warfare jump point modifier.
int pilot_inRangeSpob(const Pilot *p, int target)
Check to see if a spob is in sensor range of the pilot.
static double ew_interference
void pilot_updateSensorRange(void)
Updates the system's base sensor range.
void pilot_destealth(Pilot *p)
Destealths a pilot.
int pilot_inRangeJump(const Pilot *p, int i)
Check to see if a jump point is in sensor range of the pilot.
void pilot_ewScanStart(Pilot *p)
Initializes the scan timer for a pilot.
double pilot_ewWeaponTrack(const Pilot *p, const Pilot *t, double trackmin, double trackmax)
Calculates the weapon lead (1. is 100%, 0. is 0%)..
void pilot_ewUpdateStatic(Pilot *p)
Updates the pilot's static electronic warfare properties.
int pilot_inRangeAsteroid(const Pilot *p, int ast, int fie)
Check to see if an asteroid is in sensor range of the pilot.
static int pilot_ewStealthGetNearby(const Pilot *p, double *mod, int *close, int *isplayer)
Checks to see if there are pilots nearby to a stealthed pilot that could break stealth.
static void pilot_ewUpdate(Pilot *p)
Updates all the internal values.
double pilot_sensorRange(void)
Returns the default sensor range for the current system.
static double pilot_ewAsteroid(const Pilot *p)
Gets the electronic warfare asteroid modifier.
double pilot_ewScanTime(const Pilot *p)
Gets the time it takes to scan a pilot.
int pilot_inRange(const Pilot *p, double x, double y)
Check to see if a position is in range of the pilot.
static double pilot_ewMass(double mass)
Gets the electronic warfare mass modifier for a given mass.
int pilot_stealth(Pilot *p)
Stealths a pilot.
int pilot_runHookParam(Pilot *p, int hook_type, const HookParam *param, int nparam)
Tries to run a pilot hook if he has it.
void pilot_calcStats(Pilot *pilot)
Recalculates the pilot's stats based on his outfits.
int pilot_outfitLOnstealth(Pilot *pilot)
Runs the pilot's Lua outfits onhit script.
void pilot_outfitLOnscan(Pilot *pilot)
Runs Lua outfits when pilot scanned their target.
void pilot_outfitLOnscanned(Pilot *pilot, const Pilot *scanner)
Runs Lua outfits when pilot was scanned by scanner.
int pilot_outfitOffAll(Pilot *p)
Disables all active outfits for a pilot.
void player_autonavResetSpeed(void)
Resets the game speed.
Represents an asteroid field anchor.
Represents a single asteroid.
The actual hook parameter.
The representation of an in-game pilot.
Represents a Space Object (SPOB), including and not limited to planets, stations, wormholes,...