--- deliantra/server/common/item.C 2010/04/15 02:51:39 1.84 +++ deliantra/server/common/item.C 2010/05/12 20:40:50 1.88 @@ -204,7 +204,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 @@ -216,10 +216,11 @@ * 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 @@ -354,16 +355,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 @@ -484,7 +497,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);