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.c137
1 files changed, 110 insertions, 27 deletions
diff --git a/src/map/itemdb.c b/src/map/itemdb.c
index 2b0847e1a..7fedb19ae 100644
--- a/src/map/itemdb.c
+++ b/src/map/itemdb.c
@@ -1336,11 +1336,11 @@ void itemdb_read_options(void)
if (!libconfig->load_file(&item_options_db, filepath))
return;
-
+
#ifdef ENABLE_CASE_CHECK
script->parser_current_file = filepath;
#endif // ENABLE_CASE_CHECK
-
+
if ((ito=libconfig->setting_get_member(item_options_db.root, "item_options_db")) == NULL) {
ShowError("itemdb_read_options: '%s' could not be loaded.\n", filepath);
libconfig->destroy(&item_options_db);
@@ -1399,7 +1399,7 @@ void itemdb_read_options(void)
ShowError("itemdb_read_options: Script code not found for entry %s (Id: %d) in '%s', skipping...\n", str, t_opt.index, filepath);
continue;
}
-
+
/* Set Script */
t_opt.script = *str ? script->parse(str, filepath, t_opt.index, SCRIPT_IGNORE_EXTERNAL_BRACKETS, NULL) : NULL;
@@ -1416,11 +1416,11 @@ void itemdb_read_options(void)
count++;
}
-
+
#ifdef ENABLE_CASE_CHECK
script->parser_current_file = NULL;
#endif // ENABLE_CASE_CHECK
-
+
libconfig->destroy(&item_options_db);
VECTOR_CLEAR(duplicate_id);
@@ -1638,9 +1638,9 @@ int itemdb_gendercheck(struct item_data *id)
return 1;
if (id->nameid == WEDDING_RING_F) //Bride Ring
return 0;
- if (id->look == W_MUSICAL && id->type == IT_WEAPON) //Musical instruments are always male-only
+ if (id->subtype == W_MUSICAL && id->type == IT_WEAPON) //Musical instruments are always male-only
return 1;
- if (id->look == W_WHIP && id->type == IT_WEAPON) //Whips are always female-only
+ if (id->subtype == W_WHIP && id->type == IT_WEAPON) //Whips are always female-only
return 0;
return (battle_config.ignore_items_gender) ? 2 : id->sex;
@@ -1788,10 +1788,14 @@ int itemdb_validate_entry(struct item_data *entry, int n, const char *source) {
memset(&entry->stack, '\0', sizeof(entry->stack));
}
- if (entry->type == IT_WEAPON && (entry->look < 0 || entry->look >= MAX_SINGLE_WEAPON_TYPE)) {
- ShowWarning("itemdb_validate_entry: Invalid View for weapon items. View value %d for item %d (%s) in '%s', defaulting to 1.\n",
- entry->look, entry->nameid, entry->jname, source);
- entry->look = 1;
+ if (entry->type == IT_WEAPON && (entry->subtype <= 0 || entry->subtype >= MAX_SINGLE_WEAPON_TYPE)) {
+ ShowWarning("itemdb_validate_entry: Invalid View for weapon items. View value %d for item %d (%s) in '%s', defaulting to W_DAGGER.\n",
+ entry->subtype, entry->nameid, entry->jname, source);
+ entry->subtype = W_DAGGER;
+ } else if (entry->type == IT_AMMO && (entry->subtype <= 0 || entry->subtype >= MAX_AMMO_TYPE)) {
+ ShowWarning("itemdb_validate_entry: Invalid View for ammunition items. View value %d for item %d (%s) in '%s', defaulting to A_ARROW.\n",
+ entry->subtype, entry->nameid, entry->jname, source);
+ entry->subtype = A_ARROW;
}
entry->wlv = cap_value(entry->wlv, REFINE_TYPE_ARMOR, REFINE_TYPE_MAX);
@@ -1803,10 +1807,10 @@ int itemdb_validate_entry(struct item_data *entry, int n, const char *source) {
if( entry->type != IT_ARMOR && entry->type != IT_WEAPON && !entry->flag.no_refine )
entry->flag.no_refine = 1;
-
+
if (entry->type != IT_ARMOR && entry->type != IT_WEAPON && !entry->flag.no_options)
entry->flag.no_options = 1;
-
+
if (entry->flag.available != 1) {
entry->flag.available = 1;
entry->view_id = 0;
@@ -1986,6 +1990,14 @@ int itemdb_readdb_libconfig_sub(struct config_setting_t *it, int n, const char *
else if( !inherit )
id.type = IT_ETC;
+ if (itemdb->lookup_const(it, "Subtype", &i32) && i32 >= 0) {
+ if (id.type == IT_WEAPON || id.type == IT_AMMO)
+ id.subtype = i32;
+ else
+ ShowWarning("itemdb_readdb_libconfig_sub: Field 'Subtype' is only allowed for IT_WEAPON or IT_AMMO (Item #%d: %s). Ignoring.\n",
+ id.nameid, id.name);
+ }
+
if( itemdb->lookup_const(it, "Buy", &i32) )
id.value_buy = i32;
else if( !inherit )
@@ -2025,7 +2037,7 @@ int itemdb_readdb_libconfig_sub(struct config_setting_t *it, int n, const char *
itemdb->jobmask2mapid(id.class_base, UINT64_MAX);
}
- if( itemdb->lookup_const(it, "Upper", &i32) && i32 >= 0 )
+ if (itemdb->lookup_const_mask(it, "Upper", &i32) && i32 >= 0)
id.class_upper = (unsigned int)i32;
else if( !inherit )
id.class_upper = ITEMUPPER_ALL;
@@ -2035,7 +2047,7 @@ int itemdb_readdb_libconfig_sub(struct config_setting_t *it, int n, const char *
else if( !inherit )
id.sex = 2;
- if( itemdb->lookup_const(it, "Loc", &i32) && i32 >= 0 )
+ if (itemdb->lookup_const_mask(it, "Loc", &i32) && i32 >= 0)
id.equip = i32;
if( itemdb->lookup_const(it, "WeaponLv", &i32) && i32 >= 0 )
@@ -2054,12 +2066,27 @@ int itemdb_readdb_libconfig_sub(struct config_setting_t *it, int n, const char *
if( (t = libconfig->setting_get_member(it, "Refine")) )
id.flag.no_refine = libconfig->setting_get_bool(t) ? 0 : 1;
-
+
if ((t = libconfig->setting_get_member(it, "DisableOptions")))
id.flag.no_options = libconfig->setting_get_bool(t) ? 1 : 0;
- if( itemdb->lookup_const(it, "View", &i32) && i32 >= 0 )
- id.look = i32;
+ if (itemdb->lookup_const(it, "ViewSprite", &i32) && i32 >= 0)
+ id.view_sprite = i32;
+
+ if (itemdb->lookup_const(it, "View", &i32) && i32 >= 0) { // TODO: Remove (Deprecated - 2016-09-04 [Haru])
+ if ((id.type == IT_WEAPON || id.type == IT_AMMO) && id.subtype == 0) {
+ ShowWarning("itemdb_readdb_libconfig_sub: The 'View' field is deprecated. Please rename it to 'Subtype' (or 'ViewSprite'). (Item #%d: %s)\n",
+ id.nameid, id.name);
+ id.subtype = i32;
+ } else if ((id.type != IT_WEAPON && id.type != IT_AMMO) && id.view_sprite == 0) {
+ ShowWarning("itemdb_readdb_libconfig_sub: The 'View' field is deprecated. Please rename it to 'ViewSprite' (or 'Subtype'). (Item #%d: %s)\n",
+ id.nameid, id.name);
+ id.view_sprite = i32;
+ } else {
+ ShowWarning("itemdb_readdb_libconfig_sub: The 'View' field is deprecated. Please rename it to 'Subtype' or 'ViewSprite'. (Item #%d: %s)\n",
+ id.nameid, id.name);
+ }
+ }
if( (t = libconfig->setting_get_member(it, "BindOnEquip")) )
id.flag.bindonequip = libconfig->setting_get_bool(t) ? 1 : 0;
@@ -2197,21 +2224,76 @@ int itemdb_readdb_libconfig_sub(struct config_setting_t *it, int n, const char *
bool itemdb_lookup_const(const struct config_setting_t *it, const char *name, int *value)
{
+ const char *str = NULL;
+
nullpo_retr(false, name);
nullpo_retr(false, value);
- if (libconfig->setting_lookup_int(it, name, value))
- {
+
+ if (libconfig->setting_lookup_int(it, name, value)) {
return true;
}
- else
- {
+
+ if (libconfig->setting_lookup_string(it, name, &str)) {
+ if (*str && script->get_constant(str, value))
+ return true;
+ }
+
+ return false;
+}
+
+bool itemdb_lookup_const_mask(const struct config_setting_t *it, const char *name, int *value)
+{
+ const struct config_setting_t *t = NULL;
+
+ nullpo_retr(false, it);
+ nullpo_retr(false, name);
+ nullpo_retr(false, value);
+
+ if ((t = libconfig->setting_get_member(it, name)) == NULL) {
+ return false;
+ }
+
+ if (config_setting_is_scalar(t)) {
const char *str = NULL;
- if (libconfig->setting_lookup_string(it, name, &str))
- {
- if (*str && script->get_constant(str, value))
+
+ if (config_setting_is_number(t)) {
+ *value = libconfig->setting_get_int(t);
+ return true;
+ }
+
+ if ((str = libconfig->setting_get_string(t)) != NULL) {
+ int i32 = -1;
+ if (script->get_constant(str, &i32) && i32 >= 0) {
+ *value = i32;
return true;
+ }
+ }
+
+ return false;
+ }
+
+ if (config_setting_is_aggregate(t) && libconfig->setting_length(t) >= 1) {
+ const struct config_setting_t *elem = NULL;
+ int i = 0;
+
+ *value = 0;
+
+ while ((elem = libconfig->setting_get_elem(t, i++)) != NULL) {
+ const char *str = libconfig->setting_get_string(elem);
+ int i32 = -1;
+
+ if (str == NULL)
+ return false;
+
+ if (!script->get_constant(str, &i32) || i32 < 0)
+ return false;
+
+ *value |= i32;
}
+
+ return true;
}
+
return false;
}
@@ -2369,10 +2451,10 @@ int itemdb_final_sub(union DBKey key, struct DBData *data, va_list ap)
int itemdb_options_final_sub(union DBKey key, struct DBData *data, va_list ap)
{
struct item_option *ito = DB->data2ptr(data);
-
+
if (ito->script != NULL)
script->free_code(ito->script);
-
+
return 0;
}
@@ -2637,4 +2719,5 @@ void itemdb_defaults(void) {
itemdb->id2combo = itemdb_id2combo;
itemdb->is_item_usable = itemdb_is_item_usable;
itemdb->lookup_const = itemdb_lookup_const;
+ itemdb->lookup_const_mask = itemdb_lookup_const_mask;
}