summaryrefslogtreecommitdiffstats
path: root/crawl-ref
diff options
context:
space:
mode:
authorj-p-e-g <j-p-e-g@c06c8d41-db1a-0410-9941-cceddc491573>2009-02-18 08:15:47 +0000
committerj-p-e-g <j-p-e-g@c06c8d41-db1a-0410-9941-cceddc491573>2009-02-18 08:15:47 +0000
commitf81ebd6b075237e35e1e736839610f585189feec (patch)
tree948315fbe438f7b6d8a918b1bf87b7ace56515d0 /crawl-ref
parent94d956b872a116e4523fc73fec1a0420c33615ee (diff)
downloadcrawl-ref-f81ebd6b075237e35e1e736839610f585189feec.tar.gz
crawl-ref-f81ebd6b075237e35e1e736839610f585189feec.zip
Book acquirement again:
* Weigh magic skills stronger to bias against manuals. * Fall through to randart (theme) books if all spells are known. * Allow spell school combinations (Conj/Fire) in naming randarts after hell lords and others. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@9122 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref')
-rw-r--r--crawl-ref/source/dat/database/randbook.txt182
-rw-r--r--crawl-ref/source/effects.cc63
-rw-r--r--crawl-ref/source/spl-book.cc45
-rw-r--r--crawl-ref/source/stuff.h6
-rw-r--r--crawl-ref/source/tutorial.cc2
5 files changed, 215 insertions, 83 deletions
diff --git a/crawl-ref/source/dat/database/randbook.txt b/crawl-ref/source/dat/database/randbook.txt
index acbef6af85..0bc397000c 100644
--- a/crawl-ref/source/dat/database/randbook.txt
+++ b/crawl-ref/source/dat/database/randbook.txt
@@ -27,6 +27,18 @@
# a keyword that is used as a prefix for "level book".
# @level@ is parsed to the word describing the spell level.
#
+# Books also may get previous "owners" (or authors) that may be the gifting
+# god (if gifted), a name depending on school(s) as defined in this file,
+# a random name, or an appropriate god (if not a god gift).
+# The school dependant names consist of uniques or spell names that have a
+# strong connection to one or more schools. Pandemonium or hell lords' names
+# may only get used if a book is "highlevel", i.e. contains at least one
+# spell of level 6 or higher.
+# If the first and second school are different the two names are tested in
+# combination, in alphabetical order. If this is not the case or nothing is
+# found (or "__NONE" == the empty string was returned) and all spells match
+# the primary school try again with only that one.
+#
# See the explanation in the main file, randname.txt, for more general
# information on randart naming.
######################################################
@@ -693,27 +705,97 @@ Gliding
%%%%
# potential previous owners of books
# __NONE is parsed to the empty string
-Conjuration owner
+# First, combinations.
+highlevel Conjuration Earth owner
+
+Dispater
+
+@Conjuration Earth owner@
+%%%%
+Conjuration Earth owner
Lee
Lehudib
+%%%%
+highlevel Conjuration Fire owner
-Iskenderun
+Asmodeus
-Erolcha
+Cerebov
-Louise
+w:5
+@Conjuration Fire owner@
+%%%%
+Conjuration Fire owner
+
+Azrael
+
+Margery
+
+__NONE
+%%%%
+highlevel Conjuration Necromancy owner
+
+Ereshkigal
+
+@Conjuration Necromancy owner@
+%%%%
+Conjuration Necromancy owner
Boris
Nergalle
-Josephine
+__NONE
+%%%%
+highlevel Conjuration Summoning owner
-Frederick
+Asmodeus
+
+Dispater
+
+w:5
+__NONE
%%%%
-high-level Conjuration owner
+highlevel Conjuration Translocation owner
+
+Lom Lobon
+
+__NONE
+%%%%
+Earth Transmutation owner
+
+Roxanne
+
+__NONE
+%%%%
+highlevel Earth Summoning owner
+
+Dispater
+
+__NONE
+%%%%
+highlevel Fire Summoning owner
+
+Asmodeus
+
+__NONE
+%%%%
+highlevel Necromancy Poison owner
+
+Gloorx Vloq
+
+__NONE
+%%%%
+Necromancy Transmutation owner
+
+Cigotuvi
+
+__NONE
+%%%%
+# Single spell schools.
+highlevel Conjuration owner
Asmodeus
@@ -728,6 +810,26 @@ Lom Lobon
w:30
@Conjuration owner@
%%%%
+Conjuration owner
+
+Lee
+
+Lehudib
+
+Iskenderun
+
+Erolcha
+
+Louise
+
+Boris
+
+Nergalle
+
+Josephine
+
+Frederick
+%%%%
Enchantment owner
Ilsuiw
@@ -738,11 +840,7 @@ Norris
__NONE
%%%%
-Summoning owner
-
-__NONE
-%%%%
-high-level Summoning owner
+highlevel Summoning owner
Asmodeus
@@ -752,15 +850,11 @@ Mnoleg
@Summoning owner@
%%%%
-Fire owner
-
-Azrael
-
-Margery
+Summoning owner
__NONE
%%%%
-high-level Fire owner
+highlevel Fire owner
Asmodeus
@@ -769,6 +863,14 @@ Cerebov
w:20
@Fire owner@
%%%%
+Fire owner
+
+Azrael
+
+Margery
+
+__NONE
+%%%%
Ice owner
w:5
@@ -784,6 +886,15 @@ Roxanne
__NONE
%%%%
+highlevel Necromancy owner
+
+Ereshkigal
+
+Gloorx Vloq
+
+w:40
+@Necromancy owner@
+%%%%
Necromancy owner
Borgnjor
@@ -800,28 +911,25 @@ Murray
Nergalle
%%%%
-high-level Necromancy owner
-
-Ereshkigal
-
-Gloorx Vloq
-
-w:40
-@Necromancy owner@
-%%%%
Divination owner
__NONE
%%%%
+highlevel Translocation owner
+
+Lom Lobon
+
+@Translocation owner@
+%%%%
Translocation owner
__NONE
%%%%
-high-level Translocation owner
+highlevel Poison owner
-Lom Lobon
+Gloorx Vloq
-@Translocation owner@
+@Poison owner@
%%%%
Poison owner
@@ -831,11 +939,12 @@ Alistair
__NONE
%%%%
-high-level Poison owner
+highlevel Earth owner
-Gloorx Vloq
+Dispater
-@Poison owner@
+w:30
+@Earth owner@
%%%%
Earth owner
@@ -847,13 +956,6 @@ Roxanne
__NONE
%%%%
-high-level Earth owner
-
-Dispater
-
-w:30
-@Earth owner@
-%%%%
Air owner
__NONE
diff --git a/crawl-ref/source/effects.cc b/crawl-ref/source/effects.cc
index 9161e0f80e..c5acfe2441 100644
--- a/crawl-ref/source/effects.cc
+++ b/crawl-ref/source/effects.cc
@@ -1322,13 +1322,13 @@ static int _spell_weight(spell_type spell)
int skill = you.skills[spell_type2skill(disc)]
* 100 / species_skills(i, you.species);
- weight += skill;
+ weight += skill + 1;
count++;
}
}
ASSERT(count > 0);
- int level = spell_difficulty(spell);
+ int level = spell_difficulty(spell) - 1;
return std::max(0, weight/count - 2*level);
}
@@ -1396,25 +1396,26 @@ static void _do_book_acquirement(item_def &book, int agent)
// Manuals are too useful for Xom, and useless when gifted from Sif Muna.
if (agent != GOD_XOM && agent != GOD_SIF_MUNA)
{
- int weights[NUM_SKILLS];
int magic_weights = 0;
int other_weights = 0;
for (int i = 0; i < NUM_SKILLS; i++)
{
if (i > SK_UNARMED_COMBAT && i < SK_SPELLCASTING)
- {
- weights[i] = 0;
continue;
- }
- weights[i] = you.skills[i]
- * 100 / species_skills(i, you.species);
+ int weight = you.skills[i] * 100 / species_skills(i, you.species);
+ // Anyone can get Spellcasting 1. Doesn't prove anything.
+ if (i == SK_SPELLCASTING && weight >= 1)
+ weight--;
+
+ // Count magic skills double to bias against manuals
+ // for magic users.
if (i >= SK_SPELLCASTING && i <= SK_POISON_MAGIC)
- magic_weights += weights[i];
+ magic_weights += 2*weight;
else
- other_weights += weights[i];
+ other_weights += weight;
}
if (x_chance_in_y(other_weights, magic_weights + other_weights))
@@ -1445,6 +1446,26 @@ static void _do_book_acquirement(item_def &book, int agent)
switch (choice)
{
+ default:
+ {
+ int total_weights = 0;
+
+ // Pick a random spellbook according to unknown spells contained.
+ int weights[MAX_NORMAL_BOOK+1];
+ for (int bk = 0; bk <= MAX_NORMAL_BOOK; bk++)
+ {
+ weights[bk] = _book_weight(bk);
+ total_weights += weights[bk];
+ }
+
+ if (total_weights > 0)
+ {
+ book.sub_type = choose_random_weighted(weights,
+ weights + ARRAYSZ(weights));
+ break;
+ }
+ // else intentional fall-through
+ }
case BOOK_RANDART_THEME:
book.sub_type = choice;
make_book_theme_randart(book, 0, 0, 7, 22, SPELL_NO_SPELL, owner);
@@ -1479,10 +1500,7 @@ static void _do_book_acquirement(item_def &book, int agent)
* 100 / species_skills(i, you.species);
int w = (skill < 12) ? skill + 3
- : 25 - skill;
-
- if (w < 0)
- w = 0;
+ : std::max(0, 25 - skill);
// If we don't know any magic skills, make non-magic skills
// more likely.
@@ -1500,25 +1518,12 @@ static void _do_book_acquirement(item_def &book, int agent)
return;
}
- int skill = choose_random_weighted(weights,
- weights + ARRAYSZ(weights));
book.sub_type = BOOK_MANUAL;
- book.plus = skill;
+ book.plus = choose_random_weighted(weights, weights + NUM_SKILLS);
// Set number of reads possible before it "crumbles to dust".
- book.plus2 = 3 + random2(15);
+ book.plus2 = 3 + random2(15);
break;
}
-
- default:
- {
- // Pick a random spellbook according to unknown spells contained.
- int weights[MAX_NORMAL_BOOK+1];
- for (int bk = 0; bk <= MAX_NORMAL_BOOK; bk++)
- weights[bk] = _book_weight(bk);
-
- book.sub_type = choose_random_weighted(weights,
- weights + ARRAYSZ(weights));
- }
}
}
diff --git a/crawl-ref/source/spl-book.cc b/crawl-ref/source/spl-book.cc
index e771b0ce31..a70637fb47 100644
--- a/crawl-ref/source/spl-book.cc
+++ b/crawl-ref/source/spl-book.cc
@@ -2446,8 +2446,9 @@ bool make_book_theme_randart(item_def &book, int disc1, int disc2,
for (int i = 0; i < SPELLBOOK_SIZE; i++)
{
spell_vec[i] = (long) chosen_spells[i];
- if (spell_difficulty(chosen_spells[i]) > highest_level)
- highest_level = spell_difficulty(chosen_spells[i]);
+ int diff = spell_difficulty(chosen_spells[i]);
+ if (diff > highest_level)
+ highest_level = diff;
if (all_spells_disc1 && is_valid_spell(chosen_spells[i])
&& !spell_typematch( chosen_spells[i], disc1 ))
@@ -2471,18 +2472,40 @@ bool make_book_theme_randart(item_def &book, int disc1, int disc2,
const bool god_gift = (god != GOD_NO_GOD);
if (god_gift && !one_chance_in(4))
owner = god_name(god, false);
- else if (all_spells_disc1
- && (god_gift && one_chance_in(3) || one_chance_in(5)))
+ else if (god_gift && one_chance_in(3) || one_chance_in(5))
{
- std::string lookup = spelltype_long_name(disc1);
- if (highest_level >= 6 + random2(3))
- owner = getRandNameString("high-level " + lookup + " owner");
+ bool highlevel = (highest_level >= 6 + random2(3));
- if (owner.empty() || owner == "__NONE")
- owner = getRandNameString(lookup + " owner");
+ if (disc1 != disc2)
+ {
+ std::string schools[2];
+ schools[0] = spelltype_long_name(disc1);
+ schools[1] = spelltype_long_name(disc2);
+ std::sort(schools, schools + 2);
+ std::string lookup = schools[0] + " " + schools[1];
+
+ if (highlevel)
+ owner = getRandNameString("highlevel " + lookup + " owner");
+
+ if (owner.empty() || owner == "__NONE")
+ owner = getRandNameString(lookup + " owner");
+
+ if (owner == "__NONE")
+ owner = "";
+ }
- if (owner == "__NONE")
- owner = "";
+ if (owner.empty() && all_spells_disc1)
+ {
+ std::string lookup = spelltype_long_name(disc1);
+ if (highlevel && disc1 == disc2)
+ owner = getRandNameString("highlevel " + lookup + " owner");
+
+ if (owner.empty() || owner == "__NONE")
+ owner = getRandNameString(lookup + " owner");
+
+ if (owner == "__NONE")
+ owner = "";
+ }
}
if (owner.empty())
diff --git a/crawl-ref/source/stuff.h b/crawl-ref/source/stuff.h
index 2a63276b7a..464fb1794d 100644
--- a/crawl-ref/source/stuff.h
+++ b/crawl-ref/source/stuff.h
@@ -233,10 +233,10 @@ int choose_random_weighted(Iterator beg, const Iterator end)
int totalweight = 0;
int count = 0, result = 0;
- while ( beg != end )
+ while (beg != end)
{
totalweight += *beg;
- if ( random2(totalweight) < *beg )
+ if (random2(totalweight) < *beg)
{
result = count;
#if DEBUG
@@ -246,7 +246,9 @@ int choose_random_weighted(Iterator beg, const Iterator end)
++count;
++beg;
}
+#if DEBUG
ASSERT(times_set > 0);
+#endif
return result;
}
diff --git a/crawl-ref/source/tutorial.cc b/crawl-ref/source/tutorial.cc
index 18326f1689..fb131a5d56 100644
--- a/crawl-ref/source/tutorial.cc
+++ b/crawl-ref/source/tutorial.cc
@@ -1634,7 +1634,7 @@ void learned_something_new(tutorial_event_type seen_what, coord_def gc)
#endif
". You can eat it by typing <w>e</w>"
#ifdef USE_TILE
- " or by clicking on it with your <w>left mouse button</w> "
+ " or by clicking on it with your <w>left mouse button</w>"
#endif
".";
break;