summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorharanp <haranp@c06c8d41-db1a-0410-9941-cceddc491573>2008-06-16 07:08:18 +0000
committerharanp <haranp@c06c8d41-db1a-0410-9941-cceddc491573>2008-06-16 07:08:18 +0000
commit3dcc9d0f7bccea62a912b438cac19e7d8737ec3c (patch)
tree2a683233ccaee1aa1a5aea3901937a48a8e72f26
parentf13fb6fd227d1bf21cbef7542c487271a178a77c (diff)
downloadcrawl-ref-3dcc9d0f7bccea62a912b438cac19e7d8737ec3c.tar.gz
crawl-ref-3dcc9d0f7bccea62a912b438cac19e7d8737ec3c.zip
More cleanups and use of stack_iterator. Added operator-> to stack_iterator
and radius_iterator. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@5876 c06c8d41-db1a-0410-9941-cceddc491573
-rw-r--r--crawl-ref/source/misc.cc4
-rw-r--r--crawl-ref/source/religion.cc131
-rw-r--r--crawl-ref/source/stuff.cc11
-rw-r--r--crawl-ref/source/stuff.h2
4 files changed, 70 insertions, 78 deletions
diff --git a/crawl-ref/source/misc.cc b/crawl-ref/source/misc.cc
index 495d3459b6..0033d0c0c4 100644
--- a/crawl-ref/source/misc.cc
+++ b/crawl-ref/source/misc.cc
@@ -2368,9 +2368,7 @@ void get_playervisible_monsters(std::vector<monsters*> &mons,
range = LOS_RADIUS;
// Sweep every square within range.
- radius_iterator ri(you.pos(), range);
-
- for ( ; ri; ++ri )
+ for ( radius_iterator ri(you.pos(), range); ri; ++ri )
{
const unsigned short targ_monst = env.mgrid(*ri);
if (targ_monst != NON_MONSTER)
diff --git a/crawl-ref/source/religion.cc b/crawl-ref/source/religion.cc
index df5340db9d..d95b1ee2e3 100644
--- a/crawl-ref/source/religion.cc
+++ b/crawl-ref/source/religion.cc
@@ -3078,105 +3078,86 @@ bool trog_burn_books()
god_acting gdact;
- int i = igrd[you.x_pos][you.y_pos];
- while (i != NON_ITEM)
+ for ( stack_iterator si(you.pos()); si; ++si )
{
- const int next = mitm[i].link; // in case we can't get it later.
-
- if (mitm[i].base_type == OBJ_BOOKS
- && mitm[i].sub_type != BOOK_MANUAL
- && mitm[i].sub_type != BOOK_DESTRUCTION)
+ if ( si->base_type == OBJ_BOOKS
+ && si->sub_type != BOOK_MANUAL
+ && si->sub_type != BOOK_DESTRUCTION )
{
mpr("Burning your own feet might not be such a smart idea!");
return (false);
}
- i = next;
}
int totalpiety = 0;
- for (int xpos = you.x_pos - 8; xpos < you.x_pos + 8; xpos++)
- for (int ypos = you.y_pos - 8; ypos < you.y_pos + 8; ypos++)
+
+ for (radius_iterator ri(you.pos(), LOS_RADIUS, true, true, true); ri; ++ri)
+ {
+ // If a grid is blocked, books lying there will be ignored.
+ // Allow bombing of monsters.
+ const unsigned short cloud = env.cgrid(*ri);
+ if (grid_is_solid(grd(*ri))
+ || cloud != EMPTY_CLOUD && env.cloud[cloud].type != CLOUD_FIRE)
{
- // Checked above.
- if (xpos == you.x_pos && ypos == you.y_pos)
- continue;
-
- // Burn only squares in sight.
- if (!see_grid(xpos, ypos))
- continue;
+ continue;
+ }
- // If a grid is blocked, books lying there will be ignored.
- // Allow bombing of monsters.
- const int cloud = env.cgrid[xpos][ypos];
- if (grid_is_solid(grd[ xpos ][ ypos ])
- || cloud != EMPTY_CLOUD && env.cloud[cloud].type != CLOUD_FIRE)
+ int count = 0;
+ int rarity = 0;
+ for ( stack_iterator si(*ri); si; ++si )
+ {
+ if ( si->base_type != OBJ_BOOKS
+ || si->sub_type == BOOK_MANUAL
+ || si->sub_type == BOOK_DESTRUCTION )
{
continue;
}
-
- int count = 0;
- int rarity = 0;
- i = igrd[xpos][ypos];
- while (i != NON_ITEM)
+
+ // Ignore {!D} inscribed books.
+ if (!check_warning_inscriptions( *si, OPER_DESTROY))
{
- const int next = mitm[i].link; // in case we can't get it later
-
- if (mitm[i].base_type != OBJ_BOOKS
- || mitm[i].sub_type == BOOK_MANUAL
- || mitm[i].sub_type == BOOK_DESTRUCTION)
- {
- i = next;
- continue;
- }
-
- // Ignore {!D} inscribed books.
- if (!check_warning_inscriptions(mitm[i], OPER_DESTROY))
- {
- mpr("Won't ignite {!D} inscribed book.");
- i = next;
- continue;
- }
-
- rarity += book_rarity(mitm[i].sub_type);
- // Piety increases by 2 for books never cracked open, else 1.
- // Conversely, rarity influences the duration of the pyre.
- if (!item_type_known(mitm[i]))
- totalpiety += 2;
- else
- totalpiety++;
+ mpr("Won't ignite {!D} inscribed book.");
+ continue;
+ }
+
+ rarity += book_rarity( si->sub_type );
+ // Piety increases by 2 for books never cracked open, else 1.
+ // Conversely, rarity influences the duration of the pyre.
+ if (!item_type_known(*si))
+ totalpiety += 2;
+ else
+ totalpiety++;
#ifdef DEBUG_DIAGNOSTICS
- mprf(MSGCH_DIAGNOSTICS, "Burned book rarity: %d", rarity);
+ mprf(MSGCH_DIAGNOSTICS, "Burned book rarity: %d", rarity);
#endif
- destroy_item(i);
- count++;
- i = next;
- }
+ destroy_item(si.link());
+ count++;
+ }
- if (count)
+ if (count)
+ {
+ if (cloud != EMPTY_CLOUD)
{
- if (cloud != EMPTY_CLOUD)
- {
- // Reinforce the cloud.
- mpr( "The fire roars with new energy!" );
- const int extra_dur = count + random2(rarity/2);
- env.cloud[cloud].decay += extra_dur * 5;
- env.cloud[cloud].whose = KC_YOU;
- continue;
- }
-
- int durat = 4 + count + random2(rarity/2);
+ // Reinforce the cloud.
+ mpr( "The fire roars with new energy!" );
+ const int extra_dur = count + random2(rarity/2);
+ env.cloud[cloud].decay += extra_dur * 5;
+ env.cloud[cloud].whose = KC_YOU;
+ continue;
+ }
- if (durat > 23)
- durat = 23;
+ int durat = 4 + count + random2(rarity/2);
- place_cloud( CLOUD_FIRE, xpos, ypos, durat, KC_YOU );
+ if (durat > 23)
+ durat = 23;
- mpr(count == 1 ? "The book bursts into flames."
- : "The books burst into flames.", MSGCH_GOD);
- }
+ place_cloud( CLOUD_FIRE, ri->x, ri->y, durat, KC_YOU );
+ mpr(count == 1 ? "The book bursts into flames."
+ : "The books burst into flames.", MSGCH_GOD);
}
+ }
if (!totalpiety)
{
diff --git a/crawl-ref/source/stuff.cc b/crawl-ref/source/stuff.cc
index ea171db473..a0236de6c2 100644
--- a/crawl-ref/source/stuff.cc
+++ b/crawl-ref/source/stuff.cc
@@ -106,6 +106,12 @@ item_def& stack_iterator::operator*() const
return mitm[cur_link];
}
+item_def* stack_iterator::operator->() const
+{
+ ASSERT( cur_link != NON_ITEM );
+ return &mitm[cur_link];
+}
+
int stack_iterator::link() const
{
return cur_link;
@@ -157,6 +163,11 @@ coord_def radius_iterator::operator *() const
return location;
}
+const coord_def* radius_iterator::operator->() const
+{
+ return &location;
+}
+
void radius_iterator::step()
{
const int minx = std::max(X_BOUND_1+1, center.x - radius);
diff --git a/crawl-ref/source/stuff.h b/crawl-ref/source/stuff.h
index 3bb0221fca..02fa98aa5e 100644
--- a/crawl-ref/source/stuff.h
+++ b/crawl-ref/source/stuff.h
@@ -60,6 +60,7 @@ public:
operator bool() const;
item_def& operator *() const;
+ item_def* operator->() const;
int link() const;
const stack_iterator& operator ++ ();
@@ -81,6 +82,7 @@ public:
void reset();
operator bool() const { return !done(); }
coord_def operator *() const;
+ const coord_def* operator->() const;
const radius_iterator& operator ++ ();
const radius_iterator& operator -- ();