Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/hudelements/src/modules/pickup/items/HealthPickup.h @ 6849

Last change on this file since 6849 was 6540, checked in by dafrick, 15 years ago

Removed some TODO's. Finished up documenting pickup module.

File size: 6.1 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*/
33
34#ifndef _HealthPickup_H__
35#define _HealthPickup_H__
36
37#include "pickup/PickupPrereqs.h"
38
39#include <string>
40#include <worldentities/pawns/Pawn.h>
41#include "worldentities/StaticEntity.h"
42
43#include "pickup/Pickup.h"
44#include "tools/interfaces/Tickable.h"
45
46namespace orxonox {
47   
48    //! Enum for the type of the HealthPickup
49    namespace pickupHealthType
50    {
51        enum Value
52        {
53            limited,
54            temporary,
55            permanent
56        };
57    }
58   
59    /**
60    @brief
61        A pickup that can do (dependent upon the parameters) lots of different things to the health of a Pawn.
62        There are 4 parameters that can be chosen:
63        1) The health. The amount of health that (in a way dependent on the other parameters) is transfered to the Pawn.
64        2) The activation type: It can be chosen to be either 'immediate' or 'onUse'. The activation type essentially (as indicated by the name) defines when the health is transfered, either immediately after being picked up or only after the player uses it.
65        3) The duration type: It can be chosen to be either 'once' or 'continuous'. For 'once' the specified health is transfered once to the Pawn, for 'continuous' the set health is transfered over a span of time at a rate defined by the health rate parameter.
66        4) The health type: The health type can be chosen to be 'limited', 'temporary' or 'permanent'. 'limited' 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. 'permanent' 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.
67    @author
68        Damian 'Mozork' Frick
69    */
70    class _PickupExport HealthPickup : public Pickup, public Tickable
71    {
72        public:
73       
74            HealthPickup(BaseObject* creator); //!< Constructor.
75            virtual ~HealthPickup(); //!< Destructor.
76           
77            virtual void XMLPort(Element& xmlelement, orxonox::XMLPort::Mode mode); //!< Method for creating a HealthPickup object through XML.
78            virtual void tick(float dt); //!< Is called every tick.
79           
80            virtual void changedUsed(void); //!< Is called when the pickup has transited from used to unused or the other way around.
81            virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input OrxonoxClass.
82           
83            /**
84            @brief Get the health that is transfered to the Pawn upon usage of this pickup.
85            @return Returns the health.
86            */
87            inline float getHealth(void)
88                { return this->health_; }
89            /**
90            @brief Get the rate at which the health is transferred to the Pawn, if this pickup has duration type 'continuous'.
91            @return Returns the rate.
92            */
93            inline float getHealthRate(void)
94                { return this->healthRate_; }
95               
96            /**
97            @brief Get the type of HealthPickup, this pickup is.
98            @return Returns the health type as an enum.
99            */
100            inline pickupHealthType::Value getHealthTypeDirect(void)
101                { return this->healthType_; }
102            const std::string& getHealthType(void); //!< Get the health type of this pickup.
103           
104        protected:
105            void initializeIdentifier(void); //!< Initializes the PickupIdentifier of this pickup.
106
107            void setHealth(float health); //!< Sets the health.
108            void setHealthRate(float speed); //!< Set the rate at which health is transferred if the pickup is continuous.
109           
110            /**
111            @brief Set the health type of this pickup.
112            @param type The type of this pickup as an enum.
113            */
114            inline void setHealthTypeDirect(pickupHealthType::Value type)
115                { this->healthType_ = type; }
116            void setHealthType(std::string type); //!< Set the type of the HealthPickup.
117       
118        private:
119            void initialize(void); //!< Initializes the member variables.
120            Pawn* carrierToPawnHelper(void); //!< Helper to transform the PickupCarrier to a Pawn, and throw an error message if the conversion fails.
121           
122            float health_; //!< The health that is transferred to the Pawn.
123            float healthRate_; //!< The rate at which the health is transferred.
124            float maxHealthSave_; //!< Helper to remember what the actual maxHealth of the Pawn was before we changed it.
125            float maxHealthOverwrite_; //!< Helper to remember with which value we overwrote the maxHealh, to detect if someone else changed it as well.
126            pickupHealthType::Value healthType_; //!< The type of the HealthPickup.
127           
128            //! Strings for the health types.
129            static const std::string healthTypeLimited_s;
130            static const std::string healthTypeTemporary_s;
131            static const std::string healthTypePermanent_s;
132       
133    };
134}
135
136#endif // _HealthPickup_H__
Note: See TracBrowser for help on using the repository browser.