summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2017-08-21 20:41:17 +0200
committerHaru <haru@dotalux.com>2017-09-17 17:48:31 +0200
commitfd610efdb3cd8f1583a3918d54a679eb02ec76cd (patch)
treed5311f5103d1121dba214738071dc81b79e1a5f6 /src
parent015f2760dbfeb45132813830e4f5e1bda54f3eee (diff)
downloadhercules-fd610efdb3cd8f1583a3918d54a679eb02ec76cd.tar.gz
hercules-fd610efdb3cd8f1583a3918d54a679eb02ec76cd.tar.bz2
hercules-fd610efdb3cd8f1583a3918d54a679eb02ec76cd.tar.xz
hercules-fd610efdb3cd8f1583a3918d54a679eb02ec76cd.zip
Add support for parsing arrays of constants as bitmasks in the item_db
Fields marked as constant bitmasks will support the following syntaxes: Field: 10 // Decimal value Field: 0xA // Hexadecimal value Field: "FOO" // Constant Field: [2, 8] // Array of decimal values Field: [0x2, 0x8] // Array of hexadecimal values Field: ["FOO", "BAR"] // Array of constants Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src')
-rw-r--r--src/map/itemdb.c70
-rw-r--r--src/map/itemdb.h1
2 files changed, 64 insertions, 7 deletions
diff --git a/src/map/itemdb.c b/src/map/itemdb.c
index 40dd9ab4f..7a2c967fb 100644
--- a/src/map/itemdb.c
+++ b/src/map/itemdb.c
@@ -2224,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;
}
@@ -2664,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;
}
diff --git a/src/map/itemdb.h b/src/map/itemdb.h
index 8a1799fbd..980e8730e 100644
--- a/src/map/itemdb.h
+++ b/src/map/itemdb.h
@@ -647,6 +647,7 @@ struct itemdb_interface {
struct item_combo * (*id2combo) (unsigned short id);
bool (*is_item_usable) (struct item_data *item);
bool (*lookup_const) (const struct config_setting_t *it, const char *name, int *value);
+ bool (*lookup_const_mask) (const struct config_setting_t *it, const char *name, int *value);
};
#ifdef HERCULES_CORE