summaryrefslogtreecommitdiff
path: root/src/map/mob.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/map/mob.c')
-rw-r--r--src/map/mob.c2030
1 files changed, 1081 insertions, 949 deletions
diff --git a/src/map/mob.c b/src/map/mob.c
index 6bb40478f..3f1769d37 100644
--- a/src/map/mob.c
+++ b/src/map/mob.c
@@ -2,46 +2,51 @@
// See the LICENSE file
// Portions Copyright (c) Athena Dev Teams
-#include "../common/cbasetypes.h"
-#include "../common/timer.h"
-#include "../common/db.h"
-#include "../common/nullpo.h"
-#include "../common/malloc.h"
-#include "../common/showmsg.h"
-#include "../common/ers.h"
-#include "../common/random.h"
-#include "../common/strlib.h"
-#include "../common/utils.h"
-#include "../common/socket.h"
+#define HERCULES_CORE
-#include "map.h"
-#include "path.h"
-#include "clif.h"
-#include "intif.h"
-#include "pc.h"
-#include "pet.h"
-#include "status.h"
+#include "../config/core.h" // AUTOLOOT_DISTANCE, DBPATH, DEFTYPE_MAX, DEFTYPE_MIN, RENEWAL_DROP, RENEWAL_EXP
#include "mob.h"
-#include "homunculus.h"
-#include "mercenary.h"
+
+#include <math.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "atcommand.h"
+#include "battle.h"
+#include "clif.h"
+#include "date.h"
#include "elemental.h"
#include "guild.h"
+#include "homunculus.h"
+#include "intif.h"
#include "itemdb.h"
-#include "skill.h"
-#include "battle.h"
-#include "party.h"
-#include "npc.h"
#include "log.h"
-#include "script.h"
-#include "atcommand.h"
-#include "date.h"
+#include "map.h"
+#include "mercenary.h"
+#include "npc.h"
+#include "party.h"
+#include "path.h"
+#include "pc.h"
+#include "pet.h"
#include "quest.h"
+#include "script.h"
+#include "skill.h"
+#include "status.h"
+#include "../common/cbasetypes.h"
+#include "../common/db.h"
+#include "../common/ers.h"
+#include "../common/malloc.h"
+#include "../common/nullpo.h"
+#include "../common/random.h"
+#include "../common/showmsg.h"
+#include "../common/socket.h"
+#include "../common/strlib.h"
+#include "../common/timer.h"
+#include "../common/utils.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#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.
@@ -50,21 +55,10 @@
#define MOB_LAZYSKILLPERC 0 // Probability for mobs far from players from doing their IDLE skill. (rate of 1000 minute)
// Move probability for mobs away from players (rate of 1000 minute)
// in Aegis, this is 100% for mobs that have been activated by players and none otherwise.
-#define MOB_LAZYMOVEPERC(md) (md->state.spotted?1000:0)
+#define MOB_LAZYMOVEPERC(md) ((md)->state.spotted?1000:0)
#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 +76,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,28 +93,40 @@ 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)
+ return i;
+ if(battle_config.case_sensitive_aegisnames && strcmp(monster->sprite,str)==0)
+ return i;
+ if(!battle_config.case_sensitive_aegisnames && strcasecmp(monster->sprite,str)==0)
return i;
}
return 0;
}
-static int mobdb_searchname_array_sub(struct mob_db* mob, const char *str)
-{
- 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(stristr(mob->jname,str))
- return 0;
- if(stristr(mob->name,str))
- return 0;
- return strcmpi(mob->jname,str);
+ if( !flag ) {
+ if(stristr(monster->jname,str))
+ return 0;
+ if(stristr(monster->name,str))
+ return 0;
+ } else {
+ if(strcmpi(monster->jname,str) == 0)
+ return 0;
+ if(strcmpi(monster->name,str) == 0)
+ return 0;
+ }
+ if (battle_config.case_sensitive_aegisnames)
+ return strcmp(monster->sprite,str);
+ return strcasecmp(monster->sprite,str);
}
/*==========================================
@@ -131,19 +137,19 @@ 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->dir = md->ud.dir;
nd->bl.m = md->bl.m;
nd->bl.x = md->bl.x;
nd->bl.y = md->bl.y;
nd->bl.type = BL_NPC;
- safestrncpy(nd->name, msg_txt(656), sizeof(nd->name));
+ safestrncpy(nd->name, msg_txt(856), sizeof(nd->name)); // "Tomb"
nd->class_ = 565;
nd->speed = 200;
@@ -157,33 +163,33 @@ void mvptomb_create(struct mob_data *md, char *killer, time_t time)
else
nd->u.tomb.killer_name[0] = '\0';
- iMap->addnpc(nd->bl.m, nd);
- iMap->addblock(&nd->bl);
- status_set_viewdata(&nd->bl, nd->class_);
- clif->spawn(&nd->bl);
+ map->addnpc(nd->bl.m, nd);
+ map->addblock(&nd->bl);
+ status->set_viewdata(&nd->bl, nd->class_);
+ clif->spawn(&nd->bl);
}
void mvptomb_destroy(struct mob_data *md) {
struct npc_data *nd;
- if ( (nd = iMap->id2nd(md->tomb_nid)) ) {
+ if ( (nd = map->id2nd(md->tomb_nid)) ) {
int16 m, i;
m = nd->bl.m;
clif->clearunit_area(&nd->bl,CLR_OUTSIGHT);
- iMap->delblock(&nd->bl);
+ map->delblock(&nd->bl);
- ARR_FIND( 0, map[m].npc_num, i, map[m].npc[i] == nd );
- if( !(i == map[m].npc_num) ) {
- map[m].npc_num--;
- map[m].npc[i] = map[m].npc[map[m].npc_num];
- map[m].npc[map[m].npc_num] = NULL;
+ ARR_FIND( 0, map->list[m].npc_num, i, map->list[m].npc[i] == nd );
+ if( !(i == map->list[m].npc_num) ) {
+ map->list[m].npc_num--;
+ map->list[m].npc[i] = map->list[m].npc[map->list[m].npc_num];
+ map->list[m].npc[map->list[m].npc_num] = NULL;
}
- iMap->deliddb(&nd->bl);
+ map->deliddb(&nd->bl);
aFree(nd);
}
@@ -194,17 +200,17 @@ void mvptomb_destroy(struct mob_data *md) {
/*==========================================
* Founds up to N matches. Returns number of matches [Skotlex]
*------------------------------------------*/
-int mobdb_searchname_array(struct mob_db** data, int size, const char *str)
+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)) {
+ if (!mob->db_searchname_array_sub(monster, str, flag)) {
if (count < size)
- data[count] = mob;
+ data[count] = monster;
count++;
}
}
@@ -216,9 +222,9 @@ int mobdb_searchname_array(struct mob_db** data, int size, const char *str)
*------------------------------------------*/
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;
}
@@ -228,9 +234,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"
@@ -239,7 +245,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 )
@@ -251,9 +257,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;
}
@@ -262,14 +268,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);
@@ -284,11 +290,11 @@ struct mob_data* mob_spawn_dataset(struct spawn_data *data) {
md->spawn_timer = INVALID_TIMER;
md->deletetimer = INVALID_TIMER;
md->skill_idx = -1;
- status_set_viewdata(&md->bl, md->class_);
- status_change_init(&md->bl);
- unit_dataset(&md->bl);
+ status->set_viewdata(&md->bl, md->class_);
+ status->change_init(&md->bl);
+ unit->dataset(&md->bl);
- iMap->addiddb(&md->bl);
+ map->addiddb(&md->bl);
return md;
}
@@ -307,7 +313,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);
@@ -318,25 +324,24 @@ 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_;
}
/*==========================================
* Kill Steal Protection [Zephyrus]
*------------------------------------------*/
-bool mob_ksprotected (struct block_list *src, struct block_list *target)
-{
+bool mob_ksprotected(struct block_list *src, struct block_list *target) {
struct block_list *s_bl, *t_bl;
struct map_session_data
*sd, // Source
@@ -344,14 +349,14 @@ bool mob_ksprotected (struct block_list *src, struct block_list *target)
*t_sd; // Mob Target
struct status_change_entry *sce;
struct mob_data *md;
- unsigned int tick = iTimer->gettick();
+ int64 tick = timer->gettick();
char output[128];
if( !battle_config.ksprotection )
return false; // KS Protection Disabled
if( !(md = BL_CAST(BL_MOB,target)) )
- return false; // Tarjet is not MOB
+ return false; // Target is not MOB
if( (s_bl = battle->get_master(src)) == NULL )
s_bl = src;
@@ -359,14 +364,14 @@ bool mob_ksprotected (struct block_list *src, struct block_list *target)
if( !(sd = BL_CAST(BL_PC,s_bl)) )
return false; // Master is not PC
- t_bl = iMap->id2bl(md->target_id);
+ t_bl = map->id2bl(md->target_id);
if( !t_bl || (s_bl = battle->get_master(t_bl)) == NULL )
s_bl = t_bl;
t_sd = BL_CAST(BL_PC,s_bl);
do {
- if( map[md->bl.m].flag.allowks || map_flag_ks(md->bl.m) )
+ if( map->list[md->bl.m].flag.allowks || map_flag_ks(md->bl.m) )
return false; // Ignores GVG, PVP and AllowKS map flags
if( md->db->mexp || md->master_id )
@@ -386,7 +391,7 @@ bool mob_ksprotected (struct block_list *src, struct block_list *target)
(sce->val2 == 3 && sce->val4 && sce->val4 != t_sd->status.guild_id)) )
break;
- if( (pl_sd = iMap->id2sd(sce->val1)) == NULL || pl_sd->bl.m != md->bl.m )
+ if( (pl_sd = map->id2sd(sce->val1)) == NULL || pl_sd->bl.m != md->bl.m )
break;
if( !pl_sd->state.noks )
@@ -396,7 +401,7 @@ bool mob_ksprotected (struct block_list *src, struct block_list *target)
if( DIFF_TICK(sd->ks_floodprotect_tick, tick) <= 0 )
{
sprintf(output, "[KS Warning!! - Owner : %s]", pl_sd->status.name);
- clif->disp_onlyself(sd, output, strlen(output));
+ clif_disp_onlyself(sd, output, strlen(output));
sd->ks_floodprotect_tick = tick + 2000;
}
@@ -405,7 +410,7 @@ bool mob_ksprotected (struct block_list *src, struct block_list *target)
if( DIFF_TICK(pl_sd->ks_floodprotect_tick, tick) <= 0 )
{
sprintf(output, "[Watch out! %s is trying to KS you!]", sd->status.name);
- clif->disp_onlyself(pl_sd, output, strlen(output));
+ clif_disp_onlyself(pl_sd, output, strlen(output));
pl_sd->ks_floodprotect_tick = tick + 2000;
}
@@ -413,7 +418,7 @@ bool mob_ksprotected (struct block_list *src, struct block_list *target)
return true;
} while(0);
- status_change_start(target, SC_KSPROTECTED, 10000, sd->bl.id, sd->state.noks, sd->status.party_id, sd->status.guild_id, battle_config.ksprotection, 0);
+ status->change_start(NULL, target, SC_KSPROTECTED, 10000, sd->bl.id, sd->state.noks, sd->status.party_id, sd->status.guild_id, battle_config.ksprotection, 0);
return false;
}
@@ -442,68 +447,67 @@ struct mob_data *mob_once_spawn_sub(struct block_list *bl, int16 m, int16 x, int
// Locate spot next to player.
if (bl && (x < 0 || y < 0))
- iMap->search_freecell(bl, m, &x, &y, 1, 1, 0);
+ map->search_freecell(bl, m, &x, &y, 1, 1, 0);
// if none found, pick random position on map
- if (x <= 0 || y <= 0 || iMap->getcell(m,x,y,CELL_CHKNOREACH))
- iMap->search_freecell(NULL, m, &x, &y, -1, -1, 1);
+ if (x <= 0 || x >= map->list[m].xs || y <= 0 || y >= map->list[m].ys)
+ map->search_freecell(NULL, m, &x, &y, -1, -1, 1);
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);
}
/*==========================================
* Spawn a single mob on the specified coordinates.
*------------------------------------------*/
-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(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) {
struct mob_data* md = NULL;
int count, lv;
+ bool no_guardian_data = false;
+
+ if( ai && ai&0x200 ) {
+ no_guardian_data = true;
+ ai &=~ 0x200;
+ }
if (m < 0 || amount <= 0)
return 0; // invalid input
lv = (sd) ? sd->status.base_level : 255;
- 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);
+ 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);
if (!md)
continue;
- if (class_ == MOBID_EMPERIUM)
- {
- struct guild_castle* gc = guild->mapindex2gc(map[m].index);
+ if ( class_ == MOBID_EMPERIUM && !no_guardian_data ) {
+ struct guild_castle* gc = guild->mapindex2gc(map_id2index(m));
struct guild* g = (gc) ? guild->search(gc->guild_id) : NULL;
- if (gc)
- {
+ if( gc ) {
md->guardian_data = (struct guardian_data*)aCalloc(1, sizeof(struct guardian_data));
md->guardian_data->castle = gc;
md->guardian_data->number = MAX_GUARDIANS;
- md->guardian_data->guild_id = gc->guild_id;
- if (g)
- {
- md->guardian_data->emblem_id = g->emblem_id;
- 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);
+ if( g )
+ md->guardian_data->g = g;
+ else if( gc->guild_id ) //Guild not yet available, retry in 5.
+ timer->add(timer->gettick()+5000,mob->spawn_guardian_sub,md->bl.id,gc->guild_id);
}
} // end addition [Valaris]
- mob_spawn(md);
+ mob->spawn(md);
- if (class_ < 0 && battle_config.dead_branch_active)
+ if (class_ < 0 && battle_config.dead_branch_active) {
//Behold Aegis's masterful decisions yet again...
//"I understand the "Aggressive" part, but the "Can Move" and "Can Attack" is just stupid" - Poki#3
- sc_start4(&md->bl, SC_MODECHANGE, 100, 1, 0, MD_AGGRESSIVE|MD_CANATTACK|MD_CANMOVE|MD_ANGRY, 0, 60000);
+ sc_start4(NULL, &md->bl, SC_MODECHANGE, 100, 1, 0, MD_AGGRESSIVE|MD_CANATTACK|MD_CANMOVE|MD_ANGRY, 0, 60000);
+ }
}
return (md) ? md->bl.id : 0; // id of last spawned mob
@@ -542,7 +546,7 @@ int mob_once_spawn_area(struct map_session_data* sd, int16 m, int16 x0, int16 y0
x = rnd()%(x1-x0+1)+x0;
y = rnd()%(y1-y0+1)+y0;
j++;
- } while (iMap->getcell(m,x,y,CELL_CHKNOPASS) && j < max);
+ } while (map->getcell(m,x,y,CELL_CHKNOPASS) && j < max);
if (j == max)
{// attempt to find an available cell failed
@@ -558,26 +562,28 @@ 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
}
-/*==========================================
- * Set a Guardian's guild data [Skotlex]
- *------------------------------------------*/
-static 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);
+
+/**
+ * Sets a guardian's guild data and liberates castle if couldn't retrieve guild data
+ * @param data (int)guild_id
+ * @retval Always 0
+ * @author Skotlex
+ **/
+int mob_spawn_guardian_sub(int tid, int64 tick, int id, intptr_t data) {
+ //Needed because the guild data may not be available at guardian spawn time.
+ struct block_list* bl = map->id2bl(id);
struct mob_data* md;
struct guild* g;
- int guardup_lv;
- if (bl == NULL) //It is possible mob was already removed from map when the castle has no owner. [Skotlex]
+ if( bl == NULL ) //It is possible mob was already removed from map when the castle has no owner. [Skotlex]
return 0;
- if (bl->type != BL_MOB)
- {
+ if( bl->type != BL_MOB ) {
ShowError("mob_spawn_guardian_sub: Block error!\n");
return 0;
}
@@ -586,30 +592,28 @@ static int mob_spawn_guardian_sub(int tid, unsigned int tick, int id, intptr_t d
nullpo_ret(md->guardian_data);
g = guild->search((int)data);
- if (g == NULL)
- { //Liberate castle, if the guild is not found this is an error! [Skotlex]
+ if( g == NULL ) { //Liberate castle, if the guild is not found this is an error! [Skotlex]
ShowError("mob_spawn_guardian_sub: Couldn't load guild %d!\n", (int)data);
- if (md->class_ == MOBID_EMPERIUM)
- { //Not sure this is the best way, but otherwise we'd be invoking this for ALL guardians spawned later on.
- md->guardian_data->guild_id = 0;
- if (md->guardian_data->castle->guild_id) //Free castle up.
- {
+ //Not sure this is the best way, but otherwise we'd be invoking this for ALL guardians spawned later on.
+ if( md->class_ == MOBID_EMPERIUM && md->guardian_data ) {
+ md->guardian_data->g = NULL;
+ if( md->guardian_data->castle->guild_id ) {//Free castle up.
ShowNotice("Clearing ownership of castle %d (%s)\n", md->guardian_data->castle->castle_id, md->guardian_data->castle->castle_name);
guild->castledatasave(md->guardian_data->castle->castle_id, 1, 0);
}
} else {
- if (md->guardian_data->number >= 0 && md->guardian_data->number < MAX_GUARDIANS && md->guardian_data->castle->guardian[md->guardian_data->number].visible)
+ if( md->guardian_data && 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;
}
- guardup_lv = guild->checkskill(g,GD_GUARDUP);
- md->guardian_data->emblem_id = g->emblem_id;
- memcpy(md->guardian_data->guild_name, g->name, NAME_LENGTH);
- md->guardian_data->guardup_lv = guardup_lv;
- if( guardup_lv )
- status_calc_mob(md, 0); //Give bonuses.
+
+ if( guild->checkskill(g,GD_GUARDUP) )
+ status_calc_mob(md, SCO_NONE); // Give bonuses.
+
return 0;
}
@@ -626,7 +630,7 @@ int mob_spawn_guardian(const char* mapname, short x, short y, const char* mobnam
memset(&data, 0, sizeof(struct spawn_data));
data.num = 1;
- m=iMap->mapname2mapid(mapname);
+ m=map->mapname2mapid(mapname);
if(m<0)
{
@@ -636,60 +640,55 @@ 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;
}
data.class_ = class_;
- if( !has_index )
- {
+ if( !has_index ) {
guardian = -1;
- }
- else if( guardian < 0 || guardian >= MAX_GUARDIANS )
- {
- ShowError("mob_spawn_guardian: Invalid guardian index %d for guardian %d (castle map %s)\n", guardian, class_, map[m].name);
+ } else if( guardian < 0 || guardian >= MAX_GUARDIANS ) {
+ ShowError("mob_spawn_guardian: Invalid guardian index %d for guardian %d (castle map %s)\n", guardian, class_, map->list[m].name);
return 0;
}
- if((x<=0 || y<=0) && !iMap->search_freecell(NULL, m, &x, &y, -1,-1, 1))
- {
- ShowWarning("mob_spawn_guardian: Couldn't locate a spawn cell for guardian class %d (index %d) at castle map %s\n",class_, guardian, map[m].name);
+ if((x<=0 || y<=0) && !map->search_freecell(NULL, m, &x, &y, -1,-1, 1)) {
+ ShowWarning("mob_spawn_guardian: Couldn't locate a spawn cell for guardian class %d (index %d) at castle map %s\n",class_, guardian, map->list[m].name);
return 0;
}
data.x = x;
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);
- if (gc == NULL)
- {
- ShowError("mob_spawn_guardian: No castle set at map %s\n", map[m].name);
+ gc=guild->mapname2gc(map->list[m].name);
+ if (gc == NULL) {
+ ShowError("mob_spawn_guardian: No castle set at map %s\n", map->list[m].name);
return 0;
}
if (!gc->guild_id)
- ShowWarning("mob_spawn_guardian: Spawning guardian %d on a castle with no guild (castle map %s)\n", class_, map[m].name);
+ ShowWarning("mob_spawn_guardian: Spawning guardian %d on a castle with no guild (castle map %s)\n", class_, map->list[m].name);
else
g = guild->search(gc->guild_id);
if( has_index && gc->guardian[guardian].id )
{ //Check if guardian already exists, refuse to spawn if so.
- struct mob_data *md2 = (TBL_MOB*)iMap->id2bl(gc->guardian[guardian].id);
- if (md2 && md2->bl.type == BL_MOB &&
- md2->guardian_data && md2->guardian_data->number == guardian)
- {
- ShowError("mob_spawn_guardian: Attempted to spawn guardian in position %d which already has a guardian (castle map %s)\n", guardian, map[m].name);
+ struct mob_data *md2 = (TBL_MOB*)map->id2bl(gc->guardian[guardian].id);
+ if (md2 && md2->bl.type == BL_MOB
+ && md2->guardian_data
+ && md2->guardian_data->number == guardian
+ ) {
+ ShowError("mob_spawn_guardian: Attempted to spawn guardian in position %d which already has a guardian (castle map %s)\n", guardian, map->list[m].name);
return 0;
}
}
- 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;
md->guardian_data->castle = gc;
if( has_index )
{// permanent guardian
@@ -706,14 +705,11 @@ int mob_spawn_guardian(const char* mapname, short x, short y, const char* mobnam
}
gc->temp_guardians[i] = md->bl.id;
}
- if (g)
- {
- md->guardian_data->emblem_id = g->emblem_id;
- 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);
+ if( g )
+ md->guardian_data->g = g;
+ else if( gc->guild_id )
+ timer->add(timer->gettick()+5000,mob->spawn_guardian_sub,md->bl.id,gc->guild_id);
+ mob->spawn(md);
return md->bl.id;
}
@@ -727,8 +723,7 @@ int mob_spawn_bg(const char* mapname, short x, short y, const char* mobname, int
struct spawn_data data;
int16 m;
- if( (m = iMap->mapname2mapid(mapname)) < 0 )
- {
+ if( (m = map->mapname2mapid(mapname)) < 0 ) {
ShowWarning("mob_spawn_bg: Map [%s] not found.\n", mapname);
return 0;
}
@@ -738,14 +733,13 @@ 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;
}
data.class_ = class_;
- if( (x <= 0 || y <= 0) && !iMap->search_freecell(NULL, m, &x, &y, -1,-1, 1) )
- {
- ShowWarning("mob_spawn_bg: Couldn't locate a spawn cell for guardian class %d (bg_id %d) at map %s\n",class_, bg_id, map[m].name);
+ if( (x <= 0 || y <= 0) && !map->search_freecell(NULL, m, &x, &y, -1,-1, 1) ) {
+ ShowWarning("mob_spawn_bg: Couldn't locate a spawn cell for guardian class %d (bg_id %d) at map %s\n",class_, bg_id, map->list[m].name);
return 0;
}
@@ -753,11 +747,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;
@@ -786,30 +780,29 @@ 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);
}
/*==========================================
* Links nearby mobs (supportive mobs)
*------------------------------------------*/
-int mob_linksearch(struct block_list *bl,va_list ap)
-{
+int mob_linksearch(struct block_list *bl,va_list ap) {
struct mob_data *md;
int class_;
struct block_list *target;
- unsigned int tick;
+ int64 tick;
nullpo_ret(bl);
md=(struct mob_data *)bl;
class_ = va_arg(ap, int);
target = va_arg(ap, struct block_list *);
- tick=va_arg(ap, unsigned int);
+ tick = va_arg(ap, int64);
if (md->class_ == class_ && DIFF_TICK(md->last_linktime, tick) < MIN_MOBLINKTIME
&& !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;
@@ -822,9 +815,8 @@ int mob_linksearch(struct block_list *bl,va_list ap)
/*==========================================
* mob spawn with delay (timer function)
*------------------------------------------*/
-int mob_delayspawn(int tid, unsigned int tick, int id, intptr_t data)
-{
- struct block_list* bl = iMap->id2bl(id);
+int mob_delayspawn(int tid, int64 tick, int id, intptr_t data) {
+ struct block_list* bl = map->id2bl(id);
struct mob_data* md = BL_CAST(BL_MOB, bl);
if( md )
@@ -835,7 +827,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;
}
@@ -849,14 +841,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) {
@@ -876,20 +868,21 @@ 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);
+ timer->delete(md->spawn_timer, mob->delayspawn);
+ md->spawn_timer = timer->add(timer->gettick()+spawntime, mob->delayspawn, md->bl.id, 0);
return 0;
}
int mob_count_sub(struct block_list *bl, va_list ap) {
- int mobid[10], i;
- ARR_FIND(0, 10, i, (mobid[i] = va_arg(ap, int)) == 0); //fetch till 0
- if (mobid[0]) { //if there one let's check it otherwise go backward
- TBL_MOB *md = BL_CAST(BL_MOB, bl);
- ARR_FIND(0, 10, i, md->class_ == mobid[i]);
- return (i < 10) ? 1 : 0;
- }
- return 1; //backward compatibility
+ int mobid[10] = { 0 }, i;
+ ARR_FIND(0, 10, i, (mobid[i] = va_arg(ap, int)) == 0); //fetch till 0
+ if (mobid[0]) { //if there one let's check it otherwise go backward
+ TBL_MOB *md = BL_CAST(BL_MOB, bl);
+ nullpo_ret(md);
+ ARR_FIND(0, 10, i, md->class_ == mobid[i]);
+ return (i < 10) ? 1 : 0;
+ }
+ return 1; //backward compatibility
}
/*==========================================
@@ -898,18 +891,16 @@ int mob_count_sub(struct block_list *bl, va_list ap) {
int mob_spawn (struct mob_data *md)
{
int i=0;
- unsigned int tick = iTimer->gettick();
- int c =0;
+ int64 tick = timer->gettick();
+ int64 c = 0;
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_;
- status_set_viewdata(&md->bl, md->class_);
- md->db = mob_db(md->class_);
+ status->set_viewdata(&md->bl, md->class_);
+ md->db = mob->db(md->class_);
memcpy(md->name,md->spawn->name,NAME_LENGTH);
}
@@ -918,27 +909,26 @@ int mob_spawn (struct mob_data *md)
md->bl.x = md->spawn->x;
md->bl.y = md->spawn->y;
- if( (md->bl.x == 0 && md->bl.y == 0) || md->spawn->xs || md->spawn->ys )
- { //Monster can be spawned on an area.
- 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->bl.x == 0 && md->bl.y == 0) || md->spawn->xs || md->spawn->ys ) {
+ //Monster can be spawned on an area.
+ if( !map->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);
+ timer->delete(md->spawn_timer, mob->delayspawn);
+ md->spawn_timer = timer->add(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) )
- { // retry again later (players on sight)
+ } else if( battle_config.no_spawn_on_player > 99 && map->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);
+ timer->delete(md->spawn_timer, mob->delayspawn);
+ md->spawn_timer = timer->add(tick+5000,mob->delayspawn,md->bl.id,0);
return 1;
}
}
memset(&md->state, 0, sizeof(md->state));
- status_calc_mob(md, 1);
+ status_calc_mob(md, SCO_FIRST);
md->attacked_id = 0;
md->target_id = 0;
md->move_fail_count = 0;
@@ -946,7 +936,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);
+ timer->delete(md->spawn_timer, mob->delayspawn);
md->spawn_timer = INVALID_TIMER;
}
@@ -977,20 +967,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 )
+ map->addblock(&md->bl);
+ if( map->list[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)
@@ -1028,10 +1018,10 @@ 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(!status_check_skilluse(&md->bl, bl, 0, 0))
+ if(!status->check_skilluse(&md->bl, bl, 0, 0))
return 0;
md->target_id = bl->id; // Since there was no disturbance, it locks on to target.
@@ -1046,7 +1036,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;
@@ -1059,48 +1049,47 @@ static int mob_ai_sub_hard_activesearch(struct block_list *bl,va_list ap)
mode= va_arg(ap,int);
//If can't seek yet, not an enemy, or you can't attack it, skip.
- if ((*target) == bl || !status_check_skilluse(&md->bl, bl, 0, 0))
+ if (md->bl.id == bl->id || (*target) == bl || !status->check_skilluse(&md->bl, bl, 0, 0))
return 0;
- if ((mode&MD_TARGETWEAK) && status_get_lv(bl) >= md->level-5)
+ if ((mode&MD_TARGETWEAK) && status->get_lv(bl) >= md->level-5)
return 0;
if(battle->check_target(&md->bl,bl,BCT_ENEMY)<=0)
return 0;
- switch (bl->type)
- {
- case BL_PC:
- if (((TBL_PC*)bl)->state.gangsterparadise &&
- !(status_get_mode(&md->bl)&MD_BOSS))
- return 0; //Gangster paradise protection.
- default:
- if (battle_config.hom_setting&0x4 &&
- (*target) && (*target)->type == BL_HOM && bl->type != BL_HOM)
- return 0; //For some reason Homun targets are never overriden.
+ switch (bl->type) {
+ case BL_PC:
+ if (((TBL_PC*)bl)->state.gangsterparadise &&
+ !(status_get_mode(&md->bl)&MD_BOSS))
+ return 0; //Gangster paradise protection.
+ default:
+ if (battle_config.hom_setting&0x4 &&
+ (*target) && (*target)->type == BL_HOM && bl->type != BL_HOM)
+ return 0; //For some reason Homun targets are never overridden.
- dist = distance_bl(&md->bl, bl);
- if(
- ((*target) == NULL || !check_distance_bl(&md->bl, *target, dist)) &&
- battle->check_range(&md->bl,bl,md->db->range2)
- ) { //Pick closest target?
+ dist = distance_bl(&md->bl, bl);
+ if(
+ ((*target) == NULL || !check_distance_bl(&md->bl, *target, dist)) &&
+ battle->check_range(&md->bl,bl,md->db->range2)
+ ) { //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) ) {
+ if( map->list[bl->m].icewall_num &&
+ !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;
+ if( !check_distance_bl(&md->bl, bl, status_get_range(&md->bl) ) )
+ return 0;
- }
+ }
- (*target) = bl;
- md->target_id=bl->id;
- md->min_chase= dist + md->db->range3;
- if(md->min_chase>MAX_MINCHASE)
- md->min_chase=MAX_MINCHASE;
- return 1;
- }
- break;
+ (*target) = bl;
+ md->target_id=bl->id;
+ md->min_chase= dist + md->db->range3;
+ if(md->min_chase>MAX_MINCHASE)
+ md->min_chase=MAX_MINCHASE;
+ return 1;
+ }
+ break;
}
return 0;
}
@@ -1108,8 +1097,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;
@@ -1118,9 +1106,10 @@ static int mob_ai_sub_hard_changechase(struct block_list *bl,va_list ap)
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 ||
- battle->check_target(&md->bl,bl,BCT_ENEMY)<=0 ||
- !status_check_skilluse(&md->bl, bl, 0, 0))
+ if( md->bl.id == bl->id || *target == bl
+ || battle->check_target(&md->bl,bl,BCT_ENEMY) <= 0
+ || !status->check_skilluse(&md->bl, bl, 0, 0)
+ )
return 0;
if(battle->check_range (&md->bl, bl, md->status.rhw.range)) {
@@ -1134,7 +1123,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;
@@ -1142,7 +1131,7 @@ static int mob_ai_sub_hard_bg_ally(struct block_list *bl,va_list ap) {
md=va_arg(ap,struct mob_data *);
target= va_arg(ap,struct block_list**);
- if( status_check_skilluse(&md->bl, bl, 0, 0) && battle->check_target(&md->bl,bl,BCT_ENEMY)<=0 ) {
+ if( status->check_skilluse(&md->bl, bl, 0, 0) && battle->check_target(&md->bl,bl,BCT_ENEMY)<=0 ) {
(*target) = bl;
}
return 1;
@@ -1151,7 +1140,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;
@@ -1161,7 +1150,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;
@@ -1171,7 +1160,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;
@@ -1187,12 +1176,12 @@ static int mob_warpchase_sub(struct block_list *bl,va_list ap) {
if(nd->subtype != WARP)
return 0; //Not a warp
- if(nd->u.warp.mapindex != map[target->m].index)
+ if(nd->u.warp.mapindex != map_id2index(target->m))
return 0; //Does not lead to the same map.
cur_distance = distance_blxy(target, nd->u.warp.x, nd->u.warp.y);
- if (cur_distance < *min_distance)
- { //Pick warp that leads closest to target.
+ if (cur_distance < *min_distance) {
+ //Pick warp that leads closest to target.
*target_nd = nd;
*min_distance = cur_distance;
return 1;
@@ -1202,13 +1191,12 @@ 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, int64 tick) {
struct block_list *bl;
- bl=iMap->id2bl(md->master_id);
+ bl=map->id2bl(md->master_id);
- if (!bl || status_isdead(bl)) {
+ if (!bl || status->isdead(bl)) {
status_kill(&md->bl);
return 1;
}
@@ -1229,7 +1217,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;
}
@@ -1237,13 +1225,13 @@ static int mob_ai_sub_hard_slavemob(struct mob_data *md,unsigned int tick)
return 0;
// 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))
- {
+ if( (md->master_dist>MOB_SLAVEDISTANCE || md->master_dist == 0)
+ && 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))
+ if(map->search_freecell(&md->bl, bl->m, &x, &y, MOB_SLAVEDISTANCE, MOB_SLAVEDISTANCE, 1)
+ && unit->walktoxy(&md->bl, x, y, 0))
return 1;
}
} else if (bl->m != md->bl.m && map_flag_gvg(md->bl.m)) {
@@ -1255,20 +1243,20 @@ 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) {
struct block_list *tbl=NULL;
if (ud->target && ud->state.attack_continue)
- tbl=iMap->id2bl(ud->target);
+ tbl=map->id2bl(ud->target);
else if (ud->skilltarget) {
- tbl = iMap->id2bl(ud->skilltarget);
+ tbl = map->id2bl(ud->skilltarget);
//Required check as skilltarget is not always an enemy. [Skotlex]
if (tbl && battle->check_target(&md->bl, tbl, BCT_ENEMY) <= 0)
tbl = NULL;
}
- if (tbl && status_check_skilluse(&md->bl, tbl, 0, 0)) {
+ if (tbl && status->check_skilluse(&md->bl, tbl, 0, 0)) {
md->target_id=tbl->id;
md->min_chase=md->db->range3+distance_bl(&md->bl, tbl);
if(md->min_chase>MAX_MINCHASE)
@@ -1286,8 +1274,7 @@ static int mob_ai_sub_hard_slavemob(struct mob_data *md,unsigned int tick)
* when trying to pick new targets when the current chosen target is
* unreachable.
*------------------------------------------*/
-int mob_unlocktarget(struct mob_data *md, unsigned int tick)
-{
+int mob_unlocktarget(struct mob_data *md, int64 tick) {
nullpo_ret(md);
switch (md->state.skillstate) {
@@ -1299,12 +1286,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;
@@ -1319,15 +1306,14 @@ 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;
}
/*==========================================
* Random walk
*------------------------------------------*/
-int mob_randomwalk(struct mob_data *md,unsigned int tick)
-{
+int mob_randomwalk(struct mob_data *md, int64 tick) {
const int retrycount=20;
int i,x,y,c,d;
int speed;
@@ -1335,7 +1321,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;
@@ -1348,23 +1334,24 @@ 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((map->getcell(md->bl.m,x,y,CELL_CHKPASS)) && unit->walktoxy(&md->bl,x,y,1)){
break;
}
}
if(i==retrycount){
md->move_fail_count++;
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);
+ ShowWarning("MOB can't move. random spawn %d, class = %d, at %s (%d,%d)\n",md->bl.id,md->class_,map->list[md->bl.m].name, md->bl.x, md->bl.y);
md->move_fail_count=0;
- mob_spawn(md);
+ mob->spawn(md);
}
return 0;
}
- speed=status_get_speed(&md->bl);
- for(i=c=0;i<md->ud.walkpath.path_len;i++){ // The next walk start time is calculated.
+ speed=status->get_speed(&md->bl);
+ for(i=c=0;i<md->ud.walkpath.path_len;i++) {
+ // The next walk start time is calculated.
if(md->ud.walkpath.path[i]&1)
- c+=speed*14/10;
+ c+=speed*MOVE_DIAGONAL_COST/MOVE_COST;
else
c+=speed;
}
@@ -1385,14 +1372,14 @@ int mob_warpchase(struct mob_data *md, struct block_list *target)
return 0; //No need to do a warp chase.
if (md->ud.walktimer != INVALID_TIMER &&
- iMap->getcell(md->bl.m,md->ud.to_x,md->ud.to_y,CELL_CHKNPC))
+ map->getcell(md->bl.m,md->ud.to_x,md->ud.to_y,CELL_CHKNPC))
return 1; //Already walking to a warp.
//Search for warps within mob's viewing range.
- iMap->foreachinrange (mob_warpchase_sub, &md->bl,
- md->db->range2, BL_NPC, target, &warp, &distance);
+ map->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;
}
@@ -1400,8 +1387,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, int64 tick) {
struct block_list *tbl = NULL, *abl = NULL;
int mode;
int view_range, can_move;
@@ -1422,7 +1408,8 @@ static bool mob_ai_sub_hard(struct mob_data *md, unsigned int tick)
// Abnormalities
if(( md->sc.opt1 > 0 && md->sc.opt1 != OPT1_STONEWAIT && md->sc.opt1 != OPT1_BURNING && md->sc.opt1 != OPT1_CRYSTALIZE )
- || md->sc.data[SC_BLADESTOP] || md->sc.data[SC__MANHOLE] || md->sc.data[SC_CURSEDCIRCLE_TARGET]) {//Should reset targets.
+ || md->sc.data[SC_DEEP_SLEEP] || md->sc.data[SC_BLADESTOP] || md->sc.data[SC__MANHOLE] || md->sc.data[SC_CURSEDCIRCLE_TARGET]) {
+ //Should reset targets.
md->target_id = md->attacked_id = 0;
return false;
}
@@ -1433,22 +1420,23 @@ 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);
-
- if (md->target_id)
- { //Check validity of current target. [Skotlex]
- tbl = iMap->id2bl(md->target_id);
- if (!tbl || tbl->m != md->bl.m ||
- (md->ud.attacktimer == INVALID_TIMER && !status_check_skilluse(&md->bl, tbl, 0, 0)) ||
- (md->ud.walktimer != INVALID_TIMER && !(battle_config.mob_ai&0x1) && !check_distance_bl(&md->bl, tbl, md->min_chase)) ||
- (
- tbl->type == BL_PC &&
- ((((TBL_PC*)tbl)->state.gangsterparadise && !(mode&MD_BOSS)) ||
- ((TBL_PC*)tbl)->invincible_timer != INVALID_TIMER)
- )) { //Unlock current target.
- if (mob_warpchase(md, tbl))
+ can_move = (mode&MD_CANMOVE)&&unit->can_move(&md->bl);
+
+ if (md->target_id) {
+ //Check validity of current target. [Skotlex]
+ tbl = map->id2bl(md->target_id);
+ if (!tbl || tbl->m != md->bl.m
+ || (md->ud.attacktimer == INVALID_TIMER && !status->check_skilluse(&md->bl, tbl, 0, 0))
+ || (md->ud.walktimer != INVALID_TIMER && !(battle_config.mob_ai&0x1) && !check_distance_bl(&md->bl, tbl, md->min_chase))
+ || ( tbl->type == BL_PC
+ && ((((TBL_PC*)tbl)->state.gangsterparadise && !(mode&MD_BOSS))
+ || ((TBL_PC*)tbl)->invincible_timer != INVALID_TIMER)
+ )
+ ) {
+ //Unlock current target.
+ 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)); //Immediately do random walk.
tbl = NULL;
}
}
@@ -1463,36 +1451,36 @@ 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 = map->id2bl(md->attacked_id)) && (!tbl || mob->can_changetarget(md, abl, mode) || (md->sc.count && md->sc.data[SC__CHAOS]))) {
int dist;
if( md->bl.m != abl->m || abl->prev == NULL
- || (dist = distance_bl(&md->bl, abl)) >= MAX_MINCHASE // Attacker longer than visual area
- || battle->check_target(&md->bl, abl, BCT_ENEMY) <= 0 // Attacker is not enemy of mob
- || (battle_config.mob_ai&0x2 && !status_check_skilluse(&md->bl, abl, 0, 0)) // Cannot normal attack back to Attacker
- || (!battle->check_range(&md->bl, abl, md->status.rhw.range) // Not on Melee Range and ...
- && ( // Reach check
- (!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)
- )
- ) )
- { // Rude attacked
+ || (dist = distance_bl(&md->bl, abl)) >= MAX_MINCHASE // Attacker longer than visual area
+ || battle->check_target(&md->bl, abl, BCT_ENEMY) <= 0 // Attacker is not enemy of mob
+ || (battle_config.mob_ai&0x2 && !status->check_skilluse(&md->bl, abl, 0, 0)) // Cannot normal attack back to Attacker
+ || (!battle->check_range(&md->bl, abl, md->status.rhw.range) // Not on Melee Range and ...
+ && ( // Reach check
+ (!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)
+ )
+ )
+ ) {
+ // 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;
@@ -1500,12 +1488,10 @@ static bool mob_ai_sub_hard(struct mob_data *md, unsigned int tick)
}
}
else
- if (!(battle_config.mob_ai&0x2) && !status_check_skilluse(&md->bl, abl, 0, 0))
- {
+ if (!(battle_config.mob_ai&0x2) && !status->check_skilluse(&md->bl, abl, 0, 0)) {
//Can't attack back, but didn't invoke a rude attacked skill...
- }
- else
- { //Attackable
+ } else {
+ //Attackable
if (!tbl || dist < md->status.rhw.range || !check_distance_bl(&md->bl, tbl, dist)
|| battle->get_target(tbl) != md->bl.id)
{ //Change if the new target is closer than the actual one
@@ -1526,26 +1512,23 @@ 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);
+ 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.
+ map->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);
- }
- else
- if (mode&MD_CHANGECHASE && (md->state.skillstate == MSS_RUSH || md->state.skillstate == MSS_FOLLOW))
- {
+ if ((!tbl && mode&MD_AGGRESSIVE) || md->state.skillstate == MSS_FOLLOW) {
+ map->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)) || (md->sc.count && md->sc.data[SC__CHAOS])) {
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);
+ map->foreachinrange (mob->ai_sub_hard_changechase, &md->bl, search_size, DEFAULT_ENEMY_TYPE(md), md, &tbl);
}
if (!tbl) { //No targets available.
@@ -1556,15 +1539,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);
+ map->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;
}
@@ -1576,21 +1559,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.
@@ -1605,7 +1588,7 @@ static bool mob_ai_sub_hard(struct mob_data *md, unsigned int tick)
memcpy (&md->lootitem[md->lootitem_count++], &fitem->item_data, sizeof(md->lootitem[0]));
} else { //Destroy first looted item...
if (md->lootitem[0].card[0] == CARD0_PET)
- intif_delete_petdata( MakeDWord(md->lootitem[0].card[1],md->lootitem[0].card[2]) );
+ intif->delete_petdata( MakeDWord(md->lootitem[0].card[1],md->lootitem[0].card[2]) );
memmove(&md->lootitem[0], &md->lootitem[1], (LOOTITEM_SIZE-1)*sizeof(md->lootitem[0]));
memcpy (&md->lootitem[LOOTITEM_SIZE-1], &fitem->item_data, sizeof(md->lootitem[0]));
}
@@ -1613,11 +1596,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);
+ map->clearflooritem (tbl);
+ mob->unlocktarget (md,tick);
return true;
}
//Attempt to attack.
@@ -1629,8 +1612,20 @@ 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)
+
+ if(!(mode&MD_RANDOMTARGET))
+ unit->attack(&md->bl,tbl->id,1);
+ else { // Attack once and find new random target
+ int search_size = (view_range < md->status.rhw.range) ? view_range : md->status.rhw.range;
+ unit->attack(&md->bl,tbl->id,0);
+ tbl = battle->get_enemy(&md->bl, DEFAULT_ENEMY_TYPE(md), search_size);
+ // If no target was found, keep atacking the old one
+ if( tbl ) {
+ md->target_id = tbl->id;
+ md->min_chase = md->db->range3;
+ }
+ }
return true;
}
@@ -1638,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;
}
@@ -1647,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;
}
@@ -1659,18 +1654,17 @@ 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))
+ int64 tick = va_arg(ap, int64);
+ if (mob->ai_sub_hard(md, tick))
{ //Hard AI triggered.
if(!md->state.spotted)
md->state.spotted = 1;
@@ -1682,11 +1676,10 @@ 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)
-{
- 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);
+int mob_ai_sub_foreachclient(struct map_session_data *sd, va_list ap) {
+ int64 tick;
+ tick=va_arg(ap, int64);
+ map->foreachinrange(mob->ai_sub_hard_timer,&sd->bl, AREA_SIZE+ACTIVE_AI_RANGE, BL_MOB,tick);
return 0;
}
@@ -1694,19 +1687,18 @@ 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)
-{
- unsigned int tick;
+int mob_ai_sub_lazy(struct mob_data *md, va_list args) {
+ int64 tick;
nullpo_ret(md);
if(md->bl.prev == NULL)
return 0;
- tick = va_arg(args,unsigned int);
+ tick = va_arg(args, int64);
- if (battle_config.mob_ai&0x20 && map[md->bl.m].users>0)
- return (int)mob_ai_sub_hard(md, tick);
+ if (battle_config.mob_ai&0x20 && map->list[md->bl.m].users>0)
+ return (int)mob->ai_sub_hard(md, tick);
if (md->bl.prev==NULL || md->status.hp == 0)
return 1;
@@ -1717,7 +1709,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;
}
@@ -1727,7 +1719,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;
}
@@ -1737,24 +1729,23 @@ 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( map[md->bl.m].users > 0 )
+ if( DIFF_TICK(md->next_walktime,tick) < 0 && (status_get_mode(&md->bl)&MD_CANMOVE) && unit->can_move(&md->bl) ) {
+ if( map->list[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;
@@ -1763,22 +1754,20 @@ 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)
-{
- iMap->map_foreachmob(mob_ai_sub_lazy,tick);
+int mob_ai_lazy(int tid, int64 tick, int id, intptr_t data) {
+ 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, int64 tick, int id, intptr_t data) {
if (battle_config.mob_ai&0x20)
- iMap->map_foreachmob(mob_ai_sub_lazy,tick);
+ map->foreachmob(mob->ai_sub_lazy,tick);
else
- iMap->map_foreachpc(mob_ai_sub_foreachclient,tick);
+ map->foreachpc(mob->ai_sub_foreachclient,tick);
return 0;
}
@@ -1786,12 +1775,11 @@ 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;
}
@@ -1799,7 +1787,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));
@@ -1810,16 +1798,15 @@ 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, int64 tick, int id, intptr_t data) {
struct item_drop_list *list;
struct item_drop *ditem, *ditem_prev;
list=(struct item_drop_list *)data;
ditem = list->item;
while (ditem) {
- iMap->addflooritem(&ditem->item_data,ditem->item_data.amount,
- list->m,list->x,list->y,
- list->first_charid,list->second_charid,list->third_charid,0);
+ map->addflooritem(&ditem->item_data,ditem->item_data.amount,
+ list->m,list->x,list->y,
+ list->first_charid,list->second_charid,list->third_charid,0);
ditem_prev = ditem;
ditem = ditem->next;
ers_free(item_drop_ers, ditem_prev);
@@ -1834,20 +1821,20 @@ 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;
//Logs items, dropped by mobs [Lupus]
logs->pick_mob(md, loot?LOG_TYPE_LOOT:LOG_TYPE_PICKDROP_MONSTER, -ditem->item_data.amount, &ditem->item_data, NULL);
- sd = iMap->charid2sd(dlist->first_charid);
- if( sd == NULL ) sd = iMap->charid2sd(dlist->second_charid);
- if( sd == NULL ) sd = iMap->charid2sd(dlist->third_charid);
+ sd = map->charid2sd(dlist->first_charid);
+ if( sd == NULL ) sd = map->charid2sd(dlist->second_charid);
+ if( sd == NULL ) sd = map->charid2sd(dlist->third_charid);
if( sd
&& (drop_rate <= sd->state.autoloot || pc->isautolooting(sd, ditem->item_data.nameid))
- && (battle_config.idle_no_autoloot == 0 || DIFF_TICK(last_tick, sd->idletime) < battle_config.idle_no_autoloot)
+ && (battle_config.idle_no_autoloot == 0 || DIFF_TICK(sockt->last_tick, sd->idletime) < battle_config.idle_no_autoloot)
&& (battle_config.homunculus_autoloot?1:!flag)
#ifdef AUTOLOOT_DISTANCE
&& sd->bl.m == md->bl.m
@@ -1865,9 +1852,8 @@ static void mob_item_drop(struct mob_data *md, struct item_drop_list *dlist, str
dlist->item = ditem;
}
-int mob_timer_delete(int tid, unsigned int tick, int id, intptr_t data)
-{
- struct block_list* bl = iMap->id2bl(id);
+int mob_timer_delete(int tid, int64 tick, int id, intptr_t data) {
+ struct block_list* bl = map->id2bl(id);
struct mob_data* md = BL_CAST(BL_MOB, bl);
if( md )
@@ -1879,7 +1865,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;
}
@@ -1904,20 +1890,18 @@ int mob_deleteslave_sub(struct block_list *bl,va_list ap)
/*==========================================
*
*------------------------------------------*/
-int mob_deleteslave(struct mob_data *md)
-{
+int mob_deleteslave(struct mob_data *md) {
nullpo_ret(md);
- iMap->foreachinmap(mob_deleteslave_sub, md->bl.m, BL_MOB,md->bl.id);
+ map->foreachinmap(mob->deleteslave_sub, md->bl.m, BL_MOB,md->bl.id);
return 0;
}
// Mob respawning through KAIZEL or NPC_REBIRTH [Skotlex]
-int mob_respawn(int tid, unsigned int tick, int id, intptr_t data)
-{
- struct block_list *bl = iMap->id2bl(id);
+int mob_respawn(int tid, int64 tick, int id, intptr_t data) {
+ struct block_list *bl = map->id2bl(id);
if(!bl) return 0;
- status_revive(bl, (uint8)data, 0);
+ status->revive(bl, (uint8)data, 0);
return 1;
}
@@ -1976,9 +1960,8 @@ void mob_log_damage(struct mob_data *md, struct block_list *src, int damage)
case BL_MOB:
{
struct mob_data* md2 = (TBL_MOB*)src;
- if( md2->special_state.ai && md2->master_id )
- {
- struct map_session_data* msd = iMap->id2sd(md2->master_id);
+ if( md2->special_state.ai && md2->master_id ) {
+ struct map_session_data* msd = map->id2sd(md2->master_id);
if( msd )
char_id = msd->status.char_id;
}
@@ -2053,8 +2036,8 @@ void mob_damage(struct mob_data *md, struct block_list *src, int damage) {
}
//Log damage
if (src)
- mob_log_damage(md, src, damage);
- md->dmgtick = iTimer->gettick();
+ mob->log_damage(md, src, damage);
+ md->dmgtick = timer->gettick();
}
if (battle_config.show_mob_info&3)
@@ -2068,7 +2051,7 @@ void mob_damage(struct mob_data *md, struct block_list *src, int damage) {
int i;
for(i = 0; i < DAMAGELOG_SIZE; i++){ // must show hp bar to all char who already hit the mob.
if( md->dmglog[i].id ) {
- struct map_session_data *sd = iMap->charid2sd(md->dmglog[i].id);
+ struct map_session_data *sd = map->charid2sd(md->dmglog[i].id);
if( sd && check_distance_bl(&md->bl, &sd->bl, AREA_SIZE) ) // check if in range
clif->monster_hp_bar(md,sd);
}
@@ -2078,7 +2061,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, timer->gettick(), MSC_ALCHEMIST);
}
}
@@ -2086,9 +2069,8 @@ void mob_damage(struct mob_data *md, struct block_list *src, int damage) {
* Signals death of mob.
* type&1 -> no drops, type&2 -> no exp
*------------------------------------------*/
-int mob_dead(struct mob_data *md, struct block_list *src, int type)
-{
- struct status_data *status;
+int mob_dead(struct mob_data *md, struct block_list *src, int type) {
+ struct status_data *mstatus;
struct map_session_data *sd = NULL, *tmpsd[DAMAGELOG_SIZE];
struct map_session_data *mvp_sd = NULL, *second_sd = NULL, *third_sd = NULL;
@@ -2098,11 +2080,12 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type)
unsigned int base_exp,job_exp;
} pt[DAMAGELOG_SIZE];
int i, temp, count, m = md->bl.m, pnum = 0;
- int dmgbltypes = 0; // bitfield of all bl types, that caused damage to the mob and are elligible for exp distribution
- unsigned int mvp_damage, tick = iTimer->gettick();
+ int dmgbltypes = 0; // bitfield of all bl types, that caused damage to the mob and are eligible for exp distribution
+ unsigned int mvp_damage;
+ int64 tick = timer->gettick();
bool rebirth, homkillonly;
- status = &md->status;
+ mstatus = &md->status;
if( src && src->type == BL_PC )
{
@@ -2116,21 +2099,20 @@ 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();
+ map->freeblock_lock();
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));
- for(i = 0, count = 0, mvp_damage = 0; i < DAMAGELOG_SIZE && md->dmglog[i].id; i++)
- {
- struct map_session_data* tsd = iMap->charid2sd(md->dmglog[i].id);
+ for(i = 0, count = 0, mvp_damage = 0; i < DAMAGELOG_SIZE && md->dmglog[i].id; i++) {
+ struct map_session_data* tsd = map->charid2sd(md->dmglog[i].id);
if(tsd == NULL)
continue; // skip empty entries
@@ -2175,21 +2157,21 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type)
}
}
- if(!(type&2) && //No exp
- (!map[m].flag.pvp || battle_config.pvp_exp) && //Pvp no exp rule [MouseJstr]
- (!md->master_id || !md->special_state.ai) && //Only player-summoned mobs do not give exp. [Skotlex]
- (!map[m].flag.nobaseexp || !map[m].flag.nojobexp) //Gives Exp
+ if( !(type&2) //No exp
+ && (!map->list[m].flag.pvp || battle_config.pvp_exp) //Pvp no exp rule [MouseJstr]
+ && (!md->master_id || !md->special_state.ai) //Only player-summoned mobs do not give exp. [Skotlex]
+ && (!map->list[m].flag.nobaseexp || !map->list[m].flag.nojobexp) //Gives Exp
) { //Experience calculation.
int bonus = 100; //Bonus on top of your share (common to all attackers).
if (md->sc.data[SC_RICHMANKIM])
bonus += md->sc.data[SC_RICHMANKIM]->val2;
if(sd) {
- temp = status_get_class(&md->bl);
+ temp = status->get_class(&md->bl);
if(sd->sc.data[SC_MIRACLE]) i = 2; //All mobs are Star Targets
else
ARR_FIND(0, MAX_PC_FEELHATE, i, temp == sd->hate_mob[i] &&
- (battle_config.allow_skill_without_day || sg_info[i].day_func()));
- if(i<MAX_PC_FEELHATE && (temp=pc->checkskill(sd,sg_info[i].bless_id)))
+ (battle_config.allow_skill_without_day || pc->sg_info[i].day_func()));
+ if(i<MAX_PC_FEELHATE && (temp=pc->checkskill(sd,pc->sg_info[i].bless_id)))
bonus += (i==2?20:10)*temp;
}
if(battle_config.mobs_level_up && md->level > md->db->lv) // [Valaris]
@@ -2207,7 +2189,7 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type)
per = (double)md->dmglog[i].dmg/(double)md->tdmg;
else {
//eAthena's exp formula based on max hp.
- per = (double)md->dmglog[i].dmg/(double)status->max_hp;
+ per = (double)md->dmglog[i].dmg/(double)mstatus->max_hp;
if (per > 2) per = 2; // prevents unlimited exp gain
}
@@ -2221,7 +2203,7 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type)
// change experience for different sized monsters [Valaris]
if (battle_config.mob_size_influence) {
switch( md->special_state.size ) {
- case SZ_MEDIUM:
+ case SZ_SMALL:
per /= 2.;
break;
case SZ_BIG:
@@ -2240,15 +2222,15 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type)
zeny*=rnd()%250;
}
- if (map[m].flag.nobaseexp || !md->db->base_exp)
+ if (map->list[m].flag.nobaseexp || !md->db->base_exp)
base_exp = 0;
else
- base_exp = (unsigned int)cap_value(md->db->base_exp * per * bonus/100. * map[m].bexp/100., 1, UINT_MAX);
+ base_exp = (unsigned int)cap_value(md->db->base_exp * per * bonus/100. * map->list[m].bexp/100., 1, UINT_MAX);
- if (map[m].flag.nojobexp || !md->db->job_exp || md->dmglog[i].flag == MDLF_HOMUN) //Homun earned job-exp is always lost.
+ if (map->list[m].flag.nojobexp || !md->db->job_exp || md->dmglog[i].flag == MDLF_HOMUN) //Homun earned job-exp is always lost.
job_exp = 0;
else
- job_exp = (unsigned int)cap_value(md->db->job_exp * per * bonus/100. * map[m].jexp/100., 1, UINT_MAX);
+ job_exp = (unsigned int)cap_value(md->db->job_exp * per * bonus/100. * map->list[m].jexp/100., 1, UINT_MAX);
if ( (temp = tmpsd[i]->status.party_id) > 0 ) {
int j;
@@ -2285,7 +2267,7 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type)
if(base_exp || job_exp) {
if( md->dmglog[i].flag != MDLF_PET || battle_config.pet_attack_exp_to_master ) {
#ifdef RENEWAL_EXP
- int rate = pc->level_penalty_mod(tmpsd[i], md, 1);
+ int rate = pc->level_penalty_mod(md->level - (tmpsd[i])->status.base_level, md->status.race, md->status.mode, 1);
base_exp = (unsigned int)cap_value(base_exp * rate / 100, 1, UINT_MAX);
job_exp = (unsigned int)cap_value(job_exp * rate / 100, 1, UINT_MAX);
#endif
@@ -2302,7 +2284,7 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type)
} //End EXP giving.
- if( !(type&1) && !map[m].flag.nomobloot && !md->state.rebirth && (
+ if( !(type&1) && !map->list[m].flag.nomobloot && !md->state.rebirth && (
!md->special_state.ai || //Non special mob
battle_config.alchemist_summon_reward == 2 || //All summoned give drops
(md->special_state.ai==2 && battle_config.alchemist_summon_reward == 1) //Marine Sphere Drops items.
@@ -2313,10 +2295,10 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type)
struct item_data* it = NULL;
int drop_rate;
#ifdef RENEWAL_DROP
- int drop_modifier = mvp_sd ? pc->level_penalty_mod(mvp_sd, md, 2) :
- second_sd ? pc->level_penalty_mod(second_sd, md, 2):
- third_sd ? pc->level_penalty_mod(third_sd, md, 2) :
- 100;/* no player was attached, we dont use any modifier (100 = rates are not touched) */
+ int drop_modifier = mvp_sd ? pc->level_penalty_mod( md->level - mvp_sd->status.base_level, md->status.race, md->status.mode, 2) :
+ second_sd ? pc->level_penalty_mod( md->level - second_sd->status.base_level, md->status.race, md->status.mode, 2):
+ third_sd ? pc->level_penalty_mod( md->level - third_sd->status.base_level, md->status.race, md->status.mode, 2) :
+ 100;/* no player was attached, we don't use any modifier (100 = rates are not touched) */
#endif
dlist->m = md->bl.m;
dlist->x = md->bl.x;
@@ -2330,7 +2312,7 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type)
{
if (md->db->dropitem[i].nameid <= 0)
continue;
- if ( !(it = itemdb_exists(md->db->dropitem[i].nameid)) )
+ if ( !(it = itemdb->exists(md->db->dropitem[i].nameid)) )
continue;
drop_rate = md->db->dropitem[i].p;
if (drop_rate <= 0) {
@@ -2342,7 +2324,7 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type)
// change drops depending on monsters size [Valaris]
if (battle_config.mob_size_influence)
{
- if (md->special_state.size == SZ_MEDIUM && drop_rate >= 2)
+ if (md->special_state.size == SZ_SMALL && drop_rate >= 2)
drop_rate /= 2;
else if( md->special_state.size == SZ_BIG)
drop_rate *= 2;
@@ -2370,33 +2352,49 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type)
drop_rate = 1;
}
#endif
+ if( sd && sd->status.mod_drop != 100 ) {
+ drop_rate = drop_rate * sd->status.mod_drop / 100;
+ if( drop_rate < 1 )
+ drop_rate = 1;
+ }
+
// attempt to drop the item
if (rnd() % 10000 >= drop_rate)
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 ) {
char message[128];
sprintf (message, msg_txt(541), mvp_sd->status.name, md->name, it->jname, (float)drop_rate/100);
//MSG: "'%s' won %s's %s (chance: %0.02f%%)"
- intif_broadcast(message,strlen(message)+1,0);
+ intif->broadcast(message, strlen(message)+1, BC_DEFAULT);
}
+
+ /* heres the thing we got the feature set up however we're still discussing how to best define the ids,
+ * so while we discuss, for a small period of time, the list is hardcoded (yes officially only those 2 use it,
+ * thus why we're unsure on how to best place the setting) */
+ /* temp, will not be hardcoded for long thudu. */
+ if( it->nameid == 7782 || it->nameid == 7783 ) /* for when not hardcoded: add a check on mvp bonus drop as well */
+ clif->item_drop_announce(mvp_sd, it->nameid, md->name);
+
// 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 && battle_config.finding_ore_rate/10 >= rnd()%10000) {
- ditem = mob_setdropitem(itemdb_searchrandomid(IG_FINDINGORE), 1, NULL);
- mob_item_drop(md, dlist, ditem, 0, battle_config.finding_ore_rate/10, homkillonly);
+ 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);
+ }
}
if(sd) {
@@ -2406,8 +2404,8 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type)
{
if ( sd->add_drop[i].race == -md->class_ ||
( sd->add_drop[i].race > 0 && (
- sd->add_drop[i].race & (1<<status->race) ||
- sd->add_drop[i].race & (1<<(status->mode&MD_BOSS?RC_BOSS:RC_NONBOSS))
+ sd->add_drop[i].race & (1<<mstatus->race) ||
+ sd->add_drop[i].race & (1<<(mstatus->mode&MD_BOSS?RC_BOSS:RC_NONBOSS))
)))
{
//check if the bonus item drop rate should be multiplied with mob level/10 [Lupus]
@@ -2424,8 +2422,9 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type)
if (rnd()%10000 >= drop_rate)
continue;
- itemid = (sd->add_drop[i].id > 0) ? sd->add_drop[i].id : itemdb_searchrandomid(sd->add_drop[i].group);
- mob_item_drop(md, dlist, mob_setdropitem(itemid,1,NULL), 0, drop_rate, homkillonly);
+ 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);
}
}
@@ -2440,10 +2439,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);
+ timer->add(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!
@@ -2456,18 +2455,17 @@ 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);
+ timer->add(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) {
int log_mvp[2] = {0};
unsigned int mexp;
- struct item item;
double exp;
//mapflag: noexp check [Lorky]
- if (map[m].flag.nobaseexp || type&2)
+ if (map->list[m].flag.nobaseexp || type&2)
exp =1;
else {
exp = md->db->mexp;
@@ -2482,10 +2480,11 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type)
pc->gainexp(mvp_sd, &md->bl, mexp,0, false);
log_mvp[1] = mexp;
- if( !(map[m].flag.nomvploot || type&1) ) {
+ if( !(map->list[m].flag.nomvploot || type&1) ) {
/* pose them randomly in the list -- so on 100% drop servers it wont always drop the same item */
int mdrop_id[MAX_MVP_DROP];
int mdrop_p[MAX_MVP_DROP];
+ struct item item;
memset(&mdrop_id,0,MAX_MVP_DROP*sizeof(int));
@@ -2504,7 +2503,7 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type)
struct item_data *data;
if(mdrop_id[i] <= 0)
continue;
- if(! (data = itemdb_exists(mdrop_id[i])) )
+ if(! (data = itemdb->exists(mdrop_id[i])) )
continue;
temp = mdrop_p[i];
@@ -2515,7 +2514,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;
@@ -2524,12 +2523,12 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type)
char message[128];
sprintf (message, msg_txt(541), mvp_sd->status.name, md->name, data->jname, temp/100.);
//MSG: "'%s' won %s's %s (chance: %0.02f%%)"
- intif_broadcast(message,strlen(message)+1,0);
+ intif->broadcast(message, strlen(message)+1, BC_DEFAULT);
}
if((temp = pc->additem(mvp_sd,&item,1,LOG_TYPE_PICKDROP_PLAYER)) != 0) {
clif->additem(mvp_sd,0,0,temp);
- iMap->addflooritem(&item,1,mvp_sd->bl.m,mvp_sd->bl.x,mvp_sd->bl.y,mvp_sd->status.char_id,(second_sd?second_sd->status.char_id:0),(third_sd?third_sd->status.char_id:0),1);
+ map->addflooritem(&item,1,mvp_sd->bl.m,mvp_sd->bl.x,mvp_sd->bl.y,mvp_sd->status.char_id,(second_sd?second_sd->status.char_id:0),(third_sd?third_sd->status.char_id:0),1);
}
//Logs items, MVP prizes [Lupus]
@@ -2541,7 +2540,7 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type)
logs->mvpdrop(mvp_sd, md->class_, log_mvp);
}
- if (type&2 && !sd && md->class_ == MOBID_EMPERIUM)
+ if (type&2 && !sd && md->class_ == MOBID_EMPERIUM && md->guardian_data)
//Emperium destroyed by script. Discard mvp character. [Skotlex]
mvp_sd = NULL;
@@ -2559,58 +2558,58 @@ 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);
+ pc_setglobalreg(sd,script->add_str("TK_MISSION_ID"), temp);
sd->mission_count = 0;
clif->mission_info(sd, temp, 0);
}
- pc_setglobalreg(sd,"TK_MISSION_COUNT", sd->mission_count);
+ pc_setglobalreg(sd,script->add_str("TK_MISSION_COUNT"), sd->mission_count);
}
if( sd->status.party_id )
- iMap->foreachinrange(quest_update_objective_sub,&md->bl,AREA_SIZE,BL_PC,sd->status.party_id,md->class_);
+ map->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 )
- mercenary_kills(sd->md);
+ 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);
+ timer->delete(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();
+ map->freeblock_unlock();
if( !rebirth ) {
if( pcdb_checkid(md->vd->class_) ) {//Player mobs are not removed automatically by the client.
- /* first we set them dead, then we delay the outsight effect */
+ /* first we set them dead, then we delay the out sight effect */
clif->clearunit_area(&md->bl,CLR_DEAD);
clif->clearunit_delayed(&md->bl, CLR_OUTSIGHT,tick+3000);
} else
@@ -2622,23 +2621,23 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type)
}
- if(!md->spawn) //Tell status_damage to remove it from memory.
+ if(!md->spawn) //Tell status->damage to remove it from memory.
return 5; // Note: Actually, it's 4. Oh well...
// MvP tomb [GreenBox]
- if (battle_config.mvp_tomb_enabled && md->spawn->state.boss)
- mvptomb_create(md, mvp_sd ? mvp_sd->status.name : NULL, time(NULL));
+ if (battle_config.mvp_tomb_enabled && md->spawn->state.boss && map->list[md->bl.m].flag.notomb != 1)
+ mob->mvptomb_create(md, mvp_sd ? mvp_sd->status.name : NULL, time(NULL));
if( !rebirth ) {
- status_change_clear(&md->bl,1);
- mob_setdelayspawn(md); //Set respawning.
+ status->change_clear(&md->bl,1);
+ mob->setdelayspawn(md); //Set respawning.
}
return 3; //Remove from map.
}
void mob_revive(struct mob_data *md, unsigned int hp)
{
- unsigned int tick = iTimer->gettick();
+ int64 tick = timer->gettick();
md->state.skillstate = MSS_IDLE;
md->last_thinktime = tick;
md->next_walktime = tick+rnd()%50+5000;
@@ -2647,10 +2646,10 @@ void mob_revive(struct mob_data *md, unsigned int hp)
memset(md->dmglog, 0, sizeof(md->dmglog)); // Reset the damage done on the rebirthed monster, otherwise will grant full exp + damage done. [Valaris]
md->tdmg = 0;
if (!md->bl.prev)
- iMap->addblock(&md->bl);
+ map->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);
}
@@ -2663,35 +2662,29 @@ int mob_guardian_guildchange(struct mob_data *md)
if (!md->guardian_data)
return 0;
- if (md->guardian_data->castle->guild_id == 0)
+ if( md->guardian_data->castle->guild_id == 0 )
{ //Castle with no owner? Delete the guardians.
- if (md->class_ == MOBID_EMPERIUM)
- { //But don't delete the emperium, just clear it's guild-data
- md->guardian_data->guild_id = 0;
- md->guardian_data->emblem_id = 0;
- md->guardian_data->guild_name[0] = '\0';
- } else {
+ if( md->class_ == MOBID_EMPERIUM ) //But don't delete the emperium, just clear it's guild-data
+ md->guardian_data->g = NULL;
+ 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;
}
g = guild->search(md->guardian_data->castle->guild_id);
- if (g == NULL)
+ if( g == NULL )
{ //Properly remove guardian info from Castle data.
- ShowError("mob_guardian_guildchange: New Guild (id %d) does not exists!\n", md->guardian_data->guild_id);
+ ShowError("mob_guardian_guildchange: New Guild (id %d) does not exists!\n", md->guardian_data->castle->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;
}
- md->guardian_data->guild_id = g->guild_id;
- md->guardian_data->emblem_id = g->emblem_id;
- md->guardian_data->guardup_lv = guild->checkskill(g,GD_GUARDUP);
- memcpy(md->guardian_data->guild_name, g->name, NAME_LENGTH);
+ md->guardian_data->g = g;
return 1;
}
@@ -2706,16 +2699,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]);
}
/*==========================================
@@ -2723,8 +2716,8 @@ int mob_random_class (int *value, size_t count)
*------------------------------------------*/
int mob_class_change (struct mob_data *md, int class_)
{
- unsigned int tick = iTimer->gettick();
- int i, c, hp_rate;
+ int64 tick = timer->gettick(), c = 0;
+ int i, hp_rate;
nullpo_ret(md);
@@ -2741,7 +2734,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_ )
@@ -2749,7 +2742,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
@@ -2757,10 +2750,10 @@ int mob_class_change (struct mob_data *md, int class_)
mob_stop_attack(md);
mob_stop_walking(md, 0);
- unit_skillcastcancel(&md->bl, 0);
- status_set_viewdata(&md->bl, class_);
+ unit->skillcastcancel(&md->bl, 0);
+ status->set_viewdata(&md->bl, class_);
clif->class_change(&md->bl, md->vd->class_, 1);
- status_calc_mob(md, 1);
+ status_calc_mob(md, SCO_FIRST);
md->ud.state.speed_changed = 1; //Speed change update.
if (battle_config.monster_class_change_recover) {
@@ -2793,13 +2786,25 @@ void mob_heal(struct mob_data *md,unsigned int heal)
{
if (battle_config.show_mob_info&3)
clif->charnameack (0, &md->bl);
+
+#if PACKETVER >= 20120404
+ if( !(md->status.mode&MD_BOSS) ){
+ int i;
+ for(i = 0; i < DAMAGELOG_SIZE; i++){ // must show hp bar to all char who already hit the mob.
+ if( md->dmglog[i].id ) {
+ struct map_session_data *sd = map->charid2sd(md->dmglog[i].id);
+ if( sd && check_distance_bl(&md->bl, &sd->bl, AREA_SIZE) ) // check if in range
+ clif->monster_hp_bar(md,sd);
+ }
+ }
+ }
+#endif
}
/*==========================================
* Added by RoVeRT
*------------------------------------------*/
-int mob_warpslave_sub(struct block_list *bl,va_list ap)
-{
+int mob_warpslave_sub(struct block_list *bl,va_list ap) {
struct mob_data *md=(struct mob_data *)bl;
struct block_list *master;
short x,y,range=0;
@@ -2809,8 +2814,8 @@ int mob_warpslave_sub(struct block_list *bl,va_list ap)
if(md->master_id!=master->id)
return 0;
- iMap->search_freecell(master, 0, &x, &y, range, range, 0);
- unit_warp(&md->bl, master->m, x, y,CLR_RESPAWN);
+ map->search_freecell(master, 0, &x, &y, range, range, 0);
+ unit->warp(&md->bl, master->m, x, y,CLR_TELEPORT);
return 1;
}
@@ -2819,16 +2824,15 @@ int mob_warpslave_sub(struct block_list *bl,va_list ap)
* Warps slaves. Range is the area around the master that they can
* appear in randomly.
*------------------------------------------*/
-int mob_warpslave(struct block_list *bl, int range)
-{
+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 map->foreachinmap(mob->warpslave_sub, bl->m, BL_MOB, bl, range);
}
/*==========================================
- * Counts slave sub, curently checking if mob master is the given ID.
+ * Counts slave sub, currently checking if mob master is the given ID.
*------------------------------------------*/
int mob_countslave_sub(struct block_list *bl,va_list ap)
{
@@ -2845,9 +2849,8 @@ int mob_countslave_sub(struct block_list *bl,va_list ap)
/*==========================================
* Counts the number of slaves a mob has on the map.
*------------------------------------------*/
-int mob_countslave(struct block_list *bl)
-{
- return iMap->foreachinmap(mob_countslave_sub, bl->m, BL_MOB,bl->id);
+int mob_countslave(struct block_list *bl) {
+ return map->foreachinmap(mob->countslave_sub, bl->m, BL_MOB,bl->id);
}
/*==========================================
@@ -2870,14 +2873,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;
@@ -2891,10 +2894,10 @@ 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)) {
+ if (map->search_freecell(&md2->bl, 0, &x, &y, MOB_SLAVEDISTANCE, MOB_SLAVEDISTANCE, 0)) {
data.x = x;
data.y = y;
} else {
@@ -2908,15 +2911,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;
@@ -2927,17 +2930,17 @@ int mob_summonslave(struct mob_data *md2,int *value,int amount,uint16 skill_id)
switch (battle_config.slaves_inherit_mode) {
case 1: //Always aggressive
if (!(md->status.mode&MD_AGGRESSIVE))
- sc_start4(&md->bl, SC_MODECHANGE, 100,1,0, MD_AGGRESSIVE, 0, 0);
+ sc_start4(NULL, &md->bl, SC_MODECHANGE, 100,1,0, MD_AGGRESSIVE, 0, 0);
break;
case 2: //Always passive
if (md->status.mode&MD_AGGRESSIVE)
- sc_start4(&md->bl, SC_MODECHANGE, 100,1,0, 0, MD_AGGRESSIVE, 0);
+ sc_start4(NULL, &md->bl, SC_MODECHANGE, 100,1,0, 0, MD_AGGRESSIVE, 0);
break;
default: //Copy master.
if (md2->status.mode&MD_AGGRESSIVE)
- sc_start4(&md->bl, SC_MODECHANGE, 100,1,0, MD_AGGRESSIVE, 0, 0);
+ sc_start4(NULL, &md->bl, SC_MODECHANGE, 100,1,0, MD_AGGRESSIVE, 0, 0);
else
- sc_start4(&md->bl, SC_MODECHANGE, 100,1,0, 0, MD_AGGRESSIVE, 0);
+ sc_start4(NULL, &md->bl, SC_MODECHANGE, 100,1,0, 0, MD_AGGRESSIVE, 0);
break;
}
}
@@ -2954,8 +2957,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;
@@ -2993,8 +2996,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;
@@ -3003,17 +3005,15 @@ 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);
+ map->foreachinrange(mob->getfriendhprate_sub, &md->bl, 8, type,md,min_rate,max_rate,&fr);
return fr;
}
/*==========================================
* Check hp rate of its master
*------------------------------------------*/
-struct block_list *mob_getmasterhpltmaxrate(struct mob_data *md,int rate)
-{
- if( md && md->master_id > 0 )
- {
- struct block_list *bl = iMap->id2bl(md->master_id);
+struct block_list *mob_getmasterhpltmaxrate(struct mob_data *md,int rate) {
+ if( md && md->master_id > 0 ) {
+ struct block_list *bl = map->id2bl(md->master_id);
if( bl && get_percentage(status_get_hp(bl), status_get_max_hp(bl)) < rate )
return bl;
}
@@ -3055,25 +3055,24 @@ int mob_getfriendstatus_sub(struct block_list *bl,va_list ap)
return 0;
}
-struct mob_data *mob_getfriendstatus(struct mob_data *md,int cond1,int cond2)
-{
+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);
+ map->foreachinrange(mob->getfriendstatus_sub, &md->bl, 8,BL_MOB, md,cond1,cond2,&fr);
return fr;
}
/*==========================================
* Skill use judging
*------------------------------------------*/
-int mobskill_use(struct mob_data *md, unsigned int tick, int event)
-{
+int mobskill_use(struct mob_data *md, int64 tick, int event) {
struct mob_skill *ms;
struct block_list *fbl = NULL; //Friend bl, which can either be a BL_PC or BL_MOB depending on the situation. [Skotlex]
struct block_list *bl;
struct mob_data *fmd = NULL;
int i,j,n;
+ short skill_target;
nullpo_ret(md);
nullpo_ret(ms = md->db->skill);
@@ -3139,20 +3138,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:
@@ -3160,9 +3159,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=map->id2bl(md->master_id)) && unit->counttargeted(fbl) > 0); break;
case MSC_ALCHEMIST:
flag = (md->state.alchemist);
break;
@@ -3172,10 +3171,12 @@ int mobskill_use(struct mob_data *md, unsigned int tick, int event)
if (!flag)
continue; //Skill requisite failed to be fulfilled.
+
//Execute skill
+ skill_target = (md->db->status.mode&MD_RANDOMTARGET)? MST_RANDOM : ms[i].target;
if (skill->get_casttype(ms[i].skill_id) == CAST_GROUND) {//Ground skill.
short x, y;
- switch (ms[i].target) {
+ switch (skill_target) {
case MST_RANDOM: //Pick a random enemy within skill range.
bl = battle->get_enemy(&md->bl, DEFAULT_ENEMY_TYPE(md),
skill->get_range2(&md->bl, ms[i].skill_id, ms[i].skill_lv));
@@ -3185,12 +3186,12 @@ int mobskill_use(struct mob_data *md, unsigned int tick, int event)
case MST_AROUND6:
case MST_AROUND7:
case MST_AROUND8:
- bl = iMap->id2bl(md->target_id);
+ bl = map->id2bl(md->target_id);
break;
case MST_MASTER:
bl = &md->bl;
if (md->master_id)
- bl = iMap->id2bl(md->master_id);
+ bl = map->id2bl(md->master_id);
if (bl) //Otherwise, fall through.
break;
case MST_FRIEND:
@@ -3205,34 +3206,34 @@ int mobskill_use(struct mob_data *md, unsigned int tick, int event)
x = bl->x;
y = bl->y;
// Look for an area to cast the spell around...
- if (ms[i].target >= MST_AROUND1 || ms[i].target >= MST_AROUND5) {
- j = ms[i].target >= MST_AROUND1?
- (ms[i].target-MST_AROUND1) +1:
- (ms[i].target-MST_AROUND5) +1;
- iMap->search_freecell(&md->bl, md->bl.m, &x, &y, j, j, 3);
+ if (skill_target >= MST_AROUND1 || skill_target >= MST_AROUND5) {
+ j = skill_target >= MST_AROUND1?
+ (skill_target-MST_AROUND1) +1:
+ (skill_target-MST_AROUND5) +1;
+ map->search_freecell(&md->bl, md->bl.m, &x, &y, j, j, 3);
}
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) )
- {
- iMap->freeblock_unlock();
+ map->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)
+ ) {
+ map->freeblock_unlock();
continue;
}
} else {
- //Targetted skill
- switch (ms[i].target) {
+ //Targeted skill
+ switch (skill_target) {
case MST_RANDOM: //Pick a random enemy within skill range.
bl = battle->get_enemy(&md->bl, DEFAULT_ENEMY_TYPE(md),
skill->get_range2(&md->bl, ms[i].skill_id, ms[i].skill_lv));
break;
case MST_TARGET:
- bl = iMap->id2bl(md->target_id);
+ bl = map->id2bl(md->target_id);
break;
case MST_MASTER:
bl = &md->bl;
if (md->master_id)
- bl = iMap->id2bl(md->master_id);
+ bl = map->id2bl(md->master_id);
if (bl) //Otherwise, fall through.
break;
case MST_FRIEND:
@@ -3250,17 +3251,17 @@ int mobskill_use(struct mob_data *md, unsigned int tick, int event)
if (!bl) continue;
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) )
- {
- iMap->freeblock_unlock();
+ map->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)
+ ) {
+ map->freeblock_unlock();
continue;
}
}
//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);
@@ -3274,7 +3275,7 @@ int mobskill_use(struct mob_data *md, unsigned int tick, int event)
md->skilldelay[j]=tick;
} else
md->skilldelay[i]=tick;
- iMap->freeblock_unlock();
+ map->freeblock_unlock();
return 1;
}
//No skill was used.
@@ -3284,8 +3285,7 @@ int mobskill_use(struct mob_data *md, unsigned int tick, int event)
/*==========================================
* Skill use event processing
*------------------------------------------*/
-int mobskill_event(struct mob_data *md, struct block_list *src, unsigned int tick, int flag)
-{
+int mobskill_event(struct mob_data *md, struct block_list *src, int64 tick, int flag) {
int target_id, res = 0;
if(md->bl.prev == NULL || md->status.hp <= 0)
@@ -3296,13 +3296,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]
@@ -3319,53 +3319,52 @@ 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_;
}
//Flag values:
-//&1: Set special ai (fight mobs, not players)
+//&1: Set special AI (fight mobs, not players)
//If mode is not passed, a default aggressive mode is used.
//If master_id is passed, clone is attached to him.
//Returns: ID of newly crafted copy.
-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_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 class_;
int i,j,h,inf,skill_id, fd;
struct mob_data *md;
struct mob_skill *ms;
struct mob_db* db;
- struct status_data *status;
+ struct status_data *mstatus;
nullpo_ret(sd);
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));
- status = &db->status;
+ db = mob->db_data[class_]=(struct mob_db*)aCalloc(1, sizeof(struct mob_db));
+ mstatus = &db->status;
strcpy(db->sprite,sd->status.name);
strcpy(db->name,sd->status.name);
strcpy(db->jname,sd->status.name);
- db->lv=status_get_lv(&sd->bl);
- memcpy(status, &sd->base_status, sizeof(struct status_data));
- status->rhw.atk2= status->dex + status->rhw.atk + status->rhw.atk2; //Max ATK
- status->rhw.atk = status->dex; //Min ATK
- if (status->lhw.atk) {
- status->lhw.atk2= status->dex + status->lhw.atk + status->lhw.atk2; //Max ATK
- status->lhw.atk = status->dex; //Min ATK
+ db->lv=status->get_lv(&sd->bl);
+ memcpy(mstatus, &sd->base_status, sizeof(struct status_data));
+ mstatus->rhw.atk2= mstatus->dex + mstatus->rhw.atk + mstatus->rhw.atk2; //Max ATK
+ mstatus->rhw.atk = mstatus->dex; //Min ATK
+ if (mstatus->lhw.atk) {
+ mstatus->lhw.atk2= mstatus->dex + mstatus->lhw.atk + mstatus->lhw.atk2; //Max ATK
+ mstatus->lhw.atk = mstatus->dex; //Min ATK
}
if (mode) //User provided mode.
- status->mode = mode;
+ mstatus->mode = mode;
else if (flag&1) //Friendly Character, remove looting.
- status->mode &= ~MD_LOOTER;
- status->hp = status->max_hp;
- status->sp = status->max_sp;
+ mstatus->mode &= ~MD_LOOTER;
+ mstatus->hp = mstatus->max_hp;
+ mstatus->sp = mstatus->max_sp;
memcpy(&db->vd, &sd->vd, sizeof(struct view_data));
db->base_exp=1;
db->job_exp=1;
@@ -3384,18 +3383,18 @@ int mob_clone_spawn(struct map_session_data *sd, int16 m, int16 x, int16 y, cons
//Go Backwards to give better priority to advanced skills.
for (i=0,j = MAX_SKILL_TREE-1;j>=0 && i< MAX_MOBSKILL ;j--) {
- int idx = skill_tree[pc->class2idx(sd->status.class_)][j].idx;
- skill_id = skill_tree[pc->class2idx(sd->status.class_)][j].id;
+ int idx = pc->skill_tree[pc->class2idx(sd->status.class_)][j].idx;
+ skill_id = pc->skill_tree[pc->class2idx(sd->status.class_)][j].id;
if (!skill_id || sd->status.skill[idx].lv < 1 ||
- (skill_db[idx].inf2&(INF2_WEDDING_SKILL|INF2_GUILD_SKILL))
+ (skill->db[idx].inf2&(INF2_WEDDING_SKILL|INF2_GUILD_SKILL))
)
continue;
- for(h = 0; h < map[sd->bl.m].zone->disabled_skills_count; h++) {
- if( skill_id == map[sd->bl.m].zone->disabled_skills[h]->nameid && map[sd->bl.m].zone->disabled_skills[h]->subtype == MZS_CLONE ) {
+ for(h = 0; h < map->list[sd->bl.m].zone->disabled_skills_count; h++) {
+ if( skill_id == map->list[sd->bl.m].zone->disabled_skills[h]->nameid && map->list[sd->bl.m].zone->disabled_skills[h]->subtype == MZS_CLONE ) {
break;
}
}
- if( h < map[sd->bl.m].zone->disabled_skills_count )
+ if( h < map->list[sd->bl.m].zone->disabled_skills_count )
continue;
//Normal aggressive mob, disable skills that cannot help them fight
//against players (those with flags UF_NOMOB and UF_NOPC are specific
@@ -3420,7 +3419,7 @@ int mob_clone_spawn(struct map_session_data *sd, int16 m, int16 x, int16 y, cons
ms[i].casttime = skill->cast_fix(&sd->bl,skill_id, ms[i].skill_lv);
ms[i].delay = 5000+skill->delay_fix(&sd->bl,skill_id, ms[i].skill_lv);
- inf = skill_db[idx].inf;
+ inf = skill->db[idx].inf;
if (inf&INF_ATTACK_SKILL) {
ms[i].target = MST_TARGET;
ms[i].cond1 = MSC_ALWAYS;
@@ -3509,7 +3508,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_MEDIUM, AI_NONE);
if (!md) return 0; //Failed?
md->special_state.clone = 1;
@@ -3522,12 +3521,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);
+ timer->delete(md->deletetimer, mob->timer_delete);
+ md->deletetimer = timer->add(timer->gettick() + duration, mob->timer_delete, md->bl.id, 0);
}
}
- mob_spawn(md);
+ mob->spawn(md);
return md->bl.id;
}
@@ -3536,11 +3535,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;
}
@@ -3553,50 +3552,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;
@@ -3612,13 +3611,13 @@ static unsigned int mob_drop_adjust(int baserate, int rate_adjust, unsigned shor
}
/**
- * Check if global item drop rate is overriden for given item
+ * Check if global item drop rate is overridden for given item
* in db/mob_item_ratio.txt
* @param nameid ID of the item
* @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
@@ -3631,14 +3630,23 @@ static void item_dropratio_adjust(int nameid, int mob_id, int *rate_adjust)
*rate_adjust = item_drop_ratio_db[nameid]->drop_ratio;
}
}
-
+/* (mob_parse_dbrow)_cap_value */
+static inline int mob_parse_dbrow_cap_value(int class_, int min, int max, int value) {
+ if( value > max ) {
+ ShowError("mob_parse_dbrow: for class '%d', field value '%d' is higher than the maximum '%d'! capping...\n", class_, value, max);
+ return max;
+ } else if ( value < min ) {
+ ShowError("mob_parse_dbrow: for class '%d', field value '%d' is lower than the minimum '%d'! capping...\n", class_, value, min);
+ return min;
+ }
+ return value;
+}
/*==========================================
* 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;
+ struct status_data *mstatus;
int class_, i, k;
double exp, maxhp;
struct mob_data data;
@@ -3662,7 +3670,7 @@ static bool mob_parse_dbrow(char** str)
memset(&entry, 0, sizeof(entry));
db = &entry;
- status = &db->status;
+ mstatus = &db->status;
db->vd.class_ = class_;
safestrncpy(db->sprite, str[1], sizeof(db->sprite));
@@ -3670,8 +3678,8 @@ static bool mob_parse_dbrow(char** str)
safestrncpy(db->name, str[3], sizeof(db->name));
db->lv = atoi(str[4]);
db->lv = cap_value(db->lv, 1, USHRT_MAX);
- status->max_hp = atoi(str[5]);
- status->max_sp = atoi(str[6]);
+ mstatus->max_hp = atoi(str[5]);
+ mstatus->max_sp = atoi(str[6]);
exp = (double)atoi(str[7]) * (double)battle_config.base_exp_rate / 100.;
db->base_exp = (unsigned int)cap_value(exp, 0, UINT_MAX);
@@ -3679,24 +3687,28 @@ static bool mob_parse_dbrow(char** str)
exp = (double)atoi(str[8]) * (double)battle_config.job_exp_rate / 100.;
db->job_exp = (unsigned int)cap_value(exp, 0, UINT_MAX);
- status->rhw.range = atoi(str[9]);
- status->rhw.atk = atoi(str[10]);
- status->rhw.atk2 = atoi(str[11]);
- status->def = atoi(str[12]);
- status->mdef = atoi(str[13]);
- status->str = atoi(str[14]);
- status->agi = atoi(str[15]);
- status->vit = atoi(str[16]);
- status->int_ = atoi(str[17]);
- status->dex = atoi(str[18]);
- status->luk = atoi(str[19]);
+ mstatus->rhw.range = atoi(str[9]);
+
+ mstatus->rhw.atk = mob_parse_dbrow_cap_value(class_,UINT16_MIN,UINT16_MAX,atoi(str[10]));
+ mstatus->rhw.atk2 = mob_parse_dbrow_cap_value(class_,UINT16_MIN,UINT16_MAX,atoi(str[11]));
+
+ mstatus->def = mob_parse_dbrow_cap_value(class_,DEFTYPE_MIN,DEFTYPE_MAX,atoi(str[12]));
+ mstatus->mdef = mob_parse_dbrow_cap_value(class_,DEFTYPE_MIN,DEFTYPE_MAX,atoi(str[13]));
+
+ mstatus->str = mob_parse_dbrow_cap_value(class_,UINT16_MIN,UINT16_MAX,atoi(str[14]));
+ mstatus->agi = mob_parse_dbrow_cap_value(class_,UINT16_MIN,UINT16_MAX,atoi(str[15]));
+ mstatus->vit = mob_parse_dbrow_cap_value(class_,UINT16_MIN,UINT16_MAX,atoi(str[16]));
+ mstatus->int_ = mob_parse_dbrow_cap_value(class_,UINT16_MIN,UINT16_MAX,atoi(str[17]));
+ mstatus->dex = mob_parse_dbrow_cap_value(class_,UINT16_MIN,UINT16_MAX,atoi(str[18]));
+ mstatus->luk = mob_parse_dbrow_cap_value(class_,UINT16_MIN,UINT16_MAX,atoi(str[19]));
+
//All status should be min 1 to prevent divisions by zero from some skills. [Skotlex]
- if (status->str < 1) status->str = 1;
- if (status->agi < 1) status->agi = 1;
- if (status->vit < 1) status->vit = 1;
- if (status->int_< 1) status->int_= 1;
- if (status->dex < 1) status->dex = 1;
- if (status->luk < 1) status->luk = 1;
+ if (mstatus->str < 1) mstatus->str = 1;
+ if (mstatus->agi < 1) mstatus->agi = 1;
+ if (mstatus->vit < 1) mstatus->vit = 1;
+ if (mstatus->int_< 1) mstatus->int_= 1;
+ if (mstatus->dex < 1) mstatus->dex = 1;
+ if (mstatus->luk < 1) mstatus->luk = 1;
db->range2 = atoi(str[20]);
db->range3 = atoi(str[21]);
@@ -3711,52 +3723,52 @@ static bool mob_parse_dbrow(char** str)
db->range3 = db->range2;
}
- status->size = atoi(str[22]);
- status->race = atoi(str[23]);
+ mstatus->size = atoi(str[22]);
+ mstatus->race = atoi(str[23]);
i = atoi(str[24]); //Element
- status->def_ele = i%10;
- status->ele_lv = i/20;
- if (status->def_ele >= ELE_MAX) {
- ShowError("mob_parse_dbrow: Invalid element type %d for monster ID %d (max=%d).\n", status->def_ele, class_, ELE_MAX-1);
+ mstatus->def_ele = i%10;
+ mstatus->ele_lv = i/20;
+ if (mstatus->def_ele >= ELE_MAX) {
+ ShowError("mob_parse_dbrow: Invalid element type %d for monster ID %d (max=%d).\n", mstatus->def_ele, class_, ELE_MAX-1);
return false;
}
- if (status->ele_lv < 1 || status->ele_lv > 4) {
- ShowError("mob_parse_dbrow: Invalid element level %d for monster ID %d, must be in range 1-4.\n", status->ele_lv, class_);
+ if (mstatus->ele_lv < 1 || mstatus->ele_lv > 4) {
+ ShowError("mob_parse_dbrow: Invalid element level %d for monster ID %d, must be in range 1-4.\n", mstatus->ele_lv, class_);
return false;
}
- status->mode = (int)strtol(str[25], NULL, 0);
+ mstatus->mode = (int)strtol(str[25], NULL, 0);
if (!battle_config.monster_active_enable)
- status->mode &= ~MD_AGGRESSIVE;
+ mstatus->mode &= ~MD_AGGRESSIVE;
- status->speed = atoi(str[26]);
- status->aspd_rate = 1000;
+ mstatus->speed = atoi(str[26]);
+ mstatus->aspd_rate = 1000;
i = atoi(str[27]);
- status->adelay = cap_value(i, battle_config.monster_max_aspd*2, 4000);
+ mstatus->adelay = cap_value(i, battle_config.monster_max_aspd*2, 4000);
i = atoi(str[28]);
- status->amotion = cap_value(i, battle_config.monster_max_aspd, 2000);
+ mstatus->amotion = cap_value(i, battle_config.monster_max_aspd, 2000);
//If the attack animation is longer than the delay, the client crops the attack animation!
//On aegis there is no real visible effect of having a recharge-time less than amotion anyway.
- if (status->adelay < status->amotion)
- status->adelay = status->amotion;
- status->dmotion = atoi(str[29]);
+ if (mstatus->adelay < mstatus->amotion)
+ mstatus->adelay = mstatus->amotion;
+ mstatus->dmotion = atoi(str[29]);
if(battle_config.monster_damage_delay_rate != 100)
- status->dmotion = status->dmotion * battle_config.monster_damage_delay_rate / 100;
+ mstatus->dmotion = mstatus->dmotion * battle_config.monster_damage_delay_rate / 100;
// Fill in remaining status data by using a dummy monster.
data.bl.type = BL_MOB;
data.level = db->lv;
- memcpy(&data.status, status, sizeof(struct status_data));
- status_calc_misc(&data.bl, status, db->lv);
+ memcpy(&data.status, mstatus, sizeof(struct status_data));
+ status->calc_misc(&data.bl, mstatus, db->lv);
// MVP EXP Bonus: MEXP
- // Some new MVP's MEXP multipled by high exp-rate cause overflow. [LuzZza]
+ // Some new MVP's MEXP multiple by high exp-rate cause overflow. [LuzZza]
exp = (double)atoi(str[30]) * (double)battle_config.mvp_exp_rate / 100.;
db->mexp = (unsigned int)cap_value(exp, 0, UINT_MAX);
//Now that we know if it is an mvp or not, apply battle_config modifiers [Skotlex]
- maxhp = (double)status->max_hp;
+ maxhp = (double)mstatus->max_hp;
if (db->mexp > 0) { //Mvp
if (battle_config.mvp_hp_rate != 100)
maxhp = maxhp * (double)battle_config.mvp_hp_rate / 100.;
@@ -3764,12 +3776,12 @@ static bool mob_parse_dbrow(char** str)
if (battle_config.monster_hp_rate != 100)
maxhp = maxhp * (double)battle_config.monster_hp_rate / 100.;
- status->max_hp = (unsigned int)cap_value(maxhp, 1, UINT_MAX);
- if(status->max_sp < 1) status->max_sp = 1;
+ mstatus->max_hp = (unsigned int)cap_value(maxhp, 1, UINT_MAX);
+ if(mstatus->max_sp < 1) mstatus->max_sp = 1;
//Since mobs always respawn with full life...
- status->hp = status->max_hp;
- status->sp = status->max_sp;
+ mstatus->hp = mstatus->max_hp;
+ mstatus->sp = mstatus->max_sp;
// MVP Drops: MVP1id,MVP1per,MVP2id,MVP2per,MVP3id,MVP3per
for(i = 0; i < MAX_MVP_DROP; i++) {
@@ -3779,13 +3791,13 @@ 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) {
struct item_data *id;
- id = itemdb_search(db->mvpitem[i].nameid);
+ id = itemdb->search(db->mvpitem[i].nameid);
if (id->maxchance == -1 || (id->maxchance < db->mvpitem[i].p/10 + 1) ) {
//item has bigger drop chance or sold in shops
id->maxchance = db->mvpitem[i].p/10 + 1; //reduce MVP drop info to not spoil common drop rate
@@ -3803,7 +3815,7 @@ static bool mob_parse_dbrow(char** str)
db->dropitem[i].p = 0; //No drop.
continue;
}
- id = itemdb_search(db->dropitem[i].nameid);
+ id = itemdb->search(db->dropitem[i].nameid);
type = id->type;
rate = atoi(str[k+1]);
if( (class_ >= 1324 && class_ <= 1363) || (class_ >= 1938 && class_ <= 1946) )
@@ -3813,38 +3825,38 @@ static bool mob_parse_dbrow(char** str)
ratemax = battle_config.item_drop_treasure_max;
}
else switch (type)
- { // Added suport to restrict normal drops of MVP's [Reddozen]
+ { // Added support to restrict normal drops of MVP's [Reddozen]
case IT_HEALING:
- rate_adjust = (status->mode&MD_BOSS) ? battle_config.item_rate_heal_boss : battle_config.item_rate_heal;
+ rate_adjust = (mstatus->mode&MD_BOSS) ? battle_config.item_rate_heal_boss : battle_config.item_rate_heal;
ratemin = battle_config.item_drop_heal_min;
ratemax = battle_config.item_drop_heal_max;
break;
case IT_USABLE:
case IT_CASH:
- rate_adjust = (status->mode&MD_BOSS) ? battle_config.item_rate_use_boss : battle_config.item_rate_use;
+ rate_adjust = (mstatus->mode&MD_BOSS) ? battle_config.item_rate_use_boss : battle_config.item_rate_use;
ratemin = battle_config.item_drop_use_min;
ratemax = battle_config.item_drop_use_max;
break;
case IT_WEAPON:
case IT_ARMOR:
case IT_PETARMOR:
- rate_adjust = (status->mode&MD_BOSS) ? battle_config.item_rate_equip_boss : battle_config.item_rate_equip;
+ rate_adjust = (mstatus->mode&MD_BOSS) ? battle_config.item_rate_equip_boss : battle_config.item_rate_equip;
ratemin = battle_config.item_drop_equip_min;
ratemax = battle_config.item_drop_equip_max;
break;
case IT_CARD:
- rate_adjust = (status->mode&MD_BOSS) ? battle_config.item_rate_card_boss : battle_config.item_rate_card;
+ rate_adjust = (mstatus->mode&MD_BOSS) ? battle_config.item_rate_card_boss : battle_config.item_rate_card;
ratemin = battle_config.item_drop_card_min;
ratemax = battle_config.item_drop_card_max;
break;
default:
- rate_adjust = (status->mode&MD_BOSS) ? battle_config.item_rate_common_boss : battle_config.item_rate_common;
+ rate_adjust = (mstatus->mode&MD_BOSS) ? battle_config.item_rate_common_boss : battle_config.item_rate_common;
ratemin = battle_config.item_drop_common_min;
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) )
@@ -3865,68 +3877,62 @@ static bool mob_parse_dbrow(char** str)
id->mob[k].id = class_;
}
}
-
// Finally insert monster's data into the database.
- if (mob_db_data[class_] == NULL)
- mob_db_data[class_] = (struct mob_db*)aCalloc(1, 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)
-{
- return mob_parse_dbrow(fields);
+bool mob_readdb_sub(char* fields[], int columns, int current) {
+ return mob->parse_dbrow(fields);
}
-static void mob_readdb(void)
-{
+void mob_readdb(void) {
const char* filename[] = {
DBPATH"mob_db.txt",
"mob_db2.txt" };
int fi;
- for( fi = 0; fi < ARRAYLENGTH(filename); ++fi )
- {
- if(fi > 0)
- {
- char path[256];
- sprintf(path, "%s/%s", iMap->db_path, filename[fi]);
- if(!exists(path))
- {
+ for( fi = 0; fi < ARRAYLENGTH(filename); ++fi ) {
+ if(fi > 0) {
+ char filepath[256];
+ sprintf(filepath, "%s/%s", map->db_path, filename[fi]);
+ if(!exists(filepath)) {
continue;
}
}
- 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(map->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->name_constants();
}
/*==========================================
* mob_db table reading
*------------------------------------------*/
-static int mob_read_sqldb(void)
-{
- const char* mob_db_name[] = { iMap->mob_db_db, iMap->mob_db2_db };
+int mob_read_sqldb(void) {
+ const char* mob_db_name[] = { map->mob_db_db, map->mob_db2_db };
int fi;
for( fi = 0; fi < ARRAYLENGTH(mob_db_name); ++fi ) {
uint32 lines = 0, count = 0;
// retrieve all rows from the mob database
- if( SQL_ERROR == SQL->Query(mmysql_handle, "SELECT * FROM `%s`", mob_db_name[fi]) ) {
- Sql_ShowDebug(mmysql_handle);
+ if( SQL_ERROR == SQL->Query(map->mysql_handle, "SELECT * FROM `%s`", mob_db_name[fi]) ) {
+ Sql_ShowDebug(map->mysql_handle);
continue;
}
// process rows one by one
- while( SQL_SUCCESS == SQL->NextRow(mmysql_handle) ) {
+ while( SQL_SUCCESS == SQL->NextRow(map->mysql_handle) ) {
// wrap the result into a TXT-compatible format
char line[1024];
char* str[31+2*MAX_MVP_DROP+2*MAX_MOB_DROP];
@@ -3938,37 +3944,52 @@ static int mob_read_sqldb(void)
{
char* data;
size_t len;
- SQL->GetData(mmysql_handle, i, &data, &len);
+ SQL->GetData(map->mysql_handle, i, &data, &len);
strcpy(p, data);
str[i] = p;
p+= len + 1;
}
- if (!mob_parse_dbrow(str))
+ if (!mob->parse_dbrow(str))
continue;
count++;
}
// free the query result
- SQL->FreeResult(mmysql_handle);
+ SQL->FreeResult(map->mysql_handle);
- ShowStatus("Done reading '"CL_WHITE"%lu"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", count, mob_db_name[fi]);
+ ShowStatus("Done reading '"CL_WHITE"%"PRIu32""CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", count, mob_db_name[fi]);
}
+ mob->name_constants();
return 0;
}
+void mob_name_constants(void) {
+ int i;
+#ifdef ENABLE_CASE_CHECK
+ script->parser_current_file = "Mob Database (Likely an invalid or conflicting SpriteName)";
+#endif // ENABLE_CASE_CHECK
+ for (i = 0; i < MAX_MOB_DB; i++) {
+ if (mob->db_data[i] && !mob->is_clone(i))
+ script->set_constant2(mob->db_data[i]->sprite, i, 0);
+ }
+#ifdef ENABLE_CASE_CHECK
+ script->parser_current_file = NULL;
+#endif // ENABLE_CASE_CHECK
+}
+
/*==========================================
* 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;
@@ -3976,24 +3997,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;
@@ -4003,7 +4024,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];
@@ -4020,8 +4041,8 @@ 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
- sprintf(line, "%s/%s", iMap->db_path, mobfile[i]);
+ mob->db_data[0]->summonper[i] = 1002; // Default fallback value, in case the database does not provide one
+ sprintf(line, "%s/%s", map->db_path, mobfile[i]);
fp=fopen(line,"r");
if(fp==NULL){
ShowError("can't read %s\n",line);
@@ -4043,10 +4064,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_;
@@ -4057,11 +4078,11 @@ 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);
- ShowStatus("Done reading '"CL_WHITE"%lu"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n",count,mobfile[i]);
+ ShowStatus("Done reading '"CL_WHITE"%u"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n",count,mobfile[i]);
}
return 0;
}
@@ -4070,7 +4091,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;
@@ -4088,14 +4109,14 @@ 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
- ms->color=strtoul(str[1],NULL,0);
+ ms->color=(unsigned int)strtoul(str[1],NULL,0);
//Message
msg = str[2];
len = strlen(msg);
@@ -4128,23 +4149,20 @@ 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;
- char line[1024], path[256];
+ char line[1024], filepath[256];
int i, tmp=0;
FILE *fp;
- sprintf(path, "%s/%s", iMap->db_path, arc);
- fp=fopen(path, "r");
- if(fp == NULL)
- {
- ShowWarning("mob_readchatdb: File not found \"%s\", skipping.\n", path);
+ sprintf(filepath, "%s/%s", map->db_path, arc);
+ fp=fopen(filepath, "r");
+ if(fp == NULL) {
+ ShowWarning("mob_readchatdb: File not found \"%s\", skipping.\n", filepath);
return;
}
- while(fgets(line, sizeof(line), fp))
- {
+ while(fgets(line, sizeof(line), fp)) {
char *str[3], *p, *np;
int j=0;
@@ -4172,19 +4190,19 @@ static void mob_readchatdb(void)
continue;
}
- if( !mob_parse_row_chatdb(str, path, lines, &tmp) )
+ if( !mob->parse_row_chatdb(str, filepath, lines, &tmp) )
continue;
count++;
}
fclose(fp);
- ShowStatus("Done reading '"CL_WHITE"%lu"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", count, arc);
+ ShowStatus("Done reading '"CL_WHITE"%"PRIu32""CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", count, arc);
}
/*==========================================
* 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];
@@ -4266,7 +4284,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);
@@ -4277,8 +4295,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;
}
@@ -4287,11 +4305,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;
@@ -4313,7 +4331,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;
@@ -4354,14 +4372,14 @@ static bool mob_parse_row_mobskilldb(char** str, int columns, int current)
if ( skill->get_casttype2(sidx) == CAST_GROUND) {//Ground skill.
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);
+ ms->skill_id, skill->db[sidx].name,
+ 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);
+ ms->skill_id, skill->db[sidx].name,
+ mob_id < 0?"all mobs":mob->db_data[mob_id]->sprite);
ms->target = MST_TARGET;
}
@@ -4389,7 +4407,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.
@@ -4408,7 +4426,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;
@@ -4418,9 +4436,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;
@@ -4428,15 +4446,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;
}
@@ -4444,31 +4462,27 @@ 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" };
int fi;
- if( battle_config.mob_skill_rate == 0 )
- {
+ if( battle_config.mob_skill_rate == 0 ) {
ShowStatus("Mob skill use disabled. Not reading mob skills.\n");
return;
}
- for( fi = 0; fi < ARRAYLENGTH(filename); ++fi )
- {
- if(fi > 0)
- {
- char path[256];
- sprintf(path, "%s/%s", iMap->db_path, filename[fi]);
- if(!exists(path))
- {
+ for( fi = 0; fi < ARRAYLENGTH(filename); ++fi ) {
+ if(fi > 0) {
+ char filepath[256];
+ sprintf(filepath, "%s/%s", map->db_path, filename[fi]);
+ if(!exists(filepath)) {
continue;
}
}
- sv->readdb(iMap->db_path, filename[fi], ',', 19, 19, -1, &mob_parse_row_mobskilldb);
+ sv->readdb(map->db_path, filename[fi], ',', 19, 19, -1, mob->parse_row_mobskilldb);
}
}
@@ -4477,9 +4491,8 @@ static void mob_readskilldb(void) {
* not overly sure if this is all correct
* seems to work though...
*/
-static int mob_read_sqlskilldb(void)
-{
- const char* mob_skill_db_name[] = { iMap->mob_skill_db_db, iMap->mob_skill_db2_db };
+int mob_read_sqlskilldb(void) {
+ const char* mob_skill_db_name[] = { map->mob_skill_db_db, map->mob_skill_db2_db };
int fi;
if( battle_config.mob_skill_rate == 0 ) {
@@ -4492,13 +4505,13 @@ static int mob_read_sqlskilldb(void)
uint32 lines = 0, count = 0;
// retrieve all rows from the mob skill database
- if( SQL_ERROR == SQL->Query(mmysql_handle, "SELECT * FROM `%s`", mob_skill_db_name[fi]) ) {
- Sql_ShowDebug(mmysql_handle);
+ if( SQL_ERROR == SQL->Query(map->mysql_handle, "SELECT * FROM `%s`", mob_skill_db_name[fi]) ) {
+ Sql_ShowDebug(map->mysql_handle);
continue;
}
// process rows one by one
- while( SQL_SUCCESS == SQL->NextRow(mmysql_handle) ) {
+ while( SQL_SUCCESS == SQL->NextRow(map->mysql_handle) ) {
// wrap the result into a TXT-compatible format
char* str[19];
char* dummy = "";
@@ -4506,20 +4519,20 @@ static int mob_read_sqlskilldb(void)
++lines;
for( i = 0; i < 19; ++i )
{
- SQL->GetData(mmysql_handle, i, &str[i], NULL);
+ SQL->GetData(map->mysql_handle, i, &str[i], NULL);
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++;
}
// free the query result
- SQL->FreeResult(mmysql_handle);
+ SQL->FreeResult(map->mysql_handle);
- ShowStatus("Done reading '"CL_WHITE"%lu"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", count, mob_skill_db_name[fi]);
+ ShowStatus("Done reading '"CL_WHITE"%"PRIu32""CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", count, mob_skill_db_name[fi]);
}
return 0;
}
@@ -4527,7 +4540,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;
@@ -4542,12 +4555,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;
}
@@ -4555,12 +4568,12 @@ 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]);
- if( itemdb_exists(nameid) == NULL )
+ if( itemdb->exists(nameid) == NULL )
{
ShowWarning("itemdb_read_itemratio: Invalid item id %d.\n", nameid);
return false;
@@ -4581,33 +4594,36 @@ 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();
- if (iMap->db_use_sqldbs)
- {
- mob_read_sqldb();
- mob_read_sqlskilldb();
+void mob_load(bool minimal) {
+ if (minimal) {
+ // Only read the mob db in minimal mode
+ mob->readdb();
+ return;
}
- else
- {
- mob_readdb();
- mob_readskilldb();
+ sv->readdb(map->db_path, "mob_item_ratio.txt", ',', 2, 2+MAX_ITEMRATIO_MOBS, -1, mob->readdb_itemratio); // must be read before mobdb
+ mob->readchatdb();
+ if (map->db_use_sql_mob_db) {
+ mob->read_sqldb();
}
- 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);
+ if (map->db_use_sql_mob_skill_db) {
+ mob->read_sqlskilldb();
+ } else {
+ mob->readdb();
+ mob->readskilldb();
+ }
+ sv->readdb(map->db_path, "mob_avail.txt", ',', 2, 12, -1, mob->readdb_mobavail);
+ mob->read_randommonster();
+ sv->readdb(map->db_path, DBPATH"mob_race2_db.txt", ',', 2, 20, -1, mob->readdb_race2);
}
void mob_reload(void) {
int i;
-
+
//Mob skills need to be cleared before re-reading them. [Skotlex]
for (i = 0; i < MAX_MOB_DB; i++)
- if (mob_db_data[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
@@ -4618,39 +4634,42 @@ void mob_reload(void) {
}
}
- mob_load();
+ mob->load(false);
}
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));
}
/*==========================================
* Circumference initialization of mob
*------------------------------------------*/
-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
- item_drop_ers = ers_new(sizeof(struct item_drop),"mob.c::item_drop_ers",ERS_OPT_NONE);
+int do_init_mob(bool minimal) {
+ // 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
+ item_drop_ers = ers_new(sizeof(struct item_drop),"mob.c::item_drop_ers",ERS_OPT_CLEAN);
item_drop_list_ers = ers_new(sizeof(struct item_drop_list),"mob.c::item_drop_list_ers",ERS_OPT_NONE);
- mob_load();
+ mob->load(minimal);
- 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);
+ if (minimal)
+ return 0;
+
+ timer->add_func_list(mob->delayspawn,"mob_delayspawn");
+ timer->add_func_list(mob->delay_item_drop,"mob_delay_item_drop");
+ timer->add_func_list(mob->ai_hard,"mob_ai_hard");
+ timer->add_func_list(mob->ai_lazy,"mob_ai_lazy");
+ timer->add_func_list(mob->timer_delete,"mob_timer_delete");
+ timer->add_func_list(mob->spawn_guardian_sub,"mob_spawn_guardian_sub");
+ timer->add_func_list(mob->respawn,"mob_respawn");
+ timer->add_interval(timer->gettick()+MIN_MOBTHINKTIME,mob->ai_hard,0,0,MIN_MOBTHINKTIME);
+ timer->add_interval(timer->gettick()+MIN_MOBTHINKTIME*10,mob->ai_lazy,0,0,MIN_MOBTHINKTIME*10);
return 0;
}
@@ -4661,25 +4680,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++)
@@ -4694,3 +4713,116 @@ 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->name_constants = mob_name_constants;
+ 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;
+}