Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/pickup2/src/orxonox/interfaces/Pickupable.h @ 6445

Last change on this file since 6445 was 6405, checked in by dafrick, 15 years ago

Commit changes in pickup before merge.

File size: 7.3 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
31    @brief Definition of the Pickupable class.
32*/
33
34#ifndef _Pickupable_H__
35#define _Pickupable_H__
36
37#include "OrxonoxPrereqs.h"
38#include "core/OrxonoxClass.h"
39
40#include "core/Identifier.h"
41#include "core/Super.h"
42#include "interfaces/PickupCarrier.h"
43#include "worldentities/pawns/Pawn.h"
44#include <list>
45
46namespace orxonox
47{
48
49    //! Enum for the activation type.
50    namespace pickupActivationType
51    {
52        enum Value
53        {
54            immediate,
55            onUse,
56        };
57    }
58   
59    //! Enum for the duration tyoe.
60    namespace pickupDurationType
61    {
62        enum Value
63        {
64            once,
65            continuous,
66        };
67    }
68   
69    /**
70    @brief
71        An Interface (or more precisely an abstract Class) to model and manage different (all kinds of) pickups.
72    @author
73        Damian 'Mozork' Frick
74    */
75    //TODO: Add stuff like weight/space ?
76    class _OrxonoxExport Pickupable : virtual public OrxonoxClass
77    {
78        public:
79            Pickupable(); //!< Default constructor.
80            virtual ~Pickupable() {} //!< Default destructor.
81           
82            /**
83            @brief Get the activation type of the pickup.
84            @return Returns the activation type of the pickup.
85            */
86            inline pickupActivationType::Value getActivationType(void)
87                { return this->activationType_; }
88            /**
89            @brief Get the duration type of the pickup.
90            @return Returns the duration type of the pickup.
91            */
92            inline pickupDurationType::Value getDurationType(void)
93                { return this->durationType_; }
94               
95            /**
96            @brief Get the owner of the pickup.
97            @return Returns a pointer to the owner of the pickup.
98            */
99            inline PickupCarrier* getOwner(void)
100                { return this->owner_; }
101               
102            /**
103            @brief Get whether the pickup is currently in use or not.
104            @return Returns true if the pickup is currently in use.
105            */
106            inline bool isUsed(void)
107                { return this->used_; }
108               
109            /**
110            @brief Get whether the given pawn is a target of this pickup.
111            @param pawn The Pawn of which it has to be determinde whether it is a target of this pickup.
112            @return Retruns true if the given Pawn is a target.
113            */
114            //TODO: Determine whether Pawn includes all possible cases and if PickupCarrier wouldn't be better.
115            inline bool isTarget(Pawn* pawn)
116                {
117                    Identifier* identifier = pawn->getIdentifier();
118                    for(std::list<Identifier*>::iterator it = this->targets_.begin(); it != this->targets_.end(); it++)
119                    {
120                        if(identifier->isA(*it))
121                            return true;
122                    }
123                    return false;
124                }
125               
126            /**
127            @brief  Should be called when the pickup has transitetd from used to unused or the other way around.
128                    Any Class overwriting this method must call its SUPER function by adding SUPER(Classname, changedUsed); to their changeUsed method.
129            */
130            virtual inline void changedUsed(void)
131                {
132                    if(this->isUsed())
133                        this->used_ = false;
134                    else
135                        this->used_ = true;
136                }
137
138            /**
139            @brief  Sets the pickup to used and makes sure the effects of the pickup take effect at the right places.
140                    This method needs to be implemented by any Class inheriting from Pickupable.
141            @return Returns false if for some reason the method could not take effect, e.g. because it is already in use, or some other circumstance.
142            */
143            virtual bool use(void) = 0;
144            /**
145            @brief  Sets the pickup to unused and makes sure the effects of the pickup no longer take effect.
146                    This method needs to be implemented by any Class inheriting from Pickupable.
147            @return Returns false if for some reason the method could not take effect, e.g. because the pickup is already unused, or some other circumstance.
148            */
149            virtual bool unuse(void) = 0;
150           
151            /**
152            @brief  Adds the pickup to the input PickupCarrier.
153                    This method needs to be implemented by any Class inheriting from Pickupable.
154            @return Returns false if, for some reason, the pickup could not be picked up.
155            */
156            //TODO: Maybe better in PickupCarrier?
157            virtual bool pickup(PickupCarrier* carrier) = 0;
158            /**
159            @brief  Drops the pickup. Creates a PickupSpawner at the place the Pickup has been dropped.
160                    This method needs to be implemented by any Class inheriting from Pickupable.
161            @return Returns false if the pickup could not be dropped.
162            */
163            //TODO: Probably could be done here?
164            virtual bool drop(void) = 0;
165           
166            /**
167            @brief  Creates a duplicate of the pickup.
168                    This method needs to e implemented by any Class inheriting from Pickupable.
169            @return Returns the clone of this pickup as a pointer to a Pickupable.
170            */
171            //TODO: Would be nicer if standard case was implemented here.
172            virtual Pickupable* clone(void) = 0;
173           
174            /**
175            @brief Sets the owner of the pickup.
176            @param owner Sets the input PickupCarrier as the owner of the pickup.
177            */
178            //TODO: Protected? Check for NULL and return true/false?
179            inline void setOwner(PickupCarrier* owner)
180                { this->owner_ = owner; }
181           
182        private:
183           
184            pickupActivationType::Value activationType_; //!< The activation type of the Pickup.
185            pickupDurationType::Value durationType_; //!< The duration type of the pickup.
186           
187            bool used_; //!< Whether the pickup is currently in use or not.
188           
189            PickupCarrier* owner_; //!< The owner of the pickup.
190            std::list<Identifier*> targets_; //!< The possible targets of this pickup.
191
192    };
193   
194    SUPER_FUNCTION(10, Pickupable, changedUsed, true)
195}
196
197#endif /* _Pickupable_H__ */
Note: See TracBrowser for help on using the repository browser.