Move get_item_interesting_string() into the cItem class

This commit is contained in:
2023-01-19 09:32:07 -05:00
parent 7dcaa7d332
commit 2d1bbe0058
6 changed files with 64 additions and 64 deletions

View File

@@ -411,7 +411,7 @@ static void put_item_graphics(cDialog& me, size_t& first_item_shown, short& curr
if(item.graphic_num >= 1000)
pic.setPict(item.graphic_num - 1000, PIC_CUSTOM_ITEM);
else pic.setPict(item.graphic_num, PIC_ITEM);
me[detail].setText(get_item_interesting_string(item));
me[detail].setText(item.interesting_string());
me[weight].setText("Weight: " + std::to_string(item.item_weight()));
me[key].setText(key_stash);
} else { // erase the spot

View File

@@ -734,7 +734,7 @@ void draw_shop_graphics(bool pressed,rectangle clip_area_rect) {
switch(item.type) {
case eShopItemType::ITEM:
base_item.ident = true;
cur_info_str = get_item_interesting_string(base_item);
cur_info_str = base_item.interesting_string();
break;
case eShopItemType::ALCHEMY:
cur_info_str = get_str("item-abilities", int(alch_ingred1[base_item.item_level]) + 1);
@@ -841,66 +841,6 @@ void click_talk_rect(word_rect_t word) {
place_talk_face();
}
std::string get_item_interesting_string(cItem item) {
if(item.property) {
return "Not yours.";
}
if(!item.ident) {
return "Not identified.";
}
if(item.cursed) {
return "Cursed item.";
}
bool got_string = true;
std::ostringstream sout;
switch(item.variety) {
case eItemType::ONE_HANDED:
case eItemType::TWO_HANDED:
case eItemType::ARROW:
case eItemType::THROWN_MISSILE:
case eItemType::BOLTS:
case eItemType::MISSILE_NO_AMMO:
if(item.bonus != 0)
sout << "Damage: 1-" << item.item_level << " + " << item.bonus;
else sout << "Damage: 1-" << item.item_level;
break;
case eItemType::SHIELD:
case eItemType::ARMOR:
case eItemType::HELM:
case eItemType::GLOVES:
case eItemType::SHIELD_2:
case eItemType::BOOTS: // TODO: Verify that this is displayed correctly
sout << "Blocks " << item.item_level + ((item.protection > 0) ? 1 : 0) << '-' << item.item_level + item.protection << " damage";
break;
case eItemType::BOW:
case eItemType::CROSSBOW:
sout << "Bonus: +" << item.bonus << " to hit";
break;
case eItemType::GOLD:
sout << item.item_level << " gold pieces";
break;
case eItemType::SPECIAL:
case eItemType::QUEST:
sout << "Special";
break;
case eItemType::FOOD:
sout << item.item_level << " food";
break;
case eItemType::WEAPON_POISON:
sout << "Poison: " << item.item_level << '-' << item.item_level * 6 << " damage";
break;
default:
got_string = false;
break;
}
if(item.charges > 0 && item.ability != eItemAbil::MESSAGE) {
if(got_string) sout << "; ";
sout << "Uses: " << item.charges;
}
sout << '.';
return sout.str();
}
// color 0 - regular 1 - darker
void place_talk_str(std::string str_to_place,std::string str_to_place2,short color,rectangle c_rect) {
rectangle area_rect;

View File

@@ -59,7 +59,6 @@ void do_explosion_anim(short sound_num,short expand,short snd = -1);
void click_shop_rect(rectangle area_rect);
void draw_shop_graphics(bool pressed,rectangle clip_area_rect);
void refresh_shopping();
std::string get_item_interesting_string(cItem item);
void click_talk_rect(word_rect_t word);
void place_talk_str(std::string str_to_place,std::string str_to_place2,short color,rectangle c_rect);
short scan_for_response(const char *str);

View File

@@ -2388,7 +2388,7 @@ void general_spec(const runtime_state& ctx) {
if(spec.ex1b == 1)
univ.get_buf() += univ.scenario.scen_items[spec.ex1a].full_name;
else if(spec.ex1b == 2)
univ.get_buf() += get_item_interesting_string(univ.scenario.scen_items[spec.ex1a]);
univ.get_buf() += univ.scenario.scen_items[spec.ex1a].interesting_string();
else univ.get_buf() += univ.scenario.scen_items[spec.ex1a].name;
break;
case eSpecType::APPEND_TER:

View File

@@ -90,6 +90,66 @@ short cItem::item_weight() const {
return w;
}
std::string cItem::interesting_string() const {
if(property) {
return "Not yours.";
}
if(!ident) {
return "Not identified.";
}
if(cursed) {
return "Cursed item.";
}
bool got_string = true;
std::ostringstream sout;
switch(variety) {
case eItemType::ONE_HANDED:
case eItemType::TWO_HANDED:
case eItemType::ARROW:
case eItemType::THROWN_MISSILE:
case eItemType::BOLTS:
case eItemType::MISSILE_NO_AMMO:
if(bonus != 0)
sout << "Damage: 1-" << item_level << " + " << bonus;
else sout << "Damage: 1-" << item_level;
break;
case eItemType::SHIELD:
case eItemType::ARMOR:
case eItemType::HELM:
case eItemType::GLOVES:
case eItemType::SHIELD_2:
case eItemType::BOOTS: // TODO: Verify that this is displayed correctly
sout << "Blocks " << item_level + ((protection > 0) ? 1 : 0) << '-' << item_level + protection << " damage";
break;
case eItemType::BOW:
case eItemType::CROSSBOW:
sout << "Bonus: +" << bonus << " to hit";
break;
case eItemType::GOLD:
sout << item_level << " gold pieces";
break;
case eItemType::SPECIAL:
case eItemType::QUEST:
sout << "Special";
break;
case eItemType::FOOD:
sout << item_level << " food";
break;
case eItemType::WEAPON_POISON:
sout << "Poison: " << item_level << '-' << item_level * 6 << " damage";
break;
default:
got_string = false;
break;
}
if(charges > 0 && ability != eItemAbil::MESSAGE) {
if(got_string) sout << "; ";
sout << "Uses: " << charges;
}
sout << '.';
return sout.str();
}
bool cItem::abil_harms() const {
if(magic_use_type == eItemUse::HARM_ONE || magic_use_type == eItemUse::HARM_ALL)
return true;

View File

@@ -78,6 +78,7 @@ public:
std::string desc;
unsigned char rec_treas_class() const;
short item_weight() const;
std::string interesting_string() const;
std::string getAbilName() const;
void enchant_weapon(eEnchant enchant_type, short new_val);