summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJude Brown <bookofjude@users.sourceforge.net>2009-12-08 23:15:03 +1000
committerJude Brown <bookofjude@users.sourceforge.net>2009-12-08 23:16:37 +1000
commitde30595826d2800afff619d6a1dc01c0d3610950 (patch)
treed13c4ae7a49f217a6c104a02edcce1c06ee50e54
parent9840acaf22b2fc6690b3ce54c1a0f4a778d4af2f (diff)
downloadcrawl-ref-de30595826d2800afff619d6a1dc01c0d3610950.tar.gz
crawl-ref-de30595826d2800afff619d6a1dc01c0d3610950.zip
Allow vaults to create specifically themed randart books.
It is basically a simple wrapper onto spl-book.cc's make_book_theme_randart. More documentation can be found in syntax.txt.
-rw-r--r--crawl-ref/docs/develop/levels/syntax.txt34
-rw-r--r--crawl-ref/source/dungeon.cc15
-rw-r--r--crawl-ref/source/mapdef.cc97
-rw-r--r--crawl-ref/source/mapdef.h5
4 files changed, 148 insertions, 3 deletions
diff --git a/crawl-ref/docs/develop/levels/syntax.txt b/crawl-ref/docs/develop/levels/syntax.txt
index 5dd29559a8..cc6de15206 100644
--- a/crawl-ref/docs/develop/levels/syntax.txt
+++ b/crawl-ref/docs/develop/levels/syntax.txt
@@ -490,8 +490,38 @@ ITEM: (list of items, separated by comma)
Limitations: You can't specify specific pluses or number of charges.
You also can't lay down corpses, skeletons, or chunks.
- You can place multiple items on the same square by using the KITEM
- directive. See that section for more information.
+ Randart spell books
+ -------------------
+
+ You can specify random artefact spell books using:
+
+ * "any fixed theme book" will generate a book with a fixed theme
+ (set of spell schools).
+ * "any fixed level book" will generate a book with a fixed set of
+ spells around the same level.
+
+ You can further specify artefact spell books using "randbook" and any
+ combination of the following tags:
+
+ * "disc:spell_school", the first spell school that should be included
+ in the book. For example, "disc:earth" or "disc:ice".
+ * "disc2:spell_school" an optional second spell school that can be
+ included in the book. Note: specifying two spell schools doesn't
+ mean that they will both definitely be included, just that they
+ might be.
+ * "numspells:number" a number of spells to include in the book. Will
+ not always be followed.
+ * "slevels:max_levels" the total, combined level of spells to include
+ in the book. "slevels:6" will use three level two spells, two level
+ three spells, a level two and a level four spell, and so on.
+ * "spell:spell" a spell to include in the book. All of "_" will be
+ replaced with " " and will be parsed as such.
+ * "owner:name" will be used to generate the title of the book if
+ provided. For example, "owner:Roxanne" may create "Roxanne's
+ Treatise on Mountains".
+
+ NOTE: You can place multiple items on the same square by using the
+ KITEM directive. See that section for more information.
MONS: (list of monsters)
These are used to help place specific monsters at specific places
diff --git a/crawl-ref/source/dungeon.cc b/crawl-ref/source/dungeon.cc
index b13f745005..652d9370f0 100644
--- a/crawl-ref/source/dungeon.cc
+++ b/crawl-ref/source/dungeon.cc
@@ -55,6 +55,8 @@
#include "random.h"
#include "religion.h"
#include "spells3.h"
+#include "spl-book.h"
+#include "spl-util.h"
#include "state.h"
#include "stuff.h"
#include "tags.h"
@@ -4718,6 +4720,19 @@ static void _dgn_place_item_explicit(const item_spec &spec,
{
item_def &item(mitm[item_made]);
item.pos = where;
+ CrawlHashTable props = spec.props;
+
+ if (props.exists("make_book_theme_randart"))
+ {
+ make_book_theme_randart(item,
+ props["randbook_disc1"].get_short(),
+ props["randbook_disc2"].get_short(),
+ props["randbook_num_spells"].get_short(),
+ props["randbook_slevels"].get_short(),
+ spell_by_name(props["randbook_spell"].get_string()),
+ props["randbook_owner"].get_string());
+ }
+
// Remove unsuitable inscriptions such as {god gift}.
item.inscription.clear();
// And wipe item origin to remove "this is a god gift!" from there.
diff --git a/crawl-ref/source/mapdef.cc b/crawl-ref/source/mapdef.cc
index fd2b3581f4..628b3f39c6 100644
--- a/crawl-ref/source/mapdef.cc
+++ b/crawl-ref/source/mapdef.cc
@@ -39,6 +39,7 @@
#include "random.h"
#include "religion.h"
#include "spl-util.h"
+#include "spl-book.h"
#include "stuff.h"
#include "env.h"
#include "tags.h"
@@ -3869,6 +3870,102 @@ item_spec item_list::parse_single_spec(std::string s)
}
}
+ // XXX: This is nice-ish now, but could probably do with being improved.
+ if (strip_tag(s, "randbook"))
+ {
+ result.props["make_book_theme_randart"] = true;
+ // make_book_theme_randart requires the following properties:
+ // disc: <first discipline>, disc2: <optional second discipline>
+ // numspells: <total number of spells>, slevels: <maximum levels>
+ // spell: <include this spell>, owner:<name of owner>
+ // None of these are required, but if you don't intend on using any
+ // of them, use "any fixed theme book" instead.
+ short disc1 = 0;
+ short disc2 = 0;
+
+ std::string st_disc1 = strip_tag_prefix(s, "disc:");
+ if (!st_disc1.empty())
+ {
+ disc1 = school_by_name(st_disc1);
+ if (disc1 == SPTYP_NONE)
+ {
+ error = make_stringf("Bad spell school: %s", st_disc1.c_str());
+ return (result);
+ }
+ }
+
+ std::string st_disc2 = strip_tag_prefix(s, "disc2:");
+ if (!st_disc2.empty())
+ {
+ disc2 = school_by_name(st_disc2);
+ if (disc2 == SPTYP_NONE)
+ {
+ error = make_stringf("Bad spell school: %s", st_disc2.c_str());
+ return (result);
+ }
+ }
+
+ if (disc1 != 0 && disc2 != 0)
+ {
+ if (disciplines_conflict(disc1, disc2))
+ {
+ error = make_stringf("Bad combination of spell schools: %s & %s.",
+ st_disc1.c_str(), st_disc2.c_str());
+ return (result);
+ }
+ }
+
+ if (disc1 == 0 && disc2 != 0)
+ {
+ // Don't fail, just quietly swap. Any errors in disc1's syntax will
+ // have been caught above, anyway.
+ disc1 = disc2;
+ disc2 = 0;
+ }
+
+ short num_spells = strip_number_tag(s, "numspells:");
+ if (num_spells == TAG_UNFOUND)
+ num_spells = -1;
+ else if (num_spells <= 0 || num_spells > SPELLBOOK_SIZE)
+ {
+ error = make_stringf("Bad spellbook size: %d", num_spells);
+ return (result);
+ }
+
+ short slevels = strip_number_tag(s, "slevels:");
+ if (slevels == TAG_UNFOUND)
+ slevels = -1;
+ else if (slevels == 0)
+ {
+ error = make_stringf("Bad slevels: %d.", slevels);
+ return (result);
+ }
+
+ const std::string spell = replace_all_of(strip_tag_prefix(s, "spell:"),
+ "_", " ");
+ if (!spell.empty() && spell_by_name(spell) == SPELL_NO_SPELL)
+ {
+ error = make_stringf("Bad spell: %s", spell.c_str());
+ return (result);
+ }
+
+ const std::string owner = replace_all_of(strip_tag_prefix(s, "owner:"),
+ "_", " ");
+ result.props["randbook_disc1"] = disc1;
+ result.props["randbook_disc2"] = disc2;
+ result.props["randbook_num_spells"] = num_spells;
+ result.props["randbook_slevels"] = slevels;
+ result.props["randbook_spell"] = spell;
+ result.props["randbook_owner"] = owner;
+
+ result.base_type = OBJ_BOOKS;
+ // This is changed in make_book_theme_randart.
+ result.sub_type = BOOK_MINOR_MAGIC_I;
+ result.plus = -1;
+
+ return (result);
+ }
+
// Clean up after any tag brain damage.
trim_string(s);
diff --git a/crawl-ref/source/mapdef.h b/crawl-ref/source/mapdef.h
index f85ae22103..7b3f2518c1 100644
--- a/crawl-ref/source/mapdef.h
+++ b/crawl-ref/source/mapdef.h
@@ -474,10 +474,13 @@ struct item_spec
int acquirement_source;
level_id place;
+ // Specifically for storing information about randart spell books.
+ CrawlHashTable props;
+
item_spec() : genweight(10), base_type(OBJ_RANDOM), sub_type(OBJ_RANDOM),
plus(-1), plus2(-1), ego(0), allow_uniques(1), level(-1),
race(MAKE_ITEM_RANDOM_RACE), qty(0), acquirement_source(0),
- place()
+ place(), props()
{
}
};