Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/pickups/src/orxonox/objects/pickup/BaseItem.h @ 2955

Last change on this file since 2955 was 2864, checked in by danielh, 16 years ago

first commit of pickup system

  • working PickupCollection
  • working PickupSpawner
  • base classes for items
  • updated Pawn to include PickupCollection
  • updated Projectile to use damage modifier on hit
File size: 4.2 KB
RevLine 
[2864]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 *      Daniel 'Huty' Haggenmueller
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29/**
30    @file
31    @brief Definition of BaseItem (base-class for items/pickups).
32*/
33
34#ifndef _BaseItem_H__
35#define _BaseItem_H__
36
37#include "OrxonoxPrereqs.h"
38
39#include "core/BaseObject.h"
40
41namespace orxonox
42{
43    /**
44        @brief
45            Base class for all items/pickups.
46
47            Provides common methods to be used in derived classes.
48        @author
49            Daniel 'Huty' Haggenmueller
50    */
51    class _OrxonoxExport BaseItem : public BaseObject
52    {
53    public:
54        BaseItem(BaseObject* creator);
55        virtual ~BaseItem();
56
57        /**
58            @brief Checks how many instances of this item can be carried at a time.
59            @return How many of this item can be carried.
60        */
61        virtual int getMaxCarryAmount() const
62            { return 1; }
63
64        bool addTo(Pawn* pawn);             //!< Add the item to a pawn.
65        bool removeFrom(Pawn* pawn);        //!< Removes the item from a pawn.
66        /**
67            @brief
68                Method invoked when the item gets picked up.
69
70                Has to be overridden for an item to work,
71                should contain a call to addTo().
72
73            @param pawn Pawn who picks up the item.
74            @return Returns whether the pawn was able to pick up the item.
75        */
76        virtual bool pickedUp(Pawn* pawn)
77            { return false; }
78        /**
79            @brief
80                Method invoked when the item is dropped from a player.
81
82                Should be overridden by derived classes,
83                should also contain a call to removeFrom().
84
85            @param pawn Pawn which dropped the item.
86            @return Returns whether the item was able to get dropped by the pawn.
87        */
88        virtual bool dropped(Pawn* pawn)
89            { return false; }
90
91        /**
92            @brief Gets the current owner of the pickup.
93            @return Returns the current owner.
94        */
95        inline Pawn* getOwner() const
96            { return this->owner_; }
97        /**
98            @brief Sets the owner of the pickup.
99            @param owner New owner for the pickup.
100        */
101        inline void setOwner(Pawn* owner)
102            { this->owner_ = owner; }
103
104        /**
105            @brief Gets the pickupIdentifier of the item.
106            @return Returns the pickupIdentifier of the item.
107            @see pickupIdentifier_
108        */
109        inline const std::string& getPickupIdentifier() const
110            { return this->pickupIdentifier_; }
111        /**
112            @brief Sets the pickupIdentifier for the item.
113            @param identifier New pickupIdentifier for the item.
114            @see pickupIdentifier_
115        */
116        inline void setPickupIdentifier(const std::string& identifier)
117            { this->pickupIdentifier_ = identifier; }
118    private:
119        Pawn* owner_;   //!< The current owner of the item.
120
121        /**
122            @brief
123                The pickupIdentifier of the item..
124
125                Usually set to the template name used by a PickupSpawner,
126                used to index items in the PickupCollection.
127        */
128        std::string pickupIdentifier_;
129    };
130}
131
132#endif /* _BaseItem_H__ */
Note: See TracBrowser for help on using the repository browser.