Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentation2012merge/src/modules/pickup/items/HealthPickup.h @ 9352

Last change on this file since 9352 was 9320, checked in by landauf, 12 years ago

removed Pickupable::clone() because it is not needed anymore

  • Property svn:eol-style set to native
File size: 7.0 KB
RevLine 
[6474]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Damian 'Mozork' Frick
24 *   Co-authors:
25 *      ...
26 *
27 */
28
[6540]29/**
30    @file HealthPickup.h
31    @brief Declaration of the HealthPickup class.
[7456]32    @ingroup PickupItems
[6540]33*/
34
[6474]35#ifndef _HealthPickup_H__
36#define _HealthPickup_H__
37
38#include "pickup/PickupPrereqs.h"
39
[6477]40#include <string>
41
[6474]42#include "pickup/Pickup.h"
43#include "tools/interfaces/Tickable.h"
44
45namespace orxonox {
[7163]46
[7541]47    /**
48    @brief
49        Enum for the type of the @ref orxonox::HealthPickup "HealthPickup".
50
51    @ingroup PickupItems
52    */
[6474]53    namespace pickupHealthType
54    {
55        enum Value
56        {
[7541]57            limited, //!< Means that the @ref orxonox::HealthPickup "HealthPickup" only increases the users health to its maximum health.
58            temporary, //!< Means that the @ref orxonox::HealthPickup "HealthPickup" temporarily increases the users health even above its maximum health, but only as long as it is in use.
59            permanent //!< Means that the @ref orxonox::HealthPickup "HealthPickup" increases the users health even above its maximum health and increases the maximum health permanently such that it matches the new health.
[6474]60        };
61    }
[7163]62
[6477]63    /**
64    @brief
[7547]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.
[7541]72
[7547]73        An example of a XML implementation of a HealthPickup would be:
[7541]74        @code
75        <HealthPickup
[7551]76            health = 50
[7541]77            healthType = "limited"
78            activationType = "immediate"
79            durationType = "once"
80        />
81        @endcode
82
[6477]83    @author
84        Damian 'Mozork' Frick
[7541]85
86    @ingroup PickupItems
[6477]87    */
[6474]88    class _PickupExport HealthPickup : public Pickup, public Tickable
89    {
90        public:
[7163]91
[6477]92            HealthPickup(BaseObject* creator); //!< Constructor.
93            virtual ~HealthPickup(); //!< Destructor.
[7163]94
[6477]95            virtual void XMLPort(Element& xmlelement, orxonox::XMLPort::Mode mode); //!< Method for creating a HealthPickup object through XML.
96            virtual void tick(float dt); //!< Is called every tick.
[7163]97
[6477]98            virtual void changedUsed(void); //!< Is called when the pickup has transited from used to unused or the other way around.
[7163]99
[6477]100            /**
[7541]101            @brief Get the health that is transferred to the Pawn upon usage of this pickup.
[6477]102            @return Returns the health.
103            */
[7547]104            inline float getHealth(void) const
[6477]105                { return this->health_; }
106            /**
107            @brief Get the rate at which the health is transferred to the Pawn, if this pickup has duration type 'continuous'.
108            @return Returns the rate.
109            */
[7547]110            inline float getHealthRate(void) const
[6477]111                { return this->healthRate_; }
[7163]112
[6477]113            /**
114            @brief Get the type of HealthPickup, this pickup is.
[7163]115            @return Returns the health type as an enum.
[6477]116            */
[9312]117            inline pickupHealthType::Value getHealthType(void) const
[6477]118                { return this->healthType_; }
[9312]119            const std::string& getHealthTypeAsString(void) const; //!< Get the health type of this pickup.
[7163]120
[6474]121        protected:
[6477]122            void setHealth(float health); //!< Sets the health.
123            void setHealthRate(float speed); //!< Set the rate at which health is transferred if the pickup is continuous.
[7163]124
[6477]125            /**
126            @brief Set the health type of this pickup.
127            @param type The type of this pickup as an enum.
128            */
[9312]129            inline void setHealthType(pickupHealthType::Value type)
[6474]130                { this->healthType_ = type; }
[9312]131            void setHealthTypeAsString(const std::string& type); //!< Set the type of the HealthPickup.
[7163]132
[6474]133        private:
[6477]134            void initialize(void); //!< Initializes the member variables.
135            Pawn* carrierToPawnHelper(void); //!< Helper to transform the PickupCarrier to a Pawn, and throw an error message if the conversion fails.
[7163]136
[6477]137            float health_; //!< The health that is transferred to the Pawn.
138            float healthRate_; //!< The rate at which the health is transferred.
139            float maxHealthSave_; //!< Helper to remember what the actual maxHealth of the Pawn was before we changed it.
140            float maxHealthOverwrite_; //!< Helper to remember with which value we overwrote the maxHealh, to detect if someone else changed it as well.
141            pickupHealthType::Value healthType_; //!< The type of the HealthPickup.
[7163]142
[6477]143            //! Strings for the health types.
[6474]144            static const std::string healthTypeLimited_s;
145            static const std::string healthTypeTemporary_s;
146            static const std::string healthTypePermanent_s;
[7163]147
[6474]148    };
149}
150
151#endif // _HealthPickup_H__
Note: See TracBrowser for help on using the repository browser.