summaryrefslogtreecommitdiff
path: root/src/map/itemdb.c
diff options
context:
space:
mode:
authorai4rei <ai4rei@54d463be-8e91-2dee-dedb-b68131a5f0ec>2010-12-30 01:25:19 +0000
committerai4rei <ai4rei@54d463be-8e91-2dee-dedb-b68131a5f0ec>2010-12-30 01:25:19 +0000
commita5cb1049e0175a1c2c7e9de40f498ed54c29e187 (patch)
tree8f423bffc93ffde0024b44d0545e3d4115ee4e8a /src/map/itemdb.c
parent5baa12ea4a48b09cfc2007ec5c1f05f60a92fd45 (diff)
downloadhercules-a5cb1049e0175a1c2c7e9de40f498ed54c29e187.tar.gz
hercules-a5cb1049e0175a1c2c7e9de40f498ed54c29e187.tar.bz2
hercules-a5cb1049e0175a1c2c7e9de40f498ed54c29e187.tar.xz
hercules-a5cb1049e0175a1c2c7e9de40f498ed54c29e187.zip
* Made remaining csv databases (guild, castle, homunculus, itemdb, mercenary) use sv_readdb, where applicable (follow up to r14524, r14526 and r14532).
- Few databases remain unchanged, which have either a custom layout or are otherwise incompatible with sv_readdb. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@14640 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/map/itemdb.c')
-rw-r--r--src/map/itemdb.c211
1 files changed, 75 insertions, 136 deletions
diff --git a/src/map/itemdb.c b/src/map/itemdb.c
index ce10f4f39..98f9a90d1 100644
--- a/src/map/itemdb.c
+++ b/src/map/itemdb.c
@@ -471,46 +471,32 @@ int itemdb_isidentified(int nameid)
/*==========================================
* アイテム使用可能フラグのオーバーライド
*------------------------------------------*/
-static int itemdb_read_itemavail (void)
-{
- FILE *fp;
- int nameid, j, k, ln = 0;
- char line[1024], *str[10], *p;
+static bool itemdb_read_itemavail(char* str[], int columns, int current)
+{// <nameid>,<sprite>
+ int nameid, sprite;
struct item_data *id;
- sprintf(line, "%s/item_avail.txt", db_path);
- if ((fp = fopen(line,"r")) == NULL) {
- ShowError("can't read %s\n", line);
- return -1;
- }
+ nameid = atoi(str[0]);
- while(fgets(line, sizeof(line), fp))
+ if( ( id = itemdb_exists(nameid) ) == NULL )
{
- if (line[0] == '/' && line[1] == '/')
- continue;
- memset(str, 0, sizeof(str));
- for (j = 0, p = line; j < 2 && p; j++) {
- str[j] = p;
- p = strchr(p, ',');
- if(p) *p++ = 0;
- }
+ ShowWarning("itemdb_read_itemavail: Invalid item id %d.\n", nameid);
+ return false;
+ }
- if (j < 2 || str[0] == NULL ||
- (nameid = atoi(str[0])) < 0 || !(id = itemdb_exists(nameid)))
- continue;
+ sprite = atoi(str[1]);
- k = atoi(str[1]);
- if (k > 0) {
- id->flag.available = 1;
- id->view_id = k;
- } else
- id->flag.available = 0;
- ln++;
+ if( sprite > 0 )
+ {
+ id->flag.available = 1;
+ id->view_id = sprite;
+ }
+ else
+ {
+ id->flag.available = 0;
}
- fclose(fp);
- ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", ln, "item_avail.txt");
- return 0;
+ return true;
}
/*==========================================
@@ -591,137 +577,90 @@ static void itemdb_read_itemgroup(void)
/*==========================================
* 装備制限ファイル読み出し
*------------------------------------------*/
-static int itemdb_read_noequip(void)
-{
- FILE *fp;
- char line[1024];
- int ln=0;
- int nameid,j;
- char *str[32],*p;
+static bool itemdb_read_noequip(char* str[], int columns, int current)
+{// <nameid>,<mode>
+ int nameid;
struct item_data *id;
- sprintf(line, "%s/item_noequip.txt", db_path);
- if( (fp=fopen(line,"r"))==NULL ){
- ShowError("can't read %s\n", line);
- return -1;
- }
- while(fgets(line, sizeof(line), fp))
- {
- if(line[0]=='/' && line[1]=='/')
- continue;
- memset(str,0,sizeof(str));
- for(j=0,p=line;j<2 && p;j++){
- str[j]=p;
- p=strchr(p,',');
- if(p) *p++=0;
- }
- if(str[0]==NULL)
- continue;
-
- nameid=atoi(str[0]);
- if(nameid<=0 || !(id=itemdb_exists(nameid)))
- continue;
+ nameid = atoi(str[0]);
- id->flag.no_equip |= atoi(str[1]);
+ if( ( id = itemdb_exists(nameid) ) == NULL )
+ {
+ ShowWarning("itemdb_read_noequip: Invalid item id %d.\n", nameid);
+ return false;
+ }
- ln++;
+ id->flag.no_equip |= atoi(str[1]);
- }
- fclose(fp);
- if (ln > 0) {
- ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n",ln,"item_noequip.txt");
- }
- return 0;
+ return true;
}
/*==========================================
* Reads item trade restrictions [Skotlex]
*------------------------------------------*/
-static int itemdb_read_itemtrade(void)
-{
- FILE *fp;
- int nameid, j, flag, gmlv, ln = 0;
- char line[1024], *str[10], *p;
+static bool itemdb_read_itemtrade(char* str[], int columns, int current)
+{// <nameid>,<mask>,<gm level>
+ int nameid, flag, gmlv;
struct item_data *id;
- sprintf(line, "%s/item_trade.txt", db_path);
- if ((fp = fopen(line,"r")) == NULL) {
- ShowError("can't read %s\n", line);
- return -1;
- }
+ nameid = atoi(str[0]);
- while(fgets(line, sizeof(line), fp))
+ if( ( id = itemdb_exists(nameid) ) == NULL )
{
- if (line[0] == '/' && line[1] == '/')
- continue;
- memset(str, 0, sizeof(str));
- for (j = 0, p = line; j < 3 && p; j++) {
- str[j] = p;
- p = strchr(p, ',');
- if(p) *p++ = 0;
- }
+ //ShowWarning("itemdb_read_itemtrade: Invalid item id %d.\n", nameid);
+ //return false;
+ // FIXME: item_trade.txt contains items, which are commented in item database.
+ return true;
+ }
- if (j < 3 || str[0] == NULL ||
- (nameid = atoi(str[0])) < 0 || !(id = itemdb_exists(nameid)))
- continue;
+ flag = atoi(str[1]);
+ gmlv = atoi(str[2]);
- flag = atoi(str[1]);
- gmlv = atoi(str[2]);
-
- if (flag > 0 && flag < 128 && gmlv > 0) { //Check range
- id->flag.trade_restriction = flag;
- id->gm_lv_trade_override = gmlv;
- ln++;
- }
+ if( flag < 0 || flag >= 128 )
+ {//Check range
+ ShowWarning("itemdb_read_itemtrade: Invalid trading mask %d for item id %d.\n", flag, nameid);
+ return false;
}
- fclose(fp);
- ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", ln, "item_trade.txt");
- return 0;
+ if( gmlv < 1 )
+ {
+ ShowWarning("itemdb_read_itemtrade: Invalid override GM level %d for item id %d.\n", gmlv, nameid);
+ return false;
+ }
+
+ id->flag.trade_restriction = flag;
+ id->gm_lv_trade_override = gmlv;
+
+ return true;
}
/*==========================================
* Reads item delay amounts [Paradox924X]
*------------------------------------------*/
-static int itemdb_read_itemdelay(void)
-{
- FILE *fp;
- int nameid, j, item_delays = 0;
- char line[1024], *str[10], *p;
+static bool itemdb_read_itemdelay(char* str[], int columns, int current)
+{// <nameid>,<delay>
+ int nameid, delay;
struct item_data *id;
- sprintf(line, "%s/item_delay.txt", db_path);
- if ((fp = fopen(line,"r")) == NULL) {
- ShowError("can't read %s\n", line);
- return -1;
- }
+ nameid = atoi(str[0]);
- while(fgets(line, sizeof(line), fp))
+ if( ( id = itemdb_exists(nameid) ) == NULL )
{
- if (line[0] == '/' && line[1] == '/')
- continue;
- if (item_delays == MAX_ITEMDELAYS) {
- ShowError("itemdb_read_itemdelay: Too many entries specified in %s/item_delay.txt! Increase MAX_ITEMDELAYS in itemdb.h!\n", db_path);
- break;
- }
- memset(str, 0, sizeof(str));
- for (j = 0, p = line; j < 2 && p; j++) {
- str[j] = p;
- p = strchr(p, ',');
- if(p) *p++ = 0;
- }
+ ShowWarning("itemdb_read_itemdelay: Invalid item id %d.\n", nameid);
+ return false;
+ }
- if (j < 2 || str[0] == NULL ||
- (nameid = atoi(str[0])) < 0 || !(id = itemdb_exists(nameid)))
- continue;
+ delay = atoi(str[1]);
- id->delay = atoi(str[1]);
- item_delays++;
+ if( delay < 0 )
+ {
+ ShowWarning("itemdb_read_itemdelay: Invalid delay %d for item id %d.\n", id->delay, nameid);
+ return false;
}
- fclose(fp);
- ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", item_delays, "item_delay.txt");
- return 0;
+ id->delay = delay;
+
+ return true;
}
/*======================================
@@ -1036,10 +975,10 @@ static void itemdb_read(void)
itemdb_readdb();
itemdb_read_itemgroup();
- itemdb_read_itemavail();
- itemdb_read_noequip();
- itemdb_read_itemtrade();
- itemdb_read_itemdelay();
+ sv_readdb(db_path, "item_avail.txt", ',', 2, 2, -1, &itemdb_read_itemavail);
+ sv_readdb(db_path, "item_noequip.txt", ',', 2, 2, -1, &itemdb_read_noequip);
+ sv_readdb(db_path, "item_trade.txt", ',', 3, 3, -1, &itemdb_read_itemtrade);
+ sv_readdb(db_path, "item_delay.txt", ',', 2, 2, MAX_ITEMDELAYS, &itemdb_read_itemdelay);
}
/*==========================================