From cbef37bd5bfb938a2303ee3887520c08be85d8e8 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Tue, 26 Mar 2013 17:10:10 +0100 Subject: Switch almost everything over to C++ --- src/object1.cc | 6696 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 6696 insertions(+) create mode 100644 src/object1.cc (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc new file mode 100644 index 00000000..2a555581 --- /dev/null +++ b/src/object1.cc @@ -0,0 +1,6696 @@ +/* File: object1.c */ + +/* Purpose: Object code, part 1 */ + +/* + * Copyright (c) 1989 James E. Wilson, Robert A. Koeneke + * + * This software may be copied and distributed for educational, research, and + * not for profit purposes provided that this copyright and statement are + * included in all such copies. + */ + +#include "angband.h" + +#include "quark.h" +#include "spell_type.h" +#include "hooks.h" + +/* + * Hack -- note that "TERM_MULTI" is now just "TERM_VIOLET". + * We will have to find a cleaner method for "MULTI_HUED" later. + * There were only two multi-hued "flavors" (one potion, one food). + * Plus five multi-hued "base-objects" (3 dragon scales, one blade + * of chaos, and one something else). See the SHIMMER_OBJECTS code + * in "dungeon.c" and the object color extractor in "cave.c". + */ +#define TERM_MULTI TERM_VIOLET + + +/* + * Max sizes of the following arrays + */ +#define MAX_ROCKS 62 /* Used with rings (min 58) */ +#define MAX_AMULETS 34 /* Used with amulets (min 30) */ +#define MAX_WOODS 35 /* Used with staffs (min 32) */ +#define MAX_METALS 39 /* Used with wands/rods (min 32/30) */ +#define MAX_COLORS 66 /* Used with potions (min 62) */ +#define MAX_SHROOM 20 /* Used with mushrooms (min 20) */ +#define MAX_TITLES 55 /* Used with scrolls (min 55) */ +#define MAX_SYLLABLES 164 /* Used with scrolls (see below) */ + + +/* + * Rings (adjectives and colors) + */ + +static cptr ring_adj[MAX_ROCKS] = +{ + "Alexandrite", "Amethyst", "Aquamarine", "Azurite", "Beryl", + "Bloodstone", "Calcite", "Carnelian", "Corundum", "Diamond", + "Emerald", "Fluorite", "Garnet", "Granite", "Jade", + "Jasper", "Lapis Lazuli", "Malachite", "Marble", "Moonstone", + "Onyx", "Opal", "Pearl", "Quartz", "Quartzite", + "Rhodonite", "Ruby", "Sapphire", "Tiger Eye", "Topaz", + "Turquoise", "Zircon", "Platinum", "Bronze", "Gold", + "Obsidian", "Silver", "Tortoise Shell", "Mithril", "Jet", + "Engagement", "Adamantite", + "Wire", "Dilithium", "Bone", "Wooden", + "Spikard", "Serpent", "Wedding", "Double", + "Plain", "Brass", "Scarab", "Shining", + "Rusty", "Transparent", "Copper", "Black Opal", "Nickel", + "Glass", "Fluorspar", "Agate", +}; + +static byte ring_col[MAX_ROCKS] = +{ + TERM_GREEN, TERM_VIOLET, TERM_L_BLUE, TERM_L_BLUE, TERM_L_GREEN, + TERM_RED, TERM_WHITE, TERM_RED, TERM_SLATE, TERM_WHITE, + TERM_GREEN, TERM_L_GREEN, TERM_RED, TERM_L_DARK, TERM_L_GREEN, + TERM_UMBER, TERM_BLUE, TERM_GREEN, TERM_WHITE, TERM_L_WHITE, + TERM_L_RED, TERM_L_WHITE, TERM_WHITE, TERM_L_WHITE, TERM_L_WHITE, + TERM_L_RED, TERM_RED, TERM_BLUE, TERM_YELLOW, TERM_YELLOW, + TERM_L_BLUE, TERM_L_UMBER, TERM_WHITE, TERM_L_UMBER, TERM_YELLOW, + TERM_L_DARK, TERM_L_WHITE, TERM_GREEN, TERM_L_BLUE, TERM_L_DARK, + TERM_YELLOW, TERM_VIOLET, + TERM_UMBER, TERM_L_WHITE, TERM_WHITE, TERM_UMBER, + TERM_BLUE, TERM_GREEN, TERM_YELLOW, TERM_ORANGE, + TERM_YELLOW, TERM_ORANGE, TERM_L_GREEN, TERM_YELLOW, + TERM_RED, TERM_WHITE, TERM_UMBER, TERM_L_DARK, TERM_L_WHITE, + TERM_WHITE, TERM_BLUE, TERM_L_WHITE +}; + + +/* + * Amulets (adjectives and colors) + */ + +static cptr amulet_adj[MAX_AMULETS] = +{ + "Amber", "Driftwood", "Coral", "Agate", "Ivory", + "Obsidian", "Bone", "Brass", "Bronze", "Pewter", + "Tortoise Shell", "Golden", "Azure", "Crystal", "Silver", + "Copper", "Amethyst", "Mithril", "Sapphire", "Dragon Tooth", + "Carved Oak", "Sea Shell", "Flint Stone", "Ruby", "Scarab", + "Origami Paper", "Meteoric Iron", "Platinum", "Glass", "Beryl", + "Malachite", "Adamantite", "Mother-of-pearl", "Runed" +}; + +static byte amulet_col[MAX_AMULETS] = +{ + TERM_YELLOW, TERM_L_UMBER, TERM_WHITE, TERM_L_WHITE, TERM_WHITE, + TERM_L_DARK, TERM_WHITE, TERM_ORANGE, TERM_L_UMBER, TERM_SLATE, + TERM_GREEN, TERM_YELLOW, TERM_L_BLUE, TERM_L_BLUE, TERM_L_WHITE, + TERM_L_UMBER, TERM_VIOLET, TERM_L_BLUE, TERM_BLUE, TERM_L_WHITE, + TERM_UMBER, TERM_L_BLUE, TERM_SLATE, TERM_RED, TERM_L_GREEN, + TERM_WHITE, TERM_L_DARK, TERM_L_WHITE, TERM_WHITE, TERM_L_GREEN, + TERM_GREEN, TERM_VIOLET, TERM_L_WHITE, TERM_UMBER +}; + + +/* + * Staffs (adjectives and colors) + */ + +static cptr staff_adj[MAX_WOODS] = +{ + "Aspen", "Balsa", "Banyan", "Birch", "Cedar", + "Cottonwood", "Cypress", "Dogwood", "Elm", "Eucalyptus", + "Hemlock", "Hickory", "Ironwood", "Locust", "Mahogany", + "Maple", "Mulberry", "Oak", "Pine", "Redwood", + "Rosewood", "Spruce", "Sycamore", "Teak", "Walnut", + "Mistletoe", "Hawthorn", "Bamboo", "Silver", "Runed", + "Golden", "Ashen", "Gnarled", "Ivory", "Willow" +}; + +static byte staff_col[MAX_WOODS] = +{ + TERM_L_UMBER, TERM_L_UMBER, TERM_L_UMBER, TERM_L_UMBER, TERM_L_UMBER, + TERM_L_UMBER, TERM_L_UMBER, TERM_L_UMBER, TERM_L_UMBER, TERM_L_UMBER, + TERM_L_UMBER, TERM_L_UMBER, TERM_UMBER, TERM_L_UMBER, TERM_UMBER, + TERM_L_UMBER, TERM_L_UMBER, TERM_L_UMBER, TERM_L_UMBER, TERM_RED, + TERM_RED, TERM_L_UMBER, TERM_L_UMBER, TERM_L_UMBER, TERM_UMBER, + TERM_GREEN, TERM_L_UMBER, TERM_L_UMBER, TERM_L_WHITE, TERM_UMBER, + TERM_YELLOW, TERM_SLATE, TERM_UMBER, TERM_L_WHITE, TERM_L_UMBER +}; + + +/* + * Wands (adjectives and colors) + */ + +static cptr wand_adj[MAX_METALS] = +{ + "Aluminium", "Cast Iron", "Chromium", "Copper", "Gold", + "Iron", "Magnesium", "Molybdenum", "Nickel", "Rusty", + "Silver", "Steel", "Tin", "Titanium", "Tungsten", + "Zirconium", "Zinc", "Aluminium-Plated", "Copper-Plated", "Gold-Plated", + "Nickel-Plated", "Silver-Plated", "Steel-Plated", "Tin-Plated", "Zinc-Plated", + "Mithril-Plated", "Mithril", "Runed", "Bronze", "Brass", + "Platinum", "Lead", "Lead-Plated", "Ivory" , "Adamantite", + "Uridium", "Long", "Short", "Hexagonal" +}; + +static byte wand_col[MAX_METALS] = +{ + TERM_L_BLUE, TERM_L_DARK, TERM_WHITE, TERM_UMBER, TERM_YELLOW, + TERM_SLATE, TERM_L_WHITE, TERM_L_WHITE, TERM_L_WHITE, TERM_RED, + TERM_L_WHITE, TERM_L_WHITE, TERM_L_WHITE, TERM_WHITE, TERM_WHITE, + TERM_L_WHITE, TERM_L_WHITE, TERM_L_BLUE, TERM_L_UMBER, TERM_YELLOW, + TERM_L_UMBER, TERM_L_WHITE, TERM_L_WHITE, TERM_L_WHITE, TERM_L_WHITE, + TERM_L_BLUE, TERM_L_BLUE, TERM_UMBER, TERM_L_UMBER, TERM_L_UMBER, + TERM_WHITE, TERM_SLATE, TERM_SLATE, TERM_WHITE, TERM_VIOLET, + TERM_L_RED, TERM_L_BLUE, TERM_BLUE, TERM_RED +}; + + +/* + * Rods (adjectives and colors). + * Efficiency -- copied from wand arrays + */ + +static cptr rod_adj[MAX_METALS]; + +static byte rod_col[MAX_METALS]; + + +/* + * Mushrooms (adjectives and colors) + */ + +static cptr food_adj[MAX_SHROOM] = +{ + "Blue", "Black", "Black Spotted", "Brown", "Dark Blue", + "Dark Green", "Dark Red", "Yellow", "Furry", "Green", + "Grey", "Light Blue", "Light Green", "Violet", "Red", + "Slimy", "Tan", "White", "White Spotted", "Wrinkled", +}; + +static byte food_col[MAX_SHROOM] = +{ + TERM_BLUE, TERM_L_DARK, TERM_L_DARK, TERM_UMBER, TERM_BLUE, + TERM_GREEN, TERM_RED, TERM_YELLOW, TERM_L_WHITE, TERM_GREEN, + TERM_SLATE, TERM_L_BLUE, TERM_L_GREEN, TERM_VIOLET, TERM_RED, + TERM_SLATE, TERM_L_UMBER, TERM_WHITE, TERM_WHITE, TERM_UMBER +}; + + +/* + * Color adjectives and colors, for potions. + * Hack -- The first four entries are hard-coded. + * (water, apple juice, slime mold juice, something) + */ + +static cptr potion_adj[MAX_COLORS] = +{ + "Clear", "Light Brown", "Icky Green", "Strangely Phosphorescent", + "Azure", "Blue", "Blue Speckled", "Black", "Brown", "Brown Speckled", + "Bubbling", "Chartreuse", "Cloudy", "Copper Speckled", "Crimson", "Cyan", + "Dark Blue", "Dark Green", "Dark Red", "Gold Speckled", "Green", + "Green Speckled", "Grey", "Grey Speckled", "Hazy", "Indigo", + "Light Blue", "Light Green", "Magenta", "Metallic Blue", "Metallic Red", + "Metallic Green", "Metallic Purple", "Misty", "Orange", "Orange Speckled", + "Pink", "Pink Speckled", "Puce", "Purple", "Purple Speckled", + "Red", "Red Speckled", "Silver Speckled", "Smoky", "Tangerine", + "Violet", "Vermilion", "White", "Yellow", "Violet Speckled", + "Pungent", "Clotted Red", "Viscous Pink", "Oily Yellow", "Gloopy Green", + "Shimmering", "Coagulated Crimson", "Yellow Speckled", "Gold", + "Manly", "Stinking", "Oily Black", "Ichor", "Ivory White", "Sky Blue", +}; + +static byte potion_col[MAX_COLORS] = +{ + TERM_WHITE, TERM_L_UMBER, TERM_GREEN, TERM_MULTI, + TERM_L_BLUE, TERM_BLUE, TERM_BLUE, TERM_L_DARK, TERM_UMBER, TERM_UMBER, + TERM_L_WHITE, TERM_L_GREEN, TERM_WHITE, TERM_L_UMBER, TERM_RED, TERM_L_BLUE, + TERM_BLUE, TERM_GREEN, TERM_RED, TERM_YELLOW, TERM_GREEN, + TERM_GREEN, TERM_SLATE, TERM_SLATE, TERM_L_WHITE, TERM_VIOLET, + TERM_L_BLUE, TERM_L_GREEN, TERM_RED, TERM_BLUE, TERM_RED, + TERM_GREEN, TERM_VIOLET, TERM_L_WHITE, TERM_ORANGE, TERM_ORANGE, + TERM_L_RED, TERM_L_RED, TERM_VIOLET, TERM_VIOLET, TERM_VIOLET, + TERM_RED, TERM_RED, TERM_L_WHITE, TERM_L_DARK, TERM_ORANGE, + TERM_VIOLET, TERM_RED, TERM_WHITE, TERM_YELLOW, TERM_VIOLET, + TERM_L_RED, TERM_RED, TERM_L_RED, TERM_YELLOW, TERM_GREEN, + TERM_MULTI, TERM_RED, TERM_YELLOW, TERM_YELLOW, + TERM_L_UMBER, TERM_UMBER, TERM_L_DARK, TERM_RED, TERM_WHITE, TERM_L_BLUE +}; + + +/* + * Syllables for scrolls (must be 1-4 letters each) + */ + +static cptr syllables[MAX_SYLLABLES] = +{ + "a", "ab", "ag", "aks", "ala", "an", "ankh", "app", + "arg", "arze", "ash", "aus", "ban", "bar", "bat", "bek", + "bie", "bin", "bit", "bjor", "blu", "bot", "bu", + "byt", "comp", "con", "cos", "cre", "dalf", "dan", + "den", "der", "doe", "dok", "eep", "el", "eng", "er", "ere", "erk", + "esh", "evs", "fa", "fid", "flit", "for", "fri", "fu", "gan", + "gar", "glen", "gop", "gre", "ha", "he", "hyd", "i", + "ing", "ion", "ip", "ish", "it", "ite", "iv", "jo", + "kho", "kli", "klis", "la", "lech", "man", "mar", + "me", "mi", "mic", "mik", "mon", "mung", "mur", "nag", "nej", + "nelg", "nep", "ner", "nes", "nis", "nih", "nin", "o", + "od", "ood", "org", "orn", "ox", "oxy", "pay", "pet", + "ple", "plu", "po", "pot", "prok", "re", "rea", "rhov", + "ri", "ro", "rog", "rok", "rol", "sa", "san", "sat", + "see", "sef", "seh", "shu", "ski", "sna", "sne", "snik", + "sno", "so", "sol", "sri", "sta", "sun", "ta", "tab", + "tem", "ther", "ti", "tox", "trol", "tue", "turs", "u", + "ulk", "um", "un", "uni", "ur", "val", "viv", "vly", + "vom", "wah", "wed", "werg", "wex", "whon", "wun", "x", + "yerg", "yp", "zun", "tri", "blaa", "jah", "bul", "on", + "foo", "ju", "xuxu" +}; + +/* + * Hold the titles of scrolls, 6 to 14 characters each + * Also keep an array of scroll colors (always WHITE for now) + */ + +static char scroll_adj[MAX_TITLES][16]; + +static byte scroll_col[MAX_TITLES]; + + +/* + * Certain items have a flavor + * This function is used only by "flavor_init()" + */ +static bool_ object_flavor(int k_idx) +{ + object_kind *k_ptr = &k_info[k_idx]; + + /* Analyze the item */ + switch (k_ptr->tval) + { + case TV_AMULET: + { + return (0x80 + amulet_col[k_ptr->sval]); + } + + case TV_RING: + { + return (0x90 + ring_col[k_ptr->sval]); + } + + case TV_STAFF: + { + return (0xA0 + staff_col[k_ptr->sval]); + } + + case TV_WAND: + { + return (0xB0 + wand_col[k_ptr->sval]); + } + + case TV_ROD: + { + return (0xC0 + rod_col[k_ptr->sval]); + } + + case TV_SCROLL: + { + return (0xD0 + scroll_col[k_ptr->sval]); + } + + case TV_POTION: + case TV_POTION2: + { + return (0xE0 + potion_col[k_ptr->sval]); + } + + case TV_FOOD: + { + if (k_ptr->sval < SV_FOOD_MIN_FOOD) + { + return (0xF0 + food_col[k_ptr->sval]); + } + + break; + } + } + + /* No flavor */ + return (0); +} + + +void get_table_name(char *out_string) +{ + int testcounter = (randint(3)) + 1; + + strcpy(out_string, "'"); + + if (randint(3) == 2) + { + while (testcounter--) + strcat(out_string, syllables[(randint(MAX_SYLLABLES)) - 1]); + } + + else + { + char Syllable[80]; + testcounter = (randint(2)) + 1; + while (testcounter--) + { + get_rnd_line("elvish.txt", Syllable); + strcat(out_string, Syllable); + } + } + + out_string[1] = toupper(out_string[1]); + + strcat(out_string, "'"); + + out_string[18] = '\0'; + + return; +} + + +/* + * Certain items, if aware, are known instantly + * This function is used only by "flavor_init()" + * + * XXX XXX XXX Add "EASY_KNOW" flag to "k_info.txt" file + */ +static bool_ object_easy_know(int i) +{ + object_kind *k_ptr = &k_info[i]; + + /* Analyze the "tval" */ + switch (k_ptr->tval) + { + /* Spellbooks */ + case TV_DRUID_BOOK: + case TV_MUSIC_BOOK: + case TV_SYMBIOTIC_BOOK: + { + return (TRUE); + } + + /* Simple items */ + case TV_FLASK: + case TV_EGG: + case TV_BOTTLE: + case TV_SKELETON: + case TV_CORPSE: + case TV_HYPNOS: + case TV_SPIKE: + case TV_JUNK: + { + return (TRUE); + } + + /* All Food, Potions, Scrolls, Rods */ + case TV_FOOD: + case TV_POTION: + case TV_POTION2: + case TV_SCROLL: + case TV_ROD: + case TV_ROD_MAIN: + case TV_BATERIE: + { + if (k_ptr->flags3 & TR3_NORM_ART) + return ( FALSE ); + return (TRUE); + } + + /* Some Rings, Amulets, Lites */ + case TV_RING: + case TV_AMULET: + case TV_LITE: + { + if (k_ptr->flags3 & (TR3_EASY_KNOW)) return (TRUE); + return (FALSE); + } + } + + /* Nope */ + return (FALSE); +} + +/* + * Prepare the "variable" part of the "k_info" array. + * + * The "color"/"metal"/"type" of an item is its "flavor". + * For the most part, flavors are assigned randomly each game. + * + * Initialize descriptions for the "colored" objects, including: + * Rings, Amulets, Staffs, Wands, Rods, Food, Potions, Scrolls. + * + * The first 4 entries for potions are fixed (Water, Apple Juice, + * Slime Mold Juice, Unused Potion). + * + * Scroll titles are always between 6 and 14 letters long. This is + * ensured because every title is composed of whole words, where every + * word is from 1 to 8 letters long (one or two syllables of 1 to 4 + * letters each), and that no scroll is finished until it attempts to + * grow beyond 15 letters. The first time this can happen is when the + * current title has 6 letters and the new word has 8 letters, which + * would result in a 6 letter scroll title. + * + * Duplicate titles are avoided by requiring that no two scrolls share + * the same first four letters (not the most efficient method, and not + * the least efficient method, but it will always work). + * + * Hack -- make sure everything stays the same for each saved game + * This is accomplished by the use of a saved "random seed", as in + * "town_gen()". Since no other functions are called while the special + * seed is in effect, so this function is pretty "safe". + * + * Note that the "hacked seed" may provide an RNG with alternating parity! + */ +void flavor_init(void) +{ + int i, j; + + byte temp_col; + + cptr temp_adj; + + + /* Hack -- Use the "simple" RNG */ + Rand_quick = TRUE; + + /* Hack -- Induce consistant flavors */ + Rand_value = seed_flavor; + + + /* Efficiency -- Rods/Wands share initial array */ + for (i = 0; i < MAX_METALS; i++) + { + rod_adj[i] = wand_adj[i]; + rod_col[i] = wand_col[i]; + } + + + /* Rings have "ring colors" */ + for (i = 0; i < MAX_ROCKS; i++) + { + j = rand_int(MAX_ROCKS); + temp_adj = ring_adj[i]; + ring_adj[i] = ring_adj[j]; + ring_adj[j] = temp_adj; + temp_col = ring_col[i]; + ring_col[i] = ring_col[j]; + ring_col[j] = temp_col; + } + + /* Amulets have "amulet colors" */ + for (i = 0; i < MAX_AMULETS; i++) + { + j = rand_int(MAX_AMULETS); + temp_adj = amulet_adj[i]; + amulet_adj[i] = amulet_adj[j]; + amulet_adj[j] = temp_adj; + temp_col = amulet_col[i]; + amulet_col[i] = amulet_col[j]; + amulet_col[j] = temp_col; + } + + /* Staffs */ + for (i = 0; i < MAX_WOODS; i++) + { + j = rand_int(MAX_WOODS); + temp_adj = staff_adj[i]; + staff_adj[i] = staff_adj[j]; + staff_adj[j] = temp_adj; + temp_col = staff_col[i]; + staff_col[i] = staff_col[j]; + staff_col[j] = temp_col; + } + + /* Wands */ + for (i = 0; i < MAX_METALS; i++) + { + j = rand_int(MAX_METALS); + temp_adj = wand_adj[i]; + wand_adj[i] = wand_adj[j]; + wand_adj[j] = temp_adj; + temp_col = wand_col[i]; + wand_col[i] = wand_col[j]; + wand_col[j] = temp_col; + } + + /* Rods */ + for (i = 0; i < MAX_METALS; i++) + { + j = rand_int(MAX_METALS); + temp_adj = rod_adj[i]; + rod_adj[i] = rod_adj[j]; + rod_adj[j] = temp_adj; + temp_col = rod_col[i]; + rod_col[i] = rod_col[j]; + rod_col[j] = temp_col; + } + + /* Foods (Mushrooms) */ + for (i = 0; i < MAX_SHROOM; i++) + { + j = rand_int(MAX_SHROOM); + temp_adj = food_adj[i]; + food_adj[i] = food_adj[j]; + food_adj[j] = temp_adj; + temp_col = food_col[i]; + food_col[i] = food_col[j]; + food_col[j] = temp_col; + } + + /* Potions */ + for (i = 4; i < MAX_COLORS; i++) + { + j = rand_int(MAX_COLORS - 4) + 4; + temp_adj = potion_adj[i]; + potion_adj[i] = potion_adj[j]; + potion_adj[j] = temp_adj; + temp_col = potion_col[i]; + potion_col[i] = potion_col[j]; + potion_col[j] = temp_col; + } + + /* Scrolls (random titles, always white) */ + for (i = 0; i < MAX_TITLES; i++) + { + /* Get a new title */ + while (TRUE) + { + char buf[80]; + + bool_ okay; + + /* Start a new title */ + buf[0] = '\0'; + + /* Collect words until done */ + while (1) + { + int q, s; + + char tmp[80]; + + /* Start a new word */ + tmp[0] = '\0'; + + /* Choose one or two syllables */ + s = ((rand_int(100) < 30) ? 1 : 2); + + /* Add a one or two syllable word */ + for (q = 0; q < s; q++) + { + /* Add the syllable */ + strcat(tmp, syllables[rand_int(MAX_SYLLABLES)]); + } + + /* Stop before getting too long */ + if (strlen(buf) + 1 + strlen(tmp) > 15) break; + + /* Add a space */ + strcat(buf, " "); + + /* Add the word */ + strcat(buf, tmp); + } + + /* Save the title */ + strcpy(scroll_adj[i], buf + 1); + + /* Assume okay */ + okay = TRUE; + + /* Check for "duplicate" scroll titles */ + for (j = 0; j < i; j++) + { + cptr hack1 = scroll_adj[j]; + cptr hack2 = scroll_adj[i]; + + /* Compare first four characters */ + if (*hack1++ != *hack2++) continue; + if (*hack1++ != *hack2++) continue; + if (*hack1++ != *hack2++) continue; + if (*hack1++ != *hack2++) continue; + + /* Not okay */ + okay = FALSE; + + /* Stop looking */ + break; + } + + /* Break when done */ + if (okay) break; + } + + /* All scrolls are white */ + scroll_col[i] = TERM_WHITE; + } + + + /* Hack -- Use the "complex" RNG */ + Rand_quick = FALSE; + + /* Analyze every object */ + for (i = 1; i < max_k_idx; i++) + { + object_kind *k_ptr = &k_info[i]; + + /* Skip "empty" objects */ + if (!k_ptr->name) continue; + + /* Extract "flavor" (if any) */ + k_ptr->flavor = object_flavor(i); + + /* No flavor yields aware */ + if ((!k_ptr->flavor) && (k_ptr->tval != TV_ROD_MAIN)) k_ptr->aware = TRUE; + + /* Check for "easily known" */ + k_ptr->easy_know = object_easy_know(i); + } +} + +/* + * Reset the "visual" lists + * + * This involves resetting various things to their "default" state. + * + * If the "prefs" flag is TRUE, then we will also load the appropriate + * "user pref file" based on the current setting of the "use_graphics" + * flag. This is useful for switching "graphics" on/off. + * + * The features, objects, and monsters, should all be encoded in the + * relevant "font.pref" and/or "graf.prf" files. XXX XXX XXX + * + * The "prefs" parameter is no longer meaningful. XXX XXX XXX + */ +void reset_visuals(void) +{ + int i; + + /* Extract some info about terrain features */ + for (i = 0; i < max_f_idx; i++) + { + feature_type *f_ptr = &f_info[i]; + + /* Assume we will use the underlying values */ + f_ptr->x_attr = f_ptr->d_attr; + f_ptr->x_char = f_ptr->d_char; + } + + /* Extract default attr/char code for stores */ + for (i = 0; i < max_st_idx; i++) + { + store_info_type *st_ptr = &st_info[i]; + + /* Default attr/char */ + st_ptr->x_attr = st_ptr->d_attr; + st_ptr->x_char = st_ptr->d_char; + } + + /* Extract default attr/char code for objects */ + for (i = 0; i < max_k_idx; i++) + { + object_kind *k_ptr = &k_info[i]; + + /* Default attr/char */ + k_ptr->x_attr = k_ptr->d_attr; + k_ptr->x_char = k_ptr->d_char; + } + + /* Extract default attr/char code for monsters */ + for (i = 0; i < max_r_idx; i++) + { + monster_race *r_ptr = &r_info[i]; + + /* Default attr/char */ + r_ptr->x_attr = r_ptr->d_attr; + r_ptr->x_char = r_ptr->d_char; + } + + /* Reset attr/char code for ego monster overlay graphics */ + for (i = 0; i < max_re_idx; i++) + { + monster_ego *re_ptr = &re_info[i]; + + /* Default attr/char */ + re_ptr->g_attr = 0; + re_ptr->g_char = 0; + } + + /* Reset attr/char code for race modifier overlay graphics */ + for (i = 0; i < max_rmp_idx; i++) + { + player_race_mod *rmp_ptr = &race_mod_info[i]; + + /* Default attr/char */ + rmp_ptr->g_attr = 0; + rmp_ptr->g_char = 0; + } + + /* Reset attr/char code for trap overlay graphics */ + for (i = 0; i < max_rmp_idx; i++) + { + trap_type *t_ptr = &t_info[i]; + + /* Default attr/char */ + t_ptr->g_attr = 0; + t_ptr->g_char = 0; + } + + + if (use_graphics) + { + /* Process "graf.prf" */ + process_pref_file("graf.prf"); + + /* + * Hack -- remember graphics mode as an integer value, + * for faster processing of map_info() + */ + + /* IBM-PC pseudo-graphics -- not maintained, but the code is there */ + if (streq(ANGBAND_SYS, "ibm")) + { + graphics_mode = GRAPHICS_IBM; + } + + /* + * Isometric view. Also assumes all the attributes of the "new" + * graphics. + */ + else if (streq(ANGBAND_GRAF, "iso")) + { + graphics_mode = GRAPHICS_ISO; + } + + /* + * "New" graphics -- supports graphics overlay for traps, ego monsters + * and player subraces, and has tiles for lighting effects (row + 1 + * and row + 2 for "darker" versions of terrain features) + */ + else if (streq(ANGBAND_GRAF, "new")) + { + graphics_mode = GRAPHICS_NEW; + } + + /* + * "Old" graphics -- doesn't support graphics overlay and lighting + * effects + */ + else if (streq(ANGBAND_GRAF, "old")) + { + graphics_mode = GRAPHICS_OLD; + } + + /* ??? */ + else + { + graphics_mode = GRAPHICS_UNKNOWN; + } + } + + /* Normal symbols */ + else + { + /* Process "font.prf" */ + process_pref_file("font.prf"); + + graphics_mode = GRAPHICS_NONE; + } +} + + +/* + * Extract "xtra" flags from object. + */ +void object_flags_xtra(object_type *o_ptr, u32b *f2, u32b *f3, u32b *esp) +{ + switch (o_ptr->xtra1) + { + case EGO_XTRA_SUSTAIN: + { + /* Choose a sustain */ + switch (o_ptr->xtra2 % 6) + { + case 0: + (*f2) |= (TR2_SUST_STR); + break; + case 1: + (*f2) |= (TR2_SUST_INT); + break; + case 2: + (*f2) |= (TR2_SUST_WIS); + break; + case 3: + (*f2) |= (TR2_SUST_DEX); + break; + case 4: + (*f2) |= (TR2_SUST_CON); + break; + case 5: + (*f2) |= (TR2_SUST_CHR); + break; + } + + break; + } + + case EGO_XTRA_POWER: + { + /* Choose a power */ + switch (o_ptr->xtra2 % 11) + { + case 0: + (*f2) |= (TR2_RES_BLIND); + break; + case 1: + (*f2) |= (TR2_RES_CONF); + break; + case 2: + (*f2) |= (TR2_RES_SOUND); + break; + case 3: + (*f2) |= (TR2_RES_SHARDS); + break; + case 4: + (*f2) |= (TR2_RES_NETHER); + break; + case 5: + (*f2) |= (TR2_RES_NEXUS); + break; + case 6: + (*f2) |= (TR2_RES_CHAOS); + break; + case 7: + (*f2) |= (TR2_RES_DISEN); + break; + case 8: + (*f2) |= (TR2_RES_POIS); + break; + case 9: + (*f2) |= (TR2_RES_DARK); + break; + case 10: + (*f2) |= (TR2_RES_LITE); + break; + } + + break; + } + + case EGO_XTRA_ABILITY: + { + /* Choose an ability */ + switch (o_ptr->xtra2 % 8) + { + case 0: + (*f3) |= (TR3_FEATHER); + break; + case 1: + (*f3) |= (TR3_LITE1); + break; + case 2: + (*f3) |= (TR3_SEE_INVIS); + break; + case 3: + (*esp) |= (ESP_ALL); + break; + case 4: + (*f3) |= (TR3_SLOW_DIGEST); + break; + case 5: + (*f3) |= (TR3_REGEN); + break; + case 6: + (*f2) |= (TR2_FREE_ACT); + break; + case 7: + (*f2) |= (TR2_HOLD_LIFE); + break; + } + + break; + } + + } +} + + +/* + * Obtain the "flags" for an item + */ +bool_ object_flags_no_set = FALSE; +void object_flags(object_type *o_ptr, u32b *f1, u32b *f2, u32b *f3, u32b *f4, u32b *f5, u32b *esp) +{ + object_kind *k_ptr = &k_info[o_ptr->k_idx]; + + /* Base object */ + (*f1) = k_ptr->flags1; + (*f2) = k_ptr->flags2; + (*f3) = k_ptr->flags3; + (*f4) = k_ptr->flags4; + (*f5) = k_ptr->flags5; + (*esp) = k_ptr->esp; + + /* Artifact */ + if (o_ptr->name1) + { + artifact_type *a_ptr = &a_info[o_ptr->name1]; + + (*f1) = a_ptr->flags1; + (*f2) = a_ptr->flags2; + (*f3) = a_ptr->flags3; + (*f4) = a_ptr->flags4; + (*f5) = a_ptr->flags5; + (*esp) = a_ptr->esp; + + if ((!object_flags_no_set) && (a_ptr->set != -1)) + apply_flags_set(o_ptr->name1, a_ptr->set, f1, f2, f3, f4, f5, esp); + } + + /* Random artifact ! */ + if (o_ptr->art_flags1 || o_ptr->art_flags2 || o_ptr->art_flags3 || o_ptr->art_flags4 || o_ptr->art_flags5 || o_ptr->art_esp) + { + (*f1) |= o_ptr->art_flags1; + (*f2) |= o_ptr->art_flags2; + (*f3) |= o_ptr->art_flags3; + (*f4) |= o_ptr->art_flags4; + (*f5) |= o_ptr->art_flags5; + (*esp) |= o_ptr->art_esp; + } + + /* Extra powers */ + if (!(o_ptr->art_name)) + { + object_flags_xtra(o_ptr, f2, f3, esp); + } +} + +/* Return object granted power */ +int object_power(object_type *o_ptr) +{ + object_kind *k_ptr = &k_info[o_ptr->k_idx]; + int power = -1; + + /* Base object */ + power = k_ptr->power; + + /* Ego-item */ + if (o_ptr->name2) + { + ego_item_type *e_ptr = &e_info[o_ptr->name2]; + + if (power == -1) power = e_ptr->power; + + if (o_ptr->name2b) + { + ego_item_type *e_ptr = &e_info[o_ptr->name2b]; + + if (power == -1) power = e_ptr->power; + } + } + + /* Artifact */ + if (o_ptr->name1) + { + artifact_type *a_ptr = &a_info[o_ptr->name1]; + + if (power == -1) power = a_ptr->power; + } + + return (power); +} + + + +/* + * Obtain the "flags" for an item which are known to the player + */ +void object_flags_known(object_type *o_ptr, u32b *f1, u32b *f2, u32b *f3, u32b *f4, u32b *f5, u32b *esp) +{ + object_kind *k_ptr = &k_info[o_ptr->k_idx]; + + /* Clear */ + (*f1) = (*f2) = (*f3) = (*f4) = (*esp) = (*f5) = 0L; + + /* Must be identified */ + if (!object_known_p(o_ptr)) return; + + /* Base object */ + (*f1) = k_ptr->flags1; + (*f2) = k_ptr->flags2; + (*f3) = k_ptr->flags3; + (*f4) = k_ptr->flags4; + (*f5) = k_ptr->flags5; + (*esp) = k_ptr->esp; + + (*f1) |= k_ptr->oflags1; + (*f2) |= k_ptr->oflags2; + (*f3) |= k_ptr->oflags3; + (*f4) |= k_ptr->oflags4; + (*f5) |= k_ptr->oflags5; + (*esp) |= k_ptr->oesp; + + /* Artifact */ + if (o_ptr->name1) + { + artifact_type *a_ptr = &a_info[o_ptr->name1]; + + /* Need full knowledge or spoilers */ + if ((o_ptr->ident & IDENT_MENTAL)) + { + (*f1) = a_ptr->flags1; + (*f2) = a_ptr->flags2; + (*f3) = a_ptr->flags3; + (*f4) = a_ptr->flags4; + (*f5) = a_ptr->flags5; + (*esp) = a_ptr->esp; + + if ((!object_flags_no_set) && (a_ptr->set != -1)) + apply_flags_set(o_ptr->name1, a_ptr->set, f1, f2, f3, f4, f5, esp); + } + else + { + (*f1) = (*f2) = (*f3) = (*f4) = (*esp) = (*f5) = 0L; + } + + (*f1) |= a_ptr->oflags1; + (*f2) |= a_ptr->oflags2; + (*f3) |= a_ptr->oflags3; + (*f4) |= a_ptr->oflags4; + (*f5) |= a_ptr->oflags5; + (*esp) |= a_ptr->oesp; + } + + /* Random artifact or ego item! */ + if (o_ptr->art_flags1 || o_ptr->art_flags2 || o_ptr->art_flags3 || o_ptr->art_flags4 || o_ptr->art_flags5 || o_ptr->art_esp) + { + /* Need full knowledge or spoilers */ + if ((o_ptr->ident & IDENT_MENTAL)) + { + (*f1) |= o_ptr->art_flags1; + (*f2) |= o_ptr->art_flags2; + (*f3) |= o_ptr->art_flags3; + (*f4) |= o_ptr->art_flags4; + (*f5) |= o_ptr->art_flags5; + (*esp) |= o_ptr->art_esp; + } + + (*f1) |= o_ptr->art_oflags1; + (*f2) |= o_ptr->art_oflags2; + (*f3) |= o_ptr->art_oflags3; + (*f4) |= o_ptr->art_oflags4; + (*f5) |= o_ptr->art_oflags5; + (*esp) |= o_ptr->art_oesp; + } + + /* Full knowledge for *identified* objects */ + if (!(o_ptr->ident & IDENT_MENTAL)) return; + + if (!(o_ptr->art_name)) + { + object_flags_xtra(o_ptr, f2, f3, esp); + } + + /* Hack - Res Chaos -> Res Confusion */ + if (*f2 & TR2_RES_CHAOS) (*f2) |= (TR2_RES_CONF); +} + + + + + +/* + * Print a char "c" into a string "t", as if by sprintf(t, "%c", c), + * and return a pointer to the terminator (t + 1). + */ +static char *object_desc_chr(char *t, char c) +{ + /* Copy the char */ + *t++ = c; + + /* Terminate */ + *t = '\0'; + + /* Result */ + return (t); +} + + +/* + * Print a string "s" into a string "t", as if by strcpy(t, s), + * and return a pointer to the terminator. + */ +static char *object_desc_str(char *t, cptr s) +{ + /* Copy the string */ + while (*s) *t++ = *s++; + + /* Terminate */ + *t = '\0'; + + /* Result */ + return (t); +} + +/* + * Do the actual conversion of a number for object_desc_num() and + * object_desc_int(). + */ +static char *convert_number(char *result, u32b num) +{ + char *tp; + char temp[11]; + + tp = temp; + *tp = '0' + (num % 10); + for (num /= 10; num != 0; num /= 10) + { + *++tp = '0' + (num % 10); + } + + while (tp != temp) + { + *result++ = *tp--; + } + *result++ = *tp; + *result = '\0'; + + return result; +} + +/* + * Print a nnumber "n" into a string "t", as if by + * sprintf(t, "%u", n), and return a pointer to the terminator. + */ +static char *object_desc_num(char *result, s32b num) +{ + u32b n; + + if (num < 0) + { + *result++ = '-'; + n = -num; + } + else + n = num; + + /* Result */ + return convert_number(result, n); +} + +/* + * Print an signed number "num" into a string "result", as if by + * sprintf(t, "%+d", n), and return a pointer to the terminator. + * Note that we always print a sign, either "+" or "-". + */ +static char *object_desc_int(char *result, s32b num) +{ + u32b n; + + /* Negative */ + if (num < 0) + { + /* Take the absolute value */ + n = -num; + + /* Use a "minus" sign */ + *result++ = '-'; + } + /* Positive (or zero) */ + else + { + /* Use the actual number */ + n = num; + + /* Use a "plus" sign */ + *result++ = '+'; + } + + /* Result */ + return convert_number(result, n); +} + +/* + * Creates a description of the item "o_ptr", and stores it in "out_val". + * + * One can choose the "verbosity" of the description, including whether + * or not the "number" of items should be described, and how much detail + * should be used when describing the item. + * + * The given "buf" must be 80 chars long to hold the longest possible + * description, which can get pretty long, including incriptions, such as: + * "no more Maces of Disruption (Defender) (+10,+10) [+5] (+3 to stealth)". + * Note that the inscription will be clipped to keep the total description + * under 79 chars (plus a terminator). + * + * Note the use of "object_desc_num()" and "object_desc_int()" as hyper-efficient, + * portable, versions of some common "sprintf()" commands. + * + * Note that all ego-items (when known) append an "Ego-Item Name", unless + * the item is also an artifact, which should NEVER happen. + * + * Note that all artifacts (when known) append an "Artifact Name", so we + * have special processing for "Specials" (artifact Lites, Rings, Amulets). + * The "Specials" never use "modifiers" if they are "known", since they + * have special "descriptions", such as "The Necklace of the Dwarves". + * + * Special Lite's use the "k_info" base-name (Phial, Star, or Arkenstone), + * plus the artifact name, just like any other artifact, if known. + * + * Special Ring's and Amulet's, if not "aware", use the same code as normal + * rings and amulets, and if "aware", use the "k_info" base-name (Ring or + * Amulet or Necklace). They will NEVER "append" the "k_info" name. But, + * they will append the artifact name, just like any artifact, if known. + * + * None of the Special Rings/Amulets are "EASY_KNOW", though they could be, + * at least, those which have no "pluses", such as the three artifact lites. + * + * Hack -- Display "The One Ring" as "a Plain Gold Ring" until aware. + * + * If "pref" then a "numeric" prefix will be pre-pended. + * + * Mode: + * 0 -- The Cloak of Death + * 1 -- The Cloak of Death [1,+3] + * 2 -- The Cloak of Death [1,+3] (+2 to Stealth) + * 3 -- The Cloak of Death [1,+3] (+2 to Stealth) {nifty} + */ +void object_desc(char *buf, object_type *o_ptr, int pref, int mode) +{ + bool_ hack_name = FALSE; + cptr basenm, modstr; + int indexx; + + bool_ aware = FALSE; + bool_ known = FALSE; + + bool_ append_name = FALSE; + + bool_ show_weapon = FALSE; + bool_ show_armour = FALSE; + + cptr s, u; + char *t; + + char p1 = '(', p2 = ')'; + char b1 = '[', b2 = ']'; + char c1 = '{', c2 = '}'; + + char tmp_val[160]; + char tmp_val2[90]; + + s32b power; + u32b f1, f2, f3, f4, f5, esp; + + object_kind *k_ptr = &k_info[o_ptr->k_idx]; + + cptr str; + + /* Extract some flags */ + object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); + + + /* See if the object is "aware" */ + if (object_aware_p(o_ptr)) aware = TRUE; + + /* See if the object is "known" */ + if (object_known_p(o_ptr)) known = TRUE; + + /* Hack -- Extract the sub-type "indexx" */ + indexx = o_ptr->sval; + + /* Extract default "base" string */ + basenm = (k_name + k_ptr->name); + + /* Assume no "modifier" string */ + modstr = ""; + + /* Analyze the object */ + switch (o_ptr->tval) + { + /* Some objects are easy to describe */ + case TV_SKELETON: + case TV_BOTTLE: + case TV_JUNK: + case TV_SPIKE: + case TV_FLASK: + case TV_CHEST: + case TV_INSTRUMENT: + case TV_TOOL: + case TV_DIGGING: + { + break; + } + + + /* Missiles/ Bows/ Weapons */ + case TV_SHOT: + case TV_BOLT: + case TV_ARROW: + case TV_BOOMERANG: + case TV_BOW: + case TV_HAFTED: + case TV_POLEARM: + case TV_MSTAFF: + case TV_SWORD: + case TV_AXE: + { + show_weapon = TRUE; + break; + } + + /* Trapping Kits */ + case TV_TRAPKIT: + { + modstr = basenm; + basenm = "& # Trap Set~"; + break; + } + + /* Armour */ + case TV_BOOTS: + case TV_GLOVES: + case TV_CROWN: + case TV_HELM: + case TV_SHIELD: + case TV_SOFT_ARMOR: + case TV_HARD_ARMOR: + case TV_DRAG_ARMOR: + { + show_armour = TRUE; + break; + } + + + /* Lites (including a few "Specials") */ + case TV_LITE: + { + break; + } + + /* Amulets (including a few "Specials") */ + case TV_AMULET: + { + /* Color the object */ + modstr = amulet_adj[indexx]; + if (aware) append_name = TRUE; + + if (((plain_descriptions) && (aware)) || o_ptr->ident & IDENT_STOREB) + basenm = "& Amulet~"; + else + basenm = aware ? "& # Amulet~" : "& # Amulet~"; + + if (known && !o_ptr->art_name && artifact_p(o_ptr)) basenm = k_ptr->name + k_name; + + break; + } + + /* Rings (including a few "Specials") */ + case TV_RING: + { + /* Color the object */ + modstr = ring_adj[indexx]; + if (aware) append_name = TRUE; + + if (((plain_descriptions) && (aware)) || o_ptr->ident & IDENT_STOREB) + basenm = "& Ring~"; + else + basenm = aware ? "& # Ring~" : "& # Ring~"; + + /* Hack -- The One Ring */ + if (!aware && (o_ptr->sval == SV_RING_POWER)) modstr = "Plain Gold"; + + if (known && !o_ptr->art_name && artifact_p(o_ptr)) basenm = k_ptr->name + k_name; + + break; + } + + case TV_STAFF: + { + /* Color the object */ + modstr = staff_adj[o_ptr->pval2 % MAX_WOODS]; + if (aware) append_name = TRUE; + if (((plain_descriptions) && (aware)) || o_ptr->ident & IDENT_STOREB) + basenm = "& Staff~"; + else + basenm = "& # Staff~"; + break; + } + + case TV_WAND: + { + /* Color the object */ + modstr = wand_adj[o_ptr->pval2 % MAX_METALS]; + if (aware) append_name = TRUE; + if (((plain_descriptions) && (aware)) || o_ptr->ident & IDENT_STOREB) + basenm = "& Wand~"; + else + basenm = "& # Wand~"; + break; + } + + case TV_ROD: + { + /* Color the object */ + modstr = rod_adj[indexx]; + if (aware) append_name = TRUE; + if (((plain_descriptions) && (aware)) || o_ptr->ident & IDENT_STOREB) + basenm = "& Rod Tip~"; + else + basenm = aware ? "& # Rod Tip~" : "& # Rod Tip~"; + if (o_ptr->sval == SV_ROD_HOME) + { + basenm = "& Great Rod Tip~ of Home Summoning"; + hack_name = TRUE; + } + break; + } + + case TV_ROD_MAIN: + { + object_kind *tip_ptr = &k_info[lookup_kind(TV_ROD, o_ptr->pval)]; + + modstr = k_name + tip_ptr->name; + break; + } + + case TV_SCROLL: + { + /* Color the object */ + modstr = scroll_adj[indexx]; + if (aware) append_name = TRUE; + if (((plain_descriptions) && (aware)) || o_ptr->ident & IDENT_STOREB) + basenm = "& Scroll~"; + else + basenm = aware ? "& Scroll~ titled \"#\"" : "& Scroll~ titled \"#\""; + break; + } + + case TV_POTION: + case TV_POTION2: + { + /* Color the object */ + if ((o_ptr->tval != TV_POTION2) || (o_ptr->sval != SV_POTION2_MIMIC) || (!aware)) + { + modstr = potion_adj[indexx]; + if (aware) append_name = TRUE; + } + else + { + modstr = get_mimic_name(o_ptr->pval2); + } + if (((plain_descriptions) && (aware)) || o_ptr->ident & IDENT_STOREB) + basenm = "& Potion~"; + else + basenm = aware ? "& # Potion~" : "& # Potion~"; + break; + } + + case TV_FOOD: + { + /* Ordinary food is "boring" */ + if (o_ptr->sval >= SV_FOOD_MIN_FOOD) break; + + /* Color the object */ + modstr = food_adj[indexx]; + if (aware) append_name = TRUE; + if (((plain_descriptions) && (aware)) || o_ptr->ident & IDENT_STOREB) + basenm = "& Mushroom~"; + else + basenm = aware ? "& # Mushroom~" : "& # Mushroom~"; + break; + } + + + /* Cloak of Mimicry */ + case TV_CLOAK: + { + show_armour = TRUE; + if (o_ptr->sval == SV_MIMIC_CLOAK) + { + modstr = get_mimic_object_name(o_ptr->pval2); + } + break; + } + + + case TV_SYMBIOTIC_BOOK: + { + modstr = basenm; + basenm = "& Symbiotic Spellbook~ #"; + break; + } + + case TV_MUSIC_BOOK: + { + modstr = basenm; + basenm = "& Songbook~ #"; + break; + } + + /* Druid Books */ + case TV_DRUID_BOOK: + { + modstr = basenm; + basenm = "& Elemental Stone~ #"; + break; + } + + case TV_BATERIE: + { + modstr = basenm; + basenm = "& Essence~ of #"; + break; + } + + case TV_PARCHMENT: + { + modstr = basenm; + basenm = "& Parchment~ - #"; + break; + } + + + /* Hack -- Gold/Gems */ + case TV_GOLD: + { + strcpy(buf, basenm); + return; + } + + case TV_CORPSE: + { + monster_race* r_ptr = &r_info[o_ptr->pval2]; + modstr = basenm; + if (r_ptr->flags1 & RF1_UNIQUE) + basenm = format("& %s's #~", r_name + r_ptr->name); + else + basenm = format("& %s #~", r_name + r_ptr->name); + break; + } + + case TV_EGG: + { + monster_race* r_ptr = &r_info[o_ptr->pval2]; + modstr = basenm; + + basenm = format("& %s #~", r_name + r_ptr->name); + break; + } + + case TV_HYPNOS: + { + /* We print hit points further down. --dsb */ + monster_race* r_ptr = &r_info[o_ptr->pval]; + modstr = basenm; + basenm = format("& %s~", r_name + r_ptr->name); + break; + } + + case TV_TOTEM: + { + char name[80]; + monster_type monster; + + monster.r_idx = o_ptr->pval; + monster.ego = o_ptr->pval2; + monster.ml = TRUE; + monster.status = MSTATUS_ENEMY; + + monster_desc(name, &monster, 0x188); + + modstr = basenm; + basenm = format("& #~ of %s", name); + break; + } + + case TV_RANDART: + { + modstr = basenm; + + if (known) + { + basenm = random_artifacts[indexx].name_full; + } + else + { + basenm = random_artifacts[indexx].name_short; + } + break; + } + + case TV_RUNE2: + { + if (o_ptr->sval != RUNE_STONE) + { + modstr = basenm; + basenm = "& Rune~ [#]"; + } + break; + } + + case TV_RUNE1: + { + modstr = basenm; + basenm = "& Rune~ [#]"; + break; + } + + case TV_DAEMON_BOOK: + case TV_BOOK: + { + basenm = k_name + k_ptr->name; + if (o_ptr->sval == 255) + { + modstr = spell_type_name(spell_at(o_ptr->pval)); + } + break; + } + + /* Used in the "inventory" routine */ + default: + { + if (process_hooks_ret(HOOK_ITEM_NAME, "ss", "(O,s,s)", + o_ptr, basenm, modstr)) + { + basenm = process_hooks_return[0].str; + modstr = process_hooks_return[1].str; + break; + } + else + { + strcpy(buf, "(nothing)"); + return; + } + } + } + + /* Mega Hack */ + if ((!hack_name) && known && (k_ptr->flags5 & TR5_FULL_NAME)) basenm = (k_name + k_ptr->name); + + + /* Start dumping the result */ + t = tmp_val; + + /* The object "expects" a "number" */ + if (basenm[0] == '&') + { + monster_race* r_ptr; + cptr ego = NULL; + + if (o_ptr->tval == TV_CORPSE) r_ptr = &r_info[o_ptr->pval2]; + else r_ptr = &r_info[o_ptr->pval]; + + /* Grab any ego-item name */ + if (known && (o_ptr->name2 || o_ptr->name2b) && (o_ptr->tval != TV_ROD_MAIN)) + { + ego_item_type *e_ptr = &e_info[o_ptr->name2]; + ego_item_type *e2_ptr = &e_info[o_ptr->name2b]; + + if (e_ptr->before) + { + ego = e_ptr->name + e_name; + } + else if (e2_ptr->before) + { + ego = e2_ptr->name + e_name; + } + } + + /* Skip the ampersand (and space) */ + s = basenm + 2; + + /* No prefix */ + if (pref <= 0) + { + /* Nothing */ + } + + /* Hack -- None left */ + else if (o_ptr->number <= 0) + { + t = object_desc_str(t, "no more "); + } + + /* Extract the number */ + else if (o_ptr->number > 1) + { + t = object_desc_num(t, o_ptr->number); + t = object_desc_chr(t, ' '); + } + + else if ((o_ptr->tval == TV_CORPSE) && (r_ptr->flags1 & RF1_UNIQUE)) + {} + + + else if ((o_ptr->tval == TV_HYPNOS) && (r_ptr->flags1 & RF1_UNIQUE)) + {} + + /* Hack -- The only one of its kind */ + else if (known && (artifact_p(o_ptr) || o_ptr->art_name)) + { + t = object_desc_str(t, "The "); + } + + else if (ego != NULL) + { + if (is_a_vowel(ego[0])) + { + t = object_desc_str(t, "an "); + } + else + { + t = object_desc_str(t, "a "); + } + } + + /* A single one, with a vowel in the modifier */ + else if ((*s == '#') && (is_a_vowel(modstr[0]))) + { + t = object_desc_str(t, "an "); + } + + /* A single one, with a vowel */ + else if (is_a_vowel(*s)) + { + t = object_desc_str(t, "an "); + } + + /* A single one, without a vowel */ + else + { + t = object_desc_str(t, "a "); + } + + /* Grab any ego-item name */ + if (known && (o_ptr->name2 || o_ptr->name2b) && (o_ptr->tval != TV_ROD_MAIN)) + { + ego_item_type *e_ptr = &e_info[o_ptr->name2]; + ego_item_type *e2_ptr = &e_info[o_ptr->name2b]; + + if (e_ptr->before) + { + t = object_desc_str(t, (e_name + e_ptr->name)); + t = object_desc_chr(t, ' '); + } + if (e2_ptr->before) + { + t = object_desc_str(t, (e_name + e2_ptr->name)); + t = object_desc_chr(t, ' '); + } + } + + /* -TM- Hack -- Add false-artifact names */ + /* Dagger inscribed {@w0%Smelly} will be named + * Smelly Dagger {@w0} */ + + if (o_ptr->note) + { + str = strchr(quark_str(o_ptr->note), '%'); + + /* Add the false name */ + if (str) + { + t = object_desc_str(t, &str[1]); + t = object_desc_chr(t, ' '); + } + } + + } + + /* Hack -- objects that "never" take an article */ + else + { + /* No ampersand */ + s = basenm; + + /* No pref */ + if (!pref) + { + /* Nothing */ + } + + /* Hack -- all gone */ + else if (o_ptr->number <= 0) + { + t = object_desc_str(t, "no more "); + } + + /* Prefix a number if required */ + else if (o_ptr->number > 1) + { + t = object_desc_num(t, o_ptr->number); + t = object_desc_chr(t, ' '); + } + + else if (o_ptr->tval == TV_RANDART) + { + /* Do nothing, since randarts have their prefix already included */ + } + + /* Hack -- The only one of its kind */ + else if (known && (artifact_p(o_ptr) || o_ptr->art_name)) + { + t = object_desc_str(t, "The "); + } + + /* Hack -- single items get no prefix */ + else + { + /* Nothing */ + } + + /* Grab any ego-item name */ + if (known && (o_ptr->name2 || o_ptr->name2b) && (o_ptr->tval != TV_ROD_MAIN)) + { + ego_item_type *e_ptr = &e_info[o_ptr->name2]; + ego_item_type *e2_ptr = &e_info[o_ptr->name2b]; + + if (e_ptr->before) + { + t = object_desc_str(t, (e_name + e_ptr->name)); + t = object_desc_chr(t, ' '); + } + if (e2_ptr->before) + { + t = object_desc_str(t, (e_name + e2_ptr->name)); + t = object_desc_chr(t, ' '); + } + } + } + + /* Paranoia -- skip illegal tildes */ + /* while (*s == '~') s++; */ + + /* Copy the string */ + for (; *s; s++) + { + /* Pluralizer */ + if (*s == '~') + { + /* Add a plural if needed */ + if ((o_ptr->number != 1) && (pref >= 0)) + { + char k = t[ -1]; + + /* XXX XXX XXX Mega-Hack */ + + /* Hack -- "Cutlass-es" and "Torch-es" */ + if ((k == 's') || (k == 'h')) *t++ = 'e'; + + /* Add an 's' */ + *t++ = 's'; + } + } + + /* Modifier */ + else if (*s == '#') + { + /* Grab any ego-item name */ + if (o_ptr->tval == TV_ROD_MAIN) + { + t = object_desc_chr(t, ' '); + + if (known && o_ptr->name2) + { + ego_item_type *e_ptr = &e_info[o_ptr->name2]; + + t = object_desc_str(t, (e_name + e_ptr->name)); + } + } + + /* Insert the modifier */ + for (u = modstr; *u; u++) *t++ = *u; + } + + /* Normal */ + else + { + /* Copy */ + *t++ = *s; + } + } + + /* Terminate */ + *t = '\0'; + + + /* Append the "kind name" to the "base name" */ + if ((append_name) && (!artifact_p(o_ptr))) + { + t = object_desc_str(t, " of "); + + if (((o_ptr->tval == TV_WAND) || (o_ptr->tval == TV_STAFF))) + { + t = object_desc_str(t, spell_type_name(spell_at(o_ptr->pval2))); + if (mode >= 1) + { + s32b bonus = o_ptr->pval3 & 0xFFFF; + s32b max = o_ptr->pval3 >> 16; + + t = object_desc_chr(t, '['); + t = object_desc_num(t, bonus); + t = object_desc_chr(t, '|'); + t = object_desc_num(t, max); + t = object_desc_chr(t, ']'); + } + } + else + t = object_desc_str(t, (k_name + k_ptr->name)); + } + + /* Hack -- Append "Artifact" or "Special" names */ + if (known) + { + + /* -TM- Hack -- Add false-artifact names */ + /* Dagger inscribed {@w0#of Smell} will be named + * Dagger of Smell {@w0} */ + if (o_ptr->note) + { + str = strchr(quark_str(o_ptr->note), '#'); + + /* Add the false name */ + if (str) + { + t = object_desc_chr(t, ' '); + t = object_desc_str(t, &str[1]); + } + } + + /* Is it a new random artifact ? */ + if (o_ptr->art_name) + { + t = object_desc_chr(t, ' '); + + t = object_desc_str(t, quark_str(o_ptr->art_name)); + } + + + /* Grab any artifact name */ + else if (o_ptr->name1) + { + artifact_type *a_ptr = &a_info[o_ptr->name1]; + + /* Unique corpses don't require another name */ + if (o_ptr->tval != TV_CORPSE) + { + t = object_desc_chr(t, ' '); + t = object_desc_str(t, (a_name + a_ptr->name)); + } + } + + /* Grab any ego-item name */ + else if ((o_ptr->name2 || o_ptr->name2b) && (o_ptr->tval != TV_ROD_MAIN)) + { + ego_item_type *e_ptr = &e_info[o_ptr->name2]; + ego_item_type *e2_ptr = &e_info[o_ptr->name2b]; + + if (o_ptr->name2 && !e_ptr->before) + { + t = object_desc_chr(t, ' '); + t = object_desc_str(t, (e_name + e_ptr->name)); + } + if (o_ptr->name2b && !e2_ptr->before) + { + t = object_desc_chr(t, ' '); + t = object_desc_str(t, (e_name + e2_ptr->name)); + } + } + } + + /* It contains a spell */ + if ((known) && (f5 & TR5_SPELL_CONTAIN) && (o_ptr->pval2 != -1)) + { + t = object_desc_str(t, format(" [%s]", spell_type_name(spell_at(o_ptr->pval2)))); + } + + /* Add symbiote hp here, after the "fake-artifact" name. --dsb */ + if (o_ptr->tval == TV_HYPNOS) + { + t = object_desc_str(t, " ("); + t = object_desc_num(t, o_ptr->pval2); + t = object_desc_str(t, " hp)"); + } + + /* No more details wanted */ + if (mode < 1) goto copyback; + + /* Hack -- Some objects can have an exp level */ + if ((f4 & TR4_LEVELS) && known) + { + t = object_desc_str(t, " (E:"); + if (exp_need) + { + s32b need; + /* Formula from check_experience_obj(). */ + need = player_exp[o_ptr->elevel - 1] * 5 / 2; + t = object_desc_num(t, need - o_ptr->exp); + } + else + { + t = object_desc_num(t, o_ptr->exp); + } + t = object_desc_str(t, ", L:"); + t = object_desc_num(t, o_ptr->elevel); + t = object_desc_chr(t, ')'); + } + if ((f4 & TR4_ART_EXP) && known) + { + t = object_desc_str(t, " (Exp:"); + t = object_desc_num(t, o_ptr->exp); + t = object_desc_chr(t, ')'); + } + + /* Hack -- Chests must be described in detail */ + if (o_ptr->tval == TV_CHEST) + { + /* Not searched yet */ + if (!known) + { + /* Nothing */ + } + + /* May be "empty" */ + else if (!o_ptr->pval) + { + t = object_desc_str(t, " (empty)"); + } + + /* May be "disarmed" */ + else if (o_ptr->pval < 0) + { + t = object_desc_str(t, " (disarmed)"); + } + + /* Describe the traps, if any */ + else + { + /* Describe the traps */ + t = object_desc_str(t, " ("); + if (t_info[o_ptr->pval].ident) + t = object_desc_str(t, t_name + t_info[o_ptr->pval].name); + else + t = object_desc_str(t, "trapped"); + t = object_desc_str(t, ")"); + } + } + + + /* Display the item like a weapon */ + if (f3 & (TR3_SHOW_MODS)) show_weapon = TRUE; + + /* Display the item like a weapon */ + if (o_ptr->to_h && o_ptr->to_d) show_weapon = TRUE; + + /* Display the item like armour */ + if (o_ptr->ac) show_armour = TRUE; + + /* Dump base weapon info */ + switch (o_ptr->tval) + { + /* Missiles and Weapons */ + case TV_SHOT: + case TV_BOLT: + case TV_ARROW: + /* Exploding arrow? */ + if (o_ptr->pval2 != 0) + t = object_desc_str(t, " (exploding)"); + /* No break, we want to continue the description */ + + case TV_BOOMERANG: + case TV_HAFTED: + case TV_POLEARM: + case TV_MSTAFF: + case TV_AXE: + case TV_SWORD: + case TV_DAEMON_BOOK: + if ((o_ptr->tval == TV_DAEMON_BOOK) && (o_ptr->sval != SV_DEMONBLADE)) + break; + + /* Append a "damage" string */ + t = object_desc_chr(t, ' '); + t = object_desc_chr(t, p1); + t = object_desc_num(t, o_ptr->dd); + t = object_desc_chr(t, 'd'); + t = object_desc_num(t, o_ptr->ds); + t = object_desc_chr(t, p2); + + /* All done */ + break; + + + /* Bows get a special "damage string" */ + case TV_BOW: + + /* Mega-Hack -- Extract the "base power" */ + power = (o_ptr->sval % 10); + + /* Apply the "Extra Might" flag */ + if (f3 & (TR3_XTRA_MIGHT)) power += o_ptr->pval; + + /* Append a special "damage" string */ + t = object_desc_chr(t, ' '); + t = object_desc_chr(t, p1); + t = object_desc_chr(t, 'x'); + t = object_desc_num(t, power); + t = object_desc_chr(t, p2); + + /* All done */ + break; + } + + + /* Add the weapon bonuses */ + if (known) + { + /* Show the tohit/todam on request */ + if (show_weapon) + { + t = object_desc_chr(t, ' '); + t = object_desc_chr(t, p1); + t = object_desc_int(t, o_ptr->to_h); + t = object_desc_chr(t, ','); + t = object_desc_int(t, o_ptr->to_d); + t = object_desc_chr(t, p2); + } + + /* Show the tohit if needed */ + else if (o_ptr->to_h) + { + t = object_desc_chr(t, ' '); + t = object_desc_chr(t, p1); + t = object_desc_int(t, o_ptr->to_h); + if (!(f3 & (TR3_HIDE_TYPE)) || o_ptr->art_name) + t = object_desc_str(t, " to accuracy"); + t = object_desc_chr(t, p2); + } + + /* Show the todam if needed */ + else if (o_ptr->to_d) + { + t = object_desc_chr(t, ' '); + t = object_desc_chr(t, p1); + t = object_desc_int(t, o_ptr->to_d); + if (!(f3 & (TR3_HIDE_TYPE)) || o_ptr->art_name) + t = object_desc_str(t, " to damage"); + t = object_desc_chr(t, p2); + } + } + + + /* Add the armor bonuses */ + if (known) + { + /* Show the armor class info */ + if (show_armour) + { + t = object_desc_chr(t, ' '); + t = object_desc_chr(t, b1); + t = object_desc_num(t, o_ptr->ac); + t = object_desc_chr(t, ','); + t = object_desc_int(t, o_ptr->to_a); + t = object_desc_chr(t, b2); + } + + /* No base armor, but does increase armor */ + else if (o_ptr->to_a) + { + t = object_desc_chr(t, ' '); + t = object_desc_chr(t, b1); + t = object_desc_int(t, o_ptr->to_a); + t = object_desc_chr(t, b2); + } + } + + /* Hack -- always show base armor */ + else if (show_armour) + { + t = object_desc_chr(t, ' '); + t = object_desc_chr(t, b1); + t = object_desc_num(t, o_ptr->ac); + t = object_desc_chr(t, b2); + } + + if ((f1 & TR1_MANA) && (known) && (o_ptr->pval > 0)) + { + t = object_desc_chr(t, '('); + t = object_desc_num(t, 100 * o_ptr->pval / 5); + t = object_desc_str(t, "%)"); + } + + if ((known) && (f2 & TR2_LIFE) ) /* Can disp neg now -- Improv */ + { + t = object_desc_chr(t, '('); + t = object_desc_num(t, 100 * o_ptr->pval / 5); + t = object_desc_str(t, "%)"); + } + + /* No more details wanted */ + if (mode < 2) goto copyback; + + + /* Hack -- Wands and Staffs have charges */ + if (known && + ((o_ptr->tval == TV_STAFF) || + (o_ptr->tval == TV_WAND))) + { + /* Dump " (N charges)" */ + t = object_desc_chr(t, ' '); + t = object_desc_chr(t, p1); + t = object_desc_num(t, o_ptr->pval); + t = object_desc_str(t, " charge"); + if (o_ptr->pval != 1) t = object_desc_chr(t, 's'); + t = object_desc_chr(t, p2); + } + + /* + * Hack -- Rods have a "charging" indicator. + */ + else if (known && (o_ptr->tval == TV_ROD_MAIN)) + { + /* Display prettily. */ + t = object_desc_str(t, " ("); + t = object_desc_num(t, o_ptr->timeout); + t = object_desc_chr(t, '/'); + t = object_desc_num(t, o_ptr->pval2); + t = object_desc_chr(t, ')'); + } + + /* + * Hack -- Rods have a "charging" indicator. + */ + else if (known && (o_ptr->tval == TV_ROD)) + { + /* Display prettily. */ + t = object_desc_str(t, " ("); + t = object_desc_num(t, o_ptr->pval); + t = object_desc_str(t, " Mana to cast"); + t = object_desc_chr(t, ')'); + } + + /* Hack -- Process Lanterns/Torches */ + else if ((o_ptr->tval == TV_LITE) && (f4 & TR4_FUEL_LITE)) + { + /* Hack -- Turns of light for normal lites */ + t = object_desc_str(t, " (with "); + t = object_desc_num(t, o_ptr->timeout); + t = object_desc_str(t, " turns of light)"); + } + + + /* Dump "pval" flags for wearable items */ + if (known && ((f1 & (TR1_PVAL_MASK)) || (f5 & (TR5_PVAL_MASK)))) + { + /* Start the display */ + t = object_desc_chr(t, ' '); + t = object_desc_chr(t, p1); + + /* Dump the "pval" itself */ + t = object_desc_int(t, o_ptr->pval); + + /* Do not display the "pval" flags */ + if (f3 & (TR3_HIDE_TYPE)) + { + /* Nothing */ + } + + /* Speed */ + else if (f1 & (TR1_SPEED)) + { + /* Dump " to speed" */ + t = object_desc_str(t, " to speed"); + } + + /* Attack speed */ + else if (f1 & (TR1_BLOWS)) + { + /* Add " attack" */ + t = object_desc_str(t, " attack"); + + /* Add "attacks" */ + if (ABS(o_ptr->pval) != 1) t = object_desc_chr(t, 's'); + } + + /* Critical chance */ + else if (f5 & (TR5_CRIT)) + { + /* Add " attack" */ + t = object_desc_str(t, "% of critical hits"); + } + + /* Stealth */ + else if (f1 & (TR1_STEALTH)) + { + /* Dump " to stealth" */ + t = object_desc_str(t, " to stealth"); + } + + /* Search */ + else if (f1 & (TR1_SEARCH)) + { + /* Dump " to searching" */ + t = object_desc_str(t, " to searching"); + } + + /* Infravision */ + else if (f1 & (TR1_INFRA)) + { + /* Dump " to infravision" */ + t = object_desc_str(t, " to infravision"); + } + + /* Tunneling */ + else if (f1 & (TR1_TUNNEL)) + { + /* Nothing */ + } + + /* Finish the display */ + t = object_desc_chr(t, p2); + } + + + /* Indicate "charging" artifacts XXX XXX XXX */ + if (known && (f3 & TR3_ACTIVATE) && o_ptr->timeout) + { + if(o_ptr->tval == TV_EGG) + /* Hack -- Dump " (stopped)" if relevant */ + t = object_desc_str(t, " (stopped)"); + else + /* Hack -- Dump " (charging)" if relevant */ + t = object_desc_str(t, " (charging)"); + } + + /* Indicate "charging" Mage Staffs XXX XXX XXX */ + if (known && o_ptr->timeout && (is_ego_p(o_ptr, EGO_MSTAFF_SPELL))) + { + /* Hack -- Dump " (charging spell1)" if relevant */ + t = object_desc_str(t, " (charging spell1)"); + } + if (known && o_ptr->xtra2 && (is_ego_p(o_ptr, EGO_MSTAFF_SPELL))) + { + /* Hack -- Dump " (charging spell2)" if relevant */ + t = object_desc_str(t, " (charging spell2)"); + } + + + /* No more details wanted */ + if (mode < 3) goto copyback; + + + /* No inscription yet */ + tmp_val2[0] = '\0'; + + /* Sensed stuff */ + if (o_ptr->ident & (IDENT_SENSE)) + { + strcpy(tmp_val2, sense_desc[o_ptr->sense]); + } + + /* Hack - Note "cursed" if the item is 'known' and cursed */ + if (cursed_p(o_ptr) && (known) && (!tmp_val2[0])) + { + if (tmp_val2[0]) strcat(tmp_val2, ", "); + strcat(tmp_val2, "cursed"); + } + + /* Use the standard inscription if available */ + if (o_ptr->note) + { + char *u = tmp_val2; + + if (tmp_val2[0]) strcat(tmp_val2, ", "); + + strcat(tmp_val2, quark_str(o_ptr->note)); + + for (; *u && (*u != '#') && (*u != '%'); u++); + + *u = '\0'; + } + + /* Mega-Hack -- note empty wands/staffs */ + if (!known && (o_ptr->ident & (IDENT_EMPTY))) + { + if (tmp_val2[0]) strcat(tmp_val2, ", "); + strcat(tmp_val2, "empty"); + } + + /* Note "tried" if the object has been tested unsuccessfully */ + if (!aware && object_tried_p(o_ptr)) + { + if (tmp_val2[0]) strcat(tmp_val2, ", "); + strcpy(tmp_val2, "tried"); + } + + /* Note the discount, if any */ + if ((o_ptr->discount) && (!tmp_val2[0])) + { + object_desc_num(tmp_val2, o_ptr->discount); + strcat(tmp_val2, "% off"); + } + + /* Append the inscription, if any */ + if (tmp_val2[0]) + { + int n; + + /* Hack -- How much so far */ + n = (t - tmp_val); + + /* Paranoia -- do not be stupid */ + if (n > 75) n = 75; + + /* Hack -- shrink the inscription */ + tmp_val2[75 - n] = '\0'; + + /* Append the inscription */ + t = object_desc_chr(t, ' '); + t = object_desc_chr(t, c1); + t = object_desc_str(t, tmp_val2); + t = object_desc_chr(t, c2); + } +copyback: + /* Here's where we dump the built string into buf. */ + tmp_val[79] = '\0'; + t = tmp_val; + while ((*(buf++) = *(t++))); /* copy the string over */ +} + + +/* + * Hack -- describe an item currently in a store's inventory + * This allows an item to *look* like the player is "aware" of it + */ +void object_desc_store(char *buf, object_type *o_ptr, int pref, int mode) +{ + /* Save the "aware" flag */ + bool_ hack_aware = k_info[o_ptr->k_idx].aware; + + /* Save the "known" flag */ + bool_ hack_known = (o_ptr->ident & (IDENT_KNOWN)) ? TRUE : FALSE; + + + /* Set the "known" flag */ + o_ptr->ident |= (IDENT_KNOWN); + + /* Force "aware" for description */ + k_info[o_ptr->k_idx].aware = TRUE; + + + /* Describe the object */ + object_desc(buf, o_ptr, pref, mode); + + + /* Restore "aware" flag */ + k_info[o_ptr->k_idx].aware = hack_aware; + + /* Clear the known flag */ + if (!hack_known) o_ptr->ident &= ~(IDENT_KNOWN); +} + + + + +/* + * Determine the "Activation" (if any) for an artifact + * Return a string, or NULL for "no activation" + */ +cptr item_activation(object_type *o_ptr, byte num) +{ + u32b f1, f2, f3, f4, f5, esp; + + /* Needed hacks */ + static char rspell[2][80]; + + /* Extract the flags */ + object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); + + /* Require activation ability */ + if (!(f3 & (TR3_ACTIVATE))) return (NULL); + + + /* + * We need to deduce somehow that it is a random artifact -- one + * problem: It could be a random artifact which has NOT YET received + * a name. Thus we eliminate other possibilities instead of checking + * for art_name + */ + + if (is_ego_p(o_ptr, EGO_MSTAFF_SPELL)) + { + int gf, mod, mana; + + if (!num) + { + gf = o_ptr->pval & 0xFFFF; + mod = o_ptr->pval3 & 0xFFFF; + mana = o_ptr->pval2 & 0xFF; + } + else + { + gf = o_ptr->pval >> 16; + mod = o_ptr->pval3 >> 16; + mana = o_ptr->pval2 >> 8; + } + sprintf(rspell[num], "runespell(%s, %s, %d) every %d turns", + k_info[lookup_kind(TV_RUNE1, gf)].name + k_name, + k_info[lookup_kind(TV_RUNE2, mod)].name + k_name, + mana, mana * 5); + return rspell[num]; + } + + if (o_ptr->tval == TV_EGG) + { + return "stop or resume the egg development"; + } + + if (o_ptr->tval == TV_INSTRUMENT) + { + if (!((o_ptr->name1 && a_info[o_ptr->name1].activate) || + (o_ptr->name2 && e_info[o_ptr->name2].activate) || + (o_ptr->name2b && e_info[o_ptr->name2b].activate))) + { + if (o_ptr->sval == SV_HORN) + { + return "aggravate monster every 100 turns"; + } + } + } + + if (process_hooks_ret(HOOK_ACTIVATE_DESC, "s", "(O)", o_ptr)) + return (process_hooks_return[0].str); + + return activation_aux(o_ptr, FALSE, 0); +} + +/* Grab the tval desc */ +bool_ grab_tval_desc(int tval) +{ + int tv = 0; + + while (tval_descs[tv].tval && (tval_descs[tv].tval != tval)) + { + tv++; + } + + if (!tval_descs[tv].tval) return FALSE; + + text_out_c(TERM_L_BLUE, tval_descs[tv].desc); + text_out("\n"); + + return TRUE; +} + +#define CHECK_FIRST(txt, first) \ +if ((first)) { (first) = FALSE; text_out((txt)); } else text_out(", "); + +/* + * Display the damage done with a multiplier + */ +void output_dam(object_type *o_ptr, int mult, int mult2, cptr against, cptr against2, bool_ *first) +{ + int dam; + + dam = (o_ptr->dd + (o_ptr->dd * o_ptr->ds)) * 5 * mult; + dam += (o_ptr->to_d + p_ptr->to_d + p_ptr->to_d_melee) * 10; + dam *= p_ptr->num_blow; + CHECK_FIRST("", *first); + if (dam > 0) + { + if (dam % 10) + text_out_c(TERM_L_GREEN, format("%d.%d", dam / 10, dam % 10)); + else + text_out_c(TERM_L_GREEN, format("%d", dam / 10)); + } + else + text_out_c(TERM_L_RED, "0"); + text_out(format(" against %s", against)); + + if (mult2) + { + dam = (o_ptr->dd + (o_ptr->dd * o_ptr->ds)) * 5 * mult2; + dam += (o_ptr->to_d + p_ptr->to_d + p_ptr->to_d_melee) * 10; + dam *= p_ptr->num_blow; + CHECK_FIRST("", *first); + if (dam > 0) + { + if (dam % 10) + text_out_c(TERM_L_GREEN, format("%d.%d", dam / 10, dam % 10)); + else + text_out_c(TERM_L_GREEN, format("%d", dam / 10)); + } + else + text_out_c(TERM_L_RED, "0"); + text_out(format(" against %s", against2)); + } +} + +/* + * Outputs the damage we do/would do with the weapon + */ +void display_weapon_damage(object_type *o_ptr) +{ + object_type forge, *old_ptr = &forge; + u32b f1, f2, f3, f4, f5, esp; + bool_ first = TRUE; + bool_ full = o_ptr->ident & (IDENT_MENTAL); + + /* Extract the flags */ + object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); + + /* Ok now the hackish stuff, we replace the current weapon with this one */ + object_copy(old_ptr, &p_ptr->inventory[INVEN_WIELD]); + object_copy(&p_ptr->inventory[INVEN_WIELD], o_ptr); + calc_bonuses(TRUE); + + text_out("\nUsing it you would have "); + text_out_c(TERM_L_GREEN, format("%d ", p_ptr->num_blow)); + text_out(format("blow%s and do an average damage per turn of ", (p_ptr->num_blow) ? "s" : "")); + + if (full && (f1 & TR1_SLAY_ANIMAL)) output_dam(o_ptr, 2, 0, "animals", NULL, &first); + if (full && (f1 & TR1_SLAY_EVIL)) output_dam(o_ptr, 2, 0, "evil creatures", NULL, &first); + if (full && (f1 & TR1_SLAY_ORC)) output_dam(o_ptr, 3, 0, "orcs", NULL, &first); + if (full && (f1 & TR1_SLAY_TROLL)) output_dam(o_ptr, 3, 0, "trolls", NULL, &first); + if (full && (f1 & TR1_SLAY_GIANT)) output_dam(o_ptr, 3, 0, "giants", NULL, &first); + if (full && (f1 & TR1_KILL_DRAGON)) output_dam(o_ptr, 5, 0, "dragons", NULL, &first); + else if (full && (f1 & TR1_SLAY_DRAGON)) output_dam(o_ptr, 3, 0, "dragons", NULL, &first); + if (full && (f5 & TR5_KILL_UNDEAD)) output_dam(o_ptr, 5, 0, "undead", NULL, &first); + else if (full && (f1 & TR1_SLAY_UNDEAD)) output_dam(o_ptr, 3, 0, "undead", NULL, &first); + if (full && (f5 & TR5_KILL_DEMON)) output_dam(o_ptr, 5, 0, "demons", NULL, &first); + else if (full && (f1 & TR1_SLAY_DEMON)) output_dam(o_ptr, 3, 0, "demons", NULL, &first); + + if (full && (f1 & TR1_BRAND_FIRE)) output_dam(o_ptr, 3, 6, "non fire resistant creatures", "fire susceptible creatures", &first); + if (full && (f1 & TR1_BRAND_COLD)) output_dam(o_ptr, 3, 6, "non cold resistant creatures", "cold susceptible creatures", &first); + if (full && (f1 & TR1_BRAND_ELEC)) output_dam(o_ptr, 3, 6, "non lightning resistant creatures", "lightning susceptible creatures", &first); + if (full && (f1 & TR1_BRAND_ACID)) output_dam(o_ptr, 3, 6, "non acid resistant creatures", "acid susceptible creatures", &first); + if (full && (f1 & TR1_BRAND_POIS)) output_dam(o_ptr, 3, 6, "non poison resistant creatures", "poison susceptible creatures", &first); + + output_dam(o_ptr, 1, 0, (first) ? "all monsters" : "other monsters", NULL, &first); + + text_out("."); + + /* get our weapon back */ + object_copy(&p_ptr->inventory[INVEN_WIELD], old_ptr); + calc_bonuses(TRUE); +} + +/* + * Display the ammo damage done with a multiplier + */ +void output_ammo_dam(object_type *o_ptr, int mult, int mult2, cptr against, cptr against2, bool_ *first) +{ + int dam; + object_type *b_ptr = &p_ptr->inventory[INVEN_BOW]; + int is_boomerang = (o_ptr->tval == TV_BOOMERANG); + int tmul = get_shooter_mult(b_ptr) + p_ptr->xtra_might; + if (is_boomerang) tmul = p_ptr->throw_mult; + + dam = (o_ptr->dd + (o_ptr->dd * o_ptr->ds)) * 5; + dam += o_ptr->to_d * 10; + if (!is_boomerang) dam += b_ptr->to_d * 10; + dam *= tmul; + if (!is_boomerang) dam += (p_ptr->to_d_ranged) * 10; + dam *= mult; + CHECK_FIRST("", *first); + if (dam > 0) + { + if (dam % 10) + text_out_c(TERM_L_GREEN, format("%d.%d", dam / 10, dam % 10)); + else + text_out_c(TERM_L_GREEN, format("%d", dam / 10)); + } + else + text_out_c(TERM_L_RED, "0"); + text_out(format(" against %s", against)); + + if (mult2) + { + dam = (o_ptr->dd + (o_ptr->dd * o_ptr->ds)) * 5; + dam += o_ptr->to_d * 10; + if (!is_boomerang) dam += b_ptr->to_d * 10; + dam *= tmul; + if (!is_boomerang) dam += (p_ptr->to_d_ranged) * 10; + dam *= mult2; + CHECK_FIRST("", *first); + if (dam > 0) + { + if (dam % 10) + text_out_c(TERM_L_GREEN, format("%d.%d", dam / 10, dam % 10)); + else + text_out_c(TERM_L_GREEN, format("%d", dam / 10)); + } + else + text_out_c(TERM_L_RED, "0"); + text_out(format(" against %s", against2)); + } +} + +/* + * Outputs the damage we do/would do with the current bow and this ammo + */ +void display_ammo_damage(object_type *o_ptr) +{ + u32b f1, f2, f3, f4, f5, esp; + bool_ first = TRUE; + int i; + bool_ full = o_ptr->ident & (IDENT_MENTAL); + + /* Extract the flags */ + object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); + + if (o_ptr->tval == TV_BOOMERANG) + text_out("\nUsing it you would do an average damage per throw of "); + else + text_out("\nUsing it with your current shooter you would do an average damage per shot of "); + if (full && (f1 & TR1_SLAY_ANIMAL)) output_ammo_dam(o_ptr, 2, 0, "animals", NULL, &first); + if (full && (f1 & TR1_SLAY_EVIL)) output_ammo_dam(o_ptr, 2, 0, "evil creatures", NULL, &first); + if (full && (f1 & TR1_SLAY_ORC)) output_ammo_dam(o_ptr, 3, 0, "orcs", NULL, &first); + if (full && (f1 & TR1_SLAY_TROLL)) output_ammo_dam(o_ptr, 3, 0, "trolls", NULL, &first); + if (full && (f1 & TR1_SLAY_GIANT)) output_ammo_dam(o_ptr, 3, 0, "giants", NULL, &first); + if (full && (f1 & TR1_KILL_DRAGON)) output_ammo_dam(o_ptr, 5, 0, "dragons", NULL, &first); + else if (full && (f1 & TR1_SLAY_DRAGON)) output_ammo_dam(o_ptr, 3, 0, "dragons", NULL, &first); + if (full && (f5 & TR5_KILL_UNDEAD)) output_ammo_dam(o_ptr, 5, 0, "undeads", NULL, &first); + else if (full && (f1 & TR1_SLAY_UNDEAD)) output_ammo_dam(o_ptr, 3, 0, "undeads", NULL, &first); + if (full && (f5 & TR5_KILL_DEMON)) output_ammo_dam(o_ptr, 5, 0, "demons", NULL, &first); + else if (full && (f1 & TR1_SLAY_DEMON)) output_ammo_dam(o_ptr, 3, 0, "demons", NULL, &first); + + if (full && (f1 & TR1_BRAND_FIRE)) output_ammo_dam(o_ptr, 3, 6, "non fire resistant creatures", "fire susceptible creatures", &first); + if (full && (f1 & TR1_BRAND_COLD)) output_ammo_dam(o_ptr, 3, 6, "non cold resistant creatures", "cold susceptible creatures", &first); + if (full && (f1 & TR1_BRAND_ELEC)) output_ammo_dam(o_ptr, 3, 6, "non lightning resistant creatures", "lightning susceptible creatures", &first); + if (full && (f1 & TR1_BRAND_ACID)) output_ammo_dam(o_ptr, 3, 6, "non acid resistant creatures", "acid susceptible creatures", &first); + if (full && (f1 & TR1_BRAND_POIS)) output_ammo_dam(o_ptr, 3, 6, "non poison resistant creatures", "poison susceptible creatures", &first); + + output_ammo_dam(o_ptr, 1, 0, (first) ? "all monsters" : "other monsters", NULL, &first); + text_out(". "); + + if (o_ptr->pval2) + { + text_out("The explosion will be "); + i = 0; + while (gf_names[i].gf != -1) + { + if (gf_names[i].gf == o_ptr->pval2) + break; + i++; + } + text_out_c(TERM_L_GREEN, (gf_names[i].gf != -1) ? gf_names[i].name : "something weird"); + text_out("."); + } +} + +/* + * Output spell description + */ +static void print_device_desc_callback(void *data, cptr text) +{ + text_out("\n"); + text_out(text); +} + +/* + * Describe a magic stick powers + */ +void describe_device(object_type *o_ptr) +{ + char buf[128]; + + /* Wands/... of shcool spell */ + if (((o_ptr->tval == TV_WAND) || (o_ptr->tval == TV_STAFF)) && object_known_p(o_ptr)) + { + /* Enter device mode */ + set_stick_mode(o_ptr); + + text_out("\nSpell description:\n"); + spell_type_description_foreach(spell_at(o_ptr->pval2), + print_device_desc_callback, + NULL); + + text_out("\nSpell level: "); + sprintf(buf, FMTs32b, get_level(o_ptr->pval2, 50, 0)); + text_out_c(TERM_L_BLUE, buf); + + text_out("\nMinimum Magic Device level to increase spell level: "); + text_out_c(TERM_L_BLUE, format("%d", spell_type_skill_level(spell_at(o_ptr->pval2)))); + + text_out("\nSpell fail: "); + sprintf(buf, FMTs32b, spell_chance(o_ptr->pval2)); + text_out_c(TERM_GREEN, buf); + + text_out("\nSpell info: "); + text_out_c(TERM_YELLOW, spell_type_info(spell_at(o_ptr->pval2))); + + /* Leave device mode */ + unset_stick_mode(); + + text_out("\n"); + } +} + + +/* + * Helper for object_out_desc + * + * Print the level something was found on + * + */ +static cptr object_out_desc_where_found(s16b level, s16b dungeon) +{ + static char str[80]; + + if (dungeon == DUNGEON_WILDERNESS) + /* Taking care of older objects */ + if (level == 0) + sprintf(str, "in the wilderness or in a town"); + else if (wf_info[level].terrain_idx == TERRAIN_TOWN) + sprintf(str, "in the town of %s", wf_info[level].name + wf_name); + else + sprintf(str, "in %s", wf_info[level].text + wf_text); + else + sprintf(str, "on level %d of %s", level, d_info[dungeon].name + d_name); + + return str; +} + +/* + * Describe an item + */ +bool_ object_out_desc(object_type *o_ptr, FILE *fff, bool_ trim_down, bool_ wait_for_it) +{ + u32b f1, f2, f3, f4, f5, esp; + + const char *txt; + + cptr vp[64]; + byte vc[64]; + int vn; + + bool_ first = TRUE; + + /* Extract the flags */ + if ((!(o_ptr->ident & (IDENT_MENTAL))) && (!fff)) + { + f1 = o_ptr->art_oflags1; + f2 = o_ptr->art_oflags2; + f3 = o_ptr->art_oflags3; + f4 = o_ptr->art_oflags4; + f5 = o_ptr->art_oflags5; + esp = o_ptr->art_oesp; + } + else + { + object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); + } + + if (fff) + { + /* Set up stuff for text_out */ + text_out_file = fff; + text_out_hook = text_out_to_file; + } + else + { + /* Save the screen */ + character_icky = TRUE; + Term_save(); + + /* Set up stuff for text_out */ + text_out_hook = text_out_to_screen; + text_out("\n"); + } + + /* No need to dump that */ + if (!fff) + { + if (!trim_down) grab_tval_desc(o_ptr->tval); + } + + if (object_known_p(o_ptr)) + { + if (o_ptr->k_idx && (!trim_down)) + { + object_kind *k_ptr = &k_info[o_ptr->k_idx]; + + text_out_c(TERM_ORANGE, k_text + k_ptr->text); + text_out("\n"); + } + + if (o_ptr->name1 && (!trim_down)) + { + artifact_type *a_ptr = &a_info[o_ptr->name1]; + + text_out_c(TERM_YELLOW, a_text + a_ptr->text); + text_out("\n"); + + if (a_ptr->set != -1) + { + set_type *set_ptr = &set_info[a_ptr->set]; + + text_out_c(TERM_GREEN, set_text + set_ptr->desc); + text_out("\n"); + } + } + + if ((f4 & TR4_LEVELS) && (!trim_down)) + { + int j = 0; + + if (count_bits(o_ptr->pval3) == 0) text_out("It is sentient"); + else if (count_bits(o_ptr->pval3) > 1) text_out("It is sentient and can have access to the realms of "); + else text_out("It is sentient and can have access to the realm of "); + + first = TRUE; + txt = ""; + for (j = 0; j < MAX_FLAG_GROUP; j++) + { + if (BIT(j) & o_ptr->pval3) + { + CHECK_FIRST(txt, first); + text_out_c(flags_groups[j].color, flags_groups[j].name); + } + } + + text_out(". "); + } + + if (f4 & TR4_ULTIMATE) + { + if ((wield_slot(o_ptr) == INVEN_WIELD) || + (wield_slot(o_ptr) == INVEN_BOW)) + text_out_c(TERM_VIOLET, "It is part of the trinity of the ultimate weapons. "); + else + text_out_c(TERM_VIOLET, "It is the ultimate armor. "); + } + + if (f4 & TR4_COULD2H) text_out("It can be wielded two-handed. "); + if (f4 & TR4_MUST2H) text_out("It must be wielded two-handed. "); + + /* Mega-Hack -- describe activation */ + if (f3 & (TR3_ACTIVATE)) + { + text_out("It can be activated for "); + if (is_ego_p(o_ptr, EGO_MSTAFF_SPELL)) + { + text_out(item_activation(o_ptr, 0)); + text_out(" and "); + text_out(item_activation(o_ptr, 1)); + } + else + text_out(item_activation(o_ptr, 0)); + + /* Mega-hack -- get rid of useless line for e.g. randarts */ + if (f5 & (TR5_ACTIVATE_NO_WIELD)) + text_out(". "); + else + text_out(" if it is being worn. "); + } + /* Granted power */ + if (object_power(o_ptr) != -1) + { + text_out("It grants you the power of "); + text_out(powers_type[object_power(o_ptr)].name); + text_out(" if it is being worn. "); + } + + /* Hack -- describe lites */ + if ((o_ptr->tval == TV_LITE) || (f3 & TR3_LITE1) || (f4 & TR4_LITE2) || (f4 & TR4_LITE3)) + { + int radius = 0; + + if (f3 & TR3_LITE1) radius++; + if (f4 & TR4_LITE2) radius += 2; + if (f4 & TR4_LITE3) radius += 3; + if (radius > 5) radius = 5; + + if (f4 & TR4_FUEL_LITE) + { + text_out(format("It provides light (radius %d) when fueled. ", radius)); + } + else + { + text_out(format("It provides light (radius %d) forever. ", radius)); + } + } + + /* Mega Hack^3 -- describe the Anchor of Space-time */ + if (o_ptr->name1 == ART_ANCHOR) + { + text_out("It prevents the space-time continuum from being disrupted. "); + } + + if ((f4 & (TR4_ANTIMAGIC_50)) || (f4 & (TR4_ANTIMAGIC_30)) || (f4 & (TR4_ANTIMAGIC_20)) || (f4 & (TR4_ANTIMAGIC_10))) + { + text_out("It generates an antimagic field. "); + } + + if (f5 & TR5_SPELL_CONTAIN) + { + if (o_ptr->pval2 == -1) + text_out("It can be used to store a spell. "); + else + text_out("It has a spell stored inside. "); + } + + /* Pick up stat bonuses */ + vn = 0; + if (f1 & (TR1_STR)) vp[vn++] = "strength"; + if (f1 & (TR1_INT)) vp[vn++] = "intelligence"; + if (f1 & (TR1_WIS)) vp[vn++] = "wisdom"; + if (f1 & (TR1_DEX)) vp[vn++] = "dexterity"; + if (f1 & (TR1_CON)) vp[vn++] = "constitution"; + if (f1 & (TR1_CHR)) vp[vn++] = "charisma"; + if ((o_ptr->tval != TV_TRAPKIT) && (f1 & (TR1_STEALTH))) vp[vn++] = "stealth"; + if (f1 & (TR1_SEARCH)) vp[vn++] = "searching"; + if (f1 & (TR1_INFRA)) vp[vn++] = "infravision"; + if (f1 & (TR1_TUNNEL)) vp[vn++] = "ability to tunnel"; + if (f1 & (TR1_SPEED)) vp[vn++] = "speed"; + if (f1 & (TR1_BLOWS)) vp[vn++] = "attack speed"; + if (f5 & (TR5_CRIT)) vp[vn++] = "ability to score critical hits"; + if (f5 & (TR5_LUCK)) vp[vn++] = "luck"; + if (f1 & (TR1_SPELL)) vp[vn++] = "spell power"; + + /* Describe */ + if (vn) + { + int i; + + /* Intro */ + text_out("It "); + + /* What it does */ + if (o_ptr->pval > 0) text_out("increases "); + else text_out("decreases "); + + /* List */ + for (i = 0; i < vn; i++) + { + /* Connectives */ + if (i == 0) text_out("your "); + else if (i < (vn - 1)) text_out(", "); + else text_out(" and "); + + /* Dump the stat */ + text_out(vp[i]); + } + + text_out(" by "); + if (o_ptr->pval > 0) + text_out_c(TERM_L_GREEN, format("%i", o_ptr->pval)); + else + text_out_c(TERM_L_RED, format("%i", -o_ptr->pval)); + text_out(". "); + } + + + vn = 0; + if (f1 & (TR1_MANA)) vp[vn++] = "mana capacity"; + if (f2 & (TR2_LIFE)) vp[vn++] = "hit points"; + + /* Describe with percentuals */ + if (vn) + { + int percent; + + /* What it does */ + if (o_ptr->pval > 0) + text_out("It increases"); + else + text_out("It decreases"); + + text_out(" your "); + text_out(vp[0]); + if (vn == 2) + { + text_out(" and "); + text_out(vp[1]); + } + + text_out(" by "); + percent = 100 * o_ptr->pval / 5; + + + if (o_ptr->pval > 0) + text_out_c(TERM_L_GREEN, format("%i%%", percent)); + else + text_out_c(TERM_L_RED, format("%i%%", -percent)); + text_out(". "); + } + + if ((o_ptr->tval == TV_TRAPKIT) && (f1 & (TR1_STEALTH))) + { + text_out("It is well-hidden. "); + } + + vn = 0; + if (f1 & (TR1_BRAND_ACID)) + { + vc[vn] = TERM_GREEN; + vp[vn++] = "acid"; + } + if (f1 & (TR1_BRAND_ELEC)) + { + vc[vn] = TERM_L_BLUE; + vp[vn++] = "electricity"; + } + if (f1 & (TR1_BRAND_FIRE)) + { + vc[vn] = TERM_RED; + vp[vn++] = "fire"; + } + if (f1 & (TR1_BRAND_COLD)) + { + vc[vn] = TERM_L_WHITE; + vp[vn++] = "frost"; + } + /* Describe */ + if (vn) + { + int i; + + /* Intro */ + text_out("It does extra damage "); + + /* List */ + for (i = 0; i < vn; i++) + { + /* Connectives */ + if (i == 0) text_out("from "); + else if (i < (vn - 1)) text_out(", "); + else text_out(" and "); + + /* Dump the stat */ + text_out_c(vc[i], vp[i]); + } + text_out(". "); + } + + + if (f1 & (TR1_BRAND_POIS)) + { + text_out("It "); + text_out_c(TERM_L_GREEN, "poisons your foes"); + text_out(". "); + } + + if (f1 & (TR1_CHAOTIC)) + { + text_out("It produces chaotic effects. "); + } + + if (f1 & (TR1_VAMPIRIC)) + { + text_out("It drains life from your foes. "); + } + + if (f1 & (TR1_IMPACT)) + { + text_out("It can cause earthquakes. "); + } + + if (f1 & (TR1_VORPAL)) + { + text_out("It is very sharp and can cut your foes. "); + } + + if (f5 & (TR5_WOUNDING)) + { + text_out("It is very sharp and can make your foes bleed. "); + } + + if (f1 & (TR1_KILL_DRAGON)) + { + text_out("It is a great bane of dragons. "); + } + else if (f1 & (TR1_SLAY_DRAGON)) + { + text_out("It is especially deadly against dragons. "); + } + if (f1 & (TR1_SLAY_ORC)) + { + text_out("It is especially deadly against orcs. "); + } + if (f1 & (TR1_SLAY_TROLL)) + { + text_out("It is especially deadly against trolls. "); + } + if (f1 & (TR1_SLAY_GIANT)) + { + text_out("It is especially deadly against giants. "); + } + if (f5 & (TR5_KILL_DEMON)) + { + text_out("It is a great bane of demons. "); + } + else if (f1 & (TR1_SLAY_DEMON)) + { + text_out("It strikes at demons with holy wrath. "); + } + if (f5 & (TR5_KILL_UNDEAD)) + { + text_out("It is a great bane of undead. "); + } + else if (f1 & (TR1_SLAY_UNDEAD)) + { + text_out("It strikes at undead with holy wrath. "); + } + if (f1 & (TR1_SLAY_EVIL)) + { + text_out("It fights against evil with holy fury. "); + } + if (f1 & (TR1_SLAY_ANIMAL)) + { + text_out("It is especially deadly against natural creatures. "); + } + + if (f2 & (TR2_INVIS)) + { + text_out("It makes you invisible. "); + } + + if (o_ptr->tval != TV_TRAPKIT) + { + vn = 0; + if (f2 & (TR2_SUST_STR)) + { + vp[vn++] = "strength"; + } + if (f2 & (TR2_SUST_INT)) + { + vp[vn++] = "intelligence"; + } + if (f2 & (TR2_SUST_WIS)) + { + vp[vn++] = "wisdom"; + } + if (f2 & (TR2_SUST_DEX)) + { + vp[vn++] = "dexterity"; + } + if (f2 & (TR2_SUST_CON)) + { + vp[vn++] = "constitution"; + } + if (f2 & (TR2_SUST_CHR)) + { + vp[vn++] = "charisma"; + } + /* Describe */ + if (vn) + { + int i; + + /* Intro */ + text_out("It sustains "); + + /* List */ + for (i = 0; i < vn; i++) + { + /* Connectives */ + if (i == 0) text_out("your "); + else if (i < (vn - 1)) text_out(", "); + else text_out(" and "); + + /* Dump the stat */ + text_out(vp[i]); + } + text_out(". "); + } + + vn = 0; + if (f2 & (TR2_IM_ACID)) + { + vc[vn] = TERM_GREEN; + vp[vn++] = "acid"; + } + if (f2 & (TR2_IM_ELEC)) + { + vc[vn] = TERM_L_BLUE; + vp[vn++] = "electricity"; + } + if (f2 & (TR2_IM_FIRE)) + { + vc[vn] = TERM_RED; + vp[vn++] = "fire"; + } + if (f2 & (TR2_IM_COLD)) + { + vc[vn] = TERM_L_WHITE; + vp[vn++] = "cold"; + } + if (f4 & (TR4_IM_NETHER)) + { + vc[vn] = TERM_L_GREEN; + vp[vn++] = "nether"; + } + /* Describe */ + if (vn) + { + int i; + + /* Intro */ + text_out("It provides immunity "); + + /* List */ + for (i = 0; i < vn; i++) + { + /* Connectives */ + if (i == 0) text_out("to "); + else if (i < (vn - 1)) text_out(", "); + else text_out(" and "); + + /* Dump the stat */ + text_out_c(vc[i], vp[i]); + } + text_out(". "); + } + } + else + { + if (f2 & (TRAP2_AUTOMATIC_5)) + { + text_out("It can rearm itself. "); + } + if (f2 & (TRAP2_AUTOMATIC_99)) + { + text_out("It rearms itself. "); + } + if (f2 & (TRAP2_KILL_GHOST)) + { + text_out("It is effective against Ghosts. "); + } + if (f2 & (TRAP2_TELEPORT_TO)) + { + text_out("It can teleport monsters to you. "); + } + if (f2 & (TRAP2_ONLY_DRAGON)) + { + text_out("It can only be set off by dragons. "); + } + if (f2 & (TRAP2_ONLY_DEMON)) + { + text_out("It can only be set off by demons. "); + } + if (f2 & (TRAP2_ONLY_UNDEAD)) + { + text_out("It can only be set off by undead. "); + } + if (f2 & (TRAP2_ONLY_ANIMAL)) + { + text_out("It can only be set off by animals. "); + } + if (f2 & (TRAP2_ONLY_EVIL)) + { + text_out("It can only be set off by evil creatures. "); + } + } + + if (f2 & (TR2_FREE_ACT)) + { + text_out("It provides immunity to paralysis. "); + } + if (f2 & (TR2_RES_FEAR)) + { + text_out("It makes you completely fearless. "); + } + + vn = 0; + if (f2 & (TR2_HOLD_LIFE)) + { + vp[vn++] = "life draining"; + } + if ((f2 & (TR2_RES_ACID)) && !(f2 & (TR2_IM_ACID))) + { + vp[vn++] = "acid"; + } + if ((f2 & (TR2_RES_ELEC)) && !(f2 & (TR2_IM_ELEC))) + { + vp[vn++] = "electricity"; + } + if ((f2 & (TR2_RES_FIRE)) && !(f2 & (TR2_IM_FIRE))) + { + vp[vn++] = "fire"; + } + if ((f2 & (TR2_RES_COLD)) && !(f2 & (TR2_IM_COLD))) + { + vp[vn++] = "cold"; + } + if (f2 & (TR2_RES_POIS)) + { + vp[vn++] = "poison"; + } + if (f2 & (TR2_RES_LITE)) + { + vp[vn++] = "light"; + } + if (f2 & (TR2_RES_DARK)) + { + vp[vn++] = "dark"; + } + if (f2 & (TR2_RES_BLIND)) + { + vp[vn++] = "blindness"; + } + if (f2 & (TR2_RES_CONF)) + { + vp[vn++] = "confusion"; + } + if (f2 & (TR2_RES_SOUND)) + { + vp[vn++] = "sound"; + } + if (f2 & (TR2_RES_SHARDS)) + { + vp[vn++] = "shards"; + } + if ((f2 & (TR2_RES_NETHER)) && !(f4 & (TR4_IM_NETHER))) + { + vp[vn++] = "nether"; + } + if (f2 & (TR2_RES_NEXUS)) + { + vp[vn++] = "nexus"; + } + if (f2 & (TR2_RES_CHAOS)) + { + vp[vn++] = "chaos"; + } + if (f2 & (TR2_RES_DISEN)) + { + vp[vn++] = "disenchantment"; + } + /* Describe */ + if (vn) + { + int i; + + /* Intro */ + text_out("It provides resistance "); + + /* List */ + for (i = 0; i < vn; i++) + { + /* Connectives */ + if (i == 0) text_out("to "); + else if (i < (vn - 1)) text_out(", "); + else text_out(" and "); + + /* Dump the stat */ + text_out(vp[i]); + } + text_out(". "); + } + + if (f2 & (TR2_SENS_FIRE)) + { + text_out("It renders you especially vulnerable to fire. "); + } + if (f3 & (TR3_WRAITH)) + { + text_out("It renders you incorporeal. "); + } + if (f5 & (TR5_WATER_BREATH)) + { + text_out("It allows you to breathe underwater. "); + } + if (f5 & (TR5_MAGIC_BREATH)) + { + text_out("It allows you to breathe without air. "); + } + if (f3 & (TR3_FEATHER)) + { + text_out("It allows you to levitate. "); + } + if (f4 & (TR4_FLY)) + { + text_out("It allows you to fly. "); + } + if (f4 & (TR4_CLIMB)) + { + text_out("It allows you to climb mountains. "); + } + if (f5 & (TR5_IMMOVABLE)) + { + text_out("It renders you immovable. "); + } + if (f3 & (TR3_SEE_INVIS)) + { + text_out("It allows you to see invisible monsters. "); + } + if (esp) + { + if (esp & ESP_ALL) text_out("It gives telepathic powers. "); + else + { + vn = 0; + if (esp & ESP_ORC) vp[vn++] = "orcs"; + if (esp & ESP_TROLL) vp[vn++] = "trolls"; + if (esp & ESP_DRAGON) vp[vn++] = "dragons"; + if (esp & ESP_SPIDER) vp[vn++] = "spiders"; + if (esp & ESP_GIANT) vp[vn++] = "giants"; + if (esp & ESP_DEMON) vp[vn++] = "demons"; + if (esp & ESP_UNDEAD) vp[vn++] = "undead"; + if (esp & ESP_EVIL) vp[vn++] = "evil beings"; + if (esp & ESP_ANIMAL) vp[vn++] = "animals"; + if (esp & ESP_THUNDERLORD) vp[vn++] = "thunderlords"; + if (esp & ESP_GOOD) vp[vn++] = "good beings"; + if (esp & ESP_NONLIVING) vp[vn++] = "non-living things"; + if (esp & ESP_UNIQUE) vp[vn++] = "unique beings"; + /* Describe */ + if (vn) + { + int i; + + /* Intro */ + text_out("It allows you to sense the presence "); + + /* List */ + for (i = 0; i < vn; i++) + { + /* Connectives */ + if (i == 0) text_out("of "); + else if (i < (vn - 1)) text_out(", "); + else text_out(" and "); + + /* Dump the stat */ + text_out(vp[i]); + } + text_out(". "); + } + } + } + + if (f3 & (TR3_SLOW_DIGEST)) + { + text_out("It slows your metabolism. "); + } + if (f3 & (TR3_REGEN)) + { + text_out("It speeds your regenerative powers. "); + } + if (f2 & (TR2_REFLECT)) + { + text_out("It reflects bolts and arrows. "); + } + if (f3 & (TR3_SH_FIRE)) + { + text_out("It produces a fiery sheath. "); + } + if (f3 & (TR3_SH_ELEC)) + { + text_out("It produces an electric sheath. "); + } + if (f3 & (TR3_NO_MAGIC)) + { + text_out("It produces an anti-magic shell. "); + } + if (f3 & (TR3_NO_TELE)) + { + text_out("It prevents teleportation. "); + } + if (f3 & (TR3_XTRA_MIGHT)) + { + text_out("It fires missiles with extra might. "); + } + if (f3 & (TR3_XTRA_SHOTS)) + { + text_out("It fires missiles excessively fast. "); + } + + vn = 0; + if (f5 & (TR5_DRAIN_MANA)) + { + vc[vn] = TERM_BLUE; + vp[vn++] = "mana"; + } + if (f5 & (TR5_DRAIN_HP)) + { + vc[vn] = TERM_RED; + vp[vn++] = "life"; + } + if (f3 & (TR3_DRAIN_EXP)) + { + vc[vn] = TERM_L_DARK; + vp[vn++] = "experience"; + } + /* Describe */ + if (vn) + { + int i; + + /* Intro */ + text_out("It "); + + /* List */ + for (i = 0; i < vn; i++) + { + /* Connectives */ + if (i == 0) text_out("drains "); + else if (i < (vn - 1)) text_out(", "); + else text_out(" and "); + + /* Dump the stat */ + text_out_c(vc[i], vp[i]); + } + text_out(". "); + } + + if (f3 & (TR3_BLESSED)) + { + text_out("It has been blessed by the gods. "); + } + if (f4 & (TR4_AUTO_ID)) + { + text_out("It identifies all items for you. "); + } + + if (f3 & (TR3_TELEPORT)) + { + text_out("It induces random teleportation. "); + } + if (f3 & (TR3_AGGRAVATE)) + { + text_out("It aggravates nearby creatures. "); + } + if (f4 & (TR4_NEVER_BLOW)) + { + text_out("It can't attack. "); + } + if (f4 & (TR4_BLACK_BREATH)) + { + text_out("It fills you with the Black Breath. "); + } + if (cursed_p(o_ptr)) + { + if (f3 & (TR3_PERMA_CURSE)) + { + text_out("It is permanently cursed. "); + } + else if (f3 & (TR3_HEAVY_CURSE)) + { + text_out("It is heavily cursed. "); + } + else + { + text_out("It is cursed. "); + } + } + if (f3 & (TR3_TY_CURSE)) + { + text_out("It carries an ancient foul curse. "); + } + + if (f4 & (TR4_DG_CURSE)) + { + text_out("It carries an ancient Morgothian curse. "); + } + if (f4 & (TR4_CLONE)) + { + text_out("It can clone monsters. "); + } + if (f4 & (TR4_CURSE_NO_DROP)) + { + text_out("It cannot be dropped while cursed. "); + } + if (f3 & (TR3_AUTO_CURSE)) + { + text_out("It can re-curse itself. "); + } + + if (f4 & (TR4_CAPACITY)) + { + text_out("It can hold more mana. "); + } + if (f4 & (TR4_CHEAPNESS)) + { + text_out("It can cast spells for a lesser mana cost. "); + } + if (f4 & (TR4_FAST_CAST)) + { + text_out("It can cast spells faster. "); + } + if (f4 & (TR4_CHARGING)) + { + text_out("It regenerates its mana faster. "); + } + + if (f5 & (TR5_RES_MORGUL)) + { + text_out("It can resist being shattered by morgul beings. "); + } + if ((f3 & (TR3_IGNORE_ACID)) && (f3 & (TR3_IGNORE_FIRE)) && (f3 & (TR3_IGNORE_COLD)) && (f3 & (TR3_IGNORE_ELEC))) + { + text_out("It cannot be harmed by acid, cold, lightning or fire. "); + } + else + { + if (f3 & (TR3_IGNORE_ACID)) + { + text_out("It cannot be harmed by acid. "); + } + if (f3 & (TR3_IGNORE_ELEC)) + { + text_out("It cannot be harmed by electricity. "); + } + if (f3 & (TR3_IGNORE_FIRE)) + { + text_out("It cannot be harmed by fire. "); + } + if (f3 & (TR3_IGNORE_COLD)) + { + text_out("It cannot be harmed by cold. "); + } + } + } + + + if (!trim_down && !fff) + { + describe_device(o_ptr); + + if (object_known_p(o_ptr)) + { + /* Damage display for weapons */ + if (wield_slot(o_ptr) == INVEN_WIELD) + display_weapon_damage(o_ptr); + + /* Breakage/Damage display for boomerangs */ + if (o_ptr->tval == TV_BOOMERANG) + { + if (artifact_p(o_ptr)) + text_out("\nIt can never be broken."); + else + text_out("\nIt has 1% chance to break upon hit."); + display_ammo_damage(o_ptr); + } + + /* Breakage/Damage display for ammo */ + if (wield_slot(o_ptr) == INVEN_AMMO) + { + if (artifact_p(o_ptr)) + { + text_out("\nIt can never be broken."); + } + /* Exclude exploding arrows */ + else if (o_ptr->pval2 == 0) + { + text_out("\nIt has "); + text_out_c(TERM_L_RED, format("%d", breakage_chance(o_ptr))); + text_out("% chance to break upon hit."); + } + display_ammo_damage(o_ptr); + } + + /* Monster recall for totems and corpses */ + if (o_ptr->tval == TV_TOTEM) + { + monster_description_out(o_ptr->pval, 0); + } + if (o_ptr->tval == TV_CORPSE) + { + monster_description_out(o_ptr->pval2, 0); + } + } + + if (!object_known_p(o_ptr)) + text_out("\nYou might need to identify the item to know some more about it..."); + else if (!(o_ptr->ident & (IDENT_MENTAL))) + text_out("\nYou might need to *identify* the item to know more about it..."); + } + + /* Copying how others seem to do it. -- neil */ + if (o_ptr->tval == TV_RING || o_ptr->tval == TV_AMULET || + !trim_down || (ego_item_p(o_ptr)) || (artifact_p(o_ptr))) + { + /* Where did we found it ? */ + if (o_ptr->found == OBJ_FOUND_MONSTER) + { + char m_name[80]; + + monster_race_desc(m_name, o_ptr->found_aux1, o_ptr->found_aux2); + text_out(format("\nYou found it in the remains of %s %s.", + m_name, object_out_desc_where_found(o_ptr->found_aux4, o_ptr->found_aux3))); + } + else if (o_ptr->found == OBJ_FOUND_FLOOR) + { + text_out(format("\nYou found it lying on the ground %s.", + object_out_desc_where_found(o_ptr->found_aux2, o_ptr->found_aux1))); + } + else if (o_ptr->found == OBJ_FOUND_VAULT) + { + text_out(format("\nYou found it lying in a vault %s.", + object_out_desc_where_found(o_ptr->found_aux2, o_ptr->found_aux1))); + } + else if (o_ptr->found == OBJ_FOUND_SPECIAL) + { + text_out("\nYou found it lying on the floor of a special level."); + } + else if (o_ptr->found == OBJ_FOUND_RUBBLE) + { + text_out("\nYou found it while digging a rubble."); + } + else if (o_ptr->found == OBJ_FOUND_REWARD) + { + text_out("\nIt was given to you as a reward."); + } + else if (o_ptr->found == OBJ_FOUND_STORE) + { + text_out(format("\nYou bought it from the %s.", + st_info[o_ptr->found_aux1].name + st_name)); + } + else if (o_ptr->found == OBJ_FOUND_STOLEN) + { + text_out(format("\nYou stole it from the %s.", + st_info[o_ptr->found_aux1].name + st_name)); + } + else if (o_ptr->found == OBJ_FOUND_SELFMADE) + { + text_out("\nYou made it yourself."); + } + /* useful for debugging + else + { + text_out("\nYou ordered it from a catalog in the Town."); + }*/ + } + + if (fff) + { + /* Flush the line position. */ + text_out("\n"); + text_out_file = NULL; + } + else + { + if (wait_for_it) + { + /* Wait for it */ + inkey(); + + /* Restore the screen */ + Term_load(); + } + character_icky = FALSE; + + } + + /* Reset stuff for text_out */ + text_out_hook = text_out_to_screen; + + /* Gave knowledge */ + return (TRUE); +} + + + +/* + * Convert an inventory index into a one character label + * Note that the label does NOT distinguish inven/equip. + */ +char index_to_label(int i) +{ + /* Indexes for "inven" are easy */ + if (i < INVEN_WIELD) return (I2A(i)); + + /* Indexes for "equip" are offset */ + return (I2A(i - INVEN_WIELD)); +} + + +/* + * Convert a label into the index of an item in the "inven" + * Return "-1" if the label does not indicate a real item + */ +s16b label_to_inven(int c) +{ + int i; + + /* Convert */ + i = (islower(c) ? A2I(c) : -1); + + /* Verify the index */ + if ((i < 0) || (i > INVEN_PACK)) return ( -1); + + /* Empty slots can never be chosen */ + if (!p_ptr->inventory[i].k_idx) return ( -1); + + /* Return the index */ + return (i); +} + + +/* + * Convert a label into the index of a item in the "equip" + * Return "-1" if the label does not indicate a real item + */ +s16b label_to_equip(int c) +{ + int i; + + /* Convert */ + i = ((islower(c) || (c > 'z')) ? A2I(c) : -1) + INVEN_WIELD; + + /* Verify the index */ + if ((i < INVEN_WIELD) || (i >= INVEN_TOTAL)) return ( -1); + + /* Empty slots can never be chosen */ + if (!p_ptr->inventory[i].k_idx) return ( -1); + + /* Return the index */ + return (i); +} + +/* + * Returns the next free slot of the given "type", return the first + * if all are used + */ +int get_slot(int slot) +{ + int i = 0; + + /* If there are at least one body part corretsonding, the find the free one */ + if (p_ptr->body_parts[slot - INVEN_WIELD] == slot) + { + /* Find a free body part */ + while ((i < 6) && (slot + i < INVEN_TOTAL) && (p_ptr->body_parts[slot - INVEN_WIELD + i] == slot)) + { + if (p_ptr->body_parts[slot + i - INVEN_WIELD]) + { + /* Free ? return the slot */ + if (!p_ptr->inventory[slot + i].k_idx) return (slot + i); + } + else break; + + i++; + } + /* Found nothing ? return the first one */ + return slot; + } + /* No body parts ? return -1 */ + else return ( -1); +} + +/* + * Determine which equipment slot (if any) an item likes, ignoring the player's + * current body and stuff if ideal == TRUE + */ +s16b wield_slot_ideal(object_type *o_ptr, bool_ ideal) +{ + /* Try for a script first */ + if (process_hooks_ret(HOOK_WIELD_SLOT, "d", "(O,d)", o_ptr, ideal)) + return process_hooks_return[0].num; + + /* Theme has restrictions for winged races. */ + if (game_module_idx == MODULE_THEME) + { + cptr race_name = rp_ptr->title + rp_name; + + if (streq(race_name, "Dragon") || + streq(race_name, "Eagle")) + { + switch (o_ptr->tval) + { + case TV_CLOAK: + case TV_HARD_ARMOR: + case TV_DRAG_ARMOR: + return -1; + } + } + } + + /* Slot for equipment */ + switch (o_ptr->tval) + { + case TV_DIGGING: + case TV_TOOL: + { + return ideal ? INVEN_TOOL : get_slot(INVEN_TOOL); + } + + case TV_HAFTED: + case TV_POLEARM: + case TV_MSTAFF: + case TV_SWORD: + case TV_AXE: + { + return ideal ? INVEN_WIELD : get_slot(INVEN_WIELD); + } + + case TV_BOOMERANG: + case TV_BOW: + case TV_INSTRUMENT: + { + return ideal ? INVEN_BOW : get_slot(INVEN_BOW); + } + + case TV_RING: + { + return ideal ? INVEN_RING : get_slot(INVEN_RING); + } + + case TV_AMULET: + { + return ideal ? INVEN_NECK : get_slot(INVEN_NECK); + } + + case TV_LITE: + { + return ideal ? INVEN_LITE : get_slot(INVEN_LITE); + } + + case TV_DRAG_ARMOR: + case TV_HARD_ARMOR: + case TV_SOFT_ARMOR: + { + return ideal ? INVEN_BODY : get_slot(INVEN_BODY); + } + + case TV_CLOAK: + { + return ideal ? INVEN_OUTER : get_slot(INVEN_OUTER); + } + + case TV_SHIELD: + { + return ideal ? INVEN_ARM : get_slot(INVEN_ARM); + } + + case TV_CROWN: + case TV_HELM: + { + return ideal ? INVEN_HEAD : get_slot(INVEN_HEAD); + } + + case TV_GLOVES: + { + return ideal ? INVEN_HANDS : get_slot(INVEN_HANDS); + } + + case TV_BOOTS: + { + return ideal ? INVEN_FEET : get_slot(INVEN_FEET); + } + + case TV_HYPNOS: + { + return ideal ? INVEN_CARRY : get_slot(INVEN_CARRY); + } + + case TV_SHOT: + { + if (ideal) + { + return INVEN_AMMO; + } + else if (p_ptr->inventory[INVEN_AMMO].k_idx && + object_similar(o_ptr, &p_ptr->inventory[INVEN_AMMO]) && + p_ptr->inventory[INVEN_AMMO].number + o_ptr->number < MAX_STACK_SIZE) + { + return get_slot(INVEN_AMMO); + } + else if ((p_ptr->inventory[INVEN_BOW].k_idx) && (p_ptr->inventory[INVEN_BOW].tval == TV_BOW)) + { + if (p_ptr->inventory[INVEN_BOW].sval < 10) + return get_slot(INVEN_AMMO); + } + return -1; + } + + case TV_ARROW: + { + if (ideal) + { + return INVEN_AMMO; + } + else if (p_ptr->inventory[INVEN_AMMO].k_idx && + object_similar(o_ptr, &p_ptr->inventory[INVEN_AMMO]) && + p_ptr->inventory[INVEN_AMMO].number + o_ptr->number < MAX_STACK_SIZE) + { + return get_slot(INVEN_AMMO); + } + else if ((p_ptr->inventory[INVEN_BOW].k_idx) && (p_ptr->inventory[INVEN_BOW].tval == TV_BOW)) + { + if ((p_ptr->inventory[INVEN_BOW].sval >= 10) && (p_ptr->inventory[INVEN_BOW].sval < 20)) + return get_slot(INVEN_AMMO); + } + return -1; + } + + case TV_BOLT: + { + if (ideal) + { + return INVEN_AMMO; + } + else if (p_ptr->inventory[INVEN_AMMO].k_idx && + object_similar(o_ptr, &p_ptr->inventory[INVEN_AMMO]) && + p_ptr->inventory[INVEN_AMMO].number + o_ptr->number < MAX_STACK_SIZE) + { + return get_slot(INVEN_AMMO); + } + else if ((p_ptr->inventory[INVEN_BOW].k_idx) && (p_ptr->inventory[INVEN_BOW].tval == TV_BOW)) + { + if (p_ptr->inventory[INVEN_BOW].sval >= 20) + return get_slot(INVEN_AMMO); + } + return -1; + } + + case TV_DAEMON_BOOK: + { + int slot = -1; + + switch (o_ptr->sval) + { + case SV_DEMONBLADE : slot = INVEN_WIELD; break; + case SV_DEMONSHIELD: slot = INVEN_ARM; break; + case SV_DEMONHORN : slot = INVEN_HEAD; break; + } + + if ((slot >= 0) && (!ideal)) + { + slot = get_slot(slot); + } + + return slot; + } + } + + /* No slot available */ + return ( -1); +} + +/* + * Determine which equipment slot (if any) an item likes for the player's + * current body and stuff + */ +s16b wield_slot(object_type *o_ptr) +{ + return wield_slot_ideal(o_ptr, FALSE); +} + +/* + * Return a string mentioning how a given item is carried + */ +cptr mention_use(int i) +{ + cptr p; + + /* Examine the location */ + switch (i) + { + case INVEN_WIELD: + case INVEN_WIELD + 1: + case INVEN_WIELD + 2: + p = "Wielding"; + break; + case INVEN_BOW: + p = "Shooting"; + break; + case INVEN_RING: + case INVEN_RING + 1: + case INVEN_RING + 2: + case INVEN_RING + 3: + case INVEN_RING + 4: + case INVEN_RING + 5: + p = "On finger"; + break; + case INVEN_NECK: + case INVEN_NECK + 1: + p = "Around neck"; + break; + case INVEN_LITE: + p = "Light source"; + break; + case INVEN_BODY: + p = "On body"; + break; + case INVEN_OUTER: + p = "About body"; + break; + case INVEN_ARM: + case INVEN_ARM + 1: + case INVEN_ARM + 2: + p = "On arm"; + break; + case INVEN_HEAD: + case INVEN_HEAD + 1: + p = "On head"; + break; + case INVEN_HANDS: + case INVEN_HANDS + 1: + case INVEN_HANDS + 2: + p = "On hands"; + break; + case INVEN_FEET: + case INVEN_FEET + 1: + p = "On feet"; + break; + case INVEN_CARRY: + p = "Symbiote"; + break; + case INVEN_AMMO: + p = "Quiver"; + break; + case INVEN_TOOL: + p = "Using"; + break; + default: + p = "In pack"; + break; + } + + /* Hack -- Heavy weapons */ + if ((INVEN_WIELD <= i) && (i <= INVEN_WIELD + 2)) + { + object_type *o_ptr; + o_ptr = &p_ptr->inventory[i]; + if (adj_str_hold[p_ptr->stat_ind[A_STR]] < o_ptr->weight / 10) + { + p = "Just lifting"; + } + } + + /* Hack -- music instruments and heavy bow */ + if (i == INVEN_BOW) + { + object_type *o_ptr; + o_ptr = &p_ptr->inventory[i]; + if (o_ptr->tval == TV_INSTRUMENT) + { + p = "Playing"; + } + else if (adj_str_hold[p_ptr->stat_ind[A_STR]] < o_ptr->weight / 10) + { + p = "Just holding"; + } + } + + /* Return the result */ + return (p); +} + + +/* + * Return a string describing how a given item is being worn. + * Currently, only used for items in the equipment, not inventory. + */ +cptr describe_use(int i) +{ + cptr p; + + switch (i) + { + case INVEN_WIELD: + case INVEN_WIELD + 1: + case INVEN_WIELD + 2: + p = "attacking monsters with"; + break; + case INVEN_BOW: + p = "shooting missiles with"; + break; + case INVEN_RING: + case INVEN_RING + 1: + case INVEN_RING + 2: + case INVEN_RING + 3: + case INVEN_RING + 4: + case INVEN_RING + 5: + p = "wearing on your finger"; + break; + case INVEN_NECK: + case INVEN_NECK + 1: + p = "wearing around your neck"; + break; + case INVEN_LITE: + p = "using to light the way"; + break; + case INVEN_BODY: + p = "wearing on your body"; + break; + case INVEN_OUTER: + p = "wearing on your back"; + break; + case INVEN_ARM: + case INVEN_ARM + 1: + case INVEN_ARM + 2: + p = "wearing on your arm"; + break; + case INVEN_HEAD: + case INVEN_HEAD + 1: + p = "wearing on your head"; + break; + case INVEN_HANDS: + case INVEN_HANDS + 1: + case INVEN_HANDS + 2: + p = "wearing on your hands"; + break; + case INVEN_FEET: + case INVEN_FEET + 1: + p = "wearing on your feet"; + break; + case INVEN_CARRY: + p = "in symbiosis with"; + break; + case INVEN_AMMO: + p = "carrying in your quiver"; + break; + case INVEN_TOOL: + p = "using as a tool"; + break; + default: + p = "carrying in your pack"; + break; + } + + /* Hack -- Heavy weapons */ + if ((INVEN_WIELD <= i) && (i <= INVEN_WIELD + 2)) + { + object_type *o_ptr; + o_ptr = &p_ptr->inventory[i]; + if (adj_str_hold[p_ptr->stat_ind[A_STR]] < o_ptr->weight / 10) + { + p = "just lifting"; + } + } + + /* Hack -- Music instruments and heavy bow */ + if (i == INVEN_BOW) + { + object_type *o_ptr; + o_ptr = &p_ptr->inventory[i]; + if (o_ptr->tval == TV_INSTRUMENT) + { + p = "playing music with"; + } + else if (adj_str_hold[p_ptr->stat_ind[A_STR]] < o_ptr->weight / 10) + { + p = "just holding"; + } + } + + /* Return the result */ + return p; +} + +/* + * Check an item against the item tester info + */ +bool_ item_tester_okay(object_type *o_ptr) +{ + /* Hack -- allow listing empty slots */ + if (item_tester_full) return (TRUE); + + /* Require an item */ + if (!o_ptr->k_idx) return (FALSE); + + /* Hack -- ignore "gold" */ + if (o_ptr->tval == TV_GOLD) return (FALSE); + + /* Check the tval */ + if (item_tester_tval) + { + if (!(item_tester_tval == o_ptr->tval)) return (FALSE); + } + + /* Check the hook */ + if (item_tester_hook) + { + if (!(*item_tester_hook)(o_ptr)) return (FALSE); + } + + /* Assume okay */ + return (TRUE); +} + + + + +void show_equip_aux(bool_ mirror, bool_ everything); +void show_inven_aux(bool_ mirror, bool_ everything); + +/* + * Choice window "shadow" of the "show_inven()" function + */ +void display_inven(void) +{ + show_inven_aux(TRUE, inventory_no_move); +} + + + +/* + * Choice window "shadow" of the "show_equip()" function + */ +void display_equip(void) +{ + show_equip_aux(TRUE, inventory_no_move); +} + + + +/* Get the color of the letter idx */ +byte get_item_letter_color(object_type *o_ptr) +{ + byte color = TERM_WHITE; + + /* Must have knowlegde */ + if (!object_known_p(o_ptr)) return (TERM_SLATE); + + if (ego_item_p(o_ptr)) color = TERM_L_BLUE; + if (artifact_p(o_ptr)) color = TERM_YELLOW; + if (o_ptr->name1 && ( -1 != a_info[o_ptr->name1].set)) color = TERM_GREEN; + if (o_ptr->name1 && (a_info[o_ptr->name1].flags4 & TR4_ULTIMATE) && (o_ptr->ident & (IDENT_MENTAL))) color = TERM_VIOLET; + + return (color); +} + + +/* + * Display the inventory. + * + * Hack -- do not display "trailing" empty slots + */ +void show_inven_aux(bool_ mirror, bool_ everything) +{ + int i, j, k, l, z = 0; + int row, col, len, lim; + int wid, hgt; + object_type *o_ptr; + char o_name[80]; + char tmp_val[80]; + int out_index[23]; + byte out_color[23]; + char out_desc[23][80]; + + + /* Retrive current screen size */ + Term_get_size(&wid, &hgt); + + /* Starting row */ + row = mirror ? 0 : 1; + + /* Starting column */ + col = mirror ? 0 : 50; + + /* Default "max-length" */ + len = 79 - col; + + /* Maximum space allowed for descriptions */ + lim = 79 - 3; + + /* Space for weight */ + lim -= 9; + + /* Space for icon */ + lim -= 2; + + /* Find the "final" slot */ + for (i = 0; i < INVEN_PACK; i++) + { + o_ptr = &p_ptr->inventory[i]; + + /* Skip non-objects */ + if (!o_ptr->k_idx) continue; + + /* Track */ + z = i + 1; + } + + /* Display the inventory */ + for (k = 0, i = 0; i < z; i++) + { + o_ptr = &p_ptr->inventory[i]; + + /* Is this item acceptable? */ + if (!item_tester_okay(o_ptr)) + { + if ( !everything ) + continue; + out_index[k] = -i - 1; + } + else + { + /* Save the object index */ + out_index[k] = i + 1; + } + + /* Describe the object */ + object_desc(o_name, o_ptr, TRUE, 3); + + /* Hack -- enforce max length */ + o_name[lim] = '\0'; + + /* Save the object color, and description */ + out_color[k] = tval_to_attr[o_ptr->tval % 128]; + (void)strcpy(out_desc[k], o_name); + + /* Find the predicted "line length" */ + l = strlen(out_desc[k]) + 5; + + /* Be sure to account for the weight */ + l += 9; + + /* Account for icon */ + l += 2; + + /* Maintain the maximum length */ + if (l > len) len = l; + + /* Advance to next "line" */ + k++; + } + + /* Find the column to start in */ + if (mirror) col = 0; + else col = (len > wid - 4) ? 0 : (wid - len - 1); + + /* Output each entry */ + for (j = 0; j < k; j++) + { + /* Get the index */ + i = out_index[j]; + + /* Get the item */ + o_ptr = &p_ptr->inventory[ABS(i) - 1]; + + /* Clear the line */ + prt("", row + j, col ? col - 2 : col); + + /* Prepare an index --(-- */ + /* Prepare a blank index if not selectable */ + if ( i > 0 ) + sprintf(tmp_val, "%c)", index_to_label(i - 1)); + else + sprintf(tmp_val, " "); + + /* Clear the line with the (possibly indented) index */ + c_put_str(get_item_letter_color(o_ptr), tmp_val, row + j, col); + + /* Display graphics for object */ + { + byte a = object_attr(o_ptr); + char c = object_char(o_ptr); + + if (!o_ptr->k_idx) c = ' '; + + Term_draw(col + 3, row + j, a, c); + } + + /* Display the entry itself */ + c_put_str(out_color[j], out_desc[j], row + j, + col + 5); + + /* Display the weight */ + { + int wgt = o_ptr->weight * o_ptr->number; + sprintf(tmp_val, "%3d.%1d lb", wgt / 10, wgt % 10); + put_str(tmp_val, row + j, wid - 9); + } + } + + /* Shadow windows */ + if (mirror) + { + /* Erase the rest of the window */ + for (j = row + k; j < Term->hgt; j++) + { + /* Erase the line */ + Term_erase(0, j, 255); + } + } + + /* Main window */ + else + { + /* Make a "shadow" below the list (only if needed) */ + if (j && (j < 23)) prt("", row + j, col ? col - 2 : col); + } +} + + +void show_inven() +{ + show_inven_aux(FALSE, FALSE); +} + +void show_equip() +{ + show_equip_aux(FALSE, FALSE); +} + +/* + * Display the equipment. + */ +void show_equip_aux(bool_ mirror, bool_ everything) +{ + int i, j, k, l; + int row, col, len, lim, idx; + int wid, hgt; + object_type *o_ptr; + char tmp_val[80]; + char o_name[80]; + int out_index[INVEN_TOOL - INVEN_WIELD]; + int out_rindex[INVEN_TOOL - INVEN_WIELD]; + byte out_color[INVEN_TOOL - INVEN_WIELD]; + char out_desc[INVEN_TOOL - INVEN_WIELD][80]; + + + /* Retrive current screen size */ + Term_get_size(&wid, &hgt); + + /* Starting row */ + row = mirror ? 0 : 1; + + /* Starting column */ + col = mirror ? 0 : 50; + + /* Maximal length */ + len = 79 - col; + + /* Maximum space allowed for descriptions */ + lim = 79 - 3; + + /* Require space for labels */ + lim -= (14 + 2); + + /* Require space for weight */ + lim -= 9; + + /* Require space for icon */ + lim -= 2; + + /* Scan the equipment list */ + idx = 0; + for (k = 0, i = INVEN_WIELD; i < INVEN_TOTAL; i++) + { + /* Is there actualy a body part here ? */ + if (!p_ptr->body_parts[i - INVEN_WIELD]) continue; + + /* Mega Hack -- don't show symbiote slot if we can't use it */ + if ((i == INVEN_CARRY) && (!get_skill(SKILL_SYMBIOTIC))) continue; + + o_ptr = &p_ptr->inventory[i]; + + /* Inform the player that he/she can't use a shield */ + if ((p_ptr->body_parts[i - INVEN_WIELD] == INVEN_ARM) && + !o_ptr->k_idx && + p_ptr->inventory[i - INVEN_ARM + INVEN_WIELD].k_idx) + { + u32b f1, f2, f3, f4, f5, esp; + object_type *q_ptr = &p_ptr->inventory[i - INVEN_ARM + INVEN_WIELD]; + char q_name[80]; + + /* Description */ + object_desc(q_name, q_ptr, TRUE, 3); + + /* Get weapon flags */ + object_flags(q_ptr, &f1, &f2, &f3, &f4, &f5, &esp); + + if (f4 & TR4_MUST2H) + { + sprintf(o_name, "(two handed) %s", q_name); + + /* Truncate the description */ + o_name[lim] = 0; + + /* Save the index */ + out_index[k] = idx; + out_rindex[k] = i; + idx++; + + /* Save the color */ + out_color[k] = TERM_L_RED; + (void)strcpy(out_desc[k], o_name); + continue; + } + } + + if ((p_ptr->body_parts[i - INVEN_WIELD] == INVEN_WIELD) && + !o_ptr->k_idx) + { + sprintf(o_name, "(%s)", melee_names[get_melee_skill()]); + + /* Truncate the description */ + o_name[lim] = 0; + + /* Save the index */ + out_index[k] = idx; + out_rindex[k] = i; + idx++; + + /* Save the color */ + out_color[k] = TERM_L_BLUE; + (void)strcpy(out_desc[k], o_name); + } + else + { + idx++; + + /* Description */ + object_desc(o_name, o_ptr, TRUE, 3); + + /* Truncate the description */ + o_name[lim] = 0; + /* Is this item acceptable? */ + if (!item_tester_okay(o_ptr)) + { + if (!everything) continue; + out_index[k] = -1; + } + else + { + /* Save the index */ + out_index[k] = idx; + } + out_rindex[k] = i; + + /* Save the color */ + out_color[k] = tval_to_attr[o_ptr->tval % 128]; + (void)strcpy(out_desc[k], o_name); + } + + /* Extract the maximal length (see below) */ + l = strlen(out_desc[k]) + (2 + 3); + + /* Increase length for labels (if needed) */ + l += (14 + 2); + + /* Increase length for weight */ + l += 9; + + /* Icon */ + l += 2; + + /* Maintain the max-length */ + if (l > len) len = l; + + /* Advance the entry */ + k++; + } + + /* Hack -- Find a column to start in */ + if (mirror) col = 0; + else col = (len > wid - 4) ? 0 : (wid - len - 1); + + /* Output each entry */ + for (j = 0; j < k; j++) + { + if (j > 20) break; + + /* Get the index */ + i = out_index[j]; + + /* Get the item */ + o_ptr = &p_ptr->inventory[out_rindex[j]]; + + /* Clear the line */ + prt("", row + j, col ? col - 2 : col); + + /* Prepare an index --(-- */ + if (out_index[j] >= 0 ) + sprintf(tmp_val, "%c)", index_to_label(out_rindex[j])); + else + sprintf(tmp_val, " "); + + /* Clear the line with the (possibly indented) index */ + c_put_str(get_item_letter_color(o_ptr), tmp_val, row + j, col); + + /* Show icon */ + { + byte a = object_attr(o_ptr); + char c = object_char(o_ptr); + + if (!o_ptr->k_idx) c = ' '; + + Term_draw(col + 3, row + j, a, c); + } + + /* Use labels */ + { + /* Mention the use */ + (void)sprintf(tmp_val, "%-14s: ", mention_use(out_rindex[j])); + put_str(tmp_val, row + j, col + 5); + + /* Display the entry itself */ + c_put_str(out_color[j], out_desc[j], row + j, col + 21); + } + + /* Display the weight */ + { + int wgt = o_ptr->weight * o_ptr->number; + sprintf(tmp_val, "%3d.%d lb", wgt / 10, wgt % 10); + put_str(tmp_val, row + j, wid - 9); + } + } + + + /* Shadow windows */ + if (mirror) + { + /* Erase the rest of the window */ + for (j = row + k; j < Term->hgt; j++) + { + /* Erase the line */ + Term_erase(0, j, 255); + } + } + + /* Main window */ + else + { + /* Make a "shadow" below the list (only if needed) */ + if (j && (j < 23)) prt("", row + j, col ? col - 2 : col); + } +} + + + + +/* + * Flip "inven" and "equip" in any sub-windows + */ +void toggle_inven_equip(void) +{ + int j; + + /* Scan windows */ + for (j = 0; j < 8; j++) + { + /* Unused */ + if (!angband_term[j]) continue; + + /* Flip inven to equip */ + if (window_flag[j] & (PW_INVEN)) + { + /* Flip flags */ + window_flag[j] &= ~(PW_INVEN); + window_flag[j] |= (PW_EQUIP); + + /* Window stuff */ + p_ptr->window |= (PW_EQUIP); + } + + /* Flip inven to equip */ + else if (window_flag[j] & (PW_EQUIP)) + { + /* Flip flags */ + window_flag[j] &= ~(PW_EQUIP); + window_flag[j] |= (PW_INVEN); + + /* Window stuff */ + p_ptr->window |= (PW_INVEN); + } + } +} + + + +/* + * Verify the choice of an item. + * + * The item can be negative to mean "item on floor". + */ +bool_ verify(cptr prompt, int item) +{ + char o_name[80]; + + char out_val[160]; + + object_type *o_ptr; + + /* Get object */ + o_ptr = get_object(item); + + /* Describe */ + object_desc(o_name, o_ptr, TRUE, 3); + + /* Prompt */ + (void)sprintf(out_val, "%s %s? ", prompt, o_name); + + /* Query */ + return (get_check(out_val)); +} + + +/* + * Hack -- allow user to "prevent" certain choices + * + * The item can be negative to mean "item on floor". + */ +static bool_ get_item_allow(int item) +{ + cptr s; + + object_type *o_ptr; + + /* Get object */ + o_ptr = get_object(item); + + /* No inscription */ + if (!o_ptr->note) return (TRUE); + + /* Find a '!' */ + s = strchr(quark_str(o_ptr->note), '!'); + + /* Process preventions */ + while (s) + { + /* Check the "restriction" */ + if ((s[1] == command_cmd) || (s[1] == '*')) + { + /* Verify the choice */ + if (!verify("Really try", item)) return (FALSE); + } + + /* Find another '!' */ + s = strchr(s + 1, '!'); + } + + /* Allow it */ + return (TRUE); +} + + + +/* + * Auxiliary function for "get_item()" -- test an index + */ +static bool_ get_item_okay(int i) +{ + /* Illegal items */ + if ((i < 0) || (i >= INVEN_TOTAL)) return (FALSE); + + /* Verify the item */ + if (!item_tester_okay(&p_ptr->inventory[i])) return (FALSE); + + /* Assume okay */ + return (TRUE); +} + + + +/* + * Find the "first" inventory object with the given "tag". + * + * A "tag" is a char "n" appearing as "@n" anywhere in the + * inscription of an object. + * + * Also, the tag "@xn" will work as well, where "n" is a tag-char, + * and "x" is the "current" command_cmd code. + */ +static int get_tag(int *cp, char tag) +{ + int i; + cptr s; + + + /* Check every object */ + for (i = 0; i < INVEN_TOTAL; ++i) + { + object_type *o_ptr = &p_ptr->inventory[i]; + + /* Skip non-objects */ + if (!o_ptr->k_idx) continue; + + /* Skip empty inscriptions */ + if (!o_ptr->note) continue; + + /* Find a '@' */ + s = strchr(quark_str(o_ptr->note), '@'); + + /* Process all tags */ + while (s) + { + /* Check the normal tags */ + if (s[1] == tag) + { + /* Save the actual inventory ID */ + *cp = i; + + /* Success */ + return (TRUE); + } + + /* Check the special tags */ + if ((s[1] == command_cmd) && (s[2] == tag)) + { + /* Save the actual inventory ID */ + *cp = i; + + /* Success */ + return (TRUE); + } + + /* Find another '@' */ + s = strchr(s + 1, '@'); + } + } + + /* No such tag */ + return (FALSE); +} + +/* + * scan_floor -- + * + * Return a list of o_list[] indexes of items at the given cave + * location. Valid flags are: + * + * mode & 0x01 -- Item tester + * mode & 0x02 -- Marked items only + * mode & 0x04 -- Stop after first + */ +bool_ scan_floor(int *items, int *item_num, int y, int x, int mode) +{ + int this_o_idx, next_o_idx; + + int num = 0; + + (*item_num) = 0; + + /* Sanity */ + if (!in_bounds(y, x)) return (FALSE); + + /* Scan all objects in the grid */ + for (this_o_idx = cave[y][x].o_idx; this_o_idx; this_o_idx = next_o_idx) + { + object_type * o_ptr; + + /* Acquire object */ + o_ptr = &o_list[this_o_idx]; + + /* Acquire next object */ + next_o_idx = o_ptr->next_o_idx; + + /* Item tester */ + if ((mode & 0x01) && !item_tester_okay(o_ptr)) continue; + + /* Marked */ + if ((mode & 0x02) && !o_ptr->marked) continue; + + /* Accept this item */ + items[num++] = this_o_idx; + + /* Only one */ + if (mode & 0x04) break; + + /* XXX Hack -- Enforce limit */ + if (num == 23) break; + } + + /* Number of items */ + (*item_num) = num; + + /* Result */ + return (num != 0); +} + +/* + * Display a list of the items on the floor at the given location. + */ +void show_floor(int y, int x) +{ + int i, j, k, l; + int col, len, lim; + + object_type *o_ptr; + + char o_name[80]; + + char tmp_val[80]; + + int out_index[23]; + byte out_color[23]; + char out_desc[23][80]; + + int floor_list[23], floor_num; + + /* Default length */ + len = 79 - 50; + + /* Maximum space allowed for descriptions */ + lim = 79 - 3; + + /* Require space for weight */ + lim -= 9; + + /* Scan for objects in the grid, using item_tester_okay() */ + (void) scan_floor(floor_list, &floor_num, y, x, 0x01); + + /* Display the inventory */ + for (k = 0, i = 0; i < floor_num; i++) + { + o_ptr = &o_list[floor_list[i]]; + + /* Describe the object */ + object_desc(o_name, o_ptr, TRUE, 3); + + /* Hack -- enforce max length */ + o_name[lim] = '\0'; + + /* Save the index */ + out_index[k] = i; + + /* Acquire inventory color */ + out_color[k] = tval_to_attr[o_ptr->tval & 0x7F]; + + /* Save the object description */ + strcpy(out_desc[k], o_name); + + /* Find the predicted "line length" */ + l = strlen(out_desc[k]) + 5; + + /* Account for the weight */ + l += 9; + + /* Maintain the maximum length */ + if (l > len) len = l; + + /* Advance to next "line" */ + k++; + } + + /* Find the column to start in */ + col = (len > 76) ? 0 : (79 - len); + + /* Output each entry */ + for (j = 0; j < k; j++) + { + /* Get the index */ + i = floor_list[out_index[j]]; + + /* Get the item */ + o_ptr = &o_list[i]; + + /* Clear the line */ + prt("", j + 1, col ? col - 2 : col); + + /* Prepare an index --(-- */ + sprintf(tmp_val, "%c)", index_to_label(j)); + + /* Clear the line with the (possibly indented) index */ + put_str(tmp_val, j + 1, col); + + /* Display the entry itself */ + c_put_str(out_color[j], out_desc[j], j + 1, col + 3); + + /* Display the weight if needed */ + { + int wgt = o_ptr->weight * o_ptr->number; + sprintf(tmp_val, "%3d.%1d lb", wgt / 10, wgt % 10); + put_str(tmp_val, j + 1, 71); + } + } + + /* Make a "shadow" below the list (only if needed) */ + if (j && (j < 23)) prt("", j + 1, col ? col - 2 : col); +} + +/* + * This version of get_item() is called by get_item() when + * the easy_floor is on. + */ +bool_ (*get_item_extra_hook)(int *cp); +bool_ get_item_floor(int *cp, cptr pmt, cptr str, int mode) +{ + char n1 = 0, n2 = 0, which = ' '; + + int j, k, i1, i2, e1, e2; + + bool_ done, item; + + bool_ oops = FALSE; + + bool_ equip = FALSE; + bool_ inven = FALSE; + bool_ floor = FALSE; + bool_ extra = FALSE; + bool_ automat = FALSE; + + bool_ allow_equip = FALSE; + bool_ allow_inven = FALSE; + bool_ allow_floor = FALSE; + + bool_ toggle = FALSE; + + char tmp_val[160]; + char out_val[160]; + + int floor_num, floor_list[23], floor_top = 0; + + k = 0; + + /* Get the item index */ + if (repeat_pull(cp)) + { + /* Floor item? */ + if (*cp < 0) + { + object_type *o_ptr; + + /* Special index */ + k = 0 - (*cp); + + /* Acquire object */ + o_ptr = &o_list[k]; + + /* Validate the item */ + if (item_tester_okay(o_ptr)) + { + /* Forget the item_tester_tval restriction */ + item_tester_tval = 0; + + /* Forget the item_tester_hook restriction */ + item_tester_hook = NULL; + + /* Success */ + return (TRUE); + } + } + + /* Verify the item */ + else if (get_item_okay(*cp)) + { + /* Forget the item_tester_tval restriction */ + item_tester_tval = 0; + + /* Forget the item_tester_hook restriction */ + item_tester_hook = NULL; + + /* Success */ + return (TRUE); + } + } + + + /* Extract args */ + if (mode & (USE_EQUIP)) equip = TRUE; + if (mode & (USE_INVEN)) inven = TRUE; + if (mode & (USE_FLOOR)) floor = TRUE; + if (mode & (USE_EXTRA)) extra = TRUE; + if (mode & (USE_AUTO)) automat = TRUE; + + + /* Paranoia XXX XXX XXX */ + msg_print(NULL); + + + /* Not done */ + done = FALSE; + + /* No item selected */ + item = FALSE; + + + /* Full inventory */ + i1 = 0; + i2 = INVEN_PACK - 1; + + /* Forbid inventory */ + if (!inven) i2 = -1; + + /* Restrict inventory indexes */ + while ((i1 <= i2) && (!get_item_okay(i1))) i1++; + while ((i1 <= i2) && (!get_item_okay(i2))) i2--; + + + /* Full equipment */ + e1 = INVEN_WIELD; + e2 = INVEN_TOTAL - 1; + + /* Forbid equipment */ + if (!equip) e2 = -1; + + /* Restrict equipment indexes */ + while ((e1 <= e2) && (!get_item_okay(e1))) e1++; + while ((e1 <= e2) && (!get_item_okay(e2))) e2--; + + + /* Count "okay" floor items */ + floor_num = 0; + + /* Restrict floor usage */ + if (floor) + { + /* Scan all objects in the grid */ + (void) scan_floor(floor_list, &floor_num, p_ptr->py, p_ptr->px, 0x01); + } + + /* Accept inventory */ + if (i1 <= i2) allow_inven = TRUE; + + /* Accept equipment */ + if (e1 <= e2) allow_equip = TRUE; + + /* Accept floor */ + if (floor_num) allow_floor = TRUE; + + /* Require at least one legal choice */ + if (!allow_inven && !allow_equip && !allow_floor) + { + /* Oops */ + oops = TRUE; + + /* Done */ + done = TRUE; + } + + /* Analyze choices */ + else + { + /* Hack -- Start on equipment if requested */ + if ((command_wrk == (USE_EQUIP)) && allow_equip) + { + command_wrk = (USE_EQUIP); + } + + /* Use inventory if allowed */ + else if (allow_inven) + { + command_wrk = (USE_INVEN); + } + + /* Use equipment if allowed */ + else if (allow_equip) + { + command_wrk = (USE_EQUIP); + } + + /* Use floor if allowed */ + else if (allow_floor) + { + command_wrk = (USE_FLOOR); + } + } + + /* Save screen */ + screen_save(); + + /* Repeat until done */ + while (!done) + { + /* Show choices */ + { + int ni = 0; + int ne = 0; + + /* Scan windows */ + for (j = 0; j < 8; j++) + { + /* Unused */ + if (!angband_term[j]) continue; + + /* Count windows displaying inven */ + if (window_flag[j] & (PW_INVEN)) ni++; + + /* Count windows displaying equip */ + if (window_flag[j] & (PW_EQUIP)) ne++; + } + + /* Toggle if needed */ + if ((command_wrk == (USE_EQUIP) && ni && !ne) || + (command_wrk == (USE_INVEN) && !ni && ne)) + { + /* Toggle */ + toggle_inven_equip(); + + /* Track toggles */ + toggle = !toggle; + } + + /* Update */ + p_ptr->window |= (PW_INVEN | PW_EQUIP); + + /* Redraw windows */ + window_stuff(); + } + + /* Inventory screen */ + if (command_wrk == (USE_INVEN)) + { + /* Extract the legal requests */ + n1 = I2A(i1); + n2 = I2A(i2); + + /* Redraw */ + show_inven(); + } + + /* Equipment screen */ + else if (command_wrk == (USE_EQUIP)) + { + /* Extract the legal requests */ + n1 = I2A(e1 - INVEN_WIELD); + n2 = I2A(e2 - INVEN_WIELD); + + /* Redraw */ + show_equip(); + } + + /* Floor screen */ + else if (command_wrk == (USE_FLOOR)) + { + j = floor_top; + k = MIN(floor_top + 23, floor_num) - 1; + + /* Extract the legal requests */ + n1 = I2A(j - floor_top); + n2 = I2A(k - floor_top); + + /* Redraw */ + show_floor(p_ptr->py, p_ptr->px); + } + + /* Viewing inventory */ + if (command_wrk == (USE_INVEN)) + { + /* Begin the prompt */ + sprintf(out_val, "Inven:"); + + /* Build the prompt */ + sprintf(tmp_val, " %c-%c,", + index_to_label(i1), index_to_label(i2)); + + /* Append */ + strcat(out_val, tmp_val); + + /* Append */ + if (allow_equip) strcat(out_val, " / for Equip,"); + + /* Append */ + if (allow_floor) strcat(out_val, " - for floor,"); + } + + /* Viewing equipment */ + else if (command_wrk == (USE_EQUIP)) + { + /* Begin the prompt */ + sprintf(out_val, "Equip:"); + + /* Build the prompt */ + sprintf(tmp_val, " %c-%c,", + index_to_label(e1), index_to_label(e2)); + + /* Append */ + strcat(out_val, tmp_val); + + /* Append */ + if (allow_inven) strcat(out_val, " / for Inven,"); + + /* Append */ + if (allow_floor) strcat(out_val, " - for floor,"); + } + + /* Viewing floor */ + else if (command_wrk == (USE_FLOOR)) + { + /* Begin the prompt */ + sprintf(out_val, "Floor:"); + + /* Build the prompt */ + sprintf(tmp_val, " %c-%c,", n1, n2); + + /* Append */ + strcat(out_val, tmp_val); + + /* Append */ + if (allow_inven) + { + strcat(out_val, " / for Inven,"); + } + else if (allow_equip) + { + strcat(out_val, " / for Equip,"); + } + } + + /* Extra? */ + if (extra) + { + strcat(out_val, " @ for extra selection,"); + } + + /* Create automatizer rule?? */ + if (automat) + { + if (automatizer_create) + strcat(out_val, " $ new automatizer rule(ON),"); + else + strcat(out_val, " $ new automatizer rule(OFF),"); + } + + /* Finish the prompt */ + strcat(out_val, " ESC"); + + /* Build the prompt */ + sprintf(tmp_val, "(%s) %s", out_val, pmt); + + /* Show the prompt */ + prt(tmp_val, 0, 0); + + /* Get a key */ + which = inkey(); + + /* Parse it */ + switch (which) + { + case ESCAPE: + { + done = TRUE; + break; + } + + case '/': + { + if (command_wrk == (USE_INVEN)) + { + if (!allow_equip) + { + bell(); + break; + } + command_wrk = (USE_EQUIP); + } + else if (command_wrk == (USE_EQUIP)) + { + if (!allow_inven) + { + bell(); + break; + } + command_wrk = (USE_INVEN); + } + else if (command_wrk == (USE_FLOOR)) + { + if (allow_inven) + { + command_wrk = (USE_INVEN); + } + else if (allow_equip) + { + command_wrk = (USE_EQUIP); + } + else + { + bell(); + break; + } + } + + /* Hack -- Fix screen */ + screen_load(); + screen_save(); + + /* Need to redraw */ + break; + } + + case '-': + { + if (!allow_floor) + { + bell(); + break; + } + + /* + * If we are already examining the floor, and there + * is only one item, we will always select it. + * If we aren't examining the floor and there is only + * one item, we will select it if floor_query_flag + * is FALSE. + */ + if (floor_num == 1) + { + if (command_wrk == (USE_FLOOR)) + { + /* Special index */ + k = 0 - floor_list[0]; + + /* Allow player to "refuse" certain actions */ + if (!get_item_allow(k)) + { + done = TRUE; + break; + } + + /* Accept that choice */ + (*cp) = k; + item = TRUE; + done = TRUE; + + break; + } + } + + /* Hack -- Fix screen */ + screen_load(); + screen_save(); + + command_wrk = (USE_FLOOR); + + break; + } + + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + { + /* Look up the tag */ + if (!get_tag(&k, which)) + { + bell(); + break; + } + + /* Hack -- Validate the item */ + if ((k < INVEN_WIELD) ? !inven : !equip) + { + bell(); + break; + } + + /* Validate the item */ + if (!get_item_okay(k)) + { + bell(); + break; + } + + /* Allow player to "refuse" certain actions */ + if (!get_item_allow(k)) + { + done = TRUE; + break; + } + + /* Accept that choice */ + (*cp) = k; + item = TRUE; + done = TRUE; + break; + } + + case '\n': + case '\r': + { + /* Choose "default" inventory item */ + if (command_wrk == (USE_INVEN)) + { + k = ((i1 == i2) ? i1 : -1); + } + + /* Choose "default" equipment item */ + else if (command_wrk == (USE_EQUIP)) + { + k = ((e1 == e2) ? e1 : -1); + } + + /* Choose "default" floor item */ + else if (command_wrk == (USE_FLOOR)) + { + if (floor_num == 1) + { + /* Special index */ + k = 0 - floor_list[0]; + + /* Allow player to "refuse" certain actions */ + if (!get_item_allow(k)) + { + done = TRUE; + break; + } + + /* Accept that choice */ + (*cp) = k; + item = TRUE; + done = TRUE; + } + break; + } + + /* Validate the item */ + if (!get_item_okay(k)) + { + bell(); + break; + } + + /* Allow player to "refuse" certain actions */ + if (!get_item_allow(k)) + { + done = TRUE; + break; + } + + /* Accept that choice */ + (*cp) = k; + item = TRUE; + done = TRUE; + break; + } + + case '@': + { + int i; + + if (extra && get_item_extra_hook(&i)) + { + (*cp) = i; + item = TRUE; + done = TRUE; + } + break; + } + + case '$': + { + automatizer_create = !automatizer_create; + break; + } + + default: + { + int ver; + + ver = isupper(which); + which = tolower(which); + + /* Convert letter to inventory index */ + if (command_wrk == (USE_INVEN)) + { + k = label_to_inven(which); + if (k == -1) + { + bell(); + break; + } + } + + /* Convert letter to equipment index */ + else if (command_wrk == (USE_EQUIP)) + { + k = label_to_equip(which); + if (k == -1) + { + bell(); + break; + } + } + + /* Convert letter to floor index */ + else if (command_wrk == (USE_FLOOR)) + { + k = islower(which) ? A2I(which) : -1; + if (k < 0 || k >= floor_num) + { + bell(); + break; + } + + /* Special index */ + k = 0 - floor_list[k]; + } + + /* Validate the item */ + if ((k >= 0) && !get_item_okay(k)) + { + bell(); + break; + } + + /* Verify the item */ + if (ver && !verify("Try", k)) + { + done = TRUE; + break; + } + + /* Allow player to "refuse" certain actions */ + if (!get_item_allow(k)) + { + done = TRUE; + break; + } + + /* Accept that choice */ + (*cp) = k; + item = TRUE; + done = TRUE; + break; + } + } + } + + /* Fix the screen */ + screen_load(); + + /* Forget the item_tester_tval restriction */ + item_tester_tval = 0; + + /* Forget the item_tester_hook restriction */ + item_tester_hook = NULL; + + /* Track */ + if (item && done) + { + if (*cp >= 0) + { + object_track(&p_ptr->inventory[*cp]); + } + else + { + object_track(&o_list[0 - *cp]); + } + } + + /* Clean up */ + { + /* Toggle again if needed */ + if (toggle) toggle_inven_equip(); + + /* Update */ + p_ptr->window |= (PW_INVEN | PW_EQUIP); + + /* Window stuff */ + window_stuff(); + } + + + /* Clear the prompt line */ + prt("", 0, 0); + + /* Warning if needed */ + if (oops && str) msg_print(str); + + + if (item) repeat_push(*cp); + + /* Result */ + return (item); +} + + +/* + * Let the user select an item, save its "index" + * + * Return TRUE only if an acceptable item was chosen by the user. + * + * The selected item must satisfy the "item_tester_hook()" function, + * if that hook is set, and the "item_tester_tval", if that value is set. + * + * All "item_tester" restrictions are cleared before this function returns. + * + * The user is allowed to choose acceptable items from the equipment, + * inventory, or floor, respectively, if the proper flag was given, + * and there are any acceptable items in that location. + * + * The equipment or inventory are displayed (even if no acceptable + * items are in that location) if the proper flag was given. + * + * If there are no acceptable items available anywhere, and "str" is + * not NULL, then it will be used as the text of a warning message + * before the function returns. + * + * Note that the user must press "-" to specify the item on the floor, + * and there is no way to "examine" the item on the floor, while the + * use of "capital" letters will "examine" an inventory/equipment item, + * and prompt for its use. + * + * If a legal item is selected from the inventory, we save it in "cp" + * directly (0 to 35), and return TRUE. + * + * If a legal item is selected from the floor, we save it in "cp" as + * a negative (-1 to -511), and return TRUE. + * + * If no item is available, we do nothing to "cp", and we display a + * warning message, using "str" if available, and return FALSE. + * + * If no item is selected, we do nothing to "cp", and return FALSE. + * + * Global "p_ptr->command_new" is used when viewing the inventory or equipment + * to allow the user to enter a command while viewing those screens, and + * also to induce "auto-enter" of stores, and other such stuff. + * + * Global "p_ptr->command_wrk" is used to choose between equip/inven listings. + * If it is TRUE then we are viewing inventory, else equipment. + * + * We always erase the prompt when we are done, leaving a blank line, + * or a warning message, if appropriate, if no items are available. + */ +bool_ get_item(int *cp, cptr pmt, cptr str, int mode) +{ + automatizer_create = FALSE; + + return get_item_floor(cp, pmt, str, mode); +} + +/* + * Hook to determine if an object is getable + */ +static bool_ item_tester_hook_getable(object_type *o_ptr) +{ + if (!inven_carry_okay(o_ptr)) return (FALSE); + + if ((o_ptr->tval == TV_HYPNOS) && (!get_skill(SKILL_SYMBIOTIC))) return FALSE; + + /* Assume yes */ + return (TRUE); +} + +/* + * Wear a single item from o_ptr + */ +int wear_ammo(object_type *o_ptr) +{ + int slot, num = 1; + + object_type forge; + object_type *q_ptr; + + /* Check the slot */ + slot = wield_slot(o_ptr); + + if(slot == -1) + return -1; + + /* Get local object */ + q_ptr = &forge; + + /* Obtain local object */ + object_copy(q_ptr, o_ptr); + + num = o_ptr->number; + + /* Modify quantity */ + q_ptr->number = num; + + /* Access the wield slot */ + o_ptr = &p_ptr->inventory[slot]; + + q_ptr->number += o_ptr->number; + + /* Wear the new stuff */ + object_copy(o_ptr, q_ptr); + + /* Increment the equip counter by hand */ + equip_cnt++; + + /* Cursed! */ + if (cursed_p(o_ptr)) + { + /* Warn the player */ + msg_print("Oops! It feels deathly cold!"); + + /* Note the curse */ + o_ptr->ident |= (IDENT_SENSE); + o_ptr->sense = SENSE_CURSED; + } + + /* Recalculate bonuses */ + p_ptr->update |= (PU_BONUS); + + /* Recalculate torch */ + p_ptr->update |= (PU_TORCH); + + /* Recalculate hitpoint */ + p_ptr->update |= (PU_HP); + + /* Recalculate mana */ + p_ptr->update |= (PU_MANA); + + /* Redraw monster hitpoint */ + p_ptr->redraw |= (PR_MH); + + /* Window stuff */ + p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER); + + return slot; +} + + +/* + * Try to pickup arrows + */ +void pickup_ammo() +{ + s16b this_o_idx, next_o_idx = 0, slot; + char o_name[80]; + + /* Scan the pile of objects */ + for (this_o_idx = cave[p_ptr->py][p_ptr->px].o_idx; this_o_idx; this_o_idx = next_o_idx) + { + object_type * o_ptr; + + /* Acquire object */ + o_ptr = &o_list[this_o_idx]; + + if (object_similar(o_ptr, &p_ptr->inventory[INVEN_AMMO])) + { + msg_print("You add the ammo to your quiver."); + slot = wear_ammo(o_ptr); + + if (slot != -1) + { + /* Get the item again */ + o_ptr = &p_ptr->inventory[slot]; + + /* Describe the object */ + object_desc(o_name, o_ptr, TRUE, 3); + + /* Message */ + msg_format("You have %s (%c).", o_name, index_to_label(slot)); + + /* Delete the object */ + delete_object_idx(this_o_idx); + } + } + + /* Acquire next object */ + next_o_idx = o_ptr->next_o_idx; + } +} + + +/* + * Make the player carry everything in a grid + * + * If "pickup" is FALSE then only gold will be picked up + * + * This is called by py_pickup() when easy_floor is TRUE. + */ +bool_ can_carry_heavy(object_type *o_ptr) +{ + /* Query if object is heavy */ + if (prompt_pickup_heavy) + { + int i, j; + int old_enc = 0; + int new_enc = 0; + + /* Extract the "weight limit" (in tenth pounds) */ + i = weight_limit(); + + /* Calculate current encumbarance */ + j = calc_total_weight(); + + /* Apply encumbarance from weight */ + if (j > i / 2) old_enc = ((j - (i / 2)) / (i / 10)); + + /* Increase the weight, recalculate encumbarance */ + j += (o_ptr->number * o_ptr->weight); + + /* Apply encumbarance from weight */ + if (j > i / 2) new_enc = ((j - (i / 2)) / (i / 10)); + + /* Should we query? */ + if (new_enc > old_enc) + { + return (FALSE); + } + } + return (TRUE); +} + +/* Do the actuall picking up */ +void object_pickup(int this_o_idx) +{ + int slot = 0; + char o_name[80] = ""; + object_type *q_ptr, *o_ptr; + + /* Access the item */ + o_ptr = &o_list[this_o_idx]; + + if (p_ptr->auto_id) + { + object_aware(o_ptr); + object_known(o_ptr); + } + + /* Describe the object */ + object_desc(o_name, o_ptr, TRUE, 3); + + /* Note that the pack is too full */ + if (!inven_carry_okay(o_ptr) && !object_similar(o_ptr, &p_ptr->inventory[INVEN_AMMO])) + { + msg_format("You have no room for %s.", o_name); + } + + /* Pick up object */ + else + { + /* Tell the scripts */ + if (process_hooks(HOOK_GET, "(O,d)", o_ptr, this_o_idx)) + return; + + /* Hooks */ + { + hook_get_in in = { o_ptr, this_o_idx }; + if (process_hooks_new(HOOK_GET, &in, NULL)) + { + return; + } + } + + q_ptr = &p_ptr->inventory[INVEN_AMMO]; + + /* Carry the item */ + if (object_similar(o_ptr, q_ptr)) + { + msg_print("You add the ammo to your quiver."); + slot = wear_ammo(o_ptr); + } + else + { + slot = inven_carry(o_ptr, FALSE); + } + + /* Sanity check */ + if (slot != -1) + { + /* Get the item again */ + o_ptr = &p_ptr->inventory[slot]; + + object_track(o_ptr); + + /* Describe the object */ + object_desc(o_name, o_ptr, TRUE, 3); + + /* Message */ + msg_format("You have %s (%c).", o_name, index_to_label(slot)); + + /* Delete the object */ + delete_object_idx(this_o_idx); + + /* Sense object. */ + sense_inventory(); + } + } +} + + +void py_pickup_floor(int pickup) +{ + s16b this_o_idx, next_o_idx = 0; + + char o_name[80] = ""; + object_type *o_ptr = 0; + + int floor_num = 0, floor_o_idx = 0; + + bool_ do_pickup = TRUE; + + bool_ do_ask = TRUE; + + /* Hack -- ignore monster traps */ + if (cave[p_ptr->py][p_ptr->px].feat == FEAT_MON_TRAP) return; + + /* Try to grab ammo */ + pickup_ammo(); + + /* Mega Hack -- If we have auto-Id, do an ID sweep *before* squleching, + * so that we don't have to walk over things twice to get them + * squelched. --dsb */ + if (p_ptr->auto_id) + { + this_o_idx = cave[p_ptr->py][p_ptr->px].o_idx; + + for (; this_o_idx; this_o_idx = next_o_idx) + { + /* Aquire the object */ + o_ptr = &o_list[this_o_idx]; + + /* Acquire the next object index */ + next_o_idx = o_ptr->next_o_idx; + + /* Identify Object */ + object_aware(o_ptr); + object_known(o_ptr); + } + } + + /* Squeltch the floor */ + squeltch_grid(); + + /* Scan the pile of objects */ + for (this_o_idx = cave[p_ptr->py][p_ptr->px].o_idx; this_o_idx; this_o_idx = next_o_idx) + { + /* Acquire object */ + o_ptr = &o_list[this_o_idx]; + + /* Acquire next object */ + next_o_idx = o_ptr->next_o_idx; + + /* Hack -- disturb */ + disturb(0); + + /* Pick up gold */ + if (o_ptr->tval == TV_GOLD) + { + char goldname[80]; + object_desc(goldname, o_ptr, TRUE, 3); + /* Message */ + msg_format("You have found %ld gold pieces worth of %s.", + (long)o_ptr->pval, goldname); + + /* Collect the gold */ + p_ptr->au += o_ptr->pval; + + /* Redraw gold */ + p_ptr->redraw |= (PR_GOLD); + + /* Window stuff */ + p_ptr->window |= (PW_PLAYER); + + /* Delete the gold */ + delete_object_idx(this_o_idx); + + continue; + } + + { + char testdesc[80]; + + object_desc(testdesc, o_ptr, TRUE, 3); + if (0 != strncmp(testdesc, "(nothing)", 80)) + { + strncpy(o_name, testdesc, 80); + } + } + + /* Count non-gold */ + floor_num++; + + /* Remember this index */ + floor_o_idx = this_o_idx; + } + + /* There were no non-gold items */ + if (!floor_num) return; + + /* Mention number of items */ + if (!pickup) + { + /* One item */ + if (floor_num == 1) + { + /* Acquire object */ + o_ptr = &o_list[floor_o_idx]; + + /* Message */ + msg_format("You see %s.", o_name); + } + + /* Multiple items */ + else + { + /* Message */ + msg_format("You see a pile of %d items.", floor_num); + } + + /* Done */ + return; + } + + /* One item */ + if (floor_num == 1) + { + /* Hack -- query every item */ + if (carry_query_flag || (!can_carry_heavy(&o_list[floor_o_idx]))) + { + if (!inven_carry_okay(o_ptr) && !object_similar(o_ptr, &p_ptr->inventory[INVEN_AMMO])) + { + object_desc(o_name, o_ptr, TRUE, 3); + msg_format("You have no room for %s.", o_name); + do_pickup = FALSE; + } + else + { + char out_val[160]; + sprintf(out_val, "Pick up %s? ", o_name); + do_pickup = get_check(out_val); + } + } + + /* Don't ask */ + do_ask = FALSE; + + if ((o_list[floor_o_idx].tval == TV_HYPNOS) && (!get_skill(SKILL_SYMBIOTIC))) + do_pickup = FALSE; + else + this_o_idx = floor_o_idx; + } + + /* Ask */ + if (do_ask) + { + cptr q, s; + + int item; + + /* Get an item */ + + item_tester_hook = item_tester_hook_getable; + + q = "Get which item? "; + s = "You have no room in your pack for any of the items here."; + if (get_item(&item, q, s, (USE_FLOOR))) + { + this_o_idx = 0 - item; + + if (!can_carry_heavy(&o_list[this_o_idx])) + { + char out_val[160]; + + /* Describe the object */ + object_desc(o_name, &o_list[this_o_idx], TRUE, 3); + + sprintf(out_val, "Pick up %s? ", o_name); + do_pickup = get_check(out_val); + } + } + else + { + do_pickup = FALSE; + } + } + + /* Pick up the item */ + if (do_pickup) + { + object_pickup(this_o_idx); + } +} + +/* Add a flags group */ +void gain_flag_group(object_type *o_ptr, bool_ silent) +{ + int grp = 0; + int tries = 1000; + + while (tries--) + { + grp = rand_int(MAX_FLAG_GROUP); + + /* If we already got this group continue */ + if (o_ptr->pval3 & BIT(grp)) continue; + + /* Not enough points ? */ + if (flags_groups[grp].price > o_ptr->pval2) continue; + + /* Ok, enough points and not already got it */ + break; + } + + /* Ack, nothing found */ + if (tries <= 1) return; + + o_ptr->pval2 -= flags_groups[grp].price; + o_ptr->pval3 |= BIT(grp); + + if (!silent) + { + char o_name[80]; + + object_desc(o_name, o_ptr, FALSE, 0); + msg_format("%s gains access to the %s realm.", o_name, flags_groups[grp].name); + } +} + +u32b get_flag(object_type *o_ptr, int grp, int k) +{ + u32b f = 0, flag_set = 0; + int tries = 1000; + u32b f1, f2, f3, f4, f5, esp, flag_test; + + /* Extract some flags */ + object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); + + /* get the corresponding flag set of the group */ + switch (k) + { + case 0: + flag_set = flags_groups[grp].flags1; + flag_test = f1; + break; + case 1: + flag_set = flags_groups[grp].flags2; + flag_test = f2; + break; + case 2: + flag_set = flags_groups[grp].flags3; + flag_test = f3; + break; + case 3: + flag_set = flags_groups[grp].flags4; + flag_test = f4; + break; + case 4: + flag_set = flags_groups[grp].esp; + flag_test = esp; + break; + default: + flag_set = flags_groups[grp].flags1; + flag_test = f1; + break; + } + + /* If no flags, no need to look */ + if (!count_bits(flag_set)) return 0; + + while (tries--) + { + /* get a random flag */ + f = BIT(rand_int(32)); + + /* is it part of the group */ + if (!(f & flag_set)) continue; + + /* Already got it */ + if (f & flag_test) continue; + + /* Ok one */ + break; + } + + if (tries <= 1) return (0); + else return (f); +} + +/* Add a flags from a flag group */ +void gain_flag_group_flag(object_type *o_ptr, bool_ silent) +{ + int grp = 0, k = 0; + u32b f = 0; + int tries = 20000; + + if (!count_bits(o_ptr->pval3)) return; + + while (tries--) + { + /* Get a flag set */ + k = rand_int(5); + + /* get a flag group */ + grp = rand_int(MAX_FLAG_GROUP); + + if (!(BIT(grp) & o_ptr->pval3)) continue; + + /* Return a flag from the group/set */ + f = get_flag(o_ptr, grp, k); + + if (!f) continue; + + break; + } + + if (tries <= 1) return; + + switch (k) + { + case 0: + o_ptr->art_flags1 |= f; + break; + case 1: + o_ptr->art_flags2 |= f; + break; + case 2: + o_ptr->art_flags3 |= f; + break; + case 3: + o_ptr->art_flags4 |= f; + break; + case 4: + o_ptr->art_esp |= f; + break; + } + + if (!silent) + { + char o_name[80]; + + object_desc(o_name, o_ptr, FALSE, 0); + msg_format("%s gains a new power from the %s realm.", o_name, flags_groups[grp].name); + } +} + +/* + * When an object gain a level, he can gain some attributes + */ +void object_gain_level(object_type *o_ptr) +{ + u32b f1, f2, f3, f4, f5, esp; + + /* Extract some flags */ + object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); + + /* First it can gain some tohit and todam */ + if ((o_ptr->tval == TV_AXE) || (o_ptr->tval == TV_SWORD) || (o_ptr->tval == TV_POLEARM) || + (o_ptr->tval == TV_HAFTED) || (o_ptr->tval == TV_MSTAFF)) + { + int k = rand_int(100); + + /* gain +2,+1 */ + if (k < 33) + { + o_ptr->to_h += randint(2); + o_ptr->to_d += 1; + } + /* +1 and 1 point */ + else if (k < 66) + { + o_ptr->to_h += 1; + o_ptr->pval2++; + + if (magik(NEW_GROUP_CHANCE)) gain_flag_group(o_ptr, FALSE); + } + else + { + if (!o_ptr->pval3) gain_flag_group(o_ptr, FALSE); + + gain_flag_group_flag(o_ptr, FALSE); + + if (!o_ptr->pval) o_ptr->pval = 1; + else + { + while (magik(20 - (o_ptr->pval * 2))) o_ptr->pval++; + + if (o_ptr->pval > 5) o_ptr->pval = 5; + } + } + } +} + + +/* + * Item sets fcts + */ +bool_ wield_set(s16b a_idx, s16b set_idx, bool_ silent) +{ + set_type *s_ptr = &set_info[set_idx]; + int i; + + if ( -1 == a_info[a_idx].set) return (FALSE); + for (i = 0; i < s_ptr->num; i++) + if (a_idx == s_ptr->arts[i].a_idx) break; + if (!s_ptr->arts[i].present) + { + s_ptr->num_use++; + s_ptr->arts[i].present = TRUE; + if (s_ptr->num_use > s_ptr->num) msg_print("ERROR!! s_ptr->num_use > s_ptr->use"); + else if ((s_ptr->num_use == s_ptr->num) && (!silent)) cmsg_format(TERM_GREEN, "%s item set completed.", s_ptr->name + set_name); + return (TRUE); + } + return (FALSE); +} + +bool_ takeoff_set(s16b a_idx, s16b set_idx) +{ + set_type *s_ptr = &set_info[set_idx]; + int i; + + if ( -1 == a_info[a_idx].set) return (FALSE); + for (i = 0; i < s_ptr->num; i++) + if (a_idx == s_ptr->arts[i].a_idx) break; + + if (s_ptr->arts[i].present) + { + s_ptr->arts[i].present = FALSE; + s_ptr->num_use--; + + if (s_ptr->num_use == 255) msg_print("ERROR!! s_ptr->num_use < 0"); + if (s_ptr->num_use == s_ptr->num - 1) cmsg_format(TERM_GREEN, "%s item set not complete anymore.", s_ptr->name + set_name); + return (TRUE); + } + return (FALSE); +} + +bool_ apply_set(s16b a_idx, s16b set_idx) +{ + set_type *s_ptr = &set_info[set_idx]; + int i, j; + + if ( -1 == a_info[a_idx].set) return (FALSE); + for (i = 0; i < s_ptr->num; i++) + if (a_idx == s_ptr->arts[i].a_idx) break; + if (s_ptr->arts[i].present) + { + for (j = 0; j < s_ptr->num_use; j++) + { + apply_flags(s_ptr->arts[i].flags1[j], + s_ptr->arts[i].flags2[j], + s_ptr->arts[i].flags3[j], + s_ptr->arts[i].flags4[j], + s_ptr->arts[i].flags5[j], + s_ptr->arts[i].esp[j], + s_ptr->arts[i].pval[j], + 0, 0, 0, 0); + } + return (TRUE); + } + return (FALSE); +} + +bool_ apply_flags_set(s16b a_idx, s16b set_idx, + u32b *f1, u32b *f2, u32b *f3, u32b *f4, u32b *f5, u32b *esp) +{ + set_type *s_ptr = &set_info[set_idx]; + int i, j; + + if ( -1 == a_info[a_idx].set) return (FALSE); + + for (i = 0; i < s_ptr->num; i++) + { + if (a_idx == s_ptr->arts[i].a_idx) break; + } + + if (s_ptr->arts[i].present) + { + for (j = 0; j < s_ptr->num_use; j++) + { + (*f1) |= s_ptr->arts[i].flags1[j]; + (*f2) |= s_ptr->arts[i].flags2[j]; + (*f3) |= s_ptr->arts[i].flags3[j]; + (*f4) |= s_ptr->arts[i].flags4[j]; + (*f5) |= s_ptr->arts[i].flags5[j]; + (*esp) |= s_ptr->arts[i].esp[j]; + } + return (TRUE); + } + return (FALSE); +} + + + + + -- cgit v1.2.3 From 269859b90eb98667105f2dc7c2fbd92c96d866f2 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sun, 8 Sep 2013 21:57:44 +0200 Subject: Remove old-style HOOK_GET support --- src/object1.cc | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 2a555581..4fb3e553 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -6149,10 +6149,6 @@ void object_pickup(int this_o_idx) /* Pick up object */ else { - /* Tell the scripts */ - if (process_hooks(HOOK_GET, "(O,d)", o_ptr, this_o_idx)) - return; - /* Hooks */ { hook_get_in in = { o_ptr, this_o_idx }; -- cgit v1.2.3 From ca71ccff098e4eec97480d2a08773a06629cc66e Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Thu, 26 Jun 2014 06:50:06 +0200 Subject: Simplify PR_* redraw code and remove direct references to Term members --- src/object1.cc | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 4fb3e553..5d819f5f 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -4613,8 +4613,10 @@ void show_inven_aux(bool_ mirror, bool_ everything) /* Shadow windows */ if (mirror) { + int hgt; + Term_get_size(nullptr, &hgt); /* Erase the rest of the window */ - for (j = row + k; j < Term->hgt; j++) + for (j = row + k; j < hgt; j++) { /* Erase the line */ Term_erase(0, j, 255); @@ -4849,8 +4851,10 @@ void show_equip_aux(bool_ mirror, bool_ everything) /* Shadow windows */ if (mirror) { + int hgt; + Term_get_size(nullptr, &hgt); /* Erase the rest of the window */ - for (j = row + k; j < Term->hgt; j++) + for (j = row + k; j < hgt; j++) { /* Erase the line */ Term_erase(0, j, 255); @@ -6029,7 +6033,7 @@ int wear_ammo(object_type *o_ptr) p_ptr->update |= (PU_MANA); /* Redraw monster hitpoint */ - p_ptr->redraw |= (PR_MH); + p_ptr->redraw |= (PR_FRAME); /* Window stuff */ p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER); @@ -6263,7 +6267,7 @@ void py_pickup_floor(int pickup) p_ptr->au += o_ptr->pval; /* Redraw gold */ - p_ptr->redraw |= (PR_GOLD); + p_ptr->redraw |= (PR_FRAME); /* Window stuff */ p_ptr->window |= (PW_PLAYER); -- cgit v1.2.3 From 25f27454b680ae37439ef2f573988f74ebbb90e6 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 2 Jul 2014 18:55:11 +0200 Subject: Remove graphics support --- src/object1.cc | 61 ++-------------------------------------------------------- 1 file changed, 2 insertions(+), 59 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 5d819f5f..54fa596b 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -681,7 +681,7 @@ void flavor_init(void) * flag. This is useful for switching "graphics" on/off. * * The features, objects, and monsters, should all be encoded in the - * relevant "font.pref" and/or "graf.prf" files. XXX XXX XXX + * relevant "font.pref". XXX XXX XXX * * The "prefs" parameter is no longer meaningful. XXX XXX XXX */ @@ -760,65 +760,8 @@ void reset_visuals(void) } - if (use_graphics) - { - /* Process "graf.prf" */ - process_pref_file("graf.prf"); - - /* - * Hack -- remember graphics mode as an integer value, - * for faster processing of map_info() - */ - - /* IBM-PC pseudo-graphics -- not maintained, but the code is there */ - if (streq(ANGBAND_SYS, "ibm")) - { - graphics_mode = GRAPHICS_IBM; - } - - /* - * Isometric view. Also assumes all the attributes of the "new" - * graphics. - */ - else if (streq(ANGBAND_GRAF, "iso")) - { - graphics_mode = GRAPHICS_ISO; - } - - /* - * "New" graphics -- supports graphics overlay for traps, ego monsters - * and player subraces, and has tiles for lighting effects (row + 1 - * and row + 2 for "darker" versions of terrain features) - */ - else if (streq(ANGBAND_GRAF, "new")) - { - graphics_mode = GRAPHICS_NEW; - } - - /* - * "Old" graphics -- doesn't support graphics overlay and lighting - * effects - */ - else if (streq(ANGBAND_GRAF, "old")) - { - graphics_mode = GRAPHICS_OLD; - } - - /* ??? */ - else - { - graphics_mode = GRAPHICS_UNKNOWN; - } - } - /* Normal symbols */ - else - { - /* Process "font.prf" */ - process_pref_file("font.prf"); - - graphics_mode = GRAPHICS_NONE; - } + process_pref_file("font.prf"); } -- cgit v1.2.3 From c315b41d8fd2ee37a36eaaafec10994623392df3 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Tue, 23 Dec 2014 11:58:47 +0100 Subject: Rework spell_type_description_foreach to use lambdas --- src/object1.cc | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 54fa596b..6c051c67 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -14,6 +14,7 @@ #include "quark.h" #include "spell_type.h" +#include "spell_type.hpp" #include "hooks.h" /* @@ -2745,15 +2746,6 @@ void display_ammo_damage(object_type *o_ptr) } } -/* - * Output spell description - */ -static void print_device_desc_callback(void *data, cptr text) -{ - text_out("\n"); - text_out(text); -} - /* * Describe a magic stick powers */ @@ -2769,8 +2761,10 @@ void describe_device(object_type *o_ptr) text_out("\nSpell description:\n"); spell_type_description_foreach(spell_at(o_ptr->pval2), - print_device_desc_callback, - NULL); + [] (std::string const &text) -> void { + text_out("\n"); + text_out(text.c_str()); + }); text_out("\nSpell level: "); sprintf(buf, FMTs32b, get_level(o_ptr->pval2, 50, 0)); -- cgit v1.2.3 From aab1ab37bcc0f02a57c1559ff02bd7f4d8d42fca Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Fri, 19 Dec 2014 01:16:48 +0100 Subject: Remove unused HOOK_WIELD_SLOT --- src/object1.cc | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 6c051c67..7b54d5ee 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -3935,10 +3935,6 @@ int get_slot(int slot) */ s16b wield_slot_ideal(object_type *o_ptr, bool_ ideal) { - /* Try for a script first */ - if (process_hooks_ret(HOOK_WIELD_SLOT, "d", "(O,d)", o_ptr, ideal)) - return process_hooks_return[0].num; - /* Theme has restrictions for winged races. */ if (game_module_idx == MODULE_THEME) { -- cgit v1.2.3 From 8bd2ec1ea3385e53dcf8aad90e32498a622ed0b1 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sun, 21 Dec 2014 15:35:29 +0100 Subject: Remove unused HOOK_ITEM_NAME --- src/object1.cc | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 7b54d5ee..e83bb9aa 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -1617,18 +1617,8 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) /* Used in the "inventory" routine */ default: { - if (process_hooks_ret(HOOK_ITEM_NAME, "ss", "(O,s,s)", - o_ptr, basenm, modstr)) - { - basenm = process_hooks_return[0].str; - modstr = process_hooks_return[1].str; - break; - } - else - { - strcpy(buf, "(nothing)"); - return; - } + strcpy(buf, "(nothing)"); + return; } } -- cgit v1.2.3 From 7533517d633336e9a6b3edd261974ac788198acb Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sun, 21 Dec 2014 15:36:37 +0100 Subject: Remove unused HOOK_ACTIVATE_DESC --- src/object1.cc | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index e83bb9aa..e53f1cf3 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -2515,9 +2515,6 @@ cptr item_activation(object_type *o_ptr, byte num) } } - if (process_hooks_ret(HOOK_ACTIVATE_DESC, "s", "(O)", o_ptr)) - return (process_hooks_return[0].str); - return activation_aux(o_ptr, FALSE, 0); } -- cgit v1.2.3 From 19b1a6f409dcc25b922c2a917155bfd8a66cf599 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Tue, 23 Dec 2014 10:46:20 +0100 Subject: Remove dead get_table_name() and its data file --- src/object1.cc | 33 --------------------------------- 1 file changed, 33 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index e53f1cf3..fccea302 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -339,39 +339,6 @@ static bool_ object_flavor(int k_idx) } -void get_table_name(char *out_string) -{ - int testcounter = (randint(3)) + 1; - - strcpy(out_string, "'"); - - if (randint(3) == 2) - { - while (testcounter--) - strcat(out_string, syllables[(randint(MAX_SYLLABLES)) - 1]); - } - - else - { - char Syllable[80]; - testcounter = (randint(2)) + 1; - while (testcounter--) - { - get_rnd_line("elvish.txt", Syllable); - strcat(out_string, Syllable); - } - } - - out_string[1] = toupper(out_string[1]); - - strcat(out_string, "'"); - - out_string[18] = '\0'; - - return; -} - - /* * Certain items, if aware, are known instantly * This function is used only by "flavor_init()" -- cgit v1.2.3 From 8b9a7c687a215f38fbcec0e5ea75d00493c3fea6 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Tue, 23 Dec 2014 10:46:40 +0100 Subject: Fix signature of object_flavor --- src/object1.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index fccea302..4dc266f5 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -280,7 +280,7 @@ static byte scroll_col[MAX_TITLES]; * Certain items have a flavor * This function is used only by "flavor_init()" */ -static bool_ object_flavor(int k_idx) +static byte object_flavor(int k_idx) { object_kind *k_ptr = &k_info[k_idx]; -- cgit v1.2.3 From 0b74fd491aeda33e25a20986f40f6c461fb20f06 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:55 +0100 Subject: Split spell_chance into device and book variants The code calling spell_chance() always actually knows which kind of spell its looking at, so we might as well exploit that. --- src/object1.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 4dc266f5..e3f29bd3 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -11,7 +11,7 @@ */ #include "angband.h" - +#include "lua_bind.hpp" #include "quark.h" #include "spell_type.h" #include "spell_type.hpp" @@ -2728,7 +2728,7 @@ void describe_device(object_type *o_ptr) text_out_c(TERM_L_BLUE, format("%d", spell_type_skill_level(spell_at(o_ptr->pval2)))); text_out("\nSpell fail: "); - sprintf(buf, FMTs32b, spell_chance(o_ptr->pval2)); + sprintf(buf, FMTs32b, spell_chance_device(o_ptr->pval2)); text_out_c(TERM_GREEN, buf); text_out("\nSpell info: "); -- cgit v1.2.3 From 692699f064b2d792b61a5aa448b6844e8c713248 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:55 +0100 Subject: Change spell_chance_device parameter to use spell_type pointer There's no need to go through the extra indirection of the spell list. --- src/object1.cc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index e3f29bd3..96f01517 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -2713,8 +2713,11 @@ void describe_device(object_type *o_ptr) /* Enter device mode */ set_stick_mode(o_ptr); + // Spell reference + auto spell = spell_at(o_ptr->pval2); + text_out("\nSpell description:\n"); - spell_type_description_foreach(spell_at(o_ptr->pval2), + spell_type_description_foreach(spell, [] (std::string const &text) -> void { text_out("\n"); text_out(text.c_str()); @@ -2725,14 +2728,14 @@ void describe_device(object_type *o_ptr) text_out_c(TERM_L_BLUE, buf); text_out("\nMinimum Magic Device level to increase spell level: "); - text_out_c(TERM_L_BLUE, format("%d", spell_type_skill_level(spell_at(o_ptr->pval2)))); + text_out_c(TERM_L_BLUE, format("%d", spell_type_skill_level(spell))); text_out("\nSpell fail: "); - sprintf(buf, FMTs32b, spell_chance_device(o_ptr->pval2)); + sprintf(buf, FMTs32b, spell_chance_device(spell)); text_out_c(TERM_GREEN, buf); text_out("\nSpell info: "); - text_out_c(TERM_YELLOW, spell_type_info(spell_at(o_ptr->pval2))); + text_out_c(TERM_YELLOW, spell_type_info(spell)); /* Leave device mode */ unset_stick_mode(); -- cgit v1.2.3 From 7d6273cfbbc9717c30792817824b5511f7aee05f Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:55 +0100 Subject: Consolide the two spell_type headers --- src/object1.cc | 1 - 1 file changed, 1 deletion(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 96f01517..b6677850 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -13,7 +13,6 @@ #include "angband.h" #include "lua_bind.hpp" #include "quark.h" -#include "spell_type.h" #include "spell_type.hpp" #include "hooks.h" -- cgit v1.2.3 From ebb2771875ec2fffd7c63ee138024e6ebc47ebf8 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:55 +0100 Subject: Move school_spells array to spells5.cc --- src/object1.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index b6677850..9fef5eaf 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -15,6 +15,7 @@ #include "quark.h" #include "spell_type.hpp" #include "hooks.h" +#include "spells5.hpp" /* * Hack -- note that "TERM_MULTI" is now just "TERM_VIOLET". -- cgit v1.2.3 From 96df8c0a3e61d38507f26d74105a14541cc9d61c Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:56 +0100 Subject: Remove exp_need option; behave as if always set --- src/object1.cc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 9fef5eaf..2ec915de 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -1944,16 +1944,15 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) if ((f4 & TR4_LEVELS) && known) { t = object_desc_str(t, " (E:"); - if (exp_need) + if (o_ptr->elevel < PY_MAX_LEVEL) { - s32b need; /* Formula from check_experience_obj(). */ - need = player_exp[o_ptr->elevel - 1] * 5 / 2; + s32b need = player_exp[o_ptr->elevel - 1] * 5 / 2; t = object_desc_num(t, need - o_ptr->exp); } else { - t = object_desc_num(t, o_ptr->exp); + t = object_desc_str(t, "*****"); } t = object_desc_str(t, ", L:"); t = object_desc_num(t, o_ptr->elevel); -- cgit v1.2.3 From 65cf7c8566d814e0564ef86db698bd52fc6bc788 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:56 +0100 Subject: Remove option plain_descriptions --- src/object1.cc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 2ec915de..9e01eebd 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -1309,7 +1309,7 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) modstr = amulet_adj[indexx]; if (aware) append_name = TRUE; - if (((plain_descriptions) && (aware)) || o_ptr->ident & IDENT_STOREB) + if (aware || o_ptr->ident & IDENT_STOREB) basenm = "& Amulet~"; else basenm = aware ? "& # Amulet~" : "& # Amulet~"; @@ -1326,7 +1326,7 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) modstr = ring_adj[indexx]; if (aware) append_name = TRUE; - if (((plain_descriptions) && (aware)) || o_ptr->ident & IDENT_STOREB) + if (aware || o_ptr->ident & IDENT_STOREB) basenm = "& Ring~"; else basenm = aware ? "& # Ring~" : "& # Ring~"; @@ -1344,7 +1344,7 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) /* Color the object */ modstr = staff_adj[o_ptr->pval2 % MAX_WOODS]; if (aware) append_name = TRUE; - if (((plain_descriptions) && (aware)) || o_ptr->ident & IDENT_STOREB) + if (aware || o_ptr->ident & IDENT_STOREB) basenm = "& Staff~"; else basenm = "& # Staff~"; @@ -1356,7 +1356,7 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) /* Color the object */ modstr = wand_adj[o_ptr->pval2 % MAX_METALS]; if (aware) append_name = TRUE; - if (((plain_descriptions) && (aware)) || o_ptr->ident & IDENT_STOREB) + if (aware || o_ptr->ident & IDENT_STOREB) basenm = "& Wand~"; else basenm = "& # Wand~"; @@ -1368,7 +1368,7 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) /* Color the object */ modstr = rod_adj[indexx]; if (aware) append_name = TRUE; - if (((plain_descriptions) && (aware)) || o_ptr->ident & IDENT_STOREB) + if (aware || o_ptr->ident & IDENT_STOREB) basenm = "& Rod Tip~"; else basenm = aware ? "& # Rod Tip~" : "& # Rod Tip~"; @@ -1393,7 +1393,7 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) /* Color the object */ modstr = scroll_adj[indexx]; if (aware) append_name = TRUE; - if (((plain_descriptions) && (aware)) || o_ptr->ident & IDENT_STOREB) + if (aware || o_ptr->ident & IDENT_STOREB) basenm = "& Scroll~"; else basenm = aware ? "& Scroll~ titled \"#\"" : "& Scroll~ titled \"#\""; @@ -1413,7 +1413,7 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) { modstr = get_mimic_name(o_ptr->pval2); } - if (((plain_descriptions) && (aware)) || o_ptr->ident & IDENT_STOREB) + if (aware || o_ptr->ident & IDENT_STOREB) basenm = "& Potion~"; else basenm = aware ? "& # Potion~" : "& # Potion~"; @@ -1428,7 +1428,7 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) /* Color the object */ modstr = food_adj[indexx]; if (aware) append_name = TRUE; - if (((plain_descriptions) && (aware)) || o_ptr->ident & IDENT_STOREB) + if (aware || o_ptr->ident & IDENT_STOREB) basenm = "& Mushroom~"; else basenm = aware ? "& # Mushroom~" : "& # Mushroom~"; -- cgit v1.2.3 From c4746c0f6d328baa429c96e54d86d2d7f97ccbcc Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:57 +0100 Subject: Remove r_name, r_text, r_head in favor of simple strings --- src/object1.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 9e01eebd..fe38d081 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -1497,9 +1497,9 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) monster_race* r_ptr = &r_info[o_ptr->pval2]; modstr = basenm; if (r_ptr->flags1 & RF1_UNIQUE) - basenm = format("& %s's #~", r_name + r_ptr->name); + basenm = format("& %s's #~", r_ptr->name); else - basenm = format("& %s #~", r_name + r_ptr->name); + basenm = format("& %s #~", r_ptr->name); break; } @@ -1508,7 +1508,7 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) monster_race* r_ptr = &r_info[o_ptr->pval2]; modstr = basenm; - basenm = format("& %s #~", r_name + r_ptr->name); + basenm = format("& %s #~", r_ptr->name); break; } @@ -1517,7 +1517,7 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) /* We print hit points further down. --dsb */ monster_race* r_ptr = &r_info[o_ptr->pval]; modstr = basenm; - basenm = format("& %s~", r_name + r_ptr->name); + basenm = format("& %s~", r_ptr->name); break; } -- cgit v1.2.3 From 4b6f8d810f5ad513bea8fada09be01dde0fd643c Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:57 +0100 Subject: Remove k_name, k_text, k_head in favor of simple strings --- src/object1.cc | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index fe38d081..34eb8ade 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -1234,7 +1234,7 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) indexx = o_ptr->sval; /* Extract default "base" string */ - basenm = (k_name + k_ptr->name); + basenm = k_ptr->name; /* Assume no "modifier" string */ modstr = ""; @@ -1314,7 +1314,10 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) else basenm = aware ? "& # Amulet~" : "& # Amulet~"; - if (known && !o_ptr->art_name && artifact_p(o_ptr)) basenm = k_ptr->name + k_name; + if (known && !o_ptr->art_name && artifact_p(o_ptr)) + { + basenm = k_ptr->name; + } break; } @@ -1334,7 +1337,10 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) /* Hack -- The One Ring */ if (!aware && (o_ptr->sval == SV_RING_POWER)) modstr = "Plain Gold"; - if (known && !o_ptr->art_name && artifact_p(o_ptr)) basenm = k_ptr->name + k_name; + if (known && !o_ptr->art_name && artifact_p(o_ptr)) + { + basenm = k_ptr->name; + } break; } @@ -1382,9 +1388,7 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) case TV_ROD_MAIN: { - object_kind *tip_ptr = &k_info[lookup_kind(TV_ROD, o_ptr->pval)]; - - modstr = k_name + tip_ptr->name; + modstr = k_info[lookup_kind(TV_ROD, o_ptr->pval)].name; break; } @@ -1573,7 +1577,7 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) case TV_DAEMON_BOOK: case TV_BOOK: { - basenm = k_name + k_ptr->name; + basenm = k_ptr->name; if (o_ptr->sval == 255) { modstr = spell_type_name(spell_at(o_ptr->pval)); @@ -1590,7 +1594,10 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) } /* Mega Hack */ - if ((!hack_name) && known && (k_ptr->flags5 & TR5_FULL_NAME)) basenm = (k_name + k_ptr->name); + if ((!hack_name) && known && (k_ptr->flags5 & TR5_FULL_NAME)) + { + basenm = k_ptr->name; + } /* Start dumping the result */ @@ -1860,7 +1867,9 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) } } else - t = object_desc_str(t, (k_name + k_ptr->name)); + { + t = object_desc_str(t, k_ptr->name); + } } /* Hack -- Append "Artifact" or "Special" names */ @@ -2457,8 +2466,8 @@ cptr item_activation(object_type *o_ptr, byte num) mana = o_ptr->pval2 >> 8; } sprintf(rspell[num], "runespell(%s, %s, %d) every %d turns", - k_info[lookup_kind(TV_RUNE1, gf)].name + k_name, - k_info[lookup_kind(TV_RUNE2, mod)].name + k_name, + k_info[lookup_kind(TV_RUNE1, gf)].name, + k_info[lookup_kind(TV_RUNE2, mod)].name, mana, mana * 5); return rspell[num]; } @@ -2827,7 +2836,7 @@ bool_ object_out_desc(object_type *o_ptr, FILE *fff, bool_ trim_down, bool_ wait { object_kind *k_ptr = &k_info[o_ptr->k_idx]; - text_out_c(TERM_ORANGE, k_text + k_ptr->text); + text_out_c(TERM_ORANGE, k_ptr->text); text_out("\n"); } -- cgit v1.2.3 From cbc6fe196f7205f3e5de8c14cba957dbd2e72890 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:57 +0100 Subject: Replace a_head, a_name, a_text with simple char * --- src/object1.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 34eb8ade..1abdf36b 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -1909,7 +1909,7 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) if (o_ptr->tval != TV_CORPSE) { t = object_desc_chr(t, ' '); - t = object_desc_str(t, (a_name + a_ptr->name)); + t = object_desc_str(t, a_ptr->name); } } @@ -2844,7 +2844,7 @@ bool_ object_out_desc(object_type *o_ptr, FILE *fff, bool_ trim_down, bool_ wait { artifact_type *a_ptr = &a_info[o_ptr->name1]; - text_out_c(TERM_YELLOW, a_text + a_ptr->text); + text_out_c(TERM_YELLOW, a_ptr->text); text_out("\n"); if (a_ptr->set != -1) -- cgit v1.2.3 From e6d0a04ee4231400fe9cd4037bf89e2985a18bf3 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:58 +0100 Subject: Remove e_name, e_text, e_head --- src/object1.cc | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 1abdf36b..6346a492 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -1620,11 +1620,11 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) if (e_ptr->before) { - ego = e_ptr->name + e_name; + ego = e_ptr->name; } else if (e2_ptr->before) { - ego = e2_ptr->name + e_name; + ego = e2_ptr->name; } } @@ -1701,12 +1701,12 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) if (e_ptr->before) { - t = object_desc_str(t, (e_name + e_ptr->name)); + t = object_desc_str(t, e_ptr->name); t = object_desc_chr(t, ' '); } if (e2_ptr->before) { - t = object_desc_str(t, (e_name + e2_ptr->name)); + t = object_desc_str(t, e2_ptr->name); t = object_desc_chr(t, ' '); } } @@ -1779,12 +1779,12 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) if (e_ptr->before) { - t = object_desc_str(t, (e_name + e_ptr->name)); + t = object_desc_str(t, e_ptr->name); t = object_desc_chr(t, ' '); } if (e2_ptr->before) { - t = object_desc_str(t, (e_name + e2_ptr->name)); + t = object_desc_str(t, e2_ptr->name); t = object_desc_chr(t, ' '); } } @@ -1825,8 +1825,7 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) if (known && o_ptr->name2) { ego_item_type *e_ptr = &e_info[o_ptr->name2]; - - t = object_desc_str(t, (e_name + e_ptr->name)); + t = object_desc_str(t, e_ptr->name); } } @@ -1922,12 +1921,12 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) if (o_ptr->name2 && !e_ptr->before) { t = object_desc_chr(t, ' '); - t = object_desc_str(t, (e_name + e_ptr->name)); + t = object_desc_str(t, e_ptr->name); } if (o_ptr->name2b && !e2_ptr->before) { t = object_desc_chr(t, ' '); - t = object_desc_str(t, (e_name + e2_ptr->name)); + t = object_desc_str(t, e2_ptr->name); } } } -- cgit v1.2.3 From de5ee3b24f035efe3da8260687200109302f350a Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:58 +0100 Subject: Remove d_head, d_name, d_text --- src/object1.cc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 6346a492..85328bfe 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -2763,15 +2763,25 @@ static cptr object_out_desc_where_found(s16b level, s16b dungeon) static char str[80]; if (dungeon == DUNGEON_WILDERNESS) + { /* Taking care of older objects */ if (level == 0) + { sprintf(str, "in the wilderness or in a town"); + } else if (wf_info[level].terrain_idx == TERRAIN_TOWN) + { sprintf(str, "in the town of %s", wf_info[level].name + wf_name); + } else + { sprintf(str, "in %s", wf_info[level].text + wf_text); + } + } else - sprintf(str, "on level %d of %s", level, d_info[dungeon].name + d_name); + { + sprintf(str, "on level %d of %s", level, d_info[dungeon].name); + } return str; } -- cgit v1.2.3 From caa23251d8b279529330641032c62f8640ee13ff Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:58 +0100 Subject: Remove rp_head, rp_name, rp_text, rmp_head, rmp_name, rmp_text --- src/object1.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 85328bfe..dacf1b93 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -3912,7 +3912,7 @@ s16b wield_slot_ideal(object_type *o_ptr, bool_ ideal) /* Theme has restrictions for winged races. */ if (game_module_idx == MODULE_THEME) { - cptr race_name = rp_ptr->title + rp_name; + cptr race_name = rp_ptr->title; if (streq(race_name, "Dragon") || streq(race_name, "Eagle")) -- cgit v1.2.3 From 560ebe18ecf165dcfffa2d57870f01f1099be44c Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:58 +0100 Subject: Remove set_head, set_name, set_text --- src/object1.cc | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index dacf1b93..cffd1f84 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -17,6 +17,8 @@ #include "hooks.h" #include "spells5.hpp" +#include + /* * Hack -- note that "TERM_MULTI" is now just "TERM_VIOLET". * We will have to find a cleaner method for "MULTI_HUED" later. @@ -2858,9 +2860,7 @@ bool_ object_out_desc(object_type *o_ptr, FILE *fff, bool_ trim_down, bool_ wait if (a_ptr->set != -1) { - set_type *set_ptr = &set_info[a_ptr->set]; - - text_out_c(TERM_GREEN, set_text + set_ptr->desc); + text_out_c(TERM_GREEN, set_info[a_ptr->set].desc); text_out("\n"); } } @@ -6514,8 +6514,14 @@ bool_ wield_set(s16b a_idx, s16b set_idx, bool_ silent) { s_ptr->num_use++; s_ptr->arts[i].present = TRUE; - if (s_ptr->num_use > s_ptr->num) msg_print("ERROR!! s_ptr->num_use > s_ptr->use"); - else if ((s_ptr->num_use == s_ptr->num) && (!silent)) cmsg_format(TERM_GREEN, "%s item set completed.", s_ptr->name + set_name); + if (s_ptr->num_use > s_ptr->num) + { + msg_print("ERROR!! s_ptr->num_use > s_ptr->use"); + } + else if ((s_ptr->num_use == s_ptr->num) && (!silent)) + { + cmsg_format(TERM_GREEN, "%s item set completed.", s_ptr->name); + } return (TRUE); } return (FALSE); @@ -6533,10 +6539,15 @@ bool_ takeoff_set(s16b a_idx, s16b set_idx) if (s_ptr->arts[i].present) { s_ptr->arts[i].present = FALSE; + + assert(s_ptr->num_use > 0); s_ptr->num_use--; - if (s_ptr->num_use == 255) msg_print("ERROR!! s_ptr->num_use < 0"); - if (s_ptr->num_use == s_ptr->num - 1) cmsg_format(TERM_GREEN, "%s item set not complete anymore.", s_ptr->name + set_name); + if (s_ptr->num_use == s_ptr->num - 1) + { + cmsg_format(TERM_GREEN, "%s item set not complete anymore.", s_ptr->name); + } + return (TRUE); } return (FALSE); -- cgit v1.2.3 From e3405ca03eebafa60e773812c4f12fed7f4805db Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:58 +0100 Subject: Remove t_head, t_name, t_text --- src/object1.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index cffd1f84..2dae8303 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -2002,9 +2002,13 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) /* Describe the traps */ t = object_desc_str(t, " ("); if (t_info[o_ptr->pval].ident) - t = object_desc_str(t, t_name + t_info[o_ptr->pval].name); + { + t = object_desc_str(t, t_info[o_ptr->pval].name); + } else + { t = object_desc_str(t, "trapped"); + } t = object_desc_str(t, ")"); } } -- cgit v1.2.3 From 1ba4f05af61fbc1b65cf12d140bb4bce6c91e71d Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:58 +0100 Subject: Remove wf_head, wf_name, wf_text --- src/object1.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 2dae8303..3bf48663 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -2777,11 +2777,11 @@ static cptr object_out_desc_where_found(s16b level, s16b dungeon) } else if (wf_info[level].terrain_idx == TERRAIN_TOWN) { - sprintf(str, "in the town of %s", wf_info[level].name + wf_name); + sprintf(str, "in the town of %s", wf_info[level].name); } else { - sprintf(str, "in %s", wf_info[level].text + wf_text); + sprintf(str, "in %s", wf_info[level].text); } } else -- cgit v1.2.3 From c54c7ab7a45e1729bcd3a238cd296850ba91c55f Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:58 +0100 Subject: Remove st_head, st_name --- src/object1.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 3bf48663..d704272c 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -3773,12 +3773,12 @@ bool_ object_out_desc(object_type *o_ptr, FILE *fff, bool_ trim_down, bool_ wait else if (o_ptr->found == OBJ_FOUND_STORE) { text_out(format("\nYou bought it from the %s.", - st_info[o_ptr->found_aux1].name + st_name)); + st_info[o_ptr->found_aux1].name)); } else if (o_ptr->found == OBJ_FOUND_STOLEN) { text_out(format("\nYou stole it from the %s.", - st_info[o_ptr->found_aux1].name + st_name)); + st_info[o_ptr->found_aux1].name)); } else if (o_ptr->found == OBJ_FOUND_SELFMADE) { -- cgit v1.2.3 From 9670b948b8d1974ae3ec8212eec1773908c345c5 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:58 +0100 Subject: Move mimic.cc function delcarations into separate header --- src/object1.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index d704272c..5248bda4 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -16,6 +16,7 @@ #include "spell_type.hpp" #include "hooks.h" #include "spells5.hpp" +#include "mimic.hpp" #include -- cgit v1.2.3 From dc4b789acb2e6737dd6ed5721b3efbde1a2be14f Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:59 +0100 Subject: Move skills.cc function declarations to skills.hpp --- src/object1.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 5248bda4..b5344638 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -11,12 +11,13 @@ */ #include "angband.h" +#include "hooks.h" #include "lua_bind.hpp" +#include "mimic.hpp" #include "quark.h" +#include "skills.hpp" #include "spell_type.hpp" -#include "hooks.h" #include "spells5.hpp" -#include "mimic.hpp" #include @@ -4644,7 +4645,7 @@ void show_equip_aux(bool_ mirror, bool_ everything) if ((p_ptr->body_parts[i - INVEN_WIELD] == INVEN_WIELD) && !o_ptr->k_idx) { - sprintf(o_name, "(%s)", melee_names[get_melee_skill()]); + sprintf(o_name, "(%s)", get_melee_name()); /* Truncate the description */ o_name[lim] = 0; -- cgit v1.2.3 From c99c89cdde0b37fab35f6abe2ccf9169c6133cef Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:59 +0100 Subject: Move squeltch.cc function declarations to new include file --- src/object1.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index b5344638..90917459 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -18,6 +18,7 @@ #include "skills.hpp" #include "spell_type.hpp" #include "spells5.hpp" +#include "squeltch.hpp" #include -- cgit v1.2.3 From 63fae54381d0898503c5dc7f4dcfabc125c04807 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:59 +0100 Subject: Move xtra1.cc function declarations to separate header Make a couple of functions private to the module while we're at it. --- src/object1.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 90917459..fec6f1b2 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -19,6 +19,7 @@ #include "spell_type.hpp" #include "spells5.hpp" #include "squeltch.hpp" +#include "xtra1.hpp" #include -- cgit v1.2.3 From fe6ebd4af16244a02e16eb095181c0d8d5c56858 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:12:00 +0100 Subject: Move cave.cc function declarations to separate header --- src/object1.cc | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index fec6f1b2..492cd9dd 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -1,7 +1,3 @@ -/* File: object1.c */ - -/* Purpose: Object code, part 1 */ - /* * Copyright (c) 1989 James E. Wilson, Robert A. Koeneke * @@ -11,6 +7,7 @@ */ #include "angband.h" +#include "cave.hpp" #include "hooks.h" #include "lua_bind.hpp" #include "mimic.hpp" -- cgit v1.2.3 From f995c99cc4b7c0695b3642c8bbac06124874ffcb Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:12:00 +0100 Subject: Move cmd2.cc function declarations to separate header --- src/object1.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 492cd9dd..dc80962a 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -8,6 +8,7 @@ #include "angband.h" #include "cave.hpp" +#include "cmd2.hpp" #include "hooks.h" #include "lua_bind.hpp" #include "mimic.hpp" -- cgit v1.2.3 From b94e14c35d91ec5c99a208e9ddf84f81f9b84013 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:12:00 +0100 Subject: Move cmd6.cc function declarations to separate header file --- src/object1.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index dc80962a..b5b25c59 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -9,6 +9,7 @@ #include "angband.h" #include "cave.hpp" #include "cmd2.hpp" +#include "cmd6.hpp" #include "hooks.h" #include "lua_bind.hpp" #include "mimic.hpp" -- cgit v1.2.3 From a59d8968c3bf669790e15a6170577b92f36745b6 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:12:00 +0100 Subject: Remove dead declarations/code Tidy up scan_floor a little to avoid unused cases and parameters. --- src/object1.cc | 80 +++++++++++++++++++++++----------------------------------- 1 file changed, 31 insertions(+), 49 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index b5b25c59..5e62519d 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -2502,7 +2502,7 @@ cptr item_activation(object_type *o_ptr, byte num) } /* Grab the tval desc */ -bool_ grab_tval_desc(int tval) +static bool_ grab_tval_desc(int tval) { int tv = 0; @@ -3841,7 +3841,7 @@ char index_to_label(int i) * Convert a label into the index of an item in the "inven" * Return "-1" if the label does not indicate a real item */ -s16b label_to_inven(int c) +static s16b label_to_inven(int c) { int i; @@ -3863,7 +3863,7 @@ s16b label_to_inven(int c) * Convert a label into the index of a item in the "equip" * Return "-1" if the label does not indicate a real item */ -s16b label_to_equip(int c) +static s16b label_to_equip(int c) { int i; @@ -4108,7 +4108,7 @@ s16b wield_slot(object_type *o_ptr) /* * Return a string mentioning how a given item is carried */ -cptr mention_use(int i) +static cptr mention_use(int i) { cptr p; @@ -4974,61 +4974,46 @@ static int get_tag(int *cp, char tag) * scan_floor -- * * Return a list of o_list[] indexes of items at the given cave - * location. Valid flags are: - * - * mode & 0x01 -- Item tester - * mode & 0x02 -- Marked items only - * mode & 0x04 -- Stop after first + * location. */ -bool_ scan_floor(int *items, int *item_num, int y, int x, int mode) +static std::vector scan_floor(int y, int x) { int this_o_idx, next_o_idx; - - int num = 0; - - (*item_num) = 0; + std::vector items; /* Sanity */ - if (!in_bounds(y, x)) return (FALSE); + if (!in_bounds(y, x)) + { + return items; + } /* Scan all objects in the grid */ for (this_o_idx = cave[y][x].o_idx; this_o_idx; this_o_idx = next_o_idx) { - object_type * o_ptr; - /* Acquire object */ - o_ptr = &o_list[this_o_idx]; + object_type * o_ptr = &o_list[this_o_idx]; /* Acquire next object */ next_o_idx = o_ptr->next_o_idx; /* Item tester */ - if ((mode & 0x01) && !item_tester_okay(o_ptr)) continue; - - /* Marked */ - if ((mode & 0x02) && !o_ptr->marked) continue; + if (!item_tester_okay(o_ptr)) continue; /* Accept this item */ - items[num++] = this_o_idx; - - /* Only one */ - if (mode & 0x04) break; + items.push_back(this_o_idx); /* XXX Hack -- Enforce limit */ - if (num == 23) break; + if (items.size() == 23) break; } - /* Number of items */ - (*item_num) = num; - /* Result */ - return (num != 0); + return items; } /* * Display a list of the items on the floor at the given location. */ -void show_floor(int y, int x) +static void show_floor(int y, int x) { int i, j, k, l; int col, len, lim; @@ -5043,8 +5028,6 @@ void show_floor(int y, int x) byte out_color[23]; char out_desc[23][80]; - int floor_list[23], floor_num; - /* Default length */ len = 79 - 50; @@ -5055,7 +5038,9 @@ void show_floor(int y, int x) lim -= 9; /* Scan for objects in the grid, using item_tester_okay() */ - (void) scan_floor(floor_list, &floor_num, y, x, 0x01); + auto const floor_list = scan_floor(y, x); + assert(floor_list.size() <= 23); + int const floor_num = floor_list.size(); // "int" for warning avoidance /* Display the inventory */ for (k = 0, i = 0; i < floor_num; i++) @@ -5131,7 +5116,7 @@ void show_floor(int y, int x) * the easy_floor is on. */ bool_ (*get_item_extra_hook)(int *cp); -bool_ get_item_floor(int *cp, cptr pmt, cptr str, int mode) +static bool_ get_item_floor(int *cp, cptr pmt, cptr str, int mode) { char n1 = 0, n2 = 0, which = ' '; @@ -5156,7 +5141,7 @@ bool_ get_item_floor(int *cp, cptr pmt, cptr str, int mode) char tmp_val[160]; char out_val[160]; - int floor_num, floor_list[23], floor_top = 0; + int floor_top = 0; k = 0; @@ -5246,15 +5231,12 @@ bool_ get_item_floor(int *cp, cptr pmt, cptr str, int mode) while ((e1 <= e2) && (!get_item_okay(e2))) e2--; - /* Count "okay" floor items */ - floor_num = 0; - - /* Restrict floor usage */ - if (floor) - { - /* Scan all objects in the grid */ - (void) scan_floor(floor_list, &floor_num, p_ptr->py, p_ptr->px, 0x01); - } + /* Floor items? */ + auto const floor_list = + floor ? std::move(scan_floor(p_ptr->py, p_ptr->px)) + : std::vector(); + assert(floor_list.size() <= 23); + int const floor_num = floor_list.size(); // "int" for warning avoidance /* Accept inventory */ if (i1 <= i2) allow_inven = TRUE; @@ -5263,7 +5245,7 @@ bool_ get_item_floor(int *cp, cptr pmt, cptr str, int mode) if (e1 <= e2) allow_equip = TRUE; /* Accept floor */ - if (floor_num) allow_floor = TRUE; + if (!floor_list.empty()) allow_floor = TRUE; /* Require at least one legal choice */ if (!allow_inven && !allow_equip && !allow_floor) @@ -6307,7 +6289,7 @@ void py_pickup_floor(int pickup) } /* Add a flags group */ -void gain_flag_group(object_type *o_ptr, bool_ silent) +static void gain_flag_group(object_type *o_ptr, bool_ silent) { int grp = 0; int tries = 1000; @@ -6402,7 +6384,7 @@ u32b get_flag(object_type *o_ptr, int grp, int k) } /* Add a flags from a flag group */ -void gain_flag_group_flag(object_type *o_ptr, bool_ silent) +static void gain_flag_group_flag(object_type *o_ptr, bool_ silent) { int grp = 0, k = 0; u32b f = 0; -- cgit v1.2.3 From aba7dbda30fcc8be0fe129f065ce3e494b374c54 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:12:00 +0100 Subject: Remove dead code/flags --- src/object1.cc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 5e62519d..e33f2193 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -6289,7 +6289,7 @@ void py_pickup_floor(int pickup) } /* Add a flags group */ -static void gain_flag_group(object_type *o_ptr, bool_ silent) +static void gain_flag_group(object_type *o_ptr) { int grp = 0; int tries = 1000; @@ -6314,7 +6314,7 @@ static void gain_flag_group(object_type *o_ptr, bool_ silent) o_ptr->pval2 -= flags_groups[grp].price; o_ptr->pval3 |= BIT(grp); - if (!silent) + /* Message */ { char o_name[80]; @@ -6323,7 +6323,7 @@ static void gain_flag_group(object_type *o_ptr, bool_ silent) } } -u32b get_flag(object_type *o_ptr, int grp, int k) +static u32b get_flag(object_type *o_ptr, int grp, int k) { u32b f = 0, flag_set = 0; int tries = 1000; @@ -6384,7 +6384,7 @@ u32b get_flag(object_type *o_ptr, int grp, int k) } /* Add a flags from a flag group */ -static void gain_flag_group_flag(object_type *o_ptr, bool_ silent) +static void gain_flag_group_flag(object_type *o_ptr) { int grp = 0, k = 0; u32b f = 0; @@ -6431,7 +6431,7 @@ static void gain_flag_group_flag(object_type *o_ptr, bool_ silent) break; } - if (!silent) + /* Message */ { char o_name[80]; @@ -6468,13 +6468,13 @@ void object_gain_level(object_type *o_ptr) o_ptr->to_h += 1; o_ptr->pval2++; - if (magik(NEW_GROUP_CHANCE)) gain_flag_group(o_ptr, FALSE); + if (magik(NEW_GROUP_CHANCE)) gain_flag_group(o_ptr); } else { - if (!o_ptr->pval3) gain_flag_group(o_ptr, FALSE); + if (!o_ptr->pval3) gain_flag_group(o_ptr); - gain_flag_group_flag(o_ptr, FALSE); + gain_flag_group_flag(o_ptr); if (!o_ptr->pval) o_ptr->pval = 1; else -- cgit v1.2.3 From 37ac44add61e4547507770017dcb85b53c20acb5 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:12:01 +0100 Subject: Split util.cc function declarations into separate header files We need one .h file and one .hpp since some of the functions are being called from plain C code. --- src/object1.cc | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index e33f2193..2f4ddf79 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -18,6 +18,8 @@ #include "spell_type.hpp" #include "spells5.hpp" #include "squeltch.hpp" +#include "util.hpp" +#include "util.h" #include "xtra1.hpp" #include -- cgit v1.2.3 From 85f1b7d97f1612c70edd774bfd9cf8b75c0b6c39 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 7 Mar 2015 16:55:40 +0100 Subject: Split monster1.cc declarations to separate header --- src/object1.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 2f4ddf79..8bbdac82 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -13,6 +13,7 @@ #include "hooks.h" #include "lua_bind.hpp" #include "mimic.hpp" +#include "monster1.hpp" #include "quark.h" #include "skills.hpp" #include "spell_type.hpp" -- cgit v1.2.3 From d379c47aaec011921c1d09140ee1098a7053b5b6 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 7 Mar 2015 16:55:40 +0100 Subject: Split monster2.cc declarations into separate header --- src/object1.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 8bbdac82..e02ad50d 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -14,6 +14,7 @@ #include "lua_bind.hpp" #include "mimic.hpp" #include "monster1.hpp" +#include "monster2.hpp" #include "quark.h" #include "skills.hpp" #include "spell_type.hpp" -- cgit v1.2.3 From 7bdfa1a20c8921e53baecdd12b48870417f8b426 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 7 Mar 2015 16:55:40 +0100 Subject: Split files.cc declarations into separate header files --- src/object1.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index e02ad50d..bf2a682f 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -10,6 +10,7 @@ #include "cave.hpp" #include "cmd2.hpp" #include "cmd6.hpp" +#include "files.hpp" #include "hooks.h" #include "lua_bind.hpp" #include "mimic.hpp" -- cgit v1.2.3 From 5a1497b285b2aaad6c8945b9014c5ccd899af695 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 7 Mar 2015 16:55:40 +0100 Subject: Split dungeon.cc declarations into separate header files --- src/object1.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index bf2a682f..36081a57 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -10,6 +10,7 @@ #include "cave.hpp" #include "cmd2.hpp" #include "cmd6.hpp" +#include "dungeon.hpp" #include "files.hpp" #include "hooks.h" #include "lua_bind.hpp" -- cgit v1.2.3 From cfc0a04155eda35a4fe80ef72fd2b0f9eb10856b Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 7 Mar 2015 16:55:41 +0100 Subject: Split object*.cc declarations into separate header files --- src/object1.cc | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 36081a57..f1ec9136 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -6,6 +6,8 @@ * included in all such copies. */ +#include "object1.hpp" + #include "angband.h" #include "cave.hpp" #include "cmd2.hpp" @@ -17,6 +19,7 @@ #include "mimic.hpp" #include "monster1.hpp" #include "monster2.hpp" +#include "object2.hpp" #include "quark.h" #include "skills.hpp" #include "spell_type.hpp" @@ -28,6 +31,9 @@ #include +static bool_ apply_flags_set(s16b a_idx, s16b set_idx, + u32b *f1, u32b *f2, u32b *f3, u32b *f4, u32b *f5, u32b *esp); + /* * Hack -- note that "TERM_MULTI" is now just "TERM_VIOLET". * We will have to find a cleaner method for "MULTI_HUED" later. @@ -2725,7 +2731,7 @@ void display_ammo_damage(object_type *o_ptr) /* * Describe a magic stick powers */ -void describe_device(object_type *o_ptr) +static void describe_device(object_type *o_ptr) { char buf[128]; @@ -3890,7 +3896,7 @@ static s16b label_to_equip(int c) * Returns the next free slot of the given "type", return the first * if all are used */ -int get_slot(int slot) +static int get_slot(int slot) { int i = 0; @@ -6574,7 +6580,7 @@ bool_ apply_set(s16b a_idx, s16b set_idx) return (FALSE); } -bool_ apply_flags_set(s16b a_idx, s16b set_idx, +static bool_ apply_flags_set(s16b a_idx, s16b set_idx, u32b *f1, u32b *f2, u32b *f3, u32b *f4, u32b *f5, u32b *esp) { set_type *s_ptr = &set_info[set_idx]; -- cgit v1.2.3 From 72ceb4f2aba3b86be43ba9a7cb5c576b79920543 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 7 Mar 2015 16:55:41 +0100 Subject: Split option variables into separate header and source file Remove unused testing_stack testing_carry options while we're at it. --- src/object1.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index f1ec9136..5d1e80f4 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -20,6 +20,7 @@ #include "monster1.hpp" #include "monster2.hpp" #include "object2.hpp" +#include "options.hpp" #include "quark.h" #include "skills.hpp" #include "spell_type.hpp" -- cgit v1.2.3 From f93c700dc8320da438ad46b59b2541e29d9b6d68 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 7 Mar 2015 16:55:42 +0100 Subject: Split tables.cc declarations into separate header files --- src/object1.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 5d1e80f4..4280e88a 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -26,6 +26,7 @@ #include "spell_type.hpp" #include "spells5.hpp" #include "squeltch.hpp" +#include "tables.hpp" #include "util.hpp" #include "util.h" #include "xtra1.hpp" -- cgit v1.2.3 From 6f612c6e6cf9b20c00fd2f515d3694d2b7f7f444 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 7 Mar 2015 16:55:42 +0100 Subject: Split variables.cc declarations to separate header files - Can now remove externs.h. Yay! - Put a stray option variable into its rightful place in options.hpp --- src/object1.cc | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 4280e88a..93021cec 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -29,6 +29,8 @@ #include "tables.hpp" #include "util.hpp" #include "util.h" +#include "variable.h" +#include "variable.hpp" #include "xtra1.hpp" #include -- cgit v1.2.3 From 99a0478c7a943290ab4350d64688682dbb615f24 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 7 Mar 2015 16:55:42 +0100 Subject: Convert object-related macros from defines.h into functions --- src/object1.cc | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 93021cec..2e9f09ff 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -6613,7 +6613,106 @@ static bool_ apply_flags_set(s16b a_idx, s16b set_idx, return (FALSE); } +/* + * Return the "attr" for a given item. + * Use "flavor" if available. + * Default to user definitions. + */ + +byte object_attr(object_type const *o_ptr) +{ + if (o_ptr->tval == TV_RANDART) + { + return random_artifacts[o_ptr->sval].attr; + } + else if (k_info[o_ptr->k_idx].flavor) + { + return misc_to_attr[k_info[o_ptr->k_idx].flavor]; + } + else + { + return k_info[o_ptr->k_idx].x_attr; + } +} + +byte object_attr_default(object_type *o_ptr) +{ + if (o_ptr->tval == TV_RANDART) + { + return random_artifacts[o_ptr->sval].attr; + } + else if (k_info[o_ptr->k_idx].flavor) + { + return misc_to_attr[k_info[o_ptr->k_idx].flavor]; + } + else + { + return k_info[o_ptr->k_idx].d_attr; + } +} + +/* + * Return the "char" for a given item. + * Use "flavor" if available. + * Default to user definitions. + */ + +char object_char(object_type const *o_ptr) +{ + if (k_info[o_ptr->k_idx].flavor) + { + return misc_to_char[k_info[o_ptr->k_idx].flavor]; + } + else + { + return k_info[o_ptr->k_idx].x_char; + } +} +char object_char_default(object_type const *o_ptr) +{ + if (k_info[o_ptr->k_idx].flavor) + { + return misc_to_char[k_info[o_ptr->k_idx].flavor]; + } + else + { + return k_info[o_ptr->k_idx].d_char; + } +} +/** + * Is the given object an artifact? + */ +bool artifact_p(object_type const *o_ptr) +{ + return + (o_ptr->tval == TV_RANDART) || + (o_ptr->name1 ? true : false) || + (o_ptr->art_name ? true : false) || + ((k_info[o_ptr->k_idx].flags3 & TR3_NORM_ART) ? true : false); +} +/** + * Is the given object an ego item? + */ +bool ego_item_p(object_type const *o_ptr) +{ + return o_ptr->name2 || (o_ptr->name2b ? TRUE : FALSE); +} +/* + * Is the given object an ego item of the given type? + */ +bool is_ego_p(object_type const *o_ptr, s16b ego) +{ + return (o_ptr->name2 == ego) || (o_ptr->name2b == ego); +} + +/** + * Is the given object identified as cursed? + */ +bool cursed_p(object_type const *o_ptr) +{ + return o_ptr->ident & (IDENT_CURSED); +} -- cgit v1.2.3 From c17c9486a22ce9f2160b2d2ad559d9a19e453f83 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sun, 22 Mar 2015 15:22:02 +0100 Subject: Rename miscellaneous .h headers to .hpp --- src/object1.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 2e9f09ff..3c269c60 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -14,14 +14,14 @@ #include "cmd6.hpp" #include "dungeon.hpp" #include "files.hpp" -#include "hooks.h" +#include "hooks.hpp" #include "lua_bind.hpp" #include "mimic.hpp" #include "monster1.hpp" #include "monster2.hpp" #include "object2.hpp" #include "options.hpp" -#include "quark.h" +#include "quark.hpp" #include "skills.hpp" #include "spell_type.hpp" #include "spells5.hpp" -- cgit v1.2.3 From e8345c7da1e3b62dec011798a03d25c2f23f9d60 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Tue, 14 Apr 2015 06:39:21 +0200 Subject: Add a few "const" qualifiers to object-related functions --- src/object1.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 3c269c60..cb1a6604 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -757,7 +757,7 @@ void reset_visuals(void) /* * Extract "xtra" flags from object. */ -void object_flags_xtra(object_type *o_ptr, u32b *f2, u32b *f3, u32b *esp) +static void object_flags_xtra(object_type const *o_ptr, u32b *f2, u32b *f3, u32b *esp) { switch (o_ptr->xtra1) { @@ -874,7 +874,7 @@ void object_flags_xtra(object_type *o_ptr, u32b *f2, u32b *f3, u32b *esp) * Obtain the "flags" for an item */ bool_ object_flags_no_set = FALSE; -void object_flags(object_type *o_ptr, u32b *f1, u32b *f2, u32b *f3, u32b *f4, u32b *f5, u32b *esp) +void object_flags(object_type const *o_ptr, u32b *f1, u32b *f2, u32b *f3, u32b *f4, u32b *f5, u32b *esp) { object_kind *k_ptr = &k_info[o_ptr->k_idx]; @@ -960,7 +960,7 @@ int object_power(object_type *o_ptr) /* * Obtain the "flags" for an item which are known to the player */ -void object_flags_known(object_type *o_ptr, u32b *f1, u32b *f2, u32b *f3, u32b *f4, u32b *f5, u32b *esp) +void object_flags_known(object_type const *o_ptr, u32b *f1, u32b *f2, u32b *f3, u32b *f4, u32b *f5, u32b *esp) { object_kind *k_ptr = &k_info[o_ptr->k_idx]; @@ -3930,7 +3930,7 @@ static int get_slot(int slot) * Determine which equipment slot (if any) an item likes, ignoring the player's * current body and stuff if ideal == TRUE */ -s16b wield_slot_ideal(object_type *o_ptr, bool_ ideal) +s16b wield_slot_ideal(object_type const *o_ptr, bool_ ideal) { /* Theme has restrictions for winged races. */ if (game_module_idx == MODULE_THEME) @@ -4116,7 +4116,7 @@ s16b wield_slot_ideal(object_type *o_ptr, bool_ ideal) * Determine which equipment slot (if any) an item likes for the player's * current body and stuff */ -s16b wield_slot(object_type *o_ptr) +s16b wield_slot(object_type const *o_ptr) { return wield_slot_ideal(o_ptr, FALSE); } -- cgit v1.2.3 From a029d18b62794a44dbaf3530d1d20663287f3ce2 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Tue, 14 Apr 2015 06:39:21 +0200 Subject: Add pseudo-ID for items at player's feet It's a bit silly and tedious play-wise to force player to actually pick things up for pseudo-ID to kick in. --- src/object1.cc | 58 ++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 22 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index cb1a6604..25b848a0 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -4229,7 +4229,7 @@ static cptr mention_use(int i) */ cptr describe_use(int i) { - cptr p; + cptr p = nullptr; switch (i) { @@ -6113,48 +6113,57 @@ void object_pickup(int this_o_idx) void py_pickup_floor(int pickup) { - s16b this_o_idx, next_o_idx = 0; - - char o_name[80] = ""; - object_type *o_ptr = 0; - - int floor_num = 0, floor_o_idx = 0; - - bool_ do_pickup = TRUE; - - bool_ do_ask = TRUE; - /* Hack -- ignore monster traps */ if (cave[p_ptr->py][p_ptr->px].feat == FEAT_MON_TRAP) return; /* Try to grab ammo */ pickup_ammo(); + /* Build a list of the floor objects. */ + std::vector floor_object_idxs; + { + s16b this_o_idx = cave[p_ptr->py][p_ptr->px].o_idx; + /* Reserve a number of slots if at least one is needed */ + if (this_o_idx) + { + floor_object_idxs.reserve(16); // Avoid resizing in the common case + } + /* Fill in the indexes */ + for (; this_o_idx; this_o_idx = o_list[this_o_idx].next_o_idx) + { + // Note the "-"! We need it for get_object() + // lookups to function correctly. + floor_object_idxs.push_back(0 - this_o_idx); + } + } + /* Mega Hack -- If we have auto-Id, do an ID sweep *before* squleching, * so that we don't have to walk over things twice to get them * squelched. --dsb */ if (p_ptr->auto_id) { - this_o_idx = cave[p_ptr->py][p_ptr->px].o_idx; - - for (; this_o_idx; this_o_idx = next_o_idx) + for (auto const o_idx : floor_object_idxs) { - /* Aquire the object */ - o_ptr = &o_list[this_o_idx]; - - /* Acquire the next object index */ - next_o_idx = o_ptr->next_o_idx; - - /* Identify Object */ + object_type *o_ptr = get_object(o_idx); object_aware(o_ptr); object_known(o_ptr); } } + /* Sense floor tile */ + sense_objects(floor_object_idxs); + /* Squeltch the floor */ squeltch_grid(); /* Scan the pile of objects */ + s16b next_o_idx = 0; + char o_name[80] = ""; + object_type *o_ptr = 0; + int floor_num = 0; + int floor_o_idx = 0; + + s16b this_o_idx; for (this_o_idx = cave[p_ptr->py][p_ptr->px].o_idx; this_o_idx; this_o_idx = next_o_idx) { /* Acquire object */ @@ -6190,6 +6199,7 @@ void py_pickup_floor(int pickup) continue; } + /* Describe */ { char testdesc[80]; @@ -6234,6 +6244,10 @@ void py_pickup_floor(int pickup) return; } + /* Are we actually going to pick up and/or ask about which item to pick up? */ + bool_ do_pickup = TRUE; + bool_ do_ask = TRUE; + /* One item */ if (floor_num == 1) { -- cgit v1.2.3 From 8b2be5adc24ffdecc7bb5d8ed08be12a7590bc46 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 15 Apr 2015 19:12:41 +0200 Subject: Rework object list filters to avoid global variables --- src/object1.cc | 171 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 85 insertions(+), 86 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 25b848a0..fcbc35f8 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -49,6 +49,12 @@ static bool_ apply_flags_set(s16b a_idx, s16b set_idx, #define TERM_MULTI TERM_VIOLET +/** + * Show all equipment/inventory slots, even when empty? + */ +static bool item_tester_full; + + /* * Max sizes of the following arrays */ @@ -4327,45 +4333,42 @@ cptr describe_use(int i) /* * Check an item against the item tester info */ -bool_ item_tester_okay(object_type *o_ptr) +static bool item_tester_okay(object_type const *o_ptr, object_filter_t const &filter) { /* Hack -- allow listing empty slots */ - if (item_tester_full) return (TRUE); + if (item_tester_full) + { + return true; + } /* Require an item */ - if (!o_ptr->k_idx) return (FALSE); - - /* Hack -- ignore "gold" */ - if (o_ptr->tval == TV_GOLD) return (FALSE); - - /* Check the tval */ - if (item_tester_tval) + if (!o_ptr->k_idx) { - if (!(item_tester_tval == o_ptr->tval)) return (FALSE); + return false; } - /* Check the hook */ - if (item_tester_hook) + /* Hack -- ignore "gold" */ + if (o_ptr->tval == TV_GOLD) { - if (!(*item_tester_hook)(o_ptr)) return (FALSE); + return false; } - /* Assume okay */ - return (TRUE); + /* Check against the filter */ + return filter(o_ptr); } -void show_equip_aux(bool_ mirror, bool_ everything); -void show_inven_aux(bool_ mirror, bool_ everything); +static void show_equip_aux(bool_ mirror, bool_ everything, object_filter_t const &filter); +static void show_inven_aux(bool_ mirror, bool_ everything, object_filter_t const &filter); /* * Choice window "shadow" of the "show_inven()" function */ void display_inven(void) { - show_inven_aux(TRUE, inventory_no_move); + show_inven_aux(TRUE, inventory_no_move, object_filter::True()); } @@ -4375,7 +4378,7 @@ void display_inven(void) */ void display_equip(void) { - show_equip_aux(TRUE, inventory_no_move); + show_equip_aux(TRUE, inventory_no_move, object_filter::True()); } @@ -4402,7 +4405,7 @@ byte get_item_letter_color(object_type *o_ptr) * * Hack -- do not display "trailing" empty slots */ -void show_inven_aux(bool_ mirror, bool_ everything) +void show_inven_aux(bool_ mirror, bool_ everything, const object_filter_t &filter) { int i, j, k, l, z = 0; int row, col, len, lim; @@ -4454,7 +4457,7 @@ void show_inven_aux(bool_ mirror, bool_ everything) o_ptr = &p_ptr->inventory[i]; /* Is this item acceptable? */ - if (!item_tester_okay(o_ptr)) + if (!item_tester_okay(o_ptr, filter)) { if ( !everything ) continue; @@ -4562,20 +4565,34 @@ void show_inven_aux(bool_ mirror, bool_ everything) } -void show_inven() +static void show_inven(object_filter_t const &filter) { - show_inven_aux(FALSE, FALSE); + show_inven_aux(FALSE, FALSE, filter); } -void show_equip() +void show_inven_full() { - show_equip_aux(FALSE, FALSE); + item_tester_full = true; + show_inven(object_filter::True()); + item_tester_full = false; +} + +static void show_equip(object_filter_t const &filter) +{ + show_equip_aux(FALSE, FALSE, filter); +} + +void show_equip_full() +{ + item_tester_full = true; + show_equip(object_filter::True()); + item_tester_full = false; } /* * Display the equipment. */ -void show_equip_aux(bool_ mirror, bool_ everything) +void show_equip_aux(bool_ mirror, bool_ everything, object_filter_t const &filter) { int i, j, k, l; int row, col, len, lim, idx; @@ -4686,7 +4703,7 @@ void show_equip_aux(bool_ mirror, bool_ everything) /* Truncate the description */ o_name[lim] = 0; /* Is this item acceptable? */ - if (!item_tester_okay(o_ptr)) + if (!item_tester_okay(o_ptr, filter)) { if (!everything) continue; out_index[k] = -1; @@ -4911,16 +4928,16 @@ static bool_ get_item_allow(int item) /* * Auxiliary function for "get_item()" -- test an index */ -static bool_ get_item_okay(int i) +static bool get_item_okay(int i, object_filter_t const &filter) { /* Illegal items */ - if ((i < 0) || (i >= INVEN_TOTAL)) return (FALSE); + if ((i < 0) || (i >= INVEN_TOTAL)) + { + return (FALSE); + } /* Verify the item */ - if (!item_tester_okay(&p_ptr->inventory[i])) return (FALSE); - - /* Assume okay */ - return (TRUE); + return item_tester_okay(&p_ptr->inventory[i], filter); } @@ -4992,7 +5009,7 @@ static int get_tag(int *cp, char tag) * Return a list of o_list[] indexes of items at the given cave * location. */ -static std::vector scan_floor(int y, int x) +static std::vector scan_floor(int y, int x, object_filter_t const &filter) { int this_o_idx, next_o_idx; std::vector items; @@ -5013,7 +5030,10 @@ static std::vector scan_floor(int y, int x) next_o_idx = o_ptr->next_o_idx; /* Item tester */ - if (!item_tester_okay(o_ptr)) continue; + if (!item_tester_okay(o_ptr, filter)) + { + continue; + } /* Accept this item */ items.push_back(this_o_idx); @@ -5029,7 +5049,7 @@ static std::vector scan_floor(int y, int x) /* * Display a list of the items on the floor at the given location. */ -static void show_floor(int y, int x) +static void show_floor(int y, int x, object_filter_t const &filter) { int i, j, k, l; int col, len, lim; @@ -5054,7 +5074,7 @@ static void show_floor(int y, int x) lim -= 9; /* Scan for objects in the grid, using item_tester_okay() */ - auto const floor_list = scan_floor(y, x); + auto const floor_list = scan_floor(y, x, filter); assert(floor_list.size() <= 23); int const floor_num = floor_list.size(); // "int" for warning avoidance @@ -5131,8 +5151,7 @@ static void show_floor(int y, int x) * This version of get_item() is called by get_item() when * the easy_floor is on. */ -bool_ (*get_item_extra_hook)(int *cp); -static bool_ get_item_floor(int *cp, cptr pmt, cptr str, int mode) +static bool_ get_item_floor(int *cp, cptr pmt, cptr str, int mode, object_filter_t const &filter, select_by_name_t const &select_by_name) { char n1 = 0, n2 = 0, which = ' '; @@ -5145,7 +5164,6 @@ static bool_ get_item_floor(int *cp, cptr pmt, cptr str, int mode) bool_ equip = FALSE; bool_ inven = FALSE; bool_ floor = FALSE; - bool_ extra = FALSE; bool_ automat = FALSE; bool_ allow_equip = FALSE; @@ -5176,28 +5194,16 @@ static bool_ get_item_floor(int *cp, cptr pmt, cptr str, int mode) o_ptr = &o_list[k]; /* Validate the item */ - if (item_tester_okay(o_ptr)) + if (item_tester_okay(o_ptr, filter)) { - /* Forget the item_tester_tval restriction */ - item_tester_tval = 0; - - /* Forget the item_tester_hook restriction */ - item_tester_hook = NULL; - /* Success */ return (TRUE); } } /* Verify the item */ - else if (get_item_okay(*cp)) + else if (get_item_okay(*cp, filter)) { - /* Forget the item_tester_tval restriction */ - item_tester_tval = 0; - - /* Forget the item_tester_hook restriction */ - item_tester_hook = NULL; - /* Success */ return (TRUE); } @@ -5208,7 +5214,6 @@ static bool_ get_item_floor(int *cp, cptr pmt, cptr str, int mode) if (mode & (USE_EQUIP)) equip = TRUE; if (mode & (USE_INVEN)) inven = TRUE; if (mode & (USE_FLOOR)) floor = TRUE; - if (mode & (USE_EXTRA)) extra = TRUE; if (mode & (USE_AUTO)) automat = TRUE; @@ -5231,8 +5236,8 @@ static bool_ get_item_floor(int *cp, cptr pmt, cptr str, int mode) if (!inven) i2 = -1; /* Restrict inventory indexes */ - while ((i1 <= i2) && (!get_item_okay(i1))) i1++; - while ((i1 <= i2) && (!get_item_okay(i2))) i2--; + while ((i1 <= i2) && (!get_item_okay(i1, filter))) i1++; + while ((i1 <= i2) && (!get_item_okay(i2, filter))) i2--; /* Full equipment */ @@ -5243,13 +5248,13 @@ static bool_ get_item_floor(int *cp, cptr pmt, cptr str, int mode) if (!equip) e2 = -1; /* Restrict equipment indexes */ - while ((e1 <= e2) && (!get_item_okay(e1))) e1++; - while ((e1 <= e2) && (!get_item_okay(e2))) e2--; + while ((e1 <= e2) && (!get_item_okay(e1, filter))) e1++; + while ((e1 <= e2) && (!get_item_okay(e2, filter))) e2--; /* Floor items? */ auto const floor_list = - floor ? std::move(scan_floor(p_ptr->py, p_ptr->px)) + floor ? std::move(scan_floor(p_ptr->py, p_ptr->px, filter)) : std::vector(); assert(floor_list.size() <= 23); int const floor_num = floor_list.size(); // "int" for warning avoidance @@ -5351,7 +5356,7 @@ static bool_ get_item_floor(int *cp, cptr pmt, cptr str, int mode) n2 = I2A(i2); /* Redraw */ - show_inven(); + show_inven(filter); } /* Equipment screen */ @@ -5362,7 +5367,7 @@ static bool_ get_item_floor(int *cp, cptr pmt, cptr str, int mode) n2 = I2A(e2 - INVEN_WIELD); /* Redraw */ - show_equip(); + show_equip(filter); } /* Floor screen */ @@ -5376,7 +5381,7 @@ static bool_ get_item_floor(int *cp, cptr pmt, cptr str, int mode) n2 = I2A(k - floor_top); /* Redraw */ - show_floor(p_ptr->py, p_ptr->px); + show_floor(p_ptr->py, p_ptr->px, filter); } /* Viewing inventory */ @@ -5442,8 +5447,8 @@ static bool_ get_item_floor(int *cp, cptr pmt, cptr str, int mode) } } - /* Extra? */ - if (extra) + /* Do we allow selection by name? */ + if (select_by_name) { strcat(out_val, " @ for extra selection,"); } @@ -5596,7 +5601,7 @@ static bool_ get_item_floor(int *cp, cptr pmt, cptr str, int mode) } /* Validate the item */ - if (!get_item_okay(k)) + if (!get_item_okay(k, filter)) { bell(); break; @@ -5655,7 +5660,7 @@ static bool_ get_item_floor(int *cp, cptr pmt, cptr str, int mode) } /* Validate the item */ - if (!get_item_okay(k)) + if (!get_item_okay(k, filter)) { bell(); break; @@ -5677,11 +5682,15 @@ static bool_ get_item_floor(int *cp, cptr pmt, cptr str, int mode) case '@': { - int i; - - if (extra && get_item_extra_hook(&i)) + // Ignore if not "enabled" + if (!select_by_name) { - (*cp) = i; + break; + } + // Find by name + if (auto i = select_by_name(filter)) + { + (*cp) = *i; item = TRUE; done = TRUE; } @@ -5738,7 +5747,7 @@ static bool_ get_item_floor(int *cp, cptr pmt, cptr str, int mode) } /* Validate the item */ - if ((k >= 0) && !get_item_okay(k)) + if ((k >= 0) && !get_item_okay(k, filter)) { bell(); break; @@ -5770,12 +5779,6 @@ static bool_ get_item_floor(int *cp, cptr pmt, cptr str, int mode) /* Fix the screen */ screen_load(); - /* Forget the item_tester_tval restriction */ - item_tester_tval = 0; - - /* Forget the item_tester_hook restriction */ - item_tester_hook = NULL; - /* Track */ if (item && done) { @@ -5863,17 +5866,16 @@ static bool_ get_item_floor(int *cp, cptr pmt, cptr str, int mode) * We always erase the prompt when we are done, leaving a blank line, * or a warning message, if appropriate, if no items are available. */ -bool_ get_item(int *cp, cptr pmt, cptr str, int mode) +bool_ get_item(int *cp, cptr pmt, cptr str, int mode, object_filter_t const &filter, select_by_name_t const &select_by_name) { automatizer_create = FALSE; - - return get_item_floor(cp, pmt, str, mode); + return get_item_floor(cp, pmt, str, mode, filter, select_by_name); } /* * Hook to determine if an object is getable */ -static bool_ item_tester_hook_getable(object_type *o_ptr) +static bool item_tester_hook_getable(object_type const *o_ptr) { if (!inven_carry_okay(o_ptr)) return (FALSE); @@ -6285,12 +6287,9 @@ void py_pickup_floor(int pickup) int item; /* Get an item */ - - item_tester_hook = item_tester_hook_getable; - q = "Get which item? "; s = "You have no room in your pack for any of the items here."; - if (get_item(&item, q, s, (USE_FLOOR))) + if (get_item(&item, q, s, (USE_FLOOR), item_tester_hook_getable)) { this_o_idx = 0 - item; -- cgit v1.2.3 From 82936c32458b8d8312a4fdfce8b2d8274f493872 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sun, 7 Jun 2015 17:49:09 +0200 Subject: Remove prompt_pickup_heavy option; behave as if always set --- src/object1.cc | 49 ++++++++++++++++++------------------------------- 1 file changed, 18 insertions(+), 31 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index fcbc35f8..ccfd5ac5 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -5999,44 +5999,31 @@ void pickup_ammo() } -/* - * Make the player carry everything in a grid - * - * If "pickup" is FALSE then only gold will be picked up - * - * This is called by py_pickup() when easy_floor is TRUE. +/** + * Check for encumberance if player were to pick up + * given item. */ -bool_ can_carry_heavy(object_type *o_ptr) +static bool can_carry_heavy(object_type const *o_ptr) { - /* Query if object is heavy */ - if (prompt_pickup_heavy) - { - int i, j; - int old_enc = 0; - int new_enc = 0; - - /* Extract the "weight limit" (in tenth pounds) */ - i = weight_limit(); + /* Extract the "weight limit" (in tenth pounds) */ + int i = weight_limit(); - /* Calculate current encumbarance */ - j = calc_total_weight(); + /* Calculate current encumbarance */ + int j = calc_total_weight(); - /* Apply encumbarance from weight */ - if (j > i / 2) old_enc = ((j - (i / 2)) / (i / 10)); + /* Apply encumbarance from weight */ + int old_enc = 0; + if (j > i / 2) old_enc = ((j - (i / 2)) / (i / 10)); - /* Increase the weight, recalculate encumbarance */ - j += (o_ptr->number * o_ptr->weight); + /* Increase the weight, recalculate encumbarance */ + j += (o_ptr->number * o_ptr->weight); - /* Apply encumbarance from weight */ - if (j > i / 2) new_enc = ((j - (i / 2)) / (i / 10)); + /* Apply encumbarance from weight */ + int new_enc = 0; + if (j > i / 2) new_enc = ((j - (i / 2)) / (i / 10)); - /* Should we query? */ - if (new_enc > old_enc) - { - return (FALSE); - } - } - return (TRUE); + /* If the encumberance is the same, then we pick up without prompt */ + return (new_enc <= old_enc); } /* Do the actuall picking up */ -- cgit v1.2.3 From c8a270e51dc22f39ed048ab1cc609e6e456df58f Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sun, 7 Jun 2015 17:49:09 +0200 Subject: Split types.h into separate header for each type --- src/object1.cc | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index ccfd5ac5..231faa12 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -8,29 +8,47 @@ #include "object1.hpp" -#include "angband.h" +#include "artifact_type.hpp" #include "cave.hpp" +#include "cave_type.hpp" #include "cmd2.hpp" #include "cmd6.hpp" #include "dungeon.hpp" +#include "dungeon_info_type.hpp" +#include "ego_item_type.hpp" +#include "feature_type.hpp" #include "files.hpp" +#include "hook_get_in.hpp" #include "hooks.hpp" #include "lua_bind.hpp" #include "mimic.hpp" #include "monster1.hpp" #include "monster2.hpp" +#include "monster_ego.hpp" +#include "monster_race.hpp" +#include "monster_type.hpp" #include "object2.hpp" +#include "object_kind.hpp" +#include "object_type.hpp" #include "options.hpp" +#include "player_race.hpp" +#include "player_race_mod.hpp" +#include "player_type.hpp" #include "quark.hpp" +#include "set_type.hpp" #include "skills.hpp" #include "spell_type.hpp" #include "spells5.hpp" #include "squeltch.hpp" +#include "stats.hpp" +#include "store_info_type.hpp" #include "tables.hpp" +#include "trap_type.hpp" #include "util.hpp" #include "util.h" #include "variable.h" #include "variable.hpp" +#include "wilderness_type_info.hpp" #include "xtra1.hpp" #include -- cgit v1.2.3 From c6196b25d119a10e79deedef26a73e0d5a021b0e Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Fri, 12 Jun 2015 06:27:05 +0200 Subject: Refactor cave_type and monster_type to use non-intrusive lists We use vectors of object indexes instead of embedding the list within object_type itself. --- src/object1.cc | 287 ++++++++++++++++++++++++++------------------------------- 1 file changed, 131 insertions(+), 156 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 231faa12..0f79d0ee 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -5029,7 +5029,6 @@ static int get_tag(int *cp, char tag) */ static std::vector scan_floor(int y, int x, object_filter_t const &filter) { - int this_o_idx, next_o_idx; std::vector items; /* Sanity */ @@ -5039,14 +5038,11 @@ static std::vector scan_floor(int y, int x, object_filter_t const &filter) } /* Scan all objects in the grid */ - for (this_o_idx = cave[y][x].o_idx; this_o_idx; this_o_idx = next_o_idx) + for (auto const this_o_idx: cave[y][x].o_idxs) { /* Acquire object */ object_type * o_ptr = &o_list[this_o_idx]; - /* Acquire next object */ - next_o_idx = o_ptr->next_o_idx; - /* Item tester */ if (!item_tester_okay(o_ptr, filter)) { @@ -5979,21 +5975,19 @@ int wear_ammo(object_type *o_ptr) */ void pickup_ammo() { - s16b this_o_idx, next_o_idx = 0, slot; - char o_name[80]; + /* Copy list of objects since we're manipulating the list */ + auto const object_idxs(cave[p_ptr->py][p_ptr->px].o_idxs); /* Scan the pile of objects */ - for (this_o_idx = cave[p_ptr->py][p_ptr->px].o_idx; this_o_idx; this_o_idx = next_o_idx) + for (auto const this_o_idx: object_idxs) { - object_type * o_ptr; - /* Acquire object */ - o_ptr = &o_list[this_o_idx]; + object_type *o_ptr = &o_list[this_o_idx]; if (object_similar(o_ptr, &p_ptr->inventory[INVEN_AMMO])) { msg_print("You add the ammo to your quiver."); - slot = wear_ammo(o_ptr); + s16b slot = wear_ammo(o_ptr); if (slot != -1) { @@ -6001,6 +5995,7 @@ void pickup_ammo() o_ptr = &p_ptr->inventory[slot]; /* Describe the object */ + char o_name[80]; object_desc(o_name, o_ptr, TRUE, 3); /* Message */ @@ -6010,9 +6005,6 @@ void pickup_ammo() delete_object_idx(this_o_idx); } } - - /* Acquire next object */ - next_o_idx = o_ptr->next_o_idx; } } @@ -6118,66 +6110,16 @@ void object_pickup(int this_o_idx) } -void py_pickup_floor(int pickup) +static void absorb_gold(cave_type const *c_ptr) { - /* Hack -- ignore monster traps */ - if (cave[p_ptr->py][p_ptr->px].feat == FEAT_MON_TRAP) return; - - /* Try to grab ammo */ - pickup_ammo(); - - /* Build a list of the floor objects. */ - std::vector floor_object_idxs; - { - s16b this_o_idx = cave[p_ptr->py][p_ptr->px].o_idx; - /* Reserve a number of slots if at least one is needed */ - if (this_o_idx) - { - floor_object_idxs.reserve(16); // Avoid resizing in the common case - } - /* Fill in the indexes */ - for (; this_o_idx; this_o_idx = o_list[this_o_idx].next_o_idx) - { - // Note the "-"! We need it for get_object() - // lookups to function correctly. - floor_object_idxs.push_back(0 - this_o_idx); - } - } - - /* Mega Hack -- If we have auto-Id, do an ID sweep *before* squleching, - * so that we don't have to walk over things twice to get them - * squelched. --dsb */ - if (p_ptr->auto_id) - { - for (auto const o_idx : floor_object_idxs) - { - object_type *o_ptr = get_object(o_idx); - object_aware(o_ptr); - object_known(o_ptr); - } - } + /* Copy list of objects since we're going to manipulate the list itself */ + auto const object_idxs(c_ptr->o_idxs); - /* Sense floor tile */ - sense_objects(floor_object_idxs); - - /* Squeltch the floor */ - squeltch_grid(); - - /* Scan the pile of objects */ - s16b next_o_idx = 0; - char o_name[80] = ""; - object_type *o_ptr = 0; - int floor_num = 0; - int floor_o_idx = 0; - - s16b this_o_idx; - for (this_o_idx = cave[p_ptr->py][p_ptr->px].o_idx; this_o_idx; this_o_idx = next_o_idx) + /* Go through everything */ + for (auto const this_o_idx: object_idxs) { /* Acquire object */ - o_ptr = &o_list[this_o_idx]; - - /* Acquire next object */ - next_o_idx = o_ptr->next_o_idx; + object_type *o_ptr = &o_list[this_o_idx]; /* Hack -- disturb */ disturb(0); @@ -6189,7 +6131,7 @@ void py_pickup_floor(int pickup) object_desc(goldname, o_ptr, TRUE, 3); /* Message */ msg_format("You have found %ld gold pieces worth of %s.", - (long)o_ptr->pval, goldname); + (long)o_ptr->pval, goldname); /* Collect the gold */ p_ptr->au += o_ptr->pval; @@ -6202,123 +6144,156 @@ void py_pickup_floor(int pickup) /* Delete the gold */ delete_object_idx(this_o_idx); - - continue; } + } +} - /* Describe */ +static void sense_floor(cave_type const *c_ptr) +{ + /* Build a list of the floor objects. */ + std::vector floor_object_idxs; + { + /* Reserve the correct number of slots */ + floor_object_idxs.reserve(c_ptr->o_idxs.size()); + /* Fill in the indexes */ + for (auto const this_o_idx: c_ptr->o_idxs) { - char testdesc[80]; + // Note the "-"! We need it for get_object() + // lookups to function correctly. + floor_object_idxs.push_back(0 - this_o_idx); + } + } - object_desc(testdesc, o_ptr, TRUE, 3); - if (0 != strncmp(testdesc, "(nothing)", 80)) - { - strncpy(o_name, testdesc, 80); - } + /* Mega Hack -- If we have auto-Id, do an ID sweep *before* squleching, + * so that we don't have to walk over things twice to get them + * squelched. --dsb */ + if (p_ptr->auto_id) + { + for (auto const o_idx: floor_object_idxs) + { + object_type *o_ptr = get_object(o_idx); + object_aware(o_ptr); + object_known(o_ptr); } + } - /* Count non-gold */ - floor_num++; + /* Sense floor tile */ + sense_objects(floor_object_idxs); +} - /* Remember this index */ - floor_o_idx = this_o_idx; +void py_pickup_floor(int pickup) +{ + /* Get the tile */ + auto c_ptr = &cave[p_ptr->py][p_ptr->px]; + + /* Hack -- ignore monster traps */ + if (c_ptr->feat == FEAT_MON_TRAP) + { + return; } - /* There were no non-gold items */ - if (!floor_num) return; + /* Try to grab ammo */ + pickup_ammo(); + + /* Auto-ID and pseudo-ID */ + sense_floor(c_ptr); + + /* Squeltch the floor */ + squeltch_grid(); + + /* Absorb gold on the tile */ + absorb_gold(&cave[p_ptr->py][p_ptr->px]); - /* Mention number of items */ - if (!pickup) + /* We handle 0, 1, or "many" items cases separately */ + if (c_ptr->o_idxs.empty()) + { + /* Nothing to do */ + } + else if (c_ptr->o_idxs.size() == 1) { - /* One item */ - if (floor_num == 1) + /* Acquire object */ + auto floor_o_idx = c_ptr->o_idxs.front(); + auto o_ptr = &o_list[floor_o_idx]; + + /* Describe or pick up? */ + if (!pickup) { - /* Acquire object */ - o_ptr = &o_list[floor_o_idx]; + /* Describe */ + char o_name[80] = ""; + object_desc(o_name, o_ptr, TRUE, 3); /* Message */ msg_format("You see %s.", o_name); } - - /* Multiple items */ else { - /* Message */ - msg_format("You see a pile of %d items.", floor_num); - } - - /* Done */ - return; - } + /* Are we actually going to pick up? */ + bool_ do_pickup = TRUE; - /* Are we actually going to pick up and/or ask about which item to pick up? */ - bool_ do_pickup = TRUE; - bool_ do_ask = TRUE; - - /* One item */ - if (floor_num == 1) - { - /* Hack -- query every item */ - if (carry_query_flag || (!can_carry_heavy(&o_list[floor_o_idx]))) - { - if (!inven_carry_okay(o_ptr) && !object_similar(o_ptr, &p_ptr->inventory[INVEN_AMMO])) + /* Hack -- query every item */ + if (carry_query_flag || (!can_carry_heavy(&o_list[floor_o_idx]))) { + char o_name[80] = ""; object_desc(o_name, o_ptr, TRUE, 3); - msg_format("You have no room for %s.", o_name); - do_pickup = FALSE; + + if (!inven_carry_okay(o_ptr) && !object_similar(o_ptr, &p_ptr->inventory[INVEN_AMMO])) + { + msg_format("You have no room for %s.", o_name); + return; /* Done */ + } + else + { + char out_val[160]; + sprintf(out_val, "Pick up %s? ", o_name); + do_pickup = get_check(out_val); + } } - else + + /* Just pick it up; unless it's a symbiote and we don't have Symbiosis */ + if (do_pickup && ((o_list[floor_o_idx].tval != TV_HYPNOS) || (get_skill(SKILL_SYMBIOTIC)))) { - char out_val[160]; - sprintf(out_val, "Pick up %s? ", o_name); - do_pickup = get_check(out_val); + object_pickup(floor_o_idx); } } - - /* Don't ask */ - do_ask = FALSE; - - if ((o_list[floor_o_idx].tval == TV_HYPNOS) && (!get_skill(SKILL_SYMBIOTIC))) - do_pickup = FALSE; - else - this_o_idx = floor_o_idx; } - - /* Ask */ - if (do_ask) + else { - cptr q, s; - - int item; - - /* Get an item */ - q = "Get which item? "; - s = "You have no room in your pack for any of the items here."; - if (get_item(&item, q, s, (USE_FLOOR), item_tester_hook_getable)) + /* Describe or pick up? */ + if (!pickup) { - this_o_idx = 0 - item; - - if (!can_carry_heavy(&o_list[this_o_idx])) + /* Message */ + msg_format("You see a pile of %d items.", c_ptr->o_idxs.size()); + } + else + { + /* Prompt for the item to pick up */ + cptr q = "Get which item? "; + cptr s = "You have no room in your pack for any of the items here."; + int item; + if (get_item(&item, q, s, (USE_FLOOR), item_tester_hook_getable)) { - char out_val[160]; + s16b this_o_idx = 0 - item; - /* Describe the object */ - object_desc(o_name, &o_list[this_o_idx], TRUE, 3); + bool_ do_pickup = TRUE; + if (!can_carry_heavy(&o_list[this_o_idx])) + { + /* Describe the object */ + char o_name[80] = ""; + object_desc(o_name, &o_list[this_o_idx], TRUE, 3); + + /* Prompt */ + char out_val[160]; + sprintf(out_val, "Pick up %s? ", o_name); + do_pickup = get_check(out_val); + } - sprintf(out_val, "Pick up %s? ", o_name); - do_pickup = get_check(out_val); + /* Pick up the item */ + if (do_pickup) + { + object_pickup(this_o_idx); + } } } - else - { - do_pickup = FALSE; - } - } - - /* Pick up the item */ - if (do_pickup) - { - object_pickup(this_o_idx); } } -- cgit v1.2.3 From 47fb7807d77c92fa6e72017501d9355d780adf40 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 14 Sep 2015 06:03:01 +0200 Subject: Remove TR4_ANTIMAGIC_{30,20,10} flags They're only used for the Antimagic realm of leveling items and we might as well use ANTIMAGIC_50 there, given the rarity of the flag. --- src/object1.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 0f79d0ee..95cd0522 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -2999,7 +2999,7 @@ bool_ object_out_desc(object_type *o_ptr, FILE *fff, bool_ trim_down, bool_ wait text_out("It prevents the space-time continuum from being disrupted. "); } - if ((f4 & (TR4_ANTIMAGIC_50)) || (f4 & (TR4_ANTIMAGIC_30)) || (f4 & (TR4_ANTIMAGIC_20)) || (f4 & (TR4_ANTIMAGIC_10))) + if (f4 & TR4_ANTIMAGIC_50) { text_out("It generates an antimagic field. "); } -- cgit v1.2.3 From cc50d2db6418690470ead3faf71e0818eff1b8e4 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Thu, 29 Oct 2015 19:40:43 +0100 Subject: Fix clang warning; don't explicitly move --- src/object1.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 95cd0522..eca26087 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -5268,7 +5268,7 @@ static bool_ get_item_floor(int *cp, cptr pmt, cptr str, int mode, object_filter /* Floor items? */ auto const floor_list = - floor ? std::move(scan_floor(p_ptr->py, p_ptr->px, filter)) + floor ? scan_floor(p_ptr->py, p_ptr->px, filter) : std::vector(); assert(floor_list.size() <= 23); int const floor_num = floor_list.size(); // "int" for warning avoidance -- cgit v1.2.3 From 33e7dc3baa6b375efb6d8989ffe3c50511291228 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Fri, 11 Dec 2015 08:09:30 +0100 Subject: Remove Alchemist class and associated skills/code Alchemy has always been ridiculously broken and there's been a huge amount of horrible code to support it. Sorry to any fans of Alchemy, but it's got to go. --- src/object1.cc | 14 -------------- 1 file changed, 14 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index eca26087..c38f2254 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -425,7 +425,6 @@ static bool_ object_easy_know(int i) case TV_SCROLL: case TV_ROD: case TV_ROD_MAIN: - case TV_BATERIE: { if (k_ptr->flags3 & TR3_NORM_ART) return ( FALSE ); @@ -1519,13 +1518,6 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) break; } - case TV_BATERIE: - { - modstr = basenm; - basenm = "& Essence~ of #"; - break; - } - case TV_PARCHMENT: { modstr = basenm; @@ -2011,12 +2003,6 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) t = object_desc_num(t, o_ptr->elevel); t = object_desc_chr(t, ')'); } - if ((f4 & TR4_ART_EXP) && known) - { - t = object_desc_str(t, " (Exp:"); - t = object_desc_num(t, o_ptr->exp); - t = object_desc_chr(t, ')'); - } /* Hack -- Chests must be described in detail */ if (o_ptr->tval == TV_CHEST) -- cgit v1.2.3 From 97bcf1bc612d9920390c885b8dcea0b0cda6f246 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Fri, 11 Dec 2015 08:09:30 +0100 Subject: Migrate z-rand.c to C++ - Include explicitly instead of via angband.h - Change to regular functions instead of macros. --- src/object1.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index c38f2254..6bbf23e9 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -50,6 +50,7 @@ #include "variable.hpp" #include "wilderness_type_info.hpp" #include "xtra1.hpp" +#include "z-rand.hpp" #include -- cgit v1.2.3 From 0626333610e343551f88778320a04836f2d2b406 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Fri, 5 Feb 2016 19:22:46 +0100 Subject: Remove formal "min" parameter to get_level() --- src/object1.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 6bbf23e9..17a2d096 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -2767,7 +2767,7 @@ static void describe_device(object_type *o_ptr) }); text_out("\nSpell level: "); - sprintf(buf, FMTs32b, get_level(o_ptr->pval2, 50, 0)); + sprintf(buf, FMTs32b, get_level(o_ptr->pval2, 50)); text_out_c(TERM_L_BLUE, buf); text_out("\nMinimum Magic Device level to increase spell level: "); -- cgit v1.2.3 From ea91fcd36198086ea21d167e27a1e5fef7185f88 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Thu, 10 Mar 2016 18:41:54 +0100 Subject: Change CHECK_FIRST() from macro to function --- src/object1.cc | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 17a2d096..04faa90b 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -2546,8 +2546,16 @@ static bool_ grab_tval_desc(int tval) return TRUE; } -#define CHECK_FIRST(txt, first) \ -if ((first)) { (first) = FALSE; text_out((txt)); } else text_out(", "); +static void check_first(bool_ *first) +{ + if (*first) { + *first = FALSE; + } + else + { + text_out(", "); + } +} /* * Display the damage done with a multiplier @@ -2559,7 +2567,7 @@ void output_dam(object_type *o_ptr, int mult, int mult2, cptr against, cptr agai dam = (o_ptr->dd + (o_ptr->dd * o_ptr->ds)) * 5 * mult; dam += (o_ptr->to_d + p_ptr->to_d + p_ptr->to_d_melee) * 10; dam *= p_ptr->num_blow; - CHECK_FIRST("", *first); + check_first(first); if (dam > 0) { if (dam % 10) @@ -2576,7 +2584,7 @@ void output_dam(object_type *o_ptr, int mult, int mult2, cptr against, cptr agai dam = (o_ptr->dd + (o_ptr->dd * o_ptr->ds)) * 5 * mult2; dam += (o_ptr->to_d + p_ptr->to_d + p_ptr->to_d_melee) * 10; dam *= p_ptr->num_blow; - CHECK_FIRST("", *first); + check_first(first); if (dam > 0) { if (dam % 10) @@ -2656,7 +2664,7 @@ void output_ammo_dam(object_type *o_ptr, int mult, int mult2, cptr against, cptr dam *= tmul; if (!is_boomerang) dam += (p_ptr->to_d_ranged) * 10; dam *= mult; - CHECK_FIRST("", *first); + check_first(first); if (dam > 0) { if (dam % 10) @@ -2676,7 +2684,7 @@ void output_ammo_dam(object_type *o_ptr, int mult, int mult2, cptr against, cptr dam *= tmul; if (!is_boomerang) dam += (p_ptr->to_d_ranged) * 10; dam *= mult2; - CHECK_FIRST("", *first); + check_first(first); if (dam > 0) { if (dam % 10) @@ -2829,14 +2837,10 @@ bool_ object_out_desc(object_type *o_ptr, FILE *fff, bool_ trim_down, bool_ wait { u32b f1, f2, f3, f4, f5, esp; - const char *txt; - cptr vp[64]; byte vc[64]; int vn; - bool_ first = TRUE; - /* Extract the flags */ if ((!(o_ptr->ident & (IDENT_MENTAL))) && (!fff)) { @@ -2907,13 +2911,12 @@ bool_ object_out_desc(object_type *o_ptr, FILE *fff, bool_ trim_down, bool_ wait else if (count_bits(o_ptr->pval3) > 1) text_out("It is sentient and can have access to the realms of "); else text_out("It is sentient and can have access to the realm of "); - first = TRUE; - txt = ""; + bool_ first = TRUE; for (j = 0; j < MAX_FLAG_GROUP; j++) { if (BIT(j) & o_ptr->pval3) { - CHECK_FIRST(txt, first); + check_first(&first); text_out_c(flags_groups[j].color, flags_groups[j].name); } } -- cgit v1.2.3 From c6bb51bd11891177b20bdeecc6baa77f0261e45e Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Thu, 10 Mar 2016 18:41:54 +0100 Subject: Use std::string for object_desc --- src/object1.cc | 632 ++++++++++++++++++++------------------------------------- 1 file changed, 221 insertions(+), 411 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 04faa90b..096cadc5 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -52,7 +52,12 @@ #include "xtra1.hpp" #include "z-rand.hpp" +#include +#include #include +#include + +using boost::starts_with; static bool_ apply_flags_set(s16b a_idx, s16b set_idx, u32b *f1, u32b *f2, u32b *f3, u32b *f4, u32b *f5, u32b *esp); @@ -1075,119 +1080,16 @@ void object_flags_known(object_type const *o_ptr, u32b *f1, u32b *f2, u32b *f3, } - - - -/* - * Print a char "c" into a string "t", as if by sprintf(t, "%c", c), - * and return a pointer to the terminator (t + 1). - */ -static char *object_desc_chr(char *t, char c) -{ - /* Copy the char */ - *t++ = c; - - /* Terminate */ - *t = '\0'; - - /* Result */ - return (t); -} - - -/* - * Print a string "s" into a string "t", as if by strcpy(t, s), - * and return a pointer to the terminator. - */ -static char *object_desc_str(char *t, cptr s) -{ - /* Copy the string */ - while (*s) *t++ = *s++; - - /* Terminate */ - *t = '\0'; - - /* Result */ - return (t); -} - -/* - * Do the actual conversion of a number for object_desc_num() and - * object_desc_int(). - */ -static char *convert_number(char *result, u32b num) -{ - char *tp; - char temp[11]; - - tp = temp; - *tp = '0' + (num % 10); - for (num /= 10; num != 0; num /= 10) - { - *++tp = '0' + (num % 10); - } - - while (tp != temp) - { - *result++ = *tp--; - } - *result++ = *tp; - *result = '\0'; - - return result; -} - -/* - * Print a nnumber "n" into a string "t", as if by - * sprintf(t, "%u", n), and return a pointer to the terminator. +/** + * Calculate amount of EXP needed for the given object to + * level, assuming it's a sentient object. */ -static char *object_desc_num(char *result, s32b num) +s32b calc_object_need_exp(object_type const *o_ptr) { - u32b n; - - if (num < 0) - { - *result++ = '-'; - n = -num; - } - else - n = num; - - /* Result */ - return convert_number(result, n); + return (player_exp[o_ptr->elevel - 1] * 5 / 2); } -/* - * Print an signed number "num" into a string "result", as if by - * sprintf(t, "%+d", n), and return a pointer to the terminator. - * Note that we always print a sign, either "+" or "-". - */ -static char *object_desc_int(char *result, s32b num) -{ - u32b n; - /* Negative */ - if (num < 0) - { - /* Take the absolute value */ - n = -num; - - /* Use a "minus" sign */ - *result++ = '-'; - } - /* Positive (or zero) */ - else - { - /* Use the actual number */ - n = num; - - /* Use a "plus" sign */ - *result++ = '+'; - } - - /* Result */ - return convert_number(result, n); -} /* * Creates a description of the item "o_ptr", and stores it in "out_val". @@ -1234,11 +1136,9 @@ static char *object_desc_int(char *result, s32b num) * 2 -- The Cloak of Death [1,+3] (+2 to Stealth) * 3 -- The Cloak of Death [1,+3] (+2 to Stealth) {nifty} */ -void object_desc(char *buf, object_type *o_ptr, int pref, int mode) +std::string object_desc_aux(object_type *o_ptr, int pref, int mode) { bool_ hack_name = FALSE; - cptr basenm, modstr; - int indexx; bool_ aware = FALSE; bool_ known = FALSE; @@ -1248,24 +1148,10 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) bool_ show_weapon = FALSE; bool_ show_armour = FALSE; - cptr s, u; - char *t; - - char p1 = '(', p2 = ')'; - char b1 = '[', b2 = ']'; - char c1 = '{', c2 = '}'; - - char tmp_val[160]; - char tmp_val2[90]; - - s32b power; - u32b f1, f2, f3, f4, f5, esp; - object_kind *k_ptr = &k_info[o_ptr->k_idx]; - cptr str; - /* Extract some flags */ + u32b f1, f2, f3, f4, f5, esp; object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); @@ -1276,13 +1162,13 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) if (object_known_p(o_ptr)) known = TRUE; /* Hack -- Extract the sub-type "indexx" */ - indexx = o_ptr->sval; + auto const indexx = o_ptr->sval; /* Extract default "base" string */ - basenm = k_ptr->name; + std::string basenm(k_ptr->name); /* Assume no "modifier" string */ - modstr = ""; + std::string modstr; /* Analyze the object */ switch (o_ptr->tval) @@ -1530,8 +1416,7 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) /* Hack -- Gold/Gems */ case TV_GOLD: { - strcpy(buf, basenm); - return; + return basenm; } case TV_CORPSE: @@ -1539,9 +1424,13 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) monster_race* r_ptr = &r_info[o_ptr->pval2]; modstr = basenm; if (r_ptr->flags1 & RF1_UNIQUE) - basenm = format("& %s's #~", r_ptr->name); + { + basenm = fmt::format("& {}'s #~", r_ptr->name); + } else - basenm = format("& %s #~", r_ptr->name); + { + basenm = fmt::format("& {} #~", r_ptr->name); + } break; } @@ -1549,8 +1438,7 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) { monster_race* r_ptr = &r_info[o_ptr->pval2]; modstr = basenm; - - basenm = format("& %s #~", r_ptr->name); + basenm = fmt::format("& {} #~", r_ptr->name); break; } @@ -1559,24 +1447,23 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) /* We print hit points further down. --dsb */ monster_race* r_ptr = &r_info[o_ptr->pval]; modstr = basenm; - basenm = format("& %s~", r_ptr->name); + basenm = fmt::format("& {}~", r_ptr->name); break; } case TV_TOTEM: { - char name[80]; monster_type monster; - monster.r_idx = o_ptr->pval; monster.ego = o_ptr->pval2; monster.ml = TRUE; monster.status = MSTATUS_ENEMY; + char name[80]; monster_desc(name, &monster, 0x188); modstr = basenm; - basenm = format("& #~ of %s", name); + basenm = fmt::format("& #~ of {}", name); break; } @@ -1625,10 +1512,7 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) /* Used in the "inventory" routine */ default: - { - strcpy(buf, "(nothing)"); - return; - } + return "(nothing)"; } /* Mega Hack */ @@ -1637,18 +1521,26 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) basenm = k_ptr->name; } + /* Copy of the base string _without_ a prefix */ + std::string s; /* Start dumping the result */ - t = tmp_val; + std::string t; /* The object "expects" a "number" */ - if (basenm[0] == '&') + if (starts_with(basenm, "&")) { - monster_race* r_ptr; cptr ego = NULL; - if (o_ptr->tval == TV_CORPSE) r_ptr = &r_info[o_ptr->pval2]; - else r_ptr = &r_info[o_ptr->pval]; + monster_race* r_ptr; + if (o_ptr->tval == TV_CORPSE) + { + r_ptr = &r_info[o_ptr->pval2]; + } + else + { + r_ptr = &r_info[o_ptr->pval]; + } /* Grab any ego-item name */ if (known && (o_ptr->name2 || o_ptr->name2b) && (o_ptr->tval != TV_ROD_MAIN)) @@ -1667,7 +1559,7 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) } /* Skip the ampersand (and space) */ - s = basenm + 2; + s = basenm.substr(2); /* No prefix */ if (pref <= 0) @@ -1678,14 +1570,14 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) /* Hack -- None left */ else if (o_ptr->number <= 0) { - t = object_desc_str(t, "no more "); + t += "no more "; } /* Extract the number */ else if (o_ptr->number > 1) { - t = object_desc_num(t, o_ptr->number); - t = object_desc_chr(t, ' '); + t += std::to_string(o_ptr->number); + t += ' '; } else if ((o_ptr->tval == TV_CORPSE) && (r_ptr->flags1 & RF1_UNIQUE)) @@ -1698,37 +1590,37 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) /* Hack -- The only one of its kind */ else if (known && (artifact_p(o_ptr) || o_ptr->art_name)) { - t = object_desc_str(t, "The "); + t += "The "; } else if (ego != NULL) { if (is_a_vowel(ego[0])) { - t = object_desc_str(t, "an "); + t += "an "; } else { - t = object_desc_str(t, "a "); + t += "a "; } } /* A single one, with a vowel in the modifier */ - else if ((*s == '#') && (is_a_vowel(modstr[0]))) + else if ((s[0] == '#') && (is_a_vowel(modstr[0]))) { - t = object_desc_str(t, "an "); + t += "an "; } /* A single one, with a vowel */ - else if (is_a_vowel(*s)) + else if (is_a_vowel(s[0])) { - t = object_desc_str(t, "an "); + t += "an "; } /* A single one, without a vowel */ else { - t = object_desc_str(t, "a "); + t += "a "; } /* Grab any ego-item name */ @@ -1739,13 +1631,13 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) if (e_ptr->before) { - t = object_desc_str(t, e_ptr->name); - t = object_desc_chr(t, ' '); + t += e_ptr->name; + t += ' '; } if (e2_ptr->before) { - t = object_desc_str(t, e2_ptr->name); - t = object_desc_chr(t, ' '); + t += e2_ptr->name; + t += ' '; } } @@ -1755,13 +1647,13 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) if (o_ptr->note) { - str = strchr(quark_str(o_ptr->note), '%'); + cptr str = strchr(quark_str(o_ptr->note), '%'); /* Add the false name */ if (str) { - t = object_desc_str(t, &str[1]); - t = object_desc_chr(t, ' '); + t += &str[1]; + t += ' '; } } @@ -1782,14 +1674,14 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) /* Hack -- all gone */ else if (o_ptr->number <= 0) { - t = object_desc_str(t, "no more "); + t += "no more "; } /* Prefix a number if required */ else if (o_ptr->number > 1) { - t = object_desc_num(t, o_ptr->number); - t = object_desc_chr(t, ' '); + t += std::to_string(o_ptr->number); + t += ' '; } else if (o_ptr->tval == TV_RANDART) @@ -1800,7 +1692,7 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) /* Hack -- The only one of its kind */ else if (known && (artifact_p(o_ptr) || o_ptr->art_name)) { - t = object_desc_str(t, "The "); + t += "The "; } /* Hack -- single items get no prefix */ @@ -1817,95 +1709,86 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) if (e_ptr->before) { - t = object_desc_str(t, e_ptr->name); - t = object_desc_chr(t, ' '); + t += e_ptr->name; + t += ' '; } if (e2_ptr->before) { - t = object_desc_str(t, e2_ptr->name); - t = object_desc_chr(t, ' '); + t += e2_ptr->name; + t += ' '; } } } - /* Paranoia -- skip illegal tildes */ - /* while (*s == '~') s++; */ - /* Copy the string */ - for (; *s; s++) + for (auto const c: s) { /* Pluralizer */ - if (*s == '~') + if (c == '~') { /* Add a plural if needed */ if ((o_ptr->number != 1) && (pref >= 0)) { - char k = t[ -1]; + assert(t.size() > 0); + char k = t[t.size() - 1]; /* XXX XXX XXX Mega-Hack */ /* Hack -- "Cutlass-es" and "Torch-es" */ - if ((k == 's') || (k == 'h')) *t++ = 'e'; + if ((k == 's') || (k == 'h')) { + t += "e"; + } /* Add an 's' */ - *t++ = 's'; + t += "s"; } } /* Modifier */ - else if (*s == '#') + else if (c == '#') { /* Grab any ego-item name */ if (o_ptr->tval == TV_ROD_MAIN) { - t = object_desc_chr(t, ' '); + t += ' '; if (known && o_ptr->name2) { ego_item_type *e_ptr = &e_info[o_ptr->name2]; - t = object_desc_str(t, e_ptr->name); + t += e_ptr->name; } } /* Insert the modifier */ - for (u = modstr; *u; u++) *t++ = *u; + t += modstr; } /* Normal */ else { /* Copy */ - *t++ = *s; + t += c; } } - /* Terminate */ - *t = '\0'; - - /* Append the "kind name" to the "base name" */ if ((append_name) && (!artifact_p(o_ptr))) { - t = object_desc_str(t, " of "); + t += " of "; if (((o_ptr->tval == TV_WAND) || (o_ptr->tval == TV_STAFF))) { - t = object_desc_str(t, spell_type_name(spell_at(o_ptr->pval2))); + t += spell_type_name(spell_at(o_ptr->pval2)); if (mode >= 1) { s32b bonus = o_ptr->pval3 & 0xFFFF; s32b max = o_ptr->pval3 >> 16; - - t = object_desc_chr(t, '['); - t = object_desc_num(t, bonus); - t = object_desc_chr(t, '|'); - t = object_desc_num(t, max); - t = object_desc_chr(t, ']'); + t += fmt::format("[{:d}|{:d}]", bonus, max); } } else { - t = object_desc_str(t, k_ptr->name); + t += k_ptr->name; } } @@ -1918,22 +1801,21 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) * Dagger of Smell {@w0} */ if (o_ptr->note) { - str = strchr(quark_str(o_ptr->note), '#'); + cptr str = strchr(quark_str(o_ptr->note), '#'); /* Add the false name */ if (str) { - t = object_desc_chr(t, ' '); - t = object_desc_str(t, &str[1]); + t += ' '; + t += &str[1]; } } /* Is it a new random artifact ? */ if (o_ptr->art_name) { - t = object_desc_chr(t, ' '); - - t = object_desc_str(t, quark_str(o_ptr->art_name)); + t += ' '; + t += quark_str(o_ptr->art_name); } @@ -1945,8 +1827,8 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) /* Unique corpses don't require another name */ if (o_ptr->tval != TV_CORPSE) { - t = object_desc_chr(t, ' '); - t = object_desc_str(t, a_ptr->name); + t += ' '; + t += a_ptr->name; } } @@ -1958,13 +1840,13 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) if (o_ptr->name2 && !e_ptr->before) { - t = object_desc_chr(t, ' '); - t = object_desc_str(t, e_ptr->name); + t += ' '; + t += e_ptr->name; } if (o_ptr->name2b && !e2_ptr->before) { - t = object_desc_chr(t, ' '); - t = object_desc_str(t, e2_ptr->name); + t += ' '; + t += e2_ptr->name; } } } @@ -1972,37 +1854,28 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) /* It contains a spell */ if ((known) && (f5 & TR5_SPELL_CONTAIN) && (o_ptr->pval2 != -1)) { - t = object_desc_str(t, format(" [%s]", spell_type_name(spell_at(o_ptr->pval2)))); + t += fmt::format(" [{}]", spell_type_name(spell_at(o_ptr->pval2))); } /* Add symbiote hp here, after the "fake-artifact" name. --dsb */ if (o_ptr->tval == TV_HYPNOS) { - t = object_desc_str(t, " ("); - t = object_desc_num(t, o_ptr->pval2); - t = object_desc_str(t, " hp)"); + t += fmt::format(" ({:d} hp)", o_ptr->pval2); } /* No more details wanted */ - if (mode < 1) goto copyback; + if (mode < 1) + { + return t; + } /* Hack -- Some objects can have an exp level */ if ((f4 & TR4_LEVELS) && known) { - t = object_desc_str(t, " (E:"); - if (o_ptr->elevel < PY_MAX_LEVEL) - { - /* Formula from check_experience_obj(). */ - s32b need = player_exp[o_ptr->elevel - 1] * 5 / 2; - t = object_desc_num(t, need - o_ptr->exp); - } - else - { - t = object_desc_str(t, "*****"); - } - t = object_desc_str(t, ", L:"); - t = object_desc_num(t, o_ptr->elevel); - t = object_desc_chr(t, ')'); + auto need_exp = (o_ptr->elevel < PY_MAX_LEVEL) + ? std::to_string(calc_object_need_exp(o_ptr) - o_ptr->exp) + : "*****"; + t += fmt::format(" (E:{}, L:{})", need_exp, o_ptr->elevel); } /* Hack -- Chests must be described in detail */ @@ -2017,29 +1890,24 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) /* May be "empty" */ else if (!o_ptr->pval) { - t = object_desc_str(t, " (empty)"); + t += " (empty)"; } /* May be "disarmed" */ else if (o_ptr->pval < 0) { - t = object_desc_str(t, " (disarmed)"); + t += " (disarmed)"; } /* Describe the traps, if any */ else { /* Describe the traps */ - t = object_desc_str(t, " ("); - if (t_info[o_ptr->pval].ident) - { - t = object_desc_str(t, t_info[o_ptr->pval].name); - } - else - { - t = object_desc_str(t, "trapped"); - } - t = object_desc_str(t, ")"); + auto trap_name = (t_info[o_ptr->pval].ident) + ? t_info[o_ptr->pval].name + : "trapped"; + + t += fmt::format(" ({})", trap_name); } } @@ -2062,7 +1930,7 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) case TV_ARROW: /* Exploding arrow? */ if (o_ptr->pval2 != 0) - t = object_desc_str(t, " (exploding)"); + t += " (exploding)"; /* No break, we want to continue the description */ case TV_BOOMERANG: @@ -2076,12 +1944,7 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) break; /* Append a "damage" string */ - t = object_desc_chr(t, ' '); - t = object_desc_chr(t, p1); - t = object_desc_num(t, o_ptr->dd); - t = object_desc_chr(t, 'd'); - t = object_desc_num(t, o_ptr->ds); - t = object_desc_chr(t, p2); + t += fmt::format(" ({:d}d{:d})", o_ptr->dd, o_ptr->ds); /* All done */ break; @@ -2089,19 +1952,14 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) /* Bows get a special "damage string" */ case TV_BOW: - /* Mega-Hack -- Extract the "base power" */ - power = (o_ptr->sval % 10); + s32b power = (o_ptr->sval % 10); /* Apply the "Extra Might" flag */ if (f3 & (TR3_XTRA_MIGHT)) power += o_ptr->pval; /* Append a special "damage" string */ - t = object_desc_chr(t, ' '); - t = object_desc_chr(t, p1); - t = object_desc_chr(t, 'x'); - t = object_desc_num(t, power); - t = object_desc_chr(t, p2); + t += fmt::format(" (x{:d})", power); /* All done */ break; @@ -2114,34 +1972,29 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) /* Show the tohit/todam on request */ if (show_weapon) { - t = object_desc_chr(t, ' '); - t = object_desc_chr(t, p1); - t = object_desc_int(t, o_ptr->to_h); - t = object_desc_chr(t, ','); - t = object_desc_int(t, o_ptr->to_d); - t = object_desc_chr(t, p2); + t += fmt::format(" ({:+d},{:+d})", o_ptr->to_h, o_ptr->to_d); } /* Show the tohit if needed */ else if (o_ptr->to_h) { - t = object_desc_chr(t, ' '); - t = object_desc_chr(t, p1); - t = object_desc_int(t, o_ptr->to_h); + t += fmt::format(" ({:+d}", o_ptr->to_h); if (!(f3 & (TR3_HIDE_TYPE)) || o_ptr->art_name) - t = object_desc_str(t, " to accuracy"); - t = object_desc_chr(t, p2); + { + t += " to accuracy"; + } + t += ')'; } /* Show the todam if needed */ else if (o_ptr->to_d) { - t = object_desc_chr(t, ' '); - t = object_desc_chr(t, p1); - t = object_desc_int(t, o_ptr->to_d); + t += fmt::format(" ({:+d}", o_ptr->to_d); if (!(f3 & (TR3_HIDE_TYPE)) || o_ptr->art_name) - t = object_desc_str(t, " to damage"); - t = object_desc_chr(t, p2); + { + t += " to damage"; + } + t += ')'; } } @@ -2152,49 +2005,37 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) /* Show the armor class info */ if (show_armour) { - t = object_desc_chr(t, ' '); - t = object_desc_chr(t, b1); - t = object_desc_num(t, o_ptr->ac); - t = object_desc_chr(t, ','); - t = object_desc_int(t, o_ptr->to_a); - t = object_desc_chr(t, b2); + t += fmt::format(" [{:d},{:+d}]", o_ptr->ac, o_ptr->to_a); } /* No base armor, but does increase armor */ else if (o_ptr->to_a) { - t = object_desc_chr(t, ' '); - t = object_desc_chr(t, b1); - t = object_desc_int(t, o_ptr->to_a); - t = object_desc_chr(t, b2); + t += fmt::format(" [{:+d}]", o_ptr->to_a); } } /* Hack -- always show base armor */ else if (show_armour) { - t = object_desc_chr(t, ' '); - t = object_desc_chr(t, b1); - t = object_desc_num(t, o_ptr->ac); - t = object_desc_chr(t, b2); + t += fmt::format(" [{:d}]", o_ptr->ac); } if ((f1 & TR1_MANA) && (known) && (o_ptr->pval > 0)) { - t = object_desc_chr(t, '('); - t = object_desc_num(t, 100 * o_ptr->pval / 5); - t = object_desc_str(t, "%)"); + t += fmt::format("({:d}%)", 100 * o_ptr->pval / 5); } if ((known) && (f2 & TR2_LIFE) ) /* Can disp neg now -- Improv */ { - t = object_desc_chr(t, '('); - t = object_desc_num(t, 100 * o_ptr->pval / 5); - t = object_desc_str(t, "%)"); + t += fmt::format("({:d}%)", 100 * o_ptr->pval / 5); } /* No more details wanted */ - if (mode < 2) goto copyback; + if (mode < 2) + { + return t; + } /* Hack -- Wands and Staffs have charges */ @@ -2202,13 +2043,8 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) ((o_ptr->tval == TV_STAFF) || (o_ptr->tval == TV_WAND))) { - /* Dump " (N charges)" */ - t = object_desc_chr(t, ' '); - t = object_desc_chr(t, p1); - t = object_desc_num(t, o_ptr->pval); - t = object_desc_str(t, " charge"); - if (o_ptr->pval != 1) t = object_desc_chr(t, 's'); - t = object_desc_chr(t, p2); + auto plural = (o_ptr->pval != 1) ? "s" : ""; + t += fmt::format(" ({:d} charge{})", o_ptr->pval, plural); } /* @@ -2216,12 +2052,7 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) */ else if (known && (o_ptr->tval == TV_ROD_MAIN)) { - /* Display prettily. */ - t = object_desc_str(t, " ("); - t = object_desc_num(t, o_ptr->timeout); - t = object_desc_chr(t, '/'); - t = object_desc_num(t, o_ptr->pval2); - t = object_desc_chr(t, ')'); + t += fmt::format(" ({:d}/{:d})", o_ptr->timeout, o_ptr->pval2); } /* @@ -2229,20 +2060,13 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) */ else if (known && (o_ptr->tval == TV_ROD)) { - /* Display prettily. */ - t = object_desc_str(t, " ("); - t = object_desc_num(t, o_ptr->pval); - t = object_desc_str(t, " Mana to cast"); - t = object_desc_chr(t, ')'); + t += fmt::format(" ({:d} Mana to cast)", o_ptr->pval); } /* Hack -- Process Lanterns/Torches */ else if ((o_ptr->tval == TV_LITE) && (f4 & TR4_FUEL_LITE)) { - /* Hack -- Turns of light for normal lites */ - t = object_desc_str(t, " (with "); - t = object_desc_num(t, o_ptr->timeout); - t = object_desc_str(t, " turns of light)"); + t += fmt::format(" (with {:d} turns of light)", o_ptr->timeout); } @@ -2250,11 +2074,7 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) if (known && ((f1 & (TR1_PVAL_MASK)) || (f5 & (TR5_PVAL_MASK)))) { /* Start the display */ - t = object_desc_chr(t, ' '); - t = object_desc_chr(t, p1); - - /* Dump the "pval" itself */ - t = object_desc_int(t, o_ptr->pval); + t += fmt::format(" ({:+d}", o_ptr->pval); /* Do not display the "pval" flags */ if (f3 & (TR3_HIDE_TYPE)) @@ -2265,46 +2085,41 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) /* Speed */ else if (f1 & (TR1_SPEED)) { - /* Dump " to speed" */ - t = object_desc_str(t, " to speed"); + t += " to speed"; } /* Attack speed */ else if (f1 & (TR1_BLOWS)) { - /* Add " attack" */ - t = object_desc_str(t, " attack"); - - /* Add "attacks" */ - if (ABS(o_ptr->pval) != 1) t = object_desc_chr(t, 's'); + t += " attack"; + if (ABS(o_ptr->pval) != 1) + { + t += 's'; + } } /* Critical chance */ else if (f5 & (TR5_CRIT)) { - /* Add " attack" */ - t = object_desc_str(t, "% of critical hits"); + t += "% of critical hits"; } /* Stealth */ else if (f1 & (TR1_STEALTH)) { - /* Dump " to stealth" */ - t = object_desc_str(t, " to stealth"); + t += " to stealth"; } /* Search */ else if (f1 & (TR1_SEARCH)) { - /* Dump " to searching" */ - t = object_desc_str(t, " to searching"); + t += " to searching"; } /* Infravision */ else if (f1 & (TR1_INFRA)) { - /* Dump " to infravision" */ - t = object_desc_str(t, " to infravision"); + t += " to infravision"; } /* Tunneling */ @@ -2314,116 +2129,111 @@ void object_desc(char *buf, object_type *o_ptr, int pref, int mode) } /* Finish the display */ - t = object_desc_chr(t, p2); + t += ')'; } /* Indicate "charging" artifacts XXX XXX XXX */ if (known && (f3 & TR3_ACTIVATE) && o_ptr->timeout) { - if(o_ptr->tval == TV_EGG) - /* Hack -- Dump " (stopped)" if relevant */ - t = object_desc_str(t, " (stopped)"); + if (o_ptr->tval == TV_EGG) + { + t += " (stopped)"; + } else - /* Hack -- Dump " (charging)" if relevant */ - t = object_desc_str(t, " (charging)"); + { + t += " (charging)"; + } } /* Indicate "charging" Mage Staffs XXX XXX XXX */ if (known && o_ptr->timeout && (is_ego_p(o_ptr, EGO_MSTAFF_SPELL))) { - /* Hack -- Dump " (charging spell1)" if relevant */ - t = object_desc_str(t, " (charging spell1)"); + t += " (charging spell1)"; } if (known && o_ptr->xtra2 && (is_ego_p(o_ptr, EGO_MSTAFF_SPELL))) { - /* Hack -- Dump " (charging spell2)" if relevant */ - t = object_desc_str(t, " (charging spell2)"); + t += " (charging spell2)"; } /* No more details wanted */ - if (mode < 3) goto copyback; - - - /* No inscription yet */ - tmp_val2[0] = '\0'; - - /* Sensed stuff */ - if (o_ptr->ident & (IDENT_SENSE)) + if (mode < 3) { - strcpy(tmp_val2, sense_desc[o_ptr->sense]); + return t; } - /* Hack - Note "cursed" if the item is 'known' and cursed */ - if (cursed_p(o_ptr) && (known) && (!tmp_val2[0])) - { - if (tmp_val2[0]) strcat(tmp_val2, ", "); - strcat(tmp_val2, "cursed"); - } - /* Use the standard inscription if available */ - if (o_ptr->note) + /* Inscribe */ { - char *u = tmp_val2; - - if (tmp_val2[0]) strcat(tmp_val2, ", "); - - strcat(tmp_val2, quark_str(o_ptr->note)); + std::vector inscrip; - for (; *u && (*u != '#') && (*u != '%'); u++); - - *u = '\0'; - } + /* Sensed stuff */ + if ((o_ptr->ident & (IDENT_SENSE)) && sense_desc[o_ptr->sense] && sense_desc[o_ptr->sense][0] != '\0') + { + inscrip.push_back(sense_desc[o_ptr->sense]); + } - /* Mega-Hack -- note empty wands/staffs */ - if (!known && (o_ptr->ident & (IDENT_EMPTY))) - { - if (tmp_val2[0]) strcat(tmp_val2, ", "); - strcat(tmp_val2, "empty"); - } + /* Hack - Note "cursed" if the item is 'known' and cursed */ + if (cursed_p(o_ptr) && known && inscrip.empty()) + { + inscrip.push_back("cursed"); + } - /* Note "tried" if the object has been tested unsuccessfully */ - if (!aware && object_tried_p(o_ptr)) - { - if (tmp_val2[0]) strcat(tmp_val2, ", "); - strcpy(tmp_val2, "tried"); - } + /* Use the standard inscription if available */ + if (o_ptr->note) + { + // Chop at '#' or '%' if present. The suffix of the + // '%' or '#' is handled elsewhere in this function. + std::string note = quark_str(o_ptr->note); + auto const pos = note.find_first_of("%#"); + if (pos > 0) + { + inscrip.push_back(note.substr(0, pos)); + } + } - /* Note the discount, if any */ - if ((o_ptr->discount) && (!tmp_val2[0])) - { - object_desc_num(tmp_val2, o_ptr->discount); - strcat(tmp_val2, "% off"); - } + /* Mega-Hack -- note empty wands/staffs */ + if (!known && (o_ptr->ident & (IDENT_EMPTY))) + { + inscrip.push_back("empty"); + } - /* Append the inscription, if any */ - if (tmp_val2[0]) - { - int n; + /* Note "tried" if the object has been tested unsuccessfully */ + if (!aware && object_tried_p(o_ptr)) + { + inscrip.push_back("tried"); + } - /* Hack -- How much so far */ - n = (t - tmp_val); + /* Note the discount, if any */ + if ((o_ptr->discount) && inscrip.empty()) + { + inscrip.push_back(fmt::format("{:d}% off", o_ptr->discount)); + } - /* Paranoia -- do not be stupid */ - if (n > 75) n = 75; + /* Append the inscription, if any */ + if (!inscrip.empty()) + { + auto inscrip_str = boost::algorithm::join(inscrip, ", "); - /* Hack -- shrink the inscription */ - tmp_val2[75 - n] = '\0'; + /* Make sure we don't exceed 75 characters */ + t.resize(std::min(t.size(), 75)); - /* Append the inscription */ - t = object_desc_chr(t, ' '); - t = object_desc_chr(t, c1); - t = object_desc_str(t, tmp_val2); - t = object_desc_chr(t, c2); + /* Append the inscription */ + t += fmt::format(" {{{}}}", inscrip_str); + } } -copyback: - /* Here's where we dump the built string into buf. */ - tmp_val[79] = '\0'; - t = tmp_val; - while ((*(buf++) = *(t++))); /* copy the string over */ + + return t; } +void object_desc(char *buf, object_type *o_ptr, int pref, int mode) +{ + auto s = object_desc_aux(o_ptr, pref, mode); + auto n = std::min(s.size(), 79); + s.copy(buf, n); + buf[n] = '\0'; +} /* * Hack -- describe an item currently in a store's inventory -- cgit v1.2.3 From f6812b19be995ddd26a318391a0f5311e4de11a6 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Thu, 10 Mar 2016 18:41:54 +0100 Subject: Rework scroll title generator to use std::string --- src/object1.cc | 39 ++++++++++++++------------------------- 1 file changed, 14 insertions(+), 25 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 096cadc5..cb935973 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -596,48 +596,37 @@ void flavor_init(void) /* Get a new title */ while (TRUE) { - char buf[80]; - - bool_ okay; - - /* Start a new title */ - buf[0] = '\0'; + std::string buf; /* Collect words until done */ while (1) { - int q, s; - - char tmp[80]; - - /* Start a new word */ - tmp[0] = '\0'; - /* Choose one or two syllables */ - s = ((rand_int(100) < 30) ? 1 : 2); + int s = ((rand_int(100) < 30) ? 1 : 2); /* Add a one or two syllable word */ - for (q = 0; q < s; q++) + std::string tmp; + for (int q = 0; q < s; q++) { - /* Add the syllable */ - strcat(tmp, syllables[rand_int(MAX_SYLLABLES)]); + tmp += syllables[rand_int(MAX_SYLLABLES)]; } /* Stop before getting too long */ - if (strlen(buf) + 1 + strlen(tmp) > 15) break; - - /* Add a space */ - strcat(buf, " "); + if (buf.size() + tmp.size() + 1 > 15) + { + break; + } - /* Add the word */ - strcat(buf, tmp); + /* Add the word with separator */ + buf += " "; + buf += tmp; } /* Save the title */ - strcpy(scroll_adj[i], buf + 1); + strcpy(scroll_adj[i], buf.c_str()); /* Assume okay */ - okay = TRUE; + bool_ okay = TRUE; /* Check for "duplicate" scroll titles */ for (j = 0; j < i; j++) -- cgit v1.2.3 From c999ae0630fbdc08b3e95f4d9987a69315f9713b Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sun, 27 Mar 2016 15:46:59 +0200 Subject: Tidy up variable initialization in object_desc_aux --- src/object1.cc | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index cb935973..78206f68 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -1129,9 +1129,6 @@ std::string object_desc_aux(object_type *o_ptr, int pref, int mode) { bool_ hack_name = FALSE; - bool_ aware = FALSE; - bool_ known = FALSE; - bool_ append_name = FALSE; bool_ show_weapon = FALSE; @@ -1143,12 +1140,11 @@ std::string object_desc_aux(object_type *o_ptr, int pref, int mode) u32b f1, f2, f3, f4, f5, esp; object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); - /* See if the object is "aware" */ - if (object_aware_p(o_ptr)) aware = TRUE; + bool_ aware = object_aware_p(o_ptr); /* See if the object is "known" */ - if (object_known_p(o_ptr)) known = TRUE; + bool_ known = object_known_p(o_ptr); /* Hack -- Extract the sub-type "indexx" */ auto const indexx = o_ptr->sval; -- cgit v1.2.3 From 0ec2cec5fad1f5cb1aa048b49bb67bfe493785e6 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Tue, 29 Mar 2016 20:32:55 +0200 Subject: Have RANDOM_{RESIST,POWER} avoid existing flags --- src/object1.cc | 51 +++++++-------------------------------------------- 1 file changed, 7 insertions(+), 44 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 78206f68..ae0317c7 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -850,40 +850,6 @@ static void object_flags_xtra(object_type const *o_ptr, u32b *f2, u32b *f3, u32b break; } - case EGO_XTRA_ABILITY: - { - /* Choose an ability */ - switch (o_ptr->xtra2 % 8) - { - case 0: - (*f3) |= (TR3_FEATHER); - break; - case 1: - (*f3) |= (TR3_LITE1); - break; - case 2: - (*f3) |= (TR3_SEE_INVIS); - break; - case 3: - (*esp) |= (ESP_ALL); - break; - case 4: - (*f3) |= (TR3_SLOW_DIGEST); - break; - case 5: - (*f3) |= (TR3_REGEN); - break; - case 6: - (*f2) |= (TR2_FREE_ACT); - break; - case 7: - (*f2) |= (TR2_HOLD_LIFE); - break; - } - - break; - } - } } @@ -920,16 +886,13 @@ void object_flags(object_type const *o_ptr, u32b *f1, u32b *f2, u32b *f3, u32b * apply_flags_set(o_ptr->name1, a_ptr->set, f1, f2, f3, f4, f5, esp); } - /* Random artifact ! */ - if (o_ptr->art_flags1 || o_ptr->art_flags2 || o_ptr->art_flags3 || o_ptr->art_flags4 || o_ptr->art_flags5 || o_ptr->art_esp) - { - (*f1) |= o_ptr->art_flags1; - (*f2) |= o_ptr->art_flags2; - (*f3) |= o_ptr->art_flags3; - (*f4) |= o_ptr->art_flags4; - (*f5) |= o_ptr->art_flags5; - (*esp) |= o_ptr->art_esp; - } + /* Mix in art_{flagsX,esp} */ + (*f1) |= o_ptr->art_flags1; + (*f2) |= o_ptr->art_flags2; + (*f3) |= o_ptr->art_flags3; + (*f4) |= o_ptr->art_flags4; + (*f5) |= o_ptr->art_flags5; + (*esp) |= o_ptr->art_esp; /* Extra powers */ if (!(o_ptr->art_name)) -- cgit v1.2.3 From fc2af69bd5c33cde0f340cfb9f2707765ce68029 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 20 Jun 2016 22:49:05 +0200 Subject: Fix issue with leading space for scroll flavors --- src/object1.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index ae0317c7..7a462b41 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -618,7 +618,10 @@ void flavor_init(void) } /* Add the word with separator */ - buf += " "; + if (buf.size() > 0) + { + buf += " "; + } buf += tmp; } -- cgit v1.2.3 From 68e2a10b2d76cb3a2f5aa6818b4b184b6a02ef14 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 20 Jun 2016 22:49:05 +0200 Subject: Rework RF{1,2,3,7,8,9}_* monster flags to use flag_set<> --- src/object1.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 7a462b41..1aaf2a6c 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -26,6 +26,7 @@ #include "monster2.hpp" #include "monster_ego.hpp" #include "monster_race.hpp" +#include "monster_race_flag.hpp" #include "monster_type.hpp" #include "object2.hpp" #include "object_kind.hpp" @@ -1374,7 +1375,7 @@ std::string object_desc_aux(object_type *o_ptr, int pref, int mode) { monster_race* r_ptr = &r_info[o_ptr->pval2]; modstr = basenm; - if (r_ptr->flags1 & RF1_UNIQUE) + if (r_ptr->flags & RF_UNIQUE) { basenm = fmt::format("& {}'s #~", r_ptr->name); } @@ -1531,11 +1532,11 @@ std::string object_desc_aux(object_type *o_ptr, int pref, int mode) t += ' '; } - else if ((o_ptr->tval == TV_CORPSE) && (r_ptr->flags1 & RF1_UNIQUE)) + else if ((o_ptr->tval == TV_CORPSE) && (r_ptr->flags & RF_UNIQUE)) {} - else if ((o_ptr->tval == TV_HYPNOS) && (r_ptr->flags1 & RF1_UNIQUE)) + else if ((o_ptr->tval == TV_HYPNOS) && (r_ptr->flags & RF_UNIQUE)) {} /* Hack -- The only one of its kind */ -- cgit v1.2.3 From 61a9e3c08009d143def75765169ed844944c370e Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 20 Jun 2016 22:49:05 +0200 Subject: Add "const" qualifiers --- src/object1.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 1aaf2a6c..fd3ab769 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -1092,7 +1092,7 @@ s32b calc_object_need_exp(object_type const *o_ptr) * 2 -- The Cloak of Death [1,+3] (+2 to Stealth) * 3 -- The Cloak of Death [1,+3] (+2 to Stealth) {nifty} */ -std::string object_desc_aux(object_type *o_ptr, int pref, int mode) +static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) { bool_ hack_name = FALSE; @@ -2179,7 +2179,7 @@ std::string object_desc_aux(object_type *o_ptr, int pref, int mode) return t; } -void object_desc(char *buf, object_type *o_ptr, int pref, int mode) +void object_desc(char *buf, object_type const *o_ptr, int pref, int mode) { auto s = object_desc_aux(o_ptr, pref, mode); auto n = std::min(s.size(), 79); @@ -4154,7 +4154,7 @@ void display_equip(void) /* Get the color of the letter idx */ -byte get_item_letter_color(object_type *o_ptr) +byte get_item_letter_color(object_type const *o_ptr) { byte color = TERM_WHITE; -- cgit v1.2.3 From 2fcc9f1712b630055ae9ce5c3ecf017b8a93fbbb Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 20 Jun 2016 22:49:05 +0200 Subject: Change flags_group to non-POD type --- src/object1.cc | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index fd3ab769..ae803db9 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -2667,19 +2667,17 @@ bool_ object_out_desc(object_type *o_ptr, FILE *fff, bool_ trim_down, bool_ wait if ((f4 & TR4_LEVELS) && (!trim_down)) { - int j = 0; - if (count_bits(o_ptr->pval3) == 0) text_out("It is sentient"); else if (count_bits(o_ptr->pval3) > 1) text_out("It is sentient and can have access to the realms of "); else text_out("It is sentient and can have access to the realm of "); bool_ first = TRUE; - for (j = 0; j < MAX_FLAG_GROUP; j++) + for (std::size_t j = 0; j < flags_groups().size(); j++) { if (BIT(j) & o_ptr->pval3) { check_first(&first); - text_out_c(flags_groups[j].color, flags_groups[j].name); + text_out_c(flags_groups()[j].color, flags_groups()[j].name); } } @@ -6057,13 +6055,13 @@ static void gain_flag_group(object_type *o_ptr) while (tries--) { - grp = rand_int(MAX_FLAG_GROUP); + grp = rand_int(flags_groups().size()); /* If we already got this group continue */ if (o_ptr->pval3 & BIT(grp)) continue; /* Not enough points ? */ - if (flags_groups[grp].price > o_ptr->pval2) continue; + if (flags_groups()[grp].price > o_ptr->pval2) continue; /* Ok, enough points and not already got it */ break; @@ -6072,7 +6070,7 @@ static void gain_flag_group(object_type *o_ptr) /* Ack, nothing found */ if (tries <= 1) return; - o_ptr->pval2 -= flags_groups[grp].price; + o_ptr->pval2 -= flags_groups()[grp].price; o_ptr->pval3 |= BIT(grp); /* Message */ @@ -6080,7 +6078,7 @@ static void gain_flag_group(object_type *o_ptr) char o_name[80]; object_desc(o_name, o_ptr, FALSE, 0); - msg_format("%s gains access to the %s realm.", o_name, flags_groups[grp].name); + msg_format("%s gains access to the %s realm.", o_name, flags_groups()[grp].name); } } @@ -6097,27 +6095,27 @@ static u32b get_flag(object_type *o_ptr, int grp, int k) switch (k) { case 0: - flag_set = flags_groups[grp].flags1; + flag_set = flags_groups()[grp].flags1; flag_test = f1; break; case 1: - flag_set = flags_groups[grp].flags2; + flag_set = flags_groups()[grp].flags2; flag_test = f2; break; case 2: - flag_set = flags_groups[grp].flags3; + flag_set = flags_groups()[grp].flags3; flag_test = f3; break; case 3: - flag_set = flags_groups[grp].flags4; + flag_set = flags_groups()[grp].flags4; flag_test = f4; break; case 4: - flag_set = flags_groups[grp].esp; + flag_set = flags_groups()[grp].esp; flag_test = esp; break; default: - flag_set = flags_groups[grp].flags1; + flag_set = flags_groups()[grp].flags1; flag_test = f1; break; } @@ -6159,7 +6157,7 @@ static void gain_flag_group_flag(object_type *o_ptr) k = rand_int(5); /* get a flag group */ - grp = rand_int(MAX_FLAG_GROUP); + grp = rand_int(flags_groups().size()); if (!(BIT(grp) & o_ptr->pval3)) continue; @@ -6197,7 +6195,7 @@ static void gain_flag_group_flag(object_type *o_ptr) char o_name[80]; object_desc(o_name, o_ptr, FALSE, 0); - msg_format("%s gains a new power from the %s realm.", o_name, flags_groups[grp].name); + msg_format("%s gains a new power from the %s realm.", o_name, flags_groups()[grp].name); } } -- cgit v1.2.3 From 9dd2f09626ad96caae709ce1fb51c7e87ee00d36 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 20 Jun 2016 22:49:05 +0200 Subject: Fix extraneous space in light descriptions --- src/object1.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index ae803db9..d68775df 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -2018,7 +2018,7 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) /* Hack -- Process Lanterns/Torches */ else if ((o_ptr->tval == TV_LITE) && (f4 & TR4_FUEL_LITE)) { - t += fmt::format(" (with {:d} turns of light)", o_ptr->timeout); + t += fmt::format(" (with {:d} turns of light)", o_ptr->timeout); } -- cgit v1.2.3 From 073ad3584fbf781ce10bef61ad4ff38850282f47 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Tue, 21 Jun 2016 13:37:02 +0200 Subject: Rework TR{1,2,3,4,5}_* flags to flag_set<> --- src/object1.cc | 871 +++++++++++++++++++++++++++------------------------------ 1 file changed, 417 insertions(+), 454 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index d68775df..5aa53c7f 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -29,6 +29,9 @@ #include "monster_race_flag.hpp" #include "monster_type.hpp" #include "object2.hpp" +#include "object_flag.hpp" +#include "object_flag_meta.hpp" +#include "object_flag_set.hpp" #include "object_kind.hpp" #include "object_type.hpp" #include "options.hpp" @@ -60,8 +63,7 @@ using boost::starts_with; -static bool_ apply_flags_set(s16b a_idx, s16b set_idx, - u32b *f1, u32b *f2, u32b *f3, u32b *f4, u32b *f5, u32b *esp); +static void apply_flags_set(s16b a_idx, s16b set_idx, object_flag_set *f); /* * Hack -- note that "TERM_MULTI" is now just "TERM_VIOLET". @@ -433,7 +435,7 @@ static bool_ object_easy_know(int i) case TV_ROD: case TV_ROD_MAIN: { - if (k_ptr->flags3 & TR3_NORM_ART) + if (k_ptr->flags & TR_NORM_ART) return ( FALSE ); return (TRUE); } @@ -443,7 +445,7 @@ static bool_ object_easy_know(int i) case TV_AMULET: case TV_LITE: { - if (k_ptr->flags3 & (TR3_EASY_KNOW)) return (TRUE); + if (k_ptr->flags & TR_EASY_KNOW) return (TRUE); return (FALSE); } } @@ -779,8 +781,15 @@ void reset_visuals(void) /* * Extract "xtra" flags from object. */ -static void object_flags_xtra(object_type const *o_ptr, u32b *f2, u32b *f3, u32b *esp) +static void object_flags_xtra(object_type const *o_ptr, object_flag_set *f) { + // Artifacts don't get *ego* extra powers. + if (o_ptr->art_name) + { + return; + } + + // Add sustain or power. switch (o_ptr->xtra1) { case EGO_XTRA_SUSTAIN: @@ -789,22 +798,22 @@ static void object_flags_xtra(object_type const *o_ptr, u32b *f2, u32b *f3, u32b switch (o_ptr->xtra2 % 6) { case 0: - (*f2) |= (TR2_SUST_STR); + (*f) |= TR_SUST_STR; break; case 1: - (*f2) |= (TR2_SUST_INT); + (*f) |= TR_SUST_INT; break; case 2: - (*f2) |= (TR2_SUST_WIS); + (*f) |= TR_SUST_WIS; break; case 3: - (*f2) |= (TR2_SUST_DEX); + (*f) |= TR_SUST_DEX; break; case 4: - (*f2) |= (TR2_SUST_CON); + (*f) |= TR_SUST_CON; break; case 5: - (*f2) |= (TR2_SUST_CHR); + (*f) |= TR_SUST_CHR; break; } @@ -817,37 +826,37 @@ static void object_flags_xtra(object_type const *o_ptr, u32b *f2, u32b *f3, u32b switch (o_ptr->xtra2 % 11) { case 0: - (*f2) |= (TR2_RES_BLIND); + (*f) |= TR_RES_BLIND; break; case 1: - (*f2) |= (TR2_RES_CONF); + (*f) |= TR_RES_CONF; break; case 2: - (*f2) |= (TR2_RES_SOUND); + (*f) |= TR_RES_SOUND; break; case 3: - (*f2) |= (TR2_RES_SHARDS); + (*f) |= TR_RES_SHARDS; break; case 4: - (*f2) |= (TR2_RES_NETHER); + (*f) |= TR_RES_NETHER; break; case 5: - (*f2) |= (TR2_RES_NEXUS); + (*f) |= TR_RES_NEXUS; break; case 6: - (*f2) |= (TR2_RES_CHAOS); + (*f) |= TR_RES_CHAOS; break; case 7: - (*f2) |= (TR2_RES_DISEN); + (*f) |= TR_RES_DISEN; break; case 8: - (*f2) |= (TR2_RES_POIS); + (*f) |= TR_RES_POIS; break; case 9: - (*f2) |= (TR2_RES_DARK); + (*f) |= TR_RES_DARK; break; case 10: - (*f2) |= (TR2_RES_LITE); + (*f) |= TR_RES_LITE; break; } @@ -857,52 +866,41 @@ static void object_flags_xtra(object_type const *o_ptr, u32b *f2, u32b *f3, u32b } } +/* + * Disregard sets when calculating flags? + */ +bool_ object_flags_no_set = FALSE; /* * Obtain the "flags" for an item */ -bool_ object_flags_no_set = FALSE; -void object_flags(object_type const *o_ptr, u32b *f1, u32b *f2, u32b *f3, u32b *f4, u32b *f5, u32b *esp) +object_flag_set object_flags(object_type const *o_ptr) { object_kind *k_ptr = &k_info[o_ptr->k_idx]; /* Base object */ - (*f1) = k_ptr->flags1; - (*f2) = k_ptr->flags2; - (*f3) = k_ptr->flags3; - (*f4) = k_ptr->flags4; - (*f5) = k_ptr->flags5; - (*esp) = k_ptr->esp; + auto f = k_ptr->flags; /* Artifact */ if (o_ptr->name1) { artifact_type *a_ptr = &a_info[o_ptr->name1]; - (*f1) = a_ptr->flags1; - (*f2) = a_ptr->flags2; - (*f3) = a_ptr->flags3; - (*f4) = a_ptr->flags4; - (*f5) = a_ptr->flags5; - (*esp) = a_ptr->esp; + f = a_ptr->flags; if ((!object_flags_no_set) && (a_ptr->set != -1)) - apply_flags_set(o_ptr->name1, a_ptr->set, f1, f2, f3, f4, f5, esp); + { + apply_flags_set(o_ptr->name1, a_ptr->set, &f); + } } - /* Mix in art_{flagsX,esp} */ - (*f1) |= o_ptr->art_flags1; - (*f2) |= o_ptr->art_flags2; - (*f3) |= o_ptr->art_flags3; - (*f4) |= o_ptr->art_flags4; - (*f5) |= o_ptr->art_flags5; - (*esp) |= o_ptr->art_esp; + /* Mix in art_{flags,esp} */ + f |= o_ptr->art_flags; /* Extra powers */ - if (!(o_ptr->art_name)) - { - object_flags_xtra(o_ptr, f2, f3, esp); - } + object_flags_xtra(o_ptr, &f); + + return f; } /* Return object granted power */ @@ -945,30 +943,21 @@ int object_power(object_type *o_ptr) /* * Obtain the "flags" for an item which are known to the player */ -void object_flags_known(object_type const *o_ptr, u32b *f1, u32b *f2, u32b *f3, u32b *f4, u32b *f5, u32b *esp) +object_flag_set object_flags_known(object_type const *o_ptr) { object_kind *k_ptr = &k_info[o_ptr->k_idx]; - /* Clear */ - (*f1) = (*f2) = (*f3) = (*f4) = (*esp) = (*f5) = 0L; - /* Must be identified */ - if (!object_known_p(o_ptr)) return; + if (!object_known_p(o_ptr)) + { + return object_flag_set(); + } /* Base object */ - (*f1) = k_ptr->flags1; - (*f2) = k_ptr->flags2; - (*f3) = k_ptr->flags3; - (*f4) = k_ptr->flags4; - (*f5) = k_ptr->flags5; - (*esp) = k_ptr->esp; - - (*f1) |= k_ptr->oflags1; - (*f2) |= k_ptr->oflags2; - (*f3) |= k_ptr->oflags3; - (*f4) |= k_ptr->oflags4; - (*f5) |= k_ptr->oflags5; - (*esp) |= k_ptr->oesp; + auto flags = k_ptr->flags; + + /* Obvious flags */ + flags |= k_ptr->oflags; /* Artifact */ if (o_ptr->name1) @@ -978,61 +967,50 @@ void object_flags_known(object_type const *o_ptr, u32b *f1, u32b *f2, u32b *f3, /* Need full knowledge or spoilers */ if ((o_ptr->ident & IDENT_MENTAL)) { - (*f1) = a_ptr->flags1; - (*f2) = a_ptr->flags2; - (*f3) = a_ptr->flags3; - (*f4) = a_ptr->flags4; - (*f5) = a_ptr->flags5; - (*esp) = a_ptr->esp; + flags = a_ptr->flags; if ((!object_flags_no_set) && (a_ptr->set != -1)) - apply_flags_set(o_ptr->name1, a_ptr->set, f1, f2, f3, f4, f5, esp); + { + apply_flags_set(o_ptr->name1, a_ptr->set, &flags); + } } else { - (*f1) = (*f2) = (*f3) = (*f4) = (*esp) = (*f5) = 0L; + flags = object_flag_set(); } - (*f1) |= a_ptr->oflags1; - (*f2) |= a_ptr->oflags2; - (*f3) |= a_ptr->oflags3; - (*f4) |= a_ptr->oflags4; - (*f5) |= a_ptr->oflags5; - (*esp) |= a_ptr->oesp; + flags |= a_ptr->oflags; } /* Random artifact or ego item! */ - if (o_ptr->art_flags1 || o_ptr->art_flags2 || o_ptr->art_flags3 || o_ptr->art_flags4 || o_ptr->art_flags5 || o_ptr->art_esp) + if (o_ptr->art_flags) { /* Need full knowledge or spoilers */ if ((o_ptr->ident & IDENT_MENTAL)) { - (*f1) |= o_ptr->art_flags1; - (*f2) |= o_ptr->art_flags2; - (*f3) |= o_ptr->art_flags3; - (*f4) |= o_ptr->art_flags4; - (*f5) |= o_ptr->art_flags5; - (*esp) |= o_ptr->art_esp; + flags |= o_ptr->art_flags; } - (*f1) |= o_ptr->art_oflags1; - (*f2) |= o_ptr->art_oflags2; - (*f3) |= o_ptr->art_oflags3; - (*f4) |= o_ptr->art_oflags4; - (*f5) |= o_ptr->art_oflags5; - (*esp) |= o_ptr->art_oesp; + flags |= o_ptr->art_oflags; } /* Full knowledge for *identified* objects */ - if (!(o_ptr->ident & IDENT_MENTAL)) return; - - if (!(o_ptr->art_name)) + if (!(o_ptr->ident & IDENT_MENTAL)) { - object_flags_xtra(o_ptr, f2, f3, esp); + return flags; } + /* Extra powers */ + object_flags_xtra(o_ptr, &flags); + /* Hack - Res Chaos -> Res Confusion */ - if (*f2 & TR2_RES_CHAOS) (*f2) |= (TR2_RES_CONF); + if (flags & TR_RES_CHAOS) + { + flags |= TR_RES_CONF; + } + + // Done + return flags; } @@ -1046,6 +1024,23 @@ s32b calc_object_need_exp(object_type const *o_ptr) } +/** + * Calculate the PVAL mask. + */ +static object_flag_set compute_pval_mask() +{ + object_flag_set f; + for (auto const object_flag_meta: object_flags_meta()) + { + if (object_flag_meta->is_pval) + { + f |= object_flag_meta->flag_set; + } + } + return f; +} + + /* * Creates a description of the item "o_ptr", and stores it in "out_val". @@ -1094,6 +1089,8 @@ s32b calc_object_need_exp(object_type const *o_ptr) */ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) { + static auto const TR_PVAL_MASK = compute_pval_mask(); + bool_ hack_name = FALSE; bool_ append_name = FALSE; @@ -1104,8 +1101,7 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) object_kind *k_ptr = &k_info[o_ptr->k_idx]; /* Extract some flags */ - u32b f1, f2, f3, f4, f5, esp; - object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); + auto const flags = object_flags(o_ptr); /* See if the object is "aware" */ bool_ aware = object_aware_p(o_ptr); @@ -1468,7 +1464,7 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) } /* Mega Hack */ - if ((!hack_name) && known && (k_ptr->flags5 & TR5_FULL_NAME)) + if ((!hack_name) && known && (k_ptr->flags & TR_FULL_NAME)) { basenm = k_ptr->name; } @@ -1804,7 +1800,7 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) } /* It contains a spell */ - if ((known) && (f5 & TR5_SPELL_CONTAIN) && (o_ptr->pval2 != -1)) + if (known && (flags & TR_SPELL_CONTAIN) && (o_ptr->pval2 != -1)) { t += fmt::format(" [{}]", spell_type_name(spell_at(o_ptr->pval2))); } @@ -1822,7 +1818,7 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) } /* Hack -- Some objects can have an exp level */ - if ((f4 & TR4_LEVELS) && known) + if ((flags & TR_LEVELS) && known) { auto need_exp = (o_ptr->elevel < PY_MAX_LEVEL) ? std::to_string(calc_object_need_exp(o_ptr) - o_ptr->exp) @@ -1865,7 +1861,7 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) /* Display the item like a weapon */ - if (f3 & (TR3_SHOW_MODS)) show_weapon = TRUE; + if (flags & TR_SHOW_MODS) show_weapon = TRUE; /* Display the item like a weapon */ if (o_ptr->to_h && o_ptr->to_d) show_weapon = TRUE; @@ -1908,7 +1904,7 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) s32b power = (o_ptr->sval % 10); /* Apply the "Extra Might" flag */ - if (f3 & (TR3_XTRA_MIGHT)) power += o_ptr->pval; + if (flags & TR_XTRA_MIGHT) power += o_ptr->pval; /* Append a special "damage" string */ t += fmt::format(" (x{:d})", power); @@ -1931,7 +1927,7 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) else if (o_ptr->to_h) { t += fmt::format(" ({:+d}", o_ptr->to_h); - if (!(f3 & (TR3_HIDE_TYPE)) || o_ptr->art_name) + if (!(flags & TR_HIDE_TYPE) || o_ptr->art_name) { t += " to accuracy"; } @@ -1942,7 +1938,7 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) else if (o_ptr->to_d) { t += fmt::format(" ({:+d}", o_ptr->to_d); - if (!(f3 & (TR3_HIDE_TYPE)) || o_ptr->art_name) + if (!(flags & TR_HIDE_TYPE) || o_ptr->art_name) { t += " to damage"; } @@ -1973,12 +1969,12 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) t += fmt::format(" [{:d}]", o_ptr->ac); } - if ((f1 & TR1_MANA) && (known) && (o_ptr->pval > 0)) + if ((flags & TR_MANA) && known && (o_ptr->pval > 0)) { t += fmt::format("({:d}%)", 100 * o_ptr->pval / 5); } - if ((known) && (f2 & TR2_LIFE) ) /* Can disp neg now -- Improv */ + if (known && (flags & TR_LIFE) ) /* Can disp neg now -- Improv */ { t += fmt::format("({:d}%)", 100 * o_ptr->pval / 5); } @@ -2016,32 +2012,32 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) } /* Hack -- Process Lanterns/Torches */ - else if ((o_ptr->tval == TV_LITE) && (f4 & TR4_FUEL_LITE)) + else if ((o_ptr->tval == TV_LITE) && (flags & TR_FUEL_LITE)) { t += fmt::format(" (with {:d} turns of light)", o_ptr->timeout); } /* Dump "pval" flags for wearable items */ - if (known && ((f1 & (TR1_PVAL_MASK)) || (f5 & (TR5_PVAL_MASK)))) + if (known && (flags & TR_PVAL_MASK)) { /* Start the display */ t += fmt::format(" ({:+d}", o_ptr->pval); /* Do not display the "pval" flags */ - if (f3 & (TR3_HIDE_TYPE)) + if (flags & TR_HIDE_TYPE) { /* Nothing */ } /* Speed */ - else if (f1 & (TR1_SPEED)) + else if (flags & TR_SPEED) { t += " to speed"; } /* Attack speed */ - else if (f1 & (TR1_BLOWS)) + else if (flags & TR_BLOWS) { t += " attack"; if (ABS(o_ptr->pval) != 1) @@ -2051,31 +2047,31 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) } /* Critical chance */ - else if (f5 & (TR5_CRIT)) + else if (flags & TR_CRIT) { t += "% of critical hits"; } /* Stealth */ - else if (f1 & (TR1_STEALTH)) + else if (flags & TR_STEALTH) { t += " to stealth"; } /* Search */ - else if (f1 & (TR1_SEARCH)) + else if (flags & TR_SEARCH) { t += " to searching"; } /* Infravision */ - else if (f1 & (TR1_INFRA)) + else if (flags & TR_INFRA) { t += " to infravision"; } /* Tunneling */ - else if (f1 & (TR1_TUNNEL)) + else if (flags & TR_TUNNEL) { /* Nothing */ } @@ -2086,7 +2082,7 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) /* Indicate "charging" artifacts XXX XXX XXX */ - if (known && (f3 & TR3_ACTIVATE) && o_ptr->timeout) + if (known && (flags & TR_ACTIVATE) && o_ptr->timeout) { if (o_ptr->tval == TV_EGG) { @@ -2227,16 +2223,14 @@ void object_desc_store(char *buf, object_type *o_ptr, int pref, int mode) */ cptr item_activation(object_type *o_ptr, byte num) { - u32b f1, f2, f3, f4, f5, esp; - /* Needed hacks */ static char rspell[2][80]; /* Extract the flags */ - object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); + auto const flags = object_flags(o_ptr); /* Require activation ability */ - if (!(f3 & (TR3_ACTIVATE))) return (NULL); + if (!(flags & TR_ACTIVATE)) return (NULL); /* @@ -2366,12 +2360,11 @@ void output_dam(object_type *o_ptr, int mult, int mult2, cptr against, cptr agai void display_weapon_damage(object_type *o_ptr) { object_type forge, *old_ptr = &forge; - u32b f1, f2, f3, f4, f5, esp; bool_ first = TRUE; bool_ full = o_ptr->ident & (IDENT_MENTAL); /* Extract the flags */ - object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); + auto const flags = object_flags(o_ptr); /* Ok now the hackish stuff, we replace the current weapon with this one */ object_copy(old_ptr, &p_ptr->inventory[INVEN_WIELD]); @@ -2382,23 +2375,23 @@ void display_weapon_damage(object_type *o_ptr) text_out_c(TERM_L_GREEN, format("%d ", p_ptr->num_blow)); text_out(format("blow%s and do an average damage per turn of ", (p_ptr->num_blow) ? "s" : "")); - if (full && (f1 & TR1_SLAY_ANIMAL)) output_dam(o_ptr, 2, 0, "animals", NULL, &first); - if (full && (f1 & TR1_SLAY_EVIL)) output_dam(o_ptr, 2, 0, "evil creatures", NULL, &first); - if (full && (f1 & TR1_SLAY_ORC)) output_dam(o_ptr, 3, 0, "orcs", NULL, &first); - if (full && (f1 & TR1_SLAY_TROLL)) output_dam(o_ptr, 3, 0, "trolls", NULL, &first); - if (full && (f1 & TR1_SLAY_GIANT)) output_dam(o_ptr, 3, 0, "giants", NULL, &first); - if (full && (f1 & TR1_KILL_DRAGON)) output_dam(o_ptr, 5, 0, "dragons", NULL, &first); - else if (full && (f1 & TR1_SLAY_DRAGON)) output_dam(o_ptr, 3, 0, "dragons", NULL, &first); - if (full && (f5 & TR5_KILL_UNDEAD)) output_dam(o_ptr, 5, 0, "undead", NULL, &first); - else if (full && (f1 & TR1_SLAY_UNDEAD)) output_dam(o_ptr, 3, 0, "undead", NULL, &first); - if (full && (f5 & TR5_KILL_DEMON)) output_dam(o_ptr, 5, 0, "demons", NULL, &first); - else if (full && (f1 & TR1_SLAY_DEMON)) output_dam(o_ptr, 3, 0, "demons", NULL, &first); - - if (full && (f1 & TR1_BRAND_FIRE)) output_dam(o_ptr, 3, 6, "non fire resistant creatures", "fire susceptible creatures", &first); - if (full && (f1 & TR1_BRAND_COLD)) output_dam(o_ptr, 3, 6, "non cold resistant creatures", "cold susceptible creatures", &first); - if (full && (f1 & TR1_BRAND_ELEC)) output_dam(o_ptr, 3, 6, "non lightning resistant creatures", "lightning susceptible creatures", &first); - if (full && (f1 & TR1_BRAND_ACID)) output_dam(o_ptr, 3, 6, "non acid resistant creatures", "acid susceptible creatures", &first); - if (full && (f1 & TR1_BRAND_POIS)) output_dam(o_ptr, 3, 6, "non poison resistant creatures", "poison susceptible creatures", &first); + if (full && (flags & TR_SLAY_ANIMAL)) output_dam(o_ptr, 2, 0, "animals", NULL, &first); + if (full && (flags & TR_SLAY_EVIL)) output_dam(o_ptr, 2, 0, "evil creatures", NULL, &first); + if (full && (flags & TR_SLAY_ORC)) output_dam(o_ptr, 3, 0, "orcs", NULL, &first); + if (full && (flags & TR_SLAY_TROLL)) output_dam(o_ptr, 3, 0, "trolls", NULL, &first); + if (full && (flags & TR_SLAY_GIANT)) output_dam(o_ptr, 3, 0, "giants", NULL, &first); + if (full && (flags & TR_KILL_DRAGON)) output_dam(o_ptr, 5, 0, "dragons", NULL, &first); + else if (full && (flags & TR_SLAY_DRAGON)) output_dam(o_ptr, 3, 0, "dragons", NULL, &first); + if (full && (flags & TR_KILL_UNDEAD)) output_dam(o_ptr, 5, 0, "undead", NULL, &first); + else if (full && (flags & TR_SLAY_UNDEAD)) output_dam(o_ptr, 3, 0, "undead", NULL, &first); + if (full && (flags & TR_KILL_DEMON)) output_dam(o_ptr, 5, 0, "demons", NULL, &first); + else if (full && (flags & TR_SLAY_DEMON)) output_dam(o_ptr, 3, 0, "demons", NULL, &first); + + if (full && (flags & TR_BRAND_FIRE)) output_dam(o_ptr, 3, 6, "non fire resistant creatures", "fire susceptible creatures", &first); + if (full && (flags & TR_BRAND_COLD)) output_dam(o_ptr, 3, 6, "non cold resistant creatures", "cold susceptible creatures", &first); + if (full && (flags & TR_BRAND_ELEC)) output_dam(o_ptr, 3, 6, "non lightning resistant creatures", "lightning susceptible creatures", &first); + if (full && (flags & TR_BRAND_ACID)) output_dam(o_ptr, 3, 6, "non acid resistant creatures", "acid susceptible creatures", &first); + if (full && (flags & TR_BRAND_POIS)) output_dam(o_ptr, 3, 6, "non poison resistant creatures", "poison susceptible creatures", &first); output_dam(o_ptr, 1, 0, (first) ? "all monsters" : "other monsters", NULL, &first); @@ -2465,35 +2458,34 @@ void output_ammo_dam(object_type *o_ptr, int mult, int mult2, cptr against, cptr */ void display_ammo_damage(object_type *o_ptr) { - u32b f1, f2, f3, f4, f5, esp; bool_ first = TRUE; int i; bool_ full = o_ptr->ident & (IDENT_MENTAL); /* Extract the flags */ - object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); + auto const flags = object_flags(o_ptr); if (o_ptr->tval == TV_BOOMERANG) text_out("\nUsing it you would do an average damage per throw of "); else text_out("\nUsing it with your current shooter you would do an average damage per shot of "); - if (full && (f1 & TR1_SLAY_ANIMAL)) output_ammo_dam(o_ptr, 2, 0, "animals", NULL, &first); - if (full && (f1 & TR1_SLAY_EVIL)) output_ammo_dam(o_ptr, 2, 0, "evil creatures", NULL, &first); - if (full && (f1 & TR1_SLAY_ORC)) output_ammo_dam(o_ptr, 3, 0, "orcs", NULL, &first); - if (full && (f1 & TR1_SLAY_TROLL)) output_ammo_dam(o_ptr, 3, 0, "trolls", NULL, &first); - if (full && (f1 & TR1_SLAY_GIANT)) output_ammo_dam(o_ptr, 3, 0, "giants", NULL, &first); - if (full && (f1 & TR1_KILL_DRAGON)) output_ammo_dam(o_ptr, 5, 0, "dragons", NULL, &first); - else if (full && (f1 & TR1_SLAY_DRAGON)) output_ammo_dam(o_ptr, 3, 0, "dragons", NULL, &first); - if (full && (f5 & TR5_KILL_UNDEAD)) output_ammo_dam(o_ptr, 5, 0, "undeads", NULL, &first); - else if (full && (f1 & TR1_SLAY_UNDEAD)) output_ammo_dam(o_ptr, 3, 0, "undeads", NULL, &first); - if (full && (f5 & TR5_KILL_DEMON)) output_ammo_dam(o_ptr, 5, 0, "demons", NULL, &first); - else if (full && (f1 & TR1_SLAY_DEMON)) output_ammo_dam(o_ptr, 3, 0, "demons", NULL, &first); - - if (full && (f1 & TR1_BRAND_FIRE)) output_ammo_dam(o_ptr, 3, 6, "non fire resistant creatures", "fire susceptible creatures", &first); - if (full && (f1 & TR1_BRAND_COLD)) output_ammo_dam(o_ptr, 3, 6, "non cold resistant creatures", "cold susceptible creatures", &first); - if (full && (f1 & TR1_BRAND_ELEC)) output_ammo_dam(o_ptr, 3, 6, "non lightning resistant creatures", "lightning susceptible creatures", &first); - if (full && (f1 & TR1_BRAND_ACID)) output_ammo_dam(o_ptr, 3, 6, "non acid resistant creatures", "acid susceptible creatures", &first); - if (full && (f1 & TR1_BRAND_POIS)) output_ammo_dam(o_ptr, 3, 6, "non poison resistant creatures", "poison susceptible creatures", &first); + if (full && (flags & TR_SLAY_ANIMAL)) output_ammo_dam(o_ptr, 2, 0, "animals", NULL, &first); + if (full && (flags & TR_SLAY_EVIL)) output_ammo_dam(o_ptr, 2, 0, "evil creatures", NULL, &first); + if (full && (flags & TR_SLAY_ORC)) output_ammo_dam(o_ptr, 3, 0, "orcs", NULL, &first); + if (full && (flags & TR_SLAY_TROLL)) output_ammo_dam(o_ptr, 3, 0, "trolls", NULL, &first); + if (full && (flags & TR_SLAY_GIANT)) output_ammo_dam(o_ptr, 3, 0, "giants", NULL, &first); + if (full && (flags & TR_KILL_DRAGON)) output_ammo_dam(o_ptr, 5, 0, "dragons", NULL, &first); + else if (full && (flags & TR_SLAY_DRAGON)) output_ammo_dam(o_ptr, 3, 0, "dragons", NULL, &first); + if (full && (flags & TR_KILL_UNDEAD)) output_ammo_dam(o_ptr, 5, 0, "undeads", NULL, &first); + else if (full && (flags & TR_SLAY_UNDEAD)) output_ammo_dam(o_ptr, 3, 0, "undeads", NULL, &first); + if (full && (flags & TR_KILL_DEMON)) output_ammo_dam(o_ptr, 5, 0, "demons", NULL, &first); + else if (full && (flags & TR_SLAY_DEMON)) output_ammo_dam(o_ptr, 3, 0, "demons", NULL, &first); + + if (full && (flags & TR_BRAND_FIRE)) output_ammo_dam(o_ptr, 3, 6, "non fire resistant creatures", "fire susceptible creatures", &first); + if (full && (flags & TR_BRAND_COLD)) output_ammo_dam(o_ptr, 3, 6, "non cold resistant creatures", "cold susceptible creatures", &first); + if (full && (flags & TR_BRAND_ELEC)) output_ammo_dam(o_ptr, 3, 6, "non lightning resistant creatures", "lightning susceptible creatures", &first); + if (full && (flags & TR_BRAND_ACID)) output_ammo_dam(o_ptr, 3, 6, "non acid resistant creatures", "acid susceptible creatures", &first); + if (full && (flags & TR_BRAND_POIS)) output_ammo_dam(o_ptr, 3, 6, "non poison resistant creatures", "poison susceptible creatures", &first); output_ammo_dam(o_ptr, 1, 0, (first) ? "all monsters" : "other monsters", NULL, &first); text_out(". "); @@ -2597,25 +2589,20 @@ static cptr object_out_desc_where_found(s16b level, s16b dungeon) */ bool_ object_out_desc(object_type *o_ptr, FILE *fff, bool_ trim_down, bool_ wait_for_it) { - u32b f1, f2, f3, f4, f5, esp; - cptr vp[64]; byte vc[64]; int vn; + object_flag_set flags; + /* Extract the flags */ if ((!(o_ptr->ident & (IDENT_MENTAL))) && (!fff)) { - f1 = o_ptr->art_oflags1; - f2 = o_ptr->art_oflags2; - f3 = o_ptr->art_oflags3; - f4 = o_ptr->art_oflags4; - f5 = o_ptr->art_oflags5; - esp = o_ptr->art_oesp; + flags = o_ptr->art_oflags; } else { - object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); + flags = object_flags(o_ptr); } if (fff) @@ -2665,9 +2652,9 @@ bool_ object_out_desc(object_type *o_ptr, FILE *fff, bool_ trim_down, bool_ wait } } - if ((f4 & TR4_LEVELS) && (!trim_down)) + if ((flags & TR_LEVELS) && (!trim_down)) { - if (count_bits(o_ptr->pval3) == 0) text_out("It is sentient"); + if (o_ptr->pval3 == 0) text_out("It is sentient"); else if (count_bits(o_ptr->pval3) > 1) text_out("It is sentient and can have access to the realms of "); else text_out("It is sentient and can have access to the realm of "); @@ -2684,7 +2671,7 @@ bool_ object_out_desc(object_type *o_ptr, FILE *fff, bool_ trim_down, bool_ wait text_out(". "); } - if (f4 & TR4_ULTIMATE) + if (flags & TR_ULTIMATE) { if ((wield_slot(o_ptr) == INVEN_WIELD) || (wield_slot(o_ptr) == INVEN_BOW)) @@ -2693,11 +2680,11 @@ bool_ object_out_desc(object_type *o_ptr, FILE *fff, bool_ trim_down, bool_ wait text_out_c(TERM_VIOLET, "It is the ultimate armor. "); } - if (f4 & TR4_COULD2H) text_out("It can be wielded two-handed. "); - if (f4 & TR4_MUST2H) text_out("It must be wielded two-handed. "); + if (flags & TR_COULD2H) text_out("It can be wielded two-handed. "); + if (flags & TR_MUST2H) text_out("It must be wielded two-handed. "); /* Mega-Hack -- describe activation */ - if (f3 & (TR3_ACTIVATE)) + if (flags & TR_ACTIVATE) { text_out("It can be activated for "); if (is_ego_p(o_ptr, EGO_MSTAFF_SPELL)) @@ -2710,7 +2697,7 @@ bool_ object_out_desc(object_type *o_ptr, FILE *fff, bool_ trim_down, bool_ wait text_out(item_activation(o_ptr, 0)); /* Mega-hack -- get rid of useless line for e.g. randarts */ - if (f5 & (TR5_ACTIVATE_NO_WIELD)) + if (flags & TR_ACTIVATE_NO_WIELD) text_out(". "); else text_out(" if it is being worn. "); @@ -2723,23 +2710,25 @@ bool_ object_out_desc(object_type *o_ptr, FILE *fff, bool_ trim_down, bool_ wait text_out(" if it is being worn. "); } - /* Hack -- describe lites */ - if ((o_ptr->tval == TV_LITE) || (f3 & TR3_LITE1) || (f4 & TR4_LITE2) || (f4 & TR4_LITE3)) + /* Describe light sources */ { int radius = 0; - if (f3 & TR3_LITE1) radius++; - if (f4 & TR4_LITE2) radius += 2; - if (f4 & TR4_LITE3) radius += 3; + if (flags & TR_LITE1) radius += 1; + if (flags & TR_LITE2) radius += 2; + if (flags & TR_LITE3) radius += 3; if (radius > 5) radius = 5; - if (f4 & TR4_FUEL_LITE) + if (radius > 0) { - text_out(format("It provides light (radius %d) when fueled. ", radius)); - } - else - { - text_out(format("It provides light (radius %d) forever. ", radius)); + if (flags & TR_FUEL_LITE) + { + text_out(format("It provides light (radius %d) when fueled. ", radius)); + } + else + { + text_out(format("It provides light (radius %d) forever. ", radius)); + } } } @@ -2749,12 +2738,12 @@ bool_ object_out_desc(object_type *o_ptr, FILE *fff, bool_ trim_down, bool_ wait text_out("It prevents the space-time continuum from being disrupted. "); } - if (f4 & TR4_ANTIMAGIC_50) + if (flags & TR_ANTIMAGIC_50) { text_out("It generates an antimagic field. "); } - if (f5 & TR5_SPELL_CONTAIN) + if (flags & TR_SPELL_CONTAIN) { if (o_ptr->pval2 == -1) text_out("It can be used to store a spell. "); @@ -2764,21 +2753,21 @@ bool_ object_out_desc(object_type *o_ptr, FILE *fff, bool_ trim_down, bool_ wait /* Pick up stat bonuses */ vn = 0; - if (f1 & (TR1_STR)) vp[vn++] = "strength"; - if (f1 & (TR1_INT)) vp[vn++] = "intelligence"; - if (f1 & (TR1_WIS)) vp[vn++] = "wisdom"; - if (f1 & (TR1_DEX)) vp[vn++] = "dexterity"; - if (f1 & (TR1_CON)) vp[vn++] = "constitution"; - if (f1 & (TR1_CHR)) vp[vn++] = "charisma"; - if ((o_ptr->tval != TV_TRAPKIT) && (f1 & (TR1_STEALTH))) vp[vn++] = "stealth"; - if (f1 & (TR1_SEARCH)) vp[vn++] = "searching"; - if (f1 & (TR1_INFRA)) vp[vn++] = "infravision"; - if (f1 & (TR1_TUNNEL)) vp[vn++] = "ability to tunnel"; - if (f1 & (TR1_SPEED)) vp[vn++] = "speed"; - if (f1 & (TR1_BLOWS)) vp[vn++] = "attack speed"; - if (f5 & (TR5_CRIT)) vp[vn++] = "ability to score critical hits"; - if (f5 & (TR5_LUCK)) vp[vn++] = "luck"; - if (f1 & (TR1_SPELL)) vp[vn++] = "spell power"; + if (flags & TR_STR) vp[vn++] = "strength"; + if (flags & TR_INT) vp[vn++] = "intelligence"; + if (flags & TR_WIS) vp[vn++] = "wisdom"; + if (flags & TR_DEX) vp[vn++] = "dexterity"; + if (flags & TR_CON) vp[vn++] = "constitution"; + if (flags & TR_CHR) vp[vn++] = "charisma"; + if ((o_ptr->tval != TV_TRAPKIT) && (flags & TR_STEALTH)) vp[vn++] = "stealth"; + if (flags & TR_SEARCH) vp[vn++] = "searching"; + if (flags & TR_INFRA) vp[vn++] = "infravision"; + if (flags & TR_TUNNEL) vp[vn++] = "ability to tunnel"; + if (flags & TR_SPEED) vp[vn++] = "speed"; + if (flags & TR_BLOWS) vp[vn++] = "attack speed"; + if (flags & TR_CRIT) vp[vn++] = "ability to score critical hits"; + if (flags & TR_LUCK) vp[vn++] = "luck"; + if (flags & TR_SPELL) vp[vn++] = "spell power"; /* Describe */ if (vn) @@ -2814,8 +2803,8 @@ bool_ object_out_desc(object_type *o_ptr, FILE *fff, bool_ trim_down, bool_ wait vn = 0; - if (f1 & (TR1_MANA)) vp[vn++] = "mana capacity"; - if (f2 & (TR2_LIFE)) vp[vn++] = "hit points"; + if (flags & TR_MANA) vp[vn++] = "mana capacity"; + if (flags & TR_LIFE) vp[vn++] = "hit points"; /* Describe with percentuals */ if (vn) @@ -2847,28 +2836,28 @@ bool_ object_out_desc(object_type *o_ptr, FILE *fff, bool_ trim_down, bool_ wait text_out(". "); } - if ((o_ptr->tval == TV_TRAPKIT) && (f1 & (TR1_STEALTH))) + if ((o_ptr->tval == TV_TRAPKIT) && (flags & TR_STEALTH)) { text_out("It is well-hidden. "); } vn = 0; - if (f1 & (TR1_BRAND_ACID)) + if (flags & TR_BRAND_ACID) { vc[vn] = TERM_GREEN; vp[vn++] = "acid"; } - if (f1 & (TR1_BRAND_ELEC)) + if (flags & TR_BRAND_ELEC) { vc[vn] = TERM_L_BLUE; vp[vn++] = "electricity"; } - if (f1 & (TR1_BRAND_FIRE)) + if (flags & TR_BRAND_FIRE) { vc[vn] = TERM_RED; vp[vn++] = "fire"; } - if (f1 & (TR1_BRAND_COLD)) + if (flags & TR_BRAND_COLD) { vc[vn] = TERM_L_WHITE; vp[vn++] = "frost"; @@ -2896,84 +2885,91 @@ bool_ object_out_desc(object_type *o_ptr, FILE *fff, bool_ trim_down, bool_ wait } - if (f1 & (TR1_BRAND_POIS)) + if (flags & TR_BRAND_POIS) { text_out("It "); text_out_c(TERM_L_GREEN, "poisons your foes"); text_out(". "); } - if (f1 & (TR1_CHAOTIC)) + if (flags & TR_CHAOTIC) { text_out("It produces chaotic effects. "); } - if (f1 & (TR1_VAMPIRIC)) + if (flags & TR_VAMPIRIC) { text_out("It drains life from your foes. "); } - if (f1 & (TR1_IMPACT)) + if (flags & TR_IMPACT) { text_out("It can cause earthquakes. "); } - if (f1 & (TR1_VORPAL)) + if (flags & TR_VORPAL) { text_out("It is very sharp and can cut your foes. "); } - if (f5 & (TR5_WOUNDING)) + if (flags & TR_WOUNDING) { text_out("It is very sharp and can make your foes bleed. "); } - if (f1 & (TR1_KILL_DRAGON)) + if (flags & TR_KILL_DRAGON) { text_out("It is a great bane of dragons. "); } - else if (f1 & (TR1_SLAY_DRAGON)) + else if (flags & TR_SLAY_DRAGON) { text_out("It is especially deadly against dragons. "); } - if (f1 & (TR1_SLAY_ORC)) + + if (flags & TR_SLAY_ORC) { text_out("It is especially deadly against orcs. "); } - if (f1 & (TR1_SLAY_TROLL)) + + if (flags & TR_SLAY_TROLL) { text_out("It is especially deadly against trolls. "); } - if (f1 & (TR1_SLAY_GIANT)) + + if (flags & TR_SLAY_GIANT) { text_out("It is especially deadly against giants. "); } - if (f5 & (TR5_KILL_DEMON)) + + if (flags & TR_KILL_DEMON) { text_out("It is a great bane of demons. "); } - else if (f1 & (TR1_SLAY_DEMON)) + else if (flags & TR_SLAY_DEMON) { text_out("It strikes at demons with holy wrath. "); } - if (f5 & (TR5_KILL_UNDEAD)) + + if (flags & TR_KILL_UNDEAD) { text_out("It is a great bane of undead. "); } - else if (f1 & (TR1_SLAY_UNDEAD)) + else if (flags & TR_SLAY_UNDEAD) { text_out("It strikes at undead with holy wrath. "); } - if (f1 & (TR1_SLAY_EVIL)) + + if (flags & TR_SLAY_EVIL) { text_out("It fights against evil with holy fury. "); } - if (f1 & (TR1_SLAY_ANIMAL)) + + if (flags & TR_SLAY_ANIMAL) { text_out("It is especially deadly against natural creatures. "); } - if (f2 & (TR2_INVIS)) + if (flags & TR_INVIS) { text_out("It makes you invisible. "); } @@ -2981,27 +2977,27 @@ bool_ object_out_desc(object_type *o_ptr, FILE *fff, bool_ trim_down, bool_ wait if (o_ptr->tval != TV_TRAPKIT) { vn = 0; - if (f2 & (TR2_SUST_STR)) + if (flags & TR_SUST_STR) { vp[vn++] = "strength"; } - if (f2 & (TR2_SUST_INT)) + if (flags & TR_SUST_INT) { vp[vn++] = "intelligence"; } - if (f2 & (TR2_SUST_WIS)) + if (flags & TR_SUST_WIS) { vp[vn++] = "wisdom"; } - if (f2 & (TR2_SUST_DEX)) + if (flags & TR_SUST_DEX) { vp[vn++] = "dexterity"; } - if (f2 & (TR2_SUST_CON)) + if (flags & TR_SUST_CON) { vp[vn++] = "constitution"; } - if (f2 & (TR2_SUST_CHR)) + if (flags & TR_SUST_CHR) { vp[vn++] = "charisma"; } @@ -3028,27 +3024,27 @@ bool_ object_out_desc(object_type *o_ptr, FILE *fff, bool_ trim_down, bool_ wait } vn = 0; - if (f2 & (TR2_IM_ACID)) + if (flags & TR_IM_ACID) { vc[vn] = TERM_GREEN; vp[vn++] = "acid"; } - if (f2 & (TR2_IM_ELEC)) + if (flags & TR_IM_ELEC) { vc[vn] = TERM_L_BLUE; vp[vn++] = "electricity"; } - if (f2 & (TR2_IM_FIRE)) + if (flags & TR_IM_FIRE) { vc[vn] = TERM_RED; vp[vn++] = "fire"; } - if (f2 & (TR2_IM_COLD)) + if (flags & TR_IM_COLD) { vc[vn] = TERM_L_WHITE; vp[vn++] = "cold"; } - if (f4 & (TR4_IM_NETHER)) + if (flags & TR_IM_NETHER) { vc[vn] = TERM_L_GREEN; vp[vn++] = "nether"; @@ -3077,115 +3073,115 @@ bool_ object_out_desc(object_type *o_ptr, FILE *fff, bool_ trim_down, bool_ wait } else { - if (f2 & (TRAP2_AUTOMATIC_5)) + if (flags & TR_AUTOMATIC_5) { text_out("It can rearm itself. "); } - if (f2 & (TRAP2_AUTOMATIC_99)) + if (flags & TR_AUTOMATIC_99) { text_out("It rearms itself. "); } - if (f2 & (TRAP2_KILL_GHOST)) + if (flags & TR_KILL_GHOST) { text_out("It is effective against Ghosts. "); } - if (f2 & (TRAP2_TELEPORT_TO)) + if (flags & TR_TELEPORT_TO) { text_out("It can teleport monsters to you. "); } - if (f2 & (TRAP2_ONLY_DRAGON)) + if (flags & TR_ONLY_DRAGON) { text_out("It can only be set off by dragons. "); } - if (f2 & (TRAP2_ONLY_DEMON)) + if (flags & TR_ONLY_DEMON) { text_out("It can only be set off by demons. "); } - if (f2 & (TRAP2_ONLY_UNDEAD)) + if (flags & TR_ONLY_UNDEAD) { text_out("It can only be set off by undead. "); } - if (f2 & (TRAP2_ONLY_ANIMAL)) + if (flags & TR_ONLY_ANIMAL) { text_out("It can only be set off by animals. "); } - if (f2 & (TRAP2_ONLY_EVIL)) + if (flags & TR_ONLY_EVIL) { text_out("It can only be set off by evil creatures. "); } } - if (f2 & (TR2_FREE_ACT)) + if (flags & TR_FREE_ACT) { text_out("It provides immunity to paralysis. "); } - if (f2 & (TR2_RES_FEAR)) + if (flags & TR_RES_FEAR) { text_out("It makes you completely fearless. "); } vn = 0; - if (f2 & (TR2_HOLD_LIFE)) + if (flags & TR_HOLD_LIFE) { vp[vn++] = "life draining"; } - if ((f2 & (TR2_RES_ACID)) && !(f2 & (TR2_IM_ACID))) + if ((flags & TR_RES_ACID) && !(flags & TR_IM_ACID)) { vp[vn++] = "acid"; } - if ((f2 & (TR2_RES_ELEC)) && !(f2 & (TR2_IM_ELEC))) + if ((flags & TR_RES_ELEC) && !(flags & TR_IM_ELEC)) { vp[vn++] = "electricity"; } - if ((f2 & (TR2_RES_FIRE)) && !(f2 & (TR2_IM_FIRE))) + if ((flags & TR_RES_FIRE) && !(flags & TR_IM_FIRE)) { vp[vn++] = "fire"; } - if ((f2 & (TR2_RES_COLD)) && !(f2 & (TR2_IM_COLD))) + if ((flags & TR_RES_COLD) && !(flags & TR_IM_COLD)) { vp[vn++] = "cold"; } - if (f2 & (TR2_RES_POIS)) + if (flags & TR_RES_POIS) { vp[vn++] = "poison"; } - if (f2 & (TR2_RES_LITE)) + if (flags & TR_RES_LITE) { vp[vn++] = "light"; } - if (f2 & (TR2_RES_DARK)) + if (flags & TR_RES_DARK) { vp[vn++] = "dark"; } - if (f2 & (TR2_RES_BLIND)) + if (flags & TR_RES_BLIND) { vp[vn++] = "blindness"; } - if (f2 & (TR2_RES_CONF)) + if (flags & TR_RES_CONF) { vp[vn++] = "confusion"; } - if (f2 & (TR2_RES_SOUND)) + if (flags & TR_RES_SOUND) { vp[vn++] = "sound"; } - if (f2 & (TR2_RES_SHARDS)) + if (flags & TR_RES_SHARDS) { vp[vn++] = "shards"; } - if ((f2 & (TR2_RES_NETHER)) && !(f4 & (TR4_IM_NETHER))) + if ((flags & TR_RES_NETHER) && !(flags & TR_IM_NETHER)) { vp[vn++] = "nether"; } - if (f2 & (TR2_RES_NEXUS)) + if (flags & TR_RES_NEXUS) { vp[vn++] = "nexus"; } - if (f2 & (TR2_RES_CHAOS)) + if (flags & TR_RES_CHAOS) { vp[vn++] = "chaos"; } - if (f2 & (TR2_RES_DISEN)) + if (flags & TR_RES_DISEN) { vp[vn++] = "disenchantment"; } @@ -3211,61 +3207,65 @@ bool_ object_out_desc(object_type *o_ptr, FILE *fff, bool_ trim_down, bool_ wait text_out(". "); } - if (f2 & (TR2_SENS_FIRE)) + if (flags & TR_SENS_FIRE) { text_out("It renders you especially vulnerable to fire. "); } - if (f3 & (TR3_WRAITH)) + if (flags & TR_WRAITH) { text_out("It renders you incorporeal. "); } - if (f5 & (TR5_WATER_BREATH)) + if (flags & TR_WATER_BREATH) { text_out("It allows you to breathe underwater. "); } - if (f5 & (TR5_MAGIC_BREATH)) + if (flags & TR_MAGIC_BREATH) { text_out("It allows you to breathe without air. "); } - if (f3 & (TR3_FEATHER)) + if (flags & TR_FEATHER) { text_out("It allows you to levitate. "); } - if (f4 & (TR4_FLY)) + if (flags & TR_FLY) { text_out("It allows you to fly. "); } - if (f4 & (TR4_CLIMB)) + if (flags & TR_CLIMB) { text_out("It allows you to climb mountains. "); } - if (f5 & (TR5_IMMOVABLE)) + if (flags & TR_IMMOVABLE) { text_out("It renders you immovable. "); } - if (f3 & (TR3_SEE_INVIS)) + if (flags & TR_SEE_INVIS) { text_out("It allows you to see invisible monsters. "); } - if (esp) + + // ESP_* { - if (esp & ESP_ALL) text_out("It gives telepathic powers. "); + if (flags & ESP_ALL) + { + text_out("It gives telepathic powers. "); + } else { vn = 0; - if (esp & ESP_ORC) vp[vn++] = "orcs"; - if (esp & ESP_TROLL) vp[vn++] = "trolls"; - if (esp & ESP_DRAGON) vp[vn++] = "dragons"; - if (esp & ESP_SPIDER) vp[vn++] = "spiders"; - if (esp & ESP_GIANT) vp[vn++] = "giants"; - if (esp & ESP_DEMON) vp[vn++] = "demons"; - if (esp & ESP_UNDEAD) vp[vn++] = "undead"; - if (esp & ESP_EVIL) vp[vn++] = "evil beings"; - if (esp & ESP_ANIMAL) vp[vn++] = "animals"; - if (esp & ESP_THUNDERLORD) vp[vn++] = "thunderlords"; - if (esp & ESP_GOOD) vp[vn++] = "good beings"; - if (esp & ESP_NONLIVING) vp[vn++] = "non-living things"; - if (esp & ESP_UNIQUE) vp[vn++] = "unique beings"; + if (flags & ESP_ORC) vp[vn++] = "orcs"; + if (flags & ESP_TROLL) vp[vn++] = "trolls"; + if (flags & ESP_DRAGON) vp[vn++] = "dragons"; + if (flags & ESP_SPIDER) vp[vn++] = "spiders"; + if (flags & ESP_GIANT) vp[vn++] = "giants"; + if (flags & ESP_DEMON) vp[vn++] = "demons"; + if (flags & ESP_UNDEAD) vp[vn++] = "undead"; + if (flags & ESP_EVIL) vp[vn++] = "evil beings"; + if (flags & ESP_ANIMAL) vp[vn++] = "animals"; + if (flags & ESP_THUNDERLORD) vp[vn++] = "thunderlords"; + if (flags & ESP_GOOD) vp[vn++] = "good beings"; + if (flags & ESP_NONLIVING) vp[vn++] = "non-living things"; + if (flags & ESP_UNIQUE) vp[vn++] = "unique beings"; /* Describe */ if (vn) { @@ -3290,55 +3290,55 @@ bool_ object_out_desc(object_type *o_ptr, FILE *fff, bool_ trim_down, bool_ wait } } - if (f3 & (TR3_SLOW_DIGEST)) + if (flags & TR_SLOW_DIGEST) { text_out("It slows your metabolism. "); } - if (f3 & (TR3_REGEN)) + if (flags & TR_REGEN) { text_out("It speeds your regenerative powers. "); } - if (f2 & (TR2_REFLECT)) + if (flags & TR_REFLECT) { text_out("It reflects bolts and arrows. "); } - if (f3 & (TR3_SH_FIRE)) + if (flags & TR_SH_FIRE) { text_out("It produces a fiery sheath. "); } - if (f3 & (TR3_SH_ELEC)) + if (flags & TR_SH_ELEC) { text_out("It produces an electric sheath. "); } - if (f3 & (TR3_NO_MAGIC)) + if (flags & TR_NO_MAGIC) { text_out("It produces an anti-magic shell. "); } - if (f3 & (TR3_NO_TELE)) + if (flags & TR_NO_TELE) { text_out("It prevents teleportation. "); } - if (f3 & (TR3_XTRA_MIGHT)) + if (flags & TR_XTRA_MIGHT) { text_out("It fires missiles with extra might. "); } - if (f3 & (TR3_XTRA_SHOTS)) + if (flags & TR_XTRA_SHOTS) { text_out("It fires missiles excessively fast. "); } vn = 0; - if (f5 & (TR5_DRAIN_MANA)) + if (flags & TR_DRAIN_MANA) { vc[vn] = TERM_BLUE; vp[vn++] = "mana"; } - if (f5 & (TR5_DRAIN_HP)) + if (flags & TR_DRAIN_HP) { vc[vn] = TERM_RED; vp[vn++] = "life"; } - if (f3 & (TR3_DRAIN_EXP)) + if (flags & TR_DRAIN_EXP) { vc[vn] = TERM_L_DARK; vp[vn++] = "experience"; @@ -3365,38 +3365,38 @@ bool_ object_out_desc(object_type *o_ptr, FILE *fff, bool_ trim_down, bool_ wait text_out(". "); } - if (f3 & (TR3_BLESSED)) + if (flags & TR_BLESSED) { text_out("It has been blessed by the gods. "); } - if (f4 & (TR4_AUTO_ID)) + if (flags & TR_AUTO_ID) { text_out("It identifies all items for you. "); } - if (f3 & (TR3_TELEPORT)) + if (flags & TR_TELEPORT) { text_out("It induces random teleportation. "); } - if (f3 & (TR3_AGGRAVATE)) + if (flags & TR_AGGRAVATE) { text_out("It aggravates nearby creatures. "); } - if (f4 & (TR4_NEVER_BLOW)) + if (flags & TR_NEVER_BLOW) { text_out("It can't attack. "); } - if (f4 & (TR4_BLACK_BREATH)) + if (flags & TR_BLACK_BREATH) { text_out("It fills you with the Black Breath. "); } if (cursed_p(o_ptr)) { - if (f3 & (TR3_PERMA_CURSE)) + if (flags & TR_PERMA_CURSE) { text_out("It is permanently cursed. "); } - else if (f3 & (TR3_HEAVY_CURSE)) + else if (flags & TR_HEAVY_CURSE) { text_out("It is heavily cursed. "); } @@ -3405,68 +3405,68 @@ bool_ object_out_desc(object_type *o_ptr, FILE *fff, bool_ trim_down, bool_ wait text_out("It is cursed. "); } } - if (f3 & (TR3_TY_CURSE)) + if (flags & TR_TY_CURSE) { text_out("It carries an ancient foul curse. "); } - if (f4 & (TR4_DG_CURSE)) + if (flags & TR_DG_CURSE) { text_out("It carries an ancient Morgothian curse. "); } - if (f4 & (TR4_CLONE)) + if (flags & TR_CLONE) { text_out("It can clone monsters. "); } - if (f4 & (TR4_CURSE_NO_DROP)) + if (flags & TR_CURSE_NO_DROP) { text_out("It cannot be dropped while cursed. "); } - if (f3 & (TR3_AUTO_CURSE)) + if (flags & TR_AUTO_CURSE) { text_out("It can re-curse itself. "); } - if (f4 & (TR4_CAPACITY)) + if (flags & TR_CAPACITY) { text_out("It can hold more mana. "); } - if (f4 & (TR4_CHEAPNESS)) + if (flags & TR_CHEAPNESS) { text_out("It can cast spells for a lesser mana cost. "); } - if (f4 & (TR4_FAST_CAST)) + if (flags & TR_FAST_CAST) { text_out("It can cast spells faster. "); } - if (f4 & (TR4_CHARGING)) + if (flags & TR_CHARGING) { text_out("It regenerates its mana faster. "); } - if (f5 & (TR5_RES_MORGUL)) + if (flags & TR_RES_MORGUL) { text_out("It can resist being shattered by morgul beings. "); } - if ((f3 & (TR3_IGNORE_ACID)) && (f3 & (TR3_IGNORE_FIRE)) && (f3 & (TR3_IGNORE_COLD)) && (f3 & (TR3_IGNORE_ELEC))) + if ((flags & TR_IGNORE_ACID) && (flags & TR_IGNORE_FIRE) && (flags & TR_IGNORE_COLD) && (flags & TR_IGNORE_ELEC)) { text_out("It cannot be harmed by acid, cold, lightning or fire. "); } else { - if (f3 & (TR3_IGNORE_ACID)) + if (flags & TR_IGNORE_ACID) { text_out("It cannot be harmed by acid. "); } - if (f3 & (TR3_IGNORE_ELEC)) + if (flags & TR_IGNORE_ELEC) { text_out("It cannot be harmed by electricity. "); } - if (f3 & (TR3_IGNORE_FIRE)) + if (flags & TR_IGNORE_FIRE) { text_out("It cannot be harmed by fire. "); } - if (f3 & (TR3_IGNORE_COLD)) + if (flags & TR_IGNORE_COLD) { text_out("It cannot be harmed by cold. "); } @@ -4162,7 +4162,7 @@ byte get_item_letter_color(object_type const *o_ptr) if (ego_item_p(o_ptr)) color = TERM_L_BLUE; if (artifact_p(o_ptr)) color = TERM_YELLOW; if (o_ptr->name1 && ( -1 != a_info[o_ptr->name1].set)) color = TERM_GREEN; - if (o_ptr->name1 && (a_info[o_ptr->name1].flags4 & TR4_ULTIMATE) && (o_ptr->ident & (IDENT_MENTAL))) color = TERM_VIOLET; + if (o_ptr->name1 && (a_info[o_ptr->name1].flags & TR_ULTIMATE) && (o_ptr->ident & (IDENT_MENTAL))) color = TERM_VIOLET; return (color); } @@ -4415,7 +4415,6 @@ void show_equip_aux(bool_ mirror, bool_ everything, object_filter_t const &filte !o_ptr->k_idx && p_ptr->inventory[i - INVEN_ARM + INVEN_WIELD].k_idx) { - u32b f1, f2, f3, f4, f5, esp; object_type *q_ptr = &p_ptr->inventory[i - INVEN_ARM + INVEN_WIELD]; char q_name[80]; @@ -4423,9 +4422,9 @@ void show_equip_aux(bool_ mirror, bool_ everything, object_filter_t const &filte object_desc(q_name, q_ptr, TRUE, 3); /* Get weapon flags */ - object_flags(q_ptr, &f1, &f2, &f3, &f4, &f5, &esp); + auto const flags = object_flags(q_ptr); - if (f4 & TR4_MUST2H) + if (flags & TR_MUST2H) { sprintf(o_name, "(two handed) %s", q_name); @@ -6082,120 +6081,79 @@ static void gain_flag_group(object_type *o_ptr) } } -static u32b get_flag(object_type *o_ptr, int grp, int k) +static object_flag_set get_flag(object_type *o_ptr, int grp) { - u32b f = 0, flag_set = 0; int tries = 1000; - u32b f1, f2, f3, f4, f5, esp, flag_test; - - /* Extract some flags */ - object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); /* get the corresponding flag set of the group */ - switch (k) - { - case 0: - flag_set = flags_groups()[grp].flags1; - flag_test = f1; - break; - case 1: - flag_set = flags_groups()[grp].flags2; - flag_test = f2; - break; - case 2: - flag_set = flags_groups()[grp].flags3; - flag_test = f3; - break; - case 3: - flag_set = flags_groups()[grp].flags4; - flag_test = f4; - break; - case 4: - flag_set = flags_groups()[grp].esp; - flag_test = esp; - break; - default: - flag_set = flags_groups()[grp].flags1; - flag_test = f1; - break; - } + auto const flag_set = flags_groups()[grp].flags; + auto const flag_test = object_flags(o_ptr); /* If no flags, no need to look */ - if (!count_bits(flag_set)) return 0; + if (flag_set.empty()) + { + return object_flag_set(); + } while (tries--) { - /* get a random flag */ - f = BIT(rand_int(32)); + // Choose a random flag + auto const f = object_flag_set::make_bit(rand_int(object_flag_set::nbits)); - /* is it part of the group */ - if (!(f & flag_set)) continue; + // Ignore if not part of the group + if (!(f & flag_set)) + { + continue; + } - /* Already got it */ - if (f & flag_test) continue; + // Ignore if already present + if (f & flag_test) + { + continue; + } - /* Ok one */ - break; + // Got a match! + return f; } - if (tries <= 1) return (0); - else return (f); + // Exhausted the number of tries + return object_flag_set(); } /* Add a flags from a flag group */ static void gain_flag_group_flag(object_type *o_ptr) { - int grp = 0, k = 0; - u32b f = 0; - int tries = 20000; - - if (!count_bits(o_ptr->pval3)) return; - - while (tries--) + // Try a "few" times to see if we can't find a flag. + for (int tries = 20000; tries > 0; tries--) { - /* Get a flag set */ - k = rand_int(5); - - /* get a flag group */ - grp = rand_int(flags_groups().size()); - - if (!(BIT(grp) & o_ptr->pval3)) continue; + // Choose a random flag group + auto grp = rand_int(flags_groups().size()); - /* Return a flag from the group/set */ - f = get_flag(o_ptr, grp, k); + // If that group isn't available to the object, then choose a new one. + if (!(BIT(grp) & o_ptr->pval3)) + { + continue; + } - if (!f) continue; + // Get an as-yet unused flag from the group, if possible. + auto const f = get_flag(o_ptr, grp); - break; - } + // If we couldn't find a flag, then we try again. + if (f.empty()) + { + continue; + } - if (tries <= 1) return; + // Got a flag; mix it into the object. + o_ptr->art_flags |= f; - switch (k) - { - case 0: - o_ptr->art_flags1 |= f; - break; - case 1: - o_ptr->art_flags2 |= f; - break; - case 2: - o_ptr->art_flags3 |= f; - break; - case 3: - o_ptr->art_flags4 |= f; - break; - case 4: - o_ptr->art_esp |= f; - break; - } - - /* Message */ - { + // Describe what happened char o_name[80]; - object_desc(o_name, o_ptr, FALSE, 0); msg_format("%s gains a new power from the %s realm.", o_name, flags_groups()[grp].name); + + // We're done. + return; } } @@ -6204,11 +6162,6 @@ static void gain_flag_group_flag(object_type *o_ptr) */ void object_gain_level(object_type *o_ptr) { - u32b f1, f2, f3, f4, f5, esp; - - /* Extract some flags */ - object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); - /* First it can gain some tohit and todam */ if ((o_ptr->tval == TV_AXE) || (o_ptr->tval == TV_SWORD) || (o_ptr->tval == TV_POLEARM) || (o_ptr->tval == TV_HAFTED) || (o_ptr->tval == TV_MSTAFF)) @@ -6231,16 +6184,31 @@ void object_gain_level(object_type *o_ptr) } else { - if (!o_ptr->pval3) gain_flag_group(o_ptr); + // Gain a group if none are available. + if (!o_ptr->pval3) + { + gain_flag_group(o_ptr); + } + // Gain a flag gain_flag_group_flag(o_ptr); - if (!o_ptr->pval) o_ptr->pval = 1; + // Increase/grant PVAL + if (!o_ptr->pval) + { + o_ptr->pval = 1; + } else { - while (magik(20 - (o_ptr->pval * 2))) o_ptr->pval++; + while (magik(20 - (o_ptr->pval * 2))) + { + o_ptr->pval++; + } - if (o_ptr->pval > 5) o_ptr->pval = 5; + if (o_ptr->pval > 5) + { + o_ptr->pval = 5; + } } } } @@ -6301,40 +6269,42 @@ bool_ takeoff_set(s16b a_idx, s16b set_idx) return (FALSE); } -bool_ apply_set(s16b a_idx, s16b set_idx) +void apply_set(s16b a_idx, s16b set_idx) { set_type *s_ptr = &set_info[set_idx]; - int i, j; - if ( -1 == a_info[a_idx].set) return (FALSE); + if ( -1 == a_info[a_idx].set) + { + return; + } + + int i; for (i = 0; i < s_ptr->num; i++) + { if (a_idx == s_ptr->arts[i].a_idx) break; + } + if (s_ptr->arts[i].present) { - for (j = 0; j < s_ptr->num_use; j++) + for (int j = 0; j < s_ptr->num_use; j++) { - apply_flags(s_ptr->arts[i].flags1[j], - s_ptr->arts[i].flags2[j], - s_ptr->arts[i].flags3[j], - s_ptr->arts[i].flags4[j], - s_ptr->arts[i].flags5[j], - s_ptr->arts[i].esp[j], + apply_flags(s_ptr->arts[i].flags[j], s_ptr->arts[i].pval[j], 0, 0, 0, 0); } - return (TRUE); } - return (FALSE); } -static bool_ apply_flags_set(s16b a_idx, s16b set_idx, - u32b *f1, u32b *f2, u32b *f3, u32b *f4, u32b *f5, u32b *esp) +static void apply_flags_set(s16b a_idx, s16b set_idx, object_flag_set *f) { - set_type *s_ptr = &set_info[set_idx]; - int i, j; + if ( -1 == a_info[a_idx].set) + { + return; + } - if ( -1 == a_info[a_idx].set) return (FALSE); + set_type *s_ptr = &set_info[set_idx]; + int i; for (i = 0; i < s_ptr->num; i++) { if (a_idx == s_ptr->arts[i].a_idx) break; @@ -6342,18 +6312,11 @@ static bool_ apply_flags_set(s16b a_idx, s16b set_idx, if (s_ptr->arts[i].present) { - for (j = 0; j < s_ptr->num_use; j++) + for (int j = 0; j < s_ptr->num_use; j++) { - (*f1) |= s_ptr->arts[i].flags1[j]; - (*f2) |= s_ptr->arts[i].flags2[j]; - (*f3) |= s_ptr->arts[i].flags3[j]; - (*f4) |= s_ptr->arts[i].flags4[j]; - (*f5) |= s_ptr->arts[i].flags5[j]; - (*esp) |= s_ptr->arts[i].esp[j]; + (*f) |= s_ptr->arts[i].flags[j]; } - return (TRUE); } - return (FALSE); } /* @@ -6433,7 +6396,7 @@ bool artifact_p(object_type const *o_ptr) (o_ptr->tval == TV_RANDART) || (o_ptr->name1 ? true : false) || (o_ptr->art_name ? true : false) || - ((k_info[o_ptr->k_idx].flags3 & TR3_NORM_ART) ? true : false); + ((k_info[o_ptr->k_idx].flags & TR_NORM_ART) ? true : false); } /** -- cgit v1.2.3 From 2190e84bd31c6cb0078df0fd674177989880afee Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 22 Jun 2016 15:50:36 +0200 Subject: Clean up flavor_init() and use Fisher-Yates shuffle --- src/object1.cc | 126 +++++++++++++++------------------------------------------ 1 file changed, 32 insertions(+), 94 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 5aa53c7f..9e130be9 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -60,6 +60,7 @@ #include #include #include +#include using boost::starts_with; @@ -454,6 +455,25 @@ static bool_ object_easy_know(int i) return (FALSE); } + + +/** + * Shuffle flavor arrays into a random permutation + */ +template +static void shuffle_flavors(cptr adj[], byte col[]) +{ + // The classic Fisher-Yates shuffle + for (std::size_t i = N - 1; i > 0; i--) + { + int j = rand_int(i + 1); + std::swap(adj[i], adj[j]); + std::swap(col[i], col[j]); + } +} + + + /* * Prepare the "variable" part of the "k_info" array. * @@ -487,13 +507,6 @@ static bool_ object_easy_know(int i) */ void flavor_init(void) { - int i, j; - - byte temp_col; - - cptr temp_adj; - - /* Hack -- Use the "simple" RNG */ Rand_quick = TRUE; @@ -502,99 +515,24 @@ void flavor_init(void) /* Efficiency -- Rods/Wands share initial array */ - for (i = 0; i < MAX_METALS; i++) + for (std::size_t i = 0; i < MAX_METALS; i++) { rod_adj[i] = wand_adj[i]; rod_col[i] = wand_col[i]; } - /* Rings have "ring colors" */ - for (i = 0; i < MAX_ROCKS; i++) - { - j = rand_int(MAX_ROCKS); - temp_adj = ring_adj[i]; - ring_adj[i] = ring_adj[j]; - ring_adj[j] = temp_adj; - temp_col = ring_col[i]; - ring_col[i] = ring_col[j]; - ring_col[j] = temp_col; - } - - /* Amulets have "amulet colors" */ - for (i = 0; i < MAX_AMULETS; i++) - { - j = rand_int(MAX_AMULETS); - temp_adj = amulet_adj[i]; - amulet_adj[i] = amulet_adj[j]; - amulet_adj[j] = temp_adj; - temp_col = amulet_col[i]; - amulet_col[i] = amulet_col[j]; - amulet_col[j] = temp_col; - } - - /* Staffs */ - for (i = 0; i < MAX_WOODS; i++) - { - j = rand_int(MAX_WOODS); - temp_adj = staff_adj[i]; - staff_adj[i] = staff_adj[j]; - staff_adj[j] = temp_adj; - temp_col = staff_col[i]; - staff_col[i] = staff_col[j]; - staff_col[j] = temp_col; - } - - /* Wands */ - for (i = 0; i < MAX_METALS; i++) - { - j = rand_int(MAX_METALS); - temp_adj = wand_adj[i]; - wand_adj[i] = wand_adj[j]; - wand_adj[j] = temp_adj; - temp_col = wand_col[i]; - wand_col[i] = wand_col[j]; - wand_col[j] = temp_col; - } - - /* Rods */ - for (i = 0; i < MAX_METALS; i++) - { - j = rand_int(MAX_METALS); - temp_adj = rod_adj[i]; - rod_adj[i] = rod_adj[j]; - rod_adj[j] = temp_adj; - temp_col = rod_col[i]; - rod_col[i] = rod_col[j]; - rod_col[j] = temp_col; - } - - /* Foods (Mushrooms) */ - for (i = 0; i < MAX_SHROOM; i++) - { - j = rand_int(MAX_SHROOM); - temp_adj = food_adj[i]; - food_adj[i] = food_adj[j]; - food_adj[j] = temp_adj; - temp_col = food_col[i]; - food_col[i] = food_col[j]; - food_col[j] = temp_col; - } - - /* Potions */ - for (i = 4; i < MAX_COLORS; i++) - { - j = rand_int(MAX_COLORS - 4) + 4; - temp_adj = potion_adj[i]; - potion_adj[i] = potion_adj[j]; - potion_adj[j] = temp_adj; - temp_col = potion_col[i]; - potion_col[i] = potion_col[j]; - potion_col[j] = temp_col; - } + /* Object flavors */ + shuffle_flavors(ring_adj, ring_col); + shuffle_flavors(amulet_adj, amulet_col); + shuffle_flavors(staff_adj, staff_col); + shuffle_flavors(wand_adj, wand_col); + shuffle_flavors(rod_adj, rod_col); + shuffle_flavors(food_adj, food_col); + shuffle_flavors(potion_adj + 4, potion_col + 4); /* Scrolls (random titles, always white) */ - for (i = 0; i < MAX_TITLES; i++) + for (std::size_t i = 0; i < MAX_TITLES; i++) { /* Get a new title */ while (TRUE) @@ -635,7 +573,7 @@ void flavor_init(void) bool_ okay = TRUE; /* Check for "duplicate" scroll titles */ - for (j = 0; j < i; j++) + for (std::size_t j = 0; j < i; j++) { cptr hack1 = scroll_adj[j]; cptr hack2 = scroll_adj[i]; @@ -666,7 +604,7 @@ void flavor_init(void) Rand_quick = FALSE; /* Analyze every object */ - for (i = 1; i < max_k_idx; i++) + for (std::size_t i = 1; i < max_k_idx; i++) { object_kind *k_ptr = &k_info[i]; -- cgit v1.2.3 From d249c64b5ea5b59b475584fa1a70208b8e4a4c64 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 17 Sep 2016 09:58:13 +0200 Subject: Remove inventory_no_move option --- src/object1.cc | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 9e130be9..a3cb5593 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -4066,15 +4066,15 @@ static bool item_tester_okay(object_type const *o_ptr, object_filter_t const &fi -static void show_equip_aux(bool_ mirror, bool_ everything, object_filter_t const &filter); -static void show_inven_aux(bool_ mirror, bool_ everything, object_filter_t const &filter); +static void show_equip_aux(bool_ mirror, object_filter_t const &filter); +static void show_inven_aux(bool_ mirror, object_filter_t const &filter); /* * Choice window "shadow" of the "show_inven()" function */ void display_inven(void) { - show_inven_aux(TRUE, inventory_no_move, object_filter::True()); + show_inven_aux(TRUE, object_filter::True()); } @@ -4084,7 +4084,7 @@ void display_inven(void) */ void display_equip(void) { - show_equip_aux(TRUE, inventory_no_move, object_filter::True()); + show_equip_aux(TRUE, object_filter::True()); } @@ -4111,7 +4111,7 @@ byte get_item_letter_color(object_type const *o_ptr) * * Hack -- do not display "trailing" empty slots */ -void show_inven_aux(bool_ mirror, bool_ everything, const object_filter_t &filter) +void show_inven_aux(bool_ mirror, const object_filter_t &filter) { int i, j, k, l, z = 0; int row, col, len, lim; @@ -4165,16 +4165,13 @@ void show_inven_aux(bool_ mirror, bool_ everything, const object_filter_t &filte /* Is this item acceptable? */ if (!item_tester_okay(o_ptr, filter)) { - if ( !everything ) - continue; - out_index[k] = -i - 1; - } - else - { - /* Save the object index */ - out_index[k] = i + 1; + /* Skip to next slot */ + continue; } + /* Save the object index */ + out_index[k] = i + 1; + /* Describe the object */ object_desc(o_name, o_ptr, TRUE, 3); @@ -4273,7 +4270,7 @@ void show_inven_aux(bool_ mirror, bool_ everything, const object_filter_t &filte static void show_inven(object_filter_t const &filter) { - show_inven_aux(FALSE, FALSE, filter); + show_inven_aux(FALSE, filter); } void show_inven_full() @@ -4285,7 +4282,7 @@ void show_inven_full() static void show_equip(object_filter_t const &filter) { - show_equip_aux(FALSE, FALSE, filter); + show_equip_aux(FALSE, filter); } void show_equip_full() @@ -4298,7 +4295,7 @@ void show_equip_full() /* * Display the equipment. */ -void show_equip_aux(bool_ mirror, bool_ everything, object_filter_t const &filter) +void show_equip_aux(bool_ mirror, object_filter_t const &filter) { int i, j, k, l; int row, col, len, lim, idx; @@ -4407,17 +4404,16 @@ void show_equip_aux(bool_ mirror, bool_ everything, object_filter_t const &filte /* Truncate the description */ o_name[lim] = 0; + /* Is this item acceptable? */ if (!item_tester_okay(o_ptr, filter)) { - if (!everything) continue; - out_index[k] = -1; - } - else - { - /* Save the index */ - out_index[k] = idx; + /* Skip to next slot */ + continue; } + + /* Save the index */ + out_index[k] = idx; out_rindex[k] = i; /* Save the color */ -- cgit v1.2.3 From 90ab4c37504bfa1f33246d963d40032b70ed39ac Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 17 Sep 2016 09:58:14 +0200 Subject: Theme: Remove armor restriction for Eagle/Dragon It interferes badly with Possession and it seems a little unfair that (non-Dragon/Eagle) Possessors with a Dragon body *do* get armor -- albeit usually with penalties. --- src/object1.cc | 18 ------------------ 1 file changed, 18 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index a3cb5593..b0760abe 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -3644,24 +3644,6 @@ static int get_slot(int slot) */ s16b wield_slot_ideal(object_type const *o_ptr, bool_ ideal) { - /* Theme has restrictions for winged races. */ - if (game_module_idx == MODULE_THEME) - { - cptr race_name = rp_ptr->title; - - if (streq(race_name, "Dragon") || - streq(race_name, "Eagle")) - { - switch (o_ptr->tval) - { - case TV_CLOAK: - case TV_HARD_ARMOR: - case TV_DRAG_ARMOR: - return -1; - } - } - } - /* Slot for equipment */ switch (o_ptr->tval) { -- cgit v1.2.3 From f035201f330a3b1f50a2041ea9ad3f854f7d4e00 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 17 Sep 2016 09:58:14 +0200 Subject: Move all options to a struct instead of using globals --- src/object1.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index b0760abe..5f4db047 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -5896,7 +5896,7 @@ void py_pickup_floor(int pickup) bool_ do_pickup = TRUE; /* Hack -- query every item */ - if (carry_query_flag || (!can_carry_heavy(&o_list[floor_o_idx]))) + if (options->carry_query_flag || !can_carry_heavy(&o_list[floor_o_idx])) { char o_name[80] = ""; object_desc(o_name, o_ptr, TRUE, 3); -- cgit v1.2.3 From f673763cfaf90c81db4af495aa06b6fc7906ddd9 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 17 Sep 2016 09:58:14 +0200 Subject: Bump cppformat -> fmt-3.0.0 --- src/object1.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 5f4db047..c4945e6b 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -59,7 +59,7 @@ #include #include #include -#include +#include #include using boost::starts_with; -- cgit v1.2.3 From 6d11bb4a2d5bc8ab7c1491639f1083532b1b8fd1 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 17 Sep 2016 09:58:14 +0200 Subject: Replace RNG with PCG random number generator --- src/object1.cc | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index c4945e6b..3f5d123f 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -507,12 +507,8 @@ static void shuffle_flavors(cptr adj[], byte col[]) */ void flavor_init(void) { - /* Hack -- Use the "simple" RNG */ - Rand_quick = TRUE; - /* Hack -- Induce consistant flavors */ - Rand_value = seed_flavor; - + set_quick_rng(seed_flavor()); /* Efficiency -- Rods/Wands share initial array */ for (std::size_t i = 0; i < MAX_METALS; i++) @@ -599,9 +595,8 @@ void flavor_init(void) scroll_col[i] = TERM_WHITE; } - /* Hack -- Use the "complex" RNG */ - Rand_quick = FALSE; + set_complex_rng(); /* Analyze every object */ for (std::size_t i = 1; i < max_k_idx; i++) -- cgit v1.2.3 From b15461dbcedf27f28a843f700ce0473d57364230 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 17 Sep 2016 09:58:14 +0200 Subject: Remove redundant checks "around" artifact_p() Turns out artifact_p() already performs the necessary checks. --- src/object1.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 3f5d123f..c93d1ff1 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -1469,7 +1469,7 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) {} /* Hack -- The only one of its kind */ - else if (known && (artifact_p(o_ptr) || o_ptr->art_name)) + else if (known && artifact_p(o_ptr)) { t += "The "; } @@ -1571,7 +1571,7 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) } /* Hack -- The only one of its kind */ - else if (known && (artifact_p(o_ptr) || o_ptr->art_name)) + else if (known && artifact_p(o_ptr)) { t += "The "; } @@ -3463,7 +3463,7 @@ bool_ object_out_desc(object_type *o_ptr, FILE *fff, bool_ trim_down, bool_ wait /* Copying how others seem to do it. -- neil */ if (o_ptr->tval == TV_RING || o_ptr->tval == TV_AMULET || - !trim_down || (ego_item_p(o_ptr)) || (artifact_p(o_ptr))) + !trim_down || ego_item_p(o_ptr) || artifact_p(o_ptr)) { /* Where did we found it ? */ if (o_ptr->found == OBJ_FOUND_MONSTER) -- cgit v1.2.3 From 013e27d39ee8ee513208d2855c7e3f6252f0c0bf Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 17 Sep 2016 09:58:14 +0200 Subject: Refactor object_type 'inscription' field to std::string We don't really need quarks for this since we're not nearly as memory-constrained these days. --- src/object1.cc | 71 +++++++++++++++++++++++----------------------------------- 1 file changed, 28 insertions(+), 43 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index c93d1ff1..a7c1edf1 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -1526,16 +1526,10 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) /* Dagger inscribed {@w0%Smelly} will be named * Smelly Dagger {@w0} */ - if (o_ptr->note) + if (auto str = strchr(o_ptr->inscription.c_str(), '%')) { - cptr str = strchr(quark_str(o_ptr->note), '%'); - - /* Add the false name */ - if (str) - { - t += &str[1]; - t += ' '; - } + t += &str[1]; + t += ' '; } } @@ -1680,16 +1674,10 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) /* -TM- Hack -- Add false-artifact names */ /* Dagger inscribed {@w0#of Smell} will be named * Dagger of Smell {@w0} */ - if (o_ptr->note) + if (auto str = strchr(o_ptr->inscription.c_str(), '#')) { - cptr str = strchr(quark_str(o_ptr->note), '#'); - - /* Add the false name */ - if (str) - { - t += ' '; - t += &str[1]; - } + t += ' '; + t += &str[1]; } /* Is it a new random artifact ? */ @@ -2061,17 +2049,13 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) inscrip.push_back("cursed"); } - /* Use the standard inscription if available */ - if (o_ptr->note) + /* Use the standard inscription if available; + Chop at '#' or '%' if present. The suffix of the + '%' or '#' is handled elsewhere in this function. + */ + if (auto const pos = o_ptr->inscription.find_first_of("%#") != std::string::npos) { - // Chop at '#' or '%' if present. The suffix of the - // '%' or '#' is handled elsewhere in this function. - std::string note = quark_str(o_ptr->note); - auto const pos = note.find_first_of("%#"); - if (pos > 0) - { - inscrip.push_back(note.substr(0, pos)); - } + inscrip.push_back(o_ptr->inscription.substr(0, pos)); } /* Mega-Hack -- note empty wands/staffs */ @@ -4570,18 +4554,17 @@ bool_ verify(cptr prompt, int item) */ static bool_ get_item_allow(int item) { - cptr s; - - object_type *o_ptr; - /* Get object */ - o_ptr = get_object(item); + auto o_ptr = get_object(item); /* No inscription */ - if (!o_ptr->note) return (TRUE); + if (o_ptr->inscription.empty()) + { + return TRUE; + } /* Find a '!' */ - s = strchr(quark_str(o_ptr->note), '!'); + auto s = strchr(o_ptr->inscription.c_str(), '!'); /* Process preventions */ while (s) @@ -4631,23 +4614,25 @@ static bool get_item_okay(int i, object_filter_t const &filter) */ static int get_tag(int *cp, char tag) { - int i; - cptr s; - - /* Check every object */ - for (i = 0; i < INVEN_TOTAL; ++i) + for (int i = 0; i < INVEN_TOTAL; ++i) { object_type *o_ptr = &p_ptr->inventory[i]; /* Skip non-objects */ - if (!o_ptr->k_idx) continue; + if (!o_ptr->k_idx) + { + continue; + } /* Skip empty inscriptions */ - if (!o_ptr->note) continue; + if (o_ptr->inscription.empty()) + { + continue; + } /* Find a '@' */ - s = strchr(quark_str(o_ptr->note), '@'); + auto s = strchr(o_ptr->inscription.c_str(), '@'); /* Process all tags */ while (s) -- cgit v1.2.3 From 8bbf783ead4517465445272f9144cf06bdac9be7 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 17 Sep 2016 09:58:14 +0200 Subject: Refactor object_type 'artifact name' field to std::string We don't really need quarks for this since we're not nearly as memory-constrained these days. --- src/object1.cc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index a7c1edf1..b4e1141d 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -717,7 +717,7 @@ void reset_visuals(void) static void object_flags_xtra(object_type const *o_ptr, object_flag_set *f) { // Artifacts don't get *ego* extra powers. - if (o_ptr->art_name) + if (!o_ptr->artifact_name.empty()) { return; } @@ -1126,7 +1126,7 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) else basenm = aware ? "& # Amulet~" : "& # Amulet~"; - if (known && !o_ptr->art_name && artifact_p(o_ptr)) + if (known && o_ptr->artifact_name.empty() && artifact_p(o_ptr)) { basenm = k_ptr->name; } @@ -1149,7 +1149,7 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) /* Hack -- The One Ring */ if (!aware && (o_ptr->sval == SV_RING_POWER)) modstr = "Plain Gold"; - if (known && !o_ptr->art_name && artifact_p(o_ptr)) + if (known && o_ptr->artifact_name.empty() && artifact_p(o_ptr)) { basenm = k_ptr->name; } @@ -1681,10 +1681,10 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) } /* Is it a new random artifact ? */ - if (o_ptr->art_name) + if (!o_ptr->artifact_name.empty()) { t += ' '; - t += quark_str(o_ptr->art_name); + t += o_ptr->artifact_name; } @@ -1848,7 +1848,7 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) else if (o_ptr->to_h) { t += fmt::format(" ({:+d}", o_ptr->to_h); - if (!(flags & TR_HIDE_TYPE) || o_ptr->art_name) + if (!(flags & TR_HIDE_TYPE) || (!o_ptr->artifact_name.empty())) { t += " to accuracy"; } @@ -1859,7 +1859,7 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) else if (o_ptr->to_d) { t += fmt::format(" ({:+d}", o_ptr->to_d); - if (!(flags & TR_HIDE_TYPE) || o_ptr->art_name) + if (!(flags & TR_HIDE_TYPE) || (!o_ptr->artifact_name.empty())) { t += " to damage"; } @@ -6291,7 +6291,7 @@ bool artifact_p(object_type const *o_ptr) return (o_ptr->tval == TV_RANDART) || (o_ptr->name1 ? true : false) || - (o_ptr->art_name ? true : false) || + (!o_ptr->artifact_name.empty()) || ((k_info[o_ptr->k_idx].flags & TR_NORM_ART) ? true : false); } -- cgit v1.2.3 From 288c3d3f725eabfee06507966a0ba63bf587c3da Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 17 Sep 2016 09:58:14 +0200 Subject: Remove quark.{cc,hpp} --- src/object1.cc | 1 - 1 file changed, 1 deletion(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index b4e1141d..c311ee34 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -38,7 +38,6 @@ #include "player_race.hpp" #include "player_race_mod.hpp" #include "player_type.hpp" -#include "quark.hpp" #include "set_type.hpp" #include "skills.hpp" #include "spell_type.hpp" -- cgit v1.2.3 From 35daca530fecc0b74dea0820941a273950c59bf2 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:07 +0200 Subject: Fix for 'invisible' inscriptions in object lists --- src/object1.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index c311ee34..c812462f 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -2070,11 +2070,17 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) } /* Note the discount, if any */ - if ((o_ptr->discount) && inscrip.empty()) + if ((o_ptr->discount) && o_ptr->inscription.empty()) { inscrip.push_back(fmt::format("{:d}% off", o_ptr->discount)); } + /* Append the user's inscription */ + if (!o_ptr->inscription.empty()) + { + inscrip.push_back(o_ptr->inscription); + } + /* Append the inscription, if any */ if (!inscrip.empty()) { -- cgit v1.2.3 From bea14b1db03fcd62d7dfd6633a0802f222792311 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Fix typo where incorrect array bound was being used --- src/object1.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index c812462f..0d93c917 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -695,7 +695,7 @@ void reset_visuals(void) } /* Reset attr/char code for trap overlay graphics */ - for (i = 0; i < max_rmp_idx; i++) + for (i = 0; i < max_t_idx; i++) { trap_type *t_ptr = &t_info[i]; -- cgit v1.2.3 From d33961f89a0c80f2fae4020184e72467b5c192cf Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Move race_info and race_mod_info to GameEditData --- src/object1.cc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 0d93c917..e0b4f60b 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -18,6 +18,7 @@ #include "ego_item_type.hpp" #include "feature_type.hpp" #include "files.hpp" +#include "game.hpp" #include "hook_get_in.hpp" #include "hooks.hpp" #include "lua_bind.hpp" @@ -632,6 +633,8 @@ void flavor_init(void) */ void reset_visuals(void) { + auto &race_mod_info = game->edit_data.race_mod_info; + int i; /* Extract some info about terrain features */ @@ -685,13 +688,11 @@ void reset_visuals(void) } /* Reset attr/char code for race modifier overlay graphics */ - for (i = 0; i < max_rmp_idx; i++) + for (player_race_mod &rmp: race_mod_info) { - player_race_mod *rmp_ptr = &race_mod_info[i]; - /* Default attr/char */ - rmp_ptr->g_attr = 0; - rmp_ptr->g_char = 0; + rmp.g_attr = 0; + rmp.g_char = 0; } /* Reset attr/char code for trap overlay graphics */ -- cgit v1.2.3 From 667acd0e312301ad613b6a71f843c51d2062aee6 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Move d_info into GameEditData --- src/object1.cc | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index e0b4f60b..fe777d10 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -2481,6 +2481,8 @@ static void describe_device(object_type *o_ptr) */ static cptr object_out_desc_where_found(s16b level, s16b dungeon) { + auto const &d_info = game->edit_data.d_info; + static char str[80]; if (dungeon == DUNGEON_WILDERNESS) -- cgit v1.2.3 From 7ccb0c1a48d571abd6dc3aca725275e2d264aa2d Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Change strings in dungeon_info_type to std::string --- src/object1.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index fe777d10..3e783121 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -2503,7 +2503,7 @@ static cptr object_out_desc_where_found(s16b level, s16b dungeon) } else { - sprintf(str, "on level %d of %s", level, d_info[dungeon].name); + sprintf(str, "on level %d of %s", level, d_info[dungeon].name.c_str()); } return str; -- cgit v1.2.3 From 1726fc7a8ab66c15385bdda8f0533cddeb867b58 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Move set_info into GameEditData --- src/object1.cc | 46 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 9 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 3e783121..0d958fc8 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -2514,6 +2514,8 @@ static cptr object_out_desc_where_found(s16b level, s16b dungeon) */ bool_ object_out_desc(object_type *o_ptr, FILE *fff, bool_ trim_down, bool_ wait_for_it) { + auto const &set_info = game->edit_data.set_info; + cptr vp[64]; byte vc[64]; int vn; @@ -6124,12 +6126,21 @@ void object_gain_level(object_type *o_ptr) */ bool_ wield_set(s16b a_idx, s16b set_idx, bool_ silent) { - set_type *s_ptr = &set_info[set_idx]; - int i; + auto &set_info = game->edit_data.set_info; + + auto s_ptr = &set_info[set_idx]; if ( -1 == a_info[a_idx].set) return (FALSE); + + int i; for (i = 0; i < s_ptr->num; i++) - if (a_idx == s_ptr->arts[i].a_idx) break; + { + if (a_idx == s_ptr->arts[i].a_idx) + { + break; + } + } + if (!s_ptr->arts[i].present) { s_ptr->num_use++; @@ -6144,17 +6155,26 @@ bool_ wield_set(s16b a_idx, s16b set_idx, bool_ silent) } return (TRUE); } + return (FALSE); } bool_ takeoff_set(s16b a_idx, s16b set_idx) { - set_type *s_ptr = &set_info[set_idx]; - int i; + auto &set_info = game->edit_data.set_info; + + auto s_ptr = &set_info[set_idx]; if ( -1 == a_info[a_idx].set) return (FALSE); + + int i; for (i = 0; i < s_ptr->num; i++) - if (a_idx == s_ptr->arts[i].a_idx) break; + { + if (a_idx == s_ptr->arts[i].a_idx) + { + break; + } + } if (s_ptr->arts[i].present) { @@ -6170,12 +6190,15 @@ bool_ takeoff_set(s16b a_idx, s16b set_idx) return (TRUE); } + return (FALSE); } void apply_set(s16b a_idx, s16b set_idx) { - set_type *s_ptr = &set_info[set_idx]; + auto const &set_info = game->edit_data.set_info; + + auto s_ptr = &set_info[set_idx]; if ( -1 == a_info[a_idx].set) { @@ -6185,7 +6208,10 @@ void apply_set(s16b a_idx, s16b set_idx) int i; for (i = 0; i < s_ptr->num; i++) { - if (a_idx == s_ptr->arts[i].a_idx) break; + if (a_idx == s_ptr->arts[i].a_idx) + { + break; + } } if (s_ptr->arts[i].present) @@ -6201,12 +6227,14 @@ void apply_set(s16b a_idx, s16b set_idx) static void apply_flags_set(s16b a_idx, s16b set_idx, object_flag_set *f) { + auto const &set_info = game->edit_data.set_info; + if ( -1 == a_info[a_idx].set) { return; } - set_type *s_ptr = &set_info[set_idx]; + auto s_ptr = &set_info[set_idx]; int i; for (i = 0; i < s_ptr->num; i++) -- cgit v1.2.3 From 0cea35759ed072d3a42b54926d6fee7d12346418 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Change set_type name/desc to std::string --- src/object1.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 0d958fc8..191b2046 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -2574,7 +2574,7 @@ bool_ object_out_desc(object_type *o_ptr, FILE *fff, bool_ trim_down, bool_ wait if (a_ptr->set != -1) { - text_out_c(TERM_GREEN, set_info[a_ptr->set].desc); + text_out_c(TERM_GREEN, set_info[a_ptr->set].desc.c_str()); text_out("\n"); } } @@ -6151,7 +6151,7 @@ bool_ wield_set(s16b a_idx, s16b set_idx, bool_ silent) } else if ((s_ptr->num_use == s_ptr->num) && (!silent)) { - cmsg_format(TERM_GREEN, "%s item set completed.", s_ptr->name); + cmsg_format(TERM_GREEN, "%s item set completed.", s_ptr->name.c_str()); } return (TRUE); } @@ -6185,7 +6185,7 @@ bool_ takeoff_set(s16b a_idx, s16b set_idx) if (s_ptr->num_use == s_ptr->num - 1) { - cmsg_format(TERM_GREEN, "%s item set not complete anymore.", s_ptr->name); + cmsg_format(TERM_GREEN, "%s item set not complete anymore.", s_ptr->name.c_str()); } return (TRUE); -- cgit v1.2.3 From aebc48dffa75698be4d2c1bb2b1a0927b10be1cc Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Move st_info into GameEditData --- src/object1.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 191b2046..b035326f 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -633,6 +633,7 @@ void flavor_init(void) */ void reset_visuals(void) { + auto &st_info = game->edit_data.st_info; auto &race_mod_info = game->edit_data.race_mod_info; int i; @@ -648,13 +649,11 @@ void reset_visuals(void) } /* Extract default attr/char code for stores */ - for (i = 0; i < max_st_idx; i++) + for (auto &st_ref: st_info) { - store_info_type *st_ptr = &st_info[i]; - /* Default attr/char */ - st_ptr->x_attr = st_ptr->d_attr; - st_ptr->x_char = st_ptr->d_char; + st_ref.x_attr = st_ref.d_attr; + st_ref.x_char = st_ref.d_char; } /* Extract default attr/char code for objects */ @@ -2515,6 +2514,7 @@ static cptr object_out_desc_where_found(s16b level, s16b dungeon) bool_ object_out_desc(object_type *o_ptr, FILE *fff, bool_ trim_down, bool_ wait_for_it) { auto const &set_info = game->edit_data.set_info; + auto const &st_info = game->edit_data.st_info; cptr vp[64]; byte vc[64]; -- cgit v1.2.3 From e02a2dfd184a996a02ecc6004a0a03bcfbd19131 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Change store_info_type::name to std::string --- src/object1.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index b035326f..656446c3 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -3493,12 +3493,12 @@ bool_ object_out_desc(object_type *o_ptr, FILE *fff, bool_ trim_down, bool_ wait else if (o_ptr->found == OBJ_FOUND_STORE) { text_out(format("\nYou bought it from the %s.", - st_info[o_ptr->found_aux1].name)); + st_info[o_ptr->found_aux1].name.c_str())); } else if (o_ptr->found == OBJ_FOUND_STOLEN) { text_out(format("\nYou stole it from the %s.", - st_info[o_ptr->found_aux1].name)); + st_info[o_ptr->found_aux1].name.c_str())); } else if (o_ptr->found == OBJ_FOUND_SELFMADE) { -- cgit v1.2.3 From e1230547a936c7180b3a69012659fc511027f035 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Move re_info into GameEditData --- src/object1.cc | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 656446c3..c98e2ed5 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -635,6 +635,7 @@ void reset_visuals(void) { auto &st_info = game->edit_data.st_info; auto &race_mod_info = game->edit_data.race_mod_info; + auto &re_info = game->edit_data.re_info; int i; @@ -677,17 +678,15 @@ void reset_visuals(void) } /* Reset attr/char code for ego monster overlay graphics */ - for (i = 0; i < max_re_idx; i++) + for (auto &re_ref: re_info) { - monster_ego *re_ptr = &re_info[i]; - /* Default attr/char */ - re_ptr->g_attr = 0; - re_ptr->g_char = 0; + re_ref.g_attr = 0; + re_ref.g_char = 0; } /* Reset attr/char code for race modifier overlay graphics */ - for (player_race_mod &rmp: race_mod_info) + for (auto &rmp: race_mod_info) { /* Default attr/char */ rmp.g_attr = 0; -- cgit v1.2.3 From 5ddcbbf1cdce68e565376819efedd519892512ad Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Move wf_info into GameEditData --- src/object1.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index c98e2ed5..8be0655a 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -2480,6 +2480,7 @@ static void describe_device(object_type *o_ptr) static cptr object_out_desc_where_found(s16b level, s16b dungeon) { auto const &d_info = game->edit_data.d_info; + auto const &wf_info = game->edit_data.wf_info; static char str[80]; -- cgit v1.2.3 From 0c2f30b56c221a826ba64f0ec864c29d0f717644 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Move r_info into GameEditData --- src/object1.cc | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 8be0655a..466488fe 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -636,6 +636,7 @@ void reset_visuals(void) auto &st_info = game->edit_data.st_info; auto &race_mod_info = game->edit_data.race_mod_info; auto &re_info = game->edit_data.re_info; + auto &r_info = game->edit_data.r_info; int i; @@ -668,13 +669,11 @@ void reset_visuals(void) } /* Extract default attr/char code for monsters */ - for (i = 0; i < max_r_idx; i++) + for (auto &r_ref: r_info) { - monster_race *r_ptr = &r_info[i]; - /* Default attr/char */ - r_ptr->x_attr = r_ptr->d_attr; - r_ptr->x_char = r_ptr->d_char; + r_ref.x_attr = r_ref.d_attr; + r_ref.x_char = r_ref.d_char; } /* Reset attr/char code for ego monster overlay graphics */ @@ -1020,6 +1019,7 @@ static object_flag_set compute_pval_mask() */ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) { + auto const &r_info = game->edit_data.r_info; static auto const TR_PVAL_MASK = compute_pval_mask(); bool_ hack_name = FALSE; @@ -1300,7 +1300,8 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) case TV_CORPSE: { - monster_race* r_ptr = &r_info[o_ptr->pval2]; + auto r_ptr = &r_info[o_ptr->pval2]; + modstr = basenm; if (r_ptr->flags & RF_UNIQUE) { @@ -1315,7 +1316,8 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) case TV_EGG: { - monster_race* r_ptr = &r_info[o_ptr->pval2]; + auto r_ptr = &r_info[o_ptr->pval2]; + modstr = basenm; basenm = fmt::format("& {} #~", r_ptr->name); break; @@ -1324,7 +1326,8 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) case TV_HYPNOS: { /* We print hit points further down. --dsb */ - monster_race* r_ptr = &r_info[o_ptr->pval]; + auto r_ptr = &r_info[o_ptr->pval]; + modstr = basenm; basenm = fmt::format("& {}~", r_ptr->name); break; @@ -1411,16 +1414,6 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) { cptr ego = NULL; - monster_race* r_ptr; - if (o_ptr->tval == TV_CORPSE) - { - r_ptr = &r_info[o_ptr->pval2]; - } - else - { - r_ptr = &r_info[o_ptr->pval]; - } - /* Grab any ego-item name */ if (known && (o_ptr->name2 || o_ptr->name2b) && (o_ptr->tval != TV_ROD_MAIN)) { @@ -1459,12 +1452,15 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) t += ' '; } - else if ((o_ptr->tval == TV_CORPSE) && (r_ptr->flags & RF_UNIQUE)) - {} - + else if ((o_ptr->tval == TV_CORPSE) && (r_info[o_ptr->pval2].flags & RF_UNIQUE)) + { + /* Nothing */ + } - else if ((o_ptr->tval == TV_HYPNOS) && (r_ptr->flags & RF_UNIQUE)) - {} + else if ((o_ptr->tval == TV_HYPNOS) && (r_info[o_ptr->pval].flags & RF_UNIQUE)) + { + /* Nothing */ + } /* Hack -- The only one of its kind */ else if (known && artifact_p(o_ptr)) -- cgit v1.2.3 From b9fca0267b1d6a32d57e1fb4387f52c19d1c3fa6 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Move f_info into GameEditData --- src/object1.cc | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 466488fe..c10a52f9 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -637,17 +637,15 @@ void reset_visuals(void) auto &race_mod_info = game->edit_data.race_mod_info; auto &re_info = game->edit_data.re_info; auto &r_info = game->edit_data.r_info; + auto &f_info = game->edit_data.f_info; int i; /* Extract some info about terrain features */ - for (i = 0; i < max_f_idx; i++) + for (auto &f_ref: f_info) { - feature_type *f_ptr = &f_info[i]; - - /* Assume we will use the underlying values */ - f_ptr->x_attr = f_ptr->d_attr; - f_ptr->x_char = f_ptr->d_char; + f_ref.x_attr = f_ref.d_attr; + f_ref.x_char = f_ref.d_char; } /* Extract default attr/char code for stores */ -- cgit v1.2.3 From 1bbed63b66c0f69809e698576a51501150f06bba Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Move k_info into GameEditData --- src/object1.cc | 70 ++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 26 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index c10a52f9..42c3f9ff 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -331,14 +331,8 @@ static char scroll_adj[MAX_TITLES][16]; static byte scroll_col[MAX_TITLES]; -/* - * Certain items have a flavor - * This function is used only by "flavor_init()" - */ -static byte object_flavor(int k_idx) +static byte object_flavor(object_kind const *k_ptr) { - object_kind *k_ptr = &k_info[k_idx]; - /* Analyze the item */ switch (k_ptr->tval) { @@ -390,7 +384,7 @@ static byte object_flavor(int k_idx) } /* No flavor */ - return (0); + return 0; } @@ -400,10 +394,8 @@ static byte object_flavor(int k_idx) * * XXX XXX XXX Add "EASY_KNOW" flag to "k_info.txt" file */ -static bool_ object_easy_know(int i) +static bool_ object_easy_know(object_kind const *k_ptr) { - object_kind *k_ptr = &k_info[i]; - /* Analyze the "tval" */ switch (k_ptr->tval) { @@ -507,6 +499,8 @@ static void shuffle_flavors(cptr adj[], byte col[]) */ void flavor_init(void) { + auto &k_info = game->edit_data.k_info; + /* Hack -- Induce consistant flavors */ set_quick_rng(seed_flavor()); @@ -599,21 +593,24 @@ void flavor_init(void) set_complex_rng(); /* Analyze every object */ - for (std::size_t i = 1; i < max_k_idx; i++) + for (auto &k_ref: k_info) { - object_kind *k_ptr = &k_info[i]; + auto k_ptr = &k_ref; /* Skip "empty" objects */ if (!k_ptr->name) continue; /* Extract "flavor" (if any) */ - k_ptr->flavor = object_flavor(i); + k_ptr->flavor = object_flavor(k_ptr); /* No flavor yields aware */ - if ((!k_ptr->flavor) && (k_ptr->tval != TV_ROD_MAIN)) k_ptr->aware = TRUE; + if ((!k_ptr->flavor) && (k_ptr->tval != TV_ROD_MAIN)) + { + k_ptr->aware = TRUE; + } /* Check for "easily known" */ - k_ptr->easy_know = object_easy_know(i); + k_ptr->easy_know = object_easy_know(k_ptr); } } @@ -638,6 +635,7 @@ void reset_visuals(void) auto &re_info = game->edit_data.re_info; auto &r_info = game->edit_data.r_info; auto &f_info = game->edit_data.f_info; + auto &k_info = game->edit_data.k_info; int i; @@ -657,13 +655,11 @@ void reset_visuals(void) } /* Extract default attr/char code for objects */ - for (i = 0; i < max_k_idx; i++) + for (auto &k_ref: k_info) { - object_kind *k_ptr = &k_info[i]; - /* Default attr/char */ - k_ptr->x_attr = k_ptr->d_attr; - k_ptr->x_char = k_ptr->d_char; + k_ref.x_attr = k_ref.d_attr; + k_ref.x_char = k_ref.d_char; } /* Extract default attr/char code for monsters */ @@ -804,7 +800,9 @@ bool_ object_flags_no_set = FALSE; */ object_flag_set object_flags(object_type const *o_ptr) { - object_kind *k_ptr = &k_info[o_ptr->k_idx]; + auto const &k_info = game->edit_data.k_info; + + auto k_ptr = &k_info[o_ptr->k_idx]; /* Base object */ auto f = k_ptr->flags; @@ -834,7 +832,9 @@ object_flag_set object_flags(object_type const *o_ptr) /* Return object granted power */ int object_power(object_type *o_ptr) { - object_kind *k_ptr = &k_info[o_ptr->k_idx]; + auto const &k_info = game->edit_data.k_info; + + auto k_ptr = &k_info[o_ptr->k_idx]; int power = -1; /* Base object */ @@ -873,7 +873,9 @@ int object_power(object_type *o_ptr) */ object_flag_set object_flags_known(object_type const *o_ptr) { - object_kind *k_ptr = &k_info[o_ptr->k_idx]; + auto const &k_info = game->edit_data.k_info; + + auto k_ptr = &k_info[o_ptr->k_idx]; /* Must be identified */ if (!object_known_p(o_ptr)) @@ -1018,6 +1020,7 @@ static object_flag_set compute_pval_mask() static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) { auto const &r_info = game->edit_data.r_info; + auto const &k_info = game->edit_data.k_info; static auto const TR_PVAL_MASK = compute_pval_mask(); bool_ hack_name = FALSE; @@ -1027,7 +1030,7 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) bool_ show_weapon = FALSE; bool_ show_armour = FALSE; - object_kind *k_ptr = &k_info[o_ptr->k_idx]; + auto k_ptr = &k_info[o_ptr->k_idx]; /* Extract some flags */ auto const flags = object_flags(o_ptr); @@ -2104,6 +2107,8 @@ void object_desc(char *buf, object_type const *o_ptr, int pref, int mode) */ void object_desc_store(char *buf, object_type *o_ptr, int pref, int mode) { + auto &k_info = game->edit_data.k_info; + /* Save the "aware" flag */ bool_ hack_aware = k_info[o_ptr->k_idx].aware; @@ -2138,6 +2143,8 @@ void object_desc_store(char *buf, object_type *o_ptr, int pref, int mode) */ cptr item_activation(object_type *o_ptr, byte num) { + auto const &k_info = game->edit_data.k_info; + /* Needed hacks */ static char rspell[2][80]; @@ -2509,6 +2516,7 @@ bool_ object_out_desc(object_type *o_ptr, FILE *fff, bool_ trim_down, bool_ wait { auto const &set_info = game->edit_data.set_info; auto const &st_info = game->edit_data.st_info; + auto const &k_info = game->edit_data.k_info; cptr vp[64]; byte vc[64]; @@ -2553,7 +2561,7 @@ bool_ object_out_desc(object_type *o_ptr, FILE *fff, bool_ trim_down, bool_ wait { if (o_ptr->k_idx && (!trim_down)) { - object_kind *k_ptr = &k_info[o_ptr->k_idx]; + auto k_ptr = &k_info[o_ptr->k_idx]; text_out_c(TERM_ORANGE, k_ptr->text); text_out("\n"); @@ -6253,6 +6261,8 @@ static void apply_flags_set(s16b a_idx, s16b set_idx, object_flag_set *f) byte object_attr(object_type const *o_ptr) { + auto const &k_info = game->edit_data.k_info; + if (o_ptr->tval == TV_RANDART) { return random_artifacts[o_ptr->sval].attr; @@ -6269,6 +6279,8 @@ byte object_attr(object_type const *o_ptr) byte object_attr_default(object_type *o_ptr) { + auto const &k_info = game->edit_data.k_info; + if (o_ptr->tval == TV_RANDART) { return random_artifacts[o_ptr->sval].attr; @@ -6291,6 +6303,8 @@ byte object_attr_default(object_type *o_ptr) char object_char(object_type const *o_ptr) { + auto const &k_info = game->edit_data.k_info; + if (k_info[o_ptr->k_idx].flavor) { return misc_to_char[k_info[o_ptr->k_idx].flavor]; @@ -6303,6 +6317,8 @@ char object_char(object_type const *o_ptr) char object_char_default(object_type const *o_ptr) { + auto const &k_info = game->edit_data.k_info; + if (k_info[o_ptr->k_idx].flavor) { return misc_to_char[k_info[o_ptr->k_idx].flavor]; @@ -6318,6 +6334,8 @@ char object_char_default(object_type const *o_ptr) */ bool artifact_p(object_type const *o_ptr) { + auto const &k_info = game->edit_data.k_info; + return (o_ptr->tval == TV_RANDART) || (o_ptr->name1 ? true : false) || -- cgit v1.2.3 From 57bb453a15034c67d04496360b306a5f3bfd0bf2 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Move a_info into GameEditData --- src/object1.cc | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 42c3f9ff..8795bdbd 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -801,6 +801,7 @@ bool_ object_flags_no_set = FALSE; object_flag_set object_flags(object_type const *o_ptr) { auto const &k_info = game->edit_data.k_info; + auto const &a_info = game->edit_data.a_info; auto k_ptr = &k_info[o_ptr->k_idx]; @@ -810,7 +811,7 @@ object_flag_set object_flags(object_type const *o_ptr) /* Artifact */ if (o_ptr->name1) { - artifact_type *a_ptr = &a_info[o_ptr->name1]; + auto a_ptr = &a_info[o_ptr->name1]; f = a_ptr->flags; @@ -833,6 +834,7 @@ object_flag_set object_flags(object_type const *o_ptr) int object_power(object_type *o_ptr) { auto const &k_info = game->edit_data.k_info; + auto const &a_info = game->edit_data.a_info; auto k_ptr = &k_info[o_ptr->k_idx]; int power = -1; @@ -858,9 +860,12 @@ int object_power(object_type *o_ptr) /* Artifact */ if (o_ptr->name1) { - artifact_type *a_ptr = &a_info[o_ptr->name1]; + auto a_ptr = &a_info[o_ptr->name1]; - if (power == -1) power = a_ptr->power; + if (power == -1) + { + power = a_ptr->power; + } } return (power); @@ -874,6 +879,7 @@ int object_power(object_type *o_ptr) object_flag_set object_flags_known(object_type const *o_ptr) { auto const &k_info = game->edit_data.k_info; + auto const &a_info = game->edit_data.a_info; auto k_ptr = &k_info[o_ptr->k_idx]; @@ -892,7 +898,7 @@ object_flag_set object_flags_known(object_type const *o_ptr) /* Artifact */ if (o_ptr->name1) { - artifact_type *a_ptr = &a_info[o_ptr->name1]; + auto a_ptr = &a_info[o_ptr->name1]; /* Need full knowledge or spoilers */ if ((o_ptr->ident & IDENT_MENTAL)) @@ -1021,6 +1027,7 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) { auto const &r_info = game->edit_data.r_info; auto const &k_info = game->edit_data.k_info; + auto const &a_info = game->edit_data.a_info; static auto const TR_PVAL_MASK = compute_pval_mask(); bool_ hack_name = FALSE; @@ -1686,7 +1693,7 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) /* Grab any artifact name */ else if (o_ptr->name1) { - artifact_type *a_ptr = &a_info[o_ptr->name1]; + auto a_ptr = &a_info[o_ptr->name1]; /* Unique corpses don't require another name */ if (o_ptr->tval != TV_CORPSE) @@ -2144,6 +2151,7 @@ void object_desc_store(char *buf, object_type *o_ptr, int pref, int mode) cptr item_activation(object_type *o_ptr, byte num) { auto const &k_info = game->edit_data.k_info; + auto const &a_info = game->edit_data.a_info; /* Needed hacks */ static char rspell[2][80]; @@ -2517,6 +2525,7 @@ bool_ object_out_desc(object_type *o_ptr, FILE *fff, bool_ trim_down, bool_ wait auto const &set_info = game->edit_data.set_info; auto const &st_info = game->edit_data.st_info; auto const &k_info = game->edit_data.k_info; + auto const &a_info = game->edit_data.a_info; cptr vp[64]; byte vc[64]; @@ -2569,7 +2578,7 @@ bool_ object_out_desc(object_type *o_ptr, FILE *fff, bool_ trim_down, bool_ wait if (o_ptr->name1 && (!trim_down)) { - artifact_type *a_ptr = &a_info[o_ptr->name1]; + auto a_ptr = &a_info[o_ptr->name1]; text_out_c(TERM_YELLOW, a_ptr->text); text_out("\n"); @@ -4065,6 +4074,8 @@ void display_equip(void) /* Get the color of the letter idx */ byte get_item_letter_color(object_type const *o_ptr) { + auto const &a_info = game->edit_data.a_info; + byte color = TERM_WHITE; /* Must have knowlegde */ @@ -6129,6 +6140,7 @@ void object_gain_level(object_type *o_ptr) bool_ wield_set(s16b a_idx, s16b set_idx, bool_ silent) { auto &set_info = game->edit_data.set_info; + auto const &a_info = game->edit_data.a_info; auto s_ptr = &set_info[set_idx]; @@ -6164,6 +6176,7 @@ bool_ wield_set(s16b a_idx, s16b set_idx, bool_ silent) bool_ takeoff_set(s16b a_idx, s16b set_idx) { auto &set_info = game->edit_data.set_info; + auto const &a_info = game->edit_data.a_info; auto s_ptr = &set_info[set_idx]; @@ -6199,6 +6212,7 @@ bool_ takeoff_set(s16b a_idx, s16b set_idx) void apply_set(s16b a_idx, s16b set_idx) { auto const &set_info = game->edit_data.set_info; + auto const &a_info = game->edit_data.a_info; auto s_ptr = &set_info[set_idx]; @@ -6230,6 +6244,7 @@ void apply_set(s16b a_idx, s16b set_idx) static void apply_flags_set(s16b a_idx, s16b set_idx, object_flag_set *f) { auto const &set_info = game->edit_data.set_info; + auto const &a_info = game->edit_data.a_info; if ( -1 == a_info[a_idx].set) { -- cgit v1.2.3 From 89e75b855662b1dcc86a6dc3789fa496aafbb0a2 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Move e_info into GameEditData --- src/object1.cc | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 8795bdbd..3c7da36e 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -835,6 +835,7 @@ int object_power(object_type *o_ptr) { auto const &k_info = game->edit_data.k_info; auto const &a_info = game->edit_data.a_info; + auto const &e_info = game->edit_data.e_info; auto k_ptr = &k_info[o_ptr->k_idx]; int power = -1; @@ -845,15 +846,21 @@ int object_power(object_type *o_ptr) /* Ego-item */ if (o_ptr->name2) { - ego_item_type *e_ptr = &e_info[o_ptr->name2]; + auto e_ptr = &e_info[o_ptr->name2]; - if (power == -1) power = e_ptr->power; + if (power == -1) + { + power = e_ptr->power; + } if (o_ptr->name2b) { - ego_item_type *e_ptr = &e_info[o_ptr->name2b]; + auto e_ptr = &e_info[o_ptr->name2b]; - if (power == -1) power = e_ptr->power; + if (power == -1) + { + power = e_ptr->power; + } } } @@ -1028,6 +1035,7 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) auto const &r_info = game->edit_data.r_info; auto const &k_info = game->edit_data.k_info; auto const &a_info = game->edit_data.a_info; + auto const &e_info = game->edit_data.e_info; static auto const TR_PVAL_MASK = compute_pval_mask(); bool_ hack_name = FALSE; @@ -1425,8 +1433,8 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) /* Grab any ego-item name */ if (known && (o_ptr->name2 || o_ptr->name2b) && (o_ptr->tval != TV_ROD_MAIN)) { - ego_item_type *e_ptr = &e_info[o_ptr->name2]; - ego_item_type *e2_ptr = &e_info[o_ptr->name2b]; + auto e_ptr = &e_info[o_ptr->name2]; + auto e2_ptr = &e_info[o_ptr->name2b]; if (e_ptr->before) { @@ -1509,8 +1517,8 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) /* Grab any ego-item name */ if (known && (o_ptr->name2 || o_ptr->name2b) && (o_ptr->tval != TV_ROD_MAIN)) { - ego_item_type *e_ptr = &e_info[o_ptr->name2]; - ego_item_type *e2_ptr = &e_info[o_ptr->name2b]; + auto e_ptr = &e_info[o_ptr->name2]; + auto e2_ptr = &e_info[o_ptr->name2b]; if (e_ptr->before) { @@ -1581,8 +1589,8 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) /* Grab any ego-item name */ if (known && (o_ptr->name2 || o_ptr->name2b) && (o_ptr->tval != TV_ROD_MAIN)) { - ego_item_type *e_ptr = &e_info[o_ptr->name2]; - ego_item_type *e2_ptr = &e_info[o_ptr->name2b]; + auto e_ptr = &e_info[o_ptr->name2]; + auto e2_ptr = &e_info[o_ptr->name2b]; if (e_ptr->before) { @@ -1631,7 +1639,7 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) if (known && o_ptr->name2) { - ego_item_type *e_ptr = &e_info[o_ptr->name2]; + auto e_ptr = &e_info[o_ptr->name2]; t += e_ptr->name; } } @@ -1706,8 +1714,8 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) /* Grab any ego-item name */ else if ((o_ptr->name2 || o_ptr->name2b) && (o_ptr->tval != TV_ROD_MAIN)) { - ego_item_type *e_ptr = &e_info[o_ptr->name2]; - ego_item_type *e2_ptr = &e_info[o_ptr->name2b]; + auto e_ptr = &e_info[o_ptr->name2]; + auto e2_ptr = &e_info[o_ptr->name2b]; if (o_ptr->name2 && !e_ptr->before) { @@ -2152,6 +2160,7 @@ cptr item_activation(object_type *o_ptr, byte num) { auto const &k_info = game->edit_data.k_info; auto const &a_info = game->edit_data.a_info; + auto const &e_info = game->edit_data.e_info; /* Needed hacks */ static char rspell[2][80]; -- cgit v1.2.3 From c25b265c056a4512b0fb0e1789927e6c4b7b32cf Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Move t_info into GameEditData --- src/object1.cc | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 3c7da36e..d04c7ab2 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -636,8 +636,7 @@ void reset_visuals(void) auto &r_info = game->edit_data.r_info; auto &f_info = game->edit_data.f_info; auto &k_info = game->edit_data.k_info; - - int i; + auto &t_info = game->edit_data.t_info; /* Extract some info about terrain features */ for (auto &f_ref: f_info) @@ -687,13 +686,11 @@ void reset_visuals(void) } /* Reset attr/char code for trap overlay graphics */ - for (i = 0; i < max_t_idx; i++) + for (auto &t_ref: t_info) { - trap_type *t_ptr = &t_info[i]; - /* Default attr/char */ - t_ptr->g_attr = 0; - t_ptr->g_char = 0; + t_ref.g_attr = 0; + t_ref.g_char = 0; } @@ -1036,6 +1033,7 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) auto const &k_info = game->edit_data.k_info; auto const &a_info = game->edit_data.a_info; auto const &e_info = game->edit_data.e_info; + auto const &t_info = game->edit_data.t_info; static auto const TR_PVAL_MASK = compute_pval_mask(); bool_ hack_name = FALSE; -- cgit v1.2.3 From cbafbc638c2e1d5bb40ee6bc419007062e9615e4 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:09 +0200 Subject: Remove traps Credit goes mostly to "miramor" who did most of the actual work. I just did a few minor tweaks and fixes + rebased onto master. --- src/object1.cc | 89 ---------------------------------------------------------- 1 file changed, 89 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index d04c7ab2..e81c5742 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -47,7 +47,6 @@ #include "stats.hpp" #include "store_info_type.hpp" #include "tables.hpp" -#include "trap_type.hpp" #include "util.hpp" #include "util.h" #include "variable.h" @@ -636,7 +635,6 @@ void reset_visuals(void) auto &r_info = game->edit_data.r_info; auto &f_info = game->edit_data.f_info; auto &k_info = game->edit_data.k_info; - auto &t_info = game->edit_data.t_info; /* Extract some info about terrain features */ for (auto &f_ref: f_info) @@ -685,15 +683,6 @@ void reset_visuals(void) rmp.g_char = 0; } - /* Reset attr/char code for trap overlay graphics */ - for (auto &t_ref: t_info) - { - /* Default attr/char */ - t_ref.g_attr = 0; - t_ref.g_char = 0; - } - - /* Normal symbols */ process_pref_file("font.prf"); } @@ -1033,7 +1022,6 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) auto const &k_info = game->edit_data.k_info; auto const &a_info = game->edit_data.a_info; auto const &e_info = game->edit_data.e_info; - auto const &t_info = game->edit_data.t_info; static auto const TR_PVAL_MASK = compute_pval_mask(); bool_ hack_name = FALSE; @@ -1097,14 +1085,6 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) break; } - /* Trapping Kits */ - case TV_TRAPKIT: - { - modstr = basenm; - basenm = "& # Trap Set~"; - break; - } - /* Armour */ case TV_BOOTS: case TV_GLOVES: @@ -1769,23 +1749,6 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) { t += " (empty)"; } - - /* May be "disarmed" */ - else if (o_ptr->pval < 0) - { - t += " (disarmed)"; - } - - /* Describe the traps, if any */ - else - { - /* Describe the traps */ - auto trap_name = (t_info[o_ptr->pval].ident) - ? t_info[o_ptr->pval].name - : "trapped"; - - t += fmt::format(" ({})", trap_name); - } } @@ -2704,7 +2667,6 @@ bool_ object_out_desc(object_type *o_ptr, FILE *fff, bool_ trim_down, bool_ wait if (flags & TR_DEX) vp[vn++] = "dexterity"; if (flags & TR_CON) vp[vn++] = "constitution"; if (flags & TR_CHR) vp[vn++] = "charisma"; - if ((o_ptr->tval != TV_TRAPKIT) && (flags & TR_STEALTH)) vp[vn++] = "stealth"; if (flags & TR_SEARCH) vp[vn++] = "searching"; if (flags & TR_INFRA) vp[vn++] = "infravision"; if (flags & TR_TUNNEL) vp[vn++] = "ability to tunnel"; @@ -2781,11 +2743,6 @@ bool_ object_out_desc(object_type *o_ptr, FILE *fff, bool_ trim_down, bool_ wait text_out(". "); } - if ((o_ptr->tval == TV_TRAPKIT) && (flags & TR_STEALTH)) - { - text_out("It is well-hidden. "); - } - vn = 0; if (flags & TR_BRAND_ACID) { @@ -2919,7 +2876,6 @@ bool_ object_out_desc(object_type *o_ptr, FILE *fff, bool_ trim_down, bool_ wait text_out("It makes you invisible. "); } - if (o_ptr->tval != TV_TRAPKIT) { vn = 0; if (flags & TR_SUST_STR) @@ -3016,45 +2972,6 @@ bool_ object_out_desc(object_type *o_ptr, FILE *fff, bool_ trim_down, bool_ wait text_out(". "); } } - else - { - if (flags & TR_AUTOMATIC_5) - { - text_out("It can rearm itself. "); - } - if (flags & TR_AUTOMATIC_99) - { - text_out("It rearms itself. "); - } - if (flags & TR_KILL_GHOST) - { - text_out("It is effective against Ghosts. "); - } - if (flags & TR_TELEPORT_TO) - { - text_out("It can teleport monsters to you. "); - } - if (flags & TR_ONLY_DRAGON) - { - text_out("It can only be set off by dragons. "); - } - if (flags & TR_ONLY_DEMON) - { - text_out("It can only be set off by demons. "); - } - if (flags & TR_ONLY_UNDEAD) - { - text_out("It can only be set off by undead. "); - } - if (flags & TR_ONLY_ANIMAL) - { - text_out("It can only be set off by animals. "); - } - if (flags & TR_ONLY_EVIL) - { - text_out("It can only be set off by evil creatures. "); - } - } if (flags & TR_FREE_ACT) { @@ -5861,12 +5778,6 @@ void py_pickup_floor(int pickup) /* Get the tile */ auto c_ptr = &cave[p_ptr->py][p_ptr->px]; - /* Hack -- ignore monster traps */ - if (c_ptr->feat == FEAT_MON_TRAP) - { - return; - } - /* Try to grab ammo */ pickup_ammo(); -- cgit v1.2.3 From b3d136333c1b516123cc83e3dc96d4bd79dd52ca Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 20:01:12 +0200 Subject: Fix indentation --- src/object1.cc | 168 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 83 insertions(+), 85 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index e81c5742..7a9f7543 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -2876,101 +2876,99 @@ bool_ object_out_desc(object_type *o_ptr, FILE *fff, bool_ trim_down, bool_ wait text_out("It makes you invisible. "); } + vn = 0; + if (flags & TR_SUST_STR) { - vn = 0; - if (flags & TR_SUST_STR) - { - vp[vn++] = "strength"; - } - if (flags & TR_SUST_INT) - { - vp[vn++] = "intelligence"; - } - if (flags & TR_SUST_WIS) - { - vp[vn++] = "wisdom"; - } - if (flags & TR_SUST_DEX) - { - vp[vn++] = "dexterity"; - } - if (flags & TR_SUST_CON) - { - vp[vn++] = "constitution"; - } - if (flags & TR_SUST_CHR) - { - vp[vn++] = "charisma"; - } - /* Describe */ - if (vn) - { - int i; + vp[vn++] = "strength"; + } + if (flags & TR_SUST_INT) + { + vp[vn++] = "intelligence"; + } + if (flags & TR_SUST_WIS) + { + vp[vn++] = "wisdom"; + } + if (flags & TR_SUST_DEX) + { + vp[vn++] = "dexterity"; + } + if (flags & TR_SUST_CON) + { + vp[vn++] = "constitution"; + } + if (flags & TR_SUST_CHR) + { + vp[vn++] = "charisma"; + } + /* Describe */ + if (vn) + { + int i; - /* Intro */ - text_out("It sustains "); + /* Intro */ + text_out("It sustains "); - /* List */ - for (i = 0; i < vn; i++) - { - /* Connectives */ - if (i == 0) text_out("your "); - else if (i < (vn - 1)) text_out(", "); - else text_out(" and "); + /* List */ + for (i = 0; i < vn; i++) + { + /* Connectives */ + if (i == 0) text_out("your "); + else if (i < (vn - 1)) text_out(", "); + else text_out(" and "); - /* Dump the stat */ - text_out(vp[i]); - } - text_out(". "); + /* Dump the stat */ + text_out(vp[i]); } + text_out(". "); + } - vn = 0; - if (flags & TR_IM_ACID) - { - vc[vn] = TERM_GREEN; - vp[vn++] = "acid"; - } - if (flags & TR_IM_ELEC) - { - vc[vn] = TERM_L_BLUE; - vp[vn++] = "electricity"; - } - if (flags & TR_IM_FIRE) - { - vc[vn] = TERM_RED; - vp[vn++] = "fire"; - } - if (flags & TR_IM_COLD) - { - vc[vn] = TERM_L_WHITE; - vp[vn++] = "cold"; - } - if (flags & TR_IM_NETHER) - { - vc[vn] = TERM_L_GREEN; - vp[vn++] = "nether"; - } - /* Describe */ - if (vn) - { - int i; + vn = 0; + if (flags & TR_IM_ACID) + { + vc[vn] = TERM_GREEN; + vp[vn++] = "acid"; + } + if (flags & TR_IM_ELEC) + { + vc[vn] = TERM_L_BLUE; + vp[vn++] = "electricity"; + } + if (flags & TR_IM_FIRE) + { + vc[vn] = TERM_RED; + vp[vn++] = "fire"; + } + if (flags & TR_IM_COLD) + { + vc[vn] = TERM_L_WHITE; + vp[vn++] = "cold"; + } + if (flags & TR_IM_NETHER) + { + vc[vn] = TERM_L_GREEN; + vp[vn++] = "nether"; + } + /* Describe */ + if (vn) + { + int i; - /* Intro */ - text_out("It provides immunity "); + /* Intro */ + text_out("It provides immunity "); - /* List */ - for (i = 0; i < vn; i++) - { - /* Connectives */ - if (i == 0) text_out("to "); - else if (i < (vn - 1)) text_out(", "); - else text_out(" and "); + /* List */ + for (i = 0; i < vn; i++) + { + /* Connectives */ + if (i == 0) text_out("to "); + else if (i < (vn - 1)) text_out(", "); + else text_out(" and "); - /* Dump the stat */ - text_out_c(vc[i], vp[i]); - } - text_out(". "); + /* Dump the stat */ + text_out_c(vc[i], vp[i]); } + text_out(". "); } if (flags & TR_FREE_ACT) -- cgit v1.2.3 From 1bbec92ffb269156c2a3e32b25072eab572502ef Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Thu, 6 Oct 2016 07:47:56 +0200 Subject: Fix out-of-bounds accesses to set_info --- src/object1.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 7a9f7543..8f1e5905 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -6058,10 +6058,10 @@ bool_ wield_set(s16b a_idx, s16b set_idx, bool_ silent) auto &set_info = game->edit_data.set_info; auto const &a_info = game->edit_data.a_info; - auto s_ptr = &set_info[set_idx]; - if ( -1 == a_info[a_idx].set) return (FALSE); + auto s_ptr = &set_info[set_idx]; + int i; for (i = 0; i < s_ptr->num; i++) { @@ -6094,10 +6094,10 @@ bool_ takeoff_set(s16b a_idx, s16b set_idx) auto &set_info = game->edit_data.set_info; auto const &a_info = game->edit_data.a_info; - auto s_ptr = &set_info[set_idx]; - if ( -1 == a_info[a_idx].set) return (FALSE); + auto s_ptr = &set_info[set_idx]; + int i; for (i = 0; i < s_ptr->num; i++) { @@ -6130,13 +6130,13 @@ void apply_set(s16b a_idx, s16b set_idx) auto const &set_info = game->edit_data.set_info; auto const &a_info = game->edit_data.a_info; - auto s_ptr = &set_info[set_idx]; - if ( -1 == a_info[a_idx].set) { return; } + auto s_ptr = &set_info[set_idx]; + int i; for (i = 0; i < s_ptr->num; i++) { -- cgit v1.2.3 From 71a820e7298a670c13bd68cb3e6f2274a4dc3ba9 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 8 Oct 2016 11:38:29 +0200 Subject: Remove unused parameter from disturb() --- src/object1.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 8f1e5905..1eb9b484 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -5712,7 +5712,7 @@ static void absorb_gold(cave_type const *c_ptr) object_type *o_ptr = &o_list[this_o_idx]; /* Hack -- disturb */ - disturb(0); + disturb(); /* Pick up gold */ if (o_ptr->tval == TV_GOLD) -- cgit v1.2.3 From 54bd76ebab55ed5e090407747e6c7af402acf82b Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sun, 16 Oct 2016 12:28:53 +0200 Subject: Remove TR_SEARCH object flag Since the removal of traps its only effect was diluting the list of flags "available" for randarts and sentient items. --- src/object1.cc | 7 ------- 1 file changed, 7 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 1eb9b484..ad82f20f 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -1950,12 +1950,6 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) t += " to stealth"; } - /* Search */ - else if (flags & TR_SEARCH) - { - t += " to searching"; - } - /* Infravision */ else if (flags & TR_INFRA) { @@ -2667,7 +2661,6 @@ bool_ object_out_desc(object_type *o_ptr, FILE *fff, bool_ trim_down, bool_ wait if (flags & TR_DEX) vp[vn++] = "dexterity"; if (flags & TR_CON) vp[vn++] = "constitution"; if (flags & TR_CHR) vp[vn++] = "charisma"; - if (flags & TR_SEARCH) vp[vn++] = "searching"; if (flags & TR_INFRA) vp[vn++] = "infravision"; if (flags & TR_TUNNEL) vp[vn++] = "ability to tunnel"; if (flags & TR_SPEED) vp[vn++] = "speed"; -- cgit v1.2.3 From 33ab0c7749426684d044bd25da05526bf19de742 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 19 Nov 2016 21:16:34 +0100 Subject: Reduce length of "light radius" object description message --- src/object1.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index ad82f20f..4c065b24 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -2629,7 +2629,7 @@ bool_ object_out_desc(object_type *o_ptr, FILE *fff, bool_ trim_down, bool_ wait } else { - text_out(format("It provides light (radius %d) forever. ", radius)); + text_out(format("It provides light (radius %d). ", radius)); } } } -- cgit v1.2.3 From 5bc01c584066a0cea37021eb6e13bd96d74de7b5 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Tue, 28 Feb 2017 19:44:12 +0100 Subject: Remove Runecrafting --- src/object1.cc | 65 ++-------------------------------------------------------- 1 file changed, 2 insertions(+), 63 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 4c065b24..8d2a2bb0 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -1358,23 +1358,6 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) break; } - case TV_RUNE2: - { - if (o_ptr->sval != RUNE_STONE) - { - modstr = basenm; - basenm = "& Rune~ [#]"; - } - break; - } - - case TV_RUNE1: - { - modstr = basenm; - basenm = "& Rune~ [#]"; - break; - } - case TV_DAEMON_BOOK: case TV_BOOK: { @@ -1980,16 +1963,6 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) } } - /* Indicate "charging" Mage Staffs XXX XXX XXX */ - if (known && o_ptr->timeout && (is_ego_p(o_ptr, EGO_MSTAFF_SPELL))) - { - t += " (charging spell1)"; - } - if (known && o_ptr->xtra2 && (is_ego_p(o_ptr, EGO_MSTAFF_SPELL))) - { - t += " (charging spell2)"; - } - /* No more details wanted */ if (mode < 3) @@ -2111,15 +2084,11 @@ void object_desc_store(char *buf, object_type *o_ptr, int pref, int mode) * Determine the "Activation" (if any) for an artifact * Return a string, or NULL for "no activation" */ -cptr item_activation(object_type *o_ptr, byte num) +cptr item_activation(object_type *o_ptr) { - auto const &k_info = game->edit_data.k_info; auto const &a_info = game->edit_data.a_info; auto const &e_info = game->edit_data.e_info; - /* Needed hacks */ - static char rspell[2][80]; - /* Extract the flags */ auto const flags = object_flags(o_ptr); @@ -2134,29 +2103,6 @@ cptr item_activation(object_type *o_ptr, byte num) * for art_name */ - if (is_ego_p(o_ptr, EGO_MSTAFF_SPELL)) - { - int gf, mod, mana; - - if (!num) - { - gf = o_ptr->pval & 0xFFFF; - mod = o_ptr->pval3 & 0xFFFF; - mana = o_ptr->pval2 & 0xFF; - } - else - { - gf = o_ptr->pval >> 16; - mod = o_ptr->pval3 >> 16; - mana = o_ptr->pval2 >> 8; - } - sprintf(rspell[num], "runespell(%s, %s, %d) every %d turns", - k_info[lookup_kind(TV_RUNE1, gf)].name, - k_info[lookup_kind(TV_RUNE2, mod)].name, - mana, mana * 5); - return rspell[num]; - } - if (o_ptr->tval == TV_EGG) { return "stop or resume the egg development"; @@ -2589,14 +2535,7 @@ bool_ object_out_desc(object_type *o_ptr, FILE *fff, bool_ trim_down, bool_ wait if (flags & TR_ACTIVATE) { text_out("It can be activated for "); - if (is_ego_p(o_ptr, EGO_MSTAFF_SPELL)) - { - text_out(item_activation(o_ptr, 0)); - text_out(" and "); - text_out(item_activation(o_ptr, 1)); - } - else - text_out(item_activation(o_ptr, 0)); + text_out(item_activation(o_ptr)); /* Mega-hack -- get rid of useless line for e.g. randarts */ if (flags & TR_ACTIVATE_NO_WIELD) -- cgit v1.2.3 From 6a35e3de332df186eab39c3b67506882409a3ca2 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Tue, 2 May 2017 19:20:57 +0200 Subject: Remove redundant (void) parameters and return value casts --- src/object1.cc | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 8d2a2bb0..d10f3042 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -496,7 +496,7 @@ static void shuffle_flavors(cptr adj[], byte col[]) * * Note that the "hacked seed" may provide an RNG with alternating parity! */ -void flavor_init(void) +void flavor_init() { auto &k_info = game->edit_data.k_info; @@ -627,7 +627,7 @@ void flavor_init(void) * * The "prefs" parameter is no longer meaningful. XXX XXX XXX */ -void reset_visuals(void) +void reset_visuals() { auto &st_info = game->edit_data.st_info; auto &race_mod_info = game->edit_data.race_mod_info; @@ -3908,7 +3908,7 @@ static void show_inven_aux(bool_ mirror, object_filter_t const &filter); /* * Choice window "shadow" of the "show_inven()" function */ -void display_inven(void) +void display_inven() { show_inven_aux(TRUE, object_filter::True()); } @@ -3918,7 +3918,7 @@ void display_inven(void) /* * Choice window "shadow" of the "show_equip()" function */ -void display_equip(void) +void display_equip() { show_equip_aux(TRUE, object_filter::True()); } @@ -4018,7 +4018,7 @@ void show_inven_aux(bool_ mirror, const object_filter_t &filter) /* Save the object color, and description */ out_color[k] = tval_to_attr[o_ptr->tval % 128]; - (void)strcpy(out_desc[k], o_name); + strcpy(out_desc[k], o_name); /* Find the predicted "line length" */ l = strlen(out_desc[k]) + 5; @@ -4211,7 +4211,7 @@ void show_equip_aux(bool_ mirror, object_filter_t const &filter) /* Save the color */ out_color[k] = TERM_L_RED; - (void)strcpy(out_desc[k], o_name); + strcpy(out_desc[k], o_name); continue; } } @@ -4231,7 +4231,7 @@ void show_equip_aux(bool_ mirror, object_filter_t const &filter) /* Save the color */ out_color[k] = TERM_L_BLUE; - (void)strcpy(out_desc[k], o_name); + strcpy(out_desc[k], o_name); } else { @@ -4256,7 +4256,7 @@ void show_equip_aux(bool_ mirror, object_filter_t const &filter) /* Save the color */ out_color[k] = tval_to_attr[o_ptr->tval % 128]; - (void)strcpy(out_desc[k], o_name); + strcpy(out_desc[k], o_name); } /* Extract the maximal length (see below) */ @@ -4318,7 +4318,7 @@ void show_equip_aux(bool_ mirror, object_filter_t const &filter) /* Use labels */ { /* Mention the use */ - (void)sprintf(tmp_val, "%-14s: ", mention_use(out_rindex[j])); + sprintf(tmp_val, "%-14s: ", mention_use(out_rindex[j])); put_str(tmp_val, row + j, col + 5); /* Display the entry itself */ @@ -4361,7 +4361,7 @@ void show_equip_aux(bool_ mirror, object_filter_t const &filter) /* * Flip "inven" and "equip" in any sub-windows */ -void toggle_inven_equip(void) +void toggle_inven_equip() { int j; @@ -4417,7 +4417,7 @@ bool_ verify(cptr prompt, int item) object_desc(o_name, o_ptr, TRUE, 3); /* Prompt */ - (void)sprintf(out_val, "%s %s? ", prompt, o_name); + sprintf(out_val, "%s %s? ", prompt, o_name); /* Query */ return (get_check(out_val)); -- cgit v1.2.3 From 2c8b8579faf729b9cf21b8b2d827f0e482570bd3 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Tue, 2 May 2017 19:20:57 +0200 Subject: Move random_artifacts to Game struct --- src/object1.cc | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index d10f3042..34c22a4a 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -1022,6 +1022,7 @@ static std::string object_desc_aux(object_type const *o_ptr, int pref, int mode) auto const &k_info = game->edit_data.k_info; auto const &a_info = game->edit_data.a_info; auto const &e_info = game->edit_data.e_info; + auto const &random_artifacts = game->random_artifacts; static auto const TR_PVAL_MASK = compute_pval_mask(); bool_ hack_name = FALSE; @@ -6125,6 +6126,7 @@ static void apply_flags_set(s16b a_idx, s16b set_idx, object_flag_set *f) byte object_attr(object_type const *o_ptr) { auto const &k_info = game->edit_data.k_info; + auto const &random_artifacts = game->random_artifacts; if (o_ptr->tval == TV_RANDART) { @@ -6143,6 +6145,7 @@ byte object_attr(object_type const *o_ptr) byte object_attr_default(object_type *o_ptr) { auto const &k_info = game->edit_data.k_info; + auto const &random_artifacts = game->random_artifacts; if (o_ptr->tval == TV_RANDART) { -- cgit v1.2.3 From c0d3818fa0a3859d5f6cd923488ac3244d3c00d6 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Tue, 13 Jun 2017 18:24:42 +0200 Subject: Use ANGBAND_TERM_MAX instead of literal 8 (This won't cover nearly all cases, but it helps a little.) --- src/object1.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/object1.cc') diff --git a/src/object1.cc b/src/object1.cc index 34c22a4a..3fb2ef26 100644 --- a/src/object1.cc +++ b/src/object1.cc @@ -4367,7 +4367,7 @@ void toggle_inven_equip() int j; /* Scan windows */ - for (j = 0; j < 8; j++) + for (j = 0; j < ANGBAND_TERM_MAX; j++) { /* Unused */ if (!angband_term[j]) continue; @@ -4855,7 +4855,7 @@ static bool_ get_item_floor(int *cp, cptr pmt, cptr str, int mode, object_filter int ne = 0; /* Scan windows */ - for (j = 0; j < 8; j++) + for (j = 0; j < ANGBAND_TERM_MAX; j++) { /* Unused */ if (!angband_term[j]) continue; -- cgit v1.2.3