Changeset 10919 for code/branches/cpp11_v2/src/orxonox/controllers
- Timestamp:
- Dec 5, 2015, 10:47:51 PM (9 years ago)
- Location:
- code/branches/cpp11_v2/src/orxonox/controllers
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/cpp11_v2/src/orxonox/controllers/FormationController.cc
r10916 r10919 97 97 this->removeFromFormation(); 98 98 99 for ( ObjectList<FormationController>::iterator it = ObjectList<FormationController>::begin(); it; ++it)100 { 101 if ( *it!= this)99 for (FormationController* controller : ObjectList<FormationController>()) 100 { 101 if (controller != this) 102 102 { 103 if ( it->myMaster_ == this)103 if (controller->myMaster_ == this) 104 104 { 105 orxout(internal_error) << this << " is still master in " << (*it)<< endl;106 it->myMaster_ = nullptr;105 orxout(internal_error) << this << " is still master in " << controller << endl; 106 controller->myMaster_ = nullptr; 107 107 } 108 108 109 109 while (true) 110 110 { 111 std::vector<FormationController*>::iterator it2 = std::find( it->slaves_.begin(), it->slaves_.end(), this);112 if (it2 != it->slaves_.end())111 std::vector<FormationController*>::iterator it2 = std::find(controller->slaves_.begin(), controller->slaves_.end(), this); 112 if (it2 != controller->slaves_.end()) 113 113 { 114 orxout(internal_error) << this << " is still slave in " << (*it)<< endl;115 it->slaves_.erase(it2);114 orxout(internal_error) << this << " is still slave in " << controller << endl; 115 controller->slaves_.erase(it2); 116 116 } 117 117 else … … 140 140 void FormationController::formationflight(const bool form) 141 141 { 142 for ( ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)142 for (Pawn* pawn : ObjectList<Pawn>()) 143 143 { 144 144 Controller* controller = nullptr; 145 145 146 if ( it->getController())147 controller = it->getController();148 else if ( it->getXMLController())149 controller = it->getXMLController();146 if (pawn->getController()) 147 controller = pawn->getController(); 148 else if (pawn->getXMLController()) 149 controller = pawn->getXMLController(); 150 150 151 151 if (!controller) … … 171 171 void FormationController::masteraction(const int action) 172 172 { 173 for ( ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)173 for (Pawn* pawn : ObjectList<Pawn>()) 174 174 { 175 175 Controller* controller = nullptr; 176 176 177 if ( it->getController())178 controller = it->getController();179 else if ( it->getXMLController())180 controller = it->getXMLController();177 if (pawn->getController()) 178 controller = pawn->getController(); 179 else if (pawn->getXMLController()) 180 controller = pawn->getXMLController(); 181 181 182 182 if (!controller) … … 201 201 void FormationController::passivebehaviour(const bool passive) 202 202 { 203 for ( ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)203 for (Pawn* pawn : ObjectList<Pawn>()) 204 204 { 205 205 Controller* controller = nullptr; 206 206 207 if ( it->getController())208 controller = it->getController();209 else if ( it->getXMLController())210 controller = it->getXMLController();207 if (pawn->getController()) 208 controller = pawn->getController(); 209 else if (pawn->getXMLController()) 210 controller = pawn->getXMLController(); 211 211 212 212 if (!controller) … … 228 228 void FormationController::formationsize(const int size) 229 229 { 230 for ( ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)230 for (Pawn* pawn : ObjectList<Pawn>()) 231 231 { 232 232 Controller* controller = nullptr; 233 233 234 if ( it->getController())235 controller = it->getController();236 else if ( it->getXMLController())237 controller = it->getXMLController();234 if (pawn->getController()) 235 controller = pawn->getController(); 236 else if (pawn->getXMLController()) 237 controller = pawn->getXMLController(); 238 238 239 239 if (!controller) … … 398 398 int teamSize = 0; 399 399 //go through all pawns 400 for ( ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)400 for (Pawn* pawn : ObjectList<Pawn>()) 401 401 { 402 402 … … 405 405 if (!gt) 406 406 { 407 gt= it->getGametype();408 } 409 if (!FormationController::sameTeam(this->getControllableEntity(), static_cast<ControllableEntity*>( *it),gt))407 gt=pawn->getGametype(); 408 } 409 if (!FormationController::sameTeam(this->getControllableEntity(), static_cast<ControllableEntity*>(pawn),gt)) 410 410 continue; 411 411 … … 413 413 Controller* controller = nullptr; 414 414 415 if ( it->getController())416 controller = it->getController();417 else if ( it->getXMLController())418 controller = it->getXMLController();415 if (pawn->getController()) 416 controller = pawn->getController(); 417 else if (pawn->getXMLController()) 418 controller = pawn->getXMLController(); 419 419 420 420 if (!controller) … … 422 422 423 423 //is pawn oneself? 424 if (orxonox_cast<ControllableEntity*>( *it) == this->getControllableEntity())424 if (orxonox_cast<ControllableEntity*>(pawn) == this->getControllableEntity()) 425 425 continue; 426 426 … … 433 433 continue; 434 434 435 float distance = ( it->getPosition() - this->getControllableEntity()->getPosition()).length();435 float distance = (pawn->getPosition() - this->getControllableEntity()->getPosition()).length(); 436 436 437 437 // is pawn in range? … … 520 520 newMaster->myMaster_ = nullptr; 521 521 522 for( std::vector<FormationController*>::iterator it = newMaster->slaves_.begin(); it != newMaster->slaves_.end(); it++)523 { 524 (*it)->myMaster_ = newMaster;522 for(FormationController* slave : newMaster->slaves_) 523 { 524 slave->myMaster_ = newMaster; 525 525 } 526 526 } … … 549 549 newMaster->myMaster_ = nullptr; 550 550 551 for( std::vector<FormationController*>::iterator it = newMaster->slaves_.begin(); it != newMaster->slaves_.end(); it++)551 for(FormationController* slave : newMaster->slaves_) 552 552 { 553 (*it)->myMaster_ = newMaster;553 slave->myMaster_ = newMaster; 554 554 } 555 555 } … … 777 777 std::vector<FormationController*> allMasters; 778 778 779 for ( ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)779 for (Pawn* pawn : ObjectList<Pawn>()) 780 780 { 781 781 Controller* controller = nullptr; 782 782 783 if ( it->getController())784 controller = it->getController();785 else if ( it->getXMLController())786 controller = it->getXMLController();783 if (pawn->getController()) 784 controller = pawn->getController(); 785 else if (pawn->getXMLController()) 786 controller = pawn->getXMLController(); 787 787 788 788 if (!controller) … … 791 791 currentHumanController = orxonox_cast<NewHumanController*>(controller); 792 792 793 if(currentHumanController) humanPawn = *it;793 if(currentHumanController) humanPawn = pawn; 794 794 795 795 FormationController *aiController = orxonox_cast<FormationController*>(controller); … … 808 808 int i = 0; 809 809 810 for( std::vector<FormationController*>::iterator it = allMasters.begin(); it != allMasters.end(); it++, i++)811 { 812 if (!FormationController::sameTeam( (*it)->getControllableEntity(), humanPawn, (*it)->getGametype())) continue;813 distance = posHuman - (*it)->getControllableEntity()->getPosition().length();810 for(FormationController* master : allMasters) 811 { 812 if (!FormationController::sameTeam(master->getControllableEntity(), humanPawn, master->getGametype())) continue; 813 distance = posHuman - master->getControllableEntity()->getPosition().length(); 814 814 if(distance < minDistance) index = i; 815 i++; 815 816 } 816 817 allMasters[index]->followInit(humanPawn); … … 847 848 NewHumanController *currentHumanController = nullptr; 848 849 849 for ( ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)850 { 851 if (! it->getController())852 continue; 853 854 currentHumanController = orxonox_cast<NewHumanController*>( it->getController());850 for (Pawn* pawn : ObjectList<Pawn>()) 851 { 852 if (!pawn->getController()) 853 continue; 854 855 currentHumanController = orxonox_cast<NewHumanController*>(pawn->getController()); 855 856 if(currentHumanController) 856 857 { 857 if (!FormationController::sameTeam(this->getControllableEntity(), *it, this->getGametype())) continue;858 humanPawn = *it;858 if (!FormationController::sameTeam(this->getControllableEntity(), pawn, this->getGametype())) continue; 859 humanPawn = pawn; 859 860 break; 860 861 } … … 918 919 this->forgetTarget(); 919 920 920 for ( ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)921 { 922 if (FormationController::sameTeam(this->getControllableEntity(), static_cast<ControllableEntity*>( *it), this->getGametype()))921 for (Pawn* pawn : ObjectList<Pawn>()) 922 { 923 if (FormationController::sameTeam(this->getControllableEntity(), static_cast<ControllableEntity*>(pawn), this->getGametype())) 923 924 continue; 924 925 925 926 /* So AI won't choose invisible Spaceships as target */ 926 if (! it->getRadarVisibility())927 continue; 928 929 if (static_cast<ControllableEntity*>( *it) != this->getControllableEntity())927 if (!pawn->getRadarVisibility()) 928 continue; 929 930 if (static_cast<ControllableEntity*>(pawn) != this->getControllableEntity()) 930 931 { 931 932 float speed = this->getControllableEntity()->getVelocity().length(); 932 933 Vector3 distanceCurrent = this->targetPosition_ - this->getControllableEntity()->getPosition(); 933 Vector3 distanceNew = it->getPosition() - this->getControllableEntity()->getPosition();934 if (!this->target_ || it->getPosition().squaredDistance(this->getControllableEntity()->getPosition()) * (1.5f + acos((this->getControllableEntity()->getOrientation() * WorldEntity::FRONT).dotProduct(distanceNew) / speed / distanceNew.length()) / math::twoPi)934 Vector3 distanceNew = pawn->getPosition() - this->getControllableEntity()->getPosition(); 935 if (!this->target_ || pawn->getPosition().squaredDistance(this->getControllableEntity()->getPosition()) * (1.5f + acos((this->getControllableEntity()->getOrientation() * WorldEntity::FRONT).dotProduct(distanceNew) / speed / distanceNew.length()) / math::twoPi) 935 936 < this->targetPosition_.squaredDistance(this->getControllableEntity()->getPosition()) * (1.5f + acos((this->getControllableEntity()->getOrientation() * WorldEntity::FRONT).dotProduct(distanceCurrent) / speed / distanceCurrent.length()) / math::twoPi) + rnd(-250, 250)) 936 937 { 937 this->setTarget( *it);938 this->setTarget(pawn); 938 939 } 939 940 } -
code/branches/cpp11_v2/src/orxonox/controllers/ScriptController.cc
r10765 r10919 121 121 122 122 /* Debugging: print all the scriptcontroller object pointers */ 123 for(ObjectList<ScriptController>::iterator it = 124 ObjectList<ScriptController>::begin(); 125 it != ObjectList<ScriptController>::end(); ++it) 126 { orxout(verbose) << "Have object in list: " << *it << endl; } 123 for(ScriptController* controller : ObjectList<ScriptController>()) 124 { orxout(verbose) << "Have object in list: " << controller << endl; } 127 125 128 126 /* Find the first one with a nonzero ID */ 129 for(ObjectList<ScriptController>::iterator it = 130 ObjectList<ScriptController>::begin(); 131 it != ObjectList<ScriptController>::end(); ++it) 127 for(ScriptController* controller : ObjectList<ScriptController>()) 132 128 { 133 129 // TODO: do some selection here. Currently just returns the first one 134 if( (*it)->getID() > 0 )135 { orxout(verbose) << "Controller to return: " << *it<< endl;136 return *it;130 if( controller->getID() > 0 ) 131 { orxout(verbose) << "Controller to return: " << controller << endl; 132 return controller; 137 133 } 138 134 -
code/branches/cpp11_v2/src/orxonox/controllers/WaypointPatrolController.cc
r10768 r10919 87 87 float shortestsqdistance = (float)static_cast<unsigned int>(-1); 88 88 89 for ( ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); ++it)89 for (Pawn* pawn : ObjectList<Pawn>()) 90 90 { 91 if (ArtificialController::sameTeam(this->getControllableEntity(), static_cast<ControllableEntity*>( *it), this->getGametype()))91 if (ArtificialController::sameTeam(this->getControllableEntity(), static_cast<ControllableEntity*>(pawn), this->getGametype())) 92 92 continue; 93 93 94 float sqdistance = it->getPosition().squaredDistance(myposition);94 float sqdistance = pawn->getPosition().squaredDistance(myposition); 95 95 if (sqdistance < shortestsqdistance) 96 96 { 97 97 shortestsqdistance = sqdistance; 98 this->target_ = (*it);98 this->target_ = pawn; 99 99 } 100 100 }
Note: See TracChangeset
for help on using the changeset viewer.