- Timestamp:
- Nov 24, 2015, 11:54:47 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc
r10843 r10847 76 76 77 77 78 if (this->action_ == Action::FIGHT) 78 /* if (this->target_) 79 { 80 if (CommonController::distance (this->getControllableEntity(), newTarget) < 81 CommonController::distance (this->getControllableEntity(), target_)) 82 { 83 Actionpoint* ap = new Actionpoint(this->getContext()); 84 ap->setPosition (0, 0, 0); 85 ap->setActionXML ("FIGHT"); 86 //ap->setEnemyXML(CommonController::getName(newTarget)); 87 this->addActionpoint (ap); 88 } 89 90 }*/ 91 //----Whatever ship is doing, if there are targets close to it and its own target is far away, fight them---- 92 //analog to attack move 93 if (this->action_ != Action::FIGHT && this->action_ != Action::FIGHTALL) 94 { 95 if ((this->target_ && CommonController::distance (this->getControllableEntity(), this->target_) > this->attackRange_) || 96 !this->target_) 97 { 98 ControllableEntity* newTarget = this->closestTarget(); 99 if (newTarget && CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_) 100 { 101 this->backupAction(); 102 this->setAction (Action::FIGHT, newTarget); 103 } 104 } 105 } 106 //action is NONE whenever ships finishes current action, 107 //if it was fighting before because enemies were close, resume what it was doing 108 //otherwise try to execute next action 109 if (this->action_ == Action::NONE) 110 { 111 if (this->bBackuped_) 112 { 113 this->restoreAction(); 114 } else if (!this->actionpoints_.empty()) 115 { 116 this->popAction(); 117 } 118 } 119 if (this->action_ == Action::FIGHT || this->action_ == Action::FIGHTALL) 79 120 { 80 121 if (!this->hasTarget()) 81 122 { 82 123 //----find a target---- 83 this->setClosestTarget(); 84 } 85 else 124 if (this->action_ == Action::FIGHT) 125 { 126 ControllableEntity* newTarget = this->closestTarget(); 127 if (newTarget && CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_) 128 { 129 this->setAction (Action::FIGHT, newTarget); 130 } 131 else 132 { 133 this->setAction (Action::NONE); 134 } 135 } 136 else if (this->action_ == Action::FIGHTALL) 137 { 138 this->setClosestTarget(); 139 } 140 141 } 142 else if (this->hasTarget()) 86 143 { 87 144 //----fly in formation if far enough---- 88 145 Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition(); 89 if (diffVector.length() > 3000)146 if (diffVector.length() > this->attackRange_) 90 147 { 91 148 this->setTargetPositionOfWingman(); … … 131 188 this->setProtect (static_cast<ControllableEntity*>(*itP)); 132 189 } 190 } 191 if (!this->getProtect()) 192 { 193 this->setAction (Action::NONE); 133 194 } 134 195 }
Note: See TracChangeset
for help on using the changeset viewer.