Changeset 10725 for code/branches/AI_HS15/src/orxonox/controllers
- Timestamp:
- Oct 30, 2015, 11:07:34 PM (9 years ago)
- Location:
- code/branches/AI_HS15/src/orxonox/controllers
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc
r10722 r10725 51 51 52 52 RegisterObject(CommonController); 53 54 53 //this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&LeaderController::action, this))); 55 54 } … … 60 59 } 61 60 61 void CommonController::moveToPosition(const Vector3& target) 62 { 63 if (!this->getControllableEntity()) 64 return; 65 66 Vector2 coord = get2DViewCoordinates(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target); 67 float distance = (target - this->getControllableEntity()->getPosition()).length(); 68 float rotateX = clamp(coord.x * 10, -1.0f, 1.0f); 69 float rotateY = clamp(coord.y * 10, -1.0f, 1.0f); 70 71 72 if (this->target_ || distance > 10) 73 { 74 this->getControllableEntity()->rotateYaw(-1.0f * 0.8f * rotateX); 75 this->getControllableEntity()->rotatePitch(0.8f * rotateY); 76 } 77 78 if (this->target_ && distance < 200 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength()) 79 { 80 this->getControllableEntity()->moveFrontBack(-0.05f); // They don't brake with full power to give the player a chance 81 } 82 else if (distance > 100) 83 this->getControllableEntity()->moveFrontBack(0.8f); 84 85 86 87 if (distance < 100) 88 { 89 this->positionReached(); 90 bHasTargetOrientation_=false; 91 } 92 } 62 93 63 94 -
code/branches/AI_HS15/src/orxonox/controllers/CommonController.h
r10722 r10725 39 39 { 40 40 public: 41 41 enum FormationMode {VEE,FINGER4,DIAMOND, WALL}; 42 virtual void setFormationMode(FormationMode val) 43 { this->formationMode_ = val; } 44 inline FormationMode getFormationMode() const 45 { return this->formationMode_; } 46 42 47 CommonController(Context* context); 43 48 virtual ~CommonController(); … … 45 50 virtual bool setWingman(CommonController* wingman); 46 51 virtual bool hasWingman(); 47 CommonController* myWingman_;52 Vector3* desiredRelativePosition_; 48 53 49 CommonController* myLeader_;50 54 51 55 protected: 56 void moveToPosition(const Vector3& target); 57 virtual void positionReached() {} 58 59 /* void moveToTargetPosition(); 60 void absoluteMoveToPosition(const Vector3& target); 61 void copyOrientation(const Quaternion& orient); 62 void copyTargetOrientation(); 63 64 void spin(); 65 void turn180(); 66 void follow(); 67 void setTargetPosition(const Vector3& target); 68 69 void setTargetOrientation(const Quaternion& orient); 70 void setTargetOrientation(Pawn* target); 71 72 73 74 void setTarget(Pawn* target); 75 76 void searchNewTarget(); 77 void forgetTarget(); 78 79 void targetDied(); 80 */ 81 bool bHasTargetPosition_; 82 Vector3 targetPosition_; 83 bool bHasTargetOrientation_; 84 Quaternion targetOrientation_; 85 86 WeakPtr<ControllableEntity> target_; 87 bool bShooting_; 88 89 FormationMode formationMode_; 90 91 52 92 53 93 //void defaultBehaviour(float maxrand); //<! Helper function for code reusage. Some concrete commands for a bot. -
code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc
r10722 r10725 34 34 35 35 RegisterClass(DivisionController); 36 static const float ACTION_INTERVAL = 1.0f; 36 37 37 38 DivisionController::DivisionController(Context* context) : LeaderController(context) 38 39 { 39 40 RegisterObject(DivisionController); 41 this->setFormationMode(WALL); 42 40 43 bIsDivisionLeader_ = true; 44 this->myFollower_ = 0; 45 this->myWingman_ = 0; 46 this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&DivisionController::action, this))); 47 41 48 } 42 49 43 50 DivisionController::~DivisionController() 44 51 { 45 if (this->isInitialized()) 46 { 47 if (this->myFollower_) 48 this->myFollower_->myDivisionLeader_ = 0; 49 if (this->myWingman_) 50 this->myWingman_->myLeader_ = 0; 51 } 52 } void DivisionController::tick(float dt) 52 53 } 54 void DivisionController::tick(float dt) 53 55 { 54 56 SUPER(DivisionController, tick, dt); 55 57 56 58 } 59 void DivisionController::action() 60 { 61 /* setDesiredPositionOfFollower(); 62 setDesiredPositionOfWingman();*/ 63 } 64 57 65 bool DivisionController::setFollower(LeaderController* myFollower) 58 66 { … … 67 75 } 68 76 } 77 78 /* void DivisionController::setDesiredPositionOfWingman() 79 { 80 if (!this->myWingman_) 81 return; 82 83 switch (this->formationMode_){ 84 case WALL: 85 { 86 myWingman_->desiredRelativePosition_ = new Vector3 (200, 0, 0); 87 break; 88 } 89 case FINGER4: 90 { 91 break; 92 } 93 case VEE: 94 { 95 break; 96 } 97 case DIAMOND: 98 { 99 break; 100 } 101 } 102 103 } 104 void DivisionController::setDesiredPositionOfFollower() 105 { 106 if (!this->myFollower_) 107 return; 108 109 switch (this->formationMode_){ 110 case WALL: 111 { 112 myWingman_->desiredRelativePosition_ = new Vector3 (-200, 0, 0); 113 break; 114 } 115 case FINGER4: 116 { 117 break; 118 } 119 case VEE: 120 { 121 break; 122 } 123 case DIAMOND: 124 { 125 break; 126 } 127 } 128 129 }*/ 69 130 void DivisionController::XMLPort(Element& xmlelement, XMLPort::Mode mode) 70 131 { -
code/branches/AI_HS15/src/orxonox/controllers/DivisionController.h
r10722 r10725 48 48 49 49 //Using british military aircraft formations 50 enum FormationMode {VEE,FINGER4,DIAMOND, WALL}; 51 void setFormationMode(FormationMode val); 52 inline FormationMode getFormationMode() const 53 { return this->formationMode_; } 50 51 54 52 virtual bool setFollower(LeaderController* myFollower); 55 53 virtual bool setWingman(CommonController* wingman) … … 85 83 86 84 protected: 85 void setDesiredPositionOfWingman(); 86 void setDesiredPositionOfFollower(); 87 virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour ~ setting targets. 87 88 88 89 //Target enemy, set by fleet controller. 89 WeakPtr<Pawn> target_; 90 bool bHasTargetPosition_; 91 Vector3 targetPosition_; 92 bool bHasTargetOrientation_; 93 Quaternion targetOrientation_; 94 FormationMode formationMode_; 90 95 91 96 92 … … 99 95 100 96 private: 97 Timer actionTimer_; //<! Regularly calls action(). 98 101 99 }; 102 100 } -
code/branches/AI_HS15/src/orxonox/controllers/LeaderController.h
r10722 r10725 63 63 return true; 64 64 }; 65 LeaderController* myFollower_; 66 LeaderController* myDivisionLeader_; 65 WeakPtr<CommonController> myWingman_; 66 67 WeakPtr<LeaderController> myFollower_; 68 WeakPtr<LeaderController> myDivisionLeader_; 67 69 68 70 … … 75 77 private: 76 78 77 WeakPtr<Pawn> target_;78 79 79 80 -
code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc
r10722 r10725 38 38 { 39 39 RegisterObject(SectionController); 40 this->setFormationMode(WALL); 41 40 42 bIsDivisionLeader_ = false; 41 43 this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&SectionController::action, this))); 42 44 this->myWingman_ = 0; 45 this->myDivisionLeader_ = 0; 46 this->desiredRelativePosition_ = 0; 47 48 orxout(internal_error) << this << "Was created" << endl; 43 49 44 50 } … … 46 52 SectionController::~SectionController() 47 53 { 48 if (this->isInitialized()) 49 { 50 if (this->myDivisionLeader_) 51 this->myDivisionLeader_->myFollower_ = 0; 52 if(this->myWingman_) 53 this->myWingman_->myLeader_ = 0; 54 } 55 } 56 54 55 } 56 /*void SectionController::setDesiredPositionOfWingman() 57 { 58 if (!this->myWingman_) 59 return; 60 61 switch (this->formationMode_){ 62 case WALL: 63 { 64 myWingman_->desiredRelativePosition_ = new Vector3 (-200, 0, 0); 65 break; 66 } 67 case FINGER4: 68 { 69 break; 70 } 71 case VEE: 72 { 73 break; 74 } 75 case DIAMOND: 76 { 77 break; 78 } 79 } 80 81 } 82 */ 57 83 LeaderController* SectionController::findNewDivisionLeader() 58 84 { … … 112 138 LeaderController* newDivisionLeader = findNewDivisionLeader(); 113 139 this->myDivisionLeader_ = newDivisionLeader; 114 /*if (newDivisionLeader)140 if (newDivisionLeader) 115 141 orxout(internal_error) << "new DivisionLeader set" << endl; 116 else 117 orxout(internal_error) << "0 division leader" << endl;*/118 } 119 }142 143 } 144 /* setDesiredPositionOfWingman(); 145 */ } 120 146 /* 121 147 Wingmen and Leaders attack target_, which is a member variable of their classes. … … 132 158 133 159 */ 160 /* void SectionController::keepDivisionTick() 161 { 162 163 164 if (this->myDivisionLeader_ && this->myDivisionLeader_->getControllableEntity() && desiredRelativePosition_) 165 { 166 167 Vector3 desiredAbsolutePosition = ((this->myDivisionLeader_->getControllableEntity()->getWorldPosition()) + 168 (this->myDivisionLeader_->getControllableEntity()->getWorldOrientation()* (*desiredRelativePosition_))); 169 this->moveToPosition (desiredAbsolutePosition); 170 } 171 }*/ 134 172 void SectionController::tick(float dt) 135 {/* 173 { 174 175 176 /* 136 177 if (!this->isActive()) 137 178 return; 138 179 139 180 //--------------------------Stay in division-------------------------- 140 this->keepDivisionTick();*/ 141 /*keepDivisionTick(){ 142 if (this->divisionLeader_ && this->divisionLeader_->getControllableEntity() && desiredRelativePosition_){ 143 Vector3 desiredAbsolutePosition = ((this->divisionLeader_->getControllableEntity()->getWorldPosition()) + 144 (this->divisionLeader_->getControllableEntity()->getWorldOrientation()* (*desiredRelativePosition_))); 145 this->moveToPosition (desiredAbsolutePosition); 146 } 147 } 181 this->keepDivisionTick(); 148 182 */ 149 /*//If ordered to attack -> follow target and shoot150 if (this->bAttackOrder_)151 {152 153 }154 183 //If ordered to move -> move to a target Point 155 184 156 185 //No orders -> Don't move, but shoot at whatever is close, unless Boss is shooting at it. 157 186 //(Section shoots same target, Boss's section shoots another target) 158 { 159 160 }*/ 187 161 188 162 189 //orxout(internal_error) << "my Wingman is " << this->myWingman_ << endl; -
code/branches/AI_HS15/src/orxonox/controllers/SectionController.h
r10722 r10725 53 53 return false; 54 54 } 55 }; 55 } 56 56 57 virtual bool hasWingman() 57 58 { … … 68 69 69 70 protected: 70 71 void setDesiredPositionOfWingman(); 72 void keepDivisionTick(); 71 73 //A division is the biggest block of spaceships. 72 74 //In division one section is leading, the other one always stays on the same position … … 83 85 Timer actionTimer_; //<! Regularly calls action(). 84 86 85 Vector3* desiredRelativePosition_;86 87 87 88 }; -
code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc
r10722 r10725 40 40 RegisterObject(WingmanController); 41 41 this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&WingmanController::action, this))); 42 this->myLeader_ = 0; 43 this->desiredRelativePosition_ = 0; 42 44 } 43 45 44 46 WingmanController::~WingmanController() 45 47 { 46 if (this->myLeader_) 47 this->myLeader_->myWingman_ = 0; 48 48 49 } 49 50 … … 69 70 continue; 70 71 71 72 73 74 75 72 float distance = (it->getControllableEntity()->getPosition() - this->getControllableEntity()->getPosition()).length(); 76 73 if (distance < minDistance && !(it->hasWingman())) … … 79 76 minDistance = distance; 80 77 } 81 /*// is pawn in range? 82 if (distance < RADIUS_TO_SEARCH_FOR_LEADER) 83 { 84 85 if (it->setWingman(this)) 86 return *it; 87 }*/ 78 88 79 } 89 80 if (closestLeader) … … 110 101 else 111 102 { 112 113 //orxout(internal_error) << "already have a Leader" << endl;114 103 115 104 } … … 155 144 }*/ 156 145 157 /* void FormationController::setDesiredPositionOfSlaves() 146 147 /*void WingmanController::keepSectionTick() 158 148 { 159 if (this->state_ != MASTER) 160 return; 161 switch (this->formationMode_){ 162 case ATTACK: 163 { 164 float i = 0; 165 for(std::vector<FormationController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++) 166 { 167 (*it)->desiredRelativePosition_ = new Vector3 ((i-slaves_.size()/2)*200, 0, 0); 168 i++; 169 } 170 break; 171 } 172 case NORMAL: 173 { 174 break; 175 } 176 case DEFEND: 177 { 178 break; 179 } 149 if (this->myLeader_ && this->myLeader_->getControllableEntity()) 150 //orxout(internal_error) << "MOVING" << endl; 151 152 if (this->myLeader_ && this->myLeader_->getControllableEntity() && desiredRelativePosition_) 153 { 154 Vector3 desiredAbsolutePosition = ((this->myLeader_->getControllableEntity()->getWorldPosition()) + 155 (this->myLeader_->getControllableEntity()->getWorldOrientation()* (*desiredRelativePosition_))); 156 this->moveToPosition (desiredAbsolutePosition); 180 157 } 181 182 158 }*/ 183 159 void WingmanController::tick(float dt) 184 160 { 185 //-------------------------------------------------------161 /* //------------------------------------------------------- 186 162 187 /*163 188 164 if (!this->isActive()) 189 165 return; 190 166 //--------------------------Stay in formation-------------------------- 191 if (bFollowLeader_) 167 this->keepSectionTick();*/ 168 169 170 //--------------------------Attack same target as the Leader-------------------------- 171 172 /*if (this->target_) 192 173 { 193 this->keepSectionTick(); 194 195 keepSectionTick(){ 196 if (this->sectionLeader_ && this->sectionLeader_->getControllableEntity() && desiredRelativePosition_){ 197 Vector3 desiredAbsolutePosition = ((this->sectionLeader_->getControllableEntity()->getWorldPosition()) + 198 (this->sectionLeader_->getControllableEntity()->getWorldOrientation()* (*desiredRelativePosition_))); 199 this->moveToPosition (desiredAbsolutePosition); 200 } 201 } 202 203 204 //--------------------------Attack same target as the Leader-------------------------- 205 206 if (this->target_) 207 { 208 this->aimAtTarget(); 209 this->doFire(); 210 } 174 this->aimAtTarget(); 175 this->doFire(); 211 176 } 212 */ 213 //orxout(internal_error) << "I am " << this << endl; 177 */ 178 179 //orxout(internal_error) << "I am " << this << endl; 214 180 215 181 -
code/branches/AI_HS15/src/orxonox/controllers/WingmanController.h
r10722 r10725 57 57 58 58 protected: 59 WeakPtr<CommonController> myLeader_; 59 60 60 61 virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour ~ setting targets. … … 65 66 private: 66 67 //const float ACTION_INTERVAL; 67 68 WeakPtr<Pawn> target_; 68 void keepSectionTick(); 69 69 70 //LeaderController* leader_; 70 71
Note: See TracChangeset
for help on using the changeset viewer.