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" |
---|
37 | #include "objects/worldentities/pawns/Pawn.h" |
---|
38 | |
---|
39 | namespace orxonox |
---|
40 | { |
---|
41 | /** |
---|
42 | @brief Constructor. Registers the BaseItem. |
---|
43 | @param creator Pointer to the object which created this item. |
---|
44 | */ |
---|
45 | BaseItem::BaseItem(BaseObject* creator) : BaseObject(creator) |
---|
46 | { |
---|
47 | RegisterObject(BaseItem); |
---|
48 | |
---|
49 | this->setOwner(0); |
---|
50 | this->setPickupIdentifier(this->getName()); |
---|
51 | } |
---|
52 | //! Deconstructor. |
---|
53 | BaseItem::~BaseItem() |
---|
54 | { |
---|
55 | } |
---|
56 | /** |
---|
57 | @brief Method to add the item to a pawn. |
---|
58 | @param pawn Pawn to which the item should get added. |
---|
59 | @return Returns whether the pawn's PickupCollection accepted the item. |
---|
60 | */ |
---|
61 | bool BaseItem::addTo(Pawn* pawn) |
---|
62 | { |
---|
63 | this->setOwner(pawn); |
---|
64 | |
---|
65 | COUT(3) << "Adding '" << this->getPickupIdentifier() << "' item." << std::endl; |
---|
66 | |
---|
67 | return pawn->getPickups().add(this); |
---|
68 | } |
---|
69 | /** |
---|
70 | @brief Removes the item from a pawn. |
---|
71 | @param pawn Pawn from which to remove the item. |
---|
72 | @return Returns whether the pawn's PickupCollection was able to locate and remove the item. |
---|
73 | */ |
---|
74 | bool BaseItem::removeFrom(Pawn* pawn) |
---|
75 | { |
---|
76 | this->setOwner(0); |
---|
77 | |
---|
78 | COUT(3) << "Removing '" << this->getPickupIdentifier() << "' item." << std::endl; |
---|
79 | |
---|
80 | pawn->getPickups().remove(this, false); |
---|
81 | |
---|
82 | return true; |
---|
83 | } |
---|
84 | } |
---|