more work on the forest level
[supertux.git] / lib / special / game_object.h
index 88e1ccb..a657d49 100644 (file)
@@ -27,6 +27,8 @@ namespace SuperTux
 
   class DrawingContext;
 
+  class ObjectRemoveListener;
+
   /**
    * Base class for all game objects. This contains functions for:
    *  -querying the actual type of the object
@@ -67,7 +69,18 @@ namespace SuperTux
       {
         wants_to_die = true;
       }
+      /** registers a remove listener which will be called if the object 
+       * gets removed/destroyed
+       */
+      void add_remove_listener(ObjectRemoveListener* listener)
+      {
+        RemoveListenerListEntry* entry = new RemoveListenerListEntry();
+        entry->next = remove_listeners;
+        entry->listener = listener;
 
+        remove_listeners = entry;
+      }
+      
       // flags
       enum {
         /// the tile so you can stand on it
@@ -87,6 +100,13 @@ namespace SuperTux
        */
       bool wants_to_die;
 
+      struct RemoveListenerListEntry
+      {
+        RemoveListenerListEntry* next;
+        ObjectRemoveListener* listener;
+      };
+      RemoveListenerListEntry* remove_listeners;
+
     protected:
       int flags;
     };