diff options
Diffstat (limited to 'src/game/base/ship.cc')
-rw-r--r-- | src/game/base/ship.cc | 147 |
1 files changed, 92 insertions, 55 deletions
diff --git a/src/game/base/ship.cc b/src/game/base/ship.cc index ba5d7ba..739b29a 100644 --- a/src/game/base/ship.cc +++ b/src/game/base/ship.cc @@ -24,7 +24,8 @@ namespace game { const float MIN_DELTA = 0.000001f; Ship::Ship(core::Player *owner, ShipModel *shipmodel) : - core::EntityControlable(owner, ship_enttype) + core::EntityControlable(owner, ship_enttype), + PhysicsBody(this) { set_modelname(shipmodel->modelname()); set_name(shipmodel->name()); @@ -50,7 +51,7 @@ Ship::Ship(core::Player *owner, ShipModel *shipmodel) : Ship::~Ship() { - + shutdown_physics(); } void Ship::reset() @@ -145,8 +146,6 @@ void Ship::func_jump(std::string const &args) owner()->send("Jumping to the " + jumptargetzone->name()); set_zone(jumptargetzone); - if (owner()->control() == (EntityControlable*) this) - owner()->set_zone(jumptargetzone); ship_jumpdrive_timer = 0; entity_timer = 0; @@ -225,27 +224,40 @@ void Ship::explode() } }; -void Ship::frame(float seconds) +void Ship::set_zone(core::Zone *zone) { - const float direction_change_speed = 2; - float cosangle; // cosine of an angle - float angle; // angle in radians - math::Vector3f n; // normal of a plane + shutdown_physics(); + + core::EntityControlable::set_zone(zone); + + if (owner() && (owner()->control() == (EntityControlable*) this)) + owner()->set_zone(zone); + + init_physics(radius()); +} +void Ship::frame(float seconds) +{ float actual_maxspeed = ship_shipmodel->maxspeed(); float actual_turnspeed = ship_shipmodel->turnspeed(); float actual_acceleration = ship_shipmodel->acceleration(); + float actual_thrust = 0; +#ifndef HAVE_BULLET + const float direction_change_speed = 2; + float cosangle; // cosine of an angle + float angle; // angle in radians + math::Vector3f n; // normal of a plane + math::Axis target_axis(entity_axis); // target axis +#endif entity_movement = 0; - // speed might get set to 0 on this update + /* -- update state ----------------------------------------- */ + + // speed might be set to 0 on this update if (entity_speed != 0.0f) entity_dirty = true; - // jumpdrive - // target axis - math::Axis target_axis(entity_axis); - if (entity_state == core::Entity::Docked) { target_thrust = 0; @@ -257,7 +269,6 @@ void Ship::frame(float seconds) entity_speed = 0; entity_thrust = 0; - return; } else if (entity_state == core::Entity::JumpInitiate) { @@ -267,10 +278,6 @@ void Ship::frame(float seconds) if (entity_timer <= 0) { if (ship_jumpdepart && ship_jumpdepart->target()) { set_state(core::Entity::Jump); - 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()); @@ -278,6 +285,8 @@ void Ship::frame(float seconds) } else { entity_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 { set_state(core::Entity::Normal); @@ -302,6 +311,7 @@ void Ship::frame(float seconds) target_thrust = 0.1; } else if (entity_state == core::Entity::Jump) { + // control is disabled while the jumpdrive is activated target_thrust = 0; target_pitch = 0; @@ -345,6 +355,7 @@ void Ship::frame(float seconds) 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) { @@ -355,6 +366,7 @@ 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 = Game::g_impulsespeed->value(); actual_acceleration = Game::g_impulseacceleration->value(); actual_turnspeed *= 0.5; @@ -385,6 +397,41 @@ void Ship::frame(float seconds) entity_thrust = 0; } + // 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); + actual_thrust = entity_thrust + current_target_afterburner * 0.15f; + if ((entity_state == core::Entity::ImpulseInitiate) || (entity_state == core::Entity::Impulse)) { + actual_thrust = 1.0f; + } + +#ifndef HAVE_BULLET + + /* -- original frame --------------------------------------- */ + // update roll if (current_target_roll < target_roll) { current_target_roll += direction_change_speed * seconds; @@ -450,38 +497,6 @@ 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; - - if ((entity_state == core::Entity::ImpulseInitiate) || (entity_state == core::Entity::Impulse)) { - actual_thrust = 1.0f; - } - // update speed if (entity_speed < actual_thrust * actual_maxspeed) { entity_speed += actual_acceleration * seconds; @@ -510,6 +525,31 @@ void Ship::frame(float seconds) entity_location += entity_axis.left() * (current_target_strafe * 0.15f * actual_maxspeed) * seconds; } + if (entity_speed) { + entity_location += entity_axis.forward() * entity_speed * seconds; + } + +#else /* #ifndef HAVE_BULLET */ + + /* -- bullet frame ----------------------------------------- */ + + // get entity speed from physics body + btVector3 velocity(body()->getInterpolationLinearVelocity()); + entity_speed = velocity.length(); + + // get physics body world transformation + btTransform t; + body()->getMotionState()->getWorldTransform(t); + + // get entity location from physics body + btVector3 v(t.getOrigin()); + location().assign(v[0], v[1], v[2]); + + // apply engine trust to the body + body()->applyCentralImpulse(to_btVector3(axis().forward() * actual_thrust * actual_acceleration * seconds * 10.0f)); + +#endif /* else #ifndef HAVE_BULLET */ + entity_movement = target_thrust; entity_movement = math::max(entity_movement, fabs(current_target_pitch)); entity_movement = math::max(entity_movement, fabs(current_target_direction)); @@ -517,10 +557,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_speed) { - entity_location += entity_axis.forward() * entity_speed * seconds; - entity_dirty = true; - } else if (entity_movement > 0.0f) { + if ((entity_movement > 0)|| (entity_speed > 0)) { entity_dirty = true; } } |