Changeset 10729 for code/branches/AI_HS15
- Timestamp:
- Oct 31, 2015, 12:20:00 PM (9 years ago)
- Location:
- code/branches/AI_HS15
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/AI_HS15/data/levels/AITest.oxw
r10725 r10729 32 32 33 33 <Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0"/> 34 <SpawnPoint team=0 position="1000,1000,-1000" lookat=" 0,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff />34 <SpawnPoint team=0 position="1000,1000,-1000" lookat="1,1,-1" spawnclass=SpaceShip pawndesign=spaceshipassff /> 35 35 <!--> 36 36 … … 80 80 </controller> 81 81 </SpaceShip> 82 <SpaceShip position="1000, 1 000, -1300 ?>" lookat="0,0,0">82 <SpaceShip position="1000, 1500, -1300 ?>" lookat="0,0,0"> 83 83 <templates> 84 84 <Template link=spaceshipassff /> … … 89 89 </controller> 90 90 </SpaceShip> 91 <SpaceShip position="1000, 1 000, -1700 ?>" lookat="0,0,0">91 <SpaceShip position="1000, 1500, -1700 ?>" lookat="0,0,0"> 92 92 <templates> 93 93 <Template link=spaceshipassff /> -
code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc
r10725 r10729 32 32 33 33 RegisterClass(CommonController); 34 static const float SPEED = 0.6f; 35 static const float ROTATEFACTOR = 0.2f; 34 36 37 /*static const float SPEED_FREE = 0.8f; 38 static const float ROTATEFACTOR_FREE = 0.8f;*/ 35 39 36 40 bool CommonController::setWingman (CommonController* wingman) … … 51 55 52 56 RegisterObject(CommonController); 53 //this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&LeaderController::action, this)));54 57 } 55 58 … … 58 61 { 59 62 } 63 //copy the Roll orientation of given Quaternion. 64 void CommonController::copyOrientation(const Quaternion& orient) 65 { 66 //roll angle difference in radian 67 float diff=orient.getRoll(false).valueRadians()-(this->getControllableEntity()->getOrientation().getRoll(false).valueRadians()); 68 while(diff>math::twoPi) diff-=math::twoPi; 69 while(diff<-math::twoPi) diff+=math::twoPi; 70 this->getControllableEntity()->rotateRoll(-diff); 71 72 73 74 } 75 void CommonController::setTargetPosition(const Vector3& target) 76 { 77 this->targetPosition_ = target; 78 this->bHasTargetPosition_ = true; 79 } 80 81 void CommonController::copyTargetOrientation() 82 { 83 if (bHasTargetOrientation_) 84 { 85 copyOrientation(targetOrientation_); 86 } 87 } 88 void CommonController::setTargetOrientation(const Quaternion& orient) 89 { 90 this->targetOrientation_=orient; 91 this->bHasTargetOrientation_=true; 92 } 93 void CommonController::setTargetOrientation(ControllableEntity* target) 94 { 95 if (target) 96 setTargetOrientation(target->getOrientation()); 97 } 98 60 99 61 100 void CommonController::moveToPosition(const Vector3& target) … … 63 102 if (!this->getControllableEntity()) 64 103 return; 104 105 //100 is (so far) the smallest tolerance (empirically found) that can be reached, 106 //with smaller distance spaceships can't reach position and go circles around it instead 107 int tolerance = 100; 65 108 66 Vector2 coord = get2DViewCoordinates(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target); 109 ControllableEntity* entity = this->getControllableEntity(); 110 Vector2 coord = get2DViewCoordinates 111 (entity->getPosition(), 112 entity->getOrientation() * WorldEntity::FRONT, 113 entity->getOrientation() * WorldEntity::UP, 114 target); 115 67 116 float distance = (target - this->getControllableEntity()->getPosition()).length(); 117 118 //rotates should be in range [-1,+1], clamp cuts off all that is not 68 119 float rotateX = clamp(coord.x * 10, -1.0f, 1.0f); 69 120 float rotateY = clamp(coord.y * 10, -1.0f, 1.0f); 70 121 71 122 72 if ( this->target_ || distance > 10)123 if (distance > tolerance) 73 124 { 74 this->getControllableEntity()->rotateYaw(-1.0f * 0.8f * rotateX); 75 this->getControllableEntity()->rotatePitch(0.8f * rotateY); 125 //Yaw and Pitch are enough to start facing the target 126 this->getControllableEntity()->rotateYaw(-2.0f * ROTATEFACTOR * rotateX); 127 this->getControllableEntity()->rotatePitch(2.0f * ROTATEFACTOR * rotateY); 128 129 //300 works, maybe less is better 130 if (distance < 300) 131 { 132 //Change roll when close. When Spaceship faces target, roll doesn't affect it's trajectory 133 //It's important that roll is not changed in the process of changing yaw and pitch 134 //Wingmen won't face same direction as Leaders, but when Leaders start moving 135 //Yaw and Pitch will adapt. 136 if (bHasTargetOrientation_) 137 { 138 copyTargetOrientation(); 139 } 140 } 141 this->getControllableEntity()->moveFrontBack(1.2f*SPEED); 142 } 143 else 144 { 145 bHasTargetPosition_ = false; 146 bHasTargetOrientation_ = false; 76 147 } 77 148 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 } 149 150 } 151 void CommonController::moveToTargetPosition() 152 { 153 this->moveToPosition(this->targetPosition_); 92 154 } 93 155 -
code/branches/AI_HS15/src/orxonox/controllers/CommonController.h
r10725 r10729 39 39 { 40 40 public: 41 static const float ACTION_INTERVAL = 1.0f; 42 41 43 enum FormationMode {VEE,FINGER4,DIAMOND, WALL}; 42 44 virtual void setFormationMode(FormationMode val) … … 50 52 virtual bool setWingman(CommonController* wingman); 51 53 virtual bool hasWingman(); 52 Vector3* desiredRelativePosition_;53 54 55 56 void setTargetOrientation(const Quaternion& orient); 57 void setTargetOrientation(ControllableEntity* target); 58 void setTargetPosition(const Vector3& target); 54 59 55 60 protected: … … 57 62 virtual void positionReached() {} 58 63 59 /* void moveToTargetPosition();60 void absoluteMoveToPosition(const Vector3& target);64 65 void moveToTargetPosition(); 61 66 void copyOrientation(const Quaternion& orient); 62 67 void copyTargetOrientation(); 63 68 64 void spin();65 void turn180();66 void follow();67 void setTargetPosition(const Vector3& target);68 69 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 70 bool bHasTargetPosition_; 82 71 Vector3 targetPosition_; … … 91 80 92 81 93 //void defaultBehaviour(float maxrand); //<! Helper function for code reusage. Some concrete commands for a bot.94 82 95 83 private: 96 84 97 //Timer actionTimer_; //<! Regularly calls action().98 85 99 86 }; -
code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc
r10725 r10729 34 34 35 35 RegisterClass(DivisionController); 36 static const float ACTION_INTERVAL = 1.0f;37 36 38 37 DivisionController::DivisionController(Context* context) : LeaderController(context) … … 45 44 this->myWingman_ = 0; 46 45 this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&DivisionController::action, this))); 46 47 /*Vector3* pos = new Vector3(500,500,-500); 48 this->setTargetPosition(*pos);*/ 47 49 48 50 } … … 54 56 void DivisionController::tick(float dt) 55 57 { 58 if (this->bHasTargetPosition_) 59 { 60 this->moveToTargetPosition(); 61 } 62 56 63 SUPER(DivisionController, tick, dt); 57 64 … … 59 66 void DivisionController::action() 60 67 { 61 /* setDesiredPositionOfFollower();62 set DesiredPositionOfWingman();*/68 setTargetPositionOfFollower(); 69 setTargetPositionOfWingman(); 63 70 } 64 71 … … 76 83 } 77 84 78 /* void DivisionController::setDesiredPositionOfWingman()85 void DivisionController::setTargetPositionOfWingman() 79 86 { 80 87 if (!this->myWingman_) 81 88 return; 82 89 Vector3* targetRelativePositionOfWingman; 83 90 switch (this->formationMode_){ 84 91 case WALL: 85 92 { 86 myWingman_->desiredRelativePosition_ = new Vector3 (200, 0, 0);93 targetRelativePositionOfWingman = new Vector3 (400, 0, 0); 87 94 break; 88 95 } … … 100 107 } 101 108 } 109 Quaternion orient = this->getControllableEntity()->getWorldOrientation(); 110 111 Vector3 targetAbsolutePositionOfWingman = ((this->getControllableEntity()->getWorldPosition()) + 112 (this->getControllableEntity()->getWorldOrientation()* (*targetRelativePositionOfWingman))); 113 114 myWingman_->setTargetOrientation(orient); 115 myWingman_->setTargetPosition(targetAbsolutePositionOfWingman); 102 116 103 117 } 104 void DivisionController::set DesiredPositionOfFollower()118 void DivisionController::setTargetPositionOfFollower() 105 119 { 106 120 if (!this->myFollower_) 107 121 return; 108 122 Vector3* targetRelativePositionOfFollower; 109 123 switch (this->formationMode_){ 110 124 case WALL: 111 125 { 112 myWingman_->desiredRelativePosition_ = new Vector3 (-200, 0, 0);126 targetRelativePositionOfFollower = new Vector3 (-400, 0, 0); 113 127 break; 114 128 } … … 126 140 } 127 141 } 142 Quaternion orient = this->getControllableEntity()->getWorldOrientation(); 143 144 Vector3 targetAbsolutePositionOfFollower = ((this->getControllableEntity()->getWorldPosition()) + 145 (this->getControllableEntity()->getWorldOrientation()* (*targetRelativePositionOfFollower))); 146 147 myFollower_->setTargetOrientation(orient); 148 myFollower_->setTargetPosition(targetAbsolutePositionOfFollower); 128 149 129 } */150 } 130 151 void DivisionController::XMLPort(Element& xmlelement, XMLPort::Mode mode) 131 152 { -
code/branches/AI_HS15/src/orxonox/controllers/DivisionController.h
r10725 r10729 51 51 52 52 virtual bool setFollower(LeaderController* myFollower); 53 virtual bool setWingman(CommonController* wingman)53 virtual bool setWingman(CommonController* cwingman) 54 54 { 55 WeakPtr<WingmanController> wingman = orxonox_cast<WingmanController*>(cwingman); 55 56 if (!this->myWingman_) 56 57 { … … 83 84 84 85 protected: 85 void set DesiredPositionOfWingman();86 void set DesiredPositionOfFollower();86 void setTargetPositionOfWingman(); 87 void setTargetPositionOfFollower(); 87 88 virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour ~ setting targets. 88 89 //Target enemy, set by fleet controller.90 91 92 93 94 95 89 96 90 private: -
code/branches/AI_HS15/src/orxonox/controllers/LeaderController.cc
r10719 r10729 47 47 RegisterObject(LeaderController); 48 48 49 //this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&LeaderController::action, this)));50 49 } 51 50 52 51 53 52 LeaderController::~LeaderController() 54 53 { 55 54 } 56 55 57 58 //**********************************************NEW59 /* void LeaderController::defaultBehaviour(float maxrand)60 {61 62 }*/63 56 64 57 } -
code/branches/AI_HS15/src/orxonox/controllers/LeaderController.h
r10725 r10729 42 42 { 43 43 public: 44 static const int RADIUS_TO_SEARCH_FOR_LEADER = 3000;45 44 46 45 LeaderController(Context* context); … … 63 62 return true; 64 63 }; 65 WeakPtr< CommonController> myWingman_;64 WeakPtr<WingmanController> myWingman_; 66 65 67 66 WeakPtr<LeaderController> myFollower_; … … 70 69 71 70 protected: 72 73 74 75 //void defaultBehaviour(float maxrand); //<! Helper function for code reusage. Some concrete commands for a bot.76 71 77 72 private: 78 73 79 80 81 //Timer actionTimer_; //<! Regularly calls action().82 83 74 }; 84 75 } -
code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc
r10725 r10729 33 33 34 34 RegisterClass(SectionController); 35 static const float ACTION_INTERVAL = 1.0f;36 35 37 36 SectionController::SectionController(Context* context) : LeaderController(context) 38 37 { 39 38 RegisterObject(SectionController); 40 39 this->setFormationMode(WALL); 41 40 42 41 bIsDivisionLeader_ = false; … … 44 43 this->myWingman_ = 0; 45 44 this->myDivisionLeader_ = 0; 46 this->desiredRelativePosition_ = 0;47 45 48 46 orxout(internal_error) << this << "Was created" << endl; … … 54 52 55 53 } 56 /*void SectionController::setDesiredPositionOfWingman()54 void SectionController::setTargetPositionOfWingman() 57 55 { 58 56 if (!this->myWingman_) 59 57 return; 60 58 Vector3* targetRelativePositionOfWingman; 61 59 switch (this->formationMode_){ 62 60 case WALL: 63 61 { 64 myWingman_->desiredRelativePosition_ = new Vector3 (-200, 0, 0);62 targetRelativePositionOfWingman = new Vector3 (-400, 0, 0); 65 63 break; 66 64 } … … 78 76 } 79 77 } 78 Quaternion orient = this->getControllableEntity()->getWorldOrientation(); 79 80 Vector3 targetAbsolutePositionOfWingman = ((this->getControllableEntity()->getWorldPosition()) + 81 (this->getControllableEntity()->getWorldOrientation()* (*targetRelativePositionOfWingman))); 82 83 myWingman_->setTargetOrientation(orient); 84 myWingman_->setTargetPosition(targetAbsolutePositionOfWingman); 80 85 81 86 } 82 */ 87 83 88 LeaderController* SectionController::findNewDivisionLeader() 84 89 { … … 104 109 105 110 106 107 108 109 111 float distance = ((it)->getControllableEntity()->getPosition() - this->getControllableEntity()->getPosition()).length(); 110 112 … … 114 116 minDistance = distance; 115 117 } 116 /* // is pawn in range? 117 if (distance < RADIUS_TO_SEARCH_FOR_LEADER) 118 { 119 120 if ((it)->setFollower(this)) 121 return (*it); 122 }*/ 118 123 119 } 124 120 if (closestLeader) … … 142 138 143 139 } 144 /* setDesiredPositionOfWingman(); 145 */ } 140 setTargetPositionOfWingman(); 141 142 } 146 143 /* 147 144 Wingmen and Leaders attack target_, which is a member variable of their classes. … … 158 155 159 156 */ 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 }*/ 157 172 158 void SectionController::tick(float dt) 173 159 { 174 175 176 /*177 160 if (!this->isActive()) 178 161 return; 179 162 180 //--------------------------Stay in division-------------------------- 181 this->keepDivisionTick(); 182 */ 183 //If ordered to move -> move to a target Point 184 185 //No orders -> Don't move, but shoot at whatever is close, unless Boss is shooting at it. 186 //(Section shoots same target, Boss's section shoots another target) 187 163 if (this->bHasTargetPosition_) 164 { 165 this->moveToTargetPosition(); 166 } 188 167 189 //orxout(internal_error) << "my Wingman is " << this->myWingman_ << endl;190 168 191 169 SUPER(SectionController, tick, dt); -
code/branches/AI_HS15/src/orxonox/controllers/SectionController.h
r10725 r10729 42 42 SectionController(Context* context); 43 43 virtual ~SectionController(); 44 virtual bool setWingman(CommonController* wingman)44 virtual bool setWingman(CommonController* cwingman) 45 45 { 46 WeakPtr<WingmanController> wingman = orxonox_cast<WingmanController*>(cwingman); 47 46 48 if (!this->myWingman_) 47 49 { … … 54 56 } 55 57 } 58 56 59 57 60 virtual bool hasWingman() … … 69 72 70 73 protected: 71 void setDesiredPositionOfWingman(); 72 void keepDivisionTick(); 74 void setTargetPositionOfWingman(); 73 75 //A division is the biggest block of spaceships. 74 76 //In division one section is leading, the other one always stays on the same position -
code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc
r10725 r10729 34 34 35 35 RegisterClass(WingmanController); 36 static const int RADIUS_TO_SEARCH_FOR_LEADER = 7000;37 static const float ACTION_INTERVAL = 1.0f; 36 37 38 38 WingmanController::WingmanController(Context* context) : CommonController(context) 39 39 { … … 41 41 this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&WingmanController::action, this))); 42 42 this->myLeader_ = 0; 43 this->desiredRelativePosition_ = 0;44 43 } 45 44 … … 88 87 void WingmanController::action() 89 88 { 90 //this->target_ = this->sectionTarget_;91 89 if (!this->myLeader_) 92 90 { … … 145 143 146 144 147 /*void WingmanController::keepSectionTick() 148 { 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); 157 } 158 }*/ 145 159 146 void WingmanController::tick(float dt) 160 147 { 161 /*//-------------------------------------------------------148 //------------------------------------------------------- 162 149 163 150 … … 165 152 return; 166 153 //--------------------------Stay in formation-------------------------- 167 this->keepSectionTick();*/ 168 154 if (this->bHasTargetPosition_) 155 { 156 //targetPosition_ and targetOrientation_ are set by the Leader in its action() 157 this->moveToTargetPosition(); 158 } 169 159 170 160 //--------------------------Attack same target as the Leader-------------------------- … … 175 165 this->doFire(); 176 166 } 177 */167 */ 178 168 179 169 //orxout(internal_error) << "I am " << this << endl; … … 190 180 } 191 181 192 //**********************************************NEW 193 /*void WingmanController::defaultBehaviour(float maxrand) 194 { 195 196 }*/ 182 197 183 198 184 } -
code/branches/AI_HS15/src/orxonox/controllers/WingmanController.h
r10725 r10729 60 60 61 61 virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour ~ setting targets. 62 //void defaultBehaviour(float maxrand); //<! Helper function for code reusage. Some concrete commands for a bot.63 62 64 63 65 64 66 65 private: 67 //const float ACTION_INTERVAL;68 void keepSectionTick();69 66 70 //LeaderController* leader_;71 67 72 68 Timer actionTimer_; //<! Regularly calls action().
Note: See TracChangeset
for help on using the changeset viewer.