From e139172fede6b4211955996a6e581b4de26db97e Mon Sep 17 00:00:00 2001 From: Allanis Date: Tue, 26 Mar 2013 16:48:42 +0000 Subject: [PATCH] [Change] Reverted PID changes and changed headhunter missile to "smart" --- dat/outfit.xml | 4 ++-- src/lephisto.c | 2 ++ src/weapon.c | 63 +++++++------------------------------------------- 3 files changed, 12 insertions(+), 57 deletions(-) diff --git a/dat/outfit.xml b/dat/outfit.xml index 3b79166..e973ee0 100644 --- a/dat/outfit.xml +++ b/dat/outfit.xml @@ -95,7 +95,7 @@ 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. missile - + Headhunter 1400 @@ -109,7 +109,7 @@ 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. missile - + headhunter missile ExpM diff --git a/src/lephisto.c b/src/lephisto.c index e951c87..4a9ffc3 100644 --- a/src/lephisto.c +++ b/src/lephisto.c @@ -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); diff --git a/src/weapon.c b/src/weapon.c index 2b645c7..e4eceba 100644 --- a/src/weapon.c +++ b/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)