diff options
Diffstat (limited to 'src/map/itemdb.c')
-rw-r--r-- | src/map/itemdb.c | 81 |
1 files changed, 63 insertions, 18 deletions
diff --git a/src/map/itemdb.c b/src/map/itemdb.c index 508a0ccec..19cc02d21 100644 --- a/src/map/itemdb.c +++ b/src/map/itemdb.c @@ -16,6 +16,7 @@ #include "mob.h" // MAX_MOB_DB #include "pc.h" // W_MUSICAL, W_WHIP #include "script.h" // item script processing +#include "../common/HPM.h" #include "../common/conf.h" #include "../common/malloc.h" #include "../common/nullpo.h" @@ -1501,6 +1502,11 @@ int itemdb_validate_entry(struct item_data *entry, int n, const char *source) { return item->nameid; } +void itemdb_readdb_additional_fields(int itemid, config_setting_t *it, int n, const char *source) +{ + // do nothing. plugins can do own work +} + /** * Processes one itemdb entry from the sql backend, loading and inserting it * into the item database. @@ -1676,7 +1682,7 @@ int itemdb_readdb_libconfig_sub(config_setting_t *it, int n, const char *source) * OnUnequipScript: <" OnUnequip Script "> * Inherit: inherit or override */ - if( !libconfig->setting_lookup_int(it, "Id", &i32) ) { + if( !itemdb->lookup_const(it, "Id", &i32) ) { ShowWarning("itemdb_readdb_libconfig_sub: Invalid or missing id in \"%s\", entry #%d, skipping.\n", source, n); return 0; } @@ -1711,57 +1717,57 @@ int itemdb_readdb_libconfig_sub(config_setting_t *it, int n, const char *source) safestrncpy(id.jname, str, sizeof(id.jname)); } - if( libconfig->setting_lookup_int(it, "Type", &i32) ) + if( itemdb->lookup_const(it, "Type", &i32) ) id.type = i32; else if( !inherit ) id.type = IT_ETC; - if( libconfig->setting_lookup_int(it, "Buy", &i32) ) + if( itemdb->lookup_const(it, "Buy", &i32) ) id.value_buy = i32; else if( !inherit ) id.value_buy = -1; - if( libconfig->setting_lookup_int(it, "Sell", &i32) ) + if( itemdb->lookup_const(it, "Sell", &i32) ) id.value_sell = i32; else if( !inherit ) id.value_sell = -1; - if( libconfig->setting_lookup_int(it, "Weight", &i32) && i32 >= 0 ) + if( itemdb->lookup_const(it, "Weight", &i32) && i32 >= 0 ) id.weight = i32; - if( libconfig->setting_lookup_int(it, "Atk", &i32) && i32 >= 0 ) + if( itemdb->lookup_const(it, "Atk", &i32) && i32 >= 0 ) id.atk = i32; - if( libconfig->setting_lookup_int(it, "Matk", &i32) && i32 >= 0 ) + if( itemdb->lookup_const(it, "Matk", &i32) && i32 >= 0 ) id.matk = i32; - if( libconfig->setting_lookup_int(it, "Def", &i32) && i32 >= 0 ) + if( itemdb->lookup_const(it, "Def", &i32) && i32 >= 0 ) id.def = i32; - if( libconfig->setting_lookup_int(it, "Range", &i32) && i32 >= 0 ) + if( itemdb->lookup_const(it, "Range", &i32) && i32 >= 0 ) id.range = i32; - if( libconfig->setting_lookup_int(it, "Slots", &i32) && i32 >= 0 ) + if( itemdb->lookup_const(it, "Slots", &i32) && i32 >= 0 ) id.slot = i32; - if( libconfig->setting_lookup_int(it, "Job", &i32) ) // This is an unsigned value, do not check for >= 0 + if( itemdb->lookup_const(it, "Job", &i32) ) // This is an unsigned value, do not check for >= 0 itemdb->jobid2mapid(id.class_base, (unsigned int)i32); else if( !inherit ) itemdb->jobid2mapid(id.class_base, UINT_MAX); - if( libconfig->setting_lookup_int(it, "Upper", &i32) && i32 >= 0 ) + if( itemdb->lookup_const(it, "Upper", &i32) && i32 >= 0 ) id.class_upper = (unsigned int)i32; else if( !inherit ) id.class_upper = ITEMUPPER_ALL; - if( libconfig->setting_lookup_int(it, "Gender", &i32) && i32 >= 0 ) + if( itemdb->lookup_const(it, "Gender", &i32) && i32 >= 0 ) id.sex = i32; else if( !inherit ) id.sex = 2; - if( libconfig->setting_lookup_int(it, "Loc", &i32) && i32 >= 0 ) + if( itemdb->lookup_const(it, "Loc", &i32) && i32 >= 0 ) id.equip = i32; - if( libconfig->setting_lookup_int(it, "WeaponLv", &i32) && i32 >= 0 ) + if( itemdb->lookup_const(it, "WeaponLv", &i32) && i32 >= 0 ) id.wlv = i32; if( (t = libconfig->setting_get_member(it, "EquipLv")) ) { @@ -1778,7 +1784,7 @@ int itemdb_readdb_libconfig_sub(config_setting_t *it, int n, const char *source) if( (t = libconfig->setting_get_member(it, "Refine")) ) id.flag.no_refine = libconfig->setting_get_bool(t) ? 0 : 1; - if( libconfig->setting_lookup_int(it, "View", &i32) && i32 >= 0 ) + if( itemdb->lookup_const(it, "View", &i32) && i32 >= 0 ) id.look = i32; if( (t = libconfig->setting_get_member(it, "BindOnEquip")) ) @@ -1790,7 +1796,7 @@ int itemdb_readdb_libconfig_sub(config_setting_t *it, int n, const char *source) if ((t = libconfig->setting_get_member(it, "KeepAfterUse"))) id.flag.keepafteruse = libconfig->setting_get_bool(t) ? 1 : 0; - if (libconfig->setting_lookup_int(it, "Delay", &i32) && i32 >= 0) + if (itemdb->lookup_const(it, "Delay", &i32) && i32 >= 0) id.delay = i32; if ( (t = libconfig->setting_get_member(it, "Trade")) ) { @@ -1892,7 +1898,7 @@ int itemdb_readdb_libconfig_sub(config_setting_t *it, int n, const char *source) } } - if (libconfig->setting_lookup_int(it, "Sprite", &i32) && i32 >= 0) { + if (itemdb->lookup_const(it, "Sprite", &i32) && i32 >= 0) { id.flag.available = 1; id.view_id = i32; } @@ -1909,6 +1915,24 @@ int itemdb_readdb_libconfig_sub(config_setting_t *it, int n, const char *source) return itemdb->validate_entry(&id, n, source); } +bool itemdb_lookup_const(const config_setting_t *it, const char *name, int *value) +{ + if (libconfig->setting_lookup_int(it, name, value)) + { + return true; + } + else + { + const char *str = NULL; + if (libconfig->setting_lookup_string(it, name, &str)) + { + if (*str && script->get_constant(str, value)) + return true; + } + } + return false; +} + /** * Reads from a libconfig-formatted itemdb file and inserts the found entries into the * item database, overwriting duplicate ones (i.e. item_db2 overriding item_db.) @@ -1936,6 +1960,7 @@ int itemdb_readdb_libconfig(const char *filename) { if( !nameid ) continue; + itemdb->readdb_additional_fields(nameid, it, i - 1, filename); count++; if( duplicate[nameid] ) { @@ -2054,6 +2079,14 @@ struct item_combo * itemdb_id2combo( unsigned short id ) { return itemdb->combos[id]; } +/** + * check is item have usable type + **/ +bool itemdb_is_item_usable(struct item_data *item) +{ + return item->type == IT_HEALING || item->type == IT_USABLE || item->type == IT_CASH; +} + /*========================================== * Initialize / Finalize *------------------------------------------*/ @@ -2061,6 +2094,7 @@ struct item_combo * itemdb_id2combo( unsigned short id ) { /// Destroys the item_data. void destroy_item_data(struct item_data* self, int free_self) { + int v; if( self == NULL ) return; // free scripts @@ -2072,6 +2106,14 @@ void destroy_item_data(struct item_data* self, int free_self) script->free_code(self->unequip_script); if( self->combos ) aFree(self->combos); + for (v = 0; v < self->hdatac; v++ ) { + if (self->hdata[v]->flag.free ) { + aFree(self->hdata[v]->data); + } + aFree(self->hdata[v]); + } + if (self->hdata) + aFree(self->hdata); #if defined(DEBUG) // trash item memset(self, 0xDD, sizeof(struct item_data)); @@ -2327,6 +2369,7 @@ void itemdb_defaults(void) { itemdb->read_combos = itemdb_read_combos; itemdb->gendercheck = itemdb_gendercheck; itemdb->validate_entry = itemdb_validate_entry; + itemdb->readdb_additional_fields = itemdb_readdb_additional_fields; itemdb->readdb_sql_sub = itemdb_readdb_sql_sub; itemdb->readdb_libconfig_sub = itemdb_readdb_libconfig_sub; itemdb->readdb_libconfig = itemdb_readdb_libconfig; @@ -2337,4 +2380,6 @@ void itemdb_defaults(void) { itemdb->final_sub = itemdb_final_sub; itemdb->clear = itemdb_clear; itemdb->id2combo = itemdb_id2combo; + itemdb->is_item_usable = itemdb_is_item_usable; + itemdb->lookup_const = itemdb_lookup_const; } |