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