--- deliantra/server/common/item.C 2010/04/30 20:43:17 1.86
+++ deliantra/server/common/item.C 2018/11/17 23:40:00 1.100
@@ -1,24 +1,25 @@
/*
* 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 (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team
+ * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 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
*/
@@ -51,21 +52,9 @@
*/
// see include/object.h
Body_Locations body_locations[NUM_BODY_LOCATIONS] = {
- {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"} */
+# define def(name, use, nonuse) { # name, KW_body_ ## name, use, nonuse },
+# include "slotinc.h"
+# undef def
};
static char numbers_10[10][20] = {
@@ -88,8 +77,8 @@
/* The following is a large table of item types, the fields are:
* item number, item name, item name (plural), and two numbers that are the skills
* used to identify them. Anytime a new item type is added or removed, this list
- * should be altered to reflect that. The defines for the numerical values are in
- * define.h
+ * should be altered to reflect that. The defines for the numerical values are in
+ * define.h
*/
static const typedata item_types[] = {
{PLAYER, "player", "players", 0, 0},
@@ -160,6 +149,7 @@
{LIGHTER, "lighter", "lighters", 0, 0},
{BUILDABLE_WALL, "buildable wall", "buildable walls", 0, 0},
{MISC_OBJECT, "bric-a-brac", "bric-a-brac", 0, 0},
+ {TORCH, "torch", "torches", 0, 0},
{LAMP, "lamp", "lamps", 0, 0},
{DUPLICATOR, "duplicator", "duplicators", 0, 0},
{SPELLBOOK, "spellbook", "spellbooks", SK_LITERACY, 0},
@@ -293,7 +283,7 @@
/* This protection logic is pretty flawed. 20% fire resistance
* is much more valuable than 20% confusion, or 20% slow, or
* several others. Start at 1 - ignore physical - all that normal
- * armour shouldn't be counted against
+ * armour shouldn't be counted against
*/
tmp = 0;
for (i = 1; i < NROFATTACKS; i++)
@@ -355,19 +345,31 @@
return get_power_from_ench (enc);
}
-/* returns the typedata that has a number equal to itemtype, if there
+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)
{
- for (int 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
+/* 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 *
@@ -477,7 +479,7 @@
ring_desc (const object *op)
{
static dynbuf_text buf; buf.clear ();
- int attr, val, len;
+ int attr, val;
if (op->flag [FLAG_IDENTIFIED])
{
@@ -485,7 +487,7 @@
if ((val = op->stats.stat (attr)))
buf.printf ("(%s%+d)", short_stat_name[attr], val);
- if (op->stats.exp) buf.printf ("(speed %+lld)", (long long)op->stats.exp);
+ 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);
@@ -515,7 +517,7 @@
}
/*
- * query_short_name(object) is similar to query_name, but doesn't
+ * 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.
@@ -621,7 +623,6 @@
const char *
query_name (const object *op)
{
- int len = 0;
static dynbuf_text bufs[5];
static int use_buf = 0;
@@ -676,12 +677,11 @@
{
switch (op->type)
{
+ case RANGED:
case BOW:
case WAND:
case ROD:
case HORN:
- buf << " (applied)";
- break;
case WEAPON:
buf << " (applied)";
break;
@@ -981,6 +981,7 @@
switch (op->type)
{
+ case RANGED:
case BOW:
case ARROW:
case WAND:
@@ -1011,21 +1012,15 @@
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";
+ i = op->stats.sp * 10 / max (op->stats.maxsp, 1);
+
+ if (op->stats.sp == 0) buf << "empty";
+ else if (i <= 0) buf << "almost empty";
+ else if (i <= 2) buf << "partially filled";
+ else if (i <= 5) buf << "half full";
+ else if (i <= 8) buf << "well charged";
+ else if (op->stats.sp < op->stats.maxsp) buf << "almost full";
+ else buf << "fully charged";
buf << ')';
break;
@@ -1095,10 +1090,8 @@
*/
if (identified || op->flag [FLAG_BEEN_APPLIED])
{
- int attr, val;
-
- for (attr = 0; attr < NUM_STATS; attr++)
- if ((val = op->stats.stat (attr)))
+ for (int attr = 0; attr < NUM_STATS; attr++)
+ if (int val = op->stats.stat (attr))
buf.printf ("(%s%+d)", short_stat_name[attr], val);
if (op->stats.exp)
@@ -1106,6 +1099,7 @@
switch (op->type)
{
+ case RANGED:
case BOW:
case ARROW:
case GIRDLE:
@@ -1158,6 +1152,7 @@
switch (op->type)
{
+ case RANGED:
case ROD: /* These use stats.sp for spell selection and stats.food */
case HORN: /* and stats.hp for spell-point regeneration... */
case BOW:
@@ -1200,7 +1195,7 @@
{
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.sp) buf.printf ("(magic%+d)", op->stats.sp);
if (op->stats.hp) buf.printf ("(regeneration%+d)", op->stats.hp);
}
@@ -1354,7 +1349,7 @@
&& inv->type == SPELL
&& flag [FLAG_IDENTIFIED]
&& (type == SPELLBOOK || type == ROD || type == WAND
- || type == ROD || type == POTION || type == SCROLL))
+ || 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';
@@ -1419,7 +1414,7 @@
/*
* inventory prints object's inventory. If inv==NULL then print player's
- * inventory.
+ * inventory.
* [ Only items which are applied are showed. Tero.Haatanen@lut.fi ]
*/
const char *