summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/command.cc
diff options
context:
space:
mode:
authorharanp <haranp@c06c8d41-db1a-0410-9941-cceddc491573>2007-05-08 19:29:27 +0000
committerharanp <haranp@c06c8d41-db1a-0410-9941-cceddc491573>2007-05-08 19:29:27 +0000
commit4693832f9d2a2ece40217c6adadc5855645312fb (patch)
tree309aae5a3f7b1e126d01fb245bfad62933dde897 /crawl-ref/source/command.cc
parent035aa2aee09dbf78183e61745d0d243af6c01016 (diff)
downloadcrawl-ref-4693832f9d2a2ece40217c6adadc5855645312fb.tar.gz
crawl-ref-4693832f9d2a2ece40217c6adadc5855645312fb.zip
Cleaned up ability handling. It's still rather hacky, but not nearly
as bad as the old horror. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@1425 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/command.cc')
-rw-r--r--crawl-ref/source/command.cc157
1 files changed, 69 insertions, 88 deletions
diff --git a/crawl-ref/source/command.cc b/crawl-ref/source/command.cc
index 2fd4f54892..8b17d088bd 100644
--- a/crawl-ref/source/command.cc
+++ b/crawl-ref/source/command.cc
@@ -89,7 +89,7 @@ void adjust(void)
{
mpr( "Adjust (i)tems, (s)pells, or (a)bilities?", MSGCH_PROMPT );
- unsigned char keyin = tolower( get_ch() );
+ const int keyin = tolower( get_ch() );
if (keyin == 'i')
adjust_item();
@@ -295,122 +295,103 @@ static void adjust_spells(void)
static void adjust_ability(void)
{
- unsigned char index_1, index_2;
- unsigned char nthing = 0;
+ const std::vector<talent> talents = your_talents(false);
- bool needs_redraw = false;
-
- if (!generate_abilities(false))
+ if ( talents.empty() )
{
- mpr( "You don't currently have any abilities." );
+ mpr("You don't currently have any abilities.");
return;
}
- query:
- mpr( "Adjust which ability?", MSGCH_PROMPT );
+ int selected = -1;
+ while ( selected < 0 )
+ {
+ msg::streams(MSGCH_PROMPT) << "Adjust which ability? (? or * to list)"
+ << std::endl;
- unsigned char keyin = get_ch();
+ const int keyin = get_ch();
- if (keyin == '?' || keyin == '*')
- {
- if (keyin == '*' || keyin == '?')
+ if ( keyin == '?' || keyin == '*' )
{
- nthing = show_abilities();
- needs_redraw = true;
+ selected = choose_ability_menu(talents);
}
-
- if (isalpha( nthing ) || nthing == ESCAPE)
- keyin = nthing;
- else
+ else if (keyin == ESCAPE || keyin == ' ' ||
+ keyin == '\r' || keyin == '\n')
{
- mesclr( true );
- goto query;
+ canned_msg( MSG_OK );
+ return;
}
- }
+ else if ( isalpha(keyin) )
+ {
+ // try to find the hotkey
+ for (unsigned int i = 0; i < talents.size(); ++i)
+ {
+ if ( talents[i].hotkey == keyin )
+ {
+ selected = static_cast<int>(i);
+ break;
+ }
+ }
- if (keyin == ESCAPE)
- {
- adjust_spells_cleanup(needs_redraw);
- canned_msg( MSG_OK );
- return;
+ // if we can't, cancel out
+ if ( selected < 0 )
+ {
+ mpr("No such ability.");
+ return;
+ }
+ }
}
- int input_1 = keyin;
+ msg::stream << static_cast<char>(talents[selected].hotkey)
+ << " - "
+ << ability_name(talents[selected].which)
+ << std::endl;
- if (!isalpha( input_1 ))
+ const int index1 = letter_to_index(talents[selected].hotkey);
+
+ msg::streams(MSGCH_PROMPT) << "Adjust to which letter?" << std::endl;
+
+ const int keyin = get_ch();
+
+ if ( !isalpha(keyin) )
{
- adjust_spells_cleanup(needs_redraw);
- mpr("You don't have that ability.");
+ canned_msg(MSG_HUH);
return;
}
- index_1 = letter_to_index( input_1 );
-
- if (you.ability_letter_table[index_1] == ABIL_NON_ABILITY)
+ const int index2 = letter_to_index(keyin);
+ if ( index1 == index2 )
{
- adjust_spells_cleanup(needs_redraw);
- mpr("You don't have that ability.");
+ mpr("That would be singularly pointless.");
return;
}
- // print out targeted spell:
- mprf("%c - %s", input_1, get_ability_name_by_index( index_1 ) );
-
- mpr( "Adjust to which letter?", MSGCH_PROMPT );
-
- keyin = get_ch();
-
- if (keyin == '?' || keyin == '*')
+ // see if we moved something out
+ bool printed_message = false;
+ for ( unsigned int i = 0; i < talents.size(); ++i )
{
- if (keyin == '*' || keyin == '?')
+ if ( talents[i].hotkey == keyin )
{
- nthing = show_abilities();
- needs_redraw = true;
+ msg::stream << "Swapping with: "
+ << static_cast<char>(keyin) << " - "
+ << ability_name(talents[i].which)
+ << std::endl;
+ printed_message = true;
+ break;
}
-
- if (isalpha( nthing ) || nthing == ESCAPE)
- keyin = nthing;
- else
- {
- mesclr( true );
- goto query;
- }
- }
-
- if (keyin == ESCAPE)
- {
- adjust_spells_cleanup(needs_redraw);
- canned_msg( MSG_OK );
- return;
}
-
- int input_2 = keyin;
-
- if (!isalpha( input_2 ))
- {
- adjust_spells_cleanup(needs_redraw);
- mpr("What?");
- return;
- }
-
- adjust_spells_cleanup(needs_redraw);
-
- index_2 = letter_to_index( input_2 );
+
+ if (!printed_message)
+ msg::stream << "Moving to: "
+ << static_cast<char>(keyin) << " - "
+ << ability_name(talents[selected].which)
+ << std::endl;
// swap references in the letter table:
- int tmp = you.ability_letter_table[index_2];
- you.ability_letter_table[index_2] = you.ability_letter_table[index_1];
- you.ability_letter_table[index_1] = tmp;
-
- // Note: the input_2/index_1 and input_1/index_2 here is intentional.
- // This is because nothing actually moves until generate_abilities is
- // called again... fortunately that has to be done everytime because
- // that's the silly way this system currently works. -- bwr
- mprf("%c - %s", input_2, get_ability_name_by_index( index_1 ) );
-
- if (you.ability_letter_table[index_1] != ABIL_NON_ABILITY)
- mprf("%c - %s", input_1, get_ability_name_by_index( index_2 ) );
-} // end adjust_ability()
+ ability_type tmp = you.ability_letter_table[index2];
+ you.ability_letter_table[index2] = you.ability_letter_table[index1];
+ you.ability_letter_table[index1] = tmp;
+}
void list_armour()
{