Changeset 10796
- Timestamp:
- Nov 12, 2015, 9:30:14 AM (9 years ago)
- Location:
- code/branches/AI_HS15/src/orxonox/controllers
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc
r10793 r10796 358 358 } 359 359 } 360 float CommonController::randomInRange(float a, float b) 361 { 362 float random = rnd(1.0f); 363 float diff = b - a; 364 float r = random * diff; 365 return a + r; 366 } 367 void CommonController::attack() 368 { 369 if ( !this->getControllableEntity() ) 370 return; 371 if ( this->target_ ) 372 { 373 this->positionOfTarget_ = getPredictedPosition( 374 this->getControllableEntity()->getWorldPosition(), 375 hardcoded_projectile_speed, 376 this->target_->getWorldPosition(), 377 this->target_->getVelocity() 378 ); 379 Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition(); 380 float diffLength = diffVector.length(); 381 if (diffLength < 100) 382 { 383 Vector3* targetPosition; 384 targetPosition = new Vector3 ( 385 //randomInRange(200, 300), 386 0, 387 //randomInRange(-300, -200), 388 0, 389 randomInRange(-300, -400) 390 ); 391 Quaternion rotationToTarget = (this->getControllableEntity()->getOrientation() * WorldEntity::FRONT).getRotationTo(diffVector); 392 Vector3 target = rotationToTarget * (*targetPosition); 393 moveToPoint( 394 target, 395 randomInRange(45, 180) 396 ); 397 executingMoveToPoint_ = true; 398 return; 399 } 400 this->bShooting_ = true; 401 this->positionOfTarget_ = getPredictedPosition( 402 this->getControllableEntity()->getWorldPosition(), 403 hardcoded_projectile_speed, 404 this->target_->getWorldPosition(), 405 this->target_->getVelocity() 406 ); 407 this->targetPosition_ = positionOfTarget_; 408 409 } 410 else 411 { 412 this->chooseManeuverType(); 413 } 414 } 415 void CommonController::scissors() 416 { 417 if ( !this->getControllableEntity() ) 418 return; 419 if ( this->target_ ) 420 { 421 this->positionOfTarget_ = getPredictedPosition( 422 this->getControllableEntity()->getWorldPosition(), 423 hardcoded_projectile_speed, 424 this->target_->getWorldPosition(), 425 this->target_->getVelocity() 426 ); 427 Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition(); 428 float diffLength = diffVector.length(); 429 Vector3 opponentForwardVector = this->target_->getOrientation() * WorldEntity::FRONT; 430 float opponentDotProduct = diffVector.dotProduct(opponentForwardVector); 431 432 int f = (int) rnd(100.0f); 433 f = (f % 2 == 0 ? 1 : -1); 434 435 if(!this->executingMoveToPoint_) 436 { 437 Vector3* targetPosition; 438 if ( diffLength < 100 ) 439 { 440 targetPosition = new Vector3 ( 441 //f * randomInRange(200, 300), 442 0, 443 //f * randomInRange(-300, -200), 444 0, 445 //randomInRange(-300, -400) 446 0 447 ); 448 } 449 else 450 { 451 if ( opponentDotProduct < 0 ) 452 { 453 targetPosition = new Vector3 ( 454 //f * randomInRange(200, 300), 455 0, 456 //f * randomInRange(-300, -200), 457 0, 458 //randomInRange(-300, -400) 459 -300 460 ); 461 } 462 else 463 { 464 targetPosition = new Vector3 ( 465 //f * randomInRange(200, 300), 466 0, 467 //f * randomInRange(-300, -200), 468 0, 469 //randomInRange(-300, -400) 470 300 471 ); 472 } 473 } 474 Quaternion rotationToTarget = (this->getControllableEntity()->getOrientation() * WorldEntity::FRONT).getRotationTo(diffVector); 475 Vector3 target = rotationToTarget * (*targetPosition); 476 moveToPoint( 477 target, 478 randomInRange(45, 180) 479 ); 480 executingMoveToPoint_ = true; 481 } 482 } 483 484 else 485 { 486 this->chooseManeuverType(); 487 } 488 } 489 void CommonController::gunsD() 490 { 491 if ( !this->getControllableEntity() ) 492 return; 493 if ( this->target_ ) 494 { 495 this->positionOfTarget_ = getPredictedPosition( 496 this->getControllableEntity()->getWorldPosition(), 497 hardcoded_projectile_speed, 498 this->target_->getWorldPosition(), 499 this->target_->getVelocity() 500 ); 501 Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition(); 502 float diffLength = diffVector.length(); 503 if(!this->executingMoveToPoint_) 504 { 505 Vector3* targetPosition; 506 if ( diffLength < 200 ) 507 { 508 targetPosition = new Vector3 ( 509 //f * randomInRange(200, 300), 510 0, 511 //f * randomInRange(-300, -200), 512 0, 513 //randomInRange(-300, -400) 514 0 515 ); 516 } 517 else if ( diffLength < 500 ) 518 { 519 targetPosition = new Vector3 ( 520 //randomInRange(100, 200), 521 0, 522 //randomInRange(-200, -100), 523 0, 524 //randomInRange(-400, -600) 525 500 526 ); 527 } 528 else 529 { 530 targetPosition = new Vector3 ( 531 //randomInRange(200, 300), 532 0, 533 //randomInRange(-300, -200), 534 0, 535 //randomInRange(-400, -600) 536 500 537 ); 538 } 539 Quaternion rotationToTarget = (this->getControllableEntity()->getOrientation() * WorldEntity::FRONT).getRotationTo(diffVector); 540 Vector3 target = rotationToTarget * (*targetPosition); 541 moveToPoint( 542 target, 543 randomInRange(45, 180) 544 ); 545 executingMoveToPoint_ = true; 546 } 547 } 548 else 549 { 550 this->chooseManeuverType(); 551 } 552 } 360 553 //to be called in action 361 554 //PRE: relativeTargetPosition is desired position relative to the spaceship, -
code/branches/AI_HS15/src/orxonox/controllers/CommonController.h
r10793 r10796 79 79 class _OrxonoxExport CommonController : public Controller 80 80 { 81 81 82 public: 83 static const float hardcoded_projectile_speed = 750; 82 84 83 85 static const float ACTION_INTERVAL = 1.0f; … … 147 149 int getFiremode(std::string name); 148 150 149 151 float randomInRange(float a, float b); 150 152 bool bHasTargetPosition_; 151 153 Vector3 targetPosition_; … … 167 169 168 170 void chooseManeuverType(); 169 171 void gunsD(); 172 void attack(); 173 void scissors(); 170 174 FormationMode::Value formationMode_; 171 175 Rank::Value rank_; -
code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc
r10793 r10796 77 77 executingMoveToPoint_ = !this->moveAndRoll(dt); 78 78 } 79 else 80 { 81 if (this->target_) 82 { 83 this->positionOfTarget_ = getPredictedPosition( 84 this->getControllableEntity()->getWorldPosition(), 85 hardcoded_projectile_speed, 86 this->target_->getWorldPosition(), 87 this->target_->getVelocity() 88 ); 89 Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition(); 90 float diffLength = diffVector.length(); 91 /* Quaternion rotationToTarget = (this->getControllableEntity()->getOrientation() * WorldEntity::FRONT).getRotationTo(diffVector); 92 Vector3* targetPosition = new Vector3 ( 0, 0, -200 ); 93 Vector3 target = rotationToTarget * (*targetPosition);*/ 94 if (diffLength > 200) 95 this->setTargetPosition( this->positionOfTarget_ - 0.6f*diffVector); 96 97 else 98 this->setTargetPosition( this->getControllableEntity()->getWorldPosition() ); 99 executingMoveToPoint_ = true; 100 } 101 102 103 if (this->maneuverType_ == ManeuverType::OFFENSIVE) 104 { 105 this->attack(); 106 this->moveAndRoll(dt); 107 } 108 } 79 109 if (this->bShooting_) 80 110 doFire(); … … 104 134 } 105 135 }*/ 106 this->chooseManeuverType();136 //this->chooseManeuverType(); 107 137 switch (this->maneuverType_) 108 138 { … … 113 143 break; 114 144 } 115 case ManeuverType::DEFEN SIVE:145 case ManeuverType::DEFENCIVE: 116 146 { 117 147 this->gunsD(); 148 break; 118 149 } 119 150 case ManeuverType::OFFENSIVE: 120 151 { 121 152 this->attack(); 153 break; 154 } 155 case ManeuverType::NEUTRAL: 156 { 157 this->scissors(); 158 } 159 default: 160 { 161 this->gunsD(); 162 break; 122 163 } 123 164 } 124 165 125 if (!executingMoveToPoint_)166 /*if (!executingMoveToPoint_) 126 167 { 127 168 Vector3* targetPosition = new Vector3 (0, 0, -2000); … … 129 170 executingMoveToPoint_ = true; 130 171 } 131 172 */ 132 173 if (this->myFollower_ && this->target_) 133 174 this->myFollower_->setTarget(this->target_);
Note: See TracChangeset
for help on using the changeset viewer.