- Timestamp:
- Oct 29, 2015, 8:02:23 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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)
Note: See TracChangeset
for help on using the changeset viewer.