diff options
Diffstat (limited to 'src/map/script.cpp')
-rw-r--r-- | src/map/script.cpp | 912 |
1 files changed, 465 insertions, 447 deletions
diff --git a/src/map/script.cpp b/src/map/script.cpp index 93f9d31..0b2d05e 100644 --- a/src/map/script.cpp +++ b/src/map/script.cpp @@ -23,12 +23,11 @@ // along with this program. If not, see <http://www.gnu.org/licenses/>. #include <cassert> -#include <cctype> #include <cmath> #include <cstdlib> -#include <cstring> #include <ctime> +#include <algorithm> #include <set> #include "../compat/fun.hpp" @@ -38,6 +37,7 @@ #include "../strings/astring.hpp" #include "../strings/zstring.hpp" #include "../strings/xstring.hpp" +#include "../strings/literal.hpp" #include "../generic/db.hpp" #include "../generic/intern-pool.hpp" @@ -46,13 +46,15 @@ #include "../io/cxxstdio.hpp" #include "../io/lock.hpp" #include "../io/read.hpp" +#include "../io/write.hpp" + +#include "../net/socket.hpp" +#include "../net/timer.hpp" -#include "../mmo/config_parse.hpp" #include "../mmo/core.hpp" #include "../mmo/extract.hpp" -#include "../mmo/socket.hpp" +#include "../mmo/human_time_diff.hpp" #include "../mmo/utils.hpp" -#include "../mmo/timer.hpp" #include "atcommand.hpp" #include "battle.hpp" @@ -60,7 +62,7 @@ #include "clif.hpp" #include "intif.hpp" #include "itemdb.hpp" -#include "magic.hpp" +#include "magic-interpreter-base.hpp" #include "map.hpp" #include "mob.hpp" #include "npc.hpp" @@ -71,6 +73,9 @@ #include "../poison.hpp" + +namespace tmwa +{ constexpr bool DEBUG_DISP = false; constexpr bool DEBUG_RUN = false; @@ -93,8 +98,8 @@ static Map<SIR, RString> mapregstr_db; static int mapreg_dirty = -1; -AString mapreg_txt = "save/mapreg.txt"; -constexpr std::chrono::milliseconds MAPREG_AUTOSAVE_INTERVAL = std::chrono::seconds(10); +AString mapreg_txt = "save/mapreg.txt"_s; +constexpr std::chrono::milliseconds MAPREG_AUTOSAVE_INTERVAL = 10_s; Map<ScriptLabel, int> scriptlabel_db; static @@ -102,19 +107,19 @@ std::set<ScriptLabel> probable_labels; UPMap<RString, const ScriptBuffer> userfunc_db; static -Array<ZString, 11> pos_str //= +Array<LString, 11> pos_str //= {{ - ZString("Head"), - ZString("Body"), - ZString("Left hand"), - ZString("Right hand"), - ZString("Robe"), - ZString("Shoes"), - ZString("Accessory 1"), - ZString("Accessory 2"), - ZString("Head 2"), - ZString("Head 3"), - ZString("Not Equipped"), + "Head"_s, + "Body"_s, + "Left hand"_s, + "Right hand"_s, + "Robe"_s, + "Shoes"_s, + "Accessory 1"_s, + "Accessory 2"_s, + "Head 2"_s, + "Head 3"_s, + "Not Equipped"_s, }}; static @@ -150,8 +155,9 @@ void mapreg_setregstr(SIR num, XString str); struct BuiltinFunction { void (*func)(ScriptState *); - ZString name; - ZString arg; + LString name; + LString arg; + char ret; }; // defined later extern BuiltinFunction builtin_functions[]; @@ -382,15 +388,15 @@ void disp_error_message(ZString mes, ZString::iterator pos_) ZString::iterator lineend = std::find(p, startptr.end(), '\n'); if (pos_ < lineend) { - PRINTF("\n%s\nline %d : ", mes, line); + PRINTF("\n%s\nline %d : "_fmt, mes, line); for (int i = 0; linestart + i != lineend; i++) { if (linestart + i != pos_) - PRINTF("%c", linestart[i]); + PRINTF("%c"_fmt, linestart[i]); else - PRINTF("\'%c\'", linestart[i]); + PRINTF("\'%c\'"_fmt, linestart[i]); } - PRINTF("\a\n"); + PRINTF("\a\n"_fmt); return; } p = lineend + 1; @@ -407,7 +413,7 @@ ZString::iterator ScriptBuffer::parse_simpleexpr(ZString::iterator p) if (*p == ';' || *p == ',') { - disp_error_message("unexpected expr end", p); + disp_error_message("unexpected expr end"_s, p); exit(1); } if (*p == '(') @@ -417,7 +423,7 @@ ZString::iterator ScriptBuffer::parse_simpleexpr(ZString::iterator p) p = skip_space(p); if ((*p++) != ')') { - disp_error_message("unmatch ')'", p); + disp_error_message("unmatch ')'"_s, p); exit(1); } } @@ -438,14 +444,14 @@ ZString::iterator ScriptBuffer::parse_simpleexpr(ZString::iterator p) p++; else if (*p == '\n') { - disp_error_message("unexpected newline @ string", p); + disp_error_message("unexpected newline @ string"_s, p); exit(1); } add_scriptb(*p++); } if (!*p) { - disp_error_message("unexpected eof @ string", p); + disp_error_message("unexpected eof @ string"_s, p); exit(1); } add_scriptb(0); @@ -457,35 +463,35 @@ ZString::iterator ScriptBuffer::parse_simpleexpr(ZString::iterator p) ZString::iterator p2 = skip_word(p); if (p2 == p) { - disp_error_message("unexpected character", p); + disp_error_message("unexpected character"_s, p); exit(1); } XString word(&*p, &*p2, nullptr); - if (word.startswith("On") || word.startswith("L_") || word.startswith("S_")) + if (word.startswith("On"_s) || word.startswith("L_"_s) || word.startswith("S_"_s)) probable_labels.insert(stringish<ScriptLabel>(word)); - if (parse_cmd_if && (word == "callsub" || word == "callfunc" || word == "return")) + if (parse_cmd_if && (word == "callsub"_s || word == "callfunc"_s || word == "return"_s)) { - disp_error_message("Sorry, callsub/callfunc/return have never worked properly in an if statement.", p); + disp_error_message("Sorry, callsub/callfunc/return have never worked properly in an if statement."_s, p); } str_data_t *ld = add_strp(word); parse_cmdp = ld; // warn_*_mismatch_paramnumのために必要 - // why not just check l->str == "if" or std::string(p, p2) == "if"? - if (ld == search_strp("if")) // warn_cmd_no_commaのために必要 + // why not just check l->str == "if"_s or std::string(p, p2) == "if"_s? + if (ld == search_strp("if"_s)) // warn_cmd_no_commaのために必要 parse_cmd_if++; p = p2; if (ld->type != ByteCode::FUNC_ && *p == '[') { // array(name[i] => getelementofarray(name,i) ) - add_scriptl(search_strp("getelementofarray")); + add_scriptl(search_strp("getelementofarray"_s)); add_scriptc(ByteCode::ARG); add_scriptl(ld); p = parse_subexpr(p + 1, -1); p = skip_space(p); if (*p != ']') { - disp_error_message("unmatch ']'", p); + disp_error_message("unmatch ']'"_s, p); exit(1); } p++; @@ -515,7 +521,7 @@ ZString::iterator ScriptBuffer::parse_subexpr(ZString::iterator p, int limit) ZString::iterator tmpp = skip_space(p + 1); if (*tmpp == ';' || *tmpp == ',') { - --script_errors; disp_error_message("deprecated: implicit 'next statement' label", p); + --script_errors; disp_error_message("deprecated: implicit 'next statement' label"_s, p); add_scriptl(&LABEL_NEXTLINE_); p++; return p; @@ -560,7 +566,7 @@ ZString::iterator ScriptBuffer::parse_subexpr(ZString::iterator p, int limit) if (funcp->type != ByteCode::FUNC_) { - disp_error_message("expect function", tmpp); + disp_error_message("expect function"_s, tmpp); exit(0); } @@ -574,7 +580,7 @@ ZString::iterator ScriptBuffer::parse_subexpr(ZString::iterator p, int limit) p++; else if (*p != ')' && script_config.warn_func_no_comma) { - disp_error_message("expect ',' or ')' at func params", + disp_error_message("expect ',' or ')' at func params"_s, p); } p = skip_space(p); @@ -583,7 +589,7 @@ ZString::iterator ScriptBuffer::parse_subexpr(ZString::iterator p, int limit) plist[i] = p; if (*p != ')') { - disp_error_message("func request '(' ')'", p); + disp_error_message("func request '(' ')'"_s, p); exit(1); } p++; @@ -593,14 +599,19 @@ ZString::iterator ScriptBuffer::parse_subexpr(ZString::iterator p, int limit) { ZString arg = builtin_functions[funcp->val].arg; int j = 0; + // TODO handle ? and multiple * correctly for (j = 0; arg[j]; j++) - if (arg[j] == '*') + if (arg[j] == '*' || arg[j] == '?') break; - if ((arg[j] == 0 && i != j) || (arg[j] == '*' && i < j)) + if ((arg[j] == 0 && i != j) || ((arg[j] == '*' || arg[j] == '?') && i < j)) { - disp_error_message("illegal number of parameters", + disp_error_message("illegal number of parameters"_s, plist[std::min(i, j)]); } + if (!builtin_functions[funcp->val].ret) + { + disp_error_message("statement in function context"_s, tmpp); + } } } else // not op == ByteCode::FUNC @@ -627,7 +638,7 @@ ZString::iterator ScriptBuffer::parse_expr(ZString::iterator p) case '[': case ']': case '}': - disp_error_message("unexpected char", p); + disp_error_message("unexpected char"_s, p); exit(1); } p = parse_subexpr(p, -1); @@ -657,21 +668,22 @@ ZString::iterator ScriptBuffer::parse_line(ZString::iterator p, bool *can_step) str_data_t *cmd = parse_cmdp; if (cmd->type != ByteCode::FUNC_) { - disp_error_message("expect command", p2); + disp_error_message("expect command"_s, p2); // exit(0); } { + // TODO should be LString, but no heterogenous lookup yet static std::set<ZString> terminators = { - "goto", - "return", - "close", - "menu", - "end", - "mapexit", - "shop", + "goto"_s, + "return"_s, + "close"_s, + "menu"_s, + "end"_s, + "mapexit"_s, + "shop"_s, }; *can_step = terminators.count(cmd->strs) == 0; } @@ -689,7 +701,7 @@ ZString::iterator ScriptBuffer::parse_line(ZString::iterator p, bool *can_step) else if (*p != ';' && script_config.warn_cmd_no_comma && parse_cmd_if * 2 <= i) { - disp_error_message("expect ',' or ';' at cmd params", p); + disp_error_message("expect ',' or ';' at cmd params"_s, p); } p = skip_space(p); i++; @@ -697,7 +709,7 @@ ZString::iterator ScriptBuffer::parse_line(ZString::iterator p, bool *can_step) plist[i] = p; if (*(p++) != ';') { - disp_error_message("need ';'", p); + disp_error_message("need ';'"_s, p); exit(1); } add_scriptc(ByteCode::FUNC_); @@ -707,14 +719,19 @@ ZString::iterator ScriptBuffer::parse_line(ZString::iterator p, bool *can_step) { ZString arg = builtin_functions[cmd->val].arg; int j = 0; + // TODO see above for (j = 0; arg[j]; j++) - if (arg[j] == '*') + if (arg[j] == '*' || arg[j] == '?') break; - if ((arg[j] == 0 && i != j) || (arg[j] == '*' && i < j)) + if ((arg[j] == 0 && i != j) || ((arg[j] == '*' || arg[j] == '?') && i < j)) { - disp_error_message("illegal number of parameters", + disp_error_message("illegal number of parameters"_s, plist[std::min(i, j)]); } + if (builtin_functions[cmd->val].ret) + { + disp_error_message("function in statement context"_s, p2); + } } return p; @@ -740,24 +757,50 @@ bool read_constdb(ZString filename) io::ReadFile in(filename); if (!in.is_open()) { - PRINTF("can't read %s\n", filename); + PRINTF("can't read %s\n"_fmt, filename); return false; } bool rv = true; - AString line; - while (in.getline(line)) - { - if (is_comment(line)) + AString line_; + while (in.getline(line_)) + { + // is_comment only works for whole-line comments + // that could change once the Z dependency is dropped ... + LString comment = "//"_s; + XString line = line_.xislice_h(std::search(line_.begin(), line_.end(), comment.begin(), comment.end())).rstrip(); + if (!line) continue; + // "%m[A-Za-z0-9_] %i %i" + + // TODO promote either qsplit() or asplit() + auto _it = std::find(line.begin(), line.end(), ' '); + auto name = line.xislice_h(_it); + auto _rest = line.xislice_t(_it); + while (_rest.startswith(' ')) + _rest = _rest.xslice_t(1); + auto _it2 = std::find(_rest.begin(), _rest.end(), ' '); + auto val_ = _rest.xislice_h(_it2); + auto type_ = _rest.xislice_t(_it2); + while (type_.startswith(' ')) + type_ = type_.xslice_t(1); + // yes, the above actually DTRT even for underlength input - AString name; int val; - int type = 0; // if not provided - // TODO get rid of SSCANF - this is the last serious use - if (SSCANF(line, "%m[A-Za-z0-9_] %i %i", &name, &val, &type) < 2) + int type = 0; + // Note for future archeaologists: this code is indented correctly + if (std::find_if_not(name.begin(), name.end(), + [](char c) + { + return ('0' <= c && c <= '9') + || ('A' <= c && c <= 'Z') + || ('a' <= c && c <= 'z') + || (c == '_'); + }) != name.end() + || !extract(val_, &val) + || (!extract(type_, &type) && type_)) { - PRINTF("Bad const line: %s\n", line); + PRINTF("Bad const line: %s\n"_fmt, line_); rv = false; continue; } @@ -815,7 +858,7 @@ void ScriptBuffer::parse_script(ZString src, int line, bool implicit_end) p = skip_space(p); if (*p != '{') { - disp_error_message("not found '{'", p); + disp_error_message("not found '{'"_s, p); abort(); } for (p++; *p && *p != '}';) @@ -825,7 +868,7 @@ void ScriptBuffer::parse_script(ZString src, int line, bool implicit_end) { if (can_step) { - --script_errors; disp_error_message("deprecated: implicit fallthrough", p); + --script_errors; disp_error_message("deprecated: implicit fallthrough"_s, p); } can_step = true; @@ -838,7 +881,7 @@ void ScriptBuffer::parse_script(ZString src, int line, bool implicit_end) assert (e1 == e2 && e2 == e3); if (e3) { - disp_error_message("dup label ", p); + disp_error_message("dup label "_s, p); exit(1); } set_label(ld, script_buf.size()); @@ -849,7 +892,7 @@ void ScriptBuffer::parse_script(ZString src, int line, bool implicit_end) if (!can_step) { - --script_errors; disp_error_message("deprecated: unreachable statement", p); + --script_errors; disp_error_message("deprecated: unreachable statement"_s, p); } // 他は全部一緒くた p = parse_line(p, &can_step); @@ -864,7 +907,7 @@ void ScriptBuffer::parse_script(ZString src, int line, bool implicit_end) if (can_step && !implicit_end) { - --script_errors; disp_error_message("deprecated: implicit end", p); + --script_errors; disp_error_message("deprecated: implicit end"_s, p); } add_scriptc(ByteCode::NOP); @@ -893,17 +936,17 @@ void ScriptBuffer::parse_script(ZString src, int line, bool implicit_end) for (const auto& pair : scriptlabel_db) { ScriptLabel key = pair.first; - if (key.startswith("On")) + if (key.startswith("On"_s)) continue; - if (!(key.startswith("L_") || key.startswith("S_"))) - PRINTF("Warning: ugly label: %s\n", key); + if (!(key.startswith("L_"_s) || key.startswith("S_"_s))) + PRINTF("Warning: ugly label: %s\n"_fmt, key); else if (!probable_labels.count(key)) - PRINTF("Warning: unused label: %s\n", key); + PRINTF("Warning: unused label: %s\n"_fmt, key); } for (ScriptLabel used : probable_labels) { if (!scriptlabel_db.search(used)) - PRINTF("Warning: no such label: %s\n", used); + PRINTF("Warning: no such label: %s\n"_fmt, used); } probable_labels.clear(); @@ -912,12 +955,12 @@ void ScriptBuffer::parse_script(ZString src, int line, bool implicit_end) for (size_t i = 0; i < script_buf.size(); i++) { if ((i & 15) == 0) - PRINTF("%04zx : ", i); - PRINTF("%02x ", script_buf[i]); + PRINTF("%04zx : "_fmt, i); + PRINTF("%02x "_fmt, script_buf[i]); if ((i & 15) == 15) - PRINTF("\n"); + PRINTF("\n"_fmt); } - PRINTF("\n"); + PRINTF("\n"_fmt); } // @@ -943,7 +986,7 @@ dumb_ptr<map_session_data> script_rid2sd(ScriptState *st) dumb_ptr<map_session_data> sd = map_id2sd(st->rid); if (!sd) { - PRINTF("script_rid2sd: fatal error ! player not attached!\n"); + PRINTF("script_rid2sd: fatal error ! player not attached!\n"_fmt); } return sd; } @@ -957,8 +1000,8 @@ void get_val(dumb_ptr<map_session_data> sd, struct script_data *data) { if (data->type == ByteCode::PARAM_) { - if (sd == NULL) - PRINTF("get_val error param SP::%d\n", data->u.reg.sp()); + if (sd == nullptr) + PRINTF("get_val error param SP::%d\n"_fmt, data->u.reg.sp()); data->type = ByteCode::INT; if (sd) data->u.numi = pc_readparam(sd, data->u.reg.sp()); @@ -972,8 +1015,8 @@ void get_val(dumb_ptr<map_session_data> sd, struct script_data *data) if (prefix != '$') { - if (sd == NULL) - PRINTF("get_val error name?:%s\n", name); + if (sd == nullptr) + PRINTF("get_val error name?:%s\n"_fmt, name); } if (postfix == '$') { @@ -990,11 +1033,11 @@ void get_val(dumb_ptr<map_session_data> sd, struct script_data *data) } else { - PRINTF("script: get_val: illegal scope string variable.\n"); - data->u.str = dumb_string::fake("!!ERROR!!"); + PRINTF("script: get_val: illegal scope string variable.\n"_fmt); + data->u.str = dumb_string::fake("!!ERROR!!"_s); } if (!data->u.str) - data->u.str = dumb_string::fake(""); + data->u.str = dumb_string::fake(""_s); } else { @@ -1085,7 +1128,7 @@ void set_reg(dumb_ptr<map_session_data> sd, ByteCode type, SIR reg, struct scrip } else { - PRINTF("script: set_reg: illegal scope string variable !"); + PRINTF("script: set_reg: illegal scope string variable !"_fmt); } } else @@ -1143,7 +1186,7 @@ dumb_string conv_str(ScriptState *st, struct script_data *data) assert (data->type != ByteCode::RETINFO); if (data->type == ByteCode::INT) { - AString buf = STRPRINTF("%d", data->u.numi); + AString buf = STRPRINTF("%d"_fmt, data->u.numi); data->type = ByteCode::STR; data->u.str = dumb_string::copys(buf); } @@ -1285,7 +1328,7 @@ void builtin_goto(ScriptState *st) { if (AARGO2(2).type != ByteCode::POS) { - PRINTF("script: goto: not label !\n"); + PRINTF("script: goto: not label !\n"_fmt); st->state = ScriptEndState::END; return; } @@ -1324,7 +1367,7 @@ void builtin_callfunc(ScriptState *st) } else { - PRINTF("script:callfunc: function not found! [%s]\n", str); + PRINTF("script:callfunc: function not found! [%s]\n"_fmt, str); st->state = ScriptEndState::END; } } @@ -1442,7 +1485,7 @@ void builtin_menu(ScriptState *st) // not just the displayed number that ends with the "". // (Would it be better to pop the stack before rerunning?) int menu_choices = (st->end - (st->start + 2)) / 2; - pc_setreg(sd, SIR::from(variable_names.intern("@menu")), sd->npc_menu); + pc_setreg(sd, SIR::from(variable_names.intern("@menu"_s)), sd->npc_menu); sd->state.menu_or_input = 0; if (sd->npc_menu > 0 && sd->npc_menu <= menu_choices) { @@ -1481,23 +1524,6 @@ void builtin_rand(ScriptState *st) } /*========================================== - * - *------------------------------------------ - */ -static -void builtin_pow(ScriptState *st) -{ - int a, b; - - a = conv_num(st, &AARGO2(2)); - b = conv_num(st, &AARGO2(3)); - -#warning "This is silly" - push_int(st->stack, ByteCode::INT, static_cast<int>(pow(a * 0.001, b))); - -} - -/*========================================== * Check whether the PC is at the specified location *------------------------------------------ */ @@ -1532,9 +1558,9 @@ void builtin_warp(ScriptState *st) MapName str = stringish<MapName>(ZString(conv_str(st, &AARGO2(2)))); x = conv_num(st, &AARGO2(3)); y = conv_num(st, &AARGO2(4)); - if (str == "Random") + if (str == "Random"_s) pc_randomwarp(sd, BeingRemoveWhy::WARPED); - else if (str == "SavePoint" or str == "Save") + else if (str == "SavePoint"_s or str == "Save"_s) { if (sd->bl_m->flag.get(MapFlag::NORETURN)) return; @@ -1554,7 +1580,7 @@ static void builtin_areawarp_sub(dumb_ptr<block_list> bl, MapName mapname, int x, int y) { dumb_ptr<map_session_data> sd = bl->is_player(); - if (mapname == "Random") + if (mapname == "Random"_s) pc_randomwarp(sd, BeingRemoveWhy::WARPED); else pc_setpos(sd, mapname, x, y, BeingRemoveWhy::GONE); @@ -1635,7 +1661,7 @@ void builtin_percentheal(ScriptState *st) static void builtin_input(ScriptState *st) { - dumb_ptr<map_session_data> sd = NULL; + dumb_ptr<map_session_data> sd = nullptr; script_data& scrd = AARGO2(2); ByteCode type = scrd.type; assert (type == ByteCode::VARIABLE); @@ -1712,7 +1738,7 @@ void builtin_if (ScriptState *st) static void builtin_set(ScriptState *st) { - dumb_ptr<map_session_data> sd = NULL; + dumb_ptr<map_session_data> sd = nullptr; SIR reg = AARGO2(2).u.reg; if (AARGO2(2).type == ByteCode::PARAM_) { @@ -1753,7 +1779,7 @@ void builtin_set(ScriptState *st) static void builtin_setarray(ScriptState *st) { - dumb_ptr<map_session_data> sd = NULL; + dumb_ptr<map_session_data> sd = nullptr; assert (AARGO2(2).type == ByteCode::VARIABLE); SIR reg = AARGO2(2).u.reg; ZString name = variable_names.outtern(reg.base()); @@ -1762,7 +1788,7 @@ void builtin_setarray(ScriptState *st) if (prefix != '$' && prefix != '@') { - PRINTF("builtin_setarray: illegal scope !\n"); + PRINTF("builtin_setarray: illegal scope !\n"_fmt); return; } if (prefix != '$') @@ -1784,7 +1810,7 @@ void builtin_setarray(ScriptState *st) static void builtin_cleararray(ScriptState *st) { - dumb_ptr<map_session_data> sd = NULL; + dumb_ptr<map_session_data> sd = nullptr; assert (AARGO2(2).type == ByteCode::VARIABLE); SIR reg = AARGO2(2).u.reg; ZString name = variable_names.outtern(reg.base()); @@ -1794,7 +1820,7 @@ void builtin_cleararray(ScriptState *st) if (prefix != '$' && prefix != '@') { - PRINTF("builtin_cleararray: illegal scope !\n"); + PRINTF("builtin_cleararray: illegal scope !\n"_fmt); return; } if (prefix != '$') @@ -1839,7 +1865,7 @@ void builtin_getarraysize(ScriptState *st) if (prefix != '$' && prefix != '@') { - PRINTF("builtin_copyarray: illegal scope !\n"); + PRINTF("builtin_copyarray: illegal scope !\n"_fmt); return; } @@ -1858,8 +1884,8 @@ void builtin_getelementofarray(ScriptState *st) int i = conv_num(st, &AARGO2(3)); if (i > 255 || i < 0) { - PRINTF("script: getelementofarray (operator[]): param2 illegal number %d\n", - i); + PRINTF("script: getelementofarray (operator[]): param2 illegal number %d\n"_fmt, + i); push_int(st->stack, ByteCode::INT, 0); } else @@ -1870,7 +1896,7 @@ void builtin_getelementofarray(ScriptState *st) } else { - PRINTF("script: getelementofarray (operator[]): param1 not name !\n"); + PRINTF("script: getelementofarray (operator[]): param1 not name !\n"_fmt); push_int(st->stack, ByteCode::INT, 0); } } @@ -1896,7 +1922,8 @@ void builtin_setlook(ScriptState *st) static void builtin_countitem(ScriptState *st) { - int nameid = 0, count = 0, i; + ItemNameId nameid; + int count = 0; dumb_ptr<map_session_data> sd; struct script_data *data; @@ -1909,22 +1936,24 @@ void builtin_countitem(ScriptState *st) { ZString name = ZString(conv_str(st, data)); struct item_data *item_data = itemdb_searchname(name); - if (item_data != NULL) + if (item_data != nullptr) nameid = item_data->nameid; } else - nameid = conv_num(st, data); + nameid = wrap<ItemNameId>(conv_num(st, data)); - if (nameid >= 500) //if no such ID then skip this iteration - for (i = 0; i < MAX_INVENTORY; i++) + if (nameid) + { + for (IOff0 i : IOff0::iter()) { if (sd->status.inventory[i].nameid == nameid) count += sd->status.inventory[i].amount; } + } else { if (battle_config.error_log) - PRINTF("wrong item ID : countitem (%i)\n", nameid); + PRINTF("wrong item ID : countitem (%i)\n"_fmt, nameid); } push_int(st->stack, ByteCode::INT, count); @@ -1937,7 +1966,8 @@ void builtin_countitem(ScriptState *st) static void builtin_checkweight(ScriptState *st) { - int nameid = 0, amount; + ItemNameId nameid; + int amount; dumb_ptr<map_session_data> sd; struct script_data *data; @@ -1953,10 +1983,10 @@ void builtin_checkweight(ScriptState *st) nameid = item_data->nameid; } else - nameid = conv_num(st, data); + nameid = wrap<ItemNameId>(conv_num(st, data)); amount = conv_num(st, &AARGO2(3)); - if (amount <= 0 || nameid < 500) + if (amount <= 0 || !nameid) { //if get wrong item ID or amount<=0, don't count weight of non existing items push_int(st->stack, ByteCode::INT, 0); @@ -1981,7 +2011,8 @@ void builtin_checkweight(ScriptState *st) static void builtin_getitem(ScriptState *st) { - int nameid, amount; + ItemNameId nameid; + int amount; dumb_ptr<map_session_data> sd; struct script_data *data; @@ -1993,12 +2024,11 @@ void builtin_getitem(ScriptState *st) { ZString name = ZString(conv_str(st, data)); struct item_data *item_data = itemdb_searchname(name); - nameid = 727; //Default to iten - if (item_data != NULL) + if (item_data != nullptr) nameid = item_data->nameid; } else - nameid = conv_num(st, data); + nameid = wrap<ItemNameId>(conv_num(st, data)); if ((amount = conv_num(st, &AARGO2(3))) <= 0) @@ -2006,21 +2036,21 @@ void builtin_getitem(ScriptState *st) return; //return if amount <=0, skip the useles iteration } - if (nameid > 0) + if (nameid) { - struct item item_tmp {}; + Item item_tmp {}; item_tmp.nameid = nameid; if (HARGO2(5)) //アイテムを指定したIDに渡す - sd = map_id2sd(conv_num(st, &AARGO2(5))); - if (sd == NULL) //アイテムを渡す相手がいなかったらお帰り + sd = map_id2sd(wrap<BlockId>(conv_num(st, &AARGO2(5)))); + if (sd == nullptr) //アイテムを渡す相手がいなかったらお帰り return; PickupFail flag; if ((flag = pc_additem(sd, &item_tmp, amount)) != PickupFail::OKAY) { - clif_additem(sd, 0, 0, flag); + clif_additem(sd, IOff0::from(0), 0, flag); map_addflooritem(&item_tmp, amount, sd->bl_m, sd->bl_x, sd->bl_y, - NULL, NULL, NULL); + nullptr, nullptr, nullptr); } } @@ -2033,7 +2063,8 @@ void builtin_getitem(ScriptState *st) static void builtin_makeitem(ScriptState *st) { - int nameid, amount; + ItemNameId nameid; + int amount; int x, y; dumb_ptr<map_session_data> sd; struct script_data *data; @@ -2046,12 +2077,11 @@ void builtin_makeitem(ScriptState *st) { ZString name = ZString(conv_str(st, data)); struct item_data *item_data = itemdb_searchname(name); - nameid = 512; //Apple Item ID if (item_data) nameid = item_data->nameid; } else - nameid = conv_num(st, data); + nameid = wrap<ItemNameId>(conv_num(st, data)); amount = conv_num(st, &AARGO2(3)); MapName mapname = stringish<MapName>(ZString(conv_str(st, &AARGO2(4)))); @@ -2064,12 +2094,12 @@ void builtin_makeitem(ScriptState *st) else m = map_mapname2mapid(mapname); - if (nameid > 0) + if (nameid) { - struct item item_tmp {}; + Item item_tmp {}; item_tmp.nameid = nameid; - map_addflooritem(&item_tmp, amount, m, x, y, NULL, NULL, NULL); + map_addflooritem(&item_tmp, amount, m, x, y, nullptr, nullptr, nullptr); } } @@ -2080,7 +2110,8 @@ void builtin_makeitem(ScriptState *st) static void builtin_delitem(ScriptState *st) { - int nameid = 0, amount, i; + ItemNameId nameid; + int amount; dumb_ptr<map_session_data> sd; struct script_data *data; @@ -2092,31 +2123,21 @@ void builtin_delitem(ScriptState *st) { ZString name = ZString(conv_str(st, data)); struct item_data *item_data = itemdb_searchname(name); - //nameid=512; if (item_data) nameid = item_data->nameid; } else - nameid = conv_num(st, data); + nameid = wrap<ItemNameId>(conv_num(st, data)); amount = conv_num(st, &AARGO2(3)); - if (nameid < 500 || amount <= 0) + if (!nameid || amount <= 0) { //by Lupus. Don't run FOR if u got wrong item ID or amount<=0 - //PRINTF("wrong item ID or amount<=0 : delitem %i,\n",nameid,amount); return; } - for (i = 0; i < MAX_INVENTORY; i++) - { - if (sd->status.inventory[i].nameid <= 0 - || sd->inventory_data[i] == NULL - || sd->inventory_data[i]->type != ItemType::_7 - || sd->status.inventory[i].amount <= 0) - continue; - } - for (i = 0; i < MAX_INVENTORY; i++) + for (IOff0 i : IOff0::iter()) { if (sd->status.inventory[i].nameid == nameid) { @@ -2153,7 +2174,7 @@ void builtin_readparam(ScriptState *st) else sd = script_rid2sd(st); - if (sd == NULL) + if (sd == nullptr) { push_int(st->stack, ByteCode::INT, -1); return; @@ -2178,19 +2199,19 @@ void builtin_getcharid(ScriptState *st) sd = map_nick2sd(stringish<CharName>(ZString(conv_str(st, &AARGO2(3))))); else sd = script_rid2sd(st); - if (sd == NULL) + if (sd == nullptr) { push_int(st->stack, ByteCode::INT, -1); return; } if (num == 0) - push_int(st->stack, ByteCode::INT, sd->status_key.char_id); + push_int(st->stack, ByteCode::INT, unwrap<CharId>(sd->status_key.char_id)); if (num == 1) - push_int(st->stack, ByteCode::INT, sd->status.party_id); + push_int(st->stack, ByteCode::INT, unwrap<PartyId>(sd->status.party_id)); if (num == 2) push_int(st->stack, ByteCode::INT, 0/*guild_id*/); if (num == 3) - push_int(st->stack, ByteCode::INT, sd->status_key.account_id); + push_int(st->stack, ByteCode::INT, unwrap<AccountId>(sd->status_key.account_id)); } /*========================================== @@ -2198,9 +2219,9 @@ void builtin_getcharid(ScriptState *st) *------------------------------------------ */ static -dumb_string builtin_getpartyname_sub(int party_id) +dumb_string builtin_getpartyname_sub(PartyId party_id) { - struct party *p = party_search(party_id); + PartyPair p = party_search(party_id); if (p) return dumb_string::copys(p->name); @@ -2231,12 +2252,12 @@ void builtin_strcharinfo(ScriptState *st) if (buf) push_str(st->stack, ByteCode::STR, buf); else - push_str(st->stack, ByteCode::CONSTSTR, dumb_string::fake("")); + push_str(st->stack, ByteCode::CONSTSTR, dumb_string::fake(""_s)); } if (num == 2) { // was: guild name - push_str(st->stack, ByteCode::CONSTSTR, dumb_string::fake("")); + push_str(st->stack, ByteCode::CONSTSTR, dumb_string::fake(""_s)); } } @@ -2266,23 +2287,23 @@ Array<EPOS, 11> equip //= static void builtin_getequipid(ScriptState *st) { - int i, num; + int num; dumb_ptr<map_session_data> sd; struct item_data *item; sd = script_rid2sd(st); - if (sd == NULL) + if (sd == nullptr) { - PRINTF("getequipid: sd == NULL\n"); + PRINTF("getequipid: sd == nullptr\n"_fmt); return; } num = conv_num(st, &AARGO2(2)); - i = pc_checkequip(sd, equip[num - 1]); - if (i >= 0) + IOff0 i = pc_checkequip(sd, equip[num - 1]); + if (i.ok()) { item = sd->inventory_data[i]; if (item) - push_int(st->stack, ByteCode::INT, item->nameid); + push_int(st->stack, ByteCode::INT, unwrap<ItemNameId>(item->nameid)); else push_int(st->stack, ByteCode::INT, 0); } @@ -2299,7 +2320,7 @@ void builtin_getequipid(ScriptState *st) static void builtin_getequipname(ScriptState *st) { - int i, num; + int num; dumb_ptr<map_session_data> sd; struct item_data *item; @@ -2307,18 +2328,18 @@ void builtin_getequipname(ScriptState *st) sd = script_rid2sd(st); num = conv_num(st, &AARGO2(2)); - i = pc_checkequip(sd, equip[num - 1]); - if (i >= 0) + IOff0 i = pc_checkequip(sd, equip[num - 1]); + if (i.ok()) { item = sd->inventory_data[i]; if (item) - buf = STRPRINTF("%s-[%s]", pos_str[num - 1], item->jname); + buf = STRPRINTF("%s-[%s]"_fmt, pos_str[num - 1], item->jname); else - buf = STRPRINTF("%s-[%s]", pos_str[num - 1], pos_str[10]); + buf = STRPRINTF("%s-[%s]"_fmt, pos_str[num - 1], pos_str[10]); } else { - buf = STRPRINTF("%s-[%s]", pos_str[num - 1], pos_str[10]); + buf = STRPRINTF("%s-[%s]"_fmt, pos_str[num - 1], pos_str[10]); } push_str(st->stack, ByteCode::STR, dumb_string::copys(buf)); @@ -2423,7 +2444,7 @@ void builtin_getskilllv(ScriptState *st) static void builtin_getgmlevel(ScriptState *st) { - push_int(st->stack, ByteCode::INT, pc_isGM(script_rid2sd(st))); + push_int(st->stack, ByteCode::INT, pc_isGM(script_rid2sd(st)).get_all_bits()); } /*========================================== @@ -2448,7 +2469,7 @@ void builtin_getopt2(ScriptState *st) sd = script_rid2sd(st); - push_int(st->stack, ByteCode::INT, uint16_t(sd->opt2)); + push_int(st->stack, ByteCode::INT, static_cast<uint16_t>(sd->opt2)); } @@ -2613,14 +2634,15 @@ void builtin_getexp(ScriptState *st) static void builtin_monster(ScriptState *st) { - int mob_class, amount, x, y; + Species mob_class; + int amount, x, y; NpcEvent event; MapName mapname = stringish<MapName>(ZString(conv_str(st, &AARGO2(2)))); x = conv_num(st, &AARGO2(3)); y = conv_num(st, &AARGO2(4)); MobName str = stringish<MobName>(ZString(conv_str(st, &AARGO2(5)))); - mob_class = conv_num(st, &AARGO2(6)); + mob_class = wrap<Species>(conv_num(st, &AARGO2(6))); amount = conv_num(st, &AARGO2(7)); if (HARGO2(8)) extract(ZString(conv_str(st, &AARGO2(8))), &event); @@ -2636,7 +2658,8 @@ void builtin_monster(ScriptState *st) static void builtin_areamonster(ScriptState *st) { - int mob_class, amount, x0, y0, x1, y1; + Species mob_class; + int amount, x0, y0, x1, y1; NpcEvent event; MapName mapname = stringish<MapName>(ZString(conv_str(st, &AARGO2(2)))); @@ -2645,7 +2668,7 @@ void builtin_areamonster(ScriptState *st) x1 = conv_num(st, &AARGO2(5)); y1 = conv_num(st, &AARGO2(6)); MobName str = stringish<MobName>(ZString(conv_str(st, &AARGO2(7)))); - mob_class = conv_num(st, &AARGO2(8)); + mob_class = wrap<Species>(conv_num(st, &AARGO2(8))); amount = conv_num(st, &AARGO2(9)); if (HARGO2(10)) extract(ZString(conv_str(st, &AARGO2(10))), &event); @@ -2683,7 +2706,7 @@ void builtin_killmonster(ScriptState *st) MapName mapname = stringish<MapName>(ZString(conv_str(st, &AARGO2(2)))); ZString event_ = ZString(conv_str(st, &AARGO2(3))); NpcEvent event; - if (event_ != "All") + if (event_ != "All"_s) extract(event_, &event); map_local *m = map_mapname2mapid(mapname); @@ -2997,7 +3020,7 @@ void builtin_getareausers(ScriptState *st) *------------------------------------------ */ static -void builtin_getareadropitem_sub(dumb_ptr<block_list> bl, int item, int *amount) +void builtin_getareadropitem_sub(dumb_ptr<block_list> bl, ItemNameId item, int *amount) { dumb_ptr<flooritem_data> drop = bl->is_item(); @@ -3007,14 +3030,14 @@ void builtin_getareadropitem_sub(dumb_ptr<block_list> bl, int item, int *amount) } static -void builtin_getareadropitem_sub_anddelete(dumb_ptr<block_list> bl, int item, int *amount) +void builtin_getareadropitem_sub_anddelete(dumb_ptr<block_list> bl, ItemNameId item, int *amount) { dumb_ptr<flooritem_data> drop = bl->is_item(); if (drop->item_data.nameid == item) { (*amount) += drop->item_data.amount; - clif_clearflooritem(drop, 0); + clif_clearflooritem(drop, nullptr); map_delobject(drop->bl_id, drop->bl_type); } } @@ -3022,7 +3045,8 @@ void builtin_getareadropitem_sub_anddelete(dumb_ptr<block_list> bl, int item, in static void builtin_getareadropitem(ScriptState *st) { - int x0, y0, x1, y1, item, amount = 0, delitems = 0; + ItemNameId item; + int x0, y0, x1, y1, amount = 0, delitems = 0; struct script_data *data; MapName str = stringish<MapName>(ZString(conv_str(st, &AARGO2(2)))); @@ -3037,12 +3061,11 @@ void builtin_getareadropitem(ScriptState *st) { ZString name = ZString(conv_str(st, data)); struct item_data *item_data = itemdb_searchname(name); - item = 512; if (item_data) item = item_data->nameid; } else - item = conv_num(st, data); + item = wrap<ItemNameId>(conv_num(st, data)); if (HARGO2(8)) delitems = conv_num(st, &AARGO2(8)); @@ -3102,7 +3125,7 @@ void builtin_sc_start(ScriptState *st) int val1; StatusChange type = static_cast<StatusChange>(conv_num(st, &AARGO2(2))); interval_t tick = static_cast<interval_t>(conv_num(st, &AARGO2(3))); - if (tick < std::chrono::seconds(1)) + if (tick < 1_s) // work around old behaviour of: // speed potion // atk potion @@ -3113,7 +3136,7 @@ void builtin_sc_start(ScriptState *st) tick *= 1000; val1 = conv_num(st, &AARGO2(4)); if (HARGO2(5)) //指定したキャラを状態異常にする - bl = map_id2bl(conv_num(st, &AARGO2(5))); + bl = map_id2bl(wrap<BlockId>(conv_num(st, &AARGO2(5)))); else bl = map_id2bl(st->rid); skill_status_change_start(bl, type, val1, tick); @@ -3151,7 +3174,7 @@ static void builtin_debugmes(ScriptState *st) { dumb_string mes = conv_str(st, &AARGO2(2)); - PRINTF("script debug : %d %d : %s\n", + PRINTF("script debug : %d %d : %s\n"_fmt, st->rid, st->oid, mes); } @@ -3174,10 +3197,10 @@ void builtin_resetstatus(ScriptState *st) static void builtin_changesex(ScriptState *st) { - dumb_ptr<map_session_data> sd = NULL; + dumb_ptr<map_session_data> sd = nullptr; sd = script_rid2sd(st); - chrif_char_ask_name(-1, sd->status_key.name, 5, HumanTimeDiff()); // type: 5 - changesex + chrif_char_ask_name(AccountId(), sd->status_key.name, 5, HumanTimeDiff()); // type: 5 - changesex chrif_save(sd); } @@ -3188,8 +3211,8 @@ void builtin_changesex(ScriptState *st) static void builtin_attachrid(ScriptState *st) { - st->rid = conv_num(st, &AARGO2(2)); - push_int(st->stack, ByteCode::INT, (map_id2sd(st->rid) != NULL)); + st->rid = wrap<BlockId>(conv_num(st, &AARGO2(2))); + push_int(st->stack, ByteCode::INT, (map_id2sd(st->rid) != nullptr)); } /*========================================== @@ -3199,7 +3222,7 @@ void builtin_attachrid(ScriptState *st) static void builtin_detachrid(ScriptState *st) { - st->rid = 0; + st->rid = BlockId(); } /*========================================== @@ -3210,8 +3233,7 @@ static void builtin_isloggedin(ScriptState *st) { push_int(st->stack, ByteCode::INT, - map_id2sd(conv_num(st, - &AARGO2(2))) != NULL); + map_id2sd(wrap<BlockId>(conv_num(st, &AARGO2(2)))) != nullptr); } static @@ -3279,7 +3301,7 @@ void builtin_pvpon(ScriptState *st) { if (m == pl_sd->bl_m && !pl_sd->pvp_timer) { - pl_sd->pvp_timer = Timer(gettick() + std::chrono::milliseconds(200), + pl_sd->pvp_timer = Timer(gettick() + 200_ms, std::bind(pc_calc_pvprank_timer, ph::_1, ph::_2, pl_sd->bl_id)); pl_sd->pvp_rank = 0; @@ -3411,7 +3433,7 @@ void builtin_marriage(ScriptState *st) dumb_ptr<map_session_data> sd = script_rid2sd(st); dumb_ptr<map_session_data> p_sd = map_nick2sd(partner); - if (sd == NULL || p_sd == NULL || pc_marriage(sd, p_sd) < 0) + if (sd == nullptr || p_sd == nullptr || pc_marriage(sd, p_sd) < 0) { push_int(st->stack, ByteCode::INT, 0); return; @@ -3428,7 +3450,7 @@ void builtin_divorce(ScriptState *st) sd->npc_flags.divorce = 1; - if (sd == NULL || pc_divorce(sd) < 0) + if (sd == nullptr || pc_divorce(sd) < 0) { push_int(st->stack, ByteCode::INT, 0); return; @@ -3456,7 +3478,7 @@ void builtin_getitemname(ScriptState *st) } else { - int item_id = conv_num(st, data); + ItemNameId item_id = wrap<ItemNameId>(conv_num(st, data)); i_data = itemdb_search(item_id); } @@ -3464,7 +3486,7 @@ void builtin_getitemname(ScriptState *st) if (i_data) item_name = dumb_string::copys(i_data->jname); else - item_name = dumb_string::copys("Unknown Item"); + item_name = dumb_string::copys("Unknown Item"_s); push_str(st->stack, ByteCode::STR, item_name); } @@ -3476,7 +3498,7 @@ void builtin_getspellinvocation(ScriptState *st) AString invocation = magic_find_invocation(name.str()); if (!invocation) - invocation = "..."; + invocation = "..."_s; push_str(st->stack, ByteCode::STR, dumb_string::copys(invocation)); } @@ -3486,7 +3508,7 @@ void builtin_getpartnerid2(ScriptState *st) { dumb_ptr<map_session_data> sd = script_rid2sd(st); - push_int(st->stack, ByteCode::INT, sd->status.partner_id); + push_int(st->stack, ByteCode::INT, unwrap<CharId>(sd->status.partner_id)); } /*========================================== @@ -3497,24 +3519,24 @@ static void builtin_getinventorylist(ScriptState *st) { dumb_ptr<map_session_data> sd = script_rid2sd(st); - int i, j = 0; + int j = 0; if (!sd) return; - for (i = 0; i < MAX_INVENTORY; i++) + for (IOff0 i : IOff0::iter()) { - if (sd->status.inventory[i].nameid > 0 + if (sd->status.inventory[i].nameid && sd->status.inventory[i].amount > 0) { - pc_setreg(sd, SIR::from(variable_names.intern("@inventorylist_id"), j), - sd->status.inventory[i].nameid); - pc_setreg(sd, SIR::from(variable_names.intern("@inventorylist_amount"), j), + pc_setreg(sd, SIR::from(variable_names.intern("@inventorylist_id"_s), j), + unwrap<ItemNameId>(sd->status.inventory[i].nameid)); + pc_setreg(sd, SIR::from(variable_names.intern("@inventorylist_amount"_s), j), sd->status.inventory[i].amount); - pc_setreg(sd, SIR::from(variable_names.intern("@inventorylist_equip"), j), + pc_setreg(sd, SIR::from(variable_names.intern("@inventorylist_equip"_s), j), static_cast<uint16_t>(sd->status.inventory[i].equip)); j++; } } - pc_setreg(sd, SIR::from(variable_names.intern("@inventorylist_count")), j); + pc_setreg(sd, SIR::from(variable_names.intern("@inventorylist_count"_s)), j); } static @@ -3534,18 +3556,18 @@ void builtin_getactivatedpoolskilllist(ScriptState *st) if (sd->status.skill[skill_id].lv) { - pc_setreg(sd, SIR::from(variable_names.intern("@skilllist_id"), count), + pc_setreg(sd, SIR::from(variable_names.intern("@skilllist_id"_s), count), static_cast<uint16_t>(skill_id)); - pc_setreg(sd, SIR::from(variable_names.intern("@skilllist_lv"), count), + pc_setreg(sd, SIR::from(variable_names.intern("@skilllist_lv"_s), count), sd->status.skill[skill_id].lv); - pc_setreg(sd, SIR::from(variable_names.intern("@skilllist_flag"), count), + pc_setreg(sd, SIR::from(variable_names.intern("@skilllist_flag"_s), count), static_cast<uint16_t>(sd->status.skill[skill_id].flags)); - pc_setregstr(sd, SIR::from(variable_names.intern("@skilllist_name$"), count), + pc_setregstr(sd, SIR::from(variable_names.intern("@skilllist_name$"_s), count), skill_name(skill_id)); ++count; } } - pc_setreg(sd, SIR::from(variable_names.intern("@skilllist_count")), count); + pc_setreg(sd, SIR::from(variable_names.intern("@skilllist_count"_s)), count); } @@ -3565,18 +3587,18 @@ void builtin_getunactivatedpoolskilllist(ScriptState *st) if (sd->status.skill[skill_id].lv && !bool(sd->status.skill[skill_id].flags & SkillFlags::POOL_ACTIVATED)) { - pc_setreg(sd, SIR::from(variable_names.intern("@skilllist_id"), count), + pc_setreg(sd, SIR::from(variable_names.intern("@skilllist_id"_s), count), static_cast<uint16_t>(skill_id)); - pc_setreg(sd, SIR::from(variable_names.intern("@skilllist_lv"), count), + pc_setreg(sd, SIR::from(variable_names.intern("@skilllist_lv"_s), count), sd->status.skill[skill_id].lv); - pc_setreg(sd, SIR::from(variable_names.intern("@skilllist_flag"), count), + pc_setreg(sd, SIR::from(variable_names.intern("@skilllist_flag"_s), count), static_cast<uint16_t>(sd->status.skill[skill_id].flags)); - pc_setregstr(sd, SIR::from(variable_names.intern("@skilllist_name$"), count), + pc_setregstr(sd, SIR::from(variable_names.intern("@skilllist_name$"_s), count), skill_name(skill_id)); ++count; } } - pc_setreg(sd, SIR::from(variable_names.intern("@skilllist_count")), count); + pc_setreg(sd, SIR::from(variable_names.intern("@skilllist_count"_s)), count); } static @@ -3616,9 +3638,9 @@ static void builtin_misceffect(ScriptState *st) { int type; - int id = 0; + BlockId id; CharName name; - dumb_ptr<block_list> bl = NULL; + dumb_ptr<block_list> bl = nullptr; type = conv_num(st, &AARGO2(2)); @@ -3631,7 +3653,7 @@ void builtin_misceffect(ScriptState *st) if (sdata->type == ByteCode::STR || sdata->type == ByteCode::CONSTSTR) name = stringish<CharName>(ZString(conv_str(st, sdata))); else - id = conv_num(st, sdata); + id = wrap<BlockId>(conv_num(st, sdata)); } if (name.to__actual()) @@ -3665,7 +3687,7 @@ void builtin_specialeffect(ScriptState *st) { dumb_ptr<block_list> bl = map_id2bl(st->oid); - if (bl == NULL) + if (bl == nullptr) return; clif_specialeffect(bl, @@ -3680,7 +3702,7 @@ void builtin_specialeffect2(ScriptState *st) { dumb_ptr<map_session_data> sd = script_rid2sd(st); - if (sd == NULL) + if (sd == nullptr) return; clif_specialeffect(sd, @@ -3700,13 +3722,13 @@ void builtin_nude(ScriptState *st) { dumb_ptr<map_session_data> sd = script_rid2sd(st); - if (sd == NULL) + if (sd == nullptr) return; for (EQUIP i : EQUIPs) { - int idx = sd->equip_index_maybe[i]; - if (idx >= 0) + IOff0 idx = sd->equip_index_maybe[i]; + if (idx.ok()) pc_unequipitem(sd, idx, CalcStatus::LATER); } pc_calcstatus(sd, 0); @@ -3722,15 +3744,15 @@ static void builtin_unequipbyid(ScriptState *st) { dumb_ptr<map_session_data> sd = script_rid2sd(st); - if (sd == NULL) + if (sd == nullptr) return; EQUIP slot_id = EQUIP(conv_num(st, &AARGO2(2))); if (slot_id >= EQUIP() && slot_id < EQUIP::COUNT) { - int idx = sd->equip_index_maybe[slot_id]; - if (idx >= 0) + IOff0 idx = sd->equip_index_maybe[slot_id]; + if (idx.ok()) pc_unequipitem(sd, idx, CalcStatus::LATER); } @@ -3753,7 +3775,7 @@ void builtin_gmcommand(ScriptState *st) sd = script_rid2sd(st); dumb_string cmd = conv_str(st, &AARGO2(2)); - is_atcommand(sd->sess, sd, cmd, 99); + is_atcommand(sd->sess, sd, cmd, GmLevel::from(-1U)); } @@ -3766,7 +3788,7 @@ static void builtin_npcwarp(ScriptState *st) { int x, y; - dumb_ptr<npc_data> nd = NULL; + dumb_ptr<npc_data> nd = nullptr; x = conv_num(st, &AARGO2(2)); y = conv_num(st, &AARGO2(3)); @@ -3775,7 +3797,7 @@ void builtin_npcwarp(ScriptState *st) if (!nd) { - PRINTF("builtin_npcwarp: no such npc: %s\n", npc); + PRINTF("builtin_npcwarp: no such npc: %s\n"_fmt, npc); return; } @@ -3808,7 +3830,7 @@ void builtin_message(ScriptState *st) ZString msg = ZString(conv_str(st, &AARGO2(3))); dumb_ptr<map_session_data> pl_sd = map_nick2sd(player); - if (pl_sd == NULL) + if (pl_sd == nullptr) return; clif_displaymessage(pl_sd->sess, msg); @@ -3828,11 +3850,7 @@ void builtin_npctalk(ScriptState *st) if (nd) { - MString message; - message += nd->name; - message += " : "; - message += ZString(str); - clif_message(nd, AString(message)); + clif_message(nd, XString(str)); } } @@ -3856,13 +3874,13 @@ void builtin_getlook(ScriptState *st) val = static_cast<uint16_t>(sd->status.weapon); break; case LOOK::HEAD_BOTTOM: //3 - val = sd->status.head_bottom; + val = unwrap<ItemNameId>(sd->status.head_bottom); break; case LOOK::HEAD_TOP: //4 - val = sd->status.head_top; + val = unwrap<ItemNameId>(sd->status.head_top); break; case LOOK::HEAD_MID: //5 - val = sd->status.head_mid; + val = unwrap<ItemNameId>(sd->status.head_mid); break; case LOOK::HAIR_COLOR: //6 val = sd->status.hair_color; @@ -3871,7 +3889,7 @@ void builtin_getlook(ScriptState *st) val = sd->status.clothes_color; break; case LOOK::SHIELD: //8 - val = sd->status.shield; + val = unwrap<ItemNameId>(sd->status.shield); break; case LOOK::SHOES: //9 break; @@ -3988,7 +4006,7 @@ void builtin_shop(ScriptState *st) nd = npc_name2id(name); if (!nd) { - PRINTF("builtin_shop: no such npc: %s\n", name); + PRINTF("builtin_shop: no such npc: %s\n"_fmt, name); return; } @@ -4017,11 +4035,11 @@ void builtin_fakenpcname(ScriptState *st) { NpcName name = stringish<NpcName>(ZString(conv_str(st, &AARGO2(2)))); NpcName newname = stringish<NpcName>(ZString(conv_str(st, &AARGO2(3)))); - int newsprite = conv_num(st, &AARGO2(4)); + Species newsprite = wrap<Species>(static_cast<uint16_t>(conv_num(st, &AARGO2(4)))); dumb_ptr<npc_data> nd = npc_name2id(name); if (!nd) { - PRINTF("builtin_fakenpcname: no such npc: %s\n", name); + PRINTF("builtin_fakenpcname: no such npc: %s\n"_fmt, name); return; } nd->name = newname; @@ -4205,7 +4223,7 @@ void op_2str(ScriptState *st, ByteCode op, dumb_string s1_, dumb_string s2_) a = s1 <= s2; break; default: - PRINTF("illegal string operater\n"); + PRINTF("illegal string operater\n"_fmt); break; } @@ -4308,7 +4326,7 @@ void op_2(ScriptState *st, ByteCode op) else { // si,is => error - PRINTF("script: op_2: int&str, str&int not allow.\n"); + PRINTF("script: op_2: int&str, str&int not allow.\n"_fmt); push_int(st->stack, ByteCode::INT, 0); } } @@ -4351,7 +4369,7 @@ void run_func(ScriptState *st) if (start_sp == 0) { if (battle_config.error_log) - PRINTF("function not found\n"); + PRINTF("function not found\n"_fmt); st->state = ScriptEndState::END; return; } @@ -4364,52 +4382,52 @@ void run_func(ScriptState *st) size_t func = st->stack->stack_datav[st->start].u.numi; if (st->stack->stack_datav[st->start].type != ByteCode::FUNC_REF) { - PRINTF("run_func: not function and command! \n"); + PRINTF("run_func: not function and command! \n"_fmt); st->state = ScriptEndState::END; return; } if (DEBUG_RUN && battle_config.etc_log) { - PRINTF("run_func : %s\n", + PRINTF("run_func : %s\n"_fmt, builtin_functions[func].name); - PRINTF("stack dump :"); + PRINTF("stack dump :"_fmt); for (script_data& d : st->stack->stack_datav) { switch (d.type) { case ByteCode::INT: - PRINTF(" int(%d)", d.u.numi); + PRINTF(" int(%d)"_fmt, d.u.numi); break; case ByteCode::RETINFO: - PRINTF(" retinfo(%p)", static_cast<const void *>(d.u.script)); + PRINTF(" retinfo(%p)"_fmt, static_cast<const void *>(d.u.script)); break; case ByteCode::PARAM_: - PRINTF(" param(%d)", d.u.reg.sp()); + PRINTF(" param(%d)"_fmt, d.u.reg.sp()); break; case ByteCode::VARIABLE: - PRINTF(" name(%s)[%d]", variable_names.outtern(d.u.reg.base()), d.u.reg.index()); + PRINTF(" name(%s)[%d]"_fmt, variable_names.outtern(d.u.reg.base()), d.u.reg.index()); break; case ByteCode::ARG: - PRINTF(" arg"); + PRINTF(" arg"_fmt); break; case ByteCode::POS: - PRINTF(" pos(%d)", d.u.numi); + PRINTF(" pos(%d)"_fmt, d.u.numi); break; case ByteCode::STR: - PRINTF(" str(%s)", d.u.str); + PRINTF(" str(%s)"_fmt, d.u.str); break; case ByteCode::CONSTSTR: - PRINTF(" cstr(%s)", d.u.str); + PRINTF(" cstr(%s)"_fmt, d.u.str); break; case ByteCode::FUNC_REF: - PRINTF(" func(%s)", builtin_functions[d.u.numi].name); + PRINTF(" func(%s)"_fmt, builtin_functions[d.u.numi].name); break; default: - PRINTF(" %d,%d", d.type, d.u.numi); + PRINTF(" %d,%d"_fmt, d.type, d.u.numi); } } - PRINTF("\n"); + PRINTF("\n"_fmt); } builtin_functions[func].func(st); @@ -4424,7 +4442,7 @@ void run_func(ScriptState *st) if (st->defsp < 4 || st->stack->stack_datav[st->defsp - 1].type != ByteCode::RETINFO) { - PRINTF("script:run_func (return) return without callfunc or callsub!\n"); + PRINTF("script:run_func (return) return without callfunc or callsub!\n"_fmt); st->state = ScriptEndState::END; return; } @@ -4449,15 +4467,15 @@ void dump_script(const ScriptBuffer *script) ScriptPointer scriptp(script, 0); while (scriptp.pos < reinterpret_cast<const std::vector<ByteCode> *>(script)->size()) { - PRINTF("%6zu: ", scriptp.pos); + PRINTF("%6zu: "_fmt, scriptp.pos); switch (ByteCode c = get_com(&scriptp)) { case ByteCode::EOL: - PRINTF("EOL\n"); // extra newline between functions + PRINTF("EOL\n"_fmt); // extra newline between functions break; case ByteCode::INT: // synthesized! - PRINTF("INT %d", get_num(&scriptp)); + PRINTF("INT %d"_fmt, get_num(&scriptp)); break; case ByteCode::POS: @@ -4472,103 +4490,103 @@ void dump_script(const ScriptBuffer *script) switch(c) { case ByteCode::POS: - PRINTF("POS %d", arg); + PRINTF("POS %d"_fmt, arg); break; case ByteCode::VARIABLE: - PRINTF("VARIABLE %s", variable_names.outtern(arg)); + PRINTF("VARIABLE %s"_fmt, variable_names.outtern(arg)); break; case ByteCode::FUNC_REF: - PRINTF("FUNC_REF %s", builtin_functions[arg].name); + PRINTF("FUNC_REF %s"_fmt, builtin_functions[arg].name); break; case ByteCode::PARAM_: - PRINTF("PARAM SP::#%d (sorry)", arg); + PRINTF("PARAM SP::#%d (sorry)"_fmt, arg); break; } } break; case ByteCode::ARG: - PRINTF("ARG"); + PRINTF("ARG"_fmt); break; case ByteCode::STR: - PRINTF("STR \"%s\"", scriptp.pops()); + PRINTF("STR \"%s\""_fmt, scriptp.pops()); break; case ByteCode::FUNC_: - PRINTF("FUNC_"); + PRINTF("FUNC_"_fmt); break; case ByteCode::ADD: - PRINTF("ADD"); + PRINTF("ADD"_fmt); break; case ByteCode::SUB: - PRINTF("SUB"); + PRINTF("SUB"_fmt); break; case ByteCode::MUL: - PRINTF("MUL"); + PRINTF("MUL"_fmt); break; case ByteCode::DIV: - PRINTF("DIV"); + PRINTF("DIV"_fmt); break; case ByteCode::MOD: - PRINTF("MOD"); + PRINTF("MOD"_fmt); break; case ByteCode::EQ: - PRINTF("EQ"); + PRINTF("EQ"_fmt); break; case ByteCode::NE: - PRINTF("NE"); + PRINTF("NE"_fmt); break; case ByteCode::GT: - PRINTF("GT"); + PRINTF("GT"_fmt); break; case ByteCode::GE: - PRINTF("GE"); + PRINTF("GE"_fmt); break; case ByteCode::LT: - PRINTF("LT"); + PRINTF("LT"_fmt); break; case ByteCode::LE: - PRINTF("LE"); + PRINTF("LE"_fmt); break; case ByteCode::AND: - PRINTF("AND"); + PRINTF("AND"_fmt); break; case ByteCode::OR: - PRINTF("OR"); + PRINTF("OR"_fmt); break; case ByteCode::XOR: - PRINTF("XOR"); + PRINTF("XOR"_fmt); break; case ByteCode::LAND: - PRINTF("LAND"); + PRINTF("LAND"_fmt); break; case ByteCode::LOR: - PRINTF("LOR"); + PRINTF("LOR"_fmt); break; case ByteCode::R_SHIFT: - PRINTF("R_SHIFT"); + PRINTF("R_SHIFT"_fmt); break; case ByteCode::L_SHIFT: - PRINTF("L_SHIFT"); + PRINTF("L_SHIFT"_fmt); break; case ByteCode::NEG: - PRINTF("NEG"); + PRINTF("NEG"_fmt); break; case ByteCode::NOT: - PRINTF("NOT"); + PRINTF("NOT"_fmt); break; case ByteCode::LNOT: - PRINTF("LNOT"); + PRINTF("LNOT"_fmt); break; case ByteCode::NOP: - PRINTF("NOP"); + PRINTF("NOP"_fmt); break; default: - PRINTF("??? %d", c); + PRINTF("??? %d"_fmt, c); break; } - PRINTF("\n"); + PRINTF("\n"_fmt); } } @@ -4595,7 +4613,7 @@ void run_script_main(ScriptState *st, const ScriptBuffer *rootscript) if (stack->stack_datav.size() != st->defsp) { if (battle_config.error_log) - PRINTF("stack.sp (%zu) != default (%d)\n", + PRINTF("stack.sp (%zu) != default (%d)\n"_fmt, stack->stack_datav.size(), st->defsp); stack->stack_datav.resize(st->defsp); @@ -4650,7 +4668,7 @@ void run_script_main(ScriptState *st, const ScriptBuffer *rootscript) st->state = ScriptEndState::ZERO; if (gotocount > 0 && (--gotocount) <= 0) { - PRINTF("run_script: infinity loop !\n"); + PRINTF("run_script: infinity loop !\n"_fmt); st->state = ScriptEndState::END; } } @@ -4692,14 +4710,14 @@ void run_script_main(ScriptState *st, const ScriptBuffer *rootscript) default: if (battle_config.error_log) - PRINTF("unknown command : %d @ %zu\n", + PRINTF("unknown command : %d @ %zu\n"_fmt, c, st->scriptp.pos); st->state = ScriptEndState::END; break; } if (cmdcount > 0 && (--cmdcount) <= 0) { - PRINTF("run_script: infinity loop !\n"); + PRINTF("run_script: infinity loop !\n"_fmt); st->state = ScriptEndState::END; } } @@ -4739,12 +4757,12 @@ void run_script_main(ScriptState *st, const ScriptBuffer *rootscript) * スクリプトの実行 *------------------------------------------ */ -int run_script(ScriptPointer sp, int rid, int oid) +int run_script(ScriptPointer sp, BlockId rid, BlockId oid) { return run_script_l(sp, rid, oid, nullptr); } -int run_script_l(ScriptPointer sp, int rid, int oid, +int run_script_l(ScriptPointer sp, BlockId rid, BlockId oid, Slice<argrec_t> args) { struct script_stack stack; @@ -4752,7 +4770,7 @@ int run_script_l(ScriptPointer sp, int rid, int oid, dumb_ptr<map_session_data> sd = map_id2sd(rid); const ScriptBuffer *rootscript = sp.code; int i; - if (sp.code == NULL || sp.pos >> 24) + if (sp.code == nullptr || sp.pos >> 24) return -1; if (sd && !sd->npc_stackbuf.empty() && sd->npc_scriptroot == rootscript) @@ -4846,7 +4864,7 @@ void script_load_mapreg(void) else { borken: - PRINTF("%s: %s broken data !\n", mapreg_txt, AString(buf1)); + PRINTF("%s: %s broken data !\n"_fmt, mapreg_txt, AString(buf1)); continue; } } @@ -4865,9 +4883,9 @@ void script_save_mapreg_intsub(SIR key, int data, io::WriteFile& fp) if (name[1] != '@') { if (i == 0) - FPRINTF(fp, "%s\t%d\n", name, data); + FPRINTF(fp, "%s\t%d\n"_fmt, name, data); else - FPRINTF(fp, "%s,%d\t%d\n", name, i, data); + FPRINTF(fp, "%s,%d\t%d\n"_fmt, name, i, data); } } @@ -4879,9 +4897,9 @@ void script_save_mapreg_strsub(SIR key, ZString data, io::WriteFile& fp) if (name[1] != '@') { if (i == 0) - FPRINTF(fp, "%s\t%s\n", name, data); + FPRINTF(fp, "%s\t%s\n"_fmt, name, data); else - FPRINTF(fp, "%s,%d\t%s\n", name, i, data); + FPRINTF(fp, "%s,%d\t%s\n"_fmt, name, i, data); } } @@ -4932,129 +4950,128 @@ void do_init_script(void) ).detach(); } -#define BUILTIN(func, args) \ -{builtin_##func, {#func}, {args}} +#define BUILTIN(func, args, ret) \ +{builtin_##func, #func ## _s, args, ret} BuiltinFunction builtin_functions[] = { - BUILTIN(mes, "s"), - BUILTIN(next, ""), - BUILTIN(close, ""), - BUILTIN(close2, ""), - BUILTIN(menu, "sL*"), - BUILTIN(goto, "L"), - BUILTIN(callsub, "L"), - BUILTIN(callfunc, "F"), - BUILTIN(return, ""), - BUILTIN(input, "N"), - BUILTIN(warp, "Mxy"), - BUILTIN(isat, "Mxy"), - BUILTIN(areawarp, "MxyxyMxy"), - BUILTIN(setlook, "ii"), - BUILTIN(set, "Ne"), - BUILTIN(setarray, "Ne*"), - BUILTIN(cleararray, "Nei"), - BUILTIN(getarraysize, "N"), - BUILTIN(getelementofarray, "Ni"), - BUILTIN(if, "iF*"), - BUILTIN(getitem, "Ii**"), - BUILTIN(makeitem, "IiMxy"), - BUILTIN(delitem, "Ii"), - BUILTIN(heal, "ii"), - BUILTIN(itemheal, "ii"), - BUILTIN(percentheal, "ii"), - BUILTIN(rand, "i*"), - BUILTIN(pow, "ii"), - BUILTIN(countitem, "I"), - BUILTIN(checkweight, "Ii"), - BUILTIN(readparam, "i*"), - BUILTIN(getcharid, "i*"), - BUILTIN(strcharinfo, "i"), - BUILTIN(getequipid, "i"), - BUILTIN(getequipname, "i"), - BUILTIN(statusup2, "ii"), - BUILTIN(bonus, "ii"), - BUILTIN(bonus2, "iii"), - BUILTIN(skill, "ii*"), - BUILTIN(setskill, "ii"), - BUILTIN(getskilllv, "i"), - BUILTIN(getgmlevel, ""), - BUILTIN(end, ""), - BUILTIN(getopt2, ""), - BUILTIN(setopt2, "i"), - BUILTIN(savepoint, "Mxy"), - BUILTIN(gettimetick, "i"), - BUILTIN(gettime, "i"), - BUILTIN(openstorage, "*"), - BUILTIN(monster, "Mxysmi*"), - BUILTIN(areamonster, "Mxyxysmi*"), - BUILTIN(killmonster, "ME"), - BUILTIN(killmonsterall, "M"), - BUILTIN(donpcevent, "E"), - BUILTIN(addtimer, "tE"), - BUILTIN(initnpctimer, ""), - BUILTIN(stopnpctimer, ""), - BUILTIN(startnpctimer, "*"), - BUILTIN(setnpctimer, "i"), - BUILTIN(getnpctimer, "i"), - BUILTIN(announce, "si"), - BUILTIN(mapannounce, "Msi"), - BUILTIN(getusers, "i"), - BUILTIN(getmapusers, "M"), - BUILTIN(getareausers, "Mxyxy*"), - BUILTIN(getareadropitem, "Mxyxyi*"), - BUILTIN(enablenpc, "s"), - BUILTIN(disablenpc, "s"), - BUILTIN(sc_start, "iTi*"), - BUILTIN(sc_end, "i"), - BUILTIN(sc_check, "i"), - BUILTIN(debugmes, "s"), - BUILTIN(resetstatus, ""), - BUILTIN(changesex, ""), - BUILTIN(attachrid, "i"), - BUILTIN(detachrid, ""), - BUILTIN(isloggedin, "i"), - BUILTIN(setmapflag, "Mi"), - BUILTIN(removemapflag, "Mi"), - BUILTIN(getmapflag, "Mi"), - BUILTIN(pvpon, "M"), - BUILTIN(pvpoff, "M"), - BUILTIN(emotion, "i"), - BUILTIN(marriage, "P"), - BUILTIN(divorce, ""), - BUILTIN(getitemname, "I"), - BUILTIN(getspellinvocation, "s"), - BUILTIN(getpartnerid2, ""), - BUILTIN(getexp, "ii"), - BUILTIN(getinventorylist, ""), - BUILTIN(getactivatedpoolskilllist, ""), - BUILTIN(getunactivatedpoolskilllist, ""), - BUILTIN(poolskill, "i"), - BUILTIN(unpoolskill, "i"), - BUILTIN(misceffect, "i*"), - BUILTIN(specialeffect, "i"), - BUILTIN(specialeffect2, "i"), - BUILTIN(nude, ""), - BUILTIN(mapwarp, "MMxy"), - BUILTIN(cmdothernpc, "ss"), - BUILTIN(gmcommand, "s"), - BUILTIN(npcwarp, "xys"), - BUILTIN(message, "Ps"), - BUILTIN(npctalk, "s"), - BUILTIN(mobcount, "ME"), - BUILTIN(getlook, "i"), - BUILTIN(getsavepoint, "i"), - BUILTIN(areatimer, "MxyxytE"), - BUILTIN(isin, "Mxyxy"), - BUILTIN(shop, "s"), - BUILTIN(isdead, ""), - BUILTIN(unequipbyid, "i"), - BUILTIN(fakenpcname, "ssi"), - BUILTIN(getx, ""), - BUILTIN(gety, ""), - BUILTIN(getmap, ""), - BUILTIN(mapexit, ""), - {nullptr, ZString(), ZString()}, + BUILTIN(mes, "s"_s, '\0'), + BUILTIN(goto, "L"_s, '\0'), + BUILTIN(callfunc, "F"_s, '\0'), + BUILTIN(callsub, "L"_s, '\0'), + BUILTIN(return, ""_s, '\0'), + BUILTIN(next, ""_s, '\0'), + BUILTIN(close, ""_s, '\0'), + BUILTIN(close2, ""_s, '\0'), + BUILTIN(menu, "sL**"_s, '\0'), + BUILTIN(rand, "i?"_s, 'i'), + BUILTIN(isat, "Mxy"_s, 'i'), + BUILTIN(warp, "Mxy"_s, '\0'), + BUILTIN(areawarp, "MxyxyMxy"_s, '\0'), + BUILTIN(heal, "ii"_s, '\0'), + BUILTIN(itemheal, "ii"_s, '\0'), + BUILTIN(percentheal, "ii"_s, '\0'), + BUILTIN(input, "N"_s, '\0'), + BUILTIN(if, "iF*"_s, '\0'), + BUILTIN(set, "Ne"_s, '\0'), + BUILTIN(setarray, "Ne*"_s, '\0'), + BUILTIN(cleararray, "Nei"_s, '\0'), + BUILTIN(getarraysize, "N"_s, 'i'), + BUILTIN(getelementofarray, "Ni"_s, '.'), + BUILTIN(setlook, "ii"_s, '\0'), + BUILTIN(countitem, "I"_s, 'i'), + BUILTIN(checkweight, "Ii"_s, 'i'), + BUILTIN(getitem, "Ii??"_s, '\0'), + BUILTIN(makeitem, "IiMxy"_s, '\0'), + BUILTIN(delitem, "Ii"_s, '\0'), + BUILTIN(readparam, "i?"_s, 'i'), + BUILTIN(getcharid, "i?"_s, 'i'), + BUILTIN(strcharinfo, "i"_s, 's'), + BUILTIN(getequipid, "i"_s, 'i'), + BUILTIN(getequipname, "i"_s, 's'), + BUILTIN(statusup2, "ii"_s, '\0'), + BUILTIN(bonus, "ii"_s, '\0'), + BUILTIN(bonus2, "iii"_s, '\0'), + BUILTIN(skill, "ii?"_s, '\0'), + BUILTIN(setskill, "ii"_s, '\0'), + BUILTIN(getskilllv, "i"_s, 'i'), + BUILTIN(getgmlevel, ""_s, 'i'), + BUILTIN(end, ""_s, '\0'), + BUILTIN(getopt2, ""_s, 'i'), + BUILTIN(setopt2, "i"_s, '\0'), + BUILTIN(savepoint, "Mxy"_s, '\0'), + BUILTIN(gettimetick, "i"_s, 'i'), + BUILTIN(gettime, "i"_s, 'i'), + BUILTIN(openstorage, ""_s, '\0'), + BUILTIN(getexp, "ii"_s, '\0'), + BUILTIN(monster, "Mxysmi?"_s, '\0'), + BUILTIN(areamonster, "Mxyxysmi?"_s, '\0'), + BUILTIN(killmonster, "ME"_s, '\0'), + BUILTIN(killmonsterall, "M"_s, '\0'), + BUILTIN(donpcevent, "E"_s, '\0'), + BUILTIN(addtimer, "tE"_s, '\0'), + BUILTIN(initnpctimer, ""_s, '\0'), + BUILTIN(startnpctimer, "?"_s, '\0'), + BUILTIN(stopnpctimer, ""_s, '\0'), + BUILTIN(getnpctimer, "i"_s, 'i'), + BUILTIN(setnpctimer, "i"_s, '\0'), + BUILTIN(announce, "si"_s, '\0'), + BUILTIN(mapannounce, "Msi"_s, '\0'), + BUILTIN(getusers, "i"_s, 'i'), + BUILTIN(getmapusers, "M"_s, 'i'), + BUILTIN(getareausers, "Mxyxy?"_s, 'i'), + BUILTIN(getareadropitem, "Mxyxyi?"_s, 'i'), + BUILTIN(enablenpc, "s"_s, '\0'), + BUILTIN(disablenpc, "s"_s, '\0'), + BUILTIN(sc_start, "iTi?"_s, '\0'), + BUILTIN(sc_end, "i"_s, '\0'), + BUILTIN(sc_check, "i"_s, 'i'), + BUILTIN(debugmes, "s"_s, '\0'), + BUILTIN(resetstatus, ""_s, '\0'), + BUILTIN(changesex, ""_s, '\0'), + BUILTIN(attachrid, "i"_s, 'i'), + BUILTIN(detachrid, ""_s, '\0'), + BUILTIN(isloggedin, "i"_s, 'i'), + BUILTIN(setmapflag, "Mi"_s, '\0'), + BUILTIN(removemapflag, "Mi"_s, '\0'), + BUILTIN(getmapflag, "Mi"_s, 'i'), + BUILTIN(pvpon, "M"_s, '\0'), + BUILTIN(pvpoff, "M"_s, '\0'), + BUILTIN(emotion, "i"_s, '\0'), + BUILTIN(mapwarp, "MMxy"_s, '\0'), + BUILTIN(cmdothernpc, "ss"_s, '\0'), + BUILTIN(mobcount, "ME"_s, 'i'), + BUILTIN(marriage, "P"_s, 'i'), + BUILTIN(divorce, ""_s, 'i'), + BUILTIN(getitemname, "I"_s, 's'), + BUILTIN(getspellinvocation, "s"_s, 's'), + BUILTIN(getpartnerid2, ""_s, 'i'), + BUILTIN(getinventorylist, ""_s, '\0'), + BUILTIN(getactivatedpoolskilllist, ""_s, '\0'), + BUILTIN(getunactivatedpoolskilllist, ""_s, '\0'), + BUILTIN(poolskill, "i"_s, '\0'), + BUILTIN(unpoolskill, "i"_s, '\0'), + BUILTIN(misceffect, "i?"_s, '\0'), + BUILTIN(specialeffect, "i"_s, '\0'), + BUILTIN(specialeffect2, "i"_s, '\0'), + BUILTIN(nude, ""_s, '\0'), + BUILTIN(unequipbyid, "i"_s, '\0'), + BUILTIN(gmcommand, "s"_s, '\0'), + BUILTIN(npcwarp, "xys"_s, '\0'), + BUILTIN(message, "Ps"_s, '\0'), + BUILTIN(npctalk, "s"_s, '\0'), + BUILTIN(getlook, "i"_s, 'i'), + BUILTIN(getsavepoint, "i"_s, '.'), + BUILTIN(areatimer, "MxyxytE"_s, '\0'), + BUILTIN(isin, "Mxyxy"_s, 'i'), + BUILTIN(shop, "s"_s, '\0'), + BUILTIN(isdead, ""_s, 'i'), + BUILTIN(fakenpcname, "ssi"_s, '\0'), + BUILTIN(getx, ""_s, 'i'), + BUILTIN(gety, ""_s, 'i'), + BUILTIN(getmap, ""_s, 's'), + BUILTIN(mapexit, ""_s, '\0'), + {nullptr, ""_s, ""_s, '\0'}, }; void set_script_var_i(dumb_ptr<map_session_data> sd, VarName var, int e, int val) @@ -5079,7 +5096,7 @@ int get_script_var_i(dumb_ptr<map_session_data> sd, VarName var, int e) 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!"); + PRINTF("Warning: you lied about the type and I'm too lazy to fix it!"_fmt); return 0; } ZString get_script_var_s(dumb_ptr<map_session_data> sd, VarName var, int e) @@ -5092,6 +5109,7 @@ ZString get_script_var_s(dumb_ptr<map_session_data> sd, VarName var, int e) 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!"); + PRINTF("Warning: you lied about the type and I can't fix it!"_fmt); return ZString(); } +} // namespace tmwa |