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.cc182
1 files changed, 104 insertions, 78 deletions
diff --git a/src/game/base/ship.cc b/src/game/base/ship.cc
index 03fe3de..8bc7799 100644
--- a/src/game/base/ship.cc
+++ b/src/game/base/ship.cc
@@ -36,8 +36,8 @@ Ship::Ship(core::Player *owner, ShipModel *shipmodel) :
entity_moduletypeid = ship_enttype;
- entity_color = owner->color();
- entity_color_second = owner->color_second();
+ get_color().assign(owner->color());
+ get_color_second().assign(owner->color_second());
ship_shipmodel = shipmodel;
ship_jumpdrive = shipmodel->shipmodel_jumpdrive;
@@ -88,10 +88,9 @@ void Ship::func_impulse()
entity_timer = 3;
}
ship_impulsedrive_timer = core::server()->time();
- entity_dirty = true;
}
- entity_dirty = true;
+ set_dirty();
}
void Ship::initiate_jump(JumpPoint *depart)
@@ -114,7 +113,7 @@ void Ship::initiate_jump(JumpPoint *depart)
}
ship_jumpdrive_timer = core::server()->time();
- entity_dirty = true;
+ set_dirty();
}
void Ship::func_jump(std::string const &args)
@@ -149,8 +148,8 @@ void Ship::func_jump(std::string const &args)
ship_jumpdrive_timer = 0;
entity_timer = 0;
- entity_state = core::Entity::Jump;
- entity_dirty = true;
+ set_state(core::Entity::Jump);
+ set_dirty();
return;
} else {
@@ -244,11 +243,16 @@ void Ship::frame(float seconds)
float actual_thrust = 0;
#ifndef HAVE_BULLET
- const float direction_change_speed = 2;
+ 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
+
+
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
+ math::Axis target_axis(axis()); // target axis
#endif
entity_movement = 0;
@@ -256,7 +260,7 @@ void Ship::frame(float seconds)
// speed might be set to 0 on this update
if (entity_speed != 0.0f)
- entity_dirty = true;
+ set_dirty();
if (entity_state == core::Entity::Docked) {
@@ -280,11 +284,11 @@ void Ship::frame(float seconds)
set_state(core::Entity::Jump);
entity_speed = Game::g_impulsespeed->value();
if (ship_jumpdepart->moduletype() == jumpgate_enttype) {
- entity_axis.assign(ship_jumpdepart->target()->axis());
- entity_location.assign(ship_jumpdepart->target()->location());
+ get_axis().assign(ship_jumpdepart->target()->axis());
+ get_location().assign(ship_jumpdepart->target()->location());
//entity_location += entity_axis.forward() * radius();
} else {
- entity_location.assign(ship_jumpdepart->target()->location() + location() - ship_jumpdepart->location());
+ 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());
@@ -294,11 +298,11 @@ void Ship::frame(float seconds)
ship_jumpdrive_timer = 0;
entity_timer = 0;
- entity_dirty = true;
+ set_dirty();
return;
} else {
ship_jumpdrive_timer = core::server()->time();
- entity_dirty = true;
+ set_dirty();
}
}
@@ -323,7 +327,7 @@ void Ship::frame(float seconds)
// FIXME 5 second cooldown
entity_state = core::Entity::Normal;
- entity_dirty = true;
+ set_dirty();
if (owner() && owner()->view() && owner()->control() == (EntityControlable*) this)
owner()->set_view(0);
@@ -332,30 +336,38 @@ void Ship::frame(float seconds)
} else if (entity_state == core::Entity::ImpulseInitiate) {
- if (ship_impulsedrive_timer + 1.0f <= core::server()->time()) {
- entity_timer -= 1.0f;
+ // cancel impulse drive if afterburner goes reverse
+ if (target_afterburner < 0.0f) {
+ set_state(core::Entity::Normal);
+ set_dirty();
+ entity_timer = 0;
+ } else {
- if (entity_timer <= 0) {
- actual_maxspeed = Game::g_impulsespeed->value();
- actual_acceleration = Game::g_impulseacceleration->value();
- entity_state = core::Entity::Impulse;
- entity_timer = 0;
- entity_dirty = true;
- } else {
- ship_impulsedrive_timer = core::server()->time();
- entity_dirty = true;
+ 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();
+ entity_state = core::Entity::Impulse;
+ entity_timer = 0;
+ set_dirty();
+ } else {
+ ship_impulsedrive_timer = core::server()->time();
+ 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;
}
- // 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
@@ -365,9 +377,18 @@ void Ship::frame(float seconds)
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;
+ // cancel impulse drive if afterburner goes reverse
+ if (target_afterburner < 0.0f) {
+ set_state(core::Entity::Normal);
+ set_dirty();
+ entity_timer = 0;
+ target_thrust = 1.0f;
+ target_thrust = 1.0f;
+ } else {
+ actual_maxspeed = Game::g_impulsespeed->value();
+ actual_acceleration = Game::g_impulseacceleration->value();
+ actual_turnspeed *= 0.5;
+ }
} else if (entity_state == core::Entity::Normal) {
@@ -395,28 +416,30 @@ void Ship::frame(float seconds)
entity_thrust = 0;
}
- // update afterburner
+ // update afterburner control target
if (current_target_afterburner < target_afterburner) {
- current_target_afterburner += 2.0f * seconds;
+ current_target_afterburner += afterburner_reaction * 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;
+ current_target_afterburner -= afterburner_reaction * seconds;
if (current_target_afterburner < target_afterburner)
current_target_afterburner = target_afterburner;
}
- // update thrust
+ // update thrust control target
if (current_target_afterburner < 0.0f) {
target_thrust = 0;
}
if (entity_thrust < target_thrust) {
- entity_thrust += seconds * 0.5f;
+ entity_thrust += thrust_reaction * seconds;
if (entity_thrust > target_thrust)
entity_thrust = target_thrust;
+
} else if (entity_thrust > target_thrust) {
- entity_thrust -= seconds * 0.5f;
+ entity_thrust -= thrust_reaction * seconds;
if (entity_thrust < target_thrust)
entity_thrust = target_thrust;
}
@@ -426,17 +449,28 @@ void Ship::frame(float seconds)
actual_thrust = 1.0f;
}
+
+ // update strafe control target
+ if (current_target_strafe < target_strafe) {
+ current_target_strafe += strafe_reaction * seconds;
+ if (current_target_strafe > target_strafe)
+ current_target_strafe = target_strafe;
+ } else if (current_target_strafe > target_strafe) {
+ current_target_strafe -= strafe_reaction * seconds;
+ if (current_target_strafe < target_strafe)
+ current_target_strafe = target_strafe;
+ }
#ifndef HAVE_BULLET
/* -- original frame --------------------------------------- */
- // update roll
+ // update roll control target
if (current_target_roll < target_roll) {
- current_target_roll += direction_change_speed * seconds;
+ current_target_roll += direction_reaction * seconds;
if (current_target_roll > target_roll)
current_target_roll = target_roll;
} else if (current_target_roll > target_roll) {
- current_target_roll -= direction_change_speed * seconds;
+ current_target_roll -= direction_reaction * seconds;
if (current_target_roll < target_roll)
current_target_roll = target_roll;
}
@@ -444,19 +478,19 @@ void Ship::frame(float seconds)
if (fabs(current_target_roll) > MIN_DELTA) {
float roll_offset = seconds * current_target_roll;
- entity_axis.change_roll(actual_turnspeed * roll_offset);
+ get_axis().change_roll(actual_turnspeed * roll_offset);
} else {
current_target_roll = 0.0f;
}
- // update target_axis direction
+ // update direction control target
if (current_target_direction < target_direction) {
- current_target_direction += direction_change_speed * seconds;
+ current_target_direction += direction_reaction * seconds;
if (current_target_direction > target_direction) {
current_target_direction = target_direction;
}
} else if (current_target_direction > target_direction) {
- current_target_direction -= direction_change_speed * seconds;
+ current_target_direction -= direction_reaction * seconds;
if (current_target_direction < target_direction) {
current_target_direction = target_direction;
}
@@ -469,12 +503,13 @@ void Ship::frame(float seconds)
current_target_direction = 0.0f;
}
+ // update pitch control target
if (current_target_pitch < target_pitch) {
- current_target_pitch += direction_change_speed * seconds;
+ current_target_pitch += direction_reaction * seconds;
if (current_target_pitch > target_pitch)
current_target_pitch = target_pitch;
} else if (current_target_pitch > target_pitch) {
- current_target_pitch -= direction_change_speed * seconds;
+ current_target_pitch -= direction_reaction * seconds;
if (current_target_pitch < target_pitch)
current_target_pitch = target_pitch;
}
@@ -486,45 +521,36 @@ void Ship::frame(float seconds)
current_target_pitch = 0.0f;
}
- n.assign(math::crossproduct(entity_axis.forward(), target_axis.forward()));
+ // update axis
+ n.assign(math::crossproduct(axis().forward(), target_axis.forward()));
if (!(n.length() < MIN_DELTA)) {
n.normalize();
- cosangle = math::dotproduct(entity_axis.forward(), target_axis.forward());
+ cosangle = math::dotproduct(axis().forward(), target_axis.forward());
angle = acos(cosangle) * seconds; // * 180.0f / M_PI;
if (angle > MIN_DELTA)
- entity_axis.rotate(n, -angle);
+ get_axis().rotate(n, -angle);
}
// update speed
- if (entity_speed < actual_thrust * actual_maxspeed) {
+ const float max = actual_thrust * actual_maxspeed;
+ if (entity_speed < max) {
entity_speed += actual_acceleration * seconds;
- if (entity_speed > actual_thrust * actual_maxspeed) {
- entity_speed = actual_thrust * actual_maxspeed;
+ if (entity_speed > max) {
+ entity_speed = max;
}
- } else if(entity_speed > actual_thrust * actual_maxspeed) {
+ } else if(entity_speed > max) {
entity_speed -= actual_acceleration * seconds;
- if (entity_speed < actual_thrust * actual_maxspeed) {
- entity_speed = actual_thrust * actual_maxspeed;
+ if (entity_speed < max) {
+ entity_speed = max;
}
}
- // update strafe
- if (current_target_strafe < target_strafe) {
- current_target_strafe += 2.0f * seconds;
- if (current_target_strafe > target_strafe)
- current_target_strafe = target_strafe;
- } else if (current_target_strafe > target_strafe) {
- current_target_strafe -= 2.0f * seconds;
- if (current_target_strafe < target_strafe)
- current_target_strafe = target_strafe;
- }
-
if (fabs(current_target_strafe) > MIN_DELTA) {
- entity_location += entity_axis.left() * (current_target_strafe * 0.15f * actual_maxspeed) * seconds;
+ get_location() += axis().left() * (current_target_strafe * 0.15f * actual_maxspeed) * seconds;
}
- if (entity_speed) {
- entity_location += entity_axis.forward() * entity_speed * seconds;
+ if (fabs(speed()) > MIN_DELTA) {
+ get_location() += axis().forward() * speed() * seconds;
}
#else /* #ifndef HAVE_BULLET */
@@ -559,7 +585,7 @@ void Ship::frame(float seconds)
entity_movement = math::max(entity_movement, fabs(current_target_strafe));
if ((entity_movement > 0)|| (entity_speed > 0)) {
- entity_dirty = true;
+ set_dirty();
}
}