diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/map/mob.c | 9 | ||||
-rw-r--r-- | src/map/npc.c | 60 | ||||
-rw-r--r-- | src/map/npc.h | 1 |
3 files changed, 24 insertions, 46 deletions
diff --git a/src/map/mob.c b/src/map/mob.c index cb22f71c0..629653c8d 100644 --- a/src/map/mob.c +++ b/src/map/mob.c @@ -141,14 +141,9 @@ void mvptomb_create(struct mob_data *md, char *killer, time_t time) if ( md->tomb_nid ) mob->mvptomb_destroy(md); - CREATE(nd, struct npc_data, 1); - - nd->bl.id = md->tomb_nid = npc->get_new_npc_id(); - + nd = npc->create_npc(md->bl.m, md->bl.x, md->bl.y); + md->tomb_nid = nd->bl.id; nd->dir = md->ud.dir; - nd->bl.m = md->bl.m; - nd->bl.x = md->bl.x; - nd->bl.y = md->bl.y; nd->bl.type = BL_NPC; safestrncpy(nd->name, msg_txt(856), sizeof(nd->name)); // "Tomb" diff --git a/src/map/npc.c b/src/map/npc.c index 869a33509..8c2f61d58 100644 --- a/src/map/npc.c +++ b/src/map/npc.c @@ -2495,18 +2495,27 @@ bool npc_viewisid(const char * viewid) return true; } +struct npc_data* npc_create_npc(int m, int x, int y) +{ + struct npc_data *nd; + + CREATE(nd, struct npc_data, 1); + nd->bl.id = npc->get_new_npc_id(); + nd->bl.prev = nd->bl.next = NULL; + nd->bl.m = m; + nd->bl.x = x; + nd->bl.y = y; + + return nd; +} + //Add then display an npc warp on map struct npc_data* npc_add_warp(char* name, short from_mapid, short from_x, short from_y, short xs, short ys, unsigned short to_mapindex, short to_x, short to_y) { int i, flag = 0; struct npc_data *nd; - CREATE(nd, struct npc_data, 1); - nd->bl.id = npc->get_new_npc_id(); + nd = npc->create_npc(from_mapid, from_x, from_y); map->addnpc(from_mapid, nd); - nd->bl.prev = nd->bl.next = NULL; - nd->bl.m = from_mapid; - nd->bl.x = from_x; - nd->bl.y = from_y; safestrncpy(nd->exname, name, ARRAYLENGTH(nd->exname)); if (npc->name2id(nd->exname) != NULL) @@ -2574,14 +2583,8 @@ const char* npc_parse_warp(char* w1, char* w2, char* w3, char* w4, const char* s return strchr(start,'\n');;//try next } - CREATE(nd, struct npc_data, 1); - - nd->bl.id = npc->get_new_npc_id(); + nd = npc->create_npc(m, x, y); map->addnpc(m, nd); - nd->bl.prev = nd->bl.next = NULL; - nd->bl.m = m; - nd->bl.x = x; - nd->bl.y = y; npc->parsename(nd, w3, start, buffer, filepath); if (!battle_config.warp_point_debug) @@ -2716,17 +2719,12 @@ const char* npc_parse_shop(char* w1, char* w2, char* w3, char* w4, const char* s return strchr(start,'\n');// continue } - CREATE(nd, struct npc_data, 1); + nd = npc->create_npc(m, x, y); CREATE(nd->u.shop.shop_item, struct npc_item_list, i); memcpy(nd->u.shop.shop_item, items, sizeof(items[0])*i); aFree(items); nd->u.shop.count = i; - nd->bl.prev = nd->bl.next = NULL; - nd->bl.m = m; - nd->bl.x = x; - nd->bl.y = y; - nd->bl.id = npc->get_new_npc_id(); npc->parsename(nd, w3, start, buffer, filepath); nd->class_ = m == -1 ? -1 : npc->parseview(w4, start, buffer, filepath); nd->speed = 200; @@ -2890,8 +2888,7 @@ const char* npc_parse_script(char* w1, char* w2, char* w3, char* w4, const char* npc->convertlabel_db(label_list,filepath); } - CREATE(nd, struct npc_data, 1); - + nd = npc->create_npc(m, x, y); if( sscanf(w4, "%*[^,],%d,%d", &xs, &ys) == 2 ) {// OnTouch area defined nd->u.scr.xs = xs; @@ -2903,12 +2900,7 @@ const char* npc_parse_script(char* w1, char* w2, char* w3, char* w4, const char* nd->u.scr.ys = -1; } - nd->bl.prev = nd->bl.next = NULL; - nd->bl.m = m; - nd->bl.x = x; - nd->bl.y = y; npc->parsename(nd, w3, start, buffer, filepath); - nd->bl.id = npc->get_new_npc_id(); nd->class_ = m == -1 ? -1 : npc->parseview(w4, start, buffer, filepath); nd->speed = 200; nd->u.scr.script = scriptroot; @@ -3040,14 +3032,8 @@ const char* npc_parse_duplicate(char* w1, char* w2, char* w3, char* w4, const ch return end;// next line, try to continue } - CREATE(nd, struct npc_data, 1); - - nd->bl.prev = nd->bl.next = NULL; - nd->bl.m = m; - nd->bl.x = x; - nd->bl.y = y; + nd = npc->create_npc(m, x, y); npc->parsename(nd, w3, start, buffer, filepath); - nd->bl.id = npc->get_new_npc_id(); nd->class_ = m == -1 ? -1 : npc->parseview(w4, start, buffer, filepath); nd->speed = 200; nd->src_id = src_id; @@ -3159,13 +3145,8 @@ int npc_duplicate4instance(struct npc_data *snd, int16 m) { return 1; } - CREATE(wnd, struct npc_data, 1); - wnd->bl.id = npc->get_new_npc_id(); + wnd = npc->create_npc(m, snd->bl.x, snd->bl.y); map->addnpc(m, wnd); - wnd->bl.prev = wnd->bl.next = NULL; - wnd->bl.m = m; - wnd->bl.x = snd->bl.x; - wnd->bl.y = snd->bl.y; safestrncpy(wnd->name, "", ARRAYLENGTH(wnd->name)); safestrncpy(wnd->exname, newname, ARRAYLENGTH(wnd->exname)); wnd->class_ = WARP_CLASS; @@ -4676,6 +4657,7 @@ void npc_defaults(void) { npc->parsename = npc_parsename; npc->parseview = npc_parseview; npc->viewisid = npc_viewisid; + npc->create_npc = npc_create_npc; npc->add_warp = npc_add_warp; npc->parse_warp = npc_parse_warp; npc->parse_shop = npc_parse_shop; diff --git a/src/map/npc.h b/src/map/npc.h index 97ea7713a..fba14d485 100644 --- a/src/map/npc.h +++ b/src/map/npc.h @@ -231,6 +231,7 @@ struct npc_interface { void (*parsename) (struct npc_data *nd, const char *name, const char *start, const char *buffer, const char *filepath); int (*parseview) (const char *w4, const char *start, const char *buffer, const char *filepath); bool (*viewisid) (const char *viewid); + struct npc_data* (*create_npc) (int m, int x, int y); struct npc_data* (*add_warp) (char *name, short from_mapid, short from_x, short from_y, short xs, short ys, unsigned short to_mapindex, short to_x, short to_y); const char* (*parse_warp) (char *w1, char *w2, char *w3, char *w4, const char *start, const char *buffer, const char *filepath, int *retval); const char* (*parse_shop) (char *w1, char *w2, char *w3, char *w4, const char *start, const char *buffer, const char *filepath, int *retval); |