Changeset 11071 for code/trunk/src/orxonox/controllers/WingmanController.cc
- Timestamp:
- Jan 17, 2016, 10:29:21 PM (9 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/controllers/WingmanController.cc
r11052 r11071 39 39 { 40 40 RegisterObject(WingmanController); 41 this->myLeader_ = 0;41 this->myLeader_ = nullptr; 42 42 this->bFirstAction_ = true; 43 43 … … 46 46 WingmanController::~WingmanController() 47 47 { 48 for ( size_t i = 0; i < this->actionpoints_.size(); ++i)48 for (WorldEntity* actionpoint : this->actionpoints_) 49 49 { 50 if (this->actionpoints_[i])51 this->actionpoints_[i]->destroy();50 if (actionpoint) 51 actionpoint->destroy(); 52 52 } 53 53 this->parsedActionpoints_.clear(); 54 54 this->actionpoints_.clear(); 55 }56 57 void WingmanController::XMLPort(Element& xmlelement, XMLPort::Mode mode)58 {59 SUPER(WingmanController, XMLPort, xmlelement, mode);60 }61 62 //----in tick, move (or look) and shoot----63 void WingmanController::tick(float dt)64 {65 if (!this->isActive())66 return;67 68 SUPER(WingmanController, tick, dt);69 70 55 } 71 56 … … 122 107 Vector3 WingmanController::getFormationPosition () 123 108 { 124 125 126 109 this->setFormationMode( this->myLeader_->getFormationMode() ); 127 Vector3* targetRelativePosition;128 110 this->spread_ = this->myLeader_->getSpread(); 129 111 if (this->myLeader_->getIdentifier()->getName() == "DivisionController") … … 131 113 switch (this->formationMode_){ 132 114 case FormationMode::WALL: 133 { 134 targetRelativePosition = new Vector3 (2.0f*this->spread_, 0, 0 - 1.0f*this->tolerance_); 135 break; 136 } 115 return Vector3 (2.0f*this->spread_, 0, 0 - 1.0f*this->tolerance_); 137 116 case FormationMode::FINGER4: 138 { 139 targetRelativePosition = new Vector3 (2.0f*this->spread_, 0, this->spread_ - 1.0f*this->tolerance_); 140 break; 141 } 117 return Vector3 (2.0f*this->spread_, 0, this->spread_ - 1.0f*this->tolerance_); 142 118 case FormationMode::DIAMOND: 143 { 144 targetRelativePosition = new Vector3 (2.0f*this->spread_, 0, this->spread_ - 1.0f*this->tolerance_); 145 break; 146 } 119 return Vector3 (2.0f*this->spread_, 0, this->spread_ - 1.0f*this->tolerance_); 120 default: 121 return Vector3::ZERO; 147 122 } 148 123 } … … 151 126 switch (this->formationMode_){ 152 127 case FormationMode::WALL: 153 { 154 targetRelativePosition = new Vector3 (-2.0f*this->spread_, 0, 0 - 1.0f*this->tolerance_); 155 break; 156 } 128 return Vector3 (-2.0f*this->spread_, 0, 0 - 1.0f*this->tolerance_); 157 129 case FormationMode::FINGER4: 158 { 159 targetRelativePosition = new Vector3 (-2.0f*this->spread_, 0, this->spread_ - 1.0f*this->tolerance_); 160 break; 161 } 130 return Vector3 (-2.0f*this->spread_, 0, this->spread_ - 1.0f*this->tolerance_); 162 131 case FormationMode::DIAMOND: 163 { 164 targetRelativePosition = new Vector3 (2.0f*this->spread_, -1.0f*this->spread_, 0 - 1.0f*this->tolerance_); 165 break; 166 } 132 return Vector3 (2.0f*this->spread_, -1.0f*this->spread_, 0 - 1.0f*this->tolerance_); 133 default: 134 return Vector3::ZERO; 167 135 } 168 136 } 169 Vector3 result = *targetRelativePosition;170 delete targetRelativePosition;171 return result;172 137 } 173 138 void WingmanController::keepFormation() … … 185 150 186 151 if (!this->getControllableEntity()) 187 return 0;152 return nullptr; 188 153 189 154 //----vars for finding the closest leader---- 190 ActionpointController* closestLeader = 0;155 ActionpointController* closestLeader = nullptr; 191 156 float minDistance = std::numeric_limits<float>::infinity(); 192 157 Gametype* gt = this->getGametype(); 193 158 194 for ( ObjectList<ActionpointController>::iterator it = ObjectList<ActionpointController>::begin(); it; ++it)159 for (ActionpointController* controller : ObjectList<ActionpointController>()) 195 160 { 196 161 //----0ptr or not a leader or dead?---- 197 if (! it ||198 ( it->getIdentifier()->getName() != "SectionController" && it->getIdentifier()->getName() != "DivisionController") ||199 !( it->getControllableEntity()))162 if (!controller || 163 (controller->getIdentifier()->getName() != "SectionController" && controller->getIdentifier()->getName() != "DivisionController") || 164 !(controller->getControllableEntity())) 200 165 continue; 201 166 202 167 //----same team?---- 203 if ( !CommonController::sameTeam (this->getControllableEntity(), (it)->getControllableEntity(), gt) )168 if ( !CommonController::sameTeam (this->getControllableEntity(), controller->getControllableEntity(), gt) ) 204 169 continue; 205 170 206 171 //----check distance---- 207 float distance = CommonController::distance ( it->getControllableEntity(), this->getControllableEntity());208 if (distance < minDistance && !( it->hasWingman()))172 float distance = CommonController::distance (controller->getControllableEntity(), this->getControllableEntity()); 173 if (distance < minDistance && !(controller->hasWingman())) 209 174 { 210 closestLeader = *it;175 closestLeader = controller; 211 176 minDistance = distance; 212 177 } … … 222 187 } 223 188 } 224 return 0;189 return nullptr; 225 190 } 226 191
Note: See TracChangeset
for help on using the changeset viewer.