| [2917] | 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 Implementation of BaseItem (base-class for items/pickups). | 
|---|
 | 32 | */ | 
|---|
 | 33 |  | 
|---|
 | 34 | #include "BaseItem.h" | 
|---|
 | 35 |  | 
|---|
 | 36 | #include "PickupCollection.h" | 
|---|
| [2972] | 37 |  | 
|---|
 | 38 | #include "core/CoreIncludes.h" | 
|---|
 | 39 | #include "core/XMLPort.h" | 
|---|
| [2917] | 40 | #include "objects/worldentities/pawns/Pawn.h" | 
|---|
 | 41 |  | 
|---|
 | 42 | namespace orxonox | 
|---|
 | 43 | { | 
|---|
 | 44 |     /** | 
|---|
 | 45 |         @brief Constructor. Registers the BaseItem. | 
|---|
 | 46 |         @param creator Pointer to the object which created this item. | 
|---|
 | 47 |     */ | 
|---|
 | 48 |     BaseItem::BaseItem(BaseObject* creator) : BaseObject(creator) | 
|---|
 | 49 |     { | 
|---|
 | 50 |         RegisterObject(BaseItem); | 
|---|
 | 51 |  | 
|---|
 | 52 |         this->setOwner(0); | 
|---|
 | 53 |         this->setPickupIdentifier(this->getName()); | 
|---|
| [3001] | 54 |         this->setGUIImage(""); | 
|---|
 | 55 |         this->setGUIText(""); | 
|---|
| [2917] | 56 |     } | 
|---|
 | 57 |     //! Deconstructor. | 
|---|
 | 58 |     BaseItem::~BaseItem() | 
|---|
 | 59 |     { | 
|---|
 | 60 |     } | 
|---|
| [2972] | 61 |  | 
|---|
| [2917] | 62 |     /** | 
|---|
| [2972] | 63 |         @brief XMLPort for BaseItem. | 
|---|
 | 64 |         @param xmlelement Element of the XML-file. | 
|---|
 | 65 |         @param mode XMLPort mode to use. | 
|---|
 | 66 |     */ | 
|---|
 | 67 |     void BaseItem::XMLPort(Element& xmlelement, XMLPort::Mode mode) | 
|---|
 | 68 |     { | 
|---|
 | 69 |         SUPER(BaseItem, XMLPort, xmlelement, mode); | 
|---|
 | 70 |  | 
|---|
 | 71 |         XMLPortParam(BaseItem, "guiText", setGUIText, getGUIText, xmlelement, mode); | 
|---|
 | 72 |         XMLPortParam(BaseItem, "guiImage", setGUIImage, getGUIImage, xmlelement, mode); | 
|---|
 | 73 |     } | 
|---|
 | 74 |  | 
|---|
 | 75 |     /** | 
|---|
| [2917] | 76 |         @brief Method to add the item to a pawn. | 
|---|
 | 77 |         @param pawn Pawn to which the item should get added. | 
|---|
 | 78 |         @return Returns whether the pawn's PickupCollection accepted the item. | 
|---|
 | 79 |     */ | 
|---|
 | 80 |     bool BaseItem::addTo(Pawn* pawn) | 
|---|
 | 81 |     { | 
|---|
 | 82 |         this->setOwner(pawn); | 
|---|
 | 83 |  | 
|---|
 | 84 |         if (pawn->getPickups().add(this)) | 
|---|
 | 85 |         { | 
|---|
 | 86 |             COUT(3) << "Added '" << this->getPickupIdentifier() << "' item." << std::endl; | 
|---|
 | 87 |             return true; | 
|---|
 | 88 |         } | 
|---|
 | 89 |         return false; | 
|---|
 | 90 |     } | 
|---|
 | 91 |     /** | 
|---|
 | 92 |         @brief Removes the item from a pawn. | 
|---|
 | 93 |         @param pawn Pawn from which to remove the item. | 
|---|
 | 94 |         @return Returns whether the pawn's PickupCollection was able to locate and remove the item. | 
|---|
 | 95 |     */ | 
|---|
 | 96 |     bool BaseItem::removeFrom(Pawn* pawn) | 
|---|
 | 97 |     { | 
|---|
 | 98 |         this->setOwner(0); | 
|---|
 | 99 |  | 
|---|
 | 100 |         COUT(3) << "Removing '" << this->getPickupIdentifier() << "' item." << std::endl; | 
|---|
 | 101 |  | 
|---|
 | 102 |         pawn->getPickups().remove(this, false); | 
|---|
 | 103 |  | 
|---|
 | 104 |         return true; | 
|---|
 | 105 |     } | 
|---|
| [3001] | 106 |  | 
|---|
 | 107 |     const std::string& BaseItem::getGUIText() const { return this->guiText_; } | 
|---|
| [2917] | 108 | } | 
|---|