Changeset 8992
- Timestamp:
- Dec 16, 2011, 8:36:41 PM (13 years ago)
- Location:
- code/branches/presentation2011
- Files:
-
- 10 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation2011
- Property svn:mergeinfo changed
/code/branches/formation (added) merged: 8885,8908,8939,8943,8948,8953,8957,8965,8967,8978,8985,8989-8991
- Property svn:mergeinfo changed
-
code/branches/presentation2011/data/defaultConfig/keybindings.ini
r8706 r8992 71 71 KeyNumLock= 72 72 KeyNumRow0= 73 KeyNumRow1= 74 KeyNumRow2= 73 KeyNumRow1="toggleFormationFlight" 74 KeyNumRow2="FFChangeMode" 75 75 KeyNumRow3= 76 76 KeyNumRow4= -
code/branches/presentation2011/src/orxonox/controllers/AIController.cc
r8980 r8992 75 75 76 76 this->defaultBehaviour(maxrand); 77 } 78 79 if (this->state_ == SLAVE) 80 { 77 78 } 79 80 if (this->state_ == SLAVE && this->formationMode_ == ATTACK) //TODO: add botlevel parameter 81 { 82 // search enemy 83 random = rnd(maxrand); 84 if (random < 75 && (!this->target_)) 85 this->searchNewTarget(); 86 87 // next enemy 88 random = rnd(maxrand); 89 if (random < 10 && (this->target_)) 90 this->searchNewTarget(); 91 92 // shoot 93 random = rnd(maxrand); 94 if (!(this->passive_) && random < 75 && (this->target_ && !this->bShooting_)) 95 this->bShooting_ = true; 96 97 // stop shooting 98 random = rnd(maxrand); 99 if (random < 25 && (this->bShooting_)) 100 this->bShooting_ = false; 81 101 82 102 } … … 101 121 this->spinInit(); 102 122 103 / / follow a randomly chosen human - a specific Master Action123 /*// follow a randomly chosen human - a specific Master Action 104 124 random = rnd(1000.0f); 105 125 if (random < 1) 106 126 this->followRandomHumanInit(); 107 127 */ 108 128 // lose master status (only if less than 4 slaves in formation) 109 129 random = rnd(maxrand); … … 117 137 118 138 this->defaultBehaviour(maxrand); 119 } 120 } 139 140 } 141 } 142 121 143 } 122 144 … … 129 151 float maxrand = 100.0f / ACTION_INTERVAL; 130 152 ControllableEntity* controllable = this->getControllableEntity(); 131 153 //DOES: Either move to the waypoint or search for a Point of interest 132 154 if (controllable && this->mode_ == DEFAULT)// bot is ready to move to a target 133 155 { … … 151 173 } 152 174 } 153 if(this->mode_ == DEFAULT) 154 { 175 176 if (this->mode_ == DEFAULT) 177 { 155 178 if (this->state_ == MASTER) 156 179 { … … 165 188 this->aimAtTarget(); 166 189 random = rnd(maxrand); 167 if(this->botlevel_* 100 > random && !this->isCloseAtTarget(20))190 if(this->botlevel_*70 > random && !this->isCloseAtTarget(100)) 168 191 this->follow(); //If a bot is shooting a player, it shouldn't let him go away easily. 169 192 } … … 172 195 if (this->bHasTargetPosition_) 173 196 this->moveToTargetPosition(); 174 175 197 this->doFire(); 176 198 } … … 185 207 } 186 208 187 if (this->state_ == SLAVE )209 if (this->state_ == SLAVE && this->formationMode_ != ATTACK) 188 210 { 189 211 if (this->bHasTargetPosition_) … … 191 213 } 192 214 193 if (this->state_ == FREE )215 if (this->state_ == FREE || (this->state_==SLAVE && this->formationMode_ == ATTACK) ) 194 216 { 195 217 if (this->target_) … … 197 219 if (!this->target_->getRadarVisibility()) /* So AI won't shoot invisible Spaceships */ 198 220 this->forgetTarget(); 199 else 200 { 201 this->aimAtTarget(); 202 random = rnd(maxrand); 203 204 if(this->botlevel_*100 > random && !this->isCloseAtTarget(20)) 205 this->follow();//If a bot is shooting a player, it shouldn't let him go away easily. 206 } 221 else this->aimAtTarget(); 207 222 } 208 223 … … 210 225 this->moveToTargetPosition(); 211 226 212 this->doFire();213 } 214 } //END_OF DEFAULT MODE227 this->doFire(); 228 } 229 } 215 230 else if (this->mode_ == ROCKET)//Rockets do not belong to a group of bots -> bot states are not relevant. 216 231 { //Vector-implementation: mode_.back() == ROCKET; … … 237 252 SUPER(AIController, tick, dt); 238 253 } 239 254 //**********************************************NEW 240 255 void AIController::defaultBehaviour(float maxrand) 241 256 { float random; -
code/branches/presentation2011/src/orxonox/controllers/AIController.h
r8980 r8992 53 53 static const float ACTION_INTERVAL; 54 54 55 Timer actionTimer_; //<! Regularly calls action(). 55 Timer actionTimer_; //<! Regularly calls action(). 56 56 }; 57 57 } -
code/branches/presentation2011/src/orxonox/controllers/ArtificialController.cc
r8980 r8992 24 24 * Co-authors: 25 25 * Dominik Solenicki 26 * 26 * 27 27 */ 28 28 29 29 #include "ArtificialController.h" 30 31 #include <vector>32 #include <climits>33 34 #include "util/Math.h"35 30 #include "core/CoreIncludes.h" 36 #include "core/XMLPort.h"37 #include "core/command/ConsoleCommand.h"38 #include "worldentities/ControllableEntity.h"39 31 #include "worldentities/pawns/Pawn.h" 40 #include "worldentities/pawns/TeamBaseMatchBase.h"41 32 #include "worldentities/pawns/SpaceShip.h" 42 #include "gametypes/TeamDeathmatch.h" 43 #include "gametypes/Dynamicmatch.h" 44 #include "gametypes/Mission.h" 45 #include "controllers/WaypointPatrolController.h" 46 #include "controllers/NewHumanController.h" 47 #include "controllers/DroneController.h" 33 48 34 #include "weaponsystem/WeaponMode.h" 49 35 #include "weaponsystem/WeaponPack.h" … … 52 38 #include "weaponsystem/WeaponSlot.h" 53 39 40 54 41 namespace orxonox 55 42 { 56 SetConsoleCommand("ArtificialController", "formationflight", &ArtificialController::formationflight); 57 SetConsoleCommand("ArtificialController", "masteraction", &ArtificialController::masteraction); 58 SetConsoleCommand("ArtificialController", "followme", &ArtificialController::followme); 59 SetConsoleCommand("ArtificialController", "passivebehaviour", &ArtificialController::passivebehaviour); 60 SetConsoleCommand("ArtificialController", "formationsize", &ArtificialController::formationsize); 61 SetConsoleCommand("ArtificialController", "setbotlevel", &ArtificialController::setAllBotLevel); 62 63 static const unsigned int STANDARD_MAX_FORMATION_SIZE = 7; 64 static const int RADIUS_TO_SEARCH_FOR_MASTERS = 5000; 65 static const int FORMATION_LENGTH = 130; 66 static const int FORMATION_WIDTH = 110; 67 static const int FREEDOM_COUNT = 4; //seconds the slaves in a formation will be set free when master attacks an enemy 68 static const float SPEED_MASTER = 0.6f; 69 static const float ROTATEFACTOR_MASTER = 0.2f; 70 static const float SPEED_FREE = 0.8f; 71 static const float ROTATEFACTOR_FREE = 0.8f; 72 73 74 ArtificialController::ArtificialController(BaseObject* creator) : Controller(creator) 75 { 76 RegisterObject(ArtificialController); 77 78 this->target_ = 0; 79 this->formationFlight_ = false; 80 this->passive_ = false; 81 this->maxFormationSize_ = STANDARD_MAX_FORMATION_SIZE; 82 this->myMaster_ = 0; 83 this->freedomCount_ = 0; 84 this->team_ = -1; 85 this->state_ = FREE; 86 this->specificMasterAction_ = NONE; 87 this->specificMasterActionHoldCount_ = 0; 88 this->bShooting_ = false; 89 this->bHasTargetPosition_ = false; 90 this->speedCounter_ = 0.2f; 91 this->targetPosition_ = Vector3::ZERO; 92 93 this->target_.setCallback(createFunctor(&ArtificialController::targetDied, this)); 43 44 ArtificialController::ArtificialController(BaseObject* creator) : FormationController(creator) 45 { 94 46 this->bSetupWorked = false; 95 47 this->botlevel_ = 0.5f; 96 this->mode_ = DEFAULT;////Vector-implementation: mode_.push_back(DEFAULT);97 48 this->timeout_ = 0; 98 49 this->currentWaypoint_ = 0; 99 50 this->setAccuracy(5); 100 51 this->defaultWaypoint_ = NULL; 52 this->mode_ = DEFAULT;//Vector-implementation: mode_.push_back(DEFAULT); 101 53 } 102 54 … … 106 58 {//Vector-implementation: mode_.erase(mode_.begin(),mode_.end()); 107 59 this->waypoints_.clear(); 108 this->removeFromFormation();109 60 this->weaponModes_.clear(); 110 for (ObjectList<ArtificialController>::iterator it = ObjectList<ArtificialController>::begin(); it; ++it) 111 { 112 if (*it != this) 113 { 114 if (it->myMaster_ == this) 115 { 116 orxout(internal_error) << this << " is still master in " << (*it) << endl; 117 it->myMaster_ = 0; 118 } 119 120 while (true) 121 { 122 std::vector<ArtificialController*>::iterator it2 = std::find(it->slaves_.begin(), it->slaves_.end(), this); 123 if (it2 != it->slaves_.end()) 124 { 125 orxout(internal_error) << this << " is still slave in " << (*it) << endl; 126 it->slaves_.erase(it2); 127 } 128 else 129 break; 130 } 131 } 132 } 133 } 134 } 135 136 void ArtificialController::XMLPort(Element& xmlelement, XMLPort::Mode mode) 137 { 138 SUPER(ArtificialController, XMLPort, xmlelement, mode); 139 140 XMLPortParam(ArtificialController, "team", setTeam, getTeam, xmlelement, mode).defaultValues(-1); 141 XMLPortParam(ArtificialController, "formationFlight", setFormationFlight, getFormationFlight, xmlelement, mode).defaultValues(false); 142 XMLPortParam(ArtificialController, "formationSize", setFormationSize, getFormationSize, xmlelement, mode).defaultValues(STANDARD_MAX_FORMATION_SIZE); 143 XMLPortParam(ArtificialController, "passive", setPassive, getPassive, xmlelement, mode).defaultValues(false); 144 } 145 146 // Documentation only here to get a faster overview for creating a useful documentation... 147 148 /** 149 @brief Activates / deactivates formationflight behaviour 150 @param form activate formflight if form is true 151 */ 152 void ArtificialController::formationflight(const bool form) 153 { 154 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it) 155 { 156 Controller* controller = 0; 157 158 if (it->getController()) 159 controller = it->getController(); 160 else if (it->getXMLController()) 161 controller = it->getXMLController(); 162 163 if (!controller) 164 continue; 165 166 ArtificialController *aiController = orxonox_cast<ArtificialController*>(controller); 167 168 if (aiController) 169 { 170 aiController->formationFlight_ = form; 171 if (!form) 172 { 173 aiController->removeFromFormation(); 174 } 175 } 176 } 177 } 178 179 /** 180 @brief Get all masters to do a "specific master action" 181 @param action which action to perform (integer, so it can be called with a console command (tmp solution)) 182 */ 183 void ArtificialController::masteraction(const int action) 184 { 185 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it) 186 { 187 Controller* controller = 0; 188 189 if (it->getController()) 190 controller = it->getController(); 191 else if (it->getXMLController()) 192 controller = it->getXMLController(); 193 194 if (!controller) 195 continue; 196 197 ArtificialController *aiController = orxonox_cast<ArtificialController*>(controller); 198 199 if(aiController && aiController->state_ == MASTER) 200 { 201 if (action == 1) 202 aiController->spinInit(); 203 if (action == 2) 204 aiController->turn180Init(); 205 } 206 } 207 } 208 209 /** 210 @brief A human player gets followed by its nearest master. Initiated by console command, so far intended for demonstration puproses (possible future pickup). 211 */ 212 void ArtificialController::followme() 213 { 214 215 Pawn *humanPawn = NULL; 216 NewHumanController *currentHumanController = NULL; 217 std::vector<ArtificialController*> allMasters; 218 219 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it) 220 { 221 Controller* controller = 0; 222 223 if (it->getController()) 224 controller = it->getController(); 225 else if (it->getXMLController()) 226 controller = it->getXMLController(); 227 228 if (!controller) 229 continue; 230 231 currentHumanController = orxonox_cast<NewHumanController*>(controller); 232 233 if(currentHumanController) humanPawn = *it; 234 235 ArtificialController *aiController = orxonox_cast<ArtificialController*>(controller); 236 237 if(aiController && aiController->state_ == MASTER) 238 allMasters.push_back(aiController); 239 240 } 241 242 if((humanPawn != NULL) && (allMasters.size() != 0)) 243 { 244 float posHuman = humanPawn->getPosition().length(); 245 float distance = 0.0f; 246 float minDistance = FLT_MAX; 247 int index = 0; 248 int i = 0; 249 250 for(std::vector<ArtificialController*>::iterator it = allMasters.begin(); it != allMasters.end(); it++, i++) 251 { 252 if (!ArtificialController::sameTeam((*it)->getControllableEntity(), humanPawn, (*it)->getGametype())) continue; 253 distance = posHuman - (*it)->getControllableEntity()->getPosition().length(); 254 if(distance < minDistance) index = i; 255 } 256 allMasters[index]->followInit(humanPawn); 257 } 258 259 } 260 261 /** 262 @brief Sets shooting behaviour of pawns. 263 @param passive if true, bots won't shoot. 264 */ 265 void ArtificialController::passivebehaviour(const bool passive) 266 { 267 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it) 268 { 269 Controller* controller = 0; 270 271 if (it->getController()) 272 controller = it->getController(); 273 else if (it->getXMLController()) 274 controller = it->getXMLController(); 275 276 if (!controller) 277 continue; 278 279 ArtificialController *aiController = orxonox_cast<ArtificialController*>(controller); 280 281 if(aiController) 282 { 283 aiController->passive_ = passive; 284 } 285 } 286 } 287 288 289 /** 290 @brief Sets maximal formation size 291 @param size maximal formation size. 292 */ 293 void ArtificialController::formationsize(const int size) 294 { 295 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it) 296 { 297 Controller* controller = 0; 298 299 if (it->getController()) 300 controller = it->getController(); 301 else if (it->getXMLController()) 302 controller = it->getXMLController(); 303 304 if (!controller) 305 continue; 306 307 ArtificialController *aiController = orxonox_cast<ArtificialController*>(controller); 308 309 if(aiController) 310 { 311 aiController->maxFormationSize_ = size; 312 } 313 } 314 } 61 } 62 } 63 315 64 316 65 /** … … 321 70 if (!this->getControllableEntity()) 322 71 this->removeFromFormation(); 323 this->bSetupWorked = false; // reset weapon information 324 this->setupWeapons(); 325 } 326 327 void ArtificialController::removeFromFormation() 328 { 329 if (this->state_ == SLAVE || this->myMaster_) // slaves can also be temporary free, so check if myMaster_ is set 330 this->unregisterSlave(); 331 else if (this->state_ == MASTER) 332 this->setNewMasterWithinFormation(); 333 } 334 335 void ArtificialController::moveToPosition(const Vector3& target) 336 { 337 if (!this->getControllableEntity()) 338 return; 339 340 // Slave uses special movement if its master is in FOLLOW mode 341 if(this->state_ == SLAVE && this->myMaster_ && this->myMaster_->specificMasterAction_ == FOLLOW) 342 { 343 // this->followForSlaves(target); 344 // return; 345 } 346 347 Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target); 348 float distance = (target - this->getControllableEntity()->getPosition()).length(); 349 350 351 if(this->state_ == FREE) 352 { 353 if (this->target_ || distance > 10) 354 { 355 // Multiply with ROTATEFACTOR_FREE to make them a bit slower 356 this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_FREE * sgn(coord.x) * coord.x*coord.x); 357 this->getControllableEntity()->rotatePitch(ROTATEFACTOR_FREE * sgn(coord.y) * coord.y*coord.y); 358 } 359 360 if (this->target_ && distance < 200 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength()) 361 { 362 this->getControllableEntity()->moveFrontBack(-0.05f); // They don't brake with full power to give the player a chance 363 } else this->getControllableEntity()->moveFrontBack(SPEED_FREE); 364 } 365 366 367 368 if(this->state_ == MASTER) 369 { 370 if (this->target_ || distance > 10) 371 { 372 this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_MASTER * sgn(coord.x) * coord.x*coord.x); 373 this->getControllableEntity()->rotatePitch(ROTATEFACTOR_MASTER * sgn(coord.y) * coord.y*coord.y); 374 } 375 376 if (this->target_ && distance < 200 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength()) 377 { 378 this->getControllableEntity()->moveFrontBack(-0.05f); 379 } else this->getControllableEntity()->moveFrontBack(SPEED_MASTER); 380 } 381 382 383 384 if(this->state_ == SLAVE) 385 { 386 387 this->getControllableEntity()->rotateYaw(-2.0f * ROTATEFACTOR_MASTER * sgn(coord.x) * coord.x*coord.x); 388 this->getControllableEntity()->rotatePitch(2.0f * ROTATEFACTOR_MASTER * sgn(coord.y) * coord.y*coord.y); 389 390 if (distance < 300) 391 { 392 if (distance < 40) 393 { 394 this->getControllableEntity()->moveFrontBack(0.8f*SPEED_MASTER); 395 } else this->getControllableEntity()->moveFrontBack(1.2f*SPEED_MASTER); 396 397 } else { 398 this->getControllableEntity()->moveFrontBack(1.2f*SPEED_MASTER + distance/300.0f); 399 } 400 } 401 402 if (distance < 10) 403 { 404 this->positionReached(); 405 } 406 } 407 408 void ArtificialController::absoluteMoveToPosition(const Vector3& target) 409 { 410 float minDistance = 40.0f; 411 if (!this->getControllableEntity()) 412 return; 413 414 Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target); 415 float distance = (target - this->getControllableEntity()->getPosition()).length(); 416 417 if (this->target_ || distance > minDistance) 418 { 419 // Multiply with ROTATEFACTOR_FREE to make them a bit slower 420 this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_FREE * sgn(coord.x) * coord.x*coord.x); 421 this->getControllableEntity()->rotatePitch(ROTATEFACTOR_FREE * sgn(coord.y) * coord.y*coord.y); 422 this->getControllableEntity()->moveFrontBack(SPEED_FREE); 423 } 424 425 426 if (distance < minDistance) 427 { 428 this->positionReached(); 429 } 430 } 431 432 433 void ArtificialController::moveToTargetPosition() 434 { 435 this->moveToPosition(this->targetPosition_); 436 } 437 438 /** 439 @brief Unregisters a slave from its master. Initiated by a slave. 440 */ 441 void ArtificialController::unregisterSlave() 442 { 443 if (this->myMaster_) 444 { 445 std::vector<ArtificialController*>::iterator it = std::find(this->myMaster_->slaves_.begin(), this->myMaster_->slaves_.end(), this); 446 if (it != this->myMaster_->slaves_.end()) 447 this->myMaster_->slaves_.erase(it); 448 } 449 450 this->myMaster_ = 0; 451 this->state_ = FREE; 452 } 453 454 void ArtificialController::searchNewMaster() 455 { 456 457 if (!this->getControllableEntity()) 458 return; 459 460 this->targetPosition_ = this->getControllableEntity()->getPosition(); 461 this->forgetTarget(); 462 int teamSize = 0; 463 //go through all pawns 464 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it) 465 { 466 //same team? 467 if (!ArtificialController::sameTeam(this->getControllableEntity(), static_cast<ControllableEntity*>(*it), this->getGametype())) 468 continue; 469 470 //has it an ArtificialController? 471 Controller* controller = 0; 472 473 if (it->getController()) 474 controller = it->getController(); 475 else if (it->getXMLController()) 476 controller = it->getXMLController(); 477 478 if (!controller) 479 continue; 480 481 //is pawn oneself? 482 if (orxonox_cast<ControllableEntity*>(*it) == this->getControllableEntity()) 483 continue; 484 485 teamSize++; 486 487 ArtificialController *newMaster = orxonox_cast<ArtificialController*>(controller); 488 489 //is it a master? 490 if (!newMaster || newMaster->state_ != MASTER) 491 continue; 492 493 float distance = (it->getPosition() - this->getControllableEntity()->getPosition()).length(); 494 495 // is pawn in range? 496 if (distance < RADIUS_TO_SEARCH_FOR_MASTERS) 497 { 498 if(newMaster->slaves_.size() > this->maxFormationSize_) continue; 499 500 for(std::vector<ArtificialController*>::iterator itSlave = this->slaves_.begin(); itSlave != this->slaves_.end(); itSlave++) 501 { 502 (*itSlave)->myMaster_ = newMaster; 503 newMaster->slaves_.push_back(*itSlave); 504 } 505 this->slaves_.clear(); 506 this->state_ = SLAVE; 507 508 this->myMaster_ = newMaster; 509 newMaster->slaves_.push_back(this); 510 511 break; 512 } 513 } 514 515 if (this->state_ != SLAVE && teamSize != 0) 516 { 517 this->state_ = MASTER; 518 this->myMaster_ = 0; 519 } 520 } 521 522 /** 523 @brief Commands the slaves of a master into a formation. Sufficiently fast not to be called within tick. Initiated by a master. 524 */ 525 void ArtificialController::commandSlaves() 526 { 527 if(this->state_ != MASTER) return; 528 529 Quaternion orient = this->getControllableEntity()->getOrientation(); 530 Vector3 dest = this->getControllableEntity()->getPosition(); 531 532 // 1 slave: follow 533 if (this->slaves_.size() == 1) 534 { 535 dest += 4*orient*WorldEntity::BACK; 536 this->slaves_.front()->setTargetPosition(dest); 537 } 538 else 539 { 540 dest += 1.0f*orient*WorldEntity::BACK; 541 Vector3 pos = Vector3::ZERO; 542 int i = 1; 543 544 for(std::vector<ArtificialController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++) 545 { 546 pos = Vector3::ZERO; 547 if (i <= 1) pos += dest + (float)FORMATION_WIDTH*(orient*WorldEntity::LEFT); 548 if (i == 2) pos += dest + (float)FORMATION_WIDTH*(orient*WorldEntity::RIGHT); 549 if (i == 3) pos += dest + (float)FORMATION_WIDTH*(orient*WorldEntity::UP); 550 if (i >= 4) 551 { 552 pos += dest + (float)FORMATION_WIDTH*(orient*WorldEntity::DOWN); 553 i = 1; 554 dest += (float)FORMATION_LENGTH*(orient*WorldEntity::BACK); 555 (*it)->setTargetPosition(pos); 556 continue; 557 } 558 i++; 559 (*it)->setTargetPosition(pos); 560 } 561 } 562 } 563 564 /** 565 @brief Sets a new master within the formation. Called by a master. 566 */ 567 void ArtificialController::setNewMasterWithinFormation() 568 { 569 if(this->state_ != MASTER) return; 570 571 if (!this->slaves_.empty()) 572 { 573 ArtificialController *newMaster = this->slaves_.back(); 574 this->slaves_.pop_back(); 575 576 newMaster->state_ = MASTER; 577 newMaster->slaves_ = this->slaves_; 578 newMaster->myMaster_ = 0; 579 580 for(std::vector<ArtificialController*>::iterator it = newMaster->slaves_.begin(); it != newMaster->slaves_.end(); it++) 581 { 582 (*it)->myMaster_ = newMaster; 583 } 584 } 585 586 this->slaves_.clear(); 587 this->specificMasterAction_ = NONE; 588 this->state_ = FREE; 589 } 590 591 /** 592 @brief Frees all slaves form a master. Initiated by a master. 593 */ 594 void ArtificialController::freeSlaves() 595 { 596 if(this->state_ != MASTER) return; 597 598 for(std::vector<ArtificialController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++) 599 { 600 (*it)->state_ = FREE; 601 (*it)->myMaster_ = 0; 602 } 603 this->slaves_.clear(); 604 } 605 606 /** 607 @brief Master sets its slaves free for @ref FREEDOM_COUNT seconds. 608 */ 609 void ArtificialController::forceFreeSlaves() 610 { 611 if(this->state_ != MASTER) return; 612 613 for(std::vector<ArtificialController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++) 614 { 615 (*it)->state_ = FREE; 616 (*it)->forceFreedom(); 617 (*it)->targetPosition_ = this->targetPosition_; 618 (*it)->bShooting_ = true; 619 // (*it)->getControllableEntity()->fire(0);// fire once for fun 620 } 621 } 622 623 void ArtificialController::loseMasterState() 624 { 625 this->freeSlaves(); 626 this->state_ = FREE; 627 } 628 629 630 void ArtificialController::forceFreedom() 631 { 632 this->freedomCount_ = FREEDOM_COUNT; 633 } 634 635 /** 636 @brief Checks wether caller has been forced free, decrements time to stay forced free. 637 @return true if forced free. 638 */ 639 bool ArtificialController::forcedFree() 640 { 641 if(this->freedomCount_ > 0) 642 { 643 this->freedomCount_--; 644 return true; 645 } else return false; 646 } 647 648 /** 649 @brief Used to continue a "specific master action" for a certain time and resuming normal behaviour after. 650 */ 651 void ArtificialController::specificMasterActionHold() 652 { 653 if(this->state_ != MASTER) return; 654 655 if (specificMasterActionHoldCount_ == 0) 656 { 657 this->specificMasterAction_ = NONE; 658 this->searchNewTarget(); 659 } 660 else specificMasterActionHoldCount_--; 661 } 662 663 /** 664 @brief Master initializes a 180 degree turn. Leads to a "specific master action". 665 */ 666 void ArtificialController::turn180Init() 667 { 668 if(this->state_ != MASTER) return; 669 670 Quaternion orient = this->getControllableEntity()->getOrientation(); 671 672 this->setTargetPosition(this->getControllableEntity()->getPosition() + 1000.0f*orient*WorldEntity::BACK); 673 674 this->specificMasterActionHoldCount_ = 4; 675 676 this->specificMasterAction_ = TURN180; 677 } 678 679 /** 680 @brief Execute the 180 degree turn. Called within tick. 681 */ 682 void ArtificialController::turn180() 683 { 684 Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, this->targetPosition_); 685 686 this->getControllableEntity()->rotateYaw(-2.0f * sgn(coord.x) * coord.x*coord.x); 687 this->getControllableEntity()->rotatePitch(2.0f * sgn(coord.y) * coord.y*coord.y); 688 689 this->getControllableEntity()->moveFrontBack(SPEED_MASTER); 690 } 691 692 /** 693 @brief Master initializes a spin around its looking direction axis. Leads to a "specific master action". 694 */ 695 void ArtificialController::spinInit() 696 { 697 if(this->state_ != MASTER) return; 698 this->specificMasterAction_ = SPIN; 699 this->specificMasterActionHoldCount_ = 10; 700 } 701 702 /** 703 @brief Execute the spin. Called within tick. 704 */ 705 void ArtificialController::spin() 706 { 707 this->moveToTargetPosition(); 708 this->getControllableEntity()->rotateRoll(0.8f); 709 } 710 711 /** 712 @brief Master begins to follow a pawn. Is a "specific master action". 713 @param pawn pawn to follow. 714 @param always follows pawn forever if true (false if omitted). 715 @param secondsToFollow seconds to follow the pawn if always is false. Will follow pawn 100 seconds if omitted (set in header). 716 */ 717 void ArtificialController::followInit(Pawn* pawn, const bool always, const int secondsToFollow) 718 { 719 if (pawn == NULL || this->state_ != MASTER) 720 return; 721 this->specificMasterAction_ = FOLLOW; 722 723 this->setTarget(pawn); 724 if (!always) 725 this->specificMasterActionHoldCount_ = secondsToFollow; 726 else 727 this->specificMasterActionHoldCount_ = INT_MAX; //for now... 728 729 } 730 731 732 /** 733 @brief Master begins to follow a randomly chosen human player of the same team. Is a "specific master action". 734 */ 735 void ArtificialController::followRandomHumanInit() 736 { 737 738 Pawn *humanPawn = NULL; 739 NewHumanController *currentHumanController = NULL; 740 741 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it) 742 { 743 if (!it->getController()) 744 continue; 745 746 currentHumanController = orxonox_cast<NewHumanController*>(it->getController()); 747 if(currentHumanController) 748 { 749 if (!ArtificialController::sameTeam(this->getControllableEntity(), *it, this->getGametype())) continue; 750 humanPawn = *it; 751 break; 752 } 753 } 754 755 if((humanPawn != NULL)) 756 this->followInit(humanPawn); 757 } 758 759 /** 760 @brief Master follows target with adjusted speed. Called within tick. 761 */ 762 void ArtificialController::follow() 763 { 764 if (this->target_) 765 this->moveToPosition(this->target_->getPosition()); 766 else 767 this->specificMasterActionHoldCount_ = 0; 768 /* 769 if (!this->getControllableEntity()) 770 return; 771 772 float distance = (this->target_->getPosition() - this->getControllableEntity()->getPosition()).length(); 773 774 Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, this->target_->getPosition()); 775 776 777 this->getControllableEntity()->rotateYaw(-0.8f * sgn(coord.x) * coord.x*coord.x); 778 this->getControllableEntity()->rotatePitch(0.8f * sgn(coord.y) * coord.y*coord.y); 779 780 float speedDiv = this->getControllableEntity()->getVelocity().squaredLength() - this->target_->getVelocity().squaredLength(); 781 782 orxout() << "~follow distance: " << distance << "SpeedCounter: " << this->speedCounter_ << "~speedDiv: " << speedDiv << endl; 783 if (distance < 800) 784 { 785 if (distance < 200) 786 { 787 this->speedCounter_ -= 0.5f; 788 if(this->speedCounter_ < 0) this->speedCounter_ = 0.0f; 789 this->getControllableEntity()->moveFrontBack(speedCounter_); 790 } else { 791 if(speedDiv < 0) 792 this->speedCounter_ += 0.01f; 793 else 794 this->speedCounter_ -= 0.05f; 795 this->getControllableEntity()->moveFrontBack(speedCounter_); 796 } 797 798 } else { 799 this->speedCounter_ += 0.05f; 800 this->getControllableEntity()->moveFrontBack(speedCounter_ + distance/300.0f); 801 } 802 // if (this->getControllableEntity()->getVelocity().squaredLength() > 50.0f) this->speedCounter_ = 0; 803 804 */ 805 } 806 807 808 /** 809 @brief Slave moving behaviour when master is following a pawn, gets redirected from moveToPosition(const Vector3& target)). Called within tick. 810 */ 811 void ArtificialController::followForSlaves(const Vector3& target) 812 { 813 814 /* 815 if (!this->getControllableEntity() && !this->myMaster_ && this->myMaster_->state_ != FOLLOW && !this->myMaster_->target_) 816 return; 817 818 float distance = (target - this->getControllableEntity()->getPosition()).length(); 819 820 Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target); 821 822 823 this->getControllableEntity()->rotateYaw(-0.8f * sgn(coord.x) * coord.x*coord.x); 824 this->getControllableEntity()->rotatePitch(0.8f * sgn(coord.y) * coord.y*coord.y); 825 826 827 float speedDiv = this->getControllableEntity()->getVelocity().squaredLength() - this->myMaster_->target_->getVelocity().squaredLength(); 828 829 830 if (distance < 800) 831 { 832 if (distance < 200) 833 { 834 this->speedCounter_ -= 5.0f; 835 if(this->speedCounter_ < 0) this->speedCounter_ = 0.0f; 836 this->getControllableEntity()->moveFrontBack(speedCounter_); 837 } else { 838 if(speedDiv < 0) 839 this->speedCounter_ += 0.01f; 840 else 841 this->speedCounter_ -= 0.05f; 842 this->getControllableEntity()->moveFrontBack(speedCounter_); 843 } 844 845 } else { 846 this->speedCounter_ += 0.05f; 847 this->getControllableEntity()->moveFrontBack(speedCounter_ + distance/300.0f); 848 } 849 // if (this->getControllableEntity()->getVelocity().squaredLength() > 50.0f) this->speedCounter_ = 0; 850 */ 851 } 852 853 854 void ArtificialController::setTargetPosition(const Vector3& target) 855 { 856 this->targetPosition_ = target; 857 this->bHasTargetPosition_ = true; 858 } 859 860 void ArtificialController::searchRandomTargetPosition() 861 { 862 this->targetPosition_ = Vector3(rnd(-2000,2000), rnd(-2000,2000), rnd(-2000,2000)); 863 this->bHasTargetPosition_ = true; 864 } 865 866 void ArtificialController::setTarget(Pawn* target) 867 { 868 this->target_ = target; 869 870 if (target) 871 this->targetPosition_ = target->getPosition(); 872 } 873 874 void ArtificialController::searchNewTarget() 875 { 876 if (!this->getControllableEntity()) 877 return; 878 879 this->targetPosition_ = this->getControllableEntity()->getPosition(); 880 this->forgetTarget(); 881 882 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it) 883 { 884 if (ArtificialController::sameTeam(this->getControllableEntity(), static_cast<ControllableEntity*>(*it), this->getGametype())) 885 continue; 886 887 /* So AI won't choose invisible Spaceships as target */ 888 if (!it->getRadarVisibility()) 889 continue; 890 891 if (static_cast<ControllableEntity*>(*it) != this->getControllableEntity()) 892 { 893 float speed = this->getControllableEntity()->getVelocity().length(); 894 Vector3 distanceCurrent = this->targetPosition_ - this->getControllableEntity()->getPosition(); 895 Vector3 distanceNew = it->getPosition() - this->getControllableEntity()->getPosition(); 896 if (!this->target_ || it->getPosition().squaredDistance(this->getControllableEntity()->getPosition()) * (1.5f + acos((this->getControllableEntity()->getOrientation() * WorldEntity::FRONT).dotProduct(distanceNew) / speed / distanceNew.length()) / math::twoPi) 897 < this->targetPosition_.squaredDistance(this->getControllableEntity()->getPosition()) * (1.5f + acos((this->getControllableEntity()->getOrientation() * WorldEntity::FRONT).dotProduct(distanceCurrent) / speed / distanceCurrent.length()) / math::twoPi) + rnd(-250, 250)) 898 { 899 this->target_ = (*it); 900 this->targetPosition_ = it->getPosition(); 901 } 902 } 903 } 904 } 905 906 void ArtificialController::forgetTarget() 907 { 908 this->target_ = 0; 909 this->bShooting_ = false; 910 } 72 } 73 911 74 912 75 void ArtificialController::aimAtTarget() … … 950 113 } 951 114 952 void ArtificialController::targetDied() 953 { 954 this->forgetTarget(); 955 this->searchRandomTargetPosition(); 956 } 957 958 bool ArtificialController::sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype) 959 { 960 if(!entity1 || !entity2) 961 return true; 962 if (entity1 == entity2) 963 return true; 964 965 int team1 = -1; 966 int team2 = -1; 967 968 Controller* controller = 0; 969 if (entity1->getController()) 970 controller = entity1->getController(); 971 else 972 controller = entity1->getXMLController(); 973 if (controller) 974 { 975 ArtificialController* ac = orxonox_cast<ArtificialController*>(controller); 976 if (ac) 977 team1 = ac->getTeam(); 978 } 979 980 if (entity2->getController()) 981 controller = entity2->getController(); 982 else 983 controller = entity2->getXMLController(); 984 if (controller) 985 { 986 ArtificialController* ac = orxonox_cast<ArtificialController*>(controller); 987 if (ac) 988 team2 = ac->getTeam(); 989 } 990 991 TeamDeathmatch* tdm = orxonox_cast<TeamDeathmatch*>(gametype); 992 if (tdm) 993 { 994 if (entity1->getPlayer()) 995 team1 = tdm->getTeam(entity1->getPlayer()); 996 997 if (entity2->getPlayer()) 998 team2 = tdm->getTeam(entity2->getPlayer()); 999 } 1000 1001 Mission* miss = orxonox_cast<Mission*>(gametype); 1002 if (miss) 1003 { 1004 if (entity1->getPlayer()) 1005 team1 = miss->getTeam(entity1->getPlayer()); 1006 1007 if (entity2->getPlayer()) 1008 team2 = miss->getTeam(entity2->getPlayer()); 1009 } 1010 1011 TeamBaseMatchBase* base = 0; 1012 base = orxonox_cast<TeamBaseMatchBase*>(entity1); 1013 if (base) 1014 { 1015 switch (base->getState()) 1016 { 1017 case BaseState::ControlTeam1: 1018 team1 = 0; 1019 break; 1020 case BaseState::ControlTeam2: 1021 team1 = 1; 1022 break; 1023 case BaseState::Uncontrolled: 1024 default: 1025 team1 = -1; 1026 } 1027 } 1028 base = orxonox_cast<TeamBaseMatchBase*>(entity2); 1029 if (base) 1030 { 1031 switch (base->getState()) 1032 { 1033 case BaseState::ControlTeam1: 1034 team2 = 0; 1035 break; 1036 case BaseState::ControlTeam2: 1037 team2 = 1; 1038 break; 1039 case BaseState::Uncontrolled: 1040 default: 1041 team2 = -1; 1042 } 1043 } 1044 1045 DroneController* droneController = 0; 1046 droneController = orxonox_cast<DroneController*>(entity1->getController()); 1047 if (droneController && static_cast<ControllableEntity*>(droneController->getOwner()) == entity2) 1048 return true; 1049 droneController = orxonox_cast<DroneController*>(entity2->getController()); 1050 if (droneController && static_cast<ControllableEntity*>(droneController->getOwner()) == entity1) 1051 return true; 1052 DroneController* droneController1 = orxonox_cast<DroneController*>(entity1->getController()); 1053 DroneController* droneController2 = orxonox_cast<DroneController*>(entity2->getController()); 1054 if (droneController1 && droneController2 && droneController1->getOwner() == droneController2->getOwner()) 1055 return true; 1056 1057 Dynamicmatch* dynamic = orxonox_cast<Dynamicmatch*>(gametype); 1058 if (dynamic) 1059 { 1060 if (dynamic->notEnoughPigs||dynamic->notEnoughKillers||dynamic->notEnoughChasers) {return false;} 1061 1062 if (entity1->getPlayer()) 1063 team1 = dynamic->getParty(entity1->getPlayer()); 1064 1065 if (entity2->getPlayer()) 1066 team2 = dynamic->getParty(entity2->getPlayer()); 1067 1068 if (team1 ==-1 ||team2 ==-1 ) {return false;} 1069 else if (team1 == dynamic->chaser && team2 != dynamic->chaser) {return false;} 1070 else if (team1 == dynamic->piggy && team2 == dynamic->chaser) {return false;} 1071 else if (team1 == dynamic->killer && team2 == dynamic->chaser) {return false;} 1072 else return true; 1073 } 1074 1075 return (team1 == team2 && team1 != -1); 1076 } 1077 115 //****************************************************************************************** NEW 1078 116 /** 1079 117 @brief DoFire is called when a bot should shoot and decides which weapon is used and whether the bot shoots at all. … … 1228 266 1229 267 /** 1230 @brief Adds point of interest depending on context. Further Possibilites: "ForceField", "PortalEndPoint", "MovableEntity", "Dock"268 @brief Adds point of interest depending on context. TODO: Further Possibilites: "ForceField", "PortalEndPoint", "MovableEntity", "Dock" 1231 269 */ 1232 270 void ArtificialController::manageWaypoints() … … 1237 275 this->updatePointsOfInterest("PickupSpawner", 20.0f); // take pickup en passant if there is a default waypoint 1238 276 } 1239 277 1240 278 } -
code/branches/presentation2011/src/orxonox/controllers/ArtificialController.h
r8980 r8992 31 31 32 32 #include "OrxonoxPrereqs.h" 33 34 #include <map> 35 36 #include "util/Math.h" 37 #include "Controller.h" 38 #include "controllers/NewHumanController.h" 39 #include "weaponsystem/WeaponSystem.h" 33 #include "controllers/FormationController.h" 40 34 41 35 namespace orxonox 42 36 { 43 class _OrxonoxExport ArtificialController : public Controller37 class _OrxonoxExport ArtificialController : public FormationController 44 38 { 45 39 public: … … 47 41 virtual ~ArtificialController(); 48 42 49 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);50 51 43 void abandonTarget(Pawn* target); 52 44 53 inline void setTeam(int team) //TODO: write through to controllable entity.54 { this->team_ = team; }55 inline int getTeam() const56 { return this->team_; }57 58 inline void setFormationFlight(bool formation)59 { this->formationFlight_ = formation; }60 inline bool getFormationFlight() const61 { return this->formationFlight_; }62 63 inline void setFormationSize(int size)64 { this->maxFormationSize_ = size; }65 inline int getFormationSize() const66 { return this->maxFormationSize_; }67 68 inline void setPassive(bool passive)69 { this->passive_ = passive; }70 inline bool getPassive() const71 { return this->passive_; }72 73 45 virtual void changedControllableEntity(); 74 75 static void formationflight(const bool form); 76 static void masteraction(const int action); 77 static void followme(); 78 static void passivebehaviour(const bool passive); 79 static void formationsize(const int size); 80 46 //************************************************************************* NEW 81 47 virtual void doFire(); 82 48 void setBotLevel(float level=1.0f); … … 95 61 void manageWaypoints(); 96 62 63 64 97 65 protected: 98 99 int team_; 100 bool formationFlight_; 101 bool passive_; 102 unsigned int maxFormationSize_; 103 int freedomCount_; 104 enum State {SLAVE, MASTER, FREE}; 105 State state_; 106 std::vector<ArtificialController*> slaves_; 107 ArtificialController *myMaster_; 108 enum SpecificMasterAction {NONE, HOLD, SPIN, TURN180, FOLLOW}; 109 SpecificMasterAction specificMasterAction_; 110 int specificMasterActionHoldCount_; 111 float speedCounter_; //for speed adjustment when following 112 113 void moveToPosition(const Vector3& target); 114 void moveToTargetPosition(); 115 void absoluteMoveToPosition(const Vector3& target); 116 117 virtual void positionReached() {} 118 119 void removeFromFormation(); 120 void unregisterSlave(); 121 void searchNewMaster(); 122 void commandSlaves(); 123 void setNewMasterWithinFormation(); 124 125 void freeSlaves(); 126 void forceFreeSlaves(); 127 void loseMasterState(); 128 void forceFreedom(); 129 bool forcedFree(); 130 131 void specificMasterActionHold(); 132 void turn180Init(); 133 void turn180(); 134 void spinInit(); 135 void spin(); 136 void followInit(Pawn* pawn, const bool always = false, const int secondsToFollow = 100); 137 void followRandomHumanInit(); 138 void follow(); 139 void followForSlaves(const Vector3& target); 140 141 void setTargetPosition(const Vector3& target); 142 void searchRandomTargetPosition(); 143 144 void setTarget(Pawn* target); 145 void searchNewTarget(); 146 void forgetTarget(); 66 147 67 void aimAtTarget(); 148 68 149 69 bool isCloseAtTarget(float distance) const; 150 70 bool isLookingAtTarget(float angle) const; 151 152 void targetDied(); 153 154 static bool sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype); // hack 155 void boostControl(); //<! Sets and resets the boost parameter of the spaceship. Bots alternate between boosting and saving boost. 156 157 bool bHasTargetPosition_; 158 Vector3 targetPosition_; 159 WeakPtr<Pawn> target_; 160 bool bShooting_; 161 71 //************************************************************************* NEW 162 72 float botlevel_; //<! Makes the level of a bot configurable. 163 73 enum Mode {DEFAULT, ROCKET, DEFENCE, MOVING};//TODO; implement DEFENCE, MOVING modes … … 165 75 void setPreviousMode(); 166 76 77 167 78 //WEAPONSYSTEM DATA 168 std::map<std::string, int> weaponModes_; //<! Links each "weapon" to it's weaponmode - managed by setupWeapons()79 std::map<std::string, int> weaponModes_; //<! Links each "weapon" to it's weaponmode - managed by setupWeapons() 169 80 //std::vector<int> projectiles_; //<! Displays amount of projectiles of each weapon. - managed by setupWeapons() 170 81 float timeout_; //<! Timeout for rocket usage. (If a rocket misses, a bot should stop using it.) … … 173 84 int getFiremode(std::string name); 174 85 86 175 87 //WAYPOINT DATA 176 88 std::vector<WeakPtr<WorldEntity> > waypoints_; … … 178 90 float squaredaccuracy_; 179 91 WorldEntity* defaultWaypoint_; 92 93 void boostControl(); //<! Sets and resets the boost parameter of the spaceship. Bots alternate between boosting and saving boost. 94 95 private: 180 96 }; 181 97 } -
code/branches/presentation2011/src/orxonox/controllers/CMakeLists.txt
r7163 r8992 9 9 WaypointPatrolController.cc 10 10 DroneController.cc 11 FormationController.cc 11 12 ) -
code/branches/presentation2011/src/orxonox/controllers/FormationController.cc
r8991 r8992 40 40 #include "gametypes/TeamDeathmatch.h" 41 41 #include "gametypes/Dynamicmatch.h" 42 //#include "gametypes/Mission.h" TODO: include mission after merging42 #include "gametypes/Mission.h" TODO: include mission after merging 43 43 #include "gametypes/Gametype.h" 44 44 #include "controllers/WaypointPatrolController.h" … … 962 962 } 963 963 964 /*Mission* miss = orxonox_cast<Mission*>(gametype); //NEW964 Mission* miss = orxonox_cast<Mission*>(gametype); 965 965 if (miss) 966 966 { … … 970 970 if (entity2->getPlayer()) 971 971 team2 = miss->getTeam(entity2->getPlayer()); 972 } */972 } 973 973 974 974 TeamBaseMatchBase* base = 0; … … 1039 1039 } 1040 1040 1041 void FormationController::absoluteMoveToPosition(const Vector3& target) 1042 { 1043 float minDistance = 40.0f; 1044 if (!this->getControllableEntity()) 1045 return; 1046 1047 Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target); 1048 float distance = (target - this->getControllableEntity()->getPosition()).length(); 1049 1050 if (this->target_ || distance > minDistance) 1051 { 1052 // Multiply with ROTATEFACTOR_FREE to make them a bit slower 1053 this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_FREE * sgn(coord.x) * coord.x*coord.x); 1054 this->getControllableEntity()->rotatePitch(ROTATEFACTOR_FREE * sgn(coord.y) * coord.y*coord.y); 1055 this->getControllableEntity()->moveFrontBack(SPEED_FREE); 1056 } 1057 1058 1059 if (distance < minDistance) 1060 { 1061 this->positionReached(); 1062 } 1063 } 1064 1041 1065 } -
code/branches/presentation2011/src/orxonox/controllers/FormationController.h
r8991 r8992 118 118 void moveToPosition(const Vector3& target); 119 119 void moveToTargetPosition(); 120 void absoluteMoveToPosition(const Vector3& target); 120 121 void copyOrientation(const Quaternion& orient); 121 122 void copyTargetOrientation(); -
code/branches/presentation2011/src/orxonox/controllers/HumanController.cc
r8980 r8992 50 50 SetConsoleCommand("HumanController", "rotatePitch", &HumanController::rotatePitch ).addShortcut().setAsInputCommand(); 51 51 SetConsoleCommand("HumanController", "rotateRoll", &HumanController::rotateRoll ).addShortcut().setAsInputCommand(); 52 SetConsoleCommand("HumanController", "toggleFormationFlight", &HumanController::toggleFormationFlight).addShortcut().keybindMode(KeybindMode::OnPress); 53 SetConsoleCommand("HumanController", "FFChangeMode", &HumanController::FFChangeMode).addShortcut().keybindMode(KeybindMode::OnPress); 52 54 SetConsoleCommand("HumanController", __CC_fire_name, &HumanController::fire ).addShortcut().keybindMode(KeybindMode::OnHold); 53 55 SetConsoleCommand("HumanController", "reload", &HumanController::reload ).addShortcut(); … … 69 71 /*static*/ const float HumanController::BOOSTING_TIME = 0.1f; 70 72 71 HumanController::HumanController(BaseObject* creator) : Controller(creator)73 HumanController::HumanController(BaseObject* creator) : FormationController(creator) 72 74 { 73 75 RegisterObject(HumanController); … … 76 78 this->boosting_ = false; 77 79 this->boosting_ = false; 78 80 this->tempMaster=NULL; 79 81 HumanController::localController_s = this; 80 82 this->boostingTimeout_.setTimer(HumanController::BOOSTING_TIME, false, createExecutor(createFunctor(&HumanController::terminateBoosting, this))); 81 83 this->boostingTimeout_.stopTimer(); 84 this->state_=FREE; 82 85 } 83 86 84 87 HumanController::~HumanController() 85 88 { 89 if (HumanController::localController_s) 90 { 91 HumanController::localController_s->removeFromFormation(); 92 } 86 93 HumanController::localController_s = 0; 87 94 } … … 95 102 orxout(internal_warning) << "HumanController, Warning: Using a ControllableEntity without Camera" << endl; 96 103 } 104 105 // commandslaves when Master of a formation 106 if (HumanController::localController_s && HumanController::localController_s->state_==MASTER) 107 { 108 if (HumanController::localController_s->formationMode_ != ATTACK) 109 HumanController::localController_s->commandSlaves(); 110 } 97 111 } 98 112 … … 160 174 { 161 175 if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) 176 { 162 177 HumanController::localController_s->controllableEntity_->fire(firemode); 178 //if human fires, set slaves free. See FormationController::forceFreeSlaves() 179 if (HumanController::localController_s->state_==MASTER && HumanController::localController_s->formationMode_ == NORMAL) 180 { 181 HumanController::localController_s->forceFreeSlaves(); 182 } 183 } 163 184 } 164 185 … … 262 283 } 263 284 285 /** 286 @brief 287 toggle the formation. Not usable, if formationflight is disabled generally (formationFlight_) 288 */ 289 void HumanController::toggleFormationFlight() 290 { 291 if (HumanController::localController_s) 292 { 293 if (!HumanController::localController_s->formationFlight_) 294 { 295 return; //dont use when formationFlight is disabled 296 } 297 if (HumanController::localController_s->state_==MASTER) 298 { 299 HumanController::localController_s->loseMasterState(); 300 orxout(message) <<"FormationFlight disabled "<< endl; 301 } else //SLAVE or FREE 302 { 303 HumanController::localController_s->takeLeadOfFormation(); 304 orxout(message) <<"FormationFlight enabled "<< endl; 305 } 306 307 } 308 309 } 310 311 /** 312 @brief 313 Switch through the different Modes of formationflight. You must be a master of a formation to use. 314 */ 315 void HumanController::FFChangeMode() 316 { 317 if (HumanController::localController_s && HumanController::localController_s->state_==MASTER) 318 { 319 switch (HumanController::localController_s->getFormationMode()) { 320 case NORMAL: 321 HumanController::localController_s->setFormationMode(DEFEND); 322 orxout(message) <<"Mode: DEFEND "<< endl; 323 break; 324 case DEFEND: 325 HumanController::localController_s->setFormationMode(ATTACK); 326 orxout(message) <<"Mode: ATTACK "<< endl; 327 break; 328 case ATTACK: 329 HumanController::localController_s->setFormationMode(NORMAL); 330 orxout(message) <<"Mode: NORMAL "<< endl; 331 break; 332 } 333 } 334 } 335 336 337 //used, when slaves are in DEFEND mode. 338 void HumanController::hit(Pawn* originator, btManifoldPoint& contactpoint, float damage) 339 { 340 if (!this->formationFlight_ || this->state_!=MASTER || this->formationMode_!=DEFEND) return; 341 this->masterAttacked(originator); 342 } 343 264 344 void HumanController::addBots(unsigned int amount) 265 345 { -
code/branches/presentation2011/src/orxonox/controllers/HumanController.h
r8706 r8992 34 34 #include "tools/Timer.h" 35 35 #include "tools/interfaces/Tickable.h" 36 #include " Controller.h"36 #include "FormationController.h" 37 37 38 38 // tolua_begin … … 41 41 class _OrxonoxExport HumanController 42 42 // tolua_end 43 : public Controller, public Tickable43 : public FormationController, public Tickable 44 44 { // tolua_export 45 45 public: … … 74 74 void keepBoosting(void); 75 75 void terminateBoosting(void); 76 76 77 77 78 static void greet(); 78 79 static void switchCamera(); … … 84 85 static void toggleGodMode(); 85 86 static void myposition(); 87 88 static void toggleFormationFlight(); 89 static void FFChangeMode(); 90 virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage); 91 86 92 87 93 static void addBots(unsigned int amount); … … 107 113 Timer boostingTimeout_; // A timer to check whether the player is no longer boosting. 108 114 static const float BOOSTING_TIME; // The time after it is checked, whether the player is no longer boosting. 115 FormationController* tempMaster; 109 116 110 117 }; // tolua_export -
code/branches/presentation2011/src/orxonox/controllers/NewHumanController.cc
r8858 r8992 277 277 } 278 278 279 void NewHumanController::doFire(unsigned int firemode) 279 void NewHumanController::doFire(unsigned int firemode)//TODO?? 280 280 { 281 281 if (!this->controllableEntity_) … … 297 297 void NewHumanController::hit(Pawn* originator, btManifoldPoint& contactpoint, float damage) 298 298 { 299 //Used in HumanController for formationFlight 300 HumanController::hit(originator,contactpoint,damage); 301 299 302 if (this->showDamageOverlay_ && !this->controlPaused_ && this->controllableEntity_ && !this->controllableEntity_->isInMouseLook()) 300 303 {
Note: See TracChangeset
for help on using the changeset viewer.