From 7a561ba98e5908d4887a15148487ee1800312e1f Mon Sep 17 00:00:00 2001 From: mekolat Date: Sun, 5 Jul 2015 12:59:52 -0400 Subject: fix getmapusers --- src/map/map.cpp | 4 ++-- src/map/script-fun.cpp | 23 +++++++++++++++-------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/map/map.cpp b/src/map/map.cpp index 97b9e2e..d40977f 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -183,7 +183,7 @@ int map_addblock(dumb_ptr bl) if (bl->bl_next) bl->bl_next->bl_prev = bl; m->blocks.ref(x / BLOCK_SIZE, y / BLOCK_SIZE).normal = bl; - if (bl->bl_type == BL::PC && !bool(bl->is_player()->status.option & Opt0::HIDE)) + if (bl->bl_type == BL::PC) m->users++; } @@ -211,7 +211,7 @@ int map_delblock(dumb_ptr bl) return 0; } - if (bl->bl_type == BL::PC && !bool(bl->is_player()->status.option & Opt0::HIDE)) + if (bl->bl_type == BL::PC) bl->bl_m->users--; if (bl->bl_next) diff --git a/src/map/script-fun.cpp b/src/map/script-fun.cpp index 2822550..5e55e53 100644 --- a/src/map/script-fun.cpp +++ b/src/map/script-fun.cpp @@ -1752,29 +1752,36 @@ void builtin_getusers(ScriptState *st) * マップ指定ユーザー数所得 *------------------------------------------ */ + static + void builtin_getareausers_sub(dumb_ptr bl, int *users) + { + if (bool(bl->is_player()->status.option & Opt0::HIDE)) + return; + (*users)++; + } + static void builtin_getmapusers(ScriptState *st) { + int users = 0; MapName str = stringish(ZString(conv_str(st, &AARG(0)))); P m = TRY_UNWRAP(map_mapname2mapid(str), { push_int(st->stack, -1); return; }); - push_int(st->stack, m->users); + map_foreachinarea(std::bind(builtin_getareausers_sub, ph::_1, &users), + m, + 0, 0, + m->xs, m->ys, + BL::PC); + push_int(st->stack, users); } /*========================================== * エリア指定ユーザー数所得 *------------------------------------------ */ -static -void builtin_getareausers_sub(dumb_ptr bl, int *users) -{ - if (bool(bl->is_player()->status.option & Opt0::HIDE)) - return; - (*users)++; -} static void builtin_getareausers_living_sub(dumb_ptr bl, int *users) -- cgit v1.2.3-70-g09d2