diff options
author | haranp <haranp@c06c8d41-db1a-0410-9941-cceddc491573> | 2007-07-13 12:40:50 +0000 |
---|---|---|
committer | haranp <haranp@c06c8d41-db1a-0410-9941-cceddc491573> | 2007-07-13 12:40:50 +0000 |
commit | 1b7682ecfe6bb7d7d37e73f8769a452fdc8b04d2 (patch) | |
tree | 153c6ac2a903248e5c28e39b4a6cc3928834951a /crawl-ref/source/command.cc | |
parent | 0eb7e87096f07509f3fed6a82fab696d505a2c18 (diff) | |
download | crawl-ref-1b7682ecfe6bb7d7d37e73f8769a452fdc8b04d2.tar.gz crawl-ref-1b7682ecfe6bb7d7d37e73f8769a452fdc8b04d2.zip |
General code cleanups and goto removal.
Fixed a possible crash when using Backspace to restart character selection.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@1855 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/command.cc')
-rw-r--r-- | crawl-ref/source/command.cc | 111 |
1 files changed, 29 insertions, 82 deletions
diff --git a/crawl-ref/source/command.cc b/crawl-ref/source/command.cc index cd6955ec0a..ea370ed5d3 100644 --- a/crawl-ref/source/command.cc +++ b/crawl-ref/source/command.cc @@ -167,124 +167,71 @@ static void adjust_item(void) swap_inv_slots(from_slot, to_slot, true); } // end adjust_item() -static void adjust_spells_cleanup(bool needs_redraw) -{ - if (needs_redraw) - redraw_screen(); -} - static void adjust_spells(void) { - unsigned char index_1, index_2; - unsigned char nthing = 0; - - bool needs_redraw = false; - if (!you.spell_no) { mpr("You don't know any spells."); return; } - query: + // Select starting slot mpr("Adjust which spell?", MSGCH_PROMPT); - unsigned char keyin = get_ch(); - - if (keyin == '?' || keyin == '*') + int keyin = 0; + if ( Options.auto_list ) + keyin = list_spells(); + else { - if (keyin == '*' || keyin == '?') - { - nthing = list_spells(); - needs_redraw = true; - } - - if (isalpha( nthing ) || nthing == ESCAPE) - keyin = nthing; - else - { - mesclr( true ); - goto query; - } + keyin = get_ch(); + if (keyin == '?' || keyin == '*') + keyin = list_spells(); } - - if (keyin == ESCAPE) + + if ( !isalpha(keyin) ) { - adjust_spells_cleanup(needs_redraw); canned_msg( MSG_OK ); return; } - int input_1 = keyin; - - if (!isalpha( input_1 )) - { - adjust_spells_cleanup(needs_redraw); - mpr("You don't know that spell."); - return; - } - - index_1 = letter_to_index( input_1 ); - spell_type spell = get_spell_by_letter( input_1 ); + const int input_1 = keyin; + const int index_1 = letter_to_index( input_1 ); + spell_type spell = get_spell_by_letter( input_1 ); if (spell == SPELL_NO_SPELL) { - adjust_spells_cleanup(needs_redraw); mpr("You don't know that spell."); return; } // print out targeted spell: - mprf( "%c - %s", input_1, spell_title( spell ) ); - - mpr( "Adjust to which letter?", MSGCH_PROMPT ); - - keyin = get_ch(); + mprf( "%c - %s", keyin, spell_title( spell ) ); - if (keyin == '?' || keyin == '*') + // Select target slot + keyin = 0; + while ( !isalpha(keyin) ) { - if (keyin == '*' || keyin == '?') - { - nthing = list_spells(); - needs_redraw = true; - } - - if (isalpha( nthing ) || nthing == ESCAPE) - keyin = nthing; - else + mpr( "Adjust to which letter?", MSGCH_PROMPT ); + keyin = get_ch(); + if (keyin == ESCAPE) { - mesclr( true ); - goto query; + canned_msg( MSG_OK ); + return; } + if (keyin == '?' || keyin == '*') + keyin = list_spells(); } - 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 ); + const int input_2 = keyin; + const int index_2 = letter_to_index( keyin ); // swap references in the letter table: - int tmp = you.spell_letter_table[index_2]; + const int tmp = you.spell_letter_table[index_2]; you.spell_letter_table[index_2] = you.spell_letter_table[index_1]; you.spell_letter_table[index_1] = tmp; - // print out spell in new slot (now at input_2) - mprf("%c - %s", input_2, spell_title( get_spell_by_letter(input_2) ) ); + // print out spell in new slot + mprf("%c - %s", input_2, spell_title(get_spell_by_letter(input_2))); // print out other spell if one was involved (now at input_1) spell = get_spell_by_letter( input_1 ); |