Changeset 10759
- Timestamp:
- Nov 2, 2015, 4:48:27 PM (9 years ago)
- Location:
- code/branches/AI_HS15
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/AI_HS15/data/levels/AITest.oxw
r10731 r10759 62 62 <?lua end ?> 63 63 </!--> 64 <SpaceShip position="0,-10000,0" direction="0,-1,0" > 65 <templates> 66 <Template link=spaceshipassff /> 67 </templates> 68 <controller> 69 <FleetController team=1> 70 </FleetController> 71 </controller> 72 </SpaceShip> 73 <?lua 74 for i = 0, 0, 1 do 75 ?> 76 64 77 78 <SpaceShip position="<?1000 ?>,<?lua print(1500+i*1000) ?>, -1000 ?>" lookat="0,0,0"> 79 <templates> 80 <Template link=spaceshipassff /> 81 </templates> 82 <controller> 83 <DivisionController team=1 formationMode="DIAMOND"> 84 </DivisionController> 85 </controller> 86 </SpaceShip> 87 <SpaceShip position="<?1000 ?>,<?lua print(1500+i*1000) ?>, -1600 ?>" lookat="0,0,0"> 88 <templates> 89 <Template link=spaceshipassff /> 90 </templates> 91 <controller> 92 <WingmanController team=1> 93 </WingmanController> 94 </controller> 95 </SpaceShip> 96 <SpaceShip position="<?1000 ?>,<?lua print(1500+i*1000) ?>, -2200 ?>" lookat="0,0,0"> 97 <templates> 98 <Template link=spaceshipassff /> 99 </templates> 100 <controller> 101 <WingmanController team=1> 102 </WingmanController> 103 </controller> 104 </SpaceShip> 105 <SpaceShip position="<?1000 ?>,<?lua print(1500+i*1000) ?>, -2800 ?>" lookat="0,0,0"> 106 <templates> 107 <Template link=spaceshipassff /> 108 </templates> 109 <controller> 110 <SectionController team=1> 111 </SectionController> 112 </controller> 113 </SpaceShip> 114 <?lua end ?> 115 <!-- <SpaceShip position="4000, 1500, -1300 ?>" lookat="0,0,0"> 116 <templates> 117 <Template link=spaceshipassff /> 118 </templates> 119 <controller> 120 <WingmanController team=2> 121 </WingmanController> 122 </controller> 123 </SpaceShip> --> 124 <!-- 125 <?lua 126 for i = 0, 0, 1 do 127 ?> 128 129 <StaticEntity position="1000,-10000,0" direction="0,-1,0" > 130 <controller> 131 <FleetController team=2> 132 </FleetController> 133 </controller> 134 </StaticEntity> 135 <SpaceShip position="<?50000 ?>,<?lua print(1500+i*1000) ?>, -1000 ?>" lookat="0,0,0"> 136 <templates> 137 <Template link=spaceshipassff /> 138 </templates> 139 <controller> 140 <DivisionController team=2> 141 </DivisionController> 142 </controller> 143 </SpaceShip> 144 <SpaceShip position="<?50000 ?>,<?lua print(1500+i*1000) ?>, -1600 ?>" lookat="0,0,0"> 145 <templates> 146 <Template link=spaceshipassff /> 147 </templates> 148 <controller> 149 <WingmanController team=2> 150 </WingmanController> 151 </controller> 152 </SpaceShip> 153 <SpaceShip position="<?50000 ?>,<?lua print(1500+i*1000) ?>, -2200 ?>" lookat="0,0,0"> 154 <templates> 155 <Template link=spaceshipassff /> 156 </templates> 157 <controller> 158 <WingmanController team=2> 159 </WingmanController> 160 </controller> 161 </SpaceShip> 162 <SpaceShip position="<?50000 ?>,<?lua print(1500+i*1000) ?>, -2800 ?>" lookat="0,0,0"> 163 <templates> 164 <Template link=spaceshipassff /> 165 </templates> 166 <controller> 167 <SectionController team=2> 168 </SectionController> 169 </controller> 170 </SpaceShip> 171 <?lua end ?> --> 172 173 <!-- 174 65 175 <StaticEntity position = "-1000, -1000, -1000"> 66 176 … … 108 218 </SpaceShip> 109 219 220 221 <StaticEntity position = "-1000, -1000, -2000"> 222 223 <controller> 224 <FleetController accuracy=10 team=2 > 225 </FleetController> 226 </controller> 227 </StaticEntity> 228 229 <SpaceShip position="4000, 1000, -1300 ?>" lookat="0,0,0"> 230 <templates> 231 <Template link=spaceshipassff /> 232 </templates> 233 <controller> 234 <DivisionController team=2> 235 </DivisionController> 236 </controller> 237 </SpaceShip> 238 <SpaceShip position="4000, 1500, -1300 ?>" lookat="0,0,0"> 239 <templates> 240 <Template link=spaceshipassff /> 241 </templates> 242 <controller> 243 <WingmanController team=2> 244 </WingmanController> 245 </controller> 246 </SpaceShip> 247 <SpaceShip position="4000, 1500, -1700 ?>" lookat="0,0,0"> 248 <templates> 249 <Template link=spaceshipassff /> 250 </templates> 251 <controller> 252 <WingmanController team=2> 253 </WingmanController> 254 </controller> 255 </SpaceShip> 256 <SpaceShip position="4000, 1000, -1900 ?>" lookat="0,0,0"> 257 <templates> 258 <Template link=spaceshipassff /> 259 </templates> 260 <controller> 261 <SectionController team=2> 262 </SectionController> 263 </controller> 264 </SpaceShip> --> 265 110 266 111 267 <!--> -
code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc
r10737 r10759 27 27 */ 28 28 #include "controllers/CommonController.h" 29 /* 29 #include "core/XMLPort.h" 30 30 31 #include "weaponsystem/WeaponMode.h" 31 32 #include "weaponsystem/WeaponPack.h" … … 34 35 #include "weaponsystem/WeaponSlot.h" 35 36 #include "worldentities/pawns/SpaceShip.h" 36 */ 37 37 38 38 39 namespace orxonox … … 40 41 41 42 RegisterClass(CommonController); 42 static const float SPEED = 0.6f;43 static const float ROTATEFACTOR = 0.2f;43 float SPEED = 0.7f; 44 float ROTATEFACTOR = 0.3f; 44 45 45 46 CommonController::CommonController(Context* context) : Controller(context) 46 47 { 47 //this->bSetupWorked = false;48 this->bSetupWorked = false; 48 49 49 50 RegisterObject(CommonController); … … 55 56 } 56 57 57 58 58 void CommonController::XMLPort(Element& xmlelement, XMLPort::Mode mode) 59 { 60 SUPER(CommonController, XMLPort, xmlelement, mode); 61 XMLPortParam(CommonController, "formationMode", setFormationModeXML, getFormationModeXML, xmlelement, mode); 62 63 } 64 void CommonController::setFormationModeXML(std::string val) 65 { 66 const std::string valUpper = getUppercase(val); 67 FormationMode::Value value; 68 if (valUpper == "VEE") 69 value = FormationMode::VEE; 70 else if (valUpper == "WALL") 71 value = FormationMode::WALL; 72 else if (valUpper == "FINGER4") 73 value = FormationMode::FINGER4; 74 else if (valUpper == "DIAMOND") 75 value = FormationMode::DIAMOND; 76 else 77 ThrowException(ParseError, std::string("Attempting to set an unknown FormationMode: '") + val + "'."); 78 this->setFormationMode(value); 79 80 } 81 std::string CommonController::getFormationModeXML() 82 { 83 switch (this->formationMode_) 84 { 85 case FormationMode::VEE: 86 { 87 return "VEE"; 88 break; 89 } 90 case FormationMode::WALL: 91 { 92 return "WALL"; 93 break; 94 } 95 case FormationMode::FINGER4: 96 { 97 return "FINGER4"; 98 break; 99 } 100 case FormationMode::DIAMOND: 101 { 102 return "DIAMOND"; 103 break; 104 } 105 default: 106 return "DIAMOND"; 107 break; 108 109 } 110 } 59 111 60 112 bool CommonController::setWingman (CommonController* wingman) … … 67 119 return true; 68 120 } 69 121 void CommonController::setTarget(ControllableEntity* target) 122 { 123 this->target_ = target; 124 orxout (internal_error) << " TARGET SET " << endl; 125 if (target) 126 this->targetPosition_ = target->getPosition(); 127 } 70 128 71 129 … … 113 171 while(diff>math::twoPi) diff-=math::twoPi; 114 172 while(diff<-math::twoPi) diff+=math::twoPi; 115 this->getControllableEntity()->rotateRoll( -diff);173 this->getControllableEntity()->rotateRoll(diff*ROTATEFACTOR); 116 174 } 117 175 void CommonController::copyTargetOrientation() … … 134 192 if (!this->getControllableEntity()) 135 193 return; 194 if (this->rank_ == Rank::DIVISIONLEADER) 195 SPEED *= 0.8; 196 if (this->rank_ == Rank::SECTIONLEADER) 197 SPEED *= 0.9; 136 198 137 199 //100 is (so far) the smallest tolerance (empirically found) that can be reached, 138 200 //with smaller distance spaceships can't reach position and go circles around it instead 139 int tolerance = 100;201 int tolerance = 60; 140 202 141 203 ControllableEntity* entity = this->getControllableEntity(); … … 160 222 161 223 //300 works, maybe less is better 162 if (distance < 300)224 if (distance < 400) 163 225 { 164 226 //Change roll when close. When Spaceship faces target, roll doesn't affect it's trajectory … … 180 242 } 181 243 182 /* 244 183 245 int CommonController::getFiremode(std::string name) 184 246 { … … 227 289 void CommonController::doFire() 228 290 { 229 if(!this->bSetupWorked)//setup: find out which weapons are active ! hard coded: laser is "0", lens flare is "1", ...291 if(!this->bSetupWorked)//setup: find out which weapons are active ! hard coded: laser is "0", lens flare is "1", ... 230 292 { 231 293 this->setupWeapons(); 232 294 } 233 else if(this->getControllableEntity() && 234 weaponModes_.size()&& 235 this->bShooting_ && 236 this->isCloseAtTarget((3)*1000) && 237 this->isLookingAtTarget(math::pi / 20.0f)) 295 else if(this->getControllableEntity() && weaponModes_.size()&&this->bShooting_ && 296 this->isCloseAtTarget((1 + 2)*1000) && this->isLookingAtTarget(math::pi / 20.0f)) 238 297 { 239 298 int firemode; … … 246 305 else if ((firemode = getFiremode("HsW01")) > -1 ) //LASER: default weapon 247 306 this->getControllableEntity()->fire(firemode); 307 248 308 } 249 309 } … … 269 329 if (pawn) 270 330 pawn->setAimPosition(aimPosition); 271 } */331 } 272 332 273 333 -
code/branches/AI_HS15/src/orxonox/controllers/CommonController.h
r10737 r10759 33 33 #include "controllers/Controller.h" 34 34 #include "worldentities/ControllableEntity.h" 35 /*#include "worldentities/pawns/Pawn.h"36 */ 35 #include "worldentities/pawns/Pawn.h" 36 37 37 38 38 namespace orxonox 39 39 { 40 41 namespace FormationMode 42 { 43 enum Value 44 { 45 VEE, FINGER4, DIAMOND, WALL 46 }; 47 } 48 namespace Rank 49 { 50 enum Value 51 { 52 NONE, SECTIONLEADER, DIVISIONLEADER, WINGMAN 53 }; 54 55 } 56 40 57 class _OrxonoxExport CommonController : public Controller 41 58 { … … 50 67 51 68 52 enum FormationMode { VEE, FINGER4, DIAMOND, WALL }; 53 virtual void setFormationMode(FormationMode val) 69 70 71 virtual void setFormationMode(FormationMode::Value val) 54 72 { this->formationMode_ = val; } 55 inline FormationMode getFormationMode() const73 inline FormationMode::Value getFormationMode() const 56 74 { return this->formationMode_; } 75 virtual void setFormationModeXML(std::string val); 76 virtual std::string getFormationModeXML(); 57 77 58 enum Rank { NONE, SECTIONLEADER, DIVISIONLEADER, WINGMAN }; 59 virtual void setRank(Rank val) 78 virtual void setRank(Rank::Value val) 60 79 { this->rank_ = val; } 61 inline Rank getRank() const80 inline Rank::Value getRank() const 62 81 { return this->rank_; } 63 82 83 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 64 84 65 85 … … 68 88 virtual bool hasWingman(); 69 89 90 void setTarget(ControllableEntity* target); 70 91 71 92 void setTargetOrientation(const Quaternion& orient); … … 87 108 void copyTargetOrientation(); 88 109 89 /*bool isCloseAtTarget(float distance) const;110 bool isCloseAtTarget(float distance) const; 90 111 void doFire(); 91 112 void aimAtTarget(); … … 99 120 bool bSetupWorked; //<! If false, setupWeapons() is called. 100 121 int getFiremode(std::string name); 101 */ 122 102 123 103 124 bool bHasTargetPosition_; … … 111 132 112 133 113 FormationMode formationMode_;114 Rank rank_;134 FormationMode::Value formationMode_; 135 Rank::Value rank_; 115 136 116 137 -
code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc
r10737 r10759 38 38 { 39 39 RegisterObject(DivisionController); 40 this->setFormationMode(WALL); 40 41 this->setFormationMode(FormationMode::DIAMOND); 41 42 42 43 this->myFollower_ = 0; 43 44 this->myWingman_ = 0; 44 45 this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&DivisionController::action, this))); 45 this->rank_ = DIVISIONLEADER;46 47 Vector3* pos = new Vector3( 500,500,-500);46 this->rank_ = Rank::DIVISIONLEADER; 47 48 Vector3* pos = new Vector3(-4000,-1000,-2000); 48 49 this->setTargetPosition(*pos); 49 50 … … 58 59 void DivisionController::tick(float dt) 59 60 { 60 if (this->target_)61 { 62 //this->aimAtTarget();63 //this->doFire();64 //this->bShooting_ = true;65 } 61 /*if (this->target_) 62 { 63 this->aimAtTarget(); 64 this->doFire(); 65 this->bShooting_ = true; 66 }*/ 66 67 67 68 if (this->bHasTargetPosition_) … … 77 78 setTargetPositionOfFollower(); 78 79 setTargetPositionOfWingman(); 79 /* 80 81 82 if (this->myFollower_ && this->target_) 83 this->myFollower_->setTarget(this->target_); 84 if (this->target_ && this->myWingman_) 85 this->myWingman_->setTarget(this->target_); 86 /* 80 87 for (ObjectList<Controller>::iterator it = ObjectList<Controller>::begin(); it; ++it) 81 88 { 82 if ( this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam())83 { 84 this-> target_=it->getControllableEntity();85 this->setTargetPosition(this->target_->getWorldPosition());89 if ((this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam()) && (it)->getControllableEntity()->getTeam() != 0) 90 { 91 this->setTargetPosition(it->getControllableEntity()->getWorldPosition()); 92 86 93 break; 87 94 } 88 } */89 95 } 96 */ 90 97 91 98 } … … 99 106 Vector3* targetRelativePositionOfWingman; 100 107 switch (this->formationMode_){ 101 case WALL:108 case FormationMode::WALL: 102 109 { 103 110 targetRelativePositionOfWingman = new Vector3 (400, 0, 0); 104 111 break; 105 112 } 106 case FINGER4: 107 { 108 break; 109 } 110 case VEE: 111 { 112 break; 113 } 114 case DIAMOND: 115 { 113 case FormationMode::FINGER4: 114 { 115 targetRelativePositionOfWingman = new Vector3 (400, 0, -200); 116 break; 117 } 118 case FormationMode::VEE: 119 { 120 break; 121 } 122 case FormationMode::DIAMOND: 123 { 124 targetRelativePositionOfWingman = new Vector3 (400, 0, -200); 116 125 break; 117 126 } … … 130 139 if (!this->myFollower_) 131 140 return; 141 this->myFollower_->setFormationMode(this->formationMode_); 142 132 143 Vector3* targetRelativePositionOfFollower; 133 144 switch (this->formationMode_){ 134 case WALL:145 case FormationMode::WALL: 135 146 { 136 147 targetRelativePositionOfFollower = new Vector3 (-400, 0, 0); 137 148 break; 138 149 } 139 case FINGER4: 140 { 141 break; 142 } 143 case VEE: 144 { 145 break; 146 } 147 case DIAMOND: 148 { 150 case FormationMode::FINGER4: 151 { 152 targetRelativePositionOfFollower = new Vector3 (-400, 0, -200); 153 break; 154 } 155 case FormationMode::VEE: 156 { 157 break; 158 } 159 case FormationMode::DIAMOND: 160 { 161 targetRelativePositionOfFollower = new Vector3 (-400, 0, -200); 149 162 break; 150 163 } -
code/branches/AI_HS15/src/orxonox/controllers/FleetController.cc
r10731 r10759 44 44 this->goalProtect_ = NULL;*/ 45 45 46 //this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&FleetController::action, this)));46 this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&FleetController::action, this))); 47 47 } 48 48 … … 56 56 void FleetController::action() 57 57 { 58 58 this->divisions_.clear(); 59 60 /*for (ObjectList<DivisionController>::iterator it = ObjectList<DivisionController>::begin(); it; ++it) 61 { 62 if ((this->getControllableEntity()->getTeam() == (it)->getControllableEntity()->getTeam())) 63 { 64 this->divisions_.push_back(*(it)); 65 } 66 } 67 for (ObjectList<Controller>::iterator it = ObjectList<Controller>::begin(); it; ++it) 68 { 69 if ((this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam()) && (it)->getControllableEntity()->getTeam() != 0) 70 { 71 for(std::vector<WeakPtr<DivisionController> >::iterator it2 = divisions_.begin(); it2 != divisions_.end(); ++it2) { 72 (*it2)->setTarget(it->getControllableEntity()); 73 } 74 break; 75 } 76 }*/ 59 77 60 78 } -
code/branches/AI_HS15/src/orxonox/controllers/FleetController.h
r10731 r10759 56 56 { 57 57 public: 58 static const float ACTION_INTERVAL = 1.0f; 59 58 60 FleetController(Context* context); 59 61 virtual ~FleetController(); … … 74 76 75 77 protected: 78 virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour ~ setting targets. 76 79 77 80 … … 81 84 WeakPtr<Pawn> goalProtect_; 82 85 83 virtual void action();84 86 private: 85 87 86 88 std::vector<WeakPtr<DivisionController> > divisions_; 87 //Timer actionTimer_; //<! Regularly calls action().89 Timer actionTimer_; //<! Regularly calls action(). 88 90 89 91 }; -
code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc
r10731 r10759 37 37 { 38 38 RegisterObject(SectionController); 39 this->setFormationMode( WALL);39 this->setFormationMode(FormationMode::FINGER4); 40 40 41 41 this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&SectionController::action, this))); 42 42 this->myWingman_ = 0; 43 43 this->myDivisionLeader_ = 0; 44 this->rank_ = SECTIONLEADER;44 this->rank_ = Rank::SECTIONLEADER; 45 45 46 46 orxout(internal_error) << this << "Was created" << endl; … … 58 58 return; 59 59 60 /*if (this->target_) 61 { 62 this->aimAtTarget(); 63 this->doFire(); 64 this->bShooting_ = true; 65 }*/ 60 66 if (this->bHasTargetPosition_) 61 67 { … … 76 82 if (newDivisionLeader) 77 83 orxout(internal_error) << "new DivisionLeader set" << endl; 84 else 85 { 86 87 } 78 88 79 89 } 80 90 setTargetPositionOfWingman(); 91 if (this->target_ && this->myWingman_) 92 this->myWingman_->setTarget(this->target_); 93 81 94 82 95 } … … 88 101 Vector3* targetRelativePositionOfWingman; 89 102 switch (this->formationMode_){ 90 case WALL:103 case FormationMode::WALL: 91 104 { 92 105 targetRelativePositionOfWingman = new Vector3 (-400, 0, 0); 93 106 break; 94 107 } 95 case FINGER4: 96 { 97 break; 98 } 99 case VEE: 100 { 101 break; 102 } 103 case DIAMOND: 104 { 108 case FormationMode::FINGER4: 109 { 110 targetRelativePositionOfWingman = new Vector3 (-400, 0, -200); 111 break; 112 } 113 case FormationMode::VEE: 114 { 115 break; 116 } 117 case FormationMode::DIAMOND: 118 { 119 targetRelativePositionOfWingman = new Vector3 (400, -200, 0); 105 120 break; 106 121 } … … 127 142 { 128 143 //0ptr or not DivisionController? 129 if (!(it) || !((it)->getRank() == DIVISIONLEADER) || !(it->getControllableEntity()))144 if (!(it) || !((it)->getRank() == Rank::DIVISIONLEADER) || !(it->getControllableEntity())) 130 145 continue; 131 146 //same team? -
code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc
r10731 r10759 41 41 this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&WingmanController::action, this))); 42 42 this->myLeader_ = 0; 43 this->rank_ = WINGMAN;43 this->rank_ = Rank::WINGMAN; 44 44 45 45 } … … 53 53 { 54 54 //------------------------------------------------------- 55 55 /* if (this->target_) 56 { 57 this->aimAtTarget(); 58 this->doFire(); 59 this->bShooting_ = true; 60 }*/ 56 61 57 62 if (!this->isActive()) … … 88 93 orxout(internal_error) << "new Leader set" << endl; 89 94 else 90 orxout(internal_error) << "0 leader" << endl; 95 { 96 //orxout(internal_error) << "0 leader" << endl; 97 98 } 91 99 92 100 } … … 113 121 //0ptr? 114 122 if (!it || 115 (it->getRank() != SECTIONLEADER && it->getRank() !=DIVISIONLEADER) ||123 (it->getRank() != Rank::SECTIONLEADER && it->getRank() != Rank::DIVISIONLEADER) || 116 124 !(it->getControllableEntity())) 117 125 continue;
Note: See TracChangeset
for help on using the changeset viewer.