summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/act-iter.cc
diff options
context:
space:
mode:
authorAdam Borowski <kilobyte@angband.pl>2013-10-30 09:03:59 +0100
committerAdam Borowski <kilobyte@angband.pl>2013-10-31 16:57:54 +0100
commit02d62bf9075ef5ceeafe1f28372feac70d11e7d5 (patch)
tree7ce0badecdc77549e37f2181486a4ff480b75c43 /crawl-ref/source/act-iter.cc
parentec9c540f2946ec9f21d632cc22cc05e8f285fe0b (diff)
downloadcrawl-ref-02d62bf9075ef5ceeafe1f28372feac70d11e7d5.tar.gz
crawl-ref-02d62bf9075ef5ceeafe1f28372feac70d11e7d5.zip
Simplify actor_iterator and some of its users, rename to actor_near_iterator.
Diffstat (limited to 'crawl-ref/source/act-iter.cc')
-rw-r--r--crawl-ref/source/act-iter.cc66
1 files changed, 34 insertions, 32 deletions
diff --git a/crawl-ref/source/act-iter.cc b/crawl-ref/source/act-iter.cc
index 54798f279f..d5e0b3e41e 100644
--- a/crawl-ref/source/act-iter.cc
+++ b/crawl-ref/source/act-iter.cc
@@ -2,67 +2,69 @@
#include "act-iter.h"
-#include "coord-circle.h"
-#include "mon-iter.h"
-#include "monster.h"
-#include "player.h"
+#include "env.h"
+#include "losglobal.h"
-actor_iterator::actor_iterator(const los_base* los_)
- : los(los_), did_you(false), mi(los_)
+actor_near_iterator::actor_near_iterator(coord_def c, los_type los)
+ : center(c), _los(los), viewer(nullptr), i(-1)
{
- advance(true);
+ if (!valid(&you))
+ advance();
}
-actor_iterator::operator bool() const
+actor_near_iterator::actor_near_iterator(const actor* a, los_type los)
+ : center(a->pos()), _los(los), viewer(a), i(-1)
{
- return (!did_you || mi);
+ if (!valid(&you))
+ advance();
}
-actor* actor_iterator::operator*() const
+actor_near_iterator::operator bool() const
{
- if (!did_you)
+ return valid(**this);
+}
+
+actor* actor_near_iterator::operator*() const
+{
+ if (i == -1)
return &you;
+ else if (i < MAX_MONSTERS)
+ return &menv[i];
else
- return *mi;
+ return nullptr;
}
-actor* actor_iterator::operator->() const
+actor* actor_near_iterator::operator->() const
{
return **this;
}
-actor_iterator& actor_iterator::operator++()
+actor_near_iterator& actor_near_iterator::operator++()
{
advance();
return *this;
}
-actor_iterator actor_iterator::operator++(int)
+actor_near_iterator actor_near_iterator::operator++(int)
{
- actor_iterator copy = *this;
+ actor_near_iterator copy = *this;
++(*this);
return copy;
}
-bool actor_iterator::valid(const actor* a) const
+bool actor_near_iterator::valid(const actor* a) const
{
- if (!a->alive())
+ if (!a || !a->alive())
return false;
- return los->see_cell(a->pos());
-}
-
-void actor_iterator::raw_advance()
-{
- if (!did_you)
- did_you = true;
- else
- ++mi;
+ if (viewer && !a->visible_to(a))
+ return false;
+ return cell_see_cell(center, a->pos(), _los);
}
-void actor_iterator::advance(bool may_stay)
+void actor_near_iterator::advance()
{
- if (!may_stay)
- raw_advance();
- while (*this && !valid(**this))
- raw_advance();
+ do
+ if (++i >= MAX_MONSTERS)
+ return;
+ while (!valid(**this));
}