summaryrefslogtreecommitdiff
path: root/src/map
diff options
context:
space:
mode:
authorshennetsind <ind@henn.et>2013-09-16 10:20:29 -0300
committershennetsind <ind@henn.et>2013-09-16 10:20:29 -0300
commit95e13fe4774a7c46c15c6e41ab28338cca827ecc (patch)
treeb37ef0f49cdb905eda361614e0ebcf6f93a58438 /src/map
parent5d33b1cc58d3c831f5fb9f7f368aa996d4be82c7 (diff)
downloadhercules-95e13fe4774a7c46c15c6e41ab28338cca827ecc.tar.gz
hercules-95e13fe4774a7c46c15c6e41ab28338cca827ecc.tar.bz2
hercules-95e13fe4774a7c46c15c6e41ab28338cca827ecc.tar.xz
hercules-95e13fe4774a7c46c15c6e41ab28338cca827ecc.zip
HPM: Npc.c Interface
Fully Interfaced. Special Thanks to Haruna Signed-off-by: shennetsind <ind@henn.et>
Diffstat (limited to 'src/map')
-rw-r--r--src/map/atcommand.c40
-rw-r--r--src/map/battleground.c4
-rw-r--r--src/map/chat.c2
-rw-r--r--src/map/chrif.c4
-rw-r--r--src/map/clif.c54
-rw-r--r--src/map/elemental.c2
-rw-r--r--src/map/guild.c18
-rw-r--r--src/map/homunculus.c2
-rw-r--r--src/map/instance.c4
-rw-r--r--src/map/map.c43
-rw-r--r--src/map/mercenary.c2
-rw-r--r--src/map/mob.c12
-rw-r--r--src/map/npc.c615
-rw-r--r--src/map/npc.h198
-rw-r--r--src/map/pc.c34
-rw-r--r--src/map/pet.c2
-rw-r--r--src/map/script.c116
-rw-r--r--src/map/skill.c6
-rw-r--r--src/map/status.c6
-rw-r--r--src/map/unit.c20
20 files changed, 650 insertions, 534 deletions
diff --git a/src/map/atcommand.c b/src/map/atcommand.c
index 6c44f8919..d9b9543e4 100644
--- a/src/map/atcommand.c
+++ b/src/map/atcommand.c
@@ -3749,7 +3749,7 @@ ACMD(reloadscript)
flush_fifos();
iMap->reloadnpc(true); // reload config files seeking for npcs
script->reload();
- npc_reload();
+ npc->reload();
clif->message(fd, msg_txt(100)); // Scripts have been reloaded.
@@ -4237,7 +4237,7 @@ ACMD(tonpc)
return false;
}
- if ((nd = npc_name2id(npcname)) != NULL) {
+ if ((nd = npc->name2id(npcname)) != NULL) {
if (pc->setpos(sd, map_id2index(nd->bl.m), nd->bl.x, nd->bl.y, CLR_TELEPORT) == 0)
clif->message(fd, msg_txt(0)); // Warped.
else
@@ -4265,8 +4265,8 @@ ACMD(shownpc)
return false;
}
- if (npc_name2id(NPCname) != NULL) {
- npc_enable(NPCname, 1);
+ if (npc->name2id(NPCname) != NULL) {
+ npc->enable(NPCname, 1);
clif->message(fd, msg_txt(110)); // Npc Enabled.
} else {
clif->message(fd, msg_txt(111)); // This NPC doesn't exist.
@@ -4291,12 +4291,12 @@ ACMD(hidenpc)
return false;
}
- if (npc_name2id(NPCname) == NULL) {
+ if (npc->name2id(NPCname) == NULL) {
clif->message(fd, msg_txt(111)); // This NPC doesn't exist.
return false;
}
- npc_enable(NPCname, 0);
+ npc->enable(NPCname, 0);
clif->message(fd, msg_txt(112)); // Npc Disabled.
return true;
}
@@ -4318,9 +4318,9 @@ ACMD(loadnpc)
fclose(fp);
// add to list of script sources and run it
- npc_addsrcfile(message);
- npc_parsesrcfile(message,true);
- npc_read_event_script();
+ npc->addsrcfile(message);
+ npc->parsesrcfile(message,true);
+ npc->read_event_script();
clif->message(fd, msg_txt(262));
@@ -4340,14 +4340,14 @@ ACMD(unloadnpc)
return false;
}
- if ((nd = npc_name2id(NPCname)) == NULL) {
+ if ((nd = npc->name2id(NPCname)) == NULL) {
clif->message(fd, msg_txt(111)); // This NPC doesn't exist.
return false;
}
- npc_unload_duplicates(nd);
- npc_unload(nd,true);
- npc_read_event_script();
+ npc->unload_duplicates(nd);
+ npc->unload(nd,true);
+ npc->read_event_script();
clif->message(fd, msg_txt(112)); // Npc Disabled.
return true;
}
@@ -4749,7 +4749,7 @@ ACMD(disguise)
} else { //Acquired a Name
if ((id = mob->db_searchname(message)) == 0)
{
- struct npc_data* nd = npc_name2id(message);
+ struct npc_data* nd = npc->name2id(message);
if (nd != NULL)
id = nd->class_;
}
@@ -4828,7 +4828,7 @@ ACMD(disguiseguild)
id = 0;
} else {
if( (id = mob->db_searchname(monster)) == 0 ) {
- struct npc_data* nd = npc_name2id(monster);
+ struct npc_data* nd = npc->name2id(monster);
if( nd != NULL )
id = nd->class_;
}
@@ -5116,7 +5116,7 @@ ACMD(npcmove)
return false;
}
- if ((nd = npc_name2id(atcmd_player_name)) == NULL)
+ if ((nd = npc->name2id(atcmd_player_name)) == NULL)
{
clif->message(fd, msg_txt(111)); // This NPC doesn't exist.
return false;
@@ -5165,7 +5165,7 @@ ACMD(addwarp)
return false;
}
- nd = npc_add_warp(warpname, sd->bl.m, sd->bl.x, sd->bl.y, 2, 2, m, x, y);
+ nd = npc->add_warp(warpname, sd->bl.m, sd->bl.x, sd->bl.y, 2, 2, m, x, y);
if( nd == NULL )
return false;
@@ -6194,7 +6194,7 @@ ACMD(npctalk)
}
}
- if (!(nd = npc_name2id(name))) {
+ if (!(nd = npc->name2id(name))) {
clif->message(fd, msg_txt(111)); // This NPC doesn't exist
return false;
}
@@ -8759,7 +8759,7 @@ ACMD(unloadnpcfile) {
return false;
}
- if( npc_unloadfile(message) )
+ if( npc->unloadfile(message) )
clif->message(fd, msg_txt(1386)); // File unloaded. Be aware that mapflags and monsters spawned directly are not removed.
else {
clif->message(fd, msg_txt(1387)); // File not found.
@@ -10018,7 +10018,7 @@ bool is_atcommand(const int fd, struct map_session_data* sd, const char* message
if( binding->log ) /* log only if this command should be logged [Ind/Hercules] */
logs->atcommand(sd, atcmd_msg);
- npc_do_atcmd_event((invokeFlag ? sd : ssd), command, params, binding->npc_event);
+ npc->do_atcmd_event((invokeFlag ? sd : ssd), command, params, binding->npc_event);
return true;
}
}
diff --git a/src/map/battleground.c b/src/map/battleground.c
index 3b2e0b1ce..66586c5fe 100644
--- a/src/map/battleground.c
+++ b/src/map/battleground.c
@@ -149,7 +149,7 @@ int bg_team_leave(struct map_session_data *sd, int flag)
}
if( bg_data->logout_event[0] && flag )
- npc_event(sd, bg_data->logout_event, 0);
+ npc->event(sd, bg_data->logout_event, 0);
if( sd->bg_queue.arena ) {
bg->queue_pc_cleanup(sd);
@@ -534,7 +534,7 @@ void bg_begin(struct bg_arena *arena) {
arena->ongoing = true;
mapreg_setreg(script->add_str("$@bg_queue_id"),arena->queue_id);/* TODO: make this a arena-independant var? or just .@? */
mapreg_setregstr(script->add_str("$@bg_delay_var$"),bg->gdelay_var);
- npc_event_do(arena->npc_event);
+ npc->event_do(arena->npc_event);
/* we split evenly? */
/* but if a party of say 10 joins, it cant be split evenly unless by luck there are 10 soloers in the queue besides them */
/* not sure how to split T_T needs more info */
diff --git a/src/map/chat.c b/src/map/chat.c
index 3a76dd157..28de86fe1 100644
--- a/src/map/chat.c
+++ b/src/map/chat.c
@@ -388,7 +388,7 @@ int chat_triggerevent(struct chat_data *cd)
nullpo_ret(cd);
if( cd->users >= cd->trigger && cd->npc_event[0] )
- npc_event_do(cd->npc_event);
+ npc->event_do(cd->npc_event);
return 0;
}
diff --git a/src/map/chrif.c b/src/map/chrif.c
index 6b0397b56..524286da1 100644
--- a/src/map/chrif.c
+++ b/src/map/chrif.c
@@ -463,10 +463,10 @@ int chrif_connectack(int fd) {
chrif_sendmap(fd);
- ShowStatus("Event '"CL_WHITE"OnInterIfInit"CL_RESET"' executed with '"CL_WHITE"%d"CL_RESET"' NPCs.\n", npc_event_doall("OnInterIfInit"));
+ ShowStatus("Event '"CL_WHITE"OnInterIfInit"CL_RESET"' executed with '"CL_WHITE"%d"CL_RESET"' NPCs.\n", npc->event_doall("OnInterIfInit"));
if( !char_init_done ) {
char_init_done = true;
- ShowStatus("Event '"CL_WHITE"OnInterIfInitOnce"CL_RESET"' executed with '"CL_WHITE"%d"CL_RESET"' NPCs.\n", npc_event_doall("OnInterIfInitOnce"));
+ ShowStatus("Event '"CL_WHITE"OnInterIfInitOnce"CL_RESET"' executed with '"CL_WHITE"%d"CL_RESET"' NPCs.\n", npc->event_doall("OnInterIfInitOnce"));
guild->castle_map_init();
}
diff --git a/src/map/clif.c b/src/map/clif.c
index f8f88c691..391c3c40b 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -1928,7 +1928,7 @@ void clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes)
int slen = strlen(mes) + 9;
struct block_list *bl = NULL;
- if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = iMap->id2bl(npcid)) && (bl->m!=sd->bl.m ||
+ if (!sd->state.using_fake_npc && (npcid == npc->fake_nd->bl.id || ((bl = iMap->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);
@@ -1960,7 +1960,7 @@ void clif_scriptinput(struct map_session_data *sd, int npcid)
nullpo_retv(sd);
- if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = iMap->id2bl(npcid)) && (bl->m!=sd->bl.m ||
+ if (!sd->state.using_fake_npc && (npcid == npc->fake_nd->bl.id || ((bl = iMap->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);
@@ -1991,7 +1991,7 @@ void clif_scriptinputstr(struct map_session_data *sd, int npcid)
nullpo_retv(sd);
- if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = iMap->id2bl(npcid)) && (bl->m!=sd->bl.m ||
+ if (!sd->state.using_fake_npc && (npcid == npc->fake_nd->bl.id || ((bl = iMap->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);
@@ -9531,7 +9531,7 @@ void clif_parse_LoadEndAck(int fd,struct map_session_data *sd) {
iMap->map_foreachpc(clif->friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
//Login Event
- npc_script_event(sd, NPCE_LOGIN);
+ npc->script_event(sd, NPCE_LOGIN);
} else {
//For some reason the client "loses" these on warp/map-change.
clif->updatestatus(sd,SP_STR);
@@ -9547,7 +9547,7 @@ void clif_parse_LoadEndAck(int fd,struct map_session_data *sd) {
sd->npc_menu = 0;
if(sd->npc_id)
- npc_event_dequeue(sd);
+ npc->event_dequeue(sd);
if( sd->guild && ( battle_config.guild_notice_changemap == 2 || ( battle_config.guild_notice_changemap == 1 && sd->state.changemap ) ) )
clif->guild_notice(sd,sd->guild);
@@ -9611,7 +9611,7 @@ void clif_parse_LoadEndAck(int fd,struct map_session_data *sd) {
}
if(map[sd->bl.m].flag.loadevent) // Lance
- npc_script_event(sd, NPCE_LOADMAP);
+ npc->script_event(sd, NPCE_LOADMAP);
if (pc->checkskill(sd, SG_DEVIL) && !pc->nextjobexp(sd)) //blindness [Komurka]
clif->sc_end(&sd->bl, sd->bl.id, SELF, SI_DEVIL1);
@@ -9623,7 +9623,7 @@ void clif_parse_LoadEndAck(int fd,struct map_session_data *sd) {
// For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
if (iMap->getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
- npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
+ npc->touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
else
sd->areanpc_id = 0;
@@ -9750,7 +9750,7 @@ void clif_parse_progressbar(int fd, struct map_session_data * sd)
sd->st->state = END;
sd->state.workinprogress = sd->progressbar.npc_id = sd->progressbar.timeout = 0;
- npc_scriptcont(sd, npc_id, false);
+ npc->scriptcont(sd, npc_id, false);
}
@@ -10401,8 +10401,8 @@ void clif_parse_WisMessage(int fd, struct map_session_data* sd)
//-------------------------------------------------------//
if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4)) {
char* str = target+4; //Skip the NPC: string part.
- struct npc_data* npc;
- if ((npc = npc_name2id(str))) {
+ struct npc_data *nd;
+ if ((nd = npc->name2id(str))) {
char split_data[NUM_WHISPER_VAR][CHAT_SIZE_MAX];
char *split;
char output[256];
@@ -10429,8 +10429,8 @@ void clif_parse_WisMessage(int fd, struct map_session_data* sd)
script->set_var(sd,output,(char *) split_data[i]);
}
- sprintf(output, "%s::OnWhisperGlobal", npc->exname);
- npc_event(sd,output,0); // Calls the NPC label
+ sprintf(output, "%s::OnWhisperGlobal", nd->exname);
+ npc->event(sd,output,0); // Calls the NPC label
return;
}
@@ -10837,7 +10837,7 @@ void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
break;
}
if( bl->m != -1 )// the user can't click floating npcs directly (hack attempt)
- npc_click(sd,(TBL_NPC*)bl);
+ npc->click(sd,(TBL_NPC*)bl);
break;
}
}
@@ -10852,7 +10852,7 @@ void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
{
if (sd->state.trading)
return;
- npc_buysellsel(sd,RFIFOL(fd,2),RFIFOB(fd,6));
+ npc->buysellsel(sd,RFIFOL(fd,2),RFIFOB(fd,6));
}
@@ -10884,7 +10884,7 @@ void clif_parse_NpcBuyListSend(int fd, struct map_session_data* sd)
if( sd->state.trading || !sd->npc_shopid )
result = 1;
else
- result = npc_buylist(sd,n,item_list);
+ result = npc->buylist(sd,n,item_list);
sd->npc_shopid = 0; //Clear shop data.
@@ -10920,7 +10920,7 @@ void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
if (sd->state.trading || !sd->npc_shopid)
fail = 1;
else
- fail = npc_selllist(sd,n,item_list);
+ fail = npc->selllist(sd,n,item_list);
sd->npc_shopid = 0; //Clear shop data.
@@ -10949,7 +10949,7 @@ void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
clif->skill_fail(sd,1,USESKILL_FAIL_LEVEL,3);
return;
}
- if( npc_isnear(&sd->bl) ) {
+ if( npc->isnear(&sd->bl) ) {
// uncomment for more verbose message.
//char output[150];
//sprintf(output, msg_txt(662), battle_config.min_npc_vendchat_distance);
@@ -11695,7 +11695,7 @@ void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd)
}
sd->npc_menu = select;
- npc_scriptcont(sd,npc_id, false);
+ npc->scriptcont(sd,npc_id, false);
}
@@ -11703,7 +11703,7 @@ void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd)
/// 00b9 <npc id>.L
void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
{
- npc_scriptcont(sd,RFIFOL(fd,2), false);
+ npc->scriptcont(sd,RFIFOL(fd,2), false);
}
@@ -11715,7 +11715,7 @@ void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd)
int amount = (int)RFIFOL(fd,6);
sd->npc_amount = amount;
- npc_scriptcont(sd, npcid, false);
+ npc->scriptcont(sd, npcid, false);
}
@@ -11731,7 +11731,7 @@ void clif_parse_NpcStringInput(int fd, struct map_session_data* sd)
return; // invalid input
safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
- npc_scriptcont(sd, npcid, false);
+ npc->scriptcont(sd, npcid, false);
}
@@ -11741,7 +11741,7 @@ void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
{
if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
return;
- npc_scriptcont(sd, RFIFOL(fd,2), true);
+ npc->scriptcont(sd, RFIFOL(fd,2), true);
}
@@ -13275,9 +13275,9 @@ void clif_parse_GMKick(int fd, struct map_session_data *sd)
clif->GM_kickack(sd, 0);
return;
}
- npc_unload_duplicates(nd);
- npc_unload(nd,true);
- npc_read_event_script();
+ npc->unload_duplicates(nd);
+ npc->unload(nd,true);
+ npc->read_event_script();
}
break;
@@ -15293,7 +15293,7 @@ void clif_parse_cashshop_buy(int fd, struct map_session_data *sd)
short amount = RFIFOW(fd,4);
int points = RFIFOL(fd,6);
- fail = npc_cashshop_buy(sd, nameid, amount, points);
+ fail = npc->cashshop_buy(sd, nameid, amount, points);
#else
int len = RFIFOW(fd,2);
int points = RFIFOL(fd,4);
@@ -15305,7 +15305,7 @@ void clif_parse_cashshop_buy(int fd, struct map_session_data *sd)
ShowWarning("Player %u sent incorrect cash shop buy packet (len %u:%u)!\n", sd->status.char_id, len, 10 + count * 4);
return;
}
- fail = npc_cashshop_buylist(sd,points,count,item_list);
+ fail = npc->cashshop_buylist(sd,points,count,item_list);
#endif
}
diff --git a/src/map/elemental.c b/src/map/elemental.c
index 1ef85b3e5..855d9e2c6 100644
--- a/src/map/elemental.c
+++ b/src/map/elemental.c
@@ -238,7 +238,7 @@ int elemental_data_received(struct s_elemental *ele, bool flag) {
if( !sd->ed ) { // Initialize it after first summon.
sd->ed = ed = (struct elemental_data*)aCalloc(1,sizeof(struct elemental_data));
ed->bl.type = BL_ELEM;
- ed->bl.id = npc_get_new_npc_id();
+ ed->bl.id = npc->get_new_npc_id();
ed->master = sd;
ed->db = db;
memcpy(&ed->elemental, ele, sizeof(struct s_elemental));
diff --git a/src/map/guild.c b/src/map/guild.c
index 37335f9d0..6219fc770 100644
--- a/src/map/guild.c
+++ b/src/map/guild.c
@@ -429,7 +429,7 @@ int guild_npc_request_info(int guild_id,const char *event)
if( guild->search(guild_id) )
{
if( event && *event )
- npc_event_do(event);
+ npc->event_do(event);
return 0;
}
@@ -622,7 +622,7 @@ int guild_recv_info(struct guild *sg) {
if (guild_infoevent_db->remove(guild_infoevent_db, DB->i2key(sg->guild_id), &data)) {
struct eventlist *ev = DB->data2ptr(&data), *ev2;
while(ev) {
- npc_event_do(ev->name);
+ npc->event_do(ev->name);
ev2=ev->next;
aFree(ev);
ev=ev2;
@@ -1736,7 +1736,7 @@ int castle_guild_broken_sub(DBKey key, DBData *data, va_list ap)
// We call castle_event::OnGuildBreak of all castles of the guild
// You can set all castle_events in the 'db/castle_db.txt'
safestrncpy(name, gc->castle_event, sizeof(name));
- npc_event_do(strcat(name, "::OnGuildBreak"));
+ npc->event_do(strcat(name, "::OnGuildBreak"));
//Save the new 'owner', this should invoke guardian clean up and other such things.
guild->castledatasave(gc->castle_id, 1, 0);
@@ -2044,8 +2044,8 @@ int guild_castledataloadack(int len, struct guild_castle *gc)
ev = i; // offset of castle or -1
if( ev < 0 ) { //No castles owned, invoke OnAgitInit as it is.
- npc_event_doall("OnAgitInit");
- npc_event_doall("OnAgitInit2");
+ npc->event_doall("OnAgitInit");
+ npc->event_doall("OnAgitInit2");
} else { // load received castles into memory, one by one
for( i = 0; i < n; i++, gc++ ) {
struct guild_castle *c = guild->castle_search(gc->castle_id);
@@ -2076,7 +2076,7 @@ int guild_castledataloadack(int len, struct guild_castle *gc)
*---------------------------------------------------*/
void guild_agit_start(void)
{ // Run All NPC_Event[OnAgitStart]
- int c = npc_event_doall("OnAgitStart");
+ int c = npc->event_doall("OnAgitStart");
ShowStatus("NPC_Event:[OnAgitStart] Run (%d) Events by @AgitStart.\n",c);
}
@@ -2085,7 +2085,7 @@ void guild_agit_start(void)
*---------------------------------------------------*/
void guild_agit_end(void)
{ // Run All NPC_Event[OnAgitEnd]
- int c = npc_event_doall("OnAgitEnd");
+ int c = npc->event_doall("OnAgitEnd");
ShowStatus("NPC_Event:[OnAgitEnd] Run (%d) Events by @AgitEnd.\n",c);
}
@@ -2094,7 +2094,7 @@ void guild_agit_end(void)
*---------------------------------------------------*/
void guild_agit2_start(void)
{ // Run All NPC_Event[OnAgitStart2]
- int c = npc_event_doall("OnAgitStart2");
+ int c = npc->event_doall("OnAgitStart2");
ShowStatus("NPC_Event:[OnAgitStart2] Run (%d) Events by @AgitStart2.\n",c);
}
@@ -2103,7 +2103,7 @@ void guild_agit2_start(void)
*---------------------------------------------------*/
void guild_agit2_end(void)
{ // Run All NPC_Event[OnAgitEnd2]
- int c = npc_event_doall("OnAgitEnd2");
+ int c = npc->event_doall("OnAgitEnd2");
ShowStatus("NPC_Event:[OnAgitEnd2] Run (%d) Events by @AgitEnd2.\n",c);
}
diff --git a/src/map/homunculus.c b/src/map/homunculus.c
index e0443f1f6..81971ebef 100644
--- a/src/map/homunculus.c
+++ b/src/map/homunculus.c
@@ -736,7 +736,7 @@ bool homunculus_create(struct map_session_data *sd, struct s_homunculus *hom) {
}
sd->hd = hd = (struct homun_data*)aCalloc(1,sizeof(struct homun_data));
hd->bl.type = BL_HOM;
- hd->bl.id = npc_get_new_npc_id();
+ hd->bl.id = npc->get_new_npc_id();
hd->master = sd;
hd->homunculusDB = &homun->db[i];
diff --git a/src/map/instance.c b/src/map/instance.c
index 204b7c137..98a0dfc8f 100644
--- a/src/map/instance.c
+++ b/src/map/instance.c
@@ -297,7 +297,7 @@ int instance_map_npcsub(struct block_list* bl, va_list args) {
struct npc_data* nd = (struct npc_data*)bl;
int16 m = va_arg(args, int); // Destination Map
- if ( npc_duplicate4instance(nd, m) )
+ if ( npc->duplicate4instance(nd, m) )
ShowDebug("instance_map_npcsub:npc_duplicate4instance failed (%s/%d)\n",nd->name,m);
return 1;
@@ -341,7 +341,7 @@ int instance_cleanup_sub(struct block_list *bl, va_list ap) {
iMap->quit((struct map_session_data *) bl);
break;
case BL_NPC:
- npc_unload((struct npc_data *)bl,true);
+ npc->unload((struct npc_data *)bl,true);
break;
case BL_MOB:
unit->free(bl,CLR_OUTSIGHT);
diff --git a/src/map/map.c b/src/map/map.c
index 64e765b27..e55dea152 100644
--- a/src/map/map.c
+++ b/src/map/map.c
@@ -372,7 +372,7 @@ int map_moveblock(struct block_list *bl, int x1, int y1, unsigned int tick)
sc->data[SC_PROPERTYWALK]->val3 >= skill->get_maxcount(sc->data[SC_PROPERTYWALK]->val1,sc->data[SC_PROPERTYWALK]->val2) )
status_change_end(bl,SC_PROPERTYWALK,INVALID_TIMER);
} else if (bl->type == BL_NPC)
- npc_unsetcells((TBL_NPC*)bl);
+ npc->unsetcells((TBL_NPC*)bl);
if (moveblock) iMap->delblock(bl);
#ifdef CELL_NOSTACK
@@ -443,7 +443,7 @@ int map_moveblock(struct block_list *bl, int x1, int y1, unsigned int tick)
}
}
} else if (bl->type == BL_NPC)
- npc_setcells((TBL_NPC*)bl);
+ npc->setcells((TBL_NPC*)bl);
return 0;
}
@@ -1534,10 +1534,10 @@ int map_quit(struct map_session_data *sd) {
}
if (sd->npc_timer_id != INVALID_TIMER) //Cancel the event timer.
- npc_timerevent_quit(sd);
+ npc->timerevent_quit(sd);
if (sd->npc_id)
- npc_event_dequeue(sd);
+ npc->event_dequeue(sd);
if( sd->bg_id && !sd->bg_queue.arena ) /* TODO: dump this chunk after bg_queue is fully enabled */
bg_team_leave(sd,1);
@@ -1548,7 +1548,7 @@ int map_quit(struct map_session_data *sd) {
for( i = 0; i < sd->queues_count; i++ ) {
struct hQueue *queue;
if( (queue = script->queue(sd->queues[i])) && queue->onLogOut[0] != '\0' ) {
- npc_event(sd, queue->onLogOut, 0);
+ npc->event(sd, queue->onLogOut, 0);
}
}
/* two times, the npc event above may assign a new one or delete others */
@@ -1557,7 +1557,7 @@ int map_quit(struct map_session_data *sd) {
script->queue_remove(sd->queues[i],sd->status.account_id);
}
- npc_script_event(sd, NPCE_LOGOUT);
+ npc->script_event(sd, NPCE_LOGOUT);
//Unit_free handles clearing the player related data,
//iMap->quit handles extra specific data which is related to quitting normally
@@ -2104,7 +2104,7 @@ void map_spawnmobs(int16 m)
if(map[m].moblist[i]!=NULL)
{
k+=map[m].moblist[i]->num;
- npc_parse_mob2(map[m].moblist[i]);
+ npc->parse_mob2(map[m].moblist[i]);
}
if (battle_config.etc_log && k > 0)
@@ -2361,7 +2361,7 @@ void map_cellfromcache(struct map_data *m) {
m->setcell = map_setcell;
for(i = 0; i < m->npc_num; i++) {
- npc_setcells(m->npc[i]);
+ npc->setcells(m->npc[i]);
}
}
}
@@ -3274,9 +3274,9 @@ int map_config_read(char *cfgName) {
else if (strcmpi(w1, "delmap") == 0)
iMap->map_num--;
else if (strcmpi(w1, "npc") == 0)
- npc_addsrcfile(w2);
+ npc->addsrcfile(w2);
else if (strcmpi(w1, "delnpc") == 0)
- npc_delsrcfile(w2);
+ npc->delsrcfile(w2);
else if (strcmpi(w1, "autosave_time") == 0) {
iMap->autosave_interval = atoi(w2);
if (iMap->autosave_interval < 1) //Revert to default saving.
@@ -3379,7 +3379,7 @@ void map_reloadnpc_sub(char *cfgName)
*ptr = '\0';
if (strcmpi(w1, "npc") == 0)
- npc_addsrcfile(w2);
+ npc->addsrcfile(w2);
else if (strcmpi(w1, "import") == 0)
map_reloadnpc_sub(w2);
else
@@ -3392,7 +3392,7 @@ void map_reloadnpc_sub(char *cfgName)
void map_reloadnpc(bool clear)
{
if (clear)
- npc_addsrcfile("clear"); // this will clear the current script list
+ npc->addsrcfile("clear"); // this will clear the current script list
#ifdef RENEWAL
map_reloadnpc_sub("npc/re/scripts_main.conf");
@@ -3563,7 +3563,7 @@ void map_zone_remove(int m) {
}
}
- npc_parse_mapflag(map[m].name,empty,flag,params,empty,empty,empty);
+ npc->parse_mapflag(map[m].name,empty,flag,params,empty,empty,empty);
aFree(map[m].zone_mf[k]);
map[m].zone_mf[k] = NULL;
}
@@ -4287,7 +4287,7 @@ void map_zone_apply(int m, struct map_zone_data *zone, const char* start, const
if( map_zone_mf_cache(m,flag,params) )
continue;
- npc_parse_mapflag(map[m].name,empty,flag,params,start,buffer,filepath);
+ npc->parse_mapflag(map[m].name,empty,flag,params,start,buffer,filepath);
}
}
/* used on npc load and reload to apply all "Normal" and "PK Mode" zones */
@@ -4315,7 +4315,7 @@ void map_zone_init(void) {
if( map[j].zone == zone ) {
if( map_zone_mf_cache(j,flag,params) )
break;
- npc_parse_mapflag(map[j].name,empty,flag,params,empty,empty,empty);
+ npc->parse_mapflag(map[j].name,empty,flag,params,empty,empty,empty);
}
}
}
@@ -4337,7 +4337,7 @@ void map_zone_init(void) {
if( map[j].zone == zone ) {
if( map_zone_mf_cache(j,flag,params) )
break;
- npc_parse_mapflag(map[j].name,empty,flag,params,empty,empty,empty);
+ npc->parse_mapflag(map[j].name,empty,flag,params,empty,empty,empty);
}
}
}
@@ -4869,7 +4869,7 @@ int cleanup_sub(struct block_list *bl, va_list ap) {
iMap->quit((struct map_session_data *) bl);
break;
case BL_NPC:
- npc_unload((struct npc_data *)bl,false);
+ npc->unload((struct npc_data *)bl,false);
break;
case BL_MOB:
unit->free(bl,CLR_OUTSIGHT);
@@ -4917,7 +4917,7 @@ void do_final(void)
mapit->free(iter);
/* prepares npcs for a faster shutdown process */
- do_clear_npc();
+ npc->do_clear_npc();
// remove all objects on maps
for (i = 0; i < iMap->map_num; i++) {
@@ -4936,7 +4936,7 @@ void do_final(void)
chrif->do_final_chrif();
ircbot->final();/* before clif. */
clif->final();
- do_final_npc();
+ npc->final();
script->final();
itemdb->final();
instance->final();
@@ -5170,6 +5170,7 @@ void map_hp_symbols(void) {
HPM->share(mercenary,"mercenary");
HPM->share(mob,"mob");
HPM->share(unit,"unit");
+ HPM->share(npc,"npc");
/* partial */
HPM->share(mapit,"mapit");
@@ -5416,13 +5417,13 @@ int do_init(int argc, char *argv[])
mercenary->init();
elemental->do_init_elemental();
do_init_quest();
- do_init_npc();
+ npc->init();
unit->init();
do_init_battleground();
iDuel->do_init_duel();
vending->init();
- npc_event_do_oninit(); // Init npcs (OnInit)
+ npc->event_do_oninit(); // Init npcs (OnInit)
if (battle_config.pk_mode)
ShowNotice("Server is running on '"CL_WHITE"PK Mode"CL_RESET"'.\n");
diff --git a/src/map/mercenary.c b/src/map/mercenary.c
index 8bafcde97..bf802c643 100644
--- a/src/map/mercenary.c
+++ b/src/map/mercenary.c
@@ -301,7 +301,7 @@ int merc_data_received(struct s_mercenary *merc, bool flag)
{
sd->md = md = (struct mercenary_data*)aCalloc(1,sizeof(struct mercenary_data));
md->bl.type = BL_MER;
- md->bl.id = npc_get_new_npc_id();
+ md->bl.id = npc->get_new_npc_id();
md->devotion_flag = 0;
md->master = sd;
diff --git a/src/map/mob.c b/src/map/mob.c
index c566262df..13fdae1ee 100644
--- a/src/map/mob.c
+++ b/src/map/mob.c
@@ -132,7 +132,7 @@ void mvptomb_create(struct mob_data *md, char *killer, time_t time)
CREATE(nd, struct npc_data, 1);
- nd->bl.id = md->tomb_nid = npc_get_new_npc_id();
+ nd->bl.id = md->tomb_nid = npc->get_new_npc_id();
nd->dir = md->ud.dir;
nd->bl.m = md->bl.m;
@@ -259,7 +259,7 @@ int mob_parse_dataset(struct spawn_data *data)
*------------------------------------------*/
struct mob_data* mob_spawn_dataset(struct spawn_data *data) {
struct mob_data *md = (struct mob_data*)aCalloc(1, sizeof(struct mob_data));
- md->bl.id= npc_get_new_npc_id();
+ md->bl.id= npc->get_new_npc_id();
md->bl.type = BL_MOB;
md->bl.m = data->m;
md->bl.x = data->x;
@@ -2579,15 +2579,15 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type)
if( md->npc_event[0] && !md->state.npc_killmonster ) {
if( sd && battle_config.mob_npc_event_type ) {
pc->setparam(sd, SP_KILLERRID, sd->bl.id);
- npc_event(sd,md->npc_event,0);
+ npc->event(sd,md->npc_event,0);
} else if( mvp_sd ) {
pc->setparam(mvp_sd, SP_KILLERRID, sd?sd->bl.id:0);
- npc_event(mvp_sd,md->npc_event,0);
+ npc->event(mvp_sd,md->npc_event,0);
} else
- npc_event_do(md->npc_event);
+ npc->event_do(md->npc_event);
} else if( mvp_sd && !md->state.npc_killmonster ) {
pc->setparam(mvp_sd, SP_KILLEDRID, md->class_);
- npc_script_event(mvp_sd, NPCE_KILLNPC); // PCKillNPC [Lance]
+ npc->script_event(mvp_sd, NPCE_KILLNPC); // PCKillNPC [Lance]
}
md->status.hp = 1;
diff --git a/src/map/npc.c b/src/map/npc.c
index c4ef1bcf9..1a813560b 100644
--- a/src/map/npc.c
+++ b/src/map/npc.c
@@ -36,15 +36,7 @@
#include <time.h>
#include <errno.h>
-
-struct npc_data* fake_nd;
-
-// linked list of npc source files
-struct npc_src_list {
- struct npc_src_list* next;
- char name[4]; // dynamic array, the structure is allocated with extra bytes (string length)
-};
-static struct npc_src_list* npc_src_files = NULL;
+struct npc_interface npc_s;
static int npc_id=START_NPC_NUM;
static int npc_warp=0;
@@ -54,46 +46,9 @@ static int npc_mob=0;
static int npc_delay_mob=0;
static int npc_cache_mob=0;
-/// Returns a new npc id that isn't being used in id_db.
-/// Fatal error if nothing is available.
-int npc_get_new_npc_id(void) {
- if( npc_id >= START_NPC_NUM && !iMap->blid_exists(npc_id) )
- return npc_id++;// available
- else {// find next id
- int base_id = npc_id;
- while( base_id != ++npc_id ) {
- if( npc_id < START_NPC_NUM )
- npc_id = START_NPC_NUM;
- if( !iMap->blid_exists(npc_id) )
- return npc_id++;// available
- }
- // full loop, nothing available
- ShowFatalError("npc_get_new_npc_id: All ids are taken. Exiting...");
- exit(1);
- }
-}
-
-static DBMap* ev_db; // const char* event_name -> struct event_data*
-static DBMap* ev_label_db; // const char* label_name (without leading "::") -> struct linkdb_node** (key: struct npc_data*; data: struct event_data*)
-static DBMap* npcname_db; // const char* npc_name -> struct npc_data*
-
-struct event_data {
- struct npc_data *nd;
- int pos;
-};
-
-static struct eri *timer_event_ers; //For the npc timer data. [Skotlex]
-
-/* hello */
static char *npc_last_path;
static char *npc_last_ref;
-
-struct npc_path_data {
- char* path;
- unsigned short references;
-};
struct npc_path_data *npc_last_npd;
-static DBMap *npc_path_db;
//For holding the view data of npc classes. [Skotlex]
static struct view_data npc_viewdb[MAX_NPC_CLASS];
@@ -120,7 +75,26 @@ struct view_data* npc_get_viewdata(int class_)
return NULL;
}
-static int npc_isnear_sub(struct block_list* bl, va_list args) {
+/// Returns a new npc id that isn't being used in id_db.
+/// Fatal error if nothing is available.
+int npc_get_new_npc_id(void) {
+ if( npc_id >= START_NPC_NUM && !iMap->blid_exists(npc_id) )
+ return npc_id++;// available
+ else {// find next id
+ int base_id = npc_id;
+ while( base_id != ++npc_id ) {
+ if( npc_id < START_NPC_NUM )
+ npc_id = START_NPC_NUM;
+ if( !iMap->blid_exists(npc_id) )
+ return npc_id++;// available
+ }
+ // full loop, nothing available
+ ShowFatalError("npc_get_new_npc_id: All ids are taken. Exiting...");
+ exit(1);
+ }
+}
+
+int npc_isnear_sub(struct block_list* bl, va_list args) {
struct npc_data *nd = (struct npc_data*)bl;
if( nd->option & (OPTION_HIDE|OPTION_INVISIBLE) )
@@ -132,7 +106,7 @@ static int npc_isnear_sub(struct block_list* bl, va_list args) {
bool npc_isnear(struct block_list * bl) {
if( battle_config.min_npc_vendchat_distance > 0 &&
- iMap->foreachinrange(npc_isnear_sub,bl, battle_config.min_npc_vendchat_distance, BL_NPC) )
+ iMap->foreachinrange(npc->isnear_sub,bl, battle_config.min_npc_vendchat_distance, BL_NPC) )
return true;
return false;
@@ -149,7 +123,7 @@ int npc_ontouch_event(struct map_session_data *sd, struct npc_data *nd)
return 1; // Can't trigger 'OnTouch_'. try 'OnTouch' later.
snprintf(name, ARRAYLENGTH(name), "%s::%s", nd->exname, script->config.ontouch_name);
- return npc_event(sd,name,1);
+ return npc->event(sd,name,1);
}
int npc_ontouch2_event(struct map_session_data *sd, struct npc_data *nd)
@@ -160,7 +134,7 @@ int npc_ontouch2_event(struct map_session_data *sd, struct npc_data *nd)
return 0;
snprintf(name, ARRAYLENGTH(name), "%s::%s", nd->exname, script->config.ontouch2_name);
- return npc_event(sd,name,2);
+ return npc->event(sd,name,2);
}
/*==========================================
@@ -179,13 +153,13 @@ int npc_enable_sub(struct block_list *bl, va_list ap)
if (nd->option&OPTION_INVISIBLE)
return 1;
- if( npc_ontouch_event(sd,nd) > 0 && npc_ontouch2_event(sd,nd) > 0 )
+ if( npc->ontouch_event(sd,nd) > 0 && npc->ontouch2_event(sd,nd) > 0 )
{ // failed to run OnTouch event, so just click the npc
if (sd->npc_id != 0)
return 0;
pc_stop_walking(sd,1);
- npc_click(sd,nd);
+ npc->click(sd,nd);
}
}
return 0;
@@ -196,7 +170,7 @@ int npc_enable_sub(struct block_list *bl, va_list ap)
*------------------------------------------*/
int npc_enable(const char* name, int flag)
{
- struct npc_data* nd = npc_name2id(name);
+ struct npc_data* nd = npc->name2id(name);
if ( nd == NULL ) {
ShowError("npc_enable: Attempted to %s a non-existing NPC '%s' (flag=%d).\n", (flag&3) ? "show" : "hide", name, flag);
@@ -224,7 +198,7 @@ int npc_enable(const char* name, int flag)
clif->changeoption(&nd->bl);
if( flag&3 && (nd->u.scr.xs >= 0 || nd->u.scr.ys >= 0) ) //check if player standing on a OnTouchArea
- iMap->foreachinarea( npc_enable_sub, nd->bl.m, nd->bl.x-nd->u.scr.xs, nd->bl.y-nd->u.scr.ys, nd->bl.x+nd->u.scr.xs, nd->bl.y+nd->u.scr.ys, BL_PC, nd );
+ iMap->foreachinarea( npc->enable_sub, nd->bl.m, nd->bl.x-nd->u.scr.xs, nd->bl.y-nd->u.scr.ys, nd->bl.x+nd->u.scr.xs, nd->bl.y+nd->u.scr.ys, BL_PC, nd );
return 0;
}
@@ -234,7 +208,7 @@ int npc_enable(const char* name, int flag)
*------------------------------------------*/
struct npc_data* npc_name2id(const char* name)
{
- return (struct npc_data *) strdb_get(npcname_db, name);
+ return (struct npc_data *) strdb_get(npc->name_db, name);
}
/**
* For the Secure NPC Timeout option (check config/Secure.h) [RR]
@@ -277,7 +251,7 @@ int npc_rr_secure_timeout_timer(int tid, unsigned int tick, int id, intptr_t dat
clif->scriptclear(sd,sd->npc_id);
sd->npc_idle_timer = INVALID_TIMER;
} else //Create a new instance of ourselves to continue
- sd->npc_idle_timer = iTimer->add_timer(iTimer->gettick() + (SECURE_NPCTIMEOUT_INTERVAL*1000),npc_rr_secure_timeout_timer,sd->bl.id,0);
+ sd->npc_idle_timer = iTimer->add_timer(iTimer->gettick() + (SECURE_NPCTIMEOUT_INTERVAL*1000),npc->secure_timeout_timer,sd->bl.id,0);
return 0;
}
#endif
@@ -317,7 +291,7 @@ int npc_event_dequeue(struct map_session_data* sd)
/**
* @see DBCreateData
*/
-static DBData npc_event_export_create(DBKey key, va_list args)
+DBData npc_event_export_create(DBKey key, va_list args)
{
struct linkdb_node** head_ptr;
CREATE(head_ptr, struct linkdb_node*, 1);
@@ -329,7 +303,7 @@ static DBData npc_event_export_create(DBKey key, va_list args)
* exports a npc event label
* called from npc_parse_script
*------------------------------------------*/
-static int npc_event_export(struct npc_data *nd, int i)
+int npc_event_export(struct npc_data *nd, int i)
{
char* lname = nd->u.scr.label_list[i].name;
int pos = nd->u.scr.label_list[i].pos;
@@ -338,14 +312,14 @@ static int npc_event_export(struct npc_data *nd, int i)
struct linkdb_node **label_linkdb = NULL;
char buf[EVENT_NAME_LENGTH];
snprintf(buf, ARRAYLENGTH(buf), "%s::%s", nd->exname, lname);
- if (strdb_exists(ev_db, buf)) // There was already another event of the same name?
+ if (strdb_exists(npc->ev_db, buf)) // There was already another event of the same name?
return 1;
// generate the data and insert it
CREATE(ev, struct event_data, 1);
ev->nd = nd;
ev->pos = pos;
- strdb_put(ev_db, buf, ev);
- label_linkdb = strdb_ensure(ev_label_db, lname, npc_event_export_create);
+ strdb_put(npc->ev_db, buf, ev);
+ label_linkdb = strdb_ensure(npc->ev_label_db, lname, npc->event_export_create);
linkdb_insert(label_linkdb, nd, ev);
}
return 0;
@@ -373,7 +347,7 @@ void npc_event_doall_sub(void *key, void *data, va_list ap)
if(rid) { // a player may only have 1 script running at the same time
char buf[EVENT_NAME_LENGTH];
snprintf(buf, ARRAYLENGTH(buf), "%s::%s", ev->nd->exname, name);
- npc_event_sub(iMap->id2sd(rid), ev, buf);
+ npc->event_sub(iMap->id2sd(rid), ev, buf);
}
else {
script->run(ev->nd->u.scr.script, ev->pos, rid, ev->nd->bl.id);
@@ -386,10 +360,10 @@ void npc_event_doall_sub(void *key, void *data, va_list ap)
int npc_event_do(const char* name)
{
if( name[0] == ':' && name[1] == ':' ) {
- return npc_event_doall(name+2); // skip leading "::"
+ return npc->event_doall(name+2); // skip leading "::"
}
else {
- struct event_data *ev = strdb_get(ev_db, name);
+ struct event_data *ev = strdb_get(npc->ev_db, name);
if (ev) {
script->run(ev->nd->u.scr.script, ev->pos, 0, ev->nd->bl.id);
return 1;
@@ -402,19 +376,19 @@ int npc_event_do(const char* name)
int npc_event_doall_id(const char* name, int rid)
{
int c = 0;
- struct linkdb_node **label_linkdb = strdb_get(ev_label_db, name);
+ struct linkdb_node **label_linkdb = strdb_get(npc->ev_label_db, name);
if (label_linkdb == NULL)
return 0;
- linkdb_foreach(label_linkdb, npc_event_doall_sub, &c, name, rid);
+ linkdb_foreach(label_linkdb, npc->event_doall_sub, &c, name, rid);
return c;
}
// runs the specified event (global only)
int npc_event_doall(const char* name)
{
- return npc_event_doall_id(name, 0);
+ return npc->event_doall_id(name, 0);
}
/*==========================================
@@ -447,23 +421,23 @@ int npc_event_do_clock(int tid, unsigned int tick, int id, intptr_t data)
}
sprintf(buf,"OnMinute%02d",t->tm_min);
- c += npc_event_doall(buf);
+ c += npc->event_doall(buf);
sprintf(buf,"OnClock%02d%02d",t->tm_hour,t->tm_min);
- c += npc_event_doall(buf);
+ c += npc->event_doall(buf);
sprintf(buf,"On%s%02d%02d",day,t->tm_hour,t->tm_min);
- c += npc_event_doall(buf);
+ c += npc->event_doall(buf);
}
if (t->tm_hour != ev_tm_b.tm_hour) {
sprintf(buf,"OnHour%02d",t->tm_hour);
- c += npc_event_doall(buf);
+ c += npc->event_doall(buf);
}
if (t->tm_mday != ev_tm_b.tm_mday) {
sprintf(buf,"OnDay%02d%02d",t->tm_mon+1,t->tm_mday);
- c += npc_event_doall(buf);
+ c += npc->event_doall(buf);
}
memcpy(&ev_tm_b,t,sizeof(ev_tm_b));
@@ -475,9 +449,9 @@ int npc_event_do_clock(int tid, unsigned int tick, int id, intptr_t data)
*------------------------------------------*/
void npc_event_do_oninit(void)
{
- ShowStatus("Event '"CL_WHITE"OnInit"CL_RESET"' executed with '"CL_WHITE"%d"CL_RESET"' NPCs."CL_CLL"\n", npc_event_doall("OnInit"));
+ ShowStatus("Event '"CL_WHITE"OnInit"CL_RESET"' executed with '"CL_WHITE"%d"CL_RESET"' NPCs."CL_CLL"\n", npc->event_doall("OnInit"));
- iTimer->add_timer_interval(iTimer->gettick()+100,npc_event_do_clock,0,0,1000);
+ iTimer->add_timer_interval(iTimer->gettick()+100,npc->event_do_clock,0,0,1000);
}
/*==========================================
@@ -538,7 +512,7 @@ int npc_timerevent(int tid, unsigned int tick, int id, intptr_t data)
if( ted->rid && !(sd = iMap->id2sd(ted->rid)) )
{
ShowError("npc_timerevent: Attached player not found.\n");
- ers_free(timer_event_ers, ted);
+ ers_free(npc->timer_event_ers, ted);
return 0;
}
@@ -563,9 +537,9 @@ int npc_timerevent(int tid, unsigned int tick, int id, intptr_t data)
next = nd->u.scr.timer_event[ ted->next ].timer - nd->u.scr.timer_event[ ted->next - 1 ].timer;
ted->time += next;
if( sd )
- sd->npc_timer_id = iTimer->add_timer(tick+next,npc_timerevent,id,(intptr_t)ted);
+ sd->npc_timer_id = iTimer->add_timer(tick+next,npc->timerevent,id,(intptr_t)ted);
else
- nd->u.scr.timerid = iTimer->add_timer(tick+next,npc_timerevent,id,(intptr_t)ted);
+ nd->u.scr.timerid = iTimer->add_timer(tick+next,npc->timerevent,id,(intptr_t)ted);
}
else
{
@@ -574,7 +548,7 @@ int npc_timerevent(int tid, unsigned int tick, int id, intptr_t data)
else
nd->u.scr.timerid = INVALID_TIMER;
- ers_free(timer_event_ers, ted);
+ ers_free(npc->timer_event_ers, ted);
}
// Run the script
@@ -619,20 +593,20 @@ int npc_timerevent_start(struct npc_data* nd, int rid)
int next;
struct timer_event_data *ted;
// Arrange for the next event
- ted = ers_alloc(timer_event_ers, struct timer_event_data);
+ ted = ers_alloc(npc->timer_event_ers, struct timer_event_data);
ted->next = j; // Set event index
ted->time = nd->u.scr.timer_event[j].timer;
next = nd->u.scr.timer_event[j].timer - nd->u.scr.timer;
if( sd )
{
ted->rid = sd->bl.id; // Attach only the player if attachplayerrid was used.
- sd->npc_timer_id = iTimer->add_timer(tick+next,npc_timerevent,nd->bl.id,(intptr_t)ted);
+ sd->npc_timer_id = iTimer->add_timer(tick+next,npc->timerevent,nd->bl.id,(intptr_t)ted);
}
else
{
ted->rid = 0;
nd->u.scr.timertick = tick; // Set when timer is started
- nd->u.scr.timerid = iTimer->add_timer(tick+next,npc_timerevent,nd->bl.id,(intptr_t)ted);
+ nd->u.scr.timerid = iTimer->add_timer(tick+next,npc->timerevent,nd->bl.id,(intptr_t)ted);
}
} else if (!sd) {
@@ -667,8 +641,8 @@ int npc_timerevent_stop(struct npc_data* nd)
{
td = iTimer->get_timer(*tid);
if( td && td->data )
- ers_free(timer_event_ers, (void*)td->data);
- iTimer->delete_timer(*tid,npc_timerevent);
+ ers_free(npc->timer_event_ers, (void*)td->data);
+ iTimer->delete_timer(*tid,npc->timerevent);
*tid = INVALID_TIMER;
}
@@ -701,7 +675,7 @@ void npc_timerevent_quit(struct map_session_data* sd)
// Delete timer
nd = (struct npc_data *)iMap->id2bl(td->id);
ted = (struct timer_event_data*)td->data;
- iTimer->delete_timer(sd->npc_timer_id, npc_timerevent);
+ iTimer->delete_timer(sd->npc_timer_id, npc->timerevent);
sd->npc_timer_id = INVALID_TIMER;
// Execute OnTimerQuit
@@ -711,7 +685,7 @@ void npc_timerevent_quit(struct map_session_data* sd)
struct event_data *ev;
snprintf(buf, ARRAYLENGTH(buf), "%s::OnTimerQuit", nd->exname);
- ev = (struct event_data*)strdb_get(ev_db, buf);
+ ev = (struct event_data*)strdb_get(npc->ev_db, buf);
if( ev && ev->nd != nd )
{
ShowWarning("npc_timerevent_quit: Unable to execute \"OnTimerQuit\", two NPCs have the same event name [%s]!\n",buf);
@@ -740,7 +714,7 @@ void npc_timerevent_quit(struct map_session_data* sd)
nd->u.scr.timertick = old_tick;
}
}
- ers_free(timer_event_ers, ted);
+ ers_free(npc->timer_event_ers, ted);
}
/*==========================================
@@ -780,9 +754,9 @@ int npc_settimerevent_tick(struct npc_data* nd, int newtimer)
// Check if timer is started
flag = (nd->u.scr.timerid != INVALID_TIMER || nd->u.scr.timertick);
- if( flag ) npc_timerevent_stop(nd);
+ if( flag ) npc->timerevent_stop(nd);
nd->u.scr.timer = newtimer;
- if( flag ) npc_timerevent_start(nd, -1);
+ if( flag ) npc->timerevent_start(nd, -1);
nd->u.scr.rid = old_rid;
return 0;
@@ -807,7 +781,7 @@ int npc_event_sub(struct map_session_data* sd, struct event_data* ev, const char
if( ev->nd->option&OPTION_INVISIBLE )
{
//Disabled npc, shouldn't trigger event.
- npc_event_dequeue(sd);
+ npc->event_dequeue(sd);
return 2;
}
script->run(ev->nd->u.scr.script,ev->pos,sd->bl.id,ev->nd->bl.id);
@@ -819,7 +793,7 @@ int npc_event_sub(struct map_session_data* sd, struct event_data* ev, const char
*------------------------------------------*/
int npc_event(struct map_session_data* sd, const char* eventname, int ontouch)
{
- struct event_data* ev = (struct event_data*)strdb_get(ev_db, eventname);
+ struct event_data* ev = (struct event_data*)strdb_get(npc->ev_db, eventname);
struct npc_data *nd;
nullpo_ret(sd);
@@ -840,7 +814,7 @@ int npc_event(struct map_session_data* sd, const char* eventname, int ontouch)
break;
}
- return npc_event_sub(sd,ev,eventname);
+ return npc->event_sub(sd,ev,eventname);
}
/*==========================================
@@ -865,7 +839,7 @@ int npc_touch_areanpc_sub(struct block_list *bl, va_list ap)
if( pc_id == sd->bl.id )
return 0;
- npc_event(sd,name,1);
+ npc->event(sd,name,1);
return 1;
}
@@ -894,7 +868,7 @@ int npc_touchnext_areanpc(struct map_session_data* sd, bool leavemap)
nd->touching_id = sd->touching_id = 0;
snprintf(name, ARRAYLENGTH(name), "%s::%s", nd->exname, script->config.ontouch_name);
- iMap->forcountinarea(npc_touch_areanpc_sub,nd->bl.m,nd->bl.x - xs,nd->bl.y - ys,nd->bl.x + xs,nd->bl.y + ys,1,BL_PC,sd->bl.id,name);
+ iMap->forcountinarea(npc->touch_areanpc_sub,nd->bl.m,nd->bl.x - xs,nd->bl.y - ys,nd->bl.x + xs,nd->bl.y + ys,1,BL_PC,sd->bl.id,name);
}
return 0;
}
@@ -969,7 +943,7 @@ int npc_touch_areanpc(struct map_session_data* sd, int16 m, int16 x, int16 y)
break;
}
- if( npc_ontouch_event(sd,map[m].npc[i]) > 0 && npc_ontouch2_event(sd,map[m].npc[i]) > 0 )
+ if( npc->ontouch_event(sd,map[m].npc[i]) > 0 && npc->ontouch2_event(sd,map[m].npc[i]) > 0 )
{ // failed to run OnTouch event, so just click the npc
struct unit_data *ud = unit->bl2ud(&sd->bl);
if( ud && ud->walkpath.path_pos < ud->walkpath.path_len )
@@ -978,7 +952,7 @@ int npc_touch_areanpc(struct map_session_data* sd, int16 m, int16 x, int16 y)
ud->walkpath.path_pos = ud->walkpath.path_len;
}
sd->areanpc_id = map[m].npc[i]->bl.id;
- npc_click(sd,map[m].npc[i]);
+ npc->click(sd,map[m].npc[i]);
}
break;
}
@@ -1028,7 +1002,7 @@ int npc_touch_areanpc2(struct mob_data *md)
if( map[m].npc[i]->bl.id == md->areanpc_id )
break; // Already touch this NPC
snprintf(eventname, ARRAYLENGTH(eventname), "%s::OnTouchNPC", map[m].npc[i]->exname);
- if( (ev = (struct event_data*)strdb_get(ev_db, eventname)) == NULL || ev->nd == NULL )
+ if( (ev = (struct event_data*)strdb_get(npc->ev_db, eventname)) == NULL || ev->nd == NULL )
break; // No OnTouchNPC Event
md->areanpc_id = map[m].npc[i]->bl.id;
id = md->bl.id; // Stores Unique ID
@@ -1134,7 +1108,7 @@ struct npc_data* npc_checknear(struct map_session_data* sd, struct block_list* b
*------------------------------------------*/
int npc_globalmessage(const char* name, const char* mes)
{
- struct npc_data* nd = npc_name2id(name);
+ struct npc_data* nd = npc->name2id(name);
char temp[100];
if (!nd)
@@ -1185,7 +1159,7 @@ int npc_click(struct map_session_data* sd, struct npc_data* nd)
}
if(!nd) return 1;
- if ((nd = npc_checknear(sd,&nd->bl)) == NULL)
+ if ((nd = npc->checknear(sd,&nd->bl)) == NULL)
return 1;
//Hidden/Disabled npc.
if (nd->class_ < 0 || nd->option&(OPTION_INVISIBLE|OPTION_HIDE))
@@ -1202,7 +1176,7 @@ int npc_click(struct map_session_data* sd, struct npc_data* nd)
script->run(nd->u.scr.script,0,sd->bl.id,nd->bl.id);
break;
case TOMB:
- run_tomb(sd,nd);
+ npc->run_tomb(sd,nd);
break;
}
@@ -1225,9 +1199,9 @@ int npc_scriptcont(struct map_session_data* sd, int id, bool closing)
return 1;
}
- if(id != fake_nd->bl.id) { // Not item script
- if ((npc_checknear(sd,iMap->id2bl(id))) == NULL){
- ShowWarning("npc_scriptcont: failed npc_checknear test.\n");
+ if(id != npc->fake_nd->bl.id) { // Not item script
+ if ((npc->checknear(sd,iMap->id2bl(id))) == NULL){
+ ShowWarning("npc_scriptcont: failed npc->checknear test.\n");
return 1;
}
}
@@ -1264,7 +1238,7 @@ int npc_buysellsel(struct map_session_data* sd, int id, int type)
nullpo_retr(1, sd);
- if ((nd = npc_checknear(sd,iMap->id2bl(id))) == NULL)
+ if ((nd = npc->checknear(sd,iMap->id2bl(id))) == NULL)
return 1;
if (nd->subtype!=SHOP) {
@@ -1374,7 +1348,7 @@ int npc_cashshop_buylist(struct map_session_data *sd, int points, int count, uns
}
//npc_buylist for script-controlled shops.
-static int npc_buylist_sub(struct map_session_data* sd, int n, unsigned short* item_list, struct npc_data* nd)
+int npc_buylist_sub(struct map_session_data* sd, int n, unsigned short* item_list, struct npc_data* nd)
{
char npc_ev[EVENT_NAME_LENGTH];
int i;
@@ -1393,7 +1367,7 @@ static int npc_buylist_sub(struct map_session_data* sd, int n, unsigned short* i
// invoke event
snprintf(npc_ev, ARRAYLENGTH(npc_ev), "%s::OnBuyItem", nd->exname);
- npc_event(sd, npc_ev, 0);
+ npc->event(sd, npc_ev, 0);
return 0;
}
@@ -1492,7 +1466,7 @@ int npc_buylist(struct map_session_data* sd, int n, unsigned short* item_list)
nullpo_retr(3, sd);
nullpo_retr(3, item_list);
- nd = npc_checknear(sd,iMap->id2bl(sd->npc_shopid));
+ nd = npc->checknear(sd,iMap->id2bl(sd->npc_shopid));
if( nd == NULL )
return 3;
if( nd->subtype != SHOP )
@@ -1552,7 +1526,7 @@ int npc_buylist(struct map_session_data* sd, int n, unsigned short* item_list)
}
if( nd->master_nd != NULL ) //Script-based shops.
- return npc_buylist_sub(sd,n,item_list,nd->master_nd);
+ return npc->buylist_sub(sd,n,item_list,nd->master_nd);
if( z > (double)sd->status.zeny )
return 1; // Not enough Zeny
@@ -1597,7 +1571,7 @@ int npc_buylist(struct map_session_data* sd, int n, unsigned short* item_list)
/// npc_selllist for script-controlled shops
-static int npc_selllist_sub(struct map_session_data* sd, int n, unsigned short* item_list, struct npc_data* nd)
+int npc_selllist_sub(struct map_session_data* sd, int n, unsigned short* item_list, struct npc_data* nd)
{
char npc_ev[EVENT_NAME_LENGTH];
char card_slot[NAME_LENGTH];
@@ -1647,7 +1621,7 @@ static int npc_selllist_sub(struct map_session_data* sd, int n, unsigned short*
// invoke event
snprintf(npc_ev, ARRAYLENGTH(npc_ev), "%s::OnSellItem", nd->exname);
- npc_event(sd, npc_ev, 0);
+ npc->event(sd, npc_ev, 0);
return 0;
}
@@ -1665,7 +1639,7 @@ int npc_selllist(struct map_session_data* sd, int n, unsigned short* item_list)
nullpo_retr(1, sd);
nullpo_retr(1, item_list);
- if( ( nd = npc_checknear(sd, iMap->id2bl(sd->npc_shopid)) ) == NULL || nd->subtype != SHOP ) {
+ if( ( nd = npc->checknear(sd, iMap->id2bl(sd->npc_shopid)) ) == NULL || nd->subtype != SHOP ) {
return 1;
}
@@ -1698,7 +1672,7 @@ int npc_selllist(struct map_session_data* sd, int n, unsigned short* item_list)
}
if( nd->master_nd ) { // Script-controlled shops
- return npc_selllist_sub(sd, n, item_list, nd->master_nd);
+ return npc->selllist_sub(sd, n, item_list, nd->master_nd);
}
// delete items
@@ -1748,7 +1722,7 @@ int npc_remove_map(struct npc_data* nd) {
return 1; //Not assigned to a map.
m = nd->bl.m;
clif->clearunit_area(&nd->bl,CLR_RESPAWN);
- npc_unsetcells(nd);
+ npc->unsetcells(nd);
iMap->delblock(&nd->bl);
//Remove npc from map[].npc list. [Skotlex]
ARR_FIND( 0, map[m].npc_num, i, map[m].npc[i] == nd );
@@ -1763,13 +1737,13 @@ int npc_remove_map(struct npc_data* nd) {
/**
* @see DBApply
*/
-static int npc_unload_ev(DBKey key, DBData *data, va_list ap)
+int npc_unload_ev(DBKey key, DBData *data, va_list ap)
{
struct event_data* ev = DB->data2ptr(data);
char* npcname = va_arg(ap, char *);
if(strcmp(ev->nd->exname,npcname)==0){
- db_remove(ev_db, key);
+ db_remove(npc->ev_db, key);
return 1;
}
return 0;
@@ -1778,7 +1752,7 @@ static int npc_unload_ev(DBKey key, DBData *data, va_list ap)
/**
* @see DBApply
*/
-static int npc_unload_ev_label(DBKey key, DBData *data, va_list ap)
+int npc_unload_ev_label(DBKey key, DBData *data, va_list ap)
{
struct linkdb_node **label_linkdb = DB->data2ptr(data);
struct npc_data* nd = va_arg(ap, struct npc_data *);
@@ -1790,20 +1764,20 @@ static int npc_unload_ev_label(DBKey key, DBData *data, va_list ap)
//Chk if npc matches src_id, then unload.
//Sub-function used to find duplicates.
-static int npc_unload_dup_sub(struct npc_data* nd, va_list args)
+int npc_unload_dup_sub(struct npc_data* nd, va_list args)
{
int src_id;
src_id = va_arg(args, int);
if (nd->src_id == src_id)
- npc_unload(nd, true);
+ npc->unload(nd, true);
return 0;
}
//Removes all npcs that are duplicates of the passed one. [Skotlex]
void npc_unload_duplicates(struct npc_data* nd)
{
- iMap->map_foreachnpc(npc_unload_dup_sub,nd->bl.id);
+ iMap->map_foreachnpc(npc->unload_dup_sub,nd->bl.id);
}
//Removes an npc from map and db.
@@ -1811,10 +1785,10 @@ void npc_unload_duplicates(struct npc_data* nd)
int npc_unload(struct npc_data* nd, bool single) {
nullpo_ret(nd);
- npc_remove_map(nd);
+ npc->remove_map(nd);
iMap->deliddb(&nd->bl);
if( single )
- strdb_remove(npcname_db, nd->exname);
+ strdb_remove(npc->name_db, nd->exname);
if (nd->chat_id) // remove npc chatroom object and kick users
chat->deletenpcchat(nd);
@@ -1826,11 +1800,11 @@ int npc_unload(struct npc_data* nd, bool single) {
if( single && nd->path ) {
struct npc_path_data* npd = NULL;
if( nd->path && nd->path != npc_last_ref ) {
- npd = strdb_get(npc_path_db, nd->path);
+ npd = strdb_get(npc->path_db, nd->path);
}
if( npd && --npd->references == 0 ) {
- strdb_remove(npc_path_db, nd->path);/* remove from db */
+ strdb_remove(npc->path_db, nd->path);/* remove from db */
aFree(nd->path);/* remove now that no other instances exist */
}
}
@@ -1842,8 +1816,8 @@ int npc_unload(struct npc_data* nd, bool single) {
struct block_list* bl;
if( single ) {
- ev_db->foreach(ev_db,npc_unload_ev,nd->exname); //Clean up all events related
- ev_label_db->foreach(ev_label_db,npc_unload_ev_label,nd);
+ npc->ev_db->foreach(npc->ev_db,npc->unload_ev,nd->exname); //Clean up all events related
+ npc->ev_label_db->foreach(npc->ev_label_db,npc->unload_ev_label,nd);
}
iter = mapit_geteachpc();
@@ -1856,8 +1830,8 @@ int npc_unload(struct npc_data* nd, bool single) {
continue;
if( td && td->data )
- ers_free(timer_event_ers, (void*)td->data);
- iTimer->delete_timer(sd->npc_timer_id, npc_timerevent);
+ ers_free(npc->timer_event_ers, (void*)td->data);
+ iTimer->delete_timer(sd->npc_timer_id, npc->timerevent);
sd->npc_timer_id = INVALID_TIMER;
}
}
@@ -1867,8 +1841,8 @@ int npc_unload(struct npc_data* nd, bool single) {
const struct TimerData *td;
td = iTimer->get_timer(nd->u.scr.timerid);
if (td && td->data)
- ers_free(timer_event_ers, (void*)td->data);
- iTimer->delete_timer(nd->u.scr.timerid, npc_timerevent);
+ ers_free(npc->timer_event_ers, (void*)td->data);
+ iTimer->delete_timer(nd->u.scr.timerid, npc->timerevent);
}
if (nd->u.scr.timer_event)
aFree(nd->u.scr.timer_event);
@@ -1888,7 +1862,7 @@ int npc_unload(struct npc_data* nd, bool single) {
guild->flag_remove(nd);
}
- if( nd->ud != &npc_base_ud ) {
+ if( nd->ud != &npc->base_ud ) {
aFree(nd->ud);
nd->ud = NULL;
}
@@ -1903,9 +1877,9 @@ int npc_unload(struct npc_data* nd, bool single) {
//
/// Clears the npc source file list
-static void npc_clearsrcfile(void)
+void npc_clearsrcfile(void)
{
- struct npc_src_list* file = npc_src_files;
+ struct npc_src_list* file = npc->src_files;
struct npc_src_list* file_tofree;
while( file != NULL )
@@ -1914,7 +1888,7 @@ static void npc_clearsrcfile(void)
file = file->next;
aFree(file_tofree);
}
- npc_src_files = NULL;
+ npc->src_files = NULL;
}
/// Adds a npc source file (or removes all)
@@ -1925,12 +1899,12 @@ void npc_addsrcfile(const char* name)
if( strcmpi(name, "clear") == 0 )
{
- npc_clearsrcfile();
+ npc->clearsrcfile();
return;
}
// prevent multiple insert of source files
- file = npc_src_files;
+ file = npc->src_files;
while( file != NULL )
{
if( strcmp(name, file->name) == 0 )
@@ -1943,7 +1917,7 @@ void npc_addsrcfile(const char* name)
file->next = NULL;
safestrncpy(file->name, name, strlen(name) + 1);
if( file_prev == NULL )
- npc_src_files = file;
+ npc->src_files = file;
else
file_prev->next = file;
}
@@ -1951,12 +1925,12 @@ void npc_addsrcfile(const char* name)
/// Removes a npc source file (or all)
void npc_delsrcfile(const char* name)
{
- struct npc_src_list* file = npc_src_files;
+ struct npc_src_list* file = npc->src_files;
struct npc_src_list* file_prev = NULL;
if( strcmpi(name, "all") == 0 )
{
- npc_clearsrcfile();
+ npc->clearsrcfile();
return;
}
@@ -1964,8 +1938,8 @@ void npc_delsrcfile(const char* name)
{
if( strcmp(file->name, name) == 0 )
{
- if( npc_src_files == file )
- npc_src_files = file->next;
+ if( npc->src_files == file )
+ npc->src_files = file->next;
else
file_prev->next = file->next;
aFree(file);
@@ -1978,7 +1952,7 @@ void npc_delsrcfile(const char* name)
/// Parses and sets the name and exname of a npc.
/// Assumes that m, x and y are already set in nd.
-static void npc_parsename(struct npc_data* nd, const char* name, const char* start, const char* buffer, const char* filepath)
+void npc_parsename(struct npc_data* nd, const char* name, const char* start, const char* buffer, const char* filepath)
{
const char* p;
struct npc_data* dnd;// duplicate npc
@@ -2013,7 +1987,7 @@ static void npc_parsename(struct npc_data* nd, const char* name, const char* sta
safestrncpy(nd->exname, newname, sizeof(nd->exname));
}
- if( (dnd=npc_name2id(nd->exname)) != NULL ) {// duplicate unique name, generate new one
+ if( (dnd=npc->name2id(nd->exname)) != NULL ) {// duplicate unique name, generate new one
char this_mapname[32];
char other_mapname[32];
int i = 0;
@@ -2021,7 +1995,7 @@ static void npc_parsename(struct npc_data* nd, const char* name, const char* sta
do {
++i;
snprintf(newname, ARRAYLENGTH(newname), "%d_%d_%d_%d", i, nd->bl.m, nd->bl.x, nd->bl.y);
- } while( npc_name2id(newname) != NULL );
+ } while( npc->name2id(newname) != NULL );
strcpy(this_mapname, (nd->bl.m==-1?"(not on a map)":mapindex_id2name(map[nd->bl.m].index)));
strcpy(other_mapname, (dnd->bl.m==-1?"(not on a map)":mapindex_id2name(map[dnd->bl.m].index)));
@@ -2035,9 +2009,9 @@ static void npc_parsename(struct npc_data* nd, const char* name, const char* sta
if( npc_last_path != filepath ) {
struct npc_path_data * npd = NULL;
- if( !(npd = strdb_get(npc_path_db,filepath) ) ) {
+ if( !(npd = strdb_get(npc->path_db,filepath) ) ) {
CREATE(npd, struct npc_path_data, 1);
- strdb_put(npc_path_db, filepath, npd);
+ strdb_put(npc->path_db, filepath, npd);
CREATE(npd->path, char, strlen(filepath)+1);
safestrncpy(npd->path, filepath, strlen(filepath)+1);
@@ -2064,7 +2038,7 @@ struct npc_data* npc_add_warp(char* name, short from_mapid, short from_x, short
struct npc_data *nd;
CREATE(nd, struct npc_data, 1);
- nd->bl.id = npc_get_new_npc_id();
+ nd->bl.id = npc->get_new_npc_id();
iMap->addnpc(from_mapid, nd);
nd->bl.prev = nd->bl.next = NULL;
nd->bl.m = from_mapid;
@@ -2072,13 +2046,13 @@ struct npc_data* npc_add_warp(char* name, short from_mapid, short from_x, short
nd->bl.y = from_y;
safestrncpy(nd->exname, name, ARRAYLENGTH(nd->exname));
- if (npc_name2id(nd->exname) != NULL)
+ if (npc->name2id(nd->exname) != NULL)
flag = 1;
if (flag == 1)
snprintf(nd->exname, ARRAYLENGTH(nd->exname), "warp_%d_%d_%d", from_mapid, from_x, from_y);
- for( i = 0; npc_name2id(nd->exname) != NULL; ++i )
+ for( i = 0; npc->name2id(nd->exname) != NULL; ++i )
snprintf(nd->exname, ARRAYLENGTH(nd->exname), "warp%d_%d_%d_%d", i, from_mapid, from_x, from_y);
safestrncpy(nd->name, nd->exname, ARRAYLENGTH(nd->name));
@@ -2095,19 +2069,19 @@ struct npc_data* npc_add_warp(char* name, short from_mapid, short from_x, short
nd->u.warp.ys = xs;
nd->bl.type = BL_NPC;
nd->subtype = WARP;
- npc_setcells(nd);
+ npc->setcells(nd);
iMap->addblock(&nd->bl);
iStatus->set_viewdata(&nd->bl, nd->class_);
- nd->ud = &npc_base_ud;
+ nd->ud = &npc->base_ud;
if( map[nd->bl.m].users )
clif->spawn(&nd->bl);
- strdb_put(npcname_db, nd->exname, nd);
+ strdb_put(npc->name_db, nd->exname, nd);
return nd;
}
/// Parses a warp npc.
-static const char* npc_parse_warp(char* w1, char* w2, char* w3, char* w4, const char* start, const char* buffer, const char* filepath)
+const char* npc_parse_warp(char* w1, char* w2, char* w3, char* w4, const char* start, const char* buffer, const char* filepath)
{
int x, y, xs, ys, to_x, to_y, m;
unsigned short i;
@@ -2138,13 +2112,13 @@ static const char* npc_parse_warp(char* w1, char* w2, char* w3, char* w4, const
CREATE(nd, struct npc_data, 1);
- nd->bl.id = npc_get_new_npc_id();
+ nd->bl.id = npc->get_new_npc_id();
iMap->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);
+ npc->parsename(nd, w3, start, buffer, filepath);
if (!battle_config.warp_point_debug)
nd->class_ = WARP_CLASS;
@@ -2160,19 +2134,19 @@ static const char* npc_parse_warp(char* w1, char* w2, char* w3, char* w4, const
npc_warp++;
nd->bl.type = BL_NPC;
nd->subtype = WARP;
- npc_setcells(nd);
+ npc->setcells(nd);
iMap->addblock(&nd->bl);
iStatus->set_viewdata(&nd->bl, nd->class_);
- nd->ud = &npc_base_ud;
+ nd->ud = &npc->base_ud;
if( map[nd->bl.m].users )
clif->spawn(&nd->bl);
- strdb_put(npcname_db, nd->exname, nd);
+ strdb_put(npc->name_db, nd->exname, nd);
return strchr(start,'\n');// continue
}
/// Parses a shop/cashshop npc.
-static const char* npc_parse_shop(char* w1, char* w2, char* w3, char* w4, const char* start, const char* buffer, const char* filepath)
+const char* npc_parse_shop(char* w1, char* w2, char* w3, char* w4, const char* start, const char* buffer, const char* filepath)
{
//TODO: could be rewritten to NOT need this temp array [ultramage]
#define MAX_SHOPITEM 100
@@ -2263,8 +2237,8 @@ static const char* npc_parse_shop(char* w1, char* w2, char* w3, char* w4, const
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->bl.id = npc->get_new_npc_id();
+ npc->parsename(nd, w3, start, buffer, filepath);
nd->class_ = m==-1?-1:atoi(w4);
nd->speed = 200;
@@ -2275,14 +2249,14 @@ static const char* npc_parse_shop(char* w1, char* w2, char* w3, char* w4, const
iMap->addnpc(m,nd);
iMap->addblock(&nd->bl);
iStatus->set_viewdata(&nd->bl, nd->class_);
- nd->ud = &npc_base_ud;
+ nd->ud = &npc->base_ud;
nd->dir = dir;
if( map[nd->bl.m].users )
clif->spawn(&nd->bl);
} else {// 'floating' shop?
iMap->addiddb(&nd->bl);
}
- strdb_put(npcname_db, nd->exname, nd);
+ strdb_put(npc->name_db, nd->exname, nd);
return strchr(start,'\n');// continue
}
@@ -2318,7 +2292,7 @@ void npc_convertlabel_db(struct npc_label_list* label_list, const char *filepath
}
// Skip the contents of a script.
-static const char* npc_skip_script(const char* start, const char* buffer, const char* filepath)
+const char* npc_skip_script(const char* start, const char* buffer, const char* filepath)
{
const char* p;
int curly_count;
@@ -2379,7 +2353,7 @@ static const char* npc_skip_script(const char* start, const char* buffer, const
/// -%TAB%script%TAB%<NPC Name>%TAB%-1,{<code>}
/// <map name>,<x>,<y>,<facing>%TAB%script%TAB%<NPC Name>%TAB%<sprite id>,{<code>}
/// <map name>,<x>,<y>,<facing>%TAB%script%TAB%<NPC Name>%TAB%<sprite id>,<triggerX>,<triggerY>,{<code>}
-static const char* npc_parse_script(char* w1, char* w2, char* w3, char* w4, const char* start, const char* buffer, const char* filepath, bool runOnInit) {
+const char* npc_parse_script(char* w1, char* w2, char* w3, char* w4, const char* start, const char* buffer, const char* filepath, bool runOnInit) {
int x, y, dir = 0, m, xs = 0, ys = 0, class_ = 0; // [Valaris] thanks to fov
char mapname[32];
struct script_code *scriptroot;
@@ -2416,7 +2390,7 @@ static const char* npc_parse_script(char* w1, char* w2, char* w3, char* w4, cons
}
++script_start;
- end = npc_skip_script(script_start, buffer, filepath);
+ end = npc->skip_script(script_start, buffer, filepath);
if( end == NULL )
return NULL;// (simple) parse error, don't continue
@@ -2426,7 +2400,7 @@ static const char* npc_parse_script(char* w1, char* w2, char* w3, char* w4, cons
if( script->label_count ) {
CREATE(label_list,struct npc_label_list,script->label_count);
label_list_num = script->label_count;
- npc_convertlabel_db(label_list,filepath);
+ npc->convertlabel_db(label_list,filepath);
}
CREATE(nd, struct npc_data, 1);
@@ -2447,8 +2421,8 @@ static const char* npc_parse_script(char* w1, char* w2, char* w3, char* w4, cons
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();
+ npc->parsename(nd, w3, start, buffer, filepath);
+ nd->bl.id = npc->get_new_npc_id();
nd->class_ = class_;
nd->speed = 200;
nd->u.scr.script = scriptroot;
@@ -2461,9 +2435,9 @@ static const char* npc_parse_script(char* w1, char* w2, char* w3, char* w4, cons
if( m >= 0 ) {
iMap->addnpc(m, nd);
- nd->ud = &npc_base_ud;
+ nd->ud = &npc->base_ud;
nd->dir = dir;
- npc_setcells(nd);
+ npc->setcells(nd);
iMap->addblock(&nd->bl);
if( class_ >= 0 ) {
iStatus->set_viewdata(&nd->bl, nd->class_);
@@ -2474,16 +2448,16 @@ static const char* npc_parse_script(char* w1, char* w2, char* w3, char* w4, cons
// we skip iMap->addnpc, but still add it to the list of ID's
iMap->addiddb(&nd->bl);
}
- strdb_put(npcname_db, nd->exname, nd);
+ strdb_put(npc->name_db, nd->exname, nd);
//-----------------------------------------
// 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)) {
+ if (npc->event_export(nd, i)) {
ShowWarning("npc_parse_script : duplicate event %s::%s (%s)\n",
nd->exname, nd->u.scr.label_list[i].name, filepath);
}
- npc_timerevent_export(nd, i);
+ npc->timerevent_export(nd, i);
}
nd->u.scr.timerid = INVALID_TIMER;
@@ -2494,7 +2468,7 @@ static const char* npc_parse_script(char* w1, char* w2, char* w3, char* w4, cons
snprintf(evname, ARRAYLENGTH(evname), "%s::OnInit", nd->exname);
- if( ( ev = (struct event_data*)strdb_get(ev_db, evname) ) ) {
+ if( ( ev = (struct event_data*)strdb_get(npc->ev_db, evname) ) ) {
//Execute OnInit
script->run(nd->u.scr.script,ev->pos,0,nd->bl.id);
@@ -2536,7 +2510,7 @@ const char* npc_parse_duplicate(char* w1, char* w2, char* w3, char* w4, const ch
}
safestrncpy(srcname, w2+10, length-10);
- dnd = npc_name2id(srcname);
+ dnd = npc->name2id(srcname);
if( dnd == NULL) {
ShowError("npc_parse_script: original npc not found for duplicate in file '%s', line '%d' : %s\n", filepath, strline(buffer,start-buffer), srcname);
return end;// next line, try to continue
@@ -2576,8 +2550,8 @@ const char* npc_parse_duplicate(char* w1, char* w2, char* w3, char* w4, const ch
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();
+ npc->parsename(nd, w3, start, buffer, filepath);
+ nd->bl.id = npc->get_new_npc_id();
nd->class_ = class_;
nd->speed = 200;
nd->src_id = src_id;
@@ -2617,9 +2591,9 @@ const char* npc_parse_duplicate(char* w1, char* w2, char* w3, char* w4, const ch
//Add the npc to its location
if( m >= 0 ) {
iMap->addnpc(m, nd);
- nd->ud = &npc_base_ud;
+ nd->ud = &npc->base_ud;
nd->dir = dir;
- npc_setcells(nd);
+ npc->setcells(nd);
iMap->addblock(&nd->bl);
if( class_ >= 0 ) {
iStatus->set_viewdata(&nd->bl, nd->class_);
@@ -2630,7 +2604,7 @@ const char* npc_parse_duplicate(char* w1, char* w2, char* w3, char* w4, const ch
// we skip iMap->addnpc, but still add it to the list of ID's
iMap->addiddb(&nd->bl);
}
- strdb_put(npcname_db, nd->exname, nd);
+ strdb_put(npc->name_db, nd->exname, nd);
if( type != SCRIPT )
return end;
@@ -2638,11 +2612,11 @@ const char* npc_parse_duplicate(char* w1, char* w2, char* w3, char* w4, const ch
//-----------------------------------------
// 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)) {
+ if (npc->event_export(nd, i)) {
ShowWarning("npc_parse_duplicate : duplicate event %s::%s (%s)\n",
nd->exname, nd->u.scr.label_list[i].name, filepath);
}
- npc_timerevent_export(nd, i);
+ npc->timerevent_export(nd, i);
}
nd->u.scr.timerid = INVALID_TIMER;
@@ -2657,7 +2631,7 @@ int npc_duplicate4instance(struct npc_data *snd, int16 m) {
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
+ 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;
}
@@ -2673,7 +2647,7 @@ int npc_duplicate4instance(struct npc_data *snd, int16 m) {
}
CREATE(wnd, struct npc_data, 1);
- wnd->bl.id = npc_get_new_npc_id();
+ wnd->bl.id = npc->get_new_npc_id();
iMap->addnpc(m, wnd);
wnd->bl.prev = wnd->bl.next = NULL;
wnd->bl.m = m;
@@ -2690,13 +2664,13 @@ int npc_duplicate4instance(struct npc_data *snd, int16 m) {
wnd->u.warp.ys = snd->u.warp.ys;
wnd->bl.type = BL_NPC;
wnd->subtype = WARP;
- npc_setcells(wnd);
+ npc->setcells(wnd);
iMap->addblock(&wnd->bl);
iStatus->set_viewdata(&wnd->bl, wnd->class_);
- wnd->ud = &npc_base_ud;
+ wnd->ud = &npc->base_ud;
if( map[wnd->bl.m].users )
clif->spawn(&wnd->bl);
- strdb_put(npcname_db, wnd->exname, wnd);
+ strdb_put(npc->name_db, wnd->exname, wnd);
} else {
static char w1[50], w2[50], w3[50], w4[50];
const char* stat_buf = "- call from instancing subsystem -\n";
@@ -2710,7 +2684,7 @@ int npc_duplicate4instance(struct npc_data *snd, int16 m) {
else
snprintf(w4, sizeof(w4), "%d", snd->class_);
- npc_parse_duplicate(w1, w2, w3, w4, stat_buf, stat_buf, "INSTANCING");
+ npc->parse_duplicate(w1, w2, w3, w4, stat_buf, stat_buf, "INSTANCING");
}
return 0;
@@ -2750,7 +2724,7 @@ int npc_unsetcells_sub(struct block_list* bl, va_list ap) {
struct npc_data *nd = (struct npc_data*)bl;
int id = va_arg(ap,int);
if (nd->bl.id == id) return 0;
- npc_setcells(nd);
+ npc->setcells(nd);
return 1;
}
@@ -2782,7 +2756,7 @@ void npc_unsetcells(struct npc_data* nd) {
map[m].setcell(m, j, i, CELL_NPC, false);
//Re-deploy NPC cells for other nearby npcs.
- iMap->foreachinarea( npc_unsetcells_sub, m, x0, y0, x1, y1, BL_NPC, nd->bl.id );
+ iMap->foreachinarea( npc->unsetcells_sub, m, x0, y0, x1, y1, BL_NPC, nd->bl.id );
}
void npc_movenpc(struct npc_data* nd, int16 x, int16 y)
@@ -2833,7 +2807,7 @@ void npc_setclass(struct npc_data* nd, short class_)
// @commands (script based)
int npc_do_atcmd_event(struct map_session_data* sd, const char* command, const char* message, const char* eventname)
{
- struct event_data* ev = (struct event_data*)strdb_get(ev_db, eventname);
+ struct event_data* ev = (struct event_data*)strdb_get(npc->ev_db, eventname);
struct npc_data *nd;
struct script_state *st;
int i = 0, j = 0, k = 0;
@@ -2859,7 +2833,7 @@ int npc_do_atcmd_event(struct map_session_data* sd, const char* command, const c
}
if( ev->nd->option&OPTION_INVISIBLE ) { // Disabled npc, shouldn't trigger event.
- npc_event_dequeue(sd);
+ npc->event_dequeue(sd);
return 2;
}
@@ -2894,7 +2868,7 @@ int npc_do_atcmd_event(struct map_session_data* sd, const char* command, const c
/// Parses a function.
/// function%TAB%script%TAB%<function name>%TAB%{<code>}
-static const char* npc_parse_function(char* w1, char* w2, char* w3, char* w4, const char* start, const char* buffer, const char* filepath)
+const char* npc_parse_function(char* w1, char* w2, char* w3, char* w4, const char* start, const char* buffer, const char* filepath)
{
DBMap* func_db;
DBData old_data;
@@ -2911,7 +2885,7 @@ static const char* npc_parse_function(char* w1, char* w2, char* w3, char* w4, co
}
++script_start;
- end = npc_skip_script(script_start,buffer,filepath);
+ end = npc->skip_script(script_start,buffer,filepath);
if( end == NULL )
return NULL;// (simple) parse error, don't continue
@@ -2950,7 +2924,7 @@ void npc_parse_mob2(struct spawn_data* mobspawn)
}
}
-static const char* npc_parse_mob(char* w1, char* w2, char* w3, char* w4, const char* start, const char* buffer, const char* filepath)
+const char* npc_parse_mob(char* w1, char* w2, char* w3, char* w4, const char* start, const char* buffer, const char* filepath)
{
int num, class_, m,x,y,xs,ys, i,j;
int mob_lv = -1, ai = -1, size = -1;
@@ -3105,11 +3079,11 @@ static const char* npc_parse_mob(char* w1, char* w2, char* w3, char* w4, const c
// (usually shouldn't occur when map server is just starting,
// but not the case when we do @reloadscript
if( map[data->m].users > 0 ) {
- npc_parse_mob2(data);
+ npc->parse_mob2(data);
}
} else {
data->state.dynamic = false;
- npc_parse_mob2(data);
+ npc->parse_mob2(data);
npc_delay_mob += data->num;
}
@@ -3600,7 +3574,7 @@ void npc_parsesrcfile(const char* filepath, bool runOnInit)
ShowError("npc_parsesrcfile: Unknown map '%s' in file '%s', line '%d'. Skipping line...\n", mapname, filepath, strline(buffer,p-buffer));
if( strcasecmp(w2,"script") == 0 && count > 3 )
{
- if((p = npc_skip_script(p,buffer,filepath)) == NULL)
+ if((p = npc->skip_script(p,buffer,filepath)) == NULL)
{
break;
}
@@ -3613,7 +3587,7 @@ void npc_parsesrcfile(const char* filepath, bool runOnInit)
{// "mapname" is not assigned to this server, we must skip the script info...
if( strcasecmp(w2,"script") == 0 && count > 3 )
{
- if((p = npc_skip_script(p,buffer,filepath)) == NULL)
+ if((p = npc->skip_script(p,buffer,filepath)) == NULL)
{
break;
}
@@ -3625,7 +3599,7 @@ void npc_parsesrcfile(const char* filepath, bool runOnInit)
ShowError("npc_parsesrcfile: Unknown coordinates ('%d', '%d') for map '%s' in file '%s', line '%d'. Skipping line...\n", x, y, mapname, filepath, strline(buffer,p-buffer));
if( strcasecmp(w2,"script") == 0 && count > 3 )
{
- if((p = npc_skip_script(p,buffer,filepath)) == NULL)
+ if((p = npc->skip_script(p,buffer,filepath)) == NULL)
{
break;
}
@@ -3637,30 +3611,30 @@ void npc_parsesrcfile(const char* filepath, bool runOnInit)
if( strcasecmp(w2,"warp") == 0 && count > 3 )
{
- p = npc_parse_warp(w1,w2,w3,w4, p, buffer, filepath);
+ p = npc->parse_warp(w1,w2,w3,w4, p, buffer, filepath);
}
else if( (!strcasecmp(w2,"shop") || !strcasecmp(w2,"cashshop")) && count > 3 )
{
- p = npc_parse_shop(w1,w2,w3,w4, p, buffer, filepath);
+ p = npc->parse_shop(w1,w2,w3,w4, p, buffer, filepath);
}
else if( strcasecmp(w2,"script") == 0 && count > 3 )
{
if( strcasecmp(w1,"function") == 0 )
- p = npc_parse_function(w1, w2, w3, w4, p, buffer, filepath);
+ p = npc->parse_function(w1, w2, w3, w4, p, buffer, filepath);
else
- p = npc_parse_script(w1,w2,w3,w4, p, buffer, filepath,runOnInit);
+ p = npc->parse_script(w1,w2,w3,w4, p, buffer, filepath,runOnInit);
}
else if( (i=0, sscanf(w2,"duplicate%n",&i), (i > 0 && w2[i] == '(')) && count > 3 )
{
- p = npc_parse_duplicate(w1,w2,w3,w4, p, buffer, filepath);
+ p = npc->parse_duplicate(w1,w2,w3,w4, p, buffer, filepath);
}
else if( (strcmpi(w2,"monster") == 0 || strcmpi(w2,"boss_monster") == 0) && count > 3 )
{
- p = npc_parse_mob(w1, w2, w3, w4, p, buffer, filepath);
+ p = npc->parse_mob(w1, w2, w3, w4, p, buffer, filepath);
}
else if( strcmpi(w2,"mapflag") == 0 && count >= 3 )
{
- p = npc_parse_mapflag(w1, w2, trim(w3), trim(w4), p, buffer, filepath);
+ p = npc->parse_mapflag(w1, w2, trim(w3), trim(w4), p, buffer, filepath);
}
else
{
@@ -3683,7 +3657,7 @@ int npc_script_event(struct map_session_data* sd, enum npce_event type)
return 0;
}
for (i = 0; i<script_event[type].event_count; i++)
- npc_event_sub(sd,script_event[type].event[i],script_event[type].event_name[i]);
+ npc->event_sub(sd,script_event[type].event[i],script_event[type].event_name[i]);
return i;
}
@@ -3714,7 +3688,7 @@ void npc_read_event_script(void)
safestrncpy(name+2,config[i].event_name,62);
script_event[i].event_count = 0;
- iter = db_iterator(ev_db);
+ iter = db_iterator(npc->ev_db);
for( data = iter->first(iter,&key); iter->exists(iter); data = iter->next(iter,&key) )
{
const char* p = key.str;
@@ -3747,7 +3721,7 @@ void npc_read_event_script(void)
/**
* @see DBApply
*/
-static int npc_path_db_clear_sub(DBKey key, DBData *data, va_list args)
+int npc_path_db_clear_sub(DBKey key, DBData *data, va_list args)
{
struct npc_path_data *npd = DB->data2ptr(data);
if (npd->path)
@@ -3758,7 +3732,7 @@ static int npc_path_db_clear_sub(DBKey key, DBData *data, va_list args)
/**
* @see DBApply
*/
-static int ev_label_db_clear_sub(DBKey key, DBData *data, va_list args)
+int npc_ev_label_db_clear_sub(DBKey key, DBData *data, va_list args)
{
struct linkdb_node **label_linkdb = DB->data2ptr(data);
linkdb_final(label_linkdb); // linked data (struct event_data*) is freed when clearing ev_db
@@ -3776,11 +3750,11 @@ int npc_reload(void) {
/* clear guild flag cache */
guild->flags_clear();
- npc_path_db->clear(npc_path_db, npc_path_db_clear_sub);
+ npc->path_db->clear(npc->path_db, npc->path_db_clear_sub);
- db_clear(npcname_db);
- db_clear(ev_db);
- ev_label_db->clear(ev_label_db, ev_label_db_clear_sub);
+ db_clear(npc->name_db);
+ db_clear(npc->ev_db);
+ npc->ev_label_db->clear(npc->ev_label_db, npc->ev_label_db_clear_sub);
npc_last_npd = NULL;
npc_last_path = NULL;
@@ -3792,8 +3766,8 @@ int npc_reload(void) {
for( bl = (struct block_list*)mapit->first(iter); mapit->exists(iter); bl = (struct block_list*)mapit->next(iter) ) {
switch(bl->type) {
case BL_NPC:
- if( bl->id != fake_nd->bl.id )// don't remove fake_nd
- npc_unload((struct npc_data *)bl, false);
+ if( bl->id != npc->fake_nd->bl.id )// don't remove fake_nd
+ npc->unload((struct npc_data *)bl, false);
break;
case BL_MOB:
unit->free(bl,CLR_OUTSIGHT);
@@ -3831,9 +3805,9 @@ int npc_reload(void) {
//TODO: the following code is copy-pasted from do_init_npc(); clean it up
// Reloading npcs now
- for (nsl = npc_src_files; nsl; nsl = nsl->next) {
+ for (nsl = npc->src_files; nsl; nsl = nsl->next) {
ShowStatus("Loading NPC file: %s"CL_CLL"\r", nsl->name);
- npc_parsesrcfile(nsl->name,false);
+ npc->parsesrcfile(nsl->name,false);
}
ShowInfo ("Done loading '"CL_WHITE"%d"CL_RESET"' NPCs:"CL_CLL"\n"
"\t-'"CL_WHITE"%d"CL_RESET"' Warps\n"
@@ -3852,69 +3826,69 @@ int npc_reload(void) {
iMap->zone_init();
- npc->motd = npc_name2id("HerculesMOTD"); /* [Ind/Hercules] */
+ npc->motd = npc->name2id("HerculesMOTD"); /* [Ind/Hercules] */
//Re-read the NPC Script Events cache.
- npc_read_event_script();
+ npc->read_event_script();
/* refresh guild castle flags on both woe setups */
- npc_event_doall("OnAgitInit");
- npc_event_doall("OnAgitInit2");
+ npc->event_doall("OnAgitInit");
+ npc->event_doall("OnAgitInit2");
//Execute the OnInit event for freshly loaded npcs. [Skotlex]
- ShowStatus("Event '"CL_WHITE"OnInit"CL_RESET"' executed with '"CL_WHITE"%d"CL_RESET"' NPCs.\n",npc_event_doall("OnInit"));
+ ShowStatus("Event '"CL_WHITE"OnInit"CL_RESET"' executed with '"CL_WHITE"%d"CL_RESET"' NPCs.\n",npc->event_doall("OnInit"));
// Execute rest of the startup events if connected to char-server. [Lance]
if(!intif->CheckForCharServer()){
- ShowStatus("Event '"CL_WHITE"OnInterIfInit"CL_RESET"' executed with '"CL_WHITE"%d"CL_RESET"' NPCs.\n", npc_event_doall("OnInterIfInit"));
- ShowStatus("Event '"CL_WHITE"OnInterIfInitOnce"CL_RESET"' executed with '"CL_WHITE"%d"CL_RESET"' NPCs.\n", npc_event_doall("OnInterIfInitOnce"));
+ ShowStatus("Event '"CL_WHITE"OnInterIfInit"CL_RESET"' executed with '"CL_WHITE"%d"CL_RESET"' NPCs.\n", npc->event_doall("OnInterIfInit"));
+ ShowStatus("Event '"CL_WHITE"OnInterIfInitOnce"CL_RESET"' executed with '"CL_WHITE"%d"CL_RESET"' NPCs.\n", npc->event_doall("OnInterIfInitOnce"));
}
return 0;
}
//Unload all npc in the given file
bool npc_unloadfile( const char* path ) {
- DBIterator * iter = db_iterator(npcname_db);
+ DBIterator * iter = db_iterator(npc->name_db);
struct npc_data* nd = NULL;
bool found = false;
for( nd = dbi_first(iter); dbi_exists(iter); nd = dbi_next(iter) ) {
if( nd->path && strcasecmp(nd->path,path) == 0 ) {
found = true;
- npc_unload_duplicates(nd);/* unload any npcs which could duplicate this but be in a different file */
- npc_unload(nd, true);
+ npc->unload_duplicates(nd);/* unload any npcs which could duplicate this but be in a different file */
+ npc->unload(nd, true);
}
}
dbi_destroy(iter);
if( found ) /* refresh event cache */
- npc_read_event_script();
+ npc->read_event_script();
return found;
}
void do_clear_npc(void) {
- db_clear(npcname_db);
- db_clear(ev_db);
- ev_label_db->clear(ev_label_db, ev_label_db_clear_sub);
+ db_clear(npc->name_db);
+ db_clear(npc->ev_db);
+ npc->ev_label_db->clear(npc->ev_label_db, npc->ev_label_db_clear_sub);
}
/*==========================================
* Destructor
*------------------------------------------*/
int do_final_npc(void) {
- db_destroy(ev_db);
- ev_label_db->destroy(ev_label_db, ev_label_db_clear_sub);
- db_destroy(npcname_db);
- npc_path_db->destroy(npc_path_db, npc_path_db_clear_sub);
- ers_destroy(timer_event_ers);
- npc_clearsrcfile();
+ db_destroy(npc->ev_db);
+ npc->ev_label_db->destroy(npc->ev_label_db, npc->ev_label_db_clear_sub);
+ db_destroy(npc->name_db);
+ npc->path_db->destroy(npc->path_db, npc->path_db_clear_sub);
+ ers_destroy(npc->timer_event_ers);
+ npc->clearsrcfile();
return 0;
}
-static void npc_debug_warps_sub(struct npc_data* nd)
+void npc_debug_warps_sub(struct npc_data* nd)
{
int16 m;
if (nd->bl.type != BL_NPC || nd->subtype != WARP || nd->bl.m < 0)
@@ -3945,7 +3919,7 @@ static void npc_debug_warps(void)
int16 m, i;
for (m = 0; m < iMap->map_num; m++)
for (i = 0; i < map[m].npc_num; i++)
- npc_debug_warps_sub(map[m].npc[i]);
+ npc->debug_warps_sub(map[m].npc[i]);
}
/*==========================================
@@ -3956,14 +3930,14 @@ int do_init_npc(void)
struct npc_src_list *file;
int i;
- memset(&npc_base_ud, 0, sizeof( struct unit_data) );
- npc_base_ud.bl = NULL;
- npc_base_ud.walktimer = INVALID_TIMER;
- npc_base_ud.skilltimer = INVALID_TIMER;
- npc_base_ud.attacktimer = INVALID_TIMER;
- npc_base_ud.attackabletime =
- npc_base_ud.canact_tick =
- npc_base_ud.canmove_tick = iTimer->gettick();
+ memset(&npc->base_ud, 0, sizeof( struct unit_data) );
+ npc->base_ud.bl = NULL;
+ npc->base_ud.walktimer = INVALID_TIMER;
+ npc->base_ud.skilltimer = INVALID_TIMER;
+ npc->base_ud.attacktimer = INVALID_TIMER;
+ npc->base_ud.attackabletime =
+ npc->base_ud.canact_tick =
+ npc->base_ud.canmove_tick = iTimer->gettick();
//Stock view data for normal npcs.
memset(&npc_viewdb, 0, sizeof(npc_viewdb));
@@ -3974,12 +3948,12 @@ int do_init_npc(void)
for( i = MAX_NPC_CLASS2_START; i < MAX_NPC_CLASS2_END; i++ )
npc_viewdb2[i - MAX_NPC_CLASS2_START].class_ = i;
- ev_db = stridb_alloc(DB_OPT_DUP_KEY|DB_OPT_RELEASE_DATA, EVENT_NAME_LENGTH);
- ev_label_db = stridb_alloc(DB_OPT_DUP_KEY|DB_OPT_RELEASE_DATA, NAME_LENGTH);
- npcname_db = strdb_alloc(DB_OPT_BASE, NAME_LENGTH);
- npc_path_db = strdb_alloc(DB_OPT_DUP_KEY|DB_OPT_RELEASE_DATA, 0);
+ npc->ev_db = stridb_alloc(DB_OPT_DUP_KEY|DB_OPT_RELEASE_DATA, EVENT_NAME_LENGTH);
+ npc->ev_label_db = stridb_alloc(DB_OPT_DUP_KEY|DB_OPT_RELEASE_DATA, NAME_LENGTH);
+ npc->name_db = strdb_alloc(DB_OPT_BASE, NAME_LENGTH);
+ npc->path_db = strdb_alloc(DB_OPT_DUP_KEY|DB_OPT_RELEASE_DATA, 0);
- timer_event_ers = ers_new(sizeof(struct timer_event_data),"clif.c::timer_event_ers",ERS_OPT_NONE);
+ npc->timer_event_ers = ers_new(sizeof(struct timer_event_data),"clif.c::timer_event_ers",ERS_OPT_NONE);
npc_last_npd = NULL;
npc_last_path = NULL;
@@ -3987,9 +3961,9 @@ int do_init_npc(void)
// process all npc files
ShowStatus("Loading NPCs...\r");
- for( file = npc_src_files; file != NULL; file = file->next ) {
+ for( file = npc->src_files; file != NULL; file = file->next ) {
ShowStatus("Loading NPC file: %s"CL_CLL"\r", file->name);
- npc_parsesrcfile(file->name,false);
+ npc->parsesrcfile(file->name,false);
}
ShowInfo ("Done loading '"CL_WHITE"%d"CL_RESET"' NPCs:"CL_CLL"\n"
"\t-'"CL_WHITE"%d"CL_RESET"' Warps\n"
@@ -4004,35 +3978,35 @@ int do_init_npc(void)
iMap->zone_init();
- npc->motd = npc_name2id("HerculesMOTD"); /* [Ind/Hercules] */
+ npc->motd = npc->name2id("HerculesMOTD"); /* [Ind/Hercules] */
// set up the events cache
memset(script_event, 0, sizeof(script_event));
- npc_read_event_script();
+ npc->read_event_script();
//Debug function to locate all endless loop warps.
if (battle_config.warp_point_debug)
- npc_debug_warps();
+ npc->debug_warps();
- iTimer->add_timer_func_list(npc_event_do_clock,"npc_event_do_clock");
- iTimer->add_timer_func_list(npc_timerevent,"npc_timerevent");
+ iTimer->add_timer_func_list(npc->event_do_clock,"npc_event_do_clock");
+ iTimer->add_timer_func_list(npc->timerevent,"npc_timerevent");
// Init dummy NPC
- fake_nd = (struct npc_data *)aCalloc(1,sizeof(struct npc_data));
- fake_nd->bl.m = -1;
- fake_nd->bl.id = npc_get_new_npc_id();
- fake_nd->class_ = -1;
- fake_nd->speed = 200;
- strcpy(fake_nd->name,"FAKE_NPC");
- memcpy(fake_nd->exname, fake_nd->name, 9);
+ npc->fake_nd = (struct npc_data *)aCalloc(1,sizeof(struct npc_data));
+ npc->fake_nd->bl.m = -1;
+ npc->fake_nd->bl.id = npc->get_new_npc_id();
+ npc->fake_nd->class_ = -1;
+ npc->fake_nd->speed = 200;
+ strcpy(npc->fake_nd->name,"FAKE_NPC");
+ memcpy(npc->fake_nd->exname, npc->fake_nd->name, 9);
npc_script++;
- fake_nd->bl.type = BL_NPC;
- fake_nd->subtype = SCRIPT;
+ npc->fake_nd->bl.type = BL_NPC;
+ npc->fake_nd->subtype = SCRIPT;
- strdb_put(npcname_db, fake_nd->exname, fake_nd);
- fake_nd->u.scr.timerid = INVALID_TIMER;
- iMap->addiddb(&fake_nd->bl);
+ strdb_put(npc->name_db, npc->fake_nd->exname, npc->fake_nd);
+ npc->fake_nd->u.scr.timerid = INVALID_TIMER;
+ iMap->addiddb(&npc->fake_nd->bl);
// End of initialization
return 0;
@@ -4041,4 +4015,101 @@ void npc_defaults(void) {
npc = &npc_s;
npc->motd = NULL;
+ npc->ev_db = NULL;
+ npc->ev_label_db = NULL;
+ npc->name_db = NULL;
+ npc->path_db = NULL;
+ npc->timer_event_ers = NULL;
+ npc->fake_nd = NULL;
+ npc->src_files = NULL;
+ /* */
+ npc->init = do_init_npc;
+ npc->final = do_final_npc;
+ /* */
+ npc->get_new_npc_id = npc_get_new_npc_id;
+ npc->get_viewdata = npc_get_viewdata;
+ npc->isnear_sub = npc_isnear_sub;
+ npc->isnear = npc_isnear;
+ npc->ontouch_event = npc_ontouch_event;
+ npc->ontouch2_event = npc_ontouch2_event;
+ npc->enable_sub = npc_enable_sub;
+ npc->enable = npc_enable;
+ npc->name2id = npc_name2id;
+ npc->event_dequeue = npc_event_dequeue;
+ npc->event_export_create = npc_event_export_create;
+ npc->event_export = npc_event_export;
+ npc->event_sub = npc_event_sub;
+ npc->event_doall_sub = npc_event_doall_sub;
+ npc->event_do = npc_event_do;
+ npc->event_doall_id = npc_event_doall_id;
+ npc->event_doall = npc_event_doall;
+ npc->event_do_clock = npc_event_do_clock;
+ npc->event_do_oninit = npc_event_do_oninit;
+ npc->timerevent_export = npc_timerevent_export;
+ npc->timerevent = npc_timerevent;
+ npc->timerevent_start = npc_timerevent_start;
+ npc->timerevent_stop = npc_timerevent_stop;
+ npc->timerevent_quit = npc_timerevent_quit;
+ npc->gettimerevent_tick = npc_gettimerevent_tick;
+ npc->settimerevent_tick = npc_settimerevent_tick;
+ npc->event = npc_event;
+ npc->touch_areanpc_sub = npc_touch_areanpc_sub;
+ npc->touchnext_areanpc = npc_touchnext_areanpc;
+ npc->touch_areanpc = npc_touch_areanpc;
+ npc->touch_areanpc2 = npc_touch_areanpc2;
+ npc->check_areanpc = npc_check_areanpc;
+ npc->checknear = npc_checknear;
+ npc->globalmessage = npc_globalmessage;
+ npc->run_tomb = run_tomb;
+ npc->click = npc_click;
+ npc->scriptcont = npc_scriptcont;
+ npc->buysellsel = npc_buysellsel;
+ npc->cashshop_buylist = npc_cashshop_buylist;
+ npc->buylist_sub = npc_buylist_sub;
+ npc->cashshop_buy = npc_cashshop_buy;
+ npc->buylist = npc_buylist;
+ npc->selllist_sub = npc_selllist_sub;
+ npc->selllist = npc_selllist;
+ npc->remove_map = npc_remove_map;
+ npc->unload_ev = npc_unload_ev;
+ npc->unload_ev_label = npc_unload_ev_label;
+ npc->unload_dup_sub = npc_unload_dup_sub;
+ npc->unload_duplicates = npc_unload_duplicates;
+ npc->unload = npc_unload;
+ npc->clearsrcfile = npc_clearsrcfile;
+ npc->addsrcfile = npc_addsrcfile;
+ npc->delsrcfile = npc_delsrcfile;
+ npc->parsename = npc_parsename;
+ npc->add_warp = npc_add_warp;
+ npc->parse_warp = npc_parse_warp;
+ npc->parse_shop = npc_parse_shop;
+ npc->convertlabel_db = npc_convertlabel_db;
+ npc->skip_script = npc_skip_script;
+ npc->parse_script = npc_parse_script;
+ npc->parse_duplicate = npc_parse_duplicate;
+ npc->duplicate4instance = npc_duplicate4instance;
+ npc->setcells = npc_setcells;
+ npc->unsetcells_sub = npc_unsetcells_sub;
+ npc->unsetcells = npc_unsetcells;
+ npc->movenpc = npc_movenpc;
+ npc->setdisplayname = npc_setdisplayname;
+ npc->setclass = npc_setclass;
+ npc->do_atcmd_event = npc_do_atcmd_event;
+ npc->parse_function = npc_parse_function;
+ npc->parse_mob2 = npc_parse_mob2;
+ npc->parse_mob = npc_parse_mob;
+ npc->parse_mapflag = npc_parse_mapflag;
+ npc->parsesrcfile = npc_parsesrcfile;
+ npc->script_event = npc_script_event;
+ npc->read_event_script = npc_read_event_script;
+ npc->path_db_clear_sub = npc_path_db_clear_sub;
+ npc->ev_label_db_clear_sub = npc_ev_label_db_clear_sub;
+ npc->reload = npc_reload;
+ npc->unloadfile = npc_unloadfile;
+ npc->do_clear_npc = do_clear_npc;
+ npc->debug_warps_sub = npc_debug_warps_sub;
+ npc->debug_warps = npc_debug_warps;
+#ifdef SECURE_NPCTIMEOUT
+ npc->secure_timeout_timer = npc_rr_secure_timeout_timer;
+#endif
}
diff --git a/src/map/npc.h b/src/map/npc.h
index 48c27b297..0fc773dfc 100644
--- a/src/map/npc.h
+++ b/src/map/npc.h
@@ -12,8 +12,6 @@ struct block_list;
struct npc_data;
struct view_data;
-struct unit_data npc_base_ud;
-
struct npc_timerevent_list {
int timer,pos;
};
@@ -82,8 +80,7 @@ struct npc_data {
#define START_NPC_NUM 110000000
-enum actor_classes
-{
+enum actor_classes {
WARP_CLASS = 45,
HIDDEN_WARP_CLASS = 139,
WARP_DEBUG_CLASS = 722,
@@ -117,86 +114,133 @@ enum npce_event {
NPCE_KILLNPC,
NPCE_MAX
};
-struct view_data* npc_get_viewdata(int class_);
-int npc_chat_sub(struct block_list* bl, va_list ap);
-int npc_event_dequeue(struct map_session_data* sd);
-int npc_event(struct map_session_data* sd, const char* eventname, int ontouch);
-int npc_touch_areanpc(struct map_session_data* sd, int16 m, int16 x, int16 y);
-int npc_touch_areanpc2(struct mob_data *md); // [Skotlex]
-int npc_check_areanpc(int flag, int16 m, int16 x, int16 y, int16 range);
-int npc_touchnext_areanpc(struct map_session_data* sd,bool leavemap);
-int npc_click(struct map_session_data* sd, struct npc_data* nd);
-int npc_scriptcont(struct map_session_data* sd, int id, bool closing);
-struct npc_data* npc_checknear(struct map_session_data* sd, struct block_list* bl);
-int npc_buysellsel(struct map_session_data* sd, int id, int type);
-int npc_buylist(struct map_session_data* sd,int n, unsigned short* item_list);
-int npc_selllist(struct map_session_data* sd, int n, unsigned short* item_list);
-void npc_parse_mob2(struct spawn_data* mob);
-const char* npc_parse_mapflag(char* w1, char* w2, char* w3, char* w4, const char* start, const char* buffer, const char* filepath);
-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 npc_globalmessage(const char* name,const char* mes);
-
-void npc_setcells(struct npc_data* nd);
-void npc_unsetcells(struct npc_data* nd);
-void npc_movenpc(struct npc_data* nd, int16 x, int16 y);
-int npc_enable(const char* name, int flag);
-void npc_setdisplayname(struct npc_data* nd, const char* newname);
-void npc_setclass(struct npc_data* nd, short class_);
-struct npc_data* npc_name2id(const char* name);
-bool npc_isnear(struct block_list * bl);
-
-int npc_get_new_npc_id(void);
-
-void npc_addsrcfile(const char* name);
-void npc_delsrcfile(const char* name);
-void npc_parsesrcfile(const char* filepath, bool runOnInit);
-void do_clear_npc(void);
-int do_final_npc(void);
-int do_init_npc(void);
-void npc_event_do_oninit(void);
-int npc_do_ontimer(int npc_id, int option);
-
-int npc_event_do(const char* name);
-int npc_event_doall(const char* name);
-int npc_event_doall_id(const char* name, int rid);
-
-int npc_timerevent_start(struct npc_data* nd, int rid);
-int npc_timerevent_stop(struct npc_data* nd);
-void npc_timerevent_quit(struct map_session_data* sd);
-int npc_gettimerevent_tick(struct npc_data* nd);
-int npc_settimerevent_tick(struct npc_data* nd, int newtimer);
-int npc_remove_map(struct npc_data* nd);
-void npc_unload_duplicates (struct npc_data* nd);
-int npc_unload(struct npc_data* nd, bool single);
-int npc_reload(void);
-void npc_read_event_script(void);
-int npc_script_event(struct map_session_data* sd, enum npce_event type);
-
-int npc_duplicate4instance(struct npc_data *snd, int16 m);
-int npc_cashshop_buy(struct map_session_data *sd, int nameid, int amount, int points);
-
-extern struct npc_data* fake_nd;
-
-int npc_cashshop_buylist(struct map_session_data *sd, int points, int count, unsigned short* item_list);
-
-/**
- * For the Secure NPC Timeout option (check config/Secure.h) [RR]
- **/
-#ifdef SECURE_NPCTIMEOUT
- int npc_rr_secure_timeout_timer(int tid, unsigned int tick, int id, intptr_t data);
-#endif
-// @commands (script-based)
-int npc_do_atcmd_event(struct map_session_data* sd, const char* command, const char* message, const char* eventname);
+// linked list of npc source files
+struct npc_src_list {
+ struct npc_src_list* next;
+ char name[4]; // dynamic array, the structure is allocated with extra bytes (string length)
+};
+
+struct event_data {
+ struct npc_data *nd;
+ int pos;
+};
+
+struct npc_path_data {
+ char* path;
+ unsigned short references;
+};
+
+/* comes from npc_chat.c */
+int npc_chat_sub (struct block_list* bl, va_list ap);
-bool npc_unloadfile( const char* path );
-/* npc.c interface (barely started/WIP) */
+/* npc.c interface */
struct npc_interface {
/* */
struct npc_data *motd;
+ DBMap *ev_db; // const char* event_name -> struct event_data*
+ DBMap *ev_label_db; // const char* label_name (without leading "::") -> struct linkdb_node** (key: struct npc_data*; data: struct event_data*)
+ DBMap *name_db; // const char* npc_name -> struct npc_data*
+ DBMap *path_db;
+ struct eri *timer_event_ers; //For the npc timer data. [Skotlex]
+ struct npc_data *fake_nd;
+ struct npc_src_list *src_files;
+ struct unit_data base_ud;
+ /* */
+ int (*init) (void);
+ int (*final) (void);
/* */
-} npc_s;
+ int (*get_new_npc_id) (void);
+ struct view_data* (*get_viewdata) (int class_);
+ int (*isnear_sub) (struct block_list *bl, va_list args);
+ bool (*isnear) (struct block_list *bl);
+ int (*ontouch_event) (struct map_session_data *sd, struct npc_data *nd);
+ int (*ontouch2_event) (struct map_session_data *sd, struct npc_data *nd);
+ int (*enable_sub) (struct block_list *bl, va_list ap);
+ int (*enable) (const char *name, int flag);
+ struct npc_data* (*name2id) (const char *name);
+ int (*event_dequeue) (struct map_session_data *sd);
+ DBData (*event_export_create) (DBKey key, va_list args);
+ int (*event_export) (struct npc_data *nd, int i);
+ int (*event_sub) (struct map_session_data *sd, struct event_data *ev, const char *eventname);
+ void (*event_doall_sub) (void *key, void *data, va_list ap);
+ int (*event_do) (const char *name);
+ int (*event_doall_id) (const char *name, int rid);
+ int (*event_doall) (const char *name);
+ int (*event_do_clock) (int tid, unsigned int tick, int id, intptr_t data);
+ void (*event_do_oninit) (void);
+ int (*timerevent_export) (struct npc_data *nd, int i);
+ int (*timerevent) (int tid, unsigned int tick, int id, intptr_t data);
+ int (*timerevent_start) (struct npc_data *nd, int rid);
+ int (*timerevent_stop) (struct npc_data *nd);
+ void (*timerevent_quit) (struct map_session_data *sd);
+ int (*gettimerevent_tick) (struct npc_data *nd);
+ int (*settimerevent_tick) (struct npc_data *nd, int newtimer);
+ int (*event) (struct map_session_data *sd, const char *eventname, int ontouch);
+ int (*touch_areanpc_sub) (struct block_list *bl, va_list ap);
+ int (*touchnext_areanpc) (struct map_session_data *sd, bool leavemap);
+ int (*touch_areanpc) (struct map_session_data *sd, int16 m, int16 x, int16 y);
+ int (*touch_areanpc2) (struct mob_data *md);
+ int (*check_areanpc) (int flag, int16 m, int16 x, int16 y, int16 range);
+ struct npc_data* (*checknear) (struct map_session_data *sd, struct block_list *bl);
+ int (*globalmessage) (const char *name, const char *mes);
+ void (*run_tomb) (struct map_session_data *sd, struct npc_data *nd);
+ int (*click) (struct map_session_data *sd, struct npc_data *nd);
+ int (*scriptcont) (struct map_session_data *sd, int id, bool closing);
+ int (*buysellsel) (struct map_session_data *sd, int id, int type);
+ int (*cashshop_buylist) (struct map_session_data *sd, int points, int count, unsigned short *item_list);
+ int (*buylist_sub) (struct map_session_data *sd, int n, unsigned short *item_list, struct npc_data *nd);
+ int (*cashshop_buy) (struct map_session_data *sd, int nameid, int amount, int points);
+ int (*buylist) (struct map_session_data *sd, int n, unsigned short *item_list);
+ int (*selllist_sub) (struct map_session_data *sd, int n, unsigned short *item_list, struct npc_data *nd);
+ int (*selllist) (struct map_session_data *sd, int n, unsigned short *item_list);
+ int (*remove_map) (struct npc_data *nd);
+ int (*unload_ev) (DBKey key, DBData *data, va_list ap);
+ int (*unload_ev_label) (DBKey key, DBData *data, va_list ap);
+ int (*unload_dup_sub) (struct npc_data *nd, va_list args);
+ void (*unload_duplicates) (struct npc_data *nd);
+ int (*unload) (struct npc_data *nd, bool single);
+ void (*clearsrcfile) (void);
+ void (*addsrcfile) (const char *name);
+ void (*delsrcfile) (const char *name);
+ void (*parsename) (struct npc_data *nd, const char *name, const char *start, const char *buffer, const char *filepath);
+ 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);
+ const char* (*parse_shop) (char *w1, char *w2, char *w3, char *w4, const char *start, const char *buffer, const char *filepath);
+ void (*convertlabel_db) (struct npc_label_list *label_list, const char *filepath);
+ const char* (*skip_script) (const char *start, const char *buffer, const char *filepath);
+ const char* (*parse_script) (char *w1, char *w2, char *w3, char *w4, const char *start, const char *buffer, const char *filepath, bool runOnInit);
+ const char* (*parse_duplicate) (char *w1, char *w2, char *w3, char *w4, const char *start, const char *buffer, const char *filepath);
+ int (*duplicate4instance) (struct npc_data *snd, int16 m);
+ void (*setcells) (struct npc_data *nd);
+ int (*unsetcells_sub) (struct block_list *bl, va_list ap);
+ void (*unsetcells) (struct npc_data *nd);
+ void (*movenpc) (struct npc_data *nd, int16 x, int16 y);
+ void (*setdisplayname) (struct npc_data *nd, const char *newname);
+ void (*setclass) (struct npc_data *nd, short class_);
+ int (*do_atcmd_event) (struct map_session_data *sd, const char *command, const char *message, const char *eventname);
+ const char* (*parse_function) (char *w1, char *w2, char *w3, char *w4, const char *start, const char *buffer, const char *filepath);
+ void (*parse_mob2) (struct spawn_data *mob);
+ const char* (*parse_mob) (char *w1, char *w2, char *w3, char *w4, const char *start, const char *buffer, const char *filepath);
+ const char* (*parse_mapflag) (char *w1, char *w2, char *w3, char *w4, const char *start, const char *buffer, const char *filepath);
+ void (*parsesrcfile) (const char *filepath, bool runOnInit);
+ int (*script_event) (struct map_session_data *sd, enum npce_event type);
+ void (*read_event_script) (void);
+ int (*path_db_clear_sub) (DBKey key, DBData *data, va_list args);
+ int (*ev_label_db_clear_sub) (DBKey key, DBData *data, va_list args);
+ int (*reload) (void);
+ bool (*unloadfile) (const char *path);
+ void (*do_clear_npc) (void);
+ void (*debug_warps_sub) (struct npc_data *nd);
+ void (*debug_warps) (void);
+ /**
+ * For the Secure NPC Timeout option (check config/Secure.h) [RR]
+ **/
+#ifdef SECURE_NPCTIMEOUT
+ int (*secure_timeout_timer) (int tid, unsigned int tick, int id, intptr_t data);
+#endif
+};
struct npc_interface *npc;
diff --git a/src/map/pc.c b/src/map/pc.c
index d502d9a3a..b591cd483 100644
--- a/src/map/pc.c
+++ b/src/map/pc.c
@@ -1334,7 +1334,7 @@ int pc_reg_received(struct map_session_data *sd)
}
if( npc->motd ) /* [Ind/Hercules] */
- script->run(npc->motd->u.scr.script, 0, sd->bl.id, fake_nd->bl.id);
+ script->run(npc->motd->u.scr.script, 0, sd->bl.id, npc->fake_nd->bl.id);
return 1;
}
@@ -4476,7 +4476,7 @@ int pc_useitem(struct map_session_data *sd,int n) {
script->current_item_id = nameid;
- script->run(item_script,0,sd->bl.id,fake_nd->bl.id);
+ script->run(item_script,0,sd->bl.id,npc->fake_nd->bl.id);
script->current_item_id = 0;
script->potion_flag = 0;
@@ -4874,7 +4874,7 @@ int pc_setpos(struct map_session_data* sd, unsigned short mapindex, int x, int y
struct hQueue *queue;
if( (queue = script->queue(sd->queues[i])) && queue->onMapChange[0] != '\0' ) {
pc->setregstr(sd, script->add_str("QMapChangeTo"), map[m].name);
- npc_event(sd, queue->onMapChange, 0);
+ npc->event(sd, queue->onMapChange, 0);
}
}
@@ -4930,8 +4930,8 @@ int pc_setpos(struct map_session_data* sd, unsigned short mapindex, int x, int y
return 2;
if (sd->npc_id)
- npc_event_dequeue(sd);
- npc_script_event(sd, NPCE_LOGOUT);
+ npc->event_dequeue(sd);
+ npc->script_event(sd, NPCE_LOGOUT);
//remove from map, THEN change x/y coordinates
unit->remove_map_pc(sd,clrtype);
sd->mapindex = mapindex;
@@ -5813,7 +5813,7 @@ int pc_checkbaselevelup(struct map_session_data *sd) {
sc_start(&sd->bl,iStatus->skill2sc(AL_BLESSING),100,10,600000);
}
clif->misceffect(&sd->bl,0);
- npc_script_event(sd, NPCE_BASELVUP); //LORDALFA - LVLUPEVENT
+ npc->script_event(sd, NPCE_BASELVUP); //LORDALFA - LVLUPEVENT
if(sd->status.party_id)
party->send_levelup(sd);
@@ -5862,7 +5862,7 @@ int pc_checkjoblevelup(struct map_session_data *sd)
if (pc->checkskill(sd, SG_DEVIL) && !pc->nextjobexp(sd))
clif->status_change(&sd->bl,SI_DEVIL1, 1, 0, 0, 0, 1); //Permanent blind effect from SG_DEVIL.
- npc_script_event(sd, NPCE_JOBLVUP);
+ npc->script_event(sd, NPCE_JOBLVUP);
return 1;
}
@@ -6755,7 +6755,7 @@ int pc_dead(struct map_session_data *sd,struct block_list *src) {
}
if (sd->npc_id && sd->st && sd->st->state != RUN)
- npc_event_dequeue(sd);
+ npc->event_dequeue(sd);
pc_setglobalreg(sd,"PC_DIE_COUNTER",sd->die_counter+1);
pc->setparam(sd, SP_KILLERRID, src?src->id:0);
@@ -6763,16 +6763,16 @@ int pc_dead(struct map_session_data *sd,struct block_list *src) {
if( sd->bg_id ) {/* TODO: purge when bgqueue is deemed ok */
struct battleground_data *bg;
if( (bg = bg_team_search(sd->bg_id)) != NULL && bg->die_event[0] )
- npc_event(sd, bg->die_event, 0);
+ npc->event(sd, bg->die_event, 0);
}
for( i = 0; i < sd->queues_count; i++ ) {
struct hQueue *queue;
if( (queue = script->queue(sd->queues[i])) && queue->onDeath[0] != '\0' )
- npc_event(sd, queue->onDeath, 0);
+ npc->event(sd, queue->onDeath, 0);
}
- npc_script_event(sd,NPCE_DIE);
+ npc->script_event(sd,NPCE_DIE);
// Clear anything NPC-related when you die and was interacting with one.
if (sd->npc_id || sd->npc_shopid) {
@@ -6850,7 +6850,7 @@ int pc_dead(struct map_session_data *sd,struct block_list *src) {
if (src && src->type == BL_PC) {
struct map_session_data *ssd = (struct map_session_data *)src;
pc->setparam(ssd, SP_KILLEDRID, sd->bl.id);
- npc_script_event(ssd, NPCE_KILLPC);
+ npc->script_event(ssd, NPCE_KILLPC);
if (battle_config.pk_mode&2) {
ssd->status.manner -= 5;
@@ -8331,7 +8331,7 @@ static int pc_eventtimer(int tid, unsigned int tick, int id, intptr_t data)
{
sd->eventtimer[i] = INVALID_TIMER;
sd->eventcount--;
- npc_event(sd,p,0);
+ npc->event(sd,p,0);
}
else
ShowError("pc_eventtimer: no such event timer\n");
@@ -8774,7 +8774,7 @@ int pc_equipitem(struct map_session_data *sd,int n,int req_pos)
//OnEquip script [Skotlex]
if (id) {
if (id->equip_script)
- script->run(id->equip_script,0,sd->bl.id,fake_nd->bl.id);
+ script->run(id->equip_script,0,sd->bl.id,npc->fake_nd->bl.id);
if(itemdb_isspecial(sd->status.inventory[n].card[0]))
; //No cards
else {
@@ -8784,7 +8784,7 @@ int pc_equipitem(struct map_session_data *sd,int n,int req_pos)
continue;
if ( ( data = itemdb->exists(sd->status.inventory[n].card[i]) ) != NULL ) {
if( data->equip_script )
- script->run(data->equip_script,0,sd->bl.id,fake_nd->bl.id);
+ script->run(data->equip_script,0,sd->bl.id,npc->fake_nd->bl.id);
}
}
}
@@ -8941,7 +8941,7 @@ int pc_unequipitem(struct map_session_data *sd,int n,int flag) {
//OnUnEquip script [Skotlex]
if (sd->inventory_data[n]) {
if (sd->inventory_data[n]->unequip_script)
- script->run(sd->inventory_data[n]->unequip_script,0,sd->bl.id,fake_nd->bl.id);
+ script->run(sd->inventory_data[n]->unequip_script,0,sd->bl.id,npc->fake_nd->bl.id);
if(itemdb_isspecial(sd->status.inventory[n].card[0]))
; //No cards
else {
@@ -8952,7 +8952,7 @@ int pc_unequipitem(struct map_session_data *sd,int n,int flag) {
if ( ( data = itemdb->exists(sd->status.inventory[n].card[i]) ) != NULL ) {
if( data->unequip_script )
- script->run(data->unequip_script,0,sd->bl.id,fake_nd->bl.id);
+ script->run(data->unequip_script,0,sd->bl.id,npc->fake_nd->bl.id);
}
}
diff --git a/src/map/pet.c b/src/map/pet.c
index d7f7c29c8..c1bce0b5b 100644
--- a/src/map/pet.c
+++ b/src/map/pet.c
@@ -349,7 +349,7 @@ int pet_data_init(struct map_session_data *sd, struct s_pet *pet)
}
sd->pd = pd = (struct pet_data *)aCalloc(1,sizeof(struct pet_data));
pd->bl.type = BL_PET;
- pd->bl.id = npc_get_new_npc_id();
+ pd->bl.id = npc->get_new_npc_id();
pd->msd = sd;
pd->petDB = &pet_db[i];
diff --git a/src/map/script.c b/src/map/script.c
index 70c9bd9f1..391109fa9 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -3381,11 +3381,11 @@ static void script_detach_state(struct script_state* st, bool dequeue_event)
* We're done with this NPC session, so we cancel the timer (if existent) and move on
**/
if( sd->npc_idle_timer != INVALID_TIMER ) {
- iTimer->delete_timer(sd->npc_idle_timer,npc_rr_secure_timeout_timer);
+ iTimer->delete_timer(sd->npc_idle_timer,npc->secure_timeout_timer);
sd->npc_idle_timer = INVALID_TIMER;
}
#endif
- npc_event_dequeue(sd);
+ npc->event_dequeue(sd);
}
} else if(st->bk_st) { // rid was set to 0, before detaching the script state
ShowError("script_detach_state: Found previous script state without attached player (rid=%d, oid=%d, state=%d, bk_npcid=%d)\n", st->bk_st->rid, st->bk_st->oid, st->bk_st->state, st->bk_npcid);
@@ -3421,7 +3421,7 @@ void script_attach_state(struct script_state* st) {
**/
#ifdef SECURE_NPCTIMEOUT
if( sd->npc_idle_timer == INVALID_TIMER )
- sd->npc_idle_timer = iTimer->add_timer(iTimer->gettick() + (SECURE_NPCTIMEOUT_INTERVAL*1000),npc_rr_secure_timeout_timer,sd->bl.id,0);
+ sd->npc_idle_timer = iTimer->add_timer(iTimer->gettick() + (SECURE_NPCTIMEOUT_INTERVAL*1000),npc->secure_timeout_timer,sd->bl.id,0);
sd->npc_idle_tick = iTimer->gettick();
#endif
}
@@ -6665,7 +6665,7 @@ BUILDIN(getnpcid)
if( script_hasdata(st,3) )
{// unique npc name
- if( ( nd = npc_name2id(script_getstr(st,3)) ) == NULL )
+ if( ( nd = npc->name2id(script_getstr(st,3)) ) == NULL )
{
ShowError("buildin_getnpcid: No such NPC '%s'.\n", script_getstr(st,3));
script_pushint(st,0);
@@ -8781,7 +8781,7 @@ BUILDIN(doevent)
}
check_event(st, event);
- npc_event(sd, event, 0);
+ npc->event(sd, event, 0);
return true;
}
/*==========================================
@@ -8790,7 +8790,7 @@ BUILDIN(donpcevent)
{
const char* event = script_getstr(st,2);
check_event(st, event);
- if( !npc_event_do(event) ) {
+ if( !npc->event_do(event) ) {
struct npc_data * nd = iMap->id2nd(st->oid);
ShowDebug("NPCEvent '%s' not found! (source: %s)\n",event,nd?nd->name:"Unknown");
script_pushint(st, 0);
@@ -8803,12 +8803,12 @@ BUILDIN(donpcevent)
/// basically a specialized 'donpcevent', with the event specified as two arguments instead of one
BUILDIN(cmdothernpc) // Added by RoVeRT
{
- const char* npc = script_getstr(st,2);
+ const char* npc_name = script_getstr(st,2);
const char* command = script_getstr(st,3);
char event[EVENT_NAME_LENGTH];
- snprintf(event, sizeof(event), "%s::OnCommand%s", npc, command);
+ snprintf(event, sizeof(event), "%s::OnCommand%s", npc_name, command);
check_event(st, event);
- npc_event_do(event);
+ npc->event_do(event);
return true;
}
@@ -8872,7 +8872,7 @@ BUILDIN(initnpctimer)
if( script_hasdata(st,3) )
{ //Two arguments: NPC name and attach flag.
- nd = npc_name2id(script_getstr(st, 2));
+ nd = npc->name2id(script_getstr(st, 2));
flag = script_getnum(st,3);
}
else if( script_hasdata(st,2) )
@@ -8881,7 +8881,7 @@ BUILDIN(initnpctimer)
data = script_getdata(st,2);
script->get_val(st,data);
if( data_isstring(data) ) //NPC name
- nd = npc_name2id(script->conv_str(st, data));
+ nd = npc->name2id(script->conv_str(st, data));
else if( data_isint(data) ) //Flag
{
nd = (struct npc_data *)iMap->id2bl(st->oid);
@@ -8907,8 +8907,8 @@ BUILDIN(initnpctimer)
}
nd->u.scr.timertick = 0;
- npc_settimerevent_tick(nd,0);
- npc_timerevent_start(nd, st->rid);
+ npc->settimerevent_tick(nd,0);
+ npc->timerevent_start(nd, st->rid);
return true;
}
/*==========================================
@@ -8920,7 +8920,7 @@ BUILDIN(startnpctimer)
if( script_hasdata(st,3) )
{ //Two arguments: NPC name and attach flag.
- nd = npc_name2id(script_getstr(st, 2));
+ nd = npc->name2id(script_getstr(st, 2));
flag = script_getnum(st,3);
}
else if( script_hasdata(st,2) )
@@ -8929,7 +8929,7 @@ BUILDIN(startnpctimer)
data = script_getdata(st,2);
script->get_val(st,data);
if( data_isstring(data) ) //NPC name
- nd = npc_name2id(script->conv_str(st, data));
+ nd = npc->name2id(script->conv_str(st, data));
else if( data_isint(data) ) //Flag
{
nd = (struct npc_data *)iMap->id2bl(st->oid);
@@ -8954,7 +8954,7 @@ BUILDIN(startnpctimer)
nd->u.scr.rid = sd->bl.id;
}
- npc_timerevent_start(nd, st->rid);
+ npc->timerevent_start(nd, st->rid);
return true;
}
/*==========================================
@@ -8966,7 +8966,7 @@ BUILDIN(stopnpctimer)
if( script_hasdata(st,3) )
{ //Two arguments: NPC name and attach flag.
- nd = npc_name2id(script_getstr(st, 2));
+ nd = npc->name2id(script_getstr(st, 2));
flag = script_getnum(st,3);
}
else if( script_hasdata(st,2) )
@@ -8975,7 +8975,7 @@ BUILDIN(stopnpctimer)
data = script_getdata(st,2);
script->get_val(st,data);
if( data_isstring(data) ) //NPC name
- nd = npc_name2id(script->conv_str(st, data));
+ nd = npc->name2id(script->conv_str(st, data));
else if( data_isint(data) ) //Flag
{
nd = (struct npc_data *)iMap->id2bl(st->oid);
@@ -8995,7 +8995,7 @@ BUILDIN(stopnpctimer)
if( flag ) //Detach
nd->u.scr.rid = 0;
- npc_timerevent_stop(nd);
+ npc->timerevent_stop(nd);
return true;
}
/*==========================================
@@ -9008,7 +9008,7 @@ BUILDIN(getnpctimer)
int val = 0;
if( script_hasdata(st,3) )
- nd = npc_name2id(script_getstr(st,3));
+ nd = npc->name2id(script_getstr(st,3));
else
nd = (struct npc_data *)iMap->id2bl(st->oid);
@@ -9021,7 +9021,7 @@ BUILDIN(getnpctimer)
switch( type )
{
- case 0: val = npc_gettimerevent_tick(nd); break;
+ case 0: val = npc->gettimerevent_tick(nd); break;
case 1:
if( nd->u.scr.rid )
{
@@ -9051,7 +9051,7 @@ BUILDIN(setnpctimer)
tick = script_getnum(st,2);
if( script_hasdata(st,3) )
- nd = npc_name2id(script_getstr(st,3));
+ nd = npc->name2id(script_getstr(st,3));
else
nd = (struct npc_data *)iMap->id2bl(st->oid);
@@ -9062,7 +9062,7 @@ BUILDIN(setnpctimer)
return false;
}
- npc_settimerevent_tick(nd,tick);
+ npc->settimerevent_tick(nd,tick);
script_pushint(st,0);
return true;
}
@@ -9107,7 +9107,7 @@ BUILDIN(detachnpctimer)
struct npc_data *nd;
if( script_hasdata(st,2) )
- nd = npc_name2id(script_getstr(st,2));
+ nd = npc->name2id(script_getstr(st,2));
else
nd = (struct npc_data *)iMap->id2bl(st->oid);
@@ -9466,7 +9466,7 @@ BUILDIN(enablenpc)
{
const char *str;
str=script_getstr(st,2);
- npc_enable(str,1);
+ npc->enable(str,1);
return true;
}
/*==========================================
@@ -9475,7 +9475,7 @@ BUILDIN(disablenpc)
{
const char *str;
str=script_getstr(st,2);
- npc_enable(str,0);
+ npc->enable(str,0);
return true;
}
@@ -9485,7 +9485,7 @@ BUILDIN(hideoffnpc)
{
const char *str;
str=script_getstr(st,2);
- npc_enable(str,2);
+ npc->enable(str,2);
return true;
}
/*==========================================
@@ -9494,7 +9494,7 @@ BUILDIN(hideonnpc)
{
const char *str;
str=script_getstr(st,2);
- npc_enable(str,4);
+ npc->enable(str,4);
return true;
}
@@ -10035,7 +10035,7 @@ BUILDIN(globalmes)
name=nd->name; //use current npc name
}
- npc_globalmessage(name,mes); // broadcast to all players connected
+ npc->globalmessage(name,mes); // broadcast to all players connected
return true;
}
@@ -10074,7 +10074,7 @@ BUILDIN(delwaitingroom)
{
struct npc_data* nd;
if( script_hasdata(st,2) )
- nd = npc_name2id(script_getstr(st, 2));
+ nd = npc->name2id(script_getstr(st, 2));
else
nd = (struct npc_data *)iMap->id2bl(st->oid);
if( nd != NULL )
@@ -10092,7 +10092,7 @@ BUILDIN(waitingroomkickall)
struct chat_data* cd;
if( script_hasdata(st,2) )
- nd = npc_name2id(script_getstr(st,2));
+ nd = npc->name2id(script_getstr(st,2));
else
nd = (struct npc_data *)iMap->id2bl(st->oid);
@@ -10111,7 +10111,7 @@ BUILDIN(enablewaitingroomevent)
struct chat_data* cd;
if( script_hasdata(st,2) )
- nd = npc_name2id(script_getstr(st, 2));
+ nd = npc->name2id(script_getstr(st, 2));
else
nd = (struct npc_data *)iMap->id2bl(st->oid);
@@ -10130,7 +10130,7 @@ BUILDIN(disablewaitingroomevent)
struct chat_data *cd;
if( script_hasdata(st,2) )
- nd = npc_name2id(script_getstr(st, 2));
+ nd = npc->name2id(script_getstr(st, 2));
else
nd = (struct npc_data *)iMap->id2bl(st->oid);
@@ -10161,7 +10161,7 @@ BUILDIN(getwaitingroomstate)
type = script_getnum(st,2);
if( script_hasdata(st,3) )
- nd = npc_name2id(script_getstr(st, 3));
+ nd = npc->name2id(script_getstr(st, 3));
else
nd = (struct npc_data *)iMap->id2bl(st->oid);
@@ -10490,7 +10490,7 @@ BUILDIN(setmapflag)
char empty[1] = "\0";
char params[MAP_ZONE_MAPFLAG_LENGTH];
memcpy(params, val2, MAP_ZONE_MAPFLAG_LENGTH);
- npc_parse_mapflag(map[m].name, empty, zone, params, empty, empty, empty);
+ npc->parse_mapflag(map[m].name, empty, zone, params, empty, empty, empty);
}
break;
case MF_NOCOMMAND: map[m].nocommand = (val <= 0) ? 100 : val; break;
@@ -10746,7 +10746,7 @@ BUILDIN(emotion)
} else
if( script_hasdata(st,4) )
{
- TBL_NPC *nd = npc_name2id(script_getstr(st,4));
+ TBL_NPC *nd = npc->name2id(script_getstr(st,4));
if(nd)
clif->emotion(&nd->bl,type);
}
@@ -11879,7 +11879,7 @@ BUILDIN(misceffect)
int type;
type=script_getnum(st,2);
- if(st->oid && st->oid != fake_nd->bl.id) {
+ if(st->oid && st->oid != npc->fake_nd->bl.id) {
struct block_list *bl = iMap->id2bl(st->oid);
if (bl)
clif->specialeffect(bl,type,AREA);
@@ -12261,7 +12261,7 @@ BUILDIN(specialeffect)
if( script_hasdata(st,4) )
{
- TBL_NPC *nd = npc_name2id(script_getstr(st,4));
+ TBL_NPC *nd = npc->name2id(script_getstr(st,4));
if(nd)
clif->specialeffect(&nd->bl, type, target);
}
@@ -12570,19 +12570,19 @@ BUILDIN(jump_zero)
*------------------------------------------*/
BUILDIN(movenpc) {
TBL_NPC *nd = NULL;
- const char *npc;
+ const char *npc_name;
int x,y;
- npc = script_getstr(st,2);
+ npc_name = script_getstr(st,2);
x = script_getnum(st,3);
y = script_getnum(st,4);
- if ((nd = npc_name2id(npc)) == NULL)
+ if ((nd = npc->name2id(npc_name)) == NULL)
return -1;
if (script_hasdata(st,5))
nd->dir = script_getnum(st,5) % 8;
- npc_movenpc(nd, x, y);
+ npc->movenpc(nd, x, y);
return true;
}
@@ -12797,7 +12797,7 @@ BUILDIN(getmapxy)
if( script_hasdata(st,6) )
{
struct npc_data *nd;
- nd=npc_name2id(script_getstr(st,6));
+ nd=npc->name2id(script_getstr(st,6));
if (nd)
bl = &nd->bl;
} else //In case the origin is not an npc?
@@ -14083,7 +14083,7 @@ BUILDIN(setnpcdisplay)
return false;
}
- nd = npc_name2id(name);
+ nd = npc->name2id(name);
if( nd == NULL )
{// not found
script_pushint(st,1);
@@ -14092,7 +14092,7 @@ BUILDIN(setnpcdisplay)
// update npc
if( newname )
- npc_setdisplayname(nd, newname);
+ npc->setdisplayname(nd, newname);
if( size != -1 && size != (int)nd->size )
nd->size = size;
@@ -14100,7 +14100,7 @@ BUILDIN(setnpcdisplay)
size = -1;
if( class_ != -1 && nd->class_ != class_ )
- npc_setclass(nd, class_);
+ npc->setclass(nd, class_);
else if( size != -1 )
{ // Required to update the visual size
clif->clearunit_area(&nd->bl, CLR_OUTSIGHT);
@@ -14384,7 +14384,7 @@ BUILDIN(callshop)
shopname = script_getstr(st, 2);
if( script_hasdata(st,3) )
flag = script_getnum(st,3);
- nd = npc_name2id(shopname);
+ nd = npc->name2id(shopname);
if( !nd || nd->bl.type != BL_NPC || (nd->subtype != SHOP && nd->subtype != CASHSHOP) )
{
ShowError("buildin_callshop: Shop [%s] not found (or NPC is not shop type)\n", shopname);
@@ -14399,8 +14399,8 @@ BUILDIN(callshop)
switch( flag )
{
- case 1: npc_buysellsel(sd,nd->bl.id,0); break; //Buy window
- case 2: npc_buysellsel(sd,nd->bl.id,1); break; //Sell window
+ case 1: npc->buysellsel(sd,nd->bl.id,0); break; //Buy window
+ case 2: npc->buysellsel(sd,nd->bl.id,1); break; //Sell window
default: clif->npcbuysell(sd,nd->bl.id); break; //Show menu
}
}
@@ -14415,7 +14415,7 @@ BUILDIN(callshop)
BUILDIN(npcshopitem)
{
const char* npcname = script_getstr(st, 2);
- struct npc_data* nd = npc_name2id(npcname);
+ struct npc_data* nd = npc->name2id(npcname);
int n, i;
int amount;
@@ -14444,7 +14444,7 @@ BUILDIN(npcshopitem)
BUILDIN(npcshopadditem)
{
const char* npcname = script_getstr(st,2);
- struct npc_data* nd = npc_name2id(npcname);
+ struct npc_data* nd = npc->name2id(npcname);
int n, i;
int amount;
@@ -14473,7 +14473,7 @@ BUILDIN(npcshopadditem)
BUILDIN(npcshopdelitem)
{
const char* npcname = script_getstr(st,2);
- struct npc_data* nd = npc_name2id(npcname);
+ struct npc_data* nd = npc->name2id(npcname);
unsigned int nameid;
int n, i;
int amount;
@@ -14512,7 +14512,7 @@ BUILDIN(npcshopdelitem)
BUILDIN(npcshopattach)
{
const char* npcname = script_getstr(st,2);
- struct npc_data* nd = npc_name2id(npcname);
+ struct npc_data* nd = npc->name2id(npcname);
int flag = 1;
if( script_hasdata(st,3) )
@@ -15246,7 +15246,7 @@ BUILDIN(awake) {
struct script_state *tst;
struct npc_data* nd;
- if( ( nd = npc_name2id(script_getstr(st, 2)) ) == NULL ) {
+ if( ( nd = npc->name2id(script_getstr(st, 2)) ) == NULL ) {
ShowError("awake: NPC \"%s\" not found\n", script_getstr(st, 2));
return false;
}
@@ -15309,7 +15309,7 @@ BUILDIN(getvariableofnpc)
return false;
}
- nd = npc_name2id(script_getstr(st,3));
+ nd = npc->name2id(script_getstr(st,3));
if( nd == NULL || nd->subtype != SCRIPT || nd->u.scr.script == NULL )
{// NPC not found or has no script
ShowError("script:getvariableofnpc: can't find npc %s\n", script_getstr(st,3));
@@ -15721,7 +15721,7 @@ BUILDIN(waitingroom2bg)
struct map_session_data *sd;
if( script_hasdata(st,7) )
- nd = npc_name2id(script_getstr(st,7));
+ nd = npc->name2id(script_getstr(st,7));
else
nd = (struct npc_data *)iMap->id2bl(st->oid);
@@ -15782,7 +15782,7 @@ BUILDIN(waitingroom2bg_single)
x = script_getnum(st,4);
y = script_getnum(st,5);
- nd = npc_name2id(script_getstr(st,6));
+ nd = npc->name2id(script_getstr(st,6));
if( nd == NULL || (cd = (struct chat_data *)iMap->id2bl(nd->chat_id)) == NULL || cd->users <= 0 )
return true;
@@ -16155,7 +16155,7 @@ BUILDIN(instance_npcname) {
else if( st->instance_id >= 0 )
instance_id = st->instance_id;
- if( instance_id >= 0 && (nd = npc_name2id(str)) != NULL ) {
+ if( instance_id >= 0 && (nd = npc->name2id(str)) != NULL ) {
static char npcname[NAME_LENGTH];
snprintf(npcname, sizeof(npcname), "dup_%d_%d", instance_id, nd->bl.id);
script_pushconststr(st,npcname);
diff --git a/src/map/skill.c b/src/map/skill.c
index 08da07137..0f448d5cb 100644
--- a/src/map/skill.c
+++ b/src/map/skill.c
@@ -543,7 +543,7 @@ int skillnotok (uint16 skill_id, struct map_session_data *sd)
break;
case MC_VENDING:
case ALL_BUYING_STORE:
- if( npc_isnear(&sd->bl) ) {
+ if( npc->isnear(&sd->bl) ) {
// uncomment for more verbose message.
//char output[150];
//sprintf(output, msg_txt(662), battle_config.min_npc_vendchat_distance);
@@ -9041,7 +9041,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
if( !script )
break;
if( dstsd )
- script->run(scriptroot,0,dstsd->bl.id,fake_nd->bl.id);
+ script->run(scriptroot,0,dstsd->bl.id,npc->fake_nd->bl.id);
else
script->run(scriptroot,0,src->id,0);
}
@@ -12633,7 +12633,7 @@ int skill_check_condition_castbegin(struct map_session_data* sd, uint16 skill_id
break;
case CG_HERMODE:
- if(!npc_check_areanpc(1,sd->bl.m,sd->bl.x,sd->bl.y,skill->get_splash(skill_id, skill_lv)))
+ if(!npc->check_areanpc(1,sd->bl.m,sd->bl.x,sd->bl.y,skill->get_splash(skill_id, skill_lv)))
{
clif->skill_fail(sd,skill_id,USESKILL_FAIL_LEVEL,0);
return 0;
diff --git a/src/map/status.c b/src/map/status.c
index 6efc0b6ca..409d4493d 100644
--- a/src/map/status.c
+++ b/src/map/status.c
@@ -6074,7 +6074,7 @@ void status_set_viewdata(struct block_list *bl, int class_)
if (mob->db_checkid(class_) || mob->is_clone(class_))
vd = mob->get_viewdata(class_);
else if (npcdb_checkid(class_) || (bl->type == BL_NPC && class_ == WARP_CLASS))
- vd = npc_get_viewdata(class_);
+ vd = npc->get_viewdata(class_);
else if (homdb_checkid(class_))
vd = homun->get_viewdata(class_);
else if (mercenary->class(class_))
@@ -9214,7 +9214,7 @@ int status_change_start(struct block_list* bl,enum sc_type type,int rate,int val
}
if( opt_flag&2 && sd && sd->touching_id )
- npc_touchnext_areanpc(sd,false); // run OnTouch_ on next char in range
+ npc->touchnext_areanpc(sd,false); // run OnTouch_ on next char in range
return 1;
}
@@ -9982,7 +9982,7 @@ int status_change_end_(struct block_list* bl, enum sc_type type, int tid, const
skill->unit_move(bl,iTimer->gettick(),1);
if(opt_flag&2 && sd && iMap->getcell(bl->m,bl->x,bl->y,CELL_CHKNPC))
- npc_touch_areanpc(sd,bl->m,bl->x,bl->y); //Trigger on-touch event.
+ npc->touch_areanpc(sd,bl->m,bl->x,bl->y); //Trigger on-touch event.
ers_free(sc_data_ers, sce);
return 1;
diff --git a/src/map/unit.c b/src/map/unit.c
index 65eea39c9..da6f26c9d 100644
--- a/src/map/unit.c
+++ b/src/map/unit.c
@@ -73,7 +73,7 @@ struct unit_data* unit_bl2ud(struct block_list *bl) {
* @return a pointer to the given object's unit_data
*/
struct unit_data* unit_bl2ud2(struct block_list *bl) {
- if( bl && bl->type == BL_NPC && ((struct npc_data*)bl)->ud == &npc_base_ud ) {
+ if( bl && bl->type == BL_NPC && ((struct npc_data*)bl)->ud == &npc->base_ud ) {
struct npc_data *nd = (struct npc_data *)bl;
nd->ud = NULL;
CREATE(nd->ud, struct unit_data, 1);
@@ -200,9 +200,9 @@ int unit_walktoxy_timer(int tid, unsigned int tick, int id, intptr_t data)
if(sd) {
if( sd->touching_id )
- npc_touchnext_areanpc(sd,false);
+ npc->touchnext_areanpc(sd,false);
if(iMap->getcell(bl->m,x,y,CELL_CHKNPC)) {
- npc_touch_areanpc(sd,bl->m,x,y);
+ npc->touch_areanpc(sd,bl->m,x,y);
if (bl->prev == NULL) //Script could have warped char, abort remaining of the function.
return 0;
} else
@@ -228,7 +228,7 @@ int unit_walktoxy_timer(int tid, unsigned int tick, int id, intptr_t data)
}
} else if (md) {
if( iMap->getcell(bl->m,x,y,CELL_CHKNPC) ) {
- if( npc_touch_areanpc2(md) ) return 0; // Warped
+ if( npc->touch_areanpc2(md) ) return 0; // Warped
} else
md->areanpc_id = 0;
if (md->min_chase > md->db->range3) md->min_chase--;
@@ -667,9 +667,9 @@ int unit_movepos(struct block_list *bl, short dst_x, short dst_y, int easy, bool
if(sd) {
if( sd->touching_id )
- npc_touchnext_areanpc(sd,false);
+ npc->touchnext_areanpc(sd,false);
if(iMap->getcell(bl->m,bl->x,bl->y,CELL_CHKNPC)) {
- npc_touch_areanpc(sd,bl->m,bl->x,bl->y);
+ npc->touch_areanpc(sd,bl->m,bl->x,bl->y);
if (bl->prev == NULL) //Script could have warped char, abort remaining of the function.
return 0;
} else
@@ -765,10 +765,10 @@ int unit_blown(struct block_list* bl, int dx, int dy, int count, int flag)
if(sd) {
if(sd->touching_id) {
- npc_touchnext_areanpc(sd, false);
+ npc->touchnext_areanpc(sd, false);
}
if(iMap->getcell(bl->m, bl->x, bl->y, CELL_CHKNPC)) {
- npc_touch_areanpc(sd, bl->m, bl->x, bl->y);
+ npc->touch_areanpc(sd, bl->m, bl->x, bl->y);
} else {
sd->areanpc_id = 0;
}
@@ -1637,7 +1637,7 @@ int unit_attack(struct block_list *src,int target_id,int continuous)
if( src->type == BL_PC ) {
TBL_PC* sd = (TBL_PC*)src;
if( target->type == BL_NPC ) { // monster npcs [Valaris]
- npc_click(sd,(TBL_NPC*)target); // submitted by leinsirk10 [Celest]
+ npc->click(sd,(TBL_NPC*)target); // submitted by leinsirk10 [Celest]
return 0;
}
if( pc_is90overweight(sd) || pc_isridingwug(sd) ) { // overweight or mounted on warg - stop attacking
@@ -2160,7 +2160,7 @@ int unit_remove_map(struct block_list *bl, clr_type clrtype, const char* file, i
if(sd->menuskill_id)
sd->menuskill_id = sd->menuskill_val = 0;
if( sd->touching_id )
- npc_touchnext_areanpc(sd,true);
+ npc->touchnext_areanpc(sd,true);
// Check if warping and not changing the map.
if ( sd->state.warping && !sd->state.changemap ) {