Index: /code/branches/modularships/data/levels/templates/HeavyCruiser.oxt
===================================================================
--- /code/branches/modularships/data/levels/templates/HeavyCruiser.oxt	(revision 10051)
+++ /code/branches/modularships/data/levels/templates/HeavyCruiser.oxt	(revision 10052)
@@ -51,5 +51,9 @@
     
     <parts>
-        <ShipPart name="frontL" initialhealth="10" damageabsorption="0.5" />
+        <ShipPart name="frontL" initialhealth="10" damageabsorption="0.5">
+	    <destructionevents>
+		<PartDestructionEvent targetType="ship" targetParam="shieldhealth" operation="*" value="0.5"/>
+	    </destructionevents>
+	</ShipPart>
         <ShipPart name="frontR" initialhealth="10" damageabsorption="0.5" />
         <ShipPart name="partL" initialhealth="10" damageabsorption="0.5" />
Index: /code/branches/modularships/src/orxonox/OrxonoxPrereqs.h
===================================================================
--- /code/branches/modularships/src/orxonox/OrxonoxPrereqs.h	(revision 10051)
+++ /code/branches/modularships/src/orxonox/OrxonoxPrereqs.h	(revision 10052)
@@ -143,4 +143,5 @@
     // items
     class ShipPart;
+    class PartDestructionEvent;
     class Engine;
     class Item;
Index: /code/branches/modularships/src/orxonox/items/CMakeLists.txt
===================================================================
--- /code/branches/modularships/src/orxonox/items/CMakeLists.txt	(revision 10051)
+++ /code/branches/modularships/src/orxonox/items/CMakeLists.txt	(revision 10052)
@@ -4,3 +4,4 @@
   MultiStateEngine.cc
   ShipPart.cc
+  PartDestructionEvent.cc
 )
Index: /code/branches/modularships/src/orxonox/items/PartDestructionEvent.cc
===================================================================
--- /code/branches/modularships/src/orxonox/items/PartDestructionEvent.cc	(revision 10052)
+++ /code/branches/modularships/src/orxonox/items/PartDestructionEvent.cc	(revision 10052)
@@ -0,0 +1,152 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Noe Pedrazzini
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "PartDestructionEvent.h"
+
+#include <algorithm>
+
+#include "core/CoreIncludes.h"
+#include "core/GameMode.h"
+#include "core/XMLPort.h"
+#include "network/NetworkFunction.h"
+#include "Item.h"
+#include "worldentities/pawns/Pawn.h"
+#include "worldentities/pawns/ModularSpaceShip.h"
+#include "gametypes/Gametype.h"
+
+
+namespace orxonox
+{
+    RegisterClass(PartDestructionEvent);
+
+    PartDestructionEvent::PartDestructionEvent(Context* context)
+        : Item(context)
+    {
+        RegisterObject(PartDestructionEvent);
+        this->isValid_ = false;
+    }
+
+    PartDestructionEvent::~PartDestructionEvent()
+    {
+
+    }
+
+    void PartDestructionEvent::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+    {
+        SUPER(PartDestructionEvent, XMLPort, xmlelement, mode);
+
+        XMLPortParam(PartDestructionEvent, "targetType", setTargetType, getTargetType, xmlelement, mode).defaultValues("NULL");
+        XMLPortParam(PartDestructionEvent, "targetName", setTargetName, getTargetName, xmlelement, mode).defaultValues("NULL");
+        XMLPortParam(PartDestructionEvent, "targetParam", setTargetParam, getTargetParam, xmlelement, mode).defaultValues("NULL");
+        XMLPortParam(PartDestructionEvent, "operation", setOperation, getOperation, xmlelement, mode).defaultValues("NULL");
+        XMLPortParam(PartDestructionEvent, "value", setEventValue, getEventValue, xmlelement, mode).defaultValues(0);
+
+        /*
+        XMLPortParam(PartDestructionEvent, "health", setHealth, getHealth, xmlelement, mode).defaultValues(100);
+        XMLPortParam(PartDestructionEvent, "maxhealth", setMaxHealth, getMaxHealth, xmlelement, mode).defaultValues(200);
+        XMLPortParam(PartDestructionEvent, "initialhealth", setInitialHealth, getInitialHealth, xmlelement, mode).defaultValues(100);
+        */
+    }
+
+    void PartDestructionEvent::execute()
+    {
+        if(!this->isValid_)
+        {
+            //orxout(internal_warning) <<
+            return;
+        }
+
+
+    }
+
+    void PartDestructionEvent::setTargetType(std::string type)
+    {
+        // ship engine weapon
+        if ((type == "ship") || (type == "engine") || (type == "weapon"))
+        {
+            this->targetType_ = type;
+            return;
+        }
+
+        // Error, if invalid target-type was entered.
+        orxout(internal_warning) << type << " is not a valid target-type for a PartDestructionEvent. Valid types are: ship engine weapon" << endl;
+        this->isValid_ = false;
+        return;
+    }
+
+    void PartDestructionEvent::setTargetName(std::string name)
+    {
+        // Error, if the target-type is "weapon" or "engine", but the name of said target was not defined.
+        if (((this->targetType_ == "weapon") || (this->targetType_ == "engine")) && (name == "NULL"))
+        {
+            orxout(internal_warning) << "The target-name of a PartDestructionEvent with target-type \"" << this->targetType_ << "\" needs to be defined!" << endl;
+            return;
+        }
+
+        this->targetName_ = name;
+    }
+
+    void PartDestructionEvent::setTargetParam(std::string param)
+    {
+        if (this->targetType_ == "NULL")
+        {
+            orxout(internal_warning) << "No valid target-type defined. Cannot set target-param for this PartDestructionEvent." << endl;
+            this->isValid_ = false;
+            return;
+        }
+
+        // ship: shieldhealth maxshieldhealth shieldabsorption shieldrechargerate
+
+        // engine:
+
+        // weapon:
+
+        if (this->targetType_ == "ship")
+        {
+            if (param == "shieldhealth")
+            {
+                this->targetParam_ = param;
+                return;
+            }
+
+            orxout(internal_warning) << param << " is not a valid target-param for a PartDestructionEvent with target-type \"ship\". Valid types are: shieldhealth maxshieldhealth shieldabsorption shieldrechargerate" << endl;
+            return;
+        }
+    }
+
+    void PartDestructionEvent::setOperation(std::string operation)
+    {
+        // * + - destroy
+        this->operation_ = operation;
+    }
+
+    void PartDestructionEvent::setEventValue(float value)
+    {
+        this->value_ = value;
+    }
+}
Index: /code/branches/modularships/src/orxonox/items/PartDestructionEvent.h
===================================================================
--- /code/branches/modularships/src/orxonox/items/PartDestructionEvent.h	(revision 10052)
+++ /code/branches/modularships/src/orxonox/items/PartDestructionEvent.h	(revision 10052)
@@ -0,0 +1,90 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Noe Pedrazzini
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _PartDestructionEvent_H__
+#define _PartDestructionEvent_H__
+
+#include "OrxonoxPrereqs.h"
+#include "Item.h"
+
+#include <string>
+
+
+namespace orxonox // tolua_export
+{ // tolua_export
+    class _OrxonoxExport PartDestructionEvent // tolua_export
+        : public Item
+    { // tolua_export
+
+        public:
+
+            PartDestructionEvent(Context* context);
+            virtual ~PartDestructionEvent();
+
+            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+
+            void execute();
+
+            void setTargetType(std::string type);
+            inline std::string getTargetType()
+                { return this->targetType_; }
+
+            void setTargetName(std::string name);
+            inline std::string getTargetName()
+                { return this->targetName_; }
+
+            void setTargetParam(std::string param);
+            inline std::string getTargetParam()
+                { return this->targetName_; }
+
+            void setOperation(std::string operation);
+            inline std::string getOperation()
+                { return this->operation_; }
+
+            void setEventValue(float value);
+            inline float getEventValue()
+                { return this->value_; }
+
+        protected:
+
+        private:
+
+            bool isValid_;
+
+            std::string targetType_;
+            std::string targetName_;
+            std::string targetParam_;
+            std::string operation_;
+
+            float value_;
+
+
+    }; // tolua_export
+} // tolua_export
+
+#endif /* _PartDestructionEvent_H__ */
Index: /code/branches/modularships/src/orxonox/items/ShipPart.cc
===================================================================
--- /code/branches/modularships/src/orxonox/items/ShipPart.cc	(revision 10051)
+++ /code/branches/modularships/src/orxonox/items/ShipPart.cc	(revision 10052)
@@ -40,4 +40,5 @@
 #include "gametypes/Gametype.h"
 #include "worldentities/StaticEntity.h"
+#include "items/PartDestructionEvent.h"
 
 
@@ -66,4 +67,6 @@
 
         XMLPortParam(ShipPart, "damageabsorption", setDamageAbsorption, getDamageAbsorption, xmlelement, mode).defaultValues(0.5);
+
+        XMLPortObject(ShipPart, PartDestructionEvent, "destructionevents", addDestructionEvent, getDestructionEvent, xmlelement, mode);
 
         /*
@@ -142,4 +145,31 @@
             orxout() << "  " << this->entityList_[j]->getName() << endl;
         }
+    }
+
+    /**
+    @brief
+        Add a PartDestructionEvent to the ShipPart.
+    @param engine
+        A pointer to the PartDestructionEvent to be added.
+    */
+    void ShipPart::addDestructionEvent(PartDestructionEvent* part)
+    {
+        OrxAssert(part != NULL, "The PartDestructionEvent cannot be NULL.");
+        this->eventList_.push_back(part);
+        //part->setParent(this);
+    }
+
+    /**
+    @brief
+        Get the i-th PartDestructionEvent of the ShipPart.
+    @return
+        Returns a pointer to the i-the PartDestructionEvent. NULL if there is no PartDestructionEvent with that index.
+    */
+    PartDestructionEvent* ShipPart::getDestructionEvent(unsigned int index)
+    {
+        if(this->eventList_.size() >= index)
+            return NULL;
+        else
+            return this->eventList_[index];
     }
 
Index: /code/branches/modularships/src/orxonox/items/ShipPart.h
===================================================================
--- /code/branches/modularships/src/orxonox/items/ShipPart.h	(revision 10051)
+++ /code/branches/modularships/src/orxonox/items/ShipPart.h	(revision 10052)
@@ -32,4 +32,5 @@
 #include "OrxonoxPrereqs.h"
 #include "Item.h"
+#include "items/PartDestructionEvent.h"
 
 #include <string>
@@ -58,4 +59,7 @@
             StaticEntity* getEntity(unsigned int index);
             bool hasEntity(StaticEntity* entity) const;
+
+            void addDestructionEvent(PartDestructionEvent* event);
+            PartDestructionEvent* getDestructionEvent(unsigned int index);
 
             void printEntities(); // FIXME: (noep) remove debug
@@ -102,4 +106,6 @@
         private:
             std::vector<StaticEntity*> entityList_; // list of all entities which belong to this part
+            std::vector<PartDestructionEvent*> eventList_;  // The list of all PartDestructionEvent assigned to this ShipPart.
+
 
     }; // tolua_export
Index: /code/branches/modularships/src/orxonox/worldentities/WorldEntity.cc
===================================================================
--- /code/branches/modularships/src/orxonox/worldentities/WorldEntity.cc	(revision 10051)
+++ /code/branches/modularships/src/orxonox/worldentities/WorldEntity.cc	(revision 10052)
@@ -119,4 +119,5 @@
     WorldEntity::~WorldEntity()
     {
+        orxout() << "destroying " << this->getIdentifier()->getName() << endl;
         if (this->isInitialized())
         {
Index: /code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.cc
===================================================================
--- /code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.cc	(revision 10051)
+++ /code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.cc	(revision 10052)
@@ -303,5 +303,5 @@
         }
         // 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)
+        for (std::map<StaticEntity*, ShipPart*>::iterator itt = this->partMap_.begin(); itt != this->partMap_.end(); )
         {
             if (itt->second == part)
@@ -314,5 +314,7 @@
                 //itt->first->setCollisionType(None);
                 //itt->first->deactivatePhysics();
-                this->partMap_.erase(itt);
+                this->partMap_.erase(itt++);
+            } else {
+                ++itt;
             }
         }
