diff options
author | Stijn Buys <ingar@osirion.org> | 2012-12-29 23:23:44 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2012-12-29 23:23:44 +0000 |
commit | 93dd038acea20774143dde34bd924f6eb0d3568a (patch) | |
tree | c357b11eeb6eb455543180ea30fa04f2054ac0d4 /src/game/base | |
parent | 962a744f6782fbcfadf7771ceb157bd82f369ab3 (diff) |
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,
Diffstat (limited to 'src/game/base')
-rw-r--r-- | src/game/base/game.cc | 12 | ||||
-rw-r--r-- | src/game/base/ship.cc | 53 | ||||
-rw-r--r-- | src/game/base/spacemine.cc | 18 | ||||
-rw-r--r-- | src/game/base/spacemine.h | 10 |
4 files changed, 59 insertions, 34 deletions
diff --git a/src/game/base/game.cc b/src/game/base/game.cc index 1be0b77..a44650b 100644 --- a/src/game/base/game.cc +++ b/src/game/base/game.cc @@ -1024,14 +1024,14 @@ void Game::func_drop(core::Player *player, const std::string &args) SpaceMine *spacemine = new SpaceMine(weapon); spacemine->set_color(ship->color()); - spacemine->set_ownerid(player->id()); + spacemine->set_owner_id(player->id()); spacemine->set_color_second(ship->color_second()); spacemine->set_location(ship->location() + ship->axis().forward() * -1.0f * (ship->radius() + spacemine->radius())); spacemine->set_axis(ship->axis()); spacemine->set_zone(ship->zone()); player->send(weapon->name() + " ejected"); - player->sound("fx/eject"); + player->sound("game/eject"); spacemine->reset(); @@ -1104,7 +1104,7 @@ void Game::func_eject(core::Player *player, const std::string &args) std::stringstream msgstr; msgstr << "^BDestroyed " << amount << " " << aux::plural("unit", amount) << " of " << item->info()->name(); ejector->owner()->send(msgstr.str()); - ejector->owner()->sound("fx/eject"); + ejector->owner()->sound("game/eject"); } } else { // create cargo pod @@ -1140,7 +1140,7 @@ void Game::func_eject(core::Player *player, const std::string &args) msgstr << "^BEjected " << amount << " " << aux::plural("unit", amount) << " of " << item->info()->name(); } ejector->owner()->send(msgstr.str()); - ejector->owner()->sound("fx/eject"); + ejector->owner()->sound("game/eject"); } pod->reset(); @@ -1236,6 +1236,7 @@ void Game::func_mount(core::Player *player, const std::string &args) std::stringstream msgstr; msgstr << "^BUnmounted " << weapon->name(); ship->owner()->send(msgstr.str()); + player->sound("game/unmount"); } } @@ -1267,6 +1268,7 @@ void Game::func_mount(core::Player *player, const std::string &args) std::stringstream msgstr; msgstr << "^BMounted " << weapon->name(); ship->owner()->send(msgstr.str()); + player->sound("game/mount"); } } } @@ -1333,7 +1335,7 @@ void Game::func_beam(core::Player *player, const std::string &args) msgstr << "^BBeamed in " << negotiated_amount << " " << aux::plural("unit", negotiated_amount) << " of " << item->info()->name(); player->send(msgstr.str()); // TODO sound must be emitted at cargo pod location - player->sound("fx/beam"); + player->sound("game/beam"); } loot_left += item->amount(); 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<core::EntityProjectile *>(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<const Weapon *>(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()); + } } } diff --git a/src/game/base/spacemine.cc b/src/game/base/spacemine.cc index 133f4e0..2a45630 100644 --- a/src/game/base/spacemine.cc +++ b/src/game/base/spacemine.cc @@ -4,9 +4,11 @@ the terms and conditions of the GNU General Public License version 2 */ +#include "math/functions.h" +#include "core/entityprojectile.h" +#include "core/gameserver.h" #include "base/spacemine.h" #include "base/game.h" -#include "math/functions.h" namespace game { @@ -95,6 +97,20 @@ void SpaceMine::collision(core::Entity *other) entity->body()->applyTorqueImpulse(math::to_btVector3(explosion_torque * force * 0.1f)); entity->hit(this); + + } else if (other->type() == core::Entity::Projectile) { + + // hit by projectile + core::EntityProjectile *projectile = static_cast<core::EntityProjectile *>(other); + core::Player *assassin = 0; + + if (projectile->owner_id()) { + assassin = core::server()->find_player(projectile->owner_id()); + } + // send hit sound to assassin + if (assassin) { + assassin->sound("game/target_hit"); + } } spacemine_detonated_timestamp = core::game()->time(); diff --git a/src/game/base/spacemine.h b/src/game/base/spacemine.h index 3c314c2..621a5a9 100644 --- a/src/game/base/spacemine.h +++ b/src/game/base/spacemine.h @@ -44,9 +44,9 @@ public: /** * @brief id of the player who dropped the spacemine * */ - inline const int ownerid() const + inline const int owner_id() const { - return spacemine_ownerid; + return spacemine_owner_id; } /* --- mutators -------------------------------------------- */ @@ -62,16 +62,16 @@ public: /** * @brief set the id of the player who dropped the spacemine * */ - inline void set_ownerid(const int ownerid) + inline void set_owner_id(const int owner_id) { - spacemine_ownerid = ownerid; + spacemine_owner_id = owner_id; } private: unsigned long spacemine_detonated_timestamp; float spacemine_damage; - int spacemine_ownerid; + int spacemine_owner_id; static const Template *spacemine_template; }; |