[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" |
---|
| 32 | |
---|
| 33 | namespace orxonox |
---|
| 34 | { |
---|
| 35 | |
---|
| 36 | /*static*/ const std::string Pickup::activationTypeImmediate_s = "immediate"; |
---|
| 37 | /*static*/ const std::string Pickup::activationTypeOnUse_s = "onUse"; |
---|
| 38 | /*static*/ const std::string Pickup::durationTypeOnce_s = "once"; |
---|
| 39 | /*static*/ const std::string Pickup::durationTypeContinuous_s = "continuous"; |
---|
| 40 | /*static*/ const std::string Pickup::blankString_s = ""; |
---|
| 41 | |
---|
| 42 | //TODO: Should this bee here? Does it work without? |
---|
| 43 | CreateFactory(Pickup); |
---|
| 44 | |
---|
| 45 | Pickup::Pickup(BaseObject* creator) : BaseObject(creator) |
---|
| 46 | { |
---|
| 47 | RegisterObject(Pickup); |
---|
| 48 | |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | Pickup::~Pickup() |
---|
| 52 | { |
---|
| 53 | |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | void Pickup::initializeIdentifier(void) |
---|
| 57 | { |
---|
| 58 | this->pickupIdentifier_.addClass(this->getIdentifier()); |
---|
| 59 | |
---|
| 60 | //TODO: Works? |
---|
| 61 | std::string val1 = this->getActivationType(); |
---|
| 62 | std::string type1 = "activationType"; |
---|
| 63 | this->pickupIdentifier_.addParameter(type1, val1); |
---|
| 64 | |
---|
| 65 | std::string val2 = this->getDurationType(); |
---|
| 66 | std::string type2 = "durationType"; |
---|
| 67 | this->pickupIdentifier_.addParameter(type2, val2); |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | void Pickup::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 71 | { |
---|
| 72 | SUPER(Pickup, XMLPort, xmlelement, mode); |
---|
| 73 | |
---|
| 74 | XMLPortParam(Pickup, "activationType", setActivationType, getActivationType, xmlelement, mode); |
---|
| 75 | XMLPortParam(Pickup, "durationType", setDurationType, getDurationType, xmlelement, mode); |
---|
| 76 | |
---|
| 77 | this->initializeIdentifier(); |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | /** |
---|
| 81 | @brief |
---|
| 82 | Get the activation type of the pickup. |
---|
| 83 | @param buffer |
---|
| 84 | The buffer to store the activation type as string in. |
---|
| 85 | */ |
---|
| 86 | const std::string& Pickup::getActivationType(void) |
---|
| 87 | { |
---|
| 88 | switch(this->activationType_) |
---|
| 89 | { |
---|
| 90 | case pickupActivationType::immediate: |
---|
| 91 | return activationTypeImmediate_s; |
---|
| 92 | case pickupActivationType::onUse: |
---|
| 93 | return activationTypeOnUse_s; |
---|
| 94 | default: |
---|
| 95 | return blankString_s; |
---|
| 96 | } |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | /** |
---|
| 100 | @brief |
---|
| 101 | Get the duration type of the pickup. |
---|
| 102 | @param buffer |
---|
| 103 | The buffer to store the duration type as string in. |
---|
| 104 | */ |
---|
| 105 | const std::string& Pickup::getDurationType(void) |
---|
| 106 | { |
---|
| 107 | switch(this->durationType_) |
---|
| 108 | { |
---|
| 109 | case pickupDurationType::once: |
---|
| 110 | return durationTypeOnce_s; |
---|
| 111 | case pickupDurationType::continuous: |
---|
| 112 | return durationTypeContinuous_s; |
---|
| 113 | default: |
---|
| 114 | return blankString_s; |
---|
| 115 | } |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | /** |
---|
| 119 | @brief |
---|
| 120 | Set the activation type of the Pickup. |
---|
| 121 | @param type |
---|
| 122 | The activation type of the Pickup as a string. |
---|
| 123 | */ |
---|
| 124 | void Pickup::setActivationType(const std::string& type) |
---|
| 125 | { |
---|
| 126 | if(type == activationTypeImmediate_s) |
---|
| 127 | { |
---|
| 128 | this->activationType_ = pickupActivationType::immediate; |
---|
| 129 | } |
---|
| 130 | else if(type == activationTypeOnUse_s) |
---|
| 131 | { |
---|
| 132 | this->activationType_ = pickupActivationType::onUse; |
---|
| 133 | } |
---|
| 134 | else |
---|
| 135 | { |
---|
| 136 | COUT(1) << "Invalid activationType in pickup." << std::endl; |
---|
| 137 | } |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | /** |
---|
| 141 | @brief |
---|
| 142 | Set the duration type of the Pickup. |
---|
| 143 | @param type |
---|
| 144 | The duration type of the Pickup as a string. |
---|
| 145 | */ |
---|
| 146 | void Pickup::setDurationType(const std::string& type) |
---|
| 147 | { |
---|
| 148 | if(type == durationTypeOnce_s) |
---|
| 149 | { |
---|
| 150 | this->durationType_ = pickupDurationType::once; |
---|
| 151 | } |
---|
| 152 | else if(type == durationTypeContinuous_s) |
---|
| 153 | { |
---|
| 154 | this->durationType_ = pickupDurationType::continuous; |
---|
| 155 | } |
---|
| 156 | else |
---|
| 157 | { |
---|
| 158 | COUT(1) << "Invalid durationType in pickup." << std::endl; |
---|
| 159 | } |
---|
| 160 | } |
---|
| 161 | |
---|
| 162 | /** |
---|
| 163 | @brief |
---|
| 164 | Creates a duplicate of the pickup. |
---|
| 165 | @return |
---|
| 166 | Returns the clone of this pickup as a pointer to a Pickupable. |
---|
| 167 | */ |
---|
| 168 | void Pickup::clone(OrxonoxClass* item) |
---|
| 169 | { |
---|
| 170 | if(item == NULL) |
---|
| 171 | item = new Pickup(this); |
---|
| 172 | |
---|
| 173 | SUPER(Pickup, clone, item); |
---|
| 174 | |
---|
| 175 | Pickup* pickup = dynamic_cast<Pickup*>(item); |
---|
| 176 | pickup->setActivationTypeDirect(this->getActivationTypeDirect()); |
---|
| 177 | pickup->setDurationTypeDirect(this->getDurationTypeDirect()); |
---|
| 178 | |
---|
| 179 | pickup->initializeIdentifier(); |
---|
| 180 | } |
---|
| 181 | |
---|
| 182 | void Pickup::changedCarrier(void) |
---|
| 183 | { |
---|
| 184 | SUPER(Pickup, changedCarrier); |
---|
| 185 | |
---|
| 186 | if(this->isPickedUp() && this->isImmediate()) |
---|
| 187 | { |
---|
| 188 | this->setUsed(true); |
---|
| 189 | } |
---|
| 190 | } |
---|
| 191 | |
---|
| 192 | } |
---|