diff options
author | Adam Borowski <kilobyte@angband.pl> | 2013-10-31 08:52:27 +0100 |
---|---|---|
committer | Adam Borowski <kilobyte@angband.pl> | 2013-10-31 16:57:54 +0100 |
commit | 263ca91b08100ae09dce275d4629413c63f343c9 (patch) | |
tree | 165acf19905df3596277a6de5a522a045daa2ada /crawl-ref/source/act-iter.cc | |
parent | a57962fa1975ecc27863c2f847fa2a1c4484f7fa (diff) | |
download | crawl-ref-263ca91b08100ae09dce275d4629413c63f343c9.tar.gz crawl-ref-263ca91b08100ae09dce275d4629413c63f343c9.zip |
Rewrite monster_iterator.
It degenerated to a simple loop over menv, hardly worth any syntactic sugar.
I kept it for now, though.
Diffstat (limited to 'crawl-ref/source/act-iter.cc')
-rw-r--r-- | crawl-ref/source/act-iter.cc | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/crawl-ref/source/act-iter.cc b/crawl-ref/source/act-iter.cc index 8e62e1acdb..06eeca8779 100644 --- a/crawl-ref/source/act-iter.cc +++ b/crawl-ref/source/act-iter.cc @@ -132,3 +132,53 @@ void monster_near_iterator::advance() return; while (!valid(**this)); } + +////////////////////////////////////////////////////////////////////////// + +monster_iterator::monster_iterator() + : i(0) +{ + while (i < MAX_MONSTERS && !menv[i].alive()) + i++; +} + +monster_iterator::operator bool() const +{ + return i < MAX_MONSTERS && (*this)->alive(); +} + +monster* monster_iterator::operator*() const +{ + if (i < MAX_MONSTERS) + return &menv[i]; + else + return nullptr; +} + +monster* monster_iterator::operator->() const +{ + return **this; +} + +monster_iterator& monster_iterator::operator++() +{ + while (++i < MAX_MONSTERS) + if (menv[i].alive()) + break; + return *this; +} + +monster_iterator monster_iterator::operator++(int) +{ + monster_iterator copy = *this; + ++(*this); + return copy; +} + +void monster_iterator::advance() +{ + do + if (++i >= MAX_MONSTERS) + return; + while (!(*this)->alive()); +} |