summaryrefslogtreecommitdiff
path: root/src/map
diff options
context:
space:
mode:
Diffstat (limited to 'src/map')
-rw-r--r--src/map/Makefile.in103
-rw-r--r--src/map/atcommand.c208
-rw-r--r--src/map/battle.c58
-rw-r--r--src/map/battleground.c127
-rw-r--r--src/map/battleground.h36
-rw-r--r--src/map/buyingstore.c2
-rw-r--r--src/map/chat.c894
-rw-r--r--src/map/chat.h112
-rw-r--r--src/map/chrif.c4
-rw-r--r--src/map/clif.c194
-rw-r--r--src/map/clif.h2
-rw-r--r--src/map/duel.c408
-rw-r--r--src/map/elemental.c1969
-rw-r--r--src/map/elemental.h206
-rw-r--r--src/map/guild.c22
-rw-r--r--src/map/homunculus.c18
-rw-r--r--src/map/instance.c6
-rw-r--r--src/map/intif.c10
-rw-r--r--src/map/intif.h256
-rw-r--r--src/map/itemdb.c248
-rw-r--r--src/map/itemdb.h82
-rw-r--r--src/map/map.c109
-rw-r--r--src/map/mapreg.h35
-rw-r--r--src/map/mapreg_sql.c163
-rw-r--r--src/map/mercenary.c10
-rw-r--r--src/map/mob.c883
-rw-r--r--src/map/mob.h189
-rw-r--r--src/map/npc.c733
-rw-r--r--src/map/npc.h250
-rw-r--r--src/map/npc_chat.c117
-rw-r--r--src/map/path.c16
-rw-r--r--src/map/path.h43
-rw-r--r--src/map/pc.c82
-rw-r--r--src/map/pc.h4
-rw-r--r--src/map/pet.c396
-rw-r--r--src/map/pet.h89
-rw-r--r--src/map/quest.c78
-rw-r--r--src/map/quest.h37
-rw-r--r--src/map/script.c413
-rw-r--r--src/map/skill.c350
-rw-r--r--src/map/status.c116
-rw-r--r--src/map/storage.c4
-rw-r--r--src/map/trade.c4
-rw-r--r--src/map/unit.c442
-rw-r--r--src/map/unit.h124
45 files changed, 5097 insertions, 4555 deletions
diff --git a/src/map/Makefile.in b/src/map/Makefile.in
index 588d19eae..ed1b9a79d 100644
--- a/src/map/Makefile.in
+++ b/src/map/Makefile.in
@@ -1,43 +1,38 @@
COMMON_H = $(shell ls ../common/*.h)
-
-MT19937AR_OBJ = ../../3rdparty/mt19937ar/mt19937ar.o
-MT19937AR_H = ../../3rdparty/mt19937ar/mt19937ar.h
-MT19937AR_INCLUDE = -I../../3rdparty/mt19937ar
-
-LIBCONFIG_OBJ = ../../3rdparty/libconfig/libconfig.o ../../3rdparty/libconfig/grammar.o \
- ../../3rdparty/libconfig/scanctx.o ../../3rdparty/libconfig/scanner.o ../../3rdparty/libconfig/strbuf.o
-LIBCONFIG_H = ../../3rdparty/libconfig/libconfig.h ../../3rdparty/libconfig/grammar.h \
- ../../3rdparty/libconfig/parsectx.h ../../3rdparty/libconfig/scanctx.h ../../3rdparty/libconfig/scanner.h \
- ../../3rdparty/libconfig/strbuf.h ../../3rdparty/libconfig/wincompat.h
-LIBCONFIG_INCLUDE = -I../../3rdparty/libconfig
-
-MAP_OBJ = map.o chrif.o clif.o pc.o status.o npc.o \
- npc_chat.o chat.o path.o itemdb.o mob.o script.o \
- storage.o skill.o atcommand.o battle.o battleground.o \
- intif.o trade.o party.o vending.o guild.o pet.o \
- log.o mail.o date.o unit.o homunculus.o mercenary.o quest.o instance.o \
- buyingstore.o searchstore.o duel.o pc_groups.o elemental.o irc-bot.o HPMmap.o
-MAP_SQL_OBJ = $(MAP_OBJ:%=obj_sql/%) \
- obj_sql/mapreg_sql.o
-MAP_H = map.h chrif.h clif.h pc.h status.h npc.h \
- chat.h itemdb.h mob.h script.h path.h \
- storage.h skill.h atcommand.h battle.h battleground.h \
- intif.h trade.h party.h vending.h guild.h pet.h \
- log.h mail.h date.h unit.h homunculus.h mercenary.h quest.h instance.h mapreg.h \
- buyingstore.h searchstore.h duel.h pc_groups.h \
- ../config/core.h ../config/renewal.h ../config/secure.h ../config/const.h \
- ../config/classes/general.h elemental.h packets.h packets_struct.h irc-bot.h HPMmap.h
+CONFIG_H = $(shell ls ../config/*.h ../config/*/*.h)
+
+MT19937AR_D = ../../3rdparty/mt19937ar
+MT19937AR_OBJ = $(MT19937AR_D)/mt19937ar.o
+MT19937AR_H = $(MT19937AR_D)/mt19937ar.h
+MT19937AR_INCLUDE = -I$(MT19937AR_D)
+
+LIBCONFIG_D = ../../3rdparty/libconfig
+LIBCONFIG_OBJ = $(addprefix $(LIBCONFIG_D)/, libconfig.o grammar.o scanctx.o \
+ scanner.o strbuf.o)
+LIBCONFIG_H = $(addprefix $(LIBCONFIG_D)/, libconfig.h grammar.h parsectx.h \
+ scanctx.h scanner.h strbuf.h wincompat.h)
+LIBCONFIG_INCLUDE = -I$(LIBCONFIG_D)
+
+MAP_OBJ = $(addprefix obj_sql/, atcommand.o battle.o battleground.o \
+ buyingstore.o chat.o chrif.o clif.o date.o duel.o elemental.o \
+ guild.o homunculus.o HPMmap.o instance.o intif.o irc-bot.o itemdb.o \
+ log.o mail.o map.o mapreg_sql.o mercenary.o mob.o npc.o npc_chat.o \
+ party.o path.o pc.o pc_groups.o pet.o quest.o script.o \
+ searchstore.o skill.o status.o storage.o trade.o unit.o vending.o)
+MAP_H = atcommand.h battle.h battleground.h buyingstore.h chat.h chrif.h \
+ clif.h date.h duel.h elemental.h guild.h homunculus.h HPMmap.h \
+ instance.h intif.h irc-bot.h itemdb.h log.h mail.h map.h mapreg.h \
+ mercenary.h mob.h npc.h packets.h packets_struct.h party.h path.h \
+ pc.h pc_groups.h pet.h quest.h script.h searchstore.h skill.h \
+ status.h storage.h trade.h unit.h vending.h
HAVE_MYSQL=@HAVE_MYSQL@
ifeq ($(HAVE_MYSQL),yes)
- ALL_DEPENDS=txt sql
- SQL_DEPENDS=map-server
+ MAP_SERVER_SQL_DEPENDS=$(MAP_OBJ) ../common/obj_sql/common_sql.a ../common/obj_all/common.a $(MT19937AR_OBJ) $(LIBCONFIG_OBJ)
else
- ALL_TARGET=txt
- SQL_DEPENDS=needs_mysql
+ MAP_SERVER_SQL_DEPENDS=needs_mysql
endif
-TXT_DEPENDS=map-server
HAVE_PCRE=@HAVE_PCRE@
ifeq ($(HAVE_PCRE),yes)
@@ -52,29 +47,22 @@ CC = @CC@
export CC
#####################################################################
-.PHONY : all txt sql clean help
-
-all: $(ALL_DEPENDS)
+.PHONY: all sql map-server clean help
-txt: $(TXT_DEPENDS)
+all: sql
-sql: $(SQL_DEPENDS)
+sql: map-server
clean:
@echo " CLEAN map"
- @rm -rf *.o obj_txt obj_sql ../../map-server@EXEEXT@
+ @rm -rf *.o obj_sql ../../map-server@EXEEXT@
help:
-ifeq ($(HAVE_MYSQL),yes)
- @echo "possible targets are 'sql' 'txt' 'all' 'clean' 'help'"
- @echo "'sql' - map server (SQL version)"
-else
- @echo "possible targets are 'txt' 'all' 'clean' 'help'"
-endif
- @echo "'txt' - map server (TXT version)"
- @echo "'all' - builds all above targets"
- @echo "'clean' - cleans builds and objects"
- @echo "'help' - outputs this message"
+ @echo "possible targets are 'map-server' 'all' 'clean' 'help'"
+ @echo "'map-server' - map server"
+ @echo "'all' - builds all above targets"
+ @echo "'clean' - cleans builds and objects"
+ @echo "'help' - outputs this message"
#####################################################################
@@ -83,9 +71,6 @@ needs_mysql:
@exit 1
# object directories
-obj_txt:
- @echo " MKDIR obj_txt"
- @-mkdir obj_txt
obj_sql:
@echo " MKDIR obj_sql"
@@ -93,25 +78,29 @@ obj_sql:
# executables
-map-server: obj_sql $(MAP_SQL_OBJ) ../common/obj_sql/common_sql.a ../common/obj_all/common.a
+map-server: $(MAP_SERVER_SQL_DEPENDS)
@echo " LD $@"
- @$(CC) @LDFLAGS@ -o ../../map-server@EXEEXT@ $(MAP_SQL_OBJ) ../common/obj_sql/common_sql.a ../common/obj_all/common.a $(MT19937AR_OBJ) $(LIBCONFIG_OBJ) @LIBS@ @PCRE_LIBS@ @MYSQL_LIBS@
+ @$(CC) @LDFLAGS@ -o ../../map-server@EXEEXT@ $(MAP_OBJ) ../common/obj_sql/common_sql.a ../common/obj_all/common.a $(MT19937AR_OBJ) $(LIBCONFIG_OBJ) @LIBS@ @PCRE_LIBS@ @MYSQL_LIBS@
# map object files
-obj_sql/%.o: %.c $(MAP_H) $(COMMON_H) $(MT19937AR_H) $(LIBCONFIG_H)
+obj_sql/%.o: %.c $(MAP_H) $(COMMON_H) $(CONFIG_H) $(MT19937AR_H) $(LIBCONFIG_H) | obj_sql
@echo " CC $<"
@$(CC) @CFLAGS@ $(MT19937AR_INCLUDE) $(LIBCONFIG_INCLUDE) $(PCRE_CFLAGS) @MYSQL_CFLAGS@ @CPPFLAGS@ -c $(OUTPUT_OPTION) $<
# missing object files
../common/obj_all/common.a:
+ @echo " MAKE $@"
@$(MAKE) -C ../common sql
../common/obj_sql/common_sql.a:
+ @echo " MAKE $@"
@$(MAKE) -C ../common sql
$(MT19937AR_OBJ):
- @$(MAKE) -C ../../3rdparty/mt19937ar
+ @echo " MAKE $@"
+ @$(MAKE) -C $(MT19937AR_D)
$(LIBCONFIG_OBJ):
- @$(MAKE) -C ../../3rdparty/libconfig
+ @echo " MAKE $@"
+ @$(MAKE) -C $(LIBCONFIG_D)
diff --git a/src/map/atcommand.c b/src/map/atcommand.c
index df97740e1..2466c2cca 100644
--- a/src/map/atcommand.c
+++ b/src/map/atcommand.c
@@ -1157,12 +1157,12 @@ ACMD(item)
item_id = item_data->nameid;
get_count = number;
//Check if it's stackable.
- if (!itemdb_isstackable2(item_data))
+ if (!itemdb->isstackable2(item_data))
get_count = 1;
for (i = 0; i < number; i += get_count) {
// if not pet egg
- if (!pet_create_egg(sd, item_id)) {
+ if (!pet->create_egg(sd, item_id)) {
memset(&item_tmp, 0, sizeof(item_tmp));
item_tmp.nameid = item_id;
item_tmp.identify = 1;
@@ -1453,11 +1453,11 @@ ACMD(help) {
// parameter: '0' - everyone, 'id' - only those attacking someone with that id
static int atcommand_stopattack(struct block_list *bl,va_list ap)
{
- struct unit_data *ud = unit_bl2ud(bl);
+ struct unit_data *ud = unit->bl2ud(bl);
int id = va_arg(ap, int);
if (ud && ud->attacktimer != INVALID_TIMER && (!id || id == ud->target))
{
- unit_stop_attack(bl);
+ unit->stop_attack(bl);
return 1;
}
return 0;
@@ -1929,8 +1929,8 @@ ACMD(monster)
return false;
}
- if ((mob_id = mobdb_searchname(monster)) == 0) // check name first (to avoid possible name begining by a number)
- mob_id = mobdb_checkid(atoi(monster));
+ if ((mob_id = mob->db_searchname(monster)) == 0) // check name first (to avoid possible name begining by a number)
+ mob_id = mob->db_checkid(atoi(monster));
if (mob_id == 0) {
clif->message(fd, msg_txt(40)); // Invalid monster ID or name.
@@ -1966,7 +1966,7 @@ ACMD(monster)
range = (int)sqrt((float)number) +2; // calculation of an odd number (+ 4 area around)
for (i = 0; i < number; i++) {
iMap->search_freecell(&sd->bl, 0, &mx, &my, range, range, 0);
- k = mob_once_spawn(sd, sd->bl.m, mx, my, name, mob_id, 1, eventname, size, AI_NONE);
+ k = mob->once_spawn(sd, sd->bl.m, mx, my, name, mob_id, 1, eventname, size, AI_NONE);
count += (k != 0) ? 1 : 0;
}
@@ -2138,7 +2138,7 @@ ACMD(produce)
item_id = item_data->nameid;
- if (itemdb_isequip2(item_data)) {
+ if (itemdb->isequip2(item_data)) {
int flag = 0;
if (attribute < MIN_ATTRIBUTE || attribute > MAX_ATTRIBUTE)
attribute = ATTRIBUTE_NORMAL;
@@ -2553,21 +2553,21 @@ ACMD(makeegg)
if ((item_data = itemdb->search_name(message)) != NULL) // for egg name
id = item_data->nameid;
else
- if ((id = mobdb_searchname(message)) != 0) // for monster name
+ if ((id = mob->db_searchname(message)) != 0) // for monster name
;
else
id = atoi(message);
- pet_id = search_petDB_index(id, PET_CLASS);
+ pet_id = pet->search_petDB_index(id, PET_CLASS);
if (pet_id < 0)
- pet_id = search_petDB_index(id, PET_EGG);
+ pet_id = pet->search_petDB_index(id, PET_EGG);
if (pet_id >= 0) {
- sd->catch_target_class = pet_db[pet_id].class_;
+ sd->catch_target_class = pet->db[pet_id].class_;
intif->create_pet(
sd->status.account_id, sd->status.char_id,
- (short)pet_db[pet_id].class_, (short)mob_db(pet_db[pet_id].class_)->lv,
- (short)pet_db[pet_id].EggID, 0, (short)pet_db[pet_id].intimate,
- 100, 0, 1, pet_db[pet_id].jname);
+ (short)pet->db[pet_id].class_, (short)mob->db(pet->db[pet_id].class_)->lv,
+ (short)pet->db[pet_id].EggID, 0, (short)pet->db[pet_id].intimate,
+ 100, 0, 1, pet->db[pet_id].jname);
} else {
clif->message(fd, msg_txt(180)); // The monster/egg name/id doesn't exist.
return false;
@@ -2623,7 +2623,7 @@ ACMD(petfriendly)
return false;
}
- pet_set_intimate(pd, friendly);
+ pet->set_intimate(pd, friendly);
clif->send_petstatus(sd);
clif->message(fd, msg_txt(182)); // Pet intimacy changed.
return true;
@@ -3595,8 +3595,8 @@ ACMD(reloaditemdb)
*------------------------------------------*/
ACMD(reloadmobdb) {
nullpo_retr(-1, sd);
- mob_reload();
- read_petdb();
+ mob->reload();
+ pet->read_db();
homun->reload();
mercenary->read_db();
mercenary->read_skilldb();
@@ -3689,7 +3689,7 @@ ACMD(reloadbattleconf)
|| prev_config.job_exp_rate != battle_config.job_exp_rate
)
{ // Exp or Drop rates changed.
- mob_reload(); //Needed as well so rate changes take effect.
+ mob->reload(); //Needed as well so rate changes take effect.
chrif->ragsrvinfo(battle_config.base_exp_rate, battle_config.job_exp_rate, battle_config.item_rate_common);
}
clif->message(fd, msg_txt(255));
@@ -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;
}
@@ -4744,12 +4744,12 @@ ACMD(disguise)
if ((id = atoi(message)) > 0)
{ //Acquired an ID
- if (!mobdb_checkid(id) && !npcdb_checkid(id))
+ if (!mob->db_checkid(id) && !npcdb_checkid(id))
id = 0; //Invalid id for either mobs or npcs.
} else { //Acquired a Name
- if ((id = mobdb_searchname(message)) == 0)
+ 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_;
}
@@ -4788,10 +4788,10 @@ ACMD(disguiseall)
return false;
}
- if ((mob_id = mobdb_searchname(message)) == 0) // check name first (to avoid possible name begining by a number)
+ if ((mob_id = mob->db_searchname(message)) == 0) // check name first (to avoid possible name begining by a number)
mob_id = atoi(message);
- if (!mobdb_checkid(mob_id) && !npcdb_checkid(mob_id)) { //if mob or npc...
+ if (!mob->db_checkid(mob_id) && !npcdb_checkid(mob_id)) { //if mob or npc...
clif->message(fd, msg_txt(123)); // Monster/NPC name/id not found.
return false;
}
@@ -4824,11 +4824,11 @@ ACMD(disguiseguild)
}
if( (id = atoi(monster)) > 0 ) {
- if( !mobdb_checkid(id) && !npcdb_checkid(id) )
+ if( !mob->db_checkid(id) && !npcdb_checkid(id) )
id = 0;
} else {
- if( (id = mobdb_searchname(monster)) == 0 ) {
- struct npc_data* nd = npc_name2id(monster);
+ if( (id = mob->db_searchname(monster)) == 0 ) {
+ 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;
@@ -5429,9 +5429,9 @@ ACMD(useskill)
bl = &sd->bl;
if (skill->get_inf(skill_id)&INF_GROUND_SKILL)
- unit_skilluse_pos(bl, pl_sd->bl.x, pl_sd->bl.y, skill_id, skill_lv);
+ unit->skilluse_pos(bl, pl_sd->bl.x, pl_sd->bl.y, skill_id, skill_lv);
else
- unit_skilluse_id(bl, pl_sd->bl.id, skill_id, skill_lv);
+ unit->skilluse_id(bl, pl_sd->bl.id, skill_id, skill_lv);
return true;
}
@@ -6091,14 +6091,14 @@ ACMD(mobsearch)
}
if ((mob_id = atoi(mob_name)) == 0)
- mob_id = mobdb_searchname(mob_name);
- if(mob_id > 0 && mobdb_checkid(mob_id) == 0){
+ mob_id = mob->db_searchname(mob_name);
+ if(mob_id > 0 && mob->db_checkid(mob_id) == 0){
snprintf(atcmd_output, sizeof atcmd_output, msg_txt(1219),mob_name); // Invalid mob ID %s!
clif->message(fd, atcmd_output);
return false;
}
- if(mob_id == atoi(mob_name) && mob_db(mob_id)->jname)
- strcpy(mob_name,mob_db(mob_id)->jname); // --ja--
+ if(mob_id == atoi(mob_name) && mob->db(mob_id)->jname)
+ strcpy(mob_name,mob->db(mob_id)->jname); // --ja--
// strcpy(mob_name,mob_db(mob_id)->name); // --en--
snprintf(atcmd_output, sizeof atcmd_output, msg_txt(1220), mob_name, mapindex_id2name(sd->mapindex)); // Mob Search... %s %s
@@ -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;
}
@@ -6355,23 +6355,23 @@ ACMD(summon)
duration =60;
if ((mob_id = atoi(name)) == 0)
- mob_id = mobdb_searchname(name);
- if(mob_id == 0 || mobdb_checkid(mob_id) == 0)
+ mob_id = mob->db_searchname(name);
+ if(mob_id == 0 || mob->db_checkid(mob_id) == 0)
{
clif->message(fd, msg_txt(40)); // Invalid monster ID or name.
return false;
}
- md = mob_once_spawn_sub(&sd->bl, sd->bl.m, -1, -1, "--ja--", mob_id, "", SZ_SMALL, AI_NONE);
+ md = mob->once_spawn_sub(&sd->bl, sd->bl.m, -1, -1, "--ja--", mob_id, "", SZ_SMALL, AI_NONE);
if(!md)
return false;
md->master_id=sd->bl.id;
md->special_state.ai=1;
- md->deletetimer=iTimer->add_timer(tick+(duration*60000),mob_timer_delete,md->bl.id,0);
+ md->deletetimer=iTimer->add_timer(tick+(duration*60000),mob->timer_delete,md->bl.id,0);
clif->specialeffect(&md->bl,344,AREA);
- mob_spawn(md);
+ mob->spawn(md);
sc_start4(&md->bl, SC_MODECHANGE, 100, 1, 0, MD_AGGRESSIVE, 0, 60000);
clif->skill_poseffect(&sd->bl,AM_CALLHOMUN,1,md->bl.x,md->bl.y,tick);
clif->message(fd, msg_txt(39)); // All monster summoned!
@@ -6643,7 +6643,7 @@ ACMD(mobinfo)
unsigned char melement[10][8] = {"Neutral", "Water", "Earth", "Fire", "Wind", "Poison", "Holy", "Dark", "Ghost", "Undead"};
char atcmd_output2[CHAT_SIZE_MAX];
struct item_data *item_data;
- struct mob_db *mob, *mob_array[MAX_SEARCH];
+ struct mob_db *monster, *mob_array[MAX_SEARCH];
int count;
int i, j, k;
@@ -6656,11 +6656,11 @@ ACMD(mobinfo)
}
// If monster identifier/name argument is a name
- if ((i = mobdb_checkid(atoi(message)))) {
- mob_array[0] = mob_db(i);
+ if ((i = mob->db_checkid(atoi(message)))) {
+ mob_array[0] = mob->db(i);
count = 1;
} else
- count = mobdb_searchname_array(mob_array, MAX_SEARCH, message, 0);
+ count = mob->db_searchname_array(mob_array, MAX_SEARCH, message, 0);
if (!count) {
clif->message(fd, msg_txt(40)); // Invalid monster ID or name.
@@ -6676,37 +6676,37 @@ ACMD(mobinfo)
for (k = 0; k < count; k++) {
unsigned int job_exp, base_exp;
- mob = mob_array[k];
+ monster = mob_array[k];
- job_exp = mob->job_exp;
- base_exp = mob->base_exp;
+ job_exp = monster->job_exp;
+ base_exp = monster->base_exp;
#ifdef RENEWAL_EXP
if( battle_config.atcommand_mobinfo_type ) {
- base_exp = base_exp * pc->level_penalty_mod(mob->lv - sd->status.base_level, mob->status.race, mob->status.mode, 1) / 100;
- job_exp = job_exp * pc->level_penalty_mod(mob->lv - sd->status.base_level, mob->status.race, mob->status.mode, 1) / 100;
+ base_exp = base_exp * pc->level_penalty_mod(monster->lv - sd->status.base_level, monster->status.race, monster->status.mode, 1) / 100;
+ job_exp = job_exp * pc->level_penalty_mod(monster->lv - sd->status.base_level, monster->status.race, monster->status.mode, 1) / 100;
}
#endif
// stats
- if (mob->mexp)
- sprintf(atcmd_output, msg_txt(1240), mob->name, mob->jname, mob->sprite, mob->vd.class_); // MVP Monster: '%s'/'%s'/'%s' (%d)
+ if (monster->mexp)
+ sprintf(atcmd_output, msg_txt(1240), monster->name, monster->jname, monster->sprite, monster->vd.class_); // MVP Monster: '%s'/'%s'/'%s' (%d)
else
- sprintf(atcmd_output, msg_txt(1241), mob->name, mob->jname, mob->sprite, mob->vd.class_); // Monster: '%s'/'%s'/'%s' (%d)
+ sprintf(atcmd_output, msg_txt(1241), monster->name, monster->jname, monster->sprite, monster->vd.class_); // Monster: '%s'/'%s'/'%s' (%d)
clif->message(fd, atcmd_output);
- sprintf(atcmd_output, msg_txt(1242), mob->lv, mob->status.max_hp, base_exp, job_exp,MOB_HIT(mob), MOB_FLEE(mob)); // Lv:%d HP:%d Base EXP:%u Job EXP:%u HIT:%d FLEE:%d
+ sprintf(atcmd_output, msg_txt(1242), monster->lv, monster->status.max_hp, base_exp, job_exp, MOB_HIT(monster), MOB_FLEE(monster)); // Lv:%d HP:%d Base EXP:%u Job EXP:%u HIT:%d FLEE:%d
clif->message(fd, atcmd_output);
sprintf(atcmd_output, msg_txt(1243), // DEF:%d MDEF:%d STR:%d AGI:%d VIT:%d INT:%d DEX:%d LUK:%d
- mob->status.def, mob->status.mdef,mob->status.str, mob->status.agi,
- mob->status.vit, mob->status.int_, mob->status.dex, mob->status.luk);
+ monster->status.def, monster->status.mdef, monster->status.str, monster->status.agi,
+ monster->status.vit, monster->status.int_, monster->status.dex, monster->status.luk);
clif->message(fd, atcmd_output);
sprintf(atcmd_output, msg_txt(1244), // ATK:%d~%d Range:%d~%d~%d Size:%s Race: %s Element: %s (Lv:%d)
- mob->status.rhw.atk, mob->status.rhw.atk2, mob->status.rhw.range,
- mob->range2 , mob->range3, msize[mob->status.size],
- mrace[mob->status.race], melement[mob->status.def_ele], mob->status.ele_lv);
+ monster->status.rhw.atk, monster->status.rhw.atk2, monster->status.rhw.range,
+ monster->range2 , monster->range3, msize[monster->status.size],
+ mrace[monster->status.race], melement[monster->status.def_ele], monster->status.ele_lv);
clif->message(fd, atcmd_output);
// drops
@@ -6716,14 +6716,14 @@ ACMD(mobinfo)
for (i = 0; i < MAX_MOB_DROP; i++) {
int droprate;
- if (mob->dropitem[i].nameid <= 0 || mob->dropitem[i].p < 1 || (item_data = itemdb->exists(mob->dropitem[i].nameid)) == NULL)
+ if (monster->dropitem[i].nameid <= 0 || monster->dropitem[i].p < 1 || (item_data = itemdb->exists(monster->dropitem[i].nameid)) == NULL)
continue;
- droprate = mob->dropitem[i].p;
+ droprate = monster->dropitem[i].p;
#ifdef RENEWAL_DROP
if( battle_config.atcommand_mobinfo_type ) {
- droprate = droprate * pc->level_penalty_mod(mob->lv - sd->status.base_level, mob->status.race, mob->status.mode, 2) / 100;
+ droprate = droprate * pc->level_penalty_mod(monster->lv - sd->status.base_level, monster->status.race, monster->status.mode, 2) / 100;
if (droprate <= 0 && !battle_config.drop_rate0item)
droprate = 1;
@@ -6748,21 +6748,21 @@ ACMD(mobinfo)
else if (j % 3 != 0)
clif->message(fd, atcmd_output);
// mvp
- if (mob->mexp) {
- sprintf(atcmd_output, msg_txt(1247), mob->mexp); // MVP Bonus EXP:%u
+ if (monster->mexp) {
+ sprintf(atcmd_output, msg_txt(1247), monster->mexp); // MVP Bonus EXP:%u
clif->message(fd, atcmd_output);
strcpy(atcmd_output, msg_txt(1248)); // MVP Items:
j = 0;
for (i = 0; i < MAX_MVP_DROP; i++) {
- if (mob->mvpitem[i].nameid <= 0 || (item_data = itemdb->exists(mob->mvpitem[i].nameid)) == NULL)
+ if (monster->mvpitem[i].nameid <= 0 || (item_data = itemdb->exists(monster->mvpitem[i].nameid)) == NULL)
continue;
- if (mob->mvpitem[i].p > 0) {
+ if (monster->mvpitem[i].p > 0) {
j++;
if (j == 1)
- sprintf(atcmd_output2, " %s %02.02f%%", item_data->jname, (float)mob->mvpitem[i].p / 100);
+ sprintf(atcmd_output2, " %s %02.02f%%", item_data->jname, (float)monster->mvpitem[i].p / 100);
else
- sprintf(atcmd_output2, " - %s %02.02f%%", item_data->jname, (float)mob->mvpitem[i].p / 100);
+ sprintf(atcmd_output2, " - %s %02.02f%%", item_data->jname, (float)monster->mvpitem[i].p / 100);
strcat(atcmd_output, atcmd_output2);
}
}
@@ -6792,20 +6792,20 @@ ACMD(showmobs)
return false;
if((mob_id = atoi(mob_name)) == 0)
- mob_id = mobdb_searchname(mob_name);
- if(mob_id > 0 && mobdb_checkid(mob_id) == 0){
+ mob_id = mob->db_searchname(mob_name);
+ if(mob_id > 0 && mob->db_checkid(mob_id) == 0){
snprintf(atcmd_output, sizeof atcmd_output, msg_txt(1250),mob_name); // Invalid mob id %s!
clif->message(fd, atcmd_output);
return true;
}
- if(mob_db(mob_id)->status.mode&MD_BOSS && !pc->has_permission(sd, PC_PERM_SHOW_BOSS)){ // If player group does not have access to boss mobs.
+ if(mob->db(mob_id)->status.mode&MD_BOSS && !pc->has_permission(sd, PC_PERM_SHOW_BOSS)){ // If player group does not have access to boss mobs.
clif->message(fd, msg_txt(1251)); // Can't show boss mobs!
return true;
}
- if(mob_id == atoi(mob_name) && mob_db(mob_id)->jname)
- strcpy(mob_name,mob_db(mob_id)->jname); // --ja--
+ if(mob_id == atoi(mob_name) && mob->db(mob_id)->jname)
+ strcpy(mob_name,mob->db(mob_id)->jname); // --ja--
//strcpy(mob_name,mob_db(mob_id)->name); // --en--
snprintf(atcmd_output, sizeof atcmd_output, msg_txt(1252), // Mob Search... %s %s
@@ -7222,7 +7222,7 @@ ACMD(iteminfo)
item_data = item_array[i];
sprintf(atcmd_output, msg_txt(1277), // Item: '%s'/'%s'[%d] (%d) Type: %s | Extra Effect: %s
item_data->name,item_data->jname,item_data->slot,item_data->nameid,
- itemdb_typename(item_data->type),
+ itemdb->typename(item_data->type),
(item_data->script==NULL)? msg_txt(1278) : msg_txt(1279) // None / With script
);
clif->message(fd, atcmd_output);
@@ -7283,7 +7283,7 @@ ACMD(whodrops)
for (j=0; j < MAX_SEARCH && item_data->mob[j].chance > 0; j++)
{
- sprintf(atcmd_output, "- %s (%02.02f%%)", mob_db(item_data->mob[j].id)->jname, item_data->mob[j].chance/100.);
+ sprintf(atcmd_output, "- %s (%02.02f%%)", mob->db(item_data->mob[j].id)->jname, item_data->mob[j].chance/100.);
clif->message(fd, atcmd_output);
}
}
@@ -7293,7 +7293,7 @@ ACMD(whodrops)
ACMD(whereis)
{
- struct mob_db *mob, *mob_array[MAX_SEARCH];
+ struct mob_db *monster, *mob_array[MAX_SEARCH];
int count;
int i, j, k;
@@ -7303,12 +7303,12 @@ ACMD(whereis)
}
// If monster identifier/name argument is a name
- if ((i = mobdb_checkid(atoi(message))))
+ if ((i = mob->db_checkid(atoi(message))))
{
- mob_array[0] = mob_db(i);
+ mob_array[0] = mob->db(i);
count = 1;
} else
- count = mobdb_searchname_array(mob_array, MAX_SEARCH, message, 0);
+ count = mob->db_searchname_array(mob_array, MAX_SEARCH, message, 0);
if (!count) {
clif->message(fd, msg_txt(40)); // Invalid monster ID or name.
@@ -7321,15 +7321,15 @@ ACMD(whereis)
count = MAX_SEARCH;
}
for (k = 0; k < count; k++) {
- mob = mob_array[k];
- snprintf(atcmd_output, sizeof atcmd_output, msg_txt(1289), mob->jname); // %s spawns in:
+ monster = mob_array[k];
+ snprintf(atcmd_output, sizeof atcmd_output, msg_txt(1289), monster->jname); // %s spawns in:
clif->message(fd, atcmd_output);
- for (i = 0; i < ARRAYLENGTH(mob->spawn) && mob->spawn[i].qty; i++)
+ for (i = 0; i < ARRAYLENGTH(monster->spawn) && monster->spawn[i].qty; i++)
{
- j = iMap->mapindex2mapid(mob->spawn[i].mapindex);
+ j = iMap->mapindex2mapid(monster->spawn[i].mapindex);
if (j < 0) continue;
- snprintf(atcmd_output, sizeof atcmd_output, "%s (%d)", map[j].name, mob->spawn[i].qty);
+ snprintf(atcmd_output, sizeof atcmd_output, "%s (%d)", map[j].name, monster->spawn[i].qty);
clif->message(fd, atcmd_output);
}
if (i == 0)
@@ -7979,7 +7979,7 @@ ACMD(clone)
}
master = sd->bl.id;
if (battle_config.atc_slave_clone_limit
- && mob_countslave(&sd->bl) >= battle_config.atc_slave_clone_limit) {
+ && mob->countslave(&sd->bl) >= battle_config.atc_slave_clone_limit) {
clif->message(fd, msg_txt(127)); // You've reached your slave clones limit.
return true;
}
@@ -7995,7 +7995,7 @@ ACMD(clone)
y = sd->bl.y;
}
- if((x = mob_clone_spawn(pl_sd, sd->bl.m, x, y, "", master, 0, flag?1:0, 0)) > 0) {
+ if((x = mob->clone_spawn(pl_sd, sd->bl.m, x, y, "", master, 0, flag?1:0, 0)) > 0) {
clif->message(fd, msg_txt(128+flag*2)); // Evil Clone spawned. Clone spawned. Slave clone spawned.
return true;
}
@@ -8622,7 +8622,7 @@ ACMD(set) {
data->u.str = pc->readregstr(sd, script->add_str(reg));
break;
case '$':
- data->u.str = mapreg_readregstr(script->add_str(reg));
+ data->u.str = mapreg->readregstr(script->add_str(reg));
break;
case '#':
if( reg[1] == '#' )
@@ -8651,7 +8651,7 @@ ACMD(set) {
data->u.num = pc->readreg(sd, script->add_str(reg));
break;
case '$':
- data->u.num = mapreg_readreg(script->add_str(reg));
+ data->u.num = mapreg->readreg(script->add_str(reg));
break;
case '#':
if( reg[1] == '#' )
@@ -8689,7 +8689,7 @@ ACMD(set) {
return true;
}
ACMD(reloadquestdb) {
- do_reload_quest();
+ quest->reload();
clif->message(fd, msg_txt(1377)); // Quest database has been reloaded.
return true;
}
@@ -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/battle.c b/src/map/battle.c
index f64700f0c..85fa2cb98 100644
--- a/src/map/battle.c
+++ b/src/map/battle.c
@@ -50,7 +50,7 @@ int battle_getcurrentskill(struct block_list *bl) { //Returns the current/last s
return su->group?su->group->skill_id:0;
}
- ud = unit_bl2ud(bl);
+ ud = unit->bl2ud(bl);
return ud?ud->skill_id:0;
}
@@ -74,7 +74,7 @@ int battle_gettargeted_sub(struct block_list *bl, va_list ap) {
if (*c >= 24)
return 0;
- if ( !(ud = unit_bl2ud(bl)) )
+ if ( !(ud = unit->bl2ud(bl)) )
return 0;
if (ud->target == target_id || ud->skilltarget == target_id) {
@@ -1250,7 +1250,7 @@ int64 battle_calc_defense(int attack_type, struct block_list *src, struct block_
if( battle_config.vit_penalty_type && battle_config.vit_penalty_target&target->type ) {
unsigned char target_count; //256 max targets should be a sane max
- target_count = unit_counttargeted(target);
+ target_count = unit->counttargeted(target);
if(target_count >= battle_config.vit_penalty_count) {
if(battle_config.vit_penalty_type == 1) {
if( !tsc || !tsc->data[SC_STEELBODY] )
@@ -2337,7 +2337,7 @@ int battle_calc_skillratio(int attack_type, struct block_list *src, struct block
int hp = status_get_max_hp(src) * (10 + 2 * skill_lv) / 100,
sp = status_get_max_sp(src) * (6 + skill_lv) / 100;
if( sc && sc->data[SC_COMBOATTACK] && sc->data[SC_COMBOATTACK]->val1 == SR_FALLENEMPIRE ) // ATK [((Caster consumed HP + SP) / 2) x Caster Base Level / 100] %
- skillratio += -100 + hp+sp / 2;
+ skillratio += -100 + (hp+sp) / 2;
else
skillratio += -100 + (hp+sp) / 4;
RE_LVL_DMOD(100);
@@ -2553,7 +2553,7 @@ int64 battle_calc_damage(struct block_list *src,struct block_list *bl,struct Dam
if( !damage )
return 0;
- if( battle_config.ksprotection && mob_ksprotected(src, bl) )
+ if( battle_config.ksprotection && mob->ksprotected(src, bl) )
return 0;
if( iMap->getcell(bl->m, bl->x, bl->y, CELL_CHKMAELSTROM) && skill->get_type(skill_id) != BF_MISC
&& skill->get_casttype(skill_id) == CAST_GROUND )
@@ -2664,7 +2664,7 @@ int64 battle_calc_damage(struct block_list *src,struct block_list *bl,struct Dam
delay = 200;
else
delay = 100;
- unit_set_walkdelay(bl, iTimer->gettick(), delay, 1);
+ unit->set_walkdelay(bl, iTimer->gettick(), delay, 1);
if(sc->data[SC_CR_SHRINK] && rnd()%100<5*sce->val1)
skill->blown(bl,src,skill->get_blewcount(CR_SHRINK,1),-1,0);
@@ -2834,14 +2834,14 @@ int64 battle_calc_damage(struct block_list *src,struct block_list *bl,struct Dam
if (src->type == BL_MOB) {
int i;
if (sc->data[SC_MANU_DEF])
- for (i=0;ARRAYLENGTH(mob_manuk)>i;i++)
- if (mob_manuk[i]==((TBL_MOB*)src)->class_) {
+ for (i=0;ARRAYLENGTH(mob->manuk)>i;i++)
+ if (mob->manuk[i]==((TBL_MOB*)src)->class_) {
damage -= damage * sc->data[SC_MANU_DEF]->val1 / 100;
break;
}
if (sc->data[SC_SPL_DEF])
- for (i=0;ARRAYLENGTH(mob_splendide)>i;i++)
- if (mob_splendide[i]==((TBL_MOB*)src)->class_) {
+ for (i=0;ARRAYLENGTH(mob->splendide)>i;i++)
+ if (mob->splendide[i]==((TBL_MOB*)src)->class_) {
damage -= damage * sc->data[SC_SPL_DEF]->val1 / 100;
break;
}
@@ -2931,9 +2931,9 @@ int64 battle_calc_damage(struct block_list *src,struct block_list *bl,struct Dam
int dx[8]={0,-1,-1,-1,0,1,1,1};
int dy[8]={1,1,0,-1,-1,-1,0,1};
uint8 dir = iMap->calc_dir(bl, src->x, src->y);
- if( unit_movepos(bl, src->x-dx[dir], src->y-dy[dir], 1, 1) ) {
+ if( unit->movepos(bl, src->x-dx[dir], src->y-dy[dir], 1, 1) ) {
clif->slide(bl,src->x-dx[dir],src->y-dy[dir]);
- unit_setdir(bl, dir);
+ unit->setdir(bl, dir);
}
d->dmg_lv = ATK_DEF;
status_change_end(bl, SC_LIGHTNINGWALK, INVALID_TIMER);
@@ -2991,16 +2991,16 @@ int64 battle_calc_damage(struct block_list *src,struct block_list *bl,struct Dam
if ( ((sce=sc->data[SC_MANU_ATK]) && (flag&BF_WEAPON)) ||
((sce=sc->data[SC_MANU_MATK]) && (flag&BF_MAGIC))
)
- for (i=0;ARRAYLENGTH(mob_manuk)>i;i++)
- if (((TBL_MOB*)bl)->class_==mob_manuk[i]) {
+ for (i=0;ARRAYLENGTH(mob->manuk)>i;i++)
+ if (((TBL_MOB*)bl)->class_==mob->manuk[i]) {
damage += damage * sce->val1 / 100;
break;
}
if ( ((sce=sc->data[SC_SPL_ATK]) && (flag&BF_WEAPON)) ||
((sce=sc->data[SC_SPL_MATK]) && (flag&BF_MAGIC))
)
- for (i=0;ARRAYLENGTH(mob_splendide)>i;i++)
- if (((TBL_MOB*)bl)->class_==mob_splendide[i]) {
+ for (i=0;ARRAYLENGTH(mob->splendide)>i;i++)
+ if (((TBL_MOB*)bl)->class_==mob->splendide[i]) {
damage += damage * sce->val1 / 100;
break;
}
@@ -3052,9 +3052,9 @@ int64 battle_calc_damage(struct block_list *src,struct block_list *bl,struct Dam
if( bl->type == BL_MOB && !iStatus->isdead(bl) && src != bl) {
if (damage > 0 )
- mobskill_event((TBL_MOB*)bl,src,iTimer->gettick(),flag);
+ mob->skill_event((TBL_MOB*)bl,src,iTimer->gettick(),flag);
if (skill_id)
- mobskill_event((TBL_MOB*)bl,src,iTimer->gettick(),MSC_SKILLUSED|(skill_id<<16));
+ mob->skill_event((TBL_MOB*)bl,src,iTimer->gettick(),MSC_SKILLUSED|(skill_id<<16));
}
if( sd ) {
if( pc_ismadogear(sd) && rnd()%100 < 50 ) {
@@ -3837,7 +3837,7 @@ struct Damage battle_calc_misc_attack(struct block_list *src,struct block_list *
if(battle_config.agi_penalty_type && battle_config.agi_penalty_target&target->type) {
unsigned char attacker_count; //256 max targets should be a sane max
- attacker_count = unit_counttargeted(target);
+ attacker_count = unit->counttargeted(target);
if(attacker_count >= battle_config.agi_penalty_count)
{
if (battle_config.agi_penalty_type == 1)
@@ -4303,7 +4303,7 @@ struct Damage battle_calc_weapon_attack(struct block_list *src,struct block_list
if(battle_config.agi_penalty_type && battle_config.agi_penalty_target&target->type) {
unsigned char attacker_count; //256 max targets should be a sane max
- attacker_count = unit_counttargeted(target);
+ attacker_count = unit->counttargeted(target);
if(attacker_count >= battle_config.agi_penalty_count) {
if (battle_config.agi_penalty_type == 1)
flee = (flee * (100 - (attacker_count - (battle_config.agi_penalty_count - 1))*battle_config.agi_penalty_num))/100;
@@ -5199,7 +5199,7 @@ int64 battle_calc_return_damage(struct block_list* bl, struct block_list *src, i
int ratio = (status_get_hp(src) / 100) * sc->data[SC_CRESCENTELBOW]->val1 * iStatus->get_lv(bl) / 125;
if (ratio > 5000) ratio = 5000; // Maximum of 5000% ATK
rdamage = rdamage * ratio / 100 + (*dmg) * (10 + sc->data[SC_CRESCENTELBOW]->val1 * 20 / 10) / 10;
- skill->blown(bl, src, skill->get_blewcount(SR_CRESCENTELBOW_AUTOSPELL, sc->data[SC_CRESCENTELBOW]->val1), unit_getdir(src), 0);
+ skill->blown(bl, src, skill->get_blewcount(SR_CRESCENTELBOW_AUTOSPELL, sc->data[SC_CRESCENTELBOW]->val1), unit->getdir(src), 0);
clif->skill_damage(bl, src, iTimer->gettick(), status_get_amotion(src), 0, rdamage,
1, SR_CRESCENTELBOW_AUTOSPELL, sc->data[SC_CRESCENTELBOW]->val1, 6); // This is how official does
clif->damage(src, bl, iTimer->gettick(), status_get_amotion(src)+1000, 0, rdamage/10, 1, 0, 0);
@@ -5226,13 +5226,13 @@ int64 battle_calc_return_damage(struct block_list* bl, struct block_list *src, i
}
if( sc->data[SC_DEATHBOUND] && skill_id != WS_CARTTERMINATION && !is_boss(src) ) {
uint8 dir = iMap->calc_dir(bl,src->x,src->y),
- t_dir = unit_getdir(bl);
+ t_dir = unit->getdir(bl);
if( !iMap->check_dir(dir,t_dir) ) {
int64 rd1 = damage * sc->data[SC_DEATHBOUND]->val2 / 100; // Amplify damage.
trdamage += rdamage = rd1 - (*dmg = rd1 * 30 / 100); // not normalized as intended.
clif->skill_damage(src, bl, iTimer->gettick(), status_get_amotion(src), 0, -3000, 1, RK_DEATHBOUND, sc->data[SC_DEATHBOUND]->val1, 6);
- skill->blown(bl, src, skill->get_blewcount(RK_DEATHBOUND, sc->data[SC_DEATHBOUND]->val1), unit_getdir(src), 0);
+ skill->blown(bl, src, skill->get_blewcount(RK_DEATHBOUND, sc->data[SC_DEATHBOUND]->val1), unit->getdir(src), 0);
if( skill_id )
status_change_end(bl, SC_DEATHBOUND, INVALID_TIMER);
*delay = clif->damage(src, src, iTimer->gettick(), status_get_amotion(src), status_get_dmotion(src), rdamage, 1, 4, 0);
@@ -5417,7 +5417,7 @@ enum damage_lv battle_weapon_attack(struct block_list* src, struct block_list* t
if( tsc && tsc->data[SC_AUTOCOUNTER] && iStatus->check_skilluse(target, src, KN_AUTOCOUNTER, 1) )
{
uint8 dir = iMap->calc_dir(target,src->x,src->y);
- int t_dir = unit_getdir(target);
+ int t_dir = unit->getdir(target);
int dist = distance_bl(src, target);
if(dist <= 0 || (!iMap->check_dir(dir,t_dir) && dist <= tstatus->rhw.range+1))
{
@@ -6028,8 +6028,8 @@ int battle_check_target( struct block_list *src, struct block_list *target,int f
int sbg_id = 0, tbg_id = 0;
if( map[m].flag.battleground )
{
- sbg_id = bg_team_get_id(s_bl);
- tbg_id = bg_team_get_id(t_bl);
+ sbg_id = bg->team_get_id(s_bl);
+ tbg_id = bg->team_get_id(t_bl);
}
if( flag&(BCT_PARTY|BCT_ENEMY) )
{
@@ -6091,7 +6091,7 @@ int battle_check_target( struct block_list *src, struct block_list *target,int f
}
/*==========================================
* Check if can attack from this range
- * Basic check then calling path_search for obstacle etc..
+ * Basic check then calling path->search for obstacle etc..
*------------------------------------------*/
bool battle_check_range(struct block_list *src, struct block_list *bl, int range)
{
@@ -6105,7 +6105,7 @@ bool battle_check_range(struct block_list *src, struct block_list *bl, int range
#ifndef CIRCULAR_AREA
if( src->type == BL_PC ) { // Range for players' attacks and skills should always have a circular check. [Angezerus]
int dx = src->x - bl->x, dy = src->y - bl->y;
- if( !check_distance(dx, dy, range) )
+ if( !path->check_distance(dx, dy, range) )
return false;
} else
#endif
@@ -6118,7 +6118,7 @@ bool battle_check_range(struct block_list *src, struct block_list *bl, int range
if( d > AREA_SIZE )
return false; // Avoid targetting objects beyond your range of sight.
- return path_search_long(NULL,src->m,src->x,src->y,bl->x,bl->y,CELL_CHKWALL);
+ return path->search_long(NULL,src->m,src->x,src->y,bl->x,bl->y,CELL_CHKWALL);
}
static const struct _battle_data {
diff --git a/src/map/battleground.c b/src/map/battleground.c
index 3b2e0b1ce..e72683880 100644
--- a/src/map/battleground.c
+++ b/src/map/battleground.c
@@ -26,13 +26,11 @@
#include <string.h>
#include <stdio.h>
-static DBMap* bg_team_db; // int bg_id -> struct battleground_data*
-static unsigned int bg_team_counter = 0; // Next bg_id
struct battleground_interface bg_s;
struct battleground_data* bg_team_search(int bg_id) { // Search a BG Team using bg_id
if( !bg_id ) return NULL;
- return (struct battleground_data *)idb_get(bg_team_db, bg_id);
+ return (struct battleground_data *)idb_get(bg->team_db, bg_id);
}
struct map_session_data* bg_getavailablesd(struct battleground_data *bg) {
@@ -46,28 +44,28 @@ int bg_team_delete(int bg_id)
{ // Deletes BG Team from db
int i;
struct map_session_data *sd;
- struct battleground_data *bg = bg_team_search(bg_id);
+ struct battleground_data *bgd = bg->team_search(bg_id);
if( bg == NULL ) return 0;
for( i = 0; i < MAX_BG_MEMBERS; i++ )
{
- if( (sd = bg->members[i].sd) == NULL )
+ if( (sd = bgd->members[i].sd) == NULL )
continue;
- bg_send_dot_remove(sd);
+ bg->send_dot_remove(sd);
sd->bg_id = 0;
}
- idb_remove(bg_team_db, bg_id);
+ idb_remove(bg->team_db, bg_id);
return 1;
}
int bg_team_warp(int bg_id, unsigned short mapindex, short x, short y)
{ // Warps a Team
int i;
- struct battleground_data *bg = bg_team_search(bg_id);
+ struct battleground_data *bgd = bg->team_search(bg_id);
if( bg == NULL ) return 0;
for( i = 0; i < MAX_BG_MEMBERS; i++ )
- if( bg->members[i].sd != NULL ) pc->setpos(bg->members[i].sd, mapindex, x, y, CLR_TELEPORT);
+ if( bgd->members[i].sd != NULL ) pc->setpos(bgd->members[i].sd, mapindex, x, y, CLR_TELEPORT);
return 1;
}
@@ -81,33 +79,33 @@ int bg_send_dot_remove(struct map_session_data *sd)
int bg_team_join(int bg_id, struct map_session_data *sd)
{ // Player joins team
int i;
- struct battleground_data *bg = bg_team_search(bg_id);
+ struct battleground_data *bgd = bg->team_search(bg_id);
struct map_session_data *pl_sd;
if( bg == NULL || sd == NULL || sd->bg_id ) return 0;
- ARR_FIND(0, MAX_BG_MEMBERS, i, bg->members[i].sd == NULL);
+ ARR_FIND(0, MAX_BG_MEMBERS, i, bgd->members[i].sd == NULL);
if( i == MAX_BG_MEMBERS ) return 0; // No free slots
sd->bg_id = bg_id;
- bg->members[i].sd = sd;
- bg->members[i].x = sd->bl.x;
- bg->members[i].y = sd->bl.y;
+ bgd->members[i].sd = sd;
+ bgd->members[i].x = sd->bl.x;
+ bgd->members[i].y = sd->bl.y;
/* populate 'where i came from' */
if(map[sd->bl.m].flag.nosave || map[sd->bl.m].instance_id >= 0){
struct map_data *m=&map[sd->bl.m];
if(m->save.map)
- memcpy(&bg->members[i].source,&m->save,sizeof(struct point));
+ memcpy(&bgd->members[i].source,&m->save,sizeof(struct point));
else
- memcpy(&bg->members[i].source,&sd->status.save_point,sizeof(struct point));
+ memcpy(&bgd->members[i].source,&sd->status.save_point,sizeof(struct point));
} else
- memcpy(&bg->members[i].source,&sd->status.last_point,sizeof(struct point));
- bg->count++;
+ memcpy(&bgd->members[i].source,&sd->status.last_point,sizeof(struct point));
+ bgd->count++;
guild->send_dot_remove(sd);
for( i = 0; i < MAX_BG_MEMBERS; i++ ) {
- if( (pl_sd = bg->members[i].sd) != NULL && pl_sd != sd )
+ if( (pl_sd = bgd->members[i].sd) != NULL && pl_sd != sd )
clif->hpmeter_single(sd->fd, pl_sd->bl.id, pl_sd->battle_status.hp, pl_sd->battle_status.max_hp);
}
@@ -124,11 +122,11 @@ int bg_team_leave(struct map_session_data *sd, int flag)
if( sd == NULL || !sd->bg_id )
return 0;
- bg_send_dot_remove(sd);
+ bg->send_dot_remove(sd);
bg_id = sd->bg_id;
sd->bg_id = 0;
- if( (bg_data = bg_team_search(bg_id)) == NULL )
+ if( (bg_data = bg->team_search(bg_id)) == NULL )
return 0;
ARR_FIND(0, MAX_BG_MEMBERS, i, bg_data->members[i].sd == sd);
@@ -149,7 +147,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);
@@ -160,34 +158,34 @@ int bg_team_leave(struct map_session_data *sd, int flag)
int bg_member_respawn(struct map_session_data *sd)
{ // Respawn after killed
- struct battleground_data *bg;
- if( sd == NULL || !pc_isdead(sd) || !sd->bg_id || (bg = bg_team_search(sd->bg_id)) == NULL )
+ struct battleground_data *bgd;
+ if( sd == NULL || !pc_isdead(sd) || !sd->bg_id || (bgd = bg->team_search(sd->bg_id)) == NULL )
return 0;
- if( bg->mapindex == 0 )
+ if( bgd->mapindex == 0 )
return 0; // Respawn not handled by Core
- pc->setpos(sd, bg->mapindex, bg->x, bg->y, CLR_OUTSIGHT);
+ pc->setpos(sd, bgd->mapindex, bgd->x, bgd->y, CLR_OUTSIGHT);
iStatus->revive(&sd->bl, 1, 100);
return 1; // Warped
}
int bg_create(unsigned short mapindex, short rx, short ry, const char *ev, const char *dev) {
- struct battleground_data *bg;
- bg_team_counter++;
-
- CREATE(bg, struct battleground_data, 1);
- bg->bg_id = bg_team_counter;
- bg->count = 0;
- bg->mapindex = mapindex;
- bg->x = rx;
- bg->y = ry;
- safestrncpy(bg->logout_event, ev, sizeof(bg->logout_event));
- safestrncpy(bg->die_event, dev, sizeof(bg->die_event));
-
- memset(&bg->members, 0, sizeof(bg->members));
- idb_put(bg_team_db, bg_team_counter, bg);
-
- return bg->bg_id;
+ struct battleground_data *bgd;
+ bg->team_counter++;
+
+ CREATE(bgd, struct battleground_data, 1);
+ bgd->bg_id = bg->team_counter;
+ bgd->count = 0;
+ bgd->mapindex = mapindex;
+ bgd->x = rx;
+ bgd->y = ry;
+ safestrncpy(bgd->logout_event, ev, sizeof(bgd->logout_event));
+ safestrncpy(bgd->die_event, dev, sizeof(bgd->die_event));
+
+ memset(&bgd->members, 0, sizeof(bgd->members));
+ idb_put(bg->team_db, bg->team_counter, bg);
+
+ return bgd->bg_id;
}
int bg_team_get_id(struct block_list *bl)
@@ -226,12 +224,12 @@ int bg_team_get_id(struct block_list *bl)
int bg_send_message(struct map_session_data *sd, const char *mes, int len)
{
- struct battleground_data *bg;
+ struct battleground_data *bgd;
nullpo_ret(sd);
- if( sd->bg_id == 0 || (bg = bg_team_search(sd->bg_id)) == NULL )
+ if( sd->bg_id == 0 || (bgd = bg->team_search(sd->bg_id)) == NULL )
return 0;
- clif->bg_message(bg, sd->bl.id, sd->status.name, mes, len);
+ clif->bg_message(bgd, sd->bl.id, sd->status.name, mes, len);
return 0;
}
@@ -257,7 +255,7 @@ int bg_send_xy_timer_sub(DBKey key, DBData *data, va_list ap)
}
int bg_send_xy_timer(int tid, unsigned int tick, int id, intptr_t data) {
- bg_team_db->foreach(bg_team_db, bg_send_xy_timer_sub, tick);
+ bg->team_db->foreach(bg->team_db, bg->send_xy_timer_sub, tick);
return 0;
}
void bg_config_read(void) {
@@ -497,7 +495,7 @@ void bg_match_over(struct bg_arena *arena, bool canceled) {
if( queue->item[i] > 0 && ( sd = iMap->id2sd(queue->item[i]) ) ) {
if( sd->bg_queue.arena ) {
- bg_team_leave(sd, 0);
+ bg->team_leave(sd, 0);
bg->queue_pc_cleanup(sd);
}
if( canceled )
@@ -532,9 +530,9 @@ void bg_begin(struct bg_arena *arena) {
bg->match_over(arena,true);
} else {
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);
+ 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);
/* 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 */
@@ -570,7 +568,7 @@ void bg_queue_check(struct bg_arena *arena) {
int count = script->hq[arena->queue_id].items;
if( count == arena->max_players ) {
if( arena->fillup_timer != INVALID_TIMER ) {
- iTimer->delete_timer(arena->fillup_timer,bg_fillup_timer);
+ iTimer->delete_timer(arena->fillup_timer,bg->fillup_timer);
arena->fillup_timer = INVALID_TIMER;
}
bg->queue_pregame(arena);
@@ -765,16 +763,16 @@ enum BATTLEGROUNDS_QUEUE_ACK bg_canqueue(struct map_session_data *sd, struct bg_
return BGQA_SUCCESS;
}
void do_init_battleground(void) {
- bg_team_db = idb_alloc(DB_OPT_RELEASE_DATA);
- iTimer->add_timer_func_list(bg_send_xy_timer, "bg_send_xy_timer");
- iTimer->add_timer_interval(iTimer->gettick() + battle_config.bg_update_interval, bg_send_xy_timer, 0, 0, battle_config.bg_update_interval);
+ bg->team_db = idb_alloc(DB_OPT_RELEASE_DATA);
+ iTimer->add_timer_func_list(bg->send_xy_timer, "bg_send_xy_timer");
+ iTimer->add_timer_interval(iTimer->gettick() + battle_config.bg_update_interval, bg->send_xy_timer, 0, 0, battle_config.bg_update_interval);
bg->config_read();
}
void do_final_battleground(void) {
int i;
- bg_team_db->destroy(bg_team_db, NULL);
+ db_destroy(bg->team_db);
for( i = 0; i < bg->arenas; i++ ) {
if( bg->arena[i] )
@@ -793,6 +791,12 @@ void battleground_defaults(void) {
bg->arena = NULL;
bg->arenas = 0;
/* */
+ bg->team_db = NULL;
+ bg->team_counter = 0;
+ /* */
+ bg->init = do_init_battleground;
+ bg->final = do_final_battleground;
+ /* */
bg->name2arena = bg_name2arena;
bg->queue_add = bg_queue_add;
bg->can_queue = bg_canqueue;
@@ -805,6 +809,19 @@ void battleground_defaults(void) {
bg->queue_ready_ack = bg_queue_ready_ack;
bg->match_over = bg_match_over;
bg->queue_check = bg_queue_check;
+ bg->team_search = bg_team_search;
+ bg->getavailablesd = bg_getavailablesd;
+ bg->team_delete = bg_team_delete;
+ bg->team_warp = bg_team_warp;
+ bg->send_dot_remove = bg_send_dot_remove;
+ bg->team_join = bg_team_join;
+ bg->team_leave = bg_team_leave;
+ bg->member_respawn = bg_member_respawn;
+ bg->create = bg_create;
+ bg->team_get_id = bg_team_get_id;
+ bg->send_message = bg_send_message;
+ bg->send_xy_timer_sub = bg_send_xy_timer_sub;
+ bg->send_xy_timer = bg_send_xy_timer;
/* */
bg->config_read = bg_config_read;
}
diff --git a/src/map/battleground.h b/src/map/battleground.h
index 1566e92b8..3edecf902 100644
--- a/src/map/battleground.h
+++ b/src/map/battleground.h
@@ -43,22 +43,6 @@ struct battleground_data {
char die_event[EVENT_NAME_LENGTH];
};
-void do_init_battleground(void);
-void do_final_battleground(void);
-
-struct battleground_data* bg_team_search(int bg_id);
-int bg_send_dot_remove(struct map_session_data *sd);
-int bg_team_get_id(struct block_list *bl);
-struct map_session_data* bg_getavailablesd(struct battleground_data *bg);
-
-int bg_create(unsigned short mapindex, short rx, short ry, const char *ev, const char *dev);
-int bg_team_join(int bg_id, struct map_session_data *sd);
-int bg_team_delete(int bg_id);
-int bg_team_leave(struct map_session_data *sd, int flag);
-int bg_team_warp(int bg_id, unsigned short mapindex, short x, short y);
-int bg_member_respawn(struct map_session_data *sd);
-int bg_send_message(struct map_session_data *sd, const char *mes, int len);
-
struct bg_arena {
char name[NAME_LENGTH];
unsigned char id;
@@ -79,7 +63,6 @@ struct bg_arena {
bool ongoing;
};
-/* battleground.c interface (incomplete) */
struct battleground_interface {
bool queue_on;
/* */
@@ -89,6 +72,12 @@ struct battleground_interface {
struct bg_arena **arena;
unsigned char arenas;
/* */
+ DBMap *team_db; // int bg_id -> struct battleground_data*
+ unsigned int team_counter; // Next bg_id
+ /* */
+ void (*init) (void);
+ void (*final) (void);
+ /* */
struct bg_arena *(*name2arena) (char *name);
void (*queue_add) (struct map_session_data *sd, struct bg_arena *arena, enum bg_queue_types type);
enum BATTLEGROUNDS_QUEUE_ACK (*can_queue) (struct map_session_data *sd, struct bg_arena *arena, enum bg_queue_types type);
@@ -101,6 +90,19 @@ struct battleground_interface {
void (*queue_ready_ack) (struct bg_arena *arena, struct map_session_data *sd, bool response);
void (*match_over) (struct bg_arena *arena, bool canceled);
void (*queue_check) (struct bg_arena *arena);
+ struct battleground_data* (*team_search) (int bg_id);
+ struct map_session_data* (*getavailablesd) (struct battleground_data *bg);
+ int (*team_delete) (int bg_id);
+ int (*team_warp) (int bg_id, unsigned short mapindex, short x, short y);
+ int (*send_dot_remove) (struct map_session_data *sd);
+ int (*team_join) (int bg_id, struct map_session_data *sd);
+ int (*team_leave) (struct map_session_data *sd, int flag);
+ int (*member_respawn) (struct map_session_data *sd);
+ int (*create) (unsigned short mapindex, short rx, short ry, const char *ev, const char *dev);
+ int (*team_get_id) (struct block_list *bl);
+ int (*send_message) (struct map_session_data *sd, const char *mes, int len);
+ int (*send_xy_timer_sub) (DBKey key, DBData *data, va_list ap);
+ int (*send_xy_timer) (int tid, unsigned int tick, int id, intptr_t data);
/* */
void (*config_read) (void);
};
diff --git a/src/map/buyingstore.c b/src/map/buyingstore.c
index 73c50b0bf..5edf9a321 100644
--- a/src/map/buyingstore.c
+++ b/src/map/buyingstore.c
@@ -147,7 +147,7 @@ void buyingstore_create(struct map_session_data* sd, int zenylimit, unsigned cha
break;
}
- if( !id->flag.buyingstore || !itemdb_cantrade_sub(id, pc->get_group_level(sd), pc->get_group_level(sd)) || ( idx = pc->search_inventory(sd, nameid) ) == -1 )
+ if( !id->flag.buyingstore || !itemdb->cantrade_sub(id, pc->get_group_level(sd), pc->get_group_level(sd)) || ( idx = pc->search_inventory(sd, nameid) ) == -1 )
{// restrictions: allowed, no character-bound items and at least one must be owned
break;
}
diff --git a/src/map/chat.c b/src/map/chat.c
index 75ae3681b..28de86fe1 100644
--- a/src/map/chat.c
+++ b/src/map/chat.c
@@ -1,447 +1,447 @@
-// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
-// For more information, see LICENCE in the main folder
-
-#include "../common/cbasetypes.h"
-#include "../common/malloc.h"
-#include "../common/nullpo.h"
-#include "../common/showmsg.h"
-#include "../common/strlib.h"
-#include "../common/mmo.h"
-#include "atcommand.h" // msg_txt()
-#include "battle.h" // struct battle_config
-#include "clif.h"
-#include "map.h"
-#include "npc.h" // npc_event_do()
-#include "pc.h"
-#include "skill.h" // ext_skill_unit_onplace()
-#include "chat.h"
-
-#include <stdio.h>
-#include <string.h>
-
-
-int chat_triggerevent(struct chat_data *cd); // forward declaration
-
-/// Initializes a chatroom object (common functionality for both pc and npc chatrooms).
-/// Returns a chatroom object on success, or NULL on failure.
-static struct chat_data* chat_createchat(struct block_list* bl, const char* title, const char* pass, int limit, bool pub, int trigger, const char* ev, int zeny, int minLvl, int maxLvl)
-{
- struct chat_data* cd;
- nullpo_retr(NULL, bl);
-
- cd = (struct chat_data *) aMalloc(sizeof(struct chat_data));
-
- safestrncpy(cd->title, title, sizeof(cd->title));
- safestrncpy(cd->pass, pass, sizeof(cd->pass));
- cd->pub = pub;
- cd->users = 0;
- cd->limit = min(limit, ARRAYLENGTH(cd->usersd));
- cd->trigger = trigger;
- cd->zeny = zeny;
- cd->minLvl = minLvl;
- cd->maxLvl = maxLvl;
- memset(cd->usersd, 0, sizeof(cd->usersd));
- cd->owner = bl;
- safestrncpy(cd->npc_event, ev, sizeof(cd->npc_event));
-
- cd->bl.id = iMap->get_new_object_id();
- cd->bl.m = bl->m;
- cd->bl.x = bl->x;
- cd->bl.y = bl->y;
- cd->bl.type = BL_CHAT;
- cd->bl.next = cd->bl.prev = NULL;
-
- if( cd->bl.id == 0 )
- {
- aFree(cd);
- cd = NULL;
- }
-
- iMap->addiddb(&cd->bl);
-
- if( bl->type != BL_NPC )
- cd->kick_list = idb_alloc(DB_OPT_BASE);
-
- return cd;
-}
-
-/*==========================================
- * player chatroom creation
- *------------------------------------------*/
-int chat_createpcchat(struct map_session_data* sd, const char* title, const char* pass, int limit, bool pub)
-{
- struct chat_data* cd;
- nullpo_ret(sd);
-
- if( sd->chatID )
- return 0; //Prevent people abusing the chat system by creating multiple chats, as pointed out by End of Exam. [Skotlex]
-
- if( sd->state.vending || sd->state.buyingstore )
- {// not chat, when you already have a store open
- return 0;
- }
-
- if( map[sd->bl.m].flag.nochat )
- {
- clif->message(sd->fd, msg_txt(281));
- return 0; //Can't create chatrooms on this map.
- }
-
- if( iMap->getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOCHAT) )
- {
- clif->message (sd->fd, msg_txt(665));
- return 0;
- }
-
- pc_stop_walking(sd,1);
-
- cd = chat_createchat(&sd->bl, title, pass, limit, pub, 0, "", 0, 1, MAX_LEVEL);
- if( cd ) {
- cd->users = 1;
- cd->usersd[0] = sd;
- pc_setchatid(sd,cd->bl.id);
- pc_stop_attack(sd);
- clif->createchat(sd,0);
- clif->dispchat(cd,0);
- } else
- clif->createchat(sd,1);
-
- return 0;
-}
-
-/*==========================================
- * join an existing chatroom
- *------------------------------------------*/
-int chat_joinchat(struct map_session_data* sd, int chatid, const char* pass)
-{
- struct chat_data* cd;
-
- nullpo_ret(sd);
- cd = (struct chat_data*)iMap->id2bl(chatid);
-
- if( cd == NULL || cd->bl.type != BL_CHAT || cd->bl.m != sd->bl.m || sd->state.vending || sd->state.buyingstore || sd->chatID || ((cd->owner->type == BL_NPC) ? cd->users+1 : cd->users) >= cd->limit )
- {
- clif->joinchatfail(sd,0);
- return 0;
- }
-
- if( !cd->pub && strncmp(pass, cd->pass, sizeof(cd->pass)) != 0 && !pc->has_permission(sd, PC_PERM_JOIN_ALL_CHAT) )
- {
- clif->joinchatfail(sd,1);
- return 0;
- }
-
- if( sd->status.base_level < cd->minLvl || sd->status.base_level > cd->maxLvl ) {
- if(sd->status.base_level < cd->minLvl)
- clif->joinchatfail(sd,5);
- else
- clif->joinchatfail(sd,6);
-
- return 0;
- }
-
- if( sd->status.zeny < cd->zeny ) {
- clif->joinchatfail(sd,4);
- return 0;
- }
-
- if( cd->owner->type != BL_NPC && idb_exists(cd->kick_list,sd->status.char_id) ) {
- clif->joinchatfail(sd,2);//You have been kicked out of the room.
- return 0;
- }
-
- pc_stop_walking(sd,1);
- cd->usersd[cd->users] = sd;
- cd->users++;
-
- pc_setchatid(sd,cd->bl.id);
-
- clif->joinchatok(sd, cd); //To the person who newly joined the list of all
- clif->addchat(cd, sd); //Reports To the person who already in the chat
- clif->dispchat(cd, 0); //Reported number of changes to the people around
-
- chat_triggerevent(cd); //Event
-
- return 0;
-}
-
-
-/*==========================================
- * leave a chatroom
- *------------------------------------------*/
-int chat_leavechat(struct map_session_data* sd, bool kicked)
-{
- struct chat_data* cd;
- int i;
- int leavechar;
-
- nullpo_retr(1, sd);
-
- cd = (struct chat_data*)iMap->id2bl(sd->chatID);
- if( cd == NULL )
- {
- pc_setchatid(sd, 0);
- return 1;
- }
-
- ARR_FIND( 0, cd->users, i, cd->usersd[i] == sd );
- if ( i == cd->users )
- { // Not found in the chatroom?
- pc_setchatid(sd, 0);
- return -1;
- }
-
- clif->leavechat(cd, sd, kicked);
- pc_setchatid(sd, 0);
- cd->users--;
-
- leavechar = i;
-
- for( i = leavechar; i < cd->users; i++ )
- cd->usersd[i] = cd->usersd[i+1];
-
-
- if( cd->users == 0 && cd->owner->type == BL_PC ) { // Delete empty chatroom
- struct skill_unit* unit;
- struct skill_unit_group* group;
-
- clif->clearchat(cd, 0);
- db_destroy(cd->kick_list);
- iMap->deliddb(&cd->bl);
- iMap->delblock(&cd->bl);
- iMap->freeblock(&cd->bl);
-
- unit = iMap->find_skill_unit_oncell(&sd->bl, sd->bl.x, sd->bl.y, AL_WARP, NULL, 0);
- group = (unit != NULL) ? unit->group : NULL;
- if (group != NULL)
- skill->unit_onplace(unit, &sd->bl, group->tick);
-
- return 1;
- }
-
- if( leavechar == 0 && cd->owner->type == BL_PC )
- { // Set and announce new owner
- cd->owner = (struct block_list*) cd->usersd[0];
- clif->changechatowner(cd, cd->usersd[0]);
- clif->clearchat(cd, 0);
-
- //Adjust Chat location after owner has been changed.
- iMap->delblock( &cd->bl );
- cd->bl.x=cd->usersd[0]->bl.x;
- cd->bl.y=cd->usersd[0]->bl.y;
- iMap->addblock( &cd->bl );
-
- clif->dispchat(cd,0);
- }
- else
- clif->dispchat(cd,0); // refresh chatroom
-
- return 0;
-}
-
-/*==========================================
- * change a chatroom's owner
- *------------------------------------------*/
-int chat_changechatowner(struct map_session_data* sd, const char* nextownername)
-{
- struct chat_data* cd;
- struct map_session_data* tmpsd;
- int i;
-
- nullpo_retr(1, sd);
-
- cd = (struct chat_data*)iMap->id2bl(sd->chatID);
- if( cd == NULL || (struct block_list*) sd != cd->owner )
- return 1;
-
- ARR_FIND( 1, cd->users, i, strncmp(cd->usersd[i]->status.name, nextownername, NAME_LENGTH) == 0 );
- if( i == cd->users )
- return -1; // name not found
-
- // erase temporarily
- clif->clearchat(cd,0);
-
- // set new owner
- cd->owner = (struct block_list*) cd->usersd[i];
- clif->changechatowner(cd,cd->usersd[i]);
-
- // swap the old and new owners' positions
- tmpsd = cd->usersd[i];
- cd->usersd[i] = cd->usersd[0];
- cd->usersd[0] = tmpsd;
-
- // set the new chatroom position
- iMap->delblock( &cd->bl );
- cd->bl.x = cd->owner->x;
- cd->bl.y = cd->owner->y;
- iMap->addblock( &cd->bl );
-
- // and display again
- clif->dispchat(cd,0);
-
- return 0;
-}
-
-/*==========================================
- * change a chatroom's status (title, etc)
- *------------------------------------------*/
-int chat_changechatstatus(struct map_session_data* sd, const char* title, const char* pass, int limit, bool pub)
-{
- struct chat_data* cd;
-
- nullpo_retr(1, sd);
-
- cd = (struct chat_data*)iMap->id2bl(sd->chatID);
- if( cd==NULL || (struct block_list *)sd != cd->owner )
- return 1;
-
- safestrncpy(cd->title, title, CHATROOM_TITLE_SIZE);
- safestrncpy(cd->pass, pass, CHATROOM_PASS_SIZE);
- cd->limit = min(limit, ARRAYLENGTH(cd->usersd));
- cd->pub = pub;
-
- clif->changechatstatus(cd);
- clif->dispchat(cd,0);
-
- return 0;
-}
-
-/*==========================================
- * kick an user from a chatroom
- *------------------------------------------*/
-int chat_kickchat(struct map_session_data* sd, const char* kickusername)
-{
- struct chat_data* cd;
- int i;
-
- nullpo_retr(1, sd);
-
- cd = (struct chat_data *)iMap->id2bl(sd->chatID);
-
- if( cd==NULL || (struct block_list *)sd != cd->owner )
- return -1;
-
- ARR_FIND( 0, cd->users, i, strncmp(cd->usersd[i]->status.name, kickusername, NAME_LENGTH) == 0 );
- if( i == cd->users )
- return -1;
-
- if (pc->has_permission(cd->usersd[i], PC_PERM_NO_CHAT_KICK))
- return 0; //gm kick protection [Valaris]
-
- idb_put(cd->kick_list,cd->usersd[i]->status.char_id,(void*)1);
-
- chat->leavechat(cd->usersd[i],1);
- return 0;
-}
-
-/// Creates a chat room for the npc.
-int chat_createnpcchat(struct npc_data* nd, const char* title, int limit, bool pub, int trigger, const char* ev, int zeny, int minLvl, int maxLvl)
-{
- struct chat_data* cd;
- nullpo_ret(nd);
-
- if( nd->chat_id ) {
- ShowError("chat_createnpcchat: npc '%s' already has a chatroom, cannot create new one!\n", nd->exname);
- return 0;
- }
-
- if( zeny > MAX_ZENY || maxLvl > MAX_LEVEL ) {
- ShowError("chat_createnpcchat: npc '%s' has a required lvl or amount of zeny over the max limit!\n", nd->exname);
- return 0;
- }
-
- cd = chat_createchat(&nd->bl, title, "", limit, pub, trigger, ev, zeny, minLvl, maxLvl);
-
- if( cd ) {
- nd->chat_id = cd->bl.id;
- clif->dispchat(cd,0);
- }
-
- return 0;
-}
-
-/// Removes the chatroom from the npc.
-int chat_deletenpcchat(struct npc_data* nd)
-{
- struct chat_data *cd;
- nullpo_ret(nd);
-
- cd = (struct chat_data*)iMap->id2bl(nd->chat_id);
- if( cd == NULL )
- return 0;
-
- chat->npckickall(cd);
- clif->clearchat(cd, 0);
- iMap->deliddb(&cd->bl);
- iMap->delblock(&cd->bl);
- iMap->freeblock(&cd->bl);
- nd->chat_id = 0;
-
- return 0;
-}
-
-/*==========================================
- * Trigger npc event when we enter the chatroom
- *------------------------------------------*/
-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);
- return 0;
-}
-
-/// Enables the event of the chat room.
-/// At most, 127 users are needed to trigger the event.
-int chat_enableevent(struct chat_data* cd)
-{
- nullpo_ret(cd);
-
- cd->trigger &= 0x7f;
- chat_triggerevent(cd);
- return 0;
-}
-
-/// Disables the event of the chat room
-int chat_disableevent(struct chat_data* cd)
-{
- nullpo_ret(cd);
-
- cd->trigger |= 0x80;
- return 0;
-}
-
-/// Kicks all the users from the chat room.
-int chat_npckickall(struct chat_data* cd)
-{
- nullpo_ret(cd);
-
- while( cd->users > 0 )
- chat->leavechat(cd->usersd[cd->users-1],0);
-
- return 0;
-}
-
-/*=====================================
-* Default Functions : chat.h
-* Generated by HerculesInterfaceMaker
-* created by Susu
-*-------------------------------------*/
-void chat_defaults(void) {
- chat = &chat_s;
- /* funcs */
-
- chat->createpcchat = chat_createpcchat;
- chat->joinchat = chat_joinchat;
- chat->leavechat = chat_leavechat;
- chat->changechatowner = chat_changechatowner;
- chat->changechatstatus = chat_changechatstatus;
- chat->kickchat = chat_kickchat;
-
- chat->createnpcchat = chat_createnpcchat;
- chat->deletenpcchat = chat_deletenpcchat;
- chat->enableevent = chat_enableevent;
- chat->disableevent = chat_disableevent;
- chat->npckickall = chat_npckickall;
-}
+// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
+// For more information, see LICENCE in the main folder
+
+#include "../common/cbasetypes.h"
+#include "../common/malloc.h"
+#include "../common/nullpo.h"
+#include "../common/showmsg.h"
+#include "../common/strlib.h"
+#include "../common/mmo.h"
+#include "atcommand.h" // msg_txt()
+#include "battle.h" // struct battle_config
+#include "clif.h"
+#include "map.h"
+#include "npc.h" // npc_event_do()
+#include "pc.h"
+#include "skill.h" // ext_skill_unit_onplace()
+#include "chat.h"
+
+#include <stdio.h>
+#include <string.h>
+
+
+int chat_triggerevent(struct chat_data *cd); // forward declaration
+
+/// Initializes a chatroom object (common functionality for both pc and npc chatrooms).
+/// Returns a chatroom object on success, or NULL on failure.
+static struct chat_data* chat_createchat(struct block_list* bl, const char* title, const char* pass, int limit, bool pub, int trigger, const char* ev, int zeny, int minLvl, int maxLvl)
+{
+ struct chat_data* cd;
+ nullpo_retr(NULL, bl);
+
+ cd = (struct chat_data *) aMalloc(sizeof(struct chat_data));
+
+ safestrncpy(cd->title, title, sizeof(cd->title));
+ safestrncpy(cd->pass, pass, sizeof(cd->pass));
+ cd->pub = pub;
+ cd->users = 0;
+ cd->limit = min(limit, ARRAYLENGTH(cd->usersd));
+ cd->trigger = trigger;
+ cd->zeny = zeny;
+ cd->minLvl = minLvl;
+ cd->maxLvl = maxLvl;
+ memset(cd->usersd, 0, sizeof(cd->usersd));
+ cd->owner = bl;
+ safestrncpy(cd->npc_event, ev, sizeof(cd->npc_event));
+
+ cd->bl.id = iMap->get_new_object_id();
+ cd->bl.m = bl->m;
+ cd->bl.x = bl->x;
+ cd->bl.y = bl->y;
+ cd->bl.type = BL_CHAT;
+ cd->bl.next = cd->bl.prev = NULL;
+
+ if( cd->bl.id == 0 )
+ {
+ aFree(cd);
+ cd = NULL;
+ }
+
+ iMap->addiddb(&cd->bl);
+
+ if( bl->type != BL_NPC )
+ cd->kick_list = idb_alloc(DB_OPT_BASE);
+
+ return cd;
+}
+
+/*==========================================
+ * player chatroom creation
+ *------------------------------------------*/
+int chat_createpcchat(struct map_session_data* sd, const char* title, const char* pass, int limit, bool pub)
+{
+ struct chat_data* cd;
+ nullpo_ret(sd);
+
+ if( sd->chatID )
+ return 0; //Prevent people abusing the chat system by creating multiple chats, as pointed out by End of Exam. [Skotlex]
+
+ if( sd->state.vending || sd->state.buyingstore )
+ {// not chat, when you already have a store open
+ return 0;
+ }
+
+ if( map[sd->bl.m].flag.nochat )
+ {
+ clif->message(sd->fd, msg_txt(281));
+ return 0; //Can't create chatrooms on this map.
+ }
+
+ if( iMap->getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOCHAT) )
+ {
+ clif->message (sd->fd, msg_txt(665));
+ return 0;
+ }
+
+ pc_stop_walking(sd,1);
+
+ cd = chat_createchat(&sd->bl, title, pass, limit, pub, 0, "", 0, 1, MAX_LEVEL);
+ if( cd ) {
+ cd->users = 1;
+ cd->usersd[0] = sd;
+ pc_setchatid(sd,cd->bl.id);
+ pc_stop_attack(sd);
+ clif->createchat(sd,0);
+ clif->dispchat(cd,0);
+ } else
+ clif->createchat(sd,1);
+
+ return 0;
+}
+
+/*==========================================
+ * join an existing chatroom
+ *------------------------------------------*/
+int chat_joinchat(struct map_session_data* sd, int chatid, const char* pass)
+{
+ struct chat_data* cd;
+
+ nullpo_ret(sd);
+ cd = (struct chat_data*)iMap->id2bl(chatid);
+
+ if( cd == NULL || cd->bl.type != BL_CHAT || cd->bl.m != sd->bl.m || sd->state.vending || sd->state.buyingstore || sd->chatID || ((cd->owner->type == BL_NPC) ? cd->users+1 : cd->users) >= cd->limit )
+ {
+ clif->joinchatfail(sd,0);
+ return 0;
+ }
+
+ if( !cd->pub && strncmp(pass, cd->pass, sizeof(cd->pass)) != 0 && !pc->has_permission(sd, PC_PERM_JOIN_ALL_CHAT) )
+ {
+ clif->joinchatfail(sd,1);
+ return 0;
+ }
+
+ if( sd->status.base_level < cd->minLvl || sd->status.base_level > cd->maxLvl ) {
+ if(sd->status.base_level < cd->minLvl)
+ clif->joinchatfail(sd,5);
+ else
+ clif->joinchatfail(sd,6);
+
+ return 0;
+ }
+
+ if( sd->status.zeny < cd->zeny ) {
+ clif->joinchatfail(sd,4);
+ return 0;
+ }
+
+ if( cd->owner->type != BL_NPC && idb_exists(cd->kick_list,sd->status.char_id) ) {
+ clif->joinchatfail(sd,2);//You have been kicked out of the room.
+ return 0;
+ }
+
+ pc_stop_walking(sd,1);
+ cd->usersd[cd->users] = sd;
+ cd->users++;
+
+ pc_setchatid(sd,cd->bl.id);
+
+ clif->joinchatok(sd, cd); //To the person who newly joined the list of all
+ clif->addchat(cd, sd); //Reports To the person who already in the chat
+ clif->dispchat(cd, 0); //Reported number of changes to the people around
+
+ chat_triggerevent(cd); //Event
+
+ return 0;
+}
+
+
+/*==========================================
+ * leave a chatroom
+ *------------------------------------------*/
+int chat_leavechat(struct map_session_data* sd, bool kicked)
+{
+ struct chat_data* cd;
+ int i;
+ int leavechar;
+
+ nullpo_retr(1, sd);
+
+ cd = (struct chat_data*)iMap->id2bl(sd->chatID);
+ if( cd == NULL )
+ {
+ pc_setchatid(sd, 0);
+ return 1;
+ }
+
+ ARR_FIND( 0, cd->users, i, cd->usersd[i] == sd );
+ if ( i == cd->users )
+ { // Not found in the chatroom?
+ pc_setchatid(sd, 0);
+ return -1;
+ }
+
+ clif->leavechat(cd, sd, kicked);
+ pc_setchatid(sd, 0);
+ cd->users--;
+
+ leavechar = i;
+
+ for( i = leavechar; i < cd->users; i++ )
+ cd->usersd[i] = cd->usersd[i+1];
+
+
+ if( cd->users == 0 && cd->owner->type == BL_PC ) { // Delete empty chatroom
+ struct skill_unit* unit;
+ struct skill_unit_group* group;
+
+ clif->clearchat(cd, 0);
+ db_destroy(cd->kick_list);
+ iMap->deliddb(&cd->bl);
+ iMap->delblock(&cd->bl);
+ iMap->freeblock(&cd->bl);
+
+ unit = iMap->find_skill_unit_oncell(&sd->bl, sd->bl.x, sd->bl.y, AL_WARP, NULL, 0);
+ group = (unit != NULL) ? unit->group : NULL;
+ if (group != NULL)
+ skill->unit_onplace(unit, &sd->bl, group->tick);
+
+ return 1;
+ }
+
+ if( leavechar == 0 && cd->owner->type == BL_PC )
+ { // Set and announce new owner
+ cd->owner = (struct block_list*) cd->usersd[0];
+ clif->changechatowner(cd, cd->usersd[0]);
+ clif->clearchat(cd, 0);
+
+ //Adjust Chat location after owner has been changed.
+ iMap->delblock( &cd->bl );
+ cd->bl.x=cd->usersd[0]->bl.x;
+ cd->bl.y=cd->usersd[0]->bl.y;
+ iMap->addblock( &cd->bl );
+
+ clif->dispchat(cd,0);
+ }
+ else
+ clif->dispchat(cd,0); // refresh chatroom
+
+ return 0;
+}
+
+/*==========================================
+ * change a chatroom's owner
+ *------------------------------------------*/
+int chat_changechatowner(struct map_session_data* sd, const char* nextownername)
+{
+ struct chat_data* cd;
+ struct map_session_data* tmpsd;
+ int i;
+
+ nullpo_retr(1, sd);
+
+ cd = (struct chat_data*)iMap->id2bl(sd->chatID);
+ if( cd == NULL || (struct block_list*) sd != cd->owner )
+ return 1;
+
+ ARR_FIND( 1, cd->users, i, strncmp(cd->usersd[i]->status.name, nextownername, NAME_LENGTH) == 0 );
+ if( i == cd->users )
+ return -1; // name not found
+
+ // erase temporarily
+ clif->clearchat(cd,0);
+
+ // set new owner
+ cd->owner = (struct block_list*) cd->usersd[i];
+ clif->changechatowner(cd,cd->usersd[i]);
+
+ // swap the old and new owners' positions
+ tmpsd = cd->usersd[i];
+ cd->usersd[i] = cd->usersd[0];
+ cd->usersd[0] = tmpsd;
+
+ // set the new chatroom position
+ iMap->delblock( &cd->bl );
+ cd->bl.x = cd->owner->x;
+ cd->bl.y = cd->owner->y;
+ iMap->addblock( &cd->bl );
+
+ // and display again
+ clif->dispchat(cd,0);
+
+ return 0;
+}
+
+/*==========================================
+ * change a chatroom's status (title, etc)
+ *------------------------------------------*/
+int chat_changechatstatus(struct map_session_data* sd, const char* title, const char* pass, int limit, bool pub)
+{
+ struct chat_data* cd;
+
+ nullpo_retr(1, sd);
+
+ cd = (struct chat_data*)iMap->id2bl(sd->chatID);
+ if( cd==NULL || (struct block_list *)sd != cd->owner )
+ return 1;
+
+ safestrncpy(cd->title, title, CHATROOM_TITLE_SIZE);
+ safestrncpy(cd->pass, pass, CHATROOM_PASS_SIZE);
+ cd->limit = min(limit, ARRAYLENGTH(cd->usersd));
+ cd->pub = pub;
+
+ clif->changechatstatus(cd);
+ clif->dispchat(cd,0);
+
+ return 0;
+}
+
+/*==========================================
+ * kick an user from a chatroom
+ *------------------------------------------*/
+int chat_kickchat(struct map_session_data* sd, const char* kickusername)
+{
+ struct chat_data* cd;
+ int i;
+
+ nullpo_retr(1, sd);
+
+ cd = (struct chat_data *)iMap->id2bl(sd->chatID);
+
+ if( cd==NULL || (struct block_list *)sd != cd->owner )
+ return -1;
+
+ ARR_FIND( 0, cd->users, i, strncmp(cd->usersd[i]->status.name, kickusername, NAME_LENGTH) == 0 );
+ if( i == cd->users )
+ return -1;
+
+ if (pc->has_permission(cd->usersd[i], PC_PERM_NO_CHAT_KICK))
+ return 0; //gm kick protection [Valaris]
+
+ idb_put(cd->kick_list,cd->usersd[i]->status.char_id,(void*)1);
+
+ chat->leavechat(cd->usersd[i],1);
+ return 0;
+}
+
+/// Creates a chat room for the npc.
+int chat_createnpcchat(struct npc_data* nd, const char* title, int limit, bool pub, int trigger, const char* ev, int zeny, int minLvl, int maxLvl)
+{
+ struct chat_data* cd;
+ nullpo_ret(nd);
+
+ if( nd->chat_id ) {
+ ShowError("chat_createnpcchat: npc '%s' already has a chatroom, cannot create new one!\n", nd->exname);
+ return 0;
+ }
+
+ if( zeny > MAX_ZENY || maxLvl > MAX_LEVEL ) {
+ ShowError("chat_createnpcchat: npc '%s' has a required lvl or amount of zeny over the max limit!\n", nd->exname);
+ return 0;
+ }
+
+ cd = chat_createchat(&nd->bl, title, "", limit, pub, trigger, ev, zeny, minLvl, maxLvl);
+
+ if( cd ) {
+ nd->chat_id = cd->bl.id;
+ clif->dispchat(cd,0);
+ }
+
+ return 0;
+}
+
+/// Removes the chatroom from the npc.
+int chat_deletenpcchat(struct npc_data* nd)
+{
+ struct chat_data *cd;
+ nullpo_ret(nd);
+
+ cd = (struct chat_data*)iMap->id2bl(nd->chat_id);
+ if( cd == NULL )
+ return 0;
+
+ chat->npckickall(cd);
+ clif->clearchat(cd, 0);
+ iMap->deliddb(&cd->bl);
+ iMap->delblock(&cd->bl);
+ iMap->freeblock(&cd->bl);
+ nd->chat_id = 0;
+
+ return 0;
+}
+
+/*==========================================
+ * Trigger npc event when we enter the chatroom
+ *------------------------------------------*/
+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);
+ return 0;
+}
+
+/// Enables the event of the chat room.
+/// At most, 127 users are needed to trigger the event.
+int chat_enableevent(struct chat_data* cd)
+{
+ nullpo_ret(cd);
+
+ cd->trigger &= 0x7f;
+ chat_triggerevent(cd);
+ return 0;
+}
+
+/// Disables the event of the chat room
+int chat_disableevent(struct chat_data* cd)
+{
+ nullpo_ret(cd);
+
+ cd->trigger |= 0x80;
+ return 0;
+}
+
+/// Kicks all the users from the chat room.
+int chat_npckickall(struct chat_data* cd)
+{
+ nullpo_ret(cd);
+
+ while( cd->users > 0 )
+ chat->leavechat(cd->usersd[cd->users-1],0);
+
+ return 0;
+}
+
+/*=====================================
+* Default Functions : chat.h
+* Generated by HerculesInterfaceMaker
+* created by Susu
+*-------------------------------------*/
+void chat_defaults(void) {
+ chat = &chat_s;
+ /* funcs */
+
+ chat->createpcchat = chat_createpcchat;
+ chat->joinchat = chat_joinchat;
+ chat->leavechat = chat_leavechat;
+ chat->changechatowner = chat_changechatowner;
+ chat->changechatstatus = chat_changechatstatus;
+ chat->kickchat = chat_kickchat;
+
+ chat->createnpcchat = chat_createnpcchat;
+ chat->deletenpcchat = chat_deletenpcchat;
+ chat->enableevent = chat_enableevent;
+ chat->disableevent = chat_disableevent;
+ chat->npckickall = chat_npckickall;
+}
diff --git a/src/map/chat.h b/src/map/chat.h
index ff78d8617..a7736e9f3 100644
--- a/src/map/chat.h
+++ b/src/map/chat.h
@@ -1,56 +1,56 @@
-// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
-// For more information, see LICENCE in the main folder
-#ifndef _CHAT_H_
-#define _CHAT_H_
-#include "map.h" // struct block_list, CHATROOM_TITLE_SIZE
-struct map_session_data;
-struct chat_data;
-
-
-struct chat_data {
- struct block_list bl; // data for this map object
- char title[CHATROOM_TITLE_SIZE]; // room title
- char pass[CHATROOM_PASS_SIZE]; // password
- bool pub; // private/public flag
- uint8 users; // current user count
- uint8 limit; // join limit
- uint8 trigger; // number of users needed to trigger event
- uint32 zeny; // required zeny to join
- uint32 minLvl; // minimum base level to join
- uint32 maxLvl; // maximum base level allowed to join
- struct map_session_data* usersd[20];
- struct block_list* owner;
- char npc_event[EVENT_NAME_LENGTH];
- DBMap* kick_list; //DBMap of users who were kicked from this chat
-};
-
-
-
-
-/*=====================================
-* Interface : chat.h
-* Generated by HerculesInterfaceMaker
-* created by Susu
-*-------------------------------------*/
-struct chat_interface {
- /* funcs */
-
- int (*createpcchat) (struct map_session_data* sd, const char* title, const char* pass, int limit, bool pub);
- int (*joinchat) (struct map_session_data* sd, int chatid, const char* pass);
- int (*leavechat) (struct map_session_data* sd, bool kicked);
- int (*changechatowner) (struct map_session_data* sd, const char* nextownername);
- int (*changechatstatus) (struct map_session_data* sd, const char* title, const char* pass, int limit, bool pub);
- int (*kickchat) (struct map_session_data* sd, const char* kickusername);
-
- int (*createnpcchat) (struct npc_data* nd, const char* title, int limit, bool pub, int trigger, const char* ev, int zeny, int minLvl, int maxLvl);
- int (*deletenpcchat) (struct npc_data* nd);
- int (*enableevent) (struct chat_data* cd);
- int (*disableevent) (struct chat_data* cd);
- int (*npckickall) (struct chat_data* cd);
-} chat_s;
-
-struct chat_interface *chat;
-
-void chat_defaults(void);
-
-#endif /* _CHAT_H_ */
+// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
+// For more information, see LICENCE in the main folder
+#ifndef _CHAT_H_
+#define _CHAT_H_
+#include "map.h" // struct block_list, CHATROOM_TITLE_SIZE
+struct map_session_data;
+struct chat_data;
+
+
+struct chat_data {
+ struct block_list bl; // data for this map object
+ char title[CHATROOM_TITLE_SIZE]; // room title
+ char pass[CHATROOM_PASS_SIZE]; // password
+ bool pub; // private/public flag
+ uint8 users; // current user count
+ uint8 limit; // join limit
+ uint8 trigger; // number of users needed to trigger event
+ uint32 zeny; // required zeny to join
+ uint32 minLvl; // minimum base level to join
+ uint32 maxLvl; // maximum base level allowed to join
+ struct map_session_data* usersd[20];
+ struct block_list* owner;
+ char npc_event[EVENT_NAME_LENGTH];
+ DBMap* kick_list; //DBMap of users who were kicked from this chat
+};
+
+
+
+
+/*=====================================
+* Interface : chat.h
+* Generated by HerculesInterfaceMaker
+* created by Susu
+*-------------------------------------*/
+struct chat_interface {
+ /* funcs */
+
+ int (*createpcchat) (struct map_session_data* sd, const char* title, const char* pass, int limit, bool pub);
+ int (*joinchat) (struct map_session_data* sd, int chatid, const char* pass);
+ int (*leavechat) (struct map_session_data* sd, bool kicked);
+ int (*changechatowner) (struct map_session_data* sd, const char* nextownername);
+ int (*changechatstatus) (struct map_session_data* sd, const char* title, const char* pass, int limit, bool pub);
+ int (*kickchat) (struct map_session_data* sd, const char* kickusername);
+
+ int (*createnpcchat) (struct npc_data* nd, const char* title, int limit, bool pub, int trigger, const char* ev, int zeny, int minLvl, int maxLvl);
+ int (*deletenpcchat) (struct npc_data* nd);
+ int (*enableevent) (struct chat_data* cd);
+ int (*disableevent) (struct chat_data* cd);
+ int (*npckickall) (struct chat_data* cd);
+} chat_s;
+
+struct chat_interface *chat;
+
+void chat_defaults(void);
+
+#endif /* _CHAT_H_ */
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 d26f11ba3..342f1d943 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -339,7 +339,7 @@ int clif_send(const void* buf, int len, struct block_list* bl, enum send_target
struct map_session_data *sd, *tsd;
struct party_data *p = NULL;
struct guild *g = NULL;
- struct battleground_data *bg = NULL;
+ struct battleground_data *bgd = NULL;
int x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd;
struct s_mapiterator* iter;
@@ -545,9 +545,9 @@ int clif_send(const void* buf, int len, struct block_list* bl, enum send_target
case BG_SAMEMAP_WOS:
case BG:
case BG_WOS:
- if( sd && sd->bg_id && (bg = bg_team_search(sd->bg_id)) != NULL ) {
+ if( sd && sd->bg_id && (bgd = bg->team_search(sd->bg_id)) != NULL ) {
for( i = 0; i < MAX_BG_MEMBERS; i++ ) {
- if( (sd = bg->members[i].sd) == NULL || !(fd = sd->fd) )
+ if( (sd = bgd->members[i].sd) == NULL || !(fd = sd->fd) )
continue;
if( sd->bl.id == bl->id && (type == BG_WOS || type == BG_SAMEMAP_WOS || type == BG_AREA_WOS) )
continue;
@@ -902,7 +902,7 @@ void clif_set_unit_idle2(struct block_list* bl, struct map_session_data *tsd, en
p.virtue = (sc) ? sc->opt3 : 0;
p.isPKModeON = (sd) ? sd->status.karma : 0;
p.sex = vd->sex;
- WBUFPOS(&p.PosDir[0],0,bl->x,bl->y,unit_getdir(bl));
+ WBUFPOS(&p.PosDir[0],0,bl->x,bl->y,unit->getdir(bl));
p.xSize = p.ySize = (sd) ? 5 : 0;
p.state = vd->dead_sit;
p.clevel = clif_setlevel(bl);
@@ -965,7 +965,7 @@ void clif_set_unit_idle(struct block_list* bl, struct map_session_data *tsd, enu
p.virtue = (sc) ? sc->opt3 : 0;
p.isPKModeON = (sd) ? sd->status.karma : 0;
p.sex = vd->sex;
- WBUFPOS(&p.PosDir[0],0,bl->x,bl->y,unit_getdir(bl));
+ WBUFPOS(&p.PosDir[0],0,bl->x,bl->y,unit->getdir(bl));
p.xSize = p.ySize = (sd) ? 5 : 0;
p.state = vd->dead_sit;
p.clevel = clif_setlevel(bl);
@@ -1034,7 +1034,7 @@ void clif_spawn_unit2(struct block_list* bl, enum send_target target) {
p.headDir = (sd)? sd->head_dir : 0;
p.isPKModeON = (sd) ? sd->status.karma : 0;
p.sex = vd->sex;
- WBUFPOS(&p.PosDir[0],0,bl->x,bl->y,unit_getdir(bl));
+ WBUFPOS(&p.PosDir[0],0,bl->x,bl->y,unit->getdir(bl));
p.xSize = p.ySize = (sd) ? 5 : 0;
clif->send(&p,sizeof(p),bl,target);
@@ -1092,7 +1092,7 @@ void clif_spawn_unit(struct block_list* bl, enum send_target target) {
p.virtue = (sc) ? sc->opt3 : 0;
p.isPKModeON = (sd) ? sd->status.karma : 0;
p.sex = vd->sex;
- WBUFPOS(&p.PosDir[0],0,bl->x,bl->y,unit_getdir(bl));
+ WBUFPOS(&p.PosDir[0],0,bl->x,bl->y,unit->getdir(bl));
p.xSize = p.ySize = (sd) ? 5 : 0;
p.clevel = clif_setlevel(bl);
#if PACKETVER >= 20080102
@@ -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);
@@ -2326,7 +2326,7 @@ void clif_inventorylist(struct map_session_data *sd) {
if( sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL )
continue;
- if( !itemdb_isstackable2(sd->inventory_data[i]) )
+ if( !itemdb->isstackable2(sd->inventory_data[i]) )
{ //Non-stackable (Equippable)
WBUFW(bufe,ne*se+4)=i+2;
clif->item_sub(bufe, ne*se+6, &sd->status.inventory[i], sd->inventory_data[i], pc->equippoint(sd,i));
@@ -2415,7 +2415,7 @@ void clif_equiplist(struct map_session_data *sd)
if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
continue;
- if(itemdb_isstackable2(sd->inventory_data[i]))
+ if(itemdb->isstackable2(sd->inventory_data[i]))
continue;
//Equippable
WBUFW(buf,n*cmd+4)=i+2;
@@ -2473,7 +2473,7 @@ void clif_storagelist(struct map_session_data* sd, struct item* items, int items
if( items[i].nameid <= 0 )
continue;
id = itemdb->search(items[i].nameid);
- if( !itemdb_isstackable2(id) )
+ if( !itemdb->isstackable2(id) )
{ //Equippable
WBUFW(bufe,ne*cmd+4)=i+1;
clif->item_sub(bufe, ne*cmd+6, &items[i], id, id->equip);
@@ -2553,7 +2553,7 @@ void clif_cartlist(struct map_session_data *sd)
if( sd->status.cart[i].nameid <= 0 )
continue;
id = itemdb->search(sd->status.cart[i].nameid);
- if( !itemdb_isstackable2(id) )
+ if( !itemdb->isstackable2(id) )
{ //Equippable
WBUFW(bufe,ne*cmd+4)=i+2;
clif->item_sub(bufe, ne*cmd+6, &sd->status.cart[i], id, id->equip);
@@ -4328,7 +4328,7 @@ void clif_getareachar_unit(struct map_session_data* sd,struct block_list *bl) {
if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->option&OPTION_INVISIBLE))
return;
- if ( ( ud = unit_bl2ud(bl) ) && ud->walktimer != INVALID_TIMER )
+ if ( ( ud = unit->bl2ud(bl) ) && ud->walktimer != INVALID_TIMER )
clif->set_unit_walking(bl,sd,ud,SELF);
else
clif->set_unit_idle(bl,sd,SELF);
@@ -4512,7 +4512,7 @@ int clif_damage(struct block_list* src, struct block_list* dst, unsigned int tic
}
if(src == dst) {
- unit_setdir(src,unit_getdir(src));
+ unit->setdir(src,unit->getdir(src));
}
//Return adjusted can't walk delay for further processing.
return clif->calc_walkdelay(dst,ddelay,type,damage+damage2,div);
@@ -8904,8 +8904,8 @@ void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int cl
{
if( pcdb_checkid(class_) ) {
clif->starskill(sd, pc->job_name(class_), class_, hate_level, type ? 10 : 11);
- } else if( mobdb_checkid(class_) ) {
- clif->starskill(sd, mob_db(class_)->jname, class_, hate_level, type ? 10 : 11);
+ } else if( mob->db_checkid(class_) ) {
+ clif->starskill(sd, mob->db(class_)->jname, class_, hate_level, type ? 10 : 11);
} else {
ShowWarning("clif_hate_info: Received invalid class %d for this packet (char_id=%d, hate_level=%u, type=%u).\n", class_, sd->status.char_id, (unsigned int)hate_level, (unsigned int)type);
}
@@ -8916,7 +8916,7 @@ void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int cl
*------------------------------------------*/
void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
{
- clif->starskill(sd, mob_db(mob_id)->jname, mob_id, progress, 20);
+ clif->starskill(sd, mob->db(mob_id)->jname, mob_id, progress, 20);
}
/*==========================================
@@ -9012,7 +9012,7 @@ void clif_viewequip_ack(struct map_session_data* sd, struct map_session_data* ts
{
if (tsd->status.inventory[i].nameid <= 0 || tsd->inventory_data[i] == NULL) // Item doesn't exist
continue;
- if (!itemdb_isequip2(tsd->inventory_data[i])) // Is not equippable
+ if (!itemdb->isequip2(tsd->inventory_data[i])) // Is not equippable
continue;
// Inventory position
@@ -9444,7 +9444,7 @@ void clif_parse_LoadEndAck(int fd,struct map_session_data *sd) {
if( sd->pd ) {
if( battle_config.pet_no_gvg && map_flag_gvg2(sd->bl.m) ) { //Return the pet to egg. [Skotlex]
clif->message(sd->fd, msg_txt(666));
- pet_menu(sd, 3); //Option 3 is return to egg.
+ pet->menu(sd, 3); //Option 3 is return to egg.
} else {
iMap->addblock(&sd->pd->bl);
clif->spawn(&sd->pd->bl);
@@ -9517,7 +9517,7 @@ void clif_parse_LoadEndAck(int fd,struct map_session_data *sd) {
}
if(sd->pd && sd->pd->pet.intimate > 900)
- clif->pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
+ clif->pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet->hungry_val(sd->pd));
if(homun_alive(sd->hd))
homun->init_timers(sd->hd);
@@ -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);
}
@@ -9784,7 +9784,7 @@ void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
//Set last idle time... [Skotlex]
sd->idletime = last_tick;
- unit_walktoxy(&sd->bl, x, y, 4);
+ unit->walktoxy(&sd->bl, x, y, 4);
}
@@ -9945,7 +9945,7 @@ void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
pc->disguise(sd,sd->status.class_);
if( pc_isdead(sd) )
clif_clearunit_single(-sd->bl.id, CLR_DEAD, sd->fd);
- if( unit_is_walking(&sd->bl) )
+ if( unit->is_walking(&sd->bl) )
clif->move(&sd->ud);
} else if ( sd->disguise == sd->status.class_ && sd->fontcolor_tid != INVALID_TIMER ) {
const struct TimerData *timer;
@@ -10000,7 +10000,7 @@ void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
WFIFOSET(fd, WFIFOW(fd,2));
#ifdef PCRE_SUPPORT
// trigger listening npcs
- iMap->foreachinrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, text, textlen, &sd->bl);
+ iMap->foreachinrange(npc_chat->sub, &sd->bl, AREA_SIZE, BL_NPC, text, textlen, &sd->bl);
#endif
// Chat logging type 'O' / Global Chat
@@ -10045,7 +10045,7 @@ void clif_changed_dir(struct block_list *bl, enum send_target target)
WBUFW(buf,0) = 0x9c;
WBUFL(buf,2) = bl->id;
WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
- WBUFB(buf,8) = unit_getdir(bl);
+ WBUFB(buf,8) = unit->getdir(bl);
clif->send(buf, packet_len(0x9c), bl, target);
@@ -10169,7 +10169,7 @@ void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type,
pc->delinvincibletimer(sd);
sd->idletime = last_tick;
- unit_attack(&sd->bl, target_id, action_type != 0);
+ unit->attack(&sd->bl, target_id, action_type != 0);
break;
case 0x02: // sitdown
if (battle_config.basic_skill_check && pc->checkskill(sd, NV_BASIC) < 3) {
@@ -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;
}
@@ -10678,7 +10678,7 @@ void clif_parse_EquipItem(int fd,struct map_session_data *sd)
return;
if(sd->inventory_data[index]->type == IT_PETARMOR){
- pet_equipitem(sd,index);
+ pet->equipitem(sd,index);
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);
@@ -11248,7 +11248,7 @@ void clif_parse_UseSkillToId_homun(struct homun_data *hd, struct map_session_dat
if( skill_lv > lv )
skill_lv = lv;
if( skill_lv )
- unit_skilluse_id(&hd->bl, target_id, skill_id, skill_lv);
+ unit->skilluse_id(&hd->bl, target_id, skill_id, skill_lv);
}
void clif_parse_UseSkillToPos_homun(struct homun_data *hd, struct map_session_data *sd, unsigned int tick, uint16 skill_id, uint16 skill_lv, short x, short y, int skillmoreinfo)
@@ -11269,7 +11269,7 @@ void clif_parse_UseSkillToPos_homun(struct homun_data *hd, struct map_session_da
if( skill_lv > lv )
skill_lv = lv;
if( skill_lv )
- unit_skilluse_pos(&hd->bl, x, y, skill_id, skill_lv);
+ unit->skilluse_pos(&hd->bl, x, y, skill_id, skill_lv);
}
void clif_parse_UseSkillToId_mercenary(struct mercenary_data *md, struct map_session_data *sd, unsigned int tick, uint16 skill_id, uint16 skill_lv, int target_id)
@@ -11291,7 +11291,7 @@ void clif_parse_UseSkillToId_mercenary(struct mercenary_data *md, struct map_ses
if( skill_lv > lv )
skill_lv = lv;
if( skill_lv )
- unit_skilluse_id(&md->bl, target_id, skill_id, skill_lv);
+ unit->skilluse_id(&md->bl, target_id, skill_id, skill_lv);
}
void clif_parse_UseSkillToPos_mercenary(struct mercenary_data *md, struct map_session_data *sd, unsigned int tick, uint16 skill_id, uint16 skill_lv, short x, short y, int skillmoreinfo)
@@ -11314,7 +11314,7 @@ void clif_parse_UseSkillToPos_mercenary(struct mercenary_data *md, struct map_se
if( skill_lv > lv )
skill_lv = lv;
if( skill_lv )
- unit_skilluse_pos(&md->bl, x, y, skill_id, skill_lv);
+ unit->skilluse_pos(&md->bl, x, y, skill_id, skill_lv);
}
@@ -11398,7 +11398,7 @@ void clif_parse_UseSkillToId(int fd, struct map_session_data *sd)
skill_lv = sd->skillitemlv;
if( !(tmp&INF_SELF_SKILL) )
pc->delinvincibletimer(sd); // Target skills thru items cancel invincibility. [Inkfish]
- unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
+ unit->skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
return;
}
@@ -11418,7 +11418,7 @@ void clif_parse_UseSkillToId(int fd, struct map_session_data *sd)
pc->delinvincibletimer(sd);
if( skill_lv )
- unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
+ unit->skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
}
/*==========================================
@@ -11490,14 +11490,14 @@ void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, uint16 ski
if( sd->skillitem == skill_id ) {
if( skill_lv != sd->skillitemlv )
skill_lv = sd->skillitemlv;
- unit_skilluse_pos(&sd->bl, x, y, skill_id, skill_lv);
+ unit->skilluse_pos(&sd->bl, x, y, skill_id, skill_lv);
} else {
int lv;
sd->skillitem = sd->skillitemlv = 0;
if( (lv = pc->checkskill(sd, skill_id)) > 0 ) {
if( skill_lv > lv )
skill_lv = lv;
- unit_skilluse_pos(&sd->bl, x, y, skill_id,skill_lv);
+ unit->skilluse_pos(&sd->bl, x, y, skill_id,skill_lv);
}
}
}
@@ -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);
}
@@ -13047,7 +13047,7 @@ void clif_parse_GuildMessage(int fd, struct map_session_data* sd)
}
if( sd->bg_id )
- bg_send_message(sd, text, textlen);
+ bg->send_message(sd, text, textlen);
else
guild->send_message(sd, text, textlen);
}
@@ -13162,7 +13162,7 @@ void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
/// 4 = unequip accessory
void clif_parse_PetMenu(int fd, struct map_session_data *sd)
{
- pet_menu(sd,RFIFOB(fd,2));
+ pet->menu(sd,RFIFOB(fd,2));
}
@@ -13170,7 +13170,7 @@ void clif_parse_PetMenu(int fd, struct map_session_data *sd)
/// 019f <id>.L
void clif_parse_CatchPet(int fd, struct map_session_data *sd)
{
- pet_catch_process2(sd,RFIFOL(fd,2));
+ pet->catch_process2(sd,RFIFOL(fd,2));
}
@@ -13183,7 +13183,7 @@ void clif_parse_SelectEgg(int fd, struct map_session_data *sd)
clif->authfail_fd(fd, 0);
return;
}
- pet_select_egg(sd,RFIFOW(fd,2)-2);
+ pet->select_egg(sd,RFIFOW(fd,2)-2);
clif_menuskill_clear(sd);
}
@@ -13223,7 +13223,7 @@ void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
/// 01a5 <name>.24B
void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
{
- pet_change_name(sd,(char*)RFIFOP(fd,2));
+ pet->change_name(sd,(char*)RFIFOP(fd,2));
}
@@ -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;
@@ -13416,7 +13416,7 @@ void clif_parse_GM_Monster_Item(int fd, struct map_session_data *sd)
return;
}
- if( (count=mobdb_searchname_array(mob_array, 10, item_monster_name, 1)) > 0){
+ if( (count=mob->db_searchname_array(mob_array, 10, item_monster_name, 1)) > 0){
for(i = 0; i < count; i++){
if( mob_array[i] && strcmp(mob_array[i]->sprite, item_monster_name) == 0 ) // It only accepts sprite name
break;
@@ -14378,9 +14378,9 @@ void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd)
else
return;
- unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
- ud = unit_bl2ud(bl);
- unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
+ unit->calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
+ ud = unit->bl2ud(bl);
+ unit->walktoxy(bl, ud->to_x, ud->to_y, 4);
}
@@ -14401,7 +14401,7 @@ void clif_parse_HomMoveTo(int fd, struct map_session_data *sd)
else
return;
- unit_walktoxy(bl, x, y, 4);
+ unit->walktoxy(bl, x, y, 4);
}
@@ -14422,8 +14422,8 @@ void clif_parse_HomAttack(int fd,struct map_session_data *sd)
bl = &sd->md->bl;
else return;
- unit_stop_attack(bl);
- unit_attack(bl, target_id, action_type != 0);
+ unit->stop_attack(bl);
+ unit->attack(bl, target_id, action_type != 0);
}
@@ -15389,7 +15389,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);
@@ -15401,7 +15401,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
}
@@ -15601,7 +15601,7 @@ void clif_quest_send_mission(struct map_session_data * sd)
int fd = sd->fd;
int i, j;
int len = sd->avail_quests*104+8;
- struct mob_db *mob;
+ struct mob_db *monster;
WFIFOHEAD(fd, len);
WFIFOW(fd, 0) = 0x2b2;
@@ -15610,16 +15610,16 @@ void clif_quest_send_mission(struct map_session_data * sd)
for( i = 0; i < sd->avail_quests; i++ ) {
WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
- WFIFOL(fd, i*104+12) = sd->quest_log[i].time - quest_db[sd->quest_index[i]].time;
+ WFIFOL(fd, i*104+12) = sd->quest_log[i].time - quest->db[sd->quest_index[i]].time;
WFIFOL(fd, i*104+16) = sd->quest_log[i].time;
- WFIFOW(fd, i*104+20) = quest_db[sd->quest_index[i]].num_objectives;
+ WFIFOW(fd, i*104+20) = quest->db[sd->quest_index[i]].num_objectives;
- for( j = 0 ; j < quest_db[sd->quest_index[i]].num_objectives; j++ )
+ for( j = 0 ; j < quest->db[sd->quest_index[i]].num_objectives; j++ )
{
- WFIFOL(fd, i*104+22+j*30) = quest_db[sd->quest_index[i]].mob[j];
+ WFIFOL(fd, i*104+22+j*30) = quest->db[sd->quest_index[i]].mob[j];
WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j];
- mob = mob_db(quest_db[sd->quest_index[i]].mob[j]);
- memcpy(WFIFOP(fd, i*104+28+j*30), mob?mob->jname:"NULL", NAME_LENGTH);
+ monster = mob->db(quest->db[sd->quest_index[i]].mob[j]);
+ memcpy(WFIFOP(fd, i*104+28+j*30), monster?monster->jname:"NULL", NAME_LENGTH);
}
}
@@ -15633,21 +15633,21 @@ void clif_quest_add(struct map_session_data * sd, struct quest * qd, int index)
{
int fd = sd->fd;
int i;
- struct mob_db *mob;
+ struct mob_db *monster;
WFIFOHEAD(fd, packet_len(0x2b3));
WFIFOW(fd, 0) = 0x2b3;
WFIFOL(fd, 2) = qd->quest_id;
WFIFOB(fd, 6) = qd->state;
- WFIFOB(fd, 7) = qd->time - quest_db[index].time;
+ WFIFOB(fd, 7) = qd->time - quest->db[index].time;
WFIFOL(fd, 11) = qd->time;
- WFIFOW(fd, 15) = quest_db[index].num_objectives;
+ WFIFOW(fd, 15) = quest->db[index].num_objectives;
- for( i = 0; i < quest_db[index].num_objectives; i++ ) {
- WFIFOL(fd, i*30+17) = quest_db[index].mob[i];
+ for( i = 0; i < quest->db[index].num_objectives; i++ ) {
+ WFIFOL(fd, i*30+17) = quest->db[index].mob[i];
WFIFOW(fd, i*30+21) = qd->count[i];
- mob = mob_db(quest_db[index].mob[i]);
- memcpy(WFIFOP(fd, i*30+23), mob?mob->jname:"NULL", NAME_LENGTH);
+ monster = mob->db(quest->db[index].mob[i]);
+ memcpy(WFIFOP(fd, i*30+23), monster?monster->jname:"NULL", NAME_LENGTH);
}
WFIFOSET(fd, packet_len(0x2b3));
@@ -15673,17 +15673,17 @@ void clif_quest_update_objective(struct map_session_data * sd, struct quest * qd
{
int fd = sd->fd;
int i;
- int len = quest_db[index].num_objectives*12+6;
+ int len = quest->db[index].num_objectives*12+6;
WFIFOHEAD(fd, len);
WFIFOW(fd, 0) = 0x2b5;
WFIFOW(fd, 2) = len;
- WFIFOW(fd, 4) = quest_db[index].num_objectives;
+ WFIFOW(fd, 4) = quest->db[index].num_objectives;
- for( i = 0; i < quest_db[index].num_objectives; i++ ) {
+ for( i = 0; i < quest->db[index].num_objectives; i++ ) {
WFIFOL(fd, i*12+6) = qd->quest_id;
- WFIFOL(fd, i*12+10) = quest_db[index].mob[i];
- WFIFOW(fd, i*12+14) = quest_db[index].count[i];
+ WFIFOL(fd, i*12+10) = quest->db[index].mob[i];
+ WFIFOW(fd, i*12+14) = quest->db[index].count[i];
WFIFOW(fd, i*12+16) = qd->count[i];
}
@@ -15695,7 +15695,7 @@ void clif_quest_update_objective(struct map_session_data * sd, struct quest * qd
/// 02b6 <quest id>.L <active>.B
void clif_parse_questStateAck(int fd, struct map_session_data * sd)
{
- quest_update_status(sd, RFIFOL(fd,2), RFIFOB(fd,6)?Q_ACTIVE:Q_INACTIVE);
+ quest->update_status(sd, RFIFOL(fd,2), RFIFOB(fd,6)?Q_ACTIVE:Q_INACTIVE);
}
@@ -16016,11 +16016,11 @@ void clif_bg_xy_remove(struct map_session_data *sd)
/// Notifies clients of a battleground message (ZC_BATTLEFIELD_CHAT).
/// 02dc <packet len>.W <account id>.L <name>.24B <message>.?B
-void clif_bg_message(struct battleground_data *bg, int src_id, const char *name, const char *mes, int len)
+void clif_bg_message(struct battleground_data *bgd, int src_id, const char *name, const char *mes, int len)
{
struct map_session_data *sd;
unsigned char *buf;
- if( !bg->count || (sd = bg_getavailablesd(bg)) == NULL )
+ if( !bgd->count || (sd = bg->getavailablesd(bgd)) == NULL )
return;
buf = (unsigned char*)aMalloc((len + NAME_LENGTH + 8)*sizeof(unsigned char));
@@ -16062,7 +16062,7 @@ void clif_parse_BattleChat(int fd, struct map_session_data* sd)
sd->cantalk_tick = iTimer->gettick() + battle_config.min_chat_delay;
}
- bg_send_message(sd, text, textlen);
+ bg->send_message(sd, text, textlen);
}
@@ -17410,12 +17410,12 @@ void clif_parse_CashShopBuy(int fd, struct map_session_data *sd) {
get_count = qty;
- if (!itemdb_isstackable2(data))
+ if (!itemdb->isstackable2(data))
get_count = 1;
pc->paycash(sd, clif->cs.data[tab][j]->price * qty, kafra_pay);// [Ryuuzaki]
for (k = 0; k < qty; k += get_count) {
- if (!pet_create_egg(sd, data->nameid)) {
+ if (!pet->create_egg(sd, data->nameid)) {
memset(&item_tmp, 0, sizeof(item_tmp));
item_tmp.nameid = data->nameid;
item_tmp.identify = 1;
diff --git a/src/map/clif.h b/src/map/clif.h
index 3a42b54da..b364765e5 100644
--- a/src/map/clif.h
+++ b/src/map/clif.h
@@ -836,7 +836,7 @@ struct clif_interface {
void (*bg_hp) (struct map_session_data *sd);
void (*bg_xy) (struct map_session_data *sd);
void (*bg_xy_remove) (struct map_session_data *sd);
- void (*bg_message) (struct battleground_data *bg, int src_id, const char *name, const char *mes, int len);
+ void (*bg_message) (struct battleground_data *bgd, int src_id, const char *name, const char *mes, int len);
void (*bg_updatescore) (int16 m);
void (*bg_updatescore_single) (struct map_session_data *sd);
void (*sendbgemblem_area) (struct map_session_data *sd);
diff --git a/src/map/duel.c b/src/map/duel.c
index a04ed855b..c3b241e9e 100644
--- a/src/map/duel.c
+++ b/src/map/duel.c
@@ -1,204 +1,204 @@
-// Copyright (c) Hercules Dev Team, licensed under GNU GPL.
-// See the LICENSE file
-// Portions Copyright (c) Athena Dev Teams
-
-#include "../common/cbasetypes.h"
-
-#include "atcommand.h" // msg_txt
-#include "clif.h"
-#include "duel.h"
-#include "pc.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-
-/*==========================================
- * Duel organizing functions [LuzZza]
- *------------------------------------------*/
-void duel_savetime(struct map_session_data* sd)
-{
- time_t timer;
- struct tm *t;
-
- time(&timer);
- t = localtime(&timer);
-
- pc_setglobalreg(sd, "PC_LAST_DUEL_TIME", t->tm_mday*24*60 + t->tm_hour*60 + t->tm_min);
-}
-
-int duel_checktime(struct map_session_data* sd)
-{
- int diff;
- time_t timer;
- struct tm *t;
-
- time(&timer);
- t = localtime(&timer);
-
- diff = t->tm_mday*24*60 + t->tm_hour*60 + t->tm_min - pc_readglobalreg(sd, "PC_LAST_DUEL_TIME");
-
- return !(diff >= 0 && diff < battle_config.duel_time_interval);
-}
-static int duel_showinfo_sub(struct map_session_data* sd, va_list va)
-{
- struct map_session_data *ssd = va_arg(va, struct map_session_data*);
- int *p = va_arg(va, int*);
- char output[256];
-
- if (sd->duel_group != ssd->duel_group) return 0;
-
- sprintf(output, " %d. %s", ++(*p), sd->status.name);
- clif->disp_onlyself(ssd, output, strlen(output));
- return 1;
-}
-
-void duel_showinfo(const unsigned int did, struct map_session_data* sd)
-{
- int p=0;
- char output[256];
-
- if(iDuel->duel_list[did].max_players_limit > 0)
- sprintf(output, msg_txt(370), //" -- Duels: %d/%d, Members: %d/%d, Max players: %d --"
- did, iDuel->duel_count,
- iDuel->duel_list[did].members_count,
- iDuel->duel_list[did].members_count + iDuel->duel_list[did].invites_count,
- iDuel->duel_list[did].max_players_limit);
- else
- sprintf(output, msg_txt(371), //" -- Duels: %d/%d, Members: %d/%d --"
- did, iDuel->duel_count,
- iDuel->duel_list[did].members_count,
- iDuel->duel_list[did].members_count + iDuel->duel_list[did].invites_count);
-
- clif->disp_onlyself(sd, output, strlen(output));
- iMap->map_foreachpc(duel_showinfo_sub, sd, &p);
-}
-
-int duel_create(struct map_session_data* sd, const unsigned int maxpl)
-{
- int i=1;
- char output[256];
-
- while(iDuel->duel_list[i].members_count > 0 && i < MAX_DUEL) i++;
- if(i == MAX_DUEL) return 0;
-
- iDuel->duel_count++;
- sd->duel_group = i;
- iDuel->duel_list[i].members_count++;
- iDuel->duel_list[i].invites_count = 0;
- iDuel->duel_list[i].max_players_limit = maxpl;
-
- strcpy(output, msg_txt(372)); // " -- Duel has been created (@invite/@leave) --"
- clif->disp_onlyself(sd, output, strlen(output));
-
- clif->map_property(sd, MAPPROPERTY_FREEPVPZONE);
- clif->maptypeproperty2(&sd->bl,SELF);
- return i;
-}
-
-void duel_invite(const unsigned int did, struct map_session_data* sd, struct map_session_data* target_sd)
-{
- char output[256];
-
- // " -- Player %s invites %s to duel --"
- sprintf(output, msg_txt(373), sd->status.name, target_sd->status.name);
- clif->disp_message(&sd->bl, output, strlen(output), DUEL_WOS);
-
- target_sd->duel_invite = did;
- iDuel->duel_list[did].invites_count++;
-
- // "Blue -- Player %s invites you to PVP duel (@accept/@reject) --"
- sprintf(output, msg_txt(374), sd->status.name);
- clif->broadcast((struct block_list *)target_sd, output, strlen(output)+1, BC_BLUE, SELF);
-}
-
-static int duel_leave_sub(struct map_session_data* sd, va_list va)
-{
- int did = va_arg(va, int);
- if (sd->duel_invite == did)
- sd->duel_invite = 0;
- return 0;
-}
-
-void duel_leave(const unsigned int did, struct map_session_data* sd)
-{
- char output[256];
-
- // " <- Player %s has left duel --"
- sprintf(output, msg_txt(375), sd->status.name);
- clif->disp_message(&sd->bl, output, strlen(output), DUEL_WOS);
-
- iDuel->duel_list[did].members_count--;
-
- if(iDuel->duel_list[did].members_count == 0) {
- iMap->map_foreachpc(duel_leave_sub, did);
- iDuel->duel_count--;
- }
-
- sd->duel_group = 0;
- duel_savetime(sd);
- clif->map_property(sd, MAPPROPERTY_NOTHING);
- clif->maptypeproperty2(&sd->bl,SELF);
-}
-
-void duel_accept(const unsigned int did, struct map_session_data* sd)
-{
- char output[256];
-
- iDuel->duel_list[did].members_count++;
- sd->duel_group = sd->duel_invite;
- iDuel->duel_list[did].invites_count--;
- sd->duel_invite = 0;
-
- // " -> Player %s has accepted duel --"
- sprintf(output, msg_txt(376), sd->status.name);
- clif->disp_message(&sd->bl, output, strlen(output), DUEL_WOS);
-
- clif->map_property(sd, MAPPROPERTY_FREEPVPZONE);
- clif->maptypeproperty2(&sd->bl,SELF);
-}
-
-void duel_reject(const unsigned int did, struct map_session_data* sd)
-{
- char output[256];
-
- // " -- Player %s has rejected duel --"
- sprintf(output, msg_txt(377), sd->status.name);
- clif->disp_message(&sd->bl, output, strlen(output), DUEL_WOS);
-
- iDuel->duel_list[did].invites_count--;
- sd->duel_invite = 0;
-}
-
-void do_final_duel(void)
-{
-}
-
-void do_init_duel(void)
-{
- memset(&iDuel->duel_list[0], 0, sizeof(iDuel->duel_list));
-}
-
-/*=====================================
-* Default Functions : duel.h
-* Generated by HerculesInterfaceMaker
-* created by Susu
-*-------------------------------------*/
-void iDuel_defaults(void) {
- iDuel = &iDuel_s;
- /* vars */
- iDuel->duel_count = 0;
- /* funcs */
- //Duel functions // [LuzZza]
- iDuel->create = duel_create;
- iDuel->invite = duel_invite;
- iDuel->accept = duel_accept;
- iDuel->reject = duel_reject;
- iDuel->leave = duel_leave;
- iDuel->showinfo = duel_showinfo;
- iDuel->checktime = duel_checktime;
-
- iDuel->do_init_duel = do_init_duel;
- iDuel->do_final_duel = do_final_duel;
-}
+// Copyright (c) Hercules Dev Team, licensed under GNU GPL.
+// See the LICENSE file
+// Portions Copyright (c) Athena Dev Teams
+
+#include "../common/cbasetypes.h"
+
+#include "atcommand.h" // msg_txt
+#include "clif.h"
+#include "duel.h"
+#include "pc.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+/*==========================================
+ * Duel organizing functions [LuzZza]
+ *------------------------------------------*/
+void duel_savetime(struct map_session_data* sd)
+{
+ time_t timer;
+ struct tm *t;
+
+ time(&timer);
+ t = localtime(&timer);
+
+ pc_setglobalreg(sd, "PC_LAST_DUEL_TIME", t->tm_mday*24*60 + t->tm_hour*60 + t->tm_min);
+}
+
+int duel_checktime(struct map_session_data* sd)
+{
+ int diff;
+ time_t timer;
+ struct tm *t;
+
+ time(&timer);
+ t = localtime(&timer);
+
+ diff = t->tm_mday*24*60 + t->tm_hour*60 + t->tm_min - pc_readglobalreg(sd, "PC_LAST_DUEL_TIME");
+
+ return !(diff >= 0 && diff < battle_config.duel_time_interval);
+}
+static int duel_showinfo_sub(struct map_session_data* sd, va_list va)
+{
+ struct map_session_data *ssd = va_arg(va, struct map_session_data*);
+ int *p = va_arg(va, int*);
+ char output[256];
+
+ if (sd->duel_group != ssd->duel_group) return 0;
+
+ sprintf(output, " %d. %s", ++(*p), sd->status.name);
+ clif->disp_onlyself(ssd, output, strlen(output));
+ return 1;
+}
+
+void duel_showinfo(const unsigned int did, struct map_session_data* sd)
+{
+ int p=0;
+ char output[256];
+
+ if(iDuel->duel_list[did].max_players_limit > 0)
+ sprintf(output, msg_txt(370), //" -- Duels: %d/%d, Members: %d/%d, Max players: %d --"
+ did, iDuel->duel_count,
+ iDuel->duel_list[did].members_count,
+ iDuel->duel_list[did].members_count + iDuel->duel_list[did].invites_count,
+ iDuel->duel_list[did].max_players_limit);
+ else
+ sprintf(output, msg_txt(371), //" -- Duels: %d/%d, Members: %d/%d --"
+ did, iDuel->duel_count,
+ iDuel->duel_list[did].members_count,
+ iDuel->duel_list[did].members_count + iDuel->duel_list[did].invites_count);
+
+ clif->disp_onlyself(sd, output, strlen(output));
+ iMap->map_foreachpc(duel_showinfo_sub, sd, &p);
+}
+
+int duel_create(struct map_session_data* sd, const unsigned int maxpl)
+{
+ int i=1;
+ char output[256];
+
+ while(iDuel->duel_list[i].members_count > 0 && i < MAX_DUEL) i++;
+ if(i == MAX_DUEL) return 0;
+
+ iDuel->duel_count++;
+ sd->duel_group = i;
+ iDuel->duel_list[i].members_count++;
+ iDuel->duel_list[i].invites_count = 0;
+ iDuel->duel_list[i].max_players_limit = maxpl;
+
+ strcpy(output, msg_txt(372)); // " -- Duel has been created (@invite/@leave) --"
+ clif->disp_onlyself(sd, output, strlen(output));
+
+ clif->map_property(sd, MAPPROPERTY_FREEPVPZONE);
+ clif->maptypeproperty2(&sd->bl,SELF);
+ return i;
+}
+
+void duel_invite(const unsigned int did, struct map_session_data* sd, struct map_session_data* target_sd)
+{
+ char output[256];
+
+ // " -- Player %s invites %s to duel --"
+ sprintf(output, msg_txt(373), sd->status.name, target_sd->status.name);
+ clif->disp_message(&sd->bl, output, strlen(output), DUEL_WOS);
+
+ target_sd->duel_invite = did;
+ iDuel->duel_list[did].invites_count++;
+
+ // "Blue -- Player %s invites you to PVP duel (@accept/@reject) --"
+ sprintf(output, msg_txt(374), sd->status.name);
+ clif->broadcast((struct block_list *)target_sd, output, strlen(output)+1, BC_BLUE, SELF);
+}
+
+static int duel_leave_sub(struct map_session_data* sd, va_list va)
+{
+ int did = va_arg(va, int);
+ if (sd->duel_invite == did)
+ sd->duel_invite = 0;
+ return 0;
+}
+
+void duel_leave(const unsigned int did, struct map_session_data* sd)
+{
+ char output[256];
+
+ // " <- Player %s has left duel --"
+ sprintf(output, msg_txt(375), sd->status.name);
+ clif->disp_message(&sd->bl, output, strlen(output), DUEL_WOS);
+
+ iDuel->duel_list[did].members_count--;
+
+ if(iDuel->duel_list[did].members_count == 0) {
+ iMap->map_foreachpc(duel_leave_sub, did);
+ iDuel->duel_count--;
+ }
+
+ sd->duel_group = 0;
+ duel_savetime(sd);
+ clif->map_property(sd, MAPPROPERTY_NOTHING);
+ clif->maptypeproperty2(&sd->bl,SELF);
+}
+
+void duel_accept(const unsigned int did, struct map_session_data* sd)
+{
+ char output[256];
+
+ iDuel->duel_list[did].members_count++;
+ sd->duel_group = sd->duel_invite;
+ iDuel->duel_list[did].invites_count--;
+ sd->duel_invite = 0;
+
+ // " -> Player %s has accepted duel --"
+ sprintf(output, msg_txt(376), sd->status.name);
+ clif->disp_message(&sd->bl, output, strlen(output), DUEL_WOS);
+
+ clif->map_property(sd, MAPPROPERTY_FREEPVPZONE);
+ clif->maptypeproperty2(&sd->bl,SELF);
+}
+
+void duel_reject(const unsigned int did, struct map_session_data* sd)
+{
+ char output[256];
+
+ // " -- Player %s has rejected duel --"
+ sprintf(output, msg_txt(377), sd->status.name);
+ clif->disp_message(&sd->bl, output, strlen(output), DUEL_WOS);
+
+ iDuel->duel_list[did].invites_count--;
+ sd->duel_invite = 0;
+}
+
+void do_final_duel(void)
+{
+}
+
+void do_init_duel(void)
+{
+ memset(&iDuel->duel_list[0], 0, sizeof(iDuel->duel_list));
+}
+
+/*=====================================
+* Default Functions : duel.h
+* Generated by HerculesInterfaceMaker
+* created by Susu
+*-------------------------------------*/
+void iDuel_defaults(void) {
+ iDuel = &iDuel_s;
+ /* vars */
+ iDuel->duel_count = 0;
+ /* funcs */
+ //Duel functions // [LuzZza]
+ iDuel->create = duel_create;
+ iDuel->invite = duel_invite;
+ iDuel->accept = duel_accept;
+ iDuel->reject = duel_reject;
+ iDuel->leave = duel_leave;
+ iDuel->showinfo = duel_showinfo;
+ iDuel->checktime = duel_checktime;
+
+ iDuel->do_init_duel = do_init_duel;
+ iDuel->do_final_duel = do_final_duel;
+}
diff --git a/src/map/elemental.c b/src/map/elemental.c
index 03aa93e49..855d9e2c6 100644
--- a/src/map/elemental.c
+++ b/src/map/elemental.c
@@ -1,984 +1,985 @@
-// Copyright (c) Hercules Dev Team, licensed under GNU GPL.
-// See the LICENSE file
-// Portions Copyright (c) Athena Dev Teams
-
-#include "../common/cbasetypes.h"
-#include "../common/malloc.h"
-#include "../common/socket.h"
-#include "../common/timer.h"
-#include "../common/nullpo.h"
-#include "../common/mmo.h"
-#include "../common/showmsg.h"
-#include "../common/utils.h"
-#include "../common/random.h"
-#include "../common/strlib.h"
-
-#include "log.h"
-#include "clif.h"
-#include "chrif.h"
-#include "intif.h"
-#include "itemdb.h"
-#include "map.h"
-#include "pc.h"
-#include "status.h"
-#include "skill.h"
-#include "mob.h"
-#include "pet.h"
-#include "battle.h"
-#include "party.h"
-#include "guild.h"
-#include "atcommand.h"
-#include "script.h"
-#include "npc.h"
-#include "trade.h"
-#include "unit.h"
-#include "elemental.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-
-int elemental_search_index(int class_) {
- int i;
- ARR_FIND(0, MAX_ELEMENTAL_CLASS, i, elemental->elemental_db[i].class_ == class_);
- return (i == MAX_ELEMENTAL_CLASS)?-1:i;
-}
-
-bool elemental_class(int class_) {
- return (bool)(elemental_search_index(class_) > -1);
-}
-
-struct view_data * elemental_get_viewdata(int class_) {
- int i = elemental_search_index(class_);
- if( i < 0 )
- return 0;
-
- return &elemental->elemental_db[i].vd;
-}
-
-int elemental_create(struct map_session_data *sd, int class_, unsigned int lifetime) {
- struct s_elemental ele;
- struct s_elemental_db *db;
- int i;
-
- nullpo_retr(1,sd);
-
- if( (i = elemental_search_index(class_)) < 0 )
- return 0;
-
- db = &elemental->elemental_db[i];
- memset(&ele,0,sizeof(struct s_elemental));
-
- ele.char_id = sd->status.char_id;
- ele.class_ = class_;
- ele.mode = EL_MODE_PASSIVE; // Initial mode
- i = db->status.size+1; // summon level
-
- //[(Casterソスs Max HP/ 3 ) + (Casterソスs INT x 10 )+ (Casterソスs Job Level x 20 )] x [(Elemental Summon Level + 2) / 3]
- ele.hp = ele.max_hp = (sd->battle_status.max_hp/3 + sd->battle_status.int_*10 + sd->status.job_level) * ((i + 2) / 3);
- //Casterソスs Max SP /4
- ele.sp = ele.max_sp = sd->battle_status.max_sp/4;
- //Casterソスs [ Max SP / (18 / Elemental Summon Skill Level) 1- 100 ]
- ele.atk = (sd->battle_status.max_sp / (18 / i) * 1 - 100);
- //Casterソスs [ Max SP / (18 / Elemental Summon Skill Level) ]
- ele.atk2 = sd->battle_status.max_sp / 18;
- //Casterソスs HIT + (Casterソスs Base Level )
- ele.hit = sd->battle_status.hit + sd->status.base_level;
- //[Elemental Summon Skill Level x (Casterソスs INT / 2 + Casterソスs DEX / 4)]
- ele.matk = i * (sd->battle_status.int_ / 2 + sd->battle_status.dex / 4);
- //150 + [Casterソスs DEX / 10] + [Elemental Summon Skill Level x 3 ]
- ele.amotion = 150 + sd->battle_status.dex / 10 + i * 3;
- //Casterソスs DEF + (Casterソスs Base Level / (5 ソス Elemental Summon Skill Level)
- ele.def = sd->battle_status.def + sd->status.base_level / (5-i);
- //Casterソスs MDEF + (Casterソスs INT / (5 - Elemental Summon Skill Level)
- ele.mdef = sd->battle_status.mdef + sd->battle_status.int_ / (5-i);
- //Casterソスs FLEE + (Casterソスs Base Level / (5 ソス Elemental Summon Skill Level)
- ele.flee = sd->status.base_level / (5-i);
- //Casterソスs HIT + (Casterソスs Base Level )
- ele.hit = sd->battle_status.hit + sd->status.base_level;
-
- //per individual bonuses
- switch(db->class_){
- case 2114: case 2115:
- case 2116: //ATK + (Summon Agni Skill Level x 20) / HIT + (Summon Agni Skill Level x 10)
- ele.atk += i * 20;
- ele.atk2 += i * 20;
- ele.hit += i * 10;
- break;
- case 2117: case 2118:
- case 2119: //MDEF + (Summon Aqua Skill Level x 10) / MATK + (Summon Aqua Skill Level x 20)
- ele.mdef += i * 10;
- ele.matk += i * 20;
- break;
- case 2120: case 2121:
- case 2122: //FLEE + (Summon Ventus Skill Level x 20) / MATK + (Summon Ventus Skill Level x 10)
- ele.flee += i * 20;
- ele.matk += i * 10;
- break;
- case 2123: case 2124:
- case 2125: //DEF + (Summon Tera Skill Level x 25) / ATK + (Summon Tera Skill Level x 5)
- ele.def += i * 25;
- ele.atk += i * 5;
- ele.atk2 += i * 5;
- break;
- }
-
- if( (i=pc->checkskill(sd,SO_EL_SYMPATHY)) > 0 ){
- ele.hp = ele.max_hp = ele.max_hp * 5 * i / 100;
- ele.sp = ele.max_sp = ele.max_sp * 5 * i / 100;
- ele.atk += 25 * i;
- ele.atk2 += 25 * i;
- ele.matk += 25 * i;
- }
-
- ele.life_time = lifetime;
-
- // Request Char Server to create this elemental
- intif->elemental_create(&ele);
-
- return 1;
-}
-
-int elemental_get_lifetime(struct elemental_data *ed) {
- const struct TimerData * td;
- if( ed == NULL || ed->summon_timer == INVALID_TIMER )
- return 0;
-
- td = iTimer->get_timer(ed->summon_timer);
- return (td != NULL) ? DIFF_TICK(td->tick, iTimer->gettick()) : 0;
-}
-
-int elemental_save(struct elemental_data *ed) {
- ed->elemental.mode = ed->battle_status.mode;
- ed->elemental.hp = ed->battle_status.hp;
- ed->elemental.sp = ed->battle_status.sp;
- ed->elemental.max_hp = ed->battle_status.max_hp;
- ed->elemental.max_sp = ed->battle_status.max_sp;
- ed->elemental.atk = ed->battle_status.rhw.atk;
- ed->elemental.atk2 = ed->battle_status.rhw.atk2;
- ed->elemental.matk = ed->battle_status.matk_min;
- ed->elemental.def = ed->battle_status.def;
- ed->elemental.mdef = ed->battle_status.mdef;
- ed->elemental.flee = ed->battle_status.flee;
- ed->elemental.hit = ed->battle_status.hit;
- ed->elemental.life_time = elemental->get_lifetime(ed);
- intif->elemental_save(&ed->elemental);
- return 1;
-}
-
-static int elemental_summon_end(int tid, unsigned int tick, int id, intptr_t data) {
- struct map_session_data *sd;
- struct elemental_data *ed;
-
- if( (sd = iMap->id2sd(id)) == NULL )
- return 1;
- if( (ed = sd->ed) == NULL )
- return 1;
-
- if( ed->summon_timer != tid ) {
- ShowError("elemental_summon_end %d != %d.\n", ed->summon_timer, tid);
- return 0;
- }
-
- ed->summon_timer = INVALID_TIMER;
- elemental->delete(ed, 0); // Elemental's summon time is over.
-
- return 0;
-}
-
-void elemental_summon_stop(struct elemental_data *ed) {
- nullpo_retv(ed);
- if( ed->summon_timer != INVALID_TIMER )
- iTimer->delete_timer(ed->summon_timer, elemental_summon_end);
- ed->summon_timer = INVALID_TIMER;
-}
-
-int elemental_delete(struct elemental_data *ed, int reply) {
- struct map_session_data *sd;
- nullpo_ret(ed);
-
- sd = ed->master;
- ed->elemental.life_time = 0;
-
- elemental->clean_effect(ed);
- elemental->summon_stop(ed);
-
- if( !sd )
- return unit_free(&ed->bl, 0);
-
- sd->ed = NULL;
- sd->status.ele_id = 0;
-
- return unit_remove_map(&ed->bl, 0);
-}
-
-void elemental_summon_init(struct elemental_data *ed) {
- if( ed->summon_timer == INVALID_TIMER )
- ed->summon_timer = iTimer->add_timer(iTimer->gettick() + ed->elemental.life_time, elemental_summon_end, ed->master->bl.id, 0);
-
- ed->regen.state.block = 0;
-}
-
-int elemental_data_received(struct s_elemental *ele, bool flag) {
- struct map_session_data *sd;
- struct elemental_data *ed;
- struct s_elemental_db *db;
- int i = elemental_search_index(ele->class_);
-
- if( (sd = iMap->charid2sd(ele->char_id)) == NULL )
- return 0;
-
- if( !flag || i < 0 ) { // Not created - loaded - DB info
- sd->status.ele_id = 0;
- return 0;
- }
-
- db = &elemental->elemental_db[i];
- 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->master = sd;
- ed->db = db;
- memcpy(&ed->elemental, ele, sizeof(struct s_elemental));
- iStatus->set_viewdata(&ed->bl, ed->elemental.class_);
- ed->vd->head_mid = 10; // Why?
- iStatus->change_init(&ed->bl);
- unit_dataset(&ed->bl);
- ed->ud.dir = sd->ud.dir;
-
- ed->bl.m = sd->bl.m;
- ed->bl.x = sd->bl.x;
- ed->bl.y = sd->bl.y;
- unit_calc_pos(&ed->bl, sd->bl.x, sd->bl.y, sd->ud.dir);
- ed->bl.x = ed->ud.to_x;
- ed->bl.y = ed->ud.to_y;
-
- iMap->addiddb(&ed->bl);
- status_calc_elemental(ed,1);
- ed->last_spdrain_time = ed->last_thinktime = iTimer->gettick();
- ed->summon_timer = INVALID_TIMER;
- elemental_summon_init(ed);
- } else {
- memcpy(&sd->ed->elemental, ele, sizeof(struct s_elemental));
- ed = sd->ed;
- }
-
- sd->status.ele_id = ele->elemental_id;
-
- if( ed->bl.prev == NULL && sd->bl.prev != NULL ) {
- iMap->addblock(&ed->bl);
- clif->spawn(&ed->bl);
- clif->elemental_info(sd);
- clif->elemental_updatestatus(sd,SP_HP);
- clif->hpmeter_single(sd->fd,ed->bl.id,ed->battle_status.hp,ed->battle_status.max_hp);
- clif->elemental_updatestatus(sd,SP_SP);
- }
-
- return 1;
-}
-
-int elemental_clean_single_effect(struct elemental_data *ed, uint16 skill_id) {
- struct block_list *bl;
- sc_type type = iStatus->skill2sc(skill_id);
-
- nullpo_ret(ed);
-
- bl = battle->get_master(&ed->bl);
-
- if( type ) {
- switch( type ) {
- // Just remove status change.
- case SC_PYROTECHNIC_OPTION:
- case SC_HEATER_OPTION:
- case SC_TROPIC_OPTION:
- case SC_FIRE_CLOAK_OPTION:
- case SC_AQUAPLAY_OPTION:
- case SC_WATER_SCREEN_OPTION:
- case SC_COOLER_OPTION:
- case SC_CHILLY_AIR_OPTION:
- case SC_GUST_OPTION:
- case SC_WIND_STEP_OPTION:
- case SC_BLAST_OPTION:
- case SC_WATER_DROP_OPTION:
- case SC_WIND_CURTAIN_OPTION:
- case SC_WILD_STORM_OPTION:
- case SC_PETROLOGY_OPTION:
- case SC_SOLID_SKIN_OPTION:
- case SC_CURSED_SOIL_OPTION:
- case SC_STONE_SHIELD_OPTION:
- case SC_UPHEAVAL_OPTION:
- case SC_CIRCLE_OF_FIRE_OPTION:
- case SC_TIDAL_WEAPON_OPTION:
- if( bl ) status_change_end(bl,type,INVALID_TIMER); // Master
- status_change_end(&ed->bl,type-1,INVALID_TIMER); // Elemental Spirit
- break;
- case SC_ZEPHYR:
- if( bl ) status_change_end(bl,type,INVALID_TIMER);
- break;
- default:
- ShowWarning("Invalid SC=%d in elemental_clean_single_effect\n",type);
- break;
- }
- }
-
- return 1;
-}
-
-int elemental_clean_effect(struct elemental_data *ed) {
- struct map_session_data *sd;
-
- nullpo_ret(ed);
-
- // Elemental side
- status_change_end(&ed->bl, SC_TROPIC, INVALID_TIMER);
- status_change_end(&ed->bl, SC_HEATER, INVALID_TIMER);
- status_change_end(&ed->bl, SC_AQUAPLAY, INVALID_TIMER);
- status_change_end(&ed->bl, SC_COOLER, INVALID_TIMER);
- status_change_end(&ed->bl, SC_CHILLY_AIR, INVALID_TIMER);
- status_change_end(&ed->bl, SC_PYROTECHNIC, INVALID_TIMER);
- status_change_end(&ed->bl, SC_FIRE_CLOAK, INVALID_TIMER);
- status_change_end(&ed->bl, SC_WATER_DROP, INVALID_TIMER);
- status_change_end(&ed->bl, SC_WATER_SCREEN, INVALID_TIMER);
- status_change_end(&ed->bl, SC_GUST, INVALID_TIMER);
- status_change_end(&ed->bl, SC_WIND_STEP, INVALID_TIMER);
- status_change_end(&ed->bl, SC_BLAST, INVALID_TIMER);
- status_change_end(&ed->bl, SC_WIND_CURTAIN, INVALID_TIMER);
- status_change_end(&ed->bl, SC_WILD_STORM, INVALID_TIMER);
- status_change_end(&ed->bl, SC_PETROLOGY, INVALID_TIMER);
- status_change_end(&ed->bl, SC_SOLID_SKIN, INVALID_TIMER);
- status_change_end(&ed->bl, SC_CURSED_SOIL, INVALID_TIMER);
- status_change_end(&ed->bl, SC_STONE_SHIELD, INVALID_TIMER);
- status_change_end(&ed->bl, SC_UPHEAVAL, INVALID_TIMER);
- status_change_end(&ed->bl, SC_CIRCLE_OF_FIRE, INVALID_TIMER);
- status_change_end(&ed->bl, SC_TIDAL_WEAPON, INVALID_TIMER);
-
- if( (sd = ed->master) == NULL )
- return 0;
-
- // Master side
- status_change_end(&sd->bl, SC_TROPIC_OPTION, INVALID_TIMER);
- status_change_end(&sd->bl, SC_HEATER_OPTION, INVALID_TIMER);
- status_change_end(&sd->bl, SC_AQUAPLAY_OPTION, INVALID_TIMER);
- status_change_end(&sd->bl, SC_COOLER_OPTION, INVALID_TIMER);
- status_change_end(&sd->bl, SC_CHILLY_AIR_OPTION, INVALID_TIMER);
- status_change_end(&sd->bl, SC_PYROTECHNIC_OPTION, INVALID_TIMER);
- status_change_end(&sd->bl, SC_FIRE_CLOAK_OPTION, INVALID_TIMER);
- status_change_end(&sd->bl, SC_WATER_DROP_OPTION, INVALID_TIMER);
- status_change_end(&sd->bl, SC_WATER_SCREEN_OPTION, INVALID_TIMER);
- status_change_end(&sd->bl, SC_GUST_OPTION, INVALID_TIMER);
- status_change_end(&sd->bl, SC_WIND_STEP_OPTION, INVALID_TIMER);
- status_change_end(&sd->bl, SC_BLAST_OPTION, INVALID_TIMER);
- status_change_end(&sd->bl, SC_WATER_DROP_OPTION, INVALID_TIMER);
- status_change_end(&sd->bl, SC_WIND_CURTAIN_OPTION, INVALID_TIMER);
- status_change_end(&sd->bl, SC_WILD_STORM_OPTION, INVALID_TIMER);
- status_change_end(&sd->bl, SC_ZEPHYR, INVALID_TIMER);
- status_change_end(&sd->bl, SC_WIND_STEP_OPTION, INVALID_TIMER);
- status_change_end(&sd->bl, SC_PETROLOGY_OPTION, INVALID_TIMER);
- status_change_end(&sd->bl, SC_SOLID_SKIN_OPTION, INVALID_TIMER);
- status_change_end(&sd->bl, SC_CURSED_SOIL_OPTION, INVALID_TIMER);
- status_change_end(&sd->bl, SC_STONE_SHIELD_OPTION, INVALID_TIMER);
- status_change_end(&sd->bl, SC_UPHEAVAL_OPTION, INVALID_TIMER);
- status_change_end(&sd->bl, SC_CIRCLE_OF_FIRE_OPTION, INVALID_TIMER);
- status_change_end(&sd->bl, SC_TIDAL_WEAPON_OPTION, INVALID_TIMER);
-
- return 1;
-}
-
-int elemental_action(struct elemental_data *ed, struct block_list *bl, unsigned int tick) {
- struct skill_condition req;
- uint16 skill_id, skill_lv;
- int i;
-
- nullpo_ret(ed);
- nullpo_ret(bl);
-
- if( !ed->master )
- return 0;
-
- if( ed->target_id )
- elemental->unlocktarget(ed); // Remove previous target.
-
- ARR_FIND(0, MAX_ELESKILLTREE, i, ed->db->skill[i].id && (ed->db->skill[i].mode&EL_SKILLMODE_AGGRESSIVE));
- if( i == MAX_ELESKILLTREE )
- return 0;
-
- skill_id = ed->db->skill[i].id;
- skill_lv = ed->db->skill[i].lv;
-
- if( elemental->skillnotok(skill_id, ed) )
- return 0;
-
- if( ed->ud.skilltimer != INVALID_TIMER )
- return 0;
- else if( DIFF_TICK(tick, ed->ud.canact_tick) < 0 )
- return 0;
-
- ed->target_id = ed->ud.skilltarget = bl->id; // Set new target
- ed->last_thinktime = tick;
-
- // Not in skill range.
- if( !battle->check_range(&ed->bl,bl,skill->get_range(skill_id,skill_lv)) ) {
- // Try to walk to the target.
- if( !unit_walktobl(&ed->bl, bl, skill->get_range(skill_id,skill_lv), 2) )
- elemental->unlocktarget(ed);
- else {
- // Walking, waiting to be in range. Client don't handle it, then we must handle it here.
- int walk_dist = distance_bl(&ed->bl,bl) - skill->get_range(skill_id,skill_lv);
- ed->ud.skill_id = skill_id;
- ed->ud.skill_lv = skill_lv;
-
- if( skill->get_inf(skill_id) & INF_GROUND_SKILL )
- ed->ud.skilltimer = iTimer->add_timer( tick+iStatus->get_speed(&ed->bl)*walk_dist, skill->castend_pos, ed->bl.id, 0 );
- else
- ed->ud.skilltimer = iTimer->add_timer( tick+iStatus->get_speed(&ed->bl)*walk_dist, skill->castend_id, ed->bl.id, 0 );
- }
- return 1;
-
- }
-
- req = elemental->skill_get_requirements(skill_id, skill_lv);
-
- if(req.hp || req.sp){
- struct map_session_data *sd = BL_CAST(BL_PC, battle->get_master(&ed->bl));
- if( sd ){
- if( sd->skill_id_old != SO_EL_ACTION && //regardless of remaining HP/SP it can be cast
- (status_get_hp(&ed->bl) < req.hp || status_get_sp(&ed->bl) < req.sp) )
- return 1;
- else
- status_zap(&ed->bl, req.hp, req.sp);
- }
- }
-
- //Otherwise, just cast the skill.
- if( skill->get_inf(skill_id) & INF_GROUND_SKILL )
- unit_skilluse_pos(&ed->bl, bl->x, bl->y, skill_id, skill_lv);
- else
- unit_skilluse_id(&ed->bl, bl->id, skill_id, skill_lv);
-
- // Reset target.
- ed->target_id = 0;
-
- return 1;
-}
-
-/*===============================================================
- * Action that elemental perform after changing mode.
- * Activates one of the skills of the new mode.
- *-------------------------------------------------------------*/
-int elemental_change_mode_ack(struct elemental_data *ed, int mode) {
- struct block_list *bl = &ed->master->bl;
- uint16 skill_id, skill_lv;
- int i;
-
- nullpo_ret(ed);
-
- if( !bl )
- return 0;
-
- // Select a skill.
- ARR_FIND(0, MAX_ELESKILLTREE, i, ed->db->skill[i].id && (ed->db->skill[i].mode&mode));
- if( i == MAX_ELESKILLTREE )
- return 0;
-
- skill_id = ed->db->skill[i].id;
- skill_lv = ed->db->skill[i].lv;
-
- if( elemental->skillnotok(skill_id, ed) )
- return 0;
-
- if( ed->ud.skilltimer != INVALID_TIMER )
- return 0;
- else if( DIFF_TICK(iTimer->gettick(), ed->ud.canact_tick) < 0 )
- return 0;
-
- ed->target_id = bl->id; // Set new target
- ed->last_thinktime = iTimer->gettick();
-
- if( skill->get_inf(skill_id) & INF_GROUND_SKILL )
- unit_skilluse_pos(&ed->bl, bl->x, bl->y, skill_id, skill_lv);
- else
- unit_skilluse_id(&ed->bl,bl->id,skill_id,skill_lv);
-
- ed->target_id = 0; // Reset target after casting the skill to avoid continious attack.
-
- return 1;
-}
-
-/*===============================================================
- * Change elemental mode.
- *-------------------------------------------------------------*/
-int elemental_change_mode(struct elemental_data *ed, int mode) {
- nullpo_ret(ed);
-
- // Remove target
- elemental->unlocktarget(ed);
-
- // Removes the effects of the previous mode.
- if(ed->elemental.mode != mode ) elemental->clean_effect(ed);
-
- ed->battle_status.mode = ed->elemental.mode = mode;
-
- // Normalize elemental mode to elemental skill mode.
- if( mode == EL_MODE_AGGRESSIVE ) mode = EL_SKILLMODE_AGGRESSIVE; // Aggressive spirit mode -> Aggressive spirit skill.
- else if( mode == EL_MODE_ASSIST ) mode = EL_SKILLMODE_ASSIST; // Assist spirit mode -> Assist spirit skill.
- else mode = EL_SKILLMODE_PASIVE; // Passive spirit mode -> Passive spirit skill.
-
- // Use a skill inmediately after every change mode.
- if( mode != EL_SKILLMODE_AGGRESSIVE )
- elemental->change_mode_ack(ed,mode);
- return 1;
-}
-
-void elemental_heal(struct elemental_data *ed, int hp, int sp) {
- if( hp )
- clif->elemental_updatestatus(ed->master, SP_HP);
- if( sp )
- clif->elemental_updatestatus(ed->master, SP_SP);
-}
-
-int elemental_dead(struct elemental_data *ed) {
- elemental->delete(ed, 1);
- return 0;
-}
-
-int elemental_unlocktarget(struct elemental_data *ed) {
- nullpo_ret(ed);
-
- ed->target_id = 0;
- elemental_stop_attack(ed);
- elemental_stop_walking(ed,1);
- return 0;
-}
-
-int elemental_skillnotok(uint16 skill_id, struct elemental_data *ed) {
- int idx = skill->get_index(skill_id);
- nullpo_retr(1,ed);
-
- if (idx == 0)
- return 1; // invalid skill id
-
- return skill->not_ok(skill_id, ed->master);
-}
-
-struct skill_condition elemental_skill_get_requirements(uint16 skill_id, uint16 skill_lv){
- struct skill_condition req;
- int idx = skill->get_index(skill_id);
-
- memset(&req,0,sizeof(req));
-
- if( idx == 0 ) // invalid skill id
- return req;
-
- if( skill_lv < 1 || skill_lv > MAX_SKILL_LEVEL )
- return req;
-
- req.hp = skill_db[idx].hp[skill_lv-1];
- req.sp = skill_db[idx].sp[skill_lv-1];
-
- return req;
-}
-
-int elemental_set_target( struct map_session_data *sd, struct block_list *bl ) {
- struct elemental_data *ed = sd->ed;
-
- nullpo_ret(ed);
- nullpo_ret(bl);
-
- if( ed->bl.m != bl->m || !check_distance_bl(&ed->bl, bl, ed->db->range2) )
- return 0;
-
- if( !iStatus->check_skilluse(&ed->bl, bl, 0, 0) )
- return 0;
-
- if( ed->target_id == 0 )
- ed->target_id = bl->id;
-
- return 1;
-}
-
-static int elemental_ai_sub_timer_activesearch(struct block_list *bl, va_list ap) {
- struct elemental_data *ed;
- struct block_list **target;
- int dist;
-
- nullpo_ret(bl);
-
- ed = va_arg(ap,struct elemental_data *);
- target = va_arg(ap,struct block_list**);
-
- //If can't seek yet, not an enemy, or you can't attack it, skip.
- if( (*target) == bl || !iStatus->check_skilluse(&ed->bl, bl, 0, 0) )
- return 0;
-
- if( battle->check_target(&ed->bl,bl,BCT_ENEMY) <= 0 )
- return 0;
-
- switch( bl->type ) {
- case BL_PC:
- if( !map_flag_vs(ed->bl.m) )
- return 0;
- default:
- dist = distance_bl(&ed->bl, bl);
- if( ((*target) == NULL || !check_distance_bl(&ed->bl, *target, dist)) && battle->check_range(&ed->bl,bl,ed->db->range2) ) { //Pick closest target?
- (*target) = bl;
- ed->target_id = bl->id;
- ed->min_chase = dist + ed->db->range3;
- if( ed->min_chase > AREA_SIZE )
- ed->min_chase = AREA_SIZE;
- return 1;
- }
- break;
- }
- return 0;
-}
-
-static int elemental_ai_sub_timer(struct elemental_data *ed, struct map_session_data *sd, unsigned int tick) {
- struct block_list *target = NULL;
- int master_dist, view_range, mode;
-
- nullpo_ret(ed);
- nullpo_ret(sd);
-
- if( ed->bl.prev == NULL || sd == NULL || sd->bl.prev == NULL )
- return 0;
-
- // Check if caster can sustain the summoned elemental
- if( DIFF_TICK(tick,ed->last_spdrain_time) >= 10000 ){// Drain SP every 10 seconds
- int sp = 5;
-
- switch(ed->vd->class_){
- case 2115: case 2118:
- case 2121: case 2124:
- sp = 8;
- break;
- case 2116: case 2119:
- case 2122: case 2125:
- sp = 11;
- break;
- }
-
- if( status_get_sp(&sd->bl) < sp ){ // Can't sustain delete it.
- elemental->delete(sd->ed,0);
- return 0;
- }
-
- status_zap(&sd->bl,0,sp);
- ed->last_spdrain_time = tick;
- }
-
- if( DIFF_TICK(tick,ed->last_thinktime) < MIN_ELETHINKTIME )
- return 0;
-
- ed->last_thinktime = tick;
-
- if( ed->ud.skilltimer != INVALID_TIMER )
- return 0;
-
- if( ed->ud.walktimer != INVALID_TIMER && ed->ud.walkpath.path_pos <= 2 )
- return 0; //No thinking when you just started to walk.
-
- if(ed->ud.walkpath.path_pos < ed->ud.walkpath.path_len && ed->ud.target == sd->bl.id)
- return 0; //No thinking until be near the master.
-
- if( ed->sc.count && ed->sc.data[SC_BLIND] )
- view_range = 3;
- else
- view_range = ed->db->range2;
-
- mode = status_get_mode(&ed->bl);
-
- master_dist = distance_bl(&sd->bl, &ed->bl);
- if( master_dist > AREA_SIZE ) { // Master out of vision range.
- elemental->unlocktarget(ed);
- unit_warp(&ed->bl,sd->bl.m,sd->bl.x,sd->bl.y,CLR_TELEPORT);
- clif->elemental_updatestatus(sd,SP_HP);
- clif->elemental_updatestatus(sd,SP_SP);
- return 0;
- } else if( master_dist > MAX_ELEDISTANCE ) { // Master too far, chase.
- short x = sd->bl.x, y = sd->bl.y;
- if( ed->target_id )
- elemental->unlocktarget(ed);
- if( ed->ud.walktimer != INVALID_TIMER && ed->ud.target == sd->bl.id )
- return 0; //Already walking to him
- if( DIFF_TICK(tick, ed->ud.canmove_tick) < 0 )
- return 0; //Can't move yet.
- if( iMap->search_freecell(&ed->bl, sd->bl.m, &x, &y, MIN_ELEDISTANCE, MIN_ELEDISTANCE, 1)
- && unit_walktoxy(&ed->bl, x, y, 0) )
- return 0;
- }
-
- if( mode == EL_MODE_AGGRESSIVE ) {
- target = iMap->id2bl(ed->ud.target);
-
- if( !target )
- iMap->foreachinrange(elemental_ai_sub_timer_activesearch, &ed->bl, view_range, BL_CHAR, ed, &target, status_get_mode(&ed->bl));
-
- if( !target ) { //No targets available.
- elemental->unlocktarget(ed);
- return 1;
- }
-
- if( battle->check_range(&ed->bl,target,view_range) && rnd()%100 < 2 ) { // 2% chance to cast attack skill.
- if( elemental->action(ed,target,tick) )
- return 1;
- }
-
- //Attempt to attack.
- //At this point we know the target is attackable, we just gotta check if the range matches.
- if( ed->ud.target == target->id && ed->ud.attacktimer != INVALID_TIMER ) //Already locked.
- return 1;
-
- if( battle->check_range(&ed->bl, target, ed->base_status.rhw.range) ) {//Target within range, engage
- unit_attack(&ed->bl,target->id,1);
- return 1;
- }
-
- //Follow up if possible.
- if( !unit_walktobl(&ed->bl, target, ed->base_status.rhw.range, 2) )
- elemental->unlocktarget(ed);
- }
-
- return 0;
-}
-
-static int elemental_ai_sub_foreachclient(struct map_session_data *sd, va_list ap) {
- unsigned int tick = va_arg(ap,unsigned int);
- if(sd->status.ele_id && sd->ed)
- elemental_ai_sub_timer(sd->ed,sd,tick);
-
- return 0;
-}
-
-static int elemental_ai_timer(int tid, unsigned int tick, int id, intptr_t data) {
- iMap->map_foreachpc(elemental_ai_sub_foreachclient,tick);
- return 0;
-}
-
-int read_elementaldb(void) {
- FILE *fp;
- char line[1024], *p;
- char *str[26];
- int i, j = 0, k = 0, ele;
- struct s_elemental_db *db;
- struct status_data *status;
-
- sprintf(line, "%s/%s", iMap->db_path, "elemental_db.txt");
- memset(elemental->elemental_db,0,sizeof(elemental->elemental_db));
-
- fp = fopen(line, "r");
- if( !fp ) {
- ShowError("read_elementaldb : can't read elemental_db.txt\n");
- return -1;
- }
-
- while( fgets(line, sizeof(line), fp) && j < MAX_ELEMENTAL_CLASS ) {
- k++;
- if( line[0] == '/' && line[1] == '/' )
- continue;
-
- if( line[0] == '\0' || line[0] == '\n' || line[0] == '\r')
- continue;
-
- i = 0;
- p = strtok(line, ",");
- while( p != NULL && i < 26 ) {
- str[i++] = p;
- p = strtok(NULL, ",");
- }
- if( i < 26 ) {
- ShowError("read_elementaldb : Incorrect number of columns at elemental_db.txt line %d.\n", k);
- continue;
- }
-
- db = &elemental->elemental_db[j];
- db->class_ = atoi(str[0]);
- safestrncpy(db->sprite, str[1], NAME_LENGTH);
- safestrncpy(db->name, str[2], NAME_LENGTH);
- db->lv = atoi(str[3]);
-
- status = &db->status;
- db->vd.class_ = db->class_;
-
- status->max_hp = atoi(str[4]);
- status->max_sp = atoi(str[5]);
- status->rhw.range = atoi(str[6]);
- status->rhw.atk = atoi(str[7]);
- status->rhw.atk2 = atoi(str[8]);
- status->def = atoi(str[9]);
- status->mdef = atoi(str[10]);
- status->str = atoi(str[11]);
- status->agi = atoi(str[12]);
- status->vit = atoi(str[13]);
- status->int_ = atoi(str[14]);
- status->dex = atoi(str[15]);
- status->luk = atoi(str[16]);
- db->range2 = atoi(str[17]);
- db->range3 = atoi(str[18]);
- status->size = atoi(str[19]);
- status->race = atoi(str[20]);
-
- ele = atoi(str[21]);
- status->def_ele = ele%10;
- status->ele_lv = ele/20;
- if( status->def_ele >= ELE_MAX ) {
- ShowWarning("Elemental %d has invalid element type %d (max element is %d)\n", db->class_, status->def_ele, ELE_MAX - 1);
- status->def_ele = ELE_NEUTRAL;
- }
- if( status->ele_lv < 1 || status->ele_lv > 4 ) {
- ShowWarning("Elemental %d has invalid element level %d (max is 4)\n", db->class_, status->ele_lv);
- status->ele_lv = 1;
- }
-
- status->aspd_rate = 1000;
- status->speed = atoi(str[22]);
- status->adelay = atoi(str[23]);
- status->amotion = atoi(str[24]);
- status->dmotion = atoi(str[25]);
-
- j++;
- }
-
- fclose(fp);
- ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' elementals in '"CL_WHITE"db/elemental_db.txt"CL_RESET"'.\n",j);
-
- return 0;
-}
-
-int read_elemental_skilldb(void) {
- FILE *fp;
- char line[1024], *p;
- char *str[4];
- struct s_elemental_db *db;
- int i, j = 0, k = 0, class_;
- uint16 skill_id, skill_lv;
- int skillmode;
-
- sprintf(line, "%s/%s", iMap->db_path, "elemental_skill_db.txt");
- fp = fopen(line, "r");
- if( !fp ) {
- ShowError("read_elemental_skilldb : can't read elemental_skill_db.txt\n");
- return -1;
- }
-
- while( fgets(line, sizeof(line), fp) ) {
- k++;
- if( line[0] == '/' && line[1] == '/' )
- continue;
-
- if( line[0] == '\0' || line[0] == '\n' || line[0] == '\r')
- continue;
-
- i = 0;
- p = strtok(line, ",");
- while( p != NULL && i < 4 ) {
- str[i++] = p;
- p = strtok(NULL, ",");
- }
- if( i < 4 ) {
- ShowError("read_elemental_skilldb : Incorrect number of columns at elemental_skill_db.txt line %d.\n", k);
- continue;
- }
-
- class_ = atoi(str[0]);
- ARR_FIND(0, MAX_ELEMENTAL_CLASS, i, class_ == elemental->elemental_db[i].class_);
- if( i == MAX_ELEMENTAL_CLASS ) {
- ShowError("read_elemental_skilldb : Class not found in elemental_db for skill entry, line %d.\n", k);
- continue;
- }
-
- skill_id = atoi(str[1]);
- if( skill_id < EL_SKILLBASE || skill_id >= EL_SKILLBASE + MAX_ELEMENTALSKILL ) {
- ShowError("read_elemental_skilldb : Skill out of range, line %d.\n", k);
- continue;
- }
-
- db = &elemental->elemental_db[i];
- skill_lv = atoi(str[2]);
-
- skillmode = atoi(str[3]);
- if( skillmode < EL_SKILLMODE_PASIVE || skillmode > EL_SKILLMODE_AGGRESSIVE ) {
- ShowError("read_elemental_skilldb : Skillmode out of range, line %d.\n",k);
- continue;
- }
- ARR_FIND( 0, MAX_ELESKILLTREE, i, db->skill[i].id == 0 || db->skill[i].id == skill_id );
- if( i == MAX_ELESKILLTREE ) {
- ShowWarning("Unable to load skill %d into Elemental %d's tree. Maximum number of skills per elemental has been reached.\n", skill_id, class_);
- continue;
- }
- db->skill[i].id = skill_id;
- db->skill[i].lv = skill_lv;
- db->skill[i].mode = skillmode;
- j++;
- }
-
- fclose(fp);
- ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"db/elemental_skill_db.txt"CL_RESET"'.\n",j);
- return 0;
-}
-
-void reload_elementaldb(void) {
- read_elementaldb();
- elemental->reload_skilldb();
-}
-
-void reload_elemental_skilldb(void) {
- elemental->read_skilldb();
-}
-
-int do_init_elemental(void) {
- read_elementaldb();
- elemental->read_skilldb();
-
- iTimer->add_timer_func_list(elemental_ai_timer,"elemental_ai_timer");
- iTimer->add_timer_interval(iTimer->gettick()+MIN_ELETHINKTIME,elemental_ai_timer,0,0,MIN_ELETHINKTIME);
-
- return 0;
-}
-
-void do_final_elemental(void) {
- return;
-}
-
-/*=====================================
-* Default Functions : elemental.h
-* Generated by HerculesInterfaceMaker
-* created by Susu
-*-------------------------------------*/
-void elemental_defaults(void) {
- elemental = &elemental_s;
- /* funcs */
-
- elemental->class = elemental_class;
- elemental->get_viewdata = elemental_get_viewdata;
-
- elemental->create = elemental_create;
- elemental->data_received = elemental_data_received;
- elemental->save = elemental_save;
-
- elemental->change_mode_ack = elemental_change_mode_ack;
- elemental->change_mode = elemental_change_mode;
-
- elemental->heal = elemental_heal;
- elemental->dead = elemental_dead;
-
- elemental->delete = elemental_delete;
- elemental->summon_stop = elemental_summon_stop;
-
- elemental->get_lifetime = elemental_get_lifetime;
-
- elemental->unlocktarget = elemental_unlocktarget;
- elemental->skillnotok = elemental_skillnotok;
- elemental->set_target = elemental_set_target;
- elemental->clean_single_effect = elemental_clean_single_effect;
- elemental->clean_effect = elemental_clean_effect;
- elemental->action = elemental_action;
- elemental->skill_get_requirements = elemental_skill_get_requirements;
-
- elemental->read_skilldb = read_elemental_skilldb;
- elemental->reload_elementaldb = reload_elementaldb;
- elemental->reload_skilldb = reload_elemental_skilldb;
- elemental->do_init_elemental = do_init_elemental;
- elemental->do_final_elemental = do_final_elemental;
-}
+// Copyright (c) Hercules Dev Team, licensed under GNU GPL.
+// See the LICENSE file
+// Portions Copyright (c) Athena Dev Teams
+
+#include "../common/cbasetypes.h"
+#include "../common/malloc.h"
+#include "../common/socket.h"
+#include "../common/timer.h"
+#include "../common/nullpo.h"
+#include "../common/mmo.h"
+#include "../common/showmsg.h"
+#include "../common/utils.h"
+#include "../common/random.h"
+#include "../common/strlib.h"
+
+#include "log.h"
+#include "clif.h"
+#include "chrif.h"
+#include "intif.h"
+#include "itemdb.h"
+#include "map.h"
+#include "pc.h"
+#include "status.h"
+#include "skill.h"
+#include "mob.h"
+#include "pet.h"
+#include "battle.h"
+#include "party.h"
+#include "guild.h"
+#include "atcommand.h"
+#include "script.h"
+#include "npc.h"
+#include "trade.h"
+#include "unit.h"
+#include "elemental.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+
+int elemental_search_index(int class_) {
+ int i;
+ ARR_FIND(0, MAX_ELEMENTAL_CLASS, i, elemental->elemental_db[i].class_ == class_);
+ return (i == MAX_ELEMENTAL_CLASS)?-1:i;
+}
+
+bool elemental_class(int class_) {
+ return (bool)(elemental_search_index(class_) > -1);
+}
+
+struct view_data * elemental_get_viewdata(int class_) {
+ int i = elemental_search_index(class_);
+ if( i < 0 )
+ return 0;
+
+ return &elemental->elemental_db[i].vd;
+}
+
+int elemental_create(struct map_session_data *sd, int class_, unsigned int lifetime) {
+ struct s_elemental ele;
+ struct s_elemental_db *db;
+ int i;
+
+ nullpo_retr(1,sd);
+
+ if( (i = elemental_search_index(class_)) < 0 )
+ return 0;
+
+ db = &elemental->elemental_db[i];
+ memset(&ele,0,sizeof(struct s_elemental));
+
+ ele.char_id = sd->status.char_id;
+ ele.class_ = class_;
+ ele.mode = EL_MODE_PASSIVE; // Initial mode
+ i = db->status.size+1; // summon level
+
+ //[(Casterソスs Max HP/ 3 ) + (Casterソスs INT x 10 )+ (Casterソスs Job Level x 20 )] x [(Elemental Summon Level + 2) / 3]
+ ele.hp = ele.max_hp = (sd->battle_status.max_hp/3 + sd->battle_status.int_*10 + sd->status.job_level) * ((i + 2) / 3);
+ //Casterソスs Max SP /4
+ ele.sp = ele.max_sp = sd->battle_status.max_sp/4;
+ //Casterソスs [ Max SP / (18 / Elemental Summon Skill Level) 1- 100 ]
+ ele.atk = (sd->battle_status.max_sp / (18 / i) * 1 - 100);
+ //Casterソスs [ Max SP / (18 / Elemental Summon Skill Level) ]
+ ele.atk2 = sd->battle_status.max_sp / 18;
+ //Casterソスs HIT + (Casterソスs Base Level )
+ ele.hit = sd->battle_status.hit + sd->status.base_level;
+ //[Elemental Summon Skill Level x (Casterソスs INT / 2 + Casterソスs DEX / 4)]
+ ele.matk = i * (sd->battle_status.int_ / 2 + sd->battle_status.dex / 4);
+ //150 + [Casterソスs DEX / 10] + [Elemental Summon Skill Level x 3 ]
+ ele.amotion = 150 + sd->battle_status.dex / 10 + i * 3;
+ //Casterソスs DEF + (Casterソスs Base Level / (5 ソス Elemental Summon Skill Level)
+ ele.def = sd->battle_status.def + sd->status.base_level / (5-i);
+ //Casterソスs MDEF + (Casterソスs INT / (5 - Elemental Summon Skill Level)
+ ele.mdef = sd->battle_status.mdef + sd->battle_status.int_ / (5-i);
+ //Casterソスs FLEE + (Casterソスs Base Level / (5 ソス Elemental Summon Skill Level)
+ ele.flee = sd->status.base_level / (5-i);
+ //Casterソスs HIT + (Casterソスs Base Level )
+ ele.hit = sd->battle_status.hit + sd->status.base_level;
+
+ //per individual bonuses
+ switch(db->class_){
+ case 2114: case 2115:
+ case 2116: //ATK + (Summon Agni Skill Level x 20) / HIT + (Summon Agni Skill Level x 10)
+ ele.atk += i * 20;
+ ele.atk2 += i * 20;
+ ele.hit += i * 10;
+ break;
+ case 2117: case 2118:
+ case 2119: //MDEF + (Summon Aqua Skill Level x 10) / MATK + (Summon Aqua Skill Level x 20)
+ ele.mdef += i * 10;
+ ele.matk += i * 20;
+ break;
+ case 2120: case 2121:
+ case 2122: //FLEE + (Summon Ventus Skill Level x 20) / MATK + (Summon Ventus Skill Level x 10)
+ ele.flee += i * 20;
+ ele.matk += i * 10;
+ break;
+ case 2123: case 2124:
+ case 2125: //DEF + (Summon Tera Skill Level x 25) / ATK + (Summon Tera Skill Level x 5)
+ ele.def += i * 25;
+ ele.atk += i * 5;
+ ele.atk2 += i * 5;
+ break;
+ }
+
+ if( (i=pc->checkskill(sd,SO_EL_SYMPATHY)) > 0 ){
+ ele.hp = ele.max_hp = ele.max_hp * 5 * i / 100;
+ ele.sp = ele.max_sp = ele.max_sp * 5 * i / 100;
+ ele.atk += 25 * i;
+ ele.atk2 += 25 * i;
+ ele.matk += 25 * i;
+ }
+
+ ele.life_time = lifetime;
+
+ // Request Char Server to create this elemental
+ intif->elemental_create(&ele);
+
+ return 1;
+}
+
+int elemental_get_lifetime(struct elemental_data *ed) {
+ const struct TimerData * td;
+ if( ed == NULL || ed->summon_timer == INVALID_TIMER )
+ return 0;
+
+ td = iTimer->get_timer(ed->summon_timer);
+ return (td != NULL) ? DIFF_TICK(td->tick, iTimer->gettick()) : 0;
+}
+
+int elemental_save(struct elemental_data *ed) {
+ ed->elemental.mode = ed->battle_status.mode;
+ ed->elemental.hp = ed->battle_status.hp;
+ ed->elemental.sp = ed->battle_status.sp;
+ ed->elemental.max_hp = ed->battle_status.max_hp;
+ ed->elemental.max_sp = ed->battle_status.max_sp;
+ ed->elemental.atk = ed->battle_status.rhw.atk;
+ ed->elemental.atk2 = ed->battle_status.rhw.atk2;
+ ed->elemental.matk = ed->battle_status.matk_min;
+ ed->elemental.def = ed->battle_status.def;
+ ed->elemental.mdef = ed->battle_status.mdef;
+ ed->elemental.flee = ed->battle_status.flee;
+ ed->elemental.hit = ed->battle_status.hit;
+ ed->elemental.life_time = elemental->get_lifetime(ed);
+ intif->elemental_save(&ed->elemental);
+ return 1;
+}
+
+static int elemental_summon_end(int tid, unsigned int tick, int id, intptr_t data) {
+ struct map_session_data *sd;
+ struct elemental_data *ed;
+
+ if( (sd = iMap->id2sd(id)) == NULL )
+ return 1;
+ if( (ed = sd->ed) == NULL )
+ return 1;
+
+ if( ed->summon_timer != tid ) {
+ ShowError("elemental_summon_end %d != %d.\n", ed->summon_timer, tid);
+ return 0;
+ }
+
+ ed->summon_timer = INVALID_TIMER;
+ elemental->delete(ed, 0); // Elemental's summon time is over.
+
+ return 0;
+}
+
+void elemental_summon_stop(struct elemental_data *ed) {
+ nullpo_retv(ed);
+ if( ed->summon_timer != INVALID_TIMER )
+ iTimer->delete_timer(ed->summon_timer, elemental_summon_end);
+ ed->summon_timer = INVALID_TIMER;
+}
+
+int elemental_delete(struct elemental_data *ed, int reply) {
+ struct map_session_data *sd;
+ nullpo_ret(ed);
+
+ sd = ed->master;
+ ed->elemental.life_time = 0;
+
+ elemental->clean_effect(ed);
+ elemental->summon_stop(ed);
+
+ if( !sd )
+ return unit->free(&ed->bl, 0);
+
+ sd->ed = NULL;
+ sd->status.ele_id = 0;
+
+ return unit->remove_map(&ed->bl, 0, ALC_MARK);
+}
+
+void elemental_summon_init(struct elemental_data *ed) {
+ if( ed->summon_timer == INVALID_TIMER )
+ ed->summon_timer = iTimer->add_timer(iTimer->gettick() + ed->elemental.life_time, elemental_summon_end, ed->master->bl.id, 0);
+
+ ed->regen.state.block = 0;
+}
+
+int elemental_data_received(struct s_elemental *ele, bool flag) {
+ struct map_session_data *sd;
+ struct elemental_data *ed;
+ struct s_elemental_db *db;
+ int i = elemental_search_index(ele->class_);
+
+ if( (sd = iMap->charid2sd(ele->char_id)) == NULL )
+ return 0;
+
+ if( !flag || i < 0 ) { // Not created - loaded - DB info
+ sd->status.ele_id = 0;
+ return 0;
+ }
+
+ db = &elemental->elemental_db[i];
+ 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->master = sd;
+ ed->db = db;
+ memcpy(&ed->elemental, ele, sizeof(struct s_elemental));
+ iStatus->set_viewdata(&ed->bl, ed->elemental.class_);
+ ed->vd->head_mid = 10; // Why?
+ iStatus->change_init(&ed->bl);
+ unit->dataset(&ed->bl);
+ ed->ud.dir = sd->ud.dir;
+
+ ed->bl.m = sd->bl.m;
+ ed->bl.x = sd->bl.x;
+ ed->bl.y = sd->bl.y;
+ unit->calc_pos(&ed->bl, sd->bl.x, sd->bl.y, sd->ud.dir);
+ ed->bl.x = ed->ud.to_x;
+ ed->bl.y = ed->ud.to_y;
+
+ iMap->addiddb(&ed->bl);
+ status_calc_elemental(ed,1);
+ ed->last_spdrain_time = ed->last_thinktime = iTimer->gettick();
+ ed->summon_timer = INVALID_TIMER;
+ elemental_summon_init(ed);
+ } else {
+ memcpy(&sd->ed->elemental, ele, sizeof(struct s_elemental));
+ ed = sd->ed;
+ }
+
+ sd->status.ele_id = ele->elemental_id;
+
+ if( ed->bl.prev == NULL && sd->bl.prev != NULL ) {
+ iMap->addblock(&ed->bl);
+ clif->spawn(&ed->bl);
+ clif->elemental_info(sd);
+ clif->elemental_updatestatus(sd,SP_HP);
+ clif->hpmeter_single(sd->fd,ed->bl.id,ed->battle_status.hp,ed->battle_status.max_hp);
+ clif->elemental_updatestatus(sd,SP_SP);
+ }
+
+ return 1;
+}
+
+int elemental_clean_single_effect(struct elemental_data *ed, uint16 skill_id) {
+ struct block_list *bl;
+ sc_type type = iStatus->skill2sc(skill_id);
+
+ nullpo_ret(ed);
+
+ bl = battle->get_master(&ed->bl);
+
+ if( type ) {
+ switch( type ) {
+ // Just remove status change.
+ case SC_PYROTECHNIC_OPTION:
+ case SC_HEATER_OPTION:
+ case SC_TROPIC_OPTION:
+ case SC_FIRE_CLOAK_OPTION:
+ case SC_AQUAPLAY_OPTION:
+ case SC_WATER_SCREEN_OPTION:
+ case SC_COOLER_OPTION:
+ case SC_CHILLY_AIR_OPTION:
+ case SC_GUST_OPTION:
+ case SC_WIND_STEP_OPTION:
+ case SC_BLAST_OPTION:
+ case SC_WATER_DROP_OPTION:
+ case SC_WIND_CURTAIN_OPTION:
+ case SC_WILD_STORM_OPTION:
+ case SC_PETROLOGY_OPTION:
+ case SC_SOLID_SKIN_OPTION:
+ case SC_CURSED_SOIL_OPTION:
+ case SC_STONE_SHIELD_OPTION:
+ case SC_UPHEAVAL_OPTION:
+ case SC_CIRCLE_OF_FIRE_OPTION:
+ case SC_TIDAL_WEAPON_OPTION:
+ if( bl ) status_change_end(bl,type,INVALID_TIMER); // Master
+ status_change_end(&ed->bl,type-1,INVALID_TIMER); // Elemental Spirit
+ break;
+ case SC_ZEPHYR:
+ if( bl ) status_change_end(bl,type,INVALID_TIMER);
+ break;
+ default:
+ ShowWarning("Invalid SC=%d in elemental_clean_single_effect\n",type);
+ break;
+ }
+ }
+
+ return 1;
+}
+
+int elemental_clean_effect(struct elemental_data *ed) {
+ struct map_session_data *sd;
+
+ nullpo_ret(ed);
+
+ // Elemental side
+ status_change_end(&ed->bl, SC_TROPIC, INVALID_TIMER);
+ status_change_end(&ed->bl, SC_HEATER, INVALID_TIMER);
+ status_change_end(&ed->bl, SC_AQUAPLAY, INVALID_TIMER);
+ status_change_end(&ed->bl, SC_COOLER, INVALID_TIMER);
+ status_change_end(&ed->bl, SC_CHILLY_AIR, INVALID_TIMER);
+ status_change_end(&ed->bl, SC_PYROTECHNIC, INVALID_TIMER);
+ status_change_end(&ed->bl, SC_FIRE_CLOAK, INVALID_TIMER);
+ status_change_end(&ed->bl, SC_WATER_DROP, INVALID_TIMER);
+ status_change_end(&ed->bl, SC_WATER_SCREEN, INVALID_TIMER);
+ status_change_end(&ed->bl, SC_GUST, INVALID_TIMER);
+ status_change_end(&ed->bl, SC_WIND_STEP, INVALID_TIMER);
+ status_change_end(&ed->bl, SC_BLAST, INVALID_TIMER);
+ status_change_end(&ed->bl, SC_WIND_CURTAIN, INVALID_TIMER);
+ status_change_end(&ed->bl, SC_WILD_STORM, INVALID_TIMER);
+ status_change_end(&ed->bl, SC_PETROLOGY, INVALID_TIMER);
+ status_change_end(&ed->bl, SC_SOLID_SKIN, INVALID_TIMER);
+ status_change_end(&ed->bl, SC_CURSED_SOIL, INVALID_TIMER);
+ status_change_end(&ed->bl, SC_STONE_SHIELD, INVALID_TIMER);
+ status_change_end(&ed->bl, SC_UPHEAVAL, INVALID_TIMER);
+ status_change_end(&ed->bl, SC_CIRCLE_OF_FIRE, INVALID_TIMER);
+ status_change_end(&ed->bl, SC_TIDAL_WEAPON, INVALID_TIMER);
+
+ if( (sd = ed->master) == NULL )
+ return 0;
+
+ // Master side
+ status_change_end(&sd->bl, SC_TROPIC_OPTION, INVALID_TIMER);
+ status_change_end(&sd->bl, SC_HEATER_OPTION, INVALID_TIMER);
+ status_change_end(&sd->bl, SC_AQUAPLAY_OPTION, INVALID_TIMER);
+ status_change_end(&sd->bl, SC_COOLER_OPTION, INVALID_TIMER);
+ status_change_end(&sd->bl, SC_CHILLY_AIR_OPTION, INVALID_TIMER);
+ status_change_end(&sd->bl, SC_PYROTECHNIC_OPTION, INVALID_TIMER);
+ status_change_end(&sd->bl, SC_FIRE_CLOAK_OPTION, INVALID_TIMER);
+ status_change_end(&sd->bl, SC_WATER_DROP_OPTION, INVALID_TIMER);
+ status_change_end(&sd->bl, SC_WATER_SCREEN_OPTION, INVALID_TIMER);
+ status_change_end(&sd->bl, SC_GUST_OPTION, INVALID_TIMER);
+ status_change_end(&sd->bl, SC_WIND_STEP_OPTION, INVALID_TIMER);
+ status_change_end(&sd->bl, SC_BLAST_OPTION, INVALID_TIMER);
+ status_change_end(&sd->bl, SC_WATER_DROP_OPTION, INVALID_TIMER);
+ status_change_end(&sd->bl, SC_WIND_CURTAIN_OPTION, INVALID_TIMER);
+ status_change_end(&sd->bl, SC_WILD_STORM_OPTION, INVALID_TIMER);
+ status_change_end(&sd->bl, SC_ZEPHYR, INVALID_TIMER);
+ status_change_end(&sd->bl, SC_WIND_STEP_OPTION, INVALID_TIMER);
+ status_change_end(&sd->bl, SC_PETROLOGY_OPTION, INVALID_TIMER);
+ status_change_end(&sd->bl, SC_SOLID_SKIN_OPTION, INVALID_TIMER);
+ status_change_end(&sd->bl, SC_CURSED_SOIL_OPTION, INVALID_TIMER);
+ status_change_end(&sd->bl, SC_STONE_SHIELD_OPTION, INVALID_TIMER);
+ status_change_end(&sd->bl, SC_UPHEAVAL_OPTION, INVALID_TIMER);
+ status_change_end(&sd->bl, SC_CIRCLE_OF_FIRE_OPTION, INVALID_TIMER);
+ status_change_end(&sd->bl, SC_TIDAL_WEAPON_OPTION, INVALID_TIMER);
+
+ return 1;
+}
+
+int elemental_action(struct elemental_data *ed, struct block_list *bl, unsigned int tick) {
+ struct skill_condition req;
+ uint16 skill_id, skill_lv;
+ int i;
+
+ nullpo_ret(ed);
+ nullpo_ret(bl);
+
+ if( !ed->master )
+ return 0;
+
+ if( ed->target_id )
+ elemental->unlocktarget(ed); // Remove previous target.
+
+ ARR_FIND(0, MAX_ELESKILLTREE, i, ed->db->skill[i].id && (ed->db->skill[i].mode&EL_SKILLMODE_AGGRESSIVE));
+ if( i == MAX_ELESKILLTREE )
+ return 0;
+
+ skill_id = ed->db->skill[i].id;
+ skill_lv = ed->db->skill[i].lv;
+
+ if( elemental->skillnotok(skill_id, ed) )
+ return 0;
+
+ if( ed->ud.skilltimer != INVALID_TIMER )
+ return 0;
+ else if( DIFF_TICK(tick, ed->ud.canact_tick) < 0 )
+ return 0;
+
+ ed->target_id = ed->ud.skilltarget = bl->id; // Set new target
+ ed->last_thinktime = tick;
+
+ // Not in skill range.
+ if( !battle->check_range(&ed->bl,bl,skill->get_range(skill_id,skill_lv)) ) {
+ // Try to walk to the target.
+ if( !unit->walktobl(&ed->bl, bl, skill->get_range(skill_id,skill_lv), 2) )
+ elemental->unlocktarget(ed);
+ else {
+ // Walking, waiting to be in range. Client don't handle it, then we must handle it here.
+ int walk_dist = distance_bl(&ed->bl,bl) - skill->get_range(skill_id,skill_lv);
+ ed->ud.skill_id = skill_id;
+ ed->ud.skill_lv = skill_lv;
+
+ if( skill->get_inf(skill_id) & INF_GROUND_SKILL )
+ ed->ud.skilltimer = iTimer->add_timer( tick+iStatus->get_speed(&ed->bl)*walk_dist, skill->castend_pos, ed->bl.id, 0 );
+ else
+ ed->ud.skilltimer = iTimer->add_timer( tick+iStatus->get_speed(&ed->bl)*walk_dist, skill->castend_id, ed->bl.id, 0 );
+ }
+ return 1;
+
+ }
+
+ req = elemental->skill_get_requirements(skill_id, skill_lv);
+
+ if(req.hp || req.sp){
+ struct map_session_data *sd = BL_CAST(BL_PC, battle->get_master(&ed->bl));
+ if( sd ){
+ if( sd->skill_id_old != SO_EL_ACTION && //regardless of remaining HP/SP it can be cast
+ (status_get_hp(&ed->bl) < req.hp || status_get_sp(&ed->bl) < req.sp) )
+ return 1;
+ else
+ status_zap(&ed->bl, req.hp, req.sp);
+ }
+ }
+
+ //Otherwise, just cast the skill.
+ if( skill->get_inf(skill_id) & INF_GROUND_SKILL )
+ unit->skilluse_pos(&ed->bl, bl->x, bl->y, skill_id, skill_lv);
+ else
+ unit->skilluse_id(&ed->bl, bl->id, skill_id, skill_lv);
+
+ // Reset target.
+ ed->target_id = 0;
+
+ return 1;
+}
+
+/*===============================================================
+ * Action that elemental perform after changing mode.
+ * Activates one of the skills of the new mode.
+ *-------------------------------------------------------------*/
+int elemental_change_mode_ack(struct elemental_data *ed, int mode) {
+ struct block_list *bl = &ed->master->bl;
+ uint16 skill_id, skill_lv;
+ int i;
+
+ nullpo_ret(ed);
+
+ if( !bl )
+ return 0;
+
+ // Select a skill.
+ ARR_FIND(0, MAX_ELESKILLTREE, i, ed->db->skill[i].id && (ed->db->skill[i].mode&mode));
+ if( i == MAX_ELESKILLTREE )
+ return 0;
+
+ skill_id = ed->db->skill[i].id;
+ skill_lv = ed->db->skill[i].lv;
+
+ if( elemental->skillnotok(skill_id, ed) )
+ return 0;
+
+ if( ed->ud.skilltimer != INVALID_TIMER )
+ return 0;
+ else if( DIFF_TICK(iTimer->gettick(), ed->ud.canact_tick) < 0 )
+ return 0;
+
+ ed->target_id = bl->id; // Set new target
+ ed->last_thinktime = iTimer->gettick();
+
+ if( skill->get_inf(skill_id) & INF_GROUND_SKILL )
+ unit->skilluse_pos(&ed->bl, bl->x, bl->y, skill_id, skill_lv);
+ else
+ unit->skilluse_id(&ed->bl,bl->id,skill_id,skill_lv);
+
+ ed->target_id = 0; // Reset target after casting the skill to avoid continious attack.
+
+ return 1;
+}
+
+/*===============================================================
+ * Change elemental mode.
+ *-------------------------------------------------------------*/
+int elemental_change_mode(struct elemental_data *ed, int mode) {
+ nullpo_ret(ed);
+
+ // Remove target
+ elemental->unlocktarget(ed);
+
+ // Removes the effects of the previous mode.
+ if(ed->elemental.mode != mode ) elemental->clean_effect(ed);
+
+ ed->battle_status.mode = ed->elemental.mode = mode;
+
+ // Normalize elemental mode to elemental skill mode.
+ if( mode == EL_MODE_AGGRESSIVE ) mode = EL_SKILLMODE_AGGRESSIVE; // Aggressive spirit mode -> Aggressive spirit skill.
+ else if( mode == EL_MODE_ASSIST ) mode = EL_SKILLMODE_ASSIST; // Assist spirit mode -> Assist spirit skill.
+ else mode = EL_SKILLMODE_PASIVE; // Passive spirit mode -> Passive spirit skill.
+
+ // Use a skill inmediately after every change mode.
+ if( mode != EL_SKILLMODE_AGGRESSIVE )
+ elemental->change_mode_ack(ed,mode);
+ return 1;
+}
+
+void elemental_heal(struct elemental_data *ed, int hp, int sp) {
+ if( hp )
+ clif->elemental_updatestatus(ed->master, SP_HP);
+ if( sp )
+ clif->elemental_updatestatus(ed->master, SP_SP);
+}
+
+int elemental_dead(struct elemental_data *ed) {
+ elemental->delete(ed, 1);
+ return 0;
+}
+
+int elemental_unlocktarget(struct elemental_data *ed) {
+ nullpo_ret(ed);
+
+ ed->target_id = 0;
+ elemental_stop_attack(ed);
+ elemental_stop_walking(ed,1);
+ return 0;
+}
+
+int elemental_skillnotok(uint16 skill_id, struct elemental_data *ed) {
+ int idx = skill->get_index(skill_id);
+ nullpo_retr(1,ed);
+
+ if (idx == 0)
+ return 1; // invalid skill id
+
+ return skill->not_ok(skill_id, ed->master);
+}
+
+struct skill_condition elemental_skill_get_requirements(uint16 skill_id, uint16 skill_lv){
+ struct skill_condition req;
+ int idx = skill->get_index(skill_id);
+
+ memset(&req,0,sizeof(req));
+
+ if( idx == 0 ) // invalid skill id
+ return req;
+
+ if( skill_lv < 1 || skill_lv > MAX_SKILL_LEVEL )
+ return req;
+
+ req.hp = skill_db[idx].hp[skill_lv-1];
+ req.sp = skill_db[idx].sp[skill_lv-1];
+
+ return req;
+}
+
+int elemental_set_target( struct map_session_data *sd, struct block_list *bl ) {
+ struct elemental_data *ed = sd->ed;
+
+ nullpo_ret(ed);
+ nullpo_ret(bl);
+
+ if( ed->bl.m != bl->m || !check_distance_bl(&ed->bl, bl, ed->db->range2) )
+ return 0;
+
+ if( !iStatus->check_skilluse(&ed->bl, bl, 0, 0) )
+ return 0;
+
+ if( ed->target_id == 0 )
+ ed->target_id = bl->id;
+
+ return 1;
+}
+
+static int elemental_ai_sub_timer_activesearch(struct block_list *bl, va_list ap) {
+ struct elemental_data *ed;
+ struct block_list **target;
+ int dist;
+
+ nullpo_ret(bl);
+
+ ed = va_arg(ap,struct elemental_data *);
+ target = va_arg(ap,struct block_list**);
+
+ //If can't seek yet, not an enemy, or you can't attack it, skip.
+ if( (*target) == bl || !iStatus->check_skilluse(&ed->bl, bl, 0, 0) )
+ return 0;
+
+ if( battle->check_target(&ed->bl,bl,BCT_ENEMY) <= 0 )
+ return 0;
+
+ switch( bl->type ) {
+ case BL_PC:
+ if( !map_flag_vs(ed->bl.m) )
+ return 0;
+ default:
+ dist = distance_bl(&ed->bl, bl);
+ if( ((*target) == NULL || !check_distance_bl(&ed->bl, *target, dist)) && battle->check_range(&ed->bl,bl,ed->db->range2) ) { //Pick closest target?
+ (*target) = bl;
+ ed->target_id = bl->id;
+ ed->min_chase = dist + ed->db->range3;
+ if( ed->min_chase > AREA_SIZE )
+ ed->min_chase = AREA_SIZE;
+ return 1;
+ }
+ break;
+ }
+ return 0;
+}
+
+static int elemental_ai_sub_timer(struct elemental_data *ed, struct map_session_data *sd, unsigned int tick) {
+ struct block_list *target = NULL;
+ int master_dist, view_range, mode;
+
+ nullpo_ret(ed);
+ nullpo_ret(sd);
+
+ if( ed->bl.prev == NULL || sd == NULL || sd->bl.prev == NULL )
+ return 0;
+
+ // Check if caster can sustain the summoned elemental
+ if( DIFF_TICK(tick,ed->last_spdrain_time) >= 10000 ){// Drain SP every 10 seconds
+ int sp = 5;
+
+ switch(ed->vd->class_){
+ case 2115: case 2118:
+ case 2121: case 2124:
+ sp = 8;
+ break;
+ case 2116: case 2119:
+ case 2122: case 2125:
+ sp = 11;
+ break;
+ }
+
+ if( status_get_sp(&sd->bl) < sp ){ // Can't sustain delete it.
+ elemental->delete(sd->ed,0);
+ return 0;
+ }
+
+ status_zap(&sd->bl,0,sp);
+ ed->last_spdrain_time = tick;
+ }
+
+ if( DIFF_TICK(tick,ed->last_thinktime) < MIN_ELETHINKTIME )
+ return 0;
+
+ ed->last_thinktime = tick;
+
+ if( ed->ud.skilltimer != INVALID_TIMER )
+ return 0;
+
+ if( ed->ud.walktimer != INVALID_TIMER && ed->ud.walkpath.path_pos <= 2 )
+ return 0; //No thinking when you just started to walk.
+
+ if(ed->ud.walkpath.path_pos < ed->ud.walkpath.path_len && ed->ud.target == sd->bl.id)
+ return 0; //No thinking until be near the master.
+
+ if( ed->sc.count && ed->sc.data[SC_BLIND] )
+ view_range = 3;
+ else
+ view_range = ed->db->range2;
+
+ mode = status_get_mode(&ed->bl);
+
+ master_dist = distance_bl(&sd->bl, &ed->bl);
+ if( master_dist > AREA_SIZE ) { // Master out of vision range.
+ elemental->unlocktarget(ed);
+ unit->warp(&ed->bl,sd->bl.m,sd->bl.x,sd->bl.y,CLR_TELEPORT);
+ clif->elemental_updatestatus(sd,SP_HP);
+ clif->elemental_updatestatus(sd,SP_SP);
+ return 0;
+ } else if( master_dist > MAX_ELEDISTANCE ) { // Master too far, chase.
+ short x = sd->bl.x, y = sd->bl.y;
+ if( ed->target_id )
+ elemental->unlocktarget(ed);
+ if( ed->ud.walktimer != INVALID_TIMER && ed->ud.target == sd->bl.id )
+ return 0; //Already walking to him
+ if( DIFF_TICK(tick, ed->ud.canmove_tick) < 0 )
+ return 0; //Can't move yet.
+ if( iMap->search_freecell(&ed->bl, sd->bl.m, &x, &y, MIN_ELEDISTANCE, MIN_ELEDISTANCE, 1)
+ && unit->walktoxy(&ed->bl, x, y, 0) )
+ return 0;
+ }
+
+ if( mode == EL_MODE_AGGRESSIVE ) {
+ target = iMap->id2bl(ed->ud.target);
+
+ if( !target )
+ iMap->foreachinrange(elemental_ai_sub_timer_activesearch, &ed->bl, view_range, BL_CHAR, ed, &target, status_get_mode(&ed->bl));
+
+ if( !target ) { //No targets available.
+ elemental->unlocktarget(ed);
+ return 1;
+ }
+
+ if( battle->check_range(&ed->bl,target,view_range) && rnd()%100 < 2 ) { // 2% chance to cast attack skill.
+ if( elemental->action(ed,target,tick) )
+ return 1;
+ }
+
+ //Attempt to attack.
+ //At this point we know the target is attackable, we just gotta check if the range matches.
+ if( ed->ud.target == target->id && ed->ud.attacktimer != INVALID_TIMER ) //Already locked.
+ return 1;
+
+ if( battle->check_range(&ed->bl, target, ed->base_status.rhw.range) ) {//Target within range, engage
+ unit->attack(&ed->bl,target->id,1);
+ return 1;
+ }
+
+ //Follow up if possible.
+ if( !unit->walktobl(&ed->bl, target, ed->base_status.rhw.range, 2) )
+ elemental->unlocktarget(ed);
+ }
+
+ return 0;
+}
+
+static int elemental_ai_sub_foreachclient(struct map_session_data *sd, va_list ap) {
+ unsigned int tick = va_arg(ap,unsigned int);
+ if(sd->status.ele_id && sd->ed)
+ elemental_ai_sub_timer(sd->ed,sd,tick);
+
+ return 0;
+}
+
+static int elemental_ai_timer(int tid, unsigned int tick, int id, intptr_t data) {
+ iMap->map_foreachpc(elemental_ai_sub_foreachclient,tick);
+ return 0;
+}
+
+int read_elementaldb(void) {
+ FILE *fp;
+ char line[1024], *p;
+ char *str[26];
+ int i, j = 0, k = 0, ele;
+ struct s_elemental_db *db;
+ struct status_data *status;
+
+ sprintf(line, "%s/%s", iMap->db_path, "elemental_db.txt");
+ memset(elemental->elemental_db,0,sizeof(elemental->elemental_db));
+
+ fp = fopen(line, "r");
+ if( !fp ) {
+ ShowError("read_elementaldb : can't read elemental_db.txt\n");
+ return -1;
+ }
+
+ while( fgets(line, sizeof(line), fp) && j < MAX_ELEMENTAL_CLASS ) {
+ k++;
+ if( line[0] == '/' && line[1] == '/' )
+ continue;
+
+ if( line[0] == '\0' || line[0] == '\n' || line[0] == '\r')
+ continue;
+
+ i = 0;
+ p = strtok(line, ",");
+ while( p != NULL && i < 26 ) {
+ str[i++] = p;
+ p = strtok(NULL, ",");
+ }
+ if( i < 26 ) {
+ ShowError("read_elementaldb : Incorrect number of columns at elemental_db.txt line %d.\n", k);
+ continue;
+ }
+
+ db = &elemental->elemental_db[j];
+ db->class_ = atoi(str[0]);
+ safestrncpy(db->sprite, str[1], NAME_LENGTH);
+ safestrncpy(db->name, str[2], NAME_LENGTH);
+ db->lv = atoi(str[3]);
+
+ status = &db->status;
+ db->vd.class_ = db->class_;
+
+ status->max_hp = atoi(str[4]);
+ status->max_sp = atoi(str[5]);
+ status->rhw.range = atoi(str[6]);
+ status->rhw.atk = atoi(str[7]);
+ status->rhw.atk2 = atoi(str[8]);
+ status->def = atoi(str[9]);
+ status->mdef = atoi(str[10]);
+ status->str = atoi(str[11]);
+ status->agi = atoi(str[12]);
+ status->vit = atoi(str[13]);
+ status->int_ = atoi(str[14]);
+ status->dex = atoi(str[15]);
+ status->luk = atoi(str[16]);
+ db->range2 = atoi(str[17]);
+ db->range3 = atoi(str[18]);
+ status->size = atoi(str[19]);
+ status->race = atoi(str[20]);
+
+ ele = atoi(str[21]);
+ status->def_ele = ele%10;
+ status->ele_lv = ele/20;
+ if( status->def_ele >= ELE_MAX ) {
+ ShowWarning("Elemental %d has invalid element type %d (max element is %d)\n", db->class_, status->def_ele, ELE_MAX - 1);
+ status->def_ele = ELE_NEUTRAL;
+ }
+ if( status->ele_lv < 1 || status->ele_lv > 4 ) {
+ ShowWarning("Elemental %d has invalid element level %d (max is 4)\n", db->class_, status->ele_lv);
+ status->ele_lv = 1;
+ }
+
+ status->aspd_rate = 1000;
+ status->speed = atoi(str[22]);
+ status->adelay = atoi(str[23]);
+ status->amotion = atoi(str[24]);
+ status->dmotion = atoi(str[25]);
+
+ j++;
+ }
+
+ fclose(fp);
+ ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' elementals in '"CL_WHITE"db/elemental_db.txt"CL_RESET"'.\n",j);
+
+ return 0;
+}
+
+int read_elemental_skilldb(void) {
+ FILE *fp;
+ char line[1024], *p;
+ char *str[4];
+ struct s_elemental_db *db;
+ int i, j = 0, k = 0, class_;
+ uint16 skill_id, skill_lv;
+ int skillmode;
+
+ sprintf(line, "%s/%s", iMap->db_path, "elemental_skill_db.txt");
+ fp = fopen(line, "r");
+ if( !fp ) {
+ ShowError("read_elemental_skilldb : can't read elemental_skill_db.txt\n");
+ return -1;
+ }
+
+ while( fgets(line, sizeof(line), fp) ) {
+ k++;
+ if( line[0] == '/' && line[1] == '/' )
+ continue;
+
+ if( line[0] == '\0' || line[0] == '\n' || line[0] == '\r')
+ continue;
+
+ i = 0;
+ p = strtok(line, ",");
+ while( p != NULL && i < 4 ) {
+ str[i++] = p;
+ p = strtok(NULL, ",");
+ }
+ if( i < 4 ) {
+ ShowError("read_elemental_skilldb : Incorrect number of columns at elemental_skill_db.txt line %d.\n", k);
+ continue;
+ }
+
+ class_ = atoi(str[0]);
+ ARR_FIND(0, MAX_ELEMENTAL_CLASS, i, class_ == elemental->elemental_db[i].class_);
+ if( i == MAX_ELEMENTAL_CLASS ) {
+ ShowError("read_elemental_skilldb : Class not found in elemental_db for skill entry, line %d.\n", k);
+ continue;
+ }
+
+ skill_id = atoi(str[1]);
+ if( skill_id < EL_SKILLBASE || skill_id >= EL_SKILLBASE + MAX_ELEMENTALSKILL ) {
+ ShowError("read_elemental_skilldb : Skill out of range, line %d.\n", k);
+ continue;
+ }
+
+ db = &elemental->elemental_db[i];
+ skill_lv = atoi(str[2]);
+
+ skillmode = atoi(str[3]);
+ if( skillmode < EL_SKILLMODE_PASIVE || skillmode > EL_SKILLMODE_AGGRESSIVE ) {
+ ShowError("read_elemental_skilldb : Skillmode out of range, line %d.\n",k);
+ continue;
+ }
+ ARR_FIND( 0, MAX_ELESKILLTREE, i, db->skill[i].id == 0 || db->skill[i].id == skill_id );
+ if( i == MAX_ELESKILLTREE ) {
+ ShowWarning("Unable to load skill %d into Elemental %d's tree. Maximum number of skills per elemental has been reached.\n", skill_id, class_);
+ continue;
+ }
+ db->skill[i].id = skill_id;
+ db->skill[i].lv = skill_lv;
+ db->skill[i].mode = skillmode;
+ j++;
+ }
+
+ fclose(fp);
+ ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"db/elemental_skill_db.txt"CL_RESET"'.\n",j);
+ return 0;
+}
+
+void reload_elementaldb(void) {
+ read_elementaldb();
+ elemental->reload_skilldb();
+}
+
+void reload_elemental_skilldb(void) {
+ elemental->read_skilldb();
+}
+
+int do_init_elemental(void) {
+ read_elementaldb();
+ elemental->read_skilldb();
+
+ iTimer->add_timer_func_list(elemental_ai_timer,"elemental_ai_timer");
+ iTimer->add_timer_interval(iTimer->gettick()+MIN_ELETHINKTIME,elemental_ai_timer,0,0,MIN_ELETHINKTIME);
+
+ return 0;
+}
+
+void do_final_elemental(void) {
+ return;
+}
+
+/*=====================================
+* Default Functions : elemental.h
+* Generated by HerculesInterfaceMaker
+* created by Susu
+*-------------------------------------*/
+void elemental_defaults(void) {
+ elemental = &elemental_s;
+
+ /* funcs */
+
+ elemental->class = elemental_class;
+ elemental->get_viewdata = elemental_get_viewdata;
+
+ elemental->create = elemental_create;
+ elemental->data_received = elemental_data_received;
+ elemental->save = elemental_save;
+
+ elemental->change_mode_ack = elemental_change_mode_ack;
+ elemental->change_mode = elemental_change_mode;
+
+ elemental->heal = elemental_heal;
+ elemental->dead = elemental_dead;
+
+ elemental->delete = elemental_delete;
+ elemental->summon_stop = elemental_summon_stop;
+
+ elemental->get_lifetime = elemental_get_lifetime;
+
+ elemental->unlocktarget = elemental_unlocktarget;
+ elemental->skillnotok = elemental_skillnotok;
+ elemental->set_target = elemental_set_target;
+ elemental->clean_single_effect = elemental_clean_single_effect;
+ elemental->clean_effect = elemental_clean_effect;
+ elemental->action = elemental_action;
+ elemental->skill_get_requirements = elemental_skill_get_requirements;
+
+ elemental->read_skilldb = read_elemental_skilldb;
+ elemental->reload_elementaldb = reload_elementaldb;
+ elemental->reload_skilldb = reload_elemental_skilldb;
+ elemental->do_init_elemental = do_init_elemental;
+ elemental->do_final_elemental = do_final_elemental;
+}
diff --git a/src/map/elemental.h b/src/map/elemental.h
index 96d2ed89f..ccc3bcb5f 100644
--- a/src/map/elemental.h
+++ b/src/map/elemental.h
@@ -1,106 +1,100 @@
-// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
-// For more information, see LICENCE in the main folder
-#ifndef _ELEMENTAL_H_
-#define _ELEMENTAL_H_
-#include "status.h" // struct status_data, struct status_change
-#include "unit.h" // struct unit_data
-#define MIN_ELETHINKTIME 100
-#define MIN_ELEDISTANCE 2
-#define MAX_ELEDISTANCE 5
-#define EL_MODE_AGGRESSIVE (MD_CANMOVE|MD_AGGRESSIVE|MD_CANATTACK)
-#define EL_MODE_ASSIST (MD_CANMOVE|MD_ASSIST)
-#define EL_MODE_PASSIVE MD_CANMOVE
-#define EL_SKILLMODE_PASIVE 0x1
-#define EL_SKILLMODE_ASSIST 0x2
-#define EL_SKILLMODE_AGGRESSIVE 0x4
-struct elemental_skill {
- unsigned short id, lv;
- short mode;
-};
-struct s_elemental_db {
- int class_;
- char sprite[NAME_LENGTH], name[NAME_LENGTH];
- unsigned short lv;
- short range2, range3;
- struct status_data status;
- struct view_data vd;
- struct elemental_skill skill[MAX_ELESKILLTREE];
-};
-struct elemental_data {
- struct block_list bl;
- struct unit_data ud;
- struct view_data *vd;
- struct status_data base_status, battle_status;
- struct status_change sc;
- struct regen_data regen;
-
- struct s_elemental_db *db;
- struct s_elemental elemental;
-
- struct map_session_data *master;
- int summon_timer;
- int skill_timer;
-
- unsigned last_thinktime, last_linktime, last_spdrain_time;
- short min_chase;
- int target_id, attacked_id;
-};
-
-
-
-
-
-
-
-
-#define elemental_stop_walking(ed, type) unit_stop_walking(&(ed)->bl, type)
-#define elemental_stop_attack(ed) unit_stop_attack(&(ed)->bl)
-
-
-/*=====================================
-* Interface : elemental.h
-* Generated by HerculesInterfaceMaker
-* created by Susu
-*-------------------------------------*/
-struct elemental_interface {
- /* vars */
- struct s_elemental_db elemental_db[MAX_ELEMENTAL_CLASS]; // Elemental Database
- /* funcs */
- bool (*class) (int class_);
- struct view_data * (*get_viewdata) (int class_);
-
- int (*create) (struct map_session_data *sd, int class_, unsigned int lifetime);
- int (*data_received) (struct s_elemental *ele, bool flag);
- int (*save) (struct elemental_data *ed);
-
- int (*change_mode_ack) (struct elemental_data *ed, int mode);
- int (*change_mode) (struct elemental_data *ed, int mode);
-
- void (*heal) (struct elemental_data *ed, int hp, int sp);
- int (*dead) (struct elemental_data *ed);
-
- int (*delete) (struct elemental_data *ed, int reply);
- void (*summon_stop) (struct elemental_data *ed);
-
- int (*get_lifetime) (struct elemental_data *ed);
-
- int (*unlocktarget) (struct elemental_data *ed);
- int (*skillnotok) (uint16 skill_id, struct elemental_data *ed);
- int (*set_target) (struct map_session_data *sd, struct block_list *bl);
- int (*clean_single_effect) (struct elemental_data *ed, uint16 skill_id);
- int (*clean_effect) (struct elemental_data *ed);
- int (*action) (struct elemental_data *ed, struct block_list *bl, unsigned int tick);
- struct skill_condition (*skill_get_requirements) (uint16 skill_id, uint16 skill_lv);
-
- int (*read_skilldb) (void);
- void (*reload_elementaldb) (void);
- void (*reload_skilldb) (void);
- int (*do_init_elemental) (void);
- void (*do_final_elemental) (void);
-} elemental_s;
-
-struct elemental_interface *elemental;
-
-void elemental_defaults(void);
-
-#endif /* _ELEMENTAL_H_ */
+// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
+// For more information, see LICENCE in the main folder
+#ifndef _ELEMENTAL_H_
+#define _ELEMENTAL_H_
+#include "status.h" // struct status_data, struct status_change
+#include "unit.h" // struct unit_data
+#define MIN_ELETHINKTIME 100
+#define MIN_ELEDISTANCE 2
+#define MAX_ELEDISTANCE 5
+#define EL_MODE_AGGRESSIVE (MD_CANMOVE|MD_AGGRESSIVE|MD_CANATTACK)
+#define EL_MODE_ASSIST (MD_CANMOVE|MD_ASSIST)
+#define EL_MODE_PASSIVE MD_CANMOVE
+#define EL_SKILLMODE_PASIVE 0x1
+#define EL_SKILLMODE_ASSIST 0x2
+#define EL_SKILLMODE_AGGRESSIVE 0x4
+struct elemental_skill {
+ unsigned short id, lv;
+ short mode;
+};
+struct s_elemental_db {
+ int class_;
+ char sprite[NAME_LENGTH], name[NAME_LENGTH];
+ unsigned short lv;
+ short range2, range3;
+ struct status_data status;
+ struct view_data vd;
+ struct elemental_skill skill[MAX_ELESKILLTREE];
+};
+struct elemental_data {
+ struct block_list bl;
+ struct unit_data ud;
+ struct view_data *vd;
+ struct status_data base_status, battle_status;
+ struct status_change sc;
+ struct regen_data regen;
+
+ struct s_elemental_db *db;
+ struct s_elemental elemental;
+
+ struct map_session_data *master;
+ int summon_timer;
+ int skill_timer;
+
+ unsigned last_thinktime, last_linktime, last_spdrain_time;
+ short min_chase;
+ int target_id, attacked_id;
+};
+
+#define elemental_stop_walking(ed, type) unit->stop_walking(&(ed)->bl, type)
+#define elemental_stop_attack(ed) unit->stop_attack(&(ed)->bl)
+
+/*=====================================
+* Interface : elemental.h
+* Generated by HerculesInterfaceMaker
+* created by Susu
+*-------------------------------------*/
+struct elemental_interface {
+
+ /* vars */
+ struct s_elemental_db elemental_db[MAX_ELEMENTAL_CLASS]; // Elemental Database
+
+ /* funcs */
+ bool (*class) (int class_);
+ struct view_data * (*get_viewdata) (int class_);
+
+ int (*create) (struct map_session_data *sd, int class_, unsigned int lifetime);
+ int (*data_received) (struct s_elemental *ele, bool flag);
+ int (*save) (struct elemental_data *ed);
+
+ int (*change_mode_ack) (struct elemental_data *ed, int mode);
+ int (*change_mode) (struct elemental_data *ed, int mode);
+
+ void (*heal) (struct elemental_data *ed, int hp, int sp);
+ int (*dead) (struct elemental_data *ed);
+
+ int (*delete) (struct elemental_data *ed, int reply);
+ void (*summon_stop) (struct elemental_data *ed);
+
+ int (*get_lifetime) (struct elemental_data *ed);
+
+ int (*unlocktarget) (struct elemental_data *ed);
+ int (*skillnotok) (uint16 skill_id, struct elemental_data *ed);
+ int (*set_target) (struct map_session_data *sd, struct block_list *bl);
+ int (*clean_single_effect) (struct elemental_data *ed, uint16 skill_id);
+ int (*clean_effect) (struct elemental_data *ed);
+ int (*action) (struct elemental_data *ed, struct block_list *bl, unsigned int tick);
+ struct skill_condition (*skill_get_requirements) (uint16 skill_id, uint16 skill_lv);
+
+ int (*read_skilldb) (void);
+ void (*reload_elementaldb) (void);
+ void (*reload_skilldb) (void);
+ int (*do_init_elemental) (void);
+ void (*do_final_elemental) (void);
+} elemental_s;
+
+struct elemental_interface *elemental;
+
+void elemental_defaults(void);
+
+#endif /* _ELEMENTAL_H_ */
diff --git a/src/map/guild.c b/src/map/guild.c
index 601d88387..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);
@@ -1883,7 +1883,7 @@ int guild_break(struct map_session_data *sd,char *name) {
}
/* regardless of char server allowing it, we clear the guild master's auras */
- if( (ud = unit_bl2ud(&sd->bl)) ) {
+ if( (ud = unit->bl2ud(&sd->bl)) ) {
int count = 0;
struct skill_unit_group *groups[4];
for (i=0;i<MAX_SKILLUNITGROUP && ud->skillunit[i];i++) {
@@ -1960,7 +1960,7 @@ int guild_castledatasave(int castle_id, int index, int value)
gc->guild_id = value;
for (i = 0; i < MAX_GUARDIANS; i++)
if (gc->guardian[i].visible && (gd = iMap->id2md(gc->guardian[i].id)) != NULL)
- mob_guardian_guildchange(gd);
+ mob->guardian_guildchange(gd);
break;
}
case 2:
@@ -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 3a6ed074c..81971ebef 100644
--- a/src/map/homunculus.c
+++ b/src/map/homunculus.c
@@ -157,7 +157,7 @@ int homunculus_vaporize(struct map_session_data *sd, int flag) {
memset(hd->blockskill, 0, sizeof(hd->blockskill));
clif->hominfo(sd, sd->hd, 0);
homun->save(hd);
- return unit_remove_map(&hd->bl, CLR_OUTSIGHT);
+ return unit->remove_map(&hd->bl, CLR_OUTSIGHT, ALC_MARK);
}
//delete a homunculus, completely "killing it".
@@ -168,7 +168,7 @@ int homunculus_delete(struct homun_data *hd, int emote) {
sd = hd->master;
if (!sd)
- return unit_free(&hd->bl,CLR_DEAD);
+ return unit->free(&hd->bl,CLR_DEAD);
if (emote >= 0)
clif->emotion(&sd->bl, emote);
@@ -178,7 +178,7 @@ int homunculus_delete(struct homun_data *hd, int emote) {
// Send homunculus_dead to client
hd->homunculus.hp = 0;
clif->hominfo(sd, hd, 0);
- return unit_remove_map(&hd->bl,CLR_OUTSIGHT);
+ return unit->remove_map(&hd->bl,CLR_OUTSIGHT, ALC_MARK);
}
int homunculus_calc_skilltree(struct homun_data *hd, int flag_evolve) {
@@ -403,7 +403,7 @@ bool homunculus_evolve(struct homun_data *hd) {
hom->luk += 10*rnd_value(min->luk, max->luk);
hom->intimacy = 500;
- unit_remove_map(&hd->bl, CLR_OUTSIGHT);
+ unit->remove_map(&hd->bl, CLR_OUTSIGHT, ALC_MARK);
iMap->addblock(&hd->bl);
clif->spawn(&hd->bl);
@@ -447,7 +447,7 @@ bool homunculus_mutate(struct homun_data *hd, int homun_id) {
return false;
}
- unit_remove_map(&hd->bl, CLR_OUTSIGHT);
+ unit->remove_map(&hd->bl, CLR_OUTSIGHT, ALC_MARK);
iMap->addblock(&hd->bl);
clif->spawn(&hd->bl);
@@ -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];
@@ -745,14 +745,14 @@ bool homunculus_create(struct map_session_data *sd, struct s_homunculus *hom) {
iStatus->set_viewdata(&hd->bl, hd->homunculus.class_);
iStatus->change_init(&hd->bl);
- unit_dataset(&hd->bl);
+ unit->dataset(&hd->bl);
hd->ud.dir = sd->ud.dir;
// Find a random valid pos around the player
hd->bl.m = sd->bl.m;
hd->bl.x = sd->bl.x;
hd->bl.y = sd->bl.y;
- unit_calc_pos(&hd->bl, sd->bl.x, sd->bl.y, sd->ud.dir);
+ unit->calc_pos(&hd->bl, sd->bl.x, sd->bl.y, sd->ud.dir);
hd->bl.x = hd->ud.to_x;
hd->bl.y = hd->ud.to_y;
@@ -801,7 +801,7 @@ bool homunculus_call(struct map_session_data *sd) {
homun->save(hd);
} else
//Warp him to master.
- unit_warp(&hd->bl,sd->bl.m, sd->bl.x, sd->bl.y,CLR_OUTSIGHT);
+ unit->warp(&hd->bl,sd->bl.m, sd->bl.x, sd->bl.y,CLR_OUTSIGHT);
return true;
}
diff --git a/src/map/instance.c b/src/map/instance.c
index 4e145fb8f..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,10 +341,10 @@ 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);
+ unit->free(bl,CLR_OUTSIGHT);
break;
case BL_PET:
//There is no need for this, the pet is removed together with the player. [Skotlex]
diff --git a/src/map/intif.c b/src/map/intif.c
index 1713cb38e..ac1471d23 100644
--- a/src/map/intif.c
+++ b/src/map/intif.c
@@ -1278,7 +1278,7 @@ int intif_parse_GuildMasterChanged(int fd)
// Request pet creation
int intif_parse_CreatePet(int fd)
{
- pet_get_egg(RFIFOL(fd,2),RFIFOL(fd,7),RFIFOB(fd,6));
+ pet->get_egg(RFIFOL(fd,2),RFIFOL(fd,7),RFIFOB(fd,6));
return 0;
}
@@ -1294,7 +1294,7 @@ int intif_parse_RecvPetData(int fd)
}
else{
memcpy(&p,RFIFOP(fd,9),sizeof(struct s_pet));
- pet_recv_petdata(RFIFOL(fd,4),&p,RFIFOB(fd,8));
+ pet->recv_petdata(RFIFOL(fd,4),&p,RFIFOB(fd,8));
}
return 0;
@@ -1330,7 +1330,7 @@ int intif_parse_ChangeNameOk(int fd)
case 0: //Players [NOT SUPPORTED YET]
break;
case 1: //Pets
- pet_change_name_ack(sd, (char*)RFIFOP(fd,12), RFIFOB(fd,11));
+ pet->change_name_ack(sd, (char*)RFIFOP(fd,12), RFIFOB(fd,11));
break;
case 2: //Hom
homun->change_name_ack(sd, (char*)RFIFOP(fd,12), RFIFOB(fd,11));
@@ -1419,7 +1419,7 @@ int intif_parse_questlog(int fd)
{
memcpy(&sd->quest_log[i], RFIFOP(fd, i*sizeof(struct quest)+8), sizeof(struct quest));
- sd->quest_index[i] = quest_search_db(sd->quest_log[i].quest_id);
+ sd->quest_index[i] = quest->search_db(sd->quest_log[i].quest_id);
if( sd->quest_index[i] < 0 )
{
@@ -1434,7 +1434,7 @@ int intif_parse_questlog(int fd)
sd->avail_quests--;
}
- quest_pc_login(sd);
+ quest->pc_login(sd);
return 0;
}
diff --git a/src/map/intif.h b/src/map/intif.h
index f0c1067fb..8abcf819d 100644
--- a/src/map/intif.h
+++ b/src/map/intif.h
@@ -1,128 +1,128 @@
-// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
-// For more information, see LICENCE in the main folder
-#ifndef _INTIF_H_
-#define _INFIF_H_
-//#include "../common/mmo.h"
-struct party_member;
-struct guild_member;
-struct guild_position;
-struct s_pet;
-struct s_homunculus;
-struct s_mercenary;
-struct s_elemental;
-struct mail_message;
-struct auction_data;
-
-
-
-
-
-#define intif_rename_pc(sd, name) intif->rename(sd, 0, name)
-#define intif_rename_pet(sd, name) intif->rename(sd, 1, name)
-#define intif_rename_hom(sd, name) intif->rename(sd, 2, name)
-
-
-
-
-
-
-/*=====================================
-* Interface : intif.h
-* Generated by HerculesInterfaceMaker
-* created by Susu
-*-------------------------------------*/
-struct intif_interface {
- /* funcs */
-
-
- int (*parse) (int fd);
-
- int (*create_pet)(int account_id, int char_id, short pet_type, short pet_lv, short pet_egg_id,
- short pet_equip, short intimate, short hungry, char rename_flag, char incuvate, char *pet_name);
-
- int (*broadcast) (const char* mes, int len, int type);
- int (*broadcast2) (const char* mes, int len, unsigned long fontColor, short fontType, short fontSize, short fontAlign, short fontY);
- int (*main_message) (struct map_session_data* sd, const char* message);
-
- int (*wis_message) (struct map_session_data *sd,char *nick,char *mes,int mes_len);
- int (*wis_message_to_gm) (char *Wisp_name, int permission, char *mes);
-
- int (*saveregistry) (struct map_session_data *sd, int type);
- int (*request_registry) (struct map_session_data *sd, int flag);
-
- int (*request_guild_storage) (int account_id, int guild_id);
- int (*send_guild_storage) (int account_id, struct guild_storage *gstor);
-
- int (*create_party) (struct party_member *member,char *name,int item,int item2);
- int (*request_partyinfo) (int party_id, int char_id);
-
- int (*party_addmember) (int party_id,struct party_member *member);
- int (*party_changeoption) (int party_id, int account_id, int exp, int item);
- int (*party_leave) (int party_id,int account_id, int char_id);
- int (*party_changemap) (struct map_session_data *sd, int online);
- int (*break_party) (int party_id);
- int (*party_message) (int party_id, int account_id, const char *mes,int len);
- int (*party_leaderchange) (int party_id,int account_id,int char_id);
-
- int (*guild_create) (const char *name, const struct guild_member *master);
- int (*guild_request_info) (int guild_id);
- int (*guild_addmember) (int guild_id, struct guild_member *m);
- int (*guild_leave) (int guild_id, int account_id, int char_id, int flag, const char *mes);
- int (*guild_memberinfoshort) (int guild_id, int account_id, int char_id, int online, int lv, int class_);
- int (*guild_break) (int guild_id);
- int (*guild_message) (int guild_id, int account_id, const char *mes, int len);
- int (*guild_change_gm) (int guild_id, const char* name, int len);
- int (*guild_change_basicinfo) (int guild_id, int type, const void *data, int len);
- int (*guild_change_memberinfo) (int guild_id, int account_id, int char_id, int type, const void *data, int len);
- int (*guild_position) (int guild_id, int idx, struct guild_position *p);
- int (*guild_skillup) (int guild_id, uint16 skill_id, int account_id, int max);
- int (*guild_alliance) (int guild_id1, int guild_id2, int account_id1, int account_id2, int flag);
- int (*guild_notice) (int guild_id, const char *mes1, const char *mes2);
- int (*guild_emblem) (int guild_id, int len, const char *data);
- int (*guild_castle_dataload) (int num, int *castle_ids);
- int (*guild_castle_datasave) (int castle_id, int index, int value);
- int (*request_petdata) (int account_id, int char_id, int pet_id);
- int (*save_petdata) (int account_id, struct s_pet *p);
- int (*delete_petdata) (int pet_id);
- int (*rename) (struct map_session_data *sd, int type, char *name);
- int (*homunculus_create) (int account_id, struct s_homunculus *sh);
- bool (*homunculus_requestload) (int account_id, int homun_id);
- int (*homunculus_requestsave) (int account_id, struct s_homunculus* sh);
- int (*homunculus_requestdelete) (int homun_id);
- /******QUEST SYTEM*******/
- int (*request_questlog) (struct map_session_data * sd);
- int (*quest_save) (struct map_session_data * sd);
- // MERCENARY SYSTEM
- int (*mercenary_create) (struct s_mercenary *merc);
- int (*mercenary_request) (int merc_id, int char_id);
- int (*mercenary_delete) (int merc_id);
- int (*mercenary_save) (struct s_mercenary *merc);
- // MAIL SYSTEM
- int (*Mail_requestinbox) (int char_id, unsigned char flag);
- int (*Mail_read) (int mail_id);
- int (*Mail_getattach) (int char_id, int mail_id);
- int (*Mail_delete) (int char_id, int mail_id);
- int (*Mail_return) (int char_id, int mail_id);
- int (*Mail_send) (int account_id, struct mail_message *msg);
- // AUCTION SYSTEM
- int (*Auction_requestlist) (int char_id, short type, int price, const char* searchtext, short page);
- int (*Auction_register) (struct auction_data *auction);
- int (*Auction_cancel) (int char_id, unsigned int auction_id);
- int (*Auction_close) (int char_id, unsigned int auction_id);
- int (*Auction_bid) (int char_id, const char* name, unsigned int auction_id, int bid);
- // ELEMENTAL SYSTEM
- int (*elemental_create) (struct s_elemental *ele);
- int (*elemental_request) (int ele_id, int char_id);
- int (*elemental_delete) (int ele_id);
- int (*elemental_save) (struct s_elemental *ele);
- /* @accinfo */
- void (*request_accinfo) (int u_fd, int aid, int group_lv, char* query);
-
- int (*CheckForCharServer) (void);
-} intif_s;
-
-struct intif_interface *intif;
-
-void intif_defaults(void);
-
-#endif /* _INTIF_H_ */
+// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
+// For more information, see LICENCE in the main folder
+#ifndef _INTIF_H_
+#define _INFIF_H_
+//#include "../common/mmo.h"
+struct party_member;
+struct guild_member;
+struct guild_position;
+struct s_pet;
+struct s_homunculus;
+struct s_mercenary;
+struct s_elemental;
+struct mail_message;
+struct auction_data;
+
+
+
+
+
+#define intif_rename_pc(sd, name) intif->rename(sd, 0, name)
+#define intif_rename_pet(sd, name) intif->rename(sd, 1, name)
+#define intif_rename_hom(sd, name) intif->rename(sd, 2, name)
+
+
+
+
+
+
+/*=====================================
+* Interface : intif.h
+* Generated by HerculesInterfaceMaker
+* created by Susu
+*-------------------------------------*/
+struct intif_interface {
+ /* funcs */
+
+
+ int (*parse) (int fd);
+
+ int (*create_pet)(int account_id, int char_id, short pet_type, short pet_lv, short pet_egg_id,
+ short pet_equip, short intimate, short hungry, char rename_flag, char incuvate, char *pet_name);
+
+ int (*broadcast) (const char* mes, int len, int type);
+ int (*broadcast2) (const char* mes, int len, unsigned long fontColor, short fontType, short fontSize, short fontAlign, short fontY);
+ int (*main_message) (struct map_session_data* sd, const char* message);
+
+ int (*wis_message) (struct map_session_data *sd,char *nick,char *mes,int mes_len);
+ int (*wis_message_to_gm) (char *Wisp_name, int permission, char *mes);
+
+ int (*saveregistry) (struct map_session_data *sd, int type);
+ int (*request_registry) (struct map_session_data *sd, int flag);
+
+ int (*request_guild_storage) (int account_id, int guild_id);
+ int (*send_guild_storage) (int account_id, struct guild_storage *gstor);
+
+ int (*create_party) (struct party_member *member,char *name,int item,int item2);
+ int (*request_partyinfo) (int party_id, int char_id);
+
+ int (*party_addmember) (int party_id,struct party_member *member);
+ int (*party_changeoption) (int party_id, int account_id, int exp, int item);
+ int (*party_leave) (int party_id,int account_id, int char_id);
+ int (*party_changemap) (struct map_session_data *sd, int online);
+ int (*break_party) (int party_id);
+ int (*party_message) (int party_id, int account_id, const char *mes,int len);
+ int (*party_leaderchange) (int party_id,int account_id,int char_id);
+
+ int (*guild_create) (const char *name, const struct guild_member *master);
+ int (*guild_request_info) (int guild_id);
+ int (*guild_addmember) (int guild_id, struct guild_member *m);
+ int (*guild_leave) (int guild_id, int account_id, int char_id, int flag, const char *mes);
+ int (*guild_memberinfoshort) (int guild_id, int account_id, int char_id, int online, int lv, int class_);
+ int (*guild_break) (int guild_id);
+ int (*guild_message) (int guild_id, int account_id, const char *mes, int len);
+ int (*guild_change_gm) (int guild_id, const char* name, int len);
+ int (*guild_change_basicinfo) (int guild_id, int type, const void *data, int len);
+ int (*guild_change_memberinfo) (int guild_id, int account_id, int char_id, int type, const void *data, int len);
+ int (*guild_position) (int guild_id, int idx, struct guild_position *p);
+ int (*guild_skillup) (int guild_id, uint16 skill_id, int account_id, int max);
+ int (*guild_alliance) (int guild_id1, int guild_id2, int account_id1, int account_id2, int flag);
+ int (*guild_notice) (int guild_id, const char *mes1, const char *mes2);
+ int (*guild_emblem) (int guild_id, int len, const char *data);
+ int (*guild_castle_dataload) (int num, int *castle_ids);
+ int (*guild_castle_datasave) (int castle_id, int index, int value);
+ int (*request_petdata) (int account_id, int char_id, int pet_id);
+ int (*save_petdata) (int account_id, struct s_pet *p);
+ int (*delete_petdata) (int pet_id);
+ int (*rename) (struct map_session_data *sd, int type, char *name);
+ int (*homunculus_create) (int account_id, struct s_homunculus *sh);
+ bool (*homunculus_requestload) (int account_id, int homun_id);
+ int (*homunculus_requestsave) (int account_id, struct s_homunculus* sh);
+ int (*homunculus_requestdelete) (int homun_id);
+ /******QUEST SYTEM*******/
+ int (*request_questlog) (struct map_session_data * sd);
+ int (*quest_save) (struct map_session_data * sd);
+ // MERCENARY SYSTEM
+ int (*mercenary_create) (struct s_mercenary *merc);
+ int (*mercenary_request) (int merc_id, int char_id);
+ int (*mercenary_delete) (int merc_id);
+ int (*mercenary_save) (struct s_mercenary *merc);
+ // MAIL SYSTEM
+ int (*Mail_requestinbox) (int char_id, unsigned char flag);
+ int (*Mail_read) (int mail_id);
+ int (*Mail_getattach) (int char_id, int mail_id);
+ int (*Mail_delete) (int char_id, int mail_id);
+ int (*Mail_return) (int char_id, int mail_id);
+ int (*Mail_send) (int account_id, struct mail_message *msg);
+ // AUCTION SYSTEM
+ int (*Auction_requestlist) (int char_id, short type, int price, const char* searchtext, short page);
+ int (*Auction_register) (struct auction_data *auction);
+ int (*Auction_cancel) (int char_id, unsigned int auction_id);
+ int (*Auction_close) (int char_id, unsigned int auction_id);
+ int (*Auction_bid) (int char_id, const char* name, unsigned int auction_id, int bid);
+ // ELEMENTAL SYSTEM
+ int (*elemental_create) (struct s_elemental *ele);
+ int (*elemental_request) (int ele_id, int char_id);
+ int (*elemental_delete) (int ele_id);
+ int (*elemental_save) (struct s_elemental *ele);
+ /* @accinfo */
+ void (*request_accinfo) (int u_fd, int aid, int group_lv, char* query);
+
+ int (*CheckForCharServer) (void);
+} intif_s;
+
+struct intif_interface *intif;
+
+void intif_defaults(void);
+
+#endif /* _INTIF_H_ */
diff --git a/src/map/itemdb.c b/src/map/itemdb.c
index fcd4ccbc1..c2a25c2d4 100644
--- a/src/map/itemdb.c
+++ b/src/map/itemdb.c
@@ -19,11 +19,6 @@
#include <stdlib.h>
#include <string.h>
-static struct item_data* itemdb_array[MAX_ITEMDB];
-static DBMap* itemdb_other;// int nameid -> struct item_data*
-
-struct item_data dummy_item; //This is the default dummy item used for non-existant items. [Skotlex]
-
struct itemdb_interface itemdb_s;
/**
@@ -31,14 +26,14 @@ struct itemdb_interface itemdb_s;
* name = item alias, so we should find items aliases first. if not found then look for "jname" (full name)
* @see DBApply
*/
-static int itemdb_searchname_sub(DBKey key, DBData *data, va_list ap)
+int itemdb_searchname_sub(DBKey key, DBData *data, va_list ap)
{
struct item_data *item = DB->data2ptr(data), **dst, **dst2;
char *str;
str=va_arg(ap,char *);
dst=va_arg(ap,struct item_data **);
dst2=va_arg(ap,struct item_data **);
- if(item == &dummy_item) return 0;
+ if(item == &itemdb->dummy) return 0;
//Absolute priority to Aegis code name.
if (*dst != NULL) return 0;
@@ -60,8 +55,8 @@ struct item_data* itemdb_searchname(const char *str) {
struct item_data* item2=NULL;
int i;
- for( i = 0; i < ARRAYLENGTH(itemdb_array); ++i ) {
- item = itemdb_array[i];
+ for( i = 0; i < ARRAYLENGTH(itemdb->array); ++i ) {
+ item = itemdb->array[i];
if( item == NULL )
continue;
@@ -75,7 +70,7 @@ struct item_data* itemdb_searchname(const char *str) {
}
item = NULL;
- itemdb_other->foreach(itemdb_other,itemdb_searchname_sub,str,&item,&item2);
+ itemdb->other->foreach(itemdb->other,itemdb->searchname_sub,str,&item,&item2);
return item?item:item2;
}
/* name to item data */
@@ -86,12 +81,12 @@ struct item_data* itemdb_name2id(const char *str) {
/**
* @see DBMatcher
*/
-static int itemdb_searchname_array_sub(DBKey key, DBData data, va_list ap)
+int itemdb_searchname_array_sub(DBKey key, DBData data, va_list ap)
{
struct item_data *item = DB->data2ptr(&data);
char *str;
str=va_arg(ap,char *);
- if (item == &dummy_item)
+ if (item == &itemdb->dummy)
return 1; //Invalid item.
if(stristr(item->jname,str))
return 0;
@@ -112,9 +107,9 @@ int itemdb_searchname_array(struct item_data** data, int size, const char *str,
int count=0;
// Search in the array
- for( i = 0; i < ARRAYLENGTH(itemdb_array); ++i )
+ for( i = 0; i < ARRAYLENGTH(itemdb->array); ++i )
{
- item = itemdb_array[i];
+ item = itemdb->array[i];
if( item == NULL )
continue;
@@ -133,7 +128,7 @@ int itemdb_searchname_array(struct item_data** data, int size, const char *str,
DBData *db_data[MAX_SEARCH];
int db_count = 0;
size -= count;
- db_count = itemdb_other->getall(itemdb_other, (DBData**)&db_data, size, itemdb_searchname_array_sub, str);
+ db_count = itemdb->other->getall(itemdb->other, (DBData**)&db_data, size, itemdb->searchname_array_sub, str);
for (i = 0; i < db_count; i++)
data[count++] = DB->data2ptr(db_data[i]);
count += db_count;
@@ -190,7 +185,7 @@ void itemdb_package_item(struct map_session_data *sd, struct item_package *packa
if( package->must_items[i].announce )
clif->package_announce(sd,package->must_items[i].id,package->id);
- get_count = itemdb_isstackable(package->must_items[i].id) ? package->must_items[i].qty : 1;
+ get_count = itemdb->isstackable(package->must_items[i].id) ? package->must_items[i].qty : 1;
it.amount = get_count == 1 ? 1 : get_count;
@@ -231,7 +226,7 @@ void itemdb_package_item(struct map_session_data *sd, struct item_package *packa
if( entry->announce )
clif->package_announce(sd,entry->id,package->id);
- get_count = itemdb_isstackable(entry->id) ? entry->qty : 1;
+ get_count = itemdb->isstackable(entry->id) ? entry->qty : 1;
it.amount = get_count == 1 ? 1 : get_count;
@@ -274,10 +269,10 @@ struct item_data* itemdb_exists(int nameid)
{
struct item_data* item;
- if( nameid >= 0 && nameid < ARRAYLENGTH(itemdb_array) )
- return itemdb_array[nameid];
- item = (struct item_data*)idb_get(itemdb_other,nameid);
- if( item == &dummy_item )
+ if( nameid >= 0 && nameid < ARRAYLENGTH(itemdb->array) )
+ return itemdb->array[nameid];
+ item = (struct item_data*)idb_get(itemdb->other,nameid);
+ if( item == &itemdb->dummy )
return NULL;// dummy data, doesn't exist
return item;
}
@@ -307,7 +302,7 @@ const char* itemdb_typename(int type)
* Converts the jobid from the format in itemdb
* to the format used by the map server. [Skotlex]
*------------------------------------------*/
-static void itemdb_jobid2mapid(unsigned int *bclass, unsigned int jobmask)
+void itemdb_jobid2mapid(unsigned int *bclass, unsigned int jobmask)
{
int i;
bclass[0]= bclass[1]= bclass[2]= 0;
@@ -373,19 +368,19 @@ static void itemdb_jobid2mapid(unsigned int *bclass, unsigned int jobmask)
bclass[1] |= 1<<MAPID_NINJA;
}
-static void create_dummy_data(void)
+void create_dummy_data(void)
{
- memset(&dummy_item, 0, sizeof(struct item_data));
- dummy_item.nameid=500;
- dummy_item.weight=1;
- dummy_item.value_sell=1;
- dummy_item.type=IT_ETC; //Etc item
- safestrncpy(dummy_item.name,"UNKNOWN_ITEM",sizeof(dummy_item.name));
- safestrncpy(dummy_item.jname,"UNKNOWN_ITEM",sizeof(dummy_item.jname));
- dummy_item.view_id=UNKNOWN_ITEM_ID;
+ memset(&itemdb->dummy, 0, sizeof(struct item_data));
+ itemdb->dummy.nameid=500;
+ itemdb->dummy.weight=1;
+ itemdb->dummy.value_sell=1;
+ itemdb->dummy.type=IT_ETC; //Etc item
+ safestrncpy(itemdb->dummy.name,"UNKNOWN_ITEM",sizeof(itemdb->dummy.name));
+ safestrncpy(itemdb->dummy.jname,"UNKNOWN_ITEM",sizeof(itemdb->dummy.jname));
+ itemdb->dummy.view_id=UNKNOWN_ITEM_ID;
}
-static struct item_data* create_item_data(int nameid)
+struct item_data* create_item_data(int nameid)
{
struct item_data *id;
CREATE(id, struct item_data, 1);
@@ -401,19 +396,19 @@ static struct item_data* create_item_data(int nameid)
struct item_data* itemdb_load(int nameid) {
struct item_data *id;
- if( nameid >= 0 && nameid < ARRAYLENGTH(itemdb_array) )
+ if( nameid >= 0 && nameid < ARRAYLENGTH(itemdb->array) )
{
- id = itemdb_array[nameid];
- if( id == NULL || id == &dummy_item )
- id = itemdb_array[nameid] = create_item_data(nameid);
+ id = itemdb->array[nameid];
+ if( id == NULL || id == &itemdb->dummy )
+ id = itemdb->array[nameid] = itemdb->create_item_data(nameid);
return id;
}
- id = (struct item_data*)idb_get(itemdb_other, nameid);
- if( id == NULL || id == &dummy_item )
+ id = (struct item_data*)idb_get(itemdb->other, nameid);
+ if( id == NULL || id == &itemdb->dummy )
{
- id = create_item_data(nameid);
- idb_put(itemdb_other, nameid, id);
+ id = itemdb->create_item_data(nameid);
+ idb_put(itemdb->other, nameid, id);
}
return id;
}
@@ -424,16 +419,16 @@ struct item_data* itemdb_load(int nameid) {
struct item_data* itemdb_search(int nameid)
{
struct item_data* id;
- if( nameid >= 0 && nameid < ARRAYLENGTH(itemdb_array) )
- id = itemdb_array[nameid];
+ if( nameid >= 0 && nameid < ARRAYLENGTH(itemdb->array) )
+ id = itemdb->array[nameid];
else
- id = (struct item_data*)idb_get(itemdb_other, nameid);
+ id = (struct item_data*)idb_get(itemdb->other, nameid);
if( id == NULL )
{
ShowWarning("itemdb_search: Item ID %d does not exists in the item_db. Using dummy data.\n", nameid);
- id = &dummy_item;
- dummy_item.nameid = nameid;
+ id = &itemdb->dummy;
+ itemdb->dummy.nameid = nameid;
}
return id;
}
@@ -546,7 +541,7 @@ int itemdb_canauction_sub(struct item_data* item, int gmlv, int unused) {
int itemdb_isrestricted(struct item* item, int gmlv, int gmlv2, int (*func)(struct item_data*, int, int))
{
- struct item_data* item_data = itemdb_search(item->nameid);
+ struct item_data* item_data = itemdb->search(item->nameid);
int i;
if (!func(item_data, gmlv, gmlv2))
@@ -557,7 +552,7 @@ int itemdb_isrestricted(struct item* item, int gmlv, int gmlv2, int (*func)(stru
for(i = 0; i < item_data->slot; i++) {
if (!item->card[i]) continue;
- if (!func(itemdb_search(item->card[i]), gmlv, gmlv2))
+ if (!func(itemdb->search(item->card[i]), gmlv, gmlv2))
return 0;
}
return 1;
@@ -594,7 +589,7 @@ int itemdb_isidentified2(struct item_data *data) {
* Search by name for the override flags available items
* (Give item another sprite)
*------------------------------------------*/
-static bool itemdb_read_itemavail(char* str[], int columns, int current)
+bool itemdb_read_itemavail(char* str[], int columns, int current)
{// <nameid>,<sprite>
int nameid, sprite;
struct item_data *id;
@@ -1202,7 +1197,7 @@ void itemdb_read_chains(void) {
/*==========================================
* Reads item trade restrictions [Skotlex]
*------------------------------------------*/
-static bool itemdb_read_itemtrade(char* str[], int columns, int current)
+bool itemdb_read_itemtrade(char* str[], int columns, int current)
{// <nameid>,<mask>,<gm level>
int nameid, flag, gmlv;
struct item_data *id;
@@ -1239,7 +1234,7 @@ static bool itemdb_read_itemtrade(char* str[], int columns, int current)
/*==========================================
* Reads item delay amounts [Paradox924X]
*------------------------------------------*/
-static bool itemdb_read_itemdelay(char* str[], int columns, int current)
+bool itemdb_read_itemdelay(char* str[], int columns, int current)
{// <nameid>,<delay>
int nameid, delay;
struct item_data *id;
@@ -1268,7 +1263,7 @@ static bool itemdb_read_itemdelay(char* str[], int columns, int current)
/*==================================================================
* Reads item stacking restrictions
*----------------------------------------------------------------*/
-static bool itemdb_read_stack(char* fields[], int columns, int current)
+bool itemdb_read_stack(char* fields[], int columns, int current)
{// <item id>,<stack limit amount>,<type>
unsigned short nameid, amount;
unsigned int type;
@@ -1282,7 +1277,7 @@ static bool itemdb_read_stack(char* fields[], int columns, int current)
return false;
}
- if( !itemdb_isstackable2(id) )
+ if( !itemdb->isstackable2(id) )
{
ShowWarning("itemdb_read_stack: Item id '%hu' is not stackable.\n", nameid);
return false;
@@ -1307,7 +1302,7 @@ static bool itemdb_read_stack(char* fields[], int columns, int current)
/// Reads items allowed to be sold in buying stores
-static bool itemdb_read_buyingstore(char* fields[], int columns, int current)
+bool itemdb_read_buyingstore(char* fields[], int columns, int current)
{// <nameid>
int nameid;
struct item_data* id;
@@ -1320,7 +1315,7 @@ static bool itemdb_read_buyingstore(char* fields[], int columns, int current)
return false;
}
- if( !itemdb_isstackable2(id) )
+ if( !itemdb->isstackable2(id) )
{
ShowWarning("itemdb_read_buyingstore: Non-stackable item id %d cannot be enabled for buying store.\n", nameid);
return false;
@@ -1334,7 +1329,7 @@ static bool itemdb_read_buyingstore(char* fields[], int columns, int current)
/*******************************************
** Item usage restriction (item_nouse.txt)
********************************************/
-static bool itemdb_read_nouse(char* fields[], int columns, int current)
+bool itemdb_read_nouse(char* fields[], int columns, int current)
{// <nameid>,<flag>,<override>
int nameid, flag, override;
struct item_data* id;
@@ -1443,7 +1438,7 @@ void itemdb_read_combos() {
struct item_data * id = NULL;
int idx = 0;
- if((retcount = itemdb_combo_split_atoi(str[0], items)) < 2) {
+ if((retcount = itemdb->combo_split_atoi(str[0], items)) < 2) {
ShowError("itemdb_read_combos: line %d of \"%s\" doesn't have enough items to make for a combo (min:2), skipping.\n", lines, path);
continue;
}
@@ -1524,7 +1519,7 @@ void itemdb_read_combos() {
/*======================================
* Applies gender restrictions according to settings. [Skotlex]
*======================================*/
-static int itemdb_gendercheck(struct item_data *id)
+int itemdb_gendercheck(struct item_data *id)
{
if (id->nameid == WEDDING_RING_M) //Grom Ring
return 1;
@@ -1588,7 +1583,7 @@ int itemdb_parse_dbrow(char** str, const char* source, int line, int scriptopt)
}
//ID,Name,Jname,Type,Price,Sell,Weight,ATK,DEF,Range,Slot,Job,Job Upper,Gender,Loc,wLV,eLV,refineable,View
- id = itemdb_load(nameid);
+ id = itemdb->load(nameid);
safestrncpy(id->name, str[1], sizeof(id->name));
safestrncpy(id->jname, str[2], sizeof(id->jname));
@@ -1637,7 +1632,7 @@ int itemdb_parse_dbrow(char** str, const char* source, int line, int scriptopt)
id->matk = atoi(str[8]);
offset += 1;
} else
- itemdb_re_split_atoi(str[7],&id->atk,&id->matk);
+ itemdb->re_split_atoi(str[7],&id->atk,&id->matk);
#else
id->atk = atoi(str[7]);
#endif
@@ -1650,12 +1645,12 @@ int itemdb_parse_dbrow(char** str, const char* source, int line, int scriptopt)
id->slot = MAX_SLOTS;
}
- itemdb_jobid2mapid(id->class_base, (unsigned int)strtoul(str[11+offset],NULL,0));
+ itemdb->jobid2mapid(id->class_base, (unsigned int)strtoul(str[11+offset],NULL,0));
id->class_upper = atoi(str[12+offset]);
id->sex = atoi(str[13+offset]);
id->equip = atoi(str[14+offset]);
- if (!id->equip && itemdb_isequip2(id)) {
+ if (!id->equip && itemdb->isequip2(id)) {
ShowWarning("Item %d (%s) is an equipment with no equip-field! Making it an etc item.\n", nameid, id->jname);
id->type = IT_ETC;
}
@@ -1667,7 +1662,7 @@ int itemdb_parse_dbrow(char** str, const char* source, int line, int scriptopt)
id->elvmax = atoi(str[17+offset]);
offset += 1;
} else
- itemdb_re_split_atoi(str[16],&id->elv,&id->elvmax);
+ itemdb->re_split_atoi(str[16],&id->elv,&id->elvmax);
#else
id->elv = atoi(str[16]);
#endif
@@ -1676,7 +1671,7 @@ int itemdb_parse_dbrow(char** str, const char* source, int line, int scriptopt)
id->flag.available = 1;
id->view_id = 0;
- id->sex = itemdb_gendercheck(id); //Apply gender filtering.
+ id->sex = itemdb->gendercheck(id); //Apply gender filtering.
if (id->script) {
script->free_code(id->script);
@@ -1705,7 +1700,7 @@ int itemdb_parse_dbrow(char** str, const char* source, int line, int scriptopt)
* Reading item from item db
* item_db2 overwriting item_db
*------------------------------------------*/
-static int itemdb_readdb(void)
+int itemdb_readdb(void)
{
const char* filename[] = {
DBPATH"item_db.txt",
@@ -1831,7 +1826,7 @@ static int itemdb_readdb(void)
/*======================================
* item_db table reading
*======================================*/
-static int itemdb_read_sqldb(void) {
+int itemdb_read_sqldb(void) {
const char* item_db_name[] = {
#ifdef RENEWAL
@@ -1914,7 +1909,7 @@ int itemdb_uid_load() {
}
SQL->GetData(mmysql_handle, 0, &uid, NULL);
- itemdb_unique_id(1, (uint64)strtoull(uid, NULL, 10));
+ itemdb->unique_id(1, (uint64)strtoull(uid, NULL, 10));
SQL->FreeResult(mmysql_handle);
return 0;
@@ -1923,37 +1918,37 @@ int itemdb_uid_load() {
/*====================================
* read all item-related databases
*------------------------------------*/
-static void itemdb_read(void) {
+void itemdb_read(void) {
int i;
DBData prev;
if (iMap->db_use_sql_item_db)
- itemdb_read_sqldb();
+ itemdb->read_sqldb();
else
- itemdb_readdb();
+ itemdb->readdb();
- for( i = 0; i < ARRAYLENGTH(itemdb_array); ++i ) {
- if( itemdb_array[i] ) {
- if( itemdb->names->put(itemdb->names,DB->str2key(itemdb_array[i]->name),DB->ptr2data(itemdb_array[i]),&prev) ) {
+ for( i = 0; i < ARRAYLENGTH(itemdb->array); ++i ) {
+ if( itemdb->array[i] ) {
+ if( itemdb->names->put(itemdb->names,DB->str2key(itemdb->array[i]->name),DB->ptr2data(itemdb->array[i]),&prev) ) {
struct item_data *data = DB->data2ptr(&prev);
- ShowError("itemdb_read: duplicate AegisName '%s' in item ID %d and %d\n",itemdb_array[i]->name,itemdb_array[i]->nameid,data->nameid);
+ ShowError("itemdb_read: duplicate AegisName '%s' in item ID %d and %d\n",itemdb->array[i]->name,itemdb->array[i]->nameid,data->nameid);
}
}
}
- itemdb_read_combos();
+ itemdb->read_combos();
itemdb->read_groups();
itemdb->read_chains();
itemdb->read_packages();
- sv->readdb(iMap->db_path, "item_avail.txt", ',', 2, 2, -1, &itemdb_read_itemavail);
- sv->readdb(iMap->db_path, DBPATH"item_trade.txt", ',', 3, 3, -1, &itemdb_read_itemtrade);
- sv->readdb(iMap->db_path, "item_delay.txt", ',', 2, 2, -1, &itemdb_read_itemdelay);
- sv->readdb(iMap->db_path, "item_stack.txt", ',', 3, 3, -1, &itemdb_read_stack);
- sv->readdb(iMap->db_path, DBPATH"item_buyingstore.txt", ',', 1, 1, -1, &itemdb_read_buyingstore);
- sv->readdb(iMap->db_path, "item_nouse.txt", ',', 3, 3, -1, &itemdb_read_nouse);
+ sv->readdb(iMap->db_path, "item_avail.txt", ',', 2, 2, -1, itemdb->read_itemavail);
+ sv->readdb(iMap->db_path, DBPATH"item_trade.txt", ',', 3, 3, -1, itemdb->read_itemtrade);
+ sv->readdb(iMap->db_path, "item_delay.txt", ',', 2, 2, -1, itemdb->read_itemdelay);
+ sv->readdb(iMap->db_path, "item_stack.txt", ',', 3, 3, -1, itemdb->read_stack);
+ sv->readdb(iMap->db_path, DBPATH"item_buyingstore.txt", ',', 1, 1, -1, itemdb->read_buyingstore);
+ sv->readdb(iMap->db_path, "item_nouse.txt", ',', 3, 3, -1, itemdb->read_nouse);
- itemdb_uid_load();
+ itemdb->uid_load();
}
/*==========================================
@@ -1961,7 +1956,7 @@ static void itemdb_read(void) {
*------------------------------------------*/
/// Destroys the item_data.
-static void destroy_item_data(struct item_data* self, int free_self)
+void destroy_item_data(struct item_data* self, int free_self)
{
if( self == NULL )
return;
@@ -1995,12 +1990,12 @@ static void destroy_item_data(struct item_data* self, int free_self)
/**
* @see DBApply
*/
-static int itemdb_final_sub(DBKey key, DBData *data, va_list ap)
+int itemdb_final_sub(DBKey key, DBData *data, va_list ap)
{
struct item_data *id = DB->data2ptr(data);
- if( id != &dummy_item )
- destroy_item_data(id, 1);
+ if( id != &itemdb->dummy )
+ itemdb->destroy_item_data(id, 1);
return 0;
}
@@ -2012,9 +2007,9 @@ void itemdb_reload(void) {
int i,d,k;
// clear the previous itemdb data
- for( i = 0; i < ARRAYLENGTH(itemdb_array); ++i )
- if( itemdb_array[i] )
- destroy_item_data(itemdb_array[i], 1);
+ for( i = 0; i < ARRAYLENGTH(itemdb->array); ++i )
+ if( itemdb->array[i] )
+ itemdb->destroy_item_data(itemdb->array[i], 1);
for( i = 0; i < itemdb->group_count; i++ ) {
if( itemdb->groups[i].nameid )
@@ -2054,14 +2049,14 @@ void itemdb_reload(void) {
itemdb->packages = NULL;
itemdb->package_count = 0;
- itemdb_other->clear(itemdb_other, itemdb_final_sub);
+ itemdb->other->clear(itemdb->other, itemdb->final_sub);
- memset(itemdb_array, 0, sizeof(itemdb_array));
+ memset(itemdb->array, 0, sizeof(itemdb->array));
db_clear(itemdb->names);
// read new data
- itemdb_read();
+ itemdb->read();
//Epoque's awesome @reloaditemdb fix - thanks! [Ind]
//- Fixes the need of a @reloadmobdb after a @reloaditemdb to re-link monster drop data
@@ -2069,12 +2064,12 @@ void itemdb_reload(void) {
struct mob_db *entry;
if( !((i < 1324 || i > 1363) && (i < 1938 || i > 1946)) )
continue;
- entry = mob_db(i);
+ entry = mob->db(i);
for(d = 0; d < MAX_MOB_DROP; d++) {
struct item_data *id;
if( !entry->dropitem[d].nameid )
continue;
- id = itemdb_search(entry->dropitem[d].nameid);
+ id = itemdb->search(entry->dropitem[d].nameid);
for (k = 0; k < MAX_SEARCH; k++) {
if (id->mob[k].chance <= entry->dropitem[d].p)
@@ -2132,9 +2127,9 @@ void itemdb_force_name_constants(void) {
void do_final_itemdb(void) {
int i;
- for( i = 0; i < ARRAYLENGTH(itemdb_array); ++i )
- if( itemdb_array[i] )
- destroy_item_data(itemdb_array[i], 1);
+ for( i = 0; i < ARRAYLENGTH(itemdb->array); ++i )
+ if( itemdb->array[i] )
+ itemdb->destroy_item_data(itemdb->array[i], 1);
for( i = 0; i < itemdb->group_count; i++ ) {
if( itemdb->groups[i].nameid )
@@ -2165,26 +2160,25 @@ void do_final_itemdb(void) {
if( itemdb->packages )
aFree(itemdb->packages);
- itemdb_other->destroy(itemdb_other, itemdb_final_sub);
- destroy_item_data(&dummy_item, 0);
+ itemdb->other->destroy(itemdb->other, itemdb->final_sub);
+ itemdb->destroy_item_data(&itemdb->dummy, 0);
db_destroy(itemdb->names);
}
void do_init_itemdb(void) {
- memset(itemdb_array, 0, sizeof(itemdb_array));
- itemdb_other = idb_alloc(DB_OPT_BASE);
+ memset(itemdb->array, 0, sizeof(itemdb->array));
+ itemdb->other = idb_alloc(DB_OPT_BASE);
itemdb->names = strdb_alloc(DB_OPT_BASE,ITEM_NAME_LENGTH);
- create_dummy_data(); //Dummy data item.
- itemdb_read();
+ itemdb->create_dummy_data(); //Dummy data item.
+ itemdb->read();
clif->cashshop_load();
}
-/* incomplete */
void itemdb_defaults(void) {
itemdb = &itemdb_s;
itemdb->init = do_init_itemdb;
itemdb->final = do_final_itemdb;
- itemdb->reload = itemdb_reload;//incomplete
+ itemdb->reload = itemdb_reload;
itemdb->name_constants = itemdb_name_constants;
itemdb->force_name_constants = itemdb_force_name_constants;
/* */
@@ -2199,6 +2193,10 @@ void itemdb_defaults(void) {
/* */
itemdb->names = NULL;
/* */
+ /* itemdb->array is cleared on itemdb->init() */
+ itemdb->other = NULL;
+ memset(&itemdb->dummy, 0, sizeof(struct item_data));
+ /* */
itemdb->read_groups = itemdb_read_groups;
itemdb->read_chains = itemdb_read_chains;
itemdb->read_packages = itemdb_read_packages;
@@ -2212,9 +2210,49 @@ void itemdb_defaults(void) {
itemdb->load = itemdb_load;
itemdb->search = itemdb_search;
itemdb->parse_dbrow = itemdb_parse_dbrow;
- itemdb->exists = itemdb_exists;//incomplete
+ itemdb->exists = itemdb_exists;
itemdb->in_group = itemdb_in_group;
itemdb->group_item = itemdb_searchrandomid;
itemdb->chain_item = itemdb_chain_item;
itemdb->package_item = itemdb_package_item;
+ itemdb->searchname_sub = itemdb_searchname_sub;
+ itemdb->searchname_array_sub = itemdb_searchname_array_sub;
+ itemdb->searchrandomid = itemdb_searchrandomid;
+ itemdb->typename = itemdb_typename;
+ itemdb->jobid2mapid = itemdb_jobid2mapid;
+ itemdb->create_dummy_data = create_dummy_data;
+ itemdb->create_item_data = create_item_data;
+ itemdb->isequip = itemdb_isequip;
+ itemdb->isequip2 = itemdb_isequip2;
+ itemdb->isstackable = itemdb_isstackable;
+ itemdb->isstackable2 = itemdb_isstackable2;
+ itemdb->isdropable_sub = itemdb_isdropable_sub;
+ itemdb->cantrade_sub = itemdb_cantrade_sub;
+ itemdb->canpartnertrade_sub = itemdb_canpartnertrade_sub;
+ itemdb->cansell_sub = itemdb_cansell_sub;
+ itemdb->cancartstore_sub = itemdb_cancartstore_sub;
+ itemdb->canstore_sub = itemdb_canstore_sub;
+ itemdb->canguildstore_sub = itemdb_canguildstore_sub;
+ itemdb->canmail_sub = itemdb_canmail_sub;
+ itemdb->canauction_sub = itemdb_canauction_sub;
+ itemdb->isrestricted = itemdb_isrestricted;
+ itemdb->isidentified = itemdb_isidentified;
+ itemdb->isidentified2 = itemdb_isidentified2;
+ itemdb->read_itemavail = itemdb_read_itemavail;
+ itemdb->read_itemtrade = itemdb_read_itemtrade;
+ itemdb->read_itemdelay = itemdb_read_itemdelay;
+ itemdb->read_stack = itemdb_read_stack;
+ itemdb->read_buyingstore = itemdb_read_buyingstore;
+ itemdb->read_nouse = itemdb_read_nouse;
+ itemdb->combo_split_atoi = itemdb_combo_split_atoi;
+ itemdb->read_combos = itemdb_read_combos;
+ itemdb->gendercheck = itemdb_gendercheck;
+ itemdb->re_split_atoi = itemdb_re_split_atoi;
+ itemdb->readdb = itemdb_readdb;
+ itemdb->read_sqldb = itemdb_read_sqldb;
+ itemdb->unique_id = itemdb_unique_id;
+ itemdb->uid_load = itemdb_uid_load;
+ itemdb->read = itemdb_read;
+ itemdb->destroy_item_data = destroy_item_data;
+ itemdb->final_sub = itemdb_final_sub;
}
diff --git a/src/map/itemdb.h b/src/map/itemdb.h
index 126ba6334..fe67ebbef 100644
--- a/src/map/itemdb.h
+++ b/src/map/itemdb.h
@@ -240,41 +240,21 @@ struct item_package {
#define itemdb_iscashfood(id) ( (id) >= 12202 && (id) <= 12207 )
#define itemdb_is_GNbomb(n) (n >= 13260 && n <= 13267)
#define itemdb_is_GNthrowable(n) (n >= 13268 && n <= 13290)
-const char* itemdb_typename(int type);
#define itemdb_value_buy(n) itemdb->search(n)->value_buy
#define itemdb_value_sell(n) itemdb->search(n)->value_sell
#define itemdb_canrefine(n) (!itemdb->search(n)->flag.no_refine)
//Item trade restrictions [Skotlex]
-int itemdb_isdropable_sub(struct item_data *, int, int);
-int itemdb_cantrade_sub(struct item_data*, int, int);
-int itemdb_canpartnertrade_sub(struct item_data*, int, int);
-int itemdb_cansell_sub(struct item_data*,int, int);
-int itemdb_cancartstore_sub(struct item_data*, int, int);
-int itemdb_canstore_sub(struct item_data*, int, int);
-int itemdb_canguildstore_sub(struct item_data*, int, int);
-int itemdb_canmail_sub(struct item_data*, int, int);
-int itemdb_canauction_sub(struct item_data*, int, int);
-int itemdb_isrestricted(struct item* item, int gmlv, int gmlv2, int (*func)(struct item_data*, int, int));
-#define itemdb_isdropable(item, gmlv) itemdb_isrestricted(item, gmlv, 0, itemdb_isdropable_sub)
-#define itemdb_cantrade(item, gmlv, gmlv2) itemdb_isrestricted(item, gmlv, gmlv2, itemdb_cantrade_sub)
-#define itemdb_canpartnertrade(item, gmlv, gmlv2) itemdb_isrestricted(item, gmlv, gmlv2, itemdb_canpartnertrade_sub)
-#define itemdb_cansell(item, gmlv) itemdb_isrestricted(item, gmlv, 0, itemdb_cansell_sub)
-#define itemdb_cancartstore(item, gmlv) itemdb_isrestricted(item, gmlv, 0, itemdb_cancartstore_sub)
-#define itemdb_canstore(item, gmlv) itemdb_isrestricted(item, gmlv, 0, itemdb_canstore_sub)
-#define itemdb_canguildstore(item, gmlv) itemdb_isrestricted(item , gmlv, 0, itemdb_canguildstore_sub)
-#define itemdb_canmail(item, gmlv) itemdb_isrestricted(item , gmlv, 0, itemdb_canmail_sub)
-#define itemdb_canauction(item, gmlv) itemdb_isrestricted(item , gmlv, 0, itemdb_canauction_sub)
+#define itemdb_isdropable(item, gmlv) itemdb->isrestricted(item, gmlv, 0, itemdb->isdropable_sub)
+#define itemdb_cantrade(item, gmlv, gmlv2) itemdb->isrestricted(item, gmlv, gmlv2, itemdb->cantrade_sub)
+#define itemdb_canpartnertrade(item, gmlv, gmlv2) itemdb->isrestricted(item, gmlv, gmlv2, itemdb->canpartnertrade_sub)
+#define itemdb_cansell(item, gmlv) itemdb->isrestricted(item, gmlv, 0, itemdb->cansell_sub)
+#define itemdb_cancartstore(item, gmlv) itemdb->isrestricted(item, gmlv, 0, itemdb->cancartstore_sub)
+#define itemdb_canstore(item, gmlv) itemdb->isrestricted(item, gmlv, 0, itemdb->canstore_sub)
+#define itemdb_canguildstore(item, gmlv) itemdb->isrestricted(item , gmlv, 0, itemdb->canguildstore_sub)
+#define itemdb_canmail(item, gmlv) itemdb->isrestricted(item , gmlv, 0, itemdb->canmail_sub)
+#define itemdb_canauction(item, gmlv) itemdb->isrestricted(item , gmlv, 0, itemdb->canauction_sub)
-int itemdb_isequip(int);
-int itemdb_isequip2(struct item_data *);
-int itemdb_isidentified(int);
-int itemdb_isidentified2(struct item_data *data);
-int itemdb_isstackable(int);
-int itemdb_isstackable2(struct item_data *);
-uint64 itemdb_unique_id(int8 flag, int64 value); // Unique Item ID
-
-/* incomplete */
struct itemdb_interface {
void (*init) (void);
void (*final) (void);
@@ -294,6 +274,10 @@ struct itemdb_interface {
/* */
DBMap *names;
/* */
+ struct item_data *array[MAX_ITEMDB];
+ DBMap *other;// int nameid -> struct item_data*
+ struct item_data dummy; //This is the default dummy item used for non-existant items. [Skotlex]
+ /* */
void (*read_groups) (void);
void (*read_chains) (void);
void (*read_packages) (void);
@@ -312,6 +296,46 @@ struct itemdb_interface {
int (*group_item) (struct item_group *group);
int (*chain_item) (unsigned short chain_id, int *rate);
void (*package_item) (struct map_session_data *sd, struct item_package *package);
+ int (*searchname_sub) (DBKey key, DBData *data, va_list ap);
+ int (*searchname_array_sub) (DBKey key, DBData data, va_list ap);
+ int (*searchrandomid) (struct item_group *group);
+ const char* (*typename) (int type);
+ void (*jobid2mapid) (unsigned int *bclass, unsigned int jobmask);
+ void (*create_dummy_data) (void);
+ struct item_data* (*create_item_data) (int nameid);
+ int (*isequip) (int nameid);
+ int (*isequip2) (struct item_data *data);
+ int (*isstackable) (int nameid);
+ int (*isstackable2) (struct item_data *data);
+ int (*isdropable_sub) (struct item_data *item, int gmlv, int unused);
+ int (*cantrade_sub) (struct item_data *item, int gmlv, int gmlv2);
+ int (*canpartnertrade_sub) (struct item_data *item, int gmlv, int gmlv2);
+ int (*cansell_sub) (struct item_data *item, int gmlv, int unused);
+ int (*cancartstore_sub) (struct item_data *item, int gmlv, int unused);
+ int (*canstore_sub) (struct item_data *item, int gmlv, int unused);
+ int (*canguildstore_sub) (struct item_data *item, int gmlv, int unused);
+ int (*canmail_sub) (struct item_data *item, int gmlv, int unused);
+ int (*canauction_sub) (struct item_data *item, int gmlv, int unused);
+ int (*isrestricted) (struct item *item, int gmlv, int gmlv2, int(*func)(struct item_data *, int, int));
+ int (*isidentified) (int nameid);
+ int (*isidentified2) (struct item_data *data);
+ bool (*read_itemavail) (char *str[], int columns, int current);
+ bool (*read_itemtrade) (char *str[], int columns, int current);
+ bool (*read_itemdelay) (char *str[], int columns, int current);
+ bool (*read_stack) (char *fields[], int columns, int current);
+ bool (*read_buyingstore) (char *fields[], int columns, int current);
+ bool (*read_nouse) (char *fields[], int columns, int current);
+ int (*combo_split_atoi) (char *str, int *val);
+ void (*read_combos) ();
+ int (*gendercheck) (struct item_data *id);
+ void (*re_split_atoi) (char *str, int *atk, int *matk);
+ int (*readdb) (void);
+ int (*read_sqldb) (void);
+ uint64 (*unique_id) (int8 flag, int64 value);
+ int (*uid_load) ();
+ void (*read) (void);
+ void (*destroy_item_data) (struct item_data *self, int free_self);
+ int (*final_sub) (DBKey key, DBData *data, va_list ap);
};
struct itemdb_interface *itemdb;
diff --git a/src/map/map.c b/src/map/map.c
index cbef8ca95..d4568766a 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;
}
@@ -810,7 +810,7 @@ static int bl_vgetall_inshootrange(struct block_list *bl, va_list args)
if (!check_distance_bl(center, bl, range))
return 0;
#endif
- if (!path_search_long(NULL, center->m, center->x, center->y, bl->x, bl->y, CELL_CHKWALL))
+ if (!path->search_long(NULL, center->m, center->x, center->y, bl->x, bl->y, CELL_CHKWALL))
return 0;
return 1;
}
@@ -1039,7 +1039,7 @@ static int bl_vgetall_inpath(struct block_list *bl, va_list args)
if ( k < 0 || k > len_limit ) //Since more skills use this, check for ending point as well.
return 0;
- if ( k > magnitude2 && !path_search_long(NULL, m, x0, y0, xi, yi, CELL_CHKWALL) )
+ if ( k > magnitude2 && !path->search_long(NULL, m, x0, y0, xi, yi, CELL_CHKWALL) )
return 0; //Targets beyond the initial ending point need the wall check.
//All these shifts are to increase the precision of the intersection point and distance considering how it's
@@ -1187,7 +1187,7 @@ int map_clearflooritem_timer(int tid, unsigned int tick, int id, intptr_t data)
}
- if (search_petDB_index(fitem->item_data.nameid, PET_EGG) >= 0)
+ if (pet->search_petDB_index(fitem->item_data.nameid, PET_EGG) >= 0)
intif->delete_petdata(MakeDWord(fitem->item_data.card[1], fitem->item_data.card[2]));
clif->clearflooritem(fitem, 0);
@@ -1307,7 +1307,7 @@ int map_search_freecell(struct block_list *src, int16 m, int16 *x,int16 *y, int1
if (iMap->getcell(m,*x,*y,CELL_CHKREACH))
{
- if(flag&2 && !unit_can_reach_pos(src, *x, *y, 1))
+ if(flag&2 && !unit->can_reach_pos(src, *x, *y, 1))
continue;
if(flag&4) {
if (spawn >= 100) return 0; //Limit of retries reached.
@@ -1534,13 +1534,13 @@ 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);
+ bg->team_leave(sd,1);
skill->cooldown_save(sd);
pc->itemcd_do(sd,false);
@@ -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
@@ -1587,7 +1587,7 @@ int map_quit(struct map_session_data *sd) {
}
// Return loot to owner
- if( sd->pd ) pet_lootitem_drop(sd->pd, sd);
+ if( sd->pd ) pet->lootitem_drop(sd->pd, sd);
if( sd->state.storage_flag == 1 ) sd->state.storage_flag = 0; // No need to Double Save Storage on Quit.
@@ -1595,7 +1595,7 @@ int map_quit(struct map_session_data *sd) {
if( sd->ed ) {
elemental->clean_effect(sd->ed);
- unit_remove_map(&sd->ed->bl,CLR_TELEPORT);
+ unit->remove_map(&sd->ed->bl,CLR_TELEPORT,ALC_MARK);
}
if( hChSys.local && map[sd->bl.m].channel && idb_exists(map[sd->bl.m].channel->users, sd->status.char_id) ) {
@@ -1604,7 +1604,7 @@ int map_quit(struct map_session_data *sd) {
clif->chsys_quit(sd);
- unit_remove_map_pc(sd,CLR_TELEPORT);
+ unit->remove_map_pc(sd,CLR_TELEPORT);
if( map[sd->bl.m].instance_id >= 0 ) { // Avoid map conflicts and warnings on next login
int16 m;
@@ -1630,7 +1630,7 @@ int map_quit(struct map_session_data *sd) {
pc->makesavestatus(sd);
pc->clean_skilltree(sd);
chrif->save(sd,1);
- unit_free_pc(sd);
+ unit->free_pc(sd);
return 0;
}
@@ -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)
@@ -2135,7 +2135,7 @@ int map_removemobs_sub(struct block_list *bl, va_list ap)
if( md->db->mexp > 0 )
return 0;
- unit_free(&md->bl,CLR_OUTSIGHT);
+ unit->free(&md->bl,CLR_OUTSIGHT);
return 1;
}
@@ -2244,7 +2244,7 @@ uint8 map_calc_dir(struct block_list* src, int16 x, int16 y)
if( dx == 0 && dy == 0 )
{ // both are standing on the same spot
//dir = 6; // aegis-style, makes knockback default to the left
- dir = unit_getdir(src); // athena-style, makes knockback default to behind 'src'
+ dir = unit->getdir(src); // athena-style, makes knockback default to behind 'src'
}
else if( dx >= 0 && dy >=0 )
{ // upper-right
@@ -2296,7 +2296,7 @@ int map_random_dir(struct block_list *bl, int16 *x, int16 *y)
segment = (short)sqrt((float)(dist2 - segment*segment)); //The complement of the previously picked segment
yi = bl->y + segment*diry[j];
} while (
- (iMap->getcell(bl->m,xi,yi,CELL_CHKNOPASS) || !path_search(NULL,bl->m,bl->x,bl->y,xi,yi,1,CELL_CHKNOREACH))
+ (iMap->getcell(bl->m,xi,yi,CELL_CHKNOPASS) || !path->search(NULL,bl->m,bl->x,bl->y,xi,yi,1,CELL_CHKNOREACH))
&& (++i)<100 );
if (i < 100) {
@@ -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");
@@ -3469,7 +3469,7 @@ int inter_config_read(char *cfgName) {
else if(strcmpi(w1,"log_db_db")==0)
strcpy(log_db_db, w2);
/* mapreg */
- else if( mapreg_config_read(w1,w2) )
+ else if( mapreg->config_read(w1,w2) )
continue;
/* import */
else if(strcmpi(w1,"import")==0)
@@ -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,10 +4869,10 @@ 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);
+ unit->free(bl,CLR_OUTSIGHT);
break;
case BL_PET:
//There is no need for this, the pet is removed together with the player. [Skotlex]
@@ -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();
@@ -4944,14 +4944,14 @@ void do_final(void)
guild->final();
party->do_final_party();
pc->do_final_pc();
- do_final_pet();
- do_final_mob();
+ pet->final();
+ mob->final();
homun->final();
atcommand->final_msg();
skill->final();
iStatus->do_final_status();
- do_final_unit();
- do_final_battleground();
+ unit->final();
+ bg->final();
iDuel->do_final_duel();
elemental->do_final_elemental();
do_final_maps();
@@ -5168,8 +5168,16 @@ void map_hp_symbols(void) {
HPM->share(elemental,"elemental");
HPM->share(intif,"intif");
HPM->share(mercenary,"mercenary");
-
-
+ HPM->share(mob,"mob");
+ HPM->share(unit,"unit");
+ HPM->share(npc,"npc");
+ HPM->share(mapreg,"mapreg");
+ HPM->share(pet,"pet");
+ HPM->share(path,"path");
+ HPM->share(quest,"quest");
+#ifdef PCRE_SUPPORT
+ HPM->share(npc_chat,"npc_chat");
+#endif
/* partial */
HPM->share(mapit,"mapit");
/* sql link */
@@ -5214,6 +5222,15 @@ void map_load_defaults(void) {
elemental_defaults();
intif_defaults();
mercenary_defaults();
+ mob_defaults();
+ unit_defaults();
+ mapreg_defaults();
+ pet_defaults();
+ path_defaults();
+ quest_defaults();
+#ifdef PCRE_SUPPORT
+ npc_chat_defaults();
+#endif
}
int do_init(int argc, char *argv[])
{
@@ -5402,24 +5419,24 @@ int do_init(int argc, char *argv[])
itemdb->init();
skill->init();
read_map_zone_db();/* read after item and skill initalization */
- do_init_mob();
+ mob->init();
pc->do_init_pc();
iStatus->do_init_status();
party->do_init_party();
guild->init();
storage->init();
- do_init_pet();
+ pet->init();
homun->init();
mercenary->init();
elemental->do_init_elemental();
- do_init_quest();
- do_init_npc();
- do_init_unit();
- do_init_battleground();
+ quest->init();
+ npc->init();
+ unit->init();
+ bg->init();
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/mapreg.h b/src/map/mapreg.h
index e83f9e053..3c1d0ba0e 100644
--- a/src/map/mapreg.h
+++ b/src/map/mapreg.h
@@ -5,6 +5,9 @@
#ifndef _MAPREG_H_
#define _MAPREG_H_
+#include "../common/cbasetypes.h"
+#include "../common/db.h"
+
struct mapreg_save {
int uid;
union {
@@ -14,14 +17,30 @@ struct mapreg_save {
bool save;
};
-void mapreg_reload(void);
-void mapreg_final(void);
-void mapreg_init(void);
-bool mapreg_config_read(const char* w1, const char* w2);
+struct mapreg_interface {
+ DBMap *db; // int var_id -> int value
+ DBMap *str_db; // int var_id -> char* value
+ struct eri *ers; //[Ind/Hercules]
+ char table[32];
+ bool i_dirty;
+ bool str_dirty;
+ /* */
+ void (*init) (void);
+ void (*final) (void);
+ /* */
+ int (*readreg) (int uid);
+ char* (*readregstr) (int uid);
+ bool (*setreg) (int uid, int val);
+ bool (*setregstr) (int uid, const char *str);
+ void (*load) (void);
+ void (*save) (void);
+ int (*save_timer) (int tid, unsigned int tick, int id, intptr_t data);
+ void (*reload) (void);
+ bool (*config_read) (const char *w1, const char *w2);
+};
+
+struct mapreg_interface *mapreg;
-int mapreg_readreg(int uid);
-char* mapreg_readregstr(int uid);
-bool mapreg_setreg(int uid, int val);
-bool mapreg_setregstr(int uid, const char* str);
+void mapreg_defaults(void);
#endif /* _MAPREG_H_ */
diff --git a/src/map/mapreg_sql.c b/src/map/mapreg_sql.c
index 4f9888aba..c0bfeb987 100644
--- a/src/map/mapreg_sql.c
+++ b/src/map/mapreg_sql.c
@@ -16,26 +16,19 @@
#include <stdlib.h>
#include <string.h>
-static DBMap* mapreg_db = NULL; // int var_id -> int value
-static DBMap* mapregstr_db = NULL; // int var_id -> char* value
-static struct eri *mapreg_ers; //[Ind/Hercules]
-
-static char mapreg_table[32] = "mapreg";
-static bool mapreg_i_dirty = false;
-static bool mapreg_str_dirty = false;
+struct mapreg_interface mapreg_s;
#define MAPREG_AUTOSAVE_INTERVAL (300*1000)
-
/// Looks up the value of an integer variable using its uid.
int mapreg_readreg(int uid) {
- struct mapreg_save *m = idb_get(mapreg_db, uid);
+ struct mapreg_save *m = idb_get(mapreg->db, uid);
return m?m->u.i:0;
}
/// Looks up the value of a string variable using its uid.
char* mapreg_readregstr(int uid) {
- struct mapreg_save *m = idb_get(mapregstr_db, uid);
+ struct mapreg_save *m = idb_get(mapreg->str_db, uid);
return m?m->u.str:NULL;
}
@@ -47,14 +40,14 @@ bool mapreg_setreg(int uid, int val) {
const char* name = script->get_str(num);
if( val != 0 ) {
- if( (m = idb_get(mapreg_db,uid)) ) {
+ if( (m = idb_get(mapreg->db,uid)) ) {
m->u.i = val;
if(name[1] != '@') {
m->save = true;
- mapreg_i_dirty = true;
+ mapreg->i_dirty = true;
}
} else {
- m = ers_alloc(mapreg_ers, struct mapreg_save);
+ m = ers_alloc(mapreg->ers, struct mapreg_save);
m->u.i = val;
m->uid = uid;
@@ -63,19 +56,19 @@ bool mapreg_setreg(int uid, int val) {
if(name[1] != '@') {// write new variable to database
char tmp_str[32*2+1];
SQL->EscapeStringLen(mmysql_handle, tmp_str, name, strnlen(name, 32));
- if( SQL_ERROR == SQL->Query(mmysql_handle, "INSERT INTO `%s`(`varname`,`index`,`value`) VALUES ('%s','%d','%d')", mapreg_table, tmp_str, i, val) )
+ if( SQL_ERROR == SQL->Query(mmysql_handle, "INSERT INTO `%s`(`varname`,`index`,`value`) VALUES ('%s','%d','%d')", mapreg->table, tmp_str, i, val) )
Sql_ShowDebug(mmysql_handle);
}
- idb_put(mapreg_db, uid, m);
+ idb_put(mapreg->db, uid, m);
}
} else { // val == 0
- if( (m = idb_get(mapreg_db,uid)) ) {
- ers_free(mapreg_ers, m);
+ if( (m = idb_get(mapreg->db,uid)) ) {
+ ers_free(mapreg->ers, m);
}
- idb_remove(mapreg_db,uid);
+ idb_remove(mapreg->db,uid);
if( name[1] != '@' ) {// Remove from database because it is unused.
- if( SQL_ERROR == SQL->Query(mmysql_handle, "DELETE FROM `%s` WHERE `varname`='%s' AND `index`='%d'", mapreg_table, name, i) )
+ if( SQL_ERROR == SQL->Query(mmysql_handle, "DELETE FROM `%s` WHERE `varname`='%s' AND `index`='%d'", mapreg->table, name, i) )
Sql_ShowDebug(mmysql_handle);
}
}
@@ -92,26 +85,26 @@ bool mapreg_setregstr(int uid, const char* str) {
if( str == NULL || *str == 0 ) {
if(name[1] != '@') {
- if( SQL_ERROR == SQL->Query(mmysql_handle, "DELETE FROM `%s` WHERE `varname`='%s' AND `index`='%d'", mapreg_table, name, i) )
+ if( SQL_ERROR == SQL->Query(mmysql_handle, "DELETE FROM `%s` WHERE `varname`='%s' AND `index`='%d'", mapreg->table, name, i) )
Sql_ShowDebug(mmysql_handle);
}
- if( (m = idb_get(mapregstr_db,uid)) ) {
+ if( (m = idb_get(mapreg->str_db,uid)) ) {
if( m->u.str != NULL )
aFree(m->u.str);
- ers_free(mapreg_ers, m);
+ ers_free(mapreg->ers, m);
}
- idb_remove(mapregstr_db,uid);
+ idb_remove(mapreg->str_db,uid);
} else {
- if( (m = idb_get(mapregstr_db,uid)) ) {
+ if( (m = idb_get(mapreg->str_db,uid)) ) {
if( m->u.str != NULL )
aFree(m->u.str);
m->u.str = aStrdup(str);
if(name[1] != '@') {
- mapreg_str_dirty = true;
+ mapreg->str_dirty = true;
m->save = true;
}
} else {
- m = ers_alloc(mapreg_ers, struct mapreg_save);
+ m = ers_alloc(mapreg->ers, struct mapreg_save);
m->uid = uid;
m->u.str = aStrdup(str);
@@ -122,10 +115,10 @@ bool mapreg_setregstr(int uid, const char* str) {
char tmp_str2[255*2+1];
SQL->EscapeStringLen(mmysql_handle, tmp_str, name, strnlen(name, 32));
SQL->EscapeStringLen(mmysql_handle, tmp_str2, str, strnlen(str, 255));
- if( SQL_ERROR == SQL->Query(mmysql_handle, "INSERT INTO `%s`(`varname`,`index`,`value`) VALUES ('%s','%d','%s')", mapreg_table, tmp_str, i, tmp_str2) )
+ if( SQL_ERROR == SQL->Query(mmysql_handle, "INSERT INTO `%s`(`varname`,`index`,`value`) VALUES ('%s','%d','%s')", mapreg->table, tmp_str, i, tmp_str2) )
Sql_ShowDebug(mmysql_handle);
}
- idb_put(mapregstr_db, uid, m);
+ idb_put(mapreg->str_db, uid, m);
}
}
@@ -133,7 +126,7 @@ bool mapreg_setregstr(int uid, const char* str) {
}
/// Loads permanent variables from database
-static void script_load_mapreg(void) {
+void script_load_mapreg(void) {
/*
0 1 2
+-------------------------+
@@ -146,7 +139,7 @@ static void script_load_mapreg(void) {
char value[255+1];
uint32 length;
- if ( SQL_ERROR == SQL->StmtPrepare(stmt, "SELECT `varname`, `index`, `value` FROM `%s`", mapreg_table)
+ if ( SQL_ERROR == SQL->StmtPrepare(stmt, "SELECT `varname`, `index`, `value` FROM `%s`", mapreg->table)
|| SQL_ERROR == SQL->StmtExecute(stmt)
) {
SqlStmt_ShowDebug(stmt);
@@ -164,59 +157,59 @@ static void script_load_mapreg(void) {
int i = index;
if( varname[length-1] == '$' ) {
- if( idb_exists(mapregstr_db, (i<<24)|s) ) {
+ if( idb_exists(mapreg->str_db, (i<<24)|s) ) {
ShowWarning("load_mapreg: duplicate! '%s' => '%s' skipping...\n",varname,value);
continue;
}
} else {
- if( idb_exists(mapreg_db, (i<<24)|s) ) {
+ if( idb_exists(mapreg->db, (i<<24)|s) ) {
ShowWarning("load_mapreg: duplicate! '%s' => '%s' skipping...\n",varname,value);
continue;
}
}
- m = ers_alloc(mapreg_ers, struct mapreg_save);
+ m = ers_alloc(mapreg->ers, struct mapreg_save);
m->uid = (i<<24)|s;
m->save = false;
if( varname[length-1] == '$' ) {
m->u.str = aStrdup(value);
- idb_put(mapregstr_db, m->uid, m);
+ idb_put(mapreg->str_db, m->uid, m);
} else {
m->u.i = atoi(value);
- idb_put(mapreg_db, m->uid, m);
+ idb_put(mapreg->db, m->uid, m);
}
}
SQL->StmtFree(stmt);
- mapreg_i_dirty = false;
- mapreg_str_dirty = false;
+ mapreg->i_dirty = false;
+ mapreg->str_dirty = false;
}
/// Saves permanent variables to database
-static void script_save_mapreg(void) {
+void script_save_mapreg(void) {
DBIterator* iter;
struct mapreg_save *m = NULL;
- if( mapreg_i_dirty ) {
- iter = db_iterator(mapreg_db);
+ if( mapreg->i_dirty ) {
+ iter = db_iterator(mapreg->db);
for( m = dbi_first(iter); dbi_exists(iter); m = dbi_next(iter) ) {
if( m->save ) {
int num = (m->uid & 0x00ffffff);
int i = (m->uid & 0xff000000) >> 24;
const char* name = script->get_str(num);
- if( SQL_ERROR == SQL->Query(mmysql_handle, "UPDATE `%s` SET `value`='%d' WHERE `varname`='%s' AND `index`='%d' LIMIT 1", mapreg_table, m->u.i, name, i) )
+ if( SQL_ERROR == SQL->Query(mmysql_handle, "UPDATE `%s` SET `value`='%d' WHERE `varname`='%s' AND `index`='%d' LIMIT 1", mapreg->table, m->u.i, name, i) )
Sql_ShowDebug(mmysql_handle);
m->save = false;
}
}
dbi_destroy(iter);
- mapreg_i_dirty = false;
+ mapreg->i_dirty = false;
}
- if( mapreg_str_dirty ) {
- iter = db_iterator(mapregstr_db);
+ if( mapreg->str_dirty ) {
+ iter = db_iterator(mapreg->str_db);
for( m = dbi_first(iter); dbi_exists(iter); m = dbi_next(iter) ) {
if( m->save ) {
int num = (m->uid & 0x00ffffff);
@@ -225,18 +218,18 @@ static void script_save_mapreg(void) {
char tmp_str2[2*255+1];
SQL->EscapeStringLen(mmysql_handle, tmp_str2, m->u.str, safestrnlen(m->u.str, 255));
- if( SQL_ERROR == SQL->Query(mmysql_handle, "UPDATE `%s` SET `value`='%s' WHERE `varname`='%s' AND `index`='%d' LIMIT 1", mapreg_table, tmp_str2, name, i) )
+ if( SQL_ERROR == SQL->Query(mmysql_handle, "UPDATE `%s` SET `value`='%s' WHERE `varname`='%s' AND `index`='%d' LIMIT 1", mapreg->table, tmp_str2, name, i) )
Sql_ShowDebug(mmysql_handle);
m->save = false;
}
}
dbi_destroy(iter);
- mapreg_str_dirty = false;
+ mapreg->str_dirty = false;
}
}
-static int script_autosave_mapreg(int tid, unsigned int tick, int id, intptr_t data) {
- script_save_mapreg();
+int script_autosave_mapreg(int tid, unsigned int tick, int id, intptr_t data) {
+ mapreg->save();
return 0;
}
@@ -245,72 +238,100 @@ void mapreg_reload(void) {
DBIterator* iter;
struct mapreg_save *m = NULL;
- script_save_mapreg();
+ mapreg->save();
- iter = db_iterator(mapreg_db);
+ iter = db_iterator(mapreg->db);
for( m = dbi_first(iter); dbi_exists(iter); m = dbi_next(iter) ) {
- ers_free(mapreg_ers, m);
+ ers_free(mapreg->ers, m);
}
dbi_destroy(iter);
- iter = db_iterator(mapregstr_db);
+ iter = db_iterator(mapreg->str_db);
for( m = dbi_first(iter); dbi_exists(iter); m = dbi_next(iter) ) {
if( m->u.str != NULL ) {
aFree(m->u.str);
}
- ers_free(mapreg_ers, m);
+ ers_free(mapreg->ers, m);
}
dbi_destroy(iter);
- db_clear(mapreg_db);
- db_clear(mapregstr_db);
+ db_clear(mapreg->db);
+ db_clear(mapreg->str_db);
- script_load_mapreg();
+ mapreg->load();
}
void mapreg_final(void) {
DBIterator* iter;
struct mapreg_save *m = NULL;
- script_save_mapreg();
+ mapreg->save();
- iter = db_iterator(mapreg_db);
+ iter = db_iterator(mapreg->db);
for( m = dbi_first(iter); dbi_exists(iter); m = dbi_next(iter) ) {
- ers_free(mapreg_ers, m);
+ ers_free(mapreg->ers, m);
}
dbi_destroy(iter);
- iter = db_iterator(mapregstr_db);
+ iter = db_iterator(mapreg->str_db);
for( m = dbi_first(iter); dbi_exists(iter); m = dbi_next(iter) ) {
if( m->u.str != NULL ) {
aFree(m->u.str);
}
- ers_free(mapreg_ers, m);
+ ers_free(mapreg->ers, m);
}
dbi_destroy(iter);
- db_destroy(mapreg_db);
- db_destroy(mapregstr_db);
+ db_destroy(mapreg->db);
+ db_destroy(mapreg->str_db);
- ers_destroy(mapreg_ers);
+ ers_destroy(mapreg->ers);
}
void mapreg_init(void) {
- mapreg_db = idb_alloc(DB_OPT_BASE);
- mapregstr_db = idb_alloc(DB_OPT_BASE);
- mapreg_ers = ers_new(sizeof(struct mapreg_save), "mapreg_sql.c::mapreg_ers", ERS_OPT_NONE);
+ mapreg->db = idb_alloc(DB_OPT_BASE);
+ mapreg->str_db = idb_alloc(DB_OPT_BASE);
+ mapreg->ers = ers_new(sizeof(struct mapreg_save), "mapreg_sql.c::mapreg_ers", ERS_OPT_NONE);
- script_load_mapreg();
+ mapreg->load();
- iTimer->add_timer_func_list(script_autosave_mapreg, "script_autosave_mapreg");
- iTimer->add_timer_interval(iTimer->gettick() + MAPREG_AUTOSAVE_INTERVAL, script_autosave_mapreg, 0, 0, MAPREG_AUTOSAVE_INTERVAL);
+ iTimer->add_timer_func_list(mapreg->save_timer, "mapreg_script_autosave_mapreg");
+ iTimer->add_timer_interval(iTimer->gettick() + MAPREG_AUTOSAVE_INTERVAL, mapreg->save_timer, 0, 0, MAPREG_AUTOSAVE_INTERVAL);
}
bool mapreg_config_read(const char* w1, const char* w2) {
if(!strcmpi(w1, "mapreg_db"))
- safestrncpy(mapreg_table, w2, sizeof(mapreg_table));
+ safestrncpy(mapreg->table, w2, sizeof(mapreg->table));
else
return false;
return true;
}
+void mapreg_defaults(void) {
+ mapreg = &mapreg_s;
+
+ /* */
+ mapreg->db = NULL;
+ mapreg->str_db = NULL;
+ mapreg->ers = NULL;
+
+ safestrncpy(mapreg->table, "mapreg", sizeof(mapreg->table));
+ mapreg->i_dirty = false;
+ mapreg->str_dirty = false;
+
+ /* */
+ mapreg->init = mapreg_init;
+ mapreg->final = mapreg_final;
+
+ /* */
+ mapreg->readreg = mapreg_readreg;
+ mapreg->readregstr = mapreg_readregstr;
+ mapreg->setreg = mapreg_setreg;
+ mapreg->setregstr = mapreg_setregstr;
+ mapreg->load = script_load_mapreg;
+ mapreg->save = script_save_mapreg;
+ mapreg->save_timer = script_autosave_mapreg;
+ mapreg->reload = mapreg_reload;
+ mapreg->config_read = mapreg_config_read;
+
+}
diff --git a/src/map/mercenary.c b/src/map/mercenary.c
index bb30bb0d1..bf802c643 100644
--- a/src/map/mercenary.c
+++ b/src/map/mercenary.c
@@ -247,7 +247,7 @@ int merc_delete(struct mercenary_data *md, int reply)
mercenary->contract_stop(md);
if( !sd )
- return unit_free(&md->bl, CLR_OUTSIGHT);
+ return unit->free(&md->bl, CLR_OUTSIGHT);
if( md->devotion_flag )
{
@@ -262,7 +262,7 @@ int merc_delete(struct mercenary_data *md, int reply)
}
clif->mercenary_message(sd, reply);
- return unit_remove_map(&md->bl, CLR_OUTSIGHT);
+ return unit->remove_map(&md->bl, CLR_OUTSIGHT, ALC_MARK);
}
void merc_contract_stop(struct mercenary_data *md)
@@ -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;
@@ -309,13 +309,13 @@ int merc_data_received(struct s_mercenary *merc, bool flag)
memcpy(&md->mercenary, merc, sizeof(struct s_mercenary));
iStatus->set_viewdata(&md->bl, md->mercenary.class_);
iStatus->change_init(&md->bl);
- unit_dataset(&md->bl);
+ unit->dataset(&md->bl);
md->ud.dir = sd->ud.dir;
md->bl.m = sd->bl.m;
md->bl.x = sd->bl.x;
md->bl.y = sd->bl.y;
- unit_calc_pos(&md->bl, sd->bl.x, sd->bl.y, sd->ud.dir);
+ unit->calc_pos(&md->bl, sd->bl.x, sd->bl.y, sd->ud.dir);
md->bl.x = md->ud.to_x;
md->bl.y = md->ud.to_y;
diff --git a/src/map/mob.c b/src/map/mob.c
index b16c57ef8..146f82239 100644
--- a/src/map/mob.c
+++ b/src/map/mob.c
@@ -43,6 +43,8 @@
#include <string.h>
#include <math.h>
+struct mob_interface mob_s;
+
#define ACTIVE_AI_RANGE 2 //Distance added on top of 'AREA_SIZE' at which mobs enter active AI mode.
#define IDLE_SKILL_INTERVAL 10 //Active idle skills should be triggered every 1 second (1000/MIN_MOBTHINKTIME)
@@ -54,17 +56,6 @@
#define MOB_MAX_DELAY (24*3600*1000)
#define MAX_MINCHASE 30 //Max minimum chase value to use for mobs.
#define RUDE_ATTACKED_COUNT 2 //After how many rude-attacks should the skill be used?
-#define MAX_MOB_CHAT 250 //Max Skill's messages
-
-//Dynamic mob database, allows saving of memory when there's big gaps in the mob_db [Skotlex]
-struct mob_db *mob_db_data[MAX_MOB_DB+1];
-struct mob_db *mob_dummy = NULL; //Dummy mob to be returned when a non-existant one is requested.
-
-struct mob_db *mob_db(int index) { if (index < 0 || index > MAX_MOB_DB || mob_db_data[index] == NULL) return mob_dummy; return mob_db_data[index]; }
-
-//Dynamic mob chat database
-struct mob_chat *mob_chat_db[MAX_MOB_CHAT+1];
-struct mob_chat *mob_chat(short id) { if(id<=0 || id>MAX_MOB_CHAT || mob_chat_db[id]==NULL) return (struct mob_chat*)NULL; return mob_chat_db[id]; }
//Dynamic item drop ratio database for per-item drop ratio modifiers overriding global drop ratios.
#define MAX_ITEMRATIO_MOBS 10
@@ -82,16 +73,16 @@ static struct {
int class_[350];
} summon[MAX_RANDOMMONSTER];
-//Defines the Manuk/Splendide mob groups for the status reductions [Epoque]
-const int mob_manuk[8] = { 1986, 1987, 1988, 1989, 1990, 1997, 1998, 1999 };
-const int mob_splendide[5] = { 1991, 1992, 1993, 1994, 1995 };
-
-/*==========================================
- * Local prototype declaration (only required thing)
- *------------------------------------------*/
-static int mob_makedummymobdb(int);
-static int mob_spawn_guardian_sub(int tid, unsigned int tick, int id, intptr_t data);
-int mob_skill_id2skill_idx(int class_,uint16 skill_id);
+struct mob_db *mob_db(int index) {
+ if (index < 0 || index > MAX_MOB_DB || mob->db_data[index] == NULL)
+ return mob->dummy;
+ return mob->db_data[index];
+}
+struct mob_chat *mob_chat(short id) {
+ if(id <= 0 || id > MAX_MOB_CHAT || mob->chat_db[id] == NULL)
+ return NULL;
+ return mob->chat_db[id];
+}
/*==========================================
* Mob is searched with a name.
@@ -99,35 +90,34 @@ int mob_skill_id2skill_idx(int class_,uint16 skill_id);
int mobdb_searchname(const char *str)
{
int i;
- struct mob_db* mob;
+ struct mob_db* monster;
for(i=0;i<=MAX_MOB_DB;i++){
- mob = mob_db(i);
- if(mob == mob_dummy) //Skip dummy mobs.
+ monster = mob->db(i);
+ if(monster == mob->dummy) //Skip dummy mobs.
continue;
- if(strcmpi(mob->name,str)==0 || strcmpi(mob->jname,str)==0 || strcmpi(mob->sprite,str)==0)
+ if(strcmpi(monster->name,str)==0 || strcmpi(monster->jname,str)==0 || strcmpi(monster->sprite,str)==0)
return i;
}
return 0;
}
-static int mobdb_searchname_array_sub(struct mob_db* mob, const char *str, int flag)
-{
- if (mob == mob_dummy)
+int mobdb_searchname_array_sub(struct mob_db* monster, const char *str, int flag) {
+ if (monster == mob->dummy)
return 1;
- if(!mob->base_exp && !mob->job_exp && mob->spawn[0].qty < 1)
+ if(!monster->base_exp && !monster->job_exp && monster->spawn[0].qty < 1)
return 1; // Monsters with no base/job exp and no spawn point are, by this criteria, considered "slave mobs" and excluded from search results
if( !flag ){
- if(stristr(mob->jname,str))
+ if(stristr(monster->jname,str))
return 0;
- if(stristr(mob->name,str))
+ if(stristr(monster->name,str))
return 0;
- return strcmpi(mob->jname,str);
+ return strcmpi(monster->jname,str);
}
- if(strcmp(mob->jname,str) == 0)
+ if(strcmp(monster->jname,str) == 0)
return 0;
- if(strcmp(mob->name,str) == 0)
+ if(strcmp(monster->name,str) == 0)
return 0;
- return strcmp(mob->sprite,str);
+ return strcmp(monster->sprite,str);
}
/*==========================================
@@ -138,11 +128,11 @@ void mvptomb_create(struct mob_data *md, char *killer, time_t time)
struct npc_data *nd;
if ( md->tomb_nid )
- mvptomb_destroy(md);
+ mob->mvptomb_destroy(md);
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;
@@ -204,14 +194,14 @@ void mvptomb_destroy(struct mob_data *md) {
int mobdb_searchname_array(struct mob_db** data, int size, const char *str, int flag)
{
int count = 0, i;
- struct mob_db* mob;
+ struct mob_db* monster;
for(i=0;i<=MAX_MOB_DB;i++){
- mob = mob_db(i);
- if (mob == mob_dummy || mob_is_clone(i) ) //keep clones out (or you leak player stats)
+ monster = mob->db(i);
+ if (monster == mob->dummy || mob->is_clone(i) ) //keep clones out (or you leak player stats)
continue;
- if (!mobdb_searchname_array_sub(mob, str, flag)) {
+ if (!mob->db_searchname_array_sub(monster, str, flag)) {
if (count < size)
- data[count] = mob;
+ data[count] = monster;
count++;
}
}
@@ -223,9 +213,9 @@ int mobdb_searchname_array(struct mob_db** data, int size, const char *str, int
*------------------------------------------*/
int mobdb_checkid(const int id)
{
- if (mob_db(id) == mob_dummy)
+ if (mob->db(id) == mob->dummy)
return 0;
- if (mob_is_clone(id)) //checkid is used mostly for random ID based code, therefore clone mobs are out of the question.
+ if (mob->is_clone(id)) //checkid is used mostly for random ID based code, therefore clone mobs are out of the question.
return 0;
return id;
}
@@ -235,9 +225,9 @@ int mobdb_checkid(const int id)
*------------------------------------------*/
struct view_data * mob_get_viewdata(int class_)
{
- if (mob_db(class_) == mob_dummy)
+ if (mob->db(class_) == mob->dummy)
return 0;
- return &mob_db(class_)->vd;
+ return &mob->db(class_)->vd;
}
/*==========================================
* Cleans up mob-spawn data to make it "valid"
@@ -246,7 +236,7 @@ int mob_parse_dataset(struct spawn_data *data)
{
size_t len;
- if ((!mobdb_checkid(data->class_) && !mob_is_clone(data->class_)) || !data->num)
+ if ((!mob->db_checkid(data->class_) && !mob->is_clone(data->class_)) || !data->num)
return 0;
if( ( len = strlen(data->eventname) ) > 0 )
@@ -258,9 +248,9 @@ int mob_parse_dataset(struct spawn_data *data)
}
if(strcmp(data->name,"--en--")==0)
- safestrncpy(data->name, mob_db(data->class_)->name, sizeof(data->name));
+ safestrncpy(data->name, mob->db(data->class_)->name, sizeof(data->name));
else if(strcmp(data->name,"--ja--")==0)
- safestrncpy(data->name, mob_db(data->class_)->jname, sizeof(data->name));
+ safestrncpy(data->name, mob->db(data->class_)->jname, sizeof(data->name));
return 1;
}
@@ -269,14 +259,14 @@ 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;
md->bl.y = data->y;
md->class_ = data->class_;
md->state.boss = data->state.boss;
- md->db = mob_db(md->class_);
+ md->db = mob->db(md->class_);
if (data->level > 0 && data->level <= MAX_LEVEL)
md->level = data->level;
memcpy(md->name, data->name, NAME_LENGTH);
@@ -293,7 +283,7 @@ struct mob_data* mob_spawn_dataset(struct spawn_data *data) {
md->skill_idx = -1;
iStatus->set_viewdata(&md->bl, md->class_);
iStatus->change_init(&md->bl);
- unit_dataset(&md->bl);
+ unit->dataset(&md->bl);
iMap->addiddb(&md->bl);
return md;
@@ -314,7 +304,7 @@ struct mob_data* mob_spawn_dataset(struct spawn_data *data) {
*------------------------------------------*/
int mob_get_random_id(int type, int flag, int lv)
{
- struct mob_db *mob;
+ struct mob_db *monster;
int i=0, class_;
if(type < 0 || type >= MAX_RANDOMMONSTER) {
ShowError("mob_get_random_id: Invalid type (%d) of random monster.\n", type);
@@ -325,17 +315,17 @@ int mob_get_random_id(int type, int flag, int lv)
class_ = summon[type].class_[rnd()%summon[type].qty];
else //Dead branch
class_ = rnd() % MAX_MOB_DB;
- mob = mob_db(class_);
- } while ((mob == mob_dummy ||
- mob_is_clone(class_) ||
- (flag&1 && mob->summonper[type] <= rnd() % 1000000) ||
- (flag&2 && lv < mob->lv) ||
- (flag&4 && mob->status.mode&MD_BOSS) ||
- (flag&8 && mob->spawn[0].qty < 1)
+ monster = mob->db(class_);
+ } while ((monster == mob->dummy ||
+ mob->is_clone(class_) ||
+ (flag&1 && monster->summonper[type] <= rnd() % 1000000) ||
+ (flag&2 && lv < monster->lv) ||
+ (flag&4 && monster->status.mode&MD_BOSS) ||
+ (flag&8 && monster->spawn[0].qty < 1)
) && (i++) < MAX_MOB_DB);
if(i >= MAX_MOB_DB) // no suitable monster found, use fallback for given list
- class_ = mob_db_data[0]->summonper[type];
+ class_ = mob->db_data[0]->summonper[type];
return class_;
}
@@ -458,10 +448,10 @@ struct mob_data *mob_once_spawn_sub(struct block_list *bl, int16 m, int16 x, int
data.x = x;
data.y = y;
- if (!mob_parse_dataset(&data))
+ if (!mob->parse_dataset(&data))
return NULL;
- return mob_spawn_dataset(&data);
+ return mob->spawn_dataset(&data);
}
/*==========================================
@@ -479,8 +469,8 @@ int mob_once_spawn(struct map_session_data* sd, int16 m, int16 x, int16 y, const
for (count = 0; count < amount; count++)
{
- int c = (class_ >= 0) ? class_ : mob_get_random_id(-class_ - 1, (battle_config.random_monster_checklv) ? 3 : 1, lv);
- md = mob_once_spawn_sub((sd) ? &sd->bl : NULL, m, x, y, mobname, c, event, size, ai);
+ int c = (class_ >= 0) ? class_ : mob->get_random_id(-class_ - 1, (battle_config.random_monster_checklv) ? 3 : 1, lv);
+ md = mob->once_spawn_sub((sd) ? &sd->bl : NULL, m, x, y, mobname, c, event, size, ai);
if (!md)
continue;
@@ -501,11 +491,11 @@ int mob_once_spawn(struct map_session_data* sd, int16 m, int16 x, int16 y, const
memcpy(md->guardian_data->guild_name, g->name, NAME_LENGTH);
}
else if (gc->guild_id) //Guild not yet available, retry in 5.
- iTimer->add_timer(iTimer->gettick()+5000,mob_spawn_guardian_sub,md->bl.id,md->guardian_data->guild_id);
+ iTimer->add_timer(iTimer->gettick()+5000,mob->spawn_guardian_sub,md->bl.id,md->guardian_data->guild_id);
}
} // end addition [Valaris]
- mob_spawn(md);
+ mob->spawn(md);
if (class_ < 0 && battle_config.dead_branch_active)
//Behold Aegis's masterful decisions yet again...
@@ -565,7 +555,7 @@ int mob_once_spawn_area(struct map_session_data* sd, int16 m, int16 x0, int16 y0
lx = x;
ly = y;
- id = mob_once_spawn(sd, m, x, y, mobname, class_, 1, event, size, ai);
+ id = mob->once_spawn(sd, m, x, y, mobname, class_, 1, event, size, ai);
}
return id; // id of last spawned mob
@@ -573,7 +563,7 @@ int mob_once_spawn_area(struct map_session_data* sd, int16 m, int16 x0, int16 y0
/*==========================================
* Set a Guardian's guild data [Skotlex]
*------------------------------------------*/
-static int mob_spawn_guardian_sub(int tid, unsigned int tick, int id, intptr_t data)
+int mob_spawn_guardian_sub(int tid, unsigned int tick, int id, intptr_t data)
{ //Needed because the guild_data may not be available at guardian spawn time.
struct block_list* bl = iMap->id2bl(id);
struct mob_data* md;
@@ -607,7 +597,7 @@ static int mob_spawn_guardian_sub(int tid, unsigned int tick, int id, intptr_t d
} else {
if (md->guardian_data->number >= 0 && md->guardian_data->number < MAX_GUARDIANS && md->guardian_data->castle->guardian[md->guardian_data->number].visible)
guild->castledatasave(md->guardian_data->castle->castle_id, 10+md->guardian_data->number,0);
- unit_free(&md->bl,CLR_OUTSIGHT); //Remove guardian.
+ unit->free(&md->bl,CLR_OUTSIGHT); //Remove guardian.
}
return 0;
}
@@ -643,7 +633,7 @@ int mob_spawn_guardian(const char* mapname, short x, short y, const char* mobnam
data.m = m;
data.num = 1;
if(class_<=0) {
- class_ = mob_get_random_id(-class_-1, 1, 99);
+ class_ = mob->get_random_id(-class_-1, 1, 99);
if (!class_) return 0;
}
@@ -668,7 +658,7 @@ int mob_spawn_guardian(const char* mapname, short x, short y, const char* mobnam
data.y = y;
safestrncpy(data.name, mobname, sizeof(data.name));
safestrncpy(data.eventname, event, sizeof(data.eventname));
- if (!mob_parse_dataset(&data))
+ if (!mob->parse_dataset(&data))
return 0;
gc=guild->mapname2gc(map[m].name);
@@ -693,7 +683,7 @@ int mob_spawn_guardian(const char* mapname, short x, short y, const char* mobnam
}
}
- md = mob_spawn_dataset(&data);
+ md = mob->spawn_dataset(&data);
md->guardian_data = (struct guardian_data*)aCalloc(1, sizeof(struct guardian_data));
md->guardian_data->number = guardian;
md->guardian_data->guild_id = gc->guild_id;
@@ -719,8 +709,8 @@ int mob_spawn_guardian(const char* mapname, short x, short y, const char* mobnam
memcpy (md->guardian_data->guild_name, g->name, NAME_LENGTH);
md->guardian_data->guardup_lv = guild->checkskill(g,GD_GUARDUP);
} else if (md->guardian_data->guild_id)
- iTimer->add_timer(iTimer->gettick()+5000,mob_spawn_guardian_sub,md->bl.id,md->guardian_data->guild_id);
- mob_spawn(md);
+ iTimer->add_timer(iTimer->gettick()+5000,mob->spawn_guardian_sub,md->bl.id,md->guardian_data->guild_id);
+ mob->spawn(md);
return md->bl.id;
}
@@ -745,7 +735,7 @@ int mob_spawn_bg(const char* mapname, short x, short y, const char* mobname, int
data.num = 1;
if( class_ <= 0 )
{
- class_ = mob_get_random_id(-class_-1,1,99);
+ class_ = mob->get_random_id(-class_-1,1,99);
if( !class_ ) return 0;
}
@@ -760,11 +750,11 @@ int mob_spawn_bg(const char* mapname, short x, short y, const char* mobname, int
data.y = y;
safestrncpy(data.name, mobname, sizeof(data.name));
safestrncpy(data.eventname, event, sizeof(data.eventname));
- if( !mob_parse_dataset(&data) )
+ if( !mob->parse_dataset(&data) )
return 0;
- md = mob_spawn_dataset(&data);
- mob_spawn(md);
+ md = mob->spawn_dataset(&data);
+ mob->spawn(md);
md->bg_id = bg_id; // BG Team ID
return md->bl.id;
@@ -793,7 +783,7 @@ int mob_can_reach(struct mob_data *md,struct block_list *bl,int range, int state
easy = 1;
break;
}
- return unit_can_reach_bl(&md->bl, bl, range, easy, NULL, NULL);
+ return unit->can_reach_bl(&md->bl, bl, range, easy, NULL, NULL);
}
/*==========================================
@@ -816,7 +806,7 @@ int mob_linksearch(struct block_list *bl,va_list ap)
&& !md->target_id)
{
md->last_linktime = tick;
- if( mob_can_reach(md,target,md->db->range2, MSS_FOLLOW) ){ // Reachability judging
+ if( mob->can_reach(md,target,md->db->range2, MSS_FOLLOW) ){ // Reachability judging
md->target_id = target->id;
md->min_chase=md->db->range3;
return 1;
@@ -842,7 +832,7 @@ int mob_delayspawn(int tid, unsigned int tick, int id, intptr_t data)
return 0;
}
md->spawn_timer = INVALID_TIMER;
- mob_spawn(md);
+ mob->spawn(md);
}
return 0;
}
@@ -856,14 +846,14 @@ int mob_setdelayspawn(struct mob_data *md)
struct mob_db *db;
if (!md->spawn) //Doesn't has respawn data!
- return unit_free(&md->bl,CLR_DEAD);
+ return unit->free(&md->bl,CLR_DEAD);
spawntime = md->spawn->delay1; //Base respawn time
if (md->spawn->delay2) //random variance
spawntime+= rnd()%md->spawn->delay2;
//Apply the spawn delay fix [Skotlex]
- db = mob_db(md->spawn->class_);
+ db = mob->db(md->spawn->class_);
mode = db->status.mode;
if (mode & MD_BOSS) { //Bosses
if (battle_config.boss_spawn_delay != 100) {
@@ -883,8 +873,8 @@ int mob_setdelayspawn(struct mob_data *md)
spawntime = 5000;
if( md->spawn_timer != INVALID_TIMER )
- iTimer->delete_timer(md->spawn_timer, mob_delayspawn);
- md->spawn_timer = iTimer->add_timer(iTimer->gettick()+spawntime, mob_delayspawn, md->bl.id, 0);
+ iTimer->delete_timer(md->spawn_timer, mob->delayspawn);
+ md->spawn_timer = iTimer->add_timer(iTimer->gettick()+spawntime, mob->delayspawn, md->bl.id, 0);
return 0;
}
@@ -910,13 +900,11 @@ int mob_spawn (struct mob_data *md)
md->last_thinktime = tick;
if (md->bl.prev != NULL)
- unit_remove_map(&md->bl,CLR_RESPAWN);
- else
- if (md->spawn && md->class_ != md->spawn->class_)
- {
+ unit->remove_map(&md->bl,CLR_RESPAWN,ALC_MARK);
+ else if (md->spawn && md->class_ != md->spawn->class_) {
md->class_ = md->spawn->class_;
iStatus->set_viewdata(&md->bl, md->class_);
- md->db = mob_db(md->class_);
+ md->db = mob->db(md->class_);
memcpy(md->name,md->spawn->name,NAME_LENGTH);
}
@@ -930,16 +918,16 @@ int mob_spawn (struct mob_data *md)
if( !iMap->search_freecell(&md->bl, -1, &md->bl.x, &md->bl.y, md->spawn->xs, md->spawn->ys, battle_config.no_spawn_on_player?4:0) )
{ // retry again later
if( md->spawn_timer != INVALID_TIMER )
- iTimer->delete_timer(md->spawn_timer, mob_delayspawn);
- md->spawn_timer = iTimer->add_timer(tick+5000,mob_delayspawn,md->bl.id,0);
+ iTimer->delete_timer(md->spawn_timer, mob->delayspawn);
+ md->spawn_timer = iTimer->add_timer(tick+5000,mob->delayspawn,md->bl.id,0);
return 1;
}
}
- else if( battle_config.no_spawn_on_player > 99 && iMap->foreachinrange(mob_count_sub, &md->bl, AREA_SIZE, BL_PC) )
+ else if( battle_config.no_spawn_on_player > 99 && iMap->foreachinrange(mob->count_sub, &md->bl, AREA_SIZE, BL_PC) )
{ // retry again later (players on sight)
if( md->spawn_timer != INVALID_TIMER )
- iTimer->delete_timer(md->spawn_timer, mob_delayspawn);
- md->spawn_timer = iTimer->add_timer(tick+5000,mob_delayspawn,md->bl.id,0);
+ iTimer->delete_timer(md->spawn_timer, mob->delayspawn);
+ md->spawn_timer = iTimer->add_timer(tick+5000,mob->delayspawn,md->bl.id,0);
return 1;
}
}
@@ -953,7 +941,7 @@ int mob_spawn (struct mob_data *md)
md->ud.target_to = 0;
if( md->spawn_timer != INVALID_TIMER )
{
- iTimer->delete_timer(md->spawn_timer, mob_delayspawn);
+ iTimer->delete_timer(md->spawn_timer, mob->delayspawn);
md->spawn_timer = INVALID_TIMER;
}
@@ -984,20 +972,20 @@ int mob_spawn (struct mob_data *md)
// MvP tomb [GreenBox]
if ( md->tomb_nid )
- mvptomb_destroy(md);
+ mob->mvptomb_destroy(md);
iMap->addblock(&md->bl);
if( map[md->bl.m].users )
clif->spawn(&md->bl);
skill->unit_move(&md->bl,tick,1);
- mobskill_use(md, tick, MSC_SPAWN);
+ mob->skill_use(md, tick, MSC_SPAWN);
return 0;
}
/*==========================================
* Determines if the mob can change target. [Skotlex]
*------------------------------------------*/
-static int mob_can_changetarget(struct mob_data* md, struct block_list* target, int mode)
+int mob_can_changetarget(struct mob_data* md, struct block_list* target, int mode)
{
// if the monster was provoked ignore the above rule [celest]
if(md->state.provoke_flag)
@@ -1035,7 +1023,7 @@ int mob_target(struct mob_data *md,struct block_list *bl,int dist)
nullpo_ret(bl);
// Nothing will be carried out if there is no mind of changing TAGE by TAGE ending.
- if(md->target_id && !mob_can_changetarget(md, bl, status_get_mode(&md->bl)))
+ if(md->target_id && !mob->can_changetarget(md, bl, status_get_mode(&md->bl)))
return 0;
if(!iStatus->check_skilluse(&md->bl, bl, 0, 0))
@@ -1053,7 +1041,7 @@ int mob_target(struct mob_data *md,struct block_list *bl,int dist)
/*==========================================
* The ?? routine of an active monster
*------------------------------------------*/
-static int mob_ai_sub_hard_activesearch(struct block_list *bl,va_list ap)
+int mob_ai_sub_hard_activesearch(struct block_list *bl,va_list ap)
{
struct mob_data *md;
struct block_list **target;
@@ -1093,7 +1081,7 @@ static int mob_ai_sub_hard_activesearch(struct block_list *bl,va_list ap)
) { //Pick closest target?
if( map[bl->m].icewall_num &&
- !path_search_long(NULL,bl->m,md->bl.x,md->bl.y,bl->x,bl->y,CELL_CHKICEWALL) ) {
+ !path->search_long(NULL,bl->m,md->bl.x,md->bl.y,bl->x,bl->y,CELL_CHKICEWALL) ) {
if( !check_distance_bl(&md->bl, bl, status_get_range(&md->bl) ) )
return 0;
@@ -1115,7 +1103,7 @@ static int mob_ai_sub_hard_activesearch(struct block_list *bl,va_list ap)
/*==========================================
* chase target-change routine.
*------------------------------------------*/
-static int mob_ai_sub_hard_changechase(struct block_list *bl,va_list ap)
+int mob_ai_sub_hard_changechase(struct block_list *bl,va_list ap)
{
struct mob_data *md;
struct block_list **target;
@@ -1141,7 +1129,7 @@ static int mob_ai_sub_hard_changechase(struct block_list *bl,va_list ap)
/*==========================================
* finds nearby bg ally for guardians looking for users to follow.
*------------------------------------------*/
-static int mob_ai_sub_hard_bg_ally(struct block_list *bl,va_list ap) {
+int mob_ai_sub_hard_bg_ally(struct block_list *bl,va_list ap) {
struct mob_data *md;
struct block_list **target;
@@ -1158,7 +1146,7 @@ static int mob_ai_sub_hard_bg_ally(struct block_list *bl,va_list ap) {
/*==========================================
* loot monster item search
*------------------------------------------*/
-static int mob_ai_sub_hard_lootsearch(struct block_list *bl,va_list ap)
+int mob_ai_sub_hard_lootsearch(struct block_list *bl,va_list ap)
{
struct mob_data* md;
struct block_list **target;
@@ -1168,7 +1156,7 @@ static int mob_ai_sub_hard_lootsearch(struct block_list *bl,va_list ap)
target= va_arg(ap,struct block_list**);
dist=distance_bl(&md->bl, bl);
- if(mob_can_reach(md,bl,dist+1, MSS_LOOT) &&
+ if(mob->can_reach(md,bl,dist+1, MSS_LOOT) &&
((*target) == NULL || !check_distance_bl(&md->bl, *target, dist)) //New target closer than previous one.
) {
(*target) = bl;
@@ -1178,7 +1166,7 @@ static int mob_ai_sub_hard_lootsearch(struct block_list *bl,va_list ap)
return 0;
}
-static int mob_warpchase_sub(struct block_list *bl,va_list ap) {
+int mob_warpchase_sub(struct block_list *bl,va_list ap) {
struct block_list *target;
struct npc_data **target_nd;
struct npc_data *nd;
@@ -1209,7 +1197,7 @@ static int mob_warpchase_sub(struct block_list *bl,va_list ap) {
/*==========================================
* Processing of slave monsters
*------------------------------------------*/
-static int mob_ai_sub_hard_slavemob(struct mob_data *md,unsigned int tick)
+int mob_ai_sub_hard_slavemob(struct mob_data *md,unsigned int tick)
{
struct block_list *bl;
@@ -1236,7 +1224,7 @@ static int mob_ai_sub_hard_slavemob(struct mob_data *md,unsigned int tick)
md->master_dist > MAX_MINCHASE
){
md->master_dist = 0;
- unit_warp(&md->bl,bl->m,bl->x,bl->y,CLR_TELEPORT);
+ unit->warp(&md->bl,bl->m,bl->x,bl->y,CLR_TELEPORT);
return 1;
}
@@ -1245,12 +1233,12 @@ static int mob_ai_sub_hard_slavemob(struct mob_data *md,unsigned int tick)
// Approach master if within view range, chase back to Master's area also if standing on top of the master.
if((md->master_dist>MOB_SLAVEDISTANCE || md->master_dist == 0) &&
- unit_can_move(&md->bl))
+ unit->can_move(&md->bl))
{
short x = bl->x, y = bl->y;
mob_stop_attack(md);
if(iMap->search_freecell(&md->bl, bl->m, &x, &y, MOB_SLAVEDISTANCE, MOB_SLAVEDISTANCE, 1)
- && unit_walktoxy(&md->bl, x, y, 0))
+ && unit->walktoxy(&md->bl, x, y, 0))
return 1;
}
} else if (bl->m != md->bl.m && map_flag_gvg(md->bl.m)) {
@@ -1262,7 +1250,7 @@ static int mob_ai_sub_hard_slavemob(struct mob_data *md,unsigned int tick)
//Avoid attempting to lock the master's target too often to avoid unnecessary overload. [Skotlex]
if (DIFF_TICK(md->last_linktime, tick) < MIN_MOBLINKTIME && !md->target_id)
{
- struct unit_data *ud = unit_bl2ud(bl);
+ struct unit_data *ud = unit->bl2ud(bl);
md->last_linktime = tick;
if (ud) {
@@ -1306,12 +1294,12 @@ int mob_unlocktarget(struct mob_data *md, unsigned int tick)
case MSS_IDLE:
// Idle skill.
if ((md->target_id || !(++md->ud.walk_count%IDLE_SKILL_INTERVAL)) &&
- mobskill_use(md, tick, -1))
+ mob->skill_use(md, tick, -1))
break;
//Random walk.
if (!md->master_id &&
DIFF_TICK(md->next_walktime, tick) <= 0 &&
- !mob_randomwalk(md,tick))
+ !mob->randomwalk(md,tick))
//Delay next random walk when this one failed.
md->next_walktime=tick+rnd()%3000;
break;
@@ -1326,7 +1314,7 @@ int mob_unlocktarget(struct mob_data *md, unsigned int tick)
if (md->target_id) {
md->target_id=0;
md->ud.target_to = 0;
- unit_set_target(&md->ud, 0);
+ unit->set_target(&md->ud, 0);
}
return 0;
}
@@ -1342,7 +1330,7 @@ int mob_randomwalk(struct mob_data *md,unsigned int tick)
nullpo_ret(md);
if(DIFF_TICK(md->next_walktime,tick)>0 ||
- !unit_can_move(&md->bl) ||
+ !unit->can_move(&md->bl) ||
!(status_get_mode(&md->bl)&MD_CANMOVE))
return 0;
@@ -1355,7 +1343,7 @@ int mob_randomwalk(struct mob_data *md,unsigned int tick)
x+=md->bl.x;
y+=md->bl.y;
- if((iMap->getcell(md->bl.m,x,y,CELL_CHKPASS)) && unit_walktoxy(&md->bl,x,y,1)){
+ if((iMap->getcell(md->bl.m,x,y,CELL_CHKPASS)) && unit->walktoxy(&md->bl,x,y,1)){
break;
}
}
@@ -1364,7 +1352,7 @@ int mob_randomwalk(struct mob_data *md,unsigned int tick)
if(md->move_fail_count>1000){
ShowWarning("MOB can't move. random spawn %d, class = %d, at %s (%d,%d)\n",md->bl.id,md->class_,map[md->bl.m].name, md->bl.x, md->bl.y);
md->move_fail_count=0;
- mob_spawn(md);
+ mob->spawn(md);
}
return 0;
}
@@ -1396,10 +1384,10 @@ int mob_warpchase(struct mob_data *md, struct block_list *target)
return 1; //Already walking to a warp.
//Search for warps within mob's viewing range.
- iMap->foreachinrange (mob_warpchase_sub, &md->bl,
+ iMap->foreachinrange (mob->warpchase_sub, &md->bl,
md->db->range2, BL_NPC, target, &warp, &distance);
- if (warp && unit_walktobl(&md->bl, &warp->bl, 1, 1))
+ if (warp && unit->walktobl(&md->bl, &warp->bl, 1, 1))
return 1;
return 0;
}
@@ -1407,7 +1395,7 @@ int mob_warpchase(struct mob_data *md, struct block_list *target)
/*==========================================
* AI of MOB whose is near a Player
*------------------------------------------*/
-static bool mob_ai_sub_hard(struct mob_data *md, unsigned int tick)
+bool mob_ai_sub_hard(struct mob_data *md, unsigned int tick)
{
struct block_list *tbl = NULL, *abl = NULL;
int mode;
@@ -1440,7 +1428,7 @@ static bool mob_ai_sub_hard(struct mob_data *md, unsigned int tick)
view_range = md->db->range2;
mode = status_get_mode(&md->bl);
- can_move = (mode&MD_CANMOVE)&&unit_can_move(&md->bl);
+ can_move = (mode&MD_CANMOVE)&&unit->can_move(&md->bl);
if (md->target_id)
{ //Check validity of current target. [Skotlex]
@@ -1453,9 +1441,9 @@ static bool mob_ai_sub_hard(struct mob_data *md, unsigned int tick)
((((TBL_PC*)tbl)->state.gangsterparadise && !(mode&MD_BOSS)) ||
((TBL_PC*)tbl)->invincible_timer != INVALID_TIMER)
)) { //Unlock current target.
- if (mob_warpchase(md, tbl))
+ if (mob->warpchase(md, tbl))
return true; //Chasing this target.
- mob_unlocktarget(md, tick-(battle_config.mob_ai&0x8?3000:0)); //Imediately do random walk.
+ mob->unlocktarget(md, tick-(battle_config.mob_ai&0x8?3000:0)); //Imediately do random walk.
tbl = NULL;
}
}
@@ -1470,18 +1458,18 @@ static bool mob_ai_sub_hard(struct mob_data *md, unsigned int tick)
(!can_move && DIFF_TICK(tick, md->ud.canmove_tick) > 0 && (battle_config.mob_ai&0x2 || (md->sc.data[SC_SPIDERWEB] && md->sc.data[SC_SPIDERWEB]->val1)
|| md->sc.data[SC_WUGBITE] || md->sc.data[SC_VACUUM_EXTREME] || md->sc.data[SC_THORNS_TRAP]
|| md->sc.data[SC__MANHOLE])) // Not yet confirmed if boss will teleport once it can't reach target.
- || !mob_can_reach(md, tbl, md->min_chase, MSS_RUSH)
+ || !mob->can_reach(md, tbl, md->min_chase, MSS_RUSH)
)
&& md->state.attacked_count++ >= RUDE_ATTACKED_COUNT
- && !mobskill_use(md, tick, MSC_RUDEATTACKED) // If can't rude Attack
- && can_move && unit_escape(&md->bl, tbl, rnd()%10 +1)) // Attempt escape
+ && !mob->skill_use(md, tick, MSC_RUDEATTACKED) // If can't rude Attack
+ && can_move && unit->escape(&md->bl, tbl, rnd()%10 +1)) // Attempt escape
{ //Escaped
md->attacked_id = 0;
return true;
}
}
else
- if( (abl = iMap->id2bl(md->attacked_id)) && (!tbl || mob_can_changetarget(md, abl, mode)) )
+ if( (abl = iMap->id2bl(md->attacked_id)) && (!tbl || mob->can_changetarget(md, abl, mode)) )
{
int dist;
if( md->bl.m != abl->m || abl->prev == NULL
@@ -1493,13 +1481,13 @@ static bool mob_ai_sub_hard(struct mob_data *md, unsigned int tick)
(!can_move && DIFF_TICK(tick, md->ud.canmove_tick) > 0 && (battle_config.mob_ai&0x2 || (md->sc.data[SC_SPIDERWEB] && md->sc.data[SC_SPIDERWEB]->val1)
|| md->sc.data[SC_WUGBITE] || md->sc.data[SC_VACUUM_EXTREME] || md->sc.data[SC_THORNS_TRAP]
|| md->sc.data[SC__MANHOLE])) // Not yet confirmed if boss will teleport once it can't reach target.
- || !mob_can_reach(md, abl, dist+md->db->range3, MSS_RUSH)
+ || !mob->can_reach(md, abl, dist+md->db->range3, MSS_RUSH)
)
) )
{ // Rude attacked
if (md->state.attacked_count++ >= RUDE_ATTACKED_COUNT
- && !mobskill_use(md, tick, MSC_RUDEATTACKED) && can_move
- && !tbl && unit_escape(&md->bl, abl, rnd()%10 +1))
+ && !mob->skill_use(md, tick, MSC_RUDEATTACKED) && can_move
+ && !tbl && unit->escape(&md->bl, abl, rnd()%10 +1))
{ //Escaped.
//TODO: Maybe it shouldn't attempt to run if it has another, valid target?
md->attacked_id = 0;
@@ -1533,26 +1521,26 @@ static bool mob_ai_sub_hard(struct mob_data *md, unsigned int tick)
}
// Processing of slave monster
- if (md->master_id > 0 && mob_ai_sub_hard_slavemob(md, tick))
+ if (md->master_id > 0 && mob->ai_sub_hard_slavemob(md, tick))
return true;
// Scan area for targets
if (!tbl && mode&MD_LOOTER && md->lootitem && DIFF_TICK(tick, md->ud.canact_tick) > 0 &&
(md->lootitem_count < LOOTITEM_SIZE || battle_config.monster_loot_type != 1))
{ // Scan area for items to loot, avoid trying to loot if the mob is full and can't consume the items.
- iMap->foreachinrange (mob_ai_sub_hard_lootsearch, &md->bl, view_range, BL_ITEM, md, &tbl);
+ iMap->foreachinrange (mob->ai_sub_hard_lootsearch, &md->bl, view_range, BL_ITEM, md, &tbl);
}
if ((!tbl && mode&MD_AGGRESSIVE) || md->state.skillstate == MSS_FOLLOW)
{
- iMap->foreachinrange (mob_ai_sub_hard_activesearch, &md->bl, view_range, DEFAULT_ENEMY_TYPE(md), md, &tbl, mode);
+ iMap->foreachinrange (mob->ai_sub_hard_activesearch, &md->bl, view_range, DEFAULT_ENEMY_TYPE(md), md, &tbl, mode);
}
else
if (mode&MD_CHANGECHASE && (md->state.skillstate == MSS_RUSH || md->state.skillstate == MSS_FOLLOW))
{
int search_size;
search_size = view_range<md->status.rhw.range ? view_range:md->status.rhw.range;
- iMap->foreachinrange (mob_ai_sub_hard_changechase, &md->bl, search_size, DEFAULT_ENEMY_TYPE(md), md, &tbl);
+ iMap->foreachinrange (mob->ai_sub_hard_changechase, &md->bl, search_size, DEFAULT_ENEMY_TYPE(md), md, &tbl);
}
if (!tbl) { //No targets available.
@@ -1563,15 +1551,15 @@ static bool mob_ai_sub_hard(struct mob_data *md, unsigned int tick)
if( md->bg_id && mode&MD_CANATTACK ) {
if( md->ud.walktimer != INVALID_TIMER )
return true;/* we are already moving */
- iMap->foreachinrange (mob_ai_sub_hard_bg_ally, &md->bl, view_range, BL_PC, md, &tbl, mode);
+ iMap->foreachinrange (mob->ai_sub_hard_bg_ally, &md->bl, view_range, BL_PC, md, &tbl, mode);
if( tbl ) {
- if( distance_blxy(&md->bl, tbl->x, tbl->y) <= 3 || unit_walktobl(&md->bl, tbl, 1, 1) )
+ if( distance_blxy(&md->bl, tbl->x, tbl->y) <= 3 || unit->walktobl(&md->bl, tbl, 1, 1) )
return true;/* we're moving or close enough don't unlock the target. */
}
}
//This handles triggering idle walk/skill.
- mob_unlocktarget(md, tick);
+ mob->unlocktarget(md, tick);
return true;
}
@@ -1583,21 +1571,21 @@ static bool mob_ai_sub_hard(struct mob_data *md, unsigned int tick)
return true; //Already locked.
if (md->lootitem == NULL)
{ //Can't loot...
- mob_unlocktarget (md, tick);
+ mob->unlocktarget (md, tick);
return true;
}
if (!check_distance_bl(&md->bl, tbl, 1))
{ //Still not within loot range.
if (!(mode&MD_CANMOVE))
{ //A looter that can't move? Real smart.
- mob_unlocktarget(md,tick);
+ mob->unlocktarget(md,tick);
return true;
}
if (!can_move) //Stuck. Wait before walking.
return true;
md->state.skillstate = MSS_LOOT;
- if (!unit_walktobl(&md->bl, tbl, 1, 1))
- mob_unlocktarget(md, tick); //Can't loot...
+ if (!unit->walktobl(&md->bl, tbl, 1, 1))
+ mob->unlocktarget(md, tick); //Can't loot...
return true;
}
//Within looting range.
@@ -1620,11 +1608,11 @@ static bool mob_ai_sub_hard(struct mob_data *md, unsigned int tick)
{ //Give them walk act/delay to properly mimic players. [Skotlex]
clif->takeitem(&md->bl,tbl);
md->ud.canact_tick = tick + md->status.amotion;
- unit_set_walkdelay(&md->bl, tick, md->status.amotion, 1);
+ unit->set_walkdelay(&md->bl, tick, md->status.amotion, 1);
}
//Clear item.
iMap->clearflooritem (tbl);
- mob_unlocktarget (md,tick);
+ mob->unlocktarget (md,tick);
return true;
}
//Attempt to attack.
@@ -1636,8 +1624,8 @@ static bool mob_ai_sub_hard(struct mob_data *md, unsigned int tick)
{ //Target within range, engage
if(tbl->type == BL_PC)
- mob_log_damage(md, tbl, 0); //Log interaction (counts as 'attacker' for the exp bonus)
- unit_attack(&md->bl,tbl->id,1);
+ mob->log_damage(md, tbl, 0); //Log interaction (counts as 'attacker' for the exp bonus)
+ unit->attack(&md->bl,tbl->id,1);
return true;
}
@@ -1645,8 +1633,8 @@ static bool mob_ai_sub_hard(struct mob_data *md, unsigned int tick)
if (!(mode&MD_CANMOVE))
{ //Can't chase. Attempt an idle skill before unlocking.
md->state.skillstate = MSS_IDLE;
- if (!mobskill_use(md, tick, -1))
- mob_unlocktarget(md,tick);
+ if (!mob->skill_use(md, tick, -1))
+ mob->unlocktarget(md,tick);
return true;
}
@@ -1654,7 +1642,7 @@ static bool mob_ai_sub_hard(struct mob_data *md, unsigned int tick)
{ //Stuck. Attempt an idle skill
md->state.skillstate = MSS_IDLE;
if (!(++md->ud.walk_count%IDLE_SKILL_INTERVAL))
- mobskill_use(md, tick, -1);
+ mob->skill_use(md, tick, -1);
return true;
}
@@ -1666,18 +1654,18 @@ static bool mob_ai_sub_hard(struct mob_data *md, unsigned int tick)
return true;
//Follow up if possible.
- if(!mob_can_reach(md, tbl, md->min_chase, MSS_RUSH) ||
- !unit_walktobl(&md->bl, tbl, md->status.rhw.range, 2))
- mob_unlocktarget(md,tick);
+ if(!mob->can_reach(md, tbl, md->min_chase, MSS_RUSH) ||
+ !unit->walktobl(&md->bl, tbl, md->status.rhw.range, 2))
+ mob->unlocktarget(md,tick);
return true;
}
-static int mob_ai_sub_hard_timer(struct block_list *bl,va_list ap)
+int mob_ai_sub_hard_timer(struct block_list *bl,va_list ap)
{
struct mob_data *md = (struct mob_data*)bl;
unsigned int tick = va_arg(ap, unsigned int);
- if (mob_ai_sub_hard(md, tick))
+ if (mob->ai_sub_hard(md, tick))
{ //Hard AI triggered.
if(!md->state.spotted)
md->state.spotted = 1;
@@ -1689,11 +1677,11 @@ static int mob_ai_sub_hard_timer(struct block_list *bl,va_list ap)
/*==========================================
* Serious processing for mob in PC field of view (foreachclient)
*------------------------------------------*/
-static int mob_ai_sub_foreachclient(struct map_session_data *sd,va_list ap)
+int mob_ai_sub_foreachclient(struct map_session_data *sd,va_list ap)
{
unsigned int tick;
tick=va_arg(ap,unsigned int);
- iMap->foreachinrange(mob_ai_sub_hard_timer,&sd->bl, AREA_SIZE+ACTIVE_AI_RANGE, BL_MOB,tick);
+ iMap->foreachinrange(mob->ai_sub_hard_timer,&sd->bl, AREA_SIZE+ACTIVE_AI_RANGE, BL_MOB,tick);
return 0;
}
@@ -1701,7 +1689,7 @@ static int mob_ai_sub_foreachclient(struct map_session_data *sd,va_list ap)
/*==========================================
* Negligent mode MOB AI (PC is not in near)
*------------------------------------------*/
-static int mob_ai_sub_lazy(struct mob_data *md, va_list args)
+int mob_ai_sub_lazy(struct mob_data *md, va_list args)
{
unsigned int tick;
@@ -1713,7 +1701,7 @@ static int mob_ai_sub_lazy(struct mob_data *md, va_list args)
tick = va_arg(args,unsigned int);
if (battle_config.mob_ai&0x20 && map[md->bl.m].users>0)
- return (int)mob_ai_sub_hard(md, tick);
+ return (int)mob->ai_sub_hard(md, tick);
if (md->bl.prev==NULL || md->status.hp == 0)
return 1;
@@ -1724,7 +1712,7 @@ static int mob_ai_sub_lazy(struct mob_data *md, va_list args)
DIFF_TICK(tick,md->last_thinktime) > MIN_MOBTHINKTIME)
{
if (DIFF_TICK(tick,md->last_pcneartime) < battle_config.mob_active_time)
- return (int)mob_ai_sub_hard(md, tick);
+ return (int)mob->ai_sub_hard(md, tick);
md->last_pcneartime = 0;
}
@@ -1734,7 +1722,7 @@ static int mob_ai_sub_lazy(struct mob_data *md, va_list args)
DIFF_TICK(tick,md->last_thinktime) > MIN_MOBTHINKTIME)
{
if (DIFF_TICK(tick,md->last_pcneartime) < battle_config.boss_active_time)
- return (int)mob_ai_sub_hard(md, tick);
+ return (int)mob->ai_sub_hard(md, tick);
md->last_pcneartime = 0;
}
@@ -1744,24 +1732,24 @@ static int mob_ai_sub_lazy(struct mob_data *md, va_list args)
md->last_thinktime=tick;
if (md->master_id) {
- mob_ai_sub_hard_slavemob (md,tick);
+ mob->ai_sub_hard_slavemob (md,tick);
return 0;
}
- if( DIFF_TICK(md->next_walktime,tick) < 0 && (status_get_mode(&md->bl)&MD_CANMOVE) && unit_can_move(&md->bl) )
+ if( DIFF_TICK(md->next_walktime,tick) < 0 && (status_get_mode(&md->bl)&MD_CANMOVE) && unit->can_move(&md->bl) )
{
if( map[md->bl.m].users > 0 )
{
if( rnd()%1000 < MOB_LAZYMOVEPERC(md) )
- mob_randomwalk(md, tick);
+ mob->randomwalk(md, tick);
else
if( rnd()%1000 < MOB_LAZYSKILLPERC ) //Chance to do a mob's idle skill.
- mobskill_use(md, tick, -1);
+ mob->skill_use(md, tick, -1);
}
else
{
if( rnd()%1000 < MOB_LAZYMOVEPERC(md) )
- mob_randomwalk(md, tick);
+ mob->randomwalk(md, tick);
}
}
return 0;
@@ -1770,22 +1758,22 @@ static int mob_ai_sub_lazy(struct mob_data *md, va_list args)
/*==========================================
* Negligent processing for mob outside PC field of view (interval timer function)
*------------------------------------------*/
-static int mob_ai_lazy(int tid, unsigned int tick, int id, intptr_t data)
+int mob_ai_lazy(int tid, unsigned int tick, int id, intptr_t data)
{
- iMap->map_foreachmob(mob_ai_sub_lazy,tick);
+ iMap->map_foreachmob(mob->ai_sub_lazy,tick);
return 0;
}
/*==========================================
* Serious processing for mob in PC field of view (interval timer function)
*------------------------------------------*/
-static int mob_ai_hard(int tid, unsigned int tick, int id, intptr_t data)
+int mob_ai_hard(int tid, unsigned int tick, int id, intptr_t data)
{
if (battle_config.mob_ai&0x20)
- iMap->map_foreachmob(mob_ai_sub_lazy,tick);
+ iMap->map_foreachmob(mob->ai_sub_lazy,tick);
else
- iMap->map_foreachpc(mob_ai_sub_foreachclient,tick);
+ iMap->map_foreachpc(mob->ai_sub_foreachclient,tick);
return 0;
}
@@ -1793,12 +1781,12 @@ static int mob_ai_hard(int tid, unsigned int tick, int id, intptr_t data)
/*==========================================
* Initializes the delay drop structure for mob-dropped items.
*------------------------------------------*/
-static struct item_drop* mob_setdropitem(int nameid, int qty, struct item_data *data) {
+struct item_drop* mob_setdropitem(int nameid, int qty, struct item_data *data) {
struct item_drop *drop = ers_alloc(item_drop_ers, struct item_drop);
memset(&drop->item_data, 0, sizeof(struct item));
drop->item_data.nameid = nameid;
drop->item_data.amount = qty;
- drop->item_data.identify = data ? itemdb_isidentified2(data) : itemdb_isidentified(nameid);
+ drop->item_data.identify = data ? itemdb->isidentified2(data) : itemdb->isidentified(nameid);
drop->next = NULL;
return drop;
}
@@ -1806,7 +1794,7 @@ static struct item_drop* mob_setdropitem(int nameid, int qty, struct item_data *
/*==========================================
* Initializes the delay drop structure for mob-looted items.
*------------------------------------------*/
-static struct item_drop* mob_setlootitem(struct item* item)
+struct item_drop* mob_setlootitem(struct item* item)
{
struct item_drop *drop = ers_alloc(item_drop_ers, struct item_drop);
memcpy(&drop->item_data, item, sizeof(struct item));
@@ -1817,7 +1805,7 @@ static struct item_drop* mob_setlootitem(struct item* item)
/*==========================================
* item drop with delay (timer function)
*------------------------------------------*/
-static int mob_delay_item_drop(int tid, unsigned int tick, int id, intptr_t data)
+int mob_delay_item_drop(int tid, unsigned int tick, int id, intptr_t data)
{
struct item_drop_list *list;
struct item_drop *ditem, *ditem_prev;
@@ -1841,7 +1829,7 @@ static int mob_delay_item_drop(int tid, unsigned int tick, int id, intptr_t data
* rate is the drop-rate of the item, required for autoloot.
* flag : Killed only by homunculus?
*------------------------------------------*/
-static void mob_item_drop(struct mob_data *md, struct item_drop_list *dlist, struct item_drop *ditem, int loot, int drop_rate, unsigned short flag)
+void mob_item_drop(struct mob_data *md, struct item_drop_list *dlist, struct item_drop *ditem, int loot, int drop_rate, unsigned short flag)
{
TBL_PC* sd;
@@ -1886,7 +1874,7 @@ int mob_timer_delete(int tid, unsigned int tick, int id, intptr_t data)
}
//for Alchemist CANNIBALIZE [Lupus]
md->deletetimer = INVALID_TIMER;
- unit_free(bl, CLR_TELEPORT);
+ unit->free(bl, CLR_TELEPORT);
}
return 0;
}
@@ -1915,7 +1903,7 @@ int mob_deleteslave(struct mob_data *md)
{
nullpo_ret(md);
- iMap->foreachinmap(mob_deleteslave_sub, md->bl.m, BL_MOB,md->bl.id);
+ iMap->foreachinmap(mob->deleteslave_sub, md->bl.m, BL_MOB,md->bl.id);
return 0;
}
// Mob respawning through KAIZEL or NPC_REBIRTH [Skotlex]
@@ -2060,7 +2048,7 @@ void mob_damage(struct mob_data *md, struct block_list *src, int damage) {
}
//Log damage
if (src)
- mob_log_damage(md, src, damage);
+ mob->log_damage(md, src, damage);
md->dmgtick = iTimer->gettick();
}
@@ -2085,7 +2073,7 @@ void mob_damage(struct mob_data *md, struct block_list *src, int damage) {
if( md->special_state.ai == 2 ) {//LOne WOlf explained that ANYONE can trigger the marine countdown skill. [Skotlex]
md->state.alchemist = 1;
- mobskill_use(md, iTimer->gettick(), MSC_ALCHEMIST);
+ mob->skill_use(md, iTimer->gettick(), MSC_ALCHEMIST);
}
}
@@ -2123,7 +2111,7 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type)
if( src )
{ // Use Dead skill only if not killed by Script or Command
md->state.skillstate = MSS_DEAD;
- mobskill_use(md,tick,-1);
+ mob->skill_use(md,tick,-1);
}
iMap->freeblock_lock();
@@ -2131,7 +2119,7 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type)
memset(pt,0,sizeof(pt));
if(src && src->type == BL_MOB)
- mob_unlocktarget((struct mob_data *)src,tick);
+ mob->unlocktarget((struct mob_data *)src,tick);
// filter out entries not eligible for exp distribution
memset(tmpsd,0,sizeof(tmpsd));
@@ -2382,11 +2370,11 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type)
continue;
if( mvp_sd && it->type == IT_PETEGG ) {
- pet_create_egg(mvp_sd, md->db->dropitem[i].nameid);
+ pet->create_egg(mvp_sd, md->db->dropitem[i].nameid);
continue;
}
- ditem = mob_setdropitem(md->db->dropitem[i].nameid, 1, it);
+ ditem = mob->setdropitem(md->db->dropitem[i].nameid, 1, it);
//A Rare Drop Global Announce by Lupus
if( mvp_sd && drop_rate <= battle_config.rare_drop_announce ) {
@@ -2397,14 +2385,14 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type)
}
// Announce first, or else ditem will be freed. [Lance]
// By popular demand, use base drop rate for autoloot code. [Skotlex]
- mob_item_drop(md, dlist, ditem, 0, md->db->dropitem[i].p, homkillonly);
+ mob->item_drop(md, dlist, ditem, 0, md->db->dropitem[i].p, homkillonly);
}
// Ore Discovery [Celest]
if (sd == mvp_sd && pc->checkskill(sd,BS_FINDINGORE) > 0) {
if( (temp = itemdb->chain_item(itemdb->chain_cache[ECC_ORE],&i)) ) {
- ditem = mob_setdropitem(temp, 1, NULL);
- mob_item_drop(md, dlist, ditem, 0, i, homkillonly);
+ ditem = mob->setdropitem(temp, 1, NULL);
+ mob->item_drop(md, dlist, ditem, 0, i, homkillonly);
}
}
@@ -2435,7 +2423,7 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type)
continue;
itemid = (sd->add_drop[i].id > 0) ? sd->add_drop[i].id : itemdb->chain_item(sd->add_drop[i].group,&drop_rate);
if( itemid )
- mob_item_drop(md, dlist, mob_setdropitem(itemid,1,NULL), 0, drop_rate, homkillonly);
+ mob->item_drop(md, dlist, mob->setdropitem(itemid,1,NULL), 0, drop_rate, homkillonly);
}
}
@@ -2450,10 +2438,10 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type)
// process items looted by the mob
if(md->lootitem) {
for(i = 0; i < md->lootitem_count; i++)
- mob_item_drop(md, dlist, mob_setlootitem(&md->lootitem[i]), 1, 10000, homkillonly);
+ mob->item_drop(md, dlist, mob->setlootitem(&md->lootitem[i]), 1, 10000, homkillonly);
}
if (dlist->item) //There are drop items.
- iTimer->add_timer(tick + (!battle_config.delay_battle_damage?500:0), mob_delay_item_drop, 0, (intptr_t)dlist);
+ iTimer->add_timer(tick + (!battle_config.delay_battle_damage?500:0), mob->delay_item_drop, 0, (intptr_t)dlist);
else //No drops
ers_free(item_drop_list_ers, dlist);
} else if (md->lootitem && md->lootitem_count) { //Loot MUST drop!
@@ -2466,8 +2454,8 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type)
dlist->third_charid = (third_sd ? third_sd->status.char_id : 0);
dlist->item = NULL;
for(i = 0; i < md->lootitem_count; i++)
- mob_item_drop(md, dlist, mob_setlootitem(&md->lootitem[i]), 1, 10000, homkillonly);
- iTimer->add_timer(tick + (!battle_config.delay_battle_damage?500:0), mob_delay_item_drop, 0, (intptr_t)dlist);
+ mob->item_drop(md, dlist, mob->setlootitem(&md->lootitem[i]), 1, 10000, homkillonly);
+ iTimer->add_timer(tick + (!battle_config.delay_battle_damage?500:0), mob->delay_item_drop, 0, (intptr_t)dlist);
}
if(mvp_sd && md->db->mexp > 0 && !md->special_state.ai) {
@@ -2525,7 +2513,7 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type)
memset(&item,0,sizeof(item));
item.nameid=mdrop_id[i];
- item.identify= itemdb_isidentified2(data);
+ item.identify= itemdb->isidentified2(data);
clif->mvp_item(mvp_sd,item.nameid);
log_mvp[0] = item.nameid;
@@ -2569,7 +2557,7 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type)
if( sd ) {
if( sd->mission_mobid == md->class_) { //TK_MISSION [Skotlex]
- if( ++sd->mission_count >= 100 && (temp = mob_get_random_id(0, 0xE, sd->status.base_level)) ) {
+ if( ++sd->mission_count >= 100 && (temp = mob->get_random_id(0, 0xE, sd->status.base_level)) ) {
pc->addfame(sd, 1);
sd->mission_mobid = temp;
pc_setglobalreg(sd,"TK_MISSION_ID", temp);
@@ -2580,40 +2568,40 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type)
}
if( sd->status.party_id )
- iMap->foreachinrange(quest_update_objective_sub,&md->bl,AREA_SIZE,BL_PC,sd->status.party_id,md->class_);
+ iMap->foreachinrange(quest->update_objective_sub,&md->bl,AREA_SIZE,BL_PC,sd->status.party_id,md->class_);
else if( sd->avail_quests )
- quest_update_objective(sd, md->class_);
+ quest->update_objective(sd, md->class_);
- if( sd->md && src && src->type != BL_HOM && mob_db(md->class_)->lv > sd->status.base_level/2 )
+ if( sd->md && src && src->type != BL_HOM && mob->db(md->class_)->lv > sd->status.base_level/2 )
mercenary->kills(sd->md);
}
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;
}
if(md->deletetimer != INVALID_TIMER) {
- iTimer->delete_timer(md->deletetimer,mob_timer_delete);
+ iTimer->delete_timer(md->deletetimer,mob->timer_delete);
md->deletetimer = INVALID_TIMER;
}
/**
* Only loops if necessary (e.g. a poring would never need to loop)
**/
if( md->can_summon )
- mob_deleteslave(md);
+ mob->deleteslave(md);
iMap->freeblock_unlock();
@@ -2637,11 +2625,11 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type)
// MvP tomb [GreenBox]
if (battle_config.mvp_tomb_enabled && md->spawn->state.boss && map[md->bl.m].flag.notomb != 1)
- mvptomb_create(md, mvp_sd ? mvp_sd->status.name : NULL, time(NULL));
+ mob->mvptomb_create(md, mvp_sd ? mvp_sd->status.name : NULL, time(NULL));
if( !rebirth ) {
iStatus->change_clear(&md->bl,1);
- mob_setdelayspawn(md); //Set respawning.
+ mob->setdelayspawn(md); //Set respawning.
}
return 3; //Remove from map.
}
@@ -2660,7 +2648,7 @@ void mob_revive(struct mob_data *md, unsigned int hp)
iMap->addblock(&md->bl);
clif->spawn(&md->bl);
skill->unit_move(&md->bl,tick,1);
- mobskill_use(md, tick, MSC_SPAWN);
+ mob->skill_use(md, tick, MSC_SPAWN);
if (battle_config.show_mob_info&3)
clif->charnameack (0, &md->bl);
}
@@ -2683,7 +2671,7 @@ int mob_guardian_guildchange(struct mob_data *md)
} else {
if (md->guardian_data->number >= 0 && md->guardian_data->number < MAX_GUARDIANS && md->guardian_data->castle->guardian[md->guardian_data->number].visible)
guild->castledatasave(md->guardian_data->castle->castle_id, 10+md->guardian_data->number, 0);
- unit_free(&md->bl,CLR_OUTSIGHT); //Remove guardian.
+ unit->free(&md->bl,CLR_OUTSIGHT); //Remove guardian.
}
return 0;
}
@@ -2694,7 +2682,7 @@ int mob_guardian_guildchange(struct mob_data *md)
ShowError("mob_guardian_guildchange: New Guild (id %d) does not exists!\n", md->guardian_data->guild_id);
if (md->guardian_data->number >= 0 && md->guardian_data->number < MAX_GUARDIANS)
guild->castledatasave(md->guardian_data->castle->castle_id, 10+md->guardian_data->number, 0);
- unit_free(&md->bl,CLR_OUTSIGHT);
+ unit->free(&md->bl,CLR_OUTSIGHT);
return 0;
}
@@ -2716,16 +2704,16 @@ int mob_random_class (int *value, size_t count)
// no count specified, look into the array manually, but take only max 5 elements
if (count < 1) {
count = 0;
- while(count < 5 && mobdb_checkid(value[count])) count++;
+ while(count < 5 && mob->db_checkid(value[count])) count++;
if(count < 1) // nothing found
return 0;
} else {
// check if at least the first value is valid
- if(mobdb_checkid(value[0]) == 0)
+ if(mob->db_checkid(value[0]) == 0)
return 0;
}
//Pick a random value, hoping it exists. [Skotlex]
- return mobdb_checkid(value[rnd()%count]);
+ return mob->db_checkid(value[rnd()%count]);
}
/*==========================================
@@ -2751,7 +2739,7 @@ int mob_class_change (struct mob_data *md, int class_)
if( md->special_state.ai > 1 )
return 0; //Marine Spheres and Floras.
- if( mob_is_clone(md->class_) )
+ if( mob->is_clone(md->class_) )
return 0; //Clones
if( md->class_ == class_ )
@@ -2759,7 +2747,7 @@ int mob_class_change (struct mob_data *md, int class_)
hp_rate = get_percentage(md->status.hp, md->status.max_hp);
md->class_ = class_;
- md->db = mob_db(class_);
+ md->db = mob->db(class_);
if (battle_config.override_mob_names==1)
memcpy(md->name,md->db->name,NAME_LENGTH);
else
@@ -2767,7 +2755,7 @@ int mob_class_change (struct mob_data *md, int class_)
mob_stop_attack(md);
mob_stop_walking(md, 0);
- unit_skillcastcancel(&md->bl, 0);
+ unit->skillcastcancel(&md->bl, 0);
iStatus->set_viewdata(&md->bl, class_);
clif->class_change(&md->bl, md->vd->class_, 1);
status_calc_mob(md, 1);
@@ -2820,7 +2808,7 @@ int mob_warpslave_sub(struct block_list *bl,va_list ap)
return 0;
iMap->search_freecell(master, 0, &x, &y, range, range, 0);
- unit_warp(&md->bl, master->m, x, y,CLR_RESPAWN);
+ unit->warp(&md->bl, master->m, x, y,CLR_RESPAWN);
return 1;
}
@@ -2834,7 +2822,7 @@ int mob_warpslave(struct block_list *bl, int range)
if (range < 1)
range = 1; //Min range needed to avoid crashes and stuff. [Skotlex]
- return iMap->foreachinmap(mob_warpslave_sub, bl->m, BL_MOB, bl, range);
+ return iMap->foreachinmap(mob->warpslave_sub, bl->m, BL_MOB, bl, range);
}
/*==========================================
@@ -2857,7 +2845,7 @@ int mob_countslave_sub(struct block_list *bl,va_list ap)
*------------------------------------------*/
int mob_countslave(struct block_list *bl)
{
- return iMap->foreachinmap(mob_countslave_sub, bl->m, BL_MOB,bl->id);
+ return iMap->foreachinmap(mob->countslave_sub, bl->m, BL_MOB,bl->id);
}
/*==========================================
@@ -2880,14 +2868,14 @@ int mob_summonslave(struct mob_data *md2,int *value,int amount,uint16 skill_id)
data.state.size = md2->special_state.size;
data.state.ai = md2->special_state.ai;
- if(mobdb_checkid(value[0]) == 0)
+ if(mob->db_checkid(value[0]) == 0)
return 0;
/**
* Flags this monster is able to summon; saves a worth amount of memory upon deletion
**/
md2->can_summon = 1;
- while(count < 5 && mobdb_checkid(value[count])) count++;
+ while(count < 5 && mob->db_checkid(value[count])) count++;
if(count < 1) return 0;
if (amount > 0 && amount < count) { //Do not start on 0, pick some random sub subset [Skotlex]
k = rnd()%count;
@@ -2901,7 +2889,7 @@ int mob_summonslave(struct mob_data *md2,int *value,int amount,uint16 skill_id)
for(;k<amount;k++) {
short x,y;
data.class_ = value[k%count]; //Summon slaves in round-robin fashion. [Skotlex]
- if (mobdb_checkid(data.class_) == 0)
+ if (mob->db_checkid(data.class_) == 0)
continue;
if (iMap->search_freecell(&md2->bl, 0, &x, &y, MOB_SLAVEDISTANCE, MOB_SLAVEDISTANCE, 0)) {
@@ -2918,15 +2906,15 @@ int mob_summonslave(struct mob_data *md2,int *value,int amount,uint16 skill_id)
else
strcpy(data.name,"--ja--");
- if (!mob_parse_dataset(&data))
+ if (!mob->parse_dataset(&data))
continue;
- md= mob_spawn_dataset(&data);
+ md= mob->spawn_dataset(&data);
if(skill_id == NPC_SUMMONSLAVE){
md->master_id=md2->bl.id;
md->special_state.ai = md2->special_state.ai;
}
- mob_spawn(md);
+ mob->spawn(md);
if (hp_rate) //Scale HP
md->status.hp = md->status.max_hp*hp_rate/100;
@@ -2964,8 +2952,8 @@ int mob_summonslave(struct mob_data *md2,int *value,int amount,uint16 skill_id)
*------------------------------------------*/
int mob_skill_id2skill_idx(int class_,uint16 skill_id)
{
- int i, max = mob_db(class_)->maxskill;
- struct mob_skill *ms=mob_db(class_)->skill;
+ int i, max = mob->db(class_)->maxskill;
+ struct mob_skill *ms=mob->db(class_)->skill;
if(ms==NULL)
return -1;
@@ -3003,7 +2991,7 @@ int mob_getfriendhprate_sub(struct block_list *bl,va_list ap)
(*fr) = bl;
return 1;
}
-static struct block_list *mob_getfriendhprate(struct mob_data *md,int min_rate,int max_rate)
+struct block_list *mob_getfriendhprate(struct mob_data *md,int min_rate,int max_rate)
{
struct block_list *fr=NULL;
int type = BL_MOB;
@@ -3013,7 +3001,7 @@ static struct block_list *mob_getfriendhprate(struct mob_data *md,int min_rate,i
if (md->special_state.ai) //Summoned creatures. [Skotlex]
type = BL_PC;
- iMap->foreachinrange(mob_getfriendhprate_sub, &md->bl, 8, type,md,min_rate,max_rate,&fr);
+ iMap->foreachinrange(mob->getfriendhprate_sub, &md->bl, 8, type,md,min_rate,max_rate,&fr);
return fr;
}
/*==========================================
@@ -3070,7 +3058,7 @@ struct mob_data *mob_getfriendstatus(struct mob_data *md,int cond1,int cond2)
struct mob_data* fr = NULL;
nullpo_ret(md);
- iMap->foreachinrange(mob_getfriendstatus_sub, &md->bl, 8,BL_MOB, md,cond1,cond2,&fr);
+ iMap->foreachinrange(mob->getfriendstatus_sub, &md->bl, 8,BL_MOB, md,cond1,cond2,&fr);
return fr;
}
@@ -3149,20 +3137,20 @@ int mobskill_use(struct mob_data *md, unsigned int tick, int event)
}
flag ^= (ms[i].cond1 == MSC_MYSTATUSOFF); break;
case MSC_FRIENDHPLTMAXRATE: // friend HP < maxhp%
- flag = ((fbl = mob_getfriendhprate(md, 0, ms[i].cond2)) != NULL); break;
+ flag = ((fbl = mob->getfriendhprate(md, 0, ms[i].cond2)) != NULL); break;
case MSC_FRIENDHPINRATE :
- flag = ((fbl = mob_getfriendhprate(md, ms[i].cond2, ms[i].val[0])) != NULL); break;
+ flag = ((fbl = mob->getfriendhprate(md, ms[i].cond2, ms[i].val[0])) != NULL); break;
case MSC_FRIENDSTATUSON: // friend status[num] on
case MSC_FRIENDSTATUSOFF: // friend status[num] off
- flag = ((fmd = mob_getfriendstatus(md, ms[i].cond1, ms[i].cond2)) != NULL); break;
+ flag = ((fmd = mob->getfriendstatus(md, ms[i].cond1, ms[i].cond2)) != NULL); break;
case MSC_SLAVELT: // slave < num
- flag = (mob_countslave(&md->bl) < c2 ); break;
+ flag = (mob->countslave(&md->bl) < c2 ); break;
case MSC_ATTACKPCGT: // attack pc > num
- flag = (unit_counttargeted(&md->bl) > c2); break;
+ flag = (unit->counttargeted(&md->bl) > c2); break;
case MSC_SLAVELE: // slave <= num
- flag = (mob_countslave(&md->bl) <= c2 ); break;
+ flag = (mob->countslave(&md->bl) <= c2 ); break;
case MSC_ATTACKPCGE: // attack pc >= num
- flag = (unit_counttargeted(&md->bl) >= c2); break;
+ flag = (unit->counttargeted(&md->bl) >= c2); break;
case MSC_AFTERSKILL:
flag = (md->ud.skill_id == c2); break;
case MSC_RUDEATTACKED:
@@ -3170,9 +3158,9 @@ int mobskill_use(struct mob_data *md, unsigned int tick, int event)
if (flag) md->state.attacked_count = 0; //Rude attacked count should be reset after the skill condition is met. Thanks to Komurka [Skotlex]
break;
case MSC_MASTERHPLTMAXRATE:
- flag = ((fbl = mob_getmasterhpltmaxrate(md, ms[i].cond2)) != NULL); break;
+ flag = ((fbl = mob->getmasterhpltmaxrate(md, ms[i].cond2)) != NULL); break;
case MSC_MASTERATTACKED:
- flag = (md->master_id > 0 && (fbl=iMap->id2bl(md->master_id)) && unit_counttargeted(fbl) > 0); break;
+ flag = (md->master_id > 0 && (fbl=iMap->id2bl(md->master_id)) && unit->counttargeted(fbl) > 0); break;
case MSC_ALCHEMIST:
flag = (md->state.alchemist);
break;
@@ -3224,7 +3212,7 @@ int mobskill_use(struct mob_data *md, unsigned int tick, int event)
md->skill_idx = i;
iMap->freeblock_lock();
if( !battle->check_range(&md->bl,bl,skill->get_range2(&md->bl, ms[i].skill_id,ms[i].skill_lv)) ||
- !unit_skilluse_pos2(&md->bl, x, y,ms[i].skill_id, ms[i].skill_lv,ms[i].casttime, ms[i].cancel) )
+ !unit->skilluse_pos2(&md->bl, x, y,ms[i].skill_id, ms[i].skill_lv,ms[i].casttime, ms[i].cancel) )
{
iMap->freeblock_unlock();
continue;
@@ -3262,7 +3250,7 @@ int mobskill_use(struct mob_data *md, unsigned int tick, int event)
md->skill_idx = i;
iMap->freeblock_lock();
if( !battle->check_range(&md->bl,bl,skill->get_range2(&md->bl, ms[i].skill_id,ms[i].skill_lv)) ||
- !unit_skilluse_id2(&md->bl, bl->id,ms[i].skill_id, ms[i].skill_lv,ms[i].casttime, ms[i].cancel) )
+ !unit->skilluse_id2(&md->bl, bl->id,ms[i].skill_id, ms[i].skill_lv,ms[i].casttime, ms[i].cancel) )
{
iMap->freeblock_unlock();
continue;
@@ -3270,7 +3258,7 @@ int mobskill_use(struct mob_data *md, unsigned int tick, int event)
}
//Skill used. Post-setups...
if ( ms[ i ].msg_id ){ //Display color message [SnakeDrak]
- struct mob_chat *mc = mob_chat(ms[i].msg_id);
+ struct mob_chat *mc = mob->chat(ms[i].msg_id);
char temp[CHAT_SIZE_MAX];
char name[NAME_LENGTH];
snprintf(name, sizeof name,"%s", md->name);
@@ -3306,13 +3294,13 @@ int mobskill_event(struct mob_data *md, struct block_list *src, unsigned int tic
md->target_id = src->id;
if (flag == -1)
- res = mobskill_use(md, tick, MSC_CASTTARGETED);
+ res = mob->skill_use(md, tick, MSC_CASTTARGETED);
else if ((flag&0xffff) == MSC_SKILLUSED)
- res = mobskill_use(md, tick, flag);
+ res = mob->skill_use(md, tick, flag);
else if (flag&BF_SHORT)
- res = mobskill_use(md, tick, MSC_CLOSEDATTACKED);
+ res = mob->skill_use(md, tick, MSC_CLOSEDATTACKED);
else if (flag&BF_LONG && !(flag&BF_MAGIC)) //Long-attacked should not include magic.
- res = mobskill_use(md, tick, MSC_LONGRANGEATTACKED);
+ res = mob->skill_use(md, tick, MSC_LONGRANGEATTACKED);
if (!res)
//Restore previous target only if skill condition failed to trigger. [Skotlex]
@@ -3329,7 +3317,7 @@ int mob_is_clone(int class_)
{
if(class_ < MOB_CLONE_START || class_ > MOB_CLONE_END)
return 0;
- if (mob_db(class_) == mob_dummy)
+ if (mob->db(class_) == mob->dummy)
return 0;
return class_;
}
@@ -3353,11 +3341,11 @@ int mob_clone_spawn(struct map_session_data *sd, int16 m, int16 x, int16 y, cons
if(pc_isdead(sd) && master_id && flag&1)
return 0;
- ARR_FIND( MOB_CLONE_START, MOB_CLONE_END, class_, mob_db_data[class_] == NULL );
+ ARR_FIND( MOB_CLONE_START, MOB_CLONE_END, class_, mob->db_data[class_] == NULL );
if(class_ >= MOB_CLONE_END)
return 0;
- db = mob_db_data[class_]=(struct mob_db*)aCalloc(1, sizeof(struct mob_db));
+ db = mob->db_data[class_]=(struct mob_db*)aCalloc(1, sizeof(struct mob_db));
status = &db->status;
strcpy(db->sprite,sd->status.name);
strcpy(db->name,sd->status.name);
@@ -3519,7 +3507,7 @@ int mob_clone_spawn(struct map_session_data *sd, int16 m, int16 x, int16 y, cons
sd->fd = fd;
//Finally, spawn it.
- md = mob_once_spawn_sub(&sd->bl, m, x, y, "--en--", class_, event, SZ_SMALL, AI_NONE);
+ md = mob->once_spawn_sub(&sd->bl, m, x, y, "--en--", class_, event, SZ_SMALL, AI_NONE);
if (!md) return 0; //Failed?
md->special_state.clone = 1;
@@ -3532,12 +3520,12 @@ int mob_clone_spawn(struct map_session_data *sd, int16 m, int16 x, int16 y, cons
if (duration) //Auto Delete after a while.
{
if( md->deletetimer != INVALID_TIMER )
- iTimer->delete_timer(md->deletetimer, mob_timer_delete);
- md->deletetimer = iTimer->add_timer (iTimer->gettick() + duration, mob_timer_delete, md->bl.id, 0);
+ iTimer->delete_timer(md->deletetimer, mob->timer_delete);
+ md->deletetimer = iTimer->add_timer (iTimer->gettick() + duration, mob->timer_delete, md->bl.id, 0);
}
}
- mob_spawn(md);
+ mob->spawn(md);
return md->bl.id;
}
@@ -3546,11 +3534,11 @@ int mob_clone_delete(struct mob_data *md)
{
const int class_ = md->class_;
if (class_ >= MOB_CLONE_START && class_ < MOB_CLONE_END
- && mob_db_data[class_]!=NULL) {
- aFree(mob_db_data[class_]);
- mob_db_data[class_]=NULL;
+ && mob->db_data[class_]!=NULL) {
+ aFree(mob->db_data[class_]);
+ mob->db_data[class_]=NULL;
//Clear references to the db
- md->db = mob_dummy;
+ md->db = mob->dummy;
md->vd = NULL;
return 1;
}
@@ -3563,50 +3551,50 @@ int mob_clone_delete(struct mob_data *md)
/*==========================================
* Since un-setting [ mob ] up was used, it is an initial provisional value setup.
*------------------------------------------*/
-static int mob_makedummymobdb(int class_)
+int mob_makedummymobdb(int class_)
{
- if (mob_dummy != NULL)
+ if (mob->dummy != NULL)
{
- if (mob_db(class_) == mob_dummy)
- return 1; //Using the mob_dummy data already. [Skotlex]
+ if (mob->db(class_) == mob->dummy)
+ return 1; //Using the mob->dummy data already. [Skotlex]
if (class_ > 0 && class_ <= MAX_MOB_DB)
{ //Remove the mob data so that it uses the dummy data instead.
- aFree(mob_db_data[class_]);
- mob_db_data[class_] = NULL;
+ aFree(mob->db_data[class_]);
+ mob->db_data[class_] = NULL;
}
return 0;
}
//Initialize dummy data.
- mob_dummy = (struct mob_db*)aCalloc(1, sizeof(struct mob_db)); //Initializing the dummy mob.
- sprintf(mob_dummy->sprite,"DUMMY");
- sprintf(mob_dummy->name,"Dummy");
- sprintf(mob_dummy->jname,"Dummy");
- mob_dummy->lv=1;
- mob_dummy->status.max_hp=1000;
- mob_dummy->status.max_sp=1;
- mob_dummy->status.rhw.range=1;
- mob_dummy->status.rhw.atk=7;
- mob_dummy->status.rhw.atk2=10;
- mob_dummy->status.str=1;
- mob_dummy->status.agi=1;
- mob_dummy->status.vit=1;
- mob_dummy->status.int_=1;
- mob_dummy->status.dex=6;
- mob_dummy->status.luk=2;
- mob_dummy->status.speed=300;
- mob_dummy->status.adelay=1000;
- mob_dummy->status.amotion=500;
- mob_dummy->status.dmotion=500;
- mob_dummy->base_exp=2;
- mob_dummy->job_exp=1;
- mob_dummy->range2=10;
- mob_dummy->range3=10;
+ mob->dummy = (struct mob_db*)aCalloc(1, sizeof(struct mob_db)); //Initializing the dummy mob.
+ sprintf(mob->dummy->sprite,"DUMMY");
+ sprintf(mob->dummy->name,"Dummy");
+ sprintf(mob->dummy->jname,"Dummy");
+ mob->dummy->lv=1;
+ mob->dummy->status.max_hp=1000;
+ mob->dummy->status.max_sp=1;
+ mob->dummy->status.rhw.range=1;
+ mob->dummy->status.rhw.atk=7;
+ mob->dummy->status.rhw.atk2=10;
+ mob->dummy->status.str=1;
+ mob->dummy->status.agi=1;
+ mob->dummy->status.vit=1;
+ mob->dummy->status.int_=1;
+ mob->dummy->status.dex=6;
+ mob->dummy->status.luk=2;
+ mob->dummy->status.speed=300;
+ mob->dummy->status.adelay=1000;
+ mob->dummy->status.amotion=500;
+ mob->dummy->status.dmotion=500;
+ mob->dummy->base_exp=2;
+ mob->dummy->job_exp=1;
+ mob->dummy->range2=10;
+ mob->dummy->range3=10;
return 0;
}
//Adjusts the drop rate of item according to the criteria given. [Skotlex]
-static unsigned int mob_drop_adjust(int baserate, int rate_adjust, unsigned short rate_min, unsigned short rate_max)
+unsigned int mob_drop_adjust(int baserate, int rate_adjust, unsigned short rate_min, unsigned short rate_max)
{
double rate = baserate;
@@ -3628,7 +3616,7 @@ static unsigned int mob_drop_adjust(int baserate, int rate_adjust, unsigned shor
* @param mob_id ID of the monster
* @param rate_adjust pointer to store ratio if found
*/
-static void item_dropratio_adjust(int nameid, int mob_id, int *rate_adjust)
+void item_dropratio_adjust(int nameid, int mob_id, int *rate_adjust)
{
if( item_drop_ratio_db[nameid] ) {
if( item_drop_ratio_db[nameid]->mob_id[0] ) { // only for listed mobs
@@ -3655,7 +3643,7 @@ static inline int mob_parse_dbrow_cap_value(int class_, int min, int max, int va
/*==========================================
* processes one mobdb entry
*------------------------------------------*/
-static bool mob_parse_dbrow(char** str)
+bool mob_parse_dbrow(char** str)
{
struct mob_db *db, entry;
struct status_data *status;
@@ -3803,8 +3791,8 @@ static bool mob_parse_dbrow(char** str)
db->mvpitem[i].p = 0; //No item....
continue;
}
- item_dropratio_adjust(db->mvpitem[i].nameid, class_, &rate_adjust);
- db->mvpitem[i].p = mob_drop_adjust(atoi(str[32+i*2]), rate_adjust, battle_config.item_drop_mvp_min, battle_config.item_drop_mvp_max);
+ mob->item_dropratio_adjust(db->mvpitem[i].nameid, class_, &rate_adjust);
+ db->mvpitem[i].p = mob->drop_adjust(atoi(str[32+i*2]), rate_adjust, battle_config.item_drop_mvp_min, battle_config.item_drop_mvp_max);
//calculate and store Max available drop chance of the MVP item
if (db->mvpitem[i].p) {
@@ -3867,8 +3855,8 @@ static bool mob_parse_dbrow(char** str)
ratemax = battle_config.item_drop_common_max;
break;
}
- item_dropratio_adjust(id->nameid, class_, &rate_adjust);
- db->dropitem[i].p = mob_drop_adjust(rate, rate_adjust, ratemin, ratemax);
+ mob->item_dropratio_adjust(id->nameid, class_, &rate_adjust);
+ db->dropitem[i].p = mob->drop_adjust(rate, rate_adjust, ratemin, ratemax);
//calculate and store Max available drop chance of the item
if( db->dropitem[i].p && (class_ < 1324 || class_ > 1363) && (class_ < 1938 || class_ > 1946) )
@@ -3890,25 +3878,25 @@ static bool mob_parse_dbrow(char** str)
}
}
// Finally insert monster's data into the database.
- if (mob_db_data[class_] == NULL)
- mob_db_data[class_] = (struct mob_db*)aMalloc(sizeof(struct mob_db));
+ if (mob->db_data[class_] == NULL)
+ mob->db_data[class_] = (struct mob_db*)aMalloc(sizeof(struct mob_db));
else
//Copy over spawn data
- memcpy(&db->spawn, mob_db_data[class_]->spawn, sizeof(db->spawn));
+ memcpy(&db->spawn, mob->db_data[class_]->spawn, sizeof(db->spawn));
- memcpy(mob_db_data[class_], db, sizeof(struct mob_db));
+ memcpy(mob->db_data[class_], db, sizeof(struct mob_db));
return true;
}
/*==========================================
* mob_db.txt reading
*------------------------------------------*/
-static bool mob_readdb_sub(char* fields[], int columns, int current)
+bool mob_readdb_sub(char* fields[], int columns, int current)
{
- return mob_parse_dbrow(fields);
+ return mob->parse_dbrow(fields);
}
-static void mob_readdb(void)
+void mob_readdb(void)
{
const char* filename[] = {
DBPATH"mob_db.txt",
@@ -3927,14 +3915,14 @@ static void mob_readdb(void)
}
}
- sv->readdb(iMap->db_path, filename[fi], ',', 31+2*MAX_MVP_DROP+2*MAX_MOB_DROP, 31+2*MAX_MVP_DROP+2*MAX_MOB_DROP, -1, &mob_readdb_sub);
+ sv->readdb(iMap->db_path, filename[fi], ',', 31+2*MAX_MVP_DROP+2*MAX_MOB_DROP, 31+2*MAX_MVP_DROP+2*MAX_MOB_DROP, -1, mob->readdb_sub);
}
}
/*==========================================
* mob_db table reading
*------------------------------------------*/
-static int mob_read_sqldb(void)
+int mob_read_sqldb(void)
{
const char* mob_db_name[] = { iMap->mob_db_db, iMap->mob_db2_db };
int fi;
@@ -3968,7 +3956,7 @@ static int mob_read_sqldb(void)
p+= len + 1;
}
- if (!mob_parse_dbrow(str))
+ if (!mob->parse_dbrow(str))
continue;
count++;
@@ -3985,13 +3973,13 @@ static int mob_read_sqldb(void)
/*==========================================
* MOB display graphic change data reading
*------------------------------------------*/
-static bool mob_readdb_mobavail(char* str[], int columns, int current)
+bool mob_readdb_mobavail(char* str[], int columns, int current)
{
int class_, k;
class_=atoi(str[0]);
- if(mob_db(class_) == mob_dummy) // invalid class (probably undefined in db)
+ if(mob->db(class_) == mob->dummy) // invalid class (probably undefined in db)
{
ShowWarning("mob_readdb_mobavail: Unknown mob id %d.\n", class_);
return false;
@@ -3999,24 +3987,24 @@ static bool mob_readdb_mobavail(char* str[], int columns, int current)
k=atoi(str[1]);
- memset(&mob_db_data[class_]->vd, 0, sizeof(struct view_data));
- mob_db_data[class_]->vd.class_=k;
+ memset(&mob->db_data[class_]->vd, 0, sizeof(struct view_data));
+ mob->db_data[class_]->vd.class_=k;
//Player sprites
if(pcdb_checkid(k) && columns==12) {
- mob_db_data[class_]->vd.sex=atoi(str[2]);
- mob_db_data[class_]->vd.hair_style=atoi(str[3]);
- mob_db_data[class_]->vd.hair_color=atoi(str[4]);
- mob_db_data[class_]->vd.weapon=atoi(str[5]);
- mob_db_data[class_]->vd.shield=atoi(str[6]);
- mob_db_data[class_]->vd.head_top=atoi(str[7]);
- mob_db_data[class_]->vd.head_mid=atoi(str[8]);
- mob_db_data[class_]->vd.head_bottom=atoi(str[9]);
- mob_db_data[class_]->option=atoi(str[10])&~(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE);
- mob_db_data[class_]->vd.cloth_color=atoi(str[11]); // Monster player dye option - Valaris
+ mob->db_data[class_]->vd.sex=atoi(str[2]);
+ mob->db_data[class_]->vd.hair_style=atoi(str[3]);
+ mob->db_data[class_]->vd.hair_color=atoi(str[4]);
+ mob->db_data[class_]->vd.weapon=atoi(str[5]);
+ mob->db_data[class_]->vd.shield=atoi(str[6]);
+ mob->db_data[class_]->vd.head_top=atoi(str[7]);
+ mob->db_data[class_]->vd.head_mid=atoi(str[8]);
+ mob->db_data[class_]->vd.head_bottom=atoi(str[9]);
+ mob->db_data[class_]->option=atoi(str[10])&~(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE);
+ mob->db_data[class_]->vd.cloth_color=atoi(str[11]); // Monster player dye option - Valaris
}
else if(columns==3)
- mob_db_data[class_]->vd.head_bottom=atoi(str[2]); // mob equipment [Valaris]
+ mob->db_data[class_]->vd.head_bottom=atoi(str[2]); // mob equipment [Valaris]
else if( columns != 2 )
return false;
@@ -4026,7 +4014,7 @@ static bool mob_readdb_mobavail(char* str[], int columns, int current)
/*==========================================
* Reading of random monster data
*------------------------------------------*/
-static int mob_read_randommonster(void)
+int mob_read_randommonster(void)
{
FILE *fp;
char line[1024];
@@ -4043,7 +4031,7 @@ static int mob_read_randommonster(void)
for( i = 0; i < ARRAYLENGTH(mobfile) && i < MAX_RANDOMMONSTER; i++ ) {
unsigned int count = 0;
- mob_db_data[0]->summonper[i] = 1002; // Default fallback value, in case the database does not provide one
+ mob->db_data[0]->summonper[i] = 1002; // Default fallback value, in case the database does not provide one
sprintf(line, "%s/%s", iMap->db_path, mobfile[i]);
fp=fopen(line,"r");
if(fp==NULL){
@@ -4066,10 +4054,10 @@ static int mob_read_randommonster(void)
continue;
class_ = atoi(str[0]);
- if(mob_db(class_) == mob_dummy)
+ if(mob->db(class_) == mob->dummy)
continue;
count++;
- mob_db_data[class_]->summonper[i]=atoi(str[2]);
+ mob->db_data[class_]->summonper[i]=atoi(str[2]);
if (i) {
if( summon[i].qty < ARRAYLENGTH(summon[i].class_) ) //MvPs
summon[i].class_[summon[i].qty++] = class_;
@@ -4080,7 +4068,7 @@ static int mob_read_randommonster(void)
}
}
if (i && !summon[i].qty) { //At least have the default here.
- summon[i].class_[0] = mob_db_data[0]->summonper[i];
+ summon[i].class_[0] = mob->db_data[0]->summonper[i];
summon[i].qty = 1;
}
fclose(fp);
@@ -4093,7 +4081,7 @@ static int mob_read_randommonster(void)
* processes one mob_chat_db entry [SnakeDrak]
* @param last_msg_id ensures that only one error message per mob id is printed
*------------------------------------------*/
-static bool mob_parse_row_chatdb(char** str, const char* source, int line, int* last_msg_id)
+bool mob_parse_row_chatdb(char** str, const char* source, int line, int* last_msg_id)
{
char* msg;
struct mob_chat *ms;
@@ -4111,10 +4099,10 @@ static bool mob_parse_row_chatdb(char** str, const char* source, int line, int*
return false;
}
- if (mob_chat_db[msg_id] == NULL)
- mob_chat_db[msg_id] = (struct mob_chat*)aCalloc(1, sizeof (struct mob_chat));
+ if (mob->chat_db[msg_id] == NULL)
+ mob->chat_db[msg_id] = (struct mob_chat*)aCalloc(1, sizeof (struct mob_chat));
- ms = mob_chat_db[msg_id];
+ ms = mob->chat_db[msg_id];
//MSG ID
ms->msg_id=msg_id;
//Color
@@ -4151,7 +4139,7 @@ static bool mob_parse_row_chatdb(char** str, const char* source, int line, int*
/*==========================================
* mob_chat_db.txt reading [SnakeDrak]
*-------------------------------------------------------------------------*/
-static void mob_readchatdb(void)
+void mob_readchatdb(void)
{
char arc[]="mob_chat_db.txt";
uint32 lines=0, count=0;
@@ -4195,7 +4183,7 @@ static void mob_readchatdb(void)
continue;
}
- if( !mob_parse_row_chatdb(str, path, lines, &tmp) )
+ if( !mob->parse_row_chatdb(str, path, lines, &tmp) )
continue;
count++;
@@ -4207,7 +4195,7 @@ static void mob_readchatdb(void)
/*==========================================
* processes one mob_skill_db entry
*------------------------------------------*/
-static bool mob_parse_row_mobskilldb(char** str, int columns, int current)
+bool mob_parse_row_mobskilldb(char** str, int columns, int current)
{
static const struct {
char str[32];
@@ -4289,7 +4277,7 @@ static bool mob_parse_row_mobskilldb(char** str, int columns, int current)
mob_id = atoi(str[0]);
- if (mob_id > 0 && mob_db(mob_id) == mob_dummy)
+ if (mob_id > 0 && mob->db(mob_id) == mob->dummy)
{
if (mob_id != last_mob_id) {
ShowError("mob_parse_row_mobskilldb: Non existant Mob id %d\n", mob_id);
@@ -4300,8 +4288,8 @@ static bool mob_parse_row_mobskilldb(char** str, int columns, int current)
if( strcmp(str[1],"clear")==0 ){
if (mob_id < 0)
return false;
- memset(mob_db_data[mob_id]->skill,0,sizeof(struct mob_skill));
- mob_db_data[mob_id]->maxskill=0;
+ memset(mob->db_data[mob_id]->skill,0,sizeof(struct mob_skill));
+ mob->db_data[mob_id]->maxskill=0;
return true;
}
@@ -4310,11 +4298,11 @@ static bool mob_parse_row_mobskilldb(char** str, int columns, int current)
memset(&gms, 0, sizeof (struct mob_skill));
ms = &gms;
} else {
- ARR_FIND( 0, MAX_MOBSKILL, i, (ms = &mob_db_data[mob_id]->skill[i])->skill_id == 0 );
+ ARR_FIND( 0, MAX_MOBSKILL, i, (ms = &mob->db_data[mob_id]->skill[i])->skill_id == 0 );
if( i == MAX_MOBSKILL )
{
if (mob_id != last_mob_id) {
- ShowError("mob_parse_row_mobskilldb: Too many skills for monster %d[%s]\n", mob_id, mob_db_data[mob_id]->sprite);
+ ShowError("mob_parse_row_mobskilldb: Too many skills for monster %d[%s]\n", mob_id, mob->db_data[mob_id]->sprite);
last_mob_id = mob_id;
}
return false;
@@ -4336,7 +4324,7 @@ static bool mob_parse_row_mobskilldb(char** str, int columns, int current)
if (mob_id < 0)
ShowError("mob_parse_row_mobskilldb: Invalid Skill ID (%d) for all mobs\n", j);
else
- ShowError("mob_parse_row_mobskilldb: Invalid Skill ID (%d) for mob %d (%s)\n", j, mob_id, mob_db_data[mob_id]->sprite);
+ ShowError("mob_parse_row_mobskilldb: Invalid Skill ID (%d) for mob %d (%s)\n", j, mob_id, mob->db_data[mob_id]->sprite);
return false;
}
ms->skill_id=j;
@@ -4378,13 +4366,13 @@ static bool mob_parse_row_mobskilldb(char** str, int columns, int current)
if (ms->target > MST_AROUND) {
ShowWarning("mob_parse_row_mobskilldb: Wrong mob skill target for ground skill %d (%s) for %s.\n",
ms->skill_id, skill_db[sidx].name,
- mob_id < 0?"all mobs":mob_db_data[mob_id]->sprite);
+ mob_id < 0?"all mobs":mob->db_data[mob_id]->sprite);
ms->target = MST_TARGET;
}
} else if (ms->target > MST_MASTER) {
ShowWarning("mob_parse_row_mobskilldb: Wrong mob skill target 'around' for non-ground skill %d (%s) for %s.\n",
ms->skill_id, skill_db[sidx].name,
- mob_id < 0?"all mobs":mob_db_data[mob_id]->sprite);
+ mob_id < 0?"all mobs":mob->db_data[mob_id]->sprite);
ms->target = MST_TARGET;
}
@@ -4412,7 +4400,7 @@ static bool mob_parse_row_mobskilldb(char** str, int columns, int current)
ms->val[4]=(int)strtol(str[16],NULL,0);
if(ms->skill_id == NPC_EMOTION && mob_id>0 &&
- ms->val[1] == mob_db(mob_id)->status.mode)
+ ms->val[1] == mob->db(mob_id)->status.mode)
{
ms->val[1] = 0;
ms->val[4] = 1; //request to return mode to normal.
@@ -4431,7 +4419,7 @@ static bool mob_parse_row_mobskilldb(char** str, int columns, int current)
else
ms->emotion=-1;
- if(str[18]!=NULL && mob_chat_db[atoi(str[18])]!=NULL)
+ if(str[18]!=NULL && mob->chat_db[atoi(str[18])]!=NULL)
ms->msg_id=atoi(str[18]);
else
ms->msg_id=0;
@@ -4441,9 +4429,9 @@ static bool mob_parse_row_mobskilldb(char** str, int columns, int current)
mob_id *= -1;
for (i = 1; i < MAX_MOB_DB; i++)
{
- if (mob_db_data[i] == NULL)
+ if (mob->db_data[i] == NULL)
continue;
- if (mob_db_data[i]->status.mode&MD_BOSS)
+ if (mob->db_data[i]->status.mode&MD_BOSS)
{
if (!(mob_id&2)) //Skill not for bosses
continue;
@@ -4451,15 +4439,15 @@ static bool mob_parse_row_mobskilldb(char** str, int columns, int current)
if (!(mob_id&1)) //Skill not for normal enemies.
continue;
- ARR_FIND( 0, MAX_MOBSKILL, j, mob_db_data[i]->skill[j].skill_id == 0 );
+ ARR_FIND( 0, MAX_MOBSKILL, j, mob->db_data[i]->skill[j].skill_id == 0 );
if(j==MAX_MOBSKILL)
continue;
- memcpy (&mob_db_data[i]->skill[j], ms, sizeof(struct mob_skill));
- mob_db_data[i]->maxskill=j+1;
+ memcpy (&mob->db_data[i]->skill[j], ms, sizeof(struct mob_skill));
+ mob->db_data[i]->maxskill=j+1;
}
} else //Skill set on a single mob.
- mob_db_data[mob_id]->maxskill=i+1;
+ mob->db_data[mob_id]->maxskill=i+1;
return true;
}
@@ -4467,7 +4455,7 @@ static bool mob_parse_row_mobskilldb(char** str, int columns, int current)
/*==========================================
* mob_skill_db.txt reading
*------------------------------------------*/
-static void mob_readskilldb(void) {
+void mob_readskilldb(void) {
const char* filename[] = {
DBPATH"mob_skill_db.txt",
"mob_skill_db2.txt" };
@@ -4491,7 +4479,7 @@ static void mob_readskilldb(void) {
}
}
- sv->readdb(iMap->db_path, filename[fi], ',', 19, 19, -1, &mob_parse_row_mobskilldb);
+ sv->readdb(iMap->db_path, filename[fi], ',', 19, 19, -1, mob->parse_row_mobskilldb);
}
}
@@ -4500,7 +4488,7 @@ static void mob_readskilldb(void) {
* not overly sure if this is all correct
* seems to work though...
*/
-static int mob_read_sqlskilldb(void)
+int mob_read_sqlskilldb(void)
{
const char* mob_skill_db_name[] = { iMap->mob_skill_db_db, iMap->mob_skill_db2_db };
int fi;
@@ -4533,7 +4521,7 @@ static int mob_read_sqlskilldb(void)
if( str[i] == NULL ) str[i] = dummy; // get rid of NULL columns
}
- if (!mob_parse_row_mobskilldb(str, 19, count))
+ if (!mob->parse_row_mobskilldb(str, 19, count))
continue;
count++;
@@ -4550,7 +4538,7 @@ static int mob_read_sqlskilldb(void)
/*==========================================
* mob_race2_db.txt reading
*------------------------------------------*/
-static bool mob_readdb_race2(char* fields[], int columns, int current)
+bool mob_readdb_race2(char* fields[], int columns, int current)
{
int race, mobid, i;
@@ -4565,12 +4553,12 @@ static bool mob_readdb_race2(char* fields[], int columns, int current)
for(i = 1; i<columns; i++)
{
mobid = atoi(fields[i]);
- if (mob_db(mobid) == mob_dummy)
+ if (mob->db(mobid) == mob->dummy)
{
ShowWarning("mob_readdb_race2: Unknown mob id %d for race2 %d.\n", mobid, race);
continue;
}
- mob_db_data[mobid]->race2 = race;
+ mob->db_data[mobid]->race2 = race;
}
return true;
}
@@ -4578,7 +4566,7 @@ static bool mob_readdb_race2(char* fields[], int columns, int current)
/**
* Read mob_item_ratio.txt
*/
-static bool mob_readdb_itemratio(char* str[], int columns, int current)
+bool mob_readdb_itemratio(char* str[], int columns, int current)
{
int nameid, ratio, i;
nameid = atoi(str[0]);
@@ -4604,26 +4592,25 @@ static bool mob_readdb_itemratio(char* str[], int columns, int current)
/**
* read all mob-related databases
*/
-static void mob_load(void)
-{
- sv->readdb(iMap->db_path, "mob_item_ratio.txt", ',', 2, 2+MAX_ITEMRATIO_MOBS, -1, &mob_readdb_itemratio); // must be read before mobdb
- mob_readchatdb();
+void mob_load(void) {
+ sv->readdb(iMap->db_path, "mob_item_ratio.txt", ',', 2, 2+MAX_ITEMRATIO_MOBS, -1, mob->readdb_itemratio); // must be read before mobdb
+ mob->readchatdb();
if (iMap->db_use_sql_mob_db)
{
- mob_read_sqldb();
+ mob->read_sqldb();
}
if (iMap->db_use_sql_mob_skill_db)
{
- mob_read_sqlskilldb();
+ mob->read_sqlskilldb();
}
else
{
- mob_readdb();
- mob_readskilldb();
+ mob->readdb();
+ mob->readskilldb();
}
- sv->readdb(iMap->db_path, "mob_avail.txt", ',', 2, 12, -1, &mob_readdb_mobavail);
- mob_read_randommonster();
- sv->readdb(iMap->db_path, DBPATH"mob_race2_db.txt", ',', 2, 20, -1, &mob_readdb_race2);
+ sv->readdb(iMap->db_path, "mob_avail.txt", ',', 2, 12, -1, mob->readdb_mobavail);
+ mob->read_randommonster();
+ sv->readdb(iMap->db_path, DBPATH"mob_race2_db.txt", ',', 2, 20, -1, mob->readdb_race2);
}
void mob_reload(void) {
@@ -4631,9 +4618,9 @@ void mob_reload(void) {
//Mob skills need to be cleared before re-reading them. [Skotlex]
for (i = 0; i < MAX_MOB_DB; i++)
- if (mob_db_data[i] && !mob_is_clone(i)) {
- memset(&mob_db_data[i]->skill,0,sizeof(mob_db_data[i]->skill));
- mob_db_data[i]->maxskill=0;
+ if (mob->db_data[i] && !mob->is_clone(i)) {
+ memset(&mob->db_data[i]->skill,0,sizeof(mob->db_data[i]->skill));
+ mob->db_data[i]->maxskill=0;
}
// Clear item_drop_ratio_db
@@ -4644,15 +4631,15 @@ void mob_reload(void) {
}
}
- mob_load();
+ mob->load();
}
void mob_clear_spawninfo()
{ //Clears spawn related information for a script reload.
int i;
for (i = 0; i < MAX_MOB_DB; i++)
- if (mob_db_data[i])
- memset(&mob_db_data[i]->spawn,0,sizeof(mob_db_data[i]->spawn));
+ if (mob->db_data[i])
+ memset(&mob->db_data[i]->spawn,0,sizeof(mob->db_data[i]->spawn));
}
/*==========================================
@@ -4660,23 +4647,23 @@ void mob_clear_spawninfo()
*------------------------------------------*/
int do_init_mob(void)
{ //Initialize the mob database
- memset(mob_db_data,0,sizeof(mob_db_data)); //Clear the array
- mob_db_data[0] = (struct mob_db*)aCalloc(1, sizeof (struct mob_db)); //This mob is used for random spawns
- mob_makedummymobdb(0); //The first time this is invoked, it creates the dummy mob
+ memset(mob->db_data,0,sizeof(mob->db_data)); //Clear the array
+ mob->db_data[0] = (struct mob_db*)aCalloc(1, sizeof (struct mob_db)); //This mob is used for random spawns
+ mob->makedummymobdb(0); //The first time this is invoked, it creates the dummy mob
item_drop_ers = ers_new(sizeof(struct item_drop),"mob.c::item_drop_ers",ERS_OPT_NONE);
item_drop_list_ers = ers_new(sizeof(struct item_drop_list),"mob.c::item_drop_list_ers",ERS_OPT_NONE);
- mob_load();
+ mob->load();
- iTimer->add_timer_func_list(mob_delayspawn,"mob_delayspawn");
- iTimer->add_timer_func_list(mob_delay_item_drop,"mob_delay_item_drop");
- iTimer->add_timer_func_list(mob_ai_hard,"mob_ai_hard");
- iTimer->add_timer_func_list(mob_ai_lazy,"mob_ai_lazy");
- iTimer->add_timer_func_list(mob_timer_delete,"mob_timer_delete");
- iTimer->add_timer_func_list(mob_spawn_guardian_sub,"mob_spawn_guardian_sub");
- iTimer->add_timer_func_list(mob_respawn,"mob_respawn");
- iTimer->add_timer_interval(iTimer->gettick()+MIN_MOBTHINKTIME,mob_ai_hard,0,0,MIN_MOBTHINKTIME);
- iTimer->add_timer_interval(iTimer->gettick()+MIN_MOBTHINKTIME*10,mob_ai_lazy,0,0,MIN_MOBTHINKTIME*10);
+ iTimer->add_timer_func_list(mob->delayspawn,"mob_delayspawn");
+ iTimer->add_timer_func_list(mob->delay_item_drop,"mob_delay_item_drop");
+ iTimer->add_timer_func_list(mob->ai_hard,"mob_ai_hard");
+ iTimer->add_timer_func_list(mob->ai_lazy,"mob_ai_lazy");
+ iTimer->add_timer_func_list(mob->timer_delete,"mob_timer_delete");
+ iTimer->add_timer_func_list(mob->spawn_guardian_sub,"mob_spawn_guardian_sub");
+ iTimer->add_timer_func_list(mob->respawn,"mob_respawn");
+ iTimer->add_timer_interval(iTimer->gettick()+MIN_MOBTHINKTIME,mob->ai_hard,0,0,MIN_MOBTHINKTIME);
+ iTimer->add_timer_interval(iTimer->gettick()+MIN_MOBTHINKTIME*10,mob->ai_lazy,0,0,MIN_MOBTHINKTIME*10);
return 0;
}
@@ -4687,25 +4674,25 @@ int do_init_mob(void)
int do_final_mob(void)
{
int i;
- if (mob_dummy)
+ if (mob->dummy)
{
- aFree(mob_dummy);
- mob_dummy = NULL;
+ aFree(mob->dummy);
+ mob->dummy = NULL;
}
for (i = 0; i <= MAX_MOB_DB; i++)
{
- if (mob_db_data[i] != NULL)
+ if (mob->db_data[i] != NULL)
{
- aFree(mob_db_data[i]);
- mob_db_data[i] = NULL;
+ aFree(mob->db_data[i]);
+ mob->db_data[i] = NULL;
}
}
for (i = 0; i <= MAX_MOB_CHAT; i++)
{
- if (mob_chat_db[i] != NULL)
+ if (mob->chat_db[i] != NULL)
{
- aFree(mob_chat_db[i]);
- mob_chat_db[i] = NULL;
+ aFree(mob->chat_db[i]);
+ mob->chat_db[i] = NULL;
}
}
for (i = 0; i < MAX_ITEMDB; i++)
@@ -4720,3 +4707,115 @@ int do_final_mob(void)
ers_destroy(item_drop_list_ers);
return 0;
}
+
+void mob_defaults(void) {
+ //Defines the Manuk/Splendide mob groups for the status reductions [Epoque]
+ const int mob_manuk[8] = { 1986, 1987, 1988, 1989, 1990, 1997, 1998, 1999 };
+ const int mob_splendide[5] = { 1991, 1992, 1993, 1994, 1995 };
+
+ mob = &mob_s;
+
+ memset(mob->db_data, 0, sizeof(mob->db_data));
+ mob->dummy = NULL;
+ memset(mob->chat_db, 0, sizeof(mob->chat_db));
+
+ memcpy(mob->manuk, mob_manuk, sizeof(mob->manuk));
+ memcpy(mob->splendide, mob_splendide, sizeof(mob->splendide));
+ /* */
+ mob->reload = mob_reload;
+ mob->init = do_init_mob;
+ mob->final = do_final_mob;
+ /* */
+ mob->db = mob_db;
+ mob->chat = mob_chat;
+ mob->makedummymobdb = mob_makedummymobdb;
+ mob->spawn_guardian_sub = mob_spawn_guardian_sub;
+ mob->skill_id2skill_idx = mob_skill_id2skill_idx;
+ mob->db_searchname = mobdb_searchname;
+ mob->db_searchname_array_sub = mobdb_searchname_array_sub;
+ mob->mvptomb_create = mvptomb_create;
+ mob->mvptomb_destroy = mvptomb_destroy;
+ mob->db_searchname_array = mobdb_searchname_array;
+ mob->db_checkid = mobdb_checkid;
+ mob->get_viewdata = mob_get_viewdata;
+ mob->parse_dataset = mob_parse_dataset;
+ mob->spawn_dataset = mob_spawn_dataset;
+ mob->get_random_id = mob_get_random_id;
+ mob->ksprotected = mob_ksprotected;
+ mob->once_spawn_sub = mob_once_spawn_sub;
+ mob->once_spawn = mob_once_spawn;
+ mob->once_spawn_area = mob_once_spawn_area;
+ mob->spawn_guardian = mob_spawn_guardian;
+ mob->spawn_bg = mob_spawn_bg;
+ mob->can_reach = mob_can_reach;
+ mob->linksearch = mob_linksearch;
+ mob->delayspawn = mob_delayspawn;
+ mob->setdelayspawn = mob_setdelayspawn;
+ mob->count_sub = mob_count_sub;
+ mob->spawn = mob_spawn;
+ mob->can_changetarget = mob_can_changetarget;
+ mob->target = mob_target;
+ mob->ai_sub_hard_activesearch = mob_ai_sub_hard_activesearch;
+ mob->ai_sub_hard_changechase = mob_ai_sub_hard_changechase;
+ mob->ai_sub_hard_bg_ally = mob_ai_sub_hard_bg_ally;
+ mob->ai_sub_hard_lootsearch = mob_ai_sub_hard_lootsearch;
+ mob->warpchase_sub = mob_warpchase_sub;
+ mob->ai_sub_hard_slavemob = mob_ai_sub_hard_slavemob;
+ mob->unlocktarget = mob_unlocktarget;
+ mob->randomwalk = mob_randomwalk;
+ mob->warpchase = mob_warpchase;
+ mob->ai_sub_hard = mob_ai_sub_hard;
+ mob->ai_sub_hard_timer = mob_ai_sub_hard_timer;
+ mob->ai_sub_foreachclient = mob_ai_sub_foreachclient;
+ mob->ai_sub_lazy = mob_ai_sub_lazy;
+ mob->ai_lazy = mob_ai_lazy;
+ mob->ai_hard = mob_ai_hard;
+ mob->setdropitem = mob_setdropitem;
+ mob->setlootitem = mob_setlootitem;
+ mob->delay_item_drop = mob_delay_item_drop;
+ mob->item_drop = mob_item_drop;
+ mob->timer_delete = mob_timer_delete;
+ mob->deleteslave_sub = mob_deleteslave_sub;
+ mob->deleteslave = mob_deleteslave;
+ mob->respawn = mob_respawn;
+ mob->log_damage = mob_log_damage;
+ mob->damage = mob_damage;
+ mob->dead = mob_dead;
+ mob->revive = mob_revive;
+ mob->guardian_guildchange = mob_guardian_guildchange;
+ mob->random_class = mob_random_class;
+ mob->class_change = mob_class_change;
+ mob->heal = mob_heal;
+ mob->warpslave_sub = mob_warpslave_sub;
+ mob->warpslave = mob_warpslave;
+ mob->countslave_sub = mob_countslave_sub;
+ mob->countslave = mob_countslave;
+ mob->summonslave = mob_summonslave;
+ mob->getfriendhprate_sub = mob_getfriendhprate_sub;
+ mob->getfriendhprate = mob_getfriendhprate;
+ mob->getmasterhpltmaxrate = mob_getmasterhpltmaxrate;
+ mob->getfriendstatus_sub = mob_getfriendstatus_sub;
+ mob->getfriendstatus = mob_getfriendstatus;
+ mob->skill_use = mobskill_use;
+ mob->skill_event = mobskill_event;
+ mob->is_clone = mob_is_clone;
+ mob->clone_spawn = mob_clone_spawn;
+ mob->clone_delete = mob_clone_delete;
+ mob->drop_adjust = mob_drop_adjust;
+ mob->item_dropratio_adjust = item_dropratio_adjust;
+ mob->parse_dbrow = mob_parse_dbrow;
+ mob->readdb_sub = mob_readdb_sub;
+ mob->readdb = mob_readdb;
+ mob->read_sqldb = mob_read_sqldb;
+ mob->readdb_mobavail = mob_readdb_mobavail;
+ mob->read_randommonster = mob_read_randommonster;
+ mob->parse_row_chatdb = mob_parse_row_chatdb;
+ mob->readchatdb = mob_readchatdb;
+ mob->parse_row_mobskilldb = mob_parse_row_mobskilldb;
+ mob->readskilldb = mob_readskilldb;
+ mob->read_sqlskilldb = mob_read_sqlskilldb;
+ mob->readdb_race2 = mob_readdb_race2;
+ mob->readdb_itemratio = mob_readdb_itemratio;
+ mob->load = mob_load;
+ mob->clear_spawninfo = mob_clear_spawninfo;
+}
diff --git a/src/map/mob.h b/src/map/mob.h
index 137e33ee7..4ac8f7bcb 100644
--- a/src/map/mob.h
+++ b/src/map/mob.h
@@ -1,5 +1,6 @@
-// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
-// For more information, see LICENCE in the main folder
+// Copyright (c) Hercules Dev Team, licensed under GNU GPL.
+// See the LICENSE file
+// Portions Copyright (c) Athena Dev Teams
#ifndef _MOB_H_
#define _MOB_H_
@@ -38,9 +39,7 @@
//Used to determine default enemy type of mobs (for use in eachinrange calls)
#define DEFAULT_ENEMY_TYPE(md) (md->special_state.ai?BL_CHAR:BL_MOB|BL_PC|BL_HOM|BL_MER)
-//Externals for the status effects. [Epoque]
-extern const int mob_manuk[8];
-extern const int mob_splendide[5];
+#define MAX_MOB_CHAT 250 //Max Skill's messages
//Mob skill states.
enum MobSkillState {
@@ -243,78 +242,124 @@ struct item_drop_list {
struct item_drop* item; // linked list of drops
};
-struct mob_db* mob_db(int class_);
-int mobdb_searchname(const char *str);
-int mobdb_searchname_array(struct mob_db** data, int size, const char *str, int flag);
-int mobdb_checkid(const int id);
-struct view_data* mob_get_viewdata(int class_);
-
-struct mob_data *mob_once_spawn_sub(struct block_list *bl, int16 m,
- short x, short y, const char *mobname, int class_, const char *event, unsigned int size, unsigned int ai);
-
-int mob_once_spawn(struct map_session_data* sd, int16 m, int16 x, int16 y,
- const char* mobname, int class_, int amount, const char* event, unsigned int size, unsigned int ai);
-
-int mob_once_spawn_area(struct map_session_data* sd, int16 m,
- int16 x0, int16 y0, int16 x1, int16 y1, const char* mobname, int class_, int amount, const char* event, unsigned int size, unsigned int ai);
-
-bool mob_ksprotected (struct block_list *src, struct block_list *target);
-
-int mob_spawn_guardian(const char* mapname, int16 x, int16 y, const char* mobname, int class_, const char* event, int guardian, bool has_index); // Spawning Guardians [Valaris]
-int mob_spawn_bg(const char* mapname, int16 x, int16 y, const char* mobname, int class_, const char* event, unsigned int bg_id);
-int mob_guardian_guildchange(struct mob_data *md); //Change Guardian's ownership. [Skotlex]
-
-int mob_randomwalk(struct mob_data *md,unsigned int tick);
-int mob_warpchase(struct mob_data *md, struct block_list *target);
-int mob_target(struct mob_data *md,struct block_list *bl,int dist);
-int mob_unlocktarget(struct mob_data *md, unsigned int tick);
-struct mob_data* mob_spawn_dataset(struct spawn_data *data);
-int mob_spawn(struct mob_data *md);
-int mob_delayspawn(int tid, unsigned int tick, int id, intptr_t data);
-int mob_setdelayspawn(struct mob_data *md);
-int mob_parse_dataset(struct spawn_data *data);
-void mob_log_damage(struct mob_data *md, struct block_list *src, int damage);
-void mob_damage(struct mob_data *md, struct block_list *src, int damage);
-int mob_dead(struct mob_data *md, struct block_list *src, int type);
-void mob_revive(struct mob_data *md, unsigned int hp);
-void mob_heal(struct mob_data *md,unsigned int heal);
-
-#define mob_stop_walking(md, type) unit_stop_walking(&(md)->bl, type)
-#define mob_stop_attack(md) unit_stop_attack(&(md)->bl)
+
+#define mob_stop_walking(md, type) unit->stop_walking(&(md)->bl, type)
+#define mob_stop_attack(md) unit->stop_attack(&(md)->bl)
#define mob_is_battleground(md) ( map[(md)->bl.m].flag.battleground && ((md)->class_ == MOBID_BARRICADE2 || ((md)->class_ >= MOBID_FOOD_STOR && (md)->class_ <= MOBID_PINK_CRYST)) )
#define mob_is_gvg(md) (map[(md)->bl.m].flag.gvg_castle && ( (md)->class_ == MOBID_EMPERIUM || (md)->class_ == MOBID_BARRICADE1 || (md)->class_ == MOBID_GUARIDAN_STONE1 || (md)->class_ == MOBID_GUARIDAN_STONE2) )
#define mob_is_treasure(md) (((md)->class_ >= MOBID_TREAS01 && (md)->class_ <= MOBID_TREAS40) || ((md)->class_ >= MOBID_TREAS41 && (md)->class_ <= MOBID_TREAS49))
-void mob_clear_spawninfo();
-int do_init_mob(void);
-int do_final_mob(void);
-
-int mob_timer_delete(int tid, unsigned int tick, int id, intptr_t data);
-int mob_deleteslave(struct mob_data *md);
-
-int mob_random_class (int *value, size_t count);
-int mob_get_random_id(int type, int flag, int lv);
-int mob_class_change(struct mob_data *md,int class_);
-int mob_warpslave(struct block_list *bl, int range);
-int mob_linksearch(struct block_list *bl,va_list ap);
-
-int mobskill_use(struct mob_data *md,unsigned int tick,int event);
-int mobskill_event(struct mob_data *md,struct block_list *src,unsigned int tick, int flag);
-int mobskill_castend_id( int tid, unsigned int tick, int id,int data );
-int mobskill_castend_pos( int tid, unsigned int tick, int id,int data );
-int mob_summonslave(struct mob_data *md2,int *value,int amount,uint16 skill_id);
-int mob_countslave(struct block_list *bl);
-int mob_count_sub(struct block_list *bl, va_list ap);
-
-int mob_is_clone(int class_);
-
-int mob_clone_spawn(struct map_session_data *sd, int16 m, int16 x, int16 y, const char *event, int master_id, int mode, int flag, unsigned int duration);
-int mob_clone_delete(struct mob_data *md);
+struct mob_interface {
+ //Dynamic mob database, allows saving of memory when there's big gaps in the mob_db [Skotlex]
+ struct mob_db *db_data[MAX_MOB_DB+1];
+ struct mob_db *dummy; //Dummy mob to be returned when a non-existant one is requested.
+ //Dynamic mob chat database
+ struct mob_chat *chat_db[MAX_MOB_CHAT+1];
+ //Defines the Manuk/Splendide mob groups for the status reductions [Epoque]
+ int manuk[8];
+ int splendide[5];
+ /* */
+ int (*init) (void);
+ int (*final) (void);
+ void (*reload) (void);
+ /* */
+ struct mob_db* (*db) (int index);
+ struct mob_chat* (*chat) (short id);
+ int (*makedummymobdb) (int);
+ int (*spawn_guardian_sub) (int tid, unsigned int tick, int id, intptr_t data);
+ int (*skill_id2skill_idx) (int class_, uint16 skill_id);
+ int (*db_searchname) (const char *str);
+ int (*db_searchname_array_sub) (struct mob_db *mob, const char *str, int flag);
+ // MvP Tomb System
+ void (*mvptomb_create) (struct mob_data *md, char *killer, time_t time);
+ void (*mvptomb_destroy) (struct mob_data *md);
+ int (*db_searchname_array) (struct mob_db **data, int size, const char *str, int flag);
+ int (*db_checkid) (const int id);
+ struct view_data* (*get_viewdata) (int class_);
+ int (*parse_dataset) (struct spawn_data *data);
+ struct mob_data* (*spawn_dataset) (struct spawn_data *data);
+ int (*get_random_id) (int type, int flag, int lv);
+ bool (*ksprotected) (struct block_list *src, struct block_list *target);
+ struct mob_data* (*once_spawn_sub) (struct block_list *bl, int16 m, int16 x, int16 y, const char *mobname, int class_, const char *event, unsigned int size, unsigned int ai);
+ int (*once_spawn) (struct map_session_data *sd, int16 m, int16 x, int16 y, const char *mobname, int class_, int amount, const char *event, unsigned int size, unsigned int ai);
+ int (*once_spawn_area) (struct map_session_data *sd, int16 m, int16 x0, int16 y0, int16 x1, int16 y1, const char *mobname, int class_, int amount, const char *event, unsigned int size, unsigned int ai);
+ int (*spawn_guardian) (const char *mapname, short x, short y, const char *mobname, int class_, const char *event, int guardian, bool has_index);
+ int (*spawn_bg) (const char *mapname, short x, short y, const char *mobname, int class_, const char *event, unsigned int bg_id);
+ int (*can_reach) (struct mob_data *md, struct block_list *bl, int range, int state);
+ int (*linksearch) (struct block_list *bl, va_list ap);
+ int (*delayspawn) (int tid, unsigned int tick, int id, intptr_t data);
+ int (*setdelayspawn) (struct mob_data *md);
+ int (*count_sub) (struct block_list *bl, va_list ap);
+ int (*spawn) (struct mob_data *md);
+ int (*can_changetarget) (struct mob_data *md, struct block_list *target, int mode);
+ int (*target) (struct mob_data *md, struct block_list *bl, int dist);
+ int (*ai_sub_hard_activesearch) (struct block_list *bl, va_list ap);
+ int (*ai_sub_hard_changechase) (struct block_list *bl, va_list ap);
+ int (*ai_sub_hard_bg_ally) (struct block_list *bl, va_list ap);
+ int (*ai_sub_hard_lootsearch) (struct block_list *bl, va_list ap);
+ int (*warpchase_sub) (struct block_list *bl, va_list ap);
+ int (*ai_sub_hard_slavemob) (struct mob_data *md, unsigned int tick);
+ int (*unlocktarget) (struct mob_data *md, unsigned int tick);
+ int (*randomwalk) (struct mob_data *md, unsigned int tick);
+ int (*warpchase) (struct mob_data *md, struct block_list *target);
+ bool (*ai_sub_hard) (struct mob_data *md, unsigned int tick);
+ int (*ai_sub_hard_timer) (struct block_list *bl, va_list ap);
+ int (*ai_sub_foreachclient) (struct map_session_data *sd, va_list ap);
+ int (*ai_sub_lazy) (struct mob_data *md, va_list args);
+ int (*ai_lazy) (int tid, unsigned int tick, int id, intptr_t data);
+ int (*ai_hard) (int tid, unsigned int tick, int id, intptr_t data);
+ struct item_drop* (*setdropitem) (int nameid, int qty, struct item_data *data);
+ struct item_drop* (*setlootitem) (struct item *item);
+ int (*delay_item_drop) (int tid, unsigned int tick, int id, intptr_t data);
+ void (*item_drop) (struct mob_data *md, struct item_drop_list *dlist, struct item_drop *ditem, int loot, int drop_rate, unsigned short flag);
+ int (*timer_delete) (int tid, unsigned int tick, int id, intptr_t data);
+ int (*deleteslave_sub) (struct block_list *bl, va_list ap);
+ int (*deleteslave) (struct mob_data *md);
+ int (*respawn) (int tid, unsigned int tick, int id, intptr_t data);
+ void (*log_damage) (struct mob_data *md, struct block_list *src, int damage);
+ void (*damage) (struct mob_data *md, struct block_list *src, int damage);
+ int (*dead) (struct mob_data *md, struct block_list *src, int type);
+ void (*revive) (struct mob_data *md, unsigned int hp);
+ int (*guardian_guildchange) (struct mob_data *md);
+ int (*random_class) (int *value, size_t count);
+ int (*class_change) (struct mob_data *md, int class_);
+ void (*heal) (struct mob_data *md, unsigned int heal);
+ int (*warpslave_sub) (struct block_list *bl, va_list ap);
+ int (*warpslave) (struct block_list *bl, int range);
+ int (*countslave_sub) (struct block_list *bl, va_list ap);
+ int (*countslave) (struct block_list *bl);
+ int (*summonslave) (struct mob_data *md2, int *value, int amount, uint16 skill_id);
+ int (*getfriendhprate_sub) (struct block_list *bl, va_list ap);
+ struct block_list* (*getfriendhprate) (struct mob_data *md, int min_rate, int max_rate);
+ struct block_list* (*getmasterhpltmaxrate) (struct mob_data *md, int rate);
+ int (*getfriendstatus_sub) (struct block_list *bl, va_list ap);
+ struct mob_data* (*getfriendstatus) (struct mob_data *md, int cond1, int cond2);
+ int (*skill_use) (struct mob_data *md, unsigned int tick, int event);
+ int (*skill_event) (struct mob_data *md, struct block_list *src, unsigned int tick, int flag);
+ int (*is_clone) (int class_);
+ int (*clone_spawn) (struct map_session_data *sd, int16 m, int16 x, int16 y, const char *event, int master_id, int mode, int flag, unsigned int duration);
+ int (*clone_delete) (struct mob_data *md);
+ unsigned int (*drop_adjust) (int baserate, int rate_adjust, unsigned short rate_min, unsigned short rate_max);
+ void (*item_dropratio_adjust) (int nameid, int mob_id, int *rate_adjust);
+ bool (*parse_dbrow) (char **str);
+ bool (*readdb_sub) (char *fields[], int columns, int current);
+ void (*readdb) (void);
+ int (*read_sqldb) (void);
+ bool (*readdb_mobavail) (char *str[], int columns, int current);
+ int (*read_randommonster) (void);
+ bool (*parse_row_chatdb) (char **str, const char *source, int line, int *last_msg_id);
+ void (*readchatdb) (void);
+ bool (*parse_row_mobskilldb) (char **str, int columns, int current);
+ void (*readskilldb) (void);
+ int (*read_sqlskilldb) (void);
+ bool (*readdb_race2) (char *fields[], int columns, int current);
+ bool (*readdb_itemratio) (char *str[], int columns, int current);
+ void (*load) (void);
+ void (*clear_spawninfo) ();
+};
-void mob_reload(void);
+struct mob_interface *mob;
-// MvP Tomb System
-void mvptomb_create(struct mob_data *md, char *killer, time_t time);
-void mvptomb_destroy(struct mob_data *md);
+void mob_defaults(void);
#endif /* _MOB_H_ */
diff --git a/src/map/npc.c b/src/map/npc.c
index 8a2c0f746..51d01d711 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,16 +943,16 @@ 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);
+ struct unit_data *ud = unit->bl2ud(&sd->bl);
if( ud && ud->walkpath.path_pos < ud->walkpath.path_len )
{ // Since walktimer always == INVALID_TIMER at this time, we stop walking manually. [Inkfish]
clif->fixpos(&sd->bl);
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;
}
@@ -1021,14 +995,14 @@ int npc_touch_areanpc2(struct mob_data *md)
xs = iMap->mapindex2mapid(map[m].npc[i]->u.warp.mapindex);
if( m < 0 )
break; // Cannot Warp between map servers
- if( unit_warp(&md->bl, xs, map[m].npc[i]->u.warp.x, map[m].npc[i]->u.warp.y, CLR_OUTSIGHT) == 0 )
+ if( unit->warp(&md->bl, xs, map[m].npc[i]->u.warp.x, map[m].npc[i]->u.warp.y, CLR_OUTSIGHT) == 0 )
return 1; // Warped
break;
case SCRIPT:
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) {
@@ -1322,7 +1296,7 @@ int npc_cashshop_buylist(struct map_session_data *sd, int points, int count, uns
if( j == nd->u.shop.count || nd->u.shop.shop_item[j].value <= 0 )
return 5;
- if( !itemdb_isstackable(nameid) && amount > 1 )
+ if( !itemdb->isstackable(nameid) && amount > 1 )
{
ShowWarning("Player %s (%d:%d) sent a hexed packet trying to buy %d of nonstackable item %d!\n", sd->status.name, sd->status.account_id, sd->status.char_id, amount, nameid);
amount = item_list[i*2+0] = 1;
@@ -1362,7 +1336,7 @@ int npc_cashshop_buylist(struct map_session_data *sd, int points, int count, uns
memset(&item_tmp,0,sizeof(item_tmp));
- if( !pet_create_egg(sd,nameid) )
+ if( !pet->create_egg(sd,nameid) )
{
item_tmp.nameid = nameid;
item_tmp.identify = 1;
@@ -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;
}
@@ -1428,7 +1402,7 @@ int npc_cashshop_buy(struct map_session_data *sd, int nameid, int amount, int po
if( nd->u.shop.shop_item[i].value <= 0 )
return 5;
- if(!itemdb_isstackable(nameid) && amount > 1)
+ if(!itemdb->isstackable(nameid) && amount > 1)
{
ShowWarning("Player %s (%d:%d) sent a hexed packet trying to buy %d of nonstackable item %d!\n",
sd->status.name, sd->status.account_id, sd->status.char_id, amount, nameid);
@@ -1466,7 +1440,7 @@ int npc_cashshop_buy(struct map_session_data *sd, int nameid, int amount, int po
pc->paycash(sd, price, points);
- if( !pet_create_egg(sd, nameid) )
+ if( !pet->create_egg(sd, nameid) )
{
struct item item_tmp;
memset(&item_tmp, 0, sizeof(struct item));
@@ -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 )
@@ -1521,7 +1495,7 @@ int npc_buylist(struct map_session_data* sd, int n, unsigned short* item_list)
if( !itemdb->exists(nameid) )
return 3; // item no longer in itemdb
- if( !itemdb_isstackable(nameid) && amount > 1 ) {
+ if( !itemdb->isstackable(nameid) && amount > 1 ) {
//Exploit? You can't buy more than 1 of equipment types o.O
ShowWarning("Player %s (%d:%d) sent a hexed packet trying to buy %d of nonstackable item %d!\n",
sd->status.name, sd->status.account_id, sd->status.char_id, amount, nameid);
@@ -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
@@ -1569,7 +1543,7 @@ int npc_buylist(struct map_session_data* sd, int n, unsigned short* item_list)
struct item item_tmp;
if (itemdb_type(nameid) == IT_PETEGG)
- pet_create_egg(sd, nameid);
+ pet->create_egg(sd, nameid);
else {
memset(&item_tmp,0,sizeof(item_tmp));
item_tmp.nameid = nameid;
@@ -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];
@@ -1631,7 +1605,7 @@ static int npc_selllist_sub(struct map_session_data* sd, int n, unsigned short*
script->setarray_pc(sd, "@sold_nameid", i, (void*)(intptr_t)sd->status.inventory[idx].nameid, &key_nameid);
script->setarray_pc(sd, "@sold_quantity", i, (void*)(intptr_t)item_list[i*2+1], &key_amount);
- if( itemdb_isequip(sd->status.inventory[idx].nameid) )
+ if( itemdb->isequip(sd->status.inventory[idx].nameid) )
{// process equipment based information into the arrays
script->setarray_pc(sd, "@sold_refine", i, (void*)(intptr_t)sd->status.inventory[idx].refine, &key_refine);
script->setarray_pc(sd, "@sold_attribute", i, (void*)(intptr_t)sd->status.inventory[idx].attribute, &key_attribute);
@@ -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
@@ -1709,7 +1683,7 @@ int npc_selllist(struct map_session_data* sd, int n, unsigned short* item_list)
amount = item_list[i*2+1];
if( sd->inventory_data[idx]->type == IT_PETEGG && sd->status.inventory[idx].card[0] == CARD0_PET ) {
- if( search_petDB_index(sd->status.inventory[idx].nameid, PET_EGG) >= 0 ) {
+ if( pet->search_petDB_index(sd->status.inventory[idx].nameid, PET_EGG) >= 0 ) {
intif->delete_petdata(MakeDWord(sd->status.inventory[idx].card[1], sd->status.inventory[idx].card[2]));
}
}
@@ -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,26 +1785,26 @@ 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);
#ifdef PCRE_SUPPORT
- npc_chat_finalize(nd); // deallocate npc PCRE data structures
+ npc_chat->finalize(nd); // deallocate npc PCRE data structures
#endif
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
@@ -2938,36 +2912,36 @@ static const char* npc_parse_function(char* w1, char* w2, char* w3, char* w4, co
* Parse Mob 2 - Actually Spawns Mob
* [Wizputer]
*------------------------------------------*/
-void npc_parse_mob2(struct spawn_data* mob)
+void npc_parse_mob2(struct spawn_data* mobspawn)
{
int i;
- for( i = mob->active; i < mob->num; ++i ) {
- struct mob_data* md = mob_spawn_dataset(mob);
- md->spawn = mob;
+ for( i = mobspawn->active; i < mobspawn->num; ++i ) {
+ struct mob_data* md = mob->spawn_dataset(mobspawn);
+ md->spawn = mobspawn;
md->spawn->active++;
- mob_spawn(md);
+ mob->spawn(md);
}
}
-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;
char mapname[32], mobname[NAME_LENGTH];
- struct spawn_data mob, *data;
+ struct spawn_data mobspawn, *data;
struct mob_db* db;
- memset(&mob, 0, sizeof(struct spawn_data));
+ memset(&mobspawn, 0, sizeof(struct spawn_data));
- mob.state.boss = !strcmpi(w2,"boss_monster");
+ mobspawn.state.boss = !strcmpi(w2,"boss_monster");
// w1=<map name>,<x>,<y>,<xs>,<ys>
// w3=<mob name>{,<mob level>}
// w4=<mob id>,<amount>,<delay1>,<delay2>,<event>{,<mob size>,<mob ai>}
if( sscanf(w1, "%31[^,],%d,%d,%d,%d", mapname, &x, &y, &xs, &ys) < 3
|| sscanf(w3, "%23[^,],%d", mobname, &mob_lv) < 1
- || sscanf(w4, "%d,%d,%u,%u,%127[^,],%d,%d[^\t\r\n]", &class_, &num, &mob.delay1, &mob.delay2, mob.eventname, &size, &ai) < 2 )
+ || sscanf(w4, "%d,%d,%u,%u,%127[^,],%d,%d[^\t\r\n]", &class_, &num, &mobspawn.delay1, &mobspawn.delay2, mobspawn.eventname, &size, &ai) < 2 )
{
ShowError("npc_parse_mob: Invalid mob definition in file '%s', line '%d'.\n * w1=%s\n * w2=%s\n * w3=%s\n * w4=%s\n", filepath, strline(buffer,start-buffer), w1, w2, w3, w4);
return strchr(start,'\n');// skip and continue
@@ -2980,16 +2954,16 @@ static const char* npc_parse_mob(char* w1, char* w2, char* w3, char* w4, const c
m = iMap->mapname2mapid(mapname);
if( m < 0 )//Not loaded on this map-server instance.
return strchr(start,'\n');// skip and continue
- mob.m = (unsigned short)m;
+ mobspawn.m = (unsigned short)m;
- if( x < 0 || x >= map[mob.m].xs || y < 0 || y >= map[mob.m].ys )
+ if( x < 0 || x >= map[mobspawn.m].xs || y < 0 || y >= map[mobspawn.m].ys )
{
- ShowError("npc_parse_mob: Spawn coordinates out of range: %s (%d,%d), map size is (%d,%d) - %s %s (file '%s', line '%d').\n", map[mob.m].name, x, y, (map[mob.m].xs-1), (map[mob.m].ys-1), w1, w3, filepath, strline(buffer,start-buffer));
+ ShowError("npc_parse_mob: Spawn coordinates out of range: %s (%d,%d), map size is (%d,%d) - %s %s (file '%s', line '%d').\n", map[mobspawn.m].name, x, y, (map[mobspawn.m].xs-1), (map[mobspawn.m].ys-1), w1, w3, filepath, strline(buffer,start-buffer));
return strchr(start,'\n');// skip and continue
}
// check monster ID if exists!
- if( mobdb_checkid(class_) == 0 )
+ if( mob->db_checkid(class_) == 0 )
{
ShowError("npc_parse_mob: Unknown mob ID %d (file '%s', line '%d').\n", class_, filepath, strline(buffer,start-buffer));
return strchr(start,'\n');// skip and continue
@@ -3001,15 +2975,15 @@ static const char* npc_parse_mob(char* w1, char* w2, char* w3, char* w4, const c
return strchr(start,'\n');// skip and continue
}
- if( (mob.state.size < 0 || mob.state.size > 2) && size != -1 )
+ if( (mobspawn.state.size < 0 || mobspawn.state.size > 2) && size != -1 )
{
- ShowError("npc_parse_mob: Invalid size number %d for mob ID %d (file '%s', line '%d').\n", mob.state.size, class_, filepath, strline(buffer, start - buffer));
+ ShowError("npc_parse_mob: Invalid size number %d for mob ID %d (file '%s', line '%d').\n", mobspawn.state.size, class_, filepath, strline(buffer, start - buffer));
return strchr(start, '\n');
}
- if( (mob.state.ai < 0 || mob.state.ai > 4) && ai != -1 )
+ if( (mobspawn.state.ai < 0 || mobspawn.state.ai > 4) && ai != -1 )
{
- ShowError("npc_parse_mob: Invalid ai %d for mob ID %d (file '%s', line '%d').\n", mob.state.ai, class_, filepath, strline(buffer, start - buffer));
+ ShowError("npc_parse_mob: Invalid ai %d for mob ID %d (file '%s', line '%d').\n", mobspawn.state.ai, class_, filepath, strline(buffer, start - buffer));
return strchr(start, '\n');
}
@@ -3019,58 +2993,58 @@ static const char* npc_parse_mob(char* w1, char* w2, char* w3, char* w4, const c
return strchr(start, '\n');
}
- mob.num = (unsigned short)num;
- mob.active = 0;
- mob.class_ = (short) class_;
- mob.x = (unsigned short)x;
- mob.y = (unsigned short)y;
- mob.xs = (signed short)xs;
- mob.ys = (signed short)ys;
+ mobspawn.num = (unsigned short)num;
+ mobspawn.active = 0;
+ mobspawn.class_ = (short) class_;
+ mobspawn.x = (unsigned short)x;
+ mobspawn.y = (unsigned short)y;
+ mobspawn.xs = (signed short)xs;
+ mobspawn.ys = (signed short)ys;
if (mob_lv > 0 && mob_lv <= MAX_LEVEL)
- mob.level = mob_lv;
+ mobspawn.level = mob_lv;
if (size > 0 && size <= 2)
- mob.state.size = size;
+ mobspawn.state.size = size;
if (ai > 0 && ai <= 4)
- mob.state.ai = ai;
+ mobspawn.state.ai = ai;
- if (mob.num > 1 && battle_config.mob_count_rate != 100) {
- if ((mob.num = mob.num * battle_config.mob_count_rate / 100) < 1)
- mob.num = 1;
+ if (mobspawn.num > 1 && battle_config.mob_count_rate != 100) {
+ if ((mobspawn.num = mobspawn.num * battle_config.mob_count_rate / 100) < 1)
+ mobspawn.num = 1;
}
- if (battle_config.force_random_spawn || (mob.x == 0 && mob.y == 0))
+ if (battle_config.force_random_spawn || (mobspawn.x == 0 && mobspawn.y == 0))
{ //Force a random spawn anywhere on the map.
- mob.x = mob.y = 0;
- mob.xs = mob.ys = -1;
+ mobspawn.x = mobspawn.y = 0;
+ mobspawn.xs = mobspawn.ys = -1;
}
- if(mob.delay1>0xfffffff || mob.delay2>0xfffffff) {
- ShowError("npc_parse_mob: Invalid spawn delays %u %u (file '%s', line '%d').\n", mob.delay1, mob.delay2, filepath, strline(buffer,start-buffer));
+ if(mobspawn.delay1>0xfffffff || mobspawn.delay2>0xfffffff) {
+ ShowError("npc_parse_mob: Invalid spawn delays %u %u (file '%s', line '%d').\n", mobspawn.delay1, mobspawn.delay2, filepath, strline(buffer,start-buffer));
return strchr(start,'\n');// skip and continue
}
//Use db names instead of the spawn file ones.
if(battle_config.override_mob_names==1)
- strcpy(mob.name,"--en--");
+ strcpy(mobspawn.name,"--en--");
else if (battle_config.override_mob_names==2)
- strcpy(mob.name,"--ja--");
+ strcpy(mobspawn.name,"--ja--");
else
- safestrncpy(mob.name, mobname, sizeof(mob.name));
+ safestrncpy(mobspawn.name, mobname, sizeof(mobspawn.name));
//Verify dataset.
- if( !mob_parse_dataset(&mob) )
+ if( !mob->parse_dataset(&mobspawn) )
{
ShowError("npc_parse_mob: Invalid dataset for monster ID %d (file '%s', line '%d').\n", class_, filepath, strline(buffer,start-buffer));
return strchr(start,'\n');// skip and continue
}
//Update mob spawn lookup database
- db = mob_db(class_);
+ db = mob->db(class_);
for( i = 0; i < ARRAYLENGTH(db->spawn); ++i )
{
- if (map[mob.m].index == db->spawn[i].mapindex)
+ if (map[mobspawn.m].index == db->spawn[i].mapindex)
{ //Update total
- db->spawn[i].qty += mob.num;
+ db->spawn[i].qty += mobspawn.num;
//Re-sort list
for( j = i; j > 0 && db->spawn[j-1].qty < db->spawn[i].qty; --j );
if( j != i )
@@ -3083,18 +3057,18 @@ static const char* npc_parse_mob(char* w1, char* w2, char* w3, char* w4, const c
}
break;
}
- if (mob.num > db->spawn[i].qty)
+ if (mobspawn.num > db->spawn[i].qty)
{ //Insert into list
memmove(&db->spawn[i+1], &db->spawn[i], sizeof(db->spawn) -(i+1)*sizeof(db->spawn[0]));
- db->spawn[i].mapindex = map[mob.m].index;
- db->spawn[i].qty = mob.num;
+ db->spawn[i].mapindex = map[mobspawn.m].index;
+ db->spawn[i].qty = mobspawn.num;
break;
}
}
//Now that all has been validated. We allocate the actual memory that the re-spawn data will use.
data = (struct spawn_data*)aMalloc(sizeof(struct spawn_data));
- memcpy(data, &mob, sizeof(struct spawn_data));
+ memcpy(data, &mobspawn, sizeof(struct spawn_data));
// spawn / cache the new mobs
if( battle_config.dynamic_mobs && iMap->addmobtolist(data->m, data) >= 0 ) {
@@ -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,11 +3766,11 @@ 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);
+ unit->free(bl,CLR_OUTSIGHT);
break;
}
}
@@ -3821,7 +3795,7 @@ int npc_reload(void) {
}
// clear mob spawn lookup index
- mob_clear_spawninfo();
+ mob->clear_spawninfo();
npc_warp = npc_shop = npc_script = 0;
npc_mob = npc_cache_mob = npc_delay_mob = 0;
@@ -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..6c1ca0972 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,
@@ -101,10 +98,6 @@ enum actor_classes
//Since new npcs are added all the time, the max valid value is the one before the first mob (Scorpion = 1001)
#define npcdb_checkid(id) ( ( (id) >= 46 && (id) <= 125) || (id) == HIDDEN_WARP_CLASS || ( (id) > 400 && (id) < MAX_NPC_CLASS ) || (id) == INVISIBLE_CLASS || ( (id) > MAX_NPC_CLASS2_START && (id) < MAX_NPC_CLASS2_END ) )
-#ifdef PCRE_SUPPORT
-void npc_chat_finalize(struct npc_data* nd);
-#endif
-
//Script NPC events.
enum npce_event {
NPCE_LOGIN,
@@ -117,89 +110,184 @@ 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;
+};
-bool npc_unloadfile( const char* path );
+struct npc_path_data {
+ char* path;
+ unsigned short references;
+};
-/* 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;
/* */
-} npc_s;
+ int (*init) (void);
+ int (*final) (void);
+ /* */
+ 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;
void npc_defaults(void);
+
+/* comes from npc_chat.c */
+#ifdef PCRE_SUPPORT
+#include "../../3rdparty/pcre/include/pcre.h"
+/* Structure containing all info associated with a single pattern block */
+struct pcrematch_entry {
+ struct pcrematch_entry* next;
+ char* pattern;
+ pcre* pcre_;
+ pcre_extra* pcre_extra_;
+ char* label;
+};
+
+/* A set of patterns that can be activated and deactived with a single command */
+struct pcrematch_set {
+ struct pcrematch_set* prev;
+ struct pcrematch_set* next;
+ struct pcrematch_entry* head;
+ int setid;
+};
+
+/*
+ * Entire data structure hung off a NPC
+ *
+ * The reason I have done it this way (a void * in npc_data and then
+ * this) was to reduce the number of patches that needed to be applied
+ * to a ragnarok distribution to bring this code online. I
+ * also wanted people to be able to grab this one file to get updates
+ * without having to do a large number of changes.
+ */
+struct npc_parse {
+ struct pcrematch_set* active;
+ struct pcrematch_set* inactive;
+};
+
+struct npc_chat_interface {
+ int (*sub) (struct block_list* bl, va_list ap);
+ void (*finalize) (struct npc_data* nd);
+ void (*def_pattern) (struct npc_data* nd, int setid, const char* pattern, const char* label);
+ struct pcrematch_entry* (*create_pcrematch_entry) (struct pcrematch_set* set);
+ void (*delete_pcreset) (struct npc_data* nd, int setid);
+ void (*deactivate_pcreset) (struct npc_data* nd, int setid);
+ void (*activate_pcreset) (struct npc_data* nd, int setid);
+ struct pcrematch_set* (*lookup_pcreset) (struct npc_data* nd, int setid);
+ void (*finalize_pcrematch_entry) (struct pcrematch_entry* e);
+};
+
+struct npc_chat_interface *npc_chat;
+
+void npc_chat_defaults(void);
+#endif
+
#endif /* _NPC_H_ */
diff --git a/src/map/npc_chat.c b/src/map/npc_chat.c
index f6459e1ae..848347888 100644
--- a/src/map/npc_chat.c
+++ b/src/map/npc_chat.c
@@ -22,6 +22,7 @@
#include <string.h>
#include <stdarg.h>
+struct npc_chat_interface npc_chat_s;
/**
* Written by MouseJstr in a vision... (2/21/2005)
@@ -70,37 +71,6 @@
* deletes a pset
*/
-/* Structure containing all info associated with a single pattern block */
-struct pcrematch_entry {
- struct pcrematch_entry* next;
- char* pattern;
- pcre* pcre_;
- pcre_extra* pcre_extra_;
- char* label;
-};
-
-/* A set of patterns that can be activated and deactived with a single command */
-struct pcrematch_set {
- struct pcrematch_set* prev;
- struct pcrematch_set* next;
- struct pcrematch_entry* head;
- int setid;
-};
-
-/*
- * Entire data structure hung off a NPC
- *
- * The reason I have done it this way (a void * in npc_data and then
- * this) was to reduce the number of patches that needed to be applied
- * to a ragnarok distribution to bring this code online. I
- * also wanted people to be able to grab this one file to get updates
- * without having to do a large number of changes.
- */
-struct npc_parse {
- struct pcrematch_set* active;
- struct pcrematch_set* inactive;
-};
-
/**
* delete everythign associated with a entry
@@ -118,7 +88,7 @@ void finalize_pcrematch_entry(struct pcrematch_entry* e)
/**
* Lookup (and possibly create) a new set of patterns by the set id
*/
-static struct pcrematch_set* lookup_pcreset(struct npc_data* nd, int setid)
+struct pcrematch_set* lookup_pcreset(struct npc_data* nd, int setid)
{
struct pcrematch_set *pcreset;
struct npc_parse *npcParse = (struct npc_parse *) nd->chatdb;
@@ -159,7 +129,7 @@ static struct pcrematch_set* lookup_pcreset(struct npc_data* nd, int setid)
*
* if the setid does not exist, this will silently return
*/
-static void activate_pcreset(struct npc_data* nd, int setid)
+void activate_pcreset(struct npc_data* nd, int setid)
{
struct pcrematch_set *pcreset;
struct npc_parse *npcParse = (struct npc_parse *) nd->chatdb;
@@ -192,7 +162,7 @@ static void activate_pcreset(struct npc_data* nd, int setid)
*
* if the setid does not exist, this will silently return
*/
-static void deactivate_pcreset(struct npc_data* nd, int setid)
+void deactivate_pcreset(struct npc_data* nd, int setid)
{
struct pcrematch_set *pcreset;
struct npc_parse *npcParse = (struct npc_parse *) nd->chatdb;
@@ -200,7 +170,7 @@ static void deactivate_pcreset(struct npc_data* nd, int setid)
return; // Nothing to deactivate...
if (setid == -1) {
while(npcParse->active != NULL)
- deactivate_pcreset(nd, npcParse->active->setid);
+ npc_chat->deactivate_pcreset(nd, npcParse->active->setid);
return;
}
pcreset = npcParse->active;
@@ -228,7 +198,7 @@ static void deactivate_pcreset(struct npc_data* nd, int setid)
/**
* delete a set of patterns.
*/
-static void delete_pcreset(struct npc_data* nd, int setid)
+void delete_pcreset(struct npc_data* nd, int setid)
{
int active = 1;
struct pcrematch_set *pcreset;
@@ -268,7 +238,7 @@ static void delete_pcreset(struct npc_data* nd, int setid)
while (pcreset->head) {
struct pcrematch_entry* n = pcreset->head->next;
- finalize_pcrematch_entry(pcreset->head);
+ npc_chat->finalize_pcrematch_entry(pcreset->head);
aFree(pcreset->head); // Cleanin' the last ones.. [Lance]
pcreset->head = n;
}
@@ -279,7 +249,7 @@ static void delete_pcreset(struct npc_data* nd, int setid)
/**
* create a new pattern entry
*/
-static struct pcrematch_entry* create_pcrematch_entry(struct pcrematch_set* set)
+struct pcrematch_entry* create_pcrematch_entry(struct pcrematch_set* set)
{
struct pcrematch_entry * e = (struct pcrematch_entry *) aCalloc(sizeof(struct pcrematch_entry), 1);
struct pcrematch_entry * last = set->head;
@@ -313,8 +283,8 @@ void npc_chat_def_pattern(struct npc_data* nd, int setid, const char* pattern, c
const char *err;
int erroff;
- struct pcrematch_set * s = lookup_pcreset(nd, setid);
- struct pcrematch_entry *e = create_pcrematch_entry(s);
+ struct pcrematch_set * s = npc_chat->lookup_pcreset(nd, setid);
+ struct pcrematch_entry *e = npc_chat->create_pcrematch_entry(s);
e->pattern = aStrdup(pattern);
e->label = aStrdup(label);
e->pcre_ = pcre_compile(pattern, PCRE_CASELESS, &err, &erroff, NULL);
@@ -334,10 +304,10 @@ void npc_chat_finalize(struct npc_data* nd)
return;
while(npcParse->active)
- delete_pcreset(nd, npcParse->active->setid);
+ npc_chat->delete_pcreset(nd, npcParse->active->setid);
while(npcParse->inactive)
- delete_pcreset(nd, npcParse->inactive->setid);
+ npc_chat->delete_pcreset(nd, npcParse->inactive->setid);
// Additional cleaning up [Lance]
aFree(npcParse);
@@ -390,7 +360,7 @@ int npc_chat_sub(struct block_list* bl, va_list ap)
lst = nd->u.scr.label_list;
ARR_FIND(0, nd->u.scr.label_list_num, i, strncmp(lst[i].name, e->label, sizeof(lst[i].name)) == 0);
if (i == nd->u.scr.label_list_num) {
- ShowWarning("Unable to find label: %s\n", e->label);
+ ShowWarning("npc_chat_sub: Unable to find label: %s\n", e->label);
return 0;
}
@@ -405,47 +375,56 @@ int npc_chat_sub(struct block_list* bl, va_list ap)
}
// Various script builtins used to support these functions
-
-int buildin_defpattern(struct script_state* st)
-{
- int setid = script->conv_num(st,& (st->stack->stack_data[st->start+2]));
- const char* pattern = script->conv_str(st,& (st->stack->stack_data[st->start+3]));
- const char* label = script->conv_str(st,& (st->stack->stack_data[st->start+4]));
+BUILDIN(defpattern) {
+ int setid = script_getnum(st,2);
+ const char* pattern = script_getstr(st,3);
+ const char* label = script_getstr(st,4);
struct npc_data* nd = (struct npc_data *)iMap->id2bl(st->oid);
- npc_chat_def_pattern(nd, setid, pattern, label);
-
- return 1;
+ npc_chat->def_pattern(nd, setid, pattern, label);
+
+ return true;
}
-int buildin_activatepset(struct script_state* st)
-{
- int setid = script->conv_num(st,& (st->stack->stack_data[st->start+2]));
+BUILDIN(activatepset) {
+ int setid = script_getnum(st,2);
struct npc_data* nd = (struct npc_data *)iMap->id2bl(st->oid);
- activate_pcreset(nd, setid);
-
- return 1;
+ npc_chat->activate_pcreset(nd, setid);
+
+ return true;
}
-int buildin_deactivatepset(struct script_state* st)
-{
- int setid = script->conv_num(st,& (st->stack->stack_data[st->start+2]));
+BUILDIN(deactivatepset) {
+ int setid = script_getnum(st,2);
struct npc_data* nd = (struct npc_data *)iMap->id2bl(st->oid);
- deactivate_pcreset(nd, setid);
+ npc_chat->deactivate_pcreset(nd, setid);
- return 1;
+ return true;
}
-int buildin_deletepset(struct script_state* st)
-{
- int setid = script->conv_num(st,& (st->stack->stack_data[st->start+2]));
+BUILDIN(deletepset) {
+ int setid = script_getnum(st,2);
struct npc_data* nd = (struct npc_data *)iMap->id2bl(st->oid);
- delete_pcreset(nd, setid);
-
- return 1;
+ npc_chat->delete_pcreset(nd, setid);
+
+ return true;
+}
+
+void npc_chat_defaults(void) {
+ npc_chat = &npc_chat_s;
+
+ npc_chat->sub = npc_chat_sub;
+ npc_chat->finalize = npc_chat_finalize;
+ npc_chat->def_pattern = npc_chat_def_pattern;
+ npc_chat->create_pcrematch_entry = create_pcrematch_entry;
+ npc_chat->delete_pcreset = delete_pcreset;
+ npc_chat->deactivate_pcreset = deactivate_pcreset;
+ npc_chat->activate_pcreset = activate_pcreset;
+ npc_chat->lookup_pcreset = lookup_pcreset;
+ npc_chat->finalize_pcrematch_entry = finalize_pcrematch_entry;
}
#endif //PCRE_SUPPORT
diff --git a/src/map/path.c b/src/map/path.c
index 32a4189bb..2de3eab00 100644
--- a/src/map/path.c
+++ b/src/map/path.c
@@ -1,5 +1,6 @@
-// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
-// For more information, see LICENCE in the main folder
+// Copyright (c) Hercules Dev Team, licensed under GNU GPL.
+// See the LICENSE file
+// Portions Copyright (c) Athena Dev Teams
#include "../common/cbasetypes.h"
#include "../common/db.h"
@@ -23,6 +24,8 @@
#define DIR_SOUTH 4
#define DIR_EAST 8
+struct path_interface path_s;
+
/// @name Structures and defines for A* pathfinding
/// @{
@@ -458,3 +461,12 @@ unsigned int distance(int dx, int dy)
return (dx<dy?dy:dx);
#endif
}
+void path_defaults(void) {
+ path = &path_s;
+
+ path->blownpos = path_blownpos;
+ path->search_long = path_search_long;
+ path->search = path_search;
+ path->check_distance = check_distance;
+ path->distance = distance;
+}
diff --git a/src/map/path.h b/src/map/path.h
index 5bc551dc9..e872c8877 100644
--- a/src/map/path.h
+++ b/src/map/path.h
@@ -1,5 +1,6 @@
-// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
-// For more information, see LICENCE in the main folder
+// Copyright (c) Hercules Dev Team, licensed under GNU GPL.
+// See the LICENSE file
+// Portions Copyright (c) Athena Dev Teams
#ifndef _PATH_H_
#define _PATH_H_
@@ -22,25 +23,27 @@ struct shootpath_data {
int y[MAX_WALKPATH];
};
-// calculates destination cell for knockback
-int path_blownpos(int16 m,int16 x0,int16 y0,int16 dx,int16 dy,int count);
-
-// tries to find a walkable path
-bool path_search(struct walkpath_data *wpd,int16 m,int16 x0,int16 y0,int16 x1,int16 y1,int flag,cell_chk cell);
-
-// tries to find a shootable path
-bool path_search_long(struct shootpath_data *spd,int16 m,int16 x0,int16 y0,int16 x1,int16 y1,cell_chk cell);
-
+#define check_distance_bl(bl1, bl2, distance) path->check_distance((bl1)->x - (bl2)->x, (bl1)->y - (bl2)->y, distance)
+#define check_distance_blxy(bl, x1, y1, distance) path->check_distance((bl)->x-(x1), (bl)->y-(y1), distance)
+#define check_distance_xy(x0, y0, x1, y1, distance) path->check_distance((x0)-(x1), (y0)-(y1), distance)
+
+#define distance_bl(bl1, bl2) path->distance((bl1)->x - (bl2)->x, (bl1)->y - (bl2)->y)
+#define distance_blxy(bl, x1, y1) path->distance((bl)->x-(x1), (bl)->y-(y1))
+#define distance_xy(x0, y0, x1, y1) path->distance((x0)-(x1), (y0)-(y1))
+
+struct path_interface {
+ // calculates destination cell for knockback
+ int (*blownpos) (int16 m, int16 x0, int16 y0, int16 dx, int16 dy, int count);
+ // tries to find a walkable path
+ bool (*search) (struct walkpath_data *wpd, int16 m, int16 x0, int16 y0, int16 x1, int16 y1, int flag, cell_chk cell);
+ // tries to find a shootable path
+ bool (*search_long) (struct shootpath_data *spd, int16 m, int16 x0, int16 y0, int16 x1, int16 y1, cell_chk cell);
+ int (*check_distance) (int dx, int dy, int distance);
+ unsigned int (*distance) (int dx, int dy);
+};
-// distance related functions
-int check_distance(int dx, int dy, int distance);
-#define check_distance_bl(bl1, bl2, distance) check_distance((bl1)->x - (bl2)->x, (bl1)->y - (bl2)->y, distance)
-#define check_distance_blxy(bl, x1, y1, distance) check_distance((bl)->x-(x1), (bl)->y-(y1), distance)
-#define check_distance_xy(x0, y0, x1, y1, distance) check_distance((x0)-(x1), (y0)-(y1), distance)
+struct path_interface *path;
-unsigned int distance(int dx, int dy);
-#define distance_bl(bl1, bl2) distance((bl1)->x - (bl2)->x, (bl1)->y - (bl2)->y)
-#define distance_blxy(bl, x1, y1) distance((bl)->x-(x1), (bl)->y-(y1))
-#define distance_xy(x0, y0, x1, y1) distance((x0)-(x1), (y0)-(y1))
+void path_defaults(void);
#endif /* _PATH_H_ */
diff --git a/src/map/pc.c b/src/map/pc.c
index d2740c76a..995687170 100644
--- a/src/map/pc.c
+++ b/src/map/pc.c
@@ -648,7 +648,7 @@ int pc_equippoint(struct map_session_data *sd,int n)
if(!sd->inventory_data[n])
return 0;
- if (!itemdb_isequip2(sd->inventory_data[n]))
+ if (!itemdb->isequip2(sd->inventory_data[n]))
return 0; //Not equippable by players.
ep = sd->inventory_data[n]->equip;
@@ -1078,7 +1078,7 @@ bool pc_authok(struct map_session_data *sd, int login_id2, time_t expiration_tim
//Set here because we need the inventory data for weapon sprite parsing.
iStatus->set_viewdata(&sd->bl, sd->status.class_);
- unit_dataset(&sd->bl);
+ unit->dataset(&sd->bl);
sd->guild_x = -1;
sd->guild_y = -1;
@@ -1330,7 +1330,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;
}
@@ -3695,7 +3695,7 @@ int pc_checkadditem(struct map_session_data *sd,int nameid,int amount)
data = itemdb->search(nameid);
- if(!itemdb_isstackable2(data))
+ if(!itemdb->isstackable2(data))
return ADDITEM_NEW;
if( data->stack.inventory && amount > data->stack.amount )
@@ -3941,7 +3941,7 @@ int pc_additem(struct map_session_data *sd,struct item *item_data,int amount,e_l
i = MAX_INVENTORY;
- if( itemdb_isstackable2(data) && item_data->expire_time == 0 )
+ if( itemdb->isstackable2(data) && item_data->expire_time == 0 )
{ // Stackable | Non Rental
for( i = 0; i < MAX_INVENTORY; i++ )
{
@@ -3972,8 +3972,8 @@ int pc_additem(struct map_session_data *sd,struct item *item_data,int amount,e_l
clif->additem(sd,i,amount,0);
}
#ifdef NSI_UNIQUE_ID
- if( !itemdb_isstackable2(data) && !item_data->unique_id )
- sd->status.inventory[i].unique_id = itemdb_unique_id(0,0);
+ if( !itemdb->isstackable2(data) && !item_data->unique_id )
+ sd->status.inventory[i].unique_id = itemdb->unique_id(0,0);
#endif
logs->pick_pc(sd, log_type, amount, &sd->status.inventory[i],sd->inventory_data[i]);
@@ -4472,7 +4472,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;
@@ -4513,7 +4513,7 @@ int pc_cart_additem(struct map_session_data *sd,struct item *item_data,int amoun
return 1;
i = MAX_CART;
- if( itemdb_isstackable2(data) && !item_data->expire_time )
+ if( itemdb->isstackable2(data) && !item_data->expire_time )
{
ARR_FIND( 0, MAX_CART, i,
sd->status.cart[i].nameid == item_data->nameid &&
@@ -4727,7 +4727,7 @@ int pc_steal_item(struct map_session_data *sd,struct block_list *bl, uint16 skil
memset(&tmp_item,0,sizeof(tmp_item));
tmp_item.nameid = itemid;
tmp_item.amount = 1;
- tmp_item.identify = itemdb_isidentified2(data);
+ tmp_item.identify = itemdb->isidentified2(data);
flag = pc->additem(sd,&tmp_item,1,LOG_TYPE_PICKDROP_PLAYER);
//TODO: Should we disable stealing when the item you stole couldn't be added to your inventory? Perhaps players will figure out a way to exploit this behaviour otherwise?
@@ -4870,7 +4870,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);
}
}
@@ -4904,7 +4904,7 @@ int pc_setpos(struct map_session_data* sd, unsigned short mapindex, int x, int y
skill->clear_unitgroup(&sd->bl);
party->send_dot_remove(sd); //minimap dot fix [Kevin]
guild->send_dot_remove(sd);
- bg_send_dot_remove(sd);
+ bg->send_dot_remove(sd);
if (sd->regen.state.gc)
sd->regen.state.gc = 0;
// make sure vending is allowed here
@@ -4926,10 +4926,10 @@ 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);
+ unit->remove_map_pc(sd,clrtype);
sd->mapindex = mapindex;
sd->bl.x=x;
sd->bl.y=y;
@@ -4938,7 +4938,7 @@ int pc_setpos(struct map_session_data* sd, unsigned short mapindex, int x, int y
chrif->changemapserver(sd, ip, (short)port);
//Free session data from this map server [Kevin]
- unit_free_pc(sd);
+ unit->free_pc(sd);
return 0;
}
@@ -4961,7 +4961,7 @@ int pc_setpos(struct map_session_data* sd, unsigned short mapindex, int x, int y
}
if(sd->bl.prev != NULL){
- unit_remove_map_pc(sd,clrtype);
+ unit->remove_map_pc(sd,clrtype);
clif->changemap(sd,m,x,y); // [MouseJstr]
} else if(sd->state.active)
//Tag player for rewarping after map-loading is done. [Skotlex]
@@ -5726,9 +5726,9 @@ int pc_follow_timer(int tid, unsigned int tick, int id, intptr_t data)
if (sd->bl.prev != NULL && tbl->prev != NULL &&
sd->ud.skilltimer == INVALID_TIMER && sd->ud.attacktimer == INVALID_TIMER && sd->ud.walktimer == INVALID_TIMER)
{
- if((sd->bl.m == tbl->m) && unit_can_reach_bl(&sd->bl,tbl, AREA_SIZE, 0, NULL, NULL)) {
+ if((sd->bl.m == tbl->m) && unit->can_reach_bl(&sd->bl,tbl, AREA_SIZE, 0, NULL, NULL)) {
if (!check_distance_bl(&sd->bl, tbl, 5))
- unit_walktobl(&sd->bl, tbl, 5, 0);
+ unit->walktobl(&sd->bl, tbl, 5, 0);
} else
pc->setpos(sd, map_id2index(tbl->m), tbl->x, tbl->y, CLR_TELEPORT);
}
@@ -5749,7 +5749,7 @@ int pc_stop_following (struct map_session_data *sd)
sd->followtarget = -1;
sd->ud.target_to = 0;
- unit_stop_walking(&sd->bl, 1);
+ unit->stop_walking(&sd->bl, 1);
return 0;
}
@@ -5809,7 +5809,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);
@@ -5858,7 +5858,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;
}
@@ -6652,7 +6652,7 @@ void pc_respawn(struct map_session_data* sd, clr_type clrtype)
{
if( !pc_isdead(sd) )
return; // not applicable
- if( sd->bg_id && bg_member_respawn(sd) )
+ if( sd->bg_id && bg->member_respawn(sd) )
return; // member revived by battleground
pc->setstand(sd);
@@ -6696,7 +6696,7 @@ void pc_damage(struct map_session_data *sd,struct block_list *src,unsigned int h
}
if( sd->status.pet_id > 0 && sd->pd && battle_config.pet_damage_support )
- pet_target_check(sd,src,1);
+ pet->target_check(sd,src,1);
if( sd->status.ele_id > 0 )
elemental->set_target(sd,src);
@@ -6722,13 +6722,13 @@ int pc_dead(struct map_session_data *sd,struct block_list *src) {
if(sd->status.pet_id > 0 && sd->pd) {
struct pet_data *pd = sd->pd;
if( !map[sd->bl.m].flag.noexppenalty ) {
- pet_set_intimate(pd, pd->pet.intimate - pd->petDB->die);
+ pet->set_intimate(pd, pd->pet.intimate - pd->petDB->die);
if( pd->pet.intimate < 0 )
pd->pet.intimate = 0;
clif->send_petdata(sd,sd->pd,1,pd->pet.intimate);
}
if( sd->pd->target_id ) // Unlock all targets...
- pet_unlocktarget(sd->pd);
+ pet->unlocktarget(sd->pd);
}
if (sd->status.hom_id > 0){
@@ -6751,24 +6751,24 @@ 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);
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);
+ struct battleground_data *bgd;
+ if( (bgd = bg->team_search(sd->bg_id)) != NULL && bgd->die_event[0] )
+ npc->event(sd, bgd->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) {
@@ -6813,7 +6813,7 @@ int pc_dead(struct map_session_data *sd,struct block_list *src) {
{
struct mob_data *md=(struct mob_data *)src;
if(md->target_id==sd->bl.id)
- mob_unlocktarget(md,tick);
+ mob->unlocktarget(md,tick);
if(battle_config.mobs_level_up && md->status.hp &&
(unsigned int)md->level < pc->maxbaselv(sd) &&
!md->guardian_data && !md->special_state.ai// Guardians/summons should not level. [Skotlex]
@@ -6846,7 +6846,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;
@@ -7032,8 +7032,8 @@ int pc_dead(struct map_session_data *sd,struct block_list *src) {
iTimer->add_timer(tick+1, pc_respawn_timer, sd->bl.id, 0);
return 1|8;
} else if( sd->bg_id ) {
- struct battleground_data *bg = bg_team_search(sd->bg_id);
- if( bg && bg->mapindex > 0 ) { // Respawn by BG
+ struct battleground_data *bgd = bg->team_search(sd->bg_id);
+ if( bgd && bgd->mapindex > 0 ) { // Respawn by BG
iTimer->add_timer(tick+1000, pc_respawn_timer, sd->bl.id, 0);
return 1|8;
}
@@ -8327,7 +8327,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");
@@ -8770,7 +8770,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 {
@@ -8780,7 +8780,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);
}
}
}
@@ -8937,7 +8937,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 {
@@ -8948,7 +8948,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/pc.h b/src/map/pc.h
index 231f369d8..c8e7e17d5 100644
--- a/src/map/pc.h
+++ b/src/map/pc.h
@@ -645,8 +645,8 @@ enum equip_pos {
// Rune Knight Dragon
#define pc_isridingdragon(sd) ( (sd)->sc.option&OPTION_DRAGON )
-#define pc_stop_walking(sd, type) unit_stop_walking(&(sd)->bl, type)
-#define pc_stop_attack(sd) unit_stop_attack(&(sd)->bl)
+#define pc_stop_walking(sd, type) unit->stop_walking(&(sd)->bl, type)
+#define pc_stop_attack(sd) unit->stop_attack(&(sd)->bl)
//Weapon check considering dual wielding.
#define pc_check_weapontype(sd, type) ((type)&((sd)->status.weapon < MAX_WEAPON_TYPE? \
diff --git a/src/map/pet.c b/src/map/pet.c
index ae8216fc2..8498517ef 100644
--- a/src/map/pet.c
+++ b/src/map/pet.c
@@ -34,14 +34,10 @@
#include <stdlib.h>
#include <string.h>
+struct pet_interface pet_s;
#define MIN_PETTHINKTIME 100
-struct s_pet_db pet_db[MAX_PET_DB];
-
-static struct eri *item_drop_ers; //For loot drops delay structures.
-static struct eri *item_drop_list_ers;
-
int pet_hungry_val(struct pet_data *pd)
{
nullpo_ret(pd);
@@ -74,16 +70,16 @@ void pet_set_intimate(struct pet_data *pd, int value)
int pet_create_egg(struct map_session_data *sd, int item_id)
{
- int pet_id = search_petDB_index(item_id, PET_EGG);
+ int pet_id = pet->search_petDB_index(item_id, PET_EGG);
if (pet_id < 0) return 0; //No pet egg here.
if (!pc->inventoryblank(sd)) return 0; // Inventory full
- sd->catch_target_class = pet_db[pet_id].class_;
+ sd->catch_target_class = pet->db[pet_id].class_;
intif->create_pet(sd->status.account_id, sd->status.char_id,
- (short)pet_db[pet_id].class_,
- (short)mob_db(pet_db[pet_id].class_)->lv,
- (short)pet_db[pet_id].EggID, 0,
- (short)pet_db[pet_id].intimate,
- 100, 0, 1, pet_db[pet_id].jname);
+ (short)pet->db[pet_id].class_,
+ (short)mob->db(pet->db[pet_id].class_)->lv,
+ (short)pet->db[pet_id].EggID, 0,
+ (short)pet->db[pet_id].intimate,
+ 100, 0, 1, pet->db[pet_id].jname);
return 1;
}
@@ -121,9 +117,9 @@ int pet_attackskill(struct pet_data *pd, int target_id)
inf = skill->get_inf(pd->a_skill->id);
if (inf & INF_GROUND_SKILL)
- unit_skilluse_pos(&pd->bl, bl->x, bl->y, pd->a_skill->id, pd->a_skill->lv);
+ unit->skilluse_pos(&pd->bl, bl->x, bl->y, pd->a_skill->id, pd->a_skill->lv);
else //Offensive self skill? Could be stuff like GX.
- unit_skilluse_id(&pd->bl,(inf&INF_SELF_SKILL?pd->bl.id:bl->id), pd->a_skill->id, pd->a_skill->lv);
+ unit->skilluse_id(&pd->bl,(inf&INF_SELF_SKILL?pd->bl.id:bl->id), pd->a_skill->id, pd->a_skill->lv);
return 1; //Skill invoked.
}
return 0;
@@ -187,12 +183,12 @@ int pet_sc_check(struct map_session_data *sd, int type)
|| pd->recovery->type != type )
return 1;
- pd->recovery->timer = iTimer->add_timer(iTimer->gettick()+pd->recovery->delay*1000,pet_recovery_timer,sd->bl.id,0);
+ pd->recovery->timer = iTimer->add_timer(iTimer->gettick()+pd->recovery->delay*1000,pet->recovery_timer,sd->bl.id,0);
return 0;
}
-static int pet_hungry(int tid, unsigned int tick, int id, intptr_t data)
+int pet_hungry(int tid, unsigned int tick, int id, intptr_t data)
{
struct map_session_data *sd;
struct pet_data *pd;
@@ -220,7 +216,7 @@ static int pet_hungry(int tid, unsigned int tick, int id, intptr_t data)
{
pet_stop_attack(pd);
pd->pet.hungry = 0;
- pet_set_intimate(pd, pd->pet.intimate - battle_config.pet_hungry_friendly_decrease);
+ pet->set_intimate(pd, pd->pet.intimate - battle_config.pet_hungry_friendly_decrease);
if( pd->pet.intimate <= 0 )
{
pd->pet.intimate = 0;
@@ -237,7 +233,7 @@ static int pet_hungry(int tid, unsigned int tick, int id, intptr_t data)
interval = pd->petDB->hungry_delay;
if(interval <= 0)
interval = 1;
- pd->pet_hungry_timer = iTimer->add_timer(tick+interval,pet_hungry,sd->bl.id,0);
+ pd->pet_hungry_timer = iTimer->add_timer(tick+interval,pet->hungry,sd->bl.id,0);
return 0;
}
@@ -248,14 +244,14 @@ int search_petDB_index(int key,int type)
for( i = 0; i < MAX_PET_DB; i++ )
{
- if(pet_db[i].class_ <= 0)
+ if(pet->db[i].class_ <= 0)
continue;
switch(type) {
- case PET_CLASS: if(pet_db[i].class_ == key) return i; break;
- case PET_CATCH: if(pet_db[i].itemID == key) return i; break;
- case PET_EGG: if(pet_db[i].EggID == key) return i; break;
- case PET_EQUIP: if(pet_db[i].AcceID == key) return i; break;
- case PET_FOOD: if(pet_db[i].FoodID == key) return i; break;
+ case PET_CLASS: if(pet->db[i].class_ == key) return i; break;
+ case PET_CATCH: if(pet->db[i].itemID == key) return i; break;
+ case PET_EGG: if(pet->db[i].EggID == key) return i; break;
+ case PET_EQUIP: if(pet->db[i].AcceID == key) return i; break;
+ case PET_FOOD: if(pet->db[i].FoodID == key) return i; break;
default:
return -1;
}
@@ -267,14 +263,14 @@ int pet_hungry_timer_delete(struct pet_data *pd)
{
nullpo_ret(pd);
if(pd->pet_hungry_timer != INVALID_TIMER) {
- iTimer->delete_timer(pd->pet_hungry_timer,pet_hungry);
+ iTimer->delete_timer(pd->pet_hungry_timer,pet->hungry);
pd->pet_hungry_timer = INVALID_TIMER;
}
return 1;
}
-static int pet_performance(struct map_session_data *sd, struct pet_data *pd)
+int pet_performance(struct map_session_data *sd, struct pet_data *pd)
{
int val;
@@ -287,16 +283,16 @@ static int pet_performance(struct map_session_data *sd, struct pet_data *pd)
pet_stop_walking(pd,2000<<8);
clif->send_petdata(NULL, pd, 4, rnd()%val + 1);
- pet_lootitem_drop(pd,NULL);
+ pet->lootitem_drop(pd,NULL);
return 1;
}
-static int pet_return_egg(struct map_session_data *sd, struct pet_data *pd)
+int pet_return_egg(struct map_session_data *sd, struct pet_data *pd)
{
struct item tmp_item;
int flag;
- pet_lootitem_drop(pd,sd);
+ pet->lootitem_drop(pd,sd);
memset(&tmp_item,0,sizeof(tmp_item));
tmp_item.nameid = pd->petDB->EggID;
tmp_item.identify = 1;
@@ -309,7 +305,7 @@ static int pet_return_egg(struct map_session_data *sd, struct pet_data *pd)
iMap->addflooritem(&tmp_item,1,sd->bl.m,sd->bl.x,sd->bl.y,0,0,0,0);
}
pd->pet.incuvate = 1;
- unit_free(&pd->bl,CLR_OUTSIGHT);
+ unit->free(&pd->bl,CLR_OUTSIGHT);
status_calc_pc(sd,0);
sd->status.pet_id = 0;
@@ -317,7 +313,7 @@ static int pet_return_egg(struct map_session_data *sd, struct pet_data *pd)
return 1;
}
-int pet_data_init(struct map_session_data *sd, struct s_pet *pet)
+int pet_data_init(struct map_session_data *sd, struct s_pet *petinfo)
{
struct pet_data *pd;
int i=0,interval=0;
@@ -326,43 +322,43 @@ int pet_data_init(struct map_session_data *sd, struct s_pet *pet)
Assert((sd->status.pet_id == 0 || sd->pd == 0) || sd->pd->msd == sd);
- if(sd->status.account_id != pet->account_id || sd->status.char_id != pet->char_id) {
+ if(sd->status.account_id != petinfo->account_id || sd->status.char_id != petinfo->char_id) {
sd->status.pet_id = 0;
return 1;
}
- if (sd->status.pet_id != pet->pet_id) {
+ if (sd->status.pet_id != petinfo->pet_id) {
if (sd->status.pet_id) {
//Wrong pet?? Set incuvate to no and send it back for saving.
- pet->incuvate = 1;
- intif->save_petdata(sd->status.account_id,pet);
+ petinfo->incuvate = 1;
+ intif->save_petdata(sd->status.account_id,petinfo);
sd->status.pet_id = 0;
return 1;
}
//The pet_id value was lost? odd... restore it.
- sd->status.pet_id = pet->pet_id;
+ sd->status.pet_id = petinfo->pet_id;
}
- i = search_petDB_index(pet->class_,PET_CLASS);
+ i = pet->search_petDB_index(petinfo->class_,PET_CLASS);
if(i < 0) {
sd->status.pet_id = 0;
return 1;
}
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];
- pd->db = mob_db(pet->class_);
- memcpy(&pd->pet, pet, sizeof(struct s_pet));
- iStatus->set_viewdata(&pd->bl, pet->class_);
- unit_dataset(&pd->bl);
+ pd->petDB = &pet->db[i];
+ pd->db = mob->db(petinfo->class_);
+ memcpy(&pd->pet, petinfo, sizeof(struct s_pet));
+ iStatus->set_viewdata(&pd->bl, petinfo->class_);
+ unit->dataset(&pd->bl);
pd->ud.dir = sd->ud.dir;
pd->bl.m = sd->bl.m;
pd->bl.x = sd->bl.x;
pd->bl.y = sd->bl.y;
- unit_calc_pos(&pd->bl, sd->bl.x, sd->bl.y, sd->ud.dir);
+ unit->calc_pos(&pd->bl, sd->bl.x, sd->bl.y, sd->ud.dir);
pd->bl.x = pd->ud.to_x;
pd->bl.y = pd->ud.to_y;
@@ -372,7 +368,7 @@ int pet_data_init(struct map_session_data *sd, struct s_pet *pet)
pd->last_thinktime = iTimer->gettick();
pd->state.skillbonus = 0;
if( battle_config.pet_status_support )
- script->run(pet_db[i].pet_script,0,sd->bl.id,0);
+ script->run(pet->db[i].pet_script,0,sd->bl.id,0);
if( pd->petDB && pd->petDB->equip_script )
status_calc_pc(sd,0);
@@ -382,31 +378,31 @@ int pet_data_init(struct map_session_data *sd, struct s_pet *pet)
interval = pd->petDB->hungry_delay;
if( interval <= 0 )
interval = 1;
- pd->pet_hungry_timer = iTimer->add_timer(iTimer->gettick() + interval, pet_hungry, sd->bl.id, 0);
+ pd->pet_hungry_timer = iTimer->add_timer(iTimer->gettick() + interval, pet->hungry, sd->bl.id, 0);
return 0;
}
-int pet_birth_process(struct map_session_data *sd, struct s_pet *pet)
+int pet_birth_process(struct map_session_data *sd, struct s_pet *petinfo)
{
nullpo_retr(1, sd);
Assert((sd->status.pet_id == 0 || sd->pd == 0) || sd->pd->msd == sd);
- if(sd->status.pet_id && pet->incuvate == 1) {
+ if(sd->status.pet_id && petinfo->incuvate == 1) {
sd->status.pet_id = 0;
return 1;
}
- pet->incuvate = 0;
- pet->account_id = sd->status.account_id;
- pet->char_id = sd->status.char_id;
- sd->status.pet_id = pet->pet_id;
- if(pet_data_init(sd, pet)) {
+ petinfo->incuvate = 0;
+ petinfo->account_id = sd->status.account_id;
+ petinfo->char_id = sd->status.char_id;
+ sd->status.pet_id = petinfo->pet_id;
+ if(pet->data_init(sd, petinfo)) {
sd->status.pet_id = 0;
return 1;
}
- intif->save_petdata(sd->status.account_id,pet);
+ intif->save_petdata(sd->status.account_id,petinfo);
if (iMap->save_settings&8)
chrif->save(sd,0); //is it REALLY Needed to save the char for hatching a pet? [Skotlex]
@@ -447,10 +443,10 @@ int pet_recv_petdata(int account_id,struct s_pet *p,int flag)
sd->status.pet_id = 0;
return 1;
}
- if (!pet_birth_process(sd,p)) //Pet hatched. Delete egg.
+ if (!pet->birth_process(sd,p)) //Pet hatched. Delete egg.
pc->delitem(sd,i,1,0,0,LOG_TYPE_OTHER);
} else {
- pet_data_init(sd,p);
+ pet->data_init(sd,p);
if(sd->pd && sd->bl.prev != NULL) {
iMap->addblock(&sd->pd->bl);
clif->spawn(&sd->pd->bl);
@@ -507,7 +503,7 @@ int pet_catch_process2(struct map_session_data* sd, int target_id)
//FIXME: delete taming item here, if this was an item-invoked capture and the item was flagged as delay-consume [ultramage]
- i = search_petDB_index(md->class_,PET_CLASS);
+ i = pet->search_petDB_index(md->class_,PET_CLASS);
//catch_target_class == 0 is used for universal lures (except bosses for now). [Skotlex]
if (sd->catch_target_class == 0 && !(md->status.mode&MD_BOSS))
sd->catch_target_class = md->class_;
@@ -518,7 +514,7 @@ int pet_catch_process2(struct map_session_data* sd, int target_id)
return 1;
}
- pet_catch_rate = (pet_db[i].capture + (sd->status.base_level - md->level)*30 + sd->battle_status.luk*20)*(200 - get_percentage(md->status.hp, md->status.max_hp))/100;
+ pet_catch_rate = (pet->db[i].capture + (sd->status.base_level - md->level)*30 + sd->battle_status.luk*20)*(200 - get_percentage(md->status.hp, md->status.max_hp))/100;
if(pet_catch_rate < 1) pet_catch_rate = 1;
if(battle_config.pet_catch_rate != 100)
@@ -526,11 +522,11 @@ int pet_catch_process2(struct map_session_data* sd, int target_id)
if(rnd()%10000 < pet_catch_rate)
{
- unit_remove_map(&md->bl,CLR_OUTSIGHT);
+ unit->remove_map(&md->bl,CLR_OUTSIGHT,ALC_MARK);
status_kill(&md->bl);
clif->pet_roulette(sd,1);
- intif->create_pet(sd->status.account_id,sd->status.char_id,pet_db[i].class_,mob_db(pet_db[i].class_)->lv,
- pet_db[i].EggID,0,pet_db[i].intimate,100,0,1,pet_db[i].jname);
+ intif->create_pet(sd->status.account_id,sd->status.char_id,pet->db[i].class_,mob->db(pet->db[i].class_)->lv,
+ pet->db[i].EggID,0,pet->db[i].intimate,100,0,1,pet->db[i].jname);
}
else
{
@@ -554,7 +550,7 @@ int pet_get_egg(int account_id,int pet_id,int flag)
if(sd == NULL)
return 0;
- i = search_petDB_index(sd->catch_target_class,PET_CLASS);
+ i = pet->search_petDB_index(sd->catch_target_class,PET_CLASS);
sd->catch_target_class = -1;
if(i < 0) {
@@ -563,7 +559,7 @@ int pet_get_egg(int account_id,int pet_id,int flag)
}
memset(&tmp_item,0,sizeof(tmp_item));
- tmp_item.nameid = pet_db[i].EggID;
+ tmp_item.nameid = pet->db[i].EggID;
tmp_item.identify = 1;
tmp_item.card[0] = CARD0_PET;
tmp_item.card[1] = GetWord(pet_id,0);
@@ -577,10 +573,6 @@ int pet_get_egg(int account_id,int pet_id,int flag)
return 1;
}
-static int pet_unequipitem(struct map_session_data *sd, struct pet_data *pd);
-static int pet_food(struct map_session_data *sd, struct pet_data *pd);
-static int pet_ai_sub_hard_lootsearch(struct block_list *bl,va_list ap);
-
int pet_menu(struct map_session_data *sd,int menunum)
{
struct item_data *egg_id;
@@ -605,16 +597,16 @@ int pet_menu(struct map_session_data *sd,int menunum)
clif->send_petstatus(sd);
break;
case 1:
- pet_food(sd, sd->pd);
+ pet->food(sd, sd->pd);
break;
case 2:
- pet_performance(sd, sd->pd);
+ pet->performance(sd, sd->pd);
break;
case 3:
- pet_return_egg(sd, sd->pd);
+ pet->return_egg(sd, sd->pd);
break;
case 4:
- pet_unequipitem(sd, sd->pd);
+ pet->unequipitem(sd, sd->pd);
break;
}
return 0;
@@ -684,18 +676,18 @@ int pet_equipitem(struct map_session_data *sd,int index)
if (pd->s_skill && pd->s_skill->timer == INVALID_TIMER)
{
if (pd->s_skill->id)
- pd->s_skill->timer=iTimer->add_timer(tick+pd->s_skill->delay*1000, pet_skill_support_timer, sd->bl.id, 0);
+ pd->s_skill->timer=iTimer->add_timer(tick+pd->s_skill->delay*1000, pet->skill_support_timer, sd->bl.id, 0);
else
- pd->s_skill->timer=iTimer->add_timer(tick+pd->s_skill->delay*1000, pet_heal_timer, sd->bl.id, 0);
+ pd->s_skill->timer=iTimer->add_timer(tick+pd->s_skill->delay*1000, pet->heal_timer, sd->bl.id, 0);
}
if (pd->bonus && pd->bonus->timer == INVALID_TIMER)
- pd->bonus->timer=iTimer->add_timer(tick+pd->bonus->delay*1000, pet_skill_bonus_timer, sd->bl.id, 0);
+ pd->bonus->timer=iTimer->add_timer(tick+pd->bonus->delay*1000, pet->skill_bonus_timer, sd->bl.id, 0);
}
return 0;
}
-static int pet_unequipitem(struct map_session_data *sd, struct pet_data *pd)
+int pet_unequipitem(struct map_session_data *sd, struct pet_data *pd)
{
struct item tmp_item;
int nameid,flag;
@@ -724,14 +716,14 @@ static int pet_unequipitem(struct map_session_data *sd, struct pet_data *pd)
if( pd->s_skill && pd->s_skill->timer != INVALID_TIMER )
{
if( pd->s_skill->id )
- iTimer->delete_timer(pd->s_skill->timer, pet_skill_support_timer);
+ iTimer->delete_timer(pd->s_skill->timer, pet->skill_support_timer);
else
- iTimer->delete_timer(pd->s_skill->timer, pet_heal_timer);
+ iTimer->delete_timer(pd->s_skill->timer, pet->heal_timer);
pd->s_skill->timer = INVALID_TIMER;
}
if( pd->bonus && pd->bonus->timer != INVALID_TIMER )
{
- iTimer->delete_timer(pd->bonus->timer, pet_skill_bonus_timer);
+ iTimer->delete_timer(pd->bonus->timer, pet->skill_bonus_timer);
pd->bonus->timer = INVALID_TIMER;
}
}
@@ -739,7 +731,7 @@ static int pet_unequipitem(struct map_session_data *sd, struct pet_data *pd)
return 0;
}
-static int pet_food(struct map_session_data *sd, struct pet_data *pd)
+int pet_food(struct map_session_data *sd, struct pet_data *pd)
{
int i,k;
@@ -752,7 +744,7 @@ static int pet_food(struct map_session_data *sd, struct pet_data *pd)
pc->delitem(sd,i,1,0,0,LOG_TYPE_CONSUME);
if( pd->pet.hungry > 90 )
- pet_set_intimate(pd, pd->pet.intimate - pd->petDB->r_full);
+ pet->set_intimate(pd, pd->pet.intimate - pd->petDB->r_full);
else
{
if( battle_config.pet_friendly_rate != 100 )
@@ -765,7 +757,7 @@ static int pet_food(struct map_session_data *sd, struct pet_data *pd)
if( k <= 0 )
k = 1;
}
- pet_set_intimate(pd, pd->pet.intimate + k);
+ pet->set_intimate(pd, pd->pet.intimate + k);
}
if( pd->pet.intimate <= 0 )
{
@@ -787,13 +779,13 @@ static int pet_food(struct map_session_data *sd, struct pet_data *pd)
return 0;
}
-static int pet_randomwalk(struct pet_data *pd,unsigned int tick)
+int pet_randomwalk(struct pet_data *pd,unsigned int tick)
{
nullpo_ret(pd);
Assert((pd->msd == 0) || (pd->msd->pd == pd));
- if(DIFF_TICK(pd->next_walktime,tick) < 0 && unit_can_move(&pd->bl)) {
+ if(DIFF_TICK(pd->next_walktime,tick) < 0 && unit->can_move(&pd->bl)) {
const int retrycount=20;
int i,x,y,c,d=12-pd->move_fail_count;
if(d<5) d=5;
@@ -801,7 +793,7 @@ static int pet_randomwalk(struct pet_data *pd,unsigned int tick)
int r=rnd();
x=pd->bl.x+r%(d*2+1)-d;
y=pd->bl.y+r/(d*2+1)%(d*2+1)-d;
- if(iMap->getcell(pd->bl.m,x,y,CELL_CHKPASS) && unit_walktoxy(&pd->bl,x,y,0)){
+ if(iMap->getcell(pd->bl.m,x,y,CELL_CHKPASS) && unit->walktoxy(&pd->bl,x,y,0)){
pd->move_fail_count=0;
break;
}
@@ -828,7 +820,7 @@ static int pet_randomwalk(struct pet_data *pd,unsigned int tick)
return 0;
}
-static int pet_ai_sub_hard(struct pet_data *pd, struct map_session_data *sd, unsigned int tick)
+int pet_ai_sub_hard(struct pet_data *pd, struct map_session_data *sd, unsigned int tick)
{
struct block_list *target = NULL;
@@ -847,14 +839,14 @@ static int pet_ai_sub_hard(struct pet_data *pd, struct map_session_data *sd, uns
if(pd->pet.intimate <= 0) {
//Pet should just... well, random walk.
- pet_randomwalk(pd,tick);
+ pet->randomwalk(pd,tick);
return 0;
}
if (!check_distance_bl(&sd->bl, &pd->bl, pd->db->range3)) {
//Master too far, chase.
if(pd->target_id)
- pet_unlocktarget(pd);
+ pet->unlocktarget(pd);
if(pd->ud.walktimer != INVALID_TIMER && pd->ud.target == sd->bl.id)
return 0; //Already walking to him
if (DIFF_TICK(tick, pd->ud.canmove_tick) < 0)
@@ -862,8 +854,8 @@ static int pet_ai_sub_hard(struct pet_data *pd, struct map_session_data *sd, uns
pd->status.speed = (sd->battle_status.speed>>1);
if(pd->status.speed <= 0)
pd->status.speed = 1;
- if (!unit_walktobl(&pd->bl, &sd->bl, 3, 0))
- pet_randomwalk(pd,tick);
+ if (!unit->walktobl(&pd->bl, &sd->bl, 3, 0))
+ pet->randomwalk(pd,tick);
return 0;
}
@@ -881,13 +873,13 @@ static int pet_ai_sub_hard(struct pet_data *pd, struct map_session_data *sd, uns
!check_distance_bl(&pd->bl, target, pd->db->range3))
{
target = NULL;
- pet_unlocktarget(pd);
+ pet->unlocktarget(pd);
}
}
if(!target && pd->loot && pd->msd && pc->has_permission(pd->msd, PC_PERM_TRADE) && pd->loot->count < pd->loot->max && DIFF_TICK(tick,pd->ud.canact_tick)>0) {
//Use half the pet's range of sight.
- iMap->foreachinrange(pet_ai_sub_hard_lootsearch,&pd->bl,
+ iMap->foreachinrange(pet->ai_sub_hard_lootsearch,&pd->bl,
pd->db->range2/2, BL_ITEM,pd,&target);
}
@@ -899,9 +891,9 @@ static int pet_ai_sub_hard(struct pet_data *pd, struct map_session_data *sd, uns
if(pd->ud.walktimer != INVALID_TIMER && check_distance_blxy(&sd->bl, pd->ud.to_x,pd->ud.to_y, 3))
return 0; //Already walking to him
- unit_calc_pos(&pd->bl, sd->bl.x, sd->bl.y, sd->ud.dir);
- if(!unit_walktoxy(&pd->bl,pd->ud.to_x,pd->ud.to_y,0))
- pet_randomwalk(pd,tick);
+ unit->calc_pos(&pd->bl, sd->bl.x, sd->bl.y, sd->ud.dir);
+ if(!unit->walktoxy(&pd->bl,pd->ud.to_x,pd->ud.to_y,0))
+ pet->randomwalk(pd,tick);
return 0;
}
@@ -914,17 +906,17 @@ static int pet_ai_sub_hard(struct pet_data *pd, struct map_session_data *sd, uns
{ //enemy targetted
if(!battle->check_range(&pd->bl,target,pd->status.rhw.range))
{ //Chase
- if(!unit_walktobl(&pd->bl, target, pd->status.rhw.range, 2))
- pet_unlocktarget(pd); //Unreachable target.
+ if(!unit->walktobl(&pd->bl, target, pd->status.rhw.range, 2))
+ pet->unlocktarget(pd); //Unreachable target.
return 0;
}
//Continuous attack.
- unit_attack(&pd->bl, pd->target_id, 1);
+ unit->attack(&pd->bl, pd->target_id, 1);
} else { //Item Targeted, attempt loot
if (!check_distance_bl(&pd->bl, target, 1))
{ //Out of range
- if(!unit_walktobl(&pd->bl, target, 1, 1)) //Unreachable target.
- pet_unlocktarget(pd);
+ if(!unit->walktobl(&pd->bl, target, 1, 1)) //Unreachable target.
+ pet->unlocktarget(pd);
return 0;
} else{
struct flooritem_data *fitem = (struct flooritem_data *)target;
@@ -934,29 +926,29 @@ static int pet_ai_sub_hard(struct pet_data *pd, struct map_session_data *sd, uns
iMap->clearflooritem(target);
}
//Target is unlocked regardless of whether it was picked or not.
- pet_unlocktarget(pd);
+ pet->unlocktarget(pd);
}
}
return 0;
}
-static int pet_ai_sub_foreachclient(struct map_session_data *sd,va_list ap)
+int pet_ai_sub_foreachclient(struct map_session_data *sd,va_list ap)
{
unsigned int tick = va_arg(ap,unsigned int);
if(sd->status.pet_id && sd->pd)
- pet_ai_sub_hard(sd->pd,sd,tick);
+ pet->ai_sub_hard(sd->pd,sd,tick);
return 0;
}
-static int pet_ai_hard(int tid, unsigned int tick, int id, intptr_t data)
+int pet_ai_hard(int tid, unsigned int tick, int id, intptr_t data)
{
- iMap->map_foreachpc(pet_ai_sub_foreachclient,tick);
+ iMap->map_foreachpc(pet->ai_sub_foreachclient,tick);
return 0;
}
-static int pet_ai_sub_hard_lootsearch(struct block_list *bl,va_list ap)
+int pet_ai_sub_hard_lootsearch(struct block_list *bl,va_list ap)
{
struct pet_data* pd;
struct flooritem_data *fitem = (struct flooritem_data *)bl;
@@ -971,7 +963,7 @@ static int pet_ai_sub_hard_lootsearch(struct block_list *bl,va_list ap)
if(sd_charid && sd_charid != pd->msd->status.char_id)
return 0;
- if(unit_can_reach_bl(&pd->bl,bl, pd->db->range2, 1, NULL, NULL) &&
+ if(unit->can_reach_bl(&pd->bl,bl, pd->db->range2, 1, NULL, NULL) &&
((*target) == NULL || //New target closer than previous one.
!check_distance_bl(&pd->bl, *target, distance_bl(&pd->bl, bl))))
{
@@ -983,7 +975,7 @@ static int pet_ai_sub_hard_lootsearch(struct block_list *bl,va_list ap)
return 0;
}
-static int pet_delay_item_drop(int tid, unsigned int tick, int id, intptr_t data)
+int pet_delay_item_drop(int tid, unsigned int tick, int id, intptr_t data)
{
struct item_drop_list *list;
struct item_drop *ditem, *ditem_prev;
@@ -995,9 +987,9 @@ static int pet_delay_item_drop(int tid, unsigned int tick, int id, intptr_t data
list->first_charid,list->second_charid,list->third_charid,0);
ditem_prev = ditem;
ditem = ditem->next;
- ers_free(item_drop_ers, ditem_prev);
+ ers_free(pet->item_drop_ers, ditem_prev);
}
- ers_free(item_drop_list_ers, list);
+ ers_free(pet->item_drop_list_ers, list);
return 0;
}
@@ -1009,7 +1001,7 @@ int pet_lootitem_drop(struct pet_data *pd,struct map_session_data *sd)
struct item *it;
if(!pd || !pd->loot || !pd->loot->count)
return 0;
- dlist = ers_alloc(item_drop_list_ers, struct item_drop_list);
+ dlist = ers_alloc(pet->item_drop_list_ers, struct item_drop_list);
dlist->m = pd->bl.m;
dlist->x = pd->bl.x;
dlist->y = pd->bl.y;
@@ -1023,14 +1015,14 @@ int pet_lootitem_drop(struct pet_data *pd,struct map_session_data *sd)
if(sd){
if((flag = pc->additem(sd,it,it->amount,LOG_TYPE_PICKDROP_PLAYER))){
clif->additem(sd,0,0,flag);
- ditem = ers_alloc(item_drop_ers, struct item_drop);
+ ditem = ers_alloc(pet->item_drop_ers, struct item_drop);
memcpy(&ditem->item_data, it, sizeof(struct item));
ditem->next = dlist->item;
dlist->item = ditem;
}
}
else {
- ditem = ers_alloc(item_drop_ers, struct item_drop);
+ ditem = ers_alloc(pet->item_drop_ers, struct item_drop);
memcpy(&ditem->item_data, it, sizeof(struct item));
ditem->next = dlist->item;
dlist->item = ditem;
@@ -1043,9 +1035,9 @@ int pet_lootitem_drop(struct pet_data *pd,struct map_session_data *sd)
pd->ud.canact_tick = iTimer->gettick()+10000; //prevent picked up during 10*1000ms
if (dlist->item)
- iTimer->add_timer(iTimer->gettick()+540,pet_delay_item_drop,0,(intptr_t)dlist);
+ iTimer->add_timer(iTimer->gettick()+540,pet->delay_item_drop,0,(intptr_t)dlist);
else
- ers_free(item_drop_list_ers, dlist);
+ ers_free(pet->item_drop_list_ers, dlist);
return 1;
}
@@ -1087,7 +1079,7 @@ int pet_skill_bonus_timer(int tid, unsigned int tick, int id, intptr_t data)
status_calc_pc(sd, 0);
}
// wait for the next timer
- pd->bonus->timer=iTimer->add_timer(tick+timer,pet_skill_bonus_timer,sd->bl.id,0);
+ pd->bonus->timer=iTimer->add_timer(tick+timer,pet->skill_bonus_timer,sd->bl.id,0);
return 0;
}
@@ -1146,14 +1138,14 @@ int pet_heal_timer(int tid, unsigned int tick, int id, intptr_t data)
(rate = get_percentage(status->hp, status->max_hp)) > pd->s_skill->hp ||
(rate = (pd->ud.skilltimer != INVALID_TIMER)) //Another skill is in effect
) { //Wait (how long? 1 sec for every 10% of remaining)
- pd->s_skill->timer=iTimer->add_timer(iTimer->gettick()+(rate>10?rate:10)*100,pet_heal_timer,sd->bl.id,0);
+ pd->s_skill->timer=iTimer->add_timer(iTimer->gettick()+(rate>10?rate:10)*100,pet->heal_timer,sd->bl.id,0);
return 0;
}
pet_stop_attack(pd);
pet_stop_walking(pd,1);
clif->skill_nodamage(&pd->bl,&sd->bl,AL_HEAL,pd->s_skill->lv,1);
iStatus->heal(&sd->bl, pd->s_skill->lv,0, 0);
- pd->s_skill->timer=iTimer->add_timer(tick+pd->s_skill->delay*1000,pet_heal_timer,sd->bl.id,0);
+ pd->s_skill->timer=iTimer->add_timer(tick+pd->s_skill->delay*1000,pet->heal_timer,sd->bl.id,0);
return 0;
}
@@ -1180,7 +1172,7 @@ int pet_skill_support_timer(int tid, unsigned int tick, int id, intptr_t data)
if (DIFF_TICK(pd->ud.canact_tick, tick) > 0)
{ //Wait until the pet can act again.
- pd->s_skill->timer=iTimer->add_timer(pd->ud.canact_tick,pet_skill_support_timer,sd->bl.id,0);
+ pd->s_skill->timer=iTimer->add_timer(pd->ud.canact_tick,pet->skill_support_timer,sd->bl.id,0);
return 0;
}
@@ -1189,24 +1181,24 @@ int pet_skill_support_timer(int tid, unsigned int tick, int id, intptr_t data)
(rate = get_percentage(status->hp, status->max_hp)) > pd->s_skill->hp ||
(rate = (pd->ud.skilltimer != INVALID_TIMER)) //Another skill is in effect
) { //Wait (how long? 1 sec for every 10% of remaining)
- pd->s_skill->timer=iTimer->add_timer(tick+(rate>10?rate:10)*100,pet_skill_support_timer,sd->bl.id,0);
+ pd->s_skill->timer=iTimer->add_timer(tick+(rate>10?rate:10)*100,pet->skill_support_timer,sd->bl.id,0);
return 0;
}
pet_stop_attack(pd);
pet_stop_walking(pd,1);
- pd->s_skill->timer=iTimer->add_timer(tick+pd->s_skill->delay*1000,pet_skill_support_timer,sd->bl.id,0);
+ pd->s_skill->timer=iTimer->add_timer(tick+pd->s_skill->delay*1000,pet->skill_support_timer,sd->bl.id,0);
if (skill->get_inf(pd->s_skill->id) & INF_GROUND_SKILL)
- unit_skilluse_pos(&pd->bl, sd->bl.x, sd->bl.y, pd->s_skill->id, pd->s_skill->lv);
+ unit->skilluse_pos(&pd->bl, sd->bl.x, sd->bl.y, pd->s_skill->id, pd->s_skill->lv);
else
- unit_skilluse_id(&pd->bl, sd->bl.id, pd->s_skill->id, pd->s_skill->lv);
+ unit->skilluse_id(&pd->bl, sd->bl.id, pd->s_skill->id, pd->s_skill->lv);
return 0;
}
/*==========================================
* Pet read db data
- * pet_db.txt
- * pet_db2.txt
+ * pet->db.txt
+ * pet->db2.txt
*------------------------------------------*/
int read_petdb()
{
@@ -1217,20 +1209,20 @@ int read_petdb()
// Remove any previous scripts in case reloaddb was invoked.
for( j = 0; j < MAX_PET_DB; j++ )
{
- if( pet_db[j].pet_script )
+ if( pet->db[j].pet_script )
{
- script->free_code(pet_db[j].pet_script);
- pet_db[j].pet_script = NULL;
+ script->free_code(pet->db[j].pet_script);
+ pet->db[j].pet_script = NULL;
}
- if( pet_db[j].equip_script )
+ if( pet->db[j].equip_script )
{
- script->free_code(pet_db[j].equip_script);
- pet_db[j].pet_script = NULL;
+ script->free_code(pet->db[j].equip_script);
+ pet->db[j].pet_script = NULL;
}
}
// clear database
- memset(pet_db,0,sizeof(pet_db));
+ memset(pet->db,0,sizeof(pet->db));
j = 0; // entry counter
for( i = 0; i < ARRAYLENGTH(filename); i++ )
@@ -1305,41 +1297,41 @@ int read_petdb()
if( (nameid = atoi(str[0])) <= 0 )
continue;
- if( !mobdb_checkid(nameid) )
+ if( !mob->db_checkid(nameid) )
{
ShowWarning("pet_db reading: Invalid mob-class %d, pet not read.\n", nameid);
continue;
}
- pet_db[j].class_ = nameid;
- safestrncpy(pet_db[j].name,str[1],NAME_LENGTH);
- safestrncpy(pet_db[j].jname,str[2],NAME_LENGTH);
- pet_db[j].itemID=atoi(str[3]);
- pet_db[j].EggID=atoi(str[4]);
- pet_db[j].AcceID=atoi(str[5]);
- pet_db[j].FoodID=atoi(str[6]);
- pet_db[j].fullness=atoi(str[7]);
- pet_db[j].hungry_delay=atoi(str[8])*1000;
- pet_db[j].r_hungry=atoi(str[9]);
- if( pet_db[j].r_hungry <= 0 )
- pet_db[j].r_hungry=1;
- pet_db[j].r_full=atoi(str[10]);
- pet_db[j].intimate=atoi(str[11]);
- pet_db[j].die=atoi(str[12]);
- pet_db[j].capture=atoi(str[13]);
- pet_db[j].speed=atoi(str[14]);
- pet_db[j].s_perfor=(char)atoi(str[15]);
- pet_db[j].talk_convert_class=atoi(str[16]);
- pet_db[j].attack_rate=atoi(str[17]);
- pet_db[j].defence_attack_rate=atoi(str[18]);
- pet_db[j].change_target_rate=atoi(str[19]);
- pet_db[j].pet_script = NULL;
- pet_db[j].equip_script = NULL;
+ pet->db[j].class_ = nameid;
+ safestrncpy(pet->db[j].name,str[1],NAME_LENGTH);
+ safestrncpy(pet->db[j].jname,str[2],NAME_LENGTH);
+ pet->db[j].itemID=atoi(str[3]);
+ pet->db[j].EggID=atoi(str[4]);
+ pet->db[j].AcceID=atoi(str[5]);
+ pet->db[j].FoodID=atoi(str[6]);
+ pet->db[j].fullness=atoi(str[7]);
+ pet->db[j].hungry_delay=atoi(str[8])*1000;
+ pet->db[j].r_hungry=atoi(str[9]);
+ if( pet->db[j].r_hungry <= 0 )
+ pet->db[j].r_hungry=1;
+ pet->db[j].r_full=atoi(str[10]);
+ pet->db[j].intimate=atoi(str[11]);
+ pet->db[j].die=atoi(str[12]);
+ pet->db[j].capture=atoi(str[13]);
+ pet->db[j].speed=atoi(str[14]);
+ pet->db[j].s_perfor=(char)atoi(str[15]);
+ pet->db[j].talk_convert_class=atoi(str[16]);
+ pet->db[j].attack_rate=atoi(str[17]);
+ pet->db[j].defence_attack_rate=atoi(str[18]);
+ pet->db[j].change_target_rate=atoi(str[19]);
+ pet->db[j].pet_script = NULL;
+ pet->db[j].equip_script = NULL;
if( *str[20] )
- pet_db[j].pet_script = script->parse(str[20], filename[i], lines, 0);
+ pet->db[j].pet_script = script->parse(str[20], filename[i], lines, 0);
if( *str[21] )
- pet_db[j].equip_script = script->parse(str[21], filename[i], lines, 0);
+ pet->db[j].equip_script = script->parse(str[21], filename[i], lines, 0);
j++;
entries++;
@@ -1358,19 +1350,19 @@ int read_petdb()
*------------------------------------------*/
int do_init_pet(void)
{
- read_petdb();
+ pet->read_db();
- item_drop_ers = ers_new(sizeof(struct item_drop),"pet.c::item_drop_ers",ERS_OPT_NONE);
- item_drop_list_ers = ers_new(sizeof(struct item_drop_list),"pet.c::item_drop_list_ers",ERS_OPT_NONE);
+ pet->item_drop_ers = ers_new(sizeof(struct item_drop),"pet.c::item_drop_ers",ERS_OPT_NONE);
+ pet->item_drop_list_ers = ers_new(sizeof(struct item_drop_list),"pet.c::item_drop_list_ers",ERS_OPT_NONE);
- iTimer->add_timer_func_list(pet_hungry,"pet_hungry");
- iTimer->add_timer_func_list(pet_ai_hard,"pet_ai_hard");
- iTimer->add_timer_func_list(pet_skill_bonus_timer,"pet_skill_bonus_timer"); // [Valaris]
- iTimer->add_timer_func_list(pet_delay_item_drop,"pet_delay_item_drop");
- iTimer->add_timer_func_list(pet_skill_support_timer, "pet_skill_support_timer"); // [Skotlex]
- iTimer->add_timer_func_list(pet_recovery_timer,"pet_recovery_timer"); // [Valaris]
- iTimer->add_timer_func_list(pet_heal_timer,"pet_heal_timer"); // [Valaris]
- iTimer->add_timer_interval(iTimer->gettick()+MIN_PETTHINKTIME,pet_ai_hard,0,0,MIN_PETTHINKTIME);
+ iTimer->add_timer_func_list(pet->hungry,"pet_hungry");
+ iTimer->add_timer_func_list(pet->ai_hard,"pet_ai_hard");
+ iTimer->add_timer_func_list(pet->skill_bonus_timer,"pet_skill_bonus_timer"); // [Valaris]
+ iTimer->add_timer_func_list(pet->delay_item_drop,"pet_delay_item_drop");
+ iTimer->add_timer_func_list(pet->skill_support_timer, "pet_skill_support_timer"); // [Skotlex]
+ iTimer->add_timer_func_list(pet->recovery_timer,"pet_recovery_timer"); // [Valaris]
+ iTimer->add_timer_func_list(pet->heal_timer,"pet_heal_timer"); // [Valaris]
+ iTimer->add_timer_interval(iTimer->gettick()+MIN_PETTHINKTIME,pet->ai_hard,0,0,MIN_PETTHINKTIME);
return 0;
}
@@ -1380,18 +1372,68 @@ int do_final_pet(void)
int i;
for( i = 0; i < MAX_PET_DB; i++ )
{
- if( pet_db[i].pet_script )
+ if( pet->db[i].pet_script )
{
- script->free_code(pet_db[i].pet_script);
- pet_db[i].pet_script = NULL;
+ script->free_code(pet->db[i].pet_script);
+ pet->db[i].pet_script = NULL;
}
- if( pet_db[i].equip_script )
+ if( pet->db[i].equip_script )
{
- script->free_code(pet_db[i].equip_script);
- pet_db[i].equip_script = NULL;
+ script->free_code(pet->db[i].equip_script);
+ pet->db[i].equip_script = NULL;
}
}
- ers_destroy(item_drop_ers);
- ers_destroy(item_drop_list_ers);
+ ers_destroy(pet->item_drop_ers);
+ ers_destroy(pet->item_drop_list_ers);
return 0;
}
+void pet_defaults(void) {
+ pet = &pet_s;
+
+ memset(pet->db,0,sizeof(pet->db));
+ pet->item_drop_ers = NULL;
+ pet->item_drop_list_ers = NULL;
+
+ /* */
+ pet->init = do_init_pet;
+ pet->final = do_final_pet;
+
+ /* */
+ pet->hungry_val = pet_hungry_val;
+ pet->set_intimate = pet_set_intimate;
+ pet->create_egg = pet_create_egg;
+ pet->unlocktarget = pet_unlocktarget;
+ pet->attackskill = pet_attackskill;
+ pet->target_check = pet_target_check;
+ pet->sc_check = pet_sc_check;
+ pet->hungry = pet_hungry;
+ pet->search_petDB_index = search_petDB_index;
+ pet->hungry_timer_delete = pet_hungry_timer_delete;
+ pet->performance = pet_performance;
+ pet->return_egg = pet_return_egg;
+ pet->data_init = pet_data_init;
+ pet->birth_process = pet_birth_process;
+ pet->recv_petdata = pet_recv_petdata;
+ pet->select_egg = pet_select_egg;
+ pet->catch_process1 = pet_catch_process1;
+ pet->catch_process2 = pet_catch_process2;
+ pet->get_egg = pet_get_egg;
+ pet->unequipitem = pet_unequipitem;
+ pet->food = pet_food;
+ pet->ai_sub_hard_lootsearch = pet_ai_sub_hard_lootsearch;
+ pet->menu = pet_menu;
+ pet->change_name = pet_change_name;
+ pet->change_name_ack = pet_change_name_ack;
+ pet->equipitem = pet_equipitem;
+ pet->randomwalk = pet_randomwalk;
+ pet->ai_sub_hard = pet_ai_sub_hard;
+ pet->ai_sub_foreachclient = pet_ai_sub_foreachclient;
+ pet->ai_hard = pet_ai_hard;
+ pet->delay_item_drop = pet_delay_item_drop;
+ pet->lootitem_drop = pet_lootitem_drop;
+ pet->skill_bonus_timer = pet_skill_bonus_timer;
+ pet->recovery_timer = pet_recovery_timer;
+ pet->heal_timer = pet_heal_timer;
+ pet->skill_support_timer = pet_skill_support_timer;
+ pet->read_db = read_petdb;
+}
diff --git a/src/map/pet.h b/src/map/pet.h
index b46f55229..b0e7cec6d 100644
--- a/src/map/pet.h
+++ b/src/map/pet.h
@@ -1,5 +1,6 @@
-// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
-// For more information, see LICENCE in the main folder
+// Copyright (c) Hercules Dev Team, licensed under GNU GPL.
+// See the LICENSE file
+// Portions Copyright (c) Athena Dev Teams
#ifndef _PET_H_
#define _PET_H_
@@ -30,7 +31,6 @@ struct s_pet_db {
struct script_code *equip_script;
struct script_code *pet_script;
};
-extern struct s_pet_db pet_db[MAX_PET_DB];
enum { PET_CLASS,PET_CATCH,PET_EGG,PET_EQUIP,PET_FOOD };
@@ -98,39 +98,58 @@ struct pet_data {
struct map_session_data *msd;
};
+#define pet_stop_walking(pd, type) unit->stop_walking(&(pd)->bl, type)
+#define pet_stop_attack(pd) unit->stop_attack(&(pd)->bl)
+
+struct pet_interface {
+ struct s_pet_db db[MAX_PET_DB];
+ struct eri *item_drop_ers; //For loot drops delay structures.
+ struct eri *item_drop_list_ers;
+ /* */
+ int (*init) (void);
+ int (*final) (void);
+ /* */
+ int (*hungry_val) (struct pet_data *pd);
+ void (*set_intimate) (struct pet_data *pd, int value);
+ int (*create_egg) (struct map_session_data *sd, int item_id);
+ int (*unlocktarget) (struct pet_data *pd);
+ int (*attackskill) (struct pet_data *pd, int target_id);
+ int (*target_check) (struct map_session_data *sd, struct block_list *bl, int type);
+ int (*sc_check) (struct map_session_data *sd, int type);
+ int (*hungry) (int tid, unsigned int tick, int id, intptr_t data);
+ int (*search_petDB_index) (int key, int type);
+ int (*hungry_timer_delete) (struct pet_data *pd);
+ int (*performance) (struct map_session_data *sd, struct pet_data *pd);
+ int (*return_egg) (struct map_session_data *sd, struct pet_data *pd);
+ int (*data_init) (struct map_session_data *sd, struct s_pet *pet);
+ int (*birth_process) (struct map_session_data *sd, struct s_pet *pet);
+ int (*recv_petdata) (int account_id, struct s_pet *p, int flag);
+ int (*select_egg) (struct map_session_data *sd, short egg_index);
+ int (*catch_process1) (struct map_session_data *sd, int target_class);
+ int (*catch_process2) (struct map_session_data *sd, int target_id);
+ int (*get_egg) (int account_id, int pet_id, int flag);
+ int (*unequipitem) (struct map_session_data *sd, struct pet_data *pd);
+ int (*food) (struct map_session_data *sd, struct pet_data *pd);
+ int (*ai_sub_hard_lootsearch) (struct block_list *bl, va_list ap);
+ int (*menu) (struct map_session_data *sd, int menunum);
+ int (*change_name) (struct map_session_data *sd, char *name);
+ int (*change_name_ack) (struct map_session_data *sd, char *name, int flag);
+ int (*equipitem) (struct map_session_data *sd, int index);
+ int (*randomwalk) (struct pet_data *pd, unsigned int tick);
+ int (*ai_sub_hard) (struct pet_data *pd, struct map_session_data *sd, unsigned int tick);
+ int (*ai_sub_foreachclient) (struct map_session_data *sd, va_list ap);
+ int (*ai_hard) (int tid, unsigned int tick, int id, intptr_t data);
+ int (*delay_item_drop) (int tid, unsigned int tick, int id, intptr_t data);
+ int (*lootitem_drop) (struct pet_data *pd, struct map_session_data *sd);
+ int (*skill_bonus_timer) (int tid, unsigned int tick, int id, intptr_t data);
+ int (*recovery_timer) (int tid, unsigned int tick, int id, intptr_t data);
+ int (*heal_timer) (int tid, unsigned int tick, int id, intptr_t data);
+ int (*skill_support_timer) (int tid, unsigned int tick, int id, intptr_t data);
+ int (*read_db) ();
+};
+struct pet_interface *pet;
-int pet_create_egg(struct map_session_data *sd, int item_id);
-int pet_hungry_val(struct pet_data *pd);
-void pet_set_intimate(struct pet_data *pd, int value);
-int pet_target_check(struct map_session_data *sd,struct block_list *bl,int type);
-int pet_unlocktarget(struct pet_data *pd);
-int pet_sc_check(struct map_session_data *sd, int type); //Skotlex
-int search_petDB_index(int key,int type);
-int pet_hungry_timer_delete(struct pet_data *pd);
-int pet_data_init(struct map_session_data *sd, struct s_pet *pet);
-int pet_birth_process(struct map_session_data *sd, struct s_pet *pet);
-int pet_recv_petdata(int account_id,struct s_pet *p,int flag);
-int pet_select_egg(struct map_session_data *sd,short egg_index);
-int pet_catch_process1(struct map_session_data *sd,int target_class);
-int pet_catch_process2(struct map_session_data *sd,int target_id);
-int pet_get_egg(int account_id,int pet_id,int flag);
-int pet_menu(struct map_session_data *sd,int menunum);
-int pet_change_name(struct map_session_data *sd,char *name);
-int pet_change_name_ack(struct map_session_data *sd, char* name, int flag);
-int pet_equipitem(struct map_session_data *sd,int index);
-int pet_lootitem_drop(struct pet_data *pd,struct map_session_data *sd);
-int pet_attackskill(struct pet_data *pd, int target_id);
-int pet_skill_support_timer(int tid, unsigned int tick, int id, intptr_t data); // [Skotlex]
-int pet_skill_bonus_timer(int tid, unsigned int tick, int id, intptr_t data); // [Valaris]
-int pet_recovery_timer(int tid, unsigned int tick, int id, intptr_t data); // [Valaris]
-int pet_heal_timer(int tid, unsigned int tick, int id, intptr_t data); // [Valaris]
-
-#define pet_stop_walking(pd, type) unit_stop_walking(&(pd)->bl, type)
-#define pet_stop_attack(pd) unit_stop_attack(&(pd)->bl)
-
-int read_petdb(void);
-int do_init_pet(void);
-int do_final_pet(void);
+void pet_defaults(void);
#endif /* _PET_H_ */
diff --git a/src/map/quest.c b/src/map/quest.c
index cf78430a4..9055b61fe 100644
--- a/src/map/quest.c
+++ b/src/map/quest.c
@@ -1,5 +1,6 @@
-// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
-// For more information, see LICENCE in the main folder
+// Copyright (c) Hercules Dev Team, licensed under GNU GPL.
+// See the LICENSE file
+// Portions Copyright (c) Athena Dev Teams
#include "../common/cbasetypes.h"
#include "../common/socket.h"
@@ -32,14 +33,13 @@
#include <time.h>
-struct s_quest_db quest_db[MAX_QUEST_DB];
-
+struct quest_interface quest_s;
int quest_search_db(int quest_id)
{
int i;
- ARR_FIND(0, MAX_QUEST_DB,i,quest_id == quest_db[i].id);
+ ARR_FIND(0, MAX_QUEST_DB,i,quest_id == quest->db[i].id);
if( i == MAX_QUEST_DB )
return -1;
@@ -74,13 +74,13 @@ int quest_add(TBL_PC * sd, int quest_id)
return 1;
}
- if( quest_check(sd, quest_id, HAVEQUEST) >= 0 )
+ if( quest->check(sd, quest_id, HAVEQUEST) >= 0 )
{
ShowError("quest_add: Character %d already has quest %d.\n", sd->status.char_id, quest_id);
return -1;
}
- if( (j = quest_search_db(quest_id)) < 0 )
+ if( (j = quest->search_db(quest_id)) < 0 )
{
ShowError("quest_add: quest %d not found in DB.\n", quest_id);
return -1;
@@ -91,9 +91,9 @@ int quest_add(TBL_PC * sd, int quest_id)
memmove(sd->quest_index+i+1, sd->quest_index+i, sizeof(int)*(sd->num_quests-sd->avail_quests));
memset(&sd->quest_log[i], 0, sizeof(struct quest));
- sd->quest_log[i].quest_id = quest_db[j].id;
- if( quest_db[j].time )
- sd->quest_log[i].time = (unsigned int)(time(NULL) + quest_db[j].time);
+ sd->quest_log[i].quest_id = quest->db[j].id;
+ if( quest->db[j].time )
+ sd->quest_log[i].time = (unsigned int)(time(NULL) + quest->db[j].time);
sd->quest_log[i].state = Q_ACTIVE;
sd->quest_index[i] = j;
@@ -114,19 +114,19 @@ int quest_change(TBL_PC * sd, int qid1, int qid2)
int i, j;
- if( quest_check(sd, qid2, HAVEQUEST) >= 0 )
+ if( quest->check(sd, qid2, HAVEQUEST) >= 0 )
{
ShowError("quest_change: Character %d already has quest %d.\n", sd->status.char_id, qid2);
return -1;
}
- if( quest_check(sd, qid1, HAVEQUEST) < 0 )
+ if( quest->check(sd, qid1, HAVEQUEST) < 0 )
{
ShowError("quest_change: Character %d doesn't have quest %d.\n", sd->status.char_id, qid1);
return -1;
}
- if( (j = quest_search_db(qid2)) < 0 )
+ if( (j = quest->search_db(qid2)) < 0 )
{
ShowError("quest_change: quest %d not found in DB.\n",qid2);
return -1;
@@ -140,9 +140,9 @@ int quest_change(TBL_PC * sd, int qid1, int qid2)
}
memset(&sd->quest_log[i], 0, sizeof(struct quest));
- sd->quest_log[i].quest_id = quest_db[j].id;
- if( quest_db[j].time )
- sd->quest_log[i].time = (unsigned int)(time(NULL) + quest_db[j].time);
+ sd->quest_log[i].quest_id = quest->db[j].id;
+ if( quest->db[j].time )
+ sd->quest_log[i].time = (unsigned int)(time(NULL) + quest->db[j].time);
sd->quest_log[i].state = Q_ACTIVE;
sd->quest_index[i] = j;
@@ -205,7 +205,7 @@ int quest_update_objective_sub(struct block_list *bl, va_list ap)
if( sd->status.party_id != party )
return 0;
- quest_update_objective(sd, mob);
+ quest->update_objective(sd, mob);
return 1;
}
@@ -219,7 +219,7 @@ void quest_update_objective(TBL_PC * sd, int mob) {
continue;
for( j = 0; j < MAX_QUEST_OBJECTIVES; j++ )
- if( quest_db[sd->quest_index[i]].mob[j] == mob && sd->quest_log[i].count[j] < quest_db[sd->quest_index[i]].count[j] ) {
+ if( quest->db[sd->quest_index[i]].mob[j] == mob && sd->quest_log[i].count[j] < quest->db[sd->quest_index[i]].count[j] ) {
sd->quest_log[i].count[j]++;
sd->save_quest = true;
clif->quest_update_objective(sd,&sd->quest_log[i],sd->quest_index[i]);
@@ -275,7 +275,7 @@ int quest_check(TBL_PC * sd, int quest_id, quest_check_type type) {
case HUNTING: {
if( sd->quest_log[i].state == 0 || sd->quest_log[i].state == 1 ) {
int j;
- ARR_FIND(0, MAX_QUEST_OBJECTIVES, j, sd->quest_log[i].count[j] < quest_db[sd->quest_index[i]].count[j]);
+ ARR_FIND(0, MAX_QUEST_OBJECTIVES, j, sd->quest_log[i].count[j] < quest->db[sd->quest_index[i]].count[j]);
if( j == MAX_QUEST_OBJECTIVES )
return 2;
if( sd->quest_log[i].time < (unsigned int)time(NULL) )
@@ -331,20 +331,20 @@ int quest_read_db(void) {
if(str[0]==NULL)
continue;
- memset(&quest_db[k], 0, sizeof(quest_db[0]));
+ memset(&quest->db[k], 0, sizeof(quest->db[0]));
- quest_db[k].id = atoi(str[0]);
- quest_db[k].time = atoi(str[1]);
+ quest->db[k].id = atoi(str[0]);
+ quest->db[k].time = atoi(str[1]);
for( i = 0; i < MAX_QUEST_OBJECTIVES; i++ ) {
- quest_db[k].mob[i] = atoi(str[2*i+2]);
- quest_db[k].count[i] = atoi(str[2*i+3]);
+ quest->db[k].mob[i] = atoi(str[2*i+2]);
+ quest->db[k].count[i] = atoi(str[2*i+3]);
- if( !quest_db[k].mob[i] || !quest_db[k].count[i] )
+ if( !quest->db[k].mob[i] || !quest->db[k].count[i] )
break;
}
- quest_db[k].num_objectives = i;
+ quest->db[k].num_objectives = i;
k++;
}
@@ -354,10 +354,30 @@ int quest_read_db(void) {
}
void do_init_quest(void) {
- quest_read_db();
+ quest->read_db();
}
void do_reload_quest(void) {
- memset(&quest_db, 0, sizeof(quest_db));
- quest_read_db();
+ memset(&quest->db, 0, sizeof(quest->db));
+ quest->read_db();
+}
+
+void quest_defaults(void) {
+ quest = &quest_s;
+
+ memset(&quest->db, 0, sizeof(quest->db));
+ /* */
+ quest->init = do_init_quest;
+ quest->reload = do_reload_quest;
+ /* */
+ quest->search_db = quest_search_db;
+ quest->pc_login = quest_pc_login;
+ quest->add = quest_add;
+ quest->change = quest_change;
+ quest->delete = quest_delete;
+ quest->update_objective_sub = quest_update_objective_sub;
+ quest->update_objective = quest_update_objective;
+ quest->update_status = quest_update_status;
+ quest->check = quest_check;
+ quest->read_db = quest_read_db;
}
diff --git a/src/map/quest.h b/src/map/quest.h
index 7f638a54c..85c987f54 100644
--- a/src/map/quest.h
+++ b/src/map/quest.h
@@ -1,5 +1,6 @@
-// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
-// For more information, see LICENCE in the main folder
+// Copyright (c) Hercules Dev Team, licensed under GNU GPL.
+// See the LICENSE file
+// Portions Copyright (c) Athena Dev Teams
#ifndef _QUEST_H_
#define _QUEST_H_
@@ -12,23 +13,29 @@ struct s_quest_db {
int num_objectives;
//char name[NAME_LENGTH];
};
-extern struct s_quest_db quest_db[MAX_QUEST_DB];
typedef enum quest_check_type { HAVEQUEST, PLAYTIME, HUNTING } quest_check_type;
-int quest_pc_login(TBL_PC * sd);
-
-int quest_add(TBL_PC * sd, int quest_id);
-int quest_delete(TBL_PC * sd, int quest_id);
-int quest_change(TBL_PC * sd, int qid1, int qid2);
-int quest_update_objective_sub(struct block_list *bl, va_list ap);
-void quest_update_objective(TBL_PC * sd, int mob);
-int quest_update_status(TBL_PC * sd, int quest_id, quest_state status);
-int quest_check(TBL_PC * sd, int quest_id, quest_check_type type);
+struct quest_interface {
+ struct s_quest_db db[MAX_QUEST_DB];
+ /* */
+ void (*init) (void);
+ void (*reload) (void);
+ /* */
+ int (*search_db) (int quest_id);
+ int (*pc_login) (TBL_PC *sd);
+ int (*add) (TBL_PC *sd, int quest_id);
+ int (*change) (TBL_PC *sd, int qid1, int qid2);
+ int (*delete) (TBL_PC *sd, int quest_id);
+ int (*update_objective_sub) (struct block_list *bl, va_list ap);
+ void (*update_objective) (TBL_PC *sd, int mob);
+ int (*update_status) (TBL_PC *sd, int quest_id, quest_state status);
+ int (*check) (TBL_PC *sd, int quest_id, quest_check_type type);
+ int (*read_db) (void);
+};
-int quest_search_db(int quest_id);
+struct quest_interface *quest;
-void do_init_quest();
-void do_reload_quest(void);
+void quest_defaults(void);
#endif
diff --git a/src/map/script.c b/src/map/script.c
index 3e2347123..7ac638848 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -63,6 +63,7 @@
#include <setjmp.h>
#include <errno.h>
+
#define FETCH(n, t) \
if( script_hasdata(st,n) ) \
(t)=script_getnum(st,n);
@@ -2340,7 +2341,7 @@ void get_val(struct script_state* st, struct script_data* data)
data->u.str = pc->readregstr(sd, data->u.num);
break;
case '$':
- data->u.str = mapreg_readregstr(data->u.num);
+ data->u.str = mapreg->readregstr(data->u.num);
break;
case '#':
if( name[1] == '#' )
@@ -2395,7 +2396,7 @@ void get_val(struct script_state* st, struct script_data* data)
data->u.num = pc->readreg(sd, data->u.num);
break;
case '$':
- data->u.num = mapreg_readreg(data->u.num);
+ data->u.num = mapreg->readreg(data->u.num);
break;
case '#':
if( name[1] == '#' )
@@ -2458,7 +2459,7 @@ static int set_reg(struct script_state* st, TBL_PC* sd, int num, const char* nam
case '@':
return pc->setregstr(sd, num, str);
case '$':
- return mapreg_setregstr(num, str);
+ return mapreg->setregstr(num, str);
case '#':
return (name[1] == '#') ?
pc_setaccountreg2str(sd, name, str) :
@@ -2505,7 +2506,7 @@ static int set_reg(struct script_state* st, TBL_PC* sd, int num, const char* nam
case '@':
return pc->setreg(sd, num, val);
case '$':
- return mapreg_setreg(num, val);
+ return mapreg->setreg(num, val);
case '#':
return (name[1] == '#') ?
pc_setaccountreg2(sd, name, val) :
@@ -3380,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);
@@ -3420,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
}
@@ -3794,7 +3795,7 @@ void do_final_script(void) {
dbi_destroy(iter);
- mapreg_final();
+ mapreg->final();
script->userfunc_db->destroy(script->userfunc_db, db_script_free_code_sub);
script->autobonus_db->destroy(script->autobonus_db, db_script_free_code_sub);
@@ -3863,7 +3864,7 @@ void do_init_script(void) {
script->parse_builtin();
read_constdb();
- mapreg_init();
+ mapreg->init();
}
int script_reload(void) {
@@ -3893,7 +3894,7 @@ int script_reload(void) {
db_clear(script->st_db);
- mapreg_reload();
+ mapreg->reload();
itemdb->force_name_constants();
@@ -5758,7 +5759,7 @@ BUILDIN(checkweight)
// item is already in inventory, but there is still space for the requested amount
break;
case ADDITEM_NEW:
- if( itemdb_isstackable(nameid) ) {// stackable
+ if( itemdb->isstackable(nameid) ) {// stackable
amount2++;
if( slots < amount2 ) {
script_pushint(st,0);
@@ -5863,7 +5864,7 @@ BUILDIN(checkweight2)
// item is already in inventory, but there is still space for the requested amount
break;
case ADDITEM_NEW:
- if( itemdb_isstackable(nameid) ){// stackable
+ if( itemdb->isstackable(nameid) ){// stackable
amount2++;
if( slots < amount2 )
fail = 1;
@@ -5931,7 +5932,7 @@ BUILDIN(getitem)
if(!flag)
it.identify=1;
else
- it.identify=itemdb_isidentified2(item_data);
+ it.identify=itemdb->isidentified2(item_data);
if( script_hasdata(st,4) )
sd=iMap->id2sd(script_getnum(st,4)); // <Account ID>
@@ -5942,7 +5943,7 @@ BUILDIN(getitem)
return true;
//Check if it's stackable.
- if (!itemdb_isstackable(nameid))
+ if (!itemdb->isstackable(nameid))
get_count = 1;
else
get_count = amount;
@@ -5950,7 +5951,7 @@ BUILDIN(getitem)
for (i = 0; i < amount; i += get_count)
{
// if not pet egg
- if (!pet_create_egg(sd, nameid))
+ if (!pet->create_egg(sd, nameid))
{
if ((flag = pc->additem(sd, &it, get_count, LOG_TYPE_SCRIPT)))
{
@@ -6040,7 +6041,7 @@ BUILDIN(getitem2)
item_tmp.card[3]=(short)c4;
//Check if it's stackable.
- if (!itemdb_isstackable(nameid))
+ if (!itemdb->isstackable(nameid))
get_count = 1;
else
get_count = amount;
@@ -6048,7 +6049,7 @@ BUILDIN(getitem2)
for (i = 0; i < amount; i += get_count)
{
// if not pet egg
- if (!pet_create_egg(sd, nameid))
+ if (!pet->create_egg(sd, nameid))
{
if ((flag = pc->additem(sd, &item_tmp, get_count, LOG_TYPE_SCRIPT)))
{
@@ -6156,7 +6157,7 @@ BUILDIN(getnameditem)
}else
nameid = script->conv_num(st,data);
- if(!itemdb->exists(nameid)/* || itemdb_isstackable(nameid)*/)
+ if(!itemdb->exists(nameid)/* || itemdb->isstackable(nameid)*/)
{ //Even though named stackable items "could" be risky, they are required for certain quests.
script_pushint(st,0);
return true;
@@ -6274,7 +6275,7 @@ BUILDIN(makeitem)
if(!flag)
item_tmp.identify=1;
else
- item_tmp.identify=itemdb_isidentified2(item_data);
+ item_tmp.identify=itemdb->isidentified2(item_data);
iMap->addflooritem(&item_tmp,amount,m,x,y,0,0,0,0);
@@ -6664,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);
@@ -6730,19 +6731,19 @@ BUILDIN(getpartymember)
if(p->party.member[i].account_id){
switch (type) {
case 2:
- mapreg_setreg(reference_uid(script->add_str("$@partymemberaid"), j),p->party.member[i].account_id);
+ mapreg->setreg(reference_uid(script->add_str("$@partymemberaid"), j),p->party.member[i].account_id);
break;
case 1:
- mapreg_setreg(reference_uid(script->add_str("$@partymembercid"), j),p->party.member[i].char_id);
+ mapreg->setreg(reference_uid(script->add_str("$@partymembercid"), j),p->party.member[i].char_id);
break;
default:
- mapreg_setregstr(reference_uid(script->add_str("$@partymembername$"), j),p->party.member[i].name);
+ mapreg->setregstr(reference_uid(script->add_str("$@partymembername$"), j),p->party.member[i].name);
}
j++;
}
}
}
- mapreg_setreg(script->add_str("$@partymembercount"),j);
+ mapreg->setreg(script->add_str("$@partymembercount"),j);
return true;
}
@@ -8349,17 +8350,17 @@ BUILDIN(makepet)
if( sd == NULL )
return true;
- pet_id = search_petDB_index(id, PET_CLASS);
+ pet_id = pet->search_petDB_index(id, PET_CLASS);
if (pet_id < 0)
- pet_id = search_petDB_index(id, PET_EGG);
+ pet_id = pet->search_petDB_index(id, PET_EGG);
if (pet_id >= 0 && sd) {
- sd->catch_target_class = pet_db[pet_id].class_;
+ sd->catch_target_class = pet->db[pet_id].class_;
intif->create_pet(
sd->status.account_id, sd->status.char_id,
- (short)pet_db[pet_id].class_, (short)mob_db(pet_db[pet_id].class_)->lv,
- (short)pet_db[pet_id].EggID, 0, (short)pet_db[pet_id].intimate,
- 100, 0, 1, pet_db[pet_id].jname);
+ (short)pet->db[pet_id].class_, (short)mob->db(pet->db[pet_id].class_)->lv,
+ (short)pet->db[pet_id].EggID, 0, (short)pet->db[pet_id].intimate,
+ 100, 0, 1, pet->db[pet_id].jname);
}
return true;
@@ -8484,7 +8485,7 @@ BUILDIN(monster)
}
}
- if (class_ >= 0 && !mobdb_checkid(class_))
+ if (class_ >= 0 && !mob->db_checkid(class_))
{
ShowWarning("buildin_monster: Attempted to spawn non-existing monster class %d\n", class_);
return false;
@@ -8509,7 +8510,7 @@ BUILDIN(monster)
}
}
- mob_id = mob_once_spawn(sd, m, x, y, str, class_, amount, event, size, ai);
+ mob_id = mob->once_spawn(sd, m, x, y, str, class_, amount, event, size, ai);
script_pushint(st, mob_id);
return true;
}
@@ -8520,30 +8521,30 @@ BUILDIN(getmobdrops)
{
int class_ = script_getnum(st,2);
int i, j = 0;
- struct mob_db *mob;
+ struct mob_db *monster;
- if( !mobdb_checkid(class_) )
+ if( !mob->db_checkid(class_) )
{
script_pushint(st, 0);
return true;
}
- mob = mob_db(class_);
+ monster = mob->db(class_);
for( i = 0; i < MAX_MOB_DROP; i++ )
{
- if( mob->dropitem[i].nameid < 1 )
+ if( monster->dropitem[i].nameid < 1 )
continue;
- if( itemdb->exists(mob->dropitem[i].nameid) == NULL )
+ if( itemdb->exists(monster->dropitem[i].nameid) == NULL )
continue;
- mapreg_setreg(reference_uid(script->add_str("$@MobDrop_item"), j), mob->dropitem[i].nameid);
- mapreg_setreg(reference_uid(script->add_str("$@MobDrop_rate"), j), mob->dropitem[i].p);
+ mapreg->setreg(reference_uid(script->add_str("$@MobDrop_item"), j), monster->dropitem[i].nameid);
+ mapreg->setreg(reference_uid(script->add_str("$@MobDrop_rate"), j), monster->dropitem[i].p);
j++;
}
- mapreg_setreg(script->add_str("$@MobDrop_count"), j);
+ mapreg->setreg(script->add_str("$@MobDrop_count"), j);
script_pushint(st, 1);
return true;
@@ -8607,7 +8608,7 @@ BUILDIN(areamonster)
}
}
- mob_id = mob_once_spawn_area(sd, m, x0, y0, x1, y1, str, class_, amount, event, size, ai);
+ mob_id = mob->once_spawn_area(sd, m, x0, y0, x1, y1, str, class_, amount, event, size, ai);
script_pushint(st, mob_id);
return true;
@@ -8761,7 +8762,7 @@ BUILDIN(clone)
master_id = 0;
}
if (sd) //Return ID of newly crafted clone.
- script_pushint(st,mob_clone_spawn(sd, m, x, y, event, master_id, mode, flag, 1000*duration));
+ script_pushint(st,mob->clone_spawn(sd, m, x, y, event, master_id, mode, flag, 1000*duration));
else //Failed to create clone.
script_pushint(st,0);
@@ -8780,7 +8781,7 @@ BUILDIN(doevent)
}
check_event(st, event);
- npc_event(sd, event, 0);
+ npc->event(sd, event, 0);
return true;
}
/*==========================================
@@ -8789,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);
@@ -8802,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;
}
@@ -8871,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) )
@@ -8880,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);
@@ -8906,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;
}
/*==========================================
@@ -8919,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) )
@@ -8928,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);
@@ -8953,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;
}
/*==========================================
@@ -8965,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) )
@@ -8974,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);
@@ -8994,7 +8995,7 @@ BUILDIN(stopnpctimer)
if( flag ) //Detach
nd->u.scr.rid = 0;
- npc_timerevent_stop(nd);
+ npc->timerevent_stop(nd);
return true;
}
/*==========================================
@@ -9007,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);
@@ -9020,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 )
{
@@ -9050,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);
@@ -9061,7 +9062,7 @@ BUILDIN(setnpctimer)
return false;
}
- npc_settimerevent_tick(nd,tick);
+ npc->settimerevent_tick(nd,tick);
script_pushint(st,0);
return true;
}
@@ -9106,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);
@@ -9169,7 +9170,7 @@ BUILDIN(announce) {
if (fontColor)
intif->broadcast2(mes, (int)strlen(mes)+1, strtol(fontColor, (char **)NULL, 0), fontType, fontSize, fontAlign, fontY);
else
- intif->broadcast(mes, (int)strlen(mes)+1, flag&(BC_SOURCE_MASK|BC_TARGET_MASK));
+ intif->broadcast(mes, (int)strlen(mes)+1, flag&BC_COLOR_MASK);
}
return true;
}
@@ -9246,7 +9247,7 @@ BUILDIN(mapannounce)
return true;
iMap->foreachinmap(buildin_announce_sub, m, BL_PC,
- mes, strlen(mes)+1, flag&(BC_SOURCE_MASK|BC_TARGET_MASK), fontColor, fontType, fontSize, fontAlign, fontY);
+ mes, strlen(mes)+1, flag&BC_COLOR_MASK, fontColor, fontType, fontSize, fontAlign, fontY);
return true;
}
/*==========================================
@@ -9271,7 +9272,7 @@ BUILDIN(areaannounce)
return true;
iMap->foreachinarea(buildin_announce_sub, m, x0, y0, x1, y1, BL_PC,
- mes, strlen(mes)+1, flag&(BC_SOURCE_MASK|BC_TARGET_MASK), fontColor, fontType, fontSize, fontAlign, fontY);
+ mes, strlen(mes)+1, flag&BC_COLOR_MASK, fontColor, fontType, fontSize, fontAlign, fontY);
return true;
}
@@ -9465,7 +9466,7 @@ BUILDIN(enablenpc)
{
const char *str;
str=script_getstr(st,2);
- npc_enable(str,1);
+ npc->enable(str,1);
return true;
}
/*==========================================
@@ -9474,7 +9475,7 @@ BUILDIN(disablenpc)
{
const char *str;
str=script_getstr(st,2);
- npc_enable(str,0);
+ npc->enable(str,0);
return true;
}
@@ -9484,7 +9485,7 @@ BUILDIN(hideoffnpc)
{
const char *str;
str=script_getstr(st,2);
- npc_enable(str,2);
+ npc->enable(str,2);
return true;
}
/*==========================================
@@ -9493,7 +9494,7 @@ BUILDIN(hideonnpc)
{
const char *str;
str=script_getstr(st,2);
- npc_enable(str,4);
+ npc->enable(str,4);
return true;
}
@@ -9760,7 +9761,7 @@ BUILDIN(catchpet)
if( sd == NULL )
return true;
- pet_catch_process1(sd,pet_id);
+ pet->catch_process1(sd,pet_id);
return true;
}
@@ -10034,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;
}
@@ -10073,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 )
@@ -10091,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);
@@ -10110,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);
@@ -10129,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);
@@ -10160,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);
@@ -10239,7 +10240,7 @@ BUILDIN(warpwaitingpc)
pc->payzeny(sd, cd->zeny, LOG_TYPE_NPC, NULL);
}
- mapreg_setreg(reference_uid(script->add_str("$@warpwaitingpc"), i), sd->bl.id);
+ mapreg->setreg(reference_uid(script->add_str("$@warpwaitingpc"), i), sd->bl.id);
if( strcmp(map_name,"Random") == 0 )
pc->randomwarp(sd,CLR_TELEPORT);
@@ -10248,7 +10249,7 @@ BUILDIN(warpwaitingpc)
else
pc->setpos(sd, mapindex_name2id(map_name), x, y, CLR_OUTSIGHT);
}
- mapreg_setreg(script->add_str("$@warpwaitingpcnum"), i);
+ mapreg->setreg(script->add_str("$@warpwaitingpcnum"), i);
return true;
}
@@ -10489,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;
@@ -10745,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);
}
@@ -11371,7 +11372,7 @@ BUILDIN(strmobinfo)
int num=script_getnum(st,2);
int class_=script_getnum(st,3);
- if(!mobdb_checkid(class_))
+ if(!mob->db_checkid(class_))
{
if (num < 3) //requested a string
script_pushconststr(st,"");
@@ -11381,13 +11382,13 @@ BUILDIN(strmobinfo)
}
switch (num) {
- case 1: script_pushstrcopy(st,mob_db(class_)->name); break;
- case 2: script_pushstrcopy(st,mob_db(class_)->jname); break;
- case 3: script_pushint(st,mob_db(class_)->lv); break;
- case 4: script_pushint(st,mob_db(class_)->status.max_hp); break;
- case 5: script_pushint(st,mob_db(class_)->status.max_sp); break;
- case 6: script_pushint(st,mob_db(class_)->base_exp); break;
- case 7: script_pushint(st,mob_db(class_)->job_exp); break;
+ case 1: script_pushstrcopy(st,mob->db(class_)->name); break;
+ case 2: script_pushstrcopy(st,mob->db(class_)->jname); break;
+ case 3: script_pushint(st,mob->db(class_)->lv); break;
+ case 4: script_pushint(st,mob->db(class_)->status.max_hp); break;
+ case 5: script_pushint(st,mob->db(class_)->status.max_sp); break;
+ case 6: script_pushint(st,mob->db(class_)->base_exp); break;
+ case 7: script_pushint(st,mob->db(class_)->job_exp); break;
default:
script_pushint(st,0);
break;
@@ -11435,7 +11436,7 @@ BUILDIN(guardian)
}
check_event(st, evt);
- script_pushint(st, mob_spawn_guardian(map,x,y,str,class_,evt,guardian,has_index));
+ script_pushint(st, mob->spawn_guardian(map,x,y,str,class_,evt,guardian,has_index));
return true;
}
@@ -11694,7 +11695,7 @@ BUILDIN(petskillbonus)
if (pd->bonus)
{ //Clear previous bonus
if (pd->bonus->timer != INVALID_TIMER)
- iTimer->delete_timer(pd->bonus->timer, pet_skill_bonus_timer);
+ iTimer->delete_timer(pd->bonus->timer, pet->skill_bonus_timer);
} else //init
pd->bonus = (struct pet_bonus *) aMalloc(sizeof(struct pet_bonus));
@@ -11710,7 +11711,7 @@ BUILDIN(petskillbonus)
if (battle_config.pet_equip_required && pd->pet.equip == 0)
pd->bonus->timer = INVALID_TIMER;
else
- pd->bonus->timer = iTimer->add_timer(iTimer->gettick()+pd->bonus->delay*1000, pet_skill_bonus_timer, sd->bl.id, 0);
+ pd->bonus->timer = iTimer->add_timer(iTimer->gettick()+pd->bonus->delay*1000, pet->skill_bonus_timer, sd->bl.id, 0);
return true;
}
@@ -11737,7 +11738,7 @@ BUILDIN(petloot)
pd = sd->pd;
if (pd->loot != NULL)
{ //Release whatever was there already and reallocate memory
- pet_lootitem_drop(pd, pd->msd);
+ pet->lootitem_drop(pd, pd->msd);
aFree(pd->loot->item);
}
else
@@ -11827,7 +11828,7 @@ BUILDIN(disguise)
id = script_getnum(st,2);
- if (mobdb_checkid(id) || npcdb_checkid(id)) {
+ if (mob->db_checkid(id) || npcdb_checkid(id)) {
pc->disguise(sd, id);
script_pushint(st,id);
} else
@@ -11878,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);
@@ -12064,7 +12065,7 @@ BUILDIN(petrecovery)
if (pd->recovery)
{ //Halt previous bonus
if (pd->recovery->timer != INVALID_TIMER)
- iTimer->delete_timer(pd->recovery->timer, pet_recovery_timer);
+ iTimer->delete_timer(pd->recovery->timer, pet->recovery_timer);
} else //Init
pd->recovery = (struct pet_recovery *)aMalloc(sizeof(struct pet_recovery));
@@ -12092,9 +12093,9 @@ BUILDIN(petheal)
if (pd->s_skill->timer != INVALID_TIMER)
{
if (pd->s_skill->id)
- iTimer->delete_timer(pd->s_skill->timer, pet_skill_support_timer);
+ iTimer->delete_timer(pd->s_skill->timer, pet->skill_support_timer);
else
- iTimer->delete_timer(pd->s_skill->timer, pet_heal_timer);
+ iTimer->delete_timer(pd->s_skill->timer, pet->heal_timer);
}
} else //init memory
pd->s_skill = (struct pet_skill_support *) aMalloc(sizeof(struct pet_skill_support));
@@ -12110,7 +12111,7 @@ BUILDIN(petheal)
if (battle_config.pet_equip_required && pd->pet.equip == 0)
pd->s_skill->timer = INVALID_TIMER;
else
- pd->s_skill->timer = iTimer->add_timer(iTimer->gettick()+pd->s_skill->delay*1000,pet_heal_timer,sd->bl.id,0);
+ pd->s_skill->timer = iTimer->add_timer(iTimer->gettick()+pd->s_skill->delay*1000,pet->heal_timer,sd->bl.id,0);
return true;
}
@@ -12186,9 +12187,9 @@ BUILDIN(petskillsupport)
if (pd->s_skill->timer != INVALID_TIMER)
{
if (pd->s_skill->id)
- iTimer->delete_timer(pd->s_skill->timer, pet_skill_support_timer);
+ iTimer->delete_timer(pd->s_skill->timer, pet->skill_support_timer);
else
- iTimer->delete_timer(pd->s_skill->timer, pet_heal_timer);
+ iTimer->delete_timer(pd->s_skill->timer, pet->heal_timer);
}
} else //init memory
pd->s_skill = (struct pet_skill_support *) aMalloc(sizeof(struct pet_skill_support));
@@ -12203,7 +12204,7 @@ BUILDIN(petskillsupport)
if (battle_config.pet_equip_required && pd->pet.equip == 0)
pd->s_skill->timer = INVALID_TIMER;
else
- pd->s_skill->timer = iTimer->add_timer(iTimer->gettick()+pd->s_skill->delay*1000,pet_skill_support_timer,sd->bl.id,0);
+ pd->s_skill->timer = iTimer->add_timer(iTimer->gettick()+pd->s_skill->delay*1000,pet->skill_support_timer,sd->bl.id,0);
return true;
}
@@ -12260,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);
}
@@ -12569,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;
}
@@ -12634,7 +12635,7 @@ BUILDIN(npcspeed) {
nd = (struct npc_data *)iMap->id2bl(st->oid);
if( nd ) {
- unit_bl2ud2(&nd->bl); // ensure nd->ud is safe to edit
+ unit->bl2ud2(&nd->bl); // ensure nd->ud is safe to edit
nd->speed = speed;
nd->ud->state.speed_changed = 1;
}
@@ -12650,13 +12651,13 @@ BUILDIN(npcwalkto) {
y=script_getnum(st,3);
if( nd ) {
- unit_bl2ud2(&nd->bl); // ensure nd->ud is safe to edit
+ unit->bl2ud2(&nd->bl); // ensure nd->ud is safe to edit
if (!nd->status.hp) {
status_calc_npc(nd, true);
} else {
status_calc_npc(nd, false);
}
- unit_walktoxy(&nd->bl,x,y,0);
+ unit->walktoxy(&nd->bl,x,y,0);
}
return true;
@@ -12666,8 +12667,8 @@ BUILDIN(npcstop) {
struct npc_data *nd = (struct npc_data *)iMap->id2bl(st->oid);
if( nd ) {
- unit_bl2ud2(&nd->bl); // ensure nd->ud is safe to edit
- unit_stop_walking(&nd->bl,1|4);
+ unit->bl2ud2(&nd->bl); // ensure nd->ud is safe to edit
+ unit->stop_walking(&nd->bl,1|4);
}
return true;
@@ -12796,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?
@@ -12931,14 +12932,14 @@ BUILDIN(summon)
clif->skill_poseffect(&sd->bl,AM_CALLHOMUN,1,sd->bl.x,sd->bl.y,tick);
- md = mob_once_spawn_sub(&sd->bl, sd->bl.m, sd->bl.x, sd->bl.y, str, _class, event, SZ_SMALL, AI_NONE);
+ md = mob->once_spawn_sub(&sd->bl, sd->bl.m, sd->bl.x, sd->bl.y, str, _class, event, SZ_SMALL, AI_NONE);
if (md) {
md->master_id=sd->bl.id;
md->special_state.ai = AI_ATTACK;
if( md->deletetimer != INVALID_TIMER )
- iTimer->delete_timer(md->deletetimer, mob_timer_delete);
- md->deletetimer = iTimer->add_timer(tick+(timeout>0?timeout*1000:60000),mob_timer_delete,md->bl.id,0);
- mob_spawn (md); //Now it is ready for spawning.
+ iTimer->delete_timer(md->deletetimer, mob->timer_delete);
+ md->deletetimer = iTimer->add_timer(tick+(timeout>0?timeout*1000:60000),mob->timer_delete,md->bl.id,0);
+ mob->spawn (md); //Now it is ready for spawning.
clif->specialeffect(&md->bl,344,AREA);
sc_start4(&md->bl, SC_MODECHANGE, 100, 1, 0, MD_AGGRESSIVE, 0, 60000);
}
@@ -13219,7 +13220,7 @@ BUILDIN(autoequip)
return false;
}
- if( !itemdb_isequip2(item_data) )
+ if( !itemdb->isequip2(item_data) )
{
ShowError("buildin_autoequip: Item '%d' cannot be equipped.\n", nameid);
return false;
@@ -14082,7 +14083,7 @@ BUILDIN(setnpcdisplay)
return false;
}
- nd = npc_name2id(name);
+ nd = npc->name2id(name);
if( nd == NULL )
{// not found
script_pushint(st,1);
@@ -14091,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;
@@ -14099,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);
@@ -14383,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);
@@ -14398,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
}
}
@@ -14414,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;
@@ -14443,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;
@@ -14472,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;
@@ -14511,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) )
@@ -14611,11 +14612,11 @@ BUILDIN(setitemscript)
*------------------------------------------*/
BUILDIN(getmonsterinfo)
{
- struct mob_db *mob;
+ struct mob_db *monster;
int mob_id;
mob_id = script_getnum(st,2);
- if (!mobdb_checkid(mob_id)) {
+ if (!mob->db_checkid(mob_id)) {
ShowError("buildin_getmonsterinfo: Wrong Monster ID: %i\n", mob_id);
if ( !script_getnum(st,3) ) //requested a string
script_pushconststr(st,"null");
@@ -14623,31 +14624,31 @@ BUILDIN(getmonsterinfo)
script_pushint(st,-1);
return -1;
}
- mob = mob_db(mob_id);
+ monster = mob->db(mob_id);
switch ( script_getnum(st,3) ) {
- case 0: script_pushstrcopy(st,mob->jname); break;
- case 1: script_pushint(st,mob->lv); break;
- case 2: script_pushint(st,mob->status.max_hp); break;
- case 3: script_pushint(st,mob->base_exp); break;
- case 4: script_pushint(st,mob->job_exp); break;
- case 5: script_pushint(st,mob->status.rhw.atk); break;
- case 6: script_pushint(st,mob->status.rhw.atk2); break;
- case 7: script_pushint(st,mob->status.def); break;
- case 8: script_pushint(st,mob->status.mdef); break;
- case 9: script_pushint(st,mob->status.str); break;
- case 10: script_pushint(st,mob->status.agi); break;
- case 11: script_pushint(st,mob->status.vit); break;
- case 12: script_pushint(st,mob->status.int_); break;
- case 13: script_pushint(st,mob->status.dex); break;
- case 14: script_pushint(st,mob->status.luk); break;
- case 15: script_pushint(st,mob->status.rhw.range); break;
- case 16: script_pushint(st,mob->range2); break;
- case 17: script_pushint(st,mob->range3); break;
- case 18: script_pushint(st,mob->status.size); break;
- case 19: script_pushint(st,mob->status.race); break;
- case 20: script_pushint(st,mob->status.def_ele); break;
- case 21: script_pushint(st,mob->status.mode); break;
- case 22: script_pushint(st,mob->mexp); break;
+ case 0: script_pushstrcopy(st,monster->jname); break;
+ case 1: script_pushint(st,monster->lv); break;
+ case 2: script_pushint(st,monster->status.max_hp); break;
+ case 3: script_pushint(st,monster->base_exp); break;
+ case 4: script_pushint(st,monster->job_exp); break;
+ case 5: script_pushint(st,monster->status.rhw.atk); break;
+ case 6: script_pushint(st,monster->status.rhw.atk2); break;
+ case 7: script_pushint(st,monster->status.def); break;
+ case 8: script_pushint(st,monster->status.mdef); break;
+ case 9: script_pushint(st,monster->status.str); break;
+ case 10: script_pushint(st,monster->status.agi); break;
+ case 11: script_pushint(st,monster->status.vit); break;
+ case 12: script_pushint(st,monster->status.int_); break;
+ case 13: script_pushint(st,monster->status.dex); break;
+ case 14: script_pushint(st,monster->status.luk); break;
+ case 15: script_pushint(st,monster->status.rhw.range); break;
+ case 16: script_pushint(st,monster->range2); break;
+ case 17: script_pushint(st,monster->range3); break;
+ case 18: script_pushint(st,monster->status.size); break;
+ case 19: script_pushint(st,monster->status.race); break;
+ case 20: script_pushint(st,monster->status.def_ele); break;
+ case 21: script_pushint(st,monster->status.mode); break;
+ case 22: script_pushint(st,monster->mexp); break;
default: script_pushint(st,-1); //wrong Index
}
return true;
@@ -14917,15 +14918,15 @@ BUILDIN(unitwalk) {
}
if( bl->type == BL_NPC ) {
- unit_bl2ud2(bl); // ensure the ((TBL_NPC*)bl)->ud is safe to edit
+ unit->bl2ud2(bl); // ensure the ((TBL_NPC*)bl)->ud is safe to edit
}
if( script_hasdata(st,4) ) {
int x = script_getnum(st,3);
int y = script_getnum(st,4);
- script_pushint(st, unit_walktoxy(bl,x,y,0));// We'll use harder calculations.
+ script_pushint(st, unit->walktoxy(bl,x,y,0));// We'll use harder calculations.
} else {
int map_id = script_getnum(st,3);
- script_pushint(st, unit_walktobl(bl,iMap->id2bl(map_id),65025,1));
+ script_pushint(st, unit->walktobl(bl,iMap->id2bl(map_id),65025,1));
}
return true;
@@ -14971,8 +14972,8 @@ BUILDIN(unitwarp) {
map = iMap->mapname2mapid(mapname);
if( map >= 0 && bl != NULL ) {
- unit_bl2ud2(bl); // ensure ((TBL_NPC*)bl)->ud is safe to edit
- script_pushint(st, unit_warp(bl,map,x,y,CLR_OUTSIGHT));
+ unit->bl2ud2(bl); // ensure ((TBL_NPC*)bl)->ud is safe to edit
+ script_pushint(st, unit->warp(bl,map,x,y,CLR_OUTSIGHT));
} else {
script_pushint(st, 0);
}
@@ -15038,7 +15039,7 @@ BUILDIN(unitattack)
script_pushint(st, 0);
return false;
}
- script_pushint(st, unit_walktobl(unit_bl, target_bl, 65025, 2));
+ script_pushint(st, unit->walktobl(unit_bl, target_bl, 65025, 2));
return true;
}
@@ -15054,9 +15055,9 @@ BUILDIN(unitstop) {
bl = iMap->id2bl(unit_id);
if( bl != NULL )
{
- unit_bl2ud2(bl); // ensure ((TBL_NPC*)bl)->ud is safe to edit
- unit_stop_attack(bl);
- unit_stop_walking(bl,4);
+ unit->bl2ud2(bl); // ensure ((TBL_NPC*)bl)->ud is safe to edit
+ unit->stop_attack(bl);
+ unit->stop_walking(bl,4);
if( bl->type == BL_MOB )
((TBL_MOB*)bl)->target_id = 0;
}
@@ -15138,7 +15139,7 @@ BUILDIN(unitskilluseid)
status_calc_npc(((TBL_NPC*)bl), false);
}
}
- unit_skilluse_id(bl, target_id, skill_id, skill_lv);
+ unit->skilluse_id(bl, target_id, skill_id, skill_lv);
}
return true;
@@ -15173,7 +15174,7 @@ BUILDIN(unitskillusepos)
status_calc_npc(((TBL_NPC*)bl), false);
}
}
- unit_skilluse_pos(bl, skill_x, skill_y, skill_id, skill_lv);
+ unit->skilluse_pos(bl, skill_x, skill_y, skill_id, skill_lv);
}
return true;
@@ -15245,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;
}
@@ -15308,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));
@@ -15644,7 +15645,7 @@ BUILDIN(setquest)
struct map_session_data *sd = script_rid2sd(st);
nullpo_ret(sd);
- quest_add(sd, script_getnum(st, 2));
+ quest->add(sd, script_getnum(st, 2));
return true;
}
@@ -15653,7 +15654,7 @@ BUILDIN(erasequest)
struct map_session_data *sd = script_rid2sd(st);
nullpo_ret(sd);
- quest_delete(sd, script_getnum(st, 2));
+ quest->delete(sd, script_getnum(st, 2));
return true;
}
@@ -15662,7 +15663,7 @@ BUILDIN(completequest)
struct map_session_data *sd = script_rid2sd(st);
nullpo_ret(sd);
- quest_update_status(sd, script_getnum(st, 2), Q_COMPLETE);
+ quest->update_status(sd, script_getnum(st, 2), Q_COMPLETE);
return true;
}
@@ -15671,7 +15672,7 @@ BUILDIN(changequest)
struct map_session_data *sd = script_rid2sd(st);
nullpo_ret(sd);
- quest_change(sd, script_getnum(st, 2),script_getnum(st, 3));
+ quest->change(sd, script_getnum(st, 2),script_getnum(st, 3));
return true;
}
@@ -15685,7 +15686,7 @@ BUILDIN(checkquest)
if( script_hasdata(st, 3) )
type = (quest_check_type)script_getnum(st, 3);
- script_pushint(st, quest_check(sd, script_getnum(st, 2), type));
+ script_pushint(st, quest->check(sd, script_getnum(st, 2), type));
return true;
}
@@ -15720,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);
@@ -15746,7 +15747,7 @@ BUILDIN(waitingroom2bg)
ev = script_getstr(st,5); // Logout Event
dev = script_getstr(st,6); // Die Event
- if( (bg_id = bg_create(mapindex, x, y, ev, dev)) == 0 )
+ if( (bg_id = bg->create(mapindex, x, y, ev, dev)) == 0 )
{ // Creation failed
script_pushint(st,0);
return true;
@@ -15755,13 +15756,13 @@ BUILDIN(waitingroom2bg)
n = cd->users;
for( i = 0; i < n && i < MAX_BG_MEMBERS; i++ )
{
- if( (sd = cd->usersd[i]) != NULL && bg_team_join(bg_id, sd) )
- mapreg_setreg(reference_uid(script->add_str("$@arenamembers"), i), sd->bl.id);
+ if( (sd = cd->usersd[i]) != NULL && bg->team_join(bg_id, sd) )
+ mapreg->setreg(reference_uid(script->add_str("$@arenamembers"), i), sd->bl.id);
else
- mapreg_setreg(reference_uid(script->add_str("$@arenamembers"), i), 0);
+ mapreg->setreg(reference_uid(script->add_str("$@arenamembers"), i), 0);
}
- mapreg_setreg(script->add_str("$@arenamembersnum"), i);
+ mapreg->setreg(script->add_str("$@arenamembersnum"), i);
script_pushint(st,bg_id);
return true;
}
@@ -15781,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;
@@ -15789,7 +15790,7 @@ BUILDIN(waitingroom2bg_single)
if( (sd = cd->usersd[0]) == NULL )
return true;
- if( bg_team_join(bg_id, sd) )
+ if( bg->team_join(bg_id, sd) )
{
pc->setpos(sd, mapindex, x, y, CLR_TELEPORT);
script_pushint(st,1);
@@ -15802,15 +15803,15 @@ BUILDIN(waitingroom2bg_single)
BUILDIN(bg_team_setxy)
{
- struct battleground_data *bg;
+ struct battleground_data *bgd;
int bg_id;
bg_id = script_getnum(st,2);
- if( (bg = bg_team_search(bg_id)) == NULL )
+ if( (bgd = bg->team_search(bg_id)) == NULL )
return true;
- bg->x = script_getnum(st,3);
- bg->y = script_getnum(st,4);
+ bgd->x = script_getnum(st,3);
+ bgd->y = script_getnum(st,4);
return true;
}
@@ -15825,7 +15826,7 @@ BUILDIN(bg_warp)
return true; // Invalid Map
x = script_getnum(st,4);
y = script_getnum(st,5);
- bg_team_warp(bg_id, mapindex, x, y);
+ bg->team_warp(bg_id, mapindex, x, y);
return true;
}
@@ -15842,7 +15843,7 @@ BUILDIN(bg_monster)
class_ = script_getnum(st,7);
if( script_hasdata(st,8) ) evt = script_getstr(st,8);
check_event(st, evt);
- script_pushint(st, mob_spawn_bg(map,x,y,str,class_,evt,bg_id));
+ script_pushint(st, mob->spawn_bg(map,x,y,str,class_,evt,bg_id));
return true;
}
@@ -15872,14 +15873,14 @@ BUILDIN(bg_leave)
if( sd == NULL || !sd->bg_id )
return true;
- bg_team_leave(sd,0);
+ bg->team_leave(sd,0);
return true;
}
BUILDIN(bg_destroy)
{
int bg_id = script_getnum(st,2);
- bg_team_delete(bg_id);
+ bg->team_delete(bg_id);
return true;
}
@@ -15889,13 +15890,13 @@ BUILDIN(bg_getareausers)
int16 m, x0, y0, x1, y1;
int bg_id;
int i = 0, c = 0;
- struct battleground_data *bg = NULL;
+ struct battleground_data *bgd = NULL;
struct map_session_data *sd;
bg_id = script_getnum(st,2);
str = script_getstr(st,3);
- if( (bg = bg_team_search(bg_id)) == NULL || (m = iMap->mapname2mapid(str)) < 0 )
+ if( (bgd = bg->team_search(bg_id)) == NULL || (m = iMap->mapname2mapid(str)) < 0 )
{
script_pushint(st,0);
return true;
@@ -15908,7 +15909,7 @@ BUILDIN(bg_getareausers)
for( i = 0; i < MAX_BG_MEMBERS; i++ )
{
- if( (sd = bg->members[i].sd) == NULL )
+ if( (sd = bgd->members[i].sd) == NULL )
continue;
if( sd->bl.m != m || sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1 )
continue;
@@ -15937,11 +15938,11 @@ BUILDIN(bg_updatescore)
BUILDIN(bg_get_data)
{
- struct battleground_data *bg;
+ struct battleground_data *bgd;
int bg_id = script_getnum(st,2),
type = script_getnum(st,3);
- if( (bg = bg_team_search(bg_id)) == NULL )
+ if( (bgd = bg->team_search(bg_id)) == NULL )
{
script_pushint(st,0);
return true;
@@ -15949,7 +15950,7 @@ BUILDIN(bg_get_data)
switch( type )
{
- case 0: script_pushint(st, bg->count); break;
+ case 0: script_pushint(st, bgd->count); break;
default:
ShowError("script:bg_get_data: unknown data identifier %d\n", type);
break;
@@ -16138,7 +16139,7 @@ BUILDIN(instance_announce) {
for( i = 0; i < instances[instance_id].num_map; i++ )
iMap->foreachinmap(buildin_announce_sub, instances[instance_id].map[i], BL_PC,
- mes, strlen(mes)+1, flag&(BC_SOURCE_MASK|BC_TARGET_MASK), fontColor, fontType, fontSize, fontAlign, fontY);
+ mes, strlen(mes)+1, flag&BC_COLOR_MASK, fontColor, fontType, fontSize, fontAlign, fontY);
return true;
}
@@ -16154,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);
@@ -16372,12 +16373,12 @@ static int buildin_mobuseskill_sub(struct block_list *bl,va_list ap)
return 0;
if( md->ud.skilltimer != INVALID_TIMER ) // Cancel the casting skill.
- unit_skillcastcancel(bl,0);
+ unit->skillcastcancel(bl,0);
if( skill->get_casttype(skill_id) == CAST_GROUND )
- unit_skilluse_pos2(&md->bl, tbl->x, tbl->y, skill_id, skill_lv, casttime, cancel);
+ unit->skilluse_pos2(&md->bl, tbl->x, tbl->y, skill_id, skill_lv, casttime, cancel);
else
- unit_skilluse_id2(&md->bl, tbl->id, skill_id, skill_lv, casttime, cancel);
+ unit->skilluse_id2(&md->bl, tbl->id, skill_id, skill_lv, casttime, cancel);
clif->emotion(&md->bl, emotion);
@@ -16474,7 +16475,7 @@ BUILDIN(pushpc)
dx = dirx[dir];
dy = diry[dir];
- unit_blown(&sd->bl, dx, dy, cells, 0);
+ unit->blown(&sd->bl, dx, dy, cells, 0);
return true;
}
@@ -17036,16 +17037,16 @@ BUILDIN(getrandgroupitem) {
nameid = itemdb->group_item(data->group);
it.nameid = nameid;
- it.identify = itemdb_isidentified(nameid);
+ it.identify = itemdb->isidentified(nameid);
- if (!itemdb_isstackable(nameid))
+ if (!itemdb->isstackable(nameid))
get_count = 1;
else
get_count = count;
for (i = 0; i < count; i += get_count) {
// if not pet egg
- if (!pet_create_egg(sd, nameid)) {
+ if (!pet->create_egg(sd, nameid)) {
if ((flag = pc->additem(sd, &it, get_count, LOG_TYPE_SCRIPT))) {
clif->additem(sd, 0, 0, flag);
if( pc->candrop(sd,&it) )
@@ -17139,9 +17140,9 @@ BUILDIN(npcskill)
}
if (skill->get_inf(skill_id)&INF_GROUND_SKILL) {
- unit_skilluse_pos(&nd->bl, sd->bl.x, sd->bl.y, skill_id, skill_level);
+ unit->skilluse_pos(&nd->bl, sd->bl.x, sd->bl.y, skill_id, skill_level);
} else {
- unit_skilluse_id(&nd->bl, sd->bl.id, skill_id, skill_level);
+ unit->skilluse_id(&nd->bl, sd->bl.id, skill_id, skill_level);
}
return true;
@@ -17544,7 +17545,7 @@ BUILDIN(bg_create_team) {
x = script_getnum(st,3);
y = script_getnum(st,4);
- if( (bg_id = bg_create(mapindex, x, y, ev, dev)) == 0 ) { // Creation failed
+ if( (bg_id = bg->create(mapindex, x, y, ev, dev)) == 0 ) { // Creation failed
script_pushint(st,-1);
} else
script_pushint(st,bg_id);
@@ -17567,7 +17568,7 @@ BUILDIN(bg_join_team) {
if( !sd )
script_pushint(st, 1);
else
- script_pushint(st,bg_team_join(team_id, sd)?0:1);
+ script_pushint(st,bg->team_join(team_id, sd)?0:1);
return true;
}
diff --git a/src/map/skill.c b/src/map/skill.c
index d9df0b869..6ec9d2fec 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);
@@ -863,7 +863,7 @@ int skill_additional_effect (struct block_list* src, struct block_list *bl, uint
break;
case WZ_FIREPILLAR:
- unit_set_walkdelay(bl, tick, skill->get_time2(skill_id, skill_lv), 1);
+ unit->set_walkdelay(bl, tick, skill->get_time2(skill_id, skill_lv), 1);
break;
case MG_FROSTDIVER:
@@ -1447,7 +1447,7 @@ int skill_additional_effect (struct block_list* src, struct block_list *bl, uint
}
if( sd && sd->ed && sc && !iStatus->isdead(bl) && !skill_id ){
- struct unit_data *ud = unit_bl2ud(src);
+ struct unit_data *ud = unit->bl2ud(src);
if( sc->data[SC_WILD_STORM_OPTION] )
temp = sc->data[SC_WILD_STORM_OPTION]->val2;
@@ -1559,7 +1559,7 @@ int skill_additional_effect (struct block_list* src, struct block_list *bl, uint
}
sd->state.autocast = 0;
//Set canact delay. [Skotlex]
- ud = unit_bl2ud(src);
+ ud = unit->bl2ud(src);
if (ud) {
rate = skill->delay_fix(src, temp, skill_lv);
if (DIFF_TICK(ud->canact_tick, tick + rate) < 0){
@@ -1594,21 +1594,21 @@ int skill_additional_effect (struct block_list* src, struct block_list *bl, uint
dstmd && !(tstatus->mode&MD_BOSS) &&
(rnd()%10000 < sd->bonus.classchange))
{
- struct mob_db *mob;
+ struct mob_db *monster;
int class_;
temp = 0;
do {
do {
class_ = rnd() % MAX_MOB_DB;
- } while (!mobdb_checkid(class_));
+ } while (!mob->db_checkid(class_));
rate = rnd() % 1000000;
- mob = mob_db(class_);
+ monster = mob->db(class_);
} while (
- (mob->status.mode&(MD_BOSS|MD_PLANT) || mob->summonper[0] <= rate) &&
+ (monster->status.mode&(MD_BOSS|MD_PLANT) || monster->summonper[0] <= rate) &&
(temp++) < 2000);
if (temp < 2000)
- mob_class_change(dstmd,class_);
+ mob->class_change(dstmd,class_);
}
return 0;
@@ -1900,7 +1900,7 @@ int skill_counter_additional_effect (struct block_list* src, struct block_list *
}
dstsd->state.autocast = 0;
//Set canact delay. [Skotlex]
- ud = unit_bl2ud(bl);
+ ud = unit->bl2ud(bl);
if (ud) {
rate = skill->delay_fix(bl, skill_id, skill_lv);
if (DIFF_TICK(ud->canact_tick, tick + rate) < 0){
@@ -2103,7 +2103,7 @@ int skill_blown(struct block_list* src, struct block_list* target, int count, in
dy = -diry[dir];
}
- return unit_blown(target, dx, dy, count, flag); // send over the proper flag
+ return unit->blown(target, dx, dy, count, flag); // send over the proper flag
}
@@ -2338,7 +2338,7 @@ int skill_attack (int attack_type, struct block_list* src, struct block_list *ds
sce->timer = iTimer->add_timer(tick+sce->val4, iStatus->change_timer, src->id, SC_COMBOATTACK);
break;
}
- unit_cancel_combo(src); // Cancel combo wait
+ unit->cancel_combo(src); // Cancel combo wait
break;
default:
if( src == dsrc ) // Ground skills are exceptions. [Inkfish]
@@ -2617,7 +2617,7 @@ int skill_attack (int attack_type, struct block_list* src, struct block_list *ds
if (dmg.dmg_lv >= ATK_MISS && (type = skill->get_walkdelay(skill_id, skill_lv)) > 0) {
//Skills with can't walk delay also stop normal attacking for that
//duration when the attack connects. [Skotlex]
- struct unit_data *ud = unit_bl2ud(src);
+ struct unit_data *ud = unit->bl2ud(src);
if (ud && DIFF_TICK(ud->attackabletime, tick + type) < 0)
ud->attackabletime = tick + type;
}
@@ -2650,7 +2650,7 @@ int skill_attack (int attack_type, struct block_list* src, struct block_list *ds
case SR_KNUCKLEARROW:
case GN_WALLOFTHORN:
case EL_FIRE_MANTLE:
- dir = unit_getdir(bl);// backwards
+ dir = unit->getdir(bl);// backwards
break;
// This ensures the storm randomly pushes instead of exactly a cell backwards per official mechanics.
case WZ_STORMGUST:
@@ -2688,7 +2688,7 @@ int skill_attack (int attack_type, struct block_list* src, struct block_list *ds
}
break;
case GN_WALLOFTHORN:
- unit_stop_walking(bl,1);
+ unit->stop_walking(bl,1);
skill->blown(dsrc,bl,dmg.blewcount,dir, 0x2 );
clif->fixpos(bl);
break;
@@ -3037,7 +3037,7 @@ int skill_check_condition_mercenary(struct block_list *bl, int skill_id, int lv,
if( !type )
switch( state ) {
case ST_MOVE_ENABLE:
- if( !unit_can_move(bl) ) {
+ if( !unit->can_move(bl) ) {
clif->skill_fail(sd, skill_id, USESKILL_FAIL_LEVEL, 0);
return 0;
}
@@ -3086,7 +3086,7 @@ int skill_area_sub_count (struct block_list *src, struct block_list *target, uin
*------------------------------------------*/
int skill_timerskill(int tid, unsigned int tick, int id, intptr_t data) {
struct block_list *src = iMap->id2bl(id),*target;
- struct unit_data *ud = unit_bl2ud(src);
+ struct unit_data *ud = unit->bl2ud(src);
struct skill_timerskill *skl;
int range;
@@ -3116,11 +3116,11 @@ int skill_timerskill(int tid, unsigned int tick, int id, intptr_t data) {
switch(skl->skill_id) {
case RG_INTIMIDATE:
- if (unit_warp(src,-1,-1,-1,CLR_TELEPORT) == 0) {
+ if (unit->warp(src,-1,-1,-1,CLR_TELEPORT) == 0) {
short x,y;
iMap->search_freecell(src, 0, &x, &y, 1, 1, 0);
if (target != src && !iStatus->isdead(target))
- unit_warp(target, -1, x, y, CLR_TELEPORT);
+ unit->warp(target, -1, x, y, CLR_TELEPORT);
}
break;
case BA_FROSTJOKER:
@@ -3193,11 +3193,11 @@ int skill_timerskill(int tid, unsigned int tick, int id, intptr_t data) {
break;
case SC_FATALMENACE:
if( src == target ) // Casters Part
- unit_warp(src, -1, skl->x, skl->y, 3);
+ unit->warp(src, -1, skl->x, skl->y, 3);
else { // Target's Part
short x = skl->x, y = skl->y;
iMap->search_freecell(NULL, target->m, &x, &y, 2, 2, 1);
- unit_warp(target,-1,x,y,3);
+ unit->warp(target,-1,x,y,3);
}
break;
case LG_MOONSLASHER:
@@ -3241,7 +3241,7 @@ int skill_timerskill(int tid, unsigned int tick, int id, intptr_t data) {
case SC_ESCAPE:
if( skl->type < 4+skl->skill_lv ){
clif->skill_damage(src,src,tick,0,0,-30000,1,skl->skill_id,skl->skill_lv,5);
- skill->blown(src,src,1,unit_getdir(src),0);
+ skill->blown(src,src,1,unit->getdir(src),0);
skill->addtimerskill(src,tick+80,src->id,0,0,skl->skill_id,skl->skill_lv,skl->type+1,0);
}
break;
@@ -3266,12 +3266,12 @@ int skill_timerskill(int tid, unsigned int tick, int id, intptr_t data) {
case WZ_METEOR:
if( skl->type >= 0 ) {
int x = skl->type>>16, y = skl->type&0xFFFF;
- if( path_search_long(NULL, src->m, src->x, src->y, x, y, CELL_CHKWALL) )
+ if( path->search_long(NULL, src->m, src->x, src->y, x, y, CELL_CHKWALL) )
skill->unitsetting(src,skl->skill_id,skl->skill_lv,x,y,skl->flag);
- if( path_search_long(NULL, src->m, src->x, src->y, skl->x, skl->y, CELL_CHKWALL) )
+ if( path->search_long(NULL, src->m, src->x, src->y, skl->x, skl->y, CELL_CHKWALL) )
clif->skill_poseffect(src,skl->skill_id,skl->skill_lv,skl->x,skl->y,tick);
}
- else if( path_search_long(NULL, src->m, src->x, src->y, skl->x, skl->y, CELL_CHKWALL) )
+ else if( path->search_long(NULL, src->m, src->x, src->y, skl->x, skl->y, CELL_CHKWALL) )
skill->unitsetting(src,skl->skill_id,skl->skill_lv,skl->x,skl->y,skl->flag);
break;
case GN_CRAZYWEED_ATK: {
@@ -3300,7 +3300,7 @@ int skill_addtimerskill (struct block_list *src, unsigned int tick, int target,
nullpo_retr(1, src);
if (src->prev == NULL)
return 0;
- ud = unit_bl2ud(src);
+ ud = unit->bl2ud(src);
nullpo_retr(1, ud);
ARR_FIND( 0, MAX_SKILLTIMERSKILL, i, ud->skilltimerskill[i] == 0 );
@@ -3328,7 +3328,7 @@ int skill_cleartimerskill (struct block_list *src)
int i;
struct unit_data *ud;
nullpo_ret(src);
- ud = unit_bl2ud(src);
+ ud = unit->bl2ud(src);
nullpo_ret(ud);
for(i=0;i<MAX_SKILLTIMERSKILL;i++) {
@@ -3574,21 +3574,21 @@ int skill_castend_damage_id (struct block_list* src, struct block_list *bl, uint
break;
case KN_CHARGEATK: {
- bool path = path_search_long(NULL, src->m, src->x, src->y, bl->x, bl->y,CELL_CHKWALL);
+ bool path_exists = path->search_long(NULL, src->m, src->x, src->y, bl->x, bl->y,CELL_CHKWALL);
unsigned int dist = distance_bl(src, bl);
uint8 dir = iMap->calc_dir(bl, src->x, src->y);
// teleport to target (if not on WoE grounds)
- if( !map_flag_gvg2(src->m) && !map[src->m].flag.battleground && unit_movepos(src, bl->x, bl->y, 0, 1) )
+ if( !map_flag_gvg2(src->m) && !map[src->m].flag.battleground && unit->movepos(src, bl->x, bl->y, 0, 1) )
clif->slide(src, bl->x, bl->y);
// cause damage and knockback if the path to target was a straight one
- if( path ) {
+ if( path_exists ) {
skill->attack(BF_WEAPON, src, src, bl, skill_id, skill_lv, tick, dist);
skill->blown(src, bl, dist, dir, 0);
//HACK: since knockback officially defaults to the left, the client also turns to the left... therefore,
// make the caster look in the direction of the target
- unit_setdir(src, (dir+4)%8);
+ unit->setdir(src, (dir+4)%8);
}
}
@@ -3626,12 +3626,12 @@ int skill_castend_damage_id (struct block_list* src, struct block_list *bl, uint
case RG_BACKSTAP:
{
- uint8 dir = iMap->calc_dir(src, bl->x, bl->y), t_dir = unit_getdir(bl);
+ uint8 dir = iMap->calc_dir(src, bl->x, bl->y), t_dir = unit->getdir(bl);
if ((!check_distance_bl(src, bl, 0) && !iMap->check_dir(dir, t_dir)) || bl->type == BL_SKILL) {
status_change_end(src, SC_HIDING, INVALID_TIMER);
skill->attack(BF_WEAPON, src, src, bl, skill_id, skill_lv, tick, flag);
dir = dir < 4 ? dir+4 : dir-4; // change direction [Celest]
- unit_setdir(bl,dir);
+ unit->setdir(bl,dir);
}
else if (sd)
clif->skill_fail(sd,skill_id,USESKILL_FAIL_LEVEL,0);
@@ -3691,7 +3691,7 @@ int skill_castend_damage_id (struct block_list* src, struct block_list *bl, uint
else if( dir == 7 || dir < 2 ) y = i;
else y = 0;
if( (mbl == src || (!map_flag_gvg2(src->m) && !map[src->m].flag.battleground) ) && // only NJ_ISSEN don't have slide effect in GVG
- unit_movepos(src, mbl->x+x, mbl->y+y, 1, 1) ) {
+ unit->movepos(src, mbl->x+x, mbl->y+y, 1, 1) ) {
clif->slide(src, src->x, src->y);
clif->fixpos(src);
clif->spiritball(src);
@@ -3830,7 +3830,7 @@ int skill_castend_damage_id (struct block_list* src, struct block_list *bl, uint
c = skill->get_blewcount(skill_id,skill_lv);
// keep moving target in the direction that src is looking, square by square
for(i=0;i<c;i++){
- if (!skill->blown(src,bl,1,(unit_getdir(src)+4)%8,0x1))
+ if (!skill->blown(src,bl,1,(unit->getdir(src)+4)%8,0x1))
break; //Can't knockback
skill_area_temp[0] = iMap->foreachinrange(skill->area_sub, bl, skill->get_splash(skill_id, skill_lv), BL_CHAR, src, skill_id, skill_lv, tick, flag|BCT_ENEMY, skill->area_sub_count);
if( skill_area_temp[0] > 1 ) break; // collision
@@ -4073,17 +4073,17 @@ int skill_castend_damage_id (struct block_list* src, struct block_list *bl, uint
{ //You don't move on GVG grounds.
short x, y;
iMap->search_freecell(bl, 0, &x, &y, 1, 1, 0);
- if (unit_movepos(src, x, y, 0, 0))
+ if (unit->movepos(src, x, y, 0, 0))
clif->slide(src,src->x,src->y);
}
status_change_end(src, SC_HIDING, INVALID_TIMER);
skill->attack(BF_WEAPON,src,src,bl,skill_id,skill_lv,tick,flag);
break;
case RK_PHANTOMTHRUST:
- unit_setdir(src,iMap->calc_dir(src, bl->x, bl->y));
+ unit->setdir(src,iMap->calc_dir(src, bl->x, bl->y));
clif->skill_nodamage(src,bl,skill_id,skill_lv,1);
- skill->blown(src,bl,distance_bl(src,bl)-1,unit_getdir(src),0);
+ skill->blown(src,bl,distance_bl(src,bl)-1,unit->getdir(src),0);
if( battle->check_target(src,bl,BCT_ENEMY) > 0 )
skill->attack(BF_WEAPON,src,src,bl,skill_id,skill_lv,tick,flag);
break;
@@ -4100,7 +4100,7 @@ int skill_castend_damage_id (struct block_list* src, struct block_list *bl, uint
else if( dir == 7 || dir < 2 ) y = -2;
else y = 0;
- if( unit_movepos(src, bl->x+x, bl->y+y, 1, 1) )
+ if( unit->movepos(src, bl->x+x, bl->y+y, 1, 1) )
{
clif->slide(src,bl->x+x,bl->y+y);
clif->fixpos(src); // the official server send these two packts.
@@ -4257,7 +4257,7 @@ int skill_castend_damage_id (struct block_list* src, struct block_list *bl, uint
break;
case WL_FROSTMISTY:
// Doesn't deal damage through non-shootable walls.
- if( path_search(NULL,src->m,src->x,src->y,bl->x,bl->y,1,CELL_CHKWALL) )
+ if( path->search(NULL,src->m,src->x,src->y,bl->x,bl->y,1,CELL_CHKWALL) )
skill->attack(BF_MAGIC,src,src,bl,skill_id,skill_lv,tick,flag|SD_ANIMATION);
break;
case WL_HELLINFERNO:
@@ -4270,7 +4270,7 @@ int skill_castend_damage_id (struct block_list* src, struct block_list *bl, uint
short y[8]={1,1,0,-1,-1,-1,0,1};
uint8 dir = iMap->calc_dir(bl, src->x, src->y);
- if( unit_movepos(src, bl->x+x[dir], bl->y+y[dir], 1, 1) )
+ if( unit->movepos(src, bl->x+x[dir], bl->y+y[dir], 1, 1) )
{
clif->slide(src, bl->x+x[dir], bl->y+y[dir]);
clif->fixpos(src);
@@ -4279,7 +4279,7 @@ int skill_castend_damage_id (struct block_list* src, struct block_list *bl, uint
break;
}
case RA_WUGBITE:
- if( path_search(NULL,src->m,src->x,src->y,bl->x,bl->y,1,CELL_CHKNOREACH) ) {
+ if( path->search(NULL,src->m,src->x,src->y,bl->x,bl->y,1,CELL_CHKNOREACH) ) {
skill->attack(BF_WEAPON,src,src,bl,skill_id,skill_lv,tick,flag);
}else if( sd && skill_id == RA_WUGBITE ) // Only RA_WUGBITE has the skill fail message.
clif->skill_fail(sd, skill_id, USESKILL_FAIL_LEVEL, 0);
@@ -4350,7 +4350,7 @@ int skill_castend_damage_id (struct block_list* src, struct block_list *bl, uint
}
break;
case LG_PINPOINTATTACK:
- if( !map_flag_gvg2(src->m) && !map[src->m].flag.battleground && unit_movepos(src, bl->x, bl->y, 1, 1) )
+ if( !map_flag_gvg2(src->m) && !map[src->m].flag.battleground && unit->movepos(src, bl->x, bl->y, 1, 1) )
clif->slide(src,bl->x,bl->y);
skill->attack(BF_WEAPON,src,src,bl,skill_id,skill_lv,tick,flag);
break;
@@ -4375,7 +4375,7 @@ int skill_castend_damage_id (struct block_list* src, struct block_list *bl, uint
break;
case SR_KNUCKLEARROW:
- if( !map_flag_gvg2(src->m) && !map[src->m].flag.battleground && unit_movepos(src, bl->x, bl->y, 1, 1) ) {
+ if( !map_flag_gvg2(src->m) && !map[src->m].flag.battleground && unit->movepos(src, bl->x, bl->y, 1, 1) ) {
clif->slide(src,bl->x,bl->y);
clif->fixpos(src); // Aegis send this packet too.
}
@@ -4523,7 +4523,7 @@ int skill_castend_damage_id (struct block_list* src, struct block_list *bl, uint
skill->attack(BF_WEAPON, src, src, bl, skill_id, skill_lv, tick, flag);
break;
case MH_TINDER_BREAKER:
- if (unit_movepos(src, bl->x, bl->y, 1, 1)) {
+ if (unit->movepos(src, bl->x, bl->y, 1, 1)) {
#if PACKETVER >= 20111005
clif->snap(src, bl->x, bl->y);
#else
@@ -4600,7 +4600,7 @@ int skill_castend_id(int tid, unsigned int tick, int id, intptr_t data)
return 0;// not found
}
- ud = unit_bl2ud(src);
+ ud = unit->bl2ud(src);
if( ud == NULL )
{
ShowDebug("skill_castend_id: ud == NULL (tid=%d, id=%d)\n", tid, id);
@@ -4615,7 +4615,7 @@ int skill_castend_id(int tid, unsigned int tick, int id, intptr_t data)
return 0;
}
- if(ud->skill_id != SA_CASTCANCEL && ud->skill_id != SO_SPELLFIST) {// otherwise handled in unit_skillcastcancel()
+ if(ud->skill_id != SA_CASTCANCEL && ud->skill_id != SO_SPELLFIST) {// otherwise handled in unit->skillcastcancel()
if( ud->skilltimer != tid ) {
ShowError("skill_castend_id: Timer mismatch %d!=%d!\n", ud->skilltimer, tid);
ud->skilltimer = INVALID_TIMER;
@@ -4668,7 +4668,7 @@ int skill_castend_id(int tid, unsigned int tick, int id, intptr_t data)
}
if(ud->skill_id == RG_BACKSTAP) {
- uint8 dir = iMap->calc_dir(src,target->x,target->y),t_dir = unit_getdir(target);
+ uint8 dir = iMap->calc_dir(src,target->x,target->y),t_dir = unit->getdir(target);
if(check_distance_bl(src, target, 0) || iMap->check_dir(dir,t_dir)) {
break;
}
@@ -4681,7 +4681,7 @@ int skill_castend_id(int tid, unsigned int tick, int id, intptr_t data)
}
if( ud->skill_id == RA_WUGSTRIKE ){
- if( !path_search(NULL,src->m,src->x,src->y,target->x,target->y,1,CELL_CHKNOREACH))
+ if( !path->search(NULL,src->m,src->x,src->y,target->x,target->y,1,CELL_CHKNOREACH))
break;
}
@@ -4769,7 +4769,7 @@ int skill_castend_id(int tid, unsigned int tick, int id, intptr_t data)
skill->consume_requirement(sd,ud->skill_id,ud->skill_lv,1);
}
#ifdef OFFICIAL_WALKPATH
- if( !path_search_long(NULL, src->m, src->x, src->y, target->x, target->y, CELL_CHKWALL) )
+ if( !path->search_long(NULL, src->m, src->x, src->y, target->x, target->y, CELL_CHKWALL) )
break;
#endif
if( (src->type == BL_MER || src->type == BL_HOM) && !skill->check_condition_mercenary(src, ud->skill_id, ud->skill_lv, 1) )
@@ -4782,7 +4782,7 @@ int skill_castend_id(int tid, unsigned int tick, int id, intptr_t data)
}
if (ud->walktimer != INVALID_TIMER && ud->skill_id != TK_RUN && ud->skill_id != RA_WUGDASH)
- unit_stop_walking(src,1);
+ unit->stop_walking(src,1);
if( !sd || sd->skillitem != ud->skill_id || skill->get_delay(ud->skill_id,ud->skill_lv) )
ud->canact_tick = tick + skill->delay_fix(src, ud->skill_id, ud->skill_lv); //Tests show wings don't overwrite the delay but skill scrolls do. [Inkfish]
@@ -4819,7 +4819,7 @@ int skill_castend_id(int tid, unsigned int tick, int id, intptr_t data)
}
}
if (skill->get_state(ud->skill_id) != ST_MOVE_ENABLE)
- unit_set_walkdelay(src, tick, battle_config.default_walk_delay+skill->get_walkdelay(ud->skill_id, ud->skill_lv), 1);
+ unit->set_walkdelay(src, tick, battle_config.default_walk_delay+skill->get_walkdelay(ud->skill_id, ud->skill_lv), 1);
if(battle_config.skill_log && battle_config.skill_log&src->type)
ShowInfo("Type %d, ID %d skill castend id [id =%d, lv=%d, target ID %d]\n",
@@ -4886,7 +4886,7 @@ int skill_castend_id(int tid, unsigned int tick, int id, intptr_t data)
if( dir > 2 && dir < 6 ) y = -2;
else if( dir == 7 || dir < 2 ) y = 2;
else y = 0;
- if (unit_movepos(src, src->x+x, src->y+y, 1, 1))
+ if (unit->movepos(src, src->x+x, src->y+y, 1, 1))
{ //Display movement + animation.
clif->slide(src,src->x,src->y);
clif->spiritball(src);
@@ -5217,14 +5217,14 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
}
else
{// mob-casted
- struct unit_data *ud = unit_bl2ud(src);
+ struct unit_data *ud = unit->bl2ud(src);
int inf = skill->get_inf(abra_skill_id);
if (!ud) break;
if (inf&INF_SELF_SKILL || inf&INF_SUPPORT_SKILL) {
if (src->type == BL_PET)
bl = (struct block_list*)((TBL_PET*)src)->msd;
if (!bl) bl = src;
- unit_skilluse_id(src, bl->id, abra_skill_id, abra_skill_lv);
+ unit->skilluse_id(src, bl->id, abra_skill_id, abra_skill_lv);
} else { //Assume offensive skills
int target_id = 0;
if (ud->target)
@@ -5238,9 +5238,9 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
if (skill->get_casttype(abra_skill_id) == CAST_GROUND) {
bl = iMap->id2bl(target_id);
if (!bl) bl = src;
- unit_skilluse_pos(src, bl->x, bl->y, abra_skill_id, abra_skill_lv);
+ unit->skilluse_pos(src, bl->x, bl->y, abra_skill_id, abra_skill_lv);
} else
- unit_skilluse_id(src, target_id, abra_skill_id, abra_skill_lv);
+ unit->skilluse_id(src, target_id, abra_skill_id, abra_skill_lv);
}
}
}
@@ -5272,7 +5272,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
break;
case SA_SUMMONMONSTER:
clif->skill_nodamage(src,bl,skill_id,skill_lv,1);
- if (sd) mob_once_spawn(sd, src->m, src->x, src->y," --ja--", -1, 1, "", SZ_SMALL, AI_NONE);
+ if (sd) mob->once_spawn(sd, src->m, src->x, src->y," --ja--", -1, 1, "", SZ_SMALL, AI_NONE);
break;
case SA_LEVELUP:
clif->skill_nodamage(src,bl,skill_id,skill_lv,1);
@@ -5296,9 +5296,9 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
clif->skill_fail(sd,skill_id,USESKILL_FAIL_LEVEL,0);
break;
}
- class_ = skill_id==SA_MONOCELL?1002:mob_get_random_id(4, 1, 0);
+ class_ = skill_id==SA_MONOCELL?1002:mob->get_random_id(4, 1, 0);
clif->skill_nodamage(src,bl,skill_id,skill_lv,1);
- mob_class_change(dstmd,class_);
+ mob->class_change(dstmd,class_);
if( tsc && dstmd->status.mode&MD_BOSS )
{
const enum sc_type scs[] = { SC_QUAGMIRE, SC_PROVOKE, SC_ROKISWEIL, SC_GRAVITATION, SC_NJ_SUITON, SC_NOEQUIPWEAPON, SC_NOEQUIPSHIELD, SC_NOEQUIPARMOR, SC_NOEQUIPHELM, SC_BLADESTOP };
@@ -5330,9 +5330,9 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
case SA_TAMINGMONSTER:
clif->skill_nodamage(src,bl,skill_id,skill_lv,1);
if (sd && dstmd) {
- ARR_FIND( 0, MAX_PET_DB, i, dstmd->class_ == pet_db[i].class_ );
+ ARR_FIND( 0, MAX_PET_DB, i, dstmd->class_ == pet->db[i].class_ );
if( i < MAX_PET_DB )
- pet_catch_process1(sd, dstmd->class_);
+ pet->catch_process1(sd, dstmd->class_);
}
break;
@@ -5474,10 +5474,10 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
break;
case TK_JUMPKICK:
- /* Check if the target is an enemy; if not, skill should fail so the character doesn't unit_movepos (exploitable) */
+ /* Check if the target is an enemy; if not, skill should fail so the character doesn't unit->movepos (exploitable) */
if( battle->check_target(src, bl, BCT_ENEMY) > 0 )
{
- if( unit_movepos(src, bl->x, bl->y, 1, 1) )
+ if( unit->movepos(src, bl->x, bl->y, 1, 1) )
{
skill->attack(BF_WEAPON,src,src,bl,skill_id,skill_lv,tick,flag);
clif->slide(src,bl->x,bl->y);
@@ -5685,7 +5685,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
clif->skill_fail(sd,skill_id,USESKILL_FAIL_LEVEL,0);
break;
}
- id = mob_get_random_id(0,0xF, sd->status.base_level);
+ id = mob->get_random_id(0,0xF, sd->status.base_level);
if (!id) {
clif->skill_fail(sd,skill_id,USESKILL_FAIL_LEVEL,0);
break;
@@ -5726,7 +5726,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
iMap->freeblock_unlock();
return 0;
}
- unit_skillcastcancel(bl, 2);
+ unit->skillcastcancel(bl, 2);
if( tsc && tsc->count )
{
@@ -5740,7 +5740,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
if( dstmd )
{
dstmd->state.provoke_flag = src->id;
- mob_target(dstmd, src, skill->get_range2(src,skill_id,skill_lv));
+ mob->target(dstmd, src, skill->get_range2(src,skill_id,skill_lv));
}
break;
@@ -5840,7 +5840,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
} else if (dstmd && !(tstatus->mode&MD_BOSS) && rnd() % 100 < 20)
{ // check if target is a monster and not a Boss, for the 20% chance to absorb 2 SP per monster's level [Reddozen]
i = 2 * dstmd->level;
- mob_target(dstmd,src,0);
+ mob->target(dstmd,src,0);
}
if (i) iStatus->heal(src, 0, i, 3);
clif->skill_nodamage(src,bl,skill_id,skill_lv,i?1:0);
@@ -6069,7 +6069,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
iMap->freeblock_unlock();
return 0;
}
- clif->skill_nodamage(src,bl,skill_id,skill_lv,sc_start4(bl,type,100,skill_lv,unit_getdir(bl),0,0,0));
+ clif->skill_nodamage(src,bl,skill_id,skill_lv,sc_start4(bl,type,100,skill_lv,unit->getdir(bl),0,0,0));
if (sd) // If the client receives a skill-use packet inmediately before a walkok packet, it will discard the walk packet! [Skotlex]
clif->walkok(sd); // So aegis has to resend the walk ok.
break;
@@ -6152,7 +6152,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
if(pc->steal_coin(sd,bl))
{
dstmd->state.provoke_flag = src->id;
- mob_target(dstmd, src, skill->get_range2(src,skill_id,skill_lv));
+ mob->target(dstmd, src, skill->get_range2(src,skill_id,skill_lv));
clif->skill_nodamage(src,bl,skill_id,skill_lv,1);
}
@@ -6238,7 +6238,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
}
clif->skill_nodamage(src,bl,skill_id,skill_lv,1);
if(dstmd)
- mob_unlocktarget(dstmd,tick);
+ mob->unlocktarget(dstmd,tick);
break;
// Mercenary Supportive Skills
@@ -6364,12 +6364,12 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
else
clif->skill_warppoint(sd,skill_id,skill_lv, (unsigned short)-1,sd->status.save_point.map,0,0);
} else
- unit_warp(bl,-1,-1,-1,CLR_TELEPORT);
+ unit->warp(bl,-1,-1,-1,CLR_TELEPORT);
break;
case NPC_EXPULSION:
clif->skill_nodamage(src,bl,skill_id,skill_lv,1);
- unit_warp(bl,-1,-1,-1,CLR_TELEPORT);
+ unit->warp(bl,-1,-1,-1,CLR_TELEPORT);
break;
case AL_HOLYWATER:
@@ -6704,12 +6704,12 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
case TF_BACKSLIDING: //This is the correct implementation as per packet logging information. [Skotlex]
clif->skill_nodamage(src,bl,skill_id,skill_lv,1);
- skill->blown(src,bl,skill->get_blewcount(skill_id,skill_lv),unit_getdir(bl),0);
+ skill->blown(src,bl,skill->get_blewcount(skill_id,skill_lv),unit->getdir(bl),0);
break;
case TK_HIGHJUMP:
{
- int x,y, dir = unit_getdir(src);
+ int x,y, dir = unit->getdir(src);
//Fails on noteleport maps, except for GvG and BG maps [Skotlex]
if( map[src->m].flag.noteleport &&
@@ -6725,7 +6725,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
clif->skill_nodamage(src,bl,TK_HIGHJUMP,skill_lv,1);
if(!iMap->count_oncell(src->m,x,y,BL_PC|BL_NPC|BL_MOB) && iMap->getcell(src->m,x,y,CELL_CHKREACH)) {
clif->slide(src,x,y);
- unit_movepos(src, x, y, 1, 0);
+ unit->movepos(src, x, y, 1, 0);
}
}
break;
@@ -6733,7 +6733,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
case SA_CASTCANCEL:
case SO_SPELLFIST:
clif->skill_nodamage(src,bl,skill_id,skill_lv,1);
- unit_skillcastcancel(src,1);
+ unit->skillcastcancel(src,1);
if(sd) {
int sp = skill->get_sp(sd->skill_id_old,sd->skill_lv_old);
if( skill_id == SO_SPELLFIST ){
@@ -6756,7 +6756,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
iStatus->heal(bl,0,sp,2);
status_percent_damage(bl, src, 0, -20, false); //20% max SP damage.
} else {
- struct unit_data *ud = unit_bl2ud(bl);
+ struct unit_data *ud = unit->bl2ud(bl);
int bl_skill_id=0,bl_skill_lv=0,hp = 0;
if (!ud || ud->skilltimer == INVALID_TIMER)
break; //Nothing to cancel.
@@ -6773,7 +6773,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
hp = tstatus->max_hp/50; //Recover 2% HP [Skotlex]
clif->skill_nodamage(src,bl,skill_id,skill_lv,1);
- unit_skillcastcancel(bl,0);
+ unit->skillcastcancel(bl,0);
sp = skill->get_sp(bl_skill_id,bl_skill_lv);
status_zap(bl, hp, sp);
@@ -6872,14 +6872,14 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
case NPC_PROVOCATION:
clif->skill_nodamage(src,bl,skill_id,skill_lv,1);
- if (md) mob_unlocktarget(md, tick);
+ if (md) mob->unlocktarget(md, tick);
break;
case NPC_KEEPING:
case NPC_BARRIER:
{
int skill_time = skill->get_time(skill_id,skill_lv);
- struct unit_data *ud = unit_bl2ud(bl);
+ struct unit_data *ud = unit->bl2ud(bl);
if (clif->skill_nodamage(src,bl,skill_id,skill_lv,
sc_start(bl,type,100,skill_lv,skill_time))
&& ud) { //Disable attacking/acting/moving for skill's duration.
@@ -6915,17 +6915,17 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
case NPC_SUMMONSLAVE:
case NPC_SUMMONMONSTER:
if(md && md->skill_idx >= 0)
- mob_summonslave(md,md->db->skill[md->skill_idx].val,skill_lv,skill_id);
+ mob->summonslave(md,md->db->skill[md->skill_idx].val,skill_lv,skill_id);
break;
case NPC_CALLSLAVE:
- mob_warpslave(src,MOB_SLAVEDISTANCE);
+ mob->warpslave(src,MOB_SLAVEDISTANCE);
break;
case NPC_RANDOMMOVE:
if (md) {
md->next_walktime = tick - 1;
- mob_randomwalk(md,tick);
+ mob->randomwalk(md,tick);
}
break;
@@ -6948,17 +6948,17 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
(tbl = battle->get_targeted(mbl)) == NULL)
break;
md->state.provoke_flag = tbl->id;
- mob_target(md, tbl, sstatus->rhw.range);
+ mob->target(md, tbl, sstatus->rhw.range);
}
break;
case NPC_RUN:
{
const int mask[8][2] = {{0,-1},{1,-1},{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1}};
- uint8 dir = (bl == src)?unit_getdir(src):iMap->calc_dir(src,bl->x,bl->y); //If cast on self, run forward, else run away.
- unit_stop_attack(src);
+ uint8 dir = (bl == src)?unit->getdir(src):iMap->calc_dir(src,bl->x,bl->y); //If cast on self, run forward, else run away.
+ unit->stop_attack(src);
//Run skillv tiles overriding the can-move check.
- if (unit_walktoxy(src, src->x + skill_lv * mask[dir][0], src->y + skill_lv * mask[dir][1], 2) && md)
+ if (unit->walktoxy(src, src->x + skill_lv * mask[dir][0], src->y + skill_lv * mask[dir][1], 2) && md)
md->state.skillstate = MSS_WALK; //Otherwise it isn't updated in the ai.
}
break;
@@ -6966,10 +6966,10 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
case NPC_TRANSFORMATION:
case NPC_METAMORPHOSIS:
if(md && md->skill_idx >= 0) {
- int class_ = mob_random_class (md->db->skill[md->skill_idx].val,0);
+ int class_ = mob->random_class (md->db->skill[md->skill_idx].val,0);
if (skill_lv > 1) //Multiply the rest of mobs. [Skotlex]
- mob_summonslave(md,md->db->skill[md->skill_idx].val,skill_lv-1,skill_id);
- if (class_) mob_class_change(md, class_);
+ mob->summonslave(md,md->db->skill[md->skill_idx].val,skill_lv-1,skill_id);
+ if (class_) mob->class_change(md, class_);
}
break;
@@ -6988,7 +6988,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
//If mode gets set by NPC_EMOTION then the target should be reset [Playtester]
if(skill_id == NPC_EMOTION && md->db->skill[md->skill_idx].val[1])
- mob_unlocktarget(md,tick);
+ mob->unlocktarget(md,tick);
if(md->db->skill[md->skill_idx].val[1] || md->db->skill[md->skill_idx].val[2])
sc_start4(src, type, 100, skill_lv,
@@ -7152,7 +7152,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
case BD_ENCORE:
clif->skill_nodamage(src,bl,skill_id,skill_lv,1);
if(sd)
- unit_skilluse_id(src,src->id,sd->skill_id_dance,sd->skill_lv_dance);
+ unit->skilluse_id(src,src->id,sd->skill_id_dance,sd->skill_lv_dance);
break;
case AS_SPLASHER:
@@ -7198,7 +7198,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
return 0;
}
- unit_skillcastcancel(bl,0);
+ unit->skillcastcancel(bl,0);
if(tsc && tsc->count){
status_change_end(bl, SC_FREEZE, INVALID_TIMER);
@@ -7208,7 +7208,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
}
if(dstmd)
- mob_target(dstmd,src,skill->get_range2(src,skill_id,skill_lv));
+ mob->target(dstmd,src,skill->get_range2(src,skill_id,skill_lv));
}
break;
@@ -7361,7 +7361,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
case 5: // 2000HP heal, random teleported
iStatus->heal(src, 2000, 0, 0);
if( !map_flag_vs(bl->m) )
- unit_warp(bl, -1,-1,-1, CLR_TELEPORT);
+ unit->warp(bl, -1,-1,-1, CLR_TELEPORT);
break;
case 6: // random 2 other effects
if (count == -1)
@@ -7605,10 +7605,10 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
if (hd)
skill->blockhomun_start(hd, skill_id, skill->get_time2(skill_id,skill_lv));
- if (unit_movepos(src,bl->x,bl->y,0,0)) {
+ if (unit->movepos(src,bl->x,bl->y,0,0)) {
clif->skill_nodamage(src,src,skill_id,skill_lv,1); // Homunc
clif->slide(src,bl->x,bl->y) ;
- if (unit_movepos(bl,x,y,0,0))
+ if (unit->movepos(bl,x,y,0,0))
{
clif->skill_nodamage(bl,bl,skill_id,skill_lv,1); // Master
clif->slide(bl,x,y) ;
@@ -8233,7 +8233,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
return 0;
}
if( sd && pc_isridingwug(sd) ) {
- clif->skill_nodamage(src,bl,skill_id,skill_lv,sc_start4(bl,type,100,skill_lv,unit_getdir(bl),0,0,1));
+ clif->skill_nodamage(src,bl,skill_id,skill_lv,sc_start4(bl,type,100,skill_lv,unit->getdir(bl),0,0,1));
clif->walkok(sd);
}
break;
@@ -8249,7 +8249,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
case NC_F_SIDESLIDE:
case NC_B_SIDESLIDE:
{
- uint8 dir = (skill_id == NC_F_SIDESLIDE) ? (unit_getdir(src)+4)%8 : unit_getdir(src);
+ uint8 dir = (skill_id == NC_F_SIDESLIDE) ? (unit->getdir(src)+4)%8 : unit->getdir(src);
skill->blown(src,bl,skill->get_blewcount(skill_id,skill_lv),dir,0);
clif->slide(src,src->x,src->y);
clif->skill_nodamage(src,bl,skill_id,skill_lv,1);
@@ -8560,8 +8560,8 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
if( is_boss(bl) ) break;
if( sc_start2(bl, type, 100, skill_lv, src->id, skill->get_time(skill_id, skill_lv))) {
if( bl->type == BL_MOB )
- mob_unlocktarget((TBL_MOB*)bl,iTimer->gettick());
- unit_stop_attack(bl);
+ mob->unlocktarget((TBL_MOB*)bl,iTimer->gettick());
+ unit->stop_attack(bl);
clif->bladestop(src, bl->id, 1);
iMap->freeblock_unlock();
return 1;
@@ -8796,14 +8796,14 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
sd->skillitemlv = improv_skill_lv;
clif->item_skill(sd, improv_skill_id, improv_skill_lv);
} else {
- struct unit_data *ud = unit_bl2ud(src);
+ struct unit_data *ud = unit->bl2ud(src);
int inf = skill->get_inf(improv_skill_id);
if (!ud) break;
if (inf&INF_SELF_SKILL || inf&INF_SUPPORT_SKILL) {
if (src->type == BL_PET)
bl = (struct block_list*)((TBL_PET*)src)->msd;
if (!bl) bl = src;
- unit_skilluse_id(src, bl->id, improv_skill_id, improv_skill_lv);
+ unit->skilluse_id(src, bl->id, improv_skill_id, improv_skill_lv);
} else {
int target_id = 0;
if (ud->target)
@@ -8817,9 +8817,9 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
if (skill->get_casttype(improv_skill_id) == CAST_GROUND) {
bl = iMap->id2bl(target_id);
if (!bl) bl = src;
- unit_skilluse_pos(src, bl->x, bl->y, improv_skill_id, improv_skill_lv);
+ unit->skilluse_pos(src, bl->x, bl->y, improv_skill_id, improv_skill_lv);
} else
- unit_skilluse_id(src, target_id, improv_skill_id, improv_skill_lv);
+ unit->skilluse_id(src, target_id, improv_skill_id, improv_skill_lv);
}
}
}
@@ -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);
}
@@ -9147,18 +9147,18 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
if(sd){
struct mob_data *md;
- md = mob_once_spawn_sub(src, src->m, src->x, src->y, iStatus->get_name(src), 2308, "", SZ_SMALL, AI_NONE);
+ md = mob->once_spawn_sub(src, src->m, src->x, src->y, iStatus->get_name(src), 2308, "", SZ_SMALL, AI_NONE);
if( md )
{
md->master_id = src->id;
md->special_state.ai = AI_ZANZOU;
if( md->deletetimer != INVALID_TIMER )
- iTimer->delete_timer(md->deletetimer, mob_timer_delete);
- md->deletetimer = iTimer->add_timer (iTimer->gettick() + skill->get_time(skill_id, skill_lv), mob_timer_delete, md->bl.id, 0);
- mob_spawn( md );
+ iTimer->delete_timer(md->deletetimer, mob->timer_delete);
+ md->deletetimer = iTimer->add_timer (iTimer->gettick() + skill->get_time(skill_id, skill_lv), mob->timer_delete, md->bl.id, 0);
+ mob->spawn( md );
pc->setinvincibletimer(sd,500);// unlock target lock
clif->skill_nodamage(src,bl,skill_id,skill_lv,1);
- skill->blown(src,bl,skill->get_blewcount(skill_id,skill_lv),unit_getdir(bl),0);
+ skill->blown(src,bl,skill->get_blewcount(skill_id,skill_lv),unit->getdir(bl),0);
}
}
break;
@@ -9198,11 +9198,11 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
break;
}
- if (unit_movepos(src, bl->x, bl->y, 0, 0)) {
+ if (unit->movepos(src, bl->x, bl->y, 0, 0)) {
clif->skill_nodamage(src, src, skill_id, skill_lv, 1);
clif->slide(src, bl->x, bl->y) ;
sc_start(src, SC_CONFUSION, 25, skill_lv, skill->get_time(skill_id, skill_lv));
- if ( !is_boss(bl) && unit_stop_walking(&sd->bl, 1) && unit_movepos(bl, x, y, 0, 0) )
+ if ( !is_boss(bl) && unit->stop_walking(&sd->bl, 1) && unit->movepos(bl, x, y, 0, 0) )
{
if( dstsd && pc_issit(dstsd) )
pc->setstand(dstsd);
@@ -9334,13 +9334,13 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
break;
for(i=0; i<qty[skill_lv - 1]; i++){ //easy way
- md = mob_once_spawn_sub(src, src->m, src->x, src->y, iStatus->get_name(src), summons[skill_lv - 1], "", SZ_SMALL, AI_ATTACK);
+ md = mob->once_spawn_sub(src, src->m, src->x, src->y, iStatus->get_name(src), summons[skill_lv - 1], "", SZ_SMALL, AI_ATTACK);
if (md) {
md->master_id = src->id;
if (md->deletetimer != INVALID_TIMER)
- iTimer->delete_timer(md->deletetimer, mob_timer_delete);
- md->deletetimer = iTimer->add_timer(iTimer->gettick() + skill->get_time(skill_id, skill_lv), mob_timer_delete, md->bl.id, 0);
- mob_spawn(md); //Now it is ready for spawning.
+ iTimer->delete_timer(md->deletetimer, mob->timer_delete);
+ md->deletetimer = iTimer->add_timer(iTimer->gettick() + skill->get_time(skill_id, skill_lv), mob->timer_delete, md->bl.id, 0);
+ mob->spawn(md); //Now it is ready for spawning.
sc_start4(&md->bl, SC_MODECHANGE, 100, 1, 0, MD_CANATTACK|MD_AGGRESSIVE, 0, 60000);
}
}
@@ -9362,8 +9362,8 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
}
if (dstmd) { //Mob skill event for no damage skills (damage ones are handled in battle_calc_damage) [Skotlex]
- mob_log_damage(dstmd, src, 0); //Log interaction (counts as 'attacker' for the exp bonus)
- mobskill_event(dstmd, src, tick, MSC_SKILLUSED|(skill_id<<16));
+ mob->log_damage(dstmd, src, 0); //Log interaction (counts as 'attacker' for the exp bonus)
+ mob->skill_event(dstmd, src, tick, MSC_SKILLUSED|(skill_id<<16));
}
if( sd && !(flag&1) ) { // ensure that the skill last-cast tick is recorded
@@ -9389,7 +9389,7 @@ int skill_castend_pos(int tid, unsigned int tick, int id, intptr_t data)
struct block_list* src = iMap->id2bl(id);
int maxcount;
struct map_session_data *sd;
- struct unit_data *ud = unit_bl2ud(src);
+ struct unit_data *ud = unit->bl2ud(src);
struct mob_data *md;
nullpo_ret(ud);
@@ -9485,7 +9485,7 @@ int skill_castend_pos(int tid, unsigned int tick, int id, intptr_t data)
src->type, src->id, ud->skill_id, ud->skill_lv, ud->skillx, ud->skilly);
if (ud->walktimer != INVALID_TIMER)
- unit_stop_walking(src,1);
+ unit->stop_walking(src,1);
if( !sd || sd->skillitem != ud->skill_id || skill->get_delay(ud->skill_id,ud->skill_lv) )
ud->canact_tick = tick + skill->delay_fix(src, ud->skill_id, ud->skill_lv);
@@ -9511,7 +9511,7 @@ int skill_castend_pos(int tid, unsigned int tick, int id, intptr_t data)
// break;
// }
// }
- unit_set_walkdelay(src, tick, battle_config.default_walk_delay+skill->get_walkdelay(ud->skill_id, ud->skill_lv), 1);
+ unit->set_walkdelay(src, tick, battle_config.default_walk_delay+skill->get_walkdelay(ud->skill_id, ud->skill_lv), 1);
status_change_end(src,SC_CAMOUFLAGE, INVALID_TIMER);// only normal attack and auto cast skills benefit from its bonuses
iMap->freeblock_lock();
skill->castend_pos2(src,ud->skillx,ud->skilly,ud->skill_id,ud->skill_lv,tick,0);
@@ -9941,7 +9941,7 @@ int skill_castend_pos2(struct block_list* src, int x, int y, uint16 skill_id, ui
tmpx = x - area + rnd()%(area * 2 + 1);
tmpy = y - area + rnd()%(area * 2 + 1);
- if( i == 0 && path_search_long(NULL, src->m, src->x, src->y, tmpx, tmpy, CELL_CHKWALL) )
+ if( i == 0 && path->search_long(NULL, src->m, src->x, src->y, tmpx, tmpy, CELL_CHKWALL) )
clif->skill_poseffect(src,skill_id,skill_lv,tmpx,tmpy,tick);
if( i > 0 )
@@ -9969,7 +9969,7 @@ int skill_castend_pos2(struct block_list* src, int x, int y, uint16 skill_id, ui
return 0; // not to consume item.
case MO_BODYRELOCATION:
- if (unit_movepos(src, x, y, 1, 1)) {
+ if (unit->movepos(src, x, y, 1, 1)) {
#if PACKETVER >= 20111005
clif->snap(src, src->x, src->y);
#else
@@ -9981,7 +9981,7 @@ int skill_castend_pos2(struct block_list* src, int x, int y, uint16 skill_id, ui
break;
case NJ_SHADOWJUMP:
if( !map_flag_gvg2(src->m) && !map[src->m].flag.battleground ) { //You don't move on GVG grounds.
- unit_movepos(src, x, y, 1, 0);
+ unit->movepos(src, x, y, 1, 0);
clif->slide(src,x,y);
}
status_change_end(src, SC_HIDING, INVALID_TIMER);
@@ -9995,14 +9995,14 @@ int skill_castend_pos2(struct block_list* src, int x, int y, uint16 skill_id, ui
struct mob_data *md;
// Correct info, don't change any of this! [celest]
- md = mob_once_spawn_sub(src, src->m, x, y, iStatus->get_name(src), class_, "", SZ_SMALL, AI_NONE);
+ md = mob->once_spawn_sub(src, src->m, x, y, iStatus->get_name(src), class_, "", SZ_SMALL, AI_NONE);
if (md) {
md->master_id = src->id;
md->special_state.ai = (skill_id == AM_SPHEREMINE) ? AI_SPHERE : AI_FLORA;
if( md->deletetimer != INVALID_TIMER )
- iTimer->delete_timer(md->deletetimer, mob_timer_delete);
- md->deletetimer = iTimer->add_timer (iTimer->gettick() + skill->get_time(skill_id,skill_lv), mob_timer_delete, md->bl.id, 0);
- mob_spawn (md); //Now it is ready for spawning.
+ iTimer->delete_timer(md->deletetimer, mob->timer_delete);
+ md->deletetimer = iTimer->add_timer (iTimer->gettick() + skill->get_time(skill_id,skill_lv), mob->timer_delete, md->bl.id, 0);
+ mob->spawn (md); //Now it is ready for spawning.
}
}
break;
@@ -10093,16 +10093,16 @@ int skill_castend_pos2(struct block_list* src, int x, int y, uint16 skill_id, ui
if (rnd()%100 < 50) {
clif->skill_fail(sd,skill_id,USESKILL_FAIL_LEVEL,0);
} else {
- TBL_MOB* md = mob_once_spawn_sub(src, src->m, x, y, "--ja--",(skill_lv < 2 ? 1084+rnd()%2 : 1078+rnd()%6),"", SZ_SMALL, AI_NONE);
+ TBL_MOB* md = mob->once_spawn_sub(src, src->m, x, y, "--ja--",(skill_lv < 2 ? 1084+rnd()%2 : 1078+rnd()%6),"", SZ_SMALL, AI_NONE);
int i;
if (!md) break;
if ((i = skill->get_time(skill_id, skill_lv)) > 0)
{
if( md->deletetimer != INVALID_TIMER )
- iTimer->delete_timer(md->deletetimer, mob_timer_delete);
- md->deletetimer = iTimer->add_timer (tick + i, mob_timer_delete, md->bl.id, 0);
+ iTimer->delete_timer(md->deletetimer, mob->timer_delete);
+ md->deletetimer = iTimer->add_timer (tick + i, mob->timer_delete, md->bl.id, 0);
}
- mob_spawn (md);
+ mob->spawn (md);
}
}
break;
@@ -10228,15 +10228,15 @@ int skill_castend_pos2(struct block_list* src, int x, int y, uint16 skill_id, ui
int class_ = 2042;
struct mob_data *md;
- md = mob_once_spawn_sub(src, src->m, x, y, iStatus->get_name(src), class_, "", SZ_SMALL, AI_NONE);
+ md = mob->once_spawn_sub(src, src->m, x, y, iStatus->get_name(src), class_, "", SZ_SMALL, AI_NONE);
if( md )
{
md->master_id = src->id;
md->special_state.ai = AI_FLORA;
if( md->deletetimer != INVALID_TIMER )
- iTimer->delete_timer(md->deletetimer, mob_timer_delete);
- md->deletetimer = iTimer->add_timer (iTimer->gettick() + skill->get_time(skill_id, skill_lv), mob_timer_delete, md->bl.id, 0);
- mob_spawn( md );
+ iTimer->delete_timer(md->deletetimer, mob->timer_delete);
+ md->deletetimer = iTimer->add_timer (iTimer->gettick() + skill->get_time(skill_id, skill_lv), mob->timer_delete, md->bl.id, 0);
+ mob->spawn( md );
}
}
break;
@@ -10248,7 +10248,7 @@ int skill_castend_pos2(struct block_list* src, int x, int y, uint16 skill_id, ui
case SC_FEINTBOMB:
skill->unitsetting(src,skill_id,skill_lv,x,y,0); // Set bomb on current Position
clif->skill_nodamage(src,src,skill_id,skill_lv,1);
- if( skill->blown(src,src,6,unit_getdir(src),0) )
+ if( skill->blown(src,src,6,unit->getdir(src),0) )
skill->castend_nodamage_id(src,src,TF_HIDING,1,tick,0x2);
break;
@@ -10312,7 +10312,7 @@ int skill_castend_pos2(struct block_list* src, int x, int y, uint16 skill_id, ui
break;
case GN_FIRE_EXPANSION: {
int i;
- struct unit_data *ud = unit_bl2ud(src);
+ struct unit_data *ud = unit->bl2ud(src);
if( !ud ) break;
@@ -10486,11 +10486,11 @@ int skill_icewall_block(struct block_list *bl,va_list ap) {
if( !md->target_id || ( target = iMap->id2bl(md->target_id) ) == NULL )
return 0;
- if( path_search_long(NULL,bl->m,bl->x,bl->y,target->x,target->y,CELL_CHKICEWALL) )
+ if( path->search_long(NULL,bl->m,bl->x,bl->y,target->x,target->y,CELL_CHKICEWALL) )
return 0;
if( !check_distance_bl(bl, target, status_get_range(bl) ) ) {
- mob_unlocktarget(md,iTimer->gettick());
+ mob->unlocktarget(md,iTimer->gettick());
mob_stop_walking(md,1);
}
@@ -10894,7 +10894,7 @@ struct skill_unit_group* skill_unitsetting (struct block_list *src, uint16 skill
if( !group->state.song_dance && !iMap->getcell(src->m,ux,uy,CELL_CHKREACH) )
continue; // don't place skill units on walls (except for songs/dances/encores)
- if( battle_config.skill_wall_check && skill->get_unit_flag(skill_id)&UF_PATHCHECK && !path_search_long(NULL,src->m,ux,uy,x,y,CELL_CHKWALL) )
+ if( battle_config.skill_wall_check && skill->get_unit_flag(skill_id)&UF_PATHCHECK && !path->search_long(NULL,src->m,ux,uy,x,y,CELL_CHKWALL) )
continue; // no path between cell and center of casting.
switch( skill_id ) {
@@ -11093,7 +11093,7 @@ int skill_unit_onplace (struct skill_unit *src, struct block_list *bl, unsigned
} else if(bl->type == BL_MOB && battle_config.mob_warp&2) {
int16 m = iMap->mapindex2mapid(sg->val3);
if (m < 0) break; //Map not available on this map-server.
- unit_warp(bl,m,sg->val2>>16,sg->val2&0xffff,CLR_TELEPORT);
+ unit->warp(bl,m,sg->val2>>16,sg->val2&0xffff,CLR_TELEPORT);
}
}
break;
@@ -11182,7 +11182,7 @@ int skill_unit_onplace (struct skill_unit *src, struct block_list *bl, unsigned
break;
if (ss == bl) //Also needed to prevent infinite loop crash.
break;
- skill->blown(ss,bl,skill->get_blewcount(sg->skill_id,sg->skill_lv),unit_getdir(bl),0);
+ skill->blown(ss,bl,skill->get_blewcount(sg->skill_id,sg->skill_lv),unit->getdir(bl),0);
break;
case UNT_WALLOFTHORN:
@@ -11399,7 +11399,7 @@ int skill_unit_onplace_timer (struct skill_unit *src, struct block_list *bl, uns
case UNT_SKIDTRAP:
{
- skill->blown(&src->bl,bl,skill->get_blewcount(sg->skill_id,sg->skill_lv),unit_getdir(bl),0);
+ skill->blown(&src->bl,bl,skill->get_blewcount(sg->skill_id,sg->skill_lv),unit->getdir(bl),0);
sg->unit_id = UNT_USED_TRAPS;
clif->changetraplook(&src->bl, UNT_USED_TRAPS);
sg->limit=DIFF_TICK(tick,sg->tick)+1500;
@@ -11415,7 +11415,7 @@ int skill_unit_onplace_timer (struct skill_unit *src, struct block_list *bl, uns
if( td )
sec = DIFF_TICK(td->tick, tick);
if( sg->unit_id == UNT_MANHOLE || battle_config.skill_trap_type || !map_flag_gvg2(src->bl.m) ) {
- unit_movepos(bl, src->bl.x, src->bl.y, 0, 0);
+ unit->movepos(bl, src->bl.x, src->bl.y, 0, 0);
clif->fixpos(bl);
}
sg->val2 = bl->id;
@@ -11644,7 +11644,7 @@ int skill_unit_onplace_timer (struct skill_unit *src, struct block_list *bl, uns
int i = battle->check_target(&src->bl, bl, BCT_ENEMY);
if( i > 0 && !(status_get_mode(bl)&MD_BOSS) )
{ // knock-back any enemy except Boss
- skill->blown(&src->bl, bl, 2, unit_getdir(bl), 0);
+ skill->blown(&src->bl, bl, 2, unit->getdir(bl), 0);
clif->fixpos(bl);
}
@@ -11720,7 +11720,7 @@ int skill_unit_onplace_timer (struct skill_unit *src, struct block_list *bl, uns
if( tsd && !map[bl->m].flag.noteleport )
pc->randomwarp(tsd,3);
else if( bl->type == BL_MOB && battle_config.mob_warp&8 )
- unit_warp(bl,-1,-1,-1,3);
+ unit->warp(bl,-1,-1,-1,3);
break;
case UNT_REVERBERATION:
@@ -11851,21 +11851,21 @@ int skill_unit_onplace_timer (struct skill_unit *src, struct block_list *bl, uns
distance_xy(src->bl.x, src->bl.y, bl->x, bl->y) <= range)// don't consider outer bounderies
sc_start(bl, type, 100, sg->skill_lv, sec);
- if( unit_is_walking(bl) && // wait until target stop walking
+ if( unit->is_walking(bl) && // wait until target stop walking
( tsc && tsc->data[type] && tsc->data[type]->val4 >= tsc->data[type]->val3-range ))
break;
if( tsc && ( !tsc->data[type] || (tsc->data[type] && tsc->data[type]->val4 < 1 ) ) )
break;
- if( unit_is_walking(bl) &&
+ if( unit->is_walking(bl) &&
distance_xy(src->bl.x, src->bl.y, bl->x, bl->y) > range )// going outside of boundaries? then force it to stop
- unit_stop_walking(bl,1);
+ unit->stop_walking(bl,1);
- if( !unit_is_walking(bl) &&
+ if( !unit->is_walking(bl) &&
distance_xy(src->bl.x, src->bl.y, bl->x, bl->y) <= range && // only snap if the target is inside the range or
src->bl.x != bl->x && src->bl.y != bl->y){// diagonal position parallel to VE's center
- unit_movepos(bl, src->bl.x, src->bl.y, 0, 0);
+ unit->movepos(bl, src->bl.x, src->bl.y, 0, 0);
clif->fixpos(bl);
}
}
@@ -11917,7 +11917,7 @@ int skill_unit_onplace_timer (struct skill_unit *src, struct block_list *bl, uns
}
if (bl->type == BL_MOB && ss != bl)
- mobskill_event((TBL_MOB*)bl, ss, tick, MSC_SKILLUSED|(skill_id<<16));
+ mob->skill_event((TBL_MOB*)bl, ss, tick, MSC_SKILLUSED|(skill_id<<16));
return skill_id;
}
@@ -12193,7 +12193,7 @@ int skill_check_condition_char_sub (struct block_list *bl, va_list ap) {
switch(skill_id) {
case PR_BENEDICTIO: {
uint8 dir = iMap->calc_dir(&sd->bl,tsd->bl.x,tsd->bl.y);
- dir = (unit_getdir(&sd->bl) + dir)%8; //This adjusts dir to account for the direction the sd is facing.
+ dir = (unit->getdir(&sd->bl) + dir)%8; //This adjusts dir to account for the direction the sd is facing.
if ((tsd->class_&MAPID_BASEMASK) == MAPID_ACOLYTE && (dir == 2 || dir == 6) //Must be standing to the left/right of Priest.
&& sd->status.sp >= 10)
p_sd[(*c)++]=tsd->bl.id;
@@ -12217,7 +12217,7 @@ int skill_check_condition_char_sub (struct block_list *bl, va_list ap) {
default: //Warning: Assuming Ensemble Dance/Songs for code speed. [Skotlex]
{
uint16 skill_lv;
- if(pc_issit(tsd) || !unit_can_move(&tsd->bl))
+ if(pc_issit(tsd) || !unit->can_move(&tsd->bl))
return 0;
if (sd->status.sex != tsd->status.sex &&
(tsd->class_&MAPID_UPPERMASK) == MAPID_BARDDANCER &&
@@ -12546,7 +12546,7 @@ int skill_check_condition_castbegin(struct map_session_data* sd, uint16 skill_id
return 0;
}
}
- else if( !unit_can_move(&sd->bl) )
+ else if( !unit->can_move(&sd->bl) )
{ //Placed here as ST_MOVE_ENABLE should not apply if rooted or on a combo. [Skotlex]
clif->skill_fail(sd,skill_id,USESKILL_FAIL_LEVEL,0);
return 0;
@@ -12590,7 +12590,7 @@ int skill_check_condition_castbegin(struct map_session_data* sd, uint16 skill_id
return 0;
}
if(sc->data[SC_COMBOATTACK]->val1 != skill_id && !( sd && sd->status.base_level >= 90 && pc->famerank(sd->status.char_id, MAPID_TAEKWON) )) { //Cancel combo wait.
- unit_cancel_combo(&sd->bl);
+ unit->cancel_combo(&sd->bl);
return 0;
}
break; //Combo ready.
@@ -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;
@@ -12938,7 +12938,7 @@ int skill_check_condition_castbegin(struct map_session_data* sd, uint16 skill_id
break;
case SR_CURSEDCIRCLE:
if (map_flag_gvg2(sd->bl.m)) {
- if (iMap->foreachinrange(mob_count_sub, &sd->bl, skill->get_splash(skill_id, skill_lv), BL_MOB,
+ if (iMap->foreachinrange(mob->count_sub, &sd->bl, skill->get_splash(skill_id, skill_lv), BL_MOB,
MOBID_EMPERIUM, MOBID_GUARIDAN_STONE1, MOBID_GUARIDAN_STONE2)) {
char output[128];
sprintf(output, "You're too close to a stone or emperium to do this skill");
@@ -13093,7 +13093,7 @@ int skill_check_condition_castbegin(struct map_session_data* sd, uint16 skill_id
if (sc && sc->data[SC_COMBOATTACK] && sc->data[SC_COMBOATTACK]->val1 == skill_id)
sd->ud.canmove_tick = iTimer->gettick(); //When using a combo, cancel the can't move delay to enable the skill. [Skotlex]
- if (!unit_can_move(&sd->bl)) {
+ if (!unit->can_move(&sd->bl)) {
clif->skill_fail(sd,skill_id,USESKILL_FAIL_LEVEL,0);
return 0;
}
@@ -14614,7 +14614,7 @@ int skill_attack_area (struct block_list *bl, va_list ap)
*------------------------------------------*/
int skill_clear_group (struct block_list *bl, int flag)
{
- struct unit_data *ud = unit_bl2ud(bl);
+ struct unit_data *ud = unit->bl2ud(bl);
struct skill_unit_group *group[MAX_SKILLUNITGROUP];
int i, count=0;
@@ -14653,7 +14653,7 @@ int skill_clear_group (struct block_list *bl, int flag)
* Returns the first element field found [Skotlex]
*------------------------------------------*/
struct skill_unit_group *skill_locate_element_field(struct block_list *bl) {
- struct unit_data *ud = unit_bl2ud(bl);
+ struct unit_data *ud = unit->bl2ud(bl);
int i;
nullpo_ret(bl);
if (!ud) return NULL;
@@ -14859,7 +14859,7 @@ int skill_cell_overlap(struct block_list *bl, va_list ap) {
int skill_chastle_mob_changetarget(struct block_list *bl,va_list ap)
{
struct mob_data* md;
- struct unit_data*ud = unit_bl2ud(bl);
+ struct unit_data*ud = unit->bl2ud(bl);
struct block_list *from_bl;
struct block_list *to_bl;
md = (struct mob_data*)bl;
@@ -15247,7 +15247,7 @@ static int skill_get_new_group_id(void)
struct skill_unit_group* skill_initunitgroup (struct block_list* src, int count, uint16 skill_id, uint16 skill_lv, int unit_id, int limit, int interval)
{
- struct unit_data* ud = unit_bl2ud( src );
+ struct unit_data* ud = unit->bl2ud( src );
struct skill_unit_group* group;
int i;
@@ -15276,7 +15276,7 @@ struct skill_unit_group* skill_initunitgroup (struct block_list* src, int count,
group->src_id = src->id;
group->party_id = iStatus->get_party_id(src);
group->guild_id = iStatus->get_guild_id(src);
- group->bg_id = bg_team_get_id(src);
+ group->bg_id = bg->team_get_id(src);
group->group_id = skill_get_new_group_id();
group->unit = (struct skill_unit *)aCalloc(count,sizeof(struct skill_unit));
group->unit_count = count;
@@ -15318,7 +15318,7 @@ int skill_delunitgroup(struct skill_unit_group *group, const char* file, int lin
}
src=iMap->id2bl(group->src_id);
- ud = unit_bl2ud(src);
+ ud = unit->bl2ud(src);
if(!src || !ud) {
ShowError("skill_delunitgroup: Group's source not found! (src_id: %d skill_id: %d)\n", group->src_id, group->skill_id);
return 0;
@@ -15442,7 +15442,7 @@ int skill_delunitgroup(struct skill_unit_group *group, const char* file, int lin
*------------------------------------------*/
int skill_clear_unitgroup (struct block_list *src)
{
- struct unit_data *ud = unit_bl2ud(src);
+ struct unit_data *ud = unit->bl2ud(src);
nullpo_ret(ud);
@@ -15464,7 +15464,7 @@ struct skill_unit_group_tickset *skill_unitgrouptickset_search (struct block_lis
if (group->interval==-1)
return NULL;
- ud = unit_bl2ud(bl);
+ ud = unit->bl2ud(bl);
if (!ud) return NULL;
set = ud->skillunittick;
@@ -16125,7 +16125,7 @@ int skill_produce_mix (struct map_session_data *sd, uint16 skill_id, int nameid,
}while( j>=0 && x>0 );
}
- if( (equip = (itemdb_isequip(nameid) && skill_id != GN_CHANGEMATERIAL && skill_id != GN_MAKEBOMB )) )
+ if( (equip = (itemdb->isequip(nameid) && skill_id != GN_CHANGEMATERIAL && skill_id != GN_MAKEBOMB )) )
wlv = itemdb_wlv(nameid);
if(!equip) {
switch(skill_id){
@@ -16726,14 +16726,14 @@ int skill_magicdecoy(struct map_session_data *sd, int nameid) {
class_ = (nameid == 990 || nameid == 991) ? 2043 + nameid - 990 : (nameid == 992) ? 2046 : 2045;
- md = mob_once_spawn_sub(&sd->bl, sd->bl.m, x, y, sd->status.name, class_, "", SZ_SMALL, AI_NONE);
+ md = mob->once_spawn_sub(&sd->bl, sd->bl.m, x, y, sd->status.name, class_, "", SZ_SMALL, AI_NONE);
if( md ) {
md->master_id = sd->bl.id;
md->special_state.ai = AI_FLORA;
if( md->deletetimer != INVALID_TIMER )
- iTimer->delete_timer(md->deletetimer, mob_timer_delete);
- md->deletetimer = iTimer->add_timer (iTimer->gettick() + skill->get_time(NC_MAGICDECOY,skill_id), mob_timer_delete, md->bl.id, 0);
- mob_spawn(md);
+ iTimer->delete_timer(md->deletetimer, mob->timer_delete);
+ md->deletetimer = iTimer->add_timer (iTimer->gettick() + skill->get_time(NC_MAGICDECOY,skill_id), mob->timer_delete, md->bl.id, 0);
+ mob->spawn(md);
md->status.matk_min = md->status.matk_max = 250 + (50 * skill_id);
}
diff --git a/src/map/status.c b/src/map/status.c
index c280d80b8..ee5d4bfd5 100644
--- a/src/map/status.c
+++ b/src/map/status.c
@@ -1225,7 +1225,7 @@ int status_damage(struct block_list *src,struct block_list *target,int64 in_hp,
if(sc->data[SC_KAGEMUSYA] && --(sc->data[SC_KAGEMUSYA]->val3) <= 0)
status_change_end(target, SC_KAGEMUSYA, INVALID_TIMER);
}
- unit_skillcastcancel(target, 2);
+ unit->skillcastcancel(target, 2);
}
status->hp-= hp;
@@ -1246,20 +1246,20 @@ int status_damage(struct block_list *src,struct block_list *target,int64 in_hp,
switch (target->type) {
case BL_PC: pc->damage((TBL_PC*)target,src,hp,sp); break;
- case BL_MOB: mob_damage((TBL_MOB*)target, src, hp); break;
+ case BL_MOB: mob->damage((TBL_MOB*)target, src, hp); break;
case BL_HOM: homun->damaged((TBL_HOM*)target); break;
case BL_MER: mercenary->heal((TBL_MER*)target,hp,sp); break;
case BL_ELEM: elemental->heal((TBL_ELEM*)target,hp,sp); break;
}
if( src && target->type == BL_PC && (((TBL_PC*)target)->disguise) > 0 ) {// stop walking when attacked in disguise to prevent walk-delay bug
- unit_stop_walking( target, 1 );
+ unit->stop_walking( target, 1 );
}
if( status->hp || (flag&8) )
{ //Still lives or has been dead before this damage.
if (walkdelay)
- unit_set_walkdelay(target, iTimer->gettick(), walkdelay, 0);
+ unit->set_walkdelay(target, iTimer->gettick(), walkdelay, 0);
return (int)(hp+sp);
}
@@ -1271,7 +1271,7 @@ int status_damage(struct block_list *src,struct block_list *target,int64 in_hp,
//&4: Also delete object from memory.
switch (target->type) {
case BL_PC: flag = pc->dead((TBL_PC*)target,src); break;
- case BL_MOB: flag = mob_dead((TBL_MOB*)target, src, flag&4?3:0); break;
+ case BL_MOB: flag = mob->dead((TBL_MOB*)target, src, flag&4?3:0); break;
case BL_HOM: flag = homun->dead((TBL_HOM*)target); break;
case BL_MER: flag = mercenary->dead((TBL_MER*)target); break;
case BL_ELEM: flag = elemental->dead((TBL_ELEM*)target); break;
@@ -1339,13 +1339,13 @@ int status_damage(struct block_list *src,struct block_list *target,int64 in_hp,
iStatus->change_clear(target,0);
if(flag&4) //Delete from memory. (also invokes map removal code)
- unit_free(target,CLR_DEAD);
+ unit->free(target,CLR_DEAD);
else if(flag&2) //remove from map
- unit_remove_map(target,CLR_DEAD);
+ unit->remove_map(target,CLR_DEAD,ALC_MARK);
else { //Some death states that would normally be handled by unit_remove_map
- unit_stop_attack(target);
- unit_stop_walking(target,1);
- unit_skillcastcancel(target,0);
+ unit->stop_attack(target);
+ unit->stop_walking(target,1);
+ unit->skillcastcancel(target,0);
clif->clearunit_area(target,CLR_DEAD);
skill->unit_move(target,iTimer->gettick(),4);
skill->cleartimerskill(target);
@@ -1420,7 +1420,7 @@ int status_heal(struct block_list *bl,int64 in_hp,int64 in_sp, int flag)
// send hp update to client
switch(bl->type) {
case BL_PC: pc->heal((TBL_PC*)bl,hp,sp,flag&2?1:0); break;
- case BL_MOB: mob_heal((TBL_MOB*)bl,hp); break;
+ case BL_MOB: mob->heal((TBL_MOB*)bl,hp); break;
case BL_HOM: homun->healed((TBL_HOM*)bl); break;
case BL_MER: mercenary->heal((TBL_MER*)bl,hp,sp); break;
case BL_ELEM: elemental->heal((TBL_ELEM*)bl,hp,sp); break;
@@ -1525,7 +1525,7 @@ int status_revive(struct block_list *bl, unsigned char per_hp, unsigned char per
switch (bl->type) {
case BL_PC: pc->revive((TBL_PC*)bl, hp, sp); break;
- case BL_MOB: mob_revive((TBL_MOB*)bl, hp); break;
+ case BL_MOB: mob->revive((TBL_MOB*)bl, hp); break;
case BL_HOM: homun->revive((TBL_HOM*)bl, hp, sp); break;
}
@@ -1628,8 +1628,8 @@ int status_check_skilluse(struct block_list *src, struct block_list *target, uin
return 0;
if (sc->data[SC_DC_WINKCHARM] && target && !flag) { //Prevents skill usage
- if( unit_bl2ud(src) && (unit_bl2ud(src))->walktimer == INVALID_TIMER )
- unit_walktobl(src, iMap->id2bl(sc->data[SC_DC_WINKCHARM]->val2), 3, 1);
+ if( unit->bl2ud(src) && (unit->bl2ud(src))->walktimer == INVALID_TIMER )
+ unit->walktobl(src, iMap->id2bl(sc->data[SC_DC_WINKCHARM]->val2), 3, 1);
clif->emotion(src, E_LV);
return 0;
}
@@ -2088,7 +2088,7 @@ int status_calc_mob_(struct mob_data* md, bool first)
if (flag&16 && mbl)
{ //Max HP setting from Summon Flora/marine Sphere
- struct unit_data *ud = unit_bl2ud(mbl);
+ struct unit_data *ud = unit->bl2ud(mbl);
//Remove special AI when this is used by regular mobs.
if (mbl->type == BL_MOB && !((TBL_MOB*)mbl)->special_state.ai)
md->special_state.ai = 0;
@@ -3743,7 +3743,7 @@ void status_calc_bl_main(struct block_list *bl, /*enum scb_flag*/int flag)
}
if(flag&SCB_SPEED) {
- struct unit_data *ud = unit_bl2ud(bl);
+ struct unit_data *ud = unit->bl2ud(bl);
status->speed = status_calc_speed(bl, sc, b_status->speed);
//Re-walk to adjust speed (we do not check if walktimer != INVALID_TIMER
@@ -3798,9 +3798,9 @@ void status_calc_bl_main(struct block_list *bl, /*enum scb_flag*/int flag)
status->mode = status_calc_mode(bl, sc, b_status->mode);
//Since mode changed, reset their state.
if (!(status->mode&MD_CANATTACK))
- unit_stop_attack(bl);
+ unit->stop_attack(bl);
if (!(status->mode&MD_CANMOVE))
- unit_stop_walking(bl,1);
+ unit->stop_walking(bl,1);
}
// No status changes alter these yet.
@@ -5858,7 +5858,7 @@ struct status_data *status_get_status_data(struct block_list *bl)
case BL_HOM: return &((TBL_HOM*)bl)->battle_status;
case BL_MER: return &((TBL_MER*)bl)->battle_status;
case BL_ELEM: return &((TBL_ELEM*)bl)->battle_status;
- case BL_NPC: return ((mobdb_checkid(((TBL_NPC*)bl)->class_) == 0) ? &((TBL_NPC*)bl)->status : &dummy_status);
+ case BL_NPC: return ((mob->db_checkid(((TBL_NPC*)bl)->class_) == 0) ? &((TBL_NPC*)bl)->status : &dummy_status);
default:
return &dummy_status;
}
@@ -5874,7 +5874,7 @@ struct status_data *status_get_base_status(struct block_list *bl)
case BL_HOM: return &((TBL_HOM*)bl)->base_status;
case BL_MER: return &((TBL_MER*)bl)->base_status;
case BL_ELEM: return &((TBL_ELEM*)bl)->base_status;
- case BL_NPC: return ((mobdb_checkid(((TBL_NPC*)bl)->class_) == 0) ? &((TBL_NPC*)bl)->status : NULL);
+ case BL_NPC: return ((mob->db_checkid(((TBL_NPC*)bl)->class_) == 0) ? &((TBL_NPC*)bl)->status : NULL);
default:
return NULL;
}
@@ -5883,7 +5883,7 @@ defType status_get_def(struct block_list *bl) {
struct unit_data *ud;
struct status_data *status = iStatus->get_status_data(bl);
int def = status?status->def:0;
- ud = unit_bl2ud(bl);
+ ud = unit->bl2ud(bl);
if (ud && ud->skilltimer != INVALID_TIMER)
def -= def * skill->get_castdef(ud->skill_id)/100;
@@ -6071,10 +6071,10 @@ void status_set_viewdata(struct block_list *bl, int class_)
{
struct view_data* vd;
nullpo_retv(bl);
- if (mobdb_checkid(class_) || mob_is_clone(class_))
- vd = mob_get_viewdata(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_))
@@ -7554,7 +7554,7 @@ int status_change_start(struct block_list* bl,enum sc_type type,int rate,int val
case SC_HANBOK:
if (!vd) return 0;
//Store previous values as they could be removed.
- unit_stop_attack(bl);
+ unit->stop_attack(bl);
break;
case SC_NOCHAT:
// [GodLesZ] FIXME: is this correct? a hardcoded interval of 60sec? what about configuration ?_?
@@ -7585,7 +7585,7 @@ int status_change_start(struct block_list* bl,enum sc_type type,int rate,int val
if( val2 && bl->type == BL_MOB ) {
struct block_list* src = iMap->id2bl(val2);
if( src )
- mob_log_damage((TBL_MOB*)bl,src,diff);
+ mob->log_damage((TBL_MOB*)bl,src,diff);
}
status_zap(bl, diff, 0);
}
@@ -7867,7 +7867,7 @@ int status_change_start(struct block_list* bl,enum sc_type type,int rate,int val
if( val3 && bl->type == BL_MOB ) {
struct block_list* src = iMap->id2bl(val3);
if( src )
- mob_log_damage((TBL_MOB*)bl,src,status->hp - 1);
+ mob->log_damage((TBL_MOB*)bl,src,status->hp - 1);
}
status_zap(bl, status->hp-1, val2?0:status->sp);
return 1;
@@ -7914,11 +7914,11 @@ int status_change_start(struct block_list* bl,enum sc_type type,int rate,int val
//val3: When set, this combo time should NOT delay attack/movement
//val3: TK: Last used kick
//val4: TK: Combo time
- struct unit_data *ud = unit_bl2ud(bl);
+ struct unit_data *ud = unit->bl2ud(bl);
if (ud && !val3) {
tick += 300 * battle_config.combo_delay_rate/100;
ud->attackabletime = iTimer->gettick()+tick;
- unit_set_walkdelay(bl, iTimer->gettick(), tick, 1);
+ unit->set_walkdelay(bl, iTimer->gettick(), tick, 1);
}
val3 = 0;
val4 = tick;
@@ -8363,7 +8363,7 @@ int status_change_start(struct block_list* bl,enum sc_type type,int rate,int val
if( pc_iswug(sd) ) pc->setoption(sd, sd->sc.option&~OPTION_WUG);
if( pc_isridingwug(sd) ) pc->setoption(sd, sd->sc.option&~OPTION_WUGRIDER);
if( pc_isfalcon(sd) ) pc->setoption(sd, sd->sc.option&~OPTION_FALCON);
- if( sd->status.pet_id > 0 ) pet_menu(sd, 3);
+ if( sd->status.pet_id > 0 ) pet->menu(sd, 3);
if( homun_alive(sd->hd) ) homun->vaporize(sd,1);
if( sd->md ) mercenary->delete(sd->md,3);
}
@@ -8498,7 +8498,7 @@ int status_change_start(struct block_list* bl,enum sc_type type,int rate,int val
break;
case SC_UNLIMITED_HUMMING_VOICE:
{
- struct unit_data *ud = unit_bl2ud(bl);
+ struct unit_data *ud = unit->bl2ud(bl);
if( ud == NULL ) return 0;
ud->state.skillcastcancel = 0;
val3 = 15 - (2 * val2);
@@ -8794,7 +8794,7 @@ int status_change_start(struct block_list* bl,enum sc_type type,int rate,int val
val4 = tick / tick_time;
break;
case SC_MONSTER_TRANSFORM:
- if( !mobdb_checkid(val1) )
+ if( !mob->db_checkid(val1) )
val1 = 1002; // default poring
val_flag |= 1;
break;
@@ -8861,9 +8861,9 @@ int status_change_start(struct block_list* bl,enum sc_type type,int rate,int val
status_change_end(bl, SC_DANCING, INVALID_TIMER);
// Cancel cast when get status [LuzZza]
if (battle_config.sc_castcancel&bl->type)
- unit_skillcastcancel(bl, 0);
+ unit->skillcastcancel(bl, 0);
case SC_WHITEIMPRISON:
- unit_stop_attack(bl);
+ unit->stop_attack(bl);
case SC_STOP:
case SC_CONFUSION:
case SC_RG_CCONFINE_M:
@@ -8882,11 +8882,11 @@ int status_change_start(struct block_list* bl,enum sc_type type,int rate,int val
case SC_KYOUGAKU:
case SC_NEEDLE_OF_PARALYZE:
case SC_DEATHBOUND:
- unit_stop_walking(bl,1);
+ unit->stop_walking(bl,1);
break;
case SC_ANKLESNARE:
if( battle_config.skill_trap_type || !map_flag_gvg(bl->m) )
- unit_stop_walking(bl,1);
+ unit->stop_walking(bl,1);
break;
case SC_HIDING:
case SC_CLOAKING:
@@ -8895,11 +8895,11 @@ int status_change_start(struct block_list* bl,enum sc_type type,int rate,int val
case SC_WEIGHTOVER90:
case SC_CAMOUFLAGE:
case SC_SIREN:
- unit_stop_attack(bl);
+ unit->stop_attack(bl);
break;
case SC_SILENCE:
if (battle_config.sc_castcancel&bl->type)
- unit_skillcastcancel(bl, 0);
+ unit->skillcastcancel(bl, 0);
break;
/* */
case SC_ITEMSCRIPT:
@@ -9133,7 +9133,7 @@ int status_change_start(struct block_list* bl,enum sc_type type,int rate,int val
status_calc_bl(bl,calc_flag);
if(sd && sd->pd)
- pet_sc_check(sd, type); //Skotlex: Pet Status Effect Healing
+ pet->sc_check(sd, type); //Skotlex: Pet Status Effect Healing
switch (type) {
case SC_BERSERK:
@@ -9148,9 +9148,9 @@ int status_change_start(struct block_list* bl,enum sc_type type,int rate,int val
break;
case SC_RUN:
{
- struct unit_data *ud = unit_bl2ud(bl);
+ struct unit_data *ud = unit->bl2ud(bl);
if( ud )
- ud->state.running = unit_run(bl);
+ ud->state.running = unit->run(bl);
}
break;
case SC_CASH_BOSS_ALARM:
@@ -9167,9 +9167,9 @@ int status_change_start(struct block_list* bl,enum sc_type type,int rate,int val
**/
case SC_WUGDASH:
{
- struct unit_data *ud = unit_bl2ud(bl);
+ struct unit_data *ud = unit->bl2ud(bl);
if( ud )
- ud->state.running = unit_wugdash(bl, sd);
+ ud->state.running = unit->wugdash(bl, sd);
}
break;
case SC_COMBOATTACK:
@@ -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;
}
@@ -9365,14 +9365,14 @@ int status_change_end_(struct block_list* bl, enum sc_type type, int tid, const
break;
case SC_RUN:
{
- struct unit_data *ud = unit_bl2ud(bl);
+ struct unit_data *ud = unit->bl2ud(bl);
bool begin_spurt = true;
if (ud) {
if(!ud->state.running)
begin_spurt = false;
ud->state.running = 0;
if (ud->walktimer != INVALID_TIMER)
- unit_stop_walking(bl,1);
+ unit->stop_walking(bl,1);
}
if (begin_spurt && sce->val1 >= 7 &&
DIFF_TICK(iTimer->gettick(), sce->val4) <= 1000 &&
@@ -9681,11 +9681,11 @@ int status_change_end_(struct block_list* bl, enum sc_type type, int tid, const
break;
case SC_WUGDASH:
{
- struct unit_data *ud = unit_bl2ud(bl);
+ struct unit_data *ud = unit->bl2ud(bl);
if (ud) {
ud->state.running = 0;
if (ud->walktimer != -1)
- unit_stop_walking(bl,1);
+ unit->stop_walking(bl,1);
}
}
break;
@@ -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;
@@ -10131,8 +10131,8 @@ int status_change_timer(int tid, unsigned int tick, int id, intptr_t data)
case SC_STONE:
if(sc->opt1 == OPT1_STONEWAIT && sce->val3) {
sce->val4 = 0;
- unit_stop_walking(bl,1);
- unit_stop_attack(bl);
+ unit->stop_walking(bl,1);
+ unit->stop_attack(bl);
sc->opt1 = OPT1_STONE;
clif->changeoption(bl);
sc_timer_next(1000+tick,iStatus->change_timer, bl->id, data );
@@ -10156,7 +10156,7 @@ int status_change_timer(int tid, unsigned int tick, int id, intptr_t data)
if( sce->val2 && bl->type == BL_MOB ) {
struct block_list* src = iMap->id2bl(sce->val2);
if( src )
- mob_log_damage((TBL_MOB*)bl,src,sce->val4);
+ mob->log_damage((TBL_MOB*)bl,src,sce->val4);
}
iMap->freeblock_lock();
status_zap(bl, sce->val4, 0);
@@ -10192,7 +10192,7 @@ int status_change_timer(int tid, unsigned int tick, int id, intptr_t data)
int hp = rnd()%600 + 200;
struct block_list* src = iMap->id2bl(sce->val2);
if( src && bl && bl->type == BL_MOB ) {
- mob_log_damage((TBL_MOB*)bl,src,sd||hp<status->hp?hp:status->hp-1);
+ mob->log_damage((TBL_MOB*)bl,src,sd||hp<status->hp?hp:status->hp-1);
}
iMap->freeblock_lock();
status_fix_damage(src, bl, sd||hp<status->hp?hp:status->hp-1, 1);
@@ -10392,7 +10392,7 @@ int status_change_timer(int tid, unsigned int tick, int id, intptr_t data)
if( --(sce->val4) > 0 ) {
int damage = status->max_hp/100; // {Target VIT x (New Poison Research Skill Level - 3)} + (Target HP/100)
damage += status->vit * (sce->val1 - 3);
- unit_skillcastcancel(bl,2);
+ unit->skillcastcancel(bl,2);
iMap->freeblock_lock();
iStatus->damage(bl, bl, damage, 0, clif->damage(bl,bl,tick,status_get_amotion(bl),status_get_dmotion(bl)+500,damage,1,0,0), 1);
if( sc->data[type] ) {
@@ -10420,8 +10420,8 @@ int status_change_timer(int tid, unsigned int tick, int id, intptr_t data)
if( !flag ) { // Random Skill Cast
if (sd && !pc_issit(sd)) { //can't cast if sit
int mushroom_skill_id = 0, i;
- unit_stop_attack(bl);
- unit_skillcastcancel(bl,1);
+ unit->stop_attack(bl);
+ unit->skillcastcancel(bl,1);
do {
i = rnd() % MAX_SKILL_MAGICMUSHROOM_DB;
mushroom_skill_id = skill_magicmushroom_db[i].skill_id;
@@ -10618,7 +10618,7 @@ int status_change_timer(int tid, unsigned int tick, int id, intptr_t data)
iMap->freeblock_lock();
damage = sce->val3;
iStatus->damage(src, bl, damage, 0, clif->damage(bl,bl,tick,status->amotion,status->dmotion+200,damage,1,0,0), 1);
- unit_skillcastcancel(bl,1);
+ unit->skillcastcancel(bl,1);
if ( sc->data[type] ) {
sc_timer_next(1000 + tick, iStatus->change_timer, bl->id, data);
}
@@ -11299,7 +11299,7 @@ static int status_natural_heal(struct block_list* bl, va_list args)
if (flag && regen->state.overweight)
flag=0;
- ud = unit_bl2ud(bl);
+ ud = unit->bl2ud(bl);
if (flag&(RGN_HP|RGN_SHP|RGN_SSP) && ud && ud->walktimer != INVALID_TIMER)
{
diff --git a/src/map/storage.c b/src/map/storage.c
index 81d746cc8..2fe7607c3 100644
--- a/src/map/storage.c
+++ b/src/map/storage.c
@@ -152,7 +152,7 @@ int storage_additem(struct map_session_data* sd, struct item* item_data, int amo
return 1;
}
- if( itemdb_isstackable2(data) )
+ if( itemdb->isstackable2(data) )
{//Stackable
for( i = 0; i < MAX_STORAGE; i++ )
{
@@ -448,7 +448,7 @@ int guild_storage_additem(struct map_session_data* sd, struct guild_storage* sto
return 1;
}
- if(itemdb_isstackable2(data)){ //Stackable
+ if(itemdb->isstackable2(data)){ //Stackable
for(i=0;i<MAX_GUILD_STORAGE;i++){
if(compare_item(&stor->items[i], item_data)) {
if( amount > MAX_AMOUNT - stor->items[i].amount || ( data->stack.guildstorage && amount > data->stack.amount - stor->items[i].amount ) )
diff --git a/src/map/trade.c b/src/map/trade.c
index 9bf63c428..3134fa3e4 100644
--- a/src/map/trade.c
+++ b/src/map/trade.c
@@ -261,7 +261,7 @@ int trade_check(struct map_session_data *sd, struct map_session_data *tsd)
data = itemdb->search(inventory[n].nameid);
i = MAX_INVENTORY;
- if (itemdb_isstackable2(data)) { //Stackable item.
+ if (itemdb->isstackable2(data)) { //Stackable item.
for(i = 0; i < MAX_INVENTORY; i++)
if (inventory2[i].nameid == inventory[n].nameid &&
inventory2[i].card[0] == inventory[n].card[0] && inventory2[i].card[1] == inventory[n].card[1] &&
@@ -292,7 +292,7 @@ int trade_check(struct map_session_data *sd, struct map_session_data *tsd)
// search if it's possible to add item (for full inventory)
data = itemdb->search(inventory2[n].nameid);
i = MAX_INVENTORY;
- if (itemdb_isstackable2(data)) {
+ if (itemdb->isstackable2(data)) {
for(i = 0; i < MAX_INVENTORY; i++)
if (inventory[i].nameid == inventory2[n].nameid &&
inventory[i].card[0] == inventory2[n].card[0] && inventory[i].card[1] == inventory2[n].card[1] &&
diff --git a/src/map/unit.c b/src/map/unit.c
index d3f72421d..0551baaea 100644
--- a/src/map/unit.c
+++ b/src/map/unit.c
@@ -45,6 +45,8 @@
const short dirx[8]={0,-1,-1,-1,0,1,1,1};
const short diry[8]={1,1,0,-1,-1,-1,0,1};
+struct unit_interface unit_s;
+
/**
* Returns the unit_data for the given block_list. If the object is using
* shared unit_data (i.e. in case of BL_NPC), it returns the shared data.
@@ -71,17 +73,17 @@ 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);
- unit_dataset(&nd->bl);
+ unit->dataset(&nd->bl);
}
- return unit_bl2ud(bl);
+ return unit->bl2ud(bl);
}
-static int unit_attack_timer(int tid, unsigned int tick, int id, intptr_t data);
-static int unit_walktoxy_timer(int tid, unsigned int tick, int id, intptr_t data);
+int unit_attack_timer(int tid, unsigned int tick, int id, intptr_t data);
+int unit_walktoxy_timer(int tid, unsigned int tick, int id, intptr_t data);
int unit_walktoxy_sub(struct block_list *bl)
{
@@ -90,10 +92,10 @@ int unit_walktoxy_sub(struct block_list *bl)
struct unit_data *ud = NULL;
nullpo_retr(1, bl);
- ud = unit_bl2ud(bl);
+ ud = unit->bl2ud(bl);
if(ud == NULL) return 0;
- if( !path_search(&wpd,bl->m,bl->x,bl->y,ud->to_x,ud->to_y,ud->state.walk_easy,CELL_CHKNOPASS) )
+ if( !path->search(&wpd,bl->m,bl->x,bl->y,ud->to_x,ud->to_y,ud->state.walk_easy,CELL_CHKNOPASS) )
return 0;
memcpy(&ud->walkpath,&wpd,sizeof(wpd));
@@ -131,11 +133,11 @@ int unit_walktoxy_sub(struct block_list *bl)
else
i = iStatus->get_speed(bl);
if( i > 0)
- ud->walktimer = iTimer->add_timer(iTimer->gettick()+i,unit_walktoxy_timer,bl->id,i);
+ ud->walktimer = iTimer->add_timer(iTimer->gettick()+i,unit->walktoxy_timer,bl->id,i);
return 1;
}
-static int unit_walktoxy_timer(int tid, unsigned int tick, int id, intptr_t data)
+int unit_walktoxy_timer(int tid, unsigned int tick, int id, intptr_t data)
{
int i;
int x,y,dx,dy;
@@ -152,7 +154,7 @@ static int unit_walktoxy_timer(int tid, unsigned int tick, int id, intptr_t data
sd = BL_CAST(BL_PC, bl);
md = BL_CAST(BL_MOB, bl);
mrd = BL_CAST(BL_MER, bl);
- ud = unit_bl2ud(bl);
+ ud = unit->bl2ud(bl);
if(ud == NULL) return 0;
@@ -178,7 +180,7 @@ static int unit_walktoxy_timer(int tid, unsigned int tick, int id, intptr_t data
dy = diry[(int)dir];
if(iMap->getcell(bl->m,x+dx,y+dy,CELL_CHKNOPASS))
- return unit_walktoxy_sub(bl);
+ return unit->walktoxy_sub(bl);
//Refresh view for all those we lose sight
iMap->foreachinmovearea(clif->outsight, bl, AREA_SIZE, dx, dy, sd?BL_ALL:BL_PC, bl);
@@ -198,9 +200,9 @@ static 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
@@ -216,7 +218,7 @@ static int unit_walktoxy_timer(int tid, unsigned int tick, int id, intptr_t data
else if (DIFF_TICK(iTimer->gettick(), sd->md->masterteleport_timer) > 3000)
{
sd->md->masterteleport_timer = 0;
- unit_warp( &sd->md->bl, sd->bl.m, sd->bl.x, sd->bl.y, CLR_TELEPORT );
+ unit->warp( &sd->md->bl, sd->bl.m, sd->bl.x, sd->bl.y, CLR_TELEPORT );
}
}
else if( sd->md )
@@ -226,7 +228,7 @@ static 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--;
@@ -234,7 +236,7 @@ static int unit_walktoxy_timer(int tid, unsigned int tick, int id, intptr_t data
//But avoid triggering on stop-walk calls.
if(tid != INVALID_TIMER &&
!(ud->walk_count%WALK_SKILL_INTERVAL) &&
- mobskill_use(md, tick, -1))
+ mob->skill_use(md, tick, -1))
{
if (!(ud->skill_id == NPC_SELFDESTRUCTION && ud->skilltimer != INVALID_TIMER))
{ //Skill used, abort walking
@@ -257,7 +259,7 @@ static int unit_walktoxy_timer(int tid, unsigned int tick, int id, intptr_t data
else if (DIFF_TICK(iTimer->gettick(), mrd->masterteleport_timer) > 3000)
{
mrd->masterteleport_timer = 0;
- unit_warp( bl, mrd->master->bl.id, mrd->master->bl.x, mrd->master->bl.y, CLR_TELEPORT );
+ unit->warp( bl, mrd->master->bl.id, mrd->master->bl.x, mrd->master->bl.y, CLR_TELEPORT );
}
}
else
@@ -270,7 +272,7 @@ static int unit_walktoxy_timer(int tid, unsigned int tick, int id, intptr_t data
return 0;
if(ud->state.change_walk_target)
- return unit_walktoxy_sub(bl);
+ return unit->walktoxy_sub(bl);
ud->walkpath.path_pos++;
if(ud->walkpath.path_pos>=ud->walkpath.path_len)
@@ -281,12 +283,12 @@ static int unit_walktoxy_timer(int tid, unsigned int tick, int id, intptr_t data
i = iStatus->get_speed(bl);
if(i > 0) {
- ud->walktimer = iTimer->add_timer(tick+i,unit_walktoxy_timer,id,i);
+ ud->walktimer = iTimer->add_timer(tick+i,unit->walktoxy_timer,id,i);
if( md && DIFF_TICK(tick,md->dmgtick) < 3000 )//not required not damaged recently
clif->move(ud);
} else if(ud->state.running) {
//Keep trying to run.
- if ( !(unit_run(bl) || unit_wugdash(bl,sd)) )
+ if ( !(unit->run(bl) || unit->wugdash(bl,sd)) )
ud->state.running = 0;
}
else if (ud->target_to) {
@@ -295,7 +297,7 @@ static int unit_walktoxy_timer(int tid, unsigned int tick, int id, intptr_t data
if (!tbl || !iStatus->check_visibility(bl, tbl)) { //Cancel chase.
ud->to_x = bl->x;
ud->to_y = bl->y;
- if (tbl && bl->type == BL_MOB && mob_warpchase((TBL_MOB*)bl, tbl) )
+ if (tbl && bl->type == BL_MOB && mob->warpchase((TBL_MOB*)bl, tbl) )
return 0;
ud->target_to = 0;
return 0;
@@ -307,10 +309,10 @@ static int unit_walktoxy_timer(int tid, unsigned int tick, int id, intptr_t data
//only need this one for syncing purposes. [Skotlex]
ud->target_to = 0;
clif->fixpos(bl);
- unit_attack(bl, tbl->id, ud->state.attack_continue);
+ unit->attack(bl, tbl->id, ud->state.attack_continue);
}
} else { //Update chase-path
- unit_walktobl(bl, tbl, ud->chaserange, ud->state.walk_easy|(ud->state.attack_continue?2:0));
+ unit->walktobl(bl, tbl, ud->chaserange, ud->state.walk_easy|(ud->state.attack_continue?2:0));
return 0;
}
}
@@ -321,13 +323,13 @@ static int unit_walktoxy_timer(int tid, unsigned int tick, int id, intptr_t data
return 0;
}
-static int unit_delay_walktoxy_timer(int tid, unsigned int tick, int id, intptr_t data)
+int unit_delay_walktoxy_timer(int tid, unsigned int tick, int id, intptr_t data)
{
struct block_list *bl = iMap->id2bl(id);
if (!bl || bl->prev == NULL)
return 0;
- unit_walktoxy(bl, (short)((data>>16)&0xffff), (short)(data&0xffff), 0);
+ unit->walktoxy(bl, (short)((data>>16)&0xffff), (short)(data&0xffff), 0);
return 1;
}
@@ -343,15 +345,15 @@ int unit_walktoxy( struct block_list *bl, short x, short y, int flag)
nullpo_ret(bl);
- ud = unit_bl2ud(bl);
+ ud = unit->bl2ud(bl);
if( ud == NULL) return 0;
- if (!path_search(&wpd, bl->m, bl->x, bl->y, x, y, flag&1, CELL_CHKNOPASS)) // Count walk path cells
+ if (!path->search(&wpd, bl->m, bl->x, bl->y, x, y, flag&1, CELL_CHKNOPASS)) // Count walk path cells
return 0;
#ifdef OFFICIAL_WALKPATH
- if( !path_search_long(NULL, bl->m, bl->x, bl->y, x, y, CELL_CHKNOPASS) // Check if there is an obstacle between
+ if( !path->search_long(NULL, bl->m, bl->x, bl->y, x, y, CELL_CHKNOPASS) // Check if there is an obstacle between
&& (wpd.path_len > (battle_config.max_walk_path/17)*14) // Official number of walkable cells is 14 if and only if there is an obstacle between. [malufett]
&& (bl->type != BL_NPC) ) // If type is a NPC, please disregard.
return 0;
@@ -362,17 +364,17 @@ int unit_walktoxy( struct block_list *bl, short x, short y, int flag)
if (flag&4 && DIFF_TICK(ud->canmove_tick, iTimer->gettick()) > 0 &&
DIFF_TICK(ud->canmove_tick, iTimer->gettick()) < 2000)
{ // Delay walking command. [Skotlex]
- iTimer->add_timer(ud->canmove_tick+1, unit_delay_walktoxy_timer, bl->id, (x<<16)|(y&0xFFFF));
+ iTimer->add_timer(ud->canmove_tick+1, unit->delay_walktoxy_timer, bl->id, (x<<16)|(y&0xFFFF));
return 1;
}
- if(!(flag&2) && (!(status_get_mode(bl)&MD_CANMOVE) || !unit_can_move(bl)))
+ if(!(flag&2) && (!(status_get_mode(bl)&MD_CANMOVE) || !unit->can_move(bl)))
return 0;
ud->state.walk_easy = flag&1;
ud->to_x = x;
ud->to_y = y;
- unit_set_target(ud, 0);
+ unit->set_target(ud, 0);
sc = iStatus->get_sc(bl);
if (sc && sc->data[SC_CONFUSION]) //Randomize the target position
@@ -380,17 +382,17 @@ int unit_walktoxy( struct block_list *bl, short x, short y, int flag)
if(ud->walktimer != INVALID_TIMER) {
// When you come to the center of the grid because the change of destination while you're walking right now
- // Call a function from a timer unit_walktoxy_sub
+ // Call a function from a timer unit->walktoxy_sub
ud->state.change_walk_target = 1;
return 1;
}
if(ud->attacktimer != INVALID_TIMER) {
- iTimer->delete_timer( ud->attacktimer, unit_attack_timer );
+ iTimer->delete_timer( ud->attacktimer, unit->attack_timer );
ud->attacktimer = INVALID_TIMER;
}
- return unit_walktoxy_sub(bl);
+ return unit->walktoxy_sub(bl);
}
//To set Mob's CHASE/FOLLOW states (shouldn't be done if there's no path to reach)
@@ -402,18 +404,18 @@ static inline void set_mobstate(struct block_list* bl, int flag)
md->state.skillstate = md->state.aggressive ? MSS_FOLLOW : MSS_RUSH;
}
-static int unit_walktobl_sub(int tid, unsigned int tick, int id, intptr_t data)
+int unit_walktobl_sub(int tid, unsigned int tick, int id, intptr_t data)
{
struct block_list *bl = iMap->id2bl(id);
- struct unit_data *ud = bl?unit_bl2ud(bl):NULL;
+ struct unit_data *ud = bl?unit->bl2ud(bl):NULL;
if (ud && ud->walktimer == INVALID_TIMER && ud->target == data)
{
if (DIFF_TICK(ud->canmove_tick, tick) > 0) //Keep waiting?
- iTimer->add_timer(ud->canmove_tick+1, unit_walktobl_sub, id, data);
- else if (unit_can_move(bl))
+ iTimer->add_timer(ud->canmove_tick+1, unit->walktobl_sub, id, data);
+ else if (unit->can_move(bl))
{
- if (unit_walktoxy_sub(bl))
+ if (unit->walktoxy_sub(bl))
set_mobstate(bl, ud->state.attack_continue);
}
}
@@ -430,13 +432,13 @@ int unit_walktobl(struct block_list *bl, struct block_list *tbl, int range, int
nullpo_ret(bl);
nullpo_ret(tbl);
- ud = unit_bl2ud(bl);
+ ud = unit->bl2ud(bl);
if( ud == NULL) return 0;
if (!(status_get_mode(bl)&MD_CANMOVE))
return 0;
- if (!unit_can_reach_bl(bl, tbl, distance_bl(bl, tbl)+1, flag&1, &ud->to_x, &ud->to_y)) {
+ if (!unit->can_reach_bl(bl, tbl, distance_bl(bl, tbl)+1, flag&1, &ud->to_x, &ud->to_y)) {
ud->to_x = bl->x;
ud->to_y = bl->y;
ud->target_to = 0;
@@ -447,7 +449,7 @@ int unit_walktobl(struct block_list *bl, struct block_list *tbl, int range, int
ud->target_to = tbl->id;
ud->chaserange = range; //Note that if flag&2, this SHOULD be attack-range
ud->state.attack_continue = flag&2?1:0; //Chase to attack.
- unit_set_target(ud, 0);
+ unit->set_target(ud, 0);
sc = iStatus->get_sc(bl);
if (sc && sc->data[SC_CONFUSION]) //Randomize the target position
@@ -461,19 +463,19 @@ int unit_walktobl(struct block_list *bl, struct block_list *tbl, int range, int
if(DIFF_TICK(ud->canmove_tick, iTimer->gettick()) > 0)
{ //Can't move, wait a bit before invoking the movement.
- iTimer->add_timer(ud->canmove_tick+1, unit_walktobl_sub, bl->id, ud->target);
+ iTimer->add_timer(ud->canmove_tick+1, unit->walktobl_sub, bl->id, ud->target);
return 1;
}
- if(!unit_can_move(bl))
+ if(!unit->can_move(bl))
return 0;
if(ud->attacktimer != INVALID_TIMER) {
- iTimer->delete_timer( ud->attacktimer, unit_attack_timer );
+ iTimer->delete_timer( ud->attacktimer, unit->attack_timer );
ud->attacktimer = INVALID_TIMER;
}
- if (unit_walktoxy_sub(bl)) {
+ if (unit->walktoxy_sub(bl)) {
set_mobstate(bl, flag&2);
return 1;
}
@@ -490,7 +492,7 @@ int unit_run(struct block_list *bl)
if (!(sc && sc->data[SC_RUN]))
return 0;
- if (!unit_can_move(bl)) {
+ if (!unit->can_move(bl)) {
status_change_end(bl, SC_RUN, INVALID_TIMER);
return 0;
}
@@ -520,30 +522,30 @@ int unit_run(struct block_list *bl)
clif->sc_load(bl,bl->id,AREA,SI_TING,0,0,0);
//Set running to 0 beforehand so status_change_end knows not to enable spurt [Kevin]
- unit_bl2ud(bl)->state.running = 0;
+ unit->bl2ud(bl)->state.running = 0;
status_change_end(bl, SC_RUN, INVALID_TIMER);
- skill->blown(bl,bl,skill->get_blewcount(TK_RUN,lv),unit_getdir(bl),0);
+ skill->blown(bl,bl,skill->get_blewcount(TK_RUN,lv),unit->getdir(bl),0);
clif->fixpos(bl); //Why is a clif->slide (skill->blown) AND a fixpos needed? Ask Aegis.
clif->sc_end(bl,bl->id,AREA,SI_TING);
return 0;
}
- if (unit_walktoxy(bl, to_x, to_y, 1))
+ if (unit->walktoxy(bl, to_x, to_y, 1))
return 1;
//There must be an obstacle nearby. Attempt walking one cell at a time.
do {
to_x -= dir_x;
to_y -= dir_y;
- } while (--i > 0 && !unit_walktoxy(bl, to_x, to_y, 1));
+ } while (--i > 0 && !unit->walktoxy(bl, to_x, to_y, 1));
if ( i == 0 ) {
// copy-paste from above
clif->sc_load(bl,bl->id,AREA,SI_TING,0,0,0);
//Set running to 0 beforehand so status_change_end knows not to enable spurt [Kevin]
- unit_bl2ud(bl)->state.running = 0;
+ unit->bl2ud(bl)->state.running = 0;
status_change_end(bl, SC_RUN, INVALID_TIMER);
- skill->blown(bl,bl,skill->get_blewcount(TK_RUN,lv),unit_getdir(bl),0);
+ skill->blown(bl,bl,skill->get_blewcount(TK_RUN,lv),unit->getdir(bl),0);
clif->fixpos(bl);
clif->sc_end(bl,bl->id,AREA,SI_TING);
return 0;
@@ -563,7 +565,7 @@ int unit_wugdash(struct block_list *bl, struct map_session_data *sd) {
nullpo_ret(sd);
nullpo_ret(bl);
- if (!unit_can_move(bl)) {
+ if (!unit->can_move(bl)) {
status_change_end(bl,SC_WUGDASH,INVALID_TIMER);
return 0;
}
@@ -588,7 +590,7 @@ int unit_wugdash(struct block_list *bl, struct map_session_data *sd) {
if(to_x == bl->x && to_y == bl->y) {
- unit_bl2ud(bl)->state.running = 0;
+ unit->bl2ud(bl)->state.running = 0;
status_change_end(bl,SC_WUGDASH,INVALID_TIMER);
if( sd ){
@@ -597,15 +599,15 @@ int unit_wugdash(struct block_list *bl, struct map_session_data *sd) {
}
return 0;
}
- if (unit_walktoxy(bl, to_x, to_y, 1))
+ if (unit->walktoxy(bl, to_x, to_y, 1))
return 1;
do {
to_x -= dir_x;
to_y -= dir_y;
- } while (--i > 0 && !unit_walktoxy(bl, to_x, to_y, 1));
+ } while (--i > 0 && !unit->walktoxy(bl, to_x, to_y, 1));
if (i==0) {
- unit_bl2ud(bl)->state.running = 0;
+ unit->bl2ud(bl)->state.running = 0;
status_change_end(bl,SC_WUGDASH,INVALID_TIMER);
if( sd ){
@@ -623,7 +625,7 @@ int unit_escape(struct block_list *bl, struct block_list *target, short dist)
uint8 dir = iMap->calc_dir(target, bl->x, bl->y);
while( dist > 0 && iMap->getcell(bl->m, bl->x + dist*dirx[dir], bl->y + dist*diry[dir], CELL_CHKNOREACH) )
dist--;
- return ( dist > 0 && unit_walktoxy(bl, bl->x + dist*dirx[dir], bl->y + dist*diry[dir], 0) );
+ return ( dist > 0 && unit->walktoxy(bl, bl->x + dist*dirx[dir], bl->y + dist*diry[dir], 0) );
}
//Instant warp function.
@@ -636,14 +638,14 @@ int unit_movepos(struct block_list *bl, short dst_x, short dst_y, int easy, bool
nullpo_ret(bl);
sd = BL_CAST(BL_PC, bl);
- ud = unit_bl2ud(bl);
+ ud = unit->bl2ud(bl);
if( ud == NULL) return 0;
- unit_stop_walking(bl,1);
- unit_stop_attack(bl);
+ unit->stop_walking(bl,1);
+ unit->stop_attack(bl);
- if( checkpath && (iMap->getcell(bl->m,dst_x,dst_y,CELL_CHKNOPASS) || !path_search(NULL,bl->m,bl->x,bl->y,dst_x,dst_y,easy,CELL_CHKNOREACH)) )
+ if( checkpath && (iMap->getcell(bl->m,dst_x,dst_y,CELL_CHKNOPASS) || !path->search(NULL,bl->m,bl->x,bl->y,dst_x,dst_y,easy,CELL_CHKNOREACH)) )
return 0; // unreachable
ud->to_x = dst_x;
@@ -665,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
@@ -677,13 +679,13 @@ int unit_movepos(struct block_list *bl, short dst_x, short dst_y, int easy, bool
{ // Check if pet needs to be teleported. [Skotlex]
int flag = 0;
struct block_list* bl = &sd->pd->bl;
- if( !checkpath && !path_search(NULL,bl->m,bl->x,bl->y,dst_x,dst_y,0,CELL_CHKNOPASS) )
+ if( !checkpath && !path->search(NULL,bl->m,bl->x,bl->y,dst_x,dst_y,0,CELL_CHKNOPASS) )
flag = 1;
else if (!check_distance_bl(&sd->bl, bl, AREA_SIZE)) //Too far, teleport.
flag = 2;
if( flag )
{
- unit_movepos(bl,sd->bl.x,sd->bl.y, 0, 0);
+ unit->movepos(bl,sd->bl.x,sd->bl.y, 0, 0);
clif->slide(bl,bl->x,bl->y);
}
}
@@ -695,7 +697,7 @@ int unit_setdir(struct block_list *bl,unsigned char dir)
{
struct unit_data *ud;
nullpo_ret(bl );
- ud = unit_bl2ud(bl);
+ ud = unit->bl2ud(bl);
if (!ud) return 0;
ud->dir = dir;
if (bl->type == BL_PC)
@@ -710,7 +712,7 @@ uint8 unit_getdir(struct block_list *bl) {
if( bl->type == BL_NPC )
return ((TBL_NPC*)bl)->dir;
- ud = unit_bl2ud(bl);
+ ud = unit->bl2ud(bl);
if (!ud) return 0;
return ud->dir;
}
@@ -729,13 +731,13 @@ int unit_blown(struct block_list* bl, int dx, int dy, int count, int flag)
sd = BL_CAST(BL_PC, bl);
su = BL_CAST(BL_SKILL, bl);
- result = path_blownpos(bl->m, bl->x, bl->y, dx, dy, count);
+ result = path->blownpos(bl->m, bl->x, bl->y, dx, dy, count);
nx = result>>16;
ny = result&0xffff;
if(!su) {
- unit_stop_walking(bl, 0);
+ unit->stop_walking(bl, 0);
}
if( sd ) {
@@ -763,17 +765,17 @@ 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;
}
}
}
- count = distance(dx, dy);
+ count = path->distance(dx, dy);
}
return count; // return amount of knocked back cells
@@ -786,7 +788,7 @@ int unit_warp(struct block_list *bl,short m,short x,short y,clr_type type)
{
struct unit_data *ud;
nullpo_ret(bl);
- ud = unit_bl2ud(bl);
+ ud = unit->bl2ud(bl);
if(bl->prev==NULL || !ud)
return 1;
@@ -832,7 +834,7 @@ int unit_warp(struct block_list *bl,short m,short x,short y,clr_type type)
if (bl->type == BL_PC) //Use pc_setpos
return pc->setpos((TBL_PC*)bl, map_id2index(m), x, y, type);
- if (!unit_remove_map(bl, type))
+ if (!unit->remove_map(bl, type, ALC_MARK))
return 3;
if (bl->m != m && battle_config.clear_unit_onwarp &&
@@ -865,14 +867,14 @@ int unit_stop_walking(struct block_list *bl,int type)
unsigned int tick;
nullpo_ret(bl);
- ud = unit_bl2ud(bl);
+ ud = unit->bl2ud(bl);
if(!ud || ud->walktimer == INVALID_TIMER)
return 0;
//NOTE: We are using timer data after deleting it because we know the
//iTimer->delete_timer function does not messes with it. If the function's
//behaviour changes in the future, this code could break!
td = iTimer->get_timer(ud->walktimer);
- iTimer->delete_timer(ud->walktimer, unit_walktoxy_timer);
+ iTimer->delete_timer(ud->walktimer, unit->walktoxy_timer);
ud->walktimer = INVALID_TIMER;
ud->state.change_walk_target = 0;
tick = iTimer->gettick();
@@ -880,7 +882,7 @@ int unit_stop_walking(struct block_list *bl,int type)
|| (type&0x04 && td && DIFF_TICK(td->tick, tick) <= td->data/2) //Enough time has passed to cover half-cell
) {
ud->walkpath.path_len = ud->walkpath.path_pos+1;
- unit_walktoxy_timer(INVALID_TIMER, tick, bl->id, ud->walkpath.path_pos);
+ unit->walktoxy_timer(INVALID_TIMER, tick, bl->id, ud->walkpath.path_pos);
}
if(type&0x01)
@@ -903,7 +905,7 @@ int unit_stop_walking(struct block_list *bl,int type)
int unit_skilluse_id(struct block_list *src, int target_id, uint16 skill_id, uint16 skill_lv)
{
- return unit_skilluse_id2(
+ return unit->skilluse_id2(
src, target_id, skill_id, skill_lv,
skill->cast_fix(src, skill_id, skill_lv),
skill->get_castcancel(skill_id)
@@ -912,7 +914,7 @@ int unit_skilluse_id(struct block_list *src, int target_id, uint16 skill_id, uin
int unit_is_walking(struct block_list *bl)
{
- struct unit_data *ud = unit_bl2ud(bl);
+ struct unit_data *ud = unit->bl2ud(bl);
nullpo_ret(bl);
if(!ud) return 0;
return (ud->walktimer != INVALID_TIMER);
@@ -927,7 +929,7 @@ int unit_can_move(struct block_list *bl) {
struct status_change *sc;
nullpo_ret(bl);
- ud = unit_bl2ud(bl);
+ ud = unit->bl2ud(bl);
sc = iStatus->get_sc(bl);
sd = BL_CAST(BL_PC, bl);
@@ -1013,10 +1015,10 @@ int unit_resume_running(int tid, unsigned int tick, int id, intptr_t data)
if(sd && pc_isridingwug(sd))
clif->skill_nodamage(ud->bl,ud->bl,RA_WUGDASH,ud->skill_lv,
- sc_start4(ud->bl,iStatus->skill2sc(RA_WUGDASH),100,ud->skill_lv,unit_getdir(ud->bl),0,0,1));
+ sc_start4(ud->bl,iStatus->skill2sc(RA_WUGDASH),100,ud->skill_lv,unit->getdir(ud->bl),0,0,1));
else
clif->skill_nodamage(ud->bl,ud->bl,TK_RUN,ud->skill_lv,
- sc_start4(ud->bl,iStatus->skill2sc(TK_RUN),100,ud->skill_lv,unit_getdir(ud->bl),0,0,0));
+ sc_start4(ud->bl,iStatus->skill2sc(TK_RUN),100,ud->skill_lv,unit->getdir(ud->bl),0,0,0));
if (sd) clif->walkok(sd);
@@ -1032,7 +1034,7 @@ int unit_resume_running(int tid, unsigned int tick, int id, intptr_t data)
*------------------------------------------*/
int unit_set_walkdelay(struct block_list *bl, unsigned int tick, int delay, int type)
{
- struct unit_data *ud = unit_bl2ud(bl);
+ struct unit_data *ud = unit->bl2ud(bl);
if (delay <= 0 || !ud) return 0;
/**
@@ -1046,7 +1048,7 @@ int unit_set_walkdelay(struct block_list *bl, unsigned int tick, int delay, int
return 0;
} else {
//Don't set walk delays when already trapped.
- if (!unit_can_move(bl))
+ if (!unit->can_move(bl))
return 0;
}
ud->canmove_tick = tick + delay;
@@ -1054,18 +1056,18 @@ int unit_set_walkdelay(struct block_list *bl, unsigned int tick, int delay, int
{ //Stop walking, if chasing, readjust timers.
if (delay == 1)
{ //Minimal delay (walk-delay) disabled. Just stop walking.
- unit_stop_walking(bl,4);
+ unit->stop_walking(bl,4);
} else {
//Resume running after can move again [Kevin]
if(ud->state.running)
{
- iTimer->add_timer(ud->canmove_tick, unit_resume_running, bl->id, (intptr_t)ud);
+ iTimer->add_timer(ud->canmove_tick, unit->resume_running, bl->id, (intptr_t)ud);
}
else
{
- unit_stop_walking(bl,2|4);
+ unit->stop_walking(bl,2|4);
if(ud->target)
- iTimer->add_timer(ud->canmove_tick+1, unit_walktobl_sub, bl->id, ud->target);
+ iTimer->add_timer(ud->canmove_tick+1, unit->walktobl_sub, bl->id, ud->target);
}
}
}
@@ -1087,7 +1089,7 @@ int unit_skilluse_id2(struct block_list *src, int target_id, uint16 skill_id, ui
return 0; //Do not continue source is dead
sd = BL_CAST(BL_PC, src);
- ud = unit_bl2ud(src);
+ ud = unit->bl2ud(src);
if(ud == NULL) return 0;
sc = iStatus->get_sc(src);
@@ -1157,7 +1159,7 @@ int unit_skilluse_id2(struct block_list *src, int target_id, uint16 skill_id, ui
if( !target || src->m != target->m || !src->prev || !target->prev )
return 0;
- if( battle_config.ksprotection && sd && mob_ksprotected(src, target) )
+ if( battle_config.ksprotection && sd && mob->ksprotected(src, target) )
return 0;
//Normally not needed because clif.c checks for it, but the at/char/script commands don't! [Skotlex]
@@ -1234,7 +1236,7 @@ int unit_skilluse_id2(struct block_list *src, int target_id, uint16 skill_id, ui
//(these are supposed to always have the same range as your attack)
if( src->id != target_id && (!temp || ud->attacktimer == INVALID_TIMER) ) {
if( skill->get_state(ud->skill_id) == ST_MOVE_ENABLE ) {
- if( !unit_can_reach_bl(src, target, range + 1, 1, NULL, NULL) )
+ if( !unit->can_reach_bl(src, target, range + 1, 1, NULL, NULL) )
return 0; // Walk-path check failed.
} else if( src->type == BL_MER && skill_id == MA_REMOVETRAP ) {
if( !battle->check_range(battle->get_master(src), target, range + 1) )
@@ -1245,7 +1247,7 @@ int unit_skilluse_id2(struct block_list *src, int target_id, uint16 skill_id, ui
}
if (!temp) //Stop attack on non-combo skills [Skotlex]
- unit_stop_attack(src);
+ unit->stop_attack(src);
else if(ud->attacktimer != INVALID_TIMER) //Elsewise, delay current attack sequence
ud->attackabletime = tick + status_get_adelay(src);
@@ -1349,7 +1351,7 @@ int unit_skilluse_id2(struct block_list *src, int target_id, uint16 skill_id, ui
}
if(!ud->state.running) //need TK_RUN or WUGDASH handler to be done before that, see bugreport:6026
- unit_stop_walking(src,1);// eventhough this is not how official works but this will do the trick. bugreport:6829
+ unit->stop_walking(src,1);// eventhough this is not how official works but this will do the trick. bugreport:6829
// in official this is triggered even if no cast time.
clif->skillcasting(src, src->id, target_id, 0,0, skill_id, skill->get_ele(skill_id, skill_lv), casttime);
@@ -1358,7 +1360,7 @@ int unit_skilluse_id2(struct block_list *src, int target_id, uint16 skill_id, ui
if (sd && target->type == BL_MOB)
{
TBL_MOB *md = (TBL_MOB*)target;
- mobskill_event(md, src, tick, -1); //Cast targetted skill event.
+ mob->skill_event(md, src, tick, -1); //Cast targetted skill event.
if (tstatus->mode&(MD_CASTSENSOR_IDLE|MD_CASTSENSOR_CHASE) &&
battle->check_target(target, src, BCT_ENEMY) > 0)
{
@@ -1430,7 +1432,7 @@ int unit_skilluse_id2(struct block_list *src, int target_id, uint16 skill_id, ui
int unit_skilluse_pos(struct block_list *src, short skill_x, short skill_y, uint16 skill_id, uint16 skill_lv)
{
- return unit_skilluse_pos2(
+ return unit->skilluse_pos2(
src, skill_x, skill_y, skill_id, skill_lv,
skill->cast_fix(src, skill_id, skill_lv),
skill->get_castcancel(skill_id)
@@ -1452,7 +1454,7 @@ int unit_skilluse_pos2( struct block_list *src, short skill_x, short skill_y, ui
if(iStatus->isdead(src)) return 0;
sd = BL_CAST(BL_PC, src);
- ud = unit_bl2ud(src);
+ ud = unit->bl2ud(src);
if(ud == NULL) return 0;
if(ud->skilltimer != INVALID_TIMER) //Normally not needed since clif.c checks for it, but at/char/script commands don't! [Skotlex]
@@ -1501,12 +1503,12 @@ int unit_skilluse_pos2( struct block_list *src, short skill_x, short skill_y, ui
range = skill->get_range2(src, skill_id, skill_lv); // Skill cast distance from database
if( skill->get_state(ud->skill_id) == ST_MOVE_ENABLE ) {
- if( !unit_can_reach_bl(src, &bl, range + 1, 1, NULL, NULL) )
+ if( !unit->can_reach_bl(src, &bl, range + 1, 1, NULL, NULL) )
return 0; //Walk-path check failed.
} else if( !battle->check_range(src, &bl, range + 1) )
return 0; //Arrow-path check failed.
- unit_stop_attack(src);
+ unit->stop_attack(src);
// moved here to prevent Suffragium from ending if skill fails
#ifndef RENEWAL_CAST
@@ -1550,7 +1552,7 @@ int unit_skilluse_pos2( struct block_list *src, short skill_x, short skill_y, ui
}
}
- unit_stop_walking(src,1);
+ unit->stop_walking(src,1);
// in official this is triggered even if no cast time.
clif->skillcasting(src, src->id, 0, skill_x, skill_y, skill_id, skill->get_ele(skill_id, skill_lv), casttime);
if( casttime > 0 ) {
@@ -1575,9 +1577,9 @@ int unit_set_target(struct unit_data* ud, int target_id)
nullpo_ret(ud);
if( ud->target != target_id ) {
- if( ud->target && (target = iMap->id2bl(ud->target)) && (ux = unit_bl2ud(target)) && ux->target_count > 0 )
+ if( ud->target && (target = iMap->id2bl(ud->target)) && (ux = unit->bl2ud(target)) && ux->target_count > 0 )
ux->target_count --;
- if( target_id && (target = iMap->id2bl(target_id)) && (ux = unit_bl2ud(target)) )
+ if( target_id && (target = iMap->id2bl(target_id)) && (ux = unit->bl2ud(target)) )
ux->target_count ++;
}
@@ -1587,31 +1589,31 @@ int unit_set_target(struct unit_data* ud, int target_id)
int unit_stop_attack(struct block_list *bl)
{
- struct unit_data *ud = unit_bl2ud(bl);
+ struct unit_data *ud = unit->bl2ud(bl);
nullpo_ret(bl);
if(!ud || ud->attacktimer == INVALID_TIMER)
return 0;
- iTimer->delete_timer( ud->attacktimer, unit_attack_timer );
+ iTimer->delete_timer( ud->attacktimer, unit->attack_timer );
ud->attacktimer = INVALID_TIMER;
- unit_set_target(ud, 0);
+ unit->set_target(ud, 0);
return 0;
}
//Means current target is unattackable. For now only unlocks mobs.
int unit_unattackable(struct block_list *bl)
{
- struct unit_data *ud = unit_bl2ud(bl);
+ struct unit_data *ud = unit->bl2ud(bl);
if (ud) {
ud->state.attack_continue = 0;
- unit_set_target(ud, 0);
+ unit->set_target(ud, 0);
}
if(bl->type == BL_MOB)
- mob_unlocktarget((struct mob_data*)bl, iTimer->gettick()) ;
+ mob->unlocktarget((struct mob_data*)bl, iTimer->gettick()) ;
else if(bl->type == BL_PET)
- pet_unlocktarget((struct pet_data*)bl);
+ pet->unlocktarget((struct pet_data*)bl);
return 0;
}
@@ -1624,31 +1626,31 @@ int unit_attack(struct block_list *src,int target_id,int continuous)
struct block_list *target;
struct unit_data *ud;
- nullpo_ret(ud = unit_bl2ud(src));
+ nullpo_ret(ud = unit->bl2ud(src));
target = iMap->id2bl(target_id);
if( target==NULL || iStatus->isdead(target) ) {
- unit_unattackable(src);
+ unit->unattackable(src);
return 1;
}
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
- unit_stop_attack(src);
+ unit->stop_attack(src);
return 0;
}
}
if( battle->check_target(src,target,BCT_ENEMY) <= 0 || !iStatus->check_skilluse(src, target, 0, 0) ) {
- unit_unattackable(src);
+ unit->unattackable(src);
return 1;
}
ud->state.attack_continue = continuous;
- unit_set_target(ud, target_id);
+ unit->set_target(ud, target_id);
if (continuous) //If you're to attack continously, set to auto-case character
ud->chaserange = status_get_range(src);
@@ -1663,9 +1665,9 @@ int unit_attack(struct block_list *src,int target_id,int continuous)
if(DIFF_TICK(ud->attackabletime, iTimer->gettick()) > 0)
//Do attack next time it is possible. [Skotlex]
- ud->attacktimer=iTimer->add_timer(ud->attackabletime,unit_attack_timer,src->id,0);
+ ud->attacktimer=iTimer->add_timer(ud->attackabletime,unit->attack_timer,src->id,0);
else //Attack NOW.
- unit_attack_timer(INVALID_TIMER, iTimer->gettick(), src->id, 0);
+ unit->attack_timer(INVALID_TIMER, iTimer->gettick(), src->id, 0);
return 0;
}
@@ -1679,7 +1681,7 @@ int unit_cancel_combo(struct block_list *bl)
if (!status_change_end(bl, SC_COMBOATTACK, INVALID_TIMER))
return 0; //Combo wasn't active.
- ud = unit_bl2ud(bl);
+ ud = unit->bl2ud(bl);
nullpo_ret(ud);
ud->attackabletime = iTimer->gettick() + status_get_amotion(bl);
@@ -1687,8 +1689,8 @@ int unit_cancel_combo(struct block_list *bl)
if (ud->attacktimer == INVALID_TIMER)
return 1; //Nothing more to do.
- iTimer->delete_timer(ud->attacktimer, unit_attack_timer);
- ud->attacktimer=iTimer->add_timer(ud->attackabletime,unit_attack_timer,bl->id,0);
+ iTimer->delete_timer(ud->attacktimer, unit->attack_timer);
+ ud->attacktimer=iTimer->add_timer(ud->attackabletime,unit->attack_timer,bl->id,0);
return 1;
}
/*==========================================
@@ -1701,7 +1703,7 @@ bool unit_can_reach_pos(struct block_list *bl,int x,int y, int easy)
if (bl->x == x && bl->y == y) //Same place
return true;
- return path_search(NULL,bl->m,bl->x,bl->y,x,y,easy,CELL_CHKNOREACH);
+ return path->search(NULL,bl->m,bl->x,bl->y,x,y,easy,CELL_CHKNOREACH);
}
/*==========================================
@@ -1739,7 +1741,7 @@ bool unit_can_reach_bl(struct block_list *bl,struct block_list *tbl, int range,
if (x) *x = tbl->x-dx;
if (y) *y = tbl->y-dy;
- return path_search(NULL,bl->m,bl->x,bl->y,tbl->x-dx,tbl->y-dy,easy,CELL_CHKNOREACH);
+ return path->search(NULL,bl->m,bl->x,bl->y,tbl->x-dx,tbl->y-dy,easy,CELL_CHKNOREACH);
}
/*==========================================
* Calculates position of Pet/Mercenary/Homunculus/Elemental
@@ -1747,7 +1749,7 @@ bool unit_can_reach_bl(struct block_list *bl,struct block_list *tbl, int range,
int unit_calc_pos(struct block_list *bl, int tx, int ty, uint8 dir)
{
int dx, dy, x, y, i, k;
- struct unit_data *ud = unit_bl2ud(bl);
+ struct unit_data *ud = unit->bl2ud(bl);
nullpo_ret(ud);
if(dir > 7)
@@ -1762,11 +1764,11 @@ int unit_calc_pos(struct block_list *bl, int tx, int ty, uint8 dir)
x = tx + dx;
y = ty + dy;
- if( !unit_can_reach_pos(bl, x, y, 0) )
+ if( !unit->can_reach_pos(bl, x, y, 0) )
{
if( dx > 0 ) x--; else if( dx < 0 ) x++;
if( dy > 0 ) y--; else if( dy < 0 ) y++;
- if( !unit_can_reach_pos(bl, x, y, 0) )
+ if( !unit->can_reach_pos(bl, x, y, 0) )
{
for( i = 0; i < 12; i++ )
{
@@ -1775,20 +1777,20 @@ int unit_calc_pos(struct block_list *bl, int tx, int ty, uint8 dir)
dy = -diry[k] * 2;
x = tx + dx;
y = ty + dy;
- if( unit_can_reach_pos(bl, x, y, 0) )
+ if( unit->can_reach_pos(bl, x, y, 0) )
break;
else
{
if( dx > 0 ) x--; else if( dx < 0 ) x++;
if( dy > 0 ) y--; else if( dy < 0 ) y++;
- if( unit_can_reach_pos(bl, x, y, 0) )
+ if( unit->can_reach_pos(bl, x, y, 0) )
break;
}
}
if( i == 12 )
{
x = tx; y = tx; // Exactly Master Position
- if( !unit_can_reach_pos(bl, x, y, 0) )
+ if( !unit->can_reach_pos(bl, x, y, 0) )
return 1;
}
}
@@ -1802,7 +1804,7 @@ int unit_calc_pos(struct block_list *bl, int tx, int ty, uint8 dir)
/*==========================================
* Continuous Attack (function timer)
*------------------------------------------*/
-static int unit_attack_timer_sub(struct block_list* src, int tid, unsigned int tick)
+int unit_attack_timer_sub(struct block_list* src, int tid, unsigned int tick)
{
struct block_list *target;
struct unit_data *ud;
@@ -1811,7 +1813,7 @@ static int unit_attack_timer_sub(struct block_list* src, int tid, unsigned int t
struct mob_data *md = NULL;
int range;
- if( (ud=unit_bl2ud(src))==NULL )
+ if( (ud=unit->bl2ud(src))==NULL )
return 0;
if( ud->attacktimer != tid )
{
@@ -1830,14 +1832,14 @@ static int unit_attack_timer_sub(struct block_list* src, int tid, unsigned int t
if( iStatus->isdead(src) || iStatus->isdead(target) ||
battle->check_target(src,target,BCT_ENEMY) <= 0 || !iStatus->check_skilluse(src, target, 0, 0)
#ifdef OFFICIAL_WALKPATH
- || !path_search_long(NULL, src->m, src->x, src->y, target->x, target->y, CELL_CHKWALL)
+ || !path->search_long(NULL, src->m, src->x, src->y, target->x, target->y, CELL_CHKWALL)
#endif
)
return 0; // can't attack under these conditions
if( src->m != target->m )
{
- if( src->type == BL_MOB && mob_warpchase((TBL_MOB*)src, target) )
+ if( src->type == BL_MOB && mob->warpchase((TBL_MOB*)src, target) )
return 1; // Follow up.
return 0;
}
@@ -1855,7 +1857,7 @@ static int unit_attack_timer_sub(struct block_list* src, int tid, unsigned int t
if( ud->state.attack_continue ) {
if( DIFF_TICK(ud->canact_tick, ud->attackabletime) > 0 )
ud->attackabletime = ud->canact_tick;
- ud->attacktimer=iTimer->add_timer(ud->attackabletime,unit_attack_timer,src->id,0);
+ ud->attacktimer=iTimer->add_timer(ud->attackabletime,unit->attack_timer,src->id,0);
}
return 1;
}
@@ -1863,20 +1865,20 @@ static int unit_attack_timer_sub(struct block_list* src, int tid, unsigned int t
sstatus = iStatus->get_status_data(src);
range = sstatus->rhw.range + 1;
- if( unit_is_walking(target) )
+ if( unit->is_walking(target) )
range++; //Extra range when chasing
if( !check_distance_bl(src,target,range) ) { //Chase if required.
if(sd)
clif->movetoattack(sd,target);
else if(ud->state.attack_continue)
- unit_walktobl(src,target,ud->chaserange,ud->state.walk_easy|2);
+ unit->walktobl(src,target,ud->chaserange,ud->state.walk_easy|2);
return 1;
}
if( !battle->check_range(src,target,range) ) {
//Within range, but no direct line of attack
if( ud->state.attack_continue ) {
if(ud->chaserange > 2) ud->chaserange-=2;
- unit_walktobl(src,target,ud->chaserange,ud->state.walk_easy|2);
+ unit->walktobl(src,target,ud->chaserange,ud->state.walk_easy|2);
}
return 1;
}
@@ -1890,24 +1892,24 @@ static int unit_attack_timer_sub(struct block_list* src, int tid, unsigned int t
ud->dir = iMap->calc_dir(src, target->x,target->y );
}
if(ud->walktimer != INVALID_TIMER)
- unit_stop_walking(src,1);
+ unit->stop_walking(src,1);
if(md) {
- if (mobskill_use(md,tick,-1))
+ if (mob->skill_use(md,tick,-1))
return 1;
if (sstatus->mode&MD_ASSIST && DIFF_TICK(md->last_linktime, tick) < MIN_MOBLINKTIME)
{ // Link monsters nearby [Skotlex]
md->last_linktime = tick;
- iMap->foreachinrange(mob_linksearch, src, md->db->range2, BL_MOB, md->class_, target, tick);
+ iMap->foreachinrange(mob->linksearch, src, md->db->range2, BL_MOB, md->class_, target, tick);
}
}
- if(src->type == BL_PET && pet_attackskill((TBL_PET*)src, target->id))
+ if(src->type == BL_PET && pet->attackskill((TBL_PET*)src, target->id))
return 1;
iMap->freeblock_lock();
ud->attacktarget_lv = battle->weapon_attack(src,target,tick,0);
if(sd && sd->status.pet_id > 0 && sd->pd && battle_config.pet_attack_support)
- pet_target_check(sd,target,0);
+ pet->target_check(sd,target,0);
iMap->freeblock_unlock();
/**
* Applied when you're unable to attack (e.g. out of ammo)
@@ -1919,24 +1921,24 @@ static int unit_attack_timer_sub(struct block_list* src, int tid, unsigned int t
ud->attackabletime = tick + sstatus->adelay;
// You can't move if you can't attack neither.
if (src->type&battle_config.attack_walk_delay)
- unit_set_walkdelay(src, tick, sstatus->amotion, 1);
+ unit->set_walkdelay(src, tick, sstatus->amotion, 1);
}
if(ud->state.attack_continue) {
if( src->type == BL_PC )
((TBL_PC*)src)->idletime = last_tick;
- ud->attacktimer = iTimer->add_timer(ud->attackabletime,unit_attack_timer,src->id,0);
+ ud->attacktimer = iTimer->add_timer(ud->attackabletime,unit->attack_timer,src->id,0);
}
return 1;
}
-static int unit_attack_timer(int tid, unsigned int tick, int id, intptr_t data)
+int unit_attack_timer(int tid, unsigned int tick, int id, intptr_t data)
{
struct block_list *bl;
bl = iMap->id2bl(id);
- if(bl && unit_attack_timer_sub(bl, tid, tick) == 0)
- unit_unattackable(bl);
+ if(bl && unit->attack_timer_sub(bl, tid, tick) == 0)
+ unit->unattackable(bl);
return 0;
}
@@ -1948,7 +1950,7 @@ static int unit_attack_timer(int tid, unsigned int tick, int id, intptr_t data)
int unit_skillcastcancel(struct block_list *bl,int type)
{
struct map_session_data *sd = NULL;
- struct unit_data *ud = unit_bl2ud( bl);
+ struct unit_data *ud = unit->bl2ud( bl);
unsigned int tick=iTimer->gettick();
int ret=0, skill_id;
@@ -2004,7 +2006,7 @@ int unit_skillcastcancel(struct block_list *bl,int type)
// unit_data initialization process
void unit_dataset(struct block_list *bl) {
struct unit_data *ud;
- nullpo_retv(ud = unit_bl2ud(bl));
+ nullpo_retv(ud = unit->bl2ud(bl));
memset( ud, 0, sizeof( struct unit_data) );
ud->bl = bl;
@@ -2022,7 +2024,7 @@ void unit_dataset(struct block_list *bl) {
int unit_counttargeted(struct block_list* bl)
{
struct unit_data* ud;
- if( bl && (ud = unit_bl2ud(bl)) )
+ if( bl && (ud = unit->bl2ud(bl)) )
return ud->target_count;
return 0;
}
@@ -2067,9 +2069,9 @@ int unit_changeviewsize(struct block_list *bl,short size)
* Otherwise it is assumed bl is being warped.
* On-Kill specific stuff is not performed here, look at iStatus->damage for that.
*------------------------------------------*/
-int unit_remove_map_(struct block_list *bl, clr_type clrtype, const char* file, int line, const char* func)
+int unit_remove_map(struct block_list *bl, clr_type clrtype, const char* file, int line, const char* func)
{
- struct unit_data *ud = unit_bl2ud(bl);
+ struct unit_data *ud = unit->bl2ud(bl);
struct status_change *sc = iStatus->get_sc(bl);
nullpo_ret(ud);
@@ -2078,14 +2080,14 @@ int unit_remove_map_(struct block_list *bl, clr_type clrtype, const char* file,
iMap->freeblock_lock();
- unit_set_target(ud, 0);
+ unit->set_target(ud, 0);
if (ud->walktimer != INVALID_TIMER)
- unit_stop_walking(bl,0);
+ unit->stop_walking(bl,0);
if (ud->attacktimer != INVALID_TIMER)
- unit_stop_attack(bl);
+ unit->stop_attack(bl);
if (ud->skilltimer != INVALID_TIMER)
- unit_skillcastcancel(bl,0);
+ unit->skillcastcancel(bl,0);
// Do not reset can-act delay. [Skotlex]
ud->attackabletime = ud->canmove_tick /*= ud->canact_tick*/ = iTimer->gettick();
@@ -2158,7 +2160,7 @@ int unit_remove_map_(struct block_list *bl, clr_type clrtype, const char* file,
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 ) {
@@ -2183,7 +2185,7 @@ int unit_remove_map_(struct block_list *bl, clr_type clrtype, const char* file,
}
party->send_dot_remove(sd);//minimap dot fix [Kevin]
guild->send_dot_remove(sd);
- bg_send_dot_remove(sd);
+ bg->send_dot_remove(sd);
if( map[bl->m].users <= 0 || sd->state.debug_remove_map )
{// this is only place where map users is decreased, if the mobs were removed too soon then this function was executed too many times [FlavioJS]
@@ -2233,10 +2235,10 @@ int unit_remove_map_(struct block_list *bl, clr_type clrtype, const char* file,
case BL_PET: {
struct pet_data *pd = (struct pet_data*)bl;
if( pd->pet.intimate <= 0 && !(pd->msd && !pd->msd->state.active) )
- { //If logging out, this is deleted on unit_free
+ { //If logging out, this is deleted on unit->free
clif->clearunit_area(bl,clrtype);
iMap->delblock(bl);
- unit_free(bl,CLR_OUTSIGHT);
+ unit->free(bl,CLR_OUTSIGHT);
iMap->freeblock_unlock();
return 0;
}
@@ -2247,11 +2249,11 @@ int unit_remove_map_(struct block_list *bl, clr_type clrtype, const char* file,
struct homun_data *hd = (struct homun_data *)bl;
ud->canact_tick = ud->canmove_tick; //It appears HOM do reset the can-act tick.
if( !hd->homunculus.intimacy && !(hd->master && !hd->master->state.active) )
- { //If logging out, this is deleted on unit_free
+ { //If logging out, this is deleted on unit->free
clif->emotion(bl, E_SOB);
clif->clearunit_area(bl,clrtype);
iMap->delblock(bl);
- unit_free(bl,CLR_OUTSIGHT);
+ unit->free(bl,CLR_OUTSIGHT);
iMap->freeblock_unlock();
return 0;
}
@@ -2264,7 +2266,7 @@ int unit_remove_map_(struct block_list *bl, clr_type clrtype, const char* file,
{
clif->clearunit_area(bl,clrtype);
iMap->delblock(bl);
- unit_free(bl,CLR_OUTSIGHT);
+ unit->free(bl,CLR_OUTSIGHT);
iMap->freeblock_unlock();
return 0;
}
@@ -2277,7 +2279,7 @@ int unit_remove_map_(struct block_list *bl, clr_type clrtype, const char* file,
{
clif->clearunit_area(bl,clrtype);
iMap->delblock(bl);
- unit_free(bl,0);
+ unit->free(bl,0);
iMap->freeblock_unlock();
return 0;
}
@@ -2297,27 +2299,27 @@ int unit_remove_map_(struct block_list *bl, clr_type clrtype, const char* file,
void unit_remove_map_pc(struct map_session_data *sd, clr_type clrtype)
{
- unit_remove_map(&sd->bl,clrtype);
+ unit->remove_map(&sd->bl,clrtype,ALC_MARK);
if (clrtype == CLR_TELEPORT) clrtype = CLR_OUTSIGHT; //CLR_TELEPORT is the warp from logging out, but pets/homunc need to just 'vanish' instead of showing the warping out animation.
if(sd->pd)
- unit_remove_map(&sd->pd->bl, clrtype);
+ unit->remove_map(&sd->pd->bl, clrtype, ALC_MARK);
if(homun_alive(sd->hd))
- unit_remove_map(&sd->hd->bl, clrtype);
+ unit->remove_map(&sd->hd->bl, clrtype, ALC_MARK);
if(sd->md)
- unit_remove_map(&sd->md->bl, clrtype);
+ unit->remove_map(&sd->md->bl, clrtype, ALC_MARK);
if(sd->ed)
- unit_remove_map(&sd->ed->bl, clrtype);
+ unit->remove_map(&sd->ed->bl, clrtype, ALC_MARK);
}
void unit_free_pc(struct map_session_data *sd)
{
- if (sd->pd) unit_free(&sd->pd->bl,CLR_OUTSIGHT);
- if (sd->hd) unit_free(&sd->hd->bl,CLR_OUTSIGHT);
- if (sd->md) unit_free(&sd->md->bl,CLR_OUTSIGHT);
- if (sd->ed) unit_free(&sd->ed->bl,CLR_OUTSIGHT);
- unit_free(&sd->bl,CLR_TELEPORT);
+ if (sd->pd) unit->free(&sd->pd->bl,CLR_OUTSIGHT);
+ if (sd->hd) unit->free(&sd->hd->bl,CLR_OUTSIGHT);
+ if (sd->md) unit->free(&sd->md->bl,CLR_OUTSIGHT);
+ if (sd->ed) unit->free(&sd->ed->bl,CLR_OUTSIGHT);
+ unit->free(&sd->bl,CLR_TELEPORT);
}
/*==========================================
@@ -2326,12 +2328,12 @@ void unit_free_pc(struct map_session_data *sd)
*------------------------------------------*/
int unit_free(struct block_list *bl, clr_type clrtype)
{
- struct unit_data *ud = unit_bl2ud( bl );
+ struct unit_data *ud = unit->bl2ud( bl );
nullpo_ret(ud);
iMap->freeblock_lock();
if( bl->prev ) //Players are supposed to logout with a "warp" effect.
- unit_remove_map(bl, clrtype);
+ unit->remove_map(bl, clrtype, ALC_MARK);
switch( bl->type ) {
case BL_PC:
@@ -2421,7 +2423,7 @@ int unit_free(struct block_list *bl, clr_type clrtype)
{
struct pet_data *pd = (struct pet_data*)bl;
struct map_session_data *sd = pd->msd;
- pet_hungry_timer_delete(pd);
+ pet->hungry_timer_delete(pd);
if( pd->a_skill )
{
aFree(pd->a_skill);
@@ -2431,9 +2433,9 @@ int unit_free(struct block_list *bl, clr_type clrtype)
{
if (pd->s_skill->timer != INVALID_TIMER) {
if (pd->s_skill->id)
- iTimer->delete_timer(pd->s_skill->timer, pet_skill_support_timer);
+ iTimer->delete_timer(pd->s_skill->timer, pet->skill_support_timer);
else
- iTimer->delete_timer(pd->s_skill->timer, pet_heal_timer);
+ iTimer->delete_timer(pd->s_skill->timer, pet->heal_timer);
}
aFree(pd->s_skill);
pd->s_skill = NULL;
@@ -2441,20 +2443,20 @@ int unit_free(struct block_list *bl, clr_type clrtype)
if( pd->recovery )
{
if(pd->recovery->timer != INVALID_TIMER)
- iTimer->delete_timer(pd->recovery->timer, pet_recovery_timer);
+ iTimer->delete_timer(pd->recovery->timer, pet->recovery_timer);
aFree(pd->recovery);
pd->recovery = NULL;
}
if( pd->bonus )
{
if (pd->bonus->timer != INVALID_TIMER)
- iTimer->delete_timer(pd->bonus->timer, pet_skill_bonus_timer);
+ iTimer->delete_timer(pd->bonus->timer, pet->skill_bonus_timer);
aFree(pd->bonus);
pd->bonus = NULL;
}
if( pd->loot )
{
- pet_lootitem_drop(pd,sd);
+ pet->lootitem_drop(pd,sd);
if (pd->loot->item)
aFree(pd->loot->item);
aFree (pd->loot);
@@ -2476,12 +2478,12 @@ int unit_free(struct block_list *bl, clr_type clrtype)
struct mob_data *md = (struct mob_data*)bl;
if( md->spawn_timer != INVALID_TIMER )
{
- iTimer->delete_timer(md->spawn_timer,mob_delayspawn);
+ iTimer->delete_timer(md->spawn_timer,mob->delayspawn);
md->spawn_timer = INVALID_TIMER;
}
if( md->deletetimer != INVALID_TIMER )
{
- iTimer->delete_timer(md->deletetimer,mob_timer_delete);
+ iTimer->delete_timer(md->deletetimer,mob->timer_delete);
md->deletetimer = INVALID_TIMER;
}
if( md->lootitem )
@@ -2523,10 +2525,10 @@ int unit_free(struct block_list *bl, clr_type clrtype)
aFree(md->base_status);
md->base_status = NULL;
}
- if( mob_is_clone(md->class_) )
- mob_clone_delete(md);
+ if( mob->is_clone(md->class_) )
+ mob->clone_delete(md);
if( md->tomb_nid )
- mvptomb_destroy(md);
+ mob->mvptomb_destroy(md);
break;
}
case BL_HOM:
@@ -2590,17 +2592,67 @@ int unit_free(struct block_list *bl, clr_type clrtype)
return 0;
}
-int do_init_unit(void)
-{
- iTimer->add_timer_func_list(unit_attack_timer, "unit_attack_timer");
- iTimer->add_timer_func_list(unit_walktoxy_timer,"unit_walktoxy_timer");
- iTimer->add_timer_func_list(unit_walktobl_sub, "unit_walktobl_sub");
- iTimer->add_timer_func_list(unit_delay_walktoxy_timer,"unit_delay_walktoxy_timer");
+int do_init_unit(void) {
+ iTimer->add_timer_func_list(unit->attack_timer, "unit_attack_timer");
+ iTimer->add_timer_func_list(unit->walktoxy_timer,"unit_walktoxy_timer");
+ iTimer->add_timer_func_list(unit->walktobl_sub, "unit_walktobl_sub");
+ iTimer->add_timer_func_list(unit->delay_walktoxy_timer,"unit_delay_walktoxy_timer");
return 0;
}
-int do_final_unit(void)
-{
+int do_final_unit(void) {
// nothing to do
return 0;
}
+
+void unit_defaults(void) {
+ unit = &unit_s;
+
+ unit->init = do_init_unit;
+ unit->final = do_final_unit;
+ /* */
+ unit->bl2ud = unit_bl2ud;
+ unit->bl2ud2 = unit_bl2ud2;
+ unit->attack_timer = unit_attack_timer;
+ unit->walktoxy_timer = unit_walktoxy_timer;
+ unit->walktoxy_sub = unit_walktoxy_sub;
+ unit->delay_walktoxy_timer = unit_delay_walktoxy_timer;
+ unit->walktoxy = unit_walktoxy;
+ unit->walktobl_sub = unit_walktobl_sub;
+ unit->walktobl = unit_walktobl;
+ unit->run = unit_run;
+ unit->wugdash = unit_wugdash;
+ unit->escape = unit_escape;
+ unit->movepos = unit_movepos;
+ unit->setdir = unit_setdir;
+ unit->getdir = unit_getdir;
+ unit->blown = unit_blown;
+ unit->warp = unit_warp;
+ unit->stop_walking = unit_stop_walking;
+ unit->skilluse_id = unit_skilluse_id;
+ unit->is_walking = unit_is_walking;
+ unit->can_move = unit_can_move;
+ unit->resume_running = unit_resume_running;
+ unit->set_walkdelay = unit_set_walkdelay;
+ unit->skilluse_id2 = unit_skilluse_id2;
+ unit->skilluse_pos = unit_skilluse_pos;
+ unit->skilluse_pos2 = unit_skilluse_pos2;
+ unit->set_target = unit_set_target;
+ unit->stop_attack = unit_stop_attack;
+ unit->unattackable = unit_unattackable;
+ unit->attack = unit_attack;
+ unit->cancel_combo = unit_cancel_combo;
+ unit->can_reach_pos = unit_can_reach_pos;
+ unit->can_reach_bl = unit_can_reach_bl;
+ unit->calc_pos = unit_calc_pos;
+ unit->attack_timer_sub = unit_attack_timer_sub;
+ unit->skillcastcancel = unit_skillcastcancel;
+ unit->dataset = unit_dataset;
+ unit->counttargeted = unit_counttargeted;
+ unit->fixdamage = unit_fixdamage;
+ unit->changeviewsize = unit_changeviewsize;
+ unit->remove_map = unit_remove_map;
+ unit->remove_map_pc = unit_remove_map_pc;
+ unit->free_pc = unit_free_pc;
+ unit->free = unit_free;
+}
diff --git a/src/map/unit.h b/src/map/unit.h
index b743fc8cb..be7b789d9 100644
--- a/src/map/unit.h
+++ b/src/map/unit.h
@@ -68,79 +68,61 @@ struct view_data {
unsigned dead_sit : 2;
};
-// PC, MOB, PET に共通する処理を1つにまとめる計画
-
-// 歩行開始
-// 戻り値は、0 ( 成功 ), 1 ( 失敗 )
-int unit_walktoxy( struct block_list *bl, short x, short y, int easy);
-int unit_walktobl( struct block_list *bl, struct block_list *target, int range, int easy);
-int unit_run(struct block_list *bl);
-int unit_calc_pos(struct block_list *bl, int tx, int ty, uint8 dir);
-
-// 歩行停止
-// typeは以下の組み合わせ :
-// 1: 位置情報の送信( この関数の後に位置情報を送信する場合は不要 )
-// 2: ダメージディレイ有り
-// 4: 不明(MOBのみ?)
-int unit_stop_walking(struct block_list *bl,int type);
-int unit_can_move(struct block_list *bl);
-int unit_is_walking(struct block_list *bl);
-int unit_set_walkdelay(struct block_list *bl, unsigned int tick, int delay, int type);
-
-int unit_escape(struct block_list *bl, struct block_list *target, short dist);
-// 位置の強制移動(吹き飛ばしなど)
-int unit_movepos(struct block_list *bl, short dst_x, short dst_y, int easy, bool checkpath);
-int unit_warp(struct block_list *bl, short map, short x, short y, clr_type type);
-int unit_setdir(struct block_list *bl,unsigned char dir);
-uint8 unit_getdir(struct block_list *bl);
-int unit_blown(struct block_list* bl, int dx, int dy, int count, int flag);
-
-// そこまで歩行でたどり着けるかの判定
-bool unit_can_reach_pos(struct block_list *bl,int x,int y,int easy);
-bool unit_can_reach_bl(struct block_list *bl,struct block_list *tbl, int range, int easy, short *x, short *y);
-
-// 攻撃関連
-int unit_stop_attack(struct block_list *bl);
-int unit_attack(struct block_list *src,int target_id,int continuous);
-int unit_cancel_combo(struct block_list *bl);
-
-// スキル使用
-int unit_skilluse_id(struct block_list *src, int target_id, uint16 skill_id, uint16 skill_lv);
-int unit_skilluse_pos(struct block_list *src, short skill_x, short skill_y, uint16 skill_id, uint16 skill_lv);
-
-// スキル使用( 補正済みキャスト時間、キャンセル不可設定付き )
-int unit_skilluse_id2(struct block_list *src, int target_id, uint16 skill_id, uint16 skill_lv, int casttime, int castcancel);
-int unit_skilluse_pos2( struct block_list *src, short skill_x, short skill_y, uint16 skill_id, uint16 skill_lv, int casttime, int castcancel);
-
-// 詠唱キャンセル
-int unit_skillcastcancel(struct block_list *bl,int type);
-
-int unit_counttargeted(struct block_list *bl);
-int unit_set_target(struct unit_data* ud, int target_id);
-
-// unit_data の初期化処理
-void unit_dataset(struct block_list *bl);
+extern const short dirx[8];
+extern const short diry[8];
-int unit_fixdamage(struct block_list *src,struct block_list *target,unsigned int tick,int sdelay,int ddelay,int64 damage,int div,int type,int64 damage2);
-// その他
-struct unit_data* unit_bl2ud(struct block_list *bl);
-struct unit_data* unit_bl2ud2(struct block_list *bl);
-void unit_remove_map_pc(struct map_session_data *sd, clr_type clrtype);
-void unit_free_pc(struct map_session_data *sd);
-#define unit_remove_map(bl,clrtype) unit_remove_map_(bl,clrtype,__FILE__,__LINE__,__func__)
-int unit_remove_map_(struct block_list *bl, clr_type clrtype, const char* file, int line, const char* func);
-int unit_free(struct block_list *bl, clr_type clrtype);
-int unit_changeviewsize(struct block_list *bl,short size);
+struct unit_interface {
+ int (*init) (void);
+ int (*final) (void);
+ /* */
+ struct unit_data* (*bl2ud) (struct block_list *bl);
+ struct unit_data* (*bl2ud2) (struct block_list *bl);
+ int (*attack_timer) (int tid, unsigned int tick, int id, intptr_t data);
+ int (*walktoxy_timer) (int tid, unsigned int tick, int id, intptr_t data);
+ int (*walktoxy_sub) (struct block_list *bl);
+ int (*delay_walktoxy_timer) (int tid, unsigned int tick, int id, intptr_t data);
+ int (*walktoxy) (struct block_list *bl, short x, short y, int flag);
+ int (*walktobl_sub) (int tid, unsigned int tick, int id, intptr_t data);
+ int (*walktobl) (struct block_list *bl, struct block_list *tbl, int range, int flag);
+ int (*run) (struct block_list *bl);
+ int (*wugdash) (struct block_list *bl, struct map_session_data *sd);
+ int (*escape) (struct block_list *bl, struct block_list *target, short dist);
+ int (*movepos) (struct block_list *bl, short dst_x, short dst_y, int easy, bool checkpath);
+ int (*setdir) (struct block_list *bl, unsigned char dir);
+ uint8 (*getdir) (struct block_list *bl);
+ int (*blown) (struct block_list *bl, int dx, int dy, int count, int flag);
+ int (*warp) (struct block_list *bl, short m, short x, short y, clr_type type);
+ int (*stop_walking) (struct block_list *bl, int type);
+ int (*skilluse_id) (struct block_list *src, int target_id, uint16 skill_id, uint16 skill_lv);
+ int (*is_walking) (struct block_list *bl);
+ int (*can_move) (struct block_list *bl);
+ int (*resume_running) (int tid, unsigned int tick, int id, intptr_t data);
+ int (*set_walkdelay) (struct block_list *bl, unsigned int tick, int delay, int type);
+ int (*skilluse_id2) (struct block_list *src, int target_id, uint16 skill_id, uint16 skill_lv, int casttime, int castcancel);
+ int (*skilluse_pos) (struct block_list *src, short skill_x, short skill_y, uint16 skill_id, uint16 skill_lv);
+ int (*skilluse_pos2) (struct block_list *src, short skill_x, short skill_y, uint16 skill_id, uint16 skill_lv, int casttime, int castcancel);
+ int (*set_target) (struct unit_data *ud, int target_id);
+ int (*stop_attack) (struct block_list *bl);
+ int (*unattackable) (struct block_list *bl);
+ int (*attack) (struct block_list *src, int target_id, int continuous);
+ int (*cancel_combo) (struct block_list *bl);
+ bool (*can_reach_pos) (struct block_list *bl, int x, int y, int easy);
+ bool (*can_reach_bl) (struct block_list *bl, struct block_list *tbl, int range, int easy, short *x, short *y);
+ int (*calc_pos) (struct block_list *bl, int tx, int ty, uint8 dir);
+ int (*attack_timer_sub) (struct block_list *src, int tid, unsigned int tick);
+ int (*skillcastcancel) (struct block_list *bl, int type);
+ void (*dataset) (struct block_list *bl);
+ int (*counttargeted) (struct block_list *bl);
+ int (*fixdamage) (struct block_list *src, struct block_list *target, unsigned int tick, int sdelay, int ddelay, int64 damage, int div, int type, int64 damage2);
+ int (*changeviewsize) (struct block_list *bl, short size);
+ int (*remove_map) (struct block_list *bl, clr_type clrtype, const char *file, int line, const char *func);
+ void (*remove_map_pc) (struct map_session_data *sd, clr_type clrtype);
+ void (*free_pc) (struct map_session_data *sd);
+ int (*free) (struct block_list *bl, clr_type clrtype);
+};
-// 初期化ルーチン
-int do_init_unit(void);
-int do_final_unit(void);
-/**
- * Ranger
- **/
-int unit_wugdash(struct block_list *bl, struct map_session_data *sd);
+struct unit_interface *unit;
-extern const short dirx[8];
-extern const short diry[8];
+void unit_defaults(void);
#endif /* _UNIT_H_ */