Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/game
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2009-03-07 13:57:09 +0000
committerStijn Buys <ingar@osirion.org>2009-03-07 13:57:09 +0000
commit4c53365c16362156529c7669079e31845384589f (patch)
tree193bb5d05299d2acb38311d108c1d39b6e1dd229 /src/game
parentee2200638be3fcb14097f3e8b0abb93e210f93d9 (diff)
renamed Entity::eventstate() to Entity::state(),
introduced Destroyed state
Diffstat (limited to 'src/game')
-rw-r--r--src/game/base/collision.cc5
-rw-r--r--src/game/base/game.cc43
-rw-r--r--src/game/base/game.h1
-rw-r--r--src/game/base/jumppoint.cc6
-rw-r--r--src/game/base/planet.cc2
-rw-r--r--src/game/base/racetrack.cc20
-rw-r--r--src/game/base/ship.cc77
-rw-r--r--src/game/base/ship.h3
-rw-r--r--src/game/base/shipdealer.cc2
-rw-r--r--src/game/base/station.cc2
10 files changed, 114 insertions, 47 deletions
diff --git a/src/game/base/collision.cc b/src/game/base/collision.cc
index e4a312a..3da65d1 100644
--- a/src/game/base/collision.cc
+++ b/src/game/base/collision.cc
@@ -17,7 +17,7 @@ void Collision::distance_test(core::EntityControlable *first, core::Entity *seco
if (!first->owner())
return;
- if (first->eventstate() == core::Entity::Docked)
+ if (first->state() == core::Entity::Docked)
return;
// FIXME - use distancesquared
@@ -29,8 +29,9 @@ void Collision::distance_test(core::EntityControlable *first, core::Entity *seco
if ( (d-r) < 0.0f) {
// crash zone
- if (first->owner()->last_warning() + 5.0f < core::application()->time()) {
+ if ((first->moduletype() == ship_enttype) && (first->state() != core::Entity::Destroyed)) {
first->owner()->send_warning("^RBOOM!^N");
+ static_cast<Ship *>(first)->explode();
}
} else if (first->owner()->last_warning() + 5.0f < core::application()->time()) {
// warning zone: star corona or planet atmosphere
diff --git a/src/game/base/game.cc b/src/game/base/game.cc
index 29c36d6..b2824f5 100644
--- a/src/game/base/game.cc
+++ b/src/game/base/game.cc
@@ -85,7 +85,7 @@ void Game::func_join(core::Player *player, std::string const &args)
if (dock) {
ship->entity_location.assign(dock->location() + (dock->axis().forward() * ((ship->radius()+ dock->radius())*2.0f)));
ship->entity_axis.assign(dock->axis());
- ship->set_eventstate(core::Entity::Docked);
+ ship->set_state(core::Entity::Docked);
player->set_view(dock);
}
@@ -183,7 +183,7 @@ void Game::func_dock(core::Player *player, core::Entity *entity)
if ((entity->flags() & core::Entity::Dockable) == 0)
return;
- if (player->control()->eventstate() != core::Entity::Normal)
+ if (player->control()->state() != core::Entity::Normal)
return;
if ((entity->flags() & core::Entity::Dockable) == core::Entity::Dockable) {
@@ -200,7 +200,7 @@ void Game::func_launch(core::Player *player, std::string const &args)
if (!player->view())
return;
- if (player->control()->eventstate() != core::Entity::Docked)
+ if (player->control()->state() != core::Entity::Docked)
return;
assert(player->view()->zone() == player->control()->zone());
@@ -208,12 +208,42 @@ void Game::func_launch(core::Player *player, std::string const &args)
core::Entity *dock = player->view();
player->control()->entity_location.assign(dock->location() + (dock->axis().forward() * (player->control()->radius()+ dock->radius())*2.0f));
player->control()->entity_axis.assign(dock->axis());
- player->control()->set_eventstate(core::Entity::Normal);
+ player->control()->set_state(core::Entity::Normal);
player->set_view(0);
player->send("^BLaunching from " + dock->name());
}
+// respawn
+void Game::func_respawn(core::Player *player, std::string const &args)
+{
+ if (!player->control())
+ return;
+
+ if (!(player->view() == player->control()))
+ return;
+
+ if (player->control()->state() != core::Entity::Destroyed)
+ return;
+
+ player->control()->set_zone(Default::zone);
+ core::Entity *dock = player->control()->zone()->default_view();
+ if (dock) {
+ player->control()->entity_location.assign(dock->location() + (dock->axis().forward() * ((player->control()->radius()+ dock->radius())*2.0f)));
+ player->control()->entity_axis.assign(dock->axis());
+ player->control()->set_state(core::Entity::Docked);
+ player->set_view(dock);
+ player->send("^BRespawning at " + dock->name());
+ } else {
+ player->control()->location().clear();
+ player->control()->axis().clear();
+ player->control()->set_state(core::Entity::Normal);
+ player->set_view(0);
+ player->send("^BRespawning");
+ }
+}
+
+
// instantaniously goto a specified entity within the zone
void Game::func_goto(core::Player *player, const std::string &args)
{
@@ -233,7 +263,7 @@ void Game::func_goto(core::Player *player, const std::string &args)
player->control()->entity_location.assign(dock->location() + (dock->axis().forward() * (player->control()->radius()+dock->radius())*2.0f));
player->control()->entity_axis.assign(dock->axis());
player->control()->entity_axis.change_direction(180.0f);
- player->control()->set_eventstate(core::Entity::Normal);
+ player->control()->set_state(core::Entity::Normal);
player->set_view(0);
player->send("Going to " + dock->name());
} else {
@@ -290,6 +320,9 @@ Game::Game() : core::Module("Project::OSiRiON", true)
func = core::Func::add("launch", Game::func_launch);
func->set_info("launch to space when docked");
+ func = core::Func::add("respawn", Game::func_respawn);
+ func->set_info("respawn when your ship has been destroyed");
+
func = core::Func::add("goto", Game::func_goto);
func->set_info("[string] goto to an entity within the zone");
diff --git a/src/game/base/game.h b/src/game/base/game.h
index 2af71ef..36de8dc 100644
--- a/src/game/base/game.h
+++ b/src/game/base/game.h
@@ -101,6 +101,7 @@ private:
static void func_impulse(core::Player *player, std::string const &args);
static void func_dock(core::Player *player,core::Entity *entity);
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_goto(core::Player *player, const std::string &args);
};
diff --git a/src/game/base/jumppoint.cc b/src/game/base/jumppoint.cc
index eb51b68..e489055 100644
--- a/src/game/base/jumppoint.cc
+++ b/src/game/base/jumppoint.cc
@@ -81,7 +81,7 @@ JumpGate::JumpGate() : JumpPoint()
entity_radius = 1.0f;
entity_moduletypeid = jumpgate_enttype;
- entity_eventstate = core::Entity::NoPower;
+ entity_state = core::Entity::NoPower;
}
JumpGate::~JumpGate()
@@ -138,7 +138,7 @@ void JumpGate::dock(core::Entity *entity)
void JumpGate::activate()
{
jumpgate_timer = 10.0f;
- entity_eventstate = core::Entity::Normal;
+ set_state(core::Entity::Normal);
}
void JumpGate::frame(float elapsed)
@@ -147,7 +147,7 @@ void JumpGate::frame(float elapsed)
jumpgate_timer -= elapsed;
if (jumpgate_timer < 0) {
- entity_eventstate = core::Entity::NoPower;
+ set_state(core::Entity::NoPower);
jumpgate_timer = 0;
}
}
diff --git a/src/game/base/planet.cc b/src/game/base/planet.cc
index 6bb1f59..3242f15 100644
--- a/src/game/base/planet.cc
+++ b/src/game/base/planet.cc
@@ -53,7 +53,7 @@ void Planet::dock(core::Entity *entity)
}
ship->location().assign(entity->location());
- ship->set_eventstate(core::Entity::Docked);
+ ship->set_state(core::Entity::Docked);
if (ship->owner() && ship->owner()->control() == ship) {
ship->owner()->set_view(this);
diff --git a/src/game/base/racetrack.cc b/src/game/base/racetrack.cc
index f36c047..f54a24b 100644
--- a/src/game/base/racetrack.cc
+++ b/src/game/base/racetrack.cc
@@ -17,7 +17,7 @@ namespace game {
CheckPoint::CheckPoint(RaceTrack *parent)
{
- entity_eventstate = core::Entity::NoPower;
+ set_state(core::Entity::NoPower);
parent_track = parent;
if (parent) {
entity_color = parent->color();
@@ -42,7 +42,7 @@ RaceTrack::RaceTrack() : EntityDynamic()
track_racestart = 0;
track_checkpointtime = 0;
- entity_eventstate = core::Entity::NoPower;
+ set_state(core::Entity::NoPower);
set_flag(core::Entity::Dockable);
}
@@ -66,10 +66,10 @@ void RaceTrack::reset()
track_checkpointtime = 0;
for (CheckPoints::iterator cpit = track_checkpoints.begin(); cpit != track_checkpoints.end(); ++cpit) {
- (*cpit)->set_eventstate(core::Entity::NoPower);
+ (*cpit)->set_state(core::Entity::NoPower);
}
- set_eventstate(core::Entity::NoPower);
+ set_state(core::Entity::NoPower);
}
void RaceTrack::dock(core::Entity *entity)
@@ -91,10 +91,10 @@ void RaceTrack::dock(core::Entity *entity)
track_player = ship->owner();
track_racestart = core::server()->time();
- set_eventstate(core::Entity::Normal);
+ set_state(core::Entity::Normal);
for (CheckPoints::iterator cpit = track_checkpoints.begin(); cpit != track_checkpoints.end(); ++cpit) {
- set_eventstate(core::Entity::Normal);
+ set_state(core::Entity::Normal);
}
entity_timer = 5.0f;
@@ -151,7 +151,7 @@ void RaceTrack::frame(float seconds)
track_racestart = core::server()->time();
} else {
for (CheckPoints::iterator cpit = track_checkpoints.begin(); cpit != track_checkpoints.end(); ++cpit) {
- (*cpit)->set_eventstate(core::Entity::NoPower);
+ (*cpit)->set_state(core::Entity::NoPower);
}
std::string message("^BGo!");
core::server()->broadcast(message);
@@ -159,7 +159,7 @@ void RaceTrack::frame(float seconds)
track_racestart = core::server()->time();
track_checkpointtime = core::server()->time() + 15.0f;
track_checkpoint = track_checkpoints.begin();
- (*track_checkpoint)->set_eventstate(core::Entity::Normal);
+ (*track_checkpoint)->set_state(core::Entity::Normal);
track_player->set_mission_target((*track_checkpoint));
}
}
@@ -184,9 +184,9 @@ void RaceTrack::frame(float seconds)
std::string message("^BCheckpoint!");
core::server()->broadcast(message);
track_checkpointtime = core::server()->time() + 15.0f;
- (*track_checkpoint)->set_eventstate(core::Entity::NoPower);
+ (*track_checkpoint)->set_state(core::Entity::NoPower);
track_checkpoint++;
- (*track_checkpoint)->set_eventstate(core::Entity::Normal);
+ (*track_checkpoint)->set_state(core::Entity::Normal);
track_player->set_mission_target((*track_checkpoint));
} else {
diff --git a/src/game/base/ship.cc b/src/game/base/ship.cc
index edfc949..ba5d7ba 100644
--- a/src/game/base/ship.cc
+++ b/src/game/base/ship.cc
@@ -63,24 +63,24 @@ void Ship::reset()
}
void Ship::func_impulse()
{
- if (entity_eventstate == core::Entity::Impulse) {
- entity_eventstate = core::Entity::Normal;
+ if (entity_state == core::Entity::Impulse) {
+ entity_state = core::Entity::Normal;
target_thrust = 1.0f;
entity_thrust = 1.0f;
- } else if (entity_eventstate == core::Entity::ImpulseInitiate) {
- entity_eventstate = core::Entity::Normal;
+ } else if (entity_state == core::Entity::ImpulseInitiate) {
+ entity_state = core::Entity::Normal;
- } else if (entity_eventstate != core::Entity::Normal) {
+ } else if (entity_state != core::Entity::Normal) {
return;
} else {
- if (entity_eventstate == core::Entity::JumpInitiate) {
+ if (entity_state == core::Entity::JumpInitiate) {
ship_jumpdrive_timer = 0;
entity_timer = 0;
}
- entity_eventstate = core::Entity::ImpulseInitiate;
+ entity_state = core::Entity::ImpulseInitiate;
if (Game::g_devel->value()) {
entity_timer = 0;
} else {
@@ -104,7 +104,7 @@ void Ship::initiate_jump(JumpPoint *depart)
return;
ship_jumpdepart = depart;
- entity_eventstate = core::Entity::JumpInitiate;
+ entity_state = core::Entity::JumpInitiate;
if (Game::g_devel->value()) {
entity_timer = 0;
@@ -118,7 +118,7 @@ void Ship::initiate_jump(JumpPoint *depart)
void Ship::func_jump(std::string const &args)
{
- if (entity_eventstate == core::Entity::Docked) {
+ if (entity_state == core::Entity::Docked) {
return;
}
@@ -150,7 +150,7 @@ void Ship::func_jump(std::string const &args)
ship_jumpdrive_timer = 0;
entity_timer = 0;
- entity_eventstate = core::Entity::Jump;
+ entity_state = core::Entity::Jump;
entity_dirty = true;
return;
@@ -160,14 +160,14 @@ void Ship::func_jump(std::string const &args)
owner()->send("This ship is not equiped with a hyperspace drive!");
return;
- } else if (entity_eventstate == core::Entity::Jump) {
+ } else if (entity_state == core::Entity::Jump) {
return;
- } else if (entity_eventstate == core::Entity::JumpInitiate) {
+ } else if (entity_state == core::Entity::JumpInitiate) {
owner()->send("Jump aborted, hyperspace drive deactivated");
ship_jumpdrive_timer = 0;
entity_timer = 0;
- entity_eventstate = core::Entity::Normal;
+ entity_state = core::Entity::Normal;
return;
}
initiate_jump(find_closest_jumppoint());
@@ -207,6 +207,24 @@ JumpPoint * Ship::find_closest_jumppoint()
return 0;
}
+void Ship::explode()
+{
+ set_state(core::Entity::Destroyed);
+
+ target_thrust = 0;
+ target_pitch = 0;
+ target_roll = 0;
+ target_direction = 0;
+ target_afterburner = 0.0f;
+ target_thrust = 0;
+ entity_thrust = 0;
+
+ if (owner()) {
+ if (owner()->control() == this)
+ owner()->set_view(this);
+ }
+};
+
void Ship::frame(float seconds)
{
const float direction_change_speed = 2;
@@ -228,7 +246,7 @@ void Ship::frame(float seconds)
// target axis
math::Axis target_axis(entity_axis);
- if (entity_eventstate == core::Entity::Docked) {
+ if (entity_state == core::Entity::Docked) {
target_thrust = 0;
target_pitch = 0;
@@ -238,16 +256,17 @@ void Ship::frame(float seconds)
target_thrust = 0;
entity_speed = 0;
+ entity_thrust = 0;
return;
- } else if (entity_eventstate == core::Entity::JumpInitiate) {
+ } else if (entity_state == core::Entity::JumpInitiate) {
if (ship_jumpdrive_timer + 1.0f <= core::server()->time()) {
entity_timer -= 1.0f;
if (entity_timer <= 0) {
if (ship_jumpdepart && ship_jumpdepart->target()) {
- entity_eventstate = core::Entity::Jump;
+ set_state(core::Entity::Jump);
set_zone(ship_jumpdepart->target()->zone());
if (owner() && owner()->control() == (EntityControlable*) this)
owner()->set_zone(ship_jumpdepart->target()->zone());
@@ -261,7 +280,7 @@ void Ship::frame(float seconds)
}
owner()->send("^BJumping to the " + ship_jumpdepart->target()->zone()->name());
} else {
- entity_eventstate = core::Entity::Normal;
+ set_state(core::Entity::Normal);
}
ship_jumpdrive_timer = 0;
entity_timer = 0;
@@ -282,7 +301,7 @@ void Ship::frame(float seconds)
target_afterburner = 0.0f;
target_thrust = 0.1;
- } else if (entity_eventstate == core::Entity::Jump) {
+ } else if (entity_state == core::Entity::Jump) {
// control is disabled while the jumpdrive is activated
target_thrust = 0;
target_pitch = 0;
@@ -298,12 +317,12 @@ void Ship::frame(float seconds)
// FIXME 5 second cooldown
entity_speed = Game::g_impulsespeed->value();
- entity_eventstate = core::Entity::Normal;
+ entity_state = core::Entity::Normal;
if (owner() && owner()->view() && owner()->control() == (EntityControlable*) this)
owner()->set_view(0);
- } else if (entity_eventstate == core::Entity::ImpulseInitiate) {
+ } else if (entity_state == core::Entity::ImpulseInitiate) {
if (ship_impulsedrive_timer + 1.0f <= core::server()->time()) {
entity_timer -= 1.0f;
@@ -311,7 +330,7 @@ void Ship::frame(float seconds)
if (entity_timer <= 0) {
actual_maxspeed = Game::g_impulsespeed->value();
actual_acceleration = Game::g_impulseacceleration->value();
- entity_eventstate = core::Entity::Impulse;
+ entity_state = core::Entity::Impulse;
entity_timer = 0;
entity_dirty = true;
} else {
@@ -328,7 +347,7 @@ void Ship::frame(float seconds)
math::clamp(target_afterburner, -1.0f, 1.0f);
actual_turnspeed *= 0.5;
- } else if (entity_eventstate == core::Entity::Impulse) {
+ } else if (entity_state == core::Entity::Impulse) {
// clamp input values
target_thrust = 0.0f;
@@ -340,7 +359,7 @@ void Ship::frame(float seconds)
actual_acceleration = Game::g_impulseacceleration->value();
actual_turnspeed *= 0.5;
- } else if (entity_eventstate == core::Entity::Normal) {
+ } else if (entity_state == core::Entity::Normal) {
// clamp input values
math::clamp(target_thrust, 0.0f, 1.0f);
@@ -354,6 +373,16 @@ void Ship::frame(float seconds)
actual_turnspeed *= 0.5;
}
+ } else if (entity_state == core::Entity::Destroyed) {
+
+ target_thrust = 0;
+ target_pitch = 0;
+ target_roll = 0;
+ target_direction = 0;
+ target_afterburner = 0.0f;
+ target_thrust = 0;
+
+ entity_thrust = 0;
}
// update roll
@@ -449,7 +478,7 @@ void Ship::frame(float seconds)
math::clamp(entity_thrust, 0.0f, 1.0f);
float actual_thrust = entity_thrust + current_target_afterburner * 0.15f;
- if ((entity_eventstate == core::Entity::ImpulseInitiate) || (entity_eventstate == core::Entity::Impulse)) {
+ if ((entity_state == core::Entity::ImpulseInitiate) || (entity_state == core::Entity::Impulse)) {
actual_thrust = 1.0f;
}
diff --git a/src/game/base/ship.h b/src/game/base/ship.h
index bed3d1e..37f8b88 100644
--- a/src/game/base/ship.h
+++ b/src/game/base/ship.h
@@ -36,6 +36,9 @@ public:
/// void reset drive controls
void reset();
+ /// explode the ship
+ void explode();
+
/// toggle impulse drive activation
void func_impulse();
diff --git a/src/game/base/shipdealer.cc b/src/game/base/shipdealer.cc
index 5aced0b..e28b922 100644
--- a/src/game/base/shipdealer.cc
+++ b/src/game/base/shipdealer.cc
@@ -133,7 +133,7 @@ void ShipDealer::func_buy(core::Player *player, const std::string &args)
if (dock) {
ship->set_zone(dock->zone());
ship->location().assign(dock->location());
- ship->set_eventstate(core::Entity::Docked);
+ ship->set_state(core::Entity::Docked);
ship->entity_axis.assign(dock->axis());
ship->entity_axis.change_direction(180.0f);
player->set_control(ship);
diff --git a/src/game/base/station.cc b/src/game/base/station.cc
index d39f1c6..69949fb 100644
--- a/src/game/base/station.cc
+++ b/src/game/base/station.cc
@@ -47,7 +47,7 @@ void Station::dock(core::Entity *entity)
}
ship->location().assign(entity->location());
- ship->set_eventstate(core::Entity::Docked);
+ ship->set_state(core::Entity::Docked);
if (ship->owner() && ship->owner()->control() == ship) {
ship->owner()->set_view(this);