summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source
diff options
context:
space:
mode:
authorAdam Borowski <kilobyte@angband.pl>2009-10-21 22:15:36 +0200
committerAdam Borowski <kilobyte@angband.pl>2009-10-21 22:15:36 +0200
commit80dbdf1828e0ce233d8adf8ca6ab1a5b4fc74e03 (patch)
treeed0acd9c4994191196a1d90b01415db708564066 /crawl-ref/source
parent10cffb19a8667ff227f3a47010097e150a54b761 (diff)
downloadcrawl-ref-80dbdf1828e0ce233d8adf8ca6ab1a5b4fc74e03.tar.gz
crawl-ref-80dbdf1828e0ce233d8adf8ca6ab1a5b4fc74e03.zip
Slightly reduce religion.cc by yanking item-handling stuff to goditem.cc
Diffstat (limited to 'crawl-ref/source')
-rw-r--r--crawl-ref/source/describe.cc1
-rw-r--r--crawl-ref/source/fight.cc1
-rw-r--r--crawl-ref/source/goditem.cc561
-rw-r--r--crawl-ref/source/goditem.h43
-rw-r--r--crawl-ref/source/item_use.cc1
-rw-r--r--crawl-ref/source/itemname.cc3
-rw-r--r--crawl-ref/source/makefile.obj1
-rw-r--r--crawl-ref/source/mon-util.cc1
-rw-r--r--crawl-ref/source/player.cc1
-rw-r--r--crawl-ref/source/religion.cc546
-rw-r--r--crawl-ref/source/religion.h30
-rw-r--r--crawl-ref/source/spells2.cc1
-rw-r--r--crawl-ref/source/spells3.cc1
-rw-r--r--crawl-ref/source/spl-book.cc1
-rw-r--r--crawl-ref/source/spl-cast.cc1
-rw-r--r--crawl-ref/source/view.cc1
-rw-r--r--crawl-ref/source/xom.cc1
17 files changed, 619 insertions, 576 deletions
diff --git a/crawl-ref/source/describe.cc b/crawl-ref/source/describe.cc
index 8f075f1b87..26366907cb 100644
--- a/crawl-ref/source/describe.cc
+++ b/crawl-ref/source/describe.cc
@@ -29,6 +29,7 @@
#include "fight.h"
#include "food.h"
#include "ghost.h"
+#include "goditem.h"
#include "invent.h"
#include "itemname.h"
#include "itemprop.h"
diff --git a/crawl-ref/source/fight.cc b/crawl-ref/source/fight.cc
index e1e8d6b339..17f7c5b322 100644
--- a/crawl-ref/source/fight.cc
+++ b/crawl-ref/source/fight.cc
@@ -27,6 +27,7 @@
#include "delay.h"
#include "effects.h"
#include "food.h"
+#include "goditem.h"
#include "invent.h"
#include "items.h"
#include "itemname.h"
diff --git a/crawl-ref/source/goditem.cc b/crawl-ref/source/goditem.cc
new file mode 100644
index 0000000000..be63717a01
--- /dev/null
+++ b/crawl-ref/source/goditem.cc
@@ -0,0 +1,561 @@
+/*
+ * File: goditem.cc
+ * Summary: Gods' attitude towards items.
+ */
+
+#include "AppHdr.h"
+
+#include "religion.h"
+#include "goditem.h"
+
+#include <algorithm>
+#include <sstream>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <cmath>
+
+#include "externs.h"
+
+
+bool is_holy_item(const item_def& item)
+{
+ bool retval = false;
+
+ if (is_unrandom_artefact(item))
+ {
+ unrandart_entry* entry = get_unrand_entry(item.special);
+
+ if (entry->flags & UNRAND_FLAG_HOLY)
+ return (true);
+ }
+
+ switch (item.base_type)
+ {
+ case OBJ_WEAPONS:
+ retval = (is_blessed_blade(item)
+ || get_weapon_brand(item) == SPWPN_HOLY_WRATH);
+ break;
+ case OBJ_SCROLLS:
+ retval = (item.sub_type == SCR_HOLY_WORD);
+ break;
+ case OBJ_BOOKS:
+ retval = is_holy_spellbook(item);
+ break;
+ case OBJ_STAVES:
+ retval = is_holy_rod(item);
+ break;
+ default:
+ break;
+ }
+
+ return (retval);
+}
+
+bool is_evil_item(const item_def& item)
+{
+ bool retval = false;
+
+ if (is_unrandom_artefact(item))
+ {
+ unrandart_entry* entry = get_unrand_entry(item.special);
+
+ if (entry->flags & UNRAND_FLAG_EVIL)
+ return (true);
+ }
+
+ switch (item.base_type)
+ {
+ case OBJ_WEAPONS:
+ {
+ const int item_brand = get_weapon_brand(item);
+
+ retval = (is_demonic(item)
+ || item_brand == SPWPN_DRAINING
+ || item_brand == SPWPN_PAIN
+ || item_brand == SPWPN_VAMPIRICISM
+ || item_brand == SPWPN_SHADOW);
+ }
+ break;
+ case OBJ_MISSILES:
+ {
+ const int item_brand = get_ammo_brand(item);
+ retval = is_demonic(item) || item_brand == SPMSL_SHADOW;
+ break;
+ }
+ case OBJ_WANDS:
+ retval = (item.sub_type == WAND_DRAINING);
+ break;
+ case OBJ_SCROLLS:
+ retval = (item.sub_type == SCR_SUMMONING
+ || item.sub_type == SCR_TORMENT);
+ break;
+ case OBJ_POTIONS:
+ retval = is_blood_potion(item);
+ break;
+ case OBJ_BOOKS:
+ retval = is_evil_spellbook(item);
+ break;
+ case OBJ_STAVES:
+ retval = (item.sub_type == STAFF_DEATH || is_evil_rod(item));
+ break;
+ case OBJ_MISCELLANY:
+ retval = (item.sub_type == MISC_BOTTLED_EFREET
+ || item.sub_type == MISC_LANTERN_OF_SHADOWS);
+ break;
+ default:
+ break;
+ }
+
+ return (retval);
+}
+
+bool is_chaotic_item(const item_def& item)
+{
+ bool retval = false;
+
+ if (is_unrandom_artefact(item))
+ {
+ unrandart_entry* entry = get_unrand_entry(item.special);
+
+ if (entry->flags & UNRAND_FLAG_CHAOTIC)
+ return (true);
+ }
+
+ switch (item.base_type)
+ {
+ case OBJ_WEAPONS:
+ {
+ const int item_brand = get_weapon_brand(item);
+ retval = (item_brand == SPWPN_CHAOS);
+ }
+ break;
+ case OBJ_MISSILES:
+ {
+ const int item_brand = get_ammo_brand(item);
+ retval = (item_brand == SPMSL_CHAOS);
+ }
+ break;
+ case OBJ_WANDS:
+ retval = (item.sub_type == WAND_POLYMORPH_OTHER);
+ break;
+ case OBJ_POTIONS:
+ retval = (item.sub_type == POT_MUTATION);
+ break;
+ case OBJ_BOOKS:
+ retval = is_chaotic_spellbook(item);
+ break;
+ case OBJ_STAVES:
+ retval = is_chaotic_rod(item);
+ break;
+ default:
+ break;
+ }
+
+ if (is_artefact(item) && artefact_wpn_property(item, ARTP_MUTAGENIC))
+ retval = true;
+
+ return (retval);
+}
+
+bool is_hasty_item(const item_def& item)
+{
+ switch (item.base_type)
+ {
+ case OBJ_WEAPONS:
+ {
+ const int item_brand = get_weapon_brand(item);
+ if (item_brand == SPWPN_SPEED)
+ return (true);
+ }
+ break;
+ case OBJ_ARMOUR:
+ {
+ const int item_brand = get_armour_ego_type(item);
+ if (item_brand == SPARM_RUNNING)
+ return (true);
+ }
+ break;
+ case OBJ_WANDS:
+ if (item.sub_type == WAND_HASTING)
+ return (true);
+ break;
+ case OBJ_POTIONS:
+ if (item.sub_type == POT_SPEED || item.sub_type == POT_BERSERK_RAGE)
+ return (true);
+ break;
+ case OBJ_JEWELLERY:
+ // should this include AMU_RESIST_SLOWING?
+ if (item.sub_type == AMU_RAGE)
+ return (true);
+ break;
+ default:
+ break;
+ }
+ return (false);
+}
+
+bool is_holy_discipline(int discipline)
+{
+ return (discipline & SPTYP_HOLY);
+}
+
+bool is_evil_discipline(int discipline)
+{
+ return (discipline & SPTYP_NECROMANCY);
+}
+
+bool is_holy_spell(spell_type spell, god_type god)
+{
+ UNUSED(god);
+
+ unsigned int disciplines = get_spell_disciplines(spell);
+
+ return (is_holy_discipline(disciplines));
+}
+
+bool is_evil_spell(spell_type spell, god_type god)
+{
+ UNUSED(god);
+
+ unsigned int flags = get_spell_flags(spell);
+ unsigned int disciplines = get_spell_disciplines(spell);
+
+ return ((flags & SPFLAG_UNHOLY) || (is_evil_discipline(disciplines)));
+}
+
+bool is_chaotic_spell(spell_type spell, god_type god)
+{
+ UNUSED(god);
+
+ return (spell == SPELL_POLYMORPH_OTHER
+ || spell == SPELL_ALTER_SELF
+ || spell == SPELL_SUMMON_UGLY_THING);
+}
+
+bool is_hasty_spell(spell_type spell, god_type god)
+{
+ UNUSED(god);
+
+ return (spell == SPELL_HASTE
+ || spell == SPELL_SWIFTNESS
+ || spell == SPELL_BERSERKER_RAGE);
+}
+
+// The default suitable() function for is_spellbook_type().
+bool is_any_spell(spell_type spell, god_type god)
+{
+ UNUSED(god);
+
+ return (true);
+}
+
+// If book_or_rod is false, only look at actual spellbooks. Otherwise,
+// only look at rods.
+bool is_spellbook_type(const item_def& item, bool book_or_rod,
+ bool (*suitable)(spell_type spell, god_type god),
+ god_type god)
+{
+ const bool is_spellbook = (item.base_type == OBJ_BOOKS
+ && item.sub_type != BOOK_MANUAL
+ && item.sub_type != BOOK_DESTRUCTION);
+ const bool is_rod = item_is_rod(item);
+
+ if (!is_spellbook && !is_rod)
+ return (false);
+
+ if (!book_or_rod && is_rod)
+ return (false);
+
+ int total = 0;
+ int total_liked = 0;
+
+ for (int i = 0; i < SPELLBOOK_SIZE; ++i)
+ {
+ spell_type spell = which_spell_in_book(item, i);
+ if (spell == SPELL_NO_SPELL)
+ continue;
+
+ total++;
+ if (suitable(spell, god))
+ total_liked++;
+ }
+
+ // If at least half of the available spells are suitable, the whole
+ // spellbook or rod is, too.
+ return (total_liked >= (total / 2) + 1);
+}
+
+bool is_holy_spellbook(const item_def& item)
+{
+ return (is_spellbook_type(item, false, is_holy_spell));
+}
+
+bool is_evil_spellbook(const item_def& item)
+{
+ return (is_spellbook_type(item, false, is_evil_spell));
+}
+
+bool is_chaotic_spellbook(const item_def& item)
+{
+ return (is_spellbook_type(item, false, is_chaotic_spell));
+}
+
+bool god_hates_spellbook(const item_def& item)
+{
+ return (is_spellbook_type(item, false, god_hates_spell_type));
+}
+
+bool is_holy_rod(const item_def& item)
+{
+ return (is_spellbook_type(item, true, is_holy_spell));
+}
+
+bool is_evil_rod(const item_def& item)
+{
+ return (is_spellbook_type(item, true, is_evil_spell));
+}
+
+bool is_chaotic_rod(const item_def& item)
+{
+ return (is_spellbook_type(item, true, is_chaotic_spell));
+}
+
+bool god_hates_rod(const item_def& item)
+{
+ return (is_spellbook_type(item, true, god_hates_spell_type));
+}
+
+conduct_type good_god_hates_item_handling(const item_def &item)
+{
+ if (!is_good_god(you.religion) || !is_evil_item(item))
+ return (DID_NOTHING);
+
+ if (is_demonic(item))
+ return (DID_UNHOLY);
+
+ if (item_type_known(item)
+ || item.base_type == OBJ_WEAPONS
+ && get_weapon_brand(item) == SPWPN_CHAOS)
+ {
+ return (DID_NECROMANCY);
+ }
+
+ return (DID_NOTHING);
+}
+
+conduct_type god_hates_item_handling(const item_def &item)
+{
+ switch (you.religion)
+ {
+ case GOD_ZIN:
+ if (item_type_known(item) && is_chaotic_item(item))
+ return (DID_CHAOS);
+ break;
+
+ case GOD_FEAWN:
+ if (!item_type_known(item))
+ return (DID_NOTHING);
+
+ if (is_evil_item(item)
+ || item.base_type == OBJ_WEAPONS
+ && get_weapon_brand(item) == SPWPN_CHAOS)
+ {
+ return (DID_NECROMANCY);
+ }
+ break;
+
+ case GOD_SHINING_ONE:
+ {
+ if (!item_type_known(item))
+ return (DID_NOTHING);
+
+ switch (item.base_type)
+ {
+ case OBJ_WEAPONS:
+ {
+ const int item_brand = get_weapon_brand(item);
+ if (item_brand == SPWPN_VENOM)
+ return (DID_POISON);
+ break;
+ }
+
+ case OBJ_MISSILES:
+ {
+ const int item_brand = get_ammo_brand(item);
+ if (item_brand == SPMSL_POISONED || item_brand == SPMSL_CURARE)
+ return (DID_POISON);
+ break;
+ }
+
+ case OBJ_STAVES:
+ if (item.sub_type == STAFF_POISON)
+ return (DID_POISON);
+ break;
+
+ default:
+ break;
+ }
+ break;
+ }
+
+ case GOD_YREDELEMNUL:
+ if (item_type_known(item) && is_holy_item(item))
+ return (DID_HOLY);
+ break;
+
+ case GOD_TROG:
+ if (item.base_type == OBJ_BOOKS
+ && item.sub_type != BOOK_MANUAL
+ && item.sub_type != BOOK_DESTRUCTION)
+ {
+ return (DID_SPELL_MEMORISE);
+ }
+ break;
+
+ case GOD_CHRONOS:
+ if (item_type_known(item) && is_hasty_item(item))
+ return (DID_HASTY);
+ break;
+
+ default:
+ break;
+ }
+
+ if (item_type_known(item)
+ && (god_hates_spellbook(item) || god_hates_rod(item)))
+ {
+ return (NUM_CONDUCTS); // FIXME: get the specific reason, if it
+ } // will ever be needed for spellbooks.
+
+ return (DID_NOTHING);
+}
+
+bool god_hates_spell_type(spell_type spell, god_type god)
+{
+ if (is_good_god(god) && is_evil_spell(spell))
+ return (true);
+
+ unsigned int disciplines = get_spell_disciplines(spell);
+
+ switch (god)
+ {
+ case GOD_ZIN:
+ if (is_chaotic_spell(spell))
+ return (true);
+ break;
+
+ case GOD_SHINING_ONE:
+ // TSO hates using poison, but is fine with curing it, resisting
+ // it, or destroying it.
+ if ((disciplines & SPTYP_POISON) && spell != SPELL_CURE_POISON
+ && spell != SPELL_RESIST_POISON && spell != SPELL_IGNITE_POISON)
+ {
+ return (true);
+ }
+
+ case GOD_YREDELEMNUL:
+ if (is_holy_spell(spell))
+ return (true);
+ break;
+
+ case GOD_CHRONOS:
+ if (is_hasty_spell(spell))
+ return (true);
+ break;
+
+ default:
+ break;
+ }
+
+ return (false);
+}
+
+bool god_dislikes_spell_type(spell_type spell, god_type god)
+{
+ if (god_hates_spell_type(spell, god))
+ return (true);
+
+ unsigned int flags = get_spell_flags(spell);
+ unsigned int disciplines = get_spell_disciplines(spell);
+
+ switch (god)
+ {
+ case GOD_SHINING_ONE:
+ // TSO probably wouldn't like spells which would put enemies
+ // into a state where attacking them would be unchivalrous.
+ if (spell == SPELL_CAUSE_FEAR || spell == SPELL_PARALYSE
+ || spell == SPELL_CONFUSE || spell == SPELL_MASS_CONFUSION
+ || spell == SPELL_SLEEP || spell == SPELL_MASS_SLEEP)
+ {
+ return (true);
+ }
+ break;
+
+ case GOD_XOM:
+ // Ideally, Xom would only like spells which have a random effect,
+ // are risky to use, or would otherwise amuse him, but that would
+ // be a really small number of spells.
+
+ // Xom would probably find these extra boring.
+ if (flags & (SPFLAG_HELPFUL | SPFLAG_NEUTRAL | SPFLAG_ESCAPE
+ | SPFLAG_RECOVERY | SPFLAG_MAPPING))
+ {
+ return (true);
+ }
+
+ // Things are more fun for Xom the less the player knows in
+ // advance.
+ if (disciplines & SPTYP_DIVINATION)
+ return (true);
+
+ // Holy spells are probably too useful for Xom to find them
+ // interesting.
+ if (disciplines & SPTYP_HOLY)
+ return (true);
+ break;
+
+ case GOD_ELYVILON:
+ // A peaceful god of healing wouldn't like combat spells.
+ if (disciplines & SPTYP_CONJURATION)
+ return (true);
+
+ // Also doesn't like battle spells of the non-conjuration type.
+ if (flags & SPFLAG_BATTLE)
+ return (true);
+ break;
+
+ default:
+ break;
+ }
+
+ return (false);
+}
+
+bool god_dislikes_spell_discipline(int discipline, god_type god)
+{
+ ASSERT(discipline < (1 << (SPTYP_LAST_EXPONENT + 1)));
+
+ if (is_good_god(god) && is_evil_discipline(discipline))
+ return (true);
+
+ switch (god)
+ {
+ case GOD_SHINING_ONE:
+ return (discipline & SPTYP_POISON);
+
+ case GOD_YREDELEMNUL:
+ return (discipline & SPTYP_HOLY);
+
+ case GOD_XOM:
+ return (discipline & (SPTYP_DIVINATION | SPTYP_HOLY));
+
+ case GOD_ELYVILON:
+ return (discipline & (SPTYP_CONJURATION | SPTYP_SUMMONING));
+
+ default:
+ break;
+ }
+
+ return (false);
+}
diff --git a/crawl-ref/source/goditem.h b/crawl-ref/source/goditem.h
new file mode 100644
index 0000000000..2fe6916bd5
--- /dev/null
+++ b/crawl-ref/source/goditem.h
@@ -0,0 +1,43 @@
+#ifndef GODITEM_H
+#define GODITEM_H
+
+#include "enum.h"
+#include "externs.h"
+
+#include "artefact.h"
+#include "itemname.h"
+#include "spl-book.h"
+#include "spl-cast.h"
+#include "spl-util.h"
+
+bool is_holy_item(const item_def& item);
+bool is_evil_item(const item_def& item);
+bool is_chaotic_item(const item_def& item);
+bool is_holy_discipline(int discipline);
+bool is_evil_discipline(int discipline);
+bool is_holy_spell(spell_type spell, god_type god = GOD_NO_GOD);
+bool is_evil_spell(spell_type spell, god_type god = GOD_NO_GOD);
+bool is_chaotic_spell(spell_type spell, god_type god = GOD_NO_GOD);
+bool is_hasty_spell(spell_type spell, god_type god = GOD_NO_GOD);
+bool is_any_spell(spell_type spell, god_type god = GOD_NO_GOD);
+bool is_spellbook_type(const item_def& item, bool book_or_rod,
+ bool (*suitable)(spell_type spell, god_type god) =
+ is_any_spell,
+ god_type god = you.religion);
+bool is_holy_spellbook(const item_def& item);
+bool is_evil_spellbook(const item_def& item);
+bool is_chaotic_spellbook(const item_def& item);
+bool god_hates_spellbook(const item_def& item);
+bool is_holy_rod(const item_def& item);
+bool is_evil_rod(const item_def& item);
+bool is_chaotic_rod(const item_def& item);
+bool god_hates_rod(const item_def& item);
+conduct_type good_god_hates_item_handling(const item_def &item);
+conduct_type god_hates_item_handling(const item_def &item);
+bool god_hates_spell_type(spell_type spell, god_type god = you.religion);
+
+// NOTE: As of now, these two functions only say if a god won't give a
+// spell/school when giving a gift.
+bool god_dislikes_spell_type(spell_type spell, god_type god = you.religion);
+bool god_dislikes_spell_discipline(int discipline, god_type god = you.religion);
+#endif
diff --git a/crawl-ref/source/item_use.cc b/crawl-ref/source/item_use.cc
index 5f271f4650..a1e1f49fa2 100644
--- a/crawl-ref/source/item_use.cc
+++ b/crawl-ref/source/item_use.cc
@@ -29,6 +29,7 @@
#include "effects.h"
#include "fight.h"
#include "food.h"
+#include "goditem.h"
#include "invent.h"
#include "it_use2.h"
#include "it_use3.h"
diff --git a/crawl-ref/source/itemname.cc b/crawl-ref/source/itemname.cc
index caf5b0bef2..8200182f4d 100644
--- a/crawl-ref/source/itemname.cc
+++ b/crawl-ref/source/itemname.cc
@@ -23,6 +23,7 @@
#include "artefact.h"
#include "decks.h"
#include "food.h"
+#include "goditem.h"
#include "initfile.h"
#include "invent.h"
#include "item_use.h"
@@ -33,8 +34,8 @@
#include "mon-util.h"
#include "notes.h"
#include "player.h"
-#include "quiver.h"
#include "religion.h"
+#include "quiver.h"
#include "skills2.h"
#include "spl-book.h"
#include "state.h"
diff --git a/crawl-ref/source/makefile.obj b/crawl-ref/source/makefile.obj
index 50b260debb..9c244722f3 100644
--- a/crawl-ref/source/makefile.obj
+++ b/crawl-ref/source/makefile.obj
@@ -29,6 +29,7 @@ files.o \
food.o \
format.o \
ghost.o \
+goditem.o \
hiscores.o \
initfile.o \
invent.o \
diff --git a/crawl-ref/source/mon-util.cc b/crawl-ref/source/mon-util.cc
index ae6af725e5..c775d19bd1 100644
--- a/crawl-ref/source/mon-util.cc
+++ b/crawl-ref/source/mon-util.cc
@@ -31,6 +31,7 @@
#include "dgnevent.h"
#include "fight.h"
#include "ghost.h"
+#include "goditem.h"
#include "itemname.h"
#include "itemprop.h"
#include "items.h"
diff --git a/crawl-ref/source/player.cc b/crawl-ref/source/player.cc
index 0db294e57e..31236b4ff4 100644
--- a/crawl-ref/source/player.cc
+++ b/crawl-ref/source/player.cc
@@ -29,6 +29,7 @@
#include "effects.h"
#include "fight.h"
#include "food.h"
+#include "goditem.h"
#include "itemname.h"
#include "itemprop.h"
#include "items.h"
diff --git a/crawl-ref/source/religion.cc b/crawl-ref/source/religion.cc
index bc6605166e..c8a99491ec 100644
--- a/crawl-ref/source/religion.cc
+++ b/crawl-ref/source/religion.cc
@@ -36,6 +36,7 @@
#include "fight.h"
#include "files.h"
#include "food.h"
+#include "goditem.h"
#include "hiscores.h"
#include "invent.h"
#include "it_use2.h"
@@ -66,10 +67,7 @@
#include "spells2.h"
#include "spells3.h"
#include "spells4.h"
-#include "spl-book.h"
-#include "spl-cast.h"
#include "spl-mis.h"
-#include "spl-util.h"
#include "stash.h"
#include "state.h"
#include "stuff.h"
@@ -3855,548 +3853,6 @@ void gain_piety(int pgn)
_do_god_gift(false);
}
-bool is_holy_item(const item_def& item)
-{
- bool retval = false;
-
- if (is_unrandom_artefact(item))
- {
- unrandart_entry* entry = get_unrand_entry(item.special);
-
- if (entry->flags & UNRAND_FLAG_HOLY)
- return (true);
- }
-
- switch (item.base_type)
- {
- case OBJ_WEAPONS:
- retval = (is_blessed_blade(item)
- || get_weapon_brand(item) == SPWPN_HOLY_WRATH);
- break;
- case OBJ_SCROLLS:
- retval = (item.sub_type == SCR_HOLY_WORD);
- break;
- case OBJ_BOOKS:
- retval = is_holy_spellbook(item);
- break;
- case OBJ_STAVES:
- retval = is_holy_rod(item);
- break;
- default:
- break;
- }
-
- return (retval);
-}
-
-bool is_evil_item(const item_def& item)
-{
- bool retval = false;
-
- if (is_unrandom_artefact(item))
- {
- unrandart_entry* entry = get_unrand_entry(item.special);
-
- if (entry->flags & UNRAND_FLAG_EVIL)
- return (true);
- }
-
- switch (item.base_type)
- {
- case OBJ_WEAPONS:
- {
- const int item_brand = get_weapon_brand(item);
-
- retval = (is_demonic(item)
- || item_brand == SPWPN_DRAINING
- || item_brand == SPWPN_PAIN
- || item_brand == SPWPN_VAMPIRICISM
- || item_brand == SPWPN_SHADOW);
- }
- break;
- case OBJ_MISSILES:
- {
- const int item_brand = get_ammo_brand(item);
- retval = is_demonic(item) || item_brand == SPMSL_SHADOW;
- break;
- }
- case OBJ_WANDS:
- retval = (item.sub_type == WAND_DRAINING);
- break;
- case OBJ_SCROLLS:
- retval = (item.sub_type == SCR_SUMMONING
- || item.sub_type == SCR_TORMENT);
- break;
- case OBJ_POTIONS:
- retval = is_blood_potion(item);
- break;
- case OBJ_BOOKS:
- retval = is_evil_spellbook(item);
- break;
- case OBJ_STAVES:
- retval = (item.sub_type == STAFF_DEATH || is_evil_rod(item));
- break;
- case OBJ_MISCELLANY:
- retval = (item.sub_type == MISC_BOTTLED_EFREET
- || item.sub_type == MISC_LANTERN_OF_SHADOWS);
- break;
- default:
- break;
- }
-
- return (retval);
-}
-
-bool is_chaotic_item(const item_def& item)
-{
- bool retval = false;
-
- if (is_unrandom_artefact(item))
- {
- unrandart_entry* entry = get_unrand_entry(item.special);
-
- if (entry->flags & UNRAND_FLAG_CHAOTIC)
- return (true);
- }
-
- switch (item.base_type)
- {
- case OBJ_WEAPONS:
- {
- const int item_brand = get_weapon_brand(item);
- retval = (item_brand == SPWPN_CHAOS);
- }
- break;
- case OBJ_MISSILES:
- {
- const int item_brand = get_ammo_brand(item);
- retval = (item_brand == SPMSL_CHAOS);
- }
- break;
- case OBJ_WANDS:
- retval = (item.sub_type == WAND_POLYMORPH_OTHER);
- break;
- case OBJ_POTIONS:
- retval = (item.sub_type == POT_MUTATION);
- break;
- case OBJ_BOOKS:
- retval = is_chaotic_spellbook(item);
- break;
- case OBJ_STAVES:
- retval = is_chaotic_rod(item);
- break;
- default:
- break;
- }
-
- if (is_artefact(item) && artefact_wpn_property(item, ARTP_MUTAGENIC))
- retval = true;
-
- return (retval);
-}
-
-bool is_hasty_item(const item_def& item)
-{
- switch (item.base_type)
- {
- case OBJ_WEAPONS:
- {
- const int item_brand = get_weapon_brand(item);
- if (item_brand == SPWPN_SPEED)
- return (true);
- }
- break;
- case OBJ_ARMOUR:
- {
- const int item_brand = get_armour_ego_type(item);
- if (item_brand == SPARM_RUNNING)
- return (true);
- }
- break;
- case OBJ_WANDS:
- if (item.sub_type == WAND_HASTING)
- return (true);
- break;
- case OBJ_POTIONS:
- if (item.sub_type == POT_SPEED || item.sub_type == POT_BERSERK_RAGE)
- return (true);
- break;
- case OBJ_JEWELLERY:
- // should this include AMU_RESIST_SLOWING?
- if (item.sub_type == AMU_RAGE)
- return (true);
- break;
- default:
- break;
- }
- return (false);
-}
-
-bool is_holy_discipline(int discipline)
-{
- return (discipline & SPTYP_HOLY);
-}
-
-bool is_evil_discipline(int discipline)
-{
- return (discipline & SPTYP_NECROMANCY);
-}
-
-bool is_holy_spell(spell_type spell, god_type god)
-{
- UNUSED(god);
-
- unsigned int disciplines = get_spell_disciplines(spell);
-
- return (is_holy_discipline(disciplines));
-}
-
-bool is_evil_spell(spell_type spell, god_type god)
-{
- UNUSED(god);
-
- unsigned int flags = get_spell_flags(spell);
- unsigned int disciplines = get_spell_disciplines(spell);
-
- return ((flags & SPFLAG_UNHOLY) || (is_evil_discipline(disciplines)));
-}
-
-bool is_chaotic_spell(spell_type spell, god_type god)
-{
- UNUSED(god);
-
- return (spell == SPELL_POLYMORPH_OTHER
- || spell == SPELL_ALTER_SELF
- || spell == SPELL_SUMMON_UGLY_THING);
-}
-
-bool is_hasty_spell(spell_type spell, god_type god)
-{
- UNUSED(god);
-
- return (spell == SPELL_HASTE
- || spell == SPELL_SWIFTNESS
- || spell == SPELL_BERSERKER_RAGE);
-}
-
-// The default suitable() function for is_spellbook_type().
-bool is_any_spell(spell_type spell, god_type god)
-{
- UNUSED(god);
-
- return (true);
-}
-
-// If book_or_rod is false, only look at actual spellbooks. Otherwise,
-// only look at rods.
-bool is_spellbook_type(const item_def& item, bool book_or_rod,
- bool (*suitable)(spell_type spell, god_type god),
- god_type god)
-{
- const bool is_spellbook = (item.base_type == OBJ_BOOKS
- && item.sub_type != BOOK_MANUAL
- && item.sub_type != BOOK_DESTRUCTION);
- const bool is_rod = item_is_rod(item);
-
- if (!is_spellbook && !is_rod)
- return (false);
-
- if (!book_or_rod && is_rod)
- return (false);
-
- int total = 0;
- int total_liked = 0;
-
- for (int i = 0; i < SPELLBOOK_SIZE; ++i)
- {
- spell_type spell = which_spell_in_book(item, i);
- if (spell == SPELL_NO_SPELL)
- continue;
-
- total++;
- if (suitable(spell, god))
- total_liked++;
- }
-
- // If at least half of the available spells are suitable, the whole
- // spellbook or rod is, too.
- return (total_liked >= (total / 2) + 1);
-}
-
-bool is_holy_spellbook(const item_def& item)
-{
- return (is_spellbook_type(item, false, is_holy_spell));
-}
-
-bool is_evil_spellbook(const item_def& item)
-{
- return (is_spellbook_type(item, false, is_evil_spell));
-}
-
-bool is_chaotic_spellbook(const item_def& item)
-{
- return (is_spellbook_type(item, false, is_chaotic_spell));
-}
-
-bool god_hates_spellbook(const item_def& item)
-{
- return (is_spellbook_type(item, false, god_hates_spell_type));
-}
-
-bool is_holy_rod(const item_def& item)
-{
- return (is_spellbook_type(item, true, is_holy_spell));
-}
-
-bool is_evil_rod(const item_def& item)
-{
- return (is_spellbook_type(item, true, is_evil_spell));
-}
-
-bool is_chaotic_rod(const item_def& item)
-{
- return (is_spellbook_type(item, true, is_chaotic_spell));
-}
-
-bool god_hates_rod(const item_def& item)
-{
- return (is_spellbook_type(item, true, god_hates_spell_type));
-}
-
-conduct_type good_god_hates_item_handling(const item_def &item)
-{
- if (!is_good_god(you.religion) || !is_evil_item(item))
- return (DID_NOTHING);
-
- if (is_demonic(item))
- return (DID_UNHOLY);
-
- if (item_type_known(item)
- || item.base_type == OBJ_WEAPONS
- && get_weapon_brand(item) == SPWPN_CHAOS)
- {
- return (DID_NECROMANCY);
- }
-
- return (DID_NOTHING);
-}
-
-conduct_type god_hates_item_handling(const item_def &item)
-{
- switch (you.religion)
- {
- case GOD_ZIN:
- if (item_type_known(item) && is_chaotic_item(item))
- return (DID_CHAOS);
- break;
-
- case GOD_FEAWN:
- if (!item_type_known(item))
- return (DID_NOTHING);
-
- if (is_evil_item(item)
- || item.base_type == OBJ_WEAPONS
- && get_weapon_brand(item) == SPWPN_CHAOS)
- {
- return (DID_NECROMANCY);
- }
- break;
-
- case GOD_SHINING_ONE:
- {
- if (!item_type_known(item))
- return (DID_NOTHING);
-
- switch (item.base_type)
- {
- case OBJ_WEAPONS:
- {
- const int item_brand = get_weapon_brand(item);
- if (item_brand == SPWPN_VENOM)
- return (DID_POISON);
- break;
- }
-
- case OBJ_MISSILES:
- {
- const int item_brand = get_ammo_brand(item);
- if (item_brand == SPMSL_POISONED || item_brand == SPMSL_CURARE)
- return (DID_POISON);
- break;
- }
-
- case OBJ_STAVES:
- if (item.sub_type == STAFF_POISON)
- return (DID_POISON);
- break;
-
- default:
- break;
- }
- break;
- }
-
- case GOD_YREDELEMNUL:
- if (item_type_known(item) && is_holy_item(item))
- return (DID_HOLY);
- break;
-
- case GOD_TROG:
- if (item.base_type == OBJ_BOOKS
- && item.sub_type != BOOK_MANUAL
- && item.sub_type != BOOK_DESTRUCTION)
- {
- return (DID_SPELL_MEMORISE);
- }
- break;
-
- case GOD_CHRONOS:
- if (item_type_known(item) && is_hasty_item(item))
- return (DID_HASTY);
- break;
-
- default:
- break;
- }
-
- if (item_type_known(item)
- && (god_hates_spellbook(item) || god_hates_rod(item)))
- {
- return (NUM_CONDUCTS); // FIXME: get the specific reason, if it
- } // will ever be needed for spellbooks.
-
- return (DID_NOTHING);
-}
-
-bool god_hates_spell_type(spell_type spell, god_type god)
-{
- if (is_good_god(god) && is_evil_spell(spell))
- return (true);
-
- unsigned int disciplines = get_spell_disciplines(spell);
-
- switch (god)
- {
- case GOD_ZIN:
- if (is_chaotic_spell(spell))
- return (true);
- break;
-
- case GOD_SHINING_ONE:
- // TSO hates using poison, but is fine with curing it, resisting
- // it, or destroying it.
- if ((disciplines & SPTYP_POISON) && spell != SPELL_CURE_POISON
- && spell != SPELL_RESIST_POISON && spell != SPELL_IGNITE_POISON)
- {
- return (true);
- }
-
- case GOD_YREDELEMNUL:
- if (is_holy_spell(spell))
- return (true);
- break;
-
- case GOD_CHRONOS:
- if (is_hasty_spell(spell))
- return (true);
- break;
-
- default:
- break;
- }
-
- return (false);
-}
-
-bool god_dislikes_spell_type(spell_type spell, god_type god)
-{
- if (god_hates_spell_type(spell, god))
- return (true);
-
- unsigned int flags = get_spell_flags(spell);
- unsigned int disciplines = get_spell_disciplines(spell);
-
- switch (god)
- {
- case GOD_SHINING_ONE:
- // TSO probably wouldn't like spells which would put enemies
- // into a state where attacking them would be unchivalrous.
- if (spell == SPELL_CAUSE_FEAR || spell == SPELL_PARALYSE
- || spell == SPELL_CONFUSE || spell == SPELL_MASS_CONFUSION
- || spell == SPELL_SLEEP || spell == SPELL_MASS_SLEEP)
- {
- return (true);
- }
- break;
-
- case GOD_XOM:
- // Ideally, Xom would only like spells which have a random effect,
- // are risky to use, or would otherwise amuse him, but that would
- // be a really small number of spells.
-
- // Xom would probably find these extra boring.
- if (flags & (SPFLAG_HELPFUL | SPFLAG_NEUTRAL | SPFLAG_ESCAPE
- | SPFLAG_RECOVERY | SPFLAG_MAPPING))
- {
- return (true);
- }
-
- // Things are more fun for Xom the less the player knows in
- // advance.
- if (disciplines & SPTYP_DIVINATION)
- return (true);
-
- // Holy spells are probably too useful for Xom to find them
- // interesting.
- if (disciplines & SPTYP_HOLY)
- return (true);
- break;
-
- case GOD_ELYVILON:
- // A peaceful god of healing wouldn't like combat spells.
- if (disciplines & SPTYP_CONJURATION)
- return (true);
-
- // Also doesn't like battle spells of the non-conjuration type.
- if (flags & SPFLAG_BATTLE)
- return (true);
- break;
-
- default:
- break;
- }
-
- return (false);
-}
-
-bool god_dislikes_spell_discipline(int discipline, god_type god)
-{
- ASSERT(discipline < (1 << (SPTYP_LAST_EXPONENT + 1)));
-
- if (is_good_god(god) && is_evil_discipline(discipline))
- return (true);
-
- switch (god)
- {
- case GOD_SHINING_ONE:
- return (discipline & SPTYP_POISON);
-
- case GOD_YREDELEMNUL:
- return (discipline & SPTYP_HOLY);
-
- case GOD_XOM:
- return (discipline & (SPTYP_DIVINATION | SPTYP_HOLY));
-
- case GOD_ELYVILON:
- return (discipline & (SPTYP_CONJURATION | SPTYP_SUMMONING));
-
- default:
- break;
- }
-
- return (false);
-}
-
// Is the destroyed weapon valuable enough to gain piety by doing so?
// Evil weapons are handled specially.
static bool _destroyed_valuable_weapon(int value, int type)
diff --git a/crawl-ref/source/religion.h b/crawl-ref/source/religion.h
index 3a24511bcf..5148e2203e 100644
--- a/crawl-ref/source/religion.h
+++ b/crawl-ref/source/religion.h
@@ -123,36 +123,6 @@ bool feawn_passthrough(const monsters * target);
bool feawn_protects(const monsters * target);
bool feawn_protects_species(int mc);
bool feawn_neutralises(const monsters * target);
-bool is_holy_item(const item_def& item);
-bool is_evil_item(const item_def& item);
-bool is_chaotic_item(const item_def& item);
-bool is_holy_discipline(int discipline);
-bool is_evil_discipline(int discipline);
-bool is_holy_spell(spell_type spell, god_type god = GOD_NO_GOD);
-bool is_evil_spell(spell_type spell, god_type god = GOD_NO_GOD);
-bool is_chaotic_spell(spell_type spell, god_type god = GOD_NO_GOD);
-bool is_hasty_spell(spell_type spell, god_type god = GOD_NO_GOD);
-bool is_any_spell(spell_type spell, god_type god = GOD_NO_GOD);
-bool is_spellbook_type(const item_def& item, bool book_or_rod,
- bool (*suitable)(spell_type spell, god_type god) =
- is_any_spell,
- god_type god = you.religion);
-bool is_holy_spellbook(const item_def& item);
-bool is_evil_spellbook(const item_def& item);
-bool is_chaotic_spellbook(const item_def& item);
-bool god_hates_spellbook(const item_def& item);
-bool is_holy_rod(const item_def& item);
-bool is_evil_rod(const item_def& item);
-bool is_chaotic_rod(const item_def& item);
-bool god_hates_rod(const item_def& item);
-conduct_type good_god_hates_item_handling(const item_def &item);
-conduct_type god_hates_item_handling(const item_def &item);
-bool god_hates_spell_type(spell_type spell, god_type god = you.religion);
-
-// NOTE: As of now, these two functions only say if a god won't give a
-// spell/school when giving a gift.
-bool god_dislikes_spell_type(spell_type spell, god_type god = you.religion);
-bool god_dislikes_spell_discipline(int discipline, god_type god = you.religion);
bool vehumet_supports_spell(spell_type spell);
diff --git a/crawl-ref/source/spells2.cc b/crawl-ref/source/spells2.cc
index fc06542b6a..cb322ebf92 100644
--- a/crawl-ref/source/spells2.cc
+++ b/crawl-ref/source/spells2.cc
@@ -24,6 +24,7 @@
#include "directn.h"
#include "dungeon.h"
#include "effects.h"
+#include "goditem.h"
#include "invent.h"
#include "itemname.h"
#include "itemprop.h"
diff --git a/crawl-ref/source/spells3.cc b/crawl-ref/source/spells3.cc
index a28524e9e0..e9b0e6cc40 100644
--- a/crawl-ref/source/spells3.cc
+++ b/crawl-ref/source/spells3.cc
@@ -26,6 +26,7 @@
#include "delay.h"
#include "effects.h"
#include "food.h"
+#include "goditem.h"
#include "itemname.h"
#include "itemprop.h"
#include "items.h"
diff --git a/crawl-ref/source/spl-book.cc b/crawl-ref/source/spl-book.cc
index 3a38121ff0..b37048c65e 100644
--- a/crawl-ref/source/spl-book.cc
+++ b/crawl-ref/source/spl-book.cc
@@ -26,6 +26,7 @@
#include "delay.h"
#include "food.h"
#include "format.h"
+#include "goditem.h"
#include "invent.h"
#include "itemname.h"
#include "itemprop.h"
diff --git a/crawl-ref/source/spl-cast.cc b/crawl-ref/source/spl-cast.cc
index cba831422c..4abad0c49f 100644
--- a/crawl-ref/source/spl-cast.cc
+++ b/crawl-ref/source/spl-cast.cc
@@ -18,6 +18,7 @@
#include "effects.h"
#include "food.h"
#include "format.h"
+#include "goditem.h"
#include "invent.h"
#include "it_use2.h"
#include "item_use.h"
diff --git a/crawl-ref/source/view.cc b/crawl-ref/source/view.cc
index 26c38fe43f..652abf1245 100644
--- a/crawl-ref/source/view.cc
+++ b/crawl-ref/source/view.cc
@@ -33,6 +33,7 @@
#include "dungeon.h"
#include "format.h"
#include "ghost.h"
+#include "goditem.h"
#include "itemprop.h"
#include "los.h"
#include "macro.h"
diff --git a/crawl-ref/source/xom.cc b/crawl-ref/source/xom.cc
index 949c9deac1..601461a8d8 100644
--- a/crawl-ref/source/xom.cc
+++ b/crawl-ref/source/xom.cc
@@ -14,6 +14,7 @@
#include "database.h"
#include "delay.h"
#include "effects.h"
+#include "goditem.h"
#include "it_use2.h"
#include "items.h"
#include "kills.h"