Index: trunk/src/lib/collision_reaction/Makefile.am
===================================================================
--- trunk/src/lib/collision_reaction/Makefile.am	(revision 8145)
+++ trunk/src/lib/collision_reaction/Makefile.am	(revision 8190)
@@ -5,9 +5,18 @@
 
 libORXcr_a_SOURCES = cr_engine.cc \
-                     collision_handle.cc
+                     collision.cc \
+                     collision_event.cc \
+                     collision_handle.cc \
+                     collision_reaction.cc \
+                     cr_object_damage.cc
 
 
 
 noinst_HEADERS =     cr_engine.h \
- 										 collision_handle.h
+                     collision.h \
+                     collision_event.h \
+                     collision_handle.h \
+                     cr_defs.h \
+                     collision_reaction.h \
+                     cr_object_damage.h
 
Index: trunk/src/lib/collision_reaction/collision.cc
===================================================================
--- trunk/src/lib/collision_reaction/collision.cc	(revision 8190)
+++ trunk/src/lib/collision_reaction/collision.cc	(revision 8190)
@@ -0,0 +1,56 @@
+/*
+   orxonox - the future of 3D-vertical-scrollers
+
+   Copyright (C) 2004 orx
+
+   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, or (at your option)
+   any later version.
+
+   ### File Specific:
+   main-programmer: Patrick Boenzli
+   co-programmer: ...
+*/
+
+#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION_REACTION
+
+#include "collision.h"
+#include "debug.h"
+
+using namespace std;
+
+
+/**
+ *  standard constructor
+ */
+Collision::Collision ()
+{
+  this->flushCollisionEvents();
+}
+
+
+/**
+ *  standard deconstructor
+ */
+Collision::~Collision ()
+{
+}
+
+
+/**
+ * flushes the CollisionEvent list
+ */
+void Collision::flushCollisionEvents()
+{
+  this->entityA = NULL;
+  this->entityB = NULL;
+
+  this->entityACollide = false;
+  this->entityBCollide = false;
+
+  this->bDispatched = true;
+
+  this->collisionEvents.clear();
+}
+
Index: trunk/src/lib/collision_reaction/collision.h
===================================================================
--- trunk/src/lib/collision_reaction/collision.h	(revision 8190)
+++ trunk/src/lib/collision_reaction/collision.h	(revision 8190)
@@ -0,0 +1,70 @@
+/*!
+ * @file collision.h
+ *  Definition of a collision as a two WE hit each other
+ *
+ *  A is shared between two WorldEntity's CollisionHandles if both are subscribed to this event. In this case only one
+ *  of the two CollisionHandles will calculate the CollisionReaction and the bDispatched flag will be set afterwards
+ *  to signal that it's already cared about and should be ignored.
+ */
+
+#ifndef _COLLISION_H
+#define _COLLISION_H
+
+#include "vector.h"
+#include <vector>
+
+class WorldEntity;
+class BoundingVolume;
+class CollisionEvent;
+
+//! A class representing a simple collision
+class Collision
+{
+
+  public:
+    Collision();
+    virtual ~Collision();
+
+    /** collides two WorldEntities @param entityA world entity A, @param entityB world entity B, @param bvA volume A @param bvB volumeB */
+    inline void collide(WorldEntity* entityA, WorldEntity* entityB) { this->entityA = entityA; this->entityB = entityB; }
+
+
+    /** @return Collision WorldEntity A */
+    inline WorldEntity* getEntityA() const { return this->entityA; }
+    /** @return Collision WorldEntity B */
+    inline WorldEntity* getEntityB() const { return this->entityB; }
+    /** @return true if Entity A collides */
+    inline bool isEntityACollide() const { return this->entityACollide; }
+    /** sets the flag if it reacts @param flag true if it should react on entityA*/
+    inline void setEntityACollide(bool flag) { this->entityACollide = flag; }
+    /** @return true if Entity B collides */
+    inline bool isEntityBCollide() const { return this->entityBCollide; }
+    /** sets the flag if it reacts @param flag true if it should react on entityB*/
+    inline void setEntityBCollide(bool flag) { this->entityACollide = flag; }
+
+    /** @returns true if this Collision has already been dispatched */
+    inline bool isDispatched() { return this->bDispatched; }
+    /** sets the dispatched flag to true */
+    inline void dispatched() { this->bDispatched = true; }
+
+    /** registers a @param event CollisionEvent to take place */
+    inline void registerCollisionEvent(CollisionEvent* event) { this->collisionEvents.push_back(event); this->bDispatched = false;}
+    /** @returns a vector of collision events */
+    inline const std::vector<CollisionEvent*>& getCollisionEvents() const { return this->collisionEvents; }
+
+
+    void flushCollisionEvents();
+
+
+  private:
+    WorldEntity*                 entityA;                       //!< the collision body A
+    WorldEntity*                 entityB;                       //!< the collision body B
+    bool                         entityACollide;                //!< true if entity A is subscribed for collision reaction
+    bool                         entityBCollide;                //!< true if entity B is subscribed for collision reaction
+
+    bool                         bDispatched;                   //!< true if this collision has already been dispatched
+
+    std::vector<CollisionEvent*> collisionEvents;               //!< the collision event list
+};
+
+#endif /* _COLLISION_H */
Index: trunk/src/lib/collision_reaction/collision_event.cc
===================================================================
--- trunk/src/lib/collision_reaction/collision_event.cc	(revision 8190)
+++ trunk/src/lib/collision_reaction/collision_event.cc	(revision 8190)
@@ -0,0 +1,44 @@
+/*
+   orxonox - the future of 3D-vertical-scrollers
+
+   Copyright (C) 2004 orx
+
+   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, or (at your option)
+   any later version.
+
+   ### File Specific:
+   main-programmer: Patrick Boenzli
+   co-programmer: ...
+*/
+
+#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION_REACTION
+
+#include "collision_event.h"
+#include "debug.h"
+
+using namespace std;
+
+
+/**
+ *  standard constructor
+ */
+CollisionEvent::CollisionEvent ()
+{
+  this->entityA = NULL;
+  this->entityB = NULL;
+  this->bvA = NULL;
+  this->bvB = NULL;
+}
+
+
+/**
+ *  standard deconstructor
+ */
+CollisionEvent::~CollisionEvent ()
+{
+}
+
+
+
Index: trunk/src/lib/collision_reaction/collision_event.h
===================================================================
--- trunk/src/lib/collision_reaction/collision_event.h	(revision 8190)
+++ trunk/src/lib/collision_reaction/collision_event.h	(revision 8190)
@@ -0,0 +1,56 @@
+/*!
+ * @file collision_event.h
+ *  Definition of a collision event
+ */
+
+#ifndef _COLLISION_EVENT_H
+#define _COLLISION_EVENT_H
+
+#include "vector.h"
+
+class WorldEntity;
+class BoundingVolume;
+class Plane;
+
+
+//! A class representing a simple collision
+class CollisionEvent {
+
+ public:
+   CollisionEvent();
+  virtual ~CollisionEvent();
+
+  /** collides two WorldEntities @param entityA world entity A, @param entityB world entity B, @param bvA volume A @param bvB volumeB */
+  inline void collide(WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB)
+  { this->entityA = entityA; this->entityB = entityB; this->bvA = bvA; this->bvB = bvB; }
+  /** collides two WorldEntities @param entity world entity , @param ground ground plane, @param position position on the ground */
+  inline void collide(WorldEntity* entity, Plane* ground, Vector position)
+  { this->entityA = entity; this->ground = ground; this->position = position; }
+
+
+  /** @return CollisionEvent WorldEntity A */
+  inline WorldEntity* getEntityA() const { return this->entityA; }
+  /** @return CollisionEvent WorldEntity B */
+  inline WorldEntity* getEntityB() const { return this->entityB; }
+  /** @return Bounding Volume from EntityA */
+  inline BoundingVolume* getBVA() const { return this->bvA; }
+  /** @return Bounding Volume from EntityB */
+  inline BoundingVolume* getBVB() const { return this->bvB; }
+
+
+  inline void operator()(WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB) { this->collide(entityA, entityB, bvA, bvB); }
+  inline void operator()(WorldEntity* entity, Plane* ground, Vector position) { this->collide(entity, ground, position); }
+
+
+ private:
+  WorldEntity*      entityA;                       //!< the collision body A
+  WorldEntity*      entityB;                       //!< the collision body B
+
+  BoundingVolume*   bvA;                           //!< reference to the bounding volume A
+  BoundingVolume*   bvB;                           //!< reference to the bounding volume B
+
+  Plane*            ground;                        //!< the ground plane with which it collides (only for bsp-model collisions
+  Vector            position;                      //!< position of the collision on the ground plane
+};
+
+#endif /* _COLLISION_EVENT_H */
Index: trunk/src/lib/collision_reaction/collision_handle.cc
===================================================================
--- trunk/src/lib/collision_reaction/collision_handle.cc	(revision 8145)
+++ trunk/src/lib/collision_reaction/collision_handle.cc	(revision 8190)
@@ -17,4 +17,12 @@
 #include "collision_handle.h"
 
+#include "world_entity.h"
+
+#include "collision.h"
+#include "collision_event.h"
+#include "collision_reaction.h"
+
+#include "cr_object_damage.h"
+
 using namespace std;
 
@@ -31,4 +39,25 @@
   this->type = type;
 
+  this->bCollided = false;
+  this->bDispatched = false;
+
+  if( this->type == CREngine::CR_PHYSICS_STEP_BACK)
+    this->bContinuousPoll = false;
+  else
+    this->bContinuousPoll = true;
+
+  if( this->type == CREngine::CR_OBJECT_DAMAGE)
+    this->bStopOnFirstCollision = true;
+  else
+   this->bStopOnFirstCollision = false;
+
+  switch( type)
+  {
+    case CREngine::CR_OBJECT_DAMAGE:
+      this->collisionReaction = new CRObjectDamage();
+      break;
+    default:
+      break;
+  };
 }
 
@@ -41,2 +70,181 @@
   // delete what has to be deleted here
 }
+
+/**
+ * restores the CollisionHandle to its initial state
+ */
+void CollisionHandle::reset()
+{
+  this->flushCollisions();
+}
+
+
+/**
+ * add more filter targets to this collision handle
+ *  @param classID the classid to look for
+ */
+void CollisionHandle::addTarget(long target)
+{
+  // make sure there is no dublicate
+  std::vector<long>::iterator it = this->targetList.begin();
+  for( ; it < this->targetList.end(); it++)
+    if( (*it) == target)
+      return;
+
+  // add element
+   PRINTF(0)("addTarget: %i \n", target);
+   this->targetList.push_back(target);
+}
+
+
+/**
+ * registers a new Collision Object
+ *  @param entityA WorldEntity A of the collision
+ *  @param entityB WorldEntity B of the collision
+ * if a there is already a collision object with the same stats
+ * registration will be skipped and the last collision object is returned
+ */
+Collision* CollisionHandle::registerCollision(WorldEntity* entityA, WorldEntity* entityB)
+{
+  //first get the collision object, multiple sources
+  Collision* c;
+  if( this->collisionList.empty() ||
+      ((this->collisionList.back())->getEntityA() != entityA && (this->collisionList.back())->getEntityB() != entityB )) {
+    c = CREngine::getInstance()->popCollisionObject();
+    c->collide(entityA, entityB);
+    this->collisionList.push_back(c);
+
+    // now register it as a shared collision with the other collision entity
+    CollisionHandle* ch = entityB->getCollisionHandle(this->type);
+    if( ch != NULL)
+      ch->registerSharedCollision(c);
+  }
+  else
+    c = this->collisionList.back();
+
+  return c;
+}
+
+
+/**
+ * register a Collision to the Collision handle.
+ *  @param collision the collision object to register
+ *
+ * This is used for internal collision registration: sharing the collision objects between Collision Reactions
+ * Therefore dispatching it only once
+ */
+void CollisionHandle::registerSharedCollision(Collision* collision)
+{
+  // fist check if we are listening for this Collision
+  if( !this->filterCollision(collision))
+    return;
+
+  // set the state to not dispatched
+  this->bDispatched = false;
+  this->bCollided = true;
+  collision->setEntityBCollide(true);
+
+  this->collisionList.push_back(collision);
+}
+
+
+/**
+ * this is the function to be called on a collision event for this handle
+ *  @param collision the collision objects containing all collision informations
+ */
+void CollisionHandle::registerCollisionEvent(CollisionEvent* collisionEvent)
+{
+  if( !this->filterCollisionEvent(collisionEvent))
+    return;
+
+  // set the state to not dispatched
+  this->bDispatched = false;
+  this->bCollided = true;
+
+  // checks if these WorldEntities have already collided or if its a new collision -> create a new Collision object
+ Collision* c = this->registerCollision(collisionEvent->getEntityA(), collisionEvent->getEntityB());
+ c->setEntityACollide(true);
+
+ c->registerCollisionEvent(collisionEvent);
+}
+
+
+/**
+ * flushes the collision list
+ */
+void CollisionHandle::flushCollisions()
+{
+  this->collisionList.clear();
+}
+
+
+/**
+ * handles the collisions and react according to algorithm
+ */
+void CollisionHandle::handleCollisions()
+{
+  // collision reaction calculations (for every collision there will be a reaction)
+  vector<Collision*>::iterator it = this->collisionList.begin();
+  for(; it < this->collisionList.end(); it++) {
+    if( !(*it)->isDispatched())
+    {
+      this->collisionReaction->reactToCollision(*it);
+      (*it)->flushCollisionEvents();
+    }
+  }
+
+  // now set state to dispatched
+  this->bDispatched = true;
+  this->bCollided = false;
+
+  this->flushCollisions();
+}
+
+
+/**
+ * filter out the CollisionEvents that are not wanted
+ *  @param collisionEvent the collision event to filter
+ */
+bool CollisionHandle::filterCollisionEvent(CollisionEvent* collisionEvent)
+{
+  vector<long>::iterator it = this->targetList.begin();
+  for(; it < this->targetList.end(); it++)
+  {
+    if( collisionEvent->getEntityA() == this->owner) {
+      if( collisionEvent->getEntityA()->isA((ClassID)(*it)))
+        return true; }
+    else {
+      if( collisionEvent->getEntityB()->isA((ClassID)(*it)))
+        return true; }
+  }
+
+  return false;
+}
+
+
+/**
+ * filter Collisions that are not wanted to be reacted to
+ *  @param collision the collision object to filter
+ */
+bool CollisionHandle::filterCollision(Collision* collision)
+{
+  vector<long>::iterator it = this->targetList.begin();
+  for(; it < this->targetList.end(); it++)
+  {
+    if( collision->getEntityA() == this->owner) {
+      if( collision->getEntityA()->isA((ClassID)(*it)))
+        return true; }
+      else {
+        if( collision->getEntityB()->isA((ClassID)(*it)))
+          return true; }
+  }
+
+  return false;
+}
+
+
+
+
+
+
+
Index: trunk/src/lib/collision_reaction/collision_handle.h
===================================================================
--- trunk/src/lib/collision_reaction/collision_handle.h	(revision 8145)
+++ trunk/src/lib/collision_reaction/collision_handle.h	(revision 8190)
@@ -11,36 +11,58 @@
 
 #include <vector>
+#include <list>
 
 
 class Collision;
 class WorldEntity;
+class CollisionReaction;
 
-// struct CRType;
 
 
 //! A class for defining collision reactions and storing events
-class CollisionHandle : public BaseObject {
+class CollisionHandle : public BaseObject
+{
 
- public:
-  CollisionHandle(WorldEntity* owner, CREngine::CRType type);
-  virtual ~CollisionHandle();
+  public:
+    CollisionHandle(WorldEntity* owner, CREngine::CRType type);
+    virtual ~CollisionHandle();
+
+    void reset();
+
+    void addTarget(long target);
+    Collision* registerCollision(WorldEntity* entityA, WorldEntity* entityB);
+    void registerSharedCollision(Collision* collision);
+    void registerCollisionEvent(CollisionEvent* collisionEvent);
+
+    /** @returns true if regiestered some new collision events in this tick frame */
+    inline bool isCollided() const { return this->bCollided; }
+    /** @returns true if this collision handle has already been dispatched */
+    inline bool isDispatched() const { return this->bDispatched; }
+    /** @returns true if this handle should be pulled also if there are no collisions */
+    inline bool isContinuousPoll() const { return this->bContinuousPoll; }
+
+    void handleCollisions();
 
 
-  void addTarget();
-
-  void registerCollision(Collision* collision);
-
-  void handleCollisions();
+  private:
+    void flushCollisions();
+    bool filterCollisionEvent(CollisionEvent* collisionEvent);
+    bool filterCollision(Collision* collision);
 
 
- private:
-   WorldEntity*                  owner;                   //!< the worldenity this reaction will be applied on
-   CREngine::CRType              type;                    //!< the reaction type
 
-   bool                          bDispatched;             //!< true if this handle has already been dispatched
-   bool                          bStopOnFirstCollision;   //!< true if the cd of this object should be terminated after one match
+  private:
+    WorldEntity*                  owner;                   //!< the worldenity this reaction will be applied on
+    CREngine::CRType              type;                    //!< the reaction type
 
-   std::vector<Collision*>       collisionList;           //!< a list full of collisions
-   std::vector<long>             targetList;              //!< a list of target classes for filtering
+    bool                          bContinuousPoll;         //!< if this is true
+    bool                          bDispatched;             //!< true if this handle has already been dispatched
+    bool                          bStopOnFirstCollision;   //!< true if the cd of this object should be terminated after one match
+    bool                          bCollided;               //!< true if the CollsionHandle has registered some new collisions
+
+    std::vector<Collision*>       collisionList;           //!< a list full of collisions
+    std::vector<long>             targetList;              //!< a list of target classes for filtering
+
+    CollisionReaction*            collisionReaction;       //!< reference to the collision reaction object
 
 };
Index: trunk/src/lib/collision_reaction/collision_reaction.cc
===================================================================
--- trunk/src/lib/collision_reaction/collision_reaction.cc	(revision 8190)
+++ trunk/src/lib/collision_reaction/collision_reaction.cc	(revision 8190)
@@ -0,0 +1,40 @@
+/*
+   orxonox - the future of 3D-vertical-scrollers
+
+   Copyright (C) 2004 orx
+
+   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, or (at your option)
+   any later version.
+
+   ### File Specific:
+   main-programmer: Patrick Boenzli
+   co-programmer: ...
+*/
+
+#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION_REACTION
+
+#include "collision_reaction.h"
+
+
+using namespace std;
+
+
+/**
+ *  standard constructor
+ */
+CollisionReaction::CollisionReaction ()
+  : BaseObject()
+{
+  this->setClassID(CL_COLLISION_REACTION, "CollisionReaction");
+}
+
+
+/**
+ *  standard deconstructor
+ */
+CollisionReaction::~CollisionReaction ()
+{
+}
+
Index: trunk/src/lib/collision_reaction/collision_reaction.h
===================================================================
--- trunk/src/lib/collision_reaction/collision_reaction.h	(revision 8190)
+++ trunk/src/lib/collision_reaction/collision_reaction.h	(revision 8190)
@@ -0,0 +1,31 @@
+/*!
+ * @file collision_reaction.h
+ *  Definition of a generic collision reaction
+ */
+
+#ifndef _COLLISION_REACTION_H
+#define _COLLISION_REACTION_H
+
+#include "base_object.h"
+
+
+
+class Collision;
+
+//! A class representing a simple collision
+class CollisionReaction : public BaseObject
+{
+
+  public:
+    CollisionReaction();
+    virtual ~CollisionReaction();
+
+    virtual void reactToCollision(Collision* collision) = 0;
+
+    inline bool isContinuousPoll() const { return this->bContinuousPoll; }
+
+  private:
+    bool                    bContinuousPoll;       //!< if true the collision rection function is also called, if there was no collision
+};
+
+#endif /* _COLLISION_REACTION_H */
Index: trunk/src/lib/collision_reaction/cr_defs.h
===================================================================
--- trunk/src/lib/collision_reaction/cr_defs.h	(revision 8190)
+++ trunk/src/lib/collision_reaction/cr_defs.h	(revision 8190)
@@ -0,0 +1,31 @@
+/*
+   orxonox - the future of 3D-vertical-scrollers
+
+   Copyright (C) 2004 orx
+
+   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, or (at your option)
+   any later version.
+
+### File Specific:
+   main-programmer: Patrick Boenzli
+*/
+
+/*!
+ * @file cr_defs.h
+ *  some global collision reaction definitions
+ */
+
+#ifndef _CR_DEFS_H
+#define _CR_DEFS_H
+
+//!< the maximal number of touching objects (collisions) per frame
+#define CR_MAX_COLLISIONS          500
+
+//!< the maximal number of bounding volumes collision events per frame
+#define CR_MAX_COLLISION_EVENTS   3000
+
+
+
+#endif /* _NETWORK_MANAGER */
Index: trunk/src/lib/collision_reaction/cr_engine.cc
===================================================================
--- trunk/src/lib/collision_reaction/cr_engine.cc	(revision 8145)
+++ trunk/src/lib/collision_reaction/cr_engine.cc	(revision 8190)
@@ -16,4 +16,11 @@
 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION_REACTION
 
+
+
+#include "collision.h"
+#include "collision_event.h"
+#include "collision_handle.h"
+#include "cr_defs.h"
+
 #include "cr_engine.h"
 
@@ -25,8 +32,10 @@
  */
 CREngine::CREngine ()
+  : BaseObject()
 {
    this->setClassID(CL_CR_ENGINE, "CREngine");
    this->setName("CREngine");
 
+   this->init();
 }
 
@@ -42,20 +51,128 @@
 {
   CREngine::singletonRef = NULL;
+
+  if( this->collisionsUnused.size() != CR_MAX_COLLISIONS)
+    PRINTF(0)("CollisionReaction Error: Collision cache size missmatch: %i of %i\n", this->collisionsUnused.size(), CR_MAX_COLLISIONS);
+  if( this->collisionEventsUnused.size() != CR_MAX_COLLISION_EVENTS)
+    PRINTF(0)("CollisionReaction Error: CollisionEvent cache size missmatch: %i of %i\n", this->collisionEventsUnused.size(), CR_MAX_COLLISION_EVENTS);
+
+  this->reset();
+
+  vector<Collision*>::iterator it1 = this->collisionsUnused.begin();
+  for(; it1 < this->collisionsUnused.end(); it1++)
+    delete *it1;
+  vector<CollisionEvent*>::iterator it2 = this->collisionEventsUnused.begin();
+  for(; it2 < this->collisionEventsUnused.end(); it2++)
+    delete *it2;
+
+  this->collisionsUnused.clear();
+  this->collisionEventsUnused.clear();
+}
+
+/**
+ * inits the CREngine to a working state
+ */
+void CREngine::init()
+{
+  // create a list of Collision events (precaching)
+  for( int i = 0; i < CR_MAX_COLLISIONS; i++)
+    this->collisionsUnused.push_back(new Collision());
+  for( int i = 0; i < CR_MAX_COLLISION_EVENTS; i++)
+    this->collisionEventsUnused.push_back(new CollisionEvent());
 }
 
 
+/**
+ * flushes the CollisionHandles and restores the CREngine to the initial state
+ */
+void CREngine::reset()
+{
+  // first clear all CollisionHandles
 
+  vector<CollisionHandle*>::iterator it = this->collisionHandles.begin();
+  for(; it < this->collisionHandles.end(); it++)
+  {
+    (*it)->reset();
+    delete *it;
+  }
 
-CollisionHandle* CREngine::subscribeReaction(WorldEntity* owner, CRType type, int nrOfTargets, ...)
-{
-
-  va_list itemlist;
-  va_start (itemlist, type);
-//  for (int i = 0; i < nrOfTargets; i++)
-  //  this->targetList.push_back(va_arg(itemlist, int));
-  va_end(itemlist);
+  this->collisionHandles.clear();
 }
 
 
+/**
+ * subscribes a WorldEntity for a CollisionReaction
+ *  @param owner: the WE to subscribe
+ *  @param type: the type of collision reaction to perform
+ *  @return the newly created CollisionHandle
+ */
+CollisionHandle* CREngine::subscribeReaction(WorldEntity* owner, CRType type)
+{
+  CollisionHandle* ch = new CollisionHandle(owner, type);
+  this->collisionHandles.push_back(ch);
+
+  return ch;
+}
 
 
+/**
+ * unsubscribe reaction from the reaction list
+ *  @param collisionHandle the CollisionHandle to remove
+ *  @param returns true if worked collrectly
+ */
+bool CREngine::unsubscribeReaction(CollisionHandle* collisionHandle)
+{
+  std::vector<CollisionHandle*>::iterator it;
+  for( it = this->collisionHandles.begin(); it != this->collisionHandles.end(); it++)
+  {
+    if( *it == collisionHandle)
+    {
+      this->collisionHandles.erase(it);
+      delete collisionHandle;
+      return true;
+    }
+  }
+  return false;
+}
+
+
+/**
+ * processes the collisions by calling the EventHandlers
+ */
+void CREngine::handleCollisions()
+{
+  std::vector<CollisionHandle*>::iterator it;
+  for( it = this->collisionHandles.begin(); it != this->collisionHandles.end(); it++)
+  {
+    if( (*it)->isCollided() || (*it)->isContinuousPoll())  //does it have any collisions to report at all
+    {
+      (*it)->handleCollisions();
+    }
+  }
+  this->flushCollisions();
+}
+
+
+/**
+ * flushes all the collision lists and puts them to their initial state
+ */
+void CREngine::flushCollisions()
+{
+  vector<Collision*>::iterator it1 = this->collisionsUsed.begin();
+  for(; it1 < this->collisionsUsed.end(); it1++)
+    this->collisionsUnused.push_back(*it1);
+
+  vector<CollisionEvent*>::iterator it2 = this->collisionEventsUsed.begin();
+  for(; it2 < this->collisionEventsUsed.end(); it2++)
+    this->collisionEventsUnused.push_back(*it2);
+
+  this->collisionsUsed.clear();
+  this->collisionEventsUsed.clear();
+}
+
+
+void CREngine::debug()
+{
+
+}
+
Index: trunk/src/lib/collision_reaction/cr_engine.h
===================================================================
--- trunk/src/lib/collision_reaction/cr_engine.h	(revision 8145)
+++ trunk/src/lib/collision_reaction/cr_engine.h	(revision 8190)
@@ -2,5 +2,10 @@
  * @file cr_engine.h
  * @brief The collision reaction engine, defining generic collision reactions to collision events
-*/
+ *
+ * some parts of this module are tuned for efficiency. They are probably not self-explenatory anymore :D
+ *  - Collision/ CollisionEvent objects recycling: This class contains a class of precached objects of these types
+ *      they are used for fast registration of collision events: These objects can be get by the interface functions and
+ *      are returned after one cycle automaticly by reseting the cached lists to its initial state. So do not wonder :D
+ */
 
 #ifndef _CR_ENGINE_
@@ -8,5 +13,5 @@
 
 #include "base_object.h"
-#include <stdarg.h>
+
 #include <vector>
 
@@ -14,4 +19,5 @@
 class CollisionHandle;
 class Collision;
+class CollisionEvent;
 class WorldEntity;
 
@@ -22,14 +28,16 @@
   public:
   typedef enum CRType {
-    CR_PHYSICS_MOMENTUM   = 0,
-    CR_PHYSICS_GROUND,
-    CR_PHYSICS_GROUND_WALK,
+    CR_PHYSICS_MOMENTUM   = 0,    //!< physical reaction: conservervation of momentum
+    CR_PHYSICS_STEP_BACK,         //!< physical reaction: just go to the last position without collisions
+    CR_PHYSICS_GROUND,            //!< physical reaction: stand on the ground, no movement: simulating simple normal force away from the gravity force
+    CR_PHYSICS_GROUND_WALK,       //!< physical reaction: walking on the ground (inkl. hills etc)
+    CR_PHYSICS_DAMAGE,            //!< physical reaction: daling damage according to the object energy and their structural stability
 
-    CR_OBJECT_DAMAGE,
-    CR_OBJECT_PICKUP,
+    CR_OBJECT_DAMAGE,             //!< object raction: deals damage according to the objects specific damage potential (like weapons, nukes, etc.)
+    CR_OBJECT_PICKUP,             //!< object rection: calling the objects pickup functions, let them handle the collision (once!)
 
-    CR_VERTEX_TRAFO,
+    CR_VERTEX_TRAFO,              //!< vertex trafo: transforming the vertex according to the damage
 
-    CR_SPECIAL_CALLBACK,
+    CR_SPECIAL_CALLBACK,          //!< special: call a callback function
 
     CR_NUMBER
@@ -39,28 +47,44 @@
 
   /** @returns a Pointer to the only object of this Class */
-  inline static CREngine* getInstance(void) { if (!singletonRef) singletonRef = new CREngine();  return singletonRef; };
+  inline static CREngine* getInstance() { if (!singletonRef) singletonRef = new CREngine();  return singletonRef; };
+
+  void reset();
 
 
-  CollisionHandle* subscribeReaction(WorldEntity* worldEntity, CRType type, int nrOfTargets, ...);
+  CollisionHandle* subscribeReaction(WorldEntity* worldEntity, CRType type);
 
-  bool unsubscribeReaction(WorldEntity* worldEntity);
   bool unsubscribeReaction(CollisionHandle* collisionHandle);
-
 
   void handleCollisions();
 
   /** @returns an instance to a collision object. instead of creating new object this ones can be resycled */
-  inline Collision* getCollisionObject() { /* return the first element of the cache list*/ }
-  /** @param collision: returns the Collision object back to the cache list */
-  inline void putCollisionObject(Collision* collision) { this->cachedCollisions.push_back(collision); }
+  inline Collision* popCollisionObject() {
+    if( !this->collisionsUnused.empty()) {
+      this->collisionsUsed.push_back(this->collisionsUnused.back()); this->collisionsUnused.pop_back(); return this->collisionsUsed.back(); } else return NULL; }
+
+
+  /** @return an instanco of a CollisionEvent object. instead of creating a new object this ones can be used and resycled */
+  inline CollisionEvent* popCollisionEventObject() {
+    if( !this->collisionEventsUnused.empty()) {
+      this->collisionEventsUsed.push_back(this->collisionEventsUnused.back()); this->collisionEventsUnused.pop_back(); return this->collisionEventsUsed.back(); } else return NULL; }
+
+  void debug();
 
 
 private:
-  CREngine(void);
+  CREngine();
+  void init();
+
+  void flushCollisions();
 
 
 private:
   std::vector<CollisionHandle*>       collisionHandles;         //!< list with the collision handles
-  std::vector<Collision*>             cachedCollisions;         //!< a list of unused, cached collision events
+
+  std::vector<Collision*>             collisionsUsed;           //!< a list of used, cached collisions
+  std::vector<Collision*>             collisionsUnused;         //!< a list of unused, cached collisions
+
+  std::vector<CollisionEvent*>        collisionEventsUsed;      //!< a list of used, cached collision events
+  std::vector<CollisionEvent*>        collisionEventsUnused;    //!< a list of unused, cached collision events
 
   static CREngine*                    singletonRef;             //!< the reference to the CREngine object (singleton)
Index: trunk/src/lib/collision_reaction/cr_object_damage.cc
===================================================================
--- trunk/src/lib/collision_reaction/cr_object_damage.cc	(revision 8190)
+++ trunk/src/lib/collision_reaction/cr_object_damage.cc	(revision 8190)
@@ -0,0 +1,85 @@
+/*
+   orxonox - the future of 3D-vertical-scrollers
+
+   Copyright (C) 2004 orx
+
+   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, or (at your option)
+   any later version.
+
+   ### File Specific:
+   main-programmer: Patrick Boenzli
+   co-programmer: ...
+*/
+
+#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION_REACTION
+
+#include "collision.h"
+#include "collision_event.h"
+
+#include "physics_interface.h"
+
+#include "world_entity.h"
+#include "cr_object_damage.h"
+
+using namespace std;
+
+
+/**
+ *  standard constructor
+ */
+CRObjectDamage::CRObjectDamage ()
+  : CollisionReaction()
+{
+  this->setClassID(CL_CR_OBJECT_DAMAGE, "CRObjectDamage");
+
+}
+
+
+/**
+ *  standard deconstructor
+ */
+CRObjectDamage::~CRObjectDamage ()
+{
+}
+
+
+/**
+ * caluculates and applys the reaction to a specific collision
+ *  @param collision the collision
+ */
+void CRObjectDamage::reactToCollision(Collision* collision)
+{
+  float damage;
+
+  PRINTF(0)("Dealing damage - Handling collision: %s vs %s\n",
+            collision->getEntityA()->getClassName(),
+            collision->getEntityB()->getClassName());
+
+  // the collision damage been dealed by the entity
+  if( collision->isEntityACollide()) {
+    damage = collision->getEntityB()->getDamage();
+    collision->getEntityA()->decreaseHealth(damage);
+  }
+  PRINTF(0)("Dealing damage - %f damage to %s \n", damage, collision->getEntityA()->getClassName());
+
+  if( collision->isEntityBCollide()) {
+    damage = collision->getEntityA()->getDamage();
+    collision->getEntityB()->decreaseHealth(damage);
+  }
+  PRINTF(0)("Dealing damage - %f damage to %s \n", damage, collision->getEntityB()->getClassName());
+
+  collision->flushCollisionEvents();
+  collision->dispatched();
+
+//   const std::vector<CollisionEvent*>* collisionEvents = &(collision->getCollisionEvents());
+//   std::vector<CollisionEvent*>::const_iterator it = collisionEvents->begin();
+//   for(; it != collisionEvents->end(); it++)
+//   {
+//     // go through the collisions and try to estimate the damage
+//     mass = (*it)->getEntityA()->getMass();
+//   }
+
+}
+
Index: trunk/src/lib/collision_reaction/cr_object_damage.h
===================================================================
--- trunk/src/lib/collision_reaction/cr_object_damage.h	(revision 8190)
+++ trunk/src/lib/collision_reaction/cr_object_damage.h	(revision 8190)
@@ -0,0 +1,27 @@
+/*!
+ * @file cr_object_damage.h
+ *  Definition of a collision reaction: dealing damage to an object
+ */
+
+#ifndef _CR_OBJECT_DAMAGE_H
+#define _CR_OBJECT_DAMAGE_H
+
+#include "collision_reaction.h"
+
+
+class Collision;
+
+//! A class representing a reaction to a collision: dealing damage to an object
+class CRObjectDamage : public CollisionReaction
+{
+  public:
+    CRObjectDamage();
+    virtual ~CRObjectDamage();
+
+    virtual void reactToCollision(Collision* collision);
+
+  private:
+
+};
+
+#endif /* _CR_OBJECT_DAMAGE_H */
