- Timestamp:
- Apr 12, 2010, 4:18:12 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/ai/src/orxonox/controllers/ArtificialController.cc
r6683 r6695 44 44 45 45 this->target_ = 0; 46 this->myMaster_ = 0; 47 //this->slaveNumber_ = -1; 46 48 this->team_ = -1;//new 47 49 this->state_ = FREE;//new … … 95 97 } 96 98 99 void ArtificialController::unregisterSlave() { 100 if(myMaster_) 101 { 102 myMaster_->slaves.remove(this); 103 } 104 } 105 97 106 void ArtificialController::searchNewMaster() 98 107 { 108 99 109 if (!this->getControllableEntity()) 100 110 return; … … 106 116 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it) 107 117 { 108 //same team? no: continue 118 119 //same team? 109 120 if (!ArtificialController::sameTeam(this->getControllableEntity(), static_cast<ControllableEntity*>(*it), this->getGametype())) 110 121 continue; 111 122 112 //has it an ArtificialController and is it a master? no: continue 123 //has it an ArtificialController and is it a master? 124 if (!it->getController()) 125 continue; 113 126 114 127 ArtificialController *controller = static_cast<ArtificialController*>(it->getController()); 115 if ( controller &&controller->getState() != MASTER)128 if (!controller || controller->getState() != MASTER) 116 129 continue; 117 130 118 131 //is pawn oneself? && is pawn in range? 119 if (static_cast<ControllableEntity*>(*it) != this->getControllableEntity() /*&& it->getPosition().squaredDistance(this->getControllableEntity()->getPosition()) < 1000 */)132 if (static_cast<ControllableEntity*>(*it) != this->getControllableEntity()) //&& it->getPosition().squaredDistance(this->getControllableEntity()->getPosition()) < 1000 120 133 { 121 //this->target_ = (*it);122 //this->targetPosition_ = it->getPosition();123 134 this->state_ = SLAVE; 124 135 this->myMaster_ = controller; 136 controller->slaves.push_back(this); 137 break; 125 138 } 126 139 }//for 127 140 128 141 //hasn't encountered any masters in range? -> become a master 129 if (state_!=SLAVE) state_=MASTER; // keep in mind: what happens when two masters encounter eache other? -> has to be evaluated in the for loop of within master mode in AIcontroller... 142 if (state_!=SLAVE) state_ = MASTER; // keep in mind: what happens when two masters encounter eache other? -> has to be evaluated in the for loop within master mode in AIcontroller... 143 130 144 } 131 145 132 146 void ArtificialController::commandSlaves() { 133 147 148 for(std::list<ArtificialController*>::iterator it = slaves.begin(); it != slaves.end(); it++) 149 { 150 (*it)->setTargetPosition(this->getControllableEntity()->getPosition()); 151 } 152 /* 134 153 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it) 135 154 { 155 156 if (!it->getController()) 157 continue; 158 136 159 ArtificialController *controller = static_cast<ArtificialController*>(it->getController()); 137 if ( controller && controller->getState() != MASTER)138 continue; 139 160 if (!controller || controller->getState() != SLAVE) 161 continue; 162 //controller->setTargetPosition(this->getControllableEntity()->getPosition()); 140 163 controller->targetPosition_ = this->getControllableEntity()->getPosition(); 141 } 142 164 controller->bHasTargetPosition_ = true; 165 } 166 */ 143 167 } 144 168 145 169 void ArtificialController::freeAllSlaves() 146 170 { 171 147 172 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it) 148 173 { 149 174 ArtificialController *controller = static_cast<ArtificialController*>(it->getController()); 150 if (controller && controller->getState() != MASTER)175 if (controller && controller->getState() != SLAVE) 151 176 continue; 152 177
Note: See TracChangeset
for help on using the changeset viewer.