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-12 19:25:13 +0000
committerj-p-e-g <j-p-e-g@c06c8d41-db1a-0410-9941-cceddc491573>2009-09-12 19:25:13 +0000
commit5324e928729d678c71ef055eea9623d16b73cb2e (patch)
tree4d11ac9ab7847185bdc3e209cc5f17f47be045fd /crawl-ref
parent1eee7e398be993bd28d97073059736779822ec2a (diff)
downloadcrawl-ref-5324e928729d678c71ef055eea9623d16b73cb2e.tar.gz
crawl-ref-5324e928729d678c71ef055eea9623d16b73cb2e.zip
Adapt Matthew's new memorisation interface for tiles, using the same
display as for spellcasting. Also force a redraw() if the player clicked on a spell. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@10661 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref')
-rw-r--r--crawl-ref/source/acr.cc6
-rw-r--r--crawl-ref/source/describe.cc2
-rw-r--r--crawl-ref/source/enum.h7
-rw-r--r--crawl-ref/source/externs.h2
-rw-r--r--crawl-ref/source/initfile.cc2
-rw-r--r--crawl-ref/source/spl-book.cc61
-rw-r--r--crawl-ref/source/spl-book.h5
-rw-r--r--crawl-ref/source/tilereg.cc85
-rw-r--r--crawl-ref/source/tilesdl.cc25
9 files changed, 151 insertions, 44 deletions
diff --git a/crawl-ref/source/acr.cc b/crawl-ref/source/acr.cc
index 7100ef161a..1cfca89f1d 100644
--- a/crawl-ref/source/acr.cc
+++ b/crawl-ref/source/acr.cc
@@ -1354,7 +1354,11 @@ void process_command( command_type cmd )
break;
case CMD_TOGGLE_SPELL_DISPLAY:
- Options.tile_display_spells = !Options.tile_display_spells;
+ if (Options.tile_display == TDSP_SPELLS)
+ Options.tile_display = TDSP_INVENT;
+ else
+ Options.tile_display = TDSP_SPELLS;
+
tiles.update_inventory();
break;
#endif
diff --git a/crawl-ref/source/describe.cc b/crawl-ref/source/describe.cc
index 4dd09e5d6d..e788a787ba 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, false) || !you.turn_is_over)
more();
redraw_screen();
}
diff --git a/crawl-ref/source/enum.h b/crawl-ref/source/enum.h
index cb650f9920..be7e2799ad 100644
--- a/crawl-ref/source/enum.h
+++ b/crawl-ref/source/enum.h
@@ -3181,6 +3181,13 @@ enum tag_pref
TAGPREF_ENEMY, // display text tags on enemy named monsters
TAGPREF_MAX
};
+
+enum tile_display_type
+{
+ TDSP_INVENT = 0,
+ TDSP_SPELLS,
+ TDSP_MEMORISE
+};
#endif
#ifdef WIZARD
diff --git a/crawl-ref/source/externs.h b/crawl-ref/source/externs.h
index 8133b12125..4b53327a4c 100644
--- a/crawl-ref/source/externs.h
+++ b/crawl-ref/source/externs.h
@@ -2230,7 +2230,7 @@ public:
int tile_key_repeat_delay;
int tile_tooltip_ms;
tag_pref tile_tag_pref;
- bool tile_display_spells;
+ tile_display_type tile_display;
#endif
typedef std::map<std::string, std::string> opt_map;
diff --git a/crawl-ref/source/initfile.cc b/crawl-ref/source/initfile.cc
index 41d3b3c024..2f7d9a504d 100644
--- a/crawl-ref/source/initfile.cc
+++ b/crawl-ref/source/initfile.cc
@@ -946,7 +946,7 @@ void game_options::reset_options()
tile_key_repeat_delay = 200;
tile_tooltip_ms = 500;
tile_tag_pref = crawl_state.arena ? TAGPREF_NAMED : TAGPREF_ENEMY;
- tile_display_spells = false;
+ tile_display = TDSP_INVENT;
#endif
// map each colour to itself as default
diff --git a/crawl-ref/source/spl-book.cc b/crawl-ref/source/spl-book.cc
index a1dec30b5a..a1c83caa89 100644
--- a/crawl-ref/source/spl-book.cc
+++ b/crawl-ref/source/spl-book.cc
@@ -1456,7 +1456,7 @@ static bool _get_mem_list(spell_list &mem_spells,
}
else if (num_low_xl > 0)
{
- mpr("You aren't experienced enough yet to memorise any of the "
+ mpr("You aren't experienced enough to memorise any of the "
"available spells.", MSGCH_PROMPT);
}
else
@@ -1477,14 +1477,32 @@ static bool _get_mem_list(spell_list &mem_spells,
bool has_spells_to_memorise()
{
- spell_list mem_spells;
+ spell_list mem_spells;
spells_to_books book_hash;
- unsigned int num_unreadable;
- unsigned int num_race;
+ unsigned int num_unreadable;
+ unsigned int num_race;
return _get_mem_list(mem_spells, book_hash, num_unreadable, num_race, true);
}
+std::vector<spell_type> get_mem_spell_list()
+{
+ std::vector<spell_type> spells;
+
+ spell_list mem_spells;
+ spells_to_books book_hash;
+ unsigned int num_unreadable;
+ unsigned int num_race;
+
+ if (!_get_mem_list(mem_spells, book_hash, num_unreadable, num_race))
+ return (spells);
+
+ for (unsigned int i = 0; i < mem_spells.size(); i++)
+ spells.push_back(mem_spells[i]);
+
+ return (spells);
+}
+
static bool _sort_mem_spells(spell_type a, spell_type b)
{
if (spell_fail(a) != spell_fail(b))
@@ -1532,16 +1550,20 @@ static spell_type _choose_mem_spell(spell_list &spells,
player_spell_levels() > 1 ? "s" : "");
if (num_unreadable > 0)
+ {
more_str += make_stringf(", <lightmagenta>%u unreadable spellbook%s"
"</lightmagenta>",
num_unreadable,
num_unreadable > 1 ? "s" : "");
+ }
if (num_race > 0)
+ {
more_str += make_stringf(", <lightred>%u spell%s unmemorizable"
"</lightred>",
num_race,
num_race > 1 ? "s" : "");
+ }
spell_menu.set_more(formatted_string::parse_string(more_str));
@@ -1620,8 +1642,10 @@ bool can_learn_spell(bool silent)
if (j == 0)
{
if (!silent)
+ {
mpr("You can't use spell magic! I'm afraid it's scrolls only "
"for now.");
+ }
return (false);
}
@@ -1672,11 +1696,10 @@ bool learn_spell()
book.quantity = 1;
book.flags |= ISFLAG_IDENT_MASK;
- return learn_spell(specspell, book, true);
+ return learn_spell(specspell, &book, true);
}
-bool learn_spell(spell_type specspell, const item_def &book,
- bool is_safest_book)
+static bool _learn_spell_checks(spell_type specspell)
{
if (!can_learn_spell())
return (false);
@@ -1711,10 +1734,20 @@ bool learn_spell(spell_type specspell, const item_def &book,
mpr("You can't memorise that many levels of magic yet!");
return (false);
}
+ return (true);
+}
+
+
+
+bool learn_spell(spell_type specspell, const item_def *book,
+ bool is_safest_book)
+{
+ if (!_learn_spell_checks(specspell))
+ return (false);
int chance = spell_fail(specspell);
- if (chance > 0 && is_dangerous_spellbook(book))
+ if (chance > 0 && book && is_dangerous_spellbook(*book))
{
std::string prompt;
@@ -1722,10 +1755,11 @@ bool learn_spell(spell_type specspell, const item_def &book,
prompt = "The only spellbook you have which contains that spell ";
else
prompt = "The spellbook you are reading from ";
+
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());
+ book->name(DESC_NOCAP_THE).c_str());
if (!yesno(prompt.c_str(), false, 'n'))
{
@@ -1756,7 +1790,8 @@ bool learn_spell(spell_type specspell, const item_def &book,
spell_title(specspell), spell_levels_required(specspell),
spell_levels_required(specspell) > 1 ? "s" : "",
player_spell_levels() - spell_levels_required(specspell));
- if ( !yesno(info, true, 'n', false) )
+
+ if (!yesno(info, true, 'n', false))
{
canned_msg( MSG_OK );
return (false);
@@ -1775,21 +1810,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->sub_type == 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->sub_type == 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->sub_type == 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 b1ba53796b..a3adf58dd1 100644
--- a/crawl-ref/source/spl-book.h
+++ b/crawl-ref/source/spl-book.h
@@ -51,8 +51,8 @@ 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,
- bool is_safest_book);
+bool learn_spell(spell_type spell, const item_def *book = NULL,
+ bool is_safest_book = true);
bool player_can_read_spellbook( const item_def &book );
@@ -65,6 +65,7 @@ bool is_memorised(spell_type spell);
bool you_cannot_memorise(spell_type spell);
bool has_spells_to_memorise();
+std::vector<spell_type> get_mem_spell_list();
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 370b8a541e..cbe24ec1b6 100644
--- a/crawl-ref/source/tilereg.cc
+++ b/crawl-ref/source/tilereg.cc
@@ -1623,7 +1623,7 @@ void InventoryRegion::render()
const coord_def max_pos(ex, ey);
std::string desc = "";
- if (Options.tile_display_spells)
+ if (Options.tile_display != TDSP_INVENT)
{
const spell_type spell = (spell_type) idx;
if (spell == NUM_SPELLS)
@@ -1633,13 +1633,24 @@ void InventoryRegion::render()
player_spell_levels());
desc = info;
}
- else
+ else if (Options.tile_display == TDSP_SPELLS)
{
snprintf(info, INFO_SIZE, "%d MP %s (%s)",
- spell_difficulty(spell), spell_title(spell),
+ spell_difficulty(spell),
+ spell_title(spell),
failure_rate_to_string(spell_fail(spell)));
desc = info;
}
+ else // if (Options.tile_display == TDSP_MEMORISE)
+ {
+ snprintf(info, INFO_SIZE, "%s (%s) %d/%d spell slot%s",
+ spell_title(spell),
+ failure_rate_to_string(spell_fail(spell)),
+ spell_levels_required(spell),
+ player_spell_levels(),
+ spell_levels_required(spell) > 1 ? "s" : "");
+ desc = info;
+ }
}
else if (floor && is_valid_item(mitm[idx]))
desc = mitm[idx].name(DESC_PLAIN);
@@ -1713,7 +1724,7 @@ void InventoryRegion::pack_buffers()
InventoryTile &item = m_items[i++];
- if (Options.tile_display_spells)
+ if (Options.tile_display != TDSP_INVENT)
{
if (item.flag & TILEI_FLAG_MELDED)
m_buf_main.add(TILE_MESH, x, y);
@@ -1740,10 +1751,10 @@ void InventoryRegion::pack_buffers()
if (item.tile)
{
- if (Options.tile_display_spells)
- m_buf_spells.add(item.tile, x, y);
- else
+ if (Options.tile_display == TDSP_INVENT)
m_buf_main.add(item.tile, x, y);
+ else
+ m_buf_spells.add(item.tile, x, y);
}
if (item.quantity != -1)
@@ -1827,12 +1838,33 @@ static int _handle_spells_mouse(MouseEvent &event, int idx, int item_idx)
{
if (spell == NUM_SPELLS)
{
- if (!learn_spell())
- flush_input_buffer( FLUSH_ON_FAILURE );
+ Options.tile_display = TDSP_MEMORISE;
+ tiles.update_inventory();
return CK_MOUSE_CMD;
}
- if (!cast_a_spell(true, spell))
- flush_input_buffer( FLUSH_ON_FAILURE );
+ if (Options.tile_display == TDSP_SPELLS)
+ {
+ you.last_clicked_item = item_idx;
+ tiles.set_need_redraw();
+ if (!cast_a_spell(true, spell))
+ flush_input_buffer( FLUSH_ON_FAILURE );
+ }
+ else if (Options.tile_display == TDSP_MEMORISE)
+ {
+ you.last_clicked_item = item_idx;
+ tiles.set_need_redraw();
+ if (!learn_spell(spell))
+ flush_input_buffer( FLUSH_ON_FAILURE );
+
+// if (!can_learn_spell(true) || !has_spells_to_memorise())
+ {
+ // Jump back to spells list. (Really, this should only happen
+ // if there aren't any other spells to memorise, but this
+ // doesn't work for some reason.)
+ Options.tile_display = TDSP_SPELLS;
+ tiles.update_inventory();
+ }
+ }
return CK_MOUSE_CMD;
}
else if (spell != NUM_SPELLS && event.button == MouseEvent::RIGHT)
@@ -1868,13 +1900,8 @@ int InventoryRegion::handle_mouse(MouseEvent &event)
int idx = m_items[item_idx].idx;
- if (m_items[item_idx].key == 0 && Options.tile_display_spells)
- {
- int key = _handle_spells_mouse(event, idx, item_idx);
- if (key != 0)
- you.last_clicked_item = item_idx;
- return (key);
- }
+ if (m_items[item_idx].key == 0 && Options.tile_display != TDSP_INVENT)
+ return _handle_spells_mouse(event, idx, item_idx);
bool on_floor = m_items[item_idx].flag & TILEI_FLAG_FLOOR;
@@ -1984,10 +2011,20 @@ static bool _can_use_item(const item_def &item, bool equipped)
void _update_spell_tip_text(std::string& tip, int flag)
{
- if (flag & TILEI_FLAG_MELDED)
- tip = "You cannot cast this spell right now.";
- else
- tip = "[L-Click] Cast (z)";
+ if (Options.tile_display == TDSP_SPELLS)
+ {
+ if (flag & TILEI_FLAG_MELDED)
+ tip = "You cannot cast this spell right now.";
+ else
+ tip = "[L-Click] Cast (z)";
+ }
+ else if (Options.tile_display == TDSP_MEMORISE)
+ {
+ if (flag & TILEI_FLAG_MELDED)
+ tip = "You don't have enough slots for this spell right now.";
+ else
+ tip = "[L-Click] Memorise (M)";
+ }
tip += "\n[R-Click] Describe (I)";
}
@@ -2008,7 +2045,7 @@ bool InventoryRegion::update_tip_text(std::string& tip)
bool display_actions = (m_items[item_idx].key == 0
&& mouse_control::current_mode() == MOUSE_MODE_COMMAND);
- if (display_actions && Options.tile_display_spells)
+ if (display_actions && Options.tile_display != TDSP_INVENT)
{
if (m_items[item_idx].idx == NUM_SPELLS)
tip = "Memorise spells (M)";
@@ -2275,7 +2312,7 @@ bool InventoryRegion::update_alt_text(std::string &alt)
}
int idx = m_items[item_idx].idx;
- if (m_items[item_idx].key == 0 && Options.tile_display_spells)
+ if (m_items[item_idx].key == 0 && Options.tile_display != TDSP_INVENT)
{
_update_spell_alt_text(alt, idx);
return (true);
diff --git a/crawl-ref/source/tilesdl.cc b/crawl-ref/source/tilesdl.cc
index b7f64cd171..5a71cb750a 100644
--- a/crawl-ref/source/tilesdl.cc
+++ b/crawl-ref/source/tilesdl.cc
@@ -1437,6 +1437,29 @@ void TilesFramework::update_spells()
{
std::vector<InventoryTile> inv;
+ if (Options.tile_display == TDSP_MEMORISE)
+ {
+ std::vector<spell_type> spells = get_mem_spell_list();
+ for (unsigned int i = 0; i < spells.size(); ++i)
+ {
+ const spell_type spell = spells[i];
+
+ InventoryTile desc;
+ desc.tile = tileidx_spell(spell);
+ desc.idx = (int) spell;
+ desc.quantity = spell_difficulty(spell);
+
+ if (spell_difficulty(spell) > you.experience_level
+ || player_spell_levels() < spell_levels_required(spell))
+ {
+ desc.flag |= TILEI_FLAG_MELDED;
+ }
+ inv.push_back(desc);
+ }
+ m_region_inv->update(inv.size(), &inv[0]);
+ return;
+ }
+
for (int i = 0; i < 52; ++i)
{
const char letter = index_to_letter(i);
@@ -1490,7 +1513,7 @@ void TilesFramework::update_inventory()
if (!Options.tile_show_items || crawl_state.arena)
return;
- if (Options.tile_display_spells)
+ if (Options.tile_display != TDSP_INVENT)
{
update_spells();
return;