diff options
author | haranp <haranp@c06c8d41-db1a-0410-9941-cceddc491573> | 2007-04-24 22:38:41 +0000 |
---|---|---|
committer | haranp <haranp@c06c8d41-db1a-0410-9941-cceddc491573> | 2007-04-24 22:38:41 +0000 |
commit | 9304ae6cc3684377e50e6fcbc3d13e80fa092b6a (patch) | |
tree | b0b15e708dbca7e6455bf0e6e3726b75037f937b | |
parent | 56b6c4f46ec7516396c1473e9d5bfef7ea79765f (diff) | |
download | crawl-ref-9304ae6cc3684377e50e6fcbc3d13e80fa092b6a.tar.gz crawl-ref-9304ae6cc3684377e50e6fcbc3d13e80fa092b6a.zip |
Cleaned up shop-handling code considerably.
Instead of shops passing around global id_arr arrays, shops use the newly
added third argument to item_def::name() which indicates whether to
override item ID status.
This means that the shop ID SIGHUP protection is now unnecessary; it's
been removed.
Hopefully I caught all the places where the stash tracker tries to get
item names and fixed them, but I might have missed something.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@1359 c06c8d41-db1a-0410-9941-cceddc491573
-rw-r--r-- | crawl-ref/source/FixAry.h | 55 | ||||
-rw-r--r-- | crawl-ref/source/FixVec.h | 51 | ||||
-rw-r--r-- | crawl-ref/source/acr.cc | 36 | ||||
-rw-r--r-- | crawl-ref/source/chardump.cc | 15 | ||||
-rw-r--r-- | crawl-ref/source/describe.cc | 110 | ||||
-rw-r--r-- | crawl-ref/source/externs.h | 7 | ||||
-rw-r--r-- | crawl-ref/source/hiscores.cc | 9 | ||||
-rw-r--r-- | crawl-ref/source/invent.cc | 8 | ||||
-rw-r--r-- | crawl-ref/source/invent.h | 1 | ||||
-rw-r--r-- | crawl-ref/source/item_use.cc | 2 | ||||
-rw-r--r-- | crawl-ref/source/itemname.cc | 277 | ||||
-rw-r--r-- | crawl-ref/source/itemname.h | 38 | ||||
-rw-r--r-- | crawl-ref/source/itemprop.cc | 5 | ||||
-rw-r--r-- | crawl-ref/source/religion.cc | 7 | ||||
-rw-r--r-- | crawl-ref/source/shopping.cc | 212 | ||||
-rw-r--r-- | crawl-ref/source/shopping.h | 39 | ||||
-rw-r--r-- | crawl-ref/source/stash.cc | 42 | ||||
-rw-r--r-- | crawl-ref/source/stash.h | 12 | ||||
-rw-r--r-- | crawl-ref/source/tags.cc | 23 |
19 files changed, 351 insertions, 598 deletions
diff --git a/crawl-ref/source/FixAry.h b/crawl-ref/source/FixAry.h index 3db9d49abd..ba4b863866 100644 --- a/crawl-ref/source/FixAry.h +++ b/crawl-ref/source/FixAry.h @@ -34,46 +34,41 @@ public: typedef unsigned long size_type; typedef long difference_type; - typedef FixedVector<TYPE, HEIGHT> Column; // operator[] needs to return one of these to avoid breaking client code (if inlining is on there won't be a speed hit) + // operator[] should return one of these to avoid breaking + // client code (if inlining is on there won't be a speed hit) + typedef FixedVector<TYPE, HEIGHT> Column; //----------------------------------- -// Initialization/Destruction -// -public: - ~FixedArray() {} - - FixedArray() {} - -//----------------------------------- // API // public: // ----- Size ----- - bool empty() const {return WIDTH == 0 || HEIGHT == 0;} - int size() const {return WIDTH*HEIGHT;} + bool empty() const { return WIDTH == 0 || HEIGHT == 0; } + int size() const { return WIDTH*HEIGHT; } + int width() const { return WIDTH; } + int height() const { return HEIGHT; } - int width() const {return WIDTH;} - int height() const {return HEIGHT;} - // ----- Access ----- - Column& operator[](unsigned long index) {return mData[index];} - const Column& operator[](unsigned long index) const {return mData[index];} - template<class Indexer> TYPE& operator () (const Indexer &i) - { - return mData[i.x][i.y]; - } + Column& operator[](unsigned long index) { return mData[index]; } + const Column& operator[](unsigned long index) const { + return mData[index]; + } + + template<class Indexer> TYPE& operator () (const Indexer &i) { + return mData[i.x][i.y]; + } + + template<class Indexer> const TYPE& operator () (const Indexer &i) const { + return mData[i.x][i.y]; + } + + void init(const TYPE& def) { + for ( int i = 0; i < WIDTH; ++i ) + mData[i].init(def); + } - template<class Indexer> const TYPE& operator () (const Indexer &i) - const - { - return mData[i.x][i.y]; - } - -//----------------------------------- -// Member Data -// protected: - FixedVector<Column, WIDTH> mData; + FixedVector<Column, WIDTH> mData; }; diff --git a/crawl-ref/source/FixVec.h b/crawl-ref/source/FixVec.h index 0086750ae3..f574f8fa1c 100644 --- a/crawl-ref/source/FixVec.h +++ b/crawl-ref/source/FixVec.h @@ -59,40 +59,35 @@ public: // instead of "int a[3] = {0, 1, 2}" you'd use "FixedVector<int, 3> // a(0, 1, 2)". Note that there must be SIZE arguments. -// public: -// FixedVector(const FixedVector& rhs); -// -// FixedVector& operator=(const FixedVector& rhs); - //----------------------------------- // API // public: -// ----- Size ----- - bool empty() const {return SIZE == 0;} - size_t size() const {return SIZE;} - -// ----- Access ----- - TYPE& operator[](unsigned long index) {ASSERT(index < SIZE); return mData[index];} - const TYPE& operator[](unsigned long index) const {ASSERT(index < SIZE); return mData[index];} - - TYPE& front() {ASSERT(SIZE > 0); return mData[0];} - const TYPE& front() const {ASSERT(SIZE > 0); return mData[0];} - - TYPE& back() {ASSERT(SIZE > 0); return mData[SIZE - 1];} - const TYPE& back() const {ASSERT(SIZE > 0); return mData[SIZE - 1];} - - TYPE* buffer() {return mData;} - const TYPE* buffer() const {return mData;} + // ----- Size ----- + bool empty() const { return SIZE == 0; } + size_t size() const { return SIZE; } + + // ----- Access ----- + TYPE& operator[](unsigned long index) { + ASSERT(index < SIZE); + return mData[index]; + } + + const TYPE& operator[](unsigned long index) const { + ASSERT(index < SIZE); + return mData[index]; + } -// ----- Iterating ----- - iterator begin() {return mData;} - const_iterator begin() const {return mData;} + const TYPE* buffer() const { return mData; } + TYPE* buffer() { return mData; } - iterator end() {return this->begin() + this->size();} - const_iterator end() const {return this->begin() + this->size();} + // ----- Iterating ----- + iterator begin() { return mData; } + const_iterator begin() const { return mData; } - void init(TYPE def); + iterator end() { return this->begin() + this->size(); } + const_iterator end() const { return this->begin() + this->size(); } + void init(const TYPE& def); //----------------------------------- // Member Data @@ -124,7 +119,7 @@ FixedVector<TYPE, SIZE>::FixedVector(TYPE value0, TYPE value1, ...) } template <class TYPE, int SIZE> -void FixedVector<TYPE, SIZE>::init(TYPE def) +void FixedVector<TYPE, SIZE>::init(const TYPE& def) { for (int i = 0; i < SIZE; ++i) mData[i] = def; diff --git a/crawl-ref/source/acr.cc b/crawl-ref/source/acr.cc index 6ccafa14fd..fe5de67155 100644 --- a/crawl-ref/source/acr.cc +++ b/crawl-ref/source/acr.cc @@ -55,6 +55,7 @@ #include <string.h> #include <fcntl.h> #include <stdio.h> +#include <sstream> #ifdef DOS #include <dos.h> @@ -309,24 +310,29 @@ int main( int argc, char *argv[] ) Options.tut_just_triggered = true; // print stats and everything prep_input(); - char ch = 'x'; - mpr("Press any key to start the tutorial intro, or Escape to skip it.", - MSGCH_TUTORIAL); + int ch = 'x'; + mpr("Press any key to start the tutorial intro, " + "or Escape to skip it.", MSGCH_TUTORIAL); ch = c_getch(); - + if (ch != ESCAPE) tut_starting_screen(); - } + } + + std::ostringstream notestr; + notestr << you.your_name << ", the " + << species_name(you.species,you.experience_level) << " " + << you.class_name + << ", began the quest for the Orb."; + take_note(Note(NOTE_USER_NOTE, 0, 0, notestr.str().c_str())); + + notestr.str(""); + notestr.clear(); - snprintf(info, INFO_SIZE, - "%s, the %s %s, began the quest for the Orb.", - you.your_name, - species_name(you.species,you.experience_level), - you.class_name); - take_note(Note(NOTE_USER_NOTE, 0, 0, info)); - snprintf(info, INFO_SIZE, "HP: %d/%d MP: %d/%d", - you.hp, you.hp_max, you.magic_points, you.max_magic_points); - take_note(Note(NOTE_XP_LEVEL_CHANGE, you.experience_level, 0, info)); + notestr << "HP: " << you.hp << "/" << you.hp_max + << " MP: " << you.magic_points << "/" << you.max_magic_points; + take_note(Note(NOTE_XP_LEVEL_CHANGE, you.experience_level, 0, + notestr.str().c_str())); } while (true) @@ -2815,7 +2821,7 @@ static bool initialise(void) you.colour = LIGHTGREY; seed_rng(); - clear_ids(); // in itemname.cc + get_typeid_array().init(ID_UNKNOWN_TYPE); init_char_table(Options.char_set); init_feature_table(); diff --git a/crawl-ref/source/chardump.cc b/crawl-ref/source/chardump.cc index 85d3bb1359..f7fef93fa2 100644 --- a/crawl-ref/source/chardump.cc +++ b/crawl-ref/source/chardump.cc @@ -563,7 +563,6 @@ static void sdump_religion(const std::string &, std::string & text) } } -extern char id[4][50]; // itemname.cc static bool dump_item_origin(const item_def &item, int value) { #define fs(x) (flags & (x)) @@ -611,7 +610,7 @@ static bool dump_item_origin(const item_def &item, int value) if (refpr == -1) return (false); if (value == -1) - value = item_value( item, id, false ); + value = item_value( item, false ); return (value >= refpr); #undef fs } @@ -624,18 +623,9 @@ static bool dump_item_origin(const item_def &item, int value) static void sdump_inventory(const std::string &, std::string & text) { int i, j; - char temp_id[4][50]; std::string text2; - for (i = 0; i < 4; i++) - { - for (j = 0; j < 50; j++) - { - temp_id[i][j] = 1; - } - } - int inv_class2[OBJ_GOLD]; int inv_count = 0; char tmp_quant[20]; @@ -704,8 +694,7 @@ static void sdump_inventory(const std::string &, std::string & text) { text += " ("; - itoa( ival = - item_value( you.inv[j], temp_id, true ), + itoa( ival = item_value( you.inv[j], true ), tmp_quant, 10 ); text += tmp_quant; diff --git a/crawl-ref/source/describe.cc b/crawl-ref/source/describe.cc index 7e86ae3316..2cc47ab016 100644 --- a/crawl-ref/source/describe.cc +++ b/crawl-ref/source/describe.cc @@ -25,6 +25,8 @@ #include <stdlib.h> #include <stdio.h> #include <string> +#include <sstream> +#include <iomanip> #ifdef DOS #include <conio.h> @@ -3242,142 +3244,132 @@ bool is_dumpable_artifact( const item_def &item, bool verbose) // be interpreted as carriage returns. // //--------------------------------------------------------------- -std::string get_item_description( const item_def &item, bool verbose, bool dump ) +std::string get_item_description( const item_def &item, bool verbose, + bool dump ) { - std::string description; - description.reserve(500); + std::ostringstream description; if (!dump) - description += item.name(DESC_INVENTORY_EQUIP); + description << item.name(DESC_INVENTORY_EQUIP); - description += "$$"; + description << "$$"; #if DEBUG_DIAGNOSTICS if (!dump) { - snprintf( info, INFO_SIZE, - "base: %d; sub: %d; plus: %d; plus2: %d; special: %ld$" - "quant: %d; colour: %d; flags: 0x%08lx$" - "x: %d; y: %d; link: %d$ident_type: %d$$", - item.base_type, item.sub_type, item.plus, item.plus2, - item.special, item.quantity, item.colour, item.flags, - item.x, item.y, item.link, - get_ident_type( item.base_type, item.sub_type ) ); - - description += info; + description << std::setfill('0'); + description << "base: " << static_cast<int>(item.base_type) + << " sub: " << static_cast<int>(item.sub_type) + << " plus: " << item.plus << " plus2: " << item.plus2 + << " special: " << item.special + << "$" + << "quant: " << item.quantity + << " colour: " << static_cast<int>(item.colour) + << " flags: " << std::hex << std::setw(8) << item.flags + << std::dec << "$" + << "x: " << item.x << " y: " << item.y + << " link: " << item.link + << "$" + << "ident_type: " + << get_ident_type(item.base_type, item.sub_type) + << "$"; } #endif switch (item.base_type) { case OBJ_WEAPONS: - description += describe_weapon( item, verbose ); + description << describe_weapon( item, verbose ); break; case OBJ_MISSILES: - description += describe_ammo( item ); + description << describe_ammo( item ); break; case OBJ_ARMOUR: - description += describe_armour( item, verbose ); + description << describe_armour( item, verbose ); break; case OBJ_WANDS: - description += describe_stick( item ); + description << describe_stick( item ); break; case OBJ_FOOD: - description += describe_food( item ); + description << describe_food( item ); break; case OBJ_SCROLLS: - description += describe_scroll( item ); + description << describe_scroll( item ); break; case OBJ_JEWELLERY: - description += describe_jewellery( item, verbose ); + description << describe_jewellery( item, verbose ); break; case OBJ_POTIONS: - description += describe_potion( item ); + description << describe_potion( item ); break; case OBJ_STAVES: - description += describe_staff( item ); + description << describe_staff( item ); break; case OBJ_BOOKS: switch (item.sub_type) { case BOOK_DESTRUCTION: - description += "An extremely powerful but unpredictable book " + description << "An extremely powerful but unpredictable book " "of magic. "; break; case BOOK_MANUAL: - description += "A valuable book of magic which allows one to " - "practise a certain skill greatly. As it is used, it gradually " - "disintegrates and will eventually fall apart. "; + description << "A valuable book of magic which allows one to " + "practise a certain skill greatly. As it is used, it " + "gradually disintegrates and will eventually fall apart. "; break; default: - description += "A book of magic spells. Beware, for some of the " + description << "A book of magic spells. Beware, for some of the " "more powerful grimoires are not to be toyed with. "; break; } break; case OBJ_ORBS: - description += "Once you have escaped to the surface with " + description << "Once you have escaped to the surface with " "this invaluable artefact, your quest is complete. "; break; case OBJ_MISCELLANY: - description += describe_misc_item( item ); + description << describe_misc_item( item ); break; case OBJ_CORPSES: - description += - ((item.sub_type == CORPSE_BODY) ? "A corpse. " - : "A decaying skeleton. "); + if ( item.sub_type == CORPSE_BODY) + description << "A corpse. "; + else + description << "A decaying skeleton. "; break; case OBJ_GOLD: - description += "A pile of glittering gold coins. "; + description << "A pile of glittering gold coins. "; break; default: DEBUGSTR("Bad item class"); - description += "This item should not exist. Mayday! Mayday! "; + description << "This item should not exist. Mayday! Mayday! "; } if (verbose) { - - description += "$It weighs around "; - const int mass = item_mass( item ); - - char item_mass[16]; - itoa( mass / 10, item_mass, 10 ); - - for (int i = 0; i < 14; i++) - { - if (item_mass[i] == 0) - { - item_mass[i] = '.'; - item_mass[i+1] = (mass % 10) + '0'; - item_mass[i+2] = 0; - break; - } - } - - description += item_mass; - description += " aum. "; // arbitrary unit of mass + description << "$It weighs around " << (mass / 10) + << "." << (mass % 10) + << " aum. "; // arbitrary unit of mass if ( is_dumpable_artifact(item, false) ) { if (item.base_type == OBJ_ARMOUR || item.base_type == OBJ_WEAPONS) - description += "$$This ancient artifact cannot be changed " + description << "$$This ancient artifact cannot be changed " "by magic or mundane means."; else - description += "$$It is an ancient artifact."; + description << "$$It is an ancient artifact."; } } - return (description); + return description.str(); } // end get_item_description() static std::string get_feature_description_wide(int feat) diff --git a/crawl-ref/source/externs.h b/crawl-ref/source/externs.h index 69b3d42291..0dd9344b83 100644 --- a/crawl-ref/source/externs.h +++ b/crawl-ref/source/externs.h @@ -431,14 +431,14 @@ struct item_def } std::string name(description_level_type descrip, - bool terse = false) const; + bool terse = false, bool ident = false) const; void clear() { *this = item_def(); } private: - void name_aux( char* buff, bool terse ) const; + void name_aux( char* buff, bool terse, bool ident ) const; }; class input_history @@ -1541,7 +1541,6 @@ extern const char* god_gain_power_messages[MAX_NUM_GODS][MAX_GOD_ABILITIES]; typedef int keycode_type; -typedef FixedArray < int, 4, 50 > id_fix_arr; -typedef char id_arr[4][50]; +typedef FixedArray < item_type_id_state_type, 4, 50 > id_arr; #endif // EXTERNS_H diff --git a/crawl-ref/source/hiscores.cc b/crawl-ref/source/hiscores.cc index 09d66dc8fe..47b1f9d68b 100644 --- a/crawl-ref/source/hiscores.cc +++ b/crawl-ref/source/hiscores.cc @@ -1063,13 +1063,6 @@ void scorefile_entry::init() //if (death_type == KILLED_BY_WINNING) points += points / 2; //if (death_type == KILLED_BY_LEAVING) points += points / 10; // these now handled by giving player the value of their inventory - char temp_id[4][50]; - - for (int d = 0; d < 4; d++) - { - for (int e = 0; e < 50; e++) - temp_id[d][e] = 1; - } FixedVector< int, NUM_RUNE_TYPES > rune_array; @@ -1088,7 +1081,7 @@ void scorefile_entry::init() if (is_valid_item( you.inv[d] )) { if (calc_item_values) - points += item_value( you.inv[d], temp_id, true ); + points += item_value( you.inv[d], true ); if (you.inv[d].base_type == OBJ_MISCELLANY && you.inv[d].sub_type == MISC_RUNE_OF_ZOT) diff --git a/crawl-ref/source/invent.cc b/crawl-ref/source/invent.cc index a00e69a77b..f2b7174405 100644 --- a/crawl-ref/source/invent.cc +++ b/crawl-ref/source/invent.cc @@ -99,7 +99,7 @@ std::string InvEntry::get_text() const if (InvEntry::show_prices) { - int value = item_value(*item, temp_id, true); + const int value = item_value(*item, show_prices); if (value > 0) snprintf(suffix, sizeof suffix, " (%d gold)", value); @@ -164,14 +164,10 @@ void InvEntry::add_class_hotkeys(const item_def &i) } bool InvEntry::show_prices = false; -char InvEntry::temp_id[4][50]; void InvEntry::set_show_prices(bool doshow) { - if ((show_prices = doshow)) - { - memset(temp_id, 1, sizeof temp_id); - } + show_prices = doshow; } InvShowPrices::InvShowPrices(bool doshow) diff --git a/crawl-ref/source/invent.h b/crawl-ref/source/invent.h index 5696a2ea8a..46384eeec3 100644 --- a/crawl-ref/source/invent.h +++ b/crawl-ref/source/invent.h @@ -54,7 +54,6 @@ class InvEntry : public MenuEntry { private: static bool show_prices; - static char temp_id[4][50]; static void set_show_prices(bool doshow); friend class InvShowPrices; diff --git a/crawl-ref/source/item_use.cc b/crawl-ref/source/item_use.cc index 88866eec89..7de4459216 100644 --- a/crawl-ref/source/item_use.cc +++ b/crawl-ref/source/item_use.cc @@ -1998,7 +1998,7 @@ bool throw_it(struct bolt &pbolt, int throw_2, monsters *dummy_target) void jewellery_wear_effects(item_def &item) { - int ident = ID_TRIED_TYPE; + item_type_id_state_type ident = ID_TRIED_TYPE; switch (item.sub_type) { diff --git a/crawl-ref/source/itemname.cc b/crawl-ref/source/itemname.cc index 66708cbfb9..059d2877e8 100644 --- a/crawl-ref/source/itemname.cc +++ b/crawl-ref/source/itemname.cc @@ -38,14 +38,10 @@ #include "view.h" #include "items.h" -id_arr id; - -// Backup of the id array used to save ids if the game receives SIGHUP -// when the character is in a shop. -id_arr shop_backup_id; +id_arr type_ids; static bool is_random_name_space( char let ); -static bool is_random_name_vowel( char let); +static bool is_random_name_vowel( char let ); static char retvow(int sed); static char retlet(int sed); @@ -55,11 +51,11 @@ static bool is_tried_type( int basetype, int subtype ) switch ( basetype ) { case OBJ_SCROLLS: - return id[IDTYPE_SCROLLS][subtype] == ID_TRIED_TYPE; + return type_ids[IDTYPE_SCROLLS][subtype] == ID_TRIED_TYPE; case OBJ_POTIONS: - return id[IDTYPE_POTIONS][subtype] == ID_TRIED_TYPE; + return type_ids[IDTYPE_POTIONS][subtype] == ID_TRIED_TYPE; case OBJ_WANDS: - return id[IDTYPE_WANDS][subtype] == ID_TRIED_TYPE; + return type_ids[IDTYPE_WANDS][subtype] == ID_TRIED_TYPE; default: return false; } @@ -68,29 +64,8 @@ static bool is_tried_type( int basetype, int subtype ) bool is_vowel( const char chr ) { const char low = tolower( chr ); - - return (low == 'a' || low == 'e' || low == 'i' || low == 'o' || low == 'u'); -} - -item_type_id_type objtype_to_idtype(int base_type) -{ - switch (base_type) - { - case OBJ_WANDS: return (IDTYPE_WANDS); - case OBJ_SCROLLS: return (IDTYPE_SCROLLS); - case OBJ_JEWELLERY: return (IDTYPE_JEWELLERY); - case OBJ_POTIONS: return (IDTYPE_POTIONS); - default: return (NUM_IDTYPE); - } -} - -bool item_type_known( const item_def &item ) -{ - if (item_ident(item, ISFLAG_KNOW_TYPE)) - return (true); - - const item_type_id_type idt = objtype_to_idtype(item.base_type); - return (idt != NUM_IDTYPE? id[idt][item.sub_type] == ID_KNOWN_TYPE : false); + return (low == 'a' || low == 'e' || low == 'i' || + low == 'o' || low == 'u'); } // quant_name is useful since it prints out a different number of items @@ -108,13 +83,13 @@ std::string quant_name( const item_def &item, int quant, // buff must be at least ITEMNAME_SIZE if non-NULL. If NULL, a static // item buffer will be used. std::string item_def::name(description_level_type descrip, - bool terse) const + bool terse, bool ident) const { char tmp_quant[20]; char itm_name[ITEMNAME_SIZE] = ""; char buff[ITEMNAME_SIZE] = ""; - this->name_aux(itm_name, terse); + this->name_aux(itm_name, terse, ident); if (descrip == DESC_INVENTORY_EQUIP || descrip == DESC_INVENTORY) { @@ -129,11 +104,11 @@ std::string item_def::name(description_level_type descrip, descrip = DESC_PLAIN; if (this->base_type == OBJ_ORBS - || (item_type_known( *this ) - && ((this->base_type == OBJ_MISCELLANY - && this->sub_type == MISC_HORN_OF_GERYON) - || (is_fixed_artefact( *this ) - || (is_random_artefact( *this )))))) + || ( (ident || item_type_known( *this )) + && ((this->base_type == OBJ_MISCELLANY + && this->sub_type == MISC_HORN_OF_GERYON) + || (is_fixed_artefact( *this ) + || (is_random_artefact( *this )))))) { // artefacts always get "the" unless we just want the plain name switch (descrip) @@ -295,12 +270,17 @@ std::string item_def::name(description_level_type descrip, // Note that "terse" is only currently used for the "in hand" listing on // the game screen. -void item_def::name_aux( char* buff, bool terse ) const +void item_def::name_aux( char* buff, bool terse, bool ident ) const { + // Shortcuts const int item_typ = this->sub_type; const int it_plus = this->plus; const int item_plus2 = this->plus2; + const bool know_curse = ident || item_ident(*this, ISFLAG_KNOW_CURSE); + const bool know_type = ident || item_type_known(*this); + const bool know_pluses = ident || item_ident(*this, ISFLAG_KNOW_PLUSES); + char tmp_quant[20]; char tmp_buff[ITEMNAME_SIZE]; int brand; @@ -311,7 +291,7 @@ void item_def::name_aux( char* buff, bool terse ) const switch (this->base_type) { case OBJ_WEAPONS: - if (item_ident( *this, ISFLAG_KNOW_CURSE ) && !terse) + if (know_curse && !terse) { // We don't bother printing "uncursed" if the item is identified // for pluses (its state should be obvious), this is so that @@ -322,13 +302,13 @@ void item_def::name_aux( char* buff, bool terse ) const if (item_cursed( *this )) strncat(buff, "cursed ", ITEMNAME_SIZE ); else if (Options.show_uncursed - && !item_ident( *this, ISFLAG_KNOW_PLUSES )) + && !know_pluses) { strncat(buff, "uncursed ", ITEMNAME_SIZE ); } } - if (item_ident( *this, ISFLAG_KNOW_PLUSES )) + if (know_pluses) { if (it_plus == 0 && item_plus2 == 0) strncat(buff, "+0 ", ITEMNAME_SIZE ); @@ -363,7 +343,7 @@ void item_def::name_aux( char* buff, bool terse ) const if (is_fixed_artefact( *this )) { - if (item_type_known( *this )) + if (know_type) { strncat(buff, (this->special == SPWPN_SINGING_SWORD) ? "Singing Sword" : @@ -411,7 +391,7 @@ void item_def::name_aux( char* buff, bool terse ) const // Now that we can have "glowing elven" weapons, it's // probably a good idea to cut out the descriptive // term once it's become obsolete. -- bwr - if (!item_ident( *this, ISFLAG_KNOW_PLUSES ) && !terse) + if (!know_pluses && !terse) { switch (get_equip_desc( *this )) { @@ -441,7 +421,7 @@ void item_def::name_aux( char* buff, bool terse ) const brand = get_weapon_brand( *this ); - if (item_type_known(*this) && !terse) + if (know_type && !terse) { if (brand == SPWPN_VAMPIRICISM) strncat(buff, "vampiric ", ITEMNAME_SIZE ); @@ -449,7 +429,7 @@ void item_def::name_aux( char* buff, bool terse ) const strncat(buff, item_base_name(*this).c_str(), ITEMNAME_SIZE); - if (item_type_known( *this )) + if (know_type) { switch (brand) { @@ -544,7 +524,7 @@ void item_def::name_aux( char* buff, bool terse ) const } } - if (item_ident(*this, ISFLAG_KNOW_CURSE) && item_cursed(*this) && terse) + if (know_curse && item_cursed(*this) && terse) strncat( buff, " (curse)", ITEMNAME_SIZE ); break; @@ -559,7 +539,7 @@ void item_def::name_aux( char* buff, bool terse ) const strncat( buff, (terse) ? "curare " : "curare-tipped ", ITEMNAME_SIZE); } - if (item_ident( *this, ISFLAG_KNOW_PLUSES )) + if (know_pluses) { if (it_plus >= 0) strncat(buff, "+", ITEMNAME_SIZE ); @@ -594,7 +574,7 @@ void item_def::name_aux( char* buff, bool terse ) const if (this->quantity > 1) strncat(buff, "s", ITEMNAME_SIZE ); - if (item_type_known( *this )) + if (know_type) { strncat( buff, (brand == SPMSL_FLAME) ? ((terse) ? " (flame)" : " of flame") : @@ -607,18 +587,18 @@ void item_def::name_aux( char* buff, bool terse ) const break; case OBJ_ARMOUR: - if (item_ident( *this, ISFLAG_KNOW_CURSE ) && !terse) + if (know_curse && !terse) { if (item_cursed( *this )) strncat(buff, "cursed ", ITEMNAME_SIZE ); else if (Options.show_uncursed - && !item_ident( *this, ISFLAG_KNOW_PLUSES )) + && !know_pluses) { strncat(buff, "uncursed ", ITEMNAME_SIZE ); } } - if (item_ident( *this, ISFLAG_KNOW_PLUSES )) + if (know_pluses) { if (it_plus >= 0) strncat(buff, "+", ITEMNAME_SIZE ); @@ -643,7 +623,7 @@ void item_def::name_aux( char* buff, bool terse ) const // Now that we can have "glowing elven" armour, it's // probably a good idea to cut out the descriptive // term once it's become obsolete. -- bwr - if (!item_ident( *this, ISFLAG_KNOW_PLUSES ) && !terse) + if (!know_pluses && !terse) { switch (get_equip_desc( *this )) { @@ -688,7 +668,7 @@ void item_def::name_aux( char* buff, bool terse ) const sparm = get_armour_ego_type( *this ); - if (item_type_known(*this) && sparm != SPARM_NORMAL) + if (know_type && sparm != SPARM_NORMAL) { if (!terse) { @@ -740,13 +720,13 @@ void item_def::name_aux( char* buff, bool terse ) const } } - if (item_ident(*this, ISFLAG_KNOW_CURSE) && item_cursed(*this) && terse) + if (know_curse && item_cursed(*this) && terse) strncat( buff, " (curse)", ITEMNAME_SIZE ); break; // compacted 15 Apr 2000 {dlb}: case OBJ_WANDS: - if (item_type_known(*this)) + if (know_type) { strncat(buff, "wand of ", ITEMNAME_SIZE ); strncat(buff, (item_typ == WAND_FLAME) ? "flame" : @@ -813,7 +793,7 @@ void item_def::name_aux( char* buff, bool terse ) const strncat(buff, " wand", ITEMNAME_SIZE ); } - if (item_ident( *this, ISFLAG_KNOW_PLUSES )) + if (know_pluses) { strncat(buff, " (", ITEMNAME_SIZE ); itoa( it_plus, tmp_quant, 10 ); @@ -827,7 +807,7 @@ void item_def::name_aux( char* buff, bool terse ) const // compacted 15 Apr 2000 {dlb}: case OBJ_POTIONS: - if (item_type_known(*this)) + if (know_type) { strncat(buff, "potion", ITEMNAME_SIZE ); strncat(buff, (this->quantity == 1) ? " " : "s ", ITEMNAME_SIZE); @@ -992,7 +972,7 @@ void item_def::name_aux( char* buff, bool terse ) const strncat(buff, "scroll", ITEMNAME_SIZE ); strncat(buff, (this->quantity == 1) ? " " : "s ", ITEMNAME_SIZE); - if (item_type_known(*this)) + if (know_type) { strncat(buff, "of ", ITEMNAME_SIZE ); strncat(buff, (item_typ == SCR_IDENTIFY) ? "identify" : @@ -1041,14 +1021,13 @@ void item_def::name_aux( char* buff, bool terse ) const // not using {tried} here because there are some confusing // issues to work out with how we want to handle jewellery // artefacts and base type id. -- bwr - if (item_ident( *this, ISFLAG_KNOW_CURSE )) + if (know_curse) { if (item_cursed( *this )) strncat(buff, "cursed ", ITEMNAME_SIZE ); else if (Options.show_uncursed - && !terse - && (!ring_has_pluses(*this) - || !item_ident(*this, ISFLAG_KNOW_PLUSES)) + && !terse + && (!ring_has_pluses(*this) || !know_pluses) // If the item is worn, its curse status is known, // no need to belabour the obvious. @@ -1064,10 +1043,10 @@ void item_def::name_aux( char* buff, bool terse ) const break; } - if (item_type_known(*this)) + if (know_type) { - if (item_ident( *this, ISFLAG_KNOW_PLUSES ) + if (know_pluses && (item_typ == RING_PROTECTION || item_typ == RING_STRENGTH || item_typ == RING_SLAYING || item_typ == RING_EVASION || item_typ == RING_DEXTERITY @@ -1435,7 +1414,7 @@ void item_def::name_aux( char* buff, bool terse ) const if (this->quantity > 1) strncat(buff, "s", ITEMNAME_SIZE ); - if (item_type_known(*this)) + if (know_type) strncat(buff, " of Zot", ITEMNAME_SIZE ); break; @@ -1444,7 +1423,7 @@ void item_def::name_aux( char* buff, bool terse ) const case MISC_DECK_OF_TRICKS: case MISC_DECK_OF_WONDERS: strncat(buff, "deck of ", ITEMNAME_SIZE ); - strncat(buff, !item_type_known(*this) ? "cards" : + strncat(buff, !know_type ? "cards" : (item_typ == MISC_DECK_OF_WONDERS) ? "wonders" : (item_typ == MISC_DECK_OF_SUMMONINGS) ? "summonings" : (item_typ == MISC_DECK_OF_TRICKS) ? "tricks" : @@ -1457,7 +1436,7 @@ void item_def::name_aux( char* buff, bool terse ) const case MISC_CRYSTAL_BALL_OF_FIXATION: case MISC_CRYSTAL_BALL_OF_SEEING: strncat(buff, "crystal ball", ITEMNAME_SIZE ); - if (item_type_known(*this)) + if (know_type) { strncat(buff, " of ", ITEMNAME_SIZE ); strncat(buff, @@ -1470,69 +1449,69 @@ void item_def::name_aux( char* buff, bool terse ) const break; case MISC_BOX_OF_BEASTS: - if (item_type_known(*this)) + if (know_type) strncat(buff, "box of beasts", ITEMNAME_SIZE ); else strncat(buff, "small ebony casket", ITEMNAME_SIZE ); break; case MISC_EMPTY_EBONY_CASKET: - if (item_type_known(*this)) + if (know_type) strncat(buff, "empty ebony casket", ITEMNAME_SIZE ); else strncat(buff, "small ebony casket", ITEMNAME_SIZE ); break; case MISC_AIR_ELEMENTAL_FAN: - if (item_type_known(*this)) + if (know_type) strncat(buff, "air elemental ", ITEMNAME_SIZE ); strncat(buff, "fan", ITEMNAME_SIZE ); break; case MISC_LAMP_OF_FIRE: strncat(buff, "lamp", ITEMNAME_SIZE ); - if (item_type_known(*this)) + if (know_type) strncat(buff, " of fire", ITEMNAME_SIZE ); break; case MISC_LANTERN_OF_SHADOWS: - if (!item_type_known(*this)) + if (!know_type) strncat(buff, "bone ", ITEMNAME_SIZE ); strncat(buff, "lantern", ITEMNAME_SIZE ); - if (item_type_known(*this)) + if (know_type) strncat(buff, " of shadows", ITEMNAME_SIZE ); break; case MISC_HORN_OF_GERYON: - if (!item_type_known(*this)) + if (!know_type) strncat(buff, "silver ", ITEMNAME_SIZE ); strncat(buff, "horn", ITEMNAME_SIZE ); - if (item_type_known(*this)) + if (know_type) strncat(buff, " of Geryon", ITEMNAME_SIZE ); break; case MISC_DISC_OF_STORMS: - if (!item_type_known(*this)) + if (!know_type) strncat(buff, "grey ", ITEMNAME_SIZE ); strncat(buff, "disc", ITEMNAME_SIZE ); - if (item_type_known(*this)) + if (know_type) strncat(buff, " of storms", ITEMNAME_SIZE ); break; case MISC_STONE_OF_EARTH_ELEMENTALS: - if (!item_type_known(*this)) + if (!know_type) strncat(buff, "nondescript ", ITEMNAME_SIZE ); strncat(buff, "stone", ITEMNAME_SIZE ); - if (item_type_known(*this)) + if (know_type) strncat(buff, " of earth elementals", ITEMNAME_SIZE ); break; case MISC_BOTTLED_EFREET: - strncat(buff, (!item_type_known(*this)) + strncat(buff, (!know_type) ? "sealed bronze flask" : "bottled efreet", ITEMNAME_SIZE ); break; @@ -1549,7 +1528,7 @@ void item_def::name_aux( char* buff, bool terse ) const // compacted 15 Apr 2000 {dlb}: case OBJ_BOOKS: - if (!item_type_known(*this)) + if (!know_type) { char primary = (this->special / 10); char secondary = (this->special % 10); @@ -1646,7 +1625,7 @@ void item_def::name_aux( char* buff, bool terse ) const // compacted 15 Apr 2000 {dlb}: case OBJ_STAVES: - if (!item_type_known(*this)) + if (!know_type) { strncat(buff, (this->special == 0) ? "curved" : (this->special == 1) ? "glowing" : @@ -1683,7 +1662,7 @@ void item_def::name_aux( char* buff, bool terse ) const strncat( buff, (item_is_rod( *this ) ? "rod" : "staff"), ITEMNAME_SIZE ); - if (item_type_known(*this)) + if (know_type) { strncat(buff, " of ", ITEMNAME_SIZE ); @@ -1714,7 +1693,7 @@ void item_def::name_aux( char* buff, bool terse ) const } if (item_is_rod( *this ) - && item_type_known(*this)) + && know_type) { strncat( buff, " (", ITEMNAME_SIZE ); itoa( this->plus / ROD_CHARGE_MULT, tmp_quant, 10 ); @@ -1760,7 +1739,7 @@ void item_def::name_aux( char* buff, bool terse ) const } // end of switch? // Disambiguation - if (!terse && item_type_known(*this)) + if (!terse && know_type) { #define name_append(x) strncat(buff, x, ITEMNAME_SIZE) switch (this->base_type) @@ -1843,89 +1822,66 @@ void item_def::name_aux( char* buff, bool terse ) const } } -void save_id(id_arr identy, bool saving_game) -{ - memcpy(identy, - (!saving_game || !crawl_state.shopping)? id : shop_backup_id, - sizeof id); -} // end save_id() - -void clear_ids(void) +item_type_id_type objtype_to_idtype(int base_type) { - - int i = 0, j = 0; - - for (i = 0; i < 4; i++) + switch (base_type) { - for (j = 0; j < 50; j++) - { - id[i][j] = ID_UNKNOWN_TYPE; - } + case OBJ_WANDS: return (IDTYPE_WANDS); + case OBJ_SCROLLS: return (IDTYPE_SCROLLS); + case OBJ_JEWELLERY: return (IDTYPE_JEWELLERY); + case OBJ_POTIONS: return (IDTYPE_POTIONS); + default: return (NUM_IDTYPE); } +} + +bool item_type_known( const item_def &item ) +{ + if (item_ident(item, ISFLAG_KNOW_TYPE)) + return (true); -} // end clear_ids() + const item_type_id_type idt = objtype_to_idtype(item.base_type); + if ( idt != NUM_IDTYPE ) + return ( type_ids[idt][item.sub_type] == ID_KNOWN_TYPE ); + else + return false; +} +id_arr& get_typeid_array() +{ + return type_ids; +} -void set_ident_type( char cla, int ty, char setting, bool force ) +void set_ident_type( int basetype, int subtype, + item_type_id_state_type setting, bool force ) { // Don't allow overwriting of known type with tried unless forced. if (!force && setting == ID_TRIED_TYPE - && get_ident_type( cla, ty ) == ID_KNOWN_TYPE) + && get_ident_type( basetype, subtype ) == ID_KNOWN_TYPE) { return; } - switch (cla) - { - case OBJ_WANDS: - id[ IDTYPE_WANDS ][ty] = setting; - break; + const item_type_id_type idt = objtype_to_idtype(basetype); - case OBJ_SCROLLS: - id[ IDTYPE_SCROLLS ][ty] = setting; - break; - - case OBJ_JEWELLERY: - id[ IDTYPE_JEWELLERY ][ty] = setting; - break; - - case OBJ_POTIONS: - id[ IDTYPE_POTIONS ][ty] = setting; - break; - - default: - break; - } -} // end set_ident_type() + if ( idt != NUM_IDTYPE ) + type_ids[idt][subtype] = setting; +} -char get_ident_type(char cla, int ty) +item_type_id_state_type get_ident_type(int basetype, int subtype) { - switch (cla) - { - case OBJ_WANDS: - return id[ IDTYPE_WANDS ][ty]; - - case OBJ_SCROLLS: - return id[ IDTYPE_SCROLLS ][ty]; - - case OBJ_JEWELLERY: - return id[ IDTYPE_JEWELLERY ][ty]; - - case OBJ_POTIONS: - return id[ IDTYPE_POTIONS ][ty]; - - default: - return (ID_UNKNOWN_TYPE); - } -} // end get_ident_type() + const item_type_id_type idt = objtype_to_idtype(basetype); + if ( idt != NUM_IDTYPE && subtype < type_ids.height() ) + return type_ids[idt][subtype]; + else + return ID_UNKNOWN_TYPE; +} static MenuEntry *discoveries_item_mangle(MenuEntry *me) { InvEntry *ie = dynamic_cast<InvEntry*>(me); MenuEntry *newme = new MenuEntry; - const std::string txt = ie->item->name(DESC_PLAIN); - newme->text = " " + txt; + newme->text = std::string(" ") + ie->item->name(DESC_PLAIN); newme->quantity = 0; delete me; @@ -1934,20 +1890,22 @@ static MenuEntry *discoveries_item_mangle(MenuEntry *me) void check_item_knowledge() { - int i,j; - std::vector<const item_def*> items; - int idx_to_objtype[4] = { OBJ_WANDS, OBJ_SCROLLS, - OBJ_JEWELLERY, OBJ_POTIONS }; - int idx_to_maxtype[4] = { NUM_WANDS, NUM_SCROLLS, - NUM_JEWELLERY, NUM_POTIONS }; + const int idx_to_objtype[4] = { OBJ_WANDS, OBJ_SCROLLS, + OBJ_JEWELLERY, OBJ_POTIONS }; + const int idx_to_maxtype[4] = { NUM_WANDS, NUM_SCROLLS, + NUM_JEWELLERY, NUM_POTIONS }; - for (i = 0; i < 4; i++) { - for (j = 0; j < idx_to_maxtype[i]; j++) { - if (id[i][j] == ID_KNOWN_TYPE) { + for (int i = 0; i < 4; i++) + { + for (int j = 0; j < idx_to_maxtype[i]; j++) + { + if (type_ids[i][j] == ID_KNOWN_TYPE) + { item_def* ptmp = new item_def; - if ( ptmp != 0 ) { + if ( ptmp != 0 ) + { ptmp->base_type = idx_to_objtype[i]; ptmp->sub_type = j; ptmp->colour = 1; @@ -1960,7 +1918,8 @@ void check_item_knowledge() if (items.empty()) mpr("You don't recognise anything yet!"); - else { + else + { InvMenu menu; menu.set_title("You recognise:"); menu.load_items(items, discoveries_item_mangle); diff --git a/crawl-ref/source/itemname.h b/crawl-ref/source/itemname.h index e42ecce3ad..915b070fb2 100644 --- a/crawl-ref/source/itemname.h +++ b/crawl-ref/source/itemname.h @@ -19,12 +19,6 @@ bool is_vowel( const char chr ); /* *********************************************************************** - * called from: describe - effects - item_use - shopping - * *********************************************************************** */ -char get_ident_type(char cla, int ty); - - -/* *********************************************************************** * called from: debug - describe - dungeon - fight - files - item_use - * monstuff - mstuff2 - players - spells0 * *********************************************************************** */ @@ -36,13 +30,6 @@ int property( const item_def &item, int prop_type ); * *********************************************************************** */ void check_item_knowledge(void); - -/* *********************************************************************** - * called from: acr - * *********************************************************************** */ -void clear_ids(void); - - std::string quant_name( const item_def &item, int quant, description_level_type des, bool terse = false ); @@ -63,30 +50,19 @@ int get_weapon_brand( const item_def &item ); int get_ammo_brand( const item_def &item ); int get_armour_ego_type( const item_def &item ); -/* *********************************************************************** - * called from: acr - * *********************************************************************** */ -void init_properties(void); +bool is_interesting_item( const item_def& item ); int make_name( unsigned long seed, bool all_caps, char buff[ ITEMNAME_SIZE ] ); /* *********************************************************************** - * called from: files - shopping - * *********************************************************************** */ -void save_id(id_arr identy, bool saving_game = false); - - -/* *********************************************************************** - * called from: files - item_use - newgame - ouch - shopping - spells1 + * called from: acr * *********************************************************************** */ -void set_ident_type( char cla, int ty, char setting, bool force = false ); +void init_properties(); +id_arr& get_typeid_array(); +item_type_id_state_type get_ident_type(int basetype, int subtype); +void set_ident_type( int basetype, int subtype, + item_type_id_state_type setting, bool force = false); -/* *********************************************************************** - * called from: dungeon - item_use - * *********************************************************************** */ -bool hide2armour( unsigned char *which_subtype ); - -bool is_interesting_item( const item_def& item ); #endif diff --git a/crawl-ref/source/itemprop.cc b/crawl-ref/source/itemprop.cc index 6059fff200..4f37cf22b7 100644 --- a/crawl-ref/source/itemprop.cc +++ b/crawl-ref/source/itemprop.cc @@ -398,7 +398,7 @@ static food_def Food_prop[NUM_FOODS] = // Must call this functions early on so that the above tables can // be accessed correctly. -void init_properties(void) +void init_properties() { int i; @@ -460,7 +460,8 @@ void set_ident_flags( item_def &item, unsigned long flags ) { const bool known_before = fully_identified(item); item.flags |= flags; - if ( !known_before && fully_identified(item) && is_interesting_item(item)) + if ( notes_are_active() && + !known_before && fully_identified(item) && is_interesting_item(item)) { /* make a note of it */ take_note(Note(NOTE_ID_ITEM, 0, 0, item.name(DESC_NOCAP_A).c_str(), diff --git a/crawl-ref/source/religion.cc b/crawl-ref/source/religion.cc index 14a403ca42..060e9fd30b 100644 --- a/crawl-ref/source/religion.cc +++ b/crawl-ref/source/religion.cc @@ -2499,10 +2499,7 @@ void offer_items() { if (you.religion == GOD_NO_GOD) return; - - char subst_id[4][50]; - memset(subst_id, 1, sizeof subst_id); - + int i = igrd[you.x_pos][you.y_pos]; while (i != NON_ITEM) { @@ -2511,7 +2508,7 @@ void offer_items() const int next = mitm[i].link; // in case we can't get it later. - const int value = item_value( mitm[i], subst_id, true ); + const int value = item_value( mitm[i], true ); switch (you.religion) { diff --git a/crawl-ref/source/shopping.cc b/crawl-ref/source/shopping.cc index 5225109309..9d27d4d898 100644 --- a/crawl-ref/source/shopping.cc +++ b/crawl-ref/source/shopping.cc @@ -40,14 +40,10 @@ #include "stuff.h" #include "view.h" -static char in_a_shop(char shoppy, id_arr id); -static char more3(void); -static void purchase( int shop, int item_got, int cost ); -static void shop_init_id(int i, id_fix_arr &shop_id); -static void shop_print(const char *shoppy, char sh_line); -static void shop_set_ident_type(int i, id_fix_arr &shop_id, - unsigned char base_type, unsigned char sub_type); -static void shop_uninit_id(int i, const id_fix_arr &shop_id); +static void in_a_shop(char shoppy); +static char more3(); +static void purchase( int shop, int item_got, int cost); +static void shop_print(const char *shoppy, int sh_line); static std::string hyphenated_suffix(char prev, char last) { @@ -110,44 +106,34 @@ static void list_shop_keys(const std::string &purchasable) fs.display(); } -char in_a_shop( char shoppy, id_arr id ) +static void in_a_shop( char shoppy ) { - // easier to work with {dlb} - unsigned int greedy = env.shop[shoppy].greed; + shop_struct& the_shop = env.shop[shoppy]; + cursor_control coff(false); - id_fix_arr shop_id; FixedVector < int, 20 > shop_items; char st_pass[ ITEMNAME_SIZE ] = ""; unsigned int gp_value = 0; - char i; unsigned char ft; std::string purchasable; clrscr(); int itty = 0; - ShopInfo &si = stashes.get_shop(env.shop[shoppy].x, env.shop[shoppy].y); + ShopInfo &si = stashes.get_shop(the_shop.x, the_shop.y); - snprintf( info, INFO_SIZE, "Welcome to %s!", - shop_name(env.shop[shoppy].x, env.shop[shoppy].y) ); + snprintf(info, INFO_SIZE, "Welcome to %s!", + shop_name(the_shop.x, the_shop.y) ); shop_print(info, 20); more3(); activate_notes(false); /* should do a better job here */ - shop_init_id(shoppy, shop_id); - - /* ************************************* - THINGS TO DO: - Allow inventory - Remove id change for antique shops - selling? - ************************************* */ - save_id(id); + const bool id_stock = shoptype_identifies_stock(the_shop.type); print_stock: clrscr(); @@ -162,11 +148,11 @@ char in_a_shop( char shoppy, id_arr id ) goto goodbye; } - for (i = 1; i < 20; i++) + for (int i = 1; i < 20; i++) { shop_items[i - 1] = itty; - if (itty == NON_ITEM) //mitm.link [itty] == NON_ITEM) + if (itty == NON_ITEM) { shop_items[i - 1] = NON_ITEM; continue; @@ -178,13 +164,13 @@ char in_a_shop( char shoppy, id_arr id ) itty = igrd[0][5 + shoppy]; purchasable.clear(); - for (i = 1; i < 18; i++) + for (int i = 1; i < 18; i++) { const char c = i + 96; gotoxy(1, i); - gp_value = greedy * item_value( mitm[itty], id ); + gp_value = the_shop.greed * item_value(mitm[itty], id_stock); gp_value /= 10; if (gp_value <= 1) gp_value = 1; @@ -199,13 +185,16 @@ char in_a_shop( char shoppy, id_arr id ) textcolor((i % 2) ? WHITE : LIGHTGREY); - cprintf("%s", mitm[itty].name(DESC_NOCAP_A).c_str()); + cprintf("%s", mitm[itty].name(DESC_NOCAP_A, false, id_stock).c_str()); +#if 0 + // huh? XXX XXX does this code do anything? std::string desc; if (is_dumpable_artifact(mitm[itty], Options.verbose_dump)) desc = munge_description(get_item_description(mitm[itty], Options.verbose_dump, true )); +#endif si.add_item(mitm[itty], gp_value); gotoxy(60, i); @@ -242,10 +231,7 @@ char in_a_shop( char shoppy, id_arr id ) if (ft == '\\') { - shop_uninit_id(shoppy, shop_id); check_item_knowledge(); - shop_init_id(shoppy, shop_id); - goto print_stock; } @@ -279,9 +265,7 @@ char in_a_shop( char shoppy, id_arr id ) if (ft == '?' || ft == '*') { - shop_uninit_id(shoppy, shop_id); invent(-1, false); - shop_init_id(shoppy, shop_id); goto print_stock; } @@ -305,7 +289,7 @@ char in_a_shop( char shoppy, id_arr id ) goto purchase; } - gp_value = greedy * item_value( mitm[shop_items[ft]], id ) / 10; + gp_value = the_shop.greed * item_value(mitm[shop_items[ft]], id_stock)/10; if (gp_value > you.gold) { @@ -317,103 +301,36 @@ char in_a_shop( char shoppy, id_arr id ) mitm[shop_items[ft]].name(DESC_NOCAP_A).c_str(), gp_value); shop_print(info, 20); if ( yesno(NULL, true, 'n', false, false, true) ) - { - shop_set_ident_type( shoppy, shop_id, mitm[shop_items[ft]].base_type, - mitm[shop_items[ft]].sub_type ); + { + if ( id_stock ) + { + // Identify the item and its type. + item_def& pitem = mitm[shop_items[ft]]; + set_ident_type(pitem.base_type, pitem.sub_type, ID_KNOWN_TYPE); + set_ident_flags(pitem, ISFLAG_IDENT_MASK); + } + // purchase() will take the note if necessary. purchase( shoppy, shop_items[ft], gp_value ); } goto print_stock; goodbye: - //clear_line(); shop_print("Goodbye!", 20); more3(); - shop_uninit_id( shoppy, shop_id ); activate_notes(true); - return 0; -} - -void shop_init_id_type(int shoptype, id_fix_arr &shop_id) -{ - if (shoptype != SHOP_WEAPON_ANTIQUE - && shoptype != SHOP_ARMOUR_ANTIQUE - && shoptype != SHOP_GENERAL_ANTIQUE) - { - for (int j = 0; j < 50; j++) - { - shop_id[ IDTYPE_WANDS ][j] = get_ident_type(OBJ_WANDS, j); - set_ident_type(OBJ_WANDS, j, ID_KNOWN_TYPE); - - shop_id[ IDTYPE_SCROLLS ][j] = get_ident_type(OBJ_SCROLLS, j); - set_ident_type(OBJ_SCROLLS, j, ID_KNOWN_TYPE); - - shop_id[ IDTYPE_JEWELLERY ][j] = get_ident_type(OBJ_JEWELLERY, j); - set_ident_type(OBJ_JEWELLERY, j, ID_KNOWN_TYPE); - - shop_id[ IDTYPE_POTIONS ][j] = get_ident_type(OBJ_POTIONS, j); - set_ident_type(OBJ_POTIONS, j, ID_KNOWN_TYPE); - } - } -} - -static void shop_init_id(int i, id_fix_arr &shop_id) -{ - shop_init_id_type( env.shop[i].type, shop_id ); -} - -void shop_uninit_id_type(int shoptype, const id_fix_arr &shop_id) -{ - if (shoptype != SHOP_WEAPON_ANTIQUE - && shoptype != SHOP_ARMOUR_ANTIQUE - && shoptype != SHOP_GENERAL_ANTIQUE) - { - for (int j = 0; j < 50; j++) - { - set_ident_type( OBJ_WANDS, j, - shop_id[ IDTYPE_WANDS ][j], true ); - set_ident_type( OBJ_SCROLLS, j, - shop_id[ IDTYPE_SCROLLS ][j], true ); - set_ident_type( OBJ_JEWELLERY, j, - shop_id[ IDTYPE_JEWELLERY ][j], true ); - set_ident_type( OBJ_POTIONS, j, - shop_id[ IDTYPE_POTIONS ][j], true ); - } - } -} - -static void shop_uninit_id(int i, const id_fix_arr &shop_id) -{ - shop_uninit_id_type(env.shop[i].type, shop_id); } -void shop_set_ident_type( int i, id_fix_arr &shop_id, - unsigned char base_type, unsigned char sub_type ) +bool shoptype_identifies_stock(int shoptype) { - if (env.shop[i].type != SHOP_WEAPON_ANTIQUE - && env.shop[i].type != SHOP_ARMOUR_ANTIQUE - && env.shop[i].type != SHOP_GENERAL_ANTIQUE) - { - switch (base_type) - { - case OBJ_WANDS: - shop_id[ IDTYPE_WANDS ][sub_type] = ID_KNOWN_TYPE; - break; - case OBJ_SCROLLS: - shop_id[ IDTYPE_SCROLLS ][sub_type] = ID_KNOWN_TYPE; - break; - case OBJ_JEWELLERY: - shop_id[ IDTYPE_JEWELLERY ][sub_type] = ID_KNOWN_TYPE; - break; - case OBJ_POTIONS: - shop_id[ IDTYPE_POTIONS ][sub_type] = ID_KNOWN_TYPE; - break; - } - } + return + shoptype != SHOP_WEAPON_ANTIQUE && + shoptype != SHOP_ARMOUR_ANTIQUE && + shoptype != SHOP_GENERAL_ANTIQUE; } -void shop_print( const char *shoppy, char sh_lines ) +static void shop_print( const char *shoppy, int sh_lines ) { gotoxy(1, sh_lines); @@ -423,7 +340,7 @@ void shop_print( const char *shoppy, char sh_lines ) cprintf(" "); } -char more3(void) +static char more3() { char keyin = 0; @@ -574,7 +491,7 @@ int randart_value( const item_def &item ) return ((ret > 0) ? ret : 0); } -unsigned int item_value( item_def item, id_arr id, bool ident ) +unsigned int item_value( item_def item, bool ident ) { // Note that we pass item in by value, since we want a local // copy to mangle as necessary... maybe that should be fixed, @@ -1134,8 +1051,7 @@ unsigned int item_value( item_def item, id_arr id, bool ident ) else valued += 50; } - else if (item_type_known(item) - && get_equip_desc(item) != 0) + else if (item_type_known(item) && get_equip_desc(item) != 0) { valued += 20; } @@ -1148,7 +1064,7 @@ unsigned int item_value( item_def item, id_arr id, bool ident ) break; case OBJ_WANDS: - if (!id[ IDTYPE_WANDS ][item.sub_type]) + if ( !item_type_known(item) ) valued += 200; else { @@ -1217,7 +1133,7 @@ unsigned int item_value( item_def item, id_arr id, bool ident ) break; case OBJ_POTIONS: - if (!id[3][item.sub_type]) + if ( !item_type_known(item) ) valued += 9; else { @@ -1328,9 +1244,10 @@ unsigned int item_value( item_def item, id_arr id, bool ident ) break; case OBJ_SCROLLS: - if (!id[1][item.sub_type]) + if ( !item_type_known(item) ) valued += 10; else + { switch (item.sub_type) { case SCR_ACQUIREMENT: @@ -1383,16 +1300,16 @@ unsigned int item_value( item_def item, id_arr id, bool ident ) valued++; break; } + } break; case OBJ_JEWELLERY: - if (!id[2][item.sub_type]) - valued += 50; - if (item_cursed( item )) valued -= 10; - if (id[2][item.sub_type] > 0) + if ( !item_type_known(item) ) + valued += 50; + else { if (item_ident( item, ISFLAG_KNOW_PLUSES ) && (item.sub_type == RING_PROTECTION @@ -1484,17 +1401,12 @@ unsigned int item_value( item_def item, id_arr id, bool ident ) if (is_random_artefact(item)) { - if (item_type_known(item)) - { - if (valued < 0) - valued = randart_value( item ) - 5; - else - valued += randart_value( item ); - } + // in this branch we're guaranteed to know + // the item type! + if (valued < 0) + valued = randart_value( item ) - 5; else - { - valued += 50; - } + valued += randart_value( item ); } valued *= 7; @@ -1554,11 +1466,10 @@ unsigned int item_value( item_def item, id_arr id, bool ident ) } break; - //case 10: break; - case OBJ_BOOKS: - valued = 150 + (item_type_known(item) - ? book_rarity(item.sub_type) * 50 : 0); + valued = 150; + if (item_type_known(item)) + valued += book_rarity(item.sub_type) * 50; break; case OBJ_STAVES: @@ -1592,9 +1503,9 @@ unsigned int item_value( item_def item, id_arr id, bool ident ) return (valued); } // end item_value() -void shop(void) +void shop() { - unsigned char i = 0; + int i; for (i = 0; i < MAX_SHOPS; i++) { @@ -1604,18 +1515,11 @@ void shop(void) if (i == MAX_SHOPS) { - mpr("Help! Non-existent shop."); + mpr("Help! Non-existent shop.", MSGCH_DANGER); return; } - id_arr identy; - - save_id(identy); - - { - shopping_hup_protect shp; - in_a_shop(i, identy); - } + in_a_shop(i); you.redraw_gold = 1; burden_change(); diff --git a/crawl-ref/source/shopping.h b/crawl-ref/source/shopping.h index 39e9c48a4c..e04c841321 100644 --- a/crawl-ref/source/shopping.h +++ b/crawl-ref/source/shopping.h @@ -17,26 +17,12 @@ #include "externs.h" #include "itemname.h" -void shop_init_id_type(int shoptype, id_fix_arr &shop_id); -void shop_uninit_id_type(int shoptype, const id_fix_arr &shop_id); - int randart_value( const item_def &item ); -// last updated 12may2000 {dlb} -/* *********************************************************************** - * called from: chardump - invent - ouch - religion - shopping - * *********************************************************************** */ - // ident == true overrides the item ident level and gives the price // as if the item was fully id'd -unsigned int item_value( item_def item, id_arr id, bool ident = false ); - - -// last updated 12may2000 {dlb} -/* *********************************************************************** - * called from: misc - * *********************************************************************** */ -void shop(void); +unsigned int item_value( item_def item, bool ident = false ); +void shop(); const shop_struct *get_shop(int sx, int sy); @@ -46,25 +32,6 @@ const shop_struct *get_shop(int sx, int sy); * *********************************************************************** */ const char *shop_name(int sx, int sy); -// Protect the id array against being clobbered by a SIGHUP with the -// character in a shop. -extern id_arr shop_backup_id; -class shopping_hup_protect -{ -public: - shopping_hup_protect() : shopping(crawl_state.shopping) - { - save_id(shop_backup_id); - crawl_state.shopping = true; - } - - ~shopping_hup_protect() - { - crawl_state.shopping = shopping; - } - -private: - bool shopping; -}; +bool shoptype_identifies_stock(int shoptype); #endif diff --git a/crawl-ref/source/stash.cc b/crawl-ref/source/stash.cc index fd0ead410b..c8f7806990 100644 --- a/crawl-ref/source/stash.cc +++ b/crawl-ref/source/stash.cc @@ -635,17 +635,6 @@ ShopInfo::ShopInfo(int xp, int yp) : x(xp), y(yp), name(), shoptype(-1), shoptype = sh->type; } -ShopInfo::ShopId::ShopId(int stype) - : shopping_hup_protect(), shoptype(stype), id() -{ - shop_init_id_type( shoptype, id ); -} - -ShopInfo::ShopId::~ShopId() -{ - shop_uninit_id_type( shoptype, id ); -} - void ShopInfo::add_item(const item_def &sitem, unsigned price) { shop_item it; @@ -657,18 +646,31 @@ void ShopInfo::add_item(const item_def &sitem, unsigned price) std::string ShopInfo::shop_item_name(const shop_item &si) const { char shopitem[ITEMNAME_SIZE * 2]; - std::string itemname = Stash::stash_item_name(si.item); + + // mangle a temporary + item_def temp_item = si.item; + if ( shoptype_identifies_stock(this->shoptype) ) + temp_item.flags |= ISFLAG_IDENT_MASK; + + const std::string itemname = Stash::stash_item_name(temp_item); snprintf(shopitem, sizeof shopitem, "%s (%u gold)", itemname.c_str(), si.price); - return shopitem; + + return shopitem; } std::string ShopInfo::shop_item_desc(const shop_item &si) const { std::string desc; - if (is_dumpable_artifact(si.item, Options.verbose_dump)) + + // mangle a temporary + item_def temp_item = si.item; + if (shoptype_identifies_stock(this->shoptype)) + temp_item.flags |= ISFLAG_IDENT_MASK; + + if (is_dumpable_artifact(temp_item, Options.verbose_dump)) { - desc = munge_description(get_item_description(si.item, + desc = munge_description(get_item_description(temp_item, Options.verbose_dump, true)); trim_string(desc); @@ -683,13 +685,16 @@ std::string ShopInfo::shop_item_desc(const shop_item &si) const void ShopInfo::describe_shop_item(const shop_item &si) const { - describe_item( si.item ); + // mangle a temporary + item_def temp_item = si.item; + if ( shoptype_identifies_stock(this->shoptype) ) + temp_item.flags |= ISFLAG_IDENT_MASK; + describe_item( temp_item ); } bool ShopInfo::show_menu(const std::string &place, bool can_travel) const { - ShopId id(shoptype); StashMenu menu; MenuEntry *mtitle = new MenuEntry(name + " (" + place, MEL_TITLE); @@ -749,7 +754,6 @@ bool ShopInfo::matches_search(const std::string &prefix, { if (items.empty() && visited) return false; - ShopId id(shoptype); bool match = false; for (unsigned i = 0; i < items.size(); ++i) @@ -800,8 +804,6 @@ bool ShopInfo::matches_search(const std::string &prefix, void ShopInfo::write(std::ostream &os, bool identify) const { - ShopId id(shoptype); - os << "[Shop] " << name << std::endl; if (items.size() > 0) { diff --git a/crawl-ref/source/stash.h b/crawl-ref/source/stash.h index c384041191..2a8becbce6 100644 --- a/crawl-ref/source/stash.h +++ b/crawl-ref/source/stash.h @@ -140,7 +140,7 @@ private: // Messy! struct shop_item { - item_def item; + item_def item; unsigned price; }; std::vector<shop_item> items; @@ -148,16 +148,6 @@ private: std::string shop_item_name(const shop_item &si) const; std::string shop_item_desc(const shop_item &si) const; void describe_shop_item(const shop_item &si) const; - - class ShopId : public shopping_hup_protect - { - public: - ShopId(int stype); - ~ShopId(); - private: - int shoptype; - id_fix_arr id; - }; }; struct stash_search_result diff --git a/crawl-ref/source/tags.cc b/crawl-ref/source/tags.cc index 6cebd63dc1..d966ec3efc 100644 --- a/crawl-ref/source/tags.cc +++ b/crawl-ref/source/tags.cc @@ -867,22 +867,15 @@ static void tag_construct_you_items(struct tagHeader &th) } // identification status + const id_arr& identy(get_typeid_array()); // how many types? - marshallByte(th, 4); + marshallByte(th, static_cast<char>(identy.width())); // how many subtypes? - marshallByte(th, 50); - - // this is really dumb. We copy the id[] array from itemname - // to the stack, for no good reason that I can see. - id_arr identy; - - save_id(identy, true); + marshallByte(th, static_cast<char>(identy.height())); - for (i = 0; i < 4; ++i) - { - for (j = 0; j < 50; ++j) - marshallByte(th, identy[i][j]); - } + for (i = 0; i < identy.width(); ++i) + for (j = 0; j < identy.height(); ++j) + marshallByte(th, static_cast<char>(identy[i][j])); // how many unique items? marshallByte(th, 50); @@ -1198,8 +1191,8 @@ static void tag_read_you_items(struct tagHeader &th, char minorVersion) { for (j = 0; j < count_c2; ++j) { - char ch; - ch = unmarshallByte(th); + const item_type_id_state_type ch = + static_cast<item_type_id_state_type>(unmarshallByte(th)); switch (i) { |