summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--crawl-ref/source/beam.cc10
-rw-r--r--crawl-ref/source/effects.cc23
-rw-r--r--crawl-ref/source/item_use.cc21
-rw-r--r--crawl-ref/source/item_use.h3
-rw-r--r--crawl-ref/source/items.cc38
-rw-r--r--crawl-ref/source/items.h6
-rw-r--r--crawl-ref/source/misc.cc29
-rw-r--r--crawl-ref/source/mon-act.cc2
-rw-r--r--crawl-ref/source/mon-stuff.cc39
-rw-r--r--crawl-ref/source/mon-transit.cc2
-rw-r--r--crawl-ref/source/monster.cc42
-rw-r--r--crawl-ref/source/wiz-item.cc3
-rw-r--r--crawl-ref/source/xom.cc2
13 files changed, 90 insertions, 130 deletions
diff --git a/crawl-ref/source/beam.cc b/crawl-ref/source/beam.cc
index abe97ceb66..451cadd81d 100644
--- a/crawl-ref/source/beam.cc
+++ b/crawl-ref/source/beam.cc
@@ -3140,7 +3140,7 @@ void bolt::drop_object()
return;
}
- if (!thrown_object_destroyed(item, pos(), false))
+ if (!thrown_object_destroyed(item, pos()))
{
if (item->sub_type == MI_THROWING_NET)
{
@@ -3154,10 +3154,10 @@ void bolt::drop_object()
set_item_stationary(*item);
}
}
+
copy_item_to_grid(*item, pos(), 1);
}
- else if (item->sub_type == MI_LARGE_ROCK
- && !feat_destroys_items(grd(pos())))
+ else if (item->sub_type == MI_LARGE_ROCK)
{
// Large rocks mulch to stone.
std::string sound_msg = "You hear a cracking sound!";
@@ -3176,6 +3176,10 @@ void bolt::drop_object()
copy_item_to_grid(*item, pos(), item->quantity);
}
+ else
+ {
+ item_was_destroyed(*item, NON_MONSTER);
+ }
}
// Returns true if the beam hits the player, fuzzing the beam if necessary
diff --git a/crawl-ref/source/effects.cc b/crawl-ref/source/effects.cc
index bede6d46c2..dcec8a0373 100644
--- a/crawl-ref/source/effects.cc
+++ b/crawl-ref/source/effects.cc
@@ -2315,14 +2315,12 @@ int acquirement_create_item(object_class_type class_wanted,
if (agent > GOD_NO_GOD && agent < NUM_GODS && agent == you.religion)
thing.inscription = "god gift";
- move_item_to_grid( &thing_created, pos );
-
- // This should never actually be NON_ITEM because of the way
- // move_item_to_grid works (doesn't create a new item ever),
- // but we're checking it anyways. -- bwr
+ // Moving this above the move since it might not exist after falling.
if (thing_created != NON_ITEM && !quiet)
canned_msg(MSG_SOMETHING_APPEARS);
+ move_item_to_grid( &thing_created, pos );
+
return (thing_created);
}
@@ -2382,10 +2380,6 @@ bool acquirement(object_class_type class_wanted, int agent,
if (feat_destroys_items(grd(you.pos())))
{
- // How sad (and stupid).
- if (!silenced(you.pos()) && !quiet)
- mprf(MSGCH_SOUND, feat_item_destruction_message(grd(you.pos())));
-
if (agent > GOD_NO_GOD && agent < NUM_GODS)
{
if (agent == GOD_XOM)
@@ -2399,18 +2393,11 @@ bool acquirement(object_class_type class_wanted, int agent,
god_name((god_type) agent).c_str());
}
}
-
- *item_index = NON_ITEM;
-
- // Well, the item may have fallen in the drink, but the intent is
- // that acquirement happened. -- bwr
- return (true);
}
- *item_index =
- acquirement_create_item(class_wanted, agent, quiet, you.pos(), debug);
+ acquirement_create_item(class_wanted, agent, quiet, you.pos(), debug);
- return (*item_index != NON_ITEM);
+ return (true);
}
bool recharge_wand(int item_slot)
diff --git a/crawl-ref/source/item_use.cc b/crawl-ref/source/item_use.cc
index fd01008e25..07aa928eb4 100644
--- a/crawl-ref/source/item_use.cc
+++ b/crawl-ref/source/item_use.cc
@@ -3113,7 +3113,7 @@ bool throw_it(bolt &pbolt, int throw_2, bool teleport, int acc_bonus,
pbolt.fire();
// The item can be destroyed before returning.
- if (did_return && thrown_object_destroyed(&item, pbolt.target, true))
+ if (did_return && thrown_object_destroyed(&item, pbolt.target))
did_return = false;
}
@@ -3178,8 +3178,7 @@ bool throw_it(bolt &pbolt, int throw_2, bool teleport, int acc_bonus,
return (hit);
}
-bool thrown_object_destroyed(item_def *item, const coord_def& where,
- bool returning)
+bool thrown_object_destroyed(item_def *item, const coord_def& where)
{
ASSERT(item != NULL);
@@ -3244,22 +3243,6 @@ bool thrown_object_destroyed(item_def *item, const coord_def& where,
// destruction: plus / (1 + plus) chance of survival.
bool destroyed = (chance == 0) ? false : (one_chance_in(chance)
&& one_chance_in(item->plus + 1));
- bool hostile_grid = feat_destroys_items(grd(where));
-
- // Non-returning items thrown into item-destroying grids are always
- // destroyed. Returning items are only destroyed if they would have
- // been randomly destroyed anyway.
- if (returning && !destroyed)
- hostile_grid = false;
-
- if (hostile_grid)
- {
- if (player_can_hear(where))
- mprf(MSGCH_SOUND, feat_item_destruction_message(grd(where)));
-
- item_was_destroyed(*item, NON_MONSTER);
- destroyed = true;
- }
return destroyed;
}
diff --git a/crawl-ref/source/item_use.h b/crawl-ref/source/item_use.h
index a76dc3843c..bba83aa3b4 100644
--- a/crawl-ref/source/item_use.h
+++ b/crawl-ref/source/item_use.h
@@ -104,8 +104,7 @@ void throw_noise(actor* act, const bolt &pbolt, const item_def &ammo);
bool throw_it(bolt &pbolt, int throw_2, bool teleport = false,
int acc_bonus = 0, dist *target = NULL);
-bool thrown_object_destroyed(item_def *item, const coord_def& where,
- bool returning);
+bool thrown_object_destroyed(item_def *item, const coord_def& where);
void prompt_inscribe_item();
int launcher_shield_slowdown(const item_def &launcher,
diff --git a/crawl-ref/source/items.cc b/crawl-ref/source/items.cc
index 29b25a021b..81adf191dd 100644
--- a/crawl-ref/source/items.cc
+++ b/crawl-ref/source/items.cc
@@ -1719,7 +1719,10 @@ void mark_items_non_pickup_at(const coord_def &pos)
//
// Done this way in the hopes that it will be obvious from
// calling code that "obj" is possibly modified.
-bool move_item_to_grid( int *const obj, const coord_def& p )
+//
+// Returns false on error or level full - cases where you
+// keep the item.
+bool move_item_to_grid( int *const obj, const coord_def& p, bool silent )
{
ASSERT(in_bounds(p));
@@ -1730,6 +1733,18 @@ bool move_item_to_grid( int *const obj, const coord_def& p )
item_def& item(mitm[ob]);
+ if (feat_destroys_items(grd(p)))
+ {
+ if (!silenced(p) && !silent)
+ mprf(MSGCH_SOUND, feat_item_destruction_message(grd(p)));
+
+ item_was_destroyed(item, NON_MONSTER);
+ destroy_item(ob);
+ ob = NON_ITEM;
+
+ return (true);
+ }
+
// If it's a stackable type...
if (is_stackable_item( item ))
{
@@ -1809,15 +1824,25 @@ void move_item_stack_to_grid( const coord_def& from, const coord_def& to )
}
-// Returns quantity dropped.
+// Returns false iff no items could be dropped.
bool copy_item_to_grid( const item_def &item, const coord_def& p,
- int quant_drop, bool mark_dropped )
+ int quant_drop, bool mark_dropped, bool silent )
{
ASSERT(in_bounds(p));
if (quant_drop == 0)
return (false);
+ if (feat_destroys_items(grd(p)))
+ {
+ if (!silenced(p))
+ mprf(MSGCH_SOUND, feat_item_destruction_message(grd(p)));
+
+ item_was_destroyed(item, NON_MONSTER);
+
+ return (true);
+ }
+
// default quant_drop == -1 => drop all
if (quant_drop < 0)
quant_drop = item.quantity;
@@ -1966,9 +1991,8 @@ bool drop_item( int item_dropped, int quant_drop, bool try_offer )
const dungeon_feature_type my_grid = grd(you.pos());
- if (!feat_destroys_items(my_grid)
- && !copy_item_to_grid( you.inv[item_dropped],
- you.pos(), quant_drop, true ))
+ if (!copy_item_to_grid( you.inv[item_dropped],
+ you.pos(), quant_drop, true, true ))
{
mpr("Too many items on this level, not dropping the item.");
return (false);
@@ -1981,8 +2005,6 @@ bool drop_item( int item_dropped, int quant_drop, bool try_offer )
{
if (!silenced(you.pos()))
mprf(MSGCH_SOUND, feat_item_destruction_message(my_grid));
-
- item_was_destroyed(you.inv[item_dropped], NON_MONSTER);
}
else if (strstr(you.inv[item_dropped].inscription.c_str(), "=s") != 0)
StashTrack.add_stash();
diff --git a/crawl-ref/source/items.h b/crawl-ref/source/items.h
index 4ffa1c9c30..8d82197764 100644
--- a/crawl-ref/source/items.h
+++ b/crawl-ref/source/items.h
@@ -34,7 +34,8 @@ bool dec_mitm_item_quantity(int obj, int amount);
void inc_inv_item_quantity(int obj, int amount, bool suppress_burden = false);
void inc_mitm_item_quantity(int obj, int amount);
-bool move_item_to_grid( int *const obj, const coord_def& p );
+bool move_item_to_grid( int *const obj, const coord_def& p,
+ bool silent = false );
void move_item_stack_to_grid( const coord_def& from, const coord_def& to );
void note_inscribe_item(item_def &item);
int move_item_to_player(int obj, int quant_got, bool quiet = false,
@@ -77,7 +78,8 @@ void item_list_on_square( std::vector<const item_def*>& items,
bool copy_item_to_grid( const item_def &item, const coord_def& p,
int quant_drop = -1, // item.quantity by default
- bool mark_dropped = false);
+ bool mark_dropped = false,
+ bool silent = false );
bool move_top_item( const coord_def &src, const coord_def &dest );
diff --git a/crawl-ref/source/misc.cc b/crawl-ref/source/misc.cc
index 4bac2e7ff0..b9d9fdabb3 100644
--- a/crawl-ref/source/misc.cc
+++ b/crawl-ref/source/misc.cc
@@ -1041,23 +1041,18 @@ void split_potions_into_decay( int obj, int amount, bool need_msg )
}
}
- // Only bother creating a distinct stack of potions
- // if it won't get destroyed right away.
- if (!feat_destroys_items(grd(you.pos())))
- {
- item_def potion2;
- potion2.base_type = OBJ_POTIONS;
- potion2.sub_type = POT_DECAY;
- // Keep description as it was.
- potion2.plus = potion.plus;
- potion2.quantity = amount;
- potion2.colour = potion.colour;
- potion2.plus2 = 0;
- potion2.flags = 0;
- potion2.special = 0;
-
- copy_item_to_grid(potion2, you.pos());
- }
+ item_def potion2;
+ potion2.base_type = OBJ_POTIONS;
+ potion2.sub_type = POT_DECAY;
+ // Keep description as it was.
+ potion2.plus = potion.plus;
+ potion2.quantity = amount;
+ potion2.colour = potion.colour;
+ potion2.plus2 = 0;
+ potion2.flags = 0;
+ potion2.special = 0;
+
+ copy_item_to_grid(potion2, you.pos());
// Is decreased even if the decay stack goes splat.
dec_inv_item_quantity(obj, amount);
diff --git a/crawl-ref/source/mon-act.cc b/crawl-ref/source/mon-act.cc
index 31d1c990a7..18ad9a1b01 100644
--- a/crawl-ref/source/mon-act.cc
+++ b/crawl-ref/source/mon-act.cc
@@ -1413,7 +1413,7 @@ static bool _mons_throw(struct monsters *monster, struct bolt &pbolt,
pbolt.fire();
// The item can be destroyed before returning.
- if (really_returns && thrown_object_destroyed(&item, pbolt.target, true))
+ if (really_returns && thrown_object_destroyed(&item, pbolt.target))
{
really_returns = false;
}
diff --git a/crawl-ref/source/mon-stuff.cc b/crawl-ref/source/mon-stuff.cc
index ca7b9cf12c..bcaeecc95a 100644
--- a/crawl-ref/source/mon-stuff.cc
+++ b/crawl-ref/source/mon-stuff.cc
@@ -255,10 +255,6 @@ bool curse_an_item( bool decay_potions, bool quiet )
void monster_drop_ething(monsters *monster, bool mark_item_origins,
int owner_id)
{
- const bool hostile_grid = feat_destroys_items(grd(monster->pos()));
-
- bool destroyed = false;
-
// Drop weapons & missiles last (ie on top) so others pick up.
for (int i = NUM_MONSTER_SLOTS - 1; i >= 0; i--)
{
@@ -268,30 +264,25 @@ void monster_drop_ething(monsters *monster, bool mark_item_origins,
{
const bool summoned_item =
testbits(mitm[item].flags, ISFLAG_SUMMONED);
- if (hostile_grid || summoned_item)
+ if (summoned_item)
{
item_was_destroyed(mitm[item], monster->mindex());
destroy_item( item );
- if (!summoned_item)
- destroyed = true;
}
else
{
if (monster->friendly() && mitm[item].is_valid())
mitm[item].flags |= ISFLAG_DROPPED_BY_ALLY;
- move_item_to_grid(&item, monster->pos());
-
if (mark_item_origins && mitm[item].is_valid())
origin_set_monster(mitm[item], monster);
+
+ move_item_to_grid(&item, monster->pos());
}
monster->inv[i] = NON_ITEM;
}
}
-
- if (destroyed)
- mprf(MSGCH_SOUND, feat_item_destruction_message(grd(monster->pos())));
}
monster_type fill_out_corpse(const monsters* monster, item_def& corpse,
@@ -421,14 +412,6 @@ bool explode_corpse(item_def& corpse, const coord_def& where)
--nchunks;
- if (feat_destroys_items(grd(cp)))
- {
- if (!silenced(cp))
- mprf(MSGCH_SOUND, feat_item_destruction_message(grd(cp)));
-
- continue;
- }
-
dprf("Success");
copy_item_to_grid(corpse, cp);
@@ -483,16 +466,8 @@ int place_monster_corpse(const monsters *monster, bool silent,
return (-1);
}
- if (feat_destroys_items(grd(monster->pos())))
- {
- item_was_destroyed(corpse);
- destroy_item(o);
- return (-1);
- }
-
- // Don't care if 'o' is changed, and it shouldn't be (corpses don't
- // stack).
move_item_to_grid(&o, monster->pos());
+
if (you.see_cell(monster->pos()))
{
if (force && !silent)
@@ -507,10 +482,12 @@ int place_monster_corpse(const monsters *monster, bool silent,
}
const bool poison = (mons_corpse_effect(corpse_class) == CE_POISONOUS
&& player_res_poison() <= 0);
- tutorial_dissection_reminder(!poison);
+
+ if (o != NON_ITEM)
+ tutorial_dissection_reminder(!poison);
}
- return (o);
+ return (o == NON_ITEM ? -1 : o);
}
static void _tutorial_inspect_kill()
diff --git a/crawl-ref/source/mon-transit.cc b/crawl-ref/source/mon-transit.cc
index 49a1e37ba0..6db3c417ca 100644
--- a/crawl-ref/source/mon-transit.cc
+++ b/crawl-ref/source/mon-transit.cc
@@ -214,7 +214,7 @@ void place_transiting_items()
pos, true);
// List of items we couldn't place.
- if (!copy_item_to_grid(*item, where_to_go))
+ if (!copy_item_to_grid(*item, where_to_go, 1, false, true))
keep.push_back(*item);
}
diff --git a/crawl-ref/source/monster.cc b/crawl-ref/source/monster.cc
index 2f83c01d6f..de3af6b0a9 100644
--- a/crawl-ref/source/monster.cc
+++ b/crawl-ref/source/monster.cc
@@ -1154,12 +1154,8 @@ bool monsters::drop_item(int eslot, int near)
was_unequipped = true;
}
- bool on_floor = true;
-
if (pitem->flags & ISFLAG_SUMMONED)
{
- on_floor = false;
-
if (need_message(near))
mprf("%s %s as %s drops %s!",
pitem->name(DESC_CAP_THE).c_str(),
@@ -1170,38 +1166,30 @@ bool monsters::drop_item(int eslot, int near)
item_was_destroyed(*pitem, mindex());
destroy_item(item_index);
}
- else if (!move_item_to_grid(&item_index, pos()))
- {
- // Re-equip item if we somehow failed to drop it.
- if (was_unequipped)
- equip(*pitem, eslot, near);
-
- return (false);
- }
-
- // move_item_to_grid could change item_index, so
- // update pitem.
- pitem = &mitm[item_index];
-
- if (on_floor)
+ else
{
- if (friendly())
- pitem->flags |= ISFLAG_DROPPED_BY_ALLY;
-
if (need_message(near))
{
mprf("%s drops %s.", name(DESC_CAP_THE).c_str(),
pitem->name(DESC_NOCAP_A).c_str());
}
- dungeon_feature_type feat = grd(pos());
- if (feat_destroys_items(feat))
+ if (!move_item_to_grid(&item_index, pos()))
{
- if ( player_can_hear(pos()) )
- mprf(MSGCH_SOUND, feat_item_destruction_message(feat));
+ // Re-equip item if we somehow failed to drop it.
+ if (was_unequipped)
+ equip(*pitem, eslot, near);
- item_was_destroyed(*pitem, mindex());
- unlink_item(item_index);
+ return (false);
+ }
+
+ if (friendly() && item_index != NON_ITEM)
+ {
+ // move_item_to_grid could change item_index, so
+ // update pitem.
+ pitem = &mitm[item_index];
+
+ pitem->flags |= ISFLAG_DROPPED_BY_ALLY;
}
}
diff --git a/crawl-ref/source/wiz-item.cc b/crawl-ref/source/wiz-item.cc
index 6fa4b411b0..1bdce290dd 100644
--- a/crawl-ref/source/wiz-item.cc
+++ b/crawl-ref/source/wiz-item.cc
@@ -50,6 +50,9 @@ static void _make_all_books()
move_item_to_grid(&thing, you.pos());
+ if (thing == NON_ITEM)
+ continue;
+
item_def book(mitm[thing]);
mark_had_book(book);
diff --git a/crawl-ref/source/xom.cc b/crawl-ref/source/xom.cc
index 4f01f1145a..4fdb333dd4 100644
--- a/crawl-ref/source/xom.cc
+++ b/crawl-ref/source/xom.cc
@@ -682,9 +682,9 @@ static void _xom_make_item(object_class_type base, int subtype, int power)
mitm[thing_created].name(DESC_PLAIN).c_str());
take_note(Note(NOTE_XOM_EFFECT, you.piety, -1, gift_buf), true);
- move_item_to_grid(&thing_created, you.pos());
mitm[thing_created].inscription = "god gift";
canned_msg(MSG_SOMETHING_APPEARS);
+ move_item_to_grid(&thing_created, you.pos());
stop_running();
}