Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2012-12-29 23:23:44 +0000
committerStijn Buys <ingar@osirion.org>2012-12-29 23:23:44 +0000
commit93dd038acea20774143dde34bd924f6eb0d3568a (patch)
treec357b11eeb6eb455543180ea30fa04f2054ac0d4 /src/core/entityprojectile.cc
parent962a744f6782fbcfadf7771ceb157bd82f369ab3 (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/core/entityprojectile.cc')
-rw-r--r--src/core/entityprojectile.cc50
1 files changed, 45 insertions, 5 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);
}