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 | * Damian 'Mozork' Frick |
---|
24 | * Co-authors: |
---|
25 | * ... |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | /** |
---|
30 | @file CollectiblePickup.cc |
---|
31 | @brief Implementation of the CollectiblePickup class. |
---|
32 | */ |
---|
33 | |
---|
34 | #include "CollectiblePickup.h" |
---|
35 | |
---|
36 | #include "core/CoreIncludes.h" |
---|
37 | #include "PickupCollection.h" |
---|
38 | |
---|
39 | namespace orxonox { |
---|
40 | |
---|
41 | /** |
---|
42 | @brief |
---|
43 | Constructor. |
---|
44 | Registers the object and initializes variables. |
---|
45 | */ |
---|
46 | CollectiblePickup::CollectiblePickup() : isInCollection_(false) |
---|
47 | { |
---|
48 | RegisterObject(CollectiblePickup); |
---|
49 | |
---|
50 | this->collection_ = NULL; |
---|
51 | } |
---|
52 | |
---|
53 | /** |
---|
54 | @brief |
---|
55 | Destructor. |
---|
56 | */ |
---|
57 | CollectiblePickup::~CollectiblePickup() |
---|
58 | { |
---|
59 | |
---|
60 | } |
---|
61 | |
---|
62 | /** |
---|
63 | @brief |
---|
64 | Is called by OrxonoxClass::destroy() before the object is actually destroyed. |
---|
65 | */ |
---|
66 | void CollectiblePickup::preDestroy(void) |
---|
67 | { |
---|
68 | this->Pickupable::preDestroy(); |
---|
69 | |
---|
70 | // The PickupCollection has to be destroyed as well. |
---|
71 | if(this->isInCollection()) |
---|
72 | this->collection_->Pickupable::destroy(); |
---|
73 | } |
---|
74 | |
---|
75 | /** |
---|
76 | @brief |
---|
77 | Destroys a Pickupable. |
---|
78 | */ |
---|
79 | void CollectiblePickup::destroyPickup(void) |
---|
80 | { |
---|
81 | if(!this->isInCollection()) // If the CollectiblePickup is not in a PickupCollection the destroyPickup method of Pickupable is called. |
---|
82 | this->Pickupable::destroyPickup(); |
---|
83 | else // Else the ColectiblePickup is dropped and disabled, |
---|
84 | { |
---|
85 | this->drop(false); |
---|
86 | if(this->isInCollection() && this->isEnabled()) // It is only disabled if it is enabled and still ina PickupCollection after having been dropped. |
---|
87 | { |
---|
88 | this->setDisabled(); |
---|
89 | this->collection_->pickupDisabled(); |
---|
90 | } |
---|
91 | } |
---|
92 | } |
---|
93 | |
---|
94 | /** |
---|
95 | @brief |
---|
96 | Is called by the PickupCarrier when it is being destroyed. |
---|
97 | */ |
---|
98 | void CollectiblePickup::carrierDestroyed(void) |
---|
99 | { |
---|
100 | if(!this->isInCollection()) |
---|
101 | this->Pickupable::destroy(); |
---|
102 | else // If the CollectiblePickup is part of a PickupCollection it is just dropped instead of destroyed. |
---|
103 | this->drop(false); |
---|
104 | } |
---|
105 | |
---|
106 | /** |
---|
107 | @brief |
---|
108 | Is called when the pickup has transited from used to unused or the other way around. |
---|
109 | */ |
---|
110 | void CollectiblePickup::changedUsed(void) |
---|
111 | { |
---|
112 | SUPER(CollectiblePickup, changedUsed); |
---|
113 | |
---|
114 | if(this->isInCollection()) |
---|
115 | this->collection_->pickupChangedUsed(this->isUsed()); |
---|
116 | } |
---|
117 | |
---|
118 | /** |
---|
119 | @brief |
---|
120 | Is called when the pickup has transited from picked up to dropped or the other way around. |
---|
121 | */ |
---|
122 | void CollectiblePickup::changedPickedUp(void) |
---|
123 | { |
---|
124 | SUPER(CollectiblePickup, changedPickedUp); |
---|
125 | |
---|
126 | if(this->isInCollection()) |
---|
127 | this->collection_->pickupChangedPickedUp(this->isPickedUp()); |
---|
128 | } |
---|
129 | |
---|
130 | /** |
---|
131 | @brief |
---|
132 | Adds this CollectiblePickup to the input PickupCollection. |
---|
133 | @param collection |
---|
134 | A pointer to the PickupCollection to which the CollectiblePickup should be added. |
---|
135 | @return |
---|
136 | Returns true if the CollectiblePickup was successfully added to the PickupCollection. |
---|
137 | */ |
---|
138 | bool CollectiblePickup::addToCollection(PickupCollection* collection) |
---|
139 | { |
---|
140 | if(this->isInCollection() || collection == NULL) //If the CollectiblePickup already is in a PickupCollection or if the input pointer is NULL. |
---|
141 | return false; |
---|
142 | |
---|
143 | this->isInCollection_ = true; |
---|
144 | this->collection_ = collection; |
---|
145 | return true; |
---|
146 | } |
---|
147 | |
---|
148 | /** |
---|
149 | @brief |
---|
150 | Removes this CollectiblePickup from its PickupCollection. |
---|
151 | @return |
---|
152 | Returns true if the CollectiblePickup was succcessfully removed. |
---|
153 | */ |
---|
154 | bool CollectiblePickup::removeFromCollection(void) |
---|
155 | { |
---|
156 | if(!this->isInCollection()) //If the CollectiblePickup is not in a PickupCollection. |
---|
157 | return false; |
---|
158 | |
---|
159 | this->isInCollection_ = false; |
---|
160 | this->collection_ = NULL; |
---|
161 | return true; |
---|
162 | } |
---|
163 | |
---|
164 | } |
---|