Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/pickups2/src/orxonox/objects/pickup/BaseItem.h @ 3070

Last change on this file since 3070 was 3001, checked in by danielh, 16 years ago
  • Added helper method to HumanController to get it's ControllableEntity as a Pawn
  • Removed tooltip, added default (empty) values for text and image from BaseItem
  • Fixed tolua in BaseItem.h
  • Added object to PickupCollection for the current UsableItem
  • Moved most inventory logic from Lua to PickupInventory (still slow)

TODO

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