- Timestamp:
- Oct 29, 2015, 11:53:45 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/AI_HS15/src/orxonox/controllers/LeaderController.cc
r10709 r10717 30 30 31 31 32 33 32 namespace orxonox 34 33 { … … 36 35 RegisterClass(LeaderController); 37 36 38 LeaderController::LeaderController(Context* context) : WingmanController(context) 37 static const int RADIUS_TO_SEARCH_FOR_LEADER = 3000; 38 39 LeaderController::LeaderController(Context* context) : CommonController(context) 39 40 { 40 41 41 42 RegisterObject(LeaderController); 43 bIsDivisionLeader_ = false; 44 42 45 //this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&LeaderController::action, this))); 43 46 } … … 48 51 } 49 52 53 LeaderController* LeaderController::findNewDivisionLeader() 54 { 55 56 if (!this->getControllableEntity()) 57 return NULL; 58 59 60 //go through all pawns 61 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it) 62 { 63 64 //same team? 65 if (!(this->getControllableEntity()->getTeam() != static_cast<ControllableEntity*>(*it)->getTeam())) 66 continue; 67 68 //Does it have a Controller? 69 Controller* controller = 0; 70 71 if (it->getController()) 72 controller = it->getController(); 73 else if (it->getXMLController()) 74 controller = it->getXMLController(); 75 76 if (!controller) 77 continue; 78 79 //is equal to this? 80 if (orxonox_cast<ControllableEntity*>(*it) == this->getControllableEntity()) 81 continue; 82 83 84 LeaderController* newLeader = orxonox_cast<LeaderController*>(controller); 85 86 //nullptr or not DivisionController? 87 if (!newLeader || !newLeader->bIsDivisionLeader_) 88 continue; 89 90 float distance = (it->getPosition() - this->getControllableEntity()->getPosition()).length(); 91 92 // is pawn in range? 93 if (distance < RADIUS_TO_SEARCH_FOR_LEADER) 94 { 95 96 if (newLeader->setFollower(this)) 97 return newLeader; 98 } 99 } 100 return NULL; 101 102 } 50 103 void LeaderController::action() 51 104 { 52 105 //this->target_ = this->sectionTarget_; 106 if (!myDivisionLeader_) 107 { 108 LeaderController* newDivisionLeader = findNewDivisionLeader(); 109 myDivisionLeader_ = newDivisionLeader; 110 orxout(internal_error) << "new DivisionLeader set" << endl; 111 } 53 112 } 54 113 /* … … 94 153 }*/ 95 154 96 orxout(internal_error) << "my Wingman is " << this-> wingman_ << endl;155 orxout(internal_error) << "my Wingman is " << this->myWingman_ << endl; 97 156 98 157 SUPER(LeaderController, tick, dt); 99 158 } 100 voidLeaderController::setWingman(WingmanController* wingman)159 bool LeaderController::setWingman(WingmanController* wingman) 101 160 { 102 this->wingman_ = wingman; 161 if (!this->myWingman_) 162 { 163 this->myWingman_ = wingman; 164 return true; 165 } 166 else 167 { 168 return false; 169 } 170 } 171 bool LeaderController::isLeader() 172 { 173 return true; 103 174 } 104 175 //**********************************************NEW
Note: See TracChangeset
for help on using the changeset viewer.