diff options
author | haranp <haranp@c06c8d41-db1a-0410-9941-cceddc491573> | 2008-06-16 06:11:50 +0000 |
---|---|---|
committer | haranp <haranp@c06c8d41-db1a-0410-9941-cceddc491573> | 2008-06-16 06:11:50 +0000 |
commit | f13fb6fd227d1bf21cbef7542c487271a178a77c (patch) | |
tree | a8a1702f38fe1c6d77a8b2eb46711bfb89917074 /crawl-ref/source/stuff.cc | |
parent | aca7f0db12247aae824668b0aeea4f2dd47f8be4 (diff) | |
download | crawl-ref-f13fb6fd227d1bf21cbef7542c487271a178a77c.tar.gz crawl-ref-f13fb6fd227d1bf21cbef7542c487271a178a77c.zip |
Finally implemented stack_iterator(), a way to iterate over objects in
a stack without all that o = mitm[o].link stuff. Redid Ely's destroy
weapons power to use it.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@5875 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/stuff.cc')
-rw-r--r-- | crawl-ref/source/stuff.cc | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/crawl-ref/source/stuff.cc b/crawl-ref/source/stuff.cc index d2e1fbb52e..ea171db473 100644 --- a/crawl-ref/source/stuff.cc +++ b/crawl-ref/source/stuff.cc @@ -77,6 +77,55 @@ #include "tutorial.h" #include "view.h" +stack_iterator::stack_iterator(const coord_def& pos) +{ + cur_link = igrd(pos); + if ( cur_link != NON_ITEM ) + next_link = mitm[cur_link].link; + else + next_link = NON_ITEM; +} + +stack_iterator::stack_iterator(int start_link) +{ + cur_link = start_link; + if ( cur_link != NON_ITEM ) + next_link = mitm[cur_link].link; + else + next_link = NON_ITEM; +} + +stack_iterator::operator bool() const +{ + return ( cur_link != NON_ITEM ); +} + +item_def& stack_iterator::operator*() const +{ + ASSERT( cur_link != NON_ITEM ); + return mitm[cur_link]; +} + +int stack_iterator::link() const +{ + return cur_link; +} + +const stack_iterator& stack_iterator::operator ++ () +{ + cur_link = next_link; + if ( cur_link != NON_ITEM ) + next_link = mitm[cur_link].link; + return *this; +} + +stack_iterator stack_iterator::operator++(int dummy) +{ + const stack_iterator copy = *this; + ++(*this); + return copy; +} + radius_iterator::radius_iterator( const coord_def& _center, int _radius, bool _roguelike_metric, bool _require_los, bool _exclude_center ) |