summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAsheraf <acheraf1998@gmail.com>2018-06-25 06:08:51 +0100
committerAsheraf <acheraf1998@gmail.com>2018-07-24 02:15:37 +0100
commit620c55e87019a46ffffc6ffb69bea77df088b904 (patch)
treea7171972c1b207778ce2dc9ac944477ff759ae76
parentbb301746703582be9f7c30b969f03c1ab14d1228 (diff)
downloadhercules-620c55e87019a46ffffc6ffb69bea77df088b904.tar.gz
hercules-620c55e87019a46ffffc6ffb69bea77df088b904.tar.bz2
hercules-620c55e87019a46ffffc6ffb69bea77df088b904.tar.xz
hercules-620c55e87019a46ffffc6ffb69bea77df088b904.zip
Convert questinfo data into a vector
-rw-r--r--src/map/clif.c4
-rw-r--r--src/map/instance.c11
-rw-r--r--src/map/map.c39
-rw-r--r--src/map/map.h3
-rw-r--r--src/map/script.c4
5 files changed, 27 insertions, 34 deletions
diff --git a/src/map/clif.c b/src/map/clif.c
index 904bfdd68..061cb7073 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -10066,8 +10066,8 @@ static void clif_parse_LoadEndAck(int fd, struct map_session_data *sd)
#if PACKETVER >= 20090218
{
int i;
- for(i = 0; i < map->list[sd->bl.m].qi_count; i++) {
- struct questinfo *qi = &map->list[sd->bl.m].qi_data[i];
+ for (i = 0; i < VECTOR_LENGTH(map->list[sd->bl.m].qi_data); i++) {
+ struct questinfo *qi = &VECTOR_INDEX(map->list[sd->bl.m].qi_data, i);
if( quest->check(sd, qi->quest_id, HAVEQUEST) == -1 ) {// Check if quest is not started
if( qi->hasJob ) { // Check if quest is job-specific, check is user is said job class.
if (sd->status.class == qi->job)
diff --git a/src/map/instance.c b/src/map/instance.c
index 2c40449ad..9b0ca3ddd 100644
--- a/src/map/instance.c
+++ b/src/map/instance.c
@@ -295,10 +295,10 @@ static int instance_add_map(const char *name, int instance_id, bool usebasename,
}
//Mimic questinfo
- if( map->list[m].qi_count ) {
- map->list[im].qi_count = map->list[m].qi_count;
- CREATE( map->list[im].qi_data, struct questinfo, map->list[im].qi_count );
- memcpy( map->list[im].qi_data, map->list[m].qi_data, map->list[im].qi_count * sizeof(struct questinfo) );
+ VECTOR_INIT(map->list[im].qi_data);
+ VECTOR_ENSURE(map->list[im].qi_data, VECTOR_LENGTH(map->list[m].qi_data), 1);
+ for (i = 0; i < VECTOR_LENGTH(map->list[m].qi_data); i++) {
+ VECTOR_PUSH(map->list[im].qi_data, VECTOR_INDEX(map->list[m].qi_data, i));
}
map->list[im].m = im;
@@ -517,8 +517,7 @@ static void instance_del_map(int16 m)
aFree(map->list[m].zone_mf);
}
- if( map->list[m].qi_data )
- aFree(map->list[m].qi_data);
+ VECTOR_CLEAR(map->list[m].qi_data);
// Remove from instance
for( i = 0; i < instance->list[map->list[m].instance_id].num_map; i++ ) {
diff --git a/src/map/map.c b/src/map/map.c
index 8ea059700..a0dfdb886 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);
+ VECTOR_CLEAR(map->list[i].qi_data);
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);
}
}
@@ -5976,30 +5971,30 @@ static void map_add_questinfo(int m, struct questinfo *qi)
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;
+ 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 == qi->nd) {
+ VECTOR_INDEX(map->list[m].qi_data, i) = *qi;
+ return;
+ }
}
-
- 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;
}
}
diff --git a/src/map/map.h b/src/map/map.h
index d6779ca91..b8956d72c 100644
--- a/src/map/map.h
+++ b/src/map/map.h
@@ -922,8 +922,7 @@ struct map_data {
} cell_buf;
/* ShowEvent Data Cache */
- struct questinfo *qi_data;
- unsigned short qi_count;
+ VECTOR_DECL(struct questinfo) qi_data;
/* speeds up clif_updatestatus processing by causing hpmeter to run only when someone with the permission can view it */
unsigned short hpmeter_visible;
diff --git a/src/map/script.c b/src/map/script.c
index e678a7738..4dc4ee333 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -20985,8 +20985,8 @@ static BUILDIN(setquest)
quest->add(sd, quest_id, time_limit);
// If questinfo is set, remove quest bubble once quest is set.
- for (i = 0; i < map->list[sd->bl.m].qi_count; i++) {
- struct questinfo *qi = &map->list[sd->bl.m].qi_data[i];
+ for (i = 0; i < VECTOR_LENGTH(map->list[sd->bl.m].qi_data); i++) {
+ struct questinfo *qi = &VECTOR_INDEX(map->list[sd->bl.m].qi_data, i);
if (qi->quest_id == quest_id) {
#if PACKETVER >= 20120410
clif->quest_show_event(sd, &qi->nd->bl, 9999, 0);