diff options
-rw-r--r-- | src/core/entityprojectile.cc | 50 | ||||
-rw-r--r-- | src/core/entityprojectile.h | 44 | ||||
-rw-r--r-- | src/core/item.h | 3 | ||||
-rw-r--r-- | src/core/net.h | 2 | ||||
-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 |
8 files changed, 132 insertions, 60 deletions
diff --git a/src/core/entityprojectile.cc b/src/core/entityprojectile.cc index 1fdf12a..0a4e081 100644 --- a/src/core/entityprojectile.cc +++ b/src/core/entityprojectile.cc @@ -14,7 +14,7 @@ namespace core { -EntityProjectile::EntityProjectile() : EntityDynamic() +EntityProjectile::EntityProjectile(const Entity *spawn) : EntityDynamic() { set_label("projectile"); set_flag(Entity::KeepAlive); @@ -24,8 +24,13 @@ EntityProjectile::EntityProjectile() : EntityDynamic() projectile_damage = 0.0f; projectile_lifespan = 0.0f; - projectile_ownerid = 0; + projectile_owner_id = 0; + projectile_spawn_id = 0; projectile_timestamp = game()->timestamp(); + + if (spawn) { + set_spawn(spawn); + } } EntityProjectile::EntityProjectile(std::istream & is) : EntityDynamic(is) @@ -38,7 +43,8 @@ EntityProjectile::EntityProjectile(std::istream & is) : EntityDynamic(is) projectile_damage = 0.0f; projectile_lifespan = 0.0f; - projectile_ownerid = 0; + projectile_owner_id = 0; + projectile_spawn_id = 0; projectile_timestamp = game()->timestamp(); } @@ -203,6 +209,34 @@ void EntityProjectile::set_projectile_soundname(const std::string soundname) projectile_soundname_str.assign(soundname); } +void EntityProjectile::set_spawn(const Entity *spawn) +{ + if (spawn) { + // set spawn id + projectile_spawn_id = spawn->id(); + + // set owner id + projectile_owner_id = 0; + if (spawn->type() == Entity::Controlable) { + const Player *player = static_cast<const EntityControlable *>(spawn)->owner(); + if (player) { + projectile_owner_id = player->id(); + } + } + + // set colors + set_color(spawn->color()); + set_color_second(spawn->color_second()); + + //set zone + set_zone(spawn->zone()); + } else { + projectile_spawn_id = 0; + projectile_owner_id = 0; + } + +} + void EntityProjectile::serialize_server_create(std::ostream & os) const { os << moduletype() << " "; @@ -215,10 +249,10 @@ void EntityProjectile::serialize_server_create(std::ostream & os) const os << std::setprecision(8) << axis().forward() << " "; os << std::setprecision(8) << axis().left() << " "; os << "\"" << projectile_modelname() << "\" "; + os << "\"" << projectile_soundname() << "\" "; os << roundf(speed() * 100.0f) << " "; os << state() << " ";; os << lifespan() << " "; - os << ownerid() << " "; } void EntityProjectile::receive_server_create(std::istream &is) @@ -256,13 +290,19 @@ void EntityProjectile::receive_server_create(std::istream &is) while ((is.get(c)) && (c != '"')) n += c; set_projectile_modelname(n); + + // read projectile soundname + n.clear(); + while ((is.get(c)) && (c != '"')); + while ((is.get(c)) && (c != '"')) + n += c; + set_projectile_soundname(n); is >> entity_speed; entity_speed /= 100.0f; is >> entity_state; is >> projectile_lifespan; - is >> projectile_ownerid; set_dirty(false); } diff --git a/src/core/entityprojectile.h b/src/core/entityprojectile.h index cfd534b..2651203 100644 --- a/src/core/entityprojectile.h +++ b/src/core/entityprojectile.h @@ -15,7 +15,7 @@ namespace core class EntityProjectile : public core::EntityDynamic { public: - EntityProjectile(); + EntityProjectile(const Entity *spawn = 0); EntityProjectile(std::istream & is); virtual ~EntityProjectile(); @@ -59,9 +59,17 @@ public: /** * @brief id of the player who fired the projectile * */ - inline const unsigned int ownerid() const + inline const int owner_id() const { - return projectile_ownerid; + return projectile_owner_id; + } + + /** + * @brief id of the entity that spawned the projectile + * */ + inline const unsigned int spawn_id() const + { + return projectile_spawn_id; } /** @@ -116,14 +124,6 @@ public: } /** - * @brief set the id of the player who fired the projectile - * */ - inline void set_ownerid(const unsigned int ownerid) - { - projectile_ownerid = ownerid; - } - - /** * @brief set the projectile timestamp * */ inline void set_timestamp(const unsigned int timestamp) @@ -141,18 +141,24 @@ public: * */ void set_projectile_soundname(const std::string soundname); -private: - unsigned long projectile_timestamp; - - unsigned long projectile_lifespan; + /** + * @brief set the entity that spawned the projectile + * This sets spawn_id() to the id of the entity and owner_id() to the id + * of the owner of the spawn, if any. + * */ + void set_spawn(const Entity *spawn); - std::string projectile_modelname_str; +private: + unsigned long projectile_timestamp; + unsigned long projectile_lifespan; - std::string projectile_soundname_str; + std::string projectile_modelname_str; + std::string projectile_soundname_str; - float projectile_damage; + float projectile_damage; - unsigned int projectile_ownerid; + int projectile_owner_id; + unsigned int projectile_spawn_id; }; } // namespace game diff --git a/src/core/item.h b/src/core/item.h index 6388838..27e6028 100644 --- a/src/core/item.h +++ b/src/core/item.h @@ -24,9 +24,10 @@ public: * Tradeable (reserved) * Unique indicates a unique item * Unrestricted can be sold everywhere (e.g. cargo) + * Mountable indicate the item can be mounted in a slot * Mounted indicates the item is mounted in a slot * */ - enum Flags {Tradeable = 1, Unique = 2, Unrestricted = 4, Mounted = 8}; + enum Flags {Tradeable = 1, Unique = 2, Unrestricted = 4, Mountable = 8, Mounted = 16}; Item(const Info *info); diff --git a/src/core/net.h b/src/core/net.h index 47da3e7..be364da 100644 --- a/src/core/net.h +++ b/src/core/net.h @@ -11,7 +11,7 @@ namespace core { /// network protocol version -const unsigned int PROTOCOLVERSION = 25; +const unsigned int PROTOCOLVERSION = 26; /// maximum lenght of a (compressed) network message block const unsigned int FRAMESIZE = 1152; 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; }; |