20#include "player_autonav.h"
43 return pow( p->solid.mass, 1./3. ) * 1.25 / (p->stats.ew_hide * p->stats.ew_signature) * p->stats.ew_scanned_time;
73 if (p->target == p->id)
75 return (p->scantimer < 0.);
83 p->ew_detection = p->ew_mass * p->ew_asteroid * p->stats.ew_hide;
84 p->ew_signature = p->ew_detection * 0.75 *
ew_interference * p->stats.ew_signature;
86 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;
116 if (p->scantimer < 0.)
128 if (p->scantimer < 0.) {
129 HookParam hparam = { .type = HOOK_PARAM_PILOT };
132 pilot_runHookParam( p, PILOT_HOOK_SCAN, &hparam, 1 );
135 pilot_runHookParam( t, PILOT_HOOK_SCANNED, &hparam, 1 );
154 return pow(mass, 1./1.8) * 350.;
168 return 1. / (1. + 0.4*
cur_system->asteroids[infield].density);
180 if (!pilot_isFlag(p,PILOT_STEALTH))
186 if (jp_isFlag(jp,JP_EXITONLY) || jp_isFlag(jp,JP_HIDDEN))
188 double d2 = vec2_dist2( &jp->pos, &p->solid.pos );
189 if (d2 <=
pow2(EW_JUMP_BONUS_RANGE))
190 return MAX( 0.5, sqrt(d2) / EW_JUMP_BONUS_RANGE);
223 double d =
pow2(x-p->solid.pos.x) +
pow2(y-p->solid.pos.y);
225 double sense =
MAX( 0., sr * p->stats.ew_detect );
250 *dist2 = vec2_dist2( &p->solid.pos, &target->
solid.
pos );
253 if ((pilot_isPlayer(p) && pilot_isFlag(target, PILOT_VISPLAYER)) ||
254 pilot_isFlag(target, PILOT_VISIBLE) ||
259 if (pilot_isFlag( target, PILOT_STEALTH ) && !
pilot_areAllies( p, target ))
263 d = (dist2!=NULL ? *dist2 : vec2_dist2( &p->solid.pos, &target->
solid.
pos ) );
291 sense = EW_SPOBDETECT_DIST;
294 d = vec2_dist2( &p->solid.pos, &pnt->
pos );
295 if (
d <
pow2(
MAX( 0., sense * p->stats.ew_detect * pnt->
hide) ) )
322 as = &f->asteroids[ast];
325 sense = EW_ASTEROID_DIST;
328 d = vec2_dist2( &p->solid.pos, &as->
sol.
pos );
331 if (
d <
pow2(
MAX( 0., sense * p->stats.ew_detect ) ) )
359 if (jp_isFlag(jp, JP_EXITONLY))
367 sense = EW_JUMPDETECT_DIST * p->stats.ew_jump_detect * p->stats.ew_detect;
369 if (jp_isFlag(jp, JP_HIDDEN))
370 sense *= p->stats.misc_hidden_jump_detect;
373 d = vec2_dist2( &p->solid.pos, &jp->pos );
374 if (
d <
pow2(
MAX( 0., sense * hide )))
391 double mod = p->stats.ew_track * p->stats.ew_detect;
392 return CLAMP( 0., 1., (t->
ew_signature * mod - trackmin) / (trackmax - trackmin + 1e-5) );
414 if (isplayer != NULL)
423 if (pilot_isDisabled(t))
429 if (pilot_isFlag(t, PILOT_LANDING) ||
430 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 );
541 p->ew_stealth_timer = 0.;
544 const HookParam hparam = { .type = HOOK_PARAM_BOOL, .u.b = 1 };
545 pilot_runHookParam( p, PILOT_HOOK_STEALTH, &hparam, 1 );
554 if (!pilot_isFlag( p, PILOT_STEALTH ))
556 pilot_rmFlag( p, PILOT_STEALTH );
557 p->ew_stealth_timer = 0.;
562 const HookParam hparam = { .type = HOOK_PARAM_BOOL, .u.b = 0 };
563 pilot_runHookParam( p, PILOT_HOOK_STEALTH, &hparam, 1 );
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.
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_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.
int pilot_areAllies(const Pilot *p, const Pilot *target)
Like areAllies but for pilots.
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.
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.
void pilot_weapSetAIClear(Pilot *p)
Useful function for AI, clears activeness of all weapon sets.
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,...