Changeset 10717 for code/branches/AI_HS15/src/orxonox/controllers
- Timestamp:
- Oct 29, 2015, 11:53:45 AM (9 years ago)
- Location:
- code/branches/AI_HS15/src/orxonox/controllers
- Files:
-
- 2 deleted
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/AI_HS15/src/orxonox/controllers/AIController.cc
r10678 r10717 44 44 { 45 45 RegisterObject(AIController); 46 46 47 this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&AIController::action, this))); 47 48 } … … 61 62 if (this->formationFlight_) 62 63 { 63 //When this is a master and was destroyed, destructor might complain that there are slaves of this, although this was removed from formation64 //race conditions?65 //destructor takes care of slaves anyway, so no need to worry about internal_error66 67 64 68 65 //changed order -> searchNewMaster MUSTN'T be called in SLAVE-state (bugfix for internal-error messages at quit) … … 72 69 73 70 // return to Master after being forced free 74 if (this->freedomCount_ == ACTION_INTERVAL)71 if (this->freedomCount_ == 1) 75 72 { 76 73 this->state_ = SLAVE; 77 this->freedomCount_ = 0; // ACTION_INTERVAL is 1 sec, freedomCount is a remaining time of temp. freedom 78 } 79 } else{ 80 //form a formation 81 if (!this->forcedFree()) 82 this->searchNewMaster(); 83 } 74 this->freedomCount_ = 0; 75 } 76 } 77 84 78 this->defaultBehaviour(maxrand); 85 79 86 80 } 87 81 88 89 82 if (this->state_ == SLAVE && this->formationMode_ == ATTACK) 90 83 { 91 84 // search enemy 92 if ((!this->target_)) 85 random = rnd(maxrand); 86 if (random < (botlevel_*100) && (!this->target_)) 93 87 this->searchNewTarget(); 94 88 95 89 // next enemy 90 random = rnd(maxrand); 91 if (random < (botlevel_*30) && (this->target_)) 92 this->searchNewTarget(); 93 96 94 // shoot 97 if ((this->target_ && !this->bShooting_)) 95 random = rnd(maxrand); 96 if (!(this->passive_) && random < (botlevel_*100) && (this->target_ && !this->bShooting_)) 98 97 this->bShooting_ = true; 99 98 100 99 // stop shooting 101 if (this->bShooting_ && !this->target_) 100 random = rnd(maxrand); 101 if (random < (1-botlevel_)*50 && (this->bShooting_)) 102 102 this->bShooting_ = false; 103 103 … … 106 106 if (this->state_ == MASTER) 107 107 { 108 109 //------------------------------------------------------- 110 //collect data for AI behaviour 111 Vector3* meanOfEnemiesPtr = new Vector3(0.0,0.0,0.0); 112 Vector3* meanOfAlliesPtr = new Vector3(0.0,0.0,0.0); 113 Vector3 meanOfAllies = *meanOfAlliesPtr; 114 Vector3 meanOfEnemies = *meanOfEnemiesPtr; 115 116 117 for (ObjectList<AIController>::iterator it = ObjectList<AIController>::begin(); it; ++it) 118 { 119 120 Gametype* gt=this->getGametype(); 121 if (!gt) 122 { 123 gt=it->getGametype(); 124 } 125 if (!FormationController::sameTeam(this->getControllableEntity(), it->getControllableEntity(),gt)) 126 { 127 enemies_.push_back(*it); 128 } 129 else { 130 allies_.push_back(*it); 131 } 132 } 133 if (enemies_.size() != 0 && allies_.size() != 0){ 134 for (std::vector<WeakPtr<AIController> >::iterator it = enemies_.begin() ; it != enemies_.end(); ++it) 135 meanOfEnemies += (*it)->getControllableEntity()->getWorldPosition(); 136 137 meanOfEnemies /= enemies_.size(); 138 139 for (std::vector<WeakPtr<AIController> >::iterator it = allies_.begin() ; it != allies_.end(); ++it) 140 meanOfAllies += (*it)->getControllableEntity()->getWorldPosition(); 141 142 meanOfAllies /= allies_.size(); 143 144 //orxout(internal_error) << "There are " << enemies_Counter << " enemies_, mean position is " << meanOfEnemies << endl; 145 orxout(internal_error) << "Distance is " << (meanOfEnemies-meanOfAllies).length() << endl; 146 orxout(internal_error) << "mean of allies_ is " << meanOfAllies << ", with a size " << allies_.size() << endl; 147 orxout(internal_error) << "mean of enemies_ is " << meanOfEnemies << ", with a size " << enemies_.size() << endl; 148 } 149 //------------------------------------------------------- 150 151 //Decide which formationMode to choose 152 this->setFormationMode(ATTACK); 153 this->setDesiredPositionOfSlaves(); 154 155 //this->commandSlaves(); 108 this->commandSlaves(); 156 109 157 110 if (this->specificMasterAction_ != NONE) … … 161 114 162 115 // make 180 degree turn - a specific Master Action 163 /*164 116 random = rnd(1000.0f); 165 117 if (random < 5) … … 171 123 this->spinInit(); 172 124 173 */174 125 /*// follow a randomly chosen human - a specific Master Action 175 126 random = rnd(1000.0f); … … 177 128 this->followRandomHumanInit(); 178 129 */ 179 /*180 130 // lose master status (only if less than 4 slaves in formation) 181 131 random = rnd(maxrand); 182 132 if(random < 15/(this->slaves_.size()+1) && this->slaves_.size() < 4 ) 183 133 this->loseMasterState(); 184 */ 185 134 186 135 // look out for outher masters if formation is small 187 136 random = rnd(maxrand); … … 193 142 } 194 143 } 195 allies_.clear(); 196 enemies_.clear(); 144 197 145 } 198 146 199 147 void AIController::tick(float dt) 200 148 { 201 202 149 if (!this->isActive()) 203 150 return; 151 204 152 float random; 205 153 float maxrand = 100.0f / ACTION_INTERVAL; 206 154 ControllableEntity* controllable = this->getControllableEntity(); 207 if (this->state_ == SLAVE && controllable && this->mode_ == DEFAULT)208 {209 210 if (this->myMaster_ && this->myMaster_->getControllableEntity() && desiredRelativePosition_){211 Vector3 desiredAbsolutePosition = this->myMaster_->getControllableEntity()->getWorldPosition() + this->myMaster_->getControllableEntity()->getWorldOrientation()* (*desiredRelativePosition_);212 this->moveToPosition (desiredAbsolutePosition);213 //WorldEntity* waypoint = new WorldEntity(this->getContext());214 //waypoint->setPosition(desiredAbsolutePosition);215 216 //this->addWaypoint(waypoint);217 218 }219 220 }221 155 //DOES: Either move to the waypoint or search for a Point of interest 222 156 if (controllable && this->mode_ == DEFAULT)// bot is ready to move to a target … … 255 189 { 256 190 this->aimAtTarget(); 257 this->follow(); //If a bot is shooting a player, it shouldn't let him go away easily. 191 random = rnd(maxrand); 192 if(this->botlevel_*70 > random && !this->isCloseAtTarget(100)) 193 this->follow(); //If a bot is shooting a player, it shouldn't let him go away easily. 258 194 } 259 195 } … … 316 252 }//END_OF ROCKET MODE 317 253 318 319 254 SUPER(AIController, tick, dt); 320 255 } 321 256 //**********************************************NEW 322 257 void AIController::defaultBehaviour(float maxrand) 323 { 324 if (!this->target_) 325 this->searchNewTarget(); 326 if (!(this->passive_) && (this->target_ && !this->bShooting_)) 327 this->bShooting_ = true; 328 258 { float random; 259 // search enemy 260 random = rnd(maxrand); 261 if (random < (botlevel_* 100) && (!this->target_)) 262 this->searchNewTarget(); 263 264 // forget enemy 265 random = rnd(maxrand); 266 if (random < ((1-botlevel_)*20) && (this->target_)) 267 this->forgetTarget(); 268 269 // next enemy 270 random = rnd(maxrand); 271 if (random < (botlevel_*30) && (this->target_)) 272 this->searchNewTarget(); 273 274 // fly somewhere 275 random = rnd(maxrand); 276 if (random < 50 && (!this->bHasTargetPosition_ && !this->target_)) 277 this->searchRandomTargetPosition(); 278 279 // stop flying 280 random = rnd(maxrand); 281 if (random < 10 && (this->bHasTargetPosition_ && !this->target_)) 282 this->bHasTargetPosition_ = false; 283 284 // fly somewhere else 285 random = rnd(maxrand); 286 if (random < 30 && (this->bHasTargetPosition_ && !this->target_)) 287 this->searchRandomTargetPosition(); 288 289 if (this->state_ == MASTER) // master: shoot 290 { 291 random = rnd(maxrand); 292 if (!(this->passive_) && random < (100*botlevel_) && (this->target_ && !this->bShooting_)) 293 { 294 this->bShooting_ = true; 295 this->forceFreeSlaves(); 296 } 297 } 298 else 299 { 300 // shoot 301 random = rnd(maxrand); 302 if (!(this->passive_) && random < (botlevel_*100) && (this->target_ && !this->bShooting_)) 303 this->bShooting_ = true; 304 } 305 306 // stop shooting 307 random = rnd(maxrand); 308 if (random < ((1 - botlevel_)*50) && (this->bShooting_)) 309 this->bShooting_ = false; 310 311 // boost 312 random = rnd(maxrand); 313 if (random < botlevel_*50 ) 314 this->boostControl(); 315 316 // update Checkpoints 317 /*random = rnd(maxrand); 318 if (this->defaultWaypoint_ && random > (maxrand-10)) 319 this->manageWaypoints(); 320 else //if(random > maxrand-10) //CHECK USABILITY!!*/ 321 if (this->waypoints_.size() == 0 ) 322 this->manageWaypoints(); 329 323 } 330 324 -
code/branches/AI_HS15/src/orxonox/controllers/AIController.h
r10678 r10717 30 30 #define _AIController_H__ 31 31 32 #include "OrxonoxPrereqs.h" 32 #include "OrxonoxPrereqs.h" 33 33 34 #include "util/Math.h"35 34 #include "tools/Timer.h" 36 35 #include "tools/interfaces/Tickable.h" 37 36 #include "ArtificialController.h" 38 39 37 40 38 namespace orxonox … … 56 54 57 55 Timer actionTimer_; //<! Regularly calls action(). 58 std::vector<WeakPtr<AIController> > enemies_, allies_;59 60 56 }; 61 57 } -
code/branches/AI_HS15/src/orxonox/controllers/ArtificialController.cc
r10678 r10717 82 82 void ArtificialController::changedControllableEntity() 83 83 { 84 FormationController::changedControllableEntity(); // super85 86 84 if (!this->getControllableEntity()) 87 85 this->removeFromFormation(); -
code/branches/AI_HS15/src/orxonox/controllers/ArtificialController.h
r10678 r10717 53 53 { return this->botlevel_; } 54 54 static void setAllBotLevel(float level); 55 //WAYPOINT FUNCTIONS `55 //WAYPOINT FUNCTIONS 56 56 void addWaypoint(WorldEntity* waypoint); 57 57 WorldEntity* getWaypoint(unsigned int index) const; … … 74 74 75 75 float botlevel_; //<! Makes the level of a bot configurable. 76 //botLevel_ is never used in XML (so far), is it redundant?77 76 enum Mode {DEFAULT, ROCKET, DEFENCE, MOVING};//TODO; implement DEFENCE, MOVING modes 78 77 Mode mode_; //TODO: replace single value with stack-like implementation: std::vector<Mode> mode_; -
code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc
r10709 r10717 38 38 { 39 39 RegisterObject(DivisionController); 40 bIsDivisionLeader_ = true; 40 41 } 41 42 … … 47 48 } 48 49 } 49 void DivisionController::setLeader(LeaderController* leader)50 bool DivisionController::setFollower(LeaderController* myFollower) 50 51 { 51 this->leader_ = leader; 52 if (!this->myFollower_) 53 { 54 this->myFollower_ = myFollower; 55 return true; 56 } 57 else 58 { 59 return false; 60 } 52 61 } 53 62 /*void DivisionController::XMLPort(Element& xmlelement, XMLPort::Mode mode) -
code/branches/AI_HS15/src/orxonox/controllers/DivisionController.h
r10709 r10717 33 33 34 34 35 #include "util/Math.h" 36 #include "tools/Timer.h" 37 #include "tools/interfaces/Tickable.h" 35 38 36 39 namespace orxonox … … 49 52 inline FormationMode getFormationMode() const 50 53 { return this->formationMode_; } 51 virtual void setLeader(LeaderController* leader);54 virtual bool setFollower(LeaderController* myFollower); 52 55 53 56 … … 63 66 FormationMode formationMode_; 64 67 65 /*void setTargetPosition(const Vector3& target); 66 void searchRandomTargetPosition(); 67 68 void setTargetOrientation(const Quaternion& orient); 69 void setTargetOrientation(Pawn* target); 70 71 virtual void positionReached() {} 72 73 74 75 void setTarget(Pawn* target); 76 77 void searchNewTarget(); 78 void forgetTarget(); 79 80 void targetDied(); 81 bool bShooting_; 82 void aimAtTarget(); 83 84 bool isCloseAtTarget(float distance) const; 85 bool isLookingAtTarget(float angle) const; 86 87 //Has nothing to do with desiredRelativePosition_, 88 //is set by fleet controller. 89 Vector3* desiredAbsolutePosition_; 90 91 enum Maneuver {NONE, SPIN, TURN180}; 92 Maneuver maneuver_; 93 94 void moveToPosition(const Vector3& target); 95 void moveToTargetPosition(); 96 void absoluteMoveToPosition(const Vector3& target); 97 void copyOrientation(const Quaternion& orient); 98 void copyTargetOrientation(); 99 100 void turn180Init(); 101 void spinInit(); 102 void spin(); 103 void turn180();*/ 104 105 LeaderController* leader_; 68 69 LeaderController* myFollower_; 106 70 107 71 -
code/branches/AI_HS15/src/orxonox/controllers/FleetController.cc
r10709 r10717 63 63 { 64 64 65 if (nTicks_ == 30)65 /*if (nTicks_ == 30) 66 66 { 67 67 std::vector<WeakPtr<WingmanController> > wingmen; … … 143 143 nTicks_ += 1; 144 144 145 } 145 }*/ 146 146 SUPER(FleetController, tick, dt); 147 147 -
code/branches/AI_HS15/src/orxonox/controllers/FormationController.cc
r10678 r10717 105 105 orxout(internal_error) << this << " is still master in " << (*it) << endl; 106 106 it->myMaster_ = 0; 107 it->state_ = FREE;108 107 } 109 108 … … 278 277 } 279 278 280 Vector2 coord = get2DView Coordinates(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);279 Vector2 coord = get2DViewcoordinates(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target); 281 280 float distance = (target - this->getControllableEntity()->getPosition()).length(); 282 281 float rotateX = clamp(coord.x * 10, -1.0f, 1.0f); … … 473 472 Vector3 dest = this->getControllableEntity()->getPosition(); 474 473 475 // only1 slave: follow474 // 1 slave: follow 476 475 if (this->slaves_.size() == 1) 477 476 { … … 703 702 } 704 703 } 705 /**706 @brief If master, set the desired relative position of slaves (Vector3) in respect to a master for all the slaves.707 */708 void FormationController::setDesiredPositionOfSlaves()709 {710 if (this->state_ != MASTER)711 return;712 switch (this->formationMode_){713 case ATTACK:714 {715 float i = 0;716 for(std::vector<FormationController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++)717 {718 (*it)->desiredRelativePosition_ = new Vector3 ((i-slaves_.size()/2)*200, 0, 0);719 i++;720 }721 break;722 }723 case NORMAL:724 {725 break;726 }727 case DEFEND:728 {729 break;730 }731 }732 733 }734 704 735 705 /** … … 1099 1069 return; 1100 1070 1101 Vector2 coord = get2DView Coordinates(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);1071 Vector2 coord = get2DViewcoordinates(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target); 1102 1072 float distance = (target - this->getControllableEntity()->getPosition()).length(); 1103 1073 … … 1117 1087 } 1118 1088 1119 void FormationController::changedControllableEntity()1120 {1121 Controller::changedControllableEntity(); // super1122 1123 // when changing the controllable entity, ensure that the controller does not use the new entity as target1124 if (this->target_ && this->getControllableEntity() == static_cast<ControllableEntity*>(this->target_))1125 this->forgetTarget();1126 }1127 1089 } -
code/branches/AI_HS15/src/orxonox/controllers/FormationController.h
r10678 r10717 70 70 { return this->maxFormationSize_; } 71 71 72 /**73 @brief If master, set the desired position of slaves (Vector2) for all the slaves.74 */75 void setDesiredPositionOfSlaves();76 72 77 73 inline void setPassive(bool passive) … … 96 92 inline FormationMode getFormationMode() const 97 93 { return this->formationMode_; } 98 94 99 95 virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage); 100 96 … … 103 99 FormationController* getSlave( void ) { return this->slaves_.back(); } 104 100 105 virtual void changedControllableEntity();106 107 101 protected: 108 Vector3* desiredRelativePosition_;109 102 bool formationFlight_; 110 103 bool passive_; … … 185 178 #endif /* _FormationController_h__ */ 186 179 180 -
code/branches/AI_HS15/src/orxonox/controllers/LeaderController.cc
r10709 r10717 30 30 31 31 32 33 32 namespace orxonox 34 33 { … … 36 35 RegisterClass(LeaderController); 37 36 38 LeaderController::LeaderController(Context* context) : WingmanController(context) 37 static const int RADIUS_TO_SEARCH_FOR_LEADER = 3000; 38 39 LeaderController::LeaderController(Context* context) : CommonController(context) 39 40 { 40 41 41 42 RegisterObject(LeaderController); 43 bIsDivisionLeader_ = false; 44 42 45 //this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&LeaderController::action, this))); 43 46 } … … 48 51 } 49 52 53 LeaderController* LeaderController::findNewDivisionLeader() 54 { 55 56 if (!this->getControllableEntity()) 57 return NULL; 58 59 60 //go through all pawns 61 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it) 62 { 63 64 //same team? 65 if (!(this->getControllableEntity()->getTeam() != static_cast<ControllableEntity*>(*it)->getTeam())) 66 continue; 67 68 //Does it have a Controller? 69 Controller* controller = 0; 70 71 if (it->getController()) 72 controller = it->getController(); 73 else if (it->getXMLController()) 74 controller = it->getXMLController(); 75 76 if (!controller) 77 continue; 78 79 //is equal to this? 80 if (orxonox_cast<ControllableEntity*>(*it) == this->getControllableEntity()) 81 continue; 82 83 84 LeaderController* newLeader = orxonox_cast<LeaderController*>(controller); 85 86 //nullptr or not DivisionController? 87 if (!newLeader || !newLeader->bIsDivisionLeader_) 88 continue; 89 90 float distance = (it->getPosition() - this->getControllableEntity()->getPosition()).length(); 91 92 // is pawn in range? 93 if (distance < RADIUS_TO_SEARCH_FOR_LEADER) 94 { 95 96 if (newLeader->setFollower(this)) 97 return newLeader; 98 } 99 } 100 return NULL; 101 102 } 50 103 void LeaderController::action() 51 104 { 52 105 //this->target_ = this->sectionTarget_; 106 if (!myDivisionLeader_) 107 { 108 LeaderController* newDivisionLeader = findNewDivisionLeader(); 109 myDivisionLeader_ = newDivisionLeader; 110 orxout(internal_error) << "new DivisionLeader set" << endl; 111 } 53 112 } 54 113 /* … … 94 153 }*/ 95 154 96 orxout(internal_error) << "my Wingman is " << this-> wingman_ << endl;155 orxout(internal_error) << "my Wingman is " << this->myWingman_ << endl; 97 156 98 157 SUPER(LeaderController, tick, dt); 99 158 } 100 voidLeaderController::setWingman(WingmanController* wingman)159 bool LeaderController::setWingman(WingmanController* wingman) 101 160 { 102 this->wingman_ = wingman; 161 if (!this->myWingman_) 162 { 163 this->myWingman_ = wingman; 164 return true; 165 } 166 else 167 { 168 return false; 169 } 170 } 171 bool LeaderController::isLeader() 172 { 173 return true; 103 174 } 104 175 //**********************************************NEW -
code/branches/AI_HS15/src/orxonox/controllers/LeaderController.h
r10709 r10717 30 30 #define _LeaderController_H__ 31 31 32 #include "controllers/CommonController.h" 32 33 #include "controllers/WingmanController.h" 33 34 34 35 35 36 #include "util/Math.h" 37 #include "tools/Timer.h" 38 #include "tools/interfaces/Tickable.h" 36 39 37 40 namespace orxonox 38 41 { 39 class _OrxonoxExport LeaderController : public WingmanController42 class _OrxonoxExport LeaderController : public CommonController, public Tickable 40 43 { 41 44 public: … … 43 46 LeaderController(Context* context); 44 47 virtual ~LeaderController(); 45 virtual void setWingman(WingmanController* wingman); 48 virtual bool isLeader(); 49 50 virtual bool setWingman(WingmanController* wingman); 46 51 virtual void tick(float dt); //<! Carrying out the targets set in action(). 47 52 48 53 protected: 49 54 50 55 LeaderController* findNewDivisionLeader(); 56 57 bool bIsDivisionLeader_; 51 58 52 59 virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour ~ setting targets. … … 57 64 WeakPtr<Pawn> target_; 58 65 59 WingmanController* wingman_;60 66 WingmanController* myWingman_; 67 LeaderController* myDivisionLeader_; 61 68 //Timer actionTimer_; //<! Regularly calls action(). 62 69 -
code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc
r10709 r10717 29 29 #include "WingmanController.h" 30 30 31 #include "core/CoreIncludes.h" 32 33 #include "core/XMLPort.h" 34 #include "core/command/ConsoleCommandIncludes.h" 35 36 #include "worldentities/ControllableEntity.h" 37 #include "worldentities/pawns/Pawn.h" 31 38 32 39 namespace orxonox … … 34 41 35 42 RegisterClass(WingmanController); 36 37 WingmanController::WingmanController(Context* context) : Controller(context) 43 static const int RADIUS_TO_SEARCH_FOR_LEADER = 3000; 44 45 WingmanController::WingmanController(Context* context) : CommonController(context) 38 46 { 39 47 RegisterObject(WingmanController); … … 52 60 XMLPortObject(WingmanController, WorldEntity, "waypoints", addWaypoint, getWaypoint, xmlelement, mode); 53 61 }*/ 62 CommonController* WingmanController::findNewLeader() 63 { 64 65 if (!this->getControllableEntity()) 66 return NULL; 67 68 69 //go through all pawns 70 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it) 71 { 72 73 //same team? 74 if (!(this->getControllableEntity()->getTeam() != static_cast<ControllableEntity*>(*it)->getTeam())) 75 continue; 76 77 //Does it have a Controller? 78 Controller* controller = 0; 79 80 if (it->getController()) 81 controller = it->getController(); 82 else if (it->getXMLController()) 83 controller = it->getXMLController(); 84 85 if (!controller) 86 continue; 87 88 //is equal to this? 89 if (orxonox_cast<ControllableEntity*>(*it) == this->getControllableEntity()) 90 continue; 91 92 93 CommonController* newLeader = orxonox_cast<CommonController*>(controller); 94 95 //nullptr? 96 if (!newLeader || !newLeader->isLeader()) 97 continue; 98 99 float distance = (it->getPosition() - this->getControllableEntity()->getPosition()).length(); 100 101 // is pawn in range? 102 if (distance < RADIUS_TO_SEARCH_FOR_LEADER) 103 { 104 105 if (newLeader->setWingman(this)) 106 return newLeader; 107 } 108 } 109 return NULL; 110 } 111 bool WingmanController::isLeader() 112 { 113 return false; 114 } 54 115 void WingmanController::action() 55 116 { 56 117 //this->target_ = this->sectionTarget_; 118 if (!myLeader_) 119 { 120 CommonController* newLeader = findNewLeader(); 121 myLeader_ = newLeader; 122 orxout(internal_error) << "new Leader set" << endl; 123 } 57 124 } 58 125 59 126 void WingmanController::tick(float dt) 60 {/* 127 { 128 //------------------------------------------------------- 129 /*//collect data for AI behaviour 130 Vector3* meanOfEnemiesPtr = new Vector3(0.0,0.0,0.0); 131 Vector3* meanOfAlliesPtr = new Vector3(0.0,0.0,0.0); 132 Vector3 meanOfAllies = *meanOfAlliesPtr; 133 Vector3 meanOfEnemies = *meanOfEnemiesPtr; 134 135 136 for (ObjectList<AIController>::iterator it = ObjectList<AIController>::begin(); it; ++it) 137 { 138 139 Gametype* gt=this->getGametype(); 140 if (!gt) 141 { 142 gt=it->getGametype(); 143 } 144 if (!FormationController::sameTeam(this->getControllableEntity(), it->getControllableEntity(),gt)) 145 { 146 enemies_.push_back(*it); 147 } 148 else { 149 allies_.push_back(*it); 150 } 151 } 152 if (enemies_.size() != 0 && allies_.size() != 0){ 153 for (std::vector<WeakPtr<AIController> >::iterator it = enemies_.begin() ; it != enemies_.end(); ++it) 154 meanOfEnemies += (*it)->getControllableEntity()->getWorldPosition(); 155 156 meanOfEnemies /= enemies_.size(); 157 158 for (std::vector<WeakPtr<AIController> >::iterator it = allies_.begin() ; it != allies_.end(); ++it) 159 meanOfAllies += (*it)->getControllableEntity()->getWorldPosition(); 160 161 meanOfAllies /= allies_.size(); 162 163 //orxout(internal_error) << "There are " << enemies_Counter << " enemies_, mean position is " << meanOfEnemies << endl; 164 orxout(internal_error) << "Distance is " << (meanOfEnemies-meanOfAllies).length() << endl; 165 orxout(internal_error) << "mean of allies_ is " << meanOfAllies << ", with a size " << allies_.size() << endl; 166 orxout(internal_error) << "mean of enemies_ is " << meanOfEnemies << ", with a size " << enemies_.size() << endl; 167 }*/ 168 /* 61 169 if (!this->isActive()) 62 170 return; … … 83 191 }*/ 84 192 //orxout(internal_error) << "I am " << this << endl; 193 194 /* void FormationController::setDesiredPositionOfSlaves() 195 { 196 if (this->state_ != MASTER) 197 return; 198 switch (this->formationMode_){ 199 case ATTACK: 200 { 201 float i = 0; 202 for(std::vector<FormationController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++) 203 { 204 (*it)->desiredRelativePosition_ = new Vector3 ((i-slaves_.size()/2)*200, 0, 0); 205 i++; 206 } 207 break; 208 } 209 case NORMAL: 210 { 211 break; 212 } 213 case DEFEND: 214 { 215 break; 216 } 217 } 218 219 }*/ 85 220 86 221 SUPER(WingmanController, tick, dt); -
code/branches/AI_HS15/src/orxonox/controllers/WingmanController.h
r10709 r10717 31 31 32 32 33 #include "controllers/Co ntroller.h"33 #include "controllers/CommonController.h" 34 34 35 35 36 #include "OrxonoxPrereqs.h"37 #include "core/class/Super.h"38 #include "core/CoreIncludes.h"39 #include "core/XMLPort.h"40 #include "core/command/ConsoleCommandIncludes.h"41 #include "core/command/Executor.h"42 43 #include <vector>44 36 #include "util/Math.h" 45 #include <climits>46 47 37 #include "tools/Timer.h" 48 38 #include "tools/interfaces/Tickable.h" 49 50 #include "worldentities/ControllableEntity.h"51 #include "worldentities/pawns/SpaceShip.h"52 #include "worldentities/pawns/Pawn.h"53 #include "worldentities/pawns/TeamBaseMatchBase.h"54 55 #include "gametypes/TeamDeathmatch.h"56 #include "gametypes/Dynamicmatch.h"57 #include "gametypes/Mission.h"58 #include "gametypes/Gametype.h"59 60 39 61 40 62 41 namespace orxonox 63 42 { 64 class _OrxonoxExport WingmanController : public Co ntroller, public Tickable43 class _OrxonoxExport WingmanController : public CommonController, public Tickable 65 44 { 66 45 public: 67 46 WingmanController(Context* context); 68 47 virtual ~WingmanController(); 69 //virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 48 virtual bool isLeader(); 49 //virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 70 50 virtual void tick(float dt); //<! Carrying out the targets set in action(). 71 51 72 52 protected: 53 CommonController* findNewLeader(); 54 73 55 virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour ~ setting targets. 74 56 //void defaultBehaviour(float maxrand); //<! Helper function for code reusage. Some concrete commands for a bot. … … 80 62 81 63 WeakPtr<Pawn> target_; 82 64 CommonController* myLeader_; 83 65 //LeaderController* leader_; 84 66
Note: See TracChangeset
for help on using the changeset viewer.