Changeset 8953 for code/branches/formation/src/orxonox
- Timestamp:
- Nov 30, 2011, 4:09:25 PM (13 years ago)
- Location:
- code/branches/formation/src/orxonox/controllers
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/formation/src/orxonox/controllers/AIController.cc
r8729 r8953 116 116 } 117 117 118 if (this->state_ == SLAVE) 119 { 118 if (this->state_ == SLAVE && this->mode_==ATTACK) 119 { 120 if (!this->target_) 121 { 122 this->searchNewTarget(); 123 } 124 125 // shoot 126 random = rnd(maxrand); 127 if (!(this->passive_) && random < 75 && (this->target_ && !this->bShooting_)) 128 this->bShooting_ = true; 129 130 // stop shooting 131 random = rnd(maxrand); 132 if (random < 25 && (this->bShooting_)) 133 this->bShooting_ = false; 120 134 121 135 } … … 142 156 this->spinInit(); 143 157 144 / / follow a randomly chosen human - a specific Master Action158 /*// follow a randomly chosen human - a specific Master Action 145 159 random = rnd(1000.0f); 146 160 if (random < 1) 147 161 this->followRandomHumanInit(); 148 162 */ 149 163 // lose master status (only if less than 4 slaves in formation) 150 164 random = rnd(maxrand); … … 233 247 } 234 248 235 if (this->state_ == SLAVE )249 if (this->state_ == SLAVE && this->mode_!=ATTACK) 236 250 { 237 251 … … 241 255 } 242 256 243 if (this->state_ == FREE )257 if (this->state_ == FREE || (this->state_==SLAVE && this->mode_==ATTACK) ) 244 258 { 245 259 if (this->target_) -
code/branches/formation/src/orxonox/controllers/ArtificialController.cc
r8939 r8953 28 28 29 29 #include "ArtificialController.h" 30 31 #include <vector>32 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 #include "gametypes/TeamDeathmatch.h"42 #include "gametypes/Dynamicmatch.h"43 32 44 33 -
code/branches/formation/src/orxonox/controllers/ArtificialController.h
r8939 r8953 31 31 32 32 #include "OrxonoxPrereqs.h" 33 34 #include <vector>35 36 #include "util/Math.h"37 #include "Controller.h"38 #include "controllers/NewHumanController.h"39 33 #include "controllers/Masterable.h" 40 34 -
code/branches/formation/src/orxonox/controllers/HumanController.cc
r8948 r8953 51 51 SetConsoleCommand("HumanController", "rotateRoll", &HumanController::rotateRoll ).addShortcut().setAsInputCommand(); 52 52 SetConsoleCommand("HumanController", "toggleFormationFlight", &HumanController::toggleFormationFlight).addShortcut().keybindMode(KeybindMode::OnPress); 53 SetConsoleCommand("HumanController", "FFChangeMode", &HumanController::FFChangeMode).addShortcut().keybindMode(KeybindMode::OnPress); 53 54 SetConsoleCommand("HumanController", __CC_fire_name, &HumanController::fire ).addShortcut().keybindMode(KeybindMode::OnHold); 54 55 SetConsoleCommand("HumanController", "reload", &HumanController::reload ).addShortcut(); … … 105 106 if (HumanController::localController_s && HumanController::localController_s->state_==MASTER) 106 107 { 107 HumanController::localController_s->commandSlaves(); 108 if (HumanController::localController_s->mode_!=ATTACK) 109 HumanController::localController_s->commandSlaves(); 108 110 } 109 111 } … … 274 276 } 275 277 278 /** 279 @brief 280 toggle the formation. Not usable, if formationflight is disabled generally (formationFlight_) 281 */ 276 282 void HumanController::toggleFormationFlight() 277 283 { 278 279 if (HumanController::localController_s) 280 { 284 if (HumanController::localController_s) 285 { 286 if (!HumanController::localController_s->formationFlight_) 287 { 288 return; //dont use when formationFlight is disabled 289 } 281 290 if (HumanController::localController_s->state_==MASTER) 282 291 { 283 HumanController::localController_s->freeSlaves(); 284 HumanController::localController_s->state_=FREE; 292 HumanController::localController_s->loseMasterState(); 285 293 orxout(message) <<"FormationFlight disabled "<< endl; 286 294 } else //SLAVE or FREE … … 294 302 } 295 303 304 /** 305 @brief 306 Switch through the different Modes of formationflight. You must be a master of a formation to use. 307 */ 308 void HumanController::FFChangeMode() 309 { 310 if (HumanController::localController_s && HumanController::localController_s->state_==MASTER) 311 { 312 switch (HumanController::localController_s->getMode()) { 313 case NORMAL: 314 HumanController::localController_s->setMode(DEFEND); 315 orxout(message) <<"Mode: DEFEND "<< endl; 316 break; 317 case DEFEND: 318 HumanController::localController_s->setMode(ATTACK); 319 orxout(message) <<"Mode: ATTACK "<< endl; 320 break; 321 case ATTACK: 322 HumanController::localController_s->setMode(NORMAL); 323 orxout(message) <<"Mode: NORMAL "<< endl; 324 break; 325 } 326 changedMode(); 327 } 328 } 329 330 void HumanController::changedMode() 331 { 332 333 } 334 296 335 void HumanController::addBots(unsigned int amount) 297 336 { -
code/branches/formation/src/orxonox/controllers/HumanController.h
r8948 r8953 74 74 void keepBoosting(void); 75 75 void terminateBoosting(void); 76 76 77 77 78 static void greet(); 78 79 static void switchCamera(); … … 86 87 87 88 static void toggleFormationFlight(); 89 static void FFChangeMode(); 90 static void changedMode(); 88 91 89 92 static void addBots(unsigned int amount); -
code/branches/formation/src/orxonox/controllers/Masterable.cc
r8948 r8953 57 57 58 58 59 static const unsigned int STANDARD_MAX_FORMATION_SIZE = 7;60 static const int RADIUS_TO_SEARCH_FOR_MASTERS = 20000;59 static const unsigned int STANDARD_MAX_FORMATION_SIZE = 9; 60 static const int RADIUS_TO_SEARCH_FOR_MASTERS = 5000; 61 61 static const int FORMATION_LENGTH = 110; 62 62 static const int FORMATION_WIDTH = 110; … … 79 79 80 80 this->state_ = FREE; 81 this->mode_ = NORMAL; 81 82 this->specificMasterAction_ = NONE; 82 83 this->specificMasterActionHoldCount_ = 0; … … 444 445 this->state_ = MASTER; 445 446 this->myMaster_ = 0; 446 orxout(debug_output) << "search new master: no master found, but teammates"<< endl; 447 } 447 orxout(debug_output) << "search new master: no master found, but "<<teamSize<<" teammates"<< endl; 448 } else if (this->state_ != SLAVE) 449 orxout(debug_output) << "search new master: no master found, no teammates..."<< endl; 448 450 } 449 451 /** … … 589 591 if (this->state_==FREE) 590 592 { 591 /*592 float minDistance=(float)RADIUS_TO_SEARCH_FOR_MASTERS;593 Masterable* bestMaster=NULL;594 595 //search nearest Master, store in bestMaster596 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)597 {598 599 //same team? (doesnt work with a HumanPlayer??!?) TODO600 if (!Masterable::sameTeam(this->getControllableEntity(), static_cast<ControllableEntity*>(*it), this->getGametype()))601 continue;602 603 //get Controller604 Controller* controller = 0;605 606 if (it->getController())607 controller = it->getController();608 else if (it->getXMLController())609 controller = it->getXMLController();610 611 if (!controller)612 continue;613 614 //myself?615 if (orxonox_cast<ControllableEntity*>(*it) == this->getControllableEntity())616 continue;617 618 Masterable *newMaster = orxonox_cast<Masterable*>(controller);619 if (!newMaster || newMaster->state_!=MASTER) continue;620 621 float distance= (it->getPosition() - this->getControllableEntity()->getPosition()).length();622 623 if (distance<minDistance)624 {625 minDistance=distance;626 bestMaster=newMaster;627 }628 }629 630 if (bestMaster!=NULL)631 {632 //becom slave of formation633 bestMaster->slaves_.push_back(this);634 this->state_=SLAVE;635 this->myMaster_=bestMaster;636 }637 else638 {639 //no formation found to lead, become master of empty formation640 this->state_=MASTER;641 this->slaves_.clear();642 this->myMaster_=0;643 orxout(debug_output) << this << "no formation found!, empty formation"<< endl;644 return;645 }646 */647 593 searchNewMaster(); 648 594 } … … 681 627 682 628 /** 629 @brief Sets the new mode. If master, set it for all slaves. 630 */ 631 void Masterable::setMode(Mode val) 632 { 633 this->mode_=val; 634 if (this->state_==MASTER) 635 { 636 for(std::vector<Masterable*>::iterator it = slaves_.begin(); it != slaves_.end(); it++) 637 { 638 (*it)->mode_=val; 639 if (val==ATTACK) 640 (*it)->forgetTarget(); 641 } 642 } 643 } 644 645 /** 683 646 @brief Used to continue a "specific master action" for a certain time and resuming normal behaviour after. 684 647 */ … … 935 898 } 936 899 937 938 939 940 941 void Masterable::setMode(Mode mode)942 {943 for (std::vector<Masterable*>::iterator it=slaves_.begin(); it != slaves_.end(); it++)944 {945 //(*it)->myMode_=mode;946 }947 }948 949 Masterable::Mode Masterable::getMode()950 {951 return Masterable::NORMAL;952 }953 954 955 900 bool Masterable::sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype) 956 901 { … … 992 937 if (entity2->getPlayer()) 993 938 team2 = tdm->getTeam(entity2->getPlayer()); 939 return (team1 == team2 && team1 != -1); //temp solution 994 940 } 995 941 -
code/branches/formation/src/orxonox/controllers/Masterable.h
r8939 r8953 88 88 */ 89 89 enum Mode {NORMAL,DEFEND,ATTACK}; 90 90 91 /** 91 @brief set a mode in formation 92 */ 93 void setMode(Mode mode); 94 /** 95 @brief get the current mode 92 @brief Sets the new mode. If master, set it for all slaves. 96 93 */ 97 Mode getMode(); 98 94 void setMode(Mode val); 95 inline Mode getMode() const 96 { return this->mode_; } 97 99 98 protected: 100 99 bool formationFlight_; … … 104 103 int freedomCount_; 105 104 enum State {SLAVE, MASTER, FREE}; 105 106 106 State state_; 107 107 std::vector<Masterable*> slaves_; 108 108 Masterable* myMaster_; 109 110 Mode mode_; 109 111 110 112 enum SpecificMasterAction {NONE, HOLD, SPIN, TURN180, FOLLOW};
Note: See TracChangeset
for help on using the changeset viewer.