supertux/tile.[ch]pp: Move the unisolid solidity checks to the "Tile" object.
[supertux.git] / src / supertux / tile.hpp
index 805d85b..7c436b5 100644 (file)
@@ -1,6 +1,7 @@
 //  SuperTux
 //  Copyright (C) 2004 Tobias Glaesser <tobi.web@gmx.de>
 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
+//  Copyright (C) 2010 Florian Forster <supertux at octo.it>
 //
 //  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
@@ -132,11 +133,29 @@ public:
   int getData() const
   { return data; }
 
+  /** Checks the SLOPE attribute. Returns "true" if set, "false" otherwise. */
   bool is_slope (void) const
   {
     return ((attributes & SLOPE) != 0);
   }
 
+  /** Determine the solidity of a tile. This version behaves correctly for
+   * unisolid tiles by taking position and movement of the object in question
+   * into account. Because creating the arguments for this function can be
+   * expensive, you should handle trivial cases using the "is_solid(void)" and
+   * "is_unisolid(void)" methods first. */
+  bool is_solid (const Rectf& tile_bbox, const Rectf& position, const Vector& movement) const;
+
+  /** This version only checks the SOLID flag to determine the solidity of a
+   * tile. This means it will always return "true" for unisolid tiles. To
+   * determine the *current* solidity of unisolid tiles, use the "is_solid"
+   * method that takes position and movement into account (see above). */
+  bool is_solid (void) const
+  {
+    return ((attributes & SOLID) != 0);
+  }
+
+  /** Checks the UNISOLID attribute. Returns "true" if set, "false" otherwise. */
   bool is_unisolid (void) const
   {
     return ((attributes & UNISOLID) != 0);
@@ -149,6 +168,15 @@ private:
   //might miss (and rebuke them for it)
   void correct_attributes();
 
+  /** Returns zero if a unisolid tile is non-solid due to the movement
+   * direction, non-zero if the tile is solid due to direction. */
+  int check_movement_unisolid (const Vector movement) const;
+
+  /** Returns zero if a unisolid tile is non-solid due to the position of the
+   * tile and the object, non-zero if the tile is solid. */
+  int check_position_unisolid (const Rectf& obj_bbox,
+      const Rectf& tile_bbox) const;
+
 private:
   Tile(const Tile&);
   Tile& operator=(const Tile&);