Index: code/branches/modularships/data/levels/emptyLevel.oxw
===================================================================
--- code/branches/modularships/data/levels/emptyLevel.oxw	(revision 10022)
+++ code/branches/modularships/data/levels/emptyLevel.oxw	(revision 10023)
@@ -98,5 +98,5 @@
     </ModularSpaceShip>
     
-    <ModularSpaceShip position="0,-1000,-200">
+    <ModularSpaceShip position="0,-1000,-200" health="1000" maxhealth="2000" initialhealth="1000">
       <templates>
         <Template link=HeavyCruiser />
Index: code/branches/modularships/data/levels/templates/HeavyCruiser.oxt
===================================================================
--- code/branches/modularships/data/levels/templates/HeavyCruiser.oxt	(revision 10022)
+++ code/branches/modularships/data/levels/templates/HeavyCruiser.oxt	(revision 10023)
@@ -11,7 +11,7 @@
    explosionchunks        = 6
 
-   health            = 100
-   maxhealth         = 200
-   initialhealth     = 100
+   health            = 1000
+   maxhealth         = 2000
+   initialhealth     = 1000
 
    shieldhealth        = 100
@@ -51,6 +51,12 @@
     
     <parts>
-        <ShipPart name="frontL" />
-        <ShipPart name="frontR" />
+        <ShipPart name="frontL" health="100" damageabsorption="0.5" />
+        <ShipPart name="frontR" health="100" damageabsorption="0.5" />
+        <ShipPart name="partL" health="100" damageabsorption="0.5" />
+        <ShipPart name="partR" health="100" damageabsorption="0.5" />
+        <ShipPart name="sidearmL" health="201" damageabsorption="0.2" />
+        <ShipPart name="sidearmLfront" health="100" damageabsorption="0.5" />
+        <ShipPart name="sidearmR" health="200" damageabsorption="0.2" />
+        <ShipPart name="sidearmRfront" health="100" damageabsorption="0.5" />
     </parts>
     
@@ -61,4 +67,7 @@
             <attached> 
                 <Model mesh="HeavyCruiser_frontL.mesh" direction="-1,0,0" position="0,0,0" scale="40"/>
+                <BlinkingBillboard position="-75,30,-416" material="Examples/Flare" colour="0.8, 0.8, 0, 0.1" amplitude=0.05 frequency=0.3 phase=240 quadratic=1 />
+                <BlinkingBillboard position="-74,30,-402" material="Examples/Flare" colour="0.8, 0.8, 0, 0.1" amplitude=0.1 frequency=0.3 phase=120 quadratic=1 />
+                <BlinkingBillboard position="-73,30,-388" material="Examples/Flare" colour="0.8, 0.8, 0, 0.1" amplitude=0.15 frequency=0.3 phase=0 quadratic=1 />
             </attached> 
             <collisionShapes> 
@@ -71,4 +80,7 @@
             <attached> 
                 <Model mesh="HeavyCruiser_frontR.mesh" direction="-1,0,0" position="0,0,0" scale="40"/>
+                <BlinkingBillboard position="75,30,-416" material="Examples/Flare" colour="0.8, 0.8, 0, 0.1" amplitude=0.05 frequency=0.3 phase=240 quadratic=1 />
+                <BlinkingBillboard position="74,30,-402" material="Examples/Flare" colour="0.8, 0.8, 0, 0.1" amplitude=0.1 frequency=0.3 phase=120 quadratic=1 />
+                <BlinkingBillboard position="73,30,-388" material="Examples/Flare" colour="0.8, 0.8, 0, 0.1" amplitude=0.15 frequency=0.3 phase=0 quadratic=1 />
             </attached> 
             <collisionShapes> 
@@ -176,11 +188,4 @@
         </StaticEntity>   
 
-            <!-- bay1 lights -->
-        <BlinkingBillboard position="75,30,-416" material="Examples/Flare" colour="0.8, 0.8, 0, 0.1" amplitude=0.05 frequency=0.3 phase=240 quadratic=1 />
-        <BlinkingBillboard position="-75,30,-416" material="Examples/Flare" colour="0.8, 0.8, 0, 0.1" amplitude=0.05 frequency=0.3 phase=240 quadratic=1 />
-        <BlinkingBillboard position="74,30,-402" material="Examples/Flare" colour="0.8, 0.8, 0, 0.1" amplitude=0.1 frequency=0.3 phase=120 quadratic=1 />
-        <BlinkingBillboard position="-74,30,-402" material="Examples/Flare" colour="0.8, 0.8, 0, 0.1" amplitude=0.1 frequency=0.3 phase=120 quadratic=1 />
-        <BlinkingBillboard position="73,30,-388" material="Examples/Flare" colour="0.8, 0.8, 0, 0.1" amplitude=0.15 frequency=0.3 phase=0 quadratic=1 />
-        <BlinkingBillboard position="-73,30,-388" material="Examples/Flare" colour="0.8, 0.8, 0, 0.1" amplitude=0.15 frequency=0.3 phase=0 quadratic=1 />
             <!-- front position lights -->
         <BlinkingBillboard position="67,-5,-240" material="Examples/Flare" colour="0, 0.7, 0, 0.1" amplitude=0.3 frequency=0.15 phase=0 quadratic=1 />
Index: code/branches/modularships/src/orxonox/OrxonoxPrereqs.h
===================================================================
--- code/branches/modularships/src/orxonox/OrxonoxPrereqs.h	(revision 10022)
+++ code/branches/modularships/src/orxonox/OrxonoxPrereqs.h	(revision 10023)
@@ -142,4 +142,5 @@
 
     // items
+    class ShipPart;
     class Engine;
     class Item;
@@ -189,4 +190,5 @@
     class Pawn;
     class SpaceShip;
+    class ModularSpaceShip;
     class Spectator;
     class TeamBaseMatchBase;
Index: code/branches/modularships/src/orxonox/items/ShipPart.cc
===================================================================
--- code/branches/modularships/src/orxonox/items/ShipPart.cc	(revision 10022)
+++ code/branches/modularships/src/orxonox/items/ShipPart.cc	(revision 10023)
@@ -37,4 +37,5 @@
 #include "Item.h"
 #include "worldentities/pawns/Pawn.h"
+#include "worldentities/pawns/ModularSpaceShip.h"
 #include "gametypes/Gametype.h"
 #include "worldentities/StaticEntity.h"
@@ -56,4 +57,37 @@
     }
 
+    void ShipPart::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+    {
+        SUPER(ShipPart, XMLPort, xmlelement, mode);
+
+        XMLPortParam(ShipPart, "health", setHealth, getHealth, xmlelement, mode).defaultValues(100);
+        XMLPortParam(ShipPart, "maxhealth", setMaxHealth, getMaxHealth, xmlelement, mode).defaultValues(200);
+        XMLPortParam(ShipPart, "initialhealth", setInitialHealth, getInitialHealth, xmlelement, mode).defaultValues(100);
+
+        XMLPortParam(ShipPart, "damageabsorption", setDamageAbsorption, getDamageAbsorption, xmlelement, mode).defaultValues(0.5);
+
+        /*
+        XMLPortParam(ShipPart, "shieldhealth", setShieldHealth, getShieldHealth, xmlelement, mode).defaultValues(0);
+        XMLPortParam(ShipPart, "initialshieldhealth", setInitialShieldHealth, getInitialShieldHealth, xmlelement, mode).defaultValues(0);
+        XMLPortParam(ShipPart, "maxshieldhealth", setMaxShieldHealth, getMaxShieldHealth, xmlelement, mode).defaultValues(100);
+        XMLPortParam(ShipPart, "shieldabsorption", setShieldAbsorption, getShieldAbsorption, xmlelement, mode).defaultValues(0);
+
+        XMLPortParam(ShipPart, "sShipPartparticlesource", setSShipPartParticleSource, getSShipPartParticleSource, xmlelement, mode);
+        XMLPortParam(ShipPart, "sShipPartparticleduration", setSShipPartParticleDuration, getSShipPartParticleDuration, xmlelement, mode).defaultValues(3.0f);
+        XMLPortParam(ShipPart, "explosionchunks", setExplosionChunks, getExplosionChunks, xmlelement, mode).defaultValues(7);
+
+        XMLPortParam(ShipPart, "reloadrate", setReloadRate, getReloadRate, xmlelement, mode).defaultValues(0);
+        XMLPortParam(ShipPart, "reloadwaittime", setReloadWaitTime, getReloadWaitTime, xmlelement, mode).defaultValues(1.0f);
+
+        XMLPortParam(ShipPart, "explosionSound",  setExplosionSound,  getExplosionSound,  xmlelement, mode);
+
+        XMLPortParam ( RadarViewable, "radarname", setRadarName, getRadarName, xmlelement, mode );
+        */
+    }
+
+    void ShipPart::death()
+    {
+        this->parent_->removeShipPart(this);
+    }
 
     /**
@@ -112,4 +146,9 @@
     {
         this->damageAbsorption_ = value;
+    }
+
+    void ShipPart::setParent(ModularSpaceShip* ship)
+    {
+        this->parent_ = ship;
     }
 
@@ -152,4 +191,7 @@
             }
         }
+        if (this->health_ < 0)
+            this->death();
+        orxout() << "Health of ShipPart " << this->getName() << " is " << this->getHealth() << endl;
     }
 
Index: code/branches/modularships/src/orxonox/items/ShipPart.h
===================================================================
--- code/branches/modularships/src/orxonox/items/ShipPart.h	(revision 10022)
+++ code/branches/modularships/src/orxonox/items/ShipPart.h	(revision 10023)
@@ -46,7 +46,9 @@
             virtual ~ShipPart();
 
-            //virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
 
             virtual void handleHit(float damage, float healthdamage, float shielddamage, Pawn* originator);
+
+            virtual void death();
 
             //virtual void attachTo(Pawn* newParent);
@@ -63,4 +65,8 @@
                 { return this->damageAbsorption_; }
 
+            void setParent(ModularSpaceShip* ship);
+            inline ModularSpaceShip* getParent()
+                { return this->parent_; }
+
             virtual void setHealth(float health);
             inline void addHealth(float health)
@@ -71,4 +77,14 @@
                 { return this->health_; }
 
+            inline void setMaxHealth(float maxhealth)
+                { this->maxHealth_ = maxhealth; this->setHealth(this->health_); }
+            inline float getMaxHealth() const
+                { return this->maxHealth_; }
+
+            inline void setInitialHealth(float initialhealth)
+                { this->initialHealth_ = initialhealth; this->setHealth(initialhealth); }
+            inline float getInitialHealth() const
+                { return this->initialHealth_; }
+
 
             // FIXME: (noep) Why doesn't this work? Works fine in Engine.h
@@ -76,9 +92,11 @@
 
         protected:
-            Pawn* parent_;
+            ModularSpaceShip* parent_;
             unsigned int parentID_; // Object ID of the SpaceShip the Part is mounted on.
 
             float damageAbsorption_;
             float health_;
+            float maxHealth_;
+            float initialHealth_;
 
         private:
Index: code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.cc
===================================================================
--- code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.cc	(revision 10022)
+++ code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.cc	(revision 10023)
@@ -88,5 +88,8 @@
                 if((this->partList_[j]->getName() == this->getAttachedObject(i)->getName()) && !this->partList_[j]->hasEntity(orxonox_cast<StaticEntity*>(this->getAttachedObject(i))))
                 {
+                    // The Entity is added to the part's entityList_
                     this->partList_[j]->addEntity(orxonox_cast<StaticEntity*>(this->getAttachedObject(i)));
+                    // An entry in the partMap_ is created, assigning the part to the entity.
+                    this->addPartEntityAssignment((StaticEntity*)(this->getAttachedObject(i)), this->partList_[j]);
                     orxout() << "A matching part-entity-pair with name " << this->partList_[j]->getName() << " was found!" << endl;
                     this->partList_[j]->printEntities(); // FIXME: (noep) remove debug
@@ -94,4 +97,10 @@
             }
         }
+
+        orxout() << "List of all assignments:" << endl;
+        for (std::map<StaticEntity*, ShipPart*>::const_iterator it = this->partMap_.begin(); it != this->partMap_.end(); ++it)
+                {
+                    orxout() << "Entity: " << it->first << "   Part: " << it->second << endl;
+                }
     }
 
@@ -143,7 +152,10 @@
         orxout() << "UserPtr of said collisionShape: " << cs->getUserPointer() << endl;
 
-        // List all attached Objects
+
+            // Print all attached objects & parts
+        /*
         orxout() << "  " << this->getName() << " has the following Objects attached:" << endl;
-        for (int i=0; i<10; i++)
+
+        for (int i=0; i<50; i++)
         {
             if (this->getAttachedObject(i)==NULL)
@@ -157,15 +169,20 @@
         {
             orxout() << "  " << i << ": " << this->partList_[i] << " (" << this->partList_[i]->getName() << ")" << endl;
-        }
+        }*/
+
 
         //int collisionShapeIndex = this->isMyCollisionShape(cs);
         //orxout() << collisionShapeIndex << endl;
 
-        orxout() << "ShipPart of Entity " << cs->getUserPointer() << ": " << this->getPartOfEntity((StaticEntity*)(cs->getUserPointer())) << endl;
+        //orxout() << "ShipPart of Entity " << cs->getUserPointer() << ": " << this->getPartOfEntity((StaticEntity*)(cs->getUserPointer())) << endl;
+
+        orxout() << "CP_start" << endl;
 
         if (this->getPartOfEntity((StaticEntity*)(cs->getUserPointer())) != NULL)
             this->getPartOfEntity((StaticEntity*)(cs->getUserPointer()))->handleHit(damage, healthdamage, shielddamage, originator);
-        //else
-        //    SpaceShip::damage(damage, healthdamage, shielddamage, originator, cs);
+        else
+            SpaceShip::damage(damage, healthdamage, shielddamage, originator, cs);
+
+        orxout() << "CP_end" << endl;
 
         /*
@@ -208,4 +225,5 @@
         OrxAssert(part != NULL, "The ShipPart cannot be NULL.");
         this->partList_.push_back(part);
+        part->setParent(this);
         //part->addToSpaceShip(this); //FIXME: (noep) add
         this->updatePartAssignment();
@@ -242,3 +260,24 @@
     }
 
+    void ModularSpaceShip::removeShipPart(ShipPart* part)
+    {
+        // Remove the part from the partList_
+        std::vector<ShipPart*>::iterator it = this->partList_.begin();
+        for(unsigned int i = 0; i < this->partList_.size(); i++)
+        {
+            if(this->partList_[i] == part)
+                this->partList_.erase(it);
+            it++;
+        }
+        // Remove the part-entity assignment and detach the Entity of this ShipPart
+        for (std::map<StaticEntity*, ShipPart*>::iterator itt = this->partMap_.begin(); itt != this->partMap_.end(); ++itt)
+        {
+            if (itt->second == part)
+            {
+                this->detach(itt->first);
+                this->partMap_.erase(itt);
+            }
+        }
+    }
+
 }
Index: code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.h
===================================================================
--- code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.h	(revision 10022)
+++ code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.h	(revision 10023)
@@ -48,5 +48,6 @@
     /**
     @brief
-        The ModularSpaceShip is the principal entity through which the player interacts with the game. Its main function is to fly, however many things, such as @ref orxonox::Engine Engines or @ref orxonox::Weapon Weapons, can be attached to it.
+        The SpaceShip is the principal entity through which the player interacts with the game. Its main function is to fly, however many things, such as @ref orxonox::Engine Engines or @ref orxonox::Weapon Weapons, can be attached to it.
+        The ModularSpaceShip is an extension of a @ref orxonox::SpaceShip SpaceShip, which uses @ref orxonox::ShipPart ShipParts to allow entities attached to it to be destroyed individually.
 
         There are several parameters that define the behavior of the ModularSpaceShip>
@@ -56,5 +57,7 @@
         - The <b>lift</b> creates a more natural flight feeling through the addition of a lift force. There are again tow parameters that can be specified. The <b>lift</b> which is the lift force that is applied. And the <b>stallSpeed</b> which is the forward speed after which no more lift is generated.
 
-        As mentioned @ref orxonox::Engine Engines can be mounted on the ModularSpaceShip. Here is a (primitive) example of a ModularSpaceShip defined in XML:
+        As mentioned @ref orxonox::Engine Engines can be mounted on the ModularSpaceShip.
+        In order to assign attached entities to a ShipPart, a ShipPart with the same name as the corresponding entity needs to be created in the <parts> tag.
+        Here is a (primitive) example of a ModularSpaceShip defined in XML:
         @code
         <ModularSpaceShip
@@ -77,4 +80,12 @@
             angularDamping    = 0.9999999
             >
+                <attached>
+                    <StaticEntity name="wing"  . . .  />
+                    <StaticEntity name="tail" . . . />
+                </attached>
+                <parts>
+                    <ShipPart name="wing" . . . />
+                    <ShipPart name="tail" . . . />
+                </parts>
                 <engines>
                     <Engine />
@@ -85,5 +96,5 @@
 
     @author
-        Fabian 'x3n' Landau
+        Fabian 'x3n' Landau, Noe Pedrazzini
     */
     class _OrxonoxExport ModularSpaceShip : public SpaceShip
@@ -105,4 +116,5 @@
             ShipPart* getShipPart(unsigned int index);
             bool hasShipPart(ShipPart* part) const;
+            void removeShipPart(ShipPart* part);
 
             virtual void updatePartAssignment();
Index: code/branches/modularships/src/orxonox/worldentities/pawns/Pawn.cc
===================================================================
--- code/branches/modularships/src/orxonox/worldentities/pawns/Pawn.cc	(revision 10022)
+++ code/branches/modularships/src/orxonox/worldentities/pawns/Pawn.cc	(revision 10023)
@@ -252,8 +252,9 @@
     void Pawn::damage(float damage, float healthdamage, float shielddamage, Pawn* originator, const btCollisionShape* cs)
     {
-        orxout() << "damage(): Collision detected on " << this->getName() << ", btCS*: " << cs << endl;
-
-        int collisionShapeIndex = this->isMyCollisionShape(cs);
-        orxout() << collisionShapeIndex << endl;
+        //FIXME: (noep) remove debug
+        //orxout() << "damage(): Collision detected on " << this->getName() << ", btCS*: " << cs << endl;
+
+        //int collisionShapeIndex = this->isMyCollisionShape(cs);
+        //orxout() << collisionShapeIndex << endl;
 
         // Applies multiplier given by the DamageBoost Pickup.
@@ -587,5 +588,5 @@
         // List all attached Objects
         orxout() << "  " << this->getName() << " has the following Objects attached:" << endl;
-        for (int i=0; i<10; i++)
+        for (int i=0; i<50; i++)
         {
             if (this->getAttachedObject(i)==NULL)
Index: code/branches/modularships/src/orxonox/worldentities/pawns/Pawn.h
===================================================================
--- code/branches/modularships/src/orxonox/worldentities/pawns/Pawn.h	(revision 10022)
+++ code/branches/modularships/src/orxonox/worldentities/pawns/Pawn.h	(revision 10023)
@@ -229,5 +229,5 @@
             unsigned int numexplosionchunks_;
 
-            virtual int isMyCollisionShape(const btCollisionShape* cs);
+            virtual int isMyCollisionShape(const btCollisionShape* cs); // FIXME: (noep) remove debug
             void printBtChildShapes(btCompoundShape* cs, int indent, int subshape); // FIXME: (noep) remove debug
             void printSpaces(int num);   // FIXME: (noep) remove debug
