diff options
Diffstat (limited to 'src/game/ship.cc')
-rw-r--r-- | src/game/ship.cc | 110 |
1 files changed, 102 insertions, 8 deletions
diff --git a/src/game/ship.cc b/src/game/ship.cc index 007b841..d502260 100644 --- a/src/game/ship.cc +++ b/src/game/ship.cc @@ -5,6 +5,8 @@ */ // project headers +#include "auxiliary/functions.h" +#include "core/gameserver.h" #include "game/game.h" #include "game/ship.h" #include "math/mathlib.h" @@ -37,6 +39,10 @@ Ship::Ship(core::Player *owner, ShipModel *shipmodel) : ship_shipmodel = shipmodel; ship_jumpdrive = shipmodel->shipmodel_jumpdrive; + ship_jumpdrive_activated = 0; + ship_jumptargetzone = 0; + + ship_countdown = 0; } Ship::~Ship() @@ -44,6 +50,58 @@ Ship::~Ship() } +void Ship::jump(std::string const &args) +{ + if (!jumpdrive()) { + core::server()->send(owner(), "This ship is not equiped with a hyperspace drive!"); + return; + } + + if (ship_jumpdrive_activated) { + core::server()->send(owner(), "Jump aborted, hyperspace drive deactivated."); + ship_jumpdrive_activated = 0; + ship_jumptargetzone = 0; + ship_countdown = 0; + return; + } + + std::string target; + std::istringstream is(args); + if (!(is >> target)) { + std::string helpstr; + for (core::Zone::Registry::iterator it = core::Zone::registry().begin(); it != core::Zone::registry().end(); it++) { + core::Zone *zone = (*it).second; + if (helpstr.size()) + helpstr.append("^N|^B"); + helpstr.append(zone->label()); + } + + core::server()->send(owner(), "Usage: jump [^B" + helpstr + "^N]"); + return; + } + + aux::to_lowercase(target); + ship_jumptargetzone = core::Zone::find_zone(target); + if (!ship_jumptargetzone) { + core::server()->send(owner(), "Unknown system '" + target + '\''); + return; + } + + if (ship_jumptargetzone == zone()) { + core::server()->send(owner(), "Already in '" + ship_jumptargetzone->name() + '\''); + ship_jumptargetzone = 0; + return; + } + + ship_jumpdrive_activated = core::server()->time(); + ship_countdown = 5; + + std::stringstream msg(""); + msg << "Hyperspace drive activated. Jumping in " << ship_countdown << "..."; + core::server()->send(owner(), msg.str()); + +} + void Ship::frame(float seconds) { const float direction_change_speed = 2; @@ -51,18 +109,54 @@ void Ship::frame(float seconds) float angle; // angle in radians math::Vector3f n; // normal of a plane + // jumpdrive // target axis math::Axis target_axis(entity_axis); - // clamp input values - math::clamp(target_thrust, 0.0f, 1.0f); - math::clamp(target_pitch, -1.0f, 1.0f); - math::clamp(target_roll, -1.0f, 1.0f); - math::clamp(target_direction, -1.0f, 1.0f); + if (ship_jumpdrive_activated) { + + if (ship_jumpdrive_activated + 1.0f <= core::server()->time()) { + ship_countdown -= 1.0f; + if (ship_countdown <= 0) { + core::server()->send(owner(), "Jumping to '" + ship_jumptargetzone->name() + '\''); + set_zone(ship_jumptargetzone); + if (owner()->control() == (EntityControlable*) this) + owner()->set_zone(ship_jumptargetzone); + ship_jumpdrive_activated = 0; + ship_jumptargetzone = 0; + return; + } else { + std::stringstream msg(""); + msg << ship_countdown << "..."; + core::server()->send(owner(), msg.str()); + ship_jumpdrive_activated = core::server()->time(); + } + } + + // control is disables while the jumpdrive is activated + target_thrust = 0; + target_pitch = 0; + target_roll = 0; + target_direction = 0; + + } else { + + // clamp input values + math::clamp(target_thrust, 0.0f, 1.0f); + math::clamp(target_pitch, -1.0f, 1.0f); + math::clamp(target_roll, -1.0f, 1.0f); + math::clamp(target_direction, -1.0f, 1.0f); + } // update thrust - entity_thrust = target_thrust; + if (entity_thrust < target_thrust) { + entity_thrust += seconds * 0.5f; + } else if (entity_thrust > target_thrust) { + entity_thrust -= seconds * 0.5f; + } + math::clamp(entity_thrust, 0.0f, 1.0f); + // update roll if (current_target_roll < target_roll) { current_target_roll += direction_change_speed * seconds; if (current_target_roll > target_roll) @@ -98,7 +192,7 @@ void Ship::frame(float seconds) math::clamp(current_target_direction, -1.0f, 1.0f); target_axis.change_direction(ship_shipmodel->turnspeed() * current_target_direction); } else { - //current_target_direction = 0.0f; + current_target_direction = 0.0f; } if (current_target_pitch < target_pitch) { @@ -115,7 +209,7 @@ void Ship::frame(float seconds) math::clamp(current_target_pitch, -1.0f, 1.0f); target_axis.change_pitch(ship_shipmodel->turnspeed() * current_target_pitch); } else { - //current_target_pitch = 0.0f; + current_target_pitch = 0.0f; } n.assign(math::crossproduct(entity_axis.forward(), target_axis.forward())); |