Added bounds check function to Level
authorMartin Read <martin@blackswordsonics.com>
Tue, 18 Feb 2014 22:48:19 +0000 (22:48 +0000)
committerMartin Read <martin@blackswordsonics.com>
Tue, 18 Feb 2014 22:48:19 +0000 (22:48 +0000)
* map.hh: Level now has a bounds checking function in_bounds which verifies
  the acceptability of a Coord.

map.hh

diff --git a/map.hh b/map.hh
index 28dfaee..6942c9c 100644 (file)
--- a/map.hh
+++ b/map.hh
@@ -217,6 +217,12 @@ public:
         }
     }
     Coord random_point(int margin) const;
+    bool in_bounds(Coord c) const
+    {
+        c += origin_off;
+        return !((c.y < 0) || (c.x < 0) || (c.y >= (chunks_high << CHUNK_SHIFT)) ||
+            (c.x >= (chunks_wide << CHUNK_SHIFT)));
+    }
 };
 
 extern Level lvl;