Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move questinfo data from map to npc_data #2433

Merged
merged 3 commits into from Jun 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/common/HPMDataCheck.h
Expand Up @@ -571,9 +571,6 @@ HPExport const struct s_HPMDataCheck HPMDataCheck[] = {
{ "mapcell", sizeof(struct mapcell), SERVER_TYPE_MAP },
{ "mapflag_skill_adjust", sizeof(struct mapflag_skill_adjust), SERVER_TYPE_MAP },
{ "mapit_interface", sizeof(struct mapit_interface), SERVER_TYPE_MAP },
{ "questinfo", sizeof(struct questinfo), SERVER_TYPE_MAP },
{ "questinfo_itemreq", sizeof(struct questinfo_itemreq), SERVER_TYPE_MAP },
{ "questinfo_qreq", sizeof(struct questinfo_qreq), SERVER_TYPE_MAP },
{ "spawn_data", sizeof(struct spawn_data), SERVER_TYPE_MAP },
#else
#define MAP_MAP_H
Expand Down Expand Up @@ -889,6 +886,9 @@ HPExport const struct s_HPMDataCheck HPMDataCheck[] = {
{ "quest_dropitem", sizeof(struct quest_dropitem), SERVER_TYPE_MAP },
{ "quest_interface", sizeof(struct quest_interface), SERVER_TYPE_MAP },
{ "quest_objective", sizeof(struct quest_objective), SERVER_TYPE_MAP },
{ "questinfo", sizeof(struct questinfo), SERVER_TYPE_MAP },
{ "questinfo_itemreq", sizeof(struct questinfo_itemreq), SERVER_TYPE_MAP },
{ "questinfo_qreq", sizeof(struct questinfo_qreq), SERVER_TYPE_MAP },
#else
#define MAP_QUEST_H
#endif // MAP_QUEST_H
Expand Down
10 changes: 1 addition & 9 deletions src/map/clif.c
Expand Up @@ -10759,15 +10759,7 @@ static void clif_parse_LoadEndAck(int fd, struct map_session_data *sd)

// NPC Quest / Event Icon Check [Kisuka]
#if PACKETVER >= 20090218
{
int 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->questinfo_validate(sd, qi))
clif->quest_show_event(sd, &qi->nd->bl, qi->icon, qi->color);
}
}
quest->questinfo_refresh(sd);
#endif
}

Expand Down
9 changes: 1 addition & 8 deletions src/map/instance.c
Expand Up @@ -295,13 +295,6 @@ static int instance_add_map(const char *name, int instance_id, bool usebasename,
}
}

//Mimic 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;
map->list[im].instance_id = instance_id;
map->list[im].instance_src_map = m;
Expand Down Expand Up @@ -518,7 +511,7 @@ static void instance_del_map(int16 m)
aFree(map->list[m].zone_mf);
}

quest->questinfo_vector_clear(m);
VECTOR_CLEAR(map->list[m].qi_list);

// Remove from instance
for( i = 0; i < instance->list[map->list[m].instance_id].num_map; i++ ) {
Expand Down
153 changes: 53 additions & 100 deletions src/map/map.c
Expand Up @@ -3586,23 +3586,27 @@ static void map_zone_db_clear(void)
}
static void map_clean(int i)
{
int v;
Assert_retv(i >= 0 && i < map->count);
if(map->list[i].cell && map->list[i].cell != (struct mapcell *)0xdeadbeaf) aFree(map->list[i].cell);
if(map->list[i].block) aFree(map->list[i].block);
if(map->list[i].block_mob) aFree(map->list[i].block_mob);

if(battle_config.dynamic_mobs) { //Dynamic mobs flag by [random]
int j;
if(map->list[i].mob_delete_timer != INVALID_TIMER)
if (map->list[i].cell && map->list[i].cell != (struct mapcell *)0xdeadbeaf)
aFree(map->list[i].cell);
if (map->list[i].block)
aFree(map->list[i].block);
if (map->list[i].block_mob)
aFree(map->list[i].block_mob);

if (battle_config.dynamic_mobs != 0) { //Dynamic mobs flag by [random]
if (map->list[i].mob_delete_timer != INVALID_TIMER)
timer->delete(map->list[i].mob_delete_timer, map->removemobs_timer);
for (j=0; j<MAX_MOB_LIST_PER_MAP; j++)
if (map->list[i].moblist[j]) aFree(map->list[i].moblist[j]);
for (int j = 0; j < MAX_MOB_LIST_PER_MAP; j++) {
if (map->list[i].moblist[j] != NULL)
aFree(map->list[i].moblist[j]);
}
}

if( map->list[i].unit_count ) {
if( map->list[i].units ) {
for(v = 0; v < map->list[i].unit_count; v++) {
if (map->list[i].unit_count != 0) {
if (map->list[i].units != NULL) {
for (int v = 0; v < map->list[i].unit_count; v++) {
aFree(map->list[i].units[v]);
}
aFree(map->list[i].units);
Expand All @@ -3611,98 +3615,44 @@ static void map_clean(int i)
map->list[i].unit_count = 0;
}

if( map->list[i].skill_count ) {
if( map->list[i].skills ) {
for(v = 0; v < map->list[i].skill_count; v++) {
aFree(map->list[i].skills[v]);
}
if (map->list[i].skill_count != 0) {
if (map->list[i].skills != NULL) {
for (int v = 0; v < map->list[i].skill_count; v++) {
aFree(map->list[i].skills[v]);
}
aFree(map->list[i].skills);
map->list[i].skills = NULL;
}
map->list[i].skill_count = 0;
}

if( map->list[i].zone_mf_count ) {
if( map->list[i].zone_mf ) {
for(v = 0; v < map->list[i].zone_mf_count; v++) {
aFree(map->list[i].zone_mf[v]);
}
if (map->list[i].zone_mf_count != 0) {
if (map->list[i].zone_mf != NULL) {
for (int v = 0; v < map->list[i].zone_mf_count; v++) {
aFree(map->list[i].zone_mf[v]);
}
aFree(map->list[i].zone_mf);
map->list[i].zone_mf = NULL;
}
map->list[i].zone_mf_count = 0;
}

if( map->list[i].channel )
if (map->list[i].drop_list_count != 0)
map->list[i].drop_list_count = 0;
if (map->list[i].drop_list != NULL)
aFree(map->list[i].drop_list);

if (map->list[i].channel != NULL)
channel->delete(map->list[i].channel);

VECTOR_CLEAR(map->list[i].qi_list);
HPM->data_store_destroy(&map->list[i].hdata);
}
static void do_final_maps(void)
{
int i, v = 0;

for( i = 0; i < map->count; i++ ) {

if(map->list[i].cell && map->list[i].cell != (struct mapcell *)0xdeadbeaf ) aFree(map->list[i].cell);
if(map->list[i].block) aFree(map->list[i].block);
if(map->list[i].block_mob) aFree(map->list[i].block_mob);

if(battle_config.dynamic_mobs) { //Dynamic mobs flag by [random]
int j;
if(map->list[i].mob_delete_timer != INVALID_TIMER)
timer->delete(map->list[i].mob_delete_timer, map->removemobs_timer);
for (j=0; j<MAX_MOB_LIST_PER_MAP; j++)
if (map->list[i].moblist[j]) aFree(map->list[i].moblist[j]);
}

if( map->list[i].unit_count ) {
if( map->list[i].units ) {
for(v = 0; v < map->list[i].unit_count; v++) {
aFree(map->list[i].units[v]);
}
aFree(map->list[i].units);
map->list[i].units = NULL;
}
map->list[i].unit_count = 0;
}

if( map->list[i].skill_count ) {
if( map->list[i].skills ) {
for(v = 0; v < map->list[i].skill_count; v++) {
aFree(map->list[i].skills[v]);
}
aFree(map->list[i].skills);
map->list[i].skills = NULL;
}
map->list[i].skill_count = 0;
}

if( map->list[i].zone_mf_count ) {
if( map->list[i].zone_mf ) {
for(v = 0; v < map->list[i].zone_mf_count; v++) {
aFree(map->list[i].zone_mf[v]);
}
aFree(map->list[i].zone_mf);
map->list[i].zone_mf = NULL;
}
map->list[i].zone_mf_count = 0;
}

if( map->list[i].drop_list_count ) {
map->list[i].drop_list_count = 0;
}
if( map->list[i].drop_list != NULL )
aFree(map->list[i].drop_list);

if( map->list[i].channel )
channel->delete(map->list[i].channel);

quest->questinfo_vector_clear(i);

HPM->data_store_destroy(&map->list[i].hdata);
}

for (int i = 0; i < map->count; i++)
map->clean(i);
map->zone_db_clear();

}

static void map_zonedb_reload(void)
Expand Down Expand Up @@ -3793,7 +3743,8 @@ static void map_flags_init(void)
map->list[i].short_damage_rate = 100;
map->list[i].long_damage_rate = 100;

VECTOR_INIT(map->list[i].qi_data);
VECTOR_CLEAR(map->list[i].qi_list);
VECTOR_INIT(map->list[i].qi_list);
}
}

Expand Down Expand Up @@ -6029,28 +5980,30 @@ static int map_get_new_bonus_id(void)
return map->bonus_id++;
}

static void map_add_questinfo(int m, struct questinfo *qi)
static bool map_add_questinfo(int m, struct npc_data *nd)
{
nullpo_retv(qi);
Assert_retv(m >= 0 && m < map->count);
nullpo_retr(false, nd);
Assert_retr(false, m >= 0 && m < map->count);

VECTOR_ENSURE(map->list[m].qi_data, 1, 1);
VECTOR_PUSH(map->list[m].qi_data, *qi);
if (&VECTOR_LAST(map->list[m].qi_list) == nd)
return false;

VECTOR_ENSURE(map->list[m].qi_list, 1, 1);
VECTOR_PUSH(map->list[m].qi_list, *nd);
return true;
}

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 < 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;
}
int i;
ARR_FIND(0, VECTOR_LENGTH(map->list[m].qi_list), i, &VECTOR_INDEX(map->list[m].qi_list, i) == nd);
if (i != VECTOR_LENGTH(map->list[m].qi_list)) {
VECTOR_ERASE(map->list[m].qi_list, i);
return true;
}
return false;
}
Expand Down
41 changes: 3 additions & 38 deletions src/map/map.h
Expand Up @@ -705,41 +705,6 @@ struct map_drop_list {
int drop_per;
};

struct questinfo_qreq {
int id;
int state;
};

struct questinfo_itemreq {
int nameid;
int min;
int max;
};

struct questinfo {
struct npc_data *nd;
unsigned short icon;
unsigned char color;
bool hasJob;
unsigned int job;/* perhaps a mapid mask would be most flexible? */
bool sex_enabled;
int sex;
struct {
int min;
int max;
} base_level;
struct {
int min;
int max;
} job_level;
VECTOR_DECL(struct questinfo_itemreq) items;
struct s_homunculus homunculus;
int homunculus_type;
VECTOR_DECL(struct questinfo_qreq) quest_requirement;
int mercenary_class;
};


struct map_data {
char name[MAP_NAME_LENGTH];
uint16 index; // The map index used by the mapindex* functions.
Expand Down Expand Up @@ -877,8 +842,8 @@ struct map_data {
int len;
} cell_buf;

/* ShowEvent Data Cache */
VECTOR_DECL(struct questinfo) qi_data;
/* questinfo entries list */
VECTOR_DECL(struct npc_data) qi_list;

/* speeds up clif_updatestatus processing by causing hpmeter to run only when someone with the permission can view it */
unsigned short hpmeter_visible;
Expand Down Expand Up @@ -1312,7 +1277,7 @@ END_ZEROED_BLOCK;
int (*abort_sub) (struct map_session_data *sd, va_list ap);
void (*update_cell_bl) (struct block_list *bl, bool increase);
int (*get_new_bonus_id) (void);
void (*add_questinfo) (int m, struct questinfo *qi);
bool (*add_questinfo) (int m, struct npc_data *nd);
bool (*remove_questinfo) (int m, struct npc_data *nd);
struct map_zone_data *(*merge_zone) (struct map_zone_data *main, struct map_zone_data *other);
void (*zone_clear_single) (struct map_zone_data *zone);
Expand Down
20 changes: 18 additions & 2 deletions src/map/npc.c
Expand Up @@ -36,6 +36,7 @@
#include "map/mob.h"
#include "map/pc.h"
#include "map/pet.h"
#include "map/quest.h"
#include "map/script.h"
#include "map/skill.h"
#include "map/status.h"
Expand Down Expand Up @@ -2638,8 +2639,9 @@ static int npc_unload(struct npc_data *nd, bool single)
nd->path = NULL;
}

if( single && nd->bl.m != -1 )
map->remove_questinfo(nd->bl.m,nd);
if (single && nd->bl.m != -1)
map->remove_questinfo(nd->bl.m, nd);
npc->questinfo_clear(nd);

if (nd->src_id == 0 && ( nd->subtype == SHOP || nd->subtype == CASHSHOP)) {
//src check for duplicate shops [Orcao]
Expand Down Expand Up @@ -2978,6 +2980,7 @@ static struct npc_data *npc_create_npc(enum npc_subtype subtype, int m, int x, i
nd->class_ = class_;
nd->speed = 200;
nd->vd = npc_viewdb[0]; // Copy INVISIBLE_CLASS view data. Actual view data is set by npc->add_to_location() later.
VECTOR_INIT(nd->qi_data);

return nd;
}
Expand Down Expand Up @@ -5331,6 +5334,18 @@ static void npc_debug_warps(void)
npc->debug_warps_sub(map->list[m].npc[i]);
}

static void npc_questinfo_clear(struct npc_data *nd)
{
nullpo_retv(nd);

for (int i = 0; i < VECTOR_LENGTH(nd->qi_data); i++) {
struct questinfo *qi = &VECTOR_INDEX(nd->qi_data, i);
VECTOR_CLEAR(qi->items);
VECTOR_CLEAR(qi->quest_requirement);
}
VECTOR_CLEAR(nd->qi_data);
}

/*==========================================
* npc initialization
*------------------------------------------*/
Expand Down Expand Up @@ -5551,4 +5566,5 @@ void npc_defaults(void)
npc->barter_delfromsql_sub = npc_barter_delfromsql_sub;
npc->db_checkid = npc_db_checkid;
npc->refresh = npc_refresh;
npc->questinfo_clear = npc_questinfo_clear;
}