Changeset 10722 for code/branches/AI_HS15/src/orxonox
- Timestamp:
- Oct 30, 2015, 12:08:30 PM (9 years ago)
- Location:
- code/branches/AI_HS15/src/orxonox/controllers
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc
r10719 r10722 42 42 return false; 43 43 } 44 bool CommonController::hasWingman() 45 { 46 return true; 47 } 48 44 49 CommonController::CommonController(Context* context) : Controller(context) 45 50 { -
code/branches/AI_HS15/src/orxonox/controllers/CommonController.h
r10719 r10722 44 44 virtual bool isLeader(); 45 45 virtual bool setWingman(CommonController* wingman); 46 virtual bool hasWingman(); 47 CommonController* myWingman_; 46 48 49 CommonController* myLeader_; 47 50 48 51 protected: -
code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc
r10719 r10722 45 45 if (this->isInitialized()) 46 46 { 47 47 if (this->myFollower_) 48 this->myFollower_->myDivisionLeader_ = 0; 49 if (this->myWingman_) 50 this->myWingman_->myLeader_ = 0; 48 51 } 49 52 } void DivisionController::tick(float dt) 50 53 { 51 54 SUPER(DivisionController, tick, dt); 52 55 53 56 } -
code/branches/AI_HS15/src/orxonox/controllers/DivisionController.h
r10719 r10722 65 65 } 66 66 }; 67 virtual bool hasWingman() 68 { 69 if (this->myWingman_) 70 return true; 71 else 72 return false; 73 } 74 virtual bool hasFollower() 75 { 76 if (this->myFollower_) 77 return true; 78 else 79 return false; 80 }; 81 82 67 83 virtual void tick(float dt); //<! Carrying out the targets set in action(). 68 84 69 70 85 71 86 protected: … … 79 94 FormationMode formationMode_; 80 95 81 CommonController* myWingman_; 82 LeaderController* myFollower_; 96 83 97 84 98 -
code/branches/AI_HS15/src/orxonox/controllers/FleetController.cc
r10719 r10722 41 41 this->gameGoal_ = DOMINATE; 42 42 this->goalPosition_ = NULL; 43 this->goalTarget_ = NULL;44 this->goalProtect_ = NULL; 43 /* this->goalTarget_ = NULL; 44 this->goalProtect_ = NULL;*/ 45 45 this->nTicks_ = 0; 46 46 this->bTicked_ = false; -
code/branches/AI_HS15/src/orxonox/controllers/FleetController.h
r10719 r10722 48 48 49 49 #include "worldentities/ControllableEntity.h" 50 #include "worldentities/pawns/SpaceShip.h"51 #include "worldentities/pawns/Pawn.h"52 #include "worldentities/pawns/TeamBaseMatchBase.h"53 54 50 55 51 -
code/branches/AI_HS15/src/orxonox/controllers/LeaderController.h
r10719 r10722 49 49 { 50 50 return true; 51 } 51 }; 52 52 bool bIsDivisionLeader_; 53 53 virtual bool setFollower(LeaderController* myFollower) … … 55 55 return false; 56 56 }; 57 virtual bool bIsDivisionLeader() 58 { 59 return bIsDivisionLeader_; 60 }; 61 virtual bool hasFollower() 62 { 63 return true; 64 }; 65 LeaderController* myFollower_; 66 LeaderController* myDivisionLeader_; 57 67 58 68 -
code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc
r10719 r10722 48 48 if (this->isInitialized()) 49 49 { 50 50 if (this->myDivisionLeader_) 51 this->myDivisionLeader_->myFollower_ = 0; 52 if(this->myWingman_) 53 this->myWingman_->myLeader_ = 0; 51 54 } 52 55 } 53 LeaderController* SectionController::findNewDivisionLeader() 56 57 LeaderController* SectionController::findNewDivisionLeader() 54 58 { 55 59 56 60 if (!this->getControllableEntity()) 57 return NULL;61 return 0; 58 62 59 63 LeaderController* closestLeader = 0; 64 float minDistance = std::numeric_limits<float>::infinity(); 60 65 //go through all pawns 61 66 for (ObjectList<LeaderController>::iterator it = ObjectList<LeaderController>::begin(); it; ++it) 62 67 { 63 68 //0ptr or not DivisionController? 69 if (!(it) || !(it)->bIsDivisionLeader_ || !(it->getControllableEntity())) 70 continue; 64 71 //same team? 65 72 if ((this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam())) … … 72 79 73 80 74 //nullptr or not DivisionController? 75 if (!(it) || !(it)->bIsDivisionLeader_) 76 continue; 81 77 82 78 83 float distance = ((it)->getControllableEntity()->getPosition() - this->getControllableEntity()->getPosition()).length(); 79 80 // is pawn in range? 84 85 if (distance < minDistance && !(it->hasFollower())) 86 { 87 closestLeader = *it; 88 minDistance = distance; 89 } 90 /* // is pawn in range? 81 91 if (distance < RADIUS_TO_SEARCH_FOR_LEADER) 82 92 { … … 84 94 if ((it)->setFollower(this)) 85 95 return (*it); 86 } 96 }*/ 87 97 } 88 return NULL; 98 if (closestLeader) 99 { 100 if (closestLeader->setFollower(this)) 101 return closestLeader; 102 } 103 return 0; 89 104 90 105 } … … 96 111 { 97 112 LeaderController* newDivisionLeader = findNewDivisionLeader(); 98 myDivisionLeader_ = newDivisionLeader;99 /*if (newDivisionLeader)113 this->myDivisionLeader_ = newDivisionLeader; 114 /*if (newDivisionLeader) 100 115 orxout(internal_error) << "new DivisionLeader set" << endl; 101 116 else 102 orxout(internal_error) << " nulldivision leader" << endl;*/117 orxout(internal_error) << "0 division leader" << endl;*/ 103 118 } 104 119 } -
code/branches/AI_HS15/src/orxonox/controllers/SectionController.h
r10719 r10722 54 54 } 55 55 }; 56 virtual bool hasWingman() 57 { 58 if (this->myWingman_) 59 return true; 60 else 61 return false; 62 } 63 56 64 virtual void tick(float dt); //<! Carrying out the targets set in action(). 57 65 58 66 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 59 67 LeaderController* findNewDivisionLeader(); 60 61 62 68 63 69 protected: … … 76 82 private: 77 83 Timer actionTimer_; //<! Regularly calls action(). 78 CommonController* myWingman_; 79 LeaderController* myDivisionLeader_; 84 80 85 Vector3* desiredRelativePosition_; 81 86 -
code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc
r10719 r10722 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"38 31 39 32 namespace orxonox … … 51 44 WingmanController::~WingmanController() 52 45 { 53 } 54 55 /* void WingmanController::XMLPort(Element& xmlelement, XMLPort::Mode mode) 56 { 57 SUPER(WingmanController, XMLPort, xmlelement, mode); 58 59 XMLPortParam(WingmanController, "accuracy", setAccuracy, getAccuracy, xmlelement, mode).defaultValues(100.0f); 60 XMLPortObject(WingmanController, WorldEntity, "waypoints", addWaypoint, getWaypoint, xmlelement, mode); 61 }*/ 46 if (this->myLeader_) 47 this->myLeader_->myWingman_ = 0; 48 } 49 62 50 CommonController* WingmanController::findNewLeader() 63 51 { 64 52 65 53 if (!this->getControllableEntity()) 66 return NULL; 67 68 69 //go through all pawns 54 return 0; 55 56 CommonController* closestLeader = 0; 57 float minDistance = std::numeric_limits<float>::infinity(); 58 70 59 for (ObjectList<CommonController>::iterator it = ObjectList<CommonController>::begin(); it; ++it) 71 60 { 61 //0ptr? 62 if (!it || !it->isLeader() || !(it->getControllableEntity())) 63 continue; 72 64 //same team? 73 if ( (this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam()))65 if (this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam()) 74 66 continue; 75 67 //is equal to this? … … 79 71 80 72 81 //nullptr? 82 if (!it || !it->isLeader()) 83 continue; 73 84 74 85 75 float distance = (it->getControllableEntity()->getPosition() - this->getControllableEntity()->getPosition()).length(); 86 87 // is pawn in range? 76 if (distance < minDistance && !(it->hasWingman())) 77 { 78 closestLeader = *it; 79 minDistance = distance; 80 } 81 /*// is pawn in range? 88 82 if (distance < RADIUS_TO_SEARCH_FOR_LEADER) 89 83 { … … 91 85 if (it->setWingman(this)) 92 86 return *it; 93 } 94 } 95 return NULL; 96 } 87 }*/ 88 } 89 if (closestLeader) 90 { 91 if (closestLeader->setWingman(this)) 92 return closestLeader; 93 } 94 return 0; 95 } 96 97 97 void WingmanController::action() 98 98 { 99 99 //this->target_ = this->sectionTarget_; 100 if (! myLeader_)100 if (!this->myLeader_) 101 101 { 102 102 CommonController* newLeader = findNewLeader(); 103 myLeader_ = newLeader;104 /*if (newLeader)103 this->myLeader_ = newLeader; 104 if (newLeader) 105 105 orxout(internal_error) << "new Leader set" << endl; 106 106 else 107 orxout(internal_error) << " nullleader" << endl;108 */ 107 orxout(internal_error) << "0 leader" << endl; 108 109 109 } 110 110 else 111 111 { 112 112 113 //orxout(internal_error) << "already have a Leader" << endl; 113 114 -
code/branches/AI_HS15/src/orxonox/controllers/WingmanController.h
r10719 r10722 32 32 33 33 #include "controllers/CommonController.h" 34 #include <limits> 34 35 35 36 … … 50 51 return false; 51 52 }; 53 52 54 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 53 55 virtual void tick(float dt); //<! Carrying out the targets set in action(). … … 65 67 66 68 WeakPtr<Pawn> target_; 67 CommonController* myLeader_;68 69 //LeaderController* leader_; 69 70
Note: See TracChangeset
for help on using the changeset viewer.