Added type checking for __custom functions
[supertux.git] / src / moving_object.hpp
index e6ae483..4cc5dc2 100644 (file)
@@ -31,7 +31,7 @@ class CollisionGrid;
 
 enum CollisionGroup {
   /** Objects in DISABLED group are not tested for collisions */
-  COLGROUP_DISABLED,
+  COLGROUP_DISABLED = 0,
   /**
    * "default" is moving object. MovingObjects get tested against all other
    * objects and against other movingobjects
@@ -42,8 +42,10 @@ enum CollisionGroup {
    * MovingOnlyStatic objects), but is tested against all other objects.
    */
   COLGROUP_MOVING_ONLY_STATIC,
+  /** TODO write docu :-/ */
+  COLGROUP_MOVING_STATIC,
   /**
-   * Doesn't move and isn't explicitely checked for collisions with other
+   * Doesn't move and isn't explicitly checked for collisions with other
    * objects (but other objects might check with this)
    * The difference to COLGROUP_TOUCHABLE is that we can do multiple
    * collision response tests in a row which is needed for static object
@@ -54,7 +56,7 @@ enum CollisionGroup {
    */
   COLGROUP_STATIC,
   /**
-   * Isn't explicitely checked for collisions with other objects. But other
+   * Isn't explicitly checked for collisions with other objects. But other
    * objects might check with this object.
    * Difference to COLGROUP_STATIC is that collisions with this object are
    * only tested once and collision response is typically not handled
@@ -63,7 +65,7 @@ enum CollisionGroup {
    * coins
    */
   COLGROUP_TOUCHABLE,
-  
+
   /**
    * Should be used for tilemaps
    */
@@ -79,34 +81,47 @@ class MovingObject : public GameObject
 public:
   MovingObject();
   virtual ~MovingObject();
-  
-  /** this function is called when the object collided with any other object
+
+  /** this function is called when the object collided with something solid */
+  virtual void collision_solid(const CollisionHit& hit)
+  {
+    (void) hit;
+  }
+  /**
+   * when 2 objects collided, we will first call the pre_collision_check
+   * functions of both objects that can decide on how to react to the collision.
    */
-  virtual HitResponse collision(GameObject& other,
-                                const CollisionHit& hit) = 0;
+  virtual bool collides(GameObject& other, const CollisionHit& hit)
+  {
+    (void) other;
+    (void) hit;
+    return true;
+  }
+  /** this function is called when the object collided with any other object */
+  virtual HitResponse collision(GameObject& other, const CollisionHit& hit) = 0;
   /** called when tiles with special attributes have been touched */
   virtual void collision_tile(uint32_t tile_attributes)
   {
     (void) tile_attributes;
   }
-  
+
   const Vector& get_pos() const
   {
     return bbox.p1;
   }
-  
+
   /** returns the bounding box of the Object */
   const Rect& get_bbox() const
   {
     return bbox;
   }
-  
+
   const Vector& get_movement() const
   {
     return movement;
   }
-  
-  /** places the moving object at a specific position. Be carefull when
+
+  /** places the moving object at a specific position. Be careful when
    * using this function. There are no collision detection checks performed
    * here so bad things could happen.
    */
@@ -143,16 +158,16 @@ public:
     return group;
   }
 
-  void set_group(CollisionGroup group)
-  {
-    this->group = group;
-  }
-  
 protected:
   friend class Sector;
   friend class CollisionGrid;
   friend class Platform;
-  
+
+  void set_group(CollisionGroup group)
+  {
+    this->group = group;
+  }
+
   /** The bounding box of the object (as used for collision detection, this
    * isn't necessarily the bounding box for graphics)
    */