Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/pickup/items/HealthPickup.h @ 7546

Last change on this file since 7546 was 7541, checked in by dafrick, 14 years ago

Some more documentation.

  • Property svn:eol-style set to native
File size: 7.0 KB
Line 
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
29/**
30    @file HealthPickup.h
31    @brief Declaration of the HealthPickup class.
32    @ingroup PickupItems
33*/
34
35#ifndef _HealthPickup_H__
36#define _HealthPickup_H__
37
38#include "pickup/PickupPrereqs.h"
39
40#include <string>
41#include <worldentities/pawns/Pawn.h>
42#include "worldentities/StaticEntity.h"
43
44#include "pickup/Pickup.h"
45#include "tools/interfaces/Tickable.h"
46
47namespace orxonox {
48
49    /**
50    @brief
51        Enum for the type of the @ref orxonox::HealthPickup "HealthPickup".
52
53    @ingroup PickupItems
54    */
55    namespace pickupHealthType
56    {
57        enum Value
58        {
59            limited, //!< Means that the @ref orxonox::HealthPickup "HealthPickup" only increases the users health to its maximum health.
60            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.
61            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.
62        };
63    }
64
65    /**
66    @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.
73
74        An examle of a XML implementation of a HealthPickup would be:
75        @code
76        <HealthPickup
77            health = 33
78            healthType = "limited"
79            activationType = "immediate"
80            durationType = "once"
81        />
82        @endcode
83
84    @author
85        Damian 'Mozork' Frick
86
87    @ingroup PickupItems
88    */
89    class _PickupExport HealthPickup : public Pickup, public Tickable
90    {
91        public:
92
93            HealthPickup(BaseObject* creator); //!< Constructor.
94            virtual ~HealthPickup(); //!< Destructor.
95
96            virtual void XMLPort(Element& xmlelement, orxonox::XMLPort::Mode mode); //!< Method for creating a HealthPickup object through XML.
97            virtual void tick(float dt); //!< Is called every tick.
98
99            virtual void changedUsed(void); //!< Is called when the pickup has transited from used to unused or the other way around.
100            virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input OrxonoxClass.
101
102            /**
103            @brief Get the health that is transferred to the Pawn upon usage of this pickup.
104            @return Returns the health.
105            */
106            inline float getHealth(void)
107                { return this->health_; }
108            /**
109            @brief Get the rate at which the health is transferred to the Pawn, if this pickup has duration type 'continuous'.
110            @return Returns the rate.
111            */
112            inline float getHealthRate(void)
113                { return this->healthRate_; }
114
115            /**
116            @brief Get the type of HealthPickup, this pickup is.
117            @return Returns the health type as an enum.
118            */
119            inline pickupHealthType::Value getHealthTypeDirect(void)
120                { return this->healthType_; }
121            const std::string& getHealthType(void); //!< Get the health type of this pickup.
122
123        protected:
124            void initializeIdentifier(void); //!< Initializes the PickupIdentifier of this pickup.
125
126            void setHealth(float health); //!< Sets the health.
127            void setHealthRate(float speed); //!< Set the rate at which health is transferred if the pickup is continuous.
128
129            /**
130            @brief Set the health type of this pickup.
131            @param type The type of this pickup as an enum.
132            */
133            inline void setHealthTypeDirect(pickupHealthType::Value type)
134                { this->healthType_ = type; }
135            void setHealthType(std::string type); //!< Set the type of the HealthPickup.
136
137        private:
138            void initialize(void); //!< Initializes the member variables.
139            Pawn* carrierToPawnHelper(void); //!< Helper to transform the PickupCarrier to a Pawn, and throw an error message if the conversion fails.
140
141            float health_; //!< The health that is transferred to the Pawn.
142            float healthRate_; //!< The rate at which the health is transferred.
143            float maxHealthSave_; //!< Helper to remember what the actual maxHealth of the Pawn was before we changed it.
144            float maxHealthOverwrite_; //!< Helper to remember with which value we overwrote the maxHealh, to detect if someone else changed it as well.
145            pickupHealthType::Value healthType_; //!< The type of the HealthPickup.
146
147            //! Strings for the health types.
148            static const std::string healthTypeLimited_s;
149            static const std::string healthTypeTemporary_s;
150            static const std::string healthTypePermanent_s;
151
152    };
153}
154
155#endif // _HealthPickup_H__
Note: See TracBrowser for help on using the repository browser.