Changed item group parsing to svreaddb
This commit is contained in:
parent
4f3468958f
commit
1739ff4153
@ -545,58 +545,16 @@ static bool itemdb_read_itemavail(char* str[], int columns, int current) {
|
||||
|
||||
static int itemdb_group_free(DBKey key, DBData *data, va_list ap);
|
||||
|
||||
/** Read item group data
|
||||
* Structure: GroupID,ItemID,Rate{,Amount,isMust,isAnnounced,Duration,GUID,isBound,isNamed}
|
||||
*/
|
||||
static void itemdb_read_itemgroup_sub(const char* filename, bool silent)
|
||||
{
|
||||
FILE *fp;
|
||||
int ln = 0, entries = 0;
|
||||
char line[1024];
|
||||
|
||||
if ((fp=fopen(filename,"r")) == NULL) {
|
||||
if(silent == 0) ShowError("Can't read %s\n", filename);
|
||||
return;
|
||||
}
|
||||
|
||||
while (fgets(line,sizeof(line),fp)) {
|
||||
static bool itemdb_read_group(char* str[], int columns, int current) {
|
||||
DBData data;
|
||||
int group_id = -1;
|
||||
unsigned int j, prob = 1;
|
||||
uint8 rand_group = 1;
|
||||
char *str[10], *p;
|
||||
struct s_item_group_random *random = NULL;
|
||||
struct s_item_group_db *group = NULL;
|
||||
struct s_item_group_entry entry;
|
||||
bool found = false;
|
||||
|
||||
ln++;
|
||||
if (line[0] == '/' && line[1] == '/')
|
||||
continue;
|
||||
if (strstr(line,"import")) {
|
||||
char w1[16], w2[64];
|
||||
|
||||
if (sscanf(line,"%15[^:]: %63[^\r\n]",w1,w2) == 2 &&
|
||||
strcmpi(w1,"import") == 0)
|
||||
{
|
||||
itemdb_read_itemgroup_sub(w2, 0);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
memset(str,0,sizeof(str));
|
||||
for (j = 0, p = line; j < 9 && p;j++) {
|
||||
str[j] = p;
|
||||
p = strchr(p,',');
|
||||
if (p) *p++=0;
|
||||
}
|
||||
if (str[0] == NULL) //Empty Group ID
|
||||
continue;
|
||||
if (j < 3) {
|
||||
if (j > 1) // Or else it barks on blank lines...
|
||||
ShowWarning("itemdb_read_itemgroup: Insufficient fields for entry at %s:%d\n", filename, ln);
|
||||
continue;
|
||||
}
|
||||
|
||||
memset(&entry, 0, sizeof(entry));
|
||||
entry.amount = 1;
|
||||
entry.bound = BOUND_NONE;
|
||||
@ -609,15 +567,15 @@ static void itemdb_read_itemgroup_sub(const char* filename, bool silent)
|
||||
script_get_constant(trim(str[0]), &group_id);
|
||||
|
||||
if (group_id < 0) {
|
||||
ShowWarning("itemdb_read_itemgroup: Invalid Group ID '%s' (%s:%d)\n", str[0], filename, ln);
|
||||
continue;
|
||||
//ShowWarning("itemdb_read_itemgroup: Invalid Group ID '%s' (%s:%d)\n", str[0], filename, ln);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Remove from DB
|
||||
if (strcmpi(str[1], "clear") == 0 && itemdb_group->remove(itemdb_group, db_ui2key(group_id), &data)) {
|
||||
itemdb_group_free(db_ui2key(group_id), &data, 0);
|
||||
ShowNotice("Item Group '%s' has been cleared.\n", str[0]);
|
||||
continue;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Checking sub group
|
||||
@ -625,13 +583,13 @@ static void itemdb_read_itemgroup_sub(const char* filename, bool silent)
|
||||
if (str[4] != NULL)
|
||||
rand_group = atoi(str[4]);
|
||||
if (rand_group < 0 || rand_group > MAX_ITEMGROUP_RANDGROUP) {
|
||||
ShowWarning("itemdb_read_itemgroup: Invalid sub group '%d' for group '%s' in %s:%d\n", rand_group, str[0], filename, ln);
|
||||
continue;
|
||||
//ShowWarning("itemdb_read_itemgroup: Invalid sub group '%d' for group '%s' in %s:%d\n", rand_group, str[0], filename, ln);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (rand_group != 0 && prob < 1) {
|
||||
ShowWarning("itemdb_read_itemgroup: Random item must has probability. Group '%s' in %s:%d\n", str[0], filename, ln);
|
||||
continue;
|
||||
//ShowWarning("itemdb_read_itemgroup: Random item must has probability. Group '%s' in %s:%d\n", str[0], filename, ln);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Checking item
|
||||
@ -647,8 +605,8 @@ static void itemdb_read_itemgroup_sub(const char* filename, bool silent)
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
ShowWarning("itemdb_read_itemgroup: Non-existant item '%s' in %s:%d\n", str[1], filename, ln);
|
||||
continue;
|
||||
//ShowWarning("itemdb_read_itemgroup: Non-existant item '%s' in %s:%d\n", str[1], filename, ln);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (str[3] != NULL) entry.amount = cap_value(atoi(str[3]),1,MAX_AMOUNT);
|
||||
@ -671,8 +629,7 @@ static void itemdb_read_itemgroup_sub(const char* filename, bool silent)
|
||||
|
||||
// If 'must' item isn't set as random item, skip the next process
|
||||
if (!prob) {
|
||||
entries++;
|
||||
continue;
|
||||
return true;
|
||||
}
|
||||
rand_group = 0;
|
||||
}
|
||||
@ -688,18 +645,7 @@ static void itemdb_read_itemgroup_sub(const char* filename, bool silent)
|
||||
random->data[j] = entry;
|
||||
|
||||
random->data_qty += prob;
|
||||
entries++;
|
||||
}
|
||||
fclose(fp);
|
||||
ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", entries, filename);
|
||||
return;
|
||||
}
|
||||
|
||||
static void itemdb_read_itemgroup(const char* basedir, bool silent) {
|
||||
char filepath[256];
|
||||
sprintf(filepath, "%s/%s", basedir, "item_group_db.txt");
|
||||
itemdb_read_itemgroup_sub(filepath, silent);
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Read item forbidden by mapflag (can't equip item)
|
||||
@ -1609,8 +1555,16 @@ static void itemdb_read(void) {
|
||||
sv_readdb(dbsubpath1, "item_avail.txt", ',', 2, 2, -1, &itemdb_read_itemavail, i);
|
||||
sv_readdb(dbsubpath1, "item_stack.txt", ',', 3, 3, -1, &itemdb_read_stack, i);
|
||||
sv_readdb(dbsubpath1, "item_nouse.txt", ',', 3, 3, -1, &itemdb_read_nouse, i);
|
||||
|
||||
itemdb_read_itemgroup(dbsubpath2, i);
|
||||
sv_readdb(dbsubpath2, "item_group_db.txt", ',', 2, 10, -1, &itemdb_read_group, i);
|
||||
sv_readdb(dbsubpath2, "item_bluebox.txt", ',', 2, 10, -1, &itemdb_read_group, i);
|
||||
sv_readdb(dbsubpath2, "item_violetbox.txt", ',', 2, 10, -1, &itemdb_read_group, i);
|
||||
sv_readdb(dbsubpath2, "item_cardalbum.txt", ',', 2, 10, -1, &itemdb_read_group, i);
|
||||
sv_readdb(dbsubpath1, "item_findingore.txt", ',', 2, 10, -1, &itemdb_read_group, i);
|
||||
sv_readdb(dbsubpath2, "item_giftbox.txt", ',', 2, 10, -1, &itemdb_read_group, i);
|
||||
sv_readdb(dbsubpath2, "item_misc.txt", ',', 2, 10, -1, &itemdb_read_group, i);
|
||||
#ifdef RENEWAL
|
||||
sv_readdb(dbsubpath2, "item_package.txt", ',', 2, 10, -1, &itemdb_read_group, i);
|
||||
#endif
|
||||
itemdb_read_combos(dbsubpath2,i); //TODO change this to sv_read ? id#script ?
|
||||
sv_readdb(dbsubpath2, "item_noequip.txt", ',', 2, 2, -1, &itemdb_read_noequip, i);
|
||||
sv_readdb(dbsubpath2, "item_trade.txt", ',', 3, 3, -1, &itemdb_read_itemtrade, i);
|
||||
|
Loading…
x
Reference in New Issue
Block a user