summaryrefslogtreecommitdiff
path: root/src/map/itemdb.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/map/itemdb.c')
-rw-r--r--src/map/itemdb.c125
1 files changed, 78 insertions, 47 deletions
diff --git a/src/map/itemdb.c b/src/map/itemdb.c
index ddae6b38a..1849fdbb6 100644
--- a/src/map/itemdb.c
+++ b/src/map/itemdb.c
@@ -102,14 +102,14 @@ int itemdb_searchrandomid(int group)
if(group<1 || group>=MAX_ITEMGROUP) {
if (battle_config.error_log)
ShowError("itemdb_searchrandomid: Invalid group id %d\n", group);
- return 512; //Return apple?
+ return UNKNOWN_ITEM_ID;
}
if (itemgroup_db[group].qty)
return itemgroup_db[group].nameid[rand()%itemgroup_db[group].qty];
if (battle_config.error_log)
ShowError("itemdb_searchrandomid: No item entries for group id %d\n", group);
- return 512;
+ return UNKNOWN_ITEM_ID;
}
/*==========================================
@@ -210,7 +210,7 @@ static void create_dummy_data(void) {
dummy_item.type=3; //Etc item
strncpy(dummy_item.name,"UNKNOWN_ITEM",ITEM_NAME_LENGTH-1);
strncpy(dummy_item.jname,"UNKNOWN_ITEM",ITEM_NAME_LENGTH-1);
- dummy_item.view_id = 512; //Use apple sprite.
+ dummy_item.view_id = UNKNOWN_ITEM_ID;
}
static void* create_item_data(DBKey key, va_list args) {
@@ -218,7 +218,7 @@ static void* create_item_data(DBKey key, va_list args) {
id=(struct item_data *)aCalloc(1,sizeof(struct item_data));
id->nameid = key.i;
id->weight=1;
- id->type=3; //Etc item
+ id->type=IT_ETC;
return id;
}
@@ -256,40 +256,33 @@ struct item_data* itemdb_search(int nameid)
}
/*==========================================
- *
+ * Returns if given item is a player-equippable piece.
*------------------------------------------
*/
int itemdb_isequip(int nameid)
{
int type=itemdb_type(nameid);
- if(type==0 || type==2 || type==3 || type==6 || type==10)
- return 0;
- return 1;
+ switch (type) {
+ case IT_WEAPON:
+ case IT_ARMOR:
+ case IT_AMMO:
+ return 1;
+ default:
+ return 0;
+ }
}
+
/*==========================================
- *
+ * Alternate version of itemdb_isequip
*------------------------------------------
*/
int itemdb_isequip2(struct item_data *data)
{
nullpo_retr(0, data);
switch(data->type) {
- case 0:
- case 2:
- case 3:
- case 6:
- case 10:
- return 0;
- default:
- return 1;
- }
-}
-//Checks if the item is pet-equipment (7/8)
-static int itemdb_ispetequip(struct item_data *data)
-{
- switch(data->type) {
- case 7:
- case 8:
+ case IT_WEAPON:
+ case IT_ARMOR:
+ case IT_AMMO:
return 1;
default:
return 0;
@@ -297,6 +290,43 @@ static int itemdb_ispetequip(struct item_data *data)
}
/*==========================================
+* Returns if given item's type is stackable.
+*------------------------------------------
+*/
+int itemdb_isstackable(int nameid)
+{
+ int type=itemdb_type(nameid);
+ switch(type) {
+ case IT_WEAPON:
+ case IT_ARMOR:
+ case IT_PETEGG:
+ case IT_PETARMOR:
+ return 0;
+ default:
+ return 1;
+ }
+}
+
+/*==========================================
+* Alternate version of itemdb_isstackable
+*------------------------------------------
+*/
+int itemdb_isstackable2(struct item_data *data)
+{
+ nullpo_retr(0, data);
+ switch(data->type) {
+ case IT_WEAPON:
+ case IT_ARMOR:
+ case IT_PETEGG:
+ case IT_PETARMOR:
+ return 0;
+ default:
+ return 1;
+ }
+}
+
+
+/*==========================================
* Trade Restriction functions [Skotlex]
*------------------------------------------
*/
@@ -343,10 +373,7 @@ int itemdb_isrestricted(struct item* item, int gmlv, int gmlv2, int (*func)(stru
if (!func(item_data, gmlv, gmlv2))
return 0;
- if(item_data->slot == 0 ||
- item->card[0] ==(short)0xff00 ||
- item->card[0]==0x00ff ||
- item->card[0]==0x00fe)
+ if(item_data->slot == 0 || itemdb_isspecial(item->card[0]))
return 1;
for(i = 0; i < item_data->slot; i++) {
@@ -358,15 +385,20 @@ int itemdb_isrestricted(struct item* item, int gmlv, int gmlv2, int (*func)(stru
}
/*==========================================
- *
+ * Specifies if item-type should drop unidentified.
*------------------------------------------
*/
-int itemdb_isequip3(int nameid)
+int itemdb_isidentified(int nameid)
{
int type=itemdb_type(nameid);
- if(type==4 || type==5 || type == 8)
- return 1;
- return 0;
+ switch (type) {
+ case IT_WEAPON:
+ case IT_ARMOR:
+ case IT_PETARMOR:
+ return 0;
+ default:
+ return 1;
+ }
}
/*==========================================
@@ -704,7 +736,7 @@ static int itemdb_read_noequip(void)
continue;
nameid=atoi(str[0]);
- if(nameid<=0 || nameid>=20000 || !(id=itemdb_exists(nameid)))
+ if(nameid<=0 || !(id=itemdb_exists(nameid)))
continue;
id->flag.no_equip=atoi(str[1]);
@@ -747,7 +779,7 @@ static int itemdb_read_itemtrade(void)
}
if (j < 3 || str[0] == NULL ||
- (nameid = atoi(str[0])) < 0 || nameid >= 20000 || !(id = itemdb_exists(nameid)))
+ (nameid = atoi(str[0])) < 0 || !(id = itemdb_exists(nameid)))
continue;
flag = atoi(str[1]);
@@ -775,9 +807,9 @@ static int itemdb_gendercheck(struct item_data *id)
return 1;
if (id->nameid == WEDDING_RING_F) //Bride Ring
return 0;
- if (id->look == 13 && id->type == 4) //Musical instruments are always male-only
+ if (id->look == W_MUSICAL && id->type == IT_WEAPON) //Musical instruments are always male-only
return 1;
- if (id->look == 14 && id->type == 4) //Whips are always female-only
+ if (id->look == W_WHIP && id->type == IT_WEAPON) //Whips are always female-only
return 0;
return (battle_config.ignore_items_gender?2:id->sex);
@@ -837,7 +869,7 @@ static int itemdb_read_sqldb(void)
nameid = atoi(sql_row[0]);
// If the identifier is not within the valid range, process the next row
- if (nameid == 0 || nameid >= 20000)
+ if (nameid == 0)
continue;
ln++;
@@ -849,10 +881,10 @@ static int itemdb_read_sqldb(void)
strncpy(id->jname, sql_row[2], ITEM_NAME_LENGTH-1);
id->type = atoi(sql_row[3]);
- if (id->type == 11)
+ if (id->type == IT_DELAYCONSUME)
{ //Items that are consumed upon target confirmation
//(yggdrasil leaf, spells & pet lures) [Skotlex]
- id->type = 2;
+ id->type = IT_USABLE;
id->flag.delay_consume=1;
}
@@ -891,7 +923,7 @@ static int itemdb_read_sqldb(void)
id->class_upper= (sql_row[12] != NULL) ? atoi(sql_row[12]) : 0;
id->sex = (sql_row[13] != NULL) ? atoi(sql_row[13]) : 0;
id->equip = (sql_row[14] != NULL) ? atoi(sql_row[14]) : 0;
- if (!id->equip && itemdb_isequip2(id) && !itemdb_ispetequip(id))
+ if (!id->equip && itemdb_isequip2(id))
{
ShowWarning("Item %d (%s) is an equipment with no equip-field! Making it an etc item.\n", nameid, id->jname);
id->type = 3;
@@ -1018,10 +1050,10 @@ static int itemdb_readdb(void)
strncpy(id->name, str[1], ITEM_NAME_LENGTH-1);
strncpy(id->jname, str[2], ITEM_NAME_LENGTH-1);
id->type=atoi(str[3]);
- if (id->type == 11)
+ if (id->type == IT_DELAYCONSUME)
{ //Items that are consumed upon target confirmation
//(yggdrasil leaf, spells & pet lures) [Skotlex]
- id->type = 2;
+ id->type = IT_USABLE;
id->flag.delay_consume=1;
}
@@ -1063,7 +1095,7 @@ static int itemdb_readdb(void)
if(id->equip != atoi(str[14])){
id->equip=atoi(str[14]);
}
- if (!id->equip && itemdb_isequip2(id) && !itemdb_ispetequip(id))
+ if (!id->equip && itemdb_isequip2(id))
{
ShowWarning("Item %d (%s) is an equipment with no equip-field! Making it an etc item.\n", nameid, id->jname);
id->type = 3;
@@ -1201,8 +1233,7 @@ static int itemdb_final_sub (DBKey key,void *data,va_list ap)
void itemdb_reload(void)
{
- // free up all item scripts first
- item_db->foreach(item_db, itemdb_final_sub, 0);
+ //Just read, the function takes care of freeing scripts.
itemdb_read();
}