Changeset 6958 for code/branches/ai
- Timestamp:
- May 21, 2010, 3:19:42 PM (15 years ago)
- Location:
- code/branches/ai/src/orxonox/controllers
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/ai/src/orxonox/controllers/ArtificialController.cc
r6919 r6958 38 38 #include "controllers/DroneController.h" 39 39 #include "util/Math.h" 40 #include "core/ConsoleCommand.h" 40 41 41 42 namespace orxonox 42 43 { 44 SetConsoleCommand(ArtificialController, formationflight, true);//.defaultValues(0, true); 45 SetConsoleCommand(ArtificialController, masteraction, true); 43 46 44 47 static const unsigned int MAX_FORMATION_SIZE = 7; … … 56 59 57 60 this->target_ = 0; 58 this->formationFlight_ =true;61 this->formationFlight_ = true; 59 62 this->myMaster_ = 0; 60 63 this->freedomCount_ = 0; … … 79 82 80 83 XMLPortParam(ArtificialController, "team", setTeam, getTeam, xmlelement, mode).defaultValues(-1); 81 // XMLPortParam(ArtificialController, "formation", setFormationFlight, getFormationFlight, xmlelement, mode).defaultValues(true); 84 XMLPortParam(ArtificialController, "formation", setFormationFlight, getFormationFlight, xmlelement, mode).defaultValues(true); 85 } 86 87 //activate/deactivate formationflight 88 void ArtificialController::formationflight(bool form) 89 { 90 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it) 91 { 92 if (!it->getController()) 93 continue; 94 95 ArtificialController *aiController = static_cast<ArtificialController*>(it->getController()); 96 97 if(aiController) 98 { 99 aiController->formationFlight_ = form; 100 } 101 } 102 } 103 //get all masters to do this action 104 void ArtificialController::masteraction(int action) 105 { 106 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it) 107 { 108 if (!it->getController()) 109 continue; 110 111 ArtificialController *aiController = static_cast<ArtificialController*>(it->getController()); 112 113 if(aiController || aiController->state_ == MASTER) 114 { 115 aiController->specificMasterAction_ = TURN180; 116 } 117 } 82 118 } 83 119 … … 125 161 if (this->target_ || distance > 10) 126 162 { 163 if (this->specificMasterAction_ == NONE) 164 { 127 165 this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_MASTER * sgn(coord.x) * coord.x*coord.x); 128 166 this->getControllableEntity()->rotatePitch(ROTATEFACTOR_MASTER * sgn(coord.y) * coord.y*coord.y); 167 } else if (this->specificMasterAction_ == TURN180) 168 { 169 this->getControllableEntity()->rotateYaw(-1.0f * sgn(coord.x) * coord.x*coord.x); 170 this->getControllableEntity()->rotatePitch(sgn(coord.y) * coord.y*coord.y); 171 } 129 172 130 173 } … … 143 186 this->getControllableEntity()->rotateYaw(-2.0f * ROTATEFACTOR_MASTER * sgn(coord.x) * coord.x*coord.x); 144 187 this->getControllableEntity()->rotatePitch(2.0f * ROTATEFACTOR_MASTER * sgn(coord.y) * coord.y*coord.y); 145 146 147 148 149 188 150 189 if (distance < 300) … … 177 216 if( it != myMaster_->slaves_.end() ) 178 217 myMaster_->slaves_.erase(it); 179 // COUT(0) << "~unregister slave" << std::endl;180 218 } 181 219 } … … 345 383 void ArtificialController::specificMasterActionHold() 346 384 { 347 if (specificMasterActionHoldCount_ == 0) this->specificMasterAction_ = NONE; 385 if (specificMasterActionHoldCount_ == 0) 386 { 387 this->specificMasterAction_ = NONE; 388 this->searchNewTarget(); 389 COUT(0) << "~action end" << std::endl; 390 } 348 391 else specificMasterActionHoldCount_--; 349 392 } … … 351 394 void ArtificialController::turn180() 352 395 { 353 this->specificMasterAction_ = NONE; 396 COUT(0) << "~turn" << std::endl; 397 398 Quaternion orient = this->getControllableEntity()->getOrientation(); 399 400 this->setTargetPosition(this->getControllableEntity()->getPosition() + 500.0f*orient*WorldEntity::BACK); 401 this->specificMasterActionHoldCount_ = 2; 402 this->specificMasterAction_ = HOLD; 354 403 } 355 404 … … 382 431 void ArtificialController::searchNewTarget() 383 432 { 384 COUT(0) << "search new target - start" << std::endl;385 433 if (!this->getControllableEntity()) 386 434 return; … … 407 455 } 408 456 } 409 COUT(0) << "search new target - end: " << this->target_ << std::endl;410 457 } 411 458 … … 544 591 if (droneController && static_cast<ControllableEntity*>(droneController->getOwner()) == entity1) 545 592 return true; 546 593 547 594 return (team1 == team2 && team1 != -1); 548 595 } -
code/branches/ai/src/orxonox/controllers/ArtificialController.h
r6919 r6958 59 59 virtual void changedControllableEntity(); 60 60 61 static void formationflight(bool form); 62 static void masteraction(int action); 61 63 62 64 protected:
Note: See TracChangeset
for help on using the changeset viewer.