/** * Choose an object kind of a given tval given a dungeon level. */ static struct object_kind *get_obj_num_by_kind(int level, bool good, int tval) { /* This is the base index into obj_alloc for this dlev */ size_t ind, item; u32b value; int total = 0; byte *objects = good ? obj_alloc_great : obj_alloc; /* Pick an object */ ind = level * z_info->k_max; /* Get new total */ for (item = 1; item < z_info->k_max; item++) if (objkind_byid(item)->tval == tval) total += objects[ind + item]; /* No appropriate items of that tval */ if (!total) return NULL; value = randint0(total); for (item = 1; item < z_info->k_max; item++) if (objkind_byid(item)->tval == tval) { if (value < objects[ind + item]) break; value -= objects[ind + item]; } /* Return the item index */ return objkind_byid(item); }
int remove_autoinscription(s16b kind) { struct object_kind *k = objkind_byid(kind); if (!k || !k->note) return 0; k->note = 0; return 1; }
static byte *o_xattr(int oid) { object_kind *kind = objkind_byid(oid); if (!kind->flavor || kind->aware) return &kind->x_attr; else return &kind->flavor->x_attr; }
static char *o_xchar(int oid) { object_kind *kind = objkind_byid(oid); if (!kind->flavor || kind->aware) return &kind->x_char; else return &kind->flavor->x_char; }
int add_autoinscription(s16b kind, const char *inscription) { struct object_kind *k = objkind_byid(kind); if (!k) return 0; if (!inscription) return remove_autoinscription(kind); k->note = quark_add(inscription); return 1; }
/* * Choose an object kind given a dungeon level to choose it for. * If tval = 0, we can choose an object of any type. * Otherwise we can only choose one of the given tval. */ object_kind *get_obj_num(int level, bool good, int tval) { /* This is the base index into obj_alloc for this dlev */ size_t ind, item; u32b value; /* Occasional level boost */ if ((level > 0) && one_in_(GREAT_OBJ)) { /* What a bizarre calculation */ level = 1 + (level * MAX_O_DEPTH / randint1(MAX_O_DEPTH)); } /* Paranoia */ level = MIN(level, MAX_O_DEPTH); level = MAX(level, 0); /* Pick an object */ ind = level * z_info->k_max; if(tval) return get_obj_num_by_kind(level, good, tval); if (!good) { value = randint0(obj_total[level]); for (item = 1; item < z_info->k_max; item++) { /* Found it */ if (value < obj_alloc[ind + item]) break; /* Decrement */ value -= obj_alloc[ind + item]; } } else { value = randint0(obj_total_great[level]); for (item = 1; item < z_info->k_max; item++) { /* Found it */ if (value < obj_alloc_great[ind + item]) break; /* Decrement */ value -= obj_alloc_great[ind + item]; } } /* Return the item index */ return objkind_byid(item); }
/** * Register an object kind autoinscription */ int add_autoinscription(s16b kind, const char *inscription, bool aware) { struct object_kind *k = objkind_byid(kind); if (!k) return 0; if (!inscription) return remove_autoinscription(kind); if (aware) k->note_aware = quark_add(inscription); else k->note_unaware = quark_add(inscription); return 1; }
/* * Display special prompt for object inscription. */ static const char *o_xtra_prompt(int oid) { object_kind *k = objkind_byid(oid); const char *no_insc = ", 's' to toggle squelch, 'r'ecall, '{'"; const char *with_insc = ", 's' to toggle squelch, 'r'ecall, '{', '}'"; /* Forget it if we've never seen the thing */ if (k->flavor && !k->aware) return ""; return k->note ? with_insc : no_insc; }
/** * Deregister an object kind autoinscription */ int remove_autoinscription(s16b kind) { struct object_kind *k = objkind_byid(kind); if (!k) return 0; /* Unaware */ if (!k->aware) { if (!k->note_unaware) { return 0; } else { k->note_unaware = 0; return 1; } } /* Aware */ if (!k->note_aware) return 0; k->note_aware = 0; return 1; }
/* * Special key actions for object inscription. */ static void o_xtra_act(struct keypress ch, int oid) { object_kind *k = objkind_byid(oid); /* Toggle squelch */ if (squelch_tval(k->tval) && (ch.code == 's' || ch.code == 'S')) { if (k->aware) { if (kind_is_squelched_aware(k)) kind_squelch_clear(k); else kind_squelch_when_aware(k); } else { if (kind_is_squelched_unaware(k)) kind_squelch_clear(k); else kind_squelch_when_unaware(k); } return; } /* Forget it if we've never seen the thing */ if (k->flavor && !k->aware) return; /* Uninscribe */ if (ch.code == '}') { if (k->note) remove_autoinscription(oid); } else if (ch.code == '{') { /* Inscribe */ char note_text[80] = ""; /* Avoid the prompt getting in the way */ screen_save(); /* Prompt */ prt("Inscribe with: ", 0, 0); /* Default note */ if (k->note) strnfmt(note_text, sizeof(note_text), "%s", get_autoinscription(k)); /* Get an inscription */ if (askfor_aux(note_text, sizeof(note_text), NULL)) { /* Remove old inscription if existent */ if (k->note) remove_autoinscription(oid); /* Add the autoinscription */ add_autoinscription(oid, note_text); /* Notice stuff (later) */ p_ptr->notice |= (PN_AUTOINSCRIBE); p_ptr->redraw |= (PR_INVEN | PR_EQUIP); } /* Reload the screen */ screen_load(); } }