Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 30, 2012, 11:08:17 PM (12 years ago)
Author:
landauf
Message:

merged branch presentation2012merge back to trunk

Location:
code/trunk
Files:
4 deleted
30 edited
2 copied

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/modules/pickup/CMakeLists.txt

    r7163 r9348  
    11SET_SOURCE_FILES(PICKUP_SRC_FILES
    22  CollectiblePickup.cc
    3   DroppedPickup.cc
    43  Pickup.cc
    54  PickupCollection.cc
    6   PickupCollectionIdentifier.cc
    75  PickupManager.cc
    86  PickupRepresentation.cc
  • code/trunk/src/modules/pickup/CollectiblePickup.cc

    r7494 r9348  
    4545        Registers the object and initializes variables.
    4646    */
    47     CollectiblePickup::CollectiblePickup() : isInCollection_(false)
     47    CollectiblePickup::CollectiblePickup() : collection_(NULL)
    4848    {
    4949        RegisterObject(CollectiblePickup);
    50 
    51         this->collection_ = NULL;
    5250    }
    5351
     
    5856    CollectiblePickup::~CollectiblePickup()
    5957    {
    60 
    61     }
    62 
    63     /**
    64     @brief
    65         Is called by OrxonoxClass::destroy() before the object is actually destroyed.
    66     */
    67     void CollectiblePickup::preDestroy(void)
    68     {
    69         this->Pickupable::preDestroy();
    70 
    71         // The PickupCollection has to be destroyed as well.
    72         if(this->isInCollection())
    73             this->collection_->Pickupable::destroy();
    74     }
    75 
    76     /**
    77     @brief
    78         Destroys a Pickupable.
    79     */
    80     void CollectiblePickup::destroyPickup(void)
    81     {
    82         if(!this->isInCollection()) // If the CollectiblePickup is not in a PickupCollection the destroyPickup method of Pickupable is called.
    83             this->Pickupable::destroyPickup();
    84         else // Else the ColectiblePickup is dropped and disabled,
    85         {
    86             this->drop(false);
    87             if(this->isInCollection() && this->isEnabled()) // It is only disabled if it is enabled and still ina PickupCollection after having been dropped.
    88             {
    89                 this->setDisabled();
    90                 this->collection_->pickupDisabled();
    91             }
    92         }
    93     }
    94 
    95     /**
    96     @brief
    97         Is called by the PickupCarrier when it is being destroyed.
    98     */
    99     void CollectiblePickup::carrierDestroyed(void)
    100     {
    101         if(!this->isInCollection())
    102             this->Pickupable::destroy();
    103         else // If the CollectiblePickup is part of a PickupCollection it is just dropped instead of destroyed.
    104             this->drop(false);
     58        if (this->isInCollection())
     59            this->collection_->removePickupable(this);
    10560    }
    10661
     
    13186    /**
    13287    @brief
    133         Adds this CollectiblePickup to the input PickupCollection.
     88        Notifies this CollectiblePickup that it was added to a PickupCollection.
    13489    @param collection
    13590        A pointer to the PickupCollection to which the CollectiblePickup should be added.
    136     @return
    137         Returns true if the CollectiblePickup was successfully added to the PickupCollection.
    13891    */
    139     bool CollectiblePickup::addToCollection(PickupCollection* collection)
     92    void CollectiblePickup::wasAddedToCollection(PickupCollection* collection)
    14093    {
    141         if(this->isInCollection() || collection == NULL) //If the CollectiblePickup already is in a PickupCollection or if the input pointer is NULL.
    142             return false;
    143 
    144         this->isInCollection_ = true;
    14594        this->collection_ = collection;
    146         return true;
    14795    }
    14896
    14997    /**
    15098    @brief
    151         Removes this CollectiblePickup from its PickupCollection.
    152     @return
    153         Returns true if the CollectiblePickup was succcessfully removed.
     99        Notifies this CollectiblePickup that it was removed from its PickupCollection.
    154100    */
    155     bool CollectiblePickup::removeFromCollection(void)
     101    void CollectiblePickup::wasRemovedFromCollection(void)
    156102    {
    157         if(!this->isInCollection()) //If the CollectiblePickup is not in a PickupCollection.
    158             return false;
    159 
    160         this->isInCollection_ = false;
    161103        this->collection_ = NULL;
    162         return true;
    163104    }
    164 
    165105}
  • code/trunk/src/modules/pickup/CollectiblePickup.h

    r7547 r9348  
    5555    class _PickupExport CollectiblePickup : public Pickupable
    5656    {
     57        friend class PickupCollection;
    5758
    5859        public:
     
    6869            */
    6970            bool isInCollection(void) const
    70                 { return this->isInCollection_; }
    71 
    72             bool addToCollection(PickupCollection* collection); //!< Adds this CollectiblePickup to the input PickupCollection.
    73             bool removeFromCollection(void); //!< Removes this CollectiblePickup from its PickupCollection.
    74 
    75             void carrierDestroyed(void); //!< Is called by the PickupCarrier when it is being destroyed.
    76 
    77         protected:
    78             virtual void preDestroy(void); //!< Is called by OrxonoxClass::destroy() before the object is actually destroyed.
    79             virtual void destroyPickup(void); //!< Destroys a Pickupable.
     71                { return this->collection_ != NULL; }
    8072
    8173        private:
    82             bool isInCollection_; //!< True if the CollectiblePickup is in a PickupCollection.
     74            void wasAddedToCollection(PickupCollection* collection);
     75            void wasRemovedFromCollection(void);
     76
    8377            PickupCollection* collection_; //!< A pointer to the PickupCollection this CollectiblePickup is in.
    84 
    8578    };
    8679}
  • code/trunk/src/modules/pickup/Pickup.cc

    r8864 r9348  
    3737#include "util/StringUtils.h"
    3838
    39 #include "pickup/PickupIdentifier.h"
    40 
    41 #include "DroppedPickup.h"
     39#include "PickupSpawner.h"
    4240
    4341namespace orxonox
     
    8684    /**
    8785    @brief
    88         Initializes the PickupIdentififer of this Pickup.
    89     */
    90     void Pickup::initializeIdentifier(void)
    91     {
    92         std::string val1 = this->getActivationType();
    93         std::string type1 = "activationType";
    94         this->pickupIdentifier_->addParameter(type1, val1);
    95 
    96         std::string val2 = this->getDurationType();
    97         std::string type2 = "durationType";
    98         this->pickupIdentifier_->addParameter(type2, val2);
    99     }
    100 
    101     /**
    102     @brief
    10386        Method for creating a Pickup object through XML.
    10487    */
     
    10790        SUPER(Pickup, XMLPort, xmlelement, mode);
    10891
    109         XMLPortParam(Pickup, "activationType", setActivationType, getActivationType, xmlelement, mode);
    110         XMLPortParam(Pickup, "durationType", setDurationType, getDurationType, xmlelement, mode);
    111 
    112         this->initializeIdentifier();
     92        XMLPortParam(Pickup, "representation", setRepresentationName, getRepresentationName, xmlelement, mode);
     93        XMLPortParam(Pickup, "activationType", setActivationTypeAsString, getActivationTypeAsString, xmlelement, mode);
     94        XMLPortParam(Pickup, "durationType", setDurationTypeAsString, getDurationTypeAsString, xmlelement, mode);
    11395    }
    11496
     
    119101        Returns a string containing the activation type.
    120102    */
    121     const std::string& Pickup::getActivationType(void) const
     103    const std::string& Pickup::getActivationTypeAsString(void) const
    122104    {
    123         switch(this->activationType_)
     105        switch(this->getActivationType())
    124106        {
    125107            case pickupActivationType::immediate:
     
    138120        Returns a string containing the duration type.
    139121    */
    140     const std::string& Pickup::getDurationType(void) const
     122    const std::string& Pickup::getDurationTypeAsString(void) const
    141123    {
    142         switch(this->durationType_)
     124        switch(this->getDurationType())
    143125        {
    144126            case pickupDurationType::once:
     
    157139        The activation type of the Pickup as a string.
    158140    */
    159     void Pickup::setActivationType(const std::string& type)
     141    void Pickup::setActivationTypeAsString(const std::string& type)
    160142    {
    161143        if(type == Pickup::activationTypeImmediate_s)
    162             this->activationType_ = pickupActivationType::immediate;
     144            this->setActivationType(pickupActivationType::immediate);
    163145        else if(type == Pickup::activationTypeOnUse_s)
    164             this->activationType_ = pickupActivationType::onUse;
     146            this->setActivationType(pickupActivationType::onUse);
    165147        else
    166148            orxout(internal_error, context::pickups) << "Invalid activationType '" << type << "' in " << this->getIdentifier()->getName() << "." << endl;
     
    173155        The duration type of the Pickup as a string.
    174156    */
    175     void Pickup::setDurationType(const std::string& type)
     157    void Pickup::setDurationTypeAsString(const std::string& type)
    176158    {
    177159        if(type == Pickup::durationTypeOnce_s)
    178             this->durationType_ = pickupDurationType::once;
     160            this->setDurationType(pickupDurationType::once);
    179161        else if(type == Pickup::durationTypeContinuous_s)
    180             this->durationType_ = pickupDurationType::continuous;
     162            this->setDurationType(pickupDurationType::continuous);
    181163        else
    182164            orxout(internal_error, context::pickups) << "Invalid durationType '" << type << "' in " << this->getIdentifier()->getName() << "." << endl;
     
    199181    /**
    200182    @brief
    201         Creates a duplicate of the OrxonoxClass.
    202     @param item
    203         A reference to the pointer of the item that we're duplicating.
    204     */
    205     void Pickup::clone(OrxonoxClass*& item)
    206     {
    207         if(item == NULL)
    208             item = new Pickup(this);
    209 
    210         SUPER(Pickup, clone, item);
    211 
    212         Pickup* pickup = dynamic_cast<Pickup*>(item);
    213         pickup->setActivationTypeDirect(this->getActivationTypeDirect());
    214         pickup->setDurationTypeDirect(this->getDurationTypeDirect());
    215 
    216         pickup->initializeIdentifier();
    217     }
    218 
    219     /**
    220     @brief
    221183        Facilitates the creation of a PickupSpawner upon dropping of the Pickupable.
    222         This method must be implemented by any class directly inheriting from Pickupable. It is most easily done by just creating a new DroppedPickup, e.g.:
    223         DroppedPickup(BaseObject* creator, Pickupable* pickup, const Vector3& position);
    224184    @return
    225185        Returns true if a spawner was created, false if not.
     
    227187    bool Pickup::createSpawner(void)
    228188    {
    229         new DroppedPickup(this, this, this->getCarrier());
     189        PickupSpawner::createDroppedPickup(this, this, this->getCarrier());
    230190        return true;
    231191    }
  • code/trunk/src/modules/pickup/Pickup.h

    r8108 r9348  
    105105            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    106106
     107            virtual const std::string& getRepresentationName() const
     108                { return this->representationName_; }
     109
    107110            /**
    108111            @brief Get the activation type of the Pickup.
    109112            @return Returns the activation type of the Pickup.
    110113            */
    111             inline pickupActivationType::Value getActivationTypeDirect(void) const
     114            inline pickupActivationType::Value getActivationType(void) const
    112115                { return this->activationType_; }
    113116            /**
     
    115118            @return Returns the duration type of the Pickup.
    116119            */
    117             inline pickupDurationType::Value getDurationTypeDirect(void) const
     120            inline pickupDurationType::Value getDurationType(void) const
    118121                { return this->durationType_; }
    119122
    120             const std::string& getActivationType(void) const; //!< Get the activation type of the Pickup.
    121             const std::string& getDurationType(void) const; //!< Get the duration type of the Pickup.
     123            const std::string& getActivationTypeAsString(void) const; //!< Get the activation type of the Pickup.
     124            const std::string& getDurationTypeAsString(void) const; //!< Get the duration type of the Pickup.
    122125
    123126            /**
     
    126129            */
    127130            inline bool isImmediate(void) const
    128                 { return this->getActivationTypeDirect() == pickupActivationType::immediate; }
     131                { return this->getActivationType() == pickupActivationType::immediate; }
    129132            /**
    130133            @brief Get whether the activation type is 'onUse'.
     
    132135            */
    133136            inline bool isOnUse(void) const
    134                 { return this->getActivationTypeDirect() == pickupActivationType::onUse; }
     137                { return this->getActivationType() == pickupActivationType::onUse; }
    135138            /**
    136139            @brief Get whether the duration type is 'once'.
     
    138141            */
    139142            inline bool isOnce(void) const
    140                 { return this->getDurationTypeDirect() == pickupDurationType::once; }
     143                { return this->getDurationType() == pickupDurationType::once; }
    141144            /**
    142145            @brief Get whether the duration type is 'continuous'.
     
    144147            */
    145148            inline bool isContinuous(void) const
    146                 { return this->getDurationTypeDirect() == pickupDurationType::continuous; }
     149                { return this->getDurationType() == pickupDurationType::continuous; }
    147150
    148151            virtual void changedPickedUp(void); //!< Should be called when the pickup has transited from picked up to dropped or the other way around.
    149             virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the OrxonoxClass.
    150152
    151153        protected:
    152             void initializeIdentifier(void);
     154            virtual bool createSpawner(void); //!< Facilitates the creation of a PickupSpawner upon dropping of the Pickupable.
    153155
    154             virtual bool createSpawner(void); //!< Facilitates the creation of a PickupSpawner upon dropping of the Pickupable.
     156            /**
     157            @brief Sets the representation name which refers to the name of the PickupRepresentation that is used to represent this pickup.
     158            */
     159            inline void setRepresentationName(const std::string& name)
     160                { this->representationName_ = name; }
    155161
    156162            /**
     
    158164            @param type The activation type of the Pickup.
    159165            */
    160             inline void setActivationTypeDirect(pickupActivationType::Value type)
     166            inline void setActivationType(pickupActivationType::Value type)
    161167                { this->activationType_ = type; }
    162168            /**
     
    164170            @param type The duration type of the Pickup.
    165171            */
    166             inline void setDurationTypeDirect(pickupDurationType::Value type)
     172            inline void setDurationType(pickupDurationType::Value type)
    167173                { this->durationType_ = type; }
    168174
    169             void setActivationType(const std::string& type); //!< Set the activation type of the Pickup.
    170             void setDurationType(const std::string& type); //!< Set the duration type of the Pickup.
     175            void setActivationTypeAsString(const std::string& type); //!< Set the activation type of the Pickup.
     176            void setDurationTypeAsString(const std::string& type); //!< Set the duration type of the Pickup.
    171177
    172178        private:
    173179            void initialize(void); //!< Initializes the member variables.
    174180
     181            std::string representationName_; //!< The name of the associated PickupRepresentation.
    175182            pickupActivationType::Value activationType_; //!< The activation type of the Pickup.
    176183            pickupDurationType::Value durationType_; //!< The duration type of the Pickup.
  • code/trunk/src/modules/pickup/PickupCollection.cc

    r8305 r9348  
    3838
    3939#include "CollectiblePickup.h"
    40 #include "DroppedPickup.h"
    41 #include "PickupCollectionIdentifier.h"
     40#include "PickupSpawner.h"
    4241
    4342#include "PickupCollection.h"
     
    5453        The creator of the object.
    5554    */
    56     PickupCollection::PickupCollection(BaseObject* creator) : BaseObject(creator), pickupCollectionIdentifier_(NULL)
     55    PickupCollection::PickupCollection(BaseObject* creator) : BaseObject(creator)
    5756    {
    5857        RegisterObject(PickupCollection);
    5958
    60         this->pickupCollectionIdentifier_ = new PickupCollectionIdentifier(this);
    61         this->usedCounter_ = 0;
    62         this->pickedUpCounter_ = 0;
    63         this->disabledCounter_ = 0;
    6459        this->processingUsed_ = false;
    6560        this->processingPickedUp_ = false;
     
    7065        Destructor. Iterates through all Pickupables this PickupCollection consists of and destroys them if they haven't been already.
    7166    */
    72     PickupCollection::~ PickupCollection()
     67    PickupCollection::~PickupCollection()
    7368    {
    7469        // Destroy all Pickupables constructing this PickupCollection.
    75         for(std::vector<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
    76         {
    77             (*it)->removeFromCollection();
     70        for(std::list<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); ++it)
     71        {
     72            (*it)->wasRemovedFromCollection();
    7873            (*it)->destroy();
    7974        }
    8075        this->pickups_.clear();
    81        
    82         if(this->pickupCollectionIdentifier_ != NULL)
    83             delete this->pickupCollectionIdentifier_;
    8476    }
    8577
     
    9284        SUPER(PickupCollection, XMLPort, xmlelement, mode);
    9385
     86        XMLPortParam(PickupCollection, "representation", setRepresentationName, getRepresentationName, xmlelement, mode);
    9487        XMLPortObject(PickupCollection, CollectiblePickup, "pickupables", addPickupable, getPickupable, xmlelement, mode);
    95 
    96         this->initializeIdentifier();
    97     }
    98 
    99     /**
    100     @brief
    101         Initializes the PickupIdentifier for this pickup.
    102     */
    103     void PickupCollection::initializeIdentifier(void)
    104     {
    105         for(std::vector<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
    106         {
    107             this->pickupCollectionIdentifier_->addPickup((*it)->getPickupIdentifier());
    108         }
    10988    }
    11089
     
    12099        this->processingUsed_ = true;
    121100        // Change used for all Pickupables this PickupCollection consists of.
    122         for(std::vector<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
     101        for(std::list<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); ++it)
    123102            (*it)->setUsed(this->isUsed());
    124103
     
    138117            return;
    139118
     119        size_t numPickupsEnabled = 0;
     120        size_t numPickupsInUse = 0;
     121        for(std::list<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); ++it)
     122        {
     123            if ((*it)->isEnabled())
     124                ++numPickupsEnabled;
     125            if ((*it)->isUsed())
     126                ++numPickupsInUse;
     127        }
     128
    140129        // If all the pickups are not in use but the PickupCollection is.
    141         if(this->usedCounter_ == 0 && this->isUsed())
     130        if(numPickupsInUse == 0 && this->isUsed())
    142131            this->setUsed(false);
    143132
    144133        // If all the enabled pickups are in use but the PickupCollection is not.
    145         if(this->usedCounter_ != 0 && this->usedCounter_ == this->pickups_.size()-this->disabledCounter_ && !this->isUsed())
     134        if(numPickupsInUse > 0 && numPickupsInUse == numPickupsEnabled && !this->isUsed())
    146135            this->setUsed(true);
    147136    }
     
    157146
    158147        // Change the PickupCarrier for all Pickupables this PickupCollection consists of.
    159         for(std::vector<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
     148        for(std::list<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); ++it)
    160149        {
    161150            if(this->getCarrier() == NULL)
     
    177166        this->processingPickedUp_ = true;
    178167        // Change the pickedUp status for all Pickupables this PickupCollection consists of.
    179         for(std::vector<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
    180             (*it)->setPickedUp(this->isPickedUp());
     168        for(std::list<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); )
     169            (*(it++))->setPickedUp(this->isPickedUp());
    181170
    182171        this->processingPickedUp_ = false;
     
    195184            return;
    196185
    197         // If at least all the enabled pickups of this PickupCollection are no longer picked up.
    198         if(this->pickedUpCounter_ <= this->disabledCounter_ && this->isPickedUp())
     186        // If at least all the enabled pickups of this PickupCollection are no longer picked up.
     187        bool isOnePickupEnabledAndPickedUp = false;
     188        for(std::list<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); ++it)
     189        {
     190            if ((*it)->isEnabled() && (*it)->isPickedUp())
     191            {
     192                isOnePickupEnabledAndPickedUp = true;
     193                break;
     194            }
     195        }
     196        if(!isOnePickupEnabledAndPickedUp && this->isPickedUp())
    199197            this->Pickupable::destroy();
    200 
    201         // If the PickupCollection is no longer picked up.
    202         if(!this->isPickedUp())
    203             this->pickedUpCounter_ = 0;
    204     }
    205 
    206     /**
    207     @brief
    208         Creates a duplicate of the input Pickupable.
    209         This method needs to be implemented by any Class inheriting from Pickupable.
    210     @param item
    211         A reference to a pointer to the OrxonoxClass that is to be duplicated.
    212     */
    213     void PickupCollection::clone(OrxonoxClass*& item)
    214     {
    215         if(item == NULL)
    216             item = new PickupCollection(this);
    217 
    218         SUPER(PickupCollection, clone, item);
    219 
    220         PickupCollection* pickup = dynamic_cast<PickupCollection*>(item);
    221         // Clone all Pickupables this PickupCollection consist of.
    222         for(std::vector<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
    223         {
    224             Pickupable* newPickup = (*it)->clone();
    225             CollectiblePickup* collectible = static_cast<CollectiblePickup*>(newPickup);
    226             pickup->addPickupable(collectible);
    227         }
    228 
    229         pickup->initializeIdentifier();
    230198    }
    231199
     
    240208    bool PickupCollection::isTarget(const PickupCarrier* carrier) const
    241209    {
    242         for(std::vector<CollectiblePickup*>::const_iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
     210        for(std::list<CollectiblePickup*>::const_iterator it = this->pickups_.begin(); it != this->pickups_.end(); ++it)
    243211        {
    244212            if(!carrier->isTarget(*it))
     
    247215
    248216        return true;
    249     }
    250 
    251     /**
    252     @brief
    253         Get the PickupIdentifier of this PickupCollection.
    254         This is in fact the PickupCollectionIdentifier.
    255     @return
    256         Returns a pointer to the PickupIdentifier of this PickupCollection.
    257     */
    258     const PickupIdentifier* PickupCollection::getPickupIdentifier(void) const
    259     {
    260         return this->pickupCollectionIdentifier_;
    261217    }
    262218
     
    274230            return false;
    275231
    276         pickup->addToCollection(this);
    277232        this->pickups_.push_back(pickup);
     233        pickup->wasAddedToCollection(this);
     234        this->pickupsChanged();
    278235        return true;
    279236    }
     
    289246    const Pickupable* PickupCollection::getPickupable(unsigned int index) const
    290247    {
    291         return this->pickups_[index];
     248        if(this->pickups_.size() >= index)
     249            return NULL;
     250
     251        std::list<CollectiblePickup*>::const_iterator it = this->pickups_.begin();
     252        std::advance(it, index);
     253        return *it;
     254    }
     255
     256    /**
     257    @brief
     258        Removes the Pickup from the Collection.
     259    @param pickup
     260        The Pickup to be removed.
     261    @return
     262        Returns true if the pickup was in the collection.
     263    */
     264    bool PickupCollection::removePickupable(CollectiblePickup* pickup)
     265    {
     266        for(std::list<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); ++it)
     267        {
     268            if (*it == pickup)
     269            {
     270                this->pickups_.erase(it);
     271                pickup->wasRemovedFromCollection();
     272                this->pickupsChanged();
     273                return true;
     274            }
     275        }
     276        return false;
    292277    }
    293278
     
    297282        This is used internally by the CollectiblePickup class.
    298283    @param changed
    299         The value the used status has changed to. 
     284        The value the used status has changed to.
    300285    */
    301286    void PickupCollection::pickupChangedUsed(bool changed)
    302287    {
    303         if(changed)
    304             this->usedCounter_++;
    305         else
    306             this->usedCounter_--;
    307 
    308288        this->changedUsedAction();
    309289    }
     
    318298    void PickupCollection::pickupChangedPickedUp(bool changed)
    319299    {
    320         if(changed)
    321             this->pickedUpCounter_++;
    322         else
    323             this->pickedUpCounter_--;
    324 
    325300        this->changedPickedUpAction();
    326301    }
     
    333308    void PickupCollection::pickupDisabled(void)
    334309    {
    335         this->disabledCounter_++;
     310    }
     311
     312    /**
     313    @brief
     314        Helpfer function if the number of pickups in this collection has changed.
     315    */
     316    void PickupCollection::pickupsChanged(void)
     317    {
     318        this->changedUsedAction();
     319        this->changedPickedUpAction();
    336320    }
    337321
     
    339323    @brief
    340324        Facilitates the creation of a PickupSpawner upon dropping of the Pickupable.
    341         This method must be implemented by any class directly inheriting from Pickupable. It is most easily done by just creating a new DroppedPickup, e.g.:
    342         DroppedPickup(BaseObject* creator, Pickupable* pickup, const Vector3& position);
    343325    @return
    344326        Returns true if a spawner was created, false if not.
     
    346328    bool PickupCollection::createSpawner(void)
    347329    {
    348         new DroppedPickup(this, this, this->getCarrier());
     330        PickupSpawner::createDroppedPickup(this, this, this->getCarrier());
    349331        return true;
    350332    }
  • code/trunk/src/modules/pickup/PickupCollection.h

    r8351 r9348  
    5050        The PickupCollection combines different @ref orxonox::Pickupable "Pickupables" (more precisely @ref orxonox::CollectiblePickup "CollectiblePickups") to a coherent, single pickup and makes them seem (from the outside looking in) just as if they were just one @ref orxonox::Pickupable "Pickupable".
    5151
    52         To differentiate between different types of @ref orxonox::PickupCollection "PickupCollections" (just as we differentiate between different types of @ref orxonox::Pickupable "Pickupables") we define a new identifyer called the @ref orxonox::PickupCollectionIdentifier "PickupCollectionIdentifier" which has pretty much the same properties as the @ref orxonox::PickupIdentifier "PickupIdentifier" but extende to @ref orxonox::PickupCollection "PickupCollections".
    53 
    5452        A PickupCollection can be created in XML as follows:
    5553        @code
     
    8179            virtual void changedPickedUp(void); //!< Is called when the pickup has transited from picked up to dropped or the other way around.
    8280
    83             virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input pickup.
    84 
    8581            virtual bool isTarget(const PickupCarrier* carrier) const; //!< Get whether a given class, represented by the input Identifier, is a target of this PickupCollection.
    8682
    87             virtual const PickupIdentifier* getPickupIdentifier(void) const; //!< Get the PickupIdentifier of this PickupCollection.
     83            inline void setRepresentationName(const std::string& name)
     84                { this->representationName_ = name; }
     85            virtual const std::string& getRepresentationName() const
     86                { return this->representationName_; }
    8887
    8988            bool addPickupable(CollectiblePickup* pickup); //!< Add the input Pickupable to list of Pickupables combined by this PickupCollection.
    9089            const Pickupable* getPickupable(unsigned int index) const; //!< Get the Pickupable at the given index.
     90            bool removePickupable(CollectiblePickup* pickup); //!< Removes the input Pickupable from the list of Pickupables in this PickupCollection.
     91
     92            inline const std::list<CollectiblePickup*>& getPickups() const
     93                { return this->pickups_; }
    9194
    9295            void pickupChangedUsed(bool changed); //!< Informs the PickupCollection, that one of its pickups has changed its used status to the input value.
     
    9598
    9699        protected:
    97             void initializeIdentifier(void); //!< Initializes the PickupIdentifier for this pickup.
    98 
    99100            virtual bool createSpawner(void); //!< Facilitates the creation of a PickupSpawner upon dropping of the Pickupable.
    100 
    101             PickupCollectionIdentifier* pickupCollectionIdentifier_; //!< The PickupCollectionIdentifier of this PickupCollection. Is used to distinguish different PickupCollections amongst themselves.
    102101
    103102        private:
    104103            void changedUsedAction(void); //!< Helper method.
    105104            void changedPickedUpAction(void); //!< Helper method.
     105            void pickupsChanged(void); //!< Helper method.
    106106
    107             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.
    108 
    109             unsigned int usedCounter_; //!< Keeps track of the number of pickups of this PickupCollection, that are in use.
    110             unsigned int pickedUpCounter_; //!< Keeps track of the number of pickups of this PickupCollection, that are picked up.
    111             unsigned int disabledCounter_; //!< Keeps track of the number of pickups of this PickupCollection, that are disabled.
     107            std::string representationName_; //!< The name of the associated PickupRepresentation.
     108            std::list<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.
    112109
    113110            bool processingUsed_; //!< Boolean to ensure, that the PickupCollection doesn't update its used status while its internal state is inconsistent.
  • code/trunk/src/modules/pickup/PickupManager.cc

    r8858 r9348  
    8787
    8888        this->representations_.clear();
    89         this->representationsNetworked_.clear();
    9089
    9190        // Destroying all the PickupInventoryContainers that are still there.
     
    106105    /**
    107106    @brief
    108         Registers a PickupRepresentation together with the PickupIdentifier of the Pickupable the PickupRepresentation represents, on the server (or in standalone mode).
    109         For every type of Pickupable (uniquely identified by a PickupIdentifier) there can be one (and just one) PickupRepresentation registered.
    110     @param identifier
    111         The PickupIdentifier identifying the Pickupable.
     107        Registers a PickupRepresentation.
     108    @param name
     109        The representation's name.
    112110    @param representation
    113111        A pointer to the PickupRepresentation.
     
    115113        Returns true if successful and false if not.
    116114    */
    117     bool PickupManager::registerRepresentation(const PickupIdentifier* identifier, PickupRepresentation* representation)
    118     {
    119         assert(identifier);
     115    bool PickupManager::registerRepresentation(const std::string& name, PickupRepresentation* representation)
     116    {
    120117        assert(representation);
    121118
    122119        // If the list is not empty and Pickupable already has a Representation registered.
    123         if(!this->representations_.empty() && this->representations_.find(identifier) != this->representations_.end())
     120        if(!this->representations_.empty() && this->representations_.find(name) != this->representations_.end())
    124121            return false;
    125122
    126         this->representations_[identifier] = representation;
     123        this->representations_[name] = representation;
    127124
    128125        orxout(verbose, context::pickups) << "PickupRepresentation &" << representation << " registered with the PickupManager." << endl;
     
    132129    /**
    133130    @brief
    134         Unegisters a PickupRepresentation together with the PickupIdentifier of the Pickupable the PickupRepresentation represents, on the server (or in standalone mode).
    135     @param identifier
    136         The PickupIdentifier identifying the Pickupable.
    137     @param representation
    138         A pointer to the PickupRepresentation.
     131        Unegisters a PickupRepresentation.
     132    @param name
     133        The representation's name.
    139134    @return
    140135        Returns true if successful and false if not.
    141136    */
    142     bool PickupManager::unregisterRepresentation(const PickupIdentifier* identifier, PickupRepresentation* representation)
    143     {
    144         assert(identifier);
    145         assert(representation);
    146 
    147         std::map<const PickupIdentifier*, PickupRepresentation*, PickupIdentifierCompare>::iterator it = this->representations_.find(identifier);
     137    bool PickupManager::unregisterRepresentation(const std::string& name)
     138    {
     139        std::map<std::string, PickupRepresentation*>::iterator it = this->representations_.find(name);
    148140        if(it == this->representations_.end()) // If the Pickupable is not registered in the first place.
    149141            return false;
     
    151143        this->representations_.erase(it);
    152144
    153         orxout(verbose, context::pickups) << "PickupRepresentation &" << representation << " unregistered with the PickupManager." << endl;
     145        orxout(verbose, context::pickups) << "PickupRepresentation &" << name << " unregistered with the PickupManager." << endl;
    154146        return true;
    155147    }
     
    157149    /**
    158150    @brief
    159         Registers a PickupRepresentation on the host it was created.
    160     @param representation
    161         A pointer to the PickupRepresentation.
    162     @return
    163         Returns true if successful, false if not.
    164     */
    165     bool PickupManager::registerRepresentation(PickupRepresentation* representation)
    166     {
    167         assert(representation);
    168 
    169         // If the list is not empty and PickupRepresentation is already registered.
    170         if(!this->representationsNetworked_.empty() && this->representationsNetworked_.find(representation->getObjectID()) != this->representationsNetworked_.end())
    171             return false;
    172 
    173         this->representationsNetworked_[representation->getObjectID()] = representation;
    174         return true;
    175     }
    176 
    177     /**
    178     @brief
    179         Unregisters a PickupRepresentation on the host it is being destroyed (which is the same host on which it was created).
    180     @param representation
    181         A pointer to the Pickuprepresentation.
    182     @return
    183         Returns true if successful, false if not.
    184     */
    185     bool PickupManager::unregisterRepresentation(PickupRepresentation* representation)
    186     {
    187         assert(representation);
    188 
    189         std::map<uint32_t, PickupRepresentation*>::iterator it = this->representationsNetworked_.find(representation->getObjectID());
    190         if(it == this->representationsNetworked_.end()) // If the Pickupable is not registered in the first place.
    191             return false;
    192 
    193         this->representationsNetworked_.erase(it);
    194         return true;
    195     }
    196 
    197     /**
    198     @brief
    199         Get the PickupRepresentation representing the Pickupable with the input PickupIdentifier.
    200     @param identifier
    201         The PickupIdentifier.
     151        Get the PickupRepresentation with the given name.
     152    @param name
     153        The name of the PickupRepresentation.
    202154    @return
    203155        Returns a pointer to the PickupRepresentation.
    204156    */
    205     PickupRepresentation* PickupManager::getRepresentation(const PickupIdentifier* identifier)
    206     {
    207         std::map<const PickupIdentifier*, PickupRepresentation*, PickupIdentifierCompare>::iterator it = this->representations_.find(identifier);
    208         if(it == this->representations_.end()) // If there is no PickupRepresentation associated with the input PickupIdentifier.
     157    PickupRepresentation* PickupManager::getRepresentation(const std::string& name)
     158    {
     159        std::map<std::string, PickupRepresentation*>::iterator it = this->representations_.find(name);
     160        if(it == this->representations_.end()) // If there is no PickupRepresentation associated with the input name.
    209161        {
    210162            orxout(verbose, context::pickups) << "PickupManager::getRepresentation() returned default representation." << endl;
     
    353305        {
    354306            // If there is no PickupRepresentation registered the default representation is used.
    355             if(this->representations_.find(pickup->getPickupIdentifier()) == this->representations_.end())
    356                 PickupManager::pickupChangedPickedUpNetwork(index, pickup->isUsable(), this->defaultRepresentation_->getObjectID(), pickedUp);
     307            if(this->representations_.find(pickup->getRepresentationName()) == this->representations_.end())
     308                PickupManager::pickupChangedPickedUpNetwork(index, pickup->isUsable(), this->defaultRepresentation_->getObjectID(), pickup->getRepresentationName(), pickedUp);
    357309            else
    358                 PickupManager::pickupChangedPickedUpNetwork(index, pickup->isUsable(), this->representations_[pickup->getPickupIdentifier()]->getObjectID(), pickedUp);
     310                PickupManager::pickupChangedPickedUpNetwork(index, pickup->isUsable(), this->representations_[pickup->getRepresentationName()]->getObjectID(), pickup->getRepresentationName(), pickedUp);
    359311        }
    360312        // If the concerned host is somewhere in the network, we call pickupChangedPickedUpNetwork() on its PickupManager.
     
    362314        {
    363315            // If there is no PickupRepresentation registered the default representation is used.
    364             if(this->representations_.find(pickup->getPickupIdentifier()) == this->representations_.end())
     316            if(this->representations_.find(pickup->getRepresentationName()) == this->representations_.end())
    365317            {
    366318                callStaticNetworkFunction(PickupManager::pickupChangedPickedUpNetwork, clientId, index, pickup->isUsable(), this->defaultRepresentation_->getObjectID(), pickedUp);
     
    368320            else
    369321            {
    370                 callStaticNetworkFunction(PickupManager::pickupChangedPickedUpNetwork, clientId, index, pickup->isUsable(), this->representations_[pickup->getPickupIdentifier()]->getObjectID(), pickedUp);
     322                callStaticNetworkFunction(PickupManager::pickupChangedPickedUpNetwork, clientId, index, pickup->isUsable(), this->representations_[pickup->getRepresentationName()]->getObjectID(), pickedUp);
    371323            }
    372324        }
     
    388340        The pickedUp status the Pickupable changed to.
    389341    */
    390     /*static*/ void PickupManager::pickupChangedPickedUpNetwork(uint32_t pickup, bool usable, uint32_t representationObjectId, bool pickedUp)
     342    /*static*/ void PickupManager::pickupChangedPickedUpNetwork(uint32_t pickup, bool usable, uint32_t representationObjectId, const std::string& representationName, bool pickedUp)
    391343    {
    392344        PickupManager& manager = PickupManager::getInstance(); // Get the PickupManager singleton on this host.
     
    402354            container->unusable = false;
    403355            container->representationObjectId = representationObjectId;
     356            container->representationName = representationName;
    404357            // Insert the container into the pickupInventoryContainers_ list.
    405358            manager.pickupInventoryContainers_.insert(std::pair<uint32_t, PickupInventoryContainer*>(pickup, container));
     
    417370            manager.updateGUI(); // Tell the PickupInventory that something has changed.
    418371        }
    419     }
    420 
    421     /**
    422     @brief
    423         Get the PickupRepresentation of an input Pickupable.
    424         This method spares us the hassle to export the PickupIdentifier class to lua.
    425     @param pickup
    426         The number identifying the Pickupable whose PickupRepresentation should be returned.
    427     @return
    428         Returns the PickupRepresentation of the input Pickupable or NULL if an error occurred.
    429     */
    430     orxonox::PickupRepresentation* PickupManager::getPickupRepresentation(uint32_t pickup)
    431     {
    432         // Clear and rebuild the representationsNetworked_ list.
    433         //TODO: Better solution?
    434         this->representationsNetworked_.clear();
    435         for(ObjectList<PickupRepresentation>::iterator it = ObjectList<PickupRepresentation>::begin(); it != ObjectList<PickupRepresentation>::end(); ++it)
    436             this->representationsNetworked_[it->getObjectID()] = *it;
    437 
    438         // Get the container belonging to the input pickup, if not found return the default representation.
    439         std::map<uint32_t, PickupInventoryContainer*>::iterator it = this->pickupInventoryContainers_.find(pickup);
    440         if(it == this->pickupInventoryContainers_.end())
    441             return this->defaultRepresentation_;
    442 
    443         // Get the PickupRepresentation of the input pickup (through the objecId of the representation stored in the PickupInventoryContainer belonging to the pickup), if not found return the default representation.
    444         std::map<uint32_t, PickupRepresentation*>::iterator it2 = this->representationsNetworked_.find(it->second->representationObjectId);
    445         if(it2 == this->representationsNetworked_.end())
    446             return this->defaultRepresentation_;
    447 
    448         return it2->second;
    449372    }
    450373
  • code/trunk/src/modules/pickup/PickupManager.h

    r8706 r9348  
    4141#include "core/WeakPtr.h"
    4242
    43 #include "pickup/PickupIdentifier.h"
    44 
    4543#include "PickupRepresentation.h"
    4644
     
    6765        bool unusable; //!< Whether the @ref orxonox::Pickupable "Pickupable" is droppable.
    6866        uint32_t representationObjectId; //!< The objectId of the @ref orxonox::PickupRepresentation "PickupRepresentation" that represents the @ref orxonox::Pickupable "Pickupable".
     67        std::string representationName; //!< The name of the associated PickupRepresentation
    6968    };
    7069    // tolua_end
     
    7473        The PickupManager class manages @ref orxonox::Pickupable "Pickupables".
    7574
    76         It has in essence two tasks to fulfill. Firstly it must link @ref orxonox::Pickupable "Pickupables" (through their @ref orxonox::PickupIdentifier "PickupIdentifiers") to their respective @ref orxonox::PickupRepresentation "PickupRepresentations". Secondly it manages the PickupInventory. (The PickupInventory is the GUI that displays @ref orxonox::Pickupable "Pickupables" for the covenience of the user.)
     75        It has in essence two tasks to fulfill. Firstly it must link @ref orxonox::Pickupable "Pickupables" (through their representation-name attribute) to the respective @ref orxonox::PickupRepresentation "PickupRepresentations". Secondly it manages the PickupInventory. (The PickupInventory is the GUI that displays @ref orxonox::Pickupable "Pickupables" for the covenience of the user.)
    7776
    7877        @section PickupManagerTechnicalDetails Technical details
     
    8685
    8786        Firstly there are a number of lists (where by list I really mean any kind of ordered data structure) kept.
    88         - The @ref orxonox::PickupManager::representations_ "representations_" list links @ref orxonox::PickupRepresentation "PickupRepresentations" with @ref orxonox::PickupIdentifier "PickupIdentifiers" and can be used to get the @ref orxonox::PickupRepresentation "PickupRepresentation" for a given @ref orxonox::Pickupable "Pickupable". It is only populated on the server (or in standalone mode). Each @ref orxonox::PickupRepresentation "PickupRepresentation" that is generated through XML registers itself with the PickupManager and is thereby added to the list.
    89         - The @ref orxonox::PickupManager::representationsNetworked_ "representationsNetworked_" list is the networked (hence the name) equivalent to the @ref orxonox::PickupManager::representations_ "representations_" list. It links an objectId of a @ref orxonox::PickupRepresentation "PickupRepresentation" to a @ref orxonox::PickupRepresentation "PickupRepresentation". This list is maintained on all hosts, each representation registers itself (in its constructor) with the PickupManager. Since the representations are synchronised they are created on each host. The "same" instance on each host is identified by the same objectId and that is why we store the representations with the objectId as key. We can then use this list to get a @ref orxonox::PickupRepresentation "PickupRepresentation" for a specific @ref orxonox::Pickupable "Pickupable" (or more precisely a number identifiying that particular pickup, but we'll see that, when we look at the next list) on a client to be used in the PickupInventory.
     87        - The @ref orxonox::PickupManager::representations_ "representations_" list links @ref orxonox::PickupRepresentation "PickupRepresentations" with its name and can be used to get the @ref orxonox::PickupRepresentation "PickupRepresentation" for a given @ref orxonox::Pickupable "Pickupable". It is only populated on the server (or in standalone mode). Each @ref orxonox::PickupRepresentation "PickupRepresentation" that is generated through XML registers itself with the PickupManager and is thereby added to the list.
    9088        - The @ref orxonox::PickupManager::pickupInventoryContainers_ "pickupInventoryContainers_" list links a number identifying a @ref orxonox::Pickupable "Pickupable" to a data structure (the @ref orxonox::PickupInventoryContainer "PickupInventoryContainer"), which contains all necessary information about that @ref orxonox::Pickupable "Pickupable". This list is maintained on all hosts, a new container is inserted when a @ref orxonox::Pickupable "Pickupable" is picked up, but only if it has been picked up by the repsective host. This list is then used by the PickupInventory to access the required information and to get the correct @ref orxonox::PickupRepresentation "PickupRepresentation".
    9189        - The @ref orxonox::PickupManager::pickups_ "pickups_" list links a number identifiying a @ref orxonox::Pickupable "Pickupable" to a (weak pointer to a) @ref orxonox::Pickupable "Pickupable". It is only maintained by the server (or in standalone mode), to be able to use, unuse and drop @ref orxonox::Pickupable "Pickupables" through the PickupInventory. Since @ref orxonox::Pickupable "Pickupables" only exist on the server a client that wants to change a pickups status has so send a request over the network (with the number identifying the pickup) to the server and then the server facilitates the change, using this list to map from the identifyer to the actual @ref orxonox::Pickupable "Pickupable".
     
    114112            static PickupManager& getInstance() { return Singleton<PickupManager>::getInstance(); } // tolua_export
    115113
    116             bool registerRepresentation(const PickupIdentifier* identifier, PickupRepresentation* representation); //!< Registers a PickupRepresentation together with the PickupIdentifier of the Pickupable the PickupRepresentation represents.
    117             bool unregisterRepresentation(const PickupIdentifier* identifier, PickupRepresentation* representation); //!< Unegisters a PickupRepresentation together with the PickupIdentifier of the Pickupable the PickupRepresentation represents.
     114            bool registerRepresentation(const std::string& name, PickupRepresentation* representation);
     115            bool unregisterRepresentation(const std::string& name);
    118116
    119             bool registerRepresentation(PickupRepresentation* representation); //!< Registers a PickupRepresentation on the host it was created.
    120             bool unregisterRepresentation(PickupRepresentation* representation); //!< Unregisters a PickupRepresentation on the host it is being destroyed.
    121 
    122             PickupRepresentation* getRepresentation(const PickupIdentifier* identifier); //!< Get the PickupRepresentation representing the Pickupable with the input PickupIdentifier.
     117            PickupRepresentation* getRepresentation(const std::string& name); // tolua_export
    123118
    124119            virtual void pickupChangedUsed(Pickupable* pickup, bool used); //!< Is called by the PickupListener to notify the PickupManager, that the input Pickupable has transited to the input used state.
    125120            static void pickupChangedUsedNetwork(uint32_t pickup, bool inUse, bool usable, bool unusable); //!< Helper method to react to the change in the used status of a Pickupable.
    126121            virtual void pickupChangedPickedUp(Pickupable* pickup, bool pickedUp); //!< Is called by the PickupListener to notify the PickupManager, that the input Pickupable has transited to the input pickedUp state.
    127             static void pickupChangedPickedUpNetwork(uint32_t pickup, bool usable, uint32_t representationObjectId, bool pickedUp); //!< Helper method to react to the change in the pickedUp status of a Pickupable.
     122            static void pickupChangedPickedUpNetwork(uint32_t pickup, bool usable, uint32_t representationObjectId, const std::string& representationName, bool pickedUp); //!< Helper method to react to the change in the pickedUp status of a Pickupable.
    128123
    129124        // Methods to be used by the PickupInventory.
    130125        public:
    131126            // tolua_begin
    132             orxonox::PickupRepresentation* getPickupRepresentation(uint32_t pickup); //!< Get the PickupRepresentation of an input indentifier for Pickupable.
    133 
    134127            int getNumPickups(void); //!< Get the number of pickups currently picked up by the player.
    135128            /**
     
    163156            PickupRepresentation* defaultRepresentation_; //!< The default PickupRepresentation.
    164157
    165             std::map<const PickupIdentifier*, PickupRepresentation*, PickupIdentifierCompare> representations_; //!< Map linking PickupIdentifiers (representing types of Pickupables) and PickupRepresentations.
    166             std::map<uint32_t, PickupRepresentation*> representationsNetworked_; //!< Map linking the PickupRepresentation's objectId to the PickupRepresentation itself. It is used for networking purposes.
     158            std::map<std::string, PickupRepresentation*> representations_; //!< Map linking PickupRepresentations and their names.
    167159
    168160            std::map<uint32_t, PickupInventoryContainer*> pickupInventoryContainers_; //!< Map linking a number identifying a Pickupable to a PickupInventoryContainer, which contains all necessary information about that Pickupable.
  • code/trunk/src/modules/pickup/PickupPrereqs.h

    r8706 r9348  
    7070
    7171    class CollectiblePickup;
    72     class DroppedPickup;
    7372    class Pickup;
    7473    class PickupCollection;
    75     class PickupCollectionIdentifier;
    7674    class PickupManager;
    7775    class PickupRepresentation;
     
    8684    class ShieldPickup;
    8785    class ShrinkPickup;
    88 
     86    class DamageBoostPickup;
    8987}
    9088
  • code/trunk/src/modules/pickup/PickupRepresentation.cc

    r8858 r9348  
    5252        This is primarily for use of the PickupManager in creating a default PickupRepresentation.
    5353    */
    54     PickupRepresentation::PickupRepresentation() : BaseObject(NULL), Synchronisable(NULL), spawnerRepresentation_(NULL), pickup_(NULL)
     54    PickupRepresentation::PickupRepresentation() : BaseObject(NULL), Synchronisable(NULL), spawnerRepresentation_(NULL)
    5555    {
    5656        RegisterObject(PickupRepresentation);
     
    6464        Default Constructor. Registers the object and initializes its member variables.
    6565    */
    66     PickupRepresentation::PickupRepresentation(BaseObject* creator) : BaseObject(creator), Synchronisable(creator), spawnerRepresentation_(NULL), pickup_(NULL)
     66    PickupRepresentation::PickupRepresentation(BaseObject* creator) : BaseObject(creator), Synchronisable(creator), spawnerRepresentation_(NULL)
    6767    {
    6868        RegisterObject(PickupRepresentation);
     
    7070        this->initialize();
    7171        this->registerVariables();
    72 
    73         PickupManager::getInstance().registerRepresentation(this); // Registers the PickupRepresentation with the PickupManager.
    7472    }
    7573
     
    8482
    8583        if(this->isInitialized())
    86         {
    87             if(GameMode::isMaster() && this->pickup_ != NULL)
    88             {
    89                 PickupManager::getInstance().unregisterRepresentation(this->pickup_->getPickupIdentifier(), this);
    90             }
    91             PickupManager::getInstance().unregisterRepresentation(this);
    92         }
     84            PickupManager::getInstance().unregisterRepresentation(this->getName());
    9385    }
    9486
     
    128120        XMLPortParam(PickupRepresentation, "spawnerTemplate", setSpawnerTemplate, getSpawnerTemplate, xmlelement, mode);
    129121        XMLPortParam(PickupRepresentation, "inventoryRepresentation", setInventoryRepresentation, getInventoryRepresentation, xmlelement, mode);
    130         XMLPortObject(PickupRepresentation, Pickupable, "pickup", setPickup, getPickup, xmlelement, mode);
    131122        XMLPortObject(PickupRepresentation, StaticEntity, "spawner-representation", setSpawnerRepresentation, getSpawnerRepresentationIndex, xmlelement, mode);
    132 
    133         if(GameMode::isMaster())
    134         {
    135             // Registers the PickupRepresentation with the PickupManager through the PickupIdentifier of the Pickupable it represents.
    136             PickupManager::getInstance().registerRepresentation(this->pickup_->getPickupIdentifier(), this);
    137         }
    138 
    139         if(this->spawnerRepresentation_ != NULL)
    140             this->spawnerRepresentation_->setVisible(false);
    141123
    142124        orxout(verbose, context::pickups) << "PickupRepresentation created: name: '" << this->name_ << "', description: '" << this->description_ << "', spawnerTemplate: '" << this->spawnerTemplate_ << "'." << endl;
     
    151133        Returns a pointer to the StaticEntity.
    152134    */
    153     StaticEntity* PickupRepresentation::getSpawnerRepresentation(PickupSpawner* spawner)
     135    StaticEntity* PickupRepresentation::createSpawnerRepresentation(PickupSpawner* spawner)
    154136    {
    155137        if(this->spawnerRepresentation_ == NULL)
     
    158140            if(this->spawnerTemplate_ == "")
    159141            {
    160                 orxout(verbose, context::pickups) << "PickupRepresentation: Spawner template is empty." << endl;
     142                orxout(internal_warning, context::pickups) << "PickupRepresentation: Spawner template is empty." << endl;
    161143                // If neither spawnerRepresentation nor spawnerTemplate was specified
    162144                return this->getDefaultSpawnerRepresentation(spawner);
     
    165147        }
    166148
    167         StaticEntity* representation = this->spawnerRepresentation_;
    168         representation->setVisible(true);
     149        this->spawnerRepresentation_->setVisible(true);
     150        StaticEntity* temp = this->spawnerRepresentation_;
     151        this->spawnerRepresentation_ = NULL;
    169152
    170         this->addTemplate(this->spawnerTemplate_);
    171         this->spawnerRepresentation_->setVisible(false);
     153        return temp;
     154    }
    172155
    173         return representation;
     156    void PickupRepresentation::changedName()
     157    {
     158        // Registers the PickupRepresentation with the PickupManager.
     159        PickupManager::getInstance().unregisterRepresentation(this->getOldName());
     160        PickupManager::getInstance().registerRepresentation(this->getName(), this);
     161    }
     162
     163    void PickupRepresentation::setSpawnerRepresentation(StaticEntity* representation)
     164    {
     165        this->spawnerRepresentation_ = representation;
     166        if(this->spawnerRepresentation_ != NULL)
     167            this->spawnerRepresentation_->setVisible(false);
    174168    }
    175169
  • code/trunk/src/modules/pickup/PickupRepresentation.h

    r7547 r9348  
    4141
    4242#include "interfaces/Pickupable.h"
    43 #include "pickup/PickupIdentifier.h"
    4443#include "worldentities/StaticEntity.h"
    4544
     
    5453    /**
    5554    @brief
    56         The PickupRepresentation class represents a specific pickup type (identified by its @ref orxonox::PickupIdentifier "PickupIdentifier"). It defines the information displayed in the GUI (PickupInventory) and how @ref orxonox::PickupSpawner "PickupSpawners" that spawn the pickup type look like.
     55        The PickupRepresentation class represents a specific pickup type. It defines the information displayed in the GUI (PickupInventory) and how @ref orxonox::PickupSpawner "PickupSpawners" that spawn the pickup type look like.
    5756        They are created through XML and are registered with the @ref orxonox::PickupManager "PickupManager".
    5857
     
    6463            spawnerTemplate = "awesomePickupRepresentation"
    6564            inventoryRepresentation = "AwesomePickup"
    66         >
    67             <pickup>
    68                 <SomePickup />
    69             </pickup>
    70         </PickupRepresentation>
     65        />
    7166        @endcode
    7267        As you might have noticed, there is a parameter called <em>spawnerTemplate</em> and also another parameter called <em>inventoryRepresentation</em>. Let's first explain the second one, <em>inventoryRepresentation</em>.
     
    133128            */
    134129            inline const std::string& getInventoryRepresentation(void) const { return this->inventoryRepresentation_; } // tolua_export
    135             /**
    136             @brief Get the Pickupable represented by this PickupRepresentation.
    137             @param index The index.
    138             @return Returns (for index = 0) a pointer to the Pickupable. For index > 0 it returns NULL.
    139             */
    140             inline const Pickupable* getPickup(unsigned int index) const
    141                 { if(index == 0) return this->pickup_; return NULL; }
    142130
    143             StaticEntity* getSpawnerRepresentation(PickupSpawner* spawner); //!< Get a spawnerRepresentation for a specific PickupSpawner.
     131            virtual void changedName();
     132
     133            StaticEntity* createSpawnerRepresentation(PickupSpawner* spawner); //!< Create a spawnerRepresentation for a specific PickupSpawner.
    144134
    145135        protected:
     
    168158            @param representation A pointer to the StaticEntity that is the spawnerRepresentation of this PickupRepresentation.
    169159            */
    170             inline void setSpawnerRepresentation(StaticEntity* representation)
    171                 { this->spawnerRepresentation_ = representation; }
     160            void setSpawnerRepresentation(StaticEntity* representation);
     161
    172162            /**
    173163            @brief Set the image representing the pickup in the PickupInventory.
     
    176166            inline void setInventoryRepresentation(const std::string& image)
    177167                { this->inventoryRepresentation_ = image; }
    178             /**
    179             @brief Set the Pickupable that is represented by this PickupRepresentation.
    180             @param pickup A pointer to the Pickupable.
    181             */
    182             inline void setPickup(Pickupable* pickup)
    183                 { this->pickup_ = pickup; }
    184168
    185169        private:
     
    195179            std::string inventoryRepresentation_; //!< The name of an image representing the pickup in the PickupInventory.
    196180
    197             Pickupable* pickup_; //!< The Pickupable that is represented by this PickupRepresentation.
    198 
    199181    }; // tolua_export
    200182
  • code/trunk/src/modules/pickup/PickupSpawner.cc

    r8891 r9348  
    5555        Pointer to the object which created this item.
    5656    */
    57     PickupSpawner::PickupSpawner(BaseObject* creator) : StaticEntity(creator), pickup_(NULL)
     57    PickupSpawner::PickupSpawner(BaseObject* creator) : StaticEntity(creator), pickup_(NULL), representation_(NULL), pickupTemplate_(NULL)
    5858    {
    5959        RegisterObject(PickupSpawner);
    6060
    6161        this->initialize();
    62     }
    63 
    64     /**
    65     @brief
    66         Constructor, Creates a fully functional PickupSpawner.
    67     @param creator
    68         The creator of this PickupSpawner.
    69     @param pickup
    70         The Pickupable to be spawned by this PickupSpawner.
    71     @param triggerDistance
    72         The distance at which the PickupSpawner will trigger.
    73     @param respawnTime
    74         The minimum time between two spawns.
    75     @param maxSpawnedItems
    76         The maximum number of items spawned by this PickupSpawner.
    77     */
    78     PickupSpawner::PickupSpawner(BaseObject* creator, Pickupable* pickup, float triggerDistance, float respawnTime, int maxSpawnedItems) : StaticEntity(creator), pickup_(NULL)
    79     {
    80         RegisterObject(PickupSpawner);
    81 
    82         this->initialize();
    83 
    84         this->pickup_ = pickup;
    85 
    86         this->triggerDistance_ = triggerDistance;
    87         this->respawnTime_ = respawnTime;
    88         this->setMaxSpawnedItems(maxSpawnedItems);
    89 
    90         if(this->pickup_ == NULL)
    91         {
    92             orxout(internal_warning, context::pickups) << "A PickupSpawner was created without a valid Pickupable. This won't work." << endl;
    93             this->setActive(false);
    94         }
    95         else
    96         {
    97             PickupRepresentation* representation = PickupManager::getInstance().getRepresentation(this->pickup_->getPickupIdentifier());
    98             this->attach(representation->getSpawnerRepresentation(this));
    99             this->setActive(true);
    100         }
    10162    }
    10263
     
    11273        this->spawnsRemaining_ = INF;
    11374        this->selfDestruct_ = false;
     75
     76        this->setPickupable(NULL);
    11477    }
    11578
     
    12285        if(this->isInitialized() && this->selfDestruct_ && this->pickup_ != NULL)
    12386            this->pickup_->destroy();
     87    }
     88
     89    /**
     90    @brief
     91        Factory method, Creates a fully functional PickupSpawner.
     92    @param creator
     93        The creator of this PickupSpawner.
     94    @param pickup
     95        The Pickupable to be spawned by this PickupSpawner.
     96    @param carrier
     97        The PickupCarrier that carried the input pickup before it was dropped.
     98    @param triggerDistance
     99        The distance at which the PickupSpawner will trigger.
     100    */
     101    /*static*/ PickupSpawner* PickupSpawner::createDroppedPickup(BaseObject* creator, Pickupable* pickup, PickupCarrier* carrier, float triggerDistance)
     102    {
     103        PickupSpawner* spawner = new PickupSpawner(creator);
     104
     105        spawner->setPickupable(pickup);
     106        spawner->setTriggerDistance(triggerDistance);
     107        spawner->setMaxSpawnedItems(1);
     108
     109        spawner->setPosition(carrier->getCarrierPosition());
     110        spawner->block(carrier);
     111
     112        return spawner;
    124113    }
    125114
     
    136125        SUPER(PickupSpawner, XMLPort, xmlelement, mode);
    137126
    138         XMLPortObject(PickupSpawner, Pickupable, "pickup", setPickupable, getPickupable, xmlelement, mode);
    139 
     127        XMLPortParam(PickupSpawner, "pickup", setPickupTemplateName, getPickupTemplateName, xmlelement, mode);
    140128        XMLPortParam(PickupSpawner, "triggerDistance", setTriggerDistance, getTriggerDistance, xmlelement, mode);
    141129        XMLPortParam(PickupSpawner, "respawnTime", setRespawnTime, getRespawnTime, xmlelement, mode);
    142130        XMLPortParam(PickupSpawner, "maxSpawnedItems", setMaxSpawnedItems, getMaxSpawnedItems, xmlelement, mode);
    143 
    144         if(this->pickup_ == NULL)
    145         {
    146             orxout(internal_warning, context::pickups) << "A PickupSpawner was created without a valid Pickupable. This won't work." << endl;
    147             this->setActive(false);
    148         }
    149         else
    150         {
    151             PickupRepresentation* representation = PickupManager::getInstance().getRepresentation(this->pickup_->getPickupIdentifier());
    152             this->attach(representation->getSpawnerRepresentation(this));
    153             this->setActive(true);
    154         }
    155     }
    156 
    157     /**
    158     @brief
    159         Invoked when the activity has changed. Sets visibility of attached objects.
    160     */
    161     void PickupSpawner::changedActivity()
    162     {
    163         SUPER(PickupSpawner, changedActivity);
    164 
    165         if(GameMode::isMaster())
    166             this->setVisible(this->isActive());
    167131    }
    168132
     
    199163
    200164                Vector3 distance = it->getWorldPosition() - this->getWorldPosition();
    201                 PickupCarrier* carrier = dynamic_cast<PickupCarrier*>(*it);
     165                PickupCarrier* carrier = static_cast<PickupCarrier*>(*it);
    202166                // If a PickupCarrier, that fits the target-range of the Pickupable spawned by this PickupSpawner, is in trigger-distance and the carrier is not blocked.
    203167                if(distance.length() < this->triggerDistance_ && carrier != NULL && this->blocked_.find(carrier) == this->blocked_.end())
     
    212176    /**
    213177    @brief
     178        Trigger the PickupSpawner.
     179        Adds the pickup to the Pawn that triggered, sets the timer to re-activate and deactives the PickupSpawner.
     180    @param carrier
     181        Carrier which triggered the PickupSpawner.
     182    */
     183    void PickupSpawner::trigger(PickupCarrier* carrier)
     184    {
     185        orxout(verbose, context::pickups) << "PickupSpawner (&" << this << ") triggered and active." << endl;
     186
     187        PickupCarrier* target = carrier->getTarget(this->pickup_);
     188
     189        this->block(carrier);
     190
     191        assert(target);
     192        bool pickedUp = this->pickup_->pickup(target);
     193        assert(pickedUp);
     194        pickedUp = false; // To avoid compiler warning.
     195
     196        this->setPickupable(NULL);
     197        this->decrementSpawnsRemaining();
     198    }
     199
     200    void PickupSpawner::setPickupTemplateName(const std::string& name)
     201    {
     202        Template* temp = Template::getTemplate(name);
     203        if (temp)
     204            this->setPickupTemplate(temp);
     205    }
     206
     207    void PickupSpawner::setPickupTemplate(Template* temp)
     208    {
     209        this->pickupTemplate_ = temp;
     210        this->pickupTemplateName_ = temp->getName();
     211
     212        this->setPickupable(this->createPickup());
     213    }
     214
     215    /**
     216    @brief
    214217        Sets the maximum number of spawned items.
    215218    @param items
     
    233236            this->spawnsRemaining_--;
    234237
     238        this->setActive(false);
     239
    235240        if(this->spawnsRemaining_ != 0 && this->respawnTime_ > 0)
    236241        {
    237242            this->startRespawnTimer();
    238 
    239             this->setActive(false);
    240243            this->fireEvent();
    241244        }
     
    243246        {
    244247            orxout(verbose, context::pickups) << "PickupSpawner (&" << this << ") empty, selfdestruct initialized." << endl;
    245             this->setActive(false);
    246248            this->destroy();
    247249        }
     
    255257    {
    256258        this->respawnTimer_.setTimer(this->respawnTime_, false, createExecutor(createFunctor(&PickupSpawner::respawnTimerCallback, this)));
     259    }
     260
     261    /**
     262    @brief
     263        Invoked by the timer, re-activates the PickupSpawner.
     264    */
     265    void PickupSpawner::respawnTimerCallback()
     266    {
     267        orxout(verbose, context::pickups) << "PickupSpawner (&" << this << ") reactivated." << endl;
     268
     269        this->setPickupable(this->createPickup());
     270    }
     271
     272    /**
     273    @brief
     274        Creates a new Pickupable.
     275    @return
     276        The Pickupable created.
     277    */
     278    Pickupable* PickupSpawner::createPickup(void)
     279    {
     280        if(this->spawnsRemaining_ == 0)
     281        {
     282            orxout(internal_error, context::pickups) << "Massive Error: PickupSpawner still alive until having spawned last item." << endl;
     283            return NULL;
     284        }
     285
     286        if (this->pickupTemplate_ != NULL)
     287        {
     288            Identifier* identifier = this->pickupTemplate_->getBaseclassIdentifier();
     289            if (identifier != NULL)
     290            {
     291                Pickupable* pickup = orxonox_cast<Pickupable*>(identifier->fabricate(this));
     292                orxonox_cast<BaseObject*>(pickup)->addTemplate(this->pickupTemplate_);
     293                return pickup;
     294            }
     295            else
     296                orxout(internal_error, context::pickups) << "No base class defined in pickup-template " << this->pickupTemplateName_ << endl;
     297        }
     298
     299        return NULL;
    257300    }
    258301
     
    265308    void PickupSpawner::setPickupable(Pickupable* pickup)
    266309    {
    267         if(this->pickup_ != NULL)
    268         {
    269             orxout(internal_error, context::pickups) << "In PickupSpawner (&" << this << "): setPickupable called, with this->pickup_ already set." << endl;
    270             return;
    271         }
    272         if(pickup == NULL)
    273         {
    274             orxout(internal_error, context::pickups) << "In PickupSpawner (&" << this << "): Argument of setPickupable is NULL." << endl;
    275             return;
     310        if (this->representation_ != NULL)
     311        {
     312            this->representation_->destroy();
     313            this->representation_ = NULL;
     314        }
     315
     316        if (pickup != NULL)
     317        {
     318            if (this->pickup_ != NULL)
     319                this->pickup_->destroy();
     320
     321            PickupRepresentation* representation = PickupManager::getInstance().getRepresentation(pickup->getRepresentationName());
     322            this->representation_ = representation->createSpawnerRepresentation(this);
     323            this->attach(this->representation_);
     324            this->setActive(true);
     325        }
     326        else
     327        {
     328            this->setActive(false);
    276329        }
    277330
    278331        this->pickup_ = pickup;
    279332    }
    280 
    281     /**
    282     @brief
    283         Get the Pickupable that is spawned by this PickupSpawner.
    284     @return
    285         Returns the Pickupable that is spawned by this PickupSpawner.
    286     */
    287     const Pickupable* PickupSpawner::getPickupable(void) const
    288     {
    289         return this->pickup_;
    290     }
    291 
    292     /**
    293     @brief
    294         Trigger the PickupSpawner.
    295         Adds the pickup to the Pawn that triggered, sets the timer to re-activate and deactives the PickupSpawner.
    296     @param pawn
    297         Pawn which triggered the PickupSpawner.
    298     */
    299     void PickupSpawner::trigger(Pawn* pawn)
    300     {
    301         if(this->isActive()) // Checks whether PickupSpawner is active.
    302         {
    303             orxout(verbose, context::pickups) << "PickupSpawner (&" << this << ") triggered and active." << endl;
    304 
    305             PickupCarrier* carrier = dynamic_cast<PickupCarrier*>(pawn);
    306             assert(carrier);
    307 
    308             // If the Pawn isn't a target of the Pickupable.
    309             if(!carrier->isTarget(this->pickup_))
    310             {
    311                 orxout(verbose, context::pickups) << "PickupSpawner (&" << this << ") triggered but Pawn wasn't a target of the Pickupable." << endl;
    312                 return;
    313             }
    314 
    315             PickupCarrier* target = carrier->getTarget(this->pickup_);
    316             Pickupable* pickup = this->getPickup();
    317 
    318             this->block(carrier);
    319 
    320             assert(pickup);
    321             assert(target);
    322             bool pickedUp = pickup->pickup(target);
    323             assert(pickedUp);
    324             pickedUp = false; // To avoid compiler warning.
    325 
    326             this->decrementSpawnsRemaining();
    327         }
    328     }
    329 
    330     /**
    331     @brief
    332         Creates a new Pickupable.
    333     @return
    334         The Pickupable created.
    335     */
    336     Pickupable* PickupSpawner::getPickup(void)
    337     {
    338         if(this->spawnsRemaining_ == 0)
    339         {
    340             orxout(internal_error, context::pickups) << "Massive Error: PickupSpawner still alive until having spawned last item." << endl;
    341             return NULL;
    342         }
    343 
    344         Pickupable* pickup = this->pickup_->clone();
    345         return pickup;
    346     }
    347 
    348     /**
    349     @brief
    350         Invoked by the timer, re-activates the PickupSpawner.
    351     */
    352     void PickupSpawner::respawnTimerCallback()
    353     {
    354         orxout(verbose, context::pickups) << "PickupSpawner (&" << this << ") reactivated." << endl;
    355 
    356         this->setActive(true);
    357     }
    358333}
  • code/trunk/src/modules/pickup/PickupSpawner.h

    r7549 r9348  
    7878        public:
    7979            PickupSpawner(BaseObject* creator); //!< Default Constructor.
    80             PickupSpawner(BaseObject* creator, Pickupable* pickup, float triggerDistance, float respawnTime, int maxSpawnedItems); //!< Constructor.
    8180            virtual ~PickupSpawner(); //!< Destructor.
    8281
     82            static PickupSpawner* createDroppedPickup(BaseObject* creator, Pickupable* pickup, PickupCarrier* carrier, float triggerDistance = 10.0);
     83
    8384            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);  //!< Method for creating a PickupSpawner through XML.
    84             virtual void changedActivity(); //!< Invoked when activity has changed (set visibilty).
    8585            virtual void tick(float dt); //!< Tick, checks if any Pawn is close enough to trigger.
    8686
     
    103103            inline int getMaxSpawnedItems(void) const
    104104                { return this->maxSpawnedItems_; }
     105            /**
     106            @brief Returns the name of the template which is used to create a pickup for this spawner.
     107            */
     108            inline const std::string& getPickupTemplateName() const
     109                { return this->pickupTemplateName_; }
     110            /**
     111            @brief Returns the template which is used to create a pickup for this spawner.
     112            */
     113            inline Template* getPickupTemplate() const
     114                {return this->pickupTemplate_; }
    105115
    106         protected:
     116        private:
     117            void initialize(void);
     118
     119            void trigger(PickupCarrier* carrier); //!< Method called when a carrier is close enough.
     120            void respawnTimerCallback(); //!< Method called when the timer runs out.
     121
    107122            void decrementSpawnsRemaining(void); //!< Decrements the number of remaining spawns.
    108123            void startRespawnTimer(void); //!< Invoked by the timer, re-activates the PickupSpawner.
     
    128143            inline void setRespawnTime(float time)
    129144                { this->respawnTime_ = time; }
     145
    130146            void setMaxSpawnedItems(int items); //!< Sets the maximum number of spawned items.
    131147
    132             virtual Pickupable* getPickup(void); //!< Creates a new Pickupable.
     148            void setPickupTemplateName(const std::string& name);
     149            void setPickupTemplate(Template* temp);
    133150
     151            Pickupable* createPickup(void); //!< Creates a new Pickupable.
    134152            void setPickupable(Pickupable* pickup); //!< Sets a Pickupable for the PickupSpawner to spawn.
    135             const Pickupable* getPickupable(void) const; //!< Get the Pickupable that is spawned by this PickupSpawner.
    136153
    137154            Pickupable* pickup_; //!< The pickup to be spawned.
    138 
    139         private:
    140             void initialize(void);
    141 
    142             void trigger(Pawn* pawn); //!< Method called when a Pawn is close enough.
    143             void respawnTimerCallback(); //!< Method called when the timer runs out.
     155            StaticEntity* representation_; //!< The active representation of the spawner.
     156            std::string pickupTemplateName_; //!< The name of the pickup template.
     157            Template* pickupTemplate_; //!< The template to be used to create a pickupable.
    144158
    145159            int maxSpawnedItems_; //!< Maximum number of items spawned by this PickupSpawner.
  • code/trunk/src/modules/pickup/items/CMakeLists.txt

    r8706 r9348  
    77  ShieldPickup.cc
    88  ShrinkPickup.cc
     9  DamageBoostPickup.cc
    910)
  • code/trunk/src/modules/pickup/items/DronePickup.cc

    r8858 r9348  
    3939
    4040#include "controllers/DroneController.h"
    41 #include "pickup/PickupIdentifier.h"
    4241#include "worldentities/Drone.h"
    4342#include "worldentities/pawns/Pawn.h"
     
    7574    {
    7675        this->addTarget(ClassIdentifier<Pawn>::getIdentifier());
    77         this->setDurationTypeDirect(pickupDurationType::once);
     76        this->setDurationType(pickupDurationType::once);
    7877        this->droneTemplate_ = "";
    79     }
    80 
    81     /**
    82     @brief
    83         Initializes the PickupIdentifier of this pickup.
    84     */
    85     void DronePickup::initializeIdentifier(void)
    86     {
    87         std::string val = this->getDroneTemplate();
    88         std::string type = "droneTemplate";
    89         this->pickupIdentifier_->addParameter(type, val);
    9078    }
    9179
     
    9886        SUPER(DronePickup, XMLPort, xmlelement, mode);
    9987        XMLPortParam(DronePickup, "droneTemplate", setDroneTemplate, getDroneTemplate, xmlelement, mode);
    100 
    101         this->initializeIdentifier();
    10288    }
    10389
     
    10894        The name of the Template to e set.
    10995    */
    110     void DronePickup::setDroneTemplate(std::string templatename){
     96    void DronePickup::setDroneTemplate(const std::string& templatename){
    11197        droneTemplate_ = templatename;
    11298    }
     
    144130
    145131                Controller* controller = drone->getController();
    146                 DroneController* droneController = dynamic_cast<DroneController*>(controller);
     132                DroneController* droneController = orxonox_cast<DroneController*>(controller);
    147133                if(droneController != NULL)
    148134                {
     
    175161    {
    176162        PickupCarrier* carrier = this->getCarrier();
    177         Pawn* pawn = dynamic_cast<Pawn*>(carrier);
     163        Pawn* pawn = orxonox_cast<Pawn*>(carrier);
    178164
    179165        if(pawn == NULL)
     
    184170        return pawn;
    185171    }
    186 
    187     /**
    188     @brief
    189         Creates a duplicate of the input OrxonoxClass.
    190     @param item
    191         A pointer to the Orxonox class.
    192     */
    193     void DronePickup::clone(OrxonoxClass*& item)
    194     {
    195         if(item == NULL)
    196             item = new DronePickup(this);
    197 
    198         SUPER(DronePickup, clone, item);
    199 
    200         DronePickup* pickup = dynamic_cast<DronePickup*>(item);
    201         pickup->setDroneTemplate(this->getDroneTemplate());
    202 
    203         pickup->initializeIdentifier();
    204     }
    205172}
  • code/trunk/src/modules/pickup/items/DronePickup.h

    r7547 r9348  
    7070
    7171            virtual void changedUsed(void); //!< Is called when the pickup has transited from used to unused or the other way around.
    72             virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input OrxonoxClass.
    7372
    7473            const std::string& getDroneTemplate() const; //!< Get the name of the droneTemplate.
    7574
    7675        protected:
    77             void initializeIdentifier(void); //!< Initializes the PickupIdentifier of this pickup.
    78 
    79             void setDroneTemplate(std::string templatename); //!< Set the droneTemplate.
     76            void setDroneTemplate(const std::string& templatename); //!< Set the droneTemplate.
    8077
    8178        private:
  • code/trunk/src/modules/pickup/items/HealthPickup.cc

    r8864 r9348  
    3838#include "core/XMLPort.h"
    3939
    40 #include "pickup/PickupIdentifier.h"
    4140#include "worldentities/pawns/Pawn.h"
    4241
     
    8786    /**
    8887    @brief
    89         Initializes the PickupIdentifier of this pickup.
    90     */
    91     void HealthPickup::initializeIdentifier(void)
    92     {
    93         std::stringstream stream;
    94         stream << this->getHealth();
    95         std::string type1 = "health";
    96         std::string val1 = stream.str();
    97         this->pickupIdentifier_->addParameter(type1, val1);
    98 
    99         std::string val2 = this->getHealthType();
    100         std::string type2 = "healthType";
    101         this->pickupIdentifier_->addParameter(type2, val2);
    102 
    103         stream.clear();
    104         stream << this->getHealthRate();
    105         std::string val3 = stream.str();
    106         std::string type3 = "healthRate";
    107         this->pickupIdentifier_->addParameter(type3, val3);
    108     }
    109 
    110     /**
    111     @brief
    11288        Method for creating a HealthPickup object through XML.
    11389    */
     
    11894        XMLPortParam(HealthPickup, "health", setHealth, getHealth, xmlelement, mode);
    11995        XMLPortParam(HealthPickup, "healthRate", setHealthRate, getHealthRate, xmlelement, mode);
    120         XMLPortParam(HealthPickup, "healthType", setHealthType, getHealthType, xmlelement, mode);
     96        XMLPortParam(HealthPickup, "healthType", setHealthTypeAsString, getHealthTypeAsString, xmlelement, mode);
    12197
    12298        if(!this->isContinuous())
    123             this->healthRate_ = 0.0f;
    124 
    125         this->initializeIdentifier();
     99            this->setHealthRate(0.0f); // TODO: this logic should be inside tick(), not in XMLPort
    126100    }
    127101
     
    151125            this->setHealth(this->getHealth()-health);
    152126
    153             switch(this->getHealthTypeDirect())
     127            switch(this->getHealthType())
    154128            {
    155129                case pickupHealthType::permanent:
     
    198172
    199173                float health = 0.0f;
    200                 switch(this->getHealthTypeDirect())
     174                switch(this->getHealthType())
    201175                {
    202176                    case pickupHealthType::permanent:
     
    227201        else
    228202        {
    229             if(this->getHealthTypeDirect() == pickupHealthType::temporary)
     203            if(this->getHealthType() == pickupHealthType::temporary)
    230204            {
    231205                PickupCarrier* carrier = this->getCarrier();
    232                 Pawn* pawn = dynamic_cast<Pawn*>(carrier);
     206                Pawn* pawn = orxonox_cast<Pawn*>(carrier);
    233207
    234208                if(pawn == NULL)
     
    264238    {
    265239        PickupCarrier* carrier = this->getCarrier();
    266         Pawn* pawn = dynamic_cast<Pawn*>(carrier);
     240        Pawn* pawn = orxonox_cast<Pawn*>(carrier);
    267241
    268242        if(pawn == NULL)
     
    270244
    271245        return pawn;
    272     }
    273 
    274     /**
    275     @brief
    276         Creates a duplicate of the input OrxonoxClass.
    277     @param item
    278         A pointer to the Orxonox class.
    279     */
    280     void HealthPickup::clone(OrxonoxClass*& item)
    281     {
    282         if(item == NULL)
    283             item = new HealthPickup(this);
    284 
    285         SUPER(HealthPickup, clone, item);
    286 
    287         HealthPickup* pickup = dynamic_cast<HealthPickup*>(item);
    288         pickup->setHealth(this->getHealth());
    289         pickup->setHealthRate(this->getHealthRate());
    290         pickup->setHealthTypeDirect(this->getHealthTypeDirect());
    291 
    292         pickup->initializeIdentifier();
    293246    }
    294247
     
    299252        Returns the health type as a string.
    300253    */
    301     const std::string& HealthPickup::getHealthType(void) const
    302     {
    303         switch(this->getHealthTypeDirect())
     254    const std::string& HealthPickup::getHealthTypeAsString(void) const
     255    {
     256        switch(this->getHealthType())
    304257        {
    305258            case pickupHealthType::limited:
     
    352305        The type as a string.
    353306    */
    354     void HealthPickup::setHealthType(std::string type)
     307    void HealthPickup::setHealthTypeAsString(const std::string& type)
    355308    {
    356309        if(type == HealthPickup::healthTypeLimited_s)
    357             this->setHealthTypeDirect(pickupHealthType::limited);
     310            this->setHealthType(pickupHealthType::limited);
    358311        else if(type == HealthPickup::healthTypeTemporary_s)
    359             this->setHealthTypeDirect(pickupHealthType::temporary);
     312            this->setHealthType(pickupHealthType::temporary);
    360313        else if(type == HealthPickup::healthTypePermanent_s)
    361             this->setHealthTypeDirect(pickupHealthType::permanent);
     314            this->setHealthType(pickupHealthType::permanent);
    362315        else
    363316            orxout(internal_error, context::pickups) << "Invalid healthType '" << type << "' in HealthPickup." << endl;
  • code/trunk/src/modules/pickup/items/HealthPickup.h

    r7551 r9348  
    9797
    9898            virtual void changedUsed(void); //!< Is called when the pickup has transited from used to unused or the other way around.
    99             virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input OrxonoxClass.
    10099
    101100            /**
     
    116115            @return Returns the health type as an enum.
    117116            */
    118             inline pickupHealthType::Value getHealthTypeDirect(void) const
     117            inline pickupHealthType::Value getHealthType(void) const
    119118                { return this->healthType_; }
    120             const std::string& getHealthType(void) const; //!< Get the health type of this pickup.
     119            const std::string& getHealthTypeAsString(void) const; //!< Get the health type of this pickup.
    121120
    122121        protected:
    123             void initializeIdentifier(void); //!< Initializes the PickupIdentifier of this pickup.
    124 
    125122            void setHealth(float health); //!< Sets the health.
    126123            void setHealthRate(float speed); //!< Set the rate at which health is transferred if the pickup is continuous.
     
    130127            @param type The type of this pickup as an enum.
    131128            */
    132             inline void setHealthTypeDirect(pickupHealthType::Value type)
     129            inline void setHealthType(pickupHealthType::Value type)
    133130                { this->healthType_ = type; }
    134             void setHealthType(std::string type); //!< Set the type of the HealthPickup.
     131            void setHealthTypeAsString(const std::string& type); //!< Set the type of the HealthPickup.
    135132
    136133        private:
  • code/trunk/src/modules/pickup/items/InvisiblePickup.cc

    r8858 r9348  
    4040#include "core/XMLPort.h"
    4141
    42 #include "pickup/PickupIdentifier.h"
    4342#include "worldentities/pawns/Pawn.h"
    4443
     
    7978    /**
    8079    @brief
    81         Initializes the PickupIdentifier of this pickup.
    82     */
    83     void InvisiblePickup::initializeIdentifier(void)
    84     {
    85         std::stringstream stream;
    86         stream << this->getDuration();
    87         std::string type1 = "duration";
    88         std::string val1 = stream.str();
    89         this->pickupIdentifier_->addParameter(type1, val1);
    90     }
    91 
    92     /**
    93     @brief
    9480        Method for creating a HealthPickup object through XML.
    9581    */
     
    9884        SUPER(InvisiblePickup, XMLPort, xmlelement, mode);
    9985        XMLPortParam(InvisiblePickup, "duration", setDuration, getDuration, xmlelement, mode);
    100 
    101         this->initializeIdentifier();
    10286    }
    10387
     
    148132    /**
    149133    @brief
    150         Creates a duplicate of the input OrxonoxClass.
    151     @param item
    152         A pointer to the Orxonox class.
    153     */
    154     void InvisiblePickup::clone(OrxonoxClass*& item)
    155     {
    156         if(item == NULL)
    157             item = new InvisiblePickup(this);
    158 
    159         SUPER(InvisiblePickup, clone, item);
    160 
    161         InvisiblePickup* pickup = dynamic_cast<InvisiblePickup*>(item);
    162         pickup->setDuration(this->getDuration());
    163         pickup->initializeIdentifier();
    164     }
    165 
    166     /**
    167     @brief
    168134        Sets the invisibility.
    169135    @param invisibility
     
    202168    {
    203169        PickupCarrier* carrier = this->getCarrier();
    204         Pawn* pawn = dynamic_cast<Pawn*>(carrier);
     170        Pawn* pawn = orxonox_cast<Pawn*>(carrier);
    205171
    206172        if(pawn == NULL)
  • code/trunk/src/modules/pickup/items/InvisiblePickup.h

    r7547 r9348  
    7272            InvisiblePickup(BaseObject* creator); //!< Constructor.
    7373            virtual ~InvisiblePickup(); //!< Destructor.
    74            
     74
    7575            virtual void XMLPort(Element& xmlelement, orxonox::XMLPort::Mode mode); //!< Method for creating a HealthPickup object through XML.
    7676            virtual void changedUsed(void); //!< Is called when the pickup has transited from used to unused or the other way around.
    77             virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input OrxonoxClass.
    7877
    7978            /**
     
    9190
    9291        protected:
    93             void initializeIdentifier(void); //!< Initializes the PickupIdentifier of this pickup.
    94 
    9592            bool setInvisible(bool invisibility); //!< Set the Pawn to be invisible or visible again.
    9693            void setDuration(float duration); //!< Sets the time the InvisibilityPickup will last.
  • code/trunk/src/modules/pickup/items/MetaPickup.cc

    r8858 r9348  
    3636
    3737#include "interfaces/PickupCarrier.h"
    38 #include "pickup/PickupIdentifier.h"
    3938#include "worldentities/pawns/Pawn.h"
    4039
     
    8079        this->addTarget(ClassIdentifier<PickupCarrier>::getIdentifier());
    8180
    82         this->setDurationTypeDirect(pickupDurationType::once);
     81        this->setDurationType(pickupDurationType::once);
    8382        this->metaType_ = pickupMetaType::none;
    8483    }
     
    8685    /**
    8786    @brief
    88         Helper method to initialize the PickupIdentifier.
    89     */
    90     void MetaPickup::initializeIdentifier(void)
    91     {
    92         std::string val = this->getMetaType();
    93         std::string type = "metaType";
    94         this->pickupIdentifier_->addParameter(type, val);
    95     }
    96 
    97     /**
    98     @brief
    9987        Method for creating a MetaPickup object through XML.
    10088    */
     
    10391        SUPER(MetaPickup, XMLPort, xmlelement, mode);
    10492
    105         XMLPortParam(MetaPickup, "metaType", setMetaType, getMetaType, xmlelement, mode);
    106 
    107         this->initializeIdentifier();
     93        XMLPortParam(MetaPickup, "metaType", setMetaTypeAsString, getMetaTypeAsString, xmlelement, mode);
    10894    }
    10995
     
    121107        {
    122108            PickupCarrier* carrier = this->getCarrier();
    123             if(this->getMetaTypeDirect() != pickupMetaType::none && carrier != NULL)
     109            if(this->getMetaType() != pickupMetaType::none && carrier != NULL)
    124110            {
    125111                // If the metaType is destroyCarrier, then the PickupCarrier is destroyed.
    126                 if(this->getMetaTypeDirect() == pickupMetaType::destroyCarrier)
     112                if(this->getMetaType() == pickupMetaType::destroyCarrier)
    127113                {
    128114                    Pawn* pawn = orxonox_cast<Pawn*>(carrier);
     
    139125
    140126                    // If the metaType is use, then the Pickupable is set to used.
    141                     if(this->getMetaTypeDirect() == pickupMetaType::use && !pickup->isUsed())
     127                    if(this->getMetaType() == pickupMetaType::use && !pickup->isUsed())
    142128                    {
    143129                        pickup->setUsed(true);
    144130                    }
    145131                    // If the metaType is drop, then the Pickupable is dropped.
    146                     else if(this->getMetaTypeDirect() == pickupMetaType::drop)
     132                    else if(this->getMetaType() == pickupMetaType::drop)
    147133                    {
    148134                        pickup->drop();
    149135                    }
    150136                    // If the metaType is destroy, then the Pickupable is destroyed.
    151                     else if(this->getMetaTypeDirect() == pickupMetaType::destroy)
     137                    else if(this->getMetaType() == pickupMetaType::destroy)
    152138                    {
    153139                        pickup->Pickupable::destroy();
     
    161147    /**
    162148    @brief
    163         Creates a duplicate of the input OrxonoxClass.
    164     @param item
    165         A pointer to the Orxonox class.
    166     */
    167     void MetaPickup::clone(OrxonoxClass*& item)
    168     {
    169         if(item == NULL)
    170             item = new MetaPickup(this);
    171 
    172         SUPER(MetaPickup, clone, item);
    173 
    174         MetaPickup* pickup = dynamic_cast<MetaPickup*>(item);
    175         pickup->setMetaTypeDirect(this->getMetaTypeDirect());
    176 
    177         pickup->initializeIdentifier();
    178     }
    179 
    180     /**
    181     @brief
    182149        Get the meta type of this MetaPickup.
    183150    @return
    184151        Returns a string with the meta type of the MetaPickup.
    185152    */
    186     const std::string& MetaPickup::getMetaType(void) const
    187     {
    188         switch(this->getMetaTypeDirect())
     153    const std::string& MetaPickup::getMetaTypeAsString(void) const
     154    {
     155        switch(this->getMetaType())
    189156        {
    190157            case pickupMetaType::none:
     
    209176        A string with the type to be set.
    210177    */
    211     void MetaPickup::setMetaType(const std::string& type)
     178    void MetaPickup::setMetaTypeAsString(const std::string& type)
    212179    {
    213180        if(type == MetaPickup::metaTypeNone_s)
    214181        {
    215             this->setMetaTypeDirect(pickupMetaType::none);
     182            this->setMetaType(pickupMetaType::none);
    216183        }
    217184        else if(type == MetaPickup::metaTypeUse_s)
    218185        {
    219             this->setMetaTypeDirect(pickupMetaType::use);
     186            this->setMetaType(pickupMetaType::use);
    220187        }
    221188        else if(type == MetaPickup::metaTypeDrop_s)
    222189        {
    223             this->setMetaTypeDirect(pickupMetaType::drop);
     190            this->setMetaType(pickupMetaType::drop);
    224191        }
    225192        else if(type == MetaPickup::metaTypeDestroy_s)
    226193        {
    227             this->setMetaTypeDirect(pickupMetaType::destroy);
     194            this->setMetaType(pickupMetaType::destroy);
    228195        }
    229196        else if(type == MetaPickup::metaTypeDestroyCarrier_s)
    230197        {
    231             this->setMetaTypeDirect(pickupMetaType::destroyCarrier);
     198            this->setMetaType(pickupMetaType::destroyCarrier);
    232199        }
    233200        else
  • code/trunk/src/modules/pickup/items/MetaPickup.h

    r7547 r9348  
    6969
    7070        The default value is <em>none</em>, which basically does nothing.
    71        
     71
    7272        The parameter <b>activation type</b> can be used to specify, whether the MetaPickup is used upon pickup (<em>immediate</em>) or not (<em>onUse</em>). With <em>immediate</em> being the default.
    7373
     
    9595
    9696            virtual void changedUsed(void); //!< Is called when the pickup has transited from used to unused or the other way around.
    97             virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input OrxonoxClass.
    9897
    9998            /**
     
    101100            @return Returns an enum with the meta type of the MetaPickup.
    102101            */
    103             inline pickupMetaType::Value getMetaTypeDirect(void) const
     102            inline pickupMetaType::Value getMetaType(void) const
    104103                { return this->metaType_; }
    105             const std::string& getMetaType(void) const; //!< Get the meta type of this MetaPickup.
     104            const std::string& getMetaTypeAsString(void) const; //!< Get the meta type of this MetaPickup.
    106105
    107106        protected:
    108             void initializeIdentifier(void); //!< Initializes the PickupIdentifier of this pickup.
    109 
    110107            /**
    111108            @brief Set the meta type of the MetaPickup.
    112109            @param type The meta type as an enum.
    113110            */
    114             inline void setMetaTypeDirect(pickupMetaType::Value type)
     111            inline void setMetaType(pickupMetaType::Value type)
    115112                { this->metaType_ =  type; }
    116             void setMetaType(const std::string& type); //!< Set the meta type of this MetaPickup.
     113            void setMetaTypeAsString(const std::string& type); //!< Set the meta type of this MetaPickup.
    117114
    118115        private:
  • code/trunk/src/modules/pickup/items/ShieldPickup.cc

    r8858 r9348  
    3838#include "core/XMLPort.h"
    3939
    40 #include "pickup/PickupIdentifier.h"
    4140#include "worldentities/pawns/Pawn.h"
    4241
     
    8079    /**
    8180    @brief
    82         Initializes the PickupIdentifier of this pickup.
    83     */
    84     void ShieldPickup::initializeIdentifier(void)
    85     {
    86         std::stringstream stream;
    87         stream << this->getDuration();
    88         std::string type1 = "duration";
    89         std::string val1 = stream.str();
    90         this->pickupIdentifier_->addParameter(type1, val1);
    91 
    92         stream.clear();
    93         stream << this->getShieldHealth();
    94         std::string type2 = "ShieldHealth";
    95         std::string val2 = stream.str();
    96         this->pickupIdentifier_->addParameter(type2, val2);
    97 
    98         stream.clear();
    99         stream << this->getShieldAbsorption();
    100         std::string type3 = "ShieldAbsorption";
    101         std::string val3 = stream.str();
    102         this->pickupIdentifier_->addParameter(type3, val3);
    103 
    104     }
    105 
    106     /**
    107     @brief
    10881        Method for creating a ShieldPickup object through XML.
    10982    */
     
    11588        XMLPortParam(ShieldPickup, "shieldabsorption", setShieldAbsorption, getShieldAbsorption, xmlelement, mode);
    11689        XMLPortParam(ShieldPickup, "duration", setDuration, getDuration, xmlelement, mode);
    117 
    118         this->initializeIdentifier();
    11990    }
    12091
     
    177148    {
    178149        PickupCarrier* carrier = this->getCarrier();
    179         Pawn* pawn = dynamic_cast<Pawn*>(carrier);
     150        Pawn* pawn = orxonox_cast<Pawn*>(carrier);
    180151
    181152        if(pawn == NULL)
     
    184155        }
    185156        return pawn;
    186     }
    187 
    188     /**
    189     @brief
    190         Creates a duplicate of the input OrxonoxClass.
    191     @param item
    192         A pointer to the Orxonox class.
    193     */
    194     void ShieldPickup::clone(OrxonoxClass*& item)
    195     {
    196         if(item == NULL)
    197             item = new ShieldPickup(this);
    198 
    199         SUPER(ShieldPickup, clone, item);
    200 
    201         ShieldPickup* pickup = dynamic_cast<ShieldPickup*>(item);
    202         pickup->setDuration(this->getDuration());
    203         pickup->setShieldAbsorption(this->getShieldAbsorption());
    204         pickup->setShieldHealth(this->getShieldHealth());
    205         pickup->initializeIdentifier();
    206157    }
    207158
  • code/trunk/src/modules/pickup/items/ShieldPickup.h

    r7547 r9348  
    8282
    8383            virtual void changedUsed(void); //!< Is called when the pickup has transited from used to unused or the other way around.
    84             virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input OrxonoxClass.
    8584
    8685            /**
     
    104103
    105104        protected:
    106             void initializeIdentifier(void); //!< Initializes the PickupIdentifier of this pickup.
    107105            void pickupTimerCallback(void); //!< Helper method. Is called by the Timer as soon as it expires.
    108106
  • code/trunk/src/modules/pickup/items/ShrinkPickup.cc

    r8713 r9348  
    4040#include "core/XMLPort.h"
    4141
    42 #include "pickup/PickupIdentifier.h"
    4342#include "worldentities/pawns/Pawn.h"
    4443
     
    8180    }
    8281
    83     void ShrinkPickup::initializeIdentifier(void)
    84     {
    85         std::stringstream stream;
    86         stream << this->getShrinkFactor();
    87         std::string type1 = "shrinkFactor";
    88         std::string val1 = stream.str();
    89         this->pickupIdentifier_->addParameter(type1, val1);
    90 
    91         stream.clear();
    92         stream << this->getDuration();
    93         std::string val2 = stream.str();
    94         std::string type2 = "duration";
    95         this->pickupIdentifier_->addParameter(type2, val2);
    96 
    97         stream.clear();
    98         stream << this->getShrinkDuration();
    99         std::string val3 = stream.str();
    100         std::string type3 = "shrinkDuration";
    101         this->pickupIdentifier_->addParameter(type3, val3);
    102     }
    103 
    10482   /**
    10583    @brief
     
    11391        XMLPortParam(ShrinkPickup, "duration", setDuration, getDuration, xmlelement, mode);
    11492        XMLPortParam(ShrinkPickup, "shrinkDuration", setShrinkDuration, getShrinkDuration, xmlelement, mode);
    115 
    116         this->initializeIdentifier();
     93    }
     94
     95    /**
     96    @brief Sets the shrinking factor.
     97    @param factor The factor, needs to greater than 1.
     98    */
     99    void ShrinkPickup::setShrinkFactor(float factor)
     100    {
     101        if(factor <= 1.0f)
     102        {
     103            orxout(internal_warning, context::pickups) << "Invalid shrinking factor in ShrinkPickup. Ignoring.." << endl;
     104            return;
     105        }
     106        this->shrinkFactor_ = factor;
     107    }
     108
     109    /**
     110    @brief Set the duration for which the ship remains shrunken.
     111    @param duration The duration, needs to be non-negative.
     112    */
     113    void ShrinkPickup::setDuration(float duration)
     114    {
     115        if(duration < 0.0f)
     116        {
     117            orxout(internal_warning, context::pickups) << "Invalid duration in ShrinkPickup. Ignoring.." << endl;
     118            return;
     119        }
     120        this->duration_ = duration;
     121    }
     122
     123    /**
     124    @brief Set the shrink duration.
     125    @param speed The shrink duration, needs to be positive.
     126    */
     127    void ShrinkPickup::setShrinkDuration(float speed)
     128    {
     129        if(speed <= 0.0f)
     130        {
     131            orxout(internal_warning, context::pickups) << "Invalid shrink duration in ShrinkPickup. Ignoring.." << endl;
     132            return;
     133        }
     134        this->shrinkDuration_ = speed;
    117135    }
    118136
     
    148166    {
    149167        SUPER(ShrinkPickup, changedPickedUp);
    150        
     168
    151169        if(!this->isPickedUp() && this->isActive_)
    152170        {
     
    271289
    272290                bool destroy = false;
    273                
     291
    274292                // Stop shrinking if the desired size is reached.
    275293                if(this->timeRemainig_ <= 0.0f)
     
    314332    {
    315333        PickupCarrier* carrier = this->getCarrier();
    316         Pawn* pawn = dynamic_cast<Pawn*>(carrier);
     334        Pawn* pawn = orxonox_cast<Pawn*>(carrier);
    317335
    318336        return pawn;
    319337    }
    320 
    321     /**
    322     @brief
    323         Creates a duplicate of the input OrxonoxClass.
    324     @param item
    325         A pointer to the Orxonox class.
    326     */
    327     void ShrinkPickup::clone(OrxonoxClass*& item)
    328     {
    329         if(item == NULL)
    330             item = new ShrinkPickup(this);
    331 
    332         SUPER(ShrinkPickup, clone, item);
    333         ShrinkPickup* pickup = dynamic_cast<ShrinkPickup*>(item);
    334         pickup->setShrinkFactor(this->getShrinkFactor());
    335         pickup->setDuration(this->getDuration());
    336         pickup->setShrinkDuration(this->getShrinkDuration());
    337 
    338         pickup->initializeIdentifier();
    339     }
    340338}
  • code/trunk/src/modules/pickup/items/ShrinkPickup.h

    r8858 r9348  
    8080            virtual void changedUsed(void); // Is called when the pickup has transited from used to unused or the other way around.
    8181            virtual void changedPickedUp(void);
    82             virtual void clone(OrxonoxClass*& item); // Creates a duplicate of the input OrxonoxClass.
    8382
    8483            /**
     
    8887            inline float getShrinkFactor(void) const
    8988                { return this->shrinkFactor_; }
    90             /**
    91             @brief Sets the shrinking factor.
    92             @param factor The factor, needs to greater than 1.
    93             */
    94             inline void setShrinkFactor(float factor)
    95                 { if(factor <= 1.0f) { orxout(internal_warning, context::pickups) << "Invalid shrinking factor in ShrinkPickup. Ignoring.." << endl; return; } this->shrinkFactor_ = factor; }
     89            void setShrinkFactor(float factor);
     90
    9691            /**
    9792            @brief Get the duration for which the ship remains shrunken.
     
    10095            inline float getDuration(void) const
    10196                { return this->duration_; }
    102             /**
    103             @brief Set the duration for which the ship remains shrunken.
    104             @param duration The duration, needs to be non-negative.
    105             */
    106             inline void setDuration(float duration)
    107                 { if(duration < 0.0f) { orxout(internal_warning, context::pickups) << "Invalid duration in ShrinkPickup. Ignoring.." << endl; return; } this->duration_ = duration; }
     97            void setDuration(float duration);
     98
    10899            /**
    109100            @brief Get the shrink speed.
     
    112103            inline float getShrinkDuration(void) const
    113104                { return this->shrinkDuration_; }
    114             /**
    115             @brief Set the shrink duration.
    116             @param speed The shrink duration, needs to be positive.
    117             */
    118             inline void setShrinkDuration(float speed)
    119                 { if(speed <= 0.0f) { orxout(internal_warning, context::pickups) << "Invalid shrink duration in ShrinkPickup. Ignoring.." << endl; return; } this->shrinkDuration_ = speed; }
    120 
    121         protected:
    122             void initializeIdentifier(void);
     105            void setShrinkDuration(float speed);
    123106
    124107        private:
     
    135118            float currentFactor_;       //!< The shrink factor that is currently applied.
    136119            float timeRemainig_;        //!< The remaining shrink time.
    137            
     120
    138121            Pawn* carrierToPawnHelper(void);
    139122            Timer durationTimer_;
  • code/trunk/src/modules/pickup/items/SpeedPickup.cc

    r8858 r9348  
    3838#include "core/XMLPort.h"
    3939
    40 #include "pickup/PickupIdentifier.h"
    4140#include "worldentities/pawns/SpaceShip.h"
    4241
     
    8079    /**
    8180    @brief
    82         Initializes the PickupIdentifier of this pickup.
    83     */
    84     void SpeedPickup::initializeIdentifier(void)
    85     {
    86         std::stringstream stream;
    87         stream << this->getDuration();
    88         std::string type1 = "duration";
    89         std::string val1 = stream.str();
    90         this->pickupIdentifier_->addParameter(type1, val1);
    91 
    92         stream.clear();
    93         stream << this->getSpeedAdd();
    94         std::string type2 = "speedAdd";
    95         std::string val2 = stream.str();
    96         this->pickupIdentifier_->addParameter(type2, val2);
    97 
    98         stream.clear();
    99         stream << this->getSpeedMultiply();
    100         std::string type3 = "speedMultiply";
    101         std::string val3 = stream.str();
    102         this->pickupIdentifier_->addParameter(type3, val3);
    103     }
    104 
    105     /**
    106     @brief
    10781        Method for creating a SpeedPickup object through XML.
    10882    */
     
    11488        XMLPortParam(SpeedPickup, "speedAdd", setSpeedAdd, getSpeedAdd, xmlelement, mode);
    11589        XMLPortParam(SpeedPickup, "speedMultiply", setSpeedMultiply, getSpeedMultiply, xmlelement, mode);
    116 
    117         this->initializeIdentifier();
    11890    }
    11991
     
    176148    {
    177149        PickupCarrier* carrier = this->getCarrier();
    178         SpaceShip* ship = dynamic_cast<SpaceShip*>(carrier);
     150        SpaceShip* ship = orxonox_cast<SpaceShip*>(carrier);
    179151
    180152        if(ship == NULL)
     
    184156
    185157        return ship;
    186     }
    187 
    188     /**
    189     @brief
    190         Creates a duplicate of the input OrxonoxClass.
    191     @param item
    192         A pointer to the Orxonox class.
    193     */
    194     void SpeedPickup::clone(OrxonoxClass*& item)
    195     {
    196         if(item == NULL)
    197             item = new SpeedPickup(this);
    198 
    199         SUPER(SpeedPickup, clone, item);
    200 
    201         SpeedPickup* pickup = dynamic_cast<SpeedPickup*>(item);
    202         pickup->setDuration(this->getDuration());
    203         pickup->setSpeedAdd(this->getSpeedAdd());
    204         pickup->setSpeedMultiply(this->getSpeedMultiply());
    205 
    206         pickup->initializeIdentifier();
    207158    }
    208159
  • code/trunk/src/modules/pickup/items/SpeedPickup.h

    r8727 r9348  
    8181
    8282            virtual void changedUsed(void); //!< Is called when the pickup has transited from used to unused or the other way around.
    83             virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input OrxonoxClass.
    8483
    8584            /**
     
    103102
    104103        protected:
    105             void initializeIdentifier(void); //!< Initializes the PickupIdentifier of this pickup.
    106104            void pickupTimerCallback(void); //!< Function that gets called when timer ends.
    107105
     
    112110        private:
    113111            void initialize(void); //!< Initializes the member variables.
    114             SpaceShip* carrierToSpaceShipHelper(void); //!< Helper to transform the PickupCarrier to a SpaceSHip, and throw an error message if the conversion fails.
     112            SpaceShip* carrierToSpaceShipHelper(void); //!< Helper to transform the PickupCarrier to a SpaceShip, and throw an error message if the conversion fails.
    115113
    116114            Timer durationTimer_; //!< Timer.
Note: See TracChangeset for help on using the changeset viewer.