[6474] | 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 | |
---|
[6540] | 29 | /** |
---|
| 30 | @file Pickup.cc |
---|
| 31 | @brief Implementation of the Pickup class. |
---|
| 32 | */ |
---|
| 33 | |
---|
[6474] | 34 | #include "Pickup.h" |
---|
| 35 | |
---|
| 36 | #include "core/CoreIncludes.h" |
---|
[6475] | 37 | #include "util/StringUtils.h" |
---|
[7494] | 38 | |
---|
[6475] | 39 | #include "pickup/PickupIdentifier.h" |
---|
[7494] | 40 | |
---|
[6475] | 41 | #include "DroppedPickup.h" |
---|
[6474] | 42 | |
---|
| 43 | namespace orxonox |
---|
| 44 | { |
---|
[6709] | 45 | |
---|
[6474] | 46 | /*static*/ const std::string Pickup::activationTypeImmediate_s = "immediate"; |
---|
| 47 | /*static*/ const std::string Pickup::activationTypeOnUse_s = "onUse"; |
---|
| 48 | /*static*/ const std::string Pickup::durationTypeOnce_s = "once"; |
---|
| 49 | /*static*/ const std::string Pickup::durationTypeContinuous_s = "continuous"; |
---|
[6709] | 50 | |
---|
[7163] | 51 | CreateUnloadableFactory(Pickup); |
---|
| 52 | |
---|
[7494] | 53 | /** |
---|
| 54 | @brief |
---|
| 55 | Constructor. Registers and initializes the object. |
---|
| 56 | @param creator |
---|
| 57 | The objects creator. |
---|
| 58 | */ |
---|
[6474] | 59 | Pickup::Pickup(BaseObject* creator) : BaseObject(creator) |
---|
| 60 | { |
---|
| 61 | RegisterObject(Pickup); |
---|
[6709] | 62 | |
---|
[6475] | 63 | this->initialize(); |
---|
[6474] | 64 | } |
---|
[6709] | 65 | |
---|
[7494] | 66 | /** |
---|
| 67 | @brief |
---|
| 68 | Destructor. |
---|
| 69 | */ |
---|
[6474] | 70 | Pickup::~Pickup() |
---|
| 71 | { |
---|
[6709] | 72 | |
---|
[6474] | 73 | } |
---|
[6709] | 74 | |
---|
[6475] | 75 | /** |
---|
| 76 | @brief |
---|
| 77 | Initializes the member variables. |
---|
| 78 | */ |
---|
| 79 | void Pickup::initialize(void) |
---|
| 80 | { |
---|
| 81 | this->activationType_ = pickupActivationType::immediate; |
---|
| 82 | this->durationType_ = pickupDurationType::once; |
---|
| 83 | } |
---|
[6709] | 84 | |
---|
[6475] | 85 | /** |
---|
| 86 | @brief |
---|
| 87 | Initializes the PickupIdentififer of this Pickup. |
---|
| 88 | */ |
---|
[6474] | 89 | void Pickup::initializeIdentifier(void) |
---|
[6709] | 90 | { |
---|
[6474] | 91 | std::string val1 = this->getActivationType(); |
---|
| 92 | std::string type1 = "activationType"; |
---|
[6475] | 93 | this->pickupIdentifier_->addParameter(type1, val1); |
---|
[6709] | 94 | |
---|
[6474] | 95 | std::string val2 = this->getDurationType(); |
---|
| 96 | std::string type2 = "durationType"; |
---|
[6475] | 97 | this->pickupIdentifier_->addParameter(type2, val2); |
---|
[6474] | 98 | } |
---|
[6709] | 99 | |
---|
[6475] | 100 | /** |
---|
| 101 | @brief |
---|
| 102 | Method for creating a Pickup object through XML. |
---|
| 103 | */ |
---|
[6474] | 104 | void Pickup::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 105 | { |
---|
| 106 | SUPER(Pickup, XMLPort, xmlelement, mode); |
---|
| 107 | |
---|
| 108 | XMLPortParam(Pickup, "activationType", setActivationType, getActivationType, xmlelement, mode); |
---|
| 109 | XMLPortParam(Pickup, "durationType", setDurationType, getDurationType, xmlelement, mode); |
---|
[6709] | 110 | |
---|
[6474] | 111 | this->initializeIdentifier(); |
---|
| 112 | } |
---|
[6709] | 113 | |
---|
[6474] | 114 | /** |
---|
| 115 | @brief |
---|
| 116 | Get the activation type of the pickup. |
---|
[6475] | 117 | @return |
---|
| 118 | Returns a string containing the activation type. |
---|
[6474] | 119 | */ |
---|
| 120 | const std::string& Pickup::getActivationType(void) |
---|
| 121 | { |
---|
| 122 | switch(this->activationType_) |
---|
| 123 | { |
---|
| 124 | case pickupActivationType::immediate: |
---|
| 125 | return activationTypeImmediate_s; |
---|
| 126 | case pickupActivationType::onUse: |
---|
| 127 | return activationTypeOnUse_s; |
---|
| 128 | default: |
---|
[6475] | 129 | return BLANKSTRING; |
---|
[6474] | 130 | } |
---|
| 131 | } |
---|
[6709] | 132 | |
---|
[6474] | 133 | /** |
---|
| 134 | @brief |
---|
| 135 | Get the duration type of the pickup. |
---|
[6475] | 136 | @return |
---|
| 137 | Returns a string containing the duration type. |
---|
[6474] | 138 | */ |
---|
| 139 | const std::string& Pickup::getDurationType(void) |
---|
| 140 | { |
---|
| 141 | switch(this->durationType_) |
---|
| 142 | { |
---|
| 143 | case pickupDurationType::once: |
---|
| 144 | return durationTypeOnce_s; |
---|
| 145 | case pickupDurationType::continuous: |
---|
| 146 | return durationTypeContinuous_s; |
---|
| 147 | default: |
---|
[6475] | 148 | return BLANKSTRING; |
---|
[6474] | 149 | } |
---|
| 150 | } |
---|
[6709] | 151 | |
---|
[6474] | 152 | /** |
---|
| 153 | @brief |
---|
| 154 | Set the activation type of the Pickup. |
---|
| 155 | @param type |
---|
| 156 | The activation type of the Pickup as a string. |
---|
| 157 | */ |
---|
| 158 | void Pickup::setActivationType(const std::string& type) |
---|
| 159 | { |
---|
[7163] | 160 | if(Pickup::activationTypeImmediate_s.compare(type) == 0) |
---|
[6474] | 161 | { |
---|
| 162 | this->activationType_ = pickupActivationType::immediate; |
---|
| 163 | } |
---|
[7163] | 164 | else if(Pickup::activationTypeOnUse_s.compare(type) == 0) |
---|
[6474] | 165 | { |
---|
| 166 | this->activationType_ = pickupActivationType::onUse; |
---|
| 167 | } |
---|
| 168 | else |
---|
| 169 | { |
---|
[7494] | 170 | COUT(1) << "Invalid activationType '" << type << "' in pickup." << std::endl; |
---|
[6474] | 171 | } |
---|
| 172 | } |
---|
[6709] | 173 | |
---|
[6474] | 174 | /** |
---|
| 175 | @brief |
---|
| 176 | Set the duration type of the Pickup. |
---|
| 177 | @param type |
---|
| 178 | The duration type of the Pickup as a string. |
---|
| 179 | */ |
---|
| 180 | void Pickup::setDurationType(const std::string& type) |
---|
| 181 | { |
---|
[7163] | 182 | if(Pickup::durationTypeOnce_s.compare(type) == 0) |
---|
[6474] | 183 | { |
---|
| 184 | this->durationType_ = pickupDurationType::once; |
---|
| 185 | } |
---|
[7163] | 186 | else if(Pickup::durationTypeContinuous_s.compare(type) == 0) |
---|
[6474] | 187 | { |
---|
| 188 | this->durationType_ = pickupDurationType::continuous; |
---|
| 189 | } |
---|
| 190 | else |
---|
| 191 | { |
---|
[7494] | 192 | COUT(1) << "Invalid durationType '" << type << "' in pickup." << std::endl; |
---|
[6474] | 193 | } |
---|
| 194 | } |
---|
[6709] | 195 | |
---|
[6474] | 196 | /** |
---|
| 197 | @brief |
---|
[6475] | 198 | Should be called when the pickup has transited from picked up to dropped or the other way around. |
---|
[6521] | 199 | Any Class overwriting this method must call its SUPER function by adding SUPER(Classname, changedPickedUp); to their changedPickedUp method. |
---|
[6475] | 200 | */ |
---|
[6521] | 201 | void Pickup::changedPickedUp(void) |
---|
[6475] | 202 | { |
---|
[6521] | 203 | SUPER(Pickup, changedPickedUp); |
---|
[6709] | 204 | |
---|
[7494] | 205 | // Sets the Pickup to used if the Pickup has activation type 'immediate' and gets picked up. |
---|
[7163] | 206 | if(this->isPickedUp() && this->isImmediate()) |
---|
[6475] | 207 | this->setUsed(true); |
---|
| 208 | } |
---|
[6709] | 209 | |
---|
[6475] | 210 | /** |
---|
| 211 | @brief |
---|
[7494] | 212 | Creates a duplicate of the OrxonoxClass. |
---|
| 213 | @param item |
---|
| 214 | A reference to the pointer of the item that we're duplicating. |
---|
[6474] | 215 | */ |
---|
[6497] | 216 | void Pickup::clone(OrxonoxClass*& item) |
---|
[6474] | 217 | { |
---|
| 218 | if(item == NULL) |
---|
| 219 | item = new Pickup(this); |
---|
[6709] | 220 | |
---|
[6474] | 221 | SUPER(Pickup, clone, item); |
---|
[6709] | 222 | |
---|
[6474] | 223 | Pickup* pickup = dynamic_cast<Pickup*>(item); |
---|
| 224 | pickup->setActivationTypeDirect(this->getActivationTypeDirect()); |
---|
| 225 | pickup->setDurationTypeDirect(this->getDurationTypeDirect()); |
---|
[6709] | 226 | |
---|
[6474] | 227 | pickup->initializeIdentifier(); |
---|
| 228 | } |
---|
[6709] | 229 | |
---|
[6475] | 230 | /** |
---|
| 231 | @brief |
---|
| 232 | Facilitates the creation of a PickupSpawner upon dropping of the Pickupable. |
---|
| 233 | This method must be implemented by any class directly inheriting from Pickupable. It is most easily done by just creating a new DroppedPickup, e.g.: |
---|
| 234 | DroppedPickup(BaseObject* creator, Pickupable* pickup, const Vector3& position); |
---|
| 235 | @return |
---|
| 236 | Returns true if a spawner was created, false if not. |
---|
| 237 | */ |
---|
[6540] | 238 | bool Pickup::createSpawner(void) |
---|
[6474] | 239 | { |
---|
[6540] | 240 | new DroppedPickup(this, this, this->getCarrier()); |
---|
[6475] | 241 | return true; |
---|
[6474] | 242 | } |
---|
[6709] | 243 | |
---|
[6474] | 244 | } |
---|