[8494] | 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 | |
---|
[8858] | 31 | #include "util/Convert.h" |
---|
[8494] | 32 | #include "core/CoreIncludes.h" |
---|
| 33 | #include "core/XMLPort.h" |
---|
[8858] | 34 | #include "chat/ChatManager.h" |
---|
[8494] | 35 | |
---|
[9016] | 36 | #include <infos/PlayerInfo.h> |
---|
| 37 | #include <worldentities/ControllableEntity.h> |
---|
| 38 | |
---|
[8767] | 39 | #include "SpaceRace.h" |
---|
| 40 | |
---|
[8494] | 41 | namespace orxonox |
---|
| 42 | { |
---|
[9667] | 43 | RegisterClass(RaceCheckPoint); |
---|
[8767] | 44 | |
---|
[9667] | 45 | RaceCheckPoint::RaceCheckPoint(Context* context) : DistanceMultiTrigger(context), |
---|
| 46 | RadarViewable(this, static_cast<WorldEntity*> (this)) |
---|
[8494] | 47 | { |
---|
[8630] | 48 | RegisterObject(RaceCheckPoint); |
---|
[9016] | 49 | this->setDistance(100); |
---|
| 50 | this->setBeaconMode("off"); |
---|
| 51 | this->setBroadcast(false); |
---|
| 52 | this->setSimultaneousTriggerers(100); |
---|
[8630] | 53 | |
---|
| 54 | this->setRadarObjectColour(ColourValue::Blue); |
---|
[11071] | 55 | this->setRadarObjectShape(RadarViewable::Shape::Triangle); |
---|
[8494] | 56 | this->setRadarVisibility(false); |
---|
[9016] | 57 | this->settingsChanged(); |
---|
[9260] | 58 | |
---|
| 59 | this->checkpointIndex_ = 0; |
---|
| 60 | this->bIsLast_ = false; |
---|
| 61 | this->timeLimit_ = 0; |
---|
[8494] | 62 | } |
---|
[8767] | 63 | |
---|
[9526] | 64 | RaceCheckPoint::~RaceCheckPoint() |
---|
| 65 | { |
---|
[9260] | 66 | |
---|
[9526] | 67 | } |
---|
[8767] | 68 | |
---|
[8494] | 69 | void RaceCheckPoint::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 70 | { |
---|
[8630] | 71 | SUPER(RaceCheckPoint, XMLPort, xmlelement, mode); |
---|
[9260] | 72 | |
---|
[8630] | 73 | XMLPortParam(RaceCheckPoint, "checkpointindex", setCheckpointIndex, getCheckpointIndex, xmlelement, mode).defaultValues(0); |
---|
[9260] | 74 | XMLPortParam(RaceCheckPoint, "islast", setLast, isLast, xmlelement, mode).defaultValues(false); |
---|
[8630] | 75 | XMLPortParam(RaceCheckPoint, "timelimit", setTimelimit, getTimeLimit, xmlelement, mode).defaultValues(0); |
---|
[9263] | 76 | XMLPortParam(RaceCheckPoint, "nextcheckpoints", setNextCheckpointsAsVector3, getNextCheckpointsAsVector3, xmlelement, mode); |
---|
[8494] | 77 | } |
---|
[8767] | 78 | |
---|
[9260] | 79 | void RaceCheckPoint::fire(bool bIsTriggered, BaseObject* originator) |
---|
[8494] | 80 | { |
---|
[9260] | 81 | DistanceMultiTrigger::fire(bIsTriggered, originator); |
---|
| 82 | |
---|
| 83 | if (bIsTriggered) |
---|
| 84 | { |
---|
| 85 | ControllableEntity* entity = orxonox_cast<ControllableEntity*>(originator); |
---|
| 86 | if (entity) |
---|
[9526] | 87 | this->players_.push_back(entity->getPlayer()); |
---|
[9260] | 88 | } |
---|
[8494] | 89 | } |
---|
[8767] | 90 | |
---|
[8616] | 91 | void RaceCheckPoint::setTimelimit(float timeLimit) |
---|
[8630] | 92 | { |
---|
[9260] | 93 | this->timeLimit_ = timeLimit; |
---|
| 94 | if (this->timeLimit_ != 0) |
---|
[8630] | 95 | { |
---|
[9526] | 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); |
---|
[9348] | 98 | this->getGametype()->getGametypeInfo()->sendAnnounceMessage(message); |
---|
[9260] | 99 | ChatManager::message(message); |
---|
[8630] | 100 | } |
---|
| 101 | } |
---|
[9263] | 102 | |
---|
| 103 | void RaceCheckPoint::setNextCheckpointsAsVector3(const Vector3& checkpoints) |
---|
| 104 | { |
---|
| 105 | this->nextCheckpoints_.clear(); |
---|
| 106 | |
---|
[9973] | 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)); |
---|
[9263] | 113 | } |
---|
| 114 | |
---|
[9526] | 115 | PlayerInfo* RaceCheckPoint::getPlayer(unsigned int clientID) const |
---|
[9263] | 116 | { |
---|
[9526] | 117 | if (players_.size() > 0) |
---|
| 118 | { |
---|
[9667] | 119 | for (size_t i = 0; i < players_.size(); i++) |
---|
[9526] | 120 | { |
---|
| 121 | if (this->players_[i]->getClientID() == clientID) |
---|
| 122 | { |
---|
| 123 | return players_[i]; |
---|
| 124 | } |
---|
| 125 | } |
---|
| 126 | } |
---|
[11071] | 127 | return nullptr; |
---|
[9526] | 128 | } |
---|
| 129 | |
---|
| 130 | bool RaceCheckPoint::playerWasHere(PlayerInfo* player) const |
---|
| 131 | { |
---|
| 132 | if (players_.size() > 0) |
---|
| 133 | { |
---|
[9667] | 134 | for (size_t i = 0; i < players_.size(); i++) |
---|
[9526] | 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; |
---|
[11071] | 148 | for (int nextCheckpoint : nextCheckpoints_) |
---|
[9973] | 149 | { |
---|
[9526] | 150 | switch (count) |
---|
[9973] | 151 | { |
---|
[11071] | 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; |
---|
[9973] | 155 | } |
---|
| 156 | ++count; |
---|
[9526] | 157 | } |
---|
| 158 | return checkpoints; |
---|
| 159 | } |
---|
| 160 | |
---|
[8494] | 161 | } |
---|