- Timestamp:
- Dec 11, 2012, 6:13:18 PM (12 years ago)
- Location:
- code/branches/Racingbot/src/modules/gametypes
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/Racingbot/src/modules/gametypes/RaceCheckPoint.cc
r9470 r9508 65 65 //orxout(user_status) << "test" << std::endl; 66 66 67 67 68 } 68 69 … … 104 105 ChatManager::message(message); 105 106 } 107 } 108 109 //Must not be called before setNextCheckpointsAsVector3 at least once has been called 110 void RaceCheckPoint::setNextVirtualCheckpointsAsVector3(const Vector3& checkpoints){ 111 std::set<int> lastcheckpoints=this->nextCheckpoints_; 112 nextCheckpoints_.clear(); 113 std::set<int>::iterator it = lastcheckpoints.begin(); 114 if(checkpoints.x<-1){ 115 virtualToRealCheckPoints_.insert(std::pair<int,int>(checkpoints.x,(*it))); 116 it++; 117 } 118 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 119 120 if(checkpoints.y<-1){ 121 virtualToRealCheckPoints_.insert(std::pair<int,int>(checkpoints.y,(*it))); 122 it++; 123 } 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 this->nextCheckpoints_.insert(static_cast<int>(checkpoints.z + 0.5)); 106 131 } 107 132 … … 148 173 } 149 174 150 Vector3 RaceCheckPoint::getNextCheckpointsAsVector3() const 175 Vector3 RaceCheckPoint::getNextCheckpointsAsVector3() 176 { 177 Vector3 checkpoints = getVirtualNextCheckpointsAsVector3(); 178 int j[3]; 179 j[0]=changeVirtualToRealCheckPoint(checkpoints.x); 180 j[1]=changeVirtualToRealCheckPoint(checkpoints.y); 181 j[2]=changeVirtualToRealCheckPoint(checkpoints.z); 182 183 184 return Vector3(j[0],j[1],j[2]); 185 186 187 } 188 189 int RaceCheckPoint::changeVirtualToRealCheckPoint(int checkpointID) { 190 int temp=checkpointID; 191 while(temp<-1){ 192 temp = this->virtualToRealCheckPoints_[temp]; 193 } 194 return temp; 195 } 196 197 198 Vector3 RaceCheckPoint::getVirtualNextCheckpointsAsVector3() const 151 199 { 152 200 Vector3 checkpoints = Vector3(-1, -1, -1); -
code/branches/Racingbot/src/modules/gametypes/RaceCheckPoint.h
r9441 r9508 60 60 61 61 void setNextCheckpointsAsVector3(const Vector3& checkpoints); 62 Vector3 getNextCheckpointsAsVector3() const; 63 const std::set<int>& getNextCheckpoints() const 62 Vector3 getNextCheckpointsAsVector3(); 63 Vector3 getVirtualNextCheckpointsAsVector3() const; 64 void setNextVirtualCheckpointsAsVector3(const Vector3& checkpoints); 65 int changeVirtualToRealCheckPoint(int); 66 67 const std::set<int>& getVirtualNextCheckpoints() const 64 68 { 65 69 return this->nextCheckpoints_; 66 70 } 67 71 std::set<int> getNextCheckpoints() 72 { 73 std::set<int> temp; 74 std::set<int> temp2=getVirtualNextCheckpoints(); 75 for (std::set<int>::iterator it = temp2.begin(); it!=temp2.end(); ++it){ 76 temp.insert(changeVirtualToRealCheckPoint((*it))); 77 } 78 return temp; 79 } 68 80 inline void setLast(bool isLast) 69 81 { … … 91 103 92 104 protected: 105 93 106 virtual void fire(bool bIsTriggered, BaseObject* originator); 94 107 … … 99 112 100 113 private: 114 101 115 int checkpointIndex_; ///< The index of this check point. The race starts with the check point with the index 0 102 116 std::set<int> nextCheckpoints_; ///< the indexes of the next check points … … 105 119 std::vector<PlayerInfo*> players_; ///< The player that reached the checkpoint 106 120 Vector3 myPosition_; 121 std::map<int,int> virtualToRealCheckPoints_; // if virtualChepoint was inserted the original can be reconstructed 107 122 }; 108 123 } -
code/branches/Racingbot/src/modules/gametypes/SpaceRaceController.cc
r9507 r9508 54 54 ArtificialController(creator) 55 55 { 56 RegisterObject(SpaceRaceController) 57 ; std::vector<RaceCheckPoint*> checkpoints; 56 RegisterObject(SpaceRaceController); 57 std::vector<RaceCheckPoint*> checkpoints; 58 59 virtualCheckPointIndex=-2; 58 60 for (ObjectList<SpaceRaceManager>::iterator it = ObjectList<SpaceRaceManager>::begin(); it!= ObjectList<SpaceRaceManager>::end(); ++it) 59 61 { … … 64 66 OrxAssert(!checkpoints.empty(), "No Checkpoints in Level"); 65 67 checkpoints_=checkpoints; 68 66 69 for( std::vector<RaceCheckPoint*>::iterator it = checkpoints.begin(); it!=checkpoints.end(); ++it) 67 70 { 68 71 std::set<int> nextCheckPoints = ((*it)->getNextCheckpoints()); 69 72 if(!nextCheckPoints.empty()) { 70 orxout() << "yay" << endl;71 73 for (std::set<int>::iterator numb = nextCheckPoints.begin(); numb!=nextCheckPoints.end(); numb++) { 72 74 RaceCheckPoint* point2 = findCheckpoint((*numb)); … … 80 82 // initialisation of currentRaceCheckpoint_ 81 83 currentRaceCheckpoint_ = NULL; 82 /* 83 // find first Checkpoint 84 for (int i=0; true; i++){ 85 if(checkpoints_[i]->getCheckpointIndex()==0){ 86 nextRaceCheckpoint_=checkpoints_[i]; 87 break; 88 } 89 }*/ 90 91 virtualCheckPointIndex=-2; 84 85 int i; 86 for (i=-2; findCheckpoint(i)!= NULL; i--){ 87 continue; 88 } 89 orxout()<<"Die ANzahl der virtuellen CP betraegt: "<< (-i)-2<<endl; 90 92 91 } 93 92 … … 109 108 std::vector<RaceCheckPoint*> SpaceRaceController::findStaticCheckpoints(std::vector<RaceCheckPoint*> allCheckpoints) 110 109 { 111 std::map<RaceCheckPoint*, int> * zaehler = new std::map< 112 RaceCheckPoint*, int>(); // counts how many times the checkpoit was reached (for simulation) 110 std::map<RaceCheckPoint*, int> * zaehler = new std::map<RaceCheckPoint*, int>(); // counts how many times the checkpoit was reached (for simulation) 113 111 for (unsigned int i = 0; i < allCheckpoints.size(); i++) 114 112 { … … 140 138 if (currentCheckpoint->isLast()) 141 139 {// last point reached 142 orxout() << "last one" << endl; 140 143 141 (*zaehler)[currentCheckpoint] += 1; 144 142 return 1; // 1 Way form the last point to this one … … 147 145 { 148 146 int numberOfWays = 0; // counts number of ways from this Point to the last point 149 for (std::set<int>::iterator it = currentCheckpoint->get NextCheckpoints().begin(); it!= currentCheckpoint->getNextCheckpoints().end(); ++it)147 for (std::set<int>::iterator it = currentCheckpoint->getVirtualNextCheckpoints().begin(); it!= currentCheckpoint->getVirtualNextCheckpoints().end(); ++it) 150 148 { 151 149 if(currentCheckpoint==findCheckpoint(*it)){ … … 153 151 continue; 154 152 } 155 for (std::set<int>::iterator a = currentCheckpoint->getNextCheckpoints().begin(); a!= currentCheckpoint->getNextCheckpoints().end(); ++a){ 156 orxout() << "Nextcheckpoints: "<<(*a) << endl; 157 } 158 orxout() << "currentCheck; " << currentCheckpoint->getCheckpointIndex() << "findCheck; " << findCheckpoint(*it)->getCheckpointIndex() << endl; 159 numberOfWays += rekSimulationCheckpointsReached(findCheckpoint(*it), zaehler); 153 numberOfWays += rekSimulationCheckpointsReached(findCheckpoint(*it), zaehler); 160 154 } 161 155 (*zaehler)[currentCheckpoint] += numberOfWays; … … 185 179 { -1, -1, -1}; 186 180 int temp_i = 0; 187 for (std::set<int>::iterator it =raceCheckpoint->get NextCheckpoints().begin(); it!= raceCheckpoint->getNextCheckpoints().end(); ++it)181 for (std::set<int>::iterator it =raceCheckpoint->getVirtualNextCheckpoints().begin(); it!= raceCheckpoint->getVirtualNextCheckpoints().end(); ++it) 188 182 { 189 183 distances[temp_i] = recCalculateDistance(findCheckpoint(*it), this->getControllableEntity()->getPosition()); … … 194 188 if (distances[2] < distances[1] && distances[2] != -1) 195 189 { 196 return findCheckpoint(*raceCheckpoint->get NextCheckpoints().end()); // return checkpoint with ID of raceCheckpoint->getNextCheckpoints() [2]190 return findCheckpoint(*raceCheckpoint->getVirtualNextCheckpoints().end()); // return checkpoint with ID of raceCheckpoint->getNextCheckpoints() [2] 197 191 } 198 192 else 199 193 { 200 std::set<int>::iterator temp = raceCheckpoint->get NextCheckpoints().begin();194 std::set<int>::iterator temp = raceCheckpoint->getVirtualNextCheckpoints().begin(); 201 195 return findCheckpoint(*(++temp)); // return [1] 202 196 } … … 206 200 if (distances[2] < distances[0] && distances[2] != -1) 207 201 { 208 return findCheckpoint(*raceCheckpoint->get NextCheckpoints().end()); // return [2]202 return findCheckpoint(*raceCheckpoint->getVirtualNextCheckpoints().end()); // return [2] 209 203 } 210 204 else 211 205 { 212 return findCheckpoint(*raceCheckpoint->get NextCheckpoints().begin()); // return [0]206 return findCheckpoint(*raceCheckpoint->getVirtualNextCheckpoints().begin()); // return [0] 213 207 } 214 208 } … … 229 223 { 230 224 int minimum = std::numeric_limits<int>::max(); 231 for (std::set<int>::iterator it = currentCheckPoint->get NextCheckpoints().begin(); it!= currentCheckPoint->getNextCheckpoints().end(); ++it)225 for (std::set<int>::iterator it = currentCheckPoint->getVirtualNextCheckpoints().begin(); it!= currentCheckPoint->getVirtualNextCheckpoints().end(); ++it) 232 226 { 233 227 int dist_currentCheckPoint_currentPosition = static_cast<int> ((currentPosition- currentCheckPoint->getPosition()).length()); … … 250 244 return nextRaceCheckpoint_; 251 245 } 252 if ((currentRaceCheckpoint_->get NextCheckpoints()).size() == 1) // no Adjust possible246 if ((currentRaceCheckpoint_->getVirtualNextCheckpoints()).size() == 1) // no Adjust possible 253 247 254 248 { … … 275 269 newTempRaceCheckPoint = new RaceCheckPoint((*it)); 276 270 } 271 newTempRaceCheckPoint->setVisible(false); 277 272 newTempRaceCheckPoint->setPosition(virtualCheckPointPosition); 278 273 newTempRaceCheckPoint->setCheckpointIndex(virtualCheckPointIndex); 279 274 newTempRaceCheckPoint->setLast(false); 280 newTempRaceCheckPoint->setNext CheckpointsAsVector3(Vector3(indexFollowingCheckPoint,-1,-1));281 282 Vector3 temp = previousCheckpoint->get NextCheckpointsAsVector3();275 newTempRaceCheckPoint->setNextVirtualCheckpointsAsVector3(Vector3(indexFollowingCheckPoint,-1,-1)); 276 277 Vector3 temp = previousCheckpoint->getVirtualNextCheckpointsAsVector3(); 283 278 checkpoints_.insert(checkpoints_.end(), newTempRaceCheckPoint); 284 279 int positionInNextCheckPoint; 285 280 for (int i = 0; i <3; i++) 286 281 { 287 if(previousCheckpoint->get NextCheckpointsAsVector3()[i]==indexFollowingCheckPoint)288 positionInNextCheckPoint=i;282 if(previousCheckpoint->getVirtualNextCheckpointsAsVector3()[i] == indexFollowingCheckPoint) 283 positionInNextCheckPoint=i; 289 284 } 290 285 switch(positionInNextCheckPoint) … … 294 289 case 2: temp.z=virtualCheckPointIndex; break; 295 290 } 296 previousCheckpoint->setNext CheckpointsAsVector3(temp);291 previousCheckpoint->setNextVirtualCheckpointsAsVector3(temp); //Existiert internes Problem bei negativen index fueer next Checkpoint 297 292 virtualCheckPointIndex--; 298 OrxAssert(virtualCheckPointIndex < -1, "TO much virtual cp"); 293 //OrxAssert(virtualCheckPointIndex < -1, "TO much virtual cp"); 294 /*orxout()<<"id: "<< previousCheckpoint->getCheckpointIndex() <<", following:"<<indexFollowingCheckPoint<<" : "<<temp.x<<", "<<temp.y<<", "<<temp.z<<"; "; 295 temp=previousCheckpoint->getNextCheckpointsAsVector3(); 296 orxout()<<"id: "<< previousCheckpoint->getCheckpointIndex() <<": "<<temp.x<<", "<<temp.y<<", "<<temp.z<<"; "; 297 orxout()<<endl;*/ 299 298 return newTempRaceCheckPoint; 300 299 } … … 315 314 if(nextRaceCheckpoint_->getCheckpointIndex() < 0) 316 315 { 317 if( distanceSpaceshipToCheckPoint(nextRaceCheckpoint_) < 30)316 if( distanceSpaceshipToCheckPoint(nextRaceCheckpoint_) < 200) 318 317 { 319 318 currentRaceCheckpoint_=nextRaceCheckpoint_; 320 319 nextRaceCheckpoint_ = nextPointFind(nextRaceCheckpoint_); 321 320 lastPositionSpaceship=this->getControllableEntity()->getPosition(); 321 orxout()<< "CP "<< currentRaceCheckpoint_->getCheckpointIndex()<<" chanched to: "<< nextRaceCheckpoint_->getCheckpointIndex()<<endl; 322 322 } 323 323 } … … 325 325 if (nextRaceCheckpoint_->playerWasHere(this->getControllableEntity()->getPlayer())) 326 326 {//Checkpoint erreicht 327 327 328 currentRaceCheckpoint_=nextRaceCheckpoint_; 328 329 OrxAssert(nextRaceCheckpoint_, "next race checkpoint undefined"); 329 330 nextRaceCheckpoint_ = nextPointFind(nextRaceCheckpoint_); 330 331 lastPositionSpaceship=this->getControllableEntity()->getPosition(); 332 orxout()<< "CP "<< currentRaceCheckpoint_->getCheckpointIndex()<<" chanched to: "<< nextRaceCheckpoint_->getCheckpointIndex()<<endl; 331 333 } 332 334 else if ((lastPositionSpaceship-this->getControllableEntity()->getPosition()).length()/dt > ADJUSTDISTANCE) … … 335 337 lastPositionSpaceship=this->getControllableEntity()->getPosition(); 336 338 } 337 //TODO: korrigieren! 338 339 340 // Abmessung fuer MINDISTANCE gut; 339 341 else if((lastPositionSpaceship-this->getControllableEntity()->getPosition()).length()/dt< MINDISTANCE ) 340 342 {
Note: See TracChangeset
for help on using the changeset viewer.