From a1eb1b4dc4d81df724ee43fc4e895dd22e81760f Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 9 Nov 2008 21:45:18 +0000 Subject: working jumpgates --- src/game/base/ship.cc | 101 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 61 insertions(+), 40 deletions(-) (limited to 'src/game/base/ship.cc') diff --git a/src/game/base/ship.cc b/src/game/base/ship.cc index c7a5eda..3e4db42 100644 --- a/src/game/base/ship.cc +++ b/src/game/base/ship.cc @@ -10,7 +10,7 @@ #include "auxiliary/functions.h" #include "core/gameserver.h" #include "core/entity.h" -#include "base/base.h" +#include "base/game.h" #include "base/ship.h" #include "math/functions.h" @@ -19,7 +19,7 @@ using math::degrees360f; using math::degrees180f; -namespace base { +namespace game { const float MIN_DELTA = 0.000001f; @@ -40,6 +40,7 @@ Ship::Ship(core::Player *owner, ShipModel *shipmodel) : ship_impulsedrive_timer = 0; ship_jumpdrive_timer = 0; + ship_jumpdepart = 0; reset(); } @@ -57,7 +58,7 @@ void Ship::reset() current_target_strafe = 0.0f; current_target_afterburner = 0.0f; } -void Ship::impulse() +void Ship::func_impulse() { if ((entity_eventstate == core::Entity::Impulse) || (entity_eventstate == core::Entity::ImpulseInitiate)) { entity_eventstate = core::Entity::Normal; @@ -72,7 +73,7 @@ void Ship::impulse() } entity_eventstate = core::Entity::ImpulseInitiate; - if (Base::g_devel->value()) { + if (Game::g_devel->value()) { entity_timer = 0; } else { entity_timer = 3; @@ -84,14 +85,37 @@ void Ship::impulse() entity_dirty = true; } -void Ship::jump(std::string const &args) +void Ship::initiate_jump(JumpPoint *depart) +{ + ship_jumpdepart = 0; + + if (!depart) + return; + + if (!depart->target()) + return; + + ship_jumpdepart = depart; + entity_eventstate = core::Entity::JumpInitiate; + + if (Game::g_devel->value()) { + entity_timer = 0; + } else { + entity_timer = 8; + } + + ship_jumpdrive_timer = core::server()->time(); + entity_dirty = true; +} + +void Ship::func_jump(std::string const &args) { if (entity_eventstate == core::Entity::Docked) { return; } // devel mode provides instant jump access to arbitrary systems - if (Base::g_devel->value() && (args.size())) { + if (Game::g_devel->value() && (args.size())) { core::Zone *jumptargetzone = 0; std::string target; @@ -117,7 +141,7 @@ void Ship::jump(std::string const &args) } if (jumptargetzone == zone()) { - owner()->send("Already in the " + jumptargetzone->name() + '.'); + owner()->send("Already in the " + jumptargetzone->name()); return; } @@ -133,7 +157,7 @@ void Ship::jump(std::string const &args) return; } else { - if (!jumpdrive() && !Base::g_devel->value()) { + if (!jumpdrive() && !Game::g_devel->value()) { owner()->send("This ship is not equiped with a hyperspace drive!"); return; @@ -141,26 +165,14 @@ void Ship::jump(std::string const &args) return; } else if (entity_eventstate == core::Entity::JumpInitiate) { - owner()->send("Jump aborted, hyperspace drive deactivated."); + owner()->send("Jump aborted, hyperspace drive deactivated"); ship_jumpdrive_timer = 0; entity_timer = 0; entity_eventstate = core::Entity::Normal; return; } - if (!find_closest_jumppoint()) { - return; - } - - entity_eventstate = core::Entity::JumpInitiate; - if (Base::g_devel->value()) { - entity_timer = 0; - } else { - entity_timer = 8; - } - - ship_jumpdrive_timer = core::server()->time(); - entity_dirty = true; + initiate_jump(find_closest_jumppoint()); } } @@ -182,7 +194,7 @@ JumpPoint * Ship::find_closest_jumppoint() } if (jumppoint && jumppoint->target()) { - if (Base::g_jumppointrange->value() < d) { + if (Game::g_jumppointrange->value() < d) { owner()->send("Jumppoint out of range!"); return 0; } else { @@ -236,14 +248,20 @@ void Ship::frame(float seconds) entity_timer -= 1.0f; if (entity_timer <= 0) { - JumpPoint *jumppoint = find_closest_jumppoint(); - - if (jumppoint) { - set_zone(jumppoint->target()->zone()); - if (owner()->control() == (EntityControlable*) this) - owner()->set_zone(jumppoint->target()->zone()); + if (ship_jumpdepart && ship_jumpdepart->target()) { entity_eventstate = core::Entity::Jump; - entity_location.assign(jumppoint->target()->location() + location() - jumppoint->location()); + set_zone(ship_jumpdepart->target()->zone()); + if (owner() && owner()->control() == (EntityControlable*) this) + owner()->set_zone(ship_jumpdepart->target()->zone()); + + if (ship_jumpdepart->moduletype() == jumpgate_enttype) { + entity_axis.assign(ship_jumpdepart->target()->axis()); + entity_location.assign(ship_jumpdepart->target()->location()); + //entity_location += entity_axis.forward() * radius(); + } else { + entity_location.assign(ship_jumpdepart->target()->location() + location() - ship_jumpdepart->location()); + } + owner()->send("^BJumping to the " + ship_jumpdepart->target()->zone()->name()); } else { entity_eventstate = core::Entity::Normal; } @@ -264,7 +282,7 @@ void Ship::frame(float seconds) target_roll = 0; target_direction = 0; target_afterburner = 0.0f; - target_thrust = 0; + target_thrust = 0.1; } else if (entity_eventstate == core::Entity::Jump) { // control is disabled while the jumpdrive is activated @@ -276,22 +294,25 @@ void Ship::frame(float seconds) target_thrust = 0; // FIXME jump location and axis - math::Axis default_axis; - entity_axis.assign(default_axis); + //math::Axis default_axis; + //entity_axis.assign(default_axis); entity_dirty = true; // FIXME 5 second cooldown - entity_speed = Base::g_impulsespeed->value(); + entity_speed = Game::g_impulsespeed->value(); entity_eventstate = core::Entity::Normal; + if (owner() && owner()->view() && owner()->control() == (EntityControlable*) this) + owner()->set_view(0); + } else if (entity_eventstate == core::Entity::ImpulseInitiate) { if (ship_impulsedrive_timer + 1.0f <= core::server()->time()) { entity_timer -= 1.0f; if (entity_timer <= 0) { - actual_maxspeed = Base::g_impulsespeed->value(); - actual_acceleration = Base::g_impulseacceleration->value(); + actual_maxspeed = Game::g_impulsespeed->value(); + actual_acceleration = Game::g_impulseacceleration->value(); entity_eventstate = core::Entity::Impulse; entity_timer = 0; entity_dirty = true; @@ -317,8 +338,8 @@ void Ship::frame(float seconds) math::clamp(target_roll, -1.0f, 1.0f); math::clamp(target_direction, -1.0f, 1.0f); target_afterburner = 0.0f; - actual_maxspeed = Base::g_impulsespeed->value(); - actual_acceleration = Base::g_impulseacceleration->value(); + actual_maxspeed = Game::g_impulsespeed->value(); + actual_acceleration = Game::g_impulseacceleration->value(); actual_turnspeed *= 0.5; } else if (entity_eventstate == core::Entity::Normal) { @@ -331,7 +352,7 @@ void Ship::frame(float seconds) math::clamp(target_afterburner, -1.0f, 1.0f); if (speed() > actual_maxspeed * 1.15f) { - actual_acceleration = Base::g_impulseacceleration->value(); + actual_acceleration = Game::g_impulseacceleration->value(); actual_turnspeed *= 0.5; } @@ -459,7 +480,7 @@ void Ship::frame(float seconds) } if (fabs(current_target_strafe) > MIN_DELTA) { - entity_location += entity_axis.left() * (current_target_strafe * Base::g_strafespeed->value()); + entity_location += entity_axis.left() * (current_target_strafe * Game::g_strafespeed->value()); } entity_movement = target_thrust; -- cgit v1.2.3