Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/game/game.cc34
-rw-r--r--src/game/game.h1
-rw-r--r--src/game/ship.cc63
-rw-r--r--src/game/ship.h5
4 files changed, 84 insertions, 19 deletions
diff --git a/src/game/game.cc b/src/game/game.cc
index f95a8ff..e469a31 100644
--- a/src/game/game.cc
+++ b/src/game/game.cc
@@ -137,7 +137,7 @@ void func_hail(core::Player *player, std::string const &args)
core::server()->send_sound(targetplayer, "com/hail");
}
-/// a player actives the jumpdrive on his ship
+/// a player actives the hyperspace jump drive on his ship
void func_jump(core::Player *player, std::string const &args)
{
if (!player->control())
@@ -148,6 +148,17 @@ void func_jump(core::Player *player, std::string const &args)
ship->jump(args);
}
+/// a player actives the kinetic impulse drive on his ship
+void 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->impulse();
+}
+
/* ---- The Game class --------------------------------------------- */
Game *Game::game_instance = 0;
@@ -181,10 +192,7 @@ void Game::init()
// add engine game functions
core::Func *func = 0;
- func = core::Func::add("buy", (core::GameFuncPtr) func_buy);
- func->set_info("buy a ship");
- func = core::Func::add("jump", (core::GameFuncPtr) func_jump);
- func->set_info("make a hyperspace jump");
+
func = core::Func::add("join", (core::GameFuncPtr) func_join);
func->set_info("join the game");
func = core::Func::add("hail", (core::GameFuncPtr) func_hail);
@@ -192,13 +200,25 @@ void Game::init()
func = core::Func::add("spectate", (core::GameFuncPtr) func_spectate);
func->set_info("leave the game and spectate");
+ func = core::Func::add("buy", (core::GameFuncPtr) func_buy);
+ func->set_info("buy a ship");
+
+ func = core::Func::add("jump", (core::GameFuncPtr) func_jump);
+ func->set_info("[string] activate or deactivate hyperspace jump drive");
+
+ func = core::Func::add("impulse", (core::GameFuncPtr) func_impulse);
+ func->set_info("activate are deactive kinetic impulse drive");
+
// add engine core functions
func = core::Func::add("list_ship", (core::FuncPtr) func_list_ship);
func->set_info("list ship statistics");
g_impulsespeed = core::Cvar::get("g_impulsespeed", "15", core::Cvar::Game | core::Cvar::Archive);
- g_impulsespeed->set_info("[float] speed of the impulse drive");
-
+ g_impulsespeed->set_info("[float] standard speed of the impulse drive");
+
+ g_impulseacceleration = core::Cvar::get("g_impulseacceleration", "4", core::Cvar::Game | core::Cvar::Archive);
+ g_impulseacceleration->set_info("[float] standard acceleration of the impulse drive");
+
// indicate the module is ready to run frames
module_running = true;
}
diff --git a/src/game/game.h b/src/game/game.h
index eed0b29..2ad977f 100644
--- a/src/game/game.h
+++ b/src/game/game.h
@@ -51,6 +51,7 @@ public:
static inline Game *instance() { return game_instance; }
core::Cvar *g_impulsespeed;
+ core::Cvar *g_impulseacceleration;
private:
bool load_world();
diff --git a/src/game/ship.cc b/src/game/ship.cc
index d502260..14a5cc8 100644
--- a/src/game/ship.cc
+++ b/src/game/ship.cc
@@ -43,6 +43,8 @@ Ship::Ship(core::Player *owner, ShipModel *shipmodel) :
ship_jumptargetzone = 0;
ship_countdown = 0;
+
+ ship_impulse = false;
}
Ship::~Ship()
@@ -50,13 +52,29 @@ Ship::~Ship()
}
+void Ship::impulse()
+{
+ if (ship_impulse) {
+ ship_impulse = false;
+
+ } else {
+ if (ship_jumpdrive_activated) {
+ ship_jumpdrive_activated = 0;
+ ship_jumptargetzone = 0;
+ ship_countdown = 0;
+ }
+
+ ship_impulse = true;
+ }
+}
+
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;
@@ -88,13 +106,14 @@ void Ship::jump(std::string const &args)
}
if (ship_jumptargetzone == zone()) {
- core::server()->send(owner(), "Already in '" + ship_jumptargetzone->name() + '\'');
+ core::server()->send(owner(), "Already in the " + ship_jumptargetzone->name() + '.');
ship_jumptargetzone = 0;
return;
}
ship_jumpdrive_activated = core::server()->time();
ship_countdown = 5;
+ ship_impulse = false;
std::stringstream msg("");
msg << "Hyperspace drive activated. Jumping in " << ship_countdown << "...";
@@ -109,6 +128,10 @@ void Ship::frame(float seconds)
float angle; // angle in radians
math::Vector3f n; // normal of a plane
+ float actual_maxspeed = ship_shipmodel->maxspeed();
+ float actual_turnspeed = ship_shipmodel->turnspeed();
+ float actual_acceleration = ship_shipmodel->acceleration();
+
// jumpdrive
// target axis
math::Axis target_axis(entity_axis);
@@ -139,13 +162,29 @@ void Ship::frame(float seconds)
target_roll = 0;
target_direction = 0;
- } else {
+ } else if (ship_impulse) {
+
+ // clamp input values
+ target_thrust = 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);
+
+ actual_maxspeed = Game::instance()->g_impulsespeed->value();
+ actual_acceleration = Game::instance()->g_impulseacceleration->value();
+ actual_turnspeed *= 0.5;
+ } 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);
+
+ if (speed() > actual_maxspeed) {
+ actual_acceleration = Game::instance()->g_impulseacceleration->value();
+ actual_turnspeed *= 0.5;
+ }
}
// update thrust
@@ -170,7 +209,7 @@ void Ship::frame(float seconds)
if (fabs(current_target_roll) > MIN_DELTA) {
float roll_offset = seconds * current_target_roll;
- entity_axis.change_roll(ship_shipmodel->turnspeed() * roll_offset);
+ entity_axis.change_roll(actual_turnspeed * roll_offset);
} else {
current_target_roll = 0.0f;
}
@@ -190,7 +229,7 @@ void Ship::frame(float seconds)
if (fabs(current_target_direction) > MIN_DELTA ) {
math::clamp(current_target_direction, -1.0f, 1.0f);
- target_axis.change_direction(ship_shipmodel->turnspeed() * current_target_direction);
+ target_axis.change_direction(actual_turnspeed * current_target_direction);
} else {
current_target_direction = 0.0f;
}
@@ -207,7 +246,7 @@ void Ship::frame(float seconds)
if (fabs(current_target_pitch) > MIN_DELTA) {
math::clamp(current_target_pitch, -1.0f, 1.0f);
- target_axis.change_pitch(ship_shipmodel->turnspeed() * current_target_pitch);
+ target_axis.change_pitch(actual_turnspeed * current_target_pitch);
} else {
current_target_pitch = 0.0f;
}
@@ -222,13 +261,13 @@ void Ship::frame(float seconds)
}
// update speed
- if (entity_speed < entity_thrust * ship_shipmodel->maxspeed()) {
- entity_speed += ship_shipmodel->acceleration() * seconds;
- if (entity_speed > entity_thrust * ship_shipmodel->maxspeed()) {
- entity_speed = entity_thrust * ship_shipmodel->maxspeed();
+ if (entity_speed < entity_thrust * actual_maxspeed) {
+ entity_speed += actual_acceleration * seconds;
+ if (entity_speed > entity_thrust * actual_maxspeed) {
+ entity_speed = entity_thrust * actual_maxspeed;
}
- } else if(entity_speed > entity_thrust * ship_shipmodel->maxspeed()) {
- entity_speed -= ship_shipmodel->acceleration() * seconds;
+ } else if(entity_speed > entity_thrust * actual_maxspeed) {
+ entity_speed -= actual_acceleration * seconds;
if (entity_speed < 0.0f) entity_speed = 0.0f;
}
diff --git a/src/game/ship.h b/src/game/ship.h
index 4d04b62..bd7f79e 100644
--- a/src/game/ship.h
+++ b/src/game/ship.h
@@ -30,6 +30,9 @@ public:
/// toggle jump drive activation
void jump(std::string const & args);
+ /// toggle impulse drive activation
+ void impulse();
+
private:
ShipModel *ship_shipmodel;
@@ -42,6 +45,8 @@ private:
core::Zone *ship_jumptargetzone;
float ship_countdown;
+
+ bool ship_impulse;
};
}