| 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 | 
|---|
| 43 | namespace 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 | 
|---|
| 67 | { return 1; } | 
|---|
| 68 |  | 
|---|
| 69 | bool addTo(Pawn* pawn);             //!< Add the item to a pawn. | 
|---|
| 70 | bool removeFrom(Pawn* pawn);        //!< Removes the item from a pawn. | 
|---|
| 71 | /** | 
|---|
| 72 | @brief | 
|---|
| 73 | Method invoked when the item gets picked up. | 
|---|
| 74 |  | 
|---|
| 75 | Has to be overridden for an item to work, | 
|---|
| 76 | should contain a call to addTo(). | 
|---|
| 77 |  | 
|---|
| 78 | @param pawn Pawn who picks up the item. | 
|---|
| 79 | @return Returns whether the pawn was able to pick up the item. | 
|---|
| 80 | */ | 
|---|
| 81 | virtual bool pickedUp(Pawn* pawn) | 
|---|
| 82 | { return false; } | 
|---|
| 83 | /** | 
|---|
| 84 | @brief | 
|---|
| 85 | Method invoked when the item is dropped from a player. | 
|---|
| 86 |  | 
|---|
| 87 | Should be overridden by derived classes, | 
|---|
| 88 | should also contain a call to removeFrom(). | 
|---|
| 89 |  | 
|---|
| 90 | @param pawn Pawn which dropped the item. | 
|---|
| 91 | @return Returns whether the item was able to get dropped by the pawn. | 
|---|
| 92 | */ | 
|---|
| 93 | virtual bool dropped(Pawn* pawn) | 
|---|
| 94 | { return false; } | 
|---|
| 95 |  | 
|---|
| 96 | /** | 
|---|
| 97 | @brief Gets the current owner of the pickup. | 
|---|
| 98 | @return Returns the current owner. | 
|---|
| 99 | */ | 
|---|
| 100 | inline Pawn* getOwner() const | 
|---|
| 101 | { return this->owner_; } | 
|---|
| 102 | /** | 
|---|
| 103 | @brief Sets the owner of the pickup. | 
|---|
| 104 | @param owner New owner for the pickup. | 
|---|
| 105 | */ | 
|---|
| 106 | inline void setOwner(Pawn* owner) | 
|---|
| 107 | { this->owner_ = owner; } | 
|---|
| 108 |  | 
|---|
| 109 | /** | 
|---|
| 110 | @brief Gets the pickupIdentifier of the item. | 
|---|
| 111 | @return Returns the pickupIdentifier of the item. | 
|---|
| 112 | @see pickupIdentifier_ | 
|---|
| 113 | */ | 
|---|
| 114 | inline const std::string& getPickupIdentifier() const | 
|---|
| 115 | { return this->pickupIdentifier_; } | 
|---|
| 116 | /** | 
|---|
| 117 | @brief Sets the pickupIdentifier for the item. | 
|---|
| 118 | @param identifier New pickupIdentifier for the item. | 
|---|
| 119 | @see pickupIdentifier_ | 
|---|
| 120 | */ | 
|---|
| 121 | inline void setPickupIdentifier(const std::string& identifier) | 
|---|
| 122 | { this->pickupIdentifier_ = identifier; } | 
|---|
| 123 |  | 
|---|
| 124 | // GUI stuff | 
|---|
| 125 | virtual const std::string& getGUIText() const; // tolua_export | 
|---|
| 126 | inline void setGUIText(const std::string& text) | 
|---|
| 127 | { this->guiText_ = text; } | 
|---|
| 128 |  | 
|---|
| 129 | virtual const std::string& getGUIImage() const | 
|---|
| 130 | { return this->guiImage_; } | 
|---|
| 131 | inline void setGUIImage(const std::string& image) | 
|---|
| 132 | { this->guiImage_ = image; } | 
|---|
| 133 | private: | 
|---|
| 134 | Pawn* owner_;   //!< The current owner of the item. | 
|---|
| 135 |  | 
|---|
| 136 | /** | 
|---|
| 137 | @brief | 
|---|
| 138 | The pickupIdentifier of the item.. | 
|---|
| 139 |  | 
|---|
| 140 | Usually set to the template name used by a PickupSpawner, | 
|---|
| 141 | used to index items in the PickupCollection. | 
|---|
| 142 | */ | 
|---|
| 143 | std::string pickupIdentifier_; | 
|---|
| 144 |  | 
|---|
| 145 | std::string guiText_; | 
|---|
| 146 | std::string guiImage_; | 
|---|
| 147 | }; // tolua_export | 
|---|
| 148 | } // tolua_export | 
|---|
| 149 |  | 
|---|
| 150 | #endif /* _BaseItem_H__ */ | 
|---|