Changeset 6884 for code/branches/ppspickups3/src/modules/pickup/items
- Timestamp:
- May 10, 2010, 4:23:29 PM (15 years ago)
- Location:
- code/branches/ppspickups3/src/modules/pickup/items
- Files:
-
- 2 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 -
code/branches/ppspickups3/src/modules/pickup/items/ShieldPickup.h
r6869 r6884 1 1 2 /* 2 3 * ORXONOX - the hottest 3D action shooter ever to exist … … 49 50 A Pickup which can add a Shield to the Pawn. 50 51 51 1) The Shield multiplier: 52 The additional (forward) Shield: 53 2) The activation type: 'immediate' or 'onUse'. defines if the item is used when it's picked up or only after the player chooses to use it.52 1) The percentage: The percentage the shield takes from the damage dealt to a Pawn 53 2) The hit points: The amount of damage points a shield can teake before collapsing 54 3) The activation type: 'immediate' or 'onUse'. defines if the item is used when it's picked up or only after the player chooses to use it. 54 55 4) The duration: the activation time of the pickup. 55 56 … … 71 72 inline float getDuration(void) 72 73 { return this->duration_; } 73 74 inline float getShieldHealth() 75 { return this->shieldHealth_; } 76 inline float getShieldAbsorption() 77 { return this->shieldAbsorption_; } 74 78 75 79 protected: 76 80 void initializeIdentifier(void); //!< Initializes the PickupIdentifier of this pickup. 77 81 78 82 virtual void pickupTimerCallback(void); //!< Function that gets called when timer ends. 79 83 80 84 void setDuration(float duration); 81 85 void setShieldHealth(float shieldHealth); 86 void setShieldAbsorption(float shieldAbsorption); 82 87 83 88 private: 84 89 void initialize(void); //!< Initializes the member variables. 85 Engine* carrierToEngineHelper(void); //!< Helper to transform the PickupCarrier to a Pawn, and throw an error message if the conversion fails.90 Pawn* carrierToPawnHelper(void); //!< Helper to transform the PickupCarrier to a Pawn, and throw an error message if the conversion fails. 86 91 87 92 float duration_; //!< The health that is transferred to the Pawn. 93 float shieldHealth_; 94 float shieldAbsorption_; // Has to be between 0 and 1 95 88 96 }; 89 97 }
Note: See TracChangeset
for help on using the changeset viewer.