summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Changelog-Trunk.txt5
-rw-r--r--db/const.txt12
-rw-r--r--src/map/atcommand.c14
-rw-r--r--src/map/itemdb.c28
-rw-r--r--src/map/itemdb.h1
-rw-r--r--src/map/pc.c2
-rw-r--r--src/map/skill.c4
7 files changed, 54 insertions, 12 deletions
diff --git a/Changelog-Trunk.txt b/Changelog-Trunk.txt
index f648d7a97..5120a0c62 100644
--- a/Changelog-Trunk.txt
+++ b/Changelog-Trunk.txt
@@ -1,6 +1,11 @@
Date Added
2010/12/02
+ * Various code tweaks and updates related to item types. [Ai4rei]
+ - Replaced item type literals with their appropriate constants.
+ - Added itemdb_typename to replace the ugly "BUG!" filled array in @iteminfo (since r1741, follow up to r14550).
+ - Made the item database parser verify item type for validity.
+ - Added item type constants to const.txt for use in scripts (getiteminfo).
* Added support for IT_CASH to @iteminfo, logging filters and item drop rate adjustment. Added 'show_picker.item_type'-specific IT_CASH value to it's description (follow up to r14549). [Ai4rei]
* Rev. 14549 Added item type IT_CASH (item type 18) Requires user confirmation before using/generating item(s). [L0ne_W0lf]
* Fixed mapflags not getting initialized upon @reloadscript (bugreport:2247, since r1275). [Ai4rei]
diff --git a/db/const.txt b/db/const.txt
index 9e876661e..d5e222239 100644
--- a/db/const.txt
+++ b/db/const.txt
@@ -1853,3 +1853,15 @@ DIR_SOUTH 4
DIR_SOUTHEAST 5
DIR_EAST 6
DIR_NORTHEAST 7
+
+IT_HEALING 0
+IT_USABLE 2
+IT_ETC 3
+IT_WEAPON 4
+IT_ARMOR 5
+IT_CARD 6
+IT_PETEGG 7
+IT_PETARMOR 8
+IT_AMMO 10
+IT_DELAYCONSUME 11
+IT_CASH 18
diff --git a/src/map/atcommand.c b/src/map/atcommand.c
index 6cf5d1c4e..117d6dc0a 100644
--- a/src/map/atcommand.c
+++ b/src/map/atcommand.c
@@ -1663,15 +1663,15 @@ ACMD_FUNC(item2)
if (item_id > 500) {
loop = 1;
get_count = number;
- if (item_data->type == 4 || item_data->type == 5 ||
- item_data->type == 7 || item_data->type == 8) {
+ if (item_data->type == IT_WEAPON || item_data->type == IT_ARMOR ||
+ item_data->type == IT_PETEGG || item_data->type == IT_PETARMOR) {
loop = number;
get_count = 1;
- if (item_data->type == 7) {
+ if (item_data->type == IT_PETEGG) {
identify = 1;
refine = 0;
}
- if (item_data->type == 8)
+ if (item_data->type == IT_PETARMOR)
refine = 0;
if (refine > 10)
refine = 10;
@@ -7390,10 +7390,6 @@ ACMD_FUNC(homshuffle)
*------------------------------------------*/
ACMD_FUNC(iteminfo)
{
- char *itype[IT_MAX] = {"Potion/Food", "BUG!", "Usable", "Etc", "Weapon", "Protection", "Card", "Egg", "Pet Acessory", "BUG!", "Arrow",
- "BUG!", // No need, type 11 items are converted to type 2 upon loading [Skotlex]
- "BUG!", "BUG!", "BUG!", "BUG!", "BUG!", "BUG!", "Cash Usable"};
-
struct item_data *item_data, *item_array[MAX_SEARCH];
int i, count = 1;
@@ -7418,7 +7414,7 @@ ACMD_FUNC(iteminfo)
item_data = item_array[i];
sprintf(atcmd_output, "Item: '%s'/'%s'[%d] (%d) Type: %s | Extra Effect: %s",
item_data->name,item_data->jname,item_data->slot,item_data->nameid,
- item_data->type < IT_MAX ? itype[item_data->type] : "BUG!",
+ itemdb_typename(item_data->type),
(item_data->script==NULL)? "None" : "With script"
);
clif_displaymessage(fd, atcmd_output);
diff --git a/src/map/itemdb.c b/src/map/itemdb.c
index 8eb173a85..10341ff0f 100644
--- a/src/map/itemdb.c
+++ b/src/map/itemdb.c
@@ -180,6 +180,27 @@ struct item_data* itemdb_exists(int nameid)
return item;
}
+/// Returns human readable name for given item type.
+/// @param type Type id to retrieve name for ( IT_* ).
+const char* itemdb_typename(int type)
+{
+ switch(type)
+ {
+ case IT_HEALING: return "Potion/Food";
+ case IT_USABLE: return "Usable";
+ case IT_ETC: return "Etc.";
+ case IT_WEAPON: return "Weapon";
+ case IT_ARMOR: return "Armor";
+ case IT_CARD: return "Card";
+ case IT_PETEGG: return "Pet Egg";
+ case IT_PETARMOR: return "Pet Accessory";
+ case IT_AMMO: return "Arrow/Ammunition";
+ case IT_DELAYCONSUME: return "Delay-Consume Usable";
+ case IT_CASH: return "Cash Usable";
+ }
+ return "Unknown Type";
+}
+
/*==========================================
* Converts the jobid from the format in itemdb
* to the format used by the map server. [Skotlex]
@@ -748,6 +769,13 @@ static bool itemdb_parse_dbrow(char** str, const char* source, int line, int scr
safestrncpy(id->jname, str[2], sizeof(id->jname));
id->type = atoi(str[3]);
+
+ if( id->type < 0 || id->type == IT_UNKNOWN || id->type == IT_UNKNOWN2 || ( id->type > IT_DELAYCONSUME && id->type < IT_CASH ) || id->type >= IT_MAX )
+ {// catch invalid item types
+ ShowWarning("itemdb_parse_dbrow: Invalid item type %d for item %d. IT_ETC will be used.\n", id->type, nameid);
+ id->type = IT_ETC;
+ }
+
if (id->type == IT_DELAYCONSUME)
{ //Items that are consumed only after target confirmation
id->type = IT_USABLE;
diff --git a/src/map/itemdb.h b/src/map/itemdb.h
index 5b07b5c1b..00dbf73e3 100644
--- a/src/map/itemdb.h
+++ b/src/map/itemdb.h
@@ -108,6 +108,7 @@ struct item_data* itemdb_exists(int nameid);
#define itemdb_available(n) (itemdb_exists(n) && itemdb_search(n)->flag.available)
#define itemdb_viewid(n) (itemdb_search(n)->view_id)
#define itemdb_autoequip(n) (itemdb_search(n)->flag.autoequip)
+const char* itemdb_typename(int type);
int itemdb_group_bonus(struct map_session_data* sd, int itemid);
int itemdb_searchrandomid(int flags);
diff --git a/src/map/pc.c b/src/map/pc.c
index 9d8ad29b0..785036d0f 100644
--- a/src/map/pc.c
+++ b/src/map/pc.c
@@ -605,7 +605,7 @@ int pc_setequipindex(struct map_session_data *sd)
if( sd->status.inventory[i].equip & EQP_HAND_L )
{
- if( sd->inventory_data[i] && sd->inventory_data[i]->type == 4 )
+ if( sd->inventory_data[i] && sd->inventory_data[i]->type == IT_WEAPON )
sd->weapontype2 = sd->inventory_data[i]->look;
else
sd->weapontype2 = 0;
diff --git a/src/map/skill.c b/src/map/skill.c
index a6b008d5d..e77703e1f 100644
--- a/src/map/skill.c
+++ b/src/map/skill.c
@@ -9306,7 +9306,7 @@ void skill_repairweapon (struct map_session_data *sd, int idx)
return;
}
- if (itemdb_type(item->nameid)==4)
+ if (itemdb_type(item->nameid)==IT_WEAPON)
material = materials [itemdb_wlv(item->nameid)-1]; // Lv1/2/3/4 weapons consume 1 Iron Ore/Iron/Steel/Rough Oridecon
else
material = materials [2]; // Armors consume 1 Steel
@@ -9357,7 +9357,7 @@ void skill_weaponrefine (struct map_session_data *sd, int idx)
struct item_data *ditem = sd->inventory_data[idx];
item = &sd->status.inventory[idx];
- if(item->nameid > 0 && ditem->type == 4)
+ if(item->nameid > 0 && ditem->type == IT_WEAPON)
{
if( item->refine >= sd->menuskill_val
|| item->refine >= MAX_REFINE // if it's no longer refineable