Changeset 10955 for code/branches/campaignHS15
- Timestamp:
- Dec 7, 2015, 10:24:20 PM (9 years ago)
- Location:
- code/branches/campaignHS15/src/orxonox/controllers
- Files:
-
- 9 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 { -
code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.h
r10953 r10955 61 61 In XML one has to attack Actionpoints in order to achieve any complex behaviour, but in Controller all actionpoints are effectively 62 62 being stored in an array of type Point::Value. 63 @note 64 ActionpointController will not work, if there is no MasterController in the level! 63 65 */ 64 66 namespace Action … … 93 95 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 94 96 95 virtual void tick(float dt); 97 /** 98 @brief 99 tick is called every tick by Game (?). 100 In tick ship flies and fires. 101 */ 102 virtual void tick(float dt); 96 103 /** 97 104 @brief … … 175 182 176 183 virtual void stayNearProtect(); 177 virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour. 184 virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour. Only gets called by MasterController 178 185 virtual void takeActionpoints (const std::vector<Point>& vector, const std::vector<Point>& loop, bool b); 179 186 -
code/branches/campaignHS15/src/orxonox/controllers/CommonController.h
r10953 r10955 49 49 CommonController(Context* context); 50 50 virtual ~CommonController(); 51 virtual void action(){}; //<! action() is called in regular intervals managing the bot's behaviour.52 51 static float randomInRange(float a, float b); 53 52 static float distance(const ControllableEntity* entity1, const ControllableEntity* entity2); -
code/branches/campaignHS15/src/orxonox/controllers/DivisionController.h
r10915 r10955 36 36 namespace orxonox 37 37 { 38 /** 39 @note 40 ActionpointController will not work, if there is no MasterController in the level! 41 */ 38 42 class _OrxonoxExport DivisionController : public ActionpointController 39 43 { -
code/branches/campaignHS15/src/orxonox/controllers/FightingController.h
r10953 r10955 39 39 FightingController stores all the fighting methods and member variables of AI. 40 40 Main methods here are maneuver() and dodge(). 41 42 @note 43 ActionpointController will not work, if there is no MasterController in the level! 41 44 */ 42 45 class _OrxonoxExport FightingController : public FlyingController … … 59 62 bool bShooting_; 60 63 bool canFire(); //<! check if target_ is in radius and if this is looking at target_ 61 64 virtual void action(){};//<! action() is called in regular intervals managing the bot's behaviour. Only gets called by MasterController, is implemented in ActionpointController 62 65 protected: 63 66 void setTarget(ControllableEntity* target); //set a target to shoot at -
code/branches/campaignHS15/src/orxonox/controllers/MasterController.cc
r10954 r10955 58 58 if (this->ticks_ == 1) 59 59 { 60 //fill the vector in the first tick 60 61 for (ObjectList<ActionpointController>::iterator it = ObjectList<ActionpointController>::begin(); it; ++it) 61 62 { … … 69 70 else 70 71 { 72 71 73 if (this->controllers_.empty()) 72 74 return; 73 75 76 //iterate over vecotr with the index, keep index in boundaries 74 77 if (this->indexOfCurrentController_ >= this->controllers_.size()) 75 78 { 76 79 this->indexOfCurrentController_ = 0; 77 80 } 81 //each 9 ticks index is incremented 78 82 if (this->numberOfTicksPassedSinceLastActionCall_ >= 9) 79 83 { … … 83 87 if (this->numberOfTicksPassedSinceLastActionCall_ > 0) 84 88 { 89 //call maneuver for current index 85 90 if (this->numberOfTicksPassedSinceLastActionCall_ == 3) 86 91 { … … 95 100 else if (this->numberOfTicksPassedSinceLastActionCall_ == 6) 96 101 { 102 //call canFire for current index 97 103 if (!this->controllers_.at(this->indexOfCurrentController_)) 98 104 { … … 107 113 else 108 114 { 115 //call action for current index 109 116 if (!this->controllers_.at(this->indexOfCurrentController_)) 110 117 { -
code/branches/campaignHS15/src/orxonox/controllers/MasterController.h
r10954 r10955 37 37 namespace orxonox 38 38 { 39 /** 40 @brief 41 calles action(), maneuver() and canFire() methods of all the ActionpointControllers in level. 42 Only one instance of MasterController is to be placed in level. 43 If no MasterController is initialized, none of ActionpointControllers will work. 44 Example: 45 <Pawn position = "100000, 100000, 100000"> 46 <controller> 47 <MasterController> 48 </MasterController> 49 </controller> 50 </Pawn> 51 */ 39 52 class _OrxonoxExport MasterController : public FightingController, public Tickable 40 53 { … … 54 67 55 68 private: 56 std::vector<WeakPtr<FightingController> > controllers_; 57 size_t indexOfCurrentController_; 69 std::vector<WeakPtr<FightingController> > controllers_; //<! vector of controllers, which action(), canFire() and maneuver() methods are to be called 70 size_t indexOfCurrentController_; //<! index of current controller 58 71 unsigned int numberOfTicksPassedSinceLastActionCall_; 59 unsigned int ticks_; //<! local tick counter72 unsigned int ticks_; //<! local tick counter 60 73 61 74 }; -
code/branches/campaignHS15/src/orxonox/controllers/SectionController.h
r10935 r10955 35 35 namespace orxonox 36 36 { 37 /** 38 @note 39 ActionpointController will not work, if there is no MasterController in the level! 40 */ 37 41 class _OrxonoxExport SectionController : public ActionpointController 38 42 { -
code/branches/campaignHS15/src/orxonox/controllers/WingmanController.h
r10935 r10955 36 36 namespace orxonox 37 37 { 38 /** 39 @note 40 ActionpointController will not work, if there is no MasterController in the level! 41 */ 38 42 class _OrxonoxExport WingmanController : public ActionpointController 39 43 {
Note: See TracChangeset
for help on using the changeset viewer.