Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/pickup3/src/orxonox/interfaces/PickupCarrier.h @ 6466

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

Lots of things done in pickups module. Compiles, but it seems, that I've also introduced an error preventing steering of the spaceship.

File size: 3.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
31    @brief Definition of the PickupCarrier class.
32*/
33
34#ifndef _PickupCarrier_H__
35#define _PickupCarrier_H__
36
37#include "OrxonoxPrereqs.h"
38#include "core/OrxonoxClass.h"
39#include "Pickupable.h"
40
41#include <set>
42#include <list>
43
44namespace orxonox
45{
46
47    class _OrxonoxExport PickupCarrier : virtual public OrxonoxClass
48    {
49        friend class Pickupable;
50       
51        public:
52            PickupCarrier();
53            virtual ~PickupCarrier() {}
54           
55            //TODO: Secure uniqueness of each item in the set, if neccessary, check.
56            inline bool pickup(Pickupable* pickup)
57                {
58                    bool pickedUp = this->pickups_.insert(pickup).second;
59                    if(pickedUp) pickup->pickedUp(this);
60                    return pickedUp;
61                }
62               
63            inline bool drop(Pickupable* pickup)
64                { 
65                   bool dropped = this->pickups_.erase(pickup) == 1;
66                   if(dropped)
67                   {
68                       pickup->dropped();
69                        //TODO: Create Spawner.
70                   }
71                   return dropped;
72                }
73               
74            inline bool isTarget(Pickupable* pickup)
75                {
76                    if(pickup->isTarget(this))
77                        return true;
78                    const std::list<PickupCarrier*>* children = this->getChildren();
79                    for(std::list<PickupCarrier*>::const_iterator it = children->begin(); it != children->end(); it++)
80                    {
81                        if((*it)->isTarget(pickup))
82                            return true;
83                    }
84                   
85                    return false;
86                }
87           
88        protected:           
89            //TODO: Good return type?
90            virtual const std::list<PickupCarrier*>* getChildren(void) = 0;
91            virtual PickupCarrier* getParent(void) = 0;
92       
93        private:
94            std::set<Pickupable*> pickups_;
95           
96       
97    };
98   
99}
100
101#endif /* _PickupCarrier_H__ */
Note: See TracBrowser for help on using the repository browser.