diff options
Diffstat (limited to 'src/game/ship.cc')
-rw-r--r-- | src/game/ship.cc | 113 |
1 files changed, 82 insertions, 31 deletions
diff --git a/src/game/ship.cc b/src/game/ship.cc index 9cfea4d..6ca29ba 100644 --- a/src/game/ship.cc +++ b/src/game/ship.cc @@ -4,23 +4,24 @@ the terms and conditions of the GNU General Public License version 2 */ -// project headers +#include <cmath> +#include <iostream> + #include "auxiliary/functions.h" #include "core/gameserver.h" #include "core/entity.h" #include "game/game.h" #include "game/ship.h" -#include "math/mathlib.h" +#include "math/functions.h" + -// C++ headers -#include <iostream> using math::degrees360f; using math::degrees180f; namespace game { -const float MIN_DELTA = 10e-10; +const float MIN_DELTA = 0.000001f; Ship::Ship(core::Player *owner, ShipModel *shipmodel) : core::EntityControlable(owner, ship_enttype) @@ -31,10 +32,6 @@ Ship::Ship(core::Player *owner, ShipModel *shipmodel) : entity_moduletypeid = ship_enttype; - current_target_direction = 0.0f; - current_target_pitch = 0.0f;; - current_target_roll = 0.0f; - entity_color = owner->color(); entity_color_second = owner->color_second(); @@ -45,6 +42,8 @@ Ship::Ship(core::Player *owner, ShipModel *shipmodel) : ship_impulsedrive_timer = 0; ship_jumpdrive_timer = 0; + + reset(); } Ship::~Ship() @@ -52,6 +51,14 @@ Ship::~Ship() } +void Ship::reset() +{ + current_target_direction = 0.0f; + current_target_pitch = 0.0f;; + current_target_roll = 0.0f; + current_target_strafe = 0.0f; + current_target_afterburner = 0.0f; +} void Ship::impulse() { if (entity_eventstate == core::Entity::Jump) { @@ -183,8 +190,18 @@ void Ship::frame(float seconds) target_pitch = 0; target_roll = 0; target_direction = 0; + target_afterburner = 0.0f; + target_thrust = 0; } else if (entity_eventstate == core::Entity::Jump) { + // control is disabled while the jumpdrive is activated + target_thrust = 0; + target_pitch = 0; + target_roll = 0; + target_direction = 0; + target_afterburner = 0.0f; + target_thrust = 0; + // FIXME jump location and axis math::Axis default_axis; entity_axis.assign(default_axis); @@ -215,7 +232,7 @@ void Ship::frame(float seconds) math::clamp(target_pitch, -1.0f, 1.0f); math::clamp(target_roll, -1.0f, 1.0f); math::clamp(target_direction, -1.0f, 1.0f); - + math::clamp(target_afterburner, -1.0f, 1.0f); actual_turnspeed *= 0.5; } else if (entity_eventstate == core::Entity::Impulse) { @@ -225,7 +242,7 @@ void Ship::frame(float seconds) math::clamp(target_pitch, -1.0f, 1.0f); math::clamp(target_roll, -1.0f, 1.0f); math::clamp(target_direction, -1.0f, 1.0f); - + target_afterburner = 0.0f; actual_maxspeed = Game::instance()->g_impulsespeed->value(); actual_acceleration = Game::instance()->g_impulseacceleration->value(); actual_turnspeed *= 0.5; @@ -237,26 +254,15 @@ void Ship::frame(float seconds) math::clamp(target_pitch, -1.0f, 1.0f); math::clamp(target_roll, -1.0f, 1.0f); math::clamp(target_direction, -1.0f, 1.0f); + math::clamp(target_afterburner, -1.0f, 1.0f); - if (speed() > actual_maxspeed) { + if (speed() > actual_maxspeed * 1.15f) { actual_acceleration = Game::instance()->g_impulseacceleration->value(); actual_turnspeed *= 0.5; } } - // update thrust - if (entity_thrust < target_thrust) { - entity_thrust += seconds * 0.5f; - if (entity_thrust > target_thrust) - entity_thrust = target_thrust; - } else if (entity_thrust > target_thrust) { - entity_thrust -= seconds * 0.5f; - if (entity_thrust < target_thrust) - entity_thrust = target_thrust; - } - //math::clamp(entity_thrust, 0.0f, 1.0f); - // update roll if (current_target_roll < target_roll) { current_target_roll += direction_change_speed * seconds; @@ -322,21 +328,66 @@ void Ship::frame(float seconds) entity_axis.rotate(n, -angle); } + // update afterburner + if (current_target_afterburner < target_afterburner) { + current_target_afterburner += 2.0f * seconds; + if (current_target_afterburner > target_afterburner) + current_target_afterburner = target_afterburner; + } else if (current_target_afterburner > target_afterburner) { + current_target_afterburner -= 2.0f * seconds; + if (current_target_afterburner < target_afterburner) + current_target_afterburner = target_afterburner; + } + + // update thrust + if (current_target_afterburner < 0.0f) { + target_thrust = 0; + } + + if (entity_thrust < target_thrust) { + entity_thrust += seconds * 0.5f; + if (entity_thrust > target_thrust) + entity_thrust = target_thrust; + } else if (entity_thrust > target_thrust) { + entity_thrust -= seconds * 0.5f; + if (entity_thrust < target_thrust) + entity_thrust = target_thrust; + } + math::clamp(entity_thrust, 0.0f, 1.0f); + float actual_thrust = entity_thrust + current_target_afterburner * 0.15f; + // update speed - if (entity_speed < entity_thrust * actual_maxspeed) { + if (entity_speed < actual_thrust * actual_maxspeed) { entity_speed += actual_acceleration * seconds; - if (entity_speed > entity_thrust * actual_maxspeed) { - entity_speed = entity_thrust * actual_maxspeed; + if (entity_speed > actual_thrust * actual_maxspeed) { + entity_speed = actual_thrust * actual_maxspeed; } - } else if(entity_speed > entity_thrust * actual_maxspeed) { + } else if(entity_speed > actual_thrust * actual_maxspeed) { entity_speed -= actual_acceleration * seconds; - if (entity_speed < 0.0f) entity_speed = 0.0f; + if (entity_speed < actual_thrust * actual_maxspeed) { + entity_speed = actual_thrust * actual_maxspeed; + } + } + + // update strafe + if (current_target_strafe < target_strafe) { + current_target_strafe += 2.0f * seconds; + if (current_target_strafe > target_strafe) + current_target_strafe = target_strafe; + } else if (current_target_strafe > target_strafe) { + current_target_strafe -= 2.0f * seconds; + if (current_target_strafe < target_strafe) + current_target_strafe = target_strafe; + } + + if (fabs(current_target_strafe) > MIN_DELTA) { + entity_location += entity_axis.left() * (current_target_strafe * Game::instance()->g_strafespeed->value()); } - if (entity_speed != 0.0f) { + if (entity_speed) { entity_location += entity_axis.forward() * entity_speed * seconds; entity_dirty = true; - } else if ((current_target_pitch != 0.0f) || (current_target_direction != 0.0f) || (current_target_roll != 0.0f)) { + } else if ((current_target_pitch != 0.0f) || (current_target_direction != 0.0f) || (current_target_roll != 0.0f) || (current_target_afterburner != 0.0f) || (current_target_strafe != 0)) { entity_dirty = true; } } |