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