Changeset 7547 for code/trunk/src/modules/pickup/items/ShieldPickup.cc
- Timestamp:
- Oct 16, 2010, 12:37:09 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/modules/pickup/items/ShieldPickup.cc
r7208 r7547 34 34 #include "ShieldPickup.h" 35 35 36 #include <sstream> 36 37 #include "core/CoreIncludes.h" 37 38 #include "core/XMLPort.h" 38 #include "util/StringUtils.h" 39 40 #include "worldentities/pawns/SpaceShip.h" 41 #include "items/Engine.h" 39 42 40 #include "pickup/PickupIdentifier.h" 43 44 #include <sstream> 45 41 #include "worldentities/pawns/Pawn.h" 46 42 47 43 namespace orxonox … … 67 63 { 68 64 69 }70 71 /**72 @brief73 Helper to transform the PickupCarrier to a Pawn, and throw an error message if the conversion fails.74 @return75 A pointer to the Pawn, or NULL if the conversion failed.76 */77 Pawn* ShieldPickup::carrierToPawnHelper(void)78 {79 PickupCarrier* carrier = this->getCarrier();80 Pawn* pawn = dynamic_cast<Pawn*>(carrier);81 82 if(pawn == NULL)83 {84 COUT(1) << "Invalid PickupCarrier in ShieldPickup." << std::endl;85 }86 return pawn;87 65 } 88 66 … … 134 112 SUPER(ShieldPickup, XMLPort, xmlelement, mode); 135 113 136 XMLPortParam(ShieldPickup, "duration", setDuration, getDuration, xmlelement, mode);137 114 XMLPortParam(ShieldPickup, "shieldhealth", setShieldHealth, getShieldHealth, xmlelement, mode); 138 115 XMLPortParam(ShieldPickup, "shieldabsorption", setShieldAbsorption, getShieldAbsorption, xmlelement, mode); 116 XMLPortParam(ShieldPickup, "duration", setDuration, getDuration, xmlelement, mode); 139 117 140 118 this->initializeIdentifier(); … … 149 127 SUPER(ShieldPickup, changedUsed); 150 128 151 // !If the pickup is not picked up nothing must be done.129 // If the pickup is not picked up nothing must be done. 152 130 if(!this->isPickedUp()) 153 131 return; … … 157 135 this->Pickupable::destroy(); 158 136 159 // !If the pickup has transited to used.137 // If the pickup has transited to used. 160 138 if(this->isUsed()) 161 139 { 162 if(!this->durationTimer_.isActive() && this->durationTimer_.getRemainingTime() > 0.0f) 140 // If its durationType is continuous, we set a Timer to be reminded, when the time has run out. 141 if(this->isContinuous()) 163 142 { 164 this->durationTimer_.unpauseTimer(); 165 } 166 else 167 { 168 this->durationTimer_.setTimer(this->getDuration(), false, createExecutor(createFunctor(&ShieldPickup::pickupTimerCallback, this))); 143 if(!this->durationTimer_.isActive() && this->durationTimer_.getRemainingTime() > 0.0f) 144 { 145 this->durationTimer_.unpauseTimer(); 146 } 147 else 148 { 149 this->durationTimer_.setTimer(this->getDuration(), false, createExecutor(createFunctor(&ShieldPickup::pickupTimerCallback, this))); 150 } 169 151 } 170 152 pawn->setShieldAbsorption(this->getShieldAbsorption()); … … 177 159 pawn->setShieldHealth(0.0f); 178 160 179 if(this->isOnce()) 161 // We destroy the pickup if either, the pickup has activationType immediate and durationType once or it has durationType continuous and the duration was exceeded. 162 if((!this->isContinuous() && this->isImmediate()) || (this->isContinuous() && !this->durationTimer_.isActive() && this->durationTimer_.getRemainingTime() == this->getDuration())) 180 163 { 181 if(!this->durationTimer_.isActive() && this->durationTimer_.getRemainingTime() == this->getDuration()) 182 { 183 this->Pickupable::destroy(); 184 } 185 else 186 { 187 this->durationTimer_.pauseTimer(); 188 } 164 this->Pickupable::destroy(); 189 165 } 190 } 166 // We pause the Timer if the pickup is continuous and the duration is not yet exceeded, 167 else if(this->isContinuous() && this->durationTimer_.isActive()) 168 { 169 this->durationTimer_.pauseTimer(); 170 } 171 } 172 } 173 174 /** 175 @brief 176 Helper to transform the PickupCarrier to a Pawn, and throw an error message if the conversion fails. 177 @return 178 A pointer to the Pawn, or NULL if the conversion failed. 179 */ 180 Pawn* ShieldPickup::carrierToPawnHelper(void) 181 { 182 PickupCarrier* carrier = this->getCarrier(); 183 Pawn* pawn = dynamic_cast<Pawn*>(carrier); 184 185 if(pawn == NULL) 186 { 187 COUT(1) << "Invalid PickupCarrier in ShieldPickup." << std::endl; 188 } 189 return pawn; 191 190 } 192 191 … … 213 212 /** 214 213 @brief 215 Sets the percentage the shield absorbs of the dealt damage. 214 Sets the duration. 215 @param duration 216 The duration in seconds. 217 */ 218 void ShieldPickup::setDuration(float duration) 219 { 220 if(duration >= 0.0f) 221 { 222 this->duration_ = duration; 223 } 224 else 225 { 226 COUT(1) << "Invalid duration in ShieldPickup." << std::endl; 227 this->duration_ = 0.0f; 228 } 229 } 230 231 /** 232 @brief 233 Sets the health of the shield. 234 @param shieldHealth 235 The shieldHealth. 236 */ 237 void ShieldPickup::setShieldHealth(float shieldHealth) 238 { 239 if (shieldHealth>=0) 240 { 241 this->shieldHealth_=shieldHealth; 242 } 243 else 244 { 245 COUT(1) << "Invalid Shieldhealth in ShieldPickup." << std::endl; 246 this->shieldHealth_=0; 247 } 248 } 249 250 /** 251 @brief 252 Sets the percentage the shield absorbs of the dealt damage. 216 253 @param shieldAbsorption 217 The shieldAbsorption. Has to be between 0 and 1254 The shieldAbsorption. Has to be between 0 and 1. 218 255 */ 219 256 void ShieldPickup::setShieldAbsorption(float shieldAbsorption) … … 232 269 /** 233 270 @brief 234 Sets the health of the shield. 235 @param shieldHealth 236 The shieldHealth 237 */ 238 void ShieldPickup::setShieldHealth(float shieldHealth) 239 { 240 if (shieldHealth>=0) 241 { 242 this->shieldHealth_=shieldHealth; 243 } 244 else 245 { 246 COUT(1) << "Invalid Shieldhealth in ShieldPickup." << std::endl; 247 this->shieldHealth_=0; 248 } 249 } 250 251 /** 252 @brief 253 Sets the duration. 254 @param duration 255 The duration 256 */ 257 void ShieldPickup::setDuration(float duration) 258 { 259 if(duration >= 0.0f) 260 { 261 this->duration_ = duration; 262 } 263 else 264 { 265 COUT(1) << "Invalid duration in ShieldPickup." << std::endl; 266 this->duration_ = 0.0f; 267 } 268 } 269 271 Helper method. Is called by the Timer as soon as it expires. 272 */ 270 273 void ShieldPickup::pickupTimerCallback(void) 271 274 {
Note: See TracChangeset
for help on using the changeset viewer.