summaryrefslogtreecommitdiff
path: root/src/map
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2015-11-03 15:39:17 +0100
committerHaru <haru@dotalux.com>2015-11-12 00:01:32 +0100
commit8be9ef957862e249a3a2e4f810be2cada31a4e94 (patch)
treeb38c07f9aa0848c914f18b78dbd52b486795be96 /src/map
parentd0bc38acd10a05bfdc8116b316a6b6eb62b9b580 (diff)
downloadhercules-8be9ef957862e249a3a2e4f810be2cada31a4e94.tar.gz
hercules-8be9ef957862e249a3a2e4f810be2cada31a4e94.tar.bz2
hercules-8be9ef957862e249a3a2e4f810be2cada31a4e94.tar.xz
hercules-8be9ef957862e249a3a2e4f810be2cada31a4e94.zip
Split npc_duplicate_sub into separate functions based on subtypes
- For plugin overriding purposes. Thanks to Andrei Karas for the idea. Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/map')
-rw-r--r--src/map/npc.c130
-rw-r--r--src/map/npc.h3
2 files changed, 85 insertions, 48 deletions
diff --git a/src/map/npc.c b/src/map/npc.c
index ea73c2f81..17a8b9414 100644
--- a/src/map/npc.c
+++ b/src/map/npc.c
@@ -3034,61 +3034,25 @@ void npc_add_to_location(struct npc_data *nd)
}
/**
- * 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, subtype to be already
- * filled.
- * @param snd The source NPC to duplicate.
- * @param class_ The npc view class.
- * @param dir The facing direction.
- * @param xs The x-span, if any.
- * @param ys The y-span, if any.
- * @param options The NPC options.
- * @retval false if there were any issues while creating and validating the NPC.
+ * Duplicates a script (@see npc_duplicate_sub)
*/
-bool npc_duplicate_sub(struct npc_data *nd, const struct npc_data *snd, int xs, int ys, int options)
+bool npc_duplicate_script_sub(struct npc_data *nd, const struct npc_data *snd, int xs, int ys, int options)
{
int i;
bool retval = true;
- nd->src_id = snd->bl.id;
- switch (nd->subtype) {
- case SCRIPT:
- ++npc_script;
- nd->u.scr.xs = xs;
- nd->u.scr.ys = ys;
- nd->u.scr.script = snd->u.scr.script;
- nd->u.scr.label_list = snd->u.scr.label_list;
- nd->u.scr.label_list_num = snd->u.scr.label_list_num;
- nd->u.scr.shop = snd->u.scr.shop;
- nd->u.scr.trader = snd->u.scr.trader;
- break;
-
- case SHOP:
- case CASHSHOP:
- ++npc_shop;
- nd->u.shop.shop_item = snd->u.shop.shop_item;
- nd->u.shop.count = snd->u.shop.count;
- break;
-
- case WARP:
- ++npc_warp;
- nd->u.warp.xs = xs;
- nd->u.warp.ys = ys;
- nd->u.warp.mapindex = snd->u.warp.mapindex;
- nd->u.warp.x = snd->u.warp.x;
- nd->u.warp.y = snd->u.warp.y;
- break;
- }
-
- //Add the npc to its location
+ ++npc_script;
+ nd->u.scr.xs = xs;
+ nd->u.scr.ys = ys;
+ nd->u.scr.script = snd->u.scr.script;
+ nd->u.scr.label_list = snd->u.scr.label_list;
+ nd->u.scr.label_list_num = snd->u.scr.label_list_num;
+ nd->u.scr.shop = snd->u.scr.shop;
+ nd->u.scr.trader = snd->u.scr.trader;
+
+ //add the npc to its location
npc->add_to_location(nd);
- if (nd->subtype != SCRIPT)
- return true;
-
- //-----------------------------------------
// Loop through labels to export them as necessary
for (i = 0; i < nd->u.scr.label_list_num; i++) {
if (npc->event_export(nd, i)) {
@@ -3116,6 +3080,73 @@ bool npc_duplicate_sub(struct npc_data *nd, const struct npc_data *snd, int xs,
return retval;
}
+/**
+ * Duplicates a shop or cash shop (@see npc_duplicate_sub)
+ */
+bool npc_duplicate_shop_sub(struct npc_data *nd, const struct npc_data *snd, int xs, int ys, int options)
+{
+ ++npc_shop;
+ nd->u.shop.shop_item = snd->u.shop.shop_item;
+ nd->u.shop.count = snd->u.shop.count;
+
+ //add the npc to its location
+ npc->add_to_location(nd);
+
+ return true;
+}
+
+/**
+ * Duplicates a warp (@see npc_duplicate_sub)
+ */
+bool npc_duplicate_warp_sub(struct npc_data *nd, const struct npc_data *snd, int xs, int ys, int options)
+{
+ ++npc_warp;
+ nd->u.warp.xs = xs;
+ nd->u.warp.ys = ys;
+ nd->u.warp.mapindex = snd->u.warp.mapindex;
+ nd->u.warp.x = snd->u.warp.x;
+ nd->u.warp.y = snd->u.warp.y;
+
+ //Add the npc to its location
+ npc->add_to_location(nd);
+
+ return true;
+}
+
+/**
+ * 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, subtype to be already
+ * filled.
+ * @param snd The source NPC to duplicate.
+ * @param class_ The npc view class.
+ * @param dir The facing direction.
+ * @param xs The x-span, if any.
+ * @param ys The y-span, if any.
+ * @param options The NPC options.
+ * @retval false if there were any issues while creating and validating the NPC.
+ */
+bool npc_duplicate_sub(struct npc_data *nd, const struct npc_data *snd, int xs, int ys, int options)
+{
+ nd->src_id = snd->bl.id;
+ switch (nd->subtype) {
+ case SCRIPT:
+ return npc->duplicate_script_sub(nd, snd, xs, ys, options);
+
+ case SHOP:
+ case CASHSHOP:
+ return npc->duplicate_shop_sub(nd, snd, xs, ys, options);
+
+ case WARP:
+ return npc->duplicate_warp_sub(nd, snd, xs, ys, options);
+
+ case TOMB:
+ return false;
+ }
+ return false;
+}
+
/// Duplicate a warp, shop, cashshop or script. [Orcao]
/// warp: <map name>,<x>,<y>,<facing>%TAB%duplicate(<name of target>)%TAB%<NPC Name>%TAB%<spanx>,<spany>
/// shop/cashshop/npc: -%TAB%duplicate(<name of target>)%TAB%<NPC Name>%TAB%<sprite id>
@@ -4756,6 +4787,9 @@ void npc_defaults(void) {
npc->skip_script = npc_skip_script;
npc->parse_script = npc_parse_script;
npc->add_to_location = npc_add_to_location;
+ npc->duplicate_script_sub = npc_duplicate_script_sub;
+ npc->duplicate_shop_sub = npc_duplicate_shop_sub;
+ npc->duplicate_warp_sub = npc_duplicate_warp_sub;
npc->duplicate_sub = npc_duplicate_sub;
npc->parse_duplicate = npc_parse_duplicate;
npc->duplicate4instance = npc_duplicate4instance;
diff --git a/src/map/npc.h b/src/map/npc.h
index 57000f1d6..de403fe76 100644
--- a/src/map/npc.h
+++ b/src/map/npc.h
@@ -240,6 +240,9 @@ struct npc_interface {
const char* (*skip_script) (const char *start, const char *buffer, const char *filepath, int *retval);
const char* (*parse_script) (char *w1, char *w2, char *w3, char *w4, const char *start, const char *buffer, const char *filepath, int options, int *retval);
void (*add_to_location) (struct npc_data *nd);
+ bool (*duplicate_script_sub) (struct npc_data *nd, const struct npc_data *snd, int xs, int ys, int options);
+ bool (*duplicate_shop_sub) (struct npc_data *nd, const struct npc_data *snd, int xs, int ys, int options);
+ bool (*duplicate_warp_sub) (struct npc_data *nd, const struct npc_data *snd, int xs, int ys, int options);
bool (*duplicate_sub) (struct npc_data *nd, const struct npc_data *snd, int xs, int ys, int options);
const char* (*parse_duplicate) (char* w1, char* w2, char* w3, char* w4, const char* start, const char* buffer, const char* filepath, int options, int *retval);
int (*duplicate4instance) (struct npc_data *snd, int16 m);