From 6f00e679d1f90041599c50c3cc86ab4e499c9ba1 Mon Sep 17 00:00:00 2001 From: haranp Date: Wed, 23 Jul 2008 20:32:37 +0000 Subject: More cleanups and fixes. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@6648 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/stuff.h | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'crawl-ref/source/stuff.h') 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 +{ +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 { @@ -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) -- cgit v1.2.3-54-g00ecf