Changeset 9348 for code/trunk/src/orxonox/controllers
- Timestamp:
- Aug 30, 2012, 11:08:17 PM (12 years ago)
- Location:
- code/trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:ignore
-
old new 1 .project 1 2 build 2 3 codeblocks 4 dependencies 3 5 vs 4 dependencies
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
code/trunk/src/orxonox/controllers/FormationController.cc
- Property svn:eol-style set to native
r9265 r9348 50 50 { 51 51 52 SetConsoleCommand("FormationController", "formationflight", &FormationController::formationflight);53 SetConsoleCommand("FormationController", "masteraction", &FormationController::masteraction);54 SetConsoleCommand("FormationController", "followme", &FormationController::followme);55 SetConsoleCommand("FormationController", "passivebehaviour", &FormationController::passivebehaviour);56 SetConsoleCommand("FormationController", "formationsize", &FormationController::formationsize);57 58 59 60 61 static const unsigned int STANDARD_MAX_FORMATION_SIZE = 9;62 static const int RADIUS_TO_SEARCH_FOR_MASTERS = 5000;63 static const float FORMATION_LENGTH = 110;64 static const float FORMATION_WIDTH = 110;65 static const int FREEDOM_COUNT = 4; //seconds the slaves in a formation will be set free when master attacks an enemy66 static const float SPEED_MASTER = 0.6f;67 static const float ROTATEFACTOR_MASTER = 0.2f;68 static const float SPEED_FREE = 0.8f;69 static const float ROTATEFACTOR_FREE = 0.8f;70 71 FormationController::FormationController(BaseObject* creator) : Controller(creator)72 {52 SetConsoleCommand("FormationController", "formationflight", &FormationController::formationflight); 53 SetConsoleCommand("FormationController", "masteraction", &FormationController::masteraction); 54 SetConsoleCommand("FormationController", "followme", &FormationController::followme); 55 SetConsoleCommand("FormationController", "passivebehaviour", &FormationController::passivebehaviour); 56 SetConsoleCommand("FormationController", "formationsize", &FormationController::formationsize); 57 58 59 60 61 static const unsigned int STANDARD_MAX_FORMATION_SIZE = 9; 62 static const int RADIUS_TO_SEARCH_FOR_MASTERS = 5000; 63 static const float FORMATION_LENGTH = 110; 64 static const float FORMATION_WIDTH = 110; 65 static const int FREEDOM_COUNT = 4; //seconds the slaves in a formation will be set free when master attacks an enemy 66 static const float SPEED_MASTER = 0.6f; 67 static const float ROTATEFACTOR_MASTER = 0.2f; 68 static const float SPEED_FREE = 0.8f; 69 static const float ROTATEFACTOR_FREE = 0.8f; 70 71 FormationController::FormationController(BaseObject* creator) : Controller(creator) 72 { 73 73 RegisterObject(FormationController); 74 74 … … 91 91 this->team_=-1; 92 92 this->target_.setCallback(createFunctor(&FormationController::targetDied, this)); 93 }94 95 FormationController::~FormationController()96 {97 if (this->isInitialized())93 } 94 95 FormationController::~FormationController() 96 { 97 if (this->isInitialized()) 98 98 { 99 99 this->removeFromFormation(); … … 123 123 } 124 124 } 125 }126 127 void FormationController::XMLPort(Element& xmlelement, XMLPort::Mode mode)125 } 126 127 void FormationController::XMLPort(Element& xmlelement, XMLPort::Mode mode) 128 128 { 129 129 SUPER(FormationController, XMLPort, xmlelement, mode); … … 137 137 138 138 139 /**139 /** 140 140 @brief Activates / deactivates formationflight behaviour 141 141 @param form activate formflight if form is true 142 142 */ 143 void FormationController::formationflight(const bool form)143 void FormationController::formationflight(const bool form) 144 144 { 145 145 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it) … … 168 168 } 169 169 170 /**170 /** 171 171 @brief Get all masters to do a "specific master action" 172 172 @param action which action to perform (integer, so it can be called with a console command (tmp solution)) … … 198 198 } 199 199 200 /**200 /** 201 201 @brief Sets shooting behaviour of pawns. 202 202 @param passive if true, bots won't shoot. … … 225 225 } 226 226 227 /**227 /** 228 228 @brief Sets maximal formation size 229 229 @param size maximal formation size. … … 280 280 } 281 281 282 Vector2 coord = get2DView direction(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);282 Vector2 coord = get2DViewcoordinates(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target); 283 283 float distance = (target - this->getControllableEntity()->getPosition()).length(); 284 284 float rotateX = clamp(coord.x * 10, -1.0f, 1.0f); 285 float rotateY = clamp(coord.y * 10, -1.0f, 1.0f); 285 286 286 287 if(this->state_ == FREE) … … 289 290 { 290 291 // Multiply with ROTATEFACTOR_FREE to make them a bit slower 291 this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_FREE * sgn(coord.x) * coord.x*coord.x);292 this->getControllableEntity()->rotatePitch(ROTATEFACTOR_FREE * sgn(coord.y) * coord.y*coord.y);293 } 294 295 if (this->target_ && distance < 200 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength())292 this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_FREE * rotateX); 293 this->getControllableEntity()->rotatePitch(ROTATEFACTOR_FREE * rotateY); 294 } 295 296 if (this->target_ && distance < 200 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength()) 296 297 { 297 298 this->getControllableEntity()->moveFrontBack(-0.05f); // They don't brake with full power to give the player a chance … … 305 306 if (this->target_ || distance > 10) 306 307 { 307 this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_MASTER * sgn(coord.x) * coord.x*coord.x);308 this->getControllableEntity()->rotatePitch(ROTATEFACTOR_MASTER * sgn(coord.y) * coord.y*coord.y);308 this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_MASTER * rotateX); 309 this->getControllableEntity()->rotatePitch(ROTATEFACTOR_MASTER * rotateY); 309 310 } 310 311 … … 320 321 { 321 322 322 this->getControllableEntity()->rotateYaw(-2.0f * ROTATEFACTOR_MASTER * sgn(coord.x) * coord.x*coord.x);323 this->getControllableEntity()->rotatePitch(2.0f * ROTATEFACTOR_MASTER * sgn(coord.y) * coord.y*coord.y);323 this->getControllableEntity()->rotateYaw(-2.0f * ROTATEFACTOR_MASTER * rotateX); 324 this->getControllableEntity()->rotatePitch(2.0f * ROTATEFACTOR_MASTER * rotateY); 324 325 325 326 if (distance < 300) 326 327 { 327 328 329 330 328 if (bHasTargetOrientation_) 329 { 330 copyTargetOrientation(); 331 } 331 332 if (distance < 100) 332 { 333 { //linear speed reduction 333 334 this->getControllableEntity()->moveFrontBack(distance/100.0f*0.4f*SPEED_MASTER); 334 335 } else this->getControllableEntity()->moveFrontBack(1.2f*SPEED_MASTER); 336 337 } else { 335 } 336 else 337 this->getControllableEntity()->moveFrontBack(1.2f*SPEED_MASTER); 338 } 339 else 338 340 this->getControllableEntity()->moveFrontBack(1.2f*SPEED_MASTER + distance/300.0f); 339 }340 341 } 341 342 … … 343 344 { 344 345 this->positionReached(); 345 346 } 347 } 348 349 350 351 void FormationController::moveToTargetPosition()346 bHasTargetOrientation_=false; 347 } 348 } 349 350 351 352 void FormationController::moveToTargetPosition() 352 353 { 353 354 this->moveToPosition(this->targetPosition_); 354 355 } 355 356 356 //copy the Roll orientation of given Quaternion.357 void FormationController::copyOrientation(const Quaternion& orient)357 //copy the Roll orientation of given Quaternion. 358 void FormationController::copyOrientation(const Quaternion& orient) 358 359 { 359 360 //roll angle difference in radian … … 373 374 374 375 375 /**376 /** 376 377 @brief Unregisters a slave from its master. Initiated by a slave. 377 378 */ … … 463 464 } 464 465 } 465 /** 466 467 /** 466 468 @brief Commands the slaves of a master into a formation. Sufficiently fast not to be called within tick. Initiated by a master. 467 469 */ 468 469 void FormationController::commandSlaves() 470 void FormationController::commandSlaves() 470 471 { 471 472 if(this->state_ != MASTER) return; … … 481 482 } 482 483 else 483 484 // formation: 484 485 { 485 486 dest += 1.0f*orient*WorldEntity::BACK; 486 487 Vector3 pos = Vector3::ZERO; 487 488 bool left=true; 488 489 int i = 1; 489 490 … … 683 684 684 685 if (specificMasterActionHoldCount_ == 0) 685 686 { 686 687 this->specificMasterAction_ = NONE; 687 688 this->searchNewTarget(); 688 } 689 else specificMasterActionHoldCount_--; 689 } 690 else 691 specificMasterActionHoldCount_--; 690 692 } 691 693 … … 711 713 void FormationController::turn180() 712 714 { 713 714 715 716 717 718 715 Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, this->targetPosition_); 716 717 this->getControllableEntity()->rotateYaw(-2.0f * sgn(coord.x) * coord.x*coord.x); 718 this->getControllableEntity()->rotatePitch(2.0f * sgn(coord.y) * coord.y*coord.y); 719 720 this->getControllableEntity()->moveFrontBack(SPEED_MASTER); 719 721 } 720 722 … … 734 736 void FormationController::spin() 735 737 { 736 737 738 this->moveToTargetPosition(); 739 this->getControllableEntity()->rotateRoll(0.8f); 738 740 } 739 741 … … 773 775 if((humanPawn != NULL) && (allMasters.size() != 0)) 774 776 { 775 float posHuman = humanPawn->getPosition().length(); 776 float distance = 0.0f; 777 float minDistance = FLT_MAX; 778 int index = 0; 779 int i = 0; 780 781 for(std::vector<FormationController*>::iterator it = allMasters.begin(); it != allMasters.end(); it++, i++) 782 { 783 if (!FormationController::sameTeam((*it)->getControllableEntity(), humanPawn, (*it)->getGametype())) continue; 784 distance = posHuman - (*it)->getControllableEntity()->getPosition().length(); 785 if(distance < minDistance) index = i; 786 } 787 allMasters[index]->followInit(humanPawn); 788 } 789 790 } 791 792 793 794 777 float posHuman = humanPawn->getPosition().length(); 778 float distance = 0.0f; 779 float minDistance = FLT_MAX; 780 int index = 0; 781 int i = 0; 782 783 for(std::vector<FormationController*>::iterator it = allMasters.begin(); it != allMasters.end(); it++, i++) 784 { 785 if (!FormationController::sameTeam((*it)->getControllableEntity(), humanPawn, (*it)->getGametype())) continue; 786 distance = posHuman - (*it)->getControllableEntity()->getPosition().length(); 787 if(distance < minDistance) index = i; 788 } 789 allMasters[index]->followInit(humanPawn); 790 } 791 } 795 792 796 793 /** … … 814 811 } 815 812 816 /**813 /** 817 814 @brief Master begins to follow a randomly chosen human player of the same team. Is a "specific master action". 818 815 */ … … 842 839 843 840 844 /**841 /** 845 842 @brief Master follows target with adjusted speed. Called within tick. 846 843 */ … … 854 851 855 852 856 void FormationController::setTargetPosition(const Vector3& target)853 void FormationController::setTargetPosition(const Vector3& target) 857 854 { 858 855 this->targetPosition_ = target; … … 918 915 } 919 916 920 void FormationController::forgetTarget()917 void FormationController::forgetTarget() 921 918 { 922 919 this->target_ = 0; … … 924 921 } 925 922 926 void FormationController::targetDied()923 void FormationController::targetDied() 927 924 { 928 925 this->forgetTarget(); … … 930 927 } 931 928 932 bool FormationController::sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype)929 bool FormationController::sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype) 933 930 { 934 931 if (entity1 == entity2) … … 1054 1051 return; 1055 1052 1056 Vector2 coord = get2DView direction(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);1053 Vector2 coord = get2DViewcoordinates(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target); 1057 1054 float distance = (target - this->getControllableEntity()->getPosition()).length(); 1058 1055 … … 1060 1057 { 1061 1058 // Multiply with ROTATEFACTOR_FREE to make them a bit slower 1062 this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_FREE * sgn(coord.x) * coord.x*coord.x);1063 this->getControllableEntity()->rotatePitch(ROTATEFACTOR_FREE * sgn(coord.y) * coord.y*coord.y);1059 this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_FREE * clamp(coord.x * 10, -1.0f, 1.0f)); 1060 this->getControllableEntity()->rotatePitch(ROTATEFACTOR_FREE * clamp(coord.y * 10, -1.0f, 1.0f)); 1064 1061 this->getControllableEntity()->moveFrontBack(SPEED_FREE); 1065 1062 } -
code/trunk/src/orxonox/controllers/FormationController.h
- Property svn:eol-style set to native
-
code/trunk/src/orxonox/controllers/NewHumanController.cc
r9016 r9348 298 298 //Used in HumanController for formationFlight 299 299 HumanController::hit(originator,contactpoint,damage); 300 300 301 301 if (this->showDamageOverlay_ && !this->controlPaused_ && this->controllableEntity_ && !this->controllableEntity_->isInMouseLook()) 302 302 { … … 397 397 try 398 398 { 399 wePtr = dynamic_cast<WorldEntity*>(Ogre::any_cast<OrxonoxClass*>(itr->movable->getUserAny()));399 wePtr = orxonox_cast<WorldEntity*>(Ogre::any_cast<OrxonoxClass*>(itr->movable->getUserAny())); 400 400 } 401 401 catch (...)
Note: See TracChangeset
for help on using the changeset viewer.