summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorgumi <mekolat@users.noreply.github.com>2017-06-21 14:12:48 -0400
committergumi <mekolat@users.noreply.github.com>2017-06-21 14:13:46 -0400
commit8d3220163ef4bbdf9a94728f35971bccf6508439 (patch)
treea9da66bce2230aa188f25763fc2dd270722ca185 /src
parent2bf7d082116013cfdad031046f3ac0c932c3eb65 (diff)
downloadhercules-8d3220163ef4bbdf9a94728f35971bccf6508439.tar.gz
hercules-8d3220163ef4bbdf9a94728f35971bccf6508439.tar.bz2
hercules-8d3220163ef4bbdf9a94728f35971bccf6508439.tar.xz
hercules-8d3220163ef4bbdf9a94728f35971bccf6508439.zip
add getdatatype() buildin
Diffstat (limited to 'src')
-rw-r--r--src/map/script.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/map/script.c b/src/map/script.c
index 5bdda8512..2f411a1a4 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -16211,6 +16211,60 @@ BUILDIN(isstr)
return true;
}
+enum datatype {
+ DATATYPE_NIL = 1 << 7, // we don't start at 1, to leave room for primitives
+ DATATYPE_STR = 1 << 8,
+ DATATYPE_INT = 1 << 9,
+ DATATYPE_CONST = 1 << 10,
+ DATATYPE_PARAM = 1 << 11,
+ DATATYPE_VAR = 1 << 12,
+ DATATYPE_LABEL = 1 << 13,
+};
+
+BUILDIN(getdatatype) {
+ int type;
+
+ if (script_hasdata(st, 2)) {
+ struct script_data *data = script_getdata(st, 2);
+
+ if (data_isstring(data)) {
+ type = DATATYPE_STR;
+ if (data->type == C_CONSTSTR) {
+ type |= DATATYPE_CONST;
+ }
+ } else if (data_isint(data)) {
+ type = DATATYPE_INT;
+ } else if (data_islabel(data)) {
+ type = DATATYPE_LABEL;
+ } else if (data_isreference(data)) {
+ if (reference_toconstant(data)) {
+ type = DATATYPE_CONST | DATATYPE_INT;
+ } else if (reference_toparam(data)) {
+ type = DATATYPE_PARAM | DATATYPE_INT;
+ } else if (reference_tovariable(data)) {
+ type = DATATYPE_VAR;
+ if (is_string_variable(reference_getname(data))) {
+ type |= DATATYPE_STR;
+ } else {
+ type |= DATATYPE_INT;
+ }
+ } else {
+ ShowError("script:getdatatype: Unknown reference type!\n");
+ script->reportdata(data);
+ st->state = END;
+ return false;
+ }
+ } else {
+ type = data->type; // fallback to primitive type if unknown
+ }
+ } else {
+ type = DATATYPE_NIL; // nothing was passed
+ }
+
+ script_pushint(st, type);
+ return true;
+}
+
//=======================================================
// chr <int>
//-------------------------------------------------------
@@ -23652,6 +23706,7 @@ void script_parse_builtin(void) {
BUILDIN_DEF(charisalpha,"si"), //isalpha [Valaris]
BUILDIN_DEF(charat,"si"),
BUILDIN_DEF(isstr,"v"),
+ BUILDIN_DEF(getdatatype, "?"),
BUILDIN_DEF(chr,"i"),
BUILDIN_DEF(ord,"s"),
BUILDIN_DEF(setchar,"ssi"),
@@ -24125,6 +24180,15 @@ void script_hardcoded_constants(void)
script->set_constant("PERM_DISABLE_EXP", PC_PERM_DISABLE_EXP, false, false);
script->set_constant("PERM_DISABLE_SKILL_USAGE", PC_PERM_DISABLE_SKILL_USAGE, false, false);
+ script->constdb_comment("Data types");
+ script->set_constant("DATATYPE_NIL", DATATYPE_NIL, false, false);
+ script->set_constant("DATATYPE_STR", DATATYPE_STR, false, false);
+ script->set_constant("DATATYPE_INT", DATATYPE_INT, false, false);
+ script->set_constant("DATATYPE_CONST", DATATYPE_CONST, false, false);
+ script->set_constant("DATATYPE_PARAM", DATATYPE_PARAM, false, false);
+ script->set_constant("DATATYPE_VAR", DATATYPE_VAR, false, false);
+ script->set_constant("DATATYPE_LABEL", DATATYPE_LABEL, false, false);
+
script->constdb_comment("Renewal");
#ifdef RENEWAL
script->set_constant("RENEWAL", 1, false, false);