[Change] Reverted PID changes and changed headhunter missile to "smart"
This commit is contained in:
parent
7ec186bee9
commit
e139172fed
@ -95,7 +95,7 @@
|
||||
<description>The Headhunter Launcher is one of the most used missile launcher by the security companies. Much more reliable then the regular missiles, Headhunters feature more sensors and an advanced tracking system making them much better at hitting their targets.</description>
|
||||
<gfx_store>missile</gfx_store>
|
||||
</general>
|
||||
<specific type="5" secondary="1">
|
||||
<specific type="7" secondary="1">
|
||||
<ammo>Headhunter</ammo>
|
||||
<delay>1400</delay>
|
||||
</specific>
|
||||
@ -109,7 +109,7 @@
|
||||
<description>Headhunters first gained fame in the crush of the Vroen, a fearsome battle against a pirate stronghold where the Empire crushed the pirates thanks to the advanced guidance system on the Headhunter. Now used by mercenaries and bounty hunters all over.</description>
|
||||
<gfx_store>missile</gfx_store>
|
||||
</general>
|
||||
<specific type="6">
|
||||
<specific type="8">
|
||||
<gfx>headhunter</gfx>
|
||||
<sound>missile</sound>
|
||||
<spfx>ExpM</spfx>
|
||||
|
@ -245,11 +245,13 @@ static void fps_control(void) {
|
||||
|
||||
// Update the game.
|
||||
static void update_all(void) {
|
||||
#if 0
|
||||
if(dt > 1./30.) {
|
||||
// Slow timers down and re-run calculations.
|
||||
pause_delay((unsigned int)dt*1000.);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
space_update(dt);
|
||||
weapons_update(dt);
|
||||
spfx_update(dt);
|
||||
|
63
src/weapon.c
63
src/weapon.c
@ -152,41 +152,10 @@ static void think_seeker(Weapon* w, const double dt) {
|
||||
|
||||
// ========================================================
|
||||
// Smart seeker brain. Much better at homing.
|
||||
//
|
||||
// SYSTEM DYNAMICS
|
||||
// INPUT:
|
||||
// MV = missile velocity
|
||||
// RP = target relative position.
|
||||
//
|
||||
// Constants:
|
||||
// KE = error constant.
|
||||
// KF = face constant.
|
||||
//
|
||||
// INTERNAL VARIABLES:
|
||||
// FD = face dir.
|
||||
// E = error.
|
||||
// PID = PID
|
||||
//
|
||||
// OUTPUT:
|
||||
// T = turn modifier.
|
||||
//
|
||||
// -- Fancy diagram.
|
||||
//
|
||||
// MV + FD + T
|
||||
// ---->0----->[PID]----[KF]---+---->
|
||||
// -^ -^ |
|
||||
// RP | | E |
|
||||
// -----+ |------[KE]------
|
||||
//
|
||||
// ========================================================
|
||||
static void think_smart(Weapon* w, const double dt) {
|
||||
Vec2 tv;
|
||||
|
||||
// Controler stuff.
|
||||
double ke, kf; // Constants
|
||||
double fd, e, ed, ei; // Internal variables.
|
||||
double t; // Internal variables.
|
||||
double kp, ki, kd; // PID.
|
||||
Vec2 sv, tv;
|
||||
double t;
|
||||
|
||||
if(w->target == w->parent) return; // No self shooting here.
|
||||
|
||||
@ -198,32 +167,16 @@ static void think_smart(Weapon* w, const double dt) {
|
||||
}
|
||||
|
||||
if(SDL_GetTicks() > (w->timer + w->outfit->u.amm.lockon)) {
|
||||
// Begin controler.
|
||||
// Constants.
|
||||
kp = 1.;
|
||||
kd = 1.;
|
||||
ki = 1.;
|
||||
|
||||
// Calculate fd.
|
||||
vect_cset(&tv, p->solid->pos.x - w->solid->pos.x,
|
||||
p->solid->pos.y - w->solid->pos.y);
|
||||
e = angle_diff(VANGLE(w->solid->vel), VANGLE(tv));
|
||||
vect_cset(&tv, VX(p->solid->pos) + dt*VX(p->solid->vel),
|
||||
VY(p->solid->pos) + dt*VY(p->solid->vel));
|
||||
|
||||
e = fd;
|
||||
ed = fd - ke*w->pid_last;
|
||||
w->pid_int += e;
|
||||
if(w->pid_int > IMAX) w->pid_int = IMAX;
|
||||
else if(w->pid_int < IMIN) w->pid_int = IMIN;
|
||||
ei = w->pid_int;
|
||||
t = e*kp + ed*kd + ei*ki;
|
||||
vect_cset(&sv, VX(w->solid->pos) + dt*VX(w->solid->vel),
|
||||
VY(w->solid->pos) + dt*VY(w->solid->vel));
|
||||
|
||||
// Final output.
|
||||
t *= kf;
|
||||
w->pid_last = t;
|
||||
|
||||
// End controller.
|
||||
t = -angle_diff(w->solid->dir, vect_angle(&tv, &sv));
|
||||
|
||||
w->solid->dir_vel = t * w->outfit->u.amm.turn; // Face the target.
|
||||
|
||||
if(w->solid->dir_vel > w->outfit->u.amm.turn)
|
||||
w->solid->dir_vel = w->outfit->u.amm.turn;
|
||||
else if(w->solid->dir_vel < -w->outfit->u.amm.turn)
|
||||
|
Loading…
Reference in New Issue
Block a user