--- deliantra/server/common/item.C 2006/09/12 18:15:34 1.5
+++ deliantra/server/common/item.C 2010/05/12 20:40:50 1.88
@@ -1,37 +1,33 @@
-
/*
- * static char *rcsid_item_c =
- * "$Id: item.C,v 1.5 2006/09/12 18:15:34 root Exp $";
+ * This file is part of Deliantra, the Roguelike Realtime MMORPG.
+ *
+ * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
+ * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
+ * Copyright (©) 1992 Frank Tore Johansen
+ *
+ * Deliantra is free software: you can redistribute it and/or modify it under
+ * the terms of the Affero GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the Affero GNU General Public License
+ * and the GNU General Public License along with this program. If not, see
+ * .
+ *
+ * The authors can be reached via e-mail to
*/
-/*
- CrossFire, A Multiplayer game for X-windows
-
- Copyright (C) 2002 Mark Wedel & Crossfire Development Team
- Copyright (C) 1992 Frank Tore Johansen
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
- The authors can be reached via e-mail at crossfire-devel@real-time.com
-*/
-
#include
-#include
#include
#include
+const char *const coins[NUM_COINS + 1] = { "royalty", "platinacoin", "goldcoin", "silvercoin", 0 };
+
/* the ordering of this is actually doesn't make a difference
* However, for ease of use, new entries should go at the end
* so those people that debug the code that get used to something
@@ -53,54 +49,38 @@
* Basically, for the use/nonuse, the code does something like:
* "This item goes %s\n", with the use/nonuse values filling in the %s
*/
+// see include/object.h
Body_Locations body_locations[NUM_BODY_LOCATIONS] = {
- {"body_range", "in your range slot", "in a human's range slot"}
- ,
- {"body_arm", "on your arm", "on a human's arm"}
- ,
- {"body_torso", "on your body", "on a human's torso"}
- ,
- {"body_head", "on your head", "on a human's head"}
- ,
- {"body_neck", "around your neck", "around a humans neck"}
- ,
- {"body_skill", "in your skill slot", "in a human's skill slot"}
- ,
- {"body_finger", "on your finger", "on a human's finger"}
- ,
- {"body_shoulder", "around your shoulders", "around a human's shoulders"}
- ,
- {"body_foot", "on your feet", "on a human's feet"}
- ,
- {"body_hand", "on your hands", "on a human's hands"}
- ,
- {"body_wrist", "around your wrists", "around a human's wrist"}
- ,
- {"body_waist", "around your waist", "around a human's waist"}
- ,
-
+ {KW_body_skill , "You can use it as your skill" , "It is used as a skill"},
+ {KW_body_combat , "You can wield it as your weapon" , "It is used as a combat weapon"},
+ {KW_body_range , "You can use it as your range weapon" , "It is used as a range weapon"},
+ {KW_body_shield , "You can wield it as a shield" , "It is used as a shield"},
+ {KW_body_arm , "You can put it on your arm" , "It goes on a human's arm"},
+ {KW_body_torso , "You can wear it on your body" , "It goes on a human's torso"},
+ {KW_body_head , "You can wear it on your head" , "It goes on a human's head"},
+ {KW_body_neck , "You can wear it around your neck" , "It goes around a human's neck"},
+ {KW_body_finger , "You can wear it on your finger" , "It goes on a human's finger"} ,
+ {KW_body_shoulder, "You can wear it around your shoulders", "It goes around a human's shoulders"},
+ {KW_body_foot , "You can put it on your foot" , "It goes on a human's foot"},
+ {KW_body_hand , "You can put it on your hand" , "It goes on a human's hand"},
+ {KW_body_wrist , "You can wear it around your wrist" , "It goes around a human's wrist"},
+ {KW_body_waist , "You can wear it around your waist" , "It goes around a human's waist"},
/*{"body_dragon_torso", "your body", "a dragon's body"} */
};
-static char numbers[21][20] = {
- "no", "", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten",
- "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen",
- "eighteen", "nineteen", "twenty"
-};
-
static char numbers_10[10][20] = {
"zero", "ten", "twenty", "thirty", "fourty", "fifty", "sixty", "seventy",
"eighty", "ninety"
};
-static char levelnumbers[21][20] = {
+static char ordnumbers[21][20] = {
"zeroth", "first", "second", "third", "fourth", "fifth", "sixth", "seventh",
"eighth", "ninth", "tenth", "eleventh", "twelfth", "thirteenth",
- "fourteenth", "fifteenth", "sixteenth", "seventeenth", "eighteen",
- "nineteen", "twentieth"
+ "fourteenth", "fifteenth", "sixteenth", "seventeenth", "eighteenth",
+ "nineteenth", "twentieth"
};
-static char levelnumbers_10[11][20] = {
+static char ordnumbers_10[11][20] = {
"zeroth", "tenth", "twentieth", "thirtieth", "fortieth", "fiftieth", "sixtieth",
"seventieth", "eightieth", "ninetieth"
};
@@ -120,7 +100,6 @@
{POISON, "poison", "poisons", SK_ALCHEMY, 0},
{BOOK, "book", "books", SK_LITERACY, 0},
{CLOCK, "clock", "clocks", 0, 0},
- {LIGHTNING, "lightning", "lightning", 0, 0},
{ARROW, "arrow", "arrows", SK_BOWYER, 0},
{BOW, "bow", "bows", SK_BOWYER, 0},
{WEAPON, "weapon", "weapons", SK_SMITHERY, 0},
@@ -150,7 +129,6 @@
{TELEPORTER, "teleporter", "teleporters", 0, 0},
{CREATOR, "creator", "creators", 0, 0},
{SKILL, "skill", "skills", 0, 0},
- {EXPERIENCE, "experience", "experience", 0, 0},
{EARTHWALL, "earthwall", "earthwalls", 0, 0},
{GOLEM, "golem", "golems", 0, 0},
{THROWN_OBJ, "projectile", "projectiles", 0, 0},
@@ -175,27 +153,21 @@
{SHOP_FLOOR, "shop floor", "shop floors", 0, 0},
{SHOP_MAT, "shop mat", "shop mats", 0, 0},
{RING, "ring", "rings", SK_JEWELER, 0},
- {FLOOR, "floor", "floors", 0, 0},
+// {FLOOR, "floor", "floors", 0, 0},
{FLESH, "flesh", "flesh", SK_WOODSMAN, 0},
{INORGANIC, "inorganic", "inorganics", SK_ALCHEMY, 0},
{SKILL_TOOL, "skill tool", "skill tools", 0, 0},
{LIGHTER, "lighter", "lighters", 0, 0},
- {TRAP_PART, "trap part", "trap parts", 0, 0},
- {WALL, "wall", "walls", 0, 0},
- {LIGHT_SOURCE, "light source", "light sources", 0, 0},
+ {BUILDABLE_WALL, "buildable wall", "buildable walls", 0, 0},
{MISC_OBJECT, "bric-a-brac", "bric-a-brac", 0, 0},
- {MONSTER, "monster", "monsters", 0, 0},
- {SPAWN_GENERATOR, "monster generator", "monster generators", 0, 0},
{LAMP, "lamp", "lamps", 0, 0},
{DUPLICATOR, "duplicator", "duplicators", 0, 0},
- {TOOL, "tool", "tools", 0, 0},
{SPELLBOOK, "spellbook", "spellbooks", SK_LITERACY, 0},
- {BUILDFAC, "building facility", "building facilities", 0, 0},
{CLOAK, "cloak", "cloaks", SK_SMITHERY, 0},
{SPINNER, "spinner", "spinners", 0, 0},
{GATE, "gate", "gates", 0, 0},
{BUTTON, "button", "buttons", 0, 0},
- {CF_HANDLE, "cf handle", "cf handles", 0, 0},
+ {T_HANDLE, "cf handle", "cf handles", 0, 0},
{HOLE, "hole", "holes", 0, 0},
{TRAPDOOR, "trapdoor", "trapdoors", 0, 0},
{SIGN, "sign", "signs", 0, 0},
@@ -207,8 +179,6 @@
{BRACERS, "bracers", "bracers", SK_SMITHERY, 0},
{POISONING, "poisoning", "poisonings", 0, 0},
{SAVEBED, "savebed", "savebeds", 0, 0},
- {POISONCLOUD, "poison cloud", "poison clouds", 0, 0},
- {FIREHOLES, "fireholes", "fireholes", 0, 0},
{WAND, "wand", "wands", SK_THAUMATURGY, 0},
{SCROLL, "scroll", "scrolls", SK_LITERACY, 0},
{DIRECTOR, "director", "directors", 0, 0},
@@ -234,32 +204,7 @@
{ITEM_TRANSFORMER, "item_transformer", "item_transformers", 0, 0},
};
-const int item_types_size = sizeof (item_types) / sizeof (*item_types);
-
-materialtype_t *materialt;
-
-/*
-materialtype material[NROFMATERIALS] = {
- * P M F E C C A D W G P S P T F C D D C C G H B I *
- * H A I L O O C R E H O L A U E A E E H O O O L N *
- * Y G R E L N I A A O I O R R A N P A A U D L I T *
- * S I E C D F D I P S S W A N R C L T O N Y N R *
- * I C T U N O T O L E E H S T P D N *
- {"paper", {15,10,17, 9, 5, 7,13, 0,20,15, 0,0,0,0,0,10,0,0,0,0,0,0,0,0}},
- {"metal", { 2,12, 3,12, 2,10, 7, 0,20,15, 0,0,0,0,0,10,0,0,0,0,0,0,0,0}},
- {"glass", {14,11, 8, 3,10, 5, 1, 0,20,15, 0,0,0,0,0, 0,0,0,0,0,0,0,0,0}},
- {"leather", { 5,10,10, 3, 3,10,10, 0,20,15, 0,0,0,0,0,12,0,0,0,0,0,0,0,0}},
- {"wood", {10,11,13, 2, 2,10, 9, 0,20,15, 0,0,0,0,0,12,0,0,0,0,0,0,0,0}},
- {"organics", { 3,12, 9,11, 3,10, 9, 0,20,15, 0,0,0,0,0, 0,0,0,0,0,0,0,0,0}},
- {"stone", { 2, 5, 2, 2, 2, 2, 1, 0,20,15, 0,0,0,0,0, 5,0,0,0,0,0,0,0,0}},
- {"cloth", {14,11,13, 4, 4, 5,10, 0,20,15, 0,0,0,0,0, 5,0,0,0,0,0,0,0,0}},
- {"adamant", { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0,0,0,0, 0,0,0,0,0,0,0,0,0}},
- {"liquid", { 0, 8, 9, 6,17, 0,15, 0,20,15,12,0,0,0,0,11,0,0,0,0,0,0,0,0}},
- {"soft metal",{ 6,12, 6,14, 2,10, 1, 0,20,15, 0,0,0,0,0,10,0,0,0,0,0,0,0,0}},
- {"bone", {10, 9, 4, 5, 3,10,10, 0,20,15, 0,0,0,0,0, 2,0,0,0,0,0,0,0,0}},
- {"ice", {14,11,16, 5, 0, 5, 6, 0,20,15, 0,0,0,0,0, 7,0,0,0,0,0,0,0,0}}
-};
-*/
+static const int item_types_size = array_length (item_types);
/* This curve may be too steep. But the point is that there should
* be tough choices - there is no real point to this if everyone can
@@ -271,20 +216,62 @@
* custom objects can use whatever they want.
*/
static int enc_to_item_power[21] = {
- 0, 0, 1, 2, 3, 4, /* 5 */
- 5, 7, 9, 11, 13, /* 10 */
- 15, 18, 21, 24, 27, /* 15 */
- 30, 35, 40, 45, 50 /* 20 */
+ 0,
+ 0, 1, 2, 3, 4, // 5
+ 5, 7, 9, 11, 13, // 10
+ 15, 18, 21, 24, 27, // 15
+ 30, 35, 40, 45, 50 // 20
};
int
get_power_from_ench (int ench)
{
- if (ench < 0)
- ench = 0;
- if (ench > 20)
- ench = 20;
- return enc_to_item_power[ench];
+ return enc_to_item_power [clamp (ench, 0, 20)];
+}
+
+static const struct need_identify_types : typeset
+{
+ need_identify_types ()
+ {
+ set (RING);
+ set (WAND);
+ set (ROD);
+ set (HORN);
+ set (SCROLL);
+ set (SKILL);
+ set (SKILLSCROLL);
+ set (SPELLBOOK);
+ set (FOOD);
+ set (POTION);
+ set (BOW);
+ set (ARROW);
+ set (WEAPON);
+ set (ARMOUR);
+ set (SHIELD);
+ set (HELMET);
+ set (AMULET);
+ set (BOOTS);
+ set (GLOVES);
+ set (BRACERS);
+ set (GIRDLE);
+ set (CONTAINER);
+ set (DRINK);
+ set (FLESH);
+ set (INORGANIC);
+ set (CLOSE_CON);
+ set (CLOAK);
+ set (GEM);
+ set (POWER_CRYSTAL);
+ set (POISON);
+ set (BOOK);
+ set (SKILL_TOOL);
+ }
+} need_identify_types;
+
+bool
+object::need_identify () const
+{
+ return need_identify_types [type];
}
/* This takes an object 'op' and figures out what its item_power
@@ -301,7 +288,7 @@
enc = 0;
for (i = 0; i < NUM_STATS; i++)
- enc += get_attr_value (&op->stats, i);
+ enc += op->stats.stat (i);
/* This protection logic is pretty flawed. 20% fire resistance
* is much more valuable than 20% confusion, or 20% slow, or
@@ -328,9 +315,11 @@
for (i = 1; i < NROFATTACKS; i++)
if (op->attacktype & (1 << i))
enc++;
+
if (op->slaying)
enc += 2; /* What it slays is probably more relevent */
}
+
/* Items the player can equip */
if ((op->type == WEAPON) || (op->type == ARMOUR) || (op->type == HELMET) ||
(op->type == SHIELD) || (op->type == RING) ||
@@ -343,72 +332,72 @@
enc += op->stats.grace; /* grace regen */
enc += op->stats.exp; /* speed bonus */
}
+
enc += op->stats.luck;
/* Do spell paths now */
for (i = 1; i < NRSPELLPATHS; i++)
- {
- if (op->path_attuned & (1 << i))
- enc++;
- else if (op->path_denied & (1 << i))
- enc -= 2;
- else if (op->path_repelled & (1 << i))
- enc--;
- }
-
- if (QUERY_FLAG (op, FLAG_LIFESAVE))
- enc += 5;
- if (QUERY_FLAG (op, FLAG_REFL_SPELL))
- enc += 3;
- if (QUERY_FLAG (op, FLAG_REFL_MISSILE))
- enc += 2;
- if (QUERY_FLAG (op, FLAG_STEALTH))
- enc += 1;
- if (QUERY_FLAG (op, FLAG_XRAYS))
- enc += 2;
- if (QUERY_FLAG (op, FLAG_SEE_IN_DARK))
- enc += 1;
- if (QUERY_FLAG (op, FLAG_MAKE_INVIS))
- enc += 1;
+ if (op->path_attuned & (1 << i))
+ enc++;
+ else if (op->path_denied & (1 << i))
+ enc -= 2;
+ else if (op->path_repelled & (1 << i))
+ enc--;
+
+ if (op->flag [FLAG_LIFESAVE ]) enc += 5;
+ if (op->flag [FLAG_REFL_SPELL ]) enc += 3;
+ if (op->flag [FLAG_REFL_MISSILE]) enc += 2;
+ if (op->flag [FLAG_XRAYS ]) enc += 2;
+ if (op->flag [FLAG_STEALTH ]) enc += 1;
+ if (op->flag [FLAG_SEE_IN_DARK ]) enc += 1;
+ if (op->flag [FLAG_MAKE_INVIS ]) enc += 1;
return get_power_from_ench (enc);
-
}
+static const struct get_typedata
+{
+ const typedata *data [NUM_TYPES];
+
+ get_typedata ()
+ {
+ for (int i = 0; i < item_types_size; i++)
+ data [item_types[i].number] = &item_types [i];
+ }
+
+ const typedata *operator ()(int itemtype) const
+ {
+ return data [itemtype];
+ }
+} get_typedata_;
+
/* returns the typedata that has a number equal to itemtype, if there
* isn't one, returns NULL */
-
const typedata *
get_typedata (int itemtype)
{
- int i;
-
- for (i = 0; i < item_types_size; i++)
- if (item_types[i].number == itemtype)
- return &item_types[i];
- return NULL;
+ return get_typedata_ (itemtype);
}
/* returns the typedata that has a name equal to itemtype, if there
* isn't one, return the plural name that matches, if there still isn't
* one return NULL */
-
const typedata *
get_typedata_by_name (const char *name)
{
- int i;
-
- for (i = 0; i < item_types_size; i++)
+ for (int i = 0; i < item_types_size; i++)
if (!strcmp (item_types[i].name, name))
return &item_types[i];
- for (i = 0; i < item_types_size; i++)
+
+ for (int i = 0; i < item_types_size; i++)
if (!strcmp (item_types[i].name_pl, name))
{
LOG (llevInfo,
- "get_typedata_by_name: I have been sent the plural %s, the singular form %s is preffered\n", name, item_types[i].name);
+ "get_typedata_by_name: I have been sent the plural %s, the singular form %s is prefered\n", name, item_types[i].name);
return &item_types[i];
}
- return NULL;
+
+ return 0;
}
/* describe_resistance generates the visible naming for resistances.
@@ -417,48 +406,39 @@
* if newline is true, we don't put parens around the description
* but do put a newline at the end. Useful when dumping to files
*/
-char *
+const char *
describe_resistance (const object *op, int newline)
{
- static char buf[VERY_BIG_BUF];
- char buf1[VERY_BIG_BUF];
- int tmpvar;
+ static dynbuf_text buf; buf.clear ();
- buf[0] = 0;
- for (tmpvar = 0; tmpvar < NROFATTACKS; tmpvar++)
- {
- if (op->resist[tmpvar] && (op->type != FLESH || atnr_is_dragon_enabled (tmpvar) == 1))
- {
- if (!newline)
- sprintf (buf1, "(%s %+d)", resist_plus[tmpvar], op->resist[tmpvar]);
- else
- sprintf (buf1, "%s %d\n", resist_plus[tmpvar], op->resist[tmpvar]);
+ for (int i = 0; i < NROFATTACKS; i++)
+ if (op->resist[i] && (op->type != FLESH || atnr_is_dragon_enabled (i) == 1))
+ buf.printf (newline ? "%s %d\n" : "(%s %+d)", resist_plus[i], op->resist[i]);
- strcat (buf, buf1);
- }
- }
return buf;
}
-
/*
* query_weight(object) returns a character pointer to a static buffer
* containing the text-representation of the weight of the given object.
* The buffer will be overwritten by the next call to query_weight().
+ *
+ * Seems to be used only by unimportant stuff. Remove?
*/
-
-char *
+const char *
query_weight (const object *op)
{
static char buf[10];
- sint32 i = (op->nrof ? op->nrof : 1) * op->weight + op->carrying;
+ sint32 i = op->total_weight ();
if (op->weight < 0)
return " ";
+
if (i % 1000)
sprintf (buf, "%6.1f", i / 1000.0);
else
sprintf (buf, "%4d ", i / 1000);
+
return buf;
}
@@ -466,46 +446,30 @@
* Returns the pointer to a static buffer containing
* the number requested (of the form first, second, third...)
*/
-
-char *
-get_levelnumber (int i)
+const char *
+ordinal (int i)
{
- static char buf[MAX_BUF];
+ if (i < 0)
+ return format ("minus %s", ordinal (-i));
- if (i > 99)
- {
- sprintf (buf, "%d.", i);
- return buf;
- }
if (i < 21)
- return levelnumbers[i];
- if (!(i % 10))
- return levelnumbers_10[i / 10];
- strcpy (buf, numbers_10[i / 10]);
- strcat (buf, levelnumbers[i % 10]);
- return buf;
-}
+ return ordnumbers[i];
+ int digit = i % 10;
-/*
- * get_number(integer) returns the text-representation of the given number
- * in a static buffer. The buffer might be overwritten at the next
- * call to get_number().
- * It is currently only used by the query_name() function.
- */
+ if (i >= 100)
+ return format (
+ digit == 1 ? "%dst"
+ : digit == 2 ? "%dnd"
+ : digit == 3 ? "%drd"
+ : "%dth",
+ i
+ );
-char *
-get_number (int i)
-{
- if (i <= 20)
- return numbers[i];
+ if (digit == 0)
+ return ordnumbers_10[i / 10];
else
- {
- static char buf[MAX_BUF];
-
- sprintf (buf, "%d", i);
- return buf;
- }
+ return format ("%s%s", numbers_10[i / 10], ordnumbers[i % 10]);
}
/*
@@ -521,67 +485,43 @@
/* Aug 95 modified this slightly so that Skill tools don't have magic bonus
* from stats.sp - b.t.
*/
-char *
+static const char *
ring_desc (const object *op)
{
- static char buf[VERY_BIG_BUF];
+ static dynbuf_text buf; buf.clear ();
int attr, val, len;
- buf[0] = 0;
-
- if (!QUERY_FLAG (op, FLAG_IDENTIFIED))
- return buf;
-
- for (attr = 0; attr < NUM_STATS; attr++)
+ if (op->flag [FLAG_IDENTIFIED])
{
- if ((val = get_attr_value (&(op->stats), attr)) != 0)
- {
- sprintf (buf + strlen (buf), "(%s%+d)", short_stat_name[attr], val);
- }
- }
- if (op->stats.exp)
- sprintf (buf + strlen (buf), "(speed %+lld)", (long long) op->stats.exp);
- if (op->stats.wc)
- sprintf (buf + strlen (buf), "(wc%+d)", op->stats.wc);
- if (op->stats.dam)
- sprintf (buf + strlen (buf), "(dam%+d)", op->stats.dam);
- if (op->stats.ac)
- sprintf (buf + strlen (buf), "(ac%+d)", op->stats.ac);
-
- strcat (buf, describe_resistance (op, 0));
-
- if (op->stats.food != 0)
- sprintf (buf + strlen (buf), "(sustenance%+d)", op->stats.food);
- /* else if (op->stats.food < 0)
- sprintf(buf+strlen(buf), "(hunger%+d)", op->stats.food); */
- if (op->stats.grace)
- sprintf (buf + strlen (buf), "(grace%+d)", op->stats.grace);
- if (op->stats.sp && op->type != SKILL)
- sprintf (buf + strlen (buf), "(magic%+d)", op->stats.sp);
- if (op->stats.hp)
- sprintf (buf + strlen (buf), "(regeneration%+d)", op->stats.hp);
- if (op->stats.luck)
- sprintf (buf + strlen (buf), "(luck%+d)", op->stats.luck);
- if (QUERY_FLAG (op, FLAG_LIFESAVE))
- strcat (buf, "(lifesaving)");
- if (QUERY_FLAG (op, FLAG_REFL_SPELL))
- strcat (buf, "(reflect spells)");
- if (QUERY_FLAG (op, FLAG_REFL_MISSILE))
- strcat (buf, "(reflect missiles)");
- if (QUERY_FLAG (op, FLAG_STEALTH))
- strcat (buf, "(stealth)");
- /* Shorten some of the names, so they appear better in the windows */
- len = strlen (buf);
- DESCRIBE_PATH_SAFE (buf, op->path_attuned, "Attuned", &len, VERY_BIG_BUF);
- DESCRIBE_PATH_SAFE (buf, op->path_repelled, "Repelled", &len, VERY_BIG_BUF);
- DESCRIBE_PATH_SAFE (buf, op->path_denied, "Denied", &len, VERY_BIG_BUF);
+ for (attr = 0; attr < NUM_STATS; attr++)
+ if ((val = op->stats.stat (attr)))
+ buf.printf ("(%s%+d)", short_stat_name[attr], val);
- /* if(op->item_power)
- sprintf(buf+strlen(buf), "(item_power %+d)",op->item_power);
- */
- if (buf[0] == 0 && op->type != SKILL)
- strcpy (buf, "of adornment");
+ if (op->stats.exp) buf.printf ("(speed %+d)", (int)op->stats.exp);
+ if (op->stats.wc) buf.printf ("(wc%+d)", op->stats.wc);
+ if (op->stats.dam) buf.printf ("(dam%+d)", op->stats.dam);
+ if (op->stats.ac) buf.printf ("(ac%+d)", op->stats.ac);
+
+ buf << describe_resistance (op, 0);
+
+ if (op->stats.food) buf.printf ("(sustenance%+d)", op->stats.food);
+ if (op->stats.grace) buf.printf ("(grace%+d)", op->stats.grace);
+ if (op->stats.sp && op->type != SKILL) buf.printf ("(magic%+d)", op->stats.sp);
+ if (op->stats.hp) buf.printf ("(regeneration%+d)", op->stats.hp);
+ if (op->stats.luck) buf.printf ("(luck%+d)", op->stats.luck);
+
+ if (op->flag [FLAG_LIFESAVE]) buf << "(lifesaving)";
+ if (op->flag [FLAG_REFL_SPELL]) buf << "(reflect spells)";
+ if (op->flag [FLAG_REFL_MISSILE]) buf << "(reflect missiles)";
+ if (op->flag [FLAG_STEALTH]) buf << "(stealth)";
+
+ buf.add_paths ("Attuned" , op->path_attuned);
+ buf.add_paths ("Repelled", op->path_repelled);
+ buf.add_paths ("Denied" , op->path_denied);
+ if (buf.empty ())
+ buf << "of adornment";
+ }
return buf;
}
@@ -589,77 +529,90 @@
/*
* query_short_name(object) is similar to query_name, but doesn't
* contain any information about object status (worn/cursed/etc.)
+ *
+ * It is sometimes used when printing messages, so should fit well into a sentence.
*/
const char *
query_short_name (const object *op)
{
- static char buf[HUGE_BUF];
- char buf2[HUGE_BUF];
- int len = 0;
-
- if (op->name == NULL)
+ if (!op->name)
return "(null)";
- if (!op->nrof && !op->weight && !op->title && !is_magical (op))
+ if (!op->nrof
+ && !op->weight
+ && !op->title
+ && !is_magical (op)
+ && op->slaying != shstr_money)
return op->name; /* To speed things up (or make things slower?) */
- if (op->nrof <= 1)
- safe_strcat (buf, op->name, &len, HUGE_BUF);
- else
- safe_strcat (buf, op->name_pl, &len, HUGE_BUF);
+ static dynbuf_text buf; buf.clear ();
- if (op->title && QUERY_FLAG (op, FLAG_IDENTIFIED))
- {
- safe_strcat (buf, " ", &len, HUGE_BUF);
- safe_strcat (buf, op->title, &len, HUGE_BUF);
- }
+ buf << (op->nrof <= 1 ? op->name : op->name_pl);
+
+ if (op->title && op->flag [FLAG_IDENTIFIED])
+ buf << ' ' << op->title;
switch (op->type)
{
- case SPELLBOOK:
- case SCROLL:
- case WAND:
- case ROD:
- if (QUERY_FLAG (op, FLAG_IDENTIFIED) || QUERY_FLAG (op, FLAG_BEEN_APPLIED))
- {
- if (!op->title)
- {
- safe_strcat (buf, " of ", &len, HUGE_BUF);
- if (op->inv)
- safe_strcat (buf, op->inv->name, &len, HUGE_BUF);
- else
- LOG (llevError, "Spellbook %s lacks inventory\n", &op->name);
- }
- if (op->type != SPELLBOOK)
- {
- sprintf (buf2, " (lvl %d)", op->level);
- safe_strcat (buf, buf2, &len, HUGE_BUF);
- }
- }
- break;
+ case SPELLBOOK:
+ case SCROLL:
+ case WAND:
+ case ROD:
+ if (op->flag [FLAG_IDENTIFIED] || op->flag [FLAG_BEEN_APPLIED])
+ {
+ if (!op->title)
+ buf << " of " << (op->inv ? &op->inv->name : "bug, please report");
- case SKILL:
- case AMULET:
- case RING:
- if (!op->title)
- {
- /* If ring has a title, full description isn't so useful */
- char *s = ring_desc (op);
-
- if (s[0])
- {
- safe_strcat (buf, " ", &len, HUGE_BUF);
- safe_strcat (buf, s, &len, HUGE_BUF);
- }
- }
- break;
- default:
- if (op->magic && ((QUERY_FLAG (op, FLAG_BEEN_APPLIED) && need_identify (op)) || QUERY_FLAG (op, FLAG_IDENTIFIED)))
- {
- sprintf (buf2, " %+d", op->magic);
- safe_strcat (buf, buf2, &len, HUGE_BUF);
- }
+ if (op->type != SPELLBOOK)
+ buf.printf (" (lvl %d)", op->level);
+ }
+ break;
+
+ case ALTAR:
+ case TRIGGER_ALTAR:
+ case IDENTIFY_ALTAR:
+ case CONVERTER:
+ if (op->slaying == shstr_money)
+ {
+ bool wrap = !!buf.size ();
+
+ if (wrap) buf << " [";
+
+ archetype *coin = 0;
+
+ for (char const *const *c = coins; *coins; ++c)
+ if ((coin = archetype::find (*c)))
+ if (op->stats.food % coin->value == 0)
+ break;
+
+ sint32 coins = op->stats.food / coin->value;
+
+ buf.printf ("drop %d %s (or equivalent)", coins, coins == 1 ? &coin->name : &coin->name_pl);
+
+ if (wrap) buf << ']';
+ }
+ break;
+
+ case SKILL:
+ case AMULET:
+ case RING:
+ if (!op->title)
+ {
+ /* If ring has a title, full description isn't so useful */
+ const char *s = ring_desc (op);
+
+ if (s && *s)
+ buf << " " << s;
+ }
+ break;
+
+ default:
+ if (op->magic
+ && ((op->flag [FLAG_BEEN_APPLIED] && op->need_identify ())
+ || op->flag [FLAG_IDENTIFIED]))
+ buf.printf (" %+d", op->magic);
}
+
return buf;
}
@@ -673,47 +626,43 @@
* returned is good forever.) However, it makes printing statements that
* use several names much easier (don't need to store them to temp variables.)
*
+ * It is used extensively within messages, so should return only a prose
+ * and short description of the item.
+ * It is also used by examine/ex and similar functions.
*/
-char *
+const char *
query_name (const object *op)
{
- static char buf[5][HUGE_BUF];
- static int use_buf = 0;
int len = 0;
-
-#ifdef NEW_MATERIAL_CODE
- materialtype_t *mt;
-#endif
+ static dynbuf_text bufs[5];
+ static int use_buf = 0;
use_buf++;
use_buf %= 5;
-#ifdef NEW_MATERIAL_CODE
- if ((IS_ARMOR (op) || IS_WEAPON (op)) && op->materialname)
- {
- mt = name_to_material (op->materialname);
- if (mt)
- {
- safe_strcat (buf[use_buf], mt->description, &len, HUGE_BUF);
- safe_strcat (buf[use_buf], " ", &len, HUGE_BUF);
- }
- }
+ dynbuf_text &buf = bufs [use_buf];
+ buf.clear ();
+
+#if 0
+ if ((op->is_armor () || op->is_weapon ()) && op->material)
+ buf << op->material->description << ' ';
#endif
- safe_strcat (buf[use_buf], query_short_name (op), &len, HUGE_BUF);
+ buf << query_short_name (op);
- if (QUERY_FLAG (op, FLAG_INV_LOCKED))
- safe_strcat (buf[use_buf], " *", &len, HUGE_BUF);
- if (op->type == CONTAINER && ((op->env && op->env->container == op) || (!op->env && QUERY_FLAG (op, FLAG_APPLIED))))
- safe_strcat (buf[use_buf], " (open)", &len, HUGE_BUF);
-
- if (QUERY_FLAG (op, FLAG_KNOWN_CURSED))
- {
- if (QUERY_FLAG (op, FLAG_DAMNED))
- safe_strcat (buf[use_buf], " (damned)", &len, HUGE_BUF);
- else if (QUERY_FLAG (op, FLAG_CURSED))
- safe_strcat (buf[use_buf], " (cursed)", &len, HUGE_BUF);
+ if (op->flag [FLAG_INV_LOCKED])
+ buf << " *";
+ if (op->is_open_container ())
+ buf << " (open)";
+
+ if (op->flag [FLAG_KNOWN_CURSED])
+ {
+ if (op->flag [FLAG_DAMNED])
+ buf << " (damned)";
+ else if (op->flag [FLAG_CURSED])
+ buf << " (cursed)";
}
+
/* Basically, if the object is known magical (detect magic spell on it),
* and it isn't identified, print out the fact that
* it is magical. Assume that the detect magical spell will only set
@@ -723,11 +672,11 @@
* if it has been applied. Equipping an item does not tell full
* abilities, especially for artifact items.
*/
- if (QUERY_FLAG (op, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (op, FLAG_IDENTIFIED))
- safe_strcat (buf[use_buf], " (magic)", &len, HUGE_BUF);
+ if (op->flag [FLAG_KNOWN_MAGICAL] && !op->flag [FLAG_IDENTIFIED])
+ buf << " (magic)";
#if 0
- /* item_power will be returned in desribe_item - it shouldn't really
+ /* item_power will be returned in describe_item - it shouldn't really
* be returned in the name.
*/
if (op->item_power)
@@ -735,43 +684,63 @@
#endif
- if (QUERY_FLAG (op, FLAG_APPLIED))
+ if (op->flag [FLAG_APPLIED])
{
switch (op->type)
{
- case BOW:
- case WAND:
- case ROD:
- case HORN:
- safe_strcat (buf[use_buf], " (readied)", &len, HUGE_BUF);
- break;
- case WEAPON:
- safe_strcat (buf[use_buf], " (wielded)", &len, HUGE_BUF);
- break;
- case ARMOUR:
- case HELMET:
- case SHIELD:
- case RING:
- case BOOTS:
- case GLOVES:
- case AMULET:
- case GIRDLE:
- case BRACERS:
- case CLOAK:
- safe_strcat (buf[use_buf], " (worn)", &len, HUGE_BUF);
- break;
- case CONTAINER:
- safe_strcat (buf[use_buf], " (active)", &len, HUGE_BUF);
- break;
- case SKILL:
- default:
- safe_strcat (buf[use_buf], " (applied)", &len, HUGE_BUF);
+ case BOW:
+ case WAND:
+ case ROD:
+ case HORN:
+ buf << " (applied)";
+ break;
+ case WEAPON:
+ buf << " (applied)";
+ break;
+ case ARMOUR:
+ case HELMET:
+ case SHIELD:
+ case RING:
+ case BOOTS:
+ case GLOVES:
+ case AMULET:
+ case GIRDLE:
+ case BRACERS:
+ case CLOAK:
+ buf << " (worn)";
+ break;
+ case CONTAINER:
+ buf << " (active)";
+ break;
+ case SKILL:
+ default:
+ buf << " (applied)";
}
}
- if (QUERY_FLAG (op, FLAG_UNPAID))
- safe_strcat (buf[use_buf], " (unpaid)", &len, HUGE_BUF);
- return buf[use_buf];
+ switch (op->type)
+ {
+ case LAMP:
+ if (op->glow_radius)
+ buf << " (on)";
+ else if (op->stats.food <= 0)
+ buf << " (empty)";
+ else
+ buf << " (off)";
+ break;
+
+ case TORCH:
+ if (op->glow_radius)
+ buf << " (burning)";
+ else if (op->stats.food <= 0)
+ buf << " (burned out)";
+ break;
+ }
+
+ if (op->flag [FLAG_UNPAID])
+ buf << " (unpaid)";
+
+ return buf;
}
/*
@@ -782,99 +751,79 @@
* don't include the item count or item status. Used for inventory sorting
* and sending to client.
* If plural is set, we generate the plural name of this.
+ *
+ * It is sometimes used to display messages, and usually only used to match stuff,
+ * so maybe this function should be removed.
+ * It is also used for client-side inventory/item descriptions.
*/
const char *
query_base_name (const object *op, int plural)
{
- static char buf[MAX_BUF], buf2[MAX_BUF];
- int len;
- materialtype_t *mt;
-
if ((!plural && !op->name) || (plural && !op->name_pl))
return "(null)";
- if (!op->nrof && !op->weight && !op->title && !is_magical (op))
+ if (!op->nrof && !op->weight && !op->title && !is_magical (op)
+ && op->type != EXIT)
return op->name; /* To speed things up (or make things slower?) */
- if ((IS_ARMOR (op) || IS_WEAPON (op)) && op->materialname)
- mt = name_to_material (op->materialname);
+ static dynbuf_text buf; buf.clear ();
-#ifdef NEW_MATERIAL_CODE
- if ((IS_ARMOR (op) || IS_WEAPON (op)) && op->materialname && mt &&
- op->arch->clone.materialname != mt->name && !(op->material & M_SPECIAL))
- {
- strcpy (buf, mt->description);
- len = strlen (buf);
- safe_strcat (buf, " ", &len, MAX_BUF);
- if (!plural)
- safe_strcat (buf, op->name, &len, MAX_BUF);
- else
- safe_strcat (buf, op->name_pl, &len, MAX_BUF);
- }
- else
- {
-#endif
- if (!plural)
- strcpy (buf, op->name);
- else
- strcpy (buf, op->name_pl);
- len = strlen (buf);
-#ifdef NEW_MATERIAL_CODE
- }
+#if 0
+ if ((op->is_armor () || op->is_weapon ()) && op->material)
+ if (op->arch->material != op->material)
+ buf << op->material->description << ' ';
#endif
- if (op->title && QUERY_FLAG (op, FLAG_IDENTIFIED))
- {
- safe_strcat (buf, " ", &len, MAX_BUF);
- safe_strcat (buf, op->title, &len, MAX_BUF);
- }
+ buf << (plural ? op->name_pl : op->name);
+
+ if (op->title && op->flag [FLAG_IDENTIFIED])
+ buf << ' ' << op->title;
switch (op->type)
{
- case SPELLBOOK:
- case SCROLL:
- case WAND:
- case ROD:
- if (QUERY_FLAG (op, FLAG_IDENTIFIED) || QUERY_FLAG (op, FLAG_BEEN_APPLIED))
- {
- if (!op->title)
- {
- safe_strcat (buf, " of ", &len, MAX_BUF);
- if (op->inv)
- safe_strcat (buf, op->inv->name, &len, MAX_BUF);
- else
- LOG (llevError, "Spellbook %s lacks inventory\n", &op->name);
- }
- if (op->type != SPELLBOOK)
- {
- sprintf (buf2, " (lvl %d)", op->level);
- safe_strcat (buf, buf2, &len, MAX_BUF);
- }
- }
- break;
+ case SPELLBOOK:
+ case SCROLL:
+ case WAND:
+ case ROD:
+ if (op->flag [FLAG_IDENTIFIED] || op->flag [FLAG_BEEN_APPLIED])
+ {
+ if (!op->title)
+ buf << " of " << (op->inv ? &op->inv->name : "bug, please report");
+ if (op->type != SPELLBOOK)
+ buf.printf (" (lvl %d)", op->level);
+ }
+ break;
- case SKILL:
- case AMULET:
- case RING:
- if (!op->title)
- {
- /* If ring has a title, full description isn't so useful */
- char *s = ring_desc (op);
-
- if (s[0])
- {
- safe_strcat (buf, " ", &len, MAX_BUF);
- safe_strcat (buf, s, &len, MAX_BUF);
- }
- }
- break;
- default:
- if (op->magic && ((QUERY_FLAG (op, FLAG_BEEN_APPLIED) && need_identify (op)) || QUERY_FLAG (op, FLAG_IDENTIFIED)))
- {
- sprintf (buf + strlen (buf), " %+d", op->magic);
- }
+
+ case SKILL:
+ case AMULET:
+ case RING:
+ if (!op->title)
+ {
+ /* If ring has a title, full description isn't so useful */
+ const char *s = ring_desc (op);
+
+ if (s && *s)
+ buf << ' ' << s;
+ }
+ break;
+
+ case EXIT:
+ // random map exits "unfortunately" get patched, so this only works before entering
+ if (EXIT_PATH (op) == shstr_random_map_exit)
+ buf << " (random map)";
+ else if (!EXIT_PATH (op))
+ buf << " (closed)";
+ break;
+
+ default:
+ if (op->magic
+ && ((op->flag [FLAG_BEEN_APPLIED] && op->need_identify ())
+ || op->flag [FLAG_IDENTIFIED]))
+ buf.printf (" %+d", op->magic);
}
+
return buf;
}
@@ -884,130 +833,97 @@
* be called with monster & player objects. Returns a description
* in a static buffer.
*/
-
-static char *
+static const char *
describe_monster (const object *op)
{
- char buf[MAX_BUF];
- static char retbuf[VERY_BIG_BUF];
- int i;
-
- retbuf[0] = '\0';
+ static dynbuf_text buf; buf.clear ();
/* Note that the resolution this provides for players really isn't
* very good. Any player with a speed greater than .67 will
* fall into the 'lightning fast movement' category.
*/
- if (FABS (op->speed) > MIN_ACTIVE_SPEED)
- {
- switch ((int) ((FABS (op->speed)) * 15))
- {
- case 0:
- strcat (retbuf, "(very slow movement)");
- break;
- case 1:
- strcat (retbuf, "(slow movement)");
- break;
- case 2:
- strcat (retbuf, "(normal movement)");
- break;
- case 3:
- case 4:
- strcat (retbuf, "(fast movement)");
- break;
- case 5:
- case 6:
- strcat (retbuf, "(very fast movement)");
- break;
- case 7:
- case 8:
- case 9:
- case 10:
- strcat (retbuf, "(extremely fast movement)");
- break;
- default:
- strcat (retbuf, "(lightning fast movement)");
- break;
- }
- }
- if (QUERY_FLAG (op, FLAG_UNDEAD))
- strcat (retbuf, "(undead)");
- if (QUERY_FLAG (op, FLAG_SEE_INVISIBLE))
- strcat (retbuf, "(see invisible)");
- if (QUERY_FLAG (op, FLAG_USE_WEAPON))
- strcat (retbuf, "(wield weapon)");
- if (QUERY_FLAG (op, FLAG_USE_BOW))
- strcat (retbuf, "(archer)");
- if (QUERY_FLAG (op, FLAG_USE_ARMOUR))
- strcat (retbuf, "(wear armour)");
- if (QUERY_FLAG (op, FLAG_USE_RING))
- strcat (retbuf, "(wear ring)");
- if (QUERY_FLAG (op, FLAG_USE_SCROLL))
- strcat (retbuf, "(read scroll)");
- if (QUERY_FLAG (op, FLAG_USE_RANGE))
- strcat (retbuf, "(fires wand/rod/horn)");
- if (QUERY_FLAG (op, FLAG_CAN_USE_SKILL))
- strcat (retbuf, "(skill user)");
- if (QUERY_FLAG (op, FLAG_CAST_SPELL))
- strcat (retbuf, "(spellcaster)");
- if (QUERY_FLAG (op, FLAG_FRIENDLY))
- strcat (retbuf, "(friendly)");
- if (QUERY_FLAG (op, FLAG_UNAGGRESSIVE))
- strcat (retbuf, "(unaggressive)");
- if (QUERY_FLAG (op, FLAG_HITBACK))
- strcat (retbuf, "(hitback)");
- if (QUERY_FLAG (op, FLAG_STEALTH))
- strcat (retbuf, "(stealthy)");
- if (op->randomitems != NULL)
+ if (op->has_active_speed ())
+ switch ((int)(op->speed * 15.))
+ {
+ case 0:
+ buf << "(very slow movement)";
+ break;
+ case 1:
+ buf << "(slow movement)";
+ break;
+ case 2:
+ buf << "(normal movement)";
+ break;
+ case 3:
+ case 4:
+ buf << "(fast movement)";
+ break;
+ case 5:
+ case 6:
+ buf << "(very fast movement)";
+ break;
+ case 7:
+ case 8:
+ case 9:
+ case 10:
+ buf << "(extremely fast movement)";
+ break;
+ default:
+ buf << "(lightning fast movement)";
+ break;
+ }
+
+ if (op->flag [FLAG_UNDEAD]) buf << "(undead)";
+ if (op->flag [FLAG_SEE_INVISIBLE]) buf << "(see invisible)";
+ if (op->flag [FLAG_USE_WEAPON]) buf << "(wield weapon)";
+ if (op->flag [FLAG_USE_BOW]) buf << "(archer)";
+ if (op->flag [FLAG_USE_ARMOUR]) buf << "(wear armour)";
+ if (op->flag [FLAG_USE_RING]) buf << "(wear ring)";
+ if (op->flag [FLAG_USE_SCROLL]) buf << "(read scroll)";
+ if (op->flag [FLAG_USE_RANGE]) buf << "(fires wand/rod/horn)";
+ if (op->flag [FLAG_CAN_USE_SKILL]) buf << "(skill user)";
+ if (op->flag [FLAG_CAST_SPELL]) buf << "(spellcaster)";
+ if (op->flag [FLAG_FRIENDLY]) buf << "(friendly)";
+ if (op->flag [FLAG_UNAGGRESSIVE]) buf << "(unaggressive)";
+ if (op->flag [FLAG_HITBACK]) buf << "(hitback)";
+ if (op->flag [FLAG_STEALTH]) buf << "(stealthy)";
+
+ if (op->randomitems)
{
- treasure *t;
- int first = 1;
+ bool first = 1;
- for (t = op->randomitems->items; t != NULL; t = t->next)
- if (t->item && (t->item->clone.type == SPELL))
+ for (treasure *t = op->randomitems->items; t; t = t->next)
+ if (t->item && t->item->type == SPELL)
{
if (first)
- {
- first = 0;
- strcat (retbuf, "(Spell abilities:)");
- }
- strcat (retbuf, "(");
- strcat (retbuf, t->item->clone.name);
- strcat (retbuf, ")");
+ buf << "(Spell abilities:)";
+
+ first = 0;
+
+ buf << '(' << t->item->object::name << ')';
}
}
+
if (op->type == PLAYER)
{
if (op->contr->digestion)
- {
- if (op->contr->digestion != 0)
- sprintf (buf, "(sustenance%+d)", op->contr->digestion);
- strcat (retbuf, buf);
- }
+ buf.printf ("(sustenance%+d)", op->contr->digestion);
+
if (op->contr->gen_grace)
- {
- sprintf (buf, "(grace%+d)", op->contr->gen_grace);
- strcat (retbuf, buf);
- }
+ buf.printf ("(grace%+d)", op->contr->gen_grace);
+
if (op->contr->gen_sp)
- {
- sprintf (buf, "(magic%+d)", op->contr->gen_sp);
- strcat (retbuf, buf);
- }
+ buf.printf ("(magic%+d)", op->contr->gen_sp);
+
if (op->contr->gen_hp)
- {
- sprintf (buf, "(regeneration%+d)", op->contr->gen_hp);
- strcat (retbuf, buf);
- }
+ buf.printf ("(regeneration%+d)", op->contr->gen_hp);
+
if (op->stats.luck)
- {
- sprintf (buf, "(luck%+d)", op->stats.luck);
- strcat (retbuf, buf);
- }
+ buf.printf ("(luck%+d)", op->stats.luck);
}
/* describe attacktypes */
- if (is_dragon_pl (op))
+ if (op->is_dragon ())
{
/* for dragon players display the attacktypes from clawing skill
* Break apart the for loop - move the comparison checking down -
@@ -1015,37 +931,28 @@
*/
object *tmp;
- for (tmp = op->inv; tmp != NULL; tmp = tmp->below)
- if (tmp->type == SKILL && !strcmp (tmp->name, "clawing"))
+ for (tmp = op->inv; tmp; tmp = tmp->below)
+ if (tmp->type == SKILL && tmp->name == shstr_clawing)
break;
- if (tmp && tmp->attacktype != 0)
- {
- DESCRIBE_ABILITY (retbuf, tmp->attacktype, "Claws");
- }
+ if (tmp && tmp->attacktype)
+ buf.add_abilities ("Claws", tmp->attacktype);
else
- {
- DESCRIBE_ABILITY (retbuf, op->attacktype, "Attacks");
- }
+ buf.add_abilities ("Attacks", op->attacktype);
}
else
- {
- DESCRIBE_ABILITY (retbuf, op->attacktype, "Attacks");
- }
- DESCRIBE_PATH (retbuf, op->path_attuned, "Attuned");
- DESCRIBE_PATH (retbuf, op->path_repelled, "Repelled");
- DESCRIBE_PATH (retbuf, op->path_denied, "Denied");
- for (i = 0; i < NROFATTACKS; i++)
- {
- if (op->resist[i])
- {
- sprintf (buf, "(%s %+d)", resist_plus[i], op->resist[i]);
- strcat (retbuf, buf);
- }
- }
- return retbuf;
-}
+ buf.add_abilities ("Attacks", op->attacktype);
+ buf.add_paths ("Attuned" , op->path_attuned);
+ buf.add_paths ("Repelled", op->path_repelled);
+ buf.add_paths ("Denied" , op->path_denied);
+
+ for (int i = 0; i < NROFATTACKS; i++)
+ if (op->resist[i])
+ buf.printf ("(%s %+d)", resist_plus[i], op->resist[i]);
+
+ return buf;
+}
/*
* Returns a pointer to a static buffer which contains a
@@ -1064,220 +971,193 @@
* a dwarven axe, in which the full abilities are only known to
* dwarves, etc.
*
- * This function is really much more complicated than it should
- * be, because different objects have different meanings
- * for the same field (eg, wands use 'food' for charges). This
- * means these special cases need to be worked out.
- *
* Add 'owner' who is the person examining this object.
* owner can be null if no one is being associated with this
* item (eg, debug dump or the like)
*/
-
-char *
+const char *
describe_item (const object *op, object *owner)
{
- char buf[MAX_BUF];
- static char retbuf[VERY_BIG_BUF];
+ if (op->flag [FLAG_MONSTER] || op->type == PLAYER)
+ return describe_monster (op);
+
+ static dynbuf_text buf; buf.clear ();
int identified, i;
- retbuf[0] = '\0';
- if (QUERY_FLAG (op, FLAG_MONSTER) || op->type == PLAYER)
- {
- return describe_monster (op);
- }
/* figure this out once, instead of making multiple calls to need_identify.
* also makes the code easier to read.
*/
- if (!need_identify (op) || QUERY_FLAG (op, FLAG_IDENTIFIED))
- identified = 1;
- else
- {
- strcpy (retbuf, "(unidentified)");
- identified = 0;
- }
+ identified = !op->need_identify () || op->flag [FLAG_IDENTIFIED];
+ if (!identified)
+ buf << "(unidentified)";
+
switch (op->type)
{
- case BOW:
- case ARROW:
- case WAND:
- case ROD:
- case HORN:
- case WEAPON:
- case ARMOUR:
- case HELMET:
- case SHIELD:
- case BOOTS:
- case GLOVES:
- case GIRDLE:
- case BRACERS:
- case CLOAK:
- case SKILL_TOOL:
- break; /* We have more information to do below this switch */
-
- case POWER_CRYSTAL:
- if (op->stats.maxsp > 1000)
- { /*higher capacity crystals */
- i = (op->stats.maxsp % 100) / 10;
- if (i)
- snprintf (buf, MAX_BUF, "(capacity %d.%dk). It is ", op->stats.maxsp / 100, i);
- else
- snprintf (buf, MAX_BUF, "(capacity %dk). It is ", op->stats.maxsp / 100);
- }
- else
- snprintf (buf, MAX_BUF, "(capacity %d). It is ", op->stats.maxsp);
- strcat (retbuf, buf);
- i = (op->stats.sp * 10) / op->stats.maxsp;
- if (op->stats.sp == 0)
- strcat (retbuf, "empty.");
- else if (i == 0)
- strcat (retbuf, "almost empty.");
- else if (i < 3)
- strcat (retbuf, "partially filled.");
- else if (i < 6)
- strcat (retbuf, "half full.");
- else if (i < 9)
- strcat (retbuf, "well charged.");
- else if (op->stats.sp == op->stats.maxsp)
- strcat (retbuf, "fully charged.");
- else
- strcat (retbuf, "almost full.");
- break;
- case FOOD:
- case FLESH:
- case DRINK:
- if (identified || QUERY_FLAG (op, FLAG_BEEN_APPLIED))
- {
- sprintf (buf, "(food+%d)", op->stats.food);
- strcat (retbuf, buf);
-
- if (op->type == FLESH && op->last_eat > 0 && atnr_is_dragon_enabled (op->last_eat))
- {
- sprintf (buf, "(%s metabolism)", change_resist_msg[op->last_eat]);
- strcat (retbuf, buf);
- }
-
- if (!QUERY_FLAG (op, FLAG_CURSED))
- {
- if (op->stats.hp)
- strcat (retbuf, "(heals)");
- if (op->stats.sp)
- strcat (retbuf, "(spellpoint regen)");
- }
- else
- {
- if (op->stats.hp)
- strcat (retbuf, "(damages)");
- if (op->stats.sp)
- strcat (retbuf, "(spellpoint depletion)");
- }
- }
- break;
+ case BOW:
+ case ARROW:
+ case WAND:
+ case ROD:
+ case HORN:
+ case WEAPON:
+ case ARMOUR:
+ case HELMET:
+ case SHIELD:
+ case BOOTS:
+ case GLOVES:
+ case GIRDLE:
+ case BRACERS:
+ case CLOAK:
+ case SKILL_TOOL:
+ break; /* We have more information to do below this switch */
+
+ case POWER_CRYSTAL:
+ if (op->stats.maxsp > 1000)
+ { /*higher capacity crystals */
+ i = (op->stats.maxsp % 1000) / 100;
+
+ if (i)
+ buf.printf ("(capacity %d.%dk; it is ", op->stats.maxsp / 1000, i);
+ else
+ buf.printf ("(capacity %dk; it is ", op->stats.maxsp / 1000);
+ }
+ else
+ buf.printf ("(capacity %d; it is ", op->stats.maxsp);
+ i = (op->stats.sp * 10) / op->stats.maxsp;
+ if (op->stats.sp == 0)
+ buf << "empty";
+ else if (i == 0)
+ buf << "almost empty";
+ else if (i < 3)
+ buf << "partially filled";
+ else if (i < 6)
+ buf << "half full";
+ else if (i < 9)
+ buf << "well charged";
+ else if (op->stats.sp == op->stats.maxsp)
+ buf << "fully charged";
+ else
+ buf << "almost full";
+
+ buf << ')';
+ break;
+
+ case LAMP:
+ {
+ int percent = ((double) 100 / op->arch->stats.food) * op->stats.food;
+ buf << "(fuel: ";
+ if (percent == 0)
+ buf << "empty";
+ else if (percent < 10)
+ buf << "very low";
+ else if (percent < 25)
+ buf << "low";
+ else if (percent < 50)
+ buf << "half empty";
+ else if (percent < 75)
+ buf << "half full";
+ else if (percent < 95)
+ buf << "well filled";
+ else if (percent <= 100)
+ buf << "full";
+ buf << ")";
+ }
+ break;
+
+ case FOOD:
+ case FLESH:
+ case DRINK:
+ if (identified || op->flag [FLAG_BEEN_APPLIED])
+ {
+ buf.printf ("(food+%d)", op->stats.food);
- case SKILL:
- case RING:
- case AMULET:
- if (op->item_power)
- {
- sprintf (buf, "(item_power %+d)", op->item_power);
- strcat (retbuf, buf);
- }
- if (op->title)
- strcat (retbuf, ring_desc (op));
- return retbuf;
+ if (op->type == FLESH && op->last_eat > 0 && atnr_is_dragon_enabled (op->last_eat))
+ buf.printf ("(%s metabolism)", change_resist_msg[op->last_eat]);
- default:
- return retbuf;
+ if (!op->flag [FLAG_CURSED])
+ {
+ if (op->stats.hp) buf << "(heals)";
+ if (op->stats.sp) buf << "(spellpoint regen)";
+ }
+ else
+ {
+ if (op->stats.hp) buf << "(damages)";
+ if (op->stats.sp) buf << "(spellpoint depletion)";
+ }
+ }
+ break;
+
+ case SKILL:
+ case RING:
+ case AMULET:
+ if (op->item_power)
+ buf.printf ("(item_power %+d)", op->item_power);
+
+ if (op->title)
+ buf << ring_desc (op);
+
+ return buf;
+
+ default:
+ return buf;
}
/* Down here, we more further describe equipment type items.
* only describe them if they have been identified or the like.
*/
- if (identified || QUERY_FLAG (op, FLAG_BEEN_APPLIED))
+ if (identified || op->flag [FLAG_BEEN_APPLIED])
{
int attr, val;
for (attr = 0; attr < NUM_STATS; attr++)
- {
- if ((val = get_attr_value (&(op->stats), attr)) != 0)
- {
- sprintf (buf, "(%s%+d)", short_stat_name[attr], val);
- strcat (retbuf, buf);
- }
- }
+ if ((val = op->stats.stat (attr)))
+ buf.printf ("(%s%+d)", short_stat_name[attr], val);
if (op->stats.exp)
- {
- sprintf (buf, "(speed %+lld)", (long long) op->stats.exp);
- strcat (retbuf, buf);
- }
-
+ buf.printf ("(speed %+lld)", (long long) op->stats.exp);
switch (op->type)
{
- case BOW:
- case ARROW:
- case GIRDLE:
- case HELMET:
- case SHIELD:
- case BOOTS:
- case GLOVES:
- case WEAPON:
- case SKILL:
- case RING:
- case AMULET:
- case ARMOUR:
- case BRACERS:
- case FORCE:
- case CLOAK:
- if (op->stats.wc)
- {
- sprintf (buf, "(wc%+d)", op->stats.wc);
- strcat (retbuf, buf);
- }
- if (op->stats.dam)
- {
- sprintf (buf, "(dam%+d)", op->stats.dam);
- strcat (retbuf, buf);
- }
- if (op->stats.ac)
- {
- sprintf (buf, "(ac%+d)", op->stats.ac);
- strcat (retbuf, buf);
- }
- if ((op->type == WEAPON || op->type == BOW) && op->level > 0)
- {
- sprintf (buf, "(improved %d/%d)", op->last_eat, op->level);
- strcat (retbuf, buf);
- }
- break;
+ case BOW:
+ case ARROW:
+ case GIRDLE:
+ case HELMET:
+ case SHIELD:
+ case BOOTS:
+ case GLOVES:
+ case WEAPON:
+ case SKILL:
+ case RING:
+ case AMULET:
+ case ARMOUR:
+ case BRACERS:
+ case FORCE:
+ case CLOAK:
+ if (op->stats.wc) buf.printf ("(wc%+d)", op->stats.wc);
+ if (op->stats.dam) buf.printf ("(dam%+d)", op->stats.dam);
+ if (op->stats.ac) buf.printf ("(ac%+d)", op->stats.ac);
+
+ if ((op->type == WEAPON || op->type == BOW) && op->level > 0)
+ buf.printf ("(improved %d/%d)", op->last_eat, op->level);
- default:
- break;
- }
- if (QUERY_FLAG (op, FLAG_XRAYS))
- strcat (retbuf, "(xray-vision)");
- if (QUERY_FLAG (op, FLAG_SEE_IN_DARK))
- strcat (retbuf, "(infravision)");
+ break;
- /* levitate was what is was before, so we'll keep it */
- if (op->move_type & MOVE_FLY_LOW)
- strcat (retbuf, "(levitate)");
+ default:
+ break;
+ }
- if (op->move_type & MOVE_FLY_HIGH)
- strcat (retbuf, "(fly)");
+ if (op->flag [FLAG_XRAYS]) buf << "(xray-vision)";
+ if (op->flag [FLAG_SEE_IN_DARK]) buf << "(infravision)";
- if (op->move_type & MOVE_SWIM)
- strcat (retbuf, "(swim)");
+ /* levitate was what is was before, so we'll keep it */
+ if (op->move_type & MOVE_FLY_LOW) buf << "(levitate)";
+ if (op->move_type & MOVE_FLY_HIGH) buf << "(fly)";
+ if (op->move_type & MOVE_SWIM) buf << "(swim)";
/* walking is presumed as 'normal', so doesn't need mentioning */
if (op->item_power)
- {
- sprintf (buf, "(item_power %+d)", op->item_power);
- strcat (retbuf, buf);
- }
+ buf.printf ("(item_power %+d)", op->item_power);
} /* End if identified or applied */
/* This blocks only deals with fully identified object.
@@ -1290,108 +1170,287 @@
switch (op->type)
{
- case ROD: /* These use stats.sp for spell selection and stats.food */
- case HORN: /* and stats.hp for spell-point regeneration... */
- case BOW:
- case ARROW:
- case WAND:
- case FOOD:
- case FLESH:
- case DRINK:
- more_info = 0;
- break;
-
- /* Armor type objects */
- case ARMOUR:
- case HELMET:
- case SHIELD:
- case BOOTS:
- case GLOVES:
- case GIRDLE:
- case BRACERS:
- case CLOAK:
- if (ARMOUR_SPEED (op))
- {
- sprintf (buf, "(Max speed %1.2f)", ARMOUR_SPEED (op) / 10.0);
- strcat (retbuf, buf);
- }
- if (ARMOUR_SPELLS (op))
- {
- sprintf (buf, "(Spell regen penalty %d)", ARMOUR_SPELLS (op));
- strcat (retbuf, buf);
- }
- more_info = 1;
- break;
-
- case WEAPON:
- /* Calculate it the same way fix_player does so the results
- * make sense.
- */
- i = (WEAPON_SPEED (op) * 2 - op->magic) / 2;
- if (i < 0)
- i = 0;
-
- sprintf (buf, "(weapon speed %d)", i);
- strcat (retbuf, buf);
- more_info = 1;
- break;
-
+ case ROD: /* These use stats.sp for spell selection and stats.food */
+ case HORN: /* and stats.hp for spell-point regeneration... */
+ case BOW:
+ case ARROW:
+ case WAND:
+ case FOOD:
+ case FLESH:
+ case DRINK:
+ more_info = 0;
+ break;
+
+ /* Armor type objects */
+ case ARMOUR:
+ case HELMET:
+ case SHIELD:
+ case BOOTS:
+ case GLOVES:
+ case GIRDLE:
+ case BRACERS:
+ case CLOAK:
+ if (ARMOUR_SPEED (op)) buf.printf ("(Max speed %1.2f)", ARMOUR_SPEED (op) / 10.0);
+ if (ARMOUR_SPELLS (op)) buf.printf ("(Spell regen penalty %d)", ARMOUR_SPELLS (op));
+ more_info = 1;
+ break;
+
+ case WEAPON:
+ /* Calculate it the same way fix_player does so the results
+ * make sense.
+ */
+ i = (WEAPON_SPEED (op) * 2 - op->magic) / 2;
+ if (i < 0)
+ i = 0;
+
+ buf.printf ("(weapon speed %d)", i);
+ more_info = 1;
+ break;
}
+
if (more_info)
{
- if (op->stats.food)
- {
- if (op->stats.food != 0)
- sprintf (buf, "(sustenance%+d)", op->stats.food);
- strcat (retbuf, buf);
- }
- if (op->stats.grace)
- {
- sprintf (buf, "(grace%+d)", op->stats.grace);
- strcat (retbuf, buf);
- }
- if (op->stats.sp)
- {
- sprintf (buf, "(magic%+d)", op->stats.sp);
- strcat (retbuf, buf);
- }
- if (op->stats.hp)
- {
- sprintf (buf, "(regeneration%+d)", op->stats.hp);
- strcat (retbuf, buf);
- }
+ if (op->stats.food) buf.printf ("(sustenance%+d)", op->stats.food);
+ if (op->stats.grace) buf.printf ("(grace%+d)", op->stats.grace);
+ if (op->stats.sp) buf.printf ("(magic%+d)", op->stats.sp);
+ if (op->stats.hp) buf.printf ("(regeneration%+d)", op->stats.hp);
}
if (op->stats.luck)
+ buf.printf ("(luck%+d)", op->stats.luck);
+
+ if (op->flag [FLAG_LIFESAVE]) buf << "(lifesaving)";
+ if (op->flag [FLAG_REFL_SPELL]) buf << "(reflect spells)";
+ if (op->flag [FLAG_REFL_MISSILE]) buf << "(reflect missiles)";
+ if (op->flag [FLAG_STEALTH]) buf << "(stealth)";
+
+ if (op->slaying && op->type != FOOD)
+ buf.printf ("(slay %s)", &op->slaying);
+
+ if (op->type == SKILL_TOOL && op->skill)
+ buf.printf ("(%s)", &op->skill);
+
+ buf.add_abilities ("Attacks", op->attacktype);
+ /* resistance on flesh is only visible for quetzals. If
+ * non flesh, everyone can see its resistances
+ */
+ if (op->type != FLESH || (owner && owner->is_dragon ()))
+ buf << describe_resistance (op, 0);
+
+ buf.add_paths ("Attuned", op->path_attuned);
+ buf.add_paths ("Repelled", op->path_repelled);
+ buf.add_paths ("Denied", op->path_denied);
+ }
+
+ return buf;
+}
+
+std::string
+object::describe_item (object *who)
+{
+ return std::string (::describe_item (this, who));
+}
+
+static void
+describe_dump_object (dynbuf &buf, object *ob)
+{
+ char *txt = dump_object (ob);
+ for (char *p = txt; *p; ++p) if (*p == '\n') *p = '\r';
+ buf << "\n" << txt << "\n";
+
+ if (!ob->is_arch ())
+ describe_dump_object (buf, ob->arch);
+}
+
+std::string
+object::describe (object *who)
+{
+ dynbuf_text buf (1024, 1024);
+
+ buf.printf ("That is: %s.\r", long_desc (who).c_str ());
+
+ if (custom_name)
+ buf.printf ("You call it %s.\r", &custom_name);
+
+ switch (type)
+ {
+ case SPELLBOOK:
+ if (flag [FLAG_IDENTIFIED] && inv)
+ buf.printf ("%s is a %s level %s spell.\r", &inv->name, ordinal (inv->level), &inv->skill);
+ break;
+
+ case BOOK:
+ if (msg)
+ buf << "Something is written in it.\r";
+ break;
+
+ case CONTAINER:
+ if (race)
+ {
+ if (weight_limit && stats.Str < 100)
+ buf.printf ("It can hold only %s and its weight limit is %.1f kg.\r",
+ &race, weight_limit / (10.0 * (100 - stats.Str)));
+ else
+ buf.printf ("It can hold only %s.\r", &race);
+ }
+ else if (weight_limit && stats.Str < 100)
+ buf.printf ("Its weight limit is %.1f kg.\r", weight_limit / (10.0 * (100 - stats.Str)));
+ break;
+
+ case WAND:
+ if (flag [FLAG_IDENTIFIED])
+ buf.printf ("It has %d %s left.\r", stats.food, stats.food == 1 ? "charge" : "charges");
+ break;
+ }
+
+ if (material != MATERIAL_NULL && !msg)
+ buf << (nrof > 1 ? "They are made of " : "It is made of ")
+ << material->description
+ << ".\r";
+
+ if (who)
+ /* Where to wear this item */
+ for (int i = 0; i < NUM_BODY_LOCATIONS; i++)
+ if (slot[i].info)
{
- sprintf (buf, "(luck%+d)", op->stats.luck);
- strcat (retbuf, buf);
+ buf << (who->slot[i].info ? body_locations[i].use_name : body_locations[i].nonuse_name);
+
+ if (slot[i].info < -1 && who->slot[i].info)
+ buf.printf ("(%d)", -slot[i].info);
+
+ buf << ".\r";
}
- if (QUERY_FLAG (op, FLAG_LIFESAVE))
- strcat (retbuf, "(lifesaving)");
- if (QUERY_FLAG (op, FLAG_REFL_SPELL))
- strcat (retbuf, "(reflect spells)");
- if (QUERY_FLAG (op, FLAG_REFL_MISSILE))
- strcat (retbuf, "(reflect missiles)");
- if (QUERY_FLAG (op, FLAG_STEALTH))
- strcat (retbuf, "(stealth)");
- if (op->slaying != NULL && op->type != FOOD)
+
+ if (weight)
+ buf.printf ("%s %3.3f kg.\r", nrof > 1 ? "They weigh" : "It weighs", weight * (nrof ? nrof : 1) / 1000.0);
+
+ if (flag [FLAG_STARTEQUIP])
+ buf << (nrof > 1 ? "They were" : "It was")
+ << " given by a god and will vanish when dropped.\r";
+
+ if (value && !flag [FLAG_STARTEQUIP] && !flag [FLAG_NO_PICK] && who)
+ {
+ buf.printf ("You reckon %s worth %s.\r", nrof > 1 ? "they are" : "it is", query_cost_string (this, who, F_TRUE | F_APPROX));
+
+ if (who->is_in_shop ())
{
- sprintf (buf, "(slay %s)", &op->slaying);
- strcat (retbuf, buf);
+ if (flag [FLAG_UNPAID])
+ buf.printf ("%s would cost you %s.\r", nrof > 1 ? "They" : "It", query_cost_string (this, who, F_BUY | F_SHOP));
+ else
+ buf.printf ("You are offered %s for %s.\r", query_cost_string (this, who, F_SELL + F_SHOP), nrof > 1 ? "them" : "it");
}
- DESCRIBE_ABILITY (retbuf, op->attacktype, "Attacks");
- /* resistance on flesh is only visible for quetzals. If
- * non flesh, everyone can see its resistances
- */
- if (op->type != FLESH || (owner && is_dragon_pl (owner)))
- strcat (retbuf, describe_resistance (op, 0));
- DESCRIBE_PATH (retbuf, op->path_attuned, "Attuned");
- DESCRIBE_PATH (retbuf, op->path_repelled, "Repelled");
- DESCRIBE_PATH (retbuf, op->path_denied, "Denied");
}
- return retbuf;
+ if (flag [FLAG_MONSTER])
+ buf << describe_monster (who);
+
+ /* Is this item buildable? */
+ if (flag [FLAG_IS_BUILDABLE])
+ buf << "This is a buildable item.\r";
+
+ /* Does the object have a message? Don't show message for all object
+ * types - especially if the first entry is a match
+ */
+ if (msg)
+ {
+ if (type != EXIT && type != BOOK && type != CORPSE && !move_on && !has_dialogue ())
+ {
+ if (!need_identify ())
+ buf << '\r' << msg << '\n';
+ else if (flag [FLAG_IDENTIFIED])
+ buf << '\r' << "The object has a story:\r" << msg;
+ }
+ }
+ else if (inv
+ && inv->msg
+ && inv->type == SPELL
+ && flag [FLAG_IDENTIFIED]
+ && (type == SPELLBOOK || type == ROD || type == WAND
+ || type == ROD || type == POTION || type == SCROLL))
+ // for spellbooks and other stuff that contains spells, print the spell message,
+ // unless the object has a custom message handled above.
+ buf << '\r' << inv->msg << '\n';
+
+ // try to display the duration for some potions and scrolls
+ // this includes change ability potions and group spells,
+ // but does not handle protection potions
+ if (inv && inv->type == SPELL && flag [FLAG_IDENTIFIED]
+ && (type == POTION || type == SCROLL))
+ {
+ object *spell = inv;
+
+ if (spell->subtype == SP_PARTY_SPELL)
+ spell = spell->other_arch;
+
+ if (spell->subtype == SP_CHANGE_ABILITY)
+ buf.printf ("\nH",
+ TICK2TIME (change_ability_duration (spell, this)));
+ }
+
+ // some help text for skill tools
+ if (type == SKILL_TOOL)
+ buf << "\nH";
+
+ // Display a hint about inscribable items [empty books]
+ // This includes the amount of text they can hold.
+ if (type == INSCRIBABLE)
+ {
+ if (other_arch && other_arch->type == SCROLL)
+ buf.printf ("\nH");
+ else
+ buf.printf ("\nH",
+ weight_limit);
+ }
+
+ buf << '\n';
+
+ // the dungeon master additionally gets a complete dump
+ if (who && who->flag [FLAG_WIZLOOK])
+ {
+ buf << "\nT