summaryrefslogtreecommitdiff
path: root/src/map/npc.c
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-11-28 23:33:52 +0300
committerAndrei Karas <akaras@inbox.ru>2014-11-28 23:33:52 +0300
commit674092152236dca6784081e5e93540069b54549e (patch)
tree3bf5030577d349b22f803158f20cdbb4426f913a /src/map/npc.c
parent489c589e3e0f9344ee2af40c04bbdcca30ab7696 (diff)
downloadhercules-674092152236dca6784081e5e93540069b54549e.tar.gz
hercules-674092152236dca6784081e5e93540069b54549e.tar.bz2
hercules-674092152236dca6784081e5e93540069b54549e.tar.xz
hercules-674092152236dca6784081e5e93540069b54549e.zip
Add function for create npc.
Diffstat (limited to 'src/map/npc.c')
-rw-r--r--src/map/npc.c60
1 files changed, 21 insertions, 39 deletions
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;