summaryrefslogtreecommitdiff
path: root/src/map/npc.c
diff options
context:
space:
mode:
authorzephyrus <zephyrus@54d463be-8e91-2dee-dedb-b68131a5f0ec>2009-08-12 21:44:02 +0000
committerzephyrus <zephyrus@54d463be-8e91-2dee-dedb-b68131a5f0ec>2009-08-12 21:44:02 +0000
commit09e154b0687a2ba69d5ce6f2456c61db86bc4dec (patch)
tree6be18bd056964352e036afef8c36c860c0ff52af /src/map/npc.c
parent653c88c4f1bf019f61132324fd7146ae2f858cec (diff)
downloadhercules-09e154b0687a2ba69d5ce6f2456c61db86bc4dec.tar.gz
hercules-09e154b0687a2ba69d5ce6f2456c61db86bc4dec.tar.bz2
hercules-09e154b0687a2ba69d5ce6f2456c61db86bc4dec.tar.xz
hercules-09e154b0687a2ba69d5ce6f2456c61db86bc4dec.zip
- Optimization to instance system.
* Removed the crc feature to generate instance npc names. The instance npc name will be "dup_" + instanceid + "_" + srcnpcid. * Removed the big array under map structure and coded in a different way. It was only used to generate map names, but i just used the instance_id + "origin map name". * Moved all instance features to separated files. * Moved the npc duplication for instances into npc.c as Ultramage says (removed npcname_db from npc.h). * Added recomendations for scripts commands by Saithis. - Testing required, i will prepare Endless Tower script soon. I hope this do almost anything in bugreport 3276. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@14003 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/map/npc.c')
-rw-r--r--src/map/npc.c75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/map/npc.c b/src/map/npc.c
index 05a58f92f..3614968c0 100644
--- a/src/map/npc.c
+++ b/src/map/npc.c
@@ -21,6 +21,7 @@
#include "script.h"
#include "mob.h"
#include "pet.h"
+#include "instance.h"
#include "battle.h"
#include "skill.h"
#include "unit.h"
@@ -2303,6 +2304,80 @@ const char* npc_parse_duplicate(char* w1, char* w2, char* w3, char* w4, const ch
return end;
}
+int npc_duplicate4instance(struct npc_data *snd, int m)
+{
+ char newname[NAME_LENGTH];
+ int i = 0;
+
+ if( map[m].instance_id == 0 )
+ return 1;
+
+ snprintf(newname, ARRAYLENGTH(newname), "dup_%d_%d", map[m].instance_id, snd->bl.id);
+ if( npc_name2id(newname) != NULL )
+ { // Name already in use
+ ShowError("npc_duplicate4instance: the npcname (%s) is already in use while trying to duplicate npc %s in instance %d.\n", newname, snd->exname, map[m].instance_id);
+ return 1;
+ }
+
+ if( snd->subtype == WARP )
+ { // Adjust destination, if instanced
+ struct npc_data *wnd = NULL; // New NPC
+ int dm = map_mapindex2mapid(snd->u.warp.mapindex), im;
+ if( dm < 0 ) return 1;
+
+ im = instance_mapid2imapid(dm, map[m].instance_id);
+ if( im == -1 )
+ {
+ ShowError("npc_duplicate4instance: warp (%s) leading to instanced map (%s), but instance map is not attached to current instance.\n", map[dm].name, snd->exname);
+ return 1;
+ }
+
+ CREATE(wnd, struct npc_data, 1);
+ wnd->bl.id = npc_get_new_npc_id();
+ 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;
+ wnd->speed = 200;
+ wnd->u.warp.mapindex = map_id2index(im);
+ wnd->u.warp.x = snd->u.warp.x;
+ wnd->u.warp.y = snd->u.warp.y;
+ wnd->u.warp.xs = snd->u.warp.xs;
+ wnd->u.warp.ys = snd->u.warp.ys;
+ wnd->bl.type = BL_NPC;
+ wnd->subtype = WARP;
+ npc_setcells(wnd);
+ map_addblock(&wnd->bl);
+ status_set_viewdata(&wnd->bl, wnd->class_);
+ status_change_init(&wnd->bl);
+ unit_dataset(&wnd->bl);
+ clif_spawn(&wnd->bl);
+ strdb_put(npcname_db, wnd->exname, wnd);
+ }
+ else
+ {
+ static char w1[50], w2[50], w3[50], w4[50];
+ const char* stat_buf = "- call from instancing subsystem -\n";
+
+ snprintf(w1, sizeof(w1), "%s,%d,%d,%d", map[m].name, snd->bl.x, snd->bl.y, snd->ud.dir);
+ snprintf(w2, sizeof(w2), "duplicate(%s)", snd->exname);
+ snprintf(w3, sizeof(w3), "%s::%s", snd->name, newname);
+
+ if( snd->u.scr.xs >= 0 && snd->u.scr.ys >= 0 )
+ snprintf(w4, sizeof(w4), "%d,%d,%d", snd->class_, snd->u.scr.xs, snd->u.scr.ys); // Touch Area
+ else
+ snprintf(w4, sizeof(w4), "%d", snd->class_);
+
+ npc_parse_duplicate(w1, w2, w3, w4, stat_buf, stat_buf, "INSTANCING");
+ }
+
+ return 0;
+}
+
void npc_setcells(struct npc_data* nd)
{
int m = nd->bl.m, x = nd->bl.x, y = nd->bl.y, xs, ys;