From 243ef412d9abb609ec1ad6ed296056c6c7c3a063 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Mon, 22 Dec 2014 21:03:32 +0000 Subject: Wingmen will try to repair their ship if the leader has a carrier and health drops below 25%. --- src/game/base/ship.cc | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'src/game/base/ship.cc') 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(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; -- cgit v1.2.3