/* * Ordering function for squelch choices. * Aware comes before unaware, and then sort alphabetically. */ static int cmp_squelch(const void *a, const void *b) { char bufa[80]; char bufb[80]; const squelch_choice *x = a; const squelch_choice *y = b; if (!x.aware && y.aware) return 1; if (x.aware && !y.aware) return -1; object_kind_name(bufa, sizeof(bufa), x.kind, x.aware); object_kind_name(bufb, sizeof(bufb), y.kind, y.aware); return strcmp(bufa, bufb); }
/** * Ordering function for ignore choices. * Aware comes before unaware, and then sort alphabetically. */ static int cmp_ignore(const void *a, const void *b) { char bufa[80]; char bufb[80]; const ignore_choice *x = a; const ignore_choice *y = b; if (!x->aware && y->aware) return 1; if (x->aware && !y->aware) return -1; object_kind_name(bufa, sizeof(bufa), x->kind, x->aware); object_kind_name(bufb, sizeof(bufb), y->kind, y->aware); return strcmp(bufa, bufb); }
/* * Print an artifact activation message. * * In order to support randarts, with scrambled names, we re-write * the message to replace instances of {name} with the artifact name * and instances of {kind} with the type of object. * * This code deals with plural and singular forms of verbs correctly * when encountering {s}, though in fact both names and kinds are * always singular in the current code (gloves are "Set of" and boots * are "Pair of") */ static void activation_message(object_type *o_ptr, const char *message) { char buf[1024] = "\0"; const char *next; const char *s; const char *tag; const char *in_cursor; size_t end = 0; in_cursor = message; next = strchr(in_cursor, '{'); while (next) { /* Copy the text leading up to this { */ strnfcat(buf, 1024, &end, "%.*s", next - in_cursor, in_cursor); s = next + 1; while (*s && isalpha((unsigned char) *s)) s++; if (*s == '}') /* Valid tag */ { tag = next + 1; /* Start the tag after the { */ in_cursor = s + 1; switch(art_tag_lookup(tag)) { case ART_TAG_NAME: end += object_desc(buf, 1024, o_ptr, ODESC_PREFIX | ODESC_BASE); break; case ART_TAG_KIND: object_kind_name(&buf[end], 1024-end, o_ptr->kind, TRUE); end += strlen(&buf[end]); break; case ART_TAG_VERB: strnfcat(buf, 1024, &end, "s"); break; case ART_TAG_VERB_IS: if((end > 2) && (buf[end-2] == 's')) strnfcat(buf, 1024, &end, "are"); else strnfcat(buf, 1024, &end, "is"); default: break; } } else /* An invalid tag, skip it */ { in_cursor = next + 1; } next = strchr(in_cursor, '{'); } strnfcat(buf, 1024, &end, in_cursor); msg("%s", buf); }
/** Object kind selection */ void wiz_create_item_subdisplay(menu_type *m, int oid, bool cursor, int row, int col, int width) { object_kind **choices = menu_priv(m); char buf[80]; object_kind_name(buf, sizeof buf, choices[oid], TRUE); c_prt(curs_attrs[CURS_KNOWN][0 != cursor], buf, row, col); }
/* * Ordering function for squelch choices. * Aware comes before unaware, and then sort alphabetically. */ static bool ang_sort_comp_hook_squelch_choices(const void *u, const void *v, int a, int b) { char bufa[80]; char bufb[80]; squelch_choice *x = (squelch_choice *) u; (void)v; /* unused */ if (x[a].aware && !x[b].aware) return TRUE; if (!x[a].aware && x[b].aware) return FALSE; object_kind_name(bufa, sizeof(bufa), x[a].idx, x[a].aware); object_kind_name(bufb, sizeof(bufb), x[b].idx, x[b].aware); /* the = is crucial, inf loop in sort if use < rather than <= */ return strcmp(bufa, bufb) <= 0; }
/* * Display the objects in a group. */ static void display_object(int col, int row, bool cursor, int oid) { int k_idx = oid; object_kind *k_ptr = &k_info[k_idx]; const char *inscrip = get_autoinscription(oid); char o_name[80]; /* Choose a color */ bool aware = (!k_ptr->flavor || k_ptr->aware); byte attr = curs_attrs[(int) aware][(int) cursor]; /* Find graphics bits -- versions of the object_char and object_attr * defines */ bool use_flavour = (k_ptr->flavor) && !(aware && k_ptr->tval == TV_SCROLL); byte a = use_flavour ? flavor_info[k_ptr->flavor].x_attr : k_ptr->x_attr; byte c = use_flavour ? flavor_info[k_ptr->flavor].x_char : k_ptr->x_char; /* Display known artifacts differently */ if (kf_has(k_ptr->flags_kind, KF_INSTA_ART) && artifact_is_known(get_artifact_from_kind(k_ptr))) { get_artifact_display_name(o_name, sizeof(o_name), get_artifact_from_kind(k_ptr)); } else { object_kind_name(o_name, sizeof(o_name), k_idx, OPT(cheat_know)); } /* If the type is "tried", display that */ if (k_ptr->tried && !aware) my_strcat(o_name, " {tried}", sizeof(o_name)); /* Display the name */ c_prt(attr, o_name, row, col); /* Show autoinscription if around */ if (aware && inscrip) c_put_str(TERM_YELLOW, inscrip, row, 55); /* Hack - don't use if double tile */ if ((tile_width > 1) || (tile_height > 1)) return; /* Display symbol */ big_pad(76, row, a, c); }
void wiz_create_item_subdisplay(menu_type * m, int oid, bool cursor, int row, int col, int width) { int *choices = menu_priv(m); char buf[80]; /* Artifacts */ if (choose_artifact) { get_art_name(buf, choices[oid]); c_prt(curs_attrs[CURS_KNOWN][0 != cursor], buf, row, col); } /* Regular objects */ else { object_kind_name(buf, sizeof buf, choices[oid], TRUE); c_prt(curs_attrs[CURS_KNOWN][0 != cursor], buf, row, col); } }
/* * Display an entry on the sval menu */ static void sval_display(menu_type *menu, int oid, bool cursor, int row, int col, int width) { char buf[80]; const squelch_choice *choice = menu_priv(menu); int idx = choice[oid].idx; byte attr = (cursor ? TERM_L_BLUE : TERM_WHITE); /* Acquire the "name" of object "i" */ object_kind_name(buf, sizeof(buf), idx, choice[oid].aware); /* Print it */ c_put_str(attr, format("[ ] %s", buf), row, col); if ((choice[oid].aware && (k_info[idx].squelch & SQUELCH_IF_AWARE)) || ((!choice[oid].aware) && (k_info[idx].squelch & SQUELCH_IF_UNAWARE))) c_put_str(TERM_L_RED, "*", row, col + 1); }
/* * Display the objects in a group. */ static void display_object(int col, int row, bool cursor, int oid) { object_kind *kind = &k_info[oid]; const char *inscrip = get_autoinscription(kind); char o_name[80]; /* Choose a color */ bool aware = (!kind->flavor || kind->aware); byte attr = curs_attrs[(int)aware][(int)cursor]; /* Find graphics bits -- versions of the object_char and object_attr defines */ bool use_flavour = (kind->flavor) && !(aware && kind->tval == TV_SCROLL); byte a = use_flavour ? kind->flavor->x_attr : kind->x_attr; byte c = use_flavour ? kind->flavor->x_char : kind->x_char; /* Display known artifacts differently */ if (of_has(kind->flags, OF_INSTA_ART) && artifact_is_known(get_artifact_from_kind(kind))) get_artifact_display_name(o_name, sizeof(o_name), get_artifact_from_kind(kind)); else object_kind_name(o_name, sizeof(o_name), kind, OPT(cheat_know)); /* If the type is "tried", display that */ if (kind->tried && !aware) my_strcat(o_name, " {tried}", sizeof(o_name)); /* Display the name */ c_prt(attr, o_name, row, col); /* Show squelch status */ if ((aware && kind_is_squelched_aware(kind)) || (!aware && kind_is_squelched_unaware(kind))) c_put_str(attr, "Yes", row, 46); /* Show autoinscription if around */ if (aware && inscrip) c_put_str(TERM_YELLOW, inscrip, row, 55); if (tile_height == 1) { big_pad(76, row, a, c); } }
/** * Display an entry on the sval menu */ static void ignore_sval_menu_display(struct menu *menu, int oid, bool cursor, int row, int col, int width) { char buf[80]; const ignore_choice *choice = menu_priv(menu); struct object_kind *kind = choice[oid].kind; bool aware = choice[oid].aware; byte attr = curs_attrs[(int)aware][0 != cursor]; /* Acquire the "name" of object "i" */ object_kind_name(buf, sizeof(buf), kind, aware); /* Print it */ c_put_str(attr, format("[ ] %s", buf), row, col); if ((aware && (kind->ignore & IGNORE_IF_AWARE)) || (!aware && (kind->ignore & IGNORE_IF_UNAWARE))) c_put_str(COLOUR_L_RED, "*", row, col + 1); }
/* * Display an entry on the sval menu */ static void squelch_sval_menu_display(menu_type *menu, int oid, bool cursor, int row, int col, int width) { char buf[80]; const squelch_choice *choice = menu_priv(menu); object_kind *kind = choice[oid].kind; bool aware = choice[oid].aware; byte attr = curs_attrs[(int)aware][0 != cursor]; /* Acquire the "name" of object "i" */ object_kind_name(buf, sizeof(buf), kind, aware); /* Print it */ c_put_str(attr, format("[ ] %s", buf), row, col); if ((aware && (kind.squelch & SQUELCH_IF_AWARE)) || (!aware && (kind.squelch & SQUELCH_IF_UNAWARE))) c_put_str(TERM_L_RED, "*", row, col + 1); }
/* * Pickup all gold at the player's current location. */ static void py_pickup_gold(void) { int py = p_ptr->py; int px = p_ptr->px; s32b total_gold = 0L; byte *treasure; s16b this_o_idx = 0; s16b next_o_idx = 0; object_type *o_ptr; int sound_msg; bool verbal = FALSE; /* Allocate an array of ordinary gold objects */ treasure = C_ZNEW(SV_GOLD_MAX, byte); /* Pick up all the ordinary gold objects */ for (this_o_idx = cave->o_idx[py][px]; this_o_idx; this_o_idx = next_o_idx) { /* Get the object */ o_ptr = object_byid(this_o_idx); /* Get the next object */ next_o_idx = o_ptr->next_o_idx; /* Ignore if not legal treasure */ if ((o_ptr->tval != TV_GOLD) || (o_ptr->sval >= SV_GOLD_MAX)) continue; /* Note that we have this kind of treasure */ treasure[o_ptr->sval]++; /* Remember whether feedback message is in order */ if (!squelch_item_ok(o_ptr)) verbal = TRUE; /* Increment total value */ total_gold += (s32b)o_ptr->pval[DEFAULT_PVAL]; /* Delete the gold */ delete_object_idx(this_o_idx); } /* Pick up the gold, if present */ if (total_gold) { char buf[1024]; char tmp[80]; int i, count, total; object_kind *kind; /* Build a message */ (void)strnfmt(buf, sizeof(buf), "You have found %ld gold pieces worth of ", (long)total_gold); /* Count the types of treasure present */ for (total = 0, i = 0; i < SV_GOLD_MAX; i++) { if (treasure[i]) total++; } /* List the treasure types */ for (count = 0, i = 0; i < SV_GOLD_MAX; i++) { /* Skip if no treasure of this type */ if (!treasure[i]) continue; /* Get this object index */ kind = lookup_kind(TV_GOLD, i); if (!kind) continue; /* Get the object name */ object_kind_name(tmp, sizeof tmp, kind, TRUE); /* Build up the pickup string */ my_strcat(buf, tmp, sizeof(buf)); /* Added another kind of treasure */ count++; /* Add a comma if necessary */ if ((total > 2) && (count < total)) my_strcat(buf, ",", sizeof(buf)); /* Add an "and" if necessary */ if ((total >= 2) && (count == total-1)) my_strcat(buf, " and", sizeof(buf)); /* Add a space or period if necessary */ if (count < total) my_strcat(buf, " ", sizeof(buf)); else my_strcat(buf, ".", sizeof(buf)); } /* Determine which sound to play */ if (total_gold < 200) sound_msg = MSG_MONEY1; else if (total_gold < 600) sound_msg = MSG_MONEY2; else sound_msg = MSG_MONEY3; /* Display the message */ if (verbal) msgt(sound_msg, "%s", buf); /* Add gold to purse */ p_ptr->au += total_gold; /* Redraw gold */ p_ptr->redraw |= (PR_GOLD); } /* Free the gold array */ FREE(treasure); }