diff options
Diffstat (limited to 'src/game')
-rw-r--r-- | src/game/base/ship.cc | 46 |
1 files changed, 33 insertions, 13 deletions
diff --git a/src/game/base/ship.cc b/src/game/base/ship.cc index ea793af..219cb0c 100644 --- a/src/game/base/ship.cc +++ b/src/game/base/ship.cc @@ -917,22 +917,42 @@ void Ship::frame(const unsigned long elapsed) const Weapon *weapon = static_cast<const Weapon *>(slot->item()->info()); if ((weapon->subtype() == Weapon::Cannon) && (weapon->projectile_interval() > 0) && (slot->last_fired() + weapon->projectile_interval() <= core::server()->timestamp())) { - // spawn a new projectile - core::EntityProjectile *projectile = new core::EntityProjectile(this); + // aim + const float projectile_radius = 0.01f; // FIXME this should be defined somewhere + + math::Axis projectile_axis(axis() * slot->axis()); + math::Vector3f projectile_location(location() + (axis() * slot->location() * modelscale) + projectile_axis.forward() * projectile_radius); + math::Vector3f projectile_direction(target_aim - projectile_location); + projectile_direction.normalize(); + float cosa = math::dotproduct(projectile_direction, projectile_axis.forward()); + + // fire a projectile if the angle between the aim direction and the slot's forward direction is small enough + // TODO configurable aim cone + if (cosa > 0.5f) { + // aim + math::Vector3f normal(math::crossproduct(projectile_direction, projectile_axis.forward())); + if (normal.length() > MIN_DELTA) { + float sina = sqrt(1 - cosa * cosa); + + normal.normalize(); + projectile_axis.rotate(normal, cosa, sina); + } - projectile->set_damage(weapon->damage()); - projectile->set_lifespan(weapon->projectile_lifespan()); - projectile->set_projectile_modelname(weapon->projectile_modelname()); - projectile->set_projectile_soundname(weapon->projectile_soundname()); - - projectile->set_axis(axis() * slot->axis()); - projectile->set_location(location() + (axis() * slot->location() * modelscale) + projectile->axis().forward() * projectile->radius()); - projectile->set_speed(weapon->projectile_speed()); + // spawn a new projectile + core::EntityProjectile *projectile = new core::EntityProjectile(this); - projectile->reset(); - - slot->set_last_fired(core::server()->timestamp()); + projectile->set_damage(weapon->damage()); + projectile->set_lifespan(weapon->projectile_lifespan()); + projectile->set_projectile_modelname(weapon->projectile_modelname()); + projectile->set_projectile_soundname(weapon->projectile_soundname()); + + projectile->set_axis(projectile_axis); + projectile->set_location(projectile_location); + projectile->set_speed(weapon->projectile_speed()); + projectile->reset(); + slot->set_last_fired(core::server()->timestamp()); + } } } } |