From 620c55e87019a46ffffc6ffb69bea77df088b904 Mon Sep 17 00:00:00 2001 From: Asheraf Date: Mon, 25 Jun 2018 06:08:51 +0100 Subject: Convert questinfo data into a vector --- src/map/clif.c | 4 ++-- src/map/instance.c | 11 +++++------ src/map/map.c | 39 +++++++++++++++++---------------------- src/map/map.h | 3 +-- src/map/script.c | 4 ++-- 5 files changed, 27 insertions(+), 34 deletions(-) (limited to 'src/map') 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); -- cgit v1.2.3-60-g2f50 From 7c43dd908622e083b0fecf7fc8ebab61501186fa Mon Sep 17 00:00:00 2001 From: Asheraf Date: Mon, 25 Jun 2018 21:00:42 +0100 Subject: Questinfo System overhaul --- doc/script_commands.txt | 29 +++-- src/common/mmo.h | 14 +++ src/map/clif.c | 11 +- src/map/homunculus.c | 5 +- src/map/instance.c | 3 +- src/map/map.c | 12 +- src/map/map.h | 19 +++- src/map/pc.c | 5 + src/map/quest.c | 291 +++++++++++++++++++++++++++++++++++++++++++++++- src/map/quest.h | 14 +++ src/map/script.c | 208 ++++++++++++++++++++++++++-------- 11 files changed, 532 insertions(+), 79 deletions(-) (limited to 'src/map') diff --git a/doc/script_commands.txt b/doc/script_commands.txt index 2653f052a..44937a34d 100644 --- a/doc/script_commands.txt +++ b/doc/script_commands.txt @@ -9337,12 +9337,10 @@ that fails, the command returns an empty string instead. //===================================== --------------------------------------- -*questinfo(, {, {, }}) - -This is esentially a combination of questprogress() and showevent(). Use this only -in an OnInit label. For the Quest ID, specify the quest ID that you want -checked if it has been started yet. +*questinfo( {, }) +This is esentially a showevent() that supports different conditions that can be set using setquestinfo(). +Use this only in an OnInit label. For Icon, use one of the following: No Icon : QTYPE_NONE @@ -9373,8 +9371,6 @@ the available color values are: When a user shows up on a map, each NPC is checked for questinfo that has been set. If questinfo is present, it will check if the quest has been started, if it has not, the bubble will appear. -Optionally, you can also specify a Job Class if the quest bubble should only appear for a certain class. - Example izlude,100,100,4 script Test 844,{ mes("[Test]"); @@ -9382,12 +9378,29 @@ Example close(); OnInit: - questinfo(1001, QTYPE_QUEST, 0, Job_Novice); + questinfo(QTYPE_QUEST); end; } --------------------------------------- +*setquestinfo( {, }) + +Use this command ONLY after a questinfo() +it allows you to set multiple required conditions for the quest bubble to show up. + +supported types: values + QINFO_JOB: job_id + QINFO_SEX: sex + QINFO_BASE_LEVEL: min, max + QINFO_JOB_LEVEL: min, max + QINFO_ITEM: item_id, amount // append to the items list on each use + QINFO_HOMUN_LEVEL: min + QINFO_HOMUN_TYPE: homunculus_type (0 - regular, 1 - evolved, 2 - S) + QINFO_QUEST: quest_id, state // append to the quests list on each use + +--------------------------------------- + *setquest({,