Index: code/trunk/src/orxonox/worldentities/pawns/Pawn.cc
===================================================================
--- code/trunk/src/orxonox/worldentities/pawns/Pawn.cc	(revision 10650)
+++ code/trunk/src/orxonox/worldentities/pawns/Pawn.cc	(revision 11052)
@@ -34,4 +34,5 @@
 #include "core/GameMode.h"
 #include "core/XMLPort.h"
+#include "core/EventIncludes.h"
 #include "network/NetworkFunction.h"
 
@@ -41,9 +42,10 @@
 #include "graphics/ParticleSpawner.h"
 #include "worldentities/ExplosionChunk.h"
-#include "worldentities/BigExplosion.h"
+#include "worldentities/ExplosionPart.h"
 #include "weaponsystem/WeaponSystem.h"
 #include "weaponsystem/WeaponSlot.h"
 #include "weaponsystem/WeaponPack.h"
 #include "weaponsystem/WeaponSet.h"
+#include "weaponsystem/Munition.h"
 #include "sound/WorldSound.h"
 
@@ -61,5 +63,5 @@
 
         this->bAlive_ = true;
-        this->bReload_ = false;
+        this->bVulnerable_ = true;
 
         this->health_ = 0;
@@ -71,8 +73,7 @@
         this->maxShieldHealth_ = 100; //otherwise shield might increase to float_max
         this->shieldAbsorption_ = 0.5;
-
-        this->reloadRate_ = 0;
-        this->reloadWaitTime_ = 1.0f;
-        this->reloadWaitCountdown_ = 0;
+        this->shieldRechargeRate_ = 0;
+        this->shieldRechargeWaitTime_ = 1.0f;
+        this->shieldRechargeWaitCountdown_ = 0;
 
         this->lastHitOriginator_ = 0;
@@ -84,4 +85,6 @@
 
         this->aimPosition_ = Vector3::ZERO;
+
+        //this->explosionPartList_ = NULL;
 
         if (GameMode::isMaster())
@@ -135,14 +138,18 @@
         XMLPortParam(Pawn, "shieldabsorption", setShieldAbsorption, getShieldAbsorption, xmlelement, mode).defaultValues(0);
 
+        XMLPortParam(Pawn, "vulnerable", setVulnerable, isVulnerable, xmlelement, mode).defaultValues(true);
+
         XMLPortParam(Pawn, "spawnparticlesource", setSpawnParticleSource, getSpawnParticleSource, xmlelement, mode);
         XMLPortParam(Pawn, "spawnparticleduration", setSpawnParticleDuration, getSpawnParticleDuration, xmlelement, mode).defaultValues(3.0f);
-        XMLPortParam(Pawn, "explosionchunks", setExplosionChunks, getExplosionChunks, xmlelement, mode).defaultValues(7);
+        XMLPortParam(Pawn, "explosionchunks", setExplosionChunks, getExplosionChunks, xmlelement, mode).defaultValues(0);
 
         XMLPortObject(Pawn, WeaponSlot, "weaponslots", addWeaponSlot, getWeaponSlot, xmlelement, mode);
         XMLPortObject(Pawn, WeaponSet, "weaponsets", addWeaponSet, getWeaponSet, xmlelement, mode);
-        XMLPortObject(Pawn, WeaponPack, "weapons", addWeaponPackXML, getWeaponPack, xmlelement, mode);
-
-        XMLPortParam(Pawn, "reloadrate", setReloadRate, getReloadRate, xmlelement, mode).defaultValues(0);
-        XMLPortParam(Pawn, "reloadwaittime", setReloadWaitTime, getReloadWaitTime, xmlelement, mode).defaultValues(1.0f);
+        XMLPortObject(Pawn, WeaponPack, "weaponpacks", addWeaponPackXML, getWeaponPack, xmlelement, mode);
+        XMLPortObject(Pawn, Munition, "munition", addMunitionXML, getMunitionXML, xmlelement, mode);
+
+        XMLPortObject(Pawn, ExplosionPart, "explosion", addExplosionPart, getExplosionPart, xmlelement, mode);
+        XMLPortParam(Pawn, "shieldrechargerate", setShieldRechargeRate, getShieldRechargeRate, xmlelement, mode).defaultValues(0);
+        XMLPortParam(Pawn, "shieldrechargewaittime", setShieldRechargeWaitTime, getShieldRechargeWaitTime, xmlelement, mode).defaultValues(1.0f);
 
         XMLPortParam(Pawn, "explosionSound",  setExplosionSound,  getExplosionSound,  xmlelement, mode);
@@ -151,31 +158,37 @@
     }
 
+    void Pawn::XMLEventPort(Element& xmlelement, XMLPort::Mode mode)
+    {
+        SUPER(Pawn, XMLEventPort, xmlelement, mode);
+
+        XMLPortEventState(Pawn, BaseObject, "vulnerability", setVulnerable, xmlelement, mode);
+    }
+
     void Pawn::registerVariables()
     {
-        registerVariable(this->bAlive_,           VariableDirection::ToClient);
-        registerVariable(this->health_,           VariableDirection::ToClient);
-        registerVariable(this->maxHealth_,        VariableDirection::ToClient);
-        registerVariable(this->shieldHealth_,     VariableDirection::ToClient);
-        registerVariable(this->maxShieldHealth_,  VariableDirection::ToClient);
-        registerVariable(this->shieldAbsorption_, VariableDirection::ToClient);
-        registerVariable(this->bReload_,          VariableDirection::ToServer);
-        registerVariable(this->aimPosition_,      VariableDirection::ToServer);  // For the moment this variable gets only transfered to the server
+        registerVariable(this->bAlive_,            VariableDirection::ToClient);
+        registerVariable(this->health_,            VariableDirection::ToClient);
+        registerVariable(this->maxHealth_,         VariableDirection::ToClient);
+        registerVariable(this->shieldHealth_,      VariableDirection::ToClient);
+        registerVariable(this->maxShieldHealth_,   VariableDirection::ToClient);
+        registerVariable(this->shieldAbsorption_,  VariableDirection::ToClient);
+        registerVariable(this->aimPosition_,       VariableDirection::ToServer);  // For the moment this variable gets only transfered to the server
     }
 
     void Pawn::tick(float dt)
     {
+        //BigExplosion* chunk = new BigExplosion(this->getContext());
         SUPER(Pawn, tick, dt);
 
-        this->bReload_ = false;
-
+        // Recharge the shield
         // TODO: use the existing timer functions instead
-        if(this->reloadWaitCountdown_ > 0)
-        {
-            this->decreaseReloadCountdownTime(dt);
-        }
-        else
-        {
-            this->addShieldHealth(this->getReloadRate() * dt);
-            this->resetReloadCountdown();
+        if(this->shieldRechargeWaitCountdown_ > 0)
+        {
+            this->decreaseShieldRechargeCountdownTime(dt);
+        }
+        else
+        {
+            this->addShieldHealth(this->getShieldRechargeRate() * dt);
+            this->resetShieldRechargeCountdown();
         }
 
@@ -229,21 +242,32 @@
     }
 
-    void Pawn::setReloadRate(float reloadrate)
-    {
-        this->reloadRate_ = reloadrate;
-    }
-
-    void Pawn::setReloadWaitTime(float reloadwaittime)
-    {
-        this->reloadWaitTime_ = reloadwaittime;
-    }
-
-    void Pawn::decreaseReloadCountdownTime(float dt)
-    {
-        this->reloadWaitCountdown_ -= dt;
+    void Pawn::setShieldRechargeRate(float shieldRechargeRate)
+    {
+        this->shieldRechargeRate_ = shieldRechargeRate;
+    }
+
+    void Pawn::setShieldRechargeWaitTime(float shieldRechargeWaitTime)
+    {
+        this->shieldRechargeWaitTime_ = shieldRechargeWaitTime;
+    }
+
+    void Pawn::decreaseShieldRechargeCountdownTime(float dt)
+    {
+        this->shieldRechargeWaitCountdown_ -= dt;
+    }
+
+    void Pawn::changedVulnerability()
+    {
+
     }
 
     void Pawn::damage(float damage, float healthdamage, float shielddamage, Pawn* originator, const btCollisionShape* cs)
     {
+        // A pawn can only get damaged if it is vulnerable
+        if (!isVulnerable())
+        {
+            return;
+        }
+
         // Applies multiplier given by the DamageBoost Pickup.
         if (originator)
@@ -252,4 +276,8 @@
         if (this->getGametype() && this->getGametype()->allowPawnDamage(this, originator))
         {
+            // Health-damage cannot be absorbed by shields.
+            // Shield-damage only reduces shield health. 
+            // Normal damage can be (partially) absorbed by shields.
+
             if (shielddamage >= this->getShieldHealth())
             {
@@ -366,5 +394,4 @@
             if (GameMode::isMaster())
             {
-                this->deatheffect();
                 this->goWithStyle();
             }
@@ -373,99 +400,25 @@
     void Pawn::goWithStyle()
     {
+
         this->bAlive_ = false;
         this->setDestroyWhenPlayerLeft(false);
 
-        BigExplosion* chunk = new BigExplosion(this->getContext());
-        chunk->setPosition(this->getPosition());
-        chunk->setVelocity(this->getVelocity());
+        while(!explosionPartList_.empty())
+        {
+            explosionPartList_.back()->setPosition(this->getPosition());
+            explosionPartList_.back()->setVelocity(this->getVelocity());
+            explosionPartList_.back()->setOrientation(this->getOrientation());
+            explosionPartList_.back()->Explode();
+            explosionPartList_.pop_back();
+        }
+
+        for (unsigned int i = 0; i < this->numexplosionchunks_; ++i)
+        {
+            ExplosionChunk* chunk = new ExplosionChunk(this->getContext());
+            chunk->setPosition(this->getPosition());
+        }
 
         this->explosionSound_->setPosition(this->getPosition());
         this->explosionSound_->play();
-    }
-    void Pawn::deatheffect()
-    {
-        // play death effect
-        /*{
-            ParticleSpawner* effect = new ParticleSpawner(this->getContext());
-            effect->setPosition(this->getPosition());
-            effect->setOrientation(this->getOrientation());
-            effect->setDestroyAfterLife(true);
-            effect->setSource("Orxonox/explosion2b");
-            effect->setLifetime(4.0f);
-        }
-        {
-            ParticleSpawner* effect = new ParticleSpawner(this->getContext());
-            effect->setPosition(this->getPosition());
-            effect->setOrientation(this->getOrientation());
-            effect->setDestroyAfterLife(true);
-            effect->setSource("Orxonox/smoke6");
-            effect->setLifetime(4.0f);
-        }
-        {
-            ParticleSpawner* effect = new ParticleSpawner(this->getContext());
-            effect->setPosition(this->getPosition());
-            effect->setOrientation(this->getOrientation());
-            effect->setDestroyAfterLife(true);
-            effect->setSource("Orxonox/sparks");
-            effect->setLifetime(4.0f);
-        }*/
-        
-        
-        {
-            ParticleSpawner* effect = new ParticleSpawner(this->getContext());
-            effect->setPosition(this->getPosition());
-            effect->setOrientation(this->getOrientation());
-            effect->setDestroyAfterLife(true);
-            effect->setSource("orxonox/explosion_flash2");
-            effect->setLifetime(5.0f);
-        }
-        {
-            ParticleSpawner* effect = new ParticleSpawner(this->getContext());
-            effect->setPosition(this->getPosition());
-            effect->setOrientation(this->getOrientation());
-            effect->setDestroyAfterLife(true);
-            effect->setSource("orxonox/explosion_flame2");
-            effect->setLifetime(5.0f);
-        }
-        {
-            ParticleSpawner* effect = new ParticleSpawner(this->getContext());
-            effect->setPosition(this->getPosition());
-            effect->setOrientation(this->getOrientation());
-            effect->setDestroyAfterLife(true);
-            effect->setSource("orxonox/explosion_shockwave2");
-            effect->scale(20);
-            effect->setLifetime(5.0f);
-        }{
-            ParticleSpawner* effect = new ParticleSpawner(this->getContext());
-            effect->setPosition(this->getPosition());
-            effect->setOrientation(this->getOrientation());
-            effect->setDestroyAfterLife(true);
-            effect->setSource("orxonox/explosion_sparks2");
-            effect->setLifetime(5.0f);
-        }
-        {
-            ParticleSpawner* effect = new ParticleSpawner(this->getContext());
-            effect->setPosition(this->getPosition());
-            effect->setOrientation(this->getOrientation());
-            effect->setDestroyAfterLife(true);
-            effect->setSource("orxonox/explosion_streak2");
-            effect->setLifetime(5.0f);
-        }
-        {
-            ParticleSpawner* effect = new ParticleSpawner(this->getContext());
-            effect->setPosition(this->getPosition());
-            effect->setOrientation(this->getOrientation());
-            effect->setDestroyAfterLife(true);
-            effect->setSource("orxonox/explosion_afterglow");
-            effect->scale(20);
-            effect->setLifetime(5.0f);
-        }
-        
-        
-        for (unsigned int i = 0; i < this->numexplosionchunks_; ++i)
-        {
-            ExplosionChunk* chunk = new ExplosionChunk(this->getContext());
-            chunk->setPosition(this->getPosition());
-        }
     }
 
@@ -474,13 +427,9 @@
         Check whether the Pawn has a @ref Orxonox::WeaponSystem and fire it with the specified firemode if it has one.
     */
+
     void Pawn::fired(unsigned int firemode)
     {
         if (this->weaponSystem_)
             this->weaponSystem_->fire(firemode);
-    }
-
-    void Pawn::reload()
-    {
-        this->bReload_ = true;
     }
 
@@ -491,4 +440,14 @@
             this->spawneffect();
     }
+
+
+    void Pawn::addExplosionPart(ExplosionPart* ePart)
+    {this->explosionPartList_.push_back(ePart);}
+
+
+    ExplosionPart * Pawn::getExplosionPart()
+    {return this->explosionPartList_.back();}
+
+
 
     /* WeaponSystem:
@@ -554,8 +513,39 @@
     }
 
+    std::vector<WeaponPack *> * Pawn::getAllWeaponPacks()
+    {
+        if (this->weaponSystem_)
+            return this->weaponSystem_->getAllWeaponPacks();
+        else
+            return 0;        
+    }
+
+    void Pawn::addMunitionXML(Munition* munition)
+    {
+        if (this->weaponSystem_ && munition)
+        {
+            this->weaponSystem_->addMunition(munition);
+        }
+    }
+
+    Munition* Pawn::getMunitionXML() const
+    {
+        return NULL;
+    }
+
+    Munition* Pawn::getMunition(SubclassIdentifier<Munition> * identifier)
+    {
+        if (weaponSystem_)
+        {
+            return weaponSystem_->getMunition(identifier);
+        }
+
+        return NULL;
+    }
+
     //Tell the Map (RadarViewable), if this is a playership
     void Pawn::startLocalHumanControl()
     {
-//        SUPER(ControllableEntity, changedPlayer());
+//        SUPER(ControllableEntity, startLocalHumanControl());
         ControllableEntity::startLocalHumanControl();
         this->isHumanShip_ = true;
