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.cc49
1 files changed, 36 insertions, 13 deletions
diff --git a/src/game/base/ship.cc b/src/game/base/ship.cc
index 23baa5d..d816943 100644
--- a/src/game/base/ship.cc
+++ b/src/game/base/ship.cc
@@ -38,6 +38,9 @@ Ship::Ship(core::Player *owner, const ShipModel *shipmodel) : core::EntityContro
ship_jumpdrive_timer = 0;
ship_jumpdepart = 0;
+ ship_autopilot_target = 0;
+ ship_autopilot_flags = AutoPilotDisabled;
+
ship_dock = 0;
ship_spawn = 0;
@@ -344,6 +347,11 @@ void Ship::set_zone(core::Zone *zone)
owner()->set_zone(zone);
}
+void Ship::set_autopilot_target(core::Entity *target)
+{
+ ship_autopilot_target = target;
+}
+
void Ship::set_dock(core::Entity *dock)
{
if (!dock) {
@@ -623,13 +631,30 @@ void Ship::frame(const unsigned long elapsed)
math::Vector3f n; // normal of a plane
math::Axis target_axis(axis()); // target axis
- /* -- update state ----------------------------------------- */
// speed might be set to 0 on this update
if (entity_speed != 0.0f) {
set_dirty();
}
+ /* -- autopilot -------------------------------------------- */
+
+ if (has_autopilot_flag(Ship::AutoPilotEnabled) && !has_target_controlflag(core::EntityControlable::ControlFlagOverride)) {
+
+ if (!ship_autopilot_target) {
+ unset_autopilot_flag(Ship::AutoPilotEnabled);
+
+ } else if (!zone()->find_entity(ship_autopilot_target)) {
+ ship_autopilot_target = 0;
+
+ } else {
+ frame_autopilot_goto(elapsed, ship_autopilot_target);
+
+ }
+ }
+
+ /* -- update state ----------------------------------------- */
+
if (entity_state == core::Entity::Docked) {
target_direction = 0;
@@ -637,13 +662,13 @@ void Ship::frame(const unsigned long elapsed)
target_roll = 0;
target_strafe = 0.0f;
target_vstrafe = 0.0f;
+ target_controlflags = 0;
target_afterburner = 0.0f;
target_thrust = 0;
entity_thrust = 0;
entity_speed = 0.0f;
- entity_controlflags = 0;
} else if (entity_state == core::Entity::JumpInitiate) {
@@ -693,8 +718,8 @@ void Ship::frame(const unsigned long elapsed)
target_afterburner = 0.0f;
target_thrust = 0.1f;
- entity_controlflags = 0;
-
+ target_controlflags = 0;
+
} else if (entity_state == core::Entity::Jump) {
// control is disabled while the jumpdrive is activated
@@ -707,8 +732,8 @@ void Ship::frame(const unsigned long elapsed)
target_afterburner = 0.0f;
target_thrust = 0.0f;
- entity_controlflags = 0;
-
+ target_controlflags = 0;
+
// apply jump drive cooldown
if (ship_jumpdrive_timer + 1.0f <= core::server()->time()) {
entity_timer -= 1.0f;
@@ -758,7 +783,7 @@ void Ship::frame(const unsigned long elapsed)
math::clamp(target_roll, -1.0f, 1.0f);
math::clamp(target_direction, -1.0f, 1.0f);
}
-
+
} else if (entity_state == core::Entity::Impulse) {
// clamp input values
@@ -777,7 +802,7 @@ void Ship::frame(const unsigned long elapsed)
//target_afterburner = 0.0f;
//target_thrust = 0.0f;
}
-
+
} else if (entity_state == core::Entity::Normal) {
// clamp input values
@@ -787,9 +812,6 @@ void Ship::frame(const unsigned long elapsed)
math::clamp(target_direction, -1.0f, 1.0f);
math::clamp(target_afterburner, -1.0f, 1.0f);
- entity_controlflags = target_controlflags;
-
-
} else if (entity_state == core::Entity::Destroyed) {
target_direction = 0;
@@ -800,9 +822,10 @@ void Ship::frame(const unsigned long elapsed)
target_afterburner = 0.0f;
target_thrust = 0;
+
+ target_controlflags = 0;
entity_thrust = 0;
- entity_controlflags = 0;
}
// current health
@@ -919,7 +942,7 @@ void Ship::frame(const unsigned long elapsed)
EntityControlable::frame(elapsed);
// fire weapons
- if (model() && slots() && (state() == core::Entity::Normal) && has_controlflag(core::EntityControlable::ControlFlagFire)) {
+ if (model() && slots() && (state() == core::Entity::Normal) && has_target_controlflag(core::EntityControlable::ControlFlagFire)) {
const float modelscale = radius() / model()->radius();