summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2013-11-14 02:55:33 +0100
committerHaru <haru@dotalux.com>2013-11-14 20:15:29 +0100
commitd3fe9bbfcde51c5bdc21512d46b7b8502422826c (patch)
tree32072ce8e36b41850d54438898fe9a9a83d88196 /src
parent091e235b78f83bd8c86c84e8b2db5ac9d5da98cd (diff)
downloadhercules-d3fe9bbfcde51c5bdc21512d46b7b8502422826c.tar.gz
hercules-d3fe9bbfcde51c5bdc21512d46b7b8502422826c.tar.bz2
hercules-d3fe9bbfcde51c5bdc21512d46b7b8502422826c.tar.xz
hercules-d3fe9bbfcde51c5bdc21512d46b7b8502422826c.zip
Added Inheritance support for item_db2
- If an item is marked as Inherit: true in item_db2, and it already exists, in item_db, then any unspecified fields are taken from the item_db entry rather than using their default values. - Special thanks to Ind. Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src')
-rw-r--r--src/map/itemdb.c61
1 files changed, 39 insertions, 22 deletions
diff --git a/src/map/itemdb.c b/src/map/itemdb.c
index f48ed8259..48b3dc837 100644
--- a/src/map/itemdb.c
+++ b/src/map/itemdb.c
@@ -1688,8 +1688,8 @@ int itemdb_readdb_libconfig_sub(config_setting_t *it, int n, const char *source)
struct item_data id = { 0 };
config_setting_t *t = NULL;
const char *str = NULL;
- uint32 ui32 = 0;
int i32 = 0;
+ bool inherit = false;
/*
* // Mandatory fields
@@ -1720,6 +1720,7 @@ int itemdb_readdb_libconfig_sub(config_setting_t *it, int n, const char *source)
* ">
* OnEquipScript: <" OnEquip Script ">
* OnUnequipScript: <" OnUnequip Script ">
+ * Inherit: inherit or override
*/
if( !config_setting_lookup_int(it, "Id", &i32) ) {
ShowWarning("itemdb_readdb_libconfig_sub: Invalid or missing id in \"%s\", entry #%d, skipping.\n", source, n);
@@ -1727,30 +1728,47 @@ int itemdb_readdb_libconfig_sub(config_setting_t *it, int n, const char *source)
}
id.nameid = (uint16)i32;
+ if( (t = config_setting_get_member(it, "Inherit")) && (inherit = config_setting_get_bool(t)) ) {
+ if( !itemdb->exists(id.nameid) ) {
+ ShowWarning("itemdb_readdb_libconfig_sub: Trying to inherit nonexistent item %d, default values will be used instead.\n", id.nameid);
+ inherit = false;
+ } else {
+ // Use old entry as default
+ struct item_data *old_entry = itemdb->load(id.nameid);
+ memcpy(&id, old_entry, sizeof(struct item_data));
+ }
+ }
+
if( !config_setting_lookup_string(it, "AegisName", &str) || !*str ) {
- ShowWarning("itemdb_readdb_libconfig_sub: Missing AegisName in item %d of \"%s\", skipping.\n", id.nameid, source);
- return 0;
+ if( !inherit ) {
+ ShowWarning("itemdb_readdb_libconfig_sub: Missing AegisName in item %d of \"%s\", skipping.\n", id.nameid, source);
+ return 0;
+ }
+ } else {
+ safestrncpy(id.name, str, sizeof(id.name));
}
- safestrncpy(id.name, str, sizeof(id.name));
if( !config_setting_lookup_string(it, "Name", &str) || !*str ) {
- ShowWarning("itemdb_readdb_libconfig_sub: Missing Name in item %d of \"%s\", skipping.\n", id.nameid, source);
- return 0;
+ if( !inherit ) {
+ ShowWarning("itemdb_readdb_libconfig_sub: Missing Name in item %d of \"%s\", skipping.\n", id.nameid, source);
+ return 0;
+ }
+ } else {
+ safestrncpy(id.jname, str, sizeof(id.jname));
}
- safestrncpy(id.jname, str, sizeof(id.jname));
if( config_setting_lookup_int(it, "Type", &i32) )
id.type = i32;
- else
+ else if( !inherit )
id.type = IT_UNKNOWN;
if( config_setting_lookup_int(it, "Buy", &i32) )
id.value_buy = i32;
- else
+ else if( !inherit )
id.value_buy = -1;
if( config_setting_lookup_int(it, "Sell", &i32) )
id.value_sell = i32;
- else
+ else if( !inherit )
id.value_sell = -1;
if( config_setting_lookup_int(it, "Weight", &i32) && i32 >= 0 )
@@ -1772,19 +1790,18 @@ int itemdb_readdb_libconfig_sub(config_setting_t *it, int n, const char *source)
id.slot = i32;
if( config_setting_lookup_int(it, "Job", &i32) ) // This is an unsigned value, do not check for >= 0
- ui32 = (unsigned int)i32;
- else
- ui32 = UINT_MAX;
- itemdb->jobid2mapid(id.class_base, ui32);
+ itemdb->jobid2mapid(id.class_base, (unsigned int)i32);
+ else if( !inherit )
+ itemdb->jobid2mapid(id.class_base, UINT_MAX);
if( config_setting_lookup_int(it, "Upper", &i32) && i32 >= 0 )
id.class_upper = (unsigned int)i32;
- else
+ else if( !inherit )
id.class_upper = ITEMUPPER_ALL;
if( config_setting_lookup_int(it, "Gender", &i32) && i32 >= 0 )
id.sex = i32;
- else
+ else if( !inherit )
id.sex = 2;
if( config_setting_lookup_int(it, "Loc", &i32) && i32 >= 0 )
@@ -1810,14 +1827,14 @@ int itemdb_readdb_libconfig_sub(config_setting_t *it, int n, const char *source)
if( config_setting_lookup_int(it, "View", &i32) && i32 >= 0 )
id.look = i32;
- if( config_setting_lookup_string(it, "Script", &str) && *str )
- id.script = script->parse(str, source, -id.nameid, SCRIPT_IGNORE_EXTERNAL_BRACKETS);
+ if( config_setting_lookup_string(it, "Script", &str) )
+ id.script = *str ? script->parse(str, source, -id.nameid, SCRIPT_IGNORE_EXTERNAL_BRACKETS) : NULL;
- if( config_setting_lookup_string(it, "OnEquipScript", &str) && *str )
- id.equip_script = script->parse(str, source, -id.nameid, SCRIPT_IGNORE_EXTERNAL_BRACKETS);
+ if( config_setting_lookup_string(it, "OnEquipScript", &str) )
+ id.equip_script = *str ? script->parse(str, source, -id.nameid, SCRIPT_IGNORE_EXTERNAL_BRACKETS) : NULL;
- if( config_setting_lookup_string(it, "OnUnequipScript", &str) && *str )
- id.unequip_script = script->parse(str, source, -id.nameid, SCRIPT_IGNORE_EXTERNAL_BRACKETS);
+ if( config_setting_lookup_string(it, "OnUnequipScript", &str) )
+ id.unequip_script = *str ? script->parse(str, source, -id.nameid, SCRIPT_IGNORE_EXTERNAL_BRACKETS) : NULL;
return itemdb->validate_entry(&id, n, source);
}