Changeset 6997
- Timestamp:
- May 27, 2010, 10:47:23 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
r6978 r6997 128 128 if (this->specificMasterAction_ != NONE) 129 129 { 130 if (this->specificMasterAction_ == HOLD)131 130 this->specificMasterActionHold(); 132 131 133 if (this->specificMasterAction_ == TURN180)134 this->turn180();135 136 if (this->specificMasterAction_ == SPIN)137 this->spin();132 // if (this->specificMasterAction_ == TURN180) 133 // this->turn180Init(); 134 135 // if (this->specificMasterAction_ == SPIN) 136 // this->spinInit(); 138 137 139 138 // if (this->specificMasterAction_ == FOLLOWHUMAN) … … 144 143 145 144 // make 180 degree turn - a specific Master Action 146 random = rnd( maxrand);145 random = rnd(1000.0f); 147 146 if (random < 5) 148 this-> specificMasterAction_ = TURN180;147 this->turn180Init(); 149 148 150 149 // spin around - a specific Master Action 151 random = rnd( maxrand);150 random = rnd(1000.0f); 152 151 if (random < 5) 153 this->sp ecificMasterAction_ = SPIN;152 this->spinInit(); 154 153 155 154 // lose master status (only if less than 4 slaves in formation) … … 191 190 // shoot 192 191 random = rnd(maxrand); 193 if (!(this->passive_) && random < 15&& (this->target_ && !this->bShooting_))192 if (!(this->passive_) && random < 9 && (this->target_ && !this->bShooting_)) 194 193 { 195 194 this->bShooting_ = true; … … 214 213 if (this->state_ == MASTER) 215 214 { 215 if (this->specificMasterAction_ == NONE) 216 { 217 if (this->target_) 218 this->aimAtTarget(); 219 220 if (this->bHasTargetPosition_) 221 this->moveToTargetPosition(); 222 223 if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::Math::PI / 20.0f)) 224 this->getControllableEntity()->fire(0); 225 } 226 227 if (this->specificMasterAction_ == TURN180) 228 this->turn180(); 229 230 if (this->specificMasterAction_ == SPIN) 231 this->spin(); 232 } 233 234 if (this->state_ == SLAVE) 235 { 236 237 if (this->bHasTargetPosition_) 238 this->moveToTargetPosition(); 239 240 } 241 242 if (this->state_ == FREE) 243 { 216 244 if (this->target_) 217 245 this->aimAtTarget(); … … 219 247 if (this->bHasTargetPosition_) 220 248 this->moveToTargetPosition(); 221 if (this->specificMasterAction_ == NONE)222 {223 if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::Math::PI / 20.0f))224 this->getControllableEntity()->fire(0);225 }226 }227 228 if (this->state_ == SLAVE)229 {230 231 if (this->bHasTargetPosition_)232 this->moveToTargetPosition();233 234 }235 236 if (this->state_ == FREE)237 {238 if (this->target_)239 this->aimAtTarget();240 241 if (this->bHasTargetPosition_)242 this->moveToTargetPosition();243 249 244 250 if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::Math::PI / 20.0f)) -
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 -
code/branches/ai/src/orxonox/controllers/ArtificialController.h
r6986 r6997 71 71 bool formationFlight_; 72 72 bool passive_; 73 int maxFormationSize_;73 unsigned int maxFormationSize_; 74 74 int freedomCount_; 75 75 enum State {SLAVE, MASTER, FREE}; … … 101 101 102 102 void specificMasterActionHold(); 103 void turn180Init(); 103 104 void turn180(); 105 void spinInit(); 104 106 void spin(); 105 107 void followHuman(Pawn* humanController, bool always);
Note: See TracChangeset
for help on using the changeset viewer.