--- deliantra/server/common/item.C 2007/07/01 05:00:17 1.38
+++ deliantra/server/common/item.C 2008/04/13 20:21:50 1.43
@@ -1,11 +1,11 @@
/*
- * This file is part of Crossfire TRT, the Roguelike Realtime MORPG.
+ * This file is part of Deliantra, the Roguelike Realtime MMORPG.
*
- * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team
+ * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
* Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
* Copyright (©) 1992,2007 Frank Tore Johansen
*
- * Crossfire TRT is free software: you can redistribute it and/or modify
+ * Deliantra 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 3 of the License, or
* (at your option) any later version.
@@ -18,7 +18,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
- * The authors can be reached via e-mail to
+ * The authors can be reached via e-mail to
*/
#include
@@ -26,6 +26,8 @@
#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
@@ -493,64 +495,40 @@
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 (QUERY_FLAG (op, FLAG_IDENTIFIED))
{
- if ((val = op->stats.stat (attr)))
- 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 %+lld)", (long long)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 (QUERY_FLAG (op, FLAG_LIFESAVE)) buf << "(lifesaving)";
+ if (QUERY_FLAG (op, FLAG_REFL_SPELL)) buf << "(reflect spells)";
+ if (QUERY_FLAG (op, FLAG_REFL_MISSILE)) buf << "(reflect missiles)";
+ if (QUERY_FLAG (op, 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;
}
@@ -562,73 +540,82 @@
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 == 0)
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 ();
+
+ buf << (op->nrof <= 1 ? op->name : op->name_pl);
if (op->title && QUERY_FLAG (op, FLAG_IDENTIFIED))
- {
- safe_strcat (buf, " ", &len, HUGE_BUF);
- safe_strcat (buf, op->title, &len, HUGE_BUF);
- }
+ 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 (QUERY_FLAG (op, FLAG_IDENTIFIED) || QUERY_FLAG (op, 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 (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)
{
- /* If ring has a title, full description isn't so useful */
- const char *s = ring_desc (op);
+ 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;
- if (s[0])
- {
- safe_strcat (buf, " ", &len, HUGE_BUF);
- safe_strcat (buf, s, &len, HUGE_BUF);
- }
+ buf.printf ("drop %d %s", coins, coins == 1 ? &coin->name : &coin->name_pl);
+
+ if (wrap) 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);
- }
+
+ 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 && ((QUERY_FLAG (op, FLAG_BEEN_APPLIED) && need_identify (op)) || QUERY_FLAG (op, FLAG_IDENTIFIED)))
+ buf.printf (" %+d", op->magic);
}
+
return buf;
}
@@ -646,42 +633,33 @@
const char *
query_name (const object *op)
{
- static char buf[5][HUGE_BUF]; // OMFG
- 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
+ dynbuf_text &buf = bufs [use_buf];
+ buf.clear ();
+
if ((op->is_armor () || op->is_weapon ()) && 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);
- }
- }
-#endif
+ if (materialtype_t *mt = name_to_material (op->materialname))
+ buf << mt->description << ' ';
- 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);
+ 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);
+ buf << " (open)";
if (QUERY_FLAG (op, FLAG_KNOWN_CURSED))
{
if (QUERY_FLAG (op, FLAG_DAMNED))
- safe_strcat (buf[use_buf], " (damned)", &len, HUGE_BUF);
+ buf << " (damned)";
else if (QUERY_FLAG (op, FLAG_CURSED))
- safe_strcat (buf[use_buf], " (cursed)", &len, HUGE_BUF);
+ buf << " (cursed)";
}
/* Basically, if the object is known magical (detect magic spell on it),
@@ -694,7 +672,7 @@
* 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);
+ buf << " (magic)";
#if 0
/* item_power will be returned in desribe_item - it shouldn't really
@@ -713,10 +691,10 @@
case WAND:
case ROD:
case HORN:
- safe_strcat (buf[use_buf], op->env && op->env->current_weapon == op ? " (readied)" : " (applied)", &len, HUGE_BUF);
+ buf << (op->env && op->env->current_weapon == op ? " (readied)" : " (applied)");
break;
case WEAPON:
- safe_strcat (buf[use_buf], op->env && op->env->current_weapon == op ? " (wielded)" : " (applied)", &len, HUGE_BUF);
+ buf << (op->env && op->env->current_weapon == op ? " (wielded)" : " (applied)");
break;
case ARMOUR:
case HELMET:
@@ -728,21 +706,21 @@
case GIRDLE:
case BRACERS:
case CLOAK:
- safe_strcat (buf[use_buf], " (worn)", &len, HUGE_BUF);
+ buf << " (worn)";
break;
case CONTAINER:
- safe_strcat (buf[use_buf], " (active)", &len, HUGE_BUF);
+ buf << " (active)";
break;
case SKILL:
default:
- safe_strcat (buf[use_buf], " (applied)", &len, HUGE_BUF);
+ buf << " (applied)";
}
}
if (QUERY_FLAG (op, FLAG_UNPAID))
- safe_strcat (buf[use_buf], " (unpaid)", &len, HUGE_BUF);
+ buf << " (unpaid)";
- return buf [use_buf];
+ return buf;
}
/*
@@ -757,49 +735,23 @@
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))
return op->name; /* To speed things up (or make things slower?) */
- if ((op->is_armor () || op->is_weapon ()) && op->materialname)
- mt = name_to_material (op->materialname);
+ static dynbuf_text buf; buf.clear ();
-#ifdef NEW_MATERIAL_CODE
- if ((op->is_armor () || op->is_weapon ()) && op->materialname && mt &&
- op->arch->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)
- assign (buf, op->name);
- else
- assign (buf, op->name_pl);
+ if ((op->is_armor () || op->is_weapon ()) && op->materialname)
+ if (materialtype_t *mt = name_to_material (op->materialname))
+ if (op->arch->materialname != mt->name)
+ buf << mt->description << ' ';
- len = strlen (buf);
-#ifdef NEW_MATERIAL_CODE
- }
-#endif
+ buf << (plural ? op->name_pl : op->name);
if (op->title && QUERY_FLAG (op, FLAG_IDENTIFIED))
- {
- safe_strcat (buf, " ", &len, MAX_BUF);
- safe_strcat (buf, op->title, &len, MAX_BUF);
- }
+ buf << ' ' << op->title;
switch (op->type)
{
@@ -810,18 +762,10 @@
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);
- }
+ buf << " of " << (op->inv ? &op->inv->name : "bug, please report");
+
if (op->type != SPELLBOOK)
- {
- sprintf (buf2, " (lvl %d)", op->level);
- safe_strcat (buf, buf2, &len, MAX_BUF);
- }
+ buf.printf (" (lvl %d)", op->level);
}
break;
@@ -834,17 +778,14 @@
/* If ring has a title, full description isn't so useful */
const char *s = ring_desc (op);
- if (s[0])
- {
- safe_strcat (buf, " ", &len, MAX_BUF);
- safe_strcat (buf, s, &len, MAX_BUF);
- }
+ if (s && *s)
+ buf << ' ' << s;
}
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);
+ buf.printf (" %+d", op->magic);
}
return buf;
@@ -856,125 +797,93 @@
* 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 (op->has_active_speed ())
+ switch ((int) ((FABS (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 (QUERY_FLAG (op, FLAG_UNDEAD)) buf << "(undead)";
+ if (QUERY_FLAG (op, FLAG_SEE_INVISIBLE)) buf << "(see invisible)";
+ if (QUERY_FLAG (op, FLAG_USE_WEAPON)) buf << "(wield weapon)";
+ if (QUERY_FLAG (op, FLAG_USE_BOW)) buf << "(archer)";
+ if (QUERY_FLAG (op, FLAG_USE_ARMOUR)) buf << "(wear armour)";
+ if (QUERY_FLAG (op, FLAG_USE_RING)) buf << "(wear ring)";
+ if (QUERY_FLAG (op, FLAG_USE_SCROLL)) buf << "(read scroll)";
+ if (QUERY_FLAG (op, FLAG_USE_RANGE)) buf << "(fires wand/rod/horn)";
+ if (QUERY_FLAG (op, FLAG_CAN_USE_SKILL)) buf << "(skill user)";
+ if (QUERY_FLAG (op, FLAG_CAST_SPELL)) buf << "(spellcaster)";
+ if (QUERY_FLAG (op, FLAG_FRIENDLY)) buf << "(friendly)";
+ if (QUERY_FLAG (op, FLAG_UNAGGRESSIVE)) buf << "(unaggressive)";
+ if (QUERY_FLAG (op, FLAG_HITBACK)) buf << "(hitback)";
+ if (QUERY_FLAG (op, FLAG_STEALTH)) buf << "(stealthy)";
+
+ if (op->randomitems)
{
- 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)
- {
- treasure *t;
- int first = 1;
+ bool first = 1;
- for (t = op->randomitems->items; t != NULL; t = t->next)
+ 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->object::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 */
@@ -986,33 +895,29 @@
*/
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") }
+ buf.add_abilities ("Attacks", op->attacktype);
- DESCRIBE_PATH (retbuf, op->path_attuned, "Attuned");
- DESCRIBE_PATH (retbuf, op->path_repelled, "Repelled");
- DESCRIBE_PATH (retbuf, op->path_denied, "Denied");
+ buf.add_paths ("Attuned" , op->path_attuned);
+ buf.add_paths ("Repelled", op->path_repelled);
+ buf.add_paths ("Denied" , op->path_denied);
- for (i = 0; i < NROFATTACKS; i++)
+ for (int i = 0; i < NROFATTACKS; i++)
if (op->resist[i])
- {
- sprintf (buf, "(%s %+d)", resist_plus[i], op->resist[i]);
- strcat (retbuf, buf);
- }
+ buf.printf ("(%s %+d)", resist_plus[i], op->resist[i]);
- return retbuf;
+ return buf;
}
-
/*
* Returns a pointer to a static buffer which contains a
* description of the given object.
@@ -1042,120 +947,104 @@
const char *
describe_item (const object *op, object *owner)
{
- char buf[MAX_BUF];
- static char retbuf[VERY_BIG_BUF];
+ if (QUERY_FLAG (op, 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 = !need_identify (op) || QUERY_FLAG (op, 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 % 1000) / 100;
-
- if (i)
- snprintf (buf, MAX_BUF, "(capacity %d.%dk). It is ", op->stats.maxsp / 1000, i);
- else
- snprintf (buf, MAX_BUF, "(capacity %dk). It is ", op->stats.maxsp / 1000);
- }
- else
- snprintf (buf, MAX_BUF, "(capacity %d). It is ", op->stats.maxsp);
+ 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);
- 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);
+ 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.";
+ break;
- 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 FOOD:
+ case FLESH:
+ case DRINK:
+ if (identified || QUERY_FLAG (op, FLAG_BEEN_APPLIED))
+ {
+ buf.printf ("(food+%d)", op->stats.food);
+ 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]);
- 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 (!QUERY_FLAG (op, 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;
- default:
- return retbuf;
+ 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.
@@ -1166,85 +1055,54 @@
int attr, val;
for (attr = 0; attr < NUM_STATS; attr++)
- {
- if ((val = op->stats.stat (attr)))
- {
- 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);
- default:
- break;
- }
- if (QUERY_FLAG (op, FLAG_XRAYS))
- strcat (retbuf, "(xray-vision)");
- if (QUERY_FLAG (op, FLAG_SEE_IN_DARK))
- strcat (retbuf, "(infravision)");
+ if ((op->type == WEAPON || op->type == BOW) && op->level > 0)
+ buf.printf ("(improved %d/%d)", op->last_eat, op->level);
- /* levitate was what is was before, so we'll keep it */
- if (op->move_type & MOVE_FLY_LOW)
- strcat (retbuf, "(levitate)");
+ break;
+
+ default:
+ break;
+ }
- if (op->move_type & MOVE_FLY_HIGH)
- strcat (retbuf, "(fly)");
+ if (QUERY_FLAG (op, FLAG_XRAYS)) buf << "(xray-vision)";
+ if (QUERY_FLAG (op, 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.
@@ -1257,108 +1115,76 @@
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)
- {
- sprintf (buf, "(luck%+d)", op->stats.luck);
- strcat (retbuf, buf);
- }
- 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)
- {
- sprintf (buf, "(slay %s)", &op->slaying);
- strcat (retbuf, buf);
- }
- DESCRIBE_ABILITY (retbuf, op->attacktype, "Attacks");
+ buf.printf ("(luck%+d)", op->stats.luck);
+
+ if (QUERY_FLAG (op, FLAG_LIFESAVE)) buf << "(lifesaving)";
+ if (QUERY_FLAG (op, FLAG_REFL_SPELL)) buf << "(reflect spells)";
+ if (QUERY_FLAG (op, FLAG_REFL_MISSILE)) buf << "(reflect missiles)";
+ if (QUERY_FLAG (op, FLAG_STEALTH)) buf << "(stealth)";
+
+ if (op->slaying && op->type != FOOD)
+ buf.printf ("(slay %s)", &op->slaying);
+
+ 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 && 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");
+ 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 retbuf;
+ return buf;
}
std::string
@@ -1367,13 +1193,44 @@
return std::string (::describe_item (this, who));
}
+void
+examine (object *op, object *tmp)
+{
+ std::string s = tmp->describe (op);
+
+ new_draw_info (NDI_UNIQUE, 0, op, s.c_str ());
+}
+
+/*
+ * inventory prints object's inventory. If inv==NULL then print player's
+ * inventory.
+ * [ Only items which are applied are showed. Tero.Haatanen@lut.fi ]
+ */
+const char *
+object::query_inventory (object *who, const char *indent)
+{
+ static dynbuf_text buf; buf.clear ();
+
+ for (object *tmp = inv; tmp; tmp = tmp->below)
+ if (who && QUERY_FLAG (who, FLAG_WIZ))
+ buf.printf ("%s- %-28.28s (%5d) %-8s\n", indent, query_name (tmp), tmp->count, query_weight (tmp));
+ else if (!tmp->invisible && (type == CONTAINER || QUERY_FLAG (tmp, FLAG_APPLIED)))
+ buf.printf ("%s- %-36.36s %-8s\n", indent, query_name (tmp), query_weight (tmp));
+
+ if (buf.size ())
+ buf.printf ("%s(total weight: %s)\n", indent, query_weight (this));
+ else
+ buf.printf ("%s(empty)\n", indent);
+
+ return buf;
+}
+
/* Return true if the item is magical. A magical item is one that
* increases/decreases any abilities, provides a resistance,
* has a generic magical bonus, or is an artifact.
* This function is used by detect_magic to determine if an item
* should be marked as magical.
*/
-
int
is_magical (const object *op)
{