summaryrefslogtreecommitdiff
path: root/src/map
diff options
context:
space:
mode:
Diffstat (limited to 'src/map')
-rw-r--r--src/map/magic-expr.cpp18
-rw-r--r--src/map/magic-stmt.cpp19
-rw-r--r--src/map/script.cpp54
-rw-r--r--src/map/script.hpp6
4 files changed, 90 insertions, 7 deletions
diff --git a/src/map/magic-expr.cpp b/src/map/magic-expr.cpp
index 7343e50..1628395 100644
--- a/src/map/magic-expr.cpp
+++ b/src/map/magic-expr.cpp
@@ -1006,11 +1006,26 @@ int fun_read_script_int(dumb_ptr<env_t>, val_t *result, const_array<val_t> args)
{
dumb_ptr<block_list> subject_p = ARGENTITY(0);
VarName var_name = stringish<VarName>(ARGSTR(1));
+ int array_index = 0;
if (subject_p->bl_type != BL::PC)
return 1;
- RESULTINT = pc_readglobalreg(subject_p->is_player(), var_name);
+ RESULTINT = get_script_var_i(subject_p->is_player(), var_name, array_index);
+ return 0;
+}
+
+static
+int fun_read_script_str(dumb_ptr<env_t>, val_t *result, const_array<val_t> args)
+{
+ dumb_ptr<block_list> subject_p = ARGENTITY(0);
+ VarName var_name = stringish<VarName>(ARGSTR(1));
+ int array_index = 0;
+
+ if (subject_p->bl_type != BL::PC)
+ return 1;
+
+ RESULTSTR = dumb_string::copys(get_script_var_s(subject_p->is_player(), var_name, array_index));
return 0;
}
@@ -1280,6 +1295,7 @@ std::map<ZString, fun_t> functions =
MAGIC_FUNCTION1(anchor, "s", 'a'),
MAGIC_FUNCTION("random_location", "a", 'l', fun_pick_location),
MAGIC_FUNCTION("script_int", "es", 'i', fun_read_script_int),
+ MAGIC_FUNCTION("script_str", "es", 's', fun_read_script_str),
MAGIC_FUNCTION1(rbox, "li", 'a'),
MAGIC_FUNCTION1(count_item, "e.", 'i'),
MAGIC_FUNCTION1(line_of_sight, "ll", 'i'),
diff --git a/src/map/magic-stmt.cpp b/src/map/magic-stmt.cpp
index 1905871..7ca718b 100644
--- a/src/map/magic-stmt.cpp
+++ b/src/map/magic-stmt.cpp
@@ -825,12 +825,28 @@ static
int op_set_script_variable(dumb_ptr<env_t>, const_array<val_t> args)
{
dumb_ptr<map_session_data> c = (ENTITY_TYPE(0) == BL::PC) ? ARGPC(0) : NULL;
+ VarName varname = stringish<VarName>(ARGSTR(1));
+ int array_index = 0;
if (!c)
return 1;
+ set_script_var_i(c, varname, array_index, ARGINT(2));
+
+ return 0;
+}
+
+static
+int op_set_script_str(dumb_ptr<env_t>, const_array<val_t> args)
+{
+ dumb_ptr<map_session_data> c = (ENTITY_TYPE(0) == BL::PC) ? ARGPC(0) : NULL;
VarName varname = stringish<VarName>(ARGSTR(1));
- pc_setglobalreg(c, varname, ARGINT(2));
+ int array_index = 0;
+
+ if (!c)
+ return 1;
+
+ set_script_var_s(c, varname, array_index, ARGSTR(2));
return 0;
}
@@ -924,6 +940,7 @@ std::map<ZString, op_t> operations =
MAGIC_OPERATION1(injure, "eeii"),
MAGIC_OPERATION1(emote, "ei"),
MAGIC_OPERATION1(set_script_variable, "esi"),
+ MAGIC_OPERATION1(set_script_str, "ess"),
MAGIC_OPERATION1(set_hair_colour, "ei"),
MAGIC_OPERATION1(set_hair_style, "ei"),
MAGIC_OPERATION("drop_item", "l.ii", op_drop_item_for),
diff --git a/src/map/script.cpp b/src/map/script.cpp
index 5889d22..d13bb05 100644
--- a/src/map/script.cpp
+++ b/src/map/script.cpp
@@ -875,13 +875,11 @@ dumb_ptr<map_session_data> script_rid2sd(ScriptState *st)
*------------------------------------------
*/
static
-void get_val(ScriptState *st, struct script_data *data)
+void get_val(dumb_ptr<map_session_data> sd, struct script_data *data)
{
- dumb_ptr<map_session_data> sd = NULL;
-
if (data->type == ByteCode::PARAM_)
{
- if ((sd = script_rid2sd(st)) == NULL)
+ if (sd == NULL)
PRINTF("get_val error param SP::%d\n", data->u.reg.sp());
data->type = ByteCode::INT;
if (sd)
@@ -896,7 +894,7 @@ void get_val(ScriptState *st, struct script_data *data)
if (prefix != '$')
{
- if ((sd = script_rid2sd(st)) == NULL)
+ if (sd == NULL)
PRINTF("get_val error name?:%s\n", name);
}
if (postfix == '$')
@@ -954,6 +952,13 @@ void get_val(ScriptState *st, struct script_data *data)
}
}
+static __attribute__((deprecated))
+void get_val(ScriptState *st, struct script_data *data)
+{
+ dumb_ptr<map_session_data> sd = st->rid ? map_id2sd(st->rid) : nullptr;
+ get_val(sd, data);
+}
+
/*==========================================
* 変数の読み取り2
*------------------------------------------
@@ -4987,3 +4992,42 @@ BuiltinFunction builtin_functions[] =
BUILTIN(mapexit, ""),
{nullptr, ZString(), ZString()},
};
+
+void set_script_var_i(dumb_ptr<map_session_data> sd, VarName var, int e, int val)
+{
+ size_t k = variable_names.intern(var);
+ SIR reg = SIR::from(k, e);
+ set_reg(sd, ByteCode::INT, reg, val);
+}
+void set_script_var_s(dumb_ptr<map_session_data> sd, VarName var, int e, XString val)
+{
+ size_t k = variable_names.intern(var);
+ SIR reg = SIR::from(k, e);
+ set_reg(sd, ByteCode::INT, reg, dumb_string::copys(val));
+}
+int get_script_var_i(dumb_ptr<map_session_data> sd, VarName var, int e)
+{
+ size_t k = variable_names.intern(var);
+ SIR reg = SIR::from(k, e);
+ struct script_data dat;
+ dat.type = ByteCode::VARIABLE;
+ dat.u.reg = reg;
+ get_val(sd, &dat);
+ if (dat.type == ByteCode::INT)
+ return dat.u.numi;
+ PRINTF("Warning: you lied about the type and I'm too lazy to fix it!");
+ return 0;
+}
+ZString get_script_var_s(dumb_ptr<map_session_data> sd, VarName var, int e)
+{
+ size_t k = variable_names.intern(var);
+ SIR reg = SIR::from(k, e);
+ struct script_data dat;
+ dat.type = ByteCode::VARIABLE;
+ dat.u.reg = reg;
+ get_val(sd, &dat);
+ if (dat.type == ByteCode::CONSTSTR)
+ return dat.u.str;
+ PRINTF("Warning: you lied about the type and I can't fix it!");
+ return ZString();
+}
diff --git a/src/map/script.hpp b/src/map/script.hpp
index 22a079b..91ee6a5 100644
--- a/src/map/script.hpp
+++ b/src/map/script.hpp
@@ -169,4 +169,10 @@ extern int script_errors;
bool read_constdb(ZString filename);
+void set_script_var_i(dumb_ptr<map_session_data> sd, VarName var, int e, int val);
+void set_script_var_s(dumb_ptr<map_session_data> sd, VarName var, int e, XString val);
+
+int get_script_var_i(dumb_ptr<map_session_data> sd, VarName var, int e);
+ZString get_script_var_s(dumb_ptr<map_session_data> sd, VarName var, int e);
+
#endif // SCRIPT_HPP