Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-08-01 22:06:11 +0000
committerStijn Buys <ingar@osirion.org>2008-08-01 22:06:11 +0000
commitf831477c2502b7a2b32cd1fe1b6678a9c87d3fda (patch)
treecae0d1c20354ee9df4eccce2b3763c95c18bf525 /src
parentd2f36485dd3fbda7c9eb212ac9ffde919af5f8e1 (diff)
jumpdrive countdown
Diffstat (limited to 'src')
-rw-r--r--src/core/gameserver.h3
-rw-r--r--src/game/game.cc37
-rw-r--r--src/game/ship.cc110
-rw-r--r--src/game/ship.h7
4 files changed, 113 insertions, 44 deletions
diff --git a/src/core/gameserver.h b/src/core/gameserver.h
index daf1abb..f05e6c6 100644
--- a/src/core/gameserver.h
+++ b/src/core/gameserver.h
@@ -38,6 +38,9 @@ public:
/// show the current time
void showtime();
+ /// current server game time
+ inline float time() const { return server_time; }
+
/*----- mutators -------------------------------------------------- */
/// is called when a player connects to the game server
diff --git a/src/game/game.cc b/src/game/game.cc
index 2f5490f..f95a8ff 100644
--- a/src/game/game.cc
+++ b/src/game/game.cc
@@ -142,45 +142,10 @@ void func_jump(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());
-
- if (!ship->jumpdrive()) {
- core::server()->send(player, "Your ship is not equiped with a jumpdrive");
- return;
- }
- std::string target;
- std::istringstream is(args);
- if (!(is >> target)) {
- std::string helpstr;
- for (core::Zone::Registry::iterator it = core::Zone::registry().begin(); it != core::Zone::registry().end(); it++) {
- core::Zone *zone = (*it).second;
- if (helpstr.size())
- helpstr.append("^N|^B");
- helpstr.append(zone->label());
- }
-
- core::server()->send(player, "Usage: jump [^B" + helpstr + "^N]");
- return;
- }
-
- aux::to_lowercase(target);
- core::Zone *zone = core::Zone::find_zone(target);
- if (!zone) {
- core::server()->send(player, "Unknown system '" + target + '\'');
- return;
- }
-
- if (zone == player->control()->zone())
- return;
-
- core::server()->send(player, "Jumping to '" + zone->name() + '\'');
-
- player->control()->set_zone(zone);
- player->set_zone(zone);
+ ship->jump(args);
}
/* ---- The Game class --------------------------------------------- */
diff --git a/src/game/ship.cc b/src/game/ship.cc
index 007b841..d502260 100644
--- a/src/game/ship.cc
+++ b/src/game/ship.cc
@@ -5,6 +5,8 @@
*/
// project headers
+#include "auxiliary/functions.h"
+#include "core/gameserver.h"
#include "game/game.h"
#include "game/ship.h"
#include "math/mathlib.h"
@@ -37,6 +39,10 @@ Ship::Ship(core::Player *owner, ShipModel *shipmodel) :
ship_shipmodel = shipmodel;
ship_jumpdrive = shipmodel->shipmodel_jumpdrive;
+ ship_jumpdrive_activated = 0;
+ ship_jumptargetzone = 0;
+
+ ship_countdown = 0;
}
Ship::~Ship()
@@ -44,6 +50,58 @@ Ship::~Ship()
}
+void Ship::jump(std::string const &args)
+{
+ if (!jumpdrive()) {
+ core::server()->send(owner(), "This ship is not equiped with a hyperspace drive!");
+ return;
+ }
+
+ if (ship_jumpdrive_activated) {
+ core::server()->send(owner(), "Jump aborted, hyperspace drive deactivated.");
+ ship_jumpdrive_activated = 0;
+ ship_jumptargetzone = 0;
+ ship_countdown = 0;
+ return;
+ }
+
+ std::string target;
+ std::istringstream is(args);
+ if (!(is >> target)) {
+ std::string helpstr;
+ for (core::Zone::Registry::iterator it = core::Zone::registry().begin(); it != core::Zone::registry().end(); it++) {
+ core::Zone *zone = (*it).second;
+ if (helpstr.size())
+ helpstr.append("^N|^B");
+ helpstr.append(zone->label());
+ }
+
+ core::server()->send(owner(), "Usage: jump [^B" + helpstr + "^N]");
+ return;
+ }
+
+ aux::to_lowercase(target);
+ ship_jumptargetzone = core::Zone::find_zone(target);
+ if (!ship_jumptargetzone) {
+ core::server()->send(owner(), "Unknown system '" + target + '\'');
+ return;
+ }
+
+ if (ship_jumptargetzone == zone()) {
+ core::server()->send(owner(), "Already in '" + ship_jumptargetzone->name() + '\'');
+ ship_jumptargetzone = 0;
+ return;
+ }
+
+ ship_jumpdrive_activated = core::server()->time();
+ ship_countdown = 5;
+
+ std::stringstream msg("");
+ msg << "Hyperspace drive activated. Jumping in " << ship_countdown << "...";
+ core::server()->send(owner(), msg.str());
+
+}
+
void Ship::frame(float seconds)
{
const float direction_change_speed = 2;
@@ -51,18 +109,54 @@ void Ship::frame(float seconds)
float angle; // angle in radians
math::Vector3f n; // normal of a plane
+ // jumpdrive
// target axis
math::Axis target_axis(entity_axis);
- // clamp input values
- math::clamp(target_thrust, 0.0f, 1.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);
+ if (ship_jumpdrive_activated) {
+
+ if (ship_jumpdrive_activated + 1.0f <= core::server()->time()) {
+ ship_countdown -= 1.0f;
+ if (ship_countdown <= 0) {
+ core::server()->send(owner(), "Jumping to '" + ship_jumptargetzone->name() + '\'');
+ set_zone(ship_jumptargetzone);
+ if (owner()->control() == (EntityControlable*) this)
+ owner()->set_zone(ship_jumptargetzone);
+ ship_jumpdrive_activated = 0;
+ ship_jumptargetzone = 0;
+ return;
+ } else {
+ std::stringstream msg("");
+ msg << ship_countdown << "...";
+ core::server()->send(owner(), msg.str());
+ ship_jumpdrive_activated = core::server()->time();
+ }
+ }
+
+ // control is disables while the jumpdrive is activated
+ target_thrust = 0;
+ target_pitch = 0;
+ target_roll = 0;
+ target_direction = 0;
+
+ } else {
+
+ // clamp input values
+ math::clamp(target_thrust, 0.0f, 1.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);
+ }
// update thrust
- entity_thrust = target_thrust;
+ if (entity_thrust < target_thrust) {
+ entity_thrust += seconds * 0.5f;
+ } else if (entity_thrust > target_thrust) {
+ entity_thrust -= seconds * 0.5f;
+ }
+ math::clamp(entity_thrust, 0.0f, 1.0f);
+ // update roll
if (current_target_roll < target_roll) {
current_target_roll += direction_change_speed * seconds;
if (current_target_roll > target_roll)
@@ -98,7 +192,7 @@ void Ship::frame(float seconds)
math::clamp(current_target_direction, -1.0f, 1.0f);
target_axis.change_direction(ship_shipmodel->turnspeed() * current_target_direction);
} else {
- //current_target_direction = 0.0f;
+ current_target_direction = 0.0f;
}
if (current_target_pitch < target_pitch) {
@@ -115,7 +209,7 @@ void Ship::frame(float seconds)
math::clamp(current_target_pitch, -1.0f, 1.0f);
target_axis.change_pitch(ship_shipmodel->turnspeed() * current_target_pitch);
} else {
- //current_target_pitch = 0.0f;
+ current_target_pitch = 0.0f;
}
n.assign(math::crossproduct(entity_axis.forward(), target_axis.forward()));
diff --git a/src/game/ship.h b/src/game/ship.h
index bca0857..4d04b62 100644
--- a/src/game/ship.h
+++ b/src/game/ship.h
@@ -27,6 +27,9 @@ public:
/// true if the ship is equiped with a jumpdrive
inline bool jumpdrive() const { return ship_jumpdrive; }
+ /// toggle jump drive activation
+ void jump(std::string const & args);
+
private:
ShipModel *ship_shipmodel;
@@ -35,6 +38,10 @@ private:
float current_target_roll;
bool ship_jumpdrive;
+ float ship_jumpdrive_activated;
+ core::Zone *ship_jumptargetzone;
+
+ float ship_countdown;
};
}