commit
3037a1b57e
153
src/map/mob.c
153
src/map/mob.c
@ -53,10 +53,11 @@
|
||||
#define ACTIVEPATHSEARCH
|
||||
|
||||
//Dynamic mob database, allows saving of memory when there's big gaps in the mob_db [Skotlex]
|
||||
//!NOTE: Mob ID is used also as index in mob db
|
||||
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]; }
|
||||
struct mob_db *mob_db(int mob_id) { if (mob_id < 0 || mob_id > MAX_MOB_DB || mob_db_data[mob_id] == NULL) return mob_dummy; return mob_db_data[mob_id]; }
|
||||
|
||||
//Dynamic mob chat database
|
||||
struct mob_chat *mob_chat_db[MAX_MOB_CHAT+1];
|
||||
@ -71,6 +72,14 @@ struct s_mob_item_drop_ratio {
|
||||
};
|
||||
static DBMap *mob_item_drop_ratio;
|
||||
|
||||
/// Mob skill struct for temporary storage
|
||||
struct s_mob_skill {
|
||||
int16 mob_id; ///< Monster ID. -1 boss types, -2 normal types, -3 all monsters
|
||||
struct mob_skill skill[MAX_MOBSKILL]; ///< Skills
|
||||
uint8 count; ///< Number of skills
|
||||
};
|
||||
static DBMap *mob_skill_db; /// Monster skill temporary db. s_mob_skill -> mobid
|
||||
|
||||
static struct eri *item_drop_ers; //For loot drops delay structures.
|
||||
static struct eri *item_drop_list_ers;
|
||||
|
||||
@ -4228,7 +4237,8 @@ static bool mob_parse_row_mobskilldb(char** str, int columns, int current)
|
||||
};
|
||||
static int last_mob_id = 0; // ensures that only one error message per mob id is printed
|
||||
|
||||
struct mob_skill *ms, gms;
|
||||
struct s_mob_skill *skill = NULL;
|
||||
struct mob_skill *ms = NULL;
|
||||
int mob_id;
|
||||
int i = 0, j, tmp;
|
||||
|
||||
@ -4242,20 +4252,21 @@ static bool mob_parse_row_mobskilldb(char** str, int columns, int current)
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if( strcmp(str[1],"clear")==0 ){
|
||||
if (mob_id < 0)
|
||||
else 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;
|
||||
|
||||
// Looking for existing entry
|
||||
if (!(skill = (struct s_mob_skill *)idb_get(mob_skill_db, mob_id)))
|
||||
CREATE(skill, struct s_mob_skill, 1);
|
||||
|
||||
if( strcmp(str[1],"clear") == 0 && skill->mob_id != 0 ) {
|
||||
idb_remove(mob_skill_db, skill->mob_id);
|
||||
aFree(skill);
|
||||
ShowInfo("Cleared skill for mob id '%d'\n", mob_id);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (mob_id < 0)
|
||||
{ //Prepare global skill. [Skotlex]
|
||||
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, skill->skill[i].skill_id == 0 );
|
||||
if( i == MAX_MOBSKILL )
|
||||
{
|
||||
if (mob_id != last_mob_id) {
|
||||
@ -4264,7 +4275,8 @@ static bool mob_parse_row_mobskilldb(char** str, int columns, int current)
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
ms = &skill->skill[i];
|
||||
|
||||
//State
|
||||
ARR_FIND( 0, ARRAYLENGTH(state), j, strcmp(str[2],state[j].str) == 0 );
|
||||
@ -4308,7 +4320,8 @@ static bool mob_parse_row_mobskilldb(char** str, int columns, int current)
|
||||
if (ms->delay < 0 || ms->delay > MOB_MAX_DELAY) //time overflow?
|
||||
ms->delay = MOB_MAX_DELAY;
|
||||
ms->cancel = atoi(str[8]);
|
||||
if( strcmp(str[8],"yes")==0 ) ms->cancel=1;
|
||||
if( strcmp(str[8],"yes")==0 )
|
||||
ms->cancel=1;
|
||||
|
||||
//Target
|
||||
ARR_FIND( 0, ARRAYLENGTH(target), j, strcmp(str[9],target[j].str) == 0 );
|
||||
@ -4384,31 +4397,11 @@ static bool mob_parse_row_mobskilldb(char** str, int columns, int current)
|
||||
else
|
||||
ms->msg_id = 0;
|
||||
|
||||
if (mob_id < 0)
|
||||
{ //Set this skill to ALL mobs. [Skotlex]
|
||||
mob_id *= -1;
|
||||
for (i = 1; i < MAX_MOB_DB; i++)
|
||||
{
|
||||
if (mob_db_data[i] == NULL)
|
||||
continue;
|
||||
if (mob_db_data[i]->status.mode&MD_BOSS)
|
||||
{
|
||||
if (!(mob_id&2)) //Skill not for bosses
|
||||
continue;
|
||||
} else
|
||||
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 );
|
||||
if(j==MAX_MOBSKILL)
|
||||
continue;
|
||||
|
||||
memcpy (&mob_db_data[i]->skill[j], ms, sizeof(struct mob_skill));
|
||||
mob_db_data[i]->maxskill=j+1;
|
||||
skill->count++;
|
||||
if (!skill->mob_id) { // Insert new entry
|
||||
skill->mob_id = mob_id;
|
||||
idb_put(mob_skill_db, mob_id, skill);
|
||||
}
|
||||
} else //Skill set on a single mob.
|
||||
mob_db_data[mob_id]->maxskill=i+1;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -4718,6 +4711,85 @@ static void mob_drop_ratio_adjust(void){
|
||||
mob_item_drop_ratio->clear( mob_item_drop_ratio, mob_item_drop_ratio_free );
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy skill from DB to monster
|
||||
* @param mob Monster DB entry
|
||||
* @param skill Monster skill entries
|
||||
**/
|
||||
static void mob_skill_db_set_single_sub(struct mob_db *mob, struct s_mob_skill *skill) {
|
||||
uint8 i;
|
||||
|
||||
nullpo_retv(mob);
|
||||
nullpo_retv(skill);
|
||||
|
||||
for (i = 0; mob->maxskill < MAX_MOBSKILL && i < skill->count; i++) {
|
||||
mob->skill[mob->maxskill++] = skill->skill[i];
|
||||
}
|
||||
|
||||
if (i < skill->count)
|
||||
ShowWarning("Monster '%s' (%d, src:%d) reaches max skill limit %d. Ignores '%d' skills left.\n", mob->sprite, mob->vd.class_, skill->mob_id, MAX_MOBSKILL, skill->count-i);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the skill & monster id before put the skills
|
||||
* @param skill
|
||||
**/
|
||||
static void mob_skill_db_set_single(struct s_mob_skill *skill) {
|
||||
struct mob_db *mob = NULL;
|
||||
|
||||
nullpo_retv(skill);
|
||||
|
||||
// Specific monster
|
||||
if (skill->mob_id >= 0) {
|
||||
mob = mob_db(skill->mob_id);
|
||||
if (mob != mob_dummy)
|
||||
//memcpy(&mob->skill, skill, sizeof(skill));
|
||||
mob_skill_db_set_single_sub(mob, skill);
|
||||
}
|
||||
// Global skill
|
||||
else {
|
||||
uint16 i, id = skill->mob_id;
|
||||
id *= -1;
|
||||
for (i = 0; i < MAX_MOB_DB; i++) {
|
||||
mob = mob_db(i);
|
||||
if (mob == mob_dummy)
|
||||
continue;
|
||||
if ( (!(id&1) && mob->status.mode&MD_BOSS) // Bosses
|
||||
|| (!(id&2) && !(mob->status.mode&MD_BOSS)) // Normal monsters
|
||||
)
|
||||
continue;
|
||||
mob_skill_db_set_single_sub(mob, skill);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Free drop ratio data
|
||||
**/
|
||||
static int mob_skill_db_free(DBKey key, DBData *data, va_list ap) {
|
||||
struct s_mob_skill *skill = (struct s_mob_skill *)db_data2ptr(data);
|
||||
if (skill)
|
||||
aFree(skill);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set monster skills
|
||||
**/
|
||||
static void mob_skill_db_set(void) {
|
||||
DBIterator *iter = db_iterator(mob_skill_db);
|
||||
struct s_mob_skill *skill = NULL;
|
||||
|
||||
for (skill = (struct s_mob_skill *)dbi_first(iter); dbi_exists(iter); skill = (struct s_mob_skill *)dbi_next(iter)) {
|
||||
mob_skill_db_set_single(skill);
|
||||
}
|
||||
dbi_destroy(iter);
|
||||
|
||||
//ShowStatus("Set skills to '%d' monsters.\n", db_size(mob_skill_db));
|
||||
mob_skill_db->clear(mob_skill_db, mob_skill_db_free);
|
||||
}
|
||||
|
||||
/**
|
||||
* read all mob-related databases
|
||||
*/
|
||||
@ -4764,6 +4836,7 @@ static void mob_load(void)
|
||||
}
|
||||
|
||||
mob_drop_ratio_adjust();
|
||||
mob_skill_db_set();
|
||||
mob_read_randommonster();
|
||||
}
|
||||
|
||||
@ -4780,7 +4853,7 @@ void mob_reload(void) {
|
||||
|
||||
// Clear item_drop_ratio_db
|
||||
mob_item_drop_ratio->clear(mob_item_drop_ratio, mob_item_drop_ratio_free);
|
||||
|
||||
mob_skill_db->clear(mob_skill_db, mob_skill_db_free);
|
||||
mob_load();
|
||||
}
|
||||
|
||||
@ -4802,6 +4875,7 @@ void do_init_mob(void){
|
||||
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_item_drop_ratio = idb_alloc(DB_OPT_BASE);
|
||||
mob_skill_db = idb_alloc(DB_OPT_BASE);
|
||||
mob_load();
|
||||
|
||||
add_timer_func_list(mob_delayspawn,"mob_delayspawn");
|
||||
@ -4842,6 +4916,7 @@ void do_final_mob(void){
|
||||
}
|
||||
}
|
||||
mob_item_drop_ratio->destroy(mob_item_drop_ratio,mob_item_drop_ratio_free);
|
||||
mob_skill_db->destroy(mob_skill_db, mob_skill_db_free);
|
||||
ers_destroy(item_drop_ers);
|
||||
ers_destroy(item_drop_list_ers);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user