- Timestamp:
- May 27, 2010, 10:47:23 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/ai/src/orxonox/controllers/ArtificialController.cc
r6991 r6997 51 51 52 52 static const unsigned int STANDARD_MAX_FORMATION_SIZE = 7; 53 static const int FORMATION_LENGTH = 1 0;53 static const int FORMATION_LENGTH = 130; 54 54 static const int FORMATION_WIDTH = 110; 55 55 static const int FREEDOM_COUNT = 4; //seconds the slaves in a formation will be set free when master attacks an enemy … … 112 112 { 113 113 aiController->formationFlight_ = form; 114 if(!form) 115 { 116 if(aiController->state_ == MASTER) aiController->freeSlaves(); 117 aiController->state_ = FREE; 118 } 114 119 } 115 120 } … … 120 125 @param action which action to perform (integer, so it can be called with a console command (tmp solution)) 121 126 */ 122 void ArtificialController::masteraction(int action) 127 void ArtificialController::masteraction(int action) 123 128 { 124 129 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it) … … 129 134 ArtificialController *aiController = orxonox_cast<ArtificialController*>(it->getController()); 130 135 131 if(aiController ||aiController->state_ == MASTER)136 if(aiController && aiController->state_ == MASTER) 132 137 { 133 138 if (action == 1) 134 aiController->sp ecificMasterAction_ = TURN180;139 aiController->spinInit(); 135 140 if (action == 2) 136 aiController-> specificMasterAction_ = SPIN;141 aiController->turn180Init(); 137 142 } 138 143 } … … 271 276 if (this->target_ || distance > 10) 272 277 { 273 if (this->specificMasterAction_ == NONE)274 {275 278 this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_MASTER * sgn(coord.x) * coord.x*coord.x); 276 279 this->getControllableEntity()->rotatePitch(ROTATEFACTOR_MASTER * sgn(coord.y) * coord.y*coord.y); 277 } else if (this->specificMasterAction_ == TURN180)278 {279 this->getControllableEntity()->rotateYaw(-1.0f * sgn(coord.x) * coord.x*coord.x);280 this->getControllableEntity()->rotatePitch(sgn(coord.y) * coord.y*coord.y);281 }282 283 280 } 284 281 … … 416 413 { 417 414 pos = Vector3::ZERO; 418 if (i <= 1) pos += dest + FORMATION_WIDTH* WorldEntity::LEFT;419 if (i == 2) pos += dest + FORMATION_WIDTH* WorldEntity::RIGHT;420 if (i == 3) pos += dest + FORMATION_WIDTH* WorldEntity::UP;415 if (i <= 1) pos += dest + FORMATION_WIDTH*(orient*WorldEntity::LEFT); 416 if (i == 2) pos += dest + FORMATION_WIDTH*(orient*WorldEntity::RIGHT); 417 if (i == 3) pos += dest + FORMATION_WIDTH*(orient*WorldEntity::UP); 421 418 if (i >= 4) 422 419 { 423 pos += dest + FORMATION_WIDTH* WorldEntity::DOWN;420 pos += dest + FORMATION_WIDTH*(orient*WorldEntity::DOWN); 424 421 i = 1; 425 dest += FORMATION_LENGTH* orient*WorldEntity::BACK;422 dest += FORMATION_LENGTH*(orient*WorldEntity::BACK); 426 423 (*it)->setTargetPosition(pos); 427 424 continue; … … 518 515 519 516 /** 520 @brief Used to continue a "specific master action" for a certain time .517 @brief Used to continue a "specific master action" for a certain time and resuming normal behaviour after. 521 518 */ 522 519 void ArtificialController::specificMasterActionHold() … … 533 530 534 531 /** 535 @brief Master engages a 180 degree turn. Is a "specific master action". 532 @brief Master initializes a 180 degree turn. Leads to a "specific master action". 533 */ 534 void ArtificialController::turn180Init() 535 { 536 COUT(0) << "~turnInit" << std::endl; 537 if(this->state_ != MASTER) return; 538 539 Quaternion orient = this->getControllableEntity()->getOrientation(); 540 541 this->setTargetPosition(this->getControllableEntity()->getPosition() + 1000.0f*orient*WorldEntity::BACK); 542 543 this->specificMasterActionHoldCount_ = 4; 544 545 this->specificMasterAction_ = TURN180; 546 } 547 548 /** 549 @brief Execute the 180 degree turn. Called within tick. 536 550 */ 537 551 void ArtificialController::turn180() 538 552 { 553 Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, this->targetPosition_); 554 555 this->getControllableEntity()->rotateYaw(-2.0f * sgn(coord.x) * coord.x*coord.x); 556 this->getControllableEntity()->rotatePitch(2.0f * sgn(coord.y) * coord.y*coord.y); 557 558 this->getControllableEntity()->moveFrontBack(SPEED_MASTER); 559 } 560 561 /** 562 @brief Master initializes a spin around its looking direction axis. Leads to a "specific master action". Not yet implemented. 563 */ 564 void ArtificialController::spinInit() 565 { 566 COUT(0) << "~spinInit" << std::endl; 539 567 if(this->state_ != MASTER) return; 540 541 COUT(0) << "~turn" << std::endl; 542 543 Quaternion orient = this->getControllableEntity()->getOrientation(); 544 545 this->setTargetPosition(this->getControllableEntity()->getPosition() + 500.0f*orient*WorldEntity::BACK); 546 this->specificMasterActionHoldCount_ = 2; 547 this->specificMasterAction_ = HOLD; 548 } 549 550 /** 551 @brief Master spins around its looking direction axis. Is a "specific master action". Not yet implemented. 568 this->specificMasterAction_ = SPIN; 569 this->specificMasterActionHoldCount_ = 10; 570 } 571 572 /** 573 @brief Execute the spin. Called within tick. 552 574 */ 553 575 void ArtificialController::spin() 554 576 { 555 if(this->state_ != MASTER) return; 556 557 this->specificMasterAction_ = NONE; 577 this->moveToTargetPosition(); 578 this->getControllableEntity()->rotateRoll(0.8f); 558 579 } 559 580
Note: See TracChangeset
for help on using the changeset viewer.