Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/game
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/game
parenta3450f23b09e8d5c66f710fbaf085d6d3b6d8122 (diff)
Introduce Entity::hit() callback, prevent projectiles from doing no damage.
Diffstat (limited to 'src/game')
-rw-r--r--src/game/base/ship.cc137
-rw-r--r--src/game/base/ship.h6
-rw-r--r--src/game/base/spacemine.cc2
3 files changed, 83 insertions, 62 deletions
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();