diff options
author | Haru <haru@dotalux.com> | 2015-09-14 16:13:00 +0200 |
---|---|---|
committer | Haru <haru@dotalux.com> | 2015-11-14 21:13:02 +0100 |
commit | 1d064776214d3f962b9af585555cca686906665a (patch) | |
tree | c5884040cc4345e2364b46de4bf3d4d394f5077e /src | |
parent | cd47c20adfcc1cdfe25fb09937dd175008d71f9f (diff) | |
download | hercules-1d064776214d3f962b9af585555cca686906665a.tar.gz hercules-1d064776214d3f962b9af585555cca686906665a.tar.bz2 hercules-1d064776214d3f962b9af585555cca686906665a.tar.xz hercules-1d064776214d3f962b9af585555cca686906665a.zip |
Changed struct script_queue_iterator::item into a VECTOR and Renamed to ::entries
Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/map/script.c | 36 | ||||
-rw-r--r-- | src/map/script.h | 6 |
2 files changed, 23 insertions, 19 deletions
diff --git a/src/map/script.c b/src/map/script.c index ac981dbbd..bf477968c 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -4633,9 +4633,7 @@ void do_final_script(void) { VECTOR_CLEAR(script->hq); for (i = 0; i < VECTOR_LENGTH(script->hqi); i++) { - if (VECTOR_INDEX(script->hqi, i).item != NULL) { - aFree(VECTOR_INDEX(script->hqi, i).item); - } + VECTOR_CLEAR(VECTOR_INDEX(script->hqi, i).entries); } VECTOR_CLEAR(script->hqi); @@ -19142,7 +19140,7 @@ BUILDIN(queueiterator) return true; } - ARR_FIND(0, VECTOR_LENGTH(script->hqi), i, VECTOR_INDEX(script->hqi, i).items == -1); + ARR_FIND(0, VECTOR_LENGTH(script->hqi), i, !VECTOR_INDEX(script->hqi, i).valid); if (i == VECTOR_LENGTH(script->hqi)) { VECTOR_ENSURE(script->hqi, 1, 1); @@ -19151,11 +19149,11 @@ BUILDIN(queueiterator) iter = &VECTOR_INDEX(script->hqi, i); - RECREATE(iter->item, int, VECTOR_LENGTH(queue->entries)); - memcpy(iter->item, VECTOR_DATA(queue->entries), sizeof(VECTOR_FIRST(queue->entries))*VECTOR_LENGTH(queue->entries)); + VECTOR_ENSURE(iter->entries, VECTOR_LENGTH(queue->entries), 1); + VECTOR_PUSHARRAY(iter->entries, VECTOR_DATA(queue->entries), VECTOR_LENGTH(queue->entries)); - iter->items = VECTOR_LENGTH(queue->entries); iter->pos = 0; + iter->valid = true; script_pushint(st, i); return true; @@ -19177,7 +19175,7 @@ BUILDIN(qiget) int idx = script_getnum(st, 2); struct script_queue_iterator *it = NULL; - if (idx < 0 || idx >= VECTOR_LENGTH(script->hqi)) { + if (idx < 0 || idx >= VECTOR_LENGTH(script->hqi) || !VECTOR_INDEX(script->hqi, idx).valid) { ShowWarning("buildin_qiget: unknown queue iterator id %d\n",idx); script_pushint(st, 0); return true; @@ -19185,18 +19183,18 @@ BUILDIN(qiget) it = &VECTOR_INDEX(script->hqi, idx); - if (it->pos >= it->items) { - if (it->pos == it->items) + if (it->pos >= VECTOR_LENGTH(it->entries)) { + if (it->pos == VECTOR_LENGTH(it->entries)) ++it->pos; // Move beyond the last position to invalidate qicheck script_pushint(st, 0); return true; } - script_pushint(st, it->item[it->pos++]); + script_pushint(st, VECTOR_INDEX(it->entries, it->pos++)); return true; } /** - * Script command qicheck: Checks if the current member in the given iterator exists. + * Script command qicheck: Checks if the current member in the given iterator (from the last call to qiget) exists. * * Returns 1 if it exists, 0 otherwise. * @@ -19211,7 +19209,7 @@ BUILDIN(qicheck) int idx = script_getnum(st, 2); struct script_queue_iterator *it = NULL; - if (idx < 0 || idx >= VECTOR_LENGTH(script->hqi)) { + if (idx < 0 || idx >= VECTOR_LENGTH(script->hqi) || !VECTOR_INDEX(script->hqi, idx).valid) { ShowWarning("buildin_qicheck: unknown queue iterator id %d\n",idx); script_pushint(st, 0); return true; @@ -19219,7 +19217,7 @@ BUILDIN(qicheck) it = &VECTOR_INDEX(script->hqi, idx); - if (it->pos <= 0 || it->pos > it->items) { + if (it->pos <= 0 || it->pos > VECTOR_LENGTH(it->entries)) { script_pushint(st, 0); } else { script_pushint(st, 1); @@ -19240,14 +19238,20 @@ BUILDIN(qicheck) BUILDIN(qiclear) { int idx = script_getnum(st, 2); + struct script_queue_iterator *it = NULL; - if (idx < 0 || idx >= VECTOR_LENGTH(script->hqi)) { + if (idx < 0 || idx >= VECTOR_LENGTH(script->hqi) || !VECTOR_INDEX(script->hqi, idx).valid) { ShowWarning("buildin_qiclear: unknown queue iterator id %d\n",idx); script_pushint(st, 0); return true; } - VECTOR_INDEX(script->hqi, idx).items = -1; + it = &VECTOR_INDEX(script->hqi, idx); + + VECTOR_CLEAR(it->entries); + it->pos = 0; + it->valid = false; + script_pushint(st, 1); return true; } diff --git a/src/map/script.h b/src/map/script.h index 6b728ab88..b153cf81a 100644 --- a/src/map/script.h +++ b/src/map/script.h @@ -410,9 +410,9 @@ struct script_queue { * Iterator for a struct script_queue. */ struct script_queue_iterator { - int *item; ///< Items in the queue (iterator's cached copy) - int items; ///< Amount of elements in \c item - int pos; ///< Iterator's cursor + VECTOR_DECL(int) entries; ///< Entries in the queue (iterator's cached copy) + bool valid; ///< Whether the queue is valid (initialized - not necessarily having entries available) + int pos; ///< Iterator's cursor }; struct script_state { |