diff options
author | Haru <haru@dotalux.com> | 2018-07-24 05:22:42 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-24 05:22:42 +0200 |
commit | 1f1b82f737809a44aaabb98499293aa75eee8125 (patch) | |
tree | ddbe3ee0b93db54a5febe237524bdf4823596911 /src/map/map.c | |
parent | 019f60feb9272ac5a527c8cdb430c2328108417c (diff) | |
parent | 90f7ef5dfb75ba3d819a4ac93518ebeadcfe7cc5 (diff) | |
download | hercules-1f1b82f737809a44aaabb98499293aa75eee8125.tar.gz hercules-1f1b82f737809a44aaabb98499293aa75eee8125.tar.bz2 hercules-1f1b82f737809a44aaabb98499293aa75eee8125.tar.xz hercules-1f1b82f737809a44aaabb98499293aa75eee8125.zip |
Merge pull request #2107 from Asheraf/questinfo_vec
Questinfo System overhaul
Diffstat (limited to 'src/map/map.c')
-rw-r--r-- | src/map/map.c | 35 |
1 files changed, 10 insertions, 25 deletions
diff --git a/src/map/map.c b/src/map/map.c index 8ea059700..0124a3035 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -3681,8 +3681,7 @@ static void do_final_maps(void) if( map->list[i].channel ) channel->delete(map->list[i].channel); - if( map->list[i].qi_data ) - aFree(map->list[i].qi_data); + quest->questinfo_vector_clear(i); HPM->data_store_destroy(&map->list[i].hdata); } @@ -3752,11 +3751,7 @@ static void map_flags_init(void) map->list[i].short_damage_rate = 100; map->list[i].long_damage_rate = 100; - if( map->list[i].qi_data ) - aFree(map->list[i].qi_data); - - map->list[i].qi_data = NULL; - map->list[i].qi_count = 0; + VECTOR_INIT(map->list[i].qi_data); } } @@ -5972,34 +5967,24 @@ static int map_get_new_bonus_id(void) static void map_add_questinfo(int m, struct questinfo *qi) { - unsigned short i; - nullpo_retv(qi); Assert_retv(m >= 0 && m < map->count); - /* duplicate, override */ - for(i = 0; i < map->list[m].qi_count; i++) { - if( map->list[m].qi_data[i].nd == qi->nd ) - break; - } - - if( i == map->list[m].qi_count ) - RECREATE(map->list[m].qi_data, struct questinfo, ++map->list[m].qi_count); - memcpy(&map->list[m].qi_data[i], qi, sizeof(struct questinfo)); + VECTOR_ENSURE(map->list[m].qi_data, 1, 1); + VECTOR_PUSH(map->list[m].qi_data, *qi); } static bool map_remove_questinfo(int m, struct npc_data *nd) { unsigned short i; + nullpo_retr(false, nd); Assert_retr(false, m >= 0 && m < map->count); - for(i = 0; i < map->list[m].qi_count; i++) { - struct questinfo *qi = &map->list[m].qi_data[i]; - if( qi->nd == nd ) { - memset(&map->list[m].qi_data[i], 0, sizeof(struct questinfo)); - if( i != --map->list[m].qi_count ) { - memmove(&map->list[m].qi_data[i],&map->list[m].qi_data[i+1],sizeof(struct questinfo)*(map->list[m].qi_count-i)); - } + + for (i = 0; i < VECTOR_LENGTH(map->list[m].qi_data); i++) { + struct questinfo *qi_data = &VECTOR_INDEX(map->list[m].qi_data, i); + if (qi_data->nd == nd) { + VECTOR_ERASE(map->list[m].qi_data, i); return true; } } |