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