diff options
Diffstat (limited to 'crawl-ref/source')
-rw-r--r-- | crawl-ref/source/effects.cc | 5 | ||||
-rw-r--r-- | crawl-ref/source/shopping.cc | 28 |
2 files changed, 25 insertions, 8 deletions
diff --git a/crawl-ref/source/effects.cc b/crawl-ref/source/effects.cc index f704f4243c..f13b2d70d1 100644 --- a/crawl-ref/source/effects.cc +++ b/crawl-ref/source/effects.cc @@ -1431,7 +1431,7 @@ static void _do_book_acquirement(item_def &book, int agent) 60, BOOK_RANDART_THEME, agent == GOD_SIF_MUNA ? 24 : 34, book.sub_type, level == -1 ? 0 : - agent == GOD_SIF_MUNA ? 3 : 1, BOOK_RANDART_LEVEL, + agent == GOD_SIF_MUNA ? 4 : 1, BOOK_RANDART_LEVEL, 0); } @@ -1481,6 +1481,9 @@ static void _do_book_acquirement(item_def &book, int agent) int w = (skill < 12) ? skill + 3 : 25 - skill; + if (w < 0) + w = 0; + // If we don't know any magic skills, make non-magic skills // more likely. if (!knows_magic && i < SK_SPELLCASTING) diff --git a/crawl-ref/source/shopping.cc b/crawl-ref/source/shopping.cc index 3df185d1b6..61c5a41ca0 100644 --- a/crawl-ref/source/shopping.cc +++ b/crawl-ref/source/shopping.cc @@ -1666,26 +1666,40 @@ unsigned int item_value( item_def item, bool ident ) valued = 150; if (item_type_known(item)) { - int rarity = 0; + double rarity = 0; if (is_random_artefact(item)) { - // Consider spellbook as rare as its rarest spell. - // NOTE: This probably undervalues a book if it contains - // lots of rare spells. + // Consider spellbook as rare as the average of its + // three rarest spells. + int rarities[SPELLBOOK_SIZE]; + int count_valid = 0; for (int i = 0; i < SPELLBOOK_SIZE; i++) { spell_type spell = which_spell_in_book(item, i); if (spell == SPELL_NO_SPELL) + { + rarities[i] = 0; continue; + } - if (rarity > spell_rarity(spell)) - rarity = spell_rarity(spell); + rarities[i] = spell_rarity(spell); + count_valid++; } + ASSERT(count_valid > 0); + + std::sort(rarities, rarities + SPELLBOOK_SIZE); + for (int i = SPELLBOOK_SIZE - 1; i >= SPELLBOOK_SIZE - 3; i--) + rarity += rarities[i]; + + if (count_valid > 3) + count_valid = 3; + + rarity /= count_valid; } else rarity = book_rarity(item.sub_type); - valued += book_rarity(item.sub_type) * 50; + valued += rarity * 50; } break; |