summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2017-04-09 00:53:14 +0200
committerGitHub <noreply@github.com>2017-04-09 00:53:14 +0200
commit2e23268d5c3c73baa91dbdb3d059c8c4d1cdab58 (patch)
tree17ab808ae60887f7eb299b0151c65c72b591871c /src
parentff56322529c290be85a44fda7914a70b31694132 (diff)
parent7580593b6c5d8bcb63befb0027609255ab255ef6 (diff)
downloadhercules-2e23268d5c3c73baa91dbdb3d059c8c4d1cdab58.tar.gz
hercules-2e23268d5c3c73baa91dbdb3d059c8c4d1cdab58.tar.bz2
hercules-2e23268d5c3c73baa91dbdb3d059c8c4d1cdab58.tar.xz
hercules-2e23268d5c3c73baa91dbdb3d059c8c4d1cdab58.zip
Merge pull request #1657 from mekolat/getunits2
add getunits() buildin
Diffstat (limited to 'src')
-rw-r--r--src/map/script.c100
1 files changed, 100 insertions, 0 deletions
diff --git a/src/map/script.c b/src/map/script.c
index 25f520450..ff28385eb 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -10955,6 +10955,91 @@ BUILDIN(gettimer)
return true;
}
+int buildin_getunits_sub(struct block_list *bl, va_list ap)
+{
+ struct script_state *st = va_arg(ap, struct script_state *);
+ struct map_session_data *sd = va_arg(ap, struct map_session_data *);
+ int32 id = va_arg(ap, int32);
+ uint32 start = va_arg(ap, uint32);
+ uint32 *count = va_arg(ap, uint32 *);
+ uint32 limit = va_arg(ap, uint32);
+ const char *name = va_arg(ap, const char *);
+ struct reg_db *ref = va_arg(ap, struct reg_db *);
+ uint32 index = start + *count;
+
+ if (index >= SCRIPT_MAX_ARRAYSIZE || *count > limit) {
+ return 1;
+ }
+
+ script->set_reg(st, sd, reference_uid(id, index), name,
+ (const void *)h64BPTRSIZE(bl->id), ref);
+
+ (*count)++;
+ return 0;
+}
+
+BUILDIN(getunits)
+{
+ const char *mapname, *name;
+ int16 m, x1, y1, x2, y2;
+ int32 id;
+ uint32 start;
+ struct reg_db *ref;
+ enum bl_type type = script_getnum(st, 2);
+ struct script_data *data = script_getdata(st, 3);
+ uint32 count = 0, limit = script_getnum(st, 4);
+ struct map_session_data *sd = NULL;
+
+ if (!data_isreference(data) || reference_toconstant(data)) {
+ ShowError("script:getunits: second argument must be a variable\n");
+ script->reportdata(data);
+ st->state = END;
+ return false;
+ }
+
+ id = reference_getid(data);
+ start = reference_getindex(data);
+ name = reference_getname(data);
+ ref = reference_getref(data);
+
+ if (not_server_variable(*name)) {
+ sd = script->rid2sd(st);
+ if (sd == NULL) {
+ return true; // player variable but no player attached
+ }
+ }
+
+ if (is_string_variable(name)) {
+ ShowError("script:getunits: second argument must be an integer variable\n");
+ script->reportdata(data);
+ st->state = END;
+ return false;
+ }
+
+ if (limit < 1 || limit > SCRIPT_MAX_ARRAYSIZE) {
+ limit = SCRIPT_MAX_ARRAYSIZE;
+ }
+
+ mapname = script_getstr(st, 5);
+ m = map->mapname2mapid(mapname);
+
+ if (script_hasdata(st, 9)) {
+ x1 = script_getnum(st, 6);
+ y1 = script_getnum(st, 7);
+ x2 = script_getnum(st, 8);
+ y2 = script_getnum(st, 9);
+
+ map->foreachinarea(buildin_getunits_sub, m, x1, y1, x2, y2, type,
+ st, sd, id, start, &count, limit, name, ref);
+ } else {
+ map->foreachinmap(buildin_getunits_sub, m, type,
+ st, sd, id, start, &count, limit, name, ref);
+ }
+
+ script_pushint(st, count);
+ return true;
+}
+
/*==========================================
*------------------------------------------*/
BUILDIN(initnpctimer)
@@ -21212,6 +21297,7 @@ void script_parse_builtin(void) {
BUILDIN_DEF(deltimer,"s?"),
BUILDIN_DEF(addtimercount,"si?"),
BUILDIN_DEF(gettimer,"i??"),
+ BUILDIN_DEF(getunits,"iris????"),
BUILDIN_DEF(initnpctimer,"??"),
BUILDIN_DEF(stopnpctimer,"??"),
BUILDIN_DEF(startnpctimer,"??"),
@@ -21763,6 +21849,20 @@ void script_hardcoded_constants(void)
script->set_constant("NAV_KAFRA_AND_SCROLL", NAV_KAFRA_AND_SCROLL, false, false);
script->set_constant("NAV_ALL", NAV_ALL, false, false);
+ script->constdb_comment("BL types");
+ script->set_constant("BL_PC",BL_PC,false, false);
+ script->set_constant("BL_MOB",BL_MOB,false, false);
+ script->set_constant("BL_PET",BL_PET,false, false);
+ script->set_constant("BL_HOM",BL_HOM,false, false);
+ script->set_constant("BL_MER",BL_MER,false, false);
+ script->set_constant("BL_ITEM",BL_ITEM,false, false);
+ script->set_constant("BL_SKILL",BL_SKILL,false, false);
+ script->set_constant("BL_NPC",BL_NPC,false, false);
+ script->set_constant("BL_CHAT",BL_CHAT,false, false);
+ script->set_constant("BL_ELEM",BL_ELEM,false, false);
+ script->set_constant("BL_CHAR",BL_CHAR,false, false);
+ script->set_constant("BL_ALL",BL_ALL,false, false);
+
script->constdb_comment("Renewal");
#ifdef RENEWAL
script->set_constant("RENEWAL", 1, false, false);