Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/objects/pickup/BaseItem.h @ 3251

Last change on this file since 3251 was 3196, checked in by rgrieder, 15 years ago

Merged pch branch back to trunk.

  • Property svn:eol-style set to native
File size: 4.7 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 *      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 <string>
40#include "core/BaseObject.h"
41
42// tolua_begin
43namespace orxonox
44{
45    /**
46        @brief
47            Base class for all items/pickups.
48
49            Provides common methods to be used in derived classes.
50        @author
51            Daniel 'Huty' Haggenmueller
52    */
53    class _OrxonoxExport BaseItem
54// tolua_end
55        : public BaseObject
56// tolua_begin
57    {
58// tolua_end
59    public:
60        BaseItem(BaseObject* creator);
61        virtual ~BaseItem();
62
63        virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);  //!< XMLPort
64
65        /**
66            @brief Checks how many instances of this item can be carried at a time.
67            @return How many of this item can be carried.
68        */
69        virtual int getMaxCarryAmount() const
70            { return 1; }
71
72        bool addTo(Pawn* pawn);             //!< Add the item to a pawn.
73        bool removeFrom(Pawn* pawn);        //!< Removes the item from a pawn.
74        /**
75            @brief
76                Method invoked when the item gets picked up.
77
78                Has to be overridden for an item to work,
79                should contain a call to addTo().
80
81            @param pawn Pawn who picks up the item.
82            @return Returns whether the pawn was able to pick up the item.
83        */
84        virtual bool pickedUp(Pawn* pawn)
85            { return false; }
86        /**
87            @brief
88                Method invoked when the item is dropped from a player.
89
90                Should be overridden by derived classes,
91                should also contain a call to removeFrom().
92
93            @param pawn Pawn which dropped the item.
94            @return Returns whether the item was able to get dropped by the pawn.
95        */
96        virtual bool dropped(Pawn* pawn)
97            { return false; }
98
99        /**
100            @brief Gets the current owner of the pickup.
101            @return Returns the current owner.
102        */
103        inline Pawn* getOwner() const
104            { return this->owner_; }
105        /**
106            @brief Sets the owner of the pickup.
107            @param owner New owner for the pickup.
108        */
109        inline void setOwner(Pawn* owner)
110            { this->owner_ = owner; }
111
112        /**
113            @brief Gets the pickupIdentifier of the item.
114            @return Returns the pickupIdentifier of the item.
115            @see pickupIdentifier_
116        */
117        inline const std::string& getPickupIdentifier() const
118            { return this->pickupIdentifier_; }
119        /**
120            @brief Sets the pickupIdentifier for the item.
121            @param identifier New pickupIdentifier for the item.
122            @see pickupIdentifier_
123        */
124        inline void setPickupIdentifier(const std::string& identifier)
125            { this->pickupIdentifier_ = identifier; }
126
127        // GUI stuff
128        virtual const std::string& getGUIText() const; // tolua_export
129        inline void setGUIText(const std::string& text)
130            { this->guiText_ = text; }
131
132        virtual const std::string& getGUIImage() const
133            { return this->guiImage_; }
134        inline void setGUIImage(const std::string& image)
135            { this->guiImage_ = image; }
136    private:
137        Pawn* owner_;   //!< The current owner of the item.
138
139        /**
140            @brief
141                The pickupIdentifier of the item..
142
143                Usually set to the template name used by a PickupSpawner,
144                used to index items in the PickupCollection.
145        */
146        std::string pickupIdentifier_;
147
148        std::string guiText_;
149        std::string guiImage_;
150    }; // tolua_export
151} // tolua_export
152
153#endif /* _BaseItem_H__ */
Note: See TracBrowser for help on using the repository browser.