Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7162


Ignore:
Timestamp:
Aug 8, 2010, 8:53:52 PM (14 years ago)
Author:
dafrick
Message:

Significant structural changes to the pickup module. Lots of bugs found and fixed.
Introduced a new class CollectiblePickup (which is now the only kind a PickupCollection can consist of) to solve some issues cleanly.
MetaPickup received additional functionality. It can now also be set to either destroy all the pickups of a PickupCarrier or destroy the PickupCarrier itself. (This was done mainly for testing purposes)
I've done some extensive testing on the pickups, so they should really work now.

Location:
code/branches/presentation3
Files:
2 added
29 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation3/data/gui/scripts/PickupInventory.lua

    r7072 r7162  
    5454                        useButton:setText("unuse")
    5555                        orxonox.GUIManager:subscribeEventHelper(useButton, "Clicked", P.name .. ".InventoryUseDetailButton_clicked")
     56                        if pickup:isUsable() == false then
     57                            useButton:setEnabled(false)
     58                        end
    5659                    else
    5760                        useButton:setText("use")
    5861                        orxonox.GUIManager:subscribeEventHelper(useButton, "Clicked", P.name .. ".InventoryUnuseDetailButton_clicked")
     62                        if pickup:isUnusable() == false then
     63                            useButton:setEnabled(false)
     64                        end
    5965                    end
    6066
     
    130136        useButton:setText("use")
    131137        orxonox.GUIManager:subscribeEventHelper(useButton, "Clicked", P.name .. ".InventoryUseButton_clicked")
     138        if pickup:isUsable() == false then
     139            useButton:setEnabled(false)
     140        end
    132141    else
    133142        useButton:setText("unuse")
    134143        orxonox.GUIManager:subscribeEventHelper(useButton, "Clicked", P.name .. ".InventoryUnuseButton_clicked")
     144        if pickup:isUnusable() == false then
     145            useButton:setEnabled(false)
     146        end
    135147    end
    136148    item:addChildWindow(useButton)
     
    229241        useButton:setText("use")
    230242        orxonox.GUIManager:subscribeEventHelper(useButton, "Clicked", P.name .. ".InventoryUseDetailButton_clicked")
     243        if pickup:isUsable() == false then
     244            useButton:setEnabled(false)
     245        end
    231246    else
    232247        useButton:setText("unuse")
    233248        orxonox.GUIManager:subscribeEventHelper(useButton, "Clicked", P.name .. ".InventoryUnuseDetailButton_clicked")
     249        if pickup:isUnusable() == false then
     250            useButton:setEnabled(false)
     251        end
    234252    end
    235253    wrapper:addChildWindow(useButton)
  • code/branches/presentation3/data/levels/pickups.oxw

    r7083 r7162  
    136136    </PickupSpawner>
    137137
     138    <PickupSpawner position="25,75,-125" triggerDistance="10" respawnTime="5" maxSpawnedItems="10">
     139      <pickup>
     140        <MetaPickup metaType="destroy" />
     141      </pickup>
     142    </PickupSpawner>
     143
     144    <PickupSpawner position="50,75,-125" triggerDistance="10" respawnTime="5" maxSpawnedItems="10">
     145      <pickup>
     146        <MetaPickup metaType="destroyCarrier" />
     147      </pickup>
     148    </PickupSpawner>
     149
    138150    <!-- Pickup Collection pickups -->
    139151
     
    162174    >
    163175      <pickup>
    164         <HealthPickup health=50 activationType="onUse" durationType="once" />
     176        <HealthPickup health=500 activationType=immediate healthRate=10 durationType=continuous />
    165177      </pickup>
    166178    </PickupRepresentation>
     
    168180    <PickupSpawner position="-50,0,-125" respawnTime="60" triggerDistance="20" maxSpawnedItems="5">
    169181      <pickup>
    170         <HealthPickup health=50 activationType=onUse durationType=once />
     182        <HealthPickup health=500 activationType=immediate healthRate=10 durationType=continuous />
    171183      </pickup>
    172184    </PickupSpawner>
  • code/branches/presentation3/src/modules/pickup/CMakeLists.txt

    r7135 r7162  
    11SET_SOURCE_FILES(PICKUP_SRC_FILES
     2  CollectiblePickup.cc
    23  DroppedPickup.cc
    34  Pickup.cc
  • code/branches/presentation3/src/modules/pickup/Pickup.cc

    r7129 r7162  
    194194
    195195        //! Sets the Pickup to used if the Pickup has activation type 'immediate' and gets picked up.
    196         if(this->getCarrier() != NULL && this->isPickedUp() && this->isImmediate())
     196        if(this->isPickedUp() && this->isImmediate())
    197197        {
    198198            this->setUsed(true);
  • code/branches/presentation3/src/modules/pickup/Pickup.h

    r7129 r7162  
    4040#include "core/XMLPort.h"
    4141
    42 #include "interfaces/Pickupable.h"
     42#include "CollectiblePickup.h"
    4343
    4444#include "tools/Timer.h"
     
    7474        Damian 'Mozork' Frick
    7575    */
    76     class _PickupExport Pickup : public Pickupable, public BaseObject
     76    class _PickupExport Pickup : public CollectiblePickup, public BaseObject
    7777    {
    7878
  • code/branches/presentation3/src/modules/pickup/PickupCollection.cc

    r7127 r7162  
    3535#include "core/XMLPort.h"
    3636#include "interfaces/PickupCarrier.h"
     37#include "CollectiblePickup.h"
    3738#include "DroppedPickup.h"
    3839#include "PickupCollectionIdentifier.h"
     
    5455
    5556        this->pickupCollectionIdentifier_ = new PickupCollectionIdentifier(this);
     57        this->usedCounter_ = 0;
     58        this->pickedUpCounter_ = 0;
     59        this->disabledCounter_ = 0;
     60        this->processingUsed_ = false;
     61        this->processingPickedUp_ = false;
    5662    }
    5763
     
    6268    PickupCollection::~PickupCollection()
    6369    {
    64         //! Destroy all Pickupables constructing this PickupCollection.
    65         for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
    66         {
    67             if((*it).get() != NULL)
    68                 (*it).get()->destroy();
    69         }
     70        // Destroy all Pickupables constructing this PickupCollection.
     71        for(std::vector<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
     72        {
     73            (*it)->removeFromCollection();
     74            (*it)->destroy();
     75        }
     76        this->pickups_.clear();
    7077    }
    7178
     
    7885        SUPER(PickupCollection, XMLPort, xmlelement, mode);
    7986
    80         XMLPortObject(PickupCollection, Pickupable, "pickupables", addPickupable, getPickupable, xmlelement, mode);
     87        XMLPortObject(PickupCollection, CollectiblePickup, "pickupables", addPickupable, getPickupable, xmlelement, mode);
    8188
    8289        this->initializeIdentifier();
     
    8996    void PickupCollection::initializeIdentifier(void)
    9097    {
    91         for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
    92         {
    93             this->pickupCollectionIdentifier_->addPickup((*it).get()->getPickupIdentifier());
     98        for(std::vector<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
     99        {
     100            this->pickupCollectionIdentifier_->addPickup((*it)->getPickupIdentifier());
    94101        }
    95102    }
     
    104111        SUPER(PickupCollection, changedUsed);
    105112
    106         //! Change used for all Pickupables this PickupCollection consists of.
    107         for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
    108         {
    109             (*it).get()->setUsed(this->isUsed());
    110         }
     113        this->processingUsed_ = true;
     114        // Change used for all Pickupables this PickupCollection consists of.
     115        for(std::vector<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
     116        {
     117            (*it)->setUsed(this->isUsed());
     118        }
     119        this->processingUsed_ = false;
     120
     121        this->changedUsedAction();
     122    }
     123
     124    /**
     125    @brief
     126        Helper method.
     127        Checks whether due to changes in the used status of the pickups of this PickupCollection the used status of this PickupCollection has to change as well.
     128    */
     129    void PickupCollection::changedUsedAction(void)
     130    {
     131        if(this->processingUsed_)
     132            return;
     133
     134        // If all the pickups are not in use but the PickupCollection is.
     135        if(this->usedCounter_ == 0 && this->isUsed())
     136            this->setUsed(false);
     137
     138        // If all the enabled pickups are in use but the PickupCollection is not.
     139        if(this->usedCounter_ != 0 && this->usedCounter_ == this->pickups_.size()-this->disabledCounter_ && !this->isUsed())
     140            this->setUsed(true);
    111141    }
    112142
     
    120150        SUPER(PickupCollection, changedCarrier);
    121151
    122         //! Change the PickupCarrier for all Pickupables this PickupCollection consists of.
    123         for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
    124         {
    125             (*it).get()->setCarrier(this->getCarrier()->getTarget(*it), true);
     152        // Change the PickupCarrier for all Pickupables this PickupCollection consists of.
     153        for(std::vector<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
     154        {
     155            if(this->getCarrier() == NULL)
     156                (*it)->setCarrier(NULL);
     157            else
     158                (*it)->setCarrier(this->getCarrier()->getTarget(*it));
    126159        }
    127160    }
     
    136169        SUPER(PickupCollection, changedPickedUp);
    137170
    138         //! Change the pickedUp status for all Pickupables this PickupCollection consists of.
    139         for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
    140         {
    141             (*it).get()->setPickedUp(this->isPickedUp());
    142         }
     171        this->processingPickedUp_ = true;
     172        // Change the pickedUp status for all Pickupables this PickupCollection consists of.
     173        for(std::vector<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
     174        {
     175            (*it)->setPickedUp(this->isPickedUp());
     176        }
     177        this->processingPickedUp_ = false;
     178
     179        this->changedPickedUpAction();
     180    }
     181
     182    /**
     183    @brief
     184        Helper method.
     185        Checks whether due to changes in the picked up status of the pickups of this PickupCollection the picked up status of this PickupCollection has to change as well.
     186    */
     187    void PickupCollection::changedPickedUpAction(void)
     188    {
     189        if(this->processingPickedUp_)
     190            return;
     191
     192        // If at least all the enabled pickups of this PickupCollection are no longer picked up.
     193        if(this->pickedUpCounter_ <= this->disabledCounter_ && this->isPickedUp())
     194            this->Pickupable::destroy();
     195
     196        // If the PickupCollection is no longer picked up.
     197        if(!this->isPickedUp())
     198            this->pickedUpCounter_ = 0;
    143199    }
    144200
     
    158214
    159215        PickupCollection* pickup = dynamic_cast<PickupCollection*>(item);
    160         //! Clone all Pickupables this PickupCollection consist of.
    161         for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
    162         {
    163             Pickupable* newPickup = (*it).get()->clone();
    164             pickup->addPickupable(newPickup);
     216        // Clone all Pickupables this PickupCollection consist of.
     217        for(std::vector<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
     218        {
     219            Pickupable* newPickup = (*it)->clone();
     220            CollectiblePickup* collectible = static_cast<CollectiblePickup*>(newPickup);
     221            pickup->addPickupable(collectible);
    165222        }
    166223
     
    178235    bool PickupCollection::isTarget(PickupCarrier* carrier) const
    179236    {
    180         for(std::vector<WeakPtr<Pickupable> >::const_iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
    181         {
    182             if(!carrier->isTarget((*it).get()))
     237        for(std::vector<CollectiblePickup*>::const_iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
     238        {
     239            if(!carrier->isTarget(*it))
    183240                return false;
    184241        }
     
    207264        Returns true if successful,
    208265    */
    209     bool PickupCollection::addPickupable(Pickupable* pickup)
     266    bool PickupCollection::addPickupable(CollectiblePickup* pickup)
    210267    {
    211268        if(pickup == NULL)
    212269            return false;
    213270
    214         WeakPtr<Pickupable> ptr = pickup; //!< Create a weak pointer to be able to test in the constructor if the Pointer is still valid.
    215         this->pickups_.push_back(ptr);
     271        pickup->addToCollection(this);
     272        this->pickups_.push_back(pickup);
    216273        return true;
    217274    }
     
    227284    const Pickupable* PickupCollection::getPickupable(unsigned int index)
    228285    {
    229         return this->pickups_[index].get();
     286        return this->pickups_[index];
     287    }
     288
     289    /**
     290    @brief
     291        Informs the PickupCollection, that one of its pickups has changed its used status to the input value.
     292        This is used internally by the CollectiblePickup class.
     293    @param changed
     294        The value the used status has changed to.
     295    */
     296    void PickupCollection::pickupChangedUsed(bool changed)
     297    {
     298        if(changed)
     299            this->usedCounter_++;
     300        else
     301            this->usedCounter_--;
     302
     303        this->changedUsedAction();
     304    }
     305
     306    /**
     307    @brief
     308        Informs the PickupCollection, that one of its pickups has changed its picked up status to the input value.
     309        This is used internally by the CollectiblePickup class.
     310    @param changed
     311        The value the picked up status has changed to.
     312    */
     313    void PickupCollection::pickupChangedPickedUp(bool changed)
     314    {
     315        if(changed)
     316            this->pickedUpCounter_++;
     317        else
     318            this->pickedUpCounter_--;
     319
     320        this->changedPickedUpAction();
     321    }
     322
     323    /**
     324    @brief
     325        Informs the PickupCollection, that one of its pickups has been disabled.
     326        This is used internally by the CollectiblePickup class.
     327    */
     328    void PickupCollection::pickupDisabled(void)
     329    {
     330        this->disabledCounter_++;
    230331    }
    231332
  • code/branches/presentation3/src/modules/pickup/PickupCollection.h

    r7127 r7162  
    3737#include "PickupPrereqs.h"
    3838
    39 #include "interfaces/Pickupable.h"
    4039#include "core/BaseObject.h"
     40#include "CollectiblePickup.h"
    4141
    4242#include <list>
     
    4747    /**
    4848    @brief
    49         The PickupCollection combines different Pickupables to a coherent, single pickup and makes the seem (from the outside looking in) just as if they were just one Pickupable.
     49        The PickupCollection combines different Pickupables to a coherent, single pickup and makes them seem (from the outside looking in) just as if they were just one Pickupable.
    5050    @author
    5151        Damian 'Mozork' Frick
    5252    */
    53     class _PickupExport PickupCollection : public Pickupable, public BaseObject
     53    class _PickupExport PickupCollection : public CollectiblePickup, public BaseObject
    5454    {
    5555
    5656        public:
    57 
    5857            PickupCollection(BaseObject* creator); //!< Default Constructor.
    5958            virtual ~PickupCollection(); //!< Destructor.
     
    7170            virtual const PickupIdentifier* getPickupIdentifier(void); //!< Get the PickupIdentifier of this PickupCollection.
    7271
    73             bool addPickupable(Pickupable* pickup); //!< Add the input Pickupable to list of Pickupables combined by this PickupCollection.
     72            bool addPickupable(CollectiblePickup* pickup); //!< Add the input Pickupable to list of Pickupables combined by this PickupCollection.
    7473            const Pickupable* getPickupable(unsigned int index); //!< Get the Pickupable at the given index.
     74
     75            void pickupChangedUsed(bool changed); //!< Informs the PickupCollection, that one of its pickups has changed its used status to the input value.
     76            void pickupChangedPickedUp(bool changed); //!< Informs the PickupCollection, that one of its pickups has changed its picked up status to the input value.
     77            void pickupDisabled(void); //!< Informs the PickupCollection, that one of its pickups has been disabled.
    7578
    7679        protected:
     
    8285
    8386        private:
     87            void changedUsedAction(void); //!< Helper method.
     88            void changedPickedUpAction(void); //!< Helper method.
     89           
     90            std::vector<CollectiblePickup*> pickups_; //!< The list of the pointers of all the Pickupables this PickupCollection consists of. They are weak pointers to facilitate testing, whether the pointers are still valid.
    8491
    85             std::vector<WeakPtr<Pickupable> > pickups_; //!< The list of the pointers of all the Pickupables this PickupCollection consists of. They are weak pointers to facilitate testing, whether the pointers are still valid.
     92            unsigned int usedCounter_; //!< Keeps track of the number of pickups of this PickupCollection, that are in use.
     93            unsigned int pickedUpCounter_; //!< Keeps track of the number of pickups of this PickupCollection, that are picked up.
     94            unsigned int disabledCounter_; //!< Keeps track of the number of pickups of this PickupCollection, that are disabled.
     95
     96            bool processingUsed_; //!< Boolean to ensure, that the PickupCollection doesn't update its used status while its internal state is inconsistent.
     97            bool processingPickedUp_; //!< Boolean to ensure, that the PickupCollection doesn't update its picked upp status while its internal state is inconsistent.
    8698
    8799    };
  • code/branches/presentation3/src/modules/pickup/PickupCollectionIdentifier.cc

    r7129 r7162  
    6767    int PickupCollectionIdentifier::compare(const PickupIdentifier* identifier) const
    6868    {
    69         //! Slight un-niceity to cast the PickupIdentifier to a PickupCollectionIdentifier.
     69        // Slight un-niceity to cast the PickupIdentifier to a PickupCollectionIdentifier.
    7070        PickupIdentifier* temp = const_cast<PickupIdentifier*>(identifier);
    7171        const PickupCollectionIdentifier* collectionIdentifier = dynamic_cast<PickupCollectionIdentifier*>(temp);
    7272
    73         //! If the input PickupIdentifier 'identifier' is no PickupCollectionIdentifier then just the two PickupIdentifiers are compared.
     73        // If the input PickupIdentifier 'identifier' is no PickupCollectionIdentifier then just the two PickupIdentifiers are compared.
    7474        if(collectionIdentifier == NULL)
    7575        {
     
    7777        }
    7878
    79         //! If the number of Pickupables each of the two PickupCollectionIdentifiers contain differ, the one with less is considered smaller.
     79        // If the number of Pickupables each of the two PickupCollectionIdentifiers contain differ, the one with less is considered smaller.
    8080        if(this->identifiers_.size() != collectionIdentifier->identifiers_.size())
    8181            return this->identifiers_.size()-collectionIdentifier->identifiers_.size();
    8282
    83         //! Compare the Pickupables of the two PickupCollectionIdentifiers one after the other. the one with the first 'smaller' one is considered smaller.
     83        // Compare the Pickupables of the two PickupCollectionIdentifiers one after the other. the one with the first 'smaller' one is considered smaller.
    8484        std::set<const PickupIdentifier*, PickupIdentifierCompare>::const_iterator it2 = collectionIdentifier->identifiers_.begin();
    8585        for(std::set<const PickupIdentifier*, PickupIdentifierCompare>::const_iterator it = this->identifiers_.begin(); it != this->identifiers_.end(); it++)
  • code/branches/presentation3/src/modules/pickup/PickupManager.cc

    r7150 r7162  
    4343#include "infos/PlayerInfo.h"
    4444#include "worldentities/pawns/Pawn.h"
     45#include "CollectiblePickup.h"
    4546#include "PickupRepresentation.h"
    4647
     
    6465        RegisterRootObject(PickupManager);
    6566
     67        //TODO: This doesn't work, yet.
    6668        if( GameMode::showsGraphics() )
    6769        {
     
    172174            for(std::set<Pickupable*>::iterator pickup = pickups.begin(); pickup != pickups.end(); pickup++)
    173175            {
    174                 this->pickupsList_.insert(std::pair<Pickupable*, WeakPtr<Pickupable> >(*pickup, WeakPtr<Pickupable>(*pickup)));
     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)));
    175179            }
    176180        }
  • code/branches/presentation3/src/modules/pickup/PickupPrereqs.h

    r7136 r7162  
    6666{
    6767
     68    class CollectiblePickup;
    6869    class DroppedPickup;
    6970    class Pickup;
  • code/branches/presentation3/src/modules/pickup/PickupRepresentation.h

    r7129 r7162  
    149149            std::string spawnerTemplate_; //!<  The name of the template of this PickupRepresentation.
    150150            StaticEntity* spawnerRepresentation_; //!< The spawnerRepresentation of this PickupRepresentation.
    151             std::string inventoryRepresentation_; //!< The name of an image representing the pickup in the PickupInventory. TODO: Exact format and placement of image?
     151            std::string inventoryRepresentation_; //!< The name of an image representing the pickup in the PickupInventory.
    152152
    153153            Pickupable* pickup_; //!< The Pickupable that is represented by this PickupRepresentation.
  • code/branches/presentation3/src/modules/pickup/PickupSpawner.cc

    r7150 r7162  
    107107        this->maxSpawnedItems_ = INF;
    108108        this->spawnsRemaining_ = INF;
     109        this->selfDestruct_ = false;
    109110    }
    110111
     
    115116    PickupSpawner::~PickupSpawner()
    116117    {
    117         if(this->pickup_ != NULL)
     118        if(this->selfDestruct_ && this->pickup_ != NULL)
    118119            this->pickup_->destroy();
    119120    }
     
    176177        if (this->isActive())
    177178        {
    178             SmartPtr<PickupSpawner> temp = this; // create a smart pointer to keep the PickupSpawner alive until we iterated through all Pawns (in case a Pawn takes the last pickup)
     179            SmartPtr<PickupSpawner> temp = this; //Create a smart pointer to keep the PickupSpawner alive until we iterated through all Pawns (in case a Pawn takes the last pickup)
    179180
    180181            //! Iterate trough all Pawns.
     
    305306            {
    306307                if(pickup->pickup(target))
    307                 {
    308308                    this->decrementSpawnsRemaining();
    309                 }
    310309                else
    311310                {
     311                    this->selfDestruct_ = true;
    312312                    pickup->destroy();
    313313                }
     
    319319
    320320                if(pickup == NULL)
    321                 {
    322321                    COUT(1) << "PickupSpawner (&" << this << "): getPickup produced an error, no Pickupable created." << std::endl;
    323                 }
    324322                else
    325323                {
     324                    this->selfDestruct_ = true;
    326325                    pickup->destroy();
    327326                }
  • code/branches/presentation3/src/modules/pickup/PickupSpawner.h

    r7127 r7162  
    125125            Timer respawnTimer_; //!< Timer used for re-activating.
    126126
     127            bool selfDestruct_; //!< True if the PickupSpawner is selfdestructing.
     128
    127129            static const int INF = -1; //!< Constant for infinity.
    128130    };
  • code/branches/presentation3/src/modules/pickup/items/DronePickup.cc

    r7127 r7162  
    131131                Pawn* pawn = this->carrierToPawnHelper();
    132132                if(pawn == NULL) //!< If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed.
    133                     this->destroy();
     133                    this->Pickupable::destroy();
    134134
    135135                //Attach to pawn
     
    155155            if(this->isOnce() || (this->isContinuous() ))
    156156            {
    157                 this->destroy();
     157                this->Pickupable::destroy();
    158158            }
    159159        }
  • code/branches/presentation3/src/modules/pickup/items/HealthPickup.cc

    r7127 r7162  
    143143            Pawn* pawn = this->carrierToPawnHelper();
    144144            if(pawn == NULL) //!< If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed.
    145                 this->destroy();
     145                this->Pickupable::destroy();
    146146
    147147            //! Calculate the health that is added this tick.
     
    191191
    192192        //! If the pickup is not picked up nothing must be done.
    193         if(!this->isPickedUp())
     193        if(!this->isPickedUp()) //TODO: Needed?
    194194            return;
    195195
     
    201201                Pawn* pawn = this->carrierToPawnHelper();
    202202                if(pawn == NULL) //!< If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed.
    203                     this->destroy();
     203                    this->Pickupable::destroy();
    204204
    205205                float health = 0;
     
    241241                {
    242242                    COUT(1) << "Something went horribly wrong in Health Pickup. PickupCarrier is no Pawn." << std::endl;
    243                     this->destroy();
     243                    this->Pickupable::destroy();
    244244                    return;
    245245                }
     
    256256            if(this->isOnce() || (this->isContinuous() && this->getHealth() == 0))
    257257            {
    258                 this->destroy();
     258                this->Pickupable::destroy();
    259259            }
    260260        }
  • code/branches/presentation3/src/modules/pickup/items/InvisiblePickup.cc

    r7129 r7162  
    133133            if(!this->getTimer()->isActive() && this->getTimer()->getRemainingTime() == this->getDuration())
    134134            {
    135                 this->destroy();
     135                this->Pickupable::destroy();
    136136            }
    137137            else
  • code/branches/presentation3/src/modules/pickup/items/MetaPickup.cc

    r7150 r7162  
    3434#include "core/CoreIncludes.h"
    3535#include "core/XMLPort.h"
     36#include "worldentities/pawns/Pawn.h"
    3637#include "interfaces/PickupCarrier.h"
    3738#include "pickup/PickupIdentifier.h"
     
    4748    /*static*/ const std::string MetaPickup::metaTypeUse_s = "use";
    4849    /*static*/ const std::string MetaPickup::metaTypeDrop_s = "drop";
     50    /*static*/ const std::string MetaPickup::metaTypeDestroy_s = "destroy";
     51    /*static*/ const std::string MetaPickup::metaTypeDestroyCarrier_s = "destroyCarrier";
    4952
    5053    /**
     
    120123            if(this->getMetaTypeDirect() != pickupMetaType::none && carrier != NULL)
    121124            {
     125                if(this->getMetaTypeDirect() == pickupMetaType::destroyCarrier)
     126                {
     127                    Pawn* pawn = orxonox_cast<Pawn*>(carrier);
     128                    pawn->kill();
     129                    return;
     130                }
    122131                std::set<Pickupable*> pickups = carrier->getPickups();
    123                 //! Set all Pickupables carried by the PickupCarrier either to used or drop them, depending o the meta type.
     132                //! Set all Pickupables carried by the PickupCarrier either to used or drop them, depending on the meta type.
    124133                for(std::set<Pickupable*>::iterator it = pickups.begin(); it != pickups.end(); it++)
    125134                {
     
    136145                        if(pickup != NULL && pickup != this)
    137146                        {
    138                             pickup->drop(carrier);
     147                            pickup->drop();
     148                        }
     149                    }
     150                    if(this->getMetaTypeDirect() == pickupMetaType::destroy)
     151                    {
     152                        if(pickup != NULL && pickup != this)
     153                        {
     154                            pickup->Pickupable::destroy();
    139155                        }
    140156                    }
    141157                }
    142158            }
    143             this->destroy();
     159            this->Pickupable::destroy();
    144160        }
    145161    }
     
    180196            case pickupMetaType::drop:
    181197                return MetaPickup::metaTypeDrop_s;
     198            case pickupMetaType::destroy:
     199                return MetaPickup::metaTypeDestroy_s;
     200            case pickupMetaType::destroyCarrier:
     201                return MetaPickup::metaTypeDestroyCarrier_s;
    182202            default:
    183203                return BLANKSTRING;
     
    205225            this->setMetaTypeDirect(pickupMetaType::drop);
    206226        }
     227        else if(type == MetaPickup::metaTypeDestroy_s)
     228        {
     229            this->setMetaTypeDirect(pickupMetaType::destroy);
     230        }
     231        else if(type == MetaPickup::metaTypeDestroyCarrier_s)
     232        {
     233            this->setMetaTypeDirect(pickupMetaType::destroyCarrier);
     234        }
     235        else
     236            COUT(2) << "Invalid metaType '" << type << "' in MetaPickup." << std::endl;
    207237    }
    208238
  • code/branches/presentation3/src/modules/pickup/items/MetaPickup.h

    r7127 r7162  
    4848            none,
    4949            use,
    50             drop
     50            drop,
     51            destroy,
     52            destroyCarrier
    5153        };
    5254    }
     
    5456    /**
    5557    @brief
    56         The MetaPickup is a pickup that can, depending on the parameters, either drop all pickups of the PickupCarrier that picks it up, or use all the unused pickups of the PickupCarrier, that picks it up. The parameter to set for this is the metaType and it can be used with the values 'none', 'drop' and 'use'.
     58        The MetaPickup is a pickup that can, depending on the parameter 'metaType', do different things. If the 'metaType' is set to
     59        1) 'use', all the pickups, the PickupCarrier has, are immediately set to used upon pickup of the MetaPickup.
     60        2) 'drop', all the pickups, the PickupCarrier has, are immediately dropped upon pickup of the MetaPickup.
     61        3) 'destroy', all the pickups, the PickupCarrier has, are immediately destroyed upon pickup of the MetaPickup.
     62        4) 'destroyCarrier', the PickupCarrier is immediately destroyed upon pickup of the MetaPickup.
    5763    @author
    5864        Damian 'Mozork' Frick
     
    98104            static const std::string metaTypeUse_s;
    99105            static const std::string metaTypeDrop_s;
     106            static const std::string metaTypeDestroy_s;
     107            static const std::string metaTypeDestroyCarrier_s;
    100108
    101109
  • code/branches/presentation3/src/modules/pickup/items/ShieldPickup.cc

    r7127 r7162  
    155155        Pawn* pawn = this->carrierToPawnHelper();
    156156        if(pawn == NULL)
    157             this->destroy();
     157            this->Pickupable::destroy();
    158158
    159159        //! If the pickup has transited to used.
     
    181181                if(!this->getTimer()->isActive() && this->getTimer()->getRemainingTime() == this->getDuration())
    182182                {
    183                     this->destroy();
     183                    this->Pickupable::destroy();
    184184                }
    185185                else
  • code/branches/presentation3/src/modules/pickup/items/SpeedPickup.cc

    r7127 r7162  
    136136        Engine* engine = this->carrierToEngineHelper();
    137137        if(engine == NULL) //!< If the PickupCarrier is no Engine, then this pickup is useless and therefore is destroyed.
    138             this->destroy();
     138            this->Pickupable::destroy();
    139139
    140140        //! If the pickup has transited to used.
     
    161161                if(!this->getTimer()->isActive() && this->getTimer()->getRemainingTime() == this->getDuration())
    162162                {
    163                     this->destroy();
     163                    this->Pickupable::destroy();
    164164                }
    165165                else
  • code/branches/presentation3/src/orxonox/CameraManager.cc

    r7161 r7162  
    6868    void CameraManager::requestFocus(Camera* camera)
    6969    {
    70       COUT(0) << "bliub" << endl;
    7170        // notify old camera (if it exists)
    7271        if (!this->cameraList_.empty())
  • code/branches/presentation3/src/orxonox/gametypes/Dynamicmatch.cc

    r7076 r7162  
    102102
    103103    bool Dynamicmatch::allowPawnDamage(Pawn* victim, Pawn* originator)
    104     { //TODO: static and fading message for the "human" player's
     104    {
     105        //TODO: static and fading message for the "human" player's
    105106        if (!originator||!victim)
    106107            return false;
  • code/branches/presentation3/src/orxonox/interfaces/InterfaceCompilation.cc

    r7127 r7162  
    5959    {
    6060        RegisterRootObject(PickupCarrier);
    61 
    62         this->setCarrierName("PickupCarrier");
    6361    }
    6462
    6563    PickupCarrier::~PickupCarrier()
    6664    {
     65
     66    }
     67
     68    void PickupCarrier::preDestroy(void)
     69    {
    6770        std::set<Pickupable*>::iterator it = this->pickups_.begin();
     71        std::set<Pickupable*>::iterator temp;
    6872        while(it != this->pickups_.end())
    6973        {
    70             (*it)->destroy();
     74            (*it)->carrierDestroyed();
     75            temp = it;
    7176            it = this->pickups_.begin();
     77            if(it == temp) // Infinite loop avoidance, in case the pickup wasn't removed from the carrier somewhere in the carrierDestroy() procedure.
     78            {
     79                COUT(2) << "Oops. In a PickupCarrier, while cleaning up, a Pickupable (&" << (*temp) << ") didn't unregister itself as it should have." << std::endl;;
     80                it++;
     81            }
    7282        }
    7383
  • code/branches/presentation3/src/orxonox/interfaces/PickupCarrier.h

    r7150 r7162  
    7979            PickupCarrier(); //!< Constructor.
    8080            virtual ~PickupCarrier(); //!< Destructor.
     81            void preDestroy(void);
    8182
    8283            /**
     
    138139            virtual const Vector3& getCarrierPosition(void) = 0;
    139140
    140             /**
    141             @brief Get the name of this PickupCarrier.
    142             @return Returns the name as a string.
    143             */
    144             const std::string& getCarrierName(void) { return this->carrierName_; } // tolua_export
    145 
    146141        protected:
    147142            /**
     
    160155
    161156            /**
     157            @brief Get all Pickupables this PickupCarrier has.
     158            @return  Returns the set of all Pickupables this PickupCarrier has.
     159            */
     160            std::set<Pickupable*>& getPickups(void)
     161                { return this->pickups_; }
     162
     163        private:
     164            std::set<Pickupable*> pickups_; //!< The list of Pickupables carried by this PickupCarrier.
     165
     166            /**
    162167            @brief Adds a Pickupable to the list of pickups that are carried by this PickupCarrier.
    163168            @param pickup A pointer to the pickup to be added.
     
    165170            */
    166171            bool addPickup(Pickupable* pickup)
    167                 { return this->pickups_.insert(pickup).second; }
     172                {
     173                    COUT(4) << "Adding Pickupable (&" << pickup << ") to PickupCarrier (&" << this << ")" << std::endl;
     174                    return this->pickups_.insert(pickup).second;
     175                }
    168176
    169177            /**
     
    173181            */
    174182            bool removePickup(Pickupable* pickup)
    175                 { return this->pickups_.erase(pickup) == 1; }
    176 
    177             /**
    178             @brief Get all Pickupables this PickupCarrier has.
    179             @return  Returns the set of all Pickupables this PickupCarrier has.
    180             */
    181             std::set<Pickupable*>& getPickups(void)
    182                 { return this->pickups_; }
    183 
    184             /**
    185             @brief Set the name of this PickupCarrier.
    186                    The name needs to be set in the constructor of every class inheriting from PickupCarrier, by calling setCarrierName().
    187             @param name The name to be set.
    188             */
    189             void setCarrierName(const std::string& name)
    190                 { this->carrierName_ = name; }
    191 
    192         private:
    193             std::set<Pickupable*> pickups_; //!< The list of Pickupables carried by this PickupCarrier.
    194             std::string carrierName_; //!< The name of the PickupCarrier, as displayed in the PickupInventory.
    195 
    196             /**
    197             @brief Get the number of carrier children this PickupCarrier has.
    198             @return Returns the number of carrier children.
    199             */
    200             unsigned int getNumCarrierChildren(void)
    201183                {
    202                     std::vector<PickupCarrier*>* list = this->getCarrierChildren();
    203                     unsigned int size = list->size();
    204                     delete list;
    205                     return size;
    206                 }
    207 
    208             /**
    209             @brief Get the index-th child of this PickupCarrier.
    210             @param index The index of the child to return.
    211             @return Returns the index-th child.
    212             */
    213             PickupCarrier* getCarrierChild(unsigned int index)
    214                 {
    215                     std::vector<PickupCarrier*>* list = this->getCarrierChildren();
    216                     if(list->size() < index)
    217                         return NULL;
    218                     PickupCarrier* carrier = (*list)[index];
    219                     delete list;
    220                     return carrier;
    221                 }
    222 
    223             /**
    224             @brief Get the number of Pickupables this PickupCarrier carries.
    225             @return returns the number of pickups.
    226             */
    227             unsigned int getNumPickups(void)
    228                 { return this->pickups_.size(); }
    229 
    230             /**
    231             @brief Get the index-th Pickupable of this PickupCarrier.
    232             @param index The index of the Pickupable to return.
    233             @return Returns the index-th pickup.
    234             */
    235             Pickupable* getPickup(unsigned int index)
    236                 {
    237                     std::set<Pickupable*>::iterator it;
    238                     for(it = this->pickups_.begin(); index != 0 && it != this->pickups_.end(); it++)
    239                         index--;
    240                     if(it == this->pickups_.end())
    241                         return NULL;
    242                     return *it;
     184                    COUT(4) << "Removing Pickupable (&" << pickup << ") from PickupCarrier (&" << this << ")" << std::endl;
     185                    return this->pickups_.erase(pickup) == 1;
    243186                }
    244187
  • code/branches/presentation3/src/orxonox/interfaces/Pickupable.cc

    r7150 r7162  
    5858
    5959        this->pickupIdentifier_ = new PickupIdentifier(this);
     60        this->beingDestroyed_ = false;
     61        this->enabled_ = true;
    6062    }
    6163
     
    6668    Pickupable::~Pickupable()
    6769    {
    68         if(this->isUsed())
    69             this->setUsed(false);
    70 
    71         if(this->isPickedUp())
    72         {
    73             this->drop(false);
    74         }
    75 
     70        COUT(4) << "Pickupable (" << this->getIdentifier()->getName() << ") (&" << this << ") destroyed." << std::endl;
    7671        if(this->pickupIdentifier_ != NULL)
    7772            this->pickupIdentifier_->destroy();
     73    }
     74
     75    /**
     76    @brief
     77        A method that is called by OrxonoxClass::destroy() before the object is actually destroyed.
     78    */
     79    void Pickupable::preDestroy(void)
     80    {
     81        this->beingDestroyed_ = true;
     82
     83        if(this->isPickedUp())
     84            this->drop(false); // Drops the pickup without creating a PickupSpawner.
     85    }
     86
     87    /**
     88    @brief
     89        Is called internally within the pickup module to destroy pickups.
     90    */
     91    void Pickupable::destroy(void)
     92    {
     93        this->destroyPickup();
     94    }
     95
     96    /**
     97    @brief
     98        Destroys a Pickupable.
     99        If the Pickupable is already in the process of being destroyed a warning is displayed and this method is skipped.
     100    */
     101    void Pickupable::destroyPickup(void)
     102    {
     103        if(!this->beingDestroyed_)
     104            this->OrxonoxClass::destroy();
     105        else
     106            COUT(2) << this->getIdentifier()->getName() << " may be unsafe. " << std::endl;
    78107    }
    79108
     
    88117    bool Pickupable::setUsed(bool used)
    89118    {
    90         if(this->used_ == used)
     119        if(this->used_ == used || !this->isPickedUp()) // If either the used status of the Pickupable doesn't change or it isn't picked up.
     120            return false;
     121
     122        if((!this->isUsable() && used) || (!this->isUnusable() && !used)) // If either the Pickupable is requested to be used but it is not usable or the Pickupable is requested to be unused, while it is not unusable.
    91123            return false;
    92124
     
    112144        if(carrier == NULL)
    113145            return false;
     146
    114147        return this->isTarget(carrier->getIdentifier());
    115148    }
     
    131164                return true;
    132165        }
     166
    133167        return false;
    134168    }
     
    178212            return false;
    179213
    180         if(!carrier->addPickup(this))
     214        if(!this->setCarrier(carrier))
    181215        {
    182216            COUT(3) << "A Pickupable (&" << this << ") was trying to be added to a PickupCarrier, but was already present." << std::endl;
    183217            return false;
    184218        }
    185 
     219       
     220        this->setPickedUp(true);
    186221        COUT(4) << "Pickupable (&" << this << ") got picked up by a PickupCarrier (&" << carrier << ")." << std::endl;
    187         this->setCarrier(carrier);
    188         this->setPickedUp(true);
    189222        return true;
    190223    }
     
    194227        Can be called to drop a Pickupable.
    195228    @param createSpawner
    196         If true a spawner is be created for the dropped Pickupable. True is default.
     229        If true a spawner is to be created for the dropped Pickupable. True is default.
    197230    @return
    198231        Returns true if the Pickupable has been dropped, false if not.
     
    200233    bool Pickupable::drop(bool createSpawner)
    201234    {
    202         if(!this->isPickedUp()) //!< If the Pickupable is not picked up.
    203             return false;
    204 
    205         assert(this->getCarrier()); //!> The Carrier cannot be NULL at this point. //TODO: Too conservative?
     235        if(!this->isPickedUp()) // If the Pickupable is not picked up.
     236            return false;
     237
     238        assert(this->getCarrier()); // The Carrier cannot be NULL at this point.
    206239        if(!this->getCarrier()->removePickup(this)) //TODO Shouldn't this be a little later?
    207             COUT(2) << "Pickupable (&" << this << ") is being dropped, but it was not present in the PickupCarriers list of pickups." << std::endl;
    208        
     240            COUT(2) << "Pickupable (&" << this << ", " << this->getIdentifier()->getName() << ") is being dropped, but it was not present in the PickupCarriers list of pickups." << std::endl;
     241
    209242        COUT(4) << "Pickupable (&" << this << ") got dropped up by a PickupCarrier (&" << this->getCarrier() << ")." << std::endl;
    210243        this->setUsed(false);
     
    217250        this->setCarrier(NULL);
    218251
    219         if(!created && createSpawner)
    220         {
     252        if(!created && createSpawner) // If a PickupSpawner should have been created but wasn't.
    221253            this->destroy();
    222         }
    223254
    224255        return true;
     
    235266    bool Pickupable::setPickedUp(bool pickedUp)
    236267    {
    237         if(this->pickedUp_ == pickedUp)
     268        if(this->pickedUp_ == pickedUp) // If the picked up status has not changed.
    238269            return false;
    239270
     
    241272
    242273        this->pickedUp_ = pickedUp;
     274        if(!pickedUp) // if the Pickupable has been dropped it unregisters itself with its PickupCarrier.
     275            this->getCarrier()->removePickup(this);
    243276        this->changedPickedUp();
    244277        GUIManager::getInstance().getLuaState()->doString("PickupInventory.update()");
     
    251284    @param carrier
    252285        Sets the input PickupCarrier as the carrier of the pickup.
    253     */
    254     inline bool Pickupable::setCarrier(PickupCarrier* carrier, bool tell)
    255     {
    256         if(this->carrier_ == carrier)
     286    @param tell
     287        If true (default) the pickup is added to the list of pickups in the PickupCarrier.
     288    @return
     289        Returns true if successful, false if not.
     290    */
     291    bool Pickupable::setCarrier(orxonox::PickupCarrier* carrier, bool tell)
     292    {
     293        if(this->carrier_ == carrier) // If the PickupCarrier doesn't change.
    257294            return false;
    258295
    259296        COUT(4) << "Pickupable (&" << this << ") changed Carrier (& " << carrier << ")." << std::endl;
    260297
     298        if(carrier != NULL && tell)
     299        {
     300            if(!carrier->addPickup(this))
     301                return false;
     302        }
     303       
    261304        this->carrier_ = carrier;
    262305        this->changedCarrier();
    263         if(tell && carrier != NULL)
    264             this->carrier_->pickups_.insert(this);
    265         return true;
     306        return true;
     307    }
     308
     309    /**
     310    @brief
     311        Is called by the PickupCarrier when it is being destroyed.
     312    */
     313    void Pickupable::carrierDestroyed(void)
     314    {
     315        this->destroy();
    266316    }
    267317
  • code/branches/presentation3/src/orxonox/interfaces/Pickupable.h

    r7150 r7162  
    9595            virtual void changedPickedUp(void) {}
    9696
    97             bool pickup(PickupCarrier* carrier);
    98             bool drop(bool createSpawner = true);
     97            /**
     98            @brief Returns whether the Pickupable can be used.
     99            @return Returns true if it can be used.
     100            */
     101            inline bool isUsable(void) { return this->enabled_; } // tolua_export
     102           
     103            /**
     104            @brief Returns whether the Pickupable can be unused.
     105            @return Returns true if it can be unused.
     106            */
     107            inline bool isUnusable(void) { return this->enabled_; } // tolua_export
     108
     109            /**
     110            @brief Returns whether the Pickupable is enabled.
     111                   Once a Pickupable is disabled it cannot be enabled again. A Pickupable that is disabled can neither be used nor unused.
     112            @return Returns true if the Pickupable is enabled.
     113            */
     114            inline bool isEnabled(void)
     115                { return this->enabled_; }
     116
     117            bool pickup(PickupCarrier* carrier); //!< Can be called to pick up a Pickupable.
     118            bool drop(bool createSpawner = true); //!< Can be called to drop a Pickupable.
    99119
    100120            virtual bool isTarget(PickupCarrier* carrier) const; //!< Get whether the given PickupCarrier is a target of this pickup.
     
    115135            bool setUsed(bool used); //!< Sets the Pickupable to used or unused, depending on the input.
    116136            bool setPickedUp(bool pickedUp); //!< Helper method to set the Pickupable to either picked up or not picked up.
    117             bool setCarrier(PickupCarrier* carrier, bool tell = false); //!< Sets the carrier of the pickup.
     137            //TODO: private?
     138            bool setCarrier(PickupCarrier* carrier, bool tell = true); //!< Sets the carrier of the pickup.
     139
     140            //TODO: private?
     141            virtual void carrierDestroyed(void); //!< Is called by the PickupCarrier when it is being destroyed.
     142
     143            void destroy(void); //!< Is called internally within the pickup module to destroy pickups.
    118144
    119145        protected:
     
    122148            */
    123149            void initializeIdentifier(void) {}
     150
     151            virtual void preDestroy(void); //!< A method that is called by OrxonoxClass::destroy() before the object is actually destroyed.
     152            virtual void destroyPickup(void); //!< Destroys a Pickupable.
     153
     154            /**
     155            @brief Sets the Pickuapble to disabled.
     156            */
     157            inline void setDisabled(void)
     158                { this->enabled_ = false; }
    124159
    125160            /**
     
    136171        private:
    137172
    138             bool used_; //!< Whether the pickup is currently in use or not.
    139             bool pickedUp_; //!< Whether the pickup is currently picked up or not.
     173            bool used_; //!< Whether the Pickupable is currently in use or not.
     174            bool pickedUp_; //!< Whether the Pickupable is currently picked up or not.
    140175
    141             PickupCarrier* carrier_; //!< The carrier of the pickup.
    142             std::list<Identifier*> targets_; //!< The possible targets of this pickup.
     176            bool enabled_; //!< Whether the Pickupable is enabled or not.
     177
     178            PickupCarrier* carrier_; //!< The PickupCarrier of the Pickupable.
     179            std::list<Identifier*> targets_; //!< The possible targets of this Pickupable.
     180
     181            bool beingDestroyed_; //!< Is true if the Pickupable is in the process of being destroyed.
    143182
    144183        // For implementing the Rewardable interface:
  • code/branches/presentation3/src/orxonox/items/Engine.cc

    r6711 r7162  
    6464        this->boostBlur_ = 0;
    6565
    66         this->setCarrierName("Engine");
    6766        this->speedAdd_ = 0.0;
    6867        this->speedMultiply_ = 1.0;
  • code/branches/presentation3/src/orxonox/pickup/PickupIdentifier.cc

    r7129 r7162  
    105105        }
    106106
    107         //! We iterate through all parameters and compar their values (which are strings). The first parameter is the most significant. The ordering is once again established by the alphabetical comparison of the two value strings.
     107        //! We iterate through all parameters and compare their values (which are strings). The first parameter is the most significant. The ordering is once again established by the alphabetical comparison of the two value strings.
    108108        for(std::map<std::string, std::string>::const_iterator it = this->parameters_.begin(); it != this->parameters_.end(); it++)
    109109        {
  • code/branches/presentation3/src/orxonox/worldentities/pawns/Pawn.cc

    r7153 r7162  
    8383            this->weaponSystem_ = 0;
    8484
    85         this->setCarrierName("Pawn");
    86 
    8785        this->setRadarObjectColour(ColourValue::Red);
    8886        this->setRadarObjectShape(RadarViewable::Dot);
Note: See TracChangeset for help on using the changeset viewer.