diff options
Diffstat (limited to 'src/game')
-rw-r--r-- | src/game/game.cc | 7 | ||||
-rw-r--r-- | src/game/game.h | 1 | ||||
-rw-r--r-- | src/game/ship.cc | 113 | ||||
-rw-r--r-- | src/game/ship.h | 5 |
4 files changed, 93 insertions, 33 deletions
diff --git a/src/game/game.cc b/src/game/game.cc index d0b4466..6b44c51 100644 --- a/src/game/game.cc +++ b/src/game/game.cc @@ -214,10 +214,13 @@ void Game::init() func->set_info("list ship statistics"); g_impulsespeed = core::Cvar::get("g_impulsespeed", "15", core::Cvar::Game | core::Cvar::Archive); - g_impulsespeed->set_info("[float] standard speed of the impulse drive"); + g_impulsespeed->set_info("[float] speed of the impulse drive"); g_impulseacceleration = core::Cvar::get("g_impulseacceleration", "4", core::Cvar::Game | core::Cvar::Archive); - g_impulseacceleration->set_info("[float] standard acceleration of the impulse drive"); + g_impulseacceleration->set_info("[float] acceleration of the impulse drive"); + + g_strafespeed = core::Cvar::get("g_strafespeed", "0.002", core::Cvar::Game | core::Cvar::Archive); + g_strafespeed->set_info("[float] strafe speed"); g_devel = core::Cvar::get("g_devel", "0", core::Cvar::Archive); g_devel->set_info("[bool] enable or disable developer mode"); diff --git a/src/game/game.h b/src/game/game.h index b9e6104..be64dd2 100644 --- a/src/game/game.h +++ b/src/game/game.h @@ -53,6 +53,7 @@ public: core::Cvar *g_impulsespeed; core::Cvar *g_impulseacceleration; + core::Cvar *g_strafespeed; core::Cvar *g_devel; 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; } } diff --git a/src/game/ship.h b/src/game/ship.h index 16c0c14..e85a0ad 100644 --- a/src/game/ship.h +++ b/src/game/ship.h @@ -33,12 +33,17 @@ public: /// toggle impulse drive activation void impulse(); + /// void reset drive controls + void reset(); + private: ShipModel *ship_shipmodel; float current_target_direction; float current_target_pitch; float current_target_roll; + float current_target_strafe; + float current_target_afterburner; bool ship_jumpdrive; float ship_jumpdrive_timer; |