- Timestamp:
- Nov 30, 2011, 4:09:25 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/formation/src/orxonox/controllers/Masterable.cc
r8948 r8953 57 57 58 58 59 static const unsigned int STANDARD_MAX_FORMATION_SIZE = 7;60 static const int RADIUS_TO_SEARCH_FOR_MASTERS = 20000;59 static const unsigned int STANDARD_MAX_FORMATION_SIZE = 9; 60 static const int RADIUS_TO_SEARCH_FOR_MASTERS = 5000; 61 61 static const int FORMATION_LENGTH = 110; 62 62 static const int FORMATION_WIDTH = 110; … … 79 79 80 80 this->state_ = FREE; 81 this->mode_ = NORMAL; 81 82 this->specificMasterAction_ = NONE; 82 83 this->specificMasterActionHoldCount_ = 0; … … 444 445 this->state_ = MASTER; 445 446 this->myMaster_ = 0; 446 orxout(debug_output) << "search new master: no master found, but teammates"<< endl; 447 } 447 orxout(debug_output) << "search new master: no master found, but "<<teamSize<<" teammates"<< endl; 448 } else if (this->state_ != SLAVE) 449 orxout(debug_output) << "search new master: no master found, no teammates..."<< endl; 448 450 } 449 451 /** … … 589 591 if (this->state_==FREE) 590 592 { 591 /*592 float minDistance=(float)RADIUS_TO_SEARCH_FOR_MASTERS;593 Masterable* bestMaster=NULL;594 595 //search nearest Master, store in bestMaster596 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)597 {598 599 //same team? (doesnt work with a HumanPlayer??!?) TODO600 if (!Masterable::sameTeam(this->getControllableEntity(), static_cast<ControllableEntity*>(*it), this->getGametype()))601 continue;602 603 //get Controller604 Controller* controller = 0;605 606 if (it->getController())607 controller = it->getController();608 else if (it->getXMLController())609 controller = it->getXMLController();610 611 if (!controller)612 continue;613 614 //myself?615 if (orxonox_cast<ControllableEntity*>(*it) == this->getControllableEntity())616 continue;617 618 Masterable *newMaster = orxonox_cast<Masterable*>(controller);619 if (!newMaster || newMaster->state_!=MASTER) continue;620 621 float distance= (it->getPosition() - this->getControllableEntity()->getPosition()).length();622 623 if (distance<minDistance)624 {625 minDistance=distance;626 bestMaster=newMaster;627 }628 }629 630 if (bestMaster!=NULL)631 {632 //becom slave of formation633 bestMaster->slaves_.push_back(this);634 this->state_=SLAVE;635 this->myMaster_=bestMaster;636 }637 else638 {639 //no formation found to lead, become master of empty formation640 this->state_=MASTER;641 this->slaves_.clear();642 this->myMaster_=0;643 orxout(debug_output) << this << "no formation found!, empty formation"<< endl;644 return;645 }646 */647 593 searchNewMaster(); 648 594 } … … 681 627 682 628 /** 629 @brief Sets the new mode. If master, set it for all slaves. 630 */ 631 void Masterable::setMode(Mode val) 632 { 633 this->mode_=val; 634 if (this->state_==MASTER) 635 { 636 for(std::vector<Masterable*>::iterator it = slaves_.begin(); it != slaves_.end(); it++) 637 { 638 (*it)->mode_=val; 639 if (val==ATTACK) 640 (*it)->forgetTarget(); 641 } 642 } 643 } 644 645 /** 683 646 @brief Used to continue a "specific master action" for a certain time and resuming normal behaviour after. 684 647 */ … … 935 898 } 936 899 937 938 939 940 941 void Masterable::setMode(Mode mode)942 {943 for (std::vector<Masterable*>::iterator it=slaves_.begin(); it != slaves_.end(); it++)944 {945 //(*it)->myMode_=mode;946 }947 }948 949 Masterable::Mode Masterable::getMode()950 {951 return Masterable::NORMAL;952 }953 954 955 900 bool Masterable::sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype) 956 901 { … … 992 937 if (entity2->getPlayer()) 993 938 team2 = tdm->getTeam(entity2->getPlayer()); 939 return (team1 == team2 && team1 != -1); //temp solution 994 940 } 995 941
Note: See TracChangeset
for help on using the changeset viewer.