From 93dd038acea20774143dde34bd924f6eb0d3568a Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sat, 29 Dec 2012 23:23:44 +0000 Subject: Added sound effects for weapon mounting and target hitting, enabled projectile soundname transfer in networked games, resolved an issue where a ship was able to shoot itself, bumped network protocol to 26, --- src/game/base/ship.cc | 53 +++++++++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 23 deletions(-) (limited to 'src/game/base/ship.cc') diff --git a/src/game/base/ship.cc b/src/game/base/ship.cc index 2368352..ea793af 100644 --- a/src/game/base/ship.cc +++ b/src/game/base/ship.cc @@ -479,8 +479,8 @@ void Ship::hit(core::Entity *other) core::Player *assassin = 0; - if (spacemine->ownerid()) { - assassin = core::server()->find_player(spacemine->ownerid()); + if (spacemine->owner_id()) { + assassin = core::server()->find_player(spacemine->owner_id()); } if (assassin) { @@ -506,11 +506,16 @@ void Ship::hit(core::Entity *other) core::EntityProjectile *projectile = static_cast(other); // don't hit self - if ((projectile->state() != core::Entity::Destroyed) && - (projectile->ownerid() != id())) { - + if ((projectile->state() != core::Entity::Destroyed) && (projectile->spawn_id() != id())) { + ship_armor -= projectile->damage(); + core::Player *assassin = 0; + + if (projectile->owner_id()) { + assassin = core::server()->find_player(projectile->owner_id()); + } + // destroyed if (ship_armor <= 0) { explode(); @@ -520,11 +525,6 @@ void Ship::hit(core::Entity *other) std::string message("^B"); message.append(owner()->name()); - core::Player *assassin = 0; - - if (projectile->ownerid()) { - assassin = core::server()->find_player(projectile->ownerid()); - } if (assassin) { if (assassin == owner()) { @@ -540,6 +540,16 @@ void Ship::hit(core::Entity *other) } else { die(); } + + // send kill sound to assassin + if (assassin) { + assassin->sound("game/target_kill"); + } + } else { + // send hit sound to assassin + if (assassin) { + assassin->sound("game/target_hit"); + } } } } @@ -892,9 +902,8 @@ void Ship::frame(const unsigned long elapsed) */ EntityControlable::frame(elapsed); - - - // TODO move to core:: + + // fire weapons if (model() && slots() && (state() == core::Entity::Normal) && has_controlflag(core::EntityControlable::ControlFlagFire)) { const float modelscale = radius() / model()->radius(); @@ -907,25 +916,23 @@ void Ship::frame(const unsigned long elapsed) const Weapon *weapon = static_cast(slot->item()->info()); if ((weapon->subtype() == Weapon::Cannon) && (weapon->projectile_interval() > 0) && (slot->last_fired() + weapon->projectile_interval() <= core::server()->timestamp())) { - slot->set_last_fired(core::server()->timestamp()); - - core::EntityProjectile *projectile = new core::EntityProjectile(); + // spawn a new projectile + core::EntityProjectile *projectile = new core::EntityProjectile(this); + 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_color(color()); - projectile->set_color_second(color_second()); - projectile->set_zone(zone()); + projectile->set_axis(axis() * slot->axis()); projectile->set_location(location() + (axis() * slot->location() * modelscale) + projectile->axis().forward() * projectile->radius()); - if (owner()) { - projectile->set_ownerid(owner()->id()); - } - projectile->set_speed(weapon->projectile_speed()); + projectile->set_speed(weapon->projectile_speed()); + projectile->reset(); + slot->set_last_fired(core::server()->timestamp()); + } } } -- cgit v1.2.3