From 2b2a5958399c551e7643237bc6b519d299bad164 Mon Sep 17 00:00:00 2001 From: haranp Date: Fri, 29 Jun 2007 16:55:20 +0000 Subject: Implemented 1715578: pressing '!' in the Z? screen toggles between showing schools/success and hunger/power. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@1693 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/menu.cc | 29 +++++++++++++ crawl-ref/source/menu.h | 27 ++++++++++++ crawl-ref/source/spl-cast.cc | 100 +++++++++++++++++++++++++------------------ crawl-ref/source/spl-cast.h | 1 + crawl-ref/source/spl-util.cc | 40 ++++++++--------- 5 files changed, 134 insertions(+), 63 deletions(-) (limited to 'crawl-ref') diff --git a/crawl-ref/source/menu.cc b/crawl-ref/source/menu.cc index 7b78c92b1e..e4a3ea7904 100644 --- a/crawl-ref/source/menu.cc +++ b/crawl-ref/source/menu.cc @@ -1382,3 +1382,32 @@ bool formatted_scroller::process_key( int keyin ) return true; } + +int ToggleableMenu::pre_process(int key) +{ + if ( std::find(toggle_keys.begin(), toggle_keys.end(), key) != + toggle_keys.end() ) + { + // Toggle all menu entries + for ( unsigned int i = 0; i < items.size(); ++i ) + { + ToggleableMenuEntry* const p = + dynamic_cast(items[i]); + if ( p ) + p->toggle(); + } + + // Toggle title + ToggleableMenuEntry* const pt = + dynamic_cast(title); + if ( pt ) + pt->toggle(); + + // Redraw + draw_menu(); + + // Don't further process the key + return 0; + } + return key; +} diff --git a/crawl-ref/source/menu.h b/crawl-ref/source/menu.h index 834946d820..2607a02702 100644 --- a/crawl-ref/source/menu.h +++ b/crawl-ref/source/menu.h @@ -117,6 +117,20 @@ struct MenuEntry } }; +struct ToggleableMenuEntry : public MenuEntry +{ +public: + std::string alt_text; + + ToggleableMenuEntry( const std::string &txt = std::string(), + const std::string &alt_txt = std::string(), + MenuEntryLevel lev = MEL_ITEM, + int qty = 0, int hotk = 0 ) : + MenuEntry(txt, lev, qty, hotk), alt_text(alt_txt) {} + + void toggle() { text.swap(alt_text); } +}; + class MenuHighlighter { public: @@ -252,6 +266,19 @@ protected: virtual bool process_key( int keyin ); }; +// Allows toggling by specific keys. +class ToggleableMenu : public Menu +{ +public: + ToggleableMenu( int _flags = MF_MULTISELECT ) : Menu(_flags) {} + void add_toggle_key(int newkey) { toggle_keys.push_back(newkey); } +protected: + virtual int pre_process(int key); + + std::vector toggle_keys; +}; + + // Uses a sliding selector rather than hotkeyed selection. class slider_menu : public Menu { diff --git a/crawl-ref/source/spl-cast.cc b/crawl-ref/source/spl-cast.cc index 9112404f9c..7936fbaa76 100644 --- a/crawl-ref/source/spl-cast.cc +++ b/crawl-ref/source/spl-cast.cc @@ -126,7 +126,7 @@ static void surge_power(spell_type spell) } } // end surge_power() -static std::string spell_full_description(spell_type spell) +static std::string spell_base_description(spell_type spell) { std::ostringstream desc; @@ -143,18 +143,34 @@ static std::string spell_full_description(spell_type spell) { if (already) desc << '/'; - desc << spelltype_short_name(1 << i); + desc << spelltype_name(1 << i); already = true; } } const int so_far = desc.str().length(); - if ( so_far < 46 ) - desc << std::string(46 - so_far, ' '); + if ( so_far < 60 ) + desc << std::string(60 - so_far, ' '); - // spell power, fail rate, level - desc << std::setw(14) << spell_power_string(spell) - << std::setw(12) << failure_rate_to_string(spell_fail(spell)) + // spell fail rate, level + desc << std::setw(12) << failure_rate_to_string(spell_fail(spell)) + << spell_difficulty(spell); + + return desc.str(); +} + +static std::string spell_extra_description(spell_type spell) +{ + std::ostringstream desc; + + desc << std::left; + + // spell name + desc << std::setw(30) << spell_title(spell); + + // spell power, hunger level, level + desc << std::setw(30) << spell_power_string(spell) + << std::setw(12) << spell_hunger_string(spell) << spell_difficulty(spell); return desc.str(); @@ -162,13 +178,18 @@ static std::string spell_full_description(spell_type spell) char list_spells() { - Menu spell_menu(MF_SINGLESELECT | MF_ANYPRINTABLE); + ToggleableMenu spell_menu(MF_SINGLESELECT | MF_ANYPRINTABLE | + MF_ALWAYS_SHOW_MORE); spell_menu.set_title( - new MenuEntry( + new ToggleableMenuEntry( " Your Spells Type " - "Power Success Level", + " Success Level", + " Your Spells Power " + " Hunger Level", MEL_TITLE)); spell_menu.set_highlighter(NULL); + spell_menu.set_more(formatted_string("Press '!' to toggle spell view.")); + spell_menu.add_toggle_key('!'); for ( int i = 0; i < 52; ++i ) { @@ -176,8 +197,10 @@ char list_spells() const spell_type spell = get_spell_by_letter(letter); if (spell != SPELL_NO_SPELL) { - MenuEntry* me = new MenuEntry(spell_full_description(spell), - MEL_ITEM, 1, letter); + ToggleableMenuEntry* me = + new ToggleableMenuEntry(spell_base_description(spell), + spell_extra_description(spell), + MEL_ITEM, 1, letter); spell_menu.add_entry(me); } } @@ -525,12 +548,6 @@ int spell_enhancement( unsigned int typeflags ) // returns false if spell failed, and true otherwise bool cast_a_spell() { - char spc = 0; - char spc2 = 0; - int spellh = 0; - unsigned char keyin = 0; - char unthing = 0; - if (!you.spell_no) { mpr("You don't know any spells."); @@ -550,27 +567,22 @@ bool cast_a_spell() return (false); } - // first query {dlb}: + int keyin = 0; // silence stupid compilers + for (;;) { - //jmf: FIXME: change to reflect range of known spells mpr( "Cast which spell ([?*] list)? ", MSGCH_PROMPT ); keyin = get_ch(); if (keyin == '?' || keyin == '*') { - unthing = list_spells(); + keyin = list_spells(); redraw_screen(); - if (unthing == 2) - return (false); - if ( isalpha(unthing) ) - { - keyin = unthing; + if ( isalpha(keyin) ) break; - } else mesclr(); } @@ -578,23 +590,18 @@ bool cast_a_spell() { break; } - } if (keyin == ESCAPE) return (false); - spc = (int) keyin; - - if (!isalpha(spc)) + if (!isalpha(keyin)) { mpr("You don't know that spell."); return (false); } - const spell_type spell = get_spell_by_letter( spc ); - - spc2 = letter_to_index(spc); + const spell_type spell = get_spell_by_letter( keyin ); if (spell == SPELL_NO_SPELL) { @@ -632,14 +639,8 @@ bool cast_a_spell() if (!player_energy() && you.is_undead != US_UNDEAD) { - spellh = spell_hunger( spell ); - - // I wonder if a better algorithm is called for? {dlb} - spellh -= you.intel * you.skills[SK_SPELLCASTING]; - - if (spellh < 1) - spellh = 1; - else + const int spellh = spell_hunger( spell ); + if (spellh > 0) make_hungry(spellh, true); } @@ -3475,6 +3476,21 @@ const char* failure_rate_to_string( int fail ) "Perfect"; // 100% } +const char* spell_hunger_string( spell_type spell ) +{ + const int hunger = spell_hunger(spell); + if ( hunger == 0 ) + return "None"; + else if ( hunger < 25 ) + return "Minor"; + else if ( hunger < 150 ) + return "Moderate"; + else if ( hunger < 500 ) + return "Major"; + else + return "Extreme"; +} + const char* spell_power_string( spell_type spell ) { const int powercap = spell_power_cap(spell); diff --git a/crawl-ref/source/spl-cast.h b/crawl-ref/source/spl-cast.h index 6fe7b5ee13..6d7a94c7a8 100644 --- a/crawl-ref/source/spl-cast.h +++ b/crawl-ref/source/spl-cast.h @@ -52,5 +52,6 @@ bool miscast_effect( unsigned int sp_type, int mag_pow, int mag_fail, const char* failure_rate_to_string( int fail ); const char* spell_power_string( spell_type spell ); +const char* spell_hunger_string( spell_type spell ); #endif diff --git a/crawl-ref/source/spl-util.cc b/crawl-ref/source/spl-util.cc index 61988ccd19..ed62c89478 100644 --- a/crawl-ref/source/spl-util.cc +++ b/crawl-ref/source/spl-util.cc @@ -150,28 +150,26 @@ bool del_spell_from_memory_by_slot( int slot ) int spell_hunger(spell_type which_spell) { - int level = seekspell(which_spell)->level; + const int level = spell_difficulty(which_spell); - switch (level) - { - case 1: return 50; - case 2: return 95; - case 3: return 160; - case 4: return 250; - case 5: return 350; - case 6: return 550; - case 7: return 700; - case 8: return 850; - case 9: return 1000; - case 10: return 1000; - case 11: return 1100; - case 12: return 1250; - case 13: return 1380; - case 14: return 1500; - case 15: return 1600; - default: return 1600 + (20 * level); - } -} // end spell_hunger(); + const int basehunger[] = { + 50, 95, 160, 250, 350, 550, 700, 850, 1000 + }; + + int hunger; + + if ( level < 10 && level > 0 ) + hunger = basehunger[level-1]; + else + hunger = (basehunger[0] * level * level) / 4; + + hunger -= you.intel * you.skills[SK_SPELLCASTING]; + + if ( hunger < 0 ) + hunger = 0; + + return hunger; +} bool spell_needs_tracer(spell_type spell) { -- cgit v1.2.3-54-g00ecf