summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2015-09-11 17:29:07 +0200
committerHaru <haru@dotalux.com>2015-11-14 17:55:16 +0100
commit7c787e8adde6a56bc32ab65e5d2cd5eb1e3deeaf (patch)
treea8dac718789612b6adc4e9a6c5ac5b3ab23f7614
parent650727ddf52650283652a021539cef5e0d0df05b (diff)
downloadhercules-7c787e8adde6a56bc32ab65e5d2cd5eb1e3deeaf.tar.gz
hercules-7c787e8adde6a56bc32ab65e5d2cd5eb1e3deeaf.tar.bz2
hercules-7c787e8adde6a56bc32ab65e5d2cd5eb1e3deeaf.tar.xz
hercules-7c787e8adde6a56bc32ab65e5d2cd5eb1e3deeaf.zip
Corrected an issue causing queue iterators not to return their last value
- Follow-up to 918b1123963ac2f91a4d074b092ceef1db71b4e8, a9042bf0bee2d2453058b22973bea8f335c5a201 - Thanks to Dastgir Signed-off-by: Haru <haru@dotalux.com>
-rw-r--r--doc/script_commands.txt6
-rw-r--r--src/map/script.c30
2 files changed, 25 insertions, 11 deletions
diff --git a/doc/script_commands.txt b/doc/script_commands.txt
index 218bb4803..28c218eba 100644
--- a/doc/script_commands.txt
+++ b/doc/script_commands.txt
@@ -9011,8 +9011,10 @@ even if you remove them from the queue.
---------------------------------------
*qicheck(<queue_iterator_id>);
-checks whether there is a next member in the iterator's queue, 1 when
-it does, 0 otherwise.
+
+Checks whether the current member in the iterator's queue exists.
+
+Returns 1 when it does, 0 otherwise.
---------------------------------------
diff --git a/src/map/script.c b/src/map/script.c
index 54d8d338d..61ee7e49f 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -19090,28 +19090,40 @@ BUILDIN(queueiterator) {
/* returns next/first member in the iterator, 0 if none */
BUILDIN(qiget) {
int idx = script_getnum(st, 2);
+ struct hQueueIterator *it = NULL;
- if( idx < 0 || idx >= script->hqis ) {
+ if (idx < 0 || idx >= script->hqis) {
ShowWarning("buildin_qiget: unknown queue iterator id %d\n",idx);
script_pushint(st, 0);
- } else if (script->hqi[idx].pos >= script->hqi[idx].items) {
- script_pushint(st, 0);
- } else {
- struct hQueueIterator *it = &script->hqi[idx];
- script_pushint(st, it->item[it->pos++]);
+ return true;
}
+ it = &script->hqi[idx];
+
+ if (it->pos >= it->items) {
+ if (it->pos == it->items)
+ ++it->pos; // Move beyond the last position to invalidate qicheck
+ script_pushint(st, 0);
+ return true;
+ }
+ script_pushint(st, it->item[it->pos++]);
return true;
}
/* Queue Iterator Check */
-/* returns 1:0 if there is a next member in the iterator */
+/* returns 1:0 if there is the current member in the iterator exists */
BUILDIN(qicheck) {
int idx = script_getnum(st, 2);
+ struct hQueueIterator *it = NULL;
- if( idx < 0 || idx >= script->hqis ) {
+ if (idx < 0 || idx >= script->hqis) {
ShowWarning("buildin_qicheck: unknown queue iterator id %d\n",idx);
script_pushint(st, 0);
- } else if (script->hqi[idx].pos >= script->hqi[idx].items) {
+ return true;
+ }
+
+ it = &script->hqi[idx];
+
+ if (it->pos <= 0 || it->pos > it->items) {
script_pushint(st, 0);
} else {
script_pushint(st, 1);