Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 16, 2010, 12:37:09 PM (14 years ago)
Author:
dafrick
Message:

Documenting and cleanup.

Location:
code/trunk/src/modules/pickup/items
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/modules/pickup/items/DronePickup.cc

    r7541 r7547  
    3535
    3636#include <sstream>
    37 
    3837#include "core/CoreIncludes.h"
    3938#include "core/XMLPort.h"
    40 #include "util/StringUtils.h"
    4139
    4240#include "controllers/DroneController.h"
    4341#include "pickup/PickupIdentifier.h"
     42#include "worldentities/Drone.h"
    4443#include "worldentities/pawns/Pawn.h"
    45 #include "worldentities/Drone.h"
    46 #include "worldentities/StaticEntity.h"
    4744
    4845namespace orxonox
  • code/trunk/src/modules/pickup/items/DronePickup.h

    r7541 r7547  
    4848    @brief
    4949        The DronePickup adds a Drone to the Pawn upon being picked up.
     50
    5051        It can be used in XML as follows:
    5152        @code
     
    7172            virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input OrxonoxClass.
    7273
    73             void setDroneTemplate(std::string templatename); //!< Set the droneTemplate.
    7474            const std::string& getDroneTemplate() const; //!< Get the name of the droneTemplate.
    7575
    7676        protected:
    7777            void initializeIdentifier(void); //!< Initializes the PickupIdentifier of this pickup.
     78
     79            void setDroneTemplate(std::string templatename); //!< Set the droneTemplate.
    7880
    7981        private:
  • code/trunk/src/modules/pickup/items/HealthPickup.cc

    r7541 r7547  
    3434#include "HealthPickup.h"
    3535
     36#include <sstream>
    3637#include "core/CoreIncludes.h"
    3738#include "core/XMLPort.h"
    38 #include "util/StringUtils.h"
    39 
     39
     40#include "pickup/PickupIdentifier.h"
    4041#include "worldentities/pawns/Pawn.h"
    41 #include "pickup/PickupIdentifier.h"
    42 
    43 #include <sstream>
    4442
    4543namespace orxonox
     
    307305        Returns the health type as a string.
    308306    */
    309     const std::string& HealthPickup::getHealthType(void)
     307    const std::string& HealthPickup::getHealthType(void) const
    310308    {
    311309        switch(this->getHealthTypeDirect())
  • code/trunk/src/modules/pickup/items/HealthPickup.h

    r7541 r7547  
    3939
    4040#include <string>
    41 #include <worldentities/pawns/Pawn.h>
    42 #include "worldentities/StaticEntity.h"
    4341
    4442#include "pickup/Pickup.h"
     
    6563    /**
    6664    @brief
    67         The Health Pickup is a Pickupable that can do (dependent upon the parameters) lots of different things to the health of a Pawn.
    68         There are 4 parameters that can be chosen:
    69         - The <b>health</b> The amount of health that (in a way dependent on the other parameters) is transferred to the Pawn.
    70         - The <b>activation type</b> It can be chosen to be either <em>immediate</em> or <em>onUse</em>. The activation type essentially (as indicated by the name) defines when the health is transferred, either immediately after being picked up or only after the player uses it.
    71         - The <b>duration type</b> It can be chosen to be either <em>once</em> or <em>continuous</em>. For <em>once</em> the specified health is transferred once to the Pawn, for <em>continuous</em> the set health is transferred over a span of time at a rate defined by the health rate parameter.
    72         - The <b>health type</b> The health type can be chosen to be <em>limited</em>, <em>temporary</em> or <em>permanent</em>. <em>limited</em> means that the health is increased only to the maximum health of the Pawn. 'temporary' means that the maximum health is temporarily elevated but will be set back as soon as the pickup is no longer in use. <em>permanent</em> means that the maximum health of the Pawn is increased such that the health provided by the pickup will fit in and the maximum health stays that way.
     65        The HealthPickup is a Pickupable that can do (dependent upon the parameters) lots of different things to the health of a Pawn.
     66        There are 5 parameters that can be chosen:
     67        - The @b activationType It can be chosen to be either <em>immediate</em> or <em>onUse</em>. The activation type essentially (as indicated by the name) defines when the health is transferred, either immediately after being picked up or only after the player uses it. The default is <em>immediate</em>.
     68        - The @b durationType It can be chosen to be either <em>once</em> or <em>continuous</em>. For <em>once</em> the specified health is transferred once to the Pawn, for <em>continuous</em> the set health is transferred over a span of time at a rate defined by the health rate parameter. The default is <em>once</em>.
     69        - The @b health The amount of health that (in a way dependent on the other parameters) is transferred to the Pawn. Default is 0.
     70        - The @b healthType The health type can be chosen to be <em>limited</em>, <em>temporary</em> or <em>permanent</em>. <em>limited</em> means that the health is increased only to the maximum health of the Pawn. 'temporary' means that the maximum health is temporarily elevated but will be set back as soon as the pickup is no longer in use. <em>permanent</em> means that the maximum health of the Pawn is increased such that the health provided by the pickup will fit in and the maximum health stays that way. The default is <em>limited</em>.
     71        - The @b healthRate If set to continuous, the health that is transferred per second is the <em>healthRate</em>. There is health transferred until the health set by <em>health</em> is depleted. The default is 0.
    7372
    74         An examle of a XML implementation of a HealthPickup would be:
     73        An example of a XML implementation of a HealthPickup would be:
    7574        @code
    7675        <HealthPickup
     
    104103            @return Returns the health.
    105104            */
    106             inline float getHealth(void)
     105            inline float getHealth(void) const
    107106                { return this->health_; }
    108107            /**
     
    110109            @return Returns the rate.
    111110            */
    112             inline float getHealthRate(void)
     111            inline float getHealthRate(void) const
    113112                { return this->healthRate_; }
    114113
     
    117116            @return Returns the health type as an enum.
    118117            */
    119             inline pickupHealthType::Value getHealthTypeDirect(void)
     118            inline pickupHealthType::Value getHealthTypeDirect(void) const
    120119                { return this->healthType_; }
    121             const std::string& getHealthType(void); //!< Get the health type of this pickup.
     120            const std::string& getHealthType(void) const; //!< Get the health type of this pickup.
    122121
    123122        protected:
  • code/trunk/src/modules/pickup/items/InvisiblePickup.cc

    r7546 r7547  
    3535
    3636#include <sstream>
    37 #include <OgreEntity.h>
    38 #include <OgreAnimationState.h>
    39 
    40 #include "util/StringUtils.h"
     37//#include <OgreEntity.h>
     38//#include <OgreAnimationState.h>
    4139#include "core/CoreIncludes.h"
    4240#include "core/XMLPort.h"
    4341
     42#include "pickup/PickupIdentifier.h"
    4443#include "worldentities/pawns/Pawn.h"
    45 #include "pickup/PickupIdentifier.h"
    4644
    4745namespace orxonox
     
    6866    }
    6967
    70 
     68    /**
     69    @brief
     70    Initializes the member variables.
     71    */
     72    void InvisiblePickup::initialize(void)
     73    {
     74        this->duration_ = 0.0f;
     75        // Defines who is allowed to pick up the pickup.
     76        this->addTarget(ClassIdentifier<Pawn>::getIdentifier());
     77    }
     78
     79    /**
     80    @brief
     81        Initializes the PickupIdentifier of this pickup.
     82    */
    7183    void InvisiblePickup::initializeIdentifier(void)
    7284    {
     
    8092    /**
    8193    @brief
    82     Initializes the member variables.
    83     */
    84     void InvisiblePickup::initialize(void)
    85     {
    86         this->duration_ = 0.0f;
    87         // Defines who is allowed to pick up the pickup.
    88         this->addTarget(ClassIdentifier<Pawn>::getIdentifier());
    89     }
    90 
    91     /**
    92     @brief
    9394        Method for creating a HealthPickup object through XML.
    9495    */
     
    113114            return;
    114115
     116        // If the pickup has transited to used.
    115117        if (this->isUsed())
    116118        {
     119            // If its durationType is continuous, we set a Timer to be reminded, when the time has run out.
    117120            if(this->isContinuous())
    118121            {
     
    134137            this->setInvisible(false);
    135138
     139            // We destroy the pickup if either, the pickup has activationType immediate and durationType once or it has durationType continuous and the duration was exceeded.
    136140            if((!this->isContinuous() && this->isImmediate()) || (this->isContinuous() && !this->durationTimer_.isActive() && this->durationTimer_.getRemainingTime() == this->getDuration()))
    137141            {
    138142                this->Pickupable::destroy();
    139143            }
     144            // We pause the Timer if the pickup is continuous and the duration is not yet exceeded,
    140145            else if(this->isContinuous() && this->durationTimer_.isActive())
    141146            {
     
    143148            }
    144149        }
    145 
    146     }
    147 
    148     /**
    149     @brief
    150         Helper to transform the PickupCarrier to a Pawn, and throw an error message if the conversion fails.
    151     @return
    152         A pointer to the Pawn, or NULL if the conversion failed.
    153     */
    154     Pawn* InvisiblePickup::carrierToPawnHelper(void)
    155     {
    156         PickupCarrier* carrier = this->getCarrier();
    157         Pawn* pawn = dynamic_cast<Pawn*>(carrier);
    158 
    159         if(pawn == NULL)
    160         {
    161             COUT(1) << "Invalid PickupCarrier in InvisiblePickup." << std::endl;
    162         }
    163         return pawn;
    164150    }
    165151
     
    212198    /**
    213199    @brief
     200        Helper to transform the PickupCarrier to a Pawn, and throw an error message if the conversion fails.
     201    @return
     202        A pointer to the Pawn, or NULL if the conversion failed.
     203    */
     204    Pawn* InvisiblePickup::carrierToPawnHelper(void)
     205    {
     206        PickupCarrier* carrier = this->getCarrier();
     207        Pawn* pawn = dynamic_cast<Pawn*>(carrier);
     208
     209        if(pawn == NULL)
     210        {
     211            COUT(1) << "Invalid PickupCarrier in InvisiblePickup." << std::endl;
     212        }
     213        return pawn;
     214    }
     215
     216    /**
     217    @brief
    214218        Sets the time the InvisibilityPickup will last.
    215219    @param duration
  • code/trunk/src/modules/pickup/items/InvisiblePickup.h

    r7545 r7547  
    4040#include <string>
    4141
    42 #include <worldentities/pawns/Pawn.h>
    43 #include "worldentities/StaticEntity.h"
    4442#include "pickup/Pickup.h"
    4543
     
    4947    @brief
    5048        A pickup that makes the Pawn invisible.
    51         There are 2 parameters that can be chosen:
    52         - The <b>activation type</b> It can be chosen to be either <em>immediate</em> or <em>onUse</em>. The activation type essentially (as indicated by the name) defines when the Pawn will be invisible, either immediately after being picked up or only after the player uses it.
    53         - The <b>duration type</b> It can be chosen to be either <em>once</em> or <em>continuous</em>. For <em>once</em> the InvisiblePickup just makes the Pawn invisible for as long as it is used, for <em>continuous</em> the Pawn is invisible for the specified duration.
    54         - The <b>duration</b> Specifies how long (in seconds) the invisibility lasts.
     49        There are 3 parameters that can be chosen:
     50        - The @b activationType It can be chosen to be either <em>immediate</em> or <em>onUse</em>. The activation type essentially (as indicated by the name) defines when the Pawn will be invisible, either immediately after being picked up or only after the player uses it. The default is <em>immediate</em>.
     51        - The @b durationType< It can be chosen to be either <em>once</em> or <em>continuous</em>. For <em>once</em> the InvisiblePickup just makes the Pawn invisible for as long as it is used, for <em>continuous</em> the Pawn is invisible for the specified duration. The default is <em>once</em>.
     52        - The @b duration Specifies how long (in seconds) the invisibility lasts. The default is 0.
    5553
    56         An examle of a XML implementation of a InvisiblePickup would be:
     54        An example of a XML implementation of a InvisiblePickup would be:
    5755        @code
    58         <HealthPickup
     56        <InvisiblePickup
    5957            activationType = "immediate"
    6058            durationType = "continuous"
     
    8381            @return Returns if the Pawn is invisible.
    8482            */
    85             inline bool getInvisibility(bool)
     83            inline bool getInvisibility(bool) const
    8684                { return this->invisible_; }
    8785            /**
     
    8987            @return Returns the time in seconds the InvisibiltyPickup lasts.
    9088            */
    91             inline float getDuration(void)
     89            inline float getDuration(void) const
    9290                { return this->duration_; }
    9391
    9492        protected:
    95             void initializeIdentifier(void);
     93            void initializeIdentifier(void); //!< Initializes the PickupIdentifier of this pickup.
    9694
    9795            bool setInvisible(bool invisibility); //!< Set the Pawn to be invisible or visible again.
  • code/trunk/src/modules/pickup/items/MetaPickup.cc

    r7533 r7547  
    3434#include "core/CoreIncludes.h"
    3535#include "core/XMLPort.h"
    36 #include "worldentities/pawns/Pawn.h"
     36
    3737#include "interfaces/PickupCarrier.h"
    3838#include "pickup/PickupIdentifier.h"
     39#include "worldentities/pawns/Pawn.h"
    3940
    4041#include "MetaPickup.h"
     
    7980        this->addTarget(ClassIdentifier<PickupCarrier>::getIdentifier());
    8081
    81         this->setActivationTypeDirect(pickupActivationType::immediate);
    8282        this->setDurationTypeDirect(pickupDurationType::once);
    8383        this->metaType_ = pickupMetaType::none;
     
    117117        SUPER(MetaPickup, changedUsed);
    118118
    119         //! If the MetaPickup transited to used.
    120         if(this->isUsed())
     119        // If the MetaPickup transited to used, and the metaType is not none.
     120        if(this->isUsed() && this->metaType_ != pickupMetaType::none)
    121121        {
    122122            PickupCarrier* carrier = this->getCarrier();
    123123            if(this->getMetaTypeDirect() != pickupMetaType::none && carrier != NULL)
    124124            {
     125                // If the metaType is destroyCarrier, then the PickupCarrier is destroyed.
    125126                if(this->getMetaTypeDirect() == pickupMetaType::destroyCarrier)
    126127                {
     
    131132                }
    132133                std::set<Pickupable*> pickups = carrier->getPickups();
    133                 //! Set all Pickupables carried by the PickupCarrier either to used or drop them, depending on the meta type.
     134                // Iterate over all Pickupables of the PickupCarrier.
    134135                for(std::set<Pickupable*>::iterator it = pickups.begin(); it != pickups.end(); it++)
    135136                {
    136                     Pickup* pickup = dynamic_cast<Pickup*>(*it);
    137                     if(this->getMetaTypeDirect() == pickupMetaType::use)
     137                    Pickupable* pickup = (*it);
     138                    if(pickup == NULL || pickup == this)
     139                        continue;
     140
     141                    // If the metaType is use, then the Pickupable is set to used.
     142                    if(this->getMetaTypeDirect() == pickupMetaType::use && !pickup->isUsed())
    138143                    {
    139                         if(pickup != NULL && pickup != this && pickup->isOnUse() && !pickup->isUsed())
    140                         {
    141                             pickup->setUsed(true);
    142                         }
     144                        pickup->setUsed(true);
    143145                    }
    144                     if(this->getMetaTypeDirect() == pickupMetaType::drop)
     146                    // If the metaType is drop, then the Pickupable is dropped.
     147                    else if(this->getMetaTypeDirect() == pickupMetaType::drop)
    145148                    {
    146                         if(pickup != NULL && pickup != this)
    147                         {
    148                             pickup->drop();
    149                         }
     149                        pickup->drop();
    150150                    }
    151                     if(this->getMetaTypeDirect() == pickupMetaType::destroy)
     151                    // If the metaType is destroy, then the Pickupable is destroyed.
     152                    else if(this->getMetaTypeDirect() == pickupMetaType::destroy)
    152153                    {
    153                         if(pickup != NULL && pickup != this)
    154                         {
    155                             pickup->Pickupable::destroy();
    156                         }
     154                        pickup->Pickupable::destroy();
    157155                    }
    158156                }
     
    187185        Returns a string with the meta type of the MetaPickup.
    188186    */
    189     const std::string& MetaPickup::getMetaType(void)
     187    const std::string& MetaPickup::getMetaType(void) const
    190188    {
    191189        switch(this->getMetaTypeDirect())
  • code/trunk/src/modules/pickup/items/MetaPickup.h

    r7533 r7547  
    4242namespace orxonox {
    4343
    44     //! The meta type, deciding what the pickup does exactly.
     44    /**
     45    @brief
     46        The meta type, specifying what the @ref orxonox::MetaPickup "MetaPickup" does exactly.
     47
     48    @ingroup PickupItems
     49    */
    4550    namespace pickupMetaType
    4651    {
    4752        enum Value
    4853        {
    49             none,
    50             use,
    51             drop,
    52             destroy,
    53             destroyCarrier
     54            none, //!< The @ref orxonox::MetaPickup "MetaPickup" does nothing.
     55            use, //!< The @ref orxonox::MetaPickup "MetaPickup" uses all the @ref orxonox::PickupCarrier "PickupCarriers'" @ref orxonox::Pickupable "Pickupables".
     56            drop, //!< The @ref orxonox::MetaPickup "MetaPickup" drops all the @ref orxonox::PickupCarrier "PickupCarriers'" @ref orxonox::Pickupable "Pickupables".
     57            destroy, //!< The @ref orxonox::MetaPickup "MetaPickup" destroys all the @ref orxonox::PickupCarrier "PickupCarriers'" @ref orxonox::Pickupable "Pickupables".
     58            destroyCarrier //!< The @ref orxonox::MetaPickup "MetaPickup" destroys the @ref orxonox::PickupCarrier "PickupCarrier".
    5459        };
    5560    }
     
    5762    /**
    5863    @brief
    59         The MetaPickup is a pickup that can, depending on the parameter 'metaType', do different things. If the 'metaType' is set to
    60         - @b use All the pickups, the PickupCarrier has, are immediately set to used upon pickup of the MetaPickup.
    61         - @b drop All the pickups, the PickupCarrier has, are immediately dropped upon pickup of the MetaPickup.
    62         - @b destroy All the pickups, the PickupCarrier has, are immediately destroyed upon pickup of the MetaPickup.
    63         - @b destroyCarrier The PickupCarrier is immediately destroyed upon pickup of the MetaPickup.
     64        The MetaPickup is a Pickupable that can, depending on the parameter <em>metaTye</em>, do different things. If the <em>metaTye</em> is set to
     65        - @b use All the @ref orxonox::Pickupable "Pickupables", the PickupCarrier has, are immediately set to used upon using the MetaPickup.
     66        - @b drop All the @ref orxonox::Pickupable "Pickupables", the PickupCarrier has, are immediately dropped upon using the MetaPickup.
     67        - @b destroy All the @ref orxonox::Pickupable "Pickupables", the PickupCarrier has, are immediately destroyed upon using the MetaPickup.
     68        - @b destroyCarrier The PickupCarrier is immediately destroyed upon using the MetaPickup.
     69
     70        The default value is <em>none</em>, which basically does nothing.
     71       
     72        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.
     73
     74        An example of a XML implementation of a MetaPickup would be:
     75        @code
     76        <MetaPickup
     77            activationType = "immediate"
     78            metaType = "use"
     79        />
     80        @endcode
     81
    6482    @author
    6583        Damian 'Mozork' Frick
     84
     85    @ingroup PickupItems
    6686    */
    6787    class _PickupExport MetaPickup : public Pickup
     
    81101            @return Returns an enum with the meta type of the MetaPickup.
    82102            */
    83             inline pickupMetaType::Value getMetaTypeDirect(void)
     103            inline pickupMetaType::Value getMetaTypeDirect(void) const
    84104                { return this->metaType_; }
    85             const std::string& getMetaType(void); //!< Get the meta type of this MetaPickup.
     105            const std::string& getMetaType(void) const; //!< Get the meta type of this MetaPickup.
    86106
    87107        protected:
  • code/trunk/src/modules/pickup/items/ShieldPickup.cc

    r7208 r7547  
    3434#include "ShieldPickup.h"
    3535
     36#include <sstream>
    3637#include "core/CoreIncludes.h"
    3738#include "core/XMLPort.h"
    38 #include "util/StringUtils.h"
    39 
    40 #include "worldentities/pawns/SpaceShip.h"
    41 #include "items/Engine.h"
     39
    4240#include "pickup/PickupIdentifier.h"
    43 
    44 #include <sstream>
    45 
     41#include "worldentities/pawns/Pawn.h"
    4642
    4743namespace orxonox
     
    6763    {
    6864
    69     }
    70 
    71     /**
    72     @brief
    73     Helper to transform the PickupCarrier to a Pawn, and throw an error message if the conversion fails.
    74     @return
    75     A pointer to the Pawn, or NULL if the conversion failed.
    76     */
    77     Pawn* ShieldPickup::carrierToPawnHelper(void)
    78     {
    79         PickupCarrier* carrier = this->getCarrier();
    80         Pawn* pawn = dynamic_cast<Pawn*>(carrier);
    81 
    82         if(pawn == NULL)
    83         {
    84             COUT(1) << "Invalid PickupCarrier in ShieldPickup." << std::endl;
    85         }
    86         return pawn;
    8765    }
    8866
     
    134112        SUPER(ShieldPickup, XMLPort, xmlelement, mode);
    135113
    136         XMLPortParam(ShieldPickup, "duration", setDuration, getDuration, xmlelement, mode);
    137114        XMLPortParam(ShieldPickup, "shieldhealth", setShieldHealth, getShieldHealth, xmlelement, mode);
    138115        XMLPortParam(ShieldPickup, "shieldabsorption", setShieldAbsorption, getShieldAbsorption, xmlelement, mode);
     116        XMLPortParam(ShieldPickup, "duration", setDuration, getDuration, xmlelement, mode);
    139117
    140118        this->initializeIdentifier();
     
    149127        SUPER(ShieldPickup, changedUsed);
    150128
    151         //! If the pickup is not picked up nothing must be done.
     129        // If the pickup is not picked up nothing must be done.
    152130        if(!this->isPickedUp())
    153131            return;
     
    157135            this->Pickupable::destroy();
    158136
    159         //! If the pickup has transited to used.
     137        // If the pickup has transited to used.
    160138        if(this->isUsed())
    161139        {
    162             if(!this->durationTimer_.isActive() && this->durationTimer_.getRemainingTime() > 0.0f)
     140            // If its durationType is continuous, we set a Timer to be reminded, when the time has run out.
     141            if(this->isContinuous())
    163142            {
    164                 this->durationTimer_.unpauseTimer();
    165             }
    166             else
    167             {
    168                 this->durationTimer_.setTimer(this->getDuration(), false, createExecutor(createFunctor(&ShieldPickup::pickupTimerCallback, this)));
     143                if(!this->durationTimer_.isActive() && this->durationTimer_.getRemainingTime() > 0.0f)
     144                {
     145                    this->durationTimer_.unpauseTimer();
     146                }
     147                else
     148                {
     149                    this->durationTimer_.setTimer(this->getDuration(), false, createExecutor(createFunctor(&ShieldPickup::pickupTimerCallback, this)));
     150                }
    169151            }
    170152            pawn->setShieldAbsorption(this->getShieldAbsorption());
     
    177159            pawn->setShieldHealth(0.0f);
    178160
    179             if(this->isOnce())
     161            // We destroy the pickup if either, the pickup has activationType immediate and durationType once or it has durationType continuous and the duration was exceeded.
     162            if((!this->isContinuous() && this->isImmediate()) || (this->isContinuous() && !this->durationTimer_.isActive() && this->durationTimer_.getRemainingTime() == this->getDuration()))
    180163            {
    181                 if(!this->durationTimer_.isActive() && this->durationTimer_.getRemainingTime() == this->getDuration())
    182                 {
    183                     this->Pickupable::destroy();
    184                 }
    185                 else
    186                 {
    187                     this->durationTimer_.pauseTimer();
    188                 }
     164                this->Pickupable::destroy();
    189165            }
    190         }
     166            // We pause the Timer if the pickup is continuous and the duration is not yet exceeded,
     167            else if(this->isContinuous() && this->durationTimer_.isActive())
     168            {
     169                this->durationTimer_.pauseTimer();
     170            }
     171        }
     172    }
     173
     174    /**
     175    @brief
     176    Helper to transform the PickupCarrier to a Pawn, and throw an error message if the conversion fails.
     177    @return
     178    A pointer to the Pawn, or NULL if the conversion failed.
     179    */
     180    Pawn* ShieldPickup::carrierToPawnHelper(void)
     181    {
     182        PickupCarrier* carrier = this->getCarrier();
     183        Pawn* pawn = dynamic_cast<Pawn*>(carrier);
     184
     185        if(pawn == NULL)
     186        {
     187            COUT(1) << "Invalid PickupCarrier in ShieldPickup." << std::endl;
     188        }
     189        return pawn;
    191190    }
    192191
     
    213212    /**
    214213    @brief
    215     Sets the percentage the shield absorbs of the dealt damage.
     214        Sets the duration.
     215    @param duration
     216        The duration in seconds.
     217    */
     218    void ShieldPickup::setDuration(float duration)
     219    {
     220        if(duration >= 0.0f)
     221        {
     222            this->duration_ = duration;
     223        }
     224        else
     225        {
     226            COUT(1) << "Invalid duration in ShieldPickup." << std::endl;
     227            this->duration_ = 0.0f;
     228        }
     229    }
     230
     231    /**
     232    @brief
     233        Sets the health of the shield.
     234    @param shieldHealth
     235        The shieldHealth.
     236    */
     237    void ShieldPickup::setShieldHealth(float shieldHealth)
     238    {
     239        if (shieldHealth>=0)
     240        {
     241            this->shieldHealth_=shieldHealth;
     242        }
     243        else
     244        {
     245            COUT(1) << "Invalid Shieldhealth in ShieldPickup." << std::endl;
     246            this->shieldHealth_=0;
     247        }
     248    }
     249
     250    /**
     251    @brief
     252        Sets the percentage the shield absorbs of the dealt damage.
    216253    @param shieldAbsorption
    217     The shieldAbsorption. Has to be between 0 and 1
     254        The shieldAbsorption. Has to be between 0 and 1.
    218255    */
    219256    void ShieldPickup::setShieldAbsorption(float shieldAbsorption)
     
    232269    /**
    233270    @brief
    234     Sets the health of the shield.
    235     @param shieldHealth
    236     The shieldHealth
    237     */
    238     void ShieldPickup::setShieldHealth(float shieldHealth)
    239     {
    240         if (shieldHealth>=0)
    241         {
    242             this->shieldHealth_=shieldHealth;
    243         }
    244         else
    245         {
    246             COUT(1) << "Invalid Shieldhealth in ShieldPickup." << std::endl;
    247             this->shieldHealth_=0;
    248         }
    249     }
    250 
    251     /**
    252     @brief
    253         Sets the duration.
    254     @param duration
    255         The duration
    256     */
    257     void ShieldPickup::setDuration(float duration)
    258     {
    259         if(duration >= 0.0f)
    260         {
    261             this->duration_ = duration;
    262         }
    263         else
    264         {
    265             COUT(1) << "Invalid duration in ShieldPickup." << std::endl;
    266             this->duration_ = 0.0f;
    267         }
    268     }
    269 
     271        Helper method. Is called by the Timer as soon as it expires.
     272    */
    270273    void ShieldPickup::pickupTimerCallback(void)
    271274    {
  • code/trunk/src/modules/pickup/items/ShieldPickup.h

    r7493 r7547  
    4040
    4141#include <string>
    42 #include "worldentities/pawns/Pawn.h"
    43 #include "worldentities/StaticEntity.h"
    4442
    4543#include "pickup/Pickup.h"
     
    5149        A Pickup which can add a Shield to the Pawn.
    5250
    53         There are 4 parameters that can be cosen.
    54         - The @b percentage The percentage the shield takes from the damage dealt to a Pawn
    55         - The @b hit @b points The amount of damage points a shield can teake before collapsing
    56         - The @b activation @b type 'immediate' or 'onUse'. defines if the item is used when it's picked up or only after the player chooses to use it.
    57         - The @b duration the activation time of the pickup.
     51        There are 5 parameters that can be cosen.
     52        - The @b shieldhealth< The amount of damage points a shield can take before collapsing. The default is 0.
     53        - The @b shieldabsorption The percentage the shield takes from the damage dealt to a Pawn. The default is 0.
     54        - The @b activationType, <em>immediate</em> or <em>onUse</em>. defines if the ShiedlPickup is used when it's picked up or only after the player chooses to use it. The default is <em>immediate</em>.
     55        - The @b durationType, <em>once</em> means, that the shield will stay until it collapses, <em>continuous</em> means, that the shield only stays for a limited amount of time, specifiey by the duration. The default is <em>once</em>.
     56        - The @b duration the time in seconds the shield is active at the most. The default is 0.
     57
     58        An example of a XML implementation of a ShieldPickup would be:
     59        @code
     60        <ShieldPickup
     61            shieldhealth = 30
     62            shieldabsorption = 0.8
     63            activationType = "immediate"
     64            durationtype = "continuous"
     65            duration = 20.0
     66        />
     67        @endcode
    5868
    5969    @author
    6070        Eric Beier
     71
     72    @ingroup PickupItems
    6173    */
    6274    class _PickupExport ShieldPickup : public Pickup
     
    7284            virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input OrxonoxClass.
    7385
    74             inline float getDuration(void)
     86            /**
     87            @brief Get the duration, the time the shield is actvie at the most.
     88            @return Returns the duration in seconds.
     89            */
     90            inline float getDuration(void) const
    7591                { return this->duration_; }
    76             inline float getShieldHealth()
     92            /**
     93            @brief Get the shield health, the amount of damage the shield can sustain.
     94            @return Returns the shield health.
     95            */
     96            inline float getShieldHealth() const
    7797                { return this->shieldHealth_; }
    78             inline float getShieldAbsorption()
     98            /**
     99            @brief Get the shield absorption, the percentage of damage that is absorbed by the shield.
     100            @return Returns the shield absorption.
     101            */
     102            inline float getShieldAbsorption() const
    79103                { return this->shieldAbsorption_; }
    80104
    81105        protected:
    82106            void initializeIdentifier(void); //!< Initializes the PickupIdentifier of this pickup.
     107            void pickupTimerCallback(void); //!< Helper method. Is called by the Timer as soon as it expires.
    83108
    84             void pickupTimerCallback(void); //!< Function that gets called when timer ends.
    85 
    86             void setDuration(float duration);
    87             void setShieldHealth(float shieldHealth);
    88             void setShieldAbsorption(float shieldAbsorption);
     109            void setDuration(float duration); //!< Sets the duration.
     110            void setShieldHealth(float shieldHealth); //!< Sets the health of the shield.
     111            void setShieldAbsorption(float shieldAbsorption); //!< Sets the percentage the shield absorbs of the dealt damage.
    89112
    90113        private:
     
    95118
    96119            float duration_; //!< The health that is transferred to the Pawn.
    97             float shieldHealth_;
    98             float shieldAbsorption_; // Has to be between 0 and 1
     120            float shieldHealth_; //!< The amount of damage the shield can sustain.
     121            float shieldAbsorption_; //!< The percentage of damage that is absorbed by the shield.
    99122
    100123    };
  • code/trunk/src/modules/pickup/items/SpeedPickup.cc

    r7401 r7547  
    3434#include "SpeedPickup.h"
    3535
     36#include <sstream>
    3637#include "core/CoreIncludes.h"
    3738#include "core/XMLPort.h"
    38 #include "util/StringUtils.h"
    39 
    40 #include "worldentities/pawns/SpaceShip.h"
     39
    4140#include "items/Engine.h"
    4241#include "pickup/PickupIdentifier.h"
    43 
    44 #include <sstream>
    45 
     42#include "worldentities/pawns/SpaceShip.h"
    4643
    4744namespace orxonox
     
    130127        SUPER(SpeedPickup, changedUsed);
    131128
    132         //! If the pickup is not picked up nothing must be done.
     129        // If the pickup is not picked up nothing must be done.
    133130        if(!this->isPickedUp())
    134131            return;
    135132
    136133        Engine* engine = this->carrierToEngineHelper();
    137         if(engine == NULL) //!< If the PickupCarrier is no Engine, then this pickup is useless and therefore is destroyed.
     134        if(engine == NULL) // If the PickupCarrier is no Engine, then this pickup is useless and therefore is destroyed.
    138135            this->Pickupable::destroy();
    139136
    140         //! If the pickup has transited to used.
     137        // If the pickup has transited to used.
    141138        if(this->isUsed())
    142139        {
    143             if(!this->durationTimer_.isActive() && this->durationTimer_.getRemainingTime() > 0.0f)
     140            // If its durationType is continuous, we set a Timer to be reminded, when the time has run out.
     141            if(this->isContinuous())
    144142            {
    145                 this->durationTimer_.unpauseTimer();
    146             }
    147             else
    148             {
    149                 this->durationTimer_.setTimer(this->getDuration(), false, createExecutor(createFunctor(&SpeedPickup::pickupTimerCallback, this)));
    150             }
    151             engine->setSpeedAdd(this->getSpeedAdd());
    152             engine->setSpeedMultiply(this->getSpeedMultiply());
    153         }
    154         else
    155         {
    156             engine->setSpeedAdd(0.0f);
    157             engine->setSpeedMultiply(1.0f);
    158 
    159             if(this->isOnce())
    160             {
    161                 if(!this->durationTimer_.isActive() && this->durationTimer_.getRemainingTime() == this->getDuration())
     143                if(!this->durationTimer_.isActive() && this->durationTimer_.getRemainingTime() > 0.0f)
    162144                {
    163                     this->Pickupable::destroy();
     145                    this->durationTimer_.unpauseTimer();
    164146                }
    165147                else
    166148                {
    167                     this->durationTimer_.pauseTimer();
     149                    this->durationTimer_.setTimer(this->getDuration(), false, createExecutor(createFunctor(&SpeedPickup::pickupTimerCallback, this)));
    168150                }
     151            }
     152
     153            engine->setSpeedAdd(this->getSpeedAdd());
     154            engine->setSpeedMultiply(this->getSpeedMultiply());
     155        }
     156        else
     157        {
     158            engine->setSpeedAdd(0.0f);
     159            engine->setSpeedMultiply(1.0f);
     160
     161            // We destroy the pickup if either, the pickup has activationType immediate and durationType once or it has durationType continuous and the duration was exceeded.
     162            if((!this->isContinuous() && this->isImmediate()) || (this->isContinuous() && !this->durationTimer_.isActive() && this->durationTimer_.getRemainingTime() == this->getDuration()))
     163            {
     164                this->Pickupable::destroy();
     165            }
     166            // We pause the Timer if the pickup is continuous and the duration is not yet exceeded,
     167            else if(this->isContinuous() && this->durationTimer_.isActive())
     168            {
     169                this->durationTimer_.pauseTimer();
    169170            }
    170171        }
     
    213214    /**
    214215    @brief
    215         Sets the duration.
     216        Sets the duration for which the SpeedPickup stays active.
    216217    @param duration
    217         The duration
     218        The duration in seconds.
    218219    */
    219220    void SpeedPickup::setDuration(float duration)
     
    232233    /**
    233234    @brief
    234         Sets the SpeedAdd
     235        Sets the speedAdd, the value that is added to the speed of the Pawn.
    235236    @param speedAdd
    236         The added Speed
     237        The added speed.
    237238    */
    238239    void SpeedPickup::setSpeedAdd(float speedAdd)
     
    251252    /**
    252253    @brief
    253         Sets the SpeedMultiply
     254        Sets the speedMultiply, the factor by which the speed of the Pawn is multiplied.
    254255    @param speedMultiply
    255         The multiplied Speed
     256        The factor by which the speed is mutiplied.
    256257    */
    257258    void SpeedPickup::setSpeedMultiply(float speedMultiply)
  • code/trunk/src/modules/pickup/items/SpeedPickup.h

    r7493 r7547  
    3939
    4040#include <string>
    41 #include "worldentities/pawns/Pawn.h"
    42 #include "worldentities/StaticEntity.h"
    4341
    4442#include "pickup/Pickup.h"
     
    5048        A Pickup which can manipulate the Speed of a Pawn.
    5149
    52         There are 4 parameters that can be cosen:
    53         - The @b speed @b multiplier
    54         - The @b additional (forward) @b speed
    55         - The @b activation @b type 'immediate' or 'onUse'. defines if the item is used when it's picked up or only after the player chooses to use it.
    56         - The @b duration The activation time of the pickup.
     50        There are 5 parameters that can be cosen:
     51        - The @b speedMultiply, specifies a factor by which the Spaceships speed is multiplied. The default is 1.
     52        - The @b speedAdd, specifies a value that is added to the speed of the Spaceship. The default is 0.
     53        - The @b activationType <em>immediate</em> or <em>onUse</em>, defines if the SpeedPickup is used when it's picked up or only after the player chooses to use it. The default is <em>immediate</em>.
     54        - The @b durationType Can be either <em>once</em> or <em>continuous</em>. For <em>once</em> the SpeedPickup is just active for as long as it is used, for <em>continuous</em> the SpeedPickup is active only for the specified duration. The default is <em>once</em>.
     55        - The @b duration The time in seconds the SpeedPickup is active at the most. The default is 0.
     56
     57        An example, how a SpeedPickup could be defined in XML could be:
     58        @code
     59        <SpeedPickup
     60            speedMultiply = 2.0
     61            speedAdd = 10.0
     62            activationType = "immediate"
     63            durationType = "continuous"
     64            duration = 30.0
     65        />
     66        @endcode
    5767
    5868    @author
    5969        Eric Beier
     70
     71    @ingroup PickupItems
    6072    */
    6173    class _PickupExport SpeedPickup : public Pickup
     
    7183            virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input OrxonoxClass.
    7284
    73             inline float getDuration(void)
     85            /**
     86            @brief Get the duration, the time the SpeedPickup is active.
     87            @return Returns the duration in seconds.
     88            */
     89            inline float getDuration(void) const
    7490                { return this->duration_; }
    75             inline float getSpeedAdd(void)
     91            /**
     92            @brief Get the value that is added to the speed of the Pawn.
     93            @return Returns the speedAdd.
     94            */
     95            inline float getSpeedAdd(void) const
    7696                { return this->speedAdd_; }
    77             inline float getSpeedMultiply(void)
     97            /**
     98            @brief Get the factor by wich the speed of the Pawn is multplied.
     99            @return Returns the speedMultiply.
     100            */
     101            inline float getSpeedMultiply(void) const
    78102                { return this->speedMultiply_; }
    79103
    80104        protected:
    81105            void initializeIdentifier(void); //!< Initializes the PickupIdentifier of this pickup.
    82 
    83106            void pickupTimerCallback(void); //!< Function that gets called when timer ends.
    84107
    85             void setDuration(float duration);
    86             void setSpeedAdd(float speedAdd);
    87             void setSpeedMultiply(float speedMultiply);
     108            void setDuration(float duration); //!< Sets the duration.
     109            void setSpeedAdd(float speedAdd); //!< Sets the SpeedAdd, the value that is added to the speed of the Pawn.
     110            void setSpeedMultiply(float speedMultiply); //!< Sets the speedMultiply, the factor by which the speed of the Pawn is multiplied.
    88111
    89112        private:
     
    93116            Timer durationTimer_; //!< Timer.
    94117
    95             float duration_; //!< The health that is transferred to the Pawn.
    96             float speedAdd_;
    97             float speedMultiply_;
     118            float duration_; //!< The time in seconds for which the SpeedPickup stays active.
     119            float speedAdd_; //!< The value that is added to the speed of the Pawn.
     120            float speedMultiply_; //!< The factor by which the speed of the Pawn is multiplied.
    98121    };
    99122}
Note: See TracChangeset for help on using the changeset viewer.