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