summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/stuff.h
diff options
context:
space:
mode:
authorharanp <haranp@c06c8d41-db1a-0410-9941-cceddc491573>2008-07-23 20:32:37 +0000
committerharanp <haranp@c06c8d41-db1a-0410-9941-cceddc491573>2008-07-23 20:32:37 +0000
commit6f00e679d1f90041599c50c3cc86ab4e499c9ba1 (patch)
tree2e1ceeed3d328f639166d0ca53dddbd6fba6cdcf /crawl-ref/source/stuff.h
parent0b1e914465f3e3f1f4c73f63cf2346c3f2253861 (diff)
downloadcrawl-ref-6f00e679d1f90041599c50c3cc86ab4e499c9ba1.tar.gz
crawl-ref-6f00e679d1f90041599c50c3cc86ab4e499c9ba1.zip
More cleanups and fixes.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@6648 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/stuff.h')
-rw-r--r--crawl-ref/source/stuff.h30
1 files changed, 28 insertions, 2 deletions
diff --git a/crawl-ref/source/stuff.h b/crawl-ref/source/stuff.h
index b43bb63cb3..7a7183b60a 100644
--- a/crawl-ref/source/stuff.h
+++ b/crawl-ref/source/stuff.h
@@ -49,6 +49,9 @@ int roll_dice( int num, int size );
int roll_dice( const struct dice_def &dice );
void scale_dice( dice_def &dice, int threshold = 24 );
+
+// Various ways to iterate over things.
+
// stack_iterator guarantees validity so long as you don't manually
// mess with item_def.link: i.e., you can kill the item you're
// examining but you can't kill the item linked to it.
@@ -71,6 +74,22 @@ private:
int next_link;
};
+class rectangle_iterator :
+ public std::iterator<std::forward_iterator_tag, coord_def>
+{
+public:
+ rectangle_iterator( const coord_def& corner1, const coord_def& corner2 );
+ explicit rectangle_iterator( int x_border_dist, int y_border_dist = -1 );
+ operator bool() const;
+ coord_def operator *() const;
+ const coord_def* operator->() const;
+
+ rectangle_iterator& operator ++ ();
+ rectangle_iterator operator ++ (int);
+private:
+ coord_def current, topleft, bottomright;
+};
+
class radius_iterator : public std::iterator<std::bidirectional_iterator_tag,
coord_def>
{
@@ -100,6 +119,14 @@ private:
bool iter_done;
};
+class adjacent_iterator : public radius_iterator
+{
+public:
+ adjacent_iterator( const coord_def& pos = you.pos(),
+ bool _exclude_center = true ) :
+ radius_iterator(pos, 1, true, false, _exclude_center) {}
+};
+
int random2limit(int max, int limit);
int stepdown_value(int base_value, int stepping, int first_step,
int last_step, int ceiling_value);
@@ -153,8 +180,7 @@ int distance( const coord_def& p1, const coord_def& p2 );
int distance( int x, int y, int x2, int y2);
bool adjacent( const coord_def& p1, const coord_def& p2 );
-bool silenced(int x, int y);
-inline bool silenced(const coord_def &p) { return silenced(p.x, p.y); }
+bool silenced(const coord_def& p);
bool player_can_hear(int x, int y);
inline bool player_can_hear(const coord_def &p)