From fac344b62ebbf48e7b1d2a7b5f0bcdd3608bd4a7 Mon Sep 17 00:00:00 2001 From: haranp Date: Sat, 21 Apr 2007 16:18:19 +0000 Subject: Eliminated it_name(), in_name(), item_name(). The function to use is now item_def::name(). Cleaned up a lot of code in the process. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@1341 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/acr.cc | 12 +- crawl-ref/source/beam.cc | 1 - crawl-ref/source/chardump.cc | 6 +- crawl-ref/source/clua.cc | 9 +- crawl-ref/source/command.cc | 35 +-- crawl-ref/source/debug.cc | 45 ++-- crawl-ref/source/delay.cc | 29 +-- crawl-ref/source/describe.cc | 14 +- crawl-ref/source/direct.cc | 25 +-- crawl-ref/source/effects.cc | 23 +- crawl-ref/source/externs.h | 5 + crawl-ref/source/fight.cc | 8 +- crawl-ref/source/food.cc | 30 +-- crawl-ref/source/hiscores.cc | 3 +- crawl-ref/source/invent.cc | 23 +- crawl-ref/source/it_use2.cc | 4 +- crawl-ref/source/it_use3.cc | 43 ++-- crawl-ref/source/item_use.cc | 189 ++++++---------- crawl-ref/source/itemname.cc | 512 +++++++++++++++++++------------------------ crawl-ref/source/itemname.h | 30 +-- crawl-ref/source/itemprop.cc | 14 +- crawl-ref/source/items.cc | 95 ++++---- crawl-ref/source/makeitem.cc | 2 +- crawl-ref/source/mon-util.cc | 19 +- crawl-ref/source/mon-util.h | 11 +- crawl-ref/source/monstuff.cc | 66 ++---- crawl-ref/source/mstuff2.cc | 7 +- crawl-ref/source/newgame.cc | 4 +- crawl-ref/source/ouch.cc | 38 ++-- crawl-ref/source/output.cc | 40 ++-- crawl-ref/source/religion.cc | 19 +- crawl-ref/source/shopping.cc | 31 ++- crawl-ref/source/spells1.cc | 4 +- crawl-ref/source/spells2.cc | 4 +- crawl-ref/source/spells3.cc | 18 +- crawl-ref/source/spells4.cc | 19 +- crawl-ref/source/spl-book.cc | 4 +- crawl-ref/source/spl-cast.cc | 15 +- crawl-ref/source/stash.cc | 5 +- crawl-ref/source/transfor.cc | 8 +- crawl-ref/source/travel.cc | 4 +- 41 files changed, 583 insertions(+), 890 deletions(-) (limited to 'crawl-ref') diff --git a/crawl-ref/source/acr.cc b/crawl-ref/source/acr.cc index e711d91f4c..5b1adf5913 100644 --- a/crawl-ref/source/acr.cc +++ b/crawl-ref/source/acr.cc @@ -452,16 +452,15 @@ static void handle_wizard_command( void ) make_item_randart( you.inv[i] ); - // if equiped, apply new randart benefits + // if equipped, apply new randart benefits if (j != NUM_EQUIP) use_randart( i ); - item_name( you.inv[i], DESC_INVENTORY_EQUIP, info ); - mpr( info ); + mpr( you.inv[i].name(DESC_INVENTORY_EQUIP).c_str() ); break; case '|': - // create all unrand arts + // create all unrandarts for (tmp = 1; tmp < NO_UNRANDARTS; tmp++) { int islot = get_item_slot(); @@ -1640,11 +1639,8 @@ static void decrement_durations() you.duration[DUR_WEAPON_BRAND] = 0; - char str_pass[ITEMNAME_SIZE]; - set_item_ego_type( you.inv[wpn], OBJ_WEAPONS, SPWPN_NORMAL ); - in_name(wpn, DESC_CAP_YOUR, str_pass); - strncpy(info, str_pass, INFO_SIZE); + strncpy(info, you.inv[wpn].name(DESC_CAP_YOUR).c_str(), INFO_SIZE); switch (temp_effect) { diff --git a/crawl-ref/source/beam.cc b/crawl-ref/source/beam.cc index d24e07551f..38dbf92dac 100644 --- a/crawl-ref/source/beam.cc +++ b/crawl-ref/source/beam.cc @@ -37,7 +37,6 @@ #include "effects.h" #include "enum.h" #include "it_use2.h" -#include "itemname.h" #include "items.h" #include "itemprop.h" #include "misc.h" diff --git a/crawl-ref/source/chardump.cc b/crawl-ref/source/chardump.cc index f7deb16869..85d3bb1359 100644 --- a/crawl-ref/source/chardump.cc +++ b/crawl-ref/source/chardump.cc @@ -38,7 +38,6 @@ #include "debug.h" #include "describe.h" #include "hiscores.h" -#include "itemname.h" #include "itemprop.h" #include "items.h" #include "macro.h" @@ -637,7 +636,6 @@ static void sdump_inventory(const std::string &, std::string & text) } } - char st_pass[ ITEMNAME_SIZE ] = ""; int inv_class2[OBJ_GOLD]; int inv_count = 0; char tmp_quant[20]; @@ -697,9 +695,7 @@ static void sdump_inventory(const std::string &, std::string & text) if (is_valid_item(you.inv[j]) && you.inv[j].base_type == i) { text += " "; - - in_name( j, DESC_INVENTORY_EQUIP, st_pass ); - text += st_pass; + text += you.inv[j].name(DESC_INVENTORY_EQUIP); inv_count--; diff --git a/crawl-ref/source/clua.cc b/crawl-ref/source/clua.cc index 326a91ff73..634d4e2740 100644 --- a/crawl-ref/source/clua.cc +++ b/crawl-ref/source/clua.cc @@ -1158,7 +1158,7 @@ static int l_item_worn(lua_State *ls) return (2); } -static int desc_code(const char *desc) +static description_level_type desc_code(const char *desc) { if (!desc) return DESC_PLAIN; @@ -1190,14 +1190,11 @@ static int l_item_name(lua_State *ls) LUA_ITEM(item, 1); if (item) { - int ndesc = DESC_PLAIN; + description_level_type ndesc = DESC_PLAIN; if (lua_isstring(ls, 2)) ndesc = desc_code(lua_tostring(ls, 2)); bool terse = lua_toboolean(ls, 3); - char bufitemname[ITEMNAME_SIZE]; - item_name(*item, ndesc, bufitemname, terse); - - lua_pushstring(ls, bufitemname); + lua_pushstring(ls, item->name(ndesc, terse).c_str()); } else lua_pushnil(ls); diff --git a/crawl-ref/source/command.cc b/crawl-ref/source/command.cc index ad79d1168d..85e7c61c5a 100644 --- a/crawl-ref/source/command.cc +++ b/crawl-ref/source/command.cc @@ -122,15 +122,10 @@ void swap_inv_slots(int from_slot, int to_slot, bool verbose) if (verbose) { - char str_pass[ ITEMNAME_SIZE ]; - in_name( to_slot, DESC_INVENTORY_EQUIP, str_pass ); - mpr( str_pass ); + mpr( you.inv[to_slot].name(DESC_INVENTORY_EQUIP).c_str() ); if (is_valid_item( you.inv[from_slot] )) - { - in_name( from_slot, DESC_INVENTORY_EQUIP, str_pass ); - mpr( str_pass ); - } + mpr( you.inv[from_slot].name(DESC_INVENTORY_EQUIP).c_str() ); } if (to_slot == you.equip[EQ_WEAPON] || from_slot == you.equip[EQ_WEAPON]) @@ -140,7 +135,6 @@ void swap_inv_slots(int from_slot, int to_slot, bool verbose) static void adjust_item(void) { int from_slot, to_slot; - char str_pass[ ITEMNAME_SIZE ]; if (inv_count() < 1) { @@ -155,8 +149,7 @@ static void adjust_item(void) return; } - in_name( from_slot, DESC_INVENTORY_EQUIP, str_pass ); - mpr( str_pass ); + mpr(you.inv[from_slot].name(DESC_INVENTORY_EQUIP).c_str()); to_slot = prompt_invent_item( "Adjust to which letter?", @@ -458,9 +451,7 @@ void list_armour(void) if (armour_id != -1) { - char str_pass[ ITEMNAME_SIZE ]; - in_name(armour_id, DESC_INVENTORY, str_pass); - strcat(info, str_pass); + strcat(info, you.inv[armour_id].name(DESC_INVENTORY).c_str()); } else { @@ -486,9 +477,7 @@ void list_jewellery(void) if (jewellery_id != -1) { - char str_pass[ ITEMNAME_SIZE ]; - in_name(jewellery_id, DESC_INVENTORY, str_pass); - strcat(info, str_pass); + strcat(info, you.inv[jewellery_id].name(DESC_INVENTORY).c_str()); } else { @@ -511,9 +500,7 @@ void list_weapons(void) if (weapon_id != -1) { - char str_pass[ ITEMNAME_SIZE ]; - in_name( weapon_id, DESC_INVENTORY_EQUIP, str_pass ); - strcat(info, str_pass); + strcat(info, you.inv[weapon_id].name(DESC_INVENTORY_EQUIP).c_str()); } else { @@ -537,9 +524,7 @@ void list_weapons(void) if (is_valid_item( you.inv[i] )) { - char str_pass[ ITEMNAME_SIZE ]; - in_name(i, DESC_INVENTORY_EQUIP, str_pass); - strcat(info, str_pass); + strcat(info, you.inv[i].name(DESC_INVENTORY_EQUIP).c_str()); } else strcat(info, " none"); @@ -555,11 +540,7 @@ void list_weapons(void) if (item == ENDOFPACK) strcat(info, " nothing"); else - { - char str_pass[ ITEMNAME_SIZE ]; - in_name( item, DESC_INVENTORY_EQUIP, str_pass ); - strcat( info, str_pass ); - } + strcat(info, you.inv[item].name(DESC_INVENTORY_EQUIP).c_str()); mpr( info, MSGCH_EQUIPMENT, menu_colour(info) ); } // end list_weapons() diff --git a/crawl-ref/source/debug.cc b/crawl-ref/source/debug.cc index 2243dabc0e..90792b5b7e 100644 --- a/crawl-ref/source/debug.cc +++ b/crawl-ref/source/debug.cc @@ -655,8 +655,8 @@ void create_spec_object() for (i = 0; i < max_subtype[ mitm[thing_created].base_type ]; i++) { - mitm[thing_created].sub_type = i; - item_name( mitm[thing_created], DESC_PLAIN, obj_name ); + mitm[thing_created].sub_type = i; + strcpy(obj_name,mitm[thing_created].name(DESC_PLAIN).c_str()); ptr = strstr( strlwr(obj_name), strlwr(specs) ); if (ptr != NULL) @@ -705,7 +705,8 @@ void create_spec_object() for (i = 1; i < 25; i++) { mitm[thing_created].special = i; - item_name( mitm[thing_created], DESC_PLAIN, obj_name ); + strcpy(obj_name, + mitm[thing_created].name(DESC_PLAIN).c_str()); ptr = strstr( strlwr(obj_name), strlwr(specs) ); if (ptr != NULL) @@ -803,8 +804,7 @@ void tweak_object(void) for (;;) { - item_name( you.inv[item], DESC_INVENTORY_EQUIP, info ); - mpr( info ); + mpr( you.inv[item].name(DESC_INVENTORY_EQUIP).c_str() ); mpr( "a - plus b - plus2 c - special d - quantity e - flags ESC - exit", MSGCH_PROMPT ); @@ -1066,10 +1066,9 @@ void debug_item_scan( void ) // Check for invalid (zero quantity) items that are linked in if (!is_valid_item( mitm[obj] )) { - snprintf( info, INFO_SIZE, "Linked invalid item at (%d,%d)!", x, y); - mpr( info, MSGCH_WARN ); - item_name( mitm[obj], DESC_PLAIN, name ); - dump_item( name, obj, mitm[obj] ); + mprf(MSGCH_WARN, "Linked invalid item at (%d,%d)!", x, y); + dump_item( mitm[obj].name(DESC_PLAIN).c_str(), + obj, mitm[obj] ); } // Check that item knows what stack it's in @@ -1077,8 +1076,8 @@ void debug_item_scan( void ) { snprintf( info, INFO_SIZE, "Item position incorrect at (%d,%d)!", x, y); mpr( info, MSGCH_WARN ); - item_name( mitm[obj], DESC_PLAIN, name ); - dump_item( name, obj, mitm[obj] ); + dump_item( mitm[obj].name(DESC_PLAIN).c_str(), + obj, mitm[obj] ); } // If we run into a premarked item we're in real trouble, @@ -1101,7 +1100,7 @@ void debug_item_scan( void ) if (!is_valid_item( mitm[i] )) continue; - item_name( mitm[i], DESC_PLAIN, name ); + strcpy(name, mitm[i].name(DESC_PLAIN).c_str()); // Don't check (-1,-1) player items or (0,0) monster items if ((mitm[i].x > 0 || mitm[i].y > 0) @@ -1670,11 +1669,11 @@ static std::string fsim_wskill() static std::string fsim_weapon(int missile_slot) { - char item_buf[ITEMNAME_SIZE]; + std::string item_buf; if (you.equip[EQ_WEAPON] != -1) { const item_def &weapon = you.inv[ you.equip[EQ_WEAPON] ]; - item_name(weapon, DESC_PLAIN, item_buf, true); + item_buf = weapon.name(DESC_PLAIN, true); if (is_range_weapon(weapon)) { @@ -1682,19 +1681,14 @@ static std::string fsim_weapon(int missile_slot) missile_slot == -1? get_fire_item_index() : missile_slot; if (missile < ENDOFPACK) - { - std::string base = item_buf; - base += " with "; - in_name(missile, DESC_PLAIN, item_buf, true); - return (base + item_buf); - } + return item_buf+" with "+you.inv[missile].name(DESC_PLAIN); } } else { - strncpy(item_buf, "unarmed", sizeof item_buf); + return "unarmed"; } - return (item_buf); + return item_buf; } static std::string fsim_time_string() @@ -1903,7 +1897,6 @@ static bool debug_fight_sim(int mindex, int missile_slot, int fsim_kit_equip(const std::string &kit) { int missile_slot = -1; - char item_buf[ITEMNAME_SIZE]; std::string::size_type ammo_div = kit.find("/"); std::string weapon = kit; @@ -1921,8 +1914,7 @@ int fsim_kit_equip(const std::string &kit) if (!is_valid_item(you.inv[i])) continue; - in_name(i, DESC_PLAIN, item_buf, true); - if (std::string(item_buf).find(weapon) != std::string::npos) + if (you.inv[i].name(DESC_PLAIN).find(weapon) != std::string::npos) { if (i != you.equip[EQ_WEAPON]) { @@ -1941,8 +1933,7 @@ int fsim_kit_equip(const std::string &kit) if (!is_valid_item(you.inv[i])) continue; - in_name(i, DESC_PLAIN, item_buf, true); - if (std::string(item_buf).find(missile) != std::string::npos) + if (you.inv[i].name(DESC_PLAIN).find(missile)!=std::string::npos) { missile_slot = i; break; diff --git a/crawl-ref/source/delay.cc b/crawl-ref/source/delay.cc index c20494879e..5d3fc4334f 100644 --- a/crawl-ref/source/delay.cc +++ b/crawl-ref/source/delay.cc @@ -278,8 +278,6 @@ bool is_being_butchered(const item_def &item) void handle_delay( void ) /***********************/ { - char str_pass[ ITEMNAME_SIZE ]; - if (!you_are_delayed()) return; @@ -373,16 +371,12 @@ void handle_delay( void ) switch ( delay.type ) { case DELAY_ARMOUR_ON: - in_name( delay.parm1, DESC_NOCAP_YOUR, str_pass ); - snprintf( info, INFO_SIZE, - "You continue putting on %s.", str_pass ); - mpr(info, MSGCH_MULTITURN_ACTION); + mprf(MSGCH_MULTITURN_ACTION, "You continue putting on %s.", + you.inv[delay.parm1].name(DESC_NOCAP_YOUR).c_str()); break; case DELAY_ARMOUR_OFF: - in_name( delay.parm1, DESC_NOCAP_YOUR, str_pass ); - snprintf( info, INFO_SIZE, - "You continue taking off %s.", str_pass ); - mpr(info, MSGCH_MULTITURN_ACTION); + mprf(MSGCH_MULTITURN_ACTION, "You continue taking off %s.", + you.inv[delay.parm1].name(DESC_NOCAP_YOUR).c_str()); break; case DELAY_BUTCHER: mpr("You continue butchering the corpse.", @@ -413,7 +407,6 @@ void handle_delay( void ) static void finish_delay(const delay_queue_item &delay) { - char str_pass[ ITEMNAME_SIZE ]; switch (delay.type) { case DELAY_WEAPON_SWAP: @@ -430,9 +423,8 @@ static void finish_delay(const delay_queue_item &delay) case DELAY_ARMOUR_OFF: { - in_name( delay.parm1, DESC_NOCAP_YOUR, str_pass ); - snprintf( info, INFO_SIZE, "You finish taking off %s.", str_pass ); - mpr(info); + mprf("You finish taking off %s.", + you.inv[delay.parm1].name(DESC_NOCAP_YOUR).c_str()); const equipment_type slot = get_armour_slot( you.inv[delay.parm1] ); @@ -585,10 +577,9 @@ static void finish_delay(const delay_queue_item &delay) } else { - quant_name( you.inv[ delay.parm1 ], delay.parm2, - DESC_NOCAP_A, str_pass ); - - snprintf( info, INFO_SIZE, "You drop %s.", str_pass ); + snprintf( info, INFO_SIZE, "You drop %s.", + quant_name(you.inv[delay.parm1], delay.parm2, + DESC_NOCAP_A).c_str()); mpr(info); dec_inv_item_quantity( delay.parm1, delay.parm2 ); @@ -626,7 +617,7 @@ static void armour_wear_effects(const int item_slot) item_def &arm = you.inv[item_slot]; set_ident_flags(arm, ISFLAG_EQ_ARMOUR_MASK ); - mprf("You finish putting on %s.", item_name(arm, DESC_NOCAP_YOUR)); + mprf("You finish putting on %s.", arm.name(DESC_NOCAP_YOUR).c_str()); const equipment_type eq_slot = get_armour_slot(arm); diff --git a/crawl-ref/source/describe.cc b/crawl-ref/source/describe.cc index 834d58f378..7bff89c355 100644 --- a/crawl-ref/source/describe.cc +++ b/crawl-ref/source/describe.cc @@ -3228,11 +3228,7 @@ std::string get_item_description( const item_def &item, bool verbose, bool dump description.reserve(500); if (!dump) - { - char str_pass[ ITEMNAME_SIZE ]; - item_name( item, DESC_INVENTORY_EQUIP, str_pass ); - description += std::string(str_pass); - } + description += item.name(DESC_INVENTORY_EQUIP); description += "$$"; @@ -4878,13 +4874,11 @@ void describe_monsters(int class_described, unsigned char which_mons) has_item = true; } - char buff[ ITEMNAME_SIZE ]; - + // duplicate it, because we're going to change it item_def item = mitm[ menv[which_mons].inv[i] ]; set_ident_flags( item, ISFLAG_IDENT_MASK ); - - item_name( item, DESC_NOCAP_A, buff ); - snprintf( info, INFO_SIZE, " %d: %s$", i, buff ); + snprintf( info, INFO_SIZE, " %d: %s$", i, + item.name(DESC_NOCAP_A).c_str() ); description += info; } } diff --git a/crawl-ref/source/direct.cc b/crawl-ref/source/direct.cc index d5b8bb8dbc..aeb942f947 100644 --- a/crawl-ref/source/direct.cc +++ b/crawl-ref/source/direct.cc @@ -1456,8 +1456,7 @@ static void describe_mons_enchantment(const monsters &mons, static void describe_cell(int mx, int my) { - char str_pass[ ITEMNAME_SIZE ]; - bool mimic_item = false; + bool mimic_item = false; if (mgrd[mx][my] != NON_MONSTER) { @@ -1485,21 +1484,18 @@ static void describe_cell(int mx, int my) if (menv[i].type != MONS_DANCING_WEAPON && mon_wep != NON_ITEM) { - snprintf( info, INFO_SIZE, "%s is wielding ", - mons_pronoun( menv[i].type, PRONOUN_CAP )); - it_name(mon_wep, DESC_NOCAP_A, str_pass); - strcat(info, str_pass); + snprintf( info, INFO_SIZE, "%s is wielding %s", + mons_pronoun( menv[i].type, PRONOUN_CAP ), + mitm[mon_wep].name(DESC_NOCAP_A).c_str()); // 2-headed ogres can wield 2 weapons - if ((menv[i].type == MONS_TWO_HEADED_OGRE - || menv[i].type == MONS_ETTIN) + if ((menv[i].type == MONS_TWO_HEADED_OGRE + || menv[i].type == MONS_ETTIN) && menv[i].inv[MSLOT_MISSILE] != NON_ITEM) { - strcat( info, " and " ); - it_name(menv[i].inv[MSLOT_MISSILE], DESC_NOCAP_A, str_pass); - strcat(info, str_pass); + strcat(info, " and " ); + strcat(info, mitm[menv[i].inv[MSLOT_MISSILE]].name(DESC_NOCAP_A).c_str()); strcat(info, "."); - mpr(info); } else @@ -1512,8 +1508,7 @@ static void describe_cell(int mx, int my) if (mon_arm != NON_ITEM) mprf("%s is wearing %s.", mons_pronoun(menv[i].type, PRONOUN_CAP), - it_name(mon_arm, DESC_NOCAP_A, str_pass)); - + mitm[mon_arm].name(DESC_NOCAP_A).c_str()); if (menv[i].type == MONS_HYDRA) mprf("It has %d head%s.", menv[i].number, @@ -1590,7 +1585,7 @@ static void describe_cell(int mx, int my) mprf( MSGCH_FLOOR_ITEMS, "A pile of gold coins." ); else mprf( MSGCH_FLOOR_ITEMS, "You see %s here.", - it_name(targ_item, DESC_NOCAP_A, str_pass)); + mitm[targ_item].name(DESC_NOCAP_A).c_str()); if (mitm[ targ_item ].link != NON_ITEM) mprf( MSGCH_FLOOR_ITEMS, diff --git a/crawl-ref/source/effects.cc b/crawl-ref/source/effects.cc index fd82b37e24..cf25b6d3af 100644 --- a/crawl-ref/source/effects.cc +++ b/crawl-ref/source/effects.cc @@ -376,11 +376,8 @@ void random_uselessness(unsigned char ru, unsigned char sc_read_2) switch (ru) { case 0: - strcpy(info, "The dust glows a "); weird_colours(random2(256), wc); - strcat(info, wc); - strcat(info, " colour!"); - mpr(info); + mprf("The dust glows a %s colour!", wc); break; case 1: @@ -391,14 +388,10 @@ void random_uselessness(unsigned char ru, unsigned char sc_read_2) case 2: if (you.equip[EQ_WEAPON] != -1) { - char str_pass[ ITEMNAME_SIZE ]; - in_name(you.equip[EQ_WEAPON], DESC_CAP_YOUR, str_pass); - strcpy(info, str_pass); - strcat(info, " glows "); weird_colours(random2(256), wc); - strcat(info, wc); - strcat(info, " for a moment."); - mpr(info); + mprf("%s glows %s for a moment.", + you.inv[you.equip[EQ_WEAPON]].name(DESC_CAP_YOUR).c_str(), + wc); } else { @@ -1479,9 +1472,7 @@ bool recharge_wand(void) break; } - char str_pass[ ITEMNAME_SIZE ]; - item_name(wand, DESC_CAP_YOUR, str_pass); - mprf("%s glows for a moment.", str_pass); + mprf("%s glows for a moment.", wand.name(DESC_CAP_YOUR).c_str()); wand.plus += 1 + random2avg( ((charge_gain - 1) * 3) + 1, 3 ); @@ -1512,9 +1503,7 @@ bool recharge_wand(void) if (!work) return (false); - char str_pass[ITEMNAME_SIZE]; - item_name( wand, DESC_CAP_YOUR, str_pass ); - mprf("%s glows for a moment.", str_pass); + mprf("%s glows for a moment.", wand.name(DESC_CAP_YOUR).c_str()); } you.wield_change = true; diff --git a/crawl-ref/source/externs.h b/crawl-ref/source/externs.h index c3edebce66..69b3d42291 100644 --- a/crawl-ref/source/externs.h +++ b/crawl-ref/source/externs.h @@ -430,10 +430,15 @@ struct item_def { } + std::string name(description_level_type descrip, + bool terse = false) const; + void clear() { *this = item_def(); } +private: + void name_aux( char* buff, bool terse ) const; }; class input_history diff --git a/crawl-ref/source/fight.cc b/crawl-ref/source/fight.cc index 0362cad36d..577b3afdbf 100644 --- a/crawl-ref/source/fight.cc +++ b/crawl-ref/source/fight.cc @@ -1011,8 +1011,7 @@ void melee_attack::player_weapon_auto_id() && random2(100) < you.skills[ wpn_skill ]) { set_ident_flags( *weapon, ISFLAG_KNOW_PLUSES ); - mprf("You are wielding %s.", - item_name(*weapon, DESC_NOCAP_A)); + mprf("You are wielding %s.", weapon->name(DESC_NOCAP_A).c_str()); more(); you.wield_change = true; } @@ -1980,8 +1979,7 @@ void melee_attack::player_apply_staff_damage() { set_ident_flags( *weapon, ISFLAG_KNOW_TYPE ); - mprf("You are wielding %s.", - item_name(*weapon, DESC_NOCAP_A)); + mprf("You are wielding %s.", weapon->name(DESC_NOCAP_A).c_str()); more(); you.wield_change = true; } @@ -2622,7 +2620,7 @@ std::string melee_attack::mons_attack_verb(const mon_attack_def &attk) std::string melee_attack::mons_weapon_desc() { if (weapon && attacker->id() != MONS_DANCING_WEAPON) - return make_stringf(" with %s", item_name(*weapon, DESC_NOCAP_A)); + return std::string(" with ") + weapon->name(DESC_NOCAP_A); return (""); } diff --git a/crawl-ref/source/food.cc b/crawl-ref/source/food.cc index ba6c1539d2..6b45115643 100644 --- a/crawl-ref/source/food.cc +++ b/crawl-ref/source/food.cc @@ -125,13 +125,10 @@ void weapon_switch( int targ ) } else { - char buff[80]; - in_name( targ, DESC_NOCAP_A, buff ); - - char let = index_to_letter( targ ); - - snprintf( info, INFO_SIZE, "Switching back to %c - %s.", let, buff ); - mpr( info ); + // XXX XXX FIXME Why not just use DESC_INVENTORY? + mprf("Switching back to %c - %s.", + index_to_letter(targ), + you.inv[targ].name(DESC_NOCAP_A).c_str()); } // unwield the old weapon and wield the new. @@ -193,8 +190,6 @@ static bool find_butchering_implement() bool butchery(void) { - char str_pass[ ITEMNAME_SIZE ]; - bool can_butcher = false; bool wpn_switch = false; bool new_cursed = false; @@ -250,8 +245,8 @@ bool butchery(void) found_nonzero_corpses = true; // offer the possibility of butchering - it_name(objl, DESC_NOCAP_A, str_pass); - snprintf(info, INFO_SIZE, "Butcher %s?", str_pass); + snprintf(info, INFO_SIZE, "Butcher %s?", + mitm[objl].name(DESC_NOCAP_A).c_str()); int answer = yesnoquit( info, true, 'n', false ); if ( answer == -1 ) { @@ -597,21 +592,20 @@ void eat_floor_item(int item_link) bool eat_from_floor(void) { - char str_pass[ ITEMNAME_SIZE ]; - if (player_is_levitating() && !wearing_amulet(AMU_CONTROLLED_FLIGHT)) return (false); bool need_more = false; for (int o = igrd[you.x_pos][you.y_pos]; o != NON_ITEM; o = mitm[o].link) { - if (mitm[o].base_type != OBJ_FOOD) + item_def& item = mitm[o]; + + if (item.base_type != OBJ_FOOD) continue; - it_name( o, DESC_NOCAP_A, str_pass ); mprf( MSGCH_PROMPT, - "Eat %s%s?", (mitm[o].quantity > 1) ? "one of " : "", - str_pass ); + "Eat %s%s?", (item.quantity > 1) ? "one of " : "", + item.name(DESC_NOCAP_A).c_str() ); // If we're prompting now, we don't need a -more- when // breaking out, because the prompt serves as a -more-. Of @@ -631,7 +625,7 @@ bool eat_from_floor(void) if (keyin == 'y') { - if (!can_ingest( mitm[o].base_type, mitm[o].sub_type, false )) + if (!can_ingest( item.base_type, item.sub_type, false )) { need_more = true; continue; diff --git a/crawl-ref/source/hiscores.cc b/crawl-ref/source/hiscores.cc index 34e78b0f31..09d66dc8fe 100644 --- a/crawl-ref/source/hiscores.cc +++ b/crawl-ref/source/hiscores.cc @@ -983,8 +983,7 @@ void scorefile_entry::init_death_cause(int dam, int dsrc, // Setting this is redundant for dancing weapons, however // we do care about the above indentification. -- bwr if (monster->type != MONS_DANCING_WEAPON) - auxkilldata = it_name( monster->inv[MSLOT_WEAPON], - DESC_NOCAP_A ); + auxkilldata = mitm[monster->inv[MSLOT_WEAPON]].name(DESC_NOCAP_A); } death_source_name = diff --git a/crawl-ref/source/invent.cc b/crawl-ref/source/invent.cc index 78d0aacf20..a00e69a77b 100644 --- a/crawl-ref/source/invent.cc +++ b/crawl-ref/source/invent.cc @@ -61,15 +61,19 @@ InvEntry::InvEntry( const item_def &i ) : MenuEntry( "", MEL_ITEM ), item( &i ) { data = const_cast( item ); - char buf[ITEMNAME_SIZE]; if (i.base_type == OBJ_GOLD) + { + // XXX XXX FIXME XXX XXX Why the special-casing? + char buf[ITEMNAME_SIZE]; snprintf(buf, sizeof buf, "%d gold piece%s", i.quantity, - (i.quantity > 1? "s" : "")); + (i.quantity > 1? "s" : "")); + text = buf; + } else - item_name(i, - in_inventory(i)? - DESC_INVENTORY_EQUIP : DESC_NOCAP_A, buf, false); - text = buf; + { + text = i.name(in_inventory(i)? DESC_INVENTORY_EQUIP : DESC_NOCAP_A, + false); + } if (i.base_type != OBJ_GOLD && in_inventory(i)) { @@ -738,26 +742,23 @@ static bool has_warning_inscription(const item_def& item, { char iletter = (char)(oper); unsigned int i; - char name[ITEMNAME_SIZE]; - item_name(item, DESC_INVENTORY, name, false); const std::string& r(item.inscription); for ( i = 0; i + 1 < r.size(); ++i ) if (r[i] == '!' && (r[i+1] == iletter || r[i+1] == '*')) return true; return false; -} +} /* return true if user OK'd it (or no warning), false otherwise */ bool check_warning_inscriptions( const item_def& item, operation_types oper ) { char prompt[ITEMNAME_SIZE + 100]; - char name[ITEMNAME_SIZE]; if ( has_warning_inscription(item, oper) ) { snprintf(prompt, sizeof prompt, "Really choose %s?", - item_name(item, DESC_INVENTORY, name, false)); + item.name(DESC_INVENTORY).c_str()); return yesno(prompt, false, 'n'); } else diff --git a/crawl-ref/source/it_use2.cc b/crawl-ref/source/it_use2.cc index 08e083cb69..969683e7c8 100644 --- a/crawl-ref/source/it_use2.cc +++ b/crawl-ref/source/it_use2.cc @@ -322,9 +322,7 @@ void unwield_item(char unw, bool showMsgs) if (brand != SPWPN_NORMAL) { - char str_pass[ ITEMNAME_SIZE ]; - in_name(unw, DESC_CAP_YOUR, str_pass); - strcpy(info, str_pass); + strcpy(info, you.inv[unw].name(DESC_CAP_YOUR).c_str()); switch (brand) { diff --git a/crawl-ref/source/it_use3.cc b/crawl-ref/source/it_use3.cc index bb231b2e1a..f738995135 100644 --- a/crawl-ref/source/it_use3.cc +++ b/crawl-ref/source/it_use3.cc @@ -62,7 +62,6 @@ void special_wielded(void) const int old_plus2 = you.inv[wpn].plus2; const char old_colour = you.inv[wpn].colour; - char str_pass[ ITEMNAME_SIZE ]; int temp_rand = 0; // for probability determination {dlb} bool makes_noise = (one_chance_in(20) && !silenced(you.x_pos, you.y_pos)); @@ -200,20 +199,14 @@ void special_wielded(void) case SPWLD_HUM: if (makes_noise) { - in_name(wpn, DESC_CAP_YOUR, str_pass); - strcpy(info, str_pass); - strcat(info, " lets out a weird humming sound."); - mpr(info, MSGCH_SOUND); } break; // to noisy() call at foot 2apr2000 {dlb} case SPWLD_CHIME: if (makes_noise) { - in_name(wpn, DESC_CAP_YOUR, str_pass); - strcpy(info, str_pass); - strcat(info, " chimes like a gong."); - mpr(info, MSGCH_SOUND); + mprf(MSGCH_SOUND, "%s chimes like a gong.", + you.inv[wpn].name(DESC_CAP_YOUR).c_str()); } break; @@ -335,8 +328,6 @@ bool evoke_wielded( void ) int pract = 0; bool did_work = false; // used for default "nothing happens" message - char str_pass[ ITEMNAME_SIZE ]; - int wield = you.equip[EQ_WEAPON]; if (you.berserker) @@ -350,10 +341,12 @@ bool evoke_wielded( void ) return (false); } - switch (you.inv[wield].base_type) + item_def& wpn = you.inv[wield]; + + switch (wpn.base_type) { case OBJ_WEAPONS: - if (get_weapon_brand( you.inv[wield] ) == SPWPN_REACHING + if (get_weapon_brand( wpn ) == SPWPN_REACHING && enough_mp(1, false)) { // needed a cost to prevent evocation training abuse -- bwr @@ -363,9 +356,9 @@ bool evoke_wielded( void ) pract = (one_chance_in(5) ? 1 : 0); did_work = true; } - else if (is_fixed_artefact( you.inv[wield] )) + else if (is_fixed_artefact( wpn )) { - switch (you.inv[wield].special) + switch (wpn.special) { case SPWPN_STAFF_OF_DISPATER: if (you.deaths_door || !enough_hp(11, true) @@ -486,7 +479,7 @@ bool evoke_wielded( void ) break; case OBJ_STAVES: - if (item_is_rod( you.inv[wield] )) + if (item_is_rod( wpn )) { pract = staff_spell( wield ); // [ds] Early exit, no turns are lost. @@ -495,7 +488,7 @@ bool evoke_wielded( void ) did_work = true; // staff_spell() will handle messages } - else if (you.inv[wield].sub_type == STAFF_CHANNELING) + else if (wpn.sub_type == STAFF_CHANNELING) { if (you.magic_points < you.max_magic_points && you.skills[SK_EVOCATIONS] >= random2(30)) @@ -506,17 +499,13 @@ bool evoke_wielded( void ) pract = (one_chance_in(5) ? 1 : 0); did_work = true; - if (!item_type_known( you.inv[you.equip[EQ_WEAPON]] )) + if (!item_type_known(wpn)) { - set_ident_flags( you.inv[you.equip[EQ_WEAPON]], - ISFLAG_KNOW_TYPE ); - - strcpy( info, "You are wielding " ); - in_name( you.equip[EQ_WEAPON], DESC_NOCAP_A, str_pass ); - strcat( info, str_pass ); - strcat( info, "." ); + set_ident_flags( wpn, ISFLAG_KNOW_TYPE ); - mpr( info ); + mprf("You are wielding %s.", + wpn.name(DESC_NOCAP_A).c_str()); + more(); you.wield_change = true; @@ -527,7 +516,7 @@ bool evoke_wielded( void ) case OBJ_MISCELLANY: did_work = true; // easier to do it this way for misc items - switch (you.inv[wield].sub_type) + switch (wpn.sub_type) { case MISC_BOTTLED_EFREET: if (efreet_flask()) diff --git a/crawl-ref/source/item_use.cc b/crawl-ref/source/item_use.cc index 703550e896..8fd396f0e4 100644 --- a/crawl-ref/source/item_use.cc +++ b/crawl-ref/source/item_use.cc @@ -170,7 +170,6 @@ bool can_wield(const item_def *weapon, bool say_reason) bool wield_weapon(bool auto_wield, int slot, bool show_weff_messages) { int item_slot = 0; - char str_pass[ ITEMNAME_SIZE ]; if (inv_count() < 1) { @@ -258,8 +257,7 @@ bool wield_weapon(bool auto_wield, int slot, bool show_weff_messages) // any oddness on wielding taken care of here wield_effects(item_slot, show_weff_messages); - in_name( item_slot, DESC_INVENTORY_EQUIP, str_pass ); - mpr( str_pass ); + mpr(you.inv[item_slot].name(DESC_INVENTORY_EQUIP).c_str()); // warn player about low str/dex or throwing skill wield_warning(); @@ -951,9 +949,8 @@ bool takeoff_armour(int item) { if (item == you.equip[loopy]) { - in_name(item, DESC_CAP_YOUR, info); - strcat(info, " is stuck to your body!"); - mpr(info); + mprf("%s is stuck to your body!", + you.inv[item].name(DESC_CAP_YOUR).c_str()); return false; } } @@ -1212,7 +1209,6 @@ int get_fire_item_index( void ) void shoot_thing(void) { struct bolt beam; // passed in by reference, but never used here - char str_pass[ ITEMNAME_SIZE ]; if (you.berserker) { @@ -1228,7 +1224,7 @@ void shoot_thing(void) return; } - mprf("Firing: %s", in_name(item, DESC_INVENTORY_EQUIP, str_pass)); + mprf("Firing: %s", you.inv[item].name(DESC_INVENTORY_EQUIP).c_str()); throw_it( beam, item ); } // end shoot_thing() @@ -1393,13 +1389,11 @@ bool throw_it(struct bolt &pbolt, int throw_2, monsters *dummy_target) } // Making a copy of the item: changed only for venom launchers - item_def item = you.inv[throw_2]; + item_def item = you.inv[throw_2]; item.quantity = 1; item.slot = index_to_letter(item.link); origin_set_unknown(item); - char str_pass[ ITEMNAME_SIZE ]; - if (you.conf) { thr.isTarget = true; @@ -1436,8 +1430,7 @@ bool throw_it(struct bolt &pbolt, int throw_2, monsters *dummy_target) pbolt.source_y = you.y_pos; pbolt.colour = item.colour; - item_name( item, DESC_PLAIN, str_pass ); - pbolt.name = str_pass; + pbolt.name = item.name(DESC_PLAIN); pbolt.thrower = KILL_YOU_MISSILE; pbolt.aux_source.clear(); @@ -1713,8 +1706,7 @@ bool throw_it(struct bolt &pbolt, int throw_2, monsters *dummy_target) { // poison brand the ammo set_item_ego_type( item, OBJ_MISSILES, SPMSL_POISONED ); - item_name( item, DESC_PLAIN, str_pass ); - pbolt.name = str_pass; + pbolt.name = item.name(DESC_PLAIN); } // Note that bow_brand is known since the bow is equiped. @@ -1769,23 +1761,19 @@ bool throw_it(struct bolt &pbolt, int throw_2, monsters *dummy_target) { if ( !item_ident(you.inv[throw_2], ISFLAG_KNOW_PLUSES) && random2(100) < rc_skill ) - { + { set_ident_flags( item, ISFLAG_KNOW_PLUSES ); set_ident_flags( you.inv[throw_2], ISFLAG_KNOW_PLUSES ); - in_name( throw_2, DESC_NOCAP_A, str_pass); - snprintf(info, INFO_SIZE, "You are firing %s.", str_pass); - mpr(info); + mprf("You are firing %s.", + you.inv[throw_2].name(DESC_NOCAP_A).c_str()); } } else if (random2(100) < shoot_skill) { - set_ident_flags(you.inv[you.equip[EQ_WEAPON]], ISFLAG_KNOW_PLUSES); + item_def& weapon = you.inv[you.equip[EQ_WEAPON]]; + set_ident_flags(weapon, ISFLAG_KNOW_PLUSES); - strcpy(info, "You are wielding "); - in_name(you.equip[EQ_WEAPON], DESC_NOCAP_A, str_pass); - strcat(info, str_pass); - strcat(info, "."); - mpr(info); + mprf("You are wielding %s.", weapon.name(DESC_NOCAP_A).c_str()); more(); you.wield_change = true; @@ -1873,12 +1861,11 @@ bool throw_it(struct bolt &pbolt, int throw_2, monsters *dummy_target) // ID check if ( !item_ident(you.inv[throw_2], ISFLAG_KNOW_PLUSES) && random2(100) < you.skills[SK_RANGED_COMBAT] ) - { + { set_ident_flags( item, ISFLAG_KNOW_PLUSES ); set_ident_flags( you.inv[throw_2], ISFLAG_KNOW_PLUSES ); - in_name( throw_2, DESC_NOCAP_A, str_pass); - snprintf(info, INFO_SIZE, "You are throwing %s.", str_pass); - mpr(info); + mprf("You are throwing %s.", + you.inv[throw_2].name(DESC_NOCAP_A).c_str()); } } @@ -1975,16 +1962,8 @@ bool throw_it(struct bolt &pbolt, int throw_2, monsters *dummy_target) #endif // create message - if (launched) - strcpy(info, "You shoot "); - else - strcpy(info, "You throw "); - - item_name( item, DESC_NOCAP_A, str_pass ); - - strcat(info, str_pass); - strcat(info, "."); - mpr(info); + mprf( "You %s %s.", launched ? "shoot" : "throw", + item.name(DESC_NOCAP_A).c_str() ); // ensure we're firing a 'missile'-type beam pbolt.is_beam = false; @@ -2119,7 +2098,7 @@ void jewellery_wear_effects(item_def &item) // cursed or not, we know that since we've put the ring on set_ident_flags( item, ISFLAG_KNOW_CURSE ); - mpr( item_name( item, DESC_INVENTORY_EQUIP ) ); + mpr( item.name(DESC_INVENTORY_EQUIP).c_str() ); } static int prompt_ring_to_remove(int new_ring) @@ -2134,7 +2113,7 @@ static int prompt_ring_to_remove(int new_ring) } mesclr(); - mprf("Wearing %s.", in_name(new_ring, DESC_NOCAP_A)); + mprf("Wearing %s.", you.inv[new_ring].name(DESC_NOCAP_A).c_str()); char lslot = index_to_letter(left.link), rslot = index_to_letter(right.link); @@ -2142,8 +2121,8 @@ static int prompt_ring_to_remove(int new_ring) mprf(MSGCH_PROMPT, "You're wearing two rings. Remove which one? (%c/%c/Esc)", lslot, rslot); - mprf(" %s", item_name( left, DESC_INVENTORY )); - mprf(" %s", item_name( right, DESC_INVENTORY )); + mprf(" %s", left.name(DESC_INVENTORY).c_str() ); + mprf(" %s", right.name(DESC_INVENTORY).c_str() ); int c; do @@ -2308,10 +2287,10 @@ void jewellery_remove_effects(item_def &item) // Turn off show_uncursed before getting the item name, because this item // was just removed, and the player knows it's uncursed. - bool old_showuncursed = Options.show_uncursed; + const bool old_showuncursed = Options.show_uncursed; Options.show_uncursed = false; - mprf("You remove %s.", item_name(item, DESC_NOCAP_YOUR)); + mprf("You remove %s.", item.name(DESC_NOCAP_YOUR).c_str() ); Options.show_uncursed = old_showuncursed; @@ -2479,8 +2458,7 @@ bool remove_ring(int slot, bool announce) { if (announce) mprf("%s is stuck to you!", - in_name(you.equip[hand_used + EQ_LEFT_RING], - DESC_CAP_YOUR)); + you.inv[you.equip[hand_used + EQ_LEFT_RING]].name(DESC_CAP_YOUR).c_str()); else mpr("It's stuck to you!"); @@ -2505,7 +2483,6 @@ void zap_wand(void) struct bolt beam; struct dist zap_wand; int item_slot; - char str_pass[ ITEMNAME_SIZE ]; // Unless the character knows the type of the wand, the targeting // system will default to enemies. -- [ds] @@ -2631,8 +2608,7 @@ void zap_wand(void) set_ident_type( you.inv[item_slot].base_type, you.inv[item_slot].sub_type, ID_KNOWN_TYPE ); - in_name(item_slot, DESC_INVENTORY_EQUIP, str_pass); - mpr( str_pass ); + mpr(you.inv[item_slot].name(DESC_INVENTORY_EQUIP).c_str()); // update if wielding if (you.equip[EQ_WEAPON] == item_slot) @@ -2689,7 +2665,7 @@ void inscribe_item() canned_msg( MSG_OK ); return; } - mpr( item_name( you.inv[item_slot], DESC_INVENTORY ), MSGCH_EQUIPMENT ); + mpr( you.inv[item_slot].name(DESC_INVENTORY).c_str(), MSGCH_EQUIPMENT ); mpr( "Inscribe with what? ", MSGCH_PROMPT ); get_input_line( buf, sizeof(buf) ); you.inv[item_slot].inscription = std::string(buf); @@ -2953,7 +2929,6 @@ bool enchant_weapon( int which_stat, bool quiet ) const int wpn = you.equip[ EQ_WEAPON ]; bool affected = true; int enchant_level; - char str_pass[ ITEMNAME_SIZE ]; if (wpn == -1 || (you.inv[ wpn ].base_type != OBJ_WEAPONS @@ -2965,19 +2940,21 @@ bool enchant_weapon( int which_stat, bool quiet ) return (false); } + item_def& item = you.inv[wpn]; + you.wield_change = true; // missiles only have one stat - if (you.inv[ wpn ].base_type == OBJ_MISSILES) + if (item.base_type == OBJ_MISSILES) which_stat = ENCHANT_TO_HIT; if (which_stat == ENCHANT_TO_HIT) - enchant_level = you.inv[ wpn ].plus; + enchant_level = item.plus; else - enchant_level = you.inv[ wpn ].plus2; + enchant_level = item.plus2; // artefacts can't be enchanted, but scrolls still remove curses - if (you.inv[ wpn ].base_type == OBJ_WEAPONS + if (item.base_type == OBJ_WEAPONS && (is_fixed_artefact( you.inv[wpn] ) || is_random_artefact( you.inv[wpn] ))) { @@ -2993,14 +2970,12 @@ bool enchant_weapon( int which_stat, bool quiet ) // be uncursed: if (!affected) { - if (item_cursed( you.inv[you.equip[EQ_WEAPON]] )) + if (item_cursed(item)) { if (!quiet) { - in_name(you.equip[EQ_WEAPON], DESC_CAP_YOUR, str_pass); - strcpy(info, str_pass); - strcat(info, " glows silver for a moment."); - mpr(info); + mprf("%s glows silver for a moment.", + item.name(DESC_CAP_YOUR).c_str()); } do_uncurse_item( you.inv[you.equip[EQ_WEAPON]] ); @@ -3016,43 +2991,34 @@ bool enchant_weapon( int which_stat, bool quiet ) } } - // vVvVv This is *here* (as opposed to lower down) for a reason! - in_name( wpn, DESC_CAP_YOUR, str_pass ); - strcpy( info, str_pass ); + // Get the item name now before the enchantment changes it. + std::string iname = item.name(DESC_CAP_YOUR); - do_uncurse_item( you.inv[ wpn ] ); + do_uncurse_item( item ); - if (you.inv[ wpn ].base_type == OBJ_WEAPONS) + if (item.base_type == OBJ_WEAPONS) { if (which_stat == ENCHANT_TO_DAM) { - you.inv[ wpn ].plus2++; + item.plus2++; if (!quiet) - { - strcat(info, " glows red for a moment."); - mpr(info); - } + mprf("%s glows red for a moment.", iname.c_str()); } else if (which_stat == ENCHANT_TO_HIT) { - you.inv[ wpn ].plus++; + item.plus++; if (!quiet) - { - strcat(info, " glows green for a moment."); - mpr(info); - } + mprf("%s glows green for a moment.", iname.c_str()); } } - else if (you.inv[ wpn ].base_type == OBJ_MISSILES) + else if (item.base_type == OBJ_MISSILES) { - strcat( info, (you.inv[ wpn ].quantity > 1) ? " glow" - : " glows" ); + mprf("%s %s red for a moment.", iname.c_str(), + item.quantity > 1 ? "glow" : "glows"); - strcat(info, " red for a moment."); - - you.inv[ wpn ].plus++; + item.plus++; } return (true); @@ -3062,7 +3028,6 @@ static bool enchant_armour( void ) { // NOTE: It is assumed that armour which changes in this way does // not change into a form of armour with a different evasion modifier. - char str_pass[ ITEMNAME_SIZE ]; int nthing = you.equip[EQ_BODY_ARMOUR]; if (nthing != -1 @@ -3075,10 +3040,8 @@ static bool enchant_armour( void ) || you.inv[nthing].sub_type == ARM_SWAMP_DRAGON_HIDE || you.inv[nthing].sub_type == ARM_TROLL_HIDE)) { - in_name( you.equip[EQ_BODY_ARMOUR], DESC_CAP_YOUR, str_pass ); - strcpy(info, str_pass); - strcat(info, " glows purple and changes!"); - mpr(info); + mprf("%s glows purple and changes!", + you.inv[you.equip[EQ_BODY_ARMOUR]].name(DESC_CAP_YOUR).c_str()); you.redraw_armour_class = 1; @@ -3127,10 +3090,8 @@ static bool enchant_armour( void ) { if (item_cursed( item )) { - item_name(item, DESC_CAP_YOUR, str_pass); - strcpy(info, str_pass); - strcat(info, " glows silver for a moment."); - mpr(info); + mprf("%s glows silver for a moment.", + item.name(DESC_CAP_YOUR).c_str()); do_uncurse_item( item ); return (true); @@ -3143,10 +3104,8 @@ static bool enchant_armour( void ) } // vVvVv This is *here* for a reason! - item_name(item, DESC_CAP_YOUR, str_pass); - strcpy(info, str_pass); - strcat(info, " glows green for a moment."); - mpr(info); + mprf("%s glows green for a moment.", + item.name(DESC_CAP_YOUR).c_str()); item.plus++; @@ -3211,7 +3170,6 @@ void read_scroll(void) int count; int nthing; struct bolt beam; - char str_pass[ ITEMNAME_SIZE ]; // added: scroll effects are never tracers. beam.is_tracer = false; @@ -3431,10 +3389,8 @@ void read_scroll(void) } else { - in_name( nthing, DESC_CAP_YOUR, str_pass ); - strcpy(info, str_pass); - strcat(info, " glows black for a moment."); - mpr(info); + mprf("%s glows black for a moment.", + you.inv[nthing].name(DESC_CAP_YOUR).c_str()); do_curse_item( you.inv[nthing] ); you.wield_change = true; @@ -3453,11 +3409,15 @@ void read_scroll(void) case SCR_ENCHANT_WEAPON_III: if (you.equip[ EQ_WEAPON ] != -1) { - in_name( you.equip[EQ_WEAPON], DESC_CAP_YOUR, info ); + // Get the name before it changes. + const std::string iname = + you.inv[you.equip[EQ_WEAPON]].name(DESC_CAP_YOUR); + + // Successfully affixing the enchantment will print + // its own message. if (!affix_weapon_enchantment()) { - strcat( info, " glows bright yellow for a while." ); - mpr( info ); + mprf("%s glows bright yellow for a while.", iname.c_str() ); enchant_weapon( ENCHANT_TO_HIT, true ); @@ -3492,11 +3452,8 @@ void read_scroll(void) break; } - in_name(nthing, DESC_CAP_YOUR, str_pass); - - strcpy(info, str_pass); - strcat(info, " emits a brilliant flash of light!"); - mpr(info); + mprf("%s emits a brilliant flash of light!", + you.inv[nthing].name(DESC_CAP_YOUR).c_str()); alert_nearby_monsters(); @@ -3553,14 +3510,14 @@ void read_scroll(void) id_the_scroll = false; break; } - - // make the name _before_ we curse it - in_name( you.equip[affected], DESC_CAP_YOUR, str_pass ); - do_curse_item( you.inv[you.equip[affected]] ); - - strcpy(info, str_pass); - strcat(info, " glows black for a moment."); - mpr(info); + else + { + // make the name before we curse it + item_def& item = you.inv[you.equip[affected]]; + mprf("%s glows black for a moment.", + item.name(DESC_CAP_YOUR).c_str()); + do_curse_item( item ); + } break; } // end switch diff --git a/crawl-ref/source/itemname.cc b/crawl-ref/source/itemname.cc index 2332515fad..66708cbfb9 100644 --- a/crawl-ref/source/itemname.cc +++ b/crawl-ref/source/itemname.cc @@ -46,15 +46,10 @@ id_arr shop_backup_id; static bool is_random_name_space( char let ); static bool is_random_name_vowel( char let); -static const char *item_name_2( - const item_def &item, char buff[ ITEMNAME_SIZE ], bool terse ); static char retvow(int sed); static char retlet(int sed); -// [dshaligram] For calls to item_name without a pre-allocated buffer. -static char default_itembuf[ITEMNAME_SIZE]; - static bool is_tried_type( int basetype, int subtype ) { switch ( basetype ) @@ -98,55 +93,34 @@ bool item_type_known( const item_def &item ) return (idt != NUM_IDTYPE? id[idt][item.sub_type] == ID_KNOWN_TYPE : false); } -// it_name() and in_name() are now somewhat obsolete now that itemname -// takes item_def, so consider them deprecated. -const char *it_name( int itn, char des, char *buff, bool terse ) -{ - return item_name( mitm[itn], des, buff, terse ); -} // end it_name() - - -const char *in_name( int inn, char des, char *buff, bool terse ) -{ - return item_name( you.inv[inn], des, buff, terse ); -} // end in_name() - -// quant_name is usful since it prints out a different number of items +// quant_name is useful since it prints out a different number of items // than the item actually contains. -const char *quant_name( const item_def &item, int quant, char des, - char buff[ ITEMNAME_SIZE ], bool terse ) +std::string quant_name( const item_def &item, int quant, + description_level_type des, bool terse ) { // item_name now requires a "real" item, so we'll mangle a tmp item_def tmp = item; tmp.quantity = quant; - return item_name( tmp, des, buff, terse ); -} // end quant_name() + return tmp.name(des, terse); +} // buff must be at least ITEMNAME_SIZE if non-NULL. If NULL, a static // item buffer will be used. -const char *item_name( const item_def &item, char descrip, - char *buff, bool terse ) +std::string item_def::name(description_level_type descrip, + bool terse) const { - const int item_clas = item.base_type; - const int item_typ = item.sub_type; - const int it_quant = item.quantity; - char tmp_quant[20]; - char itm_name[ ITEMNAME_SIZE ] = ""; + char itm_name[ITEMNAME_SIZE] = ""; + char buff[ITEMNAME_SIZE] = ""; - if (!buff) - buff = default_itembuf; - - item_name_2( item, itm_name, terse ); - - buff[0] = '\0'; + this->name_aux(itm_name, terse); if (descrip == DESC_INVENTORY_EQUIP || descrip == DESC_INVENTORY) { - if (in_inventory(item)) // actually in inventory + if (in_inventory(*this)) // actually in inventory snprintf( buff, ITEMNAME_SIZE, (terse) ? "%c) " : "%c - ", - index_to_letter( item.link ) ); + index_to_letter( this->link ) ); else descrip = DESC_CAP_A; } @@ -154,12 +128,12 @@ const char *item_name( const item_def &item, char descrip, if (terse) descrip = DESC_PLAIN; - if (item_clas == OBJ_ORBS - || (item_type_known( item ) - && ((item_clas == OBJ_MISCELLANY - && item_typ == MISC_HORN_OF_GERYON) - || (is_fixed_artefact( item ) - || (is_random_artefact( item )))))) + 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 )))))) { // artefacts always get "the" unless we just want the plain name switch (descrip) @@ -182,7 +156,7 @@ const char *item_name( const item_def &item, char descrip, break; } } - else if (it_quant > 1) + else if (this->quantity > 1) { switch (descrip) { @@ -211,7 +185,7 @@ const char *item_name( const item_def &item, char descrip, break; } - itoa(it_quant, tmp_quant, 10); + itoa(this->quantity, tmp_quant, 10); strncat(buff, tmp_quant, ITEMNAME_SIZE ); strncat(buff, " ", ITEMNAME_SIZE ); } @@ -228,12 +202,10 @@ const char *item_name( const item_def &item, char descrip, case DESC_CAP_A: strncat(buff, "A", ITEMNAME_SIZE ); - if (itm_name[0] == 'a' || itm_name[0] == 'e' || itm_name[0] == 'i' - || itm_name[0] == 'o' || itm_name[0] == 'u') + if (is_vowel(itm_name[0])) { strncat(buff, "n", ITEMNAME_SIZE ); } - strncat(buff, " ", ITEMNAME_SIZE ); break; // A/An @@ -242,8 +214,7 @@ const char *item_name( const item_def &item, char descrip, case DESC_INVENTORY: strncat(buff, "a", ITEMNAME_SIZE ); - if (itm_name[0] == 'a' || itm_name[0] == 'e' || itm_name[0] == 'i' - || itm_name[0] == 'o' || itm_name[0] == 'u') + if (is_vowel(itm_name[0])) { strncat(buff, "n", ITEMNAME_SIZE ); } @@ -268,11 +239,11 @@ const char *item_name( const item_def &item, char descrip, strncat(buff, itm_name, ITEMNAME_SIZE ); - if (descrip == DESC_INVENTORY_EQUIP && item.x == -1 && item.y == -1) + if (descrip == DESC_INVENTORY_EQUIP && this->x == -1 && this->y == -1) { - ASSERT( item.link != -1 ); + ASSERT( this->link != -1 ); - if (item.link == you.equip[EQ_WEAPON]) + if (this->link == you.equip[EQ_WEAPON]) { if (you.inv[ you.equip[EQ_WEAPON] ].base_type == OBJ_WEAPONS || item_is_staff( you.inv[ you.equip[EQ_WEAPON] ] )) @@ -284,85 +255,80 @@ const char *item_name( const item_def &item, char descrip, strncat( buff, " (in hand)", ITEMNAME_SIZE ); } } - else if (item.link == you.equip[EQ_CLOAK] - || item.link == you.equip[EQ_HELMET] - || item.link == you.equip[EQ_GLOVES] - || item.link == you.equip[EQ_BOOTS] - || item.link == you.equip[EQ_SHIELD] - || item.link == you.equip[EQ_BODY_ARMOUR]) + else if (this->link == you.equip[EQ_CLOAK] + || this->link == you.equip[EQ_HELMET] + || this->link == you.equip[EQ_GLOVES] + || this->link == you.equip[EQ_BOOTS] + || this->link == you.equip[EQ_SHIELD] + || this->link == you.equip[EQ_BODY_ARMOUR]) { strncat( buff, " (worn)", ITEMNAME_SIZE ); } - else if (item.link == you.equip[EQ_LEFT_RING]) + else if (this->link == you.equip[EQ_LEFT_RING]) { strncat( buff, " (left hand)", ITEMNAME_SIZE ); } - else if (item.link == you.equip[EQ_RIGHT_RING]) + else if (this->link == you.equip[EQ_RIGHT_RING]) { strncat( buff, " (right hand)", ITEMNAME_SIZE ); } - else if (item.link == you.equip[EQ_AMULET]) + else if (this->link == you.equip[EQ_AMULET]) { strncat( buff, " (around neck)", ITEMNAME_SIZE ); } } - if ( !item.inscription.empty() ) + if ( !(this->inscription.empty()) ) { strncat( buff, " {", 2 ); - if ( is_tried_type(item.base_type, item.sub_type) ) + if ( is_tried_type(this->base_type, this->sub_type) ) strncat(buff, "tried, ", 10); - strncat( buff, item.inscription.c_str(), ITEMNAME_SIZE ); + strncat( buff, this->inscription.c_str(), ITEMNAME_SIZE ); strncat( buff, "}", 1 ); } - else if ( is_tried_type(item.base_type, item.sub_type) ) + else if ( is_tried_type(this->base_type, this->sub_type) ) strncat(buff, " {tried}", 10); - return (buff); + return std::string(buff); } // end item_name() // Note that "terse" is only currently used for the "in hand" listing on // the game screen. -static const char *item_name_2( - const item_def &item, - char buff[ITEMNAME_SIZE], - bool terse ) +void item_def::name_aux( char* buff, bool terse ) const { - const int item_clas = item.base_type; - const int item_typ = item.sub_type; - const int it_plus = item.plus; - const int item_plus2 = item.plus2; - const int it_quant = item.quantity; + const int item_typ = this->sub_type; + const int it_plus = this->plus; + const int item_plus2 = this->plus2; char tmp_quant[20]; char tmp_buff[ITEMNAME_SIZE]; int brand; - unsigned char sparm; + int sparm; buff[0] = 0; - switch (item_clas) + switch (this->base_type) { case OBJ_WEAPONS: - if (item_ident( item, ISFLAG_KNOW_CURSE ) && !terse) + if (item_ident( *this, ISFLAG_KNOW_CURSE ) && !terse) { // We don't bother printing "uncursed" if the item is identified - // for pluses (it's state should be obvious), this is so that + // for pluses (its state should be obvious), this is so that // the weapon name is kept short (there isn't a lot of room // for the name on the main screen). If you're going to change // this behaviour, *please* make it so that there is an option // that maintains this behaviour. -- bwr - if (item_cursed( item )) + if (item_cursed( *this )) strncat(buff, "cursed ", ITEMNAME_SIZE ); else if (Options.show_uncursed - && !item_ident( item, ISFLAG_KNOW_PLUSES )) + && !item_ident( *this, ISFLAG_KNOW_PLUSES )) { strncat(buff, "uncursed ", ITEMNAME_SIZE ); } } - if (item_ident( item, ISFLAG_KNOW_PLUSES )) + if (item_ident( *this, ISFLAG_KNOW_PLUSES )) { if (it_plus == 0 && item_plus2 == 0) strncat(buff, "+0 ", ITEMNAME_SIZE ); @@ -389,53 +355,53 @@ static const char *item_name_2( } } - if (is_random_artefact( item )) + if (is_random_artefact( *this )) { - strncat( buff, randart_name(item), ITEMNAME_SIZE ); + strncat( buff, randart_name(*this), ITEMNAME_SIZE ); break; } - if (is_fixed_artefact( item )) + if (is_fixed_artefact( *this )) { - if (item_type_known( item )) + if (item_type_known( *this )) { strncat(buff, - (item.special == SPWPN_SINGING_SWORD) ? "Singing Sword" : - (item.special == SPWPN_WRATH_OF_TROG) ? "Wrath of Trog" : - (item.special == SPWPN_SCYTHE_OF_CURSES) ? "Scythe of Curses" : - (item.special == SPWPN_MACE_OF_VARIABILITY) ? "Mace of Variability" : - (item.special == SPWPN_GLAIVE_OF_PRUNE) ? "Glaive of Prune" : - (item.special == SPWPN_SCEPTRE_OF_TORMENT) ? "Sceptre of Torment" : - (item.special == SPWPN_SWORD_OF_ZONGULDROK) ? "Sword of Zonguldrok" : - (item.special == SPWPN_SWORD_OF_CEREBOV) ? "Sword of Cerebov" : - (item.special == SPWPN_STAFF_OF_DISPATER) ? "Staff of Dispater" : - (item.special == SPWPN_SCEPTRE_OF_ASMODEUS) ? "Sceptre of Asmodeus" : - (item.special == SPWPN_SWORD_OF_POWER) ? "Sword of Power" : - (item.special == SPWPN_KNIFE_OF_ACCURACY) ? "Knife of Accuracy" : - (item.special == SPWPN_STAFF_OF_OLGREB) ? "Staff of Olgreb" : - (item.special == SPWPN_VAMPIRES_TOOTH) ? "Vampire's Tooth" : - (item.special == SPWPN_STAFF_OF_WUCAD_MU) ? "Staff of Wucad Mu" + (this->special == SPWPN_SINGING_SWORD) ? "Singing Sword" : + (this->special == SPWPN_WRATH_OF_TROG) ? "Wrath of Trog" : + (this->special == SPWPN_SCYTHE_OF_CURSES) ? "Scythe of Curses" : + (this->special == SPWPN_MACE_OF_VARIABILITY) ? "Mace of Variability" : + (this->special == SPWPN_GLAIVE_OF_PRUNE) ? "Glaive of Prune" : + (this->special == SPWPN_SCEPTRE_OF_TORMENT) ? "Sceptre of Torment" : + (this->special == SPWPN_SWORD_OF_ZONGULDROK) ? "Sword of Zonguldrok" : + (this->special == SPWPN_SWORD_OF_CEREBOV) ? "Sword of Cerebov" : + (this->special == SPWPN_STAFF_OF_DISPATER) ? "Staff of Dispater" : + (this->special == SPWPN_SCEPTRE_OF_ASMODEUS) ? "Sceptre of Asmodeus" : + (this->special == SPWPN_SWORD_OF_POWER) ? "Sword of Power" : + (this->special == SPWPN_KNIFE_OF_ACCURACY) ? "Knife of Accuracy" : + (this->special == SPWPN_STAFF_OF_OLGREB) ? "Staff of Olgreb" : + (this->special == SPWPN_VAMPIRES_TOOTH) ? "Vampire's Tooth" : + (this->special == SPWPN_STAFF_OF_WUCAD_MU) ? "Staff of Wucad Mu" : "Brodale's Buggy Bola", ITEMNAME_SIZE ); } else { strncat(buff, - (item.special == SPWPN_SINGING_SWORD) ? "golden long sword" : - (item.special == SPWPN_WRATH_OF_TROG) ? "bloodstained battleaxe" : - (item.special == SPWPN_SCYTHE_OF_CURSES) ? "warped scythe" : - (item.special == SPWPN_MACE_OF_VARIABILITY) ? "shimmering mace" : - (item.special == SPWPN_GLAIVE_OF_PRUNE) ? "purple glaive" : - (item.special == SPWPN_SCEPTRE_OF_TORMENT) ? "jeweled golden mace" : - (item.special == SPWPN_SWORD_OF_ZONGULDROK) ? "bone long sword" : - (item.special == SPWPN_SWORD_OF_CEREBOV) ? "great serpentine sword" : - (item.special == SPWPN_STAFF_OF_DISPATER) ? "golden staff" : - (item.special == SPWPN_SCEPTRE_OF_ASMODEUS) ? "ruby sceptre" : - (item.special == SPWPN_SWORD_OF_POWER) ? "chunky great sword" : - (item.special == SPWPN_KNIFE_OF_ACCURACY) ? "thin dagger" : - (item.special == SPWPN_STAFF_OF_OLGREB) ? "green glowing staff" : - (item.special == SPWPN_VAMPIRES_TOOTH) ? "ivory dagger" : - (item.special == SPWPN_STAFF_OF_WUCAD_MU) ? "ephemeral quarterstaff" + (this->special == SPWPN_SINGING_SWORD) ? "golden long sword" : + (this->special == SPWPN_WRATH_OF_TROG) ? "bloodstained battleaxe" : + (this->special == SPWPN_SCYTHE_OF_CURSES) ? "warped scythe" : + (this->special == SPWPN_MACE_OF_VARIABILITY) ? "shimmering mace" : + (this->special == SPWPN_GLAIVE_OF_PRUNE) ? "purple glaive" : + (this->special == SPWPN_SCEPTRE_OF_TORMENT) ? "jeweled golden mace" : + (this->special == SPWPN_SWORD_OF_ZONGULDROK) ? "bone long sword" : + (this->special == SPWPN_SWORD_OF_CEREBOV) ? "great serpentine sword" : + (this->special == SPWPN_STAFF_OF_DISPATER) ? "golden staff" : + (this->special == SPWPN_SCEPTRE_OF_ASMODEUS) ? "ruby sceptre" : + (this->special == SPWPN_SWORD_OF_POWER) ? "chunky great sword" : + (this->special == SPWPN_KNIFE_OF_ACCURACY) ? "thin dagger" : + (this->special == SPWPN_STAFF_OF_OLGREB) ? "green glowing staff" : + (this->special == SPWPN_VAMPIRES_TOOTH) ? "ivory dagger" : + (this->special == SPWPN_STAFF_OF_WUCAD_MU) ? "ephemeral quarterstaff" : "buggy bola", ITEMNAME_SIZE ); } @@ -445,9 +411,9 @@ static const char *item_name_2( // 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( item, ISFLAG_KNOW_PLUSES ) && !terse) + if (!item_ident( *this, ISFLAG_KNOW_PLUSES ) && !terse) { - switch (get_equip_desc( item )) + switch (get_equip_desc( *this )) { case ISFLAG_RUNED: strncat(buff, "runed ", ITEMNAME_SIZE ); @@ -460,7 +426,7 @@ static const char *item_name_2( // always give racial type (it does have game effects) - switch (get_equip_race( item )) + switch (get_equip_race( *this )) { case ISFLAG_ORCISH: strncat( buff, (terse) ? "orc " : "orcish ", ITEMNAME_SIZE ); @@ -473,17 +439,17 @@ static const char *item_name_2( break; } - brand = get_weapon_brand( item ); + brand = get_weapon_brand( *this ); - if (item_type_known(item) && !terse) + if (item_type_known(*this) && !terse) { if (brand == SPWPN_VAMPIRICISM) strncat(buff, "vampiric ", ITEMNAME_SIZE ); } // end if - strncat(buff, item_base_name(item).c_str(), ITEMNAME_SIZE); + strncat(buff, item_base_name(*this).c_str(), ITEMNAME_SIZE); - if (item_type_known( item )) + if (item_type_known( *this )) { switch (brand) { @@ -517,14 +483,14 @@ static const char *item_name_2( strncat(buff, (terse) ? " (speed)" : " of speed", ITEMNAME_SIZE ); break; case SPWPN_VORPAL: - if (is_range_weapon( item )) + if (is_range_weapon( *this )) { strncat(buff, (terse) ? " (velocity)" : " of velocity", ITEMNAME_SIZE ); break; } - switch (get_vorpal_type(item)) + switch (get_vorpal_type(*this)) { case DVORP_CRUSHING: strncat(buff, (terse) ? " (crush)" : " of crushing", ITEMNAME_SIZE ); @@ -578,12 +544,12 @@ static const char *item_name_2( } } - if (item_ident(item, ISFLAG_KNOW_CURSE) && item_cursed(item) && terse) + if (item_ident(*this, ISFLAG_KNOW_CURSE) && item_cursed(*this) && terse) strncat( buff, " (curse)", ITEMNAME_SIZE ); break; case OBJ_MISSILES: - brand = get_ammo_brand( item ); + brand = get_ammo_brand( *this ); if (brand == SPMSL_POISONED) strncat( buff, (terse) ? "poison " : "poisoned ", ITEMNAME_SIZE ); @@ -593,7 +559,7 @@ static const char *item_name_2( strncat( buff, (terse) ? "curare " : "curare-tipped ", ITEMNAME_SIZE); } - if (item_ident( item, ISFLAG_KNOW_PLUSES )) + if (item_ident( *this, ISFLAG_KNOW_PLUSES )) { if (it_plus >= 0) strncat(buff, "+", ITEMNAME_SIZE ); @@ -604,9 +570,9 @@ static const char *item_name_2( strncat(buff, " ", ITEMNAME_SIZE ); } - if (get_equip_race( item )) + if (get_equip_race( *this )) { - int dwpn = get_equip_race( item ); + int dwpn = get_equip_race( *this ); strncat(buff, (dwpn == ISFLAG_ORCISH) ? ((terse) ? "orc " : "orcish ") : @@ -625,10 +591,10 @@ static const char *item_name_2( "hysterical raisin", ITEMNAME_SIZE); // this should probably be "" {dlb} - if (it_quant > 1) + if (this->quantity > 1) strncat(buff, "s", ITEMNAME_SIZE ); - if (item_type_known( item )) + if (item_type_known( *this )) { strncat( buff, (brand == SPMSL_FLAME) ? ((terse) ? " (flame)" : " of flame") : @@ -641,18 +607,18 @@ static const char *item_name_2( break; case OBJ_ARMOUR: - if (item_ident( item, ISFLAG_KNOW_CURSE ) && !terse) + if (item_ident( *this, ISFLAG_KNOW_CURSE ) && !terse) { - if (item_cursed( item )) + if (item_cursed( *this )) strncat(buff, "cursed ", ITEMNAME_SIZE ); else if (Options.show_uncursed - && !item_ident( item, ISFLAG_KNOW_PLUSES )) + && !item_ident( *this, ISFLAG_KNOW_PLUSES )) { strncat(buff, "uncursed ", ITEMNAME_SIZE ); } } - if (item_ident( item, ISFLAG_KNOW_PLUSES )) + if (item_ident( *this, ISFLAG_KNOW_PLUSES )) { if (it_plus >= 0) strncat(buff, "+", ITEMNAME_SIZE ); @@ -668,18 +634,18 @@ static const char *item_name_2( strncat( buff, "pair of ", ITEMNAME_SIZE ); } - if (is_random_artefact( item )) + if (is_random_artefact( *this )) { - strncat(buff, randart_armour_name(item), ITEMNAME_SIZE); + strncat(buff, randart_armour_name(*this), ITEMNAME_SIZE); break; } // 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( item, ISFLAG_KNOW_PLUSES ) && !terse) + if (!item_ident( *this, ISFLAG_KNOW_PLUSES ) && !terse) { - switch (get_equip_desc( item )) + switch (get_equip_desc( *this )) { case ISFLAG_EMBROIDERED_SHINY: if (item_typ == ARM_ROBE || item_typ == ARM_CLOAK @@ -705,7 +671,7 @@ static const char *item_name_2( } // always give racial description (has game effects) - switch (get_equip_race( item )) + switch (get_equip_race( *this )) { case ISFLAG_ELVEN: strncat(buff, (terse) ? "elf " :"elven ", ITEMNAME_SIZE ); @@ -718,11 +684,11 @@ static const char *item_name_2( break; } // end switch - strncat( buff, item_base_name(item).c_str(), ITEMNAME_SIZE ); + strncat( buff, item_base_name(*this).c_str(), ITEMNAME_SIZE ); - sparm = get_armour_ego_type( item ); + sparm = get_armour_ego_type( *this ); - if (item_type_known(item) && sparm != SPARM_NORMAL) + if (item_type_known(*this) && sparm != SPARM_NORMAL) { if (!terse) { @@ -774,13 +740,13 @@ static const char *item_name_2( } } - if (item_ident(item, ISFLAG_KNOW_CURSE) && item_cursed(item) && terse) + if (item_ident(*this, ISFLAG_KNOW_CURSE) && item_cursed(*this) && terse) strncat( buff, " (curse)", ITEMNAME_SIZE ); break; // compacted 15 Apr 2000 {dlb}: case OBJ_WANDS: - if (item_type_known(item)) + if (item_type_known(*this)) { strncat(buff, "wand of ", ITEMNAME_SIZE ); strncat(buff, (item_typ == WAND_FLAME) ? "flame" : @@ -808,8 +774,8 @@ static const char *item_name_2( } else { - char primary = (item.special % 12); - char secondary = (item.special / 12); + char primary = (this->special % 12); + char secondary = (this->special / 12); strncat(buff,(secondary == 0) ? "" : // hope this works {dlb} (secondary == 1) ? "jeweled" : @@ -847,7 +813,7 @@ static const char *item_name_2( strncat(buff, " wand", ITEMNAME_SIZE ); } - if (item_ident( item, ISFLAG_KNOW_PLUSES )) + if (item_ident( *this, ISFLAG_KNOW_PLUSES )) { strncat(buff, " (", ITEMNAME_SIZE ); itoa( it_plus, tmp_quant, 10 ); @@ -861,10 +827,10 @@ static const char *item_name_2( // compacted 15 Apr 2000 {dlb}: case OBJ_POTIONS: - if (item_type_known(item)) + if (item_type_known(*this)) { strncat(buff, "potion", ITEMNAME_SIZE ); - strncat(buff, (it_quant == 1) ? " " : "s ", ITEMNAME_SIZE); + strncat(buff, (this->quantity == 1) ? " " : "s ", ITEMNAME_SIZE); strncat(buff, "of ", ITEMNAME_SIZE ); strncat(buff, (item_typ == POT_HEALING) ? "healing" : (item_typ == POT_HEAL_WOUNDS) ? "heal wounds" : @@ -894,8 +860,8 @@ static const char *item_name_2( } else { - int pqual = PQUAL(item.special); - int pcolour = PCOLOUR(item.special); + int pqual = PQUAL(this->special); + int pcolour = PCOLOUR(this->special); static const char *potion_qualifiers[] = { "", "bubbling ", "fuming ", "fizzy ", "viscous ", "lumpy ", @@ -917,15 +883,15 @@ static const char *item_name_2( (pqual < 0 || pqual >= PDQ_NQUALS)? "bug-filled " : potion_qualifiers[pqual]; - const char *colour = + const char *clr = (pcolour < 0 || pcolour >= PDC_NCOLOURS)? "bogus" : potion_colours[pcolour]; strncat(buff, qualifier, ITEMNAME_SIZE - strlen(buff)); - strncat(buff, colour, ITEMNAME_SIZE - strlen(buff)); + strncat(buff, clr, ITEMNAME_SIZE - strlen(buff)); strncat(buff, " potion", ITEMNAME_SIZE - strlen(buff) ); - if (it_quant > 1) + if (this->quantity > 1) strncat(buff, "s", ITEMNAME_SIZE ); } break; @@ -1001,12 +967,12 @@ static const char *item_name_2( case FOOD_CHUNK: moname( it_plus, true, DESC_PLAIN, tmp_buff ); - if (item.special < 100) + if (this->special < 100) strncat(buff, "rotting ", ITEMNAME_SIZE ); strncat(buff, "chunk", ITEMNAME_SIZE ); - if (it_quant > 1) + if (this->quantity > 1) strncat(buff, "s", ITEMNAME_SIZE ); strncat(buff, " of ", ITEMNAME_SIZE ); @@ -1018,15 +984,15 @@ static const char *item_name_2( if (item_typ == FOOD_ROYAL_JELLY || item_typ == FOOD_STRAWBERRY || item_typ == FOOD_BEEF_JERKY) - strncat(buff, (it_quant > 1) ? "ie" : "y", ITEMNAME_SIZE ); + strncat(buff, (this->quantity > 1) ? "ie" : "y", ITEMNAME_SIZE ); break; // compacted 15 Apr 2000 {dlb}: case OBJ_SCROLLS: strncat(buff, "scroll", ITEMNAME_SIZE ); - strncat(buff, (it_quant == 1) ? " " : "s ", ITEMNAME_SIZE); + strncat(buff, (this->quantity == 1) ? " " : "s ", ITEMNAME_SIZE); - if (item_type_known(item)) + if (item_type_known(*this)) { strncat(buff, "of ", ITEMNAME_SIZE ); strncat(buff, (item_typ == SCR_IDENTIFY) ? "identify" : @@ -1062,9 +1028,9 @@ static const char *item_name_2( char buff3[ ITEMNAME_SIZE ]; const unsigned long sseed = - item.special + this->special + (static_cast(it_plus) << 8) - + (static_cast(item_clas) << 16); + + (static_cast(OBJ_SCROLLS) << 16); make_name( sseed, true, buff3 ); strncat( buff, buff3 , ITEMNAME_SIZE ); } @@ -1075,33 +1041,33 @@ static const char *item_name_2( // 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( item, ISFLAG_KNOW_CURSE )) + if (item_ident( *this, ISFLAG_KNOW_CURSE )) { - if (item_cursed( item )) + if (item_cursed( *this )) strncat(buff, "cursed ", ITEMNAME_SIZE ); else if (Options.show_uncursed && !terse - && (!ring_has_pluses(item) - || !item_ident(item, ISFLAG_KNOW_PLUSES)) + && (!ring_has_pluses(*this) + || !item_ident(*this, ISFLAG_KNOW_PLUSES)) // If the item is worn, its curse status is known, // no need to belabour the obvious. - && get_equip_slot( &item ) == -1) + && get_equip_slot( this ) == -1) { strncat(buff, "uncursed ", ITEMNAME_SIZE ); } } - if (is_random_artefact( item )) + if (is_random_artefact( *this )) { - strncat(buff, randart_ring_name(item), ITEMNAME_SIZE); + strncat(buff, randart_ring_name(*this), ITEMNAME_SIZE); break; } - if (item_type_known(item)) + if (item_type_known(*this)) { - if (item_ident( item, ISFLAG_KNOW_PLUSES ) + if (item_ident( *this, ISFLAG_KNOW_PLUSES ) && (item_typ == RING_PROTECTION || item_typ == RING_STRENGTH || item_typ == RING_SLAYING || item_typ == RING_EVASION || item_typ == RING_DEXTERITY @@ -1240,13 +1206,13 @@ static const char *item_name_2( if (item_typ < AMU_RAGE) // rings { - if (is_random_artefact( item )) + if (is_random_artefact( *this )) { - strncat(buff, randart_ring_name(item), ITEMNAME_SIZE); + strncat(buff, randart_ring_name(*this), ITEMNAME_SIZE); break; } - switch (item.special / 13) // secondary characteristic of ring + switch (this->special / 13) // secondary characteristic of ring { case 1: strncat(buff, "encrusted ", ITEMNAME_SIZE ); @@ -1286,7 +1252,7 @@ static const char *item_name_2( break; } - switch (item.special % 13) + switch (this->special % 13) { case 0: strncat(buff, "wooden ring", ITEMNAME_SIZE ); @@ -1334,15 +1300,15 @@ static const char *item_name_2( } // end of rings else // ie is an amulet { - if (is_random_artefact( item )) + if (is_random_artefact( *this )) { - strncat(buff, randart_ring_name(item), ITEMNAME_SIZE); + strncat(buff, randart_ring_name(*this), ITEMNAME_SIZE); break; } - if (item.special > 13) + if (this->special > 13) { - switch (item.special / 13) // secondary characteristic of amulet + switch (this->special / 13) // secondary characteristic of amulet { case 0: strncat(buff, "dented ", ITEMNAME_SIZE ); @@ -1386,7 +1352,7 @@ static const char *item_name_2( } } - switch (item.special % 13) + switch (this->special % 13) { case 0: strncat(buff, "zirconium amulet", ITEMNAME_SIZE ); @@ -1466,10 +1432,10 @@ static const char *item_name_2( strncat(buff, " ", ITEMNAME_SIZE ); strncat(buff, "rune", ITEMNAME_SIZE ); - if (it_quant > 1) + if (this->quantity > 1) strncat(buff, "s", ITEMNAME_SIZE ); - if (item_type_known(item)) + if (item_type_known(*this)) strncat(buff, " of Zot", ITEMNAME_SIZE ); break; @@ -1478,7 +1444,7 @@ static const char *item_name_2( case MISC_DECK_OF_TRICKS: case MISC_DECK_OF_WONDERS: strncat(buff, "deck of ", ITEMNAME_SIZE ); - strncat(buff, !item_type_known(item) ? "cards" : + strncat(buff, !item_type_known(*this) ? "cards" : (item_typ == MISC_DECK_OF_WONDERS) ? "wonders" : (item_typ == MISC_DECK_OF_SUMMONINGS) ? "summonings" : (item_typ == MISC_DECK_OF_TRICKS) ? "tricks" : @@ -1491,7 +1457,7 @@ static const char *item_name_2( case MISC_CRYSTAL_BALL_OF_FIXATION: case MISC_CRYSTAL_BALL_OF_SEEING: strncat(buff, "crystal ball", ITEMNAME_SIZE ); - if (item_type_known(item)) + if (item_type_known(*this)) { strncat(buff, " of ", ITEMNAME_SIZE ); strncat(buff, @@ -1504,69 +1470,69 @@ static const char *item_name_2( break; case MISC_BOX_OF_BEASTS: - if (item_type_known(item)) + if (item_type_known(*this)) 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(item)) + if (item_type_known(*this)) 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(item)) + if (item_type_known(*this)) 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(item)) + if (item_type_known(*this)) strncat(buff, " of fire", ITEMNAME_SIZE ); break; case MISC_LANTERN_OF_SHADOWS: - if (!item_type_known(item)) + if (!item_type_known(*this)) strncat(buff, "bone ", ITEMNAME_SIZE ); strncat(buff, "lantern", ITEMNAME_SIZE ); - if (item_type_known(item)) + if (item_type_known(*this)) strncat(buff, " of shadows", ITEMNAME_SIZE ); break; case MISC_HORN_OF_GERYON: - if (!item_type_known(item)) + if (!item_type_known(*this)) strncat(buff, "silver ", ITEMNAME_SIZE ); strncat(buff, "horn", ITEMNAME_SIZE ); - if (item_type_known(item)) + if (item_type_known(*this)) strncat(buff, " of Geryon", ITEMNAME_SIZE ); break; case MISC_DISC_OF_STORMS: - if (!item_type_known(item)) + if (!item_type_known(*this)) strncat(buff, "grey ", ITEMNAME_SIZE ); strncat(buff, "disc", ITEMNAME_SIZE ); - if (item_type_known(item)) + if (item_type_known(*this)) strncat(buff, " of storms", ITEMNAME_SIZE ); break; case MISC_STONE_OF_EARTH_ELEMENTALS: - if (!item_type_known(item)) + if (!item_type_known(*this)) strncat(buff, "nondescript ", ITEMNAME_SIZE ); strncat(buff, "stone", ITEMNAME_SIZE ); - if (item_type_known(item)) + if (item_type_known(*this)) strncat(buff, " of earth elementals", ITEMNAME_SIZE ); break; case MISC_BOTTLED_EFREET: - strncat(buff, (!item_type_known(item)) + strncat(buff, (!item_type_known(*this)) ? "sealed bronze flask" : "bottled efreet", ITEMNAME_SIZE ); break; @@ -1583,10 +1549,10 @@ static const char *item_name_2( // compacted 15 Apr 2000 {dlb}: case OBJ_BOOKS: - if (!item_type_known(item)) + if (!item_type_known(*this)) { - char primary = (item.special / 10); - char secondary = (item.special % 10); + char primary = (this->special / 10); + char secondary = (this->special % 10); strncat(buff, (primary == 0) ? "" : (primary == 1) ? "chunky " : @@ -1680,44 +1646,44 @@ static const char *item_name_2( // compacted 15 Apr 2000 {dlb}: case OBJ_STAVES: - if (!item_type_known(item)) + if (!item_type_known(*this)) { - strncat(buff, (item.special == 0) ? "curved" : - (item.special == 1) ? "glowing" : - (item.special == 2) ? "thick" : - (item.special == 3) ? "thin" : - (item.special == 4) ? "long" : - (item.special == 5) ? "twisted" : - (item.special == 6) ? "jeweled" : - (item.special == 7) ? "runed" : - (item.special == 8) ? "smoking" : - (item.special == 9) ? "gnarled" : // was "" {dlb} - (item.special == 10) ? "" : - (item.special == 11) ? "" : - (item.special == 12) ? "" : - (item.special == 13) ? "" : - (item.special == 14) ? "" : - (item.special == 15) ? "" : - (item.special == 16) ? "" : - (item.special == 17) ? "" : - (item.special == 18) ? "" : - (item.special == 19) ? "" : - (item.special == 20) ? "" : - (item.special == 21) ? "" : - (item.special == 22) ? "" : - (item.special == 23) ? "" : - (item.special == 24) ? "" : - (item.special == 25) ? "" : - (item.special == 26) ? "" : - (item.special == 27) ? "" : - (item.special == 28) ? "" : - (item.special == 29) ? "" : "buggy", ITEMNAME_SIZE); + strncat(buff, (this->special == 0) ? "curved" : + (this->special == 1) ? "glowing" : + (this->special == 2) ? "thick" : + (this->special == 3) ? "thin" : + (this->special == 4) ? "long" : + (this->special == 5) ? "twisted" : + (this->special == 6) ? "jeweled" : + (this->special == 7) ? "runed" : + (this->special == 8) ? "smoking" : + (this->special == 9) ? "gnarled" : // was "" {dlb} + (this->special == 10) ? "" : + (this->special == 11) ? "" : + (this->special == 12) ? "" : + (this->special == 13) ? "" : + (this->special == 14) ? "" : + (this->special == 15) ? "" : + (this->special == 16) ? "" : + (this->special == 17) ? "" : + (this->special == 18) ? "" : + (this->special == 19) ? "" : + (this->special == 20) ? "" : + (this->special == 21) ? "" : + (this->special == 22) ? "" : + (this->special == 23) ? "" : + (this->special == 24) ? "" : + (this->special == 25) ? "" : + (this->special == 26) ? "" : + (this->special == 27) ? "" : + (this->special == 28) ? "" : + (this->special == 29) ? "" : "buggy", ITEMNAME_SIZE); strncat(buff, " ", ITEMNAME_SIZE ); } - strncat( buff, (item_is_rod( item ) ? "rod" : "staff"), ITEMNAME_SIZE ); + strncat( buff, (item_is_rod( *this ) ? "rod" : "staff"), ITEMNAME_SIZE ); - if (item_type_known(item)) + if (item_type_known(*this)) { strncat(buff, " of ", ITEMNAME_SIZE ); @@ -1747,14 +1713,14 @@ static const char *item_name_2( : "bugginess", ITEMNAME_SIZE ); } - if (item_is_rod( item ) - && item_type_known(item)) + if (item_is_rod( *this ) + && item_type_known(*this)) { strncat( buff, " (", ITEMNAME_SIZE ); - itoa( item.plus / ROD_CHARGE_MULT, tmp_quant, 10 ); + itoa( this->plus / ROD_CHARGE_MULT, tmp_quant, 10 ); strncat( buff, tmp_quant, ITEMNAME_SIZE ); strncat( buff, "/", ITEMNAME_SIZE ); - itoa( item.plus2 / ROD_CHARGE_MULT, tmp_quant, 10 ); + itoa( this->plus2 / ROD_CHARGE_MULT, tmp_quant, 10 ); strncat( buff, tmp_quant, ITEMNAME_SIZE ); strncat( buff, ")", ITEMNAME_SIZE ); } @@ -1764,34 +1730,7 @@ static const char *item_name_2( // rearranged 15 Apr 2000 {dlb}: case OBJ_ORBS: - strncpy( buff, "Orb of ", ITEMNAME_SIZE ); - strncat( buff, (item_typ == ORB_ZOT) ? "Zot" : -/* ****************************************************************** - (item_typ == 1) ? "Zug" : - (item_typ == 2) ? "Xob" : - (item_typ == 3) ? "Ix" : - (item_typ == 4) ? "Xug" : - (item_typ == 5) ? "Zob" : - (item_typ == 6) ? "Ik" : - (item_typ == 7) ? "Grolp" : - (item_typ == 8) ? "fo brO ehT" : - (item_typ == 9) ? "Plob" : - (item_typ == 10) ? "Zuggle-Glob" : - (item_typ == 11) ? "Zin" : - (item_typ == 12) ? "Qexigok" : - (item_typ == 13) ? "Bujuk" : - (item_typ == 14) ? "Uhen Tiquritu" : - (item_typ == 15) ? "Idohoxom Sovuf" : - (item_typ == 16) ? "Voc Vocilicoso" : - (item_typ == 17) ? "Chanuaxydiviha" : - (item_typ == 18) ? "Ihexodox" : - (item_typ == 19) ? "Rynok Pol" : - (item_typ == 20) ? "Nemelex" : - (item_typ == 21) ? "Sif Muna" : - (item_typ == 22) ? "Okawaru" : - (item_typ == 23) ? "Kikubaaqudgha" : -****************************************************************** */ - "Bugginess", ITEMNAME_SIZE ); // change back to "Zot" if source of problems cannot be found {dlb} + strncpy(buff, "Orb of Zot", ITEMNAME_SIZE); break; case OBJ_GOLD: @@ -1804,7 +1743,7 @@ static const char *item_name_2( // rearranged 15 Apr 2000 {dlb}: case OBJ_CORPSES: - if (item_typ == CORPSE_BODY && item.special < 100) + if (item_typ == CORPSE_BODY && this->special < 100) strncat(buff, "rotting ", ITEMNAME_SIZE ); moname( it_plus, true, DESC_PLAIN, tmp_buff ); @@ -1821,10 +1760,10 @@ static const char *item_name_2( } // end of switch? // Disambiguation - if (!terse && item_type_known(item)) + if (!terse && item_type_known(*this)) { #define name_append(x) strncat(buff, x, ITEMNAME_SIZE) - switch (item_clas) + switch (this->base_type) { case OBJ_STAVES: switch (item_typ) @@ -1872,7 +1811,7 @@ static const char *item_name_2( char ugug[20]; strncat(buff, "bad item (cl:", ITEMNAME_SIZE ); - itoa(item_clas, ugug, 10); + itoa(this->base_type, ugug, 10); strncat(buff, ugug, ITEMNAME_SIZE ); strncat(buff, ",ty:", ITEMNAME_SIZE ); itoa(item_typ, ugug, 10); @@ -1884,27 +1823,25 @@ static const char *item_name_2( itoa(item_plus2, ugug, 10); strncat(buff, ugug, ITEMNAME_SIZE ); strncat(buff, ",sp:", ITEMNAME_SIZE ); - itoa(item.special, ugug, 10); + itoa(this->special, ugug, 10); strncat(buff, ugug, ITEMNAME_SIZE ); strncat(buff, ",qu:", ITEMNAME_SIZE ); - itoa(it_quant, ugug, 10); + itoa(this->quantity, ugug, 10); strncat(buff, ugug, ITEMNAME_SIZE ); strncat(buff, ")", ITEMNAME_SIZE ); } // hackish {dlb} - if (it_quant > 1 - && item_clas != OBJ_MISSILES - && item_clas != OBJ_SCROLLS - && item_clas != OBJ_POTIONS - && item_clas != OBJ_MISCELLANY - && (item_clas != OBJ_FOOD || item_typ != FOOD_CHUNK)) + if (this->quantity > 1 + && this->base_type != OBJ_MISSILES + && this->base_type != OBJ_SCROLLS + && this->base_type != OBJ_POTIONS + && this->base_type != OBJ_MISCELLANY + && (this->base_type != OBJ_FOOD || item_typ != FOOD_CHUNK)) { strncat(buff, "s", ITEMNAME_SIZE ); } - - return (buff); -} // end item_name_2() +} void save_id(id_arr identy, bool saving_game) { @@ -1987,7 +1924,7 @@ static MenuEntry *discoveries_item_mangle(MenuEntry *me) { InvEntry *ie = dynamic_cast(me); MenuEntry *newme = new MenuEntry; - std::string txt = item_name(*ie->item, DESC_PLAIN); + const std::string txt = ie->item->name(DESC_PLAIN); newme->text = " " + txt; newme->quantity = 0; delete me; @@ -2335,15 +2272,14 @@ static char retlet( int sed ) return (consonants[ sed % (sizeof(consonants) - 1) ]); } -bool is_interesting_item( const item_def& item ) { +bool is_interesting_item( const item_def& item ) +{ if ( is_random_artefact(item) || is_unrandom_artefact(item) || is_fixed_artefact(item) ) return true; - char name[ITEMNAME_SIZE]; - item_name(item, DESC_PLAIN, name, false); - std::string iname(name); + const std::string iname = item.name(DESC_PLAIN); for (unsigned i = 0; i < Options.note_items.size(); ++i) if (Options.note_items[i].matches(iname)) return true; diff --git a/crawl-ref/source/itemname.h b/crawl-ref/source/itemname.h index a264c6fbe4..e42ecce3ad 100644 --- a/crawl-ref/source/itemname.h +++ b/crawl-ref/source/itemname.h @@ -24,16 +24,6 @@ bool is_vowel( const char chr ); char get_ident_type(char cla, int ty); -/* *********************************************************************** - * called from: acr - chardump - direct - effects - fight - invent - - * it_use2 - item_use - items - monstuff - mstuff2 - ouch - - * shopping - spells1 - spells2 - spells3 - * *********************************************************************** */ -const char *item_name( const item_def &item, char descrip, - char *buff = NULL, - bool terse = false ); - - /* *********************************************************************** * called from: debug - describe - dungeon - fight - files - item_use - * monstuff - mstuff2 - players - spells0 @@ -53,24 +43,8 @@ void check_item_knowledge(void); void clear_ids(void); -/* *********************************************************************** - * called from: direct - fight - food - items - monstuff - religion - - * shopping - * *********************************************************************** */ -const char *it_name(int itn, char des, char *buff = NULL, bool terse = false); - -/* *********************************************************************** - * called from: acr - chardump - command - effects - fight - invent - - * it_use2 - it_use3 - item_use - items - ouch - output - - * spell - spells1 - spells2 - spells3 - spells4 - transfor - * *********************************************************************** */ -const char *in_name(int inn, char des, char *buff = NULL, bool terse = false); - -/* *********************************************************************** - * called from: itemname.cc items.cc item_use.cc mstuff2.cc - * *********************************************************************** */ -const char *quant_name( const item_def &item, int quant, char des, - char buff[ITEMNAME_SIZE], bool terse = false ); +std::string quant_name( const item_def &item, int quant, + description_level_type des, bool terse = false ); /* *********************************************************************** * bit operations called from a large number of files diff --git a/crawl-ref/source/itemprop.cc b/crawl-ref/source/itemprop.cc index 00bef2feaa..6059fff200 100644 --- a/crawl-ref/source/itemprop.cc +++ b/crawl-ref/source/itemprop.cc @@ -458,17 +458,13 @@ bool item_ident( const item_def &item, unsigned long flags ) void set_ident_flags( item_def &item, unsigned long flags ) { - bool known_before = fully_identified(item); + const bool known_before = fully_identified(item); item.flags |= flags; - if ( !known_before && fully_identified(item) ) { + if ( !known_before && fully_identified(item) && is_interesting_item(item)) + { /* make a note of it */ - if ( is_interesting_item(item) ) { - char buf[ITEMNAME_SIZE]; - char buf2[ITEMNAME_SIZE]; - item_name( item, DESC_NOCAP_A, buf ); - strcpy(buf2, origin_desc(item).c_str()); - take_note(Note(NOTE_ID_ITEM, 0, 0, buf, buf2)); - } + take_note(Note(NOTE_ID_ITEM, 0, 0, item.name(DESC_NOCAP_A).c_str(), + origin_desc(item).c_str())); } } diff --git a/crawl-ref/source/items.cc b/crawl-ref/source/items.cc index 7eb0fa1363..e06ebe4c13 100644 --- a/crawl-ref/source/items.cc +++ b/crawl-ref/source/items.cc @@ -797,9 +797,7 @@ void item_check(char keyin) } else { - char str_pass[ ITEMNAME_SIZE ]; - it_name(objl, DESC_NOCAP_A, str_pass); - strcpy(item_show[counter], str_pass); + strcpy(item_show[counter], mitm[objl].name(DESC_NOCAP_A).c_str()); } } @@ -967,7 +965,7 @@ static int first_corpse_monnum(int x, int y) #ifdef DGL_MILESTONES static std::string milestone_rune(const item_def &item) { - return std::string("found ") + item_name( item, DESC_NOCAP_A ) + "."; + return std::string("found ") + item.name(DESC_NOCAP_A) + "."; } static void milestone_check(const item_def &item) @@ -1198,7 +1196,6 @@ void pickup() { int m = 0; int keyin = 'x'; - char str_pass[ ITEMNAME_SIZE ]; if (you.attribute[ATTR_TRANSFORMATION] == TRAN_AIR && you.duration[DUR_TRANSFORMATION] > 0) @@ -1231,25 +1228,24 @@ void pickup() { if (!is_valid_item( you.inv[m] )) { - you.inv[m].base_type = OBJ_MISCELLANY; - you.inv[m].sub_type = MISC_PORTABLE_ALTAR_OF_NEMELEX; - you.inv[m].plus = 0; - you.inv[m].plus2 = 0; - you.inv[m].special = 0; - you.inv[m].colour = LIGHTMAGENTA; - you.inv[m].quantity = 1; - you.inv[m].inscription = you.last_altar_inscription; - set_ident_flags( you.inv[m], ISFLAG_IDENT_MASK ); - - you.inv[m].x = -1; - you.inv[m].y = -1; - you.inv[m].link = m; + item_def& item = you.inv[m]; + item.base_type = OBJ_MISCELLANY; + item.sub_type = MISC_PORTABLE_ALTAR_OF_NEMELEX; + item.plus = 0; + item.plus2 = 0; + item.special = 0; + item.colour = LIGHTMAGENTA; + item.quantity = 1; + item.inscription = you.last_altar_inscription; + set_ident_flags( item, ISFLAG_IDENT_MASK ); + + item.x = -1; + item.y = -1; + item.link = m; burden_change(); - in_name( m, DESC_INVENTORY_EQUIP, str_pass ); - strcpy( info, str_pass ); - mpr( info ); + mpr( item.name(DESC_INVENTORY_EQUIP).c_str() ); break; } } @@ -1294,9 +1290,8 @@ void pickup() if (keyin != 'a') { - char buf[ITEMNAME_SIZE]; - item_name( mitm[o], DESC_NOCAP_A, buf ); - snprintf( info, INFO_SIZE, "Pick up %s? (y/n/a/*?g,/q)", buf ); + snprintf( info, INFO_SIZE, "Pick up %s? (y/n/a/*?g,/q)", + mitm[o].name(DESC_NOCAP_A).c_str() ); mpr( info, MSGCH_PROMPT ); keyin = get_ch(); } @@ -1551,10 +1546,7 @@ int move_item_to_player( int obj, int quant_got, bool quiet ) burden_change(); if (!quiet) - { - in_name( m, DESC_INVENTORY, info ); - mpr(info); - } + mpr( you.inv[m].name(DESC_INVENTORY).c_str() ); you.turn_is_over = true; @@ -1594,10 +1586,7 @@ int move_item_to_player( int obj, int quant_got, bool quiet ) burden_change(); if (!quiet) - { - in_name( freeslot, DESC_INVENTORY, info ); - mpr(info); - } + mpr( you.inv[freeslot].name(DESC_INVENTORY).c_str() ); if (Options.tutorial_left) { @@ -1833,9 +1822,8 @@ bool drop_item( int item_dropped, int quant_drop, bool try_offer ) return (false); } - char str_pass[ ITEMNAME_SIZE ]; - quant_name( you.inv[item_dropped], quant_drop, DESC_NOCAP_A, str_pass ); - mprf( "You drop %s.", str_pass ); + mprf("You drop %s.", + quant_name(you.inv[item_dropped], quant_drop, DESC_NOCAP_A).c_str()); if ( grid_destroys_items(my_grid) ) mprf(MSGCH_SOUND, grid_item_destruction_message(my_grid)); @@ -2628,12 +2616,10 @@ void handle_time( long time_delta ) if (random2(100) < total_skill) { - set_ident_flags( you.inv[you.equip[EQ_WEAPON]], ISFLAG_IDENT_MASK ); + item_def& item = you.inv[you.equip[EQ_WEAPON]]; + set_ident_flags( item, ISFLAG_IDENT_MASK ); - char str_pass[ ITEMNAME_SIZE ]; - in_name(you.equip[EQ_WEAPON], DESC_NOCAP_A, str_pass); - snprintf( info, INFO_SIZE, "You are wielding %s.", str_pass ); - mpr(info); + mprf("You are wielding %s.", item.name(DESC_NOCAP_A).c_str()); more(); you.wield_change = true; @@ -2796,12 +2782,9 @@ void handle_time( long time_delta ) static void autoinscribe_item( item_def& item ) { - char name[ITEMNAME_SIZE]; - item_name(item, DESC_INVENTORY, name, false); - - std::string iname = name; + std::string iname = item.name(DESC_INVENTORY); - /* if there's an inscription already do nothing */ + /* if there's an inscription already, do nothing */ if ( item.inscription.size() > 0 ) return; @@ -2809,6 +2792,8 @@ static void autoinscribe_item( item_def& item ) { if ( Options.autoinscriptions[i].first.matches(iname) ) { + // Note that this might cause the item inscription to + // pass 80 characters. item.inscription += Options.autoinscriptions[i].second; } } @@ -2816,7 +2801,7 @@ static void autoinscribe_item( item_def& item ) static bool is_denied_autopickup(const item_def &item) { - std::string iname = item_name(item, DESC_PLAIN); + const std::string iname = item.name(DESC_PLAIN); for (unsigned i = 0, size = Options.never_pickup.size(); i < size; ++i) { if (Options.never_pickup[i].matches(iname)) @@ -2827,7 +2812,7 @@ static bool is_denied_autopickup(const item_def &item) static bool is_forced_autopickup(const item_def &item) { - std::string iname = item_name(item, DESC_PLAIN); + const std::string iname = item.name(DESC_PLAIN); for (unsigned i = 0, size = Options.always_pickup.size(); i < size; ++i) { if (Options.always_pickup[i].matches(iname)) @@ -3031,12 +3016,12 @@ static bool find_subtype_by_name(item_def &item, int type_wanted = -1; int best_index = 10000; - char obj_name[ITEMNAME_SIZE]; const char *ptr; for (int i = 0; i < ntypes; i++) { - item.sub_type = i; - item_name( item, DESC_PLAIN, obj_name ); + item.sub_type = i; + char obj_name[ITEMNAME_SIZE]; + strncpy(obj_name, item.name(DESC_PLAIN).c_str(), sizeof obj_name); ptr = strstr( strlwr(obj_name), name.c_str() ); if (ptr != NULL) @@ -3144,7 +3129,6 @@ item_def find_item_type(int base_type, std::string name) void cmd_destroy_item( void ) { int i; - char str_pass[ ITEMNAME_SIZE ]; // ask the item to destroy int item = prompt_invent_item( "Destroy which item? ", -1, true, false ); @@ -3163,15 +3147,14 @@ void cmd_destroy_item( void ) } // ask confirmation - // quant_name(you.inv[item], you.inv[item].quantity, DESC_NOCAP_A, str_pass ); - item_name( you.inv[item], DESC_NOCAP_THE, str_pass ); - snprintf( info, INFO_SIZE, "Destroy %s? ", str_pass ); + snprintf( info, INFO_SIZE, "Destroy %s? ", + you.inv[item].name(DESC_NOCAP_THE).c_str() ); if (yesno( info, true )) { //destroy it!! - snprintf( info, INFO_SIZE, "You destroy %s.", str_pass ); - mpr( info ); + mprf( "You destroy %s.", + you.inv[item].name(DESC_NOCAP_THE).c_str() ); dec_inv_item_quantity( item, you.inv[item].quantity ); burden_change(); } diff --git a/crawl-ref/source/makeitem.cc b/crawl-ref/source/makeitem.cc index 7d24aa0d47..7137a31c70 100644 --- a/crawl-ref/source/makeitem.cc +++ b/crawl-ref/source/makeitem.cc @@ -55,7 +55,7 @@ static int newwave_weapon_colour(const item_def &item) int item_colour = BLACK; // fixed artefacts get predefined colours - std::string itname = item_name( item, DESC_PLAIN ); + std::string itname = item.name(DESC_PLAIN); lowercase(itname); const bool item_runed = itname.find(" runed ") != std::string::npos; diff --git a/crawl-ref/source/mon-util.cc b/crawl-ref/source/mon-util.cc index a3cd33daa2..cb35349277 100644 --- a/crawl-ref/source/mon-util.cc +++ b/crawl-ref/source/mon-util.cc @@ -1371,7 +1371,8 @@ std::string str_monam(const monsters *mon, description_level_type desc, } /* ------------------------- monam/moname ------------------------- */ -const char *ptr_monam( const monsters *mon, char desc, bool force_seen ) +const char *ptr_monam( const monsters *mon, description_level_type desc, + bool force_seen ) { // We give an item type description for mimics now, note that // since gold mimics only have one description (to match the @@ -1379,11 +1380,13 @@ const char *ptr_monam( const monsters *mon, char desc, bool force_seen ) // this for them. -- bwr if (mons_is_mimic( mon->type ) && mon->type != MONS_GOLD_MIMIC) { + // XXX Ugly hack - FIXME XXX static char mimic_name_buff[ ITEMNAME_SIZE ]; item_def item; get_mimic_item( mon, item ); - item_name( item, desc, mimic_name_buff ); + strncpy(mimic_name_buff, item.name(desc).c_str(), + sizeof mimic_name_buff); return (mimic_name_buff); } @@ -1394,7 +1397,8 @@ const char *ptr_monam( const monsters *mon, char desc, bool force_seen ) } const char *monam( const monsters *mon, - int mons_num, int mons, bool vis, char desc, int mons_wpn ) + int mons_num, int mons, bool vis, + description_level_type desc, int mons_wpn ) { static char gmo_n[ ITEMNAME_SIZE ]; char gmo_n2[ ITEMNAME_SIZE ] = ""; @@ -1427,6 +1431,7 @@ const char *monam( const monsters *mon, strcpy(gmo_n, "a"); break; case DESC_PLAIN: /* do nothing */ ; + default: break; //default: DEBUGSTR("bad desc flag"); } @@ -1493,7 +1498,7 @@ const char *monam( const monsters *mon, { item_def item = mitm[mons_wpn]; unset_ident_flags( item, ISFLAG_KNOW_CURSE | ISFLAG_KNOW_PLUSES ); - item_name( item, desc, gmo_n ); + strncpy( gmo_n, item.name(desc).c_str(), sizeof gmo_n ); } break; @@ -1514,7 +1519,8 @@ const char *monam( const monsters *mon, return (gmo_n); } // end monam() -const char *moname(int mons_num, bool vis, char descrip, char glog[ ITEMNAME_SIZE ]) +const char *moname(int mons_num, bool vis, description_level_type descrip, + char glog[ ITEMNAME_SIZE ]) { glog[0] = 0; @@ -1540,6 +1546,8 @@ const char *moname(int mons_num, bool vis, char descrip, char glog[ ITEMNAME_SIZ case DESC_CAP_YOUR: strcpy(glog, "Its"); break; + default: + strcpy(glog, "Its buggy"); } strcpy(gmon_name, glog); @@ -1565,6 +1573,7 @@ const char *moname(int mons_num, bool vis, char descrip, char glog[ ITEMNAME_SIZ strcpy(glog, "a"); break; case DESC_PLAIN: + default: break; // default: DEBUGSTR("bad monster descrip flag"); } diff --git a/crawl-ref/source/mon-util.h b/crawl-ref/source/mon-util.h index 92efc1a444..a66fa48580 100644 --- a/crawl-ref/source/mon-util.h +++ b/crawl-ref/source/mon-util.h @@ -129,14 +129,14 @@ void init_monsters( FixedVector& colour ); * *********************************************************************** */ // mons_wpn only important for dancing weapons -- bwr const char *monam(const monsters *mon, - int mons_num, int mons, bool vis, char desc, - int mons_wpn = NON_ITEM); + int mons_num, int mons, bool vis, + description_level_type desc, int mons_wpn = NON_ITEM); // these front for monam -const char *ptr_monam(const monsters *mon, char desc, bool force_seen = false); +const char *ptr_monam(const monsters *mon, description_level_type desc, + bool force_seen = false); std::string str_monam(const monsters *mon, description_level_type desc, bool force_seen = false); - // last updated 12may2000 {dlb} /* *********************************************************************** @@ -349,7 +349,8 @@ void define_monster(int mid); /* *********************************************************************** * called from: debug - itemname - mon-util * *********************************************************************** */ -const char *moname(int mcl, bool vis, char descrip, char glog[ ITEMNAME_SIZE ]); +const char *moname(int mcl, bool vis, description_level_type descrip, + char glog[ ITEMNAME_SIZE ]); #ifdef DEBUG_DIAGNOSTICS diff --git a/crawl-ref/source/monstuff.cc b/crawl-ref/source/monstuff.cc index 9dc3e235c0..95398e679c 100644 --- a/crawl-ref/source/monstuff.cc +++ b/crawl-ref/source/monstuff.cc @@ -2635,9 +2635,6 @@ static bool handle_wand(monsters *monster, bolt &beem) int power = 30 + monster->hit_dice; bolt theBeam = mons_spells(mzap, power); - // XXX: ugly hack this: - static char wand_buff[ ITEMNAME_SIZE ]; - beem.name = theBeam.name; beem.beam_source = monster_index(monster); beem.source_x = monster->x; @@ -2663,9 +2660,7 @@ static bool handle_wand(monsters *monster, bolt &beem) set_ident_flags( item, ISFLAG_KNOW_TYPE ); #endif - item_name( item, DESC_PLAIN, wand_buff ); - - beem.aux_source = wand_buff; + beem.aux_source = item.name(DESC_PLAIN); switch (mitm[monster->inv[MSLOT_WAND]].sub_type) { @@ -3808,7 +3803,6 @@ static bool monster_wants_weapon(const monsters *monster, const item_def &weap) static bool handle_pickup(monsters *monster) { // single calculation permissible {dlb} - char str_pass[ ITEMNAME_SIZE ]; bool monsterNearby = mons_near(monster); int item = NON_ITEM; @@ -3931,12 +3925,8 @@ static bool handle_pickup(monsters *monster) if (monsterNearby) { - strcpy(info, ptr_monam(monster, DESC_CAP_THE)); - strcat(info, " picks up "); - it_name(monster->inv[MSLOT_WEAPON], DESC_NOCAP_A, str_pass); - strcat(info, str_pass); - strcat(info, "."); - mpr(info); + mprf("%s picks up %s.", ptr_monam(monster, DESC_CAP_THE), + mitm[monster->inv[MSLOT_WEAPON]].name(DESC_NOCAP_A).c_str()); } break; @@ -3952,12 +3942,8 @@ static bool handle_pickup(monsters *monster) { if (monsterNearby) { - strcpy(info, ptr_monam(monster, DESC_CAP_THE)); - strcat(info, " picks up "); - it_name(item, DESC_NOCAP_A, str_pass); - strcat(info, str_pass); - strcat(info, "."); - mpr(info); + mprf("%s picks up %s.", ptr_monam(monster, DESC_CAP_THE), + mitm[item].name(DESC_NOCAP_A).c_str()); } inc_mitm_item_quantity( monster->inv[MSLOT_MISSILE], @@ -3979,12 +3965,8 @@ static bool handle_pickup(monsters *monster) if (monsterNearby) { - strcpy(info, ptr_monam(monster, DESC_CAP_THE)); - strcat(info, " picks up "); - it_name(monster->inv[MSLOT_MISSILE], DESC_NOCAP_A, str_pass); - strcat(info, str_pass); - strcat(info, "."); - mpr(info); + mprf("%s picks up %s.", ptr_monam(monster, DESC_CAP_THE), + mitm[item].name(DESC_NOCAP_A).c_str()); } break; @@ -3996,12 +3978,8 @@ static bool handle_pickup(monsters *monster) if (monsterNearby) { - strcpy(info, ptr_monam(monster, DESC_CAP_THE)); - strcat(info, " picks up "); - it_name(monster->inv[MSLOT_WAND], DESC_NOCAP_A, str_pass); - strcat(info, str_pass); - strcat(info, "."); - mpr(info); + mprf("%s picks up %s.", ptr_monam(monster, DESC_CAP_THE), + mitm[item].name(DESC_NOCAP_A).c_str()); } break; @@ -4013,12 +3991,8 @@ static bool handle_pickup(monsters *monster) if (monsterNearby) { - strcpy(info, ptr_monam(monster, DESC_CAP_THE)); - strcat(info, " picks up "); - it_name(monster->inv[MSLOT_SCROLL], DESC_NOCAP_A, str_pass); - strcat(info, str_pass); - strcat(info, "."); - mpr(info); + mprf("%s picks up %s.", ptr_monam(monster, DESC_CAP_THE), + mitm[item].name(DESC_NOCAP_A).c_str()); } break; @@ -4030,12 +4004,8 @@ static bool handle_pickup(monsters *monster) if (monsterNearby) { - strcpy(info, ptr_monam(monster, DESC_CAP_THE)); - strcat(info, " picks up "); - it_name(monster->inv[MSLOT_POTION], DESC_NOCAP_A, str_pass); - strcat(info, str_pass); - strcat(info, "."); - mpr(info); + mprf("%s picks up %s.", ptr_monam(monster, DESC_CAP_THE), + mitm[item].name(DESC_NOCAP_A).c_str()); } break; @@ -4043,7 +4013,7 @@ static bool handle_pickup(monsters *monster) if (monster->type != MONS_NECROPHAGE && monster->type != MONS_GHOUL) return (false); - monster->hit_points += 1 + random2(mons_weight(mitm[item].plus)) / 100; + monster->hit_points += 1 + random2(mons_weight(mitm[item].plus))/100; // limited growth factor here -- should 77 really be the cap? {dlb}: if (monster->hit_points > 100) @@ -4054,12 +4024,8 @@ static bool handle_pickup(monsters *monster) if (monsterNearby) { - strcpy(info, ptr_monam(monster, DESC_CAP_THE)); - strcat(info, " eats "); - it_name(item, DESC_NOCAP_THE, str_pass); - strcat(info, str_pass); - strcat(info, "."); - mpr(info); + mprf("%s eats %s.", ptr_monam(monster, DESC_CAP_THE), + mitm[item].name(DESC_NOCAP_THE).c_str()); } destroy_item( item ); diff --git a/crawl-ref/source/mstuff2.cc b/crawl-ref/source/mstuff2.cc index c523a5c352..99b4a6a6be 100644 --- a/crawl-ref/source/mstuff2.cc +++ b/crawl-ref/source/mstuff2.cc @@ -1242,13 +1242,10 @@ bool mons_throw(struct monsters *monster, struct bolt &pbolt, int hand_used) else { // build shoot message - char str_pass[ ITEMNAME_SIZE ]; - item_name( item, DESC_NOCAP_A, str_pass ); - strcat(info, str_pass); + strcat(info, item.name(DESC_NOCAP_A).c_str()); // build beam name - item_name( item, DESC_PLAIN, str_pass ); - pbolt.name = str_pass; + pbolt.name = item.name(DESC_PLAIN); } strcat(info, "."); diff --git a/crawl-ref/source/newgame.cc b/crawl-ref/source/newgame.cc index f6521f9302..36e40c5b7c 100644 --- a/crawl-ref/source/newgame.cc +++ b/crawl-ref/source/newgame.cc @@ -1449,10 +1449,8 @@ static void choose_book( item_def& book, int firstbook, int numbooks ) for (int i=0; i < numbooks; ++i) { - char buf[ITEMNAME_SIZE]; book.sub_type = firstbook + i; - item_name( book, DESC_PLAIN, buf ); - cprintf("%c - %s" EOL, 'a' + i, buf); + cprintf("%c - %s" EOL, 'a' + i, book.name(DESC_PLAIN).c_str()); } textcolor(BROWN); diff --git a/crawl-ref/source/ouch.cc b/crawl-ref/source/ouch.cc index db94e5d87e..41fd58617b 100644 --- a/crawl-ref/source/ouch.cc +++ b/crawl-ref/source/ouch.cc @@ -74,8 +74,8 @@ #include "view.h" -void end_game( struct scorefile_entry &se ); -void item_corrode( char itco ); +static void end_game( scorefile_entry &se ); +static void item_corrode( int itco ); /* NOTE: DOES NOT check for hellfire!!! */ @@ -319,7 +319,7 @@ void weapon_acid( char acid_strength ) } } // end weapon_acid() -void item_corrode( char itco ) +void item_corrode( int itco ) { int chance_corr = 0; // no idea what its full range is {dlb} bool it_resists = false; // code simplifier {dlb} @@ -340,17 +340,18 @@ void item_corrode( char itco ) if (how_rusty < -5) return; + item_def& item = you.inv[itco]; // determine possibility of resistance by object type {dlb}: - switch (you.inv[itco].base_type) + switch (item.base_type) { case OBJ_ARMOUR: - if (is_random_artefact( you.inv[itco] )) + if (is_random_artefact( item )) { it_resists = true; suppress_msg = true; } - else if ((you.inv[itco].sub_type == ARM_CRYSTAL_PLATE_MAIL - || get_equip_race(you.inv[itco]) == ISFLAG_DWARVEN) + else if ((item.sub_type == ARM_CRYSTAL_PLATE_MAIL + || get_equip_race(item) == ISFLAG_DWARVEN) && !one_chance_in(5)) { it_resists = true; @@ -359,13 +360,13 @@ void item_corrode( char itco ) break; case OBJ_WEAPONS: - if (is_fixed_artefact(you.inv[itco]) - || is_random_artefact(you.inv[itco])) + if (is_fixed_artefact(item) + || is_random_artefact(item)) { it_resists = true; suppress_msg = true; } - else if (get_equip_race(you.inv[itco]) == ISFLAG_DWARVEN + else if (get_equip_race(item) == ISFLAG_DWARVEN && !one_chance_in(5)) { it_resists = true; @@ -374,7 +375,7 @@ void item_corrode( char itco ) break; case OBJ_MISSILES: - if (get_equip_race(you.inv[itco]) == ISFLAG_DWARVEN + if (get_equip_race(item) == ISFLAG_DWARVEN && !one_chance_in(5)) { it_resists = true; @@ -402,7 +403,7 @@ void item_corrode( char itco ) if (chance_corr >= 0 && chance_corr <= 4) { it_resists = (random2(100) < - 2 + (2 << (1 + chance_corr)) + (chance_corr * 8)); + 2 + (4 << chance_corr) + (chance_corr * 8)); } else it_resists = true; // no idea how often this occurs {dlb} @@ -414,21 +415,18 @@ void item_corrode( char itco ) // handle message output and item damage {dlb}: if (!suppress_msg) { - char str_pass[ ITEMNAME_SIZE ]; - in_name(itco, DESC_CAP_YOUR, str_pass); - strcpy(info, str_pass); - strcat(info, (it_resists) ? " resists." : " is eaten away!"); - mpr(info); + mprf("%s %s", item.name(DESC_CAP_YOUR).c_str(), + (it_resists) ? " resists." : " is eaten away!"); } if (!it_resists) { how_rusty--; - if (you.inv[itco].base_type == OBJ_WEAPONS) - you.inv[itco].plus2 = how_rusty; + if (item.base_type == OBJ_WEAPONS) + item.plus2 = how_rusty; else - you.inv[itco].plus = how_rusty; + item.plus = how_rusty; you.redraw_armour_class = 1; // for armour, rings, etc. {dlb} diff --git a/crawl-ref/source/output.cc b/crawl-ref/source/output.cc index ede63e2a61..cccf6e9469 100644 --- a/crawl-ref/source/output.cc +++ b/crawl-ref/source/output.cc @@ -337,28 +337,24 @@ void print_stats(void) cprintf(" "); #endif + gotoxy(40, 13); + if (you.equip[EQ_WEAPON] != -1) { - gotoxy(40, 13); - textcolor(you.inv[you.equip[EQ_WEAPON]].colour); - char str_pass[ ITEMNAME_SIZE ]; - in_name( you.equip[EQ_WEAPON], DESC_INVENTORY, str_pass, false ); - int prefcol = menu_colour(str_pass); + const item_def& wpn = you.inv[you.equip[EQ_WEAPON]]; + textcolor(wpn.colour); + + const int prefcol = menu_colour(wpn.name(DESC_INVENTORY)); if (prefcol != -1) textcolor(prefcol); - in_name( you.equip[EQ_WEAPON], DESC_INVENTORY, str_pass, - Options.terse_hand ); - str_pass[39] = 0; - - cprintf("%s", str_pass); + cprintf("%s", + wpn.name(DESC_INVENTORY, Options.terse_hand).c_str()); textcolor(LIGHTGREY); } else { - gotoxy(40, 13); - if (you.attribute[ATTR_TRANSFORMATION] == TRAN_BLADE_HANDS) { textcolor(RED); @@ -855,7 +851,6 @@ std::vector get_full_detail(bool calc_unid) cols.add_formatted(1, buf, true); { - char str_pass[ITEMNAME_SIZE]; const int e_order[] = { EQ_WEAPON, EQ_BODY_ARMOUR, EQ_SHIELD, EQ_HELMET, EQ_CLOAK, @@ -874,12 +869,11 @@ std::vector get_full_detail(bool calc_unid) if ( you.equip[ e_order[i] ] != -1) { - const int inum = you.equip[e_order[i]]; - in_name( inum, DESC_PLAIN, str_pass, true ); - str_pass[38] = 0; // truncate - const char* colname = colour_to_str(you.inv[inum].colour); + const item_def& item = you.inv[you.equip[e_order[i]]]; + const char* colname = colour_to_str(item.colour); snprintf(buf, sizeof buf, "%-7s: <%s>%s", - slot, colname, str_pass, colname); + slot, colname, + item.name(DESC_PLAIN).substr(0,38).c_str(), colname); } else { @@ -1262,7 +1256,6 @@ void print_overview_screen() cols.add_formatted(1, buf, false); { - char str_pass[ITEMNAME_SIZE]; const int e_order[] = { EQ_WEAPON, EQ_BODY_ARMOUR, EQ_SHIELD, EQ_HELMET, EQ_CLOAK, @@ -1281,12 +1274,11 @@ void print_overview_screen() if ( you.equip[ e_order[i] ] != -1) { - const int inum = you.equip[e_order[i]]; - in_name( inum, DESC_PLAIN, str_pass, true ); - str_pass[38] = 0; // truncate - const char* colname = colour_to_str(you.inv[inum].colour); + const item_def& item = you.inv[you.equip[e_order[i]]]; + const char* colname = colour_to_str(item.colour); snprintf(buf, sizeof buf, "%-7s: <%s>%s", - slot, colname, str_pass, colname); + slot, colname, + item.name(DESC_PLAIN).substr(0,37).c_str(), colname); } else { diff --git a/crawl-ref/source/religion.cc b/crawl-ref/source/religion.cc index f2aff8b816..319d39af0f 100644 --- a/crawl-ref/source/religion.cc +++ b/crawl-ref/source/religion.cc @@ -2519,7 +2519,8 @@ void offer_items() case GOD_OKAWARU: case GOD_MAKHLEB: case GOD_NEMELEX_XOBEH: - mprf("%s%s", it_name(i, DESC_CAP_THE), sacrifice[you.religion - 1]); + mprf("%s%s", mitm[i].name(DESC_CAP_THE).c_str(), + sacrifice[you.religion - 1]); #ifdef DEBUG_DIAGNOSTICS mprf(MSGCH_DIAGNOSTICS, "Sacrifice item value: %d", value); @@ -2536,7 +2537,8 @@ void offer_items() break; case GOD_SIF_MUNA: - mprf("%s%s", it_name(i, DESC_CAP_THE), sacrifice[you.religion - 1]); + mprf("%s%s", mitm[i].name(DESC_CAP_THE).c_str(), + sacrifice[you.religion - 1]); if (value >= 150) gain_piety(1 + random2(3)); @@ -2549,7 +2551,8 @@ void offer_items() if (mitm[i].base_type != OBJ_CORPSES) break; - mprf("%s%s", it_name(i, DESC_CAP_THE), sacrifice[you.religion - 1]); + mprf("%s%s", mitm[i].name(DESC_CAP_THE).c_str(), + sacrifice[you.religion - 1]); gain_piety(1); destroy_item(i); @@ -2562,7 +2565,8 @@ void offer_items() break; } - mprf("%s%s", it_name(i, DESC_CAP_THE), sacrifice[you.religion - 1]); + mprf("%s%s", mitm[i].name(DESC_CAP_THE).c_str(), + sacrifice[you.religion - 1]); if (random2(value) >= random2(50) || (mitm[i].base_type == OBJ_WEAPONS @@ -2672,11 +2676,8 @@ void god_pitch(unsigned char which_god) void offer_corpse(int corpse) { - char str_pass[ ITEMNAME_SIZE ]; - it_name(corpse, DESC_CAP_THE, str_pass); - strcpy(info, str_pass); - strcat(info, sacrifice[you.religion - 1]); - mpr(info); + mprf("%s%s", mitm[corpse].name(DESC_CAP_THE).c_str(), + sacrifice[you.religion - 1]); did_god_conduct(DID_DEDICATED_BUTCHERY, 10); } // end offer_corpse() diff --git a/crawl-ref/source/shopping.cc b/crawl-ref/source/shopping.cc index a5f46d5077..8092f69fde 100644 --- a/crawl-ref/source/shopping.cc +++ b/crawl-ref/source/shopping.cc @@ -199,8 +199,7 @@ char in_a_shop( char shoppy, id_arr id ) textcolor((i % 2) ? WHITE : LIGHTGREY); - it_name(itty, DESC_NOCAP_A, st_pass); - cprintf("%s", st_pass); + cprintf("%s", mitm[itty].name(DESC_NOCAP_A).c_str()); std::string desc; if (is_dumpable_artifact(mitm[itty], Options.verbose_dump)) @@ -315,7 +314,7 @@ char in_a_shop( char shoppy, id_arr id ) goto purchase; } snprintf(info, INFO_SIZE, "Purchase %s (%d gold)? [y/n]", - item_name(mitm[shop_items[ft]], DESC_NOCAP_A), gp_value); + mitm[shop_items[ft]].name(DESC_NOCAP_A).c_str(), gp_value); shop_print(info, 20); if ( yesno(NULL, true, 'n', false, false, true) ) { @@ -441,31 +440,31 @@ static void purchase( int shop, int item_got, int cost ) { you.gold -= cost; - origin_purchased(mitm[item_got]); + item_def& item = mitm[item_got]; - if ( fully_identified(mitm[item_got]) && - is_interesting_item(mitm[item_got]) ) { + origin_purchased(item); + if ( fully_identified(item) && is_interesting_item(item) ) + { activate_notes(true); - char buf[ITEMNAME_SIZE]; - char buf2[ITEMNAME_SIZE]; - item_name( mitm[item_got], DESC_NOCAP_A, buf ); - strcpy(buf2, origin_desc(mitm[item_got]).c_str()); - take_note(Note(NOTE_ID_ITEM, 0, 0, buf, buf2)); + take_note(Note(NOTE_ID_ITEM, 0, 0, + item.name(DESC_NOCAP_A).c_str(), + origin_desc(item).c_str())); activate_notes(false); } - int num = move_item_to_player( item_got, mitm[item_got].quantity, true ); + const int quant = item.quantity; + // note that item will be invalidated if num == item.quantity + const int num = move_item_to_player( item_got, item.quantity, true ); // Shopkeepers will now place goods you can't carry outside the shop. - if (num < mitm[item_got].quantity) + if (num < quant) { snprintf( info, INFO_SIZE, "I'll put %s outside for you.", - (mitm[item_got].quantity == 1) ? "it" : - (num > 0) ? "the rest" - : "these" ); + (quant == 1) ? "it" : + (num > 0) ? "the rest" : "these" ); shop_print( info, 20 ); more3(); diff --git a/crawl-ref/source/spells1.cc b/crawl-ref/source/spells1.cc index fe3a1beaa4..c4695d2c80 100644 --- a/crawl-ref/source/spells1.cc +++ b/crawl-ref/source/spells1.cc @@ -360,7 +360,6 @@ void identify(int power) { int id_used = 1; int item_slot; - char str_pass[ ITEMNAME_SIZE ]; // scrolls of identify *may* produce "extra" identifications {dlb}: if (power == -1 && one_chance_in(5)) @@ -383,8 +382,7 @@ void identify(int power) remove_empty_inscription(you.inv[item_slot]); // output identified item - in_name( item_slot, DESC_INVENTORY_EQUIP, str_pass ); - mpr( str_pass ); + mpr(you.inv[item_slot].name(DESC_INVENTORY_EQUIP).c_str()); if (item_slot == you.equip[EQ_WEAPON]) you.wield_change = true; diff --git a/crawl-ref/source/spells2.cc b/crawl-ref/source/spells2.cc index f042b7c674..5bd2c3dbe0 100644 --- a/crawl-ref/source/spells2.cc +++ b/crawl-ref/source/spells2.cc @@ -552,9 +552,7 @@ bool brand_weapon(int which_brand, int power) return false; } - char str_pass[ ITEMNAME_SIZE ]; - in_name( wpn, DESC_CAP_YOUR, str_pass ); - strcpy( info, str_pass ); + strcpy( info, you.inv[wpn].name(DESC_CAP_YOUR).c_str() ); const int wpn_type = get_vorpal_type(you.inv[wpn]); diff --git a/crawl-ref/source/spells3.cc b/crawl-ref/source/spells3.cc index 6611421703..3f7d4691f5 100644 --- a/crawl-ref/source/spells3.cc +++ b/crawl-ref/source/spells3.cc @@ -413,11 +413,10 @@ void simulacrum(int power) void dancing_weapon(int pow, bool force_hostile) { int numsc = cap_int(2 + (random2(pow) / 5), 6); - char str_pass[ ITEMNAME_SIZE ]; int i; int summs = 0; - char behavi = BEH_FRIENDLY; + beh_type behavi = BEH_FRIENDLY; const int wpn = you.equip[EQ_WEAPON]; @@ -463,10 +462,7 @@ void dancing_weapon(int pow, bool force_hostile) // Mark the weapon as thrown so we'll autograb it when the tango's done. mitm[i].flags |= ISFLAG_THROWN; - in_name( wpn, DESC_CAP_YOUR, str_pass ); - strcpy( info, str_pass ); - strcat( info, " dances into the air!" ); - mpr( info ); + mprf("%s dances into the air!", you.inv[wpn].name(DESC_CAP_YOUR).c_str()); you.inv[ wpn ].quantity = 0; you.equip[EQ_WEAPON] = -1; @@ -811,7 +807,6 @@ bool entomb(void) void cast_poison_ammo(void) { const int ammo = you.equip[EQ_WEAPON]; - char str_pass[ ITEMNAME_SIZE ]; if (ammo == -1 || you.inv[ammo].base_type != OBJ_MISSILES @@ -825,12 +820,9 @@ void cast_poison_ammo(void) if (set_item_ego_type( you.inv[ammo], OBJ_MISSILES, SPMSL_POISONED )) { - in_name(ammo, DESC_CAP_YOUR, str_pass); - strcpy(info, str_pass); - strcat(info, (you.inv[ammo].quantity == 1) ? " is" : " are"); - strcat(info, " covered in a thin film of poison."); - mpr(info); - + mprf("%s %s covered in a thin film of poison.", + you.inv[ammo].name(DESC_CAP_YOUR).c_str(), + (you.inv[ammo].quantity == 1) ? " is" : " are"); you.wield_change = true; } else diff --git a/crawl-ref/source/spells4.cc b/crawl-ref/source/spells4.cc index a5e3c7564f..8d89d88fbe 100644 --- a/crawl-ref/source/spells4.cc +++ b/crawl-ref/source/spells4.cc @@ -1078,7 +1078,8 @@ void cast_ignite_poison(int pow) { if (set_item_ego_type( you.inv[wpn], OBJ_WEAPONS, SPWPN_FLAMING )) { - mprf("%s bursts into flame!", in_name(wpn, DESC_CAP_YOUR)); + mprf("%s bursts into flame!", + you.inv[wpn].name(DESC_CAP_YOUR).c_str()); you.wield_change = true; you.duration[DUR_WEAPON_BRAND] += 1 + you.duration[DUR_WEAPON_BRAND] / 2; @@ -2031,8 +2032,6 @@ void cast_evaporate(int pow) // using up the corpse might also lead to game balance problems. -- bwr void cast_fulsome_distillation( int powc ) { - char str_pass[ ITEMNAME_SIZE ]; - if (powc > 50) powc = 50; @@ -2047,11 +2046,11 @@ void cast_fulsome_distillation( int powc ) curr_item != NON_ITEM; curr_item = mitm[curr_item].link) { - if (mitm[curr_item].base_type == OBJ_CORPSES - && mitm[curr_item].sub_type == CORPSE_BODY) + const item_def& item = mitm[curr_item]; + if (item.base_type == OBJ_CORPSES && item.sub_type == CORPSE_BODY) { - it_name( curr_item, DESC_NOCAP_THE, str_pass ); - snprintf( info, INFO_SIZE, "Distill a potion from %s?", str_pass ); + snprintf( info, INFO_SIZE, "Distill a potion from %s?", + item.name(DESC_NOCAP_THE).c_str() ); if (yesno( info, true, 0, false )) { @@ -2169,10 +2168,8 @@ void cast_fulsome_distillation( int powc ) mitm[corpse].plus2 = 0; item_colour( mitm[corpse] ); // sets special as well - it_name( corpse, DESC_NOCAP_A, str_pass ); - snprintf( info, INFO_SIZE, "You extract %s from the corpse.", - str_pass ); - mpr( info ); + mprf("You extract %s from the corpse.", + mitm[corpse].name(DESC_NOCAP_A).c_str()); // try to move the potion to the player (for convenience) if (move_item_to_player( corpse, 1 ) != 1) diff --git a/crawl-ref/source/spl-book.cc b/crawl-ref/source/spl-book.cc index ea75e16d0c..ef29a46937 100644 --- a/crawl-ref/source/spl-book.cc +++ b/crawl-ref/source/spl-book.cc @@ -714,9 +714,7 @@ unsigned char spellbook_contents( item_def &book, int action, formatted_string out; out.textcolor(LIGHTGREY); - char str_pass[ ITEMNAME_SIZE ]; - item_name( book, DESC_CAP_THE, str_pass ); - out.cprintf( "%s", str_pass ); + out.cprintf( "%s", book.name(DESC_CAP_THE).c_str() ); out.cprintf( EOL EOL " Spells Type Level" EOL ); diff --git a/crawl-ref/source/spl-cast.cc b/crawl-ref/source/spl-cast.cc index 125443d3fe..7a3f84d2dd 100644 --- a/crawl-ref/source/spl-cast.cc +++ b/crawl-ref/source/spl-cast.cc @@ -95,7 +95,7 @@ static bool surge_identify_boosters(int spell) ID_KNOWN_TYPE ); set_ident_flags(ring, ISFLAG_KNOW_PROPERTIES); mprf("You are wearing: %s", - item_name(ring, DESC_INVENTORY_EQUIP)); + ring.name(DESC_INVENTORY_EQUIP).c_str()); } } } @@ -776,17 +776,10 @@ void spellcasting_side_effects(spell_type spc2, bool idonly = false) if (random2(100) < total_skill) { - char str_pass[ ITEMNAME_SIZE ]; - + item_def& wpn = you.inv[you.equip[EQ_WEAPON]]; // changed from ISFLAG_KNOW_TYPE - set_ident_flags( you.inv[you.equip[EQ_WEAPON]], ISFLAG_IDENT_MASK); - - strcpy(info, "You are wielding "); - in_name(you.equip[EQ_WEAPON], DESC_NOCAP_A, str_pass); - strcat(info, str_pass); - strcat(info, "."); - mpr(info); - + set_ident_flags( wpn, ISFLAG_IDENT_MASK); + mprf("You are wielding %s.", wpn.name(DESC_NOCAP_A).c_str()); more(); you.wield_change = true; diff --git a/crawl-ref/source/stash.cc b/crawl-ref/source/stash.cc index dcac179e8b..fd0ead410b 100644 --- a/crawl-ref/source/stash.cc +++ b/crawl-ref/source/stash.cc @@ -355,11 +355,12 @@ std::string Stash::stash_item_name(const item_def &item) { char buf[ITEMNAME_SIZE]; + // XXX XXX FIXME why the special-casing? if (item.base_type == OBJ_GOLD) snprintf(buf, sizeof buf, "%d gold piece%s", item.quantity, (item.quantity > 1? "s" : "")); else - item_name(item, DESC_NOCAP_A, buf, false); + return item.name(DESC_NOCAP_A); return buf; } @@ -658,7 +659,7 @@ 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); snprintf(shopitem, sizeof shopitem, "%s (%u gold)", - itemname.c_str(), si.price); + itemname.c_str(), si.price); return shopitem; } diff --git a/crawl-ref/source/transfor.cc b/crawl-ref/source/transfor.cc index eed691ff5f..20b45f78b1 100644 --- a/crawl-ref/source/transfor.cc +++ b/crawl-ref/source/transfor.cc @@ -33,8 +33,6 @@ void extra_hp(int amount_extra); bool remove_equipment(FixedVector < char, 8 > &remove_stuff) { - char str_pass[ ITEMNAME_SIZE ]; - // if we're removing body armour, the cloak will come off as well -- bwr if (remove_stuff[EQ_BODY_ARMOUR] == 1 && you.equip[EQ_BODY_ARMOUR] != -1) remove_stuff[EQ_CLOAK] = 1; @@ -56,10 +54,8 @@ bool remove_equipment(FixedVector < char, 8 > &remove_stuff) if (remove_stuff[i] == 0 || you.equip[i] == -1) continue; - in_name( you.equip[i], DESC_CAP_YOUR, str_pass ); - - snprintf( info, INFO_SIZE, "%s falls away.", str_pass ); - mpr(info); + mprf("%s falls away.", + you.inv[you.equip[i]].name(DESC_CAP_YOUR).c_str()); unwear_armour( you.equip[i] ); you.equip[i] = -1; diff --git a/crawl-ref/source/travel.cc b/crawl-ref/source/travel.cc index 233a9dee60..ed0801e971 100644 --- a/crawl-ref/source/travel.cc +++ b/crawl-ref/source/travel.cc @@ -3445,13 +3445,13 @@ void explore_discoveries::add_item(const item_def &i) if (items_stack(i, items[j].thing)) { items[j].thing.quantity += i.quantity; - items[j].name = item_name(items[j].thing, DESC_NOCAP_A); + items[j].name = items[j].thing.name(DESC_NOCAP_A); return; } } } - items.push_back( named_thing(item_name(i, DESC_NOCAP_A), i) ); + items.push_back( named_thing(i.name(DESC_NOCAP_A), i) ); // first item of this type? // only works when travelling -- cgit v1.2.3-54-g00ecf