Changeset 10886
- Timestamp:
- Nov 29, 2015, 12:14:43 PM (9 years ago)
- Location:
- code/branches/campaignHS15
- Files:
-
- 2 deleted
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/campaignHS15/data/levels/AITest.oxw
r10885 r10886 32 32 33 33 <Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0"/> 34 <TeamSpawnPoint team=0 position=" -5000, 3000, -2000" lookat="1,1,-1" spawnclass=SpaceShip pawndesign=spaceshipassff />34 <TeamSpawnPoint team=0 position="3000, -1500, 1000" lookat="1,1,-1" spawnclass=SpaceShip pawndesign=spaceshipassff /> 35 35 36 36 <!-- HERE STARTS DEMO FOR THE "WAYPOINTS" --> … … 62 62 <!-- HERE STARTS DEMO FOR THE ACTIONPOINTS. 63 63 P.S. Never set protectMe in the first actionpoint: if human didn't spawn, that actionpoint will be skipped --> 64 <!--64 65 65 <Model mesh="cube.mesh" scale=8 position="0,0,0" /> 66 66 … … 123 123 </templates> 124 124 </SpaceShip> 125 -->125 126 126 127 127 <!-- HERE ENDS DEMO FOR THE ACTIONPOINTS --> 128 128 <!-- HERE STARTS DEMO FOR FIGHTING --> 129 129 <!-- 130 130 <SpaceShip position="-4000, 1500, -1000" lookat="0,0,0" team=0 name="ss2"> 131 131 <templates> … … 242 242 </controller> 243 243 </SpaceShip> 244 244 --> 245 245 246 246 <!-- HERE ENDS DEMO FOR FIGHTING --> … … 297 297 --> 298 298 <!-- HERE ENDS DEMO FOR FORMATIONS --> 299 <!-- 300 <SpaceShip position="-2000, 3000, -2000" lookat="0,0,0" team=1 name="ss2"> 301 <templates> 302 <Template link=spaceshipassff /> 303 </templates> 304 <controller> 305 <DivisionController team=1 formationMode="finger4"> 306 307 </DivisionController> 308 </controller> 309 </SpaceShip> 310 --> 299 <!-- 1 division is roughly equal to 6 AIControllers--!> 300 <!-- 301 <SpaceShip position="2000, -1500, 1000" lookat="0,0,0" team=1 > 302 <templates> 303 <Template link=spaceshipassff /> 304 </templates> 305 <controller> 306 <DivisionController team=1 formationMode="WALL"> 307 308 </DivisionController> 309 </controller> 310 </SpaceShip> 311 <SpaceShip position="2000, -1900, 1000" lookat="0,0,0" team=1> 312 <templates> 313 <Template link=spaceshipassff /> 314 </templates> 315 <controller> 316 <SectionController team=1> 317 </SectionController> 318 </controller> 319 </SpaceShip> 320 <SpaceShip position="2000, -2100, 1000" lookat="0,0,0" team=1> 321 <templates> 322 <Template link=spaceshipassff /> 323 </templates> 324 <controller> 325 <WingmanController team=1> 326 </WingmanController> 327 </controller> 328 </SpaceShip> 329 <SpaceShip position="2000, -2400, 1000" lookat="0,0,0" team=1> 330 <templates> 331 <Template link=spaceshipassff /> 332 </templates> 333 <controller> 334 <WingmanController team=1> 335 </WingmanController> 336 </controller> 337 </SpaceShip> 338 339 <?lua 340 for i = 0, 5, 1 do 341 ?> 342 <SpaceShip position="<?lua print(7000) ?>,<?lua print(i*500) ?>,<?lua print(0) ?>" team=2> 343 <templates> 344 <Template link=spaceshipassff /> 345 </templates> 346 <controller> 347 <AIController team=2 /> 348 </controller> 349 </SpaceShip> 350 <?lua end ?> --> 351 311 352 312 353 </Scene> -
code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc
r10885 r10886 59 59 XMLPortObject(ActionpointController, WorldEntity, "actionpoints", addActionpoint, getActionpoint, xmlelement, mode); 60 60 } 61 void ActionpointController::tick(float dt) 62 { 61 ActionpointController::~ActionpointController() 62 { 63 loopActionpoints_.clear(); 64 parsedActionpoints_.clear(); 65 actionpoints_.clear(); 66 } 67 void ActionpointController::tick(float dt) 68 { 69 63 70 if (this->timeout_ > 0 && this->bFiredRocket_) 64 71 { … … 68 75 this->bFiredRocket_ = false; 69 76 70 77 if (this->bHasTargetPosition_) 71 78 { 72 79 this->moveToTargetPosition(dt); … … 90 97 } 91 98 if (this->bFirstTick_) 92 { 93 // this->getControllableEntity()->setOrientation(1,0,0,0); 94 // this->getControllableEntity()->rotateRoll(-this->getControllableEntity()->getOrientation().getRoll(true).valueRadians()); 95 // this->getControllableEntity()->rotateYaw(-this->getControllableEntity()->getOrientation().getYaw(true).valueRadians()); 96 // this->getControllableEntity()->rotatePitch(-this->getControllableEntity()->getOrientation().getPitch(true).valueRadians()); 99 { 97 100 this->bFirstTick_ = false; 98 99 } 100 SUPER(ActionpointController, tick, dt); 101 } 102 ActionpointController::~ActionpointController() 103 { 104 loopActionpoints_.clear(); 105 parsedActionpoints_.clear(); 106 actionpoints_.clear(); 101 } 102 103 SUPER(ActionpointController, tick, dt); 104 } 105 void ActionpointController::action() 106 { 107 if (!this || !this->getControllableEntity()) 108 return; 109 if (!this->getControllableEntity() || !orxonox_cast<Pawn*> (this->getControllableEntity())) 110 return; 111 this->deltaHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth() - this->previousHp; 112 this->previousHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth(); 113 if (this->actionCounter_ % 2 == 0) 114 this->startAttackingEnemiesThatAreClose(); 115 //No action -> pop one from stack 116 if (this->action_ == Action::NONE || this->bTakenOver_) 117 { 118 if (this->parsedActionpoints_.empty() && this->loopActionpoints_.empty()) 119 { 120 Point p = { Action::FIGHTALL, "", Vector3::ZERO, false }; 121 this->parsedActionpoints_.push_back (p); 122 } 123 this->executeActionpoint(); 124 this->bTakenOver_ = false; 125 this->action(); 126 } 127 //Action fightall -> fight till nobody alive 128 if (this->action_ == Action::FIGHTALL) 129 { 130 if (!this->hasTarget()) 131 { 132 ControllableEntity* newTarget = this->closestTarget(); 133 if (newTarget) 134 { 135 this->setAction (Action::FIGHTALL, newTarget); 136 this->action(); 137 } 138 else 139 { 140 this->nextActionpoint(); 141 if (!(this->parsedActionpoints_.empty() && this->loopActionpoints_.empty())) 142 { 143 this->action(); 144 } 145 } 146 } 147 } 148 //Action fight -> fight as long as enemies in range 149 else if (this->action_ == Action::FIGHT) 150 { 151 if (!this->hasTarget()) 152 { 153 //----find a target---- 154 ControllableEntity* newTarget = this->closestTarget(); 155 if (newTarget && 156 CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_) 157 { 158 this->setAction (Action::FIGHT, newTarget); 159 this->action(); 160 } 161 else 162 { 163 this->nextActionpoint(); 164 this->action(); 165 } 166 } 167 else if (this->hasTarget()) 168 { 169 //----fly in formation if far enough---- 170 Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition(); 171 172 if (diffVector.length() > this->attackRange_) 173 { 174 ControllableEntity* newTarget = this->closestTarget(); 175 176 if (newTarget && 177 CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_) 178 { 179 this->setAction (Action::FIGHT, newTarget); 180 } 181 else 182 { 183 this->nextActionpoint(); 184 this->action(); 185 } 186 } 187 } 188 } 189 else if (this->action_ == Action::FLY) 190 { 191 if (this->squaredDistanceToTarget() <= this->squaredaccuracy_) 192 { 193 this->nextActionpoint(); 194 this->action(); 195 } 196 } 197 else if (this->action_ == Action::PROTECT) 198 { 199 if (!this->getProtect()) 200 { 201 this->nextActionpoint(); 202 this->action(); 203 } 204 this->stayNearProtect(); 205 } 206 else if (this->action_ == Action::ATTACK) 207 { 208 if (!this->hasTarget()) 209 { 210 this->nextActionpoint(); 211 this->action(); 212 } 213 } 214 if (this->hasTarget()) 215 { 216 //----choose where to go---- 217 this->maneuver(); 218 //----fire if you can---- 219 this->bShooting_ = this->canFire(); 220 } 221 this->actionCounter_ += this->actionCounter_ < 100000 ? 1 : -this->actionCounter_ ; 107 222 } 108 223 void ActionpointController::setProtect (ControllableEntity* protect) … … 273 388 return; 274 389 } 275 this-> action_ = p.action;276 switch ( this->action_)390 this->setAction (p.action); 391 switch (this->action_) 277 392 { 278 393 case Action::FIGHT: … … 280 395 std::string targetName = p.name; 281 396 if (targetName == "") 282 {283 397 break; 284 }285 398 for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP) 286 399 { … … 289 402 this->setTarget (static_cast<ControllableEntity*>(*itP)); 290 403 } 291 } 404 } 292 405 break; 293 406 } … … 361 474 default: 362 475 break; 363 } 364 476 } 365 477 } 366 478 … … 368 480 void ActionpointController::stayNearProtect() 369 481 { 370 Vector3 targetRelativePosition(0, 300, 300); 482 Vector3 targetRelativePosition(0, 300, 300); 483 if (!this->getProtect()) 484 { 485 this->nextActionpoint(); 486 return; 487 } 371 488 Vector3 targetAbsolutePosition = ((this->getProtect()->getWorldPosition()) + 372 489 (this->getProtect()->getWorldOrientation()* (targetRelativePosition))); 373 490 this->setTargetPosition(targetAbsolutePosition); 491 if (!this->getProtect()) 492 { 493 this->nextActionpoint(); 494 return; 495 } 374 496 if (this->actionCounter_ % 3 == 0) 375 497 this->setTargetOrientation(this->getProtect()->getWorldOrientation()); … … 422 544 } 423 545 } 424 void ActionpointController::action() 425 { 426 if (!this || !this->getControllableEntity()) 427 return; 428 // orxout (internal_error) << "Size of actions is " << this->parsedActionpoints_.size() << endl; 429 if (this->actionCounter_ % 2 == 0) 430 this->startAttackingEnemiesThatAreClose(); 431 //No action -> pop one from stack 432 if (this->action_ == Action::NONE || this->bTakenOver_) 433 { 434 if (this->parsedActionpoints_.empty() && this->loopActionpoints_.empty()) 435 { 436 Point p = { Action::FIGHTALL, "", Vector3::ZERO, false }; 437 this->parsedActionpoints_.push_back (p); 438 439 } 440 this->executeActionpoint(); 441 this->bTakenOver_ = false; 442 this->action(); 443 } 444 //Action fightall -> fight till nobody alive 445 if (this->action_ == Action::FIGHTALL) 446 { 447 if (!this->hasTarget()) 448 { 449 //----find a target---- 450 ControllableEntity* newTarget = this->closestTarget(); 451 if (newTarget) 452 { 453 this->setAction (Action::FIGHTALL, newTarget); 454 } 455 else 456 { 457 this->nextActionpoint(); 458 459 if (!(this->parsedActionpoints_.empty() && this->loopActionpoints_.empty())) 460 { 461 this->action(); 462 } 463 464 } 465 } 466 else if (this->hasTarget()) 467 { 468 469 } 470 } 471 //Action fight -> fight as long as enemies in range 472 else if (this->action_ == Action::FIGHT) 473 { 474 if (!this->hasTarget()) 475 { 476 //----find a target---- 477 ControllableEntity* newTarget = this->closestTarget(); 478 if (newTarget && 479 CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_) 480 { 481 this->setAction (Action::FIGHT, newTarget); 482 } 483 else 484 { 485 this->nextActionpoint(); 486 this->action(); 487 } 488 } 489 else if (this->hasTarget()) 490 { 491 //----fly in formation if far enough---- 492 Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition(); 493 494 if (diffVector.length() > this->attackRange_) 495 { 496 ControllableEntity* newTarget = this->closestTarget(); 497 498 if (newTarget && 499 CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_) 500 { 501 this->setAction (Action::FIGHT, newTarget); 502 } 503 else 504 { 505 this->nextActionpoint(); 506 this->action(); 507 } 508 } 509 } 510 } 511 else if (this->action_ == Action::FLY) 512 { 513 if (this->squaredDistanceToTarget() <= this->squaredaccuracy_) 514 { 515 this->nextActionpoint(); 516 this->action(); 517 } 518 } 519 else if (this->action_ == Action::PROTECT) 520 { 521 if (!this->getProtect()) 522 { 523 this->nextActionpoint(); 524 this->action(); 525 } 526 this->stayNearProtect(); 527 } 528 else if (this->action_ == Action::ATTACK) 529 { 530 if (!this->hasTarget()) 531 { 532 this->nextActionpoint(); 533 this->action(); 534 } 535 } 536 if (this->hasTarget()) 537 { 538 //----choose where to go---- 539 this->maneuver(); 540 //----fire if you can---- 541 this->bShooting_ = this->canFire(); 542 } 543 this->actionCounter_ += this->actionCounter_ < 100000 ? 1 : -this->actionCounter_ ; 544 545 } 546 546 547 void ActionpointController::takeActionpoints (const std::vector<Point>& vector, const std::vector<Point>& loop, bool b) 547 548 { … … 550 551 this->bLoop_ = b; 551 552 this->bTakenOver_ = true; 552 // orxout(internal_error) << "Top action is " << this->parsedActionpoints_.back().action << endl;553 553 } 554 554 void ActionpointController::setClosestTarget() -
code/branches/campaignHS15/src/orxonox/controllers/CMakeLists.txt
r10871 r10886 12 12 ControllerDirector.cc 13 13 DivisionController.cc 14 LeaderController.cc15 14 WingmanController.cc 16 15 SectionController.cc -
code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc
r10885 r10886 36 36 37 37 //Leaders share the fact that they have Wingmans 38 DivisionController::DivisionController(Context* context) : LeaderController(context)38 DivisionController::DivisionController(Context* context) : ActionpointController(context) 39 39 { 40 40 RegisterObject(DivisionController); -
code/branches/campaignHS15/src/orxonox/controllers/DivisionController.h
r10885 r10886 30 30 #define _DivisionController_H__ 31 31 32 #include "controllers/ LeaderController.h"32 #include "controllers/ActionpointController.h" 33 33 34 34 … … 36 36 namespace orxonox 37 37 { 38 class _OrxonoxExport DivisionController : public LeaderController38 class _OrxonoxExport DivisionController : public ActionpointController 39 39 { 40 40 public: -
code/branches/campaignHS15/src/orxonox/controllers/FightingController.cc
r10885 r10886 45 45 FightingController::FightingController( Context* context ): FlyingController( context ) 46 46 { 47 this->attackRange_ = 3000;47 this->attackRange_ = 2500; 48 48 this->stopLookingAtTarget(); 49 49 this->bSetupWorked = false; … … 126 126 float diffLength = diffVector.length(); 127 127 Vector3 diffUnit = diffVector/diffLength; 128 bool bTargetIsLookingAtThis = CommonController::isLooking (this->target_, this->getControllableEntity(), math::pi/20.0f); 129 128 bool bTargetIsLookingAtThis = CommonController::isLooking (this->target_, this->getControllableEntity(), math::pi/15.0f) 129 || this->deltaHp < 0; 130 130 131 //too far? well, come closer then 131 132 if (diffLength > this->attackRange_) 132 133 { 133 this->spread_ = 300;134 this->formationMode_ = FormationMode:: WALL;134 this->spread_ = 400; 135 this->formationMode_ = FormationMode::DIAMOND; 135 136 this->bKeepFormation_ = true; 136 137 137 this->setTargetPosition(this->positionOfTarget_ - diffUnit * 200.0f);138 this->setTargetPosition(this->positionOfTarget_ - diffUnit * 100.0f); 138 139 } 139 140 //too close? How do u expect to dodge anything? Just attack! 140 else if (diffLength < 500)141 else if (diffLength < 400) 141 142 { 142 143 this->bKeepFormation_ = false; 143 144 144 145 //at this point, just look and shoot 145 if (diffLength < 2 50)146 if (diffLength < 200) 146 147 { 147 148 this->stopMoving(); … … 150 151 else 151 152 { 152 this->setTargetPosition(this->positionOfTarget_ - diffUnit * 200.0f);153 this->setTargetPosition(this->positionOfTarget_ - diffUnit * 100.0f); 153 154 } 154 155 } … … 157 158 { 158 159 this->bKeepFormation_ = false; 159 this->setTargetPosition(this->positionOfTarget_ - diffUnit * 200.0f);160 this->setTargetPosition(this->positionOfTarget_ - diffUnit * 100.0f); 160 161 } 161 162 //That's unfortunate, he is looking and probably shooting... try to dodge what we can... … … 165 166 if (maneuverCounter_ == 0) 166 167 { 167 this->setTargetPosition(this->positionOfTarget_ - diffUnit * 200.0f);168 this->setTargetPosition(this->positionOfTarget_ - diffUnit * 50.0f); 168 169 return; 169 170 } … … 176 177 //d.x*x + d.y*y + d.z*z == 0 177 178 //z = 1/d.z * (-d.y*y - d.x * x) 178 float x = CommonController::randomInRange (100 0, 10000) * (CommonController::randomInRange(0,1) <= 0.5 ? 1 : -1);179 float y = CommonController::randomInRange (100 0, 10000) * (CommonController::randomInRange(0,1) <= 0.5 ? 1 : -1);179 float x = CommonController::randomInRange (100, 800) * (CommonController::randomInRange(0,1) <= 0.5 ? 1 : -1); 180 float y = CommonController::randomInRange (100, 800) * (CommonController::randomInRange(0,1) <= 0.5 ? 1 : -1); 180 181 float z = (1/diffUnit.z) * (-x * diffUnit.x - y * diffUnit.y); 181 this->setTargetPosition(thisPosition + Vector3(x,y,z) + diffUnit * 1000.0f);182 this->setTargetPosition(thisPosition + Vector3(x,y,z) + (this->deltaHp < 0 ? -diffUnit * 450.0f : diffUnit * 100.0f)); 182 183 this->boostControl(); 183 184 … … 195 196 this->setPositionOfTarget(newPositionOfTarget); 196 197 } 198 197 199 return squaredDistanceToTarget() < this->attackRange_*this->attackRange_ && this->isLookingAtTarget(math::pi / 20.0f); 198 200 } … … 270 272 return; 271 273 } 274 272 275 Pawn* pawn = orxonox_cast<Pawn*> (this->getControllableEntity()); 273 276 if (pawn) 274 277 pawn->setAimPosition (this->positionOfTarget_); 275 278 // if (pawn->getHealth() < 100) 279 // orxout(internal_error) << "not full, hp = " << pawn->getHealth() << endl; 276 280 int firemode; 277 281 float distance = CommonController::distance (this->getControllableEntity(), this->target_); … … 281 285 // : getFiremode("HsW01")) : 282 286 // (distance < 2500 ? getFiremode("LightningGun") : getFiremode("HsW01")); 283 if (distance < 800)284 { 285 if (this->rocketsLeft_ > 0 )286 { 287 firemode = getFiremode (" SimpleRocketFire");287 if (distance < 1500) 288 { 289 if (this->rocketsLeft_ > 0 && !this->bFiredRocket_) 290 { 291 firemode = getFiremode ("RocketFire"); 288 292 } 289 293 else 290 294 { 291 if (distance > 450) 295 if (distance > 800) 296 firemode = getFiremode ("HsW01"); 297 else 292 298 firemode = getFiremode ("LightningGun"); 293 else294 firemode = getFiremode ("HsW01");295 299 } 296 300 297 301 } 298 else if (distance < 1200) 299 { 300 if (this->rocketsLeft_ > 0 && !this->bFiredRocket_) 301 { 302 firemode = getFiremode ("RocketFire"); 303 } 304 else 305 { 306 firemode = getFiremode ("HsW01"); 307 } 308 } 309 else if (distance < 1500) 302 // else if (distance < 1000) 303 // { 304 // if (this->rocketsLeft_ > 0 && !this->bFiredRocket_) 305 // { 306 // firemode = getFiremode ("RocketFire"); 307 // } 308 // else 309 // { 310 // firemode = getFiremode ("HsW01"); 311 // } 312 // } 313 else if (distance < 2000) 314 { 315 firemode = getFiremode ("HsW01"); 316 } 317 else 310 318 { 311 319 firemode = getFiremode ("LightningGun"); 312 320 } 313 else314 {315 firemode = getFiremode ("HsW01");316 }317 321 if (firemode < 0) 318 322 { 319 firemode = getFiremode ("HsW01"); 323 //assuming there is always some weapon with index 0 324 firemode = 0; 320 325 } 321 326 if (firemode == getFiremode("RocketFire")) 322 327 { 323 this->timeout_ = 1.0f;328 this->timeout_ = 0.5f; 324 329 this->rocketsLeft_--; 325 330 this->bFiredRocket_ = true; -
code/branches/campaignHS15/src/orxonox/controllers/FightingController.h
r10885 r10886 77 77 int maneuverCounter_; 78 78 bool bLookAtTarget_; 79 79 float deltaHp; 80 float previousHp; 80 81 //WEAPONSYSTEM DATA 81 82 int rocketsLeft_; -
code/branches/campaignHS15/src/orxonox/controllers/FlyingController.cc
r10885 r10886 201 201 } 202 202 } 203 void FlyingController::keepFormation(const ControllableEntity* leaderEntity, Vector3& targetRelativePosition) 204 { 205 ControllableEntity* myEntity = this->getControllableEntity(); 206 Vector3 myPosition = myEntity->getWorldPosition(); 207 208 if (!leaderEntity) 209 { 210 return; 211 } 212 Quaternion orient = leaderEntity->getWorldOrientation(); 213 Vector3 leaderPosition = leaderEntity->getWorldPosition(); 214 215 if (!leaderEntity) 216 { 217 return; 218 } 219 Vector3 targetAbsolutePosition = 220 (leaderPosition + (orient*WorldEntity::FRONT) * (leaderEntity->getVelocity().length()/5) 221 + (orient* (targetRelativePosition))); 222 //let ship finish rotating. also don't call copyOrientation to often as it is a slow function. 223 if (this->actionCounter_ % 6 == 0 && !this->bHasTargetOrientation_) 224 this->setTargetOrientation (orient); 225 this->setTargetPosition (targetAbsolutePosition); 226 if ((targetAbsolutePosition - myPosition).length() > this->tolerance_ * 1.5f) 227 { 228 this->boostControl(); 229 } 230 else 231 { 232 this->getControllableEntity()->boost(false); 233 } 234 } 203 235 } -
code/branches/campaignHS15/src/orxonox/controllers/FlyingController.h
r10885 r10886 21 21 * 22 22 * Author: 23 * Fabian 'x3n' Landau23 * Gani Aliguzhinov 24 24 * Co-authors: 25 * ...25 * Dominik Solenicki 26 26 * 27 27 */ … … 79 79 void setTargetOrientation(const Quaternion& orient); 80 80 void setTargetOrientation(ControllableEntity* target); 81 virtual void boostControl(); 81 virtual void boostControl(); 82 void keepFormation (const ControllableEntity* leaderEntity, Vector3& targetRelativePosition); 82 83 FormationMode::Value formationMode_; 83 84 -
code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc
r10885 r10886 39 39 40 40 //Leaders share the fact that they have Wingmans 41 SectionController::SectionController(Context* context) : LeaderController(context)41 SectionController::SectionController(Context* context) : ActionpointController(context) 42 42 { 43 43 RegisterObject(SectionController); … … 54 54 SectionController::~SectionController() 55 55 { 56 // if (this->myWingman_)57 // {58 // this->myWingman_->takeActionpoints(this->parsedActionpoints_, this->loopActionpoints_, this->bLoop_);59 // }60 56 for (size_t i = 0; i < this->actionpoints_.size(); ++i) 61 57 { … … 69 65 { 70 66 SUPER(SectionController, XMLPort, xmlelement, mode); 71 72 //XMLPortParam(SectionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f);73 67 } 74 68 … … 78 72 if (!this->isActive()) 79 73 return; 80 81 //this doesn't fight in formation flight, thus we can afford executing following code in tick: when nobody fights, tick is anyway stable. 82 if (this->myDivisionLeader_ && this->myDivisionLeader_->getAction() != Action::FIGHT && this->myDivisionLeader_->getAction() != 83 Action::FIGHTALL && this->myDivisionLeader_->getAction() != Action::ATTACK) 84 { 85 86 } 74 87 75 SUPER(SectionController, tick, dt); 88 76 } … … 110 98 if (!myDivisionLeader_) 111 99 { 112 113 100 ActionpointController::action(); 114 101 if (!this || !this->getControllableEntity()) … … 128 115 || this->myDivisionLeader_->getAction() == Action::ATTACK)) 129 116 { 130 ControllableEntity* myEntity = this->getControllableEntity(); 131 Vector3 myPosition = myEntity->getWorldPosition(); 132 if (!this->myDivisionLeader_) 133 { 134 return; 135 } 136 ControllableEntity* leaderEntity = this->myDivisionLeader_->getControllableEntity(); 137 Quaternion orient = leaderEntity->getWorldOrientation(); 138 Vector3 leaderPosition = leaderEntity->getWorldPosition(); 139 140 Vector3 targetRelativePosition = getFormationPosition(); 141 if (!this->myDivisionLeader_) 142 { 143 return; 144 } 145 Vector3 targetAbsolutePosition = 146 (leaderPosition + (orient*WorldEntity::FRONT) * (leaderEntity->getVelocity().length()/5) 147 + (orient* (targetRelativePosition))); 148 //let ship finish rotating. also don't call copyOrientation to often as it is a slow function. 149 if (this->actionCounter_ % 6 == 0 && !this->bHasTargetOrientation_) 150 this->setAction (Action::FLY, targetAbsolutePosition, orient); 151 else 152 this->setAction (Action::FLY, targetAbsolutePosition); 153 154 if ((targetAbsolutePosition - myPosition).length() > this->tolerance_ * 1.5f) 155 { 156 this->boostControl(); 157 } 158 else 159 { 160 this->getControllableEntity()->boost(false); 161 } 162 } 163 else 164 { 165 switch (myDivisionLeader_->getAction()) 166 { 167 case Action::FIGHT: 168 { 169 if (!this->hasTarget()) 170 { 171 this->chooseTarget(); 172 } 173 break; 174 } 175 case Action::FIGHTALL: 176 { 177 if (!this->hasTarget()) 178 { 179 this->chooseTarget(); 180 } 181 break; 182 } 183 case Action::ATTACK: 184 { 185 if (!this->hasTarget()) 186 { 187 this->chooseTarget(); 188 } 189 break; 190 } 191 default: 192 { 193 //formation flight is executed in tick 194 } 117 this->keepFormation(); 118 } 119 else if (!this->myDivisionLeader_->bKeepFormation_) 120 { 121 if (!this->hasTarget()) 122 { 123 this->chooseTarget(); 195 124 } 196 125 if (this->hasTarget()) 197 126 { 198 //----choose where to go----199 127 this->maneuver(); 200 //----fire if you can----201 128 this->bShooting_ = this->canFire(); 202 129 } 203 130 } 204 205 206 131 } 207 132 this->actionCounter_ += this->actionCounter_ < 100000 ? 1 : -this->actionCounter_ ; 208 209 133 } 210 134 … … 298 222 } 299 223 300 224 void SectionController::keepFormation() 225 { 226 this->bKeepFormation_ = true; 227 ControllableEntity* leaderEntity = this->myDivisionLeader_->getControllableEntity(); 228 Vector3 targetRelativePosition = this->getFormationPosition(); 229 if (!leaderEntity) 230 return; 231 FlyingController::keepFormation(leaderEntity, targetRelativePosition); 232 } 301 233 302 234 ActionpointController* SectionController::findNewDivisionLeader() -
code/branches/campaignHS15/src/orxonox/controllers/SectionController.h
r10885 r10886 30 30 #define _SectionController_H__ 31 31 32 #include "controllers/ LeaderController.h"32 #include "controllers/ActionpointController.h" 33 33 34 34 35 35 namespace orxonox 36 36 { 37 class _OrxonoxExport SectionController : public LeaderController37 class _OrxonoxExport SectionController : public ActionpointController 38 38 { 39 39 public: … … 64 64 virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour. 65 65 Vector3 getFormationPosition (); 66 void keepFormation(); 66 67 private: 67 68 //----private variables----- -
code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc
r10885 r10886 59 59 { 60 60 SUPER(WingmanController, XMLPort, xmlelement, mode); 61 62 //XMLPortParam(SectionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f);63 61 } 64 62 … … 67 65 { 68 66 if (!this->isActive()) 69 return; 70 if (this->myLeader_ && this->myLeader_->getAction() != Action::FIGHT && this->myLeader_->getAction() != 71 Action::FIGHTALL && this->myLeader_->getAction() != Action::ATTACK) 72 { 73 } 67 return; 74 68 75 69 SUPER(WingmanController, tick, dt); … … 108 102 || this->myLeader_->getAction() == Action::ATTACK)) 109 103 { 110 ControllableEntity* myEntity = this->getControllableEntity(); 111 Vector3 myPosition = myEntity->getWorldPosition(); 112 if (!this->myLeader_) 113 { 114 return; 115 } 116 ControllableEntity* leaderEntity = this->myLeader_->getControllableEntity(); 117 Quaternion orient = leaderEntity->getWorldOrientation(); 118 Vector3 leaderPosition = leaderEntity->getWorldPosition(); 119 Vector3 targetRelativePosition = getFormationPosition(); 120 if (!this->myLeader_) 121 { 122 return; 123 } 124 Vector3 targetAbsolutePosition = 125 (leaderPosition + (orient*WorldEntity::FRONT) * (leaderEntity->getVelocity().length()/5) 126 + (orient* (targetRelativePosition))); 127 //let ship finish rotating. also don't call copyOrientation to often as it is a slow function. 128 if (this->actionCounter_ % 6 == 0 && !this->bHasTargetOrientation_) 129 this->setAction (Action::FLY, targetAbsolutePosition, orient); 130 else 131 this->setAction (Action::FLY, targetAbsolutePosition); 132 if ((targetAbsolutePosition - myPosition).length() > this->tolerance_ * 1.5f) 133 { 134 this->boostControl(); 135 } 136 else 137 { 138 this->getControllableEntity()->boost(false); 139 } 140 } 141 else 142 { 143 switch (this->myLeader_->getAction()) 144 { 145 case Action::FIGHT: 146 { 147 if (!this->hasTarget()) 148 { 149 this->setTarget(this->myLeader_->getTarget()); 150 } 151 break; 152 } 153 case Action::FIGHTALL: 154 { 155 if (!this->hasTarget()) 156 { 157 this->setTarget(this->myLeader_->getTarget()); 158 } 159 break; 160 } 161 case Action::ATTACK: 162 { 163 if (!this->hasTarget()) 164 { 165 this->setTarget(this->myLeader_->getTarget()); 166 } 167 break; 168 } 169 default: 170 { 171 172 } 104 this->keepFormation(); 105 } 106 else if (!this->myLeader_->bKeepFormation_) 107 { 108 if (!this->hasTarget()) 109 { 110 this->setTarget(this->myLeader_->getTarget()); 173 111 } 174 112 if (this->hasTarget()) … … 180 118 } 181 119 } 182 183 184 120 } 185 121 this->actionCounter_ += this->actionCounter_ < 100000 ? 1 : -this->actionCounter_ ; … … 236 172 delete targetRelativePosition; 237 173 return result; 174 } 175 void WingmanController::keepFormation() 176 { 177 this->bKeepFormation_ = true; 178 ControllableEntity* leaderEntity = this->myLeader_->getControllableEntity(); 179 Vector3 targetRelativePosition = this->getFormationPosition(); 180 if (!leaderEntity) 181 return; 182 FlyingController::keepFormation (leaderEntity, targetRelativePosition); 238 183 } 239 184 //----POST: closest leader that is ready to take a new wingman is returned---- … … 268 213 minDistance = distance; 269 214 } 270 271 215 } 272 216 if (closestLeader) … … 277 221 return closestLeader; 278 222 } 279 280 } 281 223 } 282 224 return 0; 283 225 } 284 226 285 286 287 288 227 } -
code/branches/campaignHS15/src/orxonox/controllers/WingmanController.h
r10885 r10886 63 63 virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour. 64 64 Vector3 getFormationPosition (); 65 65 void keepFormation(); 66 66 67 private: 67 68 //----private variables-----
Note: See TracChangeset
for help on using the changeset viewer.