diff options
Diffstat (limited to 'src/game')
-rw-r--r-- | src/game/ship.cc | 105 | ||||
-rw-r--r-- | src/game/ship.h | 7 |
2 files changed, 67 insertions, 45 deletions
diff --git a/src/game/ship.cc b/src/game/ship.cc index f8a1143..4ddd118 100644 --- a/src/game/ship.cc +++ b/src/game/ship.cc @@ -40,12 +40,11 @@ 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_impulse = false; + ship_impulsedrive_timer = 0; + ship_jumpdrive_timer = 0; } Ship::~Ship() @@ -55,19 +54,26 @@ Ship::~Ship() void Ship::impulse() { - if (ship_impulse) { - ship_impulse = false; + if (entity_eventstate == core::Entity::Jump) { + return; + + } else if ((entity_eventstate == core::Entity::Impulse) || (entity_eventstate == core::Entity::ImpulseInitiate)) { entity_eventstate = core::Entity::Normal; + } else { - if (ship_jumpdrive_activated) { - ship_jumpdrive_activated = 0; + + if (entity_eventstate == core::Entity::JumpInitiate) { + ship_jumpdrive_timer = 0; ship_jumptargetzone = 0; - ship_countdown = 0; + entity_timer = 0; } - entity_eventstate = core::Entity::Impulse; - ship_impulse = true; + entity_eventstate = core::Entity::ImpulseInitiate; + entity_timer = 3; + ship_impulsedrive_timer = core::server()->time(); + entity_dirty = true; } + entity_dirty = true; } @@ -76,13 +82,15 @@ 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) { + + } else if (entity_eventstate == core::Entity::Jump) { + return; + + } else if (entity_eventstate == core::Entity::JumpInitiate) { core::server()->send(owner(), "Jump aborted, hyperspace drive deactivated."); - ship_jumpdrive_activated = 0; ship_jumptargetzone = 0; - ship_countdown = 0; + ship_jumpdrive_timer = 0; + entity_timer = 0; entity_eventstate = core::Entity::Normal; return; } @@ -115,16 +123,9 @@ void Ship::jump(std::string const &args) return; } - ship_jumpdrive_activated = core::server()->time(); - ship_countdown = 10; - ship_impulse = false; - - std::stringstream msg(""); - msg << "Initializing hyperspace jump drive..."; - core::server()->send(owner(), msg.str()); - entity_eventstate = core::Entity::JumpInitiate; - entity_timer = ship_countdown; // countdown to jump, in seconds + entity_timer = 10; + ship_jumpdrive_timer = core::server()->time(); entity_dirty = true; } @@ -147,34 +148,29 @@ void Ship::frame(float seconds) // target axis math::Axis target_axis(entity_axis); - if (ship_jumpdrive_activated) { + if (entity_eventstate == core::Entity::JumpInitiate) { - if (ship_jumpdrive_activated + 1.0f <= core::server()->time()) { - ship_countdown -= 1.0f; - entity_timer = ship_countdown; + if (ship_jumpdrive_timer + 1.0f <= core::server()->time()) { + entity_timer -= 1.0f; - if (ship_countdown <= 0) { + if (entity_timer <= 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_jumpdrive_timer = 0; ship_jumptargetzone = 0; - entity_dirty = true; + entity_timer = 0; entity_eventstate = core::Entity::Jump; + entity_dirty = true; return; } else { - if (ship_countdown <= 5) { - std::stringstream msg(""); - msg << ship_countdown << "..."; - core::server()->send(owner(), msg.str()); - } - ship_jumpdrive_activated = core::server()->time(); + ship_jumpdrive_timer = core::server()->time(); entity_dirty = true; } } - // control is disables while the jumpdrive is activated + // control is disabled while the jumpdrive is activated target_thrust = 0; target_pitch = 0; target_roll = 0; @@ -189,7 +185,32 @@ void Ship::frame(float seconds) // FIXME 5 second cooldown entity_eventstate = core::Entity::Normal; - } else if (ship_impulse) { + } 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 = Game::instance()->g_impulsespeed->value(); + actual_acceleration = Game::instance()->g_impulseacceleration->value(); + entity_eventstate = core::Entity::Impulse; + entity_timer = 0; + entity_dirty = true; + } else { + ship_impulsedrive_timer = core::server()->time(); + entity_dirty = true; + } + } + + // clamp input values + target_thrust = 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); + + actual_turnspeed *= 0.5; + + } else if (entity_eventstate == core::Entity::Impulse) { // clamp input values target_thrust = 1.0f; @@ -201,7 +222,8 @@ void Ship::frame(float seconds) actual_acceleration = Game::instance()->g_impulseacceleration->value(); actual_turnspeed *= 0.5; - } else { + } else if (entity_eventstate == core::Entity::Normal) { + // clamp input values math::clamp(target_thrust, 0.0f, 1.0f); math::clamp(target_pitch, -1.0f, 1.0f); @@ -212,6 +234,7 @@ void Ship::frame(float seconds) actual_acceleration = Game::instance()->g_impulseacceleration->value(); actual_turnspeed *= 0.5; } + } // update thrust diff --git a/src/game/ship.h b/src/game/ship.h index bd7f79e..16c0c14 100644 --- a/src/game/ship.h +++ b/src/game/ship.h @@ -41,12 +41,11 @@ private: float current_target_roll; bool ship_jumpdrive; - float ship_jumpdrive_activated; - core::Zone *ship_jumptargetzone; + float ship_jumpdrive_timer; - float ship_countdown; + float ship_impulsedrive_timer; - bool ship_impulse; + core::Zone *ship_jumptargetzone; }; } |