summaryrefslogtreecommitdiffstats
path: root/crawl-ref
diff options
context:
space:
mode:
authorzelgadis <zelgadis@c06c8d41-db1a-0410-9941-cceddc491573>2008-12-03 06:08:48 +0000
committerzelgadis <zelgadis@c06c8d41-db1a-0410-9941-cceddc491573>2008-12-03 06:08:48 +0000
commit8bf4f93aa163d478558f5ea3897c6158bd9781ea (patch)
tree9cefd9fff350b86c4d83a7be00b16199e8fe46b9 /crawl-ref
parent921d8f93a339385678d72c8347725a5bc3de1145 (diff)
downloadcrawl-ref-8bf4f93aa163d478558f5ea3897c6158bd9781ea.tar.gz
crawl-ref-8bf4f93aa163d478558f5ea3897c6158bd9781ea.zip
Add another optional parameter to items() of makeitem.{cc,h}, the agent
parameter. If not -1 then it will be used to set the acquirement agent of the item. This is done in items() so that make_item_randart() can use it if it's called from items(). Before this _god_fits_artefact() in randart.cc was only being called for choosing an appropriate god for random artifact names, and not to check the appropriateness of the randart proeprties chosen for randart god gifts. Changed _god_fits_artefact() so that if a bug leads a god to gifting an item with an inapropriate base_type or sub_type that it will give an assertion or error message instead of causing make_item_randart() to go into an infinite loop. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@7726 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref')
-rw-r--r--crawl-ref/source/effects.cc20
-rw-r--r--crawl-ref/source/makeitem.cc8
-rw-r--r--crawl-ref/source/makeitem.h2
-rw-r--r--crawl-ref/source/randart.cc84
-rw-r--r--crawl-ref/source/religion.cc11
-rw-r--r--crawl-ref/source/xom.cc9
6 files changed, 92 insertions, 42 deletions
diff --git a/crawl-ref/source/effects.cc b/crawl-ref/source/effects.cc
index 3fdbb64552..7bbe08c462 100644
--- a/crawl-ref/source/effects.cc
+++ b/crawl-ref/source/effects.cc
@@ -1460,7 +1460,20 @@ bool acquirement(object_class_type class_wanted, int agent,
if (!silenced(you.pos()) && !quiet)
mprf(MSGCH_SOUND, grid_item_destruction_message(grd(you.pos())));
- item_was_destroyed(mitm[igrd(you.pos())], NON_MONSTER);
+ if (agent > GOD_NO_GOD && agent < NUM_GODS)
+ {
+ if (agent == GOD_XOM)
+ simple_god_message(" snickers.", GOD_XOM);
+ else
+ {
+ ASSERT(!"God gave gift item while player was on grid which "
+ "destroys items.");
+ mprf(MSGCH_ERROR, "%s gave a god gift while you were on "
+ "terrain which destroys items.",
+ god_name((god_type) agent).c_str());
+ }
+ }
+
*item_index = NON_ITEM;
}
else
@@ -1475,7 +1488,8 @@ bool acquirement(object_class_type class_wanted, int agent,
class_wanted = OBJ_POTIONS;
thing_created = items( 1, class_wanted, type_wanted, true,
- MAKE_GOOD_ITEM, MAKE_ITEM_RANDOM_RACE );
+ MAKE_GOOD_ITEM, MAKE_ITEM_RANDOM_RACE,
+ 0, 0, agent );
if (thing_created == NON_ITEM)
continue;
@@ -1693,7 +1707,6 @@ bool acquirement(object_class_type class_wanted, int agent,
thing.inscription = "god gift";
if (is_random_artefact(thing))
{
- origin_acquired(thing, agent);
if (!is_unrandom_artefact(thing))
{
// Give another name that takes god gift into account.
@@ -1711,7 +1724,6 @@ bool acquirement(object_class_type class_wanted, int agent,
{
if (!quiet)
canned_msg(MSG_SOMETHING_APPEARS);
- origin_acquired(mitm[thing_created], agent);
}
*item_index = thing_created;
}
diff --git a/crawl-ref/source/makeitem.cc b/crawl-ref/source/makeitem.cc
index bd7131e0bd..80f2b20771 100644
--- a/crawl-ref/source/makeitem.cc
+++ b/crawl-ref/source/makeitem.cc
@@ -2648,7 +2648,8 @@ int items( int allow_uniques, // not just true-false,
int item_race, // weapon / armour racial categories
// item_race also gives type of rune!
unsigned mapmask,
- int force_ego) // desired ego/brand
+ int force_ego, // desired ego/brand
+ int agent) // acquirement agent, if not -1
{
// TODO: Allow a combination of force_ego > 0 and
// force_type == OBJ_RANDOM, so that (for example) you could have
@@ -2667,6 +2668,11 @@ int items( int allow_uniques, // not just true-false,
item_def& item(mitm[p]);
+ // make_item_randart() might do things differently based upon the
+ // acquirement agent, especially for god gifts.
+ if (agent != -1)
+ origin_acquired(item, agent);
+
const bool force_good = (item_level == MAKE_GOOD_ITEM);
if (force_ego > 0)
diff --git a/crawl-ref/source/makeitem.h b/crawl-ref/source/makeitem.h
index 26797f7bb3..7335055592 100644
--- a/crawl-ref/source/makeitem.h
+++ b/crawl-ref/source/makeitem.h
@@ -23,7 +23,7 @@ enum item_make_species_type
int items( int allow_uniques, object_class_type force_class, int force_type,
bool dont_place, int item_level, int item_race,
- unsigned mapmask = 0, int force_ego = 0 );
+ unsigned mapmask = 0, int force_ego = 0, int agent = -1 );
void item_colour( item_def &item );
void init_rod_mp(item_def &item);
diff --git a/crawl-ref/source/randart.cc b/crawl-ref/source/randart.cc
index 234ac1eff4..b6b407cfba 100644
--- a/crawl-ref/source/randart.cc
+++ b/crawl-ref/source/randart.cc
@@ -40,11 +40,67 @@ static const char* _get_fixedart_name(const item_def &item);
// dungeon.cc and consists of giving it a few random things - plus &
// plus2 mainly.
-static bool _god_fits_artefact(const god_type which_god, const item_def &item)
+static bool _god_fits_artefact(const god_type which_god, const item_def &item,
+ bool name_check_only = false)
{
if (which_god == GOD_NO_GOD)
return (false);
+ // First check the item's base_type and sub_type, then check the
+ // item's brand and other randart properties.
+ bool type_bad = false;
+ switch (which_god)
+ {
+ case GOD_ELYVILON: // peaceful healer god, no weapons, no berserking
+ if (item.base_type == OBJ_WEAPONS)
+ type_bad = true;
+
+ if (item.base_type == OBJ_JEWELLERY && item.sub_type == AMU_RAGE)
+ type_bad = true;
+ break;
+
+ case GOD_OKAWARU: // precision fighter
+ if (item.base_type == OBJ_JEWELLERY && item.sub_type == AMU_INACCURACY)
+ type_bad = true;
+ break;
+
+ case GOD_ZIN:
+ if (item.base_type == OBJ_JEWELLERY && item.sub_type == RING_HUNGER)
+ type_bad = true;
+ break;
+
+ case GOD_SIF_MUNA:
+ case GOD_KIKUBAAQUDGHA:
+ case GOD_VEHUMET:
+ // The magic gods: no weapons, no preventing spellcasting.
+ if (item.base_type == OBJ_WEAPONS)
+ type_bad = true;
+ break;
+
+ case GOD_TROG: // hates anything enhancing magic
+ if (item.base_type == OBJ_JEWELLERY && (item.sub_type == RING_WIZARDRY
+ || item.sub_type == RING_FIRE || item.sub_type == RING_ICE
+ || item.sub_type == RING_MAGICAL_POWER))
+ {
+ type_bad = true;
+ }
+ break;
+
+ default:
+ break;
+ }
+
+ if (type_bad && !name_check_only)
+ {
+ ASSERT(!"God attempting to gift invalid type of item.");
+ mprf(MSGCH_ERROR, "%s attempting to gift invalid type of item.");
+ // Prevent infinite loop in make_item_randart()
+ return (true);
+ }
+
+ if (type_bad)
+ return (false);
+
const int brand = get_weapon_brand(item);
if (is_evil_god(which_god) && brand == SPWPN_HOLY_WRATH)
@@ -65,12 +121,6 @@ static bool _god_fits_artefact(const god_type which_god, const item_def &item)
break;
case GOD_ELYVILON: // peaceful healer god, no weapons, no berserking
- if (item.base_type == OBJ_WEAPONS)
- return (false);
-
- if (item.base_type == OBJ_JEWELLERY && item.sub_type == AMU_RAGE)
- return (false);
-
if (randart_wpn_property(item, RAP_ANGRY)
|| randart_wpn_property(item, RAP_BERSERK))
{
@@ -78,15 +128,7 @@ static bool _god_fits_artefact(const god_type which_god, const item_def &item)
}
break;
- case GOD_OKAWARU: // precision fighter
- if (item.base_type == OBJ_JEWELLERY && item.sub_type == AMU_INACCURACY)
- return (false);
- break;
-
case GOD_ZIN:
- if (item.base_type == OBJ_JEWELLERY && item.sub_type == RING_HUNGER)
- return (false); // goes against food theme
-
if (randart_wpn_property( item, RAP_MUTAGENIC ))
return (false); // goes against anti-mutagenic theme
break;
@@ -110,21 +152,11 @@ static bool _god_fits_artefact(const god_type which_god, const item_def &item)
case GOD_SIF_MUNA:
case GOD_KIKUBAAQUDGHA:
case GOD_VEHUMET:
- // The magic gods: no weapons, no preventing spellcasting.
- if (item.base_type == OBJ_WEAPONS)
- return (false);
-
if (randart_wpn_property( item, RAP_PREVENT_SPELLCASTING ))
return (false);
break;
case GOD_TROG: // hates anything enhancing magic
- if (item.base_type == OBJ_JEWELLERY && (item.sub_type == RING_WIZARDRY
- || item.sub_type == RING_FIRE || item.sub_type == RING_ICE
- || item.sub_type == RING_MAGICAL_POWER))
- {
- return (false);
- }
if (brand == SPWPN_PAIN) // involves magic
return (false);
@@ -242,7 +274,7 @@ static std::string _replace_name_parts(const std::string name_in,
{
which_god = static_cast<god_type>(random2(NUM_GODS - 1) + 1);
}
- while (!_god_fits_artefact(which_god, item));
+ while (!_god_fits_artefact(which_god, item), true);
}
name = replace_all(name, "@god_name@", god_name(which_god, false));
diff --git a/crawl-ref/source/religion.cc b/crawl-ref/source/religion.cc
index 96f45320d3..491e0f2639 100644
--- a/crawl-ref/source/religion.cc
+++ b/crawl-ref/source/religion.cc
@@ -1137,7 +1137,8 @@ static void _give_nemelex_gift()
_update_sacrifice_weights(choice);
int thing_created = items( 1, OBJ_MISCELLANY, gift_type,
- true, 1, MAKE_ITEM_RANDOM_RACE );
+ true, 1, MAKE_ITEM_RANDOM_RACE,
+ 0, 0, GOD_NEMELEX_XOBEH );
if (thing_created != NON_ITEM)
{
@@ -1174,7 +1175,6 @@ static void _give_nemelex_gift()
deck.inscription = "god gift";
move_item_to_grid( &thing_created, you.pos() );
- origin_acquired(deck, you.religion);
simple_god_message(" grants you a gift!");
more();
@@ -1972,7 +1972,8 @@ static void _do_god_gift(bool prayed_for)
else
{
int thing_created = items(1, OBJ_BOOKS, gift, true, 1,
- MAKE_ITEM_RANDOM_RACE);
+ MAKE_ITEM_RANDOM_RACE,
+ 0, 0, you.religion);
if (thing_created == NON_ITEM)
return;
@@ -1982,7 +1983,6 @@ static void _do_god_gift(bool prayed_for)
{
success = true;
mitm[thing_created].inscription = "god gift";
- origin_acquired(mitm[thing_created], you.religion);
}
}
@@ -4199,7 +4199,8 @@ static bool _beogh_retribution()
// Create item.
int slot = items(0, OBJ_WEAPONS, WPN_CLUB + random2(13),
true, you.experience_level,
- am_orc ? MAKE_ITEM_NO_RACE : MAKE_ITEM_ORCISH);
+ am_orc ? MAKE_ITEM_NO_RACE : MAKE_ITEM_ORCISH,
+ 0, 0, GOD_BEOGH);
if (slot == -1)
continue;
diff --git a/crawl-ref/source/xom.cc b/crawl-ref/source/xom.cc
index 36eecf6854..63ecd54eb0 100644
--- a/crawl-ref/source/xom.cc
+++ b/crawl-ref/source/xom.cc
@@ -245,8 +245,11 @@ static void _try_brand_switch(const int item_index)
static void _xom_make_item(object_class_type base, int subtype, int power)
{
+ god_acting gdact(GOD_XOM);
+
int thing_created =
- items(true, base, subtype, true, power, MAKE_ITEM_RANDOM_RACE);
+ items(true, base, subtype, true, power, MAKE_ITEM_RANDOM_RACE,
+ 0, 0, GOD_XOM);
if (thing_created == NON_ITEM)
{
@@ -256,14 +259,10 @@ static void _xom_make_item(object_class_type base, int subtype, int power)
_try_brand_switch(thing_created);
- god_acting gdact(GOD_XOM);
-
move_item_to_grid(&thing_created, you.pos());
mitm[thing_created].inscription = "god gift";
canned_msg(MSG_SOMETHING_APPEARS);
stop_running();
-
- origin_acquired(mitm[thing_created], GOD_XOM);
}
static void _xom_acquirement(object_class_type force_class)