Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 24, 2010, 4:59:23 PM (14 years ago)
Author:
dafrick
Message:

Cleaned up in PickupInventory, to be able to improve it at a later stage.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation3/src/modules/pickup/PickupManager.cc

    r6752 r6965  
    6464       
    6565        this->defaultRepresentation_ = new PickupRepresentation();
     66        this->pickupsIndex_ = 0;
    6667       
    6768        COUT(3) << "PickupManager created." << std::endl;
     
    149150        return it->second;
    150151    }
    151    
    152     PickupCarrier* PickupManager::getPawn(void)
    153     {
     152
     153    int PickupManager::getNumPickups(void)
     154    {
     155        this->pickupsList_.clear();
     156        this->pickupsIndex_ = 0;
     157       
    154158        PlayerInfo* player = GUIManager::getInstance().getPlayer(PickupManager::guiName_s);
     159        PickupCarrier* carrier = NULL;
    155160        if (player != NULL)
    156             return dynamic_cast<PickupCarrier*>(player->getControllableEntity());
     161            carrier = dynamic_cast<PickupCarrier*>(player->getControllableEntity());
    157162        else
    158             return NULL;
    159     }
    160    
    161     int PickupManager::getNumCarrierChildren(PickupCarrier* carrier)
    162     {
    163         if(carrier == NULL)
    164163            return 0;
    165         return carrier->getNumCarrierChildren();
    166     }
    167            
    168     PickupCarrier* PickupManager::getCarrierChild(int index, PickupCarrier* carrier)
    169     {
    170         if(carrier == NULL)
    171             return NULL;
    172         return carrier->getCarrierChild(index);
    173     }
    174    
    175     const std::string& PickupManager::getCarrierName(orxonox::PickupCarrier* carrier)
    176     {
    177         if(carrier == NULL)
    178             return BLANKSTRING;
    179         return carrier->getCarrierName();
    180     }
    181    
    182     PickupRepresentation* PickupManager::getPickupRepresentation(int index, PickupCarrier* carrier)
    183     {
    184         Pickupable* pickup = carrier->getPickup(index);
    185         if(pickup == NULL)
    186             return NULL;
    187        
    188         return this->getRepresentation(pickup->getPickupIdentifier());
    189     }
    190    
    191     int PickupManager::getNumPickups(PickupCarrier* carrier)
    192     {
    193         if(carrier == NULL)
    194             return 0;
    195         return carrier->getNumPickups();
    196     }
    197    
    198     void PickupManager::dropPickup(int index, PickupCarrier* carrier)
    199     {
    200         Pickupable* pickup = carrier->getPickup(index);
    201         if(pickup != NULL)
     164
     165        std::vector<PickupCarrier*>* carriers = this->getAllCarriers(carrier);
     166        for(std::vector<PickupCarrier*>::iterator it = carriers->begin(); it != carriers->end(); it++)
     167        {
     168            std::set<Pickupable*> pickups = (*it)->getPickups();
     169            for(std::set<Pickupable*>::iterator pickup = pickups.begin(); pickup != pickups.end(); pickup++)
     170            {
     171                this->pickupsList_.insert(*pickup);
     172            }
     173        }
     174        delete carriers;
     175
     176        this->pickupsIterator_ = this->pickupsList_.begin();
     177        return this->pickupsList_.size();
     178    }
     179
     180    std::vector<PickupCarrier*>* PickupManager::getAllCarriers(PickupCarrier* carrier)
     181    {
     182        //TODO: More efficiently.
     183        std::vector<PickupCarrier*>* carriers = new std::vector<PickupCarrier*>();
     184        carriers->insert(carriers->end(), carrier);
     185        std::vector<PickupCarrier*>* children = carrier->getCarrierChildren();
     186        for(std::vector<PickupCarrier*>::iterator it = children->begin(); it != children->end(); it++)
     187        {
     188            std::vector<PickupCarrier*>* childrensChildren = this->getAllCarriers(*it);
     189            for(std::vector<PickupCarrier*>::iterator it2 = childrensChildren->begin(); it2 != childrensChildren->end(); it2++)
     190            {
     191                carriers->insert(carriers->end(), *it2);
     192            }
     193            delete childrensChildren;
     194        }
     195        delete children;
     196        return carriers;
     197    }
     198
     199    void PickupManager::dropPickup(orxonox::Pickupable* pickup)
     200    {
     201        if(!pickup->isPickedUp())
     202            return;
     203       
     204        PickupCarrier* carrier = pickup->getCarrier();
     205        if(pickup != NULL && carrier != NULL)
    202206            carrier->drop(pickup);
    203207    }
    204    
    205     void PickupManager::usePickup(int index, PickupCarrier* carrier, bool use)
    206     {
    207         Pickupable* pickup = carrier->getPickup(index);
    208         if(pickup != NULL)
     208
     209    void PickupManager::usePickup(orxonox::Pickupable* pickup, bool use)
     210    {
     211        if(!pickup->isPickedUp())
     212            return;
     213
     214        PickupCarrier* carrier = pickup->getCarrier();
     215        if(pickup != NULL && carrier != NULL)
    209216            pickup->setUsed(use);
    210217    }
Note: See TracChangeset for help on using the changeset viewer.