19#include "player_autonav.h"
44 return pow( p->solid.mass, 1. / 3. ) * 1.25 /
45 ( p->stats.ew_hide * p->stats.ew_signature ) *
46 p->stats.ew_scanned_time;
76 if ( p->target == p->id )
78 return ( p->scantimer < 0. );
86 p->ew_detection = p->ew_mass * p->ew_asteroid * p->stats.ew_hide;
92 MAX( 1000., p->ew_mass * p->stats.ew_hide * 0.25 * p->stats.ew_stealth ) *
123 if ( p->scantimer < 0. )
132 if ( vec2_dist2( &p->solid.pos, &t->
solid.
pos ) <
133 pow2(
MAX( 0., p->stats.ew_detect * p->stats.ew_track *
137 if ( p->scantimer < 0. ) {
138 HookParam hparam = { .type = HOOK_PARAM_PILOT };
141 pilot_runHookParam( p, PILOT_HOOK_SCAN, &hparam, 1 );
144 pilot_runHookParam( t, PILOT_HOOK_SCANNED, &hparam, 1 );
164 return pow( mass, 1. / 1.8 ) * 350.;
178 return 1. / ( 1. + 0.4 *
cur_system->asteroids[infield].density );
190 if ( !pilot_isFlag( p, PILOT_STEALTH ) )
196 if ( jp_isFlag( jp, JP_EXITONLY ) || jp_isFlag( jp, JP_HIDDEN ) )
198 double d2 = vec2_dist2( &jp->pos, &p->solid.pos );
199 if ( d2 <=
pow2( EW_JUMP_BONUS_RANGE ) )
200 return MAX( 0.5, sqrt( d2 ) / EW_JUMP_BONUS_RANGE );
233 double d =
pow2( x - p->solid.pos.x ) +
pow2( y - p->solid.pos.y );
235 double sense =
MAX( 0., sr * p->stats.ew_detect );
236 if (
d <
pow2( sense ) )
262 *dist2 = vec2_dist2( &p->solid.pos, &target->
solid.
pos );
265 if ( ( pilot_isPlayer( p ) && pilot_isFlag( target, PILOT_VISPLAYER ) ) ||
266 pilot_isFlag( target, PILOT_VISIBLE ) || target->
parent == p->id )
270 if ( pilot_isFlag( target, PILOT_STEALTH ) && !
pilot_areAllies( p, target ) )
274 d = ( dist2 != NULL ? *dist2
275 : vec2_dist2( &p->solid.pos, &target->
solid.
pos ) );
276 if (
d <
pow2(
MAX( 0., p->stats.ew_detect * p->stats.ew_track *
305 sense = EW_SPOBDETECT_DIST;
308 d = vec2_dist2( &p->solid.pos, &pnt->
pos );
309 if (
d <
pow2(
MAX( 0., sense * p->stats.ew_detect * pnt->
hide ) ) )
337 as = &f->asteroids[ast];
340 sense = EW_ASTEROID_DIST;
343 d = vec2_dist2( &p->solid.pos, &as->
sol.
pos );
347 if (
d <
pow2(
MAX( 0., sense * p->stats.ew_detect ) ) )
376 if ( jp_isFlag( jp, JP_EXITONLY ) )
385 sense = EW_JUMPDETECT_DIST * p->stats.ew_jump_detect * p->stats.ew_detect;
387 if ( jp_isFlag( jp, JP_HIDDEN ) )
388 sense *= p->stats.misc_hidden_jump_detect;
391 d = vec2_dist2( &p->solid.pos, &jp->pos );
392 if (
d <
pow2(
MAX( 0., sense * hide ) ) )
413 mod = p->stats.ew_track * p->stats.ew_detect;
417 MAX( trackmax - trackmin,
442 if ( isplayer != NULL )
446 for (
int i = 0; i <
array_size( ps ); i++ ) {
451 if ( pilot_isDisabled( t ) )
457 if ( pilot_isFlag( t, PILOT_LANDING ) ||
458 pilot_isFlag( t, PILOT_TAKEOFF ) )
470 dist = vec2_dist2( &p->solid.pos, &t->
solid.
pos );
472 if ( ( close != NULL ) && !pilot_isFlag( t, PILOT_STEALTH ) &&
480 *mod += 1.0 - sqrt( dist ) / ( p->ew_stealth * t->
stats.
ew_detect );
484 if ( ( isplayer != NULL ) && pilot_isPlayer( t ) )
499 int n, close, isplayer;
502 if ( !pilot_isFlag( p, PILOT_STEALTH ) )
506 if ( pilot_isPlayer( p ) ) {
507 if ( pilot_isFlag( p, PILOT_NONTARGETABLE ) )
520 p->ew_stealth_timer += dt * 5e3 / p->ew_stealth;
521 if ( p->ew_stealth_timer > 1. )
522 p->ew_stealth_timer = 1.;
526 p->ew_stealth_timer -=
527 dt * ( p->ew_stealth / 10e3 + mod ) * p->stats.ew_stealth_timer;
528 if ( p->ew_stealth_timer < 0. ) {
530 if ( pilot_isPlayer( p ) )
547 if ( pilot_isFlag( p, PILOT_STEALTH ) )
557 pilot_setFlag( p, PILOT_STEALTH );
560 pilot_rmFlag( p, PILOT_STEALTH );
574 p->ew_stealth_timer = 0.;
577 const HookParam hparam = { .type = HOOK_PARAM_BOOL, .u.b = 1 };
578 pilot_runHookParam( p, PILOT_HOOK_STEALTH, &hparam, 1 );
587 if ( !pilot_isFlag( p, PILOT_STEALTH ) )
589 pilot_rmFlag( p, PILOT_STEALTH );
590 p->ew_stealth_timer = 0.;
595 const HookParam hparam = { .type = HOOK_PARAM_BOOL, .u.b = 0 };
596 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_reputationColourChar 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.
void pilot_weapSetUpdateOutfitState(Pilot *p)
Updates the local state of all the pilot's outfits based on the weapon sets.
int pilot_outfitOffAllStealth(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.
union HookParam::@114305201244257020071001257133270030317263020235 u
The representation of an in-game pilot.
Represents a Space Object (SPOB), including and not limited to planets, stations, wormholes,...