| 1 | /* |
|---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
|---|
| 3 | * > www.orxonox.net < |
|---|
| 4 | * |
|---|
| 5 | * |
|---|
| 6 | * License notice: |
|---|
| 7 | * |
|---|
| 8 | * This program is free software; you can redistribute it and/or |
|---|
| 9 | * modify it under the terms of the GNU General Public License |
|---|
| 10 | * as published by the Free Software Foundation; either version 2 |
|---|
| 11 | * of the License, or (at your option) any later version. |
|---|
| 12 | * |
|---|
| 13 | * This program is distributed in the hope that it will be useful, |
|---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 16 | * GNU General Public License for more details. |
|---|
| 17 | * |
|---|
| 18 | * You should have received a copy of the GNU General Public License |
|---|
| 19 | * along with this program; if not, write to the Free Software |
|---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|---|
| 21 | * |
|---|
| 22 | * Author: |
|---|
| 23 | * Mauro Salomon |
|---|
| 24 | * Co-authors: |
|---|
| 25 | * ... |
|---|
| 26 | * |
|---|
| 27 | */ |
|---|
| 28 | |
|---|
| 29 | #include "RaceCheckPoint.h" |
|---|
| 30 | |
|---|
| 31 | #include "util/Convert.h" |
|---|
| 32 | #include "core/CoreIncludes.h" |
|---|
| 33 | #include "core/XMLPort.h" |
|---|
| 34 | #include "chat/ChatManager.h" |
|---|
| 35 | |
|---|
| 36 | #include <infos/PlayerInfo.h> |
|---|
| 37 | #include <worldentities/ControllableEntity.h> |
|---|
| 38 | |
|---|
| 39 | #include "SpaceRace.h" |
|---|
| 40 | |
|---|
| 41 | namespace orxonox |
|---|
| 42 | { |
|---|
| 43 | RegisterClass(RaceCheckPoint); |
|---|
| 44 | |
|---|
| 45 | RaceCheckPoint::RaceCheckPoint(Context* context) : DistanceMultiTrigger(context), |
|---|
| 46 | RadarViewable(this, static_cast<WorldEntity*> (this)) |
|---|
| 47 | { |
|---|
| 48 | RegisterObject(RaceCheckPoint); |
|---|
| 49 | this->setDistance(100); |
|---|
| 50 | this->setBeaconMode("off"); |
|---|
| 51 | this->setBroadcast(false); |
|---|
| 52 | this->setSimultaneousTriggerers(100); |
|---|
| 53 | |
|---|
| 54 | this->setRadarObjectColour(ColourValue::Blue); |
|---|
| 55 | this->setRadarObjectShape(RadarViewable::Shape::Triangle); |
|---|
| 56 | this->setRadarVisibility(false); |
|---|
| 57 | this->settingsChanged(); |
|---|
| 58 | |
|---|
| 59 | this->checkpointIndex_ = 0; |
|---|
| 60 | this->bIsLast_ = false; |
|---|
| 61 | this->timeLimit_ = 0; |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | RaceCheckPoint::~RaceCheckPoint() |
|---|
| 65 | { |
|---|
| 66 | |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | void RaceCheckPoint::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
|---|
| 70 | { |
|---|
| 71 | SUPER(RaceCheckPoint, XMLPort, xmlelement, mode); |
|---|
| 72 | |
|---|
| 73 | XMLPortParam(RaceCheckPoint, "checkpointindex", setCheckpointIndex, getCheckpointIndex, xmlelement, mode).defaultValues(0); |
|---|
| 74 | XMLPortParam(RaceCheckPoint, "islast", setLast, isLast, xmlelement, mode).defaultValues(false); |
|---|
| 75 | XMLPortParam(RaceCheckPoint, "timelimit", setTimelimit, getTimeLimit, xmlelement, mode).defaultValues(0); |
|---|
| 76 | XMLPortParam(RaceCheckPoint, "nextcheckpoints", setNextCheckpointsAsVector3, getNextCheckpointsAsVector3, xmlelement, mode); |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | void RaceCheckPoint::fire(bool bIsTriggered, BaseObject* originator) |
|---|
| 80 | { |
|---|
| 81 | DistanceMultiTrigger::fire(bIsTriggered, originator); |
|---|
| 82 | |
|---|
| 83 | if (bIsTriggered) |
|---|
| 84 | { |
|---|
| 85 | ControllableEntity* entity = orxonox_cast<ControllableEntity*>(originator); |
|---|
| 86 | if (entity) |
|---|
| 87 | this->players_.push_back(entity->getPlayer()); |
|---|
| 88 | } |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | void RaceCheckPoint::setTimelimit(float timeLimit) |
|---|
| 92 | { |
|---|
| 93 | this->timeLimit_ = timeLimit; |
|---|
| 94 | if (this->timeLimit_ != 0) |
|---|
| 95 | { |
|---|
| 96 | std::string message = "You have " + multi_cast<std::string>(this->timeLimit_) |
|---|
| 97 | + " seconds to reach the check point " + multi_cast<std::string>(this->checkpointIndex_ + 1); |
|---|
| 98 | this->getGametype()->getGametypeInfo()->sendAnnounceMessage(message); |
|---|
| 99 | ChatManager::message(message); |
|---|
| 100 | } |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | void RaceCheckPoint::setNextCheckpointsAsVector3(const Vector3& checkpoints) |
|---|
| 104 | { |
|---|
| 105 | this->nextCheckpoints_.clear(); |
|---|
| 106 | |
|---|
| 107 | if (checkpoints.x > -0.5) |
|---|
| 108 | this->nextCheckpoints_.insert(static_cast<int>(checkpoints.x + 0.5)); // the red number has the type double and for the cast (to int) is added 0.5 so that the cast works correctly |
|---|
| 109 | if (checkpoints.y > -0.5) |
|---|
| 110 | this->nextCheckpoints_.insert(static_cast<int>(checkpoints.y + 0.5)); |
|---|
| 111 | if (checkpoints.z > -0.5) |
|---|
| 112 | this->nextCheckpoints_.insert(static_cast<int>(checkpoints.z + 0.5)); |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | PlayerInfo* RaceCheckPoint::getPlayer(unsigned int clientID) const |
|---|
| 116 | { |
|---|
| 117 | if (players_.size() > 0) |
|---|
| 118 | { |
|---|
| 119 | for (size_t i = 0; i < players_.size(); i++) |
|---|
| 120 | { |
|---|
| 121 | if (this->players_[i]->getClientID() == clientID) |
|---|
| 122 | { |
|---|
| 123 | return players_[i]; |
|---|
| 124 | } |
|---|
| 125 | } |
|---|
| 126 | } |
|---|
| 127 | return nullptr; |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | bool RaceCheckPoint::playerWasHere(PlayerInfo* player) const |
|---|
| 131 | { |
|---|
| 132 | if (players_.size() > 0) |
|---|
| 133 | { |
|---|
| 134 | for (size_t i = 0; i < players_.size(); i++) |
|---|
| 135 | { |
|---|
| 136 | if (this->players_[i] == player) |
|---|
| 137 | { |
|---|
| 138 | return true; |
|---|
| 139 | } |
|---|
| 140 | } |
|---|
| 141 | } |
|---|
| 142 | return false; |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | Vector3 RaceCheckPoint::getNextCheckpointsAsVector3() |
|---|
| 146 | { |
|---|
| 147 | Vector3 checkpoints(-1,-1,-1); int count=0; |
|---|
| 148 | for (int nextCheckpoint : nextCheckpoints_) |
|---|
| 149 | { |
|---|
| 150 | switch (count) |
|---|
| 151 | { |
|---|
| 152 | case 0: checkpoints.x = static_cast<Ogre::Real>(nextCheckpoint); break; |
|---|
| 153 | case 1: checkpoints.y = static_cast<Ogre::Real>(nextCheckpoint); break; |
|---|
| 154 | case 2: checkpoints.z = static_cast<Ogre::Real>(nextCheckpoint); break; |
|---|
| 155 | } |
|---|
| 156 | ++count; |
|---|
| 157 | } |
|---|
| 158 | return checkpoints; |
|---|
| 159 | } |
|---|
| 160 | |
|---|
| 161 | } |
|---|