summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLance <Lance@54d463be-8e91-2dee-dedb-b68131a5f0ec>2006-05-31 03:52:56 +0000
committerLance <Lance@54d463be-8e91-2dee-dedb-b68131a5f0ec>2006-05-31 03:52:56 +0000
commitaf2d2bc89af950fe2b780ef72ac6b0f8561ac950 (patch)
tree0044bf40e7f93ec7b089bfe6385bfc07c5cd58f2 /src
parent4107030428aa608b62524bcde7d211665ab83ca3 (diff)
downloadhercules-af2d2bc89af950fe2b780ef72ac6b0f8561ac950.tar.gz
hercules-af2d2bc89af950fe2b780ef72ac6b0f8561ac950.tar.bz2
hercules-af2d2bc89af950fe2b780ef72ac6b0f8561ac950.tar.xz
hercules-af2d2bc89af950fe2b780ef72ac6b0f8561ac950.zip
[Improved]:
- Fake NPC interface to use real NPCs. - Scripting interface to restore and save sd->npc_id. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@6873 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src')
-rw-r--r--src/map/clif.c8
-rw-r--r--src/map/map.h2
-rw-r--r--src/map/npc.c28
-rw-r--r--src/map/pc.c12
-rw-r--r--src/map/script.c5
5 files changed, 38 insertions, 17 deletions
diff --git a/src/map/clif.c b/src/map/clif.c
index 8fe61ae46..e704d756e 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -1874,7 +1874,7 @@ int clif_scriptclose(struct map_session_data *sd, int npcid) {
*/
void clif_sendfakenpc(struct map_session_data *sd, int npcid) {
int fd = sd->fd;
- sd->npc_id = npcid;
+ //sd->npc_id = npcid;
sd->state.using_fake_npc = 1;
memset(WFIFOP(fd,0), 0, packet_len_table[0x78]);
WFIFOW(fd,0)=0x78;
@@ -1899,7 +1899,7 @@ int clif_scriptmenu(struct map_session_data *sd, int npcid, char *mes) {
nullpo_retr(0, sd);
- if (!sd->state.using_fake_npc && (npcid == fake_npc_id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
+ if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
clif_sendfakenpc(sd, npcid);
@@ -1924,7 +1924,7 @@ int clif_scriptinput(struct map_session_data *sd, int npcid) {
nullpo_retr(0, sd);
- if (!sd->state.using_fake_npc && (npcid == fake_npc_id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
+ if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
clif_sendfakenpc(sd, npcid);
@@ -1948,7 +1948,7 @@ int clif_scriptinputstr(struct map_session_data *sd, int npcid) {
nullpo_retr(0, sd);
- if (!sd->state.using_fake_npc && (npcid == fake_npc_id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
+ if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
clif_sendfakenpc(sd, npcid);
diff --git a/src/map/map.h b/src/map/map.h
index 7beb0bb4a..2f18845bc 100644
--- a/src/map/map.h
+++ b/src/map/map.h
@@ -1478,6 +1478,6 @@ typedef struct homun_data TBL_HOMUNCULUS;
extern int lowest_gm_level;
extern char main_chat_nick[16];
-int fake_npc_id;
+struct npc_data *fake_nd;
#endif
diff --git a/src/map/npc.c b/src/map/npc.c
index 3c4e09b41..e671c844e 100644
--- a/src/map/npc.c
+++ b/src/map/npc.c
@@ -816,7 +816,6 @@ int npc_event_sub(struct map_session_data *sd, struct event_data *ev, const unsi
return 0;
}
- sd->npc_id=ev->nd->bl.id;
sd->npc_pos=run_script(ev->nd->u.scr.script,ev->pos,sd->bl.id,ev->nd->bl.id);
return 0;
}
@@ -1050,7 +1049,6 @@ int npc_click(struct map_session_data *sd,int id)
if (nd->class_ < 0 || nd->sc.option&OPTION_INVISIBLE)
return 1;
- sd->npc_id=id;
switch(nd->bl.subtype) {
case SHOP:
clif_npcbuysell(sd,id);
@@ -1079,7 +1077,7 @@ int npc_scriptcont(struct map_session_data *sd,int id)
return 1;
}
- if(sd->npc_id != fake_npc_id){ // Not item script
+ if(sd->npc_id != fake_nd->bl.id){ // Not item script
if (npc_checknear(sd,id)){
ShowWarning("npc_scriptcont: failed npc_checknear test.\n");
return 1;
@@ -1112,7 +1110,7 @@ int npc_buysellsel(struct map_session_data *sd,int id,int type)
if (nd->bl.subtype!=SHOP) {
if (battle_config.error_log)
ShowError("no such shop npc : %d\n",id);
- sd->npc_id=0;
+ //sd->npc_id=0;
return 1;
}
if (nd->sc.option&OPTION_INVISIBLE) // 無効化されている
@@ -2944,7 +2942,27 @@ int do_init_npc(void)
add_timer_func_list(npc_timerevent,"npc_timerevent");
// Init dummy NPC
- fake_npc_id = npc_get_new_npc_id();
+ fake_nd = (struct npc_data *)aCalloc(sizeof(struct npc_data),1);
+ fake_nd->bl.prev = fake_nd->bl.next = NULL;
+ fake_nd->bl.m = -1;
+ fake_nd->bl.x = 0;
+ fake_nd->bl.y = 0;
+ fake_nd->bl.id = npc_get_new_npc_id();
+ fake_nd->class_ = -1;
+ fake_nd->speed = 200;
+ fake_nd->u.scr.script = NULL;
+ fake_nd->u.scr.src_id = 0;
+ strcpy(fake_nd->name,"FAKE_NPC");
+ memcpy(fake_nd->exname, fake_nd->name, 9);
+
+ npc_script++;
+ fake_nd->bl.type = BL_NPC;
+ fake_nd->bl.subtype = SCRIPT;
+
+ strdb_put(npcname_db, fake_nd->exname, fake_nd);
+ fake_nd->u.scr.timerid = -1;
+ map_addiddb(&fake_nd->bl);
+ // End of initialization
return 0;
}
diff --git a/src/map/pc.c b/src/map/pc.c
index 8e76d3c7e..9049bc52b 100644
--- a/src/map/pc.c
+++ b/src/map/pc.c
@@ -2785,8 +2785,8 @@ int pc_useitem(struct map_session_data *sd,int n)
}
sd->canuseitem_tick= tick + battle_config.item_use_interval; //Update item use time.
- sd->npc_id = fake_npc_id;
- run_script(script,0,sd->bl.id,fake_npc_id);
+ //sd->npc_id = fake_nd->bl.id;
+ run_script(script,0,sd->bl.id,fake_nd->bl.id);
potion_flag = 0;
return 1;
}
@@ -6077,7 +6077,7 @@ int pc_equipitem(struct map_session_data *sd,int n,int pos)
int i;
struct item_data *data;
if (sd->inventory_data[n]->equip_script)
- run_script(sd->inventory_data[n]->equip_script,0,sd->bl.id,0);
+ run_script(sd->inventory_data[n]->equip_script,0,sd->bl.id,fake_nd->bl.id);
if(sd->status.inventory[n].card[0]==0x00ff ||
sd->status.inventory[n].card[0]==0x00fe ||
sd->status.inventory[n].card[0]==(short)0xff00)
@@ -6089,7 +6089,7 @@ int pc_equipitem(struct map_session_data *sd,int n,int pos)
continue;
data = itemdb_exists(sd->status.inventory[n].card[i]);
if (data && data->equip_script)
- run_script(data->equip_script,0,sd->bl.id,0);
+ run_script(data->equip_script,0,sd->bl.id,fake_nd->bl.id);
}
}
return 0;
@@ -6175,7 +6175,7 @@ int pc_unequipitem(struct map_session_data *sd,int n,int flag)
if (sd->inventory_data[n]) {
struct item_data *data;
if (sd->inventory_data[n]->unequip_script)
- run_script(sd->inventory_data[n]->unequip_script,0,sd->bl.id,0);
+ run_script(sd->inventory_data[n]->unequip_script,0,sd->bl.id,fake_nd->bl.id);
if(sd->status.inventory[n].card[0]==0x00ff ||
sd->status.inventory[n].card[0]==0x00fe ||
sd->status.inventory[n].card[0]==(short)0xff00)
@@ -6187,7 +6187,7 @@ int pc_unequipitem(struct map_session_data *sd,int n,int flag)
continue;
data = itemdb_exists(sd->status.inventory[n].card[i]);
if (data && data->unequip_script)
- run_script(data->unequip_script,0,sd->bl.id,0);
+ run_script(data->unequip_script,0,sd->bl.id,fake_nd->bl.id);
}
}
diff --git a/src/map/script.c b/src/map/script.c
index 1707b59eb..6aa75d0fa 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -11438,7 +11438,7 @@ int run_script(struct script_code *rootscript,int pos,int rid,int oid)
//Variables for backing up the previous script and restore it if needed. [Skotlex]
struct script_code *bck_script = NULL;
struct script_code *bck_scriptroot = NULL;
- int bck_scriptstate = 0;
+ int bck_scriptstate = 0,bck_npcid = 0;
struct script_stack *bck_stack = NULL;
if (rootscript == NULL || pos < 0)
@@ -11473,6 +11473,8 @@ int run_script(struct script_code *rootscript,int pos,int rid,int oid)
bck_scriptstate = sd->npc_scriptstate;
bck_stack = sd->stack;
sd->stack = NULL;
+ bck_npcid = sd->npc_id;
+ sd->npc_id = st->oid;
}
}
st->pos = pos;
@@ -11513,6 +11515,7 @@ int run_script(struct script_code *rootscript,int pos,int rid,int oid)
sd->npc_scriptroot = bck_scriptroot;
sd->npc_scriptstate = bck_scriptstate;
sd->stack = bck_stack;
+ sd->npc_id = bck_npcid;
//Since the script is done, save any changed account variables [Skotlex]
if (sd->state.reg_dirty&2)
intif_saveregistry(sd,2);