Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Documenting and cleanup.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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    {
Note: See TracChangeset for help on using the changeset viewer.