--- deliantra/server/common/item.C 2010/04/21 05:40:21 1.85 +++ deliantra/server/common/item.C 2012/10/29 23:55:52 1.96 @@ -1,24 +1,24 @@ /* * 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 (©) 2005,2006,2007,2008,2009,2010,2011,2012 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 +51,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] = { @@ -160,6 +148,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}, @@ -204,7 +193,7 @@ {ITEM_TRANSFORMER, "item_transformer", "item_transformers", 0, 0}, }; -static const int item_types_size = sizeof (item_types) / sizeof (*item_types); +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 @@ -217,10 +206,10 @@ */ 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, 1, 2, 3, 4, // 5 + 5, 7, 9, 11, 13, // 10 + 15, 18, 21, 24, 27, // 15 + 30, 35, 40, 45, 50 // 20 }; int @@ -355,16 +344,28 @@ 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) { - 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 @@ -477,7 +478,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 +486,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); @@ -621,7 +622,6 @@ const char * query_name (const object *op) { - int len = 0; static dynbuf_text bufs[5]; static int use_buf = 0; @@ -676,12 +676,11 @@ { switch (op->type) { + case RANGED: case BOW: case WAND: case ROD: case HORN: - buf << " (applied)"; - break; case WEAPON: buf << " (applied)"; break; @@ -981,6 +980,7 @@ switch (op->type) { + case RANGED: case BOW: case ARROW: case WAND: @@ -1095,10 +1095,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 +1104,7 @@ switch (op->type) { + case RANGED: case BOW: case ARROW: case GIRDLE: @@ -1158,6 +1157,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: @@ -1354,7 +1354,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';