Changeset 9964 for code/trunk
- Timestamp:
- Jan 3, 2014, 9:44:23 PM (11 years ago)
- Location:
- code/trunk/src/modules/gametypes
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/modules/gametypes/RaceCheckPoint.cc
r9963 r9964 104 104 } 105 105 106 //Must not be called before setNextCheckpointsAsVector3 at least once has been called107 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 correctly117 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 140 106 void RaceCheckPoint::setNextCheckpointsAsVector3(const Vector3& checkpoints) 141 107 { … … 148 114 if (checkpoints.z > -1) 149 115 this->nextCheckpoints_.insert(static_cast<int>(checkpoints.z + 0.5)); 150 151 this->nextCheckpointsVirtual_=nextCheckpoints_;152 116 } 153 117 … … 195 159 } 196 160 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 161 } 208 162 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() const219 {220 Vector3 checkpoints = Vector3(-1, -1, -1);221 222 size_t count = 0;223 for (std::set<int>::iterator it = this->nextCheckpointsVirtual_.begin(); it != this->nextCheckpointsVirtual_.end(); ++it)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 }236 163 } -
code/trunk/src/modules/gametypes/RaceCheckPoint.h
r9963 r9964 61 61 void setNextCheckpointsAsVector3(const Vector3& checkpoints); 62 62 Vector3 getNextCheckpointsAsVector3(); 63 Vector3 getVirtualNextCheckpointsAsVector3() const;64 void setNextVirtualCheckpointsAsVector3(const Vector3& checkpoints);65 int changeVirtualToRealCheckPoint(int);66 67 const std::set<int>& getVirtualNextCheckpoints() const68 {69 return this->nextCheckpointsVirtual_;70 }71 63 72 64 std::set<int> getNextCheckpoints() 73 65 { 74 66 return nextCheckpoints_; 75 std::set<int> temp;76 std::set<int> temp2=getVirtualNextCheckpoints();77 for (std::set<int>::iterator it = temp2.begin(); it!=temp2.end(); ++it){78 temp.insert(changeVirtualToRealCheckPoint((*it)));79 }80 return temp;81 67 } 82 68 inline void setLast(bool isLast) … … 120 106 float timeLimit_; ///< The time limit (from the start of the level) to reach this check point. If the check point is reached after this time, the game ends and the player looses. 121 107 std::vector<PlayerInfo*> players_; ///< The player that reached the checkpoint 122 std::set<int> nextCheckpointsVirtual_;123 std::map<int,int> virtualToRealCheckPoints_; // if virtualChepoint was inserted the original can be reconstructed124 108 }; 125 109 } -
code/trunk/src/modules/gametypes/SpaceRaceController.cc
r9962 r9964 188 188 { 189 189 int numberOfWays = 0; // counts number of ways from this Point to the last point 190 for (std::set<int>::iterator it = currentCheckpoint->get VirtualNextCheckpoints().begin(); it!= currentCheckpoint->getVirtualNextCheckpoints().end(); ++it)190 for (std::set<int>::iterator it = currentCheckpoint->getNextCheckpoints().begin(); it!= currentCheckpoint->getNextCheckpoints().end(); ++it) 191 191 { 192 192 if(currentCheckpoint == findCheckpoint(*it)) … … 224 224 float distances[] = {-1, -1, -1}; 225 225 int temp_i = 0; 226 for (std::set<int>::iterator it =raceCheckpoint->get VirtualNextCheckpoints().begin(); it!= raceCheckpoint->getVirtualNextCheckpoints().end(); ++it)226 for (std::set<int>::iterator it =raceCheckpoint->getNextCheckpoints().begin(); it!= raceCheckpoint->getNextCheckpoints().end(); ++it) 227 227 { 228 228 distances[temp_i] = recCalculateDistance(findCheckpoint(*it), this->getControllableEntity()->getPosition()); … … 233 233 if (distances[2] < distances[1] && distances[2] >= 0) 234 234 { 235 return findCheckpoint(*raceCheckpoint->get VirtualNextCheckpoints().end()); // return checkpoint with ID of raceCheckpoint->getNextCheckpoints() [2]235 return findCheckpoint(*raceCheckpoint->getNextCheckpoints().end()); // return checkpoint with ID of raceCheckpoint->getNextCheckpoints() [2] 236 236 } 237 237 else 238 238 { 239 std::set<int>::iterator temp = raceCheckpoint->get VirtualNextCheckpoints().begin();239 std::set<int>::iterator temp = raceCheckpoint->getNextCheckpoints().begin(); 240 240 return findCheckpoint(*(++temp)); // return [1] 241 241 } … … 245 245 if (distances[2] < distances[0] && distances[2] >= 0) 246 246 { 247 return findCheckpoint(*raceCheckpoint->get VirtualNextCheckpoints().end()); // return [2]247 return findCheckpoint(*raceCheckpoint->getNextCheckpoints().end()); // return [2] 248 248 } 249 249 else 250 250 { 251 return findCheckpoint(*raceCheckpoint->get VirtualNextCheckpoints().begin()); // return [0]251 return findCheckpoint(*raceCheckpoint->getNextCheckpoints().begin()); // return [0] 252 252 } 253 253 } … … 268 268 { 269 269 float minimum = std::numeric_limits<float>::max(); 270 for (std::set<int>::iterator it = currentCheckPoint->get VirtualNextCheckpoints().begin(); it != currentCheckPoint->getVirtualNextCheckpoints().end(); ++it)270 for (std::set<int>::iterator it = currentCheckPoint->getNextCheckpoints().begin(); it != currentCheckPoint->getNextCheckpoints().end(); ++it) 271 271 { 272 272 int dist_currentCheckPoint_currentPosition = static_cast<int> ((currentPosition- currentCheckPoint->getPosition()).length()); … … 289 289 return nextRaceCheckpoint_; 290 290 } 291 if ((currentRaceCheckpoint_->get VirtualNextCheckpoints()).size() == 1) // no Adjust possible291 if ((currentRaceCheckpoint_->getNextCheckpoints()).size() == 1) // no Adjust possible 292 292 293 293 {
Note: See TracChangeset
for help on using the changeset viewer.