summaryrefslogtreecommitdiffstats
path: root/crawl-ref
diff options
context:
space:
mode:
authorj-p-e-g <j-p-e-g@c06c8d41-db1a-0410-9941-cceddc491573>2009-09-14 14:25:03 +0000
committerj-p-e-g <j-p-e-g@c06c8d41-db1a-0410-9941-cceddc491573>2009-09-14 14:25:03 +0000
commita58a5788137ad5c8e81286c534ade1e82840041c (patch)
tree03b9dd0f4e90dd67c0a0b9cff0b64ef60ef92c15 /crawl-ref
parentce630aeacdfb03552b7750156df37ff2a3725826 (diff)
downloadcrawl-ref-a58a5788137ad5c8e81286c534ade1e82840041c.tar.gz
crawl-ref-a58a5788137ad5c8e81286c534ade1e82840041c.zip
Fix 2858572: tiles spell memorisation crashes.
Also handles dangerous spellbooks correctly now, prompts and all. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@10675 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref')
-rw-r--r--crawl-ref/docs/tiles_creation.txt15
-rw-r--r--crawl-ref/source/describe.cc2
-rw-r--r--crawl-ref/source/spl-book.cc37
-rw-r--r--crawl-ref/source/spl-book.h4
-rw-r--r--crawl-ref/source/tilereg.cc10
-rw-r--r--crawl-ref/source/tilereg.h1
-rw-r--r--crawl-ref/source/tilesdl.cc4
7 files changed, 42 insertions, 31 deletions
diff --git a/crawl-ref/docs/tiles_creation.txt b/crawl-ref/docs/tiles_creation.txt
index 72df10035c..3f4a23f9c6 100644
--- a/crawl-ref/docs/tiles_creation.txt
+++ b/crawl-ref/docs/tiles_creation.txt
@@ -6,12 +6,15 @@ image editing software (such as Photoshop or the GIMP) as well as some basic
knowledge of how to use it. While the fancier functions can occasionally come
in useful, simply drawing and erasing of pixels will usually suffice.
-You may want to download the latest source or even the trunk version. The
-source/rltiles/ directory contains all tiles used in the game, and some more
-that are currently unused. While you can create new tiles without having access
-to existing ones, it can be useful to have them around for comparison. Also,
-you'll probably want to compile them into the game to test your creations.
-(You don't have to, though.) For compiling the game, see INSTALL.txt.
+You may want to download the latest source or even the trunk version. Either
+way, the source/rltiles/ directory contains all tiles used in the game, and
+some more that are currently unused. While you can create new tiles without
+having access to existing ones, it can be useful to have them around for
+comparison. Also, you'll probably want to compile them into the game to test
+your creations. (You don't have to, though.) For compiling the game, see
+INSTALL.txt.
+If you're going to change anything in the main code you'll probably want to
+create a patch. See docs/patch_guide.txt for help with that.
Crawl's tiles are png files in a format of 32x32 pixels. Larger tiles such
as for the pandemonium demons are possible, but require additional coding and
diff --git a/crawl-ref/source/describe.cc b/crawl-ref/source/describe.cc
index fbdd17c441..df8f20edcb 100644
--- a/crawl-ref/source/describe.cc
+++ b/crawl-ref/source/describe.cc
@@ -2460,7 +2460,7 @@ void describe_spell(spell_type spelled, const item_def* item)
if (can_mem && toupper(ch) == 'M')
{
- if (!learn_spell(spelled, item, false) || !you.turn_is_over)
+ if (!learn_spell(spelled, item->sub_type, false) || !you.turn_is_over)
more();
redraw_screen();
}
diff --git a/crawl-ref/source/spl-book.cc b/crawl-ref/source/spl-book.cc
index ebcb7f6421..e204e24dfd 100644
--- a/crawl-ref/source/spl-book.cc
+++ b/crawl-ref/source/spl-book.cc
@@ -1496,7 +1496,7 @@ static bool _sort_mem_spells(spell_type a, spell_type b)
return (stricmp(spell_title(a), spell_title(b)) < 0);
}
-std::vector<spell_type> get_mem_spell_list()
+std::vector<spell_type> get_mem_spell_list(std::vector<int> &books)
{
std::vector<spell_type> spells;
@@ -1511,7 +1511,13 @@ std::vector<spell_type> get_mem_spell_list()
std::sort(mem_spells.begin(), mem_spells.end(), _sort_mem_spells);
for (unsigned int i = 0; i < mem_spells.size(); i++)
- spells.push_back(mem_spells[i]);
+ {
+ spell_type spell = mem_spells[i];
+ spells.push_back(spell);
+
+ spells_to_books::iterator it = book_hash.find(spell);
+ books.push_back(it->second);
+ }
return (spells);
}
@@ -1693,13 +1699,7 @@ bool learn_spell()
spells_to_books::iterator it = book_hash.find(specspell);
- item_def book;
- book.base_type = OBJ_BOOKS;
- book.sub_type = it->second;
- book.quantity = 1;
- book.flags |= ISFLAG_IDENT_MASK;
-
- return learn_spell(specspell, &book, true);
+ return learn_spell(specspell, it->second, true);
}
static bool _learn_spell_checks(spell_type specspell)
@@ -1740,15 +1740,14 @@ static bool _learn_spell_checks(spell_type specspell)
return (true);
}
-bool learn_spell(spell_type specspell, const item_def *book,
- bool is_safest_book)
+bool learn_spell(spell_type specspell, int book, bool is_safest_book)
{
if (!_learn_spell_checks(specspell))
return (false);
int chance = spell_fail(specspell);
- if (chance > 0 && book && is_dangerous_spellbook(*book))
+ if (chance > 0 && is_dangerous_spellbook(book))
{
std::string prompt;
@@ -1757,10 +1756,16 @@ bool learn_spell(spell_type specspell, const item_def *book,
else
prompt = "The spellbook you are reading from ";
+ item_def fakebook;
+ fakebook.base_type = OBJ_BOOKS;
+ fakebook.sub_type = book;
+ fakebook.quantity = 1;
+ fakebook.flags |= ISFLAG_IDENT_MASK;
+
prompt += make_stringf("is %s, a dangerous spellbook which will "
"strike back at you if your memorisation "
"attempt fails. Attempt to memorise anyway?",
- book->name(DESC_NOCAP_THE).c_str());
+ fakebook.name(DESC_NOCAP_THE).c_str());
if (!yesno(prompt.c_str(), false, 'n'))
{
@@ -1811,21 +1816,21 @@ bool learn_spell(spell_type specspell, const item_def *book,
mpr("You fail to memorise the spell.");
you.turn_is_over = true;
- if (book->sub_type == BOOK_NECRONOMICON)
+ if (book == BOOK_NECRONOMICON)
{
mpr("The pages of the Necronomicon glow with a dark malevolence...");
MiscastEffect( &you, MISC_KNOWN_MISCAST, SPTYP_NECROMANCY,
8, random2avg(88, 3),
"reading the Necronomicon" );
}
- else if (book->sub_type == BOOK_DEMONOLOGY)
+ else if (book == BOOK_DEMONOLOGY)
{
mpr("This book does not appreciate being disturbed by one of your ineptitude!");
MiscastEffect( &you, MISC_KNOWN_MISCAST, SPTYP_SUMMONING,
7, random2avg(88, 3),
"reading the book of Demonology" );
}
- else if (book->sub_type == BOOK_ANNIHILATIONS)
+ else if (book == BOOK_ANNIHILATIONS)
{
mpr("This book does not appreciate being disturbed by one of your ineptitude!");
MiscastEffect( &you, MISC_KNOWN_MISCAST, SPTYP_CONJURATION,
diff --git a/crawl-ref/source/spl-book.h b/crawl-ref/source/spl-book.h
index c9fea05191..b73b890baf 100644
--- a/crawl-ref/source/spl-book.h
+++ b/crawl-ref/source/spl-book.h
@@ -51,7 +51,7 @@ int read_book( item_def &item, read_book_action_type action );
bool player_can_memorise(const item_def &book);
bool can_learn_spell(bool silent = false);
bool learn_spell();
-bool learn_spell(spell_type spell, const item_def *book = NULL,
+bool learn_spell(spell_type spell, int book = NUM_BOOKS,
bool is_safest_book = true);
bool player_can_read_spellbook( const item_def &book );
@@ -65,7 +65,7 @@ bool is_memorised(spell_type spell);
bool you_cannot_memorise(spell_type spell);
bool has_spells_to_memorise(bool silent = true);
-std::vector<spell_type> get_mem_spell_list();
+std::vector<spell_type> get_mem_spell_list(std::vector<int> &books);
int spellbook_contents( item_def &book, read_book_action_type action,
formatted_string *fs = NULL );
diff --git a/crawl-ref/source/tilereg.cc b/crawl-ref/source/tilereg.cc
index 608f174b13..b5892abc37 100644
--- a/crawl-ref/source/tilereg.cc
+++ b/crawl-ref/source/tilereg.cc
@@ -1789,7 +1789,7 @@ void InventoryRegion::pack_buffers()
add_quad_char('0' + c1, x, y, offset_x, offset_y);
}
- if (item.special)
+ if (Options.tile_display == TDSP_INVENT && item.special)
m_buf_main.add(item.special, x, y, 0, 0, false);
if (item.flag & TILEI_FLAG_TRIED)
@@ -1831,9 +1831,9 @@ void InventoryRegion::place_cursor(const coord_def &cursor)
m_dirty = true;
}
-static int _handle_spells_mouse(MouseEvent &event, int idx, int item_idx)
+int InventoryRegion::handle_spells_mouse(MouseEvent &event, int item_idx)
{
- const spell_type spell = (spell_type) idx;
+ const spell_type spell = (spell_type) m_items[item_idx].idx;
if (event.button == MouseEvent::LEFT)
{
if (spell == NUM_SPELLS)
@@ -1862,7 +1862,7 @@ static int _handle_spells_mouse(MouseEvent &event, int idx, int item_idx)
{
you.last_clicked_item = item_idx;
tiles.set_need_redraw();
- if (!learn_spell(spell))
+ if (!learn_spell(spell, m_items[item_idx].special))
flush_input_buffer( FLUSH_ON_FAILURE );
// if (!can_learn_spell(true) || !has_spells_to_memorise())
@@ -1910,7 +1910,7 @@ int InventoryRegion::handle_mouse(MouseEvent &event)
int idx = m_items[item_idx].idx;
if (m_items[item_idx].key == 0 && Options.tile_display != TDSP_INVENT)
- return _handle_spells_mouse(event, idx, item_idx);
+ return handle_spells_mouse(event, item_idx);
bool on_floor = m_items[item_idx].flag & TILEI_FLAG_FLOOR;
diff --git a/crawl-ref/source/tilereg.h b/crawl-ref/source/tilereg.h
index fee0a75886..2c2bf1d88f 100644
--- a/crawl-ref/source/tilereg.h
+++ b/crawl-ref/source/tilereg.h
@@ -339,6 +339,7 @@ public:
virtual void clear();
virtual void render();
virtual void on_resize();
+ virtual int handle_spells_mouse(MouseEvent &event, int item_idx);
virtual int handle_mouse(MouseEvent &event);
void update(int num, InventoryTile *items);
diff --git a/crawl-ref/source/tilesdl.cc b/crawl-ref/source/tilesdl.cc
index 0eaedbee79..2c9f70df7d 100644
--- a/crawl-ref/source/tilesdl.cc
+++ b/crawl-ref/source/tilesdl.cc
@@ -1443,7 +1443,8 @@ void TilesFramework::update_spells()
const int my = m_region_inv->my;
const unsigned int max_spells = mx * my;
- std::vector<spell_type> spells = get_mem_spell_list();
+ std::vector<int> books;
+ std::vector<spell_type> spells = get_mem_spell_list(books);
for (unsigned int i = 0; inv.size() < max_spells && i < spells.size();
++i)
{
@@ -1452,6 +1453,7 @@ void TilesFramework::update_spells()
InventoryTile desc;
desc.tile = tileidx_spell(spell);
desc.idx = (int) spell;
+ desc.special = books[i];
desc.quantity = spell_difficulty(spell);
if (spell_difficulty(spell) > you.experience_level