Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 10, 2010, 4:23:29 PM (15 years ago)
Author:
benedict
Message:

did the shield pickup. upload for testing

Location:
code/branches/ppspickups3/src/modules/pickup/items
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/ppspickups3/src/modules/pickup/items/ShieldPickup.cc

    r6869 r6884  
    7171    /**
    7272    @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;
     87    }
     88   
     89    /**
     90    @brief
    7391        Initializes the member variables.
    7492    */
     
    7694    {
    7795        this->duration_ = 0.0f;
     96        this->shieldAbsorption_ = 0.0f;
     97        this->shieldHealth_ = 0.0f;
    7898
    7999        this->addTarget(ClassIdentifier<Engine>::getIdentifier());
     
    92112        this->pickupIdentifier_->addParameter(type1, val1);
    93113
    94 //         stream.clear();
    95 //         stream << this->getShieldAdd();
    96 //         std::string type2 = "ShieldAdd";
    97 //         std::string val2 = stream.str();
    98 //         this->pickupIdentifier_->addParameter(type2, val2);
     114        stream.clear();
     115        stream << this->getShieldHealth();
     116        std::string type2 = "ShieldHealth";
     117        std::string val2 = stream.str();
     118        this->pickupIdentifier_->addParameter(type2, val2);
     119       
     120        stream.clear();
     121        stream << this->getShieldAbsorption();
     122        std::string type3 = "ShieldAbsorption";
     123        std::string val3 = stream.str();
     124        this->pickupIdentifier_->addParameter(type3, val3);
    99125
    100126    }
     
    109135
    110136        XMLPortParam(ShieldPickup, "duration", setDuration, getDuration, xmlelement, mode);
     137        XMLPortParam(ShieldPickup, "shieldhealth", setShieldHealth, getShieldHealth, xmlelement, mode);
     138        XMLPortParam(ShieldPickup, "shieldabsorption", setShieldAbsorption, getShieldAbsorption, xmlelement, mode);
    111139
    112140        this->initializeIdentifier();
     
    124152        if(!this->isPickedUp())
    125153            return;
     154
     155        Pawn* pawn = this->carrierToPawnHelper();
     156        if(pawn == NULL)
     157            this->destroy();
     158
     159        //! If the pickup has transited to used.
     160        if(this->isUsed())
     161        {
     162            if(!this->getTimer()->isActive() && this->getTimer()->getRemainingTime() > 0.0f)
     163            {
     164                this->getTimer()->unpauseTimer();
     165            }
     166            else
     167            {
     168                this->startPickupTimer(this->getDuration());
     169            }
     170            pawn->setShieldAbsorption(this->getShieldAbsorption());
     171            pawn->setShieldHealth(this->getShieldHealth());
     172        }
     173        else
     174        {
     175            pawn->setShieldAbsorption(0.0f);
     176            this->setShieldHealth(pawn->getShieldHealth());
     177            pawn->setShieldHealth(0.0f);
     178
     179            if(this->isOnce())
     180            {
     181                if(!this->getTimer()->isActive() && this->getTimer()->getRemainingTime() == this->getDuration())
     182                {
     183                    this->destroy();
     184                }
     185                else
     186                {
     187                    this->getTimer()->pauseTimer();
     188                }
     189            }
     190        }
    126191    }
    127192
     
    141206        ShieldPickup* pickup = dynamic_cast<ShieldPickup*>(item);
    142207        pickup->setDuration(this->getDuration());
    143 
     208        pickup->setShieldAbsorption(this->getShieldAbsorption());
     209        pickup->setShieldHealth(this->getShieldHealth());
    144210        pickup->initializeIdentifier();
     211    }
     212
     213    /**
     214    @brief
     215    Sets the percentage the shield absorbs of the dealt damage.
     216    @param shieldAbsorption
     217    The shieldAbsorption. Has to be between 0 and 1
     218    */
     219    void ShieldPickup::setShieldAbsorption(float shieldAbsorption)
     220    {
     221        if (shieldAbsorption>=0 && shieldAbsorption<=1)
     222        {
     223            this->shieldAbsorption_=shieldAbsorption;
     224        }
     225        else
     226        {
     227            COUT(1) << "Invalid Absorption in ShieldPickup." << std::endl;
     228            this->shieldAbsorption_=0;
     229        }
     230    }
     231
     232    /**
     233    @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        }
    145249    }
    146250
  • code/branches/ppspickups3/src/modules/pickup/items/ShieldPickup.h

    r6869 r6884  
     1
    12/*
    23 *   ORXONOX - the hottest 3D action shooter ever to exist
     
    4950        A Pickup which can add a Shield to the Pawn.
    5051
    51         1) The Shield multiplier:
    52            The additional (forward) Shield:
    53         2) The activation type: 'immediate' or 'onUse'. defines if the item is used when it's picked up or only after the player chooses to use it.
     52        1) The percentage: The percentage the shield takes from the damage dealt to a Pawn
     53        2) The hit points: The amount of damage points a shield can teake before collapsing
     54        3) The activation type: 'immediate' or 'onUse'. defines if the item is used when it's picked up or only after the player chooses to use it.
    5455        4) The duration: the activation time of the pickup.
    5556
     
    7172            inline float getDuration(void)
    7273                { return this->duration_; }
    73 
     74            inline float getShieldHealth()
     75                { return this->shieldHealth_; }
     76            inline float getShieldAbsorption()
     77                { return this->shieldAbsorption_; }
    7478
    7579        protected:
    7680            void initializeIdentifier(void); //!< Initializes the PickupIdentifier of this pickup.
    77            
     81
    7882            virtual void pickupTimerCallback(void); //!< Function that gets called when timer ends.
    7983
    8084            void setDuration(float duration);
    81 
     85            void setShieldHealth(float shieldHealth);
     86            void setShieldAbsorption(float shieldAbsorption);
    8287
    8388        private:
    8489            void initialize(void); //!< Initializes the member variables.
    85             Engine* carrierToEngineHelper(void); //!< Helper to transform the PickupCarrier to a Pawn, and throw an error message if the conversion fails.
     90            Pawn* carrierToPawnHelper(void); //!< Helper to transform the PickupCarrier to a Pawn, and throw an error message if the conversion fails.
    8691
    8792            float duration_; //!< The health that is transferred to the Pawn.
     93            float shieldHealth_;
     94            float shieldAbsorption_; // Has to be between 0 and 1
     95
    8896    };
    8997}
Note: See TracChangeset for help on using the changeset viewer.