- Timestamp:
- Dec 11, 2012, 6:13:18 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.