summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2007-04-25 19:41:46 +0000
committerdshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2007-04-25 19:41:46 +0000
commite46965c192b6ddc04357366a2f136d6e2115bb59 (patch)
treed35217c1c5b22d20e6070865ff92fefe7d5a1cd1
parent3729bb7d83361ee5032dcc513e5740da08798be6 (diff)
downloadcrawl-ref-e46965c192b6ddc04357366a2f136d6e2115bb59.tar.gz
crawl-ref-e46965c192b6ddc04357366a2f136d6e2115bb59.zip
Allow describing rod/spellbook spells from the examine command (jarpiain).
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@1370 c06c8d41-db1a-0410-9941-cceddc491573
-rw-r--r--crawl-ref/source/describe.cc62
-rw-r--r--crawl-ref/source/externs.h5
-rw-r--r--crawl-ref/source/items.cc19
-rw-r--r--crawl-ref/source/spl-book.cc11
4 files changed, 75 insertions, 22 deletions
diff --git a/crawl-ref/source/describe.cc b/crawl-ref/source/describe.cc
index 2cc47ab016..e635114093 100644
--- a/crawl-ref/source/describe.cc
+++ b/crawl-ref/source/describe.cc
@@ -3470,25 +3470,14 @@ void describe_feature_wide(int x, int y)
getch();
}
-//---------------------------------------------------------------
-//
-// describe_item
-//
-// Describes all items in the game.
-//
-//---------------------------------------------------------------
-void describe_item( const item_def &item )
+static void show_item_description(const item_def &item)
{
clrscr();
std::string description = get_item_description( item, 1 );
print_description(description);
- if ( (item.base_type == OBJ_BOOKS && item_type_known(item)
- && item.sub_type != BOOK_DESTRUCTION
- && item.sub_type != BOOK_MANUAL)
- ||
- count_staff_spells(item, true) > 1 )
+ if (item.has_spells())
{
formatted_string fs;
item_def dup = item;
@@ -3499,10 +3488,55 @@ void describe_item( const item_def &item )
&fs );
fs.display(2, -2);
}
+}
+
+static bool describe_spells(const item_def &item)
+{
+ int c = getch();
+ if (c < 'a' || c > 'h') //jmf: was 'g', but 8=h
+ {
+ mesclr( true );
+ return (false);
+ }
+
+ const int spell_index = letter_to_index(c);
+
+ spell_type nthing =
+ which_spell_in_book(item.book_number(), spell_index);
+ if (nthing == SPELL_NO_SPELL)
+ return (false);
+
+ describe_spell( nthing );
+ return (true);
+}
+//---------------------------------------------------------------
+//
+// describe_item
+//
+// Describes all items in the game.
+//
+//---------------------------------------------------------------
+void describe_item( const item_def &item )
+{
+ for (;;)
+ {
+ show_item_description(item);
+ if (item.has_spells())
+ {
+ gotoxy(1, wherey());
+ textcolor(LIGHTGREY);
+ cprintf("Select a spell to read its description.");
+ if (!describe_spells(item))
+ return;
+ continue;
+ }
+ break;
+ }
+
if (getch() == 0)
getch();
-} // end describe_item()
+}
//---------------------------------------------------------------
diff --git a/crawl-ref/source/externs.h b/crawl-ref/source/externs.h
index 11ce96a940..69b1727d70 100644
--- a/crawl-ref/source/externs.h
+++ b/crawl-ref/source/externs.h
@@ -422,7 +422,8 @@ struct item_def
short orig_monnum;
std::string inscription;
-
+
+public:
item_def() : base_type(OBJ_UNASSIGNED), sub_type(0), plus(0), plus2(0),
special(0L), colour(0), flags(0L), quantity(0),
x(0), y(0), link(NON_ITEM), slot(0), orig_place(0),
@@ -432,6 +433,8 @@ struct item_def
std::string name(description_level_type descrip,
bool terse = false, bool ident = false) const;
+ bool has_spells() const;
+ int book_number() const;
void clear()
{
diff --git a/crawl-ref/source/items.cc b/crawl-ref/source/items.cc
index 22ef3e05d7..af953b7d15 100644
--- a/crawl-ref/source/items.cc
+++ b/crawl-ref/source/items.cc
@@ -58,6 +58,7 @@
#include "shopping.h"
#include "skills.h"
#include "spl-cast.h"
+#include "spl-book.h"
#include "stuff.h"
#include "stash.h"
#include "tutorial.h"
@@ -3144,3 +3145,21 @@ void cmd_destroy_item( void )
}
}
#endif
+
+////////////////////////////////////////////////////////////////////////
+// item_def functions.
+
+bool item_def::has_spells() const
+{
+ return ((base_type == OBJ_BOOKS && item_type_known(*this)
+ && sub_type != BOOK_DESTRUCTION
+ && sub_type != BOOK_MANUAL)
+ || count_staff_spells(*this, true) > 1);
+}
+
+int item_def::book_number() const
+{
+ return (base_type == OBJ_BOOKS? sub_type :
+ base_type == OBJ_STAVES? sub_type + 40 :
+ -1);
+}
diff --git a/crawl-ref/source/spl-book.cc b/crawl-ref/source/spl-book.cc
index 07ac68b5ac..33c201f6f2 100644
--- a/crawl-ref/source/spl-book.cc
+++ b/crawl-ref/source/spl-book.cc
@@ -693,10 +693,7 @@ unsigned char spellbook_contents( item_def &book, int action,
bool update_screen = !fs;
const int spell_levels = player_spell_levels();
-
- // special case for staves
- const int type = (book.base_type == OBJ_STAVES) ? book.sub_type + 40
- : book.sub_type;
+ const int type = book.book_number();
bool spell_skills = false;
@@ -1311,8 +1308,8 @@ int count_staff_spells(const item_def &item, bool need_id)
return (0);
const int stype = item.sub_type;
- const int type = stype + 40;
- if (stype < STAFF_SMITING || stype >= STAFF_AIR)
+ const int type = item.book_number();
+ if (stype < STAFF_SMITING || stype >= STAFF_AIR || type == -1)
return (0);
int nspel = 0;
@@ -1347,7 +1344,7 @@ int staff_spell( int staff )
int mana, diff, food, energy;
item_def& istaff(you.inv[staff]);
// converting sub_type into book index type
- const int type = istaff.sub_type + 40;
+ const int type = istaff.book_number();
// Spell staves are mostly for the benefit of non-spellcasters, so we're
// not going to involve INT or Spellcasting skills for power. -- bwr