- Timestamp:
- Mar 29, 2010, 4:33:22 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/ppspickups2/src/modules/pickup/items/InvisiblePickup.cc
r6555 r6641 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 * Benedict Simlinger 24 * Co-authors: 25 * ... 26 * 27 */ 28 29 /** 30 @file InvisiblePickup.cc 31 @brief Implementation of the InvisiblePickup class. 32 */ 33 34 #include "InvisiblePickup.h" 35 36 #include "core/CoreIncludes.h" 37 #include "core/XMLPort.h" 38 #include "util/StringUtils.h" 39 40 #include "worldentities/pawns/Pawn.h" 41 #include "pickup/PickupIdentifier.h" 42 43 #include <sstream> 44 45 namespace orxonox 46 { 47 48 49 CreateFactory(InvisiblePickup); 50 51 /** 52 @brief 53 Constructor. Registers the object and initializes the member variables. 54 */ 55 InvisiblePickup::InvisiblePickup(BaseObject* creator) : Pickup(creator) 56 { 57 RegisterObject(InvisiblePickup); 58 //! Defines who is allowed to pick up the pickup. 59 this->initialize(); 60 } 61 62 /** 63 @brief 64 Destructor. 65 */ 66 InvisiblePickup::~InvisiblePickup() 67 { 68 } 69 70 71 void InvisiblePickup::initializeIdentifier(void) 72 { 73 std::stringstream stream; 74 stream << this->getDuration(); 75 std::string type1 = "duration"; 76 std::string val1 = stream.str(); 77 this->pickupIdentifier_->addParameter(type1, val1); 78 } 79 80 /** 81 @brief 82 Initializes the member variables. 83 */ 84 void InvisiblePickup::initialize(void) 85 { 86 this->duration_ = 0.0; 87 this->addTarget(ClassIdentifier<Pawn>::getIdentifier()); 88 } 89 90 91 92 93 /** 94 @brief 95 Method for creating a HealthPickup object through XML. 96 */ 97 void InvisiblePickup::XMLPort(Element& xmlelement, orxonox::XMLPort::Mode mode) 98 { 99 SUPER(InvisiblePickup, XMLPort, xmlelement, mode); 100 XMLPortParam(InvisiblePickup, "duration", setDuration, getDuration, xmlelement, mode); 101 102 this->initializeIdentifier(); 103 } 104 105 106 /** 107 @brief 108 Is called when the pickup has transited from used to unused or the other way around. 109 */ 110 void InvisiblePickup::changedUsed(void) 111 { 112 SUPER(InvisiblePickup, changedUsed); 113 114 115 //! If the pickup is not picked up nothing must be done. 116 if(!this->isPickedUp()) 117 return; 118 if (this->isUsed()) 119 { 120 this->setInvisible(true); 121 this->startPickupTimer(this->getDuration()); 122 } 123 else 124 this->setInvisible(false); 125 126 } 127 128 /** 129 @brief 130 Helper to transform the PickupCarrier to a Pawn, and throw an error message if the conversion fails. 131 @return 132 A pointer to the Pawn, or NULL if the conversion failed. 133 */ 134 Pawn* InvisiblePickup::carrierToPawnHelper(void) 135 { 136 PickupCarrier* carrier = this->getCarrier(); 137 Pawn* pawn = dynamic_cast<Pawn*>(carrier); 138 139 if(pawn == NULL) 140 { 141 COUT(1) << "Invalid PickupCarrier in InvisiblePickup." << std::endl; 142 } 143 return pawn; 144 } 145 146 /** 147 @brief 148 Creates a duplicate of the input OrxonoxClass. 149 @param item 150 A pointer to the Orxonox class. 151 */ 152 void InvisiblePickup::clone(OrxonoxClass*& item) 153 { 154 if(item == NULL) 155 item = new InvisiblePickup(this); 156 157 SUPER(InvisiblePickup, clone, item); 158 159 InvisiblePickup* pickup = dynamic_cast<InvisiblePickup*>(item); 160 pickup->setDuration(this->getDuration()); 161 pickup->initializeIdentifier(); 162 } 163 164 165 166 167 168 /** 169 @brief 170 Sets the invisibility. 171 @param health 172 The invisibility. 173 */ 174 bool InvisiblePickup::setInvisible(bool invisibility) 175 { 176 177 Pawn* pawn = this->carrierToPawnHelper(); 178 pawn->setVisible(!invisibility); 179 return 0; 180 } 181 182 183 184 /** 185 @brief 186 Sets the duration. 187 @param duration 188 The duration 189 */ 190 void InvisiblePickup::setDuration(float duration) 191 { 192 if(duration >= 0.0f) 193 { 194 this->duration_ = duration; 195 } 196 else 197 { 198 COUT(1) << "Invalid duration in InvisiblePickup." << std::endl; 199 this->duration_ = 0; 200 } 201 } 202 203 204 205 void InvisiblePickup::PickupTimerCallBack(void){ 206 this->setInvisible(false); 207 } 208 209 }
Note: See TracChangeset
for help on using the changeset viewer.