From 8ce947975fa9f9c0b3d8575ab43ff042c5d6b872 Mon Sep 17 00:00:00 2001 From: reaverb Date: Fri, 8 Aug 2014 03:46:43 -0400 Subject: Move item placement code from items() to the only place it is used --- crawl-ref/source/dungeon.cc | 34 +++++++++++++++++++++++++++++++++- crawl-ref/source/makeitem.cc | 22 +--------------------- 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/crawl-ref/source/dungeon.cc b/crawl-ref/source/dungeon.cc index fb53789bc0..2429324f4e 100644 --- a/crawl-ref/source/dungeon.cc +++ b/crawl-ref/source/dungeon.cc @@ -3977,6 +3977,33 @@ static void _builder_monsters() } } +/** + * Randomly place a single item + * + * @param item The item slot of the item being randomly placed + */ +static void _randomly_place_item(int item) +{ + coord_def itempos; + bool found = false; + for (int i = 0; i < 500 && !found; ++i) + { + itempos = random_in_bounds(); + const monster* mon = monster_at(itempos); + found = grd(itempos) == DNGN_FLOOR + && !map_masked(itempos, MMT_NO_ITEM) + // oklobs or statues are ok + && (!mon || !mons_is_firewood(mon)); + } + if (!found) + { + // Couldn't find a single good spot! + destroy_item(item); + } + else + move_item_to_grid(&item, itempos); +} + static void _builder_items() { int i = 0; @@ -3993,7 +4020,12 @@ static void _builder_items() specif_type = OBJ_GOLD; // Lots of gold in the orcish mines. for (i = 0; i < items_wanted; i++) - items(1, specif_type, OBJ_RANDOM, false, items_levels, MMT_NO_ITEM); + { + int item = items(1, specif_type, OBJ_RANDOM, true, items_levels); + + _randomly_place_item(item); + } + } static bool _connect_vault_exit(const coord_def& exit) diff --git a/crawl-ref/source/makeitem.cc b/crawl-ref/source/makeitem.cc index 3e39a602f4..9a3c06c5ee 100644 --- a/crawl-ref/source/makeitem.cc +++ b/crawl-ref/source/makeitem.cc @@ -2853,27 +2853,7 @@ int items(bool allow_uniques, item.link = NON_ITEM; } else - { - coord_def itempos; - bool found = false; - for (int i = 0; i < 500 && !found; ++i) - { - itempos = random_in_bounds(); - const monster* mon = monster_at(itempos); - found = grd(itempos) == DNGN_FLOOR - && !map_masked(itempos, mapmask) - // oklobs or statues are ok - && (!mon || !mons_is_firewood(mon)); - } - if (!found) - { - // Couldn't find a single good spot! - destroy_item(p); - return NON_ITEM; - } - move_item_to_grid(&p, itempos); - } - + die("dont_place is used outside dungeon.cc oops"); // Note that item might be invalidated now, since p could have changed. ASSERT(mitm[p].is_valid()); return p; -- cgit v1.2.3-54-g00ecf