Changeset 11071 for code/trunk/src/orxonox/controllers/SectionController.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/SectionController.cc
r11052 r11071 40 40 this->setFormationMode(FormationMode::FINGER4); 41 41 42 this->myWingman_ = 0;43 this->myDivisionLeader_ = 0;42 this->myWingman_ = nullptr; 43 this->myDivisionLeader_ = nullptr; 44 44 this->bFirstAction_ = true; 45 45 … … 48 48 SectionController::~SectionController() 49 49 { 50 for (size_t i = 0; i < this->actionpoints_.size(); ++i)51 { 52 if (this->actionpoints_[i])53 this->actionpoints_[i]->destroy();50 for (WorldEntity* actionpoint : this->actionpoints_) 51 { 52 if (actionpoint) 53 actionpoint->destroy(); 54 54 } 55 55 this->parsedActionpoints_.clear(); 56 56 this->actionpoints_.clear(); 57 }58 void SectionController::XMLPort(Element& xmlelement, XMLPort::Mode mode)59 {60 SUPER(SectionController, XMLPort, xmlelement, mode);61 }62 63 //----in tick, move (or look) and shoot----64 void SectionController::tick(float dt)65 {66 if (!this->isActive())67 return;68 69 SUPER(SectionController, tick, dt);70 71 57 } 72 58 … … 131 117 { 132 118 //----If division leader fights, cover him by fighting emenies close to his target---- 133 Action ::Valueaction = this->myDivisionLeader_->getAction();119 Action action = this->myDivisionLeader_->getAction(); 134 120 135 121 if (action == Action::FIGHT || action == Action::FIGHTALL || action == Action::ATTACK) … … 147 133 Vector3 divisionTargetPosition = this->myDivisionLeader_->getTarget()->getWorldPosition(); 148 134 Gametype* gt = this->getGametype(); 149 for ( ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)135 for (Pawn* pawn : ObjectList<Pawn>()) 150 136 { 151 137 //----is enemy?---- 152 if ( CommonController::sameTeam (this->getControllableEntity(), static_cast<ControllableEntity*>( *itP), gt) )138 if ( CommonController::sameTeam (this->getControllableEntity(), static_cast<ControllableEntity*>(pawn), gt) ) 153 139 continue; 154 140 //----in range?---- 155 if (( (*itP)->getWorldPosition() - divisionTargetPosition).length() < 3000 &&156 (*itP)!= this->myDivisionLeader_->getTarget())141 if ((pawn->getWorldPosition() - divisionTargetPosition).length() < 3000 && 142 pawn != this->myDivisionLeader_->getTarget()) 157 143 { 158 144 foundTarget = true; 159 target = (*itP);145 target = pawn; 160 146 break; 161 147 } … … 188 174 this->setFormationMode( this->myDivisionLeader_->getFormationMode() ); 189 175 this->spread_ = this->myDivisionLeader_->getSpread(); 190 Vector3* targetRelativePosition;191 176 switch (this->formationMode_){ 192 177 case FormationMode::WALL: 193 { 194 targetRelativePosition = new Vector3 (-2.0f*this->spread_, 0, 0); 195 break; 196 } 178 return Vector3 (-2.0f*this->spread_, 0, 0); 179 197 180 case FormationMode::FINGER4: 198 { 199 targetRelativePosition = new Vector3 (-2.0f*this->spread_, 0, 1.0f*this->spread_); 200 break; 201 } 181 return Vector3 (-2.0f*this->spread_, 0, 1.0f*this->spread_); 202 182 203 183 case FormationMode::DIAMOND: 204 { 205 targetRelativePosition = new Vector3 (-2.0f*this->spread_, 0, 1.0f*this->spread_); 206 break; 207 } 208 } 209 Vector3 result = *targetRelativePosition; 210 delete targetRelativePosition; 211 return result; 184 return Vector3 (-2.0f*this->spread_, 0, 1.0f*this->spread_); 185 186 default: 187 return Vector3::ZERO; 188 } 212 189 } 213 190 … … 226 203 227 204 if (!this->getControllableEntity()) 228 return 0;229 230 ActionpointController* closestLeader = 0;205 return nullptr; 206 207 ActionpointController* closestLeader = nullptr; 231 208 float minDistance = std::numeric_limits<float>::infinity(); 232 209 //go through all pawns 233 for ( ObjectList<ActionpointController>::iterator it = ObjectList<ActionpointController>::begin(); it; ++it)210 for (ActionpointController* controller : ObjectList<ActionpointController>()) 234 211 { 235 212 //0ptr or not DivisionController? 236 if (! (it) || !((it)->getIdentifier()->getName() == "DivisionController") || !(it->getControllableEntity()))213 if (!controller || !(controller->getIdentifier()->getName() == "DivisionController") || !(controller->getControllableEntity())) 237 214 continue; 238 215 //same team? 239 if ((this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam()))216 if ((this->getControllableEntity()->getTeam() != controller->getControllableEntity()->getTeam())) 240 217 continue; 241 218 242 219 //is equal to this? 243 if (orxonox_cast<ControllableEntity*>( *it) == this->getControllableEntity())220 if (orxonox_cast<ControllableEntity*>(controller) == this->getControllableEntity()) 244 221 continue; 245 222 246 float distance = CommonController::distance ( it->getControllableEntity(), this->getControllableEntity());223 float distance = CommonController::distance (controller->getControllableEntity(), this->getControllableEntity()); 247 224 248 if (distance < minDistance && !( it->hasFollower()))249 { 250 closestLeader = *it;225 if (distance < minDistance && !(controller->hasFollower())) 226 { 227 closestLeader = controller; 251 228 minDistance = distance; 252 229 } … … 258 235 return closestLeader; 259 236 } 260 return 0;237 return nullptr; 261 238 } 262 239
Note: See TracChangeset
for help on using the changeset viewer.