diff options
author | shennetsind <ind@henn.et> | 2013-09-16 06:11:40 -0300 |
---|---|---|
committer | shennetsind <ind@henn.et> | 2013-09-16 06:11:40 -0300 |
commit | 58cd45757fff179ca5b381bcb777d50a5dea302d (patch) | |
tree | 1a4f3d33479b4a00c0e9b657c9687624e1690c7d /src/map/mob.c | |
parent | f1a594db1b40a5a20ec5a4af093b27c58266cba0 (diff) | |
download | hercules-58cd45757fff179ca5b381bcb777d50a5dea302d.tar.gz hercules-58cd45757fff179ca5b381bcb777d50a5dea302d.tar.bz2 hercules-58cd45757fff179ca5b381bcb777d50a5dea302d.tar.xz hercules-58cd45757fff179ca5b381bcb777d50a5dea302d.zip |
HPM: Mob.c Interface
Fully Interfaced
Signed-off-by: shennetsind <ind@henn.et>
Diffstat (limited to 'src/map/mob.c')
-rw-r--r-- | src/map/mob.c | 791 |
1 files changed, 446 insertions, 345 deletions
diff --git a/src/map/mob.c b/src/map/mob.c index b16c57ef8..49120fdaf 100644 --- a/src/map/mob.c +++ b/src/map/mob.c @@ -43,6 +43,8 @@ #include <string.h> #include <math.h> +struct mob_interface mob_s; + #define ACTIVE_AI_RANGE 2 //Distance added on top of 'AREA_SIZE' at which mobs enter active AI mode. #define IDLE_SKILL_INTERVAL 10 //Active idle skills should be triggered every 1 second (1000/MIN_MOBTHINKTIME) @@ -54,17 +56,6 @@ #define MOB_MAX_DELAY (24*3600*1000) #define MAX_MINCHASE 30 //Max minimum chase value to use for mobs. #define RUDE_ATTACKED_COUNT 2 //After how many rude-attacks should the skill be used? -#define MAX_MOB_CHAT 250 //Max Skill's messages - -//Dynamic mob database, allows saving of memory when there's big gaps in the mob_db [Skotlex] -struct mob_db *mob_db_data[MAX_MOB_DB+1]; -struct mob_db *mob_dummy = NULL; //Dummy mob to be returned when a non-existant one is requested. - -struct mob_db *mob_db(int index) { if (index < 0 || index > MAX_MOB_DB || mob_db_data[index] == NULL) return mob_dummy; return mob_db_data[index]; } - -//Dynamic mob chat database -struct mob_chat *mob_chat_db[MAX_MOB_CHAT+1]; -struct mob_chat *mob_chat(short id) { if(id<=0 || id>MAX_MOB_CHAT || mob_chat_db[id]==NULL) return (struct mob_chat*)NULL; return mob_chat_db[id]; } //Dynamic item drop ratio database for per-item drop ratio modifiers overriding global drop ratios. #define MAX_ITEMRATIO_MOBS 10 @@ -82,16 +73,16 @@ static struct { int class_[350]; } summon[MAX_RANDOMMONSTER]; -//Defines the Manuk/Splendide mob groups for the status reductions [Epoque] -const int mob_manuk[8] = { 1986, 1987, 1988, 1989, 1990, 1997, 1998, 1999 }; -const int mob_splendide[5] = { 1991, 1992, 1993, 1994, 1995 }; - -/*========================================== - * Local prototype declaration (only required thing) - *------------------------------------------*/ -static int mob_makedummymobdb(int); -static int mob_spawn_guardian_sub(int tid, unsigned int tick, int id, intptr_t data); -int mob_skill_id2skill_idx(int class_,uint16 skill_id); +struct mob_db *mob_db(int index) { + if (index < 0 || index > MAX_MOB_DB || mob->db_data[index] == NULL) + return mob->dummy; + return mob->db_data[index]; +} +struct mob_chat *mob_chat(short id) { + if(id <= 0 || id > MAX_MOB_CHAT || mob->chat_db[id] == NULL) + return NULL; + return mob->chat_db[id]; +} /*========================================== * Mob is searched with a name. @@ -99,35 +90,34 @@ int mob_skill_id2skill_idx(int class_,uint16 skill_id); int mobdb_searchname(const char *str) { int i; - struct mob_db* mob; + struct mob_db* monster; for(i=0;i<=MAX_MOB_DB;i++){ - mob = mob_db(i); - if(mob == mob_dummy) //Skip dummy mobs. + monster = mob->db(i); + if(monster == mob->dummy) //Skip dummy mobs. continue; - if(strcmpi(mob->name,str)==0 || strcmpi(mob->jname,str)==0 || strcmpi(mob->sprite,str)==0) + if(strcmpi(monster->name,str)==0 || strcmpi(monster->jname,str)==0 || strcmpi(monster->sprite,str)==0) return i; } return 0; } -static int mobdb_searchname_array_sub(struct mob_db* mob, const char *str, int flag) -{ - if (mob == mob_dummy) +int mobdb_searchname_array_sub(struct mob_db* monster, const char *str, int flag) { + if (monster == mob->dummy) return 1; - if(!mob->base_exp && !mob->job_exp && mob->spawn[0].qty < 1) + if(!monster->base_exp && !monster->job_exp && monster->spawn[0].qty < 1) return 1; // Monsters with no base/job exp and no spawn point are, by this criteria, considered "slave mobs" and excluded from search results if( !flag ){ - if(stristr(mob->jname,str)) + if(stristr(monster->jname,str)) return 0; - if(stristr(mob->name,str)) + if(stristr(monster->name,str)) return 0; - return strcmpi(mob->jname,str); + return strcmpi(monster->jname,str); } - if(strcmp(mob->jname,str) == 0) + if(strcmp(monster->jname,str) == 0) return 0; - if(strcmp(mob->name,str) == 0) + if(strcmp(monster->name,str) == 0) return 0; - return strcmp(mob->sprite,str); + return strcmp(monster->sprite,str); } /*========================================== @@ -138,7 +128,7 @@ 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); @@ -204,14 +194,14 @@ void mvptomb_destroy(struct mob_data *md) { int mobdb_searchname_array(struct mob_db** data, int size, const char *str, int flag) { int count = 0, i; - struct mob_db* mob; + struct mob_db* monster; for(i=0;i<=MAX_MOB_DB;i++){ - mob = mob_db(i); - if (mob == mob_dummy || mob_is_clone(i) ) //keep clones out (or you leak player stats) + monster = mob->db(i); + if (monster == mob->dummy || mob->is_clone(i) ) //keep clones out (or you leak player stats) continue; - if (!mobdb_searchname_array_sub(mob, str, flag)) { + if (!mob->db_searchname_array_sub(monster, str, flag)) { if (count < size) - data[count] = mob; + data[count] = monster; count++; } } @@ -223,9 +213,9 @@ int mobdb_searchname_array(struct mob_db** data, int size, const char *str, int *------------------------------------------*/ int mobdb_checkid(const int id) { - if (mob_db(id) == mob_dummy) + if (mob->db(id) == mob->dummy) return 0; - if (mob_is_clone(id)) //checkid is used mostly for random ID based code, therefore clone mobs are out of the question. + if (mob->is_clone(id)) //checkid is used mostly for random ID based code, therefore clone mobs are out of the question. return 0; return id; } @@ -235,9 +225,9 @@ int mobdb_checkid(const int id) *------------------------------------------*/ struct view_data * mob_get_viewdata(int class_) { - if (mob_db(class_) == mob_dummy) + if (mob->db(class_) == mob->dummy) return 0; - return &mob_db(class_)->vd; + return &mob->db(class_)->vd; } /*========================================== * Cleans up mob-spawn data to make it "valid" @@ -246,7 +236,7 @@ int mob_parse_dataset(struct spawn_data *data) { size_t len; - if ((!mobdb_checkid(data->class_) && !mob_is_clone(data->class_)) || !data->num) + if ((!mob->db_checkid(data->class_) && !mob->is_clone(data->class_)) || !data->num) return 0; if( ( len = strlen(data->eventname) ) > 0 ) @@ -258,9 +248,9 @@ int mob_parse_dataset(struct spawn_data *data) } if(strcmp(data->name,"--en--")==0) - safestrncpy(data->name, mob_db(data->class_)->name, sizeof(data->name)); + safestrncpy(data->name, mob->db(data->class_)->name, sizeof(data->name)); else if(strcmp(data->name,"--ja--")==0) - safestrncpy(data->name, mob_db(data->class_)->jname, sizeof(data->name)); + safestrncpy(data->name, mob->db(data->class_)->jname, sizeof(data->name)); return 1; } @@ -276,7 +266,7 @@ struct mob_data* mob_spawn_dataset(struct spawn_data *data) { 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); @@ -314,7 +304,7 @@ struct mob_data* mob_spawn_dataset(struct spawn_data *data) { *------------------------------------------*/ int mob_get_random_id(int type, int flag, int lv) { - struct mob_db *mob; + struct mob_db *monster; int i=0, class_; if(type < 0 || type >= MAX_RANDOMMONSTER) { ShowError("mob_get_random_id: Invalid type (%d) of random monster.\n", type); @@ -325,17 +315,17 @@ int mob_get_random_id(int type, int flag, int lv) class_ = summon[type].class_[rnd()%summon[type].qty]; else //Dead branch class_ = rnd() % MAX_MOB_DB; - mob = mob_db(class_); - } while ((mob == mob_dummy || - mob_is_clone(class_) || - (flag&1 && mob->summonper[type] <= rnd() % 1000000) || - (flag&2 && lv < mob->lv) || - (flag&4 && mob->status.mode&MD_BOSS) || - (flag&8 && mob->spawn[0].qty < 1) + monster = mob->db(class_); + } while ((monster == mob->dummy || + mob->is_clone(class_) || + (flag&1 && monster->summonper[type] <= rnd() % 1000000) || + (flag&2 && lv < monster->lv) || + (flag&4 && monster->status.mode&MD_BOSS) || + (flag&8 && monster->spawn[0].qty < 1) ) && (i++) < MAX_MOB_DB); if(i >= MAX_MOB_DB) // no suitable monster found, use fallback for given list - class_ = mob_db_data[0]->summonper[type]; + class_ = mob->db_data[0]->summonper[type]; return class_; } @@ -458,10 +448,10 @@ struct mob_data *mob_once_spawn_sub(struct block_list *bl, int16 m, int16 x, int data.x = x; data.y = y; - if (!mob_parse_dataset(&data)) + if (!mob->parse_dataset(&data)) return NULL; - return mob_spawn_dataset(&data); + return mob->spawn_dataset(&data); } /*========================================== @@ -479,8 +469,8 @@ int mob_once_spawn(struct map_session_data* sd, int16 m, int16 x, int16 y, const for (count = 0; count < amount; count++) { - int c = (class_ >= 0) ? class_ : mob_get_random_id(-class_ - 1, (battle_config.random_monster_checklv) ? 3 : 1, lv); - md = mob_once_spawn_sub((sd) ? &sd->bl : NULL, m, x, y, mobname, c, event, size, ai); + int c = (class_ >= 0) ? class_ : mob->get_random_id(-class_ - 1, (battle_config.random_monster_checklv) ? 3 : 1, lv); + md = mob->once_spawn_sub((sd) ? &sd->bl : NULL, m, x, y, mobname, c, event, size, ai); if (!md) continue; @@ -501,11 +491,11 @@ int mob_once_spawn(struct map_session_data* sd, int16 m, int16 x, int16 y, const memcpy(md->guardian_data->guild_name, g->name, NAME_LENGTH); } else if (gc->guild_id) //Guild not yet available, retry in 5. - iTimer->add_timer(iTimer->gettick()+5000,mob_spawn_guardian_sub,md->bl.id,md->guardian_data->guild_id); + iTimer->add_timer(iTimer->gettick()+5000,mob->spawn_guardian_sub,md->bl.id,md->guardian_data->guild_id); } } // end addition [Valaris] - mob_spawn(md); + mob->spawn(md); if (class_ < 0 && battle_config.dead_branch_active) //Behold Aegis's masterful decisions yet again... @@ -565,7 +555,7 @@ int mob_once_spawn_area(struct map_session_data* sd, int16 m, int16 x0, int16 y0 lx = x; ly = y; - id = mob_once_spawn(sd, m, x, y, mobname, class_, 1, event, size, ai); + id = mob->once_spawn(sd, m, x, y, mobname, class_, 1, event, size, ai); } return id; // id of last spawned mob @@ -573,7 +563,7 @@ int mob_once_spawn_area(struct map_session_data* sd, int16 m, int16 x0, int16 y0 /*========================================== * Set a Guardian's guild data [Skotlex] *------------------------------------------*/ -static int mob_spawn_guardian_sub(int tid, unsigned int tick, int id, intptr_t data) +int mob_spawn_guardian_sub(int tid, unsigned int tick, int id, intptr_t data) { //Needed because the guild_data may not be available at guardian spawn time. struct block_list* bl = iMap->id2bl(id); struct mob_data* md; @@ -643,7 +633,7 @@ int mob_spawn_guardian(const char* mapname, short x, short y, const char* mobnam data.m = m; data.num = 1; if(class_<=0) { - class_ = mob_get_random_id(-class_-1, 1, 99); + class_ = mob->get_random_id(-class_-1, 1, 99); if (!class_) return 0; } @@ -668,7 +658,7 @@ int mob_spawn_guardian(const char* mapname, short x, short y, const char* mobnam data.y = y; safestrncpy(data.name, mobname, sizeof(data.name)); safestrncpy(data.eventname, event, sizeof(data.eventname)); - if (!mob_parse_dataset(&data)) + if (!mob->parse_dataset(&data)) return 0; gc=guild->mapname2gc(map[m].name); @@ -693,7 +683,7 @@ int mob_spawn_guardian(const char* mapname, short x, short y, const char* mobnam } } - md = mob_spawn_dataset(&data); + md = mob->spawn_dataset(&data); md->guardian_data = (struct guardian_data*)aCalloc(1, sizeof(struct guardian_data)); md->guardian_data->number = guardian; md->guardian_data->guild_id = gc->guild_id; @@ -719,8 +709,8 @@ int mob_spawn_guardian(const char* mapname, short x, short y, const char* mobnam memcpy (md->guardian_data->guild_name, g->name, NAME_LENGTH); md->guardian_data->guardup_lv = guild->checkskill(g,GD_GUARDUP); } else if (md->guardian_data->guild_id) - iTimer->add_timer(iTimer->gettick()+5000,mob_spawn_guardian_sub,md->bl.id,md->guardian_data->guild_id); - mob_spawn(md); + iTimer->add_timer(iTimer->gettick()+5000,mob->spawn_guardian_sub,md->bl.id,md->guardian_data->guild_id); + mob->spawn(md); return md->bl.id; } @@ -745,7 +735,7 @@ int mob_spawn_bg(const char* mapname, short x, short y, const char* mobname, int data.num = 1; if( class_ <= 0 ) { - class_ = mob_get_random_id(-class_-1,1,99); + class_ = mob->get_random_id(-class_-1,1,99); if( !class_ ) return 0; } @@ -760,11 +750,11 @@ int mob_spawn_bg(const char* mapname, short x, short y, const char* mobname, int data.y = y; safestrncpy(data.name, mobname, sizeof(data.name)); safestrncpy(data.eventname, event, sizeof(data.eventname)); - if( !mob_parse_dataset(&data) ) + if( !mob->parse_dataset(&data) ) return 0; - md = mob_spawn_dataset(&data); - mob_spawn(md); + md = mob->spawn_dataset(&data); + mob->spawn(md); md->bg_id = bg_id; // BG Team ID return md->bl.id; @@ -816,7 +806,7 @@ int mob_linksearch(struct block_list *bl,va_list ap) && !md->target_id) { md->last_linktime = tick; - if( mob_can_reach(md,target,md->db->range2, MSS_FOLLOW) ){ // Reachability judging + if( mob->can_reach(md,target,md->db->range2, MSS_FOLLOW) ){ // Reachability judging md->target_id = target->id; md->min_chase=md->db->range3; return 1; @@ -842,7 +832,7 @@ int mob_delayspawn(int tid, unsigned int tick, int id, intptr_t data) return 0; } md->spawn_timer = INVALID_TIMER; - mob_spawn(md); + mob->spawn(md); } return 0; } @@ -863,7 +853,7 @@ int mob_setdelayspawn(struct mob_data *md) spawntime+= rnd()%md->spawn->delay2; //Apply the spawn delay fix [Skotlex] - db = mob_db(md->spawn->class_); + db = mob->db(md->spawn->class_); mode = db->status.mode; if (mode & MD_BOSS) { //Bosses if (battle_config.boss_spawn_delay != 100) { @@ -883,8 +873,8 @@ int mob_setdelayspawn(struct mob_data *md) spawntime = 5000; if( md->spawn_timer != INVALID_TIMER ) - iTimer->delete_timer(md->spawn_timer, mob_delayspawn); - md->spawn_timer = iTimer->add_timer(iTimer->gettick()+spawntime, mob_delayspawn, md->bl.id, 0); + iTimer->delete_timer(md->spawn_timer, mob->delayspawn); + md->spawn_timer = iTimer->add_timer(iTimer->gettick()+spawntime, mob->delayspawn, md->bl.id, 0); return 0; } @@ -916,7 +906,7 @@ int mob_spawn (struct mob_data *md) { md->class_ = md->spawn->class_; iStatus->set_viewdata(&md->bl, md->class_); - md->db = mob_db(md->class_); + md->db = mob->db(md->class_); memcpy(md->name,md->spawn->name,NAME_LENGTH); } @@ -930,16 +920,16 @@ int mob_spawn (struct mob_data *md) if( !iMap->search_freecell(&md->bl, -1, &md->bl.x, &md->bl.y, md->spawn->xs, md->spawn->ys, battle_config.no_spawn_on_player?4:0) ) { // retry again later if( md->spawn_timer != INVALID_TIMER ) - iTimer->delete_timer(md->spawn_timer, mob_delayspawn); - md->spawn_timer = iTimer->add_timer(tick+5000,mob_delayspawn,md->bl.id,0); + iTimer->delete_timer(md->spawn_timer, mob->delayspawn); + md->spawn_timer = iTimer->add_timer(tick+5000,mob->delayspawn,md->bl.id,0); return 1; } } - else if( battle_config.no_spawn_on_player > 99 && iMap->foreachinrange(mob_count_sub, &md->bl, AREA_SIZE, BL_PC) ) + else if( battle_config.no_spawn_on_player > 99 && iMap->foreachinrange(mob->count_sub, &md->bl, AREA_SIZE, BL_PC) ) { // retry again later (players on sight) if( md->spawn_timer != INVALID_TIMER ) - iTimer->delete_timer(md->spawn_timer, mob_delayspawn); - md->spawn_timer = iTimer->add_timer(tick+5000,mob_delayspawn,md->bl.id,0); + iTimer->delete_timer(md->spawn_timer, mob->delayspawn); + md->spawn_timer = iTimer->add_timer(tick+5000,mob->delayspawn,md->bl.id,0); return 1; } } @@ -953,7 +943,7 @@ int mob_spawn (struct mob_data *md) md->ud.target_to = 0; if( md->spawn_timer != INVALID_TIMER ) { - iTimer->delete_timer(md->spawn_timer, mob_delayspawn); + iTimer->delete_timer(md->spawn_timer, mob->delayspawn); md->spawn_timer = INVALID_TIMER; } @@ -984,20 +974,20 @@ int mob_spawn (struct mob_data *md) // MvP tomb [GreenBox] if ( md->tomb_nid ) - mvptomb_destroy(md); + mob->mvptomb_destroy(md); iMap->addblock(&md->bl); if( map[md->bl.m].users ) clif->spawn(&md->bl); skill->unit_move(&md->bl,tick,1); - mobskill_use(md, tick, MSC_SPAWN); + mob->skill_use(md, tick, MSC_SPAWN); return 0; } /*========================================== * Determines if the mob can change target. [Skotlex] *------------------------------------------*/ -static int mob_can_changetarget(struct mob_data* md, struct block_list* target, int mode) +int mob_can_changetarget(struct mob_data* md, struct block_list* target, int mode) { // if the monster was provoked ignore the above rule [celest] if(md->state.provoke_flag) @@ -1035,7 +1025,7 @@ int mob_target(struct mob_data *md,struct block_list *bl,int dist) nullpo_ret(bl); // Nothing will be carried out if there is no mind of changing TAGE by TAGE ending. - if(md->target_id && !mob_can_changetarget(md, bl, status_get_mode(&md->bl))) + if(md->target_id && !mob->can_changetarget(md, bl, status_get_mode(&md->bl))) return 0; if(!iStatus->check_skilluse(&md->bl, bl, 0, 0)) @@ -1053,7 +1043,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; @@ -1115,7 +1105,7 @@ static int mob_ai_sub_hard_activesearch(struct block_list *bl,va_list ap) /*========================================== * chase target-change routine. *------------------------------------------*/ -static int mob_ai_sub_hard_changechase(struct block_list *bl,va_list ap) +int mob_ai_sub_hard_changechase(struct block_list *bl,va_list ap) { struct mob_data *md; struct block_list **target; @@ -1141,7 +1131,7 @@ static int mob_ai_sub_hard_changechase(struct block_list *bl,va_list ap) /*========================================== * finds nearby bg ally for guardians looking for users to follow. *------------------------------------------*/ -static int mob_ai_sub_hard_bg_ally(struct block_list *bl,va_list ap) { +int mob_ai_sub_hard_bg_ally(struct block_list *bl,va_list ap) { struct mob_data *md; struct block_list **target; @@ -1158,7 +1148,7 @@ static int mob_ai_sub_hard_bg_ally(struct block_list *bl,va_list ap) { /*========================================== * loot monster item search *------------------------------------------*/ -static int mob_ai_sub_hard_lootsearch(struct block_list *bl,va_list ap) +int mob_ai_sub_hard_lootsearch(struct block_list *bl,va_list ap) { struct mob_data* md; struct block_list **target; @@ -1168,7 +1158,7 @@ static int mob_ai_sub_hard_lootsearch(struct block_list *bl,va_list ap) target= va_arg(ap,struct block_list**); dist=distance_bl(&md->bl, bl); - if(mob_can_reach(md,bl,dist+1, MSS_LOOT) && + if(mob->can_reach(md,bl,dist+1, MSS_LOOT) && ((*target) == NULL || !check_distance_bl(&md->bl, *target, dist)) //New target closer than previous one. ) { (*target) = bl; @@ -1178,7 +1168,7 @@ static int mob_ai_sub_hard_lootsearch(struct block_list *bl,va_list ap) return 0; } -static int mob_warpchase_sub(struct block_list *bl,va_list ap) { +int mob_warpchase_sub(struct block_list *bl,va_list ap) { struct block_list *target; struct npc_data **target_nd; struct npc_data *nd; @@ -1209,7 +1199,7 @@ static int mob_warpchase_sub(struct block_list *bl,va_list ap) { /*========================================== * Processing of slave monsters *------------------------------------------*/ -static int mob_ai_sub_hard_slavemob(struct mob_data *md,unsigned int tick) +int mob_ai_sub_hard_slavemob(struct mob_data *md,unsigned int tick) { struct block_list *bl; @@ -1306,12 +1296,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; @@ -1364,7 +1354,7 @@ int mob_randomwalk(struct mob_data *md,unsigned int tick) if(md->move_fail_count>1000){ ShowWarning("MOB can't move. random spawn %d, class = %d, at %s (%d,%d)\n",md->bl.id,md->class_,map[md->bl.m].name, md->bl.x, md->bl.y); md->move_fail_count=0; - mob_spawn(md); + mob->spawn(md); } return 0; } @@ -1396,7 +1386,7 @@ int mob_warpchase(struct mob_data *md, struct block_list *target) return 1; //Already walking to a warp. //Search for warps within mob's viewing range. - iMap->foreachinrange (mob_warpchase_sub, &md->bl, + iMap->foreachinrange (mob->warpchase_sub, &md->bl, md->db->range2, BL_NPC, target, &warp, &distance); if (warp && unit_walktobl(&md->bl, &warp->bl, 1, 1)) @@ -1407,7 +1397,7 @@ int mob_warpchase(struct mob_data *md, struct block_list *target) /*========================================== * AI of MOB whose is near a Player *------------------------------------------*/ -static bool mob_ai_sub_hard(struct mob_data *md, unsigned int tick) +bool mob_ai_sub_hard(struct mob_data *md, unsigned int tick) { struct block_list *tbl = NULL, *abl = NULL; int mode; @@ -1453,9 +1443,9 @@ static bool mob_ai_sub_hard(struct mob_data *md, unsigned int tick) ((((TBL_PC*)tbl)->state.gangsterparadise && !(mode&MD_BOSS)) || ((TBL_PC*)tbl)->invincible_timer != INVALID_TIMER) )) { //Unlock current target. - if (mob_warpchase(md, tbl)) + if (mob->warpchase(md, tbl)) return true; //Chasing this target. - mob_unlocktarget(md, tick-(battle_config.mob_ai&0x8?3000:0)); //Imediately do random walk. + mob->unlocktarget(md, tick-(battle_config.mob_ai&0x8?3000:0)); //Imediately do random walk. tbl = NULL; } } @@ -1470,10 +1460,10 @@ 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 + && !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; @@ -1481,7 +1471,7 @@ static bool mob_ai_sub_hard(struct mob_data *md, unsigned int tick) } } else - if( (abl = iMap->id2bl(md->attacked_id)) && (!tbl || mob_can_changetarget(md, abl, mode)) ) + if( (abl = iMap->id2bl(md->attacked_id)) && (!tbl || mob->can_changetarget(md, abl, mode)) ) { int dist; if( md->bl.m != abl->m || abl->prev == NULL @@ -1493,12 +1483,12 @@ static bool mob_ai_sub_hard(struct mob_data *md, unsigned int tick) (!can_move && DIFF_TICK(tick, md->ud.canmove_tick) > 0 && (battle_config.mob_ai&0x2 || (md->sc.data[SC_SPIDERWEB] && md->sc.data[SC_SPIDERWEB]->val1) || md->sc.data[SC_WUGBITE] || md->sc.data[SC_VACUUM_EXTREME] || md->sc.data[SC_THORNS_TRAP] || md->sc.data[SC__MANHOLE])) // Not yet confirmed if boss will teleport once it can't reach target. - || !mob_can_reach(md, abl, dist+md->db->range3, MSS_RUSH) + || !mob->can_reach(md, abl, dist+md->db->range3, MSS_RUSH) ) ) ) { // Rude attacked if (md->state.attacked_count++ >= RUDE_ATTACKED_COUNT - && !mobskill_use(md, tick, MSC_RUDEATTACKED) && can_move + && !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? @@ -1533,26 +1523,26 @@ static bool mob_ai_sub_hard(struct mob_data *md, unsigned int tick) } // Processing of slave monster - if (md->master_id > 0 && mob_ai_sub_hard_slavemob(md, tick)) + if (md->master_id > 0 && mob->ai_sub_hard_slavemob(md, tick)) return true; // Scan area for targets if (!tbl && mode&MD_LOOTER && md->lootitem && DIFF_TICK(tick, md->ud.canact_tick) > 0 && (md->lootitem_count < LOOTITEM_SIZE || battle_config.monster_loot_type != 1)) { // Scan area for items to loot, avoid trying to loot if the mob is full and can't consume the items. - iMap->foreachinrange (mob_ai_sub_hard_lootsearch, &md->bl, view_range, BL_ITEM, md, &tbl); + iMap->foreachinrange (mob->ai_sub_hard_lootsearch, &md->bl, view_range, BL_ITEM, md, &tbl); } if ((!tbl && mode&MD_AGGRESSIVE) || md->state.skillstate == MSS_FOLLOW) { - iMap->foreachinrange (mob_ai_sub_hard_activesearch, &md->bl, view_range, DEFAULT_ENEMY_TYPE(md), md, &tbl, mode); + iMap->foreachinrange (mob->ai_sub_hard_activesearch, &md->bl, view_range, DEFAULT_ENEMY_TYPE(md), md, &tbl, mode); } else if (mode&MD_CHANGECHASE && (md->state.skillstate == MSS_RUSH || md->state.skillstate == MSS_FOLLOW)) { int search_size; search_size = view_range<md->status.rhw.range ? view_range:md->status.rhw.range; - iMap->foreachinrange (mob_ai_sub_hard_changechase, &md->bl, search_size, DEFAULT_ENEMY_TYPE(md), md, &tbl); + iMap->foreachinrange (mob->ai_sub_hard_changechase, &md->bl, search_size, DEFAULT_ENEMY_TYPE(md), md, &tbl); } if (!tbl) { //No targets available. @@ -1563,7 +1553,7 @@ static bool mob_ai_sub_hard(struct mob_data *md, unsigned int tick) if( md->bg_id && mode&MD_CANATTACK ) { if( md->ud.walktimer != INVALID_TIMER ) return true;/* we are already moving */ - iMap->foreachinrange (mob_ai_sub_hard_bg_ally, &md->bl, view_range, BL_PC, md, &tbl, mode); + iMap->foreachinrange (mob->ai_sub_hard_bg_ally, &md->bl, view_range, BL_PC, md, &tbl, mode); if( tbl ) { if( distance_blxy(&md->bl, tbl->x, tbl->y) <= 3 || unit_walktobl(&md->bl, tbl, 1, 1) ) return true;/* we're moving or close enough don't unlock the target. */ @@ -1571,7 +1561,7 @@ static bool mob_ai_sub_hard(struct mob_data *md, unsigned int tick) } //This handles triggering idle walk/skill. - mob_unlocktarget(md, tick); + mob->unlocktarget(md, tick); return true; } @@ -1583,21 +1573,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... + mob->unlocktarget(md, tick); //Can't loot... return true; } //Within looting range. @@ -1624,7 +1614,7 @@ static bool mob_ai_sub_hard(struct mob_data *md, unsigned int tick) } //Clear item. iMap->clearflooritem (tbl); - mob_unlocktarget (md,tick); + mob->unlocktarget (md,tick); return true; } //Attempt to attack. @@ -1636,7 +1626,7 @@ 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) + mob->log_damage(md, tbl, 0); //Log interaction (counts as 'attacker' for the exp bonus) unit_attack(&md->bl,tbl->id,1); return true; } @@ -1645,8 +1635,8 @@ static bool mob_ai_sub_hard(struct mob_data *md, unsigned int tick) if (!(mode&MD_CANMOVE)) { //Can't chase. Attempt an idle skill before unlocking. md->state.skillstate = MSS_IDLE; - if (!mobskill_use(md, tick, -1)) - mob_unlocktarget(md,tick); + if (!mob->skill_use(md, tick, -1)) + mob->unlocktarget(md,tick); return true; } @@ -1654,7 +1644,7 @@ static bool mob_ai_sub_hard(struct mob_data *md, unsigned int tick) { //Stuck. Attempt an idle skill md->state.skillstate = MSS_IDLE; if (!(++md->ud.walk_count%IDLE_SKILL_INTERVAL)) - mobskill_use(md, tick, -1); + mob->skill_use(md, tick, -1); return true; } @@ -1666,18 +1656,18 @@ static bool mob_ai_sub_hard(struct mob_data *md, unsigned int tick) return true; //Follow up if possible. - if(!mob_can_reach(md, tbl, md->min_chase, MSS_RUSH) || + 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); + mob->unlocktarget(md,tick); return true; } -static int mob_ai_sub_hard_timer(struct block_list *bl,va_list ap) +int mob_ai_sub_hard_timer(struct block_list *bl,va_list ap) { struct mob_data *md = (struct mob_data*)bl; unsigned int tick = va_arg(ap, unsigned int); - if (mob_ai_sub_hard(md, tick)) + if (mob->ai_sub_hard(md, tick)) { //Hard AI triggered. if(!md->state.spotted) md->state.spotted = 1; @@ -1689,11 +1679,11 @@ static int mob_ai_sub_hard_timer(struct block_list *bl,va_list ap) /*========================================== * Serious processing for mob in PC field of view (foreachclient) *------------------------------------------*/ -static int mob_ai_sub_foreachclient(struct map_session_data *sd,va_list ap) +int mob_ai_sub_foreachclient(struct map_session_data *sd,va_list ap) { unsigned int tick; tick=va_arg(ap,unsigned int); - iMap->foreachinrange(mob_ai_sub_hard_timer,&sd->bl, AREA_SIZE+ACTIVE_AI_RANGE, BL_MOB,tick); + iMap->foreachinrange(mob->ai_sub_hard_timer,&sd->bl, AREA_SIZE+ACTIVE_AI_RANGE, BL_MOB,tick); return 0; } @@ -1701,7 +1691,7 @@ static int mob_ai_sub_foreachclient(struct map_session_data *sd,va_list ap) /*========================================== * Negligent mode MOB AI (PC is not in near) *------------------------------------------*/ -static int mob_ai_sub_lazy(struct mob_data *md, va_list args) +int mob_ai_sub_lazy(struct mob_data *md, va_list args) { unsigned int tick; @@ -1713,7 +1703,7 @@ static int mob_ai_sub_lazy(struct mob_data *md, va_list args) tick = va_arg(args,unsigned int); if (battle_config.mob_ai&0x20 && map[md->bl.m].users>0) - return (int)mob_ai_sub_hard(md, tick); + return (int)mob->ai_sub_hard(md, tick); if (md->bl.prev==NULL || md->status.hp == 0) return 1; @@ -1724,7 +1714,7 @@ static int mob_ai_sub_lazy(struct mob_data *md, va_list args) DIFF_TICK(tick,md->last_thinktime) > MIN_MOBTHINKTIME) { if (DIFF_TICK(tick,md->last_pcneartime) < battle_config.mob_active_time) - return (int)mob_ai_sub_hard(md, tick); + return (int)mob->ai_sub_hard(md, tick); md->last_pcneartime = 0; } @@ -1734,7 +1724,7 @@ static int mob_ai_sub_lazy(struct mob_data *md, va_list args) DIFF_TICK(tick,md->last_thinktime) > MIN_MOBTHINKTIME) { if (DIFF_TICK(tick,md->last_pcneartime) < battle_config.boss_active_time) - return (int)mob_ai_sub_hard(md, tick); + return (int)mob->ai_sub_hard(md, tick); md->last_pcneartime = 0; } @@ -1744,7 +1734,7 @@ 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; } @@ -1753,15 +1743,15 @@ static int mob_ai_sub_lazy(struct mob_data *md, va_list args) if( map[md->bl.m].users > 0 ) { if( rnd()%1000 < MOB_LAZYMOVEPERC(md) ) - mob_randomwalk(md, tick); + mob->randomwalk(md, tick); else if( rnd()%1000 < MOB_LAZYSKILLPERC ) //Chance to do a mob's idle skill. - mobskill_use(md, tick, -1); + mob->skill_use(md, tick, -1); } else { if( rnd()%1000 < MOB_LAZYMOVEPERC(md) ) - mob_randomwalk(md, tick); + mob->randomwalk(md, tick); } } return 0; @@ -1770,22 +1760,22 @@ static int mob_ai_sub_lazy(struct mob_data *md, va_list args) /*========================================== * Negligent processing for mob outside PC field of view (interval timer function) *------------------------------------------*/ -static int mob_ai_lazy(int tid, unsigned int tick, int id, intptr_t data) +int mob_ai_lazy(int tid, unsigned int tick, int id, intptr_t data) { - iMap->map_foreachmob(mob_ai_sub_lazy,tick); + iMap->map_foreachmob(mob->ai_sub_lazy,tick); return 0; } /*========================================== * Serious processing for mob in PC field of view (interval timer function) *------------------------------------------*/ -static int mob_ai_hard(int tid, unsigned int tick, int id, intptr_t data) +int mob_ai_hard(int tid, unsigned int tick, int id, intptr_t data) { if (battle_config.mob_ai&0x20) - iMap->map_foreachmob(mob_ai_sub_lazy,tick); + iMap->map_foreachmob(mob->ai_sub_lazy,tick); else - iMap->map_foreachpc(mob_ai_sub_foreachclient,tick); + iMap->map_foreachpc(mob->ai_sub_foreachclient,tick); return 0; } @@ -1793,7 +1783,7 @@ 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; @@ -1806,7 +1796,7 @@ static struct item_drop* mob_setdropitem(int nameid, int qty, struct item_data * /*========================================== * Initializes the delay drop structure for mob-looted items. *------------------------------------------*/ -static struct item_drop* mob_setlootitem(struct item* item) +struct item_drop* mob_setlootitem(struct item* item) { struct item_drop *drop = ers_alloc(item_drop_ers, struct item_drop); memcpy(&drop->item_data, item, sizeof(struct item)); @@ -1817,7 +1807,7 @@ static struct item_drop* mob_setlootitem(struct item* item) /*========================================== * item drop with delay (timer function) *------------------------------------------*/ -static int mob_delay_item_drop(int tid, unsigned int tick, int id, intptr_t data) +int mob_delay_item_drop(int tid, unsigned int tick, int id, intptr_t data) { struct item_drop_list *list; struct item_drop *ditem, *ditem_prev; @@ -1841,7 +1831,7 @@ static int mob_delay_item_drop(int tid, unsigned int tick, int id, intptr_t data * rate is the drop-rate of the item, required for autoloot. * flag : Killed only by homunculus? *------------------------------------------*/ -static void mob_item_drop(struct mob_data *md, struct item_drop_list *dlist, struct item_drop *ditem, int loot, int drop_rate, unsigned short flag) +void mob_item_drop(struct mob_data *md, struct item_drop_list *dlist, struct item_drop *ditem, int loot, int drop_rate, unsigned short flag) { TBL_PC* sd; @@ -1915,7 +1905,7 @@ int mob_deleteslave(struct mob_data *md) { nullpo_ret(md); - iMap->foreachinmap(mob_deleteslave_sub, md->bl.m, BL_MOB,md->bl.id); + iMap->foreachinmap(mob->deleteslave_sub, md->bl.m, BL_MOB,md->bl.id); return 0; } // Mob respawning through KAIZEL or NPC_REBIRTH [Skotlex] @@ -2060,7 +2050,7 @@ void mob_damage(struct mob_data *md, struct block_list *src, int damage) { } //Log damage if (src) - mob_log_damage(md, src, damage); + mob->log_damage(md, src, damage); md->dmgtick = iTimer->gettick(); } @@ -2085,7 +2075,7 @@ void mob_damage(struct mob_data *md, struct block_list *src, int damage) { if( md->special_state.ai == 2 ) {//LOne WOlf explained that ANYONE can trigger the marine countdown skill. [Skotlex] md->state.alchemist = 1; - mobskill_use(md, iTimer->gettick(), MSC_ALCHEMIST); + mob->skill_use(md, iTimer->gettick(), MSC_ALCHEMIST); } } @@ -2123,7 +2113,7 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type) if( src ) { // Use Dead skill only if not killed by Script or Command md->state.skillstate = MSS_DEAD; - mobskill_use(md,tick,-1); + mob->skill_use(md,tick,-1); } iMap->freeblock_lock(); @@ -2131,7 +2121,7 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type) memset(pt,0,sizeof(pt)); if(src && src->type == BL_MOB) - mob_unlocktarget((struct mob_data *)src,tick); + mob->unlocktarget((struct mob_data *)src,tick); // filter out entries not eligible for exp distribution memset(tmpsd,0,sizeof(tmpsd)); @@ -2386,7 +2376,7 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type) continue; } - ditem = mob_setdropitem(md->db->dropitem[i].nameid, 1, it); + ditem = mob->setdropitem(md->db->dropitem[i].nameid, 1, it); //A Rare Drop Global Announce by Lupus if( mvp_sd && drop_rate <= battle_config.rare_drop_announce ) { @@ -2397,14 +2387,14 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type) } // Announce first, or else ditem will be freed. [Lance] // By popular demand, use base drop rate for autoloot code. [Skotlex] - mob_item_drop(md, dlist, ditem, 0, md->db->dropitem[i].p, homkillonly); + mob->item_drop(md, dlist, ditem, 0, md->db->dropitem[i].p, homkillonly); } // Ore Discovery [Celest] if (sd == mvp_sd && pc->checkskill(sd,BS_FINDINGORE) > 0) { if( (temp = itemdb->chain_item(itemdb->chain_cache[ECC_ORE],&i)) ) { - ditem = mob_setdropitem(temp, 1, NULL); - mob_item_drop(md, dlist, ditem, 0, i, homkillonly); + ditem = mob->setdropitem(temp, 1, NULL); + mob->item_drop(md, dlist, ditem, 0, i, homkillonly); } } @@ -2435,7 +2425,7 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type) continue; itemid = (sd->add_drop[i].id > 0) ? sd->add_drop[i].id : itemdb->chain_item(sd->add_drop[i].group,&drop_rate); if( itemid ) - mob_item_drop(md, dlist, mob_setdropitem(itemid,1,NULL), 0, drop_rate, homkillonly); + mob->item_drop(md, dlist, mob->setdropitem(itemid,1,NULL), 0, drop_rate, homkillonly); } } @@ -2450,10 +2440,10 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type) // process items looted by the mob if(md->lootitem) { for(i = 0; i < md->lootitem_count; i++) - mob_item_drop(md, dlist, mob_setlootitem(&md->lootitem[i]), 1, 10000, homkillonly); + mob->item_drop(md, dlist, mob->setlootitem(&md->lootitem[i]), 1, 10000, homkillonly); } if (dlist->item) //There are drop items. - iTimer->add_timer(tick + (!battle_config.delay_battle_damage?500:0), mob_delay_item_drop, 0, (intptr_t)dlist); + iTimer->add_timer(tick + (!battle_config.delay_battle_damage?500:0), mob->delay_item_drop, 0, (intptr_t)dlist); else //No drops ers_free(item_drop_list_ers, dlist); } else if (md->lootitem && md->lootitem_count) { //Loot MUST drop! @@ -2466,8 +2456,8 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type) dlist->third_charid = (third_sd ? third_sd->status.char_id : 0); dlist->item = NULL; for(i = 0; i < md->lootitem_count; i++) - mob_item_drop(md, dlist, mob_setlootitem(&md->lootitem[i]), 1, 10000, homkillonly); - iTimer->add_timer(tick + (!battle_config.delay_battle_damage?500:0), mob_delay_item_drop, 0, (intptr_t)dlist); + mob->item_drop(md, dlist, mob->setlootitem(&md->lootitem[i]), 1, 10000, homkillonly); + iTimer->add_timer(tick + (!battle_config.delay_battle_damage?500:0), mob->delay_item_drop, 0, (intptr_t)dlist); } if(mvp_sd && md->db->mexp > 0 && !md->special_state.ai) { @@ -2569,7 +2559,7 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type) if( sd ) { if( sd->mission_mobid == md->class_) { //TK_MISSION [Skotlex] - if( ++sd->mission_count >= 100 && (temp = mob_get_random_id(0, 0xE, sd->status.base_level)) ) { + if( ++sd->mission_count >= 100 && (temp = mob->get_random_id(0, 0xE, sd->status.base_level)) ) { pc->addfame(sd, 1); sd->mission_mobid = temp; pc_setglobalreg(sd,"TK_MISSION_ID", temp); @@ -2584,7 +2574,7 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type) else if( sd->avail_quests ) quest_update_objective(sd, md->class_); - if( sd->md && src && src->type != BL_HOM && mob_db(md->class_)->lv > sd->status.base_level/2 ) + if( sd->md && src && src->type != BL_HOM && mob->db(md->class_)->lv > sd->status.base_level/2 ) mercenary->kills(sd->md); } @@ -2606,14 +2596,14 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type) } if(md->deletetimer != INVALID_TIMER) { - iTimer->delete_timer(md->deletetimer,mob_timer_delete); + iTimer->delete_timer(md->deletetimer,mob->timer_delete); md->deletetimer = INVALID_TIMER; } /** * Only loops if necessary (e.g. a poring would never need to loop) **/ if( md->can_summon ) - mob_deleteslave(md); + mob->deleteslave(md); iMap->freeblock_unlock(); @@ -2637,11 +2627,11 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type) // MvP tomb [GreenBox] if (battle_config.mvp_tomb_enabled && md->spawn->state.boss && map[md->bl.m].flag.notomb != 1) - mvptomb_create(md, mvp_sd ? mvp_sd->status.name : NULL, time(NULL)); + mob->mvptomb_create(md, mvp_sd ? mvp_sd->status.name : NULL, time(NULL)); if( !rebirth ) { iStatus->change_clear(&md->bl,1); - mob_setdelayspawn(md); //Set respawning. + mob->setdelayspawn(md); //Set respawning. } return 3; //Remove from map. } @@ -2660,7 +2650,7 @@ void mob_revive(struct mob_data *md, unsigned int hp) iMap->addblock(&md->bl); clif->spawn(&md->bl); skill->unit_move(&md->bl,tick,1); - mobskill_use(md, tick, MSC_SPAWN); + mob->skill_use(md, tick, MSC_SPAWN); if (battle_config.show_mob_info&3) clif->charnameack (0, &md->bl); } @@ -2716,16 +2706,16 @@ int mob_random_class (int *value, size_t count) // no count specified, look into the array manually, but take only max 5 elements if (count < 1) { count = 0; - while(count < 5 && mobdb_checkid(value[count])) count++; + while(count < 5 && mob->db_checkid(value[count])) count++; if(count < 1) // nothing found return 0; } else { // check if at least the first value is valid - if(mobdb_checkid(value[0]) == 0) + if(mob->db_checkid(value[0]) == 0) return 0; } //Pick a random value, hoping it exists. [Skotlex] - return mobdb_checkid(value[rnd()%count]); + return mob->db_checkid(value[rnd()%count]); } /*========================================== @@ -2751,7 +2741,7 @@ int mob_class_change (struct mob_data *md, int class_) if( md->special_state.ai > 1 ) return 0; //Marine Spheres and Floras. - if( mob_is_clone(md->class_) ) + if( mob->is_clone(md->class_) ) return 0; //Clones if( md->class_ == class_ ) @@ -2759,7 +2749,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 @@ -2834,7 +2824,7 @@ int mob_warpslave(struct block_list *bl, int range) if (range < 1) range = 1; //Min range needed to avoid crashes and stuff. [Skotlex] - return iMap->foreachinmap(mob_warpslave_sub, bl->m, BL_MOB, bl, range); + return iMap->foreachinmap(mob->warpslave_sub, bl->m, BL_MOB, bl, range); } /*========================================== @@ -2857,7 +2847,7 @@ int mob_countslave_sub(struct block_list *bl,va_list ap) *------------------------------------------*/ int mob_countslave(struct block_list *bl) { - return iMap->foreachinmap(mob_countslave_sub, bl->m, BL_MOB,bl->id); + return iMap->foreachinmap(mob->countslave_sub, bl->m, BL_MOB,bl->id); } /*========================================== @@ -2880,14 +2870,14 @@ int mob_summonslave(struct mob_data *md2,int *value,int amount,uint16 skill_id) data.state.size = md2->special_state.size; data.state.ai = md2->special_state.ai; - if(mobdb_checkid(value[0]) == 0) + if(mob->db_checkid(value[0]) == 0) return 0; /** * Flags this monster is able to summon; saves a worth amount of memory upon deletion **/ md2->can_summon = 1; - while(count < 5 && mobdb_checkid(value[count])) count++; + while(count < 5 && mob->db_checkid(value[count])) count++; if(count < 1) return 0; if (amount > 0 && amount < count) { //Do not start on 0, pick some random sub subset [Skotlex] k = rnd()%count; @@ -2901,7 +2891,7 @@ int mob_summonslave(struct mob_data *md2,int *value,int amount,uint16 skill_id) for(;k<amount;k++) { short x,y; data.class_ = value[k%count]; //Summon slaves in round-robin fashion. [Skotlex] - if (mobdb_checkid(data.class_) == 0) + if (mob->db_checkid(data.class_) == 0) continue; if (iMap->search_freecell(&md2->bl, 0, &x, &y, MOB_SLAVEDISTANCE, MOB_SLAVEDISTANCE, 0)) { @@ -2918,15 +2908,15 @@ int mob_summonslave(struct mob_data *md2,int *value,int amount,uint16 skill_id) else strcpy(data.name,"--ja--"); - if (!mob_parse_dataset(&data)) + if (!mob->parse_dataset(&data)) continue; - md= mob_spawn_dataset(&data); + md= mob->spawn_dataset(&data); if(skill_id == NPC_SUMMONSLAVE){ md->master_id=md2->bl.id; md->special_state.ai = md2->special_state.ai; } - mob_spawn(md); + mob->spawn(md); if (hp_rate) //Scale HP md->status.hp = md->status.max_hp*hp_rate/100; @@ -2964,8 +2954,8 @@ int mob_summonslave(struct mob_data *md2,int *value,int amount,uint16 skill_id) *------------------------------------------*/ int mob_skill_id2skill_idx(int class_,uint16 skill_id) { - int i, max = mob_db(class_)->maxskill; - struct mob_skill *ms=mob_db(class_)->skill; + int i, max = mob->db(class_)->maxskill; + struct mob_skill *ms=mob->db(class_)->skill; if(ms==NULL) return -1; @@ -3003,7 +2993,7 @@ int mob_getfriendhprate_sub(struct block_list *bl,va_list ap) (*fr) = bl; return 1; } -static struct block_list *mob_getfriendhprate(struct mob_data *md,int min_rate,int max_rate) +struct block_list *mob_getfriendhprate(struct mob_data *md,int min_rate,int max_rate) { struct block_list *fr=NULL; int type = BL_MOB; @@ -3013,7 +3003,7 @@ static struct block_list *mob_getfriendhprate(struct mob_data *md,int min_rate,i if (md->special_state.ai) //Summoned creatures. [Skotlex] type = BL_PC; - iMap->foreachinrange(mob_getfriendhprate_sub, &md->bl, 8, type,md,min_rate,max_rate,&fr); + iMap->foreachinrange(mob->getfriendhprate_sub, &md->bl, 8, type,md,min_rate,max_rate,&fr); return fr; } /*========================================== @@ -3070,7 +3060,7 @@ struct mob_data *mob_getfriendstatus(struct mob_data *md,int cond1,int cond2) struct mob_data* fr = NULL; nullpo_ret(md); - iMap->foreachinrange(mob_getfriendstatus_sub, &md->bl, 8,BL_MOB, md,cond1,cond2,&fr); + iMap->foreachinrange(mob->getfriendstatus_sub, &md->bl, 8,BL_MOB, md,cond1,cond2,&fr); return fr; } @@ -3149,18 +3139,18 @@ 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; 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; case MSC_AFTERSKILL: @@ -3170,7 +3160,7 @@ 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; case MSC_ALCHEMIST: @@ -3270,7 +3260,7 @@ int mobskill_use(struct mob_data *md, unsigned int tick, int event) } //Skill used. Post-setups... if ( ms[ i ].msg_id ){ //Display color message [SnakeDrak] - struct mob_chat *mc = mob_chat(ms[i].msg_id); + struct mob_chat *mc = mob->chat(ms[i].msg_id); char temp[CHAT_SIZE_MAX]; char name[NAME_LENGTH]; snprintf(name, sizeof name,"%s", md->name); @@ -3306,13 +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] @@ -3329,7 +3319,7 @@ int mob_is_clone(int class_) { if(class_ < MOB_CLONE_START || class_ > MOB_CLONE_END) return 0; - if (mob_db(class_) == mob_dummy) + if (mob->db(class_) == mob->dummy) return 0; return class_; } @@ -3353,11 +3343,11 @@ int mob_clone_spawn(struct map_session_data *sd, int16 m, int16 x, int16 y, cons if(pc_isdead(sd) && master_id && flag&1) return 0; - ARR_FIND( MOB_CLONE_START, MOB_CLONE_END, class_, mob_db_data[class_] == NULL ); + ARR_FIND( MOB_CLONE_START, MOB_CLONE_END, class_, mob->db_data[class_] == NULL ); if(class_ >= MOB_CLONE_END) return 0; - db = mob_db_data[class_]=(struct mob_db*)aCalloc(1, sizeof(struct mob_db)); + db = mob->db_data[class_]=(struct mob_db*)aCalloc(1, sizeof(struct mob_db)); status = &db->status; strcpy(db->sprite,sd->status.name); strcpy(db->name,sd->status.name); @@ -3519,7 +3509,7 @@ int mob_clone_spawn(struct map_session_data *sd, int16 m, int16 x, int16 y, cons sd->fd = fd; //Finally, spawn it. - md = mob_once_spawn_sub(&sd->bl, m, x, y, "--en--", class_, event, SZ_SMALL, AI_NONE); + md = mob->once_spawn_sub(&sd->bl, m, x, y, "--en--", class_, event, SZ_SMALL, AI_NONE); if (!md) return 0; //Failed? md->special_state.clone = 1; @@ -3532,12 +3522,12 @@ int mob_clone_spawn(struct map_session_data *sd, int16 m, int16 x, int16 y, cons if (duration) //Auto Delete after a while. { if( md->deletetimer != INVALID_TIMER ) - iTimer->delete_timer(md->deletetimer, mob_timer_delete); - md->deletetimer = iTimer->add_timer (iTimer->gettick() + duration, mob_timer_delete, md->bl.id, 0); + iTimer->delete_timer(md->deletetimer, mob->timer_delete); + md->deletetimer = iTimer->add_timer (iTimer->gettick() + duration, mob->timer_delete, md->bl.id, 0); } } - mob_spawn(md); + mob->spawn(md); return md->bl.id; } @@ -3546,11 +3536,11 @@ int mob_clone_delete(struct mob_data *md) { const int class_ = md->class_; if (class_ >= MOB_CLONE_START && class_ < MOB_CLONE_END - && mob_db_data[class_]!=NULL) { - aFree(mob_db_data[class_]); - mob_db_data[class_]=NULL; + && mob->db_data[class_]!=NULL) { + aFree(mob->db_data[class_]); + mob->db_data[class_]=NULL; //Clear references to the db - md->db = mob_dummy; + md->db = mob->dummy; md->vd = NULL; return 1; } @@ -3563,50 +3553,50 @@ int mob_clone_delete(struct mob_data *md) /*========================================== * Since un-setting [ mob ] up was used, it is an initial provisional value setup. *------------------------------------------*/ -static int mob_makedummymobdb(int class_) +int mob_makedummymobdb(int class_) { - if (mob_dummy != NULL) + if (mob->dummy != NULL) { - if (mob_db(class_) == mob_dummy) - return 1; //Using the mob_dummy data already. [Skotlex] + if (mob->db(class_) == mob->dummy) + return 1; //Using the mob->dummy data already. [Skotlex] if (class_ > 0 && class_ <= MAX_MOB_DB) { //Remove the mob data so that it uses the dummy data instead. - aFree(mob_db_data[class_]); - mob_db_data[class_] = NULL; + aFree(mob->db_data[class_]); + mob->db_data[class_] = NULL; } return 0; } //Initialize dummy data. - mob_dummy = (struct mob_db*)aCalloc(1, sizeof(struct mob_db)); //Initializing the dummy mob. - sprintf(mob_dummy->sprite,"DUMMY"); - sprintf(mob_dummy->name,"Dummy"); - sprintf(mob_dummy->jname,"Dummy"); - mob_dummy->lv=1; - mob_dummy->status.max_hp=1000; - mob_dummy->status.max_sp=1; - mob_dummy->status.rhw.range=1; - mob_dummy->status.rhw.atk=7; - mob_dummy->status.rhw.atk2=10; - mob_dummy->status.str=1; - mob_dummy->status.agi=1; - mob_dummy->status.vit=1; - mob_dummy->status.int_=1; - mob_dummy->status.dex=6; - mob_dummy->status.luk=2; - mob_dummy->status.speed=300; - mob_dummy->status.adelay=1000; - mob_dummy->status.amotion=500; - mob_dummy->status.dmotion=500; - mob_dummy->base_exp=2; - mob_dummy->job_exp=1; - mob_dummy->range2=10; - mob_dummy->range3=10; + mob->dummy = (struct mob_db*)aCalloc(1, sizeof(struct mob_db)); //Initializing the dummy mob. + sprintf(mob->dummy->sprite,"DUMMY"); + sprintf(mob->dummy->name,"Dummy"); + sprintf(mob->dummy->jname,"Dummy"); + mob->dummy->lv=1; + mob->dummy->status.max_hp=1000; + mob->dummy->status.max_sp=1; + mob->dummy->status.rhw.range=1; + mob->dummy->status.rhw.atk=7; + mob->dummy->status.rhw.atk2=10; + mob->dummy->status.str=1; + mob->dummy->status.agi=1; + mob->dummy->status.vit=1; + mob->dummy->status.int_=1; + mob->dummy->status.dex=6; + mob->dummy->status.luk=2; + mob->dummy->status.speed=300; + mob->dummy->status.adelay=1000; + mob->dummy->status.amotion=500; + mob->dummy->status.dmotion=500; + mob->dummy->base_exp=2; + mob->dummy->job_exp=1; + mob->dummy->range2=10; + mob->dummy->range3=10; return 0; } //Adjusts the drop rate of item according to the criteria given. [Skotlex] -static unsigned int mob_drop_adjust(int baserate, int rate_adjust, unsigned short rate_min, unsigned short rate_max) +unsigned int mob_drop_adjust(int baserate, int rate_adjust, unsigned short rate_min, unsigned short rate_max) { double rate = baserate; @@ -3628,7 +3618,7 @@ static unsigned int mob_drop_adjust(int baserate, int rate_adjust, unsigned shor * @param mob_id ID of the monster * @param rate_adjust pointer to store ratio if found */ -static void item_dropratio_adjust(int nameid, int mob_id, int *rate_adjust) +void item_dropratio_adjust(int nameid, int mob_id, int *rate_adjust) { if( item_drop_ratio_db[nameid] ) { if( item_drop_ratio_db[nameid]->mob_id[0] ) { // only for listed mobs @@ -3655,7 +3645,7 @@ static inline int mob_parse_dbrow_cap_value(int class_, int min, int max, int va /*========================================== * processes one mobdb entry *------------------------------------------*/ -static bool mob_parse_dbrow(char** str) +bool mob_parse_dbrow(char** str) { struct mob_db *db, entry; struct status_data *status; @@ -3803,8 +3793,8 @@ static bool mob_parse_dbrow(char** str) db->mvpitem[i].p = 0; //No item.... continue; } - item_dropratio_adjust(db->mvpitem[i].nameid, class_, &rate_adjust); - db->mvpitem[i].p = mob_drop_adjust(atoi(str[32+i*2]), rate_adjust, battle_config.item_drop_mvp_min, battle_config.item_drop_mvp_max); + mob->item_dropratio_adjust(db->mvpitem[i].nameid, class_, &rate_adjust); + db->mvpitem[i].p = mob->drop_adjust(atoi(str[32+i*2]), rate_adjust, battle_config.item_drop_mvp_min, battle_config.item_drop_mvp_max); //calculate and store Max available drop chance of the MVP item if (db->mvpitem[i].p) { @@ -3867,8 +3857,8 @@ static bool mob_parse_dbrow(char** str) ratemax = battle_config.item_drop_common_max; break; } - item_dropratio_adjust(id->nameid, class_, &rate_adjust); - db->dropitem[i].p = mob_drop_adjust(rate, rate_adjust, ratemin, ratemax); + mob->item_dropratio_adjust(id->nameid, class_, &rate_adjust); + db->dropitem[i].p = mob->drop_adjust(rate, rate_adjust, ratemin, ratemax); //calculate and store Max available drop chance of the item if( db->dropitem[i].p && (class_ < 1324 || class_ > 1363) && (class_ < 1938 || class_ > 1946) ) @@ -3890,25 +3880,25 @@ static bool mob_parse_dbrow(char** str) } } // Finally insert monster's data into the database. - if (mob_db_data[class_] == NULL) - mob_db_data[class_] = (struct mob_db*)aMalloc(sizeof(struct mob_db)); + if (mob->db_data[class_] == NULL) + mob->db_data[class_] = (struct mob_db*)aMalloc(sizeof(struct mob_db)); else //Copy over spawn data - memcpy(&db->spawn, mob_db_data[class_]->spawn, sizeof(db->spawn)); + memcpy(&db->spawn, mob->db_data[class_]->spawn, sizeof(db->spawn)); - memcpy(mob_db_data[class_], db, sizeof(struct mob_db)); + memcpy(mob->db_data[class_], db, sizeof(struct mob_db)); return true; } /*========================================== * mob_db.txt reading *------------------------------------------*/ -static bool mob_readdb_sub(char* fields[], int columns, int current) +bool mob_readdb_sub(char* fields[], int columns, int current) { - return mob_parse_dbrow(fields); + return mob->parse_dbrow(fields); } -static void mob_readdb(void) +void mob_readdb(void) { const char* filename[] = { DBPATH"mob_db.txt", @@ -3927,14 +3917,14 @@ static void mob_readdb(void) } } - sv->readdb(iMap->db_path, filename[fi], ',', 31+2*MAX_MVP_DROP+2*MAX_MOB_DROP, 31+2*MAX_MVP_DROP+2*MAX_MOB_DROP, -1, &mob_readdb_sub); + sv->readdb(iMap->db_path, filename[fi], ',', 31+2*MAX_MVP_DROP+2*MAX_MOB_DROP, 31+2*MAX_MVP_DROP+2*MAX_MOB_DROP, -1, mob->readdb_sub); } } /*========================================== * mob_db table reading *------------------------------------------*/ -static int mob_read_sqldb(void) +int mob_read_sqldb(void) { const char* mob_db_name[] = { iMap->mob_db_db, iMap->mob_db2_db }; int fi; @@ -3968,7 +3958,7 @@ static int mob_read_sqldb(void) p+= len + 1; } - if (!mob_parse_dbrow(str)) + if (!mob->parse_dbrow(str)) continue; count++; @@ -3985,13 +3975,13 @@ static int mob_read_sqldb(void) /*========================================== * MOB display graphic change data reading *------------------------------------------*/ -static bool mob_readdb_mobavail(char* str[], int columns, int current) +bool mob_readdb_mobavail(char* str[], int columns, int current) { int class_, k; class_=atoi(str[0]); - if(mob_db(class_) == mob_dummy) // invalid class (probably undefined in db) + if(mob->db(class_) == mob->dummy) // invalid class (probably undefined in db) { ShowWarning("mob_readdb_mobavail: Unknown mob id %d.\n", class_); return false; @@ -3999,24 +3989,24 @@ static bool mob_readdb_mobavail(char* str[], int columns, int current) k=atoi(str[1]); - memset(&mob_db_data[class_]->vd, 0, sizeof(struct view_data)); - mob_db_data[class_]->vd.class_=k; + memset(&mob->db_data[class_]->vd, 0, sizeof(struct view_data)); + mob->db_data[class_]->vd.class_=k; //Player sprites if(pcdb_checkid(k) && columns==12) { - mob_db_data[class_]->vd.sex=atoi(str[2]); - mob_db_data[class_]->vd.hair_style=atoi(str[3]); - mob_db_data[class_]->vd.hair_color=atoi(str[4]); - mob_db_data[class_]->vd.weapon=atoi(str[5]); - mob_db_data[class_]->vd.shield=atoi(str[6]); - mob_db_data[class_]->vd.head_top=atoi(str[7]); - mob_db_data[class_]->vd.head_mid=atoi(str[8]); - mob_db_data[class_]->vd.head_bottom=atoi(str[9]); - mob_db_data[class_]->option=atoi(str[10])&~(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE); - mob_db_data[class_]->vd.cloth_color=atoi(str[11]); // Monster player dye option - Valaris + mob->db_data[class_]->vd.sex=atoi(str[2]); + mob->db_data[class_]->vd.hair_style=atoi(str[3]); + mob->db_data[class_]->vd.hair_color=atoi(str[4]); + mob->db_data[class_]->vd.weapon=atoi(str[5]); + mob->db_data[class_]->vd.shield=atoi(str[6]); + mob->db_data[class_]->vd.head_top=atoi(str[7]); + mob->db_data[class_]->vd.head_mid=atoi(str[8]); + mob->db_data[class_]->vd.head_bottom=atoi(str[9]); + mob->db_data[class_]->option=atoi(str[10])&~(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE); + mob->db_data[class_]->vd.cloth_color=atoi(str[11]); // Monster player dye option - Valaris } else if(columns==3) - mob_db_data[class_]->vd.head_bottom=atoi(str[2]); // mob equipment [Valaris] + mob->db_data[class_]->vd.head_bottom=atoi(str[2]); // mob equipment [Valaris] else if( columns != 2 ) return false; @@ -4026,7 +4016,7 @@ static bool mob_readdb_mobavail(char* str[], int columns, int current) /*========================================== * Reading of random monster data *------------------------------------------*/ -static int mob_read_randommonster(void) +int mob_read_randommonster(void) { FILE *fp; char line[1024]; @@ -4043,7 +4033,7 @@ static int mob_read_randommonster(void) for( i = 0; i < ARRAYLENGTH(mobfile) && i < MAX_RANDOMMONSTER; i++ ) { unsigned int count = 0; - mob_db_data[0]->summonper[i] = 1002; // Default fallback value, in case the database does not provide one + mob->db_data[0]->summonper[i] = 1002; // Default fallback value, in case the database does not provide one sprintf(line, "%s/%s", iMap->db_path, mobfile[i]); fp=fopen(line,"r"); if(fp==NULL){ @@ -4066,10 +4056,10 @@ static int mob_read_randommonster(void) continue; class_ = atoi(str[0]); - if(mob_db(class_) == mob_dummy) + if(mob->db(class_) == mob->dummy) continue; count++; - mob_db_data[class_]->summonper[i]=atoi(str[2]); + mob->db_data[class_]->summonper[i]=atoi(str[2]); if (i) { if( summon[i].qty < ARRAYLENGTH(summon[i].class_) ) //MvPs summon[i].class_[summon[i].qty++] = class_; @@ -4080,7 +4070,7 @@ static int mob_read_randommonster(void) } } if (i && !summon[i].qty) { //At least have the default here. - summon[i].class_[0] = mob_db_data[0]->summonper[i]; + summon[i].class_[0] = mob->db_data[0]->summonper[i]; summon[i].qty = 1; } fclose(fp); @@ -4093,7 +4083,7 @@ static int mob_read_randommonster(void) * processes one mob_chat_db entry [SnakeDrak] * @param last_msg_id ensures that only one error message per mob id is printed *------------------------------------------*/ -static bool mob_parse_row_chatdb(char** str, const char* source, int line, int* last_msg_id) +bool mob_parse_row_chatdb(char** str, const char* source, int line, int* last_msg_id) { char* msg; struct mob_chat *ms; @@ -4111,10 +4101,10 @@ static bool mob_parse_row_chatdb(char** str, const char* source, int line, int* return false; } - if (mob_chat_db[msg_id] == NULL) - mob_chat_db[msg_id] = (struct mob_chat*)aCalloc(1, sizeof (struct mob_chat)); + if (mob->chat_db[msg_id] == NULL) + mob->chat_db[msg_id] = (struct mob_chat*)aCalloc(1, sizeof (struct mob_chat)); - ms = mob_chat_db[msg_id]; + ms = mob->chat_db[msg_id]; //MSG ID ms->msg_id=msg_id; //Color @@ -4151,7 +4141,7 @@ static bool mob_parse_row_chatdb(char** str, const char* source, int line, int* /*========================================== * mob_chat_db.txt reading [SnakeDrak] *-------------------------------------------------------------------------*/ -static void mob_readchatdb(void) +void mob_readchatdb(void) { char arc[]="mob_chat_db.txt"; uint32 lines=0, count=0; @@ -4195,7 +4185,7 @@ static void mob_readchatdb(void) continue; } - if( !mob_parse_row_chatdb(str, path, lines, &tmp) ) + if( !mob->parse_row_chatdb(str, path, lines, &tmp) ) continue; count++; @@ -4207,7 +4197,7 @@ static void mob_readchatdb(void) /*========================================== * processes one mob_skill_db entry *------------------------------------------*/ -static bool mob_parse_row_mobskilldb(char** str, int columns, int current) +bool mob_parse_row_mobskilldb(char** str, int columns, int current) { static const struct { char str[32]; @@ -4289,7 +4279,7 @@ static bool mob_parse_row_mobskilldb(char** str, int columns, int current) mob_id = atoi(str[0]); - if (mob_id > 0 && mob_db(mob_id) == mob_dummy) + if (mob_id > 0 && mob->db(mob_id) == mob->dummy) { if (mob_id != last_mob_id) { ShowError("mob_parse_row_mobskilldb: Non existant Mob id %d\n", mob_id); @@ -4300,8 +4290,8 @@ static bool mob_parse_row_mobskilldb(char** str, int columns, int current) if( strcmp(str[1],"clear")==0 ){ if (mob_id < 0) return false; - memset(mob_db_data[mob_id]->skill,0,sizeof(struct mob_skill)); - mob_db_data[mob_id]->maxskill=0; + memset(mob->db_data[mob_id]->skill,0,sizeof(struct mob_skill)); + mob->db_data[mob_id]->maxskill=0; return true; } @@ -4310,11 +4300,11 @@ static bool mob_parse_row_mobskilldb(char** str, int columns, int current) memset(&gms, 0, sizeof (struct mob_skill)); ms = &gms; } else { - ARR_FIND( 0, MAX_MOBSKILL, i, (ms = &mob_db_data[mob_id]->skill[i])->skill_id == 0 ); + ARR_FIND( 0, MAX_MOBSKILL, i, (ms = &mob->db_data[mob_id]->skill[i])->skill_id == 0 ); if( i == MAX_MOBSKILL ) { if (mob_id != last_mob_id) { - ShowError("mob_parse_row_mobskilldb: Too many skills for monster %d[%s]\n", mob_id, mob_db_data[mob_id]->sprite); + ShowError("mob_parse_row_mobskilldb: Too many skills for monster %d[%s]\n", mob_id, mob->db_data[mob_id]->sprite); last_mob_id = mob_id; } return false; @@ -4336,7 +4326,7 @@ static bool mob_parse_row_mobskilldb(char** str, int columns, int current) if (mob_id < 0) ShowError("mob_parse_row_mobskilldb: Invalid Skill ID (%d) for all mobs\n", j); else - ShowError("mob_parse_row_mobskilldb: Invalid Skill ID (%d) for mob %d (%s)\n", j, mob_id, mob_db_data[mob_id]->sprite); + ShowError("mob_parse_row_mobskilldb: Invalid Skill ID (%d) for mob %d (%s)\n", j, mob_id, mob->db_data[mob_id]->sprite); return false; } ms->skill_id=j; @@ -4378,13 +4368,13 @@ static bool mob_parse_row_mobskilldb(char** str, int columns, int current) if (ms->target > MST_AROUND) { ShowWarning("mob_parse_row_mobskilldb: Wrong mob skill target for ground skill %d (%s) for %s.\n", ms->skill_id, skill_db[sidx].name, - mob_id < 0?"all mobs":mob_db_data[mob_id]->sprite); + mob_id < 0?"all mobs":mob->db_data[mob_id]->sprite); ms->target = MST_TARGET; } } else if (ms->target > MST_MASTER) { ShowWarning("mob_parse_row_mobskilldb: Wrong mob skill target 'around' for non-ground skill %d (%s) for %s.\n", ms->skill_id, skill_db[sidx].name, - mob_id < 0?"all mobs":mob_db_data[mob_id]->sprite); + mob_id < 0?"all mobs":mob->db_data[mob_id]->sprite); ms->target = MST_TARGET; } @@ -4412,7 +4402,7 @@ static bool mob_parse_row_mobskilldb(char** str, int columns, int current) ms->val[4]=(int)strtol(str[16],NULL,0); if(ms->skill_id == NPC_EMOTION && mob_id>0 && - ms->val[1] == mob_db(mob_id)->status.mode) + ms->val[1] == mob->db(mob_id)->status.mode) { ms->val[1] = 0; ms->val[4] = 1; //request to return mode to normal. @@ -4431,7 +4421,7 @@ static bool mob_parse_row_mobskilldb(char** str, int columns, int current) else ms->emotion=-1; - if(str[18]!=NULL && mob_chat_db[atoi(str[18])]!=NULL) + if(str[18]!=NULL && mob->chat_db[atoi(str[18])]!=NULL) ms->msg_id=atoi(str[18]); else ms->msg_id=0; @@ -4441,9 +4431,9 @@ static bool mob_parse_row_mobskilldb(char** str, int columns, int current) mob_id *= -1; for (i = 1; i < MAX_MOB_DB; i++) { - if (mob_db_data[i] == NULL) + if (mob->db_data[i] == NULL) continue; - if (mob_db_data[i]->status.mode&MD_BOSS) + if (mob->db_data[i]->status.mode&MD_BOSS) { if (!(mob_id&2)) //Skill not for bosses continue; @@ -4451,15 +4441,15 @@ static bool mob_parse_row_mobskilldb(char** str, int columns, int current) if (!(mob_id&1)) //Skill not for normal enemies. continue; - ARR_FIND( 0, MAX_MOBSKILL, j, mob_db_data[i]->skill[j].skill_id == 0 ); + ARR_FIND( 0, MAX_MOBSKILL, j, mob->db_data[i]->skill[j].skill_id == 0 ); if(j==MAX_MOBSKILL) continue; - memcpy (&mob_db_data[i]->skill[j], ms, sizeof(struct mob_skill)); - mob_db_data[i]->maxskill=j+1; + memcpy (&mob->db_data[i]->skill[j], ms, sizeof(struct mob_skill)); + mob->db_data[i]->maxskill=j+1; } } else //Skill set on a single mob. - mob_db_data[mob_id]->maxskill=i+1; + mob->db_data[mob_id]->maxskill=i+1; return true; } @@ -4467,7 +4457,7 @@ static bool mob_parse_row_mobskilldb(char** str, int columns, int current) /*========================================== * mob_skill_db.txt reading *------------------------------------------*/ -static void mob_readskilldb(void) { +void mob_readskilldb(void) { const char* filename[] = { DBPATH"mob_skill_db.txt", "mob_skill_db2.txt" }; @@ -4491,7 +4481,7 @@ static void mob_readskilldb(void) { } } - sv->readdb(iMap->db_path, filename[fi], ',', 19, 19, -1, &mob_parse_row_mobskilldb); + sv->readdb(iMap->db_path, filename[fi], ',', 19, 19, -1, mob->parse_row_mobskilldb); } } @@ -4500,7 +4490,7 @@ static void mob_readskilldb(void) { * not overly sure if this is all correct * seems to work though... */ -static int mob_read_sqlskilldb(void) +int mob_read_sqlskilldb(void) { const char* mob_skill_db_name[] = { iMap->mob_skill_db_db, iMap->mob_skill_db2_db }; int fi; @@ -4533,7 +4523,7 @@ static int mob_read_sqlskilldb(void) if( str[i] == NULL ) str[i] = dummy; // get rid of NULL columns } - if (!mob_parse_row_mobskilldb(str, 19, count)) + if (!mob->parse_row_mobskilldb(str, 19, count)) continue; count++; @@ -4550,7 +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; @@ -4565,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; } @@ -4578,7 +4568,7 @@ static bool mob_readdb_race2(char* fields[], int columns, int current) /** * Read mob_item_ratio.txt */ -static bool mob_readdb_itemratio(char* str[], int columns, int current) +bool mob_readdb_itemratio(char* str[], int columns, int current) { int nameid, ratio, i; nameid = atoi(str[0]); @@ -4604,26 +4594,25 @@ static bool mob_readdb_itemratio(char* str[], int columns, int current) /** * read all mob-related databases */ -static void mob_load(void) -{ - sv->readdb(iMap->db_path, "mob_item_ratio.txt", ',', 2, 2+MAX_ITEMRATIO_MOBS, -1, &mob_readdb_itemratio); // must be read before mobdb - mob_readchatdb(); +void mob_load(void) { + sv->readdb(iMap->db_path, "mob_item_ratio.txt", ',', 2, 2+MAX_ITEMRATIO_MOBS, -1, mob->readdb_itemratio); // must be read before mobdb + mob->readchatdb(); if (iMap->db_use_sql_mob_db) { - mob_read_sqldb(); + mob->read_sqldb(); } if (iMap->db_use_sql_mob_skill_db) { - mob_read_sqlskilldb(); + mob->read_sqlskilldb(); } else { - mob_readdb(); - mob_readskilldb(); + mob->readdb(); + mob->readskilldb(); } - sv->readdb(iMap->db_path, "mob_avail.txt", ',', 2, 12, -1, &mob_readdb_mobavail); - mob_read_randommonster(); - sv->readdb(iMap->db_path, DBPATH"mob_race2_db.txt", ',', 2, 20, -1, &mob_readdb_race2); + sv->readdb(iMap->db_path, "mob_avail.txt", ',', 2, 12, -1, mob->readdb_mobavail); + mob->read_randommonster(); + sv->readdb(iMap->db_path, DBPATH"mob_race2_db.txt", ',', 2, 20, -1, mob->readdb_race2); } void mob_reload(void) { @@ -4631,9 +4620,9 @@ void mob_reload(void) { //Mob skills need to be cleared before re-reading them. [Skotlex] for (i = 0; i < MAX_MOB_DB; i++) - if (mob_db_data[i] && !mob_is_clone(i)) { - memset(&mob_db_data[i]->skill,0,sizeof(mob_db_data[i]->skill)); - mob_db_data[i]->maxskill=0; + if (mob->db_data[i] && !mob->is_clone(i)) { + memset(&mob->db_data[i]->skill,0,sizeof(mob->db_data[i]->skill)); + mob->db_data[i]->maxskill=0; } // Clear item_drop_ratio_db @@ -4644,15 +4633,15 @@ void mob_reload(void) { } } - mob_load(); + mob->load(); } void mob_clear_spawninfo() { //Clears spawn related information for a script reload. int i; for (i = 0; i < MAX_MOB_DB; i++) - if (mob_db_data[i]) - memset(&mob_db_data[i]->spawn,0,sizeof(mob_db_data[i]->spawn)); + if (mob->db_data[i]) + memset(&mob->db_data[i]->spawn,0,sizeof(mob->db_data[i]->spawn)); } /*========================================== @@ -4660,23 +4649,23 @@ void mob_clear_spawninfo() *------------------------------------------*/ int do_init_mob(void) { //Initialize the mob database - memset(mob_db_data,0,sizeof(mob_db_data)); //Clear the array - mob_db_data[0] = (struct mob_db*)aCalloc(1, sizeof (struct mob_db)); //This mob is used for random spawns - mob_makedummymobdb(0); //The first time this is invoked, it creates the dummy mob + memset(mob->db_data,0,sizeof(mob->db_data)); //Clear the array + mob->db_data[0] = (struct mob_db*)aCalloc(1, sizeof (struct mob_db)); //This mob is used for random spawns + mob->makedummymobdb(0); //The first time this is invoked, it creates the dummy mob item_drop_ers = ers_new(sizeof(struct item_drop),"mob.c::item_drop_ers",ERS_OPT_NONE); item_drop_list_ers = ers_new(sizeof(struct item_drop_list),"mob.c::item_drop_list_ers",ERS_OPT_NONE); - mob_load(); + mob->load(); - iTimer->add_timer_func_list(mob_delayspawn,"mob_delayspawn"); - iTimer->add_timer_func_list(mob_delay_item_drop,"mob_delay_item_drop"); - iTimer->add_timer_func_list(mob_ai_hard,"mob_ai_hard"); - iTimer->add_timer_func_list(mob_ai_lazy,"mob_ai_lazy"); - iTimer->add_timer_func_list(mob_timer_delete,"mob_timer_delete"); - iTimer->add_timer_func_list(mob_spawn_guardian_sub,"mob_spawn_guardian_sub"); - iTimer->add_timer_func_list(mob_respawn,"mob_respawn"); - iTimer->add_timer_interval(iTimer->gettick()+MIN_MOBTHINKTIME,mob_ai_hard,0,0,MIN_MOBTHINKTIME); - iTimer->add_timer_interval(iTimer->gettick()+MIN_MOBTHINKTIME*10,mob_ai_lazy,0,0,MIN_MOBTHINKTIME*10); + iTimer->add_timer_func_list(mob->delayspawn,"mob_delayspawn"); + iTimer->add_timer_func_list(mob->delay_item_drop,"mob_delay_item_drop"); + iTimer->add_timer_func_list(mob->ai_hard,"mob_ai_hard"); + iTimer->add_timer_func_list(mob->ai_lazy,"mob_ai_lazy"); + iTimer->add_timer_func_list(mob->timer_delete,"mob_timer_delete"); + iTimer->add_timer_func_list(mob->spawn_guardian_sub,"mob_spawn_guardian_sub"); + iTimer->add_timer_func_list(mob->respawn,"mob_respawn"); + iTimer->add_timer_interval(iTimer->gettick()+MIN_MOBTHINKTIME,mob->ai_hard,0,0,MIN_MOBTHINKTIME); + iTimer->add_timer_interval(iTimer->gettick()+MIN_MOBTHINKTIME*10,mob->ai_lazy,0,0,MIN_MOBTHINKTIME*10); return 0; } @@ -4687,25 +4676,25 @@ int do_init_mob(void) int do_final_mob(void) { int i; - if (mob_dummy) + if (mob->dummy) { - aFree(mob_dummy); - mob_dummy = NULL; + aFree(mob->dummy); + mob->dummy = NULL; } for (i = 0; i <= MAX_MOB_DB; i++) { - if (mob_db_data[i] != NULL) + if (mob->db_data[i] != NULL) { - aFree(mob_db_data[i]); - mob_db_data[i] = NULL; + aFree(mob->db_data[i]); + mob->db_data[i] = NULL; } } for (i = 0; i <= MAX_MOB_CHAT; i++) { - if (mob_chat_db[i] != NULL) + if (mob->chat_db[i] != NULL) { - aFree(mob_chat_db[i]); - mob_chat_db[i] = NULL; + aFree(mob->chat_db[i]); + mob->chat_db[i] = NULL; } } for (i = 0; i < MAX_ITEMDB; i++) @@ -4720,3 +4709,115 @@ int do_final_mob(void) ers_destroy(item_drop_list_ers); return 0; } + +void mob_defaults(void) { + //Defines the Manuk/Splendide mob groups for the status reductions [Epoque] + const int mob_manuk[8] = { 1986, 1987, 1988, 1989, 1990, 1997, 1998, 1999 }; + const int mob_splendide[5] = { 1991, 1992, 1993, 1994, 1995 }; + + mob = &mob_s; + + memset(mob->db_data, 0, sizeof(mob->db_data)); + mob->dummy = NULL; + memset(mob->chat_db, 0, sizeof(mob->chat_db)); + + memcpy(mob->manuk, mob_manuk, sizeof(mob->manuk)); + memcpy(mob->splendide, mob_splendide, sizeof(mob->splendide)); + /* */ + mob->reload = mob_reload; + mob->init = do_init_mob; + mob->final = do_final_mob; + /* */ + mob->db = mob_db; + mob->chat = mob_chat; + mob->makedummymobdb = mob_makedummymobdb; + mob->spawn_guardian_sub = mob_spawn_guardian_sub; + mob->skill_id2skill_idx = mob_skill_id2skill_idx; + mob->db_searchname = mobdb_searchname; + mob->db_searchname_array_sub = mobdb_searchname_array_sub; + mob->mvptomb_create = mvptomb_create; + mob->mvptomb_destroy = mvptomb_destroy; + mob->db_searchname_array = mobdb_searchname_array; + mob->db_checkid = mobdb_checkid; + mob->get_viewdata = mob_get_viewdata; + mob->parse_dataset = mob_parse_dataset; + mob->spawn_dataset = mob_spawn_dataset; + mob->get_random_id = mob_get_random_id; + mob->ksprotected = mob_ksprotected; + mob->once_spawn_sub = mob_once_spawn_sub; + mob->once_spawn = mob_once_spawn; + mob->once_spawn_area = mob_once_spawn_area; + mob->spawn_guardian = mob_spawn_guardian; + mob->spawn_bg = mob_spawn_bg; + mob->can_reach = mob_can_reach; + mob->linksearch = mob_linksearch; + mob->delayspawn = mob_delayspawn; + mob->setdelayspawn = mob_setdelayspawn; + mob->count_sub = mob_count_sub; + mob->spawn = mob_spawn; + mob->can_changetarget = mob_can_changetarget; + mob->target = mob_target; + mob->ai_sub_hard_activesearch = mob_ai_sub_hard_activesearch; + mob->ai_sub_hard_changechase = mob_ai_sub_hard_changechase; + mob->ai_sub_hard_bg_ally = mob_ai_sub_hard_bg_ally; + mob->ai_sub_hard_lootsearch = mob_ai_sub_hard_lootsearch; + mob->warpchase_sub = mob_warpchase_sub; + mob->ai_sub_hard_slavemob = mob_ai_sub_hard_slavemob; + mob->unlocktarget = mob_unlocktarget; + mob->randomwalk = mob_randomwalk; + mob->warpchase = mob_warpchase; + mob->ai_sub_hard = mob_ai_sub_hard; + mob->ai_sub_hard_timer = mob_ai_sub_hard_timer; + mob->ai_sub_foreachclient = mob_ai_sub_foreachclient; + mob->ai_sub_lazy = mob_ai_sub_lazy; + mob->ai_lazy = mob_ai_lazy; + mob->ai_hard = mob_ai_hard; + mob->setdropitem = mob_setdropitem; + mob->setlootitem = mob_setlootitem; + mob->delay_item_drop = mob_delay_item_drop; + mob->item_drop = mob_item_drop; + mob->timer_delete = mob_timer_delete; + mob->deleteslave_sub = mob_deleteslave_sub; + mob->deleteslave = mob_deleteslave; + mob->respawn = mob_respawn; + mob->log_damage = mob_log_damage; + mob->damage = mob_damage; + mob->dead = mob_dead; + mob->revive = mob_revive; + mob->guardian_guildchange = mob_guardian_guildchange; + mob->random_class = mob_random_class; + mob->class_change = mob_class_change; + mob->heal = mob_heal; + mob->warpslave_sub = mob_warpslave_sub; + mob->warpslave = mob_warpslave; + mob->countslave_sub = mob_countslave_sub; + mob->countslave = mob_countslave; + mob->summonslave = mob_summonslave; + mob->getfriendhprate_sub = mob_getfriendhprate_sub; + mob->getfriendhprate = mob_getfriendhprate; + mob->getmasterhpltmaxrate = mob_getmasterhpltmaxrate; + mob->getfriendstatus_sub = mob_getfriendstatus_sub; + mob->getfriendstatus = mob_getfriendstatus; + mob->skill_use = mobskill_use; + mob->skill_event = mobskill_event; + mob->is_clone = mob_is_clone; + mob->clone_spawn = mob_clone_spawn; + mob->clone_delete = mob_clone_delete; + mob->drop_adjust = mob_drop_adjust; + mob->item_dropratio_adjust = item_dropratio_adjust; + mob->parse_dbrow = mob_parse_dbrow; + mob->readdb_sub = mob_readdb_sub; + mob->readdb = mob_readdb; + mob->read_sqldb = mob_read_sqldb; + mob->readdb_mobavail = mob_readdb_mobavail; + mob->read_randommonster = mob_read_randommonster; + mob->parse_row_chatdb = mob_parse_row_chatdb; + mob->readchatdb = mob_readchatdb; + mob->parse_row_mobskilldb = mob_parse_row_mobskilldb; + mob->readskilldb = mob_readskilldb; + mob->read_sqlskilldb = mob_read_sqlskilldb; + mob->readdb_race2 = mob_readdb_race2; + mob->readdb_itemratio = mob_readdb_itemratio; + mob->load = mob_load; + mob->clear_spawninfo = mob_clear_spawninfo; +} |