/** * A modifier string, put where '#' goes in the basename below. The weird * games played with book names are to allow the non-essential part of the * name to be abbreviated when there is not much room to display. */ static const char *obj_desc_get_modstr(const struct object_kind *kind) { if (tval_can_have_flavor_k(kind)) return kind->flavor ? kind->flavor->text : ""; if (tval_is_book_k(kind)) return kind->name; return ""; }
/** * Display an object. Each object may be prefixed with a label. * Used by show_inven(), show_equip(), show_quiver() and show_floor(). * Mode flags are documented in object.h */ static void show_obj(int obj_num, int row, int col, bool cursor, olist_detail_t mode) { int attr; int label_attr = cursor ? COLOUR_L_BLUE : COLOUR_WHITE; int ex_offset_ctr; char buf[80]; struct object *obj = items[obj_num].object; bool show_label = mode & (OLIST_WINDOW | OLIST_DEATH) ? true : false; int label_size = show_label ? strlen(items[obj_num].label) : 0; int equip_label_size = strlen(items[obj_num].equip_label); /* Clear the line */ prt("", row + obj_num, MAX(col - 1, 0)); /* If we have no label then we won't display anything */ if (!strlen(items[obj_num].label)) return; /* Print the label */ if (show_label) c_put_str(label_attr, items[obj_num].label, row + obj_num, col); /* Print the equipment label */ c_put_str(label_attr, items[obj_num].equip_label, row + obj_num, col + label_size); /* Limit object name */ if (label_size + equip_label_size + strlen(items[obj_num].o_name) > (size_t)ex_offset) { int truncate = ex_offset - label_size - equip_label_size; if (truncate < 0) truncate = 0; if ((size_t)truncate > sizeof(items[obj_num].o_name) - 1) truncate = sizeof(items[obj_num].o_name) - 1; items[obj_num].o_name[truncate] = '\0'; } /* Item kind determines the color of the output */ if (obj) { attr = obj->kind->base->attr; /* Unreadable books are a special case */ if (tval_is_book_k(obj->kind) && (player_object_to_book(player, obj) == NULL)) { attr = COLOUR_SLATE; } } else { attr = COLOUR_SLATE; } /* Object name */ c_put_str(attr, items[obj_num].o_name, row + obj_num, col + label_size + equip_label_size); /* If we don't have an object, we can skip the rest of the output */ if (!obj) return; /* Extra fields */ ex_offset_ctr = ex_offset; /* Price */ if (mode & OLIST_PRICE) { struct store *store = store_at(cave, player->grid); if (store) { int price = price_item(store, obj, true, obj->number); strnfmt(buf, sizeof(buf), "%6d au", price); put_str(buf, row + obj_num, col + ex_offset_ctr); ex_offset_ctr += 9; } } /* Failure chance for magic devices and activations */ if (mode & OLIST_FAIL && obj_can_fail(obj)) { int fail = (9 + get_use_device_chance(obj)) / 10; if (object_effect_is_known(obj)) strnfmt(buf, sizeof(buf), "%4d%% fail", fail); else my_strcpy(buf, " ? fail", sizeof(buf)); put_str(buf, row + obj_num, col + ex_offset_ctr); ex_offset_ctr += 10; } /* Failure chances for recharging an item; see effect_handler_RECHARGE */ if (mode & OLIST_RECHARGE) { int fail = 1000 / recharge_failure_chance(obj, player->upkeep->recharge_pow); if (object_effect_is_known(obj)) strnfmt(buf, sizeof(buf), "%2d.%1d%% fail", fail / 10, fail % 10); else my_strcpy(buf, " ? fail", sizeof(buf)); put_str(buf, row + obj_num, col + ex_offset_ctr); ex_offset_ctr += 10; } /* Weight */ if (mode & OLIST_WEIGHT) { int weight = obj->weight * obj->number; strnfmt(buf, sizeof(buf), "%4d.%1d lb", weight / 10, weight % 10); put_str(buf, row + obj_num, col + ex_offset_ctr); ex_offset_ctr += 9; } }