/* * Display a list of objects. Each object may be prefixed with a label. * Used by show_inven(), show_equip(), and show_floor(). Mode flags are * documented in object.h */ static void show_obj_list(int num_obj, int num_head, char labels[50][80], object_type *objects[50], olist_detail_t mode) { int i, row = 0, col = 0; int attr; size_t max_len = 0; int ex_width = 0, ex_offset, ex_offset_ctr; object_type *o_ptr; char o_name[50][80]; char tmp_val[80]; bool in_term = (mode & OLIST_WINDOW) ? TRUE : FALSE; bool terse = FALSE; if (in_term) max_len = 40; if (in_term && Term->wid < 40) mode &= ~(OLIST_WEIGHT); if (Term->wid < 50) terse = TRUE; /* Calculate name offset and max name length */ for (i = 0; i < num_obj; i++) { o_ptr = objects[i]; /* Null objects are used to skip lines, or display only a label */ if (!o_ptr || !o_ptr->kind) { if (i < num_head) strnfmt(o_name[i], sizeof(o_name[i]), ""); else strnfmt(o_name[i], sizeof(o_name[i]), "(nothing)"); } else object_desc(o_name[i], sizeof(o_name[i]), o_ptr, ODESC_PREFIX | ODESC_FULL | (terse ? ODESC_TERSE : 0)); /* Max length of label + object name */ max_len = MAX(max_len, strlen(labels[i]) + strlen(o_name[i])); } /* Take the quiver message into consideration */ if (mode & OLIST_QUIVER && p_ptr->quiver_slots > 0) max_len = MAX(max_len, 24); /* Width of extra fields */ if (mode & OLIST_WEIGHT) ex_width += 9; if (mode & OLIST_PRICE) ex_width += 9; if (mode & OLIST_FAIL) ex_width += 10; /* Determine beginning row and column */ if (in_term) { /* Term window */ row = 0; col = 0; } else { /* Main window */ row = 1; col = Term->wid - 1 - max_len - ex_width; if (col < 3) col = 0; } /* Column offset of the first extra field */ ex_offset = MIN(max_len, (size_t)(Term->wid - 1 - ex_width - col)); /* Output the list */ for (i = 0; i < num_obj; i++) { o_ptr = objects[i]; /* Clear the line */ prt("", row + i, MAX(col - 2, 0)); /* If we have no label then we won't display anything */ if (!strlen(labels[i])) continue; /* Print the label */ put_str(labels[i], row + i, col); /* Limit object name */ if (strlen(labels[i]) + strlen(o_name[i]) > (size_t)ex_offset) { int truncate = ex_offset - strlen(labels[i]); if (truncate < 0) truncate = 0; if ((size_t)truncate > sizeof(o_name[i]) - 1) truncate = sizeof(o_name[i]) - 1; o_name[i][truncate] = '\0'; } /* Item kind determines the color of the output */ if (o_ptr && o_ptr->kind) attr = tval_to_attr[o_ptr->tval % N_ELEMENTS(tval_to_attr)]; else attr = TERM_SLATE; /* Object name */ c_put_str(attr, o_name[i], row + i, col + strlen(labels[i])); /* If we don't have an object, we can skip the rest of the output */ if (!(o_ptr && o_ptr->kind)) continue; /* Extra fields */ ex_offset_ctr = ex_offset; if (mode & OLIST_PRICE) { int price = price_item(o_ptr, TRUE, o_ptr->number); strnfmt(tmp_val, sizeof(tmp_val), "%6d au", price); put_str(tmp_val, row + i, col + ex_offset_ctr); ex_offset_ctr += 9; } if (mode & OLIST_FAIL && obj_can_fail(o_ptr)) { int fail = (9 + get_use_device_chance(o_ptr)) / 10; if (object_effect_is_known(o_ptr)) strnfmt(tmp_val, sizeof(tmp_val), "%4d%% fail", fail); else my_strcpy(tmp_val, " ? fail", sizeof(tmp_val)); put_str(tmp_val, row + i, col + ex_offset_ctr); ex_offset_ctr += 10; } if (mode & OLIST_WEIGHT) { int weight = o_ptr->weight * o_ptr->number; strnfmt(tmp_val, sizeof(tmp_val), "%4d.%1d lb", weight / 10, weight % 10); put_str(tmp_val, row + i, col + ex_offset_ctr); ex_offset_ctr += 9; } } /* For the inventory: print the quiver count */ if (mode & OLIST_QUIVER) { int count, j; /* Quiver may take multiple lines */ for(j = 0; j < p_ptr->quiver_slots; j++, i++) { const char *fmt = "in Quiver: %d missile%s"; char letter = index_to_label(in_term ? i - 1 : i); /* Number of missiles in this "slot" */ if (j == p_ptr->quiver_slots - 1 && p_ptr->quiver_remainder > 0) count = p_ptr->quiver_remainder; else count = MAX_STACK_SIZE-1; /* Clear the line */ prt("", row + i, MAX(col - 2, 0)); /* Print the (disabled) label */ strnfmt(tmp_val, sizeof(tmp_val), "%c) ", letter); c_put_str(TERM_SLATE, tmp_val, row + i, col); /* Print the count */ strnfmt(tmp_val, sizeof(tmp_val), fmt, count, count == 1 ? "" : "s"); c_put_str(TERM_L_UMBER, tmp_val, row + i, col + 3); } } /* Clear term windows */ if (in_term) { for (; i < Term->hgt; i++) { prt("", row + i, MAX(col - 2, 0)); } } /* Print a drop shadow for the main window if necessary */ else if (i > 0 && row + i < 24) { prt("", row + i, MAX(col - 2, 0)); } }
/** * 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; } }
/* * Display a list of objects. Each object may be prefixed with a label. * Used by show_inven(), show_equip(), and show_floor(). Mode flags are * documented in object.h */ static void show_obj_list(int num_obj, char labels[50][80], object_type *objects[50], olist_detail_t mode) { int i, row = 0, col = 0; size_t max_len = 0; int ex_width = 0, ex_offset, ex_offset_ctr; object_type *o_ptr; char o_name[50][80]; char tmp_val[80]; bool in_term; in_term = (mode & OLIST_WINDOW) ? TRUE : FALSE; if (in_term) max_len = 40; /* Calculate name offset and max name length */ for (i = 0; i < num_obj; i++) { o_ptr = objects[i]; /* Null objects are used to skip lines, or display only a label */ if (o_ptr == NULL) continue; /* Max length of label + object name */ object_desc(o_name[i], sizeof(o_name[i]), o_ptr, ODESC_PREFIX | ODESC_FULL); max_len = MAX(max_len, strlen(labels[i]) + strlen(o_name[i])); } /* Width of extra fields */ if (mode & OLIST_WEIGHT) ex_width += 9; if (mode & OLIST_PRICE) ex_width += 9; if (mode & OLIST_FAIL) ex_width += 10; /* Determine beginning row and column */ if (in_term) { /* Term window */ row = 0; col = 0; } else { /* Main window */ row = 1; col = Term->wid - 1 - max_len - ex_width; if (col < 3) col = 0; } /* Column offset of the first extra field */ ex_offset = MIN(max_len, (size_t)(Term->wid - 1 - ex_width - col)); /* Output the list */ for (i = 0; i < num_obj; i++) { o_ptr = objects[i]; /* Clear the line */ prt("", row + i, MAX(col - 2, 0)); /* Print the label */ put_str(labels[i], row + i, col); /* Print the object */ if (o_ptr != NULL) { /* Limit object name */ if (strlen(labels[i]) + strlen(o_name[i]) > (size_t)ex_offset) { int truncate = ex_offset - strlen(labels[i]); if (truncate < 0) truncate = 0; if ((size_t)truncate > sizeof(o_name[i]) - 1) truncate = sizeof(o_name[i]) - 1; o_name[i][truncate] = '\0'; } /* Object name */ c_put_str(tval_to_attr[o_ptr->tval % N_ELEMENTS(tval_to_attr)], o_name[i], row + i, col + strlen(labels[i])); /* Extra fields */ ex_offset_ctr = ex_offset; if (mode & OLIST_PRICE) { int price = price_item(o_ptr, TRUE, o_ptr->number); strnfmt(tmp_val, sizeof(tmp_val), "%6d au", price); put_str(tmp_val, row + i, col + ex_offset_ctr); ex_offset_ctr += 9; } if (mode & OLIST_FAIL) { int fail = (9 + get_use_device_chance(o_ptr)) / 10; if (object_effect_is_known(o_ptr)) strnfmt(tmp_val, sizeof(tmp_val), "%4d%% fail", fail); else my_strcpy(tmp_val, " ? fail", sizeof(tmp_val)); put_str(tmp_val, row + i, col + ex_offset_ctr); ex_offset_ctr += 10; } if (mode & OLIST_WEIGHT) { int weight = o_ptr->weight * o_ptr->number; strnfmt(tmp_val, sizeof(tmp_val), "%4d.%1d lb", weight / 10, weight % 10); put_str(tmp_val, row + i, col + ex_offset_ctr); ex_offset_ctr += 9; } } } /* For the inventory: print the quiver count */ if (mode & OLIST_QUIVER) { int count, j; /* Quiver may take multiple lines */ for(j = 0; j < p_ptr->quiver_slots; j++, i++) { /* Number of missiles in this "slot" */ if (j == p_ptr->quiver_slots - 1 && p_ptr->quiver_remainder > 0) count = p_ptr->quiver_remainder; else count = 99; /* Clear the line */ prt("", row + i, MAX(col - 2, 0)); /* Print the (disabled) label */ strnfmt(tmp_val, sizeof(tmp_val), "%c) ", index_to_label(i)); c_put_str(TERM_SLATE, tmp_val, row + i, col); /* Print the count */ strnfmt(tmp_val, sizeof(tmp_val), "in Quiver: %d missile%s", count, count == 1 ? "" : "s"); c_put_str(TERM_L_UMBER, tmp_val, row + i, col + 3); } } /* Clear term windows */ if (in_term) { for (; i < Term->hgt; i++) { prt("", row + i, MAX(col - 2, 0)); } } /* Print a drop shadow for the main window if necessary */ else if (i > 0 && row + i < 24) { prt("", row + i, MAX(col - 2, 0)); } }
/* * Display an object. Each object may be prefixed with a label. * Used by show_inven(), show_equip(), and show_floor(). Mode flags are * documented in object.h */ static void show_obj(int onum, size_t max_len, char label[80], const object_type *object, bool cursor, olist_detail_t mode) { int row = 0, col = 0; int ex_width = 0, ex_offset, ex_offset_ctr; object_type *o_ptr = (object_type *) object; char o_name[160]; char tmp_val[80]; bool in_term; byte attr = proc_list_color_hack(o_ptr); /* Highlight */ if (cursor) attr = get_color(attr, ATTR_HIGH, 1); in_term = (mode & OLIST_WINDOW) ? TRUE : FALSE; /* Object name */ object_desc(o_name, sizeof(o_name), o_ptr, ODESC_PREFIX | ODESC_FULL); /* Width of extra fields */ if (mode & OLIST_WEIGHT) ex_width += 9; if (mode & OLIST_PRICE) ex_width += 9; if (mode & OLIST_FAIL) ex_width += 10; /* Determine beginning row and column */ if (in_term) { /* Term window */ row = offset; col = 0; } else { /* Main window */ row = 1; col = Term->wid - 3 - max_len - ex_width; col = MIN(col, COL_MAP + tile_width); if (col < 3) col = 0; } /* Column offset of the first extra field */ ex_offset = MIN(max_len, (size_t) (Term->wid - 1 - ex_width - col)); /* Clear the line */ prt("", row + onum, MAX(col - 2, 0)); /* Print the label */ put_str(label, row + onum, col); /* Print the object */ if (o_ptr != NULL) { /* Limit object name */ if (strlen(label) + strlen(o_name) > (size_t) ex_offset) { int truncate = ex_offset - strlen(label); if (truncate < 0) truncate = 0; if ((size_t) truncate > sizeof(o_name) - 1) truncate = sizeof(o_name) - 1; o_name[truncate] = '\0'; } /* Object name */ c_put_str(attr, o_name, row + onum, col + strlen(label)); /* Extra fields */ ex_offset_ctr = ex_offset; if (mode & OLIST_PRICE) { int price = price_item(o_ptr, TRUE, o_ptr->number); strnfmt(tmp_val, sizeof(tmp_val), "%6d au", price); put_str(tmp_val, row + onum, col + ex_offset_ctr); ex_offset_ctr += 9; } if (mode & OLIST_FAIL) { int fail = (9 + get_use_device_chance(o_ptr)) / 10; if (object_aware_p(o_ptr)) strnfmt(tmp_val, sizeof(tmp_val), "%4d%% fail", fail); else my_strcpy(tmp_val, " ? fail", sizeof(tmp_val)); put_str(tmp_val, row + onum, col + ex_offset_ctr); ex_offset_ctr += 10; } if (mode & OLIST_WEIGHT) { int weight = o_ptr->weight * o_ptr->number; strnfmt(tmp_val, sizeof(tmp_val), "%4d.%1d lb", weight / 10, weight % 10); put_str(tmp_val, row + onum, col + ex_offset_ctr); ex_offset_ctr += 9; } } }