Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/base/ship.cc')
-rw-r--r--src/game/base/ship.cc117
1 files changed, 53 insertions, 64 deletions
diff --git a/src/game/base/ship.cc b/src/game/base/ship.cc
index 7cd602e..d234783 100644
--- a/src/game/base/ship.cc
+++ b/src/game/base/ship.cc
@@ -76,12 +76,17 @@ Ship::Ship(core::Player *owner, ShipModel *shipmodel) : core::EntityControlable(
set_flag(core::Entity::Dockable);
}
-
- set_mass(radius() * 10.0f);
+
+ set_mass(shipmodel->mass());
+ set_impulse_force(shipmodel->impulse_force());
+ set_thrust_force(shipmodel->thrust_force());
+ set_strafe_force(shipmodel->strafe_force());
+ set_torque_force(shipmodel->torque_force());
reset();
- const float linear_damp = 0.5f;
- const float angular_damp = 0.75f;
+ const float linear_damp = 0.8f;
+ const float angular_damp = 0.8f;
+
body()->setDamping(linear_damp, angular_damp);
}
@@ -301,48 +306,43 @@ void Ship::set_zone(core::Zone *zone)
void Ship::action (btScalar seconds)
{
- /* controls
- *
- * current_target_direction
- * current_target_pitch
- * current_target_roll
- * current_target_strafe
- * current_target_vstrafe
- * entity_thrust
- */
-
- float actual_maxspeed = 0;
- float actual_acceleration = 0;
- float actual_thrust = 0;
+ float maxspeed = 0;
+ float engine_force = 0;
+
btTransform t;
switch (entity_state) {
case core::Entity::Normal:
- actual_maxspeed = ship_shipmodel->maxspeed();
- actual_acceleration = ship_shipmodel->acceleration();
- actual_thrust = entity_thrust;
+ engine_force = ship_thrust_force * entity_thrust;
+ maxspeed = ship_shipmodel->maxspeed() * entity_thrust;
break;
+
case core::Entity::ImpulseInitiate:
case core::Entity::Impulse:
- actual_maxspeed = Game::g_impulsespeed->value();
- actual_acceleration = Game::g_impulseacceleration->value();
- actual_thrust = 1.0f;
+ engine_force = ship_impulse_force;
+ maxspeed = (Game::g_impulsespeed ? Game::g_impulsespeed->value() * 0.01f : 0.0f);
break;
+
case core::Entity::JumpInitiate:
case core::Entity::Jump:
- actual_maxspeed = 0.0f;
- actual_acceleration = Game::g_impulseacceleration->value();
- actual_thrust = 0.0f;
+ maxspeed = 0.0f;
+ engine_force = 0.0f;
break;
case core::Entity::Docked:
-
+ maxspeed = 0.0f;
+ engine_force = 0.0f;
+
t.setIdentity();
t.setOrigin(to_btVector3(location()));
t.setBasis(to_btMatrix3x3(axis()));
body()->setWorldTransform(t);
+ zone()->physics()->synchronizeSingleMotionState(entity_body);
+
return;
break;
default:
+ maxspeed = 0.0f;
+ engine_force = 0.0f;
break;
}
@@ -350,42 +350,41 @@ void Ship::action (btScalar seconds)
entity_motionstate->getWorldTransform(t);
get_location().assign(t.getOrigin());
get_axis().assign(t.getBasis());
-
- const float force_scale = 1.0f;
- const float thrust_scale = 4.0f;
- body()->applyCentralImpulse(math::to_btVector3(axis().up() * current_target_vstrafe * actual_acceleration * force_scale));
- body()->applyCentralImpulse(math::to_btVector3(axis().left() * current_target_strafe * actual_acceleration * force_scale));
+ const float torque_scale = 0.001f;
+ const float roll_scale = 0.25f;
- body()->applyCentralImpulse(math::to_btVector3(axis().forward() * current_target_afterburner * actual_acceleration * force_scale));
+ // apply strafe
+ body()->applyCentralImpulse(math::to_btVector3(axis().up() * current_target_vstrafe * ship_strafe_force));
+ body()->applyCentralImpulse(math::to_btVector3(axis().left() * current_target_strafe * ship_strafe_force));
+
+ // apply afterburner
+ body()->applyCentralImpulse(math::to_btVector3(axis().forward() * current_target_afterburner * ship_strafe_force));
+ // apply main thruster
if (current_target_afterburner >= 0) {
- body()->applyCentralImpulse(math::to_btVector3(axis().forward() * actual_thrust * actual_acceleration * thrust_scale));
+ body()->applyCentralImpulse(math::to_btVector3(axis().forward() * engine_force));
}
+
+ // apply direction
+ body()->applyTorqueImpulse(math::to_btVector3(axis().up() * current_target_direction * ship_torque_force * torque_scale));
+ // apply pitch
+ body()->applyTorqueImpulse(math::to_btVector3(axis().left() * -current_target_pitch * ship_torque_force * torque_scale));
+ // apply roll
+ body()->applyTorqueImpulse(math::to_btVector3(axis().forward() * -current_target_roll * ship_torque_force * roll_scale * torque_scale));
- const float torque_scale = 0.001f;
- body()->applyTorqueImpulse(math::to_btVector3(axis().up() * current_target_direction * ship_shipmodel->turnspeed() * torque_scale));
- body()->applyTorqueImpulse(math::to_btVector3(axis().left() * -current_target_pitch * ship_shipmodel->turnspeed() * torque_scale));
-
- body()->applyTorqueImpulse(math::to_btVector3(axis().forward() * -current_target_roll * ship_shipmodel->turnspeed() * torque_scale * 0.25f));
-
+ // limit speed
entity_speed = (float) entity_body->getLinearVelocity().length();
- if (entity_speed > Game::g_impulsespeed->value()) {
- body()->setLinearVelocity(math::to_btVector3(axis().forward() * Game::g_impulsespeed->value()));
- entity_speed = actual_maxspeed;
+ if (entity_speed > Game::g_impulsespeed->value() * 0.01f) {
+ entity_speed = Game::g_impulsespeed->value() * 0.01f;
+ body()->setLinearVelocity(math::to_btVector3(axis().forward() * entity_speed));
}
-
}
void Ship::frame(float seconds)
{
- const float direction_reaction = 2.0f; // direction controls reaction time factor
- 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
- //const float actual_turnspeed = ship_shipmodel->turnspeed();
-
- float actual_maxspeed = ship_shipmodel->maxspeed();
- float actual_acceleration = ship_shipmodel->acceleration();
- //float actual_thrust = 0;
+ const float direction_reaction = 2.0f; // directional control reaction time
+ const float thrust_reaction = 0.5f; // thrust control reaction time
+ const float strafe_reaction = 1.5f; // strafe control reaction time
+ const float afterburner_reaction = 1.0f; // afterburner control reaction time
math::Vector3f n; // normal of a plane
math::Axis target_axis(axis()); // target axis
@@ -419,7 +418,7 @@ void Ship::frame(float seconds)
if (entity_timer <= 0) {
if (ship_jumpdepart && ship_jumpdepart->target()) {
set_state(core::Entity::Jump);
- entity_speed = Game::g_impulsespeed->value();
+ entity_speed = Game::g_impulsespeed->value() * 0.01f;
if (ship_jumpdepart->moduletype() == jumpgate_enttype) {
get_axis().assign(ship_jumpdepart->target()->axis());
get_location().assign(ship_jumpdepart->target()->location());
@@ -493,8 +492,6 @@ void Ship::frame(float seconds)
entity_timer -= 1.0f;
if (entity_timer <= 0) {
- actual_maxspeed = Game::g_impulsespeed->value();
- actual_acceleration = Game::g_impulseacceleration->value();
entity_state = core::Entity::Impulse;
entity_timer = 0;
set_dirty();
@@ -510,9 +507,6 @@ void Ship::frame(float seconds)
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_maxspeed = Game::g_impulsespeed->value();
- actual_acceleration = Game::g_impulseacceleration->value();
}
} else if (entity_state == core::Entity::Impulse) {
@@ -530,8 +524,6 @@ void Ship::frame(float seconds)
target_thrust = 1.0f;
entity_thrust = 1.0f;
} else {
- actual_maxspeed = Game::g_impulsespeed->value();
- actual_acceleration = Game::g_impulseacceleration->value();
target_afterburner = 0.0f;
target_thrust = 0.0f;
}
@@ -545,9 +537,6 @@ void Ship::frame(float seconds)
math::clamp(target_direction, -1.0f, 1.0f);
math::clamp(target_afterburner, -1.0f, 1.0f);
- if (speed() > actual_maxspeed * 1.15f) {
- actual_acceleration = Game::g_impulseacceleration->value();
- }
} else if (entity_state == core::Entity::Destroyed) {