- Timestamp:
- Oct 31, 2015, 4:07:29 PM (9 years ago)
- Location:
- code/branches/AI_HS15
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/AI_HS15/data/levels/AITest.oxw
r10729 r10731 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="1,1,-1" spawnclass=SpaceShip pawndesign=spaceshipassff />34 <SpawnPoint team=0 position="-1000,-1000,-1000" lookat="1,1,-1" spawnclass=SpaceShip pawndesign=spaceshipassff /> 35 35 <!--> 36 36 -
code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc
r10729 r10731 35 35 static const float ROTATEFACTOR = 0.2f; 36 36 37 /*static const float SPEED_FREE = 0.8f; 38 static const float ROTATEFACTOR_FREE = 0.8f;*/ 39 37 CommonController::CommonController(Context* context) : Controller(context) 38 { 39 40 RegisterObject(CommonController); 41 } 42 43 44 CommonController::~CommonController() 45 { 46 } 47 48 49 50 40 51 bool CommonController::setWingman (CommonController* wingman) 41 52 { 42 53 return false; 43 54 } 44 bool CommonController::isLeader () 45 { 46 return false; 47 } 55 48 56 bool CommonController::hasWingman() 49 57 { … … 51 59 } 52 60 53 CommonController::CommonController(Context* context) : Controller(context) 54 { 55 56 RegisterObject(CommonController); 57 } 58 59 60 CommonController::~CommonController() 61 { 62 } 61 62 63 64 void CommonController::setTargetPosition(const Vector3& target) 65 { 66 this->targetPosition_ = target; 67 this->bHasTargetPosition_ = true; 68 } 69 70 void CommonController::setTargetOrientation(const Quaternion& orient) 71 { 72 this->targetOrientation_=orient; 73 this->bHasTargetOrientation_=true; 74 } 75 76 void CommonController::setTargetOrientation(ControllableEntity* target) 77 { 78 if (target) 79 setTargetOrientation(target->getOrientation()); 80 } 81 82 /*void CommonController::spin() 83 { 84 this->moveToTargetPosition(); 85 this->getControllableEntity()->rotateRoll(8.0f); 86 } 87 void CommonController::turn180() 88 { 89 Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, this->targetPosition_); 90 91 this->getControllableEntity()->rotateYaw(-2.0f * sgn(coord.x) * coord.x*coord.x); 92 this->getControllableEntity()->rotatePitch(2.0f * sgn(coord.y) * coord.y*coord.y); 93 94 this->getControllableEntity()->moveFrontBack(SPEED); 95 }*/ 96 97 98 63 99 //copy the Roll orientation of given Quaternion. 64 100 void CommonController::copyOrientation(const Quaternion& orient) … … 69 105 while(diff<-math::twoPi) diff+=math::twoPi; 70 106 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 107 } 81 108 void CommonController::copyTargetOrientation() 82 109 { … … 86 113 } 87 114 } 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 99 115 116 117 118 119 void CommonController::moveToTargetPosition() 120 { 121 this->moveToPosition(this->targetPosition_); 122 } 100 123 void CommonController::moveToPosition(const Vector3& target) 101 124 { … … 146 169 bHasTargetOrientation_ = false; 147 170 } 148 149 150 } 151 void CommonController::moveToTargetPosition() 152 { 153 this->moveToPosition(this->targetPosition_); 154 } 171 } 172 void CommonController::doFire() 173 { 174 if (this->isLookingAtTarget(math::pi / 20.0f)) 175 this->getControllableEntity()->fire(0); //ai uses lens flare if they're close enough to the target 176 } 177 bool CommonController::isLookingAtTarget(float angle) const 178 { 179 if (!this->getControllableEntity()) 180 return false; 181 182 return (getAngle(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->targetPosition_) < angle); 183 } 184 185 void CommonController::aimAtTarget() 186 { 187 if (!this->target_ || !this->getControllableEntity()) 188 return; 189 190 static const float hardcoded_projectile_speed = 750; 191 192 Vector3 aimPosition = getPredictedPosition(this->getControllableEntity()->getWorldPosition(), 193 hardcoded_projectile_speed, this->target_->getWorldPosition(), this->target_->getVelocity()); 194 195 Pawn* pawn = orxonox_cast<Pawn*>(this->getControllableEntity()); 196 if (pawn) 197 pawn->setAimPosition(aimPosition); 198 } 199 155 200 156 201 -
code/branches/AI_HS15/src/orxonox/controllers/CommonController.h
r10729 r10731 33 33 #include "controllers/Controller.h" 34 34 #include "worldentities/ControllableEntity.h" 35 #include "worldentities/pawns/Pawn.h" 36 35 37 36 38 namespace orxonox … … 39 41 { 40 42 public: 43 41 44 static const float ACTION_INTERVAL = 1.0f; 42 45 43 enum FormationMode {VEE,FINGER4,DIAMOND, WALL}; 46 47 CommonController(Context* context); 48 virtual ~CommonController(); 49 50 51 52 enum FormationMode { VEE, FINGER4, DIAMOND, WALL }; 44 53 virtual void setFormationMode(FormationMode val) 45 54 { this->formationMode_ = val; } … … 47 56 { return this->formationMode_; } 48 57 49 CommonController(Context* context); 50 virtual ~CommonController(); 51 virtual bool isLeader(); 58 enum Rank { NONE, SECTIONLEADER, DIVISIONLEADER, WINGMAN }; 59 virtual void setRank(Rank val) 60 { this->rank_ = val; } 61 inline Rank getRank() const 62 { return this->rank_; } 63 64 65 66 52 67 virtual bool setWingman(CommonController* wingman); 53 68 virtual bool hasWingman(); … … 58 73 void setTargetPosition(const Vector3& target); 59 74 75 /*void spin(); 76 void turn180();*/ 77 78 60 79 protected: 80 61 81 void moveToPosition(const Vector3& target); 62 v irtual void positionReached() {}82 void moveToTargetPosition(); 63 83 64 65 void moveToTargetPosition(); 84 66 85 void copyOrientation(const Quaternion& orient); 67 86 void copyTargetOrientation(); 68 87 88 void doFire(); 89 void aimAtTarget(); 90 bool isLookingAtTarget(float angle) const; 69 91 70 92 bool bHasTargetPosition_; … … 73 95 Quaternion targetOrientation_; 74 96 97 75 98 WeakPtr<ControllableEntity> target_; 76 99 bool bShooting_; 77 100 101 78 102 FormationMode formationMode_; 79 103 Rank rank_; 80 104 81 105 -
code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc
r10729 r10731 40 40 this->setFormationMode(WALL); 41 41 42 bIsDivisionLeader_ = true;43 42 this->myFollower_ = 0; 44 43 this->myWingman_ = 0; 45 44 this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&DivisionController::action, this))); 46 47 /*Vector3* pos = new Vector3(500,500,-500); 48 this->setTargetPosition(*pos);*/ 45 this->rank_ = DIVISIONLEADER; 46 47 Vector3* pos = new Vector3(500,500,-500); 48 this->setTargetPosition(*pos); 49 49 50 50 } … … 54 54 55 55 } 56 57 56 58 void DivisionController::tick(float dt) 57 59 { 60 if (this->target_) 61 { 62 this->aimAtTarget(); 63 this->doFire(); 64 } 65 58 66 if (this->bHasTargetPosition_) 59 67 { … … 68 76 setTargetPositionOfFollower(); 69 77 setTargetPositionOfWingman(); 70 } 71 72 bool DivisionController::setFollower(LeaderController* myFollower) 73 { 74 if (!this->myFollower_) 75 { 76 this->myFollower_ = myFollower; 77 return true; 78 } 79 else 80 { 81 return false; 82 } 83 } 78 79 for (ObjectList<Controller>::iterator it = ObjectList<Controller>::begin(); it; ++it) 80 { 81 if (this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam()) 82 { 83 this->target_=it->getControllableEntity(); 84 this->setTargetPosition(this->target_->getWorldPosition()); 85 break; 86 } 87 } 88 89 90 } 91 92 84 93 85 94 void DivisionController::setTargetPositionOfWingman() … … 149 158 150 159 } 160 161 162 bool DivisionController::setWingman(CommonController* cwingman) 163 { 164 165 WeakPtr<WingmanController> wingman = orxonox_cast<WingmanController*>(cwingman); 166 if (!this->myWingman_) 167 { 168 this->myWingman_ = wingman; 169 return true; 170 } 171 else 172 { 173 return false; 174 } 175 176 } 177 bool DivisionController::setFollower(LeaderController* myFollower) 178 { 179 if (!this->myFollower_) 180 { 181 this->myFollower_ = myFollower; 182 return true; 183 } 184 else 185 { 186 return false; 187 } 188 } 189 bool DivisionController::hasWingman() 190 { 191 if (this->myWingman_) 192 return true; 193 else 194 return false; 195 } 196 bool DivisionController::hasFollower() 197 { 198 if (this->myFollower_) 199 return true; 200 else 201 return false; 202 } 203 204 151 205 void DivisionController::XMLPort(Element& xmlelement, XMLPort::Mode mode) 152 206 { -
code/branches/AI_HS15/src/orxonox/controllers/DivisionController.h
r10729 r10731 42 42 { 43 43 public: 44 44 45 DivisionController(Context* context); 45 46 virtual ~DivisionController(); 46 47 47 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);48 virtual void tick(float dt); //<! Carrying out the targets set in action(). 48 49 49 //Using british military aircraft formations50 51 50 52 51 virtual bool setFollower(LeaderController* myFollower); 53 virtual bool setWingman(CommonController* cwingman) 54 { 55 WeakPtr<WingmanController> wingman = orxonox_cast<WingmanController*>(cwingman); 56 if (!this->myWingman_) 57 { 58 this->myWingman_ = wingman; 59 return true; 60 } 61 else 62 { 63 return false; 64 } 65 }; 66 virtual bool hasWingman() 67 { 68 if (this->myWingman_) 69 return true; 70 else 71 return false; 72 } 73 virtual bool hasFollower() 74 { 75 if (this->myFollower_) 76 return true; 77 else 78 return false; 79 }; 80 52 virtual bool setWingman(CommonController* cwingman); 53 virtual bool hasWingman(); 54 virtual bool hasFollower(); 81 55 82 virtual void tick(float dt); //<! Carrying out the targets set in action(). 83 56 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 84 57 85 58 protected: 59 86 60 void setTargetPositionOfWingman(); 87 61 void setTargetPositionOfFollower(); 62 88 63 virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour ~ setting targets. 89 64 90 65 private: 66 91 67 Timer actionTimer_; //<! Regularly calls action(). 92 68 -
code/branches/AI_HS15/src/orxonox/controllers/FleetController.cc
r10722 r10731 43 43 /* this->goalTarget_ = NULL; 44 44 this->goalProtect_ = NULL;*/ 45 this->nTicks_ = 0; 46 this->bTicked_ = false; 45 47 46 //this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&FleetController::action, this))); 48 47 } … … 63 62 { 64 63 65 /*if (nTicks_ == 30)66 {67 std::vector<WeakPtr<WingmanController> > wingmen;68 std::vector<WeakPtr<LeaderController> > leaders;69 70 //--------------------------Put all WingmanController's in a vector--------------------------71 for (ObjectList<WingmanController>::iterator it = ObjectList<WingmanController>::begin(); it; ++it)72 {73 74 75 if ((*it)->getTeam() == this->getTeam())76 {77 orxout(internal_error) << "ANOTHER SUCKER" << endl;78 wingmen.push_back(*it);79 }80 81 }82 //--------------------------Substitute half of WingmanController's with LeaderController--------------------------83 84 bool nowLeader = true;85 LeaderController* leader;86 87 for (std::vector<WeakPtr<WingmanController> >::iterator it = wingmen.begin() ; it != wingmen.end(); ++it)88 {89 if (nowLeader)90 {91 leader = new LeaderController(this->getContext());92 leader->setTeam(this->team_);93 94 (*it)->getControllableEntity()->setController(leader);95 leaders.push_back(leader);96 nowLeader = !nowLeader;97 orxout(internal_error) << "NEW SUCKER" << endl;98 99 }100 else101 {102 if (leader)103 {104 leader->setWingman(*it);105 nowLeader = !nowLeader;106 orxout(internal_error) << "I OWN THE SUCKER" << endl;107 108 }109 }110 }111 112 //--------------------------Substitute half of LeaderController's with DivisionController--------------------------113 bool nowDivision = true;114 DivisionController* division;115 116 for (std::vector<WeakPtr<LeaderController> >::iterator it = leaders.begin() ; it != leaders.end(); ++it)117 {118 if (nowDivision)119 {120 division = new DivisionController(this->getContext());121 division->setTeam(this->team_);122 123 (*it)->getControllableEntity()->setController(division);124 125 divisions_.push_back(division);126 127 nowDivision = !nowDivision;128 }129 else130 {131 if (division)132 {133 division->setLeader(*it);134 nowDivision = !nowDivision;135 }136 }137 }138 bTicked_ = true;139 nTicks_ += 1;140 }141 else if (!bTicked_)142 {143 nTicks_ += 1;144 145 }*/146 64 SUPER(FleetController, tick, dt); 147 65 -
code/branches/AI_HS15/src/orxonox/controllers/FleetController.h
r10722 r10731 83 83 virtual void action(); 84 84 private: 85 int nTicks_; 86 bool bTicked_; 87 85 88 86 std::vector<WeakPtr<DivisionController> > divisions_; 89 87 //Timer actionTimer_; //<! Regularly calls action(). -
code/branches/AI_HS15/src/orxonox/controllers/LeaderController.h
r10729 r10731 45 45 LeaderController(Context* context); 46 46 virtual ~LeaderController(); 47 virtual bool isLeader() 48 { 49 return true; 50 }; 51 bool bIsDivisionLeader_; 47 52 48 virtual bool setFollower(LeaderController* myFollower) 53 { 54 return false; 55 }; 56 virtual bool bIsDivisionLeader() 57 { 58 return bIsDivisionLeader_; 59 }; 49 { return false; } 50 60 51 virtual bool hasFollower() 61 { 62 return true; 63 }; 52 { return true; } 53 54 55 56 57 protected: 58 64 59 WeakPtr<WingmanController> myWingman_; 65 60 … … 67 62 WeakPtr<LeaderController> myDivisionLeader_; 68 63 69 70 protected: 71 64 72 65 private: 73 66 -
code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc
r10729 r10731 39 39 this->setFormationMode(WALL); 40 40 41 bIsDivisionLeader_ = false;42 41 this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&SectionController::action, this))); 43 42 this->myWingman_ = 0; 44 43 this->myDivisionLeader_ = 0; 44 this->rank_ = SECTIONLEADER; 45 45 46 46 orxout(internal_error) << this << "Was created" << endl; … … 52 52 53 53 } 54 55 void SectionController::tick(float dt) 56 { 57 if (!this->isActive()) 58 return; 59 60 if (this->bHasTargetPosition_) 61 { 62 this->moveToTargetPosition(); 63 } 64 65 66 SUPER(SectionController, tick, dt); 67 } 68 69 void SectionController::action() 70 { 71 //this->target_ = this->sectionTarget_; 72 if (!myDivisionLeader_) 73 { 74 LeaderController* newDivisionLeader = findNewDivisionLeader(); 75 this->myDivisionLeader_ = newDivisionLeader; 76 if (newDivisionLeader) 77 orxout(internal_error) << "new DivisionLeader set" << endl; 78 79 } 80 setTargetPositionOfWingman(); 81 82 } 83 54 84 void SectionController::setTargetPositionOfWingman() 55 85 { … … 85 115 86 116 } 87 88 117 LeaderController* SectionController::findNewDivisionLeader() 89 118 { … … 98 127 { 99 128 //0ptr or not DivisionController? 100 if (!(it) || !( it)->bIsDivisionLeader_|| !(it->getControllableEntity()))129 if (!(it) || !((it)->getRank() == DIVISIONLEADER) || !(it->getControllableEntity())) 101 130 continue; 102 131 //same team? … … 126 155 127 156 } 157 bool SectionController::setWingman(CommonController* cwingman) 158 { 159 WeakPtr<WingmanController> wingman = orxonox_cast<WingmanController*>(cwingman); 128 160 129 void SectionController::action() 130 { 131 //this->target_ = this->sectionTarget_; 132 if (!myDivisionLeader_) 161 if (!this->myWingman_) 133 162 { 134 LeaderController* newDivisionLeader = findNewDivisionLeader(); 135 this->myDivisionLeader_ = newDivisionLeader; 136 if (newDivisionLeader) 137 orxout(internal_error) << "new DivisionLeader set" << endl; 138 163 this->myWingman_ = wingman; 164 return true; 139 165 } 140 setTargetPositionOfWingman(); 141 142 } 143 /* 144 Wingmen and Leaders attack target_, which is a member variable of their classes. 145 Wingmen's target_ is set to sectionTarget_, which is a member variable of SectionController class, unless 146 Wingman covers Leader's rear. 147 Leader's target_ must always equal sectionTarget_. 148 if section has a target, its Leader shoots at it, but doesn't follow. 149 Every section is a part of division. Division consisting of one Section is still a division. 150 Division's leader's target_ must always equal divisionTarget_, which is a member variable of DivisionController. 151 Division leader ONLY can follow target_ while in formation flight. 152 If Division doesn't have a target, Division Leader stays in place, unless it has a waypoint. 153 Division Leader's sectionTarget_ must equal divisionTarget_, 154 but the other section, that is not a leading section, can attack any target that is near divisonTarget_ 155 156 */ 157 158 void SectionController::tick(float dt) 159 { 160 if (!this->isActive()) 161 return; 162 163 if (this->bHasTargetPosition_) 166 else 164 167 { 165 this->moveToTargetPosition();168 return false; 166 169 } 167 168 169 SUPER(SectionController, tick, dt);170 170 } 171 171 172 bool SectionController::hasWingman() 173 { 174 if (this->myWingman_) 175 return true; 176 else 177 return false; 178 } 172 179 173 180 void SectionController::XMLPort(Element& xmlelement, XMLPort::Mode mode) -
code/branches/AI_HS15/src/orxonox/controllers/SectionController.h
r10729 r10731 40 40 { 41 41 public: 42 42 43 SectionController(Context* context); 43 44 virtual ~SectionController(); 44 virtual bool setWingman(CommonController* cwingman)45 {46 WeakPtr<WingmanController> wingman = orxonox_cast<WingmanController*>(cwingman);45 46 virtual void tick(float dt); //<! Carrying out the targets set in action(). 47 47 48 48 if (!this->myWingman_) 49 { 50 this->myWingman_ = wingman; 51 return true; 52 } 53 else 54 { 55 return false; 56 } 57 } 58 59 60 virtual bool hasWingman() 61 { 62 if (this->myWingman_) 63 return true; 64 else 65 return false; 66 } 67 68 virtual void tick(float dt); //<! Carrying out the targets set in action(). 69 49 LeaderController* findNewDivisionLeader(); 50 virtual bool setWingman(CommonController* cwingman); 51 virtual bool hasWingman(); 52 70 53 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 71 LeaderController* findNewDivisionLeader();72 54 73 55 protected: 56 74 57 void setTargetPositionOfWingman(); 75 //A division is the biggest block of spaceships. 76 //In division one section is leading, the other one always stays on the same position 77 //relative to the Leader of the leading section. 78 //In section a Wingman always stays on same position relative to the Leader. 79 //That position is desiredRelativePosition_ 58 80 59 virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour ~ setting targets. 81 60 61 private: 82 62 83 84 85 86 private:87 63 Timer actionTimer_; //<! Regularly calls action(). 88 64 -
code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc
r10729 r10731 41 41 this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&WingmanController::action, this))); 42 42 this->myLeader_ = 0; 43 this->rank_ = WINGMAN; 44 43 45 } 44 46 … … 48 50 } 49 51 50 CommonController* WingmanController::findNewLeader()51 {52 53 if (!this->getControllableEntity())54 return 0;55 56 CommonController* closestLeader = 0;57 float minDistance = std::numeric_limits<float>::infinity();58 59 for (ObjectList<CommonController>::iterator it = ObjectList<CommonController>::begin(); it; ++it)60 {61 //0ptr?62 if (!it || !it->isLeader() || !(it->getControllableEntity()))63 continue;64 //same team?65 if (this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam())66 continue;67 //is equal to this?68 if (it->getControllableEntity() == this->getControllableEntity())69 continue;70 71 float distance = (it->getControllableEntity()->getPosition() - this->getControllableEntity()->getPosition()).length();72 if (distance < minDistance && !(it->hasWingman()))73 {74 closestLeader = *it;75 minDistance = distance;76 }77 78 }79 if (closestLeader)80 {81 if (closestLeader->setWingman(this))82 return closestLeader;83 }84 return 0;85 }86 87 void WingmanController::action()88 {89 if (!this->myLeader_)90 {91 CommonController* newLeader = findNewLeader();92 this->myLeader_ = newLeader;93 if (newLeader)94 orxout(internal_error) << "new Leader set" << endl;95 else96 orxout(internal_error) << "0 leader" << endl;97 98 }99 else100 {101 102 }103 }104 /*//collect data for AI behaviour105 Vector3* meanOfEnemiesPtr = new Vector3(0.0,0.0,0.0);106 Vector3* meanOfAlliesPtr = new Vector3(0.0,0.0,0.0);107 Vector3 meanOfAllies = *meanOfAlliesPtr;108 Vector3 meanOfEnemies = *meanOfEnemiesPtr;109 110 111 for (ObjectList<AIController>::iterator it = ObjectList<AIController>::begin(); it; ++it)112 {113 114 Gametype* gt=this->getGametype();115 if (!gt)116 {117 gt=it->getGametype();118 }119 if (!FormationController::sameTeam(this->getControllableEntity(), it->getControllableEntity(),gt))120 {121 enemies_.push_back(*it);122 }123 else {124 allies_.push_back(*it);125 }126 }127 if (enemies_.size() != 0 && allies_.size() != 0){128 for (std::vector<WeakPtr<AIController> >::iterator it = enemies_.begin() ; it != enemies_.end(); ++it)129 meanOfEnemies += (*it)->getControllableEntity()->getWorldPosition();130 131 meanOfEnemies /= enemies_.size();132 133 for (std::vector<WeakPtr<AIController> >::iterator it = allies_.begin() ; it != allies_.end(); ++it)134 meanOfAllies += (*it)->getControllableEntity()->getWorldPosition();135 136 meanOfAllies /= allies_.size();137 138 //orxout(internal_error) << "There are " << enemies_Counter << " enemies_, mean position is " << meanOfEnemies << endl;139 orxout(internal_error) << "Distance is " << (meanOfEnemies-meanOfAllies).length() << endl;140 orxout(internal_error) << "mean of allies_ is " << meanOfAllies << ", with a size " << allies_.size() << endl;141 orxout(internal_error) << "mean of enemies_ is " << meanOfEnemies << ", with a size " << enemies_.size() << endl;142 }*/143 144 145 146 52 void WingmanController::tick(float dt) 147 53 { … … 172 78 SUPER(WingmanController, tick, dt); 173 79 } 80 81 void WingmanController::action() 82 { 83 if (!this->myLeader_) 84 { 85 CommonController* newLeader = findNewLeader(); 86 this->myLeader_ = newLeader; 87 if (newLeader) 88 orxout(internal_error) << "new Leader set" << endl; 89 else 90 orxout(internal_error) << "0 leader" << endl; 91 92 } 93 else 94 { 95 96 } 97 } 98 99 100 101 102 CommonController* WingmanController::findNewLeader() 103 { 104 105 if (!this->getControllableEntity()) 106 return 0; 107 108 CommonController* closestLeader = 0; 109 float minDistance = std::numeric_limits<float>::infinity(); 110 111 for (ObjectList<CommonController>::iterator it = ObjectList<CommonController>::begin(); it; ++it) 112 { 113 //0ptr? 114 if (!it || 115 (it->getRank() != SECTIONLEADER && it->getRank() != DIVISIONLEADER) || 116 !(it->getControllableEntity())) 117 continue; 118 //same team? 119 if (this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam()) 120 continue; 121 //is equal to this? 122 if (it->getControllableEntity() == this->getControllableEntity()) 123 continue; 124 125 float distance = (it->getControllableEntity()->getPosition() - this->getControllableEntity()->getPosition()).length(); 126 if (distance < minDistance && !(it->hasWingman())) 127 { 128 closestLeader = *it; 129 minDistance = distance; 130 } 131 132 } 133 if (closestLeader) 134 { 135 if (closestLeader->setWingman(this)) 136 return closestLeader; 137 } 138 return 0; 139 } 174 140 175 141 void WingmanController::XMLPort(Element& xmlelement, XMLPort::Mode mode) -
code/branches/AI_HS15/src/orxonox/controllers/WingmanController.h
r10729 r10731 47 47 WingmanController(Context* context); 48 48 virtual ~WingmanController(); 49 virtual bool isLeader() 50 { 51 return false; 52 }; 53 49 54 50 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 55 51 virtual void tick(float dt); //<! Carrying out the targets set in action(). -
code/branches/AI_HS15/src/orxonox/worldentities/pawns/Pawn.cc
r10725 r10731 320 320 } 321 321 322 322 323 void Pawn::death() 323 324 { … … 325 326 if (this->getGametype() && this->getGametype()->allowPawnDeath(this, this->lastHitOriginator_)) 326 327 { 327 // Set bAlive_ to false and wait for destroyLater()to do the destruction328 // Set bAlive_ to false and wait for PawnManager to do the destruction 328 329 this->bAlive_ = false; 329 this->destroyLater();330 330 331 331 this->setDestroyWhenPlayerLeft(false); … … 367 367 if (GameMode::isMaster()) 368 368 { 369 this->deatheffect();369 // this->deathEffect(); 370 370 this->goWithStyle(); 371 371 } … … 387 387 { 388 388 // play death effect 389 /*{389 { 390 390 ParticleSpawner* effect = new ParticleSpawner(this->getContext()); 391 391 effect->setPosition(this->getPosition()); … … 410 410 effect->setSource("Orxonox/sparks"); 411 411 effect->setLifetime(4.0f); 412 }*/ 413 414 415 { 416 ParticleSpawner* effect = new ParticleSpawner(this->getContext()); 417 effect->setPosition(this->getPosition()); 418 effect->setOrientation(this->getOrientation()); 419 effect->setDestroyAfterLife(true); 420 effect->setSource("orxonox/explosion_flash2"); 421 effect->setLifetime(5.0f); 422 } 423 { 424 ParticleSpawner* effect = new ParticleSpawner(this->getContext()); 425 effect->setPosition(this->getPosition()); 426 effect->setOrientation(this->getOrientation()); 427 effect->setDestroyAfterLife(true); 428 effect->setSource("orxonox/explosion_flame2"); 429 effect->setLifetime(5.0f); 430 } 431 { 432 ParticleSpawner* effect = new ParticleSpawner(this->getContext()); 433 effect->setPosition(this->getPosition()); 434 effect->setOrientation(this->getOrientation()); 435 effect->setDestroyAfterLife(true); 436 effect->setSource("orxonox/explosion_shockwave2"); 437 effect->scale(20); 438 effect->setLifetime(5.0f); 439 }{ 440 ParticleSpawner* effect = new ParticleSpawner(this->getContext()); 441 effect->setPosition(this->getPosition()); 442 effect->setOrientation(this->getOrientation()); 443 effect->setDestroyAfterLife(true); 444 effect->setSource("orxonox/explosion_sparks2"); 445 effect->setLifetime(5.0f); 446 } 447 { 448 ParticleSpawner* effect = new ParticleSpawner(this->getContext()); 449 effect->setPosition(this->getPosition()); 450 effect->setOrientation(this->getOrientation()); 451 effect->setDestroyAfterLife(true); 452 effect->setSource("orxonox/explosion_streak2"); 453 effect->setLifetime(5.0f); 454 } 455 { 456 ParticleSpawner* effect = new ParticleSpawner(this->getContext()); 457 effect->setPosition(this->getPosition()); 458 effect->setOrientation(this->getOrientation()); 459 effect->setDestroyAfterLife(true); 460 effect->setSource("orxonox/explosion_afterglow"); 461 effect->scale(20); 462 effect->setLifetime(5.0f); 463 } 464 465 412 } 466 413 for (unsigned int i = 0; i < this->numexplosionchunks_; ++i) 467 414 { -
code/branches/AI_HS15/src/orxonox/worldentities/pawns/Pawn.h
r10437 r10731 39 39 40 40 namespace orxonox // tolua_export 41 { 42 /** 43 @brief 44 Everything in Orxonoy that has a health attribute is a Pawn. After a Pawn is spawned its health is set to 45 its initial health. In every call of the Pawns tick function the game checks whether the pawns health is at 46 or below zero. If it is, the pawn gets killed. 47 48 Pawns can carry pickups and fire weapons. The can also have shields. 49 50 Notice that every Pawn is a ControllableEntity. 51 */ 52 53 // tolua_export 41 { // tolua_export 54 42 class _OrxonoxExport Pawn // tolua_export 55 43 : public ControllableEntity, public RadarViewable, public PickupCarrier
Note: See TracChangeset
for help on using the changeset viewer.