Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 5, 2010, 6:26:54 PM (15 years ago)
Author:
dafrick
Message:

Additional documentation, code niceifying and potential bug fixing. Also: Renamed DroppedItem to DroppedPickup.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/pickup3/src/modules/pickup/Pickup.cc

    r6474 r6475  
    3030
    3131#include "core/CoreIncludes.h"
     32#include "util/StringUtils.h"
     33#include "pickup/PickupIdentifier.h"
     34#include "DroppedPickup.h"
    3235
    3336namespace orxonox
     
    3841    /*static*/ const std::string Pickup::durationTypeOnce_s = "once";
    3942    /*static*/ const std::string Pickup::durationTypeContinuous_s = "continuous";
    40     /*static*/ const std::string Pickup::blankString_s = "";
    41    
    42     //TODO: Should this bee here? Does it work without?
     43   
     44    //TODO: Should this be here? Does it work without?
    4345    CreateFactory(Pickup);
    4446   
     
    4749        RegisterObject(Pickup);
    4850       
     51        this->initialize();
    4952    }
    5053   
     
    5457    }
    5558   
     59    /**
     60    @brief
     61        Initializes the member variables.
     62    */
     63    void Pickup::initialize(void)
     64    {
     65        this->activationType_ = pickupActivationType::immediate;
     66        this->durationType_ = pickupDurationType::once;
     67    }
     68   
     69    /**
     70    @brief
     71        Initializes the PickupIdentififer of this Pickup.
     72    */
    5673    void Pickup::initializeIdentifier(void)
    5774    {
    58         this->pickupIdentifier_.addClass(this->getIdentifier());
     75        //TODO: Check whether this could not be done in the Constructor if Pickupable. Would be much more convenient.
     76        this->pickupIdentifier_->addClass(this->getIdentifier());
    5977       
    6078        //TODO: Works?
    6179        std::string val1 = this->getActivationType();
    6280        std::string type1 = "activationType";
    63         this->pickupIdentifier_.addParameter(type1, val1);
     81        this->pickupIdentifier_->addParameter(type1, val1);
    6482       
    6583        std::string val2 = this->getDurationType();
    6684        std::string type2 = "durationType";
    67         this->pickupIdentifier_.addParameter(type2, val2);
    68     }
    69    
     85        this->pickupIdentifier_->addParameter(type2, val2);
     86    }
     87   
     88    /**
     89    @brief
     90        Method for creating a Pickup object through XML.
     91    */
    7092    void Pickup::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    7193    {
     
    81103    @brief
    82104        Get the activation type of the pickup.
    83     @param buffer
    84         The buffer to store the activation type as string in.
     105    @return
     106        Returns a string containing the activation type.
    85107    */
    86108    const std::string& Pickup::getActivationType(void)
     
    93115                return activationTypeOnUse_s;
    94116            default:
    95                 return blankString_s;
     117                return BLANKSTRING;
    96118        }
    97119    }
     
    100122    @brief
    101123        Get the duration type of the pickup.
    102     @param buffer
    103         The buffer to store the duration type as string in.
     124    @return
     125        Returns a string containing the duration type.
    104126    */
    105127    const std::string& Pickup::getDurationType(void)
     
    112134                return durationTypeContinuous_s;
    113135            default:
    114                 return blankString_s;
     136                return BLANKSTRING;
    115137        }
    116138    }
     
    162184    /**
    163185    @brief
    164         Creates a duplicate of the pickup.
     186        Should be called when the pickup has transited from picked up to dropped or the other way around.
     187        Any Class overwriting this method must call its SUPER function by adding SUPER(Classname, changedCarrier); to their changedCarrier method.
     188    */
     189    void Pickup::changedCarrier(void)
     190    {
     191        SUPER(Pickup, changedCarrier);
     192       
     193        //! Sets the Pickup to used if the Pickup has activation type 'immediate' and gets picked up.
     194        if(this->isPickedUp() && this->isImmediate())
     195        {
     196            this->setUsed(true);
     197        }
     198    }
     199   
     200    /**
     201    @brief
     202        Creates a duplicate of the Pickup.
    165203    @return
    166204        Returns the clone of this pickup as a pointer to a Pickupable.
     
    179217        pickup->initializeIdentifier();
    180218    }
    181    
    182     void Pickup::changedCarrier(void)
    183     {
    184         SUPER(Pickup, changedCarrier);
    185        
    186         if(this->isPickedUp() && this->isImmediate())
    187         {
    188             this->setUsed(true);
    189         }
     219       
     220    /**
     221    @brief
     222        Facilitates the creation of a PickupSpawner upon dropping of the Pickupable.
     223        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.:
     224        DroppedPickup(BaseObject* creator, Pickupable* pickup, const Vector3& position);
     225    @param position
     226        The position at which the PickupSpawner should be placed.
     227    @return
     228        Returns true if a spawner was created, false if not.
     229    */
     230    bool Pickup::createSpawner(const Vector3& position)
     231    {
     232        DroppedPickup::DroppedPickup(this, this, position);
     233        return true;
    190234    }
    191235   
Note: See TracChangeset for help on using the changeset viewer.