From f7b29b81395faf8ecbda4355bc85ef5619c7bd99 Mon Sep 17 00:00:00 2001 From: Robert Vollmert Date: Wed, 11 Nov 2009 14:57:35 +0100 Subject: Implement monster_iterator. monster_iterator allows iterating over live monsters in env.mgrid, possibly subject to some location/visibility restrictions. Possible restrictions: - within some radius (circle_def::contains(mon->pos()) - position inside some LOS (los_def::see_cell(mon->pos()) - visible to some actor (actor::can_see(mon)) Sample use: for (int i = 0; i < MAX_MONSTERS; ++i) { monsters* const monster = &menv[i]; if (!monster->alive()) continue; // ... // becomes for (monster_iterator mi; mi; ++mi) { // ..., replacing monster-> by mi-> // and monster by *mi If you were checking for mons_near(monster), use monster_iterator mi(&you.get_los()); if you were checking for you.can_see(monster), use monster_iterator mi(&you); if you were checking for (monster->pos()-you.pos()).abs() <= r*r+1, use monster_iterator mi(circle_def(you.pos(), r, C_ROUND)). This is not as general as one might hope, but it should allow reducing the amount of code that knows how monsters are stored. --- crawl-ref/source/makefile.obj | 1 + 1 file changed, 1 insertion(+) (limited to 'crawl-ref/source/makefile.obj') diff --git a/crawl-ref/source/makefile.obj b/crawl-ref/source/makefile.obj index c85450cd5f..ccbfb75aeb 100644 --- a/crawl-ref/source/makefile.obj +++ b/crawl-ref/source/makefile.obj @@ -103,6 +103,7 @@ mon-behv.o \ mon-cast.o \ mon-gear.o \ mon-info.o \ +mon-iter.o \ mon-pick.o \ mon-util.o \ monplace.o \ -- cgit v1.2.3-54-g00ecf