Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 11, 2010, 8:55:13 AM (14 years ago)
Author:
dafrick
Message:

Merged presentation3 branch into trunk.

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/modules/pickup/PickupManager.cc

    • Property svn:eol-style set to native
    r6752 r7163  
    3939#include "core/ScopedSingletonManager.h"
    4040#include "core/Identifier.h"
     41#include "util/Convert.h"
    4142#include "interfaces/PickupCarrier.h"
    4243#include "infos/PlayerInfo.h"
    4344#include "worldentities/pawns/Pawn.h"
     45#include "CollectiblePickup.h"
    4446#include "PickupRepresentation.h"
    4547
     
    5052    // Register tolua_open function when loading the library
    5153    DeclareToluaInterface(Pickup);
    52    
    53     ManageScopedSingleton(PickupManager, ScopeID::Graphics, false);
    54    
     54
     55    ManageScopedSingleton(PickupManager, ScopeID::Root, false);
     56
    5557    /*static*/ const std::string PickupManager::guiName_s = "PickupInventory";
    56    
     58
    5759    /**
    5860    @brief
     
    6264    {
    6365        RegisterRootObject(PickupManager);
    64        
     66
     67        //TODO: This doesn't work, yet.
     68        if( GameMode::showsGraphics() )
     69        {
     70            GUIManager::getInstance().loadGUI(PickupManager::guiName_s);
     71        }
    6572        this->defaultRepresentation_ = new PickupRepresentation();
    66        
     73
    6774        COUT(3) << "PickupManager created." << std::endl;
    6875    }
    69    
     76
    7077    /**
    7178    @brief
     
    7784        if(this->defaultRepresentation_ != NULL)
    7885            this->defaultRepresentation_->destroy();
    79        
     86
    8087        this->representations_.clear();
    81        
     88
    8289        COUT(3) << "PickupManager destroyed." << std::endl;
    8390    }
    84    
     91
    8592    /**
    8693    @brief
     
    95102    */
    96103    bool PickupManager::registerRepresentation(const PickupIdentifier* identifier, PickupRepresentation* representation)
    97     {       
     104    {
    98105        if(identifier == NULL || representation == NULL || this->representations_.find(identifier) != this->representations_.end()) //!< If the Pickupable already has a Representation registered.
    99106            return false;
    100        
     107
    101108        this->representations_[identifier] = representation;
    102        
     109
    103110        COUT(4) << "PickupRepresentation " << representation << " registered with the PickupManager." << std::endl;
    104111        return true;
    105112    }
    106    
     113
    107114    /**
    108115    @brief
     
    116123    */
    117124    bool PickupManager::unregisterRepresentation(const PickupIdentifier* identifier, PickupRepresentation* representation)
    118     {       
     125    {
    119126        if(identifier == NULL || representation == NULL)
    120127            return false;
    121        
     128
    122129        std::map<const PickupIdentifier*, PickupRepresentation*, PickupIdentifierCompare>::iterator it = this->representations_.find(identifier);
    123130        if(it == this->representations_.end()) //!< If the Pickupable is not registered in the first place.
    124131            return false;
    125        
     132
    126133        this->representations_.erase(it);
    127        
     134
    128135        COUT(4) << "PickupRepresentation " << representation << " unregistered with the PickupManager." << std::endl;
    129136        return true;
    130137    }
    131    
     138
    132139    /**
    133140    @brief
     
    146153            return this->defaultRepresentation_;
    147154        }
    148        
     155
    149156        return it->second;
    150157    }
    151    
    152     PickupCarrier* PickupManager::getPawn(void)
    153     {
     158
     159    int PickupManager::getNumPickups(void)
     160    {
     161        this->pickupsList_.clear();
     162
    154163        PlayerInfo* player = GUIManager::getInstance().getPlayer(PickupManager::guiName_s);
     164        PickupCarrier* carrier = NULL;
    155165        if (player != NULL)
    156             return dynamic_cast<PickupCarrier*>(player->getControllableEntity());
     166            carrier = dynamic_cast<PickupCarrier*>(player->getControllableEntity());
    157167        else
    158             return NULL;
    159     }
    160    
    161     int PickupManager::getNumCarrierChildren(PickupCarrier* carrier)
    162     {
    163         if(carrier == NULL)
    164168            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)
    202             carrier->drop(pickup);
    203     }
    204    
    205     void PickupManager::usePickup(int index, PickupCarrier* carrier, bool use)
    206     {
    207         Pickupable* pickup = carrier->getPickup(index);
    208         if(pickup != NULL)
     169
     170        std::vector<PickupCarrier*>* carriers = this->getAllCarriers(carrier);
     171        for(std::vector<PickupCarrier*>::iterator it = carriers->begin(); it != carriers->end(); it++)
     172        {
     173            std::set<Pickupable*> pickups = (*it)->getPickups();
     174            for(std::set<Pickupable*>::iterator pickup = pickups.begin(); pickup != pickups.end(); pickup++)
     175            {
     176                CollectiblePickup* collectible = orxonox_cast<CollectiblePickup*>(*pickup);
     177                if(collectible == NULL || !collectible->isInCollection())
     178                    this->pickupsList_.insert(std::pair<Pickupable*, WeakPtr<Pickupable> >(*pickup, WeakPtr<Pickupable>(*pickup)));
     179            }
     180        }
     181        delete carriers;
     182
     183        this->pickupsIterator_ = this->pickupsList_.begin();
     184        return this->pickupsList_.size();
     185    }
     186
     187    std::vector<PickupCarrier*>* PickupManager::getAllCarriers(PickupCarrier* carrier)
     188    {
     189        //TODO: More efficiently.
     190        std::vector<PickupCarrier*>* carriers = new std::vector<PickupCarrier*>();
     191        carriers->insert(carriers->end(), carrier);
     192        std::vector<PickupCarrier*>* children = carrier->getCarrierChildren();
     193        for(std::vector<PickupCarrier*>::iterator it = children->begin(); it != children->end(); it++)
     194        {
     195            std::vector<PickupCarrier*>* childrensChildren = this->getAllCarriers(*it);
     196            for(std::vector<PickupCarrier*>::iterator it2 = childrensChildren->begin(); it2 != childrensChildren->end(); it2++)
     197            {
     198                carriers->insert(carriers->end(), *it2);
     199            }
     200            delete childrensChildren;
     201        }
     202        delete children;
     203        return carriers;
     204    }
     205
     206    void PickupManager::dropPickup(orxonox::Pickupable* pickup)
     207    {
     208        std::map<Pickupable*, WeakPtr<Pickupable> >::iterator it = this->pickupsList_.find(pickup);
     209        if(pickup == NULL || it == this->pickupsList_.end() || it->second.get() == NULL)
     210            return;
     211
     212        if(!pickup->isPickedUp())
     213            return;
     214
     215        PickupCarrier* carrier = pickup->getCarrier();
     216        if(pickup != NULL && carrier != NULL)
     217        {
     218            pickup->drop(carrier);
     219        }
     220    }
     221
     222    void PickupManager::usePickup(orxonox::Pickupable* pickup, bool use)
     223    {
     224        std::map<Pickupable*, WeakPtr<Pickupable> >::iterator it = this->pickupsList_.find(pickup);
     225        if(pickup == NULL || it == this->pickupsList_.end() || it->second.get() == NULL)
     226            return;
     227
     228        if(!pickup->isPickedUp())
     229            return;
     230
     231        PickupCarrier* carrier = pickup->getCarrier();
     232        if(pickup != NULL && carrier != NULL)
    209233            pickup->setUsed(use);
    210234    }
    211    
     235
    212236}
Note: See TracChangeset for help on using the changeset viewer.