- Timestamp:
- Dec 7, 2015, 10:24:20 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc
r10953 r10955 78 78 return; 79 79 80 //count ticks, ticks_ is unsigned, so overflow is not a problem 80 81 ++this->ticks_; 81 82 if (this->ticks_ == 1) 82 83 { 84 //those vectors are in reversed order after being set by XML. 83 85 std::reverse(parsedActionpoints_.begin(), parsedActionpoints_.end()); 84 86 std::reverse(actionpoints_.begin(), actionpoints_.end()); 85 if (this->parsedActionpoints_.empty()) 86 { 87 this->action_ = Action::FIGHTALL; 88 } 89 } 90 91 if (!this || !this->getControllableEntity()) 92 return; 87 } 88 89 if (!this || !this->getControllableEntity()) 90 return; 91 //fly 92 if (this->bHasTargetPosition_) 93 { 94 this->moveToTargetPosition(dt); 95 }//or just rotate 96 else if (this->bLookAtTarget_) 97 { 98 this->lookAtTarget(dt); 99 } 93 100 94 if (this->bHasTargetPosition_) 95 { 96 this->moveToTargetPosition(dt); 97 } 98 else if (this->bLookAtTarget_) 99 { 100 this->lookAtTarget(dt); 101 } 102 103 104 if (!this || !this->getControllableEntity()) 105 return; 106 101 102 if (!this || !this->getControllableEntity()) 103 return; 104 //don't fire rocket each tick 107 105 if (timeout_ <= 0) 108 106 { … … 116 114 if (!this || !this->getControllableEntity()) 117 115 return; 118 116 //sometimes dodge, sometimes attack 119 117 if (this->ticks_ % 80 <= 10) 120 118 { … … 128 126 if (!this || !this->getControllableEntity()) 129 127 return; 128 //fire if you can 129 if (this->bShooting_) 130 { 131 this->doFire(); 132 } 133 SUPER(ActionpointController, tick, dt); 134 } 130 135 131 if (this->bShooting_) 132 { 133 this->doFire(); 134 } 135 SUPER(ActionpointController, tick, dt); 136 } 137 138 136 /** 137 @brief 138 action() manages the state machine. 139 */ 139 140 140 141 void ActionpointController::action() … … 143 144 return; 144 145 146 //deltaHp is used to know if this got attacked 145 147 this->deltaHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth() - this->previousHp; 146 148 this->previousHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth(); 149 150 //look out for enemies 147 151 if (this->bDefaultPatrol_ || (this->action_ != Action::FLY && this->action_ != Action::NONE)) 148 152 { … … 155 159 if (this->action_ == Action::NONE || this->bTakenOver_) 156 160 { 161 //if default behaviour is fighting all, push it onto the stack 157 162 if (this->parsedActionpoints_.empty() && this->loopActionpoints_.empty() && this->bDefaultFightAll_) 158 163 { … … 296 301 297 302 } 303 /** 304 @brief 305 if action is protect, this follows protect_ and fights enemies that are close 306 */ 298 307 void ActionpointController::setProtect (ControllableEntity* protect) 299 308 { … … 306 315 return this->protect_; 307 316 } 317 //XML method 308 318 void ActionpointController::addActionpoint(WorldEntity* actionpoint) 309 319 { … … 360 370 this->actionpoints_.push_back(actionpoint); 361 371 } 372 //XML method 362 373 WorldEntity* ActionpointController::getActionpoint(unsigned int index) const 363 374 { … … 367 378 return 0; 368 379 } 369 380 //XML method 370 381 Action::Value ActionpointController::getAction () 371 382 { 372 383 return this->action_; 373 384 } 385 //XML method 374 386 std::string ActionpointController::getActionName() 375 387 { … … 393 405 } 394 406 } 407 //XML method 395 408 void ActionpointController::setAction (Action::Value action) 396 409 { 397 410 this->action_ = action; 398 411 } 412 //set action and target/protect 399 413 void ActionpointController::setAction (Action::Value action, ControllableEntity* target) 400 414 { … … 413 427 } 414 428 } 429 //set action and target position 415 430 void ActionpointController::setAction (Action::Value action, const Vector3& target) 416 431 { … … 423 438 } 424 439 } 440 //set action and target position and orientation 425 441 void ActionpointController::setAction (Action::Value action, const Vector3& target, const Quaternion& orient ) 426 442 { … … 590 606 } 591 607 592 608 //calculate where in world coordinates this ship has to be, so that it keeps distance to protect_, and fly there 593 609 void ActionpointController::stayNearProtect() 594 610 { … … 612 628 this->setTargetOrientation(this->getProtect()->getWorldOrientation()); 613 629 } 630 //remove current point from the stack 614 631 void ActionpointController::nextActionpoint() 615 632 { … … 638 655 this->bHasTargetPosition_ = false; 639 656 } 657 //if looping, instead of erasing point, move it to the top (back is what gets executed, so it's kinda reversed stack) 640 658 void ActionpointController::moveBackToTop() 641 659 { … … 649 667 std::reverse (loopActionpoints_.begin(), loopActionpoints_.end()); 650 668 } 669 //POST: moves all consecutive points that are in loop to the loop stack 651 670 void ActionpointController::fillLoop() 652 671 { … … 667 686 } 668 687 } 669 688 //copy other ship's stacks so that if it dies, this can finish that ship's actions 670 689 void ActionpointController::takeActionpoints (const std::vector<Point>& vector, const std::vector<Point>& loop, bool b) 671 690 { … … 679 698 this->bTakenOver_ = true; 680 699 } 700 //attack closest target 681 701 void ActionpointController::setClosestTarget() 682 702 { 683 703 this->setTarget (static_cast<ControllableEntity*>( closestTarget() ) ); 684 704 } 705 //find closest target 685 706 Pawn* ActionpointController::closestTarget() 686 707 { … … 711 732 return 0; 712 733 } 734 //push action FIGHT to the stack and set target to the closest enemy 713 735 void ActionpointController::startAttackingEnemiesThatAreClose() 714 736 {
Note: See TracChangeset
for help on using the changeset viewer.