- Timestamp:
- May 10, 2010, 4:23:29 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/ppspickups3/src/modules/pickup/items/ShieldPickup.cc
r6869 r6884 71 71 /** 72 72 @brief 73 Helper to transform the PickupCarrier to a Pawn, and throw an error message if the conversion fails. 74 @return 75 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 } 88 89 /** 90 @brief 73 91 Initializes the member variables. 74 92 */ … … 76 94 { 77 95 this->duration_ = 0.0f; 96 this->shieldAbsorption_ = 0.0f; 97 this->shieldHealth_ = 0.0f; 78 98 79 99 this->addTarget(ClassIdentifier<Engine>::getIdentifier()); … … 92 112 this->pickupIdentifier_->addParameter(type1, val1); 93 113 94 // stream.clear(); 95 // stream << this->getShieldAdd(); 96 // std::string type2 = "ShieldAdd"; 97 // std::string val2 = stream.str(); 98 // this->pickupIdentifier_->addParameter(type2, val2); 114 stream.clear(); 115 stream << this->getShieldHealth(); 116 std::string type2 = "ShieldHealth"; 117 std::string val2 = stream.str(); 118 this->pickupIdentifier_->addParameter(type2, val2); 119 120 stream.clear(); 121 stream << this->getShieldAbsorption(); 122 std::string type3 = "ShieldAbsorption"; 123 std::string val3 = stream.str(); 124 this->pickupIdentifier_->addParameter(type3, val3); 99 125 100 126 } … … 109 135 110 136 XMLPortParam(ShieldPickup, "duration", setDuration, getDuration, xmlelement, mode); 137 XMLPortParam(ShieldPickup, "shieldhealth", setShieldHealth, getShieldHealth, xmlelement, mode); 138 XMLPortParam(ShieldPickup, "shieldabsorption", setShieldAbsorption, getShieldAbsorption, xmlelement, mode); 111 139 112 140 this->initializeIdentifier(); … … 124 152 if(!this->isPickedUp()) 125 153 return; 154 155 Pawn* pawn = this->carrierToPawnHelper(); 156 if(pawn == NULL) 157 this->destroy(); 158 159 //! If the pickup has transited to used. 160 if(this->isUsed()) 161 { 162 if(!this->getTimer()->isActive() && this->getTimer()->getRemainingTime() > 0.0f) 163 { 164 this->getTimer()->unpauseTimer(); 165 } 166 else 167 { 168 this->startPickupTimer(this->getDuration()); 169 } 170 pawn->setShieldAbsorption(this->getShieldAbsorption()); 171 pawn->setShieldHealth(this->getShieldHealth()); 172 } 173 else 174 { 175 pawn->setShieldAbsorption(0.0f); 176 this->setShieldHealth(pawn->getShieldHealth()); 177 pawn->setShieldHealth(0.0f); 178 179 if(this->isOnce()) 180 { 181 if(!this->getTimer()->isActive() && this->getTimer()->getRemainingTime() == this->getDuration()) 182 { 183 this->destroy(); 184 } 185 else 186 { 187 this->getTimer()->pauseTimer(); 188 } 189 } 190 } 126 191 } 127 192 … … 141 206 ShieldPickup* pickup = dynamic_cast<ShieldPickup*>(item); 142 207 pickup->setDuration(this->getDuration()); 143 208 pickup->setShieldAbsorption(this->getShieldAbsorption()); 209 pickup->setShieldHealth(this->getShieldHealth()); 144 210 pickup->initializeIdentifier(); 211 } 212 213 /** 214 @brief 215 Sets the percentage the shield absorbs of the dealt damage. 216 @param shieldAbsorption 217 The shieldAbsorption. Has to be between 0 and 1 218 */ 219 void ShieldPickup::setShieldAbsorption(float shieldAbsorption) 220 { 221 if (shieldAbsorption>=0 && shieldAbsorption<=1) 222 { 223 this->shieldAbsorption_=shieldAbsorption; 224 } 225 else 226 { 227 COUT(1) << "Invalid Absorption in ShieldPickup." << std::endl; 228 this->shieldAbsorption_=0; 229 } 230 } 231 232 /** 233 @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 } 145 249 } 146 250
Note: See TracChangeset
for help on using the changeset viewer.