Changeset 10719 for code/branches/AI_HS15
- Timestamp:
- Oct 29, 2015, 8:02:23 PM (9 years ago)
- Location:
- code/branches/AI_HS15
- Files:
-
- 4 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/AI_HS15/data/levels/AITest.oxw
r10717 r10719 63 63 </!--> 64 64 65 <SpaceShip position = "-1000, -1000, -1000"> 66 <templates> 67 <Template link=spaceshipassff /> 68 </templates> 65 <StaticEntity position = "-1000, -1000, -1000"> 66 69 67 <controller> 70 68 <FleetController accuracy=10 team=1 > 71 69 </FleetController> 72 70 </controller> 73 </S paceShip>71 </StaticEntity> 74 72 75 73 <SpaceShip position="1000, 1000, -1500 ?>" lookat="0,0,0"> … … 96 94 </templates> 97 95 <controller> 98 < LeaderController team=1>99 </ LeaderController>96 <SectionController team=1> 97 </SectionController> 100 98 </controller> 101 99 </SpaceShip> … … 109 107 </controller> 110 108 </SpaceShip> 111 <!-->112 109 <!--> 113 110 <?lua -
code/branches/AI_HS15/src/orxonox/controllers/CMakeLists.txt
r10709 r10719 15 15 LeaderController.cc 16 16 WingmanController.cc 17 SectionController.cc 18 CommonController.cc 17 19 ) -
code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc
r10718 r10719 64 64 } 65 65 } 66 /*void DivisionController::XMLPort(Element& xmlelement, XMLPort::Mode mode)66 void DivisionController::XMLPort(Element& xmlelement, XMLPort::Mode mode) 67 67 { 68 68 SUPER(DivisionController, XMLPort, xmlelement, mode); 69 69 70 70 //XMLPortParam(DivisionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f); 71 } */71 } 72 72 73 73 -
code/branches/AI_HS15/src/orxonox/controllers/DivisionController.h
r10718 r10719 39 39 namespace orxonox 40 40 { 41 class _OrxonoxExport DivisionController : public LeaderController 41 class _OrxonoxExport DivisionController : public LeaderController, public Tickable 42 42 { 43 43 public: … … 45 45 virtual ~DivisionController(); 46 46 47 //virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);47 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 48 48 49 49 //Using british military aircraft formations … … 53 53 { return this->formationMode_; } 54 54 virtual bool setFollower(LeaderController* myFollower); 55 virtual bool setWingman(CommonController* wingman) 56 { 57 if (!this->myWingman_) 58 { 59 this->myWingman_ = wingman; 60 return true; 61 } 62 else 63 { 64 return false; 65 } 66 }; 67 virtual void tick(float dt); //<! Carrying out the targets set in action(). 55 68 56 69 … … 66 79 FormationMode formationMode_; 67 80 68 81 CommonController* myWingman_; 69 82 LeaderController* myFollower_; 70 83 -
code/branches/AI_HS15/src/orxonox/controllers/FleetController.cc
r10717 r10719 35 35 RegisterClass(FleetController); 36 36 37 FleetController::FleetController(Context* context) : FormationController(context)37 FleetController::FleetController(Context* context) : Controller(context) 38 38 { 39 39 RegisterObject(FleetController); -
code/branches/AI_HS15/src/orxonox/controllers/FleetController.h
r10709 r10719 29 29 #ifndef _FleetController_H__ 30 30 #define _FleetController_H__ 31 #include "controllers/FormationController.h"32 31 33 32 #include "controllers/Controller.h" … … 58 57 { 59 58 60 class _OrxonoxExport FleetController : public FormationController, public Tickable59 class _OrxonoxExport FleetController : public Controller, public Tickable 61 60 { 62 61 public: -
code/branches/AI_HS15/src/orxonox/controllers/FormationController.cc
r10717 r10719 277 277 } 278 278 279 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); 280 280 float distance = (target - this->getControllableEntity()->getPosition()).length(); 281 281 float rotateX = clamp(coord.x * 10, -1.0f, 1.0f); … … 1069 1069 return; 1070 1070 1071 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); 1072 1072 float distance = (target - this->getControllableEntity()->getPosition()).length(); 1073 1073 -
code/branches/AI_HS15/src/orxonox/controllers/LeaderController.cc
r10718 r10719 41 41 RegisterClass(LeaderController); 42 42 43 static const int RADIUS_TO_SEARCH_FOR_LEADER = 3000;44 43 45 44 LeaderController::LeaderController(Context* context) : CommonController(context) … … 47 46 48 47 RegisterObject(LeaderController); 49 bIsDivisionLeader_ = false;50 48 51 49 //this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&LeaderController::action, this))); … … 57 55 } 58 56 59 LeaderController* LeaderController::findNewDivisionLeader() 60 { 61 62 if (!this->getControllableEntity()) 63 return NULL; 64 65 66 //go through all pawns 67 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it) 68 { 69 70 //same team? 71 if (!(this->getControllableEntity()->getTeam() != static_cast<ControllableEntity*>(*it)->getTeam())) 72 continue; 73 74 //Does it have a Controller? 75 Controller* controller = 0; 76 77 if (it->getController()) 78 controller = it->getController(); 79 else if (it->getXMLController()) 80 controller = it->getXMLController(); 81 82 if (!controller) 83 continue; 84 85 //is equal to this? 86 if (orxonox_cast<ControllableEntity*>(*it) == this->getControllableEntity()) 87 continue; 88 89 90 LeaderController* newLeader = orxonox_cast<LeaderController*>(controller); 91 92 //nullptr or not DivisionController? 93 if (!newLeader || !newLeader->bIsDivisionLeader_) 94 continue; 95 96 float distance = (it->getPosition() - this->getControllableEntity()->getPosition()).length(); 97 98 // is pawn in range? 99 if (distance < RADIUS_TO_SEARCH_FOR_LEADER) 100 { 101 102 if (newLeader->setFollower(this)) 103 return newLeader; 104 } 105 } 106 return NULL; 107 108 } 109 void LeaderController::action() 110 { 111 //this->target_ = this->sectionTarget_; 112 if (!myDivisionLeader_) 113 { 114 LeaderController* newDivisionLeader = findNewDivisionLeader(); 115 myDivisionLeader_ = newDivisionLeader; 116 orxout(internal_error) << "new DivisionLeader set" << endl; 117 } 118 } 119 /* 120 Wingmen and Leaders attack target_, which is a member variable of their classes. 121 Wingmen's target_ is set to sectionTarget_, which is a member variable of SectionController class, unless 122 Wingman covers Leader's rear. 123 Leader's target_ must always equal sectionTarget_. 124 if section has a target, its Leader shoots at it, but doesn't follow. 125 Every section is a part of division. Division consisting of one Section is still a division. 126 Division's leader's target_ must always equal divisionTarget_, which is a member variable of DivisionController. 127 Division leader ONLY can follow target_ while in formation flight. 128 If Division doesn't have a target, Division Leader stays in place, unless it has a waypoint. 129 Division Leader's sectionTarget_ must equal divisionTarget_, 130 but the other section, that is not a leading section, can attack any target that is near divisonTarget_ 131 132 */ 133 void LeaderController::tick(float dt) 134 {/* 135 if (!this->isActive()) 136 return; 137 138 //--------------------------Stay in division-------------------------- 139 this->keepDivisionTick();*/ 140 /*keepDivisionTick(){ 141 if (this->divisionLeader_ && this->divisionLeader_->getControllableEntity() && desiredRelativePosition_){ 142 Vector3 desiredAbsolutePosition = ((this->divisionLeader_->getControllableEntity()->getWorldPosition()) + 143 (this->divisionLeader_->getControllableEntity()->getWorldOrientation()* (*desiredRelativePosition_))); 144 this->moveToPosition (desiredAbsolutePosition); 145 } 146 } 147 */ 148 /*//If ordered to attack -> follow target and shoot 149 if (this->bAttackOrder_) 150 { 151 152 } 153 //If ordered to move -> move to a target Point 154 155 //No orders -> Don't move, but shoot at whatever is close, unless Boss is shooting at it. 156 //(Section shoots same target, Boss's section shoots another target) 157 { 158 159 }*/ 160 161 orxout(internal_error) << "my Wingman is " << this->myWingman_ << endl; 162 163 SUPER(LeaderController, tick, dt); 164 } 165 bool LeaderController::setWingman(WingmanController* wingman) 166 { 167 if (!this->myWingman_) 168 { 169 this->myWingman_ = wingman; 170 return true; 171 } 172 else 173 { 174 return false; 175 } 176 } 177 bool LeaderController::isLeader() 178 { 179 return true; 180 } 57 181 58 //**********************************************NEW 182 59 /* void LeaderController::defaultBehaviour(float maxrand) -
code/branches/AI_HS15/src/orxonox/controllers/LeaderController.h
r10718 r10719 35 35 36 36 #include "util/Math.h" 37 #include "tools/Timer.h" 38 #include "tools/interfaces/Tickable.h" 37 39 38 40 39 namespace orxonox 41 40 { 42 class _OrxonoxExport LeaderController : public CommonController , virtual public Tickable41 class _OrxonoxExport LeaderController : public CommonController 43 42 { 44 43 public: 45 44 static const int RADIUS_TO_SEARCH_FOR_LEADER = 3000; 45 46 46 LeaderController(Context* context); 47 47 virtual ~LeaderController(); 48 virtual bool isLeader(); 48 virtual bool isLeader() 49 { 50 return true; 51 } 52 bool bIsDivisionLeader_; 53 virtual bool setFollower(LeaderController* myFollower) 54 { 55 return false; 56 }; 49 57 50 virtual bool setWingman(WingmanController* wingman);51 virtual void tick(float dt); //<! Carrying out the targets set in action().52 58 53 59 protected: 54 60 55 LeaderController* findNewDivisionLeader();56 61 57 bool bIsDivisionLeader_;58 62 59 virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour ~ setting targets.60 63 //void defaultBehaviour(float maxrand); //<! Helper function for code reusage. Some concrete commands for a bot. 61 64 … … 64 67 WeakPtr<Pawn> target_; 65 68 66 WingmanController* myWingman_; 67 LeaderController* myDivisionLeader_; 69 68 70 //Timer actionTimer_; //<! Regularly calls action(). 69 71 -
code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc
r10717 r10719 41 41 42 42 RegisterClass(WingmanController); 43 static const int RADIUS_TO_SEARCH_FOR_LEADER = 3000;44 43 static const int RADIUS_TO_SEARCH_FOR_LEADER = 7000; 44 static const float ACTION_INTERVAL = 1.0f; 45 45 WingmanController::WingmanController(Context* context) : CommonController(context) 46 46 { 47 47 RegisterObject(WingmanController); 48 //this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&WingmanController::action, this)));48 this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&WingmanController::action, this))); 49 49 } 50 50 … … 68 68 69 69 //go through all pawns 70 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it) 71 { 72 70 for (ObjectList<CommonController>::iterator it = ObjectList<CommonController>::begin(); it; ++it) 71 { 73 72 //same team? 74 if ( !(this->getControllableEntity()->getTeam() != static_cast<ControllableEntity*>(*it)->getTeam()))73 if ((this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam())) 75 74 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) 75 //is equal to this? 76 if (it->getControllableEntity() == this->getControllableEntity()) 86 77 continue; 87 78 88 //is equal to this? 89 if (orxonox_cast<ControllableEntity*>(*it) == this->getControllableEntity()) 79 80 81 //nullptr? 82 if (!it || !it->isLeader()) 90 83 continue; 91 84 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(); 85 float distance = (it->getControllableEntity()->getPosition() - this->getControllableEntity()->getPosition()).length(); 100 86 101 87 // is pawn in range? … … 103 89 { 104 90 105 if ( newLeader->setWingman(this))106 return newLeader;91 if (it->setWingman(this)) 92 return *it; 107 93 } 108 94 } 109 95 return NULL; 110 }111 bool WingmanController::isLeader()112 {113 return false;114 96 } 115 97 void WingmanController::action() … … 120 102 CommonController* newLeader = findNewLeader(); 121 103 myLeader_ = newLeader; 122 orxout(internal_error) << "new Leader set" << endl; 123 } 124 } 125 126 void WingmanController::tick(float dt) 127 { 128 //------------------------------------------------------- 129 /*//collect data for AI behaviour 104 /* if (newLeader) 105 orxout(internal_error) << "new Leader set" << endl; 106 else 107 orxout(internal_error) << "null leader" << endl; 108 */ 109 } 110 else 111 { 112 //orxout(internal_error) << "already have a Leader" << endl; 113 114 } 115 } 116 /*//collect data for AI behaviour 130 117 Vector3* meanOfEnemiesPtr = new Vector3(0.0,0.0,0.0); 131 118 Vector3* meanOfAlliesPtr = new Vector3(0.0,0.0,0.0); … … 166 153 orxout(internal_error) << "mean of enemies_ is " << meanOfEnemies << ", with a size " << enemies_.size() << endl; 167 154 }*/ 168 /* 169 if (!this->isActive()) 170 return; 171 //--------------------------Stay in formation-------------------------- 172 if (bFollowLeader_) 173 { 174 this->keepSectionTick();*/ 175 /*keepSectionTick(){ 176 if (this->sectionLeader_ && this->sectionLeader_->getControllableEntity() && desiredRelativePosition_){ 177 Vector3 desiredAbsolutePosition = ((this->sectionLeader_->getControllableEntity()->getWorldPosition()) + 178 (this->sectionLeader_->getControllableEntity()->getWorldOrientation()* (*desiredRelativePosition_))); 179 this->moveToPosition (desiredAbsolutePosition); 180 } 181 } 182 */ 183 /* 184 //--------------------------Attack same target as the Leader-------------------------- 185 186 if (this->target_) 187 { 188 this->aimAtTarget(); 189 this->doFire(); 190 } 191 }*/ 192 //orxout(internal_error) << "I am " << this << endl; 193 194 /* void FormationController::setDesiredPositionOfSlaves() 155 156 /* void FormationController::setDesiredPositionOfSlaves() 195 157 { 196 158 if (this->state_ != MASTER) … … 218 180 219 181 }*/ 182 void WingmanController::tick(float dt) 183 { 184 //------------------------------------------------------- 185 186 /* 187 if (!this->isActive()) 188 return; 189 //--------------------------Stay in formation-------------------------- 190 if (bFollowLeader_) 191 { 192 this->keepSectionTick(); 193 194 keepSectionTick(){ 195 if (this->sectionLeader_ && this->sectionLeader_->getControllableEntity() && desiredRelativePosition_){ 196 Vector3 desiredAbsolutePosition = ((this->sectionLeader_->getControllableEntity()->getWorldPosition()) + 197 (this->sectionLeader_->getControllableEntity()->getWorldOrientation()* (*desiredRelativePosition_))); 198 this->moveToPosition (desiredAbsolutePosition); 199 } 200 } 201 202 203 //--------------------------Attack same target as the Leader-------------------------- 204 205 if (this->target_) 206 { 207 this->aimAtTarget(); 208 this->doFire(); 209 } 210 } 211 */ 212 //orxout(internal_error) << "I am " << this << endl; 213 220 214 221 215 SUPER(WingmanController, tick, dt); 222 216 } 217 218 void WingmanController::XMLPort(Element& xmlelement, XMLPort::Mode mode) 219 { 220 SUPER(WingmanController, XMLPort, xmlelement, mode); 221 222 //XMLPortParam(SectionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f); 223 } 224 223 225 //**********************************************NEW 224 226 /*void WingmanController::defaultBehaviour(float maxrand) -
code/branches/AI_HS15/src/orxonox/controllers/WingmanController.h
r10717 r10719 46 46 WingmanController(Context* context); 47 47 virtual ~WingmanController(); 48 virtual bool isLeader(); 49 //virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 48 virtual bool isLeader() 49 { 50 return false; 51 }; 52 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 50 53 virtual void tick(float dt); //<! Carrying out the targets set in action(). 54 CommonController* findNewLeader(); 51 55 52 56 protected: 53 CommonController* findNewLeader();54 57 55 58 virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour ~ setting targets. … … 65 68 //LeaderController* leader_; 66 69 67 //Timer actionTimer_; //<! Regularly calls action().70 Timer actionTimer_; //<! Regularly calls action(). 68 71 69 72 };
Note: See TracChangeset
for help on using the changeset viewer.