Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/lastmanstanding/src/orxonox/interfaces/PickupCarrier.h @ 7585

Last change on this file since 7585 was 7456, checked in by dafrick, 14 years ago

Reviewing documentation fo Questsystem, moving documentation fully into doxygen.
Added some files to modules they belong to.

  • Property svn:eol-style set to native
File size: 7.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 PickupCarrier.h
31    @brief Definition of the PickupCarrier class.
32    @ingroup Pickup
33*/
34
35#ifndef _PickupCarrier_H__
36#define _PickupCarrier_H__
37
38#include "OrxonoxPrereqs.h"
39
40#include <list>
41#include <set>
42#include "Pickupable.h"
43#include "core/Identifier.h"
44#include "core/WeakPtr.h"
45
46#include "core/OrxonoxClass.h"
47
48namespace orxonox
49{
50
51    //! Forward-declarations.
52    class PickupManager;
53    class Pickup;
54    class HealthPickup;
55    class InvisiblePickup;
56    class MetaPickup;
57    class DronePickup;
58    class SpeedPickup;
59
60    /**
61    @brief
62        The PickupCarrier interface provides the means, for any class implementing it, to possess Pickupables.
63    @author
64        Damian 'Mozork' Frick
65    */
66    class _OrxonoxExport PickupCarrier : virtual public OrxonoxClass
67    {
68        //! So that the different Pickupables have full access to their PickupCarrier.
69        friend class Pickupable;
70        friend class PickupManager;
71        //! Friends.
72        friend class Pickup;
73        friend class HealthPickup;
74        friend class InvisiblePickup;
75        friend class MetaPickup;
76        friend class DronePickup;
77        friend class SpeedPickup;
78
79        public:
80            PickupCarrier(); //!< Constructor.
81            virtual ~PickupCarrier(); //!< Destructor.
82            void preDestroy(void);
83
84            /**
85            @brief Can be used to check whether the PickupCarrier or a child of his is a target ot the input Pickupable.
86            @param pickup A pointer to the Pickupable.
87            @return Returns true if the PickupCarrier or one of its children is a target, false if not.
88            */
89            bool isTarget(const Pickupable* pickup)
90                {
91                    if(pickup->isTarget(this)) //!< If the PickupCarrier itself is a target.
92                        return true;
93
94                    //! Go recursively through all children to check whether they are a target.
95                    std::vector<PickupCarrier*>* children = this->getCarrierChildren();
96                    for(std::vector<PickupCarrier*>::const_iterator it = children->begin(); it != children->end(); it++)
97                    {
98                        if((*it)->isTarget(pickup))
99                            return true;
100                    }
101
102                    children->clear();
103                    delete children;
104
105                    return false;
106                }
107
108            /**
109            @brief Get the carrier that is both a child of the PickupCarrier (or the PickupCarrier itself) and a target of the input Pickupable.
110            @param pickup A pounter to the Pickupable.
111            @return Returns a pointer to the PickupCarrier that is the target of the input Pickupable.
112            */
113            PickupCarrier* getTarget(const Pickupable* pickup)
114                {
115                    if(!this->isTarget(pickup))
116                        return NULL;
117
118                    if(pickup->isTarget(this)) //!< If the PickupCarrier itself is a target.
119                        return this;
120
121                    //! Go recursively through all children to check whether they are the target.
122                    std::vector<PickupCarrier*>* children = this->getCarrierChildren();
123                    for(std::vector<PickupCarrier*>::iterator it = children->begin(); it != children->end(); it++)
124                    {
125                        if(pickup->isTarget(*it))
126                            return *it;
127                    }
128
129                    children->clear();
130                    delete children;
131
132                    return NULL;
133                }
134
135            /**
136            @brief Get the (absolute) position of the PickupCarrier.
137                   This method needs to be implemented by any direct derivative class of PickupCarrier.
138            @return Returns the position as a Vector3.
139            */
140            virtual const Vector3& getCarrierPosition(void) = 0;
141
142        protected:
143            /**
144            @brief Get all direct children of this PickupSpawner.
145                   This method needs to be implemented by any direct derivative class of PickupCarrier.
146                   The returned list will be deleted by the methods calling this function.
147            @return Returns a pointer to a list of all direct children.
148            */
149            virtual std::vector<PickupCarrier*>* getCarrierChildren(void) = 0;
150            /**
151            @brief Get the parent of this PickupSpawner
152                   This method needs to be implemented by any direct derivative class of PickupCarrier.
153            @return Returns a pointer to the parent.
154            */
155            virtual PickupCarrier* getCarrierParent(void) = 0;
156
157            /**
158            @brief Get all Pickupables this PickupCarrier has.
159            @return  Returns the set of all Pickupables this PickupCarrier has.
160            */
161            std::set<Pickupable*>& getPickups(void)
162                { return this->pickups_; }
163
164        private:
165            std::set<Pickupable*> pickups_; //!< The list of Pickupables carried by this PickupCarrier.
166
167            /**
168            @brief Adds a Pickupable to the list of pickups that are carried by this PickupCarrier.
169            @param pickup A pointer to the pickup to be added.
170            @return Returns true if successfull, false if the Pickupable was already present.
171            */
172            bool addPickup(Pickupable* pickup)
173                {
174                    COUT(4) << "Adding Pickupable (&" << pickup << ") to PickupCarrier (&" << this << ")" << std::endl;
175                    return this->pickups_.insert(pickup).second;
176                }
177
178            /**
179            @brief Removes a Pickupable from the list of pickups that are carried by thsi PickupCarrier.
180            @param pickup A pointer to the pickup to be removed.
181            @return Returns true if successfull, false if the Pickupable was not present in the list.
182            */
183            bool removePickup(Pickupable* pickup)
184                {
185                    COUT(4) << "Removing Pickupable (&" << pickup << ") from PickupCarrier (&" << this << ")" << std::endl;
186                    return this->pickups_.erase(pickup) == 1;
187                }
188
189    };
190}
191
192#endif /* _PickupCarrier_H__ */
Note: See TracBrowser for help on using the repository browser.