Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/game/base/ship.cc136
1 files changed, 71 insertions, 65 deletions
diff --git a/src/game/base/ship.cc b/src/game/base/ship.cc
index d947139..bcaae46 100644
--- a/src/game/base/ship.cc
+++ b/src/game/base/ship.cc
@@ -1256,7 +1256,7 @@ void Ship::frame_autopilot_goto(const unsigned long elapsed, core::Entity *targe
if (direction.x() < 0) {
// target is behind the ship
target_direction = (direction.y() > 0 ? 1.0f : -1.0f);
- target_pitch = 0.0f;
+ target_pitch = direction.z();
} else if (direction.x() + MIN_DELTA < 1.0f) {
// target is in front of the ship
@@ -1331,28 +1331,37 @@ void Ship::frame_autopilot_combat(const unsigned long elapsed, core::Entity *tar
// normalize
direction /= distance;
+ // reference radius used in calculations
+ const float r = radius() + target->radius();
+
// transform direction from world coordinates to local entity coordinates
direction = axis().transpose() * direction;
if (direction.x() < 0) {
// target is behind the ship
- target_direction = (direction.y() > 0 ? 1.0f : -1.0f);
- target_pitch = 0.0f;
-
+ if (distance > 4.0f * r) {
+ // turn at a distance
+ target_direction = (direction.y() > 0.0f ? 1.0f : -1.0f);
+ target_pitch = direction.z();
+ } else {
+ // fly-by
+ target_direction = -direction.y();
+ target_pitch = -direction.z();
+ }
} else if (direction.x() + MIN_DELTA < 1.0f) {
// target is in front of the ship
target_direction = direction.y();
target_pitch = direction.z();
} else {
target_direction = 0.0f;
- target_pitch = 0.0f;
+ target_pitch = 0.0f;
}
// transform the target's axis into local coordinates
const math::Axis reference(axis().transpose() * target->axis());
if (reference.up().z() < 0.0f) {
// upward-down
- target_roll = (reference.up().y() > 0 ? 1.0f : 0.0f);
+ target_roll = (reference.up().y() > 0.0f ? 1.0f : 0.0f);
} else if (reference.up().z() + MIN_DELTA < 1.0f) {
target_roll = reference.up().y();
@@ -1360,10 +1369,7 @@ void Ship::frame_autopilot_combat(const unsigned long elapsed, core::Entity *tar
} else {
target_roll = 0.0f;
}
-
- // reference radius used in calculations
- const float r = radius() + target->radius();
-
+
// thruster
if (distance > 2.0f * r) {
target_thrust = 1.0f;
@@ -1375,58 +1381,6 @@ void Ship::frame_autopilot_combat(const unsigned long elapsed, core::Entity *tar
target_thrust = 0.0f;
}
}
-
-void Ship::frame_autopilot_dock(const unsigned long elapsed, core::Entity *target)
-{
- // reference radius used in calculations
- //const float r = radius() + target->radius();
- //const float dock_distance = (target->moduletype() == planet_enttype ? r + PLANET_SAFE_DISTANCE : r);
-
- if ((state() == core::Entity::Impulse) || (state() == core::Entity::ImpulseInitiate)) {
- func_impulse();
- } else if (state() != core::Entity::Normal) {
- return;
- }
-
- if (target->moduletype() == jumpgate_enttype) {
- // jumpgates have their own docking function
- JumpGate *jumpgate = static_cast<JumpGate *>(target);
- jumpgate->func_dock(this);
-
- unset_autopilot_flag(AutoPilotDock);
- return;
-
- } else if (target->moduletype() == race_enttype) {
- if (owner()) {
- RaceTrack *race = static_cast<RaceTrack *>(target);
- race->func_dock(this);
-
- }
-
- unset_autopilot_flag(AutoPilotDock);
- return;
- } else {
- set_dock(target);
-
- if (owner()) {
-
- if (owner()->control() == this) {
- owner()->set_view(target);
- }
-
- core::Player *dock_owner = (target->type() == core::Entity::Controlable ? static_cast<core::EntityControlable *>(target)->owner() : 0 );
-
- if (dock_owner) {
- owner()->send("^BDocking at " + dock_owner->name() + "^B's " + target->name());
- } else {
- owner()->send("^BDocking at " + target->name());
- }
-
- // force save
- core::server()->module()->player_save(owner());
- }
- }
-}
void Ship::frame_autopilot_formation(const unsigned long elapsed, core::Entity *target)
{
@@ -1438,8 +1392,8 @@ void Ship::frame_autopilot_formation(const unsigned long elapsed, core::Entity *
if (reference.forward().x() < 0) {
// target is behind the ship
- target_direction = (reference.forward().y() > 0 ? 1.0f : -1.0f);
- target_pitch = 0.0f;
+ target_direction = (reference.forward().y() > 0.0f ? 1.0f : -1.0f);
+ target_pitch = reference.forward().z();
} else if (reference.forward().x() + MIN_DELTA < 1.0f) {
// target is in front of the ship
@@ -1454,7 +1408,7 @@ void Ship::frame_autopilot_formation(const unsigned long elapsed, core::Entity *
if (reference.up().z() < 0.0f) {
// upward-down
- target_roll = (reference.up().y() > 0 ? 1.0f : 0.0f);
+ target_roll = (reference.up().y() > 0.0f ? 1.0f : 0.0f);
} else if (reference.up().z() + MIN_DELTA < 1.0f) {
target_roll = reference.up().y();
@@ -1493,4 +1447,56 @@ void Ship::frame_autopilot_formation(const unsigned long elapsed, core::Entity *
}
+void Ship::frame_autopilot_dock(const unsigned long elapsed, core::Entity *target)
+{
+ // reference radius used in calculations
+ //const float r = radius() + target->radius();
+ //const float dock_distance = (target->moduletype() == planet_enttype ? r + PLANET_SAFE_DISTANCE : r);
+
+ if ((state() == core::Entity::Impulse) || (state() == core::Entity::ImpulseInitiate)) {
+ func_impulse();
+ } else if (state() != core::Entity::Normal) {
+ return;
+ }
+
+ if (target->moduletype() == jumpgate_enttype) {
+ // jumpgates have their own docking function
+ JumpGate *jumpgate = static_cast<JumpGate *>(target);
+ jumpgate->func_dock(this);
+
+ unset_autopilot_flag(AutoPilotDock);
+ return;
+
+ } else if (target->moduletype() == race_enttype) {
+ if (owner()) {
+ RaceTrack *race = static_cast<RaceTrack *>(target);
+ race->func_dock(this);
+
+ }
+
+ unset_autopilot_flag(AutoPilotDock);
+ return;
+ } else {
+ set_dock(target);
+
+ if (owner()) {
+
+ if (owner()->control() == this) {
+ owner()->set_view(target);
+ }
+
+ core::Player *dock_owner = (target->type() == core::Entity::Controlable ? static_cast<core::EntityControlable *>(target)->owner() : 0 );
+
+ if (dock_owner) {
+ owner()->send("^BDocking at " + dock_owner->name() + "^B's " + target->name());
+ } else {
+ owner()->send("^BDocking at " + target->name());
+ }
+
+ // force save
+ core::server()->module()->player_save(owner());
+ }
+ }
+}
+
} // namespace game