diff options
author | mekolat <mekolat@users.noreply.github.com> | 2016-04-25 14:28:44 -0400 |
---|---|---|
committer | mekolat <mekolat@users.noreply.github.com> | 2016-04-25 15:02:38 -0400 |
commit | 6bbe790cbfba5bb83a8aa1a67907860972294aaf (patch) | |
tree | 8fb9300d1dad495e10f7c5a92f2850ef7c2be5f4 /src | |
parent | 90f7bc9aae01b3515bb52b2d6331d9820ac0989e (diff) | |
download | tmwa-6bbe790cbfba5bb83a8aa1a67907860972294aaf.tar.gz tmwa-6bbe790cbfba5bb83a8aa1a67907860972294aaf.tar.bz2 tmwa-6bbe790cbfba5bb83a8aa1a67907860972294aaf.tar.xz tmwa-6bbe790cbfba5bb83a8aa1a67907860972294aaf.zip |
use map_id_is_XXX in script-fun where appropriate
Diffstat (limited to 'src')
-rw-r--r-- | src/map/script-fun.cpp | 82 |
1 files changed, 66 insertions, 16 deletions
diff --git a/src/map/script-fun.cpp b/src/map/script-fun.cpp index c8d1af4..637f893 100644 --- a/src/map/script-fun.cpp +++ b/src/map/script-fun.cpp @@ -693,6 +693,12 @@ void builtin_target(ScriptState *st) int flag = conv_num(st, &AARG(2)); int val = 0; + if (!source || !target) + { + push_int<ScriptDataInt>(st->stack, val); + return; + } + if (flag & 0x01) { int x0 = source->bl_x - AREA_SIZE; @@ -1109,9 +1115,11 @@ void builtin_destroy(ScriptState *st) else id = st->oid; - dumb_ptr<npc_data_script> nd = map_id2bl(id)->is_npc()->is_script(); - if(!nd) + dumb_ptr<npc_data> nd = map_id_is_npc(id); + if(!nd || nd->npc_subtype != NpcSubtype::SCRIPT) return; + + nd = nd->is_script(); //assert(nd->disposable == true); we don't care about it anymore npc_free(nd); if (!HARG(0)) @@ -1276,7 +1284,7 @@ void builtin_set(ScriptState *st) } else - bl = script_rid2sd(st)->is_player(); + bl = script_rid2sd(st); if (bl == nullptr) return; @@ -1342,10 +1350,10 @@ void builtin_set(ScriptState *st) set_scope_reg(st, reg, &AARG(1)); return; } - bl = map_id2bl(st->oid)->is_npc(); + bl = map_id_is_npc(st->oid); } else - bl = map_id2bl(st->rid)->is_player(); + bl = map_id_is_player(st->rid); } if (bl == nullptr) return; @@ -1433,7 +1441,7 @@ void builtin_setarray(ScriptState *st) { ZString tn = conv_str(st, sdata); if (tn == "this"_s || tn == "oid"_s) - bl = map_id2bl(st->oid)->is_npc(); + bl = map_id_is_npc(st->oid); else { NpcName name_ = stringish<NpcName>(tn); @@ -1444,9 +1452,9 @@ void builtin_setarray(ScriptState *st) { int tid = conv_num(st, sdata); if (tid == 0) - bl = map_id2bl(st->oid)->is_npc(); + bl = map_id_is_npc(st->oid); else - bl = map_id2bl(wrap<BlockId>(tid))->is_npc(); + bl = map_id_is_npc(wrap<BlockId>(tid)); } if (!bl) { @@ -1457,7 +1465,13 @@ void builtin_setarray(ScriptState *st) j = getarraysize2(reg, bl); } else if (prefix != '$' && !name.startswith(".@"_s)) - bl = map_id2bl(st->rid)->is_player(); + bl = map_id_is_player(st->rid); + + if (!bl) + { + PRINTF("builtin_setarray: rid not attached\n"_fmt); + return; + } for (; i < st->end - st->start - 2 && j < 256; i++, j++) { @@ -1490,9 +1504,15 @@ void builtin_cleararray(ScriptState *st) return; } if (prefix == '.' && !name.startswith(".@"_s)) - bl = map_id2bl(st->oid)->is_npc(); + bl = map_id_is_npc(st->oid); else if (prefix != '$' && !name.startswith(".@"_s)) - bl = map_id2bl(st->rid)->is_player(); + bl = map_id_is_player(st->rid); + + if (!bl) + { + PRINTF("builtin_cleararray: no block list\n"_fmt); + return; + } for (int i = 0; i < sz; i++) { @@ -1969,7 +1989,7 @@ void builtin_getnpcid(ScriptState *st) if (HARG(0)) nd = npc_name2id(stringish<NpcName>(ZString(conv_str(st, &AARG(0))))); else - nd = map_id2bl(st->oid)->is_npc(); + nd = map_id_is_npc(st->oid); if (nd == nullptr) { push_int<ScriptDataInt>(st->stack, -1); @@ -2002,10 +2022,16 @@ void builtin_strcharinfo(ScriptState *st) int num; if (HARG(1)) //指定したキャラを状態異常にする - sd = map_id2bl(wrap<BlockId>(conv_num(st, &AARG(1))))->is_player(); + sd = map_id_is_player(wrap<BlockId>(conv_num(st, &AARG(1)))); else sd = script_rid2sd(st); + if (!sd) + { + PRINTF("builtin_strcharinfo: player not found\n"_fmt); + return; + } + num = conv_num(st, &AARG(0)); if (num == 0) { @@ -2434,6 +2460,12 @@ void builtin_summon(ScriptState *st) if (HARG(7)) extract(ZString(conv_str(st, &AARG(7))), &event); + if (!owner_e) + { + PRINTF("builtin_summon: bad owner\n"_fmt); + return; + } + if (monster_attitude == MonsterAttitude::SERVANT && owner_e->bl_type == BL::PC) owner = owner_e->is_player(); // XXX in the future this should also work with mobs as owner @@ -2801,6 +2833,8 @@ void builtin_setnpcdirection(ScriptState *st) else nd_ = map_id_is_npc(st->oid); + assert (nd_); + if (bool(conv_num(st, &AARG(1)))) action = DamageType::SIT; else @@ -3355,10 +3389,16 @@ void builtin_getpvpflag(ScriptState *st) { dumb_ptr<map_session_data> sd; if (HARG(1)) //指定したキャラを状態異常にする - sd = map_id2bl(wrap<BlockId>(conv_num(st, &AARG(1))))->is_player(); + sd = map_id_is_player(wrap<BlockId>(conv_num(st, &AARG(1)))); else sd = script_rid2sd(st); + if (!sd) + { + PRINTF("builtin_getpvpflag: player not found\n"_fmt); + return; + } + int num = conv_num(st, &AARG(0)); int flag = 0; @@ -3552,6 +3592,8 @@ void builtin_explode(ScriptState *st) else if (prefix != '$' && prefix != '.') bl = map_id2bl(st->rid)->is_player(); + assert (bl); + for (int j = 0; j < 256; j++) { auto find = std::find(str.begin(), str.end(), separator); @@ -3915,7 +3957,7 @@ void builtin_get(ScriptState *st) else var = pc_readaccountreg(bl->is_player(), stringish<VarName>(name_)); } - else + else if (bl) var = pc_readreg(bl, reg); push_int<ScriptDataInt>(st->stack, var); @@ -4317,6 +4359,8 @@ void builtin_getsavepoint(ScriptState *st) static void builtin_areatimer_sub(dumb_ptr<block_list> bl, interval_t tick, NpcEvent event) { + if (!bl) + return; if (bl->bl_type == BL::PC) { dumb_ptr<map_session_data> sd = map_id_is_player(bl->bl_id); @@ -4540,7 +4584,7 @@ void builtin_strnpcinfo(ScriptState *st) else { BlockId id = wrap<BlockId>(conv_num(st, sdata)); - nd = map_id2bl(id)->is_npc(); + nd = map_id_is_npc(id); } if (!nd) @@ -4552,6 +4596,8 @@ void builtin_strnpcinfo(ScriptState *st) nd = map_id_is_npc(st->oid); } + assert (nd); + switch(num) { case 0: @@ -4592,6 +4638,8 @@ void builtin_getnpcx(ScriptState *st) nd = map_id_is_npc(st->oid); } + assert (nd); + push_int<ScriptDataInt>(st->stack, nd->bl_x); } @@ -4616,6 +4664,8 @@ void builtin_getnpcy(ScriptState *st) nd = map_id_is_npc(st->oid); } + assert (nd); + push_int<ScriptDataInt>(st->stack, nd->bl_y); } |