summaryrefslogtreecommitdiff
path: root/src/map
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2015-11-03 15:26:12 +0100
committerHaru <haru@dotalux.com>2015-11-12 00:01:32 +0100
commit57f09704aaa62295a9a967726a0dbabda40770c4 (patch)
treebcc01b809712bdbd6ef2f7fff0faf4f80e382b09 /src/map
parent556ea4c20bb7ca06adb572ccefc1986f71e6a5c0 (diff)
downloadhercules-57f09704aaa62295a9a967726a0dbabda40770c4.tar.gz
hercules-57f09704aaa62295a9a967726a0dbabda40770c4.tar.bz2
hercules-57f09704aaa62295a9a967726a0dbabda40770c4.tar.xz
hercules-57f09704aaa62295a9a967726a0dbabda40770c4.zip
Added subtype initializer to npc_create_npc
Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/map')
-rw-r--r--src/map/mob.c4
-rw-r--r--src/map/npc.c33
-rw-r--r--src/map/npc.h2
3 files changed, 20 insertions, 19 deletions
diff --git a/src/map/mob.c b/src/map/mob.c
index c925d02ce..6cbbd3a2a 100644
--- a/src/map/mob.c
+++ b/src/map/mob.c
@@ -142,13 +142,11 @@ void mvptomb_create(struct mob_data *md, char *killer, time_t time)
if ( md->tomb_nid )
mob->mvptomb_destroy(md);
- nd = npc->create_npc(md->bl.m, md->bl.x, md->bl.y, md->ud.dir, MOB_TOMB);
+ nd = npc->create_npc(TOMB, md->bl.m, md->bl.x, md->bl.y, md->ud.dir, MOB_TOMB);
md->tomb_nid = nd->bl.id;
safestrncpy(nd->name, msg_txt(856), sizeof(nd->name)); // "Tomb"
- nd->subtype = TOMB;
-
nd->u.tomb.md = md;
nd->u.tomb.kill_time = time;
diff --git a/src/map/npc.c b/src/map/npc.c
index 9271d643a..e92e3c447 100644
--- a/src/map/npc.c
+++ b/src/map/npc.c
@@ -2563,6 +2563,11 @@ bool npc_viewisid(const char * viewid)
/**
* Creates a new NPC.
*
+ * @remark
+ * When creating a npc with subtype TOMB, no ID is assigned. The caller
+ * must assign the dead mob ID after the NPC is created.
+ *
+ * @param subtype The NPC subtype.
* @param m The map id.
* @param x The x coordinate on map.
* @param y The y coordinate on map.
@@ -2570,13 +2575,16 @@ bool npc_viewisid(const char * viewid)
* @param class_ The NPC view class.
* @return A pointer to the created NPC data (ownership passed to the caller).
*/
-struct npc_data *npc_create_npc(int m, int x, int y, uint8 dir, int16 class_)
+struct npc_data *npc_create_npc(enum npc_subtype subtype, int m, int x, int y, uint8 dir, int16 class_)
{
struct npc_data *nd;
CREATE(nd, struct npc_data, 1);
+ nd->subtype = subtype;
nd->bl.type = BL_NPC;
- nd->bl.id = npc->get_new_npc_id();
+ if (subtype != TOMB) {
+ nd->bl.id = npc->get_new_npc_id();
+ }
nd->bl.prev = nd->bl.next = NULL;
nd->bl.m = m;
nd->bl.x = x;
@@ -2594,7 +2602,7 @@ struct npc_data* npc_add_warp(char* name, short from_mapid, short from_x, short
int i, flag = 0;
struct npc_data *nd;
- nd = npc->create_npc(from_mapid, from_x, from_y, 0, battle_config.warp_point_debug ? WARP_DEBUG_CLASS : WARP_CLASS);
+ nd = npc->create_npc(WARP, from_mapid, from_x, from_y, 0, battle_config.warp_point_debug ? WARP_DEBUG_CLASS : WARP_CLASS);
map->addnpc(from_mapid, nd);
safestrncpy(nd->exname, name, ARRAYLENGTH(nd->exname));
@@ -2613,7 +2621,6 @@ struct npc_data* npc_add_warp(char* name, short from_mapid, short from_x, short
nd->u.warp.y = to_y;
nd->u.warp.xs = xs;
nd->u.warp.ys = xs;
- nd->subtype = WARP;
npc->setcells(nd);
map->addblock(&nd->bl);
status->set_viewdata(&nd->bl, nd->class_);
@@ -2656,7 +2663,7 @@ const char* npc_parse_warp(char* w1, char* w2, char* w3, char* w4, const char* s
return strchr(start,'\n');;//try next
}
- nd = npc->create_npc(m, x, y, 0, battle_config.warp_point_debug ? WARP_DEBUG_CLASS : WARP_CLASS);
+ nd = npc->create_npc(WARP, m, x, y, 0, battle_config.warp_point_debug ? WARP_DEBUG_CLASS : WARP_CLASS);
map->addnpc(m, nd);
npc->parsename(nd, w3, start, buffer, filepath);
nd->path = npc->retainpathreference(filepath);
@@ -2667,7 +2674,6 @@ const char* npc_parse_warp(char* w1, char* w2, char* w3, char* w4, const char* s
nd->u.warp.xs = xs;
nd->u.warp.ys = ys;
npc_warp++;
- nd->subtype = WARP;
npc->setcells(nd);
map->addblock(&nd->bl);
status->set_viewdata(&nd->bl, nd->class_);
@@ -2793,7 +2799,7 @@ const char* npc_parse_shop(char* w1, char* w2, char* w3, char* w4, const char* s
}
class_ = m == -1 ? -1 : npc->parseview(w4, start, buffer, filepath);
- nd = npc->create_npc(m, x, y, dir, class_);
+ nd = npc->create_npc(type, m, x, y, dir, class_);
CREATE(nd->u.shop.shop_item, struct npc_item_list, i);
memcpy(nd->u.shop.shop_item, items, sizeof(items[0])*i);
aFree(items);
@@ -2803,7 +2809,6 @@ const char* npc_parse_shop(char* w1, char* w2, char* w3, char* w4, const char* s
nd->path = npc->retainpathreference(filepath);
++npc_shop;
- nd->subtype = type;
if( m >= 0 ) {// normal shop npc
map->addnpc(m,nd);
map->addblock(&nd->bl);
@@ -2972,7 +2977,7 @@ const char* npc_parse_script(char* w1, char* w2, char* w3, char* w4, const char*
}
class_ = m == -1 ? -1 : npc->parseview(w4, start, buffer, filepath);
- nd = npc->create_npc(m, x, y, dir, class_);
+ nd = npc->create_npc(SCRIPT, m, x, y, dir, class_);
if (sscanf(w4, "%*[^,],%d,%d", &xs, &ys) == 2) {
// OnTouch area defined
nd->u.scr.xs = xs;
@@ -2991,9 +2996,7 @@ const char* npc_parse_script(char* w1, char* w2, char* w3, char* w4, const char*
if( options&NPO_TRADER )
nd->u.scr.trader = true;
nd->u.scr.shop = NULL;
-
++npc_script;
- nd->subtype = SCRIPT;
if( m >= 0 ) {
map->addnpc(m, nd);
@@ -3045,7 +3048,8 @@ const char* npc_parse_script(char* w1, char* w2, char* w3, char* w4, const char*
* Duplicates a warp, shop, cashshop or script.
*
* @param nd An already initialized NPC data. Expects bl->m, bl->x, bl->y,
- * name, exname, path, dir, class_, speed to be already filled.
+ * name, exname, path, dir, class_, speed, subtype to be already
+ * filled.
* @param snd The source NPC to duplicate.
* @param class_ The npc view class.
* @param dir The facing direction.
@@ -3060,7 +3064,6 @@ bool npc_duplicate_sub(struct npc_data *nd, const struct npc_data *snd, int xs,
bool retval = true;
nd->src_id = snd->bl.id;
- nd->subtype = snd->subtype;
switch (nd->subtype) {
case SCRIPT:
++npc_script;
@@ -3216,7 +3219,7 @@ const char* npc_parse_duplicate(char* w1, char* w2, char* w3, char* w4, const ch
}
class_ = m == -1 ? -1 : npc->parseview(w4, start, buffer, filepath);
- nd = npc->create_npc(m, x, y, dir, class_);
+ nd = npc->create_npc(dnd->subtype, m, x, y, dir, class_);
npc->parsename(nd, w3, start, buffer, filepath);
nd->path = npc->retainpathreference(filepath);
if (!npc->duplicate_sub(nd, dnd, xs, ys, options)) {
@@ -3270,7 +3273,7 @@ int npc_duplicate4instance(struct npc_data *snd, int16 m)
break;
}
- nd = npc->create_npc(m, snd->bl.x, snd->bl.y, snd->dir, snd->class_);
+ nd = npc->create_npc(snd->subtype, m, snd->bl.x, snd->bl.y, snd->dir, snd->class_);
safestrncpy(nd->name, snd->name, sizeof(nd->name));
safestrncpy(nd->exname, newname, sizeof(nd->exname));
nd->path = npc->retainpathreference("INSTANCING");
diff --git a/src/map/npc.h b/src/map/npc.h
index 213c5df38..bec17fd8d 100644
--- a/src/map/npc.h
+++ b/src/map/npc.h
@@ -231,7 +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, uint8 dir, int16 class_);
+ struct npc_data *(*create_npc) (enum npc_subtype subtype, int m, int x, int y, uint8 dir, int16 class_);
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);