From e3e635c7f830bb03a4a04d0f164c78105cc69197 Mon Sep 17 00:00:00 2001 From: Allanis Date: Wed, 12 Mar 2014 19:59:01 +0000 Subject: [PATCH] [Change] Turrets should just shoot at the current position if the target isn't in range. --- src/weapon.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/weapon.c b/src/weapon.c index e50823c..c999736 100644 --- a/src/weapon.c +++ b/src/weapon.c @@ -723,15 +723,27 @@ static Weapon* weapon_create(const Outfit* outfit, const double dir, const Vec2* /* Get the distance. */ dist = vect_dist(pos, &pilot_target->solid->pos); - /* Time for shots to reach that distance. */ - t = dist / w->outfit->u.blt.speed; + /* Aim. */ + if(dist > outfit->u.blt.range*1.2) { + x = pilot_target->solid->pos.x - pos->x; + y = pilot_target->solid->pos.y - pos->y; + } else { + /* + * Try to predict where the enemy will be. + * Time for shots to reach that distance. + */ + t = dist / w->outfit->u.blt.speed; - /* Position is calculated on where it should be. */ - x = (pilot_target->solid->pos.x + pilot_target->solid->vel.x*t) - - (pos->x + vel->x*t); - y = (pilot_target->solid->pos.y + pilot_target->solid->vel.y*t) - - (pos->y + vel->y*t); + /* Position is calculated on where it should be. */ + x = (pilot_target->solid->pos.x + pilot_target->solid->vel.x*t) + - (pos->x + vel->x * t); + y = (pilot_target->solid->pos.y + pilot_target->solid->vel.y * t) + - (pos->y + vel->y * t); + } + + /* Set angle to face. */ + vect_cset(&v, x, y); rdir = VANGLE(v); } } else /* Fire straight. */