Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jan 10, 2016, 1:54:11 PM (9 years ago)
Author:
landauf
Message:

merged branch cpp11_v2 into cpp11_v3

Location:
code/branches/cpp11_v3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/cpp11_v3

  • code/branches/cpp11_v3/src/orxonox/worldentities/pawns/ModularSpaceShip.cc

    r10624 r11054  
    5353    RegisterClass(ModularSpaceShip);
    5454
    55     std::map<StaticEntity*, ShipPart*>* ModularSpaceShip::partMap_s = 0;
     55    std::map<StaticEntity*, ShipPart*>* ModularSpaceShip::partMap_s = nullptr;
    5656
    5757    ModularSpaceShip::ModularSpaceShip(Context* context) : SpaceShip(context)
     
    9494        for (unsigned int i=0; i < this->getAttachedObjects().size(); i++)
    9595        {
    96             if (this->getAttachedObject(i) == NULL)
     96            if (this->getAttachedObject(i) == nullptr)
    9797            {
    9898                break;
    9999            }
    100100            // iterate through all attached parts
    101             for(unsigned int j = 0; j < this->partList_.size(); j++)
     101            for(ShipPart* part : this->partList_)
    102102            {
    103103                // if the name of the part matches the name of the object, add the object to that parts entitylist (unless it was already done).
    104                 if((this->partList_[j]->getName() == this->getAttachedObject(i)->getName()) && !this->partList_[j]->hasEntity(orxonox_cast<StaticEntity*>(this->getAttachedObject(i))))
     104                if((part->getName() == this->getAttachedObject(i)->getName()) && !part->hasEntity(orxonox_cast<StaticEntity*>(this->getAttachedObject(i))))
    105105                {
    106106                    // The Entity is added to the part's entityList_
    107                     this->partList_[j]->addEntity(orxonox_cast<StaticEntity*>(this->getAttachedObject(i)));
     107                    part->addEntity(orxonox_cast<StaticEntity*>(this->getAttachedObject(i)));
    108108                    // An entry in the partMap_ is created, assigning the part to the entity.
    109                     this->addPartEntityAssignment((StaticEntity*)(this->getAttachedObject(i)), this->partList_[j]);
     109                    this->addPartEntityAssignment((StaticEntity*)(this->getAttachedObject(i)), part);
    110110                }
    111111            }
     
    146146    ShipPart* ModularSpaceShip::getPartOfEntity(StaticEntity* entity) const
    147147    {
    148         for (std::map<StaticEntity*, ShipPart*>::const_iterator it = this->partMap_.begin(); it != this->partMap_.end(); ++it)
    149         {
    150             if (it->first == entity)
    151                 return it->second;
    152         }
    153         return NULL;
     148        for (const auto& mapEntry : this->partMap_)
     149        {
     150            if (mapEntry.first == entity)
     151                return mapEntry.second;
     152        }
     153        return nullptr;
    154154    }
    155155
     
    160160    void ModularSpaceShip::damage(float damage, float healthdamage, float shielddamage, Pawn* originator, const btCollisionShape* cs)
    161161    {
    162         if (cs != NULL && this->getPartOfEntity((StaticEntity*)(cs->getUserPointer())) != NULL)
     162        if (cs != nullptr && this->getPartOfEntity((StaticEntity*)(cs->getUserPointer())) != nullptr)
    163163            this->getPartOfEntity((StaticEntity*)(cs->getUserPointer()))->handleHit(damage, healthdamage, shielddamage, originator);
    164164        else
     
    174174    void ModularSpaceShip::killShipPartStatic(std::string name)
    175175    {
    176         for (std::map<StaticEntity*, ShipPart*>::const_iterator it = ModularSpaceShip::partMap_s->begin(); it != ModularSpaceShip::partMap_s->end(); ++it)
    177         {
    178             if (it->second->getName() == name)
    179             {
    180                 it->second->death();
     176        for (const auto& mapEntry : *ModularSpaceShip::partMap_s)
     177        {
     178            if (mapEntry.second->getName() == name)
     179            {
     180                mapEntry.second->death();
    181181                return;
    182182            }
     
    193193    void ModularSpaceShip::killShipPart(std::string name)
    194194    {
    195         for (std::map<StaticEntity*, ShipPart*>::const_iterator it = ModularSpaceShip::partMap_.begin(); it != ModularSpaceShip::partMap_.end(); ++it)
    196         {
    197             if (it->second->getName() == name)
    198             {
    199                 it->second->death();
     195        for (const auto& mapEntry : ModularSpaceShip::partMap_)
     196        {
     197            if (mapEntry.second->getName() == name)
     198            {
     199                mapEntry.second->death();
    200200                return;
    201201            }
     
    212212    void ModularSpaceShip::addShipPart(ShipPart* part)
    213213    {
    214         OrxAssert(part != NULL, "The ShipPart cannot be NULL.");
     214        OrxAssert(part != nullptr, "The ShipPart cannot be nullptr.");
    215215        this->partList_.push_back(part);
    216216        part->setParent(this);
     
    222222        Get the i-th ShipPart of the SpaceShip.
    223223    @return
    224         Returns a pointer to the i-the ShipPart. NULL if there is no ShipPart with that index.
     224        Returns a pointer to the i-the ShipPart. nullptr if there is no ShipPart with that index.
    225225    */
    226226    ShipPart* ModularSpaceShip::getShipPart(unsigned int index)
    227227    {
    228228        if(this->partList_.size() <= index)
    229             return NULL;
     229            return nullptr;
    230230        else
    231231            return this->partList_[index];
     
    238238        The name of the ShipPart to be returned.
    239239    @return
    240         Pointer to the ShipPart with the given name, or NULL if not found.
     240        Pointer to the ShipPart with the given name, or nullptr if not found.
    241241    */
    242242    ShipPart* ModularSpaceShip::getShipPartByName(std::string name)
    243243    {
    244         for(std::vector<ShipPart*>::iterator it = this->partList_.begin(); it != this->partList_.end(); ++it)
    245         {
    246             if(orxonox_cast<ShipPart*>(*it)->getName() == name)
    247             {
    248                 return orxonox_cast<ShipPart*>(*it);
     244        for(ShipPart* part : this->partList_)
     245        {
     246            if(orxonox_cast<ShipPart*>(part)->getName() == name)
     247            {
     248                return orxonox_cast<ShipPart*>(part);
    249249            }
    250250        }
    251251        orxout(internal_warning) << "Couldn't find ShipPart with name \"" << name << "\"." << endl;
    252         return NULL;
     252        return nullptr;
    253253    }
    254254
     
    256256    @brief
    257257        Check whether the SpaceShip has a particular Engine.
    258     @param engine
     258    @param search
    259259        A pointer to the Engine to be checked.
    260260    */
    261     bool ModularSpaceShip::hasShipPart(ShipPart* part) const
    262     {
    263         for(unsigned int i = 0; i < this->partList_.size(); i++)
    264         {
    265             if(this->partList_[i] == part)
     261    bool ModularSpaceShip::hasShipPart(ShipPart* search) const
     262    {
     263        for(ShipPart* part : this->partList_)
     264        {
     265            if(part == search)
    266266                return true;
    267267        }
Note: See TracChangeset for help on using the changeset viewer.