- Timestamp:
- May 25, 2011, 9:28:29 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation/src/orxonox/worldentities/pawns/Pawn.cc
r8578 r8579 23 23 * Fabian 'x3n' Landau 24 24 * Co-authors: 25 * simonmie25 * ... 26 26 * 27 27 */ … … 64 64 this->maxHealth_ = 0; 65 65 this->initialHealth_ = 0; 66 67 66 this->shieldHealth_ = 0; 68 this->initialShieldHealth_ = 0;69 this->maxShieldHealth_ = 100; //otherwise shield might increase to float_max70 67 this->shieldAbsorption_ = 0.5; 71 72 this->reloadRate_ = 0;73 this->reloadWaitTime_ = 1.0f;74 this->reloadWaitCountdown_ = 0;75 68 76 69 this->lastHitOriginator_ = 0; … … 116 109 117 110 XMLPortParam(Pawn, "shieldhealth", setShieldHealth, getShieldHealth, xmlelement, mode).defaultValues(0); 118 XMLPortParam(Pawn, "initialshieldhealth", setInitialShieldHealth, getInitialShieldHealth, xmlelement, mode).defaultValues(0);119 XMLPortParam(Pawn, "maxshieldhealth", setMaxShieldHealth, getMaxShieldHealth, xmlelement, mode).defaultValues(100);120 111 XMLPortParam(Pawn, "shieldabsorption", setShieldAbsorption, getShieldAbsorption, xmlelement, mode).defaultValues(0); 121 112 … … 127 118 XMLPortObject(Pawn, WeaponSet, "weaponsets", addWeaponSet, getWeaponSet, xmlelement, mode); 128 119 XMLPortObject(Pawn, WeaponPack, "weapons", addWeaponPackXML, getWeaponPack, xmlelement, mode); 129 130 XMLPortParam(Pawn, "reloadrate", setReloadRate, getReloadRate, xmlelement, mode).defaultValues(0);131 XMLPortParam(Pawn, "reloadwaittime", setReloadWaitTime, getReloadWaitTime, xmlelement, mode).defaultValues(1.0f);132 120 } 133 121 … … 136 124 registerVariable(this->bAlive_, VariableDirection::ToClient); 137 125 registerVariable(this->health_, VariableDirection::ToClient); 138 registerVariable(this-> maxHealth_,VariableDirection::ToClient);126 registerVariable(this->initialHealth_, VariableDirection::ToClient); 139 127 registerVariable(this->shieldHealth_, VariableDirection::ToClient); 140 registerVariable(this->maxShieldHealth_, VariableDirection::ToClient);141 128 registerVariable(this->shieldAbsorption_, VariableDirection::ToClient); 142 129 registerVariable(this->bReload_, VariableDirection::ToServer); … … 150 137 this->bReload_ = false; 151 138 152 // TODO: use the existing timer functions instead153 if(this->reloadWaitCountdown_ > 0)154 {155 this->decreaseReloadCountdownTime(dt);156 }157 else158 {159 this->addShieldHealth(this->getReloadRate() * dt);160 this->resetReloadCountdown();161 }162 163 139 if (GameMode::isMaster()) 164 {165 140 if (this->health_ <= 0 && bAlive_) 166 141 { 167 this->fireEvent(); // Event to notify anyone who want s to know about the death.142 this->fireEvent(); // Event to notify anyone who want's to know about the death. 168 143 this->death(); 169 144 } 170 }171 145 } 172 146 … … 194 168 } 195 169 196 197 170 void Pawn::setHealth(float health) 198 171 { 199 this->health_ = std::min(health, this->maxHealth_); //Health can't be set to a value bigger than maxHealth, otherwise it will be reduced at first hit 200 } 201 202 void Pawn::setShieldHealth(float shieldHealth) 203 { 204 this->shieldHealth_ = std::min(shieldHealth, this->maxShieldHealth_); 205 } 206 207 void Pawn::setMaxShieldHealth(float maxshieldhealth) 208 { 209 this->maxShieldHealth_ = maxshieldhealth; 210 } 211 212 void Pawn::setReloadRate(float reloadrate) 213 { 214 this->reloadRate_ = reloadrate; 215 } 216 217 void Pawn::setReloadWaitTime(float reloadwaittime) 218 { 219 this->reloadWaitTime_ = reloadwaittime; 220 } 221 222 void Pawn::decreaseReloadCountdownTime(float dt) 223 { 224 this->reloadWaitCountdown_ -= dt; 225 } 226 227 void Pawn::damage(float damage, float healthdamage, float shielddamage, Pawn* originator) 172 this->health_ = std::min(health, this->maxHealth_); 173 } 174 175 void Pawn::damage(float damage, Pawn* originator) 228 176 { 229 177 if (this->getGametype() && this->getGametype()->allowPawnDamage(this, originator)) 230 178 { 231 if (shielddamage >= this->getShieldHealth()) 179 //share the dealt damage to the shield and the Pawn. 180 float shielddamage = damage*this->shieldAbsorption_; 181 float healthdamage = damage*(1-this->shieldAbsorption_); 182 183 // In case the shield can not take all the shield damage. 184 if (shielddamage > this->getShieldHealth()) 232 185 { 186 healthdamage += shielddamage-this->getShieldHealth(); 233 187 this->setShieldHealth(0); 234 this->setHealth(this->health_ - (healthdamage + damage));235 188 } 236 else 189 190 this->setHealth(this->health_ - healthdamage); 191 192 if (this->getShieldHealth() > 0) 237 193 { 238 194 this->setShieldHealth(this->shieldHealth_ - shielddamage); 239 240 // remove remaining shieldAbsorpton-Part of damage from shield241 shielddamage = damage * this->shieldAbsorption_;242 shielddamage = std::min(this->getShieldHealth(),shielddamage);243 this->setShieldHealth(this->shieldHealth_ - shielddamage);244 245 // set remaining damage to health246 this->setHealth(this->health_ - (damage - shielddamage) - healthdamage);247 195 } 248 196 249 197 this->lastHitOriginator_ = originator; 250 } 251 } 252 253 // TODO: Still valid? 254 /* HIT-Funktionen 255 Die hit-Funktionen muessen auch in src/orxonox/controllers/Controller.h angepasst werden! (Visuelle Effekte) 256 257 */ 258 259 void Pawn::hit(Pawn* originator, const Vector3& force, float damage, float healthdamage, float shielddamage) 198 199 // play damage effect 200 } 201 } 202 203 void Pawn::hit(Pawn* originator, const Vector3& force, float damage) 260 204 { 261 205 if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator) && (!this->getController() || !this->getController()->getGodMode()) ) 262 206 { 263 this->damage(damage, healthdamage, shielddamage,originator);207 this->damage(damage, originator); 264 208 this->setVelocity(this->getVelocity() + force); 265 } 266 } 267 268 269 void Pawn::hit(Pawn* originator, btManifoldPoint& contactpoint, float damage, float healthdamage, float shielddamage) 209 210 // play hit effect 211 } 212 } 213 214 void Pawn::hit(Pawn* originator, btManifoldPoint& contactpoint, float damage) 270 215 { 271 216 if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator) && (!this->getController() || !this->getController()->getGodMode()) ) 272 217 { 273 this->damage(damage, healthdamage, shielddamage,originator);218 this->damage(damage, originator); 274 219 275 220 if ( this->getController() ) 276 this->getController()->hit(originator, contactpoint, damage); // changed to damage, why shielddamage? 277 } 278 } 279 221 this->getController()->hit(originator, contactpoint, damage); 222 223 // play hit effect 224 } 225 } 280 226 281 227 void Pawn::kill()
Note: See TracChangeset
for help on using the changeset viewer.