Changeset 11052 for code/trunk/src/orxonox/worldentities/pawns/Pawn.cc
- Timestamp:
- Jan 9, 2016, 6:26:20 PM (8 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/worldentities/pawns/Pawn.cc
r10650 r11052 34 34 #include "core/GameMode.h" 35 35 #include "core/XMLPort.h" 36 #include "core/EventIncludes.h" 36 37 #include "network/NetworkFunction.h" 37 38 … … 41 42 #include "graphics/ParticleSpawner.h" 42 43 #include "worldentities/ExplosionChunk.h" 43 #include "worldentities/ BigExplosion.h"44 #include "worldentities/ExplosionPart.h" 44 45 #include "weaponsystem/WeaponSystem.h" 45 46 #include "weaponsystem/WeaponSlot.h" 46 47 #include "weaponsystem/WeaponPack.h" 47 48 #include "weaponsystem/WeaponSet.h" 49 #include "weaponsystem/Munition.h" 48 50 #include "sound/WorldSound.h" 49 51 … … 61 63 62 64 this->bAlive_ = true; 63 this->b Reload_ = false;65 this->bVulnerable_ = true; 64 66 65 67 this->health_ = 0; … … 71 73 this->maxShieldHealth_ = 100; //otherwise shield might increase to float_max 72 74 this->shieldAbsorption_ = 0.5; 73 74 this->reloadRate_ = 0; 75 this->reloadWaitTime_ = 1.0f; 76 this->reloadWaitCountdown_ = 0; 75 this->shieldRechargeRate_ = 0; 76 this->shieldRechargeWaitTime_ = 1.0f; 77 this->shieldRechargeWaitCountdown_ = 0; 77 78 78 79 this->lastHitOriginator_ = 0; … … 84 85 85 86 this->aimPosition_ = Vector3::ZERO; 87 88 //this->explosionPartList_ = NULL; 86 89 87 90 if (GameMode::isMaster()) … … 135 138 XMLPortParam(Pawn, "shieldabsorption", setShieldAbsorption, getShieldAbsorption, xmlelement, mode).defaultValues(0); 136 139 140 XMLPortParam(Pawn, "vulnerable", setVulnerable, isVulnerable, xmlelement, mode).defaultValues(true); 141 137 142 XMLPortParam(Pawn, "spawnparticlesource", setSpawnParticleSource, getSpawnParticleSource, xmlelement, mode); 138 143 XMLPortParam(Pawn, "spawnparticleduration", setSpawnParticleDuration, getSpawnParticleDuration, xmlelement, mode).defaultValues(3.0f); 139 XMLPortParam(Pawn, "explosionchunks", setExplosionChunks, getExplosionChunks, xmlelement, mode).defaultValues( 7);144 XMLPortParam(Pawn, "explosionchunks", setExplosionChunks, getExplosionChunks, xmlelement, mode).defaultValues(0); 140 145 141 146 XMLPortObject(Pawn, WeaponSlot, "weaponslots", addWeaponSlot, getWeaponSlot, xmlelement, mode); 142 147 XMLPortObject(Pawn, WeaponSet, "weaponsets", addWeaponSet, getWeaponSet, xmlelement, mode); 143 XMLPortObject(Pawn, WeaponPack, "weapons", addWeaponPackXML, getWeaponPack, xmlelement, mode); 144 145 XMLPortParam(Pawn, "reloadrate", setReloadRate, getReloadRate, xmlelement, mode).defaultValues(0); 146 XMLPortParam(Pawn, "reloadwaittime", setReloadWaitTime, getReloadWaitTime, xmlelement, mode).defaultValues(1.0f); 148 XMLPortObject(Pawn, WeaponPack, "weaponpacks", addWeaponPackXML, getWeaponPack, xmlelement, mode); 149 XMLPortObject(Pawn, Munition, "munition", addMunitionXML, getMunitionXML, xmlelement, mode); 150 151 XMLPortObject(Pawn, ExplosionPart, "explosion", addExplosionPart, getExplosionPart, xmlelement, mode); 152 XMLPortParam(Pawn, "shieldrechargerate", setShieldRechargeRate, getShieldRechargeRate, xmlelement, mode).defaultValues(0); 153 XMLPortParam(Pawn, "shieldrechargewaittime", setShieldRechargeWaitTime, getShieldRechargeWaitTime, xmlelement, mode).defaultValues(1.0f); 147 154 148 155 XMLPortParam(Pawn, "explosionSound", setExplosionSound, getExplosionSound, xmlelement, mode); … … 151 158 } 152 159 160 void Pawn::XMLEventPort(Element& xmlelement, XMLPort::Mode mode) 161 { 162 SUPER(Pawn, XMLEventPort, xmlelement, mode); 163 164 XMLPortEventState(Pawn, BaseObject, "vulnerability", setVulnerable, xmlelement, mode); 165 } 166 153 167 void Pawn::registerVariables() 154 168 { 155 registerVariable(this->bAlive_, VariableDirection::ToClient); 156 registerVariable(this->health_, VariableDirection::ToClient); 157 registerVariable(this->maxHealth_, VariableDirection::ToClient); 158 registerVariable(this->shieldHealth_, VariableDirection::ToClient); 159 registerVariable(this->maxShieldHealth_, VariableDirection::ToClient); 160 registerVariable(this->shieldAbsorption_, VariableDirection::ToClient); 161 registerVariable(this->bReload_, VariableDirection::ToServer); 162 registerVariable(this->aimPosition_, VariableDirection::ToServer); // For the moment this variable gets only transfered to the server 169 registerVariable(this->bAlive_, VariableDirection::ToClient); 170 registerVariable(this->health_, VariableDirection::ToClient); 171 registerVariable(this->maxHealth_, VariableDirection::ToClient); 172 registerVariable(this->shieldHealth_, VariableDirection::ToClient); 173 registerVariable(this->maxShieldHealth_, VariableDirection::ToClient); 174 registerVariable(this->shieldAbsorption_, VariableDirection::ToClient); 175 registerVariable(this->aimPosition_, VariableDirection::ToServer); // For the moment this variable gets only transfered to the server 163 176 } 164 177 165 178 void Pawn::tick(float dt) 166 179 { 180 //BigExplosion* chunk = new BigExplosion(this->getContext()); 167 181 SUPER(Pawn, tick, dt); 168 182 169 this->bReload_ = false; 170 183 // Recharge the shield 171 184 // TODO: use the existing timer functions instead 172 if(this-> reloadWaitCountdown_ > 0)173 { 174 this->decrease ReloadCountdownTime(dt);175 } 176 else 177 { 178 this->addShieldHealth(this->get ReloadRate() * dt);179 this->reset ReloadCountdown();185 if(this->shieldRechargeWaitCountdown_ > 0) 186 { 187 this->decreaseShieldRechargeCountdownTime(dt); 188 } 189 else 190 { 191 this->addShieldHealth(this->getShieldRechargeRate() * dt); 192 this->resetShieldRechargeCountdown(); 180 193 } 181 194 … … 229 242 } 230 243 231 void Pawn::setReloadRate(float reloadrate) 232 { 233 this->reloadRate_ = reloadrate; 234 } 235 236 void Pawn::setReloadWaitTime(float reloadwaittime) 237 { 238 this->reloadWaitTime_ = reloadwaittime; 239 } 240 241 void Pawn::decreaseReloadCountdownTime(float dt) 242 { 243 this->reloadWaitCountdown_ -= dt; 244 void Pawn::setShieldRechargeRate(float shieldRechargeRate) 245 { 246 this->shieldRechargeRate_ = shieldRechargeRate; 247 } 248 249 void Pawn::setShieldRechargeWaitTime(float shieldRechargeWaitTime) 250 { 251 this->shieldRechargeWaitTime_ = shieldRechargeWaitTime; 252 } 253 254 void Pawn::decreaseShieldRechargeCountdownTime(float dt) 255 { 256 this->shieldRechargeWaitCountdown_ -= dt; 257 } 258 259 void Pawn::changedVulnerability() 260 { 261 244 262 } 245 263 246 264 void Pawn::damage(float damage, float healthdamage, float shielddamage, Pawn* originator, const btCollisionShape* cs) 247 265 { 266 // A pawn can only get damaged if it is vulnerable 267 if (!isVulnerable()) 268 { 269 return; 270 } 271 248 272 // Applies multiplier given by the DamageBoost Pickup. 249 273 if (originator) … … 252 276 if (this->getGametype() && this->getGametype()->allowPawnDamage(this, originator)) 253 277 { 278 // Health-damage cannot be absorbed by shields. 279 // Shield-damage only reduces shield health. 280 // Normal damage can be (partially) absorbed by shields. 281 254 282 if (shielddamage >= this->getShieldHealth()) 255 283 { … … 366 394 if (GameMode::isMaster()) 367 395 { 368 this->deatheffect();369 396 this->goWithStyle(); 370 397 } … … 373 400 void Pawn::goWithStyle() 374 401 { 402 375 403 this->bAlive_ = false; 376 404 this->setDestroyWhenPlayerLeft(false); 377 405 378 BigExplosion* chunk = new BigExplosion(this->getContext()); 379 chunk->setPosition(this->getPosition()); 380 chunk->setVelocity(this->getVelocity()); 406 while(!explosionPartList_.empty()) 407 { 408 explosionPartList_.back()->setPosition(this->getPosition()); 409 explosionPartList_.back()->setVelocity(this->getVelocity()); 410 explosionPartList_.back()->setOrientation(this->getOrientation()); 411 explosionPartList_.back()->Explode(); 412 explosionPartList_.pop_back(); 413 } 414 415 for (unsigned int i = 0; i < this->numexplosionchunks_; ++i) 416 { 417 ExplosionChunk* chunk = new ExplosionChunk(this->getContext()); 418 chunk->setPosition(this->getPosition()); 419 } 381 420 382 421 this->explosionSound_->setPosition(this->getPosition()); 383 422 this->explosionSound_->play(); 384 }385 void Pawn::deatheffect()386 {387 // play death effect388 /*{389 ParticleSpawner* effect = new ParticleSpawner(this->getContext());390 effect->setPosition(this->getPosition());391 effect->setOrientation(this->getOrientation());392 effect->setDestroyAfterLife(true);393 effect->setSource("Orxonox/explosion2b");394 effect->setLifetime(4.0f);395 }396 {397 ParticleSpawner* effect = new ParticleSpawner(this->getContext());398 effect->setPosition(this->getPosition());399 effect->setOrientation(this->getOrientation());400 effect->setDestroyAfterLife(true);401 effect->setSource("Orxonox/smoke6");402 effect->setLifetime(4.0f);403 }404 {405 ParticleSpawner* effect = new ParticleSpawner(this->getContext());406 effect->setPosition(this->getPosition());407 effect->setOrientation(this->getOrientation());408 effect->setDestroyAfterLife(true);409 effect->setSource("Orxonox/sparks");410 effect->setLifetime(4.0f);411 }*/412 413 414 {415 ParticleSpawner* effect = new ParticleSpawner(this->getContext());416 effect->setPosition(this->getPosition());417 effect->setOrientation(this->getOrientation());418 effect->setDestroyAfterLife(true);419 effect->setSource("orxonox/explosion_flash2");420 effect->setLifetime(5.0f);421 }422 {423 ParticleSpawner* effect = new ParticleSpawner(this->getContext());424 effect->setPosition(this->getPosition());425 effect->setOrientation(this->getOrientation());426 effect->setDestroyAfterLife(true);427 effect->setSource("orxonox/explosion_flame2");428 effect->setLifetime(5.0f);429 }430 {431 ParticleSpawner* effect = new ParticleSpawner(this->getContext());432 effect->setPosition(this->getPosition());433 effect->setOrientation(this->getOrientation());434 effect->setDestroyAfterLife(true);435 effect->setSource("orxonox/explosion_shockwave2");436 effect->scale(20);437 effect->setLifetime(5.0f);438 }{439 ParticleSpawner* effect = new ParticleSpawner(this->getContext());440 effect->setPosition(this->getPosition());441 effect->setOrientation(this->getOrientation());442 effect->setDestroyAfterLife(true);443 effect->setSource("orxonox/explosion_sparks2");444 effect->setLifetime(5.0f);445 }446 {447 ParticleSpawner* effect = new ParticleSpawner(this->getContext());448 effect->setPosition(this->getPosition());449 effect->setOrientation(this->getOrientation());450 effect->setDestroyAfterLife(true);451 effect->setSource("orxonox/explosion_streak2");452 effect->setLifetime(5.0f);453 }454 {455 ParticleSpawner* effect = new ParticleSpawner(this->getContext());456 effect->setPosition(this->getPosition());457 effect->setOrientation(this->getOrientation());458 effect->setDestroyAfterLife(true);459 effect->setSource("orxonox/explosion_afterglow");460 effect->scale(20);461 effect->setLifetime(5.0f);462 }463 464 465 for (unsigned int i = 0; i < this->numexplosionchunks_; ++i)466 {467 ExplosionChunk* chunk = new ExplosionChunk(this->getContext());468 chunk->setPosition(this->getPosition());469 }470 423 } 471 424 … … 474 427 Check whether the Pawn has a @ref Orxonox::WeaponSystem and fire it with the specified firemode if it has one. 475 428 */ 429 476 430 void Pawn::fired(unsigned int firemode) 477 431 { 478 432 if (this->weaponSystem_) 479 433 this->weaponSystem_->fire(firemode); 480 }481 482 void Pawn::reload()483 {484 this->bReload_ = true;485 434 } 486 435 … … 491 440 this->spawneffect(); 492 441 } 442 443 444 void Pawn::addExplosionPart(ExplosionPart* ePart) 445 {this->explosionPartList_.push_back(ePart);} 446 447 448 ExplosionPart * Pawn::getExplosionPart() 449 {return this->explosionPartList_.back();} 450 451 493 452 494 453 /* WeaponSystem: … … 554 513 } 555 514 515 std::vector<WeaponPack *> * Pawn::getAllWeaponPacks() 516 { 517 if (this->weaponSystem_) 518 return this->weaponSystem_->getAllWeaponPacks(); 519 else 520 return 0; 521 } 522 523 void Pawn::addMunitionXML(Munition* munition) 524 { 525 if (this->weaponSystem_ && munition) 526 { 527 this->weaponSystem_->addMunition(munition); 528 } 529 } 530 531 Munition* Pawn::getMunitionXML() const 532 { 533 return NULL; 534 } 535 536 Munition* Pawn::getMunition(SubclassIdentifier<Munition> * identifier) 537 { 538 if (weaponSystem_) 539 { 540 return weaponSystem_->getMunition(identifier); 541 } 542 543 return NULL; 544 } 545 556 546 //Tell the Map (RadarViewable), if this is a playership 557 547 void Pawn::startLocalHumanControl() 558 548 { 559 // SUPER(ControllableEntity, changedPlayer());549 // SUPER(ControllableEntity, startLocalHumanControl()); 560 550 ControllableEntity::startLocalHumanControl(); 561 551 this->isHumanShip_ = true;
Note: See TracChangeset
for help on using the changeset viewer.