Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2012-12-04 21:42:54 +0000
committerStijn Buys <ingar@osirion.org>2012-12-04 21:42:54 +0000
commit5701da5df3e5f0d3a40af0abf7e03302275dcca2 (patch)
tree6135b87fc0573183a02688b0415a1ed70a40c751 /src
parenta3450f23b09e8d5c66f710fbaf085d6d3b6d8122 (diff)
Introduce Entity::hit() callback, prevent projectiles from doing no damage.
Diffstat (limited to 'src')
-rw-r--r--src/core/entity.cc4
-rw-r--r--src/core/entity.h6
-rw-r--r--src/core/entityprojectile.cc8
-rw-r--r--src/core/entityprojectile.h6
-rw-r--r--src/game/base/ship.cc137
-rw-r--r--src/game/base/ship.h6
-rw-r--r--src/game/base/spacemine.cc2
7 files changed, 101 insertions, 68 deletions
diff --git a/src/core/entity.cc b/src/core/entity.cc
index 67227ca..4d8c4c7 100644
--- a/src/core/entity.cc
+++ b/src/core/entity.cc
@@ -955,6 +955,10 @@ void EntityDynamic::collision(Entity *other)
{
}
+void EntityDynamic::hit(Entity *other)
+{
+}
+
void EntityDynamic::serialize_server_create(std::ostream & os) const
{
Entity::serialize_server_create(os);
diff --git a/src/core/entity.h b/src/core/entity.h
index 0be81b9..df65843 100644
--- a/src/core/entity.h
+++ b/src/core/entity.h
@@ -662,6 +662,12 @@ public:
* Warning: this can be called multiple times for a single collision
* */
virtual void collision(Entity *other);
+
+ /**
+ * @brief weapon hit callback
+ * This method is called by the core-engine if the entity is hit by a weapon.
+ * */
+ virtual void hit(Entity *other);
protected:
float entity_mass;
diff --git a/src/core/entityprojectile.cc b/src/core/entityprojectile.cc
index 8c6c57b..e89c7f7 100644
--- a/src/core/entityprojectile.cc
+++ b/src/core/entityprojectile.cc
@@ -56,10 +56,12 @@ void EntityProjectile::collision(Entity *other)
{
if (state() == Entity::Destroyed) {
return;
+ } else {
+ if ((other->type() == Dynamic) || (other->type() == Controlable)) {
+ static_cast<EntityDynamic *>(other)->hit(this);
+ }
+ set_state(Entity::Destroyed);
}
-
- set_state(Entity::Destroyed);
- // this method is a bullet callback, we can not reset() here
}
void EntityProjectile::frame(const unsigned long elapsed)
diff --git a/src/core/entityprojectile.h b/src/core/entityprojectile.h
index 04070ff..6bbcdfd 100644
--- a/src/core/entityprojectile.h
+++ b/src/core/entityprojectile.h
@@ -59,7 +59,7 @@ public:
/**
* @brief id of the player who fired the projectile
* */
- inline const int ownerid() const
+ inline const unsigned int ownerid() const
{
return projectile_ownerid;
}
@@ -110,7 +110,7 @@ public:
/**
* @brief set the id of the player who fired the projectile
* */
- inline void set_ownerid(const int ownerid)
+ inline void set_ownerid(const unsigned int ownerid)
{
projectile_ownerid = ownerid;
}
@@ -137,7 +137,7 @@ private:
float projectile_damage;
- int projectile_ownerid;
+ unsigned int projectile_ownerid;
};
} // namespace game
diff --git a/src/game/base/ship.cc b/src/game/base/ship.cc
index fd7b1b8..46dba6e 100644
--- a/src/game/base/ship.cc
+++ b/src/game/base/ship.cc
@@ -380,7 +380,6 @@ void Ship::set_spawn(core::Entity *spawn)
void Ship::action (btScalar seconds)
{
- //float maxspeed = 0;
float engine_force = 0;
float turn_force = ship_turn_force;
float roll_force = ship_roll_force;
@@ -429,7 +428,9 @@ void Ship::action (btScalar seconds)
// apply afterburner
body()->applyCentralImpulse(math::to_btVector3(axis().forward() * current_target_afterburner * ship_strafe_force));
+
// apply main thruster
+ // note: negative afterburner puts the ship in reverse and disables the main thruster
if (current_target_afterburner >= 0) {
body()->applyCentralImpulse(math::to_btVector3(axis().forward() * engine_force));
}
@@ -448,10 +449,9 @@ void Ship::action (btScalar seconds)
entity_speed = Game::g_impulsespeed->value() * 0.01f;
body()->setLinearVelocity(math::to_btVector3(axis().forward() * entity_speed));
}
- // FIXME set speed to 0 if below threshold
}
-void Ship::collision(core::Entity *other)
+void Ship::hit(core::Entity *other)
{
if (state() == core::Entity::Destroyed) {
return;
@@ -461,37 +461,7 @@ void Ship::collision(core::Entity *other)
return;
}
- // do not fly into planets
- if (other->moduletype() == planet_enttype) {
-
- // ran into a planet
- explode();
-
- if (owner()) {
- std::string message("^B");
- message.append(owner()->name());
- message.append(" ^Bran into ");
- message.append(other->name());
- message.append(".");
- core::server()->broadcast(message);
- } else {
- die();
- }
- } else if (other->moduletype() == star_enttype) {
-
- // flew into a star
- explode();
-
- if (owner()) {
- std::string message("^B");
- message.append(owner()->name());
- message.append(" ^Bflew into a star.");
- core::server()->broadcast(message);
- } else {
- die();
- }
-
- } else if (other->moduletype() == spacemine_enttype) {
+ if (other->moduletype() == spacemine_enttype) {
// hit by a mine
SpaceMine * spacemine = static_cast<SpaceMine *>(other);
@@ -534,46 +504,91 @@ void Ship::collision(core::Entity *other)
} else if (other->type() == core::Entity::Projectile) {
// hit by projectile
-
- // TODO don't hit self
core::EntityProjectile *projectile = static_cast<core::EntityProjectile *>(other);
- if (projectile->state() != core::Entity::Destroyed) {
+
+ // don't hit self
+ if ((projectile->state() != core::Entity::Destroyed) &&
+ (projectile->ownerid() != id())) {
+
ship_armor -= projectile->damage();
- }
-
- // destroyed
- if (ship_armor <= 0) {
- explode();
- if (owner()) {
- ship_armor = 0;
- std::string message("^B");
- message.append(owner()->name());
-
- core::Player *assassin = 0;
-
- if (projectile->ownerid()) {
- assassin = core::server()->find_player(projectile->ownerid());
- }
+ // destroyed
+ if (ship_armor <= 0) {
+ explode();
- if (assassin) {
- if (assassin == owner()) {
- message.append(" ^Bate his own bullet.");
+ if (owner()) {
+ ship_armor = 0;
+ 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()) {
+ message.append(" ^Bate his own bullet.");
+ } else {
+ message.append(" ^Bwas blown to bits by ");
+ message.append(assassin->name());
+ }
} else {
- message.append(" ^Bwas blown to bits by ");
- message.append(assassin->name());
+ message.append(" ^Bwas blown to bits.");
}
+ core::server()->broadcast(message);
} else {
- message.append(" ^Bwas blown to bits.");
+ die();
}
- core::server()->broadcast(message);
- } else {
- die();
}
}
}
}
+void Ship::collision(core::Entity *other)
+{
+ if (state() == core::Entity::Destroyed) {
+ return;
+ }
+
+ if (state() == core::Entity::Docked) {
+ return;
+ }
+
+ // do not fly into planets
+ if (other->moduletype() == planet_enttype) {
+
+ // ran into a planet
+ explode();
+
+ if (owner()) {
+ std::string message("^B");
+ message.append(owner()->name());
+ message.append(" ^Bran into ");
+ message.append(other->name());
+ message.append(".");
+ core::server()->broadcast(message);
+ } else {
+ die();
+ }
+ } else if (other->moduletype() == star_enttype) {
+
+ // flew into a star
+ explode();
+
+ if (owner()) {
+ std::string message("^B");
+ message.append(owner()->name());
+ message.append(" ^Bflew into a star.");
+ core::server()->broadcast(message);
+ } else {
+ die();
+ }
+
+ }
+}
+
void Ship::frame(const unsigned long elapsed)
{
//const float direction_reaction = 2.0f; // directional control reaction time
diff --git a/src/game/base/ship.h b/src/game/base/ship.h
index 8b06727..4e95f5d 100644
--- a/src/game/base/ship.h
+++ b/src/game/base/ship.h
@@ -154,8 +154,12 @@ public:
/// reset physics state and ship controls
virtual void reset();
- virtual void collision(Entity *other);
+ /// collision callback
+ virtual void collision(core::Entity *other);
+ /// hit-by weapon callback
+ virtual void hit(core::Entity *other);
+
/// explode the ship
void explode();
diff --git a/src/game/base/spacemine.cc b/src/game/base/spacemine.cc
index 865deb0..133f4e0 100644
--- a/src/game/base/spacemine.cc
+++ b/src/game/base/spacemine.cc
@@ -93,6 +93,8 @@ void SpaceMine::collision(core::Entity *other)
entity->body()->applyCentralImpulse(math::to_btVector3(explosion_direction * force ));
entity->body()->applyTorqueImpulse(math::to_btVector3(explosion_torque * force * 0.1f));
+
+ entity->hit(this);
}
spacemine_detonated_timestamp = core::game()->time();