summaryrefslogtreecommitdiffstats
path: root/trunk/source/command.cc
diff options
context:
space:
mode:
authorpeterb12 <peterb12@c06c8d41-db1a-0410-9941-cceddc491573>2005-07-21 02:34:44 +0000
committerpeterb12 <peterb12@c06c8d41-db1a-0410-9941-cceddc491573>2005-07-21 02:34:44 +0000
commit673bdae75485d14f759af597c3c62b99601f9a43 (patch)
tree368103f29fe0ce5dcf98060d9b5faa04590085fb /trunk/source/command.cc
parent7e900be770db24b0405fd2162491c405a425873e (diff)
downloadcrawl-ref-673bdae75485d14f759af597c3c62b99601f9a43.tar.gz
crawl-ref-673bdae75485d14f759af597c3c62b99601f9a43.zip
Initial revision
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@3 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'trunk/source/command.cc')
-rw-r--r--trunk/source/command.cc515
1 files changed, 515 insertions, 0 deletions
diff --git a/trunk/source/command.cc b/trunk/source/command.cc
new file mode 100644
index 0000000000..977dbaf035
--- /dev/null
+++ b/trunk/source/command.cc
@@ -0,0 +1,515 @@
+/*
+ * File: command.cc
+ * Summary: Misc commands.
+ * Written by: Linley Henzell
+ *
+ * Change History (most recent first):
+ *
+ * <4> 10/12/99 BCR BUILD_DATE is now used in version()
+ * <3> 6/13/99 BWR New equipment listing commands
+ * <2> 5/20/99 BWR Swapping inventory letters.
+ * <1> -/--/-- LRH Created
+ */
+
+#include "AppHdr.h"
+#include "command.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+
+#include "externs.h"
+
+#include "abl-show.h"
+#include "invent.h"
+#include "itemname.h"
+#include "item_use.h"
+#include "items.h"
+#include "ouch.h"
+#include "spl-cast.h"
+#include "spl-util.h"
+#include "stuff.h"
+#include "version.h"
+#include "wpn-misc.h"
+
+static void adjust_item(void);
+static void adjust_spells(void);
+static void adjust_ability(void);
+
+void quit_game(void)
+{
+ if (yesno("Really quit?", false))
+ ouch(-9999, 0, KILLED_BY_QUITTING);
+} // end quit_game()
+
+void version(void)
+{
+ mpr( "This is Dungeon Crawl " VERSION " (Last build " BUILD_DATE ")." );
+} // end version()
+
+void adjust(void)
+{
+ mpr( "Adjust (i)tems, (s)pells, or (a)bilities?", MSGCH_PROMPT );
+
+ unsigned char keyin = tolower( get_ch() );
+
+ if (keyin == 'i')
+ adjust_item();
+ else if (keyin == 's')
+ adjust_spells();
+ else if (keyin == 'a')
+ adjust_ability();
+ else if (keyin == ESCAPE)
+ canned_msg( MSG_OK );
+ else
+ canned_msg( MSG_HUH );
+} // end adjust()
+
+static void adjust_item(void)
+{
+ int from_slot, to_slot;
+ char str_pass[ ITEMNAME_SIZE ];
+
+ if (inv_count() < 1)
+ {
+ canned_msg(MSG_NOTHING_CARRIED);
+ return;
+ }
+
+ from_slot = prompt_invent_item( "Adjust which item?", -1 );
+ if (from_slot == PROMPT_ABORT)
+ {
+ canned_msg( MSG_OK );
+ return;
+ }
+
+ in_name( from_slot, DESC_INVENTORY_EQUIP, str_pass );
+ mpr( str_pass );
+
+ to_slot = prompt_invent_item( "Adjust to which letter?", -1, false, false );
+ if (to_slot == PROMPT_ABORT)
+ {
+ canned_msg( MSG_OK );
+ return;
+ }
+
+ // swap items
+ item_def tmp = you.inv[to_slot];
+ you.inv[to_slot] = you.inv[from_slot];
+ you.inv[from_slot] = tmp;
+
+ you.inv[from_slot].link = from_slot;
+ you.inv[to_slot].link = to_slot;
+
+ for (int i = 0; i < NUM_EQUIP; i++)
+ {
+ if (you.equip[i] == from_slot)
+ you.equip[i] = to_slot;
+ else if (you.equip[i] == to_slot)
+ you.equip[i] = from_slot;
+ }
+
+ in_name( to_slot, DESC_INVENTORY_EQUIP, str_pass );
+ mpr( str_pass );
+
+ if (is_valid_item( you.inv[from_slot] ))
+ {
+ in_name( from_slot, DESC_INVENTORY_EQUIP, str_pass );
+ mpr( str_pass );
+ }
+
+ if (to_slot == you.equip[EQ_WEAPON] || from_slot == you.equip[EQ_WEAPON])
+ you.wield_change = 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:
+ mpr("Adjust which spell?", MSGCH_PROMPT);
+
+ unsigned char keyin = get_ch();
+
+ if (keyin == '?' || keyin == '*')
+ {
+ if (keyin == '*' || keyin == '?')
+ {
+ nthing = list_spells();
+ needs_redraw = true;
+ }
+
+ 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_1 = (int) 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 );
+ int 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:
+ snprintf( info, INFO_SIZE, "%c - %s", input_1, spell_title( spell ) );
+ mpr(info);
+
+ mpr( "Adjust to which letter?", MSGCH_PROMPT );
+
+ keyin = get_ch();
+
+ if (keyin == '?' || keyin == '*')
+ {
+ if (keyin == '*' || keyin == '?')
+ {
+ nthing = list_spells();
+ needs_redraw = true;
+ }
+
+ 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 = (int) 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 );
+
+ // swap references in the letter table:
+ 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)
+ snprintf( info, INFO_SIZE, "%c - %s", input_2,
+ spell_title( get_spell_by_letter(input_2) ) );
+
+ mpr(info);
+
+ // print out other spell if one was involved (now at input_1)
+ spell = get_spell_by_letter( input_1 );
+ if (spell != SPELL_NO_SPELL)
+ {
+ snprintf( info, INFO_SIZE, "%c - %s", input_1, spell_title(spell) );
+ mpr(info);
+ }
+} // end adjust_spells()
+
+static void adjust_ability(void)
+{
+ unsigned char index_1, index_2;
+ unsigned char nthing = 0;
+
+ bool needs_redraw = false;
+
+ if (!generate_abilities())
+ {
+ mpr( "You don't currently have any abilities." );
+ return;
+ }
+
+ query:
+ mpr( "Adjust which ability?", MSGCH_PROMPT );
+
+ unsigned char keyin = get_ch();
+
+ if (keyin == '?' || keyin == '*')
+ {
+ if (keyin == '*' || keyin == '?')
+ {
+ nthing = show_abilities();
+ needs_redraw = true;
+ }
+
+ 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_1 = (int) keyin;
+
+ if (!isalpha( input_1 ))
+ {
+ adjust_spells_cleanup(needs_redraw);
+ mpr("You don't have that ability.");
+ return;
+ }
+
+ index_1 = letter_to_index( input_1 );
+
+ if (you.ability_letter_table[index_1] == ABIL_NON_ABILITY)
+ {
+ adjust_spells_cleanup(needs_redraw);
+ mpr("You don't have that ability.");
+ return;
+ }
+
+ // print out targeted spell:
+ snprintf( info, INFO_SIZE, "%c - %s", input_1,
+ get_ability_name_by_index( index_1 ) );
+
+ mpr(info);
+
+ mpr( "Adjust to which letter?", MSGCH_PROMPT );
+
+ keyin = get_ch();
+
+ if (keyin == '?' || keyin == '*')
+ {
+ if (keyin == '*' || keyin == '?')
+ {
+ nthing = show_abilities();
+ needs_redraw = true;
+ }
+
+ 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 = (int) 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 );
+
+ // 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
+ snprintf( info, INFO_SIZE, "%c - %s", input_2,
+ get_ability_name_by_index( index_1 ) );
+
+ mpr(info);
+
+ if (you.ability_letter_table[index_1] != ABIL_NON_ABILITY)
+ {
+ snprintf( info, INFO_SIZE, "%c - %s", input_1,
+ get_ability_name_by_index( index_2 ) );
+ mpr(info);
+ }
+} // end adjust_ability()
+
+void list_armour(void)
+{
+ for (int i = EQ_CLOAK; i <= EQ_BODY_ARMOUR; i++)
+ {
+ int armour_id = you.equip[i];
+
+ strcpy( info,
+ (i == EQ_CLOAK) ? "Cloak " :
+ (i == EQ_HELMET) ? "Helmet " :
+ (i == EQ_GLOVES) ? "Gloves " :
+ (i == EQ_SHIELD) ? "Shield " :
+ (i == EQ_BODY_ARMOUR) ? "Armour " :
+
+ (i == EQ_BOOTS
+ && !(you.species == SP_CENTAUR || you.species == SP_NAGA))
+ ? "Boots " :
+ (i == EQ_BOOTS
+ && (you.species == SP_CENTAUR || you.species == SP_NAGA))
+ ? "Barding"
+ : "unknown" );
+
+ strcat(info, " : ");
+
+ if (armour_id != -1)
+ {
+ char str_pass[ ITEMNAME_SIZE ];
+ in_name(armour_id, DESC_INVENTORY, str_pass);
+ strcat(info, str_pass);
+ }
+ else
+ {
+ strcat(info, " none");
+ }
+
+ mpr( info, MSGCH_EQUIPMENT );
+ }
+} // end list_armour()
+
+void list_jewellery(void)
+{
+ for (int i = EQ_LEFT_RING; i <= EQ_AMULET; i++)
+ {
+ int jewellery_id = you.equip[i];
+
+ strcpy( info, (i == EQ_LEFT_RING) ? "Left ring " :
+ (i == EQ_RIGHT_RING) ? "Right ring" :
+ (i == EQ_AMULET) ? "Amulet "
+ : "unknown " );
+
+ strcat(info, " : ");
+
+ if (jewellery_id != -1)
+ {
+ char str_pass[ ITEMNAME_SIZE ];
+ in_name(jewellery_id, DESC_INVENTORY, str_pass);
+ strcat(info, str_pass);
+ }
+ else
+ {
+ strcat(info, " none");
+ }
+
+ mpr( info, MSGCH_EQUIPMENT );
+ }
+} // end list_jewellery()
+
+void list_weapons(void)
+{
+ const int weapon_id = you.equip[EQ_WEAPON];
+
+ // Output the current weapon
+ //
+ // Yes, this is already on the screen... I'm outputing it
+ // for completeness and to avoid confusion.
+ strcpy(info, "Current : ");
+
+ if (weapon_id != -1)
+ {
+ char str_pass[ ITEMNAME_SIZE ];
+ in_name( weapon_id, DESC_INVENTORY_EQUIP, str_pass );
+ strcat(info, str_pass);
+ }
+ else
+ {
+ if (you.attribute[ATTR_TRANSFORMATION] == TRAN_BLADE_HANDS)
+ strcat(info, " blade hands");
+ else
+ strcat(info, " empty hands");
+ }
+
+ mpr(info);
+
+ // Print out the swap slots
+ for (int i = 0; i <= 1; i++)
+ {
+ // We'll avoid repeating the current weapon for these slots,
+ // in order to keep things clean.
+ if (weapon_id == i)
+ continue;
+
+ strcpy(info, (i == 0) ? "Primary : " : "Secondary : ");
+
+ if (is_valid_item( you.inv[i] ))
+ {
+ char str_pass[ ITEMNAME_SIZE ];
+ in_name(i, DESC_INVENTORY_EQUIP, str_pass);
+ strcat(info, str_pass);
+ }
+ else
+ strcat(info, " none");
+
+ mpr(info); // Output slot
+ }
+
+ // Now we print out the current default fire weapon
+ strcpy(info, "Firing : ");
+
+ const int item = get_fire_item_index();
+
+ if (item == ENDOFPACK)
+ strcat(info, " nothing");
+ else
+ {
+ char str_pass[ ITEMNAME_SIZE ];
+ in_name( item, DESC_INVENTORY_EQUIP, str_pass );
+ strcat( info, str_pass );
+ }
+
+ mpr( info, MSGCH_EQUIPMENT );
+} // end list_weapons()