diff options
author | zelgadis <zelgadis@c06c8d41-db1a-0410-9941-cceddc491573> | 2008-12-02 14:09:20 +0000 |
---|---|---|
committer | zelgadis <zelgadis@c06c8d41-db1a-0410-9941-cceddc491573> | 2008-12-02 14:09:20 +0000 |
commit | 021366461aba2e0504b2722d28d2b967778b3702 (patch) | |
tree | a2d759df280b978514814dd96f2c8eac7bf7cc1b /crawl-ref/source/spl-book.cc | |
parent | 29d2d1be7e3d8ef6096100e6c51f1dde66f3a028 (diff) | |
download | crawl-ref-021366461aba2e0504b2722d28d2b967778b3702.tar.gz crawl-ref-021366461aba2e0504b2722d28d2b967778b3702.zip |
The start of randart spellbooks. Never randomly generated and only created via
the wizard command &+, since there's no logic to how the random set of spells
are selected and there's no valuation code in shopping.cc. No randart manuals
or books of destruction, since I have no clue what they'd be like.
The code allows for any book or spell to have its normal set of spells
overridden by an arbitrary/customized set of spells, but this is only used by
randart spellbooks as of now.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@7722 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/spl-book.cc')
-rw-r--r-- | crawl-ref/source/spl-book.cc | 45 |
1 files changed, 33 insertions, 12 deletions
diff --git a/crawl-ref/source/spl-book.cc b/crawl-ref/source/spl-book.cc index 1bcbbabc7a..957a5027e2 100644 --- a/crawl-ref/source/spl-book.cc +++ b/crawl-ref/source/spl-book.cc @@ -30,6 +30,7 @@ #include "it_use3.h" #include "message.h" #include "player.h" +#include "randart.h" #include "religion.h" #include "spl-cast.h" #include "spl-mis.h" @@ -686,6 +687,22 @@ static spell_type spellbook_template_array[NUMBER_SPELLBOOKS][SPELLBOOK_SIZE] = }, }; +spell_type which_spell_in_book(const item_def &book, int spl) +{ + ASSERT(book.base_type == OBJ_BOOKS || book.base_type == OBJ_STAVES); + + const CrawlHashTable &props = book.props; + if (!props.exists( SPELL_LIST_KEY )) + return which_spell_in_book(book.book_number(), spl); + + const CrawlVector &spells = props[SPELL_LIST_KEY].get_vector(); + + ASSERT( spells.get_type() == SV_LONG ); + ASSERT( spells.size() == SPELLBOOK_SIZE ); + + return static_cast<spell_type>(spells[spl].get_long()); +} + spell_type which_spell_in_book(int sbook_type, int spl) { ASSERT( sbook_type >= 0 ); @@ -703,7 +720,6 @@ int spellbook_contents( item_def &book, read_book_action_type action, bool update_screen = !fs; const int spell_levels = player_spell_levels(); - const int type = book.book_number(); bool spell_skills = false; @@ -727,7 +743,7 @@ int spellbook_contents( item_def &book, read_book_action_type action, for (j = 0; j < SPELLBOOK_SIZE; j++) { - spell_type stype = which_spell_in_book(type, j); + spell_type stype = which_spell_in_book(book, j); if (stype == SPELL_NO_SPELL) continue; @@ -936,6 +952,11 @@ int book_rarity(unsigned char which_book) } } +bool is_valid_spell_in_book( const item_def &book, int spell ) +{ + return which_spell_in_book(book, spell) != SPELL_NO_SPELL; +} + bool is_valid_spell_in_book( int splbook, int spell ) { return which_spell_in_book(splbook, spell) != SPELL_NO_SPELL; @@ -989,6 +1010,9 @@ bool player_can_read_spellbook( const item_def &book ) if (book.base_type != OBJ_BOOKS) return (true); + if (book.props.exists( SPELL_LIST_KEY )) + return (true); + if ((book.sub_type == BOOK_ANNIHILATIONS && you.religion != GOD_VEHUMET && (you.skills[SK_CONJURATIONS] < 10 @@ -1041,7 +1065,7 @@ int read_book( item_def &book, read_book_action_type action ) // Remember that this function is called from staff spells as well. const int keyin = spellbook_contents( book, action ); - if (book.base_type == OBJ_BOOKS) + if (book.base_type == OBJ_BOOKS && !book.props.exists( SPELL_LIST_KEY )) mark_had_book(book.sub_type); redraw_screen(); @@ -1150,7 +1174,7 @@ bool player_can_memorise(const item_def &book) for (int j = 0; j < SPELLBOOK_SIZE; j++) { - const spell_type stype = which_spell_in_book(book.book_number(), j); + const spell_type stype = which_spell_in_book(book, j); if (stype == SPELL_NO_SPELL) continue; @@ -1225,13 +1249,13 @@ bool learn_spell(int book) index = letter_to_index( spell ); if (index >= SPELLBOOK_SIZE - || !is_valid_spell_in_book( you.inv[book].sub_type, index )) + || !is_valid_spell_in_book( you.inv[book], index )) { canned_msg( MSG_HUH ); return (false); } - spell_type specspell = which_spell_in_book(you.inv[book].sub_type,index); + spell_type specspell = which_spell_in_book(you.inv[book], index); if (specspell == SPELL_NO_SPELL) { @@ -1373,7 +1397,7 @@ int count_staff_spells(const item_def &item, bool need_id) return (0); int nspel = 0; - while (nspel < SPELLBOOK_SIZE && is_valid_spell_in_book(type, nspel)) + while (nspel < SPELLBOOK_SIZE && is_valid_spell_in_book(item, nspel)) ++nspel; return (nspel); @@ -1468,16 +1492,13 @@ int staff_spell( int staff ) const int idx = letter_to_index( keyin ); - // converting sub_type into book index type - const int type = istaff.book_number(); - - if ((idx >= SPELLBOOK_SIZE) || !is_valid_spell_in_book(type, idx)) + if ((idx >= SPELLBOOK_SIZE) || !is_valid_spell_in_book(istaff, idx)) { canned_msg(MSG_HUH); return -1; } - const spell_type spell = which_spell_in_book( type, idx ); + const spell_type spell = which_spell_in_book( istaff, idx ); const int mana = spell_mana( spell ) * ROD_CHARGE_MULT; const int diff = spell_difficulty( spell ); |