[6512] | 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 | |
---|
[6519] | 29 | /** |
---|
| 30 | @file |
---|
| 31 | @brief Implementation of the MetaPickup class. |
---|
| 32 | */ |
---|
| 33 | |
---|
[6512] | 34 | #include "core/CoreIncludes.h" |
---|
| 35 | #include "core/XMLPort.h" |
---|
| 36 | #include "interfaces/PickupCarrier.h" |
---|
| 37 | #include "pickup/PickupIdentifier.h" |
---|
| 38 | |
---|
[6518] | 39 | #include "MetaPickup.h" |
---|
[6512] | 40 | |
---|
| 41 | namespace orxonox { |
---|
| 42 | |
---|
[6518] | 43 | CreateFactory(MetaPickup); |
---|
[6512] | 44 | |
---|
[6518] | 45 | /*static*/ const std::string MetaPickup::metaTypeNone_s = "none"; |
---|
| 46 | /*static*/ const std::string MetaPickup::metaTypeUse_s = "use"; |
---|
| 47 | /*static*/ const std::string MetaPickup::metaTypeDrop_s = "drop"; |
---|
[6512] | 48 | |
---|
[6519] | 49 | /** |
---|
| 50 | @brief |
---|
| 51 | Constructor. |
---|
| 52 | */ |
---|
[6518] | 53 | MetaPickup::MetaPickup(BaseObject* creator) : Pickup(creator) |
---|
[6512] | 54 | { |
---|
[6518] | 55 | RegisterObject(MetaPickup); |
---|
[6512] | 56 | |
---|
[6517] | 57 | this->addTarget(ClassIdentifier<PickupCarrier>::getIdentifier()); |
---|
[6512] | 58 | this->setActivationTypeDirect(pickupActivationType::immediate); |
---|
| 59 | this->setDurationTypeDirect(pickupDurationType::once); |
---|
[6518] | 60 | this->metaType_ = pickupMetaType::none; |
---|
[6512] | 61 | } |
---|
| 62 | |
---|
[6518] | 63 | MetaPickup::~MetaPickup() |
---|
[6512] | 64 | { |
---|
| 65 | |
---|
| 66 | } |
---|
| 67 | |
---|
[6518] | 68 | void MetaPickup::initializeIdentifier(void) |
---|
[6512] | 69 | { |
---|
[6518] | 70 | std::string val = this->getMetaType(); |
---|
| 71 | std::string type = "metaType"; |
---|
[6512] | 72 | this->pickupIdentifier_->addParameter(type, val); |
---|
| 73 | } |
---|
| 74 | |
---|
[6518] | 75 | void MetaPickup::XMLPort(Element& xmlelement, orxonox::XMLPort::Mode mode) |
---|
[6512] | 76 | { |
---|
[6518] | 77 | SUPER(MetaPickup, XMLPort, xmlelement, mode); |
---|
[6512] | 78 | |
---|
[6518] | 79 | XMLPortParam(MetaPickup, "metaType", setMetaType, getMetaType, xmlelement, mode); |
---|
[6512] | 80 | |
---|
| 81 | this->initializeIdentifier(); |
---|
| 82 | } |
---|
| 83 | |
---|
[6518] | 84 | void MetaPickup::changedUsed(void) |
---|
[6512] | 85 | { |
---|
[6518] | 86 | SUPER(MetaPickup, changedUsed); |
---|
[6512] | 87 | |
---|
| 88 | if(this->isUsed()) |
---|
| 89 | { |
---|
| 90 | PickupCarrier* carrier = this->getCarrier(); |
---|
[6518] | 91 | if(this->getMetaTypeDirect() != pickupMetaType::none && carrier != NULL) |
---|
[6512] | 92 | { |
---|
| 93 | std::set<Pickupable*> pickups = carrier->getPickups(); |
---|
| 94 | for(std::set<Pickupable*>::iterator it = pickups.begin(); it != pickups.end(); it++) |
---|
| 95 | { |
---|
| 96 | Pickup* pickup = dynamic_cast<Pickup*>(*it); |
---|
[6518] | 97 | if(this->getMetaTypeDirect() == pickupMetaType::use) |
---|
[6512] | 98 | { |
---|
| 99 | if(pickup != NULL && pickup != this && pickup->isOnUse() && !pickup->isUsed()) |
---|
| 100 | { |
---|
| 101 | pickup->setUsed(true); |
---|
| 102 | } |
---|
| 103 | } |
---|
[6518] | 104 | if(this->getMetaTypeDirect() == pickupMetaType::drop) |
---|
[6512] | 105 | { |
---|
| 106 | if(pickup != NULL && pickup != this) |
---|
| 107 | { |
---|
| 108 | carrier->drop(pickup); |
---|
| 109 | } |
---|
| 110 | } |
---|
| 111 | } |
---|
| 112 | } |
---|
| 113 | this->destroy(); |
---|
| 114 | } |
---|
| 115 | } |
---|
| 116 | |
---|
[6518] | 117 | const std::string& MetaPickup::getMetaType(void) |
---|
[6512] | 118 | { |
---|
[6518] | 119 | switch(this->getMetaTypeDirect()) |
---|
[6512] | 120 | { |
---|
[6518] | 121 | case pickupMetaType::none: |
---|
| 122 | return MetaPickup::metaTypeNone_s; |
---|
| 123 | case pickupMetaType::use: |
---|
| 124 | return MetaPickup::metaTypeUse_s; |
---|
| 125 | case pickupMetaType::drop: |
---|
| 126 | return MetaPickup::metaTypeDrop_s; |
---|
[6512] | 127 | default: |
---|
| 128 | return BLANKSTRING; |
---|
| 129 | } |
---|
| 130 | } |
---|
| 131 | |
---|
[6518] | 132 | void MetaPickup::setMetaType(const std::string& type) |
---|
[6512] | 133 | { |
---|
[6518] | 134 | if(type == MetaPickup::metaTypeNone_s) |
---|
[6512] | 135 | { |
---|
[6518] | 136 | this->setMetaTypeDirect(pickupMetaType::none); |
---|
[6512] | 137 | } |
---|
[6518] | 138 | else if(type == MetaPickup::metaTypeUse_s) |
---|
[6512] | 139 | { |
---|
[6518] | 140 | this->setMetaTypeDirect(pickupMetaType::use); |
---|
[6512] | 141 | } |
---|
[6518] | 142 | else if(type == MetaPickup::metaTypeDrop_s) |
---|
[6512] | 143 | { |
---|
[6518] | 144 | this->setMetaTypeDirect(pickupMetaType::drop); |
---|
[6512] | 145 | } |
---|
| 146 | } |
---|
| 147 | |
---|
[6518] | 148 | void MetaPickup::clone(OrxonoxClass*& item) |
---|
[6512] | 149 | { |
---|
| 150 | if(item == NULL) |
---|
[6518] | 151 | item = new MetaPickup(this); |
---|
[6512] | 152 | |
---|
[6518] | 153 | SUPER(MetaPickup, clone, item); |
---|
[6512] | 154 | |
---|
[6518] | 155 | MetaPickup* pickup = dynamic_cast<MetaPickup*>(item); |
---|
| 156 | pickup->setMetaTypeDirect(this->getMetaTypeDirect()); |
---|
[6512] | 157 | |
---|
| 158 | pickup->initializeIdentifier(); |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | } |
---|