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/core/entityprojectile.cc | 50 +++++++++++++++++++++++++++++++++++++++----- src/core/entityprojectile.h | 44 +++++++++++++++++++++----------------- src/core/item.h | 3 ++- src/core/net.h | 2 +- 4 files changed, 73 insertions(+), 26 deletions(-) (limited to 'src/core') 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(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; } /** @@ -115,14 +123,6 @@ public: projectile_lifespan = lifespan; } - /** - * @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 * */ @@ -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; -- cgit v1.2.3