diff options
Diffstat (limited to 'src/game/base/ship.cc')
-rw-r--r-- | src/game/base/ship.cc | 75 |
1 files changed, 38 insertions, 37 deletions
diff --git a/src/game/base/ship.cc b/src/game/base/ship.cc index 8bc7799..2c42ca8 100644 --- a/src/game/base/ship.cc +++ b/src/game/base/ship.cc @@ -1,7 +1,7 @@ /* base/ship.cc - This file is part of the Osirion project and is distributed under - the terms and conditions of the GNU General Public License version 2 + This file is part of the Osirion project and is distributed under + the terms and conditions of the GNU General Public License version 2 */ #include <cmath> @@ -19,13 +19,14 @@ using math::degrees360f; using math::degrees180f; -namespace game { +namespace game +{ const float MIN_DELTA = 0.000001f; Ship::Ship(core::Player *owner, ShipModel *shipmodel) : - core::EntityControlable(owner, ship_enttype), - PhysicsBody(this) + core::EntityControlable(owner, ship_enttype), + PhysicsBody(this) { set_modelname(shipmodel->modelname()); set_name(shipmodel->name()); @@ -41,7 +42,7 @@ Ship::Ship(core::Player *owner, ShipModel *shipmodel) : ship_shipmodel = shipmodel; ship_jumpdrive = shipmodel->shipmodel_jumpdrive; - + ship_impulsedrive_timer = 0; ship_jumpdrive_timer = 0; ship_jumpdepart = 0; @@ -49,7 +50,7 @@ Ship::Ship(core::Player *owner, ShipModel *shipmodel) : reset(); } -Ship::~Ship() +Ship::~Ship() { shutdown_physics(); } @@ -71,16 +72,16 @@ void Ship::func_impulse() } else if (entity_state == core::Entity::ImpulseInitiate) { entity_state = core::Entity::Normal; - + } else if (entity_state != core::Entity::Normal) { return; - - } else { + + } else { if (entity_state == core::Entity::JumpInitiate) { ship_jumpdrive_timer = 0; entity_timer = 0; } - + entity_state = core::Entity::ImpulseInitiate; if (Game::g_devel->value()) { entity_timer = 0; @@ -137,12 +138,12 @@ void Ship::func_jump(std::string const &args) owner()->send("Usage: jump [^B" + helpstr + "^N]"); return; } - + if (jumptargetzone == zone()) { owner()->send("Already in the " + jumptargetzone->name()); return; } - + owner()->send("Jumping to the " + jumptargetzone->name()); set_zone(jumptargetzone); @@ -188,7 +189,7 @@ JumpPoint * Ship::find_closest_jumppoint() } } } - + if (jumppoint && jumppoint->target()) { if (Game::g_jumppointrange->value() < d) { owner()->send("Jumppoint out of range!"); @@ -201,14 +202,14 @@ JumpPoint * Ship::find_closest_jumppoint() owner()->send("No jumppoints found!"); return 0; } - + return 0; } void Ship::explode() { set_state(core::Entity::Destroyed); - + target_thrust = 0; target_pitch = 0; target_roll = 0; @@ -235,7 +236,7 @@ void Ship::set_zone(core::Zone *zone) init_physics(radius()); } -void Ship::frame(float seconds) +void Ship::frame(float seconds) { float actual_maxspeed = ship_shipmodel->maxspeed(); float actual_turnspeed = ship_shipmodel->turnspeed(); @@ -247,10 +248,10 @@ void Ship::frame(float seconds) const float thrust_reaction = 0.5f; // thrust control reaction time factor const float strafe_reaction = 1.5f; const float afterburner_reaction = 1.0f; // a fterburner control reaction time - + float cosangle; // cosine of an angle - float angle; // angle in radians + float angle; // angle in radians math::Vector3f n; // normal of a plane math::Axis target_axis(axis()); // target axis #endif @@ -270,7 +271,7 @@ void Ship::frame(float seconds) target_direction = 0; target_afterburner = 0.0f; target_thrust = 0; - + entity_speed = 0; entity_thrust = 0; @@ -289,7 +290,7 @@ void Ship::frame(float seconds) //entity_location += entity_axis.forward() * radius(); } else { get_location().assign(ship_jumpdepart->target()->location() + location() - ship_jumpdepart->location()); - } + } set_zone(ship_jumpdepart->target()->zone()); owner()->send("^BJumping to the " + ship_jumpdepart->target()->zone()->name()); } else { @@ -297,7 +298,7 @@ void Ship::frame(float seconds) } ship_jumpdrive_timer = 0; entity_timer = 0; - + set_dirty(); return; } else { @@ -340,12 +341,12 @@ void Ship::frame(float seconds) if (target_afterburner < 0.0f) { set_state(core::Entity::Normal); set_dirty(); - entity_timer = 0; + entity_timer = 0; } else { if (ship_impulsedrive_timer + 1.0f <= core::server()->time()) { entity_timer -= 1.0f; - + if (entity_timer <= 0) { actual_maxspeed = Game::g_impulsespeed->value(); actual_acceleration = Game::g_impulseacceleration->value(); @@ -357,25 +358,23 @@ void Ship::frame(float seconds) set_dirty(); } } - + // clamp input values target_thrust = 0.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); math::clamp(target_afterburner, -1.0f, 1.0f); - + actual_turnspeed *= 0.5; } } else if (entity_state == core::Entity::Impulse) { // clamp input values - target_thrust = 0.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); - target_afterburner = 0.0f; // cancel impulse drive if afterburner goes reverse if (target_afterburner < 0.0f) { @@ -383,11 +382,13 @@ void Ship::frame(float seconds) set_dirty(); entity_timer = 0; target_thrust = 1.0f; - target_thrust = 1.0f; - } else { + entity_thrust = 1.0f; + } else { actual_maxspeed = Game::g_impulsespeed->value(); actual_acceleration = Game::g_impulseacceleration->value(); actual_turnspeed *= 0.5; + target_afterburner = 0.0f; + target_thrust = 0.0f; } } else if (entity_state == core::Entity::Normal) { @@ -412,7 +413,7 @@ void Ship::frame(float seconds) target_direction = 0; target_afterburner = 0.0f; target_thrust = 0; - + entity_thrust = 0; } @@ -448,7 +449,7 @@ void Ship::frame(float seconds) if ((entity_state == core::Entity::ImpulseInitiate) || (entity_state == core::Entity::Impulse)) { actual_thrust = 1.0f; } - + // update strafe control target if (current_target_strafe < target_strafe) { @@ -476,7 +477,7 @@ void Ship::frame(float seconds) } math::clamp(current_target_roll, -1.0f, 1.0f); - if (fabs(current_target_roll) > MIN_DELTA) { + if (fabs(current_target_roll) > MIN_DELTA) { float roll_offset = seconds * current_target_roll; get_axis().change_roll(actual_turnspeed * roll_offset); } else { @@ -496,7 +497,7 @@ void Ship::frame(float seconds) } } - if (fabs(current_target_direction) > MIN_DELTA ) { + if (fabs(current_target_direction) > MIN_DELTA) { math::clamp(current_target_direction, -1.0f, 1.0f); target_axis.change_direction(actual_turnspeed * current_target_direction); } else { @@ -513,7 +514,7 @@ void Ship::frame(float seconds) if (current_target_pitch < target_pitch) current_target_pitch = target_pitch; } - + if (fabs(current_target_pitch) > MIN_DELTA) { math::clamp(current_target_pitch, -1.0f, 1.0f); target_axis.change_pitch(actual_turnspeed * current_target_pitch); @@ -538,7 +539,7 @@ void Ship::frame(float seconds) if (entity_speed > max) { entity_speed = max; } - } else if(entity_speed > max) { + } else if (entity_speed > max) { entity_speed -= actual_acceleration * seconds; if (entity_speed < max) { entity_speed = max; @@ -584,7 +585,7 @@ void Ship::frame(float seconds) entity_movement = math::max(entity_movement, fabs(current_target_afterburner)); entity_movement = math::max(entity_movement, fabs(current_target_strafe)); - if ((entity_movement > 0)|| (entity_speed > 0)) { + if ((entity_movement > 0) || (entity_speed > 0)) { set_dirty(); } } |