Changeset 6795 for code/branches
- Timestamp:
- Apr 26, 2010, 5:02:49 PM (15 years ago)
- Location:
- code/branches/ai/src/orxonox/controllers
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/ai/src/orxonox/controllers/AIController.cc
r6696 r6795 49 49 AIController::~AIController() 50 50 { 51 if (this->state_ == MASTER) freeAllSlaves(); 51 COUT(0) << "~AIController 1" << std::endl; 52 if (this->state_ == MASTER) setNewMasterWithinFormation(); 53 COUT(0) << "~AIController 2" << std::endl; 52 54 if (this->state_ == SLAVE) unregisterSlave(); 53 this->slaves.clear(); 55 COUT(0) << "~AIController 3" << std::endl; 56 this->slaves_.clear(); 57 COUT(0) << "~AIController 4" << std::endl; 54 58 } 55 59 … … 84 88 // lose master status (only if less than 4 slaves in formation) 85 89 random = rnd(maxrand); 86 if(random < 5/(this->slaves .size()+1) && this->slaves.size() < 5 )90 if(random < 5/(this->slaves_.size()+1) && this->slaves_.size() < 5 ) 87 91 this->loseMasterState(); 88 92 89 93 // look out for outher masters if formation is small 90 if(this->slaves .size() < 3)94 if(this->slaves_.size() < 3) 91 95 this->searchNewMaster(); 92 96 -
code/branches/ai/src/orxonox/controllers/ArtificialController.cc
r6696 r6795 51 51 this->bHasTargetPosition_ = false; 52 52 this->targetPosition_ = Vector3::ZERO; 53 //this->slaves_ = new std::list<ArtificialController*>; 53 54 54 55 this->target_.setCallback(createFunctor(&ArtificialController::targetDied, this)); … … 100 101 if(myMaster_) 101 102 { 102 myMaster_->slaves .remove(this);103 myMaster_->slaves_.remove(this); 103 104 } 104 105 } … … 132 133 if (static_cast<ControllableEntity*>(*it) != this->getControllableEntity()) //&& it->getPosition().squaredDistance(this->getControllableEntity()->getPosition()) < 1000 133 134 { 134 if(controller->slaves .size() > 9) continue;135 if(controller->slaves_.size() > 9) continue; 135 136 136 137 this->freeAllSlaves(); 137 this->slaves .clear();138 this->slaves_.clear(); 138 139 this->state_ = SLAVE; 139 140 140 141 this->myMaster_ = controller; 141 controller->slaves .push_back(this);142 controller->slaves_.push_back(this); 142 143 143 144 break; … … 152 153 void ArtificialController::commandSlaves() { 153 154 154 for(std::list<ArtificialController*>::iterator it = slaves .begin(); it != slaves.end(); it++)155 for(std::list<ArtificialController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++) 155 156 { 156 157 (*it)->setTargetPosition(this->getControllableEntity()->getPosition()); … … 173 174 } 174 175 176 // binds slaves to new Master within formation 177 void ArtificialController::setNewMasterWithinFormation() 178 { 179 COUT(0) << "~setNewMasterWithinFormation 1" << std::endl; 180 if (this->slaves_.empty()) 181 return; 182 COUT(0) << "~setNewMasterWithinFormation 1b" << std::endl; 183 184 ArtificialController *newMaster = this->slaves_.back(); 185 COUT(0) << "~setNewMasterWithinFormation 2" << std::endl; 186 this->slaves_.pop_back(); 187 COUT(0) << "~setNewMasterWithinFormation 3" << std::endl; 188 if(!newMaster) return; 189 COUT(0) << "~setNewMasterWithinFormation 4" << std::endl; 190 newMaster->state_ = MASTER; 191 newMaster->slaves_ = this->slaves_; 192 //this->slaves_.clear(); 193 194 this->state_ = SLAVE; 195 this->myMaster_ = newMaster; 196 197 COUT(0) << "~setNewMasterWithinFormation 5" << std::endl; 198 for(std::list<ArtificialController*>::iterator it = newMaster->slaves_.begin(); it != newMaster->slaves_.end(); it++) 199 { 200 COUT(0) << "~setNewMasterWithinFormation 6" << std::endl; 201 (*it)->myMaster_ = newMaster; 202 } 203 COUT(0) << "~setNewMasterWithinFormation 7" << std::endl; 204 205 } 206 175 207 void ArtificialController::freeAllSlaves() 176 208 { 177 209 178 210 179 for(std::list<ArtificialController*>::iterator it = slaves .begin(); it != slaves.end(); it++)211 for(std::list<ArtificialController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++) 180 212 { 181 213 (*it)->state_ = FREE; -
code/branches/ai/src/orxonox/controllers/ArtificialController.h
r6696 r6795 47 47 void abandonTarget(Pawn* target); 48 48 49 inline void setTeam(int team) //new49 inline void setTeam(int team) 50 50 { this->team_ = team; } 51 51 inline int getTeam() const 52 52 { return this->team_; } 53 virtual void changedControllableEntity(); 53 54 54 55 … … 61 62 enum State {SLAVE, MASTER, FREE}; 62 63 int getState(); 63 std::list<ArtificialController*> slaves ;64 std::list<ArtificialController*> slaves_; 64 65 void unregisterSlave(); 65 66 void searchNewMaster(); 66 67 void commandSlaves(); 68 void setNewMasterWithinFormation(); 67 69 void freeAllSlaves(); 68 70 void loseMasterState(); … … 89 91 90 92 91 State state_; //new master: 1 slave: -1 free: 092 int team_; //new93 State state_; 94 int team_; 93 95 94 96 private:
Note: See TracChangeset
for help on using the changeset viewer.