diff options
Diffstat (limited to 'src/map/itemdb.c')
-rw-r--r-- | src/map/itemdb.c | 117 |
1 files changed, 100 insertions, 17 deletions
diff --git a/src/map/itemdb.c b/src/map/itemdb.c index 2b0847e1a..96eced725 100644 --- a/src/map/itemdb.c +++ b/src/map/itemdb.c @@ -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); @@ -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 ) @@ -2058,8 +2070,23 @@ int itemdb_readdb_libconfig_sub(struct config_setting_t *it, int n, const char * 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; } @@ -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; } |