summaryrefslogtreecommitdiff
path: root/src/map
diff options
context:
space:
mode:
authorshennetsind <ind@henn.et>2014-01-12 16:38:51 -0200
committershennetsind <ind@henn.et>2014-01-12 16:38:51 -0200
commitd9c1629c753ae756ce32613a76e69b3a03970b8d (patch)
tree00a11a44ce2f8ea3d6a7fe230871ba7ac6c7d618 /src/map
parente117c581a6afab60fe77daa05f8d49ef2436a828 (diff)
downloadhercules-d9c1629c753ae756ce32613a76e69b3a03970b8d.tar.gz
hercules-d9c1629c753ae756ce32613a76e69b3a03970b8d.tar.bz2
hercules-d9c1629c753ae756ce32613a76e69b3a03970b8d.tar.xz
hercules-d9c1629c753ae756ce32613a76e69b3a03970b8d.zip
Follow up 95f13f3420822111f928ba6079fbc2061bd38c5f
Fixed handling of arrays with 1-member and on index[0]. Thanks to Haruna. Signed-off-by: shennetsind <ind@henn.et>
Diffstat (limited to 'src/map')
-rw-r--r--src/map/script.c32
1 files changed, 16 insertions, 16 deletions
diff --git a/src/map/script.c b/src/map/script.c
index a55b43791..529ea7d5c 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -2602,6 +2602,8 @@ void* get_val2(struct script_state* st, int64 uid, struct DBMap** ref) {
**/
void script_array_ensure_zero(struct script_state *st, struct map_session_data *sd, int64 uid, struct DBMap** ref) {
const char *name = script->get_str(script_getvarid(uid));
+ struct DBMap *src = script->array_src(st, sd ? sd : st->rid ? map->id2sd(st->rid) : NULL, name);\
+ struct script_array *sa = NULL;
bool insert = false;
if( sd ) /* when sd comes, st isn't available */
@@ -2620,22 +2622,20 @@ void script_array_ensure_zero(struct script_state *st, struct map_session_data *
}
}
- if( insert ) {
- struct script_array *sa = NULL;
- struct DBMap *src = script->array_src(st, sd ? sd : st->rid ? map->id2sd(st->rid) : NULL, name);
-
- if( src ) {
- if( (sa = idb_get(src, script_getvarid(uid)) ) ) {
- unsigned int i;
-
- ARR_FIND(0, sa->size, i, sa->members[i] == 0);
- if( i != sa->size )
- return;
-
- script->array_add_member(sa,0);
- } else {
- script->array_update(&src,reference_uid(script_getvarid(uid), 0),false);
+ if( src ) {
+ if( (sa = idb_get(src, script_getvarid(uid)) ) ) {
+ unsigned int i;
+
+ ARR_FIND(0, sa->size, i, sa->members[i] == 0);
+ if( i != sa->size ) {
+ if( !insert )
+ script->array_remove_member(src,sa,i);
+ return;
}
+
+ script->array_add_member(sa,0);
+ } else if( insert ) {
+ script->array_update(&src,reference_uid(script_getvarid(uid), 0),false);
}
}
}
@@ -2672,7 +2672,7 @@ unsigned int script_array_highest_key(struct script_state *st, struct map_sessio
highest_key = sa->members[i];
}
- return highest_key + 1;
+ return sa->size ? highest_key + 1 : 0;
}
}