Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/base/ship.cc')
-rw-r--r--src/game/base/ship.cc29
1 files changed, 14 insertions, 15 deletions
diff --git a/src/game/base/ship.cc b/src/game/base/ship.cc
index 0dd5415..dbf8b19 100644
--- a/src/game/base/ship.cc
+++ b/src/game/base/ship.cc
@@ -121,12 +121,7 @@ Ship::Ship(core::Player *owner, const ShipModel *shipmodel) : core::EntityContro
set_flag(core::Entity::Dockable);
}
- ship_armor = maxarmor();
-
- // initialize physics
- // FIXME probably should not be called here
- //reset();
- //body()->setDamping(ship_shipmodel->linear_damping(), ship_shipmodel->angular_damping());
+ set_armor(maxarmor());
}
Ship::~Ship()
@@ -423,7 +418,7 @@ void Ship::explode()
entity_thrust = 0;
- ship_armor = 0;
+ set_armor(0);
set_state(core::Entity::Destroyed);
@@ -589,7 +584,14 @@ void Ship::set_spawn(core::Entity *spawn)
{
ship_spawn = spawn;
}
-
+
+void Ship::set_armor(const float armor)
+{
+ ship_armor = armor;
+ math::clamp(ship_armor, 0.0f, maxarmor());
+ entity_health = ship_armor * 100.0f / maxarmor();
+}
+
void Ship::action (btScalar seconds)
{
float engine_force = 0;
@@ -678,11 +680,11 @@ void Ship::hit(core::Entity *other)
// hit by a mine
SpaceMine * spacemine = static_cast<SpaceMine *>(other);
if (spacemine->state() != core::Entity::Destroyed) {
- ship_armor -= spacemine->damage();
+ set_armor(armor() - spacemine->damage());
}
// destroyed
- if (ship_armor <= 0) {
+ if (armor() <= 0) {
explode();
core::Player *assassin = 0;
@@ -735,7 +737,7 @@ void Ship::hit(core::Entity *other)
// don't hit self
if ((projectile->state() != core::Entity::Destroyed) && (projectile->spawn_id() != id())) {
- ship_armor -= projectile->damage();
+ set_armor(armor() - projectile->damage());
core::Player *assassin = 0;
@@ -744,7 +746,7 @@ void Ship::hit(core::Entity *other)
}
// destroyed
- if (ship_armor <= 0) {
+ if (armor() <= 0) {
explode();
if (owner()) {
@@ -1070,9 +1072,6 @@ void Ship::frame(const unsigned long elapsed)
}
}
- // current health
- entity_health = armor() * 100.0f / maxarmor();
-
/* -- SNAPPY ------------------------------------------ */
current_target_afterburner = target_afterburner;