Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2016-07-14 19:22:32 +0200
committerStijn Buys <ingar@osirion.org>2016-07-14 19:22:32 +0200
commit66b3180045c013b487962bd6b742841f74d73840 (patch)
treefa33d74ea112ab95b2184e8425a859a1588d8ee7
parent969f213219dc1b8dcaf6b4fd6fdbc9d6f21ad9e0 (diff)
Added powersteering to AI flight controls.
-rw-r--r--src/game/base/ship.cc32
1 files changed, 27 insertions, 5 deletions
diff --git a/src/game/base/ship.cc b/src/game/base/ship.cc
index ccd8718..5467728 100644
--- a/src/game/base/ship.cc
+++ b/src/game/base/ship.cc
@@ -29,6 +29,10 @@ using math::degrees180f;
namespace game
{
+
+// powersteering factor
+const float POWERSTEERING = 4.0f;
+
Ship::Ship(core::Player *owner, const ShipModel *shipmodel) : core::EntityControlable()
{
@@ -1099,7 +1103,6 @@ void Ship::frame(const unsigned long elapsed)
current_target_vstrafe = target_vstrafe;
if (has_target_controlflag(core::EntityControlable::ControlFlagOverride)) {
- const float powersteering = 4.0f;
// use mouse aim location to set steering controls
math::Vector3f direction(target_aim - location());
direction.normalize();
@@ -1109,12 +1112,12 @@ void Ship::frame(const unsigned long elapsed)
if (direction.x() < 0) {
// aim is behind the ship
- target_pitch = direction.z() * powersteering;
- target_direction = direction.y() * powersteering;
+ target_pitch = direction.z() * POWERSTEERING;
+ target_direction = direction.y() * POWERSTEERING;
} else {
// target is in front of the ship
- target_pitch = direction.z() * powersteering;
- target_direction = direction.y() * powersteering;
+ target_pitch = direction.z() * POWERSTEERING;
+ target_direction = direction.y() * POWERSTEERING;
}
math::clamp(target_pitch, -1.0f, 1.0f);
math::clamp(target_direction, -1.0f, 1.0f);
@@ -1262,6 +1265,12 @@ void Ship::frame_autopilot_goto(const unsigned long elapsed, core::Entity *targe
target_pitch = 0.0f;
}
+ target_direction *= POWERSTEERING;
+ current_target_pitch *= POWERSTEERING;
+
+ math::clamp(target_pitch, -1.0f, 1.0f);
+ math::clamp(target_direction, -1.0f, 1.0f);
+
target_roll = 0.0f;
// impulse or thruster
@@ -1364,6 +1373,7 @@ void Ship::frame_autopilot_combat(const unsigned long elapsed, core::Entity *tar
// transform direction from world coordinates to local entity coordinates
direction = axis().transpose() * direction;
+
if (direction.x() < 0) {
// target is behind the ship
@@ -1385,6 +1395,12 @@ void Ship::frame_autopilot_combat(const unsigned long elapsed, core::Entity *tar
target_pitch = 0.0f;
}
+ target_direction *= POWERSTEERING;
+ current_target_pitch *= POWERSTEERING;
+
+ math::clamp(target_pitch, -1.0f, 1.0f);
+ math::clamp(target_direction, -1.0f, 1.0f);
+
// transform the target's axis into local coordinates
const math::Axis reference(axis().transpose() * target->axis());
if (reference.up().z() < 0.0f) {
@@ -1432,6 +1448,12 @@ void Ship::frame_autopilot_formation(const unsigned long elapsed, core::Entity *
target_direction = 0.0f;
target_pitch = 0.0f;
}
+
+ target_direction *= POWERSTEERING;
+ current_target_pitch *= POWERSTEERING;
+
+ math::clamp(target_pitch, -1.0f, 1.0f);
+ math::clamp(target_direction, -1.0f, 1.0f);
if (reference.up().z() < 0.0f) {