- Timestamp:
- Nov 25, 2015, 12:07:22 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc
r10851 r10854 51 51 SectionController::~SectionController() 52 52 { 53 53 for (size_t i = 0; i < this->actionpoints_.size(); ++i) 54 { 55 if(this->actionpoints_[i]) 56 this->actionpoints_[i]->destroy(); 57 } 58 this->parsedActionpoints_.clear(); 59 this->actionpoints_.clear(); 54 60 } 55 61 void SectionController::XMLPort(Element& xmlelement, XMLPort::Mode mode) … … 86 92 if (!myDivisionLeader_) 87 93 { 88 if (this->startAttackingEnemiesThatAreClose()) 89 { 90 Point p = { Action::FIGHT, "", Vector3::ZERO }; 91 92 if (this->myWingman_) 94 CommonController::action(); 95 } 96 else if (myDivisionLeader_) 97 { 98 switch (myDivisionLeader_->getAction()) 99 { 100 // case Action::FLY: 101 // { 102 // // Vector3 targetRelativePosition = getFormationPosition(); 103 // // Quaternion orient = 104 // // this->myDivisionLeader_->getControllableEntity()->getWorldOrientation(); 105 // // Vector3 targetAbsolutePosition = 106 // // ((this->myDivisionLeader_->getControllableEntity()->getWorldPosition()) + 107 // // (orient* (targetRelativePosition))); 108 // // this->setAction (Action::FLY, targetAbsolutePosition, orient); 109 // break; 110 // } 111 // case Action::FIGHT: 112 // { 113 114 // // this->setAction (Action::FLY, targetAbsolutePosition, orient); 115 // break; 116 // } 117 default: 93 118 { 94 this->myWingman_->parsedActionpoints_.push_back(p); 119 ControllableEntity* myEntity = this->getControllableEntity(); 120 Vector3 myPosition = myEntity->getWorldPosition(); 121 if (!this->myDivisionLeader_) 122 { 123 return; 124 } 125 ControllableEntity* leaderEntity = this->myDivisionLeader_->getControllableEntity(); 126 Quaternion orient = leaderEntity->getWorldOrientation(); 127 Vector3 leaderPosition = leaderEntity->getWorldPosition(); 128 129 Vector3 targetRelativePosition = getFormationPosition(); 130 if (!this->myDivisionLeader_) 131 { 132 return; 133 } 134 Vector3 targetAbsolutePosition = 135 (leaderPosition + (orient*WorldEntity::FRONT) * (leaderEntity->getVelocity().length()/5) 136 + (orient* (targetRelativePosition))); 137 138 this->setAction (Action::FLY, targetAbsolutePosition, orient); 139 if ((targetAbsolutePosition - myPosition).length() > this->tolerance_ * 1.5f) 140 { 141 this->boostControl(); 142 } 143 else 144 { 145 this->getControllableEntity()->boost(false); 146 } 95 147 } 96 148 } 97 if (this->action_ == Action::NONE) 98 { 99 this->executeActionpoint(); 100 } 101 if (this->action_ == Action::FIGHT || this->action_ == Action::FIGHTALL) 102 { 103 if (!this->hasTarget()) 104 { 105 //----find a target---- 106 ControllableEntity* newTarget = this->closestTarget(); 107 if (this->action_ == Action::FIGHT) 108 { 109 if (newTarget && 110 CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_) 111 { 112 this->setAction (Action::FIGHT, newTarget); 113 } 114 else 115 { 116 this->nextActionpoint(); 117 if (this->myWingman_) 118 { 119 this->myWingman_->nextActionpoint(); 120 } 121 122 return; 123 } 124 } 125 else if (this->action_ == Action::FIGHTALL) 126 { 127 if (newTarget && newTarget->getController()) 128 { 129 this->setAction (Action::FIGHTALL, newTarget); 130 } 131 else 132 { 133 this->nextActionpoint(); 134 if (this->myWingman_) 135 { 136 this->myWingman_->nextActionpoint(); 137 } 138 return; 139 } 140 } 141 142 } 143 else if (this->hasTarget()) 144 { 145 //----fly in formation if far enough---- 146 Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition(); 147 148 if (diffVector.length() > this->attackRange_) 149 { 150 if (this->action_ == Action::FIGHT) 151 { 152 this->nextActionpoint(); 153 if (this->myWingman_) 154 { 155 this->myWingman_->nextActionpoint(); 156 } 157 return; 158 } 159 else 160 { 161 this->setTargetPositionOfWingman(); 162 } 163 } 164 else 165 { 166 //----wingmans shall support the fire of their leaders---- 167 if (this->myWingman_) 168 { 169 this->myWingman_->setAction (Action::FIGHT, this->target_); 170 } 171 172 } 173 } 174 } 175 else if (this->action_ == Action::FLY) 176 { 177 if (this->squaredDistanceToTarget() <= this->squaredaccuracy_) 178 { 179 this->nextActionpoint(); 180 if (this->myWingman_) 181 { 182 this->myWingman_->nextActionpoint(); 183 } 184 return; 185 } 186 this->setTargetPositionOfWingman(); 187 } 188 else if (this->action_ == Action::PROTECT) 189 { 190 if (!this->getProtect()) 191 { 192 this->nextActionpoint(); 193 if (this->myWingman_) 194 { 195 this->myWingman_->nextActionpoint(); 196 } 197 return; 198 } 199 200 Vector3* targetRelativePosition; 201 202 targetRelativePosition = new Vector3 (0, 300, 300); 149 } 203 150 204 Vector3 targetAbsolutePosition = ((this->getProtect()->getWorldPosition()) + 205 (this->getProtect()->getWorldOrientation()* (*targetRelativePosition))); 206 this->setTargetPosition(targetAbsolutePosition); 207 208 this->setTargetPositionOfWingman(); 209 210 } 211 else if (this->action_ == Action::ATTACK) 212 { 213 if (!this->hasTarget()) 214 { 215 this->nextActionpoint(); 216 if (this->myWingman_) 217 { 218 this->myWingman_->nextActionpoint(); 219 } 220 return; 221 } 222 //----fly in formation if far enough---- 223 Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition(); 224 if (diffVector.length() > this->attackRange_) 225 { 226 this->setTargetPositionOfWingman(); 227 } 228 else 229 { 230 //----wingmans shall support the fire of their leaders---- 231 if (this->myWingman_) 232 { 233 this->myWingman_->setAction (Action::FIGHT, this->target_); 234 } 235 236 } 237 } 238 if (this->hasTarget()) 239 { 240 //----choose where to go---- 241 this->maneuver(); 242 //----fire if you can---- 243 this->bShooting_ = this->canFire(); 244 } 245 } 246 //----If have leader---- 247 else 248 { 249 //----action was set to fight---- 250 if (this->action_ == Action::FIGHT) 251 { 252 if (!this->hasTarget()) 253 { 254 this->chooseTarget(); 255 } 256 else 257 { 258 //----fly in formation if far enough---- 259 Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition(); 260 if (diffVector.length() > this->attackRange_) 261 { 262 this->setTargetPositionOfWingman(); 263 } 264 else 265 { 266 //----wingmans shall support the fire of their leaders---- 267 if (this->myWingman_) 268 { 269 this->myWingman_->setAction (Action::FIGHT, this->target_); 270 } 271 } 272 } 273 if (this->hasTarget()) 274 { 275 //----choose where to go---- 276 this->maneuver(); 277 //----fire if you can---- 278 this->bShooting_ = this->canFire(); 279 } 280 } 281 282 //----action was set to fly---- 283 else if (this->action_ == Action::FLY) 284 { 285 this->setTargetPositionOfWingman(); 286 Pawn* newTarget = this->closestTarget(); 287 if ( newTarget && this->distance (this->getControllableEntity(), 288 static_cast<ControllableEntity*>(newTarget)) <= this->attackRange_ ) 289 { 290 this->setAction (Action::FIGHT, static_cast<ControllableEntity*>(newTarget)); 291 } 292 } 293 } 294 if (this->bFirstAction_ && this->myDivisionLeader_) 295 { 296 this->parsedActionpoints_ = this->myDivisionLeader_->parsedActionpoints_; 297 this->bFirstAction_ = false; 151 } 152 153 void SectionController::boostControl() 154 { 155 SpaceShip* ship = orxonox_cast<SpaceShip*>(this->getControllableEntity()); 156 if(ship == NULL) return; 157 if(ship->getBoostPower()*1.5f > ship->getInitialBoostPower() ) //upper limit ->boost 158 { 159 160 this->getControllableEntity()->boost(true); 161 } 162 else if(ship->getBoostPower()*4.0f < ship->getInitialBoostPower()) //lower limit ->do not boost 163 { 164 this->getControllableEntity()->boost(false); 298 165 } 299 166 } … … 303 170 { 304 171 //----If division leader fights, cover him by fighting emenies close to his target---- 305 if (this->myDivisionLeader_->getAction() == Action::FIGHT) 172 Action::Value action = this->myDivisionLeader_->getAction(); 173 174 Pawn* target; 175 if (action == Action::FIGHT || action == Action::FIGHTALL || action == Action::ATTACK) 306 176 { 307 177 //----if he has a target---- … … 327 197 { 328 198 foundTarget = true; 329 t his->setAction(Action::FIGHT, (*itP));199 target = (*itP); 330 200 //orxout(internal_error) << "Found target" << endl; 331 201 break; … … 335 205 if (!foundTarget) 336 206 { 337 t his->setAction(Action::FIGHT,this->myDivisionLeader_->getTarget());207 target = orxonox_cast<Pawn*>(this->myDivisionLeader_->getTarget()); 338 208 } 339 209 } … … 341 211 else 342 212 { 343 t his->setAction(Action::FIGHT,this->myDivisionLeader_->getTarget());213 target = orxonox_cast<Pawn*>(this->myDivisionLeader_->getTarget()); 344 214 } 345 215 } … … 349 219 350 220 } 221 this->setAction (Action::FIGHT, orxonox_cast<ControllableEntity*>(target)); 222 } 223 else 224 { 351 225 } 226 } 227 Vector3 SectionController::getFormationPosition () 228 { 229 this->setFormationMode( this->myDivisionLeader_->getFormationMode() ); 230 Vector3* targetRelativePosition; 231 switch (this->formationMode_){ 232 case FormationMode::WALL: 233 { 234 targetRelativePosition = new Vector3 (-400, 0, 0); 235 break; 236 } 237 case FormationMode::FINGER4: 238 { 239 targetRelativePosition = new Vector3 (-400, 0, 200); 240 break; 241 } 242 243 case FormationMode::DIAMOND: 244 { 245 targetRelativePosition = new Vector3 (-400, 0, 200); 246 break; 247 } 248 } 249 return *targetRelativePosition; 352 250 } 353 251
Note: See TracChangeset
for help on using the changeset viewer.