Changeset 6978
- Timestamp:
- May 27, 2010, 6:39:59 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
r6919 r6978 23 23 * Fabian 'x3n' Landau 24 24 * Co-authors: 25 * ...25 * Dominik Solenicki 26 26 * 27 27 */ … … 61 61 if (this->formationFlight_) 62 62 { 63 // return to Master after being forced free63 // return to Master after being forced free 64 64 if (this->freedomCount_ == 1) 65 65 { … … 103 103 this->searchRandomTargetPosition(); 104 104 105 /* 106 random = rnd(maxrand); 107 if ( random < 75 && (this->target_ && !this->bShooting_))105 // shoot 106 random = rnd(maxrand); 107 if (!(this->passive_) && random < 75 && (this->target_ && !this->bShooting_)) 108 108 this->bShooting_ = true; 109 109 … … 111 111 random = rnd(maxrand); 112 112 if (random < 25 && (this->bShooting_)) 113 this->bShooting_ = false; */113 this->bShooting_ = false; 114 114 115 115 } … … 120 120 } 121 121 122 if (this->state_ == MASTER) //MASTER122 if (this->state_ == MASTER) 123 123 { 124 124 … … 136 136 if (this->specificMasterAction_ == SPIN) 137 137 this->spin(); 138 139 // if (this->specificMasterAction_ == FOLLOWHUMAN) 140 // this->followHuman(this->HumanToFollow_, false); 138 141 } 139 142 … … 188 191 // shoot 189 192 random = rnd(maxrand); 190 if ( random <5 && (this->target_ && !this->bShooting_))193 if (!(this->passive_) && random < 15 && (this->target_ && !this->bShooting_)) 191 194 { 192 195 this->bShooting_ = true; -
code/branches/ai/src/orxonox/controllers/ArtificialController.cc
r6958 r6978 23 23 * Fabian 'x3n' Landau 24 24 * Co-authors: 25 * ...25 * Dominik Solenicki 26 26 * 27 27 */ … … 29 29 #include "ArtificialController.h" 30 30 31 #include <vector> 31 32 #include "core/CoreIncludes.h" 32 33 #include "core/XMLPort.h" … … 36 37 #include "gametypes/TeamDeathmatch.h" 37 38 #include "controllers/WaypointPatrolController.h" 39 #include "controllers/NewHumanController.h" 38 40 #include "controllers/DroneController.h" 39 41 #include "util/Math.h" … … 42 44 namespace orxonox 43 45 { 44 SetConsoleCommand(ArtificialController, formationflight, true); //.defaultValues(0, true);46 SetConsoleCommand(ArtificialController, formationflight, true); 45 47 SetConsoleCommand(ArtificialController, masteraction, true); 48 SetConsoleCommand(ArtificialController, followme, true); 49 SetConsoleCommand(ArtificialController, passivbehaviour, true); 46 50 47 51 static const unsigned int MAX_FORMATION_SIZE = 7; … … 53 57 static const float SPEED_FREE = 0.8f; 54 58 static const float ROTATEFACTOR_FREE = 0.8f; 59 static const int SECONDS_TO_FOLLOW_HUMAN = 10; 55 60 56 61 ArtificialController::ArtificialController(BaseObject* creator) : Controller(creator) … … 60 65 this->target_ = 0; 61 66 this->formationFlight_ = true; 67 this->passive_ = false; 62 68 this->myMaster_ = 0; 63 69 this->freedomCount_ = 0; … … 69 75 this->bHasTargetPosition_ = false; 70 76 this->targetPosition_ = Vector3::ZERO; 77 this->humanToFollow_ = NULL; 71 78 72 79 this->target_.setCallback(createFunctor(&ArtificialController::targetDied, this)); … … 85 92 } 86 93 87 //activate/deactivate formationflight 94 // Documentation only here to get a faster overview for creating a useful documentation, what you're reading here not intended for an actual documentation... 95 96 /** 97 @brief Activates / deactivates formationflight behaviour 98 @param form activate formflight if form is true 99 */ 88 100 void ArtificialController::formationflight(bool form) 89 101 { … … 101 113 } 102 114 } 103 //get all masters to do this action 115 116 /** 117 @brief Get all masters to do a specific action 118 @param action which action to perform (integer, so it can be called with a console command (tmp solution)) 119 */ 104 120 void ArtificialController::masteraction(int action) 105 121 { … … 118 134 } 119 135 120 // gets called when Bot dies 136 /** 137 @brief A human player gets followed by its nearest master. Initiated by console command, only for demonstration puproses. Does not work at the moment. 138 */ 139 void ArtificialController::followme() 140 { 141 142 Pawn *humanPawn = NULL; 143 NewHumanController *currentHumanController = NULL; 144 std::vector<ArtificialController*> allMasters; 145 146 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it) 147 { 148 if (!it->getController()) 149 continue; 150 151 currentHumanController = static_cast<NewHumanController*>(it->getController()); 152 153 if(currentHumanController) humanPawn = *it; 154 155 ArtificialController *aiController = static_cast<ArtificialController*>(it->getController()); 156 157 if(aiController || aiController->state_ == MASTER) 158 allMasters.push_back(aiController); 159 160 } 161 /*if((humanPawn != NULL) && (allMasters.size != 0)) 162 { 163 164 float posHuman = humanPawn->getPosition().length(); 165 float distance = 0.0f; 166 float minDistance = posHuman - allMasters.back()->getControllableEntity()->getPosition().length(); 167 int index = 0; 168 int i = 0; 169 170 for(std::vector<ArtificialController*>::iterator it = allMasters.begin(); it != allMasters.end(); it++) 171 { 172 distance = posHuman - (*it)->getControllableEntity()->getPosition().length(); 173 if(distance < minDistance) index = i; 174 } 175 allMasters[index].humanToFollow_ = humanPawn; 176 allMasters[index].followHuman(humanPawn, false); 177 }*/ 178 179 } 180 181 /** 182 @brief Sets shootingbehaviour of pawns. 183 @param passive if true, pawns won't shoot. 184 */ 185 void ArtificialController::passivebehaviour(bool passive) 186 { 187 this->passive_ = passive; 188 } 189 190 /** 191 @brief Gets called if ControllableEntity is changed. Resets the bot when it dies. 192 */ 121 193 void ArtificialController::changedControllableEntity() 122 194 { … … 130 202 } 131 203 } 204 132 205 133 206 void ArtificialController::moveToPosition(const Vector3& target) … … 210 283 } 211 284 285 /** 286 @brief Unregisters a slave from its master. Called by a slave. 287 */ 212 288 void ArtificialController::unregisterSlave() { 213 289 if(myMaster_) … … 272 348 break; 273 349 } 274 }//for 275 //hasn't encountered any masters in range? -> become a master 276 if (state_ != SLAVE && teamSize != 0) state_ = MASTER;//master encounters master? ->done 277 278 } 279 280 void ArtificialController::commandSlaves() { 350 } 351 352 if (state_ != SLAVE && teamSize != 0) state_ = MASTER; 353 354 } 355 356 /** 357 @brief Commands the slaves of a master into a formation. Called by a master. 358 */ 359 void ArtificialController::commandSlaves() 360 { 361 if(this->state_ != MASTER) return; 281 362 282 363 Quaternion orient = this->getControllableEntity()->getOrientation(); … … 315 396 } 316 397 317 // binds slaves to new Master within formation 398 /** 399 @brief Sets a new master within the formation. Called by a master. 400 */ 318 401 void ArtificialController::setNewMasterWithinFormation() 319 402 { 403 if(this->state_ != MASTER) return; 320 404 321 405 if (this->slaves_.empty()) … … 340 424 } 341 425 426 /** 427 @brief Frees all slaves form a master. Called by a master. 428 */ 342 429 void ArtificialController::freeSlaves() 343 430 { 431 if(this->state_ != MASTER) return; 432 344 433 for(std::vector<ArtificialController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++) 345 434 { … … 349 438 } 350 439 440 /** 441 @brief Master sets its slaves free for \var FREEDOM_COUNT seconds. 442 */ 351 443 void ArtificialController::forceFreeSlaves() 352 444 { 445 if(this->state_ != MASTER) return; 446 353 447 for(std::vector<ArtificialController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++) 354 448 { … … 367 461 } 368 462 463 369 464 void ArtificialController::forceFreedom() 370 465 { … … 372 467 } 373 468 469 /** 470 @brief Checks wether caller has been forced free, decrements time to stay forced free. 471 @return true if forced free. 472 */ 374 473 bool ArtificialController::forcedFree() 375 474 { … … 381 480 } 382 481 482 /** 483 @brief Used to continue a "specific master action" for a certain time. 484 */ 383 485 void ArtificialController::specificMasterActionHold() 384 486 { 487 if(this->state_ != MASTER) return; 488 385 489 if (specificMasterActionHoldCount_ == 0) 386 490 { 387 491 this->specificMasterAction_ = NONE; 388 492 this->searchNewTarget(); 389 COUT(0) << "~action end" << std::endl;390 493 } 391 494 else specificMasterActionHoldCount_--; 392 495 } 393 496 497 /** 498 @brief Master engages a 180 degree turn. Is a "specific master action". 499 */ 394 500 void ArtificialController::turn180() 395 501 { 502 if(this->state_ != MASTER) return; 503 396 504 COUT(0) << "~turn" << std::endl; 397 505 … … 403 511 } 404 512 513 /** 514 @brief Master spins around looking directions axis. Is a "specific master action". 515 */ 405 516 void ArtificialController::spin() 406 517 { 518 if(this->state_ != MASTER) return; 519 407 520 this->specificMasterAction_ = NONE; 521 } 522 523 /** 524 @brief Master begins to follow a human player. Is a "specific master action". 525 @param humanController human to follow. 526 @param alaways follows human forever if true - yet only inplemented for false. 527 */ 528 void ArtificialController::followHuman(Pawn* human, bool always) 529 { 530 if (human == NULL) 531 { 532 this->specificMasterAction_ = NONE; 533 return; 534 } 535 if (!always) 536 { 537 this->setTarget(human); 538 this->specificMasterActionHoldCount_ = SECONDS_TO_FOLLOW_HUMAN; 539 this->specificMasterAction_ = HOLD; 540 } 541 408 542 } 409 543 -
code/branches/ai/src/orxonox/controllers/ArtificialController.h
r6958 r6978 36 36 #include "util/Math.h" 37 37 #include "Controller.h" 38 #include "controllers/NewHumanController.h" 38 39 39 40 namespace orxonox … … 61 62 static void formationflight(bool form); 62 63 static void masteraction(int action); 64 static void followme(); 63 65 64 66 protected: … … 71 73 std::vector<ArtificialController*> slaves_; 72 74 ArtificialController *myMaster_; 73 enum SpecificMasterAction {NONE, HOLD, SPIN, TURN180 };75 enum SpecificMasterAction {NONE, HOLD, SPIN, TURN180, FOLLOWHUMAN}; 74 76 SpecificMasterAction specificMasterAction_; 75 77 int specificMasterActionHoldCount_; 78 Pawn* humanToFollow_; 76 79 77 80 void targetDied(); … … 86 89 void commandSlaves(); 87 90 void setNewMasterWithinFormation(); 91 88 92 void freeSlaves(); 89 93 void forceFreeSlaves(); … … 91 95 void forceFreedom(); 92 96 bool forcedFree(); 97 93 98 void specificMasterActionHold(); 94 99 void turn180(); 95 100 void spin(); 101 void followHuman(Pawn* humanController, bool always); 96 102 97 103 void setTargetPosition(const Vector3& target);
Note: See TracChangeset
for help on using the changeset viewer.