- Timestamp:
- May 17, 2010, 4:45:50 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/ai/src/orxonox/controllers/ArtificialController.cc
r6918 r6919 42 42 { 43 43 44 static const unsigned int MAX_FORMATION_SIZE = 6; 44 static const unsigned int MAX_FORMATION_SIZE = 7; 45 static const int FORMATION_LENGTH = 10; 46 static const int FORMATION_WIDTH = 110; 45 47 static const int FREEDOM_COUNT = 4; //seconds the slaves in a formation will be set free when master attacks an enemy 46 48 static const float SPEED_MASTER = 0.6f; … … 54 56 55 57 this->target_ = 0; 58 this->formationFlight_ = true; 56 59 this->myMaster_ = 0; 57 60 this->freedomCount_ = 0; 58 61 this->team_ = -1; 59 62 this->state_ = FREE; 63 this->specificMasterAction_ = NONE; 64 this->specificMasterActionHoldCount_ = 0; 60 65 this->bShooting_ = false; 61 66 this->bHasTargetPosition_ = false; … … 73 78 SUPER(ArtificialController, XMLPort, xmlelement, mode); 74 79 75 XMLPortParam(ArtificialController, "team", setTeam, getTeam, xmlelement, mode).defaultValues(0); 80 XMLPortParam(ArtificialController, "team", setTeam, getTeam, xmlelement, mode).defaultValues(-1); 81 // XMLPortParam(ArtificialController, "formation", setFormationFlight, getFormationFlight, xmlelement, mode).defaultValues(true); 76 82 } 77 83 … … 134 140 if(this->state_ == SLAVE) 135 141 { 136 // if (this->target_ || distance > 10) 137 // { 138 float rotateFactor; 139 if(this->state_ == SLAVE) rotateFactor = 1.0f; 140 141 142 this->getControllableEntity()->rotateYaw(-1.0f * rotateFactor * sgn(coord.x) * coord.x*coord.x); 143 this->getControllableEntity()->rotatePitch(rotateFactor * sgn(coord.y) * coord.y*coord.y); 144 145 146 147 // } 148 149 if (this->target_ && distance < 500 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength()) 150 { 151 if (this->target_ && distance < 60) 142 143 this->getControllableEntity()->rotateYaw(-2.0f * ROTATEFACTOR_MASTER * sgn(coord.x) * coord.x*coord.x); 144 this->getControllableEntity()->rotatePitch(2.0f * ROTATEFACTOR_MASTER * sgn(coord.y) * coord.y*coord.y); 145 146 147 148 149 150 if (distance < 300) 151 { 152 if (distance < 40) 152 153 { 153 this->getControllableEntity()-> setVelocity(0.8f*this->target_->getVelocity());154 } else this->getControllableEntity()->moveFrontBack( -1.0f*exp(distance/100.0));154 this->getControllableEntity()->moveFrontBack(0.8f*SPEED_MASTER); 155 } else this->getControllableEntity()->moveFrontBack(1.2f*SPEED_MASTER); 155 156 156 157 } else { 157 this->getControllableEntity()->moveFrontBack(1. 0f + distance/500.0f);158 this->getControllableEntity()->moveFrontBack(1.2f*SPEED_MASTER + distance/300.0f); 158 159 } 159 160 } … … 176 177 if( it != myMaster_->slaves_.end() ) 177 178 myMaster_->slaves_.erase(it); 178 // COUT(0) << "~unregister slave" << std::endl;179 // COUT(0) << "~unregister slave" << std::endl; 179 180 } 180 181 } … … 188 189 this->targetPosition_ = this->getControllableEntity()->getPosition(); 189 190 this->forgetTarget(); 190 191 int teamSize = 0; 191 192 //go through all pawns 192 193 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it) … … 197 198 continue; 198 199 199 //has it an ArtificialController and is it a master?200 //has it an ArtificialController? 200 201 if (!it->getController()) 201 202 continue; 202 203 204 //is pawn oneself? 205 if (static_cast<ControllableEntity*>(*it) == this->getControllableEntity()) 206 continue; 207 208 teamSize++; 209 203 210 ArtificialController *newMaster = static_cast<ArtificialController*>(it->getController()); 204 211 212 //is it a master? 205 213 if (!newMaster || newMaster->getState() != MASTER) 206 214 continue; … … 208 216 float distance = (it->getPosition() - this->getControllableEntity()->getPosition()).length(); 209 217 210 // is pawn oneself? &&is pawn in range?211 if ( static_cast<ControllableEntity*>(*it) != this->getControllableEntity() && distance < 5000)218 // is pawn in range? 219 if (distance < 5000) 212 220 { 213 221 if(newMaster->slaves_.size() > MAX_FORMATION_SIZE) continue; … … 227 235 } 228 236 }//for 229 230 237 //hasn't encountered any masters in range? -> become a master 231 if (state_!=SLAVE) state_ = MASTER;//master encounters master? ->done 238 if (state_ != SLAVE && teamSize != 0) state_ = MASTER;//master encounters master? ->done 239 232 240 } 233 241 … … 243 251 this->slaves_.front()->setTargetPosition(dest); 244 252 } 245 246 // 2 slaves: triangle 247 if (this->slaves_.size() == 2) 248 { 249 dest += 10*orient*WorldEntity::BACK; 250 this->slaves_[0]->setTargetPosition(dest + 10*orient*WorldEntity::LEFT); 251 this->slaves_[1]->setTargetPosition(dest + 10*orient*WorldEntity::RIGHT); 252 } 253 254 if (this->slaves_.size() > MAX_FORMATION_SIZE) 255 { 253 else 254 { 255 dest += 1.0f*orient*WorldEntity::BACK; 256 Vector3 pos = Vector3::ZERO; 257 int i = 1; 258 256 259 for(std::vector<ArtificialController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++) 257 260 { 258 (*it)->setTargetPosition(this->getControllableEntity()->getPosition()); 261 pos = Vector3::ZERO; 262 if (i <= 1) pos += dest + FORMATION_WIDTH*WorldEntity::LEFT; 263 if (i == 2) pos += dest + FORMATION_WIDTH*WorldEntity::RIGHT; 264 if (i == 3) pos += dest + FORMATION_WIDTH*WorldEntity::UP; 265 if (i >= 4) 266 { 267 pos += dest + FORMATION_WIDTH*WorldEntity::DOWN; 268 i = 1; 269 dest += FORMATION_LENGTH*orient*WorldEntity::BACK; 270 (*it)->setTargetPosition(pos); 271 continue; 272 } 273 i++; 274 (*it)->setTargetPosition(pos); 259 275 } 260 276 } … … 326 342 } else return false; 327 343 } 344 345 void ArtificialController::specificMasterActionHold() 346 { 347 if (specificMasterActionHoldCount_ == 0) this->specificMasterAction_ = NONE; 348 else specificMasterActionHoldCount_--; 349 } 350 351 void ArtificialController::turn180() 352 { 353 this->specificMasterAction_ = NONE; 354 } 355 356 void ArtificialController::spin() 357 { 358 this->specificMasterAction_ = NONE; 359 } 360 328 361 329 362 void ArtificialController::setTargetPosition(const Vector3& target)
Note: See TracChangeset
for help on using the changeset viewer.