diff options
author | Stijn Buys <ingar@osirion.org> | 2008-12-28 12:33:04 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2008-12-28 12:33:04 +0000 |
commit | 4e1d951705204899ee99d7fcedf582b25b86b506 (patch) | |
tree | 03cb919ff062368dfc334b9f71b932cf89e31517 /src/game/base/racetrack.cc | |
parent | 82c63c49134a6fca91d908792438e6284dc4cebf (diff) |
generic docking API,
race activating requires docking
Diffstat (limited to 'src/game/base/racetrack.cc')
-rw-r--r-- | src/game/base/racetrack.cc | 66 |
1 files changed, 37 insertions, 29 deletions
diff --git a/src/game/base/racetrack.cc b/src/game/base/racetrack.cc index 46a7c86..b543c9c 100644 --- a/src/game/base/racetrack.cc +++ b/src/game/base/racetrack.cc @@ -7,6 +7,7 @@ #include <string> #include <sstream> +#include "base/game.h" #include "base/racetrack.h" #include "core/gameserver.h" @@ -42,6 +43,7 @@ RaceTrack::RaceTrack() : EntityDynamic() track_checkpointtime = 0; entity_eventstate = core::Entity::NoPower; + set_flag(core::Entity::Dockable); } RaceTrack::~RaceTrack() @@ -70,40 +72,46 @@ void RaceTrack::reset() set_eventstate(core::Entity::NoPower); } -void RaceTrack::frame(float seconds) +void RaceTrack::dock(core::Entity *entity) { - if (!track_checkpoints.size()) + + if (entity->moduletype() != ship_enttype) return; + Ship * ship = static_cast<Ship *>(entity); - if (!track_player) { - - // FIXME this should go through proper collision detection - for (core::GameServer::Players::iterator it = core::server()->players().begin(); it != core::server()->players().end(); ++it) { - if ((*it)->control() && (*it)->control()->zone() == zone()) { - if (math::distance((*it)->control()->location(), location()) <= 1) { - track_player = (*it); - - track_racestart = core::server()->time(); - set_eventstate(core::Entity::Normal); - - for (CheckPoints::iterator cpit = track_checkpoints.begin(); cpit != track_checkpoints.end(); ++cpit) { - set_eventstate(core::Entity::Normal); - } - - entity_timer = 5.0f; - std::string message("^B"); - message.append(track_player->name()); - message.append(" ^Bactivated the race! Race starts in 5..."); - core::server()->broadcast(message); - track_player->set_mission_target(this); - return; - } - } - } + if (math::distance(location(), ship->location()) > radius()) { + ship->owner()->send("Target out of range"); + return; + } + if (track_player) { + ship->owner()->send("Race in use"); return; } + track_player = ship->owner(); + track_racestart = core::server()->time(); + set_eventstate(core::Entity::Normal); + + for (CheckPoints::iterator cpit = track_checkpoints.begin(); cpit != track_checkpoints.end(); ++cpit) { + set_eventstate(core::Entity::Normal); + } + + entity_timer = 5.0f; + std::string message("^B" + track_player->name() + " ^Bactivated the race! Race starts in 5..."); + core::server()->broadcast(message); + track_player->set_mission_target(this); + return; +} + +void RaceTrack::frame(float seconds) +{ + if (!track_checkpoints.size()) + return; + + if (!track_player) + return; + // FIXME this should go into a proper general function // validate current player core::Player *player = 0; @@ -125,7 +133,7 @@ void RaceTrack::frame(float seconds) if (entity_timer) { - if (math::distance(player->control()->location(), location()) > 1) { + if (math::distance(location(), player->control()->location()) > radius()) { std::string message("^BNo cheating!"); core::server()->broadcast(message); reset(); @@ -167,7 +175,7 @@ void RaceTrack::frame(float seconds) return; } - if (math::distance(track_player->control()->location(), (*track_checkpoint)->location()) <= 1) { + if (math::distance(track_player->control()->location(), (*track_checkpoint)->location()) < radius()) { CheckPoints::iterator next_checkpoint = track_checkpoint; next_checkpoint++; |