- Timestamp:
- Nov 24, 2015, 10:37:28 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc
r10850 r10851 46 46 this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&DivisionController::action, this))); 47 47 this->rank_ = Rank::DIVISIONLEADER; 48 49 50 48 } 51 49 … … 60 58 //XMLPortParam(DivisionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f); 61 59 } 62 63 64 60 void DivisionController::tick(float dt) 65 61 { 66 67 62 if (!this->isActive()) 68 63 return; 69 70 71 64 SUPER(DivisionController, tick, dt); 72 73 65 } 74 66 void DivisionController::action() 75 { 76 //----Whatever ship is doing, if there are targets close to it and its own target is far away, fight them---- 77 //analog to attack move 78 if (this->action_ != Action::FIGHT && this->action_ != Action::FIGHTALL) 79 { 80 if ( (this->target_ && CommonController::distance (this->getControllableEntity(), this->target_) > this->attackRange_) 81 || !this->target_ ) 82 { 83 Pawn* newTarget = this->closestTarget(); 84 if ( newTarget && 85 CommonController::distance (this->getControllableEntity(), static_cast<ControllableEntity*>(newTarget)) 86 <= this->attackRange_ ) 87 { 88 // this->backupAction(); 89 // this->setAction (Action::FIGHT, newTarget); 90 Point p = { Action::FIGHT, CommonController::getName(newTarget), Vector3::ZERO }; 91 this->parsedActionpoints_.push_back(p); 92 this->executeActionpoint(); 93 } 94 } 95 } 96 97 //action is NONE whenever ships finishes current action, 98 //if it was fighting before because enemies were close, resume what it was doing 99 //otherwise try to execute next action 67 { 68 if (this->startAttackingEnemiesThatAreClose()) 69 { 70 Point p = { Action::FIGHT, "", Vector3::ZERO }; 71 72 if (this->myWingman_) 73 { 74 this->myWingman_->parsedActionpoints_.push_back(p); 75 } 76 if (this->myFollower_) 77 { 78 this->myFollower_->parsedActionpoints_.push_back(p); 79 } 80 } 81 100 82 if (this->action_ == Action::NONE) 101 83 { 102 84 this->executeActionpoint(); 103 85 } 104 105 106 //this->action_ is what I am actually executing, this->target_ is what I am107 //actually attacking, etc.108 109 //after action is finished, .pop_back() is to be called.110 86 if (this->action_ == Action::FIGHT || this->action_ == Action::FIGHTALL) 111 87 { … … 116 92 if (this->action_ == Action::FIGHT) 117 93 { 118 if (newTarget && CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_) 94 if (newTarget && 95 CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_) 119 96 { 120 97 this->setAction (Action::FIGHT, newTarget); … … 123 100 { 124 101 this->nextActionpoint(); 102 if (this->myWingman_) 103 { 104 this->myWingman_->nextActionpoint(); 105 } 106 if (this->myFollower_) 107 { 108 this->myFollower_->nextActionpoint(); 109 } 125 110 return; 126 111 } … … 135 120 { 136 121 this->nextActionpoint(); 122 if (this->myWingman_) 123 { 124 this->myWingman_->nextActionpoint(); 125 } 126 if (this->myFollower_) 127 { 128 this->myFollower_->nextActionpoint(); 129 } 137 130 return; 138 131 } … … 144 137 //----fly in formation if far enough---- 145 138 Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition(); 146 147 139 148 140 if (diffVector.length() > this->attackRange_) … … 151 143 { 152 144 this->nextActionpoint(); 145 if (this->myWingman_) 146 { 147 this->myWingman_->nextActionpoint(); 148 } 149 if (this->myFollower_) 150 { 151 this->myFollower_->nextActionpoint(); 152 } 153 153 return; 154 154 } … … 158 158 this->setTargetPositionOfFollower(); 159 159 } 160 161 160 } 162 161 else … … 165 164 if (this->myWingman_) 166 165 { 167 this->myWingman_->setAction ( this->action_, this->target_);166 this->myWingman_->setAction (Action::FIGHT, this->target_); 168 167 } 169 168 if (this->myFollower_) 170 169 { 171 this->myFollower_->setAction (this->action_); 172 } 173 174 } 175 176 } 177 if (this->hasTarget()) 178 { 179 //----choose where to go---- 180 this->maneuver(); 181 //----fire if you can---- 182 this->bShooting_ = this->canFire(); 183 } 184 170 this->myFollower_->setAction (Action::FIGHT); 171 } 172 } 173 } 185 174 } 186 175 else if (this->action_ == Action::FLY) 187 176 { 188 189 177 if (this->squaredDistanceToTarget() <= this->squaredaccuracy_) 190 178 { 191 orxout(internal_error) << "arrived";192 179 this->nextActionpoint(); 180 if (this->myWingman_) 181 { 182 this->myWingman_->nextActionpoint(); 183 } 184 if (this->myFollower_) 185 { 186 this->myFollower_->nextActionpoint(); 187 } 193 188 return; 194 189 } … … 201 196 { 202 197 this->nextActionpoint(); 198 if (this->myWingman_) 199 { 200 this->myWingman_->nextActionpoint(); 201 } 202 if (this->myFollower_) 203 { 204 this->myFollower_->nextActionpoint(); 205 } 203 206 return; 204 207 } 205 /* if (this->myWingman_) 206 this->myWingman_->setAction (Action::PROTECT, this->getProtect()); 207 if (this->myFollower_) 208 this->myFollower_->setAction (Action::PROTECT, this->getProtect()); 209 */ 208 210 209 Vector3* targetRelativePosition; 211 210 212 targetRelativePosition = new Vector3 (0, 0, 500);211 targetRelativePosition = new Vector3 (0, 300, 300); 213 212 214 213 Vector3 targetAbsolutePosition = ((this->getProtect()->getWorldPosition()) + … … 225 224 { 226 225 this->nextActionpoint(); 226 if (this->myWingman_) 227 { 228 this->myWingman_->nextActionpoint(); 229 } 230 if (this->myFollower_) 231 { 232 this->myFollower_->nextActionpoint(); 233 } 227 234 return; 228 235 } … … 239 246 if (this->myWingman_) 240 247 { 241 this->myWingman_->setAction ( this->action_, this->target_);248 this->myWingman_->setAction (Action::FIGHT, this->target_); 242 249 } 243 250 if (this->myFollower_) 244 251 { 245 this->myFollower_->setAction (this->action_); 246 } 247 248 } 249 252 this->myFollower_->setAction (Action::FIGHT); 253 } 254 } 255 } 256 if (this->hasTarget()) 257 { 250 258 //----choose where to go---- 251 259 this->maneuver(); … … 253 261 this->bShooting_ = this->canFire(); 254 262 } 255 256 } 257 263 } 258 264 259 260 265 void DivisionController::setTargetPositionOfWingman() 261 266 { … … 321 326 myFollower_->setAction ( Action::FLY, targetAbsolutePositionOfFollower, orient ); 322 327 } 323 324 325 328 bool DivisionController::setWingman(CommonController* cwingman) 326 329 { … … 336 339 return false; 337 340 } 338 339 341 } 340 342 bool DivisionController::setFollower(LeaderController* myFollower) … … 364 366 return false; 365 367 } 366 367 368 369 370 371 368 }
Note: See TracChangeset
for help on using the changeset viewer.