Changeset 10826 for code/branches/AI_HS15
- Timestamp:
- Nov 22, 2015, 5:06:38 PM (9 years ago)
- Location:
- code/branches/AI_HS15
- Files:
-
- 2 deleted
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/AI_HS15/data/levels/AITest.oxw
r10805 r10826 79 79 </controller> 80 80 </SpaceShip> 81 <SpaceShip position=" 6000, 1500, -2800" lookat="0,0,0">81 <SpaceShip position="4000, 1500, -2800 " lookat="0,0,0"> 82 82 <templates> 83 83 <Template link=spaceshipassff /> … … 88 88 </controller> 89 89 </SpaceShip> 90 <SpaceShip position="6000, 1500, -1000" lookat="0,0,0">91 <templates>92 <Template link=spaceshipassff />93 </templates>94 <controller>95 <DivisionController team=1 formationMode="DIAMOND">96 </DivisionController>97 </controller>98 </SpaceShip>99 <SpaceShip position="6000 ,1500, -1600 " lookat="0,0,0">100 <templates>101 <Template link=spaceshipassff />102 </templates>103 <controller>104 <WingmanController team=1>105 </WingmanController>106 </controller>107 </SpaceShip>108 <SpaceShip position="6000, 1500, -2200" lookat="0,0,0">109 <templates>110 <Template link=spaceshipassff />111 </templates>112 <controller>113 <WingmanController team=1>114 </WingmanController>115 </controller>116 </SpaceShip>117 <SpaceShip position="6000, 1500, -2800" lookat="0,0,0">118 <templates>119 <Template link=spaceshipassff />120 </templates>121 <controller>122 <SectionController team=1>123 </SectionController>124 </controller>125 </SpaceShip>126 127 90 128 91 <SpaceShip position="-4000, 1500, -5000" lookat="0,0,0"> … … 163 126 </SpaceShip> 164 127 165 <SpaceShip position="-6000, 1500, -5000" lookat="0,0,0">166 <templates>167 <Template link=spaceshipassff />168 </templates>169 <controller>170 <DivisionController team=2 formationMode="FINGER4">171 </DivisionController>172 </controller>173 </SpaceShip>174 <SpaceShip position="-6000 , 1500, -5600" lookat="0,0,0">175 <templates>176 <Template link=spaceshipassff />177 </templates>178 <controller>179 <WingmanController team=2>180 </WingmanController>181 </controller>182 </SpaceShip>183 <SpaceShip position="-6000, 1500, -6200" lookat="0,0,0">184 <templates>185 <Template link=spaceshipassff />186 </templates>187 <controller>188 <WingmanController team=2>189 </WingmanController>190 </controller>191 </SpaceShip>192 <SpaceShip position="-6000, 1500, -6800 " lookat="0,0,0">193 <templates>194 <Template link=spaceshipassff />195 </templates>196 <controller>197 <SectionController team=2>198 </SectionController>199 </controller>200 </SpaceShip>201 202 203 128 204 129 -
code/branches/AI_HS15/src/orxonox/controllers/CMakeLists.txt
r10719 r10826 11 11 FormationController.cc 12 12 ControllerDirector.cc 13 FleetController.cc14 13 DivisionController.cc 15 14 LeaderController.cc -
code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc
r10805 r10826 46 46 47 47 RegisterClass( CommonController ); 48 float SPEED = 0.9f/0.02f;49 float ROTATEFACTOR = 1.0f/0.02f;48 const float SPEED = 0.9f/0.02f; 49 const float ROTATEFACTOR = 1.0f/0.02f; 50 50 51 51 CommonController::CommonController( Context* context ): Controller( context ) … … 53 53 this->bSetupWorked = false; 54 54 55 this->executingManeuver_ = false;55 56 56 this->executingMoveToPoint_ = false; 57 57 this->action_ = Action::FLY; 58 58 this->stopLookingAtTarget(); 59 this->maneuverType_ = ManeuverType::NONE;59 60 60 RegisterObject( CommonController ); 61 61 } … … 64 64 CommonController::~CommonController() 65 65 { 66 orxout(internal_error) << "I died, my Rank is " << rank_ << endl;66 //orxout(internal_error) << "I died, my Rank is " << rank_ << endl; 67 67 } 68 68 … … 77 77 const std::string valUpper = getUppercase( val ); 78 78 FormationMode::Value value; 79 if ( valUpper == "VEE" ) 80 value = FormationMode::VEE; 81 else if ( valUpper == "WALL" ) 79 80 if ( valUpper == "WALL" ) 82 81 value = FormationMode::WALL; 83 82 else if ( valUpper == "FINGER4" ) … … 94 93 switch ( this->formationMode_ ) 95 94 { 96 case FormationMode::VEE:97 {98 return "VEE";99 break;100 }101 95 case FormationMode::WALL: 102 96 { … … 246 240 } 247 241 } 248 if ( this->getControllableEntity() && !this->target_ ) 249 { 250 251 this->maneuverType_ = ManeuverType::NONE; 252 } 242 253 243 //orxout ( internal_error ) << "ManeuverType = " << this->maneuverType_ << endl; 254 244 } … … 606 596 607 597 } 598 float CommonController::distance (ControllableEntity* entity1, ControllableEntity* entity2) 599 { 600 if (!entity1 || !entity2) 601 return std::numeric_limits<float>::infinity(); 602 return ( entity1->getPosition() - entity2->getPosition() ).length(); 603 } 604 bool CommonController::sameTeam (ControllableEntity* entity1, ControllableEntity* entity2) 605 { 606 if (!entity1 || !entity2) 607 return false; 608 return entity1->getTeam() == entity2->getTeam(); 609 } 608 610 void CommonController::doFire() 609 611 { -
code/branches/AI_HS15/src/orxonox/controllers/CommonController.h
r10805 r10826 34 34 #include "worldentities/ControllableEntity.h" 35 35 #include "worldentities/pawns/Pawn.h" 36 #include "core/ClassTreeMask.h"36 #include <limits> 37 37 38 38 … … 44 44 enum Value 45 45 { 46 VEE,FINGER4, DIAMOND, WALL46 FINGER4, DIAMOND, WALL 47 47 }; 48 48 } … … 55 55 56 56 } 57 //none for a formation flight without attacking, neutral when opponent and this have no58 //advantage over each other, offensive when this spotted opponent first,59 //defensive otherwise60 namespace ManeuverType61 {62 enum Value63 {64 NONE, NEUTRAL, OFFENSIVE, DEFENCIVE65 };66 67 }68 57 namespace Action 69 58 { … … 73 62 }; 74 63 } 75 //none for a formation flight 76 namespace Maneuver 77 { 78 enum Value 79 { 80 NONE, GUNSD, SCISSORS, COMBATSPREAD, DEFENSIVESPLIT, BREAK, BARRELROLL, SWOOP, IMMELMANN, 81 WINGOVER, LOWYOYO, HIGHYOYO, LAGDISPLACEMENTROLL 82 }; 83 } 84 64 85 65 86 66 class _OrxonoxExport CommonController : public Controller … … 118 98 virtual bool setWingman(CommonController* wingman); 119 99 virtual bool hasWingman(); 120 100 static bool sameTeam (ControllableEntity* entity1, ControllableEntity* entity2); 121 101 void setTarget(ControllableEntity* target); 122 102 bool hasTarget(); … … 147 127 void copyTargetOrientation(float dt); 148 128 129 static float distance(ControllableEntity* entity1, ControllableEntity* entity2); 149 130 float squaredDistanceToTarget() const; 150 131 void doFire(); … … 202 183 FormationMode::Value formationMode_; 203 184 Rank::Value rank_; 204 ManeuverType::Value maneuverType_; 205 Maneuver::Value maneuver_; 206 207 bool executingManeuver_; 185 208 186 bool executingMoveToPoint_; 209 187 -
code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc
r10805 r10826 35 35 RegisterClass(DivisionController); 36 36 37 //Leaders share the fact that they have Wingmans 37 38 DivisionController::DivisionController(Context* context) : LeaderController(context) 38 39 { … … 53 54 } 54 55 56 void DivisionController::XMLPort(Element& xmlelement, XMLPort::Mode mode) 57 { 58 SUPER(DivisionController, XMLPort, xmlelement, mode); 59 60 //XMLPortParam(DivisionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f); 61 } 62 55 63 56 64 void DivisionController::tick(float dt) … … 76 84 void DivisionController::action() 77 85 { 78 if (!this->target_) 86 //----find a target---- 87 if ( !this->hasTarget() ) 79 88 { 80 89 for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP) 81 90 { 82 if ( this->getControllableEntity()->getTeam() == static_cast<ControllableEntity*>(*itP)->getTeam())91 if ( CommonController::sameTeam (this->getControllableEntity(), static_cast<ControllableEntity*>(*itP)) ) 83 92 continue; 84 93 85 94 86 if (static_cast<ControllableEntity*>(*itP) != (this)->getControllableEntity() && !(this)->hasTarget()87 && ((*itP)->getWorldPosition() - (this)->getControllableEntity()->getWorldPosition()).length()< 10000)95 if (static_cast<ControllableEntity*>(*itP) != (this)->getControllableEntity() 96 && CommonController::distance (*itP, this->getControllableEntity()) < 10000) 88 97 { 89 98 (this)->setAction(Action::FIGHT, *itP); … … 94 103 if (this->action_ == Action::FIGHT) 95 104 { 105 //----choose where to go---- 96 106 this->maneuver(); 107 //----fire if you can---- 97 108 this->bShooting_ = this->canFire(); 109 98 110 if (this->target_) 99 111 { 100 112 if (this->myWingman_) 101 113 { 114 //----wingmans shall support the fire of their leaders---- 102 115 this->myWingman_->setAction (Action::FIGHT, this->target_); 103 116 } 104 117 118 //----fly in formation if far enough---- 105 119 Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition(); 106 120 if (diffVector.length() > 3000) … … 141 155 break; 142 156 } 143 case FormationMode::VEE: 144 { 145 break; 146 } 157 147 158 case FormationMode::DIAMOND: 148 159 { … … 177 188 break; 178 189 } 179 case FormationMode::VEE: 180 { 181 break; 182 } 190 183 191 case FormationMode::DIAMOND: 184 192 { … … 239 247 240 248 241 void DivisionController::XMLPort(Element& xmlelement, XMLPort::Mode mode)242 {243 SUPER(DivisionController, XMLPort, xmlelement, mode);244 245 //XMLPortParam(DivisionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f);246 }247 248 249 249 250 -
code/branches/AI_HS15/src/orxonox/controllers/DivisionController.h
r10731 r10826 42 42 { 43 43 public: 44 //----[language demanded functions]---- 45 DivisionController(Context* context); 44 46 45 DivisionController(Context* context);46 virtual ~DivisionController();47 virtual ~DivisionController(); 48 //----[/language demanded functions]---- 47 49 48 virtual void tick(float dt); //<! Carrying out the targets set in action(). 50 //----[orxonox demanded functions]---- 51 virtual void tick(float dt); 49 52 50 51 virtual bool setFollower(LeaderController* myFollower); 52 virtual bool setWingman(CommonController* cwingman); 53 virtual bool hasWingman(); 54 virtual bool hasFollower(); 53 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 54 //----[orxonox demanded functions]---- 55 55 56 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 56 //----[own functions]---- 57 virtual bool setFollower(LeaderController* myFollower); 58 virtual bool setWingman(CommonController* cwingman); 59 virtual bool hasWingman(); 60 virtual bool hasFollower(); 61 62 void setTargetPositionOfWingman(); 63 void setTargetPositionOfFollower(); 64 //----[/own functions]---- 57 65 58 66 protected: 59 60 void setTargetPositionOfWingman(); 61 void setTargetPositionOfFollower(); 62 63 virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour ~ setting targets. 67 //----action must only be managed by this---- 68 virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour. 64 69 65 70 private: 66 71 //----private variables----- 67 72 Timer actionTimer_; //<! Regularly calls action(). 68 73 -
code/branches/AI_HS15/src/orxonox/controllers/LeaderController.cc
r10729 r10826 41 41 RegisterClass(LeaderController); 42 42 43 43 //CommonController contains all common functionality of AI Controllers 44 44 LeaderController::LeaderController(Context* context) : CommonController(context) 45 45 { -
code/branches/AI_HS15/src/orxonox/controllers/LeaderController.h
r10731 r10826 42 42 { 43 43 public: 44 //----[language demanded functions]---- 45 LeaderController(Context* context); 46 virtual ~LeaderController(); 47 //----[language demanded functions]---- 44 48 45 LeaderController(Context* context); 46 virtual ~LeaderController(); 47 48 virtual bool setFollower(LeaderController* myFollower) 49 { return false; } 50 51 virtual bool hasFollower() 52 { return true; } 53 49 //----[pseudo virtual methods]---- 50 virtual bool setFollower(LeaderController* myFollower) 51 { return false; } 52 virtual bool hasFollower() 53 { return true; } 54 //----[/pseudo virtual methods]---- 54 55 55 56 56 57 57 58 protected: 58 59 WeakPtr<WingmanController> myWingman_; 60 61 WeakPtr<LeaderController> myFollower_; 62 WeakPtr<LeaderController> myDivisionLeader_; 59 //----private variables----- 60 WeakPtr<WingmanController> myWingman_; 61 WeakPtr<LeaderController> myFollower_; 62 WeakPtr<LeaderController> myDivisionLeader_; 63 63 64 64 -
code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc
r10805 r10826 34 34 RegisterClass(SectionController); 35 35 36 //Leaders share the fact that they have Wingmans 36 37 SectionController::SectionController(Context* context) : LeaderController(context) 37 38 { … … 44 45 this->rank_ = Rank::SECTIONLEADER; 45 46 46 orxout(internal_error) << this << "Was created" << endl;47 //orxout(internal_error) << this << "Was created" << endl; 47 48 48 49 } … … 52 53 53 54 } 54 55 void SectionController::XMLPort(Element& xmlelement, XMLPort::Mode mode) 56 { 57 SUPER(SectionController, XMLPort, xmlelement, mode); 58 59 //XMLPortParam(SectionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f); 60 } 61 62 //----in tick, move (or look) and shoot---- 55 63 void SectionController::tick(float dt) 56 64 { … … 75 83 void SectionController::action() 76 84 { 77 // this->target_ = this->sectionTarget_;85 //----If no leader, find one---- 78 86 if (!myDivisionLeader_) 79 87 { 80 88 LeaderController* newDivisionLeader = findNewDivisionLeader(); 81 89 this->myDivisionLeader_ = newDivisionLeader; 90 82 91 if (newDivisionLeader) 83 orxout(internal_error) << "new DivisionLeader set" << endl; 92 { 93 //orxout(internal_error) << "new DivisionLeader set" << endl; 94 } 95 //----If no leader found, attack someone---- 96 //----TODO: find closest enemy---- 84 97 else 85 98 { 86 for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP) 87 { 88 if (this->getControllableEntity()->getTeam() == static_cast<ControllableEntity*>(*itP)->getTeam()) 89 continue; 90 91 if (!this->myDivisionLeader_) 99 if ( !this->hasTarget() || this->action_ != Action::FIGHT ) 100 { 101 for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP) 92 102 { 103 if ( CommonController::sameTeam (this->getControllableEntity(), static_cast<ControllableEntity*>(*itP)) ) 104 continue; 105 93 106 this->setAction(Action::FIGHT, (*itP)); 94 break; 107 break; 108 } 109 } 110 111 } 112 113 } 114 //----If have leader---- 115 else 116 { 117 this->chooseTarget(); 118 } 119 120 //----action was set to fight---- 121 if (this->action_ == Action::FIGHT) 122 { 123 //----choose where to go---- 124 this->maneuver(); 125 //----fire if you can---- 126 this->bShooting_ = this->canFire(); 127 128 if (this->target_) 129 { 130 //----wingmans shall support the fire of their leaders---- 131 if (this->myWingman_) 132 { 133 this->myWingman_->setAction (Action::FIGHT, this->target_); 134 } 135 //----fly in formation if far enough---- 136 Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition(); 137 if (diffVector.length() > 3000) 138 { 139 this->setTargetPositionOfWingman(); 140 } 141 } 142 } 143 144 //----action was set to fly---- 145 else if (this->action_ == Action::FLY) 146 { 147 this->setTargetPositionOfWingman(); 148 } 149 150 //----action was set to protect---- 151 else if (this->action_ == Action::PROTECT) 152 { 153 154 } 155 156 157 } 158 //PRE: myDivisionLeader_ != 0 159 //POST: this->target_ is set unless division leader doesn't have one 160 void SectionController::chooseTarget() 161 { 162 //----If division leader fights, cover him by fighting emenies close to his target---- 163 if (this->myDivisionLeader_->getAction() == Action::FIGHT) 164 { 165 //----if he has a target---- 166 if (this->myDivisionLeader_->hasTarget()) 167 { 168 //----try to find a new target if division leader has wingman (doing fine) and no good target already set---- 169 if ( this->myDivisionLeader_->hasWingman() && 170 !( this->hasTarget() && this->getTarget() != this->myDivisionLeader_->getTarget() ) ) 171 { 172 173 bool foundTarget = false; 174 //----new target should be close to division's target---- 175 Vector3 divisionTargetPosition = this->myDivisionLeader_->getTarget()->getWorldPosition(); 176 177 for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP) 178 { 179 //----is enemy?---- 180 if ( CommonController::sameTeam (this->getControllableEntity(), static_cast<ControllableEntity*>(*itP)) ) 181 continue; 182 //----in range?---- 183 if (((*itP)->getWorldPosition() - divisionTargetPosition).length() < 3000 && 184 (*itP) != this->myDivisionLeader_->getTarget()) 185 { 186 foundTarget = true; 187 this->setAction(Action::FIGHT, (*itP)); 188 //orxout(internal_error) << "Found target" << endl; 189 break; 190 } 95 191 } 96 97 } 98 } 99 100 } 101 else 102 { 103 if (this->myDivisionLeader_->getAction() == Action::FIGHT) 104 { 105 if (this->myDivisionLeader_->hasTarget()) 106 { 107 if (this->myDivisionLeader_->hasWingman() && (!this->hasTarget() || this->getTarget() == this->myDivisionLeader_->getTarget())) 192 //----no target? then attack same target as division leader---- 193 if (!foundTarget) 108 194 { 109 bool foundTarget = false; 110 Vector3 divisionTargetPosition = this->myDivisionLeader_->getTarget()->getWorldPosition(); 111 for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP) 112 { 113 if (this->getControllableEntity()->getTeam() == static_cast<ControllableEntity*>(*itP)->getTeam()) 114 continue; 115 116 if (((*itP)->getWorldPosition() - divisionTargetPosition).length() < 3000 && 117 ((*itP)->getWorldPosition() - divisionTargetPosition).length() > 1000 && 118 (*itP) != this->myDivisionLeader_->getTarget()) 119 { 120 foundTarget = true; 121 this->setAction(Action::FIGHT, (*itP)); 122 orxout(internal_error) << "Found target" << endl; 123 break; 124 } 125 } 126 if (!foundTarget) 127 { 128 this->setAction(Action::FIGHT, this->myDivisionLeader_->getTarget()); 129 } 130 195 this->setAction(Action::FIGHT, this->myDivisionLeader_->getTarget()); 131 196 } 132 197 } 133 } 134 } 135 136 if (this->action_ == Action::FIGHT) 137 { 138 this->maneuver(); 139 this->bShooting_ = this->canFire(); 140 if (this->target_) 141 { 142 if (this->myWingman_) 143 { 144 this->myWingman_->setAction (Action::FIGHT, this->target_); 198 //----if division leader doesn't have a wingman, support his fire---- 199 else 200 { 201 this->setAction(Action::FIGHT, this->myDivisionLeader_->getTarget()); 145 202 } 146 Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition(); 147 if (diffVector.length() > 3000) 148 { 149 this->setTargetPositionOfWingman(); 150 } 151 } 152 } 153 else if (this->action_ == Action::FLY) 154 { 155 this->setTargetPositionOfWingman(); 156 } 157 else if (this->action_ == Action::PROTECT) 158 { 159 160 } 161 162 163 } 164 203 } 204 //----If he fights but doesn't have a target, wait for him to get one---- 205 else 206 { 207 208 } 209 } 210 } 211 212 //----stay in formation---- 165 213 void SectionController::setTargetPositionOfWingman() 166 214 { … … 177 225 { 178 226 targetRelativePositionOfWingman = new Vector3 (-400, 0, -200); 179 break;180 }181 case FormationMode::VEE:182 {183 227 break; 184 228 } … … 197 241 198 242 } 243 199 244 LeaderController* SectionController::findNewDivisionLeader() 200 245 { … … 219 264 continue; 220 265 221 222 float distance = ((it)->getControllableEntity()->getPosition() - this->getControllableEntity()->getPosition()).length(); 266 float distance = CommonController::distance (it->getControllableEntity(), this->getControllableEntity()); 223 267 224 268 if (distance < minDistance && !(it->hasFollower())) … … 260 304 } 261 305 262 void SectionController::XMLPort(Element& xmlelement, XMLPort::Mode mode) 263 { 264 SUPER(SectionController, XMLPort, xmlelement, mode); 265 266 //XMLPortParam(SectionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f); 267 } 268 306 269 307 270 308 -
code/branches/AI_HS15/src/orxonox/controllers/SectionController.h
r10731 r10826 40 40 { 41 41 public: 42 //----[language demanded functions]---- 43 SectionController(Context* context); 42 44 43 SectionController(Context* context);44 virtual ~SectionController();45 virtual ~SectionController(); 46 //----[/language demanded functions]---- 45 47 46 virtual void tick(float dt); //<! Carrying out the targets set in action(). 48 //----[orxonox demanded functions]---- 49 virtual void tick(float dt); 50 51 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 52 //----[/orxonox demanded functions]---- 47 53 54 //----[own functions]---- 55 LeaderController* findNewDivisionLeader(); 56 void setTargetPositionOfWingman(); 48 57 49 LeaderController* findNewDivisionLeader(); 50 virtual bool setWingman(CommonController* cwingman); 51 virtual bool hasWingman(); 52 53 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 58 virtual bool setWingman(CommonController* cwingman); 59 virtual bool hasWingman(); 54 60 55 protected: 61 void chooseTarget(); 62 //----[/own functions]---- 56 63 57 void setTargetPositionOfWingman();58 59 virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour ~ setting targets.64 protected: 65 //----action must only be managed by this---- 66 virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour. 60 67 61 68 private: 62 63 Timer actionTimer_; //<! Regularly calls action().69 //----private variables----- 70 Timer actionTimer_; //<! Regularly calls action(). 64 71 65 72 -
code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc
r10805 r10826 35 35 RegisterClass(WingmanController); 36 36 37 37 //CommonController contains all common functionality of AI Controllers 38 38 WingmanController::WingmanController(Context* context) : CommonController(context) 39 39 { … … 42 42 this->myLeader_ = 0; 43 43 this->rank_ = Rank::WINGMAN; 44 45 44 } 46 45 … … 49 48 50 49 } 51 // void WingmanController::chooseManeuver() 52 // { 53 // if (this->maneuverType_ == ManeuverType::NONE) 54 // switch (this->maneuverType_ ) 55 // { 56 // case ManeuverType::NONE: 57 // { 50 51 void WingmanController::XMLPort(Element& xmlelement, XMLPort::Mode mode) 52 { 53 SUPER(WingmanController, XMLPort, xmlelement, mode); 58 54 59 // break; 60 // } 61 // case ManeuverType::NEUTRAL: 62 // { 63 64 // break; 65 // } 66 // case ManeuverType::OFFENSIVE: 67 // { 68 69 // break; 70 // } 71 // case ManeuverType::DEFENSIVE: 72 // { 73 74 // break; 75 // } 76 // } 77 // if (!this->myWingman_) 78 // return; 79 // Vector3* targetRelativePositionOfWingman; 80 // switch (this->formationMode_){ 81 // case FormationMode::WALL: 82 // { 83 // targetRelativePositionOfWingman = new Vector3 (-400, 0, 0); 84 // break; 85 // } 86 // case FormationMode::FINGER4: 87 // { 88 // targetRelativePositionOfWingman = new Vector3 (-400, 0, -200); 89 // break; 90 // } 91 // case FormationMode::VEE: 92 // { 93 // break; 94 // } 95 // case FormationMode::DIAMOND: 96 // { 97 // targetRelativePositionOfWingman = new Vector3 (400, -200, 0); 98 // break; 99 // } 100 // } 101 // Quaternion orient = this->getControllableEntity()->getWorldOrientation(); 102 103 // Vector3 targetAbsolutePositionOfWingman = ((this->getControllableEntity()->getWorldPosition()) + 104 // (this->getControllableEntity()->getWorldOrientation()* (*targetRelativePositionOfWingman))); 105 106 // myWingman_->setTargetOrientation(orient); 107 // myWingman_->setTargetPosition(targetAbsolutePositionOfWingman); 108 109 // } 110 55 //XMLPortParam(SectionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f); 56 } 57 58 //----in tick, move (or look) and shoot---- 111 59 void WingmanController::tick(float dt) 112 60 { … … 129 77 } 130 78 79 //----action for hard calculations---- 131 80 void WingmanController::action() 132 81 { 82 //----If no leader, find one---- 133 83 if (!this->myLeader_) 134 84 { … … 136 86 this->myLeader_ = newLeader; 137 87 if (newLeader) 138 orxout(internal_error) << "new Leader set" << endl; 88 { 89 //orxout(internal_error) << "new Leader set" << endl; 90 } 91 //----If no leader found, attack someone---- 92 //----TODO: find closest enemy---- 139 93 else 140 94 { 141 if (!this->target_){ 95 if ( !this->hasTarget() || this->action_ != Action::FIGHT ) 96 { 142 97 for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP) 143 98 { 144 if ( this->getControllableEntity()->getTeam() == static_cast<ControllableEntity*>(*itP)->getTeam())99 if ( CommonController::sameTeam (this->getControllableEntity(), static_cast<ControllableEntity*>(*itP)) ) 145 100 continue; 146 101 this->setAction(Action::FIGHT, (*itP)); … … 149 104 } 150 105 } 151 152 106 } 107 //----If have leader, he will deal with logic---- 153 108 else 154 109 { 155 110 156 111 } 157 112 113 114 //----action was set to fight---- 158 115 if (this->action_ == Action::FIGHT) 159 116 { 117 //----choose where to go---- 160 118 this->maneuver(); 119 //----fire if you can---- 161 120 this->bShooting_ = this->canFire(); 162 if (this->target_)163 {164 Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();165 if (diffVector.length() > 5000)166 {167 168 }169 }170 121 } 122 //----action was set to fly, leader handles the logic---- 171 123 else if (this->action_ == Action::FLY) 172 124 { 173 125 174 126 } 127 //----TODO: implement protect---- 175 128 else if (this->action_ == Action::PROTECT) 176 129 { … … 182 135 183 136 184 137 //----POST: closest leader that is ready to take a new wingman is returned---- 185 138 CommonController* WingmanController::findNewLeader() 186 139 { … … 189 142 return 0; 190 143 144 //----vars for finding the closest leader---- 191 145 CommonController* closestLeader = 0; 192 146 float minDistance = std::numeric_limits<float>::infinity(); … … 194 148 for (ObjectList<CommonController>::iterator it = ObjectList<CommonController>::begin(); it; ++it) 195 149 { 196 // 0ptr?150 //----0ptr or not a leader or dead?---- 197 151 if (!it || 198 152 (it->getRank() != Rank::SECTIONLEADER && it->getRank() != Rank::DIVISIONLEADER) || 199 153 !(it->getControllableEntity())) 200 154 continue; 201 //same team? 202 if (this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam()) 155 156 //----same team?---- 157 if ( !CommonController::sameTeam (this->getControllableEntity(), (it)->getControllableEntity()) ) 203 158 continue; 204 //is equal to this? 205 if (it->getControllableEntity() == this->getControllableEntity()) 206 continue; 207 208 float distance = (it->getControllableEntity()->getPosition() - this->getControllableEntity()->getPosition()).length(); 159 160 //----check distance---- 161 float distance = CommonController::distance (it->getControllableEntity(), this->getControllableEntity()); 209 162 if (distance < minDistance && !(it->hasWingman())) 210 163 { … … 216 169 if (closestLeader) 217 170 { 171 //----Racing conditions---- 218 172 if (closestLeader->setWingman(this)) 219 173 return closestLeader; … … 222 176 } 223 177 224 void WingmanController::XMLPort(Element& xmlelement, XMLPort::Mode mode)225 {226 SUPER(WingmanController, XMLPort, xmlelement, mode);227 228 //XMLPortParam(SectionController, "target_", setTarget, getTarget, xmlelement, mode).defaultValues(100.0f);229 }230 178 231 179 -
code/branches/AI_HS15/src/orxonox/controllers/WingmanController.h
r10731 r10826 32 32 33 33 #include "controllers/CommonController.h" 34 #include <limits>35 34 36 35 … … 45 44 { 46 45 public: 47 WingmanController(Context* context); 48 virtual ~WingmanController(); 49 50 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 51 virtual void tick(float dt); //<! Carrying out the targets set in action(). 52 CommonController* findNewLeader(); 46 //----[language demanded functions]---- 47 WingmanController(Context* context); 48 49 virtual ~WingmanController(); 50 //----[/language demanded functions]---- 51 52 //----[orxonox demanded functions]---- 53 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 54 55 virtual void tick(float dt); 56 //----[/orxonox demanded functions]---- 57 58 //----[own functions]---- 59 CommonController* findNewLeader(); 60 //----[/own functions]---- 53 61 54 62 protected: 55 WeakPtr<CommonController> myLeader_; 63 //----action must only be managed by this---- 64 virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour. 56 65 57 virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour ~ setting targets.58 59 60 61 66 private: 62 63 64 Timer actionTimer_; //<! Regularly calls action().65 67 //----private variables----- 68 WeakPtr<CommonController> myLeader_; 69 Timer actionTimer_; //<! Regularly calls action(). 70 66 71 }; 67 72 }
Note: See TracChangeset
for help on using the changeset viewer.