summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/randart.cc
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/source/randart.cc
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/source/randart.cc')
-rw-r--r--crawl-ref/source/randart.cc84
1 files changed, 58 insertions, 26 deletions
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));