Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/client/gamewindow.cc18
-rw-r--r--src/client/gamewindow.h1
-rw-r--r--src/client/input.cc17
-rw-r--r--src/client/keyboard.cc2
-rw-r--r--src/core/entity.cc8
-rw-r--r--src/core/entity.h23
-rw-r--r--src/game/base/game.cc54
-rw-r--r--src/game/base/game.h2
-rw-r--r--src/game/base/ship.cc49
-rw-r--r--src/game/base/ship.h30
10 files changed, 157 insertions, 47 deletions
diff --git a/src/client/gamewindow.cc b/src/client/gamewindow.cc
index 929cfe4..fb6c88d 100644
--- a/src/client/gamewindow.cc
+++ b/src/client/gamewindow.cc
@@ -42,6 +42,7 @@ GameWindow::GameWindow(ui::Widget *parent) : ui::Window(parent)
gamewindow_menubutton = new ui::IconButton(this, "bitmaps/icons/button_menu", "ui_menu");
gamewindow_launchbutton = new ui::IconButton(this, "bitmaps/icons/button_launch", "launch");
+ gamewindow_gotobutton = new TargetIconButton(this, "bitmaps/icons/button_goto", "goto");
gamewindow_dockbutton = new TargetIconButton(this, "bitmaps/icons/button_dock", "dock", core::Entity::Dockable);
gamewindow_homebutton = new ui::IconButton(this, "bitmaps/icons/button_home", "view main");
@@ -268,17 +269,18 @@ void GameWindow::resize()
// icons
const float icon_margin = 4.0f;
const float icon_size = 48.0f;
- const float icon_count = 7;
+ const float icon_count = 8;
const float l = (width() - ((icon_count + 1) * icon_margin) - (icon_count * icon_size)) * 0.5f;
gamewindow_menubutton->set_geometry(l, icon_margin, icon_size, icon_size);
// spacer
- gamewindow_dockbutton->set_geometry(l + 2.0f *(icon_margin + icon_size), icon_margin, icon_size, icon_size);
- gamewindow_launchbutton->set_geometry(l + 2.0f *(icon_margin + icon_size), icon_margin, icon_size, icon_size);
- gamewindow_homebutton->set_geometry(l + 3.0f *(icon_margin + icon_size), icon_margin, icon_size, icon_size);
- gamewindow_inventorybutton->set_geometry(l + 4.0f *(icon_margin + icon_size), icon_margin, icon_size, icon_size);
- gamewindow_chatbutton->set_geometry(l + 5.0f *(icon_margin + icon_size), icon_margin, icon_size, icon_size);
- gamewindow_mapbutton->set_geometry(l + 6.0f *(icon_margin + icon_size), icon_margin, icon_size, icon_size);
+ gamewindow_gotobutton->set_geometry(l + 2.0f *(icon_margin + icon_size), icon_margin, icon_size, icon_size);
+ gamewindow_dockbutton->set_geometry(l + 3.0f *(icon_margin + icon_size), icon_margin, icon_size, icon_size);
+ gamewindow_launchbutton->set_geometry(l + 4.0f *(icon_margin + icon_size), icon_margin, icon_size, icon_size);
+ gamewindow_homebutton->set_geometry(l + 5.0f *(icon_margin + icon_size), icon_margin, icon_size, icon_size);
+ gamewindow_inventorybutton->set_geometry(l + 6.0f *(icon_margin + icon_size), icon_margin, icon_size, icon_size);
+ gamewindow_chatbutton->set_geometry(l + 7.0f *(icon_margin + icon_size), icon_margin, icon_size, icon_size);
+ gamewindow_mapbutton->set_geometry(l + 8.0f *(icon_margin + icon_size), icon_margin, icon_size, icon_size);
// reposition buy menu
gamewindow_buymenu->event_resize();
@@ -311,9 +313,11 @@ void GameWindow::draw()
if (core::localcontrol()->state() == core::Entity::Docked) {
gamewindow_launchbutton->show();
+ gamewindow_gotobutton->hide();
gamewindow_dockbutton->hide();
} else {
gamewindow_launchbutton->hide();
+ gamewindow_gotobutton->show();
gamewindow_dockbutton->show();
}
diff --git a/src/client/gamewindow.h b/src/client/gamewindow.h
index d6e36db..24bc311 100644
--- a/src/client/gamewindow.h
+++ b/src/client/gamewindow.h
@@ -92,6 +92,7 @@ private:
TradeMenu *gamewindow_trademenu;
ui::IconButton *gamewindow_menubutton;
+ ui::IconButton *gamewindow_gotobutton;
ui::IconButton *gamewindow_dockbutton;
ui::IconButton *gamewindow_launchbutton;
ui::IconButton *gamewindow_homebutton;
diff --git a/src/client/input.cc b/src/client/input.cc
index fcf33f8..fed76c9 100644
--- a/src/client/input.cc
+++ b/src/client/input.cc
@@ -889,19 +889,26 @@ void frame()
if ((render::Camera::mode() == render::Camera::Track) || (render::Camera::mode() == render::Camera::Cockpit)) {
- //local_direction = mouse_direction * math::absf(mouse_direction);
- //local_pitch = mouse_pitch * math::absf(mouse_pitch);
local_direction = mouse_direction;
local_pitch = mouse_pitch;
+
+ // enable autopilot override
+ local_controlflags = local_controlflags | core::EntityControlable::ControlFlagOverride;
} else if (render::Camera::mode() == render::Camera::Free) {
- // squared values to smoothen camera movement
+
render::Camera::set_direction(-mouse_direction * math::absf(mouse_direction));
render::Camera::set_pitch(-mouse_pitch * math::absf(mouse_pitch));
+
+ // disable autopilot override
+ local_controlflags = local_controlflags & ~core::EntityControlable::ControlFlagOverride;
}
+ } else {
+ // disable autopilot override
+ local_controlflags = local_controlflags & ~core::EntityControlable::ControlFlagOverride;
}
-
+
math::clamp(local_direction, -1.0f, 1.0f);
math::clamp(local_pitch, -1.0f, 1.0f);
math::clamp(local_roll, -1.0f, 1.0f);
@@ -929,7 +936,7 @@ void frame()
local_vstrafe = 0.0f;
local_strafe = 0.0f;
local_afterburner = 0.0f;
- local_controlflags = 0;
+ local_controlflags = core::EntityControlable::ControlFlagNone;
render::Camera::set_direction(0.0f);
render::Camera::set_pitch(0.0f);
diff --git a/src/client/keyboard.cc b/src/client/keyboard.cc
index d5a14ec..43d4e7e 100644
--- a/src/client/keyboard.cc
+++ b/src/client/keyboard.cc
@@ -179,7 +179,7 @@ Keyboard::Keyboard()
add_key("pagedown", SDLK_PAGEDOWN);
add_key("f1", SDLK_F1);
- add_key("f2", SDLK_F2);
+ add_key("f2", SDLK_F2, 0, "@goto");
add_key("f3", SDLK_F3, 0, "@dock");
key = add_key("f4", SDLK_F4);
#ifdef _WIN32
diff --git a/src/core/entity.cc b/src/core/entity.cc
index 63fa4e8..e76f254 100644
--- a/src/core/entity.cc
+++ b/src/core/entity.cc
@@ -1073,7 +1073,6 @@ void EntityControlable::ActionInterface::debugDraw(btIDebugDraw* debugDrawer)
EntityControlable::EntityControlable() : EntityDynamic()
{
entity_thrust = 0;
- entity_controlflags = 0;
target_direction = 0.0f;
target_thrust = 0.0f;
@@ -1086,7 +1085,6 @@ EntityControlable::EntityControlable() : EntityDynamic()
entity_owner = 0;
entity_actioninterface = 0;
- entity_controlflags = 0;
entity_health = 100.0f;
}
@@ -1094,7 +1092,6 @@ EntityControlable::EntityControlable(std::istream & is) :
EntityDynamic(is)
{
entity_thrust = 0;
- entity_controlflags = 0;
target_direction = 0.0f;
target_thrust = 0.0f;
@@ -1107,7 +1104,6 @@ EntityControlable::EntityControlable(std::istream & is) :
entity_owner = 0;
entity_actioninterface = 0;
- entity_controlflags = 0;
entity_health = 100.0f;
}
@@ -1295,7 +1291,7 @@ void EntityControlable::set_target_controlflags(int controlflags)
void EntityControlable::set_target_controlflag(const ControlFlags controlflag)
{
- if (!has_controlflag(controlflag)) {
+ if ((target_controlflags & controlflag) == 0) {
target_controlflags = target_controlflags | controlflag;
set_dirty();
}
@@ -1303,7 +1299,7 @@ void EntityControlable::set_target_controlflag(const ControlFlags controlflag)
void EntityControlable::unset_target_controlflag(const ControlFlags controlflag)
{
- if (has_controlflag(controlflag)) {
+ if ((target_controlflags & controlflag) == controlflag) {
target_controlflags = target_controlflags & ~controlflag;
set_dirty();
}
diff --git a/src/core/entity.h b/src/core/entity.h
index 140f6ca..6878f08 100644
--- a/src/core/entity.h
+++ b/src/core/entity.h
@@ -687,7 +687,7 @@ class EntityControlable : public EntityDynamic
public:
/// control flags
- enum ControlFlags {ControlFlagNone = 0, ControlFlagFire = 1, ControlFlagAutoPilot = 2, ControlFlagAutoDock = 4, ControlFlagAutoLevel = 8 };
+ enum ControlFlags {ControlFlagNone = 0, ControlFlagFire = 1, ControlFlagOverride = 2};
/// bullet action interface class
class ActionInterface: public btActionInterface {
@@ -728,16 +728,6 @@ public:
return entity_thrust;
}
- /// control flags
- inline int controlflags() const {
- return entity_controlflags;
- }
-
- /// returns true if the specified control flag is set
- inline bool has_controlflag(ControlFlags controlflag) const {
- return ((controlflag & entity_controlflags) == controlflag);
- }
-
/// physics action
inline ActionInterface *actioninterface() {
return entity_actioninterface;
@@ -751,6 +741,14 @@ public:
return entity_health;
}
+ /**
+ * @brief returns true if a specified control flag is set
+ * */
+ inline bool has_target_controlflag(ControlFlags controlflag)
+ {
+ return ((target_controlflags & controlflag) == controlflag);
+ }
+
/*----- serializers ----------------------------------------------- */
/// serialize the entity to a stream
@@ -837,9 +835,6 @@ protected:
/// physics action interface callback
virtual void action (btScalar seconds);
- /// current control flags
- int entity_controlflags;
-
/// current thrust
float entity_thrust;
diff --git a/src/game/base/game.cc b/src/game/base/game.cc
index aa7fd07..72a684b 100644
--- a/src/game/base/game.cc
+++ b/src/game/base/game.cc
@@ -142,12 +142,60 @@ void Game::func_impulse(core::Player *player, std::string const &args)
{
if (!player->control())
return;
+
if (player->control()->moduletype() != ship_enttype)
return;
+
Ship * ship = static_cast<Ship *>(player->control());
ship->func_impulse();
}
+// autopilot free flight
+void Game::func_freeflight(core::Player *player, std::string const &args)
+{
+ if (!player->control())
+ return;
+
+ if (player->control()->moduletype() != ship_enttype)
+ return;
+
+ Ship * ship = static_cast<Ship *>(player->control());
+
+ ship->set_autopilot_target(0);
+ ship->unset_autopilot_flag(Ship::AutoPilotEnabled);
+ player->send("Autopilot disabled");
+}
+
+// autopilot goto
+void Game::func_target_goto(core::Player *player, core::Entity *entity)
+{
+ if (!player->control())
+ return;
+
+ if (player->control() == entity)
+ return;
+
+ if (player->control()->zone() != entity->zone())
+ return;
+
+ if (player->control()->moduletype() != ship_enttype)
+ return;
+
+ Ship * ship = static_cast<Ship *>(player->control());
+
+ if (ship->has_autopilot_flag(Ship::AutoPilotEnabled) && (entity == ship->autopilot_target())) {
+ ship->set_autopilot_target(0);
+ ship->unset_autopilot_flag(Ship::AutoPilotEnabled);
+ player->send("Autopilot disabled");
+ } else {
+ ship->set_autopilot_target(entity);
+ ship->set_autopilot_flag(Ship::AutoPilotEnabled);
+ ship->unset_autopilot_flag(Ship::AutoPilotDock);
+ ship->unset_autopilot_flag(Ship::AutoPilotFormation);
+ player->send("Autopilot set to " + entity->name());
+ }
+}
+
// a player sends a docking request
void Game::func_target_dock(core::Player *player, core::Entity *entity)
{
@@ -1631,6 +1679,9 @@ Game::Game() : core::Module("Project::OSiRiON", true)
func = core::Func::add("impulse", Game::func_impulse);
func->set_info("toggle kinetic impulse drive");
+
+ func = core::Func::add("freeflight", Game::func_freeflight);
+ func->set_info("disable autopilot, enable free flight");
func = core::Func::add("launch", Game::func_launch);
func->set_info("launch to space when docked");
@@ -1641,6 +1692,9 @@ Game::Game() : core::Module("Project::OSiRiON", true)
func = core::Func::add("goto", Game::func_goto);
func->set_info("[string] goto to an entity within the zone");
+ func = core::Func::add("@goto", Game::func_target_goto);
+ func->set_info("set autopilot to target");
+
func = core::Func::add("@dock", Game::func_target_dock);
func->set_info("send a docking request to target");
diff --git a/src/game/base/game.h b/src/game/base/game.h
index 3872303..645d573 100644
--- a/src/game/base/game.h
+++ b/src/game/base/game.h
@@ -125,6 +125,7 @@ private:
static void func_impulse(core::Player *player, std::string const &args);
static void func_launch(core::Player *player, std::string const &args);
static void func_respawn(core::Player *player, std::string const &args);
+ static void func_freeflight(core::Player *player, std::string const &args);
static void func_goto(core::Player *player, const std::string &args);
static void func_buy(core::Player *player, std::string const &args);
static void func_sell(core::Player *player, const std::string &args);
@@ -139,6 +140,7 @@ private:
/* ---- target functions ----------------------------------- */
+ static void func_target_goto(core::Player *player, core::Entity *entity);
static void func_target_dock(core::Player *player, core::Entity *entity);
static void func_target_hail(core::Player *player, core::Entity *entity);
static void func_target_trade(core::Player *player, core::Entity *entity);
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();
diff --git a/src/game/base/ship.h b/src/game/base/ship.h
index ad2c71b..7b25f18 100644
--- a/src/game/base/ship.h
+++ b/src/game/base/ship.h
@@ -24,6 +24,8 @@ const float MIN_DELTA = 0.000001f;
class Ship : public core::EntityControlable
{
public:
+ enum AutoPilotFlags { AutoPilotDisabled = 0, AutoPilotEnabled = 1, AutoPilotDock = 2, AutoPilotFormation = 4 };
+
Ship(core::Player *owner, const ShipModel *shipmodel);
~Ship();
@@ -72,11 +74,21 @@ public:
}
/// (dockable) entity where the ship will respawn if destroyed
- core::Entity *spawn()
+ inline core::Entity *spawn()
{
return ship_spawn;
}
+ /// current autopilot target
+ inline core::Entity *autopilot_target()
+ {
+ return ship_autopilot_target;
+ }
+
+ inline bool has_autopilot_flag(const AutoPilotFlags flag) {
+ return ( (ship_autopilot_flags & flag) == flag);
+ }
+
/// maximum amount of armor
inline const float maxarmor() const
{
@@ -177,6 +189,19 @@ public:
*/
void set_dock(core::Entity *dock);
+ /**
+ * @brief set the autopilot target
+ * */
+ void set_autopilot_target(core::Entity *target);
+
+ inline void set_autopilot_flag(const AutoPilotFlags flag) {
+ ship_autopilot_flags = ship_autopilot_flags | flag;
+ }
+
+ inline void unset_autopilot_flag(const AutoPilotFlags flag) {
+ ship_autopilot_flags = ship_autopilot_flags & ~flag;
+ }
+
void launch();
void set_spawn(core::Entity *spawn);
@@ -227,6 +252,9 @@ private:
core::Entity *ship_dock;
core::Entity *ship_spawn;
+
+ int ship_autopilot_flags;
+ core::Entity *ship_autopilot_target;
};
}