[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); |
---|
[8616] | 55 | this->setRadarObjectShape(RadarViewable::Triangle); |
---|
[8494] | 56 | this->setRadarVisibility(false); |
---|
[9016] | 57 | this->settingsChanged(); |
---|
[9260] | 58 | |
---|
| 59 | this->checkpointIndex_ = 0; |
---|
| 60 | this->bIsLast_ = false; |
---|
| 61 | this->timeLimit_ = 0; |
---|
[9526] | 62 | //this->players_ = vector<PlayerInfo*>(); |
---|
| 63 | |
---|
| 64 | //orxout(user_status) << "test" << std::endl; |
---|
[8494] | 65 | } |
---|
[8767] | 66 | |
---|
[9526] | 67 | RaceCheckPoint::~RaceCheckPoint() |
---|
| 68 | { |
---|
[9260] | 69 | |
---|
[9526] | 70 | } |
---|
[8767] | 71 | |
---|
[8494] | 72 | void RaceCheckPoint::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 73 | { |
---|
[8630] | 74 | SUPER(RaceCheckPoint, XMLPort, xmlelement, mode); |
---|
[9260] | 75 | |
---|
[8630] | 76 | XMLPortParam(RaceCheckPoint, "checkpointindex", setCheckpointIndex, getCheckpointIndex, xmlelement, mode).defaultValues(0); |
---|
[9260] | 77 | XMLPortParam(RaceCheckPoint, "islast", setLast, isLast, xmlelement, mode).defaultValues(false); |
---|
[8630] | 78 | XMLPortParam(RaceCheckPoint, "timelimit", setTimelimit, getTimeLimit, xmlelement, mode).defaultValues(0); |
---|
[9263] | 79 | XMLPortParam(RaceCheckPoint, "nextcheckpoints", setNextCheckpointsAsVector3, getNextCheckpointsAsVector3, xmlelement, mode); |
---|
[8494] | 80 | } |
---|
[8767] | 81 | |
---|
[9260] | 82 | void RaceCheckPoint::fire(bool bIsTriggered, BaseObject* originator) |
---|
[8494] | 83 | { |
---|
[9260] | 84 | DistanceMultiTrigger::fire(bIsTriggered, originator); |
---|
| 85 | |
---|
| 86 | if (bIsTriggered) |
---|
| 87 | { |
---|
| 88 | ControllableEntity* entity = orxonox_cast<ControllableEntity*>(originator); |
---|
| 89 | if (entity) |
---|
[9526] | 90 | this->players_.push_back(entity->getPlayer()); |
---|
[9260] | 91 | } |
---|
[8494] | 92 | } |
---|
[8767] | 93 | |
---|
[8616] | 94 | void RaceCheckPoint::setTimelimit(float timeLimit) |
---|
[8630] | 95 | { |
---|
[9260] | 96 | this->timeLimit_ = timeLimit; |
---|
| 97 | if (this->timeLimit_ != 0) |
---|
[8630] | 98 | { |
---|
[9526] | 99 | std::string message = "You have " + multi_cast<std::string>(this->timeLimit_) |
---|
| 100 | + " seconds to reach the check point " + multi_cast<std::string>(this->checkpointIndex_ + 1); |
---|
[9348] | 101 | this->getGametype()->getGametypeInfo()->sendAnnounceMessage(message); |
---|
[9260] | 102 | ChatManager::message(message); |
---|
[8630] | 103 | } |
---|
| 104 | } |
---|
[9263] | 105 | |
---|
[9526] | 106 | //Must not be called before setNextCheckpointsAsVector3 at least once has been called |
---|
| 107 | void RaceCheckPoint::setNextVirtualCheckpointsAsVector3(const Vector3& checkpoints){ |
---|
| 108 | /*std::set<int> lastcheckpoints=this->nextCheckpoints_; |
---|
| 109 | nextCheckpoints_.clear(); |
---|
| 110 | std::set<int>::iterator it = lastcheckpoints.begin(); |
---|
| 111 | if(checkpoints.x<-1){ |
---|
| 112 | virtualToRealCheckPoints_.insert(std::pair<int,int>(checkpoints.x,(*it))); |
---|
| 113 | it++; |
---|
| 114 | } |
---|
| 115 | if(checkpoints.x!=-1) |
---|
| 116 | 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 |
---|
| 117 | |
---|
| 118 | if(checkpoints.y<-1){ |
---|
| 119 | virtualToRealCheckPoints_.insert(std::pair<int,int>(checkpoints.y,(*it))); |
---|
| 120 | it++; |
---|
| 121 | } |
---|
| 122 | if(checkpoints.y!=-1) |
---|
| 123 | this->nextCheckpoints_.insert(static_cast<int>(checkpoints.y + 0.5)); |
---|
| 124 | |
---|
| 125 | if(checkpoints.z<-1){ |
---|
| 126 | virtualToRealCheckPoints_.insert(std::pair<int,int>(checkpoints.z,(*it))); |
---|
| 127 | it++; |
---|
| 128 | } |
---|
| 129 | if(checkpoints.z!=-1) |
---|
| 130 | this->nextCheckpoints_.insert(static_cast<int>(checkpoints.z + 0.5));*/ |
---|
| 131 | nextCheckpointsVirtual_.clear(); |
---|
| 132 | if(checkpoints.x!=-1) |
---|
| 133 | nextCheckpointsVirtual_.insert(checkpoints.x); |
---|
| 134 | if(checkpoints.y!=-1) |
---|
| 135 | nextCheckpointsVirtual_.insert(checkpoints.y); |
---|
| 136 | if(checkpoints.z!=-1) |
---|
| 137 | nextCheckpointsVirtual_.insert(checkpoints.z); |
---|
| 138 | } |
---|
| 139 | |
---|
[9263] | 140 | void RaceCheckPoint::setNextCheckpointsAsVector3(const Vector3& checkpoints) |
---|
| 141 | { |
---|
| 142 | this->nextCheckpoints_.clear(); |
---|
| 143 | |
---|
| 144 | if (checkpoints.x > -1) |
---|
[9526] | 145 | 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 |
---|
[9263] | 146 | if (checkpoints.y > -1) |
---|
[9526] | 147 | this->nextCheckpoints_.insert(static_cast<int>(checkpoints.y + 0.5)); |
---|
[9263] | 148 | if (checkpoints.z > -1) |
---|
[9526] | 149 | this->nextCheckpoints_.insert(static_cast<int>(checkpoints.z + 0.5)); |
---|
| 150 | |
---|
| 151 | this->nextCheckpointsVirtual_=nextCheckpoints_; |
---|
[9263] | 152 | } |
---|
| 153 | |
---|
[9526] | 154 | PlayerInfo* RaceCheckPoint::getPlayer(unsigned int clientID) const |
---|
[9263] | 155 | { |
---|
[9526] | 156 | if (players_.size() > 0) |
---|
| 157 | { |
---|
[9667] | 158 | for (size_t i = 0; i < players_.size(); i++) |
---|
[9526] | 159 | { |
---|
| 160 | if (this->players_[i]->getClientID() == clientID) |
---|
| 161 | { |
---|
| 162 | return players_[i]; |
---|
| 163 | } |
---|
| 164 | } |
---|
| 165 | } |
---|
| 166 | return NULL; |
---|
| 167 | } |
---|
| 168 | |
---|
| 169 | bool RaceCheckPoint::playerWasHere(PlayerInfo* player) const |
---|
| 170 | { |
---|
| 171 | if (players_.size() > 0) |
---|
| 172 | { |
---|
[9667] | 173 | for (size_t i = 0; i < players_.size(); i++) |
---|
[9526] | 174 | { |
---|
| 175 | if (this->players_[i] == player) |
---|
| 176 | { |
---|
| 177 | return true; |
---|
| 178 | } |
---|
| 179 | } |
---|
| 180 | } |
---|
| 181 | return false; |
---|
| 182 | } |
---|
| 183 | |
---|
| 184 | Vector3 RaceCheckPoint::getNextCheckpointsAsVector3() |
---|
| 185 | { |
---|
| 186 | Vector3 checkpoints(-1,-1,-1); int count=0; |
---|
| 187 | for (std::set<int>::iterator it= nextCheckpoints_.begin();it!=nextCheckpoints_.end(); it++ ){ |
---|
| 188 | switch (count) |
---|
| 189 | { |
---|
| 190 | case 0: checkpoints.x = static_cast<Ogre::Real>(*it); break; |
---|
| 191 | case 1: checkpoints.y = static_cast<Ogre::Real>(*it); break; |
---|
| 192 | case 2: checkpoints.z = static_cast<Ogre::Real>(*it); break; |
---|
| 193 | } |
---|
| 194 | ++count; |
---|
| 195 | } |
---|
| 196 | return checkpoints; |
---|
| 197 | //= getVirtualNextCheckpointsAsVector3(); |
---|
| 198 | int j[3]; |
---|
| 199 | j[0]=changeVirtualToRealCheckPoint(checkpoints.x); |
---|
| 200 | j[1]=changeVirtualToRealCheckPoint(checkpoints.y); |
---|
| 201 | j[2]=changeVirtualToRealCheckPoint(checkpoints.z); |
---|
| 202 | |
---|
| 203 | |
---|
| 204 | return Vector3(j[0],j[1],j[2]); |
---|
| 205 | |
---|
| 206 | |
---|
| 207 | } |
---|
| 208 | |
---|
| 209 | int RaceCheckPoint::changeVirtualToRealCheckPoint(int checkpointID) { |
---|
| 210 | int temp=checkpointID; |
---|
| 211 | while(temp<-1){ |
---|
| 212 | temp = this->virtualToRealCheckPoints_[temp]; |
---|
| 213 | } |
---|
| 214 | return temp; |
---|
| 215 | } |
---|
| 216 | |
---|
| 217 | |
---|
| 218 | Vector3 RaceCheckPoint::getVirtualNextCheckpointsAsVector3() const |
---|
| 219 | { |
---|
[9263] | 220 | Vector3 checkpoints = Vector3(-1, -1, -1); |
---|
| 221 | |
---|
| 222 | size_t count = 0; |
---|
[9526] | 223 | for (std::set<int>::iterator it = this->nextCheckpointsVirtual_.begin(); it != this->nextCheckpointsVirtual_.end(); ++it) |
---|
[9263] | 224 | { |
---|
| 225 | switch (count) |
---|
| 226 | { |
---|
| 227 | case 0: checkpoints.x = static_cast<Ogre::Real>(*it); break; |
---|
| 228 | case 1: checkpoints.y = static_cast<Ogre::Real>(*it); break; |
---|
| 229 | case 2: checkpoints.z = static_cast<Ogre::Real>(*it); break; |
---|
| 230 | } |
---|
| 231 | ++count; |
---|
| 232 | } |
---|
| 233 | |
---|
| 234 | return checkpoints; |
---|
| 235 | } |
---|
[8494] | 236 | } |
---|