[Change] Turrets should just shoot at the current position if the target
isn't in range.
This commit is contained in:
parent
c37e109ffc
commit
e3e635c7f8
14
src/weapon.c
14
src/weapon.c
@ -723,15 +723,27 @@ static Weapon* weapon_create(const Outfit* outfit, const double dir, const Vec2*
|
|||||||
/* Get the distance. */
|
/* Get the distance. */
|
||||||
dist = vect_dist(pos, &pilot_target->solid->pos);
|
dist = vect_dist(pos, &pilot_target->solid->pos);
|
||||||
|
|
||||||
/* Time for shots to reach that distance. */
|
/* 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;
|
t = dist / w->outfit->u.blt.speed;
|
||||||
|
|
||||||
/* Position is calculated on where it should be. */
|
/* Position is calculated on where it should be. */
|
||||||
x = (pilot_target->solid->pos.x + pilot_target->solid->vel.x*t)
|
x = (pilot_target->solid->pos.x + pilot_target->solid->vel.x*t)
|
||||||
- (pos->x + vel->x * t);
|
- (pos->x + vel->x * t);
|
||||||
|
|
||||||
y = (pilot_target->solid->pos.y + pilot_target->solid->vel.y * t)
|
y = (pilot_target->solid->pos.y + pilot_target->solid->vel.y * t)
|
||||||
- (pos->y + vel->y * t);
|
- (pos->y + vel->y * t);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set angle to face. */
|
||||||
|
vect_cset(&v, x, y);
|
||||||
rdir = VANGLE(v);
|
rdir = VANGLE(v);
|
||||||
}
|
}
|
||||||
} else /* Fire straight. */
|
} else /* Fire straight. */
|
||||||
|
Loading…
Reference in New Issue
Block a user