Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/pickup3/src/orxonox/pickup/BaseItem.h @ 6466

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

Merged pickup2 into pickup3.

  • Property svn:eol-style set to native
File size: 5.2 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 : public BaseObject
54    {
55// tolua_end
56        public:
57            BaseItem(BaseObject* creator);
58            virtual ~BaseItem();
59
60            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);  //!< XMLPort
61
62            /**
63            @brief Checks how many instances of this item can be carried at a time.
64            @return How many of this item can be carried.
65            */
66            virtual int getMaxCarryAmount() const //TODO: Maybe, better to just be virtual.
67                { return BaseItem::MAX_CARRY_AMOUNT; }
68
69            //TODO: Need to be public?
70            bool addTo(Pawn* pawn);             //!< Add the item to a pawn.
71            bool removeFrom(Pawn* pawn);        //!< Removes the item from a pawn.
72            /**
73            @brief
74                Method invoked when the item gets picked up.
75
76                Has to be overridden for an item to work,
77                should contain a call to addTo().
78
79            @param pawn Pawn who picks up the item.
80            @return Returns whether the pawn was able to pick up the item.
81            */
82            virtual bool pickedUp(Pawn* pawn) //TODO: Maybe better to be just virtual.
83                { return false; }
84            /**
85            @brief
86                Method invoked when the item is dropped from a player.
87
88                Should be overridden by derived classes,
89                should also contain a call to removeFrom().
90
91            @param pawn Pawn which dropped the item.
92            @return Returns whether the item was able to get dropped by the pawn.
93            */
94            virtual bool dropped(Pawn* pawn)
95                { return false; }
96
97            /**
98            @brief Gets the current owner of the pickup.
99            @return Returns the current owner.
100            */
101            inline Pawn* getOwner() const
102                { return this->owner_; }
103            /**
104            @brief Sets the owner of the pickup.
105            @param owner New owner for the pickup.
106            */
107            inline void setOwner(Pawn* owner)
108                { this->owner_ = owner; }
109
110            /**
111            @brief Gets the pickupIdentifier of the item.
112            @return Returns the pickupIdentifier of the item.
113            @see pickupIdentifier_
114            */
115            inline const std::string& getPickupIdentifier() const
116                { return this->pickupIdentifier_; }
117            /**
118            @brief Sets the pickupIdentifier for the item.
119            @param identifier New pickupIdentifier for the item.
120            @see pickupIdentifier_
121            */
122            //TODO: Needs to be public?
123            inline void setPickupIdentifier(const std::string& identifier)
124                { this->pickupIdentifier_ = identifier; }
125
126            // GUI stuff
127            //TODO: Comment. Maybe seperate GUI from Pickup, e.g. ItemDescription...
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            static const int MAX_CARRY_AMOUNT = 1;
138
139            Pawn* owner_;   //!< The current owner of the item.
140
141            /**
142            @brief
143                The pickupIdentifier of the item..
144
145                Usually set to the template name used by a PickupSpawner,
146                used to index items in the PickupCollection.
147            */
148            std::string pickupIdentifier_; //TODO: Remove, when always just this->getName().
149
150            //TODO: Comment.
151            std::string guiText_;
152            std::string guiImage_;
153    }; // tolua_export
154} // tolua_export
155
156#endif /* _BaseItem_H__ */
Note: See TracBrowser for help on using the repository browser.