Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2010-10-20 17:38:55 +0000
committerStijn Buys <ingar@osirion.org>2010-10-20 17:38:55 +0000
commit08f0d0fb6a57f9c398bc03ed9a3cc9537a1f3e18 (patch)
treeb7d67889e895b1fe5d7f70aab7b4296d77ff7e89 /src/game/base
parent21e6267e3f998a467ca3b5ec225e6d03653aed97 (diff)
docking functions cleanup, jumpgates work again
Diffstat (limited to 'src/game/base')
-rw-r--r--src/game/base/game.cc60
-rw-r--r--src/game/base/game.h6
-rw-r--r--src/game/base/jumppoint.cc16
-rw-r--r--src/game/base/jumppoint.h6
-rw-r--r--src/game/base/ship.cc39
-rw-r--r--src/game/base/ship.h5
6 files changed, 55 insertions, 77 deletions
diff --git a/src/game/base/game.cc b/src/game/base/game.cc
index 418bfb5..d99f80c 100644
--- a/src/game/base/game.cc
+++ b/src/game/base/game.cc
@@ -37,8 +37,6 @@ core::Entity *Default::view = 0;
ShipModel *Default::shipmodel = 0;
long Default::credits = 0;
-const float planet_safe_distance = 150.0f;
-
void Default::clear()
{
zone = 0;
@@ -170,16 +168,13 @@ void Game::func_dock(core::Player *player, core::Entity *entity)
if (!player->control())
return;
- if (player->control()->zone() != entity->zone())
- return;
-
if (player->control() == entity)
return;
- if ((entity->flags() & core::Entity::Dockable) == 0)
+ if (player->control()->zone() != entity->zone())
return;
-
- if (player->control()->state() != core::Entity::Normal)
+
+ if ((entity->flags() & core::Entity::Dockable) == 0)
return;
if (player->control()->moduletype() != ship_enttype)
@@ -188,28 +183,53 @@ void Game::func_dock(core::Player *player, core::Entity *entity)
if (!(entity->flags() & core::Entity::Dockable)) {
return;
}
-
+
Ship * ship = static_cast<Ship *>(player->control());
-
+
+ // check distance
float range = entity->radius() + ship->radius();
+
if (entity->moduletype() == planet_enttype) {
- range = planet_safe_distance;
+ range += planet_safe_distance;
}
+ core::Player *owner = (entity->type() == core::Entity::Controlable ? static_cast<core::EntityControlable *>(entity)->owner() : 0 );
if (math::distance(entity->location(), ship->location()) > range) {
- if (ship->owner()) {
- ship->owner()->send("^W" + entity->name() + " out of range");
+ if (owner) {
+ player->send("^W" + owner->name() + "^W's " + entity->name() + " out of range");
+ } else {
+ player->send("^W" + entity->name() + " out of range");
}
return;
}
+
+ if ((player->control()->state() == core::Entity::Impulse) || (player->control()->state() == core::Entity::ImpulseInitiate)) {
+ player->send("^WCan not dock at impulse speed");
+ return;
+ }
+
+ if (player->control()->state() != core::Entity::Normal)
+ return;
+
+ if (entity->moduletype() == jumpgate_enttype) {
+ // jumpgates their own docking function
+ JumpGate *jumpgate = static_cast<JumpGate *>(entity);
+ jumpgate->func_dock(ship);
+ return;
+
+ } else {
+ ship->get_location().assign(entity->location());
+ ship->set_state(core::Entity::Docked);
+ ship->reset();
- ship->get_location().assign(entity->location());
- ship->set_state(core::Entity::Docked);
- ship->reset();
-
- if (ship->owner() && ship->owner()->control() == ship) {
- ship->owner()->set_view(entity);
- ship->owner()->send("^BDocking at " + entity->name());
+ if (player->control() == ship) {
+ player->set_view(entity);
+ if (owner) {
+ player->send("^BDocking at " + owner->name() + "^B's " + entity->name());
+ } else {
+ player->send("^BDocking at " + entity->name());
+ }
+ }
}
}
diff --git a/src/game/base/game.h b/src/game/base/game.h
index 7dc17bb..1042367 100644
--- a/src/game/base/game.h
+++ b/src/game/base/game.h
@@ -35,6 +35,12 @@ const unsigned int jumpgate_enttype = 261;
const unsigned int station_enttype = 262;
const unsigned int cargopod_enttype = 263;
+// planet docking distance
+const float planet_safe_distance = 150.0f;
+
+const float jump_timer_delay = 5.0f;
+const float impulse_timer_delay = 3.0f;
+
// info class type constants
//const unsigned int shipmodel_class_id = 1;
//const unsigned int commodity_class_id = 2;
diff --git a/src/game/base/jumppoint.cc b/src/game/base/jumppoint.cc
index ae66262..283b607 100644
--- a/src/game/base/jumppoint.cc
+++ b/src/game/base/jumppoint.cc
@@ -105,20 +105,8 @@ void JumpGate::validate()
}
}
-void JumpGate::dock(core::Entity *entity)
+void JumpGate::func_dock(Ship *ship)
{
- if (entity->moduletype() != ship_enttype)
- return;
-
- Ship * ship = static_cast<Ship *>(entity);
-
- if (math::distance(location(), ship->location()) > radius() + ship->radius()) {
- if (ship->owner())
- ship->owner()->send("Jumpgate out of range");
- return;
- }
-
- con_debug << name() << " received docking request from " << entity->name() << std::endl;
if (target()) {
if (activated()) {
if (ship->owner())
@@ -144,7 +132,7 @@ void JumpGate::dock(core::Entity *entity)
void JumpGate::activate()
{
- jumpgate_timer = 10.0f;
+ jumpgate_timer = jump_timer_delay;
set_state(core::Entity::Normal);
}
diff --git a/src/game/base/jumppoint.h b/src/game/base/jumppoint.h
index fe29727..cb3ee28 100644
--- a/src/game/base/jumppoint.h
+++ b/src/game/base/jumppoint.h
@@ -15,6 +15,8 @@
namespace game
{
+class Ship;
+
/// a jumppoint
/**
* jumppoints are used to define hyperspace routes between systems.
@@ -57,8 +59,8 @@ public:
/// validate the targetlabel and set target()
virtual void validate();
- /// entity received a docking request
- virtual void dock(core::Entity *entity);
+ /// a ship wants to use the jumpgate
+ void func_dock(Ship *ship);
inline bool activated() const {
return (jumpgate_timer > 0);
diff --git a/src/game/base/ship.cc b/src/game/base/ship.cc
index d234783..d426a0d 100644
--- a/src/game/base/ship.cc
+++ b/src/game/base/ship.cc
@@ -23,9 +23,6 @@ namespace game
{
const float MIN_DELTA = 0.000001f;
-const float impulse_delay = 3.0f; // 3 second delay before impulse kicks in
- // note: this delay must match the impulse drive sound set
-const float jump_delay = 5.0f; // 5 seconds delay before jump driv kicks in
Ship::Ship(core::Player *owner, ShipModel *shipmodel) : core::EntityControlable()
{
@@ -106,36 +103,6 @@ void Ship::reset()
EntityControlable::reset();
}
-// this is called if another shuo wants to dock this ship
-void Ship::dock(Entity *entity)
-{
- if (!flag_is_set(core::Entity::Dockable))
- return;
-
- if (entity->moduletype() != ship_enttype)
- return;
-
- Ship *other_ship = static_cast<Ship *>(entity);
-
- if (math::distance(location(), other_ship->location()) > radius() + other_ship->radius()) {
- if (other_ship->owner())
- other_ship->owner()->send("Target out of range");
- return;
- }
-
- other_ship->get_location().assign(location());
- other_ship->set_state(core::Entity::Docked);
-
- if (other_ship->owner() && other_ship->owner()->control() == other_ship) {
- other_ship->owner()->set_view(this);
- if (owner()) {
- other_ship->owner()->send("^BDocking at " + owner()->name() + "^B's " + name());
- } else {
- other_ship->owner()->send("^BDocking at " + name());
- }
- }
-}
-
void Ship::func_impulse()
{
if (entity_state == core::Entity::Impulse) {
@@ -163,7 +130,7 @@ void Ship::func_impulse()
return;
entity_state = core::Entity::ImpulseInitiate;
- entity_timer = impulse_delay;
+ entity_timer = impulse_timer_delay;
ship_impulsedrive_timer = core::server()->time();
}
@@ -180,7 +147,7 @@ void Ship::initiate_jump(JumpPoint *depart)
ship_jumpdepart = depart;
entity_state = core::Entity::JumpInitiate;
- entity_timer = jump_delay;
+ entity_timer = jump_timer_delay;
ship_jumpdrive_timer = core::server()->time();
set_dirty();
@@ -422,7 +389,7 @@ void Ship::frame(float seconds)
if (ship_jumpdepart->moduletype() == jumpgate_enttype) {
get_axis().assign(ship_jumpdepart->target()->axis());
get_location().assign(ship_jumpdepart->target()->location());
- //entity_location += entity_axis.forward() * radius();
+ get_location() += axis().forward() * (radius() + ship_jumpdepart->target()->radius());
} else {
get_location().assign(ship_jumpdepart->target()->location() + location() - ship_jumpdepart->location());
}
diff --git a/src/game/base/ship.h b/src/game/base/ship.h
index c8d478c..971cb95 100644
--- a/src/game/base/ship.h
+++ b/src/game/base/ship.h
@@ -85,8 +85,6 @@ public:
/// Initiate jump, departing from a jump point
- /** Initiates a jump even if the ship has no jumpdrive
- */
void initiate_jump(JumpPoint *depart);
/// void reset drive controls
@@ -100,9 +98,6 @@ public:
/// toggle jump drive activation
void func_jump(std::string const & args);
-
-
- virtual void dock(Entity *entity);
private:
JumpPoint *find_closest_jumppoint();