From 2d4d6508f4d44036aa16052d7764432fe2fc06f9 Mon Sep 17 00:00:00 2001 From: j-p-e-g Date: Fri, 11 Sep 2009 21:35:05 +0000 Subject: Add a button to memorise spells to the new spell display. All this does at the moment is call learn_spell(), but I'm planning to reuse the spell display for this purpose. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@10655 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/rltiles/dc-spells.txt | 3 ++ crawl-ref/source/rltiles/spells/memorise.png | Bin 0 -> 652 bytes crawl-ref/source/spl-book.cc | 42 ++++++++++++++++++++---- crawl-ref/source/spl-book.h | 1 + crawl-ref/source/tilepick.cc | 5 +-- crawl-ref/source/tilereg.cc | 46 +++++++++++++++++++++------ crawl-ref/source/tilesdl.cc | 14 ++++++-- 7 files changed, 91 insertions(+), 20 deletions(-) create mode 100644 crawl-ref/source/rltiles/spells/memorise.png (limited to 'crawl-ref/source') diff --git a/crawl-ref/source/rltiles/dc-spells.txt b/crawl-ref/source/rltiles/dc-spells.txt index 3c1c9fc28f..161fe1f89c 100644 --- a/crawl-ref/source/rltiles/dc-spells.txt +++ b/crawl-ref/source/rltiles/dc-spells.txt @@ -175,3 +175,6 @@ unknown UNKNOWN alter_self ALTER_SELF blade_hands BLADE_HANDS polymorph_other POLYMORPH_OTHER + +%sdir spells +memorise MEMORISE diff --git a/crawl-ref/source/rltiles/spells/memorise.png b/crawl-ref/source/rltiles/spells/memorise.png new file mode 100644 index 0000000000..0850db6ad0 Binary files /dev/null and b/crawl-ref/source/rltiles/spells/memorise.png differ diff --git a/crawl-ref/source/spl-book.cc b/crawl-ref/source/spl-book.cc index 6d335f6334..a1dec30b5a 100644 --- a/crawl-ref/source/spl-book.cc +++ b/crawl-ref/source/spl-book.cc @@ -1300,7 +1300,8 @@ typedef std::map spells_to_books; static bool _get_mem_list(spell_list &mem_spells, spells_to_books &book_hash, unsigned int &num_unreadable, - unsigned int &num_race) + unsigned int &num_race, + bool just_check = false) { bool book_errors = false; unsigned int num_books = 0; @@ -1359,19 +1360,26 @@ static bool _get_mem_list(spell_list &mem_spells, if (num_books == 0) { - mpr("You aren't carrying any spellbooks.", MSGCH_PROMPT); + if (!just_check) + mpr("You aren't carrying any spellbooks.", MSGCH_PROMPT); return (false); } else if (num_unreadable == num_books) { - mpr("All of the spellbooks you're carrying are beyond your " - "current level of comprehension.", MSGCH_PROMPT); + if (!just_check) + { + mpr("All of the spellbooks you're carrying are beyond your " + "current level of comprehension.", MSGCH_PROMPT); + } return (false); } else if (book_hash.size() == 0) { - mpr("None of the spellbooks you are carrying contain any spells.", - MSGCH_PROMPT); + if (!just_check) + { + mpr("None of the spellbooks you are carrying contain any spells.", + MSGCH_PROMPT); + } return (false); } @@ -1419,13 +1427,17 @@ static bool _get_mem_list(spell_list &mem_spells, return (true); } - mpr("Your head is already too full of spells!"); + if (!just_check) + mpr("Your head is already too full of spells!"); return (false); } if (num_memable) return (true); + if (just_check) + return (false); + unsigned int total = num_known + num_race + num_low_xl + num_low_levels; if (num_known == total) @@ -1438,14 +1450,20 @@ static bool _get_mem_list(spell_list &mem_spells, "are a %s.", lowercase_string(species).c_str()); } else if (num_low_levels > 0) + { mpr("You do not have enough free spell levels to memorise any of the " "available spells.", MSGCH_PROMPT); + } else if (num_low_xl > 0) + { mpr("You aren't experienced enough yet to memorise any of the " "available spells.", MSGCH_PROMPT); + } else + { mpr("You can't memorise any new spells for an unknown reason; " "please file a bug report.", MSGCH_PROMPT); + } if (num_unreadable) { @@ -1457,6 +1475,16 @@ static bool _get_mem_list(spell_list &mem_spells, return (false); } +bool has_spells_to_memorise() +{ + spell_list mem_spells; + spells_to_books book_hash; + unsigned int num_unreadable; + unsigned int num_race; + + return _get_mem_list(mem_spells, book_hash, num_unreadable, num_race, true); +} + static bool _sort_mem_spells(spell_type a, spell_type b) { if (spell_fail(a) != spell_fail(b)) diff --git a/crawl-ref/source/spl-book.h b/crawl-ref/source/spl-book.h index 50803c3bbe..b1ba53796b 100644 --- a/crawl-ref/source/spl-book.h +++ b/crawl-ref/source/spl-book.h @@ -64,6 +64,7 @@ int staff_spell( int zap_device_2 ); bool is_memorised(spell_type spell); bool you_cannot_memorise(spell_type spell); +bool has_spells_to_memorise(); int spellbook_contents( item_def &book, read_book_action_type action, formatted_string *fs = NULL ); diff --git a/crawl-ref/source/tilepick.cc b/crawl-ref/source/tilepick.cc index b01bfb3d23..ee553a3361 100644 --- a/crawl-ref/source/tilepick.cc +++ b/crawl-ref/source/tilepick.cc @@ -2719,6 +2719,9 @@ int tileidx_spell(spell_type spell) case SPELL_DEBUGGING_RAY: return TILEG_ERROR; + case NUM_SPELLS: // XXX: Hack! + return TILEG_MEMORISE; + // Air case SPELL_SHOCK: return TILEG_SHOCK; case SPELL_SWIFTNESS: return TILEG_SWIFTNESS; @@ -2938,8 +2941,6 @@ int tileidx_spell(spell_type spell) case SPELL_DRACONIAN_BREATH: case SPELL_WATER_ELEMENTALS: case SPELL_PORKALATOR: - - case NUM_SPELLS: default: return TILE_ERROR; } diff --git a/crawl-ref/source/tilereg.cc b/crawl-ref/source/tilereg.cc index 6c29f9ac13..370b8a541e 100644 --- a/crawl-ref/source/tilereg.cc +++ b/crawl-ref/source/tilereg.cc @@ -28,6 +28,7 @@ REVISION("$Rev$"); #include "player.h" #include "religion.h" #include "spells3.h" +#include "spl-book.h" #include "spl-cast.h" #include "spl-util.h" #include "stuff.h" @@ -1625,10 +1626,20 @@ void InventoryRegion::render() if (Options.tile_display_spells) { const spell_type spell = (spell_type) idx; - snprintf(info, INFO_SIZE, "%d MP %s (%s)", - spell_difficulty(spell), spell_title(spell), - failure_rate_to_string(spell_fail(spell))); - desc = info; + if (spell == NUM_SPELLS) + { + snprintf(info, INFO_SIZE, "Memorise spells (%d spell levels " + "available)", + player_spell_levels()); + desc = info; + } + else + { + snprintf(info, INFO_SIZE, "%d MP %s (%s)", + spell_difficulty(spell), spell_title(spell), + failure_rate_to_string(spell_fail(spell))); + desc = info; + } } else if (floor && is_valid_item(mitm[idx])) desc = mitm[idx].name(DESC_PLAIN); @@ -1814,14 +1825,18 @@ static int _handle_spells_mouse(MouseEvent &event, int idx, int item_idx) const spell_type spell = (spell_type) idx; if (event.button == MouseEvent::LEFT) { - you.last_clicked_item = item_idx; + if (spell == NUM_SPELLS) + { + if (!learn_spell()) + flush_input_buffer( FLUSH_ON_FAILURE ); + return CK_MOUSE_CMD; + } if (!cast_a_spell(true, spell)) flush_input_buffer( FLUSH_ON_FAILURE ); return CK_MOUSE_CMD; } - else if (event.button == MouseEvent::RIGHT) + else if (spell != NUM_SPELLS && event.button == MouseEvent::RIGHT) { - you.last_clicked_item = item_idx; describe_spell(spell); redraw_screen(); return CK_MOUSE_CMD; @@ -1854,7 +1869,12 @@ int InventoryRegion::handle_mouse(MouseEvent &event) int idx = m_items[item_idx].idx; if (m_items[item_idx].key == 0 && Options.tile_display_spells) - return _handle_spells_mouse(event, idx, item_idx); + { + int key = _handle_spells_mouse(event, idx, item_idx); + if (key != 0) + you.last_clicked_item = item_idx; + return (key); + } bool on_floor = m_items[item_idx].flag & TILEI_FLAG_FLOOR; @@ -1990,7 +2010,10 @@ bool InventoryRegion::update_tip_text(std::string& tip) if (display_actions && Options.tile_display_spells) { - _update_spell_tip_text(tip, m_items[item_idx].flag); + if (m_items[item_idx].idx == NUM_SPELLS) + tip = "Memorise spells (M)"; + else + _update_spell_tip_text(tip, m_items[item_idx].flag); return (true); } @@ -2222,6 +2245,11 @@ void _update_spell_alt_text(std::string &alt, int idx) { const spell_type spell = (spell_type) idx; + if (spell == NUM_SPELLS) + { + alt.clear(); + return; + } describe_info inf; get_spell_desc(spell, inf); diff --git a/crawl-ref/source/tilesdl.cc b/crawl-ref/source/tilesdl.cc index aab5ad8ad2..b7f64cd171 100644 --- a/crawl-ref/source/tilesdl.cc +++ b/crawl-ref/source/tilesdl.cc @@ -11,6 +11,7 @@ REVISION("$Rev$"); #include "message.h" #include "mon-util.h" #include "player.h" +#include "spl-book.h" #include "spl-util.h" #include "state.h" #include "stuff.h" @@ -1468,10 +1469,19 @@ void TilesFramework::update_spells() while (inv.size() < max_spells) { InventoryTile desc; -// if ((int)inv.size() >= max_pack_items) -// desc.flag |= TILEI_FLAG_INVALID; inv.push_back(desc); } + + if (can_learn_spell(true) && has_spells_to_memorise()) + { + // FIXME: Add NUM_SPELLS to list of spells as placeholder for + // memorisation tile. (Hack!) + InventoryTile desc; + desc.tile = tileidx_spell(NUM_SPELLS); + desc.idx = NUM_SPELLS; + inv.push_back(desc); + } + m_region_inv->update(inv.size(), &inv[0]); } -- cgit v1.2.3-54-g00ecf