From bc63643a6c8bdc583694356f559f09b356d2c1c6 Mon Sep 17 00:00:00 2001 From: haranp Date: Mon, 9 Jul 2007 12:38:44 +0000 Subject: Minor refactoring. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@1817 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/spl-book.cc | 46 +++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 22 deletions(-) (limited to 'crawl-ref/source/spl-book.cc') diff --git a/crawl-ref/source/spl-book.cc b/crawl-ref/source/spl-book.cc index 45dafb7a78..cc570e99c7 100644 --- a/crawl-ref/source/spl-book.cc +++ b/crawl-ref/source/spl-book.cc @@ -1010,10 +1010,29 @@ static bool player_can_read_spellbook( const item_def &book ) return (true); } -unsigned char read_book( item_def &book, read_book_action_type action ) + +void mark_had_book(int booktype) { - unsigned char key2 = 0; + you.had_book[booktype] = true; + + if ( booktype == BOOK_MINOR_MAGIC_I + || booktype == BOOK_MINOR_MAGIC_II + || booktype == BOOK_MINOR_MAGIC_III) + { + you.had_book[BOOK_MINOR_MAGIC_I] = true; + you.had_book[BOOK_MINOR_MAGIC_II] = true; + you.had_book[BOOK_MINOR_MAGIC_III] = true; + } + else if (booktype == BOOK_CONJURATIONS_I + || booktype == BOOK_CONJURATIONS_II) + { + you.had_book[BOOK_CONJURATIONS_I] = true; + you.had_book[BOOK_CONJURATIONS_II] = true; + } +} +int read_book( item_def &book, read_book_action_type action ) +{ if (book.base_type == OBJ_BOOKS && !player_can_read_spellbook( book )) { mpr( "This book is beyond your current level of understanding." ); @@ -1022,27 +1041,10 @@ unsigned char read_book( item_def &book, read_book_action_type action ) } // remember that this function is called from staff spells as well: - key2 = spellbook_contents( book, action ); + const int keyin = spellbook_contents( book, action ); if (book.base_type == OBJ_BOOKS) - { - you.had_book[ book.sub_type ] = true; - - if ( book.sub_type == BOOK_MINOR_MAGIC_I - || book.sub_type == BOOK_MINOR_MAGIC_II - || book.sub_type == BOOK_MINOR_MAGIC_III) - { - you.had_book[BOOK_MINOR_MAGIC_I] = true; - you.had_book[BOOK_MINOR_MAGIC_II] = true; - you.had_book[BOOK_MINOR_MAGIC_III] = true; - } - else if (book.sub_type == BOOK_CONJURATIONS_I - || book.sub_type == BOOK_CONJURATIONS_II) - { - you.had_book[BOOK_CONJURATIONS_I] = true; - you.had_book[BOOK_CONJURATIONS_II] = true; - } - } + mark_had_book(book.sub_type); redraw_screen(); @@ -1051,7 +1053,7 @@ unsigned char read_book( item_def &book, read_book_action_type action ) set_ident_flags( book, ISFLAG_KNOW_TYPE ); - return (key2); + return (keyin); } // end read_book() // recoded to answer whether an UNDEAD_STATE is -- cgit v1.2.3-54-g00ecf