summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorharanp <haranp@c06c8d41-db1a-0410-9941-cceddc491573>2008-07-02 19:51:50 +0000
committerharanp <haranp@c06c8d41-db1a-0410-9941-cceddc491573>2008-07-02 19:51:50 +0000
commit4293d91bfd7e4b10b7cdee76dc7d5da7e5e3e001 (patch)
tree071c35be0b6d5541418b190765e47591ca0229b5
parent8030e3981a5ff0333ae659cbd08763c09ffdede0 (diff)
downloadcrawl-ref-4293d91bfd7e4b10b7cdee76dc7d5da7e5e3e001.tar.gz
crawl-ref-4293d91bfd7e4b10b7cdee76dc7d5da7e5e3e001.zip
Many code cleanups, mostly involving using stack_iterator and
radius_iterator instead of the previous setup. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@6347 c06c8d41-db1a-0410-9941-cceddc491573
-rw-r--r--crawl-ref/source/abyss.cc57
-rw-r--r--crawl-ref/source/dungeon.cc4
-rw-r--r--crawl-ref/source/effects.cc7
-rw-r--r--crawl-ref/source/food.cc60
-rw-r--r--crawl-ref/source/item_use.cc16
-rw-r--r--crawl-ref/source/items.cc108
-rw-r--r--crawl-ref/source/message.cc2
-rw-r--r--crawl-ref/source/misc.cc22
-rw-r--r--crawl-ref/source/ouch.cc24
-rw-r--r--crawl-ref/source/stuff.cc5
-rw-r--r--crawl-ref/source/stuff.h1
-rw-r--r--crawl-ref/source/view.cc5
-rw-r--r--crawl-ref/source/view.h1
13 files changed, 117 insertions, 195 deletions
diff --git a/crawl-ref/source/abyss.cc b/crawl-ref/source/abyss.cc
index cc1844e233..28897a7fe9 100644
--- a/crawl-ref/source/abyss.cc
+++ b/crawl-ref/source/abyss.cc
@@ -326,20 +326,11 @@ static int _abyss_exit_nearness()
{
int nearness = INFINITE_DISTANCE;
- for (int x = you.x_pos - LOS_RADIUS; x < you.x_pos + LOS_RADIUS; x++)
- for (int y = you.y_pos - LOS_RADIUS; y < you.y_pos + LOS_RADIUS; y++)
- {
- if (!in_bounds(x, y))
- continue;
-
- // HACK: Why doesn't is_terrain_known() work here?
- if (grd[x][y] == DNGN_EXIT_ABYSS
- && get_screen_glyph(x, y) != ' ')
- {
- nearness = MIN(nearness,
- grid_distance(you.x_pos, you.y_pos, x, y));
- }
- }
+ // is_terrain_known() doesn't work on unmappable levels because
+ // mapping flags are not set on such levels.
+ for (radius_iterator ri(you.pos(), LOS_RADIUS); ri; ++ri)
+ if (grd(*ri) == DNGN_EXIT_ABYSS && get_screen_glyph(*ri) != ' ')
+ nearness = std::min(nearness, grid_distance(you.pos(), *ri));
return (nearness);
}
@@ -348,31 +339,12 @@ static int _abyss_rune_nearness()
{
int nearness = INFINITE_DISTANCE;
- for (int x = you.x_pos - LOS_RADIUS; x < you.x_pos + LOS_RADIUS; x++)
- for (int y = you.y_pos - LOS_RADIUS; y < you.y_pos + LOS_RADIUS; y++)
- {
- if (!in_bounds(x, y))
- continue;
-
- // is_terrain_known() doesn't work on unmappable levels because
- // mapping flags are not set on such levels.
- if (get_screen_glyph(x, y) != ' ')
- {
- int i = igrd[x][y];
-
- while (i != NON_ITEM)
- {
- item_def& item(mitm[i]);
- if (is_rune(item) && item.plus == RUNE_ABYSSAL)
- {
- nearness = MIN(nearness,
- grid_distance(you.x_pos, you.y_pos,
- x, y));
- }
- i = item.link;
- }
- }
- }
+ // See above comment about is_terrain_known().
+ for (radius_iterator ri(you.pos(), LOS_RADIUS); ri; ++ri)
+ if (get_screen_glyph(ri->x, ri->y) != ' ')
+ for ( stack_iterator si(*ri); si; ++si )
+ if (is_rune(*si) && si->plus == RUNE_ABYSSAL)
+ nearness = std::min(nearness, grid_distance(you.pos(),*ri));
return (nearness);
}
@@ -386,7 +358,7 @@ static void _xom_check_nearness_setup()
rune_was_near = _abyss_rune_nearness();
}
-// If the player was almost to the exit when it disppeared, Xom is
+// If the player was almost to the exit when it disappeared, Xom is
// extremely amused. He's also extremely amused if the player winds
// up right next to an exit when there wasn't one there before. The
// same applies to Abyssal runes.
@@ -442,9 +414,8 @@ void area_shift(void)
coord_def sanct_pos(0, 0);
FixedArray<unsigned short, LOS_DIAMETER, LOS_DIAMETER> fprops;
const coord_def los_delta(LOS_RADIUS, LOS_RADIUS);
- radius_iterator ri(you.pos(), LOS_RADIUS);
- for ( ; ri; ++ri )
+ for ( radius_iterator ri(you.pos(), LOS_RADIUS); ri; ++ri )
{
fprops(you.pos() - *ri + los_delta) = env.map(*ri).property;
if (env.sanctuary_pos == *ri && env.sanctuary_time > 0)
@@ -479,7 +450,7 @@ void area_shift(void)
continue;
// Remove non-nearby monsters.
- if (grid_distance(m.x, m.y, you.x_pos, you.y_pos) > 10)
+ if (grid_distance(m.pos(), you.pos()) > 10)
_abyss_lose_monster(m);
}
diff --git a/crawl-ref/source/dungeon.cc b/crawl-ref/source/dungeon.cc
index 2a6a86b555..7a7d29f4f1 100644
--- a/crawl-ref/source/dungeon.cc
+++ b/crawl-ref/source/dungeon.cc
@@ -748,9 +748,7 @@ static void _reset_level()
for (int i = 0; i < MAX_MONSTERS; i++)
menv[i].reset();
- for (int i = 0; i < 20; i++)
- env.mons_alloc[i] = MONS_PROGRAM_BUG;
-
+ env.mons_alloc.init(MONS_PROGRAM_BUG);
mgrd.init(NON_MONSTER);
igrd.init(NON_ITEM);
diff --git a/crawl-ref/source/effects.cc b/crawl-ref/source/effects.cc
index 8df2cee58c..eee963659e 100644
--- a/crawl-ref/source/effects.cc
+++ b/crawl-ref/source/effects.cc
@@ -1487,15 +1487,14 @@ bool acquirement(object_class_type class_wanted, int agent,
}
}
- if (grid_destroys_items(grd[you.x_pos][you.y_pos]))
+ if (grid_destroys_items(grd(you.pos())))
{
// How sad (and stupid).
if (!silenced(you.pos()) && !quiet)
{
- mprf(MSGCH_SOUND,
- grid_item_destruction_message(grd[you.x_pos][you.y_pos]));
+ mprf(MSGCH_SOUND, grid_item_destruction_message(grd(you.pos())));
}
- item_was_destroyed(mitm[igrd[you.x_pos][you.y_pos]], NON_MONSTER);
+ item_was_destroyed(mitm[igrd(you.pos())], NON_MONSTER);
*item_index = NON_ITEM;
}
else
diff --git a/crawl-ref/source/food.cc b/crawl-ref/source/food.cc
index 02555cb734..d2c031861a 100644
--- a/crawl-ref/source/food.cc
+++ b/crawl-ref/source/food.cc
@@ -415,7 +415,7 @@ static bool _have_corpses_in_pack(bool remind)
bool butchery(int which_corpse)
{
- if (igrd[you.x_pos][you.y_pos] == NON_ITEM)
+ if (igrd(you.pos()) == NON_ITEM)
{
if (!_have_corpses_in_pack(false))
mpr("There isn't anything here!");
@@ -465,12 +465,11 @@ bool butchery(int which_corpse)
int num_corpses = 0;
int corpse_id = -1;
bool prechosen = (which_corpse != -1);
- for (int o = igrd[you.x_pos][you.y_pos]; o != NON_ITEM; o = mitm[o].link)
+ for (stack_iterator si(you.pos()); si; ++si)
{
- if (mitm[o].base_type == OBJ_CORPSES
- && mitm[o].sub_type == CORPSE_BODY)
+ if (si->base_type == OBJ_CORPSES && si->sub_type == CORPSE_BODY)
{
- corpse_id = o;
+ corpse_id = si->index();
num_corpses++;
// Return pre-chosen corpse if it exists.
@@ -535,24 +534,21 @@ bool butchery(int which_corpse)
// if there are several corpses on the square.
bool butcher_all = false;
bool bottle_all = false; // for Vampires
- for (int o = igrd[you.x_pos][you.y_pos]; o != NON_ITEM; o = mitm[o].link)
+ for (stack_iterator si(you.pos()); si; ++si)
{
- if (mitm[o].base_type != OBJ_CORPSES
- || mitm[o].sub_type != CORPSE_BODY)
- {
+ if (si->base_type != OBJ_CORPSES || si->sub_type != CORPSE_BODY)
continue;
- }
- if (bottle_all && !can_bottle_blood_from_corpse(mitm[o].plus))
+ if (bottle_all && !can_bottle_blood_from_corpse(si->plus))
continue;
if (butcher_all || bottle_all)
- corpse_id = o;
+ corpse_id = si->index();
else
{
corpse_id = -1;
- std::string corpse_name = mitm[o].name(DESC_NOCAP_A);
+ std::string corpse_name = si->name(DESC_NOCAP_A);
const bool sacrifice = (you.duration[DUR_PRAYER]
&& god_likes_butchery(you.religion));
@@ -564,14 +560,14 @@ bool butchery(int which_corpse)
// Also, don't bother colouring if it's only for sacrificing.
if (!sacrifice && !you.is_undead)
{
- corpse_name = get_message_colour_tags(mitm[o], DESC_NOCAP_A,
+ corpse_name = get_message_colour_tags(*si, DESC_NOCAP_A,
MSGCH_PROMPT);
}
// Shall we butcher this corpse?
snprintf(info, INFO_SIZE, "%s %s?",
(sacrifice
- || !can_bottle_blood_from_corpse(mitm[o].plus)) ?
+ || !can_bottle_blood_from_corpse(si->plus)) ?
"Butcher" : "Bottle",
corpse_name.c_str());
@@ -596,11 +592,11 @@ bool butchery(int which_corpse)
{
return (false);
}
- corpse_id = o;
+ corpse_id = si->index();
if (result == 2) // (a)ll
{
- if (can_bottle_blood_from_corpse(mitm[o].plus)
+ if (can_bottle_blood_from_corpse(si->plus)
&& (!you.duration[DUR_PRAYER]
|| !god_likes_butchery(you.religion)))
{
@@ -658,7 +654,7 @@ void lua_push_items(lua_State *ls, int link)
void lua_push_floor_items(lua_State *ls)
{
- lua_push_items(ls, igrd[you.x_pos][you.y_pos]);
+ lua_push_items(ls, igrd(you.pos()));
}
void lua_push_inv_items(lua_State *ls = NULL)
@@ -781,7 +777,7 @@ bool eat_food(bool run_hook, int slot)
if (run_hook && _userdef_eat_food())
return (false);
- if (igrd[you.x_pos][you.y_pos] != NON_ITEM && slot == -1)
+ if (igrd(you.pos()) != NON_ITEM && slot == -1)
{
const int res = eat_from_floor();
if (res == 1)
@@ -1118,34 +1114,32 @@ int eat_from_floor()
int inedible_food = 0;
item_def wonteat;
bool found_valid = false;
- for (int o = igrd[you.x_pos][you.y_pos]; o != NON_ITEM; o = mitm[o].link)
+ for (stack_iterator si(you.pos()); si; ++si )
{
- item_def& item = mitm[o];
-
- if (you.species != SP_VAMPIRE && item.base_type != OBJ_FOOD)
+ if (you.species != SP_VAMPIRE && si->base_type != OBJ_FOOD)
continue;
if (you.species == SP_VAMPIRE)
{
- if (item.base_type != OBJ_CORPSES || item.sub_type != CORPSE_BODY)
+ if (si->base_type != OBJ_CORPSES || si->sub_type != CORPSE_BODY)
continue;
- if (!mons_has_blood(item.plus))
+ if (!mons_has_blood(si->plus))
{
unusable_corpse++;
continue;
}
}
- else if (food_is_rotten(item) && !_player_can_eat_rotten_meat())
+ else if (food_is_rotten(*si) && !_player_can_eat_rotten_meat())
{
unusable_corpse++;
continue;
}
- else if (!can_ingest(item.base_type, item.sub_type, true))
+ else if (!can_ingest(si->base_type, si->sub_type, true))
{
if (!inedible_food)
{
- wonteat = item;
+ wonteat = *si;
inedible_food++;
}
else
@@ -1154,7 +1148,7 @@ int eat_from_floor()
// FIXME: Use a common check for herbivorous/carnivorous
// dislikes, for e.g. "Blech! You need blood!"
ASSERT(is_valid_item(wonteat));
- if (wonteat.sub_type != item.sub_type)
+ if (wonteat.sub_type != si->sub_type)
inedible_food++;
}
@@ -1164,8 +1158,8 @@ int eat_from_floor()
found_valid = true;
std::ostringstream prompt;
prompt << (you.species == SP_VAMPIRE ? "Drink blood from" : "Eat")
- << ' ' << ((item.quantity > 1) ? "one of " : "")
- << item.name(DESC_NOCAP_A) << '?';
+ << ' ' << ((si->quantity > 1) ? "one of " : "")
+ << si->name(DESC_NOCAP_A) << '?';
const int ans = yesnoquit( prompt.str().c_str(), true, 0, false, false,
'E' );
@@ -1174,9 +1168,9 @@ int eat_from_floor()
return -1;
else if (ans == 1) // yes
{
- if (can_ingest(item.base_type, item.sub_type, false))
+ if (can_ingest(si->base_type, si->sub_type, false))
{
- eat_floor_item(o);
+ eat_floor_item(si->index());
return 1;
}
need_more = true;
diff --git a/crawl-ref/source/item_use.cc b/crawl-ref/source/item_use.cc
index 2bb692af9c..2eb1259aa8 100644
--- a/crawl-ref/source/item_use.cc
+++ b/crawl-ref/source/item_use.cc
@@ -1777,20 +1777,12 @@ static int dex_adjust_thrown_tohit(int hit)
static void identify_floor_missiles_matching(item_def mitem, int idflags)
{
mitem.flags &= ~idflags;
- int item = NON_ITEM;
+
for (int y = 0; y < GYM; ++y)
for (int x = 0; x < GXM; ++x)
- {
- item = igrd[x][y];
- while (item != NON_ITEM)
- {
- item_def &i(mitm[item]);
- item = i.link;
-
- if ((i.flags & ISFLAG_THROWN) && items_stack(i, mitem))
- i.flags |= idflags;
- }
- }
+ for ( stack_iterator si(coord_def(x,y)); si; ++si )
+ if ((si->flags & ISFLAG_THROWN) && items_stack(*si, mitem))
+ si->flags |= idflags;
}
// throw_it - currently handles player throwing only. Monster
diff --git a/crawl-ref/source/items.cc b/crawl-ref/source/items.cc
index 18ffb6224f..eba72e9f7b 100644
--- a/crawl-ref/source/items.cc
+++ b/crawl-ref/source/items.cc
@@ -587,41 +587,25 @@ void item_was_destroyed(const item_def &item, int cause)
void lose_item_stack( int x, int y )
{
- int o = igrd[x][y];
-
- igrd[x][y] = NON_ITEM;
-
- while (o != NON_ITEM)
+ for ( stack_iterator si(coord_def(x,y)); si; ++si )
{
- int next = mitm[o].link;
-
- if (is_valid_item( mitm[o] ))
+ if (is_valid_item( *si )) // FIXME is this check necessary?
{
- item_was_lost(mitm[o]);
- mitm[o].clear();
+ item_was_lost(*si);
+ si->clear();
}
-
- o = next;
}
}
void destroy_item_stack( int x, int y, int cause )
{
- int o = igrd[x][y];
-
- igrd[x][y] = NON_ITEM;
-
- while (o != NON_ITEM)
+ for ( stack_iterator si(coord_def(x,y)); si; ++si )
{
- int next = mitm[o].link;
-
- if (is_valid_item( mitm[o] ))
+ if (is_valid_item( *si )) // FIXME is this check necessary?
{
- item_was_destroyed(mitm[o], cause);
- mitm[o].clear();
+ item_was_destroyed( *si, cause);
+ si->clear();
}
-
- o = next;
}
}
@@ -633,12 +617,11 @@ static bool _invisible_to_player( const item_def& item )
static int _count_nonsquelched_items( int obj )
{
int result = 0;
- while (obj != NON_ITEM)
- {
- if (!_invisible_to_player(mitm[obj]))
+
+ for ( stack_iterator si(obj); si; ++si )
+ if (!_invisible_to_player(*si))
++result;
- obj = mitm[obj].link;
- }
+
return result;
}
@@ -654,13 +637,11 @@ static void _item_list_on_square( std::vector<const item_def*>& items,
|| _count_nonsquelched_items(obj));
// Loop through the items.
- while ( obj != NON_ITEM )
+ for ( stack_iterator si(obj); si; ++si )
{
// Add them to the items list if they qualify.
- if ( !have_nonsquelched || !_invisible_to_player(mitm[obj]) )
- items.push_back( &mitm[obj] );
-
- obj = mitm[obj].link;
+ if ( !have_nonsquelched || !_invisible_to_player(*si) )
+ items.push_back( & (*si) );
}
}
@@ -747,9 +728,9 @@ void item_check(bool verbose)
std::vector<const item_def*> items;
- _item_list_on_square( items, igrd[you.x_pos][you.y_pos], true );
+ _item_list_on_square( items, igrd(you.pos()), true );
- if (items.size() == 0)
+ if (items.empty())
{
if (verbose)
strm << "There are no items here." << std::endl;
@@ -967,8 +948,7 @@ static void _check_note_item(item_def &item)
if (item.flags & (ISFLAG_NOTED_GET | ISFLAG_NOTED_ID))
return;
- if (is_rune(item) || item.base_type == OBJ_ORBS
- || is_artefact(item))
+ if (is_rune(item) || item.base_type == OBJ_ORBS || is_artefact(item))
{
take_note(Note(NOTE_GET_ITEM, 0, 0, item.name(DESC_NOCAP_A).c_str(),
origin_desc(item).c_str()));
@@ -985,18 +965,17 @@ void origin_set(int x, int y)
{
int monnum = _first_corpse_monnum(x, y);
unsigned short pplace = get_packed_place();
- for (int link = igrd[x][y]; link != NON_ITEM; link = mitm[link].link)
+ for (stack_iterator si(coord_def(x,y)); si; ++si)
{
- item_def &item = mitm[link];
- if (origin_known(item))
+ if (origin_known( *si ))
continue;
- if (!item.orig_monnum)
- item.orig_monnum = static_cast<short>( monnum );
- item.orig_place = pplace;
+ if (!si->orig_monnum)
+ si->orig_monnum = static_cast<short>( monnum );
+ si->orig_place = pplace;
#ifdef DGL_MILESTONES
- _milestone_check(item);
+ _milestone_check(*si);
#endif
}
}
@@ -1186,7 +1165,7 @@ void pickup()
return;
}
- int o = igrd[you.x_pos][you.y_pos];
+ int o = igrd(you.pos());
const int num_nonsquelched = _count_nonsquelched_items(o);
if (o == NON_ITEM)
@@ -2155,15 +2134,8 @@ static void _autoinscribe_item( item_def& item )
static void _autoinscribe_floor_items()
{
- int o, next;
- o = igrd[you.x_pos][you.y_pos];
-
- while (o != NON_ITEM)
- {
- next = mitm[o].link;
- _autoinscribe_item( mitm[o] );
- o = next;
- }
+ for ( stack_iterator si(you.pos()); si; ++si )
+ _autoinscribe_item( *si );
}
static void _autoinscribe_inventory()
@@ -2294,7 +2266,7 @@ static void _do_autopickup()
return;
}
- int o = igrd[you.x_pos][you.y_pos];
+ int o = igrd(you.pos());
std::string pickup_warning;
while (o != NON_ITEM)
@@ -2379,22 +2351,15 @@ int inv_count(void)
item_def *find_floor_item(object_class_type cls, int sub_type)
{
- int item = NON_ITEM;
for (int y = 0; y < GYM; ++y)
for (int x = 0; x < GXM; ++x)
- {
- item = igrd[x][y];
- while (item != NON_ITEM)
- {
- item_def &i(mitm[item]);
-
- if (is_valid_item(i) && i.base_type == cls
- && i.sub_type == sub_type)
- return (&i);
+ for ( stack_iterator si(coord_def(x,y)); si; ++si )
+ if (is_valid_item( *si)
+ && si->base_type == cls && si->sub_type == sub_type)
+ {
+ return (& (*si));
+ }
- item = i.link;
- }
- }
return (NULL);
}
@@ -2471,10 +2436,9 @@ item_def find_item_type(object_class_type base_type, std::string name)
if (base_type == OBJ_UNASSIGNED)
{
- for (unsigned i = 0; i < sizeof(max_subtype) / sizeof(*max_subtype);
- ++i)
+ for (unsigned i = 0; i < ARRAYSZ(max_subtype); ++i)
{
- if (!max_subtype[i])
+ if (max_subtype[i] == 0)
continue;
if (_find_subtype_by_name(item, static_cast<object_class_type>(i),
diff --git a/crawl-ref/source/message.cc b/crawl-ref/source/message.cc
index fc9b8f2df1..a4c48ceb50 100644
--- a/crawl-ref/source/message.cc
+++ b/crawl-ref/source/message.cc
@@ -443,7 +443,7 @@ void mpr(const char *inf, msg_channel_type channel, int param)
// Did the message break?
if (i + stepsize < msglen)
{
- // Aes, find a nicer place to break it.
+ // Yes, find a nicer place to break it.
int lookback, where = 0;
for (lookback = 0; lookback < lookback_size; ++lookback)
{
diff --git a/crawl-ref/source/misc.cc b/crawl-ref/source/misc.cc
index c7ecf4b35f..132d82a60d 100644
--- a/crawl-ref/source/misc.cc
+++ b/crawl-ref/source/misc.cc
@@ -87,7 +87,7 @@
static void create_monster_hide(int mons_class)
{
- int o = get_item_slot( 100 + random2(200) );
+ int o = get_item_slot();
if (o == NON_ITEM)
return;
@@ -410,17 +410,15 @@ static void _potion_stack_changed_message(item_def &potion, int num_changed,
std::string msg;
if (potion.quantity == num_changed)
msg = "Your ";
+ else if (num_changed == 1)
+ msg = "One of your ";
+ else if (num_changed == 2)
+ msg = "Two of your ";
+ else if (num_changed >= (potion.quantity * 3) / 4)
+ msg = "Most of your ";
else
- {
- if (num_changed == 1)
- msg = "One of your ";
- else if (num_changed == 2)
- msg = "Two of your ";
- else if (num_changed >= (potion.quantity * 3) / 4)
- msg = "Most of your ";
- else
- msg = "Some of your ";
- }
+ msg = "Some of your ";
+
msg += potion.name(DESC_PLAIN, false);
if (coagulate)
@@ -694,7 +692,7 @@ bool maybe_coagulate_blood_potions_inv(item_def &blood)
// If we got here nothing was found!
// Create a new stack of potions.
- o = get_item_slot( 100 + random2(200) );
+ o = get_item_slot();
if (o == NON_ITEM)
return (false);
diff --git a/crawl-ref/source/ouch.cc b/crawl-ref/source/ouch.cc
index 7f61b825bf..4ff2e61713 100644
--- a/crawl-ref/source/ouch.cc
+++ b/crawl-ref/source/ouch.cc
@@ -551,21 +551,17 @@ void expose_items_to_element(beam_type flavour, int x, int y)
if (target_class == OBJ_UNASSIGNED)
return;
- for (int i = igrd[x][y]; i != NON_ITEM; i = mitm[i].link)
+ for (stack_iterator si(coord_def(x,y)); si; ++si)
{
- if (!is_valid_item(mitm[i]))
+ if (!is_valid_item(*si))
continue;
- if (is_valid_item(mitm[i])
- && (mitm[i].base_type == target_class
- || (target_class == OBJ_FOOD
- && mitm[i].base_type == OBJ_CORPSES)))
+ if ( si->base_type == target_class
+ || (target_class == OBJ_FOOD && si->base_type == OBJ_CORPSES))
{
- num_dest += mitm[i].quantity;
-
- item_was_destroyed(mitm[i]);
-
- destroy_item(i);
+ num_dest += si->quantity;
+ item_was_destroyed(*si);
+ destroy_item(si->index());
}
}
@@ -674,7 +670,7 @@ void lose_level()
void drain_exp(bool announce_full)
{
- int protection = player_prot_life();
+ const int protection = player_prot_life();
if (protection == 3)
{
@@ -698,9 +694,7 @@ void drain_exp(bool announce_full)
unsigned long total_exp = exp_needed( you.experience_level + 2 )
- exp_needed( you.experience_level + 1 );
- unsigned long exp_drained = total_exp * (10 + random2(11));
-
- exp_drained /= 100;
+ unsigned long exp_drained = (total_exp * (10 + random2(11))) / 100;
// TSO's protection.
if (you.religion == GOD_SHINING_ONE && you.piety > protection * 50)
diff --git a/crawl-ref/source/stuff.cc b/crawl-ref/source/stuff.cc
index 0e6809d9e7..b21e99b2fa 100644
--- a/crawl-ref/source/stuff.cc
+++ b/crawl-ref/source/stuff.cc
@@ -1128,6 +1128,11 @@ int yesnoquit( const char* str, bool safe, int safeanswer, bool allow_all,
}
}
+int grid_distance( const coord_def& p1, const coord_def& p2 )
+{
+ return grid_distance(p1.x, p1.y, p2.x, p2.y);
+}
+
// More accurate than distance() given the actual movement geometry -- bwr
int grid_distance( int x, int y, int x2, int y2 )
{
diff --git a/crawl-ref/source/stuff.h b/crawl-ref/source/stuff.h
index 50ea4c3494..2883e3cacf 100644
--- a/crawl-ref/source/stuff.h
+++ b/crawl-ref/source/stuff.h
@@ -146,6 +146,7 @@ inline bool map_bounds(const coord_def &p)
return map_bounds(p.x, p.y);
}
+int grid_distance( const coord_def& p1, const coord_def& p2 );
int grid_distance( int x, int y, int x2, int y2 );
int distance( int x, int y, int x2, int y2);
bool adjacent( int x, int y, int x2, int y2 );
diff --git a/crawl-ref/source/view.cc b/crawl-ref/source/view.cc
index f9e59cb24b..b5eb5c6362 100644
--- a/crawl-ref/source/view.cc
+++ b/crawl-ref/source/view.cc
@@ -4471,6 +4471,11 @@ void init_feature_table( void )
}
}
+unsigned get_screen_glyph( const coord_def &p)
+{
+ return get_screen_glyph(p.x, p.y);
+}
+
unsigned get_screen_glyph( int x, int y )
{
const coord_def ep = view2show(grid2view(coord_def(x,y)));
diff --git a/crawl-ref/source/view.h b/crawl-ref/source/view.h
index b43967695f..b00365cdf2 100644
--- a/crawl-ref/source/view.h
+++ b/crawl-ref/source/view.h
@@ -138,6 +138,7 @@ void get_item_glyph(const item_def *item, unsigned *glych,
void get_mons_glyph(const monsters *mons, unsigned *glych,
unsigned short *glycol);
unsigned get_screen_glyph( int x, int y );
+unsigned get_screen_glyph( const coord_def &p );
std::string stringize_glyph(unsigned glyph);
int multibyte_strlen(const std::string &s);